@leitwerk-dev/ui 0.1.9 → 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 (170) 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-CSkNdC4m.js +1 -0
  10. package/dist/assets/PageHeader-DPuQInDo.css +1 -0
  11. package/dist/assets/PageHeader-sphJnWL1.js +1 -0
  12. package/dist/assets/ProcessActionsMenu-DLMywI9c.js +1 -0
  13. package/dist/assets/ProcessActionsMenu-VKT7PE6z.css +1 -0
  14. package/dist/assets/ProcessDetailPage-Cth6A0DN.css +1 -0
  15. package/dist/assets/ProcessDetailPage-fvvdvO19.js +14 -0
  16. package/dist/assets/ProcessFlowDiagram-Dx2wheGN.js +2 -0
  17. package/dist/assets/ProcessesPage-uLl7LXp8.js +1 -0
  18. package/dist/assets/ProcessesPage-yPjjrzjg.css +1 -0
  19. package/dist/assets/ScheduleDateTimePicker-DmojMRxN.js +1 -0
  20. package/dist/assets/{ScheduleDateTimePicker-CadXN9z7.css → ScheduleDateTimePicker-uacJAkIq.css} +1 -1
  21. package/dist/assets/SkillsPage-CJrtt8xU.css +1 -0
  22. package/dist/assets/SkillsPage-CotbGUxm.js +2 -0
  23. package/dist/assets/WatchersPage-ByWGNJet.js +1 -0
  24. package/dist/assets/WatchersPage-cRBnmTAD.css +1 -0
  25. package/dist/assets/external-links-CX92-VRP.js +1 -0
  26. package/dist/assets/http-client-VpPXJwbR.js +2 -0
  27. package/dist/assets/index-C7zNe3je.js +6 -0
  28. package/dist/assets/index-DtEI5gsQ.css +1 -0
  29. package/dist/assets/index-client-BYQviCtQ.js +2 -0
  30. package/dist/assets/{mermaid-render.worker-DAVgiVRG.js → mermaid-render.worker-QW2WZpEE.js} +12 -12
  31. package/dist/assets/process-terminal-display-BQRQwGod.js +1 -0
  32. package/dist/assets/router.svelte-EEldxHlO.js +1 -0
  33. package/dist/index.html +8 -8
  34. package/package.json +8 -8
  35. package/src/App.svelte +36 -0
  36. package/src/chronicle/components/ChronicleActionSection.svelte +70 -143
  37. package/src/chronicle/components/ChronicleCreateIssueButton.svelte +22 -0
  38. package/src/chronicle/components/ChronicleEntryHeader.svelte +76 -0
  39. package/src/chronicle/components/ChronicleExpandButton.svelte +11 -34
  40. package/src/chronicle/components/ChronicleFailureMessage.svelte +41 -0
  41. package/src/chronicle/components/ChronicleFlow.svelte +133 -28
  42. package/src/chronicle/components/ChronicleLeafOutcomeRendererHost.svelte +1 -8
  43. package/src/chronicle/components/ChronicleLeafOutcomeSection.svelte +25 -52
  44. package/src/chronicle/components/ChronicleLiveChip.svelte +1 -35
  45. package/src/chronicle/components/ChronicleLiveTail.svelte +55 -154
  46. package/src/chronicle/components/ChronicleMarkdown.svelte +6 -6
  47. package/src/chronicle/components/ChronicleOperatorInputSection.svelte +5 -18
  48. package/src/chronicle/components/ChronicleProcessErrorSection.svelte +10 -107
  49. package/src/chronicle/components/ChroniclePromptSection.svelte +6 -26
  50. package/src/chronicle/components/ChronicleQuestionRequest.svelte +22 -5
  51. package/src/chronicle/components/ChronicleReasoningDetailsOverlay.svelte +71 -109
  52. package/src/chronicle/components/ChronicleRecoverySection.svelte +96 -264
  53. package/src/chronicle/components/ChronicleScheduledActionSection.svelte +1 -1
  54. package/src/chronicle/components/ChronicleSectionHeader.svelte +1 -4
  55. package/src/chronicle/components/ChronicleStartupHistory.svelte +63 -0
  56. package/src/chronicle/components/ChronicleStartupRecoverySection.svelte +10 -26
  57. package/src/chronicle/components/ChronicleThinkingSection.svelte +25 -165
  58. package/src/chronicle/components/ChronicleThinkingText.svelte +1 -0
  59. package/src/chronicle/components/ChronicleToolApproval.svelte +40 -0
  60. package/src/chronicle/components/ChronicleToolCallItem.svelte +1 -1
  61. package/src/chronicle/components/ChronicleTurnCluster.svelte +208 -284
  62. package/src/chronicle/components/ChronicleTurnDetailsButton.svelte +16 -0
  63. package/src/chronicle/components/ChronicleTurnProgress.svelte +77 -54
  64. package/src/chronicle/components/ChronicleTurnRail.svelte +327 -391
  65. package/src/chronicle/components/CompactActionComposer.svelte +36 -13
  66. package/src/chronicle/components/ReadonlyJsonValue.svelte +30 -0
  67. package/src/chronicle/lib/action-bindings.ts +1 -1
  68. package/src/chronicle/lib/action-model-display.ts +2 -2
  69. package/src/chronicle/lib/action-preview.ts +1 -1
  70. package/src/chronicle/lib/chronicle-projection.ts +125 -109
  71. package/src/chronicle/lib/chronicle-rail-groups.ts +158 -0
  72. package/src/chronicle/lib/chronicle-selectable-items.ts +16 -11
  73. package/src/chronicle/lib/chronicle-ticket-artifact.ts +7 -0
  74. package/src/chronicle/lib/formatting.ts +19 -0
  75. package/src/chronicle/lib/leaf-outcome-loader.ts +30 -111
  76. package/src/chronicle/lib/leaf-outcome-runtime.ts +3 -15
  77. package/src/chronicle/lib/result-presentation.ts +40 -0
  78. package/src/chronicle/lib/retry-groups.ts +24 -0
  79. package/src/chronicle/lib/scroll-sync.ts +1 -0
  80. package/src/chronicle/lib/tool-call-summary.ts +1 -9
  81. package/src/chronicle/ticket-selection.ts +23 -0
  82. package/src/components/ElapsedTime.svelte +31 -0
  83. package/src/components/ExternalLink.svelte +39 -0
  84. package/src/components/FormFieldRenderer.svelte +4 -1
  85. package/src/components/GenericLauncher.svelte +40 -15
  86. package/src/components/KeyboardShortcutsModal.svelte +2 -2
  87. package/src/components/LaunchChecklist.svelte +184 -0
  88. package/src/components/ModalShell.svelte +43 -32
  89. package/src/components/PageHeader.svelte +7 -33
  90. package/src/components/ProcessActionsMenu.svelte +217 -140
  91. package/src/components/ProcessInfoOverlay.svelte +13 -21
  92. package/src/components/ProgressChecklist.svelte +46 -0
  93. package/src/components/ProgressChecklistRows.svelte +80 -0
  94. package/src/components/launcher-form-copy.ts +4 -1
  95. package/src/components/launcher-model-config.ts +1 -1
  96. package/src/extension-ui-dev-server.ts +2 -5
  97. package/src/lib/api-tokens.ts +34 -0
  98. package/src/lib/api.ts +323 -455
  99. package/src/lib/elapsed-time.ts +19 -0
  100. package/src/lib/external-links.ts +81 -0
  101. package/src/lib/flow-layout.ts +1 -8
  102. package/src/lib/format.ts +3 -26
  103. package/src/lib/future-launch-detail.ts +1 -1
  104. package/src/lib/http-client.ts +79 -0
  105. package/src/lib/launch-updates.ts +17 -0
  106. package/src/lib/markdown.ts +8 -1
  107. package/src/lib/primary-path-detail.ts +97 -3
  108. package/src/lib/primary-path-replay.ts +13 -7
  109. package/src/lib/process-row-view.ts +1 -1
  110. package/src/lib/process-terminal-display.ts +4 -7
  111. package/src/lib/processes.svelte.ts +41 -9
  112. package/src/lib/reasoning-history.ts +95 -0
  113. package/src/lib/retry-config.svelte.ts +1 -1
  114. package/src/lib/rich-markdown-elements.ts +2 -2
  115. package/src/lib/router-logic.ts +3 -0
  116. package/src/lib/runtime-config.ts +1 -3
  117. package/src/lib/test-fixtures.ts +1 -1
  118. package/src/lib/tool-call-rendering.ts +4 -1
  119. package/src/lib/ui-extensions.svelte.ts +78 -127
  120. package/src/lib/ws-classifier.ts +8 -1
  121. package/src/pages/ApiTokensPage.svelte +213 -0
  122. package/src/pages/FutureLaunchDetailPage.svelte +7 -35
  123. package/src/pages/HomePage.svelte +7 -7
  124. package/src/pages/ProcessCard.svelte +1 -1
  125. package/src/pages/ProcessDetailPage.svelte +158 -62
  126. package/src/pages/ProcessGallery.svelte +1 -1
  127. package/src/pages/ProcessesPage.svelte +7 -42
  128. package/src/pages/SkillsPage.svelte +37 -26
  129. package/src/pages/WatchersPage.svelte +31 -53
  130. package/src/pages/process-detail/ProcessDetailChronicle.svelte +125 -28
  131. package/src/pages/process-detail/ProcessDetailHeader.svelte +24 -2
  132. package/src/pages/process-detail/ProcessSummary.svelte +35 -0
  133. package/src/pages/process-detail/TicketCreationComposer.svelte +219 -0
  134. package/src/pages/process-detail/process-detail-action-drafts.svelte.ts +5 -5
  135. package/src/pages/process-detail/process-detail-actions.svelte.ts +4 -2
  136. package/src/pages/process-detail/process-detail-chronicle-dom.ts +39 -14
  137. package/src/pages/process-detail/process-detail-chronicle-scroll.svelte.ts +68 -10
  138. package/src/pages/process-detail/process-detail-view-model.ts +10 -24
  139. package/src/shell/AppShell.svelte +4 -1
  140. package/src/shell/Sidebar.svelte +88 -125
  141. package/src/styles/controls.css +188 -0
  142. package/dist/assets/ChronicleMarkdown-B1hD4HFS.js +0 -16
  143. package/dist/assets/ChronicleMarkdown-D6hFzERy.css +0 -1
  144. package/dist/assets/FutureLaunchDetailPage-Dy3FlLih.js +0 -1
  145. package/dist/assets/FutureLaunchDetailPage-UFgp7Ju4.css +0 -1
  146. package/dist/assets/GenericLauncher-BPEQjJ1J.js +0 -1
  147. package/dist/assets/GenericLauncher-D_GMtsQ5.css +0 -1
  148. package/dist/assets/HomePage-E41Krxko.js +0 -1
  149. package/dist/assets/PageHeader-DDgWPeHS.js +0 -1
  150. package/dist/assets/PageHeader-vhyfX7xT.css +0 -1
  151. package/dist/assets/ProcessActionsMenu-BWlFe5c4.css +0 -1
  152. package/dist/assets/ProcessActionsMenu-cI0j2LWe.js +0 -1
  153. package/dist/assets/ProcessDetailPage-DVHldJgi.js +0 -12
  154. package/dist/assets/ProcessDetailPage-Oh6ld320.css +0 -1
  155. package/dist/assets/ProcessFlowDiagram-C6m6V_cB.js +0 -2
  156. package/dist/assets/ProcessesPage-B2QGyCZO.js +0 -1
  157. package/dist/assets/ProcessesPage-BcM38HMs.css +0 -1
  158. package/dist/assets/ScheduleDateTimePicker-aey_oMiH.js +0 -1
  159. package/dist/assets/SkillsPage-MPITMvhn.css +0 -1
  160. package/dist/assets/SkillsPage-iB4sbq7r.js +0 -2
  161. package/dist/assets/WatchersPage-BOSgjtw0.css +0 -1
  162. package/dist/assets/WatchersPage-l0rwv-Nx.js +0 -1
  163. package/dist/assets/api-CtKbU0lT.js +0 -1
  164. package/dist/assets/dist-eOPUi0B8.js +0 -2
  165. package/dist/assets/index-B4flHG_s.js +0 -7
  166. package/dist/assets/index-DunTIQSW.css +0 -1
  167. package/dist/assets/index-client-CnG8mWmF.js +0 -2
  168. package/dist/assets/retry-config.svelte-WukHimiy.js +0 -1
  169. package/dist/assets/router.svelte-2RvxUvs5.js +0 -1
  170. package/src/lib/process-initial-prompt.ts +0 -7
@@ -2,14 +2,15 @@ import {
2
2
  formatPathTypeLabel,
3
3
  type ProcessInput,
4
4
  type ProcessLeafOutcomeSnapshot,
5
+ type ProcessQuestionRequest,
5
6
  type ProcessTurnRecord,
6
7
  type TurnProgressReport,
7
- trimToNull,
8
8
  } from "@leitwerk-dev/domain";
9
9
  import {
10
- buildTrailingLinePreview,
10
+ type CompactActiveTurnSnapshot,
11
11
  type PrimaryPathActiveTurnSnapshot,
12
12
  type ProcessTimelineTurnSummary,
13
+ reasoningPreviewTail,
13
14
  type TurnPiInputPart,
14
15
  type TurnTracePreview,
15
16
  type TurnTraceSnapshot,
@@ -23,7 +24,7 @@ type ChronicleInput = Pick<
23
24
 
24
25
  import type { ProcessRunDetailsView } from "@leitwerk-dev/protocol/http-contracts";
25
26
  import { formatDefinition } from "../../lib/format";
26
- import { markdownToPlainText, truncateText } from "../../lib/markdown";
27
+ import { truncateText } from "../../lib/markdown";
27
28
  import { hasDisplayableText } from "../../lib/pi-stream.js";
28
29
  import {
29
30
  getProcessTerminalRailTitle,
@@ -120,11 +121,14 @@ export interface ChronicleOperatorDecisionSection {
120
121
  export interface ChronicleTurnResultSection {
121
122
  kind: "turn_result";
122
123
  markdown: string;
124
+ resultSummary?: string;
123
125
  }
124
126
 
125
127
  export interface ChronicleTurnProgressSection {
126
128
  kind: "turn_progress";
127
129
  report: TurnProgressReport;
130
+ attemptStatus?: string;
131
+ recordedAt?: string;
128
132
  }
129
133
 
130
134
  export type ChronicleTurnClusterSection =
@@ -135,6 +139,10 @@ export type ChronicleTurnClusterSection =
135
139
 
136
140
  export interface ChronicleTurnClusterItem {
137
141
  kind: "turn_cluster";
142
+ parentTurnRecordId?: string | null;
143
+ reviewedTurnRecordId?: string;
144
+ resources?: TurnRecordView["resources"];
145
+ transition?: TurnRecordView["transition"];
138
146
  chronologyAt: string;
139
147
  anchorId: string;
140
148
  turnRecordId: string;
@@ -155,6 +163,7 @@ export interface ChronicleTurnClusterItem {
155
163
  triggeringInput: ChronicleTriggeringInputSummary | null;
156
164
  piInput: ChroniclePiInputSummary | null;
157
165
  facts: ChronicleTurnFacts;
166
+ failure?: { summary: string };
158
167
  }
159
168
 
160
169
  export interface ChroniclePromptItem {
@@ -205,7 +214,10 @@ export interface ChronicleLeafOutcomePlaceholderItem {
205
214
  }
206
215
 
207
216
  export interface ChronicleLiveTailItem {
217
+ progress?: TurnRecordView["progress"];
218
+ progressRecordedAt?: string;
208
219
  kind: "live_tail";
220
+ parentTurnRecordId?: string | null;
209
221
  anchorId: string;
210
222
  turnRecordId: string;
211
223
  turnId: string;
@@ -216,6 +228,7 @@ export interface ChronicleLiveTailItem {
216
228
  state: "tool_running" | "thinking" | "streaming" | "waiting";
217
229
  stateLabel: string;
218
230
  copy: string;
231
+ assistantTextPreview: string;
219
232
  reasoningSection: ChronicleThinkingSection | null;
220
233
  toolCall: PrimaryPathActiveTurnSnapshot["toolCalls"][number] | null;
221
234
  usage: TurnUsageSnapshot | null;
@@ -276,7 +289,7 @@ export interface BuildChronicleProjectionInput {
276
289
  inputs: readonly ChronicleInput[];
277
290
  leafOutcomeSnapshots: readonly ProcessLeafOutcomeSnapshot[];
278
291
  definesLeafOutcome: boolean;
279
- activeTurn: PrimaryPathActiveTurnSnapshot | null | undefined;
292
+ activeTurn: PrimaryPathActiveTurnSnapshot | CompactActiveTurnSnapshot | null | undefined;
280
293
  lifecycleStatus?: string | null;
281
294
  selectedTurnId?: string | null;
282
295
  processUpdatedAt?: string | null;
@@ -285,8 +298,8 @@ export interface BuildChronicleProjectionInput {
285
298
  }
286
299
 
287
300
  // Tunable inline reasoning window: keep the preview calm, recent, and line-based.
288
- export const THINKING_PREVIEW_LINE_COUNT = 3;
289
- const THINKING_PREVIEW_MAX_LENGTH = 320;
301
+ export const THINKING_PREVIEW_LINE_COUNT = 4;
302
+ const THINKING_PREVIEW_MAX_LENGTH = 1024;
290
303
 
291
304
  function sanitizeDomToken(value: string): string {
292
305
  return value.replace(/[^a-zA-Z0-9_-]/g, "_");
@@ -312,10 +325,6 @@ function buildTerminalAnchorId(status: ProcessTerminalStatus): string {
312
325
  return `chronicle-terminal-${sanitizeDomToken(status)}`;
313
326
  }
314
327
 
315
- function normalizeComparableText(value: string): string {
316
- return value.replace(/\s+/g, " ").trim();
317
- }
318
-
319
328
  function buildReasoningTimelineItems(
320
329
  turnTrace: TurnTraceSnapshot | undefined,
321
330
  ): ChronicleReasoningTimelineItem[] {
@@ -412,11 +421,10 @@ function buildReasoningSection(source: TurnTraceProjectionSource): ChronicleThin
412
421
  return null;
413
422
  }
414
423
  const thinkingPreview = source.trace
415
- ? buildTrailingLinePreview(
416
- thinkingText,
417
- THINKING_PREVIEW_LINE_COUNT,
418
- THINKING_PREVIEW_MAX_LENGTH,
419
- )
424
+ ? {
425
+ text: reasoningPreviewTail(thinkingText),
426
+ truncated: thinkingText.length > THINKING_PREVIEW_MAX_LENGTH,
427
+ }
420
428
  : {
421
429
  text: source.preview?.thinkingPreview ?? "",
422
430
  truncated: source.preview?.thinkingPreviewTruncated ?? false,
@@ -533,8 +541,8 @@ function toPiInputSummary(input: {
533
541
  fullPrompt,
534
542
  createdAt: piInput?.createdAt ?? previewInput?.createdAt ?? "",
535
543
  userInput:
536
- trimToNull(input.triggeringInput?.bodyMarkdown) ??
537
- trimToNull(input.initialUserInputText) ??
544
+ promptOrNull(input.triggeringInput?.bodyMarkdown) ??
545
+ promptOrNull(input.initialUserInputText) ??
538
546
  null,
539
547
  };
540
548
  }
@@ -542,7 +550,7 @@ function toPiInputSummary(input: {
542
550
  function buildTurnFacts(input: {
543
551
  turnId: string;
544
552
  durableTurnRecord: TurnRecordView | undefined;
545
- activeTurn?: PrimaryPathActiveTurnSnapshot | null;
553
+ activeTurn?: PrimaryPathActiveTurnSnapshot | CompactActiveTurnSnapshot | null;
546
554
  triggeringInput: ChronicleTriggeringInputSummary | null;
547
555
  actionSource: ChronicleActionSource | null;
548
556
  runDetails?: ProcessRunDetailsView | null;
@@ -578,25 +586,6 @@ function isStandaloneChronicleOperatorInput(input: ChronicleInput): boolean {
578
586
  return input.source === "app_steer" || input.source === "external_comment";
579
587
  }
580
588
 
581
- function hasDistinctTurnResult(
582
- turnRecord: TurnRecordView,
583
- assistantOutputText: string,
584
- assistantOutputTruncated = false,
585
- ): boolean {
586
- if (!hasDisplayableText(turnRecord.turnResultMarkdown)) {
587
- return false;
588
- }
589
- const markdownText = normalizeComparableText(markdownToPlainText(turnRecord.turnResultMarkdown));
590
- const assistantText = normalizeComparableText(assistantOutputText);
591
- if (markdownText.length === 0) {
592
- return false;
593
- }
594
- if (assistantOutputTruncated && assistantText.length > 0) {
595
- return !markdownText.startsWith(assistantText);
596
- }
597
- return markdownText !== assistantText;
598
- }
599
-
600
589
  function hasRenderableLeafOutcomeForTurn(
601
590
  turnRecordId: string,
602
591
  leafOutcomeSnapshots: readonly ProcessLeafOutcomeSnapshot[],
@@ -654,7 +643,17 @@ function buildTurnClusterItem(input: {
654
643
  : "";
655
644
 
656
645
  if (turnRecord.progress) {
657
- sections.push({ kind: "turn_progress", report: 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
+ });
658
657
  }
659
658
 
660
659
  if (assistantText.length === 0 && fallbackText.length > 0) {
@@ -664,22 +663,20 @@ function buildTurnClusterItem(input: {
664
663
  });
665
664
  }
666
665
 
667
- if (
668
- !input.hasRenderableLeafOutcome &&
669
- hasDistinctTurnResult(
670
- turnRecord,
671
- assistantText || fallbackText,
672
- turnTrace === undefined && turnTracePreview?.assistantTextTruncated === true,
673
- )
674
- ) {
666
+ if (!input.hasRenderableLeafOutcome && hasDisplayableText(turnRecord.turnResultMarkdown)) {
675
667
  sections.push({
676
668
  kind: "turn_result",
677
669
  markdown: turnRecord.turnResultMarkdown,
670
+ resultSummary: turnRecord.resultSummary,
678
671
  });
679
672
  }
680
673
 
681
674
  return {
682
675
  kind: "turn_cluster",
676
+ parentTurnRecordId: turnRecord.parentTurnRecordId,
677
+ reviewedTurnRecordId: turnRecord.reviewedTurnRecordId,
678
+ resources: turnRecord.resources,
679
+ transition: turnRecord.transition,
683
680
  chronologyAt: turnRecord.createdAt,
684
681
  anchorId: buildTurnAnchorId(turnRecord.id),
685
682
  turnRecordId: turnRecord.id,
@@ -704,6 +701,10 @@ function buildTurnClusterItem(input: {
704
701
  initialUserInputText: input.initialUserInputText,
705
702
  }),
706
703
  facts: input.facts,
704
+ failure:
705
+ turnRecord.outcome === "failed"
706
+ ? { summary: turnRecord.output || turnRecord.summary || "This turn failed." }
707
+ : undefined,
707
708
  };
708
709
  }
709
710
 
@@ -743,11 +744,15 @@ function buildLeafOutcomeItems(
743
744
  }));
744
745
  }
745
746
 
747
+ function promptOrNull(value: string | null | undefined): string | null {
748
+ return value?.trim() ? value : null;
749
+ }
750
+
746
751
  function buildPromptItem(
747
752
  text: string | null | undefined,
748
753
  createdAt: string | null | undefined,
749
754
  ): ChroniclePromptItem {
750
- const resolvedText = typeof text === "string" ? text.trim() : "";
755
+ const resolvedText = promptOrNull(text) ?? "";
751
756
  return {
752
757
  kind: "prompt",
753
758
  anchorId: buildPromptAnchorId(),
@@ -757,37 +762,21 @@ function buildPromptItem(
757
762
  };
758
763
  }
759
764
 
760
- function compareChronicleTimestamps(left: string, right: string): number {
761
- return left.localeCompare(right);
762
- }
763
-
764
765
  function sortInputsByConsumedAt(left: ChronicleInput, right: ChronicleInput): number {
765
766
  const leftTimestamp = left.consumedAt ?? left.receivedAt;
766
767
  const rightTimestamp = right.consumedAt ?? right.receivedAt;
767
- const timestampComparison = compareChronicleTimestamps(leftTimestamp, rightTimestamp);
768
- if (timestampComparison !== 0) {
769
- return timestampComparison;
770
- }
771
- return left.sequence - right.sequence;
768
+ return leftTimestamp.localeCompare(rightTimestamp) || left.sequence - right.sequence;
772
769
  }
773
770
 
774
771
  function sortInputsByReceivedAt(left: ChronicleInput, right: ChronicleInput): number {
775
- const timestampComparison = compareChronicleTimestamps(left.receivedAt, right.receivedAt);
776
- if (timestampComparison !== 0) {
777
- return timestampComparison;
778
- }
779
- return left.sequence - right.sequence;
772
+ return left.receivedAt.localeCompare(right.receivedAt) || left.sequence - right.sequence;
780
773
  }
781
774
 
782
775
  function sortTurnRecordsByStartedAt(
783
776
  left: Pick<TurnRecordView, "startedAt" | "id">,
784
777
  right: Pick<TurnRecordView, "startedAt" | "id">,
785
778
  ): number {
786
- const startedAtComparison = compareChronicleTimestamps(left.startedAt, right.startedAt);
787
- if (startedAtComparison !== 0) {
788
- return startedAtComparison;
789
- }
790
- return left.id.localeCompare(right.id);
779
+ return left.startedAt.localeCompare(right.startedAt) || left.id.localeCompare(right.id);
791
780
  }
792
781
 
793
782
  function isConsumedTriggeringInputCandidate(input: ChronicleInput): boolean {
@@ -798,10 +787,6 @@ function isConsumedTriggeringInputCandidate(input: ChronicleInput): boolean {
798
787
  );
799
788
  }
800
789
 
801
- function isReceivedTriggeringInputCandidate(input: ChronicleInput): boolean {
802
- return isChronicleTriggeringInput(input);
803
- }
804
-
805
790
  function toTriggeringInputSummary(
806
791
  input: ChronicleInput,
807
792
  fallbackConsumedAt?: string,
@@ -825,7 +810,7 @@ function buildInitialPromptTriggeringInputSummary(
825
810
  promptCreatedAt: string | null | undefined,
826
811
  fallbackTimestamp: string,
827
812
  ): ChronicleTriggeringInputSummary | null {
828
- const normalizedPrompt = trimToNull(initialUserInputText) ?? "";
813
+ const normalizedPrompt = promptOrNull(initialUserInputText) ?? "";
829
814
  if (!hasDisplayableText(normalizedPrompt)) {
830
815
  return null;
831
816
  }
@@ -850,7 +835,7 @@ function buildTriggeringInputIndex(
850
835
  .filter(isConsumedTriggeringInputCandidate)
851
836
  .sort(sortInputsByConsumedAt);
852
837
  const receivedCandidates = input.inputs
853
- .filter(isReceivedTriggeringInputCandidate)
838
+ .filter(isChronicleTriggeringInput)
854
839
  .sort(sortInputsByReceivedAt);
855
840
 
856
841
  const turnRecords = [...input.turnRecords].sort(sortTurnRecordsByStartedAt);
@@ -877,14 +862,11 @@ function buildTriggeringInputIndex(
877
862
  nextConsumedCandidateIndex += 1;
878
863
  continue;
879
864
  }
880
- if (
881
- windowStartExclusive &&
882
- compareChronicleTimestamps(consumedAt, windowStartExclusive) <= 0
883
- ) {
865
+ if (windowStartExclusive && consumedAt.localeCompare(windowStartExclusive) <= 0) {
884
866
  nextConsumedCandidateIndex += 1;
885
867
  continue;
886
868
  }
887
- if (compareChronicleTimestamps(consumedAt, turnRecord.startedAt) > 0) {
869
+ if (consumedAt.localeCompare(turnRecord.startedAt) > 0) {
888
870
  break;
889
871
  }
890
872
  const summary = toTriggeringInputSummary(candidate);
@@ -910,13 +892,10 @@ function buildTriggeringInputIndex(
910
892
  if (assignedInputIds.has(candidate.id)) {
911
893
  continue;
912
894
  }
913
- if (
914
- windowStartExclusive &&
915
- compareChronicleTimestamps(candidate.receivedAt, windowStartExclusive) <= 0
916
- ) {
895
+ if (windowStartExclusive && candidate.receivedAt.localeCompare(windowStartExclusive) <= 0) {
917
896
  break;
918
897
  }
919
- if (compareChronicleTimestamps(candidate.receivedAt, turnRecord.startedAt) > 0) {
898
+ if (candidate.receivedAt.localeCompare(turnRecord.startedAt) > 0) {
920
899
  continue;
921
900
  }
922
901
  const summary = toTriggeringInputSummary(candidate, candidate.receivedAt);
@@ -965,7 +944,7 @@ function mergeLiveToolCallsWithSessionDetails(
965
944
 
966
945
  function buildLiveTail(input: {
967
946
  turnRecord: TurnRecordView | null;
968
- activeTurn: PrimaryPathActiveTurnSnapshot | null | undefined;
947
+ activeTurn: PrimaryPathActiveTurnSnapshot | CompactActiveTurnSnapshot | null | undefined;
969
948
  turnTrace: TurnTraceSnapshot | undefined;
970
949
  turnTracePreview: TurnTracePreview | undefined;
971
950
  triggeringInput: ChronicleTriggeringInputSummary | null;
@@ -978,26 +957,47 @@ function buildLiveTail(input: {
978
957
  return null;
979
958
  }
980
959
  const liveToolCalls = activeTurn
981
- ? 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
+ )
982
976
  : [];
983
977
  const runningToolCall = activeTurn
984
- ? ([...liveToolCalls].reverse().find((toolCall) => toolCall.status === "running") ?? null)
978
+ ? (liveToolCalls.findLast((toolCall) => toolCall.status === "running") ?? null)
985
979
  : null;
986
980
  const thinkingText = activeTurn?.assistant.thinking ?? "";
987
981
  const assistantText = activeTurn?.assistant.text.trim() ?? "";
988
982
  const hasThinkingText = thinkingText.trim().length > 0;
989
983
  const reasoningSection = activeTurn
990
984
  ? buildReasoningSection({
991
- trace: {
985
+ trace: turnTrace ?? {
992
986
  assistant: activeTurn.assistant,
993
987
  toolCalls: liveToolCalls,
994
- traceItems: activeTurn.traceItems,
988
+ traceItems: "traceItems" in activeTurn ? activeTurn.traceItems : [],
995
989
  usage: activeTurn.usage,
996
990
  piInput: turnTrace?.piInput ?? null,
997
991
  },
998
992
  preview: turnTracePreview,
999
993
  })
1000
994
  : null;
995
+ if (activeTurn && "currentTool" in activeTurn) {
996
+ if (reasoningSection) {
997
+ reasoningSection.toolCallCount = activeTurn.toolCallCount;
998
+ reasoningSection.traceItemCount = activeTurn.traceItemCount;
999
+ }
1000
+ }
1001
1001
  const state = runningToolCall
1002
1002
  ? "tool_running"
1003
1003
  : hasThinkingText
@@ -1005,11 +1005,10 @@ function buildLiveTail(input: {
1005
1005
  : assistantText.length > 0
1006
1006
  ? "streaming"
1007
1007
  : "waiting";
1008
- const thinkingPreview = buildTrailingLinePreview(
1009
- thinkingText,
1010
- THINKING_PREVIEW_LINE_COUNT,
1011
- THINKING_PREVIEW_MAX_LENGTH,
1012
- );
1008
+ const thinkingPreview = {
1009
+ text: reasoningPreviewTail(thinkingText),
1010
+ truncated: thinkingText.length > THINKING_PREVIEW_MAX_LENGTH,
1011
+ };
1013
1012
  const copy =
1014
1013
  state === "tool_running"
1015
1014
  ? `Running ${formatDefinition(runningToolCall?.toolName ?? "tool")}…`
@@ -1029,6 +1028,9 @@ function buildLiveTail(input: {
1029
1028
 
1030
1029
  return {
1031
1030
  kind: "live_tail",
1031
+ progress: turnRecord.progress,
1032
+ progressRecordedAt: turnRecord.progressRecordedAt,
1033
+ parentTurnRecordId: turnRecord.parentTurnRecordId,
1032
1034
  anchorId: buildLiveTailAnchorId(turnRecord.id),
1033
1035
  turnRecordId: turnRecord.id,
1034
1036
  turnId: turnRecord.turnId,
@@ -1039,10 +1041,16 @@ function buildLiveTail(input: {
1039
1041
  state,
1040
1042
  stateLabel,
1041
1043
  copy,
1042
- 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),
1043
1050
  toolCall: runningToolCall,
1044
1051
  usage: activeTurn?.usage ?? null,
1045
- eventWindowTruncated: activeTurn?.eventWindowTruncated ?? false,
1052
+ eventWindowTruncated:
1053
+ activeTurn && "eventWindowTruncated" in activeTurn ? activeTurn.eventWindowTruncated : false,
1046
1054
  modelProfileId: turnRecord.modelProfileId,
1047
1055
  triggeringInput,
1048
1056
  piInput: toPiInputSummary({
@@ -1162,14 +1170,26 @@ function findReasoningSection(
1162
1170
 
1163
1171
  export function extractChronicleReasoningDetailEntries(
1164
1172
  projection: ChronicleProjection,
1173
+ questionRequests: readonly ProcessQuestionRequest[] = [],
1165
1174
  ): ChronicleReasoningDetailEntry[] {
1166
1175
  const entries: ChronicleReasoningDetailEntry[] = [];
1176
+ const questionTurnRecordIds = new Set(questionRequests.map((request) => request.turnRecordId));
1167
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
+ }
1168
1192
  if (item.kind === "turn_cluster") {
1169
- const reasoningSection = findReasoningSection(item.sections);
1170
- if (!reasoningSection) {
1171
- continue;
1172
- }
1173
1193
  entries.push({
1174
1194
  entryId: item.turnRecordId,
1175
1195
  turnRecordId: item.turnRecordId,
@@ -1187,9 +1207,6 @@ export function extractChronicleReasoningDetailEntries(
1187
1207
  });
1188
1208
  continue;
1189
1209
  }
1190
- if (item.kind !== "live_tail" || !item.reasoningSection) {
1191
- continue;
1192
- }
1193
1210
  entries.push({
1194
1211
  entryId: item.turnRecordId,
1195
1212
  turnRecordId: item.turnRecordId,
@@ -1203,7 +1220,7 @@ export function extractChronicleReasoningDetailEntries(
1203
1220
  triggeringInput: item.triggeringInput,
1204
1221
  piInput: item.piInput,
1205
1222
  facts: item.facts,
1206
- reasoningSection: item.reasoningSection,
1223
+ reasoningSection,
1207
1224
  });
1208
1225
  }
1209
1226
  return entries;
@@ -1216,7 +1233,8 @@ export function buildChronicleProjection(
1216
1233
  const resolvedTerminalStatus: ProcessTerminalStatus | null = isTerminal
1217
1234
  ? (input.lifecycleStatus as ProcessTerminalStatus)
1218
1235
  : null;
1219
- const displayPromptText = trimToNull(input.initialUserInputText) ?? trimToNull(input.promptText);
1236
+ const displayPromptText =
1237
+ promptOrNull(input.initialUserInputText) ?? promptOrNull(input.promptText);
1220
1238
  const promptItem = displayPromptText
1221
1239
  ? buildPromptItem(displayPromptText, input.promptCreatedAt)
1222
1240
  : null;
@@ -1323,12 +1341,10 @@ export function buildChronicleProjection(
1323
1341
  });
1324
1342
  }
1325
1343
 
1326
- const latestAnchorableTimelineItem = [...timelineItems]
1327
- .reverse()
1328
- .find(
1329
- (item): item is Extract<ChronicleTimelineItem, { anchorId: string }> => "anchorId" in item,
1330
- );
1331
- 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) => {
1332
1348
  return (
1333
1349
  ((item.kind === "turn_cluster" || item.kind === "live_tail") &&
1334
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
+ }