@useavalon/caelence-agent 0.2.2-canary.4 → 0.2.2-canary.6
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.
- package/desktop/src/App.tsx +143 -33
- package/desktop/src/BubbleClip.tsx +58 -0
- package/desktop/src/ComposerAttach.tsx +2 -26
- package/desktop/src/FilesPanel.tsx +68 -0
- package/desktop/src/PlatformPane.tsx +98 -0
- package/desktop/src/SkillsPanel.tsx +0 -7
- package/desktop/src/api.ts +6 -1
- package/desktop/src/app.css +906 -47
- package/desktop/src/clip.test.ts +16 -0
- package/desktop/src/clip.ts +26 -0
- package/desktop/src/composer-files.test.ts +2 -0
- package/desktop/src/composer-files.ts +10 -0
- package/desktop/src/platform.test.ts +30 -0
- package/desktop/src/platform.ts +76 -0
- package/desktop/src/rich-text.test.ts +26 -0
- package/desktop/src/rich-text.ts +51 -2
- package/desktop/src/stream.ts +1 -0
- package/desktop/src/styles/primitives.css +6 -3
- package/desktop/src/user-display.test.ts +42 -0
- package/desktop/src/user-display.ts +20 -0
- package/package.json +1 -1
- package/src/cli/models.ts +3 -1
- package/src/cli/openrouter-live.test.ts +29 -0
- package/src/cli/openrouter-live.ts +9 -1
- package/src/cli/tui.tsx +40 -5
- package/src/core/approval.test.ts +22 -0
- package/src/core/approval.ts +20 -0
- package/src/desktop/bridge.ts +35 -12
- package/src/desktop/upload-message.test.ts +53 -0
- package/src/desktop/upload-message.ts +74 -0
- package/src/desktop/uploads.test.ts +34 -0
- package/src/desktop/uploads.ts +178 -13
- package/src/index.ts +1 -0
- package/src/init.test.ts +21 -0
- package/src/runtime.ts +6 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { clipNeedsExpand } from "./clip.ts";
|
|
3
|
+
|
|
4
|
+
describe("clipNeedsExpand", () => {
|
|
5
|
+
test("ignores a sliver of the last line", () => {
|
|
6
|
+
expect(clipNeedsExpand(108, 99, 22)).toBe(false);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("expands when more than a line is hidden", () => {
|
|
10
|
+
expect(clipNeedsExpand(180, 99, 22)).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("does not expand when content fits", () => {
|
|
14
|
+
expect(clipNeedsExpand(80, 99, 22)).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function clipNeedsExpand(
|
|
2
|
+
contentHeight: number,
|
|
3
|
+
collapsedHeight: number,
|
|
4
|
+
lineHeight: number,
|
|
5
|
+
): boolean {
|
|
6
|
+
if (contentHeight <= 0 || collapsedHeight <= 0) return false;
|
|
7
|
+
const hidden = contentHeight - collapsedHeight;
|
|
8
|
+
const slop = Math.max(8, lineHeight * 1.15);
|
|
9
|
+
return hidden > slop;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function collapsedClipLimit(node: HTMLElement): number {
|
|
13
|
+
const style = getComputedStyle(node);
|
|
14
|
+
const raw = style.getPropertyValue("--desk-clip-max").trim() || style.maxHeight;
|
|
15
|
+
const fontSize = parseFloat(style.fontSize);
|
|
16
|
+
if (raw.endsWith("em") && Number.isFinite(fontSize)) return parseFloat(raw) * fontSize;
|
|
17
|
+
if (raw.endsWith("px")) return parseFloat(raw);
|
|
18
|
+
return node.clientHeight;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function clipLineHeight(node: HTMLElement): number {
|
|
22
|
+
const line = parseFloat(getComputedStyle(node).lineHeight);
|
|
23
|
+
if (Number.isFinite(line) && line > 0) return line;
|
|
24
|
+
const fontSize = parseFloat(getComputedStyle(node).fontSize);
|
|
25
|
+
return Number.isFinite(fontSize) ? fontSize * 1.45 : 20;
|
|
26
|
+
}
|
|
@@ -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,30 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
formatPlatformOutput,
|
|
4
|
+
isPlatformTool,
|
|
5
|
+
matchPlatform,
|
|
6
|
+
platformTitle,
|
|
7
|
+
toolEventOutput,
|
|
8
|
+
} from "./platform.ts";
|
|
9
|
+
|
|
10
|
+
describe("platform tools", () => {
|
|
11
|
+
test("reads the MCP namespace", () => {
|
|
12
|
+
expect(isPlatformTool("notion__notion_fetch")).toBe(true);
|
|
13
|
+
expect(isPlatformTool("read_file")).toBe(false);
|
|
14
|
+
expect(platformTitle("notion__notion_fetch", [{ id: "notion", label: "Notion" }])).toBe(
|
|
15
|
+
"Notion",
|
|
16
|
+
);
|
|
17
|
+
expect(
|
|
18
|
+
platformTitle("google_sheets__get_range", [{ id: "google-sheets", label: "Google Sheets" }]),
|
|
19
|
+
).toBe("Google Sheets");
|
|
20
|
+
expect(matchPlatform("canva__list_designs", [{ id: "canva", label: "Canva" }])?.id).toBe(
|
|
21
|
+
"canva",
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("pretty-prints JSON tool payloads", () => {
|
|
26
|
+
expect(formatPlatformOutput('{"title":"Notes"}')).toBe('{\n "title": "Notes"\n}');
|
|
27
|
+
expect(toolEventOutput({ text: "hello" })).toBe("hello");
|
|
28
|
+
expect(toolEventOutput({ content: [{ type: "text", text: "page" }] })).toBe("page");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const PLATFORM_OUTPUT_MAX = 8000;
|
|
2
|
+
|
|
3
|
+
export function platformPrefix(toolName: string): string | undefined {
|
|
4
|
+
const cut = toolName.indexOf("__");
|
|
5
|
+
if (cut <= 0) return undefined;
|
|
6
|
+
return toolName.slice(0, cut);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isPlatformTool(toolName: string): boolean {
|
|
10
|
+
return platformPrefix(toolName) !== undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function matchPlatform<T extends { id: string }>(
|
|
14
|
+
toolName: string,
|
|
15
|
+
items: readonly T[],
|
|
16
|
+
): T | undefined {
|
|
17
|
+
const prefix = platformPrefix(toolName);
|
|
18
|
+
if (!prefix) return undefined;
|
|
19
|
+
const key = prefix.replaceAll("_", "-").toLowerCase();
|
|
20
|
+
return items.find((item) => item.id.replaceAll("_", "-").toLowerCase() === key);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function platformTitle(
|
|
24
|
+
toolName: string,
|
|
25
|
+
items: ReadonlyArray<{ id: string; label: string }>,
|
|
26
|
+
): string {
|
|
27
|
+
const match = matchPlatform(toolName, items);
|
|
28
|
+
if (match) return match.label;
|
|
29
|
+
const prefix = platformPrefix(toolName);
|
|
30
|
+
if (!prefix) return "Integration";
|
|
31
|
+
const label = prefix.replaceAll("_", " ").replaceAll("-", " ").trim();
|
|
32
|
+
return label.length > 0 ? label.charAt(0).toUpperCase() + label.slice(1) : "Integration";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function clipPlatformOutput(text: string): string {
|
|
36
|
+
if (text.length <= PLATFORM_OUTPUT_MAX) return text;
|
|
37
|
+
return `${text.slice(0, PLATFORM_OUTPUT_MAX)}\n…`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function formatPlatformOutput(raw: string): string {
|
|
41
|
+
const trimmed = raw.trim();
|
|
42
|
+
if (!trimmed) return "";
|
|
43
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(JSON.parse(trimmed), null, 2);
|
|
46
|
+
} catch {
|
|
47
|
+
return trimmed;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return trimmed;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function toolEventOutput(result: unknown): string {
|
|
54
|
+
if (typeof result === "string") return clipPlatformOutput(result);
|
|
55
|
+
if (!result || typeof result !== "object") return "";
|
|
56
|
+
const rec = result as Record<string, unknown>;
|
|
57
|
+
if (typeof rec.text === "string") return clipPlatformOutput(rec.text);
|
|
58
|
+
if (Array.isArray(rec.content)) {
|
|
59
|
+
const bits: string[] = [];
|
|
60
|
+
for (const block of rec.content) {
|
|
61
|
+
if (
|
|
62
|
+
block &&
|
|
63
|
+
typeof block === "object" &&
|
|
64
|
+
typeof (block as { text?: unknown }).text === "string"
|
|
65
|
+
) {
|
|
66
|
+
bits.push((block as { text: string }).text);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (bits.length > 0) return clipPlatformOutput(bits.join("\n"));
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return clipPlatformOutput(JSON.stringify(result, null, 2));
|
|
73
|
+
} catch {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -76,6 +76,32 @@ describe("splitRichText", () => {
|
|
|
76
76
|
]);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
+
test("keeps Notion list copy and scheme-less URLs as links, not files", () => {
|
|
80
|
+
const listed = splitRichText(
|
|
81
|
+
"Pages:\n1. https://www.notion.so/workspace/Notes-abc123\n2. www.notion.so/Second-page\n3. notion.so/Third",
|
|
82
|
+
);
|
|
83
|
+
expect(listed.filter((part) => part.type === "file")).toEqual([]);
|
|
84
|
+
const links = listed.filter((part) => part.type === "link");
|
|
85
|
+
expect(links.map((part) => part.href)).toEqual([
|
|
86
|
+
"https://www.notion.so/workspace/Notes-abc123",
|
|
87
|
+
"https://www.notion.so/Second-page",
|
|
88
|
+
"https://notion.so/Third",
|
|
89
|
+
]);
|
|
90
|
+
expect(
|
|
91
|
+
splitRichText("1. www.notion.so/workspace/Notes-abc123").some((part) => part.type === "file"),
|
|
92
|
+
).toBe(false);
|
|
93
|
+
expect(
|
|
94
|
+
splitRichText("1. notion.so/workspace/Notes-abc123").some((part) => part.type === "file"),
|
|
95
|
+
).toBe(false);
|
|
96
|
+
const prose = splitRichText(
|
|
97
|
+
"Main page: CPH MARATHON 24\nURL: app.notion.com/p/53e6c2a14dfe45e5beb210a33cc8c3c4\n- Workout Schedule (planned training calendar)\n- RUNS (planned/logged runs)\n- Completed Runs",
|
|
98
|
+
);
|
|
99
|
+
expect(prose.filter((part) => part.type === "file")).toEqual([]);
|
|
100
|
+
expect(prose.some((part) => part.type === "link" && part.href.includes("53e6c2a14dfe"))).toBe(
|
|
101
|
+
true,
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
79
105
|
test("keeps an explicit home path clickable", () => {
|
|
80
106
|
const parts = splitRichText("Open ~/Documents/brief.md when you can.");
|
|
81
107
|
expect(parts.some((part) => part.type === "file" && part.path === "~/Documents/brief.md")).toBe(
|
package/desktop/src/rich-text.ts
CHANGED
|
@@ -6,6 +6,8 @@ export type RichPart =
|
|
|
6
6
|
|
|
7
7
|
const MD_LINK = /\[([^\]]+)\]\(((?:https?:\/\/|file:\/\/|~\/|\/)[^)\s]+)\)/gi;
|
|
8
8
|
const BARE_URL = /https?:\/\/[^\s<>"'\])]+/gi;
|
|
9
|
+
const WEB_REF =
|
|
10
|
+
/(?:^|[\s(])((?:www\.)[^\s<>"'\])]+|[a-z0-9][a-z0-9.-]*\.[a-z]{2,}\/[^\s<>"'\])]+)/gi;
|
|
9
11
|
const DIR_REF =
|
|
10
12
|
/(?:^|[\s(])((?:~|\/(?:Users|home|Volumes|private|tmp|opt|var|Applications|Library))[^\s):,]*)/g;
|
|
11
13
|
|
|
@@ -61,9 +63,30 @@ export function joinLocalPath(dir: string, name: string): string {
|
|
|
61
63
|
return `${dir.replace(/\/+$/, "")}/${name}`;
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
export function looksLikeWebUrl(name: string): boolean {
|
|
67
|
+
const value = name.trim();
|
|
68
|
+
if (!value) return false;
|
|
69
|
+
if (/^https?:\/\//i.test(value)) return true;
|
|
70
|
+
if (/^www\./i.test(value)) return true;
|
|
71
|
+
return /^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}(?:\/|\?|#)/i.test(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function webHref(value: string): string {
|
|
75
|
+
const trimmed = value.trim();
|
|
76
|
+
if (/^https?:\/\//i.test(trimmed)) return trimmed;
|
|
77
|
+
return `https://${trimmed.replace(/^\/+/, "")}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
export function looksLikeFilename(name: string): boolean {
|
|
65
81
|
if (!name || name.length > 240) return false;
|
|
66
|
-
if (
|
|
82
|
+
if (looksLikeWebUrl(name)) return false;
|
|
83
|
+
if (isLocalFileHref(name) || name.startsWith("./") || name.startsWith("../")) return true;
|
|
84
|
+
if (name.includes("/")) {
|
|
85
|
+
if (/\s/.test(name)) return false;
|
|
86
|
+
if (!/^[.A-Za-z0-9_~-]+(?:\/[.A-Za-z0-9_~-]+)+$/.test(name)) return false;
|
|
87
|
+
const last = name.split("/").pop() ?? "";
|
|
88
|
+
return /\.[A-Za-z0-9]{1,10}$/.test(last);
|
|
89
|
+
}
|
|
67
90
|
return /\.[A-Za-z0-9]{1,10}$/.test(name);
|
|
68
91
|
}
|
|
69
92
|
|
|
@@ -98,6 +121,15 @@ export function splitRichText(text: string): RichPart[] {
|
|
|
98
121
|
});
|
|
99
122
|
}
|
|
100
123
|
|
|
124
|
+
for (const hit of collectWebRefs(text)) {
|
|
125
|
+
if (overlaps(taken, hit.start, hit.end)) continue;
|
|
126
|
+
taken.push({
|
|
127
|
+
start: hit.start,
|
|
128
|
+
end: hit.end,
|
|
129
|
+
part: { type: "link", href: hit.href, label: hit.label },
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
101
133
|
for (const hit of collectLocalFiles(text)) {
|
|
102
134
|
if (overlaps(taken, hit.start, hit.end)) continue;
|
|
103
135
|
taken.push({
|
|
@@ -135,6 +167,23 @@ function overlaps(
|
|
|
135
167
|
return taken.some((item) => start < item.end && end > item.start);
|
|
136
168
|
}
|
|
137
169
|
|
|
170
|
+
function collectWebRefs(
|
|
171
|
+
text: string,
|
|
172
|
+
): Array<{ start: number; end: number; href: string; label: string }> {
|
|
173
|
+
const hits: Array<{ start: number; end: number; href: string; label: string }> = [];
|
|
174
|
+
for (const match of text.matchAll(WEB_REF)) {
|
|
175
|
+
const raw = match[1];
|
|
176
|
+
if (!raw || match.index === undefined) continue;
|
|
177
|
+
if (/^https?:\/\//i.test(raw)) continue;
|
|
178
|
+
const start = match.index + match[0].length - raw.length;
|
|
179
|
+
const token = trimTrailingPunct(raw);
|
|
180
|
+
if (!looksLikeWebUrl(token)) continue;
|
|
181
|
+
const href = webHref(token);
|
|
182
|
+
hits.push({ start, end: start + token.length, href, label: linkLabel(href) });
|
|
183
|
+
}
|
|
184
|
+
return hits;
|
|
185
|
+
}
|
|
186
|
+
|
|
138
187
|
function collectLocalFiles(
|
|
139
188
|
text: string,
|
|
140
189
|
): Array<{ start: number; end: number; path: string; label: string }> {
|
|
@@ -146,7 +195,7 @@ function collectLocalFiles(
|
|
|
146
195
|
if (!raw || match.index === undefined) continue;
|
|
147
196
|
const start = match.index + match[0].length - raw.length;
|
|
148
197
|
const path = trimTrailingPunct(raw).replace(/\/+$/, "") || raw;
|
|
149
|
-
if (path.length < 2) continue;
|
|
198
|
+
if (path.length < 2 || looksLikeWebUrl(path)) continue;
|
|
150
199
|
dirs.push({ start, path });
|
|
151
200
|
hits.push({ start, end: start + raw.length, path, label: path });
|
|
152
201
|
}
|
package/desktop/src/stream.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Caelence primitives. Colour only through role aliases. Radii 4 / 8 / 12 / full.
|
|
2
|
-
Icon tiles use --icon-tile / --r-tile.
|
|
2
|
+
Buttons are rounded rects (12, compact 8). Icon tiles use --icon-tile / --r-tile.
|
|
3
|
+
Handles are always round. */
|
|
3
4
|
|
|
4
5
|
.cel-btn {
|
|
5
6
|
display: inline-flex;
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
font-weight: 600;
|
|
12
13
|
line-height: 1;
|
|
13
14
|
padding: 13px 20px;
|
|
14
|
-
border-radius: var(--r-
|
|
15
|
+
border-radius: var(--r-lg);
|
|
15
16
|
border: 1px solid transparent;
|
|
16
17
|
cursor: pointer;
|
|
17
18
|
text-decoration: none;
|
|
@@ -73,11 +74,13 @@
|
|
|
73
74
|
.cel-btn--sm {
|
|
74
75
|
font-size: 13px;
|
|
75
76
|
padding: 8px 14px;
|
|
77
|
+
border-radius: var(--r-md);
|
|
76
78
|
}
|
|
77
79
|
.cel-btn--compact {
|
|
78
80
|
font-size: 13px;
|
|
79
81
|
padding: 5px 10px;
|
|
80
82
|
gap: 6px;
|
|
83
|
+
border-radius: var(--r-md);
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
.cel-tile {
|
|
@@ -462,7 +465,7 @@
|
|
|
462
465
|
}
|
|
463
466
|
|
|
464
467
|
.cel-float {
|
|
465
|
-
box-shadow: 0
|
|
468
|
+
box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--ink) 36%, transparent);
|
|
466
469
|
}
|
|
467
470
|
|
|
468
471
|
/* Hover tip. A floating layer, so the same shadow as menus is allowed.
|
|
@@ -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
package/src/cli/models.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { prettyLiveModelName } from "./openrouter-live.ts";
|
|
2
|
+
|
|
1
3
|
export interface ModelOption {
|
|
2
4
|
id: string;
|
|
3
5
|
label: string;
|
|
@@ -31,7 +33,7 @@ export function modelPickerItems(
|
|
|
31
33
|
live?: ReadonlyMap<string, string>,
|
|
32
34
|
): Array<{ id: string; label: string; hint?: string }> {
|
|
33
35
|
const items = HARNESS_MODELS.map((model) => {
|
|
34
|
-
const target = live?.get(model.id)?.trim();
|
|
36
|
+
const target = prettyLiveModelName(live?.get(model.id)?.trim() ?? "").trim();
|
|
35
37
|
const hint = target && target.toLowerCase() !== model.label.toLowerCase() ? target : undefined;
|
|
36
38
|
return { id: model.id, label: model.label, ...(hint ? { hint } : {}) };
|
|
37
39
|
});
|
|
@@ -20,6 +20,17 @@ describe("parseLiveTargetNames", () => {
|
|
|
20
20
|
expect(names.get("~x-ai/grok-latest")).toBe("Grok 4.6");
|
|
21
21
|
expect(names.get("openai/gpt-5.6-sol")).toBe("GPT-5.6 Sol");
|
|
22
22
|
});
|
|
23
|
+
|
|
24
|
+
test("drops Router from Auto labels", () => {
|
|
25
|
+
const names = parseLiveTargetNames({
|
|
26
|
+
data: [
|
|
27
|
+
{ id: "openrouter/auto", name: "OpenRouter: Auto Router" },
|
|
28
|
+
{ id: "openrouter/auto-beta", name: "Auto Router Beta" },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
expect(names.get("openrouter/auto")).toBe("Auto");
|
|
32
|
+
expect(names.get("openrouter/auto-beta")).toBe("Auto beta");
|
|
33
|
+
});
|
|
23
34
|
});
|
|
24
35
|
|
|
25
36
|
describe("model picker live names", () => {
|
|
@@ -32,4 +43,22 @@ describe("model picker live names", () => {
|
|
|
32
43
|
expect(grok?.label).toBe("Grok latest");
|
|
33
44
|
expect(grok?.hint).toBe("Grok 4.6");
|
|
34
45
|
});
|
|
46
|
+
|
|
47
|
+
test("does not hint Auto Router on Auto", () => {
|
|
48
|
+
const items = modelPickerItems(
|
|
49
|
+
"openrouter/auto",
|
|
50
|
+
new Map([
|
|
51
|
+
["openrouter/auto", "Auto Router"],
|
|
52
|
+
["openrouter/auto-beta", "Auto Router Beta"],
|
|
53
|
+
]),
|
|
54
|
+
);
|
|
55
|
+
expect(items.find((item) => item.id === "openrouter/auto")).toEqual({
|
|
56
|
+
id: "openrouter/auto",
|
|
57
|
+
label: "Auto",
|
|
58
|
+
});
|
|
59
|
+
expect(items.find((item) => item.id === "openrouter/auto-beta")).toEqual({
|
|
60
|
+
id: "openrouter/auto-beta",
|
|
61
|
+
label: "Auto beta",
|
|
62
|
+
});
|
|
63
|
+
});
|
|
35
64
|
});
|
|
@@ -9,7 +9,15 @@ function displayName(id: string, rawName: string): string {
|
|
|
9
9
|
const trimmed = rawName.trim();
|
|
10
10
|
if (!trimmed) return id;
|
|
11
11
|
const colon = trimmed.indexOf(": ");
|
|
12
|
-
|
|
12
|
+
const name = colon >= 0 ? trimmed.slice(colon + 2) : trimmed;
|
|
13
|
+
return prettyLiveModelName(name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** OpenRouter calls Auto "Auto Router". Product copy is Auto / Auto beta. */
|
|
17
|
+
export function prettyLiveModelName(name: string): string {
|
|
18
|
+
const lower = name.toLowerCase().replace(/[_-]+/g, " ").replace(/\s+/g, " ").trim();
|
|
19
|
+
if (!/\bauto\b/.test(lower) || !/\brouter\b/.test(lower)) return name;
|
|
20
|
+
return /\bbeta\b/.test(lower) ? "Auto beta" : "Auto";
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
/** Human name of the concrete model a `~latest` alias currently resolves to. */
|
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}>
|
|
405
|
-
|
|
406
|
-
|
|
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(
|
|
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
|
});
|