@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
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { resolveOpenRouter } from "../config.ts";
|
|
2
|
+
import { errorMessage } from "../core/errors.ts";
|
|
2
3
|
import { AGENT_MODES, tryParseAgentMode } from "../core/mode.ts";
|
|
3
4
|
import type { Session } from "../core/session.ts";
|
|
4
5
|
import { maskSecret, writeOpenRouterKey } from "../desktop/secrets.ts";
|
|
5
6
|
import { listEvalSuites, runNamedEval } from "../evals/runner.ts";
|
|
7
|
+
import { connectMcp } from "../integrations/connect.ts";
|
|
8
|
+
import { withOAuthLoopback } from "../integrations/loopback.ts";
|
|
9
|
+
import {
|
|
10
|
+
listPublicIntegrations,
|
|
11
|
+
type PublicIntegration,
|
|
12
|
+
removeConnection,
|
|
13
|
+
} from "../integrations/store.ts";
|
|
6
14
|
import { type GeneratedMedia, generateImage, generateVideo } from "../media/openrouter-generate.ts";
|
|
7
15
|
import { readMediaPrefs, writeMediaPrefs } from "../media/prefs.ts";
|
|
8
16
|
import type { HarnessRuntime } from "../runtime.ts";
|
|
17
|
+
import { browseSkillCatalog } from "../skills/catalog.ts";
|
|
18
|
+
import { searchSkillCatalog, skillCatalogRef, skillIsCatalogHit } from "../skills/registry.ts";
|
|
9
19
|
import { parseSkillCommand, SKILL_COMMAND_USAGE } from "../skills/skill-command.ts";
|
|
10
20
|
import { type MediaModelOption, mediaModelLabel, mediaPickerItems } from "./media-models.ts";
|
|
11
21
|
import { modelPickerItems } from "./models.ts";
|
|
@@ -14,7 +24,15 @@ import { loadModalityModels, type MediaModality } from "./openrouter-modality.ts
|
|
|
14
24
|
import { matchListedSession, type PickerItem, sessionPickerItems } from "./picker.ts";
|
|
15
25
|
import { formatSkillList, parseSlashLine, resolveSlashSubmit, SLASH_HELP } from "./slash.ts";
|
|
16
26
|
|
|
17
|
-
export type SlashPickerKind =
|
|
27
|
+
export type SlashPickerKind =
|
|
28
|
+
| "model"
|
|
29
|
+
| "mode"
|
|
30
|
+
| "resume"
|
|
31
|
+
| "image"
|
|
32
|
+
| "video"
|
|
33
|
+
| "transcribe"
|
|
34
|
+
| "skill"
|
|
35
|
+
| "integration";
|
|
18
36
|
|
|
19
37
|
export type SlashOutcome =
|
|
20
38
|
| { kind: "text"; text: string }
|
|
@@ -34,6 +52,8 @@ const PICKER_KINDS = new Set<SlashPickerKind>([
|
|
|
34
52
|
"image",
|
|
35
53
|
"video",
|
|
36
54
|
"transcribe",
|
|
55
|
+
"skill",
|
|
56
|
+
"integration",
|
|
37
57
|
]);
|
|
38
58
|
|
|
39
59
|
export function isSlashPickerKind(value: unknown): value is SlashPickerKind {
|
|
@@ -90,181 +110,333 @@ async function generateMediaOutcome(
|
|
|
90
110
|
caption: `Clip · ${mediaModelLabel(models, prefs.videoModel)}`,
|
|
91
111
|
};
|
|
92
112
|
} catch (err) {
|
|
93
|
-
return { kind: "text", text:
|
|
113
|
+
return { kind: "text", text: errorMessage(err) };
|
|
94
114
|
}
|
|
95
115
|
}
|
|
96
116
|
|
|
117
|
+
function skillPickerItems(
|
|
118
|
+
hits: Awaited<ReturnType<typeof searchSkillCatalog>>,
|
|
119
|
+
loaded: Array<{ name: string; source: string; catalogRef?: string }>,
|
|
120
|
+
disabled: string[] = [],
|
|
121
|
+
): PickerItem[] {
|
|
122
|
+
const off = new Set(disabled.map((name) => name.toLowerCase()));
|
|
123
|
+
return hits.map((hit) => {
|
|
124
|
+
const current = loaded.find((skill) => skillIsCatalogHit(skill, hit));
|
|
125
|
+
let hint = "add";
|
|
126
|
+
if (off.has(hit.name.toLowerCase())) hint = "off · enable";
|
|
127
|
+
else if (current?.source === "user") hint = "on · remove";
|
|
128
|
+
else if (current) hint = "on · disable";
|
|
129
|
+
else if (hit.source === "bundled") hint = "add · bundled";
|
|
130
|
+
else if (hit.source) hint = `add · ${hit.source}`;
|
|
131
|
+
return { id: skillCatalogRef(hit), label: hit.name, hint };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function integrationPickerItems(items: PublicIntegration[]): PickerItem[] {
|
|
136
|
+
return items.map((item) => {
|
|
137
|
+
let hint = "connect";
|
|
138
|
+
if (item.connected) hint = "on · disconnect";
|
|
139
|
+
else if (item.auth === "desktop") hint = "connect · figma desktop";
|
|
140
|
+
else if (item.auth === "google" || item.auth === "microsoft") hint = "connect · oauth client";
|
|
141
|
+
return { id: item.id, label: item.label, hint };
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function matchPublicIntegration(query: string): PublicIntegration | undefined {
|
|
146
|
+
const items = listPublicIntegrations();
|
|
147
|
+
const q = query.trim().toLowerCase();
|
|
148
|
+
if (!q) return undefined;
|
|
149
|
+
return (
|
|
150
|
+
items.find((item) => item.id.toLowerCase() === q) ??
|
|
151
|
+
items.find((item) => item.label.toLowerCase() === q) ??
|
|
152
|
+
items.find(
|
|
153
|
+
(item) => item.id.toLowerCase().startsWith(q) || item.label.toLowerCase().startsWith(q),
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function toggleIntegration(
|
|
159
|
+
harness: HarnessRuntime,
|
|
160
|
+
id: string,
|
|
161
|
+
): Promise<{ kind: "text"; text: string }> {
|
|
162
|
+
const item = matchPublicIntegration(id);
|
|
163
|
+
if (!item) return { kind: "text", text: `No integration ${JSON.stringify(id)}.` };
|
|
164
|
+
if (item.connected) {
|
|
165
|
+
removeConnection(item.id);
|
|
166
|
+
await harness.reloadIntegrations();
|
|
167
|
+
return { kind: "text", text: `Disconnected ${item.label}` };
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
await withOAuthLoopback(async ({ redirectUri, waitForCallback }) => {
|
|
171
|
+
await connectMcp({ connectorId: item.id, redirectUri, waitForCallback });
|
|
172
|
+
});
|
|
173
|
+
await harness.reloadIntegrations();
|
|
174
|
+
return { kind: "text", text: `Connected ${item.label}` };
|
|
175
|
+
} catch (err) {
|
|
176
|
+
return { kind: "text", text: errorMessage(err) };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
type SlashHandler = (harness: HarnessRuntime, arg: string, cmd: string) => Promise<SlashOutcome>;
|
|
181
|
+
|
|
182
|
+
async function handleIntegrations(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
183
|
+
if (!arg) {
|
|
184
|
+
const items = listPublicIntegrations();
|
|
185
|
+
return {
|
|
186
|
+
kind: "picker",
|
|
187
|
+
title: "Integrations",
|
|
188
|
+
picker: "integration",
|
|
189
|
+
items: integrationPickerItems(items),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return toggleIntegration(harness, arg);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function handleSkillFind(harness: HarnessRuntime, query: string): Promise<SlashOutcome> {
|
|
196
|
+
const hits = query ? await searchSkillCatalog(query) : await browseSkillCatalog();
|
|
197
|
+
const items = skillPickerItems(hits, harness.skills, harness.disabledSkills());
|
|
198
|
+
if (items.length === 0) return { kind: "text", text: "No matches." };
|
|
199
|
+
return {
|
|
200
|
+
kind: "picker",
|
|
201
|
+
title: query ? `Skills · ${query}` : "Skills",
|
|
202
|
+
picker: "skill",
|
|
203
|
+
items,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function handleSkillSlash(
|
|
208
|
+
harness: HarnessRuntime,
|
|
209
|
+
arg: string,
|
|
210
|
+
cmd: string,
|
|
211
|
+
): Promise<SlashOutcome> {
|
|
212
|
+
const payload = cmd === "skill" ? arg : `${cmd.slice("skill ".length)} ${arg}`.trim();
|
|
213
|
+
const parsed = parseSkillCommand(payload);
|
|
214
|
+
if ("error" in parsed) return { kind: "text", text: parsed.error };
|
|
215
|
+
if (parsed.action === "find") return handleSkillFind(harness, parsed.query);
|
|
216
|
+
if (parsed.action === "add") {
|
|
217
|
+
const result = await harness.addSkill(parsed.source, {
|
|
218
|
+
scope: parsed.scope,
|
|
219
|
+
...(parsed.skill ? { skill: parsed.skill } : {}),
|
|
220
|
+
});
|
|
221
|
+
return { kind: "text", text: "error" in result ? result.error : `Loaded ${result.rel}` };
|
|
222
|
+
}
|
|
223
|
+
if (parsed.action === "remove") {
|
|
224
|
+
const loaded = harness.skills.find(
|
|
225
|
+
(skill) => skill.name.toLowerCase() === parsed.name.toLowerCase(),
|
|
226
|
+
);
|
|
227
|
+
const result = harness.removeSkill(parsed.name);
|
|
228
|
+
const verb = loaded && loaded.source !== "user" ? "Disabled" : "Removed";
|
|
229
|
+
return {
|
|
230
|
+
kind: "text",
|
|
231
|
+
text: result.ok ? `${verb} ${parsed.name}` : (result.error ?? "Could not remove."),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (parsed.action === "new") {
|
|
235
|
+
const result = await harness.authorSkill(parsed.name, parsed.brief);
|
|
236
|
+
return { kind: "text", text: "error" in result ? result.error : `Wrote ${result.rel}` };
|
|
237
|
+
}
|
|
238
|
+
return { kind: "text", text: SKILL_COMMAND_USAGE };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function handleModel(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
242
|
+
if (arg) {
|
|
243
|
+
harness.setModel(arg);
|
|
244
|
+
return { kind: "applied" };
|
|
245
|
+
}
|
|
246
|
+
const live = harness.hasApiKey
|
|
247
|
+
? await loadLiveTargetNames(resolveOpenRouter(harness.config))
|
|
248
|
+
: undefined;
|
|
249
|
+
return {
|
|
250
|
+
kind: "picker",
|
|
251
|
+
title: "Model",
|
|
252
|
+
picker: "model",
|
|
253
|
+
items: modelPickerItems(harness.modelId, live),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function handleMode(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
258
|
+
if (arg) {
|
|
259
|
+
const next = tryParseAgentMode(arg);
|
|
260
|
+
if (!next) return { kind: "text", text: "Mode is ask, plan, or agent." };
|
|
261
|
+
harness.setMode(next);
|
|
262
|
+
return { kind: "applied" };
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
kind: "picker",
|
|
266
|
+
title: "Mode",
|
|
267
|
+
picker: "mode",
|
|
268
|
+
items: AGENT_MODES.map((item) => ({ id: item, label: item })),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function handleMediaPicker(
|
|
273
|
+
harness: HarnessRuntime,
|
|
274
|
+
arg: string,
|
|
275
|
+
kind: "image" | "video",
|
|
276
|
+
): Promise<SlashOutcome> {
|
|
277
|
+
if (arg) return generateMediaOutcome(harness, kind, arg);
|
|
278
|
+
const prefs = readMediaPrefs();
|
|
279
|
+
const selected = kind === "image" ? prefs.imageModel : prefs.videoModel;
|
|
280
|
+
return {
|
|
281
|
+
kind: "picker",
|
|
282
|
+
title: kind === "image" ? "Image model" : "Video model",
|
|
283
|
+
picker: kind,
|
|
284
|
+
items: mediaPickerItems(await mediaModels(harness, kind), selected),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async function handleTranscribe(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
289
|
+
const models = await mediaModels(harness, "transcription");
|
|
290
|
+
if (arg) {
|
|
291
|
+
writeMediaPrefs({ transcribeModel: arg });
|
|
292
|
+
return { kind: "applied" };
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
kind: "picker",
|
|
296
|
+
title: "Speech model",
|
|
297
|
+
picker: "transcribe",
|
|
298
|
+
items: mediaPickerItems(models, readMediaPrefs().transcribeModel),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async function handleResume(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
303
|
+
const list = await harness.store.list();
|
|
304
|
+
if (list.length === 0) return { kind: "text", text: "No saved sessions." };
|
|
305
|
+
if (arg) {
|
|
306
|
+
const session = matchListedSession(list, arg) ?? (await harness.store.get(arg));
|
|
307
|
+
if (!session) return { kind: "text", text: `No session matches ${arg}` };
|
|
308
|
+
return { kind: "session", session };
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
kind: "picker",
|
|
312
|
+
title: "Resume",
|
|
313
|
+
picker: "resume",
|
|
314
|
+
items: sessionPickerItems(list),
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function formatEvalResult(result: {
|
|
319
|
+
name: string;
|
|
320
|
+
ok: boolean;
|
|
321
|
+
steps: Array<{ id: string; ok: boolean }>;
|
|
322
|
+
}): string {
|
|
323
|
+
const mark = result.ok ? "ok" : "fail";
|
|
324
|
+
const steps = result.steps.map((step) => `${step.id}:${step.ok ? "ok" : "fail"}`).join(" ");
|
|
325
|
+
return `${result.name} ${mark} · ${steps}`;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async function handleEval(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
329
|
+
const evalsDir = `${harness.cwd}/${harness.config.evalsDir}`;
|
|
330
|
+
if (!arg) {
|
|
331
|
+
const names = await listEvalSuites(evalsDir);
|
|
332
|
+
return { kind: "text", text: names.length ? names.join("\n") : "No eval suites." };
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
const result = await runNamedEval({
|
|
336
|
+
config: harness.config,
|
|
337
|
+
cwd: harness.cwd,
|
|
338
|
+
name: arg,
|
|
339
|
+
skills: harness.skills,
|
|
340
|
+
chat: harness.chat,
|
|
341
|
+
observability: harness.observability,
|
|
342
|
+
});
|
|
343
|
+
return { kind: "text", text: formatEvalResult(result) };
|
|
344
|
+
} catch (err) {
|
|
345
|
+
return { kind: "text", text: errorMessage(err) };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function handleSettings(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
350
|
+
const body = arg.trim();
|
|
351
|
+
if (!body || body === "key") {
|
|
352
|
+
const hint = harness.hasApiKey
|
|
353
|
+
? `Key on this machine · ${maskSecret(process.env.OPENROUTER_API_KEY ?? "")}`
|
|
354
|
+
: "No key on this machine.";
|
|
355
|
+
return { kind: "text", text: `${hint}\n/settings key <token>` };
|
|
356
|
+
}
|
|
357
|
+
const token = body.startsWith("key ") ? body.slice(4).trim() : body;
|
|
358
|
+
if (!token) return { kind: "text", text: "/settings key <token>" };
|
|
359
|
+
writeOpenRouterKey(token);
|
|
360
|
+
harness.setApiKey(token);
|
|
361
|
+
return { kind: "text", text: `Key saved · ${maskSecret(token)}` };
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const SLASH_HANDLERS: Record<string, SlashHandler> = {
|
|
365
|
+
help: async () => ({ kind: "text", text: SLASH_HELP }),
|
|
366
|
+
skills: async (harness) => ({ kind: "text", text: formatSkillList(harness.skills) }),
|
|
367
|
+
integrations: (harness, arg) => handleIntegrations(harness, arg),
|
|
368
|
+
integration: (harness, arg) => handleIntegrations(harness, arg),
|
|
369
|
+
skill: handleSkillSlash,
|
|
370
|
+
"skill add": handleSkillSlash,
|
|
371
|
+
"skill find": handleSkillSlash,
|
|
372
|
+
"skill new": handleSkillSlash,
|
|
373
|
+
"skill remove": handleSkillSlash,
|
|
374
|
+
clear: async (harness) => {
|
|
375
|
+
harness.setSession(undefined);
|
|
376
|
+
return { kind: "clear" };
|
|
377
|
+
},
|
|
378
|
+
model: handleModel,
|
|
379
|
+
mode: handleMode,
|
|
380
|
+
compact: async (harness) => {
|
|
381
|
+
const ok = await harness.compact();
|
|
382
|
+
return { kind: "text", text: ok ? "Compacted earlier turns." : "Nothing to compact." };
|
|
383
|
+
},
|
|
384
|
+
image: (harness, arg) => handleMediaPicker(harness, arg, "image"),
|
|
385
|
+
video: (harness, arg) => handleMediaPicker(harness, arg, "video"),
|
|
386
|
+
transcribe: handleTranscribe,
|
|
387
|
+
resume: handleResume,
|
|
388
|
+
eval: handleEval,
|
|
389
|
+
settings: handleSettings,
|
|
390
|
+
exit: async () => ({ kind: "exit" }),
|
|
391
|
+
quit: async () => ({ kind: "exit" }),
|
|
392
|
+
};
|
|
393
|
+
|
|
97
394
|
export async function dispatchSlash(harness: HarnessRuntime, raw: string): Promise<SlashOutcome> {
|
|
98
395
|
const { cmd, arg } = parseSlashLine(raw);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
...(parsed.skill ? { skill: parsed.skill } : {}),
|
|
119
|
-
});
|
|
120
|
-
return { kind: "text", text: "error" in result ? result.error : `Loaded ${result.rel}` };
|
|
121
|
-
}
|
|
122
|
-
if (parsed.action === "remove") {
|
|
123
|
-
const result = harness.removeSkill(parsed.name);
|
|
124
|
-
return {
|
|
125
|
-
kind: "text",
|
|
126
|
-
text: result.ok ? `Removed ${parsed.name}` : (result.error ?? "Could not remove."),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (parsed.action === "new") {
|
|
130
|
-
const result = await harness.authorSkill(parsed.name, parsed.brief);
|
|
131
|
-
return { kind: "text", text: "error" in result ? result.error : `Wrote ${result.rel}` };
|
|
132
|
-
}
|
|
133
|
-
return { kind: "text", text: SKILL_COMMAND_USAGE };
|
|
134
|
-
}
|
|
135
|
-
case "clear":
|
|
136
|
-
harness.setSession(undefined);
|
|
137
|
-
return { kind: "clear" };
|
|
138
|
-
case "model": {
|
|
139
|
-
if (arg) {
|
|
140
|
-
harness.setModel(arg);
|
|
141
|
-
return { kind: "applied" };
|
|
142
|
-
}
|
|
143
|
-
const live = harness.hasApiKey
|
|
144
|
-
? await loadLiveTargetNames(resolveOpenRouter(harness.config))
|
|
145
|
-
: undefined;
|
|
146
|
-
const items = modelPickerItems(harness.modelId, live);
|
|
147
|
-
return {
|
|
148
|
-
kind: "picker",
|
|
149
|
-
title: "Model",
|
|
150
|
-
picker: "model",
|
|
151
|
-
items,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
case "mode": {
|
|
155
|
-
if (arg) {
|
|
156
|
-
const next = tryParseAgentMode(arg);
|
|
157
|
-
if (!next) return { kind: "text", text: "Mode is ask, plan, or agent." };
|
|
158
|
-
harness.setMode(next);
|
|
159
|
-
return { kind: "applied" };
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
kind: "picker",
|
|
163
|
-
title: "Mode",
|
|
164
|
-
picker: "mode",
|
|
165
|
-
items: AGENT_MODES.map((item) => ({ id: item, label: item })),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
case "compact": {
|
|
169
|
-
const ok = await harness.compact();
|
|
170
|
-
return { kind: "text", text: ok ? "Compacted earlier turns." : "Nothing to compact." };
|
|
171
|
-
}
|
|
172
|
-
case "image": {
|
|
173
|
-
if (arg) return generateMediaOutcome(harness, "image", arg);
|
|
174
|
-
return {
|
|
175
|
-
kind: "picker",
|
|
176
|
-
title: "Image model",
|
|
177
|
-
picker: "image",
|
|
178
|
-
items: mediaPickerItems(await mediaModels(harness, "image"), readMediaPrefs().imageModel),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
case "video": {
|
|
182
|
-
if (arg) return generateMediaOutcome(harness, "video", arg);
|
|
183
|
-
return {
|
|
184
|
-
kind: "picker",
|
|
185
|
-
title: "Video model",
|
|
186
|
-
picker: "video",
|
|
187
|
-
items: mediaPickerItems(await mediaModels(harness, "video"), readMediaPrefs().videoModel),
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
case "transcribe": {
|
|
191
|
-
const models = await mediaModels(harness, "transcription");
|
|
192
|
-
if (arg) {
|
|
193
|
-
writeMediaPrefs({ transcribeModel: arg });
|
|
194
|
-
return { kind: "applied" };
|
|
195
|
-
}
|
|
196
|
-
return {
|
|
197
|
-
kind: "picker",
|
|
198
|
-
title: "Speech model",
|
|
199
|
-
picker: "transcribe",
|
|
200
|
-
items: mediaPickerItems(models, readMediaPrefs().transcribeModel),
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
case "resume": {
|
|
204
|
-
const list = await harness.store.list();
|
|
205
|
-
if (list.length === 0) return { kind: "text", text: "No saved sessions." };
|
|
206
|
-
if (arg) {
|
|
207
|
-
const session = matchListedSession(list, arg) ?? (await harness.store.get(arg));
|
|
208
|
-
if (!session) return { kind: "text", text: `No session matches ${arg}` };
|
|
209
|
-
return { kind: "session", session };
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
kind: "picker",
|
|
213
|
-
title: "Resume",
|
|
214
|
-
picker: "resume",
|
|
215
|
-
items: sessionPickerItems(list),
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
case "eval": {
|
|
219
|
-
const evalsDir = `${harness.cwd}/${harness.config.evalsDir}`;
|
|
220
|
-
if (!arg) {
|
|
221
|
-
const names = await listEvalSuites(evalsDir);
|
|
222
|
-
return { kind: "text", text: names.length ? names.join("\n") : "No eval suites." };
|
|
223
|
-
}
|
|
224
|
-
try {
|
|
225
|
-
const result = await runNamedEval({
|
|
226
|
-
config: harness.config,
|
|
227
|
-
cwd: harness.cwd,
|
|
228
|
-
name: arg,
|
|
229
|
-
skills: harness.skills,
|
|
230
|
-
chat: harness.chat,
|
|
231
|
-
observability: harness.observability,
|
|
232
|
-
});
|
|
233
|
-
return {
|
|
234
|
-
kind: "text",
|
|
235
|
-
text: `${result.name} ${result.ok ? "ok" : "fail"} · ${result.steps.map((s) => `${s.id}:${s.ok ? "ok" : "fail"}`).join(" ")}`,
|
|
236
|
-
};
|
|
237
|
-
} catch (err) {
|
|
238
|
-
return { kind: "text", text: err instanceof Error ? err.message : String(err) };
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
case "settings": {
|
|
242
|
-
const body = arg.trim();
|
|
243
|
-
if (!body || body === "key") {
|
|
244
|
-
const hint = harness.hasApiKey
|
|
245
|
-
? `Key on this machine · ${maskSecret(process.env.OPENROUTER_API_KEY ?? "")}`
|
|
246
|
-
: "No key on this machine.";
|
|
247
|
-
return { kind: "text", text: `${hint}\n/settings key <token>` };
|
|
248
|
-
}
|
|
249
|
-
const token = body.startsWith("key ") ? body.slice(4).trim() : body;
|
|
250
|
-
if (!token) return { kind: "text", text: "/settings key <token>" };
|
|
251
|
-
writeOpenRouterKey(token);
|
|
252
|
-
harness.setApiKey(token);
|
|
253
|
-
return { kind: "text", text: `Key saved · ${maskSecret(token)}` };
|
|
254
|
-
}
|
|
255
|
-
case "exit":
|
|
256
|
-
case "quit":
|
|
257
|
-
return { kind: "exit" };
|
|
258
|
-
default:
|
|
259
|
-
return { kind: "text", text: `Unknown command /${cmd}. /help for the list.` };
|
|
396
|
+
const handler = SLASH_HANDLERS[cmd];
|
|
397
|
+
if (!handler) return { kind: "text", text: `Unknown command /${cmd}. /help for the list.` };
|
|
398
|
+
return handler(harness, arg, cmd);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const MEDIA_PICKER_PREFS: Partial<Record<SlashPickerKind, (id: string) => void>> = {
|
|
402
|
+
image: (id) => writeMediaPrefs({ imageModel: id }),
|
|
403
|
+
video: (id) => writeMediaPrefs({ videoModel: id }),
|
|
404
|
+
transcribe: (id) => writeMediaPrefs({ transcribeModel: id }),
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
async function applySkillPicker(
|
|
408
|
+
harness: HarnessRuntime,
|
|
409
|
+
id: string,
|
|
410
|
+
): Promise<{ kind: "text"; text: string }> {
|
|
411
|
+
const name = id.split("@").pop()?.trim() ?? id;
|
|
412
|
+
if (harness.disabledSkills().some((entry) => entry === name.toLowerCase())) {
|
|
413
|
+
harness.enableSkill(name);
|
|
414
|
+
return { kind: "text", text: `Enabled ${name}` };
|
|
260
415
|
}
|
|
416
|
+
const loaded =
|
|
417
|
+
harness.skills.find((skill) => skill.catalogRef === id) ??
|
|
418
|
+
harness.skills.find(
|
|
419
|
+
(skill) => skill.source !== "user" && skill.name.toLowerCase() === name.toLowerCase(),
|
|
420
|
+
);
|
|
421
|
+
if (loaded) {
|
|
422
|
+
const result = harness.removeSkill(loaded.name);
|
|
423
|
+
const verb = loaded.source === "user" ? "Removed" : "Disabled";
|
|
424
|
+
return {
|
|
425
|
+
kind: "text",
|
|
426
|
+
text: result.ok ? `${verb} ${loaded.name}` : (result.error ?? "Could not remove."),
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
const result = await harness.addSkill(id);
|
|
430
|
+
return { kind: "text", text: "error" in result ? result.error : `Loaded ${result.rel}` };
|
|
261
431
|
}
|
|
262
432
|
|
|
263
|
-
export function applyPickerChoice(
|
|
433
|
+
export async function applyPickerChoice(
|
|
264
434
|
harness: HarnessRuntime,
|
|
265
435
|
picker: SlashPickerKind,
|
|
266
436
|
id: string,
|
|
267
|
-
):
|
|
437
|
+
): Promise<
|
|
438
|
+
{ kind: "applied" } | { kind: "text"; text: string } | { kind: "session-id"; id: string }
|
|
439
|
+
> {
|
|
268
440
|
if (picker === "model") {
|
|
269
441
|
harness.setModel(id);
|
|
270
442
|
return { kind: "applied" };
|
|
@@ -275,17 +447,14 @@ export function applyPickerChoice(
|
|
|
275
447
|
harness.setMode(next);
|
|
276
448
|
return { kind: "applied" };
|
|
277
449
|
}
|
|
278
|
-
|
|
279
|
-
|
|
450
|
+
const writePref = MEDIA_PICKER_PREFS[picker];
|
|
451
|
+
if (writePref) {
|
|
452
|
+
writePref(id);
|
|
280
453
|
return { kind: "applied" };
|
|
281
454
|
}
|
|
282
|
-
if (picker === "
|
|
283
|
-
|
|
284
|
-
return
|
|
285
|
-
}
|
|
286
|
-
if (picker === "transcribe") {
|
|
287
|
-
writeMediaPrefs({ transcribeModel: id });
|
|
288
|
-
return { kind: "applied" };
|
|
455
|
+
if (picker === "skill") return applySkillPicker(harness, id);
|
|
456
|
+
if (picker === "integration") {
|
|
457
|
+
return toggleIntegration(harness, id);
|
|
289
458
|
}
|
|
290
459
|
return { kind: "session-id", id };
|
|
291
460
|
}
|
package/src/cli/slash.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { plainTerminalText } from "./plain-text.ts";
|
|
|
4
4
|
import {
|
|
5
5
|
completeSlashCommand,
|
|
6
6
|
filterSlashCommands,
|
|
7
|
+
formatIntegrationList,
|
|
7
8
|
formatSkillList,
|
|
8
9
|
formatSlashCommand,
|
|
9
10
|
isHelpAlias,
|
|
@@ -32,6 +33,7 @@ describe("slash palette", () => {
|
|
|
32
33
|
expect(filterSlashCommands("/mode").map((item) => item.name)).toEqual(["model", "mode"]);
|
|
33
34
|
expect(filterSlashCommands("/help").map((item) => item.name)).toEqual(["help"]);
|
|
34
35
|
expect(filterSlashCommands("/image").map((item) => item.name)).toEqual(["image"]);
|
|
36
|
+
expect(filterSlashCommands("/int").map((item) => item.name)).toEqual(["integrations"]);
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
test("puts argument slots on the command, not the hint", () => {
|
|
@@ -40,6 +42,7 @@ describe("slash palette", () => {
|
|
|
40
42
|
expect(formatSlashCommand(evalCmd!)).toBe("/eval [name]");
|
|
41
43
|
expect(SLASH_HELP).toContain("/eval [name] · run an eval suite");
|
|
42
44
|
expect(SLASH_HELP).toContain("/image [prompt] · generate an image");
|
|
45
|
+
expect(SLASH_HELP).toContain("/skill find [query] · browse bundled and skills.sh");
|
|
43
46
|
expect(SLASH_HELP).not.toContain("/eval ·");
|
|
44
47
|
});
|
|
45
48
|
|
|
@@ -72,14 +75,22 @@ describe("slash palette", () => {
|
|
|
72
75
|
source: "host",
|
|
73
76
|
},
|
|
74
77
|
] satisfies Skill[];
|
|
75
|
-
expect(formatSkillList(skills)).toBe("copywriting
|
|
78
|
+
expect(formatSkillList(skills)).toBe("copywriting project");
|
|
76
79
|
expect(formatSkillList(skills)).not.toContain("Routes copy");
|
|
77
80
|
});
|
|
81
|
+
|
|
82
|
+
test("lists integrations as name and on/off", () => {
|
|
83
|
+
expect(
|
|
84
|
+
formatIntegrationList([
|
|
85
|
+
{ label: "Linear", connected: true },
|
|
86
|
+
{ label: "Figma", connected: false, auth: "desktop" },
|
|
87
|
+
]),
|
|
88
|
+
).toBe("Linear on\nFigma off");
|
|
89
|
+
});
|
|
78
90
|
});
|
|
79
91
|
|
|
80
92
|
describe("resolveSlashSubmit", () => {
|
|
81
93
|
test("keeps commands that still need an argument in the composer", () => {
|
|
82
|
-
expect(resolveSlashSubmit("/skill find")).toEqual({ action: "send", line: "/skill find" });
|
|
83
94
|
expect(resolveSlashSubmit("/skill add")).toEqual({ action: "complete", line: "/skill add " });
|
|
84
95
|
expect(resolveSlashSubmit("/skill find billing")).toEqual({
|
|
85
96
|
action: "send",
|
|
@@ -97,9 +108,21 @@ describe("resolveSlashSubmit", () => {
|
|
|
97
108
|
expect(resolveSlashSubmit("/asdf")).toEqual({ action: "hold" });
|
|
98
109
|
});
|
|
99
110
|
|
|
111
|
+
test("sends the highlighted command when the prefix is still ambiguous", () => {
|
|
112
|
+
const integrations = SLASH_COMMANDS.find((item) => item.name === "integrations");
|
|
113
|
+
expect(integrations).toBeDefined();
|
|
114
|
+
expect(resolveSlashSubmit("/i", integrations)).toEqual({
|
|
115
|
+
action: "send",
|
|
116
|
+
line: "/integrations",
|
|
117
|
+
});
|
|
118
|
+
expect(resolveSlashSubmit("/i")).toEqual({ action: "hold" });
|
|
119
|
+
});
|
|
120
|
+
|
|
100
121
|
test("opens pickers for empty model, mode, and media commands", () => {
|
|
101
122
|
expect(resolveSlashSubmit("/image")).toEqual({ action: "send", line: "/image" });
|
|
102
123
|
expect(resolveSlashSubmit("/mode")).toEqual({ action: "send", line: "/mode" });
|
|
124
|
+
expect(resolveSlashSubmit("/integrations")).toEqual({ action: "send", line: "/integrations" });
|
|
125
|
+
expect(resolveSlashSubmit("/skill find")).toEqual({ action: "send", line: "/skill find" });
|
|
103
126
|
expect(resolveSlashSubmit("/settings")).toEqual({ action: "send", line: "/settings" });
|
|
104
127
|
});
|
|
105
128
|
});
|