@mrciphersmith/keryx 0.4.47 → 0.4.48
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/dist/cli.js +382 -60
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -16997,7 +16997,7 @@ function sameModelRef(left, right) {
|
|
|
16997
16997
|
function modelRefKey(ref) {
|
|
16998
16998
|
return `${ref.providerId}\x00${ref.modelId}`;
|
|
16999
16999
|
}
|
|
17000
|
-
var MODEL_CLASSES, MODEL_CLASS_RANK;
|
|
17000
|
+
var MODEL_CLASSES, MODEL_CLASS_RANK, ROUTING_MAX_TIER_MODELS = 32, ROUTING_TIER_IDS, ROUTING_TIERS;
|
|
17001
17001
|
var init_model_class = __esm(() => {
|
|
17002
17002
|
MODEL_CLASSES = ["light", "standard", "expert", "frontier"];
|
|
17003
17003
|
MODEL_CLASS_RANK = {
|
|
@@ -17006,6 +17006,12 @@ var init_model_class = __esm(() => {
|
|
|
17006
17006
|
expert: 2,
|
|
17007
17007
|
frontier: 3
|
|
17008
17008
|
};
|
|
17009
|
+
ROUTING_TIER_IDS = ["strong", "middle", "light"];
|
|
17010
|
+
ROUTING_TIERS = {
|
|
17011
|
+
strong: "expert",
|
|
17012
|
+
middle: "standard",
|
|
17013
|
+
light: "light"
|
|
17014
|
+
};
|
|
17009
17015
|
});
|
|
17010
17016
|
|
|
17011
17017
|
// src/gdskills/model-denylist.ts
|
|
@@ -17104,7 +17110,7 @@ function providerOptions(provider, session) {
|
|
|
17104
17110
|
}
|
|
17105
17111
|
return options;
|
|
17106
17112
|
}
|
|
17107
|
-
var ROUTING_CATEGORIES, ROUTING_CATEGORY_SET, WIRED_ROUTING_CATEGORIES, SESSION_DEFAULT_ASSIGNMENT, SESSION_SUFFIX = " (current session)";
|
|
17113
|
+
var ROUTING_CATEGORIES, ROUTING_CATEGORY_TIERS, ROUTING_CATEGORY_SET, WIRED_ROUTING_CATEGORIES, SESSION_DEFAULT_ASSIGNMENT, SESSION_SUFFIX = " (current session)";
|
|
17108
17114
|
var init_table = __esm(() => {
|
|
17109
17115
|
init_model_denylist();
|
|
17110
17116
|
ROUTING_CATEGORIES = [
|
|
@@ -17117,6 +17123,16 @@ var init_table = __esm(() => {
|
|
|
17117
17123
|
"docs",
|
|
17118
17124
|
"unattended"
|
|
17119
17125
|
];
|
|
17126
|
+
ROUTING_CATEGORY_TIERS = {
|
|
17127
|
+
default: "middle",
|
|
17128
|
+
review: "strong",
|
|
17129
|
+
subagents: "middle",
|
|
17130
|
+
quick: "light",
|
|
17131
|
+
coding: "middle",
|
|
17132
|
+
planning: "strong",
|
|
17133
|
+
docs: "middle",
|
|
17134
|
+
unattended: "middle"
|
|
17135
|
+
};
|
|
17120
17136
|
ROUTING_CATEGORY_SET = new Set(ROUTING_CATEGORIES);
|
|
17121
17137
|
WIRED_ROUTING_CATEGORIES = new Set(["review", "subagents"]);
|
|
17122
17138
|
SESSION_DEFAULT_ASSIGNMENT = { kind: "session-default" };
|
|
@@ -17198,7 +17214,9 @@ function validateRoutingConfigLayer(raw, options = {}) {
|
|
|
17198
17214
|
const errors = [];
|
|
17199
17215
|
if (!isRecord(raw))
|
|
17200
17216
|
return { ok: false, errors: ["routing config must be an object"] };
|
|
17201
|
-
unknownKeys(raw, ["schemaVersion", "classes", "categories", "providers", "classifier", "execution"], "config", errors);
|
|
17217
|
+
unknownKeys(raw, ["schemaVersion", "classes", "tierRouting", "categories", "providers", "classifier", "execution"], "config", errors);
|
|
17218
|
+
if (raw.tierRouting !== undefined && typeof raw.tierRouting !== "boolean")
|
|
17219
|
+
errors.push("tierRouting must be a boolean");
|
|
17202
17220
|
if (raw.schemaVersion !== 2)
|
|
17203
17221
|
errors.push("schemaVersion must be 2");
|
|
17204
17222
|
errors.push(...secretPaths(raw).map((path) => `${path} must not contain credentials`));
|
|
@@ -17476,6 +17494,7 @@ function normalizeRoutingConfig(layers, options = {}) {
|
|
|
17476
17494
|
return [modelClass, copyClassConfig(config)];
|
|
17477
17495
|
}));
|
|
17478
17496
|
assertAcyclicFallbacks(classes);
|
|
17497
|
+
const tierRouting = layers.project?.tierRouting ?? layers.user?.tierRouting ?? false;
|
|
17479
17498
|
const categories = {};
|
|
17480
17499
|
const categorySources = {};
|
|
17481
17500
|
for (const category of ROUTING_CATEGORIES) {
|
|
@@ -17486,7 +17505,7 @@ function normalizeRoutingConfig(layers, options = {}) {
|
|
|
17486
17505
|
categories[category] = copyAssignment(layers.user.categories[category]);
|
|
17487
17506
|
categorySources[category] = "user";
|
|
17488
17507
|
} else {
|
|
17489
|
-
categories[category] = copyAssignment(BASELINE_ASSIGNMENT);
|
|
17508
|
+
categories[category] = copyAssignment(tierRouting && category !== "review" && category !== "default" ? { mode: "auto" } : BASELINE_ASSIGNMENT);
|
|
17490
17509
|
categorySources[category] = "builtin";
|
|
17491
17510
|
}
|
|
17492
17511
|
}
|
|
@@ -17505,6 +17524,7 @@ function normalizeRoutingConfig(layers, options = {}) {
|
|
|
17505
17524
|
const normalized = Object.freeze({
|
|
17506
17525
|
schemaVersion: 2,
|
|
17507
17526
|
classes: Object.freeze(classes),
|
|
17527
|
+
...tierRouting ? { tierRouting } : {},
|
|
17508
17528
|
categories: Object.freeze(categories),
|
|
17509
17529
|
categorySources: Object.freeze(categorySources),
|
|
17510
17530
|
providers,
|
|
@@ -18853,6 +18873,7 @@ function assertCuratedCoverage(providerId, ids) {
|
|
|
18853
18873
|
function curatedProfile(providerId, modelId, entry, now) {
|
|
18854
18874
|
const priceInputPerMillion = { value: entry.priceInputPerMillion, source: "curated" };
|
|
18855
18875
|
return {
|
|
18876
|
+
availabilityUnverified: true,
|
|
18856
18877
|
providerId,
|
|
18857
18878
|
modelId,
|
|
18858
18879
|
strengthTier: { value: entry.tier, source: "curated" },
|
|
@@ -18987,6 +19008,7 @@ function sanitizeStoredProfile(value) {
|
|
|
18987
19008
|
contextLength,
|
|
18988
19009
|
priority: { value: priority.value, source: priority.source },
|
|
18989
19010
|
available: record.available,
|
|
19011
|
+
...record.availabilityUnverified === true && { availabilityUnverified: true },
|
|
18990
19012
|
chatCapable,
|
|
18991
19013
|
lastSeenAt: record.lastSeenAt,
|
|
18992
19014
|
refreshedAt: record.refreshedAt
|
|
@@ -19108,8 +19130,9 @@ function updateProfile(existing, parsed, nowIso) {
|
|
|
19108
19130
|
const priceOutputPerMillion = existing.priceOutputPerMillion.source === "operator" ? existing.priceOutputPerMillion : buildField(parsed?.priceOutputPerMillion, undefined);
|
|
19109
19131
|
const contextLength = existing.contextLength.source === "operator" ? existing.contextLength : buildField(parsed?.contextLength, undefined);
|
|
19110
19132
|
const priority = existing.priority.source === "operator" ? existing.priority : { value: computeAutoPriority(priceInputPerMillion), source: "auto" };
|
|
19133
|
+
const { availabilityUnverified: _unverified, ...observed } = existing;
|
|
19111
19134
|
return {
|
|
19112
|
-
...
|
|
19135
|
+
...observed,
|
|
19113
19136
|
strengthTier: tier,
|
|
19114
19137
|
priceInputPerMillion,
|
|
19115
19138
|
priceOutputPerMillion,
|
|
@@ -19155,7 +19178,8 @@ async function refreshModelProfiles(providerId, liveModelIds, parsedFields, deps
|
|
|
19155
19178
|
continue;
|
|
19156
19179
|
if (profile.available === false)
|
|
19157
19180
|
continue;
|
|
19158
|
-
|
|
19181
|
+
const { availabilityUnverified: _unverified, ...observed } = profile;
|
|
19182
|
+
next[key] = { ...observed, available: false, refreshedAt: nowIso };
|
|
19159
19183
|
unavailable += 1;
|
|
19160
19184
|
}
|
|
19161
19185
|
writeModelProfilesFileUnlocked(next, deps.dir);
|
|
@@ -19187,6 +19211,7 @@ async function setModelProfileField(providerId, modelId, update, dir, now = Date
|
|
|
19187
19211
|
}
|
|
19188
19212
|
};
|
|
19189
19213
|
const fallbackBase = {
|
|
19214
|
+
availabilityUnverified: true,
|
|
19190
19215
|
providerId,
|
|
19191
19216
|
modelId,
|
|
19192
19217
|
strengthTier: guessStrengthTier(modelId),
|
|
@@ -21133,6 +21158,21 @@ import path45 from "path";
|
|
|
21133
21158
|
function catalogFile(dir) {
|
|
21134
21159
|
return path45.join(keryxConfigDir(dir), CATALOG_CACHE_FILE);
|
|
21135
21160
|
}
|
|
21161
|
+
async function withCatalogRefreshLock(dir, refresh) {
|
|
21162
|
+
ensureKeryxConfigDir(dir);
|
|
21163
|
+
let acquired = false;
|
|
21164
|
+
try {
|
|
21165
|
+
return await withFileLock(`${catalogFile(dir)}.refresh.lock`, () => {
|
|
21166
|
+
acquired = true;
|
|
21167
|
+
return refresh();
|
|
21168
|
+
}, { timeoutMs: 25000, retryMs: 50, staleMs: 15000 });
|
|
21169
|
+
} catch (error) {
|
|
21170
|
+
if (!acquired && error instanceof Error && "code" in error && ["EACCES", "EPERM", "EROFS"].some((code) => code === error.code)) {
|
|
21171
|
+
return refresh();
|
|
21172
|
+
}
|
|
21173
|
+
throw error;
|
|
21174
|
+
}
|
|
21175
|
+
}
|
|
21136
21176
|
function sanitizeBalance(value) {
|
|
21137
21177
|
if (typeof value !== "object" || value === null)
|
|
21138
21178
|
return;
|
|
@@ -22105,16 +22145,28 @@ async function buildCatalogEntry(detected, deps, fetchedAt) {
|
|
|
22105
22145
|
if (detected.name === "openai-codex") {
|
|
22106
22146
|
if (loadOAuthGrant("openai-codex", deps.dir) === undefined)
|
|
22107
22147
|
return;
|
|
22108
|
-
const result = await
|
|
22148
|
+
const result = await fetchOpenAiCodexCatalog(deps.fetch, { ...deps.dir !== undefined ? { configDir: deps.dir } : {}, timeoutMs: deps.timeoutMs ?? CATALOG_FETCH_TIMEOUT_MS });
|
|
22149
|
+
if (result.source === "live") {
|
|
22150
|
+
await refreshModelProfiles(detected.name, result.models, Object.fromEntries(Object.entries(result.contextWindows).map(([model, contextLength]) => [model, { contextLength }])), deps);
|
|
22151
|
+
}
|
|
22109
22152
|
return { name: detected.name, status: classifyModelsStatus(result), models: result.models, fallbackModels: [...detected.models], fetchedAt, label: detected.label ?? "ChatGPT / Codex" };
|
|
22110
22153
|
}
|
|
22111
22154
|
const registry = providerByName(detected.name, deps.dir);
|
|
22155
|
+
if (registry === undefined && detected.name === "anthropic") {
|
|
22156
|
+
const key = envWithSavedApiKeys(deps.env, deps.dir)[detected.envKey ?? "ANTHROPIC_API_KEY"];
|
|
22157
|
+
if (!key)
|
|
22158
|
+
return;
|
|
22159
|
+
const result = await fetchAnthropicModels(deps.fetch, key, { timeoutMs: deps.timeoutMs ?? CATALOG_FETCH_TIMEOUT_MS });
|
|
22160
|
+
return {
|
|
22161
|
+
name: detected.name,
|
|
22162
|
+
status: classifyModelsStatus(result),
|
|
22163
|
+
models: result.models,
|
|
22164
|
+
fallbackModels: [...detected.models],
|
|
22165
|
+
fetchedAt,
|
|
22166
|
+
...detected.label !== undefined ? { label: detected.label } : {}
|
|
22167
|
+
};
|
|
22168
|
+
}
|
|
22112
22169
|
if (registry === undefined) {
|
|
22113
|
-
if (detected.name === "anthropic") {
|
|
22114
|
-
const key = envWithSavedApiKeys(deps.env, deps.dir)[detected.envKey ?? "ANTHROPIC_API_KEY"];
|
|
22115
|
-
if (key === undefined || key.length === 0)
|
|
22116
|
-
return;
|
|
22117
|
-
}
|
|
22118
22170
|
return {
|
|
22119
22171
|
name: detected.name,
|
|
22120
22172
|
status: "not-supported",
|
|
@@ -22160,7 +22212,7 @@ async function buildCatalogEntry(detected, deps, fetchedAt) {
|
|
|
22160
22212
|
}
|
|
22161
22213
|
async function refreshProviderCatalog(deps) {
|
|
22162
22214
|
const detectDeps = {
|
|
22163
|
-
fetch: deps.fetch,
|
|
22215
|
+
fetch: (input, init) => deps.fetch(input, { ...init, signal: AbortSignal.timeout(deps.timeoutMs ?? CATALOG_FETCH_TIMEOUT_MS) }),
|
|
22164
22216
|
env: deps.env,
|
|
22165
22217
|
...deps.dir !== undefined ? { configDir: deps.dir } : {},
|
|
22166
22218
|
...deps.baseUrl !== undefined ? { baseUrl: deps.baseUrl } : {},
|
|
@@ -22185,18 +22237,27 @@ async function detectedOrRedetected(detected, deps) {
|
|
|
22185
22237
|
return detected.length === 0 && deps.redetect !== undefined ? deps.redetect() : detected;
|
|
22186
22238
|
}
|
|
22187
22239
|
async function loadOrRefreshWith(deps, opts, refresh) {
|
|
22188
|
-
|
|
22240
|
+
const now = deps.now ?? Date.now;
|
|
22241
|
+
const readFresh = () => {
|
|
22242
|
+
if (opts.force)
|
|
22243
|
+
return;
|
|
22189
22244
|
const cached = loadProviderCatalogCache(deps.dir);
|
|
22190
|
-
if (isServableCatalog(cached,
|
|
22245
|
+
if (cached && isServableCatalog(cached, now, opts.ttlMs) && (!opts.checkEntryDates || Object.values(cached.providers).every((entry) => isCatalogFresh({ fetchedAt: entry.fetchedAt, providers: {} }, now, opts.ttlMs)))) {
|
|
22191
22246
|
return cached;
|
|
22192
22247
|
}
|
|
22193
|
-
|
|
22194
|
-
|
|
22195
|
-
|
|
22196
|
-
|
|
22197
|
-
|
|
22198
|
-
|
|
22199
|
-
|
|
22248
|
+
return;
|
|
22249
|
+
};
|
|
22250
|
+
return readFresh() ?? withCatalogRefreshLock(deps.dir, async () => {
|
|
22251
|
+
const cached = readFresh();
|
|
22252
|
+
if (cached)
|
|
22253
|
+
return cached;
|
|
22254
|
+
const fresh = await refresh();
|
|
22255
|
+
if (hasProviders(fresh))
|
|
22256
|
+
await saveProviderCatalogCache(fresh, deps.dir);
|
|
22257
|
+
else
|
|
22258
|
+
await clearProviderCatalogCache(deps.dir);
|
|
22259
|
+
return fresh;
|
|
22260
|
+
});
|
|
22200
22261
|
}
|
|
22201
22262
|
async function loadOrRefreshProviderCatalog(deps, opts = {}) {
|
|
22202
22263
|
return loadOrRefreshWith(deps, opts, () => refreshProviderCatalog(deps));
|
|
@@ -22227,7 +22288,13 @@ function catalogToFlatPickerProviders(catalog, opts = {}) {
|
|
|
22227
22288
|
continue;
|
|
22228
22289
|
}
|
|
22229
22290
|
if (entry.fallbackModels.length > 0) {
|
|
22230
|
-
out.push({
|
|
22291
|
+
out.push({
|
|
22292
|
+
name: entry.name,
|
|
22293
|
+
models: entry.fallbackModels,
|
|
22294
|
+
offline: true,
|
|
22295
|
+
observedAt: entry.fetchedAt,
|
|
22296
|
+
...entry.status === "not-supported" && { profileOnly: true }
|
|
22297
|
+
});
|
|
22231
22298
|
} else if (opts.withStatusRows === true) {
|
|
22232
22299
|
out.push({ name: entry.name, models: [], listUnavailable: describeCatalogStatus(entry.status), observedAt: entry.fetchedAt });
|
|
22233
22300
|
}
|
|
@@ -22256,6 +22323,7 @@ var init_provider_catalog = __esm(() => {
|
|
|
22256
22323
|
init_select();
|
|
22257
22324
|
init_providers();
|
|
22258
22325
|
init_provider_catalog_cache();
|
|
22326
|
+
init_model_profile();
|
|
22259
22327
|
init_provider_catalog_cache();
|
|
22260
22328
|
});
|
|
22261
22329
|
|
|
@@ -27702,7 +27770,7 @@ function approveProjectRouting(cwd, layer, configDir) {
|
|
|
27702
27770
|
}
|
|
27703
27771
|
function describeLayerForApproval(layer) {
|
|
27704
27772
|
const lines = Object.entries(layer.categories ?? {}).sort(([a], [b]) => a.localeCompare(b)).map(([category, assignment]) => `${category}: ${describeRoutingAssignment(assignment)}`);
|
|
27705
|
-
for (const key of ["classes", "providers", "classifier", "execution"]) {
|
|
27773
|
+
for (const key of ["classes", "tierRouting", "providers", "classifier", "execution"]) {
|
|
27706
27774
|
if (layer[key] !== undefined)
|
|
27707
27775
|
lines.push(`${key}: ${JSON.stringify(layer[key])}`);
|
|
27708
27776
|
}
|
|
@@ -28055,7 +28123,7 @@ async function updateRoutingLayer(input) {
|
|
|
28055
28123
|
if (before !== undefined && routingDigest(before) === routingDigest(input.next) && current[input.scope].source === "canonical") {
|
|
28056
28124
|
return { status: "unchanged", revision: current.revision };
|
|
28057
28125
|
}
|
|
28058
|
-
await writeScope(input.scope, location, "all", (base) => {
|
|
28126
|
+
await writeScope(input.scope, location, input.preserveLegacyScope ? new Set : "all", (base) => {
|
|
28059
28127
|
if (routingDigest(base) !== routingDigest(before ?? { schemaVersion: ROUTING_SCHEMA_VERSION })) {
|
|
28060
28128
|
throw new Error("routing settings revision conflict; read the settings again before writing");
|
|
28061
28129
|
}
|
|
@@ -38206,7 +38274,7 @@ var package_default;
|
|
|
38206
38274
|
var init_package = __esm(() => {
|
|
38207
38275
|
package_default = {
|
|
38208
38276
|
name: "@mrciphersmith/keryx",
|
|
38209
|
-
version: "0.4.
|
|
38277
|
+
version: "0.4.48",
|
|
38210
38278
|
description: "Version-controlled project context for AI coding agents: code graph, architecture wiki, project memory, relevant tests, quality signals, and task flows.",
|
|
38211
38279
|
private: false,
|
|
38212
38280
|
publishConfig: {
|
|
@@ -80877,8 +80945,11 @@ function object4(value, fields, label) {
|
|
|
80877
80945
|
invalid(label);
|
|
80878
80946
|
return value;
|
|
80879
80947
|
}
|
|
80948
|
+
function isDeskReviewModelName(value) {
|
|
80949
|
+
return typeof value === "string" && /^[a-z\d][a-z\d_./:@+%-]{0,159}$/i.test(value);
|
|
80950
|
+
}
|
|
80880
80951
|
function modelName(value, label) {
|
|
80881
|
-
if (
|
|
80952
|
+
if (!isDeskReviewModelName(value))
|
|
80882
80953
|
invalid(label);
|
|
80883
80954
|
return value;
|
|
80884
80955
|
}
|
|
@@ -82433,18 +82504,18 @@ class DeskRunStore {
|
|
|
82433
82504
|
return this.db.query(`SELECT id FROM runs WHERE repo=? AND pr=? AND viewer=?
|
|
82434
82505
|
AND json_extract(details,'$.source') IN ('manual','scheduled') ORDER BY rowid DESC LIMIT 1`).get(key.repositoryId, key.number, key.viewer)?.id ?? null;
|
|
82435
82506
|
}
|
|
82436
|
-
requestManual(cwd, key, revision, observedAdmission, options) {
|
|
82507
|
+
requestManual(cwd, key, revision, observedAdmission, options, effectiveOptionsKey) {
|
|
82437
82508
|
const latest = this.latestAdmission(key);
|
|
82438
82509
|
if (latest !== observedAdmission) {
|
|
82439
|
-
const existing = [this.active(key), this.queued(key)].find((attempt) => attempt && attempt.key.viewer.toLowerCase() === key.viewer.toLowerCase() && attempt.run.baseSha === revision.baseSha && attempt.run.headSha === revision.headSha &&
|
|
82510
|
+
const existing = [this.active(key), this.queued(key)].find((attempt) => attempt && attempt.key.viewer.toLowerCase() === key.viewer.toLowerCase() && attempt.run.baseSha === revision.baseSha && attempt.run.headSha === revision.headSha && this.matchesManualOptions(attempt.run, options, effectiveOptionsKey));
|
|
82440
82511
|
if (existing)
|
|
82441
82512
|
return existing.run.id;
|
|
82442
|
-
const previous = this.previousAttempt(key, revision, options);
|
|
82513
|
+
const previous = this.previousAttempt(key, revision, options, false, effectiveOptionsKey);
|
|
82443
82514
|
if (previous?.id === latest && previous.state === "completed" && previous.complete)
|
|
82444
82515
|
return previous.id;
|
|
82445
82516
|
throw new Error("stale: Another review was requested during validation. Refresh the board and try again.");
|
|
82446
82517
|
}
|
|
82447
|
-
return this.requestAttempt(cwd, key, revision, undefined, options)?.id ?? null;
|
|
82518
|
+
return this.requestAttempt(cwd, key, revision, undefined, options, undefined, effectiveOptionsKey)?.id ?? null;
|
|
82448
82519
|
}
|
|
82449
82520
|
continuationSource(key, id) {
|
|
82450
82521
|
const attempt = this.byId(id);
|
|
@@ -82635,19 +82706,23 @@ Preview truncated. Full result: ` + path192.join(this.directory(run.id), "execut
|
|
|
82635
82706
|
ORDER BY pr DESC
|
|
82636
82707
|
`).all(repositoryId, viewer).map(({ pr }) => pr);
|
|
82637
82708
|
}
|
|
82638
|
-
|
|
82709
|
+
matchesManualOptions(run, options, effectiveOptionsKey) {
|
|
82710
|
+
return effectiveOptionsKey === undefined ? deskOptionsKey(run.options) === deskOptionsKey(options) : (run.effectiveOptionsKey ?? deskOptionsKey(run.options)) === effectiveOptionsKey;
|
|
82711
|
+
}
|
|
82712
|
+
previousAttempt(key, revision, options, anyOptions = false, effectiveOptionsKey) {
|
|
82713
|
+
const storedKey = effectiveOptionsKey === undefined ? "coalesce(json_extract(details,'$.options'),'')" : "coalesce(json_extract(details,'$.effectiveOptionsKey'),json_extract(details,'$.options'),'')";
|
|
82639
82714
|
return this.db.query(`SELECT id,state,json_extract(details,'$.retryableBeforeSpend') AS retryable,
|
|
82640
82715
|
json_extract(details,'$.preflightAttempt') AS attempt,
|
|
82641
82716
|
(json_extract(details,'$.scope')=? AND json_extract(details,'$.result.coverage')='complete'
|
|
82642
82717
|
AND json_extract(details,'$.result.reviewed.baseSha')=json_extract(details,'$.baseSha')
|
|
82643
82718
|
AND json_extract(details,'$.result.reviewed.headSha')=json_extract(details,'$.headSha')) AS complete
|
|
82644
82719
|
FROM runs WHERE repo=? AND pr=? AND viewer=? AND json_extract(details,'$.baseSha')=?
|
|
82645
|
-
AND json_extract(details,'$.headSha')=? AND (
|
|
82720
|
+
AND json_extract(details,'$.headSha')=? AND (${storedKey}=? OR ?=1) AND json_extract(details,'$.source') IN ('manual','scheduled')
|
|
82646
82721
|
AND (?=1 OR coalesce(json_extract(details,'$.decision.action'),'') NOT IN ('archive','delete'))
|
|
82647
82722
|
AND NOT (state='skipped' AND coalesce(json_extract(details,'$.phase'),'')='Superseded'
|
|
82648
82723
|
AND json_extract(details,'$.startedAt') IS NULL AND json_extract(details,'$.result') IS NULL
|
|
82649
82724
|
AND json_extract(details,'$.usage') IS NULL)
|
|
82650
|
-
ORDER BY rowid DESC LIMIT 1`).get(DESK_RUN_SCOPE, key.repositoryId, key.number, key.viewer, revision.baseSha, revision.headSha, deskOptionsKey(options), anyOptions ? 1 : 0, anyOptions ? 1 : 0);
|
|
82725
|
+
ORDER BY rowid DESC LIMIT 1`).get(DESK_RUN_SCOPE, key.repositoryId, key.number, key.viewer, revision.baseSha, revision.headSha, effectiveOptionsKey ?? deskOptionsKey(options), anyOptions ? 1 : 0, anyOptions ? 1 : 0);
|
|
82651
82726
|
}
|
|
82652
82727
|
scheduledCapacityReached() {
|
|
82653
82728
|
const runs = this.db.query(`SELECT id, pid, json_extract(details,'$.workerIdentity') AS workerIdentity FROM runs
|
|
@@ -82666,8 +82741,8 @@ Preview truncated. Full result: ` + path192.join(this.directory(run.id), "execut
|
|
|
82666
82741
|
request(cwd, key, revision, schedule) {
|
|
82667
82742
|
return this.requestAttempt(cwd, key, revision, schedule)?.id ?? null;
|
|
82668
82743
|
}
|
|
82669
|
-
requestAttempt(cwd, key, revision, schedule, options, continuation) {
|
|
82670
|
-
const match = (a) => a.key.viewer.toLowerCase() === key.viewer.toLowerCase() && a.run.baseSha === revision.baseSha && a.run.headSha === revision.headSha && (schedule !== undefined ||
|
|
82744
|
+
requestAttempt(cwd, key, revision, schedule, options, continuation, effectiveOptionsKey) {
|
|
82745
|
+
const match = (a) => a.key.viewer.toLowerCase() === key.viewer.toLowerCase() && a.run.baseSha === revision.baseSha && a.run.headSha === revision.headSha && (schedule !== undefined || this.matchesManualOptions(a.run, options, effectiveOptionsKey));
|
|
82671
82746
|
this.releaseDeadForeignSlot(key);
|
|
82672
82747
|
const active = this.active(key);
|
|
82673
82748
|
const queued = this.queued(key);
|
|
@@ -82677,7 +82752,7 @@ Preview truncated. Full result: ` + path192.join(this.directory(run.id), "execut
|
|
|
82677
82752
|
return { id: queued.run.id, reused: true };
|
|
82678
82753
|
if (schedule && (active || queued))
|
|
82679
82754
|
return null;
|
|
82680
|
-
const previous = this.previousAttempt(key, revision, options, schedule !== undefined);
|
|
82755
|
+
const previous = this.previousAttempt(key, revision, options, schedule !== undefined, effectiveOptionsKey);
|
|
82681
82756
|
if (previous && !continuation && (schedule && !previous.retryable || previous.state === "completed" && previous.complete)) {
|
|
82682
82757
|
return { id: previous.id, reused: true };
|
|
82683
82758
|
}
|
|
@@ -82697,6 +82772,7 @@ Preview truncated. Full result: ` + path192.join(this.directory(run.id), "execut
|
|
|
82697
82772
|
source: schedule ? "scheduled" : "manual",
|
|
82698
82773
|
...schedule ? { schedule, preflightAttempt: (previous?.attempt ?? 0) + 1 } : {},
|
|
82699
82774
|
...options ? { options: parseDeskReviewOptions(options) } : {},
|
|
82775
|
+
...effectiveOptionsKey === undefined ? {} : { effectiveOptionsKey },
|
|
82700
82776
|
...continuation && { continuation },
|
|
82701
82777
|
scope: DESK_RUN_SCOPE,
|
|
82702
82778
|
...revision,
|
|
@@ -125724,6 +125800,18 @@ function assignmentFor(request, config) {
|
|
|
125724
125800
|
...classifierReceiptId !== undefined ? { classifierReceiptId } : {}
|
|
125725
125801
|
};
|
|
125726
125802
|
}
|
|
125803
|
+
if (config.tierRouting && source === "builtin" && (request.recommendation !== undefined || config.classifier.chain.length === 0)) {
|
|
125804
|
+
const suggested = request.recommendation?.modelClass;
|
|
125805
|
+
const modelClass = suggested === "frontier" && !config.classes.frontier.candidates.some((candidate) => candidate.enabled) && config.classes.frontier.fallbackClasses.length === 0 ? "expert" : suggested ?? ROUTING_TIERS[ROUTING_CATEGORY_TIERS[request.category]];
|
|
125806
|
+
const { candidates, fallbackClasses } = config.classes[modelClass];
|
|
125807
|
+
const hasCandidates = candidates.some((candidate) => candidate.enabled) || fallbackClasses.length > 0;
|
|
125808
|
+
return {
|
|
125809
|
+
assignment: hasCandidates ? { mode: "class", modelClass } : { mode: "baseline" },
|
|
125810
|
+
source,
|
|
125811
|
+
recommendationSource: request.recommendation?.source ?? "none",
|
|
125812
|
+
...request.recommendation?.receiptId !== undefined ? { classifierReceiptId: request.recommendation.receiptId } : {}
|
|
125813
|
+
};
|
|
125814
|
+
}
|
|
125727
125815
|
if (request.recommendation !== undefined) {
|
|
125728
125816
|
return {
|
|
125729
125817
|
assignment: { mode: "class", modelClass: request.recommendation.modelClass },
|
|
@@ -126883,11 +126971,14 @@ function estimatedCost(profile, request) {
|
|
|
126883
126971
|
return estimateModelCostUsd(profile, request.requirements.inputTokensRequired, request.requirements.outputTokensReserved);
|
|
126884
126972
|
}
|
|
126885
126973
|
function observedAvailability(provider, profile, nowMs, ttlMs) {
|
|
126886
|
-
if (provider.offline === true || !Number.isFinite(nowMs))
|
|
126974
|
+
if (provider.offline === true && !provider.profileOnly || !Number.isFinite(nowMs))
|
|
126887
126975
|
return "unknown";
|
|
126888
126976
|
const profileAvailability = freshModelProfileAvailability(profile, new Date(nowMs).toISOString(), ttlMs);
|
|
126889
126977
|
const catalogObservedAt = provider.observedAt === undefined ? NaN : Date.parse(provider.observedAt);
|
|
126890
126978
|
const freshCatalog = Number.isFinite(catalogObservedAt) && catalogObservedAt <= nowMs && nowMs - catalogObservedAt <= ttlMs;
|
|
126979
|
+
if (provider.profileOnly) {
|
|
126980
|
+
return freshCatalog && !profile?.availabilityUnverified ? profileAvailability : "unknown";
|
|
126981
|
+
}
|
|
126891
126982
|
if (!freshCatalog)
|
|
126892
126983
|
return profileAvailability;
|
|
126893
126984
|
if (profileAvailability === "unavailable" && profile !== undefined && Date.parse(profile.refreshedAt) >= catalogObservedAt)
|
|
@@ -126987,7 +127078,7 @@ async function currentUnattendedSnapshot(projectRoot, configDir, config, request
|
|
|
126987
127078
|
const observedAt = new Date().toISOString();
|
|
126988
127079
|
const listed = catalogToFlatPickerProviders(catalog, { withStatusRows: true }).filter((entry) => entry.name === baseline.providerId).map((entry) => ({ ...entry, models: entry.models?.filter((modelId) => modelId === baseline.modelId) ?? [] }));
|
|
126989
127080
|
const providers = listed.some((entry) => entry.models?.includes(baseline.modelId) === true) ? listed : [...listed.filter((entry) => entry.name !== baseline.providerId), { name: baseline.providerId, models: [baseline.modelId] }];
|
|
126990
|
-
const profiles = loadModelProfiles(configDir);
|
|
127081
|
+
const profiles = loadModelProfiles(configDir, () => Date.parse(observedAt));
|
|
126991
127082
|
const baselineProvider = providerFor(baseline);
|
|
126992
127083
|
if (baselineProvider === undefined)
|
|
126993
127084
|
throw new Error("the explicit unattended provider/model pin could not be built");
|
|
@@ -151865,7 +151956,7 @@ async function scheduleDeskReview(cwd, key, revision, schedule, authorize) {
|
|
|
151865
151956
|
store.close();
|
|
151866
151957
|
}
|
|
151867
151958
|
}
|
|
151868
|
-
async function requestDeskRun(cwd, key, input) {
|
|
151959
|
+
async function requestDeskRun(cwd, key, input, resolveManualOptions) {
|
|
151869
151960
|
const store = new DeskRunStore;
|
|
151870
151961
|
try {
|
|
151871
151962
|
const observedAdmission = input.action === "start" ? store.latestAdmission(key) : null;
|
|
@@ -151884,9 +151975,11 @@ async function requestDeskRun(cwd, key, input) {
|
|
|
151884
151975
|
return { ...store.history(key), ...completion ? { completion } : {} };
|
|
151885
151976
|
}
|
|
151886
151977
|
let startedRunId = null;
|
|
151978
|
+
const options = input.action === "start" && input.options ? parseDeskReviewOptions(input.options) : undefined;
|
|
151979
|
+
const effectiveKey = input.action === "start" && resolveManualOptions ? deskOptionsKey(resolveManualOptions(cwd, options)) : undefined;
|
|
151887
151980
|
store.atomic(() => {
|
|
151888
151981
|
if (input.action === "start")
|
|
151889
|
-
startedRunId = store.requestManual(cwd, key, input.revision, observedAdmission,
|
|
151982
|
+
startedRunId = store.requestManual(cwd, key, input.revision, observedAdmission, options, effectiveKey);
|
|
151890
151983
|
if (input.action === "continue")
|
|
151891
151984
|
startedRunId = store.requestContinuation(cwd, key, input.id, input.guidance);
|
|
151892
151985
|
if (input.action === "answer")
|
|
@@ -151918,7 +152011,7 @@ async function requestDeskRun(cwd, key, input) {
|
|
|
151918
152011
|
store.close();
|
|
151919
152012
|
}
|
|
151920
152013
|
}
|
|
151921
|
-
async function runDeskWorker(id, selectModel) {
|
|
152014
|
+
async function runDeskWorker(id, selectModel, resolveOptions = (_cwd, options) => options) {
|
|
151922
152015
|
const store = new DeskRunStore;
|
|
151923
152016
|
let timer;
|
|
151924
152017
|
const controller = new AbortController;
|
|
@@ -151968,12 +152061,27 @@ async function runDeskWorker(id, selectModel) {
|
|
|
151968
152061
|
abort();
|
|
151969
152062
|
}
|
|
151970
152063
|
}, 500);
|
|
151971
|
-
const
|
|
152064
|
+
const options = resolveOptions(cwd, run.options);
|
|
152065
|
+
const effectiveOptionsKey = deskOptionsKey(options);
|
|
152066
|
+
if (run.effectiveOptionsKey !== undefined && run.effectiveOptionsKey !== effectiveOptionsKey) {
|
|
152067
|
+
throw new Error("configuration: Routing settings changed while Review was waiting. Start the review again to use the new settings.");
|
|
152068
|
+
}
|
|
152069
|
+
store.atomic(() => {
|
|
152070
|
+
const active = store.byId(id);
|
|
152071
|
+
if (!active || active.pid !== process.pid || active.run.state !== "running") {
|
|
152072
|
+
abort();
|
|
152073
|
+
throw new Error("Review cancelled before routing options were recorded.");
|
|
152074
|
+
}
|
|
152075
|
+
active.run.effectiveOptionsKey = effectiveOptionsKey;
|
|
152076
|
+
store.save(active);
|
|
152077
|
+
});
|
|
152078
|
+
const previous = store.history(key).runs.find((item) => item.source !== "existing" && item.scope === DESK_RUN_SCOPE && (item.effectiveOptionsKey ?? deskOptionsKey(item.options)) === effectiveOptionsKey && item.state === "completed" && item.result?.coverage === "complete");
|
|
151972
152079
|
const context = await collectPrContext(cwd, key, pr, store, undefined, run.options?.flowId);
|
|
151973
152080
|
const workerRoster = createWorkerRoster(runDir, key, run);
|
|
151974
152081
|
const out = await executeDeskReview({
|
|
151975
152082
|
context,
|
|
151976
|
-
...
|
|
152083
|
+
...options ? { options } : {},
|
|
152084
|
+
...run.options ? { budgetTokens: run.options.maxTokens ?? null } : {},
|
|
151977
152085
|
cwd,
|
|
151978
152086
|
repo: key.repo,
|
|
151979
152087
|
number: key.number,
|
|
@@ -160214,6 +160322,12 @@ var init_review_pr_context = __esm(() => {
|
|
|
160214
160322
|
});
|
|
160215
160323
|
|
|
160216
160324
|
// src/commands/review-desk-provider.ts
|
|
160325
|
+
var exports_review_desk_provider = {};
|
|
160326
|
+
__export(exports_review_desk_provider, {
|
|
160327
|
+
makeDeskReviewProvider: () => makeDeskReviewProvider,
|
|
160328
|
+
resolveDeskReviewModel: () => resolveDeskReviewModel,
|
|
160329
|
+
resolveDeskReviewOptions: () => resolveDeskReviewOptions
|
|
160330
|
+
});
|
|
160217
160331
|
function makeDeskReviewProvider(provider, model, configDir, sourceEnv = process.env) {
|
|
160218
160332
|
const saved = loadShellConfig(configDir);
|
|
160219
160333
|
const baseUrl = saved.baseUrls?.[provider] ?? (saved.provider === provider ? saved.baseUrl : undefined);
|
|
@@ -160265,8 +160379,23 @@ async function resolveDeskReviewModel(cwd, configDir, env = process.env) {
|
|
|
160265
160379
|
makeDeskReviewProvider(provider, model, configDir, env);
|
|
160266
160380
|
return { provider, model };
|
|
160267
160381
|
}
|
|
160382
|
+
function resolveDeskReviewOptions(cwd, options) {
|
|
160383
|
+
if (options?.orchestrator === false)
|
|
160384
|
+
return options;
|
|
160385
|
+
const routing = loadRouting(cwd);
|
|
160386
|
+
if (!routing.tierRouting || routing.categorySources.review !== "builtin")
|
|
160387
|
+
return options;
|
|
160388
|
+
const modelPools = { strong: [], middle: [], light: [] };
|
|
160389
|
+
for (const tier of DESK_REVIEW_POOLS) {
|
|
160390
|
+
const configured = routing.classes[ROUTING_TIERS[tier]].candidates;
|
|
160391
|
+
modelPools[tier] = options?.modelPools[tier].length ? options.modelPools[tier] : configured.filter(({ enabled, target }) => enabled && isDeskReviewModelName(target.providerId) && isDeskReviewModelName(target.modelId)).sort((a, b) => b.priority - a.priority).slice(0, DESK_MAX_POOL_MODELS).map(({ target }) => ({ provider: target.providerId, model: target.modelId }));
|
|
160392
|
+
}
|
|
160393
|
+
return parseDeskReviewOptions({ mode: "manual", adaptive: true, ...options, modelPools });
|
|
160394
|
+
}
|
|
160268
160395
|
var init_review_desk_provider = __esm(() => {
|
|
160269
160396
|
init_providers();
|
|
160397
|
+
init_model_class();
|
|
160398
|
+
init_desk_run_options();
|
|
160270
160399
|
init_settings();
|
|
160271
160400
|
init_fake_provider();
|
|
160272
160401
|
init_make_provider();
|
|
@@ -160314,7 +160443,7 @@ async function runReviewDesk(args) {
|
|
|
160314
160443
|
});
|
|
160315
160444
|
if (action === "worker" && Object.keys(v).length === 1 && v.id && uuid3.test(v.id)) {
|
|
160316
160445
|
await Promise.resolve().then(() => init_review_desk_provider());
|
|
160317
|
-
await runDeskWorker(v.id, resolveDeskReviewModel);
|
|
160446
|
+
await runDeskWorker(v.id, resolveDeskReviewModel, resolveDeskReviewOptions);
|
|
160318
160447
|
return;
|
|
160319
160448
|
}
|
|
160320
160449
|
const number = Number(v.number);
|
|
@@ -160360,7 +160489,8 @@ async function runReviewDesk(args) {
|
|
|
160360
160489
|
input = { action, ...v.id ? { id: v.id } : {}, ...activityId ? { activityId } : {} };
|
|
160361
160490
|
} else
|
|
160362
160491
|
throw new Error(DESK_USAGE);
|
|
160363
|
-
const
|
|
160492
|
+
const resolveManualOptions = input.action === "start" ? (await Promise.resolve().then(() => (init_review_desk_provider(), exports_review_desk_provider))).resolveDeskReviewOptions : undefined;
|
|
160493
|
+
const snapshot = await requestDeskRun(process.cwd(), { repo: v.repo, repositoryId, viewer: v.viewer, number }, input, resolveManualOptions);
|
|
160364
160494
|
await new Promise((resolve, reject) => process.stdout.write(JSON.stringify(snapshot) + `
|
|
160365
160495
|
`, (error) => error ? reject(error) : resolve()));
|
|
160366
160496
|
}
|
|
@@ -195515,12 +195645,7 @@ function createSpawnSubagentTool(deps) {
|
|
|
195515
195645
|
});
|
|
195516
195646
|
try {
|
|
195517
195647
|
const parent = deps.getParentModel();
|
|
195518
|
-
const detected = deps.getDetectedProviders();
|
|
195519
195648
|
const session = { providerId: parent.providerId, modelId: parent.modelId };
|
|
195520
|
-
const catalog = detected.map((p) => ({
|
|
195521
|
-
...p,
|
|
195522
|
-
models: p.models ?? []
|
|
195523
|
-
}));
|
|
195524
195649
|
let routingConfig;
|
|
195525
195650
|
try {
|
|
195526
195651
|
routingConfig = loadRouting(deps.routingProjectRoot ?? deps.cwd, deps.routingConfigDir);
|
|
@@ -195581,6 +195706,11 @@ function createSpawnSubagentTool(deps) {
|
|
|
195581
195706
|
isError: true
|
|
195582
195707
|
};
|
|
195583
195708
|
}
|
|
195709
|
+
const maySwitchModel = deskOverride !== undefined || assignment.mode !== "baseline" || assignment.fallbackClass !== undefined;
|
|
195710
|
+
if (!isExternalRuntimeRequest && maySwitchModel)
|
|
195711
|
+
await deps.refreshRoutingProviders?.();
|
|
195712
|
+
const detected = deps.getDetectedProviders();
|
|
195713
|
+
const catalog = detected.map((p) => ({ ...p, models: p.models ?? [] }));
|
|
195584
195714
|
let categoryModelRequest;
|
|
195585
195715
|
let routingReceipt;
|
|
195586
195716
|
let routingExecutionBudget;
|
|
@@ -195616,7 +195746,7 @@ function createSpawnSubagentTool(deps) {
|
|
|
195616
195746
|
parentAllowed: parentAllowed(target),
|
|
195617
195747
|
cooldown: false
|
|
195618
195748
|
}));
|
|
195619
|
-
const profiles = loadModelProfiles(deps.routingConfigDir);
|
|
195749
|
+
const profiles = loadModelProfiles(deps.routingConfigDir, () => Date.parse(observedAt));
|
|
195620
195750
|
let routingBudget = routingBudgets.get(routingConfig.configDigest);
|
|
195621
195751
|
if (routingBudget === undefined) {
|
|
195622
195752
|
routingBudget = new RoutingBudgetLedger({
|
|
@@ -195749,7 +195879,7 @@ function createSpawnSubagentTool(deps) {
|
|
|
195749
195879
|
receipt: routingReceipt,
|
|
195750
195880
|
selectionTimeoutMs: routingConfig.execution.selectionTimeoutMs,
|
|
195751
195881
|
beforeIo: async (target, _decisionId, context) => {
|
|
195752
|
-
const currentDetected = deps.getDetectedProviders();
|
|
195882
|
+
const currentDetected = deps.getDetectedProviders({ forActiveRoute: true });
|
|
195753
195883
|
const currentCredentialedProviders = new Set(currentDetected.map((entry) => entry.name));
|
|
195754
195884
|
const currentProvider = currentDetected.find((entry) => entry.name === target.providerId);
|
|
195755
195885
|
const currentEnv = envWithSavedApiKeys(process.env, deps.routingConfigDir);
|
|
@@ -195771,7 +195901,7 @@ function createSpawnSubagentTool(deps) {
|
|
|
195771
195901
|
const authenticatedSession = modelRefKey(target) === modelRefKey(session);
|
|
195772
195902
|
const dispatchProfile = profiles[profileKey(target.providerId, target.modelId)];
|
|
195773
195903
|
if (!authenticatedSession) {
|
|
195774
|
-
const explicitlyUnavailable = currentProvider?.offline === true || currentProvider?.listUnavailable !== undefined || currentProvider?.models !== undefined && !currentProvider.models.includes(target.modelId);
|
|
195904
|
+
const explicitlyUnavailable = deps.refreshRoutingProviders !== undefined && currentProvider === undefined || currentProvider?.offline === true && !currentProvider.profileOnly || currentProvider?.listUnavailable !== undefined || currentProvider?.models !== undefined && !currentProvider.models.includes(target.modelId);
|
|
195775
195905
|
if (explicitlyUnavailable || selectedAvailability !== "available") {
|
|
195776
195906
|
return { ok: false, reason: "model-unavailable" };
|
|
195777
195907
|
}
|
|
@@ -196470,6 +196600,7 @@ function buildSessionSpawnDeps(input) {
|
|
|
196470
196600
|
makeProvider: (providerId, modelId, childBaseUrl) => input.providerFactory(providerId, modelId, baseUrlFor(providerId, childBaseUrl)),
|
|
196471
196601
|
describeProvider: (providerId, modelId, childBaseUrl) => input.providerFactory(providerId, modelId, baseUrlFor(providerId, childBaseUrl)).describe(),
|
|
196472
196602
|
getDetectedProviders: input.getDetectedProviders,
|
|
196603
|
+
...input.refreshRoutingProviders ? { refreshRoutingProviders: input.refreshRoutingProviders } : {},
|
|
196473
196604
|
getRankHints: (providerId) => loadRankHints(providerId),
|
|
196474
196605
|
tierRank: createTierRankHost(),
|
|
196475
196606
|
...input.getSlateSession !== undefined ? { getSlateSession: input.getSlateSession } : {},
|
|
@@ -361380,9 +361511,9 @@ function findShellCommand(name) {
|
|
|
361380
361511
|
function shellAvailableCommands() {
|
|
361381
361512
|
return ACP_SHELL_COMMAND_TABLE.map((row) => ({
|
|
361382
361513
|
name: row.name,
|
|
361383
|
-
description: row.description,
|
|
361514
|
+
description: row.name === "routing" ? "Configure models for the Strong, Middle and Light tiers" : row.description,
|
|
361384
361515
|
...row.hint !== undefined ? { input: { hint: row.hint } } : {},
|
|
361385
|
-
_meta: { keryx: { group: row.group, surface: row.surface, busy: row.busy } }
|
|
361516
|
+
_meta: { keryx: { group: row.group, surface: row.surface, busy: row.busy, ...row.name === "routing" && { routingTiers: true } } }
|
|
361386
361517
|
}));
|
|
361387
361518
|
}
|
|
361388
361519
|
function busyRefusalText(name) {
|
|
@@ -361509,7 +361640,7 @@ var init_shell_commands = __esm(() => {
|
|
|
361509
361640
|
opencomments: "owner/repo pr",
|
|
361510
361641
|
mcp: "trust list | trust revoke <server__tool> | all",
|
|
361511
361642
|
bus: "send | ask | reply | name",
|
|
361512
|
-
routing: "set <category> <provider/model | baseline> | trust",
|
|
361643
|
+
routing: "status | set <category> <provider/model | baseline> | trust",
|
|
361513
361644
|
ci: "triage <run id> [job name]",
|
|
361514
361645
|
conform: "run <target id> <document>",
|
|
361515
361646
|
task: "<mode> <description> [|| criteria]",
|
|
@@ -361599,6 +361730,115 @@ var init_shell_goal = __esm(() => {
|
|
|
361599
361730
|
init_slate_lifecycle();
|
|
361600
361731
|
});
|
|
361601
361732
|
|
|
361733
|
+
// src/acp/routing-tier-settings.ts
|
|
361734
|
+
function legacyModels(layer, tier) {
|
|
361735
|
+
if (!layer || layer.tierRouting)
|
|
361736
|
+
return [];
|
|
361737
|
+
const models = new Map;
|
|
361738
|
+
for (const category of ROUTING_CATEGORIES) {
|
|
361739
|
+
if (ROUTING_CATEGORY_TIERS[category] !== tier)
|
|
361740
|
+
continue;
|
|
361741
|
+
const assignment = layer.categories?.[category];
|
|
361742
|
+
if (assignment?.mode === "model")
|
|
361743
|
+
models.set(modelRefKey(assignment.target), assignment.target);
|
|
361744
|
+
}
|
|
361745
|
+
return [...models.values()];
|
|
361746
|
+
}
|
|
361747
|
+
function models(config) {
|
|
361748
|
+
return config.candidates.filter((candidate) => candidate.enabled).sort((a, b) => b.priority - a.priority).map((candidate) => candidate.target);
|
|
361749
|
+
}
|
|
361750
|
+
function describeTierSettings(settings) {
|
|
361751
|
+
const saveBlocked = settings.user.source === "opt-in";
|
|
361752
|
+
return {
|
|
361753
|
+
revision: settings.revision,
|
|
361754
|
+
saveBlocked,
|
|
361755
|
+
enabled: settings.user.layer?.tierRouting ?? false,
|
|
361756
|
+
projectEnabled: settings.layers.project?.tierRouting ?? null,
|
|
361757
|
+
notices: saveBlocked ? [...settings.notices, PROJECT_SCOPED_USER_NOTICE] : settings.notices,
|
|
361758
|
+
personalOverrides: Object.keys(settings.user.layer?.categories ?? {}).length > 0,
|
|
361759
|
+
projectOverrides: settings.layers.project !== undefined,
|
|
361760
|
+
projectTrustRequired: !settings.project.trusted,
|
|
361761
|
+
tiers: ROUTING_TIER_IDS.map((tier) => {
|
|
361762
|
+
const modelClass = ROUTING_TIERS[tier];
|
|
361763
|
+
const userClass = settings.user.layer?.classes?.[modelClass];
|
|
361764
|
+
const projectClass = settings.layers.project?.classes?.[modelClass];
|
|
361765
|
+
return {
|
|
361766
|
+
tier,
|
|
361767
|
+
user: userClass ? models(userClass) : legacyModels(settings.user.layer, tier),
|
|
361768
|
+
project: projectClass ? models(projectClass) : null
|
|
361769
|
+
};
|
|
361770
|
+
})
|
|
361771
|
+
};
|
|
361772
|
+
}
|
|
361773
|
+
async function saveTierSettings(location, revision, raw) {
|
|
361774
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
361775
|
+
throw new Error("Invalid routing tiers request.");
|
|
361776
|
+
const enabled = Reflect.get(raw, "enabled");
|
|
361777
|
+
const replaceOverrides = Reflect.get(raw, "replaceOverrides");
|
|
361778
|
+
if (typeof enabled !== "boolean" || typeof replaceOverrides !== "boolean" || replaceOverrides && !enabled) {
|
|
361779
|
+
throw new Error("Invalid routing tiers request.");
|
|
361780
|
+
}
|
|
361781
|
+
const modelPools = Reflect.get(raw, "modelPools");
|
|
361782
|
+
if (!modelPools || typeof modelPools !== "object" || Object.keys(modelPools).some((tier) => !ROUTING_TIER_IDS.some((value) => value === tier))) {
|
|
361783
|
+
throw new Error("Invalid routing model pools.");
|
|
361784
|
+
}
|
|
361785
|
+
const current = readRoutingSettings(location);
|
|
361786
|
+
if (current.user.source === "opt-in")
|
|
361787
|
+
throw new Error(PROJECT_SCOPED_USER_NOTICE);
|
|
361788
|
+
const user = current.user.layer;
|
|
361789
|
+
const classes = { ...user?.classes };
|
|
361790
|
+
for (const tier of ROUTING_TIER_IDS) {
|
|
361791
|
+
const modelClass = ROUTING_TIERS[tier];
|
|
361792
|
+
if (current.layers.project?.classes?.[modelClass])
|
|
361793
|
+
continue;
|
|
361794
|
+
const existing = classes[modelClass];
|
|
361795
|
+
const enabledModels = existing ? models(existing) : [];
|
|
361796
|
+
const entries = Reflect.get(modelPools, tier);
|
|
361797
|
+
if (!Array.isArray(entries) || entries.length > Math.max(ROUTING_MAX_TIER_MODELS, enabledModels.length))
|
|
361798
|
+
throw new Error(`Invalid ${tier} routing pool.`);
|
|
361799
|
+
const selected = entries.map((entry) => {
|
|
361800
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
361801
|
+
throw new Error(`Invalid model in ${tier} routing pool.`);
|
|
361802
|
+
const providerId = Reflect.get(entry, "provider");
|
|
361803
|
+
const targetModelId = Reflect.get(entry, "model");
|
|
361804
|
+
if (typeof providerId !== "string" || !providerId || typeof targetModelId !== "string" || !targetModelId) {
|
|
361805
|
+
throw new Error(`Invalid model in ${tier} routing pool.`);
|
|
361806
|
+
}
|
|
361807
|
+
return { providerId, modelId: targetModelId };
|
|
361808
|
+
});
|
|
361809
|
+
if (existing && JSON.stringify(enabledModels) === JSON.stringify(selected))
|
|
361810
|
+
continue;
|
|
361811
|
+
const known = new Set((existing?.candidates.map((candidate) => candidate.target) ?? legacyModels(user, tier)).map(modelRefKey));
|
|
361812
|
+
if (selected.some((target) => !known.has(modelRefKey(target)) && (!modelId.test(target.providerId) || !modelId.test(target.modelId)))) {
|
|
361813
|
+
throw new Error(`Invalid model in ${tier} routing pool.`);
|
|
361814
|
+
}
|
|
361815
|
+
const enabled = new Set(selected.map(modelRefKey));
|
|
361816
|
+
classes[modelClass] = {
|
|
361817
|
+
selection: existing?.selection ?? "priority",
|
|
361818
|
+
fallbackClasses: existing?.fallbackClasses ?? [],
|
|
361819
|
+
candidates: [
|
|
361820
|
+
...selected.map((target, i) => ({ target, enabled: true, priority: selected.length - i })),
|
|
361821
|
+
...existing?.candidates.filter((candidate) => !candidate.enabled && !enabled.has(modelRefKey(candidate.target))) ?? []
|
|
361822
|
+
]
|
|
361823
|
+
};
|
|
361824
|
+
}
|
|
361825
|
+
return updateRoutingLayer({
|
|
361826
|
+
...location,
|
|
361827
|
+
scope: "user",
|
|
361828
|
+
expectedRevision: revision,
|
|
361829
|
+
preserveLegacyScope: true,
|
|
361830
|
+
next: { ...user, schemaVersion: 2, tierRouting: enabled, classes, ...replaceOverrides ? { categories: {} } : {} }
|
|
361831
|
+
});
|
|
361832
|
+
}
|
|
361833
|
+
var modelId;
|
|
361834
|
+
var init_routing_tier_settings = __esm(() => {
|
|
361835
|
+
init_model_class();
|
|
361836
|
+
init_settings();
|
|
361837
|
+
init_legacy_migration();
|
|
361838
|
+
init_table();
|
|
361839
|
+
modelId = /^[a-z\d][a-z\d_./:@+%-]{0,159}$/i;
|
|
361840
|
+
});
|
|
361841
|
+
|
|
361602
361842
|
// src/acp/shell-views.ts
|
|
361603
361843
|
function viewText(view) {
|
|
361604
361844
|
const lines = [view.title];
|
|
@@ -361692,8 +361932,23 @@ ${preview.lines.join(`
|
|
|
361692
361932
|
async function runRouting(host, args) {
|
|
361693
361933
|
const [sub, ...rest] = args.trim().split(/\s+/);
|
|
361694
361934
|
const location = { cwd: host.cwd, ...host.configDir !== undefined ? { configDir: host.configDir } : {} };
|
|
361695
|
-
if (
|
|
361935
|
+
if (!sub || sub === "status" && rest.length === 0)
|
|
361696
361936
|
return viewOutcome(await routingView(host));
|
|
361937
|
+
if (sub === "tiers") {
|
|
361938
|
+
try {
|
|
361939
|
+
const input = args.trim().slice(sub.length).trim();
|
|
361940
|
+
if (!input)
|
|
361941
|
+
return { text: JSON.stringify(describeTierSettings(readRoutingSettings(location))) };
|
|
361942
|
+
const revision = input.slice(0, 64);
|
|
361943
|
+
const json = input.slice(64).trim();
|
|
361944
|
+
if (!/^[a-f0-9]{64}$/.test(revision) || input[64] !== " " || json.length > 50000)
|
|
361945
|
+
throw new Error("Invalid routing settings request.");
|
|
361946
|
+
await saveTierSettings(location, revision, JSON.parse(json));
|
|
361947
|
+
return { text: "Routing tiers saved.", effects: ["config"] };
|
|
361948
|
+
} catch (error) {
|
|
361949
|
+
return { text: errorText6(error), refused: true };
|
|
361950
|
+
}
|
|
361951
|
+
}
|
|
361697
361952
|
if (sub === "set")
|
|
361698
361953
|
return actionOutcome(await routingSet(location, rest.join(" ")));
|
|
361699
361954
|
if (sub === "trust")
|
|
@@ -361827,6 +362082,7 @@ function busView() {
|
|
|
361827
362082
|
}
|
|
361828
362083
|
var errorText6 = (error) => error instanceof Error ? error.message : String(error);
|
|
361829
362084
|
var init_shell_views_config = __esm(() => {
|
|
362085
|
+
init_routing_tier_settings();
|
|
361830
362086
|
init_config2();
|
|
361831
362087
|
init_settings();
|
|
361832
362088
|
init_table();
|
|
@@ -363612,6 +363868,10 @@ async function runAcpServer(options) {
|
|
|
363612
363868
|
const source = options.models;
|
|
363613
363869
|
if (source === undefined || stopping)
|
|
363614
363870
|
return;
|
|
363871
|
+
if (options.routingProviders) {
|
|
363872
|
+
routingRefreshNeeded = true;
|
|
363873
|
+
routingProviders = [];
|
|
363874
|
+
}
|
|
363615
363875
|
listingGeneration += 1;
|
|
363616
363876
|
listedChoices = undefined;
|
|
363617
363877
|
listing = undefined;
|
|
@@ -363921,6 +364181,42 @@ async function runAcpServer(options) {
|
|
|
363921
364181
|
clientMcpTools: sessionMcp.get(sessionId)?.mcp.tools ?? []
|
|
363922
364182
|
});
|
|
363923
364183
|
}
|
|
364184
|
+
let routingProviders;
|
|
364185
|
+
let routingRefresh;
|
|
364186
|
+
let routingRefreshNeeded = false;
|
|
364187
|
+
let routingForceRetry = false;
|
|
364188
|
+
let routingRefreshFailedAt;
|
|
364189
|
+
function freshRoutingProvider(provider, now) {
|
|
364190
|
+
const age = now - Date.parse(provider.observedAt ?? "");
|
|
364191
|
+
return age >= 0 && age < ROUTING_AVAILABILITY_TTL_MS;
|
|
364192
|
+
}
|
|
364193
|
+
function refreshRoutingProviders() {
|
|
364194
|
+
const load = options.routingProviders;
|
|
364195
|
+
if (!load)
|
|
364196
|
+
return Promise.resolve();
|
|
364197
|
+
if (routingRefresh)
|
|
364198
|
+
return routingRefresh;
|
|
364199
|
+
const now = Date.now();
|
|
364200
|
+
const retryAge = routingRefreshFailedAt === undefined ? Infinity : now - routingRefreshFailedAt;
|
|
364201
|
+
if (!routingRefreshNeeded && (retryAge >= 0 && retryAge < 1e4 || routingProviders && routingProviders.length > 0 && routingProviders.every((provider) => freshRoutingProvider(provider, now))))
|
|
364202
|
+
return Promise.resolve();
|
|
364203
|
+
const force = routingRefreshNeeded || routingForceRetry;
|
|
364204
|
+
routingRefreshNeeded = false;
|
|
364205
|
+
return routingRefresh = Promise.resolve().then(() => load(force)).then((providers) => {
|
|
364206
|
+
routingRefreshFailedAt = providers.length === 0 ? Date.now() : undefined;
|
|
364207
|
+
routingForceRetry = false;
|
|
364208
|
+
if (!routingRefreshNeeded)
|
|
364209
|
+
routingProviders = providers;
|
|
364210
|
+
}, () => {
|
|
364211
|
+
routingRefreshFailedAt = Date.now();
|
|
364212
|
+
routingForceRetry = force;
|
|
364213
|
+
options.logError("acp: could not refresh the provider catalogue for model routing");
|
|
364214
|
+
}).finally(() => {
|
|
364215
|
+
routingRefresh = undefined;
|
|
364216
|
+
if (routingRefreshNeeded)
|
|
364217
|
+
return refreshRoutingProviders();
|
|
364218
|
+
});
|
|
364219
|
+
}
|
|
363924
364220
|
const mcpGrants = new Map;
|
|
363925
364221
|
const subagentBudgetResets = new Map;
|
|
363926
364222
|
function spawnInputFor(sessionId, ownsBudget) {
|
|
@@ -363940,11 +364236,19 @@ async function runAcpServer(options) {
|
|
|
363940
364236
|
return binding.provider;
|
|
363941
364237
|
throw new Error(`keryx acp has no provider factory for ${providerId}/${modelId}; a subagent runs on its parent's model here`);
|
|
363942
364238
|
},
|
|
363943
|
-
|
|
364239
|
+
...options.routingProviders ? { refreshRoutingProviders } : {},
|
|
364240
|
+
getDetectedProviders: (lookup) => {
|
|
364241
|
+
const now = Date.now();
|
|
364242
|
+
const verified = (lookup?.forActiveRoute ? routingProviders : routingProviders?.filter((provider) => freshRoutingProvider(provider, now))) ?? [];
|
|
364243
|
+
if (verified.length > 0) {
|
|
364244
|
+
const providerId = parent().providerId;
|
|
364245
|
+
return verified.some((entry) => entry.name === providerId) ? verified : [{ name: providerId, models: [] }, ...verified];
|
|
364246
|
+
}
|
|
363944
364247
|
const byProvider = new Map;
|
|
363945
364248
|
for (const choice of listedChoices ?? [])
|
|
363946
364249
|
byProvider.set(choice.providerId, [...byProvider.get(choice.providerId) ?? [], choice.modelId]);
|
|
363947
|
-
|
|
364250
|
+
const fallback = withSessionProvider(parent().providerId, [...byProvider].map(([name, models]) => ({ name, models })));
|
|
364251
|
+
return options.routingProviders ? fallback.map((row) => ({ ...row, offline: true })) : fallback;
|
|
363948
364252
|
},
|
|
363949
364253
|
onFleetEvent: (event) => {
|
|
363950
364254
|
if (!stopping)
|
|
@@ -364992,6 +365296,7 @@ var init_server3 = __esm(() => {
|
|
|
364992
365296
|
init_ask_user();
|
|
364993
365297
|
init_profile2();
|
|
364994
365298
|
init_shell_roster();
|
|
365299
|
+
init_snapshot_adapter();
|
|
364995
365300
|
init_spawn_deps();
|
|
364996
365301
|
init_providers2();
|
|
364997
365302
|
init_shell_tasks();
|
|
@@ -365334,6 +365639,21 @@ async function acpCommand(args) {
|
|
|
365334
365639
|
} : { providerUnavailable: resolution.message, providerId: "", modelId: "" },
|
|
365335
365640
|
agentInfo: { name: "keryx", version: package_default.version },
|
|
365336
365641
|
profile,
|
|
365642
|
+
...profile === "shell" && resolution.kind === "ready" && resolution.source !== "fixture" ? {
|
|
365643
|
+
routingProviders: async (force) => {
|
|
365644
|
+
const env = envWithSavedApiKeys(process.env);
|
|
365645
|
+
const catalog = await loadOrRefreshProviderCatalogLive({
|
|
365646
|
+
fetch: globalThis.fetch,
|
|
365647
|
+
env,
|
|
365648
|
+
redetect: async () => withSavedBaseUrls(await detectProviders({
|
|
365649
|
+
fetch: (input, init) => globalThis.fetch(input, { ...init, signal: AbortSignal.timeout(CATALOG_FETCH_TIMEOUT_MS) }),
|
|
365650
|
+
env,
|
|
365651
|
+
...parsed.baseUrl !== undefined ? { baseUrl: parsed.baseUrl } : {}
|
|
365652
|
+
}), loadShellConfig())
|
|
365653
|
+
}, { ttlMs: ROUTING_AVAILABILITY_TTL_MS, force, checkEntryDates: true });
|
|
365654
|
+
return catalogToFlatPickerProviders(catalog, { withStatusRows: true });
|
|
365655
|
+
}
|
|
365656
|
+
} : {},
|
|
365337
365657
|
makeProvider: realMakeProvider(() => {}),
|
|
365338
365658
|
...parsed.dataDir !== undefined ? { dataDir: parsed.dataDir } : {},
|
|
365339
365659
|
idSeq: () => randomUUID94()
|
|
@@ -365413,6 +365733,8 @@ var init_acp = __esm(() => {
|
|
|
365413
365733
|
init_profile2();
|
|
365414
365734
|
init_server3();
|
|
365415
365735
|
init_fixture_provider();
|
|
365736
|
+
init_provider_catalog();
|
|
365737
|
+
init_snapshot_adapter();
|
|
365416
365738
|
init_fake_provider();
|
|
365417
365739
|
init_shell_config();
|
|
365418
365740
|
init_agent();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrciphersmith/keryx",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.48",
|
|
4
4
|
"description": "Version-controlled project context for AI coding agents: code graph, architecture wiki, project memory, relevant tests, quality signals, and task flows.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|