@bubblebrain-ai/bubble 0.0.16 → 0.0.18

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 (62) hide show
  1. package/dist/agent/internal-reminder-sanitizer.d.ts +2 -0
  2. package/dist/agent/internal-reminder-sanitizer.js +27 -0
  3. package/dist/agent/tool-intent.js +0 -1
  4. package/dist/agent.d.ts +1 -0
  5. package/dist/agent.js +148 -23
  6. package/dist/context/budget.js +15 -0
  7. package/dist/context/prune.d.ts +1 -0
  8. package/dist/context/prune.js +32 -0
  9. package/dist/debug-trace.js +14 -0
  10. package/dist/feishu/agent-host/run-driver.js +2 -2
  11. package/dist/feishu/card/run-state.js +1 -0
  12. package/dist/feishu/serve.js +1 -0
  13. package/dist/main.js +13 -9
  14. package/dist/model-catalog.d.ts +3 -0
  15. package/dist/model-catalog.js +38 -0
  16. package/dist/model-config.d.ts +3 -0
  17. package/dist/model-config.js +3 -0
  18. package/dist/model-pricing.js +2 -1
  19. package/dist/model-selection.d.ts +7 -0
  20. package/dist/model-selection.js +9 -0
  21. package/dist/network/chatgpt-transport.js +1 -0
  22. package/dist/orchestrator/default-hooks.js +1 -1
  23. package/dist/prompt/compose.js +1 -1
  24. package/dist/prompt/environment.js +1 -3
  25. package/dist/prompt/reminders.js +3 -3
  26. package/dist/prompt/runtime.js +2 -1
  27. package/dist/provider-anthropic.d.ts +89 -0
  28. package/dist/provider-anthropic.js +597 -0
  29. package/dist/provider-openai-codex.js +3 -1
  30. package/dist/provider-registry.d.ts +2 -0
  31. package/dist/provider-registry.js +29 -3
  32. package/dist/provider-transform.d.ts +1 -1
  33. package/dist/provider-transform.js +14 -0
  34. package/dist/provider.d.ts +4 -1
  35. package/dist/provider.js +120 -41
  36. package/dist/session-log.js +14 -2
  37. package/dist/session-title.js +3 -6
  38. package/dist/slash-commands/commands.js +8 -2
  39. package/dist/stats/usage.d.ts +1 -0
  40. package/dist/stats/usage.js +28 -3
  41. package/dist/tools/edit.js +75 -1
  42. package/dist/tools/glob.js +77 -12
  43. package/dist/tools/index.d.ts +1 -1
  44. package/dist/tools/index.js +1 -3
  45. package/dist/tools/prompt-metadata.d.ts +3 -0
  46. package/dist/tools/prompt-metadata.js +17 -0
  47. package/dist/tools/write.js +14 -0
  48. package/dist/tui/paste-placeholder.d.ts +10 -0
  49. package/dist/tui/paste-placeholder.js +45 -0
  50. package/dist/tui/run.js +23 -0
  51. package/dist/tui-ink/app.js +2 -0
  52. package/dist/tui-ink/input-box.d.ts +1 -8
  53. package/dist/tui-ink/input-box.js +8 -38
  54. package/dist/tui-opentui/app.js +2 -0
  55. package/dist/tui-opentui/input-box.d.ts +1 -3
  56. package/dist/tui-opentui/input-box.js +17 -26
  57. package/dist/types.d.ts +22 -0
  58. package/package.json +7 -3
  59. package/dist/tools/apply-patch.d.ts +0 -9
  60. package/dist/tools/apply-patch.js +0 -330
  61. package/dist/tools/patch-apply.d.ts +0 -41
  62. package/dist/tools/patch-apply.js +0 -312
@@ -13,12 +13,66 @@ import { applyEditsToContent, EditApplyError, formatEditMatchNotes } from "./edi
13
13
  import { withFileMutationQueue } from "./file-mutation-queue.js";
14
14
  import { isWithinWorkspace } from "./file-state.js";
15
15
  import { resolveToolPath } from "./path-utils.js";
16
+ function prepareEditArguments(input) {
17
+ if (!input || typeof input !== "object")
18
+ return input;
19
+ const args = { ...input };
20
+ if (typeof args.file_path === "string" && typeof args.path !== "string") {
21
+ args.path = args.file_path;
22
+ }
23
+ if (typeof args.edits === "string") {
24
+ try {
25
+ const parsed = JSON.parse(args.edits);
26
+ if (Array.isArray(parsed))
27
+ args.edits = parsed;
28
+ }
29
+ catch {
30
+ // Keep the original value so validation surfaces the problem.
31
+ }
32
+ }
33
+ if (Array.isArray(args.edits)) {
34
+ args.edits = args.edits.map((edit) => {
35
+ if (!edit || typeof edit !== "object")
36
+ return edit;
37
+ const normalized = { ...edit };
38
+ if (typeof normalized.oldText !== "string") {
39
+ normalized.oldText = firstString(edit.old_text, edit.oldString, edit.old_string);
40
+ }
41
+ if (typeof normalized.newText !== "string") {
42
+ normalized.newText = firstString(edit.new_text, edit.newString, edit.new_string);
43
+ }
44
+ return normalized;
45
+ });
46
+ }
47
+ if (!Array.isArray(args.edits)) {
48
+ const oldText = firstString(args.oldText, args.old_text, args.oldString, args.old_string);
49
+ const newText = firstString(args.newText, args.new_text, args.newString, args.new_string);
50
+ if (typeof oldText === "string" && typeof newText === "string") {
51
+ args.edits = [{ oldText, newText }];
52
+ }
53
+ }
54
+ return args;
55
+ }
56
+ function firstString(...values) {
57
+ for (const value of values) {
58
+ if (typeof value === "string")
59
+ return value;
60
+ }
61
+ return undefined;
62
+ }
16
63
  export function createEditTool(cwd, approval, lsp, fileState) {
17
64
  return {
18
65
  name: "edit",
19
66
  effect: "write_direct",
20
67
  requiresApproval: true,
21
- description: "Apply targeted string replacements to a file. Prefer exact oldText copied from a recent read. The tool can tolerate common AI formatting mistakes such as extra leading/trailing whitespace, over-escaped sequences, line ending differences, indentation differences, trailing whitespace, Unicode punctuation/space, and blank-line differences when the target is unique.",
68
+ description: "Edit a single file using targeted text replacements. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
69
+ promptSnippet: "Make precise file edits with exact text replacement, including multiple disjoint edits in one call",
70
+ promptGuidelines: [
71
+ "Use edit for precise changes; edits[].oldText should be copied from a recent read and must identify a unique target.",
72
+ "When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls.",
73
+ "Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.",
74
+ "Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.",
75
+ ],
22
76
  parameters: {
23
77
  type: "object",
24
78
  properties: {
@@ -38,7 +92,27 @@ export function createEditTool(cwd, approval, lsp, fileState) {
38
92
  },
39
93
  required: ["path", "edits"],
40
94
  },
95
+ prepareArguments: prepareEditArguments,
41
96
  async execute(args) {
97
+ if (!Array.isArray(args.edits)) {
98
+ return {
99
+ content: "Error: edit requires edits to be an array of { oldText, newText } replacements.",
100
+ isError: true,
101
+ status: "blocked",
102
+ metadata: { kind: "edit", reason: "invalid_args" },
103
+ };
104
+ }
105
+ for (let index = 0; index < args.edits.length; index++) {
106
+ const edit = args.edits[index];
107
+ if (!edit || typeof edit !== "object" || typeof edit.oldText !== "string" || typeof edit.newText !== "string") {
108
+ return {
109
+ content: `Error: edit requires edits[${index}] to contain string oldText and newText fields.`,
110
+ isError: true,
111
+ status: "blocked",
112
+ metadata: { kind: "edit", reason: "invalid_args", index },
113
+ };
114
+ }
115
+ }
42
116
  const filePath = resolveToolPath(cwd, args.path);
43
117
  if (!isWithinWorkspace(cwd, filePath)) {
44
118
  return {
@@ -2,10 +2,10 @@
2
2
  * Glob tool - discover files by path pattern without shell access.
3
3
  */
4
4
  import { readdir, stat } from "node:fs/promises";
5
- import { relative, resolve } from "node:path";
5
+ import { basename, dirname, isAbsolute, relative, resolve } from "node:path";
6
6
  import picomatch from "picomatch";
7
7
  import { isSensitivePath } from "./sensitive-paths.js";
8
- import { resolveToolPath } from "./path-utils.js";
8
+ import { expandHomePath, resolveToolPath } from "./path-utils.js";
9
9
  const MAX_RESULTS = 100;
10
10
  const DEFAULT_IGNORES = new Set([
11
11
  ".git",
@@ -32,11 +32,16 @@ export function createGlobTool(cwd) {
32
32
  required: ["pattern"],
33
33
  },
34
34
  async execute(args, ctx) {
35
- const root = resolveToolPath(cwd, typeof args.path === "string" && args.path.trim() ? args.path : ".");
36
- const pattern = String(args.pattern || "").trim();
37
- if (!pattern) {
35
+ const requestedRoot = resolveToolPath(cwd, typeof args.path === "string" && args.path.trim() ? args.path : ".");
36
+ const originalPattern = String(args.pattern || "").trim();
37
+ if (!originalPattern) {
38
38
  return { content: "Error: glob pattern is required", isError: true, status: "command_error" };
39
39
  }
40
+ const normalized = normalizeGlobSearch(requestedRoot, originalPattern);
41
+ if (normalized.error) {
42
+ return normalized.error;
43
+ }
44
+ const { root, pattern, normalizedPattern } = normalized;
40
45
  if (isSensitivePath(root)) {
41
46
  return {
42
47
  content: `Error: Glob blocked for sensitive credential storage: ${root}`,
@@ -45,7 +50,9 @@ export function createGlobTool(cwd) {
45
50
  metadata: {
46
51
  kind: "security",
47
52
  path: root,
48
- pattern,
53
+ pattern: normalizedPattern,
54
+ originalPattern,
55
+ normalizedPattern,
49
56
  reason: "Sensitive credential storage is not searchable from general-purpose tasks.",
50
57
  },
51
58
  };
@@ -74,11 +81,13 @@ export function createGlobTool(cwd) {
74
81
  metadata: {
75
82
  kind: "search",
76
83
  path: root,
77
- pattern,
84
+ pattern: normalizedPattern,
85
+ originalPattern,
86
+ normalizedPattern,
78
87
  matches: 0,
79
88
  truncated: false,
80
- searchSignature: `glob:${root}:${pattern}`,
81
- searchFamily: `glob:${pattern}`,
89
+ searchSignature: `glob:${root}:${normalizedPattern}`,
90
+ searchFamily: `glob:${normalizedPattern}`,
82
91
  paths: [],
83
92
  },
84
93
  };
@@ -89,17 +98,70 @@ export function createGlobTool(cwd) {
89
98
  metadata: {
90
99
  kind: "search",
91
100
  path: root,
92
- pattern,
101
+ pattern: normalizedPattern,
102
+ originalPattern,
103
+ normalizedPattern,
93
104
  matches: matches.length,
94
105
  truncated: wasTruncated,
95
- searchSignature: `glob:${root}:${pattern}`,
96
- searchFamily: `glob:${pattern}`,
106
+ searchSignature: `glob:${root}:${normalizedPattern}`,
107
+ searchFamily: `glob:${normalizedPattern}`,
97
108
  paths: absoluteMatches,
98
109
  },
99
110
  };
100
111
  },
101
112
  };
102
113
  }
114
+ function normalizeGlobSearch(requestedRoot, originalPattern) {
115
+ const expandedPattern = expandGlobPatternHome(originalPattern);
116
+ const scan = picomatch.scan(expandedPattern);
117
+ const prefix = scan.prefix ?? "";
118
+ if (!isAbsolute(scan.base)) {
119
+ if (escapesSearchRoot(scan.base)) {
120
+ return {
121
+ error: {
122
+ content: `Error: Glob pattern must stay within the search path: ${originalPattern}`,
123
+ isError: true,
124
+ status: "command_error",
125
+ metadata: {
126
+ kind: "search",
127
+ path: requestedRoot,
128
+ pattern: originalPattern,
129
+ originalPattern,
130
+ normalizedPattern: originalPattern,
131
+ reason: "pattern_outside_search_path",
132
+ },
133
+ },
134
+ };
135
+ }
136
+ return { root: requestedRoot, pattern: originalPattern, normalizedPattern: originalPattern };
137
+ }
138
+ const absoluteBase = resolve(scan.base);
139
+ const patternRoot = scan.isGlob ? absoluteBase : dirname(absoluteBase);
140
+ const patternBody = scan.isGlob ? scan.glob : basename(absoluteBase);
141
+ const normalizedRoot = isWithinSearchRoot(requestedRoot, patternRoot) ? requestedRoot : patternRoot;
142
+ const relativeBase = toPosix(relative(normalizedRoot, patternRoot));
143
+ const normalizedBody = [relativeBase, patternBody].filter(Boolean).join("/");
144
+ const normalizedPattern = `${prefix}${normalizedBody}`;
145
+ return {
146
+ root: normalizedRoot,
147
+ pattern: normalizedPattern,
148
+ normalizedPattern,
149
+ };
150
+ }
151
+ function expandGlobPatternHome(pattern) {
152
+ if (pattern.startsWith("!")) {
153
+ return `!${expandHomePath(pattern.slice(1))}`;
154
+ }
155
+ return expandHomePath(pattern);
156
+ }
157
+ function escapesSearchRoot(base) {
158
+ const normalized = toPosix(base);
159
+ return normalized === ".." || normalized.startsWith("../");
160
+ }
161
+ function isWithinSearchRoot(root, target) {
162
+ const rel = relative(root, target);
163
+ return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
164
+ }
103
165
  async function walk(root, dir, matcher, files, truncated, abortSignal) {
104
166
  if (abortSignal?.aborted || files.length >= MAX_RESULTS) {
105
167
  truncated.value = true;
@@ -115,6 +177,9 @@ async function walk(root, dir, matcher, files, truncated, abortSignal) {
115
177
  continue;
116
178
  }
117
179
  const absolute = resolve(dir, entry.name);
180
+ if (isSensitivePath(absolute)) {
181
+ continue;
182
+ }
118
183
  const rel = toPosix(relative(root, absolute));
119
184
  if (entry.isDirectory()) {
120
185
  await walk(root, absolute, matcher, files, truncated, abortSignal);
@@ -6,7 +6,7 @@ export { createBashTool } from "./bash.js";
6
6
  export { createManagedServerTools } from "./server.js";
7
7
  export { createWriteTool } from "./write.js";
8
8
  export { createEditTool } from "./edit.js";
9
- export { createApplyPatchTool } from "./apply-patch.js";
9
+ export { buildToolPromptOptions } from "./prompt-metadata.js";
10
10
  export { createGlobTool } from "./glob.js";
11
11
  export { createGrepTool } from "./grep.js";
12
12
  export { createLspTool } from "./lsp.js";
@@ -6,7 +6,7 @@ export { createBashTool } from "./bash.js";
6
6
  export { createManagedServerTools } from "./server.js";
7
7
  export { createWriteTool } from "./write.js";
8
8
  export { createEditTool } from "./edit.js";
9
- export { createApplyPatchTool } from "./apply-patch.js";
9
+ export { buildToolPromptOptions } from "./prompt-metadata.js";
10
10
  export { createGlobTool } from "./glob.js";
11
11
  export { createGrepTool } from "./grep.js";
12
12
  export { createLspTool } from "./lsp.js";
@@ -23,7 +23,6 @@ export { createMemoryReadSummaryTool, createMemorySearchTool } from "./memory.js
23
23
  import { createBashTool } from "./bash.js";
24
24
  import { createManagedServerTools } from "./server.js";
25
25
  import { createEditTool } from "./edit.js";
26
- import { createApplyPatchTool } from "./apply-patch.js";
27
26
  import { createExitPlanModeTool } from "./exit-plan-mode.js";
28
27
  import { createGlobTool } from "./glob.js";
29
28
  import { createGrepTool } from "./grep.js";
@@ -51,7 +50,6 @@ export function createAllTools(cwd, skillRegistry, options = {}) {
51
50
  ...createManagedServerTools(cwd, approval),
52
51
  createWriteTool(cwd, {}, approval, lsp, fileState),
53
52
  createEditTool(cwd, approval, lsp, fileState),
54
- createApplyPatchTool(cwd, approval, lsp, fileState),
55
53
  createGlobTool(cwd),
56
54
  createGrepTool(cwd),
57
55
  createLspTool(cwd, lsp, approval),
@@ -0,0 +1,3 @@
1
+ import type { SystemPromptOptions } from "../system-prompt.js";
2
+ import type { ToolRegistryEntry } from "../types.js";
3
+ export declare function buildToolPromptOptions(tools: ToolRegistryEntry[]): Pick<SystemPromptOptions, "tools" | "toolSnippets" | "guidelines">;
@@ -0,0 +1,17 @@
1
+ export function buildToolPromptOptions(tools) {
2
+ const toolSnippets = {};
3
+ const guidelines = [];
4
+ for (const tool of tools) {
5
+ if (tool.promptSnippet) {
6
+ toolSnippets[tool.name] = tool.promptSnippet;
7
+ }
8
+ for (const guideline of tool.promptGuidelines ?? []) {
9
+ guidelines.push(guideline);
10
+ }
11
+ }
12
+ return {
13
+ tools: tools.map((tool) => tool.name),
14
+ toolSnippets,
15
+ guidelines,
16
+ };
17
+ }
@@ -9,12 +9,25 @@ import { formatDiagnosticBlocks } from "../lsp/index.js";
9
9
  import { isWithinWorkspace } from "./file-state.js";
10
10
  import { withFileMutationQueue } from "./file-mutation-queue.js";
11
11
  import { resolveToolPath } from "./path-utils.js";
12
+ function prepareWriteArguments(input) {
13
+ if (!input || typeof input !== "object")
14
+ return input;
15
+ const args = { ...input };
16
+ if (typeof args.file_path === "string" && typeof args.path !== "string") {
17
+ args.path = args.file_path;
18
+ }
19
+ return args;
20
+ }
12
21
  export function createWriteTool(cwd, _options = {}, approval, lsp, fileState) {
13
22
  return {
14
23
  name: "write",
15
24
  effect: "write_direct",
16
25
  requiresApproval: true,
17
26
  description: "Write content to a file. Creates parent directories as needed. If the file already exists, this replaces the full file; use edit for small targeted changes.",
27
+ promptSnippet: "Create new files or intentionally rewrite complete files",
28
+ promptGuidelines: [
29
+ "Use write only for new files, generated files, or intentional complete rewrites. Use edit for targeted changes to existing files.",
30
+ ],
18
31
  parameters: {
19
32
  type: "object",
20
33
  properties: {
@@ -23,6 +36,7 @@ export function createWriteTool(cwd, _options = {}, approval, lsp, fileState) {
23
36
  },
24
37
  required: ["path", "content"],
25
38
  },
39
+ prepareArguments: prepareWriteArguments,
26
40
  async execute(args) {
27
41
  const filePath = resolveToolPath(cwd, args.path);
28
42
  if (!isWithinWorkspace(cwd, filePath)) {
@@ -0,0 +1,10 @@
1
+ export declare const LONG_PASTE_CHAR_THRESHOLD = 1000;
2
+ export declare const LONG_PASTE_LINE_THRESHOLD = 20;
3
+ export interface PastedContentReference {
4
+ marker: string;
5
+ content: string;
6
+ }
7
+ export declare function countTextLines(text: string): number;
8
+ export declare function shouldCollapsePastedContent(text: string): boolean;
9
+ export declare function createPastedContentMarker(content: string, index?: number): string;
10
+ export declare function expandPastedContentMarkers(displayText: string, references: PastedContentReference[]): string;
@@ -0,0 +1,45 @@
1
+ export const LONG_PASTE_CHAR_THRESHOLD = 1000;
2
+ export const LONG_PASTE_LINE_THRESHOLD = 20;
3
+ export function countTextLines(text) {
4
+ return text.length === 0 ? 0 : text.split(/\r?\n/).length;
5
+ }
6
+ export function shouldCollapsePastedContent(text) {
7
+ if (text.length >= LONG_PASTE_CHAR_THRESHOLD)
8
+ return true;
9
+ return countTextLines(text) >= LONG_PASTE_LINE_THRESHOLD;
10
+ }
11
+ export function createPastedContentMarker(content, index = 1) {
12
+ const safeIndex = Math.max(1, Math.floor(index));
13
+ const lineCount = countTextLines(content);
14
+ const size = lineCount > 1
15
+ ? `${lineCount} ${lineCount === 1 ? "line" : "lines"}`
16
+ : `${content.length} ${content.length === 1 ? "char" : "chars"}`;
17
+ return `[Pasted text #${safeIndex} +${size}]`;
18
+ }
19
+ export function expandPastedContentMarkers(displayText, references) {
20
+ if (references.length === 0 || displayText.length === 0)
21
+ return displayText;
22
+ let expanded = "";
23
+ let index = 0;
24
+ const used = new Set();
25
+ while (index < displayText.length) {
26
+ let matched = -1;
27
+ for (let i = 0; i < references.length; i++) {
28
+ const ref = references[i];
29
+ if (!used.has(i) && displayText.startsWith(ref.marker, index)) {
30
+ matched = i;
31
+ break;
32
+ }
33
+ }
34
+ if (matched >= 0) {
35
+ const ref = references[matched];
36
+ expanded += ref.content;
37
+ index += ref.marker.length;
38
+ used.add(matched);
39
+ continue;
40
+ }
41
+ expanded += displayText[index];
42
+ index += 1;
43
+ }
44
+ return expanded;
45
+ }
package/dist/tui/run.js CHANGED
@@ -480,6 +480,7 @@ function OpenTuiApp(props) {
480
480
  completionTokens: 0,
481
481
  promptCacheHitTokens: 0,
482
482
  promptCacheMissTokens: 0,
483
+ cacheCreationTokens: 0,
483
484
  reasoningTokens: 0,
484
485
  turns: 0,
485
486
  });
@@ -602,6 +603,7 @@ function OpenTuiApp(props) {
602
603
  let sidebarGaugeText;
603
604
  let sidebarGaugeLabelText;
604
605
  let sidebarUsageText;
606
+ let sidebarCacheText;
605
607
  let sidebarReasoningText;
606
608
  let sidebarCostText;
607
609
  let sidebarLspSummaryText;
@@ -956,6 +958,7 @@ function OpenTuiApp(props) {
956
958
  setSidebarText(sidebarUsageText, context.turns > 0
957
959
  ? `${formatCompactNumber(context.promptTokens)} in · ${formatCompactNumber(context.completionTokens)} out`
958
960
  : "usage pending");
961
+ setSidebarText(sidebarCacheText, context.cacheText);
959
962
  setSidebarText(sidebarReasoningText, context.reasoningTokens > 0
960
963
  ? `${formatCompactNumber(context.reasoningTokens)} reasoning`
961
964
  : "");
@@ -5341,6 +5344,7 @@ function OpenTuiApp(props) {
5341
5344
  promptCacheHitTokens: current.promptCacheHitTokens + (event.usage.promptCacheHitTokens ?? 0),
5342
5345
  promptCacheMissTokens: current.promptCacheMissTokens + (event.usage.promptCacheMissTokens
5343
5346
  ?? (event.usage.promptCacheHitTokens === undefined ? event.usage.promptTokens : 0)),
5347
+ cacheCreationTokens: current.cacheCreationTokens + (event.usage.cacheCreationTokens ?? 0),
5344
5348
  reasoningTokens: current.reasoningTokens + (event.usage.reasoningTokens ?? 0),
5345
5349
  turns: current.turns + 1,
5346
5350
  }));
@@ -6368,6 +6372,13 @@ function OpenTuiApp(props) {
6368
6372
  : "usage pending";
6369
6373
  },
6370
6374
  }),
6375
+ h("text", {
6376
+ fg: theme.textMuted,
6377
+ ref: (ref) => {
6378
+ sidebarCacheText = ref;
6379
+ ref.content = context.cacheText;
6380
+ },
6381
+ }),
6371
6382
  h("text", {
6372
6383
  fg: theme.textMuted,
6373
6384
  ref: (ref) => {
@@ -6573,16 +6584,28 @@ function OpenTuiApp(props) {
6573
6584
  completionTokens: usage.completionTokens,
6574
6585
  promptCacheHitTokens: usage.promptCacheHitTokens,
6575
6586
  promptCacheMissTokens: usage.promptCacheMissTokens,
6587
+ cacheCreationTokens: usage.cacheCreationTokens,
6576
6588
  reasoningTokens: usage.reasoningTokens,
6577
6589
  totalTokens: usage.promptTokens + usage.completionTokens,
6578
6590
  };
6579
6591
  const cost = providerId && modelId ? calculateUsageCost(providerId, modelId, tokenUsage) : undefined;
6592
+ const cacheReadTokens = usage.promptCacheHitTokens;
6593
+ const cacheCreateTokens = usage.cacheCreationTokens;
6594
+ const cacheMissTokens = Math.max(0, usage.promptCacheMissTokens - cacheCreateTokens);
6595
+ const cacheObservedTokens = cacheReadTokens + cacheCreateTokens + cacheMissTokens;
6596
+ const cacheHitRate = cacheObservedTokens > 0
6597
+ ? Math.round((cacheReadTokens / cacheObservedTokens) * 100)
6598
+ : 0;
6599
+ const cacheText = cacheObservedTokens > 0
6600
+ ? `cache ${formatCompactNumber(cacheReadTokens)} read · ${formatCompactNumber(cacheCreateTokens)} create · ${formatCompactNumber(cacheMissTokens)} miss · ${cacheHitRate}% hit`
6601
+ : "";
6580
6602
  return {
6581
6603
  tokens: contextTokens,
6582
6604
  percent: contextPercent,
6583
6605
  remainingTokens,
6584
6606
  promptTokens: usage.promptTokens,
6585
6607
  completionTokens: usage.completionTokens,
6608
+ cacheText,
6586
6609
  reasoningTokens: usage.reasoningTokens,
6587
6610
  turns: usage.turns,
6588
6611
  costText: cost ? `${formatCurrency(cost.cost, cost.currency)} spent${cost.estimated ? " est." : ""}` : "cost unavailable",
@@ -501,6 +501,7 @@ export function App({ agent, args, sessionManager, createProvider, registry, ski
501
501
  thinkingLevel: overrides?.thinkingLevel ?? agent.thinking,
502
502
  mode: overrides?.mode ?? agent.mode,
503
503
  workingDir: args.cwd,
504
+ ...agent.getSystemPromptToolOptions(),
504
505
  }));
505
506
  }, [agent, args.cwd, safeRegistry, safeSkillRegistry]);
506
507
  useInput((input, key) => {
@@ -614,6 +615,7 @@ export function App({ agent, args, sessionManager, createProvider, registry, ski
614
615
  configuredModelId: model,
615
616
  thinkingLevel: agent.thinking,
616
617
  workingDir: args.cwd,
618
+ ...agent.getSystemPromptToolOptions(),
617
619
  }));
618
620
  userConfig.pushRecentModel(model);
619
621
  setThinkingLevel(agent.thinking);
@@ -1,5 +1,6 @@
1
1
  import type { SkillRegistry } from "../skills/registry.js";
2
2
  import { type ImageAttachment } from "./image-paste.js";
3
+ export { createPastedContentMarker, expandPastedContentMarkers, shouldCollapsePastedContent, type PastedContentReference, } from "../tui/paste-placeholder.js";
3
4
  export interface SubmitPayload {
4
5
  /** Fully-expanded text sent to the agent. */
5
6
  text: string;
@@ -19,10 +20,6 @@ interface InputBoxProps {
19
20
  terminalColumns: number;
20
21
  cwd: string;
21
22
  }
22
- export interface PastedContentReference {
23
- marker: string;
24
- content: string;
25
- }
26
23
  export declare function needsCursorRowCompensation(nextOutputHeight: number, viewportRows: number, previousOutputHeight: number | null): boolean;
27
24
  export declare function resolveCursorRowCompensation(input: {
28
25
  sameRenderedFrame: boolean;
@@ -58,8 +55,4 @@ export declare function insertNewlineAtCursor(text: string, cursor: number): {
58
55
  text: string;
59
56
  cursor: number;
60
57
  };
61
- export declare function shouldCollapsePastedContent(text: string): boolean;
62
- export declare function createPastedContentMarker(content: string): string;
63
- export declare function expandPastedContentMarkers(displayText: string, references: PastedContentReference[]): string;
64
58
  export declare function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch, draftText, draftEpoch, onDraftApplied, skillRegistry, terminalColumns, cwd, }: InputBoxProps): import("react/jsx-runtime").JSX.Element;
65
- export {};
@@ -9,13 +9,13 @@ import { filterFileSuggestions, findAtContext, listProjectFiles } from "./file-m
9
9
  import { ingestClipboardImage, ingestImagePath, isImageFilePath, isScreenshotTempPath, splitPastedPaths, } from "./image-paste.js";
10
10
  import { appendHistoryEntry, loadHistorySync, pushHistoryEntry, stepHistory, } from "./input-history.js";
11
11
  import { stripTerminalMouseSequences } from "./terminal-mouse.js";
12
+ export { createPastedContentMarker, expandPastedContentMarkers, shouldCollapsePastedContent, } from "../tui/paste-placeholder.js";
13
+ import { createPastedContentMarker, expandPastedContentMarkers, shouldCollapsePastedContent, } from "../tui/paste-placeholder.js";
12
14
  const MIN_VISIBLE_LINES = 3;
13
15
  const MAX_VISIBLE_LINES = 6;
14
16
  const PADDING_X = 1;
15
17
  const PROMPT = " > ";
16
18
  const MAX_VISIBLE_SUGGESTIONS = 8;
17
- const LONG_PASTE_CHAR_THRESHOLD = 1000;
18
- const LONG_PASTE_LINE_THRESHOLD = 20;
19
19
  export function needsCursorRowCompensation(nextOutputHeight, viewportRows, previousOutputHeight) {
20
20
  const hadPreviousFrame = previousOutputHeight !== null && previousOutputHeight > 0;
21
21
  const isFullscreen = nextOutputHeight >= viewportRows;
@@ -148,41 +148,6 @@ export function insertNewlineAtCursor(text, cursor) {
148
148
  cursor: clampedCursor + 1,
149
149
  };
150
150
  }
151
- export function shouldCollapsePastedContent(text) {
152
- if (text.length >= LONG_PASTE_CHAR_THRESHOLD)
153
- return true;
154
- return text.split("\n").length >= LONG_PASTE_LINE_THRESHOLD;
155
- }
156
- export function createPastedContentMarker(content) {
157
- return `[Pasted Content ${content.length} chars]`;
158
- }
159
- export function expandPastedContentMarkers(displayText, references) {
160
- if (references.length === 0 || displayText.length === 0)
161
- return displayText;
162
- let expanded = "";
163
- let index = 0;
164
- const used = new Set();
165
- while (index < displayText.length) {
166
- let matched = -1;
167
- for (let i = 0; i < references.length; i++) {
168
- const ref = references[i];
169
- if (!used.has(i) && displayText.startsWith(ref.marker, index)) {
170
- matched = i;
171
- break;
172
- }
173
- }
174
- if (matched >= 0) {
175
- const ref = references[matched];
176
- expanded += ref.content;
177
- index += ref.marker.length;
178
- used.add(matched);
179
- continue;
180
- }
181
- expanded += displayText[index];
182
- index += 1;
183
- }
184
- return expanded;
185
- }
186
151
  export function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch = 0, draftText, draftEpoch = 0, onDraftApplied, skillRegistry, terminalColumns, cwd, }) {
187
152
  const theme = useTheme();
188
153
  const width = terminalColumns;
@@ -196,6 +161,7 @@ export function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch =
196
161
  const [historyIndex, setHistoryIndex] = useState(null);
197
162
  const historyDraftRef = useRef("");
198
163
  const loadingFilesRef = useRef(false);
164
+ const nextPastedContentIndexRef = useRef(1);
199
165
  // Paste and the keystrokes that follow can arrive inside the same stdin chunk
200
166
  // and dispatch within one discreteUpdates batch. If the Enter that a user
201
167
  // typed after a paste fires before React commits the paste-driven setState,
@@ -327,7 +293,7 @@ export function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch =
327
293
  if (imageTokens.length === 0) {
328
294
  // Plain text paste — insert into the input at the cursor.
329
295
  if (shouldCollapsePastedContent(clean)) {
330
- const marker = createPastedContentMarker(clean);
296
+ const marker = createPastedContentMarker(clean, nextPastedContentIndexRef.current++);
331
297
  setPastedContentRefs((prev) => [...prev, { marker, content: clean }]);
332
298
  insertTextAtCursor(marker);
333
299
  }
@@ -409,6 +375,7 @@ export function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch =
409
375
  setSelectedIndex(0);
410
376
  setAttachments([]);
411
377
  setPastedContentRefs([]);
378
+ nextPastedContentIndexRef.current = 1;
412
379
  setHistoryIndex(null);
413
380
  historyDraftRef.current = "";
414
381
  };
@@ -560,6 +527,7 @@ export function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch =
560
527
  historyDraftRef.current = result.draft;
561
528
  setSelectedIndex(0);
562
529
  setPastedContentRefs([]);
530
+ nextPastedContentIndexRef.current = 1;
563
531
  }
564
532
  return;
565
533
  }
@@ -576,6 +544,7 @@ export function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch =
576
544
  historyDraftRef.current = result.draft;
577
545
  setSelectedIndex(0);
578
546
  setPastedContentRefs([]);
547
+ nextPastedContentIndexRef.current = 1;
579
548
  }
580
549
  return;
581
550
  }
@@ -627,6 +596,7 @@ export function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch =
627
596
  setCursor(draftText.length);
628
597
  setSelectedIndex(0);
629
598
  setPastedContentRefs([]);
599
+ nextPastedContentIndexRef.current = 1;
630
600
  setHistoryIndex(null);
631
601
  historyDraftRef.current = "";
632
602
  onDraftApplied?.();
@@ -523,6 +523,7 @@ export function App({ agent, args, sessionManager, createProvider, registry, ski
523
523
  thinkingLevel: overrides?.thinkingLevel ?? agent.thinking,
524
524
  mode: overrides?.mode ?? agent.mode,
525
525
  workingDir: args.cwd,
526
+ ...agent.getSystemPromptToolOptions(),
526
527
  }));
527
528
  }, [agent, args.cwd, safeRegistry, safeSkillRegistry]);
528
529
  useKeyboard((key) => {
@@ -636,6 +637,7 @@ export function App({ agent, args, sessionManager, createProvider, registry, ski
636
637
  configuredModelId: model,
637
638
  thinkingLevel: agent.thinking,
638
639
  workingDir: args.cwd,
640
+ ...agent.getSystemPromptToolOptions(),
639
641
  }));
640
642
  userConfig.pushRecentModel(model);
641
643
  setThinkingLevel(agent.thinking);
@@ -8,6 +8,7 @@
8
8
  import React from "react";
9
9
  import type { SkillRegistry } from "../skills/registry.js";
10
10
  import { type ImageAttachment } from "./image-paste.js";
11
+ export { createPastedContentMarker, shouldCollapsePastedContent, } from "../tui/paste-placeholder.js";
11
12
  export interface SubmitPayload {
12
13
  text: string;
13
14
  displayText?: string;
@@ -25,10 +26,7 @@ interface InputBoxProps {
25
26
  terminalColumns: number;
26
27
  cwd: string;
27
28
  }
28
- export declare function shouldCollapsePastedContent(text: string): boolean;
29
- export declare function createPastedContentMarker(content: string): string;
30
29
  export declare function isCtrlCInput(input: string, key: {
31
30
  ctrl?: boolean;
32
31
  }): boolean;
33
32
  export declare function InputBox({ onSubmit, onPasteNotice, disabled, cursorResetEpoch, draftText, draftEpoch, onDraftApplied, skillRegistry, terminalColumns, cwd, }: InputBoxProps): React.ReactNode;
34
- export {};