Blame · Line-by-line history
BUILD_BIBLE.md
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 9ab6971 | 1 | # GLUECRON BUILD BIBLE |
| 2 | ||
| 3 | **This file is the single source of truth for the GlueCron build.** | |
| 4 | ||
| 5 | **Every Claude agent MUST read this file in full before touching code. No exceptions.** | |
| 6 | ||
| 7 | GlueCron is a GitHub replacement — AI-native code intelligence, green ecosystem enforcement, git hosting, automated CI. It is production infrastructure for multiple downstream platforms. Production cannot stop. | |
| 8 | ||
| 9 | --- | |
| 10 | ||
| 11 | ## 1. AGENT POLICY (READ FIRST, FOLLOW ALWAYS) | |
| 12 | ||
| 13 | ### 1.1 Required reads at session start | |
| 14 | 1. `BUILD_BIBLE.md` (this file) — complete | |
| 15 | 2. `CLAUDE.md` — stack + architecture | |
| 16 | 3. `README.md` — user-facing overview | |
| 17 | 4. Most recent commit on the current branch (`git log -1 --stat`) | |
| 18 | ||
| 19 | ### 1.2 Do-not-undo rule | |
| 20 | - Anything listed in **§4 LOCKED BLOCKS** is shipped and must not be deleted, renamed, or semantically altered without the owner's explicit written permission in the current session. | |
| 21 | - "Refactor" is not permission. "Clean up" is not permission. "Simplify" is not permission. | |
| 22 | - If a locked file seems wrong, open an issue in the plan and keep going on a new block. | |
| 23 | ||
| 24 | ### 1.3 Continuous-build rule | |
| 25 | - The owner runs many parallel projects. Do not stop work to ask for clarification that can be inferred from this file. | |
| 26 | - Default behaviour when a block is partially complete: **finish it, run tests, commit, push, start the next block**. | |
| 27 | - Only stop for genuinely blocking decisions: destructive operations, architectural reversals, requests outside this plan, or repeated test failures you can't diagnose. | |
| 28 | - Never stop because "the session might run out." Commit what works and keep building. | |
| 29 | ||
| 30 | ### 1.4 Branch + commit rules | |
| 31 | - Development branch: whatever the current session was told (check session opening message). Fall back to `main` if none given. | |
| 32 | - One commit per completed block. Message format: `feat(BLOCK-ID): <summary>`. | |
| 33 | - Push after every commit with `git push -u origin <branch>`. | |
| 34 | - Never force-push. Never `--no-verify`. Never amend published commits. | |
| 35 | ||
| 36 | ### 1.5 Quality bars (non-negotiable) | |
| 37 | - `bun test` must pass before every commit. | |
| 38 | - New features ship with tests in `src/__tests__/`. | |
| 39 | - New routes use `softAuth` or `requireAuth` middleware. | |
| 40 | - New DB tables have a corresponding migration in `drizzle/`. | |
| 41 | - AI features use `isAiAvailable()` guards and degrade gracefully without `ANTHROPIC_API_KEY`. | |
| 42 | - Every user-facing failure mode has a fallback — no 500s reach the UI. | |
| 43 | ||
| 44 | ### 1.6 Green-ecosystem-by-default | |
| 45 | - Every new repo auto-configures: gates on, branch protection on, labels seeded, CODEOWNERS synced, welcome issue posted. | |
| 46 | - Users can opt out per feature but defaults are maximum-green. | |
| 47 | - Nothing broken ever reaches production, the website, or the customer. | |
| 48 | ||
| 15e65d2 | 49 | ### 1.7 Parallelism rule (added per owner request) |
| 50 | - **Default to spawning sub-agents whenever work can be parallelised.** Owner-cost of an idle main thread is high; owner-cost of an extra agent is near-zero. | |
| 51 | - Independent files = parallel agents. Schema-only edits, new route files, doc updates, test additions, codebase research — all of these run in parallel by default unless they collide. | |
| 52 | - Coordinate file ownership: one agent per file. Never let two agents edit the same file. Mounting + middleware integration stay on the main thread to avoid merge conflicts. | |
| 53 | - When launching multiple agents, send them in a single message with multiple Agent tool calls so they actually run concurrently. | |
| 54 | - The main thread is responsible for: reviewing each agent's output before integrating, running the test suite, and committing. Trust-but-verify — read the changes, don't just rely on the agent's summary. | |
| 55 | ||
| 9ab6971 | 56 | --- |
| 57 | ||
| 58 | ## 2. GITHUB PARITY SCORECARD | |
| 59 | ||
| 60 | Legend: ✅ shipped · 🟡 partial · ❌ not built | |
| 61 | ||
| 62 | ### 2.1 Repository hosting | |
| 63 | | Feature | Status | Notes | | |
| 64 | |---|---|---| | |
| 65 | | Git Smart HTTP (clone / push / fetch) | ✅ | `src/routes/git.ts`, `src/git/protocol.ts` | | |
| 66 | | SSH keys | ✅ | `ssh_keys` table, `src/routes/settings.tsx` | | |
| 67 | | Public / private visibility | ✅ | `repositories.isPrivate` | | |
| 68 | | Forking | ✅ | `src/routes/fork.ts` | | |
| 69 | | Stars | ✅ | `stars` table, `/:owner/:repo/star` | | |
| 70 | | Topics | ✅ | `repo_topics` table | | |
| 71 | | Archive / disable repo | ❌ | schema has flags; no UI | | |
| 72 | | Repository transfer | ❌ | — | | |
| 73 | | Template repositories | ❌ | — | | |
| 74 | | Repository mirroring | ❌ | — | | |
| 75 | ||
| 76 | ### 2.2 Code browsing | |
| 77 | | Feature | Status | Notes | | |
| 78 | |---|---|---| | |
| 79 | | File tree browser | ✅ | `src/routes/web.tsx` | | |
| 80 | | Syntax highlighting | ✅ | 40+ languages, `src/lib/highlight.ts` | | |
| 81 | | Commit history | ✅ | | | |
| 82 | | Diffs | ✅ | | | |
| 83 | | Blame | ✅ | | | |
| 84 | | Raw file download | ✅ | | | |
| 85 | | Branch switcher | ✅ | | | |
| 86 | | Tag listing | ✅ | new this build | | |
| 87 | | Code search (ILIKE) | ✅ | per-repo + global | | |
| 3cbe3d6 | 88 | | Semantic / embedding search | ✅ | D1 — `code_chunks` table + lexical fallback, optional Voyage `voyage-code-3`; `src/lib/semantic-search.ts`, `src/routes/semantic-search.tsx` | |
| 9ab6971 | 89 | | Symbol / xref navigation | ❌ | — | |
| 90 | ||
| 91 | ### 2.3 Collaboration | |
| 92 | | Feature | Status | Notes | | |
| 93 | |---|---|---| | |
| 94 | | Issues (CRUD / comments / labels / close) | ✅ | | | |
| 95 | | Milestones | ✅ | `src/routes/insights.tsx` | | |
| 96 | | Pull requests (CRUD / review / merge) | ✅ | | | |
| 97 | | PR inline comments | ✅ | file+line anchored | | |
| 6fc53bd | 98 | | Draft PRs | ✅ | create as draft, ready-for-review toggle, dedicated tab, merge blocked until ready | |
| 99 | | Reactions (emoji) | ✅ | 8 reactions, toggle via `POST /api/reactions/:t/:id/:emoji/toggle` on issues + PRs + comments | | |
| 9ab6971 | 100 | | Mentions + notifications | ✅ | `src/routes/notifications.tsx` | |
| 101 | | Code owners | ✅ | `src/lib/codeowners.ts` | | |
| 24cf2ca | 102 | | Issue templates | ✅ | `.github/ISSUE_TEMPLATE.md` auto-prefills new issues; frontmatter stripped; `src/lib/templates.ts` | |
| 103 | | PR templates | ✅ | `.github/PULL_REQUEST_TEMPLATE.md` auto-prefills new PRs; `src/lib/templates.ts` | | |
| 104 | | Saved replies | ✅ | per-user canned comments, unique-shortcut, `/settings/replies`, `/api/user/replies` | | |
| 1e162a8 | 105 | | Discussions / forums | ✅ | E2 — categorised threads, pinned/locked, q-and-a answers. `src/routes/discussions.tsx` + `drizzle/0013_discussions.sql` | |
| 106 | | Wikis | ✅ | E3 — markdown pages per repo with revision history + revert. DB-backed v1. `src/routes/wikis.tsx` + `drizzle/0016_wikis.sql` | | |
| 107 | | Projects / kanban | ✅ | E1 — per-repo boards with auto-seeded To Do/In Progress/Done columns. Notes or linked issues/PRs. `src/routes/projects.tsx` + `drizzle/0015_projects.sql` | | |
| 108 | | AI incident responder | ✅ | D4 — auto-issues on deploy fail, `src/lib/ai-incident.ts` | | |
| 109 | | AI-generated test stubs | ✅ | D8 — `src/lib/ai-tests.ts`, `/:owner/:repo/ai/tests` | | |
| 9ab6971 | 110 | |
| 111 | ### 2.4 Automation + AI | |
| 112 | | Feature | Status | Notes | | |
| 113 | |---|---|---| | |
| ad6d4ad | 114 | | Webhooks (outbound, HMAC signed) | ✅ | `src/routes/webhooks.tsx` | |
| 115 | | GateTest inbound callback | ✅ | `POST /api/hooks/gatetest`, bearer or HMAC | | |
| 116 | | Backup PAT-auth gate ingest | ✅ | `POST /api/v1/gate-runs` | | |
| 9ab6971 | 117 | | Gate runs (test / secret / AI review) | ✅ | `gate_runs` table, `src/routes/gates.tsx` | |
| 118 | | Branch protection | ✅ | `branch_protection` table + UI | | |
| 119 | | Auto-repair engine | ✅ | `src/lib/auto-repair.ts` | | |
| 120 | | Secret scanner | ✅ | 15 patterns, `src/lib/security-scan.ts` | | |
| 121 | | AI security review | ✅ | Sonnet 4, `src/lib/security-scan.ts` | | |
| 122 | | AI commit messages | ✅ | `src/lib/ai-generators.ts` | | |
| 123 | | AI PR summaries | ✅ | | | |
| 3cbe3d6 | 124 | | AI changelogs | ✅ | auto on release create; arbitrary-range viewer at `/:owner/:repo/ai/changelog?from=&to=` (D7) | |
| 9ab6971 | 125 | | AI code review | ✅ | `src/lib/ai-review.ts` | |
| 126 | | AI merge conflict resolver | ✅ | `src/lib/merge-resolver.ts` | | |
| 127 | | AI chat (global + repo) | ✅ | `src/routes/ask.tsx` | | |
| 3cbe3d6 | 128 | | AI explain-this-codebase | ✅ | D6 — per-commit cached markdown, `GET /:owner/:repo/explain`, `src/lib/ai-explain.ts` + `src/routes/ai-explain.tsx` | |
| 129 | | AI PR triage | ✅ | D3 — Claude Haiku suggests labels/reviewers/priority as an AI comment on PR create; `triagePullRequest` in `src/lib/ai-generators.ts`, wired in `src/routes/pulls.tsx` | | |
| 5e888b7 | 130 | | GitHub Actions equivalent (workflow runner) | ✅ | `src/lib/workflow-parser.ts`, `src/lib/workflow-runner.ts`, `src/routes/workflows.tsx`; `.gluecron/workflows/*.yml` auto-discovered on push; Bun subprocess executor, per-step timeouts, size-capped logs | |
| 3cbe3d6 | 131 | | Dependabot equivalent (AI dep bumper) | ✅ | D2 — `dep_update_runs` table, npm registry fetch, plan + apply bumps, creates `gluecron/dep-update-*` branch + PR row via git plumbing. `src/lib/dep-updater.ts`, `src/routes/dep-updater.tsx`, settings UI at `/:owner/:repo/settings/dep-updater`. | |
| 9ab6971 | 132 | | Code scanning UI | 🟡 | data exists, no dedicated UI page | |
| 3cbe3d6 | 133 | | Copilot code completion | ✅ | D9 — `POST /api/copilot/completions` (PAT/OAuth/session), `GET /api/copilot/ping`. `src/lib/ai-completion.ts`, `src/routes/copilot.ts`. LRU-cached, rate-limited 60/min. | |
| 134 | | Semantic code search | ✅ | D1 — see 2.2 | | |
| 9ab6971 | 135 | |
| 136 | ### 2.5 Platform | |
| 137 | | Feature | Status | Notes | | |
| 138 | |---|---|---| | |
| 139 | | Dashboard | ✅ | `src/routes/dashboard.tsx` | | |
| 140 | | Explore / discover | ✅ | | | |
| 141 | | Global search | ✅ | repos / users / issues / PRs | | |
| 142 | | Insights (graph, contributors, green rate) | ✅ | `src/routes/insights.tsx` | | |
| 143 | | Releases + tags | ✅ | AI changelog | | |
| 144 | | Personal access tokens | ✅ | SHA-256 hashed | | |
| 058d752 | 145 | | OAuth app provider | ✅ | `src/routes/oauth.tsx`, `src/routes/developer-apps.tsx`, `src/lib/oauth.ts`; `oauth_apps` + `oauth_authorizations` + `oauth_access_tokens` tables | |
| 9ab6971 | 146 | | GitHub Apps equivalent | ❌ | | |
| 147 | | GraphQL API | ❌ | REST only | | |
| 058d752 | 148 | | Organizations + teams | ✅ | B1+B2+B3 shipped: `src/routes/orgs.tsx`, `src/lib/orgs.ts`; org-owned repos (`repositories.orgId`); team-based CODEOWNERS (`@org/team` resolution) | |
| 9ab6971 | 149 | | Enterprise SAML / SSO | ❌ | | |
| 058d752 | 150 | | 2FA / TOTP | ✅ | `src/routes/settings-2fa.tsx`, `src/lib/totp.ts`; `user_totp` + `user_recovery_codes` tables | |
| 151 | | Passkeys / WebAuthn | ✅ | `src/routes/passkeys.tsx`, `src/lib/webauthn.ts`; `user_passkeys` + `webauthn_challenges` tables | | |
| 25a91a6 | 152 | | Packages registry (npm / docker / etc) | ✅ | `src/lib/packages.ts`, `src/routes/packages-api.ts`, `src/routes/packages.tsx`; npm protocol (packument, tarball, publish, yank); PAT (`glc_`) auth via Authorization header; container registry deferred | |
| 153 | | Pages / static hosting | ✅ | `src/lib/pages.ts`, `src/routes/pages.tsx`; serves blobs from bare git at latest `gh-pages` commit; per-repo settings (source branch/dir, custom domain); short-cache headers | | |
| 1e162a8 | 154 | | Gists | ✅ | E4 — multi-file tiny repos with per-revision JSON snapshots + stars. `src/routes/gists.tsx` + `drizzle/0014_gists.sql` | |
| 9ab6971 | 155 | | Sponsors | ❌ | | |
| 156 | | Marketplace | ❌ | | | |
| 25a91a6 | 157 | | Environments / deployment tracking | ✅ | `src/routes/deployments.tsx` — grouped by env, success-rate rollup, per-deploy detail. Protected environments (`src/routes/environments.tsx`, `src/lib/environments.ts`) with reviewer-gated approval, branch-glob restrictions, approve/reject decisions recorded in `deployment_approvals` | |
| 9ab6971 | 158 | | Merge queues | ❌ | | |
| 159 | | Required checks matrix | 🟡 | branch_protection has single flag, no matrix | | |
| 160 | ||
| 161 | ### 2.6 Observability + safety | |
| 162 | | Feature | Status | Notes | | |
| 163 | |---|---|---| | |
| 164 | | Rate limiting | ✅ | `src/middleware/rate-limit.ts` | | |
| 165 | | Request-ID tracing | ✅ | `src/middleware/request-context.ts` | | |
| 166 | | Health / readiness / metrics | ✅ | `/healthz` `/readyz` `/metrics` | | |
| 167 | | Audit log (table) | ✅ | `audit_log` table | | |
| 6fc53bd | 168 | | Audit log UI | ✅ | `/settings/audit` (personal) + `/:owner/:repo/settings/audit` (per-repo, owner-only) | |
| 9ab6971 | 169 | | Traffic analytics per repo | ❌ | | |
| 24cf2ca | 170 | | Email notifications | ✅ | opt-in per kind (mention/assign/gate-fail) via `/settings`; provider-pluggable `src/lib/email.ts` (log default, resend in prod) | |
| 9ab6971 | 171 | | Email digest | ❌ | | |
| 172 | | Mobile PWA | 🟡 | responsive CSS, no manifest | | |
| 173 | | Native mobile apps | ❌ | | | |
| 6fc53bd | 174 | | Dark mode | ✅ | default | |
| 175 | | Light-mode toggle | ✅ | `/theme/toggle` + `theme` cookie, pre-paint script avoids FOUC, nav sun/moon icon | | |
| 9ab6971 | 176 | | Keyboard shortcuts | ✅ | `/shortcuts` page | |
| 177 | | Command palette | 🟡 | Cmd+K → Ask AI, no generic palette | | |
| 178 | ||
| 179 | --- | |
| 180 | ||
| 181 | ## 3. BUILD PLAN (BLOCKS) | |
| 182 | ||
| 183 | Each block is a self-contained unit. Order matters for dependencies. Each block ends with tests + commit + push. | |
| 184 | ||
| 185 | ### BLOCK A — Hardening the current surface | |
| 186 | Polish what's shipped before adding more. **Priority: do this first if parity gaps are minor.** | |
| 6fc53bd | 187 | - **A1** — Dark/light theme toggle (cookie, CSS variable swap) ✅ |
| 188 | - **A2** — Audit log UI page (`/settings/audit` + `/:owner/:repo/settings/audit`) ✅ | |
| 189 | - **A3** — Reactions UI on issues / PRs / comments (data exists) ✅ | |
| 190 | - **A4** — Draft PR toggle + filter ✅ | |
| 24cf2ca | 191 | - **A5** — Issue + PR templates (`.github/*_TEMPLATE.md` auto-prefill) ✅ |
| 192 | - **A6** — Saved replies per user ✅ | |
| 193 | - **A7** — Environments + deployment history UI (`deployments` table) ✅ | |
| 194 | - **A8** — Email notifications (opt-in, provider-pluggable) ✅ | |
| 195 | ||
| 196 | **BLOCK A COMPLETE.** Next: BLOCK B (Identity + orgs). | |
| 9ab6971 | 197 | |
| 198 | ### BLOCK B — Identity + orgs | |
| 058d752 | 199 | - **B1** — Organizations (schema: `organizations`, `org_members`, `teams`, `team_members`) → ✅ shipped (`6563f0a`) |
| 6563f0a | 200 | - Helpers in `src/lib/orgs.ts`: slug validation, role rank, reserved-slug set, loaders |
| 201 | - Routes in `src/routes/orgs.tsx`: list / create / profile / people / teams / team detail | |
| 202 | - Role-based guards: admin adds members, owner grants owner, last-owner demote/remove blocked | |
| 203 | - All sensitive actions `audit()`'d (org.create, member.add/role/remove, team.create, team.member.add/remove) | |
| 058d752 | 204 | - **B2** — Repos owned by orgs (nullable `repositories.orgId`) → ✅ shipped (`7437605`) |
| 205 | - **B3** — Team-based CODEOWNERS (`@org/team` resolution) → ✅ shipped (`40d3e3f`) | |
| 206 | - **B4** — 2FA / TOTP (enroll, recovery codes) → ✅ shipped (`7298a17`) | |
| 207 | - **B5** — WebAuthn / passkeys → ✅ shipped (`2df1f8c`) | |
| 208 | - **B6** — OAuth 2.0 provider (third-party apps can request access) → ✅ shipped (pending final commit) | |
| 9ab6971 | 209 | |
| 210 | ### BLOCK C — Runtime + hosting | |
| 5e888b7 | 211 | - **C1** — Actions-equivalent workflow runner → ✅ shipped (`eafe8c6`) |
| 212 | - Workflow YAML parser (`src/lib/workflow-parser.ts`) — hand-rolled subset | |
| 213 | - Background worker (`src/lib/workflow-runner.ts`) — Bun.spawn, size-capped logs, SIGTERM→SIGKILL timeouts | |
| 214 | - Auto-discovery from `.gluecron/workflows/*.yml` on default-branch push | |
| 215 | - UI at `/:owner/:repo/actions` with manual trigger + cancel | |
| 25a91a6 | 216 | - **C2** — Package registry (npm protocol) → ✅ shipped |
| 217 | - Packument + tarball + publish + yank via `PUT /npm/<name>` + `GET /npm/<name>` | |
| 218 | - PAT (`glc_`) bearer auth for CLI clients; add `//host/npm/:_authToken=<PAT>` to .npmrc | |
| 219 | - Container registry deferred (schema ready for it) | |
| 220 | - **C3** — Pages / static hosting → ✅ shipped | |
| 221 | - Serves `/:owner/:repo/pages/*` from the latest successful `pages_deployments` row | |
| 222 | - Auto-records on push to the repo's configured source branch (default `gh-pages`) | |
| 223 | - Settings UI at `/:owner/:repo/settings/pages` + manual redeploy | |
| 224 | - **C4** — Environments with protected approvals → ✅ shipped | |
| 225 | - Per-repo `environments` with reviewer list + branch-glob allowlist | |
| 226 | - Auto-deploy on main is gated by `requiresApprovalFor()`; pending rows show status `pending_approval` | |
| 227 | - Approve/reject at `POST /:owner/:repo/deployments/:id/approve|reject` | |
| 9ab6971 | 228 | |
| 229 | ### BLOCK D — AI-native differentiation | |
| 230 | This is where GlueCron beats GitHub outright. **Priority: ship these loud.** | |
| 3cbe3d6 | 231 | - **D1** — Semantic code search → ✅ shipped. `src/lib/semantic-search.ts` + `src/routes/semantic-search.tsx`. `code_chunks` table stores chunk embeddings as JSON (upgrade path to `pgvector`). Embedding provider: Voyage AI `voyage-code-3` when `VOYAGE_API_KEY` is set, otherwise deterministic 512-dim hashing fallback. Index via `POST /:owner/:repo/search/semantic/reindex` (owner-only). |
| 232 | - **D2** — AI dependency updater → ✅ shipped. `src/lib/dep-updater.ts` + `src/routes/dep-updater.tsx`. `dep_update_runs` table tracks run history. Parses `package.json`, queries `registry.npmjs.org`, plans bumps (skips workspace/github specs + downgrades), writes an `gluecron/dep-update-<ts>` branch via git plumbing (`hash-object` + `mktree` + `commit-tree` + `update-ref`), inserts a pull_requests row with a markdown bump table. Settings UI at `/:owner/:repo/settings/dep-updater` with "Run now". | |
| 233 | - **D3** — AI PR triage → ✅ shipped. `triagePullRequest` in `src/lib/ai-generators.ts`; hooked into PR create in `src/routes/pulls.tsx` (fire-and-forget). Posts a non-applied "## AI Triage" comment with suggested labels, reviewers, priority, and risk area. Suggestions only — PR author stays in control. | |
| 1e162a8 | 234 | - **D4** — AI incident responder → ✅ shipped. `src/lib/ai-incident.ts` exports `onDeployFailure(args)` — on deploy-fail hooks, samples ~10 recent commits, calls Sonnet 4 for a structured root-cause JSON, opens an issue (number via `serial`), best-effort attaches `incident` label, sets `deployments.blockedReason="auto-issue #N"`. Wired from `src/hooks/post-receive.ts triggerCrontechDeploy` (fire-and-forget) and from `POST /:owner/:repo/deployments/:id/retry-incident` (owner-only re-run button on the deployment detail page). Never throws; degrades to deterministic body when no `ANTHROPIC_API_KEY`. |
| 235 | - **D5** — AI code reviewer blocks merges → ✅ shipped. `src/lib/branch-protection.ts` exports `matchProtection(repoId, branch)` (exact > glob, reuses `matchGlob` from environments.ts), `evaluateProtection(rule, ctx)` pure decision helper (checks `requireAiApproval` / `requireGreenGates` / `requireHumanReview` / `requiredApprovals`), and `countHumanApprovals(prId)` (LGTM/`+1`/approved heuristic on non-AI PR comments). Wired into `src/routes/pulls.tsx` merge handler after the existing hard-gate filter — blocks merge with readable reasons when rule fails. 8 unit tests in `src/__tests__/branch-protection.test.ts`. | |
| 3cbe3d6 | 236 | - **D6** — AI "explain this codebase" → ✅ shipped. `src/lib/ai-explain.ts` + `src/routes/ai-explain.tsx`. Samples up to ~25 representative files (~60KB cap), generates a Markdown explanation via Sonnet 4, caches per (repo, commit sha) in `codebase_explanations`. `GET /:owner/:repo/explain` + owner-only `POST /:owner/:repo/explain/regenerate`. Explain link added to `RepoNav`. |
| 237 | - **D7** — AI changelog for every commit range → ✅ shipped. `src/routes/ai-changelog.tsx`. `GET /:owner/:repo/ai/changelog?from=&to=(&format=markdown)` — runs `git log` on the range, calls existing `generateChangelog`, renders form + rendered Markdown + copy-box; `format=markdown` returns `text/markdown` for CLI/CI consumers. Caps at 500 commits. | |
| 1e162a8 | 238 | - **D8** — AI-generated test suite → ✅ shipped. `src/lib/ai-tests.ts` exports `detectLanguage(path)`, `detectTestFramework(repo tree)`, `buildTestsPrompt(...)`, `suggestedTestPath(...)`, `generateTestStub({path, content, framework, language})` (returns `{code:"", framework:"fallback"}` when AI unavailable), `contentTypeFor(path)`. Route `src/routes/ai-tests.tsx` adds `GET /:owner/:repo/ai/tests` (form + file picker), `GET /:owner/:repo/ai/tests?format=raw` (raw text with correct MIME), `POST /:owner/:repo/ai/tests/generate` (requireAuth, renders highlighted source + generated failing test, copy button). Stubs are intentionally failing so the author fills them in. |
| 3cbe3d6 | 239 | - **D9** — Copilot-style completion endpoint → ✅ shipped. `src/lib/ai-completion.ts` + `src/routes/copilot.ts`. `POST /api/copilot/completions` (requireAuth accepts PAT/OAuth/session), `GET /api/copilot/ping`. Claude Haiku; in-memory LRU (size 200, 5-min TTL); code-fence stripping; 60/min rate limit per caller. |
| 9ab6971 | 240 | |
| 241 | ### BLOCK E — Collaboration parity | |
| 1e162a8 | 242 | - **E1** — Projects / kanban boards → ✅ shipped. `src/routes/projects.tsx`, tables `projects`/`project_columns`/`project_items` (migration 0015). Create creates three default columns (To Do/In Progress/Done); cards carry note or issue/pr link; one-click move between columns; owner-only close. |
| 243 | - **E2** — Discussions (forum threads per repo) → ✅ shipped. `src/routes/discussions.tsx`, tables `discussions`/`discussion_comments` (migration 0013). Categorised (general/q-and-a/ideas/announcements/show-and-tell), pinnable, lockable, q-and-a answers. | |
| 244 | - **E3** — Wikis → ✅ shipped as DB-backed v1. `src/routes/wikis.tsx`, tables `wiki_pages`/`wiki_revisions` (migration 0016). Slug auto-derived; every edit bumps revision + appends a revision row; owner can revert. Git-backed mirror deferred. | |
| 245 | - **E4** — Gists → ✅ shipped. `src/routes/gists.tsx`, tables `gists`/`gist_files`/`gist_revisions`/`gist_stars` (migration 0014). Multi-file; each edit takes a JSON snapshot into `gist_revisions` keyed on revision number; stars toggle; secret gists hidden from non-owners. | |
| 246 | - **E5** — Merge queues (serialised merge with re-test) — NOT STARTED | |
| 247 | - **E6** — Required status checks matrix (multiple named checks per branch protection rule) — NOT STARTED | |
| 248 | - **E7** — Protected tags — NOT STARTED | |
| 9ab6971 | 249 | |
| 250 | ### BLOCK F — Observability + admin | |
| 251 | - **F1** — Traffic analytics per repo (views, clones, unique visitors) | |
| 252 | - **F2** — Org-wide insights (green rate across all repos) | |
| 253 | - **F3** — Admin / superuser panel (user moderation, repo audit) | |
| 254 | - **F4** — Billing + quotas (storage, AI tokens, bandwidth) | |
| 255 | ||
| 256 | ### BLOCK G — Mobile + client | |
| 257 | - **G1** — PWA manifest + service worker | |
| 258 | - **G2** — GraphQL API mirror of REST | |
| 259 | - **G3** — Official CLI (`gluecron` binary in Bun) | |
| 260 | - **G4** — VS Code extension | |
| 261 | ||
| 262 | ### BLOCK H — Marketplace | |
| 263 | - **H1** — App marketplace (install third-party apps against a repo) | |
| 264 | - **H2** — GitHub Apps equivalent (bot identities with scoped permissions) | |
| 265 | ||
| 266 | --- | |
| 267 | ||
| 268 | ## 4. LOCKED BLOCKS (DO NOT UNDO) | |
| 269 | ||
| 270 | Everything below is committed, tested, and load-bearing. **Do not delete, rename, or semantically change without owner permission.** | |
| 271 | ||
| 272 | ### 4.1 Infrastructure (locked) | |
| 273 | - `src/app.tsx` — route composition, middleware order, error handlers | |
| 274 | - `src/index.ts` — Bun server entry | |
| 275 | - `src/lib/config.ts` — env getters (late-binding) | |
| 276 | - `src/db/schema.ts` — 27 tables. New tables only via new migration. | |
| 277 | - `src/db/index.ts` — lazy proxy DB connection | |
| 278 | - `src/db/migrate.ts` — migration runner | |
| 279 | - `drizzle/0000_initial.sql`, `drizzle/0001_green_ecosystem.sql` — migrations | |
| 058d752 | 280 | - `drizzle/0004_org_owned_repos.sql` (Block B2) — migration, never edited in place |
| 281 | - `drizzle/0005_totp_2fa.sql` (Block B4) — migration, never edited in place | |
| 282 | - `drizzle/0006_webauthn_passkeys.sql` (Block B5) — migration, never edited in place | |
| 283 | - `drizzle/0007_oauth_provider.sql` (Block B6) — migration, never edited in place | |
| 5e888b7 | 284 | - `drizzle/0008_workflows.sql` (Block C1) — migration, never edited in place |
| 25a91a6 | 285 | - `drizzle/0009_packages.sql` (Block C2) — migration, never edited in place |
| 286 | - `drizzle/0010_pages.sql` (Block C3) — migration, never edited in place | |
| 287 | - `drizzle/0011_environments.sql` (Block C4) — migration, never edited in place | |
| 3cbe3d6 | 288 | - `drizzle/0012_ai_native.sql` (Block D) — migration, never edited in place. Adds `codebase_explanations`, `dep_update_runs`, `code_chunks`. |
| 1e162a8 | 289 | - `drizzle/0013_discussions.sql` (Block E2) — migration, never edited in place. Adds `discussions`, `discussion_comments`. |
| 290 | - `drizzle/0014_gists.sql` (Block E4) — migration, never edited in place. Adds `gists`, `gist_files`, `gist_revisions`, `gist_stars`. | |
| 291 | - `drizzle/0015_projects.sql` (Block E1) — migration, never edited in place. Adds `projects`, `project_columns`, `project_items`. | |
| 292 | - `drizzle/0016_wikis.sql` (Block E3) — migration, never edited in place. Adds `wiki_pages`, `wiki_revisions`. | |
| 9ab6971 | 293 | |
| 294 | ### 4.2 Git layer (locked) | |
| 295 | - `src/git/repository.ts` — tree / blob / commits / diff / branches / blame / search / raw / tags / commitsBetween | |
| 296 | - `src/git/protocol.ts` — Smart HTTP pkt-line | |
| 297 | - `src/hooks/post-receive.ts` — CODEOWNERS sync, gates, auto-deploy, webhook fan-out | |
| 298 | ||
| 299 | ### 4.3 Auth + security (locked) | |
| 300 | - `src/lib/auth.ts` — bcrypt, session tokens | |
| 25a91a6 | 301 | - `src/middleware/auth.ts` — softAuth + requireAuth. Accepts three auth inputs: session cookie (web), OAuth access token (`glct_` prefix, Block B6), and personal access token (`glc_` prefix, Block C2). Invalid bearer → 401 JSON. Cookie flow → /login redirect. |
| 9ab6971 | 302 | - `src/middleware/rate-limit.ts` — fixed-window limiter |
| 303 | - `src/middleware/request-context.ts` — request-ID | |
| 304 | - `src/lib/security-scan.ts` — `SECRET_PATTERNS` (exported) + `scanForSecrets` + `aiSecurityScan` | |
| 058d752 | 305 | - `src/lib/codeowners.ts` — parser + `ownersForPath` (last-match-wins); team expansion helpers for `@org/team` (Block B3) |
| 306 | - `src/lib/totp.ts` (Block B4) — TOTP enroll / verify / recovery codes | |
| 307 | - `src/lib/webauthn.ts` (Block B5) — WebAuthn registration + assertion helpers | |
| 308 | - `src/lib/oauth.ts` (Block B6) — OAuth 2.0 provider: authorization code grant, token issuance, scope enforcement | |
| 5e888b7 | 309 | - `src/lib/workflow-parser.ts` (Block C1) — YAML subset parser for `.gluecron/workflows/*.yml`. Exports `parseWorkflow(src)` returning `{ ok, workflow | error }`. Never throws. |
| 310 | - `src/lib/workflow-runner.ts` (Block C1) — shell executor. Exports `executeRun`, `drainOneRun`, `enqueueRun`, `startWorker`. Clones repo to tmpdir, runs each job via `Bun.spawn(["bash","-c",step.run])` with SIGTERM→SIGKILL timeouts, size-capped stdout/stderr, cleans up in `finally`. | |
| 25a91a6 | 311 | - `src/lib/packages.ts` (Block C2) — npm protocol helpers: `parsePackageName`, `computeShasum` (sha1), `computeIntegrity` (sha512 base64), `buildPackument`, `resolveRepoFromPackageJson`, `parseRepoUrl`, `tarballFilename`. Pure functions. |
| 312 | - `src/lib/pages.ts` (Block C3) — `onPagesPush` (never throws), `resolvePagesPath` (probe list including pretty URLs + traversal strip), `contentTypeFor` (MIME). | |
| 313 | - `src/lib/environments.ts` (Block C4) — `matchGlob`, `listEnvironments`, `getOrCreateEnvironment`, `getEnvironmentByName`, `isReviewer`, `reviewerIdsOf`, `allowedBranchesOf`, `computeApprovalState`, `reduceApprovalState`, `recordApproval`, `requiresApprovalFor`. Empty reviewers list → repo owner approves. Any rejection hard-stops. | |
| 9ab6971 | 314 | |
| 315 | ### 4.4 AI layer (locked) | |
| 316 | - `src/lib/ai-client.ts` — Anthropic client + model constants | |
| 3cbe3d6 | 317 | - `src/lib/ai-generators.ts` — commit / PR / changelog / issue-triage / **pull-request-triage (D3)** |
| 9ab6971 | 318 | - `src/lib/ai-chat.ts` — conversational chat |
| 319 | - `src/lib/ai-review.ts` — PR code review | |
| 320 | - `src/lib/auto-repair.ts` — worktree-backed repair commits | |
| 321 | - `src/lib/merge-resolver.ts` — AI merge conflict resolution | |
| 3cbe3d6 | 322 | - `src/lib/ai-explain.ts` (Block D6) — `explainCodebase(...)` + `getCachedExplanation(...)`. Samples up to ~25 representative files (~60KB cap), Sonnet 4, upserts into `codebase_explanations`. Fallback to README-ish synthesis when no key. Never throws. |
| 323 | - `src/lib/ai-completion.ts` (Block D9) — `completeCode({prefix, suffix?, language?, maxTokens?, repoHint?})` via Haiku. Inline LRU (size 200, 5-min TTL) keyed on sha256 of prefix+suffix+language. Code-fence stripping. Never throws. `__test` bundle exposed. | |
| 324 | - `src/lib/dep-updater.ts` (Block D2) — `parseManifest`, `queryNpmLatest`, `planUpdates` (injectable `fetchLatest`), `applyBumps`, `runDepUpdateRun`. Creates `gluecron/dep-update-<ts>` branch via git plumbing + opens a PR row. Never throws. | |
| 325 | - `src/lib/semantic-search.ts` (Block D1) — `tokenize`, `hashEmbed` (512-dim L2-normalised FNV-1a + sign trick), `embedBatch` (Voyage `voyage-code-3` when `VOYAGE_API_KEY` set, else fallback), `chunkFile`, `isCodeFile`, `indexRepository`, `searchRepository`, `cosine`, `isEmbeddingsProviderAvailable`, `__test` bundle. | |
| 1e162a8 | 326 | - `src/lib/ai-incident.ts` (Block D4) — `onDeployFailure({deploymentId, reason, logs?})` and pure helper `summariseCommitsForIncident(commits)`. Sonnet 4 structured JSON RCA → opens `issues` row, attaches `incident` label if present, sets `deployments.blockedReason`. Never throws; deterministic fallback body when no API key. Wired from `post-receive.ts triggerCrontechDeploy` + `deployments.tsx retry-incident`. |
| 327 | - `src/lib/ai-tests.ts` (Block D8) — pure helpers `detectLanguage`, `detectTestFramework`, `buildTestsPrompt`, `suggestedTestPath`, `generateTestStub`, `contentTypeFor`. Returns `{code:"", framework:"fallback"}` on no API key. Never throws. | |
| 328 | - `src/lib/branch-protection.ts` (Block D5) — `matchProtection(repoId, branch)` (exact wins; deterministic glob sort), `evaluateProtection(rule, ctx)` (pure — checks `requireAiApproval | requireGreenGates | requireHumanReview | requiredApprovals`), `countHumanApprovals(prId)` (LGTM/+1/approved heuristic). Never throws. Enforcement is in `src/routes/pulls.tsx` merge handler, after existing hard-gate filter. | |
| 9ab6971 | 329 | |
| 330 | ### 4.5 Platform (locked) | |
| 24cf2ca | 331 | - `src/lib/notify.ts` — notification creation + audit log (swallow-failures pattern). Also fans out email to opted-in recipients for `mention|review_requested|assigned|gate_failed`. Exports `__internal` for tests. |
| 332 | - `src/lib/email.ts` — provider-pluggable email sender (`log`|`resend`). `sendEmail()` never throws. `absoluteUrl()` joins paths against `APP_BASE_URL`. | |
| 333 | - `src/lib/templates.ts` — `loadIssueTemplate` / `loadPrTemplate`. Checks standard paths (`.github/`, `.gluecron/`, root, `docs/`) on the default branch, strips YAML frontmatter, 16KB cap, returns null on any failure. | |
| 9ab6971 | 334 | - `src/lib/unread.ts` — unread count helper (never throws) |
| 335 | - `src/lib/repo-bootstrap.ts` — green defaults on repo creation | |
| 336 | - `src/lib/gate.ts` — gate orchestration + persistence | |
| 337 | - `src/lib/cache.ts` — LRU cache, git-cache invalidation | |
| 6fc53bd | 338 | - `src/lib/reactions.ts` — `summariseReactions`, `toggleReaction`, `ALLOWED_EMOJIS`, `EMOJI_GLYPH`, `isAllowedEmoji`, `isAllowedTarget` |
| 9ab6971 | 339 | |
| 340 | ### 4.6 Routes (locked endpoints — behaviour must be preserved) | |
| 341 | - `src/routes/git.ts` — Smart HTTP (clone/push) | |
| 342 | - `src/routes/api.ts` — REST (`POST /api/repos`, `GET /api/users/:u/repos`, `GET /api/repos/:o/:n`, `POST /api/setup`) | |
| ad6d4ad | 343 | - `src/routes/hooks.ts` — `POST /api/hooks/gatetest` (bearer/HMAC), `GET /api/hooks/ping`, `POST /api/v1/gate-runs` (PAT backup), `GET /api/v1/gate-runs`. See `GATETEST_HOOK.md`. |
| 6fc53bd | 344 | - `src/routes/theme.ts` — `GET /theme/toggle`, `GET /theme/set?mode=`. Writes `theme` cookie (`dark`|`light`, 1-year). Layout reads via pre-paint inline script. |
| 345 | - `src/routes/audit.tsx` — `GET /settings/audit` (personal) + `GET /:owner/:repo/settings/audit` (owner-only). | |
| 24cf2ca | 346 | - `src/routes/saved-replies.tsx` — `GET/POST /settings/replies`, `POST /settings/replies/:id`, `POST /settings/replies/:id/delete`, `GET /api/user/replies`. Unique constraint `saved_replies_user_shortcut`. |
| 347 | - `src/routes/deployments.tsx` — `GET /:owner/:repo/deployments` (grouped by env, success-rate rollup), `GET /:owner/:repo/deployments/:id` (detail). | |
| 6fc53bd | 348 | - `src/routes/reactions.ts` — `POST /api/reactions/:targetType/:targetId/:emoji/toggle` (authed, form- or fetch-compatible), `GET /api/reactions/:targetType/:targetId`. Targets: `issue|pr|issue_comment|pr_comment`. Emojis: 8 canonical. |
| 9ab6971 | 349 | - `src/routes/auth.tsx` — register / login / logout |
| 350 | - `src/routes/web.tsx` — home / new / browse / blob / commits / raw / blame / star / search / profile | |
| 351 | - `src/routes/issues.tsx` — issue CRUD + comments + labels + lock | |
| 352 | - `src/routes/pulls.tsx` — PR CRUD + review + merge + close | |
| 353 | - `src/routes/editor.tsx` — web file editor | |
| 354 | - `src/routes/compare.tsx` — base...head diff | |
| 24cf2ca | 355 | - `src/routes/settings.tsx` — profile + password + email notification preferences (`POST /settings/notifications`) |
| 9ab6971 | 356 | - `src/routes/repo-settings.tsx` — repo settings + delete |
| 357 | - `src/routes/webhooks.tsx` — webhook CRUD + test + `fireWebhooks` | |
| 358 | - `src/routes/fork.ts` — fork | |
| 359 | - `src/routes/explore.tsx` — discover | |
| 360 | - `src/routes/tokens.tsx` — personal access tokens | |
| 361 | - `src/routes/contributors.tsx` — contributor list | |
| 362 | - `src/routes/notifications.tsx` — inbox + unread API | |
| 363 | - `src/routes/dashboard.tsx` — authed home (`renderDashboard` exported) | |
| 364 | - `src/routes/ask.tsx` — global + repo AI chat + explain | |
| 365 | - `src/routes/releases.tsx` — tags + AI changelog | |
| 366 | - `src/routes/gates.tsx` — history + settings + branch protection UI | |
| 367 | - `src/routes/insights.tsx` — insights + milestones | |
| 368 | - `src/routes/search.tsx` — global search + `/shortcuts` | |
| 369 | - `src/routes/health.ts` — `/healthz` `/readyz` `/metrics` | |
| 6563f0a | 370 | - `src/routes/orgs.tsx` — `/orgs` list, `/orgs/new` create, `/orgs/:slug` profile, `/orgs/:slug/people` + add/role/remove, `/orgs/:slug/teams` + create, `/orgs/:slug/teams/:teamSlug` + member add/remove. All require auth. Role guards via `orgRoleAtLeast`; last-owner cannot be demoted or removed; every write path `audit()`'d. |
| 058d752 | 371 | - `src/lib/orgs.ts` (Block B1) — `isValidSlug` (rejects reserved + too-short/long + consecutive/leading/trailing hyphens), `normalizeSlug`, `orgRoleAtLeast` (owner>admin>member), `isValidOrgRole`, `isValidTeamRole`, `loadOrgForUser`, `listOrgsForUser`, `listOrgMembers`, `listTeamsForOrg`, `listTeamMembers`, `__test` export for unit tests. |
| 372 | - `src/routes/settings-2fa.tsx` (Block B4) — TOTP enroll / verify / disable + recovery codes UI. All require auth. | |
| 373 | - `src/routes/passkeys.tsx` (Block B5) — WebAuthn passkey registration / assertion / management. All require auth. | |
| 374 | - `src/routes/oauth.tsx` (Block B6) — OAuth 2.0 authorize + token + userinfo endpoints. | |
| 375 | - `src/routes/developer-apps.tsx` (Block B6) — developer-facing OAuth app CRUD (`/settings/developer/apps`), client secret rotation, audit-logged. | |
| 5e888b7 | 376 | - `src/routes/workflows.tsx` (Block C1) — Actions UI. `GET /:owner/:repo/actions`, `GET /:owner/:repo/actions/runs/:runId`, `POST /:owner/:repo/actions/:workflowId/run` (auth+owner), `POST /:owner/:repo/actions/runs/:runId/cancel` (auth+owner). Manual runs are `event=manual`, ref=default branch. |
| 25a91a6 | 377 | - `src/routes/packages-api.ts` (Block C2) — npm protocol: `GET/PUT/DELETE /npm/*` (packument, tarball, publish, yank); JSON helpers at `/api/packages/:owner/:repo/...`. PAT (`glc_`) bearer auth. |
| 378 | - `src/routes/packages.tsx` (Block C2) — UI: `/:owner/:repo/packages` list + `/:owner/:repo/packages/:pkgName` detail. | |
| 379 | - `src/routes/pages.tsx` (Block C3) — `GET /:owner/:repo/pages/*` serves static files from latest gh-pages commit (binary via `getRawBlob`, text via `getBlob`). `GET/POST /:owner/:repo/settings/pages` settings + redeploy. | |
| 380 | - `src/routes/environments.tsx` (Block C4) — settings CRUD at `/:owner/:repo/settings/environments`; approval endpoints at `/:owner/:repo/deployments/:id/{approve,reject}`. | |
| 3cbe3d6 | 381 | - `src/routes/ai-explain.tsx` (Block D6) — `GET /:owner/:repo/explain` (softAuth), `POST /:owner/:repo/explain/regenerate` (requireAuth, owner-only). |
| 382 | - `src/routes/ai-changelog.tsx` (Block D7) — `GET /:owner/:repo/ai/changelog` (softAuth). Form + rendered output; `?format=markdown` returns `text/markdown`. | |
| 383 | - `src/routes/copilot.ts` (Block D9) — `POST /api/copilot/completions` (requireAuth, 60/min rate limit), `GET /api/copilot/ping` (public). | |
| 384 | - `src/routes/dep-updater.tsx` (Block D2) — `GET /:owner/:repo/settings/dep-updater` + `POST /:owner/:repo/settings/dep-updater/run` (requireAuth, owner-only). | |
| 385 | - `src/routes/semantic-search.tsx` (Block D1) — `GET /:owner/:repo/search/semantic?q=` (softAuth) + `POST /:owner/:repo/search/semantic/reindex` (requireAuth, owner-only). | |
| 1e162a8 | 386 | - `src/routes/ai-tests.tsx` (Block D8) — `GET /:owner/:repo/ai/tests` (softAuth form + picker), `GET /:owner/:repo/ai/tests?format=raw` (raw text w/ MIME), `POST /:owner/:repo/ai/tests/generate` (requireAuth, renders highlighted source + AI-generated failing test with copy button). |
| 387 | - `src/routes/discussions.tsx` (Block E2) — full discussion CRUD + categories + q-and-a answers + lock/pin. Exports `isValidCategory(c)` helper. Owner-only lock/pin; owner-or-author can close/toggle. | |
| 388 | - `src/routes/gists.tsx` (Block E4) — `GET /gists` discover, `/gists/new|:slug|:slug/edit|:slug/delete|:slug/star|:slug/revisions|:slug/revisions/:rev` + `/:username/gists`. Exports `generateSlug()` (8-hex) and `snapshotOf(files)` JSON serializer. Retries on slug collision up to 5x. | |
| 389 | - `src/routes/projects.tsx` (Block E1) — kanban board CRUD. Auto-seeds three default columns on project create. `/:owner/:repo/projects/:number/items/:itemId/move` recomputes position via `max+1` of target column. | |
| 390 | - `src/routes/wikis.tsx` (Block E3) — DB-backed wiki with revision history + revert. Exports `slugifyTitle(title)` (lowercase alphanumerics joined by single dashes, trimmed). Every edit appends a `wiki_revisions` row; revert creates a new revision. | |
| 9ab6971 | 391 | |
| 392 | ### 4.7 Views (locked contracts) | |
| 393 | - `src/views/layout.tsx` — `Layout` accepts `title`, `user`, `notificationCount` | |
| 3cbe3d6 | 394 | - `src/views/components.tsx` — `RepoHeader`, `RepoNav` (active: `code|issues|pulls|commits|releases|actions|gates|insights|explain|changelog|semantic`), `RepoCard`, etc. |
| 6fc53bd | 395 | - `src/views/reactions.tsx` — `ReactionsBar` (no-JS compatible, form-per-emoji) |
| 396 | - Nav links: logo · search · theme-toggle · Explore · Ask · Notifications · New · Profile (or Sign in / Register) | |
| 9ab6971 | 397 | - Keyboard chords: `/`, `Cmd+K`, `?`, `n`, `g d`, `g n`, `g e`, `g a` |
| 398 | ||
| 399 | ### 4.8 Tests (locked) | |
| 400 | - `src/__tests__/green-ecosystem.test.ts` — secret scanner, codeowners, AI fallback, health, rate-limit headers, `/shortcuts`, `/search` | |
| 401 | - All other existing test files — do not delete without owner permission | |
| 402 | ||
| 403 | ### 4.9 Invariants (never break these) | |
| 404 | - `isAiAvailable()` guard returns true fallback strings when no ANTHROPIC_API_KEY. AI features degrade gracefully. | |
| 405 | - `getUnreadCount` never throws; returns 0 on any error. | |
| 406 | - Rate-limit middleware adds `X-RateLimit-Limit` + `X-RateLimit-Remaining` to every response, including 500s. | |
| 407 | - `c.header("X-Request-Id", ...)` set by request-context on every response. | |
| 408 | - Secret scanner skips binary/lock paths (`shouldSkipPath`). | |
| 409 | - `SECRET_PATTERNS` is an exported array. Its shape is `{ type, regex, severity }`. | |
| 6fc53bd | 410 | - Theme routes live outside `/settings/*` (they must work for logged-out visitors). Cookie name: `theme`, values: `dark|light`. |
| 411 | - Draft PRs cannot be merged — `/pulls/:n/merge` returns a redirect with the draft error when `pr.isDraft=true`. | |
| 412 | - Reactions API accepts only `ALLOWED_EMOJIS` and `ALLOWED_TARGETS`. Toggle is idempotent per (user, target, emoji). | |
| 24cf2ca | 413 | - `sendEmail()` never throws — always resolves to `{ ok, provider, ... }`. Email failures never break notification delivery or the primary request path. |
| 414 | - Email fan-out in `notify()` is scoped to kinds in `EMAIL_ELIGIBLE` (mention / review_requested / assigned / gate_failed). Each eligible kind maps to exactly one user preference column. | |
| 415 | - Issue + PR template loading must return `null` on any git-subprocess failure (templates are a convenience, not a requirement). Forms always render. | |
| 9ab6971 | 416 | |
| 417 | --- | |
| 418 | ||
| 419 | ## 5. OPERATIONAL NOTES | |
| 420 | ||
| 421 | ### 5.1 Running locally | |
| 422 | ```bash | |
| 423 | bun install | |
| 424 | bun dev # hot reload | |
| 24cf2ca | 425 | bun test # 99 tests currently pass |
| 9ab6971 | 426 | bun run db:migrate |
| 427 | ``` | |
| 428 | ||
| 429 | ### 5.2 Environment | |
| 430 | - `DATABASE_URL` — Neon Postgres | |
| 431 | - `ANTHROPIC_API_KEY` — unlocks AI features | |
| 432 | - `GIT_REPOS_PATH` — default `./repos` | |
| 433 | - `PORT` — default 3000 | |
| 24cf2ca | 434 | - `EMAIL_PROVIDER` — `log` (default, stderr-only) or `resend` |
| 435 | - `EMAIL_FROM` — sender address for outbound mail | |
| 436 | - `RESEND_API_KEY` — required when `EMAIL_PROVIDER=resend` | |
| 437 | - `APP_BASE_URL` — canonical URL used to build absolute links in emails | |
| 3cbe3d6 | 438 | - `VOYAGE_API_KEY` — optional; when set, D1 semantic search uses Voyage `voyage-code-3` embeddings. Otherwise falls back to a deterministic 512-dim hashing embedder. |
| 9ab6971 | 439 | |
| 440 | ### 5.3 Models | |
| 441 | - `claude-sonnet-4-20250514` — code review, security, chat | |
| 442 | - `claude-haiku-4-5-20251001` — commit messages, summaries, light tasks | |
| 443 | - Swap via `MODEL_SONNET` / `MODEL_HAIKU` constants in `src/lib/ai-client.ts` | |
| 444 | ||
| 445 | ### 5.4 Deployment | |
| 446 | - `railway.toml` / `fly.toml` present | |
| 447 | - Crontech deploy on green push to default branch (can opt out via `autoDeployEnabled`) | |
| 448 | ||
| 449 | --- | |
| 450 | ||
| 451 | ## 6. SESSION WORKFLOW (WHAT THE NEXT AGENT DOES) | |
| 452 | ||
| 453 | 1. Read this file, `CLAUDE.md`, `README.md`, `git log -1 --stat`. | |
| 454 | 2. Check `git status` + current branch. | |
| 455 | 3. Pick the next unfinished block from §3 (lowest letter + number first, unless owner specifies). | |
| 456 | 4. Create a todo list that mirrors the sub-items of that block. | |
| 457 | 5. Build. Write tests. Run `bun test`. | |
| 458 | 6. Commit with `feat(<BLOCK-ID>): ...`. | |
| 459 | 7. Push. | |
| 460 | 8. Update this file: | |
| 461 | - Move the block's row in §2 to ✅ where applicable. | |
| 462 | - Add the block's files to §4 LOCKED BLOCKS. | |
| 463 | - Commit + push again. | |
| 464 | 9. Start the next block. **Do not stop to ask.** | |
| 465 | ||
| 466 | If a block is too large for a single session, split it into a sub-plan at the top of the session, ship what you can, and document what's left at the end of this file under a `## 7. IN-FLIGHT` section. | |
| 467 | ||
| 468 | --- | |
| 469 | ||
| 470 | ## 7. IN-FLIGHT | |
| 471 | ||
| 472 | (Intentionally empty. Add here if a block is partially complete at session end.) |