@zyro-sec/session-ui 0.0.0-stage → 1.0.4
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,89 @@
|
|
|
1
|
+
import type { SessionMessageAssistant, SessionMessageAssistantTool, SessionMessageInfo } from "@zyro-sec/client/promise"
|
|
2
|
+
import { currentToolInput } from "../message/current-tool-state"
|
|
3
|
+
import { toolName } from "../timeline/facts"
|
|
4
|
+
import type { TimelineDetail } from "../timeline/detail"
|
|
5
|
+
import { Predicate } from "effect"
|
|
6
|
+
|
|
7
|
+
export { goal, sessionEvent } from "../timeline/place"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How the New timeline shows a call or notice. Where each shows under the detail setting is `timeline/place`'s to say.
|
|
11
|
+
* Whatever the setting, the timeline always shows your messages and the commands you ran, a turn you stopped, and what
|
|
12
|
+
* changed the session (`sessionEvent`).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type Content = SessionMessageAssistant["content"][number]
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How a call shows when it stands on its own:
|
|
19
|
+
* - `line`: one line of activity, a command's included: commands run long, so its row cuts the command to a line.
|
|
20
|
+
* - `file`: a file's name and changes, opening to its whole diff.
|
|
21
|
+
* - `event`: a subagent task or a shell started in the background.
|
|
22
|
+
*/
|
|
23
|
+
export type ToolLayout = "line" | "file" | "event"
|
|
24
|
+
|
|
25
|
+
export type ToolRule = { layout: ToolLayout }
|
|
26
|
+
|
|
27
|
+
const file: ToolRule = { layout: "file" }
|
|
28
|
+
|
|
29
|
+
/** The tools that do not show as a line of activity, by their current name. */
|
|
30
|
+
const tools = new Map<string, ToolRule>(
|
|
31
|
+
Object.entries({
|
|
32
|
+
edit: file,
|
|
33
|
+
write: file,
|
|
34
|
+
patch: file,
|
|
35
|
+
subagent: { layout: "event" },
|
|
36
|
+
} satisfies Record<string, ToolRule>),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const other: ToolRule = { layout: "line" }
|
|
40
|
+
|
|
41
|
+
/** A call's rule, under the tool's current name. */
|
|
42
|
+
export function toolRule(tool: SessionMessageAssistantTool): ToolRule & { name: string } {
|
|
43
|
+
const name = toolName(tool.name)
|
|
44
|
+
const rule = tools.get(name) ?? other
|
|
45
|
+
|
|
46
|
+
// A shell the agent started in the background reports back like a subagent.
|
|
47
|
+
if (name === "shell" && currentToolInput(tool).background === true) return { ...rule, name, layout: "event" }
|
|
48
|
+
|
|
49
|
+
return { ...rule, name }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A thought shows while it streams, before its first words arrive, so the timeline never hides that the model is
|
|
53
|
+
// thinking. Once finished, a thought without text has nothing to open.
|
|
54
|
+
export function textShows(content: Exclude<Content, { type: "tool" }>) {
|
|
55
|
+
if (content.text.trim()) return true
|
|
56
|
+
|
|
57
|
+
return content.type === "reasoning" && content.time?.completed === undefined
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether a thought starts open. Expanded details stream the thought the model is writing in view and close it once
|
|
62
|
+
* it is finished, when the next step follows; collapsed ones keep it to one line throughout. Opening it shows the
|
|
63
|
+
* thought.
|
|
64
|
+
*/
|
|
65
|
+
export function thoughtOpens(detail: TimelineDetail, streaming: boolean) {
|
|
66
|
+
return streaming && detail.thinking.details === "expanded"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Whether a thought the model is writing shows, at the end of its turn, in place of the status line. */
|
|
70
|
+
export function liveThinkingShows(detail: TimelineDetail) {
|
|
71
|
+
return detail.thinking.placement !== "hidden"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The notice the agent gets about a command the user ran repeats that command's own card, so it never shows. */
|
|
75
|
+
export function echoesUserShell(message: SessionMessageInfo, userShellIDs: ReadonlySet<string>) {
|
|
76
|
+
const shellID = message.type === "synthetic" ? message.metadata?.shellID : undefined
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
message.type === "synthetic" &&
|
|
80
|
+
message.metadata?.source === "shell" &&
|
|
81
|
+
Predicate.isString(shellID) &&
|
|
82
|
+
userShellIDs.has(shellID)
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A move to where the session already is changes nothing, so it shows nothing. */
|
|
87
|
+
export function movedInPlace(message: SessionMessageInfo) {
|
|
88
|
+
return message.type === "location-switched" && message.previous?.location.directory === message.location.directory
|
|
89
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { hasProviderIcon, ProviderIcon } from "@zyro-sec/ui/provider-icon"
|
|
2
|
+
import { Tooltip } from "@zyro-sec/ui/tooltip"
|
|
3
|
+
import { Show } from "solid-js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A divider with its label, such as a model switch or Interrupted. Rows are spaced by block, so it is only as tall as its
|
|
7
|
+
* text. A provider without its own icon shows none, rather than the generic fallback.
|
|
8
|
+
*/
|
|
9
|
+
export function Separator(props: {
|
|
10
|
+
label: string
|
|
11
|
+
value?: string
|
|
12
|
+
tooltip?: string
|
|
13
|
+
providerID?: string
|
|
14
|
+
variant?: string
|
|
15
|
+
}) {
|
|
16
|
+
const label = () => (
|
|
17
|
+
<bdi
|
|
18
|
+
data-slot="session-timeline-notice-label"
|
|
19
|
+
dir="auto"
|
|
20
|
+
class="block truncate"
|
|
21
|
+
classList={{ "shrink-0": !!props.value }}
|
|
22
|
+
title={props.tooltip ? undefined : props.label}
|
|
23
|
+
>
|
|
24
|
+
{props.label}
|
|
25
|
+
</bdi>
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div class="flex h-4 w-full items-center gap-3 text-v2-text-text-faint">
|
|
30
|
+
<span class="h-px min-w-0 flex-1 bg-v2-border-border-muted" />
|
|
31
|
+
<span class="flex min-w-0 items-center gap-1 text-[13px] font-[440] leading-text-compact tracking-[-0.04px]">
|
|
32
|
+
<Show when={props.providerID && hasProviderIcon(props.providerID) ? props.providerID : undefined}>
|
|
33
|
+
{(providerID) => <ProviderIcon id={providerID()} class="text-v2-icon-icon-faint" aria-hidden="true" />}
|
|
34
|
+
</Show>
|
|
35
|
+
<span class="flex min-w-0 items-center gap-1.5">
|
|
36
|
+
<Show when={props.tooltip} fallback={label()}>
|
|
37
|
+
{(tooltip) => (
|
|
38
|
+
<Tooltip
|
|
39
|
+
appearance="compact"
|
|
40
|
+
placement="top"
|
|
41
|
+
value={tooltip()}
|
|
42
|
+
class={props.value ? "min-w-0 shrink-0" : "min-w-0"}
|
|
43
|
+
triggerTabIndex={0}
|
|
44
|
+
>
|
|
45
|
+
{label()}
|
|
46
|
+
</Tooltip>
|
|
47
|
+
)}
|
|
48
|
+
</Show>
|
|
49
|
+
<Show when={props.value}>
|
|
50
|
+
{(value) => (
|
|
51
|
+
<bdi data-slot="session-timeline-notice-value" dir="ltr" class="min-w-0 truncate" title={value()}>
|
|
52
|
+
{value()}
|
|
53
|
+
</bdi>
|
|
54
|
+
)}
|
|
55
|
+
</Show>
|
|
56
|
+
<Show when={props.variant && props.variant !== "default" ? props.variant : undefined}>
|
|
57
|
+
{(variant) => (
|
|
58
|
+
<>
|
|
59
|
+
<span class="flex size-1.5 shrink-0 items-center justify-center" aria-hidden="true">
|
|
60
|
+
<span class="size-[2.25px] rounded-full bg-current" />
|
|
61
|
+
</span>
|
|
62
|
+
<span data-slot="session-timeline-notice-variant" class="shrink-0 capitalize">
|
|
63
|
+
{variant()}
|
|
64
|
+
</span>
|
|
65
|
+
</>
|
|
66
|
+
)}
|
|
67
|
+
</Show>
|
|
68
|
+
</span>
|
|
69
|
+
</span>
|
|
70
|
+
<span class="h-px min-w-0 flex-1 bg-v2-border-border-muted" />
|
|
71
|
+
</div>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { SessionMessageAssistant, SessionMessageInfo } from "@zyro-sec/client/promise"
|
|
2
|
+
import { Predicate } from "effect"
|
|
3
|
+
import { TimelineRow } from "../timeline/timeline-row"
|
|
4
|
+
import { resolveContent } from "./projection"
|
|
5
|
+
import { goal } from "./rules"
|
|
6
|
+
|
|
7
|
+
type Content = SessionMessageAssistant["content"][number]
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Rows are spaced by who did what: each thing the user did (a message, a command, a goal) stands apart, the agent's reply
|
|
11
|
+
* reads as one stretch, and what happened to the session (Interrupted, a switch) sits together.
|
|
12
|
+
*/
|
|
13
|
+
export type TimelineBlock = "user" | "agent" | "event"
|
|
14
|
+
|
|
15
|
+
/** What a row or an item in an opened group shows: the agent's words, or its activity (a call, a file, a thought). */
|
|
16
|
+
export type TimelineItem = "prose" | "line"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The space between two rows: small between rows of activity in a reply or a run of session events, medium between the
|
|
20
|
+
* agent's words and its activity, and large around each thing the user did and wherever a new block starts.
|
|
21
|
+
*/
|
|
22
|
+
export type TimelineGap = "s" | "m" | "l"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The gap each row holds below itself, by key: the space above the next row that shows something. The last row holds
|
|
26
|
+
* none. The row directly above holds a row's gap, never the row itself: older history loads above rows the reader is
|
|
27
|
+
* looking at, and a row that took its gap on top would grow there when the row before it arrived, and move what is on
|
|
28
|
+
* screen. So the turn gap before a turn's first row holds that row's gap, and arrives and leaves with the turn; any
|
|
29
|
+
* other gap is the row before's. A turn gap is not compared with: the row after it compares with the row before it.
|
|
30
|
+
* Background work reporting back always starts a block, which the agent's reply continues. A message joining the one
|
|
31
|
+
* above in a run sits closer still, which the row renderer applies.
|
|
32
|
+
*/
|
|
33
|
+
export function timelineGaps(
|
|
34
|
+
rows: readonly TimelineRow.TimelineRow[],
|
|
35
|
+
messageByID: ReadonlyMap<string, SessionMessageInfo>,
|
|
36
|
+
) {
|
|
37
|
+
const gaps = new Map<string, TimelineGap>()
|
|
38
|
+
|
|
39
|
+
rows.reduce<{ block: TimelineBlock; item: TimelineItem } | undefined>((previous, row, index) => {
|
|
40
|
+
const block = rowBlock(row, messageByID)
|
|
41
|
+
|
|
42
|
+
if (!block) return previous
|
|
43
|
+
const item = rowItem(row, messageByID)
|
|
44
|
+
|
|
45
|
+
// Live status takes its own space above it (laneGap), so the row above it holds none.
|
|
46
|
+
if (previous && !Predicate.isTagged(row, "Activity"))
|
|
47
|
+
gaps.set(TimelineRow.key(rows[index - 1]!), gap(previous, { block, item }, reportsBack(row)))
|
|
48
|
+
|
|
49
|
+
return { block, item }
|
|
50
|
+
}, undefined)
|
|
51
|
+
|
|
52
|
+
return gaps
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The gap above the status line below a working turn. It stands in for the agent's next line of activity, so it sits
|
|
57
|
+
* where that row would. Before the turn shows anything, such as while a hidden thought streams, it stands in for the
|
|
58
|
+
* turn's first row, so it sits where that row will land.
|
|
59
|
+
*/
|
|
60
|
+
export function laneGap(
|
|
61
|
+
rows: readonly TimelineRow.TimelineRow[],
|
|
62
|
+
turnID: string,
|
|
63
|
+
messageByID: ReadonlyMap<string, SessionMessageInfo>,
|
|
64
|
+
): TimelineGap | undefined {
|
|
65
|
+
const last =
|
|
66
|
+
rows.findLast((row) => row.userMessageID === turnID && rowBlock(row, messageByID)) ??
|
|
67
|
+
rows.findLast((row) => rowBlock(row, messageByID))
|
|
68
|
+
|
|
69
|
+
const block = last && rowBlock(last, messageByID)
|
|
70
|
+
|
|
71
|
+
if (!last || !block) return undefined
|
|
72
|
+
|
|
73
|
+
return gap({ block, item: rowItem(last, messageByID) }, { block: "agent", item: "line" }, false)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function gap(
|
|
77
|
+
previous: { block: TimelineBlock; item: TimelineItem },
|
|
78
|
+
current: { block: TimelineBlock; item: TimelineItem },
|
|
79
|
+
starts: boolean,
|
|
80
|
+
): TimelineGap {
|
|
81
|
+
// Each thing the user did stands on its own, apart from the reply before it and the one after.
|
|
82
|
+
if (starts || previous.block !== current.block || current.block === "user") return "l"
|
|
83
|
+
|
|
84
|
+
// The agent's words sit a little apart from its activity, so each reads as what it is.
|
|
85
|
+
return previous.item === current.item ? "s" : "m"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** What one part shows, so an opened group spaces its items as the timeline spaces rows. */
|
|
89
|
+
export function contentItem(content: Content): TimelineItem {
|
|
90
|
+
if (content.type === "text") return "prose"
|
|
91
|
+
|
|
92
|
+
return "line"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function rowBlock(
|
|
96
|
+
row: TimelineRow.TimelineRow,
|
|
97
|
+
messageByID: ReadonlyMap<string, SessionMessageInfo>,
|
|
98
|
+
): TimelineBlock | undefined {
|
|
99
|
+
if (Predicate.isTagged(row, "TurnGap")) return undefined
|
|
100
|
+
|
|
101
|
+
if (Predicate.isTagged(row, "UserMessage") || Predicate.isTagged(row, "Shell")) return "user"
|
|
102
|
+
|
|
103
|
+
if (Predicate.isTagged(row, "TurnDivider") || Predicate.isTagged(row, "CompactionQueued")) return "event"
|
|
104
|
+
|
|
105
|
+
if (!Predicate.isTagged(row, "Notice")) return "agent"
|
|
106
|
+
|
|
107
|
+
return goal(messageByID.get(row.messageID)) ? "user" : "event"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function rowItem(row: TimelineRow.TimelineRow, messageByID: ReadonlyMap<string, SessionMessageInfo>): TimelineItem {
|
|
111
|
+
if (!Predicate.isTagged(row, "AssistantPart")) return "line"
|
|
112
|
+
const group = row.group
|
|
113
|
+
|
|
114
|
+
if (group.type !== "part") return "line"
|
|
115
|
+
const content = resolveContent(messageByID.get(group.ref.messageID), group.ref.partID)
|
|
116
|
+
|
|
117
|
+
return content ? contentItem(content) : "line"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Notices of background work finishing join an events group under the message's own ID.
|
|
121
|
+
function reportsBack(row: TimelineRow.TimelineRow) {
|
|
122
|
+
return (
|
|
123
|
+
Predicate.isTagged(row, "AssistantPart") &&
|
|
124
|
+
row.group.type === "events" &&
|
|
125
|
+
row.group.refs.some((ref) => ref.messageID === ref.partID)
|
|
126
|
+
)
|
|
127
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
|
|
2
|
+
import { Show, type JSX } from "solid-js"
|
|
3
|
+
import type { TimelineGap } from "./spacing"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The lane below a working turn: the status line, and any action beside it. It keeps its height while empty, so the
|
|
7
|
+
* status coming and going does not move the rows around it, and collapses where the thought the model is writing takes
|
|
8
|
+
* its place.
|
|
9
|
+
*/
|
|
10
|
+
export function StatusLane(props: {
|
|
11
|
+
label?: string
|
|
12
|
+
collapsed?: boolean
|
|
13
|
+
/** The space above the next row of the turn, so the line sits where that row will. */
|
|
14
|
+
spacing?: TimelineGap
|
|
15
|
+
/** The lane sits in a row of the timeline, which clips what reaches past it, rather than in its open tail. */
|
|
16
|
+
inRow?: boolean
|
|
17
|
+
class?: string
|
|
18
|
+
children?: JSX.Element
|
|
19
|
+
}) {
|
|
20
|
+
return (
|
|
21
|
+
<div
|
|
22
|
+
data-timeline="next"
|
|
23
|
+
data-component="timeline-status-lane"
|
|
24
|
+
data-collapsed={props.collapsed ? "" : undefined}
|
|
25
|
+
data-spacing={props.spacing}
|
|
26
|
+
data-in-row={props.inRow ? "" : undefined}
|
|
27
|
+
class={props.class}
|
|
28
|
+
>
|
|
29
|
+
<Show when={props.label}>
|
|
30
|
+
{(label) => (
|
|
31
|
+
<div data-component="session-working" role="status" aria-label={label()}>
|
|
32
|
+
<span data-slot="timeline-status-label">
|
|
33
|
+
<TextShimmer text={label()} active />
|
|
34
|
+
</span>
|
|
35
|
+
</div>
|
|
36
|
+
)}
|
|
37
|
+
</Show>
|
|
38
|
+
{props.children}
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SessionMessageAssistant } from "@zyro-sec/client/promise"
|
|
2
|
+
import type { TimelineDetail } from "../timeline/detail"
|
|
3
|
+
import { liveThinkingShows, toolRule } from "./rules"
|
|
4
|
+
|
|
5
|
+
type Content = SessionMessageAssistant["content"][number]
|
|
6
|
+
|
|
7
|
+
export type TimelineStatus = "waitingApproval" | "waitingAnswer" | "waitingShell" | "working"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The status line says Working unless the turn is waiting on the user or a shell command.
|
|
11
|
+
*/
|
|
12
|
+
export function timelineStatus(input: {
|
|
13
|
+
/** A permission or a question waits on the user. */
|
|
14
|
+
blocked?: "approval" | "answer"
|
|
15
|
+
/** The active step's content, oldest first. */
|
|
16
|
+
content: readonly Content[]
|
|
17
|
+
}): TimelineStatus {
|
|
18
|
+
if (input.blocked === "approval") return "waitingApproval"
|
|
19
|
+
|
|
20
|
+
if (input.blocked === "answer") return "waitingAnswer"
|
|
21
|
+
const last = input.content.at(-1)
|
|
22
|
+
|
|
23
|
+
if (last?.type !== "tool" || (last.state.status !== "running" && last.state.status !== "streaming")) return "working"
|
|
24
|
+
|
|
25
|
+
return toolRule(last).name === "shell" ? "waitingShell" : "working"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Whether the model is writing a thought that shows, which then stands in for the status line's Working. */
|
|
29
|
+
export function timelineThinking(detail: TimelineDetail, content: readonly Content[]) {
|
|
30
|
+
const last = content.at(-1)
|
|
31
|
+
|
|
32
|
+
return liveThinkingShows(detail) && last?.type === "reasoning" && last.time?.completed === undefined
|
|
33
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
|
|
2
|
+
import { Show, createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js"
|
|
3
|
+
import { BackgroundMoveHint } from "../../../../app/src/session/timeline/message-timeline"
|
|
4
|
+
import { createStore, reconcile } from "solid-js/store"
|
|
5
|
+
import type { SessionDocument } from "../../document"
|
|
6
|
+
import { CurrentSessionProviders } from "../../storybook/current-session-story"
|
|
7
|
+
import { timelinePresets, type TimelineDetail } from "../../timeline/detail"
|
|
8
|
+
import { terminalRunningDocument } from "../../storybook/current-session-fixtures"
|
|
9
|
+
import { SessionTimeline } from "../../timeline/session-timeline"
|
|
10
|
+
import { StatusLane } from "../status-line"
|
|
11
|
+
import { NextSessionTimeline } from "./session-timeline"
|
|
12
|
+
|
|
13
|
+
// One side of the compare page: the session as this build draws it, the New timeline when `activity` is set. Other
|
|
14
|
+
// builds, such as timeline-policy, answer the same messages, so the page can compare them.
|
|
15
|
+
export default {
|
|
16
|
+
title: "OpenCode/Timeline/Compare renderer",
|
|
17
|
+
id: "timeline-compare-renderer",
|
|
18
|
+
component: SessionTimeline,
|
|
19
|
+
parameters: { layout: "fullscreen" },
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Render = {
|
|
23
|
+
type: "timeline-compare:render"
|
|
24
|
+
document: SessionDocument
|
|
25
|
+
detail: TimelineDetail
|
|
26
|
+
activity: boolean
|
|
27
|
+
turnDiffs: boolean
|
|
28
|
+
width: number
|
|
29
|
+
/** What the line below a working turn says, as the build comparing it shows it. */
|
|
30
|
+
status?: string
|
|
31
|
+
/** The New timeline's lane, which folds away while a thought takes its place, or the lane the app has today. */
|
|
32
|
+
lane: "activity" | "legacy"
|
|
33
|
+
collapsed?: boolean
|
|
34
|
+
spacing?: "s" | "l"
|
|
35
|
+
/** A shell or subagent call blocks the turn, so the lane offers to move it to the background. */
|
|
36
|
+
hint?: boolean
|
|
37
|
+
/** How long the call runs before that offer shows, as the build comparing it waits. */
|
|
38
|
+
hintDelay?: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const padding = "px-4 md:px-6"
|
|
42
|
+
|
|
43
|
+
type ScrollTo = { type: "timeline-compare:scroll-to"; anchor: string; offset: number }
|
|
44
|
+
|
|
45
|
+
export const Renderer = {
|
|
46
|
+
args: { preview: "waiting" },
|
|
47
|
+
argTypes: { preview: { options: ["waiting", "current", "new"] } },
|
|
48
|
+
render: (args: { preview: string }) => {
|
|
49
|
+
const [state, setState] = createStore<{ render?: Render }>({})
|
|
50
|
+
|
|
51
|
+
// An embedded comparison supplies the actual snapshot. In isolation the inspector can send a working turn.
|
|
52
|
+
const snapshot = createMemo<Render | undefined>(
|
|
53
|
+
() =>
|
|
54
|
+
state.render ??
|
|
55
|
+
(args.preview === "waiting"
|
|
56
|
+
? undefined
|
|
57
|
+
: {
|
|
58
|
+
type: "timeline-compare:render",
|
|
59
|
+
document: terminalRunningDocument,
|
|
60
|
+
detail: timelinePresets[2].value,
|
|
61
|
+
activity: args.preview === "new",
|
|
62
|
+
lane: args.preview === "new" ? "activity" : "legacy",
|
|
63
|
+
turnDiffs: false,
|
|
64
|
+
width: 720,
|
|
65
|
+
status: "Working",
|
|
66
|
+
}),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
const [hint, setHint] = createSignal(false)
|
|
70
|
+
|
|
71
|
+
// The offer shows once the call has blocked the turn for the build's delay, counted from when the playhead got here.
|
|
72
|
+
createEffect(() => {
|
|
73
|
+
const render = state.render
|
|
74
|
+
|
|
75
|
+
if (!render?.hint) return setHint(false)
|
|
76
|
+
const timer = setTimeout(() => setHint(true), render.hintDelay ?? 0)
|
|
77
|
+
onCleanup(() => clearTimeout(timer))
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const move = () => (
|
|
81
|
+
<Show when={hint()}>
|
|
82
|
+
<div data-component="session-background-hint-row">
|
|
83
|
+
<BackgroundMoveHint keybind={["Ctrl", "B"]} />
|
|
84
|
+
</div>
|
|
85
|
+
</Show>
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
let scroller: HTMLDivElement | undefined
|
|
89
|
+
// A scroll this frame made to follow the other side is not reported back, so the two never chase each other.
|
|
90
|
+
let following = 0
|
|
91
|
+
|
|
92
|
+
const receive = (event: MessageEvent<Render | ScrollTo>) => {
|
|
93
|
+
if (event.data?.type === "timeline-compare:render") return setState("render", reconcile(event.data))
|
|
94
|
+
|
|
95
|
+
if (event.data?.type !== "timeline-compare:scroll-to" || !scroller) return
|
|
96
|
+
const target = scroller.querySelector<HTMLElement>(`[data-message-id="${CSS.escape(event.data.anchor)}"]`)
|
|
97
|
+
|
|
98
|
+
if (!target) return
|
|
99
|
+
following = performance.now()
|
|
100
|
+
scroller.scrollTop +=
|
|
101
|
+
target.getBoundingClientRect().top - scroller.getBoundingClientRect().top - event.data.offset
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The topmost turn on screen and how far it sits from the top, which the other side lines up with.
|
|
105
|
+
const report = () => {
|
|
106
|
+
if (!scroller || performance.now() - following < 120) return
|
|
107
|
+
const top = scroller.getBoundingClientRect().top
|
|
108
|
+
|
|
109
|
+
const anchor = [...scroller.querySelectorAll<HTMLElement>("[data-message-id]")].find(
|
|
110
|
+
(element) => element.getBoundingClientRect().bottom > top,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
if (!anchor?.dataset.messageId) return
|
|
114
|
+
window.parent.postMessage(
|
|
115
|
+
{
|
|
116
|
+
type: "timeline-compare:scroll",
|
|
117
|
+
anchor: anchor.dataset.messageId,
|
|
118
|
+
offset: anchor.getBoundingClientRect().top - top,
|
|
119
|
+
},
|
|
120
|
+
"*",
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
onMount(() => {
|
|
125
|
+
window.addEventListener("message", receive)
|
|
126
|
+
window.parent.postMessage({ type: "timeline-compare:ready" }, "*")
|
|
127
|
+
})
|
|
128
|
+
onCleanup(() => window.removeEventListener("message", receive))
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
ref={scroller}
|
|
133
|
+
class="h-screen overflow-y-auto bg-v2-background-bg-base text-v2-text-text-base"
|
|
134
|
+
data-scrollable
|
|
135
|
+
onScroll={report}
|
|
136
|
+
>
|
|
137
|
+
<Show when={snapshot()}>
|
|
138
|
+
{(render) => (
|
|
139
|
+
<div class="mx-auto py-6" style={{ "max-width": `${render().width}px` }}>
|
|
140
|
+
<CurrentSessionProviders document={render().document}>
|
|
141
|
+
<Show
|
|
142
|
+
when={render().activity}
|
|
143
|
+
fallback={
|
|
144
|
+
<SessionTimeline
|
|
145
|
+
document={render().document}
|
|
146
|
+
timelineDetail={render().detail}
|
|
147
|
+
turnDiffs={render().turnDiffs}
|
|
148
|
+
/>
|
|
149
|
+
}
|
|
150
|
+
>
|
|
151
|
+
<NextSessionTimeline
|
|
152
|
+
document={render().document}
|
|
153
|
+
timelineDetail={render().detail}
|
|
154
|
+
turnDiffs={render().turnDiffs}
|
|
155
|
+
/>
|
|
156
|
+
</Show>
|
|
157
|
+
</CurrentSessionProviders>
|
|
158
|
+
<Show
|
|
159
|
+
when={render().lane === "activity"}
|
|
160
|
+
fallback={
|
|
161
|
+
<div
|
|
162
|
+
class={`flex h-9 items-center gap-2 pt-3 text-[13px] font-[530] leading-text-compact ${padding}`}
|
|
163
|
+
>
|
|
164
|
+
<Show when={render().status}>
|
|
165
|
+
{(status) => (
|
|
166
|
+
<div data-component="session-working" role="status">
|
|
167
|
+
<TextShimmer text={status()} active />
|
|
168
|
+
</div>
|
|
169
|
+
)}
|
|
170
|
+
</Show>
|
|
171
|
+
{move()}
|
|
172
|
+
</div>
|
|
173
|
+
}
|
|
174
|
+
>
|
|
175
|
+
<StatusLane
|
|
176
|
+
class={padding}
|
|
177
|
+
label={render().status}
|
|
178
|
+
collapsed={render().collapsed && !hint()}
|
|
179
|
+
spacing={render().spacing}
|
|
180
|
+
>
|
|
181
|
+
{move()}
|
|
182
|
+
</StatusLane>
|
|
183
|
+
</Show>
|
|
184
|
+
</div>
|
|
185
|
+
)}
|
|
186
|
+
</Show>
|
|
187
|
+
</div>
|
|
188
|
+
)
|
|
189
|
+
},
|
|
190
|
+
}
|