claudish 14.26.0 → 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 +1979 -178
- 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-
|
|
14148
|
+
fetchedAt: "2026-11-16T00:56:54.374Z",
|
|
14132
14149
|
format: 1,
|
|
14133
14150
|
recommendations: {
|
|
14134
14151
|
contractVersion: 3,
|
|
@@ -14234,11 +14251,11 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14234
14251
|
tier: "luxury"
|
|
14235
14252
|
}
|
|
14236
14253
|
],
|
|
14237
|
-
generationId: "g-
|
|
14254
|
+
generationId: "g-20261115161901457-250a0705"
|
|
14238
14255
|
},
|
|
14239
14256
|
source: "https://us-central1-claudish-6da10.cloudfunctions.net"
|
|
14240
14257
|
},
|
|
14241
|
-
catalogGenerationId: "g-
|
|
14258
|
+
catalogGenerationId: "g-20261115161901457-250a0705",
|
|
14242
14259
|
entries: [
|
|
14243
14260
|
{
|
|
14244
14261
|
aggregators: [
|
|
@@ -15270,9 +15287,9 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15270
15287
|
],
|
|
15271
15288
|
aliases: [
|
|
15272
15289
|
"google/gemini-4-argon",
|
|
15290
|
+
"gemini-4-argon-low",
|
|
15273
15291
|
"gemini-4-argon-medium",
|
|
15274
|
-
"gemini-4-argon-high"
|
|
15275
|
-
"gemini-4-argon-low"
|
|
15292
|
+
"gemini-4-argon-high"
|
|
15276
15293
|
],
|
|
15277
15294
|
contextWindow: 1048576,
|
|
15278
15295
|
contractVersion: 3,
|
|
@@ -15425,9 +15442,9 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15425
15442
|
],
|
|
15426
15443
|
aliases: [
|
|
15427
15444
|
"google/gemini-4-carbon",
|
|
15428
|
-
"gemini-4-carbon-
|
|
15445
|
+
"gemini-4-carbon-high",
|
|
15429
15446
|
"gemini-4-carbon-low",
|
|
15430
|
-
"gemini-4-carbon-
|
|
15447
|
+
"gemini-4-carbon-medium"
|
|
15431
15448
|
],
|
|
15432
15449
|
contextWindow: 1048576,
|
|
15433
15450
|
contractVersion: 3,
|
|
@@ -15580,10 +15597,10 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15580
15597
|
],
|
|
15581
15598
|
aliases: [
|
|
15582
15599
|
"google/gemini-4-hydrogen",
|
|
15583
|
-
"gemini-4-hydrogen-xhigh",
|
|
15584
|
-
"gemini-4-hydrogen-medium",
|
|
15585
15600
|
"gemini-4-hydrogen-high",
|
|
15586
|
-
"gemini-4-hydrogen-low"
|
|
15601
|
+
"gemini-4-hydrogen-low",
|
|
15602
|
+
"gemini-4-hydrogen-medium",
|
|
15603
|
+
"gemini-4-hydrogen-xhigh"
|
|
15587
15604
|
],
|
|
15588
15605
|
contextWindow: 1048576,
|
|
15589
15606
|
contractVersion: 3,
|
|
@@ -18249,7 +18266,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
18249
18266
|
supportsVision: true
|
|
18250
18267
|
}
|
|
18251
18268
|
],
|
|
18252
|
-
lastUpdated: "2026-11-
|
|
18269
|
+
lastUpdated: "2026-11-15T16:19:01.457Z",
|
|
18253
18270
|
models: [],
|
|
18254
18271
|
plans: [
|
|
18255
18272
|
{
|
|
@@ -19000,64 +19017,64 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19000
19017
|
id: "google-antigravity",
|
|
19001
19018
|
inclusions: [
|
|
19002
19019
|
{
|
|
19003
|
-
externalModelId: "claude-
|
|
19020
|
+
externalModelId: "claude-sonnet-5-5-high",
|
|
19004
19021
|
kind: "provider_model",
|
|
19005
19022
|
provider: "antigravity",
|
|
19006
19023
|
resolution: {
|
|
19007
|
-
modelId: "claude-
|
|
19024
|
+
modelId: "claude-sonnet-5-5",
|
|
19008
19025
|
status: "mapped"
|
|
19009
19026
|
},
|
|
19010
|
-
sourceText: "claude-
|
|
19027
|
+
sourceText: "claude-sonnet-5-5-high"
|
|
19011
19028
|
},
|
|
19012
19029
|
{
|
|
19013
|
-
externalModelId: "gemini-4-
|
|
19030
|
+
externalModelId: "gemini-4-hydrogen-high",
|
|
19014
19031
|
kind: "provider_model",
|
|
19015
19032
|
provider: "antigravity",
|
|
19016
19033
|
resolution: {
|
|
19017
|
-
modelId: "gemini-4-
|
|
19034
|
+
modelId: "gemini-4-hydrogen",
|
|
19018
19035
|
status: "mapped"
|
|
19019
19036
|
},
|
|
19020
|
-
sourceText: "gemini-4-
|
|
19037
|
+
sourceText: "gemini-4-hydrogen-high"
|
|
19021
19038
|
},
|
|
19022
19039
|
{
|
|
19023
|
-
externalModelId: "
|
|
19040
|
+
externalModelId: "gemini-4-hydrogen-low",
|
|
19024
19041
|
kind: "provider_model",
|
|
19025
19042
|
provider: "antigravity",
|
|
19026
19043
|
resolution: {
|
|
19027
|
-
modelId: "
|
|
19044
|
+
modelId: "gemini-4-hydrogen",
|
|
19028
19045
|
status: "mapped"
|
|
19029
19046
|
},
|
|
19030
|
-
sourceText: "
|
|
19047
|
+
sourceText: "gemini-4-hydrogen-low"
|
|
19031
19048
|
},
|
|
19032
19049
|
{
|
|
19033
|
-
externalModelId: "gemini-4-carbon-
|
|
19050
|
+
externalModelId: "gemini-4-carbon-high",
|
|
19034
19051
|
kind: "provider_model",
|
|
19035
19052
|
provider: "antigravity",
|
|
19036
19053
|
resolution: {
|
|
19037
19054
|
modelId: "gemini-4-carbon",
|
|
19038
19055
|
status: "mapped"
|
|
19039
19056
|
},
|
|
19040
|
-
sourceText: "gemini-4-carbon-
|
|
19057
|
+
sourceText: "gemini-4-carbon-high"
|
|
19041
19058
|
},
|
|
19042
19059
|
{
|
|
19043
|
-
externalModelId: "gemini-4-hydrogen-
|
|
19060
|
+
externalModelId: "gemini-4-hydrogen-medium",
|
|
19044
19061
|
kind: "provider_model",
|
|
19045
19062
|
provider: "antigravity",
|
|
19046
19063
|
resolution: {
|
|
19047
19064
|
modelId: "gemini-4-hydrogen",
|
|
19048
19065
|
status: "mapped"
|
|
19049
19066
|
},
|
|
19050
|
-
sourceText: "gemini-4-hydrogen-
|
|
19067
|
+
sourceText: "gemini-4-hydrogen-medium"
|
|
19051
19068
|
},
|
|
19052
19069
|
{
|
|
19053
|
-
externalModelId: "
|
|
19070
|
+
externalModelId: "claude-opus-5-5-low",
|
|
19054
19071
|
kind: "provider_model",
|
|
19055
19072
|
provider: "antigravity",
|
|
19056
19073
|
resolution: {
|
|
19057
|
-
modelId: "
|
|
19074
|
+
modelId: "claude-opus-5-5",
|
|
19058
19075
|
status: "mapped"
|
|
19059
19076
|
},
|
|
19060
|
-
sourceText: "
|
|
19077
|
+
sourceText: "claude-opus-5-5-low"
|
|
19061
19078
|
},
|
|
19062
19079
|
{
|
|
19063
19080
|
externalModelId: "gemini-4-carbon-low",
|
|
@@ -19070,94 +19087,94 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19070
19087
|
sourceText: "gemini-4-carbon-low"
|
|
19071
19088
|
},
|
|
19072
19089
|
{
|
|
19073
|
-
externalModelId: "
|
|
19090
|
+
externalModelId: "gemini-4-hydrogen-xhigh",
|
|
19074
19091
|
kind: "provider_model",
|
|
19075
19092
|
provider: "antigravity",
|
|
19076
19093
|
resolution: {
|
|
19077
|
-
modelId: "
|
|
19094
|
+
modelId: "gemini-4-hydrogen",
|
|
19078
19095
|
status: "mapped"
|
|
19079
19096
|
},
|
|
19080
|
-
sourceText: "
|
|
19097
|
+
sourceText: "gemini-4-hydrogen-xhigh"
|
|
19081
19098
|
},
|
|
19082
19099
|
{
|
|
19083
|
-
externalModelId: "
|
|
19100
|
+
externalModelId: "gemini-4-argon-low",
|
|
19084
19101
|
kind: "provider_model",
|
|
19085
19102
|
provider: "antigravity",
|
|
19086
19103
|
resolution: {
|
|
19087
|
-
modelId: "
|
|
19104
|
+
modelId: "gemini-4-argon",
|
|
19088
19105
|
status: "mapped"
|
|
19089
19106
|
},
|
|
19090
|
-
sourceText: "
|
|
19107
|
+
sourceText: "gemini-4-argon-low"
|
|
19091
19108
|
},
|
|
19092
19109
|
{
|
|
19093
|
-
externalModelId: "gemini-4-
|
|
19110
|
+
externalModelId: "gemini-4-argon-medium",
|
|
19094
19111
|
kind: "provider_model",
|
|
19095
19112
|
provider: "antigravity",
|
|
19096
19113
|
resolution: {
|
|
19097
|
-
modelId: "gemini-4-
|
|
19114
|
+
modelId: "gemini-4-argon",
|
|
19098
19115
|
status: "mapped"
|
|
19099
19116
|
},
|
|
19100
|
-
sourceText: "gemini-4-
|
|
19117
|
+
sourceText: "gemini-4-argon-medium"
|
|
19101
19118
|
},
|
|
19102
19119
|
{
|
|
19103
|
-
externalModelId: "
|
|
19120
|
+
externalModelId: "gemini-4-carbon-medium",
|
|
19104
19121
|
kind: "provider_model",
|
|
19105
19122
|
provider: "antigravity",
|
|
19106
19123
|
resolution: {
|
|
19107
|
-
modelId: "
|
|
19124
|
+
modelId: "gemini-4-carbon",
|
|
19108
19125
|
status: "mapped"
|
|
19109
19126
|
},
|
|
19110
|
-
sourceText: "
|
|
19127
|
+
sourceText: "gemini-4-carbon-medium"
|
|
19111
19128
|
},
|
|
19112
19129
|
{
|
|
19113
|
-
externalModelId: "
|
|
19130
|
+
externalModelId: "claude-sonnet-5-5-medium",
|
|
19114
19131
|
kind: "provider_model",
|
|
19115
19132
|
provider: "antigravity",
|
|
19116
19133
|
resolution: {
|
|
19117
|
-
modelId: "
|
|
19134
|
+
modelId: "claude-sonnet-5-5",
|
|
19118
19135
|
status: "mapped"
|
|
19119
19136
|
},
|
|
19120
|
-
sourceText: "
|
|
19137
|
+
sourceText: "claude-sonnet-5-5-medium"
|
|
19121
19138
|
},
|
|
19122
19139
|
{
|
|
19123
|
-
externalModelId: "claude-
|
|
19140
|
+
externalModelId: "claude-sonnet-5-5-low",
|
|
19124
19141
|
kind: "provider_model",
|
|
19125
19142
|
provider: "antigravity",
|
|
19126
19143
|
resolution: {
|
|
19127
|
-
modelId: "claude-
|
|
19144
|
+
modelId: "claude-sonnet-5-5",
|
|
19128
19145
|
status: "mapped"
|
|
19129
19146
|
},
|
|
19130
|
-
sourceText: "claude-
|
|
19147
|
+
sourceText: "claude-sonnet-5-5-low"
|
|
19131
19148
|
},
|
|
19132
19149
|
{
|
|
19133
|
-
externalModelId: "
|
|
19150
|
+
externalModelId: "claude-opus-5-5-medium",
|
|
19134
19151
|
kind: "provider_model",
|
|
19135
19152
|
provider: "antigravity",
|
|
19136
19153
|
resolution: {
|
|
19137
|
-
modelId: "
|
|
19154
|
+
modelId: "claude-opus-5-5",
|
|
19138
19155
|
status: "mapped"
|
|
19139
19156
|
},
|
|
19140
|
-
sourceText: "
|
|
19157
|
+
sourceText: "claude-opus-5-5-medium"
|
|
19141
19158
|
},
|
|
19142
19159
|
{
|
|
19143
|
-
externalModelId: "gemini-4-argon-
|
|
19160
|
+
externalModelId: "gemini-4-argon-high",
|
|
19144
19161
|
kind: "provider_model",
|
|
19145
19162
|
provider: "antigravity",
|
|
19146
19163
|
resolution: {
|
|
19147
19164
|
modelId: "gemini-4-argon",
|
|
19148
19165
|
status: "mapped"
|
|
19149
19166
|
},
|
|
19150
|
-
sourceText: "gemini-4-argon-
|
|
19167
|
+
sourceText: "gemini-4-argon-high"
|
|
19151
19168
|
},
|
|
19152
19169
|
{
|
|
19153
|
-
externalModelId: "
|
|
19170
|
+
externalModelId: "claude-opus-5-5-high",
|
|
19154
19171
|
kind: "provider_model",
|
|
19155
19172
|
provider: "antigravity",
|
|
19156
19173
|
resolution: {
|
|
19157
|
-
modelId: "
|
|
19174
|
+
modelId: "claude-opus-5-5",
|
|
19158
19175
|
status: "mapped"
|
|
19159
19176
|
},
|
|
19160
|
-
sourceText: "
|
|
19177
|
+
sourceText: "claude-opus-5-5-high"
|
|
19161
19178
|
}
|
|
19162
19179
|
],
|
|
19163
19180
|
modelDiscovery: "client",
|
|
@@ -19501,64 +19518,64 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19501
19518
|
sourceText: "mimo-v2.6-flash"
|
|
19502
19519
|
},
|
|
19503
19520
|
{
|
|
19504
|
-
externalModelId: "
|
|
19521
|
+
externalModelId: "glm-5.3-flash",
|
|
19505
19522
|
kind: "provider_model",
|
|
19506
19523
|
provider: "ollamacloud",
|
|
19507
19524
|
resolution: {
|
|
19508
|
-
modelId: "
|
|
19525
|
+
modelId: "glm-5.3-flash",
|
|
19509
19526
|
status: "mapped"
|
|
19510
19527
|
},
|
|
19511
|
-
sourceText: "
|
|
19528
|
+
sourceText: "glm-5.3-flash"
|
|
19512
19529
|
},
|
|
19513
19530
|
{
|
|
19514
|
-
externalModelId: "
|
|
19531
|
+
externalModelId: "glm-5.3",
|
|
19515
19532
|
kind: "provider_model",
|
|
19516
19533
|
provider: "ollamacloud",
|
|
19517
19534
|
resolution: {
|
|
19518
|
-
modelId: "
|
|
19535
|
+
modelId: "glm-5.3",
|
|
19519
19536
|
status: "mapped"
|
|
19520
19537
|
},
|
|
19521
|
-
sourceText: "
|
|
19538
|
+
sourceText: "glm-5.3"
|
|
19522
19539
|
},
|
|
19523
19540
|
{
|
|
19524
|
-
externalModelId: "
|
|
19541
|
+
externalModelId: "deepseek-v4.1-flash",
|
|
19525
19542
|
kind: "provider_model",
|
|
19526
19543
|
provider: "ollamacloud",
|
|
19527
19544
|
resolution: {
|
|
19528
|
-
modelId: "
|
|
19545
|
+
modelId: "deepseek-v4.1-flash",
|
|
19529
19546
|
status: "mapped"
|
|
19530
19547
|
},
|
|
19531
|
-
sourceText: "
|
|
19548
|
+
sourceText: "deepseek-v4.1-flash"
|
|
19532
19549
|
},
|
|
19533
19550
|
{
|
|
19534
|
-
externalModelId: "
|
|
19551
|
+
externalModelId: "minimax-m3.1-flash",
|
|
19535
19552
|
kind: "provider_model",
|
|
19536
19553
|
provider: "ollamacloud",
|
|
19537
19554
|
resolution: {
|
|
19538
|
-
modelId: "
|
|
19555
|
+
modelId: "minimax-m3.1-flash",
|
|
19539
19556
|
status: "mapped"
|
|
19540
19557
|
},
|
|
19541
|
-
sourceText: "
|
|
19558
|
+
sourceText: "minimax-m3.1-flash"
|
|
19542
19559
|
},
|
|
19543
19560
|
{
|
|
19544
|
-
externalModelId: "
|
|
19561
|
+
externalModelId: "kimi-k3.1-pro",
|
|
19545
19562
|
kind: "provider_model",
|
|
19546
19563
|
provider: "ollamacloud",
|
|
19547
19564
|
resolution: {
|
|
19548
|
-
modelId: "
|
|
19565
|
+
modelId: "kimi-k3.1-pro",
|
|
19549
19566
|
status: "mapped"
|
|
19550
19567
|
},
|
|
19551
|
-
sourceText: "
|
|
19568
|
+
sourceText: "kimi-k3.1-pro"
|
|
19552
19569
|
},
|
|
19553
19570
|
{
|
|
19554
|
-
externalModelId: "
|
|
19571
|
+
externalModelId: "mimo-v2.6-pro",
|
|
19555
19572
|
kind: "provider_model",
|
|
19556
19573
|
provider: "ollamacloud",
|
|
19557
19574
|
resolution: {
|
|
19558
|
-
modelId: "
|
|
19575
|
+
modelId: "mimo-v2.6-pro",
|
|
19559
19576
|
status: "mapped"
|
|
19560
19577
|
},
|
|
19561
|
-
sourceText: "
|
|
19578
|
+
sourceText: "mimo-v2.6-pro"
|
|
19562
19579
|
}
|
|
19563
19580
|
],
|
|
19564
19581
|
modelDiscovery: "catalog",
|
|
@@ -19813,7 +19830,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19813
19830
|
}
|
|
19814
19831
|
],
|
|
19815
19832
|
routeRegistry: {
|
|
19816
|
-
generationId: "g-
|
|
19833
|
+
generationId: "g-20261115161901457-250a0705",
|
|
19817
19834
|
registry: {
|
|
19818
19835
|
contractVersion: 3,
|
|
19819
19836
|
registryVersion: "3.7.0",
|
|
@@ -23531,14 +23548,13 @@ CRITICAL INSTRUCTION FOR OUTPUT FORMAT:
|
|
|
23531
23548
|
}
|
|
23532
23549
|
}
|
|
23533
23550
|
if (this.thinkingFromModelName) {
|
|
23551
|
+
payload.generationConfig.thinkingConfig = { includeThoughts: true };
|
|
23534
23552
|
if (!this.pinnedEffort && claudeRequest?.thinking?.type === "disabled") {
|
|
23535
23553
|
log(`[GeminiAPIFormat] thinking omitted (disabled) for ${this.modelId}`);
|
|
23536
23554
|
} else {
|
|
23537
23555
|
const effort = this.resolveEffortLevel(claudeRequest);
|
|
23538
23556
|
if (effort && matchesModelFamily(this.modelId, "gemini-3")) {
|
|
23539
|
-
payload.generationConfig.thinkingConfig =
|
|
23540
|
-
thinkingLevel: this.effortToThinkingLevel(effort)
|
|
23541
|
-
};
|
|
23557
|
+
payload.generationConfig.thinkingConfig.thinkingLevel = this.effortToThinkingLevel(effort);
|
|
23542
23558
|
log(`[GeminiAPIFormat] thinkingLevel -> ${payload.generationConfig.thinkingConfig.thinkingLevel} (from ${effort}) for ${this.modelId}`);
|
|
23543
23559
|
} else if (effort) {
|
|
23544
23560
|
const tier = this.effortToThinkingBudget(effort);
|
|
@@ -23549,7 +23565,7 @@ CRITICAL INSTRUCTION FOR OUTPUT FORMAT:
|
|
|
23549
23565
|
if (budget === undefined) {
|
|
23550
23566
|
log(`[GeminiAPIFormat] thinking omitted (from ${effort}): max_tokens ${claudeRequest.max_tokens} leaves no valid budget for ${this.modelId}`);
|
|
23551
23567
|
} else {
|
|
23552
|
-
payload.generationConfig.thinkingConfig =
|
|
23568
|
+
payload.generationConfig.thinkingConfig.thinkingBudget = budget;
|
|
23553
23569
|
log(`[GeminiAPIFormat] thinkingBudget -> ${budget} (from ${effort}) for ${this.modelId}`);
|
|
23554
23570
|
}
|
|
23555
23571
|
}
|
|
@@ -58368,6 +58384,20 @@ async function refreshAccountModelsList(provider, trigger, opts) {
|
|
|
58368
58384
|
};
|
|
58369
58385
|
}
|
|
58370
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
|
+
}
|
|
58371
58401
|
function sweepAccountModelsLists(trigger, opts) {
|
|
58372
58402
|
const run = async (provider) => {
|
|
58373
58403
|
const readiness = await credentials.describeReadiness(provider, { allowOpPrompt: false });
|
|
@@ -67757,6 +67787,9 @@ function computeCacheReadDiscount(pricing, billedInputTokens, detail) {
|
|
|
67757
67787
|
function computeTurnCost(pricing, inputTokens, outputTokens, detail) {
|
|
67758
67788
|
return inputTokens / 1e6 * pricing.inputCostPer1M + outputTokens / 1e6 * pricing.outputCostPer1M - computeCacheReadDiscount(pricing, inputTokens, detail);
|
|
67759
67789
|
}
|
|
67790
|
+
function clearTokenFileTotals(path) {
|
|
67791
|
+
tokenFileTotals.delete(path);
|
|
67792
|
+
}
|
|
67760
67793
|
|
|
67761
67794
|
class TokenTracker {
|
|
67762
67795
|
port;
|
|
@@ -67774,6 +67807,13 @@ class TokenTracker {
|
|
|
67774
67807
|
startedAt = Date.now();
|
|
67775
67808
|
sessionBilledInputTokens = 0;
|
|
67776
67809
|
sessionCacheReadTokens = 0;
|
|
67810
|
+
reported = {
|
|
67811
|
+
totalCost: 0,
|
|
67812
|
+
billedInputTokens: 0,
|
|
67813
|
+
outputTokens: 0,
|
|
67814
|
+
totalTokens: 0,
|
|
67815
|
+
toolCalls: new Map
|
|
67816
|
+
};
|
|
67777
67817
|
constructor(port, config) {
|
|
67778
67818
|
this.port = port;
|
|
67779
67819
|
this.config = config;
|
|
@@ -67940,11 +67980,47 @@ class TokenTracker {
|
|
|
67940
67980
|
return "OpenAI";
|
|
67941
67981
|
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
67942
67982
|
}
|
|
67943
|
-
|
|
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) {
|
|
67944
68017
|
if (this.config.writesTokenFile === false)
|
|
67945
68018
|
return;
|
|
67946
68019
|
try {
|
|
67947
|
-
const
|
|
68020
|
+
const outPath = resolveTokenFilePath(this.port);
|
|
68021
|
+
const totals = this.addToFileTotals(outPath, inputTokens);
|
|
68022
|
+
const outputTokens = totals.outputTokens;
|
|
68023
|
+
const total = totals.totalTokens;
|
|
67948
68024
|
const cw = this.config.contextWindow;
|
|
67949
68025
|
const leftPct = cw > 0 ? Math.max(0, Math.min(100, Math.round((cw - inputTokens) / cw * 100))) : -1;
|
|
67950
68026
|
const pricing = requestPricing ?? this.getPricing();
|
|
@@ -67953,16 +68029,16 @@ class TokenTracker {
|
|
|
67953
68029
|
input_tokens: inputTokens,
|
|
67954
68030
|
output_tokens: outputTokens,
|
|
67955
68031
|
total_tokens: total,
|
|
67956
|
-
total_cost:
|
|
68032
|
+
total_cost: totals.totalCost,
|
|
67957
68033
|
context_window: cw > 0 ? cw : "unknown",
|
|
67958
68034
|
context_left_percent: leftPct,
|
|
67959
68035
|
provider_name: this.getDisplayName(),
|
|
67960
68036
|
updated_at: Date.now(),
|
|
67961
68037
|
is_free: isFreeModel,
|
|
67962
68038
|
is_estimated: isEstimate || false,
|
|
67963
|
-
started_at:
|
|
67964
|
-
tool_calls:
|
|
67965
|
-
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,
|
|
67966
68042
|
input_per_m: pricing.inputCostPer1M,
|
|
67967
68043
|
output_per_m: pricing.outputCostPer1M
|
|
67968
68044
|
};
|
|
@@ -67986,7 +68062,6 @@ class TokenTracker {
|
|
|
67986
68062
|
gapEndSec: allowance.gapEndSec
|
|
67987
68063
|
};
|
|
67988
68064
|
}
|
|
67989
|
-
const outPath = resolveTokenFilePath(this.port);
|
|
67990
68065
|
mkdirSync18(dirname15(outPath), { recursive: true });
|
|
67991
68066
|
writeFileSync13(outPath, JSON.stringify(data), "utf-8");
|
|
67992
68067
|
} catch (e) {
|
|
@@ -67994,7 +68069,7 @@ class TokenTracker {
|
|
|
67994
68069
|
}
|
|
67995
68070
|
}
|
|
67996
68071
|
}
|
|
67997
|
-
var ALLOWANCE_LABEL_STALE_MS;
|
|
68072
|
+
var ALLOWANCE_LABEL_STALE_MS, tokenFileTotals;
|
|
67998
68073
|
var init_token_tracker = __esm(() => {
|
|
67999
68074
|
init_tool_name_utils();
|
|
68000
68075
|
init_types2();
|
|
@@ -68003,6 +68078,7 @@ var init_token_tracker = __esm(() => {
|
|
|
68003
68078
|
init_token_file();
|
|
68004
68079
|
init_remote_provider_types();
|
|
68005
68080
|
ALLOWANCE_LABEL_STALE_MS = 10 * 60 * 1000;
|
|
68081
|
+
tokenFileTotals = new Map;
|
|
68006
68082
|
});
|
|
68007
68083
|
|
|
68008
68084
|
// src/handlers/shared/upstream-error-capture.ts
|
|
@@ -73649,7 +73725,100 @@ function getLegacySyntaxWarning(parsed) {
|
|
|
73649
73725
|
return `Deprecation warning: "${parsed.original}" uses legacy prefix syntax.
|
|
73650
73726
|
` + ` Consider using: ${newSyntax}`;
|
|
73651
73727
|
}
|
|
73652
|
-
|
|
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;
|
|
73653
73822
|
var init_model_parser = __esm(() => {
|
|
73654
73823
|
init_claude_code_aliases();
|
|
73655
73824
|
init_provider_definitions();
|
|
@@ -73664,6 +73833,7 @@ var init_model_parser = __esm(() => {
|
|
|
73664
73833
|
NATIVE_MODEL_PATTERNS = getNativeModelPatterns();
|
|
73665
73834
|
LEGACY_PREFIX_PATTERNS = getLegacyPrefixPatterns();
|
|
73666
73835
|
MODE_MARKER_SEGMENT = /^(pro|standard)(#[a-z]+)?(:\d+)?$/i;
|
|
73836
|
+
LISTING_ENTRY = /^([^@\s/:+#]+)@(\*)?$/;
|
|
73667
73837
|
});
|
|
73668
73838
|
|
|
73669
73839
|
// src/providers/predefined-catalog.ts
|
|
@@ -92087,6 +92257,80 @@ var init_magmux_wrapper = __esm(() => {
|
|
|
92087
92257
|
STRIPPED_CHILD_VARS = ["CLAUDECODE", "CLAUDE_CODE_CHILD_SESSION"];
|
|
92088
92258
|
});
|
|
92089
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
|
+
|
|
92090
92334
|
// src/providers/cache-ttl.ts
|
|
92091
92335
|
var FIREBASE_CACHE_TTL_HOURS = 24, FIREBASE_CACHE_TTL_MS;
|
|
92092
92336
|
var init_cache_ttl = __esm(() => {
|
|
@@ -94129,19 +94373,8 @@ function storedOutcome(provider, displayName, list, catalog) {
|
|
|
94129
94373
|
const outcome = outcomeFromModelsCatalog(provider, displayName, servedOutcomeOf(list.models), servedModelsForProvider(provider, catalog));
|
|
94130
94374
|
return outcome.kind === "rows" ? { ...outcome, listFetchedAt: list.fetchedAt } : null;
|
|
94131
94375
|
}
|
|
94132
|
-
|
|
94133
|
-
|
|
94134
|
-
minAgeMs: LIVE_MS
|
|
94135
|
-
});
|
|
94136
|
-
if (result.kind === "refreshed") {
|
|
94137
|
-
return result.outcome.kind === "served" ? servedOutcomeOf(result.outcome.models) : result.outcome;
|
|
94138
|
-
}
|
|
94139
|
-
if (result.reason === "too-recent") {
|
|
94140
|
-
const list = await readAccountModelsList(provider);
|
|
94141
|
-
if (list)
|
|
94142
|
-
return servedOutcomeOf(list.models);
|
|
94143
|
-
}
|
|
94144
|
-
return discoverProviderModelsCatalog(provider);
|
|
94376
|
+
function pickerLiveModelsCatalog(provider) {
|
|
94377
|
+
return liveOrStoredModelsCatalog(provider, "picker-provider");
|
|
94145
94378
|
}
|
|
94146
94379
|
function createPickerDataSource() {
|
|
94147
94380
|
const catalog = createCatalogClient();
|
|
@@ -94229,7 +94462,7 @@ function createPickerDataSource() {
|
|
|
94229
94462
|
return [...stored.rows, ...fromCatalog.filter((m) => !listed.has(m.id))];
|
|
94230
94463
|
},
|
|
94231
94464
|
discoverModelsCatalog(provider) {
|
|
94232
|
-
return buildDiscoveredModelOutcome(provider, names.get(provider) ?? provider, catalog, isPersistedListProvider(provider) ?
|
|
94465
|
+
return buildDiscoveredModelOutcome(provider, names.get(provider) ?? provider, catalog, isPersistedListProvider(provider) ? pickerLiveModelsCatalog : undefined);
|
|
94233
94466
|
},
|
|
94234
94467
|
cachedModelsCatalog(provider) {
|
|
94235
94468
|
return cachedOutcome(provider);
|
|
@@ -107455,14 +107688,16 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
107455
107688
|
return out.markers && (out.markers.mode || out.markers.speed) ? new WireMarkerHandler(handler, out.markers) : handler;
|
|
107456
107689
|
};
|
|
107457
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));
|
|
107458
107692
|
const resolveHandlerForRequest = async (requestedModel, out, probeHopOrigin) => {
|
|
107459
107693
|
if (monitorMode)
|
|
107460
107694
|
return nativeHandler;
|
|
107461
107695
|
let target = requestedModel;
|
|
107462
107696
|
let wasFromModelMap = false;
|
|
107463
107697
|
let targetFromLaunch = false;
|
|
107698
|
+
const lineupMatched = lineupSpecs.has(requestedModel);
|
|
107464
107699
|
let slotMatched = false;
|
|
107465
|
-
const slot = options.slotMap?.get(requestedModel);
|
|
107700
|
+
const slot = lineupMatched ? undefined : options.slotMap?.get(requestedModel);
|
|
107466
107701
|
if (slot) {
|
|
107467
107702
|
target = slot.provider != null && slot.provider !== "" ? `${slot.provider}@${slot.model}` : slot.model;
|
|
107468
107703
|
slotMatched = true;
|
|
@@ -107471,8 +107706,9 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
107471
107706
|
logStderr(`[Serve] slot ${requestedModel} \u2192 ${target}`);
|
|
107472
107707
|
}
|
|
107473
107708
|
}
|
|
107709
|
+
const claudeRowPicked = options.claudeRowsAsPicked === true && nativeRouteFor(requestedModel) !== null;
|
|
107474
107710
|
const req = requestedModel.toLowerCase();
|
|
107475
|
-
if (slotMatched) {} else if (modelMap) {
|
|
107711
|
+
if (slotMatched || lineupMatched) {} else if (modelMap) {
|
|
107476
107712
|
if (req.includes("opus") && modelMap.opus) {
|
|
107477
107713
|
target = modelMap.opus;
|
|
107478
107714
|
wasFromModelMap = true;
|
|
@@ -107482,10 +107718,10 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
107482
107718
|
} else if (req.includes("haiku") && modelMap.haiku) {
|
|
107483
107719
|
target = modelMap.haiku;
|
|
107484
107720
|
wasFromModelMap = true;
|
|
107485
|
-
} else if (model)
|
|
107721
|
+
} else if (model && !claudeRowPicked)
|
|
107486
107722
|
target = model;
|
|
107487
|
-
targetFromLaunch = wasFromModelMap || Boolean(model);
|
|
107488
|
-
} else if (model) {
|
|
107723
|
+
targetFromLaunch = wasFromModelMap || Boolean(model) && !claudeRowPicked;
|
|
107724
|
+
} else if (model && !claudeRowPicked) {
|
|
107489
107725
|
target = model;
|
|
107490
107726
|
targetFromLaunch = true;
|
|
107491
107727
|
}
|
|
@@ -107702,7 +107938,18 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107702
107938
|
}
|
|
107703
107939
|
return [...seen];
|
|
107704
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
|
+
}));
|
|
107705
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
|
+
}
|
|
107706
107953
|
const ids = servedSlotIds.length > 0 ? servedSlotIds : discoverableModelIds;
|
|
107707
107954
|
return c.json({
|
|
107708
107955
|
object: "list",
|
|
@@ -107711,7 +107958,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107711
107958
|
id,
|
|
107712
107959
|
object: "model",
|
|
107713
107960
|
type: "model",
|
|
107714
|
-
created:
|
|
107961
|
+
created: MODEL_LIST_CREATED,
|
|
107715
107962
|
owned_by: "claudish"
|
|
107716
107963
|
}))
|
|
107717
107964
|
});
|
|
@@ -107850,6 +108097,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107850
108097
|
if (advisorRuntime)
|
|
107851
108098
|
await shutdownAdvisorChains(advisorRuntime.chains.values());
|
|
107852
108099
|
closeAllEpisodes();
|
|
108100
|
+
clearTokenFileTotals(resolveTokenFilePath(port));
|
|
107853
108101
|
},
|
|
107854
108102
|
invalidateHandlerCache: (providerSlug) => {
|
|
107855
108103
|
if (!providerSlug) {
|
|
@@ -107872,7 +108120,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
107872
108120
|
}
|
|
107873
108121
|
};
|
|
107874
108122
|
}
|
|
107875
|
-
var RoutingError, classifierCaptureDirReady = false;
|
|
108123
|
+
var RoutingError, classifierCaptureDirReady = false, MODEL_LIST_CREATED = 1716000000;
|
|
107876
108124
|
var init_proxy_server = __esm(() => {
|
|
107877
108125
|
init_dist13();
|
|
107878
108126
|
init_cors();
|
|
@@ -107892,6 +108140,7 @@ var init_proxy_server = __esm(() => {
|
|
|
107892
108140
|
init_anthropic_forward();
|
|
107893
108141
|
init_call_context();
|
|
107894
108142
|
init_hop_decision();
|
|
108143
|
+
init_token_tracker();
|
|
107895
108144
|
init_hooks();
|
|
107896
108145
|
init_response_seam();
|
|
107897
108146
|
init_logger();
|
|
@@ -107914,6 +108163,7 @@ var init_proxy_server = __esm(() => {
|
|
|
107914
108163
|
init_coordinator();
|
|
107915
108164
|
init_redact();
|
|
107916
108165
|
init_pricing_cache();
|
|
108166
|
+
init_token_file();
|
|
107917
108167
|
init_test_upstream();
|
|
107918
108168
|
RoutingError = class RoutingError extends Error {
|
|
107919
108169
|
constructor(message) {
|
|
@@ -108097,7 +108347,7 @@ async function parseArgs(args) {
|
|
|
108097
108347
|
const anthropicModel = process.env[ENV.ANTHROPIC_MODEL];
|
|
108098
108348
|
if (claudishModel) {
|
|
108099
108349
|
config.model = claudishModel;
|
|
108100
|
-
} else if (anthropicModel) {
|
|
108350
|
+
} else if (anthropicModel && !isModelVarSetByClaudish(process.env, "ANTHROPIC_MODEL")) {
|
|
108101
108351
|
config.model = anthropicModel;
|
|
108102
108352
|
}
|
|
108103
108353
|
const tierSources = {};
|
|
@@ -108161,6 +108411,7 @@ async function parseArgs(args) {
|
|
|
108161
108411
|
if (config.debug && config.logLevel === "info") {
|
|
108162
108412
|
config.logLevel = "debug";
|
|
108163
108413
|
}
|
|
108414
|
+
const modelValues = [];
|
|
108164
108415
|
let i = 0;
|
|
108165
108416
|
while (i < args.length) {
|
|
108166
108417
|
const arg = args[i];
|
|
@@ -108175,6 +108426,9 @@ async function parseArgs(args) {
|
|
|
108175
108426
|
config.model = chain[0];
|
|
108176
108427
|
if (chain.length > 1)
|
|
108177
108428
|
config.modelChain = chain;
|
|
108429
|
+
else
|
|
108430
|
+
delete config.modelChain;
|
|
108431
|
+
modelValues.push(modelArg);
|
|
108178
108432
|
} else if (arg === "--model-pinned") {
|
|
108179
108433
|
config.modelPinned = true;
|
|
108180
108434
|
} else if (arg === "--claude-subscription-pin") {
|
|
@@ -108518,6 +108772,16 @@ Usage: claudish --models --provider <slug>`);
|
|
|
108518
108772
|
}
|
|
108519
108773
|
i++;
|
|
108520
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
|
+
}
|
|
108521
108785
|
if (!config._hasPositionalPrompt && !config.stdin && !config._hasPrintFlag) {
|
|
108522
108786
|
config.interactive = true;
|
|
108523
108787
|
}
|
|
@@ -109297,6 +109561,9 @@ ${shortcutTable}
|
|
|
109297
109561
|
${h("OPTIONS")}
|
|
109298
109562
|
${green("-i, --interactive")} Run in interactive mode (default when no prompt given)
|
|
109299
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.")}
|
|
109300
109567
|
${green("--profile")} ${yellow("<name>")} Use named profile for model mapping (default profile if omitted)
|
|
109301
109568
|
${green("--default-provider")} ${yellow("<name>")} Fallback provider for bare model names (claudish provider or customEndpoints key)
|
|
109302
109569
|
${dim('"" disables it. Precedence: this flag > CLAUDISH_DEFAULT_PROVIDER env > config.json')}
|
|
@@ -109688,6 +109955,7 @@ var init_cli = __esm(() => {
|
|
|
109688
109955
|
init_logger();
|
|
109689
109956
|
init_model_loader();
|
|
109690
109957
|
init_model_selector();
|
|
109958
|
+
init_model_vars_env();
|
|
109691
109959
|
init_probe_chain();
|
|
109692
109960
|
init_probe_results_printer();
|
|
109693
109961
|
init_probe_tui_runtime();
|
|
@@ -109709,6 +109977,7 @@ var init_cli = __esm(() => {
|
|
|
109709
109977
|
init_routing_rules();
|
|
109710
109978
|
init_recommended_listing();
|
|
109711
109979
|
init_settings();
|
|
109980
|
+
init_redact();
|
|
109712
109981
|
init_ansi();
|
|
109713
109982
|
init_provider_resolver();
|
|
109714
109983
|
__filename2 = fileURLToPath2(import.meta.url);
|
|
@@ -111458,7 +111727,17 @@ function hasNativeAnthropicMapping(config) {
|
|
|
111458
111727
|
config.modelHaiku,
|
|
111459
111728
|
config.modelSubagent
|
|
111460
111729
|
];
|
|
111461
|
-
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);
|
|
111462
111741
|
}
|
|
111463
111742
|
function claudeLaunchAuthLine(launch, env, keySource) {
|
|
111464
111743
|
const state = (name) => {
|
|
@@ -111647,6 +111926,17 @@ function settingsArgOccurrences(args) {
|
|
|
111647
111926
|
}
|
|
111648
111927
|
return out;
|
|
111649
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
|
+
}
|
|
111650
111940
|
function customHeaderAuthNames(value) {
|
|
111651
111941
|
const names = new Set;
|
|
111652
111942
|
if (typeof value !== "string" || !value)
|
|
@@ -111810,6 +112100,42 @@ function settingsClaudeLoginToken(config, env = process.env, deps = {}) {
|
|
|
111810
112100
|
}
|
|
111811
112101
|
return "absent";
|
|
111812
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
|
+
}
|
|
111813
112139
|
function enabledSettingSources(args) {
|
|
111814
112140
|
let value;
|
|
111815
112141
|
for (let i = 0;i < args.length; i++) {
|
|
@@ -111843,7 +112169,7 @@ function readSettingsSource(source, readFile) {
|
|
|
111843
112169
|
try {
|
|
111844
112170
|
const raw = isInlineSettings(source) ? source : readFile(source);
|
|
111845
112171
|
const parsed = JSON.parse(raw);
|
|
111846
|
-
return parsed && typeof parsed === "object" ? parsed : null;
|
|
112172
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
111847
112173
|
} catch {
|
|
111848
112174
|
return null;
|
|
111849
112175
|
}
|
|
@@ -112112,12 +112438,9 @@ function userSettingsFileCandidates(cwd) {
|
|
|
112112
112438
|
join53(cwd, ".claude", "settings.local.json")
|
|
112113
112439
|
];
|
|
112114
112440
|
}
|
|
112115
|
-
function discoverUserStatusLineCommand(claudeArgs = [], cwd = process.cwd()) {
|
|
112441
|
+
function discoverUserStatusLineCommand(claudeArgs = [], cwd = process.cwd(), scope = "first") {
|
|
112116
112442
|
const sources = userSettingsFileCandidates(cwd).filter((file) => existsSync37(file));
|
|
112117
|
-
|
|
112118
|
-
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
112119
|
-
if (settingsArg)
|
|
112120
|
-
sources.push(settingsArg);
|
|
112443
|
+
sources.push(...settingsArgValues(claudeArgs, scope));
|
|
112121
112444
|
let effective;
|
|
112122
112445
|
for (const source of sources) {
|
|
112123
112446
|
const layer = parseSettingsArgSafe(source);
|
|
@@ -112148,7 +112471,7 @@ function buildChainedStatusCommand(userCommand, claudishBody, claudishSegment) {
|
|
|
112148
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`;
|
|
112149
112472
|
return `JSON=$(cat); ${runUser}; ${claudishBody}; SEG=$(${claudishSegment}); ${separator}; ${emit}`;
|
|
112150
112473
|
}
|
|
112151
|
-
function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLineCommand) {
|
|
112474
|
+
function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLineCommand, modelPicker) {
|
|
112152
112475
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
112153
112476
|
const claudishDir = join53(homeDir, ".claudish");
|
|
112154
112477
|
try {
|
|
@@ -112193,7 +112516,7 @@ function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLi
|
|
|
112193
112516
|
command: statusCommand,
|
|
112194
112517
|
padding: 0
|
|
112195
112518
|
};
|
|
112196
|
-
const settings = buildClaudishSettingsOverlay(statusLine, proxyAuthMode);
|
|
112519
|
+
const settings = buildClaudishSettingsOverlay(statusLine, proxyAuthMode, isPaneChild(), modelPicker);
|
|
112197
112520
|
writeFileSync20(tempPath, JSON.stringify(settings, null, 2), { encoding: "utf-8", mode: 384 });
|
|
112198
112521
|
return { path: tempPath, statusLine, tokenFilePath };
|
|
112199
112522
|
}
|
|
@@ -112205,7 +112528,7 @@ function scrubChildEnv(env, opts) {
|
|
|
112205
112528
|
for (const key of PANE_LAUNCH_VARS)
|
|
112206
112529
|
delete env[key];
|
|
112207
112530
|
}
|
|
112208
|
-
function buildClaudishSettingsOverlay(statusLine, proxyAuthMode, paneChild = isPaneChild()) {
|
|
112531
|
+
function buildClaudishSettingsOverlay(statusLine, proxyAuthMode, paneChild = isPaneChild(), modelPicker) {
|
|
112209
112532
|
const settings = { statusLine, disableClaudeAiConnectors: true };
|
|
112210
112533
|
if (proxyAuthMode) {
|
|
112211
112534
|
settings.forceLoginMethod = "console";
|
|
@@ -112216,9 +112539,36 @@ function buildClaudishSettingsOverlay(statusLine, proxyAuthMode, paneChild = isP
|
|
|
112216
112539
|
settings.wheelScrollAccelerationEnabled = false;
|
|
112217
112540
|
settings.tui = "fullscreen";
|
|
112218
112541
|
}
|
|
112542
|
+
if (modelPicker)
|
|
112543
|
+
settings.modelPicker = modelPicker;
|
|
112219
112544
|
return settings;
|
|
112220
112545
|
}
|
|
112221
|
-
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
|
+
}
|
|
112222
112572
|
const idx = config.claudeArgs.indexOf("--settings");
|
|
112223
112573
|
if (idx === -1 || !config.claudeArgs[idx + 1]) {
|
|
112224
112574
|
return;
|
|
@@ -112226,25 +112576,7 @@ function mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, proxyA
|
|
|
112226
112576
|
const userSettingsValue = config.claudeArgs[idx + 1];
|
|
112227
112577
|
try {
|
|
112228
112578
|
const userSettings = parseSettingsArg(userSettingsValue);
|
|
112229
|
-
userSettings
|
|
112230
|
-
if (!("disableClaudeAiConnectors" in userSettings)) {
|
|
112231
|
-
userSettings.disableClaudeAiConnectors = true;
|
|
112232
|
-
}
|
|
112233
|
-
if (proxyAuthMode && !("forceLoginMethod" in userSettings)) {
|
|
112234
|
-
userSettings.forceLoginMethod = "console";
|
|
112235
|
-
}
|
|
112236
|
-
if (paneChild && !("skipDangerousModePermissionPrompt" in userSettings)) {
|
|
112237
|
-
userSettings.skipDangerousModePermissionPrompt = true;
|
|
112238
|
-
}
|
|
112239
|
-
if (paneChild) {
|
|
112240
|
-
userSettings.editorMode = "normal";
|
|
112241
|
-
}
|
|
112242
|
-
if (paneChild) {
|
|
112243
|
-
userSettings.wheelScrollAccelerationEnabled = false;
|
|
112244
|
-
}
|
|
112245
|
-
if (paneChild) {
|
|
112246
|
-
userSettings.tui = "fullscreen";
|
|
112247
|
-
}
|
|
112579
|
+
applyClaudishSettingsKeys(userSettings, statusLine, proxyAuthMode, paneChild);
|
|
112248
112580
|
chmodSync5(tempSettingsPath, 384);
|
|
112249
112581
|
writeFileSync20(tempSettingsPath, JSON.stringify(userSettings, null, 2), {
|
|
112250
112582
|
encoding: "utf-8",
|
|
@@ -112257,6 +112589,45 @@ function mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, proxyA
|
|
|
112257
112589
|
}
|
|
112258
112590
|
config.claudeArgs.splice(idx, 2);
|
|
112259
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
|
+
}
|
|
112260
112631
|
async function resolveLocalContextWindow(spec, cachePath) {
|
|
112261
112632
|
const parsed = parseModelSpec(spec);
|
|
112262
112633
|
let provider = parsed.provider;
|
|
@@ -112337,12 +112708,9 @@ function resolveAdvisorToolEnv(config, processEnv = process.env) {
|
|
|
112337
112708
|
return { vars: {}, source: "inherited" };
|
|
112338
112709
|
return { vars: { [ADVISOR_TOOL_ENV_VAR]: "1" }, source: "claudish" };
|
|
112339
112710
|
}
|
|
112340
|
-
function discoverUserAdvisorModel(claudeArgs = [], cwd = process.cwd()) {
|
|
112711
|
+
function discoverUserAdvisorModel(claudeArgs = [], cwd = process.cwd(), scope = "first") {
|
|
112341
112712
|
const sources = userSettingsFileCandidates(cwd).filter((file) => existsSync37(file));
|
|
112342
|
-
|
|
112343
|
-
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
112344
|
-
if (settingsArg)
|
|
112345
|
-
sources.push(settingsArg);
|
|
112713
|
+
sources.push(...settingsArgValues(claudeArgs, scope));
|
|
112346
112714
|
const managed = managedSettingsPath();
|
|
112347
112715
|
if (existsSync37(managed))
|
|
112348
112716
|
sources.push(managed);
|
|
@@ -112359,7 +112727,7 @@ function discoverUserAdvisorModel(claudeArgs = [], cwd = process.cwd()) {
|
|
|
112359
112727
|
function resolveAdvisorModelArg(config, cwd = process.cwd()) {
|
|
112360
112728
|
if (!config.advisor)
|
|
112361
112729
|
return { args: [], source: "off" };
|
|
112362
|
-
const userChoice = discoverUserAdvisorModel(config.claudeArgs, cwd);
|
|
112730
|
+
const userChoice = discoverUserAdvisorModel(config.claudeArgs, cwd, settingsArgScopeOf(config));
|
|
112363
112731
|
if (userChoice)
|
|
112364
112732
|
return { args: [], model: userChoice, source: "inherited" };
|
|
112365
112733
|
return {
|
|
@@ -112408,10 +112776,29 @@ function relayChildStderr(stream) {
|
|
|
112408
112776
|
logStderr(`child stderr relay ended: ${err}`);
|
|
112409
112777
|
});
|
|
112410
112778
|
}
|
|
112411
|
-
|
|
112779
|
+
function childModelIdOf(config) {
|
|
112412
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 = {}) {
|
|
112413
112800
|
const advisorNativeSession = isAdvisorNativeSession(config);
|
|
112414
|
-
const modelId =
|
|
112801
|
+
const modelId = childModelIdOf(config);
|
|
112415
112802
|
const portMatch = proxyUrl.match(/:(\d+)/);
|
|
112416
112803
|
const port = portMatch ? portMatch[1] : "unknown";
|
|
112417
112804
|
const proxyAuthMode = isProxyAuthMode(config);
|
|
@@ -112435,15 +112822,16 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112435
112822
|
if (!gatewayEligible && globalConfig.harnessGateway !== undefined) {
|
|
112436
112823
|
log(gatewayHeldOff ? `[claude-runner] harnessGateway ignored: ${HARNESS_GATEWAY_OFF_VAR}=1` : "[claude-runner] harnessGateway ignored: a monitor session keeps the proxy URL");
|
|
112437
112824
|
}
|
|
112438
|
-
const userStatusLineCommand = discoverUserStatusLineCommand(config.claudeArgs);
|
|
112825
|
+
const userStatusLineCommand = discoverUserStatusLineCommand(config.claudeArgs, process.cwd(), settingsArgScopeOf(config));
|
|
112439
112826
|
const advisorModelArg = resolveAdvisorModelArg(config);
|
|
112827
|
+
const modelPicker = config.modelLineup?.picker;
|
|
112440
112828
|
const {
|
|
112441
112829
|
path: tempSettingsPath,
|
|
112442
112830
|
statusLine,
|
|
112443
112831
|
tokenFilePath
|
|
112444
|
-
} = createTempSettingsFile(modelId ?? "default", port, forceConsoleLogin, userStatusLineCommand);
|
|
112445
|
-
const signalShutdown = setupSignalHandlers(tempSettingsPath, config.quiet, onCleanup);
|
|
112446
|
-
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);
|
|
112447
112835
|
const claudeArgs = [];
|
|
112448
112836
|
claudeArgs.push("--settings", tempSettingsPath);
|
|
112449
112837
|
claudeArgs.push(...advisorModelArg.args);
|
|
@@ -112514,6 +112902,11 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112514
112902
|
if (!config.interactive && env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC === undefined) {
|
|
112515
112903
|
env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
|
|
112516
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
|
+
}
|
|
112517
112910
|
if (config.monitor || advisorNativeSession) {
|
|
112518
112911
|
delete env.ANTHROPIC_API_KEY;
|
|
112519
112912
|
delete env.ANTHROPIC_AUTH_TOKEN;
|
|
@@ -112523,19 +112916,12 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112523
112916
|
env.ANTHROPIC_AUTH_TOKEN = CLAUDISH_PLACEHOLDER_AUTH_TOKEN;
|
|
112524
112917
|
applyHostManagedMarker(env);
|
|
112525
112918
|
}
|
|
112526
|
-
|
|
112527
|
-
if (launchModelId) {
|
|
112528
|
-
env[ENV.ANTHROPIC_MODEL] = launchModelId;
|
|
112529
|
-
env[ENV.ANTHROPIC_SMALL_FAST_MODEL] = launchModelId;
|
|
112530
|
-
}
|
|
112919
|
+
recordModelVars(env, childModelVars);
|
|
112531
112920
|
if (config.claudeLaunch) {
|
|
112532
112921
|
log(claudeLaunchAuthLine(config.claudeLaunch, env, config.claudeLaunchKeySource));
|
|
112533
112922
|
}
|
|
112534
112923
|
} else {
|
|
112535
|
-
|
|
112536
|
-
env[ENV.ANTHROPIC_MODEL] = modelId;
|
|
112537
|
-
env[ENV.ANTHROPIC_SMALL_FAST_MODEL] = modelId;
|
|
112538
|
-
}
|
|
112924
|
+
recordModelVars(env, childModelVars);
|
|
112539
112925
|
if (shouldPreserveNativeAuth(config)) {
|
|
112540
112926
|
const scrubbed = scrubInheritedClaudishPlaceholders(env);
|
|
112541
112927
|
if (scrubbed.removed.length > 0) {
|
|
@@ -112557,7 +112943,7 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112557
112943
|
applyProxyPlaceholderAuth(env);
|
|
112558
112944
|
applyProxyFastModeGates(env);
|
|
112559
112945
|
applyHostRouting(env);
|
|
112560
|
-
const realWindow = await computeMainThreadContextWindow(config);
|
|
112946
|
+
const realWindow = config.mainThreadWindow ?? await computeMainThreadContextWindow(config);
|
|
112561
112947
|
const contextEnv = resolveContextWindowEnv(realWindow, process.env);
|
|
112562
112948
|
seedTokenFileWindow(resolveTokenFilePath(port), realWindow);
|
|
112563
112949
|
Object.assign(env, contextEnv.vars);
|
|
@@ -112601,6 +112987,7 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
112601
112987
|
`);
|
|
112602
112988
|
}
|
|
112603
112989
|
const claudeBinary = await findClaudeBinary();
|
|
112990
|
+
await hooks.beforeSpawn?.(tempSettingsPath);
|
|
112604
112991
|
const stoppedBeforeSpawn = signalShutdownExitCode();
|
|
112605
112992
|
if (stoppedBeforeSpawn !== null) {
|
|
112606
112993
|
signalShutdown.removeSettingsFile();
|
|
@@ -112669,6 +113056,13 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
112669
113056
|
shell: needsShell
|
|
112670
113057
|
});
|
|
112671
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
|
+
}
|
|
112672
113066
|
if (wrap) {
|
|
112673
113067
|
wrap.watch(proc);
|
|
112674
113068
|
}
|
|
@@ -112768,7 +113162,7 @@ function sessionOutcomeOf(exitCode) {
|
|
|
112768
113162
|
function signalShutdownExitCode() {
|
|
112769
113163
|
return signalShutdownCode;
|
|
112770
113164
|
}
|
|
112771
|
-
function setupSignalHandlers(tempSettingsPath, quiet, onCleanup) {
|
|
113165
|
+
function setupSignalHandlers(tempSettingsPath, quiet, onCleanup, onDeadline) {
|
|
112772
113166
|
const signals = isWindows2() ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
112773
113167
|
let shuttingDown = null;
|
|
112774
113168
|
let claudeCode = null;
|
|
@@ -112807,6 +113201,9 @@ function setupSignalHandlers(tempSettingsPath, quiet, onCleanup) {
|
|
|
112807
113201
|
const armDeadline = (code) => {
|
|
112808
113202
|
const deadline = setTimeout(() => {
|
|
112809
113203
|
log(`[claudish] Signal shutdown passed ${SIGNAL_SHUTDOWN_BUDGET_MS} ms; exiting`);
|
|
113204
|
+
try {
|
|
113205
|
+
onDeadline?.();
|
|
113206
|
+
} catch {}
|
|
112810
113207
|
try {
|
|
112811
113208
|
onCleanup?.();
|
|
112812
113209
|
} catch {}
|
|
@@ -112915,7 +113312,7 @@ async function checkClaudeInstalled() {
|
|
|
112915
113312
|
const binary = await findClaudeBinary();
|
|
112916
113313
|
return binary !== null;
|
|
112917
113314
|
}
|
|
112918
|
-
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;
|
|
112919
113316
|
var init_claude_runner = __esm(() => {
|
|
112920
113317
|
init_model_catalog();
|
|
112921
113318
|
init_claude_code_login();
|
|
@@ -112931,6 +113328,7 @@ var init_claude_runner = __esm(() => {
|
|
|
112931
113328
|
init_host_routing_env();
|
|
112932
113329
|
init_magmux_wrapper();
|
|
112933
113330
|
init_logger();
|
|
113331
|
+
init_model_vars_env();
|
|
112934
113332
|
init_child_env();
|
|
112935
113333
|
init_pane_launch();
|
|
112936
113334
|
init_process_tree();
|
|
@@ -112950,6 +113348,12 @@ var init_claude_runner = __esm(() => {
|
|
|
112950
113348
|
init_terminal_isolation();
|
|
112951
113349
|
init_theme_mode();
|
|
112952
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
|
+
};
|
|
112953
113357
|
STALE_TOKEN_FILE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
112954
113358
|
CHILD_STDERR_NOISE = [/^\[claude-code:unrecognized_model\]/];
|
|
112955
113359
|
});
|
|
@@ -117793,7 +118197,7 @@ function writeRecord(root, rec) {
|
|
|
117793
118197
|
`, { mode: 384 });
|
|
117794
118198
|
renameSync12(tmp, p);
|
|
117795
118199
|
}
|
|
117796
|
-
function
|
|
118200
|
+
function readRecord2(root, paneId) {
|
|
117797
118201
|
if (!isValidPaneId(paneId))
|
|
117798
118202
|
return null;
|
|
117799
118203
|
try {
|
|
@@ -117803,7 +118207,7 @@ function readRecord(root, paneId) {
|
|
|
117803
118207
|
}
|
|
117804
118208
|
}
|
|
117805
118209
|
function updateRecord(root, paneId, patch) {
|
|
117806
|
-
const rec =
|
|
118210
|
+
const rec = readRecord2(root, paneId);
|
|
117807
118211
|
if (rec)
|
|
117808
118212
|
writeRecord(root, { ...rec, ...patch });
|
|
117809
118213
|
}
|
|
@@ -117860,7 +118264,7 @@ function readRecords(root) {
|
|
|
117860
118264
|
}
|
|
117861
118265
|
const out = [];
|
|
117862
118266
|
for (const n of names) {
|
|
117863
|
-
const rec =
|
|
118267
|
+
const rec = readRecord2(root, n.slice(0, -".json".length));
|
|
117864
118268
|
if (rec)
|
|
117865
118269
|
out.push(rec);
|
|
117866
118270
|
}
|
|
@@ -124212,6 +124616,15 @@ function launchSigningFor(config, deps = {}) {
|
|
|
124212
124616
|
const wantsApiBilling = deps.wantsApiBilling ?? ((c) => wantsAnthropicApiBilling(c));
|
|
124213
124617
|
return wantsApiBilling(config) ? undefined : LOGIN_ONLY_SIGNING;
|
|
124214
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
|
+
}
|
|
124215
124628
|
function advisorKeyLookupAllowed(config, deps = {}) {
|
|
124216
124629
|
const tiers = [config.modelOpus, config.modelSonnet, config.modelHaiku, config.modelSubagent];
|
|
124217
124630
|
const hasMainModel = (config.modelChain?.length ?? 0) > 0 || Boolean(config.model) || tiers.some((m) => typeof m === "string" && m.length > 0);
|
|
@@ -124262,6 +124675,11 @@ function subscriptionPrefix(cause) {
|
|
|
124262
124675
|
return cause ? `${CLAUDE_SUBSCRIPTION_LABEL}, ${cause}` : CLAUDE_SUBSCRIPTION_LABEL;
|
|
124263
124676
|
}
|
|
124264
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
|
+
}
|
|
124265
124683
|
const main = typeof config.model === "string" ? config.model : undefined;
|
|
124266
124684
|
if (main && nativeRouteFor(main) !== null)
|
|
124267
124685
|
return;
|
|
@@ -124370,7 +124788,8 @@ function decideClaudeLaunch(config, deps = {}) {
|
|
|
124370
124788
|
}
|
|
124371
124789
|
if (!isClaudeSubscriptionSpec2(main))
|
|
124372
124790
|
return { ok: true };
|
|
124373
|
-
|
|
124791
|
+
const hasListings = (config.modelListings?.length ?? 0) > 0;
|
|
124792
|
+
if (hasListings || (deps.paneChild ?? isPaneChild())) {
|
|
124374
124793
|
config.model = normalizeNativeModelSpec(claudeSubscriptionInner(main));
|
|
124375
124794
|
config.claudeSubscriptionPin = true;
|
|
124376
124795
|
return { ok: true };
|
|
@@ -124382,6 +124801,113 @@ function decideClaudeLaunch(config, deps = {}) {
|
|
|
124382
124801
|
config.claudeLaunch = "subscription";
|
|
124383
124802
|
return { ok: true };
|
|
124384
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
|
+
}
|
|
124385
124911
|
function effectiveStartupCredential(config, env, deps) {
|
|
124386
124912
|
const credentialOf = deps.claudeCodeCredential ?? ((e) => claudeCodeStartupCredential({ env: e }));
|
|
124387
124913
|
const fromSettings = (deps.settingsLoginToken ?? settingsClaudeLoginToken)(config, env);
|
|
@@ -124529,6 +125055,7 @@ var init_claude_launch = __esm(() => {
|
|
|
124529
125055
|
init_model_parser();
|
|
124530
125056
|
init_native_route();
|
|
124531
125057
|
init_shadowed_endpoint();
|
|
125058
|
+
init_unknown_shortcut();
|
|
124532
125059
|
init_redact();
|
|
124533
125060
|
TIER_FIELDS = [
|
|
124534
125061
|
["opus", "modelOpus"],
|
|
@@ -124568,6 +125095,7 @@ function claudeCodePrintEnv(parent) {
|
|
|
124568
125095
|
scrubInheritedFastModeGates(env);
|
|
124569
125096
|
scrubInheritedHostRouting(env);
|
|
124570
125097
|
scrubInheritedHarnessGatewayTarget(env);
|
|
125098
|
+
scrubInheritedModelVars(env, { model: false, smallFast: false }, { keepsLogin: true });
|
|
124571
125099
|
return env;
|
|
124572
125100
|
}
|
|
124573
125101
|
function isFrame(v) {
|
|
@@ -124773,6 +125301,7 @@ var init_run_prompt_claude_code = __esm(() => {
|
|
|
124773
125301
|
init_harness_gateway();
|
|
124774
125302
|
init_host_routing_env();
|
|
124775
125303
|
init_claude_launch();
|
|
125304
|
+
init_model_vars_env();
|
|
124776
125305
|
init_child_env();
|
|
124777
125306
|
init_pane_launch();
|
|
124778
125307
|
init_redact();
|
|
@@ -141566,6 +142095,578 @@ var init_tui = __esm(() => {
|
|
|
141566
142095
|
}
|
|
141567
142096
|
});
|
|
141568
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
|
+
|
|
141569
142670
|
// src/diag-output.ts
|
|
141570
142671
|
import { createWriteStream as createWriteStream2, mkdirSync as mkdirSync32, unlinkSync as unlinkSync15, writeFileSync as writeFileSync32 } from "fs";
|
|
141571
142672
|
import { homedir as homedir47 } from "os";
|
|
@@ -143668,6 +144769,611 @@ var init_resume_picker_run = __esm(() => {
|
|
|
143668
144769
|
init_session_discovery();
|
|
143669
144770
|
});
|
|
143670
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
|
+
|
|
143671
145377
|
// src/session/baseline-pricing.ts
|
|
143672
145378
|
function resolveBaseline(alias, label) {
|
|
143673
145379
|
const entry = findEntryByAlias(alias);
|
|
@@ -143703,11 +145409,11 @@ var exports_session_stats = {};
|
|
|
143703
145409
|
__export(exports_session_stats, {
|
|
143704
145410
|
readSessionStats: () => readSessionStats
|
|
143705
145411
|
});
|
|
143706
|
-
import { readFileSync as
|
|
145412
|
+
import { readFileSync as readFileSync60 } from "fs";
|
|
143707
145413
|
function readSessionStats(port, opts) {
|
|
143708
145414
|
let raw;
|
|
143709
145415
|
try {
|
|
143710
|
-
raw = JSON.parse(
|
|
145416
|
+
raw = JSON.parse(readFileSync60(resolveTokenFilePath(port), "utf-8"));
|
|
143711
145417
|
} catch {
|
|
143712
145418
|
return null;
|
|
143713
145419
|
}
|
|
@@ -144094,12 +145800,12 @@ init_launch_env();
|
|
|
144094
145800
|
init_op_source();
|
|
144095
145801
|
init_startup_trace();
|
|
144096
145802
|
init_picker_cancelled();
|
|
144097
|
-
import { existsSync as existsSync50, readFileSync as
|
|
144098
|
-
import { join as
|
|
145803
|
+
import { existsSync as existsSync50, readFileSync as readFileSync61 } from "fs";
|
|
145804
|
+
import { join as join79, resolve as resolve16 } from "path";
|
|
144099
145805
|
|
|
144100
145806
|
// src/tui/runtime/should-open-picker.ts
|
|
144101
145807
|
function noModelConfigured(gate) {
|
|
144102
|
-
return !gate.monitor && !gate.advisorNativeSession && !gate.model && !gate.hasProfileTiers;
|
|
145808
|
+
return !gate.monitor && !gate.advisorNativeSession && !gate.hasModelListings && !gate.model && !gate.hasProfileTiers;
|
|
144103
145809
|
}
|
|
144104
145810
|
function shouldOpenPicker(gate, tty) {
|
|
144105
145811
|
return noModelConfigured(gate) && Boolean(gate.interactive) && tty;
|
|
@@ -144112,7 +145818,7 @@ function requiresExplicitModel(gate, tty) {
|
|
|
144112
145818
|
var autoloadDropped = [...droppedAtLaunch, ...takeLauncherDropped(process.env)];
|
|
144113
145819
|
var dotenvText;
|
|
144114
145820
|
try {
|
|
144115
|
-
dotenvText =
|
|
145821
|
+
dotenvText = readFileSync61(join79(process.cwd(), ".env"));
|
|
144116
145822
|
} catch {}
|
|
144117
145823
|
if (dotenvText !== undefined) {
|
|
144118
145824
|
await Promise.resolve().then(() => init_dotenv_allowlist());
|
|
@@ -144229,7 +145935,7 @@ async function applyOpImport() {
|
|
|
144229
145935
|
async function applyConfigOverride() {
|
|
144230
145936
|
await Promise.resolve();
|
|
144231
145937
|
const plan = planConfigOverride(process.argv.slice(2), process.env, {
|
|
144232
|
-
resolve:
|
|
145938
|
+
resolve: resolve16,
|
|
144233
145939
|
exists: existsSync50
|
|
144234
145940
|
});
|
|
144235
145941
|
if (plan.kind === "none")
|
|
@@ -144424,6 +146130,35 @@ if (isMcpMode) {
|
|
|
144424
146130
|
} else {
|
|
144425
146131
|
runCli();
|
|
144426
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
|
+
}
|
|
144427
146162
|
async function runCli() {
|
|
144428
146163
|
const endImports = beginSpan("startup:cli-imports");
|
|
144429
146164
|
await Promise.resolve().then(() => init_claude_runner());
|
|
@@ -144471,17 +146206,25 @@ async function runCli() {
|
|
|
144471
146206
|
await Promise.resolve().then(() => init_endpoint_registration());
|
|
144472
146207
|
ensureEndpointsRegistered();
|
|
144473
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
|
+
}
|
|
144474
146217
|
if (cliConfig.team && cliConfig.team.length > 0) {
|
|
144475
146218
|
let prompt = cliConfig.claudeArgs.join(" ");
|
|
144476
146219
|
if (cliConfig.inputFile) {
|
|
144477
|
-
prompt =
|
|
146220
|
+
prompt = readFileSync61(cliConfig.inputFile, "utf-8");
|
|
144478
146221
|
}
|
|
144479
146222
|
if (!prompt.trim()) {
|
|
144480
146223
|
console.error("Error: --team requires a prompt (positional args or -f <file>)");
|
|
144481
146224
|
process.exit(1);
|
|
144482
146225
|
}
|
|
144483
146226
|
const mode = cliConfig.teamMode ?? "default";
|
|
144484
|
-
const sessionPath =
|
|
146227
|
+
const sessionPath = join79(process.cwd(), `.claudish-team-${Date.now()}`);
|
|
144485
146228
|
if (mode === "json") {
|
|
144486
146229
|
await Promise.resolve().then(() => init_pane());
|
|
144487
146230
|
await Promise.resolve().then(() => init_team_orchestrator());
|
|
@@ -144501,9 +146244,9 @@ async function runCli() {
|
|
|
144501
146244
|
const status = await runModels(sessionPath);
|
|
144502
146245
|
const result = { ...status, responses: {} };
|
|
144503
146246
|
for (const anonId of Object.keys(status.models)) {
|
|
144504
|
-
const responsePath =
|
|
146247
|
+
const responsePath = join79(sessionPath, `response-${anonId}.md`);
|
|
144505
146248
|
try {
|
|
144506
|
-
const raw =
|
|
146249
|
+
const raw = readFileSync61(responsePath, "utf-8").trim();
|
|
144507
146250
|
try {
|
|
144508
146251
|
result.responses[anonId] = JSON.parse(raw);
|
|
144509
146252
|
} catch {
|
|
@@ -144620,6 +146363,7 @@ Team Status`);
|
|
|
144620
146363
|
interactive: cliConfig.interactive,
|
|
144621
146364
|
monitor: cliConfig.monitor,
|
|
144622
146365
|
advisorNativeSession,
|
|
146366
|
+
hasModelListings: (cliConfig.modelListings?.length ?? 0) > 0,
|
|
144623
146367
|
model: cliConfig.model,
|
|
144624
146368
|
hasProfileTiers
|
|
144625
146369
|
});
|
|
@@ -144741,6 +146485,20 @@ Team Status`);
|
|
|
144741
146485
|
`);
|
|
144742
146486
|
}
|
|
144743
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
|
+
}
|
|
144744
146502
|
let advisorRuntime;
|
|
144745
146503
|
if (cliConfig.advisor) {
|
|
144746
146504
|
await Promise.resolve().then(() => init_advisor_startup());
|
|
@@ -144810,9 +146568,23 @@ Team Status`);
|
|
|
144810
146568
|
if (cliConfig.contextWindow !== undefined) {
|
|
144811
146569
|
process.env.CLAUDISH_CONTEXT_WINDOW = String(cliConfig.contextWindow);
|
|
144812
146570
|
}
|
|
146571
|
+
if (lineupPromise) {
|
|
146572
|
+
const lineup = await lineupPromise;
|
|
146573
|
+
await reportModelLineup(cliConfig, lineup);
|
|
146574
|
+
}
|
|
144813
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, {
|
|
144814
146576
|
...launchSigning ? { nativeSigning: launchSigning } : {},
|
|
144815
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 } : {},
|
|
144816
146588
|
apiBillingOptIn: wantsAnthropicApiBilling(cliConfig),
|
|
144817
146589
|
advisorKeyLookup: advisorKeyLookupAllowed(cliConfig),
|
|
144818
146590
|
summarizeTools: cliConfig.summarizeTools,
|
|
@@ -144830,6 +146602,30 @@ Team Status`);
|
|
|
144830
146602
|
codeMode: cliConfig.codeMode,
|
|
144831
146603
|
hostMode: isPaneChild() ? "pane-child" : cliConfig.interactive ? "interactive" : "other"
|
|
144832
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
|
+
}
|
|
144833
146629
|
const diag = createDiagOutput({
|
|
144834
146630
|
interactive: cliConfig.interactive,
|
|
144835
146631
|
diagMode: cliConfig.diagMode
|
|
@@ -144847,7 +146643,11 @@ Team Status`);
|
|
|
144847
146643
|
diag.cleanup();
|
|
144848
146644
|
};
|
|
144849
146645
|
try {
|
|
144850
|
-
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
|
+
} : {});
|
|
144851
146651
|
} finally {
|
|
144852
146652
|
setDiagOutput(null);
|
|
144853
146653
|
cleanupDiag();
|
|
@@ -144857,6 +146657,7 @@ Team Status`);
|
|
|
144857
146657
|
[claudish] Shutting down proxy server...`);
|
|
144858
146658
|
}
|
|
144859
146659
|
await proxy.shutdown();
|
|
146660
|
+
await modelSettingWatch?.end();
|
|
144860
146661
|
}
|
|
144861
146662
|
if (!cliConfig.quiet) {
|
|
144862
146663
|
const write = cliConfig.interactive ? console.log : console.error;
|