@useavalon/caelence-agent 0.2.2-canary.5 → 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.
@@ -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
+ }
@@ -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(
@@ -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 (isLocalFileHref(name) || name.includes("/")) return true;
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
  }
@@ -24,6 +24,7 @@ export type StreamLine =
24
24
  count: number;
25
25
  preview: string;
26
26
  error?: string;
27
+ output?: string;
27
28
  }
28
29
  | { key: string; type: "system"; text: string }
29
30
  | { key: string; type: "error"; text: string }
@@ -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. Handles are always round. */
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-full);
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 18px 40px -20px color-mix(in srgb, var(--ink) 40%, transparent);
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/caelence-agent",
3
- "version": "0.2.2-canary.5",
3
+ "version": "0.2.2-canary.6",
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",
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
- return colon >= 0 ? trimmed.slice(colon + 2) : trimmed;
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. */
@@ -1,7 +1,11 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
  import { mediaModelLabel } from "../cli/media-models.ts";
3
3
  import { HARNESS_MODELS, modelPickerItems } from "../cli/models.ts";
4
- import { cachedLiveTargetNames, loadLiveTargetNames } from "../cli/openrouter-live.ts";
4
+ import {
5
+ cachedLiveTargetNames,
6
+ loadLiveTargetNames,
7
+ prettyLiveModelName,
8
+ } from "../cli/openrouter-live.ts";
5
9
  import { cachedModalityModels } from "../cli/openrouter-modality.ts";
6
10
  import { sessionPickerItems } from "../cli/picker.ts";
7
11
  import { isHelpAlias } from "../cli/slash.ts";
@@ -230,17 +234,16 @@ async function readJson(req: Request): Promise<Record<string, unknown>> {
230
234
 
231
235
  function snapshot(harness: HarnessRuntime, busy: boolean, title: string): DesktopState {
232
236
  const live = cachedLiveTargetNames();
233
- const target = live.get(harness.modelId);
237
+ const target = prettyLiveModelName(live.get(harness.modelId) ?? "").trim();
234
238
  const prefs = readMediaPrefs();
239
+ const label = modelLabel(harness.modelId);
235
240
  return {
236
241
  name: harness.config.name,
237
242
  cwd: harness.cwd,
238
243
  mode: harness.mode,
239
244
  modelId: harness.modelId,
240
- modelLabel: modelLabel(harness.modelId),
241
- ...(target && target.toLowerCase() !== modelLabel(harness.modelId).toLowerCase()
242
- ? { modelTarget: target }
243
- : {}),
245
+ modelLabel: label,
246
+ ...(target && target.toLowerCase() !== label.toLowerCase() ? { modelTarget: target } : {}),
244
247
  imageModelId: prefs.imageModel,
245
248
  imageModelLabel: mediaModelLabel(cachedModalityModels("image"), prefs.imageModel),
246
249
  videoModelId: prefs.videoModel,