#!/bin/bash
# Seed Issues for Sprint 1 -- Run once to create initial GitHub issues
# Usage: Run inside dev container after rate limit refreshes
# This script creates the foundational issues for the first development sprint

set -euo pipefail
REPO="LookNoHandsMom/LLMHosts.com"

echo "Creating seed issues for Sprint 1..."

# Issue 1: Project scaffolding
gh issue create --repo "$REPO" \
  --title "[chore] Initialize Python project structure with src layout" \
  --body "## Task
Create the foundational Python project structure following src-layout best practices.

## Acceptance Criteria
- [ ] \`src/llmhost/\` package with \`__init__.py\`
- [ ] \`src/llmhost/api/\` -- FastAPI application
- [ ] \`src/llmhost/core/\` -- Business logic
- [ ] \`src/llmhost/models/\` -- Pydantic models
- [ ] \`src/llmhost/services/\` -- External integrations
- [ ] \`tests/\` mirror of src layout
- [ ] \`pyproject.toml\` with all dependencies
- [ ] \`requirements.txt\` + \`requirements-dev.txt\`
- [ ] Pre-commit hooks configured (.pre-commit-config.yaml)
- [ ] ruff.toml with project rules
- [ ] Docker build still succeeds

## Technical Notes
Follow ADR-008 (CLI-first). See implementation-blueprint.md L0 (Foundation).
" \
  --label "type:chore,epic:conductor,priority:critical,size:m,agent:cursor"

echo "Issue 1 created"

# Issue 2: API skeleton
gh issue create --repo "$REPO" \
  --title "[feature] Create FastAPI application skeleton with health endpoint" \
  --body "## Task
Set up the FastAPI application with basic structure, CORS, health check, and OpenAPI docs.

## User Story
As a developer, I want a running API server so that I can start building endpoints.

## Acceptance Criteria
- [ ] FastAPI app in \`src/llmhost/api/app.py\`
- [ ] \`GET /health\` returns \`{\"status\": \"ok\", \"version\": \"0.1.0\"}\`
- [ ] \`GET /docs\` serves Swagger UI
- [ ] CORS configured for local development
- [ ] Structured logging with structlog
- [ ] Settings via pydantic-settings (\`.env\` support)
- [ ] Docker compose runs the API on port 8000
- [ ] Pytest test for health endpoint passes

## Technical Notes
See openapi.yaml for full API spec. This issue covers only the skeleton.
ADR-003 (API Proxy) defines the architecture.
" \
  --label "type:feature,epic:conductor,priority:critical,size:m,agent:cursor"

echo "Issue 2 created"

# Issue 3: LiteLLM integration
gh issue create --repo "$REPO" \
  --title "[feature] Integrate LiteLLM as unified LLM routing layer" \
  --body "## Task
Integrate LiteLLM as the core routing engine for multi-provider LLM access.

## User Story
As a user, I want to send requests to any LLM provider through a single API so that I don't manage multiple provider SDKs.

## Acceptance Criteria
- [ ] LiteLLM installed and configured in \`src/llmhost/services/llm_router.py\`
- [ ] Support for at least: OpenAI, Anthropic, Google (Gemini)
- [ ] \`POST /v1/chat/completions\` endpoint (OpenAI-compatible)
- [ ] Streaming support via SSE
- [ ] Provider API keys injected via environment variables
- [ ] Cost tracking per request
- [ ] Fallback routing: if primary provider fails, try secondary
- [ ] Tests with mocked provider responses

## Technical Notes
See ADR-001 (Orchestrator Model) and ADR-002 (Inference Engine).
LiteLLM docs: https://docs.litellm.ai/
" \
  --label "type:feature,epic:conductor,priority:critical,size:l,agent:cursor"

echo "Issue 3 created"

# Issue 4: Frontend scaffold
gh issue create --repo "$REPO" \
  --title "[feature] Initialize Next.js frontend with design system tokens" \
  --body "## Task
Create the frontend application with Next.js, Tailwind CSS, and our design system tokens.

## User Story
As a user, I want a web dashboard to manage my AI cloud.

## Acceptance Criteria
- [ ] Next.js 15 app in \`frontend/\`
- [ ] Tailwind CSS configured with design system tokens from \`docs/architecture/design-system.md\`
- [ ] Dark mode support (default theme)
- [ ] Layout component with sidebar navigation
- [ ] Dashboard page skeleton (matches \`docs/architecture/wireframes/dashboard-main.md\`)
- [ ] TypeScript strict mode
- [ ] ESLint + Prettier configured
- [ ] Docker compose serves frontend on port 3000
- [ ] Storybook configured for component development

## Technical Notes
See ADR-005 (Frontend Framework), design-system.md, wireframes/.
" \
  --label "type:feature,epic:frontend,priority:high,size:l,agent:cursor"

echo "Issue 4 created"

# Issue 5: Auth skeleton
gh issue create --repo "$REPO" \
  --title "[feature] Implement API key authentication middleware" \
  --body "## Task
Create authentication middleware using API keys for the v1 API.

## User Story
As a user, I want my API to be protected by API keys so that only authorized clients can access it.

## Acceptance Criteria
- [ ] API key model in \`src/llmhost/models/auth.py\`
- [ ] Auth middleware in \`src/llmhost/api/middleware/auth.py\`
- [ ] \`POST /v1/api-keys\` -- create new key (returns key once)
- [ ] \`GET /v1/api-keys\` -- list keys (masked)
- [ ] \`DELETE /v1/api-keys/{id}\` -- revoke key
- [ ] All \`/v1/\` endpoints require valid API key (except /health)
- [ ] Keys stored as bcrypt hashes
- [ ] Rate limiting per key (configurable)
- [ ] Tests: valid key, invalid key, expired key, rate limited

## Technical Notes
See threat-model.md STRIDE analysis. ADR-004 (Security Overlay).
Phase 1 uses API keys; Phase 2 adds OAuth/OIDC.
" \
  --label "type:feature,epic:security,priority:high,size:m,agent:cursor"

echo "Issue 5 created"

# Issue 6: Caching layer
gh issue create --repo "$REPO" \
  --title "[feature] Implement semantic caching for LLM responses" \
  --body "## Task
Build a caching layer that deduplicates similar LLM requests using semantic similarity.

## User Story
As a user, I want repeated similar queries to be served from cache so I save money and get faster responses.

## Acceptance Criteria
- [ ] Cache service in \`src/llmhost/services/cache.py\`
- [ ] L1: Exact match cache (in-memory LRU)
- [ ] L2: Semantic similarity cache (embedding-based, cosine similarity > 0.95)
- [ ] \`GET /v1/cache/stats\` -- cache hit rate, size, savings
- [ ] Cache-Control headers on responses
- [ ] TTL configurable per model
- [ ] Cache invalidation API
- [ ] Tests: exact hit, semantic hit, miss, expiry, invalidation

## Technical Notes
See caching-strategies.md knowledge base.
ADR-007 defines container strategy for Redis (L2 backing store).
" \
  --label "type:feature,epic:cache,priority:medium,size:l,agent:cursor"

echo "Issue 6 created"

echo ""
echo "=== All 6 seed issues created ==="
echo "View at: https://github.com/$REPO/issues"
