FE-554: Structured interview: scope phase#17
Conversation
3cab7ca to
2d37ff7
Compare
231bff6 to
1e4e403
Compare
Replace generic chat with scope-phase structured interview. Core changes: - interview.ts: phase-specific system prompts, Zod schema for structured questions, in-process MCP server with ask_question tool that persists question/why/impact/options via closure - core.ts: conductTurn uses getSystemPrompt + createInterviewMcpServer per turn, formatHistory includes structured context (why, impact) - db.ts: getOptionsForTurn, selectOption, updateTurn accepts why/impact 14 new tests (86 total): schema validation (5), system prompts (2), MCP server creation and tool handler persistence (2), conductTurn config (2), history formatting (1), option CRUD (2). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Phase parameter on conductTurn (was hardcoded 'scope') 2. interview.ts docstring clarifies shell boundary 3. Deduplicate Zod schema — tool uses structuredQuestionSchema.shape 4. formatHistory includes options with recommendation/selection markers 5. getTurn replaces redundant getActivePath call for single-turn check 6. A13 revised in SPEC.md — validated via system prompt + MCP tools, not SDK AgentDefinition skills 7. Round-trip oracle test: structured turn → persist → active path 88 tests passing (2 new: options-in-history, round-trip persistence). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- PLAN.md: mark slice 4 in-progress (server done, client pending) - SPEC.md: add I16 (schema validation on agent tool output) - SPEC.md: add ask_question tool and interview MCP server to Lexicon - SPEC.md: update phase term with concrete mechanism - SPEC.md: update coverage table (app.test.ts 15→17, +interview.test.ts) - PLAN.md: retire slice 4 parallelism note Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d4d56-9083-7259-865e-7bd338bbe27e Co-authored-by: Amp <amp@ampcode.com>
…bserver sync) - New decision D22: in-band data parts on existing SSE (default), out-of-band EventSource (fallback). TanStack DB evaluated and rejected. - New assumptions A20 (observer latency in-band), A21 (onData stale closure) - New constraint: No TanStack DB - Promote observer-complete from future to planned in D19 - Add lexicon: in-band sync, out-of-band sync, cache invalidation - Slice 5: trace to D22, A20; post-commit event requirement - Slice 6: trace to D22, A21; TanStack Query cache population via onData Amp-Thread-ID: https://ampcode.com/threads/T-019d4d56-9083-7259-865e-7bd338bbe27e Co-authored-by: Amp <amp@ampcode.com>
…ing, round-trip sync Inner loop: observer-complete post-commit + entity ID consistency + SSE data-part encoding Middle loop: round-trip oracle — conductTurn with observer → event ordering → DB match Outer loop: onData → setQueryData sidebar reactivity (manual, validates A21) Blind spot: onData stale-closure risk (ai-sdk#550); fallback to EventSource if broken Amp-Thread-ID: https://ampcode.com/threads/T-019d4d56-9083-7259-865e-7bd338bbe27e Co-authored-by: Amp <amp@ampcode.com>
1e4e403 to
246126c
Compare
229ed2d to
a36f0d5
Compare
…xt builders) - D23: UIMessage/ModelMessage split — persist parts[] JSON alongside turn scalars for faithful UI resume; inference context derived by builders - D24: Custom Data Parts for structured user input (option-selection, confirmation) and domain-specific assistant output (phase-summary, observer-result) - D25: Typed context builders replace monolithic formatHistory() — different projections per consumer (interviewer, observer, phase judge) - D15 superseded by D23 (transitional turn-field inversion → parts-based) - A22, A23 added for parts persistence assumptions - Slice 4 split into 4 (server, done), 4a (parts+context), 4b (client UI) - Lexicon updated: UIMessage, ModelMessage, parts[], Data Part, context builder - Research ref: docs/research/Chat Application Data Models... Amp-Thread-ID: https://ampcode.com/threads/T-019d4d58-261d-706a-90e9-6987dbd162ff Co-authored-by: Amp <amp@ampcode.com>
- I17: Data Part schema validation (Zod on structured user input) - I18: Parts round-trip fidelity (DomainEvents → persist → hydrate) - I19: Context builder equivalence (buildInterviewerContext matches formatHistory) - Inner loop: fast unit tests — parts added to oracle strategy - Blind spot: parts/scalar consistency deferred as metamorphic oracle - Slice 4a: drop backward-compat fallback (DB re-init is safe), oracle-informed acceptance criteria and verification approach Amp-Thread-ID: https://ampcode.com/threads/T-019d4d58-261d-706a-90e9-6987dbd162ff Co-authored-by: Amp <amp@ampcode.com>
🤖 Augment PR SummarySummary: Implements the server-side “scope phase” structured interview flow using an in-process MCP tool with schema validation, replacing generic chat prompting. Changes:
🤖 Was this summary useful? React with 👍 or 👎 |
| why: args.why, | ||
| impact: args.impact as Impact, | ||
| }); | ||
| for (let i = 0; i < args.options.length; i++) { |
There was a problem hiding this comment.
src/server/interview.ts:91 — The ask_question handler always inserts options at positions starting from 0 without clearing existing rows; because option_turn_position_unique enforces (turn_id, position), a second tool invocation/retry for the same turn can throw and leave the turn partially persisted.
Severity: high
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| import { createOption, updateTurn, type DB, type Impact, type Phase } from './db.js'; | ||
|
|
||
| /** Zod schema for the ask_question tool output. */ | ||
| export const structuredQuestionSchema = z.object({ |
There was a problem hiding this comment.
src/server/interview.ts:14 — The scope system prompt requires marking exactly one option as recommended, but structuredQuestionSchema doesn’t validate that invariant (0 or multiple is_recommended: true are accepted), which could make “recommended” ambiguous downstream.
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| .all() as Option[]; | ||
| } | ||
|
|
||
| export function selectOption(db: DB, turnId: number, position: number): void { |
There was a problem hiding this comment.
src/server/db.ts:150 — selectOption clears all selections for the turn before ensuring an option exists at the requested position; if an invalid position is passed, the prior selection is lost and the turn ends up with no selection.
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| - Branch: `ln/fe-541-rich-chat-ui` | ||
|
|
||
| 4. **Structured interview: scope phase** — Replace flat chat with structured turns. Implement the scope phase as an agent skill — the agent generates a question with options, grounding ("why this matters"), and impact signal. User selects an option or types a response. Turn persists with phase provenance. UI renders the turn card (question + options + grounding). `not-started` | ||
| 4. **Structured interview: scope phase (server)** `FE-554` — Replace flat chat with structured turns. Implement the scope phase as an agent skill — the agent generates a question with options, grounding ("why this matters"), and impact signal via `ask_question` MCP tool. Turn persists with phase provenance (question, why, impact, options). `done` |
There was a problem hiding this comment.
PR metadata: the PR title doesn’t follow the repo naming rule for issue-scoped PRs (expected FE-554: … per (Rule: AGENTS.md)); consider aligning it so stack/issue traceability stays consistent.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

feat: structured interview scope phase with SDK MCP tools
Replace generic chat with scope-phase structured interview. Core
changes:
structured questions, in-process MCP server with ask_question tool
that persists question/why/impact/options via closure
per turn, formatHistory includes structured context (why, impact)
14 new tests (86 total): schema validation (5), system prompts (2),
MCP server creation and tool handler persistence (2), conductTurn
config (2), history formatting (1), option CRUD (2).
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
refactor: address ln-review findings for slice 4
not SDK AgentDefinition skills
88 tests passing (2 new: options-in-history, round-trip persistence).
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com