claudish 14.30.0 → 14.30.2
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 +1206 -1682
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -5557,7 +5557,7 @@ var init_env_placeholder = __esm(() => {
|
|
|
5557
5557
|
});
|
|
5558
5558
|
|
|
5559
5559
|
// src/version.ts
|
|
5560
|
-
var VERSION = "14.30.
|
|
5560
|
+
var VERSION = "14.30.2";
|
|
5561
5561
|
|
|
5562
5562
|
// src/redact.ts
|
|
5563
5563
|
function isPlaceholder(value) {
|
|
@@ -10342,12 +10342,15 @@ function resolveClassifierConfig(config, env = process.env) {
|
|
|
10342
10342
|
const envProvider = env.CLAUDISH_CLASSIFIER_PROVIDER?.trim().toLowerCase();
|
|
10343
10343
|
const envModel = env.CLAUDISH_CLASSIFIER_MODEL?.trim();
|
|
10344
10344
|
const enabled = !!flagModel || flagProvider === "anthropic" || envProvider === "anthropic" || !!envModel;
|
|
10345
|
-
return { enabled, model: flagModel || envModel ||
|
|
10345
|
+
return { enabled, model: flagModel || envModel || undefined };
|
|
10346
10346
|
}
|
|
10347
10347
|
function classifierPassthroughEnabled(config, env = process.env) {
|
|
10348
10348
|
return resolveClassifierConfig(config, env).enabled;
|
|
10349
10349
|
}
|
|
10350
|
-
var CLASSIFIER_SYSTEM_MARKER = "You are a security monitor for autonomous AI coding agents.",
|
|
10350
|
+
var CLASSIFIER_SYSTEM_MARKER = "You are a security monitor for autonomous AI coding agents.", NO_CLASSIFIER_MODEL_MESSAGE;
|
|
10351
|
+
var init_classifier_passthrough = __esm(() => {
|
|
10352
|
+
NO_CLASSIFIER_MODEL_MESSAGE = "claudish cannot choose a model for the auto-mode permission classifier: the cloud models " + "catalog is not loaded or lists no Sonnet. Name one with --classifier-model <model> or " + "CLAUDISH_CLASSIFIER_MODEL.";
|
|
10353
|
+
});
|
|
10351
10354
|
|
|
10352
10355
|
// src/tui/runtime/can-draw-tui.ts
|
|
10353
10356
|
function canDrawTui() {
|
|
@@ -14138,7 +14141,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14138
14141
|
}
|
|
14139
14142
|
}
|
|
14140
14143
|
},
|
|
14141
|
-
fetchedAt: "2026-
|
|
14144
|
+
fetchedAt: "2026-12-01T09:23:35.422Z",
|
|
14142
14145
|
format: 1,
|
|
14143
14146
|
recommendations: {
|
|
14144
14147
|
contractVersion: 3,
|
|
@@ -14244,11 +14247,11 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14244
14247
|
tier: "luxury"
|
|
14245
14248
|
}
|
|
14246
14249
|
],
|
|
14247
|
-
generationId: "g-
|
|
14250
|
+
generationId: "g-20261130162421869-567d142f"
|
|
14248
14251
|
},
|
|
14249
14252
|
source: "https://us-central1-claudish-6da10.cloudfunctions.net"
|
|
14250
14253
|
},
|
|
14251
|
-
catalogGenerationId: "g-
|
|
14254
|
+
catalogGenerationId: "g-20261130162421869-567d142f",
|
|
14252
14255
|
entries: [
|
|
14253
14256
|
{
|
|
14254
14257
|
aggregators: [
|
|
@@ -14822,9 +14825,9 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14822
14825
|
],
|
|
14823
14826
|
aliases: [
|
|
14824
14827
|
"anthropic/claude-opus-5.5",
|
|
14825
|
-
"claude-opus-5-5-low",
|
|
14826
14828
|
"claude-opus-5-5-high",
|
|
14827
14829
|
"claude-opus-5-5-medium",
|
|
14830
|
+
"claude-opus-5-5-low",
|
|
14828
14831
|
"claude-opus-5-5-max",
|
|
14829
14832
|
"claude-opus-5-5-xhigh"
|
|
14830
14833
|
],
|
|
@@ -15016,8 +15019,8 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15016
15019
|
"anthropic/claude-sonnet-5.5",
|
|
15017
15020
|
"claude-sonnet-5.5",
|
|
15018
15021
|
"claude-sonnet-5-5-high",
|
|
15019
|
-
"claude-sonnet-5-5-medium",
|
|
15020
15022
|
"claude-sonnet-5-5-low",
|
|
15023
|
+
"claude-sonnet-5-5-medium",
|
|
15021
15024
|
"claude-sonnet-5-5-max",
|
|
15022
15025
|
"claude-sonnet-5-5-xhigh"
|
|
15023
15026
|
],
|
|
@@ -15281,9 +15284,9 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15281
15284
|
],
|
|
15282
15285
|
aliases: [
|
|
15283
15286
|
"google/gemini-4-carbon",
|
|
15284
|
-
"gemini-4-carbon-
|
|
15287
|
+
"gemini-4-carbon-low",
|
|
15285
15288
|
"gemini-4-carbon-high",
|
|
15286
|
-
"gemini-4-carbon-
|
|
15289
|
+
"gemini-4-carbon-medium"
|
|
15287
15290
|
],
|
|
15288
15291
|
contextWindow: 1048576,
|
|
15289
15292
|
contractVersion: 3,
|
|
@@ -15436,10 +15439,10 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15436
15439
|
],
|
|
15437
15440
|
aliases: [
|
|
15438
15441
|
"google/gemini-4-hydrogen",
|
|
15442
|
+
"gemini-4-hydrogen-high",
|
|
15439
15443
|
"gemini-4-hydrogen-xhigh",
|
|
15440
15444
|
"gemini-4-hydrogen-low",
|
|
15441
|
-
"gemini-4-hydrogen-medium"
|
|
15442
|
-
"gemini-4-hydrogen-high"
|
|
15445
|
+
"gemini-4-hydrogen-medium"
|
|
15443
15446
|
],
|
|
15444
15447
|
contextWindow: 1048576,
|
|
15445
15448
|
contractVersion: 3,
|
|
@@ -15593,8 +15596,8 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15593
15596
|
"google/gemini-4-neon",
|
|
15594
15597
|
"gemini-4-neon-xhigh",
|
|
15595
15598
|
"gemini-4-neon-low",
|
|
15596
|
-
"gemini-4-neon-
|
|
15597
|
-
"gemini-4-neon-
|
|
15599
|
+
"gemini-4-neon-medium",
|
|
15600
|
+
"gemini-4-neon-high"
|
|
15598
15601
|
],
|
|
15599
15602
|
contextWindow: 1048576,
|
|
15600
15603
|
contractVersion: 3,
|
|
@@ -18212,9 +18215,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
18212
18215
|
status: "unknown"
|
|
18213
18216
|
},
|
|
18214
18217
|
status: "known",
|
|
18215
|
-
tokenParam:
|
|
18216
|
-
status: "unknown"
|
|
18217
|
-
},
|
|
18218
|
+
tokenParam: "max_output_tokens",
|
|
18218
18219
|
toolsWithReasoning: {
|
|
18219
18220
|
status: "unknown"
|
|
18220
18221
|
}
|
|
@@ -18317,11 +18318,12 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
18317
18318
|
supportsThinking: true,
|
|
18318
18319
|
supportsTools: true,
|
|
18319
18320
|
supportsVision: true,
|
|
18321
|
+
tokenParam: "max_output_tokens",
|
|
18320
18322
|
videoInput: true,
|
|
18321
18323
|
videoOutput: false
|
|
18322
18324
|
}
|
|
18323
18325
|
],
|
|
18324
|
-
lastUpdated: "2026-11-
|
|
18326
|
+
lastUpdated: "2026-11-30T16:24:21.869Z",
|
|
18325
18327
|
models: [],
|
|
18326
18328
|
plans: [
|
|
18327
18329
|
{
|
|
@@ -18982,114 +18984,114 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
18982
18984
|
id: "google-antigravity",
|
|
18983
18985
|
inclusions: [
|
|
18984
18986
|
{
|
|
18985
|
-
externalModelId: "gemini-4-
|
|
18987
|
+
externalModelId: "gemini-4-carbon-low",
|
|
18986
18988
|
kind: "provider_model",
|
|
18987
18989
|
provider: "antigravity",
|
|
18988
18990
|
resolution: {
|
|
18989
|
-
modelId: "gemini-4-
|
|
18991
|
+
modelId: "gemini-4-carbon",
|
|
18990
18992
|
status: "mapped"
|
|
18991
18993
|
},
|
|
18992
|
-
sourceText: "gemini-4-
|
|
18994
|
+
sourceText: "gemini-4-carbon-low"
|
|
18993
18995
|
},
|
|
18994
18996
|
{
|
|
18995
|
-
externalModelId: "gemini-4-carbon-
|
|
18997
|
+
externalModelId: "gemini-4-carbon-high",
|
|
18996
18998
|
kind: "provider_model",
|
|
18997
18999
|
provider: "antigravity",
|
|
18998
19000
|
resolution: {
|
|
18999
19001
|
modelId: "gemini-4-carbon",
|
|
19000
19002
|
status: "mapped"
|
|
19001
19003
|
},
|
|
19002
|
-
sourceText: "gemini-4-carbon-
|
|
19004
|
+
sourceText: "gemini-4-carbon-high"
|
|
19003
19005
|
},
|
|
19004
19006
|
{
|
|
19005
|
-
externalModelId: "
|
|
19007
|
+
externalModelId: "gemini-4-neon-xhigh",
|
|
19006
19008
|
kind: "provider_model",
|
|
19007
19009
|
provider: "antigravity",
|
|
19008
19010
|
resolution: {
|
|
19009
|
-
modelId: "
|
|
19011
|
+
modelId: "gemini-4-neon",
|
|
19010
19012
|
status: "mapped"
|
|
19011
19013
|
},
|
|
19012
|
-
sourceText: "
|
|
19014
|
+
sourceText: "gemini-4-neon-xhigh"
|
|
19013
19015
|
},
|
|
19014
19016
|
{
|
|
19015
|
-
externalModelId: "
|
|
19017
|
+
externalModelId: "gemini-4-neon-low",
|
|
19016
19018
|
kind: "provider_model",
|
|
19017
19019
|
provider: "antigravity",
|
|
19018
19020
|
resolution: {
|
|
19019
|
-
modelId: "
|
|
19021
|
+
modelId: "gemini-4-neon",
|
|
19020
19022
|
status: "mapped"
|
|
19021
19023
|
},
|
|
19022
|
-
sourceText: "
|
|
19024
|
+
sourceText: "gemini-4-neon-low"
|
|
19023
19025
|
},
|
|
19024
19026
|
{
|
|
19025
|
-
externalModelId: "gemini-4-
|
|
19027
|
+
externalModelId: "gemini-4-carbon-medium",
|
|
19026
19028
|
kind: "provider_model",
|
|
19027
19029
|
provider: "antigravity",
|
|
19028
19030
|
resolution: {
|
|
19029
|
-
modelId: "gemini-4-
|
|
19031
|
+
modelId: "gemini-4-carbon",
|
|
19030
19032
|
status: "mapped"
|
|
19031
19033
|
},
|
|
19032
|
-
sourceText: "gemini-4-
|
|
19034
|
+
sourceText: "gemini-4-carbon-medium"
|
|
19033
19035
|
},
|
|
19034
19036
|
{
|
|
19035
|
-
externalModelId: "
|
|
19037
|
+
externalModelId: "claude-opus-5-5-high",
|
|
19036
19038
|
kind: "provider_model",
|
|
19037
19039
|
provider: "antigravity",
|
|
19038
19040
|
resolution: {
|
|
19039
|
-
modelId: "
|
|
19041
|
+
modelId: "claude-opus-5-5",
|
|
19040
19042
|
status: "mapped"
|
|
19041
19043
|
},
|
|
19042
|
-
sourceText: "
|
|
19044
|
+
sourceText: "claude-opus-5-5-high"
|
|
19043
19045
|
},
|
|
19044
19046
|
{
|
|
19045
|
-
externalModelId: "claude-
|
|
19047
|
+
externalModelId: "claude-opus-5-5-medium",
|
|
19046
19048
|
kind: "provider_model",
|
|
19047
19049
|
provider: "antigravity",
|
|
19048
19050
|
resolution: {
|
|
19049
|
-
modelId: "claude-
|
|
19051
|
+
modelId: "claude-opus-5-5",
|
|
19050
19052
|
status: "mapped"
|
|
19051
19053
|
},
|
|
19052
|
-
sourceText: "claude-
|
|
19054
|
+
sourceText: "claude-opus-5-5-medium"
|
|
19053
19055
|
},
|
|
19054
19056
|
{
|
|
19055
|
-
externalModelId: "gemini-4-
|
|
19057
|
+
externalModelId: "gemini-4-hydrogen-high",
|
|
19056
19058
|
kind: "provider_model",
|
|
19057
19059
|
provider: "antigravity",
|
|
19058
19060
|
resolution: {
|
|
19059
|
-
modelId: "gemini-4-
|
|
19061
|
+
modelId: "gemini-4-hydrogen",
|
|
19060
19062
|
status: "mapped"
|
|
19061
19063
|
},
|
|
19062
|
-
sourceText: "gemini-4-
|
|
19064
|
+
sourceText: "gemini-4-hydrogen-high"
|
|
19063
19065
|
},
|
|
19064
19066
|
{
|
|
19065
|
-
externalModelId: "
|
|
19067
|
+
externalModelId: "gemini-4-hydrogen-xhigh",
|
|
19066
19068
|
kind: "provider_model",
|
|
19067
19069
|
provider: "antigravity",
|
|
19068
19070
|
resolution: {
|
|
19069
|
-
modelId: "
|
|
19071
|
+
modelId: "gemini-4-hydrogen",
|
|
19070
19072
|
status: "mapped"
|
|
19071
19073
|
},
|
|
19072
|
-
sourceText: "
|
|
19074
|
+
sourceText: "gemini-4-hydrogen-xhigh"
|
|
19073
19075
|
},
|
|
19074
19076
|
{
|
|
19075
|
-
externalModelId: "
|
|
19077
|
+
externalModelId: "claude-sonnet-5-5-high",
|
|
19076
19078
|
kind: "provider_model",
|
|
19077
19079
|
provider: "antigravity",
|
|
19078
19080
|
resolution: {
|
|
19079
|
-
modelId: "
|
|
19081
|
+
modelId: "claude-sonnet-5-5",
|
|
19080
19082
|
status: "mapped"
|
|
19081
19083
|
},
|
|
19082
|
-
sourceText: "
|
|
19084
|
+
sourceText: "claude-sonnet-5-5-high"
|
|
19083
19085
|
},
|
|
19084
19086
|
{
|
|
19085
|
-
externalModelId: "claude-
|
|
19087
|
+
externalModelId: "claude-opus-5-5-low",
|
|
19086
19088
|
kind: "provider_model",
|
|
19087
19089
|
provider: "antigravity",
|
|
19088
19090
|
resolution: {
|
|
19089
|
-
modelId: "claude-
|
|
19091
|
+
modelId: "claude-opus-5-5",
|
|
19090
19092
|
status: "mapped"
|
|
19091
19093
|
},
|
|
19092
|
-
sourceText: "claude-
|
|
19094
|
+
sourceText: "claude-opus-5-5-low"
|
|
19093
19095
|
},
|
|
19094
19096
|
{
|
|
19095
19097
|
externalModelId: "gemini-4-neon-medium",
|
|
@@ -19102,14 +19104,14 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19102
19104
|
sourceText: "gemini-4-neon-medium"
|
|
19103
19105
|
},
|
|
19104
19106
|
{
|
|
19105
|
-
externalModelId: "
|
|
19107
|
+
externalModelId: "gemini-4-neon-high",
|
|
19106
19108
|
kind: "provider_model",
|
|
19107
19109
|
provider: "antigravity",
|
|
19108
19110
|
resolution: {
|
|
19109
|
-
modelId: "
|
|
19111
|
+
modelId: "gemini-4-neon",
|
|
19110
19112
|
status: "mapped"
|
|
19111
19113
|
},
|
|
19112
|
-
sourceText: "
|
|
19114
|
+
sourceText: "gemini-4-neon-high"
|
|
19113
19115
|
},
|
|
19114
19116
|
{
|
|
19115
19117
|
externalModelId: "gemini-4-hydrogen-low",
|
|
@@ -19122,14 +19124,14 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19122
19124
|
sourceText: "gemini-4-hydrogen-low"
|
|
19123
19125
|
},
|
|
19124
19126
|
{
|
|
19125
|
-
externalModelId: "
|
|
19127
|
+
externalModelId: "claude-sonnet-5-5-low",
|
|
19126
19128
|
kind: "provider_model",
|
|
19127
19129
|
provider: "antigravity",
|
|
19128
19130
|
resolution: {
|
|
19129
|
-
modelId: "
|
|
19131
|
+
modelId: "claude-sonnet-5-5",
|
|
19130
19132
|
status: "mapped"
|
|
19131
19133
|
},
|
|
19132
|
-
sourceText: "
|
|
19134
|
+
sourceText: "claude-sonnet-5-5-low"
|
|
19133
19135
|
},
|
|
19134
19136
|
{
|
|
19135
19137
|
externalModelId: "gemini-4-hydrogen-medium",
|
|
@@ -19142,14 +19144,14 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19142
19144
|
sourceText: "gemini-4-hydrogen-medium"
|
|
19143
19145
|
},
|
|
19144
19146
|
{
|
|
19145
|
-
externalModelId: "
|
|
19147
|
+
externalModelId: "claude-sonnet-5-5-medium",
|
|
19146
19148
|
kind: "provider_model",
|
|
19147
19149
|
provider: "antigravity",
|
|
19148
19150
|
resolution: {
|
|
19149
|
-
modelId: "
|
|
19151
|
+
modelId: "claude-sonnet-5-5",
|
|
19150
19152
|
status: "mapped"
|
|
19151
19153
|
},
|
|
19152
|
-
sourceText: "
|
|
19154
|
+
sourceText: "claude-sonnet-5-5-medium"
|
|
19153
19155
|
}
|
|
19154
19156
|
],
|
|
19155
19157
|
modelDiscovery: "client",
|
|
@@ -19493,34 +19495,34 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19493
19495
|
id: "ollama-cloud",
|
|
19494
19496
|
inclusions: [
|
|
19495
19497
|
{
|
|
19496
|
-
externalModelId: "
|
|
19498
|
+
externalModelId: "glm-5.3",
|
|
19497
19499
|
kind: "provider_model",
|
|
19498
19500
|
provider: "ollamacloud",
|
|
19499
19501
|
resolution: {
|
|
19500
|
-
modelId: "
|
|
19502
|
+
modelId: "glm-5.3",
|
|
19501
19503
|
status: "mapped"
|
|
19502
19504
|
},
|
|
19503
|
-
sourceText: "
|
|
19505
|
+
sourceText: "glm-5.3"
|
|
19504
19506
|
},
|
|
19505
19507
|
{
|
|
19506
|
-
externalModelId: "
|
|
19508
|
+
externalModelId: "deepseek-v4.1-flash",
|
|
19507
19509
|
kind: "provider_model",
|
|
19508
19510
|
provider: "ollamacloud",
|
|
19509
19511
|
resolution: {
|
|
19510
|
-
modelId: "
|
|
19512
|
+
modelId: "deepseek-v4.1-flash",
|
|
19511
19513
|
status: "mapped"
|
|
19512
19514
|
},
|
|
19513
|
-
sourceText: "
|
|
19515
|
+
sourceText: "deepseek-v4.1-flash"
|
|
19514
19516
|
},
|
|
19515
19517
|
{
|
|
19516
|
-
externalModelId: "
|
|
19518
|
+
externalModelId: "glm-5.3-flash",
|
|
19517
19519
|
kind: "provider_model",
|
|
19518
19520
|
provider: "ollamacloud",
|
|
19519
19521
|
resolution: {
|
|
19520
|
-
modelId: "
|
|
19522
|
+
modelId: "glm-5.3-flash",
|
|
19521
19523
|
status: "mapped"
|
|
19522
19524
|
},
|
|
19523
|
-
sourceText: "
|
|
19525
|
+
sourceText: "glm-5.3-flash"
|
|
19524
19526
|
},
|
|
19525
19527
|
{
|
|
19526
19528
|
externalModelId: "kimi-k3.1-pro",
|
|
@@ -19533,14 +19535,14 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19533
19535
|
sourceText: "kimi-k3.1-pro"
|
|
19534
19536
|
},
|
|
19535
19537
|
{
|
|
19536
|
-
externalModelId: "
|
|
19538
|
+
externalModelId: "mimo-v2.6-pro",
|
|
19537
19539
|
kind: "provider_model",
|
|
19538
19540
|
provider: "ollamacloud",
|
|
19539
19541
|
resolution: {
|
|
19540
|
-
modelId: "
|
|
19542
|
+
modelId: "mimo-v2.6-pro",
|
|
19541
19543
|
status: "mapped"
|
|
19542
19544
|
},
|
|
19543
|
-
sourceText: "
|
|
19545
|
+
sourceText: "mimo-v2.6-pro"
|
|
19544
19546
|
},
|
|
19545
19547
|
{
|
|
19546
19548
|
externalModelId: "minimax-m3.1-flash",
|
|
@@ -19553,14 +19555,14 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19553
19555
|
sourceText: "minimax-m3.1-flash"
|
|
19554
19556
|
},
|
|
19555
19557
|
{
|
|
19556
|
-
externalModelId: "mimo-v2.6-
|
|
19558
|
+
externalModelId: "mimo-v2.6-flash",
|
|
19557
19559
|
kind: "provider_model",
|
|
19558
19560
|
provider: "ollamacloud",
|
|
19559
19561
|
resolution: {
|
|
19560
|
-
modelId: "mimo-v2.6-
|
|
19562
|
+
modelId: "mimo-v2.6-flash",
|
|
19561
19563
|
status: "mapped"
|
|
19562
19564
|
},
|
|
19563
|
-
sourceText: "mimo-v2.6-
|
|
19565
|
+
sourceText: "mimo-v2.6-flash"
|
|
19564
19566
|
}
|
|
19565
19567
|
],
|
|
19566
19568
|
modelDiscovery: "catalog",
|
|
@@ -19815,7 +19817,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19815
19817
|
}
|
|
19816
19818
|
],
|
|
19817
19819
|
routeRegistry: {
|
|
19818
|
-
generationId: "g-
|
|
19820
|
+
generationId: "g-20261130162421869-567d142f",
|
|
19819
19821
|
registry: {
|
|
19820
19822
|
contractVersion: 3,
|
|
19821
19823
|
registryVersion: "3.7.0",
|
|
@@ -37636,13 +37638,13 @@ function getCatalogEntries() {
|
|
|
37636
37638
|
function catalogOrigin() {
|
|
37637
37639
|
return getCatalogSnapshot()?.origin ?? "none";
|
|
37638
37640
|
}
|
|
37639
|
-
function
|
|
37641
|
+
function latestAnthropicTierEntry(tier, accept) {
|
|
37640
37642
|
const snapshot = getCatalogSnapshot();
|
|
37641
37643
|
if (snapshot?.origin !== "disk")
|
|
37642
37644
|
return null;
|
|
37643
37645
|
const { entries } = snapshot;
|
|
37644
37646
|
const family = new RegExp(`^claude-${tier}-`, "i");
|
|
37645
|
-
const matches = entries.filter((entry) => family.test(entry.modelId) && accept(entry
|
|
37647
|
+
const matches = entries.filter((entry) => family.test(entry.modelId) && accept(entry));
|
|
37646
37648
|
if (matches.length === 0)
|
|
37647
37649
|
return null;
|
|
37648
37650
|
matches.sort((a, b) => {
|
|
@@ -37655,7 +37657,13 @@ function latestAnthropicTierModelId(tier, accept = () => true) {
|
|
|
37655
37657
|
return aFast - bFast;
|
|
37656
37658
|
return b.modelId.localeCompare(a.modelId);
|
|
37657
37659
|
});
|
|
37658
|
-
return matches[0]
|
|
37660
|
+
return matches[0];
|
|
37661
|
+
}
|
|
37662
|
+
function latestAnthropicTierModelId(tier, accept = () => true) {
|
|
37663
|
+
return latestAnthropicTierEntry(tier, (entry) => accept(entry.modelId, entry))?.modelId ?? null;
|
|
37664
|
+
}
|
|
37665
|
+
function implicitAnthropicTierEntry(tier, accept = () => true) {
|
|
37666
|
+
return latestAnthropicTierEntry(tier, (entry) => !isOptInWireId(entry.modelId) && accept(entry));
|
|
37659
37667
|
}
|
|
37660
37668
|
function isCatalogWarm() {
|
|
37661
37669
|
return _memCache !== null && _memCache.entries.length > 0;
|
|
@@ -47843,8 +47851,6 @@ function buildOAuthHeaders(token, accountId) {
|
|
|
47843
47851
|
};
|
|
47844
47852
|
if (accountId) {
|
|
47845
47853
|
headers["chatgpt-account-id"] = accountId;
|
|
47846
|
-
headers["x-conversation-id"] = "claudish-session";
|
|
47847
|
-
headers["x-session-id"] = "claudish-session";
|
|
47848
47854
|
}
|
|
47849
47855
|
return headers;
|
|
47850
47856
|
}
|
|
@@ -50337,8 +50343,12 @@ var init_openai_codex = __esm(() => {
|
|
|
50337
50343
|
getEndpoint(_targetModel, binding) {
|
|
50338
50344
|
return binding?.auth?.endpoint ?? super.getEndpoint();
|
|
50339
50345
|
}
|
|
50340
|
-
async getHeaders(
|
|
50346
|
+
async getHeaders(claudeRequest, binding) {
|
|
50341
50347
|
const auth = binding?.auth;
|
|
50348
|
+
if (auth?.arm === "oauth") {
|
|
50349
|
+
const key = conversationKey(claudeRequest);
|
|
50350
|
+
return { ...auth.headers, "session-id": key, "thread-id": key };
|
|
50351
|
+
}
|
|
50342
50352
|
if (auth)
|
|
50343
50353
|
return { ...auth.headers };
|
|
50344
50354
|
return super.getHeaders();
|
|
@@ -63575,76 +63585,9 @@ var init_wire_markers = __esm(() => {
|
|
|
63575
63585
|
};
|
|
63576
63586
|
});
|
|
63577
63587
|
|
|
63578
|
-
// src/providers/catalog-query.ts
|
|
63579
|
-
import { statSync as statSync11 } from "fs";
|
|
63580
|
-
function project(entry) {
|
|
63581
|
-
return {
|
|
63582
|
-
modelId: entry.modelId,
|
|
63583
|
-
aliases: entry.aliases,
|
|
63584
|
-
supportsVision: entry.supportsVision,
|
|
63585
|
-
contextWindow: entry.contextWindow,
|
|
63586
|
-
releaseDate: entry.releaseDate,
|
|
63587
|
-
aggregators: entry.aggregators
|
|
63588
|
-
};
|
|
63589
|
-
}
|
|
63590
|
-
function getCachedEntries() {
|
|
63591
|
-
let mtimeMs;
|
|
63592
|
-
try {
|
|
63593
|
-
mtimeMs = statSync11(ALL_MODELS_CACHE_PATH).mtimeMs;
|
|
63594
|
-
} catch {
|
|
63595
|
-
return null;
|
|
63596
|
-
}
|
|
63597
|
-
if (mtimeMs === _memoMtimeMs && _memoEntries !== null) {
|
|
63598
|
-
return _memoEntries;
|
|
63599
|
-
}
|
|
63600
|
-
const cache = readAllModelsCache();
|
|
63601
|
-
if (!cache)
|
|
63602
|
-
return null;
|
|
63603
|
-
_memoEntries = cache.entries;
|
|
63604
|
-
_memoMtimeMs = mtimeMs;
|
|
63605
|
-
return _memoEntries;
|
|
63606
|
-
}
|
|
63607
|
-
function findEntryByAlias(alias, accept = () => true) {
|
|
63608
|
-
const entries = getCachedEntries();
|
|
63609
|
-
if (!entries || entries.length === 0)
|
|
63610
|
-
return null;
|
|
63611
|
-
for (const entry of entries) {
|
|
63612
|
-
if (entry.aliases.includes(alias) && accept(entry.modelId)) {
|
|
63613
|
-
return project(entry);
|
|
63614
|
-
}
|
|
63615
|
-
}
|
|
63616
|
-
return null;
|
|
63617
|
-
}
|
|
63618
|
-
function findEntryByModelId(modelId) {
|
|
63619
|
-
const entries = getCachedEntries();
|
|
63620
|
-
if (!entries || entries.length === 0)
|
|
63621
|
-
return null;
|
|
63622
|
-
for (const entry of entries) {
|
|
63623
|
-
if (entry.modelId === modelId) {
|
|
63624
|
-
return project(entry);
|
|
63625
|
-
}
|
|
63626
|
-
}
|
|
63627
|
-
return null;
|
|
63628
|
-
}
|
|
63629
|
-
function findVisionAlias(alias) {
|
|
63630
|
-
const entries = getCachedEntries();
|
|
63631
|
-
if (!entries || entries.length === 0)
|
|
63632
|
-
return null;
|
|
63633
|
-
for (const entry of entries) {
|
|
63634
|
-
if (entry.supportsVision === true && entry.aliases.includes(alias) && !isOptInWireId(entry.modelId)) {
|
|
63635
|
-
return project(entry);
|
|
63636
|
-
}
|
|
63637
|
-
}
|
|
63638
|
-
return null;
|
|
63639
|
-
}
|
|
63640
|
-
var _memoEntries = null, _memoMtimeMs = -1;
|
|
63641
|
-
var init_catalog_query = __esm(() => {
|
|
63642
|
-
init_all_models_cache();
|
|
63643
|
-
});
|
|
63644
|
-
|
|
63645
63588
|
// src/services/vision-proxy.ts
|
|
63646
63589
|
function getVisionModel() {
|
|
63647
|
-
return
|
|
63590
|
+
return implicitAnthropicTierEntry("sonnet", (entry) => entry.supportsVision === true)?.modelId ?? null;
|
|
63648
63591
|
}
|
|
63649
63592
|
function parseDataUrl(dataUrl) {
|
|
63650
63593
|
if (!dataUrl.startsWith("data:"))
|
|
@@ -63662,7 +63605,7 @@ function parseDataUrl(dataUrl) {
|
|
|
63662
63605
|
return null;
|
|
63663
63606
|
return { mediaType, data };
|
|
63664
63607
|
}
|
|
63665
|
-
async function describeImage(image, auth) {
|
|
63608
|
+
async function describeImage(image, auth, model) {
|
|
63666
63609
|
const parsed = parseDataUrl(image.image_url.url);
|
|
63667
63610
|
if (!parsed) {
|
|
63668
63611
|
log("[VisionProxy] Skipping image: malformed or non-base64 data URL");
|
|
@@ -63670,7 +63613,7 @@ async function describeImage(image, auth) {
|
|
|
63670
63613
|
}
|
|
63671
63614
|
const { mediaType, data } = parsed;
|
|
63672
63615
|
const requestBody = {
|
|
63673
|
-
model
|
|
63616
|
+
model,
|
|
63674
63617
|
max_tokens: MAX_TOKENS_PER_IMAGE,
|
|
63675
63618
|
stream: false,
|
|
63676
63619
|
messages: [
|
|
@@ -63735,7 +63678,12 @@ async function describeImages(images, auth) {
|
|
|
63735
63678
|
if (images.length === 0)
|
|
63736
63679
|
return [];
|
|
63737
63680
|
try {
|
|
63738
|
-
const
|
|
63681
|
+
const model = getVisionModel();
|
|
63682
|
+
if (model === null) {
|
|
63683
|
+
log("[VisionProxy] No Sonnet with vision in the cloud models catalog; no image description requested");
|
|
63684
|
+
return null;
|
|
63685
|
+
}
|
|
63686
|
+
const results = await Promise.all(images.map((img) => describeImage(img, auth, model)));
|
|
63739
63687
|
if (results.some((r) => r === null)) {
|
|
63740
63688
|
log("[VisionProxy] One or more image descriptions failed, falling back");
|
|
63741
63689
|
return null;
|
|
@@ -63759,7 +63707,7 @@ var MAX_TOKENS_PER_IMAGE = 1024, VISION_ENDPOINT = "https://api.anthropic.com/v1
|
|
|
63759
63707
|
Be comprehensive - this description will be the only information the model has about the image.`;
|
|
63760
63708
|
var init_vision_proxy = __esm(() => {
|
|
63761
63709
|
init_logger();
|
|
63762
|
-
|
|
63710
|
+
init_catalog_client();
|
|
63763
63711
|
});
|
|
63764
63712
|
|
|
63765
63713
|
// src/auth/claude-code-facts.ts
|
|
@@ -63893,7 +63841,7 @@ function reduceEvent(state, event) {
|
|
|
63893
63841
|
}
|
|
63894
63842
|
|
|
63895
63843
|
// src/session-events/transcript-tailer.ts
|
|
63896
|
-
import { closeSync as closeSync10, openSync as openSync10, readSync as readSync3, statSync as
|
|
63844
|
+
import { closeSync as closeSync10, openSync as openSync10, readSync as readSync3, statSync as statSync11 } from "fs";
|
|
63897
63845
|
|
|
63898
63846
|
class TranscriptTailer {
|
|
63899
63847
|
filePath;
|
|
@@ -63938,7 +63886,7 @@ class TranscriptTailer {
|
|
|
63938
63886
|
if (this.disposed)
|
|
63939
63887
|
return;
|
|
63940
63888
|
try {
|
|
63941
|
-
const size =
|
|
63889
|
+
const size = statSync11(this.filePath).size;
|
|
63942
63890
|
if (size < this.offset) {
|
|
63943
63891
|
this.offset = 0;
|
|
63944
63892
|
this.buffer = "";
|
|
@@ -73747,6 +73695,62 @@ var init_poe = __esm(() => {
|
|
|
73747
73695
|
init_provider_model_discovery();
|
|
73748
73696
|
});
|
|
73749
73697
|
|
|
73698
|
+
// src/providers/catalog-query.ts
|
|
73699
|
+
import { statSync as statSync12 } from "fs";
|
|
73700
|
+
function project(entry) {
|
|
73701
|
+
return {
|
|
73702
|
+
modelId: entry.modelId,
|
|
73703
|
+
aliases: entry.aliases,
|
|
73704
|
+
supportsVision: entry.supportsVision,
|
|
73705
|
+
contextWindow: entry.contextWindow,
|
|
73706
|
+
releaseDate: entry.releaseDate,
|
|
73707
|
+
aggregators: entry.aggregators
|
|
73708
|
+
};
|
|
73709
|
+
}
|
|
73710
|
+
function getCachedEntries() {
|
|
73711
|
+
let mtimeMs;
|
|
73712
|
+
try {
|
|
73713
|
+
mtimeMs = statSync12(ALL_MODELS_CACHE_PATH).mtimeMs;
|
|
73714
|
+
} catch {
|
|
73715
|
+
return null;
|
|
73716
|
+
}
|
|
73717
|
+
if (mtimeMs === _memoMtimeMs && _memoEntries !== null) {
|
|
73718
|
+
return _memoEntries;
|
|
73719
|
+
}
|
|
73720
|
+
const cache = readAllModelsCache();
|
|
73721
|
+
if (!cache)
|
|
73722
|
+
return null;
|
|
73723
|
+
_memoEntries = cache.entries;
|
|
73724
|
+
_memoMtimeMs = mtimeMs;
|
|
73725
|
+
return _memoEntries;
|
|
73726
|
+
}
|
|
73727
|
+
function findEntryByAlias(alias, accept = () => true) {
|
|
73728
|
+
const entries = getCachedEntries();
|
|
73729
|
+
if (!entries || entries.length === 0)
|
|
73730
|
+
return null;
|
|
73731
|
+
for (const entry of entries) {
|
|
73732
|
+
if (entry.aliases.includes(alias) && accept(entry.modelId)) {
|
|
73733
|
+
return project(entry);
|
|
73734
|
+
}
|
|
73735
|
+
}
|
|
73736
|
+
return null;
|
|
73737
|
+
}
|
|
73738
|
+
function findEntryByModelId(modelId) {
|
|
73739
|
+
const entries = getCachedEntries();
|
|
73740
|
+
if (!entries || entries.length === 0)
|
|
73741
|
+
return null;
|
|
73742
|
+
for (const entry of entries) {
|
|
73743
|
+
if (entry.modelId === modelId) {
|
|
73744
|
+
return project(entry);
|
|
73745
|
+
}
|
|
73746
|
+
}
|
|
73747
|
+
return null;
|
|
73748
|
+
}
|
|
73749
|
+
var _memoEntries = null, _memoMtimeMs = -1;
|
|
73750
|
+
var init_catalog_query = __esm(() => {
|
|
73751
|
+
init_all_models_cache();
|
|
73752
|
+
});
|
|
73753
|
+
|
|
73750
73754
|
// src/providers/transport/vertex-discovery.ts
|
|
73751
73755
|
import { readFile as readFile6 } from "fs/promises";
|
|
73752
73756
|
function _clearVertexDiscoveryCache() {
|
|
@@ -111015,8 +111019,13 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
111015
111019
|
log(`[RequestMeta] model=${body.model} output_config=${JSON.stringify(body.output_config) ?? "(none)"} metadata=${JSON.stringify(body.metadata) ?? "(none)"} anthropic-beta=${c.req.header("anthropic-beta") ?? "(none)"}`);
|
|
111016
111020
|
maybeCaptureClassifierRequest(c, body);
|
|
111017
111021
|
if (!monitorMode && options.classifier?.enabled && isAutoModeClassifierRequest(body)) {
|
|
111018
|
-
|
|
111019
|
-
|
|
111022
|
+
const classifierModel = options.classifier.model ?? implicitAnthropicTierEntry("sonnet")?.modelId;
|
|
111023
|
+
if (!classifierModel) {
|
|
111024
|
+
log("[Classifier] refused: no model named and no Sonnet in the cloud models catalog");
|
|
111025
|
+
return c.json(wrapAnthropicError(400, NO_CLASSIFIER_MODEL_MESSAGE, "invalid_request_error"), 400);
|
|
111026
|
+
}
|
|
111027
|
+
log(`[Classifier] auto-mode permission classifier \u2192 native Anthropic (model ${body.model} \u2192 ${classifierModel})`);
|
|
111028
|
+
rewriteClassifierForNative(body, classifierModel);
|
|
111020
111029
|
const classifierSigning = defaultRequestSigning(body.model);
|
|
111021
111030
|
setNativeSigning(c, classifierSigning);
|
|
111022
111031
|
return await withAdvisor(nativeHandler, classifierSigning).handle(c, body);
|
|
@@ -111092,6 +111101,7 @@ var init_proxy_server = __esm(() => {
|
|
|
111092
111101
|
init_cors();
|
|
111093
111102
|
init_base_api_format();
|
|
111094
111103
|
init_authority();
|
|
111104
|
+
init_classifier_passthrough();
|
|
111095
111105
|
init_policy();
|
|
111096
111106
|
init_advisor_decorator();
|
|
111097
111107
|
init_advisor_panel_gateway();
|
|
@@ -116448,6 +116458,7 @@ var init_claude_runner = __esm(() => {
|
|
|
116448
116458
|
init_model_catalog();
|
|
116449
116459
|
init_claude_code_facts();
|
|
116450
116460
|
init_claude_code_login();
|
|
116461
|
+
init_classifier_passthrough();
|
|
116451
116462
|
init_config();
|
|
116452
116463
|
init_anthropic_forward();
|
|
116453
116464
|
init_harness_gateway();
|
|
@@ -119105,231 +119116,14 @@ var init_team_orchestrator = __esm(() => {
|
|
|
119105
119116
|
CANCELLED_DETAIL = `Stopped on the caller's instruction via team(mode:"cancel"). ` + "Whatever the child had written up to that point is in its response file.";
|
|
119106
119117
|
});
|
|
119107
119118
|
|
|
119108
|
-
// src/mcp-session/probe-launch-vars.ts
|
|
119109
|
-
var PROBE_PLUGIN_VARS, PROBE_MODE_VARS, CALLER_LAUNCH_ENV_KEYS, PROBE_COWORK_SWITCH = "CLAUDE_CODE_USE_COWORK_PLUGINS", PROBE_REFUSAL_ENV_KEYS, HOST_READ_ENV_KEYS;
|
|
119110
|
-
var init_probe_launch_vars = __esm(() => {
|
|
119111
|
-
PROBE_PLUGIN_VARS = [
|
|
119112
|
-
"CLAUDE_CODE_PLUGIN_CACHE_DIR",
|
|
119113
|
-
"CLAUDE_CODE_PLUGIN_SEED_DIR",
|
|
119114
|
-
"CLAUDE_CODE_PLUGIN_DIRS",
|
|
119115
|
-
"CLAUDE_CODE_PLUGIN_USE_ZIP_CACHE"
|
|
119116
|
-
];
|
|
119117
|
-
PROBE_MODE_VARS = [
|
|
119118
|
-
"CLAUDE_CODE_RESTRICTED",
|
|
119119
|
-
"CLAUDE_CODE_SAFE_MODE",
|
|
119120
|
-
"CLAUDE_CODE_SIMPLE",
|
|
119121
|
-
"CLAUDE_CODE_RESTRICT_PERSONAL_CONFIG",
|
|
119122
|
-
"CLAUDE_CODE_DISABLE_BUNDLED_SKILLS",
|
|
119123
|
-
"CLAUDE_CODE_DISABLE_POLICY_SKILLS",
|
|
119124
|
-
"CLAUDE_CODE_DISABLE_CLAUDE_API_SKILL",
|
|
119125
|
-
"CLAUDE_CODE_DISABLE_CLAUDE_CODE_SKILL",
|
|
119126
|
-
"CLAUDE_CODE_SKIP_PLUGIN_MCP_SERVERS",
|
|
119127
|
-
"CLAUDE_CODE_SKIP_PLUGIN_MCP_SERVERS_EXCEPT",
|
|
119128
|
-
"CLAUDE_CODE_SKIP_PLUGIN_LOCAL_MCP_SERVERS",
|
|
119129
|
-
"CLAUDE_CODE_SKIP_PLUGIN_MCP_BUNDLES",
|
|
119130
|
-
"ENABLE_CLAUDEAI_MCP_SERVERS"
|
|
119131
|
-
];
|
|
119132
|
-
CALLER_LAUNCH_ENV_KEYS = [
|
|
119133
|
-
"CLAUDE_CONFIG_DIR",
|
|
119134
|
-
...PROBE_PLUGIN_VARS,
|
|
119135
|
-
...PROBE_MODE_VARS
|
|
119136
|
-
];
|
|
119137
|
-
PROBE_REFUSAL_ENV_KEYS = [PROBE_COWORK_SWITCH];
|
|
119138
|
-
HOST_READ_ENV_KEYS = [...CALLER_LAUNCH_ENV_KEYS, ...PROBE_REFUSAL_ENV_KEYS];
|
|
119139
|
-
});
|
|
119140
|
-
|
|
119141
|
-
// src/mcp-session/host-launch.ts
|
|
119142
|
-
import { readFileSync as readFileSync45, readlinkSync } from "fs";
|
|
119143
|
-
function bindDarwin() {
|
|
119144
|
-
const { dlopen, FFIType, ptr } = __require("bun:ffi");
|
|
119145
|
-
const lib = dlopen("libSystem.B.dylib", {
|
|
119146
|
-
sysctl: {
|
|
119147
|
-
args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.u64],
|
|
119148
|
-
returns: FFIType.i32
|
|
119149
|
-
},
|
|
119150
|
-
proc_pidinfo: {
|
|
119151
|
-
args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
|
|
119152
|
-
returns: FFIType.i32
|
|
119153
|
-
}
|
|
119154
|
-
});
|
|
119155
|
-
const sysctl = (name, out, len) => lib.symbols.sysctl(ptr(name), name.length, ptr(out), ptr(len), null, 0n);
|
|
119156
|
-
return {
|
|
119157
|
-
argmax() {
|
|
119158
|
-
const out = new Int32Array(1);
|
|
119159
|
-
const len = new BigUint64Array([4n]);
|
|
119160
|
-
return sysctl(new Int32Array([CTL_KERN, KERN_ARGMAX]), out, len) === 0 ? out[0] : null;
|
|
119161
|
-
},
|
|
119162
|
-
procargs(pid, size) {
|
|
119163
|
-
const buf = Buffer.alloc(size);
|
|
119164
|
-
const len = new BigUint64Array([BigInt(size)]);
|
|
119165
|
-
if (sysctl(new Int32Array([CTL_KERN, KERN_PROCARGS2, pid]), buf, len) !== 0)
|
|
119166
|
-
return null;
|
|
119167
|
-
return buf.subarray(0, Number(len[0]));
|
|
119168
|
-
},
|
|
119169
|
-
cwd(pid) {
|
|
119170
|
-
const buf = Buffer.alloc(VNODEPATHINFO_BYTES);
|
|
119171
|
-
const got = lib.symbols.proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0n, ptr(buf), buf.length);
|
|
119172
|
-
if (got !== buf.length)
|
|
119173
|
-
return null;
|
|
119174
|
-
return cwdOfVnodePathInfo(buf);
|
|
119175
|
-
}
|
|
119176
|
-
};
|
|
119177
|
-
}
|
|
119178
|
-
function cwdOfVnodePathInfo(buf) {
|
|
119179
|
-
if (buf.length !== VNODEPATHINFO_BYTES)
|
|
119180
|
-
return null;
|
|
119181
|
-
const field = buf.subarray(VNODE_INFO_BYTES, VNODE_INFO_BYTES + MAXPATHLEN);
|
|
119182
|
-
const end = field.indexOf(0);
|
|
119183
|
-
if (end <= 0)
|
|
119184
|
-
return null;
|
|
119185
|
-
return field.toString("utf8", 0, end);
|
|
119186
|
-
}
|
|
119187
|
-
function darwin() {
|
|
119188
|
-
if (darwinBinding !== undefined)
|
|
119189
|
-
return darwinBinding;
|
|
119190
|
-
try {
|
|
119191
|
-
darwinBinding = bindDarwin();
|
|
119192
|
-
} catch {
|
|
119193
|
-
darwinBinding = null;
|
|
119194
|
-
}
|
|
119195
|
-
return darwinBinding;
|
|
119196
|
-
}
|
|
119197
|
-
function argvOfProcargs(buf) {
|
|
119198
|
-
return procargsLayout(buf)?.argv ?? null;
|
|
119199
|
-
}
|
|
119200
|
-
function procargsLayout(buf) {
|
|
119201
|
-
if (buf.length < 4)
|
|
119202
|
-
return null;
|
|
119203
|
-
const argc = buf.readInt32LE(0);
|
|
119204
|
-
if (argc < 1)
|
|
119205
|
-
return null;
|
|
119206
|
-
const pathEnd = buf.indexOf(0, 4);
|
|
119207
|
-
if (pathEnd < 0)
|
|
119208
|
-
return null;
|
|
119209
|
-
let i = 4 + Math.ceil((pathEnd - 4 + 1) / EXEC_PATH_ALIGN) * EXEC_PATH_ALIGN;
|
|
119210
|
-
if (i >= buf.length || buf[i] === 0)
|
|
119211
|
-
return null;
|
|
119212
|
-
for (let pad = pathEnd;pad < i; pad++)
|
|
119213
|
-
if (buf[pad] !== 0)
|
|
119214
|
-
return null;
|
|
119215
|
-
const argv = [];
|
|
119216
|
-
for (let k = 0;k < argc; k++) {
|
|
119217
|
-
const end = buf.indexOf(0, i);
|
|
119218
|
-
if (end < 0)
|
|
119219
|
-
return null;
|
|
119220
|
-
argv.push(buf.toString("utf8", i, end));
|
|
119221
|
-
i = end + 1;
|
|
119222
|
-
}
|
|
119223
|
-
return { argv, end: i };
|
|
119224
|
-
}
|
|
119225
|
-
function hostEnvOf(entries) {
|
|
119226
|
-
const env = {};
|
|
119227
|
-
for (const key of HOST_ENV_KEYS) {
|
|
119228
|
-
const prefix = Buffer.from(`${key}=`);
|
|
119229
|
-
const entry = entries.find((e) => e.subarray(0, prefix.length).equals(prefix));
|
|
119230
|
-
if (entry === undefined)
|
|
119231
|
-
continue;
|
|
119232
|
-
const raw = entry.subarray(prefix.length);
|
|
119233
|
-
const value = raw.toString("utf8");
|
|
119234
|
-
if (!Buffer.from(value, "utf8").equals(raw))
|
|
119235
|
-
return null;
|
|
119236
|
-
env[key] = value;
|
|
119237
|
-
}
|
|
119238
|
-
return env;
|
|
119239
|
-
}
|
|
119240
|
-
function hostEnvOfProcargs(buf) {
|
|
119241
|
-
const layout = procargsLayout(buf);
|
|
119242
|
-
if (!layout)
|
|
119243
|
-
return null;
|
|
119244
|
-
const entries = [];
|
|
119245
|
-
for (let i = layout.end;; ) {
|
|
119246
|
-
const end = buf.indexOf(0, i);
|
|
119247
|
-
if (end < 0)
|
|
119248
|
-
return null;
|
|
119249
|
-
if (end === i)
|
|
119250
|
-
break;
|
|
119251
|
-
entries.push(buf.subarray(i, end));
|
|
119252
|
-
i = end + 1;
|
|
119253
|
-
}
|
|
119254
|
-
return hostEnvOf(entries);
|
|
119255
|
-
}
|
|
119256
|
-
function hostEnvOfEnviron(raw) {
|
|
119257
|
-
if (raw.length === 0 || raw[raw.length - 1] !== 0)
|
|
119258
|
-
return null;
|
|
119259
|
-
const entries = [];
|
|
119260
|
-
for (let i = 0;i < raw.length; ) {
|
|
119261
|
-
const end = raw.indexOf(0, i);
|
|
119262
|
-
entries.push(raw.subarray(i, end));
|
|
119263
|
-
i = end + 1;
|
|
119264
|
-
}
|
|
119265
|
-
return hostEnvOf(entries);
|
|
119266
|
-
}
|
|
119267
|
-
function readDarwin(pid) {
|
|
119268
|
-
const binding = darwin();
|
|
119269
|
-
if (!binding)
|
|
119270
|
-
return null;
|
|
119271
|
-
const size = binding.argmax();
|
|
119272
|
-
if (size === null || size <= 0)
|
|
119273
|
-
return null;
|
|
119274
|
-
const raw = binding.procargs(pid, size);
|
|
119275
|
-
const argv = raw ? argvOfProcargs(raw) : null;
|
|
119276
|
-
const cwd = binding.cwd(pid);
|
|
119277
|
-
if (!raw || !argv || !cwd)
|
|
119278
|
-
return null;
|
|
119279
|
-
return { argv, cwd, env: hostEnvOfProcargs(raw) };
|
|
119280
|
-
}
|
|
119281
|
-
function argvOfCmdline(raw) {
|
|
119282
|
-
if (raw.length === 0 || raw[raw.length - 1] !== 0)
|
|
119283
|
-
return null;
|
|
119284
|
-
const argv = raw.toString("utf8", 0, raw.length - 1).split("\x00");
|
|
119285
|
-
if (argv.length > 1 && argv.slice(1).every((arg) => arg === ""))
|
|
119286
|
-
return null;
|
|
119287
|
-
return argv;
|
|
119288
|
-
}
|
|
119289
|
-
function readLinux(pid) {
|
|
119290
|
-
try {
|
|
119291
|
-
const argv = argvOfCmdline(readFileSync45(`/proc/${pid}/cmdline`));
|
|
119292
|
-
if (!argv)
|
|
119293
|
-
return null;
|
|
119294
|
-
const cwd = readlinkSync(`/proc/${pid}/cwd`);
|
|
119295
|
-
let env;
|
|
119296
|
-
try {
|
|
119297
|
-
env = hostEnvOfEnviron(readFileSync45(`/proc/${pid}/environ`));
|
|
119298
|
-
} catch {
|
|
119299
|
-
env = null;
|
|
119300
|
-
}
|
|
119301
|
-
return { argv, cwd, env };
|
|
119302
|
-
} catch {
|
|
119303
|
-
return null;
|
|
119304
|
-
}
|
|
119305
|
-
}
|
|
119306
|
-
var HOST_ENV_KEYS, CTL_KERN = 1, KERN_ARGMAX = 8, KERN_PROCARGS2 = 49, PROC_PIDVNODEPATHINFO = 9, VNODE_INFO_BYTES = 152, MAXPATHLEN = 1024, VNODEPATHINFO_BYTES, darwinBinding, EXEC_PATH_ALIGN = 8, PID_MAX, readHostLaunch = (pid) => {
|
|
119307
|
-
if (!Number.isInteger(pid) || pid <= 1 || pid > PID_MAX)
|
|
119308
|
-
return null;
|
|
119309
|
-
try {
|
|
119310
|
-
if (process.platform === "darwin")
|
|
119311
|
-
return readDarwin(pid);
|
|
119312
|
-
if (process.platform === "linux")
|
|
119313
|
-
return readLinux(pid);
|
|
119314
|
-
} catch {}
|
|
119315
|
-
return null;
|
|
119316
|
-
};
|
|
119317
|
-
var init_host_launch = __esm(() => {
|
|
119318
|
-
init_probe_launch_vars();
|
|
119319
|
-
HOST_ENV_KEYS = HOST_READ_ENV_KEYS;
|
|
119320
|
-
VNODEPATHINFO_BYTES = 2 * (VNODE_INFO_BYTES + MAXPATHLEN);
|
|
119321
|
-
PID_MAX = 2 ** 31 - 1;
|
|
119322
|
-
});
|
|
119323
|
-
|
|
119324
119119
|
// src/mcp-session/inherited-settings.ts
|
|
119325
119120
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
119326
119121
|
import {
|
|
119327
119122
|
chmodSync as chmodSync7,
|
|
119328
119123
|
closeSync as closeSync16,
|
|
119329
119124
|
existsSync as existsSync40,
|
|
119330
|
-
lstatSync as lstatSync9,
|
|
119331
119125
|
openSync as openSync16,
|
|
119332
|
-
readFileSync as
|
|
119126
|
+
readFileSync as readFileSync45,
|
|
119333
119127
|
readSync as readSync7,
|
|
119334
119128
|
readdirSync as readdirSync12,
|
|
119335
119129
|
realpathSync as realpathSync8,
|
|
@@ -119417,7 +119211,7 @@ function readSettingsValue(value) {
|
|
|
119417
119211
|
}
|
|
119418
119212
|
let text;
|
|
119419
119213
|
try {
|
|
119420
|
-
text =
|
|
119214
|
+
text = readFileSync45(value, "utf-8");
|
|
119421
119215
|
} catch (err) {
|
|
119422
119216
|
throw new Error(`invalid_args: settings ${value} cannot be read (${err.message})`);
|
|
119423
119217
|
}
|
|
@@ -119454,9 +119248,6 @@ function settingsFilesFor(setupReal, sources) {
|
|
|
119454
119248
|
...loads("local") ? localSettingsFiles(setupReal, readText, regularPathKind).map(([file]) => file) : []
|
|
119455
119249
|
];
|
|
119456
119250
|
}
|
|
119457
|
-
function launchSettingsFiles(dir) {
|
|
119458
|
-
return settingsFilesFor(realOrResolved(dir), null);
|
|
119459
|
-
}
|
|
119460
119251
|
function launchSettingsFilesByTier(dir, sources) {
|
|
119461
119252
|
const real = realOrResolved(dir);
|
|
119462
119253
|
const loads = (source) => sources === null || sources.has(source);
|
|
@@ -119466,7 +119257,7 @@ function launchSettingsFilesByTier(dir, sources) {
|
|
|
119466
119257
|
};
|
|
119467
119258
|
}
|
|
119468
119259
|
function readText(path) {
|
|
119469
|
-
return
|
|
119260
|
+
return readFileSync45(path, "utf-8");
|
|
119470
119261
|
}
|
|
119471
119262
|
function realOrResolved(path) {
|
|
119472
119263
|
const missing = [];
|
|
@@ -119643,11 +119434,6 @@ function remoteSettingsPath(managed, env, cwd) {
|
|
|
119643
119434
|
}
|
|
119644
119435
|
return managed.remoteSettingsFile;
|
|
119645
119436
|
}
|
|
119646
|
-
function hybridSettingsDirOf(managed, env, cwd) {
|
|
119647
|
-
if (managed.hybridSettingsDir === null)
|
|
119648
|
-
return join58(claudeCodeConfigDir(env, cwd), "state");
|
|
119649
|
-
return managed.hybridSettingsDir;
|
|
119650
|
-
}
|
|
119651
119437
|
function readManagedPolicy(managed, env, cwd) {
|
|
119652
119438
|
const objects = [];
|
|
119653
119439
|
const oversize = [];
|
|
@@ -119675,57 +119461,6 @@ function readManagedPolicy(managed, env, cwd) {
|
|
|
119675
119461
|
}
|
|
119676
119462
|
return { objects, oversize };
|
|
119677
119463
|
}
|
|
119678
|
-
function pathPresent(path) {
|
|
119679
|
-
try {
|
|
119680
|
-
lstatSync9(path);
|
|
119681
|
-
return true;
|
|
119682
|
-
} catch (err) {
|
|
119683
|
-
const code = err.code;
|
|
119684
|
-
return code !== "ENOENT" && code !== "ENOTDIR";
|
|
119685
|
-
}
|
|
119686
|
-
}
|
|
119687
|
-
function presentEntries(dir, keep) {
|
|
119688
|
-
if (!pathPresent(dir))
|
|
119689
|
-
return [];
|
|
119690
|
-
try {
|
|
119691
|
-
return readdirSync12(dir).filter(keep).sort().map((name) => join58(dir, name));
|
|
119692
|
-
} catch {
|
|
119693
|
-
return [dir];
|
|
119694
|
-
}
|
|
119695
|
-
}
|
|
119696
|
-
function remoteSettingsSetsNothing(path) {
|
|
119697
|
-
try {
|
|
119698
|
-
const stat = lstatSync9(path);
|
|
119699
|
-
if (!stat.isFile() || stat.size > REMOTE_SETTINGS_MAX_BYTES)
|
|
119700
|
-
return false;
|
|
119701
|
-
const parsed = JSON.parse(readText(path));
|
|
119702
|
-
return isPlainObject7(parsed) && Object.keys(parsed).every((key) => key.startsWith("$"));
|
|
119703
|
-
} catch {
|
|
119704
|
-
return false;
|
|
119705
|
-
}
|
|
119706
|
-
}
|
|
119707
|
-
function managedPolicySourcePresent(managed, env, cwd) {
|
|
119708
|
-
const remote = remoteSettingsPath(managed, env, cwd);
|
|
119709
|
-
if (remote !== undefined && pathPresent(remote) && !remoteSettingsSetsNothing(remote)) {
|
|
119710
|
-
return remote;
|
|
119711
|
-
}
|
|
119712
|
-
const files = [...managed.managedPreferencePlists ?? [], managed.managedSettingsFile];
|
|
119713
|
-
for (const path of files)
|
|
119714
|
-
if (path !== undefined && pathPresent(path))
|
|
119715
|
-
return path;
|
|
119716
|
-
const dropInDir = managed.managedSettingsDropInDir;
|
|
119717
|
-
const dropIn = dropInDir ? presentEntries(dropInDir, () => true)[0] : undefined;
|
|
119718
|
-
if (dropIn !== undefined)
|
|
119719
|
-
return dropIn;
|
|
119720
|
-
if (managed.managedMcpFile !== undefined && pathPresent(managed.managedMcpFile)) {
|
|
119721
|
-
return managed.managedMcpFile;
|
|
119722
|
-
}
|
|
119723
|
-
const hybridDir = hybridSettingsDirOf(managed, env, cwd);
|
|
119724
|
-
const hybrid = hybridDir ? presentEntries(hybridDir, (n) => n.startsWith("hybrid-settings") && n.endsWith(".json"))[0] : undefined;
|
|
119725
|
-
if (hybrid !== undefined)
|
|
119726
|
-
return hybrid;
|
|
119727
|
-
return managed.registryPolicyKeys?.[0];
|
|
119728
|
-
}
|
|
119729
119464
|
function sideloadFlagsDisabledBy(policy) {
|
|
119730
119465
|
return policy.objects.find(({ value }) => value.disableSideloadFlags === true)?.path;
|
|
119731
119466
|
}
|
|
@@ -119751,16 +119486,21 @@ function registryPolicyState(answer) {
|
|
|
119751
119486
|
return "absent";
|
|
119752
119487
|
return "unknown";
|
|
119753
119488
|
}
|
|
119754
|
-
function
|
|
119489
|
+
function unreadRegistryPolicy(managed) {
|
|
119755
119490
|
const read = managed.readRegistry ?? regQuery;
|
|
119756
119491
|
for (const key of managed.registryPolicyKeys ?? []) {
|
|
119757
119492
|
const state = registryPolicyState(read(key));
|
|
119758
|
-
if (state
|
|
119759
|
-
|
|
119760
|
-
log(state === "present" ? `[mcp-session] no MCP server handed over: the policy key ${key} holds a Settings value, which claudish does not read` : `[mcp-session] no MCP server handed over: the policy key ${key} could not be queried, so claudish cannot tell whether it is present`);
|
|
119761
|
-
return true;
|
|
119493
|
+
if (state !== "absent")
|
|
119494
|
+
return { key, state };
|
|
119762
119495
|
}
|
|
119763
|
-
return
|
|
119496
|
+
return;
|
|
119497
|
+
}
|
|
119498
|
+
function registryPolicyBlocksMcpConfig(managed) {
|
|
119499
|
+
const unread = unreadRegistryPolicy(managed);
|
|
119500
|
+
if (unread === undefined)
|
|
119501
|
+
return false;
|
|
119502
|
+
log(unread.state === "present" ? `[mcp-session] no MCP server handed over: the policy key ${unread.key} holds a Settings value, which claudish does not read` : `[mcp-session] no MCP server handed over: the policy key ${unread.key} could not be queried, so claudish cannot tell whether it is present`);
|
|
119503
|
+
return true;
|
|
119764
119504
|
}
|
|
119765
119505
|
function comparableServerName(name) {
|
|
119766
119506
|
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
@@ -119797,7 +119537,6 @@ function realManagedPaths(platform = process.platform) {
|
|
|
119797
119537
|
managedMcpFile: join58(dir, "managed-mcp.json"),
|
|
119798
119538
|
managedPreferencePlists: platform === "darwin" ? managedPreferencePlistsFor(currentUsername()) : [],
|
|
119799
119539
|
remoteSettingsFile: null,
|
|
119800
|
-
hybridSettingsDir: null,
|
|
119801
119540
|
registryPolicyKeys: platform === "win32" ? [...WINDOWS_POLICY_KEYS] : []
|
|
119802
119541
|
};
|
|
119803
119542
|
}
|
|
@@ -119991,977 +119730,499 @@ var init_parent_session = __esm(() => {
|
|
|
119991
119730
|
CLAUDE_ID_RE = /^[A-Za-z0-9_-]{8,128}$/;
|
|
119992
119731
|
});
|
|
119993
119732
|
|
|
119994
|
-
// src/mcp-session/
|
|
119995
|
-
import {
|
|
119996
|
-
|
|
119997
|
-
constants as constants5,
|
|
119998
|
-
closeSync as closeSync17,
|
|
119999
|
-
fstatSync as fstatSync5,
|
|
120000
|
-
lstatSync as lstatSync10,
|
|
120001
|
-
mkdtempSync as mkdtempSync4,
|
|
120002
|
-
openSync as openSync17,
|
|
120003
|
-
readFileSync as readFileSync47,
|
|
120004
|
-
readdirSync as readdirSync13,
|
|
120005
|
-
rmSync as rmSync15,
|
|
120006
|
-
statSync as statSync24
|
|
120007
|
-
} from "fs";
|
|
120008
|
-
import { tmpdir as tmpdir3 } from "os";
|
|
120009
|
-
import { basename as basename9, isAbsolute as isAbsolute5, join as join60, resolve as resolve9 } from "path";
|
|
120010
|
-
function passes(flags, flag) {
|
|
120011
|
-
return flags.some((t) => t === flag || t.startsWith(`${flag}=`));
|
|
120012
|
-
}
|
|
120013
|
-
function passesBeforeEnd(flags, flag) {
|
|
120014
|
-
const at = flags.indexOf(flag);
|
|
120015
|
-
const end = flags.indexOf("--");
|
|
120016
|
-
return at !== -1 && (end === -1 || at < end);
|
|
120017
|
-
}
|
|
120018
|
-
function pluginLoadingFlags(flags, base) {
|
|
120019
|
-
const out = [];
|
|
120020
|
-
const push = (flag, value) => out.push(flag, PLUGIN_PATH_FLAGS.includes(flag) ? resolve9(base, value) : value);
|
|
120021
|
-
const takesValue = (flag) => PLUGIN_PATH_FLAGS.includes(flag) || PLUGIN_VALUE_FLAGS.includes(flag);
|
|
120022
|
-
for (let i = 0;i < flags.length; i++) {
|
|
120023
|
-
const token = flags[i];
|
|
120024
|
-
if (PLUGIN_BOOLEAN_FLAGS.includes(token)) {
|
|
120025
|
-
out.push(token);
|
|
120026
|
-
continue;
|
|
120027
|
-
}
|
|
120028
|
-
if (takesValue(token)) {
|
|
120029
|
-
const value = flags[i + 1];
|
|
120030
|
-
if (value !== undefined)
|
|
120031
|
-
push(token, value);
|
|
120032
|
-
i++;
|
|
120033
|
-
continue;
|
|
120034
|
-
}
|
|
120035
|
-
const eq = token.indexOf("=");
|
|
120036
|
-
const flag = eq > 0 ? token.slice(0, eq) : "";
|
|
120037
|
-
if (takesValue(flag))
|
|
120038
|
-
push(flag, token.slice(eq + 1));
|
|
120039
|
-
}
|
|
120040
|
-
return out;
|
|
120041
|
-
}
|
|
120042
|
-
function pluginProbeArgs(settingsFile, launchFlags, base) {
|
|
120043
|
-
const quiet = QUIET_FLAGS.map((flag) => flag === "<settings file>" ? settingsFile : flag);
|
|
120044
|
-
return [...quiet, ...pluginLoadingFlags(launchFlags, base), "-p", "/effort"];
|
|
120045
|
-
}
|
|
120046
|
-
function isProbeParentVar(key) {
|
|
120047
|
-
return PROBE_PARENT_VARS.includes(key) || /^LC_[A-Z]+$/.test(key);
|
|
120048
|
-
}
|
|
120049
|
-
function pluginProbeEnv(parentEnv) {
|
|
120050
|
-
const env = {};
|
|
120051
|
-
for (const [key, value] of Object.entries(parentEnv)) {
|
|
120052
|
-
if (value !== undefined && isProbeParentVar(key))
|
|
120053
|
-
env[key] = value;
|
|
120054
|
-
}
|
|
120055
|
-
env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
|
|
120056
|
-
env[PROBE_HOST_MANAGED_MARKER] = "1";
|
|
120057
|
-
env.ANTHROPIC_BASE_URL = PLUGIN_PROBE_BASE_URL;
|
|
120058
|
-
return env;
|
|
120059
|
-
}
|
|
120060
|
-
function isPlainObject8(value) {
|
|
120061
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
120062
|
-
}
|
|
120063
|
-
function pluginProbeSettings(layer) {
|
|
120064
|
-
const base = structuredClone(layer ?? {});
|
|
120065
|
-
for (const key of ["hooks", ...COMMAND_SETTINGS])
|
|
120066
|
-
delete base[key];
|
|
120067
|
-
if (isPlainObject8(base.env)) {
|
|
120068
|
-
const closed = new Set(Object.keys(PROBE_SETTINGS_ENV));
|
|
120069
|
-
base.env = Object.fromEntries(Object.entries(base.env).filter(([key]) => !closed.has(key.toUpperCase())));
|
|
120070
|
-
} else {
|
|
120071
|
-
delete base.env;
|
|
120072
|
-
}
|
|
120073
|
-
return mergeSettingsLayers(base, { disableAllHooks: true, env: { ...PROBE_SETTINGS_ENV } });
|
|
120074
|
-
}
|
|
120075
|
-
function readRegularFile(path) {
|
|
119733
|
+
// src/mcp-session/bounded-read.ts
|
|
119734
|
+
import { constants as constants5, closeSync as closeSync17, fstatSync as fstatSync5, openSync as openSync17, readSync as readSync8 } from "fs";
|
|
119735
|
+
function readBoundedText(path, maxBytes) {
|
|
120076
119736
|
let fd;
|
|
120077
119737
|
try {
|
|
120078
119738
|
fd = openSync17(path, constants5.O_RDONLY | constants5.O_NONBLOCK);
|
|
119739
|
+
const stat = fstatSync5(fd);
|
|
119740
|
+
if (!stat.isFile())
|
|
119741
|
+
return "not_file";
|
|
119742
|
+
if (stat.size > maxBytes)
|
|
119743
|
+
return "oversize";
|
|
119744
|
+
const parts = [];
|
|
119745
|
+
let total = 0;
|
|
119746
|
+
for (;; ) {
|
|
119747
|
+
const room = Math.min(CHUNK, maxBytes + 1 - total);
|
|
119748
|
+
const chunk = Buffer.allocUnsafe(room);
|
|
119749
|
+
const n = readSync8(fd, chunk, 0, room, null);
|
|
119750
|
+
if (n === 0)
|
|
119751
|
+
break;
|
|
119752
|
+
total += n;
|
|
119753
|
+
if (total > maxBytes)
|
|
119754
|
+
return "oversize";
|
|
119755
|
+
parts.push(chunk.subarray(0, n));
|
|
119756
|
+
}
|
|
119757
|
+
return { text: Buffer.concat(parts, total).toString("utf-8"), mode: stat.mode & 511 };
|
|
120079
119758
|
} catch (err) {
|
|
120080
|
-
const code = err
|
|
120081
|
-
return code === "ENOENT" || code === "ENOTDIR" ?
|
|
120082
|
-
}
|
|
120083
|
-
try {
|
|
120084
|
-
if (!fstatSync5(fd).isFile())
|
|
120085
|
-
return "unreadable";
|
|
120086
|
-
return readFileSync47(fd, "utf-8");
|
|
120087
|
-
} catch {
|
|
120088
|
-
return "unreadable";
|
|
119759
|
+
const code = err?.code;
|
|
119760
|
+
return code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable";
|
|
120089
119761
|
} finally {
|
|
120090
|
-
|
|
120091
|
-
|
|
120092
|
-
|
|
120093
|
-
|
|
120094
|
-
for (const path of paths) {
|
|
120095
|
-
const text = readRegularFile(path);
|
|
120096
|
-
if (text === null)
|
|
120097
|
-
continue;
|
|
120098
|
-
if (text === "unreadable")
|
|
120099
|
-
return { path };
|
|
120100
|
-
let parsed;
|
|
120101
|
-
try {
|
|
120102
|
-
parsed = JSON.parse(text);
|
|
120103
|
-
} catch {
|
|
120104
|
-
return { path };
|
|
120105
|
-
}
|
|
120106
|
-
if (!isPlainObject8(parsed))
|
|
120107
|
-
return { path };
|
|
120108
|
-
const key = keys.find((k) => parsed[k] !== undefined && parsed[k] !== null);
|
|
120109
|
-
if (key !== undefined)
|
|
120110
|
-
return { path, key };
|
|
120111
|
-
}
|
|
120112
|
-
return;
|
|
120113
|
-
}
|
|
120114
|
-
function initPluginsOf(event) {
|
|
120115
|
-
const list = isPlainObject8(event) ? event.plugins : undefined;
|
|
120116
|
-
if (!Array.isArray(list))
|
|
120117
|
-
return null;
|
|
120118
|
-
const plugins = [];
|
|
120119
|
-
for (const item of list) {
|
|
120120
|
-
if (!isPlainObject8(item))
|
|
120121
|
-
return null;
|
|
120122
|
-
const { name, path, source, version } = item;
|
|
120123
|
-
if (typeof name !== "string" || typeof path !== "string" || typeof source !== "string") {
|
|
120124
|
-
return null;
|
|
120125
|
-
}
|
|
120126
|
-
if (version !== undefined && typeof version !== "string")
|
|
120127
|
-
return null;
|
|
120128
|
-
plugins.push({ name, path, source, ...version !== undefined ? { version } : {} });
|
|
120129
|
-
}
|
|
120130
|
-
return plugins;
|
|
120131
|
-
}
|
|
120132
|
-
function manifestNames(path, name) {
|
|
120133
|
-
const manifest = join60(path, ".claude-plugin", "plugin.json");
|
|
120134
|
-
try {
|
|
120135
|
-
if (!statSync24(manifest).isFile())
|
|
120136
|
-
return false;
|
|
120137
|
-
const parsed = JSON.parse(readFileSync47(manifest, "utf-8"));
|
|
120138
|
-
return isPlainObject8(parsed) && parsed.name === name;
|
|
120139
|
-
} catch {
|
|
120140
|
-
return false;
|
|
120141
|
-
}
|
|
120142
|
-
}
|
|
120143
|
-
function pluginsToHandOver(caller, child) {
|
|
120144
|
-
const childPaths = new Map(child.map((p) => [p.source, p.path]));
|
|
120145
|
-
const childInline = new Set(child.filter((p) => p.source.endsWith("@inline")).map((p) => p.name));
|
|
120146
|
-
const seen = new Set;
|
|
120147
|
-
const plugins = [];
|
|
120148
|
-
for (const p of caller) {
|
|
120149
|
-
if (p.source.endsWith("@inline") || !isAbsolute5(p.path))
|
|
120150
|
-
continue;
|
|
120151
|
-
if (childPaths.get(p.source) === p.path || seen.has(p.path))
|
|
120152
|
-
continue;
|
|
120153
|
-
if (childInline.has(p.name)) {
|
|
120154
|
-
log(`[mcp-session] plugin ${p.source} not handed over: the child loads ${p.name} from its own --plugin-dir`);
|
|
120155
|
-
continue;
|
|
120156
|
-
}
|
|
120157
|
-
if (!manifestNames(p.path, p.name)) {
|
|
120158
|
-
log(`[mcp-session] plugin ${p.source} not handed over: its copy has no .claude-plugin/plugin.json naming it ${p.name}`);
|
|
120159
|
-
continue;
|
|
119762
|
+
if (fd !== undefined) {
|
|
119763
|
+
try {
|
|
119764
|
+
closeSync17(fd);
|
|
119765
|
+
} catch {}
|
|
120160
119766
|
}
|
|
120161
|
-
seen.add(p.path);
|
|
120162
|
-
plugins.push({ id: p.source, version: p.version, path: p.path });
|
|
120163
119767
|
}
|
|
120164
|
-
return plugins;
|
|
120165
119768
|
}
|
|
120166
|
-
function
|
|
120167
|
-
const
|
|
120168
|
-
|
|
120169
|
-
|
|
120170
|
-
return true;
|
|
120171
|
-
log(`[mcp-session] plugin ${p.id} not handed over: the child's settings turn it off`);
|
|
120172
|
-
return false;
|
|
120173
|
-
});
|
|
120174
|
-
}
|
|
120175
|
-
function probeLineEvent(line, afterInit) {
|
|
120176
|
-
let event;
|
|
119769
|
+
function readBoundedJson(path, maxBytes) {
|
|
119770
|
+
const read = readBoundedText(path, maxBytes);
|
|
119771
|
+
if (typeof read === "string")
|
|
119772
|
+
return read;
|
|
120177
119773
|
try {
|
|
120178
|
-
|
|
119774
|
+
return { value: JSON.parse(read.text) };
|
|
120179
119775
|
} catch {
|
|
120180
|
-
return
|
|
120181
|
-
}
|
|
120182
|
-
if (!isPlainObject8(event))
|
|
120183
|
-
return null;
|
|
120184
|
-
if (event.type === "assistant") {
|
|
120185
|
-
if (!afterInit)
|
|
120186
|
-
return { kind: "fail", cause: "assistant_before_init" };
|
|
120187
|
-
const model = isPlainObject8(event.message) ? event.message.model : undefined;
|
|
120188
|
-
return model === "<synthetic>" ? null : { kind: "fail", cause: "turns" };
|
|
120189
|
-
}
|
|
120190
|
-
if (event.type === "result") {
|
|
120191
|
-
const success = event.subtype === "success" && event.is_error === false;
|
|
120192
|
-
return { kind: "result", success, turns: event.num_turns };
|
|
120193
|
-
}
|
|
120194
|
-
if (event.type !== "system" || event.subtype !== "init" || afterInit)
|
|
120195
|
-
return null;
|
|
120196
|
-
const plugins = initPluginsOf(event);
|
|
120197
|
-
return plugins ? { kind: "init", plugins } : { kind: "fail", cause: "plugins_malformed" };
|
|
120198
|
-
}
|
|
120199
|
-
function groupAlive(pgid) {
|
|
120200
|
-
try {
|
|
120201
|
-
process.kill(-pgid, 0);
|
|
120202
|
-
return true;
|
|
120203
|
-
} catch (err) {
|
|
120204
|
-
return err.code === "EPERM";
|
|
119776
|
+
return "unreadable";
|
|
120205
119777
|
}
|
|
120206
119778
|
}
|
|
120207
|
-
|
|
120208
|
-
|
|
120209
|
-
|
|
120210
|
-
|
|
120211
|
-
|
|
120212
|
-
|
|
120213
|
-
|
|
120214
|
-
|
|
120215
|
-
|
|
119779
|
+
var CHUNK;
|
|
119780
|
+
var init_bounded_read = __esm(() => {
|
|
119781
|
+
CHUNK = 64 * 1024;
|
|
119782
|
+
});
|
|
119783
|
+
|
|
119784
|
+
// src/mcp-session/plugin-handover.ts
|
|
119785
|
+
import { readFileSync as readFileSync46 } from "fs";
|
|
119786
|
+
import { homedir as homedir41 } from "os";
|
|
119787
|
+
import { basename as basename9, delimiter as delimiter3, join as join60, resolve as resolve9 } from "path";
|
|
119788
|
+
function isPlainObject8(value) {
|
|
119789
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
120216
119790
|
}
|
|
120217
|
-
|
|
120218
|
-
const
|
|
120219
|
-
|
|
120220
|
-
|
|
120221
|
-
|
|
120222
|
-
|
|
120223
|
-
|
|
120224
|
-
|
|
120225
|
-
|
|
120226
|
-
|
|
120227
|
-
|
|
120228
|
-
const found = Promise.resolve().then(() => findBinary(env, stop.signal)).catch(() => null);
|
|
120229
|
-
binary = await Promise.race([found, outlived]);
|
|
120230
|
-
} finally {
|
|
120231
|
-
clearTimeout(timer);
|
|
120232
|
-
clearTimeout(hardTimer);
|
|
120233
|
-
signal?.removeEventListener("abort", onAbort);
|
|
120234
|
-
}
|
|
120235
|
-
if (binary === "outlived") {
|
|
120236
|
-
stop.abort();
|
|
120237
|
-
log("[mcp-session] the plugin probe's binary lookup outlived the probe's deadline after it was stopped; the probe answers without it");
|
|
120238
|
-
}
|
|
120239
|
-
if (signal?.aborted)
|
|
120240
|
-
return "aborted";
|
|
120241
|
-
if (stop.signal.aborted)
|
|
120242
|
-
return "timeout";
|
|
120243
|
-
return binary === "outlived" ? "timeout" : binary;
|
|
120244
|
-
}
|
|
120245
|
-
function pluginProbeRunner(findBinary, serverDir = () => process.cwd()) {
|
|
120246
|
-
return async (request) => {
|
|
120247
|
-
const { signal } = request;
|
|
120248
|
-
const deadline = Date.now() + request.timeoutMs;
|
|
120249
|
-
const killAt = deadline - Math.min(PROBE_REAP_MS, Math.floor(request.timeoutMs / 4));
|
|
120250
|
-
if (signal?.aborted)
|
|
120251
|
-
return { ok: false, cause: "aborted" };
|
|
120252
|
-
const base = serverDir();
|
|
120253
|
-
const named = request.env.CLAUDE_PATH;
|
|
120254
|
-
const claudePath = named ? startablePath(base, named) : undefined;
|
|
120255
|
-
if (claudePath === null)
|
|
120256
|
-
return { ok: false, cause: "no_claude_binary" };
|
|
120257
|
-
const env = claudePath ? { ...request.env, CLAUDE_PATH: claudePath } : request.env;
|
|
120258
|
-
const binary = await lookupBinary(findBinary, env, killAt - Date.now(), deadline - Date.now(), signal);
|
|
120259
|
-
if (binary === "timeout" || binary === "aborted")
|
|
120260
|
-
return { ok: false, cause: binary };
|
|
120261
|
-
const path = binary ? startablePath(base, binary) : null;
|
|
120262
|
-
if (path === null)
|
|
120263
|
-
return { ok: false, cause: "no_claude_binary" };
|
|
120264
|
-
return runProbe(path, request, deadline, killAt);
|
|
120265
|
-
};
|
|
120266
|
-
}
|
|
120267
|
-
function startablePath(base, named) {
|
|
120268
|
-
return isAbsolute5(named) ? named : claudePathIn(base, named);
|
|
120269
|
-
}
|
|
120270
|
-
function runProbe(binary, request, deadline, killAt) {
|
|
120271
|
-
const { signal } = request;
|
|
120272
|
-
return new Promise((settle) => {
|
|
120273
|
-
let child;
|
|
120274
|
-
try {
|
|
120275
|
-
child = spawn4(binary, request.args, {
|
|
120276
|
-
cwd: request.cwd,
|
|
120277
|
-
env: request.env,
|
|
120278
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
120279
|
-
detached: true
|
|
120280
|
-
});
|
|
120281
|
-
} catch {
|
|
120282
|
-
settle({ ok: false, cause: "spawn_failed" });
|
|
120283
|
-
return;
|
|
119791
|
+
function flagValues(flags, flag) {
|
|
119792
|
+
const values = [];
|
|
119793
|
+
for (let i = 0;i < flags.length; i++) {
|
|
119794
|
+
const token = flags[i];
|
|
119795
|
+
if (token === flag) {
|
|
119796
|
+
const value = flags[i + 1];
|
|
119797
|
+
if (value !== undefined)
|
|
119798
|
+
values.push(value);
|
|
119799
|
+
i++;
|
|
119800
|
+
} else if (token.startsWith(`${flag}=`)) {
|
|
119801
|
+
values.push(token.slice(flag.length + 1));
|
|
120284
119802
|
}
|
|
120285
|
-
const pgid = child.pid;
|
|
120286
|
-
let plugins = null;
|
|
120287
|
-
let turns = null;
|
|
120288
|
-
let failure = null;
|
|
120289
|
-
let exitCode = null;
|
|
120290
|
-
let exited = false;
|
|
120291
|
-
let stdoutDone = false;
|
|
120292
|
-
let pending = "";
|
|
120293
|
-
let bytes = 0;
|
|
120294
|
-
let settled = false;
|
|
120295
|
-
let poll;
|
|
120296
|
-
const verdict = () => {
|
|
120297
|
-
if (failure)
|
|
120298
|
-
return { ok: false, cause: failure };
|
|
120299
|
-
if (!plugins)
|
|
120300
|
-
return { ok: false, cause: "exited_before_init" };
|
|
120301
|
-
if (exitCode !== 0)
|
|
120302
|
-
return { ok: false, cause: "nonzero_exit" };
|
|
120303
|
-
if (!turns)
|
|
120304
|
-
return { ok: false, cause: "no_result" };
|
|
120305
|
-
if (turns.value !== 0)
|
|
120306
|
-
return { ok: false, cause: "turns" };
|
|
120307
|
-
return { ok: true, plugins };
|
|
120308
|
-
};
|
|
120309
|
-
const finish = () => {
|
|
120310
|
-
if (settled)
|
|
120311
|
-
return;
|
|
120312
|
-
settled = true;
|
|
120313
|
-
clearTimeout(killTimer);
|
|
120314
|
-
clearTimeout(deadlineTimer);
|
|
120315
|
-
clearInterval(poll);
|
|
120316
|
-
signal?.removeEventListener("abort", onAbort);
|
|
120317
|
-
child.stdout?.destroy();
|
|
120318
|
-
settle(verdict());
|
|
120319
|
-
};
|
|
120320
|
-
const settleWhenGone = () => {
|
|
120321
|
-
if (settled || !exited || !stdoutDone)
|
|
120322
|
-
return;
|
|
120323
|
-
if (pgid === undefined || !groupAlive(pgid))
|
|
120324
|
-
return finish();
|
|
120325
|
-
if (!poll) {
|
|
120326
|
-
poll = setInterval(() => {
|
|
120327
|
-
if (pgid === undefined || !groupAlive(pgid))
|
|
120328
|
-
finish();
|
|
120329
|
-
}, GROUP_POLL_MS);
|
|
120330
|
-
}
|
|
120331
|
-
};
|
|
120332
|
-
const fail = (cause) => {
|
|
120333
|
-
failure ??= cause;
|
|
120334
|
-
killProbe(child);
|
|
120335
|
-
stdoutDone = true;
|
|
120336
|
-
settleWhenGone();
|
|
120337
|
-
};
|
|
120338
|
-
const readLine = (line) => {
|
|
120339
|
-
const event = probeLineEvent(line, plugins !== null);
|
|
120340
|
-
if (!event)
|
|
120341
|
-
return;
|
|
120342
|
-
if (event.kind === "fail")
|
|
120343
|
-
return fail(event.cause);
|
|
120344
|
-
if (event.kind === "init") {
|
|
120345
|
-
plugins = event.plugins;
|
|
120346
|
-
return;
|
|
120347
|
-
}
|
|
120348
|
-
if (plugins === null || turns !== null || !event.success)
|
|
120349
|
-
return fail("bad_result");
|
|
120350
|
-
turns = { value: event.turns };
|
|
120351
|
-
};
|
|
120352
|
-
const onAbort = () => fail("aborted");
|
|
120353
|
-
const killTimer = setTimeout(() => fail("timeout"), Math.max(0, killAt - Date.now()));
|
|
120354
|
-
const deadlineTimer = setTimeout(() => {
|
|
120355
|
-
failure ??= "timeout";
|
|
120356
|
-
finish();
|
|
120357
|
-
}, Math.max(0, deadline - Date.now()));
|
|
120358
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
120359
|
-
child.stdout?.setEncoding("utf8");
|
|
120360
|
-
child.stdout?.on("data", (chunk) => {
|
|
120361
|
-
if (failure)
|
|
120362
|
-
return;
|
|
120363
|
-
bytes += Buffer.byteLength(chunk);
|
|
120364
|
-
if (bytes > PROBE_OUTPUT_MAX_BYTES)
|
|
120365
|
-
return fail("output_too_large");
|
|
120366
|
-
pending += chunk;
|
|
120367
|
-
for (let nl = pending.indexOf(`
|
|
120368
|
-
`);nl >= 0 && !failure; nl = pending.indexOf(`
|
|
120369
|
-
`)) {
|
|
120370
|
-
readLine(pending.slice(0, nl));
|
|
120371
|
-
pending = pending.slice(nl + 1);
|
|
120372
|
-
}
|
|
120373
|
-
});
|
|
120374
|
-
child.stdout?.on("close", () => {
|
|
120375
|
-
if (!failure && pending)
|
|
120376
|
-
readLine(pending);
|
|
120377
|
-
pending = "";
|
|
120378
|
-
stdoutDone = true;
|
|
120379
|
-
settleWhenGone();
|
|
120380
|
-
});
|
|
120381
|
-
child.on("error", () => {
|
|
120382
|
-
if (child.pid === undefined) {
|
|
120383
|
-
failure ??= "spawn_failed";
|
|
120384
|
-
exited = true;
|
|
120385
|
-
stdoutDone = true;
|
|
120386
|
-
finish();
|
|
120387
|
-
}
|
|
120388
|
-
});
|
|
120389
|
-
child.on("exit", (code) => {
|
|
120390
|
-
exitCode = code;
|
|
120391
|
-
exited = true;
|
|
120392
|
-
killProbe(child);
|
|
120393
|
-
settleWhenGone();
|
|
120394
|
-
});
|
|
120395
|
-
});
|
|
120396
|
-
}
|
|
120397
|
-
function policyPlatformOf(platform, env, readProcVersion) {
|
|
120398
|
-
if (platform === "win32")
|
|
120399
|
-
return "windows";
|
|
120400
|
-
if (platform !== "linux")
|
|
120401
|
-
return "other";
|
|
120402
|
-
if (env.WSL_DISTRO_NAME || env.WSL_INTEROP)
|
|
120403
|
-
return "wsl";
|
|
120404
|
-
try {
|
|
120405
|
-
const version = readProcVersion().toLowerCase();
|
|
120406
|
-
return version.includes("microsoft") || version.includes("wsl") ? "wsl" : "other";
|
|
120407
|
-
} catch {
|
|
120408
|
-
return "other";
|
|
120409
119803
|
}
|
|
119804
|
+
return values;
|
|
120410
119805
|
}
|
|
120411
|
-
function
|
|
120412
|
-
return
|
|
120413
|
-
}
|
|
120414
|
-
function isClaudeProgram(program) {
|
|
120415
|
-
const name = basename9(program);
|
|
120416
|
-
return name === "claude" || name === "claude.exe" || /[/\\]claude[/\\]versions[/\\][^/\\]+$/.test(program);
|
|
120417
|
-
}
|
|
120418
|
-
function callerLaunchFlags(argv) {
|
|
120419
|
-
const program = argv[0];
|
|
120420
|
-
if (program === undefined)
|
|
120421
|
-
return null;
|
|
120422
|
-
let flags;
|
|
120423
|
-
if (isClaudeProgram(program)) {
|
|
120424
|
-
flags = argv.slice(1);
|
|
120425
|
-
} else if (/^(node|nodejs|bun)(\.exe)?$/.test(basename9(program))) {
|
|
120426
|
-
const script = argv[1];
|
|
120427
|
-
if (!script || !/[/\\]@anthropic-ai[/\\]claude-code[/\\]cli\.m?js$/.test(script))
|
|
120428
|
-
return null;
|
|
120429
|
-
flags = argv.slice(2);
|
|
120430
|
-
} else {
|
|
120431
|
-
return null;
|
|
120432
|
-
}
|
|
120433
|
-
if (FLAGLESS_SUBCOMMANDS.includes(flags[0] ?? ""))
|
|
120434
|
-
return null;
|
|
120435
|
-
if (flags.some((t) => t.startsWith("--bg-")))
|
|
120436
|
-
return null;
|
|
120437
|
-
return flags;
|
|
119806
|
+
function passes(flags, flag) {
|
|
119807
|
+
return flags.some((token) => token === flag || token.startsWith(`${flag}=`));
|
|
120438
119808
|
}
|
|
120439
119809
|
function claudeEnvTrue(value) {
|
|
120440
119810
|
if (!value)
|
|
120441
119811
|
return false;
|
|
120442
119812
|
return ["1", "true", "yes", "on"].includes(value.toLowerCase().trim());
|
|
120443
119813
|
}
|
|
120444
|
-
function
|
|
120445
|
-
const
|
|
120446
|
-
|
|
120447
|
-
|
|
120448
|
-
|
|
120449
|
-
|
|
120450
|
-
|
|
120451
|
-
return coworkRefusal("the caller's");
|
|
120452
|
-
}
|
|
120453
|
-
if (effective.movesConfigDir) {
|
|
120454
|
-
return {
|
|
120455
|
-
outcome: "caller_mode_unmodelled",
|
|
120456
|
-
line: "a settings env block of the caller sets CLAUDE_CONFIG_DIR, which moves the settings Claude Code reads after they were read, and claudish does not model that"
|
|
120457
|
-
};
|
|
120458
|
-
}
|
|
120459
|
-
if (effective.movesRestricted) {
|
|
120460
|
-
return {
|
|
120461
|
-
outcome: "caller_mode_unmodelled",
|
|
120462
|
-
line: "a settings env block of the caller sets CLAUDE_CODE_RESTRICTED other than its launch did, after the launch chose its setting sources, and a probe booted with that value could choose others"
|
|
120463
|
-
};
|
|
120464
|
-
}
|
|
120465
|
-
return mode(effective.mayBeOn("CLAUDE_CODE_SAFE_MODE") || beforeEnd("--safe-mode"), "safe mode") ?? mode(effective.mayBeOn("CLAUDE_CODE_SIMPLE") || beforeEnd("--bare"), "bare mode");
|
|
119814
|
+
function expandHome(value, env, cwd) {
|
|
119815
|
+
const home = env.HOME || homedir41();
|
|
119816
|
+
if (value === "~")
|
|
119817
|
+
return home;
|
|
119818
|
+
if (value.startsWith("~/"))
|
|
119819
|
+
return join60(home, value.slice(2));
|
|
119820
|
+
return resolve9(cwd, value);
|
|
120466
119821
|
}
|
|
120467
|
-
function
|
|
120468
|
-
|
|
119822
|
+
function coworkMode(env) {
|
|
119823
|
+
return claudeEnvTrue(env.CLAUDE_CODE_USE_COWORK_PLUGINS);
|
|
119824
|
+
}
|
|
119825
|
+
function envBlockOf(layer) {
|
|
119826
|
+
if (!layer || !isPlainObject8(layer.env))
|
|
120469
119827
|
return {};
|
|
120470
|
-
|
|
120471
|
-
return;
|
|
120472
|
-
const env = {};
|
|
119828
|
+
const out = {};
|
|
120473
119829
|
for (const [key, value] of Object.entries(layer.env)) {
|
|
120474
119830
|
if (typeof value === "string")
|
|
120475
|
-
|
|
120476
|
-
else if (typeof value === "number" || typeof value === "boolean")
|
|
120477
|
-
env[key] = String(value);
|
|
119831
|
+
out[key] = value;
|
|
120478
119832
|
}
|
|
120479
|
-
return
|
|
119833
|
+
return out;
|
|
120480
119834
|
}
|
|
120481
|
-
function
|
|
120482
|
-
const
|
|
120483
|
-
if (
|
|
120484
|
-
return
|
|
120485
|
-
|
|
120486
|
-
|
|
120487
|
-
|
|
120488
|
-
|
|
120489
|
-
|
|
120490
|
-
|
|
119835
|
+
function pluginsDirFor(env, cwd) {
|
|
119836
|
+
const cache = env.CLAUDE_CODE_PLUGIN_CACHE_DIR;
|
|
119837
|
+
if (cache)
|
|
119838
|
+
return expandHome(cache, env, cwd);
|
|
119839
|
+
return join60(claudeCodeConfigDir(env, cwd), coworkMode(env) ? "cowork_plugins" : "plugins");
|
|
119840
|
+
}
|
|
119841
|
+
function userSettingsPath(env, cwd) {
|
|
119842
|
+
const name = coworkMode(env) ? "cowork_settings.json" : "settings.json";
|
|
119843
|
+
return join60(claudeCodeConfigDir(env, cwd), name);
|
|
119844
|
+
}
|
|
119845
|
+
function readSettingsFile(path) {
|
|
119846
|
+
const read = readBoundedJson(path, MAX_CONFIG_READ_BYTES);
|
|
119847
|
+
if (read === "missing" || read === "not_file")
|
|
119848
|
+
return {};
|
|
119849
|
+
if (typeof read === "string")
|
|
119850
|
+
return "unreadable";
|
|
119851
|
+
return isPlainObject8(read.value) ? read.value : "unreadable";
|
|
119852
|
+
}
|
|
119853
|
+
function readInstalledPlugins(dir) {
|
|
119854
|
+
const read = readBoundedJson(join60(dir, "installed_plugins.json"), MAX_CONFIG_READ_BYTES);
|
|
119855
|
+
if (read === "missing")
|
|
119856
|
+
return {};
|
|
119857
|
+
if (typeof read === "string")
|
|
120491
119858
|
return "unreadable";
|
|
119859
|
+
const parsed = read.value;
|
|
119860
|
+
if (!isPlainObject8(parsed) || parsed.version !== 2 || !isPlainObject8(parsed.plugins)) {
|
|
119861
|
+
return "unreadable";
|
|
119862
|
+
}
|
|
119863
|
+
const plugins = {};
|
|
119864
|
+
for (const [id, rows] of Object.entries(parsed.plugins)) {
|
|
119865
|
+
if (!Array.isArray(rows))
|
|
119866
|
+
continue;
|
|
119867
|
+
plugins[id] = rows.flatMap((row) => {
|
|
119868
|
+
if (!isPlainObject8(row))
|
|
119869
|
+
return [];
|
|
119870
|
+
const { scope, projectPath, installPath, version } = row;
|
|
119871
|
+
if (typeof scope !== "string" || typeof installPath !== "string")
|
|
119872
|
+
return [];
|
|
119873
|
+
return [
|
|
119874
|
+
{
|
|
119875
|
+
scope,
|
|
119876
|
+
installPath,
|
|
119877
|
+
...typeof projectPath === "string" ? { projectPath } : {},
|
|
119878
|
+
...typeof version === "string" ? { version } : {}
|
|
119879
|
+
}
|
|
119880
|
+
];
|
|
119881
|
+
});
|
|
120492
119882
|
}
|
|
119883
|
+
return plugins;
|
|
120493
119884
|
}
|
|
120494
|
-
function
|
|
120495
|
-
const root =
|
|
120496
|
-
|
|
120497
|
-
const tiers = dirs.map((dir) => launchSettingsFilesByTier(dir, sources));
|
|
120498
|
-
return [...tiers.flatMap((t) => t.project), ...tiers.flatMap((t) => t.local)];
|
|
119885
|
+
function mainCheckoutOf(dir) {
|
|
119886
|
+
const root = mainCheckoutRoot(dir, (path) => readFileSync46(path, "utf-8"), statPathKind);
|
|
119887
|
+
return root === undefined ? null : realOrResolved(root).normalize("NFC");
|
|
120499
119888
|
}
|
|
120500
|
-
function
|
|
120501
|
-
const
|
|
120502
|
-
|
|
120503
|
-
const
|
|
120504
|
-
|
|
120505
|
-
|
|
120506
|
-
|
|
120507
|
-
});
|
|
120508
|
-
const layers = [];
|
|
120509
|
-
if (sources === null || sources.has("user")) {
|
|
120510
|
-
const file = userSettingsFile(hostEnv.CLAUDE_CONFIG_DIR, home, cwd);
|
|
120511
|
-
const env = envOfSettingsFile(file);
|
|
120512
|
-
if (env === "unreadable")
|
|
120513
|
-
return unreadable(`the caller's user settings ${file}`);
|
|
120514
|
-
if (env)
|
|
120515
|
-
layers.push({ env, mayBeDropped: false });
|
|
120516
|
-
}
|
|
120517
|
-
for (const file of projectAndLocalFiles(cwd, flags, sources)) {
|
|
120518
|
-
const env = envOfSettingsFile(file);
|
|
120519
|
-
if (env === "unreadable")
|
|
120520
|
-
return unreadable(`the caller's settings ${file}`);
|
|
120521
|
-
if (env)
|
|
120522
|
-
layers.push({ env, mayBeDropped: true });
|
|
120523
|
-
}
|
|
120524
|
-
if (launch.layer) {
|
|
120525
|
-
const env = envStringsOf(launch.layer);
|
|
120526
|
-
if (env === undefined)
|
|
120527
|
-
return unreadable("the caller's own --settings");
|
|
120528
|
-
layers.push({ env, mayBeDropped: false });
|
|
120529
|
-
}
|
|
120530
|
-
const passed = {};
|
|
120531
|
-
for (const key of CALLER_LAUNCH_ENV_KEYS) {
|
|
120532
|
-
let value = hostEnv[key];
|
|
120533
|
-
if (!LAUNCH_ONLY_KEYS.includes(key)) {
|
|
120534
|
-
for (const layer of layers)
|
|
120535
|
-
if (!layer.mayBeDropped && key in layer.env)
|
|
120536
|
-
value = layer.env[key];
|
|
120537
|
-
}
|
|
120538
|
-
if (value !== undefined)
|
|
120539
|
-
passed[key] = value;
|
|
120540
|
-
}
|
|
120541
|
-
const valuesOf = (env, key) => Object.entries(env).filter(([k]) => k.toUpperCase() === key);
|
|
120542
|
-
const mayBeOn = (key) => {
|
|
120543
|
-
let possible = new Set([hostEnv[key]]);
|
|
120544
|
-
for (const layer of layers) {
|
|
120545
|
-
const set = valuesOf(layer.env, key).map(([, v]) => v);
|
|
120546
|
-
if (set.length === 0)
|
|
120547
|
-
continue;
|
|
120548
|
-
possible = layer.mayBeDropped ? new Set([...possible, ...set]) : new Set(set);
|
|
120549
|
-
}
|
|
120550
|
-
return [...possible].some(claudeEnvTrue);
|
|
119889
|
+
function applicableInstall(rows, cwd) {
|
|
119890
|
+
const here = cwd.normalize("NFC");
|
|
119891
|
+
let ownCheckout;
|
|
119892
|
+
const checkoutOfCwd = () => {
|
|
119893
|
+
if (ownCheckout === undefined)
|
|
119894
|
+
ownCheckout = mainCheckoutOf(here);
|
|
119895
|
+
return ownCheckout;
|
|
120551
119896
|
};
|
|
120552
|
-
const
|
|
120553
|
-
|
|
120554
|
-
|
|
120555
|
-
|
|
120556
|
-
|
|
120557
|
-
|
|
120558
|
-
|
|
120559
|
-
|
|
120560
|
-
|
|
120561
|
-
|
|
120562
|
-
|
|
120563
|
-
];
|
|
120564
|
-
const layerEnv = isPlainObject8(input.layer?.env) ? envStringsOf(input.layer) : undefined;
|
|
120565
|
-
const found = passes(input.childFlags, "--cowork") || on(input.env) || on(layerEnv) || files.some((file) => {
|
|
120566
|
-
const env = envOfSettingsFile(file);
|
|
120567
|
-
return env !== null && env !== "unreadable" && on(env);
|
|
119897
|
+
const applies = rows.filter((row) => {
|
|
119898
|
+
if (row.scope === "user" || row.scope === "managed")
|
|
119899
|
+
return true;
|
|
119900
|
+
if (!row.projectPath)
|
|
119901
|
+
return false;
|
|
119902
|
+
if (row.projectPath === here)
|
|
119903
|
+
return true;
|
|
119904
|
+
if (realOrResolved(row.projectPath).normalize("NFC") === here)
|
|
119905
|
+
return true;
|
|
119906
|
+
const checkout = checkoutOfCwd();
|
|
119907
|
+
return checkout !== null && mainCheckoutOf(row.projectPath) === checkout;
|
|
120568
119908
|
});
|
|
120569
|
-
|
|
119909
|
+
if (applies.length <= 1)
|
|
119910
|
+
return applies[0];
|
|
119911
|
+
return applies.find((row) => statPathKind(resolve9(here, row.installPath)) === "dir") ?? applies[0];
|
|
120570
119912
|
}
|
|
120571
|
-
function
|
|
120572
|
-
return {
|
|
120573
|
-
outcome: "caller_mode_unmodelled",
|
|
120574
|
-
line: `${whose} launch selects cowork plugins mode (CLAUDE_CODE_USE_COWORK_PLUGINS or --cowork), whose cowork_plugins folder and cowork_settings.json claudish does not model`
|
|
120575
|
-
};
|
|
119913
|
+
function enabledOf(layer) {
|
|
119914
|
+
return layer && isPlainObject8(layer.enabledPlugins) ? layer.enabledPlugins : {};
|
|
120576
119915
|
}
|
|
120577
|
-
function
|
|
120578
|
-
|
|
120579
|
-
|
|
120580
|
-
|
|
120581
|
-
|
|
120582
|
-
|
|
120583
|
-
|
|
120584
|
-
|
|
120585
|
-
|
|
120586
|
-
outcome: "plugin_url",
|
|
120587
|
-
line: `${whose} launch passes --plugin-url, which the plugin probe never downloads, so it cannot tell which marketplace copies that plugin shadows`
|
|
120588
|
-
};
|
|
120589
|
-
}
|
|
120590
|
-
const initialize = INITIALIZE_FLAGS.find((flag) => passes(flags, flag));
|
|
120591
|
-
if (initialize !== undefined) {
|
|
120592
|
-
return {
|
|
120593
|
-
outcome: "await_initialize",
|
|
120594
|
-
line: `${whose} launch passes ${initialize}, under which Claude Code reads settings, plugins or MCP servers from its stdin, which the plugin probe never sees`
|
|
120595
|
-
};
|
|
119916
|
+
function managedEnabled(managed) {
|
|
119917
|
+
const word = new Map;
|
|
119918
|
+
for (const object of managed) {
|
|
119919
|
+
for (const [id, value] of Object.entries(enabledOf(object))) {
|
|
119920
|
+
if (value !== true)
|
|
119921
|
+
word.set(id, false);
|
|
119922
|
+
else if (!word.has(id))
|
|
119923
|
+
word.set(id, true);
|
|
119924
|
+
}
|
|
120596
119925
|
}
|
|
120597
|
-
return;
|
|
119926
|
+
return word;
|
|
120598
119927
|
}
|
|
120599
|
-
function
|
|
120600
|
-
|
|
120601
|
-
|
|
119928
|
+
function pluginsLoadedAt(launch) {
|
|
119929
|
+
const { cwd, env, flags } = launch;
|
|
119930
|
+
const restricted = passes(flags, "--restricted") || claudeEnvTrue(env.CLAUDE_CODE_RESTRICTED);
|
|
119931
|
+
const sources = restricted ? new Set : enabledSettingSources(flags);
|
|
119932
|
+
const loads = (tier) => sources === null || sources.has(tier);
|
|
119933
|
+
const files = [
|
|
119934
|
+
...loads("user") ? [userSettingsPath(env, cwd)] : [],
|
|
119935
|
+
...Object.values(launchSettingsFilesByTier(cwd, sources)).flat()
|
|
119936
|
+
];
|
|
119937
|
+
let merged = {};
|
|
119938
|
+
let settingsEnv = {};
|
|
119939
|
+
const userFile = loads("user") ? userSettingsPath(env, cwd) : undefined;
|
|
119940
|
+
for (const file of files) {
|
|
119941
|
+
const layer = readSettingsFile(file);
|
|
119942
|
+
if (layer === "unreadable")
|
|
119943
|
+
return { ok: false, outcome: "settings_unreadable", file };
|
|
119944
|
+
merged = mergeSettingsLayers(merged, { enabledPlugins: enabledOf(layer) });
|
|
119945
|
+
if (file === userFile)
|
|
119946
|
+
settingsEnv = { ...settingsEnv, ...envBlockOf(layer) };
|
|
119947
|
+
}
|
|
119948
|
+
merged = mergeSettingsLayers(merged, { enabledPlugins: enabledOf(launch.layer) });
|
|
119949
|
+
settingsEnv = { ...settingsEnv, ...envBlockOf(launch.layer) };
|
|
119950
|
+
const enabled = new Map(Object.entries(enabledOf(merged)));
|
|
119951
|
+
for (const [id, on] of managedEnabled(launch.managed))
|
|
119952
|
+
enabled.set(id, on);
|
|
119953
|
+
const pluginEnv = { ...env, ...settingsEnv };
|
|
119954
|
+
const dir = pluginsDirFor(pluginEnv, cwd);
|
|
119955
|
+
const installed = readInstalledPlugins(dir);
|
|
119956
|
+
if (installed === "unreadable") {
|
|
120602
119957
|
return {
|
|
120603
|
-
|
|
120604
|
-
|
|
119958
|
+
ok: false,
|
|
119959
|
+
outcome: "installed_plugins_unreadable",
|
|
119960
|
+
file: join60(dir, "installed_plugins.json")
|
|
120605
119961
|
};
|
|
120606
119962
|
}
|
|
120607
|
-
|
|
120608
|
-
for (const
|
|
120609
|
-
|
|
120610
|
-
|
|
120611
|
-
|
|
119963
|
+
const found = new Map;
|
|
119964
|
+
for (const [id, value] of enabled) {
|
|
119965
|
+
if (value !== true || !Object.hasOwn(installed, id))
|
|
119966
|
+
continue;
|
|
119967
|
+
const row = applicableInstall(installed[id] ?? [], cwd);
|
|
119968
|
+
if (row)
|
|
119969
|
+
found.set(id, { path: resolve9(cwd, row.installPath), version: row.version });
|
|
119970
|
+
}
|
|
119971
|
+
const inline = childInlineNames(flags, pluginEnv, cwd);
|
|
119972
|
+
const loaded = withoutUnmetDependencies(found, inline);
|
|
119973
|
+
return { ok: true, enabled, found, loaded, inline };
|
|
119974
|
+
}
|
|
119975
|
+
function marketplaceOf(id) {
|
|
119976
|
+
const at = id.lastIndexOf("@");
|
|
119977
|
+
return at > 0 ? id.slice(at + 1) : undefined;
|
|
119978
|
+
}
|
|
119979
|
+
function dependencyId(dependency, dependant) {
|
|
119980
|
+
if (marketplaceOf(dependency))
|
|
119981
|
+
return dependency;
|
|
119982
|
+
const market = marketplaceOf(dependant);
|
|
119983
|
+
if (!market || market === "inline")
|
|
119984
|
+
return dependency;
|
|
119985
|
+
return `${dependency}@${market}`;
|
|
119986
|
+
}
|
|
119987
|
+
function readManifest(path) {
|
|
119988
|
+
const read = readBoundedJson(join60(path, ".claude-plugin", "plugin.json"), MAX_CONFIG_READ_BYTES);
|
|
119989
|
+
if (typeof read === "string")
|
|
120612
119990
|
return;
|
|
120613
|
-
return
|
|
120614
|
-
outcome: "managed_policy_present",
|
|
120615
|
-
line: `the managed policy source ${present} exists, and no plugin probe runs beside a managed policy`
|
|
120616
|
-
};
|
|
119991
|
+
return isPlainObject8(read.value) ? read.value : undefined;
|
|
120617
119992
|
}
|
|
120618
|
-
function
|
|
120619
|
-
const
|
|
120620
|
-
if (
|
|
120621
|
-
return;
|
|
120622
|
-
return {
|
|
120623
|
-
|
|
120624
|
-
|
|
120625
|
-
|
|
119993
|
+
function manifestDependencies(path) {
|
|
119994
|
+
const manifest = readManifest(path);
|
|
119995
|
+
if (!manifest || !Array.isArray(manifest.dependencies))
|
|
119996
|
+
return [];
|
|
119997
|
+
return manifest.dependencies.flatMap((entry) => {
|
|
119998
|
+
if (typeof entry === "string")
|
|
119999
|
+
return [{ name: entry }];
|
|
120000
|
+
if (isPlainObject8(entry) && typeof entry.name === "string") {
|
|
120001
|
+
return [
|
|
120002
|
+
typeof entry.version === "string" ? { name: entry.name, version: entry.version } : { name: entry.name }
|
|
120003
|
+
];
|
|
120004
|
+
}
|
|
120005
|
+
return [];
|
|
120006
|
+
});
|
|
120626
120007
|
}
|
|
120627
|
-
function
|
|
120628
|
-
const
|
|
120629
|
-
|
|
120630
|
-
|
|
120631
|
-
|
|
120632
|
-
|
|
120633
|
-
|
|
120008
|
+
function versionMeets(copy, range) {
|
|
120009
|
+
const version = copy.version ?? readManifest(copy.path)?.version;
|
|
120010
|
+
if (typeof version !== "string")
|
|
120011
|
+
return false;
|
|
120012
|
+
try {
|
|
120013
|
+
return Bun.semver.satisfies(version, range);
|
|
120014
|
+
} catch {
|
|
120015
|
+
return false;
|
|
120016
|
+
}
|
|
120634
120017
|
}
|
|
120635
|
-
function
|
|
120636
|
-
const
|
|
120637
|
-
|
|
120638
|
-
|
|
120639
|
-
|
|
120640
|
-
|
|
120641
|
-
|
|
120018
|
+
function withoutUnmetDependencies(found, inline) {
|
|
120019
|
+
const loaded = new Map(found);
|
|
120020
|
+
const needs = new Map;
|
|
120021
|
+
for (const [id, copy] of found) {
|
|
120022
|
+
needs.set(id, manifestDependencies(copy.path).map((dep) => ({ ...dep, id: dependencyId(dep.name, id) })));
|
|
120023
|
+
}
|
|
120024
|
+
const met = (dep) => {
|
|
120025
|
+
const copy = loaded.get(dep.id);
|
|
120026
|
+
if (copy)
|
|
120027
|
+
return dep.version === undefined || versionMeets(copy, dep.version);
|
|
120028
|
+
return inline.has(pluginName(dep.id));
|
|
120642
120029
|
};
|
|
120030
|
+
for (let changed = true;changed; ) {
|
|
120031
|
+
changed = false;
|
|
120032
|
+
for (const id of [...loaded.keys()]) {
|
|
120033
|
+
if ((needs.get(id) ?? []).every(met))
|
|
120034
|
+
continue;
|
|
120035
|
+
loaded.delete(id);
|
|
120036
|
+
changed = true;
|
|
120037
|
+
}
|
|
120038
|
+
}
|
|
120039
|
+
return loaded;
|
|
120643
120040
|
}
|
|
120644
|
-
function
|
|
120645
|
-
const
|
|
120646
|
-
|
|
120647
|
-
if (sources !== null && !sources.has("user"))
|
|
120648
|
-
return [];
|
|
120649
|
-
return [userSettingsFile(env.CLAUDE_CONFIG_DIR, env.HOME ?? "", cwd)];
|
|
120650
|
-
});
|
|
120651
|
-
const found = commandSettingIn([...new Set(files)], USER_STARTUP_HELPERS);
|
|
120652
|
-
if (found === undefined)
|
|
120653
|
-
return;
|
|
120654
|
-
return {
|
|
120655
|
-
outcome: "user_command_setting",
|
|
120656
|
-
line: found.key === undefined ? `the user settings ${found.path} cannot be parsed, so claudish cannot tell whether a probe would run a helper from them` : `the user settings ${found.path} set ${found.key}, a helper a probe boot can run before any model turn`
|
|
120657
|
-
};
|
|
120041
|
+
function inlinePluginName(dir) {
|
|
120042
|
+
const name = readManifest(dir)?.name;
|
|
120043
|
+
return typeof name === "string" ? name : basename9(dir).replace(/\.zip$/i, "");
|
|
120658
120044
|
}
|
|
120659
|
-
function
|
|
120660
|
-
|
|
120661
|
-
|
|
120662
|
-
|
|
120663
|
-
|
|
120664
|
-
|
|
120665
|
-
|
|
120666
|
-
|
|
120667
|
-
|
|
120045
|
+
function pluginName(id) {
|
|
120046
|
+
const at = id.lastIndexOf("@");
|
|
120047
|
+
return at > 0 ? id.slice(0, at) : id;
|
|
120048
|
+
}
|
|
120049
|
+
function manifestNames(path, name) {
|
|
120050
|
+
return readManifest(path)?.name === name;
|
|
120051
|
+
}
|
|
120052
|
+
function childInlineNames(flags, env, cwd) {
|
|
120053
|
+
const dirs = [
|
|
120054
|
+
...flagValues(flags, "--plugin-dir"),
|
|
120055
|
+
...flagValues(flags, "--plugin-dir-no-mcp")
|
|
120056
|
+
].map((dir) => expandHome(dir, env, cwd));
|
|
120057
|
+
const fromEnv = env.CLAUDE_CODE_PLUGIN_DIRS?.trim();
|
|
120058
|
+
if (fromEnv) {
|
|
120059
|
+
for (const dir of fromEnv.split(delimiter3)) {
|
|
120060
|
+
if (dir.trim())
|
|
120061
|
+
dirs.push(expandHome(dir.trim(), env, cwd));
|
|
120668
120062
|
}
|
|
120669
120063
|
}
|
|
120670
|
-
return
|
|
120064
|
+
return new Set(dirs.map(inlinePluginName));
|
|
120671
120065
|
}
|
|
120672
|
-
function
|
|
120673
|
-
const
|
|
120674
|
-
|
|
120675
|
-
|
|
120676
|
-
|
|
120677
|
-
} catch {
|
|
120678
|
-
launch = null;
|
|
120066
|
+
function managedObjectsOf(input, cwds) {
|
|
120067
|
+
const unread = unreadRegistryPolicy(input.managed);
|
|
120068
|
+
if (unread !== undefined) {
|
|
120069
|
+
log(`[mcp-session] no plugin handed over: the policy key ${unread.key} ${unread.state === "present" ? "holds a Settings value, which claudish does not read" : "could not be queried"}`);
|
|
120070
|
+
return "registry_policy_unread";
|
|
120679
120071
|
}
|
|
120680
|
-
const
|
|
120681
|
-
|
|
120682
|
-
|
|
120683
|
-
|
|
120684
|
-
|
|
120685
|
-
|
|
120686
|
-
|
|
120687
|
-
|
|
120688
|
-
|
|
120689
|
-
|
|
120690
|
-
|
|
120691
|
-
|
|
120692
|
-
|
|
120693
|
-
|
|
120694
|
-
|
|
120695
|
-
|
|
120072
|
+
const objects = [];
|
|
120073
|
+
const seen = new Set;
|
|
120074
|
+
for (const cwd of cwds) {
|
|
120075
|
+
const policy = readManagedPolicy(input.managed, input.env, cwd);
|
|
120076
|
+
const oversize = policy.oversize[0];
|
|
120077
|
+
if (oversize !== undefined) {
|
|
120078
|
+
log(`[mcp-session] no plugin handed over: ${oversize} is larger than claudish reads`);
|
|
120079
|
+
return "managed_settings_oversize";
|
|
120080
|
+
}
|
|
120081
|
+
const sideload = sideloadFlagsDisabledBy(policy);
|
|
120082
|
+
if (sideload !== undefined) {
|
|
120083
|
+
log(`[mcp-session] no plugin handed over: ${sideload} sets disableSideloadFlags, and Claude Code exits on --plugin-dir while it does`);
|
|
120084
|
+
return "sideload_flags_disabled";
|
|
120085
|
+
}
|
|
120086
|
+
for (const { path, value } of policy.objects) {
|
|
120087
|
+
if (seen.has(path))
|
|
120088
|
+
continue;
|
|
120089
|
+
seen.add(path);
|
|
120090
|
+
objects.push(value);
|
|
120091
|
+
}
|
|
120696
120092
|
}
|
|
120697
|
-
const
|
|
120698
|
-
|
|
120699
|
-
if (settings !== undefined) {
|
|
120093
|
+
for (const value of flagValues(input.childFlags, "--managed-settings")) {
|
|
120094
|
+
let parsed;
|
|
120700
120095
|
try {
|
|
120701
|
-
|
|
120702
|
-
throw new Error("no value");
|
|
120703
|
-
const inline = settings.trim().startsWith("{");
|
|
120704
|
-
layer = readSettingsValue(inline ? settings : resolve9(launch.cwd, settings));
|
|
120096
|
+
parsed = JSON.parse(value);
|
|
120705
120097
|
} catch {
|
|
120706
|
-
|
|
120707
|
-
outcome: "caller_settings_unreadable",
|
|
120708
|
-
line: "the caller's own --settings cannot be read or parsed, so claudish cannot tell which plugins it turns off"
|
|
120709
|
-
};
|
|
120098
|
+
parsed = undefined;
|
|
120710
120099
|
}
|
|
120100
|
+
if (!isPlainObject8(parsed)) {
|
|
120101
|
+
log("[mcp-session] no plugin handed over: the child's --managed-settings is not a JSON object");
|
|
120102
|
+
return "managed_settings_unreadable";
|
|
120103
|
+
}
|
|
120104
|
+
if (parsed.disableSideloadFlags === true) {
|
|
120105
|
+
log("[mcp-session] no plugin handed over: the child's --managed-settings sets disableSideloadFlags, and Claude Code exits on --plugin-dir while it does");
|
|
120106
|
+
return "sideload_flags_disabled";
|
|
120107
|
+
}
|
|
120108
|
+
objects.push(parsed);
|
|
120711
120109
|
}
|
|
120712
|
-
const
|
|
120713
|
-
if (
|
|
120714
|
-
|
|
120715
|
-
|
|
120716
|
-
if (unmodelled)
|
|
120717
|
-
return unmodelled;
|
|
120718
|
-
if (setupReal !== undefined && !sharesMainCheckout(setupReal, launch.cwd)) {
|
|
120719
|
-
return {
|
|
120720
|
-
outcome: "setup_from_not_caller",
|
|
120721
|
-
line: "setup_from and the caller's launch directory do not share a main checkout, so a probe in setup_from would not load what the caller loads"
|
|
120722
|
-
};
|
|
120110
|
+
const marketplaceKey = MARKETPLACE_RULE_KEYS.find((key) => objects.some((o) => o[key] !== undefined));
|
|
120111
|
+
if (marketplaceKey) {
|
|
120112
|
+
log(`[mcp-session] no plugin handed over: a managed ${marketplaceKey} applies, and a --plugin-dir copy is not held to it`);
|
|
120113
|
+
return "marketplace_policy";
|
|
120723
120114
|
}
|
|
120724
|
-
return
|
|
120115
|
+
return objects;
|
|
120725
120116
|
}
|
|
120726
|
-
function
|
|
120727
|
-
const
|
|
120728
|
-
|
|
120729
|
-
|
|
120730
|
-
|
|
120731
|
-
delete out[key];
|
|
120732
|
-
else
|
|
120733
|
-
out[key] = value;
|
|
120117
|
+
function childLaunchRefusal(input) {
|
|
120118
|
+
const flags = input.childFlags;
|
|
120119
|
+
if (passes(flags, "--plugin-url")) {
|
|
120120
|
+
log("[mcp-session] no plugin handed over: the child's flags pass --plugin-url");
|
|
120121
|
+
return "plugin_url";
|
|
120734
120122
|
}
|
|
120735
|
-
|
|
120736
|
-
|
|
120737
|
-
|
|
120738
|
-
|
|
120739
|
-
return { plugins: [], outcome: refusal.outcome };
|
|
120740
|
-
}
|
|
120741
|
-
function pidAlive2(pid) {
|
|
120742
|
-
try {
|
|
120743
|
-
process.kill(pid, 0);
|
|
120744
|
-
return true;
|
|
120745
|
-
} catch (err) {
|
|
120746
|
-
return err.code === "EPERM";
|
|
120123
|
+
const initialize = INITIALIZE_FLAGS.find((flag) => passes(flags, flag));
|
|
120124
|
+
if (initialize) {
|
|
120125
|
+
log(`[mcp-session] no plugin handed over: the child's flags pass ${initialize}`);
|
|
120126
|
+
return "initialize_flags";
|
|
120747
120127
|
}
|
|
120748
|
-
|
|
120749
|
-
|
|
120750
|
-
|
|
120751
|
-
const now = sweep.now ?? Date.now();
|
|
120752
|
-
const alive = sweep.alive ?? pidAlive2;
|
|
120753
|
-
let names;
|
|
120754
|
-
try {
|
|
120755
|
-
names = readdirSync13(root);
|
|
120756
|
-
} catch {
|
|
120757
|
-
return;
|
|
120128
|
+
if (passes(flags, "--project-config-root")) {
|
|
120129
|
+
log("[mcp-session] no plugin handed over: the child's flags pass --project-config-root");
|
|
120130
|
+
return "project_config_root";
|
|
120758
120131
|
}
|
|
120759
|
-
const
|
|
120760
|
-
|
|
120761
|
-
|
|
120762
|
-
|
|
120763
|
-
|
|
120764
|
-
const path = join60(root, name);
|
|
120765
|
-
try {
|
|
120766
|
-
const stat = lstatSync10(path);
|
|
120767
|
-
if (!stat.isDirectory() || uid !== undefined && stat.uid !== uid)
|
|
120768
|
-
continue;
|
|
120769
|
-
const pid = match[1] === undefined ? undefined : Number(match[1]);
|
|
120770
|
-
const ownerGone = pid !== undefined && pid > 0 && !alive(pid);
|
|
120771
|
-
if (!ownerGone && now - stat.mtimeMs <= STALE_PROBE_DIR_MS)
|
|
120772
|
-
continue;
|
|
120773
|
-
rmSync15(path, { recursive: true, force: true });
|
|
120774
|
-
} catch {}
|
|
120132
|
+
const safe = passes(flags, "--safe-mode") || claudeEnvTrue(input.env.CLAUDE_CODE_SAFE_MODE);
|
|
120133
|
+
const bare = passes(flags, "--bare") || claudeEnvTrue(input.env.CLAUDE_CODE_SIMPLE);
|
|
120134
|
+
if (safe || bare) {
|
|
120135
|
+
log(`[mcp-session] no plugin handed over: the child runs in ${safe ? "safe" : "bare"} mode, which loads no installed plugin`);
|
|
120136
|
+
return "plugins_off";
|
|
120775
120137
|
}
|
|
120138
|
+
return;
|
|
120776
120139
|
}
|
|
120777
|
-
|
|
120140
|
+
function refused(outcome) {
|
|
120141
|
+
return { plugins: [], outcome };
|
|
120142
|
+
}
|
|
120143
|
+
function inheritedPluginsFor(input) {
|
|
120778
120144
|
const { setupReal } = input;
|
|
120779
120145
|
if (!setupReal)
|
|
120780
120146
|
return null;
|
|
120781
120147
|
const childReal = realOrResolved(input.childCwd);
|
|
120782
120148
|
if (sharesMainCheckout(setupReal, childReal))
|
|
120783
120149
|
return null;
|
|
120784
|
-
const early =
|
|
120785
|
-
|
|
120786
|
-
|
|
120787
|
-
|
|
120788
|
-
|
|
120789
|
-
|
|
120790
|
-
|
|
120791
|
-
const
|
|
120792
|
-
const
|
|
120793
|
-
const
|
|
120794
|
-
|
|
120795
|
-
|
|
120796
|
-
|
|
120797
|
-
|
|
120798
|
-
|
|
120799
|
-
|
|
120800
|
-
|
|
120801
|
-
const
|
|
120802
|
-
|
|
120803
|
-
|
|
120804
|
-
|
|
120805
|
-
|
|
120806
|
-
|
|
120807
|
-
|
|
120808
|
-
|
|
120809
|
-
|
|
120810
|
-
|
|
120811
|
-
|
|
120812
|
-
|
|
120813
|
-
|
|
120814
|
-
|
|
120815
|
-
|
|
120816
|
-
|
|
120817
|
-
|
|
120818
|
-
|
|
120819
|
-
|
|
120820
|
-
|
|
120821
|
-
|
|
120822
|
-
|
|
120823
|
-
|
|
120824
|
-
|
|
120825
|
-
|
|
120826
|
-
|
|
120827
|
-
rmSync15(dir, { recursive: true, force: true });
|
|
120828
|
-
}
|
|
120829
|
-
const [callerResult, childResult] = results;
|
|
120830
|
-
const failed = results.find((r) => !r.ok);
|
|
120831
|
-
if (failed || !callerResult?.ok || !childResult?.ok) {
|
|
120832
|
-
const cause = failed?.cause ?? "spawn_failed";
|
|
120833
|
-
log(`[mcp-session] no plugin handed over: the plugin probe failed (${cause})`);
|
|
120834
|
-
return { plugins: [], outcome: cause };
|
|
120150
|
+
const early = childLaunchRefusal(input);
|
|
120151
|
+
if (early)
|
|
120152
|
+
return refused(early);
|
|
120153
|
+
const managed = managedObjectsOf(input, [setupReal, childReal]);
|
|
120154
|
+
if (typeof managed === "string")
|
|
120155
|
+
return refused(managed);
|
|
120156
|
+
const at = (cwd) => pluginsLoadedAt({ cwd, env: input.env, flags: input.childFlags, layer: input.layer, managed });
|
|
120157
|
+
const caller = at(setupReal);
|
|
120158
|
+
const child = caller.ok ? at(childReal) : caller;
|
|
120159
|
+
for (const side of [caller, child]) {
|
|
120160
|
+
if (!side.ok) {
|
|
120161
|
+
log(`[mcp-session] no plugin handed over: ${side.file} cannot be read`);
|
|
120162
|
+
return refused(side.outcome);
|
|
120163
|
+
}
|
|
120164
|
+
}
|
|
120165
|
+
if (!caller.ok || !child.ok)
|
|
120166
|
+
return refused("settings_unreadable");
|
|
120167
|
+
const { inline } = child;
|
|
120168
|
+
const seen = new Set;
|
|
120169
|
+
const plugins = [];
|
|
120170
|
+
for (const id of [...caller.loaded.keys()].sort()) {
|
|
120171
|
+
const copy = caller.loaded.get(id);
|
|
120172
|
+
const name = pluginName(id);
|
|
120173
|
+
if (child.found.get(id)?.path === copy.path || seen.has(copy.path))
|
|
120174
|
+
continue;
|
|
120175
|
+
if (child.enabled.has(id) && child.enabled.get(id) !== true) {
|
|
120176
|
+
log(`[mcp-session] plugin ${id} not handed over: the work_dir's own settings turn it off`);
|
|
120177
|
+
continue;
|
|
120178
|
+
}
|
|
120179
|
+
if (inline.has(name)) {
|
|
120180
|
+
log(`[mcp-session] plugin ${id} not handed over: the child loads ${name} from its own --plugin-dir`);
|
|
120181
|
+
continue;
|
|
120182
|
+
}
|
|
120183
|
+
if (statPathKind(copy.path) !== "dir") {
|
|
120184
|
+
log(`[mcp-session] plugin ${id} not handed over: its copy ${copy.path} does not exist`);
|
|
120185
|
+
continue;
|
|
120186
|
+
}
|
|
120187
|
+
if (!manifestNames(copy.path, name)) {
|
|
120188
|
+
log(`[mcp-session] plugin ${id} not handed over: its copy has no .claude-plugin/plugin.json naming it ${name}`);
|
|
120189
|
+
continue;
|
|
120190
|
+
}
|
|
120191
|
+
seen.add(copy.path);
|
|
120192
|
+
plugins.push({ id, version: copy.version, path: copy.path });
|
|
120835
120193
|
}
|
|
120836
|
-
|
|
120837
|
-
return { plugins: withoutLayerDisabled(plugins, input.layer), outcome: "ok" };
|
|
120194
|
+
return { plugins: survivingInTheChild(plugins, child.found, inline), outcome: "ok" };
|
|
120838
120195
|
}
|
|
120839
|
-
|
|
120840
|
-
|
|
120196
|
+
function survivingInTheChild(candidates, childFound, inline) {
|
|
120197
|
+
const effective = new Map(childFound);
|
|
120198
|
+
for (const { id, path, version } of candidates)
|
|
120199
|
+
effective.set(id, { path, version });
|
|
120200
|
+
const loads = withoutUnmetDependencies(effective, inline);
|
|
120201
|
+
return candidates.filter(({ id }) => {
|
|
120202
|
+
if (loads.has(id))
|
|
120203
|
+
return true;
|
|
120204
|
+
log(`[mcp-session] plugin ${id} not handed over: a dependency it requires does not load in the child`);
|
|
120205
|
+
return false;
|
|
120206
|
+
});
|
|
120207
|
+
}
|
|
120208
|
+
var MAX_CONFIG_READ_BYTES, INITIALIZE_FLAGS, MARKETPLACE_RULE_KEYS;
|
|
120209
|
+
var init_plugin_handover = __esm(() => {
|
|
120210
|
+
init_claude_code_facts();
|
|
120841
120211
|
init_claude_runner();
|
|
120842
120212
|
init_logger();
|
|
120843
|
-
|
|
120213
|
+
init_bounded_read();
|
|
120844
120214
|
init_inherited_settings();
|
|
120845
|
-
|
|
120846
|
-
PROBE_OUTPUT_MAX_BYTES = 32 * 1024 * 1024;
|
|
120847
|
-
QUIET_FLAGS = [
|
|
120848
|
-
"--output-format",
|
|
120849
|
-
"stream-json",
|
|
120850
|
-
"--verbose",
|
|
120851
|
-
"--settings",
|
|
120852
|
-
"<settings file>",
|
|
120853
|
-
"--strict-mcp-config",
|
|
120854
|
-
"--no-session-persistence"
|
|
120855
|
-
];
|
|
120856
|
-
PLUGIN_PATH_FLAGS = ["--plugin-dir", "--plugin-dir-no-mcp", "--project-config-root"];
|
|
120215
|
+
MAX_CONFIG_READ_BYTES = 16 * 1024 * 1024;
|
|
120857
120216
|
INITIALIZE_FLAGS = [
|
|
120858
120217
|
"--await-initialize",
|
|
120859
120218
|
"--initialize-fields",
|
|
120860
120219
|
"--managed-settings-in-initialize"
|
|
120861
120220
|
];
|
|
120862
|
-
|
|
120863
|
-
|
|
120864
|
-
|
|
120865
|
-
"
|
|
120866
|
-
"CLAUDE_CODE_USE_VERTEX",
|
|
120867
|
-
"CLAUDE_CODE_USE_FOUNDRY",
|
|
120868
|
-
"CLAUDE_CODE_USE_ANTHROPIC_AWS",
|
|
120869
|
-
"CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD",
|
|
120870
|
-
"CLAUDE_CODE_USE_MANTLE",
|
|
120871
|
-
"CLAUDE_CODE_USE_GATEWAY"
|
|
120872
|
-
];
|
|
120873
|
-
PROVIDER_BASE_URLS = [
|
|
120874
|
-
"ANTHROPIC_BEDROCK_BASE_URL",
|
|
120875
|
-
"ANTHROPIC_VERTEX_BASE_URL",
|
|
120876
|
-
"ANTHROPIC_FOUNDRY_BASE_URL",
|
|
120877
|
-
"ANTHROPIC_AWS_BASE_URL",
|
|
120878
|
-
"ANTHROPIC_GOOGLE_CLOUD_BASE_URL",
|
|
120879
|
-
"ANTHROPIC_BEDROCK_MANTLE_BASE_URL"
|
|
120880
|
-
];
|
|
120881
|
-
PROBE_STARTUP_HELPER_SWITCHES = [
|
|
120882
|
-
"CLAUDE_CODE_ENABLE_PROXY_AUTH_HELPER",
|
|
120883
|
-
"CLAUDE_CODE_ENABLE_TELEMETRY"
|
|
120884
|
-
];
|
|
120885
|
-
PROBE_FIRST_PARTY_SWITCHES = [
|
|
120886
|
-
"_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL",
|
|
120887
|
-
"CLAUDE_CODE_CLIENT_DATA_URL"
|
|
120888
|
-
];
|
|
120889
|
-
PROBE_HOST_HANDOFF_VARS = [
|
|
120890
|
-
"CLAUDE_CODE_HOST_CREDS_FILE",
|
|
120891
|
-
"CLAUDE_CODE_HOST_AUTH_ENV_VAR",
|
|
120892
|
-
"CLAUDE_CODE_HOST_AUTH_ASK_AT_START",
|
|
120893
|
-
"CLAUDE_CODE_HOST_AUTH_REFRESH_TIMEOUT_MS",
|
|
120894
|
-
"CLAUDE_CODE_SDK_HAS_HOST_AUTH_REFRESH",
|
|
120895
|
-
"CLAUDE_CODE_LAUNCHER_RUNS_API_KEY_HELPER",
|
|
120896
|
-
"CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR",
|
|
120897
|
-
"CLAUDE_CODE_API_KEY_FILE_DESCRIPTOR",
|
|
120898
|
-
"CLAUDE_CODE_GATEWAY_TOKEN_FILE_DESCRIPTOR",
|
|
120899
|
-
"CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR",
|
|
120900
|
-
"CLAUDE_BG_AUTH_SNAPSHOT_PATH",
|
|
120901
|
-
"CLAUDE_CODE_OAUTH_REFRESH_TOKEN",
|
|
120902
|
-
"CLAUDE_CODE_SESSION_ACCESS_TOKEN",
|
|
120903
|
-
"CLAUDE_SESSION_INGRESS_TOKEN_FILE"
|
|
120221
|
+
MARKETPLACE_RULE_KEYS = [
|
|
120222
|
+
"strictKnownMarketplaces",
|
|
120223
|
+
"allowedMarketplaces",
|
|
120224
|
+
"blockedMarketplaces"
|
|
120904
120225
|
];
|
|
120905
|
-
PROBE_SETTINGS_EMPTY_VARS = [
|
|
120906
|
-
"ANTHROPIC_API_KEY",
|
|
120907
|
-
"ANTHROPIC_AUTH_TOKEN",
|
|
120908
|
-
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
120909
|
-
...PROBE_HOST_HANDOFF_VARS,
|
|
120910
|
-
...PROBE_PROVIDER_SWITCHES,
|
|
120911
|
-
...PROVIDER_BASE_URLS,
|
|
120912
|
-
...PROBE_STARTUP_HELPER_SWITCHES,
|
|
120913
|
-
...PROBE_FIRST_PARTY_SWITCHES,
|
|
120914
|
-
PROBE_HOST_MANAGED_MARKER
|
|
120915
|
-
];
|
|
120916
|
-
PROBE_PARENT_VARS = [
|
|
120917
|
-
"PATH",
|
|
120918
|
-
"HOME",
|
|
120919
|
-
"USER",
|
|
120920
|
-
"LOGNAME",
|
|
120921
|
-
"SHELL",
|
|
120922
|
-
"TMPDIR",
|
|
120923
|
-
"LANG",
|
|
120924
|
-
"TERM",
|
|
120925
|
-
"XDG_CONFIG_HOME",
|
|
120926
|
-
"XDG_DATA_HOME",
|
|
120927
|
-
"XDG_CACHE_HOME",
|
|
120928
|
-
"CLAUDE_CONFIG_DIR",
|
|
120929
|
-
"CLAUDE_PATH",
|
|
120930
|
-
...PROBE_PLUGIN_VARS,
|
|
120931
|
-
...PROBE_MODE_VARS
|
|
120932
|
-
];
|
|
120933
|
-
PROBE_SETTINGS_ENV = {
|
|
120934
|
-
ANTHROPIC_BASE_URL: PLUGIN_PROBE_BASE_URL,
|
|
120935
|
-
...Object.fromEntries(PROBE_SETTINGS_EMPTY_VARS.map((key) => [key, ""])),
|
|
120936
|
-
[PROBE_HOST_MANAGED_MARKER]: "1"
|
|
120937
|
-
};
|
|
120938
|
-
COMMAND_SETTINGS = [
|
|
120939
|
-
"apiKeyHelper",
|
|
120940
|
-
"awsAuthRefresh",
|
|
120941
|
-
"awsCredentialExport",
|
|
120942
|
-
"fileSuggestion",
|
|
120943
|
-
"gcpAuthRefresh",
|
|
120944
|
-
"otelHeadersHelper",
|
|
120945
|
-
"processWrapper",
|
|
120946
|
-
"policyHelpers",
|
|
120947
|
-
"proxyAuthHelper",
|
|
120948
|
-
"statusLine",
|
|
120949
|
-
"subagentStatusLine"
|
|
120950
|
-
];
|
|
120951
|
-
USER_STARTUP_HELPERS = [
|
|
120952
|
-
"apiKeyHelper",
|
|
120953
|
-
"awsAuthRefresh",
|
|
120954
|
-
"awsCredentialExport",
|
|
120955
|
-
"gcpAuthRefresh",
|
|
120956
|
-
"otelHeadersHelper",
|
|
120957
|
-
"policyHelpers",
|
|
120958
|
-
"proxyAuthHelper"
|
|
120959
|
-
];
|
|
120960
|
-
spawnPluginProbe = pluginProbeRunner(findClaudeBinary);
|
|
120961
|
-
FLAGLESS_SUBCOMMANDS = ["bg-spare", "bg-pty-host", "daemon"];
|
|
120962
|
-
LAUNCH_ONLY_KEYS = ["CLAUDE_CONFIG_DIR", "CLAUDE_CODE_RESTRICTED"];
|
|
120963
|
-
PROBE_DIR_NAME = /^claudish-plugin-probe-(?:(\d{1,10})-)?[A-Za-z0-9]{6}$/;
|
|
120964
|
-
STALE_PROBE_DIR_MS = 10 * 60000;
|
|
120965
120226
|
});
|
|
120966
120227
|
|
|
120967
120228
|
// src/mcp-session/scrollback-buffer.ts
|
|
@@ -121021,23 +120282,296 @@ var init_scrollback_buffer = __esm(() => {
|
|
|
121021
120282
|
ANSI_RE3 = /\x1b\[[0-9;]*[a-zA-Z]|\x1b\].*?\x07|\x1b[()][AB012]|\x1b[>=<]|\x0f|\x0e/g;
|
|
121022
120283
|
});
|
|
121023
120284
|
|
|
120285
|
+
// src/mcp-session/work-dir-trust.ts
|
|
120286
|
+
import * as fs from "fs";
|
|
120287
|
+
import { homedir as homedir42 } from "os";
|
|
120288
|
+
import { basename as basename10, dirname as dirname24, join as join61 } from "path";
|
|
120289
|
+
function isPlainObject9(value) {
|
|
120290
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
120291
|
+
}
|
|
120292
|
+
function gitRootOf(dir) {
|
|
120293
|
+
let current = dir;
|
|
120294
|
+
for (;; ) {
|
|
120295
|
+
if (statPathKind(join61(current, ".git")) !== undefined)
|
|
120296
|
+
return current;
|
|
120297
|
+
const parent = dirname24(current);
|
|
120298
|
+
if (parent === current)
|
|
120299
|
+
return null;
|
|
120300
|
+
current = parent;
|
|
120301
|
+
}
|
|
120302
|
+
}
|
|
120303
|
+
function recordTrusts(config, key) {
|
|
120304
|
+
const projects = config.projects;
|
|
120305
|
+
if (!isPlainObject9(projects))
|
|
120306
|
+
return false;
|
|
120307
|
+
const entry = projects[key];
|
|
120308
|
+
return isPlainObject9(entry) && Boolean(entry.hasTrustDialogAccepted);
|
|
120309
|
+
}
|
|
120310
|
+
function trustedBy(config, real) {
|
|
120311
|
+
const here = real.normalize("NFC");
|
|
120312
|
+
const checkout = mainCheckoutRoot(here, (path) => readFileSync47(path, "utf-8"), statPathKind);
|
|
120313
|
+
if (checkout !== undefined) {
|
|
120314
|
+
const key = realOrResolved(checkout).normalize("NFC");
|
|
120315
|
+
if (recordTrusts(config, key))
|
|
120316
|
+
return key;
|
|
120317
|
+
}
|
|
120318
|
+
const stop = gitRootOf(here);
|
|
120319
|
+
let current = here;
|
|
120320
|
+
for (;; ) {
|
|
120321
|
+
if (recordTrusts(config, current))
|
|
120322
|
+
return current;
|
|
120323
|
+
if (current === stop)
|
|
120324
|
+
return null;
|
|
120325
|
+
const parent = dirname24(current);
|
|
120326
|
+
if (parent === current)
|
|
120327
|
+
return null;
|
|
120328
|
+
current = parent;
|
|
120329
|
+
}
|
|
120330
|
+
}
|
|
120331
|
+
function globalConfigFile(env, cwd) {
|
|
120332
|
+
const file = claudeCodeGlobalConfigPath(env, cwd);
|
|
120333
|
+
if (!env.CLAUDE_CODE_CUSTOM_OAUTH_URL)
|
|
120334
|
+
return file;
|
|
120335
|
+
return join61(dirname24(file), ".claude-custom-oauth.json");
|
|
120336
|
+
}
|
|
120337
|
+
function errorCode2(err) {
|
|
120338
|
+
return err?.code;
|
|
120339
|
+
}
|
|
120340
|
+
function siblingName(path, tag) {
|
|
120341
|
+
const unique = `${process.pid}-${Math.random().toString(36).slice(2, 10)}`;
|
|
120342
|
+
return join61(dirname24(path), `.${basename10(path)}.claudish-${tag}-${unique}`);
|
|
120343
|
+
}
|
|
120344
|
+
function identityOf(path) {
|
|
120345
|
+
try {
|
|
120346
|
+
const { dev, ino, mtimeMs } = lstatSync9(path);
|
|
120347
|
+
return { dev, ino, mtimeMs };
|
|
120348
|
+
} catch {
|
|
120349
|
+
return;
|
|
120350
|
+
}
|
|
120351
|
+
}
|
|
120352
|
+
function sameLock(a, b) {
|
|
120353
|
+
return a !== undefined && b !== undefined && a.dev === b.dev && a.ino === b.ino && a.mtimeMs === b.mtimeMs;
|
|
120354
|
+
}
|
|
120355
|
+
async function takeConfigLock(lockPath, waitMs) {
|
|
120356
|
+
const deadline = Date.now() + waitMs;
|
|
120357
|
+
for (;; ) {
|
|
120358
|
+
try {
|
|
120359
|
+
mkdirSync27(lockPath);
|
|
120360
|
+
let mine = identityOf(lockPath);
|
|
120361
|
+
return {
|
|
120362
|
+
lease: () => {
|
|
120363
|
+
if (!sameLock(identityOf(lockPath), mine))
|
|
120364
|
+
return;
|
|
120365
|
+
const now = new Date;
|
|
120366
|
+
utimesSync(lockPath, now, now);
|
|
120367
|
+
mine = identityOf(lockPath);
|
|
120368
|
+
},
|
|
120369
|
+
release: () => {
|
|
120370
|
+
if (!sameLock(identityOf(lockPath), mine))
|
|
120371
|
+
return;
|
|
120372
|
+
try {
|
|
120373
|
+
rmdirSync3(lockPath);
|
|
120374
|
+
} catch {}
|
|
120375
|
+
}
|
|
120376
|
+
};
|
|
120377
|
+
} catch (err) {
|
|
120378
|
+
const code = errorCode2(err);
|
|
120379
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
120380
|
+
return "config_missing";
|
|
120381
|
+
if (code !== "EEXIST")
|
|
120382
|
+
return "config_unreadable";
|
|
120383
|
+
}
|
|
120384
|
+
if (Date.now() >= deadline)
|
|
120385
|
+
return "lock_busy";
|
|
120386
|
+
await Bun.sleep(25 + Math.floor(Math.random() * 50));
|
|
120387
|
+
}
|
|
120388
|
+
}
|
|
120389
|
+
function replaceFile(target, text, mode) {
|
|
120390
|
+
const temp = siblingName(target, "write");
|
|
120391
|
+
const bytes = Buffer.from(text, "utf-8");
|
|
120392
|
+
let fd;
|
|
120393
|
+
try {
|
|
120394
|
+
fd = openSync18(temp, "wx", mode);
|
|
120395
|
+
for (let written = 0;written < bytes.length; ) {
|
|
120396
|
+
const n = fs.writeSync(fd, bytes, written, bytes.length - written);
|
|
120397
|
+
if (n <= 0)
|
|
120398
|
+
throw new Error("short write");
|
|
120399
|
+
written += n;
|
|
120400
|
+
}
|
|
120401
|
+
fsyncSync4(fd);
|
|
120402
|
+
const open = fd;
|
|
120403
|
+
fd = undefined;
|
|
120404
|
+
closeSync18(open);
|
|
120405
|
+
chmodSync8(temp, mode);
|
|
120406
|
+
renameSync10(temp, target);
|
|
120407
|
+
return true;
|
|
120408
|
+
} catch {
|
|
120409
|
+
if (fd !== undefined) {
|
|
120410
|
+
try {
|
|
120411
|
+
closeSync18(fd);
|
|
120412
|
+
} catch {}
|
|
120413
|
+
}
|
|
120414
|
+
try {
|
|
120415
|
+
fs.unlinkSync(temp);
|
|
120416
|
+
} catch {}
|
|
120417
|
+
return false;
|
|
120418
|
+
}
|
|
120419
|
+
}
|
|
120420
|
+
function ignoresPersistedTrust(input) {
|
|
120421
|
+
return claudeEnvTrue(input.env.CLAUDE_CODE_IGNORE_PERSISTED_TRUST) || (input.childFlags ?? []).includes("--ignore-persisted-trust");
|
|
120422
|
+
}
|
|
120423
|
+
async function ensureWorkDirTrust(input) {
|
|
120424
|
+
let real = input.workDir;
|
|
120425
|
+
const done = (outcome, detail) => {
|
|
120426
|
+
try {
|
|
120427
|
+
log(`[mcp-session] work_dir trust ${outcome}: ${real} (${detail})`);
|
|
120428
|
+
} catch {}
|
|
120429
|
+
return outcome;
|
|
120430
|
+
};
|
|
120431
|
+
try {
|
|
120432
|
+
if (input.workDir.trim() === "")
|
|
120433
|
+
return done("not_a_directory", "work_dir is empty");
|
|
120434
|
+
real = realOrResolved(input.workDir).normalize("NFC");
|
|
120435
|
+
return await writeTrust(input, real, done);
|
|
120436
|
+
} catch {
|
|
120437
|
+
return done("write_failed", "an unexpected error; the file is as it was");
|
|
120438
|
+
}
|
|
120439
|
+
}
|
|
120440
|
+
async function writeTrust(input, real, done) {
|
|
120441
|
+
const { env } = input;
|
|
120442
|
+
const stopped = () => input.shouldStop?.() === true;
|
|
120443
|
+
if (stopped())
|
|
120444
|
+
return done("cancelled", "asked to stop before the write");
|
|
120445
|
+
if (claudeEnvTrue(env.CLAUDE_CODE_SANDBOXED)) {
|
|
120446
|
+
return done("sandboxed", "CLAUDE_CODE_SANDBOXED is on");
|
|
120447
|
+
}
|
|
120448
|
+
if (ignoresPersistedTrust(input)) {
|
|
120449
|
+
return done("ignored_trust", "the child reads no trust record");
|
|
120450
|
+
}
|
|
120451
|
+
if (statPathKind(real) !== "dir")
|
|
120452
|
+
return done("not_a_directory", "not an existing folder");
|
|
120453
|
+
if (real === dirname24(real))
|
|
120454
|
+
return done("filesystem_root", "never recorded");
|
|
120455
|
+
if (real === realOrResolved(env.HOME || homedir42()).normalize("NFC")) {
|
|
120456
|
+
return done("home_dir", "Claude Code keeps the home folder's trust for one session only");
|
|
120457
|
+
}
|
|
120458
|
+
const legacy = join61(claudeCodeConfigDir(env, real), ".config.json");
|
|
120459
|
+
if (statPathKind(legacy) !== undefined) {
|
|
120460
|
+
return done("legacy_config", `${legacy} exists, which Claude Code may read instead`);
|
|
120461
|
+
}
|
|
120462
|
+
const file = globalConfigFile(env, real);
|
|
120463
|
+
const lock = await takeConfigLock(`${file}.lock`, input.lockWaitMs ?? LOCK_WAIT_MS);
|
|
120464
|
+
if (lock === "lock_busy")
|
|
120465
|
+
return done("lock_busy", `${file}.lock is held or cannot be taken`);
|
|
120466
|
+
if (lock === "config_missing")
|
|
120467
|
+
return done("config_missing", `${dirname24(file)} does not exist`);
|
|
120468
|
+
if (lock === "config_unreadable") {
|
|
120469
|
+
return done("config_unreadable", `${file}.lock cannot be created`);
|
|
120470
|
+
}
|
|
120471
|
+
try {
|
|
120472
|
+
if (statPathKind(real) !== "dir") {
|
|
120473
|
+
return done("not_a_directory", "no longer an existing folder");
|
|
120474
|
+
}
|
|
120475
|
+
let target;
|
|
120476
|
+
try {
|
|
120477
|
+
target = realpathSync9(file);
|
|
120478
|
+
} catch (err) {
|
|
120479
|
+
if (errorCode2(err) === "ENOENT")
|
|
120480
|
+
return done("config_missing", `${file} does not exist`);
|
|
120481
|
+
return done("config_unreadable", `${file} cannot be read`);
|
|
120482
|
+
}
|
|
120483
|
+
const read = readBoundedText(target, input.maxConfigBytes ?? MAX_CONFIG_BYTES);
|
|
120484
|
+
if (read === "missing")
|
|
120485
|
+
return done("config_missing", `${file} does not exist`);
|
|
120486
|
+
if (read === "not_file")
|
|
120487
|
+
return done("config_unreadable", `${file} is not a regular file`);
|
|
120488
|
+
if (read === "oversize")
|
|
120489
|
+
return done("config_unreadable", `${file} is larger than claudish reads`);
|
|
120490
|
+
if (read === "unreadable")
|
|
120491
|
+
return done("config_unreadable", `${file} cannot be read`);
|
|
120492
|
+
const { text, mode } = read;
|
|
120493
|
+
let config;
|
|
120494
|
+
try {
|
|
120495
|
+
config = JSON.parse(text);
|
|
120496
|
+
} catch {
|
|
120497
|
+
return done("config_unreadable", `${file} is not valid JSON`);
|
|
120498
|
+
}
|
|
120499
|
+
if (!isPlainObject9(config))
|
|
120500
|
+
return done("config_not_object", `${file} is not a JSON object`);
|
|
120501
|
+
const projects = config.projects ?? {};
|
|
120502
|
+
if (!isPlainObject9(projects)) {
|
|
120503
|
+
return done("config_not_object", `${file} has a projects value that is not an object`);
|
|
120504
|
+
}
|
|
120505
|
+
const by = trustedBy(config, real);
|
|
120506
|
+
if (by !== null)
|
|
120507
|
+
return done("already_trusted", `by the record for ${by}`);
|
|
120508
|
+
const entry = projects[real];
|
|
120509
|
+
projects[real] = isPlainObject9(entry) ? { ...entry, hasTrustDialogAccepted: true } : { ...NEW_PROJECT_ENTRY };
|
|
120510
|
+
config.projects = projects;
|
|
120511
|
+
const next = `${JSON.stringify(config, null, 2)}
|
|
120512
|
+
`;
|
|
120513
|
+
if (stopped())
|
|
120514
|
+
return done("cancelled", "asked to stop before the write");
|
|
120515
|
+
lock.lease();
|
|
120516
|
+
if (!replaceFile(target, next, mode)) {
|
|
120517
|
+
return done("write_failed", `${file} could not be replaced`);
|
|
120518
|
+
}
|
|
120519
|
+
return done("written", `projects[${real}].hasTrustDialogAccepted in ${file}`);
|
|
120520
|
+
} finally {
|
|
120521
|
+
lock.release();
|
|
120522
|
+
}
|
|
120523
|
+
}
|
|
120524
|
+
var chmodSync8, closeSync18, fsyncSync4, lstatSync9, mkdirSync27, openSync18, readFileSync47, realpathSync9, renameSync10, rmdirSync3, utimesSync, NEW_PROJECT_ENTRY, LOCK_WAIT_MS = 3000, MAX_CONFIG_BYTES;
|
|
120525
|
+
var init_work_dir_trust = __esm(() => {
|
|
120526
|
+
init_claude_code_facts();
|
|
120527
|
+
init_claude_runner();
|
|
120528
|
+
init_logger();
|
|
120529
|
+
init_bounded_read();
|
|
120530
|
+
init_inherited_settings();
|
|
120531
|
+
init_plugin_handover();
|
|
120532
|
+
({
|
|
120533
|
+
chmodSync: chmodSync8,
|
|
120534
|
+
closeSync: closeSync18,
|
|
120535
|
+
fsyncSync: fsyncSync4,
|
|
120536
|
+
lstatSync: lstatSync9,
|
|
120537
|
+
mkdirSync: mkdirSync27,
|
|
120538
|
+
openSync: openSync18,
|
|
120539
|
+
readFileSync: readFileSync47,
|
|
120540
|
+
realpathSync: realpathSync9,
|
|
120541
|
+
renameSync: renameSync10,
|
|
120542
|
+
rmdirSync: rmdirSync3,
|
|
120543
|
+
utimesSync
|
|
120544
|
+
} = fs);
|
|
120545
|
+
NEW_PROJECT_ENTRY = {
|
|
120546
|
+
allowedTools: [],
|
|
120547
|
+
mcpContextUris: [],
|
|
120548
|
+
mcpServers: {},
|
|
120549
|
+
enabledMcpjsonServers: [],
|
|
120550
|
+
disabledMcpjsonServers: [],
|
|
120551
|
+
hasTrustDialogAccepted: true,
|
|
120552
|
+
hasClaudeMdExternalIncludesApproved: false,
|
|
120553
|
+
hasClaudeMdExternalIncludesWarningShown: false
|
|
120554
|
+
};
|
|
120555
|
+
MAX_CONFIG_BYTES = 64 * 1024 * 1024;
|
|
120556
|
+
});
|
|
120557
|
+
|
|
121024
120558
|
// src/mcp-session/session-manager.ts
|
|
121025
120559
|
import { randomUUID as randomUUID9 } from "crypto";
|
|
121026
120560
|
import {
|
|
121027
120561
|
appendFileSync as appendFileSync7,
|
|
121028
|
-
closeSync as
|
|
120562
|
+
closeSync as closeSync19,
|
|
121029
120563
|
createWriteStream,
|
|
121030
120564
|
existsSync as existsSync41,
|
|
121031
|
-
mkdirSync as
|
|
121032
|
-
openSync as
|
|
120565
|
+
mkdirSync as mkdirSync28,
|
|
120566
|
+
openSync as openSync19,
|
|
121033
120567
|
readFileSync as readFileSync48,
|
|
121034
|
-
readSync as
|
|
121035
|
-
renameSync as
|
|
121036
|
-
rmSync as
|
|
121037
|
-
statSync as
|
|
120568
|
+
readSync as readSync9,
|
|
120569
|
+
renameSync as renameSync11,
|
|
120570
|
+
rmSync as rmSync15,
|
|
120571
|
+
statSync as statSync24,
|
|
121038
120572
|
writeFileSync as writeFileSync23
|
|
121039
120573
|
} from "fs";
|
|
121040
|
-
import { join as
|
|
120574
|
+
import { join as join62, resolve as resolve10, sep as sep3 } from "path";
|
|
121041
120575
|
function normaliseTimeoutSeconds(raw) {
|
|
121042
120576
|
const n = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
|
|
121043
120577
|
if (typeof n !== "number" || !Number.isFinite(n))
|
|
@@ -121057,7 +120591,7 @@ function pluginRecordOf(handover) {
|
|
|
121057
120591
|
const { plugins, outcome } = handover;
|
|
121058
120592
|
return {
|
|
121059
120593
|
...plugins.length > 0 ? { inheritedPlugins: plugins.map(({ id, version }) => ({ id, version })) } : {},
|
|
121060
|
-
|
|
120594
|
+
pluginHandover: outcome
|
|
121061
120595
|
};
|
|
121062
120596
|
}
|
|
121063
120597
|
function pluginDirFlags(handover) {
|
|
@@ -121065,9 +120599,9 @@ function pluginDirFlags(handover) {
|
|
|
121065
120599
|
}
|
|
121066
120600
|
function writeInheritedFiles(sessionDir, layer, mcp) {
|
|
121067
120601
|
if (layer)
|
|
121068
|
-
writePrivateJson(
|
|
120602
|
+
writePrivateJson(join62(sessionDir, INHERITED_SETTINGS), layer);
|
|
121069
120603
|
if (mcp)
|
|
121070
|
-
writePrivateJson(
|
|
120604
|
+
writePrivateJson(join62(sessionDir, INHERITED_MCP), mcp);
|
|
121071
120605
|
}
|
|
121072
120606
|
function sessionEventFor(snap) {
|
|
121073
120607
|
switch (snap.state) {
|
|
@@ -121160,7 +120694,7 @@ function toMetaRecord(info, cwd) {
|
|
|
121160
120694
|
function writeJsonAtomic(path, value) {
|
|
121161
120695
|
const tmp = `${path}.tmp`;
|
|
121162
120696
|
writeFileSync23(tmp, JSON.stringify(value, null, 2), "utf-8");
|
|
121163
|
-
|
|
120697
|
+
renameSync11(tmp, path);
|
|
121164
120698
|
}
|
|
121165
120699
|
function anomalyKey(a) {
|
|
121166
120700
|
const at = a.lastIndexOf(" \xD7");
|
|
@@ -121169,21 +120703,21 @@ function anomalyKey(a) {
|
|
|
121169
120703
|
function readTailText(path, maxBytes) {
|
|
121170
120704
|
let fd = null;
|
|
121171
120705
|
try {
|
|
121172
|
-
const size =
|
|
120706
|
+
const size = statSync24(path).size;
|
|
121173
120707
|
if (size === 0)
|
|
121174
120708
|
return { text: "", truncated: false };
|
|
121175
120709
|
const start = Math.max(0, size - maxBytes);
|
|
121176
120710
|
const length = size - start;
|
|
121177
120711
|
const buf = Buffer.alloc(length);
|
|
121178
|
-
fd =
|
|
121179
|
-
|
|
120712
|
+
fd = openSync19(path, "r");
|
|
120713
|
+
readSync9(fd, buf, 0, length, start);
|
|
121180
120714
|
return { text: buf.toString("utf-8"), truncated: start > 0 };
|
|
121181
120715
|
} catch {
|
|
121182
120716
|
return null;
|
|
121183
120717
|
} finally {
|
|
121184
120718
|
if (fd !== null) {
|
|
121185
120719
|
try {
|
|
121186
|
-
|
|
120720
|
+
closeSync19(fd);
|
|
121187
120721
|
} catch {}
|
|
121188
120722
|
}
|
|
121189
120723
|
}
|
|
@@ -121200,7 +120734,7 @@ function readTailLines2(path, maxBytes) {
|
|
|
121200
120734
|
}
|
|
121201
120735
|
function fileSize2(path) {
|
|
121202
120736
|
try {
|
|
121203
|
-
return
|
|
120737
|
+
return statSync24(path).size;
|
|
121204
120738
|
} catch {
|
|
121205
120739
|
return 0;
|
|
121206
120740
|
}
|
|
@@ -121235,7 +120769,7 @@ function dropLeadingFragment(tail) {
|
|
|
121235
120769
|
return firstBreak === -1 ? tail.text : tail.text.slice(firstBreak + 1);
|
|
121236
120770
|
}
|
|
121237
120771
|
function diskAccounting(sessionDir) {
|
|
121238
|
-
const stats = readTokenStatsAt(
|
|
120772
|
+
const stats = readTokenStatsAt(join62(sessionDir, "tokens.json"));
|
|
121239
120773
|
return {
|
|
121240
120774
|
tokensIn: stats?.billed_input_tokens ?? null,
|
|
121241
120775
|
tokensOut: stats?.output_tokens ?? null,
|
|
@@ -121295,7 +120829,6 @@ class SessionManager {
|
|
|
121295
120829
|
paneTimings;
|
|
121296
120830
|
starting = 0;
|
|
121297
120831
|
pendingStarts = new Set;
|
|
121298
|
-
startAbort = new AbortController;
|
|
121299
120832
|
shuttingDown = false;
|
|
121300
120833
|
_hostPid;
|
|
121301
120834
|
_launcherPid;
|
|
@@ -121308,10 +120841,6 @@ class SessionManager {
|
|
|
121308
120841
|
feed;
|
|
121309
120842
|
claims;
|
|
121310
120843
|
managedPaths;
|
|
121311
|
-
pluginProbe;
|
|
121312
|
-
pluginProbeTimeoutMs;
|
|
121313
|
-
readHostLaunch;
|
|
121314
|
-
pluginPolicyPlatform;
|
|
121315
120844
|
constructor(options) {
|
|
121316
120845
|
const host = options?.hostPid !== undefined ? { hostPid: options.hostPid } : hostPidFrom(process.env, process.ppid);
|
|
121317
120846
|
this._hostPid = host.hostPid;
|
|
@@ -121329,10 +120858,6 @@ class SessionManager {
|
|
|
121329
120858
|
this.feed = options?.feed;
|
|
121330
120859
|
this.claims = options?.claims;
|
|
121331
120860
|
this.managedPaths = options?.managedPaths ?? realManagedPaths();
|
|
121332
|
-
this.pluginProbe = options?.pluginProbe;
|
|
121333
|
-
this.pluginProbeTimeoutMs = options?.pluginProbeTimeoutMs;
|
|
121334
|
-
this.readHostLaunch = options?.readHostLaunch ?? readHostLaunch;
|
|
121335
|
-
this.pluginPolicyPlatform = options?.pluginPolicyPlatform;
|
|
121336
120861
|
}
|
|
121337
120862
|
hookEngine() {
|
|
121338
120863
|
if (!this.hookEnginePromise)
|
|
@@ -121346,14 +120871,14 @@ class SessionManager {
|
|
|
121346
120871
|
return this._launcherPid;
|
|
121347
120872
|
}
|
|
121348
120873
|
recordTeamRun(opts) {
|
|
121349
|
-
|
|
120874
|
+
mkdirSync28(this.sessionsDir, { recursive: true });
|
|
121350
120875
|
let id = "";
|
|
121351
120876
|
let dir = "";
|
|
121352
120877
|
for (let attempt = 0;; attempt++) {
|
|
121353
120878
|
id = `team-${randomUUID9().replace(/-/g, "").slice(0, 8)}`;
|
|
121354
|
-
dir =
|
|
120879
|
+
dir = join62(this.sessionsDir, id);
|
|
121355
120880
|
try {
|
|
121356
|
-
|
|
120881
|
+
mkdirSync28(dir);
|
|
121357
120882
|
break;
|
|
121358
120883
|
} catch (err) {
|
|
121359
120884
|
if (err?.code !== "EEXIST" || attempt >= 4)
|
|
@@ -121383,9 +120908,9 @@ class SessionManager {
|
|
|
121383
120908
|
if (dir === null)
|
|
121384
120909
|
throw new Error("not a record id");
|
|
121385
120910
|
const completedAt = new Date().toISOString();
|
|
121386
|
-
const startedAt = this.teamRunStarts.get(record) ?? metaString(readJsonObject(
|
|
120911
|
+
const startedAt = this.teamRunStarts.get(record) ?? metaString(readJsonObject(join62(dir, "spawn.json"), META_READ_LIMIT)?.startedAt) ?? completedAt;
|
|
121387
120912
|
const elapsedMs = Date.parse(completedAt) - Date.parse(startedAt);
|
|
121388
|
-
writeJsonAtomic(
|
|
120913
|
+
writeJsonAtomic(join62(dir, "meta.json"), {
|
|
121389
120914
|
kind: "team",
|
|
121390
120915
|
status: outcome.status,
|
|
121391
120916
|
startedAt,
|
|
@@ -121417,7 +120942,7 @@ class SessionManager {
|
|
|
121417
120942
|
startedAt,
|
|
121418
120943
|
...rest
|
|
121419
120944
|
};
|
|
121420
|
-
writeJsonAtomic(
|
|
120945
|
+
writeJsonAtomic(join62(dir, "spawn.json"), body);
|
|
121421
120946
|
}
|
|
121422
120947
|
refuseWhileShuttingDown() {
|
|
121423
120948
|
if (this.shuttingDown)
|
|
@@ -121445,6 +120970,14 @@ class SessionManager {
|
|
|
121445
120970
|
}
|
|
121446
120971
|
const parentEnv = opts.parentEnv ?? this.parentEnv;
|
|
121447
120972
|
const childCwd = opts.cwd ?? process.cwd();
|
|
120973
|
+
const plugins = inheritedPluginsFor({
|
|
120974
|
+
setupReal,
|
|
120975
|
+
childCwd,
|
|
120976
|
+
layer: inherited.layer,
|
|
120977
|
+
childFlags: callerFlags,
|
|
120978
|
+
env: parentEnv,
|
|
120979
|
+
managed: this.managedPaths
|
|
120980
|
+
});
|
|
121448
120981
|
const inheritedMcp = inheritedMcpFor(setupReal, childCwd, inherited.layer, callerFlags, parentEnv, this.managedPaths);
|
|
121449
120982
|
this.starting++;
|
|
121450
120983
|
let counted = true;
|
|
@@ -121453,7 +120986,6 @@ class SessionManager {
|
|
|
121453
120986
|
this.starting--;
|
|
121454
120987
|
counted = false;
|
|
121455
120988
|
};
|
|
121456
|
-
const { signal } = this.startAbort;
|
|
121457
120989
|
let releaseStart = () => {};
|
|
121458
120990
|
const tracked = new Promise((done) => {
|
|
121459
120991
|
releaseStart = done;
|
|
@@ -121462,35 +120994,27 @@ class SessionManager {
|
|
|
121462
120994
|
try {
|
|
121463
120995
|
await assertMagmuxAvailable(this.magmuxBinary);
|
|
121464
120996
|
this.refuseWhileShuttingDown();
|
|
121465
|
-
const plugins = await inheritedPluginsFor({
|
|
121466
|
-
setupReal,
|
|
121467
|
-
childCwd,
|
|
121468
|
-
layer: inherited.layer,
|
|
121469
|
-
childFlags: callerFlags,
|
|
121470
|
-
env: parentEnv,
|
|
121471
|
-
managed: this.managedPaths,
|
|
121472
|
-
hostPid: this._hostPid,
|
|
121473
|
-
readHostLaunch: this.readHostLaunch,
|
|
121474
|
-
policyPlatform: this.pluginPolicyPlatform ?? hostPolicyPlatform(parentEnv),
|
|
121475
|
-
runner: this.pluginProbe,
|
|
121476
|
-
timeoutMs: this.pluginProbeTimeoutMs,
|
|
121477
|
-
signal
|
|
121478
|
-
});
|
|
121479
|
-
this.refuseWhileShuttingDown();
|
|
121480
120997
|
reservePanes(1, sockRootFor(parentEnv));
|
|
121481
120998
|
let entry;
|
|
121482
120999
|
try {
|
|
121483
|
-
|
|
121000
|
+
const workDirTrust = opts.cwd !== undefined ? await ensureWorkDirTrust({
|
|
121001
|
+
workDir: opts.cwd,
|
|
121002
|
+
env: parentEnv,
|
|
121003
|
+
childFlags: callerFlags,
|
|
121004
|
+
shouldStop: () => this.shuttingDown
|
|
121005
|
+
}) : undefined;
|
|
121006
|
+
this.refuseWhileShuttingDown();
|
|
121007
|
+
entry = this.recordSession(opts, inherited.layer, inheritedMcp, plugins, workDirTrust);
|
|
121484
121008
|
} catch (err) {
|
|
121485
121009
|
releasePaneReservations(1);
|
|
121486
121010
|
throw err;
|
|
121487
121011
|
}
|
|
121488
121012
|
if (inherited.layer) {
|
|
121489
|
-
flags = [...inherited.restFlags, "--settings",
|
|
121013
|
+
flags = [...inherited.restFlags, "--settings", join62(entry.sessionDir, INHERITED_SETTINGS)];
|
|
121490
121014
|
}
|
|
121491
121015
|
flags = [...pluginDirFlags(plugins), ...flags];
|
|
121492
121016
|
if (inheritedMcp)
|
|
121493
|
-
flags = ["--mcp-config",
|
|
121017
|
+
flags = ["--mcp-config", join62(entry.sessionDir, INHERITED_MCP), ...flags];
|
|
121494
121018
|
this.sessions.set(entry.info.sessionId, entry);
|
|
121495
121019
|
uncount();
|
|
121496
121020
|
await this.startPane(entry, opts, { flags, readAvailable, parentEnv });
|
|
@@ -121501,16 +121025,16 @@ class SessionManager {
|
|
|
121501
121025
|
uncount();
|
|
121502
121026
|
}
|
|
121503
121027
|
}
|
|
121504
|
-
recordSession(opts, inheritedLayer, inheritedMcp, plugins) {
|
|
121028
|
+
recordSession(opts, inheritedLayer, inheritedMcp, plugins, workDirTrust) {
|
|
121505
121029
|
const sessionId = opts.sessionId ?? randomUUID9().slice(0, 8);
|
|
121506
121030
|
const claudeSessionId = randomUUID9();
|
|
121507
121031
|
const timeout = normaliseTimeoutSeconds(opts.timeoutSeconds);
|
|
121508
121032
|
const agentRequested = requestedAgentOf(opts.claudishFlags ?? []);
|
|
121509
121033
|
const startedAt = new Date().toISOString();
|
|
121510
|
-
const sessionDir = opts.sessionDir ??
|
|
121511
|
-
|
|
121034
|
+
const sessionDir = opts.sessionDir ?? join62(this.sessionsDir, sessionId);
|
|
121035
|
+
mkdirSync28(sessionDir, { recursive: true });
|
|
121512
121036
|
if (opts.prompt)
|
|
121513
|
-
writeFileSync23(
|
|
121037
|
+
writeFileSync23(join62(sessionDir, "prompt.md"), opts.prompt, "utf-8");
|
|
121514
121038
|
this.writeSpawnRecord(sessionDir, {
|
|
121515
121039
|
kind: "session",
|
|
121516
121040
|
sessionId,
|
|
@@ -121522,6 +121046,7 @@ class SessionManager {
|
|
|
121522
121046
|
...opts.setupFrom ? { setupFrom: opts.setupFrom } : {},
|
|
121523
121047
|
inheritedMcpServers: inheritedMcp ? Object.keys(inheritedMcp.mcpServers) : undefined,
|
|
121524
121048
|
...pluginRecordOf(plugins),
|
|
121049
|
+
...workDirTrust ? { workDirTrust } : {},
|
|
121525
121050
|
...agentRequested ? { agentRequested } : {},
|
|
121526
121051
|
taskType: opts.taskType
|
|
121527
121052
|
});
|
|
@@ -121529,7 +121054,7 @@ class SessionManager {
|
|
|
121529
121054
|
const cwd = opts.cwd ?? process.cwd();
|
|
121530
121055
|
const parentEnv = opts.parentEnv ?? this.parentEnv;
|
|
121531
121056
|
const spawnModel = opts.spawnModel ?? null;
|
|
121532
|
-
const tokenFile = opts.tokenFile ??
|
|
121057
|
+
const tokenFile = opts.tokenFile ?? join62(sessionDir, "tokens.json");
|
|
121533
121058
|
return {
|
|
121534
121059
|
info: {
|
|
121535
121060
|
sessionId,
|
|
@@ -121568,18 +121093,18 @@ class SessionManager {
|
|
|
121568
121093
|
},
|
|
121569
121094
|
session: null,
|
|
121570
121095
|
scrollback: new ScrollbackBuffer(this.scrollbackCapacity),
|
|
121571
|
-
outputLogStream: createWriteStream(
|
|
121096
|
+
outputLogStream: createWriteStream(join62(sessionDir, "output.log")),
|
|
121572
121097
|
sessionDir,
|
|
121573
121098
|
cwd,
|
|
121574
121099
|
tokenFile,
|
|
121575
|
-
eventLogPath:
|
|
121100
|
+
eventLogPath: join62(sessionDir, "events.jsonl"),
|
|
121576
121101
|
eventLogBytes: 0,
|
|
121577
|
-
upstreamErrorLogPath:
|
|
121102
|
+
upstreamErrorLogPath: join62(sessionDir, "upstream-errors.jsonl"),
|
|
121578
121103
|
eventRing: [],
|
|
121579
121104
|
proseBytes: 0,
|
|
121580
121105
|
answeredTurns: new Map,
|
|
121581
121106
|
inboxPath: null,
|
|
121582
|
-
waitLogPath:
|
|
121107
|
+
waitLogPath: join62(sessionDir, "waits.jsonl"),
|
|
121583
121108
|
waitLogBytes: 0,
|
|
121584
121109
|
waitSince: null,
|
|
121585
121110
|
ended: false,
|
|
@@ -121687,7 +121212,7 @@ class SessionManager {
|
|
|
121687
121212
|
if (!entry.inboxPath)
|
|
121688
121213
|
return;
|
|
121689
121214
|
try {
|
|
121690
|
-
|
|
121215
|
+
rmSync15(entry.inboxPath, { force: true });
|
|
121691
121216
|
} catch {}
|
|
121692
121217
|
}
|
|
121693
121218
|
failNeverSpawned(entry, err) {
|
|
@@ -121791,7 +121316,7 @@ class SessionManager {
|
|
|
121791
121316
|
try {
|
|
121792
121317
|
const text = screenLines.join(`
|
|
121793
121318
|
`).replace(/\s+$/, "");
|
|
121794
|
-
writeFileSync23(
|
|
121319
|
+
writeFileSync23(join62(entry.sessionDir, "screen.txt"), `${redactSecrets(text)}
|
|
121795
121320
|
`, "utf-8");
|
|
121796
121321
|
} catch {}
|
|
121797
121322
|
}
|
|
@@ -121805,7 +121330,7 @@ class SessionManager {
|
|
|
121805
121330
|
entry.waitSince = null;
|
|
121806
121331
|
}
|
|
121807
121332
|
try {
|
|
121808
|
-
writeJsonAtomic(
|
|
121333
|
+
writeJsonAtomic(join62(entry.sessionDir, "meta.json"), toMetaRecord(entry.info, entry.cwd));
|
|
121809
121334
|
} catch (err) {
|
|
121810
121335
|
process.stderr.write(`[claudish] session ${entry.info.sessionId}: could not write meta.json: ` + `${err instanceof Error ? err.message : String(err)}
|
|
121811
121336
|
`);
|
|
@@ -122070,13 +121595,13 @@ class SessionManager {
|
|
|
122070
121595
|
if (sessionDir === null)
|
|
122071
121596
|
return null;
|
|
122072
121597
|
try {
|
|
122073
|
-
if (!
|
|
121598
|
+
if (!statSync24(sessionDir).isDirectory())
|
|
122074
121599
|
return null;
|
|
122075
121600
|
} catch {
|
|
122076
121601
|
return null;
|
|
122077
121602
|
}
|
|
122078
|
-
const spawnPath =
|
|
122079
|
-
const metaPath =
|
|
121603
|
+
const spawnPath = join62(sessionDir, "spawn.json");
|
|
121604
|
+
const metaPath = join62(sessionDir, "meta.json");
|
|
122080
121605
|
const spawnRecord = readJsonObject(spawnPath, META_READ_LIMIT);
|
|
122081
121606
|
if (spawnRecord?.kind === "team")
|
|
122082
121607
|
return null;
|
|
@@ -122167,11 +121692,10 @@ class SessionManager {
|
|
|
122167
121692
|
if (!record)
|
|
122168
121693
|
return null;
|
|
122169
121694
|
const info = record.info;
|
|
122170
|
-
return sessionRowOf(info, upstreamRecordsFor(info,
|
|
121695
|
+
return sessionRowOf(info, upstreamRecordsFor(info, join62(record.sessionDir, "upstream-errors.jsonl")));
|
|
122171
121696
|
}
|
|
122172
121697
|
async shutdownAll() {
|
|
122173
121698
|
this.shuttingDown = true;
|
|
122174
|
-
this.startAbort.abort();
|
|
122175
121699
|
await Promise.all([...this.pendingStarts]);
|
|
122176
121700
|
const pending = [];
|
|
122177
121701
|
for (const entry of this.sessions.values()) {
|
|
@@ -122200,7 +121724,7 @@ class SessionManager {
|
|
|
122200
121724
|
return null;
|
|
122201
121725
|
const root = resolve10(this.sessionsDir);
|
|
122202
121726
|
const dir = resolve10(root, sessionId);
|
|
122203
|
-
if (dir !==
|
|
121727
|
+
if (dir !== join62(root, sessionId))
|
|
122204
121728
|
return null;
|
|
122205
121729
|
if (!dir.startsWith(root + sep3))
|
|
122206
121730
|
return null;
|
|
@@ -122212,17 +121736,17 @@ class SessionManager {
|
|
|
122212
121736
|
return null;
|
|
122213
121737
|
let dirMtimeMs;
|
|
122214
121738
|
try {
|
|
122215
|
-
const stat =
|
|
121739
|
+
const stat = statSync24(sessionDir);
|
|
122216
121740
|
if (!stat.isDirectory())
|
|
122217
121741
|
return null;
|
|
122218
121742
|
dirMtimeMs = stat.mtimeMs;
|
|
122219
121743
|
} catch {
|
|
122220
121744
|
return null;
|
|
122221
121745
|
}
|
|
122222
|
-
const spawnRecord = readJsonObject(
|
|
121746
|
+
const spawnRecord = readJsonObject(join62(sessionDir, "spawn.json"), META_READ_LIMIT);
|
|
122223
121747
|
if (spawnRecord?.kind === "team")
|
|
122224
121748
|
return null;
|
|
122225
|
-
const meta = readJsonObject(
|
|
121749
|
+
const meta = readJsonObject(join62(sessionDir, "meta.json"), META_READ_LIMIT);
|
|
122226
121750
|
if (meta?.kind === "team")
|
|
122227
121751
|
return null;
|
|
122228
121752
|
const partial = meta === null;
|
|
@@ -122244,7 +121768,7 @@ class SessionManager {
|
|
|
122244
121768
|
return stored;
|
|
122245
121769
|
}
|
|
122246
121770
|
diskOutput(record, tailLines) {
|
|
122247
|
-
const tail = readTailText(
|
|
121771
|
+
const tail = readTailText(join62(record.sessionDir, "output.log"), OUTPUT_TAIL_BYTES);
|
|
122248
121772
|
const buffer = new ScrollbackBuffer(this.scrollbackCapacity);
|
|
122249
121773
|
if (tail?.text)
|
|
122250
121774
|
buffer.append(dropLeadingFragment(tail));
|
|
@@ -122264,12 +121788,12 @@ class SessionManager {
|
|
|
122264
121788
|
}
|
|
122265
121789
|
diskDiagnostics(record, limit) {
|
|
122266
121790
|
const { sessionDir, info } = record;
|
|
122267
|
-
const eventLogPath =
|
|
122268
|
-
const upstreamErrorLogPath =
|
|
122269
|
-
const outputLogPath =
|
|
121791
|
+
const eventLogPath = join62(sessionDir, "events.jsonl");
|
|
121792
|
+
const upstreamErrorLogPath = join62(sessionDir, "upstream-errors.jsonl");
|
|
121793
|
+
const outputLogPath = join62(sessionDir, "output.log");
|
|
122270
121794
|
const events = readTailLines2(eventLogPath, EVENT_TAIL_BYTES);
|
|
122271
121795
|
const outputTail = readTailText(outputLogPath, OUTPUT_TAIL_BYTES);
|
|
122272
|
-
const screen = readTailText(
|
|
121796
|
+
const screen = readTailText(join62(sessionDir, "screen.txt"), SCREEN_READ_BYTES);
|
|
122273
121797
|
return {
|
|
122274
121798
|
sessionId: info.sessionId,
|
|
122275
121799
|
state: info.state,
|
|
@@ -122541,11 +122065,11 @@ var init_session_manager = __esm(() => {
|
|
|
122541
122065
|
init_token_watch();
|
|
122542
122066
|
init_view_claims();
|
|
122543
122067
|
init_home_dir();
|
|
122544
|
-
init_host_launch();
|
|
122545
122068
|
init_inherited_settings();
|
|
122546
122069
|
init_parent_session();
|
|
122547
|
-
|
|
122070
|
+
init_plugin_handover();
|
|
122548
122071
|
init_scrollback_buffer();
|
|
122072
|
+
init_work_dir_trust();
|
|
122549
122073
|
TERMINAL_RETENTION_MS = 30 * 60000;
|
|
122550
122074
|
EVENT_LOG_LIMIT = 4 * 1024 * 1024;
|
|
122551
122075
|
WAIT_LOG_LIMIT = 1024 * 1024;
|
|
@@ -122577,8 +122101,8 @@ var init_session_manager = __esm(() => {
|
|
|
122577
122101
|
});
|
|
122578
122102
|
|
|
122579
122103
|
// src/view/history.ts
|
|
122580
|
-
import { closeSync as
|
|
122581
|
-
import { join as
|
|
122104
|
+
import { closeSync as closeSync20, openSync as openSync20, readSync as readSync10, readdirSync as readdirSync13, statSync as statSync25 } from "fs";
|
|
122105
|
+
import { join as join63 } from "path";
|
|
122582
122106
|
function finishedDetail(promptSummary) {
|
|
122583
122107
|
return {
|
|
122584
122108
|
prompt_summary: promptSummary,
|
|
@@ -122599,28 +122123,28 @@ function readJson(path) {
|
|
|
122599
122123
|
function readHead(path, bytes) {
|
|
122600
122124
|
let fd = null;
|
|
122601
122125
|
try {
|
|
122602
|
-
fd =
|
|
122126
|
+
fd = openSync20(path, "r");
|
|
122603
122127
|
const buf = Buffer.alloc(bytes);
|
|
122604
|
-
const n =
|
|
122128
|
+
const n = readSync10(fd, buf, 0, bytes, 0);
|
|
122605
122129
|
return buf.subarray(0, n).toString("utf8");
|
|
122606
122130
|
} catch {
|
|
122607
122131
|
return null;
|
|
122608
122132
|
} finally {
|
|
122609
122133
|
if (fd !== null)
|
|
122610
|
-
|
|
122134
|
+
closeSync20(fd);
|
|
122611
122135
|
}
|
|
122612
122136
|
}
|
|
122613
122137
|
function runDirs(sessionsDir) {
|
|
122614
122138
|
let names;
|
|
122615
122139
|
try {
|
|
122616
|
-
names =
|
|
122140
|
+
names = readdirSync13(sessionsDir);
|
|
122617
122141
|
} catch {
|
|
122618
122142
|
return [];
|
|
122619
122143
|
}
|
|
122620
122144
|
const dated = [];
|
|
122621
122145
|
for (const name of names) {
|
|
122622
122146
|
try {
|
|
122623
|
-
const st =
|
|
122147
|
+
const st = statSync25(join63(sessionsDir, name));
|
|
122624
122148
|
if (st.isDirectory())
|
|
122625
122149
|
dated.push({ name, mtimeMs: st.mtimeMs });
|
|
122626
122150
|
} catch {}
|
|
@@ -122657,7 +122181,7 @@ function teamItems(spawn) {
|
|
|
122657
122181
|
return { runId: run.run_id, items };
|
|
122658
122182
|
}
|
|
122659
122183
|
function runItems(sessions, dir, name, seenRuns) {
|
|
122660
|
-
const spawn = readJson(
|
|
122184
|
+
const spawn = readJson(join63(dir, "spawn.json"));
|
|
122661
122185
|
if (spawn?.kind === "team" || name.startsWith("team-")) {
|
|
122662
122186
|
const team = spawn ? teamItems(spawn) : null;
|
|
122663
122187
|
if (!team || seenRuns.has(team.runId) || team.items.length === 0)
|
|
@@ -122665,12 +122189,12 @@ function runItems(sessions, dir, name, seenRuns) {
|
|
|
122665
122189
|
seenRuns.add(team.runId);
|
|
122666
122190
|
return team.items;
|
|
122667
122191
|
}
|
|
122668
|
-
if (!spawn && readJson(
|
|
122192
|
+
if (!spawn && readJson(join63(dir, "meta.json")) === null)
|
|
122669
122193
|
return null;
|
|
122670
122194
|
const row = sessions.diskSessionRow(name);
|
|
122671
122195
|
if (!row)
|
|
122672
122196
|
return null;
|
|
122673
|
-
const prompt = readHead(
|
|
122197
|
+
const prompt = readHead(join63(dir, "prompt.md"), PROMPT_HEAD_BYTES);
|
|
122674
122198
|
return [sessionItem(row, prompt ? promptSummaryOf(prompt) : null)];
|
|
122675
122199
|
}
|
|
122676
122200
|
function readHistory(o = {}) {
|
|
@@ -122683,7 +122207,7 @@ function readHistory(o = {}) {
|
|
|
122683
122207
|
for (const name of runDirs(sessionsDir)) {
|
|
122684
122208
|
if (runs >= limit)
|
|
122685
122209
|
break;
|
|
122686
|
-
const items = runItems(sessions,
|
|
122210
|
+
const items = runItems(sessions, join63(sessionsDir, name), name, seenRuns);
|
|
122687
122211
|
if (!items)
|
|
122688
122212
|
continue;
|
|
122689
122213
|
out.push(...items);
|
|
@@ -122698,15 +122222,15 @@ function findRecordedItem(target, o = {}) {
|
|
|
122698
122222
|
const id = target.slice(2);
|
|
122699
122223
|
if (!id || id.includes("/") || id.startsWith("."))
|
|
122700
122224
|
return null;
|
|
122701
|
-
const items = runItems(sessions,
|
|
122225
|
+
const items = runItems(sessions, join63(sessionsDir, id), id, new Set);
|
|
122702
122226
|
return items?.find((i) => i.target === target) ?? null;
|
|
122703
122227
|
}
|
|
122704
122228
|
if (!target.startsWith("t:"))
|
|
122705
122229
|
return null;
|
|
122706
122230
|
const seenRuns = new Set;
|
|
122707
122231
|
for (const name of runDirs(sessionsDir)) {
|
|
122708
|
-
const dir =
|
|
122709
|
-
if (!name.startsWith("team-") && readJson(
|
|
122232
|
+
const dir = join63(sessionsDir, name);
|
|
122233
|
+
if (!name.startsWith("team-") && readJson(join63(dir, "spawn.json"))?.kind !== "team")
|
|
122710
122234
|
continue;
|
|
122711
122235
|
const found = runItems(sessions, dir, name, seenRuns)?.find((i) => i.target === target);
|
|
122712
122236
|
if (found)
|
|
@@ -122758,7 +122282,7 @@ class LineBuffer {
|
|
|
122758
122282
|
|
|
122759
122283
|
// src/view/view-client.ts
|
|
122760
122284
|
import { connect } from "net";
|
|
122761
|
-
import { basename as
|
|
122285
|
+
import { basename as basename11 } from "path";
|
|
122762
122286
|
function dial(path) {
|
|
122763
122287
|
return new Promise((resolve, reject) => {
|
|
122764
122288
|
const sock = connect(path);
|
|
@@ -122908,7 +122432,7 @@ class ViewClient {
|
|
|
122908
122432
|
}
|
|
122909
122433
|
async redial() {
|
|
122910
122434
|
let wait = RECONNECT_FIRST_MS;
|
|
122911
|
-
const name =
|
|
122435
|
+
const name = basename11(this.path);
|
|
122912
122436
|
while (!this.ended) {
|
|
122913
122437
|
if (!endpointOwnerAlive(name, await readProcessTableAsync())) {
|
|
122914
122438
|
this.end("server_gone");
|
|
@@ -122957,10 +122481,10 @@ var init_view_client = __esm(() => {
|
|
|
122957
122481
|
});
|
|
122958
122482
|
|
|
122959
122483
|
// src/view/feed-relay.ts
|
|
122960
|
-
import { chmodSync as
|
|
122961
|
-
import { dirname as
|
|
122484
|
+
import { chmodSync as chmodSync9, readFileSync as readFileSync49, renameSync as renameSync12, rmSync as rmSync16, writeFileSync as writeFileSync24 } from "fs";
|
|
122485
|
+
import { dirname as dirname25, join as join64 } from "path";
|
|
122962
122486
|
function defaultFeedPath(root) {
|
|
122963
|
-
return
|
|
122487
|
+
return join64(root, FEED_DIR, FEED_FILE);
|
|
122964
122488
|
}
|
|
122965
122489
|
function ownStamp() {
|
|
122966
122490
|
return {
|
|
@@ -123028,7 +122552,7 @@ class FeedRelay {
|
|
|
123028
122552
|
}
|
|
123029
122553
|
async start() {
|
|
123030
122554
|
ensureSockRoot(this.o.root);
|
|
123031
|
-
if (
|
|
122555
|
+
if (dirname25(this.path) === join64(this.o.root, FEED_DIR))
|
|
123032
122556
|
ensurePrivateSubdir(this.o.root, FEED_DIR);
|
|
123033
122557
|
const other = readFeedStamp(this.path);
|
|
123034
122558
|
if (other && !this.isOwn(other) && stampAlive(other, await readProcessTableAsync()))
|
|
@@ -123055,10 +122579,10 @@ class FeedRelay {
|
|
|
123055
122579
|
for (const s of this.servers.values())
|
|
123056
122580
|
s.conn.close();
|
|
123057
122581
|
this.servers.clear();
|
|
123058
|
-
|
|
122582
|
+
rmSync16(this.tmpPath(), { force: true });
|
|
123059
122583
|
const stamp = readFeedStamp(this.path);
|
|
123060
122584
|
if (stamp && this.isOwn(stamp))
|
|
123061
|
-
|
|
122585
|
+
rmSync16(this.path, { force: true });
|
|
123062
122586
|
}
|
|
123063
122587
|
nextWrite() {
|
|
123064
122588
|
return new Promise((resolve) => {
|
|
@@ -123231,8 +122755,8 @@ class FeedRelay {
|
|
|
123231
122755
|
const tmp = this.tmpPath();
|
|
123232
122756
|
writeFileSync24(tmp, `${JSON.stringify(file)}
|
|
123233
122757
|
`, { mode: 384 });
|
|
123234
|
-
|
|
123235
|
-
|
|
122758
|
+
chmodSync9(tmp, 384);
|
|
122759
|
+
renameSync12(tmp, this.path);
|
|
123236
122760
|
this.lastKey = key;
|
|
123237
122761
|
this.lastWriteAt = this.now();
|
|
123238
122762
|
this.writes += 1;
|
|
@@ -123284,16 +122808,16 @@ import {
|
|
|
123284
122808
|
constants as constants6,
|
|
123285
122809
|
accessSync as accessSync4,
|
|
123286
122810
|
existsSync as existsSync42,
|
|
123287
|
-
lstatSync as
|
|
122811
|
+
lstatSync as lstatSync10,
|
|
123288
122812
|
readFileSync as readFileSync50,
|
|
123289
|
-
readdirSync as
|
|
123290
|
-
renameSync as
|
|
123291
|
-
rmSync as
|
|
123292
|
-
rmdirSync as
|
|
123293
|
-
unlinkSync as
|
|
122813
|
+
readdirSync as readdirSync14,
|
|
122814
|
+
renameSync as renameSync13,
|
|
122815
|
+
rmSync as rmSync17,
|
|
122816
|
+
rmdirSync as rmdirSync4,
|
|
122817
|
+
unlinkSync as unlinkSync13,
|
|
123294
122818
|
writeFileSync as writeFileSync25
|
|
123295
122819
|
} from "fs";
|
|
123296
|
-
import { dirname as
|
|
122820
|
+
import { dirname as dirname26, join as join65 } from "path";
|
|
123297
122821
|
function ownerStartOfSelf() {
|
|
123298
122822
|
if (ownStart)
|
|
123299
122823
|
return ownStart;
|
|
@@ -123314,14 +122838,14 @@ function ownerAlive(owner, table) {
|
|
|
123314
122838
|
return !minted || startedAt(row, minted.startMs);
|
|
123315
122839
|
}
|
|
123316
122840
|
function recordsDir(root) {
|
|
123317
|
-
return
|
|
122841
|
+
return join65(root, "panes");
|
|
123318
122842
|
}
|
|
123319
122843
|
function writeRecord(root, rec) {
|
|
123320
122844
|
const p = recordPathOf(root, rec.paneId);
|
|
123321
122845
|
const tmp = `${p}.tmp-${process.pid}`;
|
|
123322
122846
|
writeFileSync25(tmp, `${JSON.stringify(rec)}
|
|
123323
122847
|
`, { mode: 384 });
|
|
123324
|
-
|
|
122848
|
+
renameSync13(tmp, p);
|
|
123325
122849
|
}
|
|
123326
122850
|
function readRecord2(root, paneId) {
|
|
123327
122851
|
if (!isValidPaneId(paneId))
|
|
@@ -123339,7 +122863,7 @@ function updateRecord(root, paneId, patch) {
|
|
|
123339
122863
|
}
|
|
123340
122864
|
function deleteRecord(root, paneId) {
|
|
123341
122865
|
try {
|
|
123342
|
-
|
|
122866
|
+
unlinkSync13(recordPathOf(root, paneId));
|
|
123343
122867
|
} catch {}
|
|
123344
122868
|
}
|
|
123345
122869
|
function validRecord(v, stem) {
|
|
@@ -123384,7 +122908,7 @@ function validForkRef(v) {
|
|
|
123384
122908
|
function readRecords(root) {
|
|
123385
122909
|
let names;
|
|
123386
122910
|
try {
|
|
123387
|
-
names =
|
|
122911
|
+
names = readdirSync14(recordsDir(root)).filter((n) => n.endsWith(".json"));
|
|
123388
122912
|
} catch {
|
|
123389
122913
|
return [];
|
|
123390
122914
|
}
|
|
@@ -123398,39 +122922,39 @@ function readRecords(root) {
|
|
|
123398
122922
|
}
|
|
123399
122923
|
function readGroupFile(ctlDir) {
|
|
123400
122924
|
try {
|
|
123401
|
-
return parseGroupFile(readFileSync50(
|
|
122925
|
+
return parseGroupFile(readFileSync50(join65(ctlDir, "group"), "utf8"));
|
|
123402
122926
|
} catch {
|
|
123403
122927
|
return null;
|
|
123404
122928
|
}
|
|
123405
122929
|
}
|
|
123406
122930
|
function writeGroupFile(ctlDir, snap) {
|
|
123407
|
-
const p =
|
|
122931
|
+
const p = join65(ctlDir, "group");
|
|
123408
122932
|
const tmp = `${p}.tmp`;
|
|
123409
122933
|
try {
|
|
123410
122934
|
writeFileSync25(tmp, formatGroupFile(snap), { mode: 384 });
|
|
123411
|
-
|
|
122935
|
+
renameSync13(tmp, p);
|
|
123412
122936
|
} catch {}
|
|
123413
122937
|
}
|
|
123414
122938
|
function removeForkRecord(fork, forkUuid) {
|
|
123415
122939
|
if (!isForkRecordPath(fork.projectsRoot, fork.path, forkUuid))
|
|
123416
122940
|
return;
|
|
123417
122941
|
try {
|
|
123418
|
-
|
|
122942
|
+
rmSync17(fork.path, { force: true });
|
|
123419
122943
|
if (fork.removeProjectDir)
|
|
123420
|
-
|
|
122944
|
+
rmdirSync4(dirname26(fork.path));
|
|
123421
122945
|
} catch {}
|
|
123422
122946
|
}
|
|
123423
122947
|
function removePaneFiles(root, f) {
|
|
123424
122948
|
if (f.fork && f.sessionUuid)
|
|
123425
122949
|
removeForkRecord(f.fork, f.sessionUuid);
|
|
123426
122950
|
if (isPaneSockPath(root, f.sockPath, f.paneId))
|
|
123427
|
-
|
|
122951
|
+
rmSync17(f.sockPath, { force: true });
|
|
123428
122952
|
const view = viewSockPathOf(root, f.paneId);
|
|
123429
122953
|
if (isPaneViewSockPath(root, view, f.paneId))
|
|
123430
|
-
|
|
122954
|
+
rmSync17(view, { force: true });
|
|
123431
122955
|
for (const d of [f.launcherDir, f.turnDir])
|
|
123432
122956
|
if (d && isLaunchDirPath(root, d))
|
|
123433
|
-
|
|
122957
|
+
rmSync17(d, { recursive: true, force: true });
|
|
123434
122958
|
const rec = recordPathOf(root, f.paneId);
|
|
123435
122959
|
if (isPaneRecordPath(root, rec, f.paneId))
|
|
123436
122960
|
deleteRecord(root, f.paneId);
|
|
@@ -123653,7 +123177,7 @@ function dialErrno(reported, sockPath) {
|
|
|
123653
123177
|
return reported;
|
|
123654
123178
|
let isSocket;
|
|
123655
123179
|
try {
|
|
123656
|
-
isSocket =
|
|
123180
|
+
isSocket = lstatSync10(sockPath).isSocket();
|
|
123657
123181
|
} catch (e) {
|
|
123658
123182
|
return e.code ?? "unknown";
|
|
123659
123183
|
}
|
|
@@ -123698,11 +123222,11 @@ async function sweepRecordlessSocket(root, name, out) {
|
|
|
123698
123222
|
const owner = ownerOfSocketId(id);
|
|
123699
123223
|
if (!owner || ownerAlive(owner, table))
|
|
123700
123224
|
return;
|
|
123701
|
-
const sockPath =
|
|
123225
|
+
const sockPath = join65(root, name);
|
|
123702
123226
|
const magmuxMayLive = !table || table.some((r) => isPaneMagmuxCommand(r.command, id));
|
|
123703
123227
|
const probe = await probeSocket(sockPath, magmuxMayLive);
|
|
123704
123228
|
if (probe.state === "stale") {
|
|
123705
|
-
|
|
123229
|
+
rmSync17(sockPath, { force: true });
|
|
123706
123230
|
out.cleaned.push(id);
|
|
123707
123231
|
return;
|
|
123708
123232
|
}
|
|
@@ -123728,13 +123252,13 @@ async function sweepRecordlessSocket(root, name, out) {
|
|
|
123728
123252
|
if (mag)
|
|
123729
123253
|
signal(mag.pid, "SIGKILL");
|
|
123730
123254
|
await Bun.sleep(300);
|
|
123731
|
-
|
|
123255
|
+
rmSync17(sockPath, { force: true });
|
|
123732
123256
|
(mag ? out.reaped : out.kept).push(id);
|
|
123733
123257
|
}
|
|
123734
123258
|
function sweepRecordlessViewSockets(root, out) {
|
|
123735
123259
|
let names = [];
|
|
123736
123260
|
try {
|
|
123737
|
-
names =
|
|
123261
|
+
names = readdirSync14(root).filter((n) => /^magmux-c\d+-[A-Za-z0-9_-]+\.view$/.test(n));
|
|
123738
123262
|
} catch {
|
|
123739
123263
|
return;
|
|
123740
123264
|
}
|
|
@@ -123752,7 +123276,7 @@ function sweepRecordlessViewSockets(root, out) {
|
|
|
123752
123276
|
const view = viewSockPathOf(root, id);
|
|
123753
123277
|
if (!isPaneViewSockPath(root, view, id))
|
|
123754
123278
|
continue;
|
|
123755
|
-
|
|
123279
|
+
rmSync17(view, { force: true });
|
|
123756
123280
|
out.cleaned.push(id);
|
|
123757
123281
|
}
|
|
123758
123282
|
}
|
|
@@ -123767,7 +123291,7 @@ function sweepDeadFeed(root, out) {
|
|
|
123767
123291
|
const now = readFeedStamp(path);
|
|
123768
123292
|
if (!now || now.pid !== stamp.pid || now.start36 !== stamp.start36 || now.started_at !== stamp.started_at)
|
|
123769
123293
|
return;
|
|
123770
|
-
|
|
123294
|
+
rmSync17(path, { force: true });
|
|
123771
123295
|
out.cleaned.push("feed/feed.json");
|
|
123772
123296
|
}
|
|
123773
123297
|
async function ensureSwept(root) {
|
|
@@ -123786,7 +123310,7 @@ async function sweepOrphanPanes(root = sockRootFor()) {
|
|
|
123786
123310
|
const known = new Set(readRecords(root).map((r) => r.paneId));
|
|
123787
123311
|
let names = [];
|
|
123788
123312
|
try {
|
|
123789
|
-
names =
|
|
123313
|
+
names = readdirSync14(root).filter((n) => /^magmux-c\d+-[A-Za-z0-9_-]+\.sock$/.test(n));
|
|
123790
123314
|
} catch {
|
|
123791
123315
|
names = [];
|
|
123792
123316
|
}
|
|
@@ -123848,20 +123372,20 @@ var init_exit_evidence = __esm(() => {
|
|
|
123848
123372
|
});
|
|
123849
123373
|
|
|
123850
123374
|
// src/pane/gate-binding.ts
|
|
123851
|
-
import { realpathSync as
|
|
123852
|
-
import { basename as
|
|
123375
|
+
import { realpathSync as realpathSync10 } from "fs";
|
|
123376
|
+
import { basename as basename12, dirname as dirname27, join as join66, resolve as resolve11 } from "path";
|
|
123853
123377
|
function normaliseTranscriptPath(p) {
|
|
123854
123378
|
const abs = resolve11(p);
|
|
123855
123379
|
const tail = [];
|
|
123856
123380
|
let cur = abs;
|
|
123857
123381
|
for (;; ) {
|
|
123858
123382
|
try {
|
|
123859
|
-
return tail.length ?
|
|
123383
|
+
return tail.length ? join66(realpathSync10(cur), ...tail.reverse()) : realpathSync10(cur);
|
|
123860
123384
|
} catch {
|
|
123861
|
-
const parent =
|
|
123385
|
+
const parent = dirname27(cur);
|
|
123862
123386
|
if (parent === cur)
|
|
123863
123387
|
return abs;
|
|
123864
|
-
tail.push(
|
|
123388
|
+
tail.push(basename12(cur));
|
|
123865
123389
|
cur = parent;
|
|
123866
123390
|
}
|
|
123867
123391
|
}
|
|
@@ -123950,7 +123474,7 @@ async function captureGroupBeforeReap(h) {
|
|
|
123950
123474
|
}
|
|
123951
123475
|
refreshGroupOf(h, table);
|
|
123952
123476
|
}
|
|
123953
|
-
async function
|
|
123477
|
+
async function groupAlive(h) {
|
|
123954
123478
|
if (!h.group)
|
|
123955
123479
|
return false;
|
|
123956
123480
|
const table = await readProcessTableAsync();
|
|
@@ -123974,7 +123498,7 @@ async function groupBackstop(h) {
|
|
|
123974
123498
|
for (const target of targets)
|
|
123975
123499
|
signalQuietly(target, sig);
|
|
123976
123500
|
const end = Date.now() + (sig === "SIGTERM" ? ms(h, 2000, 500) : 1000);
|
|
123977
|
-
while (Date.now() < end && await
|
|
123501
|
+
while (Date.now() < end && await groupAlive(h))
|
|
123978
123502
|
await Bun.sleep(150);
|
|
123979
123503
|
}
|
|
123980
123504
|
}
|
|
@@ -123992,7 +123516,7 @@ async function endWatcher(h) {
|
|
|
123992
123516
|
w.kill("SIGKILL");
|
|
123993
123517
|
}
|
|
123994
123518
|
async function verifyAndClean(h) {
|
|
123995
|
-
const groupGone = !await
|
|
123519
|
+
const groupGone = !await groupAlive(h);
|
|
123996
123520
|
const magGone = !alive(h.magmux());
|
|
123997
123521
|
h.client()?.close();
|
|
123998
123522
|
if (groupGone && magGone) {
|
|
@@ -124078,8 +123602,8 @@ var init_scroll_input = __esm(() => {
|
|
|
124078
123602
|
});
|
|
124079
123603
|
|
|
124080
123604
|
// src/pane/session-registry.ts
|
|
124081
|
-
import { readFileSync as readFileSync51, readdirSync as
|
|
124082
|
-
import { join as
|
|
123605
|
+
import { readFileSync as readFileSync51, readdirSync as readdirSync15 } from "fs";
|
|
123606
|
+
import { join as join67 } from "path";
|
|
124083
123607
|
function parseRegistryRecord(raw) {
|
|
124084
123608
|
let parsed;
|
|
124085
123609
|
try {
|
|
@@ -124106,7 +123630,7 @@ function parseRegistryRecord(raw) {
|
|
|
124106
123630
|
version: typeof r.version === "string" ? r.version : null
|
|
124107
123631
|
};
|
|
124108
123632
|
}
|
|
124109
|
-
function
|
|
123633
|
+
function pidAlive2(pid) {
|
|
124110
123634
|
try {
|
|
124111
123635
|
process.kill(pid, 0);
|
|
124112
123636
|
return true;
|
|
@@ -124124,9 +123648,9 @@ class SessionRegistry {
|
|
|
124124
123648
|
isAlive;
|
|
124125
123649
|
constructor(o) {
|
|
124126
123650
|
this.o = o;
|
|
124127
|
-
this.dir =
|
|
123651
|
+
this.dir = join67(o.configDir, "sessions");
|
|
124128
123652
|
this.now = o.now ?? Date.now;
|
|
124129
|
-
this.isAlive = o.isAlive ??
|
|
123653
|
+
this.isAlive = o.isAlive ?? pidAlive2;
|
|
124130
123654
|
}
|
|
124131
123655
|
read() {
|
|
124132
123656
|
if (this.pid !== null) {
|
|
@@ -124141,7 +123665,7 @@ class SessionRegistry {
|
|
|
124141
123665
|
this.lastScanAt = now;
|
|
124142
123666
|
let names;
|
|
124143
123667
|
try {
|
|
124144
|
-
names =
|
|
123668
|
+
names = readdirSync15(this.dir);
|
|
124145
123669
|
} catch {
|
|
124146
123670
|
return null;
|
|
124147
123671
|
}
|
|
@@ -124160,7 +123684,7 @@ class SessionRegistry {
|
|
|
124160
123684
|
readPid(pid) {
|
|
124161
123685
|
let raw;
|
|
124162
123686
|
try {
|
|
124163
|
-
raw = readFileSync51(
|
|
123687
|
+
raw = readFileSync51(join67(this.dir, `${pid}.json`), "utf8");
|
|
124164
123688
|
} catch {
|
|
124165
123689
|
return null;
|
|
124166
123690
|
}
|
|
@@ -124309,8 +123833,8 @@ var init_view_socket = __esm(() => {
|
|
|
124309
123833
|
});
|
|
124310
123834
|
|
|
124311
123835
|
// src/pane/pane-session.ts
|
|
124312
|
-
import { readFileSync as readFileSync52, realpathSync as
|
|
124313
|
-
import { join as
|
|
123836
|
+
import { readFileSync as readFileSync52, realpathSync as realpathSync11, rmSync as rmSync18, statSync as statSync26, writeFileSync as writeFileSync26 } from "fs";
|
|
123837
|
+
import { join as join68 } from "path";
|
|
124314
123838
|
function clearKeyCount(line, attempts, cols) {
|
|
124315
123839
|
const cells = 2 * Math.max(1, attempts) * Bun.stringWidth(line);
|
|
124316
123840
|
const halfRow = Math.max(1, Math.floor((cols - 4) / 2));
|
|
@@ -124493,7 +124017,7 @@ class PaneSessionImpl {
|
|
|
124493
124017
|
});
|
|
124494
124018
|
this.secondaryQuietMs = o.timings?.secondaryQuietMs ?? SECONDARY_QUIET_MS;
|
|
124495
124019
|
this.corroborationMs = o.timings?.corroborationMs ?? CORROBORATION_MS;
|
|
124496
|
-
this.follower = new TranscriptFollower(o.transcriptPath,
|
|
124020
|
+
this.follower = new TranscriptFollower(o.transcriptPath, join68(o.transcriptPath.replace(/\.jsonl$/, ""), "subagents"));
|
|
124497
124021
|
this.registry = new SessionRegistry({
|
|
124498
124022
|
configDir: claudeCodeConfigDir(o.parentEnv ?? process.env, o.cwd),
|
|
124499
124023
|
sessionUuid: o.sessionUuid
|
|
@@ -124540,7 +124064,7 @@ class PaneSessionImpl {
|
|
|
124540
124064
|
return this.spawnFailed(new Error("magmux did not start"));
|
|
124541
124065
|
this.magmux = proc;
|
|
124542
124066
|
try {
|
|
124543
|
-
writeFileSync26(
|
|
124067
|
+
writeFileSync26(join68(this.ctlDir, "magmux.pid"), `${proc.pid}
|
|
124544
124068
|
`, { mode: 384 });
|
|
124545
124069
|
} catch {}
|
|
124546
124070
|
updateRecord(this.root, this.paneId, { magmuxPid: proc.pid });
|
|
@@ -126853,7 +126377,7 @@ ${screenTailOf(this.screen)}`
|
|
|
126853
126377
|
if (!p)
|
|
126854
126378
|
return 0;
|
|
126855
126379
|
try {
|
|
126856
|
-
return
|
|
126380
|
+
return statSync26(p).size;
|
|
126857
126381
|
} catch {
|
|
126858
126382
|
return 0;
|
|
126859
126383
|
}
|
|
@@ -127627,7 +127151,7 @@ function preparePane(o, root, parentEnv) {
|
|
|
127627
127151
|
try {
|
|
127628
127152
|
const paneId = mintPaneId(o.kind, o.label);
|
|
127629
127153
|
const sockPath = sockPathOf(root, paneId);
|
|
127630
|
-
const cwd =
|
|
127154
|
+
const cwd = realpathSync11(o.cwd);
|
|
127631
127155
|
const launch = o.claudishSpawn ?? resolveClaudishLaunch(parentEnv);
|
|
127632
127156
|
dirs = createLaunchDirs(root);
|
|
127633
127157
|
const argv = buildClaudishPaneArgv(o.spawnModel, o.sessionUuid, dirs.turnDir, o.callerFlags, o.spawnPinned === true);
|
|
@@ -127644,7 +127168,7 @@ function preparePane(o, root, parentEnv) {
|
|
|
127644
127168
|
} catch (e) {
|
|
127645
127169
|
for (const d of dirs ? [dirs.ctlDir, dirs.turnDir] : [])
|
|
127646
127170
|
if (isLaunchDirPath(root, d))
|
|
127647
|
-
|
|
127171
|
+
rmSync18(d, { recursive: true, force: true });
|
|
127648
127172
|
if (e.code)
|
|
127649
127173
|
throw e;
|
|
127650
127174
|
throw new PaneStartError("pane_lost", e instanceof Error ? e.message : String(e));
|
|
@@ -127781,8 +127305,8 @@ var init_pane_session = __esm(() => {
|
|
|
127781
127305
|
});
|
|
127782
127306
|
|
|
127783
127307
|
// src/pane/replay-pane.ts
|
|
127784
|
-
import { rmSync as
|
|
127785
|
-
import { join as
|
|
127308
|
+
import { rmSync as rmSync19, writeFileSync as writeFileSync27 } from "fs";
|
|
127309
|
+
import { join as join69 } from "path";
|
|
127786
127310
|
async function waitUntil(pred, ms) {
|
|
127787
127311
|
const end = Date.now() + ms;
|
|
127788
127312
|
while (!pred() && Date.now() < end)
|
|
@@ -127895,7 +127419,7 @@ class ReplayPane {
|
|
|
127895
127419
|
return failed(new Error("magmux did not start"));
|
|
127896
127420
|
this.magmuxProc = proc;
|
|
127897
127421
|
try {
|
|
127898
|
-
writeFileSync27(
|
|
127422
|
+
writeFileSync27(join69(this.ctlDir, "magmux.pid"), `${proc.pid}
|
|
127899
127423
|
`, { mode: 384 });
|
|
127900
127424
|
} catch {}
|
|
127901
127425
|
updateRecord(this.root, this.paneId, { magmuxPid: proc.pid });
|
|
@@ -128367,7 +127891,7 @@ async function startReplayPane(o) {
|
|
|
128367
127891
|
} catch (e) {
|
|
128368
127892
|
for (const d of dirs ? [dirs.ctlDir, dirs.turnDir] : [])
|
|
128369
127893
|
if (isLaunchDirPath(root, d))
|
|
128370
|
-
|
|
127894
|
+
rmSync19(d, { recursive: true, force: true });
|
|
128371
127895
|
throw e;
|
|
128372
127896
|
}
|
|
128373
127897
|
const pane = new ReplayPane(o, {
|
|
@@ -128813,17 +128337,17 @@ var init_transcript_redaction = __esm(() => {
|
|
|
128813
128337
|
// src/pane/transcript-page.ts
|
|
128814
128338
|
import {
|
|
128815
128339
|
constants as constants7,
|
|
128816
|
-
closeSync as
|
|
128340
|
+
closeSync as closeSync21,
|
|
128817
128341
|
fstatSync as fstatSync6,
|
|
128818
|
-
lstatSync as
|
|
128819
|
-
openSync as
|
|
128820
|
-
readSync as
|
|
128821
|
-
readdirSync as
|
|
128822
|
-
readlinkSync
|
|
128823
|
-
realpathSync as
|
|
128824
|
-
statSync as
|
|
128342
|
+
lstatSync as lstatSync11,
|
|
128343
|
+
openSync as openSync21,
|
|
128344
|
+
readSync as readSync11,
|
|
128345
|
+
readdirSync as readdirSync16,
|
|
128346
|
+
readlinkSync,
|
|
128347
|
+
realpathSync as realpathSync12,
|
|
128348
|
+
statSync as statSync27
|
|
128825
128349
|
} from "fs";
|
|
128826
|
-
import { basename as
|
|
128350
|
+
import { basename as basename13, dirname as dirname28, join as join70, sep as sep4 } from "path";
|
|
128827
128351
|
function isUuid(v) {
|
|
128828
128352
|
return typeof v === "string" && UUID_RE.test(v);
|
|
128829
128353
|
}
|
|
@@ -128870,7 +128394,7 @@ class LineScanner {
|
|
|
128870
128394
|
return null;
|
|
128871
128395
|
const n = Math.min(READ_CHUNK, this.size - at);
|
|
128872
128396
|
const b = Buffer.alloc(n);
|
|
128873
|
-
const got =
|
|
128397
|
+
const got = readSync11(this.fd, b, 0, n, at);
|
|
128874
128398
|
if (got <= 0)
|
|
128875
128399
|
return null;
|
|
128876
128400
|
this.chunk = got < n ? b.subarray(0, got) : b;
|
|
@@ -128905,7 +128429,7 @@ function absentPage(from) {
|
|
|
128905
128429
|
}
|
|
128906
128430
|
function closeQuietly(fd) {
|
|
128907
128431
|
try {
|
|
128908
|
-
|
|
128432
|
+
closeSync21(fd);
|
|
128909
128433
|
} catch {}
|
|
128910
128434
|
}
|
|
128911
128435
|
function readTranscriptPageFd(fd, from, limits) {
|
|
@@ -128918,7 +128442,7 @@ function readTranscriptPageFd(fd, from, limits) {
|
|
|
128918
128442
|
throw new ContractErrorException("invalid_args", "'since' is past the end of the transcript");
|
|
128919
128443
|
if (from.offset > 0) {
|
|
128920
128444
|
const b = Buffer.alloc(1);
|
|
128921
|
-
const got =
|
|
128445
|
+
const got = readSync11(fd, b, 0, 1, from.offset - 1);
|
|
128922
128446
|
if (got !== 1 || b[0] !== 10)
|
|
128923
128447
|
throw new ContractErrorException("invalid_args", "'since' is not at a line start");
|
|
128924
128448
|
}
|
|
@@ -128967,15 +128491,15 @@ function locateTranscriptByUuid(projectsRoot, uuid) {
|
|
|
128967
128491
|
return null;
|
|
128968
128492
|
let dirs;
|
|
128969
128493
|
try {
|
|
128970
|
-
dirs =
|
|
128494
|
+
dirs = readdirSync16(projectsRoot);
|
|
128971
128495
|
} catch {
|
|
128972
128496
|
return null;
|
|
128973
128497
|
}
|
|
128974
128498
|
let hit = null;
|
|
128975
128499
|
for (const d of dirs) {
|
|
128976
|
-
const p =
|
|
128500
|
+
const p = join70(projectsRoot, d, `${uuid}.jsonl`);
|
|
128977
128501
|
try {
|
|
128978
|
-
if (!
|
|
128502
|
+
if (!statSync27(p).isFile())
|
|
128979
128503
|
continue;
|
|
128980
128504
|
} catch {
|
|
128981
128505
|
continue;
|
|
@@ -129003,7 +128527,7 @@ function writerLiveness(pid) {
|
|
|
129003
128527
|
}
|
|
129004
128528
|
function fileAgeMs(path, now = Date.now()) {
|
|
129005
128529
|
try {
|
|
129006
|
-
return now -
|
|
128530
|
+
return now - statSync27(path).mtimeMs;
|
|
129007
128531
|
} catch {
|
|
129008
128532
|
return null;
|
|
129009
128533
|
}
|
|
@@ -129028,15 +128552,15 @@ function errText(e) {
|
|
|
129028
128552
|
return e instanceof Error ? e.message : String(e);
|
|
129029
128553
|
}
|
|
129030
128554
|
function openContainedTranscript(path, uuid, projectsRoot) {
|
|
129031
|
-
if (
|
|
128555
|
+
if (basename13(path) !== `${uuid}.jsonl`) {
|
|
129032
128556
|
logRejection(path, "basename is not the session uuid");
|
|
129033
128557
|
return null;
|
|
129034
128558
|
}
|
|
129035
128559
|
let real;
|
|
129036
128560
|
let root;
|
|
129037
128561
|
try {
|
|
129038
|
-
real =
|
|
129039
|
-
root =
|
|
128562
|
+
real = realpathSync12(path);
|
|
128563
|
+
root = realpathSync12(projectsRoot);
|
|
129040
128564
|
} catch (e) {
|
|
129041
128565
|
if (!isEnoent(e))
|
|
129042
128566
|
logRejection(path, errText(e));
|
|
@@ -129048,7 +128572,7 @@ function openContainedTranscript(path, uuid, projectsRoot) {
|
|
|
129048
128572
|
}
|
|
129049
128573
|
let fd;
|
|
129050
128574
|
try {
|
|
129051
|
-
fd =
|
|
128575
|
+
fd = openSync21(real, OPEN_FLAGS);
|
|
129052
128576
|
} catch (e) {
|
|
129053
128577
|
if (e?.code === "ELOOP")
|
|
129054
128578
|
logRejection(path, "the transcript became a symlink");
|
|
@@ -129063,9 +128587,9 @@ function openContainedTranscript(path, uuid, projectsRoot) {
|
|
|
129063
128587
|
closeQuietly(fd);
|
|
129064
128588
|
return null;
|
|
129065
128589
|
}
|
|
129066
|
-
const parent =
|
|
129067
|
-
const named =
|
|
129068
|
-
if (
|
|
128590
|
+
const parent = dirname28(real);
|
|
128591
|
+
const named = lstatSync11(real);
|
|
128592
|
+
if (realpathSync12(parent) !== parent || !named.isFile() || named.dev !== st.dev || named.ino !== st.ino || !kernelPathMatches(fd, real)) {
|
|
129069
128593
|
logRejection(path, "the opened file is not the one under the projects directory");
|
|
129070
128594
|
closeQuietly(fd);
|
|
129071
128595
|
return null;
|
|
@@ -129083,7 +128607,7 @@ function kernelPathMatches(fd, real) {
|
|
|
129083
128607
|
return true;
|
|
129084
128608
|
let kernel;
|
|
129085
128609
|
try {
|
|
129086
|
-
kernel =
|
|
128610
|
+
kernel = readlinkSync(`/proc/self/fd/${fd}`);
|
|
129087
128611
|
} catch {
|
|
129088
128612
|
return true;
|
|
129089
128613
|
}
|
|
@@ -129096,7 +128620,7 @@ function transcriptHeadCwd(path, uuid, projectsRoot) {
|
|
|
129096
128620
|
let text;
|
|
129097
128621
|
try {
|
|
129098
128622
|
const buf = Buffer.alloc(HEAD_CWD_MAX_BYTES);
|
|
129099
|
-
const n =
|
|
128623
|
+
const n = readSync11(fd, buf, 0, HEAD_CWD_MAX_BYTES, 0);
|
|
129100
128624
|
text = buf.toString("utf8", 0, n);
|
|
129101
128625
|
} catch {
|
|
129102
128626
|
return null;
|
|
@@ -129208,7 +128732,7 @@ var init_pane = __esm(() => {
|
|
|
129208
128732
|
});
|
|
129209
128733
|
|
|
129210
128734
|
// src/view/kernel-lock.ts
|
|
129211
|
-
import { constants as constants8, closeSync as
|
|
128735
|
+
import { constants as constants8, closeSync as closeSync22, fstatSync as fstatSync7, openSync as openSync22, statSync as statSync28, unlinkSync as unlinkSync14 } from "fs";
|
|
129212
128736
|
function bindFlock() {
|
|
129213
128737
|
const library = process.platform === "darwin" ? "libSystem.B.dylib" : process.platform === "linux" ? "libc.so.6" : null;
|
|
129214
128738
|
if (!library)
|
|
@@ -129251,7 +128775,7 @@ function lockOf(fd, path) {
|
|
|
129251
128775
|
return;
|
|
129252
128776
|
open = false;
|
|
129253
128777
|
try {
|
|
129254
|
-
|
|
128778
|
+
closeSync22(fd);
|
|
129255
128779
|
} catch {}
|
|
129256
128780
|
}
|
|
129257
128781
|
};
|
|
@@ -129261,23 +128785,23 @@ function tryAcquire(path) {
|
|
|
129261
128785
|
if (!lib)
|
|
129262
128786
|
throw new KernelLockUnavailable("flock is not available in this process");
|
|
129263
128787
|
for (let attempt = 0;attempt < 5; attempt++) {
|
|
129264
|
-
const fd =
|
|
128788
|
+
const fd = openSync22(path, constants8.O_RDWR | constants8.O_CREAT | O_CLOEXEC, 384);
|
|
129265
128789
|
if (lib.flock(fd, LOCK_EX | LOCK_NB) !== 0) {
|
|
129266
128790
|
const errno = lib.errno();
|
|
129267
|
-
|
|
128791
|
+
closeSync22(fd);
|
|
129268
128792
|
if (errno === EWOULDBLOCK)
|
|
129269
128793
|
return null;
|
|
129270
128794
|
throw new KernelLockUnavailable(`flock ${path}: errno ${errno}`);
|
|
129271
128795
|
}
|
|
129272
128796
|
let same = false;
|
|
129273
128797
|
try {
|
|
129274
|
-
same = fstatSync7(fd).ino ===
|
|
128798
|
+
same = fstatSync7(fd).ino === statSync28(path).ino;
|
|
129275
128799
|
} catch {
|
|
129276
128800
|
same = false;
|
|
129277
128801
|
}
|
|
129278
128802
|
if (same)
|
|
129279
128803
|
return lockOf(fd, path);
|
|
129280
|
-
|
|
128804
|
+
closeSync22(fd);
|
|
129281
128805
|
}
|
|
129282
128806
|
throw new KernelLockUnavailable(`flock ${path}: the file keeps being replaced`);
|
|
129283
128807
|
}
|
|
@@ -129302,7 +128826,7 @@ function removeIfFree(path) {
|
|
|
129302
128826
|
if (!lock)
|
|
129303
128827
|
return false;
|
|
129304
128828
|
try {
|
|
129305
|
-
|
|
128829
|
+
unlinkSync14(path);
|
|
129306
128830
|
return true;
|
|
129307
128831
|
} catch {
|
|
129308
128832
|
return false;
|
|
@@ -129467,8 +128991,8 @@ var init_peer_link = __esm(() => {
|
|
|
129467
128991
|
|
|
129468
128992
|
// src/view/replay-registry.ts
|
|
129469
128993
|
import { randomBytes as randomBytes18 } from "crypto";
|
|
129470
|
-
import { readFileSync as readFileSync53, readdirSync as
|
|
129471
|
-
import { join as
|
|
128994
|
+
import { readFileSync as readFileSync53, readdirSync as readdirSync17, renameSync as renameSync14, rmSync as rmSync20, writeFileSync as writeFileSync28 } from "fs";
|
|
128995
|
+
import { join as join71 } from "path";
|
|
129472
128996
|
function parseEntry(raw) {
|
|
129473
128997
|
let v;
|
|
129474
128998
|
try {
|
|
@@ -129506,14 +129030,14 @@ class ReplayRegistry {
|
|
|
129506
129030
|
constructor(root, log = () => {}) {
|
|
129507
129031
|
this.root = root;
|
|
129508
129032
|
this.log = log;
|
|
129509
|
-
this.dir =
|
|
129033
|
+
this.dir = join71(root, REPLAYS_DIR);
|
|
129510
129034
|
}
|
|
129511
129035
|
ensure() {
|
|
129512
129036
|
ensureSockRoot(this.root);
|
|
129513
129037
|
return ensurePrivateSubdir(this.root, REPLAYS_DIR);
|
|
129514
129038
|
}
|
|
129515
129039
|
lockPathOf(uuid) {
|
|
129516
|
-
return
|
|
129040
|
+
return join71(this.dir, `${this.key(uuid)}.lock`);
|
|
129517
129041
|
}
|
|
129518
129042
|
tryLock(uuid) {
|
|
129519
129043
|
this.ensure();
|
|
@@ -129528,7 +129052,7 @@ class ReplayRegistry {
|
|
|
129528
129052
|
}
|
|
129529
129053
|
async withLock(fn, waitMs = REGISTRY_LOCK_WAIT_MS) {
|
|
129530
129054
|
this.ensure();
|
|
129531
|
-
const lock = await waitAcquire(
|
|
129055
|
+
const lock = await waitAcquire(join71(this.dir, "registry.lock"), waitMs);
|
|
129532
129056
|
if (!lock)
|
|
129533
129057
|
return null;
|
|
129534
129058
|
try {
|
|
@@ -129543,9 +129067,9 @@ class ReplayRegistry {
|
|
|
129543
129067
|
writeFileSync28(tmp, `${JSON.stringify(entry)}
|
|
129544
129068
|
`, { mode: 384, flag: "wx" });
|
|
129545
129069
|
try {
|
|
129546
|
-
|
|
129070
|
+
renameSync14(tmp, path);
|
|
129547
129071
|
} catch (e) {
|
|
129548
|
-
|
|
129072
|
+
rmSync20(tmp, { force: true });
|
|
129549
129073
|
throw e;
|
|
129550
129074
|
}
|
|
129551
129075
|
}
|
|
@@ -129566,7 +129090,7 @@ class ReplayRegistry {
|
|
|
129566
129090
|
const e = this.read(uuid);
|
|
129567
129091
|
if (!e || e.replay_id !== replayId)
|
|
129568
129092
|
return false;
|
|
129569
|
-
|
|
129093
|
+
rmSync20(this.entryPathOf(uuid), { force: true });
|
|
129570
129094
|
return true;
|
|
129571
129095
|
});
|
|
129572
129096
|
if (!done)
|
|
@@ -129576,7 +129100,7 @@ class ReplayRegistry {
|
|
|
129576
129100
|
async sweep() {
|
|
129577
129101
|
let names;
|
|
129578
129102
|
try {
|
|
129579
|
-
names =
|
|
129103
|
+
names = readdirSync17(this.dir);
|
|
129580
129104
|
} catch {
|
|
129581
129105
|
return [];
|
|
129582
129106
|
}
|
|
@@ -129590,7 +129114,7 @@ class ReplayRegistry {
|
|
|
129590
129114
|
if (!held)
|
|
129591
129115
|
continue;
|
|
129592
129116
|
try {
|
|
129593
|
-
await this.withLock(() =>
|
|
129117
|
+
await this.withLock(() => rmSync20(this.entryPathOf(uuid), { force: true }));
|
|
129594
129118
|
} finally {
|
|
129595
129119
|
held.close();
|
|
129596
129120
|
}
|
|
@@ -129600,18 +129124,18 @@ class ReplayRegistry {
|
|
|
129600
129124
|
await this.withLock(() => {
|
|
129601
129125
|
let now;
|
|
129602
129126
|
try {
|
|
129603
|
-
now =
|
|
129127
|
+
now = readdirSync17(this.dir);
|
|
129604
129128
|
} catch {
|
|
129605
129129
|
return;
|
|
129606
129130
|
}
|
|
129607
129131
|
for (const name of now)
|
|
129608
129132
|
if (name.endsWith(".tmp"))
|
|
129609
|
-
|
|
129133
|
+
rmSync20(join71(this.dir, name), { force: true });
|
|
129610
129134
|
});
|
|
129611
129135
|
return swept;
|
|
129612
129136
|
}
|
|
129613
129137
|
entryPathOf(uuid) {
|
|
129614
|
-
return
|
|
129138
|
+
return join71(this.dir, `${this.key(uuid)}.json`);
|
|
129615
129139
|
}
|
|
129616
129140
|
key(uuid) {
|
|
129617
129141
|
const k = uuid.toLowerCase();
|
|
@@ -129632,8 +129156,8 @@ var init_replay_registry = __esm(() => {
|
|
|
129632
129156
|
|
|
129633
129157
|
// src/mcp-session/replay-manager.ts
|
|
129634
129158
|
import { randomBytes as randomBytes19, randomUUID as randomUUID10 } from "crypto";
|
|
129635
|
-
import { constants as constants9, accessSync as accessSync5, closeSync as
|
|
129636
|
-
import { dirname as
|
|
129159
|
+
import { constants as constants9, accessSync as accessSync5, closeSync as closeSync23, existsSync as existsSync43, realpathSync as realpathSync13, statSync as statSync29 } from "fs";
|
|
129160
|
+
import { dirname as dirname29, resolve as resolve12 } from "path";
|
|
129637
129161
|
function unavailable2(reason, message) {
|
|
129638
129162
|
return new ContractErrorException("replay_unavailable", message, reason);
|
|
129639
129163
|
}
|
|
@@ -129646,17 +129170,17 @@ function elsewhere(endpoint, replayId) {
|
|
|
129646
129170
|
function replayCwd(own) {
|
|
129647
129171
|
if (own) {
|
|
129648
129172
|
try {
|
|
129649
|
-
if (
|
|
129650
|
-
return
|
|
129173
|
+
if (statSync29(own).isDirectory())
|
|
129174
|
+
return realpathSync13(own);
|
|
129651
129175
|
} catch {}
|
|
129652
129176
|
}
|
|
129653
|
-
return
|
|
129177
|
+
return realpathSync13(process.cwd());
|
|
129654
129178
|
}
|
|
129655
129179
|
async function replayClaudeBinary(env) {
|
|
129656
129180
|
const named = env.CLAUDE_PATH ? resolve12(env.CLAUDE_PATH) : "";
|
|
129657
129181
|
if (named) {
|
|
129658
129182
|
try {
|
|
129659
|
-
if (!
|
|
129183
|
+
if (!statSync29(named).isFile())
|
|
129660
129184
|
throw new Error("not a file");
|
|
129661
129185
|
accessSync5(named, constants9.X_OK);
|
|
129662
129186
|
} catch {
|
|
@@ -129674,7 +129198,7 @@ function callerOf(opener) {
|
|
|
129674
129198
|
}
|
|
129675
129199
|
function isRecordGone(path) {
|
|
129676
129200
|
try {
|
|
129677
|
-
|
|
129201
|
+
statSync29(path);
|
|
129678
129202
|
return false;
|
|
129679
129203
|
} catch (e) {
|
|
129680
129204
|
return e.code === "ENOENT";
|
|
@@ -129985,8 +129509,8 @@ class ReplayManager {
|
|
|
129985
129509
|
cwd,
|
|
129986
129510
|
projectsRoot,
|
|
129987
129511
|
forkPath,
|
|
129988
|
-
removeProjectDir: !existsSync43(
|
|
129989
|
-
configDir:
|
|
129512
|
+
removeProjectDir: !existsSync43(dirname29(forkPath)),
|
|
129513
|
+
configDir: dirname29(projectsRoot),
|
|
129990
129514
|
cols: size.cols ?? DEFAULT_PANE_COLS,
|
|
129991
129515
|
rows: size.rows ?? DEFAULT_PANE_ROWS
|
|
129992
129516
|
});
|
|
@@ -130287,7 +129811,7 @@ class ReplayManager {
|
|
|
130287
129811
|
const fd = openContainedTranscript(path, uuid, target.projectsRoot);
|
|
130288
129812
|
if (fd === null)
|
|
130289
129813
|
throw noRecord("the session's Claude Code record is gone");
|
|
130290
|
-
|
|
129814
|
+
closeSync23(fd);
|
|
130291
129815
|
return uuid;
|
|
130292
129816
|
}
|
|
130293
129817
|
itemOf(e) {
|
|
@@ -130960,6 +130484,7 @@ function noticeLines(notices) {
|
|
|
130960
130484
|
var CLAUDE_API_PROVIDER3 = "anthropic", TIER_FIELDS;
|
|
130961
130485
|
var init_claude_launch = __esm(() => {
|
|
130962
130486
|
init_claude_code_login();
|
|
130487
|
+
init_classifier_passthrough();
|
|
130963
130488
|
init_claude_runner();
|
|
130964
130489
|
init_anthropic_forward();
|
|
130965
130490
|
init_child_env();
|
|
@@ -130979,10 +130504,10 @@ var init_claude_launch = __esm(() => {
|
|
|
130979
130504
|
});
|
|
130980
130505
|
|
|
130981
130506
|
// src/mcp/run-prompt-claude-code.ts
|
|
130982
|
-
import { spawn as
|
|
130983
|
-
import { mkdirSync as
|
|
130984
|
-
import { tmpdir as
|
|
130985
|
-
import { join as
|
|
130507
|
+
import { spawn as spawn4 } from "child_process";
|
|
130508
|
+
import { mkdirSync as mkdirSync29, mkdtempSync as mkdtempSync4, rmSync as rmSync21, writeFileSync as writeFileSync29 } from "fs";
|
|
130509
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
130510
|
+
import { join as join72 } from "path";
|
|
130986
130511
|
function claudeCodePrintArgv(model, systemPromptFile, opts = {}) {
|
|
130987
130512
|
const head = [
|
|
130988
130513
|
PRINT_FLAGS[0],
|
|
@@ -131118,13 +130643,13 @@ async function runPromptViaClaudeCode(model, prompt, systemPrompt, opts = {}) {
|
|
|
131118
130643
|
} catch (e) {
|
|
131119
130644
|
throw new Error(`cannot start claudish (${parentEnv.CLAUDISH_BIN?.trim() || "claudish"}): ${e instanceof Error ? e.message : String(e)}`);
|
|
131120
130645
|
}
|
|
131121
|
-
const root =
|
|
130646
|
+
const root = mkdtempSync4(join72(tmpdir3(), "claudish-run-prompt-"));
|
|
131122
130647
|
try {
|
|
131123
|
-
const cwd =
|
|
131124
|
-
|
|
130648
|
+
const cwd = join72(root, "cwd");
|
|
130649
|
+
mkdirSync29(cwd, { mode: 448 });
|
|
131125
130650
|
let systemPromptFile;
|
|
131126
130651
|
if (typeof systemPrompt === "string" && systemPrompt.length > 0) {
|
|
131127
|
-
systemPromptFile =
|
|
130652
|
+
systemPromptFile = join72(root, "system-prompt.txt");
|
|
131128
130653
|
writeFileSync29(systemPromptFile, systemPrompt, { mode: 384 });
|
|
131129
130654
|
}
|
|
131130
130655
|
const argv = claudeCodePrintArgv(model, systemPromptFile, {
|
|
@@ -131155,14 +130680,14 @@ async function runPromptViaClaudeCode(model, prompt, systemPrompt, opts = {}) {
|
|
|
131155
130680
|
answer.auth = auth;
|
|
131156
130681
|
return answer;
|
|
131157
130682
|
} finally {
|
|
131158
|
-
|
|
130683
|
+
rmSync21(root, { recursive: true, force: true });
|
|
131159
130684
|
}
|
|
131160
130685
|
}
|
|
131161
130686
|
function runChild(launch, argv, cwd, env, prompt, signal) {
|
|
131162
130687
|
return new Promise((resolvePromise, reject) => {
|
|
131163
130688
|
let proc;
|
|
131164
130689
|
try {
|
|
131165
|
-
proc =
|
|
130690
|
+
proc = spawn4(launch.command, [...launch.prefixArgs, ...argv], {
|
|
131166
130691
|
cwd,
|
|
131167
130692
|
env,
|
|
131168
130693
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -131235,7 +130760,7 @@ var init_run_prompt_claude_code = __esm(() => {
|
|
|
131235
130760
|
ENV.CLAUDISH_PANE_CHILD
|
|
131236
130761
|
];
|
|
131237
130762
|
inFlight5 = new Set;
|
|
131238
|
-
EMPTY_PRINT_CWD =
|
|
130763
|
+
EMPTY_PRINT_CWD = join72(tmpdir3(), "claudish-run-prompt-settings-check");
|
|
131239
130764
|
});
|
|
131240
130765
|
|
|
131241
130766
|
// src/providers/bundled-list.ts
|
|
@@ -132233,9 +131758,9 @@ var init_view_server = __esm(() => {
|
|
|
132233
131758
|
});
|
|
132234
131759
|
|
|
132235
131760
|
// src/mcp-server.ts
|
|
132236
|
-
import { existsSync as existsSync44, readFileSync as readFileSync54, readdirSync as
|
|
132237
|
-
import { homedir as
|
|
132238
|
-
import { dirname as
|
|
131761
|
+
import { existsSync as existsSync44, readFileSync as readFileSync54, readdirSync as readdirSync18 } from "fs";
|
|
131762
|
+
import { homedir as homedir43 } from "os";
|
|
131763
|
+
import { dirname as dirname30, join as join73, resolve as resolve13 } from "path";
|
|
132239
131764
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
132240
131765
|
async function loadAllModels(forceRefresh = false) {
|
|
132241
131766
|
if (!forceRefresh && existsSync44(OPENROUTER_MODELS_CACHE_PATH)) {
|
|
@@ -133709,26 +133234,26 @@ This searched OpenRouter's listing only. Subscription wire ids and catalog alias
|
|
|
133709
133234
|
const sp = session_path;
|
|
133710
133235
|
for (const file of ["status.json", "manifest.json", "input.md"]) {
|
|
133711
133236
|
try {
|
|
133712
|
-
sessionData[file] = readFileSync54(
|
|
133237
|
+
sessionData[file] = readFileSync54(join73(sp, file), "utf-8");
|
|
133713
133238
|
} catch {}
|
|
133714
133239
|
}
|
|
133715
133240
|
try {
|
|
133716
|
-
const errorDir =
|
|
133241
|
+
const errorDir = join73(sp, "errors");
|
|
133717
133242
|
if (existsSync44(errorDir)) {
|
|
133718
|
-
for (const f of
|
|
133243
|
+
for (const f of readdirSync18(errorDir)) {
|
|
133719
133244
|
if (f.endsWith(".log")) {
|
|
133720
133245
|
try {
|
|
133721
|
-
sessionData[`errors/${f}`] = readFileSync54(
|
|
133246
|
+
sessionData[`errors/${f}`] = readFileSync54(join73(errorDir, f), "utf-8");
|
|
133722
133247
|
} catch {}
|
|
133723
133248
|
}
|
|
133724
133249
|
}
|
|
133725
133250
|
}
|
|
133726
133251
|
} catch {}
|
|
133727
133252
|
try {
|
|
133728
|
-
for (const f of
|
|
133253
|
+
for (const f of readdirSync18(sp)) {
|
|
133729
133254
|
if (f.startsWith("response-") && f.endsWith(".md")) {
|
|
133730
133255
|
try {
|
|
133731
|
-
const content = readFileSync54(
|
|
133256
|
+
const content = readFileSync54(join73(sp, f), "utf-8");
|
|
133732
133257
|
sessionData[f] = content.slice(0, 200) + (content.length > 200 ? "... (truncated)" : "");
|
|
133733
133258
|
} catch {}
|
|
133734
133259
|
}
|
|
@@ -133737,7 +133262,7 @@ This searched OpenRouter's listing only. Subscription wire ids and catalog alias
|
|
|
133737
133262
|
}
|
|
133738
133263
|
let version = "unknown";
|
|
133739
133264
|
try {
|
|
133740
|
-
const pkgPath =
|
|
133265
|
+
const pkgPath = join73(__dirname3, "../package.json");
|
|
133741
133266
|
if (existsSync44(pkgPath)) {
|
|
133742
133267
|
version = JSON.parse(readFileSync54(pkgPath, "utf-8")).version;
|
|
133743
133268
|
}
|
|
@@ -133902,7 +133427,7 @@ Report manually at https://github.com/anthropics/claudish/issues${autoSendHint}`
|
|
|
133902
133427
|
},
|
|
133903
133428
|
work_dir: {
|
|
133904
133429
|
type: "string",
|
|
133905
|
-
description: "Working directory for the session (default: current directory)"
|
|
133430
|
+
description: "Working directory for the session (default: current directory). A folder Claude Code has not trusted yet is marked trusted in your Claude Code config (.claude.json) before the session starts, so the session does not stop at the trust dialog."
|
|
133906
133431
|
},
|
|
133907
133432
|
setup_from: {
|
|
133908
133433
|
type: ["string", "null"],
|
|
@@ -134357,7 +133882,6 @@ async function main() {
|
|
|
134357
133882
|
const viewFeed = new ViewFeed;
|
|
134358
133883
|
const viewClaims = new ViewClaims({ notify: (target) => viewFeed.changed(target, true) });
|
|
134359
133884
|
const sessionManager = new SessionManager({ feed: viewFeed, claims: viewClaims });
|
|
134360
|
-
sweepStaleProbeDirs();
|
|
134361
133885
|
replays.setViewServices({ feed: viewFeed, claims: viewClaims });
|
|
134362
133886
|
setViewServices({ feed: viewFeed, claims: viewClaims });
|
|
134363
133887
|
const progressIntervalMs = resolveProgressIntervalMs();
|
|
@@ -134508,7 +134032,6 @@ var init_mcp_server = __esm(() => {
|
|
|
134508
134032
|
init_mcp_session();
|
|
134509
134033
|
init_inherited_settings();
|
|
134510
134034
|
init_parent_session();
|
|
134511
|
-
init_plugin_probe();
|
|
134512
134035
|
init_nested_mode();
|
|
134513
134036
|
init_progress_heartbeat();
|
|
134514
134037
|
init_run_prompt_claude_code();
|
|
@@ -134543,9 +134066,9 @@ var init_mcp_server = __esm(() => {
|
|
|
134543
134066
|
init_view_server();
|
|
134544
134067
|
init_preflight_chain();
|
|
134545
134068
|
__filename3 = fileURLToPath3(import.meta.url);
|
|
134546
|
-
__dirname3 =
|
|
134547
|
-
CLAUDISH_CACHE_DIR =
|
|
134548
|
-
OPENROUTER_MODELS_CACHE_PATH =
|
|
134069
|
+
__dirname3 = dirname30(__filename3);
|
|
134070
|
+
CLAUDISH_CACHE_DIR = join73(homedir43(), ".claudish");
|
|
134071
|
+
OPENROUTER_MODELS_CACHE_PATH = join73(CLAUDISH_CACHE_DIR, "openrouter-models.json");
|
|
134549
134072
|
NEXT_STEP = {
|
|
134550
134073
|
cancelled: "you stopped this slot; nothing is wrong with it. Re-run it if you still want its vote",
|
|
134551
134074
|
timeout: "grid mode only \u2014 magmux ended the pane. The orchestrator has no deadline",
|
|
@@ -134707,9 +134230,9 @@ var init_serve_command = __esm(() => {
|
|
|
134707
134230
|
var HOOKS_AMBIENT_DTS = '// claudish hook types \u2014 written by `claudish hooks init`. Do not edit: run\n// `claudish hooks init` from a newer claudish to refresh it.\n// With this file beside your hook, `import type { HookDefinition } from\n// "claudish/hooks"` type-checks with nothing installed.\ndeclare module "claudish/hooks" {\n /**\n * claudish/hooks \u2014 the public hook contract.\n *\n * Everything a hook author can import lives here, and nothing else does. This\n * file imports nothing from the rest of claudish and has no side effects, so it\n * can be built on its own into `dist/hooks.js` + `dist/hooks.d.ts` and served to\n * user modules as the `claudish/hooks` virtual module (see `loader.ts`).\n *\n * Every internal hooks module takes its types from here, so the contract has a\n * single source.\n *\n * ## Process isolation\n *\n * A hook module\'s top-level state is PER PROCESS. In the interactive launcher,\n * proxy events (`request` \u2026 `responseEnd`, raw) and session events\n * (`sessionStart` \u2026 `sessionEnd`) run in one process. In `create_session` and\n * team children they do not: proxy events run in the pane child, and session\n * events run in the MCP server or the CLI process that drives the pane. Pass\n * per-turn data from a proxy event to `sessionIdle` with `annotateTurn`, never\n * with module variables.\n *\n * ## Execution: a hook chain\n *\n * The hooks of one event run one after another, in effective order. Each hook\'s\n * actions are applied before the next hook is called, so `ctx.request`,\n * `ctx.tool.args` and `ctx.response` show what the earlier hooks did, and\n * `ctx.prior` lists it. A warn-severity or failing hook changes nothing for the\n * next one. Each event has a budget for all its hooks together; a hook\'s timeout\n * is cut to what is left of it.\n *\n * ## Output\n *\n * Log with `ctx.log`. `console.*` and `process.stdout`/`stderr` writes made by a\n * hook are routed to claudish\'s debug log, never to the terminal or the MCP\n * protocol stream.\n */\n export const HOOK_API_VERSION = 1;\n export type Severity = "off" | "warn" | "fix";\n export type HookOrder = "pre" | "normal" | "post";\n /** native = RouteInfo.native true; foreign = RouteInfo.native false; all = both */\n export type RouteScope = "foreign" | "native" | "all";\n export type HostMode = "interactive" | "pane-child" | "serve" | "mcp" | "other";\n export type JsonValue = string | number | boolean | null | ReadonlyArray<JsonValue> | {\n readonly [k: string]: JsonValue;\n };\n export interface HarnessFacts {\n readonly planModeActive: boolean;\n readonly planFilePath?: string;\n readonly planDir?: string;\n /** Claude Code session id from request metadata */\n readonly sessionId?: string;\n /** empty = no listing found, not "no skills" */\n readonly skills?: ReadonlyArray<{\n name: string;\n description: string;\n }>;\n }\n export interface RouteInfo {\n /** bare model name the handler serves, e.g. "glm-5" */\n readonly modelId: string;\n /** claudish provider name, e.g. "openrouter"; "anthropic" for native */\n readonly provider: string;\n /**\n * true when the request is served by the native Anthropic handler, OR when\n * !forceForeignModel && (/^claude[-.]/i.test(modelId) || provider === "anthropic")\n * where forceForeignModel is the provider profile\'s opt-in override. This is the exact\n * rule the plan-mode built-in has always used (a claude-* uid on an aggregator that sets\n * forceForeignModel is foreign).\n */\n readonly native: boolean;\n }\n export interface ClaudeTool {\n name: string;\n description?: string;\n input_schema?: unknown;\n }\n /** A Claude-format content block. Only `text` blocks are editable by closed actions. */\n export type ClaudeContentBlock = {\n type: "text";\n text: string;\n } | {\n type: "tool_use";\n id: string;\n name: string;\n input: unknown;\n } | {\n type: "tool_result";\n tool_use_id: string;\n content?: unknown;\n is_error?: boolean;\n } | {\n type: "thinking";\n thinking: string;\n signature?: string;\n } | {\n type: string;\n [k: string]: unknown;\n };\n export interface ClaudeMessage {\n role: "user" | "assistant";\n content: string | ReadonlyArray<ClaudeContentBlock>;\n }\n /**\n * In `request`, the request as the earlier steps of the hook chain left it. On\n * the response side and in `claims()`, the request chain\'s final view.\n */\n export interface RequestFacts {\n /** as Claude Code asked for it; frozen */\n readonly model: string;\n /** frozen */\n readonly stream: boolean;\n /** system prompt flattened to text, after earlier steps */\n readonly systemText: string;\n /** read-only view after earlier steps; change it through actions */\n readonly messages: ReadonlyArray<ClaudeMessage>;\n /**\n * read-only view after earlier steps; `description` includes earlier description actions as\n * stage B will apply them to the Claude-format tool (the provider copy may be summarised)\n */\n readonly tools: ReadonlyArray<ClaudeTool>;\n }\n /** Which session a proxy event belongs to, when claudish knows. */\n export interface ProxySessionRef {\n readonly kind: SessionKind;\n readonly id: string;\n readonly role: "slot" | "judge" | null;\n }\n /** One action an earlier step of this hook chain applied or handed on. */\n export interface PriorAction {\n readonly hookId: string;\n readonly action: HookAction;\n }\n interface BaseContext {\n readonly hookId: string;\n /** "warn" or "fix" (an "off" hook is never called) */\n readonly severity: Severity;\n /** writes to claudish\'s debug log; never to the terminal */\n log(message: string): void;\n /**\n * this step\'s own signal: aborted when its step timeout elapses (its own timeout, or the\n * event budget left, whichever is shorter) or when the dispatch is aborted. Never shared\n * with another hook\'s step.\n */\n readonly signal: AbortSignal;\n /**\n * actions earlier steps of this hook chain applied (or, for responseEnd/sessionStart/\n * sessionIdle, handed on), in order. Empty for the first step and in claims()/the toolCall\n * predicate. Never lists warn actions or anything a warn-severity hook returned.\n */\n readonly prior: ReadonlyArray<PriorAction>;\n }\n export interface ProxyContext extends BaseContext {\n readonly host: {\n mode: HostMode;\n };\n readonly route: RouteInfo;\n readonly request: RequestFacts;\n readonly harness: HarnessFacts;\n readonly session: ProxySessionRef | null;\n }\n export interface RequestContext extends ProxyContext {\n readonly event: "request";\n }\n export interface ToolCallContext extends ProxyContext {\n readonly event: "toolCall";\n readonly tool: {\n id: string;\n name: string;\n /** the arguments after every repair earlier hooks in the chain applied */\n args: Readonly<Record<string, unknown>>;\n /** the argument JSON exactly as the model produced it; never rewritten */\n rawArgs: string;\n };\n }\n export type ResponseBlock = {\n type: "text";\n text: string;\n } | {\n type: "thinking";\n thinking: string;\n } | {\n type: "tool_use";\n id: string;\n name: string;\n input: unknown;\n } | {\n type: "other";\n blockType: string;\n };\n export interface ResponseView {\n blocks: ReadonlyArray<ResponseBlock>;\n /** every text block, joined with "\\n\\n" */\n text: string;\n /** every thinking block, joined with "\\n\\n" */\n reasoning: string;\n toolNames: ReadonlyArray<string>;\n /** "tool_use" = an intermediate step of a tool loop; the turn continues after the tool runs */\n stopReason: string | null;\n }\n /** response = the held response after every text action earlier hooks in the chain applied */\n export interface ResponseRewriteContext extends ProxyContext {\n readonly event: "responseRewrite";\n readonly response: ResponseView;\n }\n /** response = the final bytes the client received: after any rewrite AND any raw `response` replacement */\n export interface ResponseEndContext extends ProxyContext {\n readonly event: "responseEnd";\n readonly response: ResponseView;\n }\n export type SessionKind = "interactive" | "channel" | "team";\n export interface SessionInfo {\n kind: SessionKind;\n /** team only; null otherwise */\n role: "slot" | "judge" | null;\n /** channel: the 8-hex session_id \xB7 team: "<run_id>:<slot id>" \xB7 interactive: the Claude Code session id */\n id: string;\n claudeSessionId: string | null;\n /** as the caller asked for it */\n model: string;\n cwd: string;\n /** a one-shot session stays "one-shot" through a hook-extended turn chain */\n shape: "interactive" | "one-shot";\n injection: "available" | "unavailable";\n }\n export interface SessionStartContext extends BaseContext {\n readonly event: "sessionStart";\n readonly session: SessionInfo;\n }\n export interface TurnAnnotation {\n hookId: string;\n key: string;\n value: JsonValue;\n }\n export interface SessionIdleContext extends BaseContext {\n readonly event: "sessionIdle";\n readonly session: SessionInfo;\n readonly turn: {\n /** 1-based within the session; a re-woken turn keeps its index */\n index: number;\n /** this turn\'s assistant text; "" when `answerWithheld` */\n answer: string;\n /**\n * the turn\'s prompt went as a task file, and the model\'s Read tool calls in the main\n * conversation did not return all of it: `answer` is "" whatever the model wrote. Reading\n * it another way (a shell `cat`, a subagent) does not count as reading it.\n */\n answerWithheld: boolean;\n stopReason: string | null;\n apiError: boolean;\n /** this turn was started by an injection */\n hookCaused: boolean;\n /** annotateTurn actions from this turn\'s responses, in arrival order */\n annotations: ReadonlyArray<TurnAnnotation>;\n };\n readonly consecutiveHookTurns: number;\n /** caller/human input is queued; an injection returned now will be dropped as stale */\n readonly callerInputPending: boolean;\n }\n export interface SessionBlockedContext extends BaseContext {\n readonly event: "sessionBlocked";\n readonly session: SessionInfo;\n readonly block: {\n kind: "question" | "permission";\n text: string;\n };\n }\n export interface SessionEndContext extends BaseContext {\n readonly event: "sessionEnd";\n readonly session: SessionInfo;\n readonly outcome: {\n state: string;\n reason: string | null;\n exitCode: number | null;\n };\n }\n type TextMatch = {\n find: string;\n regex?: boolean;\n flags?: string;\n };\n /** default ["user"] */\n type MessageRoles = {\n roles?: ReadonlyArray<"user" | "assistant">;\n };\n export type InjectSystemNote = {\n type: "injectSystemNote";\n text: string;\n };\n export type AppendUserText = {\n type: "appendUserText";\n text: string;\n };\n export type ReplaceMessageText = {\n type: "replaceMessageText";\n replace: string;\n } & TextMatch & MessageRoles;\n export type RemoveMessageText = {\n type: "removeMessageText";\n } & TextMatch & MessageRoles;\n export type RewriteToolDescription = {\n type: "rewriteToolDescription";\n tool: string;\n append: string;\n };\n export type ReplaceToolDescription = {\n type: "replaceToolDescription";\n tool: string;\n description: string;\n };\n export type ReplaceToolSchema = {\n type: "replaceToolSchema";\n tool: string;\n inputSchema: {\n type: "object";\n [k: string]: unknown;\n };\n };\n export type RemoveTool = {\n type: "removeTool";\n tool: string;\n };\n export type RepairToolArgs = {\n type: "repairToolArgs";\n args: Record<string, unknown>;\n reason: string;\n };\n export type AppendText = {\n type: "appendText";\n text: string;\n };\n export type PrependText = {\n type: "prependText";\n text: string;\n };\n export type ReplaceText = {\n type: "replaceText";\n replace: string;\n } & TextMatch;\n export type RemoveText = {\n type: "removeText";\n } & TextMatch;\n export type InjectUserTurn = {\n type: "injectUserTurn";\n text: string;\n };\n export type AnnotateTurn = {\n type: "annotateTurn";\n key: string;\n value: JsonValue;\n };\n export type Warn = {\n type: "warn";\n message: string;\n };\n export type RequestAction = InjectSystemNote | AppendUserText | ReplaceMessageText | RemoveMessageText | RewriteToolDescription | ReplaceToolDescription | ReplaceToolSchema | RemoveTool | Warn;\n export type ToolCallAction = RepairToolArgs | Warn;\n export type RewriteAction = AppendText | PrependText | ReplaceText | RemoveText | Warn;\n export type ResponseEndAction = InjectSystemNote | InjectUserTurn | AnnotateTurn | Warn;\n export type SessionAction = InjectUserTurn | Warn;\n export type ObserveAction = Warn;\n export type HookAction = RequestAction | ToolCallAction | RewriteAction | ResponseEndAction | SessionAction;\n export type HookResult<A> = A[] | void | Promise<A[] | void>;\n export interface HookHandlers {\n request?(ctx: RequestContext): HookResult<RequestAction>;\n toolCall?: {\n /** tool names whose completed arguments this hook sees; "*" = every tool (costs streaming of all tool input) */\n tools: ReadonlyArray<string>;\n /** synchronous, per request; default true. false = not armed for this request */\n armed?(ctx: RequestContext): boolean;\n /** true = see the call after it was forwarded; can only warn; never holds the stream */\n observe?: boolean;\n handle(ctx: ToolCallContext): HookResult<ToolCallAction>;\n };\n responseRewrite?: {\n /** synchronous, per request, evaluated before the response starts; default true */\n claims?(ctx: RequestContext): boolean;\n handle(ctx: ResponseRewriteContext): HookResult<RewriteAction>;\n };\n responseEnd?(ctx: ResponseEndContext): HookResult<ResponseEndAction>;\n sessionStart?(ctx: SessionStartContext): HookResult<SessionAction>;\n sessionIdle?(ctx: SessionIdleContext): HookResult<SessionAction>;\n sessionBlocked?(ctx: SessionBlockedContext): HookResult<ObserveAction>;\n sessionEnd?(ctx: SessionEndContext): HookResult<ObserveAction>;\n }\n export interface RawProviderRequestContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n claudeRequest: any;\n messages: any[];\n tools: any[];\n }\n export interface RawProviderChunkContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n /** A clone of the parsed provider event. Whatever this field holds when the call returns is\n * what the parser reads from then on, so it may be edited in place or replaced. */\n chunk: any;\n /** The delta object inside `chunk` at call time (Responses wire: `chunk` itself). Edit it in\n * place; assigning a new object to this field has no effect. */\n delta: any;\n /** per-stream, shared across this hook\'s chunk calls; never cloned */\n metadata: Map<string, unknown>;\n }\n export interface RawProviderStreamEndContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n metadata: Map<string, unknown>;\n }\n export interface RawResponseContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n readonly request: RequestFacts;\n /** A replay of the current Claude-format response (SSE, or JSON for stream:false), read at the\n * hook\'s own pace. claudish drains the original itself, so leaving this unread delays nothing. */\n response: Response;\n }\n export interface RawMiddleware {\n /**\n * Receives clones. They replace the live request only when this call returns (or its promise\n * resolves) within its timeout. A throw, a rejection or a timeout discards every change.\n */\n providerRequest?(ctx: RawProviderRequestContext): void | Promise<void>;\n /**\n * MUST be synchronous. Called on the parser\'s loop, on a clone of the chunk. On a normal return\n * of anything but a thenable, the clone (whatever `ctx.chunk` holds then) is committed: it\n * becomes the object the parser reads, deletions included. On a throw nothing is committed.\n * A declared `async` function is rejected at load. Any other thenable return is an invalid\n * invocation: the clone is discarded even if the hook mutated it before returning, the call is\n * journaled `invalid` (`async_return`) and counts toward the circuit breaker, and a rejection\n * handler is attached, so a rejection is journaled `error` and never becomes an\n * unhandledRejection.\n */\n providerChunk?(ctx: RawProviderChunkContext): void;\n providerStreamEnd?(ctx: RawProviderStreamEndContext): void | Promise<void>;\n /**\n * Return a replacement Response, or nothing to keep the current one. A replacement is read\n * whole and forwarded only when it completes cleanly; on any failure the original is forwarded.\n * The client never sees a partial replacement. A replacement must close within this hook\'s\n * timeout after the later of this call\'s return and the end of the original; the original\'s end\n * never depends on whether `ctx.response` is read.\n */\n response?(ctx: RawResponseContext): Response | void | Promise<Response | void>;\n }\n interface HookBase {\n apiVersion: 1;\n id: string;\n description?: string;\n /** default "fix" for user hooks */\n defaultSeverity?: Severity;\n /** default "normal" */\n order?: HookOrder;\n /** globs on RouteInfo.modelId; default "*"; proxy events only */\n models?: string | ReadonlyArray<string>;\n /** default "all"; proxy events only */\n routes?: RouteScope;\n /** per call; clamped to the event\'s maximum and to the event budget left when the hook\'s turn comes */\n timeoutMs?: number;\n on?: HookHandlers;\n }\n export interface SafeHook extends HookBase {\n unsafe?: never;\n raw?: never;\n }\n export interface UnsafeHook extends HookBase {\n unsafe: true;\n raw: RawMiddleware;\n }\n /**\n * One hook. Module-level state is per process: in `create_session` and team\n * children, proxy events run in the pane child and session events in the MCP\n * server or CLI process. Pass per-turn data from proxy events to `sessionIdle`\n * with `annotateTurn`, never with module variables.\n */\n export type HookDefinition = SafeHook | UnsafeHook;\n /** Identity function: gives editor type-checking and inference. */\n export function defineHook<const H extends HookDefinition>(hook: H): H;\n /** Action constructors (plain data; equivalent to writing the object literal). */\n export const act: {\n injectSystemNote(text: string): InjectSystemNote;\n appendUserText(text: string): AppendUserText;\n replaceMessageText(find: string, replace: string, opts?: {\n regex?: boolean;\n flags?: string;\n roles?: ReadonlyArray<"user" | "assistant">;\n }): ReplaceMessageText;\n removeMessageText(find: string, opts?: {\n regex?: boolean;\n flags?: string;\n roles?: ReadonlyArray<"user" | "assistant">;\n }): RemoveMessageText;\n rewriteToolDescription(tool: string, append: string): RewriteToolDescription;\n replaceToolDescription(tool: string, description: string): ReplaceToolDescription;\n replaceToolSchema(tool: string, inputSchema: {\n type: "object";\n [k: string]: unknown;\n }): ReplaceToolSchema;\n removeTool(tool: string): RemoveTool;\n repairToolArgs(args: Record<string, unknown>, reason: string): RepairToolArgs;\n appendText(text: string): AppendText;\n prependText(text: string): PrependText;\n replaceText(find: string, replace: string, opts?: {\n regex?: boolean;\n flags?: string;\n }): ReplaceText;\n removeText(find: string, opts?: {\n regex?: boolean;\n flags?: string;\n }): RemoveText;\n injectUserTurn(text: string): InjectUserTurn;\n annotateTurn(key: string, value: JsonValue): AnnotateTurn;\n warn(message: string): Warn;\n };\n}\n';
|
|
134708
134231
|
|
|
134709
134232
|
// src/hooks/observer/corpus.ts
|
|
134710
|
-
import { appendFileSync as appendFileSync8, readFileSync as readFileSync56, readdirSync as
|
|
134711
|
-
import { homedir as
|
|
134712
|
-
import { join as
|
|
134233
|
+
import { appendFileSync as appendFileSync8, readFileSync as readFileSync56, readdirSync as readdirSync19, statSync as statSync30 } from "fs";
|
|
134234
|
+
import { homedir as homedir44 } from "os";
|
|
134235
|
+
import { join as join74 } from "path";
|
|
134713
134236
|
function directoryOf2(filePath) {
|
|
134714
134237
|
const slash = filePath.lastIndexOf("/");
|
|
134715
134238
|
return slash > 0 ? filePath.slice(0, slash) : undefined;
|
|
@@ -134783,18 +134306,18 @@ function listTranscripts(root) {
|
|
|
134783
134306
|
const files = [];
|
|
134784
134307
|
let projects;
|
|
134785
134308
|
try {
|
|
134786
|
-
projects =
|
|
134309
|
+
projects = readdirSync19(root);
|
|
134787
134310
|
} catch {
|
|
134788
134311
|
return files;
|
|
134789
134312
|
}
|
|
134790
134313
|
for (const project of projects) {
|
|
134791
|
-
const dir =
|
|
134314
|
+
const dir = join74(root, project);
|
|
134792
134315
|
try {
|
|
134793
|
-
if (!
|
|
134316
|
+
if (!statSync30(dir).isDirectory())
|
|
134794
134317
|
continue;
|
|
134795
|
-
for (const f of
|
|
134318
|
+
for (const f of readdirSync19(dir)) {
|
|
134796
134319
|
if (f.endsWith(".jsonl"))
|
|
134797
|
-
files.push(
|
|
134320
|
+
files.push(join74(dir, f));
|
|
134798
134321
|
}
|
|
134799
134322
|
} catch {}
|
|
134800
134323
|
}
|
|
@@ -134807,7 +134330,7 @@ function buildCorpus(options = {}) {
|
|
|
134807
134330
|
for (const f of files)
|
|
134808
134331
|
records.push(...replayTranscript(f));
|
|
134809
134332
|
if (options.write && records.length > 0) {
|
|
134810
|
-
const outputPath = options.outputPath ??
|
|
134333
|
+
const outputPath = options.outputPath ?? join74(homedir44(), ".claudish", "behavior-divergences.jsonl");
|
|
134811
134334
|
try {
|
|
134812
134335
|
appendFileSync8(outputPath, `${records.map((r) => JSON.stringify(r)).join(`
|
|
134813
134336
|
`)}
|
|
@@ -134824,9 +134347,9 @@ var init_corpus = __esm(() => {
|
|
|
134824
134347
|
});
|
|
134825
134348
|
|
|
134826
134349
|
// src/hooks-command.ts
|
|
134827
|
-
import { existsSync as existsSync46, mkdirSync as
|
|
134828
|
-
import { homedir as
|
|
134829
|
-
import { join as
|
|
134350
|
+
import { existsSync as existsSync46, mkdirSync as mkdirSync30, readFileSync as readFileSync57, writeFileSync as writeFileSync30 } from "fs";
|
|
134351
|
+
import { homedir as homedir45 } from "os";
|
|
134352
|
+
import { join as join75, resolve as resolve14 } from "path";
|
|
134830
134353
|
function severityColor(sev) {
|
|
134831
134354
|
if (sev === "fix")
|
|
134832
134355
|
return green(sev);
|
|
@@ -134949,10 +134472,10 @@ async function check(file, json) {
|
|
|
134949
134472
|
return valid ? 0 : 1;
|
|
134950
134473
|
}
|
|
134951
134474
|
function init(dirArg) {
|
|
134952
|
-
const dir = dirArg ? resolve14(process.cwd(), dirArg) :
|
|
134475
|
+
const dir = dirArg ? resolve14(process.cwd(), dirArg) : join75(homedir45(), ".claudish", "hooks");
|
|
134953
134476
|
const files = [
|
|
134954
|
-
[
|
|
134955
|
-
[
|
|
134477
|
+
[join75(dir, "example-hook.ts"), EXAMPLE_HOOK],
|
|
134478
|
+
[join75(dir, "claudish-hooks.d.ts"), HOOKS_AMBIENT_DTS]
|
|
134956
134479
|
];
|
|
134957
134480
|
const existing = files.filter(([path]) => existsSync46(path)).map(([path]) => path);
|
|
134958
134481
|
if (existing.length > 0) {
|
|
@@ -134960,7 +134483,7 @@ function init(dirArg) {
|
|
|
134960
134483
|
console.error(`${path} already exists; not overwriting it.`);
|
|
134961
134484
|
return 1;
|
|
134962
134485
|
}
|
|
134963
|
-
|
|
134486
|
+
mkdirSync30(dir, { recursive: true });
|
|
134964
134487
|
for (const [path, text] of files)
|
|
134965
134488
|
writeFileSync30(path, text, { flag: "wx" });
|
|
134966
134489
|
console.log(`
|
|
@@ -135152,10 +134675,10 @@ var init_hooks_command = __esm(() => {
|
|
|
135152
134675
|
});
|
|
135153
134676
|
|
|
135154
134677
|
// src/team-grid.ts
|
|
135155
|
-
import { spawn as
|
|
134678
|
+
import { spawn as spawn5 } from "child_process";
|
|
135156
134679
|
import { existsSync as existsSync47, readFileSync as readFileSync58, writeFileSync as writeFileSync31 } from "fs";
|
|
135157
134680
|
import { connect as netConnect3 } from "net";
|
|
135158
|
-
import { join as
|
|
134681
|
+
import { join as join76 } from "path";
|
|
135159
134682
|
import { setTimeout as wait } from "timers/promises";
|
|
135160
134683
|
function paneRouteLine(explanation) {
|
|
135161
134684
|
const origin = describeRouteExplanation(explanation);
|
|
@@ -135305,9 +134828,9 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
135305
134828
|
const keep = opts?.keep ?? false;
|
|
135306
134829
|
const manifest = setupSession(sessionPath, models, input);
|
|
135307
134830
|
const startedAt = new Date().toISOString();
|
|
135308
|
-
const gridfilePath =
|
|
135309
|
-
const prompt = readFileSync58(
|
|
135310
|
-
const rawPrompt = readFileSync58(
|
|
134831
|
+
const gridfilePath = join76(sessionPath, "gridfile.txt");
|
|
134832
|
+
const prompt = readFileSync58(join76(sessionPath, "input.md"), "utf-8").replace(/'/g, "'\\''").replace(/\n/g, " ");
|
|
134833
|
+
const rawPrompt = readFileSync58(join76(sessionPath, "input.md"), "utf-8");
|
|
135311
134834
|
const usedBannerColors = new Set;
|
|
135312
134835
|
const routeLines = mode === "interactive" ? new Map : await resolvePaneRouteLines(Object.values(manifest.models).map((entry) => entry.model));
|
|
135313
134836
|
const gridLines = Object.entries(manifest.models).map(([anonId]) => {
|
|
@@ -135327,7 +134850,7 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
135327
134850
|
if (!keep && mode === "default") {
|
|
135328
134851
|
spawnArgs.push("-w");
|
|
135329
134852
|
}
|
|
135330
|
-
const proc =
|
|
134853
|
+
const proc = spawn5(magmuxPath, spawnArgs, {
|
|
135331
134854
|
stdio: "inherit",
|
|
135332
134855
|
env: { ...process.env }
|
|
135333
134856
|
});
|
|
@@ -135339,7 +134862,7 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
135339
134862
|
});
|
|
135340
134863
|
const [{ results }] = await Promise.all([subscription, procExit]);
|
|
135341
134864
|
const status = buildTeamStatus(manifest, startedAt, results?.panes ?? null);
|
|
135342
|
-
const statusPath =
|
|
134865
|
+
const statusPath = join76(sessionPath, "status.json");
|
|
135343
134866
|
writeFileSync31(statusPath, JSON.stringify(status, null, 2), "utf-8");
|
|
135344
134867
|
return status;
|
|
135345
134868
|
}
|
|
@@ -135360,7 +134883,7 @@ var init_team_grid = __esm(() => {
|
|
|
135360
134883
|
|
|
135361
134884
|
// src/team-cli.ts
|
|
135362
134885
|
import { readFileSync as readFileSync59 } from "fs";
|
|
135363
|
-
import { join as
|
|
134886
|
+
import { join as join77 } from "path";
|
|
135364
134887
|
async function runPaneTeam(sessionPath, models, input, opts) {
|
|
135365
134888
|
installPaneShutdownHooks({ exitAfter: true });
|
|
135366
134889
|
try {
|
|
@@ -135505,7 +135028,7 @@ async function teamCommand(args) {
|
|
|
135505
135028
|
}
|
|
135506
135029
|
case "judge": {
|
|
135507
135030
|
await judgeResponses(sessionPath, { judges });
|
|
135508
|
-
console.log(readFileSync59(
|
|
135031
|
+
console.log(readFileSync59(join77(sessionPath, "verdict.md"), "utf-8"));
|
|
135509
135032
|
break;
|
|
135510
135033
|
}
|
|
135511
135034
|
case "run-and-judge": {
|
|
@@ -135521,7 +135044,7 @@ async function teamCommand(args) {
|
|
|
135521
135044
|
});
|
|
135522
135045
|
printStatus(status);
|
|
135523
135046
|
await judgeResponses(sessionPath, { judges });
|
|
135524
|
-
console.log(readFileSync59(
|
|
135047
|
+
console.log(readFileSync59(join77(sessionPath, "verdict.md"), "utf-8"));
|
|
135525
135048
|
break;
|
|
135526
135049
|
}
|
|
135527
135050
|
case "status": {
|
|
@@ -137204,9 +136727,9 @@ var init_view_cli = __esm(() => {
|
|
|
137204
136727
|
|
|
137205
136728
|
// src/herdr/herdr-cli.ts
|
|
137206
136729
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
137207
|
-
import { copyFileSync as copyFileSync3, existsSync as existsSync48, mkdirSync as
|
|
137208
|
-
import { homedir as
|
|
137209
|
-
import { dirname as
|
|
136730
|
+
import { copyFileSync as copyFileSync3, existsSync as existsSync48, mkdirSync as mkdirSync31, readdirSync as readdirSync20, renameSync as renameSync15, statSync as statSync31 } from "fs";
|
|
136731
|
+
import { homedir as homedir46 } from "os";
|
|
136732
|
+
import { dirname as dirname31, join as join78, resolve as resolve15 } from "path";
|
|
137210
136733
|
function spawnHerdrApp(args) {
|
|
137211
136734
|
const r = spawnSync4("herdr-app", args, { encoding: "utf-8", timeout: 1e4 });
|
|
137212
136735
|
if (r.error)
|
|
@@ -137248,10 +136771,10 @@ function showPanelCommand(rest, out, deps) {
|
|
|
137248
136771
|
function findBuiltAppMod(from = import.meta.dir) {
|
|
137249
136772
|
let dir = from;
|
|
137250
136773
|
for (let i = 0;i < 5; i++) {
|
|
137251
|
-
const candidate =
|
|
137252
|
-
if (existsSync48(
|
|
136774
|
+
const candidate = join78(dir, BUILT_MOD_DIR);
|
|
136775
|
+
if (existsSync48(join78(candidate, "main.js")) && existsSync48(join78(candidate, "mod.json")))
|
|
137253
136776
|
return candidate;
|
|
137254
|
-
const up =
|
|
136777
|
+
const up = dirname31(dir);
|
|
137255
136778
|
if (up === dir)
|
|
137256
136779
|
break;
|
|
137257
136780
|
dir = up;
|
|
@@ -137262,24 +136785,24 @@ function herdrAppHome(env) {
|
|
|
137262
136785
|
const given = env.HERDR_APP_HOME?.trim();
|
|
137263
136786
|
if (given)
|
|
137264
136787
|
return resolve15(given);
|
|
137265
|
-
return
|
|
136788
|
+
return join78(env.HOME?.trim() || homedir46(), ".config", "herdr-app");
|
|
137266
136789
|
}
|
|
137267
136790
|
function isModFile(name) {
|
|
137268
136791
|
return !name.startsWith(".") && name !== "jsconfig.json" && !name.endsWith(".d.ts");
|
|
137269
136792
|
}
|
|
137270
136793
|
function installAppMod(source, appHome) {
|
|
137271
|
-
if (!existsSync48(
|
|
136794
|
+
if (!existsSync48(join78(source, "main.js")) || !existsSync48(join78(source, "mod.json")))
|
|
137272
136795
|
throw new Error(`${source} holds no built mod (main.js and mod.json); run \`bun run build\``);
|
|
137273
|
-
if (!existsSync48(appHome) || !
|
|
136796
|
+
if (!existsSync48(appHome) || !statSync31(appHome).isDirectory())
|
|
137274
136797
|
throw new Error(`${appHome} does not exist: start Herdr.app once so it creates its home, then run this again`);
|
|
137275
|
-
const dest =
|
|
137276
|
-
|
|
137277
|
-
const files =
|
|
136798
|
+
const dest = join78(appHome, "mods", APP_MOD_NAME);
|
|
136799
|
+
mkdirSync31(dest, { recursive: true });
|
|
136800
|
+
const files = readdirSync20(source).filter((f) => isModFile(f) && statSync31(join78(source, f)).isFile());
|
|
137278
136801
|
files.sort((a, b) => a === "mod.json" ? -1 : b === "mod.json" ? 1 : a.localeCompare(b));
|
|
137279
136802
|
for (const f of files) {
|
|
137280
|
-
const hidden =
|
|
137281
|
-
copyFileSync3(
|
|
137282
|
-
|
|
136803
|
+
const hidden = join78(dest, `.${f}.installing`);
|
|
136804
|
+
copyFileSync3(join78(source, f), hidden);
|
|
136805
|
+
renameSync15(hidden, join78(dest, f));
|
|
137283
136806
|
}
|
|
137284
136807
|
return dest;
|
|
137285
136808
|
}
|
|
@@ -137357,7 +136880,7 @@ var init_herdr_cli = __esm(() => {
|
|
|
137357
136880
|
""
|
|
137358
136881
|
].join(`
|
|
137359
136882
|
`);
|
|
137360
|
-
BUILT_MOD_DIR =
|
|
136883
|
+
BUILT_MOD_DIR = join78("herdr-app-mod", APP_MOD_NAME);
|
|
137361
136884
|
});
|
|
137362
136885
|
|
|
137363
136886
|
// src/auth/credentials/source.ts
|
|
@@ -139718,9 +139241,9 @@ var init_account_command = __esm(() => {
|
|
|
139718
139241
|
|
|
139719
139242
|
// src/auth/antigravity-oauth.ts
|
|
139720
139243
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
139721
|
-
import { existsSync as existsSync49, unlinkSync as
|
|
139722
|
-
import { homedir as
|
|
139723
|
-
import { join as
|
|
139244
|
+
import { existsSync as existsSync49, unlinkSync as unlinkSync15 } from "fs";
|
|
139245
|
+
import { homedir as homedir47 } from "os";
|
|
139246
|
+
import { join as join79 } from "path";
|
|
139724
139247
|
async function defaultSuggestModel() {
|
|
139725
139248
|
try {
|
|
139726
139249
|
const token = await getValidAntigravityAccessToken();
|
|
@@ -139839,9 +139362,9 @@ No session detected yet. Starting the Antigravity CLI interactively \u2014
|
|
|
139839
139362
|
async logout(deps) {
|
|
139840
139363
|
deleteSharedAntigravityToken(deps);
|
|
139841
139364
|
try {
|
|
139842
|
-
const tokenFile =
|
|
139365
|
+
const tokenFile = join79(homedir47(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
139843
139366
|
if (existsSync49(tokenFile))
|
|
139844
|
-
|
|
139367
|
+
unlinkSync15(tokenFile);
|
|
139845
139368
|
} catch {}
|
|
139846
139369
|
log("[AntigravityOAuth] Antigravity session cleared (keychain + agy token file)");
|
|
139847
139370
|
}
|
|
@@ -149254,18 +148777,18 @@ var init_model_lineup = __esm(() => {
|
|
|
149254
148777
|
});
|
|
149255
148778
|
|
|
149256
148779
|
// src/diag-output.ts
|
|
149257
|
-
import { createWriteStream as createWriteStream2, mkdirSync as
|
|
149258
|
-
import { homedir as
|
|
149259
|
-
import { join as
|
|
148780
|
+
import { createWriteStream as createWriteStream2, mkdirSync as mkdirSync32, unlinkSync as unlinkSync16, writeFileSync as writeFileSync32 } from "fs";
|
|
148781
|
+
import { homedir as homedir48 } from "os";
|
|
148782
|
+
import { join as join80 } from "path";
|
|
149260
148783
|
function getClaudishDir() {
|
|
149261
|
-
const dir =
|
|
148784
|
+
const dir = join80(homedir48(), ".claudish");
|
|
149262
148785
|
try {
|
|
149263
|
-
|
|
148786
|
+
mkdirSync32(dir, { recursive: true });
|
|
149264
148787
|
} catch {}
|
|
149265
148788
|
return dir;
|
|
149266
148789
|
}
|
|
149267
148790
|
function getDiagLogPath() {
|
|
149268
|
-
return
|
|
148791
|
+
return join80(getClaudishDir(), `diag-${process.pid}.log`);
|
|
149269
148792
|
}
|
|
149270
148793
|
|
|
149271
148794
|
class LogFileDiagOutput {
|
|
@@ -149293,7 +148816,7 @@ class LogFileDiagOutput {
|
|
|
149293
148816
|
this.stream.end();
|
|
149294
148817
|
} catch {}
|
|
149295
148818
|
try {
|
|
149296
|
-
|
|
148819
|
+
unlinkSync16(this.logPath);
|
|
149297
148820
|
} catch {}
|
|
149298
148821
|
}
|
|
149299
148822
|
getLogPath() {
|
|
@@ -149676,7 +149199,7 @@ var init_advisor_startup = __esm(() => {
|
|
|
149676
149199
|
});
|
|
149677
149200
|
|
|
149678
149201
|
// src/session/conversation.ts
|
|
149679
|
-
import { closeSync as
|
|
149202
|
+
import { closeSync as closeSync24, openSync as openSync23, readSync as readSync12, statSync as statSync32 } from "fs";
|
|
149680
149203
|
import { StringDecoder } from "string_decoder";
|
|
149681
149204
|
function looksLikeTurn(line) {
|
|
149682
149205
|
const assistant = line.includes('"type":"assistant"');
|
|
@@ -149731,8 +149254,8 @@ function readConversation(file, opts = {}) {
|
|
|
149731
149254
|
};
|
|
149732
149255
|
let fd = null;
|
|
149733
149256
|
try {
|
|
149734
|
-
const size =
|
|
149735
|
-
fd =
|
|
149257
|
+
const size = statSync32(file).size;
|
|
149258
|
+
fd = openSync23(file, "r");
|
|
149736
149259
|
const buf = Buffer.allocUnsafe(chunkBytes);
|
|
149737
149260
|
const decoder = new StringDecoder("utf-8");
|
|
149738
149261
|
let pending = "";
|
|
@@ -149764,7 +149287,7 @@ function readConversation(file, opts = {}) {
|
|
|
149764
149287
|
take({ role: raw.role, text, elided });
|
|
149765
149288
|
};
|
|
149766
149289
|
while (pos < size) {
|
|
149767
|
-
const n =
|
|
149290
|
+
const n = readSync12(fd, buf, 0, Math.min(chunkBytes, size - pos), pos);
|
|
149768
149291
|
if (n <= 0)
|
|
149769
149292
|
break;
|
|
149770
149293
|
pos += n;
|
|
@@ -149788,7 +149311,7 @@ function readConversation(file, opts = {}) {
|
|
|
149788
149311
|
} catch {} finally {
|
|
149789
149312
|
if (fd !== null) {
|
|
149790
149313
|
try {
|
|
149791
|
-
|
|
149314
|
+
closeSync24(fd);
|
|
149792
149315
|
} catch {}
|
|
149793
149316
|
}
|
|
149794
149317
|
}
|
|
@@ -151356,11 +150879,11 @@ var init_resume_picker_run = __esm(() => {
|
|
|
151356
150879
|
});
|
|
151357
150880
|
|
|
151358
150881
|
// src/launcher/model-setting-ledger-path.ts
|
|
151359
|
-
import { homedir as
|
|
151360
|
-
import { join as
|
|
150882
|
+
import { homedir as homedir49 } from "os";
|
|
150883
|
+
import { join as join81 } from "path";
|
|
151361
150884
|
function modelSettingLedgerPath(env = process.env) {
|
|
151362
|
-
const home = env.HOME && env.HOME.length > 0 ? env.HOME :
|
|
151363
|
-
return
|
|
150885
|
+
const home = env.HOME && env.HOME.length > 0 ? env.HOME : homedir49();
|
|
150886
|
+
return join81(home, ".claudish", MODEL_SETTING_LEDGER_FILE);
|
|
151364
150887
|
}
|
|
151365
150888
|
var MODEL_SETTING_LEDGER_FILE = "model-setting-restore.json";
|
|
151366
150889
|
var init_model_setting_ledger_path = () => {};
|
|
@@ -151368,32 +150891,32 @@ var init_model_setting_ledger_path = () => {};
|
|
|
151368
150891
|
// src/launcher/model-setting-restore.ts
|
|
151369
150892
|
import { randomUUID as randomUUID12 } from "crypto";
|
|
151370
150893
|
import {
|
|
151371
|
-
closeSync as
|
|
150894
|
+
closeSync as closeSync25,
|
|
151372
150895
|
fchmodSync as fchmodSync2,
|
|
151373
|
-
fsyncSync as
|
|
151374
|
-
openSync as
|
|
150896
|
+
fsyncSync as fsyncSync5,
|
|
150897
|
+
openSync as openSync24,
|
|
151375
150898
|
readFileSync as readFileSync60,
|
|
151376
|
-
readdirSync as
|
|
151377
|
-
realpathSync as
|
|
151378
|
-
renameSync as
|
|
151379
|
-
rmSync as
|
|
151380
|
-
statSync as
|
|
151381
|
-
unlinkSync as
|
|
151382
|
-
writeSync as
|
|
150899
|
+
readdirSync as readdirSync21,
|
|
150900
|
+
realpathSync as realpathSync14,
|
|
150901
|
+
renameSync as renameSync16,
|
|
150902
|
+
rmSync as rmSync22,
|
|
150903
|
+
statSync as statSync33,
|
|
150904
|
+
unlinkSync as unlinkSync17,
|
|
150905
|
+
writeSync as writeSync9
|
|
151383
150906
|
} from "fs";
|
|
151384
|
-
import { homedir as
|
|
151385
|
-
import { basename as
|
|
150907
|
+
import { homedir as homedir50 } from "os";
|
|
150908
|
+
import { basename as basename14, dirname as dirname32, join as join82, resolve as resolve16 } from "path";
|
|
151386
150909
|
function canonicalSettingsPath(path) {
|
|
151387
150910
|
let head = resolve16(path);
|
|
151388
150911
|
const rest = [];
|
|
151389
150912
|
for (;; ) {
|
|
151390
150913
|
try {
|
|
151391
|
-
return
|
|
150914
|
+
return join82(realpathSync14.native(head), ...rest);
|
|
151392
150915
|
} catch {
|
|
151393
|
-
const parent =
|
|
150916
|
+
const parent = dirname32(head);
|
|
151394
150917
|
if (parent === head)
|
|
151395
|
-
return
|
|
151396
|
-
rest.unshift(
|
|
150918
|
+
return join82(head, ...rest);
|
|
150919
|
+
rest.unshift(basename14(head));
|
|
151397
150920
|
head = parent;
|
|
151398
150921
|
}
|
|
151399
150922
|
}
|
|
@@ -151414,7 +150937,7 @@ function toFileStat(s) {
|
|
|
151414
150937
|
function sameStat(a, b) {
|
|
151415
150938
|
return a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.mode === b.mode;
|
|
151416
150939
|
}
|
|
151417
|
-
function writeWholeSync(fd, data, write = (f, b, o, l) =>
|
|
150940
|
+
function writeWholeSync(fd, data, write = (f, b, o, l) => writeSync9(f, b, o, l)) {
|
|
151418
150941
|
const bytes = Buffer.from(data, "utf8");
|
|
151419
150942
|
let offset = 0;
|
|
151420
150943
|
while (offset < bytes.length) {
|
|
@@ -151432,7 +150955,7 @@ function detectIndent(text) {
|
|
|
151432
150955
|
const m = text.match(/^\{\s*?\n([ \t]+)\S/);
|
|
151433
150956
|
return m?.[1] ? m[1] : 2;
|
|
151434
150957
|
}
|
|
151435
|
-
function
|
|
150958
|
+
function isPlainObject10(value) {
|
|
151436
150959
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
151437
150960
|
}
|
|
151438
150961
|
function restoreSettingsFile(settingsKey, entry, deps = realRestoreFs, fence = () => true) {
|
|
@@ -151456,7 +150979,7 @@ function nextSettingsText(text, entry) {
|
|
|
151456
150979
|
} catch {
|
|
151457
150980
|
return { outcome: "unparsable" };
|
|
151458
150981
|
}
|
|
151459
|
-
if (!
|
|
150982
|
+
if (!isPlainObject10(parsed))
|
|
151460
150983
|
return { outcome: "unparsable" };
|
|
151461
150984
|
const decision = restoreDecision(parsed.model, entry);
|
|
151462
150985
|
if (decision.action === "leave")
|
|
@@ -151488,7 +151011,7 @@ function restoreRound(settingsKey, target, entry, deps, fence) {
|
|
|
151488
151011
|
const planned = nextSettingsText(text, entry);
|
|
151489
151012
|
if ("outcome" in planned)
|
|
151490
151013
|
return planned.outcome;
|
|
151491
|
-
const temp =
|
|
151014
|
+
const temp = join82(dirname32(target), `${TEMP_PREFIX}${deps.pid ?? process.pid}-${randomUUID12()}`);
|
|
151492
151015
|
try {
|
|
151493
151016
|
deps.writeNew(temp, planned.next, statA.mode & 4095);
|
|
151494
151017
|
} catch {
|
|
@@ -151535,7 +151058,7 @@ function readLedger2(path) {
|
|
|
151535
151058
|
log(`[model-restore] ledger unparsable (${path}): ${err.message}`);
|
|
151536
151059
|
return { ok: false, reason: "unparsable" };
|
|
151537
151060
|
}
|
|
151538
|
-
if (parsed?.version !== 1 || !
|
|
151061
|
+
if (parsed?.version !== 1 || !isPlainObject10(parsed.entries)) {
|
|
151539
151062
|
log(`[model-restore] ledger of unknown shape (${path})`);
|
|
151540
151063
|
return { ok: false, reason: "unknown-shape" };
|
|
151541
151064
|
}
|
|
@@ -151554,7 +151077,7 @@ function writeLedger(path, ledger, fence) {
|
|
|
151554
151077
|
return false;
|
|
151555
151078
|
}
|
|
151556
151079
|
if (Object.keys(ledger.entries).length === 0) {
|
|
151557
|
-
|
|
151080
|
+
rmSync22(path, { force: true });
|
|
151558
151081
|
return true;
|
|
151559
151082
|
}
|
|
151560
151083
|
atomicWriteFileSync(path, `${JSON.stringify(ledger, null, 2)}
|
|
@@ -151659,14 +151182,14 @@ function settleEntry(ctx, ledger, key, silent, fence) {
|
|
|
151659
151182
|
}
|
|
151660
151183
|
}
|
|
151661
151184
|
function removeOrphanTemps(ctx, key, table) {
|
|
151662
|
-
const dirs = new Set([
|
|
151185
|
+
const dirs = new Set([dirname32(key)]);
|
|
151663
151186
|
try {
|
|
151664
|
-
dirs.add(
|
|
151187
|
+
dirs.add(dirname32(ctx.fs.realpath(key)));
|
|
151665
151188
|
} catch {}
|
|
151666
151189
|
for (const dir of dirs) {
|
|
151667
151190
|
let names;
|
|
151668
151191
|
try {
|
|
151669
|
-
names =
|
|
151192
|
+
names = readdirSync21(dir);
|
|
151670
151193
|
} catch {
|
|
151671
151194
|
continue;
|
|
151672
151195
|
}
|
|
@@ -151680,7 +151203,7 @@ function removeOrphanTemps(ctx, key, table) {
|
|
|
151680
151203
|
if (live)
|
|
151681
151204
|
continue;
|
|
151682
151205
|
try {
|
|
151683
|
-
|
|
151206
|
+
unlinkSync17(join82(dir, name));
|
|
151684
151207
|
} catch {}
|
|
151685
151208
|
}
|
|
151686
151209
|
}
|
|
@@ -151758,7 +151281,7 @@ function readOriginal(ctx, key) {
|
|
|
151758
151281
|
}
|
|
151759
151282
|
try {
|
|
151760
151283
|
const parsed = JSON.parse(text);
|
|
151761
|
-
if (!
|
|
151284
|
+
if (!isPlainObject10(parsed))
|
|
151762
151285
|
return null;
|
|
151763
151286
|
return "model" in parsed ? { present: true, value: parsed.model } : { present: false };
|
|
151764
151287
|
} catch {
|
|
@@ -151771,7 +151294,7 @@ function selfStartEpochMs() {
|
|
|
151771
151294
|
async function beginModelSettingWatch(listedSpecs, deps = {}) {
|
|
151772
151295
|
const ctx = contextOf(deps);
|
|
151773
151296
|
const env = deps.env ?? process.env;
|
|
151774
|
-
const settingsFile = deps.settingsFile ?? userSettingsFile(env.CLAUDE_CONFIG_DIR, env.HOME && env.HOME.length > 0 ? env.HOME :
|
|
151297
|
+
const settingsFile = deps.settingsFile ?? userSettingsFile(env.CLAUDE_CONFIG_DIR, env.HOME && env.HOME.length > 0 ? env.HOME : homedir50(), deps.cwd ?? process.cwd());
|
|
151775
151298
|
const key = canonicalSettingsPath(settingsFile);
|
|
151776
151299
|
const lockPath = lockPathOf(ctx.ledgerPath);
|
|
151777
151300
|
const lockOpts = {
|
|
@@ -151934,21 +151457,21 @@ var init_model_setting_restore = __esm(() => {
|
|
|
151934
151457
|
init_model_setting_ledger_path();
|
|
151935
151458
|
GIVE_UP_AFTER_MS = 14 * 24 * 60 * 60 * 1000;
|
|
151936
151459
|
realRestoreFs = {
|
|
151937
|
-
realpath: (path) =>
|
|
151460
|
+
realpath: (path) => realpathSync14.native(path),
|
|
151938
151461
|
readFile: (path) => readFileSync60(path),
|
|
151939
|
-
stat: (path) => toFileStat(
|
|
151462
|
+
stat: (path) => toFileStat(statSync33(path)),
|
|
151940
151463
|
writeNew: (path, data, mode) => {
|
|
151941
|
-
const fd =
|
|
151464
|
+
const fd = openSync24(path, "wx", mode);
|
|
151942
151465
|
try {
|
|
151943
151466
|
fchmodSync2(fd, mode);
|
|
151944
151467
|
writeWholeSync(fd, data);
|
|
151945
|
-
|
|
151468
|
+
fsyncSync5(fd);
|
|
151946
151469
|
} finally {
|
|
151947
|
-
|
|
151470
|
+
closeSync25(fd);
|
|
151948
151471
|
}
|
|
151949
151472
|
},
|
|
151950
|
-
rename: (from, to) =>
|
|
151951
|
-
unlink: (path) =>
|
|
151473
|
+
rename: (from, to) => renameSync16(from, to),
|
|
151474
|
+
unlink: (path) => unlinkSync17(path)
|
|
151952
151475
|
};
|
|
151953
151476
|
reportedUnreadableLedgers = new Set;
|
|
151954
151477
|
INERT_WATCH = {
|
|
@@ -151961,8 +151484,8 @@ var init_model_setting_restore = __esm(() => {
|
|
|
151961
151484
|
});
|
|
151962
151485
|
|
|
151963
151486
|
// src/session/baseline-pricing.ts
|
|
151964
|
-
function resolveBaseline(
|
|
151965
|
-
const entry =
|
|
151487
|
+
function resolveBaseline({ tier, label }) {
|
|
151488
|
+
const entry = implicitAnthropicTierEntry(tier);
|
|
151966
151489
|
if (!entry)
|
|
151967
151490
|
return null;
|
|
151968
151491
|
const firstParty = entry.aggregators?.find((a) => catalogRouteMatchesProvider(a.route, FIRST_PARTY) && typeof a.pricing?.input === "number");
|
|
@@ -151975,18 +151498,18 @@ function resolveBaseline(alias, label) {
|
|
|
151975
151498
|
return { modelId: entry.modelId, label, inputPerM: input, outputPerM: output };
|
|
151976
151499
|
}
|
|
151977
151500
|
function getBaselines() {
|
|
151978
|
-
return
|
|
151501
|
+
return BASELINE_TIERS.map(resolveBaseline).filter((b) => b !== null);
|
|
151979
151502
|
}
|
|
151980
151503
|
function baselineCost(b, inputTokens, outputTokens) {
|
|
151981
151504
|
return inputTokens / 1e6 * b.inputPerM + outputTokens / 1e6 * b.outputPerM;
|
|
151982
151505
|
}
|
|
151983
|
-
var
|
|
151506
|
+
var BASELINE_TIERS, FIRST_PARTY = "anthropic";
|
|
151984
151507
|
var init_baseline_pricing = __esm(() => {
|
|
151508
|
+
init_catalog_client();
|
|
151985
151509
|
init_catalog_route_bindings();
|
|
151986
|
-
|
|
151987
|
-
|
|
151988
|
-
{
|
|
151989
|
-
{ alias: "~anthropic/claude-opus-latest", label: "Opus" }
|
|
151510
|
+
BASELINE_TIERS = [
|
|
151511
|
+
{ tier: "sonnet", label: "Sonnet" },
|
|
151512
|
+
{ tier: "opus", label: "Opus" }
|
|
151990
151513
|
];
|
|
151991
151514
|
});
|
|
151992
151515
|
|
|
@@ -152384,10 +151907,11 @@ var droppedAtLaunch = dropAtLaunch();
|
|
|
152384
151907
|
init_child_env();
|
|
152385
151908
|
init_launch_env();
|
|
152386
151909
|
init_op_source();
|
|
151910
|
+
init_classifier_passthrough();
|
|
152387
151911
|
init_startup_trace();
|
|
152388
151912
|
init_picker_cancelled();
|
|
152389
151913
|
import { existsSync as existsSync50, readFileSync as readFileSync62 } from "fs";
|
|
152390
|
-
import { join as
|
|
151914
|
+
import { join as join83, resolve as resolve17 } from "path";
|
|
152391
151915
|
|
|
152392
151916
|
// src/tui/runtime/should-open-picker.ts
|
|
152393
151917
|
function noModelConfigured(gate) {
|
|
@@ -152404,7 +151928,7 @@ function requiresExplicitModel(gate, tty) {
|
|
|
152404
151928
|
var autoloadDropped = [...droppedAtLaunch, ...takeLauncherDropped(process.env)];
|
|
152405
151929
|
var dotenvText;
|
|
152406
151930
|
try {
|
|
152407
|
-
dotenvText = readFileSync62(
|
|
151931
|
+
dotenvText = readFileSync62(join83(process.cwd(), ".env"));
|
|
152408
151932
|
} catch {}
|
|
152409
151933
|
if (dotenvText !== undefined) {
|
|
152410
151934
|
await Promise.resolve().then(() => init_dotenv_allowlist());
|
|
@@ -152810,7 +152334,7 @@ async function runCli() {
|
|
|
152810
152334
|
process.exit(1);
|
|
152811
152335
|
}
|
|
152812
152336
|
const mode = cliConfig.teamMode ?? "default";
|
|
152813
|
-
const sessionPath =
|
|
152337
|
+
const sessionPath = join83(process.cwd(), `.claudish-team-${Date.now()}`);
|
|
152814
152338
|
if (mode === "json") {
|
|
152815
152339
|
await Promise.resolve().then(() => init_pane());
|
|
152816
152340
|
await Promise.resolve().then(() => init_team_orchestrator());
|
|
@@ -152830,7 +152354,7 @@ async function runCli() {
|
|
|
152830
152354
|
const status = await runModels(sessionPath);
|
|
152831
152355
|
const result = { ...status, responses: {} };
|
|
152832
152356
|
for (const anonId of Object.keys(status.models)) {
|
|
152833
|
-
const responsePath =
|
|
152357
|
+
const responsePath = join83(sessionPath, `response-${anonId}.md`);
|
|
152834
152358
|
try {
|
|
152835
152359
|
const raw = readFileSync62(responsePath, "utf-8").trim();
|
|
152836
152360
|
try {
|