Conversation
Adds session_message_count column to the analysis_usage table. Used by the insights command for resume detection: skip re-analysis if the session's message count hasn't changed since last analysis. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Exports a focused sync function that parses and writes a single session file to SQLite without scanning all providers. Used by the insights --hook path to guarantee fresh data before analysis. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
New `code-insights insights <session_id>` command:
- --native: delegates to ClaudeNativeRunner (claude -p, zero config)
- default: delegates to ProviderRunner (configured LLM)
- --hook: reads { session_id, transcript_path } from stdin JSON,
calls syncSingleFile() before analysis
- --force: bypasses resume detection, always re-analyzes
- -q: suppresses output for hook usage
Two-pass analysis: session analysis then prompt quality, both saving
to SQLite via inline DB helpers (no circular server import).
Resume detection in hook mode: compares session.message_count against
analysis_usage.session_message_count — skips if unchanged.
Also adds `insights check` subcommand for finding unanalyzed sessions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Registers the insights command and insights check subcommand in cli/src/index.ts. Updates schema.test.ts and migrate.test.ts to expect schema version 8 (and v8Applied in MigrationResult). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TA Synthesis (Phase 2): feat(cli): insights command — Round 1Review of Specialist CommentsFIX NOW #1 — Migration function ordering (Unanimous: Node/CLI + SQL + TA Insider) All three reviewers flagged this independently. Verified in the diff: Verdict: AGREE — FIX NOW. Move FIX NOW #2 — Server-side Verified by reading However: this is a pre-existing issue in the server code, not introduced by this PR. The CLI path (this PR) correctly writes Verdict: AGREE the bug is real, but reclassified from FIX NOW to ESCALATE. The server-side SUGGESTION — Two reviewers independently flagged that provider mode hardcodes Verdict: AGREE as suggestion. The CLI doesn't have access to SUGGESTION — Missing The CLI's inline Verdict: PUSHBACK — NOT APPLICABLE. In hook/CLI mode, console.warn output would pollute the terminal during automated SessionEnd hooks. The server version runs in a long-lived process where monitoring makes sense. For CLI one-shot execution, the facets are saved and visible in the dashboard. Monitoring warnings add noise without actionable value in this context. NOTE — Inline DB helpers duplicate server logic (Node/CLI + SQL) Both specialists noted this. The PR comment documents it as a deliberate trade-off (no cross-package import from CLI to server). Verdict: AGREE it's a noted trade-off, not an issue. The CLI package cannot import from the server package. Documented inline. NOTE — Safe pattern — parameterized placeholders with spread, not string interpolation. The Verdict: NOT APPLICABLE. No injection risk. NOTE — Test seed helper string interpolation (SQL)
Verdict: NOT APPLICABLE. Test code with controlled inputs. Second Pass FindingsNo additional issues found beyond what the three reviews covered. The test coverage is solid — resume detection, force flag, native vs provider mode, V8 migration, and syncSingleFile are all tested. Consolidated Review (For Dev Agent)🔴 FIX NOW:
❌ NOT APPLICABLE:
🟡 SUGGESTIONS (non-blocking, dev's discretion):
Final VerdictCHANGES REQUIRED — Round 2 needed One FIX NOW item (migration ordering — trivial fix, ~5 line move). One ESCALATE item for founder decision on companion PR scope. |
applyV8 was defined before applyV7 due to insertion order during development. Move applyV8 after applyV7 to follow project convention (migration functions in chronological order V1...VN). No logic change — runMigrations() call order was always correct. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review AddressalFIX NOW items addressed:
Pre-PR gate: All review items addressed. Ready for re-review or merge. |
…ession_message_count INSERT OR REPLACE does a DELETE+INSERT, clobbering columns not included in the write (specifically session_message_count written by the CLI). Switch both server and CLI to INSERT ... ON CONFLICT DO UPDATE so each writer only touches the columns it owns. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review AddressalFIX NOW items addressed:
Pre-PR gate: All review items addressed. Ready for re-review or merge. |
What
New
code-insights insights <session_id>CLI command (Issue 3 of 6 in Phase 12, v4.8.0). Analyzes a session using eitherclaude -p(native, zero-config) or the configured LLM provider, saving insights and prompt quality scores to SQLite.Also adds V8 schema migration,
syncSingleFile()for targeted syncing, and aninsights checksubcommand.Why
Enables the zero-config analysis path: Claude Code users can run
code-insights insights --hook --native -qfrom a SessionEnd hook without needing a separate API key. Closes Issue #240 (Issue 3 scope).How
cli/src/commands/insights.ts— new command with full flag support (--native,--hook,--force,-q,--source). Two-pass analysis: session analysis then prompt quality, each using the runner abstraction. DB writes are inline (no circular@code-insights/serverimport).cli/src/commands/sync.ts— exportssyncSingleFile()for targeted single-file sync without provider scanning.cli/src/db/migrate.ts—applyV8()addssession_message_count INTEGERtoanalysis_usagefor resume detection.cli/src/db/schema.ts— bumpsCURRENT_SCHEMA_VERSIONto 8.cli/src/index.ts— registersinsightscommand andinsights checksubcommand.Runner dispatch:
<id> --native<id>--hook --native--hookResume detection (hook mode only): compares
sessions.message_countvsanalysis_usage.session_message_count. Skips if unchanged, bypassed with--force.Schema Impact
ALTER TABLE analysis_usage ADD COLUMN session_message_count INTEGERAnalysisRunnerinterface from runner-types.ts)Verification
pnpm buildfrom repo root, zero errors)Test plan
session_message_countcolumn (3 migration tests)ProviderRunner.fromConfig(), notClaudeNativeRunner.validate()ClaudeNativeRunner.validate()and uses native runnersession_message_countwritten to analysis_usage (V8 field)--forcebypasses resume detection even with matching message countsyncSingleFile()calls provider.parse() and inserts session + messagessyncSingleFile()is a no-op when parse() returns null