NODEDC_1C/docs/TECH/1CLLMARCH-FACT.md

937 lines
41 KiB
Markdown

# 1CLLMARCH Fact Check And Stabilization Plan
Updated at: 2026-04-10
Source baseline: `docs/TECH/1CLLMARCH.md`
## 1. Purpose
This document fixes the current factual state of the codebase against `1CLLMARCH` and records a production-focused stabilization plan that preserves:
1. existing MCP routes;
2. manual routing and guard logic;
3. GUI manual markup + autorun operational loop.
## 2. Executive Reality Check
Current state is **not MVP** and also **not stable production**.
It is an advanced prototype with strong observability and eval tooling, but with architectural coupling and quality bottlenecks.
Approximate readiness against target architecture: **55/100**.
## 3. Verified Facts (Code + Runtime)
1. Strong engineering layers already exist:
- requirement extraction, coverage, grounding checks;
- rich debug payload and session trace;
- investigation state/followup continuity;
- manual annotation schema and post-analysis queues;
- async eval run + live history APIs.
2. Main production blockers:
- orchestration monolith and coupling in `assistantService.ts`;
- deterministic/template-heavy final answer construction;
- large lexical heuristic surface for intent routing;
- temporal policy inconsistency (date handling differs by lane/path);
- hidden fallback behavior around historical snapshot assumptions.
3. Quality metrics from latest Stage1 runs confirm weak user value:
- low retrieval differentiation;
- high generic explanation rate;
- low accountant actionability;
- zero mechanism specificity.
## 4. Gap Vs `1CLLMARCH`
### 4.1 Already aligned (partially or strongly)
1. Structured normalization contracts and validator loops.
2. Coverage and grounding artifacts (with different naming than target).
3. Conversation state persistence.
4. Operational diagnostics and report generation.
### 4.2 Not aligned enough for stable prod
1. Role separation (Interpreter/Planner/Critic/Answer) is incomplete and strongly coupled.
2. Final user answer quality is constrained by deterministic template synthesis.
3. Unified contract for analysis date/time scope is missing across all lanes.
4. Result classes from target (`FULLY_ANSWERED`, `BLOCKED_BY_*`, etc.) are not normalized as one contract.
5. Reason-code taxonomy exists but is fragmented across modules.
## 5. Stabilization Plan (No Route Breakage)
## Stage 1 (P0): Unified Analysis Context + Temporal Hardening
Goal:
1. Introduce unified `analysis_context` contract.
2. Propagate it through eval -> assistant -> runtime lanes.
3. Remove hidden hardcoded period fallback in live MCP plan generation.
4. Keep backward compatibility (`period_hint` still supported).
Acceptance:
1. If analysis date is set, runtime uses it explicitly in both deep/address paths.
2. If analysis date is absent, runtime no longer silently injects fixed historical date in live-plan fallback.
3. Existing APIs and manual workflows remain operational.
Implemented in current pass:
1. Added unified `analysis_context` contract to request context (`as_of_date`, `period_from`, `period_to`, `snapshot_mode`, `source`).
2. Added compatibility bridge: legacy `period_hint` is still accepted and normalized into `analysis_context`.
3. Propagated analysis context through eval flows into assistant runtime.
4. Applied analysis context in temporal guard with explicit precedence over implicit snapshot lock.
5. Removed hidden hardcoded live-plan fallback period by switching to:
- explicit analysis period/date when provided;
- query-derived period when present;
- generic live probe when period is absent.
Validation:
1. `npm run build` passed.
2. Targeted runtime tests passed:
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Status: **Completed**
## Stage 2 (P1): Orchestrator Decomposition (Behavior-Preserving Refactor)
Goal:
1. Split monolith into explicit modules:
- QueryFrame builder
- Execution planner
- Evidence assembler
- Coverage critic
- Answer package builder
2. Preserve current behavior under compatibility adapter.
Acceptance:
1. No MCP route regressions.
2. Existing tests and autorun loop remain green.
Implemented in current pass (Phase 2.1):
1. Added new orchestration contract module:
- `assistant_query_frame_v1`
- `assistant_execution_plan_v1`
- `assistant_evidence_bundle_v1`
- `assistant_coverage_contract_v1`
- outcome classifier (`FULLY_ANSWERED`, `PARTIALLY_ANSWERED`, `BLOCKED_*`, `MISROUTED`, `FAILED_TO_BIND_ENTITIES`)
2. Integrated contracts into deep-lane runtime without route/answer behavior changes:
- debug payload now includes `assistant_outcome_class_v1`;
- debug payload and event logs now include `assistant_orchestration_contracts_v1`.
3. Added unit regression tests:
- `assistantOrchestrationContracts.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted tests passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.2):
1. Added runtime orchestration adapter for the deep lane:
- `assistantOrchestrationRuntimeAdapter.ts`
- unified pipeline call for `requirements -> coverage -> grounding` with stable interfaces.
2. Integrated adapter into `assistantService` main deep-lane flow (behavior-preserving):
- existing extraction/coverage/grounding logic preserved;
- execution now routed through one orchestration boundary.
3. Added adapter unit tests:
- `assistantOrchestrationRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted tests passed:
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.3):
1. Extracted answer package builder (`answer_structure_v11`) from `assistantService` into dedicated module:
- `assistantAnswerPackageBuilder.ts`
2. Rewired deep-lane answer structure assembly to use the new module without contract changes.
3. Added focused unit tests for answer package behavior:
- `assistantAnswerPackageBuilder.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 test pack passed:
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.4):
1. Extracted coverage/grounding pipeline into dedicated module:
- `assistantCoverageGrounding.ts`
- moved requirement extraction, coverage resolution, and grounding checks under one reusable boundary.
2. Rewired `assistantService` to use extracted coverage/grounding module via compatibility wrappers (behavior-preserving).
3. Added focused regression tests:
- `assistantCoverageGrounding.test.ts`
4. Stabilized deterministic Stage 2 regression environment for followup continuity checks:
- fixed accidental false-positive token in grounding test fixture;
- fixed env isolation in `assistantWave10SettlementCorrectiveRegression.test.ts` by explicitly controlling `FEATURE_ASSISTANT_ADDRESS_QUERY_V1`.
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 + safety regressions passed:
- `assistantCoverageGrounding.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.5):
1. Extracted query-planning helpers from `assistantService` into dedicated module:
- `assistantQueryPlanning.ts`
- moved `fragmentTextById`, execution-plan builder, and debug-routes builder under one reusable boundary.
2. Rewired `assistantService` to use extracted query-planning module (behavior-preserving wrapper integration).
3. Added focused unit tests for query-planning behavior:
- `assistantQueryPlanning.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 + safety regressions passed:
- `assistantQueryPlanning.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.6):
1. Extracted evidence-bundle assembly from `assistantService` into dedicated module:
- `assistantEvidenceBundleAssembler.ts`
- centralized:
- `assistant_evidence_bundle_v1` contract assembly;
- debug `retrieval_status` projection from normalized retrieval results.
2. Rewired `assistantService` to use assembler output for both:
- `assistant_orchestration_contracts_v1.evidence_bundle`;
- debug payload `retrieval_status`.
3. Added focused unit tests:
- `assistantEvidenceBundleAssembler.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 + safety regressions passed:
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.7):
1. Extracted deep-lane debug payload assembly from `assistantService` into dedicated module:
- `assistantDebugPayloadAssembler.ts`
2. Rewired `assistantService` to build `debug` via assembler (behavior-preserving):
- keeps all existing fields, guard audits, orchestration contracts and optional sections.
3. Added focused unit tests:
- `assistantDebugPayloadAssembler.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 + safety regressions passed:
- `assistantDebugPayloadAssembler.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.8):
1. Extracted deep-lane processed log payload assembly from `assistantService` into dedicated module:
- `assistantMessageLogAssembler.ts`
2. Rewired `assistantService` to build `assistant_message_processed.details` via assembler (behavior-preserving).
3. Added focused unit tests:
- `assistantMessageLogAssembler.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 + safety regressions passed:
- `assistantMessageLogAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.9):
1. Extracted orchestration-contract bundle assembly from `assistantService` into dedicated module:
- `assistantContractsBundleAssembler.ts`
2. Rewired `assistantService` to consume bundled contracts/outcome class from assembler (behavior-preserving):
- `query_frame`, `execution_plan`, `evidence_bundle`, `coverage`, `outcome_class`.
3. Added focused unit tests:
- `assistantContractsBundleAssembler.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 + safety regressions passed:
- `assistantContractsBundleAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.10):
1. Extracted deep response envelope assembly from `assistantService` into dedicated module:
- `assistantDeepResponseAssembler.ts`
- centralized:
- safe final assistant text cleanup (debug tail stripping);
- `answer_structure_v11` selection/building policy;
- assistant conversation item construction.
2. Rewired `assistantService` to consume deep response assembler (behavior-preserving).
3. Added focused unit tests:
- `assistantDeepResponseAssembler.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 + safety regressions passed:
- `assistantDeepResponseAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantOrchestrationContracts.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.11):
1. Added top-level deep turn packager to compose extracted Stage 2 modules behind one boundary:
- `assistantDeepTurnPackaging.ts`
- centralizes orchestration of:
- evidence bundle assembly;
- contracts/outcome class assembly;
- deep answer artifacts;
- debug payload;
- assistant conversation item;
- processed log details.
2. Rewired deep-lane `assistantService` flow to use `assembleAssistantDeepTurnPackaging(...)` (behavior-preserving):
- replaced duplicated per-artifact assembly block with single orchestrator call;
- preserved investigation-state update and existing response/event contract.
3. Added focused unit test:
- `assistantDeepTurnPackaging.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.12):
1. Extracted deep-turn input normalization/defaulting from `assistantService` into dedicated module:
- `assistantDeepTurnInputBuilder.ts`
- centralized normalization of:
- `followupStateUsage` default (`null` when absent);
- composition defaults (`problem_*` fields, `answer_structure_v11`);
- `problem_unit_ids_used` array normalization.
2. Rewired `assistantService` to build deep-turn input via:
- `buildAssistantDeepTurnPackagingInput(...)`
- followed by existing `assembleAssistantDeepTurnPackaging(...)` call (behavior-preserving).
3. Added focused unit tests:
- `assistantDeepTurnInputBuilder.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.13):
1. Extracted investigation-state update/persist runtime block from `assistantService` into dedicated adapter:
- `assistantInvestigationStateRuntimeAdapter.ts`
- introduced:
- `buildAssistantInvestigationStateSnapshot(...)`
- `persistAssistantInvestigationStateSnapshot(...)`
2. Rewired `assistantService` to consume new adapter (behavior-preserving):
- same `investigation_state` snapshot semantics;
- same `FEATURE_ASSISTANT_INVESTIGATION_STATE_V1` gating;
- same session persistence call path.
3. Added focused unit tests:
- `assistantInvestigationStateRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.14):
1. Extracted deep-lane assistant post-turn commit/persist/log block from `assistantService` into dedicated adapter:
- `assistantTurnCommitRuntimeAdapter.ts`
- introduced:
- `commitAssistantTurnAndLog(...)`
2. Rewired `assistantService` deep-lane to use new adapter (behavior-preserving):
- same append-to-session semantics;
- same session persistence behavior when session exists;
- same `assistant_message_processed` log envelope and event type.
3. Added focused unit tests:
- `assistantTurnCommitRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.15):
1. Extracted deep-lane pre-packaging context assembly from `assistantService` into dedicated module:
- `assistantDeepTurnPrePackagingContext.ts`
- centralized:
- dropped intent segments extraction;
- analysis context projection for contracts;
- debug route projection;
- resolved execution state projection;
- safe assistant reply base sanitization.
2. Rewired `assistantService` deep-lane to consume `buildAssistantDeepTurnPrePackagingContext(...)` (behavior-preserving).
3. Added focused unit tests:
- `assistantDeepTurnPrePackagingContext.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.16):
1. Extracted deep-lane success response envelope assembly from `assistantService` into dedicated builder:
- `assistantDeepTurnResponseBuilder.ts`
- introduced:
- `buildAssistantDeepTurnSuccessResponse(...)`
2. Rewired `assistantService` deep-lane to return response via new builder (behavior-preserving).
3. Added focused unit tests:
- `assistantDeepTurnResponseBuilder.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.17):
1. Extracted deep-lane composition assembly from `assistantService` into dedicated runtime adapter:
- `assistantDeepTurnCompositionRuntimeAdapter.ts`
- introduced:
- `buildAssistantDeepTurnComposition(...)`
2. Centralized composition-time derivations (behavior-preserving):
- `focusDomainHint` from followup usage + investigation state;
- `questionTypeClass` via `resolveQuestionType(...)`;
- period presence signals from company anchors/normalization payload;
- downstream `composeAssistantAnswer(...)` call wiring.
3. Rewired `assistantService` deep-lane to consume adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.18):
1. Extracted deep-lane guard runtime pipeline from `assistantService` into dedicated adapter:
- `assistantDeepTurnGuardRuntimeAdapter.ts`
- introduced:
- `applyAssistantDeepTurnRetrievalGuards(...)`
- `applyAssistantDeepTurnGroundingEligibility(...)`
2. Centralized and isolated runtime sequence (behavior-preserving):
- polarity guard on retrieval results;
- targeted evidence acquisition;
- evidence admissibility gate;
- grounded-answer eligibility evaluation + grounding status overlay.
3. Rewired `assistantService` deep-lane to consume adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.19):
1. Extracted deep-lane retrieval execution loop from `assistantService` into dedicated runtime adapter:
- `assistantDeepTurnRetrievalRuntimeAdapter.ts`
- introduced:
- `executeAssistantDeepTurnRetrievalPlan(...)`
2. Centralized retrieval runtime behavior (behavior-preserving):
- skipped/no-route call record generation;
- sequential route execution with temporal hint propagation;
- raw result capture;
- failed-route fallback normalization with stable error envelope.
3. Rewired `assistantService` deep-lane to consume retrieval adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.20):
1. Extracted deep-lane execution-plan assembly/enforcement from `assistantService` into dedicated runtime adapter:
- `assistantDeepTurnPlanRuntimeAdapter.ts`
- introduced:
- `buildAssistantDeepTurnExecutionPlan(...)`
2. Centralized planning runtime sequence (behavior-preserving):
- requirement extraction by fragment;
- execution plan build from route summary;
- RBP route-plan enforcement;
- FA route-plan enforcement;
- temporal hint overlay;
- polarity hint overlay.
3. Rewired `assistantService` deep-lane to consume adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnPlanRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
- `assistantDeepTurnPlanRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.21):
1. Extracted deep-lane pre-guard runtime context assembly from `assistantService` into dedicated adapter:
- `assistantDeepTurnContextRuntimeAdapter.ts`
- introduced:
- `buildAssistantDeepTurnRuntimeContext(...)`
2. Centralized context runtime sequence (behavior-preserving):
- company anchors resolution;
- initial business-scope alignment;
- P0 domain inference + domain whitelist gating for guard focus;
- temporal guard resolution with runtime analysis context;
- domain polarity guard resolution;
- claim-bound anchors resolution;
- live business-scope resolution with followup flag;
- normalized live temporal hint projection.
3. Rewired `assistantService` deep-lane to consume context adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnContextRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
- `assistantDeepTurnPlanRuntimeAdapter.test.ts`
- `assistantDeepTurnContextRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.22):
1. Extracted deep-lane post-retrieval grounding runtime orchestration from `assistantService` into dedicated adapter:
- `assistantDeepTurnGroundingRuntimeAdapter.ts`
- introduced:
- `runAssistantDeepTurnGroundingRuntime(...)`
2. Centralized grounding/runtime sequence (behavior-preserving):
- RBP live-route audit projection;
- FA live-route audit projection;
- coverage+grounding pipeline execution;
- grounded-answer eligibility overlay on base grounding check.
3. Rewired `assistantService` deep-lane to consume adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnGroundingRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
- `assistantDeepTurnPlanRuntimeAdapter.test.ts`
- `assistantDeepTurnContextRuntimeAdapter.test.ts`
- `assistantDeepTurnGroundingRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.23):
1. Extracted deep-lane packaging orchestration block from `assistantService` into dedicated runtime adapter:
- `assistantDeepTurnPackagingRuntimeAdapter.ts`
- introduced:
- `runAssistantDeepTurnPackagingRuntime(...)`
2. Centralized packaging/runtime sequence (behavior-preserving):
- pre-packaging context assembly;
- investigation-state snapshot build/persist;
- deep-turn packaging input assembly;
- deep-turn packaging output projection (`safeAssistantReply`, debug payload, assistant item, processed log details).
3. Rewired `assistantService` deep-lane to consume packaging runtime adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnPackagingRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
- `assistantDeepTurnPlanRuntimeAdapter.test.ts`
- `assistantDeepTurnContextRuntimeAdapter.test.ts`
- `assistantDeepTurnGroundingRuntimeAdapter.test.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.24):
1. Extracted deep-lane finalization/response tail from `assistantService` into dedicated runtime adapter:
- `assistantDeepTurnFinalizeRuntimeAdapter.ts`
- introduced:
- `finalizeAssistantDeepTurn(...)`
2. Centralized finalization runtime sequence (behavior-preserving):
- assistant turn commit + processed-event logging;
- deep-turn API success response assembly from committed conversation state.
3. Rewired `assistantService` deep-lane to consume finalization adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantDeepTurnFinalizeRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 assembler/adapter pack passed:
- `assistantOrchestrationContracts.test.ts`
- `assistantOrchestrationRuntimeAdapter.test.ts`
- `assistantAnswerPackageBuilder.test.ts`
- `assistantCoverageGrounding.test.ts`
- `assistantQueryPlanning.test.ts`
- `assistantEvidenceBundleAssembler.test.ts`
- `assistantDebugPayloadAssembler.test.ts`
- `assistantMessageLogAssembler.test.ts`
- `assistantContractsBundleAssembler.test.ts`
- `assistantDeepResponseAssembler.test.ts`
- `assistantDeepTurnPackaging.test.ts`
- `assistantDeepTurnInputBuilder.test.ts`
- `assistantInvestigationStateRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
- `assistantDeepTurnPrePackagingContext.test.ts`
- `assistantDeepTurnResponseBuilder.test.ts`
- `assistantDeepTurnCompositionRuntimeAdapter.test.ts`
- `assistantDeepTurnGuardRuntimeAdapter.test.ts`
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
- `assistantDeepTurnPlanRuntimeAdapter.test.ts`
- `assistantDeepTurnContextRuntimeAdapter.test.ts`
- `assistantDeepTurnGroundingRuntimeAdapter.test.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.test.ts`
- `assistantDeepTurnFinalizeRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Implemented in current pass (Phase 2.25):
1. Extracted address-lane finalization/response tail from `assistantService` into dedicated runtime adapter:
- `assistantAddressTurnFinalizeRuntimeAdapter.ts`
- introduced:
- `finalizeAssistantAddressTurn(...)`
2. Centralized address finalization runtime sequence (behavior-preserving):
- assistant item creation for address lane;
- structured `assistant_message_address` processed-event payload build;
- turn commit/persist/log via shared commit runtime adapter;
- API success response assembly from committed conversation state.
3. Rewired `assistantService` address-lane finalize path to consume adapter output (behavior-preserving).
4. Added focused unit tests:
- `assistantAddressTurnFinalizeRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted Stage 2 adapter/finalization pack passed:
- `assistantAddressTurnFinalizeRuntimeAdapter.test.ts`
- `assistantDeepTurnFinalizeRuntimeAdapter.test.ts`
- `assistantTurnCommitRuntimeAdapter.test.ts`
3. Additional safety regressions passed:
- `assistantWave10SettlementCorrectiveRegression.test.ts`
- `assistantMcpRuntimeBridge.test.ts`
- `assistantAddressFollowupContext.test.ts`
Status: **In progress (Phase 2.1 + 2.2 + 2.3 + 2.4 + 2.5 + 2.6 + 2.7 + 2.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 + 2.14 + 2.15 + 2.16 + 2.17 + 2.18 + 2.19 + 2.20 + 2.21 + 2.22 + 2.23 + 2.24 + 2.25 completed)**
## Stage 3 (P2): Hybrid Semantic Layer (LLM + Deterministic Guards)
Goal:
1. Use LLM for semantic extraction/decomposition in strict schema.
2. Keep deterministic guardrails as verifier, not primary “brain”.
3. Reduce dictionary overfitting and false route drifts.
Status: Planned
## Stage 4 (P2): Human-Centric Answer Layer
Goal:
1. Move final user response to contract-driven answer package with:
- direct answer;
- what was checked;
- what was found;
- what remains unproven;
- best next step.
2. Keep claim-to-evidence binding strict.
Status: Planned
## Stage 5 (P3): Quality Loop Driven By GUI Markup
Goal:
1. Drive backlog from `manual_case_decision` queues.
2. Build targeted regression packs from real failed comments.
3. Track trend by reason-code clusters.
Status: Planned
## 6. Non-Negotiable Constraints
1. Do not break MCP route interfaces.
2. Do not remove manual logic without compatible replacement.
3. Preserve UTF-8 (without BOM) for all source/doc files.
4. Keep manual markup and autorun API contract stable.