Knowledge Base — task checklist
Status: Draft
Last updated: 2026-05-21
Audience: Engineers picking up tickets from the JIRA Epic. This is the granular work breakdown that feeds JIRA sub-tasks under each phase ticket.
See spec.md for the technical contract, plan.md for the phasing rationale, and acceptance.md for the gate conditions.
Phase 1A — data model + service skeleton + REST CRUD (one PR)
Entities
-
packages/agent/src/entities/work-knowledge-document.entity.ts— full column set per spec §6.1 -
packages/agent/src/entities/work-knowledge-upload.entity.ts— per spec §6.2 -
packages/agent/src/entities/work-knowledge-tag.entity.ts— per spec §6.3 -
packages/agent/src/entities/work-knowledge-citation.entity.ts— per spec §6.4 -
packages/agent/src/entities/work-knowledge-chunk.entity.ts— composite PK(workId, id)per spec §15.2 D8 - Add new entities to the
ENTITIESregistry in the platform's database module - Add
kbConfigsimple-json column toWorkentity per spec §6.5
Migrations (apps/api/src/migrations/)
-
<ts>-EnablePgvectorExtension.ts— idempotentCREATE EXTENSION IF NOT EXISTS vector; -
<ts>-CreateWorkKnowledgeDocuments.ts— table +workId XOR organizationIdCHECK constraint + indexes -
<ts>-CreateWorkKnowledgeUploads.ts— table + sha256 dedup index -
<ts>-CreateWorkKnowledgeTags.ts -
<ts>-CreateWorkKnowledgeCitations.ts— append-only, no update path -
<ts>-CreateWorkKnowledgeChunks.ts— composite PK + ivfflat index on(workId, embedding) -
<ts>-AddWorkKbConfigColumn.ts - Each migration includes its
down()revert - Generate migrations via
pnpm typeorm migration:generatefromapps/api/, read the SQL before committing (per workspace NN #16)
DTOs (packages/contracts/src/kb/)
-
kb-document.dto.ts—KbDocumentDto,KbDocumentBodyDto -
kb-upload.dto.ts—KbUploadDto -
kb-search.dto.ts—KbSearchHit -
kb-tree.dto.ts—KbTreeNode -
citation.dto.ts—CitationDto -
kb-document-class.ts— union type with the ten class values - Barrel export from
packages/contracts/src/index.ts
Service skeleton (packages/agent/src/services/knowledge-base.service.ts)
- NestJS
@Injectable()class - Repository injection for all five entities
- Method stubs with JSDoc only (no bodies):
-
resolveDocuments(workId, filter): Promise<KbDocumentDto[]> -
getDocument(workId, idOrPath): Promise<KbDocumentBodyDto> -
createDocument(workId, input): Promise<KbDocumentBodyDto> -
updateDocument(workId, docId, patch): Promise<KbDocumentBodyDto> -
deleteDocument(workId, docId): Promise<void> -
lockDocument(workId, docId, mode): Promise<KbDocumentBodyDto> -
unlockDocument(workId, docId): Promise<KbDocumentBodyDto> -
restoreDocument(workId, docId, commitSha): Promise<KbDocumentBodyDto> -
ingestUpload(workId, file, opts): Promise<KbUploadDto>(placeholder) -
search(workId, query, filter): Promise<KbSearchHit[]>(lexical only in Phase 1) -
resolveContext(workId, opts): Promise<KbContextBundle>(stub — populated in Phase 2) -
rebuildIndex(workId): Promise<void> -
resolveInheritableDocuments(workId, classes?)— for org overlay
-
- Module wiring in
packages/agent/src/services/services.module.ts(or whatever the existing convention is)
REST endpoints (apps/api/src/works/)
- Extend
WorksControllerwith the KB route set per spec §12 - Validation pipes (class-validator on input DTOs)
-
WorkMemberGuardfor read endpoints (Viewer+), Editor+ for writes, Owner for lock/unlock/restore - OpenAPI / Swagger annotations on each route
- Map service errors → HTTP responses via existing exception filter
Org-level admin endpoints
-
apps/api/src/organizations/controller additions:-
GET /api/organizations/:orgId/kb/documents?class=… -
POST /api/organizations/:orgId/kb/documents -
PATCH /api/organizations/:orgId/kb/documents/:docId -
DELETE /api/organizations/:orgId/kb/documents/:docId
-
- Restrict POST/PATCH
classtolegal | style | seowith 400 on violation - OrganizationAdminGuard for all four
- Service stub for
resolveInheritableDocuments— actual fan-out lands in Phase 2
Tests (Phase 1A scope)
- Entity unit tests in
packages/agent/test/entities/— one file per new entity:- CHECK constraint behavior (insert both workId + organizationId → reject; insert neither → reject)
- Cascade-delete behavior on parent removal
- simple-json column round-trip
- Service unit tests for
resolveContextbudget truncation logic with mocked repos - API e2e test (
apps/api/test/) for the document CRUD lifecycle
Backfill (Trigger.dev or one-time CLI task)
-
packages/tasks/job that iterates existing Works and writes an empty.content/kb/skeleton via the configuredgithub-storageplugin - Idempotent; safe to re-run
- Sets
Work.kbConfigto platform defaults if absent
Documentation
- New section in
docs/specs/architecture/database.md: "## N. Knowledge Base Entities" describing the five entities + the inheritance pattern + pgvector dependency - Link the new section back from the spec
- Update
docs/specs/architecture/database-migrations.mdif it has an examples list (mention the pgvector enable migration as the canonical "extension enable" pattern) - PR description references the JIRA Epic + spec URL
Phase 1B — workbench MVP + ingest pipeline (separate PR)
- Workbench page route at
apps/web/src/app/[locale]/(dashboard)/works/[id]/kb/page.tsx - Nested editor route
apps/web/src/app/[locale]/(dashboard)/works/[id]/kb/[...path]/page.tsx - Tree panel (KB / Originals tab toggle)
- Tiptap editor wired to the existing settings (locale, theme)
- Inline viewers: PDF.js (PDFs), native
<video>/<audio>, image viewer - DOCX/PPTX/XLSX viewers behind dynamic imports + per-format size caps from spec §14.5
- Drag-and-drop upload with classification modal
- Ingest pipeline (Trigger.dev jobs in
packages/tasks/):- Receive job (already partially covered by upload API)
- Normalize job (skip when format is "kept as-is"; only video/audio normalize)
- Extract job (calls configured content-extractor plugins)
- Materialize job (writes sidecar
.yml+.mdto Git data repo via configured Git provider) - Index job (rebuild
.index.yml+ Postgrestsvectorfor FTS)
- Activity log emits the kinds listed in spec §19.1
- Per-document lock UI (file menu in tree + lock state chip in document header)
- Search palette wired to lexical-only
/api/works/:id/kb/search
Phase 2 — agent integration + retrieval
- Plugin contract: optional
embed(input)capability inpackages/plugin/src/contracts/capabilities/ai-provider.interface.ts - Implement
embedinpackages/plugins/openai/ - Trigger.dev job: chunk + embed on document insert/update + delete cascade to chunks
- Hybrid chunker in
packages/agent/src/services/kb-chunker.ts(heading-aware + fixed-size fallback) -
KnowledgeBaseService.searchblends lexical + semantic via RRF -
KbPromptFormatterinpackages/agent/src/services/kb-prompt-formatter.ts -
KbContextBundleplumbed into every pipeline plugin's invocation signature - Pipeline integration tests with fixture KB documents
- AI conversation:
@kb:<path-or-id>parser + autocomplete + citation marker resolver - Citation hover-card component (workbench-side)
- Agent tools:
kb_search,kb_read,kb_write,kb_lock,kb_unlockregistered to agent-pipelines - Org-level inheritance fan-out:
- Trigger.dev job that materializes
.org/{class}/overlay into every Work in the org - Triggered on POST/PATCH/DELETE of org-level inheritable docs
- Workbench surfaces inherited docs as read-only with an "override locally" affordance
- Trigger.dev job that materializes
- Community PR + scheduled regen consult
lockedandlockModebefore mutating any KB doc - Comparison generator reads
competitorsandresearchclasses automatically - LLM eval suite (
vitest.eval.config.tsstyle) for retrieval-quality regression - Budget integration:
kb-embeddingcategory inUsageLedgerEntry
Phase 3 — polish
- Video → MP4 normalization via ffmpeg (Trigger.dev job)
- Audio → MP3 normalization via ffmpeg
- Plugin contract: optional
transcribe(file)capability - Implement
transcribeinopenai(Whisper) andanthropicplugins - Embedded-app output rendering (HTML decks / dashboards inside
outputs/<slug>/folders) -
output-class agent writes — "promote conversation response to KB" action - MCP namespace
kb.*inapps/mcp/(list / read / search / create / update / upload) - CLI subcommand group
ever works kb {list, show, upload, edit, search, sync}inapps/cli/ - Wikilink resolver + rename-aware reference rewriter
- Reconciliation job: daily Git ↔ DB diff,
kb.lock.violationsurfacing, orphan-storage detection with 7-day grace per spec §9.6 - Sweeper telemetry events emitted to PostHog
- All PostHog event kinds from spec §23 wired
Cross-cutting
- Permissions matrix verified against
WorkMemberGuardfor every new endpoint (spec §20) - Quotas enforced at service layer (spec §21)
- No KB body content in webhooks, telemetry, or activity-log payloads (spec §22)
- Markdownlint / prettier / lint / typecheck clean on every PR
- PR review loop completed per workspace NN #14 / #18 / #19 — bots triaged before merge