@leitwerk-dev/ui 0.1.8 → 0.2.0

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 (173) hide show
  1. package/dist/assets/ApiTokensPage-B15IzsLp.css +1 -0
  2. package/dist/assets/ApiTokensPage-ClJp9PYr.js +1 -0
  3. package/dist/assets/ChronicleMarkdown-lqwX9Ywa.js +16 -0
  4. package/dist/assets/ChronicleMarkdown-wsUF8Z75.css +1 -0
  5. package/dist/assets/FutureLaunchDetailPage-BOoZaG11.css +1 -0
  6. package/dist/assets/FutureLaunchDetailPage-Bdlgm4cJ.js +1 -0
  7. package/dist/assets/GenericLauncher-Bf7Eb1Rw.js +1 -0
  8. package/dist/assets/GenericLauncher-CExW6wei.css +1 -0
  9. package/dist/assets/HomePage-4Q7aqPBl.css +1 -0
  10. package/dist/assets/HomePage-CSkNdC4m.js +1 -0
  11. package/dist/assets/PageHeader-DPuQInDo.css +1 -0
  12. package/dist/assets/PageHeader-sphJnWL1.js +1 -0
  13. package/dist/assets/ProcessActionsMenu-DLMywI9c.js +1 -0
  14. package/dist/assets/ProcessActionsMenu-VKT7PE6z.css +1 -0
  15. package/dist/assets/ProcessDetailPage-Cth6A0DN.css +1 -0
  16. package/dist/assets/ProcessDetailPage-fvvdvO19.js +14 -0
  17. package/dist/assets/ProcessFlowDiagram-Dx2wheGN.js +2 -0
  18. package/dist/assets/ProcessesPage-uLl7LXp8.js +1 -0
  19. package/dist/assets/ProcessesPage-yPjjrzjg.css +1 -0
  20. package/dist/assets/ScheduleDateTimePicker-DmojMRxN.js +1 -0
  21. package/dist/assets/{ScheduleDateTimePicker-CadXN9z7.css → ScheduleDateTimePicker-uacJAkIq.css} +1 -1
  22. package/dist/assets/SkillsPage-CJrtt8xU.css +1 -0
  23. package/dist/assets/SkillsPage-CotbGUxm.js +2 -0
  24. package/dist/assets/WatchersPage-ByWGNJet.js +1 -0
  25. package/dist/assets/WatchersPage-cRBnmTAD.css +1 -0
  26. package/dist/assets/external-links-CX92-VRP.js +1 -0
  27. package/dist/assets/http-client-VpPXJwbR.js +2 -0
  28. package/dist/assets/index-C7zNe3je.js +6 -0
  29. package/dist/assets/index-DtEI5gsQ.css +1 -0
  30. package/dist/assets/index-client-BYQviCtQ.js +2 -0
  31. package/dist/assets/{mermaid-render.worker-DAVgiVRG.js → mermaid-render.worker-QW2WZpEE.js} +12 -12
  32. package/dist/assets/process-terminal-display-BQRQwGod.js +1 -0
  33. package/dist/assets/router.svelte-EEldxHlO.js +1 -0
  34. package/dist/index.html +8 -8
  35. package/package.json +8 -8
  36. package/src/App.svelte +41 -2
  37. package/src/chronicle/components/ChronicleActionSection.svelte +70 -143
  38. package/src/chronicle/components/ChronicleCreateIssueButton.svelte +22 -0
  39. package/src/chronicle/components/ChronicleEntryHeader.svelte +76 -0
  40. package/src/chronicle/components/ChronicleExpandButton.svelte +11 -34
  41. package/src/chronicle/components/ChronicleFailureMessage.svelte +41 -0
  42. package/src/chronicle/components/ChronicleFlow.svelte +135 -28
  43. package/src/chronicle/components/ChronicleLeafOutcomeRendererHost.svelte +1 -8
  44. package/src/chronicle/components/ChronicleLeafOutcomeSection.svelte +25 -52
  45. package/src/chronicle/components/ChronicleLiveChip.svelte +1 -35
  46. package/src/chronicle/components/ChronicleLiveTail.svelte +55 -154
  47. package/src/chronicle/components/ChronicleMarkdown.svelte +6 -6
  48. package/src/chronicle/components/ChronicleOperatorInputSection.svelte +5 -18
  49. package/src/chronicle/components/ChronicleProcessErrorSection.svelte +10 -107
  50. package/src/chronicle/components/ChroniclePromptSection.svelte +6 -26
  51. package/src/chronicle/components/ChronicleQuestionRequest.svelte +22 -5
  52. package/src/chronicle/components/ChronicleReasoningDetailsOverlay.svelte +71 -109
  53. package/src/chronicle/components/ChronicleRecoverySection.svelte +99 -262
  54. package/src/chronicle/components/ChronicleScheduledActionSection.svelte +1 -1
  55. package/src/chronicle/components/ChronicleSectionHeader.svelte +1 -4
  56. package/src/chronicle/components/ChronicleStartupHistory.svelte +63 -0
  57. package/src/chronicle/components/ChronicleStartupRecoverySection.svelte +10 -26
  58. package/src/chronicle/components/ChronicleThinkingSection.svelte +25 -165
  59. package/src/chronicle/components/ChronicleThinkingText.svelte +1 -0
  60. package/src/chronicle/components/ChronicleToolApproval.svelte +40 -0
  61. package/src/chronicle/components/ChronicleToolCallItem.svelte +1 -1
  62. package/src/chronicle/components/ChronicleTurnCluster.svelte +209 -282
  63. package/src/chronicle/components/ChronicleTurnDetailsButton.svelte +16 -0
  64. package/src/chronicle/components/ChronicleTurnProgress.svelte +94 -0
  65. package/src/chronicle/components/ChronicleTurnRail.svelte +339 -394
  66. package/src/chronicle/components/CompactActionComposer.svelte +36 -13
  67. package/src/chronicle/components/ReadonlyJsonValue.svelte +30 -0
  68. package/src/chronicle/lib/action-bindings.ts +1 -1
  69. package/src/chronicle/lib/action-model-display.ts +2 -2
  70. package/src/chronicle/lib/action-preview.ts +1 -1
  71. package/src/chronicle/lib/chronicle-projection.ts +135 -108
  72. package/src/chronicle/lib/chronicle-rail-groups.ts +158 -0
  73. package/src/chronicle/lib/chronicle-selectable-items.ts +16 -11
  74. package/src/chronicle/lib/chronicle-ticket-artifact.ts +7 -0
  75. package/src/chronicle/lib/formatting.ts +19 -0
  76. package/src/chronicle/lib/leaf-outcome-loader.ts +30 -111
  77. package/src/chronicle/lib/leaf-outcome-runtime.ts +3 -15
  78. package/src/chronicle/lib/result-presentation.ts +40 -0
  79. package/src/chronicle/lib/retry-groups.ts +24 -0
  80. package/src/chronicle/lib/scroll-sync.ts +1 -0
  81. package/src/chronicle/lib/tool-call-summary.ts +1 -9
  82. package/src/chronicle/ticket-selection.ts +23 -0
  83. package/src/components/ElapsedTime.svelte +31 -0
  84. package/src/components/ExternalLink.svelte +39 -0
  85. package/src/components/FormFieldRenderer.svelte +4 -1
  86. package/src/components/GenericLauncher.svelte +40 -15
  87. package/src/components/KeyboardShortcutsModal.svelte +2 -2
  88. package/src/components/LaunchChecklist.svelte +184 -0
  89. package/src/components/ModalShell.svelte +49 -15
  90. package/src/components/PageHeader.svelte +36 -35
  91. package/src/components/ProcessActionsMenu.svelte +247 -138
  92. package/src/components/ProcessInfoOverlay.svelte +13 -21
  93. package/src/components/ProgressChecklist.svelte +46 -0
  94. package/src/components/ProgressChecklistRows.svelte +80 -0
  95. package/src/components/launcher-form-copy.ts +4 -1
  96. package/src/components/launcher-model-config.ts +1 -1
  97. package/src/extension-ui-dev-server.ts +2 -5
  98. package/src/lib/api-tokens.ts +34 -0
  99. package/src/lib/api.ts +330 -455
  100. package/src/lib/elapsed-time.ts +19 -0
  101. package/src/lib/external-links.ts +81 -0
  102. package/src/lib/flow-layout.ts +1 -8
  103. package/src/lib/format.ts +3 -26
  104. package/src/lib/future-launch-detail.ts +1 -1
  105. package/src/lib/http-client.ts +79 -0
  106. package/src/lib/launch-updates.ts +17 -0
  107. package/src/lib/markdown.ts +8 -1
  108. package/src/lib/primary-path-detail.ts +97 -3
  109. package/src/lib/primary-path-replay.ts +13 -7
  110. package/src/lib/process-row-view.ts +1 -1
  111. package/src/lib/process-terminal-display.ts +4 -7
  112. package/src/lib/processes.svelte.ts +41 -9
  113. package/src/lib/reasoning-history.ts +95 -0
  114. package/src/lib/retry-config.svelte.ts +1 -1
  115. package/src/lib/rich-markdown-elements.ts +2 -2
  116. package/src/lib/router-logic.ts +3 -0
  117. package/src/lib/runtime-config.ts +1 -3
  118. package/src/lib/test-fixtures.ts +1 -1
  119. package/src/lib/tool-call-rendering.ts +4 -1
  120. package/src/lib/ui-extensions.svelte.ts +78 -127
  121. package/src/lib/ws-classifier.ts +8 -1
  122. package/src/pages/ApiTokensPage.svelte +213 -0
  123. package/src/pages/FutureLaunchDetailPage.svelte +8 -38
  124. package/src/pages/HomePage.svelte +8 -11
  125. package/src/pages/ProcessCard.svelte +1 -1
  126. package/src/pages/ProcessDetailPage.svelte +161 -62
  127. package/src/pages/ProcessGallery.svelte +1 -3
  128. package/src/pages/ProcessesPage.svelte +7 -42
  129. package/src/pages/SkillsPage.svelte +32 -24
  130. package/src/pages/WatchersPage.svelte +31 -55
  131. package/src/pages/process-detail/ProcessDetailChronicle.svelte +415 -19
  132. package/src/pages/process-detail/ProcessDetailHeader.svelte +66 -25
  133. package/src/pages/process-detail/ProcessSummary.svelte +35 -0
  134. package/src/pages/process-detail/TicketCreationComposer.svelte +219 -0
  135. package/src/pages/process-detail/process-detail-action-drafts.svelte.ts +5 -5
  136. package/src/pages/process-detail/process-detail-actions.svelte.ts +4 -2
  137. package/src/pages/process-detail/process-detail-chronicle-dom.ts +39 -14
  138. package/src/pages/process-detail/process-detail-chronicle-scroll.svelte.ts +68 -10
  139. package/src/pages/process-detail/process-detail-view-model.ts +10 -23
  140. package/src/shell/AppShell.svelte +260 -6
  141. package/src/shell/RouteLoadBoundary.svelte +48 -12
  142. package/src/shell/Sidebar.svelte +304 -172
  143. package/src/styles/controls.css +188 -0
  144. package/dist/assets/ChronicleMarkdown-D6hFzERy.css +0 -1
  145. package/dist/assets/ChronicleMarkdown-iH1VLv7x.js +0 -16
  146. package/dist/assets/FutureLaunchDetailPage-BJphZBFH.js +0 -1
  147. package/dist/assets/FutureLaunchDetailPage-VPMBtpYc.css +0 -1
  148. package/dist/assets/GenericLauncher-D_GMtsQ5.css +0 -1
  149. package/dist/assets/GenericLauncher-tr1to52a.js +0 -1
  150. package/dist/assets/HomePage-CSHVQefI.js +0 -1
  151. package/dist/assets/HomePage-DYh_QHXv.css +0 -1
  152. package/dist/assets/PageHeader-6PdvYODN.css +0 -1
  153. package/dist/assets/PageHeader-C4j3zJKF.js +0 -1
  154. package/dist/assets/ProcessActionsMenu-BT2r9vO8.css +0 -1
  155. package/dist/assets/ProcessActionsMenu-gNiZGUCZ.js +0 -1
  156. package/dist/assets/ProcessDetailPage-CGyVxjeH.js +0 -12
  157. package/dist/assets/ProcessDetailPage-CSrjzajF.css +0 -1
  158. package/dist/assets/ProcessFlowDiagram-BX_Zjm2n.js +0 -2
  159. package/dist/assets/ProcessesPage-BcM38HMs.css +0 -1
  160. package/dist/assets/ProcessesPage-D3jjufse.js +0 -1
  161. package/dist/assets/ScheduleDateTimePicker-D72J6EhE.js +0 -1
  162. package/dist/assets/SkillsPage-B30FAFia.css +0 -1
  163. package/dist/assets/SkillsPage-CcYm4ATy.js +0 -2
  164. package/dist/assets/WatchersPage-Bac86WLp.js +0 -1
  165. package/dist/assets/WatchersPage-Dnfi1zUK.css +0 -1
  166. package/dist/assets/api-HGtUzekR.js +0 -1
  167. package/dist/assets/dist-DVNpSD5l.js +0 -2
  168. package/dist/assets/index-66T4Gmbl.css +0 -1
  169. package/dist/assets/index-ChVsVf6R.js +0 -7
  170. package/dist/assets/index-client-BqF3_t3P.js +0 -2
  171. package/dist/assets/retry-config.svelte-DFKCJtCe.js +0 -1
  172. package/dist/assets/router.svelte-C2wi6I7k.js +0 -1
  173. package/src/lib/process-initial-prompt.ts +0 -7
@@ -2,13 +2,15 @@ import {
2
2
  formatPathTypeLabel,
3
3
  type ProcessInput,
4
4
  type ProcessLeafOutcomeSnapshot,
5
+ type ProcessQuestionRequest,
5
6
  type ProcessTurnRecord,
6
- trimToNull,
7
+ type TurnProgressReport,
7
8
  } from "@leitwerk-dev/domain";
8
9
  import {
9
- buildTrailingLinePreview,
10
+ type CompactActiveTurnSnapshot,
10
11
  type PrimaryPathActiveTurnSnapshot,
11
12
  type ProcessTimelineTurnSummary,
13
+ reasoningPreviewTail,
12
14
  type TurnPiInputPart,
13
15
  type TurnTracePreview,
14
16
  type TurnTraceSnapshot,
@@ -22,7 +24,7 @@ type ChronicleInput = Pick<
22
24
 
23
25
  import type { ProcessRunDetailsView } from "@leitwerk-dev/protocol/http-contracts";
24
26
  import { formatDefinition } from "../../lib/format";
25
- import { markdownToPlainText, truncateText } from "../../lib/markdown";
27
+ import { truncateText } from "../../lib/markdown";
26
28
  import { hasDisplayableText } from "../../lib/pi-stream.js";
27
29
  import {
28
30
  getProcessTerminalRailTitle,
@@ -119,15 +121,28 @@ export interface ChronicleOperatorDecisionSection {
119
121
  export interface ChronicleTurnResultSection {
120
122
  kind: "turn_result";
121
123
  markdown: string;
124
+ resultSummary?: string;
125
+ }
126
+
127
+ export interface ChronicleTurnProgressSection {
128
+ kind: "turn_progress";
129
+ report: TurnProgressReport;
130
+ attemptStatus?: string;
131
+ recordedAt?: string;
122
132
  }
123
133
 
124
134
  export type ChronicleTurnClusterSection =
125
135
  | ChronicleThinkingSection
126
136
  | ChronicleOperatorDecisionSection
137
+ | ChronicleTurnProgressSection
127
138
  | ChronicleTurnResultSection;
128
139
 
129
140
  export interface ChronicleTurnClusterItem {
130
141
  kind: "turn_cluster";
142
+ parentTurnRecordId?: string | null;
143
+ reviewedTurnRecordId?: string;
144
+ resources?: TurnRecordView["resources"];
145
+ transition?: TurnRecordView["transition"];
131
146
  chronologyAt: string;
132
147
  anchorId: string;
133
148
  turnRecordId: string;
@@ -148,6 +163,7 @@ export interface ChronicleTurnClusterItem {
148
163
  triggeringInput: ChronicleTriggeringInputSummary | null;
149
164
  piInput: ChroniclePiInputSummary | null;
150
165
  facts: ChronicleTurnFacts;
166
+ failure?: { summary: string };
151
167
  }
152
168
 
153
169
  export interface ChroniclePromptItem {
@@ -198,7 +214,10 @@ export interface ChronicleLeafOutcomePlaceholderItem {
198
214
  }
199
215
 
200
216
  export interface ChronicleLiveTailItem {
217
+ progress?: TurnRecordView["progress"];
218
+ progressRecordedAt?: string;
201
219
  kind: "live_tail";
220
+ parentTurnRecordId?: string | null;
202
221
  anchorId: string;
203
222
  turnRecordId: string;
204
223
  turnId: string;
@@ -209,6 +228,7 @@ export interface ChronicleLiveTailItem {
209
228
  state: "tool_running" | "thinking" | "streaming" | "waiting";
210
229
  stateLabel: string;
211
230
  copy: string;
231
+ assistantTextPreview: string;
212
232
  reasoningSection: ChronicleThinkingSection | null;
213
233
  toolCall: PrimaryPathActiveTurnSnapshot["toolCalls"][number] | null;
214
234
  usage: TurnUsageSnapshot | null;
@@ -269,7 +289,7 @@ export interface BuildChronicleProjectionInput {
269
289
  inputs: readonly ChronicleInput[];
270
290
  leafOutcomeSnapshots: readonly ProcessLeafOutcomeSnapshot[];
271
291
  definesLeafOutcome: boolean;
272
- activeTurn: PrimaryPathActiveTurnSnapshot | null | undefined;
292
+ activeTurn: PrimaryPathActiveTurnSnapshot | CompactActiveTurnSnapshot | null | undefined;
273
293
  lifecycleStatus?: string | null;
274
294
  selectedTurnId?: string | null;
275
295
  processUpdatedAt?: string | null;
@@ -278,8 +298,8 @@ export interface BuildChronicleProjectionInput {
278
298
  }
279
299
 
280
300
  // Tunable inline reasoning window: keep the preview calm, recent, and line-based.
281
- export const THINKING_PREVIEW_LINE_COUNT = 3;
282
- const THINKING_PREVIEW_MAX_LENGTH = 320;
301
+ export const THINKING_PREVIEW_LINE_COUNT = 4;
302
+ const THINKING_PREVIEW_MAX_LENGTH = 1024;
283
303
 
284
304
  function sanitizeDomToken(value: string): string {
285
305
  return value.replace(/[^a-zA-Z0-9_-]/g, "_");
@@ -305,10 +325,6 @@ function buildTerminalAnchorId(status: ProcessTerminalStatus): string {
305
325
  return `chronicle-terminal-${sanitizeDomToken(status)}`;
306
326
  }
307
327
 
308
- function normalizeComparableText(value: string): string {
309
- return value.replace(/\s+/g, " ").trim();
310
- }
311
-
312
328
  function buildReasoningTimelineItems(
313
329
  turnTrace: TurnTraceSnapshot | undefined,
314
330
  ): ChronicleReasoningTimelineItem[] {
@@ -405,11 +421,10 @@ function buildReasoningSection(source: TurnTraceProjectionSource): ChronicleThin
405
421
  return null;
406
422
  }
407
423
  const thinkingPreview = source.trace
408
- ? buildTrailingLinePreview(
409
- thinkingText,
410
- THINKING_PREVIEW_LINE_COUNT,
411
- THINKING_PREVIEW_MAX_LENGTH,
412
- )
424
+ ? {
425
+ text: reasoningPreviewTail(thinkingText),
426
+ truncated: thinkingText.length > THINKING_PREVIEW_MAX_LENGTH,
427
+ }
413
428
  : {
414
429
  text: source.preview?.thinkingPreview ?? "",
415
430
  truncated: source.preview?.thinkingPreviewTruncated ?? false,
@@ -526,8 +541,8 @@ function toPiInputSummary(input: {
526
541
  fullPrompt,
527
542
  createdAt: piInput?.createdAt ?? previewInput?.createdAt ?? "",
528
543
  userInput:
529
- trimToNull(input.triggeringInput?.bodyMarkdown) ??
530
- trimToNull(input.initialUserInputText) ??
544
+ promptOrNull(input.triggeringInput?.bodyMarkdown) ??
545
+ promptOrNull(input.initialUserInputText) ??
531
546
  null,
532
547
  };
533
548
  }
@@ -535,7 +550,7 @@ function toPiInputSummary(input: {
535
550
  function buildTurnFacts(input: {
536
551
  turnId: string;
537
552
  durableTurnRecord: TurnRecordView | undefined;
538
- activeTurn?: PrimaryPathActiveTurnSnapshot | null;
553
+ activeTurn?: PrimaryPathActiveTurnSnapshot | CompactActiveTurnSnapshot | null;
539
554
  triggeringInput: ChronicleTriggeringInputSummary | null;
540
555
  actionSource: ChronicleActionSource | null;
541
556
  runDetails?: ProcessRunDetailsView | null;
@@ -571,25 +586,6 @@ function isStandaloneChronicleOperatorInput(input: ChronicleInput): boolean {
571
586
  return input.source === "app_steer" || input.source === "external_comment";
572
587
  }
573
588
 
574
- function hasDistinctTurnResult(
575
- turnRecord: TurnRecordView,
576
- assistantOutputText: string,
577
- assistantOutputTruncated = false,
578
- ): boolean {
579
- if (!hasDisplayableText(turnRecord.turnResultMarkdown)) {
580
- return false;
581
- }
582
- const markdownText = normalizeComparableText(markdownToPlainText(turnRecord.turnResultMarkdown));
583
- const assistantText = normalizeComparableText(assistantOutputText);
584
- if (markdownText.length === 0) {
585
- return false;
586
- }
587
- if (assistantOutputTruncated && assistantText.length > 0) {
588
- return !markdownText.startsWith(assistantText);
589
- }
590
- return markdownText !== assistantText;
591
- }
592
-
593
589
  function hasRenderableLeafOutcomeForTurn(
594
590
  turnRecordId: string,
595
591
  leafOutcomeSnapshots: readonly ProcessLeafOutcomeSnapshot[],
@@ -646,6 +642,20 @@ function buildTurnClusterItem(input: {
646
642
  ? turnRecord.output.trim()
647
643
  : "";
648
644
 
645
+ if (turnRecord.progress) {
646
+ sections.push({
647
+ kind: "turn_progress",
648
+ report: turnRecord.progress,
649
+ recordedAt: turnRecord.progressRecordedAt,
650
+ attemptStatus:
651
+ turnRecord.status === "in_progress"
652
+ ? "in_progress"
653
+ : turnRecord.outcome === "failed" || turnRecord.outcome === "superseded"
654
+ ? turnRecord.outcome
655
+ : "succeeded",
656
+ });
657
+ }
658
+
649
659
  if (assistantText.length === 0 && fallbackText.length > 0) {
650
660
  sections.push({
651
661
  kind: "operator_decision",
@@ -653,22 +663,20 @@ function buildTurnClusterItem(input: {
653
663
  });
654
664
  }
655
665
 
656
- if (
657
- !input.hasRenderableLeafOutcome &&
658
- hasDistinctTurnResult(
659
- turnRecord,
660
- assistantText || fallbackText,
661
- turnTrace === undefined && turnTracePreview?.assistantTextTruncated === true,
662
- )
663
- ) {
666
+ if (!input.hasRenderableLeafOutcome && hasDisplayableText(turnRecord.turnResultMarkdown)) {
664
667
  sections.push({
665
668
  kind: "turn_result",
666
669
  markdown: turnRecord.turnResultMarkdown,
670
+ resultSummary: turnRecord.resultSummary,
667
671
  });
668
672
  }
669
673
 
670
674
  return {
671
675
  kind: "turn_cluster",
676
+ parentTurnRecordId: turnRecord.parentTurnRecordId,
677
+ reviewedTurnRecordId: turnRecord.reviewedTurnRecordId,
678
+ resources: turnRecord.resources,
679
+ transition: turnRecord.transition,
672
680
  chronologyAt: turnRecord.createdAt,
673
681
  anchorId: buildTurnAnchorId(turnRecord.id),
674
682
  turnRecordId: turnRecord.id,
@@ -693,6 +701,10 @@ function buildTurnClusterItem(input: {
693
701
  initialUserInputText: input.initialUserInputText,
694
702
  }),
695
703
  facts: input.facts,
704
+ failure:
705
+ turnRecord.outcome === "failed"
706
+ ? { summary: turnRecord.output || turnRecord.summary || "This turn failed." }
707
+ : undefined,
696
708
  };
697
709
  }
698
710
 
@@ -732,11 +744,15 @@ function buildLeafOutcomeItems(
732
744
  }));
733
745
  }
734
746
 
747
+ function promptOrNull(value: string | null | undefined): string | null {
748
+ return value?.trim() ? value : null;
749
+ }
750
+
735
751
  function buildPromptItem(
736
752
  text: string | null | undefined,
737
753
  createdAt: string | null | undefined,
738
754
  ): ChroniclePromptItem {
739
- const resolvedText = typeof text === "string" ? text.trim() : "";
755
+ const resolvedText = promptOrNull(text) ?? "";
740
756
  return {
741
757
  kind: "prompt",
742
758
  anchorId: buildPromptAnchorId(),
@@ -746,37 +762,21 @@ function buildPromptItem(
746
762
  };
747
763
  }
748
764
 
749
- function compareChronicleTimestamps(left: string, right: string): number {
750
- return left.localeCompare(right);
751
- }
752
-
753
765
  function sortInputsByConsumedAt(left: ChronicleInput, right: ChronicleInput): number {
754
766
  const leftTimestamp = left.consumedAt ?? left.receivedAt;
755
767
  const rightTimestamp = right.consumedAt ?? right.receivedAt;
756
- const timestampComparison = compareChronicleTimestamps(leftTimestamp, rightTimestamp);
757
- if (timestampComparison !== 0) {
758
- return timestampComparison;
759
- }
760
- return left.sequence - right.sequence;
768
+ return leftTimestamp.localeCompare(rightTimestamp) || left.sequence - right.sequence;
761
769
  }
762
770
 
763
771
  function sortInputsByReceivedAt(left: ChronicleInput, right: ChronicleInput): number {
764
- const timestampComparison = compareChronicleTimestamps(left.receivedAt, right.receivedAt);
765
- if (timestampComparison !== 0) {
766
- return timestampComparison;
767
- }
768
- return left.sequence - right.sequence;
772
+ return left.receivedAt.localeCompare(right.receivedAt) || left.sequence - right.sequence;
769
773
  }
770
774
 
771
775
  function sortTurnRecordsByStartedAt(
772
776
  left: Pick<TurnRecordView, "startedAt" | "id">,
773
777
  right: Pick<TurnRecordView, "startedAt" | "id">,
774
778
  ): number {
775
- const startedAtComparison = compareChronicleTimestamps(left.startedAt, right.startedAt);
776
- if (startedAtComparison !== 0) {
777
- return startedAtComparison;
778
- }
779
- return left.id.localeCompare(right.id);
779
+ return left.startedAt.localeCompare(right.startedAt) || left.id.localeCompare(right.id);
780
780
  }
781
781
 
782
782
  function isConsumedTriggeringInputCandidate(input: ChronicleInput): boolean {
@@ -787,10 +787,6 @@ function isConsumedTriggeringInputCandidate(input: ChronicleInput): boolean {
787
787
  );
788
788
  }
789
789
 
790
- function isReceivedTriggeringInputCandidate(input: ChronicleInput): boolean {
791
- return isChronicleTriggeringInput(input);
792
- }
793
-
794
790
  function toTriggeringInputSummary(
795
791
  input: ChronicleInput,
796
792
  fallbackConsumedAt?: string,
@@ -814,7 +810,7 @@ function buildInitialPromptTriggeringInputSummary(
814
810
  promptCreatedAt: string | null | undefined,
815
811
  fallbackTimestamp: string,
816
812
  ): ChronicleTriggeringInputSummary | null {
817
- const normalizedPrompt = trimToNull(initialUserInputText) ?? "";
813
+ const normalizedPrompt = promptOrNull(initialUserInputText) ?? "";
818
814
  if (!hasDisplayableText(normalizedPrompt)) {
819
815
  return null;
820
816
  }
@@ -839,7 +835,7 @@ function buildTriggeringInputIndex(
839
835
  .filter(isConsumedTriggeringInputCandidate)
840
836
  .sort(sortInputsByConsumedAt);
841
837
  const receivedCandidates = input.inputs
842
- .filter(isReceivedTriggeringInputCandidate)
838
+ .filter(isChronicleTriggeringInput)
843
839
  .sort(sortInputsByReceivedAt);
844
840
 
845
841
  const turnRecords = [...input.turnRecords].sort(sortTurnRecordsByStartedAt);
@@ -866,14 +862,11 @@ function buildTriggeringInputIndex(
866
862
  nextConsumedCandidateIndex += 1;
867
863
  continue;
868
864
  }
869
- if (
870
- windowStartExclusive &&
871
- compareChronicleTimestamps(consumedAt, windowStartExclusive) <= 0
872
- ) {
865
+ if (windowStartExclusive && consumedAt.localeCompare(windowStartExclusive) <= 0) {
873
866
  nextConsumedCandidateIndex += 1;
874
867
  continue;
875
868
  }
876
- if (compareChronicleTimestamps(consumedAt, turnRecord.startedAt) > 0) {
869
+ if (consumedAt.localeCompare(turnRecord.startedAt) > 0) {
877
870
  break;
878
871
  }
879
872
  const summary = toTriggeringInputSummary(candidate);
@@ -899,13 +892,10 @@ function buildTriggeringInputIndex(
899
892
  if (assignedInputIds.has(candidate.id)) {
900
893
  continue;
901
894
  }
902
- if (
903
- windowStartExclusive &&
904
- compareChronicleTimestamps(candidate.receivedAt, windowStartExclusive) <= 0
905
- ) {
895
+ if (windowStartExclusive && candidate.receivedAt.localeCompare(windowStartExclusive) <= 0) {
906
896
  break;
907
897
  }
908
- if (compareChronicleTimestamps(candidate.receivedAt, turnRecord.startedAt) > 0) {
898
+ if (candidate.receivedAt.localeCompare(turnRecord.startedAt) > 0) {
909
899
  continue;
910
900
  }
911
901
  const summary = toTriggeringInputSummary(candidate, candidate.receivedAt);
@@ -954,7 +944,7 @@ function mergeLiveToolCallsWithSessionDetails(
954
944
 
955
945
  function buildLiveTail(input: {
956
946
  turnRecord: TurnRecordView | null;
957
- activeTurn: PrimaryPathActiveTurnSnapshot | null | undefined;
947
+ activeTurn: PrimaryPathActiveTurnSnapshot | CompactActiveTurnSnapshot | null | undefined;
958
948
  turnTrace: TurnTraceSnapshot | undefined;
959
949
  turnTracePreview: TurnTracePreview | undefined;
960
950
  triggeringInput: ChronicleTriggeringInputSummary | null;
@@ -967,26 +957,47 @@ function buildLiveTail(input: {
967
957
  return null;
968
958
  }
969
959
  const liveToolCalls = activeTurn
970
- ? mergeLiveToolCallsWithSessionDetails(activeTurn.toolCalls, turnTrace?.toolCalls)
960
+ ? mergeLiveToolCallsWithSessionDetails(
961
+ "toolCalls" in activeTurn
962
+ ? activeTurn.toolCalls
963
+ : activeTurn.currentTool
964
+ ? [
965
+ {
966
+ ...activeTurn.currentTool,
967
+ startedAt: activeTurn.startedAt,
968
+ completedAt: null,
969
+ arguments: null,
970
+ result: null,
971
+ },
972
+ ]
973
+ : [],
974
+ turnTrace?.toolCalls,
975
+ )
971
976
  : [];
972
977
  const runningToolCall = activeTurn
973
- ? ([...liveToolCalls].reverse().find((toolCall) => toolCall.status === "running") ?? null)
978
+ ? (liveToolCalls.findLast((toolCall) => toolCall.status === "running") ?? null)
974
979
  : null;
975
980
  const thinkingText = activeTurn?.assistant.thinking ?? "";
976
981
  const assistantText = activeTurn?.assistant.text.trim() ?? "";
977
982
  const hasThinkingText = thinkingText.trim().length > 0;
978
983
  const reasoningSection = activeTurn
979
984
  ? buildReasoningSection({
980
- trace: {
985
+ trace: turnTrace ?? {
981
986
  assistant: activeTurn.assistant,
982
987
  toolCalls: liveToolCalls,
983
- traceItems: activeTurn.traceItems,
988
+ traceItems: "traceItems" in activeTurn ? activeTurn.traceItems : [],
984
989
  usage: activeTurn.usage,
985
990
  piInput: turnTrace?.piInput ?? null,
986
991
  },
987
992
  preview: turnTracePreview,
988
993
  })
989
994
  : null;
995
+ if (activeTurn && "currentTool" in activeTurn) {
996
+ if (reasoningSection) {
997
+ reasoningSection.toolCallCount = activeTurn.toolCallCount;
998
+ reasoningSection.traceItemCount = activeTurn.traceItemCount;
999
+ }
1000
+ }
990
1001
  const state = runningToolCall
991
1002
  ? "tool_running"
992
1003
  : hasThinkingText
@@ -994,11 +1005,10 @@ function buildLiveTail(input: {
994
1005
  : assistantText.length > 0
995
1006
  ? "streaming"
996
1007
  : "waiting";
997
- const thinkingPreview = buildTrailingLinePreview(
998
- thinkingText,
999
- THINKING_PREVIEW_LINE_COUNT,
1000
- THINKING_PREVIEW_MAX_LENGTH,
1001
- );
1008
+ const thinkingPreview = {
1009
+ text: reasoningPreviewTail(thinkingText),
1010
+ truncated: thinkingText.length > THINKING_PREVIEW_MAX_LENGTH,
1011
+ };
1002
1012
  const copy =
1003
1013
  state === "tool_running"
1004
1014
  ? `Running ${formatDefinition(runningToolCall?.toolName ?? "tool")}…`
@@ -1018,6 +1028,9 @@ function buildLiveTail(input: {
1018
1028
 
1019
1029
  return {
1020
1030
  kind: "live_tail",
1031
+ progress: turnRecord.progress,
1032
+ progressRecordedAt: turnRecord.progressRecordedAt,
1033
+ parentTurnRecordId: turnRecord.parentTurnRecordId,
1021
1034
  anchorId: buildLiveTailAnchorId(turnRecord.id),
1022
1035
  turnRecordId: turnRecord.id,
1023
1036
  turnId: turnRecord.turnId,
@@ -1028,10 +1041,16 @@ function buildLiveTail(input: {
1028
1041
  state,
1029
1042
  stateLabel,
1030
1043
  copy,
1031
- reasoningSection,
1044
+ assistantTextPreview: reasoningPreviewTail(assistantText),
1045
+ reasoningSection:
1046
+ reasoningSection ??
1047
+ (activeTurn && turnRecord.turnType === "llm" && assistantText.length === 0
1048
+ ? buildEmptyReasoningSection({ trace: undefined, preview: turnTracePreview })
1049
+ : null),
1032
1050
  toolCall: runningToolCall,
1033
1051
  usage: activeTurn?.usage ?? null,
1034
- eventWindowTruncated: activeTurn?.eventWindowTruncated ?? false,
1052
+ eventWindowTruncated:
1053
+ activeTurn && "eventWindowTruncated" in activeTurn ? activeTurn.eventWindowTruncated : false,
1035
1054
  modelProfileId: turnRecord.modelProfileId,
1036
1055
  triggeringInput,
1037
1056
  piInput: toPiInputSummary({
@@ -1151,14 +1170,26 @@ function findReasoningSection(
1151
1170
 
1152
1171
  export function extractChronicleReasoningDetailEntries(
1153
1172
  projection: ChronicleProjection,
1173
+ questionRequests: readonly ProcessQuestionRequest[] = [],
1154
1174
  ): ChronicleReasoningDetailEntry[] {
1155
1175
  const entries: ChronicleReasoningDetailEntry[] = [];
1176
+ const questionTurnRecordIds = new Set(questionRequests.map((request) => request.turnRecordId));
1156
1177
  for (const item of projection.timelineItems) {
1178
+ if (item.kind !== "turn_cluster" && item.kind !== "live_tail") {
1179
+ continue;
1180
+ }
1181
+ const recordedReasoningSection =
1182
+ item.kind === "turn_cluster" ? findReasoningSection(item.sections) : item.reasoningSection;
1183
+ const reasoningSection =
1184
+ recordedReasoningSection ??
1185
+ (questionTurnRecordIds.has(item.turnRecordId) ||
1186
+ (item.kind === "live_tail" && item.turnType === "llm")
1187
+ ? buildEmptyReasoningSection({ trace: undefined, preview: undefined })
1188
+ : null);
1189
+ if (!reasoningSection) {
1190
+ continue;
1191
+ }
1157
1192
  if (item.kind === "turn_cluster") {
1158
- const reasoningSection = findReasoningSection(item.sections);
1159
- if (!reasoningSection) {
1160
- continue;
1161
- }
1162
1193
  entries.push({
1163
1194
  entryId: item.turnRecordId,
1164
1195
  turnRecordId: item.turnRecordId,
@@ -1176,9 +1207,6 @@ export function extractChronicleReasoningDetailEntries(
1176
1207
  });
1177
1208
  continue;
1178
1209
  }
1179
- if (item.kind !== "live_tail" || !item.reasoningSection) {
1180
- continue;
1181
- }
1182
1210
  entries.push({
1183
1211
  entryId: item.turnRecordId,
1184
1212
  turnRecordId: item.turnRecordId,
@@ -1192,7 +1220,7 @@ export function extractChronicleReasoningDetailEntries(
1192
1220
  triggeringInput: item.triggeringInput,
1193
1221
  piInput: item.piInput,
1194
1222
  facts: item.facts,
1195
- reasoningSection: item.reasoningSection,
1223
+ reasoningSection,
1196
1224
  });
1197
1225
  }
1198
1226
  return entries;
@@ -1205,7 +1233,8 @@ export function buildChronicleProjection(
1205
1233
  const resolvedTerminalStatus: ProcessTerminalStatus | null = isTerminal
1206
1234
  ? (input.lifecycleStatus as ProcessTerminalStatus)
1207
1235
  : null;
1208
- const displayPromptText = trimToNull(input.initialUserInputText) ?? trimToNull(input.promptText);
1236
+ const displayPromptText =
1237
+ promptOrNull(input.initialUserInputText) ?? promptOrNull(input.promptText);
1209
1238
  const promptItem = displayPromptText
1210
1239
  ? buildPromptItem(displayPromptText, input.promptCreatedAt)
1211
1240
  : null;
@@ -1312,12 +1341,10 @@ export function buildChronicleProjection(
1312
1341
  });
1313
1342
  }
1314
1343
 
1315
- const latestAnchorableTimelineItem = [...timelineItems]
1316
- .reverse()
1317
- .find(
1318
- (item): item is Extract<ChronicleTimelineItem, { anchorId: string }> => "anchorId" in item,
1319
- );
1320
- const latestFocusedTurnId = [...timelineItems].reverse().find((item) => {
1344
+ const latestAnchorableTimelineItem = timelineItems.findLast(
1345
+ (item): item is Extract<ChronicleTimelineItem, { anchorId: string }> => "anchorId" in item,
1346
+ );
1347
+ const latestFocusedTurnId = timelineItems.findLast((item) => {
1321
1348
  return (
1322
1349
  ((item.kind === "turn_cluster" || item.kind === "live_tail") &&
1323
1350
  typeof item.turnRecordId === "string") ||
@@ -0,0 +1,158 @@
1
+ import type { ProcessTimelineTurnSummary } from "@leitwerk-dev/protocol";
2
+ import { markdownToPlainText } from "../../lib/markdown.js";
3
+ import type {
4
+ ChronicleSelectableItem,
5
+ ChronicleSelectableTurnItem,
6
+ } from "./chronicle-selectable-items.js";
7
+ import { groupRetryChains } from "./retry-groups.js";
8
+
9
+ export interface ChronicleRepeatedTurns {
10
+ kind: "repeated";
11
+ retryCount?: number;
12
+ id: string;
13
+ sequence: string;
14
+ items: ChronicleSelectableTurnItem[];
15
+ }
16
+
17
+ export type ChronicleRailRow =
18
+ | { kind: "item"; id: string; item: ChronicleSelectableItem }
19
+ | ChronicleRepeatedTurns;
20
+
21
+ function isHistoricalTurn(item: ChronicleSelectableItem): item is ChronicleSelectableTurnItem {
22
+ return item.kind === "turn" && item.status === "completed" && item.shape !== "square";
23
+ }
24
+
25
+ /** Fold consecutive complete cycles; keep the latest result beside its pending decision. */
26
+ export function buildChronicleRailRows(
27
+ items: readonly ChronicleSelectableItem[],
28
+ records?: readonly ProcessTimelineTurnSummary[],
29
+ ): ChronicleRailRow[] {
30
+ if (records) {
31
+ const byId = new Map(records.map((record) => [record.id, record]));
32
+ const groups = groupRetryChains(items, (item) => {
33
+ if (item.kind !== "turn") return null;
34
+ const record = byId.get(item.turnRecordId);
35
+ return record
36
+ ? {
37
+ id: record.id,
38
+ turnId: record.turnId,
39
+ parentTurnRecordId: record.parentTurnRecordId,
40
+ failed: record.outcome === "failed",
41
+ }
42
+ : null;
43
+ });
44
+ const rows: ChronicleRailRow[] = [];
45
+ let pending: ChronicleSelectableItem[] = [];
46
+ for (const group of groups) {
47
+ if (group.length === 1) {
48
+ pending.push(group[0]);
49
+ continue;
50
+ }
51
+ rows.push(...buildChronicleRailRows(pending));
52
+ pending = [];
53
+ const attempts = group as ChronicleSelectableTurnItem[];
54
+ rows.push({
55
+ kind: "repeated",
56
+ id: attempts[0].anchorId,
57
+ retryCount: attempts.length,
58
+ sequence: attempts[0].title,
59
+ items: attempts.slice(0, -1),
60
+ });
61
+ const latest = attempts[attempts.length - 1];
62
+ rows.push({ kind: "item", id: latest.anchorId, item: latest });
63
+ }
64
+ return [...rows, ...buildChronicleRailRows(pending)];
65
+ }
66
+
67
+ const rows: ChronicleRailRow[] = [];
68
+ const latestResultIndex =
69
+ items.at(-1)?.kind === "action" || items.at(-1)?.kind === "terminal"
70
+ ? items.findLastIndex((item) => item.kind === "turn")
71
+ : -1;
72
+ let index = 0;
73
+ while (index < items.length) {
74
+ let end = index;
75
+ while (end < items.length && end !== latestResultIndex && isHistoricalTurn(items[end])) end++;
76
+ let period = 0;
77
+ let length = 0;
78
+ for (let candidate = 1; candidate <= Math.floor((end - index) / 2); candidate++) {
79
+ let matched = candidate;
80
+ while (index + matched < end) {
81
+ const next = items[index + matched] as ChronicleSelectableTurnItem;
82
+ const original = items[index + (matched % candidate)] as ChronicleSelectableTurnItem;
83
+ if (next.turnId !== original.turnId) break;
84
+ matched++;
85
+ }
86
+ const completeLength = matched - (matched % candidate);
87
+ if (completeLength >= candidate * 2 && completeLength > length) {
88
+ period = candidate;
89
+ length = completeLength;
90
+ }
91
+ }
92
+ if (period > 0) {
93
+ const repeated = items.slice(index, index + length) as ChronicleSelectableTurnItem[];
94
+ rows.push({
95
+ kind: "repeated",
96
+ id: repeated[0].anchorId,
97
+ sequence: repeated
98
+ .slice(0, period)
99
+ .map((item) => item.title)
100
+ .join(" → "),
101
+ items: repeated,
102
+ });
103
+ index += length;
104
+ } else {
105
+ rows.push({ kind: "item", id: items[index].anchorId, item: items[index] });
106
+ index++;
107
+ }
108
+ }
109
+ return rows;
110
+ }
111
+
112
+ export function formatRailElapsed(
113
+ startedAt?: string | null,
114
+ endedAt?: string | null,
115
+ ): string | null {
116
+ if (!startedAt || !endedAt) return null;
117
+ const elapsed = Date.parse(endedAt) - Date.parse(startedAt);
118
+ if (!Number.isFinite(elapsed) || elapsed < 0) return null;
119
+ const seconds = Math.floor(elapsed / 1000);
120
+ if (seconds === 0) return "<1s";
121
+ const parts: string[] = [];
122
+ if (seconds >= 86400) {
123
+ const days = Math.floor(seconds / 86400);
124
+ const hours = Math.floor((seconds % 86400) / 3600);
125
+ return `${days}d${hours ? ` ${hours}h` : ""}`;
126
+ }
127
+ if (seconds >= 3600) parts.push(`${Math.floor(seconds / 3600)}h`);
128
+ if (seconds >= 60) parts.push(`${Math.floor((seconds % 3600) / 60)}m`);
129
+ parts.push(`${seconds % 60}s`);
130
+ return parts.join(" ");
131
+ }
132
+
133
+ /** Summarize recorded decisions and events without guessing why a step repeated. */
134
+ export function describeRailHistory(
135
+ group: ChronicleRepeatedTurns,
136
+ records: ReadonlyMap<string, ProcessTimelineTurnSummary>,
137
+ ): string[] {
138
+ if (group.retryCount) {
139
+ const failures = group.items.filter(
140
+ (item) => records.get(item.turnRecordId)?.outcome === "failed",
141
+ ).length;
142
+ return failures ? [`${failures} failed ${failures === 1 ? "attempt" : "attempts"}`] : [];
143
+ }
144
+ const reasons = new Map<string, number>();
145
+ for (const item of group.items) {
146
+ const record = records.get(item.turnRecordId);
147
+ const text =
148
+ item.tone === "external_trigger"
149
+ ? record?.summary
150
+ : item.tone === "operator_decision"
151
+ ? record?.outcome
152
+ : null;
153
+ if (!text || ["completed", "succeeded", "superseded"].includes(text.toLowerCase())) continue;
154
+ const label = markdownToPlainText(text).replace(/\s+/g, " ").trim();
155
+ if (label) reasons.set(label, (reasons.get(label) ?? 0) + 1);
156
+ }
157
+ return [...reasons].map(([label, count]) => (count > 1 ? `${label} (${count})` : label));
158
+ }