Skip to content

feat: LLM Knowledge Base System#3

Merged
Staxed merged 42 commits intomainfrom
archon/task-archon-ralph-dag-1775905278042
Apr 11, 2026
Merged

feat: LLM Knowledge Base System#3
Staxed merged 42 commits intomainfrom
archon/task-archon-ralph-dag-1775905278042

Conversation

@Staxed
Copy link
Copy Markdown
Owner

@Staxed Staxed commented Apr 11, 2026

Summary

  • Problem: Every new Archon session starts from zero context — the AI agent must re-discover project architecture, past decisions, known patterns, and lessons learned, wasting ~20,000+ tokens per session
  • Why it matters: Reduces context reconstruction cost by ~10x while improving accuracy of project-specific decisions through persistent cross-session knowledge
  • What changed: Added a complete 4-stage knowledge pipeline (CAPTURE → COMPILE → VALIDATE → QUERY) with hierarchical markdown indexes, auto-triggered on session end, with CLI commands for management, and integrated into the workflow engine
  • What did not change (scope boundary): No vector database, no embeddings, no RAG — agent navigates markdown indexes directly. No multi-user knowledge sharing. No real-time mid-session updates.

UX Journey

Before

User                   Archon                   AI Client
────                   ──────                   ─────────
starts session ──────▶ creates session
                       loads codebase context
                       (no project memory)
                       streams to AI ──────────▶ rediscovers architecture
                                                 re-reads dozens of files
                                                 ~20,000 tokens of context
sees reply ◀─────────  sends to platform
(session ends, all knowledge lost)

After

User                   Archon                   AI Client
────                   ──────                   ─────────
starts session ──────▶ creates session
                       loads codebase context
                       [loads KB index ~500 tokens]
                       [loads unprocessed logs ~2K tokens]
                       streams to AI ──────────▶ has project memory
                                                 knows past decisions
                                                 ~2,500 tokens of context
sees reply ◀─────────  sends to platform
(session ends)
                       [captures knowledge (Haiku)]
                       [schedules flush (10min debounce)]
                       [compiles to articles (Sonnet)]
                       [validates staleness (Haiku + git diff)]

Architecture Diagram

After

Session Start                          Session End
    │                                      │
    ▼                                      ▼
prompt-builder.ts ──────────────▶ knowledge-capture.ts
    │ loadKnowledgeIndex()              │ captureKnowledge()
    │ loadUnprocessedLogs()             │ extractKnowledge() [Haiku]
    │                                   │ appendToDailyLog()
    ▼                                   │
~/.archon/workspaces/{o}/{r}/           ▼
  knowledge/                     knowledge-scheduler.ts
  ├── index.md  ◀─────────┐        │ scheduleFlush() [10min]
  ├── meta/                │        │
  │   ├── schema.md        │        ▼
  │   ├── last-flush.json  │  knowledge-flush.ts
  │   └── flush.lock       │     │ flushKnowledge() [Sonnet]
  ├── logs/                │     │ validateStaleness() [Haiku]
  │   └── YYYY-MM-DD.md   │     │ checkBrokenWikilinks()
  └── domains/             │     │ acquireFlushLock()
      ├── architecture/ ───┘     │ writeFlushResultsAtomic()
      ├── decisions/             │
      ├── patterns/              ▼
      ├── lessons/          knowledge-init.ts
      └── connections/         │ initKnowledgeDir()
                               │ writeTemplates()

[+] packages/core/src/services/knowledge-init.ts
[+] packages/core/src/services/knowledge-capture.ts
[+] packages/core/src/services/knowledge-flush.ts
[+] packages/core/src/services/knowledge-scheduler.ts
[+] packages/core/src/services/knowledge-workflow-capture.ts
[~] packages/core/src/orchestrator/prompt-builder.ts
[~] packages/core/src/services/cleanup-service.ts
[~] packages/core/src/handlers/command-handler.ts
[~] packages/workflows/src/schemas/dag-node.ts
[~] packages/workflows/src/dag-executor.ts
[~] packages/workflows/src/deps.ts
[~] packages/workflows/src/loader.ts
[+] packages/cli/src/commands/knowledge.ts

Connection inventory:

From To Status Notes
prompt-builder knowledge/index.md new Loads KB index at session start
prompt-builder knowledge/logs/*.md new Loads unprocessed logs as fallback
cleanup-service knowledge-capture new Triggers capture on conversation-closed
command-handler knowledge-capture new Triggers capture on /reset
knowledge-capture knowledge-scheduler new Schedules flush after capture
knowledge-scheduler knowledge-flush new Debounced flush trigger
server/index.ts knowledge-workflow-capture new Subscribes to workflow events
dag-executor deps.extractKnowledge new knowledge-extract node type
store-adapter knowledge-capture new Provides extractKnowledge callback

Label Snapshot

  • Risk: risk: medium
  • Size: size: XL
  • Scope: core, workflows, cli, paths
  • Module: core:services, workflows:dag-executor, cli:knowledge, paths:archon-paths

Change Metadata

  • Change type: feature
  • Primary scope: multi

Linked Issue

  • Related: LLM Knowledge Base System PRD

Validation Evidence (required)

bun run validate  # type-check + lint + format:check + test — all pass
  • All 20 user stories implemented and validated
  • Type-check: 0 errors across 9 packages
  • Lint: 0 errors, 0 warnings
  • Format: clean
  • Tests: All pass across all packages (including 100+ new tests for KB functionality)

Security Impact (required)

  • New permissions/capabilities? No — uses existing AI client infrastructure
  • New external network calls? No — uses existing IAssistantClient
  • Secrets/tokens handling changed? No
  • File system access scope changed? Yes — writes to ~/.archon/workspaces/{o}/{r}/knowledge/ and ~/.archon/knowledge/
    • Risk: Low — same directory scope as existing artifacts/logs
    • Mitigation: Uses existing path resolution functions, no user-supplied paths

Compatibility / Migration

  • Backward compatible? Yes — KB is entirely opt-in (enabled by default but gracefully degrades when empty)
  • Config/env changes? Yes — new optional knowledge section in .archon/config.yaml
  • Database migration needed? No

Human Verification (required)

  • Verified scenarios: All acceptance criteria verified via tests
  • Edge cases checked: Empty KB, disabled KB, missing files, stale locks, concurrent flushes, model fallback
  • What was not verified: End-to-end integration with real AI models (mocked in tests)

Side Effects / Blast Radius (required)

  • Affected subsystems/workflows: prompt-builder (adds ~2.5K tokens to context), cleanup-service (triggers capture), command-handler (/reset triggers capture), default workflows (KB-aware prompts)
  • Potential unintended effects: Slightly increased token usage at session start (~2.5K tokens for KB context)
  • Guardrails/monitoring for early detection: Knowledge capture/flush operations are fire-and-forget — errors logged but never block user sessions

Rollback Plan (required)

  • Fast rollback command/path: Set knowledge.enabled: false in .archon/config.yaml to disable all KB functionality
  • Feature flags or config toggles: knowledge.enabled (default: true)
  • Observable failure symptoms: knowledge.capture_failed or knowledge.flush_failed log events

Risks and Mitigations

  • Risk: Token budget for KB context injection might be too large for some prompts
    • Mitigation: Index is truncated to ~500 tokens, logs to ~2K tokens; configurable via code constants
  • Risk: Flush lock could become stale if process crashes during flush
    • Mitigation: Stale lock detection via process.kill(pid, 0) — dead process locks are automatically reclaimed

Staxed and others added 30 commits April 11, 2026 07:08
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)
Staxed added 10 commits April 11, 2026 08:52
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
@Staxed
Copy link
Copy Markdown
Owner Author

Staxed commented Apr 11, 2026

Comprehensive PR Review

PR: #3 — feat: LLM Knowledge Base System
Reviewed by: 5 specialized agents
Date: 2026-04-11


Summary

PR #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 JSON.parse of AI responses that can crash the flush pipeline, a TOCTOU race condition in the flush lock, the PR targets main instead of dev, significant documentation gaps, and a date boundary bug that silently drops same-day knowledge captures.

Verdict: REQUEST_CHANGES

Severity Count
CRITICAL 3
HIGH 11
MEDIUM 11
LOW 10

CRITICAL Issues

1. Unvalidated JSON.parse of AI Response in synthesizeLogs()

packages/core/src/services/knowledge-flush.ts:461
Agents: code-review, error-handling

synthesizeLogs() calls JSON.parse(jsonStr) on raw AI output with no try/catch, no schema validation, and no fallback. Malformed AI JSON crashes the entire flush pipeline. The same issue in identifyStaleArticles() (line 920) silently returns [], permanently hiding staleness.

View fix

Add Zod schema validation for FlushSynthesis, wrap JSON.parse in try/catch with structured logging. See consolidated-review.md for full code.

2. CLAUDE.md Missing Knowledge Base Directory Structure

CLAUDE.md — Archon Directory Structure section
Agent: docs-impact

The new knowledge/ subdirectory tree (logs, domains, meta) and 4 new path functions are not documented. AI agents working on this codebase won't know where knowledge files live.

3. CLAUDE.md Missing CLI Knowledge Commands

CLAUDE.md — Essential Commands > CLI section
Agent: docs-impact

Three new CLI commands (knowledge flush/status/lint) are not documented in the CLI section.


HIGH Issues

1. TOCTOU Race Condition in Flush Lock

packages/core/src/services/knowledge-flush.ts:62-93

Between reading the lock file and writing the new PID, another process can acquire first. Fix: use { flag: 'wx' } (exclusive create) — pattern already exists in knowledge-init.ts:writeIfNotExists.

2. PR Targets main Instead of dev

CLAUDE.md states: "dev is the working branch." This PR should be retargeted to dev.

3. identifyStaleArticles() Silently Swallows Parse Failures

packages/core/src/services/knowledge-flush.ts:920-925

Bare catch {} returns [] without logging — staleness checking is permanently disabled with no indication.

4. triggerCapture Function Not Tested

packages/core/src/services/knowledge-capture.ts:314-346

4 early-return paths, error catch handler, and scheduleFlush integration are all untested.

5. Flush Lock Mechanism Untested for Race Conditions

packages/core/src/services/knowledge-flush.ts:67-112

Live PID rejection, dead PID reclamation, and lock release on error paths are untested.

6-11. Documentation Gaps (6 findings)

Missing from CLAUDE.md: knowledge-extract node type, knowledge config types. Missing from docs site: CLI reference, configuration reference, archon directories, workflow authoring guide.


MEDIUM Issues (Needs Decision)

View 11 medium-priority findings
# 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.extractKnowledge callback 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.enabled checks
  • Good logging: Consistent knowledge.{action}_{state} event naming
  • Idempotent init: mkdir({ recursive: true }) + wx flag
  • 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

  1. Auto-fix step will address CRITICAL + HIGH code issues
  2. Review MEDIUM issues above — decide fix now, create issue, or skip
  3. Documentation updates needed for CLAUDE.md and docs site
  4. Retarget PR to dev branch per git workflow convention
  5. 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>
@Staxed
Copy link
Copy Markdown
Owner Author

Staxed commented Apr 11, 2026

Auto-Fix Report

Status: COMPLETE
Pushed: Changes pushed to PR branch


Fixes Applied

Severity Fixed Skipped
CRITICAL 3 0
HIGH 5 3

CRITICAL

  • Unvalidated JSON.parse in synthesizeLogs() (knowledge-flush.ts) - Added Zod schema validation (flushSynthesisSchema) with structured error logging on parse and shape failures
  • CLAUDE.md Missing KB Directory Structure - Added knowledge/ subtree (logs, domains, meta, index.md) to Archon Directory Structure section
  • CLAUDE.md Missing CLI Knowledge Commands - Added knowledge flush/status/lint commands to CLI section

HIGH

  • TOCTOU Race in Flush Lock (knowledge-flush.ts) - Replaced read-check-write with atomic writeFile({flag:'wx'}), matching existing writeIfNotExists pattern
  • identifyStaleArticles() Bare Catch (knowledge-flush.ts) - Added warn-level logging on parse failure, validated array items are strings
  • CLAUDE.md Missing knowledge-extract Node Type - Added to node type list
  • CLAUDE.md Missing Knowledge Config - Added full knowledge: config section with all fields and defaults
  • Flush Lock Tests - Updated mocks to handle wx flag semantics

Additional (MEDIUM/LOW addressed opportunistically)

  • Date comparison > to >= — same-day captures after flush are now included
  • Added non-ENOENT error logging to 6 bare catch blocks across readExistingArticles, collectAllArticles, addStalenessMarker, and git helpers
  • Fixed schema header "six" to "seven" variant types
  • Fixed hardcoded model names in comments (Sonnet/Haiku to compile/capture model)

Tests Updated

  • knowledge-flush.test.ts: Updated mocks for wx flag and >= date behavior — all 35 tests pass

Not Fixed (Manual Action Required)

  • PR Targets main Instead of dev — Requires gh pr edit 3 --base dev by PR author
  • triggerCapture Not Tested — Needs new test file with separate mock.module invocation
  • Docs Site Updates (6 pages) — Should be a separate documentation PR

MEDIUM Issues (Your Decision)

Issue Recommendation
triggerCapture not wired to session transitions Create issue (cleanup service is safety net)
Duplicate owner/repo URL parsing Create issue for shared utility
Knowledge-extract node drops AI-only fields silently Add to BASH_NODE_AI_FIELDS warning
Config loader defaults not tested Add test in config-loader.test.ts

Suggested Follow-up Issues

  1. Document Knowledge Base system in docs site (P1) — 6 pages need updates
  2. Wire triggerCapture into orchestrator session transitions (P2)
  3. Add unit tests for triggerCapture (P2)
  4. Add parseOwnerRepoFromUrl() utility (P3)
  5. Add knowledge-extract to AI field warnings (P3)

Validation

Check Status
Type check PASS
Lint PASS
Format PASS
Tests PASS

Auto-fixed by Archon comprehensive-pr-review workflow
Fixes pushed to branch archon/task-archon-ralph-dag-1775905278042

…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>
@Staxed Staxed marked this pull request as ready for review April 11, 2026 17:34
@Staxed Staxed merged commit ea32068 into main Apr 11, 2026
@Staxed Staxed deleted the archon/task-archon-ralph-dag-1775905278042 branch April 11, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant