@fanglinwei/agent-fit 0.8.0 → 0.9.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/.codex-plugin/plugin.json +1 -1
- package/README.md +33 -131
- package/VERSION +1 -1
- package/adapters/codex/model-bindings.json +7 -0
- package/adapters/codex/modes.json +112 -112
- package/adapters/codex/skills/agent-fit/SKILL.md +11 -10
- package/adapters/codex/skills/agent-fit/assets/AGENTS.fragment.md +2 -2
- package/adapters/codex/skills/agent-fit/assets/codex/agents/task-execute.toml +0 -2
- package/adapters/codex/skills/agent-fit/assets/codex/agents/task-review.toml +0 -2
- package/adapters/codex/skills/agent-fit/assets/codex/agents/task-scan.toml +0 -2
- package/adapters/codex/skills/agent-fit/evals/evals.json +44 -0
- package/adapters/codex/skills/agent-fit/references/calibration.md +8 -2
- package/adapters/codex/skills/agent-fit/references/configuration.md +11 -2
- package/adapters/codex/skills/agent-fit/references/dispatch-contract.md +15 -1
- package/adapters/codex/skills/agent-fit/references/failure-policy.md +4 -4
- package/adapters/codex/skills/agent-fit/references/task-routing.md +19 -19
- package/bin/agent-fit.mjs +16 -5
- package/docs/README.md +10 -12
- package/docs/implementation-review.md +24 -140
- package/docs/usage.md +78 -154
- package/lib/codex.mjs +24 -3
- package/lib/install.mjs +85 -21
- package/lib/models.mjs +6 -3
- package/lib/scopes.mjs +1 -1
- package/package.json +1 -1
- package/web/app.js +3 -3
- package/adapters/codex/profiles/terra-evaluation.json +0 -134
package/lib/install.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import { createHash, randomUUID } from 'node:crypto';
|
|
6
6
|
import { parse as parseToml } from 'smol-toml';
|
|
7
|
-
import { VERSION, LEVELS, ROLES, BUILTINS, resolveDefinition, validateDefinition, renderPayload, verificationRequirement, skillAssets } from './codex.mjs';
|
|
7
|
+
import { VERSION, LEVELS, ROLES, BUILTINS, builtinModes, validateModelBinding, resolveDefinition, validateDefinition, renderPayload, verificationRequirement, skillAssets } from './codex.mjs';
|
|
8
8
|
import { SCOPE_FILE, scopeContext, validateScopeStore, scopeEntry, visibleModes, scopedSelection, assertUnreferenced } from './scopes.mjs';
|
|
9
9
|
import { inspectSkill, updateSkill } from './skill.mjs';
|
|
10
10
|
|
|
@@ -14,6 +14,7 @@ const CURRENT = `${STATE_DIR}/current-mode.json`;
|
|
|
14
14
|
const STATE = `${STATE_DIR}/state.json`;
|
|
15
15
|
const BASELINE = `${STATE_DIR}/restore.json`;
|
|
16
16
|
const CUSTOM = `${STATE_DIR}/custom-modes.json`;
|
|
17
|
+
const BINDINGS = `${STATE_DIR}/model-bindings.json`;
|
|
17
18
|
const LOCK = `${STATE_DIR}/install.lock`;
|
|
18
19
|
const START = '<!-- agent-fit:start -->';
|
|
19
20
|
const END = '<!-- agent-fit:end -->';
|
|
@@ -54,7 +55,7 @@ export function resolveHome(explicit) {
|
|
|
54
55
|
}
|
|
55
56
|
function owned(relative) {
|
|
56
57
|
if (typeof relative !== 'string' || !relative || relative.includes('\\') || /[\p{Cc}\p{Cf}]/u.test(relative) || relative.split('/').some(part => !part || part === '.' || part === '..')) return false;
|
|
57
|
-
return relative === CURRENT || relative === CUSTOM || relative === SCOPE_FILE || ROLE_PATHS.includes(relative) || relative.startsWith(`${SKILL}/`) && !relative.slice(SKILL.length + 1).split('/').some(part => part.startsWith('.'));
|
|
58
|
+
return relative === CURRENT || relative === CUSTOM || relative === BINDINGS || relative === SCOPE_FILE || ROLE_PATHS.includes(relative) || relative.startsWith(`${SKILL}/`) && !relative.slice(SKILL.length + 1).split('/').some(part => part.startsWith('.'));
|
|
58
59
|
}
|
|
59
60
|
function ownedDirectory(relative) {
|
|
60
61
|
return ['agents', 'skills', SKILL, STATE_DIR].includes(relative) || relative.startsWith(`${SKILL}/`) && owned(`${relative}/entry`);
|
|
@@ -229,8 +230,17 @@ async function collect(home, { ignoreLock = false } = {}) {
|
|
|
229
230
|
};
|
|
230
231
|
const directory = async relative => { if (!observedDirectories.has(relative)) observedDirectories.set(relative, await observe(home, relative, true, ignoreLock)); return observedDirectories.get(relative); };
|
|
231
232
|
await directory(''); await directory(STATE_DIR); await directory('agents'); await directory('skills');
|
|
232
|
-
for (const relative of [STATE, BASELINE, CUSTOM, SCOPE_FILE, 'AGENTS.md', 'AGENTS.override.md', 'config.toml', ...ROLE_PATHS]) await file(relative);
|
|
233
|
+
for (const relative of [STATE, BASELINE, CUSTOM, BINDINGS, SCOPE_FILE, 'AGENTS.md', 'AGENTS.override.md', 'config.toml', ...ROLE_PATHS]) await file(relative);
|
|
233
234
|
state = validateState((await file(STATE)).bytes);
|
|
235
|
+
const bindingBytes = (await file(BINDINGS)).bytes;
|
|
236
|
+
let bindings = {}, builtins = BUILTINS;
|
|
237
|
+
if (bindingBytes !== null) {
|
|
238
|
+
if (!Object.hasOwn(state?.files ?? {}, BINDINGS)) fail('STATE_INVALID', '模型绑定未登记所有权。');
|
|
239
|
+
bindings = parseJson(bindingBytes, 'MODEL_BINDINGS_INVALID', '模型绑定无法解析。');
|
|
240
|
+
if (!object(bindings)) fail('MODEL_BINDINGS_INVALID', '模型绑定格式无效。');
|
|
241
|
+
try { builtins = builtinModes(bindings); }
|
|
242
|
+
catch { fail('MODEL_BINDINGS_INVALID', '模型绑定包含无效用途、模型或备用组合。'); }
|
|
243
|
+
}
|
|
234
244
|
const customModes = validateCustom((await file(CUSTOM)).bytes);
|
|
235
245
|
let scopeStore;
|
|
236
246
|
try { const bytes = (await file(SCOPE_FILE)).bytes; scopeStore = validateScopeStore(bytes === null ? null : parseJson(bytes, 'SCOPE_CONFIG_INVALID', '作用域配置无法解析。')); }
|
|
@@ -239,7 +249,7 @@ async function collect(home, { ignoreLock = false } = {}) {
|
|
|
239
249
|
await file(modeFile);
|
|
240
250
|
let mode = null;
|
|
241
251
|
if (state) {
|
|
242
|
-
try { mode = resolveDefinition(state.mode, customModes); } catch { fail('STATE_INVALID', '活动档位引用无效。'); }
|
|
252
|
+
try { mode = resolveDefinition(state.mode, customModes, builtins); } catch { fail('STATE_INVALID', '活动档位引用无效。'); }
|
|
243
253
|
if (mode.kind !== state.mode_kind) fail('STATE_INVALID', '活动档位类型记录无效。');
|
|
244
254
|
const installedBytes = (await file(modeFile)).bytes;
|
|
245
255
|
if (installedBytes !== null) {
|
|
@@ -324,7 +334,7 @@ async function collect(home, { ignoreLock = false } = {}) {
|
|
|
324
334
|
if (override && /[^\p{White_Space}]/u.test(override.toString('utf8'))) diagnostics.push(diagnostic('RULES_SHADOWED', 'warn', path.join(home, 'AGENTS.override.md'), '非空 AGENTS.override.md 遮蔽本库 AGENTS.md。'));
|
|
325
335
|
diagnostics.push(diagnostic('MODEL_ACCESS_UNKNOWN', 'unknown', 'static_configuration', '静态配置不证明账号调用权限。', ['models', 'check']));
|
|
326
336
|
diagnostics.push(diagnostic('RULES_LOAD_UNVERIFIED', 'unknown', 'static_configuration', '规则读取与运行模型生效需要宿主证据。'));
|
|
327
|
-
const snapshot = { home, state, mode, customModes, scopeStore, baseline, observedFiles, observedDirectories, legacyFiles, skill, diagnostics, config, externalRoles, roles, payload: candidates };
|
|
337
|
+
const snapshot = { home, state, mode, customModes, bindings, builtins, scopeStore, baseline, observedFiles, observedDirectories, legacyFiles, skill, diagnostics, config, externalRoles, roles, payload: candidates };
|
|
328
338
|
snapshot.configuration_revision = revision(snapshot);
|
|
329
339
|
return snapshot;
|
|
330
340
|
}
|
|
@@ -372,7 +382,8 @@ function restart(reason, restore = false, restartRequired = false) {
|
|
|
372
382
|
return { required: reason === 'deployment_changed' ? true : reason === 'partial_or_unknown' ? null : false, reason, message: messages[reason] };
|
|
373
383
|
}
|
|
374
384
|
function changeReport(plan, result, configurationStatus, after = null, reason) {
|
|
375
|
-
|
|
385
|
+
const binding = plan.modelBinding;
|
|
386
|
+
return { action: plan.action, agent: 'codex', home: plan.snapshot.home, scope: plan.scope ?? 'global', result, configuration_status: configurationStatus, changed_files: [...plan.changes.keys()], changes: [...plan.changes].map(([relative, change]) => ({ path: relative, action: change.after === null ? 'remove' : change.before.bytes === null ? 'create' : 'replace', permission_changed: change.after !== null && change.before.mode !== change.mode })), revision_before: plan.snapshot.configuration_revision, revision_after: after, mode: plan.mode ? { id: plan.mode.id, name: plan.mode.name, kind: plan.mode.kind } : null, custom_modes_removed: plan.action === 'restore' ? [...plan.snapshot.customModes, ...plan.snapshot.scopeStore.projects.flatMap(entry => entry.modes), ...plan.snapshot.scopeStore.sessions.flatMap(entry => entry.modes)].map(mode => mode.name) : [], warnings: plan.warnings ?? [], restart: restart(reason, plan.action === 'restore', plan.restartRequired), runtime_verification: 'unverified', ...(binding && { model_binding: { ...binding, preview_token: result === 'preview' ? binding.preview_token : undefined } }) };
|
|
376
387
|
}
|
|
377
388
|
async function directoryCreation(snapshot, relatives) {
|
|
378
389
|
const directories = new Set();
|
|
@@ -418,12 +429,31 @@ function configuredLevels(definition, options) {
|
|
|
418
429
|
}
|
|
419
430
|
return levels;
|
|
420
431
|
}
|
|
432
|
+
function bindingChanges(snapshot, builtins) {
|
|
433
|
+
const changes = [];
|
|
434
|
+
for (const mode of builtins) {
|
|
435
|
+
const previous = snapshot.mode?.id === mode.id ? snapshot.mode : snapshot.builtins.find(old => old.id === mode.id);
|
|
436
|
+
for (const [level, value] of Object.entries(mode.levels)) {
|
|
437
|
+
const old = previous.levels[level];
|
|
438
|
+
for (const task of new Set([null, ...Object.keys(old.tasks ?? {}), ...Object.keys(value.tasks ?? {})])) {
|
|
439
|
+
const before = task === null ? old : old.tasks?.[task];
|
|
440
|
+
const after = task === null ? value : value.tasks?.[task];
|
|
441
|
+
for (const [position, a, b] of [['primary', before, after], ['fallback', before?.fallback, after?.fallback]]) {
|
|
442
|
+
if (a?.model === b?.model && a?.effort === b?.effort) continue;
|
|
443
|
+
changes.push({ mode: mode.id, level, task, position, before: a ? { model: a.model, effort: a.effort } : null, after: b ? { model: b.model, effort: b.effort } : null });
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return changes;
|
|
449
|
+
}
|
|
450
|
+
|
|
421
451
|
async function buildPlan(snapshot, action, options) {
|
|
422
452
|
requireRevision(snapshot, options.expectRevision);
|
|
423
453
|
requireClean(snapshot, action === 'restore', action === 'setup');
|
|
424
454
|
const { state, home } = snapshot;
|
|
425
455
|
if (action !== 'setup' && action !== 'restore' && !state) fail('NOT_INSTALLED', '请先执行 setup 配置 Codex。');
|
|
426
|
-
if (!['setup', 'set', 'clear', 'delete', 'create', 'configure', 'restore'].includes(action)) fail('INVALID_ACTION', '不支持的写入动作。', 2);
|
|
456
|
+
if (!['setup', 'set', 'clear', 'delete', 'create', 'configure', 'restore', 'model-bind'].includes(action)) fail('INVALID_ACTION', '不支持的写入动作。', 2);
|
|
427
457
|
const changes = new Map();
|
|
428
458
|
const plan = { snapshot, action, changes, mode: snapshot.mode, warnings: [], deploymentChanged: false, restartRequired: false, cleanupDirectories: [] };
|
|
429
459
|
const add = async (relative, after, mode) => {
|
|
@@ -458,8 +488,21 @@ async function buildPlan(snapshot, action, options) {
|
|
|
458
488
|
plan.restartRequired = plan.deploymentChanged;
|
|
459
489
|
return plan;
|
|
460
490
|
}
|
|
491
|
+
let { bindings, builtins } = snapshot;
|
|
492
|
+
if (action === 'model-bind') {
|
|
493
|
+
const { slot, model } = options;
|
|
494
|
+
validateModelBinding(slot, model);
|
|
495
|
+
bindings = { ...bindings, [slot]: model };
|
|
496
|
+
builtins = builtinModes(bindings);
|
|
497
|
+
const routes = bindingChanges(snapshot, builtins);
|
|
498
|
+
const previewToken = hash(json({ home, revision: snapshot.configuration_revision, slot, model, routes }));
|
|
499
|
+
if (!options.dryRun && options.apply !== previewToken) fail('MODEL_BINDING_PREVIEW_REQUIRED', '请重新预览绑定,再用预览令牌应用。', 2);
|
|
500
|
+
plan.modelBinding = { slot, model, routes, preview_token: previewToken };
|
|
501
|
+
if (!routes.length) return plan;
|
|
502
|
+
}
|
|
503
|
+
const resolve = (selector, custom) => resolveDefinition(selector, custom, builtins);
|
|
461
504
|
const context = await scopeContext(options);
|
|
462
|
-
if (
|
|
505
|
+
if (['setup', 'model-bind'].includes(action) && context.scope !== 'global') fail('INVALID_ARGUMENT', '该命令只管理绑定 home 的全局配置。', 2);
|
|
463
506
|
plan.scope = context.scope;
|
|
464
507
|
const scopeStore = structuredClone(snapshot.scopeStore);
|
|
465
508
|
const local = context.scope !== 'global';
|
|
@@ -467,7 +510,7 @@ async function buildPlan(snapshot, action, options) {
|
|
|
467
510
|
if (action === 'clear' && !scopeEntry(scopeStore, context)) { plan.mode = scopedSelection(snapshot, context).definition; return plan; }
|
|
468
511
|
const entry = scopeEntry(scopeStore, context, true);
|
|
469
512
|
const available = visibleModes(snapshot, context);
|
|
470
|
-
if (action === 'set') entry.selection =
|
|
513
|
+
if (action === 'set') entry.selection = resolve(options.mode, available).id;
|
|
471
514
|
if (action === 'clear') entry.selection = null;
|
|
472
515
|
if (action === 'create') {
|
|
473
516
|
const name = normalizeName(options.name);
|
|
@@ -477,7 +520,7 @@ async function buildPlan(snapshot, action, options) {
|
|
|
477
520
|
entry.modes.push(definition); plan.created_mode = definition;
|
|
478
521
|
}
|
|
479
522
|
if (action === 'configure') {
|
|
480
|
-
const source =
|
|
523
|
+
const source = resolve(options.mode, available);
|
|
481
524
|
if (source.kind !== 'custom') fail('BUILTIN_READ_ONLY', '内置档位不可修改;请先复制为自定义档位。', 2);
|
|
482
525
|
const levels = configuredLevels(source, options);
|
|
483
526
|
let definition = entry.modes.find(mode => mode.id === source.id);
|
|
@@ -490,7 +533,7 @@ async function buildPlan(snapshot, action, options) {
|
|
|
490
533
|
} else definition.levels = levels;
|
|
491
534
|
}
|
|
492
535
|
if (action === 'delete') {
|
|
493
|
-
const definition =
|
|
536
|
+
const definition = resolve(options.mode, available);
|
|
494
537
|
if (!entry.modes.some(mode => mode.id === definition.id)) fail('SCOPE_READ_ONLY', '只能删除当前作用域创建的自定义档位。', 2);
|
|
495
538
|
assertUnreferenced(snapshot, definition.id);
|
|
496
539
|
entry.modes = entry.modes.filter(mode => mode.id !== definition.id);
|
|
@@ -499,11 +542,11 @@ async function buildPlan(snapshot, action, options) {
|
|
|
499
542
|
plan.mode = scopedSelection({ ...snapshot, scopeStore }, context).definition;
|
|
500
543
|
}
|
|
501
544
|
let customModes = snapshot.customModes.map(mode => ({ ...mode, levels: structuredClone(mode.levels) }));
|
|
502
|
-
let desiredMode = state?.schema_version === 2 ? snapshot.mode :
|
|
503
|
-
if (!local && (action === 'setup' && options.mode !== undefined || action === 'set')) desiredMode =
|
|
504
|
-
if (!local && action === 'clear') desiredMode =
|
|
545
|
+
let desiredMode = state?.schema_version === 2 ? snapshot.mode : resolve(snapshot.mode?.id ?? 'official', customModes);
|
|
546
|
+
if (!local && (action === 'setup' && options.mode !== undefined || action === 'set')) desiredMode = resolve(options.mode, customModes);
|
|
547
|
+
if (!local && action === 'clear') desiredMode = resolve('official');
|
|
505
548
|
if (!local && action === 'delete') {
|
|
506
|
-
const definition =
|
|
549
|
+
const definition = resolve(options.mode, customModes);
|
|
507
550
|
if (definition.kind !== 'custom') fail('BUILTIN_READ_ONLY', '内置档位不可删除。', 2);
|
|
508
551
|
assertUnreferenced(snapshot, definition.id);
|
|
509
552
|
customModes = customModes.filter(mode => mode.id !== definition.id);
|
|
@@ -516,13 +559,14 @@ async function buildPlan(snapshot, action, options) {
|
|
|
516
559
|
customModes.push(definition); plan.created_mode = definition;
|
|
517
560
|
}
|
|
518
561
|
if (!local && action === 'configure') {
|
|
519
|
-
const definition =
|
|
562
|
+
const definition = resolve(options.mode, customModes);
|
|
520
563
|
if (definition.kind !== 'custom') fail('BUILTIN_READ_ONLY', '内置档位不可修改;请先复制为自定义档位。', 2);
|
|
521
564
|
const levels = configuredLevels(definition, options);
|
|
522
565
|
customModes = customModes.map(mode => mode.id === definition.id ? { ...mode, levels } : mode);
|
|
523
|
-
if (desiredMode.id === definition.id) desiredMode =
|
|
566
|
+
if (desiredMode.id === definition.id) desiredMode = resolve(definition.id, customModes);
|
|
524
567
|
}
|
|
525
|
-
const deploying = !local && (action === 'setup' || action === 'set' || action === 'clear' || action === 'configure' && desiredMode.id ===
|
|
568
|
+
const deploying = !local && (action === 'setup' || action === 'set' || action === 'clear' || action === 'configure' && desiredMode.id === resolve(options.mode, customModes).id ||
|
|
569
|
+
action === 'model-bind' && desiredMode.kind === 'builtin' && plan.modelBinding.routes.some(route => route.mode === desiredMode.id));
|
|
526
570
|
if (deploying && snapshot.diagnostics.some(value => value.code === 'RULES_SHADOWED')) fail('RULES_SHADOWED', '非空 AGENTS.override.md 遮蔽本库规则;未写入部署配置。');
|
|
527
571
|
const payload = deploying ? await renderPayload(home, desiredMode) : snapshot.payload;
|
|
528
572
|
const files = new Map(payload.files);
|
|
@@ -531,6 +575,7 @@ async function buildPlan(snapshot, action, options) {
|
|
|
531
575
|
for (const relative of Object.keys(state.files)) files.set(relative, snapshot.observedFiles.get(relative).bytes);
|
|
532
576
|
}
|
|
533
577
|
if (customModes.length || snapshot.observedFiles.get(CUSTOM).bytes !== null) files.set(CUSTOM, state?.schema_version === 2 && snapshot.observedFiles.get(CUSTOM).bytes !== null ? snapshot.observedFiles.get(CUSTOM).bytes : json({ schema_version: 1, agent: 'codex', modes: customModes.map(({ id, name, levels }) => ({ id, name, levels })) }));
|
|
578
|
+
if (Object.keys(bindings).length) files.set(BINDINGS, json(bindings));
|
|
534
579
|
if (local || snapshot.observedFiles.get(SCOPE_FILE).bytes !== null) files.set(SCOPE_FILE, local ? json(scopeStore) : snapshot.observedFiles.get(SCOPE_FILE).bytes);
|
|
535
580
|
const previous = state?.files ?? {};
|
|
536
581
|
for (const relative of [...new Set([...files.keys(), ...Object.keys(previous)])].sort()) {
|
|
@@ -571,7 +616,7 @@ async function buildPlan(snapshot, action, options) {
|
|
|
571
616
|
plan.deploymentChanged = [...ordered.keys()].some(relative => ![BASELINE, STATE, CUSTOM, SCOPE_FILE].includes(relative));
|
|
572
617
|
// Compare against today's templates rendered with the old mode, so model/effort changes alone do not require a restart.
|
|
573
618
|
plan.restartRequired = !state || deploying && [...ordered].some(([relative, change]) => {
|
|
574
|
-
if ([BASELINE, STATE, CUSTOM, SCOPE_FILE, CURRENT].includes(relative)) return false;
|
|
619
|
+
if ([BASELINE, STATE, CUSTOM, BINDINGS, SCOPE_FILE, CURRENT].includes(relative)) return false;
|
|
575
620
|
const expected = snapshot.payload.files.get(relative);
|
|
576
621
|
return !expected || !change.before.bytes?.equals(expected);
|
|
577
622
|
});
|
|
@@ -725,11 +770,27 @@ export async function applyPlan(plan, options = {}) {
|
|
|
725
770
|
return report;
|
|
726
771
|
} finally { process.off('SIGINT', onSignal); process.off('SIGTERM', onSignal); }
|
|
727
772
|
}
|
|
773
|
+
|
|
774
|
+
async function checkModelBinding(plan) {
|
|
775
|
+
const { home, configuration_revision } = plan.snapshot;
|
|
776
|
+
const pairs = plan.modelBinding.routes.flatMap(route => route.after ? [route.after] : []);
|
|
777
|
+
if (!pairs.length) return;
|
|
778
|
+
const { checkAccountModels } = await import('./models.mjs');
|
|
779
|
+
const check = await checkAccountModels({ home, target: pairs[0], expectRevision: configuration_revision, requireCodexCatalog: true });
|
|
780
|
+
if (check.configuration_changed === true) fail('CONFIG_CHANGED', '目录检查期间配置已改变;请重新预览。');
|
|
781
|
+
if (check.exit_code === 1 || check.configuration_changed !== false || check.catalog.status !== 'complete' || check.catalog.source !== 'codex_app_server' || check.context.provider !== 'openai') {
|
|
782
|
+
fail('MODEL_BINDING_CATALOG_UNAVAILABLE', '无法核对官方 Codex 目录的模型与推理强度;未更新绑定。');
|
|
783
|
+
}
|
|
784
|
+
const missing = [...new Set(pairs.filter(pair => !check.catalog.models.some(item => !item.hidden && item.model === pair.model && item.supported_reasoning_efforts.includes(pair.effort))).map(pair => `${pair.model}/${pair.effort}`))];
|
|
785
|
+
if (missing.length) fail('MODEL_BINDING_UNSUPPORTED', `目录未列出可选组合:${missing.join('、')};未更新绑定。`);
|
|
786
|
+
}
|
|
787
|
+
|
|
728
788
|
export async function mutate(home, action, options = {}) {
|
|
729
789
|
let plan;
|
|
730
790
|
try {
|
|
731
791
|
const snapshot = await readSnapshot(home);
|
|
732
792
|
plan = await buildPlan(snapshot, action, options);
|
|
793
|
+
if (plan.modelBinding) await checkModelBinding(plan);
|
|
733
794
|
const shared = action === 'setup' ? await updateSkill(snapshot.home, { installOnly: true, dryRun: true }) : null;
|
|
734
795
|
const report = await applyPlan(plan, options);
|
|
735
796
|
if (shared) {
|
|
@@ -785,12 +846,15 @@ export async function statusReport(home, options = {}) {
|
|
|
785
846
|
export async function listReport(home, options = {}) {
|
|
786
847
|
const snapshot = await readSnapshot(home, options);
|
|
787
848
|
const context = await scopeContext(options), effective = scopedSelection(snapshot, context);
|
|
788
|
-
return { ...effective, definition: undefined, configuration_revision: snapshot.configuration_revision, home: snapshot.home, modes: [...
|
|
849
|
+
return { ...effective, definition: undefined, configuration_revision: snapshot.configuration_revision, home: snapshot.home, modes: [...snapshot.builtins, ...visibleModes(snapshot, context)].map(mode => ({ ...(mode.kind === 'builtin' && snapshot.mode?.id === mode.id ? snapshot.mode : mode), active: effective.active && effective.definition.id === mode.id, definition_scope: mode.definition_scope ?? 'builtin', source: mode.kind === 'builtin' && snapshot.mode?.id === mode.id ? 'installed_snapshot' : mode.kind === 'builtin' ? builtinSource(snapshot) : 'custom_definition', definition_version: mode.kind === 'builtin' && snapshot.mode?.id === mode.id ? snapshot.mode.definition_version ?? snapshot.state.version : mode.kind === 'builtin' ? VERSION : null })), diagnostics: snapshot.diagnostics };
|
|
850
|
+
}
|
|
851
|
+
function builtinSource(snapshot) {
|
|
852
|
+
return Object.keys(snapshot.bindings).length ? path.join(snapshot.home, BINDINGS) : 'package';
|
|
789
853
|
}
|
|
790
854
|
export async function showReport(home, selector, options = {}) {
|
|
791
855
|
const snapshot = await readSnapshot(home, options);
|
|
792
856
|
const selected = scopedSelection(snapshot, await scopeContext(options), selector);
|
|
793
857
|
const { definition } = selected;
|
|
794
858
|
const activeBuiltin = definition.kind === 'builtin' && snapshot.mode?.id === definition.id;
|
|
795
|
-
return { ...selected, configuration_revision: snapshot.configuration_revision, skill_revision: snapshot.skill.revision, skill_integrity: snapshot.skill.integrity, home: snapshot.home, source: activeBuiltin ? path.join(snapshot.home, snapshot.state?.schema_version === 2 ? `${SKILL}/references/current-mode.json` : CURRENT) : definition.kind === 'builtin' ?
|
|
859
|
+
return { ...selected, configuration_revision: snapshot.configuration_revision, skill_revision: snapshot.skill.revision, skill_integrity: snapshot.skill.integrity, home: snapshot.home, source: activeBuiltin ? path.join(snapshot.home, snapshot.state?.schema_version === 2 ? `${SKILL}/references/current-mode.json` : CURRENT) : definition.kind === 'builtin' ? builtinSource(snapshot) : path.join(snapshot.home, selected.definition_scope === 'global' ? CUSTOM : SCOPE_FILE), definition_version: activeBuiltin ? snapshot.mode.definition_version ?? snapshot.state.version : definition.kind === 'builtin' ? VERSION : null, diagnostics: snapshot.diagnostics, runtime_verification: 'unverified' };
|
|
796
860
|
}
|
package/lib/models.mjs
CHANGED
|
@@ -24,6 +24,7 @@ const MESSAGES = {
|
|
|
24
24
|
RPC_TOTAL_LIMIT: '客户端响应超过整轮 8MiB 限制。',
|
|
25
25
|
RPC_CURSOR_LOOP: '目录分页 cursor 重复;目录未完整读取。',
|
|
26
26
|
RPC_PAGE_LIMIT: '目录超过 100 页限制;目录未完整读取。',
|
|
27
|
+
CODEX_CATALOG_REQUIRED: '无法确认官方 Codex 目录上下文;未查询供应商目录。',
|
|
27
28
|
CONTEXT_UNVERIFIED: '本次仅检查所选 home 的 CLI 上下文;桌面会话、启动参数和 profile 未验证。',
|
|
28
29
|
MODEL_ACCESS_UNKNOWN: '模型目录和参数支持不证明账号实际调用权限。',
|
|
29
30
|
MODEL_NOT_LISTED: '目录未列出目标模型;调用权限仍未知。',
|
|
@@ -199,7 +200,7 @@ function finishCheck(result, verify) {
|
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
// The second argument only injects a child/snapshots/deadline in isolated tests; no CLI exposes it.
|
|
202
|
-
export async function checkAccountModels({ home, scope, project, thread, verify = false, discover = false, target, expectRevision, expectCatalog } = {}, internal = {}) {
|
|
203
|
+
export async function checkAccountModels({ home, scope, project, thread, verify = false, discover = false, target, expectRevision, expectCatalog, requireCodexCatalog = false } = {}, internal = {}) {
|
|
203
204
|
if (typeof home !== 'string' || !home || home.length > 4096 || /[\p{Cc}\p{Cf}]/u.test(home) || !path.isAbsolute(home)) throw argumentError('必须提供绝对路径 Codex home。', 'INVALID_HOME');
|
|
204
205
|
if (typeof verify !== 'boolean' || typeof discover !== 'boolean' || discover && (!verify || target)) throw argumentError('模型检查参数无效。');
|
|
205
206
|
if (expectRevision !== undefined && !text(expectRevision, 200)) throw argumentError('模型检查配置版本无效。');
|
|
@@ -276,7 +277,7 @@ export async function checkAccountModels({ home, scope, project, thread, verify
|
|
|
276
277
|
try {
|
|
277
278
|
const config = await rpc.request('config/read', { includeLayers: false, cwd: null });
|
|
278
279
|
if (!object(config) || !object(config.config) || config.config.model_provider != null && !text(config.config.model_provider, 200)) throw failure('RPC_INVALID');
|
|
279
|
-
result.context.provider = config.config.model_provider ??
|
|
280
|
+
result.context.provider = config.config.model_provider ?? 'openai';
|
|
280
281
|
providerConfig = config.config;
|
|
281
282
|
if (verify) {
|
|
282
283
|
authorization = await withinDeadline(bindProbeAuthorization(home, providerConfig, internal.env ?? process.env), deadline);
|
|
@@ -288,7 +289,9 @@ export async function checkAccountModels({ home, scope, project, thread, verify
|
|
|
288
289
|
result.exit_code = 1;
|
|
289
290
|
result.diagnostics.push(diagnostic('ACCOUNT_AUTHENTICATION_REQUIRED'));
|
|
290
291
|
}
|
|
291
|
-
|
|
292
|
+
const providerCatalog = providerConfig && usesProviderCatalog(providerConfig, internal.env ?? process.env);
|
|
293
|
+
if (requireCodexCatalog && (!providerConfig || providerCatalog)) throw failure('CODEX_CATALOG_REQUIRED');
|
|
294
|
+
if (providerCatalog) {
|
|
292
295
|
result.catalog = await providerModels({ home, config: providerConfig, deadline }, requestInternal);
|
|
293
296
|
if (result.catalog.status !== 'complete') {
|
|
294
297
|
result.diagnostics.push({ ...diagnostic(result.catalog.reason_code), source: 'provider_models' });
|
package/lib/scopes.mjs
CHANGED
|
@@ -90,7 +90,7 @@ export function scopedSelection(snapshot, context, selector) {
|
|
|
90
90
|
if (entry?.selection !== null && entry?.selection !== undefined) { selection = entry.selection; effectiveScope = scope; }
|
|
91
91
|
}
|
|
92
92
|
let definition;
|
|
93
|
-
try { definition = resolveDefinition(selector ?? selection ?? 'official', modes); }
|
|
93
|
+
try { definition = resolveDefinition(selector ?? selection ?? 'official', modes, snapshot.builtins); }
|
|
94
94
|
catch (error) {
|
|
95
95
|
if (selector !== undefined) throw error;
|
|
96
96
|
throw Object.assign(new Error('有效作用域的档位引用无效;请修复或清除该层选择。'), { code: 'SCOPE_REFERENCE_INVALID', exitCode: 1 });
|
package/package.json
CHANGED
package/web/app.js
CHANGED
|
@@ -298,7 +298,7 @@ function showTab(tab) {
|
|
|
298
298
|
function renderModePicker() {
|
|
299
299
|
const focusedMode = $('mode-radios').contains(document.activeElement) ? document.activeElement.id : null;
|
|
300
300
|
const isCustom = state.modes.find(mode => mode.id === state.selected)?.kind === 'custom';
|
|
301
|
-
const descriptions = { cut: '节省优先,按任务选同级候选', official: '四级基线与任务候选', high: '
|
|
301
|
+
const descriptions = { cut: '节省优先,按任务选同级候选', official: '四级基线与任务候选', high: '选档即授权所示高强度组合', fire: '选档即授权所示高强度组合,仍须先验证', custom: '自行设置模型、候选与备用' };
|
|
302
302
|
const radios = state.modes.filter(mode => mode.kind !== 'custom').map(mode => ({ value: mode.id, label: `${mode.name} · ${mode.id}` }));
|
|
303
303
|
radios.push({ value: 'custom', label: '自定义' });
|
|
304
304
|
replace('mode-radios', radios.map(option => node('label', {}, node('input', { id: `mode-${option.value}`, type: 'radio', name: 'mode', value: option.value, 'aria-label': option.label, 'aria-describedby': `mode-${option.value}-note`, checked: option.value === 'custom' ? isCustom : state.selected === option.value, disabled: state.busy || !state.connected, on: { change: () => { if (option.value !== 'custom') selectMode(option.value); else { const target = state.modes.find(mode => mode.kind === 'custom'); if (target) selectMode(target.id); else { renderModePicker(); createMode(); } } } } }), node('span', { class: 'mode-name' }, option.label), node('span', { id: `mode-${option.value}-note`, class: 'mode-description' }, descriptions[option.value] ?? '查看模型分配'))));
|
|
@@ -346,7 +346,7 @@ function renderLevels() {
|
|
|
346
346
|
const candidates = node('details', { class: 'technical task-candidates' }, node('summary', {}, '同级任务候选'), node('p', {}, '先选复杂度与保障下限,再按任务特征选择;未指定任务类型时使用上方基线。'));
|
|
347
347
|
if (custom()) {
|
|
348
348
|
const id = `${level}-tasks`;
|
|
349
|
-
candidates.append(node('label', { htmlFor: id }, '任务候选 JSON'), node('p', { class: 'muted' }, `本等级支持:${Object.entries(TASK_LEVELS).filter(([, levels]) => levels.includes(level)).map(([task]) => task).join('、')}。每项包含 model、effort、fallback;{}
|
|
349
|
+
candidates.append(node('label', { htmlFor: id }, '任务候选 JSON'), node('p', { class: 'muted' }, `本等级支持:${Object.entries(TASK_LEVELS).filter(([, levels]) => levels.includes(level)).map(([task]) => task).join('、')}。每项包含 model、effort、fallback;{} 清空候选。明确保存并选择的组合即为授权。`), node('textarea', { id, value: typeof tasks === 'string' ? tasks : JSON.stringify(tasks ?? {}, null, 2), rows: 8, maxLength: 65536, spellcheck: false, 'data-level': level, 'aria-describedby': `${level}-error`, on: { input: event => {
|
|
350
350
|
try { const parsed = JSON.parse(event.target.value); state.draft.levels[level].tasks = parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : event.target.value; } catch { state.draft.levels[level].tasks = event.target.value; }
|
|
351
351
|
state.preview = null; updateLevelSummary(level); renderChanges(); renderControls(); renderPreview();
|
|
352
352
|
$(`${level}-error`).hidden = true; event.target.removeAttribute('aria-invalid');
|
|
@@ -513,7 +513,7 @@ function renderRules() {
|
|
|
513
513
|
$('rules-view-note').textContent = preview ? `只读预览「${definition?.name ?? '未知'}」,尚未生效。查看不会切换档位。` : `正在展示「${active.name}」的已保存生效配置;未保存草稿不参与路由。`;
|
|
514
514
|
$('rules-view-note').dataset.preview = String(preview);
|
|
515
515
|
$('rules-maximum').hidden = !maximumMode(definition);
|
|
516
|
-
replace('rules-maximum', maximumMode(definition) ? [node('p', {}, preview ? '最高强度预览:查看不构成授权,明确选择此档位后才授权所示最高强度。' : '
|
|
516
|
+
replace('rules-maximum', maximumMode(definition) ? [node('p', {}, preview ? '最高强度预览:查看不构成授权,明确选择此档位后才授权所示最高强度。' : '已选择最高强度档位:明确选档即授权所示高强度组合。'), node('p', {}, '普通任务沿用本级最高组合;低延迟仍须显式配置候选。'), definition.id === 'fire' ? node('p', {}, 'fire 每个会话首次使用前实际验证;模型、强度、供应商或账号变化后重新验证。失败时使用用户指定模型与强度,否则继承父代理。') : null] : []);
|
|
517
517
|
replace('route-overview', definition ? LEVELS.map((level, index) => node('button', { type: 'button', class: 'route-overview-item', 'data-route': '', 'data-level': level, 'data-task': '', 'aria-controls': 'route-detail', 'aria-pressed': 'false', on: { click: () => explain(level) } }, node('span', { class: 'route-overview-heading' }, node('strong', {}, level), LEVEL_LABELS[index]), node('strong', { class: 'route-overview-model', title: pairText(definition.levels[level]) }, routePair(definition.levels[level])), node('span', { class: 'muted' }, '等级默认'))) : []);
|
|
518
518
|
replace('route-levels', definition ? LEVELS.map((level, index) => {
|
|
519
519
|
const tasks = ['', ...Object.keys(TASK_LEVELS).filter(task => TASK_LEVELS[task].includes(level))];
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"levels": {
|
|
3
|
-
"L1": {
|
|
4
|
-
"model": "gpt-6-luna",
|
|
5
|
-
"effort": "high",
|
|
6
|
-
"fallback": {
|
|
7
|
-
"model": "gpt-6.1-sol",
|
|
8
|
-
"effort": "medium"
|
|
9
|
-
},
|
|
10
|
-
"tasks": {
|
|
11
|
-
"mechanical": {
|
|
12
|
-
"model": "gpt-6-luna",
|
|
13
|
-
"effort": "medium",
|
|
14
|
-
"fallback": {
|
|
15
|
-
"model": "gpt-6.1-sol",
|
|
16
|
-
"effort": "medium"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"scan": {
|
|
20
|
-
"model": "gpt-6-luna",
|
|
21
|
-
"effort": "xhigh",
|
|
22
|
-
"fallback": {
|
|
23
|
-
"model": "gpt-6.1-sol",
|
|
24
|
-
"effort": "medium"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"deep": {
|
|
28
|
-
"model": "gpt-6-luna",
|
|
29
|
-
"effort": "max",
|
|
30
|
-
"fallback": {
|
|
31
|
-
"model": "gpt-6.1-sol",
|
|
32
|
-
"effort": "high"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"L2": {
|
|
38
|
-
"model": "gpt-6.1-sol",
|
|
39
|
-
"effort": "medium",
|
|
40
|
-
"fallback": {
|
|
41
|
-
"model": "gpt-6-sol",
|
|
42
|
-
"effort": "medium"
|
|
43
|
-
},
|
|
44
|
-
"tasks": {
|
|
45
|
-
"bounded": {
|
|
46
|
-
"model": "gpt-6.1-terra",
|
|
47
|
-
"effort": "medium",
|
|
48
|
-
"fallback": null
|
|
49
|
-
},
|
|
50
|
-
"complex": {
|
|
51
|
-
"model": "gpt-6.1-sol",
|
|
52
|
-
"effort": "medium",
|
|
53
|
-
"fallback": {
|
|
54
|
-
"model": "gpt-6-sol",
|
|
55
|
-
"effort": "medium"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"scan": {
|
|
59
|
-
"model": "gpt-6-luna",
|
|
60
|
-
"effort": "xhigh",
|
|
61
|
-
"fallback": {
|
|
62
|
-
"model": "gpt-6.1-sol",
|
|
63
|
-
"effort": "medium"
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
"deep": {
|
|
67
|
-
"model": "gpt-6-luna",
|
|
68
|
-
"effort": "max",
|
|
69
|
-
"fallback": {
|
|
70
|
-
"model": "gpt-6.1-sol",
|
|
71
|
-
"effort": "high"
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
"L3": {
|
|
77
|
-
"model": "gpt-6.1-sol",
|
|
78
|
-
"effort": "high",
|
|
79
|
-
"fallback": {
|
|
80
|
-
"model": "gpt-6-sol",
|
|
81
|
-
"effort": "high"
|
|
82
|
-
},
|
|
83
|
-
"tasks": {
|
|
84
|
-
"complex": {
|
|
85
|
-
"model": "gpt-6.1-terra",
|
|
86
|
-
"effort": "medium",
|
|
87
|
-
"fallback": null
|
|
88
|
-
},
|
|
89
|
-
"uncertain": {
|
|
90
|
-
"model": "gpt-6-astra",
|
|
91
|
-
"effort": "low",
|
|
92
|
-
"fallback": {
|
|
93
|
-
"model": "gpt-6.1-sol",
|
|
94
|
-
"effort": "high"
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
"reasoning": {
|
|
98
|
-
"model": "gpt-6-astra",
|
|
99
|
-
"effort": "medium",
|
|
100
|
-
"fallback": {
|
|
101
|
-
"model": "gpt-6.1-sol",
|
|
102
|
-
"effort": "xhigh"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
"L4": {
|
|
108
|
-
"model": "gpt-6.1-sol",
|
|
109
|
-
"effort": "xhigh",
|
|
110
|
-
"fallback": {
|
|
111
|
-
"model": "gpt-6-sol",
|
|
112
|
-
"effort": "xhigh"
|
|
113
|
-
},
|
|
114
|
-
"tasks": {
|
|
115
|
-
"uncertain": {
|
|
116
|
-
"model": "gpt-6-astra",
|
|
117
|
-
"effort": "low",
|
|
118
|
-
"fallback": {
|
|
119
|
-
"model": "gpt-6.1-sol",
|
|
120
|
-
"effort": "high"
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
"reasoning": {
|
|
124
|
-
"model": "gpt-6-astra",
|
|
125
|
-
"effort": "medium",
|
|
126
|
-
"fallback": {
|
|
127
|
-
"model": "gpt-6.1-sol",
|
|
128
|
-
"effort": "xhigh"
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|