claudish 14.26.1 → 14.27.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/dist/index.js +1905 -103
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -136,6 +136,7 @@ var init_config = __esm(() => {
|
|
|
136
136
|
CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST: "CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST",
|
|
137
137
|
CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL: "_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL",
|
|
138
138
|
CLAUDISH_SET_HOST_ROUTING_VARS: "CLAUDISH_SET_HOST_ROUTING_VARS",
|
|
139
|
+
CLAUDISH_SET_MODEL_VARS: "CLAUDISH_SET_MODEL_VARS",
|
|
139
140
|
CLAUDISH_MODEL_OPUS: "CLAUDISH_MODEL_OPUS",
|
|
140
141
|
CLAUDISH_MODEL_SONNET: "CLAUDISH_MODEL_SONNET",
|
|
141
142
|
CLAUDISH_MODEL_HAIKU: "CLAUDISH_MODEL_HAIKU",
|
|
@@ -5153,6 +5154,22 @@ function acquireFileLockSync(path, opts) {
|
|
|
5153
5154
|
function sleepSync(ms) {
|
|
5154
5155
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
5155
5156
|
}
|
|
5157
|
+
async function withFileLock(path, opts, work) {
|
|
5158
|
+
let handle = null;
|
|
5159
|
+
try {
|
|
5160
|
+
handle = await acquireFileLock(path, opts);
|
|
5161
|
+
} catch (err) {
|
|
5162
|
+
if (opts.onUnavailable === "fail")
|
|
5163
|
+
throw err;
|
|
5164
|
+
opts.log?.(`[FileLock] proceeding unlocked: ${err?.message}`);
|
|
5165
|
+
handle = null;
|
|
5166
|
+
}
|
|
5167
|
+
try {
|
|
5168
|
+
return await work(handle);
|
|
5169
|
+
} finally {
|
|
5170
|
+
handle?.release();
|
|
5171
|
+
}
|
|
5172
|
+
}
|
|
5156
5173
|
var defaultDeps, LOCK_RECORD_WIDTH = 256, FileLockUnavailableError, SYNC_LOCK_POLL_MS = 25;
|
|
5157
5174
|
var init_file_lock = __esm(() => {
|
|
5158
5175
|
defaultDeps = {
|
|
@@ -5525,7 +5542,7 @@ var init_env_placeholder = __esm(() => {
|
|
|
5525
5542
|
});
|
|
5526
5543
|
|
|
5527
5544
|
// src/version.ts
|
|
5528
|
-
var VERSION = "14.
|
|
5545
|
+
var VERSION = "14.27.0";
|
|
5529
5546
|
|
|
5530
5547
|
// src/redact.ts
|
|
5531
5548
|
function isPlaceholder(value) {
|
|
@@ -14128,7 +14145,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14128
14145
|
}
|
|
14129
14146
|
}
|
|
14130
14147
|
},
|
|
14131
|
-
fetchedAt: "2026-11-16T00:
|
|
14148
|
+
fetchedAt: "2026-11-16T00:56:54.374Z",
|
|
14132
14149
|
format: 1,
|
|
14133
14150
|
recommendations: {
|
|
14134
14151
|
contractVersion: 3,
|
|
@@ -58367,6 +58384,20 @@ async function refreshAccountModelsList(provider, trigger, opts) {
|
|
|
58367
58384
|
};
|
|
58368
58385
|
}
|
|
58369
58386
|
}
|
|
58387
|
+
async function liveOrStoredModelsCatalog(provider, trigger) {
|
|
58388
|
+
const result = await refreshAccountModelsList(provider, trigger, {
|
|
58389
|
+
minAgeMs: LIVE_MS
|
|
58390
|
+
});
|
|
58391
|
+
if (result.kind === "refreshed") {
|
|
58392
|
+
return result.outcome.kind === "served" ? servedOutcomeOf(result.outcome.models) : result.outcome;
|
|
58393
|
+
}
|
|
58394
|
+
if (result.reason === "too-recent") {
|
|
58395
|
+
const list = await readAccountModelsList(provider);
|
|
58396
|
+
if (list)
|
|
58397
|
+
return servedOutcomeOf(list.models);
|
|
58398
|
+
}
|
|
58399
|
+
return discoverProviderModelsCatalog(provider);
|
|
58400
|
+
}
|
|
58370
58401
|
function sweepAccountModelsLists(trigger, opts) {
|
|
58371
58402
|
const run = async (provider) => {
|
|
58372
58403
|
const readiness = await credentials.describeReadiness(provider, { allowOpPrompt: false });
|
|
@@ -67756,6 +67787,9 @@ function computeCacheReadDiscount(pricing, billedInputTokens, detail) {
|
|
|
67756
67787
|
function computeTurnCost(pricing, inputTokens, outputTokens, detail) {
|
|
67757
67788
|
return inputTokens / 1e6 * pricing.inputCostPer1M + outputTokens / 1e6 * pricing.outputCostPer1M - computeCacheReadDiscount(pricing, inputTokens, detail);
|
|
67758
67789
|
}
|
|
67790
|
+
function clearTokenFileTotals(path) {
|
|
67791
|
+
tokenFileTotals.delete(path);
|
|
67792
|
+
}
|
|
67759
67793
|
|
|
67760
67794
|
class TokenTracker {
|
|
67761
67795
|
port;
|
|
@@ -67773,6 +67807,13 @@ class TokenTracker {
|
|
|
67773
67807
|
startedAt = Date.now();
|
|
67774
67808
|
sessionBilledInputTokens = 0;
|
|
67775
67809
|
sessionCacheReadTokens = 0;
|
|
67810
|
+
reported = {
|
|
67811
|
+
totalCost: 0,
|
|
67812
|
+
billedInputTokens: 0,
|
|
67813
|
+
outputTokens: 0,
|
|
67814
|
+
totalTokens: 0,
|
|
67815
|
+
toolCalls: new Map
|
|
67816
|
+
};
|
|
67776
67817
|
constructor(port, config) {
|
|
67777
67818
|
this.port = port;
|
|
67778
67819
|
this.config = config;
|
|
@@ -67939,11 +67980,47 @@ class TokenTracker {
|
|
|
67939
67980
|
return "OpenAI";
|
|
67940
67981
|
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
67941
67982
|
}
|
|
67942
|
-
|
|
67983
|
+
addToFileTotals(path, inputTokens) {
|
|
67984
|
+
let totals = tokenFileTotals.get(path);
|
|
67985
|
+
if (!totals) {
|
|
67986
|
+
totals = {
|
|
67987
|
+
totalCost: 0,
|
|
67988
|
+
billedInputTokens: 0,
|
|
67989
|
+
outputTokens: 0,
|
|
67990
|
+
totalTokens: 0,
|
|
67991
|
+
toolCalls: new Map,
|
|
67992
|
+
startedAt: this.startedAt
|
|
67993
|
+
};
|
|
67994
|
+
tokenFileTotals.set(path, totals);
|
|
67995
|
+
}
|
|
67996
|
+
totals.startedAt = Math.min(totals.startedAt, this.startedAt);
|
|
67997
|
+
totals.totalCost += this.sessionTotalCost - this.reported.totalCost;
|
|
67998
|
+
totals.billedInputTokens += this.sessionBilledInputTokens - this.reported.billedInputTokens;
|
|
67999
|
+
totals.outputTokens += this.sessionOutputTokens - this.reported.outputTokens;
|
|
68000
|
+
const ownTotalTokens = inputTokens + this.sessionOutputTokens;
|
|
68001
|
+
totals.totalTokens += ownTotalTokens - this.reported.totalTokens;
|
|
68002
|
+
for (const [name, count] of this.toolCallsByName) {
|
|
68003
|
+
const delta = count - (this.reported.toolCalls.get(name) ?? 0);
|
|
68004
|
+
if (delta !== 0)
|
|
68005
|
+
totals.toolCalls.set(name, (totals.toolCalls.get(name) ?? 0) + delta);
|
|
68006
|
+
}
|
|
68007
|
+
this.reported = {
|
|
68008
|
+
totalCost: this.sessionTotalCost,
|
|
68009
|
+
billedInputTokens: this.sessionBilledInputTokens,
|
|
68010
|
+
outputTokens: this.sessionOutputTokens,
|
|
68011
|
+
totalTokens: ownTotalTokens,
|
|
68012
|
+
toolCalls: new Map(this.toolCallsByName)
|
|
68013
|
+
};
|
|
68014
|
+
return totals;
|
|
68015
|
+
}
|
|
68016
|
+
writeFile(inputTokens, _outputTokens, isEstimate, requestPricing) {
|
|
67943
68017
|
if (this.config.writesTokenFile === false)
|
|
67944
68018
|
return;
|
|
67945
68019
|
try {
|
|
67946
|
-
const
|
|
68020
|
+
const outPath = resolveTokenFilePath(this.port);
|
|
68021
|
+
const totals = this.addToFileTotals(outPath, inputTokens);
|
|
68022
|
+
const outputTokens = totals.outputTokens;
|
|
68023
|
+
const total = totals.totalTokens;
|
|
67947
68024
|
const cw = this.config.contextWindow;
|
|
67948
68025
|
const leftPct = cw > 0 ? Math.max(0, Math.min(100, Math.round((cw - inputTokens) / cw * 100))) : -1;
|
|
67949
68026
|
const pricing = requestPricing ?? this.getPricing();
|
|
@@ -67952,16 +68029,16 @@ class TokenTracker {
|
|
|
67952
68029
|
input_tokens: inputTokens,
|
|
67953
68030
|
output_tokens: outputTokens,
|
|
67954
68031
|
total_tokens: total,
|
|
67955
|
-
total_cost:
|
|
68032
|
+
total_cost: totals.totalCost,
|
|
67956
68033
|
context_window: cw > 0 ? cw : "unknown",
|
|
67957
68034
|
context_left_percent: leftPct,
|
|
67958
68035
|
provider_name: this.getDisplayName(),
|
|
67959
68036
|
updated_at: Date.now(),
|
|
67960
68037
|
is_free: isFreeModel,
|
|
67961
68038
|
is_estimated: isEstimate || false,
|
|
67962
|
-
started_at:
|
|
67963
|
-
tool_calls:
|
|
67964
|
-
billed_input_tokens:
|
|
68039
|
+
started_at: totals.startedAt,
|
|
68040
|
+
tool_calls: [...totals.toolCalls].filter(([, count]) => count > 0).map(([name, count]) => ({ name, count })).sort((a, b) => b.count - a.count || a.name.localeCompare(b.name)),
|
|
68041
|
+
billed_input_tokens: totals.billedInputTokens,
|
|
67965
68042
|
input_per_m: pricing.inputCostPer1M,
|
|
67966
68043
|
output_per_m: pricing.outputCostPer1M
|
|
67967
68044
|
};
|
|
@@ -67985,7 +68062,6 @@ class TokenTracker {
|
|
|
67985
68062
|
gapEndSec: allowance.gapEndSec
|
|
67986
68063
|
};
|
|
67987
68064
|
}
|
|
67988
|
-
const outPath = resolveTokenFilePath(this.port);
|
|
67989
68065
|
mkdirSync18(dirname15(outPath), { recursive: true });
|
|
67990
68066
|
writeFileSync13(outPath, JSON.stringify(data), "utf-8");
|
|
67991
68067
|
} catch (e) {
|
|
@@ -67993,7 +68069,7 @@ class TokenTracker {
|
|
|
67993
68069
|
}
|
|
67994
68070
|
}
|
|
67995
68071
|
}
|
|
67996
|
-
var ALLOWANCE_LABEL_STALE_MS;
|
|
68072
|
+
var ALLOWANCE_LABEL_STALE_MS, tokenFileTotals;
|
|
67997
68073
|
var init_token_tracker = __esm(() => {
|
|
67998
68074
|
init_tool_name_utils();
|
|
67999
68075
|
init_types2();
|
|
@@ -68002,6 +68078,7 @@ var init_token_tracker = __esm(() => {
|
|
|
68002
68078
|
init_token_file();
|
|
68003
68079
|
init_remote_provider_types();
|
|
68004
68080
|
ALLOWANCE_LABEL_STALE_MS = 10 * 60 * 1000;
|
|
68081
|
+
tokenFileTotals = new Map;
|
|
68005
68082
|
});
|
|
68006
68083
|
|
|
68007
68084
|
// src/handlers/shared/upstream-error-capture.ts
|
|
@@ -73648,7 +73725,100 @@ function getLegacySyntaxWarning(parsed) {
|
|
|
73648
73725
|
return `Deprecation warning: "${parsed.original}" uses legacy prefix syntax.
|
|
73649
73726
|
` + ` Consider using: ${newSyntax}`;
|
|
73650
73727
|
}
|
|
73651
|
-
|
|
73728
|
+
function parseListingEntry(value) {
|
|
73729
|
+
const match = LISTING_ENTRY.exec(value.trim());
|
|
73730
|
+
if (!match)
|
|
73731
|
+
return null;
|
|
73732
|
+
return { shortcut: match[1].toLowerCase(), scope: match[2] ? "all" : "recommended" };
|
|
73733
|
+
}
|
|
73734
|
+
function modelValueForMessage(value) {
|
|
73735
|
+
return parseModelChain(value).map((element) => {
|
|
73736
|
+
const parsed = parseModelSpec(element);
|
|
73737
|
+
if (parsed.provider !== "custom-url")
|
|
73738
|
+
return element;
|
|
73739
|
+
try {
|
|
73740
|
+
return `<a raw URL at ${new URL(parsed.model).origin}>`;
|
|
73741
|
+
} catch {
|
|
73742
|
+
return "<a raw URL>";
|
|
73743
|
+
}
|
|
73744
|
+
}).join("+");
|
|
73745
|
+
}
|
|
73746
|
+
function pinnedSpecRefusal(spec) {
|
|
73747
|
+
const parsed = parseModelSpec(spec);
|
|
73748
|
+
if (parsed.provider === "custom-url") {
|
|
73749
|
+
return `--model ${modelValueForMessage(spec)}: a raw URL cannot be listed in /model. Declare the endpoint under customEndpoints and list it by name (--model <name>@).`;
|
|
73750
|
+
}
|
|
73751
|
+
if (parsed.provider === "native-anthropic") {
|
|
73752
|
+
return `--model ${spec}: a Claude model cannot be listed beside the start model, because Claude Code lists Claude's own models in /model already. Drop it, or give it as the last --model to start on it.`;
|
|
73753
|
+
}
|
|
73754
|
+
if (!parsed.isExplicitProvider) {
|
|
73755
|
+
if (parsed.provider === "unknown") {
|
|
73756
|
+
return `--model ${spec}: "${spec}" names no claudish provider to list. Use <provider>@${spec}, for example openrouter@${spec}.`;
|
|
73757
|
+
}
|
|
73758
|
+
return `--model ${spec}: a bare model name names no provider to list. Use <provider>@${spec}, or give it as the last --model to start on it.`;
|
|
73759
|
+
}
|
|
73760
|
+
return null;
|
|
73761
|
+
}
|
|
73762
|
+
function parseModelFlags(values) {
|
|
73763
|
+
const listings = [];
|
|
73764
|
+
const fullSpecs = [];
|
|
73765
|
+
const raw = [];
|
|
73766
|
+
for (const value of values) {
|
|
73767
|
+
const entry = parseListingEntry(value);
|
|
73768
|
+
if (entry) {
|
|
73769
|
+
const earlier = listings.find((l) => l.shortcut === entry.shortcut);
|
|
73770
|
+
if (earlier) {
|
|
73771
|
+
if (entry.scope === "all")
|
|
73772
|
+
earlier.scope = "all";
|
|
73773
|
+
} else {
|
|
73774
|
+
listings.push(entry);
|
|
73775
|
+
}
|
|
73776
|
+
continue;
|
|
73777
|
+
}
|
|
73778
|
+
fullSpecs.push(parseModelChain(value).map(normalizeNativeModelSpec));
|
|
73779
|
+
raw.push(value);
|
|
73780
|
+
}
|
|
73781
|
+
if (listings.length === 0) {
|
|
73782
|
+
const last = fullSpecs[fullSpecs.length - 1];
|
|
73783
|
+
if (!last)
|
|
73784
|
+
return { ok: true, value: { pinned: [], listings: [], hasLineup: false } };
|
|
73785
|
+
return {
|
|
73786
|
+
ok: true,
|
|
73787
|
+
value: {
|
|
73788
|
+
start: last[0],
|
|
73789
|
+
...last.length > 1 ? { chain: last } : {},
|
|
73790
|
+
pinned: [],
|
|
73791
|
+
listings: [],
|
|
73792
|
+
hasLineup: false
|
|
73793
|
+
}
|
|
73794
|
+
};
|
|
73795
|
+
}
|
|
73796
|
+
for (let i = 0;i < fullSpecs.length; i++) {
|
|
73797
|
+
if (fullSpecs[i].length > 1) {
|
|
73798
|
+
return {
|
|
73799
|
+
ok: false,
|
|
73800
|
+
message: `--model ${modelValueForMessage(raw[i])}: a + routing chain cannot be combined with a listing entry. Give one model per --model.`
|
|
73801
|
+
};
|
|
73802
|
+
}
|
|
73803
|
+
}
|
|
73804
|
+
const specs = fullSpecs.map((chain) => chain[0]);
|
|
73805
|
+
const pinned = specs.slice(0, -1);
|
|
73806
|
+
for (const spec of pinned) {
|
|
73807
|
+
const refusal = pinnedSpecRefusal(spec);
|
|
73808
|
+
if (refusal)
|
|
73809
|
+
return { ok: false, message: refusal };
|
|
73810
|
+
}
|
|
73811
|
+
return {
|
|
73812
|
+
ok: true,
|
|
73813
|
+
value: {
|
|
73814
|
+
...specs.length > 0 ? { start: specs[specs.length - 1] } : {},
|
|
73815
|
+
pinned,
|
|
73816
|
+
listings,
|
|
73817
|
+
hasLineup: true
|
|
73818
|
+
}
|
|
73819
|
+
};
|
|
73820
|
+
}
|
|
73821
|
+
var AUTO_ROUTE_PROVIDER = "auto-route", PROVIDER_SHORTCUTS, PROVIDER_PREFIX, LOCAL_PROVIDERS, NATIVE_MODEL_PATTERNS, LEGACY_PREFIX_PATTERNS, MODEL_CHAIN_SEPARATOR = "+", MODE_MARKER_SEGMENT, LISTING_ENTRY;
|
|
73652
73822
|
var init_model_parser = __esm(() => {
|
|
73653
73823
|
init_claude_code_aliases();
|
|
73654
73824
|
init_provider_definitions();
|
|
@@ -73663,6 +73833,7 @@ var init_model_parser = __esm(() => {
|
|
|
73663
73833
|
NATIVE_MODEL_PATTERNS = getNativeModelPatterns();
|
|
73664
73834
|
LEGACY_PREFIX_PATTERNS = getLegacyPrefixPatterns();
|
|
73665
73835
|
MODE_MARKER_SEGMENT = /^(pro|standard)(#[a-z]+)?(:\d+)?$/i;
|
|
73836
|
+
LISTING_ENTRY = /^([^@\s/:+#]+)@(\*)?$/;
|
|
73666
73837
|
});
|
|
73667
73838
|
|
|
73668
73839
|
// src/providers/predefined-catalog.ts
|
|
@@ -92086,6 +92257,80 @@ var init_magmux_wrapper = __esm(() => {
|
|
|
92086
92257
|
STRIPPED_CHILD_VARS = ["CLAUDECODE", "CLAUDE_CODE_CHILD_SESSION"];
|
|
92087
92258
|
});
|
|
92088
92259
|
|
|
92260
|
+
// src/model-vars-env.ts
|
|
92261
|
+
function recordModelVars(env, set) {
|
|
92262
|
+
const record = {};
|
|
92263
|
+
for (const name of MODEL_VAR_NAMES) {
|
|
92264
|
+
const value = set[name];
|
|
92265
|
+
if (typeof value !== "string" || value.length === 0)
|
|
92266
|
+
continue;
|
|
92267
|
+
env[name] = value;
|
|
92268
|
+
record[name] = value;
|
|
92269
|
+
}
|
|
92270
|
+
if (Object.keys(record).length > 0) {
|
|
92271
|
+
env[ENV.CLAUDISH_SET_MODEL_VARS] = JSON.stringify(record);
|
|
92272
|
+
}
|
|
92273
|
+
}
|
|
92274
|
+
function readRecord(env) {
|
|
92275
|
+
const raw = env[ENV.CLAUDISH_SET_MODEL_VARS];
|
|
92276
|
+
if (typeof raw !== "string" || raw.length === 0)
|
|
92277
|
+
return {};
|
|
92278
|
+
try {
|
|
92279
|
+
const parsed = JSON.parse(raw);
|
|
92280
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
92281
|
+
return {};
|
|
92282
|
+
const record = {};
|
|
92283
|
+
for (const name of MODEL_VAR_NAMES) {
|
|
92284
|
+
const value = parsed[name];
|
|
92285
|
+
if (typeof value === "string")
|
|
92286
|
+
record[name] = value;
|
|
92287
|
+
}
|
|
92288
|
+
return record;
|
|
92289
|
+
} catch {
|
|
92290
|
+
return {};
|
|
92291
|
+
}
|
|
92292
|
+
}
|
|
92293
|
+
function isModelVarSetByClaudish(env, name) {
|
|
92294
|
+
const value = env[name];
|
|
92295
|
+
return typeof value === "string" && value.length > 0 && readRecord(env)[name] === value;
|
|
92296
|
+
}
|
|
92297
|
+
function isClaudishProviderSpec(value) {
|
|
92298
|
+
const parsed = parseModelSpec(value);
|
|
92299
|
+
return parsed.isExplicitProvider && parsed.provider !== "native-anthropic";
|
|
92300
|
+
}
|
|
92301
|
+
function scrubInheritedModelVars(env, keep, opts = {}) {
|
|
92302
|
+
const record = readRecord(env);
|
|
92303
|
+
const removed = [];
|
|
92304
|
+
const survived = [];
|
|
92305
|
+
for (const name of MODEL_VAR_NAMES) {
|
|
92306
|
+
if (name === "ANTHROPIC_MODEL" ? keep.model : keep.smallFast)
|
|
92307
|
+
continue;
|
|
92308
|
+
const value = env[name];
|
|
92309
|
+
if (typeof value !== "string" || value.length === 0)
|
|
92310
|
+
continue;
|
|
92311
|
+
const setByClaudish = record[name] === value;
|
|
92312
|
+
if (setByClaudish || opts.keepsLogin === true && isClaudishProviderSpec(value)) {
|
|
92313
|
+
delete env[name];
|
|
92314
|
+
removed.push(name);
|
|
92315
|
+
} else {
|
|
92316
|
+
survived.push({ name, value });
|
|
92317
|
+
}
|
|
92318
|
+
}
|
|
92319
|
+
if (ENV.CLAUDISH_SET_MODEL_VARS in env)
|
|
92320
|
+
delete env[ENV.CLAUDISH_SET_MODEL_VARS];
|
|
92321
|
+
const haiku = env[ENV.ANTHROPIC_DEFAULT_HAIKU_MODEL];
|
|
92322
|
+
if (typeof haiku === "string" && haiku.length > 0) {
|
|
92323
|
+
survived.push({ name: ENV.ANTHROPIC_DEFAULT_HAIKU_MODEL, value: haiku });
|
|
92324
|
+
}
|
|
92325
|
+
return { removed, survived };
|
|
92326
|
+
}
|
|
92327
|
+
var MODEL_VAR_NAMES;
|
|
92328
|
+
var init_model_vars_env = __esm(() => {
|
|
92329
|
+
init_config();
|
|
92330
|
+
init_model_parser();
|
|
92331
|
+
MODEL_VAR_NAMES = ["ANTHROPIC_MODEL", "ANTHROPIC_SMALL_FAST_MODEL"];
|
|
92332
|
+
});
|
|
92333
|
+
|
|
92089
92334
|
// src/providers/cache-ttl.ts
|
|
92090
92335
|
var FIREBASE_CACHE_TTL_HOURS = 24, FIREBASE_CACHE_TTL_MS;
|
|
92091
92336
|
var init_cache_ttl = __esm(() => {
|
|
@@ -94128,19 +94373,8 @@ function storedOutcome(provider, displayName, list, catalog) {
|
|
|
94128
94373
|
const outcome = outcomeFromModelsCatalog(provider, displayName, servedOutcomeOf(list.models), servedModelsForProvider(provider, catalog));
|
|
94129
94374
|
return outcome.kind === "rows" ? { ...outcome, listFetchedAt: list.fetchedAt } : null;
|
|
94130
94375
|
}
|
|
94131
|
-
|
|
94132
|
-
|
|
94133
|
-
minAgeMs: LIVE_MS
|
|
94134
|
-
});
|
|
94135
|
-
if (result.kind === "refreshed") {
|
|
94136
|
-
return result.outcome.kind === "served" ? servedOutcomeOf(result.outcome.models) : result.outcome;
|
|
94137
|
-
}
|
|
94138
|
-
if (result.reason === "too-recent") {
|
|
94139
|
-
const list = await readAccountModelsList(provider);
|
|
94140
|
-
if (list)
|
|
94141
|
-
return servedOutcomeOf(list.models);
|
|
94142
|
-
}
|
|
94143
|
-
return discoverProviderModelsCatalog(provider);
|
|
94376
|
+
function pickerLiveModelsCatalog(provider) {
|
|
94377
|
+
return liveOrStoredModelsCatalog(provider, "picker-provider");
|
|
94144
94378
|
}
|
|
94145
94379
|
function createPickerDataSource() {
|
|
94146
94380
|
const catalog = createCatalogClient();
|
|
@@ -94228,7 +94462,7 @@ function createPickerDataSource() {
|
|
|
94228
94462
|
return [...stored.rows, ...fromCatalog.filter((m) => !listed.has(m.id))];
|
|
94229
94463
|
},
|
|
94230
94464
|
discoverModelsCatalog(provider) {
|
|
94231
|
-
return buildDiscoveredModelOutcome(provider, names.get(provider) ?? provider, catalog, isPersistedListProvider(provider) ?
|
|
94465
|
+
return buildDiscoveredModelOutcome(provider, names.get(provider) ?? provider, catalog, isPersistedListProvider(provider) ? pickerLiveModelsCatalog : undefined);
|
|
94232
94466
|
},
|
|
94233
94467
|
cachedModelsCatalog(provider) {
|
|
94234
94468
|
return cachedOutcome(provider);
|
|
@@ -107454,14 +107688,16 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
107454
107688
|
return out.markers && (out.markers.mode || out.markers.speed) ? new WireMarkerHandler(handler, out.markers) : handler;
|
|
107455
107689
|
};
|
|
107456
107690
|
const requestProbeHopOrigin = (c) => probeHopOriginOf(c.req.header(PROBE_HOP_ORIGIN_HEADER), options.probeProxy);
|
|
107691
|
+
const lineupSpecs = new Set((options.modelLineup ?? []).map((row) => row.model));
|
|
107457
107692
|
const resolveHandlerForRequest = async (requestedModel, out, probeHopOrigin) => {
|
|
107458
107693
|
if (monitorMode)
|
|
107459
107694
|
return nativeHandler;
|
|
107460
107695
|
let target = requestedModel;
|
|
107461
107696
|
let wasFromModelMap = false;
|
|
107462
107697
|
let targetFromLaunch = false;
|
|
107698
|
+
const lineupMatched = lineupSpecs.has(requestedModel);
|
|
107463
107699
|
let slotMatched = false;
|
|
107464
|
-
const slot = options.slotMap?.get(requestedModel);
|
|
107700
|
+
const slot = lineupMatched ? undefined : options.slotMap?.get(requestedModel);
|
|
107465
107701
|
if (slot) {
|
|
107466
107702
|
target = slot.provider != null && slot.provider !== "" ? `${slot.provider}@${slot.model}` : slot.model;
|
|
107467
107703
|
slotMatched = true;
|
|
@@ -107470,8 +107706,9 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
107470
107706
|
logStderr(`[Serve] slot ${requestedModel} \u2192 ${target}`);
|
|
107471
107707
|
}
|
|
107472
107708
|
}
|
|
107709
|
+
const claudeRowPicked = options.claudeRowsAsPicked === true && nativeRouteFor(requestedModel) !== null;
|
|
107473
107710
|
const req = requestedModel.toLowerCase();
|
|
107474
|
-
if (slotMatched) {} else if (modelMap) {
|
|
107711
|
+
if (slotMatched || lineupMatched) {} else if (modelMap) {
|
|
107475
107712
|
if (req.includes("opus") && modelMap.opus) {
|
|
107476
107713
|
target = modelMap.opus;
|
|
107477
107714
|
wasFromModelMap = true;
|
|
@@ -107481,10 +107718,10 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
107481
107718
|
} else if (req.includes("haiku") && modelMap.haiku) {
|
|
107482
107719
|
target = modelMap.haiku;
|
|
107483
107720
|
wasFromModelMap = true;
|
|
107484
|
-
} else if (model)
|
|
107721
|
+
} else if (model && !claudeRowPicked)
|
|
107485
107722
|
target = model;
|
|
107486
|
-
targetFromLaunch = wasFromModelMap || Boolean(model);
|
|
107487
|
-
} else if (model) {
|
|
107723
|
+
targetFromLaunch = wasFromModelMap || Boolean(model) && !claudeRowPicked;
|
|
107724
|
+
} else if (model && !claudeRowPicked) {
|
|
107488
107725
|
target = model;
|
|
107489
107726
|
targetFromLaunch = true;
|
|
107490
107727
|
}
|
|
@@ -107701,7 +107938,18 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107701
107938
|
}
|
|
107702
107939
|
return [...seen];
|
|
107703
107940
|
})();
|
|
107941
|
+
const lineupModels = () => (options.modelLineup ?? []).map((row) => ({
|
|
107942
|
+
id: row.model,
|
|
107943
|
+
type: "model",
|
|
107944
|
+
object: "model",
|
|
107945
|
+
display_name: redactForClient(row.label),
|
|
107946
|
+
created: MODEL_LIST_CREATED,
|
|
107947
|
+
owned_by: "claudish"
|
|
107948
|
+
}));
|
|
107704
107949
|
app.get("/v1/models", (c) => {
|
|
107950
|
+
if (servedSlotIds.length === 0 && options.modelLineup !== undefined) {
|
|
107951
|
+
return c.json({ object: "list", has_more: false, data: lineupModels() });
|
|
107952
|
+
}
|
|
107705
107953
|
const ids = servedSlotIds.length > 0 ? servedSlotIds : discoverableModelIds;
|
|
107706
107954
|
return c.json({
|
|
107707
107955
|
object: "list",
|
|
@@ -107710,7 +107958,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107710
107958
|
id,
|
|
107711
107959
|
object: "model",
|
|
107712
107960
|
type: "model",
|
|
107713
|
-
created:
|
|
107961
|
+
created: MODEL_LIST_CREATED,
|
|
107714
107962
|
owned_by: "claudish"
|
|
107715
107963
|
}))
|
|
107716
107964
|
});
|
|
@@ -107849,6 +108097,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107849
108097
|
if (advisorRuntime)
|
|
107850
108098
|
await shutdownAdvisorChains(advisorRuntime.chains.values());
|
|
107851
108099
|
closeAllEpisodes();
|
|
108100
|
+
clearTokenFileTotals(resolveTokenFilePath(port));
|
|
107852
108101
|
},
|
|
107853
108102
|
invalidateHandlerCache: (providerSlug) => {
|
|
107854
108103
|
if (!providerSlug) {
|
|
@@ -107871,7 +108120,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107871
108120
|
}
|
|
107872
108121
|
};
|
|
107873
108122
|
}
|
|
107874
|
-
var RoutingError, classifierCaptureDirReady = false;
|
|
108123
|
+
var RoutingError, classifierCaptureDirReady = false, MODEL_LIST_CREATED = 1716000000;
|
|
107875
108124
|
var init_proxy_server = __esm(() => {
|
|
107876
108125
|
init_dist13();
|
|
107877
108126
|
init_cors();
|
|
@@ -107891,6 +108140,7 @@ var init_proxy_server = __esm(() => {
|
|
|
107891
108140
|
init_anthropic_forward();
|
|
107892
108141
|
init_call_context();
|
|
107893
108142
|
init_hop_decision();
|
|
108143
|
+
init_token_tracker();
|
|
107894
108144
|
init_hooks();
|
|
107895
108145
|
init_response_seam();
|
|
107896
108146
|
init_logger();
|
|
@@ -107913,6 +108163,7 @@ var init_proxy_server = __esm(() => {
|
|
|
107913
108163
|
init_coordinator();
|
|
107914
108164
|
init_redact();
|
|
107915
108165
|
init_pricing_cache();
|
|
108166
|
+
init_token_file();
|
|
107916
108167
|
init_test_upstream();
|
|
107917
108168
|
RoutingError = class RoutingError extends Error {
|
|
107918
108169
|
constructor(message) {
|
|
@@ -108096,7 +108347,7 @@ async function parseArgs(args) {
|
|
|
108096
108347
|
const anthropicModel = process.env[ENV.ANTHROPIC_MODEL];
|
|
108097
108348
|
if (claudishModel) {
|
|
108098
108349
|
config.model = claudishModel;
|
|
108099
|
-
} else if (anthropicModel) {
|
|
108350
|
+
} else if (anthropicModel && !isModelVarSetByClaudish(process.env, "ANTHROPIC_MODEL")) {
|
|
108100
108351
|
config.model = anthropicModel;
|
|
108101
108352
|
}
|
|
108102
108353
|
const tierSources = {};
|
|
@@ -108160,6 +108411,7 @@ async function parseArgs(args) {
|
|
|
108160
108411
|
if (config.debug && config.logLevel === "info") {
|
|
108161
108412
|
config.logLevel = "debug";
|
|
108162
108413
|
}
|
|
108414
|
+
const modelValues = [];
|
|
108163
108415
|
let i = 0;
|
|
108164
108416
|
while (i < args.length) {
|
|
108165
108417
|
const arg = args[i];
|
|
@@ -108174,6 +108426,9 @@ async function parseArgs(args) {
|
|
|
108174
108426
|
config.model = chain[0];
|
|
108175
108427
|
if (chain.length > 1)
|
|
108176
108428
|
config.modelChain = chain;
|
|
108429
|
+
else
|
|
108430
|
+
delete config.modelChain;
|
|
108431
|
+
modelValues.push(modelArg);
|
|
108177
108432
|
} else if (arg === "--model-pinned") {
|
|
108178
108433
|
config.modelPinned = true;
|
|
108179
108434
|
} else if (arg === "--claude-subscription-pin") {
|
|
@@ -108517,6 +108772,16 @@ Usage: claudish --models --provider <slug>`);
|
|
|
108517
108772
|
}
|
|
108518
108773
|
i++;
|
|
108519
108774
|
}
|
|
108775
|
+
if (modelValues.some((value) => parseListingEntry(value) !== null)) {
|
|
108776
|
+
const flags = parseModelFlags(modelValues);
|
|
108777
|
+
if (!flags.ok) {
|
|
108778
|
+
console.error(`[claudish] Error: ${redactSecrets(flags.message)}`);
|
|
108779
|
+
process.exit(1);
|
|
108780
|
+
}
|
|
108781
|
+
config.model = flags.value.start;
|
|
108782
|
+
delete config.modelChain;
|
|
108783
|
+
config._modelFlags = flags.value;
|
|
108784
|
+
}
|
|
108520
108785
|
if (!config._hasPositionalPrompt && !config.stdin && !config._hasPrintFlag) {
|
|
108521
108786
|
config.interactive = true;
|
|
108522
108787
|
}
|
|
@@ -109296,6 +109561,9 @@ ${shortcutTable}
|
|
|
109296
109561
|
${h("OPTIONS")}
|
|
109297
109562
|
${green("-i, --interactive")} Run in interactive mode (default when no prompt given)
|
|
109298
109563
|
${green("-m, --model")} ${yellow("<model>")} Model to use (required for single-shot mode)
|
|
109564
|
+
${dim("--model <provider>@ (no model) lists that provider's models in /model;")}
|
|
109565
|
+
${dim("--model '<provider>@*' lists every model a gateway serves. Repeat --model")}
|
|
109566
|
+
${dim("to list several; the last <provider>@<model> starts the session.")}
|
|
109299
109567
|
${green("--profile")} ${yellow("<name>")} Use named profile for model mapping (default profile if omitted)
|
|
109300
109568
|
${green("--default-provider")} ${yellow("<name>")} Fallback provider for bare model names (claudish provider or customEndpoints key)
|
|
109301
109569
|
${dim('"" disables it. Precedence: this flag > CLAUDISH_DEFAULT_PROVIDER env > config.json')}
|
|
@@ -109687,6 +109955,7 @@ var init_cli = __esm(() => {
|
|
|
109687
109955
|
init_logger();
|
|
109688
109956
|
init_model_loader();
|
|
109689
109957
|
init_model_selector();
|
|
109958
|
+
init_model_vars_env();
|
|
109690
109959
|
init_probe_chain();
|
|
109691
109960
|
init_probe_results_printer();
|
|
109692
109961
|
init_probe_tui_runtime();
|
|
@@ -109708,6 +109977,7 @@ var init_cli = __esm(() => {
|
|
|
109708
109977
|
init_routing_rules();
|
|
109709
109978
|
init_recommended_listing();
|
|
109710
109979
|
init_settings();
|
|
109980
|
+
init_redact();
|
|
109711
109981
|
init_ansi();
|
|
109712
109982
|
init_provider_resolver();
|
|
109713
109983
|
__filename2 = fileURLToPath2(import.meta.url);
|
|
@@ -111457,7 +111727,17 @@ function hasNativeAnthropicMapping(config) {
|
|
|
111457
111727
|
config.modelHaiku,
|
|
111458
111728
|
config.modelSubagent
|
|
111459
111729
|
];
|
|
111460
|
-
return models.some((m) => m && nativeRouteFor(m) !== null);
|
|
111730
|
+
return models.some((m) => m && nativeRouteFor(m) !== null) || startsOnClaudeSubscription(config);
|
|
111731
|
+
}
|
|
111732
|
+
function startsOnClaudeSubscription(config) {
|
|
111733
|
+
if ((config.modelListings?.length ?? 0) === 0)
|
|
111734
|
+
return false;
|
|
111735
|
+
if (config.monitor)
|
|
111736
|
+
return false;
|
|
111737
|
+
if (config.model || (config.modelChain?.length ?? 0) > 0)
|
|
111738
|
+
return false;
|
|
111739
|
+
const tiers = [config.modelOpus, config.modelSonnet, config.modelHaiku, config.modelSubagent];
|
|
111740
|
+
return !tiers.some((m) => typeof m === "string" && m.length > 0);
|
|
111461
111741
|
}
|
|
111462
111742
|
function claudeLaunchAuthLine(launch, env, keySource) {
|
|
111463
111743
|
const state = (name) => {
|
|
@@ -111646,6 +111926,17 @@ function settingsArgOccurrences(args) {
|
|
|
111646
111926
|
}
|
|
111647
111927
|
return out;
|
|
111648
111928
|
}
|
|
111929
|
+
function settingsArgScopeOf(config) {
|
|
111930
|
+
return config.modelLineup?.picker ? "every" : "first";
|
|
111931
|
+
}
|
|
111932
|
+
function settingsArgValues(claudeArgs, scope) {
|
|
111933
|
+
if (scope === "every") {
|
|
111934
|
+
return settingsArgOccurrences(claudeArgs).flatMap((o) => o.value ? [o.value] : []);
|
|
111935
|
+
}
|
|
111936
|
+
const idx = claudeArgs.indexOf("--settings");
|
|
111937
|
+
const value = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
111938
|
+
return value ? [value] : [];
|
|
111939
|
+
}
|
|
111649
111940
|
function customHeaderAuthNames(value) {
|
|
111650
111941
|
const names = new Set;
|
|
111651
111942
|
if (typeof value !== "string" || !value)
|
|
@@ -111809,6 +112100,42 @@ function settingsClaudeLoginToken(config, env = process.env, deps = {}) {
|
|
|
111809
112100
|
}
|
|
111810
112101
|
return "absent";
|
|
111811
112102
|
}
|
|
112103
|
+
function modelPickerSources(config, env = process.env, deps = {}) {
|
|
112104
|
+
let user = null;
|
|
112105
|
+
let userRank = -1;
|
|
112106
|
+
let managed = null;
|
|
112107
|
+
const availableModels = [];
|
|
112108
|
+
claudeSettingsLayers(config, env, deps).forEach((layer, index) => {
|
|
112109
|
+
const settings = layer.settings;
|
|
112110
|
+
if (settings === null)
|
|
112111
|
+
return;
|
|
112112
|
+
const where = layer.file ?? layer.where;
|
|
112113
|
+
if ("availableModels" in settings)
|
|
112114
|
+
availableModels.push(where);
|
|
112115
|
+
if (!("modelPicker" in settings))
|
|
112116
|
+
return;
|
|
112117
|
+
if (layer.tier === "managed") {
|
|
112118
|
+
managed = where;
|
|
112119
|
+
return;
|
|
112120
|
+
}
|
|
112121
|
+
const rank = NON_MANAGED_TIER_RANK[layer.tier] * 1e4 + index;
|
|
112122
|
+
if (rank < userRank)
|
|
112123
|
+
return;
|
|
112124
|
+
userRank = rank;
|
|
112125
|
+
const picker = settings.modelPicker;
|
|
112126
|
+
const record = picker && typeof picker === "object" && !Array.isArray(picker) ? picker : {};
|
|
112127
|
+
user = {
|
|
112128
|
+
where,
|
|
112129
|
+
options: Array.isArray(record.options) ? record.options : [],
|
|
112130
|
+
..."replaceBuiltInOptions" in record ? { replaceBuiltInOptions: record.replaceBuiltInOptions } : {}
|
|
112131
|
+
};
|
|
112132
|
+
});
|
|
112133
|
+
return { user, managed, availableModels };
|
|
112134
|
+
}
|
|
112135
|
+
function unreadableSettingsArgs(config, deps = {}) {
|
|
112136
|
+
const readFile = deps.readFile ?? ((path) => readFileSync43(path, "utf-8"));
|
|
112137
|
+
return settingsArgOccurrences(config.claudeArgs ?? []).flatMap((occurrence, i) => occurrence.value && readSettingsSource(occurrence.value, readFile) === null ? [i + 1] : []);
|
|
112138
|
+
}
|
|
111812
112139
|
function enabledSettingSources(args) {
|
|
111813
112140
|
let value;
|
|
111814
112141
|
for (let i = 0;i < args.length; i++) {
|
|
@@ -111842,7 +112169,7 @@ function readSettingsSource(source, readFile) {
|
|
|
111842
112169
|
try {
|
|
111843
112170
|
const raw = isInlineSettings(source) ? source : readFile(source);
|
|
111844
112171
|
const parsed = JSON.parse(raw);
|
|
111845
|
-
return parsed && typeof parsed === "object" ? parsed : null;
|
|
112172
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
111846
112173
|
} catch {
|
|
111847
112174
|
return null;
|
|
111848
112175
|
}
|
|
@@ -112111,12 +112438,9 @@ function userSettingsFileCandidates(cwd) {
|
|
|
112111
112438
|
join53(cwd, ".claude", "settings.local.json")
|
|
112112
112439
|
];
|
|
112113
112440
|
}
|
|
112114
|
-
function discoverUserStatusLineCommand(claudeArgs = [], cwd = process.cwd()) {
|
|
112441
|
+
function discoverUserStatusLineCommand(claudeArgs = [], cwd = process.cwd(), scope = "first") {
|
|
112115
112442
|
const sources = userSettingsFileCandidates(cwd).filter((file) => existsSync37(file));
|
|
112116
|
-
|
|
112117
|
-
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
112118
|
-
if (settingsArg)
|
|
112119
|
-
sources.push(settingsArg);
|
|
112443
|
+
sources.push(...settingsArgValues(claudeArgs, scope));
|
|
112120
112444
|
let effective;
|
|
112121
112445
|
for (const source of sources) {
|
|
112122
112446
|
const layer = parseSettingsArgSafe(source);
|
|
@@ -112147,7 +112471,7 @@ function buildChainedStatusCommand(userCommand, claudishBody, claudishSegment) {
|
|
|
112147
112471
|
const emit = `if [ -n "$USER_OUT" ]; then LAST="\${USER_OUT##*$'\\n'}"; if [ "$LAST" = "$USER_OUT" ]; then printf '%s%s%s\\n' "$USER_OUT" "$SEP" "$SEG"; else printf '%s\\n%s%s%s\\n' "\${USER_OUT%$'\\n'*}" "$LAST" "$SEP" "$SEG"; fi; else printf '%s\\n' "$SEG"; fi`;
|
|
112148
112472
|
return `JSON=$(cat); ${runUser}; ${claudishBody}; SEG=$(${claudishSegment}); ${separator}; ${emit}`;
|
|
112149
112473
|
}
|
|
112150
|
-
function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLineCommand) {
|
|
112474
|
+
function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLineCommand, modelPicker) {
|
|
112151
112475
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
112152
112476
|
const claudishDir = join53(homeDir, ".claudish");
|
|
112153
112477
|
try {
|
|
@@ -112192,7 +112516,7 @@ function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLi
|
|
|
112192
112516
|
command: statusCommand,
|
|
112193
112517
|
padding: 0
|
|
112194
112518
|
};
|
|
112195
|
-
const settings = buildClaudishSettingsOverlay(statusLine, proxyAuthMode);
|
|
112519
|
+
const settings = buildClaudishSettingsOverlay(statusLine, proxyAuthMode, isPaneChild(), modelPicker);
|
|
112196
112520
|
writeFileSync20(tempPath, JSON.stringify(settings, null, 2), { encoding: "utf-8", mode: 384 });
|
|
112197
112521
|
return { path: tempPath, statusLine, tokenFilePath };
|
|
112198
112522
|
}
|
|
@@ -112204,7 +112528,7 @@ function scrubChildEnv(env, opts) {
|
|
|
112204
112528
|
for (const key of PANE_LAUNCH_VARS)
|
|
112205
112529
|
delete env[key];
|
|
112206
112530
|
}
|
|
112207
|
-
function buildClaudishSettingsOverlay(statusLine, proxyAuthMode, paneChild = isPaneChild()) {
|
|
112531
|
+
function buildClaudishSettingsOverlay(statusLine, proxyAuthMode, paneChild = isPaneChild(), modelPicker) {
|
|
112208
112532
|
const settings = { statusLine, disableClaudeAiConnectors: true };
|
|
112209
112533
|
if (proxyAuthMode) {
|
|
112210
112534
|
settings.forceLoginMethod = "console";
|
|
@@ -112215,9 +112539,36 @@ function buildClaudishSettingsOverlay(statusLine, proxyAuthMode, paneChild = isP
|
|
|
112215
112539
|
settings.wheelScrollAccelerationEnabled = false;
|
|
112216
112540
|
settings.tui = "fullscreen";
|
|
112217
112541
|
}
|
|
112542
|
+
if (modelPicker)
|
|
112543
|
+
settings.modelPicker = modelPicker;
|
|
112218
112544
|
return settings;
|
|
112219
112545
|
}
|
|
112220
|
-
function
|
|
112546
|
+
function applyClaudishSettingsKeys(userSettings, statusLine, proxyAuthMode, paneChild) {
|
|
112547
|
+
userSettings.statusLine = statusLine;
|
|
112548
|
+
if (!("disableClaudeAiConnectors" in userSettings)) {
|
|
112549
|
+
userSettings.disableClaudeAiConnectors = true;
|
|
112550
|
+
}
|
|
112551
|
+
if (proxyAuthMode && !("forceLoginMethod" in userSettings)) {
|
|
112552
|
+
userSettings.forceLoginMethod = "console";
|
|
112553
|
+
}
|
|
112554
|
+
if (paneChild && !("skipDangerousModePermissionPrompt" in userSettings)) {
|
|
112555
|
+
userSettings.skipDangerousModePermissionPrompt = true;
|
|
112556
|
+
}
|
|
112557
|
+
if (paneChild) {
|
|
112558
|
+
userSettings.editorMode = "normal";
|
|
112559
|
+
}
|
|
112560
|
+
if (paneChild) {
|
|
112561
|
+
userSettings.wheelScrollAccelerationEnabled = false;
|
|
112562
|
+
}
|
|
112563
|
+
if (paneChild) {
|
|
112564
|
+
userSettings.tui = "fullscreen";
|
|
112565
|
+
}
|
|
112566
|
+
}
|
|
112567
|
+
function mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, proxyAuthMode, paneChild = isPaneChild(), modelPicker) {
|
|
112568
|
+
if (modelPicker) {
|
|
112569
|
+
mergeEverySettingsArg(config, tempSettingsPath, statusLine, proxyAuthMode, paneChild, modelPicker);
|
|
112570
|
+
return;
|
|
112571
|
+
}
|
|
112221
112572
|
const idx = config.claudeArgs.indexOf("--settings");
|
|
112222
112573
|
if (idx === -1 || !config.claudeArgs[idx + 1]) {
|
|
112223
112574
|
return;
|
|
@@ -112225,25 +112576,7 @@ function mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, proxyA
|
|
|
112225
112576
|
const userSettingsValue = config.claudeArgs[idx + 1];
|
|
112226
112577
|
try {
|
|
112227
112578
|
const userSettings = parseSettingsArg(userSettingsValue);
|
|
112228
|
-
userSettings
|
|
112229
|
-
if (!("disableClaudeAiConnectors" in userSettings)) {
|
|
112230
|
-
userSettings.disableClaudeAiConnectors = true;
|
|
112231
|
-
}
|
|
112232
|
-
if (proxyAuthMode && !("forceLoginMethod" in userSettings)) {
|
|
112233
|
-
userSettings.forceLoginMethod = "console";
|
|
112234
|
-
}
|
|
112235
|
-
if (paneChild && !("skipDangerousModePermissionPrompt" in userSettings)) {
|
|
112236
|
-
userSettings.skipDangerousModePermissionPrompt = true;
|
|
112237
|
-
}
|
|
112238
|
-
if (paneChild) {
|
|
112239
|
-
userSettings.editorMode = "normal";
|
|
112240
|
-
}
|
|
112241
|
-
if (paneChild) {
|
|
112242
|
-
userSettings.wheelScrollAccelerationEnabled = false;
|
|
112243
|
-
}
|
|
112244
|
-
if (paneChild) {
|
|
112245
|
-
userSettings.tui = "fullscreen";
|
|
112246
|
-
}
|
|
112579
|
+
applyClaudishSettingsKeys(userSettings, statusLine, proxyAuthMode, paneChild);
|
|
112247
112580
|
chmodSync5(tempSettingsPath, 384);
|
|
112248
112581
|
writeFileSync20(tempSettingsPath, JSON.stringify(userSettings, null, 2), {
|
|
112249
112582
|
encoding: "utf-8",
|
|
@@ -112256,6 +112589,45 @@ function mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, proxyA
|
|
|
112256
112589
|
}
|
|
112257
112590
|
config.claudeArgs.splice(idx, 2);
|
|
112258
112591
|
}
|
|
112592
|
+
function mergeEverySettingsArg(config, tempSettingsPath, statusLine, proxyAuthMode, paneChild, modelPicker) {
|
|
112593
|
+
const occurrences = settingsArgOccurrences(config.claudeArgs);
|
|
112594
|
+
if (occurrences.length === 0)
|
|
112595
|
+
return;
|
|
112596
|
+
const merged = {};
|
|
112597
|
+
let mergedAny = false;
|
|
112598
|
+
occurrences.forEach((occurrence, i) => {
|
|
112599
|
+
if (!occurrence.value)
|
|
112600
|
+
return;
|
|
112601
|
+
const label = occurrences.length > 1 ? `--settings (occurrence ${i + 1})` : "--settings";
|
|
112602
|
+
const parsed = parseSettingsArgSafe(occurrence.value);
|
|
112603
|
+
if (parsed === null || Array.isArray(parsed)) {
|
|
112604
|
+
if (!config.quiet)
|
|
112605
|
+
console.warn(`[claudish] Warning: could not merge user settings: ${label}`);
|
|
112606
|
+
return;
|
|
112607
|
+
}
|
|
112608
|
+
Object.assign(merged, parsed);
|
|
112609
|
+
mergedAny = true;
|
|
112610
|
+
});
|
|
112611
|
+
if (mergedAny) {
|
|
112612
|
+
applyClaudishSettingsKeys(merged, statusLine, proxyAuthMode, paneChild);
|
|
112613
|
+
merged.modelPicker = modelPicker;
|
|
112614
|
+
try {
|
|
112615
|
+
chmodSync5(tempSettingsPath, 384);
|
|
112616
|
+
writeFileSync20(tempSettingsPath, JSON.stringify(merged, null, 2), {
|
|
112617
|
+
encoding: "utf-8",
|
|
112618
|
+
mode: 384
|
|
112619
|
+
});
|
|
112620
|
+
} catch {
|
|
112621
|
+
if (!config.quiet) {
|
|
112622
|
+
console.warn("[claudish] Warning: could not write the merged --settings file");
|
|
112623
|
+
}
|
|
112624
|
+
}
|
|
112625
|
+
}
|
|
112626
|
+
for (const occurrence of [...occurrences].reverse()) {
|
|
112627
|
+
const width = occurrence.spelling === "separate" && occurrence.value !== undefined ? 2 : 1;
|
|
112628
|
+
config.claudeArgs.splice(occurrence.index, width);
|
|
112629
|
+
}
|
|
112630
|
+
}
|
|
112259
112631
|
async function resolveLocalContextWindow(spec, cachePath) {
|
|
112260
112632
|
const parsed = parseModelSpec(spec);
|
|
112261
112633
|
let provider = parsed.provider;
|
|
@@ -112336,12 +112708,9 @@ function resolveAdvisorToolEnv(config, processEnv = process.env) {
|
|
|
112336
112708
|
return { vars: {}, source: "inherited" };
|
|
112337
112709
|
return { vars: { [ADVISOR_TOOL_ENV_VAR]: "1" }, source: "claudish" };
|
|
112338
112710
|
}
|
|
112339
|
-
function discoverUserAdvisorModel(claudeArgs = [], cwd = process.cwd()) {
|
|
112711
|
+
function discoverUserAdvisorModel(claudeArgs = [], cwd = process.cwd(), scope = "first") {
|
|
112340
112712
|
const sources = userSettingsFileCandidates(cwd).filter((file) => existsSync37(file));
|
|
112341
|
-
|
|
112342
|
-
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
112343
|
-
if (settingsArg)
|
|
112344
|
-
sources.push(settingsArg);
|
|
112713
|
+
sources.push(...settingsArgValues(claudeArgs, scope));
|
|
112345
112714
|
const managed = managedSettingsPath();
|
|
112346
112715
|
if (existsSync37(managed))
|
|
112347
112716
|
sources.push(managed);
|
|
@@ -112358,7 +112727,7 @@ function discoverUserAdvisorModel(claudeArgs = [], cwd = process.cwd()) {
|
|
|
112358
112727
|
function resolveAdvisorModelArg(config, cwd = process.cwd()) {
|
|
112359
112728
|
if (!config.advisor)
|
|
112360
112729
|
return { args: [], source: "off" };
|
|
112361
|
-
const userChoice = discoverUserAdvisorModel(config.claudeArgs, cwd);
|
|
112730
|
+
const userChoice = discoverUserAdvisorModel(config.claudeArgs, cwd, settingsArgScopeOf(config));
|
|
112362
112731
|
if (userChoice)
|
|
112363
112732
|
return { args: [], model: userChoice, source: "inherited" };
|
|
112364
112733
|
return {
|
|
@@ -112407,10 +112776,29 @@ function relayChildStderr(stream) {
|
|
|
112407
112776
|
logStderr(`child stderr relay ended: ${err}`);
|
|
112408
112777
|
});
|
|
112409
112778
|
}
|
|
112410
|
-
|
|
112779
|
+
function childModelIdOf(config) {
|
|
112411
112780
|
const hasProfileMappings = config.modelOpus || config.modelSonnet || config.modelHaiku || config.modelSubagent;
|
|
112781
|
+
return config.model || (hasProfileMappings || config.monitor || isAdvisorNativeSession(config) || startsOnClaudeSubscription(config) ? undefined : "unknown");
|
|
112782
|
+
}
|
|
112783
|
+
function childModelVarsFor(config) {
|
|
112784
|
+
const modelId = childModelIdOf(config);
|
|
112785
|
+
const id = config.monitor || isAdvisorNativeSession(config) ? config.claudeLaunchModel ?? modelId : modelId;
|
|
112786
|
+
if (!id)
|
|
112787
|
+
return {};
|
|
112788
|
+
if ((config.modelListings?.length ?? 0) > 0)
|
|
112789
|
+
return { ANTHROPIC_MODEL: id };
|
|
112790
|
+
return { ANTHROPIC_MODEL: id, ANTHROPIC_SMALL_FAST_MODEL: id };
|
|
112791
|
+
}
|
|
112792
|
+
function childKeepsLogin(config) {
|
|
112793
|
+
return !isProxyAuthMode(config) && config.claudeLaunch !== "api";
|
|
112794
|
+
}
|
|
112795
|
+
function scrubChildModelVars(config, env) {
|
|
112796
|
+
const set = childModelVarsFor(config);
|
|
112797
|
+
return scrubInheritedModelVars(env, { model: Boolean(set.ANTHROPIC_MODEL), smallFast: Boolean(set.ANTHROPIC_SMALL_FAST_MODEL) }, { keepsLogin: childKeepsLogin(config) });
|
|
112798
|
+
}
|
|
112799
|
+
async function runClaudeWithProxy(config, proxyUrl, onCleanup, hooks = {}) {
|
|
112412
112800
|
const advisorNativeSession = isAdvisorNativeSession(config);
|
|
112413
|
-
const modelId =
|
|
112801
|
+
const modelId = childModelIdOf(config);
|
|
112414
112802
|
const portMatch = proxyUrl.match(/:(\d+)/);
|
|
112415
112803
|
const port = portMatch ? portMatch[1] : "unknown";
|
|
112416
112804
|
const proxyAuthMode = isProxyAuthMode(config);
|
|
@@ -112434,15 +112822,16 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112434
112822
|
if (!gatewayEligible && globalConfig.harnessGateway !== undefined) {
|
|
112435
112823
|
log(gatewayHeldOff ? `[claude-runner] harnessGateway ignored: ${HARNESS_GATEWAY_OFF_VAR}=1` : "[claude-runner] harnessGateway ignored: a monitor session keeps the proxy URL");
|
|
112436
112824
|
}
|
|
112437
|
-
const userStatusLineCommand = discoverUserStatusLineCommand(config.claudeArgs);
|
|
112825
|
+
const userStatusLineCommand = discoverUserStatusLineCommand(config.claudeArgs, process.cwd(), settingsArgScopeOf(config));
|
|
112438
112826
|
const advisorModelArg = resolveAdvisorModelArg(config);
|
|
112827
|
+
const modelPicker = config.modelLineup?.picker;
|
|
112439
112828
|
const {
|
|
112440
112829
|
path: tempSettingsPath,
|
|
112441
112830
|
statusLine,
|
|
112442
112831
|
tokenFilePath
|
|
112443
|
-
} = createTempSettingsFile(modelId ?? "default", port, forceConsoleLogin, userStatusLineCommand);
|
|
112444
|
-
const signalShutdown = setupSignalHandlers(tempSettingsPath, config.quiet, onCleanup);
|
|
112445
|
-
mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, forceConsoleLogin);
|
|
112832
|
+
} = createTempSettingsFile(modelId ?? "default", port, forceConsoleLogin, userStatusLineCommand, modelPicker);
|
|
112833
|
+
const signalShutdown = setupSignalHandlers(tempSettingsPath, config.quiet, onCleanup, hooks.onDeadline);
|
|
112834
|
+
mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, forceConsoleLogin, isPaneChild(), modelPicker);
|
|
112446
112835
|
const claudeArgs = [];
|
|
112447
112836
|
claudeArgs.push("--settings", tempSettingsPath);
|
|
112448
112837
|
claudeArgs.push(...advisorModelArg.args);
|
|
@@ -112513,6 +112902,11 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112513
112902
|
if (!config.interactive && env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC === undefined) {
|
|
112514
112903
|
env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
|
|
112515
112904
|
}
|
|
112905
|
+
const childModelVars = childModelVarsFor(config);
|
|
112906
|
+
const inheritedModelVars = scrubChildModelVars(config, env);
|
|
112907
|
+
if (inheritedModelVars.removed.length > 0) {
|
|
112908
|
+
log(`[claude-runner] Removed inherited model variables claudish set: ${inheritedModelVars.removed.join(", ")}`);
|
|
112909
|
+
}
|
|
112516
112910
|
if (config.monitor || advisorNativeSession) {
|
|
112517
112911
|
delete env.ANTHROPIC_API_KEY;
|
|
112518
112912
|
delete env.ANTHROPIC_AUTH_TOKEN;
|
|
@@ -112522,19 +112916,12 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112522
112916
|
env.ANTHROPIC_AUTH_TOKEN = CLAUDISH_PLACEHOLDER_AUTH_TOKEN;
|
|
112523
112917
|
applyHostManagedMarker(env);
|
|
112524
112918
|
}
|
|
112525
|
-
|
|
112526
|
-
if (launchModelId) {
|
|
112527
|
-
env[ENV.ANTHROPIC_MODEL] = launchModelId;
|
|
112528
|
-
env[ENV.ANTHROPIC_SMALL_FAST_MODEL] = launchModelId;
|
|
112529
|
-
}
|
|
112919
|
+
recordModelVars(env, childModelVars);
|
|
112530
112920
|
if (config.claudeLaunch) {
|
|
112531
112921
|
log(claudeLaunchAuthLine(config.claudeLaunch, env, config.claudeLaunchKeySource));
|
|
112532
112922
|
}
|
|
112533
112923
|
} else {
|
|
112534
|
-
|
|
112535
|
-
env[ENV.ANTHROPIC_MODEL] = modelId;
|
|
112536
|
-
env[ENV.ANTHROPIC_SMALL_FAST_MODEL] = modelId;
|
|
112537
|
-
}
|
|
112924
|
+
recordModelVars(env, childModelVars);
|
|
112538
112925
|
if (shouldPreserveNativeAuth(config)) {
|
|
112539
112926
|
const scrubbed = scrubInheritedClaudishPlaceholders(env);
|
|
112540
112927
|
if (scrubbed.removed.length > 0) {
|
|
@@ -112556,7 +112943,7 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112556
112943
|
applyProxyPlaceholderAuth(env);
|
|
112557
112944
|
applyProxyFastModeGates(env);
|
|
112558
112945
|
applyHostRouting(env);
|
|
112559
|
-
const realWindow = await computeMainThreadContextWindow(config);
|
|
112946
|
+
const realWindow = config.mainThreadWindow ?? await computeMainThreadContextWindow(config);
|
|
112560
112947
|
const contextEnv = resolveContextWindowEnv(realWindow, process.env);
|
|
112561
112948
|
seedTokenFileWindow(resolveTokenFilePath(port), realWindow);
|
|
112562
112949
|
Object.assign(env, contextEnv.vars);
|
|
@@ -112600,6 +112987,7 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112600
112987
|
`);
|
|
112601
112988
|
}
|
|
112602
112989
|
const claudeBinary = await findClaudeBinary();
|
|
112990
|
+
await hooks.beforeSpawn?.(tempSettingsPath);
|
|
112603
112991
|
const stoppedBeforeSpawn = signalShutdownExitCode();
|
|
112604
112992
|
if (stoppedBeforeSpawn !== null) {
|
|
112605
112993
|
signalShutdown.removeSettingsFile();
|
|
@@ -112668,6 +113056,13 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
112668
113056
|
shell: needsShell
|
|
112669
113057
|
});
|
|
112670
113058
|
signalShutdown.attachClaudeCode(proc);
|
|
113059
|
+
if (proc.pid !== undefined) {
|
|
113060
|
+
try {
|
|
113061
|
+
hooks.onChildSpawned?.(proc.pid);
|
|
113062
|
+
} catch (err) {
|
|
113063
|
+
log2(`[claudish] onChildSpawned hook failed: ${err}`);
|
|
113064
|
+
}
|
|
113065
|
+
}
|
|
112671
113066
|
if (wrap) {
|
|
112672
113067
|
wrap.watch(proc);
|
|
112673
113068
|
}
|
|
@@ -112767,7 +113162,7 @@ function sessionOutcomeOf(exitCode) {
|
|
|
112767
113162
|
function signalShutdownExitCode() {
|
|
112768
113163
|
return signalShutdownCode;
|
|
112769
113164
|
}
|
|
112770
|
-
function setupSignalHandlers(tempSettingsPath, quiet, onCleanup) {
|
|
113165
|
+
function setupSignalHandlers(tempSettingsPath, quiet, onCleanup, onDeadline) {
|
|
112771
113166
|
const signals = isWindows2() ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
112772
113167
|
let shuttingDown = null;
|
|
112773
113168
|
let claudeCode = null;
|
|
@@ -112806,6 +113201,9 @@ function setupSignalHandlers(tempSettingsPath, quiet, onCleanup) {
|
|
|
112806
113201
|
const armDeadline = (code) => {
|
|
112807
113202
|
const deadline = setTimeout(() => {
|
|
112808
113203
|
log(`[claudish] Signal shutdown passed ${SIGNAL_SHUTDOWN_BUDGET_MS} ms; exiting`);
|
|
113204
|
+
try {
|
|
113205
|
+
onDeadline?.();
|
|
113206
|
+
} catch {}
|
|
112809
113207
|
try {
|
|
112810
113208
|
onCleanup?.();
|
|
112811
113209
|
} catch {}
|
|
@@ -112914,7 +113312,7 @@ async function checkClaudeInstalled() {
|
|
|
112914
113312
|
const binary = await findClaudeBinary();
|
|
112915
113313
|
return binary !== null;
|
|
112916
113314
|
}
|
|
112917
|
-
var restoreTerminal = null, SETTINGS_TIER_ORDER, STALE_TOKEN_FILE_MS, MAX_TOKEN_FILES_SCANNED = 4000, CLAUDE_CODE_DEFAULT_MAX_CONTEXT = 200000, USER_STATUS_LINE_TIMEOUT_SECONDS = 3, MIN_AUTO_COMPACT_WINDOW = 200000, MAX_AUTO_COMPACT_WINDOW = 1e6, ADVISOR_TOOL_ENV_VAR = "CLAUDE_CODE_ENABLE_EXPERIMENTAL_ADVISOR_TOOL", CLAUDISH_CHILD_ADVISOR_MODEL = "sonnet", CHILD_STDERR_NOISE, SIGNAL_CHILD_EXIT_GRACE_MS = 2000, SIGNAL_CHILD_KILL_WAIT_MS = 500, SIGNAL_DESCENDANT_READ_MS = 200, SIGNAL_SHUTDOWN_BUDGET_MS = 4500, signalShutdownCode = null;
|
|
113315
|
+
var restoreTerminal = null, SETTINGS_TIER_ORDER, NON_MANAGED_TIER_RANK, STALE_TOKEN_FILE_MS, MAX_TOKEN_FILES_SCANNED = 4000, CLAUDE_CODE_DEFAULT_MAX_CONTEXT = 200000, USER_STATUS_LINE_TIMEOUT_SECONDS = 3, MIN_AUTO_COMPACT_WINDOW = 200000, MAX_AUTO_COMPACT_WINDOW = 1e6, ADVISOR_TOOL_ENV_VAR = "CLAUDE_CODE_ENABLE_EXPERIMENTAL_ADVISOR_TOOL", CLAUDISH_CHILD_ADVISOR_MODEL = "sonnet", CHILD_STDERR_NOISE, SIGNAL_CHILD_EXIT_GRACE_MS = 2000, SIGNAL_CHILD_KILL_WAIT_MS = 500, SIGNAL_DESCENDANT_READ_MS = 200, SIGNAL_SHUTDOWN_BUDGET_MS = 4500, signalShutdownCode = null;
|
|
112918
113316
|
var init_claude_runner = __esm(() => {
|
|
112919
113317
|
init_model_catalog();
|
|
112920
113318
|
init_claude_code_login();
|
|
@@ -112930,6 +113328,7 @@ var init_claude_runner = __esm(() => {
|
|
|
112930
113328
|
init_host_routing_env();
|
|
112931
113329
|
init_magmux_wrapper();
|
|
112932
113330
|
init_logger();
|
|
113331
|
+
init_model_vars_env();
|
|
112933
113332
|
init_child_env();
|
|
112934
113333
|
init_pane_launch();
|
|
112935
113334
|
init_process_tree();
|
|
@@ -112949,6 +113348,12 @@ var init_claude_runner = __esm(() => {
|
|
|
112949
113348
|
init_terminal_isolation();
|
|
112950
113349
|
init_theme_mode();
|
|
112951
113350
|
SETTINGS_TIER_ORDER = ["managed", "cli", "local", "project", "user"];
|
|
113351
|
+
NON_MANAGED_TIER_RANK = {
|
|
113352
|
+
user: 0,
|
|
113353
|
+
project: 1,
|
|
113354
|
+
local: 2,
|
|
113355
|
+
cli: 3
|
|
113356
|
+
};
|
|
112952
113357
|
STALE_TOKEN_FILE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
112953
113358
|
CHILD_STDERR_NOISE = [/^\[claude-code:unrecognized_model\]/];
|
|
112954
113359
|
});
|
|
@@ -117792,7 +118197,7 @@ function writeRecord(root, rec) {
|
|
|
117792
118197
|
`, { mode: 384 });
|
|
117793
118198
|
renameSync12(tmp, p);
|
|
117794
118199
|
}
|
|
117795
|
-
function
|
|
118200
|
+
function readRecord2(root, paneId) {
|
|
117796
118201
|
if (!isValidPaneId(paneId))
|
|
117797
118202
|
return null;
|
|
117798
118203
|
try {
|
|
@@ -117802,7 +118207,7 @@ function readRecord(root, paneId) {
|
|
|
117802
118207
|
}
|
|
117803
118208
|
}
|
|
117804
118209
|
function updateRecord(root, paneId, patch) {
|
|
117805
|
-
const rec =
|
|
118210
|
+
const rec = readRecord2(root, paneId);
|
|
117806
118211
|
if (rec)
|
|
117807
118212
|
writeRecord(root, { ...rec, ...patch });
|
|
117808
118213
|
}
|
|
@@ -117859,7 +118264,7 @@ function readRecords(root) {
|
|
|
117859
118264
|
}
|
|
117860
118265
|
const out = [];
|
|
117861
118266
|
for (const n of names) {
|
|
117862
|
-
const rec =
|
|
118267
|
+
const rec = readRecord2(root, n.slice(0, -".json".length));
|
|
117863
118268
|
if (rec)
|
|
117864
118269
|
out.push(rec);
|
|
117865
118270
|
}
|
|
@@ -124211,6 +124616,15 @@ function launchSigningFor(config, deps = {}) {
|
|
|
124211
124616
|
const wantsApiBilling = deps.wantsApiBilling ?? ((c) => wantsAnthropicApiBilling(c));
|
|
124212
124617
|
return wantsApiBilling(config) ? undefined : LOGIN_ONLY_SIGNING;
|
|
124213
124618
|
}
|
|
124619
|
+
function claudeRowsAsPicked(config) {
|
|
124620
|
+
if ((config.modelListings?.length ?? 0) === 0)
|
|
124621
|
+
return false;
|
|
124622
|
+
if (isProxyAuthMode(config))
|
|
124623
|
+
return false;
|
|
124624
|
+
if (typeof config.model !== "string" || config.model.length === 0)
|
|
124625
|
+
return true;
|
|
124626
|
+
return nativeRouteFor(config.model) !== null;
|
|
124627
|
+
}
|
|
124214
124628
|
function advisorKeyLookupAllowed(config, deps = {}) {
|
|
124215
124629
|
const tiers = [config.modelOpus, config.modelSonnet, config.modelHaiku, config.modelSubagent];
|
|
124216
124630
|
const hasMainModel = (config.modelChain?.length ?? 0) > 0 || Boolean(config.model) || tiers.some((m) => typeof m === "string" && m.length > 0);
|
|
@@ -124261,6 +124675,11 @@ function subscriptionPrefix(cause) {
|
|
|
124261
124675
|
return cause ? `${CLAUDE_SUBSCRIPTION_LABEL}, ${cause}` : CLAUDE_SUBSCRIPTION_LABEL;
|
|
124262
124676
|
}
|
|
124263
124677
|
function subscriptionCause(config) {
|
|
124678
|
+
if (startsOnClaudeSubscription(config)) {
|
|
124679
|
+
const typed = (config.modelListings ?? []).map((listing) => listing.typed);
|
|
124680
|
+
const verb = typed.length === 1 ? "names" : "name";
|
|
124681
|
+
return `because --model ${typed.join(", ")} ${verb} no start model, so the session starts on Claude's default model`;
|
|
124682
|
+
}
|
|
124264
124683
|
const main = typeof config.model === "string" ? config.model : undefined;
|
|
124265
124684
|
if (main && nativeRouteFor(main) !== null)
|
|
124266
124685
|
return;
|
|
@@ -124369,7 +124788,8 @@ function decideClaudeLaunch(config, deps = {}) {
|
|
|
124369
124788
|
}
|
|
124370
124789
|
if (!isClaudeSubscriptionSpec2(main))
|
|
124371
124790
|
return { ok: true };
|
|
124372
|
-
|
|
124791
|
+
const hasListings = (config.modelListings?.length ?? 0) > 0;
|
|
124792
|
+
if (hasListings || (deps.paneChild ?? isPaneChild())) {
|
|
124373
124793
|
config.model = normalizeNativeModelSpec(claudeSubscriptionInner(main));
|
|
124374
124794
|
config.claudeSubscriptionPin = true;
|
|
124375
124795
|
return { ok: true };
|
|
@@ -124381,6 +124801,113 @@ function decideClaudeLaunch(config, deps = {}) {
|
|
|
124381
124801
|
config.claudeLaunch = "subscription";
|
|
124382
124802
|
return { ok: true };
|
|
124383
124803
|
}
|
|
124804
|
+
function listingProviderRefusal(typed, provider) {
|
|
124805
|
+
if (provider === "native-anthropic") {
|
|
124806
|
+
return `--model ${typed}: Claude Code lists the Claude subscription's models in /model already, so claude@ cannot be a listing entry.`;
|
|
124807
|
+
}
|
|
124808
|
+
if (provider === "custom-url") {
|
|
124809
|
+
return `--model ${typed}: a raw URL has no model list. Declare the endpoint under customEndpoints and list it by name (--model <name>@).`;
|
|
124810
|
+
}
|
|
124811
|
+
return null;
|
|
124812
|
+
}
|
|
124813
|
+
function unknownShortcutRefusal(shortcut, typed) {
|
|
124814
|
+
const { reason, hint } = describeUnknownShortcut(shortcut, "", undefined, typed);
|
|
124815
|
+
return `${reason} ${hint}`;
|
|
124816
|
+
}
|
|
124817
|
+
function unreadableSettingsRefusal(config, deps) {
|
|
124818
|
+
const unreadable = (deps.unreadableSettings ?? ((c) => unreadableSettingsArgs(c)))(config);
|
|
124819
|
+
if (unreadable.length === 0)
|
|
124820
|
+
return null;
|
|
124821
|
+
const which = unreadable.length === 1 ? `occurrence ${unreadable[0]}` : `occurrences ${unreadable.join(", ")}`;
|
|
124822
|
+
return `claudish cannot read --settings (${which}); a /model lineup merges every --settings into ` + `one file. Fix or remove ${unreadable.length === 1 ? "it" : "them"}.`;
|
|
124823
|
+
}
|
|
124824
|
+
function settingsBaseUrlRefusal(config, deps) {
|
|
124825
|
+
const keepsLogin = deps.keepsLogin ?? ((c) => !isProxyAuthMode(c));
|
|
124826
|
+
if (!keepsLogin(config))
|
|
124827
|
+
return null;
|
|
124828
|
+
const findingsOf = deps.settingsFindings ?? ((c) => settingsCredentialFindings(c, process.env));
|
|
124829
|
+
const files = [
|
|
124830
|
+
...new Set(findingsOf(config).filter((finding) => finding.kind === "base-url").map((finding) => finding.where))
|
|
124831
|
+
];
|
|
124832
|
+
if (files.length === 0)
|
|
124833
|
+
return null;
|
|
124834
|
+
const classifierOn = deps.classifierPassthrough ?? ((c) => classifierPassthroughEnabled(c));
|
|
124835
|
+
const classifierIsCause = !hasNativeAnthropicMapping(config) && classifierOn(config);
|
|
124836
|
+
const remedy = classifierIsCause ? "launch without classifier passthrough." : "start on a foreign model (--model <provider>@<id>), whose launch claudish routes.";
|
|
124837
|
+
return `${files.join(", ")} ${files.length === 1 ? "sets" : "set"} ANTHROPIC_BASE_URL, so /model picks ` + `would bypass claudish. Remove ${files.length === 1 ? "it" : "them"}, or ${remedy}`;
|
|
124838
|
+
}
|
|
124839
|
+
function decideModelListings(config, parsed, deps = {}) {
|
|
124840
|
+
if (!parsed?.hasLineup)
|
|
124841
|
+
return { ok: true };
|
|
124842
|
+
const isKnown = deps.isKnownProvider ?? isKnownProviderName;
|
|
124843
|
+
if (config.monitor) {
|
|
124844
|
+
return {
|
|
124845
|
+
ok: false,
|
|
124846
|
+
message: "--monitor cannot be combined with a listing entry (--model <provider>@): a monitor session sends every request to Anthropic, so no listed model could be routed."
|
|
124847
|
+
};
|
|
124848
|
+
}
|
|
124849
|
+
const start = parsed.start;
|
|
124850
|
+
if (start && isClaudeApiSpec(start)) {
|
|
124851
|
+
return {
|
|
124852
|
+
ok: false,
|
|
124853
|
+
message: `--model ${start} starts a Claude API session that forwards every request to Anthropic, so no listed model could be routed. Start on another model, or drop the listing entries.`
|
|
124854
|
+
};
|
|
124855
|
+
}
|
|
124856
|
+
const byProvider = new Map;
|
|
124857
|
+
const add = (provider, typed, scope) => {
|
|
124858
|
+
const existing = byProvider.get(provider);
|
|
124859
|
+
if (existing) {
|
|
124860
|
+
if (scope === "all")
|
|
124861
|
+
existing.scope = "all";
|
|
124862
|
+
return existing;
|
|
124863
|
+
}
|
|
124864
|
+
const listing = { provider, typed, scope, pinnedSpecs: [] };
|
|
124865
|
+
byProvider.set(provider, listing);
|
|
124866
|
+
return listing;
|
|
124867
|
+
};
|
|
124868
|
+
if (start) {
|
|
124869
|
+
const parsedStart = parseModelSpec(start);
|
|
124870
|
+
if (parsedStart.isExplicitProvider && listingProviderRefusal(start, parsedStart.provider) === null && isKnown(typedShortcutOf(start))) {
|
|
124871
|
+
add(parsedStart.provider, start, "recommended").pinnedSpecs.push(start);
|
|
124872
|
+
}
|
|
124873
|
+
}
|
|
124874
|
+
for (const entry of parsed.listings) {
|
|
124875
|
+
const typed = `${entry.shortcut}@${entry.scope === "all" ? "*" : ""}`;
|
|
124876
|
+
if (!isKnown(entry.shortcut)) {
|
|
124877
|
+
return { ok: false, message: unknownShortcutRefusal(entry.shortcut, typed) };
|
|
124878
|
+
}
|
|
124879
|
+
const provider = parseModelSpec(`${entry.shortcut}@x`).provider;
|
|
124880
|
+
const refusal = listingProviderRefusal(typed, provider);
|
|
124881
|
+
if (refusal)
|
|
124882
|
+
return { ok: false, message: refusal };
|
|
124883
|
+
const listing = add(provider, typed, entry.scope);
|
|
124884
|
+
if (listing.typed === start)
|
|
124885
|
+
listing.typed = typed;
|
|
124886
|
+
}
|
|
124887
|
+
for (const spec of parsed.pinned) {
|
|
124888
|
+
const shortcut = typedShortcutOf(spec);
|
|
124889
|
+
if (!isKnown(shortcut)) {
|
|
124890
|
+
const parsedPin = parseModelSpec(spec);
|
|
124891
|
+
const { reason, hint } = describeUnknownShortcut(shortcut, parsedPin.model, undefined, spec);
|
|
124892
|
+
return { ok: false, message: `${reason} ${hint}` };
|
|
124893
|
+
}
|
|
124894
|
+
const provider = parseModelSpec(spec).provider;
|
|
124895
|
+
const refusal = listingProviderRefusal(spec, provider);
|
|
124896
|
+
if (refusal)
|
|
124897
|
+
return { ok: false, message: refusal };
|
|
124898
|
+
add(provider, spec, "recommended").pinnedSpecs.push(spec);
|
|
124899
|
+
}
|
|
124900
|
+
const settingsRefusal = unreadableSettingsRefusal(config, deps);
|
|
124901
|
+
if (settingsRefusal)
|
|
124902
|
+
return { ok: false, message: settingsRefusal };
|
|
124903
|
+
config.modelListings = [...byProvider.values()];
|
|
124904
|
+
const baseUrlRefusal = settingsBaseUrlRefusal(config, deps);
|
|
124905
|
+
if (baseUrlRefusal) {
|
|
124906
|
+
delete config.modelListings;
|
|
124907
|
+
return { ok: false, message: baseUrlRefusal };
|
|
124908
|
+
}
|
|
124909
|
+
return { ok: true };
|
|
124910
|
+
}
|
|
124384
124911
|
function effectiveStartupCredential(config, env, deps) {
|
|
124385
124912
|
const credentialOf = deps.claudeCodeCredential ?? ((e) => claudeCodeStartupCredential({ env: e }));
|
|
124386
124913
|
const fromSettings = (deps.settingsLoginToken ?? settingsClaudeLoginToken)(config, env);
|
|
@@ -124528,6 +125055,7 @@ var init_claude_launch = __esm(() => {
|
|
|
124528
125055
|
init_model_parser();
|
|
124529
125056
|
init_native_route();
|
|
124530
125057
|
init_shadowed_endpoint();
|
|
125058
|
+
init_unknown_shortcut();
|
|
124531
125059
|
init_redact();
|
|
124532
125060
|
TIER_FIELDS = [
|
|
124533
125061
|
["opus", "modelOpus"],
|
|
@@ -124567,6 +125095,7 @@ function claudeCodePrintEnv(parent) {
|
|
|
124567
125095
|
scrubInheritedFastModeGates(env);
|
|
124568
125096
|
scrubInheritedHostRouting(env);
|
|
124569
125097
|
scrubInheritedHarnessGatewayTarget(env);
|
|
125098
|
+
scrubInheritedModelVars(env, { model: false, smallFast: false }, { keepsLogin: true });
|
|
124570
125099
|
return env;
|
|
124571
125100
|
}
|
|
124572
125101
|
function isFrame(v) {
|
|
@@ -124772,6 +125301,7 @@ var init_run_prompt_claude_code = __esm(() => {
|
|
|
124772
125301
|
init_harness_gateway();
|
|
124773
125302
|
init_host_routing_env();
|
|
124774
125303
|
init_claude_launch();
|
|
125304
|
+
init_model_vars_env();
|
|
124775
125305
|
init_child_env();
|
|
124776
125306
|
init_pane_launch();
|
|
124777
125307
|
init_redact();
|
|
@@ -141565,6 +142095,578 @@ var init_tui = __esm(() => {
|
|
|
141565
142095
|
}
|
|
141566
142096
|
});
|
|
141567
142097
|
|
|
142098
|
+
// src/launcher/model-lineup.ts
|
|
142099
|
+
function redactAndTruncate(text, max) {
|
|
142100
|
+
const redacted = redactSecrets(text);
|
|
142101
|
+
if (redacted.length <= max)
|
|
142102
|
+
return redacted;
|
|
142103
|
+
let cut = max - 1;
|
|
142104
|
+
for (const marker of REDACTION_MARKERS) {
|
|
142105
|
+
let at = redacted.indexOf(marker);
|
|
142106
|
+
while (at >= 0 && at < cut) {
|
|
142107
|
+
if (at + marker.length > cut) {
|
|
142108
|
+
cut = at;
|
|
142109
|
+
break;
|
|
142110
|
+
}
|
|
142111
|
+
at = redacted.indexOf(marker, at + marker.length);
|
|
142112
|
+
}
|
|
142113
|
+
}
|
|
142114
|
+
return `${redacted.slice(0, cut).trimEnd()}\u2026`;
|
|
142115
|
+
}
|
|
142116
|
+
function rowKey(spec) {
|
|
142117
|
+
const parsed = parseModelSpec(spec);
|
|
142118
|
+
return [
|
|
142119
|
+
parsed.provider,
|
|
142120
|
+
parsed.model,
|
|
142121
|
+
parsed.mode ?? "",
|
|
142122
|
+
parsed.speed ?? "",
|
|
142123
|
+
parsed.concurrency ?? ""
|
|
142124
|
+
].join("\x00");
|
|
142125
|
+
}
|
|
142126
|
+
function lineupSpecFor(provider, wireId) {
|
|
142127
|
+
const spec = buildExplicitModelSpec(provider, wireId);
|
|
142128
|
+
const parsed = parseModelSpec(spec);
|
|
142129
|
+
if (parsed.isExplicitProvider && parsed.provider === provider)
|
|
142130
|
+
return spec;
|
|
142131
|
+
return `${provider}@${wireId}`;
|
|
142132
|
+
}
|
|
142133
|
+
function lineupProviderName(provider) {
|
|
142134
|
+
try {
|
|
142135
|
+
const choice = buildProviderChoices().find((c) => c.value === provider);
|
|
142136
|
+
if (choice)
|
|
142137
|
+
return choice.name;
|
|
142138
|
+
} catch {}
|
|
142139
|
+
return getDisplayName(provider);
|
|
142140
|
+
}
|
|
142141
|
+
function priceLabel2(provider, isLocal, model) {
|
|
142142
|
+
if (isLocal)
|
|
142143
|
+
return "local";
|
|
142144
|
+
if (displayBillingOf(provider) === "sub")
|
|
142145
|
+
return "SUB";
|
|
142146
|
+
const price = resolveProviderDisplayPrice(provider, model);
|
|
142147
|
+
return price && price !== "N/A" ? price : undefined;
|
|
142148
|
+
}
|
|
142149
|
+
function rowFrom(provider, providerName, isLocal, spec, model, fallbackLabel) {
|
|
142150
|
+
const contextLength = model?.contextLength && model.contextLength > 0 ? model.contextLength : undefined;
|
|
142151
|
+
const parts = [providerName];
|
|
142152
|
+
if (contextLength)
|
|
142153
|
+
parts.push(`${formatContextLength(contextLength)} context`);
|
|
142154
|
+
const price = model ? priceLabel2(provider, isLocal, model) : isLocal ? "local" : undefined;
|
|
142155
|
+
if (price)
|
|
142156
|
+
parts.push(price);
|
|
142157
|
+
else if (!model && displayBillingOf(provider) === "sub")
|
|
142158
|
+
parts.push("SUB");
|
|
142159
|
+
return {
|
|
142160
|
+
model: spec,
|
|
142161
|
+
label: redactAndTruncate(model?.name || fallbackLabel, LINEUP_LABEL_MAX),
|
|
142162
|
+
description: redactAndTruncate(parts.join(" \xB7 "), LINEUP_DESCRIPTION_MAX),
|
|
142163
|
+
provider,
|
|
142164
|
+
...contextLength ? { contextLength } : {}
|
|
142165
|
+
};
|
|
142166
|
+
}
|
|
142167
|
+
function declaredModelInfo(id, providerName) {
|
|
142168
|
+
return { id, name: id, description: "", provider: providerName };
|
|
142169
|
+
}
|
|
142170
|
+
function allScopeHint(listing) {
|
|
142171
|
+
const at = listing.typed.indexOf("@");
|
|
142172
|
+
const shortcut = at > 0 ? listing.typed.slice(0, at) : listing.provider;
|
|
142173
|
+
return `'${shortcut}@*'`;
|
|
142174
|
+
}
|
|
142175
|
+
function discoveryEmptyReason(outcome) {
|
|
142176
|
+
switch (outcome.kind) {
|
|
142177
|
+
case "rows":
|
|
142178
|
+
return;
|
|
142179
|
+
case "failed":
|
|
142180
|
+
return describeDiscoveryFailure(outcome.failure);
|
|
142181
|
+
case "empty-models-catalog":
|
|
142182
|
+
return describeDiscoveryFailure(outcome.failure);
|
|
142183
|
+
case "all-filtered":
|
|
142184
|
+
return outcome.servedCount === 1 ? "it serves 1 model, not a chat model" : `it serves ${outcome.servedCount} models, none of them a chat model`;
|
|
142185
|
+
case "collapsed-empty":
|
|
142186
|
+
return "its model list yielded no rows";
|
|
142187
|
+
case "unsupported":
|
|
142188
|
+
return "it publishes no model list";
|
|
142189
|
+
}
|
|
142190
|
+
}
|
|
142191
|
+
function lineupRowsForProvider(input) {
|
|
142192
|
+
const { listing, tier, declared } = input;
|
|
142193
|
+
const source = candidateSource(input);
|
|
142194
|
+
let { candidates, emptyReason } = source;
|
|
142195
|
+
const isGatewayRecommended = tier === "gateway" && listing.scope === "recommended" && declared === null;
|
|
142196
|
+
if (isGatewayRecommended && (candidates.length > 0 || input.recommendedIds === null)) {
|
|
142197
|
+
const narrowed = recommendedCandidates(input, candidates);
|
|
142198
|
+
candidates = narrowed.candidates;
|
|
142199
|
+
emptyReason = narrowed.emptyReason ?? emptyReason;
|
|
142200
|
+
}
|
|
142201
|
+
const rows = assembleRows(input, candidates.filter((m) => m.supportsTools !== false));
|
|
142202
|
+
if (rows.length > 0)
|
|
142203
|
+
return { rows };
|
|
142204
|
+
return { rows, emptyReason: emptyReason ?? "it lists no chat models" };
|
|
142205
|
+
}
|
|
142206
|
+
function candidateSource(input) {
|
|
142207
|
+
const { listing, discovered, catalogRows, declared } = input;
|
|
142208
|
+
const provider = listing.provider;
|
|
142209
|
+
if (declared && declared.length > 0) {
|
|
142210
|
+
const providerName = lineupProviderName(provider);
|
|
142211
|
+
return { candidates: declared.map((id) => declaredModelInfo(id, providerName)) };
|
|
142212
|
+
}
|
|
142213
|
+
const isCustomEndpoint = declared !== null;
|
|
142214
|
+
if (isCustomEndpoint && listing.scope === "recommended") {
|
|
142215
|
+
return {
|
|
142216
|
+
candidates: [],
|
|
142217
|
+
emptyReason: `declare models for ${provider}, or use ${allScopeHint(listing)}`
|
|
142218
|
+
};
|
|
142219
|
+
}
|
|
142220
|
+
if (discovered) {
|
|
142221
|
+
return discovered.kind === "rows" ? { candidates: [...discovered.rows] } : { candidates: [], emptyReason: discoveryEmptyReason(discovered) };
|
|
142222
|
+
}
|
|
142223
|
+
if (isCustomEndpoint)
|
|
142224
|
+
return { candidates: [], emptyReason: `${provider} has no model list` };
|
|
142225
|
+
return { candidates: [...catalogRows] };
|
|
142226
|
+
}
|
|
142227
|
+
function recommendedCandidates(input, candidates) {
|
|
142228
|
+
const { listing, discovered, catalogRows, recommendedIds } = input;
|
|
142229
|
+
if (recommendedIds === null) {
|
|
142230
|
+
return {
|
|
142231
|
+
candidates: [],
|
|
142232
|
+
emptyReason: `recommended list unavailable; ${allScopeHint(listing)} lists every model it serves`
|
|
142233
|
+
};
|
|
142234
|
+
}
|
|
142235
|
+
const rank = new Map;
|
|
142236
|
+
if (discovered?.kind === "rows") {
|
|
142237
|
+
const catalogById = new Map(catalogRows.map((m) => [m.id, m]));
|
|
142238
|
+
recommendedIds.forEach((id, i) => {
|
|
142239
|
+
const row = catalogById.get(id);
|
|
142240
|
+
if (!row)
|
|
142241
|
+
return;
|
|
142242
|
+
const wire = resolveProviderExternalId(listing.provider, row);
|
|
142243
|
+
if (!rank.has(wire))
|
|
142244
|
+
rank.set(wire, i);
|
|
142245
|
+
});
|
|
142246
|
+
} else {
|
|
142247
|
+
recommendedIds.forEach((id, i) => {
|
|
142248
|
+
if (!rank.has(id))
|
|
142249
|
+
rank.set(id, i);
|
|
142250
|
+
});
|
|
142251
|
+
}
|
|
142252
|
+
const kept = candidates.filter((m) => rank.has(m.id)).sort((a, b) => (rank.get(a.id) ?? 0) - (rank.get(b.id) ?? 0));
|
|
142253
|
+
if (kept.length > 0)
|
|
142254
|
+
return { candidates: kept };
|
|
142255
|
+
return {
|
|
142256
|
+
candidates: [],
|
|
142257
|
+
emptyReason: `it serves none of the recommended models; ${allScopeHint(listing)} lists every model it serves`
|
|
142258
|
+
};
|
|
142259
|
+
}
|
|
142260
|
+
function assembleRows(input, candidates) {
|
|
142261
|
+
const { listing, isLocal, discovered, declared } = input;
|
|
142262
|
+
const provider = listing.provider;
|
|
142263
|
+
const providerName = lineupProviderName(provider);
|
|
142264
|
+
const idIsWire = discovered?.kind === "rows" || declared !== null && declared.length > 0;
|
|
142265
|
+
const listed = new Map;
|
|
142266
|
+
for (const m of candidates) {
|
|
142267
|
+
const spec = lineupSpecFor(provider, idIsWire ? m.id : resolveProviderExternalId(provider, m));
|
|
142268
|
+
const key = rowKey(spec);
|
|
142269
|
+
if (!listed.has(key))
|
|
142270
|
+
listed.set(key, { spec, model: m });
|
|
142271
|
+
}
|
|
142272
|
+
const rows = [];
|
|
142273
|
+
const seen = new Set;
|
|
142274
|
+
for (const pinned of listing.pinnedSpecs) {
|
|
142275
|
+
const key = rowKey(pinned);
|
|
142276
|
+
if (seen.has(key))
|
|
142277
|
+
continue;
|
|
142278
|
+
seen.add(key);
|
|
142279
|
+
const match = listed.get(key)?.model;
|
|
142280
|
+
rows.push(rowFrom(provider, providerName, isLocal, pinned, match, parseModelSpec(pinned).model));
|
|
142281
|
+
}
|
|
142282
|
+
for (const [key, { spec, model }] of listed) {
|
|
142283
|
+
if (seen.has(key))
|
|
142284
|
+
continue;
|
|
142285
|
+
seen.add(key);
|
|
142286
|
+
rows.push(rowFrom(provider, providerName, isLocal, spec, model, model.id));
|
|
142287
|
+
}
|
|
142288
|
+
return rows;
|
|
142289
|
+
}
|
|
142290
|
+
function stageSentence(stage, deadlineMs) {
|
|
142291
|
+
const seconds = `${Math.round(deadlineMs / 1000)} s`;
|
|
142292
|
+
switch (stage) {
|
|
142293
|
+
case "credential":
|
|
142294
|
+
return `no answer within ${seconds} while resolving its credential (a 1Password unlock may be waiting)`;
|
|
142295
|
+
case "list":
|
|
142296
|
+
return `no answer within ${seconds} while fetching its model list`;
|
|
142297
|
+
case "recommended":
|
|
142298
|
+
return `no answer within ${seconds} while reading the recommended list`;
|
|
142299
|
+
}
|
|
142300
|
+
}
|
|
142301
|
+
function notReadyReason(provider) {
|
|
142302
|
+
const def = getProviderByName(provider);
|
|
142303
|
+
if (def?.oauthLoginSlug) {
|
|
142304
|
+
return `not signed in \u2014 run \`claudish login ${def.oauthLoginSlug}\``;
|
|
142305
|
+
}
|
|
142306
|
+
if (def && def.apiKeyEnvVar === "" && def.isLocal !== true) {
|
|
142307
|
+
return `no ${lineupProviderName(provider)} sign-in found on this machine`;
|
|
142308
|
+
}
|
|
142309
|
+
return describeMissingCredential(provider);
|
|
142310
|
+
}
|
|
142311
|
+
function credentialCheck(provider, outcome) {
|
|
142312
|
+
if (outcome.kind !== "failed")
|
|
142313
|
+
return;
|
|
142314
|
+
const kind = outcome.failure.kind;
|
|
142315
|
+
if (kind !== "unauthorized" && kind !== "no-credentials")
|
|
142316
|
+
return;
|
|
142317
|
+
const envVar = getProviderByName(provider)?.apiKeyEnvVar;
|
|
142318
|
+
return envVar ? `check ${envVar} (a value in your shell overrides stored credentials)` : undefined;
|
|
142319
|
+
}
|
|
142320
|
+
function recommendedIdsOf(doc) {
|
|
142321
|
+
const tierIndex = new Map(RECOMMENDATION_SECTIONS.map((s, i) => [s.recommendationTier, i]));
|
|
142322
|
+
const ranked = doc.models.map((m, i) => ({ m, i })).filter(({ m }) => tierIndex.has(m.recommendationTier)).sort((a, b) => (tierIndex.get(a.m.recommendationTier) ?? 0) - (tierIndex.get(b.m.recommendationTier) ?? 0) || (a.m.priority ?? 0) - (b.m.priority ?? 0) || a.i - b.i);
|
|
142323
|
+
const ids = [];
|
|
142324
|
+
for (const { m } of ranked)
|
|
142325
|
+
if (!ids.includes(m.id))
|
|
142326
|
+
ids.push(m.id);
|
|
142327
|
+
return ids;
|
|
142328
|
+
}
|
|
142329
|
+
function defaultDeps7() {
|
|
142330
|
+
let catalog = null;
|
|
142331
|
+
const catalogOf = () => {
|
|
142332
|
+
catalog ??= createCatalogClient({ readSlimCache: () => readAllModelsCache() });
|
|
142333
|
+
return catalog;
|
|
142334
|
+
};
|
|
142335
|
+
return {
|
|
142336
|
+
ready: (provider) => pickerProviderReady(provider),
|
|
142337
|
+
storedList: (provider) => readAccountModelsList(provider),
|
|
142338
|
+
liveList: (provider) => liveOrStoredModelsCatalog(provider, "launch-lineup"),
|
|
142339
|
+
catalogRows: (provider) => {
|
|
142340
|
+
try {
|
|
142341
|
+
return servedModelsForProvider(provider, catalogOf());
|
|
142342
|
+
} catch {
|
|
142343
|
+
return [];
|
|
142344
|
+
}
|
|
142345
|
+
},
|
|
142346
|
+
catalogIsBundled: () => bundledListActive(),
|
|
142347
|
+
ensureCatalog: (ms) => ensureCatalogReady(Math.max(0, ms)).catch(() => {
|
|
142348
|
+
return;
|
|
142349
|
+
}),
|
|
142350
|
+
recommended: async () => {
|
|
142351
|
+
if (bundledListActive())
|
|
142352
|
+
return bundledRecommendedModelsDoc();
|
|
142353
|
+
try {
|
|
142354
|
+
await Promise.resolve().then(() => init_model_loader());
|
|
142355
|
+
const doc = await getRecommendedModels();
|
|
142356
|
+
if (doc)
|
|
142357
|
+
return doc;
|
|
142358
|
+
} catch {}
|
|
142359
|
+
return bundledListActive() ? bundledRecommendedModelsDoc() : null;
|
|
142360
|
+
},
|
|
142361
|
+
declaredModels: (provider) => {
|
|
142362
|
+
try {
|
|
142363
|
+
const endpoints = loadConfig().customEndpoints ?? {};
|
|
142364
|
+
if (!Object.prototype.hasOwnProperty.call(endpoints, provider))
|
|
142365
|
+
return null;
|
|
142366
|
+
const models = endpoints[provider].models;
|
|
142367
|
+
return Array.isArray(models) ? models.filter((m) => typeof m === "string") : [];
|
|
142368
|
+
} catch {
|
|
142369
|
+
return null;
|
|
142370
|
+
}
|
|
142371
|
+
},
|
|
142372
|
+
tier: (provider) => getProviderByName(provider)?.tier ?? "gateway",
|
|
142373
|
+
hasDiscovery: (provider) => Boolean(getProviderByName(provider)?.modelDiscovery),
|
|
142374
|
+
now: () => Date.now()
|
|
142375
|
+
};
|
|
142376
|
+
}
|
|
142377
|
+
function within(promise, ms, fallback) {
|
|
142378
|
+
if (ms <= 0)
|
|
142379
|
+
return Promise.resolve(fallback);
|
|
142380
|
+
return new Promise((resolve) => {
|
|
142381
|
+
const timer = setTimeout(() => resolve(fallback), ms);
|
|
142382
|
+
promise.then((value) => {
|
|
142383
|
+
clearTimeout(timer);
|
|
142384
|
+
resolve(value);
|
|
142385
|
+
}, () => {
|
|
142386
|
+
clearTimeout(timer);
|
|
142387
|
+
resolve(fallback);
|
|
142388
|
+
});
|
|
142389
|
+
});
|
|
142390
|
+
}
|
|
142391
|
+
async function buildModelLineup(listings, opts = {}) {
|
|
142392
|
+
const deadlineMs = opts.deadlineMs ?? LINEUP_WAIT_MS;
|
|
142393
|
+
const deps = { ...defaultDeps7(), ...opts.deps };
|
|
142394
|
+
const startedAt = deps.now();
|
|
142395
|
+
const remaining = () => Math.max(0, deadlineMs - (deps.now() - startedAt));
|
|
142396
|
+
const tiers = new Map(listings.map((l) => [l.provider, safeTier(deps, l.provider)]));
|
|
142397
|
+
const needsRecommended = listings.some((l) => tiers.get(l.provider) === "gateway" && l.scope === "recommended" && safeDeclared(deps, l.provider) === null);
|
|
142398
|
+
const recommendedPromise = needsRecommended ? deps.recommended().catch(() => null) : null;
|
|
142399
|
+
const stages = new Map;
|
|
142400
|
+
const settled = new Map;
|
|
142401
|
+
const one = async (listing) => {
|
|
142402
|
+
const provider = listing.provider;
|
|
142403
|
+
const notListed = (reason) => settled.set(provider, { rows: [], outcome: { kind: "not-listed", provider, reason } });
|
|
142404
|
+
try {
|
|
142405
|
+
stages.set(provider, "credential");
|
|
142406
|
+
const ready = await deps.ready(provider).catch(() => false);
|
|
142407
|
+
if (!ready) {
|
|
142408
|
+
notListed(notReadyReason(provider));
|
|
142409
|
+
return;
|
|
142410
|
+
}
|
|
142411
|
+
const tier = tiers.get(provider) ?? "gateway";
|
|
142412
|
+
const isLocal = getProviderByName(provider)?.isLocal === true;
|
|
142413
|
+
const declared = safeDeclared(deps, provider);
|
|
142414
|
+
stages.set(provider, "list");
|
|
142415
|
+
let discovered = null;
|
|
142416
|
+
let source = "catalog";
|
|
142417
|
+
let storedAt;
|
|
142418
|
+
if (declared && declared.length > 0) {
|
|
142419
|
+
source = "declared";
|
|
142420
|
+
} else if (deps.hasDiscovery(provider) && (declared === null || listing.scope === "all")) {
|
|
142421
|
+
const asked = await discoverFor(provider, deps, remaining());
|
|
142422
|
+
discovered = asked.discovered;
|
|
142423
|
+
source = asked.source;
|
|
142424
|
+
storedAt = asked.storedAt;
|
|
142425
|
+
if (discovered.kind !== "rows" && listing.pinnedSpecs.length === 0) {
|
|
142426
|
+
const check = credentialCheck(provider, discovered);
|
|
142427
|
+
const reason = discoveryEmptyReason(discovered) ?? "it lists no chat models";
|
|
142428
|
+
notListed(check ? `${reason}; ${check}` : reason);
|
|
142429
|
+
return;
|
|
142430
|
+
}
|
|
142431
|
+
} else if (declared === null) {
|
|
142432
|
+
await deps.ensureCatalog(remaining());
|
|
142433
|
+
}
|
|
142434
|
+
const catalogRows = declared === null ? deps.catalogRows(provider) : [];
|
|
142435
|
+
if (source === "catalog" && declared === null && deps.catalogIsBundled())
|
|
142436
|
+
source = "bundled";
|
|
142437
|
+
let recommendedIds = null;
|
|
142438
|
+
if (tier === "gateway" && listing.scope === "recommended" && declared === null) {
|
|
142439
|
+
stages.set(provider, "recommended");
|
|
142440
|
+
const doc = recommendedPromise ? await within(recommendedPromise, remaining(), null) : null;
|
|
142441
|
+
recommendedIds = doc ? recommendedIdsOf(doc) : null;
|
|
142442
|
+
}
|
|
142443
|
+
const built = lineupRowsForProvider({
|
|
142444
|
+
listing,
|
|
142445
|
+
tier,
|
|
142446
|
+
isLocal,
|
|
142447
|
+
discovered,
|
|
142448
|
+
catalogRows,
|
|
142449
|
+
recommendedIds,
|
|
142450
|
+
declared
|
|
142451
|
+
});
|
|
142452
|
+
if (built.rows.length === 0) {
|
|
142453
|
+
notListed(built.emptyReason ?? "it lists no chat models");
|
|
142454
|
+
return;
|
|
142455
|
+
}
|
|
142456
|
+
const servedTotal = tier === "gateway" && listing.scope === "recommended" && declared === null ? discovered?.kind === "rows" ? discovered.rows.length : catalogRows.length : undefined;
|
|
142457
|
+
settled.set(provider, {
|
|
142458
|
+
rows: built.rows,
|
|
142459
|
+
outcome: {
|
|
142460
|
+
kind: "listed",
|
|
142461
|
+
provider,
|
|
142462
|
+
count: built.rows.length,
|
|
142463
|
+
source,
|
|
142464
|
+
...storedAt !== undefined ? { storedAt } : {},
|
|
142465
|
+
...servedTotal !== undefined && servedTotal > built.rows.length ? { servedTotal } : {}
|
|
142466
|
+
}
|
|
142467
|
+
});
|
|
142468
|
+
} catch (err) {
|
|
142469
|
+
notListed(redactSecrets(err instanceof Error ? err.message : String(err)));
|
|
142470
|
+
} finally {
|
|
142471
|
+
stages.delete(provider);
|
|
142472
|
+
}
|
|
142473
|
+
};
|
|
142474
|
+
const all = Promise.all(listings.map(one)).then(() => {
|
|
142475
|
+
return;
|
|
142476
|
+
});
|
|
142477
|
+
const result = await within(all, remaining(), TIMED_OUT2);
|
|
142478
|
+
if (result === TIMED_OUT2)
|
|
142479
|
+
log(`[model-lineup] deadline of ${deadlineMs} ms reached`);
|
|
142480
|
+
const rows = [];
|
|
142481
|
+
const outcomes = [];
|
|
142482
|
+
for (const listing of listings) {
|
|
142483
|
+
const done = settled.get(listing.provider);
|
|
142484
|
+
if (done) {
|
|
142485
|
+
rows.push(...done.rows);
|
|
142486
|
+
outcomes.push(done.outcome);
|
|
142487
|
+
continue;
|
|
142488
|
+
}
|
|
142489
|
+
const stage = stages.get(listing.provider) ?? "credential";
|
|
142490
|
+
outcomes.push({
|
|
142491
|
+
kind: "not-listed",
|
|
142492
|
+
provider: listing.provider,
|
|
142493
|
+
reason: stageSentence(stage, deadlineMs)
|
|
142494
|
+
});
|
|
142495
|
+
}
|
|
142496
|
+
return { rows, outcomes };
|
|
142497
|
+
}
|
|
142498
|
+
async function discoverFor(provider, deps, remainingMs) {
|
|
142499
|
+
const catalogWarm = deps.ensureCatalog(remainingMs);
|
|
142500
|
+
const stored = await deps.storedList(provider).catch(() => null);
|
|
142501
|
+
let outcome;
|
|
142502
|
+
if (stored) {
|
|
142503
|
+
outcome = servedOutcomeOf(stored.models);
|
|
142504
|
+
deps.liveList(provider).catch(() => {
|
|
142505
|
+
return;
|
|
142506
|
+
});
|
|
142507
|
+
} else {
|
|
142508
|
+
outcome = await deps.liveList(provider);
|
|
142509
|
+
}
|
|
142510
|
+
await catalogWarm;
|
|
142511
|
+
const discovered = outcomeFromModelsCatalog(provider, lineupProviderName(provider), outcome, deps.catalogRows(provider));
|
|
142512
|
+
return stored ? { discovered, source: "stored", storedAt: stored.fetchedAt } : { discovered, source: "live" };
|
|
142513
|
+
}
|
|
142514
|
+
function safeTier(deps, provider) {
|
|
142515
|
+
try {
|
|
142516
|
+
return deps.tier(provider);
|
|
142517
|
+
} catch {
|
|
142518
|
+
return "gateway";
|
|
142519
|
+
}
|
|
142520
|
+
}
|
|
142521
|
+
function safeDeclared(deps, provider) {
|
|
142522
|
+
try {
|
|
142523
|
+
return deps.declaredModels(provider);
|
|
142524
|
+
} catch {
|
|
142525
|
+
return null;
|
|
142526
|
+
}
|
|
142527
|
+
}
|
|
142528
|
+
function sessionWindow(env, computedWindow) {
|
|
142529
|
+
const raw = env.CLAUDE_CODE_MAX_CONTEXT_TOKENS;
|
|
142530
|
+
const user = raw ? Number.parseInt(raw, 10) : Number.NaN;
|
|
142531
|
+
if (Number.isFinite(user) && user > 0)
|
|
142532
|
+
return user;
|
|
142533
|
+
if (computedWindow > 0)
|
|
142534
|
+
return computedWindow;
|
|
142535
|
+
return CLAUDE_CODE_DEFAULT_MAX_CONTEXT;
|
|
142536
|
+
}
|
|
142537
|
+
function lineupReport(lineup, ctx) {
|
|
142538
|
+
const listed = lineup.outcomes.filter((o) => o.kind === "listed");
|
|
142539
|
+
const lines = [summaryLine(lineup.rows.length, listed)];
|
|
142540
|
+
for (const o of lineup.outcomes) {
|
|
142541
|
+
if (o.kind !== "not-listed")
|
|
142542
|
+
continue;
|
|
142543
|
+
lines.push(`${PREFIX2}/model: ${lineupProviderName(o.provider)} not listed \u2014 ${redactSecrets(o.reason)}`);
|
|
142544
|
+
}
|
|
142545
|
+
for (const o of listed) {
|
|
142546
|
+
if (o.source !== "bundled")
|
|
142547
|
+
continue;
|
|
142548
|
+
lines.push(`${PREFIX2}/model: ${lineupProviderName(o.provider)} list is partial (the cloud models catalog was unreachable; it lists recommended models only)`);
|
|
142549
|
+
}
|
|
142550
|
+
const windowLine = smallerWindowLine(lineup.rows, ctx.sizedFor);
|
|
142551
|
+
if (windowLine)
|
|
142552
|
+
lines.push(windowLine);
|
|
142553
|
+
for (const notice of ctx.settingsNotices)
|
|
142554
|
+
lines.push(`${PREFIX2}/model: ${redactSecrets(notice)}`);
|
|
142555
|
+
if (ctx.posture === "foreign-start") {
|
|
142556
|
+
lines.push(`${PREFIX2}/model: this session starts on a foreign model, so a Claude row runs that start model`);
|
|
142557
|
+
} else if (ctx.posture === "tiers") {
|
|
142558
|
+
lines.push(`${PREFIX2}/model: Claude rows run your mapped tiers; an unmapped Claude row is not served on this launch`);
|
|
142559
|
+
}
|
|
142560
|
+
for (const { name } of ctx.inheritedModelVars) {
|
|
142561
|
+
lines.push(name === "ANTHROPIC_MODEL" ? `${PREFIX2}starts on the model ANTHROPIC_MODEL names in your environment` : `${PREFIX2}${name} from your environment still applies`);
|
|
142562
|
+
}
|
|
142563
|
+
return lines;
|
|
142564
|
+
}
|
|
142565
|
+
function summaryLine(rowCount, listed) {
|
|
142566
|
+
if (rowCount === 0) {
|
|
142567
|
+
return `${PREFIX2}/model lists no claudish models this session; Claude's own models only`;
|
|
142568
|
+
}
|
|
142569
|
+
const parts = listed.map((o) => {
|
|
142570
|
+
const name = lineupProviderName(o.provider);
|
|
142571
|
+
if (o.servedTotal === undefined)
|
|
142572
|
+
return `${name} ${o.count}`;
|
|
142573
|
+
return `${name} ${o.count} (recommended; '${shortestShortcut(o.provider)}@*' lists ${o.servedTotal})`;
|
|
142574
|
+
});
|
|
142575
|
+
const noun = rowCount === 1 ? "model" : "models";
|
|
142576
|
+
return `${PREFIX2}/model lists ${rowCount} ${noun} after Claude's own: ${parts.join(" \xB7 ")}`;
|
|
142577
|
+
}
|
|
142578
|
+
function smallerWindowLine(rows, sizedFor) {
|
|
142579
|
+
const smaller = rows.filter((r) => r.contextLength !== undefined && r.contextLength < sizedFor);
|
|
142580
|
+
if (smaller.length === 0)
|
|
142581
|
+
return null;
|
|
142582
|
+
const smallest = smaller.reduce((a, b) => (a.contextLength ?? 0) <= (b.contextLength ?? 0) ? a : b);
|
|
142583
|
+
const verb = smaller.length === 1 ? "model has" : "models have";
|
|
142584
|
+
return `${PREFIX2}/model: ${smaller.length} listed ${verb} a smaller context window than this session assumes (${formatContextLength(sizedFor)}; smallest: ${smallest.label} ${formatContextLength(smallest.contextLength)})`;
|
|
142585
|
+
}
|
|
142586
|
+
function shortestShortcut(provider) {
|
|
142587
|
+
const def = getProviderByName(provider);
|
|
142588
|
+
return def?.shortestPrefix || def?.shortcuts?.[0] || provider;
|
|
142589
|
+
}
|
|
142590
|
+
function userOption(entry) {
|
|
142591
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
142592
|
+
return null;
|
|
142593
|
+
const record = entry;
|
|
142594
|
+
const { model, label } = record;
|
|
142595
|
+
if (typeof model !== "string" || model.length === 0)
|
|
142596
|
+
return null;
|
|
142597
|
+
return { ...record, model, label: typeof label === "string" ? label : model };
|
|
142598
|
+
}
|
|
142599
|
+
function isRoutableClaudishSpec(model) {
|
|
142600
|
+
if (nativeRouteFor(model) !== null)
|
|
142601
|
+
return false;
|
|
142602
|
+
const parsed = parseModelSpec(model);
|
|
142603
|
+
if (!parsed.isExplicitProvider || parsed.isLegacySyntax)
|
|
142604
|
+
return false;
|
|
142605
|
+
if (parsed.provider === "custom-url" || parsed.provider === "native-anthropic")
|
|
142606
|
+
return false;
|
|
142607
|
+
return getProviderByName(parsed.provider) !== undefined;
|
|
142608
|
+
}
|
|
142609
|
+
function routedUserRows(options, rows) {
|
|
142610
|
+
const listed = new Set(rows.map((row) => row.model));
|
|
142611
|
+
const out = [];
|
|
142612
|
+
for (const option of options) {
|
|
142613
|
+
if (listed.has(option.model) || !isRoutableClaudishSpec(option.model))
|
|
142614
|
+
continue;
|
|
142615
|
+
listed.add(option.model);
|
|
142616
|
+
out.push({ model: option.model, label: option.label });
|
|
142617
|
+
}
|
|
142618
|
+
return out;
|
|
142619
|
+
}
|
|
142620
|
+
function modelPickerSetting(rows, sources) {
|
|
142621
|
+
const options = [];
|
|
142622
|
+
const seen = new Set;
|
|
142623
|
+
for (const entry of sources.user?.options ?? []) {
|
|
142624
|
+
const option = userOption(entry);
|
|
142625
|
+
if (!option || seen.has(option.model))
|
|
142626
|
+
continue;
|
|
142627
|
+
seen.add(option.model);
|
|
142628
|
+
options.push(option);
|
|
142629
|
+
}
|
|
142630
|
+
for (const row of rows) {
|
|
142631
|
+
if (seen.has(row.model))
|
|
142632
|
+
continue;
|
|
142633
|
+
seen.add(row.model);
|
|
142634
|
+
options.push({ model: row.model, label: row.label, description: row.description });
|
|
142635
|
+
}
|
|
142636
|
+
const notices = [];
|
|
142637
|
+
if (sources.user && sources.user.replaceBuiltInOptions === true) {
|
|
142638
|
+
notices.push(`${sources.user.where} sets modelPicker.replaceBuiltInOptions; claudish keeps Claude's own rows in /model for this session`);
|
|
142639
|
+
}
|
|
142640
|
+
if (sources.managed) {
|
|
142641
|
+
notices.push(`${sources.managed} sets modelPicker, which Claude Code applies over claudish's rows; listed models may be missing from /model`);
|
|
142642
|
+
}
|
|
142643
|
+
for (const where of sources.availableModels) {
|
|
142644
|
+
notices.push(`${where} sets availableModels, which may hide listed models from /model`);
|
|
142645
|
+
}
|
|
142646
|
+
return { setting: { options }, notices };
|
|
142647
|
+
}
|
|
142648
|
+
var LINEUP_WAIT_MS = 6000, LINEUP_LABEL_MAX = 60, LINEUP_DESCRIPTION_MAX = 100, REDACTION_MARKERS, TIMED_OUT2, PREFIX2 = "[claudish] ", MODEL_RESTORE_PROMISE = `/model: Enter saves a pick as Claude Code's default; claudish puts your setting back at exit ("s" picks for this session only)`;
|
|
142649
|
+
var init_model_lineup = __esm(() => {
|
|
142650
|
+
init_claude_runner();
|
|
142651
|
+
init_logger();
|
|
142652
|
+
init_model_loader();
|
|
142653
|
+
init_model_selector();
|
|
142654
|
+
init_profile_config();
|
|
142655
|
+
init_all_models_cache();
|
|
142656
|
+
init_bundled_list();
|
|
142657
|
+
init_catalog_client();
|
|
142658
|
+
init_dynamic_models_catalog();
|
|
142659
|
+
init_model_catalog2();
|
|
142660
|
+
init_model_discovery();
|
|
142661
|
+
init_model_parser();
|
|
142662
|
+
init_native_route();
|
|
142663
|
+
init_picker_readiness();
|
|
142664
|
+
init_provider_definitions();
|
|
142665
|
+
init_redact();
|
|
142666
|
+
REDACTION_MARKERS = ["***REDACTED***", "[redacted]"];
|
|
142667
|
+
TIMED_OUT2 = Symbol("timed-out");
|
|
142668
|
+
});
|
|
142669
|
+
|
|
141568
142670
|
// src/diag-output.ts
|
|
141569
142671
|
import { createWriteStream as createWriteStream2, mkdirSync as mkdirSync32, unlinkSync as unlinkSync15, writeFileSync as writeFileSync32 } from "fs";
|
|
141570
142672
|
import { homedir as homedir47 } from "os";
|
|
@@ -143667,6 +144769,611 @@ var init_resume_picker_run = __esm(() => {
|
|
|
143667
144769
|
init_session_discovery();
|
|
143668
144770
|
});
|
|
143669
144771
|
|
|
144772
|
+
// src/launcher/model-setting-ledger-path.ts
|
|
144773
|
+
import { homedir as homedir48 } from "os";
|
|
144774
|
+
import { join as join77 } from "path";
|
|
144775
|
+
function modelSettingLedgerPath(env = process.env) {
|
|
144776
|
+
const home = env.HOME && env.HOME.length > 0 ? env.HOME : homedir48();
|
|
144777
|
+
return join77(home, ".claudish", MODEL_SETTING_LEDGER_FILE);
|
|
144778
|
+
}
|
|
144779
|
+
var MODEL_SETTING_LEDGER_FILE = "model-setting-restore.json";
|
|
144780
|
+
var init_model_setting_ledger_path = () => {};
|
|
144781
|
+
|
|
144782
|
+
// src/launcher/model-setting-restore.ts
|
|
144783
|
+
import { randomUUID as randomUUID13 } from "crypto";
|
|
144784
|
+
import {
|
|
144785
|
+
closeSync as closeSync21,
|
|
144786
|
+
fchmodSync as fchmodSync2,
|
|
144787
|
+
fsyncSync as fsyncSync4,
|
|
144788
|
+
openSync as openSync20,
|
|
144789
|
+
readFileSync as readFileSync59,
|
|
144790
|
+
readdirSync as readdirSync20,
|
|
144791
|
+
realpathSync as realpathSync11,
|
|
144792
|
+
renameSync as renameSync15,
|
|
144793
|
+
rmSync as rmSync22,
|
|
144794
|
+
statSync as statSync32,
|
|
144795
|
+
unlinkSync as unlinkSync16,
|
|
144796
|
+
writeSync as writeSync8
|
|
144797
|
+
} from "fs";
|
|
144798
|
+
import { homedir as homedir49 } from "os";
|
|
144799
|
+
import { basename as basename10, dirname as dirname31, join as join78, resolve as resolve15 } from "path";
|
|
144800
|
+
function canonicalSettingsPath(path) {
|
|
144801
|
+
let head = resolve15(path);
|
|
144802
|
+
const rest = [];
|
|
144803
|
+
for (;; ) {
|
|
144804
|
+
try {
|
|
144805
|
+
return join78(realpathSync11.native(head), ...rest);
|
|
144806
|
+
} catch {
|
|
144807
|
+
const parent = dirname31(head);
|
|
144808
|
+
if (parent === head)
|
|
144809
|
+
return join78(head, ...rest);
|
|
144810
|
+
rest.unshift(basename10(head));
|
|
144811
|
+
head = parent;
|
|
144812
|
+
}
|
|
144813
|
+
}
|
|
144814
|
+
}
|
|
144815
|
+
function restoreDecision(current, entry) {
|
|
144816
|
+
if (typeof current !== "string" || !entry.listed.includes(current))
|
|
144817
|
+
return { action: "leave" };
|
|
144818
|
+
if (entry.original.present && entry.original.value === current)
|
|
144819
|
+
return { action: "leave" };
|
|
144820
|
+
return entry.original.present ? { action: "set", value: entry.original.value } : { action: "delete" };
|
|
144821
|
+
}
|
|
144822
|
+
function errnoOf(err) {
|
|
144823
|
+
return err?.code;
|
|
144824
|
+
}
|
|
144825
|
+
function toFileStat(s) {
|
|
144826
|
+
return { dev: s.dev, ino: s.ino, size: s.size, mtimeMs: s.mtimeMs, mode: s.mode };
|
|
144827
|
+
}
|
|
144828
|
+
function sameStat(a, b) {
|
|
144829
|
+
return a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.mode === b.mode;
|
|
144830
|
+
}
|
|
144831
|
+
function writeWholeSync(fd, data, write = (f, b, o, l) => writeSync8(f, b, o, l)) {
|
|
144832
|
+
const bytes = Buffer.from(data, "utf8");
|
|
144833
|
+
let offset = 0;
|
|
144834
|
+
while (offset < bytes.length) {
|
|
144835
|
+
const n = write(fd, bytes, offset, bytes.length - offset);
|
|
144836
|
+
if (!(n > 0)) {
|
|
144837
|
+
throw new Error(`short write: ${offset} of ${bytes.length} bytes, then no progress`);
|
|
144838
|
+
}
|
|
144839
|
+
offset += n;
|
|
144840
|
+
}
|
|
144841
|
+
}
|
|
144842
|
+
function detectIndent(text) {
|
|
144843
|
+
if (!text.trim().includes(`
|
|
144844
|
+
`))
|
|
144845
|
+
return;
|
|
144846
|
+
const m = text.match(/^\{\s*?\n([ \t]+)\S/);
|
|
144847
|
+
return m?.[1] ? m[1] : 2;
|
|
144848
|
+
}
|
|
144849
|
+
function isPlainObject8(value) {
|
|
144850
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
144851
|
+
}
|
|
144852
|
+
function restoreSettingsFile(settingsKey, entry, deps = realRestoreFs, fence = () => true) {
|
|
144853
|
+
let target;
|
|
144854
|
+
try {
|
|
144855
|
+
target = deps.realpath(settingsKey);
|
|
144856
|
+
} catch (err) {
|
|
144857
|
+
return errnoOf(err) === "ENOENT" ? "absent" : "not-writable";
|
|
144858
|
+
}
|
|
144859
|
+
for (let round = 0;round < RESTORE_ROUNDS; round++) {
|
|
144860
|
+
const outcome = restoreRound(settingsKey, target, entry, deps, fence);
|
|
144861
|
+
if (outcome !== "retry")
|
|
144862
|
+
return outcome;
|
|
144863
|
+
}
|
|
144864
|
+
return "changed-under-us";
|
|
144865
|
+
}
|
|
144866
|
+
function nextSettingsText(text, entry) {
|
|
144867
|
+
let parsed;
|
|
144868
|
+
try {
|
|
144869
|
+
parsed = JSON.parse(text);
|
|
144870
|
+
} catch {
|
|
144871
|
+
return { outcome: "unparsable" };
|
|
144872
|
+
}
|
|
144873
|
+
if (!isPlainObject8(parsed))
|
|
144874
|
+
return { outcome: "unparsable" };
|
|
144875
|
+
const decision = restoreDecision(parsed.model, entry);
|
|
144876
|
+
if (decision.action === "leave")
|
|
144877
|
+
return { outcome: "left" };
|
|
144878
|
+
if (decision.action === "set")
|
|
144879
|
+
parsed.model = decision.value;
|
|
144880
|
+
else
|
|
144881
|
+
delete parsed.model;
|
|
144882
|
+
const newline = text.endsWith(`
|
|
144883
|
+
`) ? `
|
|
144884
|
+
` : "";
|
|
144885
|
+
return { next: `${JSON.stringify(parsed, null, detectIndent(text))}${newline}` };
|
|
144886
|
+
}
|
|
144887
|
+
function unlinkQuietly(deps, path) {
|
|
144888
|
+
try {
|
|
144889
|
+
deps.unlink(path);
|
|
144890
|
+
} catch {}
|
|
144891
|
+
}
|
|
144892
|
+
function restoreRound(settingsKey, target, entry, deps, fence) {
|
|
144893
|
+
let bytesA;
|
|
144894
|
+
let statA;
|
|
144895
|
+
try {
|
|
144896
|
+
bytesA = deps.readFile(target);
|
|
144897
|
+
statA = deps.stat(target);
|
|
144898
|
+
} catch (err) {
|
|
144899
|
+
return errnoOf(err) === "ENOENT" ? "absent" : "not-writable";
|
|
144900
|
+
}
|
|
144901
|
+
const text = bytesA.toString("utf8");
|
|
144902
|
+
const planned = nextSettingsText(text, entry);
|
|
144903
|
+
if ("outcome" in planned)
|
|
144904
|
+
return planned.outcome;
|
|
144905
|
+
const temp = join78(dirname31(target), `${TEMP_PREFIX}${deps.pid ?? process.pid}-${randomUUID13()}`);
|
|
144906
|
+
try {
|
|
144907
|
+
deps.writeNew(temp, planned.next, statA.mode & 4095);
|
|
144908
|
+
} catch {
|
|
144909
|
+
unlinkQuietly(deps, temp);
|
|
144910
|
+
return "not-writable";
|
|
144911
|
+
}
|
|
144912
|
+
deps.beforeRename?.();
|
|
144913
|
+
let unchanged = false;
|
|
144914
|
+
try {
|
|
144915
|
+
unchanged = deps.realpath(settingsKey) === target && sameStat(deps.stat(target), statA) && deps.readFile(target).equals(bytesA);
|
|
144916
|
+
} catch {
|
|
144917
|
+
unchanged = false;
|
|
144918
|
+
}
|
|
144919
|
+
if (!unchanged) {
|
|
144920
|
+
unlinkQuietly(deps, temp);
|
|
144921
|
+
return "retry";
|
|
144922
|
+
}
|
|
144923
|
+
if (!fence()) {
|
|
144924
|
+
unlinkQuietly(deps, temp);
|
|
144925
|
+
return "fenced";
|
|
144926
|
+
}
|
|
144927
|
+
try {
|
|
144928
|
+
deps.rename(temp, target);
|
|
144929
|
+
} catch {
|
|
144930
|
+
unlinkQuietly(deps, temp);
|
|
144931
|
+
return "not-writable";
|
|
144932
|
+
}
|
|
144933
|
+
return "restored";
|
|
144934
|
+
}
|
|
144935
|
+
function readLedger2(path) {
|
|
144936
|
+
let text;
|
|
144937
|
+
try {
|
|
144938
|
+
text = readFileSync59(path, "utf8");
|
|
144939
|
+
} catch (err) {
|
|
144940
|
+
if (errnoOf(err) === "ENOENT")
|
|
144941
|
+
return { ok: true, ledger: { version: 1, entries: {} } };
|
|
144942
|
+
log(`[model-restore] ledger unreadable (${path}): ${errnoOf(err) ?? String(err)}`);
|
|
144943
|
+
return { ok: false, reason: "unreadable" };
|
|
144944
|
+
}
|
|
144945
|
+
let parsed;
|
|
144946
|
+
try {
|
|
144947
|
+
parsed = JSON.parse(text);
|
|
144948
|
+
} catch (err) {
|
|
144949
|
+
log(`[model-restore] ledger unparsable (${path}): ${err.message}`);
|
|
144950
|
+
return { ok: false, reason: "unparsable" };
|
|
144951
|
+
}
|
|
144952
|
+
if (parsed?.version !== 1 || !isPlainObject8(parsed.entries)) {
|
|
144953
|
+
log(`[model-restore] ledger of unknown shape (${path})`);
|
|
144954
|
+
return { ok: false, reason: "unknown-shape" };
|
|
144955
|
+
}
|
|
144956
|
+
return { ok: true, ledger: parsed };
|
|
144957
|
+
}
|
|
144958
|
+
function reportUnreadableLedger(ctx, reason) {
|
|
144959
|
+
if (reportedUnreadableLedgers.has(ctx.ledgerPath))
|
|
144960
|
+
return;
|
|
144961
|
+
reportedUnreadableLedgers.add(ctx.ledgerPath);
|
|
144962
|
+
const why = reason === "unreadable" ? "cannot be read" : reason === "unparsable" ? "is not valid JSON" : "has a version or shape this claudish does not read";
|
|
144963
|
+
ctx.report(`${ctx.ledgerPath} ${why}, so claudish cannot put back your Claude Code default model; delete that file`);
|
|
144964
|
+
}
|
|
144965
|
+
function writeLedger(path, ledger, fence) {
|
|
144966
|
+
if (!fence()) {
|
|
144967
|
+
log(`[model-restore] ledger lock taken by another claudish; ${path} not written`);
|
|
144968
|
+
return false;
|
|
144969
|
+
}
|
|
144970
|
+
if (Object.keys(ledger.entries).length === 0) {
|
|
144971
|
+
rmSync22(path, { force: true });
|
|
144972
|
+
return true;
|
|
144973
|
+
}
|
|
144974
|
+
atomicWriteFileSync(path, `${JSON.stringify(ledger, null, 2)}
|
|
144975
|
+
`, {
|
|
144976
|
+
mode: 384,
|
|
144977
|
+
dirMode: 448
|
|
144978
|
+
});
|
|
144979
|
+
return true;
|
|
144980
|
+
}
|
|
144981
|
+
function fenceOf(handle) {
|
|
144982
|
+
return () => handle?.holdsLock() ?? false;
|
|
144983
|
+
}
|
|
144984
|
+
function lockPathOf(ledgerPath) {
|
|
144985
|
+
return `${ledgerPath}.lock`;
|
|
144986
|
+
}
|
|
144987
|
+
function markLive(mark, table) {
|
|
144988
|
+
if (table === null || mark.startedEpochMs === null)
|
|
144989
|
+
return pidMayBeAlive(mark.pid);
|
|
144990
|
+
const row = table.find((r) => r.pid === mark.pid);
|
|
144991
|
+
return row !== undefined && startedAt(row, mark.startedEpochMs);
|
|
144992
|
+
}
|
|
144993
|
+
function settingsWriterLive(session, table) {
|
|
144994
|
+
if (session.settingsArg) {
|
|
144995
|
+
const needle = `--settings ${session.settingsArg}`;
|
|
144996
|
+
return table.some((r) => r.command.includes(needle));
|
|
144997
|
+
}
|
|
144998
|
+
const nameNeedle = `/.claudish/settings-${session.launcher.pid}-`;
|
|
144999
|
+
const since = session.launcher.startedEpochMs;
|
|
145000
|
+
return table.some((r) => r.command.includes("--settings ") && r.command.includes(nameNeedle) && (since === null || r.startMs === undefined || r.startMs >= since - 2000));
|
|
145001
|
+
}
|
|
145002
|
+
function sessionLiveness(session, table) {
|
|
145003
|
+
if (markLive(session.launcher, table))
|
|
145004
|
+
return "live";
|
|
145005
|
+
if (session.child !== "pending")
|
|
145006
|
+
return markLive(session.child, table) ? "live" : "ended";
|
|
145007
|
+
if (table === null)
|
|
145008
|
+
return "unknown";
|
|
145009
|
+
return settingsWriterLive(session, table) ? "live" : "ended";
|
|
145010
|
+
}
|
|
145011
|
+
function contextOf(deps) {
|
|
145012
|
+
const fs = deps.fs ?? realRestoreFs;
|
|
145013
|
+
const withHooks = {
|
|
145014
|
+
...fs,
|
|
145015
|
+
...deps.beforeRename ? { beforeRename: deps.beforeRename } : {},
|
|
145016
|
+
...deps.pid !== undefined ? { pid: deps.pid } : {}
|
|
145017
|
+
};
|
|
145018
|
+
return {
|
|
145019
|
+
ledgerPath: deps.ledgerPath ?? modelSettingLedgerPath(deps.env ?? process.env),
|
|
145020
|
+
fs: withHooks,
|
|
145021
|
+
now: deps.now ?? Date.now,
|
|
145022
|
+
report: deps.report ?? logStderr,
|
|
145023
|
+
processTable: deps.processTable ?? readProcessTable
|
|
145024
|
+
};
|
|
145025
|
+
}
|
|
145026
|
+
function statOrNull3(ctx, key) {
|
|
145027
|
+
try {
|
|
145028
|
+
return ctx.fs.stat(ctx.fs.realpath(key));
|
|
145029
|
+
} catch {
|
|
145030
|
+
return null;
|
|
145031
|
+
}
|
|
145032
|
+
}
|
|
145033
|
+
function settleEntry(ctx, ledger, key, silent, fence) {
|
|
145034
|
+
const entry = ledger.entries[key];
|
|
145035
|
+
if (!entry)
|
|
145036
|
+
return;
|
|
145037
|
+
const outcome = restoreSettingsFile(key, entry, ctx.fs, fence);
|
|
145038
|
+
log(`[model-restore] ${key}: ${outcome}`);
|
|
145039
|
+
switch (outcome) {
|
|
145040
|
+
case "fenced":
|
|
145041
|
+
return;
|
|
145042
|
+
case "restored":
|
|
145043
|
+
ctx.report(`Put back your Claude Code default model in ${key}`);
|
|
145044
|
+
delete ledger.entries[key];
|
|
145045
|
+
return;
|
|
145046
|
+
case "left":
|
|
145047
|
+
case "absent":
|
|
145048
|
+
delete ledger.entries[key];
|
|
145049
|
+
return;
|
|
145050
|
+
case "changed-under-us":
|
|
145051
|
+
entry.sessions = [];
|
|
145052
|
+
if (!silent) {
|
|
145053
|
+
ctx.report(`${key} kept changing while claudish put back your default model; it will try again at the next launch`);
|
|
145054
|
+
}
|
|
145055
|
+
return;
|
|
145056
|
+
case "unparsable":
|
|
145057
|
+
case "not-writable": {
|
|
145058
|
+
entry.sessions = [];
|
|
145059
|
+
if (!entry.failure) {
|
|
145060
|
+
entry.failure = {
|
|
145061
|
+
outcome,
|
|
145062
|
+
firstAt: ctx.now(),
|
|
145063
|
+
stat: statOrNull3(ctx, key),
|
|
145064
|
+
reported: true
|
|
145065
|
+
};
|
|
145066
|
+
const why = outcome === "unparsable" ? "is not valid JSON" : "cannot be written";
|
|
145067
|
+
ctx.report(`${key} ${why}, so claudish did not put back your default model; set or remove "model" in ${key} by hand`);
|
|
145068
|
+
} else {
|
|
145069
|
+
entry.failure.stat = statOrNull3(ctx, key);
|
|
145070
|
+
}
|
|
145071
|
+
return;
|
|
145072
|
+
}
|
|
145073
|
+
}
|
|
145074
|
+
}
|
|
145075
|
+
function removeOrphanTemps(ctx, key, table) {
|
|
145076
|
+
const dirs = new Set([dirname31(key)]);
|
|
145077
|
+
try {
|
|
145078
|
+
dirs.add(dirname31(ctx.fs.realpath(key)));
|
|
145079
|
+
} catch {}
|
|
145080
|
+
for (const dir of dirs) {
|
|
145081
|
+
let names;
|
|
145082
|
+
try {
|
|
145083
|
+
names = readdirSync20(dir);
|
|
145084
|
+
} catch {
|
|
145085
|
+
continue;
|
|
145086
|
+
}
|
|
145087
|
+
for (const name of names) {
|
|
145088
|
+
if (!name.startsWith(TEMP_PREFIX))
|
|
145089
|
+
continue;
|
|
145090
|
+
const pid = Number(name.slice(TEMP_PREFIX.length).split("-")[0]);
|
|
145091
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
145092
|
+
continue;
|
|
145093
|
+
const live = table === null ? pidMayBeAlive(pid) : table.some((r) => r.pid === pid);
|
|
145094
|
+
if (live)
|
|
145095
|
+
continue;
|
|
145096
|
+
try {
|
|
145097
|
+
unlinkSync16(join78(dir, name));
|
|
145098
|
+
} catch {}
|
|
145099
|
+
}
|
|
145100
|
+
}
|
|
145101
|
+
}
|
|
145102
|
+
function sweepLedger(ctx, ledger, fence) {
|
|
145103
|
+
const table = ctx.processTable();
|
|
145104
|
+
const now = ctx.now();
|
|
145105
|
+
for (const key of Object.keys(ledger.entries)) {
|
|
145106
|
+
const entry = ledger.entries[key];
|
|
145107
|
+
if (!entry)
|
|
145108
|
+
continue;
|
|
145109
|
+
removeOrphanTemps(ctx, key, table);
|
|
145110
|
+
const kept = [];
|
|
145111
|
+
let unknownOnly = true;
|
|
145112
|
+
for (const session of entry.sessions) {
|
|
145113
|
+
const liveness = sessionLiveness(session, table);
|
|
145114
|
+
if (liveness === "ended")
|
|
145115
|
+
continue;
|
|
145116
|
+
kept.push(session);
|
|
145117
|
+
if (liveness === "live" || now - session.startedAt <= GIVE_UP_AFTER_MS)
|
|
145118
|
+
unknownOnly = false;
|
|
145119
|
+
}
|
|
145120
|
+
entry.sessions = kept;
|
|
145121
|
+
if (kept.length > 0) {
|
|
145122
|
+
if (!unknownOnly)
|
|
145123
|
+
continue;
|
|
145124
|
+
ctx.report(`Gave up putting back your Claude Code default model in ${key}: no process table for 14 days`);
|
|
145125
|
+
delete ledger.entries[key];
|
|
145126
|
+
continue;
|
|
145127
|
+
}
|
|
145128
|
+
if (entry.failure) {
|
|
145129
|
+
if (now - entry.failure.firstAt > GIVE_UP_AFTER_MS) {
|
|
145130
|
+
ctx.report(`Gave up putting back your Claude Code default model in ${key}; set or remove "model" there by hand`);
|
|
145131
|
+
delete ledger.entries[key];
|
|
145132
|
+
continue;
|
|
145133
|
+
}
|
|
145134
|
+
const stat = statOrNull3(ctx, key);
|
|
145135
|
+
const unchanged = stat !== null && entry.failure.stat !== null && sameStat(stat, entry.failure.stat);
|
|
145136
|
+
if (unchanged)
|
|
145137
|
+
continue;
|
|
145138
|
+
settleEntry(ctx, ledger, key, true, fence);
|
|
145139
|
+
continue;
|
|
145140
|
+
}
|
|
145141
|
+
settleEntry(ctx, ledger, key, false, fence);
|
|
145142
|
+
}
|
|
145143
|
+
}
|
|
145144
|
+
async function sweepModelSettingLedger(deps = {}) {
|
|
145145
|
+
const ctx = contextOf(deps);
|
|
145146
|
+
try {
|
|
145147
|
+
await withFileLock(lockPathOf(ctx.ledgerPath), {
|
|
145148
|
+
timeoutMs: LOCK_TIMEOUT_MS,
|
|
145149
|
+
staleMs: LOCK_STALE_MS,
|
|
145150
|
+
heartbeatMs: LOCK_HEARTBEAT_MS,
|
|
145151
|
+
onUnavailable: "fail"
|
|
145152
|
+
}, async (handle) => {
|
|
145153
|
+
const read = readLedger2(ctx.ledgerPath);
|
|
145154
|
+
if (!read.ok) {
|
|
145155
|
+
reportUnreadableLedger(ctx, read.reason);
|
|
145156
|
+
return;
|
|
145157
|
+
}
|
|
145158
|
+
const fence = fenceOf(handle);
|
|
145159
|
+
sweepLedger(ctx, read.ledger, fence);
|
|
145160
|
+
writeLedger(ctx.ledgerPath, read.ledger, fence);
|
|
145161
|
+
});
|
|
145162
|
+
} catch (err) {
|
|
145163
|
+
log(`[model-restore] sweep skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
145164
|
+
}
|
|
145165
|
+
}
|
|
145166
|
+
function readOriginal(ctx, key) {
|
|
145167
|
+
let text;
|
|
145168
|
+
try {
|
|
145169
|
+
text = ctx.fs.readFile(ctx.fs.realpath(key)).toString("utf8");
|
|
145170
|
+
} catch (err) {
|
|
145171
|
+
return errnoOf(err) === "ENOENT" ? { present: false } : null;
|
|
145172
|
+
}
|
|
145173
|
+
try {
|
|
145174
|
+
const parsed = JSON.parse(text);
|
|
145175
|
+
if (!isPlainObject8(parsed))
|
|
145176
|
+
return null;
|
|
145177
|
+
return "model" in parsed ? { present: true, value: parsed.model } : { present: false };
|
|
145178
|
+
} catch {
|
|
145179
|
+
return null;
|
|
145180
|
+
}
|
|
145181
|
+
}
|
|
145182
|
+
function selfStartEpochMs() {
|
|
145183
|
+
return Math.round(Date.now() - process.uptime() * 1000);
|
|
145184
|
+
}
|
|
145185
|
+
async function beginModelSettingWatch(listedSpecs, deps = {}) {
|
|
145186
|
+
const ctx = contextOf(deps);
|
|
145187
|
+
const env = deps.env ?? process.env;
|
|
145188
|
+
const settingsFile = deps.settingsFile ?? userSettingsFile(env.CLAUDE_CONFIG_DIR, env.HOME && env.HOME.length > 0 ? env.HOME : homedir49(), deps.cwd ?? process.cwd());
|
|
145189
|
+
const key = canonicalSettingsPath(settingsFile);
|
|
145190
|
+
const lockPath = lockPathOf(ctx.ledgerPath);
|
|
145191
|
+
const lockOpts = {
|
|
145192
|
+
timeoutMs: LOCK_TIMEOUT_MS,
|
|
145193
|
+
staleMs: LOCK_STALE_MS,
|
|
145194
|
+
heartbeatMs: LOCK_HEARTBEAT_MS,
|
|
145195
|
+
onUnavailable: "fail"
|
|
145196
|
+
};
|
|
145197
|
+
const sessionId = randomUUID13();
|
|
145198
|
+
const launcherPid = deps.pid ?? process.pid;
|
|
145199
|
+
const noRestore = "so claudish will not put back your Claude Code default model after this session";
|
|
145200
|
+
let registered = false;
|
|
145201
|
+
try {
|
|
145202
|
+
registered = await withFileLock(lockPath, lockOpts, async (handle) => {
|
|
145203
|
+
const read = readLedger2(ctx.ledgerPath);
|
|
145204
|
+
if (!read.ok) {
|
|
145205
|
+
reportUnreadableLedger(ctx, read.reason);
|
|
145206
|
+
return false;
|
|
145207
|
+
}
|
|
145208
|
+
const unreadableAtLaunch = () => {
|
|
145209
|
+
log(`[model-restore] ${key} unreadable at launch; no restore for this session`);
|
|
145210
|
+
ctx.report(`${key} cannot be read or is not a JSON object, ${noRestore}`);
|
|
145211
|
+
return false;
|
|
145212
|
+
};
|
|
145213
|
+
let entry = read.ledger.entries[key];
|
|
145214
|
+
if (!entry) {
|
|
145215
|
+
const original = readOriginal(ctx, key);
|
|
145216
|
+
if (original === null)
|
|
145217
|
+
return unreadableAtLaunch();
|
|
145218
|
+
entry = { original, listed: [], sessions: [] };
|
|
145219
|
+
read.ledger.entries[key] = entry;
|
|
145220
|
+
} else if (entry.failure) {
|
|
145221
|
+
if (readOriginal(ctx, key) === null)
|
|
145222
|
+
return unreadableAtLaunch();
|
|
145223
|
+
delete entry.failure;
|
|
145224
|
+
}
|
|
145225
|
+
for (const spec of listedSpecs)
|
|
145226
|
+
if (!entry.listed.includes(spec))
|
|
145227
|
+
entry.listed.push(spec);
|
|
145228
|
+
entry.sessions.push({
|
|
145229
|
+
id: sessionId,
|
|
145230
|
+
launcher: { pid: launcherPid, startedEpochMs: selfStartEpochMs() },
|
|
145231
|
+
child: "pending",
|
|
145232
|
+
settingsArg: null,
|
|
145233
|
+
startedAt: ctx.now()
|
|
145234
|
+
});
|
|
145235
|
+
if (!writeLedger(ctx.ledgerPath, read.ledger, fenceOf(handle))) {
|
|
145236
|
+
ctx.report(`${lockPath} was taken by another claudish, ${noRestore}`);
|
|
145237
|
+
return false;
|
|
145238
|
+
}
|
|
145239
|
+
return true;
|
|
145240
|
+
});
|
|
145241
|
+
} catch (err) {
|
|
145242
|
+
log(`[model-restore] watch not begun: ${err instanceof Error ? err.message : String(err)}`);
|
|
145243
|
+
ctx.report(err instanceof FileLockUnavailableError && err.reason !== "unwritable" ? `${lockPath} is held by another claudish, ${noRestore}` : `${ctx.ledgerPath} cannot be written, ${noRestore}`);
|
|
145244
|
+
}
|
|
145245
|
+
if (!registered)
|
|
145246
|
+
return INERT_WATCH;
|
|
145247
|
+
let childMark = null;
|
|
145248
|
+
let ended = false;
|
|
145249
|
+
const updateRow = (fence, update) => {
|
|
145250
|
+
const read = readLedger2(ctx.ledgerPath);
|
|
145251
|
+
if (!read.ok)
|
|
145252
|
+
return;
|
|
145253
|
+
const session = read.ledger.entries[key]?.sessions.find((s) => s.id === sessionId);
|
|
145254
|
+
if (!session)
|
|
145255
|
+
return;
|
|
145256
|
+
update(session);
|
|
145257
|
+
writeLedger(ctx.ledgerPath, read.ledger, fence);
|
|
145258
|
+
};
|
|
145259
|
+
const exitTransaction = (fence) => {
|
|
145260
|
+
const read = readLedger2(ctx.ledgerPath);
|
|
145261
|
+
if (!read.ok)
|
|
145262
|
+
return;
|
|
145263
|
+
const entry = read.ledger.entries[key];
|
|
145264
|
+
if (!entry)
|
|
145265
|
+
return;
|
|
145266
|
+
const index = entry.sessions.findIndex((s) => s.id === sessionId);
|
|
145267
|
+
if (index < 0)
|
|
145268
|
+
return;
|
|
145269
|
+
const table = ctx.processTable();
|
|
145270
|
+
if (childMark && markLive(childMark, table))
|
|
145271
|
+
return;
|
|
145272
|
+
entry.sessions.splice(index, 1);
|
|
145273
|
+
const othersLive = entry.sessions.some((s) => sessionLiveness(s, table) !== "ended");
|
|
145274
|
+
if (!othersLive) {
|
|
145275
|
+
entry.sessions = [];
|
|
145276
|
+
settleEntry(ctx, read.ledger, key, false, fence);
|
|
145277
|
+
}
|
|
145278
|
+
writeLedger(ctx.ledgerPath, read.ledger, fence);
|
|
145279
|
+
};
|
|
145280
|
+
return {
|
|
145281
|
+
registered: true,
|
|
145282
|
+
recordSettingsArg: async (settingsPath) => {
|
|
145283
|
+
try {
|
|
145284
|
+
await withFileLock(lockPath, lockOpts, async (handle) => updateRow(fenceOf(handle), (s) => {
|
|
145285
|
+
s.settingsArg = settingsPath;
|
|
145286
|
+
}));
|
|
145287
|
+
} catch (err) {
|
|
145288
|
+
log(`[model-restore] settings path not recorded: ${err?.message ?? err}`);
|
|
145289
|
+
}
|
|
145290
|
+
},
|
|
145291
|
+
recordChild: (pid) => {
|
|
145292
|
+
const mark = { pid, startedEpochMs: Date.now() };
|
|
145293
|
+
childMark = mark;
|
|
145294
|
+
const apply = (handle) => updateRow(fenceOf(handle), (s) => {
|
|
145295
|
+
s.child = mark;
|
|
145296
|
+
});
|
|
145297
|
+
try {
|
|
145298
|
+
const handle = acquireFileLockSync(lockPath, {
|
|
145299
|
+
staleMs: LOCK_STALE_MS,
|
|
145300
|
+
waitMs: SYNC_LOCK_WAIT_MS
|
|
145301
|
+
});
|
|
145302
|
+
try {
|
|
145303
|
+
apply(handle);
|
|
145304
|
+
} finally {
|
|
145305
|
+
handle.release();
|
|
145306
|
+
}
|
|
145307
|
+
} catch {
|
|
145308
|
+
withFileLock(lockPath, lockOpts, async (handle) => apply(handle)).catch((err) => log(`[model-restore] child not recorded: ${err?.message ?? err}`));
|
|
145309
|
+
}
|
|
145310
|
+
},
|
|
145311
|
+
end: async () => {
|
|
145312
|
+
if (ended)
|
|
145313
|
+
return;
|
|
145314
|
+
ended = true;
|
|
145315
|
+
try {
|
|
145316
|
+
await withFileLock(lockPath, lockOpts, async (handle) => exitTransaction(fenceOf(handle)));
|
|
145317
|
+
} catch (err) {
|
|
145318
|
+
log(`[model-restore] exit skipped: ${err?.message ?? err}`);
|
|
145319
|
+
}
|
|
145320
|
+
},
|
|
145321
|
+
endSync: () => {
|
|
145322
|
+
if (ended)
|
|
145323
|
+
return;
|
|
145324
|
+
ended = true;
|
|
145325
|
+
try {
|
|
145326
|
+
const handle = acquireFileLockSync(lockPath, {
|
|
145327
|
+
staleMs: LOCK_STALE_MS,
|
|
145328
|
+
waitMs: SYNC_LOCK_WAIT_MS
|
|
145329
|
+
});
|
|
145330
|
+
try {
|
|
145331
|
+
exitTransaction(fenceOf(handle));
|
|
145332
|
+
} finally {
|
|
145333
|
+
handle.release();
|
|
145334
|
+
}
|
|
145335
|
+
} catch (err) {
|
|
145336
|
+
log(`[model-restore] deadline exit skipped: ${err?.message ?? err}`);
|
|
145337
|
+
}
|
|
145338
|
+
}
|
|
145339
|
+
};
|
|
145340
|
+
}
|
|
145341
|
+
var LOCK_TIMEOUT_MS = 2000, LOCK_HEARTBEAT_MS = 2000, SYNC_LOCK_WAIT_MS = 250, LOCK_STALE_MS = 1e4, RESTORE_ROUNDS = 3, GIVE_UP_AFTER_MS, TEMP_PREFIX = ".settings.json.claudish-", realRestoreFs, reportedUnreadableLedgers, INERT_WATCH;
|
|
145342
|
+
var init_model_setting_restore = __esm(() => {
|
|
145343
|
+
init_atomic_write();
|
|
145344
|
+
init_file_lock();
|
|
145345
|
+
init_claude_runner();
|
|
145346
|
+
init_logger();
|
|
145347
|
+
init_process_identity();
|
|
145348
|
+
init_model_setting_ledger_path();
|
|
145349
|
+
GIVE_UP_AFTER_MS = 14 * 24 * 60 * 60 * 1000;
|
|
145350
|
+
realRestoreFs = {
|
|
145351
|
+
realpath: (path) => realpathSync11.native(path),
|
|
145352
|
+
readFile: (path) => readFileSync59(path),
|
|
145353
|
+
stat: (path) => toFileStat(statSync32(path)),
|
|
145354
|
+
writeNew: (path, data, mode) => {
|
|
145355
|
+
const fd = openSync20(path, "wx", mode);
|
|
145356
|
+
try {
|
|
145357
|
+
fchmodSync2(fd, mode);
|
|
145358
|
+
writeWholeSync(fd, data);
|
|
145359
|
+
fsyncSync4(fd);
|
|
145360
|
+
} finally {
|
|
145361
|
+
closeSync21(fd);
|
|
145362
|
+
}
|
|
145363
|
+
},
|
|
145364
|
+
rename: (from, to) => renameSync15(from, to),
|
|
145365
|
+
unlink: (path) => unlinkSync16(path)
|
|
145366
|
+
};
|
|
145367
|
+
reportedUnreadableLedgers = new Set;
|
|
145368
|
+
INERT_WATCH = {
|
|
145369
|
+
registered: false,
|
|
145370
|
+
recordSettingsArg: async () => {},
|
|
145371
|
+
recordChild: () => {},
|
|
145372
|
+
end: async () => {},
|
|
145373
|
+
endSync: () => {}
|
|
145374
|
+
};
|
|
145375
|
+
});
|
|
145376
|
+
|
|
143670
145377
|
// src/session/baseline-pricing.ts
|
|
143671
145378
|
function resolveBaseline(alias, label) {
|
|
143672
145379
|
const entry = findEntryByAlias(alias);
|
|
@@ -143702,11 +145409,11 @@ var exports_session_stats = {};
|
|
|
143702
145409
|
__export(exports_session_stats, {
|
|
143703
145410
|
readSessionStats: () => readSessionStats
|
|
143704
145411
|
});
|
|
143705
|
-
import { readFileSync as
|
|
145412
|
+
import { readFileSync as readFileSync60 } from "fs";
|
|
143706
145413
|
function readSessionStats(port, opts) {
|
|
143707
145414
|
let raw;
|
|
143708
145415
|
try {
|
|
143709
|
-
raw = JSON.parse(
|
|
145416
|
+
raw = JSON.parse(readFileSync60(resolveTokenFilePath(port), "utf-8"));
|
|
143710
145417
|
} catch {
|
|
143711
145418
|
return null;
|
|
143712
145419
|
}
|
|
@@ -144093,12 +145800,12 @@ init_launch_env();
|
|
|
144093
145800
|
init_op_source();
|
|
144094
145801
|
init_startup_trace();
|
|
144095
145802
|
init_picker_cancelled();
|
|
144096
|
-
import { existsSync as existsSync50, readFileSync as
|
|
144097
|
-
import { join as
|
|
145803
|
+
import { existsSync as existsSync50, readFileSync as readFileSync61 } from "fs";
|
|
145804
|
+
import { join as join79, resolve as resolve16 } from "path";
|
|
144098
145805
|
|
|
144099
145806
|
// src/tui/runtime/should-open-picker.ts
|
|
144100
145807
|
function noModelConfigured(gate) {
|
|
144101
|
-
return !gate.monitor && !gate.advisorNativeSession && !gate.model && !gate.hasProfileTiers;
|
|
145808
|
+
return !gate.monitor && !gate.advisorNativeSession && !gate.hasModelListings && !gate.model && !gate.hasProfileTiers;
|
|
144102
145809
|
}
|
|
144103
145810
|
function shouldOpenPicker(gate, tty) {
|
|
144104
145811
|
return noModelConfigured(gate) && Boolean(gate.interactive) && tty;
|
|
@@ -144111,7 +145818,7 @@ function requiresExplicitModel(gate, tty) {
|
|
|
144111
145818
|
var autoloadDropped = [...droppedAtLaunch, ...takeLauncherDropped(process.env)];
|
|
144112
145819
|
var dotenvText;
|
|
144113
145820
|
try {
|
|
144114
|
-
dotenvText =
|
|
145821
|
+
dotenvText = readFileSync61(join79(process.cwd(), ".env"));
|
|
144115
145822
|
} catch {}
|
|
144116
145823
|
if (dotenvText !== undefined) {
|
|
144117
145824
|
await Promise.resolve().then(() => init_dotenv_allowlist());
|
|
@@ -144228,7 +145935,7 @@ async function applyOpImport() {
|
|
|
144228
145935
|
async function applyConfigOverride() {
|
|
144229
145936
|
await Promise.resolve();
|
|
144230
145937
|
const plan = planConfigOverride(process.argv.slice(2), process.env, {
|
|
144231
|
-
resolve:
|
|
145938
|
+
resolve: resolve16,
|
|
144232
145939
|
exists: existsSync50
|
|
144233
145940
|
});
|
|
144234
145941
|
if (plan.kind === "none")
|
|
@@ -144423,6 +146130,35 @@ if (isMcpMode) {
|
|
|
144423
146130
|
} else {
|
|
144424
146131
|
runCli();
|
|
144425
146132
|
}
|
|
146133
|
+
async function reportModelLineup(config, lineup) {
|
|
146134
|
+
await Promise.resolve().then(() => init_model_lineup());
|
|
146135
|
+
await Promise.resolve().then(() => init_claude_runner());
|
|
146136
|
+
await Promise.resolve().then(() => init_native_route());
|
|
146137
|
+
await Promise.resolve().then(() => init_redact());
|
|
146138
|
+
await Promise.resolve().then(() => init_logger());
|
|
146139
|
+
const computed = await computeMainThreadContextWindow(config);
|
|
146140
|
+
config.mainThreadWindow = computed;
|
|
146141
|
+
const picker = modelPickerSetting(lineup.rows, modelPickerSources(config, process.env));
|
|
146142
|
+
const inherited = scrubChildModelVars(config, { ...process.env });
|
|
146143
|
+
const posture = startsOnClaudeSubscription(config) ? "claude-start" : typeof config.model === "string" ? nativeRouteFor(config.model) !== null ? "claude-model-start" : "foreign-start" : isProxyAuthMode(config) ? "tiers" : "claude-model-start";
|
|
146144
|
+
const lines = lineupReport(lineup, {
|
|
146145
|
+
sizedFor: sessionWindow(process.env, computed),
|
|
146146
|
+
settingsNotices: picker.notices,
|
|
146147
|
+
posture,
|
|
146148
|
+
inheritedModelVars: inherited.survived
|
|
146149
|
+
});
|
|
146150
|
+
if (inherited.removed.length > 0) {
|
|
146151
|
+
lines.push(`[claudish] /model: removed ${inherited.removed.join(", ")}, set by a parent claudish session, from this session`);
|
|
146152
|
+
}
|
|
146153
|
+
for (const line of lines)
|
|
146154
|
+
logStderr(redactSecrets(line.replace(/^\[claudish\] /, "")));
|
|
146155
|
+
const userRows = routedUserRows(picker.setting.options, lineup.rows);
|
|
146156
|
+
config.modelLineup = {
|
|
146157
|
+
rows: lineup.rows,
|
|
146158
|
+
picker: picker.setting,
|
|
146159
|
+
...userRows.length > 0 ? { userRows } : {}
|
|
146160
|
+
};
|
|
146161
|
+
}
|
|
144426
146162
|
async function runCli() {
|
|
144427
146163
|
const endImports = beginSpan("startup:cli-imports");
|
|
144428
146164
|
await Promise.resolve().then(() => init_claude_runner());
|
|
@@ -144470,17 +146206,25 @@ async function runCli() {
|
|
|
144470
146206
|
await Promise.resolve().then(() => init_endpoint_registration());
|
|
144471
146207
|
ensureEndpointsRegistered();
|
|
144472
146208
|
});
|
|
146209
|
+
if (cliConfig._modelFlags?.hasLineup) {
|
|
146210
|
+
await Promise.resolve().then(() => init_claude_launch());
|
|
146211
|
+
const decision = decideModelListings(cliConfig, cliConfig._modelFlags);
|
|
146212
|
+
if (!decision.ok) {
|
|
146213
|
+
console.error(`[claudish] Error: ${decision.message}`);
|
|
146214
|
+
process.exit(1);
|
|
146215
|
+
}
|
|
146216
|
+
}
|
|
144473
146217
|
if (cliConfig.team && cliConfig.team.length > 0) {
|
|
144474
146218
|
let prompt = cliConfig.claudeArgs.join(" ");
|
|
144475
146219
|
if (cliConfig.inputFile) {
|
|
144476
|
-
prompt =
|
|
146220
|
+
prompt = readFileSync61(cliConfig.inputFile, "utf-8");
|
|
144477
146221
|
}
|
|
144478
146222
|
if (!prompt.trim()) {
|
|
144479
146223
|
console.error("Error: --team requires a prompt (positional args or -f <file>)");
|
|
144480
146224
|
process.exit(1);
|
|
144481
146225
|
}
|
|
144482
146226
|
const mode = cliConfig.teamMode ?? "default";
|
|
144483
|
-
const sessionPath =
|
|
146227
|
+
const sessionPath = join79(process.cwd(), `.claudish-team-${Date.now()}`);
|
|
144484
146228
|
if (mode === "json") {
|
|
144485
146229
|
await Promise.resolve().then(() => init_pane());
|
|
144486
146230
|
await Promise.resolve().then(() => init_team_orchestrator());
|
|
@@ -144500,9 +146244,9 @@ async function runCli() {
|
|
|
144500
146244
|
const status = await runModels(sessionPath);
|
|
144501
146245
|
const result = { ...status, responses: {} };
|
|
144502
146246
|
for (const anonId of Object.keys(status.models)) {
|
|
144503
|
-
const responsePath =
|
|
146247
|
+
const responsePath = join79(sessionPath, `response-${anonId}.md`);
|
|
144504
146248
|
try {
|
|
144505
|
-
const raw =
|
|
146249
|
+
const raw = readFileSync61(responsePath, "utf-8").trim();
|
|
144506
146250
|
try {
|
|
144507
146251
|
result.responses[anonId] = JSON.parse(raw);
|
|
144508
146252
|
} catch {
|
|
@@ -144619,6 +146363,7 @@ Team Status`);
|
|
|
144619
146363
|
interactive: cliConfig.interactive,
|
|
144620
146364
|
monitor: cliConfig.monitor,
|
|
144621
146365
|
advisorNativeSession,
|
|
146366
|
+
hasModelListings: (cliConfig.modelListings?.length ?? 0) > 0,
|
|
144622
146367
|
model: cliConfig.model,
|
|
144623
146368
|
hasProfileTiers
|
|
144624
146369
|
});
|
|
@@ -144740,6 +146485,20 @@ Team Status`);
|
|
|
144740
146485
|
`);
|
|
144741
146486
|
}
|
|
144742
146487
|
const launchSigning = preparedLaunch.signing;
|
|
146488
|
+
const lineupListings = cliConfig.modelListings ?? [];
|
|
146489
|
+
let lineupPromise = null;
|
|
146490
|
+
if (lineupListings.length > 0 && cliConfig.interactive) {
|
|
146491
|
+
lineupPromise = Promise.resolve().then(() => (init_model_lineup(), {})).then((m) => traceSpan("startup:model-lineup", () => buildModelLineup(lineupListings))).catch((err) => ({
|
|
146492
|
+
rows: [],
|
|
146493
|
+
outcomes: lineupListings.map((l) => ({
|
|
146494
|
+
kind: "not-listed",
|
|
146495
|
+
provider: l.provider,
|
|
146496
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
146497
|
+
}))
|
|
146498
|
+
}));
|
|
146499
|
+
} else if (lineupListings.length > 0) {
|
|
146500
|
+
log("[model-lineup] print mode: listing entries accepted, no /model list is fetched");
|
|
146501
|
+
}
|
|
144743
146502
|
let advisorRuntime;
|
|
144744
146503
|
if (cliConfig.advisor) {
|
|
144745
146504
|
await Promise.resolve().then(() => init_advisor_startup());
|
|
@@ -144809,9 +146568,23 @@ Team Status`);
|
|
|
144809
146568
|
if (cliConfig.contextWindow !== undefined) {
|
|
144810
146569
|
process.env.CLAUDISH_CONTEXT_WINDOW = String(cliConfig.contextWindow);
|
|
144811
146570
|
}
|
|
146571
|
+
if (lineupPromise) {
|
|
146572
|
+
const lineup = await lineupPromise;
|
|
146573
|
+
await reportModelLineup(cliConfig, lineup);
|
|
146574
|
+
}
|
|
144812
146575
|
const proxy = await traceSpan("startup:proxy-start", () => createProxyServer(port, cliConfig.monitor ? undefined : cliConfig.openrouterApiKey, cliConfig.monitor ? undefined : explicitModel, cliConfig.monitor, launchSigning ? undefined : cliConfig.anthropicApiKey, modelMap, {
|
|
144813
146576
|
...launchSigning ? { nativeSigning: launchSigning } : {},
|
|
144814
146577
|
...cliConfig.claudeLaunch === "api" && cliConfig.claudeLaunchModel ? { claudeApiMainModel: cliConfig.claudeLaunchModel } : {},
|
|
146578
|
+
...cliConfig.modelLineup ? {
|
|
146579
|
+
modelLineup: [
|
|
146580
|
+
...cliConfig.modelLineup.rows,
|
|
146581
|
+
...cliConfig.modelLineup.userRows ?? []
|
|
146582
|
+
].map((row) => ({
|
|
146583
|
+
model: row.model,
|
|
146584
|
+
label: row.label
|
|
146585
|
+
}))
|
|
146586
|
+
} : {},
|
|
146587
|
+
...claudeRowsAsPicked(cliConfig) ? { claudeRowsAsPicked: true } : {},
|
|
144815
146588
|
apiBillingOptIn: wantsAnthropicApiBilling(cliConfig),
|
|
144816
146589
|
advisorKeyLookup: advisorKeyLookupAllowed(cliConfig),
|
|
144817
146590
|
summarizeTools: cliConfig.summarizeTools,
|
|
@@ -144829,6 +146602,30 @@ Team Status`);
|
|
|
144829
146602
|
codeMode: cliConfig.codeMode,
|
|
144830
146603
|
hostMode: isPaneChild() ? "pane-child" : cliConfig.interactive ? "interactive" : "other"
|
|
144831
146604
|
}));
|
|
146605
|
+
let modelSettingWatch = null;
|
|
146606
|
+
if (cliConfig.interactive) {
|
|
146607
|
+
await Promise.resolve().then(() => init_model_setting_ledger_path());
|
|
146608
|
+
const { statSync } = await import("fs");
|
|
146609
|
+
let ledgerPending = false;
|
|
146610
|
+
try {
|
|
146611
|
+
ledgerPending = statSync(modelSettingLedgerPath(process.env), { throwIfNoEntry: false }) !== undefined;
|
|
146612
|
+
} catch {
|
|
146613
|
+
ledgerPending = false;
|
|
146614
|
+
}
|
|
146615
|
+
if (ledgerPending || cliConfig.modelLineup) {
|
|
146616
|
+
const restore = await Promise.resolve().then(() => (init_model_setting_restore(), {}));
|
|
146617
|
+
if (ledgerPending)
|
|
146618
|
+
await sweepModelSettingLedger();
|
|
146619
|
+
if (cliConfig.modelLineup) {
|
|
146620
|
+
modelSettingWatch = await beginModelSettingWatch(cliConfig.modelLineup.rows.map((row) => row.model));
|
|
146621
|
+
if (modelSettingWatch.registered && cliConfig.modelLineup.rows.length > 0) {
|
|
146622
|
+
await Promise.resolve().then(() => init_model_lineup());
|
|
146623
|
+
await Promise.resolve().then(() => init_logger());
|
|
146624
|
+
logStderr(MODEL_RESTORE_PROMISE);
|
|
146625
|
+
}
|
|
146626
|
+
}
|
|
146627
|
+
}
|
|
146628
|
+
}
|
|
144832
146629
|
const diag = createDiagOutput({
|
|
144833
146630
|
interactive: cliConfig.interactive,
|
|
144834
146631
|
diagMode: cliConfig.diagMode
|
|
@@ -144846,7 +146643,11 @@ Team Status`);
|
|
|
144846
146643
|
diag.cleanup();
|
|
144847
146644
|
};
|
|
144848
146645
|
try {
|
|
144849
|
-
exitCode = await runClaudeWithProxy(cliConfig, proxy.url, cleanupDiag
|
|
146646
|
+
exitCode = await runClaudeWithProxy(cliConfig, proxy.url, cleanupDiag, modelSettingWatch ? {
|
|
146647
|
+
beforeSpawn: modelSettingWatch.recordSettingsArg,
|
|
146648
|
+
onChildSpawned: modelSettingWatch.recordChild,
|
|
146649
|
+
onDeadline: modelSettingWatch.endSync
|
|
146650
|
+
} : {});
|
|
144850
146651
|
} finally {
|
|
144851
146652
|
setDiagOutput(null);
|
|
144852
146653
|
cleanupDiag();
|
|
@@ -144856,6 +146657,7 @@ Team Status`);
|
|
|
144856
146657
|
[claudish] Shutting down proxy server...`);
|
|
144857
146658
|
}
|
|
144858
146659
|
await proxy.shutdown();
|
|
146660
|
+
await modelSettingWatch?.end();
|
|
144859
146661
|
}
|
|
144860
146662
|
if (!cliConfig.quiet) {
|
|
144861
146663
|
const write = cliConfig.interactive ? console.log : console.error;
|