@cerebriline/ui 0.0.0-stage → 4.100.313

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 (222) hide show
  1. package/ADOPTION.md +833 -0
  2. package/LICENSE +201 -0
  3. package/RADIX-COLORS-LICENSE +21 -0
  4. package/README.md +427 -2
  5. package/components/agent-approval-card.css +70 -0
  6. package/components/agent-approval-card.tsx +109 -0
  7. package/components/agent-ask-question.css +103 -0
  8. package/components/agent-ask-question.tsx +276 -0
  9. package/components/agent-aurora.css +228 -0
  10. package/components/agent-aurora.tsx +96 -0
  11. package/components/agent-changes.css +13 -0
  12. package/components/agent-changes.tsx +167 -0
  13. package/components/agent-chat/agent-chat.css +556 -0
  14. package/components/agent-chat/index.tsx +1037 -0
  15. package/components/agent-chat/tool-diff.tsx +165 -0
  16. package/components/agent-chat/tool-summary/agents.ts +114 -0
  17. package/components/agent-chat/tool-summary/diff.ts +152 -0
  18. package/components/agent-chat/tool-summary/index.ts +928 -0
  19. package/components/agent-chat/tool-summary/parsers.ts +611 -0
  20. package/components/agent-chat/tool-summary/paths.ts +84 -0
  21. package/components/agent-chat/tool-summary/team.ts +401 -0
  22. package/components/agent-command-output.tsx +63 -0
  23. package/components/agent-composer.tsx +263 -0
  24. package/components/agent-context-usage.tsx +181 -0
  25. package/components/agent-conversation-layout.tsx +139 -0
  26. package/components/agent-hero-heading.css +53 -0
  27. package/components/agent-hero-heading.tsx +45 -0
  28. package/components/agent-image-lightbox.tsx +48 -0
  29. package/components/agent-prompt-queue.css +20 -0
  30. package/components/agent-prompt-queue.tsx +350 -0
  31. package/components/agent-pull-request-bar.css +13 -0
  32. package/components/agent-pull-request-bar.tsx +346 -0
  33. package/components/agent-quick-actions.css +19 -0
  34. package/components/agent-quick-actions.tsx +70 -0
  35. package/components/agent-session-row.tsx +183 -0
  36. package/components/agent-welcome-hero-pointer.ts +199 -0
  37. package/components/agent-welcome-hero.css +205 -0
  38. package/components/agent-welcome-hero.tsx +68 -0
  39. package/components/attachment-drop-zone.tsx +154 -0
  40. package/components/badge.tsx +21 -0
  41. package/components/button.tsx +324 -0
  42. package/components/generated-media.tsx +173 -0
  43. package/components/github-icon.tsx +19 -0
  44. package/components/index.ts +133 -0
  45. package/components/markdown.css +490 -0
  46. package/components/markdown.ts +365 -0
  47. package/components/mermaid-block.tsx +722 -0
  48. package/components/mermaid-diagram.ts +1260 -0
  49. package/components/mermaid-dom.ts +301 -0
  50. package/components/message-scroller.css +118 -0
  51. package/components/message-scroller.tsx +114 -0
  52. package/components/search-combobox.css +67 -0
  53. package/components/search-combobox.tsx +433 -0
  54. package/components/session-status.css +19 -0
  55. package/components/session-status.tsx +39 -0
  56. package/components/switch.css +221 -0
  57. package/components/switch.tsx +48 -0
  58. package/components.css +16 -0
  59. package/dist/components/agent-approval-card.d.ts +14 -0
  60. package/dist/components/agent-approval-card.d.ts.map +1 -0
  61. package/dist/components/agent-approval-card.js +12 -0
  62. package/dist/components/agent-approval-card.js.map +1 -0
  63. package/dist/components/agent-ask-question.d.ts +18 -0
  64. package/dist/components/agent-ask-question.d.ts.map +1 -0
  65. package/dist/components/agent-ask-question.js +101 -0
  66. package/dist/components/agent-ask-question.js.map +1 -0
  67. package/dist/components/agent-aurora.d.ts +3 -0
  68. package/dist/components/agent-aurora.d.ts.map +1 -0
  69. package/dist/components/agent-aurora.js +60 -0
  70. package/dist/components/agent-aurora.js.map +1 -0
  71. package/dist/components/agent-changes.d.ts +26 -0
  72. package/dist/components/agent-changes.d.ts.map +1 -0
  73. package/dist/components/agent-changes.js +19 -0
  74. package/dist/components/agent-changes.js.map +1 -0
  75. package/dist/components/agent-chat/disclosure.d.ts +25 -0
  76. package/dist/components/agent-chat/disclosure.d.ts.map +1 -0
  77. package/dist/components/agent-chat/disclosure.js +39 -0
  78. package/dist/components/agent-chat/disclosure.js.map +1 -0
  79. package/dist/components/agent-chat/index.d.ts +140 -0
  80. package/dist/components/agent-chat/index.d.ts.map +1 -0
  81. package/dist/components/agent-chat/index.js +379 -0
  82. package/dist/components/agent-chat/index.js.map +1 -0
  83. package/dist/components/agent-chat/tool-diff.d.ts +32 -0
  84. package/dist/components/agent-chat/tool-diff.d.ts.map +1 -0
  85. package/dist/components/agent-chat/tool-diff.js +97 -0
  86. package/dist/components/agent-chat/tool-diff.js.map +1 -0
  87. package/dist/components/agent-chat/tool-summary/agents.d.ts +10 -0
  88. package/dist/components/agent-chat/tool-summary/agents.d.ts.map +1 -0
  89. package/dist/components/agent-chat/tool-summary/agents.js +100 -0
  90. package/dist/components/agent-chat/tool-summary/agents.js.map +1 -0
  91. package/dist/components/agent-chat/tool-summary/diff.d.ts +22 -0
  92. package/dist/components/agent-chat/tool-summary/diff.d.ts.map +1 -0
  93. package/dist/components/agent-chat/tool-summary/diff.js +127 -0
  94. package/dist/components/agent-chat/tool-summary/diff.js.map +1 -0
  95. package/dist/components/agent-chat/tool-summary/index.d.ts +145 -0
  96. package/dist/components/agent-chat/tool-summary/index.d.ts.map +1 -0
  97. package/dist/components/agent-chat/tool-summary/index.js +663 -0
  98. package/dist/components/agent-chat/tool-summary/index.js.map +1 -0
  99. package/dist/components/agent-chat/tool-summary/parsers.d.ts +114 -0
  100. package/dist/components/agent-chat/tool-summary/parsers.d.ts.map +1 -0
  101. package/dist/components/agent-chat/tool-summary/parsers.js +502 -0
  102. package/dist/components/agent-chat/tool-summary/parsers.js.map +1 -0
  103. package/dist/components/agent-chat/tool-summary/paths.d.ts +10 -0
  104. package/dist/components/agent-chat/tool-summary/paths.d.ts.map +1 -0
  105. package/dist/components/agent-chat/tool-summary/paths.js +88 -0
  106. package/dist/components/agent-chat/tool-summary/paths.js.map +1 -0
  107. package/dist/components/agent-chat/tool-summary/team.d.ts +16 -0
  108. package/dist/components/agent-chat/tool-summary/team.d.ts.map +1 -0
  109. package/dist/components/agent-chat/tool-summary/team.js +283 -0
  110. package/dist/components/agent-chat/tool-summary/team.js.map +1 -0
  111. package/dist/components/agent-command-output.d.ts +14 -0
  112. package/dist/components/agent-command-output.d.ts.map +1 -0
  113. package/dist/components/agent-command-output.js +22 -0
  114. package/dist/components/agent-command-output.js.map +1 -0
  115. package/dist/components/agent-composer.d.ts +34 -0
  116. package/dist/components/agent-composer.d.ts.map +1 -0
  117. package/dist/components/agent-composer.js +65 -0
  118. package/dist/components/agent-composer.js.map +1 -0
  119. package/dist/components/agent-context-usage.d.ts +28 -0
  120. package/dist/components/agent-context-usage.d.ts.map +1 -0
  121. package/dist/components/agent-context-usage.js +51 -0
  122. package/dist/components/agent-context-usage.js.map +1 -0
  123. package/dist/components/agent-conversation-layout.d.ts +30 -0
  124. package/dist/components/agent-conversation-layout.d.ts.map +1 -0
  125. package/dist/components/agent-conversation-layout.js +24 -0
  126. package/dist/components/agent-conversation-layout.js.map +1 -0
  127. package/dist/components/agent-hero-heading.d.ts +2 -0
  128. package/dist/components/agent-hero-heading.d.ts.map +1 -0
  129. package/dist/components/agent-hero-heading.js +20 -0
  130. package/dist/components/agent-hero-heading.js.map +1 -0
  131. package/dist/components/agent-image-lightbox.d.ts +11 -0
  132. package/dist/components/agent-image-lightbox.d.ts.map +1 -0
  133. package/dist/components/agent-image-lightbox.js +8 -0
  134. package/dist/components/agent-image-lightbox.js.map +1 -0
  135. package/dist/components/agent-prompt-queue.d.ts +14 -0
  136. package/dist/components/agent-prompt-queue.d.ts.map +1 -0
  137. package/dist/components/agent-prompt-queue.js +114 -0
  138. package/dist/components/agent-prompt-queue.js.map +1 -0
  139. package/dist/components/agent-pull-request-bar.d.ts +72 -0
  140. package/dist/components/agent-pull-request-bar.d.ts.map +1 -0
  141. package/dist/components/agent-pull-request-bar.js +90 -0
  142. package/dist/components/agent-pull-request-bar.js.map +1 -0
  143. package/dist/components/agent-quick-actions.d.ts +14 -0
  144. package/dist/components/agent-quick-actions.d.ts.map +1 -0
  145. package/dist/components/agent-quick-actions.js +12 -0
  146. package/dist/components/agent-quick-actions.js.map +1 -0
  147. package/dist/components/agent-session-row.d.ts +45 -0
  148. package/dist/components/agent-session-row.d.ts.map +1 -0
  149. package/dist/components/agent-session-row.js +34 -0
  150. package/dist/components/agent-session-row.js.map +1 -0
  151. package/dist/components/agent-welcome-hero-pointer.d.ts +3 -0
  152. package/dist/components/agent-welcome-hero-pointer.d.ts.map +1 -0
  153. package/dist/components/agent-welcome-hero-pointer.js +169 -0
  154. package/dist/components/agent-welcome-hero-pointer.js.map +1 -0
  155. package/dist/components/agent-welcome-hero.d.ts +9 -0
  156. package/dist/components/agent-welcome-hero.d.ts.map +1 -0
  157. package/dist/components/agent-welcome-hero.js +14 -0
  158. package/dist/components/agent-welcome-hero.js.map +1 -0
  159. package/dist/components/attachment-drop-zone.d.ts +15 -0
  160. package/dist/components/attachment-drop-zone.d.ts.map +1 -0
  161. package/dist/components/attachment-drop-zone.js +64 -0
  162. package/dist/components/attachment-drop-zone.js.map +1 -0
  163. package/dist/components/badge.d.ts +5 -0
  164. package/dist/components/badge.d.ts.map +1 -0
  165. package/dist/components/badge.js +7 -0
  166. package/dist/components/badge.js.map +1 -0
  167. package/dist/components/button.d.ts +27 -0
  168. package/dist/components/button.d.ts.map +1 -0
  169. package/dist/components/button.js +209 -0
  170. package/dist/components/button.js.map +1 -0
  171. package/dist/components/generated-media.d.ts +12 -0
  172. package/dist/components/generated-media.d.ts.map +1 -0
  173. package/dist/components/generated-media.js +105 -0
  174. package/dist/components/generated-media.js.map +1 -0
  175. package/dist/components/github-icon.d.ts +3 -0
  176. package/dist/components/github-icon.d.ts.map +1 -0
  177. package/dist/components/github-icon.js +6 -0
  178. package/dist/components/github-icon.js.map +1 -0
  179. package/dist/components/index.d.ts +24 -0
  180. package/dist/components/index.d.ts.map +1 -0
  181. package/dist/components/index.js +25 -0
  182. package/dist/components/index.js.map +1 -0
  183. package/dist/components/markdown.d.ts +48 -0
  184. package/dist/components/markdown.d.ts.map +1 -0
  185. package/dist/components/markdown.js +264 -0
  186. package/dist/components/markdown.js.map +1 -0
  187. package/dist/components/mermaid-block.d.ts +14 -0
  188. package/dist/components/mermaid-block.d.ts.map +1 -0
  189. package/dist/components/mermaid-block.js +339 -0
  190. package/dist/components/mermaid-block.js.map +1 -0
  191. package/dist/components/mermaid-diagram.d.ts +264 -0
  192. package/dist/components/mermaid-diagram.d.ts.map +1 -0
  193. package/dist/components/mermaid-diagram.js +999 -0
  194. package/dist/components/mermaid-diagram.js.map +1 -0
  195. package/dist/components/mermaid-dom.d.ts +51 -0
  196. package/dist/components/mermaid-dom.d.ts.map +1 -0
  197. package/dist/components/mermaid-dom.js +246 -0
  198. package/dist/components/mermaid-dom.js.map +1 -0
  199. package/dist/components/message-scroller.d.ts +23 -0
  200. package/dist/components/message-scroller.d.ts.map +1 -0
  201. package/dist/components/message-scroller.js +31 -0
  202. package/dist/components/message-scroller.js.map +1 -0
  203. package/dist/components/search-combobox.d.ts +44 -0
  204. package/dist/components/search-combobox.d.ts.map +1 -0
  205. package/dist/components/search-combobox.js +191 -0
  206. package/dist/components/search-combobox.js.map +1 -0
  207. package/dist/components/session-status.d.ts +9 -0
  208. package/dist/components/session-status.d.ts.map +1 -0
  209. package/dist/components/session-status.js +11 -0
  210. package/dist/components/session-status.js.map +1 -0
  211. package/dist/components/switch.d.ts +7 -0
  212. package/dist/components/switch.d.ts.map +1 -0
  213. package/dist/components/switch.js +14 -0
  214. package/dist/components/switch.js.map +1 -0
  215. package/package.json +177 -5
  216. package/theme/base.css +83 -0
  217. package/theme/component-theme.css +126 -0
  218. package/theme/index.css +3 -0
  219. package/theme/palette.css +347 -0
  220. package/theme/scoped-tokens.css +503 -0
  221. package/theme/theme.css +90 -0
  222. package/theme/tokens.css +165 -0
@@ -0,0 +1,165 @@
1
+ "use client";
2
+
3
+ /**
4
+ * Rich diff rendering for tool-call rows, backed by @pierre/diffs
5
+ * (https://github.com/pierrecomputer/pierre). Pairs with the tool-summary
6
+ * module: feed a file item's `path`/`oldText`/`newText`/`fragment` straight
7
+ * in and every product renders the same syntax-highlighted, theme-aware diff.
8
+ *
9
+ * @pierre/diffs is an optional peer dependency — only consumers importing
10
+ * this subpath need to install it.
11
+ */
12
+
13
+ import { parseDiffFromFile } from "@pierre/diffs";
14
+ import { FileDiff } from "@pierre/diffs/react";
15
+ import {
16
+ type ComponentProps,
17
+ type CSSProperties,
18
+ useEffect,
19
+ useMemo,
20
+ useRef,
21
+ useState,
22
+ } from "react";
23
+
24
+ // Derived from the component rather than FileDiffProps: the props interface
25
+ // gained a second required type parameter in @pierre/diffs 1.4 while the
26
+ // component kept defaults for both, so naming the interface directly pins us
27
+ // to one minor of an optional peer dependency declared as ^1.3.0.
28
+ type DiffOptions = NonNullable<ComponentProps<typeof FileDiff>["options"]>;
29
+
30
+ export type ToolFileDiffProps = {
31
+ /** File path; used for the header-less language inference. */
32
+ path: string;
33
+ /** Contents after the change. */
34
+ newText: string;
35
+ /** Contents before the change; omit for created files. */
36
+ oldText?: string;
37
+ /**
38
+ * Set when oldText/newText are fragments of the file (editor str_replace
39
+ * payloads, apply_patch update sections) rather than complete contents.
40
+ * Fragments hide line numbers, which would otherwise misleadingly start
41
+ * at 1.
42
+ */
43
+ fragment?: boolean;
44
+ className?: string;
45
+ /**
46
+ * CSS color (or var()) the diff surface uses as its base background; all
47
+ * of @pierre/diffs' derived tints (context lines, gutters, separators)
48
+ * are color-mixed from it. Defaults to the host app's `--background`
49
+ * token so diffs sit on the app surface instead of pierre's pure
50
+ * white/black theme background.
51
+ */
52
+ background?: string;
53
+ /** Merged over the defaults for per-product tuning. */
54
+ options?: DiffOptions;
55
+ };
56
+
57
+ const BASE_OPTIONS: DiffOptions = {
58
+ diffStyle: "unified",
59
+ disableFileHeader: true,
60
+ themeType: "system",
61
+ };
62
+
63
+ // Tool payloads carry code fragments that rarely end in a newline, which
64
+ // would otherwise litter every diff with "No newline at end of file"
65
+ // markers — meaningless noise for chat rows. Empty text stays empty so an
66
+ // empty side diffs as zero lines rather than one blank line.
67
+ function ensureTrailingNewline(text: string): string {
68
+ if (!text) return "";
69
+ return text.endsWith("\n") ? text : `${text}\n`;
70
+ }
71
+
72
+ // A freshly mounted FileDiff can end up permanently blank: React StrictMode
73
+ // double-invokes the wrapper's ref, the first (immediately cleaned up)
74
+ // instance leaves a half-rendered shadow tree behind — its async highlight
75
+ // work aborts on cleanup — and the second instance adopts that skeleton as if
76
+ // it were complete prerendered output, never rendering the code or attaching
77
+ // its theme stylesheet. A rendered diff always carries `style[data-theme-css]`
78
+ // in the shadow root; when it is missing after the async window, remounting
79
+ // FileDiff (fresh host element, fresh render path) recovers reliably.
80
+ const RENDER_CHECK_DELAY_MS = 400;
81
+ const MAX_RENDER_ATTEMPTS = 3;
82
+
83
+ export function ToolFileDiff({
84
+ background = "var(--background, light-dark(#fff, #000))",
85
+ className,
86
+ fragment = false,
87
+ newText,
88
+ oldText,
89
+ options,
90
+ path,
91
+ }: ToolFileDiffProps) {
92
+ const hostRef = useRef<HTMLSpanElement | null>(null);
93
+ const [renderAttempt, setRenderAttempt] = useState(0);
94
+ const fileDiff = useMemo(() => {
95
+ try {
96
+ return parseDiffFromFile(
97
+ oldText !== undefined
98
+ ? { contents: ensureTrailingNewline(oldText), name: path }
99
+ : null,
100
+ { contents: ensureTrailingNewline(newText), name: path },
101
+ );
102
+ } catch {
103
+ // Unparsable or identical contents — the row's +/- badge and
104
+ // detail lines still describe the change.
105
+ return null;
106
+ }
107
+ }, [oldText, newText, path]);
108
+ const resolvedOptions = useMemo(
109
+ () => ({
110
+ ...BASE_OPTIONS,
111
+ ...(fragment ? { disableLineNumbers: true } : {}),
112
+ ...options,
113
+ }),
114
+ [fragment, options],
115
+ );
116
+
117
+ useEffect(() => {
118
+ if (!fileDiff || renderAttempt >= MAX_RENDER_ATTEMPTS) return;
119
+ const timer = window.setTimeout(() => {
120
+ const container = hostRef.current?.firstElementChild;
121
+ if (!container) return;
122
+ const themed = container.shadowRoot?.querySelector(
123
+ "style[data-theme-css]",
124
+ );
125
+ if (!themed) setRenderAttempt((attempt) => attempt + 1);
126
+ }, RENDER_CHECK_DELAY_MS);
127
+ return () => window.clearTimeout(timer);
128
+ }, [fileDiff, renderAttempt]);
129
+
130
+ if (!fileDiff) return null;
131
+ return (
132
+ <span ref={hostRef} style={{ display: "contents" }}>
133
+ <FileDiff
134
+ className={className}
135
+ fileDiff={fileDiff}
136
+ key={renderAttempt}
137
+ options={resolvedOptions}
138
+ style={
139
+ {
140
+ // @pierre/diffs defaults to a fixed 13px / 20px, which ignores
141
+ // the app's root font size. The rem-based text tokens scale
142
+ // with it (e.g. the desktop font-size setting).
143
+ "--diffs-font-size": "var(--text-xs, 0.8rem)",
144
+ "--diffs-line-height": "calc(var(--text-xs, 0.8rem) * 1.5)",
145
+ "--diffs-light-bg": background,
146
+ "--diffs-dark-bg": background,
147
+ // @pierre/diffs declares `color-scheme: light dark` on its
148
+ // shadow :host, so its light-dark() token colors follow the
149
+ // browser's preferred scheme — not the host app's
150
+ // class-based theme — leaving e.g. near-black light-palette
151
+ // text on a dark app surface. Inheriting the app's
152
+ // color-scheme (flipped by `.dark` in the @cline/ui theme)
153
+ // keeps the syntax palette in lockstep with the app theme.
154
+ // Skipped when a caller pins an explicit themeType, which
155
+ // pierre implements as its own :host color-scheme rule.
156
+ ...(resolvedOptions.themeType === "system" ||
157
+ resolvedOptions.themeType === undefined
158
+ ? { colorScheme: "inherit" }
159
+ : {}),
160
+ } as CSSProperties
161
+ }
162
+ />
163
+ </span>
164
+ );
165
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Rows for the lead's tools over its delegated agents: the status tool and
3
+ * the controls. Each says which agent or round it was about, which a bare
4
+ * humanized tool name did not.
5
+ */
6
+
7
+ function isRecord(value: unknown): value is Record<string, unknown> {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9
+ }
10
+
11
+ function ids(record: Record<string, unknown>, one: string, many: string) {
12
+ const list = [
13
+ ...(typeof record[one] === "string" ? [record[one] as string] : []),
14
+ ...(Array.isArray(record[many])
15
+ ? (record[many] as unknown[]).filter(
16
+ (entry): entry is string => typeof entry === "string",
17
+ )
18
+ : []),
19
+ ]
20
+ .map((entry) => entry.trim())
21
+ .filter(Boolean);
22
+ return list;
23
+ }
24
+
25
+ function listed(list: string[], max = 4): string {
26
+ return list.length > max
27
+ ? `${list.slice(0, max).join(", ")} and ${list.length - max} more`
28
+ : list.join(", ");
29
+ }
30
+
31
+ /** The tools this covers. */
32
+ export const AGENT_CONTROL_TOOL_NAMES: ReadonlySet<string> = new Set([
33
+ "agents_status",
34
+ "requeue_agent",
35
+ "restart_agent",
36
+ "resume_agent",
37
+ "retry_failed",
38
+ "message_agents",
39
+ "stop_agents",
40
+ "await_agents",
41
+ "compact_agents",
42
+ ]);
43
+
44
+ /** The row label for one of {@link AGENT_CONTROL_TOOL_NAMES}, or undefined. */
45
+ export function agentControlLabel(
46
+ toolName: string,
47
+ input: unknown,
48
+ inProgress: boolean,
49
+ ): string | undefined {
50
+ if (!AGENT_CONTROL_TOOL_NAMES.has(toolName)) {
51
+ return undefined;
52
+ }
53
+ const record = isRecord(input) ? input : {};
54
+ const verb = (now: string, done: string) => (inProgress ? now : done);
55
+ switch (toolName) {
56
+ case "agents_status": {
57
+ const agents = ids(record, "agent_id", "agent_ids");
58
+ if (agents.length > 0) {
59
+ return `${verb("Checking", "Checked")} agent${agents.length === 1 ? "" : "s"} ${listed(agents)}`;
60
+ }
61
+ if (typeof record.round_id === "string" && record.round_id.trim()) {
62
+ return `${verb("Checking", "Checked")} round ${record.round_id.trim()}`;
63
+ }
64
+ return `${verb("Checking", "Checked")} the agents`;
65
+ }
66
+ case "requeue_agent":
67
+ case "restart_agent":
68
+ case "resume_agent": {
69
+ const agent = ids(record, "agent_id", "agent_ids")[0] ?? "an agent";
70
+ const reason =
71
+ typeof record.reason === "string" && record.reason.trim()
72
+ ? ` (${record.reason.trim()})`
73
+ : "";
74
+ const extra = Number(record.extra_iterations);
75
+ if (toolName === "requeue_agent") {
76
+ return `${verb("Requeuing", "Requeued")} ${agent}${reason}`;
77
+ }
78
+ if (toolName === "restart_agent") {
79
+ return `${verb("Restarting", "Restarted")} ${agent}`;
80
+ }
81
+ const resumed = ids(record, "agent_id", "agent_ids");
82
+ return `${verb("Resuming", "Resumed")} ${
83
+ resumed.length === 0
84
+ ? "every waiting agent"
85
+ : resumed.length === 1
86
+ ? agent
87
+ : listed(resumed)
88
+ }${Number.isFinite(extra) && extra > 0 ? ` (+${extra} iterations)` : ""}`;
89
+ }
90
+ case "retry_failed": {
91
+ const round =
92
+ typeof record.round_id === "string" ? record.round_id.trim() : "";
93
+ return `${verb("Retrying", "Retried")} the failed agents${round ? ` of ${round}` : ""}`;
94
+ }
95
+ case "message_agents":
96
+ case "stop_agents": {
97
+ const agents = ids(record, "agent", "agents");
98
+ if (toolName === "message_agents") {
99
+ return `${verb("Messaging", "Messaged")} ${agents.length > 0 ? listed(agents) : "every running agent"}`;
100
+ }
101
+ return `${verb("Stopping", "Stopped")} ${agents.length > 0 ? listed(agents) : "every running agent"}`;
102
+ }
103
+ case "compact_agents": {
104
+ const agents = ids(record, "agent", "agents");
105
+ return `${verb("Compacting", "Compacted")} ${agents.length > 0 ? listed(agents) : "no agents"}`;
106
+ }
107
+ case "await_agents": {
108
+ const rounds = ids(record, "round_id", "round_ids");
109
+ return `${verb("Waiting for", "Waited for")} ${rounds.length > 0 ? `round ${listed(rounds)}` : "the running rounds"}`;
110
+ }
111
+ default:
112
+ return undefined;
113
+ }
114
+ }
@@ -0,0 +1,152 @@
1
+ function computeLcs(a: string[], b: string[]): number[][] {
2
+ const m = a.length;
3
+ const n = b.length;
4
+ const dp: number[][] = Array.from({ length: m + 1 }, () =>
5
+ new Array(n + 1).fill(0),
6
+ );
7
+ for (let i = 1; i <= m; i++) {
8
+ for (let j = 1; j <= n; j++) {
9
+ dp[i][j] =
10
+ a[i - 1] === b[j - 1]
11
+ ? dp[i - 1][j - 1] + 1
12
+ : Math.max(dp[i - 1][j], dp[i][j - 1]);
13
+ }
14
+ }
15
+ return dp;
16
+ }
17
+
18
+ function diffLines(
19
+ oldLines: string[],
20
+ newLines: string[],
21
+ ): { type: "+" | "-" | " "; line: string }[] {
22
+ const dp = computeLcs(oldLines, newLines);
23
+ const result: { type: "+" | "-" | " "; line: string }[] = [];
24
+ let i = oldLines.length;
25
+ let j = newLines.length;
26
+ while (i > 0 || j > 0) {
27
+ if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
28
+ result.unshift({ type: " ", line: oldLines[i - 1] });
29
+ i--;
30
+ j--;
31
+ } else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
32
+ result.unshift({ type: "+", line: newLines[j - 1] });
33
+ j--;
34
+ } else {
35
+ result.unshift({ type: "-", line: oldLines[i - 1] });
36
+ i--;
37
+ }
38
+ }
39
+ return result;
40
+ }
41
+
42
+ /** Honest hunk separator for diffs built from file fragments. */
43
+ export const FRAGMENT_HUNK_HEADER = "@@ … @@";
44
+
45
+ export type MakeUnifiedDiffOptions = {
46
+ /**
47
+ * Set when oldText/newText are fragments of a larger file (e.g. editor
48
+ * str_replace payloads) rather than complete file contents. Hunk headers
49
+ * then render as `@@ … @@` instead of fabricating line-1-relative
50
+ * positions that would mislocate the change.
51
+ */
52
+ fragment?: boolean;
53
+ };
54
+
55
+ export function makeUnifiedDiff(
56
+ oldText: string,
57
+ newText: string,
58
+ filePath: string,
59
+ ctx = 3,
60
+ options?: MakeUnifiedDiffOptions,
61
+ ): string {
62
+ // Empty text means zero lines, not one blank line — otherwise creating an
63
+ // empty file or deleting all content reports a phantom blank addition.
64
+ const oldArr = oldText ? oldText.split("\n") : [];
65
+ const newArr = newText ? newText.split("\n") : [];
66
+ const ops = diffLines(oldArr, newArr);
67
+
68
+ const output: string[] = [];
69
+ output.push(`--- a/${filePath}`);
70
+ output.push(`+++ b/${filePath}`);
71
+
72
+ let i = 0;
73
+ while (i < ops.length) {
74
+ if (ops[i].type === " ") {
75
+ i++;
76
+ continue;
77
+ }
78
+
79
+ const hunkStart = Math.max(0, i - ctx);
80
+ let end = i;
81
+ while (end < ops.length) {
82
+ if (ops[end].type !== " ") {
83
+ end++;
84
+ continue;
85
+ }
86
+ let next = end;
87
+ while (next < ops.length && ops[next].type === " ") next++;
88
+ if (next < ops.length && next - end <= ctx * 2) {
89
+ end = next + 1;
90
+ } else {
91
+ break;
92
+ }
93
+ }
94
+ const hunkEnd = Math.min(ops.length, end + ctx);
95
+
96
+ let oldCount = 0;
97
+ let newCount = 0;
98
+ for (let k = hunkStart; k < hunkEnd; k++) {
99
+ if (ops[k].type !== "+") oldCount++;
100
+ if (ops[k].type !== "-") newCount++;
101
+ }
102
+
103
+ let oldStart = 1;
104
+ let newStart = 1;
105
+ for (let k = 0; k < hunkStart; k++) {
106
+ if (ops[k].type !== "+") oldStart++;
107
+ if (ops[k].type !== "-") newStart++;
108
+ }
109
+
110
+ output.push(
111
+ options?.fragment
112
+ ? FRAGMENT_HUNK_HEADER
113
+ : `@@ -${oldStart},${oldCount} +${newStart},${newCount} @@`,
114
+ );
115
+ for (let k = hunkStart; k < hunkEnd; k++) {
116
+ const prefix = ops[k].type === " " ? " " : ops[k].type;
117
+ output.push(`${prefix}${ops[k].line}`);
118
+ }
119
+
120
+ i = hunkEnd;
121
+ }
122
+
123
+ return output.join("\n");
124
+ }
125
+
126
+ export function hunkHeader(lines: string[]): string {
127
+ let oldCount = 0;
128
+ let newCount = 0;
129
+ for (const l of lines) {
130
+ if (!l.startsWith("+")) oldCount++;
131
+ if (!l.startsWith("-")) newCount++;
132
+ }
133
+ return `@@ -1,${oldCount} +1,${newCount} @@`;
134
+ }
135
+
136
+ /**
137
+ * Count added/removed lines in a unified diff, ignoring the `---`/`+++`
138
+ * file headers and `@@` hunk headers.
139
+ */
140
+ export function countDiffLines(diff: string): {
141
+ additions: number;
142
+ deletions: number;
143
+ } {
144
+ let additions = 0;
145
+ let deletions = 0;
146
+ for (const line of diff.split("\n")) {
147
+ if (line.startsWith("+++") || line.startsWith("---")) continue;
148
+ if (line.startsWith("+")) additions++;
149
+ else if (line.startsWith("-")) deletions++;
150
+ }
151
+ return { additions, deletions };
152
+ }