-
Notifications
You must be signed in to change notification settings - Fork 4
feat: insights CLI command with --native and --hook modes #240
Description
Context
Part of the Native Analysis via Claude Code Hooks feature (Phase 12, v4.8.0).
Plan: docs/plans/2026-03-28-native-analysis-hooks.md
Issue 3 of 6 — Core feature. Depends on #238 and #239.
Problem
Users need a way to trigger session analysis from the CLI, supporting both native mode (Claude Code's own LLM) and provider mode (configured API key).
Solution
Command Interface
code-insights insights <session_id> [options]
Options:
--native Use calling AI tool (claude -p) instead of configured LLM
--hook Read session context from stdin JSON (for hook invocation)
--source <tool> Source tool identifier (default: claude-code)
--force Re-analyze even if insights already exist
--quiet, -q Suppress output
Behavior Matrix
| Invocation | session_id source | Runner | Sync |
|---|---|---|---|
--hook --native |
stdin JSON | NativeRunner | syncSingleFile |
--hook (no native) |
stdin JSON | ProviderRunner | syncSingleFile |
<id> --native |
positional arg | NativeRunner | none |
<id> |
positional arg | ProviderRunner | none |
Key Mechanisms
-
syncSingleFile()— targeted sync of one session file (no full provider scan). Guarantees fresh data before analysis when called from hook. -
Resume detection — stores
session_message_countinanalysis_usage(V8 migration). If message count hasn't changed since last analysis, skip. If changed (session was resumed), re-analyze. -
Two analysis calls — session analysis + prompt quality, sequential. Same prompts as existing provider path.
-
Upsert — DELETE existing insights + INSERT new in a transaction. Latest analysis always wins.
Schema V8 Migration
ALTER TABLE analysis_usage ADD COLUMN session_message_count INTEGER;New/Modified Files
| File | Change |
|---|---|
cli/src/commands/insights.ts |
NEW — full command implementation |
cli/src/commands/sync.ts |
MODIFY — export syncSingleFile() |
cli/src/db/migrate.ts |
MODIFY — add V8 migration |
cli/src/db/schema.ts |
MODIFY — bump CURRENT_SCHEMA_VERSION to 8 |
cli/src/index.ts |
MODIFY — register insights command |
Acceptance Criteria
-
code-insights insights <id>analyzes using configured LLM provider -
code-insights insights <id> --nativeanalyzes usingclaude -p -
--hookreads session_id from stdin JSON, runssyncSingleFile()first -
--forcere-analyzes regardless of existing insights -
--quietsuppresses all output except errors - Resume detection: skips if message_count unchanged, re-analyzes if changed
- V8 migration adds
session_message_countcolumn - Both analysis + PQ run sequentially, both save to SQLite
- Summary line printed:
[Code Insights] Session analyzed: N insights, PQ X/100 - Integration tests with mocked runners