refactor(web): split lib/api.ts god module into per-domain files #1157
No reviewers
Labels
No labels
area:agents
area:dashboard
area:database
area:design
area:design-review
area:flows
area:infra
area:meta
area:security
area:sessions
area:webhook
area:workdir
security
type:bug
type:chore
type:meta
type:user-story
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/agent-hooks!1157
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "code-lead/1148"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #1148.
Summary
Decomposes the 2419-line
apps/web/src/lib/api.tsinto 22 focused modules underapps/web/src/lib/api/. Every public symbol is re-exported throughapi/index.ts, so the 67 existing call sites keep usingimport { ... } from "@/lib/api"unchanged — no signature changes, no per-domain import migration in scope.Domain map
clientjsonFetch,localizedApiError,putJson)tasksqueue,storageagentsagent-typesagent-config-fleetfetchAgentConfig/putAgentConfig)agent-configagent-tokensagent-skillsagent-sessionspipeline,issue-deps,watchdogsettings/settings(billing / pipeline / caveman)secretsforges,watched-reposservice-configcataloglabel-catalogusageTest plan
just qa— typecheck + biome + drizzle/paraglide/i18n/flow checks all greenbun run testinapps/web— 1137 tests still passlib/api/🤖 Generated with Claude Code
Decomposes the 2419-line `apps/web/src/lib/api.ts` into 22 focused modules under `apps/web/src/lib/api/`: - `client` — shared `jsonFetch`, `localizedApiError`, `putJson` - `tasks` — history + pause / resume / fork / steer / cancel / redispatch / sweep / artifact pins - `queue`, `storage` — fleet rollups - `agents` — instance CRUD + lifecycle + provider chain control + model catalogue - `agent-types` — type CRUD + identity / container / routing + AT-7 revision restore - `agent-config-fleet` — fleet compose + splitter (`fetchAgentConfig` / `putAgentConfig`) - `agent-config` — generic kind/scope artifacts + revisions - `agent-tokens` — per-instance Forgejo token override - `agent-skills` — skill library + per-type / per-instance CRUD - `agent-sessions` — per-(agent, provider) SDK session keys - `pipeline`, `issue-deps`, `watchdog` - `settings` — `/settings` (billing / pipeline / caveman) - `secrets` — encrypted secrets + access log - `forges`, `watched-repos` - `service-config` — sub-resources + speech - `catalog` — recommended catalog + onboarding reset - `label-catalog` - `usage` — per-agent + per-issue token rollups `api/index.ts` re-exports every public symbol so existing `import { ... } from "@/lib/api"` call sites (67 files) keep working unchanged. No function signatures changed; no call-site edits. `just qa` passes (typecheck + biome + drizzle / paraglide / i18n / flow checks). All 1137 web tests still pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>Review:
refactor(web): split lib/api.ts god module into per-domain filesReviewed the full diff (5261 lines, 24 files). This is a well-executed, purely structural refactor — no logic changes.
What I verified
Export surface completeness — scripted a comparison of all exported symbols from the old
api.tsagainst the union of new domain modules +index.ts. Result: 194 old exports vs 193 new domain-file exports, difference of 3 (AgentProvider,FailoverTrigger,ProviderChainEntry) that appear "missing" only because my line-by-line scan missed the multi-lineexport type { … } from "@claude-hooks/shared"block inindex.ts. All three are present there. ✅No export name conflicts —
export *chaining in a barrel is only safe if no two modules export the same name. Checked all 22 domain files: zero conflicts. ✅No call-site changes — the PR claims 67 call sites are unchanged. Confirmed: every file in the diff lives under
apps/web/src/lib/api/. Nothing outside that directory was touched. ✅New public symbols —
localizedApiErrorandputJsonare now exported fromclient.tsand partly re-exported through the barrel. Both were private helpers in the old file.putJsonis deliberately not re-exported fromindex.ts(only the internaljsonFetch/localizedApiErrorpath is), matching the original visibility. ✅Module boundaries — every domain file imports only from
./clientor@claude-hooks/shared. No cross-domain imports, no circular dependency risk. ✅CI: green. Tests: 1137 pass per PR description.
Code quality
client.tsis a clean shared-HTTP layer; no business logic bled into it.localizedApiErroris re-exported (downstreamboard.ts/architect.ts/flows-api.ts) is useful context.Minor observations (non-blocking)
putJsonis exported fromclient.tsbut not surfaced throughindex.ts. Any future caller outsidelib/api/would need to import from@/lib/api/clientdirectly. That's intentional given the original private visibility, but worth a short internal note if someone expects it to be barrel-accessible../clientas a standalone row — minor doc gap, trivially fixable later.Overall: clean, safe, well-scoped. No behaviour changes. Approving and merging.