orcacompass 0.0.0-stage → 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/LICENSE +202 -0
- package/NOTICE +51 -0
- package/README.md +171 -3
- package/data/modelindex-snapshot.json +1537 -0
- package/data/models-snapshot.json +1356 -0
- package/dist/cli.js +906 -0
- package/dist/config.js +272 -0
- package/dist/install.js +56 -0
- package/dist/paths.js +30 -0
- package/dist/placements/agents/antigravity.js +87 -0
- package/dist/placements/agents/claude.js +72 -0
- package/dist/placements/agents/codex.js +66 -0
- package/dist/placements/agents/cursor.js +102 -0
- package/dist/placements/agents/deps.js +19 -0
- package/dist/placements/agents/grok.js +92 -0
- package/dist/placements/agents/list-cache.js +85 -0
- package/dist/placements/agents/muse.js +7 -0
- package/dist/placements/agents/opencode.js +77 -0
- package/dist/placements/agents/orca-catalog.js +34 -0
- package/dist/placements/benchmark.js +70 -0
- package/dist/placements/build.js +94 -0
- package/dist/placements/score.js +70 -0
- package/dist/placements/sources/artificialanalysis.js +133 -0
- package/dist/placements/sources/modelindex.js +84 -0
- package/dist/placements/sources/modelsdev.js +113 -0
- package/dist/placements/table.js +94 -0
- package/dist/placements/tiers.js +136 -0
- package/dist/routing/effort.js +31 -0
- package/dist/routing/environment.js +51 -0
- package/dist/routing/orca-settings.js +111 -0
- package/dist/routing/orca-usage.js +85 -0
- package/dist/routing/pace.js +52 -0
- package/dist/routing/rejection.js +58 -0
- package/dist/routing/rejections.js +18 -0
- package/dist/routing/router.js +552 -0
- package/dist/setup.js +358 -0
- package/dist/system/run.js +128 -0
- package/dist/types.js +8 -0
- package/dist/verify.js +106 -0
- package/dist/version.js +3 -0
- package/package.json +60 -6
- package/skills/orcacompass/SKILL.md +278 -0
package/dist/setup.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { createInterface } from 'node:readline';
|
|
3
|
+
import { applyAgentChoice, DEFAULT_CONFIG, isChosen, parsePercent, setAgentChoice, setBans, setPin, setPreferRiskLimit, updateConfigFile, } from './config.js';
|
|
4
|
+
import { agentNotFamily, agentSkipReason, banMatches, enabledInOrca, launchIds, route } from './routing/router.js';
|
|
5
|
+
import { TIERS } from './types.js';
|
|
6
|
+
import { configPath } from './paths.js';
|
|
7
|
+
function agentRows(env, config) {
|
|
8
|
+
return env.discoveries.map((d) => {
|
|
9
|
+
const reason = agentSkipReason(d, env, config);
|
|
10
|
+
const orca = enabledInOrca(env.orcaAgents, d.agent);
|
|
11
|
+
const chosen = isChosen(d.agent, config);
|
|
12
|
+
return {
|
|
13
|
+
agent: d.agent,
|
|
14
|
+
installed: d.installed,
|
|
15
|
+
enabledInOrca: orca,
|
|
16
|
+
orcaUsage: env.usage[d.agent]?.status ?? 'unknown',
|
|
17
|
+
models: d.models.length,
|
|
18
|
+
chosen,
|
|
19
|
+
preselected: d.installed && d.models.length > 0 && orca !== 'no' && chosen,
|
|
20
|
+
verdict: reason === undefined ? 'used' : `not used: ${reason}`,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** The discovered base id behind a launched model id (Cursor's `claude-opus-5-5-high` is `claude-opus-5-5`). */
|
|
25
|
+
function baseModel(env, agent, launched) {
|
|
26
|
+
const d = env.discoveries.find((x) => x.agent === agent);
|
|
27
|
+
return d?.models.find((m) => launchIds(m).includes(launched))?.modelId ?? launched;
|
|
28
|
+
}
|
|
29
|
+
const pace = (risk) => (risk ? Math.round(risk.projectedPercent) : null);
|
|
30
|
+
function tierChoice(tier, env, config) {
|
|
31
|
+
const d = route({ tier, noDowngrade: true }, env, config);
|
|
32
|
+
// A structural upgrade belongs to another tier; only the tier's own routes are choices here.
|
|
33
|
+
const own = d.tier === undefined || d.tier === tier;
|
|
34
|
+
const options = [];
|
|
35
|
+
if (own && d.route) {
|
|
36
|
+
const prefix = `${d.route.agent} ${d.route.model}: `;
|
|
37
|
+
const reason = d.reasons[0] ?? '';
|
|
38
|
+
options.push({
|
|
39
|
+
agent: d.route.agent, model: baseModel(env, d.route.agent, d.route.model), blocked: false, onPacePercent: pace(d.risk),
|
|
40
|
+
reason: reason.startsWith(prefix) ? reason.slice(prefix.length) : reason,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (own) {
|
|
44
|
+
for (const a of d.alternatives) {
|
|
45
|
+
options.push({ agent: a.agent, model: baseModel(env, a.agent, a.model), blocked: a.blocked, onPacePercent: pace(a.risk), reason: a.reason });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
pick: own && d.route ? d.route : null,
|
|
50
|
+
preferred: config.pins[tier] ?? null,
|
|
51
|
+
options,
|
|
52
|
+
warnings: own ? d.warnings : [],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function familyRows(env, config) {
|
|
56
|
+
const byFamily = new Map();
|
|
57
|
+
for (const d of env.discoveries) {
|
|
58
|
+
for (const m of d.models) {
|
|
59
|
+
const family = m.meta?.family;
|
|
60
|
+
if (!family)
|
|
61
|
+
continue;
|
|
62
|
+
const models = byFamily.get(family) ?? [];
|
|
63
|
+
if (!models.some((x) => x.agent === d.agent && x.model === m.modelId))
|
|
64
|
+
models.push({ agent: d.agent, model: m.modelId });
|
|
65
|
+
byFamily.set(family, models);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const newestFirst = (a, b) => b.model.localeCompare(a.model, 'en', { numeric: true });
|
|
69
|
+
return [...byFamily.keys()].sort().map((family) => ({
|
|
70
|
+
family, models: byFamily.get(family).sort(newestFirst), banned: config.banModels.includes(family),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
/** `orcacompass setup --json`: everything an orchestrator needs to ask the setup questions in chat. */
|
|
74
|
+
export function setupInfo(env, config) {
|
|
75
|
+
return {
|
|
76
|
+
configPath: configPath(),
|
|
77
|
+
configExists: existsSync(configPath()),
|
|
78
|
+
orcaAgents: env.orcaAgents ?? null,
|
|
79
|
+
config: {
|
|
80
|
+
allowAgents: config.allowAgents ?? null,
|
|
81
|
+
denyAgents: config.denyAgents,
|
|
82
|
+
pins: config.pins,
|
|
83
|
+
preferRiskLimit: config.preferRiskLimit,
|
|
84
|
+
banModels: config.banModels,
|
|
85
|
+
},
|
|
86
|
+
defaultPreferRiskLimit: DEFAULT_CONFIG.preferRiskLimit,
|
|
87
|
+
agents: agentRows(env, config),
|
|
88
|
+
tiers: Object.fromEntries(TIERS.map((t) => [t, tierChoice(t, env, config)])),
|
|
89
|
+
families: familyRows(env, config),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// --- the terminal wizard --------------------------------------------------------------------
|
|
93
|
+
class Canceled extends Error {
|
|
94
|
+
}
|
|
95
|
+
const TIER_NAMES = { light: 'Light', daily: 'Daily', advanced: 'Advanced', frontier: 'Frontier' };
|
|
96
|
+
const prefLabel = (p) => (!p ? 'none' : p.model ? `${p.agent} ${p.model}` : `${p.agent} (its best model)`);
|
|
97
|
+
const paceLabel = (o) => (o.blocked ? 'blocked' : o.onPacePercent === null ? 'usage unknown' : `on pace for ${o.onPacePercent}%`);
|
|
98
|
+
const samePin = (a, b) => a?.agent === b?.agent && a?.model === b?.model;
|
|
99
|
+
const sameList = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
100
|
+
function table(rows) {
|
|
101
|
+
const widths = rows[0].map((_, i) => Math.max(...rows.map((r) => r[i].length)));
|
|
102
|
+
return rows.map((r) => ` ${r.map((cell, i) => (i === r.length - 1 ? cell : cell.padEnd(widths[i]))).join(' ')}`.trimEnd());
|
|
103
|
+
}
|
|
104
|
+
/** Numbers (1-based) or names from `items`, separated by commas or spaces; or the first token that is neither. */
|
|
105
|
+
function pickMany(answer, items) {
|
|
106
|
+
const picked = [];
|
|
107
|
+
for (const token of answer.split(/[\s,]+/).filter(Boolean)) {
|
|
108
|
+
const n = /^\d+$/.test(token) ? Number(token) : NaN;
|
|
109
|
+
const item = Number.isNaN(n) ? items.find((i) => i === token.toLowerCase()) : items[n - 1];
|
|
110
|
+
if (item === undefined)
|
|
111
|
+
return { bad: token };
|
|
112
|
+
if (!picked.includes(item))
|
|
113
|
+
picked.push(item);
|
|
114
|
+
}
|
|
115
|
+
return { picked };
|
|
116
|
+
}
|
|
117
|
+
/** Runs the four setup questions and writes the answers when the user agrees. Returns the exit code. */
|
|
118
|
+
export async function setupWizard(term, env, config) {
|
|
119
|
+
const rl = createInterface({ input: term.input, output: term.output });
|
|
120
|
+
// Queue lines typed ahead of their question; Ctrl+C or the end of input cancels the setup.
|
|
121
|
+
const typed = [];
|
|
122
|
+
let closed = false;
|
|
123
|
+
let wake = () => { };
|
|
124
|
+
rl.on('line', (line) => {
|
|
125
|
+
typed.push(line);
|
|
126
|
+
wake();
|
|
127
|
+
});
|
|
128
|
+
rl.on('close', () => {
|
|
129
|
+
closed = true;
|
|
130
|
+
wake();
|
|
131
|
+
});
|
|
132
|
+
rl.on('SIGINT', () => rl.close());
|
|
133
|
+
const say = (s = '') => term.output.write(`${s}\n`);
|
|
134
|
+
const ask = async (question) => {
|
|
135
|
+
// Input that has already ended (answers piped in) still has typed lines to read.
|
|
136
|
+
if (closed)
|
|
137
|
+
term.output.write(question);
|
|
138
|
+
else {
|
|
139
|
+
rl.setPrompt(question);
|
|
140
|
+
rl.prompt();
|
|
141
|
+
}
|
|
142
|
+
while (typed.length === 0 && !closed)
|
|
143
|
+
await new Promise((resolve) => (wake = resolve));
|
|
144
|
+
const line = typed.shift();
|
|
145
|
+
if (line === undefined)
|
|
146
|
+
throw new Canceled();
|
|
147
|
+
return line.trim();
|
|
148
|
+
};
|
|
149
|
+
const yesNo = async (question, yes) => {
|
|
150
|
+
for (;;) {
|
|
151
|
+
const a = (await ask(`${question} [${yes ? 'Y/n' : 'y/N'}]: `)).toLowerCase();
|
|
152
|
+
if (a === '')
|
|
153
|
+
return yes;
|
|
154
|
+
if (['y', 'yes'].includes(a))
|
|
155
|
+
return true;
|
|
156
|
+
if (['n', 'no'].includes(a))
|
|
157
|
+
return false;
|
|
158
|
+
say(' Please answer y or n.');
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
try {
|
|
162
|
+
const path = configPath();
|
|
163
|
+
const exists = existsSync(path);
|
|
164
|
+
say('OrcaCompass setup: three questions, then a summary. Press Enter to keep the answer in [brackets].');
|
|
165
|
+
say(`Nothing is saved until you confirm at the end. Config: ${path}${exists ? '' : ' (not created yet)'}`);
|
|
166
|
+
// 1. Agents
|
|
167
|
+
say();
|
|
168
|
+
say('1/4 Agents');
|
|
169
|
+
const rows = agentRows(env, config);
|
|
170
|
+
const yes = (b) => (b ? 'yes' : 'no');
|
|
171
|
+
for (const line of table([
|
|
172
|
+
['#', 'agent', 'installed', 'enabled in Orca', 'Orca usage', 'models'],
|
|
173
|
+
...rows.map((r, i) => [String(i + 1), r.agent, yes(r.installed), r.enabledInOrca, r.orcaUsage, String(r.models)]),
|
|
174
|
+
]))
|
|
175
|
+
say(line);
|
|
176
|
+
const before = rows.filter((r) => r.preselected).map((r) => r.agent);
|
|
177
|
+
let selected = before;
|
|
178
|
+
for (;;) {
|
|
179
|
+
const a = await ask(`Use which agents? Numbers or names, separated by commas [${before.join(', ') || 'none'}]: `);
|
|
180
|
+
if (a === '')
|
|
181
|
+
break;
|
|
182
|
+
const got = pickMany(a, rows.map((r) => r.agent));
|
|
183
|
+
if ('bad' in got)
|
|
184
|
+
say(` "${got.bad}" is not one of the agents above.`);
|
|
185
|
+
else if (got.picked.length === 0)
|
|
186
|
+
say(' Choose at least one agent.');
|
|
187
|
+
else {
|
|
188
|
+
selected = got.picked;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Only what the answer changed is written, as `agents disable` / `agents enable` would.
|
|
193
|
+
let choice = { ...(config.allowAgents ? { allowAgents: config.allowAgents } : {}), denyAgents: config.denyAgents };
|
|
194
|
+
const removed = before.filter((a) => !selected.includes(a));
|
|
195
|
+
const added = selected.filter((a) => !before.includes(a));
|
|
196
|
+
if (removed.length > 0)
|
|
197
|
+
choice = applyAgentChoice(choice, 'disable', removed);
|
|
198
|
+
if (added.length > 0)
|
|
199
|
+
choice = applyAgentChoice(choice, 'enable', added);
|
|
200
|
+
for (const agent of added) {
|
|
201
|
+
const row = rows.find((r) => r.agent === agent);
|
|
202
|
+
if (!row.installed)
|
|
203
|
+
say(` note: ${agent} is not installed; it is used once it is installed.`);
|
|
204
|
+
else if (row.enabledInOrca === 'no')
|
|
205
|
+
say(` note: ${agent} is switched off in Orca; switch it on in Orca's settings (Agents) to use it.`);
|
|
206
|
+
}
|
|
207
|
+
const working = { ...config, ...choice };
|
|
208
|
+
if (!choice.allowAgents)
|
|
209
|
+
delete working.allowAgents;
|
|
210
|
+
// 2. Favorites
|
|
211
|
+
say();
|
|
212
|
+
say('2/4 Favorite routes (optional)');
|
|
213
|
+
const limitNote = config.preferRiskLimit === DEFAULT_CONFIG.preferRiskLimit ? 'the default' : `the default is ${DEFAULT_CONFIG.preferRiskLimit}%`;
|
|
214
|
+
say('An available, unblocked favorite is used for its tier. Above');
|
|
215
|
+
say(`${config.preferRiskLimit}% (${limitNote}) projected usage, a known within-limit alternative replaces it.`);
|
|
216
|
+
say('If none exists, the favorite is retained with a warning. Without a favorite, the route with the most room wins.');
|
|
217
|
+
const pins = { ...config.pins };
|
|
218
|
+
let riskLimit = config.preferRiskLimit;
|
|
219
|
+
if (await yesNo('Set favorites?', Object.keys(config.pins).length > 0)) {
|
|
220
|
+
for (const tier of TIERS) {
|
|
221
|
+
const t = tierChoice(tier, env, working);
|
|
222
|
+
say();
|
|
223
|
+
const now = t.pick ? `${t.pick.agent} · ${t.pick.model}${t.pick.effort ? ` · ${t.pick.effort}` : ''}` : 'no route';
|
|
224
|
+
say(`${TIER_NAMES[tier]}: now ${now}; favorite: ${prefLabel(pins[tier])}`);
|
|
225
|
+
if (t.options.length === 0) {
|
|
226
|
+
say(' No routes with these agents; skipped.');
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
for (const line of table(t.options.map((o, i) => [String(i + 1), `${o.agent} ${o.model}`, paceLabel(o)])))
|
|
230
|
+
say(line);
|
|
231
|
+
for (;;) {
|
|
232
|
+
const a = await ask(`Favorite for ${TIER_NAMES[tier]}? Number, 0 for none [${pins[tier] ? 'keep' : 'none'}]: `);
|
|
233
|
+
if (a === '')
|
|
234
|
+
break;
|
|
235
|
+
const n = /^\d+$/.test(a) ? Number(a) : NaN;
|
|
236
|
+
if (n === 0) {
|
|
237
|
+
delete pins[tier];
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
const o = t.options[n - 1];
|
|
241
|
+
if (o) {
|
|
242
|
+
pins[tier] = { agent: o.agent, model: o.model };
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
say(` Answer a number from 0 to ${t.options.length}.`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (Object.keys(pins).length > 0) {
|
|
249
|
+
for (;;) {
|
|
250
|
+
const a = await ask(`Skip a favorite when it is on pace for more than what percent? [${riskLimit}]: `);
|
|
251
|
+
const n = a === '' ? riskLimit : parsePercent(a);
|
|
252
|
+
if (n !== undefined) {
|
|
253
|
+
riskLimit = n;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
say(' Answer a number of percent, such as 100.');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// 3. Bans
|
|
261
|
+
say();
|
|
262
|
+
say('3/4 Models never to use (optional)');
|
|
263
|
+
const families = familyRows(env, working);
|
|
264
|
+
if (families.length > 0) {
|
|
265
|
+
say('Model families found:');
|
|
266
|
+
for (const line of table(families.map((f, i) => {
|
|
267
|
+
const ids = [...new Set(f.models.map((m) => m.model))];
|
|
268
|
+
return [String(i + 1), f.family, ids.slice(0, 4).join(', ') + (ids.length > 4 ? ', …' : '')];
|
|
269
|
+
})))
|
|
270
|
+
say(line);
|
|
271
|
+
}
|
|
272
|
+
say('Your answer replaces the list. To stop using a whole agent, leave it out in question 1 instead.');
|
|
273
|
+
let bans = config.banModels;
|
|
274
|
+
for (;;) {
|
|
275
|
+
const a = await ask(`Never use which? Numbers, families or model ids; "none" for no bans [${bans.join(', ') || 'none'}]: `);
|
|
276
|
+
if (a === '')
|
|
277
|
+
break;
|
|
278
|
+
if (a.toLowerCase() === 'none') {
|
|
279
|
+
bans = [];
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
const entries = [...new Set(a.split(/[\s,]+/).filter(Boolean).map((token) => /^\d+$/.test(token) ? (families[Number(token) - 1]?.family ?? '') : token.toLowerCase()))];
|
|
283
|
+
if (entries.includes('')) {
|
|
284
|
+
say(` Numbers go from 1 to ${families.length}.`);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const matches = banMatches(entries, env);
|
|
288
|
+
const agent = agentNotFamily(entries, matches);
|
|
289
|
+
if (agent) {
|
|
290
|
+
say(` "${agent}" is an agent, not a model family; leave it out in question 1 (or run: orcacompass agents disable ${agent}).`);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
for (const e of entries)
|
|
294
|
+
if (matches[e].length === 0)
|
|
295
|
+
say(` note: "${e}" matches no model found right now; it is kept anyway.`);
|
|
296
|
+
bans = entries;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
// 4. Summary
|
|
300
|
+
const next = { ...working, pins, preferRiskLimit: riskLimit, banModels: bans };
|
|
301
|
+
say();
|
|
302
|
+
say('4/4 Summary');
|
|
303
|
+
const verdicts = env.discoveries.map((d) => ({ agent: d.agent, reason: agentSkipReason(d, env, next) }));
|
|
304
|
+
say(`Agents used: ${verdicts.filter((v) => !v.reason).map((v) => v.agent).join(', ') || 'none'}`);
|
|
305
|
+
const unused = verdicts.filter((v) => v.reason);
|
|
306
|
+
// The short reason only: "not signed in or unavailable", without Orca's message.
|
|
307
|
+
if (unused.length > 0)
|
|
308
|
+
say(`Not used: ${unused.map((v) => `${v.agent} (${v.reason.split(': ')[0]})`).join(', ')}`);
|
|
309
|
+
const favs = TIERS.filter((t) => pins[t]).map((t) => `${TIER_NAMES[t]} ${prefLabel(pins[t])}`);
|
|
310
|
+
say(favs.length > 0
|
|
311
|
+
? `Favorites: ${favs.join('; ')}; above ${riskLimit}%, switch only to a known within-limit alternative`
|
|
312
|
+
: 'Favorites: none; every tier takes the route with the most room');
|
|
313
|
+
say(`Never used: ${bans.join(', ') || 'nothing'}`);
|
|
314
|
+
say('Example routes:');
|
|
315
|
+
for (const tier of TIERS) {
|
|
316
|
+
const d = route({ tier }, env, next);
|
|
317
|
+
const r = d.route;
|
|
318
|
+
const moved = d.tier && d.tier !== tier ? ` (${d.downgraded ? 'downgraded' : 'upgraded'} to ${d.tier})` : '';
|
|
319
|
+
say(` ${tier.padEnd(8)} ${r ? `${r.agent} · ${r.model}${r.effort ? ` · ${r.effort}` : ''}${moved}` : 'no route'}`);
|
|
320
|
+
for (const w of d.warnings)
|
|
321
|
+
say(` ${' '.repeat(8)} warning: ${w}`);
|
|
322
|
+
}
|
|
323
|
+
const changedTiers = TIERS.filter((t) => !samePin(pins[t], config.pins[t]));
|
|
324
|
+
const agentsChanged = !sameList(choice.allowAgents, config.allowAgents) || !sameList(choice.denyAgents, config.denyAgents);
|
|
325
|
+
const changed = agentsChanged || changedTiers.length > 0 || riskLimit !== config.preferRiskLimit || !sameList(bans, config.banModels);
|
|
326
|
+
say();
|
|
327
|
+
if (!changed && exists) {
|
|
328
|
+
say(`Nothing changed. Config: ${path}`);
|
|
329
|
+
return 0;
|
|
330
|
+
}
|
|
331
|
+
if (!(await yesNo(`Save to ${path}?`, true))) {
|
|
332
|
+
say('Not saved.');
|
|
333
|
+
return 0;
|
|
334
|
+
}
|
|
335
|
+
updateConfigFile((raw) => {
|
|
336
|
+
if (agentsChanged)
|
|
337
|
+
setAgentChoice(raw, choice);
|
|
338
|
+
for (const t of changedTiers)
|
|
339
|
+
setPin(raw, t, pins[t]);
|
|
340
|
+
if (riskLimit !== config.preferRiskLimit)
|
|
341
|
+
setPreferRiskLimit(raw, riskLimit);
|
|
342
|
+
if (!sameList(bans, config.banModels))
|
|
343
|
+
setBans(raw, bans);
|
|
344
|
+
}, path);
|
|
345
|
+
say(`Saved ${path}`);
|
|
346
|
+
return 0;
|
|
347
|
+
}
|
|
348
|
+
catch (e) {
|
|
349
|
+
if (!(e instanceof Canceled))
|
|
350
|
+
throw e;
|
|
351
|
+
say();
|
|
352
|
+
say('Setup canceled; nothing was saved.');
|
|
353
|
+
return 1;
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
rl.close();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { accessSync, constants, statSync } from 'node:fs';
|
|
3
|
+
import { delimiter, join } from 'node:path';
|
|
4
|
+
import { homeDir } from '../paths.js';
|
|
5
|
+
// cmd.exe has no escape for `"` inside a quoted argument, and it expands `%NAME%` even inside
|
|
6
|
+
// quotes (which could leak an environment variable's value), so refuse both rather than mangle them.
|
|
7
|
+
export const quote = (s) => {
|
|
8
|
+
if (s.includes('"'))
|
|
9
|
+
throw new Error(`cannot pass an argument containing a double quote through cmd.exe: ${s}`);
|
|
10
|
+
if (s.includes('%'))
|
|
11
|
+
throw new Error(`cannot pass an argument containing % through cmd.exe: ${s}`);
|
|
12
|
+
if (/^[\w\-.:\\/=@]+$/.test(s))
|
|
13
|
+
return s;
|
|
14
|
+
// Backslashes right before the closing quote would escape it, so double them.
|
|
15
|
+
return `"${s.replace(/(\\+)$/, '$1$1')}"`;
|
|
16
|
+
};
|
|
17
|
+
// The folders Orca adds to its own PATH on macOS and Linux, which is where installers and package managers
|
|
18
|
+
// put CLIs. A launcher or non-login shell can leave them out of ours, and Orca could then run an agent (or
|
|
19
|
+
// its own `orca`, in ~/.local/bin or /usr/local/bin) that OrcaCompass reports as missing.
|
|
20
|
+
function unixToolDirs(env, platform) {
|
|
21
|
+
const home = homeDir(env, platform);
|
|
22
|
+
return [
|
|
23
|
+
'/opt/homebrew/bin', '/opt/homebrew/sbin', '/usr/local/bin', '/usr/local/sbin',
|
|
24
|
+
...(platform === 'linux' ? ['/snap/bin', '/home/linuxbrew/.linuxbrew/bin'] : []),
|
|
25
|
+
'/nix/var/nix/profiles/default/bin',
|
|
26
|
+
...['bin', '.local/bin', '.nix-profile/bin', '.opencode/bin', '.vite-plus/bin', '.grok/bin'].map((dir) => join(home, dir)),
|
|
27
|
+
...(platform === 'darwin' ? ['/opt/local/bin', '/opt/local/sbin'] : []),
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
/** PATH followed by those folders, so the user's own order wins. Windows installers update PATH themselves. */
|
|
31
|
+
export function searchPath(path = process.env.PATH, env = process.env, platform = process.platform) {
|
|
32
|
+
const current = path ?? '';
|
|
33
|
+
if (platform === 'win32')
|
|
34
|
+
return current;
|
|
35
|
+
const known = new Set(current.split(delimiter));
|
|
36
|
+
return [current, ...unixToolDirs(env, platform).filter((dir) => !known.has(dir))].filter(Boolean).join(delimiter);
|
|
37
|
+
}
|
|
38
|
+
export const runCommand = (cmd, args, opts = {}) => new Promise((resolve) => {
|
|
39
|
+
const timeoutMs = opts.timeoutMs ?? 15_000;
|
|
40
|
+
let line;
|
|
41
|
+
if (process.platform === 'win32') {
|
|
42
|
+
try {
|
|
43
|
+
line = [cmd, ...args].map(quote).join(' ');
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
resolve({ code: null, stdout: '', stderr: '', error: e instanceof Error ? e.message : String(e) });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let stdout = '';
|
|
51
|
+
let stderr = '';
|
|
52
|
+
let error;
|
|
53
|
+
let settled = false;
|
|
54
|
+
let timer;
|
|
55
|
+
const finish = (code) => {
|
|
56
|
+
if (settled)
|
|
57
|
+
return;
|
|
58
|
+
settled = true;
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
resolve({ code, stdout, stderr, ...(error ? { error } : {}) });
|
|
61
|
+
};
|
|
62
|
+
// Windows .cmd shims (orca, cursor-agent) only run through a shell.
|
|
63
|
+
// stdin is ignored so a login prompt sees EOF instead of waiting forever.
|
|
64
|
+
const stdio = ['ignore', 'pipe', 'pipe'];
|
|
65
|
+
const env = { ...process.env, ...opts.env };
|
|
66
|
+
// Node looks a bare command up on this PATH. Windows keeps its own "Path" spelling, so it is left alone.
|
|
67
|
+
if (process.platform !== 'win32')
|
|
68
|
+
env.PATH = searchPath(env.PATH, env);
|
|
69
|
+
const child = line !== undefined ? spawn(line, { shell: true, windowsHide: true, stdio, env }) : spawn(cmd, args, { stdio, env });
|
|
70
|
+
const kill = () => {
|
|
71
|
+
if (line === undefined || child.pid === undefined) {
|
|
72
|
+
child.kill();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// child is cmd.exe; /T needs it alive to find the real process, which would otherwise
|
|
76
|
+
// keep our stdout/stderr pipes (and so the event loop) open.
|
|
77
|
+
const killer = spawn('taskkill', ['/T', '/F', '/PID', String(child.pid)], { windowsHide: true, stdio: 'ignore' });
|
|
78
|
+
killer.on('error', () => child.kill());
|
|
79
|
+
killer.on('close', () => child.kill());
|
|
80
|
+
};
|
|
81
|
+
timer = setTimeout(() => {
|
|
82
|
+
error = `timed out after ${timeoutMs} ms`;
|
|
83
|
+
kill();
|
|
84
|
+
child.stdout.destroy();
|
|
85
|
+
child.stderr.destroy();
|
|
86
|
+
finish(null);
|
|
87
|
+
}, timeoutMs);
|
|
88
|
+
child.stdout.on('data', (d) => (stdout += d));
|
|
89
|
+
child.stderr.on('data', (d) => (stderr += d));
|
|
90
|
+
child.on('error', (e) => {
|
|
91
|
+
error = e.message;
|
|
92
|
+
finish(null);
|
|
93
|
+
});
|
|
94
|
+
child.on('close', (code) => finish(code));
|
|
95
|
+
});
|
|
96
|
+
export const runInteractive = (cmd, args) => new Promise((resolve, reject) => {
|
|
97
|
+
// npx and npm are .cmd shims on Windows, which only run through a shell.
|
|
98
|
+
const child = process.platform === 'win32'
|
|
99
|
+
? spawn([cmd, ...args].map(quote).join(' '), { shell: true, stdio: 'inherit' })
|
|
100
|
+
: spawn(cmd, args, { stdio: 'inherit' });
|
|
101
|
+
child.on('error', reject);
|
|
102
|
+
child.on('close', (code) => resolve(code));
|
|
103
|
+
});
|
|
104
|
+
/** A file this user can run; on Windows the X_OK check only asks whether it exists. */
|
|
105
|
+
function isRunnable(path) {
|
|
106
|
+
try {
|
|
107
|
+
accessSync(path, constants.X_OK);
|
|
108
|
+
return statSync(path).isFile();
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** Looks for an executable in extraPaths, on PATH (with PATHEXT on Windows) and in the usual tool folders. */
|
|
115
|
+
export function findExecutable(name, extraPaths = [], pathVar = process.env.PATH) {
|
|
116
|
+
const dirs = [...extraPaths, ...searchPath(pathVar).split(delimiter)].filter(Boolean);
|
|
117
|
+
const exts = process.platform === 'win32'
|
|
118
|
+
? ['', ...(process.env.PATHEXT ?? '.EXE;.CMD;.BAT;.COM').split(';').map((e) => e.toLowerCase())]
|
|
119
|
+
: [''];
|
|
120
|
+
for (const dir of dirs) {
|
|
121
|
+
for (const ext of exts) {
|
|
122
|
+
const p = join(dir, name + ext);
|
|
123
|
+
if (isRunnable(p))
|
|
124
|
+
return p;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Shared types for the routing core and its adapters. The core never does I/O;
|
|
2
|
+
// adapters turn the machine into an Environment and the router turns that into a Decision.
|
|
3
|
+
export const TIERS = ['light', 'daily', 'advanced', 'frontier'];
|
|
4
|
+
export const DEMANDS = ['low', 'moderate', 'high', 'exceptional'];
|
|
5
|
+
export const EFFORT_POLICIES = ['efficient', 'balanced', 'quality'];
|
|
6
|
+
/** Every agent OrcaCompass knows, in display order (Muse is detected only, never routed). */
|
|
7
|
+
export const AGENT_IDS = ['claude', 'codex', 'cursor', 'grok', 'antigravity', 'opencode', 'muse'];
|
|
8
|
+
export const CLASSIFICATION_SOURCES = ['override', 'lineup', 'family', 'benchmark', 'score', 'auto'];
|
package/dist/verify.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { findRejection } from './routing/rejection.js';
|
|
2
|
+
function orcaResult(stdout, code, error) {
|
|
3
|
+
try {
|
|
4
|
+
const data = JSON.parse(stdout);
|
|
5
|
+
if (data?.ok === true)
|
|
6
|
+
return { ok: true, value: data.result ?? {} };
|
|
7
|
+
const e = data?.error;
|
|
8
|
+
return { ok: false, error: typeof e === 'string' ? e : e?.message ?? e?.code ?? 'orca reported an error' };
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return { ok: false, error: error ?? (code === 0 ? 'orca printed no JSON' : `orca exited with code ${code}`) };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** `orca orchestration worker-show --json`: the effective launch (agent, model) and the Task. */
|
|
15
|
+
export function parseWorkerShow(stdout, code = 0, error) {
|
|
16
|
+
const r = orcaResult(stdout, code, error);
|
|
17
|
+
if (!r.ok)
|
|
18
|
+
return r;
|
|
19
|
+
const launch = r.value.worker?.startOptions?.launch ?? {};
|
|
20
|
+
const effective = launch.effective ?? launch.requested ?? {};
|
|
21
|
+
const str = (x) => (typeof x === 'string' && x !== '' ? x : undefined);
|
|
22
|
+
return {
|
|
23
|
+
ok: true,
|
|
24
|
+
value: {
|
|
25
|
+
agent: str(effective.agent) ?? str(r.value.worker?.startOptions?.agent),
|
|
26
|
+
model: str(effective.model),
|
|
27
|
+
taskId: str(r.value.dispatch?.taskId) ?? str(r.value.dispatch?.task_id),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** `orca orchestration worker-read --source terminal --json`: the fleet projection and the terminal tail. */
|
|
32
|
+
export function parseWorkerRead(stdout, code = 0, error) {
|
|
33
|
+
const r = orcaResult(stdout, code, error);
|
|
34
|
+
if (!r.ok)
|
|
35
|
+
return r;
|
|
36
|
+
const p = r.value.projection ?? {};
|
|
37
|
+
const tail = Array.isArray(r.value.terminal?.tail) ? r.value.terminal.tail.filter((l) => typeof l === 'string') : [];
|
|
38
|
+
return {
|
|
39
|
+
ok: true,
|
|
40
|
+
value: { activity: p.stage?.activity, outcome: p.outcome, liveness: p.liveness?.verdict, stage: p.stage?.detail, tail },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const lastLines = (tail, n = 12) => tail.map((l) => l.trimEnd()).filter((l) => l.trim() !== '').slice(-n);
|
|
44
|
+
export async function verifyWorker(dispatchId, deps, opts) {
|
|
45
|
+
const waitMs = Math.min(60_000, Math.max(0, opts.waitMs));
|
|
46
|
+
const deadline = deps.clock() + waitMs;
|
|
47
|
+
const remaining = () => Math.max(0, deadline - deps.clock());
|
|
48
|
+
const timeoutDetail = `no verdict within ${waitMs / 1000}s`;
|
|
49
|
+
if (waitMs === 0)
|
|
50
|
+
return { status: 'unknown', dispatchId, detail: timeoutDetail, cleanup: [] };
|
|
51
|
+
const workingMs = opts.workingMs ?? 8_000;
|
|
52
|
+
const pollMs = opts.pollMs ?? 1_500;
|
|
53
|
+
const orca = (args) => deps.run('orca', ['orchestration', ...args, '--dispatch', dispatchId, '--json'], { timeoutMs: Math.min(20_000, remaining()) });
|
|
54
|
+
const stop = ['orca', 'orchestration', 'worker-stop', '--dispatch', dispatchId, '--json'];
|
|
55
|
+
const release = ['orca', 'orchestration', 'worker-release', '--dispatch', dispatchId, '--json'];
|
|
56
|
+
const shown = await orca(['worker-show']);
|
|
57
|
+
const launch = parseWorkerShow(shown.stdout, shown.code, shown.error);
|
|
58
|
+
if (!launch.ok)
|
|
59
|
+
return { status: 'unknown', dispatchId, detail: `orca worker-show failed: ${launch.error}`, cleanup: [] };
|
|
60
|
+
const { agent, model, taskId } = launch.value;
|
|
61
|
+
const base = { dispatchId, ...(taskId ? { taskId } : {}), ...(agent ? { agent } : {}), ...(model ? { model } : {}) };
|
|
62
|
+
let tail = [];
|
|
63
|
+
let workingSince;
|
|
64
|
+
let doneSince;
|
|
65
|
+
let lastError;
|
|
66
|
+
for (;;) {
|
|
67
|
+
if (remaining() === 0) {
|
|
68
|
+
const detail = lastError ? `orca worker-read failed: ${lastError}` : timeoutDetail;
|
|
69
|
+
return { ...base, status: 'unknown', detail, ...(tail.length ? { tail: lastLines(tail) } : {}), cleanup: [] };
|
|
70
|
+
}
|
|
71
|
+
const read = await orca(['worker-read', '--source', 'terminal', '--limit', '80']);
|
|
72
|
+
const obs = parseWorkerRead(read.stdout, read.code, read.error);
|
|
73
|
+
const now = deps.clock();
|
|
74
|
+
if (!obs.ok) {
|
|
75
|
+
lastError = obs.error;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
lastError = undefined;
|
|
79
|
+
const o = obs.value;
|
|
80
|
+
// An exited terminal can come back empty: keep the last output that was seen.
|
|
81
|
+
if (o.tail.length > 0)
|
|
82
|
+
tail = o.tail;
|
|
83
|
+
const settled = o.liveness === 'exited' || o.outcome === 'failed';
|
|
84
|
+
const message = model ? findRejection(model, tail) : undefined;
|
|
85
|
+
if (message) {
|
|
86
|
+
return { ...base, status: 'rejected', message, detail: `${agent ?? 'the agent'} refused ${model}`, cleanup: settled ? [release] : [stop, release] };
|
|
87
|
+
}
|
|
88
|
+
if (o.outcome === 'succeeded')
|
|
89
|
+
return { ...base, status: 'reported', detail: 'the worker already reported worker_done', cleanup: [] };
|
|
90
|
+
if (settled) {
|
|
91
|
+
const why = o.stage ? ` (${o.stage.replace(/_/g, ' ')})` : '';
|
|
92
|
+
return { ...base, status: 'failed', detail: `the worker ended without worker_done${why}`, tail: lastLines(tail), cleanup: [release] };
|
|
93
|
+
}
|
|
94
|
+
workingSince = o.activity === 'working' ? (workingSince ?? now) : undefined;
|
|
95
|
+
if (workingSince !== undefined && now - workingSince >= workingMs) {
|
|
96
|
+
return { ...base, status: 'started', detail: `working for ${Math.round((now - workingSince) / 1000)}s with no refusal`, cleanup: [] };
|
|
97
|
+
}
|
|
98
|
+
// The agent's turn ended without worker_done: a refusal not recognized, an error, or a question in its own prompt.
|
|
99
|
+
doneSince = o.activity === 'done' && o.outcome === 'in_progress' ? (doneSince ?? now) : undefined;
|
|
100
|
+
if (doneSince !== undefined && now - doneSince >= 3_000) {
|
|
101
|
+
return { ...base, status: 'stalled', detail: 'the agent stopped without worker_done', tail: lastLines(tail), cleanup: [] };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
await deps.sleep(Math.min(pollMs, remaining()));
|
|
105
|
+
}
|
|
106
|
+
}
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "orcacompass",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "orcacompass",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Usage-aware agent/model/effort routing for Orca coordinator agents",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "manomilano",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/manomilano/orca-compass.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/manomilano/orca-compass#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/manomilano/orca-compass/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"orca",
|
|
17
|
+
"agent-skill",
|
|
18
|
+
"ai-agents",
|
|
19
|
+
"llm",
|
|
20
|
+
"model-routing",
|
|
21
|
+
"claude-code",
|
|
22
|
+
"codex",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bin": {
|
|
27
|
+
"orcacompass": "dist/cli.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"data",
|
|
32
|
+
"skills",
|
|
33
|
+
"NOTICE"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc",
|
|
40
|
+
"prepare": "tsc",
|
|
41
|
+
"prepublishOnly": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc && npm test && npm run test:package",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"snapshot": "node scripts/make-snapshot.mjs",
|
|
44
|
+
"test:package": "node scripts/test-package.mjs",
|
|
45
|
+
"docs:dev": "vitepress dev docs",
|
|
46
|
+
"docs:build": "vitepress build docs",
|
|
47
|
+
"docs:preview": "vitepress preview docs"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^26.6.6",
|
|
51
|
+
"typescript": "^7.0.2",
|
|
52
|
+
"vitepress": "^1.6.4",
|
|
53
|
+
"vitest": "^5.0.5"
|
|
54
|
+
},
|
|
55
|
+
"overrides": {
|
|
56
|
+
"vitepress": {
|
|
57
|
+
"vite": "^6.4.4"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|