Conversation
…nalysis/ Move DB persistence helpers from server to cli/src/analysis/ so the CLI can use them directly without a cross-package import. - analysis-db.ts: saveInsightsToDb, deleteSessionInsights (with includeOnlyTypes), saveFacetsToDb (analysisVersion param + default), convertToInsightRows, convertPQToInsightRow, ANALYSIS_VERSION. Preserves [pattern-monitor] and [pq-monitor] console.warn monitors. - analysis-usage-db.ts: saveAnalysisUsage, getSessionAnalysisUsage, SaveAnalysisUsageData (session_message_count as optional), AnalysisUsageRow. - TDD: tests written first in __tests__/analysis-db.test.ts and __tests__/analysis-usage-db.test.ts, covering all key behaviors. Follows PR #238 migration pattern. Closes #248 (together with re-exports). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…orts from cli Server consumers import the same functions from the same paths as before. Adds convertPromptQualityToInsightRow as a backward-compat alias for the cli's convertPQToInsightRow (used in prompt-quality-analysis.ts). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace inline duplicates with imports from analysis/analysis-db.js and analysis/analysis-usage-db.js. Add package.json exports for the new modules. The null→undefined adapter (sessionData) bridges SQLite row nulls to the SessionData interface's optional (undefined) fields. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TA Review (Phase 1 - Insider): refactor: move analysis DB helpers from server to CLI — Round 1TA Plan Compliance (6 adjustments)
Divergence convergence details (adjustment 5):
Architecture AlignmentData Contract Impact
Pattern Consistency
Test Coverage (TDD Domain Verification)
Server Re-Export Completeness
CLI
|
TA Synthesis (Phase 2): refactor: move analysis DB helpers from server to CLI — Round 1Review of Specialist CommentsNode/CLI Specialist — APPROVED SQL/DB Specialist — CHANGES REQUIRED
This is a regression: the deduplication merged two callers with different write patterns into one function without protecting the optional field. Same class of bug as PR #247. AGREE with SQL specialist. Finding is valid and verified against the diff. Consolidated Review (For Dev Agent)FIX NOW:
NOT APPLICABLE: SUGGESTIONS (non-blocking):
Final VerdictChanges Required — one FIX NOW item before merge. Dev agent: fix the COALESCE issue, add a regression test for the NULL-clobber case, then report back. |
…-analysis upsert Without COALESCE, a server-side re-analysis call (which doesn't provide session_message_count) would overwrite the CLI-written value with NULL, breaking resume detection on the next hook invocation. COALESCE(excluded.session_message_count, analysis_usage.session_message_count) writes the new value when provided, preserves the existing value when NULL. Adds regression test: CLI writes 42, server upserts without it, 42 survives. 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. |
Triple-Layer Code Review — Round 1Reviewers
Pre-Review Gates
TA Plan Compliance (6 adjustments)All 6 TA-approved adjustments verified implemented:
Issues Found & Resolution🔴 FIX NOW (resolved)
🟡 SUGGESTIONS (non-blocking)
Round 1 verdict: PASS — Ready for merge |
What
Move
analysis-db.tsandanalysis-usage-db.tsfromserver/src/llm/tocli/src/analysis/. Server files become thin re-export wrappers. Eliminates ~170 lines of inline duplicates frominsights.ts.Closes #248.
Why
The CLI had ~170 lines of inline DB helpers duplicating the server's
analysis-db.tsandanalysis-usage-db.ts. Any change to the DB persistence logic required updating both copies. Moving to CLI with server re-exports follows the same pattern established by PR #238 (prompt module migration).How
cli/src/analysis/analysis-db.ts: all insight/facet DB helpers with converged divergences:deleteSessionInsightsgainsincludeOnlyTypesoption (from server version)saveFacetsToDbtakesanalysisVersionas optional parameter with defaultANALYSIS_VERSION?? []guards ondecisions/learnings(from CLI inline version)[pattern-monitor]and[pq-monitor]console.warnmonitorscli/src/analysis/analysis-usage-db.ts: usage tracking withsession_message_countas optional field onSaveAnalysisUsageDataconvertPromptQualityToInsightRowalias for backward compatcli/src/commands/insights.ts: replaces ~170 inline lines with imports; addssessionDataadapter to bridgenull(SQLite row) →undefined(SessionData interface)cli/package.json: adds./analysis/analysis-dband./analysis/analysis-usage-dbexportsSchema Impact
Testing
pnpm build: PASS (zero errors)pnpm test: PASS (1016 tests across CLI + server)analysis-db.test.ts(15 tests) andanalysis-usage-db.test.ts(8 tests) written first, RED verified, then implementation made them GREENVerification