@bubblebrain-ai/bubble 0.0.23 → 0.0.25

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 (168) hide show
  1. package/README.md +1 -1
  2. package/dist/config.d.ts +3 -0
  3. package/dist/config.js +22 -6
  4. package/dist/goal/command.d.ts +20 -0
  5. package/dist/goal/command.js +71 -0
  6. package/dist/goal/engine.d.ts +33 -0
  7. package/dist/goal/engine.js +65 -0
  8. package/dist/goal/format.d.ts +18 -0
  9. package/dist/goal/format.js +112 -0
  10. package/dist/goal/prompts.d.ts +13 -0
  11. package/dist/goal/prompts.js +84 -0
  12. package/dist/goal/store.d.ts +64 -0
  13. package/dist/goal/store.js +174 -0
  14. package/dist/goal/tools.d.ts +10 -0
  15. package/dist/goal/tools.js +70 -0
  16. package/dist/goal/usage.d.ts +2 -0
  17. package/dist/goal/usage.js +3 -0
  18. package/dist/main.js +29 -42
  19. package/dist/model-catalog.js +11 -0
  20. package/dist/provider-transform.js +17 -0
  21. package/dist/provider.js +20 -5
  22. package/dist/session-types.d.ts +3 -0
  23. package/dist/tools/index.d.ts +3 -0
  24. package/dist/tools/index.js +2 -0
  25. package/dist/tui/detect-theme.d.ts +1 -0
  26. package/dist/tui/detect-theme.js +23 -0
  27. package/dist/tui/image-display.d.ts +13 -0
  28. package/dist/tui/image-display.js +49 -0
  29. package/dist/tui/input-history.d.ts +37 -6
  30. package/dist/tui/input-history.js +194 -23
  31. package/dist/tui/model-switch.d.ts +42 -0
  32. package/dist/tui/model-switch.js +55 -0
  33. package/dist/tui-ink/app.d.ts +32 -2
  34. package/dist/tui-ink/app.js +1360 -522
  35. package/dist/tui-ink/approval/select.js +10 -0
  36. package/dist/tui-ink/detect-theme.d.ts +1 -2
  37. package/dist/tui-ink/detect-theme.js +1 -87
  38. package/dist/tui-ink/display-history.d.ts +1 -0
  39. package/dist/tui-ink/display-history.js +11 -0
  40. package/dist/tui-ink/feedback-dialog.js +10 -0
  41. package/dist/tui-ink/feishu-setup-picker.js +10 -0
  42. package/dist/tui-ink/footer.d.ts +1 -0
  43. package/dist/tui-ink/footer.js +8 -2
  44. package/dist/tui-ink/input-box.d.ts +70 -9
  45. package/dist/tui-ink/input-box.js +354 -120
  46. package/dist/tui-ink/input-history.d.ts +1 -16
  47. package/dist/tui-ink/input-history.js +1 -79
  48. package/dist/tui-ink/input-queue.d.ts +12 -0
  49. package/dist/tui-ink/input-queue.js +17 -0
  50. package/dist/tui-ink/key-events.d.ts +9 -0
  51. package/dist/tui-ink/key-events.js +8 -0
  52. package/dist/tui-ink/markdown.js +1 -1
  53. package/dist/tui-ink/message-list.d.ts +3 -1
  54. package/dist/tui-ink/message-list.js +42 -24
  55. package/dist/tui-ink/model-picker.d.ts +24 -2
  56. package/dist/tui-ink/model-picker.js +224 -20
  57. package/dist/tui-ink/plan-confirm.js +10 -0
  58. package/dist/tui-ink/question-dialog.js +10 -0
  59. package/dist/tui-ink/run.d.ts +11 -0
  60. package/dist/tui-ink/run.js +21 -28
  61. package/dist/tui-ink/session-picker.js +3 -0
  62. package/dist/tui-ink/submit-dedupe.d.ts +5 -0
  63. package/dist/tui-ink/submit-dedupe.js +25 -0
  64. package/dist/tui-ink/terminal-mouse.d.ts +13 -1
  65. package/dist/tui-ink/terminal-mouse.js +63 -21
  66. package/dist/tui-ink/theme.d.ts +6 -3
  67. package/dist/tui-ink/theme.js +10 -4
  68. package/dist/tui-ink/transcript-input.d.ts +8 -0
  69. package/dist/tui-ink/transcript-input.js +9 -0
  70. package/dist/tui-ink/transcript-viewport-math.d.ts +1 -2
  71. package/dist/tui-ink/transcript-viewport-math.js +1 -2
  72. package/dist/tui-ink/welcome.d.ts +1 -0
  73. package/dist/tui-ink/welcome.js +25 -28
  74. package/package.json +1 -5
  75. package/dist/tui/clipboard.d.ts +0 -1
  76. package/dist/tui/clipboard.js +0 -53
  77. package/dist/tui/escape-confirmation.d.ts +0 -15
  78. package/dist/tui/escape-confirmation.js +0 -30
  79. package/dist/tui/global-key-router.d.ts +0 -3
  80. package/dist/tui/global-key-router.js +0 -87
  81. package/dist/tui/markdown-inline.d.ts +0 -22
  82. package/dist/tui/markdown-inline.js +0 -68
  83. package/dist/tui/markdown-theme-rules.d.ts +0 -23
  84. package/dist/tui/markdown-theme-rules.js +0 -164
  85. package/dist/tui/markdown-theme.d.ts +0 -5
  86. package/dist/tui/markdown-theme.js +0 -27
  87. package/dist/tui/opencode-spinner.d.ts +0 -22
  88. package/dist/tui/opencode-spinner.js +0 -216
  89. package/dist/tui/prompt-keybindings.d.ts +0 -42
  90. package/dist/tui/prompt-keybindings.js +0 -35
  91. package/dist/tui/render-signature.d.ts +0 -1
  92. package/dist/tui/render-signature.js +0 -7
  93. package/dist/tui/run.d.ts +0 -65
  94. package/dist/tui/run.js +0 -9934
  95. package/dist/tui/sidebar-mcp.d.ts +0 -31
  96. package/dist/tui/sidebar-mcp.js +0 -62
  97. package/dist/tui/sidebar-state.d.ts +0 -12
  98. package/dist/tui/sidebar-state.js +0 -69
  99. package/dist/tui/streaming-tool-args.d.ts +0 -15
  100. package/dist/tui/streaming-tool-args.js +0 -30
  101. package/dist/tui/tool-renderers/fallback.d.ts +0 -2
  102. package/dist/tui/tool-renderers/fallback.js +0 -75
  103. package/dist/tui/tool-renderers/registry.d.ts +0 -3
  104. package/dist/tui/tool-renderers/registry.js +0 -11
  105. package/dist/tui/tool-renderers/subagent.d.ts +0 -2
  106. package/dist/tui/tool-renderers/subagent.js +0 -135
  107. package/dist/tui/tool-renderers/types.d.ts +0 -36
  108. package/dist/tui/tool-renderers/types.js +0 -1
  109. package/dist/tui/tool-renderers/write-preview.d.ts +0 -12
  110. package/dist/tui/tool-renderers/write-preview.js +0 -32
  111. package/dist/tui/tool-renderers/write.d.ts +0 -6
  112. package/dist/tui/tool-renderers/write.js +0 -88
  113. package/dist/tui-opentui/app.d.ts +0 -54
  114. package/dist/tui-opentui/app.js +0 -1371
  115. package/dist/tui-opentui/approval/approval-dialog.d.ts +0 -15
  116. package/dist/tui-opentui/approval/approval-dialog.js +0 -155
  117. package/dist/tui-opentui/approval/diff-view.d.ts +0 -9
  118. package/dist/tui-opentui/approval/diff-view.js +0 -43
  119. package/dist/tui-opentui/approval/select.d.ts +0 -37
  120. package/dist/tui-opentui/approval/select.js +0 -91
  121. package/dist/tui-opentui/detect-theme.d.ts +0 -2
  122. package/dist/tui-opentui/detect-theme.js +0 -87
  123. package/dist/tui-opentui/display-history.d.ts +0 -56
  124. package/dist/tui-opentui/display-history.js +0 -130
  125. package/dist/tui-opentui/edit-diff.d.ts +0 -11
  126. package/dist/tui-opentui/edit-diff.js +0 -57
  127. package/dist/tui-opentui/feedback-dialog.d.ts +0 -21
  128. package/dist/tui-opentui/feedback-dialog.js +0 -164
  129. package/dist/tui-opentui/feishu-setup-picker.d.ts +0 -7
  130. package/dist/tui-opentui/feishu-setup-picker.js +0 -272
  131. package/dist/tui-opentui/file-mentions.d.ts +0 -29
  132. package/dist/tui-opentui/file-mentions.js +0 -174
  133. package/dist/tui-opentui/footer.d.ts +0 -26
  134. package/dist/tui-opentui/footer.js +0 -40
  135. package/dist/tui-opentui/image-paste.d.ts +0 -54
  136. package/dist/tui-opentui/image-paste.js +0 -288
  137. package/dist/tui-opentui/input-box.d.ts +0 -32
  138. package/dist/tui-opentui/input-box.js +0 -462
  139. package/dist/tui-opentui/input-history.d.ts +0 -16
  140. package/dist/tui-opentui/input-history.js +0 -79
  141. package/dist/tui-opentui/markdown.d.ts +0 -66
  142. package/dist/tui-opentui/markdown.js +0 -127
  143. package/dist/tui-opentui/message-list.d.ts +0 -31
  144. package/dist/tui-opentui/message-list.js +0 -131
  145. package/dist/tui-opentui/model-picker.d.ts +0 -63
  146. package/dist/tui-opentui/model-picker.js +0 -450
  147. package/dist/tui-opentui/plan-confirm.d.ts +0 -9
  148. package/dist/tui-opentui/plan-confirm.js +0 -124
  149. package/dist/tui-opentui/question-dialog.d.ts +0 -10
  150. package/dist/tui-opentui/question-dialog.js +0 -110
  151. package/dist/tui-opentui/recent-activity.d.ts +0 -8
  152. package/dist/tui-opentui/recent-activity.js +0 -71
  153. package/dist/tui-opentui/run-session-picker.d.ts +0 -10
  154. package/dist/tui-opentui/run-session-picker.js +0 -28
  155. package/dist/tui-opentui/run.d.ts +0 -38
  156. package/dist/tui-opentui/run.js +0 -48
  157. package/dist/tui-opentui/session-picker.d.ts +0 -12
  158. package/dist/tui-opentui/session-picker.js +0 -120
  159. package/dist/tui-opentui/theme.d.ts +0 -89
  160. package/dist/tui-opentui/theme.js +0 -157
  161. package/dist/tui-opentui/todos.d.ts +0 -9
  162. package/dist/tui-opentui/todos.js +0 -45
  163. package/dist/tui-opentui/trace-groups.d.ts +0 -27
  164. package/dist/tui-opentui/trace-groups.js +0 -455
  165. package/dist/tui-opentui/use-terminal-size.d.ts +0 -4
  166. package/dist/tui-opentui/use-terminal-size.js +0 -5
  167. package/dist/tui-opentui/welcome.d.ts +0 -25
  168. package/dist/tui-opentui/welcome.js +0 -77
@@ -1,31 +0,0 @@
1
- /**
2
- * Pure helpers for the TUI MCP sidebar widget.
3
- *
4
- * Kept separate from run.ts so they can be unit-tested without mounting the
5
- * full opentui renderer. run.ts imports sidebarMcpRowsFromStates and
6
- * renderMcpRowMarker for display; everything else stays in-TUI because it
7
- * depends on theme / renderable construction.
8
- */
9
- import type { McpServerState } from "../mcp/types.js";
10
- export interface SidebarMcpRow {
11
- name: string;
12
- kind: "connected" | "failed" | "disabled";
13
- label: string;
14
- toolCount: number;
15
- promptCount: number;
16
- errorDetail?: string;
17
- canReconnect: boolean;
18
- }
19
- /**
20
- * Project raw McpServerState[] (from McpManager.getStates()) into the display
21
- * shape consumed by the sidebar's row renderer. Deterministic and side-effect
22
- * free — the single source of truth for what the widget shows per server.
23
- */
24
- export declare function sidebarMcpRowsFromStates(states: McpServerState[]): SidebarMcpRow[];
25
- /**
26
- * Single-char status marker used at the start of each sidebar row.
27
- * Mirrors opencode's convention so a connected row reads as a bullet, failed
28
- * as a cross, disabled as a hollow circle. Colour is applied separately by
29
- * the caller using theme mapping.
30
- */
31
- export declare function renderMcpRowMarker(kind: SidebarMcpRow["kind"]): string;
@@ -1,62 +0,0 @@
1
- /**
2
- * Pure helpers for the TUI MCP sidebar widget.
3
- *
4
- * Kept separate from run.ts so they can be unit-tested without mounting the
5
- * full opentui renderer. run.ts imports sidebarMcpRowsFromStates and
6
- * renderMcpRowMarker for display; everything else stays in-TUI because it
7
- * depends on theme / renderable construction.
8
- */
9
- const ERROR_LABEL_MAX = 32;
10
- function truncateInline(s, n) {
11
- return s.length <= n ? s : s.slice(0, n - 1) + "…";
12
- }
13
- /**
14
- * Project raw McpServerState[] (from McpManager.getStates()) into the display
15
- * shape consumed by the sidebar's row renderer. Deterministic and side-effect
16
- * free — the single source of truth for what the widget shows per server.
17
- */
18
- export function sidebarMcpRowsFromStates(states) {
19
- return states.map((state) => {
20
- const kind = state.status.kind;
21
- const toolCount = kind === "connected" ? state.status.tools.length : 0;
22
- const promptCount = kind === "connected" ? state.status.prompts.length : 0;
23
- const errorDetail = kind === "failed" ? state.status.error : undefined;
24
- let label;
25
- if (kind === "connected") {
26
- const parts = [];
27
- parts.push(`${toolCount} tool${toolCount === 1 ? "" : "s"}`);
28
- if (promptCount > 0) {
29
- parts.push(`${promptCount} prompt${promptCount === 1 ? "" : "s"}`);
30
- }
31
- label = parts.join(", ");
32
- }
33
- else if (kind === "failed") {
34
- label = truncateInline(state.status.error, ERROR_LABEL_MAX);
35
- }
36
- else {
37
- label = "disabled";
38
- }
39
- return {
40
- name: state.name,
41
- kind,
42
- label,
43
- toolCount,
44
- promptCount,
45
- errorDetail,
46
- canReconnect: kind === "failed" || kind === "disabled",
47
- };
48
- });
49
- }
50
- /**
51
- * Single-char status marker used at the start of each sidebar row.
52
- * Mirrors opencode's convention so a connected row reads as a bullet, failed
53
- * as a cross, disabled as a hollow circle. Colour is applied separately by
54
- * the caller using theme mapping.
55
- */
56
- export function renderMcpRowMarker(kind) {
57
- if (kind === "connected")
58
- return "●";
59
- if (kind === "failed")
60
- return "✗";
61
- return "○";
62
- }
@@ -1,12 +0,0 @@
1
- export interface SidebarFileChange {
2
- file: string;
3
- additions: number;
4
- deletions: number;
5
- }
6
- export interface SidebarGitState {
7
- branch?: string;
8
- files: SidebarFileChange[];
9
- }
10
- export declare function parseGitNumstat(output: string): SidebarFileChange[];
11
- export declare function mergeFileChanges(...groups: SidebarFileChange[][]): SidebarFileChange[];
12
- export declare function readGitSidebarState(cwd: string): SidebarGitState;
@@ -1,69 +0,0 @@
1
- import { execFileSync } from "node:child_process";
2
- export function parseGitNumstat(output) {
3
- return output
4
- .split(/\r?\n/)
5
- .map((line) => line.trim())
6
- .filter(Boolean)
7
- .map((line) => {
8
- const [rawAdditions, rawDeletions, ...pathParts] = line.split(/\t/);
9
- const file = pathParts.join("\t").trim();
10
- if (!file)
11
- return undefined;
12
- return {
13
- file,
14
- additions: parseGitCount(rawAdditions),
15
- deletions: parseGitCount(rawDeletions),
16
- };
17
- })
18
- .filter((item) => !!item);
19
- }
20
- export function mergeFileChanges(...groups) {
21
- const merged = new Map();
22
- for (const group of groups) {
23
- for (const item of group) {
24
- const existing = merged.get(item.file);
25
- if (!existing) {
26
- merged.set(item.file, { ...item });
27
- continue;
28
- }
29
- existing.additions += item.additions;
30
- existing.deletions += item.deletions;
31
- }
32
- }
33
- return [...merged.values()].sort((a, b) => a.file.localeCompare(b.file));
34
- }
35
- export function readGitSidebarState(cwd) {
36
- const branch = runGit(cwd, ["branch", "--show-current"]).trim()
37
- || runGit(cwd, ["rev-parse", "--abbrev-ref", "HEAD"]).trim()
38
- || undefined;
39
- const unstaged = parseGitNumstat(runGit(cwd, ["--no-pager", "diff", "--numstat"]));
40
- const staged = parseGitNumstat(runGit(cwd, ["--no-pager", "diff", "--cached", "--numstat"]));
41
- const untracked = runGit(cwd, ["ls-files", "--others", "--exclude-standard"])
42
- .split(/\r?\n/)
43
- .map((file) => file.trim())
44
- .filter(Boolean)
45
- .map((file) => ({ file, additions: 0, deletions: 0 }));
46
- return {
47
- branch,
48
- files: mergeFileChanges(unstaged, staged, untracked),
49
- };
50
- }
51
- function runGit(cwd, args) {
52
- try {
53
- return execFileSync("git", args, {
54
- cwd,
55
- encoding: "utf8",
56
- stdio: ["ignore", "pipe", "ignore"],
57
- timeout: 750,
58
- });
59
- }
60
- catch {
61
- return "";
62
- }
63
- }
64
- function parseGitCount(value) {
65
- if (value === "-")
66
- return 0;
67
- const count = Number.parseInt(value, 10);
68
- return Number.isFinite(count) ? count : 0;
69
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Extract user-visible signals from a partial tool-call JSON buffer.
3
- *
4
- * We deliberately do NOT attempt a full partial-JSON parse. The goal is just
5
- * to surface the file path (so the tool header can render) and a coarse
6
- * "how much has been streamed" hint, both available the moment the model has
7
- * emitted enough text for them to be unambiguous.
8
- */
9
- export interface StreamingArgsHint {
10
- /** First fully-closed string value found for a known path field. */
11
- path?: string;
12
- /** Count of escaped newline sequences (`\n`) seen so far — proxy for written line count. */
13
- newlineCount: number;
14
- }
15
- export declare function extractStreamingArgsHint(raw: string): StreamingArgsHint;
@@ -1,30 +0,0 @@
1
- /**
2
- * Extract user-visible signals from a partial tool-call JSON buffer.
3
- *
4
- * We deliberately do NOT attempt a full partial-JSON parse. The goal is just
5
- * to surface the file path (so the tool header can render) and a coarse
6
- * "how much has been streamed" hint, both available the moment the model has
7
- * emitted enough text for them to be unambiguous.
8
- */
9
- const PATH_FIELDS = ["path", "file_path", "filePath"];
10
- export function extractStreamingArgsHint(raw) {
11
- let path;
12
- for (const field of PATH_FIELDS) {
13
- const re = new RegExp(`"${field}"\\s*:\\s*"((?:\\\\.|[^"\\\\])*)"`);
14
- const m = raw.match(re);
15
- if (m) {
16
- try {
17
- path = JSON.parse(`"${m[1]}"`);
18
- break;
19
- }
20
- catch {
21
- // The matched substring ended mid-escape; ignore and wait for more.
22
- }
23
- }
24
- }
25
- const newlines = raw.match(/\\n/g);
26
- return {
27
- path,
28
- newlineCount: newlines ? newlines.length : 0,
29
- };
30
- }
@@ -1,2 +0,0 @@
1
- import type { ToolRenderer } from "./types.js";
2
- export declare const fallbackToolRenderer: ToolRenderer;
@@ -1,75 +0,0 @@
1
- import { fg, StyledText } from "@opentui/core";
2
- export const fallbackToolRenderer = {
3
- canRender: (_tool) => true,
4
- render: renderFallbackTool,
5
- };
6
- function renderFallbackTool({ ctx, tool, syntaxStyle, width, helpers }) {
7
- const { theme } = helpers;
8
- const icon = helpers.toolStateIcon(tool);
9
- const color = helpers.toolColor(tool);
10
- const header = helpers.toolHeader(tool);
11
- const diff = helpers.extractToolDiff(tool);
12
- const isError = tool.isError === true || tool.status === "error";
13
- if (diff && !isError && (tool.name === "edit" || tool.name === "apply_patch")) {
14
- return helpers.createBox(ctx, {
15
- paddingLeft: 3,
16
- marginTop: 1,
17
- flexDirection: "column",
18
- flexShrink: 0,
19
- }, [
20
- helpers.createText(ctx, new StyledText([
21
- fg(color)(`${icon} ${helpers.displayToolName(tool.name)}`),
22
- fg(theme.toolText)(header ? ` ${header}` : ""),
23
- ])),
24
- helpers.createBox(ctx, {
25
- paddingLeft: 1,
26
- marginTop: 1,
27
- border: ["left"],
28
- borderColor: theme.borderSubtle,
29
- flexDirection: "column",
30
- flexShrink: 0,
31
- }, [helpers.createDiffRenderable(ctx, diff, helpers.toolPath(tool), syntaxStyle, width)]),
32
- ]);
33
- }
34
- const chunks = [
35
- fg(color)(`${icon} ${helpers.displayToolName(tool.name)}`),
36
- ];
37
- if (header)
38
- chunks.push(fg(theme.toolText)(` ${header}`));
39
- const showTail = !!tool.result || tool.status === "running" || tool.status === "pending" || tool.streamingArgs === true;
40
- if (showTail) {
41
- const summary = helpers.summarizeToolResult(tool);
42
- if (summary) {
43
- chunks.push(fg(theme.text)("\n"));
44
- chunks.push(fg(theme.borderSubtle)(" "));
45
- chunks.push(fg(isError ? theme.toolError : theme.textMuted)(summary));
46
- }
47
- const preview = helpers.toolPreview(tool);
48
- if (preview) {
49
- for (const line of preview.lines) {
50
- chunks.push(fg(theme.text)("\n"));
51
- chunks.push(fg(theme.borderSubtle)(" "));
52
- chunks.push(fg(theme.toolText)(line));
53
- }
54
- if (preview.omitted > 0) {
55
- chunks.push(fg(theme.text)("\n"));
56
- chunks.push(fg(theme.borderSubtle)(" "));
57
- chunks.push(fg(theme.textMuted)(`+ ${preview.omitted} more`));
58
- }
59
- }
60
- }
61
- const containerProps = {
62
- paddingLeft: isError ? 1 : 3,
63
- marginTop: 1,
64
- flexDirection: "column",
65
- flexShrink: 0,
66
- };
67
- if (isError) {
68
- containerProps.border = ["left"];
69
- containerProps.borderColor = theme.toolError;
70
- containerProps.paddingLeft = 2;
71
- }
72
- return helpers.createBox(ctx, containerProps, [
73
- helpers.createText(ctx, new StyledText(chunks), { wrapMode: "word" }),
74
- ]);
75
- }
@@ -1,3 +0,0 @@
1
- import type { DisplayToolCall } from "../display-history.js";
2
- import type { ToolRenderer } from "./types.js";
3
- export declare function findToolRenderer(tool: DisplayToolCall): ToolRenderer | undefined;
@@ -1,11 +0,0 @@
1
- import { fallbackToolRenderer } from "./fallback.js";
2
- import { subagentToolRenderer } from "./subagent.js";
3
- import { writeToolRenderer } from "./write.js";
4
- const TOOL_RENDERERS = [
5
- writeToolRenderer,
6
- subagentToolRenderer,
7
- fallbackToolRenderer,
8
- ];
9
- export function findToolRenderer(tool) {
10
- return TOOL_RENDERERS.find((renderer) => renderer.canRender(tool));
11
- }
@@ -1,2 +0,0 @@
1
- import type { ToolRenderer } from "./types.js";
2
- export declare const subagentToolRenderer: ToolRenderer;
@@ -1,135 +0,0 @@
1
- import { fg, StyledText } from "@opentui/core";
2
- import { formatSubagentRoute } from "../../agent/subagent-route-format.js";
3
- export const subagentToolRenderer = {
4
- canRender: (tool) => tool.name === "subagent" || tool.metadata?.kind === "subagent",
5
- render: renderSubagentTool,
6
- };
7
- function renderSubagentTool({ ctx, tool, width, helpers }) {
8
- const { theme } = helpers;
9
- const metadata = tool.metadata ?? {};
10
- const subagents = subagentsFrom(tool);
11
- const mode = typeof metadata.mode === "string" ? metadata.mode : (subagents.length > 1 ? "parallel" : "single");
12
- const completed = subagents.filter((item) => item.status === "completed").length;
13
- const failed = subagents.filter((item) => ["failed", "blocked", "cancelled"].includes(item.status ?? "")).length;
14
- const color = tool.isError ? theme.toolError : tool.status === "running" ? theme.toolPending : theme.toolSuccess;
15
- const headerChunks = [
16
- fg(color)(`> ${helpers.displayToolName(tool.name)}`),
17
- fg(theme.toolText)(` ${mode}`),
18
- ];
19
- if (subagents.length > 0) {
20
- headerChunks.push(fg(theme.textMuted)(` ${completed}/${subagents.length}`));
21
- if (failed > 0)
22
- headerChunks.push(fg(theme.toolError)(` ${failed} failed`));
23
- }
24
- const children = [
25
- helpers.createText(ctx, new StyledText(headerChunks), { wrapMode: "word" }),
26
- ];
27
- const rows = sortSubagents(subagents).map((subagent) => renderSubagentRow(ctx, subagent, width, helpers));
28
- if (rows.length > 0) {
29
- children.push(helpers.createBox(ctx, {
30
- paddingLeft: 1,
31
- marginTop: 0,
32
- border: ["left"],
33
- borderColor: theme.borderSubtle,
34
- flexDirection: "column",
35
- flexShrink: 0,
36
- }, rows));
37
- }
38
- else if (tool.result) {
39
- children.push(helpers.createText(ctx, helpers.summarizeToolResult(tool), {
40
- fg: tool.isError ? theme.toolError : theme.textMuted,
41
- wrapMode: "word",
42
- }));
43
- }
44
- return helpers.createBox(ctx, {
45
- paddingLeft: 3,
46
- marginTop: 1,
47
- flexDirection: "column",
48
- flexShrink: 0,
49
- }, children);
50
- }
51
- function renderSubagentRow(ctx, subagent, width, helpers) {
52
- const { theme } = helpers;
53
- const status = subagent.status ?? "running";
54
- const color = status === "completed"
55
- ? theme.toolSuccess
56
- : status === "running" || status === "queued"
57
- ? theme.toolPending
58
- : theme.toolError;
59
- const source = subagent.profileSource ? ` [${subagent.profileSource}]` : "";
60
- const usage = subagent.usage?.totalTokens ? ` ${subagent.usage.totalTokens} tokens` : "";
61
- const summary = firstUsefulLine(subagent.error || subagent.summary || lastToolNote(subagent.toolNotes));
62
- const task = firstUsefulLine(subagent.task);
63
- const maxLine = Math.max(24, width - 12);
64
- const descriptor = subagentDescriptor(subagent, true);
65
- const lines = [
66
- helpers.createText(ctx, new StyledText([
67
- fg(color)(`${statusIcon(status)} ${subagentLabel(subagent)}`),
68
- fg(theme.textMuted)(` ${descriptor}${source} ${status}${usage}`),
69
- ]), { wrapMode: "word" }),
70
- ];
71
- if (task) {
72
- lines.push(helpers.createText(ctx, shorten(`task: ${task}`, maxLine), {
73
- fg: theme.textMuted,
74
- wrapMode: "word",
75
- }));
76
- }
77
- if (summary) {
78
- lines.push(helpers.createText(ctx, shorten(summary, maxLine), {
79
- fg: subagent.error ? theme.toolError : theme.toolText,
80
- wrapMode: "word",
81
- }));
82
- }
83
- return helpers.createBox(ctx, {
84
- flexDirection: "column",
85
- flexShrink: 0,
86
- }, lines);
87
- }
88
- function subagentLabel(subagent) {
89
- return subagent.nickname ?? subagent.agentName ?? "subagent";
90
- }
91
- function subagentRole(subagent) {
92
- return [subagent.agentName, subagent.category ? `/${subagent.category}` : ""].join("") || "default";
93
- }
94
- function subagentDescriptor(subagent, includeThinking = false) {
95
- const route = formatSubagentRoute(subagent.route, { includeThinking });
96
- const role = subagentRole(subagent);
97
- return route ? `${role} @ ${route}` : role;
98
- }
99
- function subagentsFrom(tool) {
100
- const raw = tool.metadata?.subagents;
101
- if (!Array.isArray(raw))
102
- return [];
103
- return raw.filter((item) => typeof item === "object" && item !== null);
104
- }
105
- function statusIcon(status) {
106
- if (status === "completed")
107
- return "+";
108
- if (status === "running")
109
- return ">";
110
- if (status === "queued")
111
- return ".";
112
- return "!";
113
- }
114
- function sortSubagents(subagents) {
115
- const rank = {
116
- running: 0,
117
- blocked: 1,
118
- failed: 2,
119
- queued: 3,
120
- cancelled: 4,
121
- completed: 5,
122
- };
123
- return [...subagents].sort((a, b) => (rank[a.status ?? "running"] ?? 9) - (rank[b.status ?? "running"] ?? 9));
124
- }
125
- function lastToolNote(notes) {
126
- return notes?.filter(Boolean).at(-1);
127
- }
128
- function firstUsefulLine(value) {
129
- return value?.split(/\r?\n/).map((line) => line.trim()).find(Boolean) ?? "";
130
- }
131
- function shorten(value, max) {
132
- if (value.length <= max)
133
- return value;
134
- return `${value.slice(0, Math.max(0, max - 3))}...`;
135
- }
@@ -1,36 +0,0 @@
1
- import type { RenderContext, Renderable, StyledText, SyntaxStyle, TextRenderable } from "@opentui/core";
2
- import type { DisplayToolCall } from "../display-history.js";
3
- export interface ToolRenderer {
4
- canRender(tool: DisplayToolCall): boolean;
5
- expansionKey?(messageKey: string, tool: DisplayToolCall): string | undefined;
6
- signature?(messageKey: string, tool: DisplayToolCall, expandedWrites: Set<string>): string;
7
- render(context: ToolRenderContext): Renderable;
8
- }
9
- export interface ToolRenderContext {
10
- ctx: RenderContext;
11
- tool: DisplayToolCall;
12
- syntaxStyle: SyntaxStyle;
13
- width: number;
14
- writeExpanded: boolean;
15
- onToggleWrite?: () => void;
16
- helpers: ToolRenderHelpers;
17
- }
18
- export interface ToolRenderHelpers {
19
- theme: Record<string, string>;
20
- createBox: (ctx: RenderContext, options: Record<string, unknown>, children?: Array<Renderable | null | undefined>) => Renderable;
21
- createText: (ctx: RenderContext, content: string | StyledText, options?: Record<string, unknown>) => TextRenderable;
22
- createCodeBlockRenderable: (ctx: RenderContext, content: string, filePath: string | undefined, syntaxStyle: SyntaxStyle) => Renderable;
23
- createDiffRenderable: (ctx: RenderContext, diff: string, filePath: string | undefined, syntaxStyle: SyntaxStyle, width?: number) => Renderable;
24
- toolColor: (tool: DisplayToolCall) => string;
25
- displayToolName: (name: string) => string;
26
- toolHeader: (tool: DisplayToolCall) => string;
27
- toolPath: (tool: DisplayToolCall) => string | undefined;
28
- extractToolDiff: (tool: DisplayToolCall) => string | undefined;
29
- summarizeToolResult: (tool: DisplayToolCall) => string;
30
- isToolFinished: (tool: DisplayToolCall) => boolean;
31
- toolPreview: (tool: DisplayToolCall) => {
32
- lines: string[];
33
- omitted: number;
34
- } | undefined;
35
- toolStateIcon: (tool: DisplayToolCall) => string;
36
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import type { DisplayToolCall } from "../display-history.js";
2
- export declare const WRITE_PREVIEW_CHAR_LIMIT = 5000;
3
- export declare function isWritePreviewTool(tool: DisplayToolCall): tool is DisplayToolCall & {
4
- args: {
5
- content?: string;
6
- };
7
- };
8
- export declare function formatWritePreview(content: string, expanded: boolean): {
9
- content: string;
10
- omittedLines: number;
11
- omittedChars: number;
12
- };
@@ -1,32 +0,0 @@
1
- const WRITE_PREVIEW_LINE_LIMIT = 10;
2
- export const WRITE_PREVIEW_CHAR_LIMIT = 5000;
3
- export function isWritePreviewTool(tool) {
4
- if (tool.resultCollapsed)
5
- return false;
6
- if (tool.isError)
7
- return false;
8
- if (tool.name !== "write")
9
- return false;
10
- if (typeof tool.args?.content === "string")
11
- return true;
12
- // While the model is still streaming the JSON args, content may not be
13
- // populated yet — keep ownership so the header renders progressively.
14
- return tool.streamingArgs === true;
15
- }
16
- export function formatWritePreview(content, expanded) {
17
- const lines = content.split(/\r?\n/);
18
- if (expanded) {
19
- return { content, omittedLines: 0, omittedChars: 0 };
20
- }
21
- let previewContent = lines.slice(0, WRITE_PREVIEW_LINE_LIMIT).join("\n");
22
- let omittedLines = Math.max(0, lines.length - WRITE_PREVIEW_LINE_LIMIT);
23
- if (previewContent.length > WRITE_PREVIEW_CHAR_LIMIT) {
24
- previewContent = previewContent.slice(0, WRITE_PREVIEW_CHAR_LIMIT);
25
- omittedLines = Math.max(omittedLines, lines.length - previewContent.split(/\r?\n/).length);
26
- }
27
- return {
28
- content: previewContent,
29
- omittedLines,
30
- omittedChars: Math.max(0, content.length - previewContent.length),
31
- };
32
- }
@@ -1,6 +0,0 @@
1
- import type { DisplayMessage, DisplayToolCall } from "../display-history.js";
2
- import type { ToolRenderer } from "./types.js";
3
- export declare const writeToolRenderer: ToolRenderer;
4
- export declare function writeToolKey(messageKey: string, tool: DisplayToolCall): string;
5
- export declare function writeToolExpansionDigest(message: DisplayMessage, messageKey: string, expandedWrites: Set<string>): string;
6
- export declare function writeToolExpansionSignature(messageKey: string, tool: DisplayToolCall, expandedWrites: Set<string>): string;
@@ -1,88 +0,0 @@
1
- import { fg, StyledText } from "@opentui/core";
2
- import { hashString } from "../render-signature.js";
3
- import { formatWritePreview, isWritePreviewTool, WRITE_PREVIEW_CHAR_LIMIT } from "./write-preview.js";
4
- export const writeToolRenderer = {
5
- canRender: isWritePreviewTool,
6
- expansionKey: writeToolKey,
7
- signature: writeToolExpansionSignature,
8
- render: renderWriteTool,
9
- };
10
- export function writeToolKey(messageKey, tool) {
11
- return `${messageKey}:write:${tool.id}`;
12
- }
13
- export function writeToolExpansionDigest(message, messageKey, expandedWrites) {
14
- return (message.toolCalls ?? [])
15
- .filter((tool) => isWritePreviewTool(tool))
16
- .map((tool) => writeToolExpansionSignature(messageKey, tool, expandedWrites))
17
- .join("|");
18
- }
19
- export function writeToolExpansionSignature(messageKey, tool, expandedWrites) {
20
- if (!isWritePreviewTool(tool))
21
- return "";
22
- const content = typeof tool.args.content === "string" ? tool.args.content : "";
23
- return [
24
- tool.id,
25
- expandedWrites.has(writeToolKey(messageKey, tool)) ? "expanded" : "collapsed",
26
- content.length,
27
- content.split(/\r?\n/).length,
28
- hashString(content.slice(0, WRITE_PREVIEW_CHAR_LIMIT)),
29
- hashString(content.slice(-WRITE_PREVIEW_CHAR_LIMIT)),
30
- ].join(":");
31
- }
32
- function renderWriteTool({ ctx, tool, syntaxStyle, writeExpanded, onToggleWrite, helpers }) {
33
- const { theme } = helpers;
34
- const color = helpers.toolColor(tool);
35
- const icon = "●";
36
- const header = helpers.toolHeader(tool);
37
- const hasContent = typeof tool.args.content === "string";
38
- const contentStr = hasContent ? String(tool.args.content) : "";
39
- const preview = hasContent ? formatWritePreview(contentStr, writeExpanded) : null;
40
- const writeLineCount = hasContent
41
- ? contentStr.split(/\r?\n/).length
42
- : (tool.streamingNewlineCount ?? 0) + 1;
43
- const summary = tool.result
44
- ? helpers.summarizeToolResult(tool)
45
- : `${helpers.isToolFinished(tool) ? "Prepared" : "Writing"} ${writeLineCount} line${writeLineCount === 1 ? "" : "s"} to ${helpers.toolPath(tool) ?? "file"}`;
46
- const hint = preview && preview.omittedLines > 0
47
- ? `... +${preview.omittedLines} lines (${writeExpanded ? "click or /write-previews to collapse" : "click or /write-previews to expand"})`
48
- : preview && preview.omittedChars > 0
49
- ? `... +${preview.omittedChars} chars (${writeExpanded ? "click or /write-previews to collapse" : "click or /write-previews to expand"})`
50
- : preview && writeExpanded
51
- ? "(click or /write-previews to collapse)"
52
- : "";
53
- return helpers.createBox(ctx, {
54
- paddingLeft: 3,
55
- marginTop: 1,
56
- flexDirection: "column",
57
- flexShrink: 0,
58
- }, [
59
- helpers.createText(ctx, new StyledText([
60
- fg(color)(`${icon} ${helpers.displayToolName(tool.name)}`),
61
- fg(theme.toolText)(header ? ` ${header}` : ""),
62
- ]), {
63
- onMouseUp: onToggleWrite,
64
- }),
65
- helpers.createBox(ctx, {
66
- paddingLeft: 1,
67
- marginTop: 0,
68
- border: ["left"],
69
- borderColor: theme.borderSubtle,
70
- flexDirection: "column",
71
- flexShrink: 0,
72
- }, [
73
- helpers.createText(ctx, `└ ${summary}`, {
74
- fg: tool.isError ? theme.toolError : theme.textMuted,
75
- onMouseUp: onToggleWrite,
76
- }),
77
- preview
78
- ? helpers.createCodeBlockRenderable(ctx, preview.content, helpers.toolPath(tool), syntaxStyle)
79
- : null,
80
- hint
81
- ? helpers.createText(ctx, hint, {
82
- fg: theme.textMuted,
83
- onMouseUp: onToggleWrite,
84
- })
85
- : null,
86
- ]),
87
- ]);
88
- }