@zyro-sec/session-ui 0.0.0-stage → 1.0.3
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.
- package/AGENTS.md +25 -0
- package/bunfig.toml +2 -0
- package/component-tests/basic-tool.fixture.tsx +46 -0
- package/component-tests/basic-tool.spec.ts +63 -0
- package/component-tests/file-media.fixture.tsx +39 -0
- package/component-tests/file-media.spec.ts +13 -0
- package/component-tests/file-tool.spec.ts +62 -0
- package/component-tests/file-viewer.fixture.tsx +109 -0
- package/component-tests/file-viewer.spec.ts +134 -0
- package/component-tests/file.spec.ts +33 -0
- package/component-tests/line-comment-v2.spec.ts +15 -0
- package/component-tests/markdown-code-wrap.spec.ts +94 -0
- package/component-tests/markdown-readiness.spec.ts +95 -0
- package/component-tests/markdown.fixture.tsx +104 -0
- package/component-tests/markdown.spec.ts +1564 -0
- package/component-tests/mermaid-preview.spec.ts +43 -0
- package/component-tests/patch-group.spec.ts +79 -0
- package/component-tests/read-group.spec.ts +72 -0
- package/component-tests/read-image.fixture.tsx +66 -0
- package/component-tests/read-image.spec.ts +154 -0
- package/component-tests/session-compaction.spec.ts +254 -0
- package/component-tests/session-lifecycle.spec.ts +190 -0
- package/component-tests/session-message-projection.spec.ts +639 -0
- package/component-tests/session-notice-projection.spec.ts +20 -0
- package/component-tests/session-review-comments.spec.ts +179 -0
- package/component-tests/session-shell.spec.ts +93 -0
- package/component-tests/session-timeline-mobile.spec.ts +201 -0
- package/component-tests/session-timeline-notices.spec.ts +38 -0
- package/component-tests/session-timeline-reasoning.spec.ts +107 -0
- package/component-tests/session-timeline.spec.ts +157 -0
- package/component-tests/session-tool-projection.spec.ts +323 -0
- package/component-tests/text-lifecycle.fixture.tsx +26 -0
- package/component-tests/text-lifecycle.spec.ts +42 -0
- package/component-tests/timeline-subagent-rows.spec.ts +33 -0
- package/component-tests/tool-disclosure.spec.ts +48 -0
- package/component-tests/tool-group-sticky.spec.ts +37 -0
- package/component-tests/tool-group.spec.ts +290 -0
- package/component-tests/tool-status-title.fixture.tsx +22 -0
- package/component-tests/tool-status-title.spec.ts +30 -0
- package/component-tests/user-message-quotes.spec.ts +111 -0
- package/package.json +91 -4
- package/playwright.components.config.ts +4 -0
- package/playwright.local.config.ts +2 -0
- package/src/actions.ts +54 -0
- package/src/components/apply-patch-file.ts +122 -0
- package/src/components/basic-tool.css +487 -0
- package/src/components/basic-tool.tsx +258 -0
- package/src/components/copy-machine.ts +78 -0
- package/src/components/copy.ts +85 -0
- package/src/components/diagram-preview.tsx +28 -0
- package/src/components/disclosure-machine.ts +188 -0
- package/src/components/disclosure.ts +129 -0
- package/src/components/dock-prompt.stories.tsx +73 -0
- package/src/components/dock-prompt.tsx +29 -0
- package/src/components/file-comment-selection.tsx +146 -0
- package/src/components/file-media-machine.ts +165 -0
- package/src/components/file-media.stories.tsx +112 -0
- package/src/components/file-media.tsx +323 -0
- package/src/components/file-search.tsx +73 -0
- package/src/components/file.css +59 -0
- package/src/components/file.tsx +1300 -0
- package/src/components/image-preview.tsx +35 -0
- package/src/components/line-comment-annotations.tsx +580 -0
- package/src/components/line-comment-machine.ts +262 -0
- package/src/components/line-comment-styles.ts +293 -0
- package/src/components/line-comment.stories.tsx +152 -0
- package/src/components/line-comment.tsx +448 -0
- package/src/components/link-segments.ts +20 -0
- package/src/components/linked-text.tsx +21 -0
- package/src/components/markdown-cache-machine.ts +257 -0
- package/src/components/markdown-cache.tsx +556 -0
- package/src/components/markdown-clipboard.ts +101 -0
- package/src/components/markdown-code-machine.ts +200 -0
- package/src/components/markdown-code-state.ts +22 -0
- package/src/components/markdown-fragment-links.ts +74 -0
- package/src/components/markdown-github.svg +3 -0
- package/src/components/markdown-globe.svg +5 -0
- package/src/components/markdown-image-machine.ts +170 -0
- package/src/components/markdown-image.ts +156 -0
- package/src/components/markdown-inline-code-kind.ts +39 -0
- package/src/components/markdown-mermaid.ts +18 -0
- package/src/components/markdown-phase-machine.ts +102 -0
- package/src/components/markdown-projection.ts +13 -0
- package/src/components/markdown-session-links.ts +183 -0
- package/src/components/markdown-solid.test.tsx +92 -0
- package/src/components/markdown-solid.tsx +113 -0
- package/src/components/markdown-stream.ts +95 -0
- package/src/components/markdown-worker-machine.ts +516 -0
- package/src/components/markdown-worker-protocol.ts +73 -0
- package/src/components/markdown-worker.ts +250 -0
- package/src/components/markdown.css +672 -0
- package/src/components/markdown.stories.tsx +199 -0
- package/src/components/markdown.tsx +1612 -0
- package/src/components/markdown.worker.ts +188 -0
- package/src/components/message-file.ts +102 -0
- package/src/components/message-nav.css +134 -0
- package/src/components/message-nav.tsx +159 -0
- package/src/components/message-part.css +2109 -0
- package/src/components/message-part.tsx +3 -0
- package/src/components/question-prompt-experimental.css +576 -0
- package/src/components/question-prompt.css +527 -0
- package/src/components/quote-highlight.css +59 -0
- package/src/components/review-focus-driver.ts +142 -0
- package/src/components/review-focus-machine.ts +95 -0
- package/src/components/session-compaction.css +270 -0
- package/src/components/session-diff.ts +358 -0
- package/src/components/session-error.tsx +41 -0
- package/src/components/session-retry.tsx +92 -0
- package/src/components/session-review-machine.ts +241 -0
- package/src/components/session-review.css +264 -0
- package/src/components/session-review.stories.tsx +232 -0
- package/src/components/session-review.tsx +733 -0
- package/src/components/session-turn.css +282 -0
- package/src/components/shell-submessage.css +24 -0
- package/src/components/timeline-separator.tsx +69 -0
- package/src/components/tool-count-label.css +57 -0
- package/src/components/tool-count-label.tsx +76 -0
- package/src/components/tool-count-summary.css +102 -0
- package/src/components/tool-count-summary.stories.tsx +99 -0
- package/src/components/tool-count-summary.tsx +44 -0
- package/src/components/tool-error-card.css +178 -0
- package/src/components/tool-error-card.stories.tsx +113 -0
- package/src/components/tool-error-card.tsx +202 -0
- package/src/components/tool-status-title-machine.ts +128 -0
- package/src/components/tool-status-title.css +89 -0
- package/src/components/tool-status-title.tsx +163 -0
- package/src/context/data.tsx +107 -0
- package/src/context/index.ts +1 -0
- package/src/context/markdown.tsx +129 -0
- package/src/context/sources.tsx +34 -0
- package/src/document.ts +8 -0
- package/src/file-presentation.ts +34 -0
- package/src/message/action-machine.ts +72 -0
- package/src/message/agent-label.ts +3 -0
- package/src/message/attachment-card.css +119 -0
- package/src/message/attachment-card.tsx +40 -0
- package/src/message/attachment-media-machine.ts +213 -0
- package/src/message/comment-card.tsx +155 -0
- package/src/message/compaction-entrance-machine.ts +93 -0
- package/src/message/current-message.tsx +157 -0
- package/src/message/current-tool-state.ts +161 -0
- package/src/message/message-content.tsx +1391 -0
- package/src/message/paced-text-machine.ts +73 -0
- package/src/message/prompt-message.stories.tsx +149 -0
- package/src/message/relative-time.ts +45 -0
- package/src/message/user-message-quote-parts.ts +16 -0
- package/src/message/user-message-quotes.stories.tsx +797 -0
- package/src/message/user-message-quotes.tsx +135 -0
- package/src/pierre/comment-hover-machine.ts +53 -0
- package/src/pierre/comment-hover.ts +131 -0
- package/src/pierre/comment-selection-machine.ts +257 -0
- package/src/pierre/commented-lines.ts +106 -0
- package/src/pierre/diff-selection.ts +91 -0
- package/src/pierre/file-find-machine.ts +323 -0
- package/src/pierre/file-find.ts +537 -0
- package/src/pierre/file-runtime.ts +42 -0
- package/src/pierre/file-selection.ts +140 -0
- package/src/pierre/index.ts +344 -0
- package/src/pierre/media.ts +140 -0
- package/src/pierre/render-machine.ts +381 -0
- package/src/pierre/selection-bridge.ts +82 -0
- package/src/pierre/selection-machine.ts +198 -0
- package/src/pierre/virtualizer.ts +114 -0
- package/src/pierre/worker.ts +46 -0
- package/src/sources/experiment.ts +59 -0
- package/src/sources/site-icon.tsx +53 -0
- package/src/sources/sources-chip.tsx +57 -0
- package/src/sources/sources-expand-machine.ts +101 -0
- package/src/sources/sources-panel.tsx +249 -0
- package/src/sources/sources-title.tsx +21 -0
- package/src/sources/sources.css +266 -0
- package/src/sources/sources.ts +141 -0
- package/src/storybook/current-session-fixtures.ts +1492 -0
- package/src/storybook/current-session-scenarios.ts +76 -0
- package/src/storybook/current-session-story.tsx +154 -0
- package/src/storybook/index.ts +43 -0
- package/src/styles/index.css +19 -0
- package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
- package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
- package/src/timeline/code-blocks.stories.tsx +105 -0
- package/src/timeline/commentary.stories.tsx +70 -0
- package/src/timeline/commentary.ts +38 -0
- package/src/timeline/detail.ts +111 -0
- package/src/timeline/error-card.stories.tsx +134 -0
- package/src/timeline/error-spacing.stories.tsx +71 -0
- package/src/timeline/facts.ts +493 -0
- package/src/timeline/file-changes.stories.tsx +436 -0
- package/src/timeline/group-label-fixtures.ts +97 -0
- package/src/timeline/mermaid.stories.tsx +131 -0
- package/src/timeline/place.ts +280 -0
- package/src/timeline/placement-fixtures.ts +365 -0
- package/src/timeline/placement-reactivity.ts +133 -0
- package/src/timeline/projection.ts +1261 -0
- package/src/timeline/research-and-agents.stories.tsx +461 -0
- package/src/timeline/session-timeline-row.tsx +1675 -0
- package/src/timeline/session-timeline.tsx +68 -0
- package/src/timeline/steer-arrival-machine.ts +134 -0
- package/src/timeline/terminal-work.stories.tsx +464 -0
- package/src/timeline/timeline-row.stories.tsx +1069 -0
- package/src/timeline/timeline-row.ts +238 -0
- package/src/timeline/turn-phase-machine.ts +112 -0
- package/src/timeline/user-message-fold.stories.tsx +194 -0
- package/src/timeline/user-runs.ts +87 -0
- package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
- package/src/timeline-next/compaction.tsx +236 -0
- package/src/timeline-next/errors.ts +101 -0
- package/src/timeline-next/event-row.tsx +168 -0
- package/src/timeline-next/events.ts +103 -0
- package/src/timeline-next/index.ts +10 -0
- package/src/timeline-next/nested-rail.ts +125 -0
- package/src/timeline-next/projection.ts +1028 -0
- package/src/timeline-next/row.tsx +1728 -0
- package/src/timeline-next/rules.ts +89 -0
- package/src/timeline-next/separator.tsx +73 -0
- package/src/timeline-next/spacing.ts +127 -0
- package/src/timeline-next/status-line.tsx +41 -0
- package/src/timeline-next/status.ts +33 -0
- package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
- package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
- package/src/timeline-next/stories/compare.stories.tsx +486 -0
- package/src/timeline-next/stories/playground.stories.tsx +297 -0
- package/src/timeline-next/stories/session-replay.ts +1156 -0
- package/src/timeline-next/stories/session-timeline.tsx +50 -0
- package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
- package/src/timeline-next/timeline-next.css +649 -0
- package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
- package/src/timeline-next/tools/activity-label.ts +166 -0
- package/src/timeline-next/tools/assistant-content.tsx +84 -0
- package/src/timeline-next/tools/context-group.tsx +619 -0
- package/src/timeline-next/tools/error-card.tsx +147 -0
- package/src/timeline-next/tools/explore.tsx +119 -0
- package/src/timeline-next/tools/file-group.tsx +128 -0
- package/src/timeline-next/tools/patch.tsx +174 -0
- package/src/timeline-next/tools/shell.tsx +186 -0
- package/src/timeline-next/tools/thought.tsx +87 -0
- package/src/timeline-next/tools/tool-display.tsx +119 -0
- package/src/tools/ansi.ts +8 -0
- package/src/tools/context-group-label.ts +123 -0
- package/src/tools/file-runs.ts +35 -0
- package/src/tools/project-path.ts +18 -0
- package/src/tools/read-group.stories.tsx +159 -0
- package/src/tools/run-machine.ts +185 -0
- package/src/tools/shell-output-machine.ts +233 -0
- package/src/tools/shell-output.ts +91 -0
- package/src/tools/subagent-row-variants.stories.tsx +129 -0
- package/src/tools/tool-group.stories.tsx +345 -0
- package/src/tools/tool-renderer.tsx +2876 -0
- package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
- package/src/v2/components/session-file-panel-v2.tsx +149 -0
- package/src/v2/components/session-progress-indicator-v2.css +5 -0
- package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
- package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
- package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
- package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
- package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
- package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
- package/src/v2/components/session-review-v2.css +653 -0
- package/src/v2/components/session-review-v2.tsx +422 -0
- package/src/v2/components/sidebar-presence-machine.ts +69 -0
- package/tsconfig.json +20 -0
- package/README.md +0 -3
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import type { SessionMessageInfo } from "@zyro-sec/client/promise"
|
|
2
|
+
import { For, Show, createEffect, createMemo, on, onCleanup, onMount, type JSX } from "solid-js"
|
|
3
|
+
import { createStore } from "solid-js/store"
|
|
4
|
+
import { timelinePresets } from "../../timeline/detail"
|
|
5
|
+
import { createNextTimelineProjection } from "../projection"
|
|
6
|
+
import { laneGap } from "../spacing"
|
|
7
|
+
import { timelineStatus, timelineThinking } from "../status"
|
|
8
|
+
import { replayScript, replaySession, scenarios, sessionSteps, ticks } from "./session-replay"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Compares the same session drawn two ways, side by side. On its own it shows this build's current timeline beside its
|
|
12
|
+
* New timeline, which is the page to share with the team: `?id=timeline-compare--compare`. With `?base=` set to another
|
|
13
|
+
* checkout's stories server it compares that build with this one instead, such as dev with the New timeline off.
|
|
14
|
+
*
|
|
15
|
+
* Every control drives both sides, so the only difference between them is the timeline. The controls live in the
|
|
16
|
+
* address, so a link opens on the same session, setting and step.
|
|
17
|
+
*/
|
|
18
|
+
export default {
|
|
19
|
+
title: "OpenCode/Timeline/Compare",
|
|
20
|
+
id: "timeline-compare",
|
|
21
|
+
parameters: { layout: "fullscreen" },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PresetID = (typeof timelinePresets)[number]["id"]
|
|
25
|
+
|
|
26
|
+
type Side = "base" | "head"
|
|
27
|
+
|
|
28
|
+
const views = ["side", "swipe", "onion"] as const
|
|
29
|
+
|
|
30
|
+
type View = (typeof views)[number]
|
|
31
|
+
|
|
32
|
+
const defaultView: View = "side"
|
|
33
|
+
|
|
34
|
+
const defaultPreset: PresetID = "compact"
|
|
35
|
+
|
|
36
|
+
// Scripted sessions by name; a name with no script is an exported session.
|
|
37
|
+
const scripts = new Map(Object.entries(scenarios))
|
|
38
|
+
|
|
39
|
+
// Sessions exported with `script/timeline-compare.ts export <id>`. The folder is ignored by git: they hold real code.
|
|
40
|
+
const exported = Object.entries(
|
|
41
|
+
import.meta.glob<{ info: { id: string; title?: string }; messages: SessionMessageInfo[] }>(
|
|
42
|
+
"./compare-sessions/*.json",
|
|
43
|
+
{ eager: true, import: "default" },
|
|
44
|
+
),
|
|
45
|
+
).map(([path, data]) => ({
|
|
46
|
+
name:
|
|
47
|
+
data.info.title ||
|
|
48
|
+
path
|
|
49
|
+
.split("/")
|
|
50
|
+
.at(-1)!
|
|
51
|
+
.replace(/\.json$/, ""),
|
|
52
|
+
data,
|
|
53
|
+
}))
|
|
54
|
+
|
|
55
|
+
const statusLabels = {
|
|
56
|
+
waitingApproval: "Waiting for approval",
|
|
57
|
+
waitingAnswer: "Waiting for your answer",
|
|
58
|
+
waitingShell: "Waiting for shell",
|
|
59
|
+
working: "Working",
|
|
60
|
+
} as const
|
|
61
|
+
|
|
62
|
+
const sessions = [...Object.keys(scenarios), ...exported.map((session) => session.name)]
|
|
63
|
+
|
|
64
|
+
const presetIDs = timelinePresets.map((preset) => preset.id)
|
|
65
|
+
|
|
66
|
+
export const Compare = {
|
|
67
|
+
args: {
|
|
68
|
+
session: sessions[0]!,
|
|
69
|
+
preset: defaultPreset,
|
|
70
|
+
view: defaultView,
|
|
71
|
+
theme: "dark",
|
|
72
|
+
width: 720,
|
|
73
|
+
turnDiffs: false,
|
|
74
|
+
mix: 50,
|
|
75
|
+
},
|
|
76
|
+
argTypes: {
|
|
77
|
+
session: { options: sessions },
|
|
78
|
+
preset: { options: presetIDs },
|
|
79
|
+
view: { options: views },
|
|
80
|
+
theme: { options: ["light", "dark"] },
|
|
81
|
+
width: { control: { type: "range", min: 480, max: 960, step: 240 } },
|
|
82
|
+
mix: { control: { type: "range", min: 0, max: 100, step: 1 } },
|
|
83
|
+
},
|
|
84
|
+
render: (args: {
|
|
85
|
+
session: string
|
|
86
|
+
preset: PresetID
|
|
87
|
+
view: View
|
|
88
|
+
theme: "light" | "dark"
|
|
89
|
+
width: number
|
|
90
|
+
turnDiffs: boolean
|
|
91
|
+
mix: number
|
|
92
|
+
}) => {
|
|
93
|
+
const query = new URLSearchParams(location.search)
|
|
94
|
+
// Without another build to compare, the page compares this build's two timelines.
|
|
95
|
+
const other = query.get("base")
|
|
96
|
+
// This build's own page, wherever it is hosted, and the other build's stories server.
|
|
97
|
+
const self = location.href.split("?")[0]!
|
|
98
|
+
const base = other ? `${other.replace(/\/$/, "")}/` : self
|
|
99
|
+
const baseLabel = query.get("baseLabel") ?? (other ? "base" : "Current timeline")
|
|
100
|
+
const headLabel = query.get("headLabel") ?? (other ? "head" : "New timeline")
|
|
101
|
+
const number = (key: string) => (query.has(key) ? Number(query.get(key)) : undefined)
|
|
102
|
+
|
|
103
|
+
const [state, setState] = createStore({
|
|
104
|
+
session: sessions.find((session) => session === query.get("session")) ?? args.session,
|
|
105
|
+
preset: presetIDs.find((preset) => preset === query.get("preset")) ?? args.preset,
|
|
106
|
+
next: query.get("next") !== "false",
|
|
107
|
+
baseNext: query.get("baseNext") === "true",
|
|
108
|
+
tick: number("step") ?? Number.MAX_SAFE_INTEGER,
|
|
109
|
+
playing: false,
|
|
110
|
+
width: ([480, 720, 960] as const).find((width) => width === number("width")) ?? args.width,
|
|
111
|
+
theme: (["light", "dark"] as const).find((theme) => theme === query.get("theme")) ?? args.theme,
|
|
112
|
+
turnDiffs: query.has("files") ? query.get("files") === "true" : args.turnDiffs,
|
|
113
|
+
view: views.find((view) => view === query.get("view")) ?? args.view,
|
|
114
|
+
mix: args.mix,
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// A standalone comparison may have opened at a bookmarked setting. Only subsequent inspector edits override it.
|
|
118
|
+
createEffect(
|
|
119
|
+
on(
|
|
120
|
+
() => args.session,
|
|
121
|
+
(session) => setState({ session, tick: Number.MAX_SAFE_INTEGER, playing: false }),
|
|
122
|
+
{ defer: true },
|
|
123
|
+
),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
for (const key of ["preset", "view", "theme", "width", "turnDiffs", "mix"] as const) {
|
|
127
|
+
createEffect(
|
|
128
|
+
on(
|
|
129
|
+
() => args[key],
|
|
130
|
+
(value) => setState({ [key]: value }),
|
|
131
|
+
{ defer: true },
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The address follows the controls, so a link opens where it was copied.
|
|
137
|
+
createEffect(() => {
|
|
138
|
+
if (query.get("id") !== "timeline-compare--compare") return
|
|
139
|
+
const address = new URLSearchParams(location.search)
|
|
140
|
+
address.set("session", state.session)
|
|
141
|
+
address.set("preset", state.preset)
|
|
142
|
+
address.set("theme", state.theme)
|
|
143
|
+
address.set("width", String(state.width))
|
|
144
|
+
address.set("view", state.view)
|
|
145
|
+
|
|
146
|
+
if (state.turnDiffs) address.set("files", "true")
|
|
147
|
+
else address.delete("files")
|
|
148
|
+
|
|
149
|
+
if (state.tick < Number.MAX_SAFE_INTEGER) address.set("step", String(state.tick))
|
|
150
|
+
else address.delete("step")
|
|
151
|
+
history.replaceState(history.state, "", `?${address}`)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
const real = createMemo(() => exported.find((session) => session.name === state.session)?.data)
|
|
155
|
+
|
|
156
|
+
const total = createMemo(() => {
|
|
157
|
+
const session = real()
|
|
158
|
+
|
|
159
|
+
if (session) return sessionSteps(session.messages)
|
|
160
|
+
|
|
161
|
+
return (scripts.get(state.session) ?? []).reduce((sum, beat) => sum + ticks(beat), 0)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const tick = createMemo(() => Math.min(state.tick, total()))
|
|
165
|
+
|
|
166
|
+
// The playhead is now, so live durations read like a session happening as you watch.
|
|
167
|
+
const replay = createMemo(() => {
|
|
168
|
+
const session = real()
|
|
169
|
+
|
|
170
|
+
if (session) return replaySession(session.info.id, session.messages, tick())
|
|
171
|
+
|
|
172
|
+
return replayScript(scripts.get(state.session) ?? [], tick(), Date.now() - tick() * 1_500)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const detail = createMemo(() => timelinePresets.find((preset) => preset.id === state.preset)!.value)
|
|
176
|
+
const busy = () => replay().document.status.type === "busy"
|
|
177
|
+
|
|
178
|
+
const nextStatus = createMemo(() => {
|
|
179
|
+
if (!busy()) return undefined
|
|
180
|
+
const last = replay().document.messages.findLast((message) => message.type === "assistant")
|
|
181
|
+
const content = last?.type === "assistant" ? last.content : []
|
|
182
|
+
const status = timelineStatus({ content })
|
|
183
|
+
|
|
184
|
+
// The thought the model is writing says Thinking in its own row, in place of Working.
|
|
185
|
+
if (status === "working" && timelineThinking(detail(), content)) return undefined
|
|
186
|
+
|
|
187
|
+
return statusLabels[status]
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
const projection = createNextTimelineProjection({
|
|
191
|
+
sessionMessages: () => replay().document.messages,
|
|
192
|
+
status: () => replay().document.status,
|
|
193
|
+
timelineDetail: detail,
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
// Where the New timeline's status line sits: the space its next row would take, as the app computes it.
|
|
197
|
+
const laneSpacing = createMemo(() => {
|
|
198
|
+
const active = projection.activeMessageID()
|
|
199
|
+
|
|
200
|
+
return active ? laneGap(projection.rows(), active, projection.messageByID()) : undefined
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
// As in the app: a shell or subagent call still running in the step the agent is on blocks the turn.
|
|
204
|
+
const blocking = createMemo(() => {
|
|
205
|
+
if (!busy()) return false
|
|
206
|
+
const last = replay().document.messages.findLast((message) => message.type === "assistant")
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
last?.type === "assistant" &&
|
|
210
|
+
last.time.completed === undefined &&
|
|
211
|
+
last.content.some(
|
|
212
|
+
(part) =>
|
|
213
|
+
part.type === "tool" &&
|
|
214
|
+
part.state.status === "running" &&
|
|
215
|
+
(part.name === "shell" || part.name === "subagent"),
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const collapsed = createMemo(() => {
|
|
221
|
+
if (!busy()) return false
|
|
222
|
+
const last = replay().document.messages.findLast((message) => message.type === "assistant")
|
|
223
|
+
|
|
224
|
+
return !nextStatus() && timelineThinking(detail(), last?.type === "assistant" ? last.content : [])
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
const next = (side: "base" | "head") => (side === "head" ? state.next : state.baseNext)
|
|
228
|
+
|
|
229
|
+
const frames = new Map<Side, HTMLIFrameElement>()
|
|
230
|
+
|
|
231
|
+
const send = (side: Side) =>
|
|
232
|
+
frames.get(side)?.contentWindow?.postMessage(
|
|
233
|
+
{
|
|
234
|
+
type: "timeline-compare:render",
|
|
235
|
+
document: replay().document,
|
|
236
|
+
detail: detail(),
|
|
237
|
+
activity: next(side),
|
|
238
|
+
turnDiffs: state.turnDiffs,
|
|
239
|
+
width: state.width,
|
|
240
|
+
status: next(side) ? nextStatus() : busy() ? "Working" : undefined,
|
|
241
|
+
lane: next(side) ? "activity" : "legacy",
|
|
242
|
+
collapsed: next(side) && collapsed(),
|
|
243
|
+
spacing: next(side) ? laneSpacing() : undefined,
|
|
244
|
+
hint: blocking(),
|
|
245
|
+
hintDelay: next(side) ? 300 : 0,
|
|
246
|
+
},
|
|
247
|
+
"*",
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
createEffect(() => {
|
|
251
|
+
send("base")
|
|
252
|
+
send("head")
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
// A frame that loads, or reloads for a theme, asks for the session. A scroll in one lines the other up with it.
|
|
256
|
+
const receive = (event: MessageEvent<{ type: string; anchor: string; offset: number }>) => {
|
|
257
|
+
const side =
|
|
258
|
+
event.source === frames.get("base")?.contentWindow
|
|
259
|
+
? "base"
|
|
260
|
+
: event.source === frames.get("head")?.contentWindow
|
|
261
|
+
? "head"
|
|
262
|
+
: undefined
|
|
263
|
+
|
|
264
|
+
if (!side) return
|
|
265
|
+
|
|
266
|
+
if (event.data?.type === "timeline-compare:ready") return send(side)
|
|
267
|
+
|
|
268
|
+
if (event.data?.type !== "timeline-compare:scroll") return
|
|
269
|
+
frames
|
|
270
|
+
.get(side === "base" ? "head" : "base")
|
|
271
|
+
?.contentWindow?.postMessage(
|
|
272
|
+
{ type: "timeline-compare:scroll-to", anchor: event.data.anchor, offset: event.data.offset },
|
|
273
|
+
"*",
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
onMount(() => window.addEventListener("message", receive))
|
|
278
|
+
onCleanup(() => window.removeEventListener("message", receive))
|
|
279
|
+
|
|
280
|
+
createEffect(() => {
|
|
281
|
+
if (!state.playing) return
|
|
282
|
+
|
|
283
|
+
const timer = setInterval(() => {
|
|
284
|
+
if (tick() >= total()) return setState("playing", false)
|
|
285
|
+
setState("tick", tick() + 1)
|
|
286
|
+
}, 700)
|
|
287
|
+
|
|
288
|
+
onCleanup(() => clearInterval(timer))
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
const src = (page: string) => `${page}?id=timeline-compare-renderer--renderer&globals=theme:${state.theme}`
|
|
292
|
+
|
|
293
|
+
const frame = (side: Side, origin: string, style?: JSX.CSSProperties) => (
|
|
294
|
+
<Show when={state.theme} keyed>
|
|
295
|
+
{(_) => (
|
|
296
|
+
<iframe
|
|
297
|
+
ref={(element) => frames.set(side, element)}
|
|
298
|
+
title={side === "base" ? baseLabel : headLabel}
|
|
299
|
+
src={src(origin)}
|
|
300
|
+
class="absolute inset-0 h-full w-full border-0"
|
|
301
|
+
style={style}
|
|
302
|
+
/>
|
|
303
|
+
)}
|
|
304
|
+
</Show>
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
<div class="flex h-screen min-h-0 flex-col bg-v2-background-bg-base text-v2-text-text-base">
|
|
309
|
+
<div class="flex flex-wrap items-center gap-x-5 gap-y-2 border-b border-v2-border-border-base px-5 py-2.5 text-13-regular">
|
|
310
|
+
<Choice
|
|
311
|
+
label="Session"
|
|
312
|
+
options={sessions}
|
|
313
|
+
value={state.session}
|
|
314
|
+
onChange={(session) => setState({ session, tick: Number.MAX_SAFE_INTEGER, playing: false })}
|
|
315
|
+
/>
|
|
316
|
+
<Choice
|
|
317
|
+
label="Preset"
|
|
318
|
+
options={presetIDs}
|
|
319
|
+
value={state.preset}
|
|
320
|
+
onChange={(preset) => setState("preset", preset)}
|
|
321
|
+
/>
|
|
322
|
+
<Show when={other}>
|
|
323
|
+
<Check
|
|
324
|
+
label={`New timeline (${headLabel})`}
|
|
325
|
+
checked={state.next}
|
|
326
|
+
onChange={(next) => setState("next", next)}
|
|
327
|
+
/>
|
|
328
|
+
<Check
|
|
329
|
+
label={`New timeline (${baseLabel})`}
|
|
330
|
+
checked={state.baseNext}
|
|
331
|
+
onChange={(next) => setState("baseNext", next)}
|
|
332
|
+
/>
|
|
333
|
+
</Show>
|
|
334
|
+
<Choice
|
|
335
|
+
label="Width"
|
|
336
|
+
options={[480, 720, 960] as const}
|
|
337
|
+
value={state.width}
|
|
338
|
+
onChange={(width) => setState("width", width)}
|
|
339
|
+
/>
|
|
340
|
+
<Choice
|
|
341
|
+
label="Theme"
|
|
342
|
+
options={["light", "dark"] as const}
|
|
343
|
+
value={state.theme}
|
|
344
|
+
onChange={(theme) => setState("theme", theme)}
|
|
345
|
+
/>
|
|
346
|
+
<Check
|
|
347
|
+
label="Changed files"
|
|
348
|
+
checked={state.turnDiffs}
|
|
349
|
+
onChange={(turnDiffs) => setState("turnDiffs", turnDiffs)}
|
|
350
|
+
/>
|
|
351
|
+
<Choice
|
|
352
|
+
label="View"
|
|
353
|
+
options={["side", "swipe", "onion"] as const}
|
|
354
|
+
value={state.view}
|
|
355
|
+
onChange={(view) => setState("view", view)}
|
|
356
|
+
/>
|
|
357
|
+
<Show when={state.view !== "side"}>
|
|
358
|
+
<input
|
|
359
|
+
type="range"
|
|
360
|
+
aria-label={state.view === "swipe" ? "Divider" : "Head opacity"}
|
|
361
|
+
min="0"
|
|
362
|
+
max="100"
|
|
363
|
+
value={state.mix}
|
|
364
|
+
onInput={(event) => setState("mix", event.currentTarget.valueAsNumber)}
|
|
365
|
+
/>
|
|
366
|
+
</Show>
|
|
367
|
+
</div>
|
|
368
|
+
<div class="flex items-center gap-3 border-b border-v2-border-border-base px-5 py-2.5 text-13-regular">
|
|
369
|
+
<button
|
|
370
|
+
type="button"
|
|
371
|
+
class="w-16 rounded-md border border-v2-border-border-base px-2 py-1"
|
|
372
|
+
onClick={() => {
|
|
373
|
+
if (tick() >= total()) setState("tick", 0)
|
|
374
|
+
setState("playing", !state.playing)
|
|
375
|
+
}}
|
|
376
|
+
>
|
|
377
|
+
{state.playing ? "Pause" : "Play"}
|
|
378
|
+
</button>
|
|
379
|
+
<button
|
|
380
|
+
type="button"
|
|
381
|
+
class="rounded-md border border-v2-border-border-base px-2 py-1"
|
|
382
|
+
onClick={() => setState({ tick: Math.max(0, tick() - 1), playing: false })}
|
|
383
|
+
>
|
|
384
|
+
‹
|
|
385
|
+
</button>
|
|
386
|
+
<button
|
|
387
|
+
type="button"
|
|
388
|
+
class="rounded-md border border-v2-border-border-base px-2 py-1"
|
|
389
|
+
onClick={() => setState({ tick: Math.min(total(), tick() + 1), playing: false })}
|
|
390
|
+
>
|
|
391
|
+
›
|
|
392
|
+
</button>
|
|
393
|
+
<input
|
|
394
|
+
type="range"
|
|
395
|
+
aria-label="Point in the session"
|
|
396
|
+
class="min-w-0 flex-1"
|
|
397
|
+
min="0"
|
|
398
|
+
max={total()}
|
|
399
|
+
value={tick()}
|
|
400
|
+
onInput={(event) => setState({ tick: event.currentTarget.valueAsNumber, playing: false })}
|
|
401
|
+
/>
|
|
402
|
+
<span class="w-64 shrink-0 truncate text-v2-text-text-muted tabular-nums">
|
|
403
|
+
{tick()}/{total()} · {replay().caption}
|
|
404
|
+
</span>
|
|
405
|
+
</div>
|
|
406
|
+
<Show
|
|
407
|
+
when={state.view === "side"}
|
|
408
|
+
fallback={
|
|
409
|
+
<div class="relative min-h-0 flex-1">
|
|
410
|
+
{frame("base", base)}
|
|
411
|
+
{frame(
|
|
412
|
+
"head",
|
|
413
|
+
self,
|
|
414
|
+
state.view === "swipe" ? { "clip-path": `inset(0 0 0 ${state.mix}%)` } : { opacity: state.mix / 100 },
|
|
415
|
+
)}
|
|
416
|
+
<Show when={state.view === "swipe"}>
|
|
417
|
+
<div
|
|
418
|
+
class="pointer-events-none absolute inset-y-0 w-px bg-v2-state-fg-danger"
|
|
419
|
+
style={{ left: `${state.mix}%` }}
|
|
420
|
+
/>
|
|
421
|
+
</Show>
|
|
422
|
+
<div class="pointer-events-none absolute top-2 left-2 rounded bg-v2-background-bg-layer-03 px-2 py-0.5 text-12-regular">
|
|
423
|
+
{state.view === "swipe" ? `${baseLabel} | ${headLabel}` : `${baseLabel} under ${headLabel}`}
|
|
424
|
+
</div>
|
|
425
|
+
</div>
|
|
426
|
+
}
|
|
427
|
+
>
|
|
428
|
+
<div class="grid min-h-0 flex-1 grid-cols-2 divide-x divide-v2-border-border-base">
|
|
429
|
+
<For
|
|
430
|
+
each={
|
|
431
|
+
[
|
|
432
|
+
["base", base],
|
|
433
|
+
["head", self],
|
|
434
|
+
] as const
|
|
435
|
+
}
|
|
436
|
+
>
|
|
437
|
+
{([side, address]) => (
|
|
438
|
+
<div class="flex min-h-0 flex-col">
|
|
439
|
+
<div class="border-b border-v2-border-border-base px-4 py-1.5 text-12-medium text-v2-text-text-muted">
|
|
440
|
+
{side === "base" ? baseLabel : headLabel}
|
|
441
|
+
</div>
|
|
442
|
+
<div class="relative min-h-0 flex-1">{frame(side, address)}</div>
|
|
443
|
+
</div>
|
|
444
|
+
)}
|
|
445
|
+
</For>
|
|
446
|
+
</div>
|
|
447
|
+
</Show>
|
|
448
|
+
</div>
|
|
449
|
+
)
|
|
450
|
+
},
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function Choice<T extends string | number>(props: {
|
|
454
|
+
label: string
|
|
455
|
+
options: readonly T[]
|
|
456
|
+
value: T
|
|
457
|
+
onChange: (value: T) => void
|
|
458
|
+
}) {
|
|
459
|
+
return (
|
|
460
|
+
<label class="flex items-center gap-2">
|
|
461
|
+
<span class="text-v2-text-text-muted">{props.label}</span>
|
|
462
|
+
<select
|
|
463
|
+
class="rounded-md border border-v2-border-border-base bg-transparent px-1.5 py-0.5"
|
|
464
|
+
value={String(props.value)}
|
|
465
|
+
onChange={(event) =>
|
|
466
|
+
props.onChange(props.options.find((option) => String(option) === event.currentTarget.value)!)
|
|
467
|
+
}
|
|
468
|
+
>
|
|
469
|
+
<For each={props.options}>{(option) => <option value={String(option)}>{option}</option>}</For>
|
|
470
|
+
</select>
|
|
471
|
+
</label>
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function Check(props: { label: string; checked: boolean; onChange: (checked: boolean) => void }) {
|
|
476
|
+
return (
|
|
477
|
+
<label class="flex items-center gap-2">
|
|
478
|
+
<input
|
|
479
|
+
type="checkbox"
|
|
480
|
+
checked={props.checked}
|
|
481
|
+
onChange={(event) => props.onChange(event.currentTarget.checked)}
|
|
482
|
+
/>
|
|
483
|
+
{props.label}
|
|
484
|
+
</label>
|
|
485
|
+
)
|
|
486
|
+
}
|