@useavalon/caelence-agent 0.2.2-canary.3 → 0.2.2-canary.5

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.
@@ -0,0 +1,268 @@
1
+ import { CheckIcon } from "@phosphor-icons/react/dist/csr/Check";
2
+ import { type ReactElement, useEffect, useState } from "react";
3
+ import { errorMessage } from "../../src/core/errors";
4
+ import { addMcp, type BridgeClient, getMcps, type PublicUserMcp, removeMcp } from "./api";
5
+
6
+ const LOCAL_MCP_PLACEHOLDER = `uvx mcp-server-fetch
7
+ or ------------------------
8
+ {
9
+ "mcpServers": {
10
+ "fetch": {
11
+ "command": "uvx",
12
+ "args": ["mcp-server-fetch"]
13
+ }
14
+ }
15
+ }`;
16
+
17
+ function mcpGlyph(item: PublicUserMcp): string {
18
+ if (item.kind === "http") return "URL";
19
+ const letters = item.label.replace(/[^a-zA-Z0-9]/g, "").slice(0, 2);
20
+ return letters.toUpperCase() || "MCP";
21
+ }
22
+
23
+ function mcpOrigin(item: PublicUserMcp): string {
24
+ if (item.origin === "config") return `${item.detail} · harness.config.ts`;
25
+ return item.detail;
26
+ }
27
+
28
+ function McpActions(
29
+ props: Readonly<{
30
+ item: PublicUserMcp;
31
+ pending: boolean;
32
+ onRemove: () => void;
33
+ }>,
34
+ ): ReactElement {
35
+ if (props.pending) {
36
+ return (
37
+ <span className="desk-integration-ok">
38
+ <span className="cel-chip__spin" aria-hidden="true" />
39
+ <span>Removing</span>
40
+ </span>
41
+ );
42
+ }
43
+ if (props.item.removable) {
44
+ return (
45
+ <button
46
+ type="button"
47
+ className="cel-btn cel-btn--quiet cel-btn--compact"
48
+ onClick={props.onRemove}
49
+ >
50
+ Remove
51
+ </button>
52
+ );
53
+ }
54
+ return (
55
+ <span className="desk-integration-ok">
56
+ <CheckIcon size={16} weight="regular" aria-hidden="true" />
57
+ In config
58
+ </span>
59
+ );
60
+ }
61
+
62
+ function McpRow(
63
+ props: Readonly<{
64
+ item: PublicUserMcp;
65
+ pending: boolean;
66
+ onRemove: () => void;
67
+ }>,
68
+ ): ReactElement {
69
+ const { item } = props;
70
+ return (
71
+ <li>
72
+ <span className="desk-integration-glyph desk-integration-mark" aria-hidden="true">
73
+ {mcpGlyph(item)}
74
+ </span>
75
+ <div>
76
+ <p>{item.label}</p>
77
+ <em>{mcpOrigin(item)}</em>
78
+ </div>
79
+ <div className="desk-integration-actions">
80
+ <McpActions item={item} pending={props.pending} onRemove={props.onRemove} />
81
+ </div>
82
+ </li>
83
+ );
84
+ }
85
+
86
+ export function McpPanel(
87
+ props: Readonly<{
88
+ bridge: BridgeClient;
89
+ onNotice: (text: string) => void;
90
+ }>,
91
+ ): ReactElement {
92
+ const [items, setItems] = useState<PublicUserMcp[] | null>(null);
93
+ const [loadFailed, setLoadFailed] = useState(false);
94
+ const [kind, setKind] = useState<"stdio" | "http">("stdio");
95
+ const [label, setLabel] = useState("");
96
+ const [command, setCommand] = useState("");
97
+ const [url, setUrl] = useState("");
98
+ const [token, setToken] = useState("");
99
+ const [busy, setBusy] = useState(false);
100
+ const [pendingId, setPendingId] = useState<string | null>(null);
101
+
102
+ useEffect(() => {
103
+ let alive = true;
104
+ void getMcps(props.bridge)
105
+ .then((result) => {
106
+ if (alive) setItems(result.items);
107
+ })
108
+ .catch((err: unknown) => {
109
+ if (!alive) return;
110
+ setLoadFailed(true);
111
+ props.onNotice(errorMessage(err));
112
+ });
113
+ return () => {
114
+ alive = false;
115
+ };
116
+ }, [props.bridge, props.onNotice]);
117
+
118
+ const submit = async (): Promise<void> => {
119
+ setBusy(true);
120
+ try {
121
+ const result = await addMcp(
122
+ props.bridge,
123
+ kind === "http"
124
+ ? { kind: "http", label: label.trim() || undefined, url: url.trim(), token: token.trim() }
125
+ : { kind: "stdio", label: label.trim() || undefined, command: command.trim() },
126
+ );
127
+ setItems(result.items);
128
+ setLabel("");
129
+ setCommand("");
130
+ setUrl("");
131
+ setToken("");
132
+ } catch (err) {
133
+ props.onNotice(errorMessage(err));
134
+ } finally {
135
+ setBusy(false);
136
+ }
137
+ };
138
+
139
+ const drop = async (id: string): Promise<void> => {
140
+ setPendingId(id);
141
+ try {
142
+ const result = await removeMcp(props.bridge, id);
143
+ setItems(result.items);
144
+ } catch (err) {
145
+ props.onNotice(errorMessage(err));
146
+ } finally {
147
+ setPendingId(null);
148
+ }
149
+ };
150
+
151
+ if (!items && !loadFailed) {
152
+ return <p>Loading MCP servers</p>;
153
+ }
154
+
155
+ if (!items && loadFailed) {
156
+ return <p className="desk-side-empty">MCP servers could not be loaded</p>;
157
+ }
158
+
159
+ const listed = items ?? [];
160
+ const canAdd = kind === "http" ? url.trim().length > 0 : command.trim().length > 0;
161
+
162
+ return (
163
+ <>
164
+ <p className="desk-integrations-lead">
165
+ Local command or URL MCP servers for this project. Paste a command, or an mcpServers JSON
166
+ block.
167
+ </p>
168
+ <div className="desk-pane-tabs desk-pane-tabs--compact" role="tablist" aria-label="MCP kind">
169
+ <button
170
+ type="button"
171
+ role="tab"
172
+ aria-selected={kind === "stdio"}
173
+ className={kind === "stdio" ? "is-on" : undefined}
174
+ onClick={() => setKind("stdio")}
175
+ >
176
+ Local
177
+ </button>
178
+ <button
179
+ type="button"
180
+ role="tab"
181
+ aria-selected={kind === "http"}
182
+ className={kind === "http" ? "is-on" : undefined}
183
+ onClick={() => setKind("http")}
184
+ >
185
+ URL
186
+ </button>
187
+ </div>
188
+ <form
189
+ className="desk-mcp-form"
190
+ onSubmit={(event) => {
191
+ event.preventDefault();
192
+ if (canAdd && !busy) void submit();
193
+ }}
194
+ >
195
+ <label>
196
+ <span>Name</span>
197
+ <input
198
+ className="cel-input"
199
+ value={label}
200
+ placeholder="Optional"
201
+ onChange={(event) => setLabel(event.target.value)}
202
+ />
203
+ </label>
204
+ {kind === "http" ? (
205
+ <>
206
+ <label>
207
+ <span>Server URL</span>
208
+ <input
209
+ className="cel-input"
210
+ value={url}
211
+ placeholder="http://127.0.0.1:3100/mcp"
212
+ autoComplete="off"
213
+ spellCheck={false}
214
+ onChange={(event) => setUrl(event.target.value)}
215
+ />
216
+ </label>
217
+ <label>
218
+ <span>Bearer token</span>
219
+ <input
220
+ className="cel-input"
221
+ type="password"
222
+ value={token}
223
+ placeholder="Optional"
224
+ autoComplete="off"
225
+ spellCheck={false}
226
+ onChange={(event) => setToken(event.target.value)}
227
+ />
228
+ </label>
229
+ </>
230
+ ) : (
231
+ <label>
232
+ <span>Command</span>
233
+ <textarea
234
+ className="cel-input"
235
+ rows={8}
236
+ value={command}
237
+ placeholder={LOCAL_MCP_PLACEHOLDER}
238
+ autoComplete="off"
239
+ spellCheck={false}
240
+ onChange={(event) => setCommand(event.target.value)}
241
+ />
242
+ </label>
243
+ )}
244
+ <button
245
+ type="submit"
246
+ className="cel-btn cel-btn--secondary cel-btn--compact"
247
+ disabled={!canAdd || busy}
248
+ >
249
+ {busy ? "Adding" : "Add"}
250
+ </button>
251
+ </form>
252
+ {listed.length === 0 ? (
253
+ <p className="desk-side-empty">No MCP servers yet. Add a local command or a URL.</p>
254
+ ) : (
255
+ <ul className="desk-integration-list">
256
+ {listed.map((item) => (
257
+ <McpRow
258
+ key={item.id}
259
+ item={item}
260
+ pending={pendingId === item.id}
261
+ onRemove={() => void drop(item.id)}
262
+ />
263
+ ))}
264
+ </ul>
265
+ )}
266
+ </>
267
+ );
268
+ }
@@ -30,6 +30,7 @@ export interface DesktopState {
30
30
  skills: Array<{ name: string; source: string }>;
31
31
  busy: boolean;
32
32
  hasApiKey: boolean;
33
+ uploads?: Array<{ name: string; rel: string; sourcePath?: string }>;
33
34
  }
34
35
 
35
36
  export interface PickerItem {
@@ -250,6 +251,48 @@ export function disconnectIntegration(
250
251
  });
251
252
  }
252
253
 
254
+ export interface PublicUserMcp {
255
+ id: string;
256
+ label: string;
257
+ kind: "stdio" | "http";
258
+ detail: string;
259
+ origin: "user" | "config";
260
+ removable: boolean;
261
+ }
262
+
263
+ export interface AddMcpInput {
264
+ label?: string;
265
+ kind: "stdio" | "http";
266
+ command?: string;
267
+ args?: string;
268
+ url?: string;
269
+ token?: string;
270
+ }
271
+
272
+ export function getMcps(bridge: BridgeClient): Promise<{ items: PublicUserMcp[] }> {
273
+ return request(bridge, "/mcp");
274
+ }
275
+
276
+ export function addMcp(
277
+ bridge: BridgeClient,
278
+ input: AddMcpInput,
279
+ ): Promise<{ ok: boolean; items: PublicUserMcp[] }> {
280
+ return request(bridge, "/mcp/add", {
281
+ method: "POST",
282
+ body: JSON.stringify(input),
283
+ });
284
+ }
285
+
286
+ export function removeMcp(
287
+ bridge: BridgeClient,
288
+ id: string,
289
+ ): Promise<{ ok: boolean; items: PublicUserMcp[] }> {
290
+ return request(bridge, "/mcp/remove", {
291
+ method: "POST",
292
+ body: JSON.stringify({ id }),
293
+ });
294
+ }
295
+
253
296
  export function openUrl(bridge: BridgeClient, url: string): Promise<{ ok: boolean }> {
254
297
  return request(bridge, "/open", {
255
298
  method: "POST",
@@ -385,7 +428,11 @@ export function deleteSession(
385
428
 
386
429
  export function approve(
387
430
  bridge: BridgeClient,
388
- body: { callId: string; decision: "yes" | "no" | "always"; toolName?: string },
431
+ body: {
432
+ callId: string;
433
+ decision: "yes" | "no" | "always" | "copy" | "original";
434
+ toolName?: string;
435
+ },
389
436
  ): Promise<{ ok: boolean }> {
390
437
  return request(bridge, "/approve", { method: "POST", body: JSON.stringify(body) });
391
438
  }
@@ -1630,6 +1630,75 @@ p.desk-line__caption {
1630
1630
  gap: 12px;
1631
1631
  }
1632
1632
 
1633
+ .desk-pane-tabs {
1634
+ display: flex;
1635
+ align-self: start;
1636
+ gap: 2px;
1637
+ padding: 3px;
1638
+ border-radius: var(--r-lg);
1639
+ background: var(--bg-inset);
1640
+ }
1641
+
1642
+ .desk-pane-tabs button {
1643
+ margin: 0;
1644
+ padding: 6px 12px;
1645
+ border: 0;
1646
+ border-radius: var(--r-md);
1647
+ background: transparent;
1648
+ color: var(--text-secondary);
1649
+ font: inherit;
1650
+ font-size: 13px;
1651
+ font-weight: 600;
1652
+ line-height: 1.2;
1653
+ cursor: pointer;
1654
+ }
1655
+
1656
+ .desk-pane-tabs button.is-on {
1657
+ background: var(--card);
1658
+ color: var(--text);
1659
+ box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 14%, transparent);
1660
+ }
1661
+
1662
+ .desk-pane-tabs button:focus-visible {
1663
+ outline: 1.5px solid var(--measure);
1664
+ outline-offset: 1px;
1665
+ }
1666
+
1667
+ .desk-pane-tabs--compact button {
1668
+ padding: 5px 10px;
1669
+ font-weight: 500;
1670
+ }
1671
+
1672
+ .desk-mcp-form {
1673
+ display: flex;
1674
+ flex-direction: column;
1675
+ gap: 10px;
1676
+ }
1677
+
1678
+ .desk-mcp-form label {
1679
+ display: flex;
1680
+ flex-direction: column;
1681
+ gap: 6px;
1682
+ }
1683
+
1684
+ .desk-mcp-form label > span:first-child {
1685
+ font-weight: 600;
1686
+ }
1687
+
1688
+ .desk-mcp-form .cel-btn {
1689
+ align-self: flex-start;
1690
+ }
1691
+
1692
+ .desk-mcp-form textarea.cel-input {
1693
+ height: auto;
1694
+ min-height: 148px;
1695
+ padding-top: 8px;
1696
+ padding-bottom: 8px;
1697
+ resize: vertical;
1698
+ line-height: 1.45;
1699
+ font-family: var(--mono);
1700
+ }
1701
+
1633
1702
  .desk-integrations-lead {
1634
1703
  margin: 0;
1635
1704
  color: var(--text-secondary);
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import {
3
3
  attachmentKind,
4
+ createAttachment,
4
5
  droppedPaths,
5
6
  fileExtension,
6
7
  filesFromTransfer,
@@ -32,6 +33,7 @@ describe("composer files", () => {
32
33
  const transfer = { files: [file] } as unknown as DataTransfer;
33
34
  expect(filesFromTransfer(transfer).map((item) => item.name)).toEqual(["a.txt"]);
34
35
  expect(droppedPaths(transfer)).toEqual(["/tmp/a.txt"]);
36
+ expect(createAttachment(file).sourcePath).toBe("/tmp/a.txt");
35
37
  });
36
38
 
37
39
  test("merges unique files and rejects oversized extras", () => {
@@ -12,6 +12,7 @@ export interface ComposerAttachment {
12
12
  size: number;
13
13
  kind: ComposerFileKind;
14
14
  previewUrl?: string;
15
+ sourcePath?: string;
15
16
  file: File;
16
17
  }
17
18
 
@@ -19,6 +20,7 @@ export interface TurnAttachmentPayload {
19
20
  name: string;
20
21
  mime: string;
21
22
  data: string;
23
+ sourcePath?: string;
22
24
  }
23
25
 
24
26
  export interface AttachmentPreview {
@@ -62,6 +64,11 @@ export function droppedPaths(transfer: DataTransfer | null): string[] {
62
64
  return paths;
63
65
  }
64
66
 
67
+ export function nativeFilePath(file: File): string | undefined {
68
+ const path = (file as File & { path?: string }).path?.trim();
69
+ return path || undefined;
70
+ }
71
+
65
72
  export function createAttachment(file: File): ComposerAttachment {
66
73
  const mime = file.type || "application/octet-stream";
67
74
  const kind = attachmentKind(file.name, mime);
@@ -72,6 +79,7 @@ export function createAttachment(file: File): ComposerAttachment {
72
79
  typeof URL.createObjectURL === "function"
73
80
  ? URL.createObjectURL(file)
74
81
  : undefined;
82
+ const sourcePath = nativeFilePath(file);
75
83
  return {
76
84
  id: `${file.name}-${file.size}-${file.lastModified}-${Math.random().toString(36).slice(2, 8)}`,
77
85
  name: file.name || "file",
@@ -79,6 +87,7 @@ export function createAttachment(file: File): ComposerAttachment {
79
87
  size: file.size,
80
88
  kind,
81
89
  ...(previewUrl ? { previewUrl } : {}),
90
+ ...(sourcePath ? { sourcePath } : {}),
82
91
  file,
83
92
  };
84
93
  }
@@ -130,6 +139,7 @@ export async function serializeComposerAttachments(
130
139
  name: item.name,
131
140
  mime: item.mime,
132
141
  data: await blobToBase64(item.file),
142
+ ...(item.sourcePath ? { sourcePath: item.sourcePath } : {}),
133
143
  })),
134
144
  );
135
145
  }
@@ -0,0 +1,42 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { composeUploadMessage } from "../../src/desktop/upload-message.ts";
3
+ import { userBubbleContent } from "./user-display.ts";
4
+
5
+ describe("user bubble display", () => {
6
+ test("shows a document chip instead of the uploaded file text", () => {
7
+ const composed = composeUploadMessage("can you add a title to this doc", [
8
+ {
9
+ name: "zeugg-design-handover.md",
10
+ rel: ".harness/uploads/1-0-zeugg-design-handover.md",
11
+ mime: "text/markdown",
12
+ excerpt: "# Zeugg Design System — Handover\n\nDark, technical, precise.",
13
+ },
14
+ ]);
15
+ const shown = userBubbleContent(composed);
16
+ expect(shown.text).toBe("can you add a title to this doc");
17
+ expect(shown.text).not.toContain("Zeugg Design System");
18
+ expect(shown.attachments).toEqual([
19
+ {
20
+ name: "zeugg-design-handover.md",
21
+ mime: "",
22
+ kind: "file",
23
+ },
24
+ ]);
25
+ });
26
+
27
+ test("keeps live composer chips and still strips a dumped excerpt", () => {
28
+ const composed = composeUploadMessage("edit this", [
29
+ {
30
+ name: "notes.md",
31
+ rel: ".harness/uploads/9-0-notes.md",
32
+ mime: "text/markdown",
33
+ excerpt: "lots of notes",
34
+ },
35
+ ]);
36
+ const shown = userBubbleContent(composed, [
37
+ { name: "notes.md", mime: "text/markdown", kind: "file" },
38
+ ]);
39
+ expect(shown.text).toBe("edit this");
40
+ expect(shown.attachments).toEqual([{ name: "notes.md", mime: "text/markdown", kind: "file" }]);
41
+ });
42
+ });
@@ -0,0 +1,20 @@
1
+ import { joinUploadDisplay, parseUploadDisplay } from "../../src/desktop/upload-message.ts";
2
+ import { type AttachmentPreview, attachmentKind } from "./composer-files.ts";
3
+
4
+ export function userBubbleContent(
5
+ text: string,
6
+ attachments: AttachmentPreview[] = [],
7
+ ): { text: string; attachments: AttachmentPreview[]; suffix: string } {
8
+ const shown = parseUploadDisplay(text);
9
+ const chips =
10
+ attachments.length > 0
11
+ ? attachments
12
+ : shown.attachments.map((file) => ({
13
+ name: file.name,
14
+ mime: file.mime ?? "",
15
+ kind: attachmentKind(file.name, file.mime ?? ""),
16
+ }));
17
+ return { text: shown.prompt, attachments: chips, suffix: shown.suffix };
18
+ }
19
+
20
+ export { joinUploadDisplay };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/caelence-agent",
3
- "version": "0.2.2-canary.3",
3
+ "version": "0.2.2-canary.5",
4
4
  "description": "Caelence agent: Strands turn loop, local tools, skills, evals, and a themable terminal UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,6 +58,7 @@ function fakeHarness(overrides: Partial<HarnessRuntime> = {}): HarnessRuntime {
58
58
  disabledSkills: () => [],
59
59
  enableSkill: () => ({ ok: true }),
60
60
  reloadIntegrations: async () => {},
61
+ reloadExtraMcp: async () => {},
61
62
  chat: async () => "",
62
63
  observability: {} as HarnessRuntime["observability"],
63
64
  close() {},
package/src/cli/tui.tsx CHANGED
@@ -3,6 +3,7 @@ import type React from "react";
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { resolveOpenRouter } from "../config.ts";
5
5
  import type { ApprovalRequest } from "../core/approval.ts";
6
+ import { isUploadEditRequest } from "../core/approval.ts";
6
7
  import { errorMessage } from "../core/errors.ts";
7
8
  import type { AgentEvent } from "../core/events.ts";
8
9
  import type { Session } from "../core/session.ts";
@@ -389,10 +390,15 @@ function SlashMenu(
389
390
  }
390
391
 
391
392
  function ApprovalCard(props: Readonly<{ theme: Theme; req: ApprovalRequest }>): React.ReactElement {
393
+ const upload = isUploadEditRequest(props.req);
392
394
  const command =
393
395
  typeof props.req.input.command === "string"
394
396
  ? props.req.input.command
395
397
  : JSON.stringify(props.req.input);
398
+ const copyPath =
399
+ typeof props.req.input.copyPath === "string" ? props.req.input.copyPath : undefined;
400
+ const originalPath =
401
+ typeof props.req.input.originalPath === "string" ? props.req.input.originalPath : undefined;
396
402
  return (
397
403
  <Box
398
404
  flexDirection="column"
@@ -401,9 +407,21 @@ function ApprovalCard(props: Readonly<{ theme: Theme; req: ApprovalRequest }>):
401
407
  borderColor={props.theme.warning}
402
408
  paddingX={1}
403
409
  >
404
- <Text color={props.theme.warning}>Approval needed · {props.req.toolName}</Text>
405
- <Text color={props.theme.ink}>{command}</Text>
406
- <Text color={props.theme.muted}>y approve · n deny · a always this session</Text>
410
+ <Text color={props.theme.warning}>
411
+ {upload ? "Edit this file where?" : `Approval needed · ${props.req.toolName}`}
412
+ </Text>
413
+ {upload ? (
414
+ <>
415
+ <Text color={props.theme.ink}>Copy: {copyPath}</Text>
416
+ <Text color={props.theme.ink}>Original: {originalPath}</Text>
417
+ <Text color={props.theme.muted}>c copy · o original · n cancel</Text>
418
+ </>
419
+ ) : (
420
+ <>
421
+ <Text color={props.theme.ink}>{command}</Text>
422
+ <Text color={props.theme.muted}>y approve · n deny · a always this session</Text>
423
+ </>
424
+ )}
407
425
  </Box>
408
426
  );
409
427
  }
@@ -418,7 +436,17 @@ function pickerSelectedValue(picker: SlashPickerKind, harness: HarnessRuntime):
418
436
  return undefined;
419
437
  }
420
438
 
421
- function approvalDecision(input: string, escaped: boolean): "yes" | "no" | "always" | undefined {
439
+ function approvalDecision(
440
+ input: string,
441
+ escaped: boolean,
442
+ upload: boolean,
443
+ ): "yes" | "no" | "always" | "copy" | "original" | undefined {
444
+ if (upload) {
445
+ if (input === "c" || input === "C") return "copy";
446
+ if (input === "o" || input === "O") return "original";
447
+ if (input === "n" || input === "N" || escaped) return "no";
448
+ return undefined;
449
+ }
422
450
  if (input === "y" || input === "Y") return "yes";
423
451
  if (input === "a" || input === "A") return "always";
424
452
  if (input === "n" || input === "N" || escaped) return "no";
@@ -664,9 +692,16 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
664
692
  useInput(
665
693
  (input, key) => {
666
694
  if (status === "approval" && pending) {
667
- const decision = approvalDecision(input, key.escape);
695
+ const decision = approvalDecision(input, key.escape, isUploadEditRequest(pending.req));
668
696
  if (!decision) return;
669
697
  if (decision === "always") harness.allowRiskyAlways(pending.req.toolName);
698
+ if (
699
+ decision === "original" &&
700
+ typeof pending.req.input.originalPath === "string" &&
701
+ pending.req.input.originalPath.trim()
702
+ ) {
703
+ pending.req.input.path = pending.req.input.originalPath;
704
+ }
670
705
  pending.resolve(decision !== "no");
671
706
  setPending(null);
672
707
  setStatus("running");
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
2
2
  import {
3
3
  createExecApprovalGate,
4
4
  isLikelyDestructive,
5
+ isUploadEditRequest,
5
6
  parseExecApprovalPolicy,
6
7
  } from "../core/approval.ts";
7
8
 
@@ -99,4 +100,25 @@ describe("exec approval", () => {
99
100
  await auto.request({ callId: "2", toolName: "edit_file", input: { path: "a.ts" } }),
100
101
  ).toBe(true);
101
102
  });
103
+
104
+ test("asks where to edit an uploaded file with an original path", async () => {
105
+ const input: Record<string, unknown> = { path: ".harness/uploads/1-note.txt" };
106
+ const asked: string[] = [];
107
+ const gate = createExecApprovalGate({
108
+ policy: "prompt",
109
+ resolveUploadEdit: (path) =>
110
+ path.includes("uploads")
111
+ ? { rel: path, sourcePath: "/tmp/note.txt", name: "note.txt" }
112
+ : undefined,
113
+ ask: async (req) => {
114
+ asked.push(req.toolName);
115
+ expect(isUploadEditRequest(req)).toBe(true);
116
+ req.input.path = req.input.originalPath;
117
+ return true;
118
+ },
119
+ });
120
+ expect(await gate.request({ callId: "1", toolName: "edit_file", input })).toBe(true);
121
+ expect(asked).toEqual(["edit_file"]);
122
+ expect(input.path).toBe("/tmp/note.txt");
123
+ });
102
124
  });