@principal-ai/subsystems-react 0.56.34 → 0.56.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/subsystem/SubsystemComponentGraph.d.ts +106 -2
  2. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  3. package/dist/subsystem/SubsystemComponentGraph.js +454 -70
  4. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  5. package/dist/subsystem/TrailStepsNav.d.ts +4 -2
  6. package/dist/subsystem/TrailStepsNav.d.ts.map +1 -1
  7. package/dist/subsystem/TrailStepsNav.js +14 -4
  8. package/dist/subsystem/TrailStepsNav.js.map +1 -1
  9. package/dist/subsystem/TrailsPanel.d.ts +18 -2
  10. package/dist/subsystem/TrailsPanel.d.ts.map +1 -1
  11. package/dist/subsystem/TrailsPanel.js +40 -18
  12. package/dist/subsystem/TrailsPanel.js.map +1 -1
  13. package/dist/subsystem/model.d.ts +27 -6
  14. package/dist/subsystem/model.d.ts.map +1 -1
  15. package/dist/subsystem/model.js +48 -45
  16. package/dist/subsystem/model.js.map +1 -1
  17. package/dist/subsystem/nodeIconography.d.ts +25 -0
  18. package/dist/subsystem/nodeIconography.d.ts.map +1 -0
  19. package/dist/subsystem/nodeIconography.js +55 -0
  20. package/dist/subsystem/nodeIconography.js.map +1 -0
  21. package/dist/subsystem/nodes.d.ts +4 -3
  22. package/dist/subsystem/nodes.d.ts.map +1 -1
  23. package/dist/subsystem/nodes.js +149 -153
  24. package/dist/subsystem/nodes.js.map +1 -1
  25. package/dist/subsystem/stepEmphasis.d.ts +5 -0
  26. package/dist/subsystem/stepEmphasis.d.ts.map +1 -1
  27. package/dist/subsystem/stepEmphasis.js +7 -0
  28. package/dist/subsystem/stepEmphasis.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/stories/Canvases/Subsystem/AgentDrivenWalkthrough.stories.tsx +2079 -0
  31. package/src/stories/Canvases/Subsystem/Deprecated.stories.tsx +1 -1
  32. package/src/stories/Canvases/Subsystem/NodeAnatomy.stories.tsx +17 -21
  33. package/src/stories/Canvases/Subsystem/NodeIconography.stories.tsx +960 -0
  34. package/src/stories/Canvases/Subsystem/Spotlights.stories.tsx +1 -1
  35. package/src/subsystem/SubsystemComponentGraph.tsx +609 -70
  36. package/src/subsystem/TrailStepsNav.tsx +16 -4
  37. package/src/subsystem/TrailsPanel.tsx +86 -12
  38. package/src/subsystem/model.test.ts +17 -13
  39. package/src/subsystem/model.ts +66 -48
  40. package/src/subsystem/nodeIconography.ts +88 -0
  41. package/src/subsystem/nodes.component.test.tsx +177 -0
  42. package/src/subsystem/nodes.tsx +256 -174
  43. package/src/subsystem/stepEmphasis.ts +8 -0
@@ -0,0 +1,2079 @@
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
+ import "@xyflow/react/dist/style.css";
3
+ import type { Meta, StoryObj } from "@storybook/react";
4
+ import {
5
+ ThemeProvider,
6
+ defaultEditorTheme,
7
+ useTheme,
8
+ } from "@principal-ade/industry-theme";
9
+ import {
10
+ SubsystemComponentGraph,
11
+ type SubsystemTrailStepHistory,
12
+ } from "../../../subsystem/SubsystemComponentGraph";
13
+ import {
14
+ HOST_PROPOSAL_COLOR,
15
+ type SubsystemComponent,
16
+ type SubsystemTrail,
17
+ type SubsystemTrailStep,
18
+ } from "../../../subsystem/model";
19
+ import {
20
+ buildStepEmphasisMap,
21
+ emphasisKey,
22
+ stepClaimKey,
23
+ variationStepNumber,
24
+ type StepEmphasisRecord,
25
+ } from "../../../subsystem/stepEmphasis";
26
+
27
+ /**
28
+ * PROTOTYPE: simulate an agent driving a subsystem model without ACP.
29
+ *
30
+ * The fake tool-call stream below mirrors the shape the electron host will
31
+ * eventually emit. It drives the graph with `focusedTrailStep`, `stepEmphasis`,
32
+ * and `sidebarAfterDescription`. A proposed trail, step replacement or new
33
+ * component is appended as the final guided-walkthrough step and announced in
34
+ * the guide header, without stealing the current step. A `walk-steps` call
35
+ * advances the guide on its own `pauseMs` clock; manual navigation cancels that
36
+ * run. Plain `agent` events narrate; separate `agent-working` events turn on the
37
+ * working indicator; separate `agent-decision` events resolve proposals in
38
+ * conversation. An accepted step change keeps a host-local previous-state ghost
39
+ * beneath the committed step, with a Hide/Show toggle. An accepted component
40
+ * removal leaves a dim REMOVED ghost in the graph. There are no confirm/decline
41
+ * buttons. Nothing here changes the portable model document.
42
+ */
43
+ const meta = {
44
+ title: "Canvases/Subsystem/Prototypes/Agent-Driven Walkthrough",
45
+ component: SubsystemComponentGraph,
46
+ parameters: {
47
+ layout: "fullscreen",
48
+ docs: {
49
+ description: {
50
+ component:
51
+ "Story-only driving harness: a fake agent stream opens the subsystem model, focuses trails, walks guide steps on a configurable pause, and appends a host-local proposal as the final guide step. Distinct agent-working events turn on the working indicator, and distinct agent-decision events accept or decline the proposal in conversation; there are no decision buttons. Accepted step changes show a host-local before/after ghost with a Hide/Show toggle; accepted removals stay as dim REMOVED nodes. Use Animate opening to replay the opening tool call.",
52
+ },
53
+ },
54
+ },
55
+ decorators: [
56
+ (Story) => (
57
+ <ThemeProvider theme={defaultEditorTheme}>
58
+ <Story />
59
+ </ThemeProvider>
60
+ ),
61
+ ],
62
+ } satisfies Meta<typeof SubsystemComponentGraph>;
63
+
64
+ export default meta;
65
+ type Story = StoryObj<typeof meta>;
66
+
67
+ const PURL = "pkg:github/acme/booking-web";
68
+ const stepPurl = (file: string) => `${PURL}#${file}`;
69
+
70
+ const seedComponents: SubsystemComponent[] = [
71
+ {
72
+ alias: "ui",
73
+ name: "BookingPage",
74
+ construct: "function",
75
+ file: "src/ui/BookingPage.tsx",
76
+ purl: PURL,
77
+ symbol: "BookingPage",
78
+ purpose: "picks a slot and submits the booking",
79
+ process: "booking-web/client",
80
+ },
81
+ {
82
+ alias: "api",
83
+ name: "checkoutApi",
84
+ construct: "function",
85
+ file: "src/api/checkout.ts",
86
+ purl: PURL,
87
+ symbol: "checkoutApi",
88
+ purpose: "validates and books a slot",
89
+ process: "booking-web/server",
90
+ },
91
+ {
92
+ alias: "store",
93
+ name: "BookingStore",
94
+ construct: "class",
95
+ file: "src/store/bookingStore.ts",
96
+ purl: PURL,
97
+ symbol: "BookingStore",
98
+ purpose: "retains bookings",
99
+ process: "booking-web/server",
100
+ },
101
+ {
102
+ alias: "mailer",
103
+ name: "Mailer",
104
+ construct: "external",
105
+ file: "src/services/mailer.ts",
106
+ purl: PURL,
107
+ symbol: "Mailer",
108
+ purpose: "sends confirmations and refunds",
109
+ role: "service",
110
+ },
111
+ ];
112
+
113
+ const seedTrails: SubsystemTrail[] = [
114
+ {
115
+ id: "wt-book",
116
+ title: "Book a slot",
117
+ steps: [
118
+ {
119
+ from: "ui",
120
+ to: "api",
121
+ mechanism: "calls",
122
+ file: "src/ui/BookingPage.tsx",
123
+ span: { startLine: 42, endLine: 42, contentHash: "fixture" },
124
+ purl: stepPurl("src/ui/BookingPage.tsx"),
125
+ symbol: "BookingPage.submit",
126
+ annotation: "Submit hands the picked slot to the API.",
127
+ },
128
+ {
129
+ from: "api",
130
+ to: "store",
131
+ mechanism: "writes",
132
+ file: "src/api/checkout.ts",
133
+ span: { startLine: 18, endLine: 18, contentHash: "fixture" },
134
+ purl: stepPurl("src/api/checkout.ts"),
135
+ symbol: "checkoutApi.book",
136
+ annotation: "The API writes the booking into the store.",
137
+ },
138
+ {
139
+ from: "store",
140
+ to: "mailer",
141
+ mechanism: "produces",
142
+ file: "src/store/bookingStore.ts",
143
+ span: { startLine: 27, endLine: 27, contentHash: "fixture" },
144
+ purl: stepPurl("src/store/bookingStore.ts"),
145
+ symbol: "BookingStore.confirm",
146
+ annotation: "The stored booking triggers the confirmation email.",
147
+ },
148
+ ],
149
+ },
150
+ {
151
+ id: "wt-cancel",
152
+ title: "Cancel a booking",
153
+ steps: [
154
+ {
155
+ from: "ui",
156
+ to: "api",
157
+ mechanism: "calls",
158
+ file: "src/ui/BookingPage.tsx",
159
+ span: { startLine: 61, endLine: 61, contentHash: "fixture" },
160
+ purl: stepPurl("src/ui/BookingPage.tsx"),
161
+ symbol: "BookingPage.cancel",
162
+ annotation: "Cancel sends the booking id to the API.",
163
+ },
164
+ {
165
+ from: "api",
166
+ to: "store",
167
+ mechanism: "writes",
168
+ file: "src/api/checkout.ts",
169
+ span: { startLine: 33, endLine: 33, contentHash: "fixture" },
170
+ purl: stepPurl("src/api/checkout.ts"),
171
+ symbol: "checkoutApi.cancel",
172
+ annotation: "The API marks the stored booking cancelled.",
173
+ },
174
+ ],
175
+ },
176
+ ];
177
+
178
+ const proposedTrail: SubsystemTrail = {
179
+ id: "wt-refund",
180
+ title: "Refund a cancelled booking",
181
+ steps: [
182
+ {
183
+ from: "store",
184
+ to: "mailer",
185
+ mechanism: "produces",
186
+ file: "src/store/bookingStore.ts",
187
+ span: { startLine: 44, endLine: 44, contentHash: "proposed" },
188
+ purl: stepPurl("src/store/bookingStore.ts"),
189
+ symbol: "BookingStore.refund",
190
+ annotation: "Emit a refund intent once the cancellation is committed.",
191
+ },
192
+ {
193
+ from: "mailer",
194
+ to: "ui",
195
+ mechanism: "feeds",
196
+ file: "src/services/mailer.ts",
197
+ span: { startLine: 12, endLine: 12, contentHash: "proposed" },
198
+ purl: stepPurl("src/services/mailer.ts"),
199
+ symbol: "Mailer.refundNotice",
200
+ annotation: "Return the refund status to the booking page.",
201
+ },
202
+ ],
203
+ };
204
+
205
+ // Host-local replacement for one step of an existing trail. Only the step text
206
+ // changes; the trail and the portable model document stay as authored.
207
+ const proposedCancelStep: SubsystemTrailStep = {
208
+ from: "api",
209
+ to: "mailer",
210
+ mechanism: "produces",
211
+ file: "src/api/checkout.ts",
212
+ span: { startLine: 33, endLine: 33, contentHash: "proposed" },
213
+ purl: stepPurl("src/api/checkout.ts"),
214
+ symbol: "checkoutApi.refundNotice",
215
+ annotation: "Cancel emits a refund notice instead of stopping at the store.",
216
+ };
217
+
218
+ // Host-local component proposal. It exists only while the host is showing the
219
+ // proposal (and after the user accepts it), never in the portable document.
220
+ const proposedRefundService: SubsystemComponent = {
221
+ alias: "refund",
222
+ name: "RefundService",
223
+ construct: "class",
224
+ file: "src/services/refundService.ts",
225
+ purl: PURL,
226
+ symbol: "RefundService",
227
+ purpose: "owns refund notices for cancelled bookings",
228
+ process: "booking-web/server",
229
+ };
230
+
231
+ const proposedRefundServiceTrail: SubsystemTrail = {
232
+ id: "wt-refund-service",
233
+ title: "Refund a cancelled booking",
234
+ steps: [
235
+ {
236
+ from: "store",
237
+ to: "refund",
238
+ mechanism: "produces",
239
+ file: "src/store/bookingStore.ts",
240
+ span: { startLine: 44, endLine: 44, contentHash: "proposed" },
241
+ purl: stepPurl("src/store/bookingStore.ts"),
242
+ symbol: "BookingStore.refundRequested",
243
+ annotation: "Emit a refund intent once the cancellation is committed.",
244
+ },
245
+ {
246
+ from: "refund",
247
+ to: "ui",
248
+ mechanism: "feeds",
249
+ file: "src/services/refundService.ts",
250
+ span: { startLine: 12, endLine: 12, contentHash: "proposed" },
251
+ purl: stepPurl("src/services/refundService.ts"),
252
+ symbol: "RefundService.refundNotice",
253
+ annotation: "Return the refund status to the booking page.",
254
+ },
255
+ ],
256
+ };
257
+
258
+ type GuideStep = {
259
+ id: string;
260
+ title: string;
261
+ trailId: string;
262
+ /** Omit for whole-trail focus (no file drawer). */
263
+ stepIndex?: number;
264
+ /** Host-driven focus is file-free; set true only to demo an explicit open. */
265
+ showFile?: boolean;
266
+ body: string;
267
+ /** Added as step emphasis when this step becomes active. */
268
+ guidance?: string;
269
+ /** Marks the step as a host-local proposal awaiting agent resolution. */
270
+ proposal?: "trail" | "step" | "component" | "removal";
271
+ };
272
+
273
+ type DriveEvent =
274
+ | { kind: "open-model"; id: string; tool: string; text: string }
275
+ | { kind: "prompt"; id: string; text: string }
276
+ /** Plain narration. It does not change the working indicator. */
277
+ | { kind: "agent"; id: string; text: string }
278
+ /** The agent explicitly starts working on a named part of the model. */
279
+ | {
280
+ kind: "agent-working";
281
+ id: string;
282
+ text: string;
283
+ workingOn: string;
284
+ }
285
+ /** The agent resolves the current proposal in conversation. */
286
+ | {
287
+ kind: "agent-decision";
288
+ id: string;
289
+ text: string;
290
+ decision: "accepted" | "rejected";
291
+ }
292
+ | {
293
+ kind: "guide";
294
+ id: string;
295
+ tool: string;
296
+ question: string;
297
+ steps: GuideStep[];
298
+ }
299
+ | {
300
+ kind: "walk-steps";
301
+ id: string;
302
+ tool: string;
303
+ pauseMs: number;
304
+ stepIds: string[];
305
+ }
306
+ | {
307
+ kind: "propose-trail";
308
+ id: string;
309
+ tool: string;
310
+ trail: SubsystemTrail;
311
+ rationale: string;
312
+ }
313
+ | {
314
+ kind: "propose-step";
315
+ id: string;
316
+ tool: string;
317
+ trailId: string;
318
+ stepIndex: number;
319
+ step: SubsystemTrailStep;
320
+ rationale: string;
321
+ }
322
+ | {
323
+ kind: "propose-component";
324
+ id: string;
325
+ tool: string;
326
+ component: SubsystemComponent;
327
+ trail: SubsystemTrail;
328
+ rationale: string;
329
+ }
330
+ | {
331
+ kind: "propose-component-removal";
332
+ id: string;
333
+ tool: string;
334
+ componentAlias: string;
335
+ rationale: string;
336
+ };
337
+
338
+ /**
339
+ * A proposal is a variation of the step currently under discussion, not the
340
+ * next sequential guide step. `2 · Where it stops` therefore yields `2a`.
341
+ */
342
+ function stepNumberFromTitle(title: string): number | null {
343
+ const match = title.match(/^\s*(\d+)[a-z]?\s*(?:·|-|:|$)/i);
344
+ return match ? Number(match[1]) : null;
345
+ }
346
+
347
+ function proposalStepTitle(
348
+ walkthrough: { steps: readonly GuideStep[] } | null | undefined,
349
+ label: string,
350
+ ): string {
351
+ const steps = walkthrough?.steps ?? [];
352
+ // The last authored guide step is the one the proposal responds to; autoplay
353
+ // may not have advanced the host's active step when the proposal lands.
354
+ const target = steps[steps.length - 1];
355
+ const base = target ? stepNumberFromTitle(target.title) : null;
356
+ return `${variationStepNumber(base ?? 1)} · ${label}`;
357
+ }
358
+
359
+ const trailProposalEvents: DriveEvent[] = [
360
+ {
361
+ kind: "prompt",
362
+ id: "ev-prompt",
363
+ text: "Walk me through how a booking is confirmed, then suggest what is missing for refunds.",
364
+ },
365
+ {
366
+ kind: "agent",
367
+ id: "ev-agent-1",
368
+ text: "I found a path through the booking flow. I will frame the whole trail first, then walk it step by step and call out the confirmation hop when we reach it.",
369
+ },
370
+ {
371
+ kind: "open-model",
372
+ id: "ev-open-model",
373
+ tool: "open_subsystem_model",
374
+ text: "Open the subsystem model artifact so the walkthrough has somewhere to land.",
375
+ },
376
+ {
377
+ kind: "guide",
378
+ id: "ev-guide",
379
+ tool: "subsystem_model_guided_walkthrough",
380
+ question:
381
+ "Where does confirmation happen, and what is missing for refunds?",
382
+ steps: [
383
+ {
384
+ id: "gs-frame",
385
+ title: "1 · Frame the trail",
386
+ trailId: "wt-book",
387
+ body: "Select the whole booking flow first. No file opens — this is trail-level focus.",
388
+ },
389
+ {
390
+ id: "gs-submit",
391
+ title: "2 · Submit",
392
+ trailId: "wt-book",
393
+ stepIndex: 0,
394
+ body: "The page sends the selected slot to the API. Nothing is durable yet.",
395
+ },
396
+ {
397
+ id: "gs-book",
398
+ title: "3 · Persist",
399
+ trailId: "wt-book",
400
+ stepIndex: 1,
401
+ body: "The API writes the booking. This is the source of truth for the next hop.",
402
+ },
403
+ {
404
+ id: "gs-confirm",
405
+ title: "4 · Confirm",
406
+ trailId: "wt-book",
407
+ stepIndex: 2,
408
+ body: "The store emits the confirmation email — the user-visible signal.",
409
+ guidance:
410
+ "This is the hop that turns a stored booking into a user-visible confirmation. It is the answer to “how do I know it succeeded?”",
411
+ },
412
+ {
413
+ id: "gs-cancel",
414
+ title: "5 · Compare with cancel",
415
+ trailId: "wt-cancel",
416
+ stepIndex: 1,
417
+ body: "Cancellation stops at the store. There is no refund hop anywhere in the model.",
418
+ },
419
+ ],
420
+ },
421
+ {
422
+ kind: "walk-steps",
423
+ id: "ev-walk-steps",
424
+ tool: "subsystem_model_walkthrough_steps",
425
+ pauseMs: 1800,
426
+ stepIds: ["gs-frame", "gs-submit", "gs-book", "gs-confirm", "gs-cancel"],
427
+ },
428
+ {
429
+ kind: "agent-working",
430
+ id: "ev-agent-2",
431
+ text: "I have walked the booking trail and compared it with cancellation. The cancellation path has no refund step, so I have appended it as the last walkthrough step.",
432
+ workingOn: "comparing cancellation with confirmation",
433
+ },
434
+ {
435
+ kind: "propose-trail",
436
+ id: "ev-propose-refund",
437
+ tool: "propose_subsystem_model_trail",
438
+ trail: proposedTrail,
439
+ rationale:
440
+ "Cancellation currently ends in the store with no user-visible refund. These two hops close that gap and reuse existing components.",
441
+ },
442
+ {
443
+ kind: "agent-working",
444
+ id: "ev-agent-3",
445
+ text: "I have the refund trail staged. I am checking its hops against the cancellation flow before I commit anything.",
446
+ workingOn: "reviewing the proposed refund trail",
447
+ },
448
+ {
449
+ kind: "agent-decision",
450
+ id: "ev-agent-4",
451
+ text: "The refund trail reuses components already in the model, so I am committing it to this host-local view.",
452
+ decision: "accepted",
453
+ },
454
+ ];
455
+
456
+ const stepProposalEvents: DriveEvent[] = [
457
+ {
458
+ kind: "prompt",
459
+ id: "sp-prompt",
460
+ text: "Show me where cancellation stops, then propose a better final step.",
461
+ },
462
+ {
463
+ kind: "agent",
464
+ id: "sp-agent-1",
465
+ text: "The cancel trail has two steps. I will frame the flow, stop on the store write, then propose replacing that hop with a refund notification.",
466
+ },
467
+ {
468
+ kind: "open-model",
469
+ id: "sp-open-model",
470
+ tool: "open_subsystem_model",
471
+ text: "Open the subsystem model artifact so the step change has somewhere to land.",
472
+ },
473
+ {
474
+ kind: "guide",
475
+ id: "sp-guide",
476
+ tool: "subsystem_model_guided_walkthrough",
477
+ question: "What should the cancel trail's final hop do?",
478
+ steps: [
479
+ {
480
+ id: "sp-frame",
481
+ title: "1 · Frame cancellation",
482
+ trailId: "wt-cancel",
483
+ body: "Select the existing cancel flow first. No new trail is added here.",
484
+ },
485
+ {
486
+ id: "sp-stop",
487
+ title: "2 · Where it stops",
488
+ trailId: "wt-cancel",
489
+ stepIndex: 1,
490
+ body: "The API writes the cancellation to the store. The flow ends with no user-visible refund.",
491
+ },
492
+ ],
493
+ },
494
+ {
495
+ kind: "walk-steps",
496
+ id: "sp-walk-steps",
497
+ tool: "subsystem_model_walkthrough_steps",
498
+ pauseMs: 1800,
499
+ stepIds: ["sp-frame", "sp-stop"],
500
+ },
501
+ {
502
+ kind: "agent-working",
503
+ id: "sp-agent-2",
504
+ text: "That final hop is the gap. I have appended its replacement as the last guide step — the step text turns proposal-colored until the proposal is resolved.",
505
+ workingOn: "preparing the refund step change",
506
+ },
507
+ {
508
+ kind: "propose-step",
509
+ id: "sp-propose-refund",
510
+ tool: "propose_subsystem_model_step_change",
511
+ trailId: "wt-cancel",
512
+ stepIndex: 1,
513
+ step: proposedCancelStep,
514
+ rationale:
515
+ "Replace the store write with a refund notification so cancellation has a user-visible outcome. The existing trail keeps its place in the model.",
516
+ },
517
+ {
518
+ kind: "agent-working",
519
+ id: "sp-agent-3",
520
+ text: "The replacement is staged on the existing trail. I am checking that the old hop is fully covered before applying it.",
521
+ workingOn: "reviewing the refund step change",
522
+ },
523
+ {
524
+ kind: "agent-decision",
525
+ id: "sp-agent-4",
526
+ text: "The replacement keeps the trail's place and gives cancellation a user-visible outcome, so I am applying it.",
527
+ decision: "accepted",
528
+ },
529
+ ];
530
+
531
+ const componentProposalEvents: DriveEvent[] = [
532
+ {
533
+ kind: "prompt",
534
+ id: "cp-prompt",
535
+ text: "Show me the refund gap, then propose a component that should own it.",
536
+ },
537
+ {
538
+ kind: "agent",
539
+ id: "cp-agent-1",
540
+ text: "Cancellation stops at BookingStore. I will frame that flow, stop on the gap, then propose a new RefundService box and the trail that uses it.",
541
+ },
542
+ {
543
+ kind: "open-model",
544
+ id: "cp-open-model",
545
+ tool: "open_subsystem_model",
546
+ text: "Open the subsystem model artifact so the new box has somewhere to land.",
547
+ },
548
+ {
549
+ kind: "guide",
550
+ id: "cp-guide",
551
+ tool: "subsystem_model_guided_walkthrough",
552
+ question: "Which component should own refunds after cancellation?",
553
+ steps: [
554
+ {
555
+ id: "cp-frame",
556
+ title: "1 · Frame cancellation",
557
+ trailId: "wt-cancel",
558
+ body: "Start with the existing cancel flow. The model has no refund owner yet.",
559
+ },
560
+ {
561
+ id: "cp-stop",
562
+ title: "2 · Where it stops",
563
+ trailId: "wt-cancel",
564
+ stepIndex: 1,
565
+ body: "The API writes the cancellation to BookingStore. Nothing here owns a refund.",
566
+ },
567
+ ],
568
+ },
569
+ {
570
+ kind: "walk-steps",
571
+ id: "cp-walk-steps",
572
+ tool: "subsystem_model_walkthrough_steps",
573
+ pauseMs: 1800,
574
+ stepIds: ["cp-frame", "cp-stop"],
575
+ },
576
+ {
577
+ kind: "agent-working",
578
+ id: "cp-agent-2",
579
+ text: "The missing piece is a refund owner. I have appended a proposal that adds RefundService as a new box and reuses the existing booking page.",
580
+ workingOn: "staging the RefundService box",
581
+ },
582
+ {
583
+ kind: "propose-component",
584
+ id: "cp-propose-refund-service",
585
+ tool: "propose_subsystem_model_component",
586
+ component: proposedRefundService,
587
+ trail: proposedRefundServiceTrail,
588
+ rationale:
589
+ "Add RefundService as the owner of refund notices. The proposed box is dashed and badged until it is committed.",
590
+ },
591
+ {
592
+ kind: "agent-working",
593
+ id: "cp-agent-3",
594
+ text: "The new box and its trail are staged. I am checking that no existing component already owns refunds.",
595
+ workingOn: "reviewing the RefundService proposal",
596
+ },
597
+ {
598
+ kind: "agent-decision",
599
+ id: "cp-agent-4",
600
+ text: "No existing component owns refunds, so I am committing the RefundService box and its trail.",
601
+ decision: "accepted",
602
+ },
603
+ ];
604
+
605
+ const componentRemovalEvents: DriveEvent[] = [
606
+ {
607
+ kind: "prompt",
608
+ id: "mr-prompt",
609
+ text: "The confirmation mailer is being retired. Show the impact on this model.",
610
+ },
611
+ {
612
+ kind: "agent",
613
+ id: "mr-agent-1",
614
+ text: "I will frame the booking flow, then stage the mailer removal for review.",
615
+ },
616
+ {
617
+ kind: "open-model",
618
+ id: "mr-open-model",
619
+ tool: "open_subsystem_model",
620
+ text: "Open the model so the removal can be seen in context.",
621
+ },
622
+ {
623
+ kind: "agent",
624
+ id: "mr-agent-2",
625
+ text: "The mailer only carries confirmation and refund notices, so the rest of the booking path stays.",
626
+ },
627
+ {
628
+ kind: "guide",
629
+ id: "mr-guide",
630
+ tool: "subsystem_model_guided_walkthrough",
631
+ question: "Which parts of the model disappear when the mailer is retired?",
632
+ steps: [
633
+ {
634
+ id: "mr-frame",
635
+ title: "1 · Frame confirmation",
636
+ trailId: "wt-book",
637
+ body: "Look at the booking flow before the removal. The mailer is the final hop.",
638
+ },
639
+ ],
640
+ },
641
+ {
642
+ kind: "walk-steps",
643
+ id: "mr-walk-steps",
644
+ tool: "subsystem_model_walkthrough_steps",
645
+ pauseMs: 1800,
646
+ stepIds: ["mr-frame"],
647
+ },
648
+ {
649
+ kind: "agent-working",
650
+ id: "mr-agent-3",
651
+ text: "I have staged the mailer removal as a host-local change — its box stays as a dim record.",
652
+ workingOn: "staging the confirmation mailer removal",
653
+ },
654
+ {
655
+ kind: "propose-component-removal",
656
+ id: "mr-propose-removal",
657
+ tool: "propose_subsystem_model_component_removal",
658
+ componentAlias: "mailer",
659
+ rationale:
660
+ "Retire the confirmation mailer. Its steps leave the trails, but its box remains dimmed so the removed state is visible.",
661
+ },
662
+ {
663
+ kind: "agent-working",
664
+ id: "mr-agent-4",
665
+ text: "The dependent steps are gone and no other component owns the mailer's seam. I am checking the result.",
666
+ workingOn: "reviewing the confirmation mailer removal",
667
+ },
668
+ {
669
+ kind: "agent-decision",
670
+ id: "mr-agent-5",
671
+ text: "The mailer is retired; I am applying the removal and keeping its node as a dim ghost.",
672
+ decision: "accepted",
673
+ },
674
+ ];
675
+
676
+ // Declined variants reuse the same staged proposal but resolve it in
677
+ // conversation: the agent reviews it, then leaves the model untouched.
678
+ function withFinalDecision(
679
+ events: DriveEvent[],
680
+ decision: "accepted" | "rejected",
681
+ text: string,
682
+ ): DriveEvent[] {
683
+ return events.map((event, index) =>
684
+ index === events.length - 1 && event.kind === "agent-decision"
685
+ ? { ...event, decision, text }
686
+ : event,
687
+ );
688
+ }
689
+
690
+ const trailDeclinedEvents = withFinalDecision(
691
+ trailProposalEvents,
692
+ "rejected",
693
+ "The refund trail assumes an owner that is not in the model yet, so I am keeping the model as is.",
694
+ );
695
+ const stepDeclinedEvents = withFinalDecision(
696
+ stepProposalEvents,
697
+ "rejected",
698
+ "The replacement would hide the store write, so I am keeping the original step.",
699
+ );
700
+ const componentDeclinedEvents = withFinalDecision(
701
+ componentProposalEvents,
702
+ "rejected",
703
+ "RefundService would duplicate the mailer's responsibility, so I am keeping the model as is.",
704
+ );
705
+
706
+ // `Animate opening` replays through the open call so the artifact appears
707
+ // immediately, then lets the rest of the stream continue behind it.
708
+ function openingEventCountFor(events: DriveEvent[]) {
709
+ const index = events.findIndex((event) => event.kind === "open-model");
710
+ return index < 0 ? 0 : index + 1;
711
+ }
712
+
713
+ /** Host-local before/after view retained when a step replacement is accepted. */
714
+ type StepChange = {
715
+ trailId: string;
716
+ stepIndex: number;
717
+ previous: SubsystemTrailStep;
718
+ };
719
+
720
+ type DriveState = {
721
+ modelOpen: boolean;
722
+ components: SubsystemComponent[];
723
+ trails: SubsystemTrail[];
724
+ records: StepEmphasisRecord[];
725
+ walkthrough: {
726
+ question: string;
727
+ steps: GuideStep[];
728
+ activeStepId?: string;
729
+ } | null;
730
+ pendingTrail: SubsystemTrail | null;
731
+ pendingComponent: SubsystemComponent | null;
732
+ /** Host-local component alias staged for removal. */
733
+ pendingRemoval: string | null;
734
+ /** Accepted removals: their nodes stay in place as dim ghosts. */
735
+ removedComponentAliases: Set<string>;
736
+ pendingStep: {
737
+ trailId: string;
738
+ stepIndex: number;
739
+ step: SubsystemTrailStep;
740
+ } | null;
741
+ /** Host-local auto-walk started by a `walk-steps` tool call. */
742
+ walkRun: { stepIds: string[]; pauseMs: number; index: number } | null;
743
+ /** Narrated focus from the latest agent message. */
744
+ agentWorkingOn: string | null;
745
+ lastDecision: "accepted" | "rejected" | null;
746
+ /** Host-local comparison for an accepted step change. */
747
+ stepChange: StepChange | null;
748
+ /** Unchanged steps linked to accepted changes, for shared layout + focus. */
749
+ stepHistory: SubsystemTrailStepHistory[];
750
+ };
751
+
752
+ const initialState = (): DriveState => ({
753
+ modelOpen: false,
754
+ components: seedComponents,
755
+ trails: seedTrails,
756
+ records: [],
757
+ walkthrough: null,
758
+ pendingTrail: null,
759
+ pendingComponent: null,
760
+ pendingRemoval: null,
761
+ removedComponentAliases: new Set<string>(),
762
+ pendingStep: null,
763
+ walkRun: null,
764
+ agentWorkingOn: null,
765
+ lastDecision: null,
766
+ stepChange: null,
767
+ stepHistory: [],
768
+ });
769
+
770
+ // While staged, the step proposal guide step points at the inserted variation.
771
+ // Once resolved the variation is gone, so point the same guide step back at the
772
+ // real trail step — otherwise host focus would aim past the end of the trail.
773
+ function retargetResolvedStepProposal(state: DriveState): DriveState {
774
+ const pendingStep = state.pendingStep;
775
+ if (!pendingStep || !state.walkthrough) return state;
776
+ return {
777
+ ...state,
778
+ walkthrough: {
779
+ ...state.walkthrough,
780
+ steps: state.walkthrough.steps.map((step) =>
781
+ step.proposal === "step"
782
+ ? { ...step, stepIndex: pendingStep.stepIndex }
783
+ : step,
784
+ ),
785
+ },
786
+ };
787
+ }
788
+
789
+ // The agent, not a button, resolves a staged proposal. Accepted proposals move
790
+ // from host-local pending state into the visible graph; declined ones leave the
791
+ // visible model unchanged.
792
+ function resolveProposal(
793
+ state: DriveState,
794
+ decision: "accepted" | "rejected",
795
+ ): DriveState {
796
+ if (state.lastDecision) return state;
797
+ if (decision === "rejected") {
798
+ return { ...retargetResolvedStepProposal(state), lastDecision: "rejected" };
799
+ }
800
+
801
+ const pendingRemoval = state.pendingRemoval;
802
+ if (pendingRemoval) {
803
+ const removedSteps: SubsystemTrailStepHistory[] = state.trails.flatMap(
804
+ (trail) =>
805
+ trail.steps.flatMap((step, stepIndex) =>
806
+ step.from === pendingRemoval || step.to === pendingRemoval
807
+ ? [
808
+ {
809
+ trailId: trail.id,
810
+ stepIndex,
811
+ previous: step,
812
+ kind: "removed" as const,
813
+ },
814
+ ]
815
+ : [],
816
+ ),
817
+ );
818
+ return {
819
+ ...state,
820
+ removedComponentAliases: new Set([
821
+ ...state.removedComponentAliases,
822
+ pendingRemoval,
823
+ ]),
824
+ trails: state.trails.map((trail) => ({
825
+ ...trail,
826
+ steps: trail.steps.filter(
827
+ (step) => step.from !== pendingRemoval && step.to !== pendingRemoval,
828
+ ),
829
+ })),
830
+ lastDecision: "accepted",
831
+ stepHistory: [...state.stepHistory, ...removedSteps],
832
+ };
833
+ }
834
+
835
+ const pendingComponent = state.pendingComponent;
836
+ if (pendingComponent) {
837
+ const pendingTrail = state.pendingTrail;
838
+ return {
839
+ ...state,
840
+ components: state.components.some(
841
+ (c) => c.alias === pendingComponent.alias,
842
+ )
843
+ ? state.components
844
+ : [...state.components, pendingComponent],
845
+ trails:
846
+ pendingTrail && !state.trails.some((t) => t.id === pendingTrail.id)
847
+ ? [...state.trails, pendingTrail]
848
+ : state.trails,
849
+ lastDecision: "accepted",
850
+ };
851
+ }
852
+
853
+ const pendingTrail = state.pendingTrail;
854
+ if (pendingTrail) {
855
+ if (state.trails.some((t) => t.id === pendingTrail.id)) return state;
856
+ return {
857
+ ...state,
858
+ trails: [...state.trails, pendingTrail],
859
+ lastDecision: "accepted",
860
+ };
861
+ }
862
+
863
+ const pendingStep = state.pendingStep;
864
+ if (!pendingStep) return state;
865
+ const previous = state.trails.find(
866
+ (trail) => trail.id === pendingStep.trailId,
867
+ )?.steps[pendingStep.stepIndex];
868
+ const next: DriveState = {
869
+ ...state,
870
+ // Keep the original step in place and leave its variation after it: the
871
+ // accepted row never moves, only its proposal colour is dropped.
872
+ trails: state.trails.map((trail) =>
873
+ trail.id === pendingStep.trailId
874
+ ? {
875
+ ...trail,
876
+ steps: [
877
+ ...trail.steps.slice(0, pendingStep.stepIndex + 1),
878
+ pendingStep.step,
879
+ ...trail.steps.slice(pendingStep.stepIndex + 1),
880
+ ],
881
+ }
882
+ : trail,
883
+ ),
884
+ lastDecision: "accepted",
885
+ stepChange: previous
886
+ ? {
887
+ trailId: pendingStep.trailId,
888
+ stepIndex: pendingStep.stepIndex,
889
+ previous,
890
+ }
891
+ : null,
892
+ stepHistory: previous
893
+ ? [
894
+ {
895
+ trailId: pendingStep.trailId,
896
+ stepIndex: pendingStep.stepIndex,
897
+ previous,
898
+ kind: "changed",
899
+ },
900
+ ]
901
+ : [],
902
+ };
903
+ return retargetResolvedStepProposal(next);
904
+ }
905
+
906
+ function applyEvent(event: DriveEvent, state: DriveState): DriveState {
907
+ switch (event.kind) {
908
+ case "open-model":
909
+ return { ...state, modelOpen: true };
910
+ case "agent":
911
+ return { ...state, agentWorkingOn: null };
912
+ case "agent-working":
913
+ return { ...state, agentWorkingOn: event.workingOn };
914
+ case "agent-decision":
915
+ return {
916
+ ...resolveProposal(state, event.decision),
917
+ agentWorkingOn: null,
918
+ };
919
+ case "guide":
920
+ return {
921
+ ...state,
922
+ walkthrough: {
923
+ question: event.question,
924
+ steps: event.steps,
925
+ activeStepId: event.steps[0]?.id,
926
+ },
927
+ };
928
+ case "walk-steps":
929
+ return {
930
+ ...state,
931
+ walkRun: {
932
+ stepIds: event.stepIds,
933
+ pauseMs: event.pauseMs,
934
+ index: 0,
935
+ },
936
+ walkthrough: state.walkthrough
937
+ ? {
938
+ ...state.walkthrough,
939
+ activeStepId: event.stepIds[0] ?? state.walkthrough.activeStepId,
940
+ }
941
+ : state.walkthrough,
942
+ };
943
+ case "propose-trail": {
944
+ // Append the proposal to the same guide, but keep the user's current
945
+ // step. The header advertises the new step so they can opt into it.
946
+ const proposalStep: GuideStep = {
947
+ id: "gs-propose-refund",
948
+ title: proposalStepTitle(state.walkthrough, "Confirm refund trail"),
949
+ trailId: event.trail.id,
950
+ stepIndex: 0,
951
+ showFile: false,
952
+ proposal: "trail",
953
+ body: event.rationale,
954
+ };
955
+ return {
956
+ ...state,
957
+ pendingTrail: event.trail,
958
+ lastDecision: null,
959
+ walkthrough: state.walkthrough
960
+ ? {
961
+ ...state.walkthrough,
962
+ steps: [...state.walkthrough.steps, proposalStep],
963
+ }
964
+ : state.walkthrough,
965
+ };
966
+ }
967
+ case "propose-step": {
968
+ // Focus the staged replacement, not the step it replaces. The graph's
969
+ // before/after links keep the existing step framed beside it, and the
970
+ // different index avoids re-triggering the previous step's focus toggle.
971
+ const proposalStep: GuideStep = {
972
+ id: "sp-propose-refund",
973
+ title: proposalStepTitle(state.walkthrough, "Confirm refund step"),
974
+ trailId: event.trailId,
975
+ stepIndex: event.stepIndex + 1,
976
+ showFile: false,
977
+ proposal: "step",
978
+ body: event.rationale,
979
+ };
980
+ return {
981
+ ...state,
982
+ pendingStep: {
983
+ trailId: event.trailId,
984
+ stepIndex: event.stepIndex,
985
+ step: event.step,
986
+ },
987
+ stepChange: null,
988
+ stepHistory: [],
989
+ lastDecision: null,
990
+ walkthrough: state.walkthrough
991
+ ? {
992
+ ...state.walkthrough,
993
+ steps: [...state.walkthrough.steps, proposalStep],
994
+ }
995
+ : state.walkthrough,
996
+ };
997
+ }
998
+ case "propose-component": {
999
+ const proposalStep: GuideStep = {
1000
+ id: "cp-propose-refund-service",
1001
+ title: proposalStepTitle(state.walkthrough, "Confirm component"),
1002
+ trailId: event.trail.id,
1003
+ stepIndex: 0,
1004
+ showFile: false,
1005
+ proposal: "component",
1006
+ body: event.rationale,
1007
+ };
1008
+ return {
1009
+ ...state,
1010
+ pendingComponent: event.component,
1011
+ pendingTrail: event.trail,
1012
+ lastDecision: null,
1013
+ walkthrough: state.walkthrough
1014
+ ? {
1015
+ ...state.walkthrough,
1016
+ steps: [...state.walkthrough.steps, proposalStep],
1017
+ }
1018
+ : state.walkthrough,
1019
+ };
1020
+ }
1021
+ case "propose-component-removal": {
1022
+ const proposalStep: GuideStep = {
1023
+ id: "mr-propose-remove-mailer",
1024
+ title: proposalStepTitle(
1025
+ state.walkthrough,
1026
+ "Retire confirmation mailer",
1027
+ ),
1028
+ trailId: "wt-book",
1029
+ showFile: false,
1030
+ proposal: "removal",
1031
+ body: event.rationale,
1032
+ };
1033
+ return {
1034
+ ...state,
1035
+ pendingRemoval: event.componentAlias,
1036
+ stepChange: null,
1037
+ stepHistory: [],
1038
+ lastDecision: null,
1039
+ walkthrough: state.walkthrough
1040
+ ? {
1041
+ ...state.walkthrough,
1042
+ steps: [...state.walkthrough.steps, proposalStep],
1043
+ }
1044
+ : state.walkthrough,
1045
+ };
1046
+ }
1047
+ default:
1048
+ return state;
1049
+ }
1050
+ }
1051
+
1052
+ /** Shared theme tokens plus the host-local proposal color for prototype chrome. */
1053
+ function usePrototypeTheme() {
1054
+ const { theme } = useTheme();
1055
+ return {
1056
+ theme,
1057
+ border: theme.colors.border ?? "#2d3034",
1058
+ muted: theme.colors.textMuted ?? theme.colors.textSecondary ?? "#8b95a3",
1059
+ accent: theme.colors.accent ?? theme.colors.primary ?? "#a78bfa",
1060
+ proposal: HOST_PROPOSAL_COLOR,
1061
+ mono: theme.fonts.monospace,
1062
+ small: theme.fontSizes[0],
1063
+ body: theme.fontSizes[1],
1064
+ };
1065
+ }
1066
+
1067
+ // Slow enough to read each tool call and watch the camera settle between steps.
1068
+ const AUTOPLAY_INTERVAL_MS = 1800;
1069
+
1070
+ function ToolRow({ event }: { event: DriveEvent }) {
1071
+ const { theme, border, muted, accent, mono, small } = usePrototypeTheme();
1072
+ const isAgentEvent =
1073
+ event.kind === "agent" ||
1074
+ event.kind === "agent-working" ||
1075
+ event.kind === "agent-decision";
1076
+ const label =
1077
+ event.kind === "prompt"
1078
+ ? "prompt"
1079
+ : event.kind === "agent"
1080
+ ? "agent"
1081
+ : event.kind === "agent-working"
1082
+ ? "agent · working"
1083
+ : event.kind === "agent-decision"
1084
+ ? "agent · decision"
1085
+ : event.tool;
1086
+ const detail =
1087
+ event.kind === "prompt" || isAgentEvent || event.kind === "open-model"
1088
+ ? event.text
1089
+ : event.kind === "guide"
1090
+ ? `${event.steps.length} steps · ${event.question}`
1091
+ : event.kind === "walk-steps"
1092
+ ? `${event.pauseMs}ms · ${event.stepIds.length} steps`
1093
+ : event.kind === "propose-trail"
1094
+ ? `add ${event.trail.id}`
1095
+ : event.kind === "propose-component"
1096
+ ? `add ${event.component.alias} + ${event.trail.id}`
1097
+ : `change ${event.trailId} step ${event.stepIndex + 1}`;
1098
+
1099
+ return (
1100
+ <div
1101
+ style={{
1102
+ border: `1px solid ${border}`,
1103
+ borderRadius: 6,
1104
+ padding: "8px 10px",
1105
+ display: "grid",
1106
+ gap: 4,
1107
+ background: isAgentEvent
1108
+ ? (theme.colors.backgroundHover ??
1109
+ theme.colors.backgroundSecondary ??
1110
+ theme.colors.background)
1111
+ : (theme.colors.backgroundSecondary ?? theme.colors.background),
1112
+ }}
1113
+ >
1114
+ <div
1115
+ style={{
1116
+ display: "flex",
1117
+ justifyContent: "space-between",
1118
+ gap: 8,
1119
+ fontFamily: mono,
1120
+ fontSize: small,
1121
+ color: isAgentEvent ? theme.colors.text : accent,
1122
+ }}
1123
+ >
1124
+ <span>{label}</span>
1125
+ <span style={{ color: muted }}>completed</span>
1126
+ </div>
1127
+ <div style={{ fontSize: small, lineHeight: 1.5, color: muted }}>
1128
+ {detail}
1129
+ </div>
1130
+ </div>
1131
+ );
1132
+ }
1133
+
1134
+ function Prototype({
1135
+ events,
1136
+ title,
1137
+ persistKey,
1138
+ description,
1139
+ }: {
1140
+ events: DriveEvent[];
1141
+ title: string;
1142
+ persistKey: string;
1143
+ description: string;
1144
+ }) {
1145
+ const { theme, border, muted, accent, proposal, mono, small, body } =
1146
+ usePrototypeTheme();
1147
+ const openingEventCount = useMemo(
1148
+ () => openingEventCountFor(events),
1149
+ [events],
1150
+ );
1151
+ const [state, setState] = useState<DriveState>(initialState);
1152
+ const [cursor, setCursor] = useState(0);
1153
+ const [playing, setPlaying] = useState(false);
1154
+ const [openingKey, setOpeningKey] = useState(0);
1155
+ const [drivenHeaderMode, setDrivenHeaderMode] = useState(true);
1156
+
1157
+ // Applying the open call remounts the artifact so its entrance replays each
1158
+ // time the host emits it.
1159
+ const applyDriveEvent = useCallback((event: DriveEvent) => {
1160
+ setState((prev) => applyEvent(event, prev));
1161
+ if (event.kind === "open-model") {
1162
+ setOpeningKey((prev) => prev + 1);
1163
+ }
1164
+ }, []);
1165
+
1166
+ useEffect(() => {
1167
+ if (!playing) return;
1168
+ if (cursor >= events.length) {
1169
+ setPlaying(false);
1170
+ return;
1171
+ }
1172
+ const timer = window.setTimeout(() => {
1173
+ const event = events[cursor]!;
1174
+ applyDriveEvent(event);
1175
+ setCursor((prev) => prev + 1);
1176
+ }, AUTOPLAY_INTERVAL_MS);
1177
+ return () => window.clearTimeout(timer);
1178
+ }, [cursor, playing, events, applyDriveEvent]);
1179
+
1180
+ const reset = useCallback(() => {
1181
+ setState(initialState());
1182
+ setCursor(0);
1183
+ setPlaying(false);
1184
+ }, []);
1185
+
1186
+ // Replay the host moment: prompt and agent land first, then the open call
1187
+ // reveals the artifact, then the rest of the stream arrives behind it.
1188
+ const animateOpening = useCallback(() => {
1189
+ setState(initialState());
1190
+ events.slice(0, openingEventCount).forEach(applyDriveEvent);
1191
+ setCursor(openingEventCount);
1192
+ setPlaying(true);
1193
+ }, [applyDriveEvent, events, openingEventCount]);
1194
+
1195
+ const step = useCallback(() => {
1196
+ if (cursor >= events.length) return;
1197
+ applyDriveEvent(events[cursor]!);
1198
+ setCursor((prev) => prev + 1);
1199
+ }, [cursor, events, applyDriveEvent]);
1200
+
1201
+ const emphasis = useMemo(
1202
+ () => buildStepEmphasisMap(state.records),
1203
+ [state.records],
1204
+ );
1205
+
1206
+ // A proposed component stays host-local. It is visible while awaiting a
1207
+ // decision (and after acceptance) so its box can be decorated/committed, but
1208
+ // disappears entirely on rejection.
1209
+ const visibleComponents = useMemo(() => {
1210
+ const pending = state.pendingComponent;
1211
+ if (
1212
+ !pending ||
1213
+ state.lastDecision === "rejected" ||
1214
+ state.components.some((c) => c.alias === pending.alias)
1215
+ ) {
1216
+ return state.components;
1217
+ }
1218
+ return [...state.components, pending];
1219
+ }, [state.components, state.pendingComponent, state.lastDecision]);
1220
+
1221
+ // Proposals are host-local until confirmed, but they still need to be in the
1222
+ // graph so the guide can focus their trail/step before the decision.
1223
+ const visibleTrails = useMemo(() => {
1224
+ const pendingTrail = state.pendingTrail;
1225
+ if (
1226
+ pendingTrail &&
1227
+ state.lastDecision !== "rejected" &&
1228
+ !state.trails.some((t) => t.id === pendingTrail.id)
1229
+ ) {
1230
+ return [...state.trails, pendingTrail];
1231
+ }
1232
+ // The staged variation sits directly after the step it varies. It stays
1233
+ // there after acceptance — only its colour changes.
1234
+ const pendingStep = state.pendingStep;
1235
+ if (!pendingStep || state.lastDecision) {
1236
+ return state.trails;
1237
+ }
1238
+ return state.trails.map((trail) =>
1239
+ trail.id === pendingStep.trailId
1240
+ ? {
1241
+ ...trail,
1242
+ steps: [
1243
+ ...trail.steps.slice(0, pendingStep.stepIndex + 1),
1244
+ pendingStep.step,
1245
+ ...trail.steps.slice(pendingStep.stepIndex + 1),
1246
+ ],
1247
+ }
1248
+ : trail,
1249
+ );
1250
+ }, [state.trails, state.pendingTrail, state.pendingStep, state.lastDecision]);
1251
+
1252
+ const activeGuideIndex = useMemo(
1253
+ () =>
1254
+ state.walkthrough
1255
+ ? state.walkthrough.steps.findIndex(
1256
+ (s) => s.id === state.walkthrough?.activeStepId,
1257
+ )
1258
+ : -1,
1259
+ [state.walkthrough],
1260
+ );
1261
+ const activeGuideStep =
1262
+ activeGuideIndex >= 0 && state.walkthrough
1263
+ ? state.walkthrough.steps[activeGuideIndex]
1264
+ : undefined;
1265
+ const activeGuideLabel =
1266
+ activeGuideStep?.title.match(/^\s*(\d+[a-z]?)\s*·/i)?.[1] ??
1267
+ String(activeGuideIndex + 1);
1268
+ const hasProposalStep =
1269
+ state.walkthrough?.steps.some((s) => s.proposal) ?? false;
1270
+
1271
+ // While an agent-working event is active, light up the components it is
1272
+ // working on: the pending proposal's participants, or the current step's.
1273
+ const workingComponentAliases = useMemo(() => {
1274
+ if (!state.agentWorkingOn) return undefined;
1275
+ const aliases = new Set<string>();
1276
+ const addStep = (step?: SubsystemTrailStep) => {
1277
+ if (!step) return;
1278
+ aliases.add(step.from);
1279
+ aliases.add(step.to);
1280
+ };
1281
+ if (state.pendingComponent) aliases.add(state.pendingComponent.alias);
1282
+ if (state.pendingRemoval) aliases.add(state.pendingRemoval);
1283
+ state.pendingTrail?.steps.forEach(addStep);
1284
+ if (state.pendingStep) {
1285
+ addStep(state.pendingStep.step);
1286
+ } else if (activeGuideStep?.trailId) {
1287
+ const trail = visibleTrails.find((t) => t.id === activeGuideStep.trailId);
1288
+ if (activeGuideStep.stepIndex == null) {
1289
+ trail?.steps.forEach(addStep);
1290
+ } else {
1291
+ addStep(trail?.steps[activeGuideStep.stepIndex]);
1292
+ }
1293
+ }
1294
+ return aliases.size ? aliases : undefined;
1295
+ }, [
1296
+ state.agentWorkingOn,
1297
+ state.pendingComponent,
1298
+ state.pendingRemoval,
1299
+ state.pendingTrail,
1300
+ state.pendingStep,
1301
+ activeGuideStep,
1302
+ visibleTrails,
1303
+ ]);
1304
+
1305
+ // Emphasis is a step effect, not a separate tool call: guidance is attached
1306
+ // to a walkthrough step and lands on the model when that step becomes active.
1307
+ useEffect(() => {
1308
+ if (!activeGuideStep?.guidance) return;
1309
+ const trail = visibleTrails.find((t) => t.id === activeGuideStep.trailId);
1310
+ const step = trail?.steps[activeGuideStep.stepIndex ?? -1];
1311
+ if (!trail || !step) return;
1312
+ const stepKey = stepClaimKey(step);
1313
+ const guidance = activeGuideStep.guidance;
1314
+ setState((prev) => {
1315
+ if (
1316
+ prev.records.some(
1317
+ (r) => r.trailId === trail.id && r.stepKey === stepKey,
1318
+ )
1319
+ ) {
1320
+ return prev;
1321
+ }
1322
+ return {
1323
+ ...prev,
1324
+ records: [
1325
+ ...prev.records,
1326
+ {
1327
+ trailId: trail.id,
1328
+ stepKey,
1329
+ guidance,
1330
+ provenance: {
1331
+ source: "agent",
1332
+ author: "opencode",
1333
+ at: new Date().toISOString(),
1334
+ },
1335
+ },
1336
+ ],
1337
+ };
1338
+ });
1339
+ }, [activeGuideStep, visibleTrails]);
1340
+
1341
+ // The staged replacement variations of one step are a single focus group:
1342
+ // the guide names one of them, but the panel and camera frame them together.
1343
+ const focusedVariationStepIndexes = useMemo(() => {
1344
+ const pending = state.pendingStep;
1345
+ if (!pending || state.lastDecision === "rejected") return undefined;
1346
+ if (state.lastDecision && !state.stepChange) return undefined;
1347
+ return new Map<string, ReadonlySet<number>>([
1348
+ [pending.trailId, new Set([pending.stepIndex, pending.stepIndex + 1])],
1349
+ ]);
1350
+ }, [state.pendingStep, state.lastDecision, state.stepChange]);
1351
+
1352
+ // Once accepted, the variation keeps its `2a` label in the panel even though
1353
+ // it is now an ordinary step in the host-local trails.
1354
+ const acceptedStepNumberLabels = useMemo(() => {
1355
+ const pending = state.pendingStep;
1356
+ if (!state.lastDecision || !pending || !state.stepChange) return undefined;
1357
+ return new Map<string, string>([
1358
+ [
1359
+ emphasisKey(pending.trailId, pending.step),
1360
+ variationStepNumber(pending.stepIndex + 1),
1361
+ ],
1362
+ ]);
1363
+ }, [state.lastDecision, state.pendingStep, state.stepChange]);
1364
+
1365
+ const focusedTrailStep = useMemo(() => {
1366
+ if (!state.walkthrough) return undefined;
1367
+ if (!activeGuideStep) return null;
1368
+ return {
1369
+ trailId: activeGuideStep.trailId,
1370
+ stepIndex: activeGuideStep.stepIndex,
1371
+ showFile:
1372
+ activeGuideStep.stepIndex == null
1373
+ ? false
1374
+ : (activeGuideStep.showFile ?? false),
1375
+ };
1376
+ }, [activeGuideStep, state.walkthrough]);
1377
+
1378
+ const removeGuidance = useCallback(
1379
+ (trail: SubsystemTrail, stepIndex: number) => {
1380
+ const target = trail.steps[stepIndex];
1381
+ if (!target) return;
1382
+ const key = stepClaimKey(target);
1383
+ setState((prev) => ({
1384
+ ...prev,
1385
+ records: prev.records.filter(
1386
+ (r) => !(r.trailId === trail.id && r.stepKey === key),
1387
+ ),
1388
+ }));
1389
+ },
1390
+ [],
1391
+ );
1392
+
1393
+ const moveWalkthroughStep = useCallback((delta: number) => {
1394
+ setState((prev) => {
1395
+ const walkthrough = prev.walkthrough;
1396
+ if (!walkthrough) return prev;
1397
+ const index = walkthrough.steps.findIndex(
1398
+ (s) => s.id === walkthrough.activeStepId,
1399
+ );
1400
+ const nextIndex = index + delta;
1401
+ if (nextIndex < 0 || nextIndex >= walkthrough.steps.length) return prev;
1402
+ const target = walkthrough.steps[nextIndex]!;
1403
+ return {
1404
+ ...prev,
1405
+ walkRun: null,
1406
+ walkthrough: { ...walkthrough, activeStepId: target.id },
1407
+ };
1408
+ });
1409
+ }, []);
1410
+
1411
+ // A `walk-steps` call advances the host focus on its own clock. Manual
1412
+ // navigation cancels the run by clearing `walkRun`.
1413
+ useEffect(() => {
1414
+ const run = state.walkRun;
1415
+ if (!run) return;
1416
+ if (run.index >= run.stepIds.length - 1) {
1417
+ setState((prev) =>
1418
+ prev.walkRun === run ? { ...prev, walkRun: null } : prev,
1419
+ );
1420
+ return;
1421
+ }
1422
+ const timer = window.setTimeout(() => {
1423
+ const nextIndex = run.index + 1;
1424
+ const nextStepId = run.stepIds[nextIndex];
1425
+ if (!nextStepId) return;
1426
+ setState((prev) => {
1427
+ if (prev.walkRun !== run) return prev;
1428
+ return {
1429
+ ...prev,
1430
+ walkRun: { ...run, index: nextIndex },
1431
+ walkthrough: prev.walkthrough
1432
+ ? { ...prev.walkthrough, activeStepId: nextStepId }
1433
+ : prev.walkthrough,
1434
+ };
1435
+ });
1436
+ }, run.pauseMs);
1437
+ return () => window.clearTimeout(timer);
1438
+ }, [state.walkRun]);
1439
+
1440
+ const proposalKind = activeGuideStep?.proposal;
1441
+ const proposalPending =
1442
+ (proposalKind === "trail" && !!state.pendingTrail) ||
1443
+ (proposalKind === "step" && !!state.pendingStep) ||
1444
+ (proposalKind === "component" && !!state.pendingComponent) ||
1445
+ (proposalKind === "removal" && !!state.pendingRemoval);
1446
+ const appliedLabel =
1447
+ proposalKind === "step"
1448
+ ? "Change applied"
1449
+ : proposalKind === "removal"
1450
+ ? "Removed from model"
1451
+ : "Added to model";
1452
+ const proposalStatus = state.lastDecision
1453
+ ? state.lastDecision === "accepted"
1454
+ ? appliedLabel
1455
+ : "Kept model as is"
1456
+ : "Awaiting agent decision";
1457
+
1458
+ const guidePanel =
1459
+ state.walkthrough && activeGuideStep && hasProposalStep ? (
1460
+ <div style={{ fontFamily: mono, color: theme.colors.text }}>
1461
+ <span
1462
+ style={{
1463
+ fontSize: small,
1464
+ letterSpacing: "0.04em",
1465
+ fontWeight: 600,
1466
+ color: proposal,
1467
+ whiteSpace: "nowrap",
1468
+ }}
1469
+ >
1470
+ PROPOSAL ADDED
1471
+ {state.lastDecision === "accepted"
1472
+ ? " · ACCEPTED"
1473
+ : state.lastDecision === "rejected"
1474
+ ? " · DECLINED"
1475
+ : ""}
1476
+ </span>
1477
+ </div>
1478
+ ) : null;
1479
+
1480
+ // Navigation sits on the canvas, directly above the active step card.
1481
+ const stepNavigation =
1482
+ state.walkthrough && activeGuideStep ? (
1483
+ <div
1484
+ style={{
1485
+ display: "flex",
1486
+ alignItems: "center",
1487
+ gap: 8,
1488
+ pointerEvents: "auto",
1489
+ }}
1490
+ >
1491
+ <button
1492
+ type="button"
1493
+ onClick={() => moveWalkthroughStep(-1)}
1494
+ disabled={activeGuideIndex === 0}
1495
+ style={{
1496
+ padding: "4px 10px",
1497
+ borderRadius: 4,
1498
+ border: `1px solid ${border}`,
1499
+ background: "transparent",
1500
+ color: muted,
1501
+ fontFamily: mono,
1502
+ fontSize: small,
1503
+ cursor: activeGuideIndex === 0 ? "default" : "pointer",
1504
+ opacity: activeGuideIndex === 0 ? 0.5 : 1,
1505
+ }}
1506
+ >
1507
+ Previous
1508
+ </button>
1509
+ <span
1510
+ style={{
1511
+ textAlign: "center",
1512
+ fontSize: small,
1513
+ color: muted,
1514
+ whiteSpace: "nowrap",
1515
+ }}
1516
+ >
1517
+ STEP {activeGuideLabel} OF {state.walkthrough.steps.length}
1518
+ </span>
1519
+ <button
1520
+ type="button"
1521
+ onClick={() => moveWalkthroughStep(1)}
1522
+ disabled={activeGuideIndex === state.walkthrough.steps.length - 1}
1523
+ style={{
1524
+ padding: "4px 10px",
1525
+ borderRadius: 4,
1526
+ border: `1px solid ${accent}`,
1527
+ background: `${accent}18`,
1528
+ color: accent,
1529
+ fontFamily: mono,
1530
+ fontSize: small,
1531
+ fontWeight: 600,
1532
+ cursor:
1533
+ activeGuideIndex === state.walkthrough.steps.length - 1
1534
+ ? "default"
1535
+ : "pointer",
1536
+ opacity:
1537
+ activeGuideIndex === state.walkthrough.steps.length - 1 ? 0.5 : 1,
1538
+ }}
1539
+ >
1540
+ Next step
1541
+ </button>
1542
+ </div>
1543
+ ) : null;
1544
+
1545
+ // The active step sits above the map so the instruction is read where the
1546
+ // camera is moving. The question stays in the left rail.
1547
+ const guideStepCard =
1548
+ state.walkthrough && activeGuideStep ? (
1549
+ <div
1550
+ style={{
1551
+ width: 380,
1552
+ maxWidth: "100%",
1553
+ padding: 12,
1554
+ borderRadius: 6,
1555
+ border: `1px solid ${accent}55`,
1556
+ background:
1557
+ theme.colors.backgroundSecondary ?? theme.colors.background,
1558
+ boxShadow: "0 8px 28px rgba(0,0,0,0.32)",
1559
+ fontFamily: mono,
1560
+ color: theme.colors.text,
1561
+ }}
1562
+ >
1563
+ <div
1564
+ style={{
1565
+ fontSize: body,
1566
+ fontWeight: 600,
1567
+ color: theme.colors.text,
1568
+ }}
1569
+ >
1570
+ {activeGuideStep.title}
1571
+ </div>
1572
+ <p
1573
+ style={{
1574
+ margin: "6px 0 0",
1575
+ fontSize: small,
1576
+ lineHeight: 1.5,
1577
+ color: theme.colors.text,
1578
+ }}
1579
+ >
1580
+ {activeGuideStep.body}
1581
+ </p>
1582
+ {proposalPending ? (
1583
+ <div
1584
+ aria-live="polite"
1585
+ style={{ marginTop: 10, fontSize: small, color: proposal }}
1586
+ >
1587
+ {proposalStatus}
1588
+ </div>
1589
+ ) : null}
1590
+ </div>
1591
+ ) : null;
1592
+
1593
+ // The agent status lives on the graph itself, not in the left guide column.
1594
+ // No pill is shown until the agent starts working or resolves a proposal.
1595
+ const agentStatusOverlay =
1596
+ state.agentWorkingOn || state.lastDecision ? (
1597
+ <div
1598
+ aria-live="polite"
1599
+ style={{
1600
+ display: "flex",
1601
+ alignItems: "center",
1602
+ gap: 8,
1603
+ padding: "6px 12px",
1604
+ borderRadius: 999,
1605
+ border: `1px solid ${state.agentWorkingOn ? accent : proposal}`,
1606
+ background:
1607
+ theme.colors.backgroundSecondary ?? theme.colors.background,
1608
+ boxShadow: "0 6px 20px rgba(0,0,0,0.35)",
1609
+ fontFamily: mono,
1610
+ fontSize: small,
1611
+ whiteSpace: "nowrap",
1612
+ }}
1613
+ >
1614
+ {state.agentWorkingOn ? (
1615
+ <>
1616
+ <span
1617
+ className="agent-working-dot"
1618
+ style={{
1619
+ width: 6,
1620
+ height: 6,
1621
+ borderRadius: "50%",
1622
+ background: accent,
1623
+ flexShrink: 0,
1624
+ }}
1625
+ />
1626
+ <span style={{ color: accent, fontWeight: 600 }}>
1627
+ AGENT WORKING ON
1628
+ </span>
1629
+ <span style={{ color: theme.colors.text }}>
1630
+ {state.agentWorkingOn}
1631
+ </span>
1632
+ </>
1633
+ ) : (
1634
+ <span style={{ color: proposal, fontWeight: 600 }}>
1635
+ {state.lastDecision === "accepted"
1636
+ ? "AGENT COMMITTED PROPOSAL"
1637
+ : "AGENT DECLINED PROPOSAL"}
1638
+ </span>
1639
+ )}
1640
+ </div>
1641
+ ) : null;
1642
+
1643
+ // Navigation, the step card and agent status float as one stack over the
1644
+ // map: buttons on top, status directly beneath the card.
1645
+ const graphCardStack =
1646
+ stepNavigation || guideStepCard || agentStatusOverlay ? (
1647
+ <div
1648
+ style={{
1649
+ position: "absolute",
1650
+ top: 56,
1651
+ left: "50%",
1652
+ transform: "translateX(-50%)",
1653
+ zIndex: 20,
1654
+ pointerEvents: "none",
1655
+ display: "flex",
1656
+ flexDirection: "column",
1657
+ alignItems: "center",
1658
+ gap: 8,
1659
+ width: "max-content",
1660
+ maxWidth: "calc(100% - 32px)",
1661
+ }}
1662
+ >
1663
+ {stepNavigation}
1664
+ {guideStepCard}
1665
+ {agentStatusOverlay}
1666
+ </div>
1667
+ ) : null;
1668
+
1669
+ // The swap lives in whichever header is currently visible. In driven mode it
1670
+ // sits beside the question; in standard mode it rides in the old header's
1671
+ // actions, whose sidebar-view switch stays part of that header only.
1672
+ const swapHeaderButton = (
1673
+ <button
1674
+ type="button"
1675
+ onClick={() => setDrivenHeaderMode((prev) => !prev)}
1676
+ aria-label="Swap header"
1677
+ style={{
1678
+ padding: "4px 10px",
1679
+ borderRadius: 4,
1680
+ border: `1px solid ${border}`,
1681
+ background: "transparent",
1682
+ color: muted,
1683
+ fontFamily: mono,
1684
+ fontSize: small,
1685
+ cursor: "pointer",
1686
+ whiteSpace: "nowrap",
1687
+ }}
1688
+ >
1689
+ Swap header
1690
+ </button>
1691
+ );
1692
+
1693
+ const drivenHeader = drivenHeaderMode ? (
1694
+ <header
1695
+ style={{
1696
+ position: "relative",
1697
+ flexShrink: 0,
1698
+ display: "flex",
1699
+ alignItems: "center",
1700
+ gap: 12,
1701
+ padding: "12px 16px",
1702
+ background: theme.colors.background,
1703
+ borderBottom: `1px solid ${border}`,
1704
+ fontFamily: mono,
1705
+ }}
1706
+ >
1707
+ <span
1708
+ style={{
1709
+ fontSize: small,
1710
+ letterSpacing: "0.08em",
1711
+ fontWeight: 600,
1712
+ color: accent,
1713
+ whiteSpace: "nowrap",
1714
+ }}
1715
+ >
1716
+ AGENT-DRIVEN
1717
+ </span>
1718
+ <span
1719
+ style={{
1720
+ position: "absolute",
1721
+ left: "50%",
1722
+ transform: "translateX(-50%)",
1723
+ maxWidth: "calc(100% - 320px)",
1724
+ fontSize: theme.fontSizes[2],
1725
+ color: theme.colors.text,
1726
+ whiteSpace: "nowrap",
1727
+ overflow: "hidden",
1728
+ textOverflow: "ellipsis",
1729
+ textAlign: "center",
1730
+ pointerEvents: "none",
1731
+ }}
1732
+ >
1733
+ {state.walkthrough?.question ?? title}
1734
+ </span>
1735
+ <span style={{ marginLeft: "auto" }}>{swapHeaderButton}</span>
1736
+ </header>
1737
+ ) : null;
1738
+
1739
+ return (
1740
+ <div
1741
+ style={{
1742
+ display: "flex",
1743
+ height: "100vh",
1744
+ background: theme.colors.background,
1745
+ }}
1746
+ >
1747
+ <style>{`
1748
+ @keyframes agent-working-star {
1749
+ 0%, 100% { opacity: 0.45; }
1750
+ 50% { opacity: 1; }
1751
+ }
1752
+ /* Only the sparkle arms twinkle; the wand, icon, and status dot stay put. */
1753
+ .agent-working-icon path:nth-of-type(n+3) {
1754
+ animation: agent-working-star 1.6s ease-in-out infinite;
1755
+ }
1756
+ .agent-working-icon path:nth-of-type(3),
1757
+ .agent-working-icon path:nth-of-type(6) {
1758
+ animation-delay: 0s;
1759
+ }
1760
+ .agent-working-icon path:nth-of-type(4),
1761
+ .agent-working-icon path:nth-of-type(7) {
1762
+ animation-delay: -0.55s;
1763
+ }
1764
+ .agent-working-icon path:nth-of-type(5),
1765
+ .agent-working-icon path:nth-of-type(8) {
1766
+ animation-delay: -1.1s;
1767
+ }
1768
+ @keyframes agent-model-opening-in {
1769
+ from {
1770
+ opacity: 0;
1771
+ transform: translateY(22px) scale(0.985);
1772
+ filter: blur(4px);
1773
+ }
1774
+ to {
1775
+ opacity: 1;
1776
+ transform: translateY(0) scale(1);
1777
+ filter: blur(0);
1778
+ }
1779
+ }
1780
+ .agent-model-opening {
1781
+ animation: agent-model-opening-in 700ms cubic-bezier(0.16, 1, 0.3, 1) both;
1782
+ transform-origin: 50% 35%;
1783
+ }
1784
+ @media (prefers-reduced-motion: reduce) {
1785
+ .agent-working-dot,
1786
+ .agent-working-icon,
1787
+ .agent-working-icon path:nth-of-type(n+3) {
1788
+ animation: none !important;
1789
+ }
1790
+ .agent-model-opening {
1791
+ animation: none !important;
1792
+ }
1793
+ }
1794
+ `}</style>
1795
+ {state.modelOpen ? (
1796
+ <div
1797
+ key={openingKey}
1798
+ className="agent-model-opening"
1799
+ style={{
1800
+ flex: 1,
1801
+ minWidth: 0,
1802
+ display: "flex",
1803
+ flexDirection: "column",
1804
+ }}
1805
+ >
1806
+ {drivenHeader}
1807
+ <div style={{ flex: 1, minHeight: 0, position: "relative" }}>
1808
+ <SubsystemComponentGraph
1809
+ components={visibleComponents}
1810
+ trails={visibleTrails}
1811
+ focusedTrailStep={focusedTrailStep}
1812
+ focusedVariationStepIndexes={focusedVariationStepIndexes}
1813
+ proposedTrailIds={
1814
+ state.pendingTrail && !state.lastDecision
1815
+ ? new Set([state.pendingTrail.id])
1816
+ : undefined
1817
+ }
1818
+ proposedStepKeys={
1819
+ state.pendingStep && !state.lastDecision
1820
+ ? new Set([
1821
+ emphasisKey(
1822
+ state.pendingStep.trailId,
1823
+ state.pendingStep.step,
1824
+ ),
1825
+ ])
1826
+ : undefined
1827
+ }
1828
+ stepNumberLabels={acceptedStepNumberLabels}
1829
+ proposedStep={
1830
+ state.pendingStep && !state.lastDecision
1831
+ ? state.pendingStep
1832
+ : null
1833
+ }
1834
+ stepChange={state.stepChange}
1835
+ stepHistory={state.stepHistory}
1836
+ proposedComponentAliases={
1837
+ state.pendingComponent && !state.lastDecision
1838
+ ? new Set([state.pendingComponent.alias])
1839
+ : undefined
1840
+ }
1841
+ workingComponentAliases={workingComponentAliases}
1842
+ removedComponentAliases={state.removedComponentAliases}
1843
+ canvasOverlay={graphCardStack}
1844
+ trailFocusDurationMs={600}
1845
+ focusVerticalBiasPx={96}
1846
+ persistKey={persistKey}
1847
+ stepEmphasis={emphasis}
1848
+ onRemoveStepEmphasis={removeGuidance}
1849
+ sidebarAfterDescription={guidePanel}
1850
+ hideHeader={drivenHeaderMode}
1851
+ headerActions={drivenHeaderMode ? undefined : swapHeaderButton}
1852
+ title={title}
1853
+ description={state.walkthrough ? undefined : description}
1854
+ notes={
1855
+ state.walkthrough
1856
+ ? undefined
1857
+ : "**Prototype boundary:** this is Storybook-only. The same tool-call shapes can later be emitted by the MCP bridge; the portable model document is untouched."
1858
+ }
1859
+ />
1860
+ </div>
1861
+ </div>
1862
+ ) : (
1863
+ <div
1864
+ style={{
1865
+ flex: 1,
1866
+ minWidth: 0,
1867
+ background: theme.colors.background,
1868
+ }}
1869
+ />
1870
+ )}
1871
+
1872
+ <aside
1873
+ style={{
1874
+ width: 390,
1875
+ flexShrink: 0,
1876
+ display: "flex",
1877
+ flexDirection: "column",
1878
+ borderLeft: `1px solid ${border}`,
1879
+ background: theme.colors.background,
1880
+ overflow: "hidden",
1881
+ }}
1882
+ >
1883
+ <header
1884
+ style={{
1885
+ padding: "14px 16px 10px",
1886
+ borderBottom: `1px solid ${border}`,
1887
+ }}
1888
+ >
1889
+ <div
1890
+ style={{
1891
+ fontFamily: mono,
1892
+ fontSize: body,
1893
+ color: theme.colors.text,
1894
+ }}
1895
+ >
1896
+ Agent tool stream
1897
+ </div>
1898
+ <p
1899
+ style={{
1900
+ margin: "6px 0 0",
1901
+ fontSize: small,
1902
+ lineHeight: 1.5,
1903
+ color: muted,
1904
+ }}
1905
+ >
1906
+ Step through the fake calls or play them like a live session.
1907
+ </p>
1908
+ <div style={{ display: "flex", gap: 6, marginTop: 10 }}>
1909
+ <button
1910
+ type="button"
1911
+ onClick={step}
1912
+ disabled={cursor >= events.length}
1913
+ style={{
1914
+ padding: "4px 10px",
1915
+ borderRadius: 4,
1916
+ border: `1px solid ${border}`,
1917
+ background:
1918
+ theme.colors.backgroundSecondary ?? theme.colors.background,
1919
+ color: theme.colors.text,
1920
+ fontFamily: mono,
1921
+ fontSize: small,
1922
+ cursor: cursor >= events.length ? "default" : "pointer",
1923
+ opacity: cursor >= events.length ? 0.5 : 1,
1924
+ }}
1925
+ >
1926
+ Next tool call
1927
+ </button>
1928
+ <button
1929
+ type="button"
1930
+ onClick={() => setPlaying((prev) => !prev)}
1931
+ disabled={cursor >= events.length && !playing}
1932
+ style={{
1933
+ padding: "4px 10px",
1934
+ borderRadius: 4,
1935
+ border: `1px solid ${accent}`,
1936
+ background: `${accent}18`,
1937
+ color: accent,
1938
+ fontFamily: mono,
1939
+ fontSize: small,
1940
+ fontWeight: 600,
1941
+ cursor: "pointer",
1942
+ }}
1943
+ >
1944
+ {playing ? "Pause" : "Play"}
1945
+ </button>
1946
+ <button
1947
+ type="button"
1948
+ onClick={reset}
1949
+ style={{
1950
+ padding: "4px 10px",
1951
+ borderRadius: 4,
1952
+ border: `1px solid ${border}`,
1953
+ background: "transparent",
1954
+ color: muted,
1955
+ fontFamily: mono,
1956
+ fontSize: small,
1957
+ cursor: "pointer",
1958
+ }}
1959
+ >
1960
+ Reset
1961
+ </button>
1962
+ <button
1963
+ type="button"
1964
+ onClick={animateOpening}
1965
+ style={{
1966
+ padding: "4px 10px",
1967
+ borderRadius: 4,
1968
+ border: `1px solid ${border}`,
1969
+ background: "transparent",
1970
+ color: muted,
1971
+ fontFamily: mono,
1972
+ fontSize: small,
1973
+ cursor: "pointer",
1974
+ }}
1975
+ >
1976
+ Animate opening
1977
+ </button>
1978
+ </div>
1979
+ <div style={{ marginTop: 8, fontSize: small, color: muted }}>
1980
+ {cursor} / {events.length} calls replayed
1981
+ </div>
1982
+ </header>
1983
+
1984
+ <div
1985
+ style={{
1986
+ flex: 1,
1987
+ minHeight: 0,
1988
+ overflow: "auto",
1989
+ padding: "12px 16px",
1990
+ display: "grid",
1991
+ gap: 8,
1992
+ alignContent: "start",
1993
+ }}
1994
+ >
1995
+ {events.slice(0, cursor).map((event) => (
1996
+ <ToolRow key={event.id} event={event} />
1997
+ ))}
1998
+ </div>
1999
+ </aside>
2000
+ </div>
2001
+ );
2002
+ }
2003
+
2004
+ export const Walkthrough: Story = {
2005
+ render: () => (
2006
+ <Prototype
2007
+ events={trailProposalEvents}
2008
+ title="Agent-driven walkthrough · prototype"
2009
+ persistKey="agent-driven-walkthrough-prototype"
2010
+ description="A simulated agent stream narrates what it is working on, focuses trails, walks across trails, then reviews and commits a trail proposal in conversation. All state is host-local."
2011
+ />
2012
+ ),
2013
+ };
2014
+
2015
+ export const StepChangeProposal: Story = {
2016
+ render: () => (
2017
+ <Prototype
2018
+ events={stepProposalEvents}
2019
+ title="Agent-driven step change · prototype"
2020
+ persistKey="agent-driven-step-change-prototype"
2021
+ description="A simulated agent stream narrates its focus, stages a step replacement, then reviews and applies it in conversation. The proposed step text stays host-local until committed."
2022
+ />
2023
+ ),
2024
+ };
2025
+
2026
+ export const ComponentProposal: Story = {
2027
+ render: () => (
2028
+ <Prototype
2029
+ events={componentProposalEvents}
2030
+ title="Agent-driven component proposal · prototype"
2031
+ persistKey="agent-driven-component-proposal-prototype"
2032
+ description="A simulated agent stream focuses the refund gap, stages a new component, then reviews and commits it in conversation. Its box is dashed, badged and proposal-colored until committed."
2033
+ />
2034
+ ),
2035
+ };
2036
+
2037
+ export const ComponentRemoval: Story = {
2038
+ render: () => (
2039
+ <Prototype
2040
+ events={componentRemovalEvents}
2041
+ title="Agent-driven component removal · prototype"
2042
+ persistKey="agent-driven-component-removal-prototype"
2043
+ description="A simulated agent retires the confirmation mailer. Its steps leave the trails, while its box stays in place as a dim REMOVED ghost."
2044
+ />
2045
+ ),
2046
+ };
2047
+
2048
+ export const TrailProposalDeclined: Story = {
2049
+ render: () => (
2050
+ <Prototype
2051
+ events={trailDeclinedEvents}
2052
+ title="Agent-driven walkthrough · declined"
2053
+ persistKey="agent-driven-walkthrough-declined-prototype"
2054
+ description="The same narrated trail proposal, but the agent declines it in conversation and the visible model stays unchanged."
2055
+ />
2056
+ ),
2057
+ };
2058
+
2059
+ export const StepProposalDeclined: Story = {
2060
+ render: () => (
2061
+ <Prototype
2062
+ events={stepDeclinedEvents}
2063
+ title="Agent-driven step change · declined"
2064
+ persistKey="agent-driven-step-change-declined-prototype"
2065
+ description="The agent reviews the staged step change, declines it, and the original step remains in the trail."
2066
+ />
2067
+ ),
2068
+ };
2069
+
2070
+ export const ComponentProposalDeclined: Story = {
2071
+ render: () => (
2072
+ <Prototype
2073
+ events={componentDeclinedEvents}
2074
+ title="Agent-driven component proposal · declined"
2075
+ persistKey="agent-driven-component-proposal-declined-prototype"
2076
+ description="The agent reviews the staged component and trail, declines them, and no new box appears in the model."
2077
+ />
2078
+ ),
2079
+ };