@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.
- package/README.md +201 -0
- package/bin/harness.ts +10 -0
- package/package.json +75 -0
- package/skills/copy-editor/SKILL.md +74 -0
- package/skills/copy-editor/references/anti-slop.md +62 -0
- package/skills/copy-editor/references/ui-states.md +46 -0
- package/skills/copy-editor/scripts/lint-copy.py +78 -0
- package/skills/copy-harry-dry/SKILL.md +120 -0
- package/skills/copy-rmbc/SKILL.md +97 -0
- package/skills/copywriting/SKILL.md +73 -0
- package/skills/impeccable/SKILL.md +133 -0
- package/skills/impeccable/references/visual-slop.md +36 -0
- package/src/cli/main.test.ts +36 -0
- package/src/cli/main.ts +384 -0
- package/src/cli/media-models.ts +82 -0
- package/src/cli/models.ts +43 -0
- package/src/cli/openrouter-live.test.ts +35 -0
- package/src/cli/openrouter-live.ts +72 -0
- package/src/cli/openrouter-modality.test.ts +25 -0
- package/src/cli/openrouter-modality.ts +83 -0
- package/src/cli/picker.test.ts +53 -0
- package/src/cli/picker.ts +48 -0
- package/src/cli/plain-text.ts +15 -0
- package/src/cli/slash-dispatch.test.ts +213 -0
- package/src/cli/slash-dispatch.ts +298 -0
- package/src/cli/slash.test.ts +113 -0
- package/src/cli/slash.ts +119 -0
- package/src/cli/theme.test.ts +10 -0
- package/src/cli/theme.ts +44 -0
- package/src/cli/tui-layout.test.ts +33 -0
- package/src/cli/tui-layout.ts +33 -0
- package/src/cli/tui-screen.test.ts +33 -0
- package/src/cli/tui-screen.ts +13 -0
- package/src/cli/tui.tsx +735 -0
- package/src/config.ts +86 -0
- package/src/core/approval.test.ts +60 -0
- package/src/core/approval.ts +83 -0
- package/src/core/auto-router.test.ts +31 -0
- package/src/core/auto-router.ts +66 -0
- package/src/core/errors.ts +67 -0
- package/src/core/events.ts +85 -0
- package/src/core/hooks.test.ts +66 -0
- package/src/core/hooks.ts +94 -0
- package/src/core/ids.ts +6 -0
- package/src/core/instructions.test.ts +49 -0
- package/src/core/instructions.ts +44 -0
- package/src/core/logger.ts +45 -0
- package/src/core/mcp.ts +191 -0
- package/src/core/mode.test.ts +63 -0
- package/src/core/mode.ts +60 -0
- package/src/core/run-turn.test.ts +339 -0
- package/src/core/run-turn.ts +487 -0
- package/src/core/session.test.ts +203 -0
- package/src/core/session.ts +349 -0
- package/src/core/stdio-mcp.ts +143 -0
- package/src/core/strands.ts +262 -0
- package/src/core/usage.test.ts +69 -0
- package/src/core/usage.ts +171 -0
- package/src/desktop/bridge.test.ts +331 -0
- package/src/desktop/bridge.ts +729 -0
- package/src/desktop/open-local.test.ts +40 -0
- package/src/desktop/open-local.ts +52 -0
- package/src/desktop/preview-cache.test.ts +36 -0
- package/src/desktop/preview-cache.ts +63 -0
- package/src/desktop/secrets.test.ts +44 -0
- package/src/desktop/secrets.ts +60 -0
- package/src/evals/runner.test.ts +43 -0
- package/src/evals/runner.ts +225 -0
- package/src/index.ts +132 -0
- package/src/init.test.ts +54 -0
- package/src/init.ts +117 -0
- package/src/integrations/catalog-data.json +424 -0
- package/src/integrations/catalog.ts +81 -0
- package/src/integrations/connect.ts +231 -0
- package/src/integrations/integrations.test.ts +329 -0
- package/src/integrations/marks/airtable.svg +1 -0
- package/src/integrations/marks/algolia-mcp.svg +1 -0
- package/src/integrations/marks/canva.jpg +0 -0
- package/src/integrations/marks/cloudflare-mcp.svg +1 -0
- package/src/integrations/marks/contentful-mcp.svg +1 -0
- package/src/integrations/marks/craft.png +0 -0
- package/src/integrations/marks/dinero.png +0 -0
- package/src/integrations/marks/figma.svg +1 -0
- package/src/integrations/marks/gitlab.svg +1 -0
- package/src/integrations/marks/google-calendar.svg +1 -0
- package/src/integrations/marks/google-docs.svg +1 -0
- package/src/integrations/marks/google-drive.svg +1 -0
- package/src/integrations/marks/google-gmail.svg +1 -0
- package/src/integrations/marks/google-sheets.svg +1 -0
- package/src/integrations/marks/google-slides.svg +1 -0
- package/src/integrations/marks/granola.png +0 -0
- package/src/integrations/marks/jira.svg +1 -0
- package/src/integrations/marks/linear.svg +1 -0
- package/src/integrations/marks/microsoft-365.svg +7 -0
- package/src/integrations/marks/miro.svg +1 -0
- package/src/integrations/marks/mixpanel-mcp.svg +1 -0
- package/src/integrations/marks/monday.png +0 -0
- package/src/integrations/marks/mux-mcp.png +0 -0
- package/src/integrations/marks/neon-mcp.svg +1 -0
- package/src/integrations/marks/notion.svg +1 -0
- package/src/integrations/marks/paddle-mcp.svg +1 -0
- package/src/integrations/marks/posthog-mcp.svg +1 -0
- package/src/integrations/marks/prismic-mcp.svg +1 -0
- package/src/integrations/marks/replicate-mcp.svg +1 -0
- package/src/integrations/marks/resend-mcp.svg +1 -0
- package/src/integrations/marks/sanity-mcp.svg +1 -0
- package/src/integrations/marks/sceneplane.png +0 -0
- package/src/integrations/marks/sentry-mcp.svg +1 -0
- package/src/integrations/marks/stripe-mcp.svg +1 -0
- package/src/integrations/marks/supabase-mcp.svg +1 -0
- package/src/integrations/marks/upstash-mcp.svg +1 -0
- package/src/integrations/marks/vercel.svg +1 -0
- package/src/integrations/marks/webflow.svg +1 -0
- package/src/integrations/mcp-oauth.test.ts +39 -0
- package/src/integrations/mcp-oauth.ts +330 -0
- package/src/integrations/oauth-clients.test.ts +77 -0
- package/src/integrations/oauth-clients.ts +127 -0
- package/src/integrations/oauth.ts +145 -0
- package/src/integrations/remote-mcp.ts +307 -0
- package/src/integrations/store.ts +149 -0
- package/src/media/openrouter-generate.test.ts +80 -0
- package/src/media/openrouter-generate.ts +178 -0
- package/src/media/prefs.ts +54 -0
- package/src/observability/categories.ts +41 -0
- package/src/observability/create.test.ts +56 -0
- package/src/observability/create.ts +45 -0
- package/src/observability/experiments.ts +113 -0
- package/src/observability/fake.ts +191 -0
- package/src/observability/index.ts +57 -0
- package/src/observability/judges.ts +91 -0
- package/src/observability/langfuse.ts +275 -0
- package/src/observability/noop.ts +33 -0
- package/src/observability/observability.test.ts +113 -0
- package/src/observability/prompts.ts +98 -0
- package/src/observability/regression-items.ts +158 -0
- package/src/observability/sanitize.test.ts +26 -0
- package/src/observability/sanitize.ts +57 -0
- package/src/observability/types.ts +122 -0
- package/src/observability/version.ts +41 -0
- package/src/product.ts +2 -0
- package/src/runtime.test.ts +98 -0
- package/src/runtime.ts +438 -0
- package/src/skills/author-skill.ts +49 -0
- package/src/skills/create-skill.test.ts +108 -0
- package/src/skills/create-skill.ts +70 -0
- package/src/skills/loader.test.ts +122 -0
- package/src/skills/loader.ts +162 -0
- package/src/skills/registry.test.ts +190 -0
- package/src/skills/registry.ts +402 -0
- package/src/skills/skill-command.ts +53 -0
- package/src/skills/user-dir.ts +8 -0
- package/src/tools/git.test.ts +71 -0
- package/src/tools/git.ts +126 -0
- package/src/tools/local.ts +258 -0
- package/src/tools/paths.test.ts +24 -0
- package/src/tools/paths.ts +39 -0
- package/src/tools/read-skill.ts +43 -0
- package/src/tools/subagent.test.ts +77 -0
- package/src/tools/subagent.ts +74 -0
- package/src/tools/todo.test.ts +25 -0
- package/src/tools/todo.ts +70 -0
package/src/cli/main.ts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { loadConfig, resolveOpenRouter } from "../config.ts";
|
|
6
|
+
import type { AgentEvent } from "../core/events.ts";
|
|
7
|
+
import { type AgentMode, tryParseAgentMode } from "../core/mode.ts";
|
|
8
|
+
import { formatUsage } from "../core/usage.ts";
|
|
9
|
+
import { applyStoredOpenRouterKey } from "../desktop/secrets.ts";
|
|
10
|
+
import { createOpenRouterChat, listEvalSuites, runNamedEval } from "../evals/runner.ts";
|
|
11
|
+
import { initHost } from "../init.ts";
|
|
12
|
+
import { startObservability } from "../observability/create.ts";
|
|
13
|
+
import { runLocalExperiment } from "../observability/experiments.ts";
|
|
14
|
+
import { harnessPromptRecords, syncPrompts } from "../observability/prompts.ts";
|
|
15
|
+
import { WEBSITE_GENERATION_REGRESSION } from "../observability/regression-items.ts";
|
|
16
|
+
import { PRODUCT_NAME } from "../product.ts";
|
|
17
|
+
import { createHarness } from "../runtime.ts";
|
|
18
|
+
import { loadSkills } from "../skills/loader.ts";
|
|
19
|
+
import { installSkillFromSource, removeSkillFromRoots, searchSkills } from "../skills/registry.ts";
|
|
20
|
+
import { parseSkillCommand } from "../skills/skill-command.ts";
|
|
21
|
+
import { userSkillsDir } from "../skills/user-dir.ts";
|
|
22
|
+
import { startTui } from "./tui.tsx";
|
|
23
|
+
|
|
24
|
+
function printHelp(): void {
|
|
25
|
+
process.stdout.write(`${PRODUCT_NAME}
|
|
26
|
+
|
|
27
|
+
Usage:
|
|
28
|
+
harness Fullscreen terminal UI
|
|
29
|
+
harness desktop Open the desktop window
|
|
30
|
+
harness chat -m <text> One-shot turn
|
|
31
|
+
harness eval [name] Run an eval suite (list if omitted)
|
|
32
|
+
harness experiment Run the local regression dataset (no Langfuse required)
|
|
33
|
+
harness init Write host project files
|
|
34
|
+
harness skill find [q] Search bundled skills and skills.sh
|
|
35
|
+
harness skill add <src> Install a bundled or skills.sh skill into ~/.harness/skills
|
|
36
|
+
harness help This message
|
|
37
|
+
|
|
38
|
+
Flags:
|
|
39
|
+
--mode ask|plan|agent Read-only, plan, or implement (default agent)
|
|
40
|
+
--cwd <path> Project root
|
|
41
|
+
-m, --message <text> Chat message
|
|
42
|
+
--name <name> Init project name
|
|
43
|
+
|
|
44
|
+
Modes:
|
|
45
|
+
ask Read the repo. No edits, exec, commit, or task
|
|
46
|
+
plan Read plus todo_write. No edits
|
|
47
|
+
agent Full tools, including approved exec and git_commit
|
|
48
|
+
|
|
49
|
+
Instructions: ~/.harness/AGENTS.md (or HARNESS_USER_INSTRUCTIONS) then project AGENTS.md
|
|
50
|
+
Git tools: git_status, git_diff, git_log, git_commit (approval, no push)
|
|
51
|
+
Hooks: session_start, pre_tool (nonzero exit denies), post_tool in harness.config.ts
|
|
52
|
+
|
|
53
|
+
Install in another project:
|
|
54
|
+
bun add github:useAvalon/caelence-agent
|
|
55
|
+
bunx harness init
|
|
56
|
+
bunx harness
|
|
57
|
+
|
|
58
|
+
Env: OPENROUTER_API_KEY, optional OPENROUTER_MODEL, OPENROUTER_BASE_URL
|
|
59
|
+
Optional Langfuse: LANGFUSE_SECRET_KEY, LANGFUSE_PUBLIC_KEY, LANGFUSE_BASE_URL
|
|
60
|
+
Optional LLM-as-judge: LANGFUSE_QUALITY_EVAL=1 (off unless set; spends OpenRouter)
|
|
61
|
+
`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function printEvent(event: AgentEvent): void {
|
|
65
|
+
switch (event.kind) {
|
|
66
|
+
case "text_delta":
|
|
67
|
+
process.stdout.write(event.text);
|
|
68
|
+
break;
|
|
69
|
+
case "tool_call_start":
|
|
70
|
+
process.stderr.write(`\n› ${event.toolName}\n`);
|
|
71
|
+
break;
|
|
72
|
+
case "tool_call_end":
|
|
73
|
+
process.stderr.write(event.success ? " ok\n" : ` fail ${event.error ?? ""}\n`);
|
|
74
|
+
break;
|
|
75
|
+
case "todos":
|
|
76
|
+
process.stderr.write(
|
|
77
|
+
`\ntodos ${event.items.map((item) => `${item.status} ${item.content}`).join(" · ")}\n`,
|
|
78
|
+
);
|
|
79
|
+
break;
|
|
80
|
+
case "usage":
|
|
81
|
+
process.stderr.write(
|
|
82
|
+
`\n${formatUsage({
|
|
83
|
+
promptTokens: event.promptTokens,
|
|
84
|
+
completionTokens: event.completionTokens,
|
|
85
|
+
totalTokens: event.totalTokens,
|
|
86
|
+
...(event.costUsd !== undefined ? { costUsd: event.costUsd } : {}),
|
|
87
|
+
})}\n`,
|
|
88
|
+
);
|
|
89
|
+
break;
|
|
90
|
+
case "error":
|
|
91
|
+
process.stderr.write(`\n${event.message}\n`);
|
|
92
|
+
break;
|
|
93
|
+
case "completion":
|
|
94
|
+
process.stdout.write("\n");
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function desktopToolchainEnv(desktopDir: string, cwd: string): NodeJS.ProcessEnv {
|
|
102
|
+
const cargoHome = resolve(desktopDir, ".toolchain/cargo");
|
|
103
|
+
const rustupHome = resolve(desktopDir, ".toolchain/rustup");
|
|
104
|
+
const cargoBin = resolve(cargoHome, "bin");
|
|
105
|
+
const env: NodeJS.ProcessEnv = { ...process.env, HARNESS_CWD: cwd };
|
|
106
|
+
if (existsSync(resolve(cargoBin, "cargo"))) {
|
|
107
|
+
env.CARGO_HOME = cargoHome;
|
|
108
|
+
env.RUSTUP_HOME = rustupHome;
|
|
109
|
+
env.PATH = `${cargoBin}:${env.PATH ?? ""}`;
|
|
110
|
+
}
|
|
111
|
+
return env;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function hasCargo(env: NodeJS.ProcessEnv): boolean {
|
|
115
|
+
if (env.CARGO_HOME && existsSync(resolve(env.CARGO_HOME, "bin/cargo"))) return true;
|
|
116
|
+
return (env.PATH ?? "").split(":").some((dir) => dir && existsSync(resolve(dir, "cargo")));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function takeFlag(args: string[], name: string): { value?: string; rest: string[] } {
|
|
120
|
+
const idx = args.indexOf(name);
|
|
121
|
+
if (idx < 0) return { rest: args };
|
|
122
|
+
const value = args[idx + 1];
|
|
123
|
+
return {
|
|
124
|
+
value,
|
|
125
|
+
rest: [...args.slice(0, idx), ...args.slice(idx + 2)],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function parseCliArgs(argv: string[]): {
|
|
130
|
+
cwd: string;
|
|
131
|
+
cmd?: string;
|
|
132
|
+
rest: string[];
|
|
133
|
+
name?: string;
|
|
134
|
+
message?: string;
|
|
135
|
+
mode?: string;
|
|
136
|
+
} {
|
|
137
|
+
let args = argv;
|
|
138
|
+
const cwdFlag = takeFlag(args, "--cwd");
|
|
139
|
+
args = cwdFlag.rest;
|
|
140
|
+
const nameFlag = takeFlag(args, "--name");
|
|
141
|
+
args = nameFlag.rest;
|
|
142
|
+
const modeFlag = takeFlag(args, "--mode");
|
|
143
|
+
args = modeFlag.rest;
|
|
144
|
+
const shortMsg = takeFlag(args, "-m");
|
|
145
|
+
args = shortMsg.rest;
|
|
146
|
+
const longMsg = takeFlag(args, "--message");
|
|
147
|
+
args = longMsg.rest;
|
|
148
|
+
const cmd = args[0];
|
|
149
|
+
return {
|
|
150
|
+
cwd: resolve(cwdFlag.value ?? process.cwd()),
|
|
151
|
+
cmd,
|
|
152
|
+
rest: args.slice(1),
|
|
153
|
+
name: nameFlag.value,
|
|
154
|
+
message: shortMsg.value ?? longMsg.value,
|
|
155
|
+
mode: modeFlag.value,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function resolveCliMode(raw: string | undefined): AgentMode | undefined | "invalid" {
|
|
160
|
+
if (raw === undefined) return undefined;
|
|
161
|
+
return tryParseAgentMode(raw) ?? "invalid";
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function main(argv = process.argv.slice(2)): Promise<number> {
|
|
165
|
+
const parsed = parseCliArgs(argv);
|
|
166
|
+
const { cwd, cmd, rest } = parsed;
|
|
167
|
+
|
|
168
|
+
if (cmd === "help" || cmd === "--help" || cmd === "-h") {
|
|
169
|
+
printHelp();
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (cmd === "desktop") {
|
|
174
|
+
const desktopDir = resolve(fileURLToPath(new URL("../../desktop", import.meta.url)));
|
|
175
|
+
if (!existsSync(resolve(desktopDir, "package.json"))) {
|
|
176
|
+
process.stderr.write("Desktop app files are missing from this install.\n");
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
const env = desktopToolchainEnv(desktopDir, cwd);
|
|
180
|
+
if (!hasCargo(env)) {
|
|
181
|
+
process.stderr.write(
|
|
182
|
+
"Rust is required for the desktop window. Install rustup from https://rustup.rs then run harness desktop again.\n",
|
|
183
|
+
);
|
|
184
|
+
return 1;
|
|
185
|
+
}
|
|
186
|
+
const child = spawn("bun", ["x", "tauri", "dev"], {
|
|
187
|
+
cwd: desktopDir,
|
|
188
|
+
env,
|
|
189
|
+
stdio: "inherit",
|
|
190
|
+
});
|
|
191
|
+
return await new Promise<number>((done) => {
|
|
192
|
+
child.on("exit", (code) => done(code ?? 1));
|
|
193
|
+
child.on("error", (err) => {
|
|
194
|
+
process.stderr.write(`${err.message}\n`);
|
|
195
|
+
done(1);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (cmd === "init") {
|
|
201
|
+
const result = initHost({ cwd, name: parsed.name });
|
|
202
|
+
for (const rel of result.created) process.stdout.write(`created ${rel}\n`);
|
|
203
|
+
for (const rel of result.skipped) process.stdout.write(`skipped ${rel}\n`);
|
|
204
|
+
return 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (cmd === "skill") {
|
|
208
|
+
const action = parseSkillCommand(rest.join(" "));
|
|
209
|
+
if ("error" in action) {
|
|
210
|
+
process.stderr.write(`${action.error}\n`);
|
|
211
|
+
return 1;
|
|
212
|
+
}
|
|
213
|
+
if (action.action === "find") {
|
|
214
|
+
process.stdout.write(`${await searchSkills(action.query)}\n`);
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
if (action.action === "add") {
|
|
218
|
+
const config = action.scope === "project" ? await loadConfig(cwd) : undefined;
|
|
219
|
+
const destRoot =
|
|
220
|
+
action.scope === "project" ? resolve(cwd, config?.skillsDir ?? "skills") : userSkillsDir();
|
|
221
|
+
const result = await installSkillFromSource({
|
|
222
|
+
source: action.source,
|
|
223
|
+
destRoot,
|
|
224
|
+
...(action.skill ? { skill: action.skill } : {}),
|
|
225
|
+
});
|
|
226
|
+
if ("error" in result) {
|
|
227
|
+
const extra = result.choices?.length ? ` Available: ${result.choices.join(", ")}` : "";
|
|
228
|
+
process.stderr.write(`${result.error}${extra}\n`);
|
|
229
|
+
return 1;
|
|
230
|
+
}
|
|
231
|
+
process.stdout.write(`Loaded ${destRoot}/${result.rel}\n`);
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
if (action.action === "remove") {
|
|
235
|
+
const result = removeSkillFromRoots(action.name, [userSkillsDir(), resolve(cwd, "skills")]);
|
|
236
|
+
if (!result.removed) {
|
|
237
|
+
process.stderr.write(`${result.reason ?? "Could not remove."}\n`);
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
process.stdout.write(`Removed ${action.name}\n`);
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
process.stderr.write("Use the TUI for /skill new.\n");
|
|
244
|
+
return 1;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (cmd === "eval") {
|
|
248
|
+
const config = await loadConfig(cwd);
|
|
249
|
+
const name = rest[0];
|
|
250
|
+
const evalsDir = resolve(cwd, config.evalsDir);
|
|
251
|
+
if (!name) {
|
|
252
|
+
const names = await listEvalSuites(evalsDir);
|
|
253
|
+
if (names.length === 0) {
|
|
254
|
+
process.stderr.write("No eval suites (expected evals/<name>/eval.ts).\n");
|
|
255
|
+
return 1;
|
|
256
|
+
}
|
|
257
|
+
process.stdout.write(`${names.join("\n")}\n`);
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
const or = resolveOpenRouter(config);
|
|
261
|
+
const skills = loadSkills(resolve(cwd, config.skillsDir));
|
|
262
|
+
const obs = await startObservability({ enabled: config.observability?.enabled });
|
|
263
|
+
void syncPrompts({ prompts: harnessPromptRecords() });
|
|
264
|
+
try {
|
|
265
|
+
const result = await runNamedEval({
|
|
266
|
+
config,
|
|
267
|
+
cwd,
|
|
268
|
+
name,
|
|
269
|
+
skills,
|
|
270
|
+
chat: createOpenRouterChat({ apiKey: or.apiKey, baseUrl: or.baseUrl }),
|
|
271
|
+
observability: obs,
|
|
272
|
+
});
|
|
273
|
+
process.stdout.write(`${result.name} ${result.ok ? "ok" : "fail"}\n`);
|
|
274
|
+
for (const step of result.steps) {
|
|
275
|
+
process.stdout.write(
|
|
276
|
+
` ${step.id} ${step.ok ? "ok" : "fail"}${step.detail ? ` ${step.detail}` : ""}\n`,
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
return result.ok ? 0 : 1;
|
|
280
|
+
} finally {
|
|
281
|
+
await obs.shutdown();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (cmd === "experiment") {
|
|
286
|
+
const config = await loadConfig(cwd);
|
|
287
|
+
const obs = await startObservability({ enabled: config.observability?.enabled });
|
|
288
|
+
void syncPrompts({ prompts: harnessPromptRecords() });
|
|
289
|
+
try {
|
|
290
|
+
const result = await runLocalExperiment({
|
|
291
|
+
name: "website-generation-regression",
|
|
292
|
+
observability: obs,
|
|
293
|
+
items: WEBSITE_GENERATION_REGRESSION,
|
|
294
|
+
task: async (item) => item.input,
|
|
295
|
+
evaluators: [
|
|
296
|
+
{
|
|
297
|
+
name: "has_brief",
|
|
298
|
+
run: ({ input }) => {
|
|
299
|
+
const brief =
|
|
300
|
+
input && typeof input === "object" && "brief" in input
|
|
301
|
+
? String((input as { brief?: unknown }).brief ?? "")
|
|
302
|
+
: "";
|
|
303
|
+
return { value: brief.trim().length > 0 ? 1 : 0 };
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
});
|
|
308
|
+
process.stdout.write(
|
|
309
|
+
`${result.name} ${result.ok ? "ok" : "fail"} items=${result.itemResults.length} has_brief=${result.aggregates.has_brief ?? 0}\n`,
|
|
310
|
+
);
|
|
311
|
+
return result.ok ? 0 : 1;
|
|
312
|
+
} finally {
|
|
313
|
+
await obs.shutdown();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const mode = resolveCliMode(parsed.mode);
|
|
318
|
+
if (mode === "invalid") {
|
|
319
|
+
process.stderr.write("Mode is ask, plan, or agent.\n");
|
|
320
|
+
return 1;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
applyStoredOpenRouterKey();
|
|
324
|
+
|
|
325
|
+
if (cmd === "chat") {
|
|
326
|
+
const message = parsed.message;
|
|
327
|
+
if (!message) {
|
|
328
|
+
process.stderr.write("harness chat -m <text>\n");
|
|
329
|
+
return 1;
|
|
330
|
+
}
|
|
331
|
+
const tty = Boolean(process.stdin.isTTY);
|
|
332
|
+
const harness = await createHarness({
|
|
333
|
+
cwd,
|
|
334
|
+
approvalPolicy: tty ? undefined : "deny",
|
|
335
|
+
...(mode ? { mode } : {}),
|
|
336
|
+
});
|
|
337
|
+
try {
|
|
338
|
+
await harness.runTurn(message, printEvent, {
|
|
339
|
+
approvalAsk: tty
|
|
340
|
+
? async (req) => {
|
|
341
|
+
process.stderr.write(`Approve ${req.toolName}? [y/N] `);
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
: undefined,
|
|
345
|
+
});
|
|
346
|
+
} finally {
|
|
347
|
+
harness.close();
|
|
348
|
+
await harness.observability.shutdown();
|
|
349
|
+
}
|
|
350
|
+
return 0;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (cmd?.startsWith("-")) {
|
|
354
|
+
process.stderr.write(`Unknown flag ${cmd}. Try harness help.\n`);
|
|
355
|
+
return 1;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (cmd) {
|
|
359
|
+
process.stderr.write(`Unknown command ${cmd}. Try harness help.\n`);
|
|
360
|
+
return 1;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const harness = await createHarness({
|
|
364
|
+
cwd,
|
|
365
|
+
...(mode ? { mode } : {}),
|
|
366
|
+
});
|
|
367
|
+
try {
|
|
368
|
+
await startTui(harness);
|
|
369
|
+
} finally {
|
|
370
|
+
harness.close();
|
|
371
|
+
await harness.observability.shutdown();
|
|
372
|
+
}
|
|
373
|
+
return 0;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (import.meta.main) {
|
|
377
|
+
main().then(
|
|
378
|
+
(code) => process.exit(code),
|
|
379
|
+
(err) => {
|
|
380
|
+
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
381
|
+
process.exit(1);
|
|
382
|
+
},
|
|
383
|
+
);
|
|
384
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface MediaModelOption {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** Offline seed. The picker prefers the live OpenRouter catalog. */
|
|
8
|
+
export const IMAGE_MODELS: readonly MediaModelOption[] = [
|
|
9
|
+
{ id: "black-forest-labs/flux.2-pro", label: "Flux 2 Pro" },
|
|
10
|
+
{ id: "black-forest-labs/flux.2-flex", label: "Flux 2 Flex" },
|
|
11
|
+
{ id: "google/gemini-2.5-flash-image", label: "Gemini Flash Image" },
|
|
12
|
+
{ id: "bytedance/seedream-4.5", label: "Seedream 4.5" },
|
|
13
|
+
{ id: "openai/gpt-5-image", label: "GPT image" },
|
|
14
|
+
{ id: "meta/muse-image", label: "Muse Image" },
|
|
15
|
+
{ id: "microsoft/mai-image-2.6", label: "MAI Image" },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export const VIDEO_MODELS: readonly MediaModelOption[] = [
|
|
19
|
+
{ id: "google/veo-3.1-lite", label: "Veo 3.1 Lite" },
|
|
20
|
+
{ id: "google/veo-3.1", label: "Veo 3.1" },
|
|
21
|
+
{ id: "bytedance/seedance-2.0-mini", label: "Seedance 2 Mini" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export const TRANSCRIBE_MODELS: readonly MediaModelOption[] = [
|
|
25
|
+
{ id: "openai/whisper-1", label: "Whisper" },
|
|
26
|
+
{ id: "openai/whisper-large-v3", label: "Whisper Large V3" },
|
|
27
|
+
{ id: "openai/whisper-large-v3-turbo", label: "Whisper Large V3 Turbo" },
|
|
28
|
+
{ id: "openai/gpt-4o-mini-transcribe", label: "GPT-4o mini transcribe" },
|
|
29
|
+
{ id: "openai/gpt-4o-transcribe", label: "GPT-4o transcribe" },
|
|
30
|
+
{ id: "openai/gpt-transcribe", label: "GPT Transcribe" },
|
|
31
|
+
{ id: "meta/muse-voice-transcribe-1.0", label: "Muse Voice Transcribe" },
|
|
32
|
+
{ id: "microsoft/mai-transcribe-2", label: "MAI Transcribe 2" },
|
|
33
|
+
{ id: "microsoft/mai-transcribe-1.5", label: "MAI Transcribe 1.5" },
|
|
34
|
+
{ id: "mistralai/voxtral-mini-transcribe", label: "Voxtral Mini Transcribe" },
|
|
35
|
+
{ id: "mistralai/voxtral-mini-3b-2507", label: "Voxtral Mini" },
|
|
36
|
+
{ id: "mistralai/voxtral-small-24b-2507-stt", label: "Voxtral Small STT" },
|
|
37
|
+
{ id: "qwen/qwen3-asr-1.7b", label: "Qwen3 ASR 1.7B" },
|
|
38
|
+
{ id: "qwen/qwen3-asr-0.6b", label: "Qwen3 ASR 0.6B" },
|
|
39
|
+
{ id: "qwen/qwen3-asr-flash-2026-02-10", label: "Qwen3 ASR Flash" },
|
|
40
|
+
{ id: "nvidia/nemotron-3.5-asr-streaming-multilingual-0.6b", label: "Nemotron ASR" },
|
|
41
|
+
{ id: "nvidia/parakeet-tdt-0.6b-v3", label: "Parakeet TDT" },
|
|
42
|
+
{ id: "google/chirp-3", label: "Chirp 3" },
|
|
43
|
+
{ id: "x-ai/grok-stt-1.0", label: "Grok STT" },
|
|
44
|
+
{ id: "deepgram/nova-3", label: "Deepgram Nova 3" },
|
|
45
|
+
{ id: "fish-audio/transcribe-1", label: "Fish Transcribe" },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export const DEFAULT_IMAGE_MODEL = "black-forest-labs/flux.2-pro";
|
|
49
|
+
export const DEFAULT_VIDEO_MODEL = "google/veo-3.1-lite";
|
|
50
|
+
export const DEFAULT_TRANSCRIBE_MODEL = "openai/whisper-1";
|
|
51
|
+
|
|
52
|
+
export function mediaPickerItems(
|
|
53
|
+
list: readonly MediaModelOption[],
|
|
54
|
+
current?: string,
|
|
55
|
+
): Array<{ id: string; label: string; hint?: string }> {
|
|
56
|
+
const items = list.map((model) => ({
|
|
57
|
+
id: model.id,
|
|
58
|
+
label: model.label,
|
|
59
|
+
...(model.hint ? { hint: model.hint } : {}),
|
|
60
|
+
}));
|
|
61
|
+
const id = current?.trim();
|
|
62
|
+
if (id && !items.some((item) => item.id === id)) {
|
|
63
|
+
items.unshift({ id, label: id, hint: "current" });
|
|
64
|
+
}
|
|
65
|
+
return items;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function mediaModelLabel(list: readonly MediaModelOption[], id: string): string {
|
|
69
|
+
return list.find((model) => model.id === id)?.label ?? id;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function formatMediaComposerLine(prefs: {
|
|
73
|
+
imageModel: string;
|
|
74
|
+
videoModel: string;
|
|
75
|
+
transcribeModel: string;
|
|
76
|
+
}): string {
|
|
77
|
+
return [
|
|
78
|
+
`Image ${mediaModelLabel(IMAGE_MODELS, prefs.imageModel)}`,
|
|
79
|
+
`Clip ${mediaModelLabel(VIDEO_MODELS, prefs.videoModel)}`,
|
|
80
|
+
`Speech ${mediaModelLabel(TRANSCRIBE_MODELS, prefs.transcribeModel)}`,
|
|
81
|
+
].join(" · ");
|
|
82
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface ModelOption {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Default OpenRouter slugs offered in the composer. */
|
|
7
|
+
export const HARNESS_MODELS: readonly ModelOption[] = [
|
|
8
|
+
{ id: "openrouter/auto", label: "Auto" },
|
|
9
|
+
{ id: "openrouter/auto-beta", label: "Auto beta" },
|
|
10
|
+
{ id: "~x-ai/grok-latest", label: "Grok latest" },
|
|
11
|
+
{ id: "~anthropic/claude-fable-latest", label: "Claude Fable latest" },
|
|
12
|
+
{ id: "~anthropic/claude-opus-latest", label: "Claude Opus latest" },
|
|
13
|
+
{ id: "~anthropic/claude-sonnet-latest", label: "Claude Sonnet latest" },
|
|
14
|
+
{ id: "openai/gpt-5.6-sol", label: "GPT-5.6 Sol" },
|
|
15
|
+
{ id: "openai/gpt-5.6-terra", label: "GPT-5.6 Terra" },
|
|
16
|
+
{ id: "google/gemini-3.1-pro-preview", label: "Gemini 3.1 Pro" },
|
|
17
|
+
{ id: "~z-ai/glm-latest", label: "GLM latest" },
|
|
18
|
+
{ id: "deepseek/deepseek-v4-pro-0813", label: "DeepSeek V4 Pro" },
|
|
19
|
+
{ id: "~deepseek/deepseek-v4-flash-latest", label: "DeepSeek V4 Flash latest" },
|
|
20
|
+
{ id: "openai/gpt-5.6-luna", label: "GPT-5.6 Luna" },
|
|
21
|
+
{ id: "~google/gemini-flash-latest", label: "Gemini Flash latest" },
|
|
22
|
+
{ id: "anthropic/claude-haiku-4.5", label: "Claude Haiku 4.5" },
|
|
23
|
+
{ id: "~moonshotai/kimi-latest", label: "Kimi latest" },
|
|
24
|
+
{ id: "moonshotai/kimi-k2.7-code", label: "Kimi K2.7 Code" },
|
|
25
|
+
{ id: "qwen/qwen3-coder-next", label: "Qwen3 Coder" },
|
|
26
|
+
{ id: "z-ai/glm-5.2", label: "GLM 5.2" },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export function modelPickerItems(
|
|
30
|
+
current?: string,
|
|
31
|
+
live?: ReadonlyMap<string, string>,
|
|
32
|
+
): Array<{ id: string; label: string; hint?: string }> {
|
|
33
|
+
const items = HARNESS_MODELS.map((model) => {
|
|
34
|
+
const target = live?.get(model.id)?.trim();
|
|
35
|
+
const hint = target && target.toLowerCase() !== model.label.toLowerCase() ? target : undefined;
|
|
36
|
+
return { id: model.id, label: model.label, ...(hint ? { hint } : {}) };
|
|
37
|
+
});
|
|
38
|
+
const id = current?.trim();
|
|
39
|
+
if (id && !items.some((item) => item.id === id)) {
|
|
40
|
+
items.unshift({ id, label: live?.get(id) ?? id, hint: "current" });
|
|
41
|
+
}
|
|
42
|
+
return items;
|
|
43
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { modelPickerItems } from "./models.ts";
|
|
3
|
+
import { parseLiveTargetNames } from "./openrouter-live.ts";
|
|
4
|
+
|
|
5
|
+
describe("parseLiveTargetNames", () => {
|
|
6
|
+
test("reads alias_target names the way OpenRouter sends them", () => {
|
|
7
|
+
const names = parseLiveTargetNames({
|
|
8
|
+
data: [
|
|
9
|
+
{
|
|
10
|
+
id: "~x-ai/grok-latest",
|
|
11
|
+
name: "xAI: Grok Latest",
|
|
12
|
+
alias_target: { slug: "x-ai/grok-4.6", name: "xAI: Grok 4.6" },
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "openai/gpt-5.6-sol",
|
|
16
|
+
name: "OpenAI: GPT-5.6 Sol",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
});
|
|
20
|
+
expect(names.get("~x-ai/grok-latest")).toBe("Grok 4.6");
|
|
21
|
+
expect(names.get("openai/gpt-5.6-sol")).toBe("GPT-5.6 Sol");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("model picker live names", () => {
|
|
26
|
+
test("uses the OpenRouter target as the hint, not the slug", () => {
|
|
27
|
+
const items = modelPickerItems(
|
|
28
|
+
"~x-ai/grok-latest",
|
|
29
|
+
new Map([["~x-ai/grok-latest", "Grok 4.6"]]),
|
|
30
|
+
);
|
|
31
|
+
const grok = items.find((item) => item.id === "~x-ai/grok-latest");
|
|
32
|
+
expect(grok?.label).toBe("Grok latest");
|
|
33
|
+
expect(grok?.hint).toBe("Grok 4.6");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { OPENROUTER_DEFAULT_BASE_URL } from "../config.ts";
|
|
2
|
+
|
|
3
|
+
const LIVE_TTL_MS = 10 * 60 * 1000;
|
|
4
|
+
const EMPTY = new Map<string, string>();
|
|
5
|
+
|
|
6
|
+
let cache: { expires: number; names: Map<string, string> } | null = null;
|
|
7
|
+
|
|
8
|
+
function displayName(id: string, rawName: string): string {
|
|
9
|
+
const trimmed = rawName.trim();
|
|
10
|
+
if (!trimmed) return id;
|
|
11
|
+
const colon = trimmed.indexOf(": ");
|
|
12
|
+
return colon >= 0 ? trimmed.slice(colon + 2) : trimmed;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Human name of the concrete model a `~latest` alias currently resolves to. */
|
|
16
|
+
export function parseLiveTargetNames(json: unknown): Map<string, string> {
|
|
17
|
+
const names = new Map<string, string>();
|
|
18
|
+
if (typeof json !== "object" || json === null) return names;
|
|
19
|
+
const data = (json as { data?: unknown }).data;
|
|
20
|
+
if (!Array.isArray(data)) return names;
|
|
21
|
+
for (const item of data) {
|
|
22
|
+
if (typeof item !== "object" || item === null) continue;
|
|
23
|
+
const row = item as Record<string, unknown>;
|
|
24
|
+
const id = typeof row.id === "string" ? row.id : "";
|
|
25
|
+
if (!id) continue;
|
|
26
|
+
const target = row.alias_target;
|
|
27
|
+
if (typeof target === "object" && target !== null) {
|
|
28
|
+
const name = (target as { name?: unknown }).name;
|
|
29
|
+
const slug = (target as { slug?: unknown }).slug;
|
|
30
|
+
if (typeof name === "string" && name.trim()) {
|
|
31
|
+
names.set(id, displayName(typeof slug === "string" ? slug : id, name));
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof row.name === "string" && row.name.trim()) {
|
|
36
|
+
names.set(id, displayName(id, row.name));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return names;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function cachedLiveTargetNames(): ReadonlyMap<string, string> {
|
|
43
|
+
return cache?.names ?? EMPTY;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function loadLiveTargetNames(options: {
|
|
47
|
+
apiKey: string;
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
fetchImpl?: typeof fetch;
|
|
50
|
+
}): Promise<ReadonlyMap<string, string>> {
|
|
51
|
+
if (!options.apiKey.trim()) return EMPTY;
|
|
52
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
53
|
+
const useCache = fetchImpl === globalThis.fetch;
|
|
54
|
+
if (useCache && cache && cache.expires > Date.now()) return cache.names;
|
|
55
|
+
try {
|
|
56
|
+
const base = (options.baseUrl ?? OPENROUTER_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
57
|
+
const res = await fetchImpl(`${base}/models`, {
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
60
|
+
"HTTP-Referer": "https://caelence.com",
|
|
61
|
+
"X-Title": "Caelence agent",
|
|
62
|
+
},
|
|
63
|
+
signal: AbortSignal.timeout(4_000),
|
|
64
|
+
});
|
|
65
|
+
if (!res.ok) return cache?.names ?? EMPTY;
|
|
66
|
+
const names = parseLiveTargetNames(await res.json());
|
|
67
|
+
if (useCache) cache = { expires: Date.now() + LIVE_TTL_MS, names };
|
|
68
|
+
return names;
|
|
69
|
+
} catch {
|
|
70
|
+
return cache?.names ?? EMPTY;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { parseModalityModels } from "./openrouter-modality.ts";
|
|
3
|
+
|
|
4
|
+
describe("parseModalityModels", () => {
|
|
5
|
+
test("keeps Muse, MAI, Voxtral, Qwen, and NVIDIA transcription slugs", () => {
|
|
6
|
+
const items = parseModalityModels({
|
|
7
|
+
data: [
|
|
8
|
+
{ id: "meta/muse-voice-transcribe-1.0", name: "Meta: Muse Voice Transcribe 1.0" },
|
|
9
|
+
{ id: "microsoft/mai-transcribe-2", name: "Microsoft AI: MAI-Transcribe 2" },
|
|
10
|
+
{ id: "mistralai/voxtral-mini-transcribe", name: "Mistral: Voxtral Mini Transcribe" },
|
|
11
|
+
{ id: "qwen/qwen3-asr-1.7b", name: "Qwen: Qwen3 ASR 1.7B" },
|
|
12
|
+
{ id: "nvidia/parakeet-tdt-0.6b-v3", name: "NVIDIA: Parakeet TDT 0.6B v3" },
|
|
13
|
+
{ id: "openai/whisper-1:batch", name: "Whisper batch" },
|
|
14
|
+
],
|
|
15
|
+
});
|
|
16
|
+
expect(items.map((item) => item.id)).toEqual([
|
|
17
|
+
"meta/muse-voice-transcribe-1.0",
|
|
18
|
+
"microsoft/mai-transcribe-2",
|
|
19
|
+
"mistralai/voxtral-mini-transcribe",
|
|
20
|
+
"qwen/qwen3-asr-1.7b",
|
|
21
|
+
"nvidia/parakeet-tdt-0.6b-v3",
|
|
22
|
+
]);
|
|
23
|
+
expect(items[0]?.label).toBe("Muse Voice Transcribe 1.0");
|
|
24
|
+
});
|
|
25
|
+
});
|