@bubblebrain-ai/bubble 0.0.7 → 0.0.9

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 (119) hide show
  1. package/dist/agent/categories.d.ts +34 -0
  2. package/dist/agent/categories.js +98 -0
  3. package/dist/agent/profiles.d.ts +4 -0
  4. package/dist/agent/profiles.js +2 -3
  5. package/dist/agent/subagent-control.d.ts +5 -0
  6. package/dist/agent/subagent-control.js +4 -0
  7. package/dist/agent/subagent-lifecycle-reminder.d.ts +3 -0
  8. package/dist/agent/subagent-lifecycle-reminder.js +102 -0
  9. package/dist/agent/subagent-route-format.d.ts +8 -0
  10. package/dist/agent/subagent-route-format.js +18 -0
  11. package/dist/agent/subtask-policy.d.ts +0 -1
  12. package/dist/agent/subtask-policy.js +0 -4
  13. package/dist/agent.d.ts +18 -0
  14. package/dist/agent.js +188 -16
  15. package/dist/config.d.ts +23 -3
  16. package/dist/config.js +59 -6
  17. package/dist/context/budget.d.ts +3 -2
  18. package/dist/context/budget.js +29 -15
  19. package/dist/context/compact.d.ts +23 -0
  20. package/dist/context/compact.js +129 -0
  21. package/dist/context/llm-compactor.d.ts +19 -0
  22. package/dist/context/llm-compactor.js +200 -0
  23. package/dist/context/projector.js +28 -12
  24. package/dist/context/token-estimator.d.ts +14 -0
  25. package/dist/context/token-estimator.js +106 -0
  26. package/dist/context/tool-output-truncate.d.ts +8 -0
  27. package/dist/context/tool-output-truncate.js +59 -0
  28. package/dist/context/usage.d.ts +34 -0
  29. package/dist/context/usage.js +213 -0
  30. package/dist/diff-stats.d.ts +5 -0
  31. package/dist/diff-stats.js +21 -0
  32. package/dist/main.js +68 -7
  33. package/dist/mcp/transports.d.ts +1 -0
  34. package/dist/mcp/transports.js +8 -0
  35. package/dist/model-catalog.d.ts +9 -0
  36. package/dist/model-catalog.js +17 -1
  37. package/dist/orchestrator/default-hooks.js +24 -18
  38. package/dist/prompt/compose.js +2 -1
  39. package/dist/prompt/provider-prompts/kimi.js +3 -1
  40. package/dist/provider-openai-codex.d.ts +13 -2
  41. package/dist/provider-openai-codex.js +81 -32
  42. package/dist/provider-registry.js +22 -6
  43. package/dist/provider-transform.d.ts +3 -1
  44. package/dist/provider-transform.js +15 -0
  45. package/dist/provider.d.ts +4 -1
  46. package/dist/provider.js +89 -4
  47. package/dist/reasoning-debug.d.ts +7 -0
  48. package/dist/reasoning-debug.js +30 -0
  49. package/dist/session-log.js +13 -2
  50. package/dist/session-types.d.ts +1 -1
  51. package/dist/slash-commands/commands.js +60 -2
  52. package/dist/slash-commands/types.d.ts +7 -0
  53. package/dist/tools/agent-lifecycle.js +22 -4
  54. package/dist/tools/edit.js +7 -2
  55. package/dist/tools/file-state.d.ts +19 -0
  56. package/dist/tools/file-state.js +15 -0
  57. package/dist/tools/glob.js +2 -1
  58. package/dist/tools/grep.js +2 -2
  59. package/dist/tools/lsp.js +2 -2
  60. package/dist/tools/path-utils.d.ts +2 -0
  61. package/dist/tools/path-utils.js +16 -0
  62. package/dist/tools/read.d.ts +1 -1
  63. package/dist/tools/read.js +207 -14
  64. package/dist/tools/write.js +3 -2
  65. package/dist/tui/escape-confirmation.d.ts +15 -0
  66. package/dist/tui/escape-confirmation.js +30 -0
  67. package/dist/tui/run.js +93 -23
  68. package/dist/tui-ink/app.d.ts +52 -0
  69. package/dist/tui-ink/app.js +1129 -0
  70. package/dist/tui-ink/approval/approval-dialog.d.ts +13 -0
  71. package/dist/tui-ink/approval/approval-dialog.js +132 -0
  72. package/dist/tui-ink/approval/diff-view.d.ts +7 -0
  73. package/dist/tui-ink/approval/diff-view.js +44 -0
  74. package/dist/tui-ink/approval/select.d.ts +35 -0
  75. package/dist/tui-ink/approval/select.js +88 -0
  76. package/dist/tui-ink/code-highlight.d.ts +8 -0
  77. package/dist/tui-ink/code-highlight.js +122 -0
  78. package/dist/tui-ink/detect-theme.d.ts +19 -0
  79. package/dist/tui-ink/detect-theme.js +123 -0
  80. package/dist/tui-ink/display-history.d.ts +38 -0
  81. package/dist/tui-ink/display-history.js +130 -0
  82. package/dist/tui-ink/edit-diff.d.ts +11 -0
  83. package/dist/tui-ink/edit-diff.js +52 -0
  84. package/dist/tui-ink/file-mentions.d.ts +29 -0
  85. package/dist/tui-ink/file-mentions.js +174 -0
  86. package/dist/tui-ink/footer.d.ts +19 -0
  87. package/dist/tui-ink/footer.js +45 -0
  88. package/dist/tui-ink/image-paste.d.ts +54 -0
  89. package/dist/tui-ink/image-paste.js +288 -0
  90. package/dist/tui-ink/input-box.d.ts +41 -0
  91. package/dist/tui-ink/input-box.js +694 -0
  92. package/dist/tui-ink/input-history.d.ts +16 -0
  93. package/dist/tui-ink/input-history.js +81 -0
  94. package/dist/tui-ink/markdown.d.ts +38 -0
  95. package/dist/tui-ink/markdown.js +394 -0
  96. package/dist/tui-ink/message-list.d.ts +33 -0
  97. package/dist/tui-ink/message-list.js +667 -0
  98. package/dist/tui-ink/model-picker.d.ts +43 -0
  99. package/dist/tui-ink/model-picker.js +331 -0
  100. package/dist/tui-ink/plan-confirm.d.ts +7 -0
  101. package/dist/tui-ink/plan-confirm.js +105 -0
  102. package/dist/tui-ink/question-dialog.d.ts +8 -0
  103. package/dist/tui-ink/question-dialog.js +99 -0
  104. package/dist/tui-ink/recent-activity.d.ts +8 -0
  105. package/dist/tui-ink/recent-activity.js +71 -0
  106. package/dist/tui-ink/run.d.ts +37 -0
  107. package/dist/tui-ink/run.js +53 -0
  108. package/dist/tui-ink/theme.d.ts +66 -0
  109. package/dist/tui-ink/theme.js +115 -0
  110. package/dist/tui-ink/todos.d.ts +7 -0
  111. package/dist/tui-ink/todos.js +46 -0
  112. package/dist/tui-ink/trace-groups.d.ts +27 -0
  113. package/dist/tui-ink/trace-groups.js +389 -0
  114. package/dist/tui-ink/use-terminal-size.d.ts +4 -0
  115. package/dist/tui-ink/use-terminal-size.js +21 -0
  116. package/dist/tui-ink/welcome.d.ts +18 -0
  117. package/dist/tui-ink/welcome.js +138 -0
  118. package/dist/types.d.ts +10 -0
  119. package/package.json +7 -1
@@ -0,0 +1,288 @@
1
+ /**
2
+ * Image paste utilities: path detection, file reading, clipboard access, and size-capping.
3
+ *
4
+ * Terminals don't forward image bytes to stdin. Paths arrive as text when users
5
+ * drag files in; Cmd+V of an image produces an empty paste (we probe the
6
+ * clipboard). macOS screenshot shortcut (Cmd+Shift+Ctrl+4) writes to both a
7
+ * TemporaryItems path and the clipboard — the path often gets cleaned up before
8
+ * we can read it, so we fall back to the clipboard.
9
+ */
10
+ import { execFile } from "node:child_process";
11
+ import fs from "node:fs/promises";
12
+ import os from "node:os";
13
+ import path from "node:path";
14
+ import { promisify } from "node:util";
15
+ const execFileAsync = promisify(execFile);
16
+ const IMAGE_EXT = /\.(png|jpe?g|gif|webp|bmp)$/i;
17
+ // Anthropic/OpenAI image uploads cap at ~5MB base64. We target a bit below so
18
+ // the base64 inflation (4/3) doesn't push us over.
19
+ const MAX_BASE64_BYTES = 5 * 1024 * 1024;
20
+ const RESIZE_TRIGGER_BYTES = Math.floor(MAX_BASE64_BYTES * 0.95);
21
+ // Target max dimension for auto-resize.
22
+ const RESIZE_MAX_DIM = 2048;
23
+ export function isImageFilePath(raw) {
24
+ const s = raw.trim();
25
+ if (!s)
26
+ return false;
27
+ if (!IMAGE_EXT.test(s))
28
+ return false;
29
+ // Require an absolute or home-relative path. Pasted arbitrary text shouldn't
30
+ // be treated as a path.
31
+ return path.isAbsolute(s) || s.startsWith("~") || /^[A-Za-z]:\\/.test(s);
32
+ }
33
+ /**
34
+ * Split a pasted blob into candidate path tokens.
35
+ *
36
+ * Multi-drag from Finder delivers a mix of newline- and space-separated
37
+ * absolute paths. Spaces inside a single path are escaped (`\ `) — we split
38
+ * only on a space that is followed by the start of a new absolute path.
39
+ */
40
+ export function splitPastedPaths(pasted) {
41
+ const out = [];
42
+ for (const line of pasted.split(/\r?\n/)) {
43
+ for (const piece of line.split(/ (?=\/|[A-Za-z]:\\)/)) {
44
+ const t = piece.trim();
45
+ if (t)
46
+ out.push(t);
47
+ }
48
+ }
49
+ return out;
50
+ }
51
+ function mediaTypeFromExt(p) {
52
+ const ext = path.extname(p).toLowerCase();
53
+ if (ext === ".jpg" || ext === ".jpeg")
54
+ return "image/jpeg";
55
+ if (ext === ".gif")
56
+ return "image/gif";
57
+ if (ext === ".webp")
58
+ return "image/webp";
59
+ if (ext === ".bmp")
60
+ return "image/bmp";
61
+ return "image/png";
62
+ }
63
+ function resolveHome(p) {
64
+ if (p.startsWith("~/") || p === "~") {
65
+ return path.join(os.homedir(), p.slice(1));
66
+ }
67
+ return p;
68
+ }
69
+ function unescapeShell(p) {
70
+ return p.replace(/\\ /g, " ");
71
+ }
72
+ function attachmentFromBuffer(buffer, mediaType, meta = {}) {
73
+ const base64 = buffer.toString("base64");
74
+ return {
75
+ base64,
76
+ mediaType,
77
+ bytes: buffer.length,
78
+ dataUrl: `data:${mediaType};base64,${base64}`,
79
+ filename: meta.filename,
80
+ sourcePath: meta.sourcePath,
81
+ };
82
+ }
83
+ export async function readImageFromPath(rawPath) {
84
+ const resolved = resolveHome(unescapeShell(rawPath.trim()));
85
+ try {
86
+ const stat = await fs.stat(resolved);
87
+ if (!stat.isFile())
88
+ return null;
89
+ const buffer = await fs.readFile(resolved);
90
+ return attachmentFromBuffer(buffer, mediaTypeFromExt(resolved), {
91
+ filename: path.basename(resolved),
92
+ sourcePath: resolved,
93
+ });
94
+ }
95
+ catch {
96
+ return null;
97
+ }
98
+ }
99
+ /** macOS screenshot shortcut writes to these paths and they may be auto-cleaned. */
100
+ export function isScreenshotTempPath(s) {
101
+ return /\/TemporaryItems\/.*screencaptureui.*\/Screenshot/i.test(s);
102
+ }
103
+ export async function getImageFromClipboard() {
104
+ switch (process.platform) {
105
+ case "darwin":
106
+ return getClipboardImageDarwin();
107
+ case "linux":
108
+ return getClipboardImageLinux();
109
+ case "win32":
110
+ return getClipboardImageWindows();
111
+ default:
112
+ return null;
113
+ }
114
+ }
115
+ async function getClipboardImageDarwin() {
116
+ // Probe first — `as «class PNGf»` throws if clipboard has no image.
117
+ try {
118
+ await execFileAsync("osascript", ["-e", "the clipboard as «class PNGf»"], {
119
+ timeout: 5000,
120
+ });
121
+ }
122
+ catch {
123
+ return null;
124
+ }
125
+ const tmp = path.join(os.tmpdir(), `bubble_clip_${Date.now()}_${process.pid}.png`);
126
+ const script = `set png_data to (the clipboard as «class PNGf»)\n` +
127
+ `set fp to open for access POSIX file "${tmp}" with write permission\n` +
128
+ `write png_data to fp\n` +
129
+ `close access fp`;
130
+ try {
131
+ await execFileAsync("osascript", ["-e", script], { timeout: 5000 });
132
+ const buf = await fs.readFile(tmp);
133
+ return attachmentFromBuffer(buf, "image/png");
134
+ }
135
+ catch {
136
+ return null;
137
+ }
138
+ finally {
139
+ await fs.unlink(tmp).catch(() => undefined);
140
+ }
141
+ }
142
+ async function getClipboardImageLinux() {
143
+ const candidates = [
144
+ ["xclip", ["-selection", "clipboard", "-t", "image/png", "-o"]],
145
+ ["wl-paste", ["--type", "image/png"]],
146
+ ];
147
+ for (const [cmd, args] of candidates) {
148
+ try {
149
+ // encoding: "buffer" makes stdout a Buffer instead of a string so PNG
150
+ // bytes survive without UTF-8 mangling.
151
+ const result = await execFileAsync(cmd, args, {
152
+ timeout: 5000,
153
+ encoding: "buffer",
154
+ });
155
+ const buf = result.stdout;
156
+ if (buf && buf.length > 0) {
157
+ return attachmentFromBuffer(buf, "image/png");
158
+ }
159
+ }
160
+ catch {
161
+ continue;
162
+ }
163
+ }
164
+ return null;
165
+ }
166
+ async function getClipboardImageWindows() {
167
+ const tmp = path.join(os.tmpdir(), `bubble_clip_${Date.now()}_${process.pid}.png`);
168
+ const tmpPs = tmp.replace(/\\/g, "\\\\");
169
+ const script = `Add-Type -AssemblyName System.Drawing; ` +
170
+ `$img = Get-Clipboard -Format Image; ` +
171
+ `if ($img) { $img.Save('${tmpPs}', [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'OK' } ` +
172
+ `else { Write-Output 'NONE' }`;
173
+ try {
174
+ const result = await execFileAsync("powershell", ["-NoProfile", "-Command", script], { timeout: 5000 });
175
+ if (!String(result.stdout).includes("OK"))
176
+ return null;
177
+ const buf = await fs.readFile(tmp);
178
+ return attachmentFromBuffer(buf, "image/png");
179
+ }
180
+ catch {
181
+ return null;
182
+ }
183
+ finally {
184
+ await fs.unlink(tmp).catch(() => undefined);
185
+ }
186
+ }
187
+ async function which(cmd) {
188
+ try {
189
+ await execFileAsync(process.platform === "win32" ? "where" : "which", [cmd], {
190
+ timeout: 1500,
191
+ });
192
+ return true;
193
+ }
194
+ catch {
195
+ return false;
196
+ }
197
+ }
198
+ /**
199
+ * If the image is close to the API size cap, try to downscale it in place.
200
+ * Uses the OS-native tools that are typically available:
201
+ * - macOS: `sips` (always present)
202
+ * - linux: ImageMagick `convert` (if installed)
203
+ * Returns the original attachment if resize isn't needed or can't run.
204
+ */
205
+ export async function maybeResizeImage(att) {
206
+ if (att.base64.length < RESIZE_TRIGGER_BYTES)
207
+ return att;
208
+ const tmpDir = os.tmpdir();
209
+ const stamp = `${Date.now()}_${process.pid}`;
210
+ const inExt = path.extname(att.filename ?? att.sourcePath ?? `.png`).toLowerCase() || ".png";
211
+ const tmpIn = path.join(tmpDir, `bubble_img_in_${stamp}${inExt}`);
212
+ const tmpOut = path.join(tmpDir, `bubble_img_out_${stamp}.jpg`);
213
+ try {
214
+ await fs.writeFile(tmpIn, Buffer.from(att.base64, "base64"));
215
+ let ok = false;
216
+ if (process.platform === "darwin") {
217
+ try {
218
+ await execFileAsync("sips", ["-Z", String(RESIZE_MAX_DIM), "-s", "format", "jpeg", "-s", "formatOptions", "80", tmpIn, "--out", tmpOut], { timeout: 10000 });
219
+ ok = true;
220
+ }
221
+ catch {
222
+ ok = false;
223
+ }
224
+ }
225
+ else if (await which("convert")) {
226
+ try {
227
+ await execFileAsync("convert", [tmpIn, "-resize", `${RESIZE_MAX_DIM}x${RESIZE_MAX_DIM}>`, "-quality", "80", tmpOut], { timeout: 10000 });
228
+ ok = true;
229
+ }
230
+ catch {
231
+ ok = false;
232
+ }
233
+ }
234
+ if (!ok)
235
+ return att;
236
+ const resized = await fs.readFile(tmpOut);
237
+ if (resized.length >= att.bytes)
238
+ return att;
239
+ return attachmentFromBuffer(resized, "image/jpeg", {
240
+ filename: att.filename,
241
+ sourcePath: att.sourcePath,
242
+ });
243
+ }
244
+ catch {
245
+ return att;
246
+ }
247
+ finally {
248
+ await fs.unlink(tmpIn).catch(() => undefined);
249
+ await fs.unlink(tmpOut).catch(() => undefined);
250
+ }
251
+ }
252
+ export function validateImageSize(att) {
253
+ if (att.base64.length > MAX_BASE64_BYTES) {
254
+ const kb = Math.round(att.base64.length / 1024);
255
+ const max = Math.round(MAX_BASE64_BYTES / 1024);
256
+ const hint = process.platform === "darwin"
257
+ ? " (install/confirm `sips` on PATH to auto-resize)"
258
+ : process.platform === "linux"
259
+ ? " (install ImageMagick `convert` to auto-resize)"
260
+ : "";
261
+ return {
262
+ ok: false,
263
+ reason: `image base64 is ${kb}KB, exceeds ${max}KB API cap${hint}`,
264
+ };
265
+ }
266
+ return { ok: true };
267
+ }
268
+ /** End-to-end: given a file path, read -> resize-if-needed -> validate. */
269
+ export async function ingestImagePath(p) {
270
+ const raw = await readImageFromPath(p);
271
+ if (!raw)
272
+ return { error: `cannot read image at ${p}` };
273
+ const sized = await maybeResizeImage(raw);
274
+ const validation = validateImageSize(sized);
275
+ if (!validation.ok)
276
+ return { error: validation.reason };
277
+ return { attachment: sized };
278
+ }
279
+ export async function ingestClipboardImage() {
280
+ const raw = await getImageFromClipboard();
281
+ if (!raw)
282
+ return { error: "clipboard has no image" };
283
+ const sized = await maybeResizeImage(raw);
284
+ const validation = validateImageSize(sized);
285
+ if (!validation.ok)
286
+ return { error: validation.reason };
287
+ return { attachment: sized };
288
+ }
@@ -0,0 +1,41 @@
1
+ import type { SkillRegistry } from "../skills/registry.js";
2
+ import { type ImageAttachment } from "./image-paste.js";
3
+ export interface SubmitPayload {
4
+ text: string;
5
+ images: ImageAttachment[];
6
+ }
7
+ interface InputBoxProps {
8
+ onSubmit: (payload: SubmitPayload) => void;
9
+ onPasteNotice?: (notice: string) => void;
10
+ disabled?: boolean;
11
+ skillRegistry?: SkillRegistry;
12
+ terminalColumns: number;
13
+ cwd: string;
14
+ }
15
+ export declare function needsCursorRowCompensation(nextOutputHeight: number, viewportRows: number, previousOutputHeight: number | null): boolean;
16
+ export declare function shouldSubmitExactSlashSuggestion(input: string, suggestionName?: string): boolean;
17
+ export declare function resolveSlashEnterAction(input: string, suggestions: Array<{
18
+ name: string;
19
+ }>, selectedIndex: number): {
20
+ kind: "submit";
21
+ } | {
22
+ kind: "complete";
23
+ text: string;
24
+ } | {
25
+ kind: "none";
26
+ };
27
+ export type InkEnterIntent = "none" | "newline" | "submit";
28
+ export declare function isInkModifiedEnterInput(input: string): boolean;
29
+ export declare function resolveInkEnterIntent(input: string, key: {
30
+ return?: boolean;
31
+ shift?: boolean;
32
+ ctrl?: boolean;
33
+ meta?: boolean;
34
+ eventType?: string;
35
+ }): InkEnterIntent;
36
+ export declare function insertNewlineAtCursor(text: string, cursor: number): {
37
+ text: string;
38
+ cursor: number;
39
+ };
40
+ export declare function InputBox({ onSubmit, onPasteNotice, disabled, skillRegistry, terminalColumns, cwd }: InputBoxProps): import("react/jsx-runtime").JSX.Element;
41
+ export {};