@useavalon/caelence-agent 0.1.0

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 (161) hide show
  1. package/README.md +201 -0
  2. package/bin/harness.ts +10 -0
  3. package/package.json +75 -0
  4. package/skills/copy-editor/SKILL.md +74 -0
  5. package/skills/copy-editor/references/anti-slop.md +62 -0
  6. package/skills/copy-editor/references/ui-states.md +46 -0
  7. package/skills/copy-editor/scripts/lint-copy.py +78 -0
  8. package/skills/copy-harry-dry/SKILL.md +120 -0
  9. package/skills/copy-rmbc/SKILL.md +97 -0
  10. package/skills/copywriting/SKILL.md +73 -0
  11. package/skills/impeccable/SKILL.md +133 -0
  12. package/skills/impeccable/references/visual-slop.md +36 -0
  13. package/src/cli/main.test.ts +36 -0
  14. package/src/cli/main.ts +384 -0
  15. package/src/cli/media-models.ts +82 -0
  16. package/src/cli/models.ts +43 -0
  17. package/src/cli/openrouter-live.test.ts +35 -0
  18. package/src/cli/openrouter-live.ts +72 -0
  19. package/src/cli/openrouter-modality.test.ts +25 -0
  20. package/src/cli/openrouter-modality.ts +83 -0
  21. package/src/cli/picker.test.ts +53 -0
  22. package/src/cli/picker.ts +48 -0
  23. package/src/cli/plain-text.ts +15 -0
  24. package/src/cli/slash-dispatch.test.ts +213 -0
  25. package/src/cli/slash-dispatch.ts +298 -0
  26. package/src/cli/slash.test.ts +113 -0
  27. package/src/cli/slash.ts +119 -0
  28. package/src/cli/theme.test.ts +10 -0
  29. package/src/cli/theme.ts +44 -0
  30. package/src/cli/tui-layout.test.ts +33 -0
  31. package/src/cli/tui-layout.ts +33 -0
  32. package/src/cli/tui-screen.test.ts +33 -0
  33. package/src/cli/tui-screen.ts +13 -0
  34. package/src/cli/tui.tsx +735 -0
  35. package/src/config.ts +86 -0
  36. package/src/core/approval.test.ts +60 -0
  37. package/src/core/approval.ts +83 -0
  38. package/src/core/auto-router.test.ts +31 -0
  39. package/src/core/auto-router.ts +66 -0
  40. package/src/core/errors.ts +67 -0
  41. package/src/core/events.ts +85 -0
  42. package/src/core/hooks.test.ts +66 -0
  43. package/src/core/hooks.ts +94 -0
  44. package/src/core/ids.ts +6 -0
  45. package/src/core/instructions.test.ts +49 -0
  46. package/src/core/instructions.ts +44 -0
  47. package/src/core/logger.ts +45 -0
  48. package/src/core/mcp.ts +191 -0
  49. package/src/core/mode.test.ts +63 -0
  50. package/src/core/mode.ts +60 -0
  51. package/src/core/run-turn.test.ts +339 -0
  52. package/src/core/run-turn.ts +487 -0
  53. package/src/core/session.test.ts +203 -0
  54. package/src/core/session.ts +349 -0
  55. package/src/core/stdio-mcp.ts +143 -0
  56. package/src/core/strands.ts +262 -0
  57. package/src/core/usage.test.ts +69 -0
  58. package/src/core/usage.ts +171 -0
  59. package/src/desktop/bridge.test.ts +331 -0
  60. package/src/desktop/bridge.ts +729 -0
  61. package/src/desktop/open-local.test.ts +40 -0
  62. package/src/desktop/open-local.ts +52 -0
  63. package/src/desktop/preview-cache.test.ts +36 -0
  64. package/src/desktop/preview-cache.ts +63 -0
  65. package/src/desktop/secrets.test.ts +44 -0
  66. package/src/desktop/secrets.ts +60 -0
  67. package/src/evals/runner.test.ts +43 -0
  68. package/src/evals/runner.ts +225 -0
  69. package/src/index.ts +132 -0
  70. package/src/init.test.ts +54 -0
  71. package/src/init.ts +117 -0
  72. package/src/integrations/catalog-data.json +424 -0
  73. package/src/integrations/catalog.ts +81 -0
  74. package/src/integrations/connect.ts +231 -0
  75. package/src/integrations/integrations.test.ts +329 -0
  76. package/src/integrations/marks/airtable.svg +1 -0
  77. package/src/integrations/marks/algolia-mcp.svg +1 -0
  78. package/src/integrations/marks/canva.jpg +0 -0
  79. package/src/integrations/marks/cloudflare-mcp.svg +1 -0
  80. package/src/integrations/marks/contentful-mcp.svg +1 -0
  81. package/src/integrations/marks/craft.png +0 -0
  82. package/src/integrations/marks/dinero.png +0 -0
  83. package/src/integrations/marks/figma.svg +1 -0
  84. package/src/integrations/marks/gitlab.svg +1 -0
  85. package/src/integrations/marks/google-calendar.svg +1 -0
  86. package/src/integrations/marks/google-docs.svg +1 -0
  87. package/src/integrations/marks/google-drive.svg +1 -0
  88. package/src/integrations/marks/google-gmail.svg +1 -0
  89. package/src/integrations/marks/google-sheets.svg +1 -0
  90. package/src/integrations/marks/google-slides.svg +1 -0
  91. package/src/integrations/marks/granola.png +0 -0
  92. package/src/integrations/marks/jira.svg +1 -0
  93. package/src/integrations/marks/linear.svg +1 -0
  94. package/src/integrations/marks/microsoft-365.svg +7 -0
  95. package/src/integrations/marks/miro.svg +1 -0
  96. package/src/integrations/marks/mixpanel-mcp.svg +1 -0
  97. package/src/integrations/marks/monday.png +0 -0
  98. package/src/integrations/marks/mux-mcp.png +0 -0
  99. package/src/integrations/marks/neon-mcp.svg +1 -0
  100. package/src/integrations/marks/notion.svg +1 -0
  101. package/src/integrations/marks/paddle-mcp.svg +1 -0
  102. package/src/integrations/marks/posthog-mcp.svg +1 -0
  103. package/src/integrations/marks/prismic-mcp.svg +1 -0
  104. package/src/integrations/marks/replicate-mcp.svg +1 -0
  105. package/src/integrations/marks/resend-mcp.svg +1 -0
  106. package/src/integrations/marks/sanity-mcp.svg +1 -0
  107. package/src/integrations/marks/sceneplane.png +0 -0
  108. package/src/integrations/marks/sentry-mcp.svg +1 -0
  109. package/src/integrations/marks/stripe-mcp.svg +1 -0
  110. package/src/integrations/marks/supabase-mcp.svg +1 -0
  111. package/src/integrations/marks/upstash-mcp.svg +1 -0
  112. package/src/integrations/marks/vercel.svg +1 -0
  113. package/src/integrations/marks/webflow.svg +1 -0
  114. package/src/integrations/mcp-oauth.test.ts +39 -0
  115. package/src/integrations/mcp-oauth.ts +330 -0
  116. package/src/integrations/oauth-clients.test.ts +77 -0
  117. package/src/integrations/oauth-clients.ts +127 -0
  118. package/src/integrations/oauth.ts +145 -0
  119. package/src/integrations/remote-mcp.ts +307 -0
  120. package/src/integrations/store.ts +149 -0
  121. package/src/media/openrouter-generate.test.ts +80 -0
  122. package/src/media/openrouter-generate.ts +178 -0
  123. package/src/media/prefs.ts +54 -0
  124. package/src/observability/categories.ts +41 -0
  125. package/src/observability/create.test.ts +56 -0
  126. package/src/observability/create.ts +45 -0
  127. package/src/observability/experiments.ts +113 -0
  128. package/src/observability/fake.ts +191 -0
  129. package/src/observability/index.ts +57 -0
  130. package/src/observability/judges.ts +91 -0
  131. package/src/observability/langfuse.ts +275 -0
  132. package/src/observability/noop.ts +33 -0
  133. package/src/observability/observability.test.ts +113 -0
  134. package/src/observability/prompts.ts +98 -0
  135. package/src/observability/regression-items.ts +158 -0
  136. package/src/observability/sanitize.test.ts +26 -0
  137. package/src/observability/sanitize.ts +57 -0
  138. package/src/observability/types.ts +122 -0
  139. package/src/observability/version.ts +41 -0
  140. package/src/product.ts +2 -0
  141. package/src/runtime.test.ts +98 -0
  142. package/src/runtime.ts +438 -0
  143. package/src/skills/author-skill.ts +49 -0
  144. package/src/skills/create-skill.test.ts +108 -0
  145. package/src/skills/create-skill.ts +70 -0
  146. package/src/skills/loader.test.ts +122 -0
  147. package/src/skills/loader.ts +162 -0
  148. package/src/skills/registry.test.ts +190 -0
  149. package/src/skills/registry.ts +402 -0
  150. package/src/skills/skill-command.ts +53 -0
  151. package/src/skills/user-dir.ts +8 -0
  152. package/src/tools/git.test.ts +71 -0
  153. package/src/tools/git.ts +126 -0
  154. package/src/tools/local.ts +258 -0
  155. package/src/tools/paths.test.ts +24 -0
  156. package/src/tools/paths.ts +39 -0
  157. package/src/tools/read-skill.ts +43 -0
  158. package/src/tools/subagent.test.ts +77 -0
  159. package/src/tools/subagent.ts +74 -0
  160. package/src/tools/todo.test.ts +25 -0
  161. package/src/tools/todo.ts +70 -0
@@ -0,0 +1,83 @@
1
+ import { OPENROUTER_DEFAULT_BASE_URL } from "../config.ts";
2
+ import {
3
+ IMAGE_MODELS,
4
+ type MediaModelOption,
5
+ TRANSCRIBE_MODELS,
6
+ VIDEO_MODELS,
7
+ } from "./media-models.ts";
8
+
9
+ export type MediaModality = "image" | "video" | "transcription";
10
+
11
+ const LIVE_TTL_MS = 10 * 60 * 1000;
12
+ const caches = new Map<MediaModality, { expires: number; items: MediaModelOption[] }>();
13
+
14
+ function displayName(id: string, rawName: string): string {
15
+ const trimmed = rawName.trim();
16
+ if (!trimmed) return id;
17
+ const colon = trimmed.indexOf(": ");
18
+ return colon >= 0 ? trimmed.slice(colon + 2) : trimmed;
19
+ }
20
+
21
+ export function fallbackModels(modality: MediaModality): readonly MediaModelOption[] {
22
+ if (modality === "image") return IMAGE_MODELS;
23
+ if (modality === "video") return VIDEO_MODELS;
24
+ return TRANSCRIBE_MODELS;
25
+ }
26
+
27
+ /** Parse `GET /models?output_modalities=` into picker rows. */
28
+ export function parseModalityModels(json: unknown): MediaModelOption[] {
29
+ if (typeof json !== "object" || json === null) return [];
30
+ const data = (json as { data?: unknown }).data;
31
+ if (!Array.isArray(data)) return [];
32
+ const items: MediaModelOption[] = [];
33
+ const seen = new Set<string>();
34
+ for (const item of data) {
35
+ if (typeof item !== "object" || item === null) continue;
36
+ const row = item as Record<string, unknown>;
37
+ const id = typeof row.id === "string" ? row.id.trim() : "";
38
+ if (!id || id.includes(":batch") || seen.has(id)) continue;
39
+ seen.add(id);
40
+ const name = typeof row.name === "string" ? displayName(id, row.name) : id;
41
+ items.push({ id, label: name });
42
+ }
43
+ return items;
44
+ }
45
+
46
+ export function cachedModalityModels(modality: MediaModality): readonly MediaModelOption[] {
47
+ return caches.get(modality)?.items ?? fallbackModels(modality);
48
+ }
49
+
50
+ export async function loadModalityModels(options: {
51
+ modality: MediaModality;
52
+ apiKey: string;
53
+ baseUrl?: string;
54
+ fetchImpl?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
55
+ }): Promise<readonly MediaModelOption[]> {
56
+ const fallback = fallbackModels(options.modality);
57
+ if (!options.apiKey.trim()) return fallback;
58
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
59
+ const useCache = fetchImpl === globalThis.fetch;
60
+ const cached = caches.get(options.modality);
61
+ if (useCache && cached && cached.expires > Date.now()) return cached.items;
62
+ try {
63
+ const base = (options.baseUrl ?? OPENROUTER_DEFAULT_BASE_URL).replace(/\/+$/, "");
64
+ const res = await fetchImpl(
65
+ `${base}/models?output_modalities=${encodeURIComponent(options.modality)}`,
66
+ {
67
+ headers: {
68
+ Authorization: `Bearer ${options.apiKey}`,
69
+ "HTTP-Referer": "https://caelence.com",
70
+ "X-Title": "Caelence agent",
71
+ },
72
+ signal: AbortSignal.timeout(4_000),
73
+ },
74
+ );
75
+ if (!res.ok) return cached?.items ?? fallback;
76
+ const items = parseModalityModels(await res.json());
77
+ if (items.length === 0) return cached?.items ?? fallback;
78
+ if (useCache) caches.set(options.modality, { expires: Date.now() + LIVE_TTL_MS, items });
79
+ return items;
80
+ } catch {
81
+ return cached?.items ?? fallback;
82
+ }
83
+ }
@@ -0,0 +1,53 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import type { Session } from "../core/session.ts";
3
+ import { modelPickerItems } from "./models.ts";
4
+ import { matchListedSession, relativeTime, sessionPickerItems, stepIndex } from "./picker.ts";
5
+
6
+ function session(partial: Partial<Session> & Pick<Session, "id" | "title">): Session {
7
+ return {
8
+ createdAt: "2026-09-14T10:00:00.000Z",
9
+ updatedAt: "2026-09-14T12:00:00.000Z",
10
+ messages: [],
11
+ ...partial,
12
+ };
13
+ }
14
+
15
+ describe("session picker", () => {
16
+ const sessions = [
17
+ session({ id: "ses_a", title: "Fix the nav overlay" }),
18
+ session({ id: "ses_b", title: "Add billing copy" }),
19
+ ];
20
+
21
+ test("labels by title, not id", () => {
22
+ const items = sessionPickerItems(sessions);
23
+ expect(items.map((item) => item.label)).toEqual(["Fix the nav overlay", "Add billing copy"]);
24
+ expect(items.some((item) => item.label.includes("ses_"))).toBe(false);
25
+ });
26
+
27
+ test("matches 1-based index and title", () => {
28
+ expect(matchListedSession(sessions, "2")?.id).toBe("ses_b");
29
+ expect(matchListedSession(sessions, "billing")?.title).toBe("Add billing copy");
30
+ expect(matchListedSession(sessions, "")).toBeUndefined();
31
+ });
32
+
33
+ test("relativeTime uses the stored timestamp", () => {
34
+ expect(relativeTime("2026-09-14T11:00:00.000Z", Date.parse("2026-09-14T12:10:00.000Z"))).toBe(
35
+ "1 h ago",
36
+ );
37
+ });
38
+ });
39
+
40
+ describe("model picker", () => {
41
+ test("includes the current model even if it is not in the catalog", () => {
42
+ const items = modelPickerItems("acme/custom-1");
43
+ expect(items[0]?.id).toBe("acme/custom-1");
44
+ expect(items.some((item) => item.id === "~x-ai/grok-latest")).toBe(true);
45
+ });
46
+ });
47
+
48
+ describe("stepIndex", () => {
49
+ test("wraps", () => {
50
+ expect(stepIndex(0, 3, -1)).toBe(2);
51
+ expect(stepIndex(2, 3, 1)).toBe(0);
52
+ });
53
+ });
@@ -0,0 +1,48 @@
1
+ import type { Session } from "../core/session.ts";
2
+
3
+ export interface PickerItem {
4
+ id: string;
5
+ label: string;
6
+ hint?: string;
7
+ }
8
+
9
+ export function relativeTime(iso: string, now = Date.now()): string {
10
+ const then = Date.parse(iso);
11
+ if (!Number.isFinite(then)) return iso;
12
+ const min = Math.floor((now - then) / 60_000);
13
+ if (min < 1) return "just now";
14
+ if (min < 60) return `${min} min ago`;
15
+ const hours = Math.floor(min / 60);
16
+ if (hours < 24) return `${hours} h ago`;
17
+ return `${Math.floor(hours / 24)} d ago`;
18
+ }
19
+
20
+ export function sessionPickerItems(sessions: Session[], now = Date.now()): PickerItem[] {
21
+ return sessions.map((session) => ({
22
+ id: session.id,
23
+ label: session.title.trim() || "New chat",
24
+ hint: [relativeTime(session.updatedAt, now), session.model].filter(Boolean).join(" · "),
25
+ }));
26
+ }
27
+
28
+ /** Pick by 1-based list index, title, or id. Empty query means open a picker. */
29
+ export function matchListedSession(sessions: Session[], query: string): Session | undefined {
30
+ const value = query.trim();
31
+ if (!value) return undefined;
32
+ if (/^\d+$/.test(value)) {
33
+ const index = Number(value);
34
+ return sessions[index - 1];
35
+ }
36
+ const lower = value.toLowerCase();
37
+ return (
38
+ sessions.find((session) => session.id === value) ??
39
+ sessions.find((session) => session.title.toLowerCase() === lower) ??
40
+ sessions.find((session) => session.title.toLowerCase().startsWith(lower)) ??
41
+ sessions.find((session) => session.title.toLowerCase().includes(lower))
42
+ );
43
+ }
44
+
45
+ export function stepIndex(index: number, count: number, delta: number): number {
46
+ if (count <= 0) return 0;
47
+ return (index + delta + count) % count;
48
+ }
@@ -0,0 +1,15 @@
1
+ /** Strip markdown so a terminal line does not render as `**bold**`. */
2
+ export function plainTerminalText(text: string): string {
3
+ return text
4
+ .replace(/```[\s\S]*?```/g, (block) =>
5
+ block
6
+ .replace(/^```\w*\n?/, "")
7
+ .replace(/```$/, "")
8
+ .trim(),
9
+ )
10
+ .replace(/\*\*([^*]+)\*\*/g, "$1")
11
+ .replace(/__([^_]+)__/g, "$1")
12
+ .replace(/`([^`]+)`/g, "$1")
13
+ .replace(/^#{1,6}\s+/gm, "")
14
+ .replace(/(^|\s)\*([^*\n]+)\*(?=\s|$)/g, "$1$2");
15
+ }
@@ -0,0 +1,213 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { mkdtemp, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import type { Session } from "../core/session.ts";
6
+ import type { HarnessRuntime } from "../runtime.ts";
7
+ import { HARNESS_MODELS } from "./models.ts";
8
+ import { applyPickerChoice, dispatchSlash, runSlashLine } from "./slash-dispatch.ts";
9
+
10
+ function fakeHarness(overrides: Partial<HarnessRuntime> = {}): HarnessRuntime {
11
+ const sessions: Session[] = [
12
+ {
13
+ id: "s1",
14
+ title: "Billing copy",
15
+ createdAt: "2026-01-01T00:00:00.000Z",
16
+ updatedAt: "2026-01-01T00:00:00.000Z",
17
+ model: "openai/gpt-5.6-sol",
18
+ messages: [],
19
+ },
20
+ ];
21
+ return {
22
+ cwd: "/tmp/proj",
23
+ config: { evalsDir: "evals" } as HarnessRuntime["config"],
24
+ theme: {} as HarnessRuntime["theme"],
25
+ skills: [{ name: "copywriting", source: "host" }] as HarnessRuntime["skills"],
26
+ store: {
27
+ async list() {
28
+ return sessions;
29
+ },
30
+ async get(id: string) {
31
+ return sessions.find((session) => session.id === id);
32
+ },
33
+ } as HarnessRuntime["store"],
34
+ systemPrompt: "",
35
+ modelId: "openai/gpt-5.6-sol",
36
+ mode: "agent",
37
+ runTurn: async () => undefined,
38
+ setModel(id) {
39
+ this.modelId = id;
40
+ },
41
+ setMode(mode) {
42
+ this.mode = mode;
43
+ },
44
+ hasApiKey: false,
45
+ setApiKey() {},
46
+ setSession() {},
47
+ allowExecAlways() {},
48
+ allowRiskyAlways() {},
49
+ compact: async () => false,
50
+ reloadSkills() {
51
+ return this.skills;
52
+ },
53
+ authorSkill: async () => ({ rel: "skills/demo/SKILL.md" }),
54
+ findSkills: async () => "frontend-design",
55
+ addSkill: async () => ({ rel: "frontend-design/SKILL.md" }),
56
+ removeSkill: () => ({ ok: true }),
57
+ chat: async () => "",
58
+ observability: {} as HarnessRuntime["observability"],
59
+ close() {},
60
+ ...overrides,
61
+ } as HarnessRuntime;
62
+ }
63
+
64
+ describe("dispatchSlash", () => {
65
+ test("help lists slash commands", async () => {
66
+ const result = await dispatchSlash(fakeHarness(), "/help");
67
+ expect(result.kind).toBe("text");
68
+ if (result.kind === "text") expect(result.text).toContain("/resume");
69
+ });
70
+
71
+ test("resume without an argument opens a title picker", async () => {
72
+ const result = await dispatchSlash(fakeHarness(), "/resume");
73
+ expect(result).toMatchObject({
74
+ kind: "picker",
75
+ picker: "resume",
76
+ });
77
+ if (result.kind === "picker") {
78
+ expect(result.items[0]?.label).toBe("Billing copy");
79
+ expect(result.items[0]?.id).toBe("s1");
80
+ }
81
+ });
82
+
83
+ test("resume matches a title", async () => {
84
+ const result = await dispatchSlash(fakeHarness(), "/resume billing");
85
+ expect(result.kind).toBe("session");
86
+ if (result.kind === "session") expect(result.session.title).toBe("Billing copy");
87
+ });
88
+
89
+ test("model without an argument opens a label picker", async () => {
90
+ const result = await dispatchSlash(fakeHarness(), "/model");
91
+ expect(result.kind).toBe("picker");
92
+ if (result.kind === "picker") {
93
+ expect(result.items.some((item) => item.label === "Auto")).toBe(true);
94
+ expect(result.items.some((item) => item.id === "openrouter/auto")).toBe(true);
95
+ expect(result.items.some((item) => item.label === "Grok latest")).toBe(true);
96
+ expect(result.items.some((item) => item.id === "~x-ai/grok-latest")).toBe(true);
97
+ }
98
+ });
99
+
100
+ test("transcribe without an argument lists Muse, MAI, Voxtral, Qwen, and NVIDIA", async () => {
101
+ const result = await dispatchSlash(fakeHarness(), "/transcribe");
102
+ expect(result.kind).toBe("picker");
103
+ if (result.kind === "picker") {
104
+ const ids = result.items.map((item) => item.id);
105
+ expect(ids).toContain("meta/muse-voice-transcribe-1.0");
106
+ expect(ids).toContain("microsoft/mai-transcribe-2");
107
+ expect(ids).toContain("mistralai/voxtral-mini-transcribe");
108
+ expect(ids).toContain("qwen/qwen3-asr-1.7b");
109
+ expect(ids).toContain("nvidia/parakeet-tdt-0.6b-v3");
110
+ }
111
+ });
112
+
113
+ test("image without a prompt opens a model picker", async () => {
114
+ const result = await dispatchSlash(fakeHarness(), "/image");
115
+ expect(result.kind).toBe("picker");
116
+ if (result.kind === "picker") {
117
+ expect(result.picker).toBe("image");
118
+ expect(result.items.some((item) => item.id === "black-forest-labs/flux.2-pro")).toBe(true);
119
+ }
120
+ });
121
+
122
+ test("image with a prompt generates", async () => {
123
+ const home = await mkdtemp(join(tmpdir(), "harness-media-"));
124
+ const prevHome = process.env.HARNESS_HOME;
125
+ const prevKey = process.env.OPENROUTER_API_KEY;
126
+ const prevFetch = globalThis.fetch;
127
+ process.env.HARNESS_HOME = home;
128
+ process.env.OPENROUTER_API_KEY = "sk-test";
129
+ globalThis.fetch = (async () =>
130
+ new Response(JSON.stringify({ data: [{ b64_json: "aaa" }] }), {
131
+ status: 200,
132
+ headers: { "content-type": "application/json" },
133
+ })) as unknown as typeof fetch;
134
+ try {
135
+ const result = await dispatchSlash(fakeHarness({ hasApiKey: true }), "/image a cat");
136
+ expect(result.kind).toBe("media");
137
+ if (result.kind === "media") {
138
+ expect(result.media.kind).toBe("image");
139
+ expect(result.caption).toContain("Image");
140
+ }
141
+ } finally {
142
+ globalThis.fetch = prevFetch;
143
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
144
+ else process.env.HARNESS_HOME = prevHome;
145
+ if (prevKey === undefined) delete process.env.OPENROUTER_API_KEY;
146
+ else process.env.OPENROUTER_API_KEY = prevKey;
147
+ await rm(home, { recursive: true, force: true });
148
+ }
149
+ });
150
+
151
+ test("image picker stores the model", async () => {
152
+ const home = await mkdtemp(join(tmpdir(), "harness-media-"));
153
+ const prevHome = process.env.HARNESS_HOME;
154
+ process.env.HARNESS_HOME = home;
155
+ try {
156
+ const result = applyPickerChoice(fakeHarness(), "image", "google/gemini-2.5-flash-image");
157
+ expect(result).toEqual({ kind: "applied" });
158
+ } finally {
159
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
160
+ else process.env.HARNESS_HOME = prevHome;
161
+ await rm(home, { recursive: true, force: true });
162
+ }
163
+ });
164
+
165
+ test("mode picker stores the mode without a transcript line", () => {
166
+ const harness = fakeHarness({ mode: "ask" });
167
+ const result = applyPickerChoice(harness, "mode", "agent");
168
+ expect(result).toEqual({ kind: "applied" });
169
+ expect(harness.mode).toBe("agent");
170
+ });
171
+
172
+ test("runSlashLine lists the skill catalog on bare find", async () => {
173
+ expect(await runSlashLine(fakeHarness(), "/skill find")).toEqual({
174
+ kind: "text",
175
+ text: "frontend-design",
176
+ });
177
+ expect(await runSlashLine(fakeHarness(), "/ima")).toEqual({
178
+ kind: "incomplete",
179
+ draft: "/image ",
180
+ });
181
+ expect(await runSlashLine(fakeHarness(), "/asdf")).toEqual({ kind: "hold" });
182
+ });
183
+
184
+ test("settings reports a missing key without opening a picker", async () => {
185
+ const result = await dispatchSlash(fakeHarness({ hasApiKey: false }), "/settings");
186
+ expect(result.kind).toBe("text");
187
+ if (result.kind === "text") {
188
+ expect(result.text).toContain("No key");
189
+ expect(result.text).toContain("/settings key");
190
+ }
191
+ });
192
+
193
+ test("clear starts a new session", async () => {
194
+ let cleared = false;
195
+ const result = await dispatchSlash(
196
+ fakeHarness({
197
+ setSession(id) {
198
+ cleared = id === undefined;
199
+ },
200
+ }),
201
+ "/clear",
202
+ );
203
+ expect(result.kind).toBe("clear");
204
+ expect(cleared).toBe(true);
205
+ });
206
+ });
207
+
208
+ describe("HARNESS_MODELS", () => {
209
+ test("lists Auto first", () => {
210
+ expect(HARNESS_MODELS[0]).toEqual({ id: "openrouter/auto", label: "Auto" });
211
+ expect(HARNESS_MODELS.some((model) => model.id === "openrouter/auto-beta")).toBe(true);
212
+ });
213
+ });