@useavalon/caelence-agent 0.1.0 → 0.1.1-canary.1
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/LICENSE +21 -0
- package/README.md +129 -137
- package/brand/logo/favicon-agent-bg-16.svg +7 -0
- package/brand/logo/favicon-agent-bg-32.svg +7 -0
- package/brand/previews/desktop-chat.png +0 -0
- package/brand/previews/desktop-commands.png +0 -0
- package/brand/previews/desktop-integrations.png +0 -0
- package/brand/previews/desktop-skills.png +0 -0
- package/package.json +5 -3
- package/skills/impeccable/LICENSE +13 -0
- package/skills/impeccable/NOTICE +14 -0
- package/skills/impeccable/SKILL.md +2 -1
- package/src/agent-cwd.ts +51 -0
- package/src/cli/agent-cwd.test.ts +65 -0
- package/src/cli/main.test.ts +5 -0
- package/src/cli/main.ts +282 -201
- package/src/cli/picker.test.ts +59 -1
- package/src/cli/picker.ts +46 -0
- package/src/cli/slash-dispatch.test.ts +116 -7
- package/src/cli/slash-dispatch.ts +343 -174
- package/src/cli/slash.test.ts +25 -2
- package/src/cli/slash.ts +37 -8
- package/src/cli/theme.test.ts +7 -0
- package/src/cli/theme.ts +6 -6
- package/src/cli/tui.tsx +385 -217
- package/src/config.ts +1 -1
- package/src/core/strands.ts +10 -1
- package/src/desktop/bridge.test.ts +56 -1
- package/src/desktop/bridge.ts +527 -390
- package/src/desktop/uploads.test.ts +57 -0
- package/src/desktop/uploads.ts +92 -0
- package/src/index.ts +26 -2
- package/src/init.test.ts +19 -2
- package/src/init.ts +25 -17
- package/src/integrations/loopback.test.ts +17 -0
- package/src/integrations/loopback.ts +91 -0
- package/src/observability/prompts.ts +1 -1
- package/src/product.ts +3 -1
- package/src/runtime.test.ts +24 -0
- package/src/runtime.ts +48 -5
- package/src/skills/catalog.test.ts +188 -0
- package/src/skills/catalog.ts +279 -0
- package/src/skills/disabled.test.ts +27 -0
- package/src/skills/disabled.ts +59 -0
- package/src/skills/loader.test.ts +31 -0
- package/src/skills/loader.ts +31 -4
- package/src/skills/registry.test.ts +64 -3
- package/src/skills/registry.ts +248 -93
- package/src/skills/skill-command.ts +2 -0
package/src/cli/main.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { resolveAgentCwd } from "../agent-cwd.ts";
|
|
5
6
|
import { loadConfig, resolveOpenRouter } from "../config.ts";
|
|
7
|
+
import { errorMessage } from "../core/errors.ts";
|
|
6
8
|
import type { AgentEvent } from "../core/events.ts";
|
|
7
9
|
import { type AgentMode, tryParseAgentMode } from "../core/mode.ts";
|
|
8
10
|
import { formatUsage } from "../core/usage.ts";
|
|
@@ -13,10 +15,23 @@ import { startObservability } from "../observability/create.ts";
|
|
|
13
15
|
import { runLocalExperiment } from "../observability/experiments.ts";
|
|
14
16
|
import { harnessPromptRecords, syncPrompts } from "../observability/prompts.ts";
|
|
15
17
|
import { WEBSITE_GENERATION_REGRESSION } from "../observability/regression-items.ts";
|
|
16
|
-
import { PRODUCT_NAME } from "../product.ts";
|
|
18
|
+
import { CLI_NAME, PRODUCT_NAME } from "../product.ts";
|
|
17
19
|
import { createHarness } from "../runtime.ts";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
+
import { browseSkillCatalog } from "../skills/catalog.ts";
|
|
21
|
+
import { disableSkills } from "../skills/disabled.ts";
|
|
22
|
+
import {
|
|
23
|
+
isBundledCatalogDir,
|
|
24
|
+
loadMergedSkills,
|
|
25
|
+
loadSkills,
|
|
26
|
+
resolveHostSkillDirs,
|
|
27
|
+
} from "../skills/loader.ts";
|
|
28
|
+
import {
|
|
29
|
+
formatBundledHits,
|
|
30
|
+
formatRegistryHits,
|
|
31
|
+
installSkillFromSource,
|
|
32
|
+
removeSkillFromRoots,
|
|
33
|
+
searchSkills,
|
|
34
|
+
} from "../skills/registry.ts";
|
|
20
35
|
import { parseSkillCommand } from "../skills/skill-command.ts";
|
|
21
36
|
import { userSkillsDir } from "../skills/user-dir.ts";
|
|
22
37
|
import { startTui } from "./tui.tsx";
|
|
@@ -25,21 +40,22 @@ function printHelp(): void {
|
|
|
25
40
|
process.stdout.write(`${PRODUCT_NAME}
|
|
26
41
|
|
|
27
42
|
Usage:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
${CLI_NAME} Terminal UI
|
|
44
|
+
${CLI_NAME} desktop Open the desktop window
|
|
45
|
+
${CLI_NAME} chat -m <text> One-shot turn
|
|
46
|
+
${CLI_NAME} eval [name] Run an eval suite (list if omitted)
|
|
47
|
+
${CLI_NAME} experiment Run the local regression dataset (no Langfuse required)
|
|
48
|
+
${CLI_NAME} init Add .harness/ to .gitignore
|
|
49
|
+
${CLI_NAME} skill find [q] Browse bundled and popular skills.sh (query to search)
|
|
50
|
+
${CLI_NAME} skill add <src> Install a bundled or skills.sh skill into ~/.harness/skills
|
|
51
|
+
${CLI_NAME} help This message
|
|
37
52
|
|
|
38
53
|
Flags:
|
|
39
54
|
--mode ask|plan|agent Read-only, plan, or implement (default agent)
|
|
40
|
-
--cwd <path>
|
|
55
|
+
--cwd <path> Workspace folder
|
|
41
56
|
-m, --message <text> Chat message
|
|
42
|
-
--name <name> Init project name
|
|
57
|
+
--name <name> Init project name (with --examples)
|
|
58
|
+
--examples Init: also write config, AGENTS.md, sample skill, eval
|
|
43
59
|
|
|
44
60
|
Modes:
|
|
45
61
|
ask Read the repo. No edits, exec, commit, or task
|
|
@@ -52,10 +68,9 @@ Hooks: session_start, pre_tool (nonzero exit denies), post_tool in harness.confi
|
|
|
52
68
|
|
|
53
69
|
Install in another project:
|
|
54
70
|
bun add github:useAvalon/caelence-agent
|
|
55
|
-
bunx
|
|
56
|
-
bunx harness
|
|
71
|
+
bunx ${CLI_NAME}
|
|
57
72
|
|
|
58
|
-
|
|
73
|
+
Desktop: paste an OpenRouter key in Settings. Optional env: OPENROUTER_API_KEY, OPENROUTER_MODEL, OPENROUTER_BASE_URL
|
|
59
74
|
Optional Langfuse: LANGFUSE_SECRET_KEY, LANGFUSE_PUBLIC_KEY, LANGFUSE_BASE_URL
|
|
60
75
|
Optional LLM-as-judge: LANGFUSE_QUALITY_EVAL=1 (off unless set; spends OpenRouter)
|
|
61
76
|
`);
|
|
@@ -72,11 +87,11 @@ function printEvent(event: AgentEvent): void {
|
|
|
72
87
|
case "tool_call_end":
|
|
73
88
|
process.stderr.write(event.success ? " ok\n" : ` fail ${event.error ?? ""}\n`);
|
|
74
89
|
break;
|
|
75
|
-
case "todos":
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
90
|
+
case "todos": {
|
|
91
|
+
const todos = event.items.map((item) => `${item.status} ${item.content}`).join(" · ");
|
|
92
|
+
process.stderr.write(`\ntodos ${todos}\n`);
|
|
79
93
|
break;
|
|
94
|
+
}
|
|
80
95
|
case "usage":
|
|
81
96
|
process.stderr.write(
|
|
82
97
|
`\n${formatUsage({
|
|
@@ -128,6 +143,7 @@ function takeFlag(args: string[], name: string): { value?: string; rest: string[
|
|
|
128
143
|
|
|
129
144
|
export function parseCliArgs(argv: string[]): {
|
|
130
145
|
cwd: string;
|
|
146
|
+
cwdExplicit: boolean;
|
|
131
147
|
cmd?: string;
|
|
132
148
|
rest: string[];
|
|
133
149
|
name?: string;
|
|
@@ -148,6 +164,7 @@ export function parseCliArgs(argv: string[]): {
|
|
|
148
164
|
const cmd = args[0];
|
|
149
165
|
return {
|
|
150
166
|
cwd: resolve(cwdFlag.value ?? process.cwd()),
|
|
167
|
+
cwdExplicit: cwdFlag.value !== undefined,
|
|
151
168
|
cmd,
|
|
152
169
|
rest: args.slice(1),
|
|
153
170
|
name: nameFlag.value,
|
|
@@ -161,205 +178,219 @@ function resolveCliMode(raw: string | undefined): AgentMode | undefined | "inval
|
|
|
161
178
|
return tryParseAgentMode(raw) ?? "invalid";
|
|
162
179
|
}
|
|
163
180
|
|
|
164
|
-
|
|
165
|
-
const parsed = parseCliArgs(argv);
|
|
166
|
-
const { cwd, cmd, rest } = parsed;
|
|
181
|
+
type ParsedCli = ReturnType<typeof parseCliArgs>;
|
|
167
182
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
183
|
+
function agentCwd(parsed: ParsedCli): string {
|
|
184
|
+
return resolveAgentCwd({
|
|
185
|
+
start: parsed.cwd,
|
|
186
|
+
explicit: parsed.cwdExplicit ? parsed.cwd : undefined,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
172
189
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
});
|
|
190
|
+
async function runDesktop(cwd: string): Promise<number> {
|
|
191
|
+
const desktopDir = resolve(fileURLToPath(new URL("../../desktop", import.meta.url)));
|
|
192
|
+
if (!existsSync(resolve(desktopDir, "package.json"))) {
|
|
193
|
+
process.stderr.write("Desktop app files are missing from this install.\n");
|
|
194
|
+
return 1;
|
|
198
195
|
}
|
|
199
|
-
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
196
|
+
const env = desktopToolchainEnv(desktopDir, cwd);
|
|
197
|
+
if (!hasCargo(env)) {
|
|
198
|
+
process.stderr.write(
|
|
199
|
+
"Rust is required for the desktop window. Install rustup from https://rustup.rs then run caelence desktop again.\n",
|
|
200
|
+
);
|
|
201
|
+
return 1;
|
|
205
202
|
}
|
|
203
|
+
const child = spawn("bun", [resolve(desktopDir, "scripts/run-tauri.ts")], {
|
|
204
|
+
cwd: desktopDir,
|
|
205
|
+
env,
|
|
206
|
+
stdio: "inherit",
|
|
207
|
+
});
|
|
208
|
+
return await new Promise<number>((done) => {
|
|
209
|
+
child.on("exit", (code) => done(code ?? 1));
|
|
210
|
+
child.on("error", (err) => {
|
|
211
|
+
process.stderr.write(`${err.message}\n`);
|
|
212
|
+
done(1);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
206
216
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
217
|
+
function runInit(parsed: ParsedCli): number {
|
|
218
|
+
const examples = parsed.rest.includes("--examples");
|
|
219
|
+
const result = initHost({ cwd: parsed.cwd, name: parsed.name, examples });
|
|
220
|
+
for (const rel of result.created) process.stdout.write(`created ${rel}\n`);
|
|
221
|
+
for (const rel of result.skipped) process.stdout.write(`skipped ${rel}\n`);
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function formatSkillHits(hits: Awaited<ReturnType<typeof browseSkillCatalog>>): string {
|
|
226
|
+
if (hits.length === 0) return "No matches.";
|
|
227
|
+
const bundled = hits.filter((hit) => hit.source === "bundled");
|
|
228
|
+
const remote = hits.filter((hit) => hit.source !== "bundled");
|
|
229
|
+
return [formatBundledHits(bundled), remote.length > 0 ? formatRegistryHits(remote) : ""]
|
|
230
|
+
.filter(Boolean)
|
|
231
|
+
.join("\n");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function runSkillFind(query: string): Promise<number> {
|
|
235
|
+
const text = query ? await searchSkills(query) : formatSkillHits(await browseSkillCatalog());
|
|
236
|
+
process.stdout.write(`${text}\n`);
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async function runSkillAdd(
|
|
241
|
+
cwd: string,
|
|
242
|
+
action: Extract<ReturnType<typeof parseSkillCommand>, { action: "add" }>,
|
|
243
|
+
): Promise<number> {
|
|
244
|
+
const config = action.scope === "project" ? await loadConfig(cwd) : undefined;
|
|
245
|
+
const projectDir = resolve(cwd, config?.skillsDir ?? "skills");
|
|
246
|
+
const destRoot =
|
|
247
|
+
action.scope === "project" && !isBundledCatalogDir(projectDir) ? projectDir : userSkillsDir();
|
|
248
|
+
const result = await installSkillFromSource({
|
|
249
|
+
source: action.source,
|
|
250
|
+
destRoot,
|
|
251
|
+
...(action.skill ? { skill: action.skill } : {}),
|
|
252
|
+
});
|
|
253
|
+
if ("error" in result) {
|
|
254
|
+
const extra = result.choices?.length ? ` Available: ${result.choices.join(", ")}` : "";
|
|
255
|
+
process.stderr.write(`${result.error}${extra}\n`);
|
|
244
256
|
return 1;
|
|
245
257
|
}
|
|
258
|
+
process.stdout.write(`Loaded ${destRoot}/${result.rel}\n`);
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
246
261
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
262
|
+
async function runSkill(cwd: string, rest: string[]): Promise<number> {
|
|
263
|
+
const action = parseSkillCommand(rest.join(" "));
|
|
264
|
+
if ("error" in action) {
|
|
265
|
+
process.stderr.write(`${action.error}\n`);
|
|
266
|
+
return 1;
|
|
267
|
+
}
|
|
268
|
+
if (action.action === "find") return runSkillFind(action.query);
|
|
269
|
+
if (action.action === "add") return runSkillAdd(cwd, action);
|
|
270
|
+
if (action.action === "remove") {
|
|
271
|
+
const roots = [userSkillsDir()];
|
|
272
|
+
const projectSkills = resolve(cwd, "skills");
|
|
273
|
+
if (!isBundledCatalogDir(projectSkills)) roots.push(projectSkills);
|
|
274
|
+
const result = removeSkillFromRoots(action.name, roots);
|
|
275
|
+
if (result.removed) {
|
|
276
|
+
process.stdout.write(`Removed ${action.name}\n`);
|
|
258
277
|
return 0;
|
|
259
278
|
}
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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();
|
|
279
|
+
const loaded = loadMergedSkills(resolveHostSkillDirs(cwd, "skills"), userSkillsDir());
|
|
280
|
+
if (loaded.some((skill) => skill.name.toLowerCase() === action.name.toLowerCase())) {
|
|
281
|
+
disableSkills(cwd, action.name);
|
|
282
|
+
process.stdout.write(`Disabled ${action.name}\n`);
|
|
283
|
+
return 0;
|
|
314
284
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const mode = resolveCliMode(parsed.mode);
|
|
318
|
-
if (mode === "invalid") {
|
|
319
|
-
process.stderr.write("Mode is ask, plan, or agent.\n");
|
|
285
|
+
process.stderr.write(`${result.reason ?? "Could not remove."}\n`);
|
|
320
286
|
return 1;
|
|
321
287
|
}
|
|
288
|
+
process.stderr.write("Use the TUI for /skill new.\n");
|
|
289
|
+
return 1;
|
|
290
|
+
}
|
|
322
291
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
292
|
+
async function runEval(cwd: string, rest: string[]): Promise<number> {
|
|
293
|
+
const config = await loadConfig(cwd);
|
|
294
|
+
const name = rest[0];
|
|
295
|
+
const evalsDir = resolve(cwd, config.evalsDir);
|
|
296
|
+
if (!name) {
|
|
297
|
+
const names = await listEvalSuites(evalsDir);
|
|
298
|
+
if (names.length === 0) {
|
|
299
|
+
process.stderr.write("No eval suites (expected evals/<name>/eval.ts).\n");
|
|
329
300
|
return 1;
|
|
330
301
|
}
|
|
331
|
-
|
|
332
|
-
|
|
302
|
+
process.stdout.write(`${names.join("\n")}\n`);
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
305
|
+
const or = resolveOpenRouter(config);
|
|
306
|
+
const skills = loadSkills(resolve(cwd, config.skillsDir));
|
|
307
|
+
const obs = await startObservability({ enabled: config.observability?.enabled });
|
|
308
|
+
void syncPrompts({ prompts: harnessPromptRecords() });
|
|
309
|
+
try {
|
|
310
|
+
const result = await runNamedEval({
|
|
311
|
+
config,
|
|
333
312
|
cwd,
|
|
334
|
-
|
|
335
|
-
|
|
313
|
+
name,
|
|
314
|
+
skills,
|
|
315
|
+
chat: createOpenRouterChat({ apiKey: or.apiKey, baseUrl: or.baseUrl }),
|
|
316
|
+
observability: obs,
|
|
336
317
|
});
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
: undefined,
|
|
345
|
-
});
|
|
346
|
-
} finally {
|
|
347
|
-
harness.close();
|
|
348
|
-
await harness.observability.shutdown();
|
|
318
|
+
process.stdout.write(`${result.name} ${result.ok ? "ok" : "fail"}\n`);
|
|
319
|
+
for (const step of result.steps) {
|
|
320
|
+
const mark = step.ok ? "ok" : "fail";
|
|
321
|
+
const detail = step.detail ? ` ${step.detail}` : "";
|
|
322
|
+
process.stdout.write(` ${step.id} ${mark}${detail}\n`);
|
|
349
323
|
}
|
|
350
|
-
return 0;
|
|
324
|
+
return result.ok ? 0 : 1;
|
|
325
|
+
} finally {
|
|
326
|
+
await obs.shutdown();
|
|
351
327
|
}
|
|
328
|
+
}
|
|
352
329
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
330
|
+
function experimentBrief(input: unknown): string {
|
|
331
|
+
if (!input || typeof input !== "object" || !("brief" in input)) return "";
|
|
332
|
+
const brief = (input as { brief?: unknown }).brief;
|
|
333
|
+
return typeof brief === "string" ? brief : "";
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async function runExperiment(cwd: string): Promise<number> {
|
|
337
|
+
const config = await loadConfig(cwd);
|
|
338
|
+
const obs = await startObservability({ enabled: config.observability?.enabled });
|
|
339
|
+
void syncPrompts({ prompts: harnessPromptRecords() });
|
|
340
|
+
try {
|
|
341
|
+
const result = await runLocalExperiment({
|
|
342
|
+
name: "website-generation-regression",
|
|
343
|
+
observability: obs,
|
|
344
|
+
items: WEBSITE_GENERATION_REGRESSION,
|
|
345
|
+
task: async (item) => item.input,
|
|
346
|
+
evaluators: [
|
|
347
|
+
{
|
|
348
|
+
name: "has_brief",
|
|
349
|
+
run: ({ input }) => {
|
|
350
|
+
const brief = experimentBrief(input);
|
|
351
|
+
return { value: brief.trim().length > 0 ? 1 : 0 };
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
});
|
|
356
|
+
process.stdout.write(
|
|
357
|
+
`${result.name} ${result.ok ? "ok" : "fail"} items=${result.itemResults.length} has_brief=${result.aggregates.has_brief ?? 0}\n`,
|
|
358
|
+
);
|
|
359
|
+
return result.ok ? 0 : 1;
|
|
360
|
+
} finally {
|
|
361
|
+
await obs.shutdown();
|
|
356
362
|
}
|
|
363
|
+
}
|
|
357
364
|
|
|
358
|
-
|
|
359
|
-
|
|
365
|
+
async function runChat(parsed: ParsedCli, mode: AgentMode | undefined): Promise<number> {
|
|
366
|
+
const message = parsed.message;
|
|
367
|
+
if (!message) {
|
|
368
|
+
process.stderr.write("harness chat -m <text>\n");
|
|
360
369
|
return 1;
|
|
361
370
|
}
|
|
371
|
+
const tty = Boolean(process.stdin.isTTY);
|
|
372
|
+
const harness = await createHarness({
|
|
373
|
+
cwd: agentCwd(parsed),
|
|
374
|
+
approvalPolicy: tty ? undefined : "deny",
|
|
375
|
+
...(mode ? { mode } : {}),
|
|
376
|
+
});
|
|
377
|
+
try {
|
|
378
|
+
await harness.runTurn(message, printEvent, {
|
|
379
|
+
approvalAsk: tty
|
|
380
|
+
? async (req) => {
|
|
381
|
+
process.stderr.write(`Approve ${req.toolName}? [y/N] `);
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
: undefined,
|
|
385
|
+
});
|
|
386
|
+
} finally {
|
|
387
|
+
harness.close();
|
|
388
|
+
await harness.observability.shutdown();
|
|
389
|
+
}
|
|
390
|
+
return 0;
|
|
391
|
+
}
|
|
362
392
|
|
|
393
|
+
async function runTui(cwd: string, mode: AgentMode | undefined): Promise<number> {
|
|
363
394
|
const harness = await createHarness({
|
|
364
395
|
cwd,
|
|
365
396
|
...(mode ? { mode } : {}),
|
|
@@ -373,12 +404,62 @@ export async function main(argv = process.argv.slice(2)): Promise<number> {
|
|
|
373
404
|
return 0;
|
|
374
405
|
}
|
|
375
406
|
|
|
407
|
+
const COMMANDS: Record<string, (parsed: ParsedCli) => Promise<number>> = {
|
|
408
|
+
help: async () => {
|
|
409
|
+
printHelp();
|
|
410
|
+
return 0;
|
|
411
|
+
},
|
|
412
|
+
"--help": async () => {
|
|
413
|
+
printHelp();
|
|
414
|
+
return 0;
|
|
415
|
+
},
|
|
416
|
+
"-h": async () => {
|
|
417
|
+
printHelp();
|
|
418
|
+
return 0;
|
|
419
|
+
},
|
|
420
|
+
desktop: async (parsed) => runDesktop(agentCwd(parsed)),
|
|
421
|
+
init: async (parsed) => runInit(parsed),
|
|
422
|
+
skill: async (parsed) => runSkill(parsed.cwd, parsed.rest),
|
|
423
|
+
eval: async (parsed) => runEval(parsed.cwd, parsed.rest),
|
|
424
|
+
experiment: async (parsed) => runExperiment(parsed.cwd),
|
|
425
|
+
chat: async (parsed) => {
|
|
426
|
+
const mode = resolveCliMode(parsed.mode);
|
|
427
|
+
if (mode === "invalid") {
|
|
428
|
+
process.stderr.write("Mode is ask, plan, or agent.\n");
|
|
429
|
+
return 1;
|
|
430
|
+
}
|
|
431
|
+
applyStoredOpenRouterKey();
|
|
432
|
+
return runChat(parsed, mode);
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
export async function main(argv = process.argv.slice(2)): Promise<number> {
|
|
437
|
+
const parsed = parseCliArgs(argv);
|
|
438
|
+
const { cmd } = parsed;
|
|
439
|
+
if (!cmd) {
|
|
440
|
+
const mode = resolveCliMode(parsed.mode);
|
|
441
|
+
if (mode === "invalid") {
|
|
442
|
+
process.stderr.write("Mode is ask, plan, or agent.\n");
|
|
443
|
+
return 1;
|
|
444
|
+
}
|
|
445
|
+
applyStoredOpenRouterKey();
|
|
446
|
+
return runTui(agentCwd(parsed), mode);
|
|
447
|
+
}
|
|
448
|
+
const handler = COMMANDS[cmd];
|
|
449
|
+
if (handler) return handler(parsed);
|
|
450
|
+
if (cmd.startsWith("-")) {
|
|
451
|
+
process.stderr.write(`Unknown flag ${cmd}. Try harness help.\n`);
|
|
452
|
+
return 1;
|
|
453
|
+
}
|
|
454
|
+
process.stderr.write(`Unknown command ${cmd}. Try harness help.\n`);
|
|
455
|
+
return 1;
|
|
456
|
+
}
|
|
457
|
+
|
|
376
458
|
if (import.meta.main) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
);
|
|
459
|
+
try {
|
|
460
|
+
process.exit(await main());
|
|
461
|
+
} catch (err) {
|
|
462
|
+
process.stderr.write(`${errorMessage(err)}\n`);
|
|
463
|
+
process.exit(1);
|
|
464
|
+
}
|
|
384
465
|
}
|
package/src/cli/picker.test.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import type { Session } from "../core/session.ts";
|
|
3
3
|
import { modelPickerItems } from "./models.ts";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
inkPickerNav,
|
|
6
|
+
matchListedSession,
|
|
7
|
+
paintPickerLine,
|
|
8
|
+
pickerPage,
|
|
9
|
+
pickerVisibleRows,
|
|
10
|
+
relativeTime,
|
|
11
|
+
sessionPickerItems,
|
|
12
|
+
stepIndex,
|
|
13
|
+
} from "./picker.ts";
|
|
5
14
|
|
|
6
15
|
function session(partial: Partial<Session> & Pick<Session, "id" | "title">): Session {
|
|
7
16
|
return {
|
|
@@ -51,3 +60,52 @@ describe("stepIndex", () => {
|
|
|
51
60
|
expect(stepIndex(2, 3, 1)).toBe(0);
|
|
52
61
|
});
|
|
53
62
|
});
|
|
63
|
+
|
|
64
|
+
describe("pickerPage", () => {
|
|
65
|
+
test("keeps the selection in a short window", () => {
|
|
66
|
+
const items = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
|
|
67
|
+
expect(pickerPage(items, 0, 4)).toEqual({ items: ["a", "b", "c", "d"], offset: 0 });
|
|
68
|
+
expect(pickerPage(items, 9, 4)).toEqual({ items: ["g", "h", "i", "j"], offset: 6 });
|
|
69
|
+
expect(pickerPage(items, 5, 4)).toEqual({ items: ["d", "e", "f", "g"], offset: 3 });
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("pickerVisibleRows", () => {
|
|
74
|
+
test("uses the terminal height instead of a fixed 8-row window", () => {
|
|
75
|
+
expect(pickerVisibleRows(12)).toBe(6);
|
|
76
|
+
expect(pickerVisibleRows(40)).toBe(34);
|
|
77
|
+
expect(pickerVisibleRows(4)).toBe(4);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("inkPickerNav", () => {
|
|
82
|
+
const blank = {
|
|
83
|
+
escape: false,
|
|
84
|
+
upArrow: false,
|
|
85
|
+
downArrow: false,
|
|
86
|
+
tab: false,
|
|
87
|
+
shift: false,
|
|
88
|
+
return: false,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
test("moves on arrows even when escape is also set", () => {
|
|
92
|
+
expect(inkPickerNav({ ...blank, escape: true, upArrow: true })).toBe(-1);
|
|
93
|
+
expect(inkPickerNav({ ...blank, escape: true, downArrow: true })).toBe(1);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("cancels on a bare escape", () => {
|
|
97
|
+
expect(inkPickerNav({ ...blank, escape: true })).toBe("esc");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("paintPickerLine", () => {
|
|
102
|
+
test("pads a short connect hint over a longer leftover", () => {
|
|
103
|
+
const previous = paintPickerLine(" Neon · on · disconnect", 28);
|
|
104
|
+
const next = paintPickerLine(" Neon · connect", 28);
|
|
105
|
+
expect(previous).toContain("disconnect");
|
|
106
|
+
expect(next).toHaveLength(28);
|
|
107
|
+
expect(next).toContain("connect");
|
|
108
|
+
expect(next).not.toContain("disconnect");
|
|
109
|
+
expect(next).not.toContain("connectnect");
|
|
110
|
+
});
|
|
111
|
+
});
|