Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements US-001 from PRD.
Changes:
- Add getProjectKnowledgePath(owner, repo) returning ~/.archon/workspaces/{owner}/{repo}/knowledge/
- Add getGlobalKnowledgePath() returning ~/.archon/knowledge/
- Add getKnowledgeLogsPath(owner, repo) returning .../knowledge/logs/
- Add getKnowledgeDomainsPath(owner, repo) returning .../knowledge/domains/
- Export all new functions from packages/paths/src/index.ts
- Add tests for all four functions
Implements US-002 from PRD. Changes: - Add KnowledgeConfig interface with enabled, captureModel, compileModel, flushDebounceMinutes, domains fields - Add knowledge?: KnowledgeConfig to GlobalConfig and RepoConfig interfaces - Add knowledge field to MergedConfig with Required<KnowledgeConfig> defaults - Add merge logic in mergeGlobalConfig and mergeRepoConfig (repo overrides global)
Implements US-003 from PRD. Changes: - Add initKnowledgeDir(owner, repo) for project KB directory tree creation - Add initGlobalKnowledgeDir() for global KB directory tree creation - Both functions create knowledge/, meta/, logs/, domains/, and 5 default domain subdirs - Functions are idempotent using mkdir recursive: true - Add tests for both functions with 6 test cases - Add knowledge-init test batch to core package test script
Implements US-004 from PRD. Changes: - Add schema.md template describing KB structure, navigation, and conventions - Add index.md template with domain sections and [[wikilink]] navigation - Add domain _index.md templates for all 5 starting domains - Extend initKnowledgeDir()/initGlobalKnowledgeDir() to write templates using 'wx' flag (skip if exists) - Add tests for template writing, EEXIST handling, and error propagation
Implements US-005 from PRD. Changes: - New knowledge-capture.ts service with captureKnowledge() function - Reads conversation transcript via listMessages() from DB - Calls Haiku model via IAssistantClient to extract structured knowledge - Appends extracted knowledge to knowledge/logs/YYYY-MM-DD.md daily log - Respects knowledge.enabled config (skip if false) - Logs capture events: capture_started, capture_completed, capture_failed - 12 tests covering all acceptance criteria - Added knowledge-capture.test.ts as separate test batch
Implements US-007 from PRD. Changes: - Made buildOrchestratorPrompt() and buildProjectScopedPrompt() async to support loading knowledge index files - Added loadKnowledgeIndex() helper with ENOENT handling and ~500 token budget truncation - Added formatKnowledgeSection() for combining global and project knowledge indexes - Updated buildFullPrompt() in orchestrator-agent.ts to await async prompt builders - Added 13 tests covering knowledge loading, truncation, graceful skip, and precedence - Added prompt-builder-knowledge.test.ts as separate test batch in package.json
Implements US-006 from PRD. Changes: - Add triggerCapture() fire-and-forget helper to knowledge-capture.ts - Wire capture into onConversationClosed() in cleanup-service.ts - Wire capture into /reset command in command-handler.ts - Add tests for both trigger points in respective test files
Implements US-008 from PRD. Changes: - Add loadUnprocessedLogs() to prompt-builder.ts that reads daily logs newer than last-flush.json - Add readdir import and KNOWLEDGE_LOGS_MAX_CHARS constant for ~2000 token budget - Extend formatKnowledgeSection() with optional unprocessedLogs parameter - Wire unprocessed logs into both buildOrchestratorPrompt and buildProjectScopedPrompt - Add 6 new tests covering: all logs when no flush, filtered logs after flush, truncation, empty state, ordering, global fallback
Implements US-009 from PRD.
Changes:
- Create flushKnowledge(owner, repo) function in knowledge-flush.ts
- Read unprocessed daily logs since meta/last-flush.json timestamp
- Call Sonnet model via IAssistantClient to synthesize logs into domain articles
- Create/update concept articles in domains/{domain}/{concept}.md
- Update domain _index.md files and top-level index.md with summaries
- Update meta/last-flush.json with new timestamp after flush
- Support organic domain creation beyond starting set
- Articles use standard markdown with [[wikilink]] backlinks
- Log flush events: knowledge.flush_started, _completed, _failed
- Add 17 tests covering all acceptance criteria
Implements US-010 from PRD. Changes: - Add file-based lock at knowledge/meta/flush.lock with PID - Acquire lock before flush, release in finally block (even on error) - Skip with warning if lock held by another live process - Reclaim stale locks from dead processes (process.kill(pid, 0)) - Write articles to .tmp/ dir first, then atomic rename to final paths - Update last-flush.json via temp+rename for crash safety - Clean up leftover .tmp/ from previous crashed flushes - Add 8 new tests covering lock lifecycle, atomicity, and crash recovery
Implements US-011 from PRD. Changes: - Add validateStaleness() that runs Haiku model against git diff to detect stale articles - Add checkBrokenWikilinks() to detect broken [[wikilink]] cross-references - Add addStalenessMarker() for idempotent staleness warnings on flagged articles - Update updateLastFlush() to store actual git SHA via git rev-parse HEAD - Add getCurrentGitSha() and getGitDiffNameOnly() git helpers using execFileAsync - Integrate validation step into flush pipeline after article synthesis - Add 6 new tests covering staleness detection, wikilink checking, git SHA storage
Implements US-012 from PRD. Changes: - Create knowledge-scheduler.ts with per-project debounced flush scheduling - Wire scheduleFlush into triggerCapture (fires after successful capture) - Timer resets on subsequent captures within debounce window - Uses knowledge.flushDebounceMinutes from config (default 10 min) - Timers unref'd to avoid keeping process alive - Add cancelScheduledFlush, isFlushScheduled, cancelAllScheduledFlushes helpers - Add knowledge-scheduler.test.ts with 7 tests (22 expects) - Add test batch to package.json
Implements US-013 from PRD. Changes: - Refactored flushKnowledge() to use shared flushKnowledgeCore() with FlushCoreOptions - Added flushGlobalKnowledge() operating on ~/.archon/knowledge/ path - Global flush skips git-based staleness validation (no associated repo) - Added scheduleGlobalFlush() for debounced global flush scheduling - Updated updateLastFlush() to accept optional owner/repo (empty git SHA for global) - Added 8 new tests covering global flush, staleness skip, independence, and scheduling
Implements US-014 from PRD. Changes: - Add packages/cli/src/commands/knowledge.ts with knowledgeFlushCommand() - Add --project owner/repo flag with git remote fallback for project resolution - Display flush results (articles created/updated/stale, domains, logs processed) - Respect --quiet flag for suppressed output - Register knowledge command in cli.ts with help text - Add 8 tests covering all acceptance criteria
Implements US-015 from PRD. Changes: - Add knowledgeStatusCommand() to packages/cli/src/commands/knowledge.ts - Add gatherKBStats() for pure filesystem inspection of KB directories - Register `knowledge status` subcommand in packages/cli/src/cli.ts - Support --project, --json, and --quiet flags - Display project and global KB stats (articles, domains, flush time, logs, staleness) - Add 10 tests in knowledge-status.test.ts (separate batch for mock isolation)
Implements US-016 from PRD. Changes: - Export validation functions from knowledge-flush.ts (collectAllArticles, checkBrokenWikilinks, identifyStaleArticles, getGitDiffNameOnly, readLastFlush) - Add knowledgeLintCommand to packages/cli/src/commands/knowledge.ts with staleness, broken wikilink, and orphaned article checks - Register `knowledge lint` subcommand in cli.ts with --project and --json flags - Add knowledge-lint.test.ts with 10 tests (34 expect calls) - Add test batch to packages/cli/package.json
Implements US-017 from PRD. Changes: - Create knowledge-workflow-capture.ts service that subscribes to workflow_completed events - Triggers captureKnowledge() with conversation context and JSONL workflow logs - Add additionalTranscript parameter to captureKnowledge() for workflow log context - Wire subscription into server startup via subscribeToWorkflowCapture() - Export subscribeToWorkflowCapture from @archon/core - Add 8 tests covering all scenarios (capture trigger, skip conditions, error handling)
Implements US-018 from PRD.
Changes:
- Add KB-aware prompts to archon-interactive-prd research and technical nodes
- Add KB-aware prompts to archon-piv-loop explore and create-plan nodes
- Add KB-aware prompt to archon-adversarial-dev plan node
- Add KB-aware prompt to archon-architect analyze node
- Add KB-aware prompt to archon-refactor-safely analyze-impact node
- Add KB-aware prompt to archon-create-issue investigate node
- All references use graceful degradation ("if available in your context")
Implements US-019 from PRD. Changes: - Add Knowledge Base Integration section to generate-yaml node with guidance for generated workflows - Add KB awareness hint to extract-intent node for workflow design - Add Rule 11 requiring KB sections on analysis/planning/decision-making prompt nodes
Implements US-020 from PRD. Changes: - Add KnowledgeExtractNode type to dag-node schema with mutual exclusivity enforcement - Add isKnowledgeExtractNode type guard and export from schemas/index.ts - Add KnowledgeExtractFn callback type and optional extractKnowledge field to WorkflowDeps - Add executeKnowledgeExtractNode dispatch in dag-executor with variable substitution and upstream output collection - Add extractKnowledgeFromContext function in knowledge-capture.ts for standalone knowledge extraction - Wire extractKnowledge callback in store-adapter.ts createWorkflowDeps() - Update loader.ts to warn about AI-specific fields on knowledge-extract nodes - Update loader.ts validateDagStructure to check $nodeId.output refs in knowledge_extract prompts - Add tests for schema parsing, type guard, node execution, and extraction function
Comprehensive PR ReviewPR: #3 — feat: LLM Knowledge Base System SummaryPR #3 introduces a comprehensive LLM Knowledge Base System spanning 21 source files and 14 test files across 5 packages. The implementation is well-structured with clean dependency injection, good test isolation, and consistent logging patterns. However, there are critical issues that must be addressed: unvalidated Verdict:
CRITICAL Issues1. Unvalidated JSON.parse of AI Response in synthesizeLogs()
View fixAdd Zod schema validation for 2. CLAUDE.md Missing Knowledge Base Directory Structure
The new 3. CLAUDE.md Missing CLI Knowledge Commands
Three new CLI commands ( HIGH Issues1. TOCTOU Race Condition in Flush Lock
Between reading the lock file and writing the new PID, another process can acquire first. Fix: use 2. PR Targets
|
| # | Issue | Location | Recommendation |
|---|---|---|---|
| 1 | Date comparison > should be >= — same-day captures lost |
knowledge-flush.ts:366 |
Fix now (1 char change) |
| 2 | triggerCapture not wired into session transitions |
orchestrator-agent.ts |
Create issue (cleanup service is safety net) |
| 3 | Duplicate owner/repo URL parsing in 3+ places | knowledge-capture.ts:195 |
Create issue |
| 4 | Knowledge-extract node silently drops AI-only fields | dag-node.ts:355 |
Fix now (add to warning pattern) |
| 5 | Bare catch blocks swallow FS errors (EPERM, EIO) | knowledge-flush.ts:407-415, 870-882 |
Fix now (add non-ENOENT logging) |
| 6 | AI JSON parse failure not tested | knowledge-flush.ts:435-467 |
Fix now |
| 7 | Remote URL parsing edge cases not tested | knowledge-capture.ts:249 |
Create issue |
| 8 | Staleness validation AI response not tested | knowledge-flush.ts:900-931 |
Fix now |
| 9 | Config loader knowledge defaults not tested | config-loader.ts |
Fix now |
| 10 | Schema header says "six" types — now seven | dag-node.ts:5-6 |
Fix now |
| 11 | triggerCapture not wired to session transitions |
orchestrator-agent.ts |
Create issue |
LOW Issues
View 10 low-priority suggestions
| Issue | Location | Suggestion |
|---|---|---|
Unused _owner/_repo params |
knowledge-init.ts:119 |
Remove (YAGNI) |
| Lazy logger repeated 8x | Multiple files | Keep as-is (established) |
addStalenessMarker swallows all errors |
knowledge-flush.ts:954 |
Add non-ENOENT logging |
loadUnprocessedLogs swallows JSON parse |
prompt-builder.ts:140 |
Distinguish ENOENT from parse error |
| Git helpers return empty on all errors | knowledge-flush.ts:726-749 |
Add debug-level logging |
| Cleanup shutdown hook not tested | cleanup-service.ts |
Already covered by scheduler tests |
| Loader knowledge-extract not tested separately | loader.ts |
Schema tests cover it |
| SYNTHESIS_PROMPT hardcodes "Sonnet" | knowledge-flush.ts:31 |
Change to "compile model" |
| KnowledgeExtractFn hardcodes "Haiku" | deps.ts:213 |
Change to "capture model" |
| EXTRACTION_PROMPT hardcodes "Haiku" | knowledge-capture.ts:24 |
Change to "capture model" |
What's Good
- Excellent test coverage: 14 new test files with comprehensive edge cases and proper mock isolation
- Clean dependency injection:
WorkflowDeps.extractKnowledgecallback keeps packages decoupled - Atomic writes: Temp-dir + rename for crash-safe article writes
- Debounced scheduling: Well-designed with
timer.unref()to avoid keeping process alive - Graceful degradation: Consistent
config.knowledge.enabledchecks - Good logging: Consistent
knowledge.{action}_{state}event naming - Idempotent init:
mkdir({ recursive: true })+wxflag - Excellent module documentation: Clear JSDoc headers on every new service
Suggested Follow-up Issues
| Issue Title | Priority |
|---|---|
| Wire triggerCapture into orchestrator session transitions | P2 |
| Add parseOwnerRepoFromUrl() utility to @archon/paths | P3 |
| Document Knowledge Base system in docs site | P1 |
| Add Knowledge Base overview guide page | P2 |
Next Steps
- Auto-fix step will address CRITICAL + HIGH code issues
- Review MEDIUM issues above — decide fix now, create issue, or skip
- Documentation updates needed for CLAUDE.md and docs site
- Retarget PR to
devbranch per git workflow convention - Merge when ready
Reviewed by Archon comprehensive-pr-review workflow
Artifacts: review/consolidated-review.md
CRITICAL fixes: - Add Zod schema validation for AI JSON responses in synthesizeLogs() - Add structured error logging in identifyStaleArticles() catch block - Update CLAUDE.md with knowledge base directory structure - Update CLAUDE.md with knowledge CLI commands HIGH fixes: - Fix TOCTOU race in flush lock using atomic wx flag - Add non-ENOENT error logging to bare catch blocks in readExistingArticles/collectAllArticles - Update CLAUDE.md with knowledge-extract node type and knowledge config - Fix date comparison boundary bug (> to >=) preventing same-day captures Additional fixes: - Fix hardcoded model name comments (Sonnet/Haiku → compile/capture model) - Fix dag-node.ts header comment (six → seven variant types) - Update flush lock tests to handle wx flag semantics Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Auto-Fix ReportStatus: COMPLETE Fixes Applied
CRITICAL
HIGH
Additional (MEDIUM/LOW addressed opportunistically)
Tests Updated
Not Fixed (Manual Action Required)
MEDIUM Issues (Your Decision)
Suggested Follow-up Issues
Validation
Auto-fixed by Archon comprehensive-pr-review workflow |
…failure tests Add missing test coverage for two knowledge system gaps: 1. triggerCapture fire-and-forget wiring (new test file): verifies that captureKnowledge is called with correct owner/repo when triggerCapture fires, scheduleFlush is called after successful capture, and errors are caught/logged without propagating (fire-and-forget contract). 2. AI JSON parse failure in flush synthesis (added to existing flush tests): verifies that malformed JSON, schema-invalid JSON, and partial article structures all throw with clear errors, log warnings, release the flush lock, and leave the KB in a consistent state (no partial writes). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
UX Journey
Before
After
Architecture Diagram
After
Connection inventory:
Label Snapshot
risk: mediumsize: XLcore,workflows,cli,pathscore:services,workflows:dag-executor,cli:knowledge,paths:archon-pathsChange Metadata
featuremultiLinked Issue
Validation Evidence (required)
bun run validate # type-check + lint + format:check + test — all passSecurity Impact (required)
No— uses existing AI client infrastructureNo— uses existing IAssistantClientNoYes— writes to~/.archon/workspaces/{o}/{r}/knowledge/and~/.archon/knowledge/Compatibility / Migration
Yes— KB is entirely opt-in (enabled by default but gracefully degrades when empty)Yes— new optionalknowledgesection in.archon/config.yamlNoHuman Verification (required)
Side Effects / Blast Radius (required)
Rollback Plan (required)
knowledge.enabled: falsein.archon/config.yamlto disable all KB functionalityknowledge.enabled(default: true)knowledge.capture_failedorknowledge.flush_failedlog eventsRisks and Mitigations
process.kill(pid, 0)— dead process locks are automatically reclaimed