git:20260715.11fbfbe to git:20260716.91f140b
2 added, 2 removed. Audit A to A.
# DOX — packages/kb-plugin/src/server
Files in this directory. One row per source file. See change: add-kb-folder-slot.
| File | Purpose |
|------|---------|
- | `index.ts` | Server entry `registerPlugin`. Mounts `/api/kb/*` routes via `mountKbRoutes`. Consumes host service `host.knownFolderCwds` for cwd validation; falls back to session cwds. See change: add-kb-folder-slot. |
+ | `index.ts` | Server entry `registerPlugin`. Mounts `/api/kb/*` routes via `mountKbRoutes`. Consumes host service `host.knownFolderCwds` for cwd validation; falls back to session cwds. See change: add-kb-folder-slot. Registers a `plugin_action` handler: `reindex` → `registry.start(cwd,()=>reindexAll(cwd))`; `config.set` → `applyConfigPatch(cwd,patch)` (+ optional reindex); both guarded by `isAllowedCwd` (same allow-list as routes), dispatching the SAME cores (no HTTP re-entry). See change: fix-plugin-action-fanout-and-handlers. |
| `job-registry.ts` | `KbJobRegistry`. Per-cwd reindex coalescing. `start` sets running synchronously; concurrent start coalesced onto in-flight promise. `statusFor` → `idle|running|error`. Failed job retains `error`; later success clears to idle. See change: add-kb-folder-slot. |
- | `kb-routes.ts` | `mountKbRoutes(fastify, {knownCwds, registry})`. Routes GET `/api/kb/stats`, POST `/api/kb/reindex`, GET/PUT `/api/kb/config`. Reuses `loadConfig`/`SqliteFtsStore`/`indexSource`/`validateConfig`. Validates cwd ∈ knownCwds (403 else, 400 missing); `canonPath` realpath-canonicalizes BOTH sides (symlink match); `worktreeMainPath` git-derives a worktree's main repo so a session-less worktree of a known repo is admitted. `countStale` reads `dox-staleness.json` (source-file drift only). `applyConfigPatch` merges path fields over project file, validateConfig then atomic tmp+rename write; sparse merged object persisted (untouched fields round-trip). Reindex session-less (no pi session). POST reindex NON-BLOCKING: registers job, attaches `promise.catch(fastify.log.error)` synchronously, returns `202 {status:"running",jobId}` immediately (never awaits walk / no 500 body); walk failure surfaces via `/stats` `jobStatus:"error"`+`lastError`. See change: add-kb-folder-slot; fix-kb-index-feedback; fix-kb-worktree-cwd-guard. |
+ | `kb-routes.ts` | `mountKbRoutes(fastify, {knownCwds, registry})`. Routes GET `/api/kb/stats`, POST `/api/kb/reindex`, GET/PUT `/api/kb/config`. Reuses `loadConfig`/`SqliteFtsStore`/`indexSource`/`validateConfig`. Validates cwd ∈ knownCwds (403 else, 400 missing); `canonPath` realpath-canonicalizes BOTH sides (symlink match); `worktreeMainPath` git-derives a worktree's main repo so a session-less worktree of a known repo is admitted. `countStale` reads `dox-staleness.json` (source-file drift only). `applyConfigPatch` merges path fields over project file, validateConfig then atomic tmp+rename write; sparse merged object persisted (untouched fields round-trip). Reindex session-less (no pi session). POST reindex NON-BLOCKING: registers job, attaches `promise.catch(fastify.log.error)` synchronously, returns `202 {status:"running",jobId}` immediately (never awaits walk / no 500 body); walk failure surfaces via `/stats` `jobStatus:"error"`+`lastError`. Exports `isAllowedCwd(cwd,known)` (pure cwd guard, refactored out of `rejectCwd`), `reindexAll`, `applyConfigPatch`, `projectConfigPath` for reuse by the plugin_action handler. See change: add-kb-folder-slot; fix-kb-index-feedback; fix-kb-worktree-cwd-guard; fix-plugin-action-fanout-and-handlers. |