sumo-agents 0.0.0-stage → 0.3.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/AGENTS.md +38 -0
- package/LICENSE +21 -0
- package/README.md +111 -2
- package/bin/sumo.mjs +33 -0
- package/guides/delegation.md +33 -0
- package/guides/feature.md +14 -0
- package/guides/fix.md +14 -0
- package/guides/memory.md +23 -0
- package/guides/projects.md +27 -0
- package/guides/review.md +16 -0
- package/guides/workflows.md +26 -0
- package/logo.txt +19 -0
- package/package.json +42 -4
- package/prompts/agent.md +7 -0
- package/prompts/dream.md +13 -0
- package/prompts/scribe.md +21 -0
- package/spinner.txt +90 -0
- package/src/advisor.mjs +59 -0
- package/src/apply.mjs +368 -0
- package/src/auth.mjs +80 -0
- package/src/card.mjs +72 -0
- package/src/catalog.mjs +167 -0
- package/src/chat.mjs +1162 -0
- package/src/cli.mjs +815 -0
- package/src/cost.mjs +128 -0
- package/src/db.mjs +384 -0
- package/src/dream.mjs +97 -0
- package/src/editor.mjs +198 -0
- package/src/export.mjs +132 -0
- package/src/guard.mjs +121 -0
- package/src/guides.mjs +86 -0
- package/src/herdr.mjs +117 -0
- package/src/hooks.mjs +270 -0
- package/src/images.mjs +89 -0
- package/src/jobs.mjs +1184 -0
- package/src/jobtools.mjs +82 -0
- package/src/local-server.mjs +169 -0
- package/src/lock.mjs +45 -0
- package/src/loop.mjs +838 -0
- package/src/mcp.mjs +604 -0
- package/src/memory.mjs +400 -0
- package/src/model.mjs +270 -0
- package/src/page.html +304 -0
- package/src/page.mjs +135 -0
- package/src/paths.mjs +33 -0
- package/src/prime.mjs +177 -0
- package/src/projects.mjs +232 -0
- package/src/recall.mjs +45 -0
- package/src/redact.mjs +173 -0
- package/src/render.mjs +45 -0
- package/src/route.mjs +287 -0
- package/src/sandbox.mjs +173 -0
- package/src/scan.mjs +204 -0
- package/src/scribe.mjs +349 -0
- package/src/sessions.mjs +371 -0
- package/src/setup.mjs +528 -0
- package/src/sqlite.mjs +66 -0
- package/src/text.mjs +97 -0
- package/src/tools.mjs +987 -0
- package/src/transcript.mjs +106 -0
- package/src/tty.mjs +529 -0
- package/src/ui.mjs +1363 -0
- package/src/verify.mjs +369 -0
- package/src/web.mjs +49 -0
- package/src/workflows.mjs +270 -0
- package/src/worktree.mjs +128 -0
package/src/catalog.mjs
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { anthropicClient, resolveAnthropicCredential } from './auth.mjs';
|
|
4
|
+
import { getMeta, setMeta } from './db.mjs';
|
|
5
|
+
import { UsageError } from './memory.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The models Sumo can run on: the short names the router, `/model` and `sumo config` use, cheapest
|
|
9
|
+
* first, and the API model each one means. Each has a switch. `sumo setup` asks the API once which
|
|
10
|
+
* of them this credential can use and sets the switches from the answer; `sumo models discover` asks
|
|
11
|
+
* again; `sumo models enable|disable <name>` sets one by hand. The chat, the router, the passes and a
|
|
12
|
+
* job's run all read the switches as they are now.
|
|
13
|
+
*/
|
|
14
|
+
export const MODEL_IDS = {
|
|
15
|
+
haiku: 'claude-haiku-4-5-20251001',
|
|
16
|
+
sonnet: 'claude-sonnet-5-5',
|
|
17
|
+
opus: 'claude-opus-5-5',
|
|
18
|
+
fable: 'claude-fable-5-1',
|
|
19
|
+
};
|
|
20
|
+
export const MODELS = Object.keys(MODEL_IDS);
|
|
21
|
+
|
|
22
|
+
export const modelId = (model) => MODEL_IDS[model] ?? model;
|
|
23
|
+
|
|
24
|
+
const STATE_KEY = 'models.state';
|
|
25
|
+
const CHECKED_KEY = 'models.checked';
|
|
26
|
+
const TIMEOUT_MS = 30_000;
|
|
27
|
+
/** What a Claude Code OAuth token needs on a request outside the Messages API. */
|
|
28
|
+
const OAUTH_BETA = 'oauth-2025-04-20';
|
|
29
|
+
|
|
30
|
+
const day = (now) => String(now).slice(0, 10);
|
|
31
|
+
|
|
32
|
+
/** Every model's switch and the note that explains it — on, and "not checked", until something is recorded. */
|
|
33
|
+
export function modelStates(db) {
|
|
34
|
+
let stored = {};
|
|
35
|
+
try {
|
|
36
|
+
stored = JSON.parse(getMeta(db, STATE_KEY) ?? '{}');
|
|
37
|
+
} catch {
|
|
38
|
+
stored = {};
|
|
39
|
+
}
|
|
40
|
+
return Object.fromEntries(MODELS.map((name) => [name, { on: stored[name]?.on !== false, note: stored[name]?.note ?? 'not checked' }]));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const writeStates = (db, states) => setMeta(db, STATE_KEY, JSON.stringify(states));
|
|
44
|
+
|
|
45
|
+
/** The models the chat, the router and the passes may use, cheapest first. */
|
|
46
|
+
export function usableModels(db) {
|
|
47
|
+
const states = modelStates(db);
|
|
48
|
+
return MODELS.filter((name) => states[name].on);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** When the API was last asked which models it has, or null while it never was. */
|
|
52
|
+
export const modelsChecked = (db) => getMeta(db, CHECKED_KEY);
|
|
53
|
+
|
|
54
|
+
/** `name` is a model Sumo knows, or a usage error listing them — after `also`, the other values the setting takes. */
|
|
55
|
+
export function knownModel(name, also = []) {
|
|
56
|
+
if (!MODELS.includes(name)) throw new UsageError(`no such model "${name}" — one of: ${[...also, ...MODELS].join(', ')}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Why `name` cannot be used right now, with the way out (`orElse` is another one), or null while it is on. */
|
|
60
|
+
export function offLine(db, name, orElse) {
|
|
61
|
+
if (modelStates(db)[name].on) return null;
|
|
62
|
+
return `${name} is off — sumo models enable ${name}${orElse ? `, or ${orElse}` : ''}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** `name` is on, or a usage error saying how to turn it on. */
|
|
66
|
+
export function assertOn(db, name, orElse) {
|
|
67
|
+
const line = offLine(db, name, orElse);
|
|
68
|
+
if (line) throw new UsageError(line);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Turns one model on or off by hand. */
|
|
72
|
+
export function setModel(db, name, on, now = new Date().toISOString()) {
|
|
73
|
+
knownModel(name);
|
|
74
|
+
const states = modelStates(db);
|
|
75
|
+
states[name] = { on, note: `turned ${on ? 'on' : 'off'} ${day(now)}` };
|
|
76
|
+
writeStates(db, states);
|
|
77
|
+
return states[name];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One line per model: its name, its switch, the API id and the note — what `sumo models` prints. */
|
|
81
|
+
export function modelLines(db, names = MODELS) {
|
|
82
|
+
const states = modelStates(db);
|
|
83
|
+
return names.map((name) => `${name.padEnd(7)} ${states[name].on ? 'on ' : 'off'} ${MODEL_IDS[name].padEnd(26)} ${states[name].note}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** What went wrong with an API call, in one line a person can act on. */
|
|
87
|
+
export function describeApiError(cause) {
|
|
88
|
+
if (cause instanceof Anthropic.AuthenticationError) return 'the Anthropic credential is missing or invalid — export ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN in the shell that runs sumo';
|
|
89
|
+
if (cause instanceof Anthropic.RateLimitError) return 'the API is rate-limiting this key — try again in a minute';
|
|
90
|
+
if (cause instanceof Anthropic.APIError) return `the API answered ${cause.status ?? 'an error'}: ${String(cause.message).slice(0, 300)}`;
|
|
91
|
+
return String(cause?.message ?? cause).slice(0, 300);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The stand-in's answer to "which models are there": `{ found: [names], errors: { name: why } }`; anything else is a failed check. */
|
|
95
|
+
function askStandIn(standIn) {
|
|
96
|
+
const run = spawnSync(standIn, [], { input: JSON.stringify({ kind: 'models', models: MODEL_IDS }), encoding: 'utf8', timeout: TIMEOUT_MS });
|
|
97
|
+
if (run.error) return { error: `could not run ${standIn}: ${run.error.message}` };
|
|
98
|
+
let answer;
|
|
99
|
+
try {
|
|
100
|
+
answer = JSON.parse(run.stdout);
|
|
101
|
+
} catch {
|
|
102
|
+
return { error: (run.stderr || run.stdout).trim().slice(0, 200) || `exit ${run.status}` };
|
|
103
|
+
}
|
|
104
|
+
if (!answer || typeof answer !== 'object') return { error: `${standIn} answered ${String(run.stdout).trim().slice(0, 80)}, not a list of models` };
|
|
105
|
+
const found = new Set(answer.found ?? []);
|
|
106
|
+
const errors = answer.errors ?? {};
|
|
107
|
+
return Object.fromEntries(MODELS.map((name) => [name, found.has(name) ? 'found' : Object.hasOwn(errors, name) ? String(errors[name]) : 'missing']));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** One GET /v1/models/<id> per model, together: found, missing, or what went wrong asking. */
|
|
111
|
+
async function askApi() {
|
|
112
|
+
const standIn = process.env.SUMO_AGENTS_MODEL_CMD;
|
|
113
|
+
if (standIn) return askStandIn(standIn);
|
|
114
|
+
const credential = resolveAnthropicCredential();
|
|
115
|
+
if (!credential) return { error: 'no Anthropic credential — export ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN in this shell' };
|
|
116
|
+
const client = anthropicClient({ timeout: TIMEOUT_MS }, credential);
|
|
117
|
+
const options = credential.type === 'oauth' ? { headers: { 'anthropic-beta': OAUTH_BETA } } : {};
|
|
118
|
+
const entries = await Promise.all(
|
|
119
|
+
MODELS.map(async (name) => {
|
|
120
|
+
try {
|
|
121
|
+
await client.models.retrieve(MODEL_IDS[name], options);
|
|
122
|
+
return [name, 'found'];
|
|
123
|
+
} catch (cause) {
|
|
124
|
+
return [name, cause instanceof Anthropic.NotFoundError ? 'missing' : describeApiError(cause)];
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
return Object.fromEntries(entries);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Asks the API which of Sumo's models this credential can use, and sets the switches from the answer:
|
|
133
|
+
* found → on, not there → off; a model whose own check errored is left as it was, with the error in its
|
|
134
|
+
* note. An answer with none of them found is a failed check, not an API that has none: nothing is changed
|
|
135
|
+
* and the reason is returned. Never throws.
|
|
136
|
+
*/
|
|
137
|
+
export async function discoverModels(db, { now = new Date().toISOString() } = {}) {
|
|
138
|
+
const answers = await askApi();
|
|
139
|
+
if (answers.error) return { ok: false, error: answers.error };
|
|
140
|
+
const found = MODELS.filter((name) => answers[name] === 'found');
|
|
141
|
+
const missing = MODELS.filter((name) => answers[name] === 'missing');
|
|
142
|
+
const errors = Object.fromEntries(MODELS.filter((name) => answers[name] !== 'found' && answers[name] !== 'missing').map((name) => [name, answers[name]]));
|
|
143
|
+
if (found.length === 0) {
|
|
144
|
+
// Any model that could not be asked says more than the ones that were not there: a connection that failed is not a credential that cannot see.
|
|
145
|
+
const failed = Object.values(errors);
|
|
146
|
+
const error = failed.length > 0 ? failed[0] : 'the API found none of the models Sumo knows — the credential may not be allowed to see them';
|
|
147
|
+
return { ok: false, error };
|
|
148
|
+
}
|
|
149
|
+
const states = modelStates(db);
|
|
150
|
+
// A model the user turned off stays off: the API says what this credential can use, not what the user wants used.
|
|
151
|
+
const offByHand = (name) => !states[name].on && /^turned off /.test(states[name].note ?? '');
|
|
152
|
+
for (const name of found) if (!offByHand(name)) states[name] = { on: true, note: `found ${day(now)}` };
|
|
153
|
+
for (const name of missing) states[name] = { on: false, note: `not found ${day(now)}` };
|
|
154
|
+
for (const [name, error] of Object.entries(errors)) states[name] = { on: states[name].on, note: `not checked — ${error}` };
|
|
155
|
+
writeStates(db, states);
|
|
156
|
+
setMeta(db, CHECKED_KEY, now);
|
|
157
|
+
return { ok: true, found, missing, errors };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A finished discovery in one line: what was found, what was turned off, what could not be checked. */
|
|
161
|
+
export function discoverySummary({ found, missing, errors }) {
|
|
162
|
+
const parts = [`found: ${found.join(', ')}`];
|
|
163
|
+
if (missing.length > 0) parts.push(`not found, turned off: ${missing.join(', ')}`);
|
|
164
|
+
const failed = Object.entries(errors);
|
|
165
|
+
if (failed.length > 0) parts.push(`not checked: ${failed.map(([name, error]) => `${name} (${error})`).join(', ')}`);
|
|
166
|
+
return parts.join(' — ');
|
|
167
|
+
}
|