claudish 14.29.2 → 14.29.3
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 +2385 -504
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -5542,7 +5542,7 @@ var init_env_placeholder = __esm(() => {
|
|
|
5542
5542
|
});
|
|
5543
5543
|
|
|
5544
5544
|
// src/version.ts
|
|
5545
|
-
var VERSION = "14.29.
|
|
5545
|
+
var VERSION = "14.29.3";
|
|
5546
5546
|
|
|
5547
5547
|
// src/redact.ts
|
|
5548
5548
|
function isPlaceholder(value) {
|
|
@@ -14123,7 +14123,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14123
14123
|
}
|
|
14124
14124
|
}
|
|
14125
14125
|
},
|
|
14126
|
-
fetchedAt: "2026-11-
|
|
14126
|
+
fetchedAt: "2026-11-28T11:55:53.655Z",
|
|
14127
14127
|
format: 1,
|
|
14128
14128
|
recommendations: {
|
|
14129
14129
|
contractVersion: 3,
|
|
@@ -14229,11 +14229,11 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14229
14229
|
tier: "luxury"
|
|
14230
14230
|
}
|
|
14231
14231
|
],
|
|
14232
|
-
generationId: "g-
|
|
14232
|
+
generationId: "g-20261127161649657-d819d8a0"
|
|
14233
14233
|
},
|
|
14234
14234
|
source: "https://us-central1-claudish-6da10.cloudfunctions.net"
|
|
14235
14235
|
},
|
|
14236
|
-
catalogGenerationId: "g-
|
|
14236
|
+
catalogGenerationId: "g-20261127161649657-d819d8a0",
|
|
14237
14237
|
entries: [
|
|
14238
14238
|
{
|
|
14239
14239
|
aggregators: [
|
|
@@ -14807,9 +14807,9 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14807
14807
|
],
|
|
14808
14808
|
aliases: [
|
|
14809
14809
|
"anthropic/claude-opus-5.5",
|
|
14810
|
-
"claude-opus-5-5-medium",
|
|
14811
|
-
"claude-opus-5-5-high",
|
|
14812
14810
|
"claude-opus-5-5-low",
|
|
14811
|
+
"claude-opus-5-5-high",
|
|
14812
|
+
"claude-opus-5-5-medium",
|
|
14813
14813
|
"claude-opus-5-5-max",
|
|
14814
14814
|
"claude-opus-5-5-xhigh"
|
|
14815
14815
|
],
|
|
@@ -15000,8 +15000,8 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15000
15000
|
aliases: [
|
|
15001
15001
|
"anthropic/claude-sonnet-5.5",
|
|
15002
15002
|
"claude-sonnet-5.5",
|
|
15003
|
-
"claude-sonnet-5-5-medium",
|
|
15004
15003
|
"claude-sonnet-5-5-high",
|
|
15004
|
+
"claude-sonnet-5-5-medium",
|
|
15005
15005
|
"claude-sonnet-5-5-low",
|
|
15006
15006
|
"claude-sonnet-5-5-max",
|
|
15007
15007
|
"claude-sonnet-5-5-xhigh"
|
|
@@ -15267,8 +15267,8 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15267
15267
|
aliases: [
|
|
15268
15268
|
"google/gemini-4-carbon",
|
|
15269
15269
|
"gemini-4-carbon-low",
|
|
15270
|
-
"gemini-4-carbon-
|
|
15271
|
-
"gemini-4-carbon-
|
|
15270
|
+
"gemini-4-carbon-high",
|
|
15271
|
+
"gemini-4-carbon-medium"
|
|
15272
15272
|
],
|
|
15273
15273
|
contextWindow: 1048576,
|
|
15274
15274
|
contractVersion: 3,
|
|
@@ -15421,10 +15421,10 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
15421
15421
|
],
|
|
15422
15422
|
aliases: [
|
|
15423
15423
|
"google/gemini-4-hydrogen",
|
|
15424
|
-
"gemini-4-hydrogen-medium",
|
|
15425
15424
|
"gemini-4-hydrogen-low",
|
|
15425
|
+
"gemini-4-hydrogen-xhigh",
|
|
15426
15426
|
"gemini-4-hydrogen-high",
|
|
15427
|
-
"gemini-4-hydrogen-
|
|
15427
|
+
"gemini-4-hydrogen-medium"
|
|
15428
15428
|
],
|
|
15429
15429
|
contextWindow: 1048576,
|
|
15430
15430
|
contractVersion: 3,
|
|
@@ -18306,7 +18306,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
18306
18306
|
videoOutput: false
|
|
18307
18307
|
}
|
|
18308
18308
|
],
|
|
18309
|
-
lastUpdated: "2026-11-
|
|
18309
|
+
lastUpdated: "2026-11-27T16:16:49.657Z",
|
|
18310
18310
|
models: [],
|
|
18311
18311
|
plans: [
|
|
18312
18312
|
{
|
|
@@ -18967,174 +18967,174 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
18967
18967
|
id: "google-antigravity",
|
|
18968
18968
|
inclusions: [
|
|
18969
18969
|
{
|
|
18970
|
-
externalModelId: "gemini-4-
|
|
18970
|
+
externalModelId: "gemini-4-carbon-low",
|
|
18971
18971
|
kind: "provider_model",
|
|
18972
18972
|
provider: "antigravity",
|
|
18973
18973
|
resolution: {
|
|
18974
|
-
modelId: "gemini-4-
|
|
18974
|
+
modelId: "gemini-4-carbon",
|
|
18975
18975
|
status: "mapped"
|
|
18976
18976
|
},
|
|
18977
|
-
sourceText: "gemini-4-
|
|
18977
|
+
sourceText: "gemini-4-carbon-low"
|
|
18978
18978
|
},
|
|
18979
18979
|
{
|
|
18980
|
-
externalModelId: "
|
|
18980
|
+
externalModelId: "claude-opus-5-5-low",
|
|
18981
18981
|
kind: "provider_model",
|
|
18982
18982
|
provider: "antigravity",
|
|
18983
18983
|
resolution: {
|
|
18984
|
-
modelId: "
|
|
18984
|
+
modelId: "claude-opus-5-5",
|
|
18985
18985
|
status: "mapped"
|
|
18986
18986
|
},
|
|
18987
|
-
sourceText: "
|
|
18987
|
+
sourceText: "claude-opus-5-5-low"
|
|
18988
18988
|
},
|
|
18989
18989
|
{
|
|
18990
|
-
externalModelId: "gemini-4-
|
|
18990
|
+
externalModelId: "gemini-4-carbon-high",
|
|
18991
18991
|
kind: "provider_model",
|
|
18992
18992
|
provider: "antigravity",
|
|
18993
18993
|
resolution: {
|
|
18994
|
-
modelId: "gemini-4-
|
|
18994
|
+
modelId: "gemini-4-carbon",
|
|
18995
18995
|
status: "mapped"
|
|
18996
18996
|
},
|
|
18997
|
-
sourceText: "gemini-4-
|
|
18997
|
+
sourceText: "gemini-4-carbon-high"
|
|
18998
18998
|
},
|
|
18999
18999
|
{
|
|
19000
|
-
externalModelId: "claude-
|
|
19000
|
+
externalModelId: "claude-sonnet-5-5-high",
|
|
19001
19001
|
kind: "provider_model",
|
|
19002
19002
|
provider: "antigravity",
|
|
19003
19003
|
resolution: {
|
|
19004
|
-
modelId: "claude-
|
|
19004
|
+
modelId: "claude-sonnet-5-5",
|
|
19005
19005
|
status: "mapped"
|
|
19006
19006
|
},
|
|
19007
|
-
sourceText: "claude-
|
|
19007
|
+
sourceText: "claude-sonnet-5-5-high"
|
|
19008
19008
|
},
|
|
19009
19009
|
{
|
|
19010
|
-
externalModelId: "
|
|
19010
|
+
externalModelId: "claude-opus-5-5-high",
|
|
19011
19011
|
kind: "provider_model",
|
|
19012
19012
|
provider: "antigravity",
|
|
19013
19013
|
resolution: {
|
|
19014
|
-
modelId: "
|
|
19014
|
+
modelId: "claude-opus-5-5",
|
|
19015
19015
|
status: "mapped"
|
|
19016
19016
|
},
|
|
19017
|
-
sourceText: "
|
|
19017
|
+
sourceText: "claude-opus-5-5-high"
|
|
19018
19018
|
},
|
|
19019
19019
|
{
|
|
19020
|
-
externalModelId: "gemini-4-
|
|
19020
|
+
externalModelId: "gemini-4-hydrogen-low",
|
|
19021
19021
|
kind: "provider_model",
|
|
19022
19022
|
provider: "antigravity",
|
|
19023
19023
|
resolution: {
|
|
19024
|
-
modelId: "gemini-4-
|
|
19024
|
+
modelId: "gemini-4-hydrogen",
|
|
19025
19025
|
status: "mapped"
|
|
19026
19026
|
},
|
|
19027
|
-
sourceText: "gemini-4-
|
|
19027
|
+
sourceText: "gemini-4-hydrogen-low"
|
|
19028
19028
|
},
|
|
19029
19029
|
{
|
|
19030
|
-
externalModelId: "claude-
|
|
19030
|
+
externalModelId: "claude-sonnet-5-5-medium",
|
|
19031
19031
|
kind: "provider_model",
|
|
19032
19032
|
provider: "antigravity",
|
|
19033
19033
|
resolution: {
|
|
19034
|
-
modelId: "claude-
|
|
19034
|
+
modelId: "claude-sonnet-5-5",
|
|
19035
19035
|
status: "mapped"
|
|
19036
19036
|
},
|
|
19037
|
-
sourceText: "claude-
|
|
19037
|
+
sourceText: "claude-sonnet-5-5-medium"
|
|
19038
19038
|
},
|
|
19039
19039
|
{
|
|
19040
|
-
externalModelId: "gemini-4-neon-
|
|
19040
|
+
externalModelId: "gemini-4-neon-high",
|
|
19041
19041
|
kind: "provider_model",
|
|
19042
19042
|
provider: "antigravity",
|
|
19043
19043
|
resolution: {
|
|
19044
19044
|
modelId: "gemini-4-neon",
|
|
19045
19045
|
status: "mapped"
|
|
19046
19046
|
},
|
|
19047
|
-
sourceText: "gemini-4-neon-
|
|
19047
|
+
sourceText: "gemini-4-neon-high"
|
|
19048
19048
|
},
|
|
19049
19049
|
{
|
|
19050
|
-
externalModelId: "gemini-4-
|
|
19050
|
+
externalModelId: "gemini-4-hydrogen-xhigh",
|
|
19051
19051
|
kind: "provider_model",
|
|
19052
19052
|
provider: "antigravity",
|
|
19053
19053
|
resolution: {
|
|
19054
|
-
modelId: "gemini-4-
|
|
19054
|
+
modelId: "gemini-4-hydrogen",
|
|
19055
19055
|
status: "mapped"
|
|
19056
19056
|
},
|
|
19057
|
-
sourceText: "gemini-4-
|
|
19057
|
+
sourceText: "gemini-4-hydrogen-xhigh"
|
|
19058
19058
|
},
|
|
19059
19059
|
{
|
|
19060
|
-
externalModelId: "gemini-4-
|
|
19060
|
+
externalModelId: "gemini-4-hydrogen-high",
|
|
19061
19061
|
kind: "provider_model",
|
|
19062
19062
|
provider: "antigravity",
|
|
19063
19063
|
resolution: {
|
|
19064
|
-
modelId: "gemini-4-
|
|
19064
|
+
modelId: "gemini-4-hydrogen",
|
|
19065
19065
|
status: "mapped"
|
|
19066
19066
|
},
|
|
19067
|
-
sourceText: "gemini-4-
|
|
19067
|
+
sourceText: "gemini-4-hydrogen-high"
|
|
19068
19068
|
},
|
|
19069
19069
|
{
|
|
19070
|
-
externalModelId: "
|
|
19070
|
+
externalModelId: "gemini-4-neon-medium",
|
|
19071
19071
|
kind: "provider_model",
|
|
19072
19072
|
provider: "antigravity",
|
|
19073
19073
|
resolution: {
|
|
19074
|
-
modelId: "
|
|
19074
|
+
modelId: "gemini-4-neon",
|
|
19075
19075
|
status: "mapped"
|
|
19076
19076
|
},
|
|
19077
|
-
sourceText: "
|
|
19077
|
+
sourceText: "gemini-4-neon-medium"
|
|
19078
19078
|
},
|
|
19079
19079
|
{
|
|
19080
|
-
externalModelId: "claude-
|
|
19080
|
+
externalModelId: "claude-opus-5-5-medium",
|
|
19081
19081
|
kind: "provider_model",
|
|
19082
19082
|
provider: "antigravity",
|
|
19083
19083
|
resolution: {
|
|
19084
|
-
modelId: "claude-
|
|
19084
|
+
modelId: "claude-opus-5-5",
|
|
19085
19085
|
status: "mapped"
|
|
19086
19086
|
},
|
|
19087
|
-
sourceText: "claude-
|
|
19087
|
+
sourceText: "claude-opus-5-5-medium"
|
|
19088
19088
|
},
|
|
19089
19089
|
{
|
|
19090
|
-
externalModelId: "
|
|
19090
|
+
externalModelId: "gemini-4-neon-xhigh",
|
|
19091
19091
|
kind: "provider_model",
|
|
19092
19092
|
provider: "antigravity",
|
|
19093
19093
|
resolution: {
|
|
19094
|
-
modelId: "
|
|
19094
|
+
modelId: "gemini-4-neon",
|
|
19095
19095
|
status: "mapped"
|
|
19096
19096
|
},
|
|
19097
|
-
sourceText: "
|
|
19097
|
+
sourceText: "gemini-4-neon-xhigh"
|
|
19098
19098
|
},
|
|
19099
19099
|
{
|
|
19100
|
-
externalModelId: "gemini-4-
|
|
19100
|
+
externalModelId: "gemini-4-carbon-medium",
|
|
19101
19101
|
kind: "provider_model",
|
|
19102
19102
|
provider: "antigravity",
|
|
19103
19103
|
resolution: {
|
|
19104
|
-
modelId: "gemini-4-
|
|
19104
|
+
modelId: "gemini-4-carbon",
|
|
19105
19105
|
status: "mapped"
|
|
19106
19106
|
},
|
|
19107
|
-
sourceText: "gemini-4-
|
|
19107
|
+
sourceText: "gemini-4-carbon-medium"
|
|
19108
19108
|
},
|
|
19109
19109
|
{
|
|
19110
|
-
externalModelId: "
|
|
19110
|
+
externalModelId: "claude-sonnet-5-5-low",
|
|
19111
19111
|
kind: "provider_model",
|
|
19112
19112
|
provider: "antigravity",
|
|
19113
19113
|
resolution: {
|
|
19114
|
-
modelId: "
|
|
19114
|
+
modelId: "claude-sonnet-5-5",
|
|
19115
19115
|
status: "mapped"
|
|
19116
19116
|
},
|
|
19117
|
-
sourceText: "
|
|
19117
|
+
sourceText: "claude-sonnet-5-5-low"
|
|
19118
19118
|
},
|
|
19119
19119
|
{
|
|
19120
|
-
externalModelId: "
|
|
19120
|
+
externalModelId: "gemini-4-neon-low",
|
|
19121
19121
|
kind: "provider_model",
|
|
19122
19122
|
provider: "antigravity",
|
|
19123
19123
|
resolution: {
|
|
19124
|
-
modelId: "
|
|
19124
|
+
modelId: "gemini-4-neon",
|
|
19125
19125
|
status: "mapped"
|
|
19126
19126
|
},
|
|
19127
|
-
sourceText: "
|
|
19127
|
+
sourceText: "gemini-4-neon-low"
|
|
19128
19128
|
},
|
|
19129
19129
|
{
|
|
19130
|
-
externalModelId: "gemini-4-
|
|
19130
|
+
externalModelId: "gemini-4-hydrogen-medium",
|
|
19131
19131
|
kind: "provider_model",
|
|
19132
19132
|
provider: "antigravity",
|
|
19133
19133
|
resolution: {
|
|
19134
|
-
modelId: "gemini-4-
|
|
19134
|
+
modelId: "gemini-4-hydrogen",
|
|
19135
19135
|
status: "mapped"
|
|
19136
19136
|
},
|
|
19137
|
-
sourceText: "gemini-4-
|
|
19137
|
+
sourceText: "gemini-4-hydrogen-medium"
|
|
19138
19138
|
}
|
|
19139
19139
|
],
|
|
19140
19140
|
modelDiscovery: "client",
|
|
@@ -19478,74 +19478,74 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19478
19478
|
id: "ollama-cloud",
|
|
19479
19479
|
inclusions: [
|
|
19480
19480
|
{
|
|
19481
|
-
externalModelId: "
|
|
19481
|
+
externalModelId: "deepseek-v4.1-flash",
|
|
19482
19482
|
kind: "provider_model",
|
|
19483
19483
|
provider: "ollamacloud",
|
|
19484
19484
|
resolution: {
|
|
19485
|
-
modelId: "
|
|
19485
|
+
modelId: "deepseek-v4.1-flash",
|
|
19486
19486
|
status: "mapped"
|
|
19487
19487
|
},
|
|
19488
|
-
sourceText: "
|
|
19488
|
+
sourceText: "deepseek-v4.1-flash"
|
|
19489
19489
|
},
|
|
19490
19490
|
{
|
|
19491
|
-
externalModelId: "
|
|
19491
|
+
externalModelId: "mimo-v2.6-pro",
|
|
19492
19492
|
kind: "provider_model",
|
|
19493
19493
|
provider: "ollamacloud",
|
|
19494
19494
|
resolution: {
|
|
19495
|
-
modelId: "
|
|
19495
|
+
modelId: "mimo-v2.6-pro",
|
|
19496
19496
|
status: "mapped"
|
|
19497
19497
|
},
|
|
19498
|
-
sourceText: "
|
|
19498
|
+
sourceText: "mimo-v2.6-pro"
|
|
19499
19499
|
},
|
|
19500
19500
|
{
|
|
19501
|
-
externalModelId: "
|
|
19501
|
+
externalModelId: "kimi-k3.1-pro",
|
|
19502
19502
|
kind: "provider_model",
|
|
19503
19503
|
provider: "ollamacloud",
|
|
19504
19504
|
resolution: {
|
|
19505
|
-
modelId: "
|
|
19505
|
+
modelId: "kimi-k3.1-pro",
|
|
19506
19506
|
status: "mapped"
|
|
19507
19507
|
},
|
|
19508
|
-
sourceText: "
|
|
19508
|
+
sourceText: "kimi-k3.1-pro"
|
|
19509
19509
|
},
|
|
19510
19510
|
{
|
|
19511
|
-
externalModelId: "
|
|
19511
|
+
externalModelId: "minimax-m3.1-flash",
|
|
19512
19512
|
kind: "provider_model",
|
|
19513
19513
|
provider: "ollamacloud",
|
|
19514
19514
|
resolution: {
|
|
19515
|
-
modelId: "
|
|
19515
|
+
modelId: "minimax-m3.1-flash",
|
|
19516
19516
|
status: "mapped"
|
|
19517
19517
|
},
|
|
19518
|
-
sourceText: "
|
|
19518
|
+
sourceText: "minimax-m3.1-flash"
|
|
19519
19519
|
},
|
|
19520
19520
|
{
|
|
19521
|
-
externalModelId: "mimo-v2.6-
|
|
19521
|
+
externalModelId: "mimo-v2.6-flash",
|
|
19522
19522
|
kind: "provider_model",
|
|
19523
19523
|
provider: "ollamacloud",
|
|
19524
19524
|
resolution: {
|
|
19525
|
-
modelId: "mimo-v2.6-
|
|
19525
|
+
modelId: "mimo-v2.6-flash",
|
|
19526
19526
|
status: "mapped"
|
|
19527
19527
|
},
|
|
19528
|
-
sourceText: "mimo-v2.6-
|
|
19528
|
+
sourceText: "mimo-v2.6-flash"
|
|
19529
19529
|
},
|
|
19530
19530
|
{
|
|
19531
|
-
externalModelId: "glm-5.3",
|
|
19531
|
+
externalModelId: "glm-5.3-flash",
|
|
19532
19532
|
kind: "provider_model",
|
|
19533
19533
|
provider: "ollamacloud",
|
|
19534
19534
|
resolution: {
|
|
19535
|
-
modelId: "glm-5.3",
|
|
19535
|
+
modelId: "glm-5.3-flash",
|
|
19536
19536
|
status: "mapped"
|
|
19537
19537
|
},
|
|
19538
|
-
sourceText: "glm-5.3"
|
|
19538
|
+
sourceText: "glm-5.3-flash"
|
|
19539
19539
|
},
|
|
19540
19540
|
{
|
|
19541
|
-
externalModelId: "glm-5.3
|
|
19541
|
+
externalModelId: "glm-5.3",
|
|
19542
19542
|
kind: "provider_model",
|
|
19543
19543
|
provider: "ollamacloud",
|
|
19544
19544
|
resolution: {
|
|
19545
|
-
modelId: "glm-5.3
|
|
19545
|
+
modelId: "glm-5.3",
|
|
19546
19546
|
status: "mapped"
|
|
19547
19547
|
},
|
|
19548
|
-
sourceText: "glm-5.3
|
|
19548
|
+
sourceText: "glm-5.3"
|
|
19549
19549
|
}
|
|
19550
19550
|
],
|
|
19551
19551
|
modelDiscovery: "catalog",
|
|
@@ -19800,7 +19800,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
19800
19800
|
}
|
|
19801
19801
|
],
|
|
19802
19802
|
routeRegistry: {
|
|
19803
|
-
generationId: "g-
|
|
19803
|
+
generationId: "g-20261127161649657-d819d8a0",
|
|
19804
19804
|
registry: {
|
|
19805
19805
|
contractVersion: 3,
|
|
19806
19806
|
registryVersion: "3.7.0",
|
|
@@ -90356,6 +90356,18 @@ function isRowSpace(c) {
|
|
|
90356
90356
|
return c !== undefined && c !== `
|
|
90357
90357
|
` && /\s/.test(c);
|
|
90358
90358
|
}
|
|
90359
|
+
function boxEndsWith(shown, whole) {
|
|
90360
|
+
if (matchFrom(shown, whole) === "line")
|
|
90361
|
+
return true;
|
|
90362
|
+
for (let k = 1;k < shown.length; k++) {
|
|
90363
|
+
if (shown[k] === `
|
|
90364
|
+
`)
|
|
90365
|
+
continue;
|
|
90366
|
+
if (matchFrom(shown.slice(k), whole) === "line")
|
|
90367
|
+
return true;
|
|
90368
|
+
}
|
|
90369
|
+
return false;
|
|
90370
|
+
}
|
|
90359
90371
|
function matchFrom(shown, line) {
|
|
90360
90372
|
const want = line;
|
|
90361
90373
|
let at = 0;
|
|
@@ -90585,10 +90597,34 @@ function typedWriteEnds(text) {
|
|
|
90585
90597
|
function typedWriteCount(text) {
|
|
90586
90598
|
return typedWriteEnds(text).length;
|
|
90587
90599
|
}
|
|
90588
|
-
function
|
|
90600
|
+
function isGoSpace(c) {
|
|
90601
|
+
return c === "\x85" || c !== "\uFEFF" && /\s/.test(c);
|
|
90602
|
+
}
|
|
90603
|
+
function evidencedWriteEnds(text) {
|
|
90604
|
+
const rs = Array.from(text);
|
|
90605
|
+
const ends = [];
|
|
90606
|
+
let start = 0;
|
|
90607
|
+
for (const end of typedWriteEnds(text)) {
|
|
90608
|
+
let visibleEnd = end;
|
|
90609
|
+
while (visibleEnd > start && isGoSpace(rs[visibleEnd - 1]))
|
|
90610
|
+
visibleEnd--;
|
|
90611
|
+
if (visibleEnd === start)
|
|
90612
|
+
continue;
|
|
90613
|
+
ends.push(visibleEnd);
|
|
90614
|
+
start = visibleEnd;
|
|
90615
|
+
}
|
|
90616
|
+
if (start < rs.length) {
|
|
90617
|
+
if (ends.length === 0)
|
|
90618
|
+
ends.push(rs.length);
|
|
90619
|
+
else
|
|
90620
|
+
ends[ends.length - 1] = rs.length;
|
|
90621
|
+
}
|
|
90622
|
+
return ends;
|
|
90623
|
+
}
|
|
90624
|
+
function writtenPrefix(text, writes, evidenced = false) {
|
|
90589
90625
|
if (writes <= 0)
|
|
90590
90626
|
return "";
|
|
90591
|
-
const ends = typedWriteEnds(text);
|
|
90627
|
+
const ends = evidenced ? evidencedWriteEnds(text) : typedWriteEnds(text);
|
|
90592
90628
|
if (writes >= ends.length)
|
|
90593
90629
|
return text;
|
|
90594
90630
|
return Array.from(text).slice(0, ends[writes - 1]).join("");
|
|
@@ -90602,7 +90638,7 @@ function sendBudgetMs(s) {
|
|
|
90602
90638
|
const accept = s.submit ? SEND_ACCEPT_WINDOWS * SEND_ACCEPT_WINDOW_MS : 0;
|
|
90603
90639
|
return readyWaitMs(s.readyTimeoutMs) + 2 * attempt + accept + SEND_BUDGET_SLACK_MS;
|
|
90604
90640
|
}
|
|
90605
|
-
var DIALOG_KINDS, BOOT_DIALOG_KINDS, DIALOG_PREFIX = "dialog:", MAYBE_SUBMITTED_MARKER = "check the conversation before sending", BOX_STAYED_EMPTY, SEND_READY_WAIT_DEFAULT_MS = 1e4, SEND_READY_WAIT_MAX_MS = 60000, SEND_TYPED_CHUNK_RUNES = 32, SEND_TYPED_CHUNK_GAP_MS = 8, SEND_KEY_GAP_MS = 20, SEND_SETTLE_MS = 150, SEND_VERIFY_MIN_MS = 1200, SEND_VERIFY_STEP_MS = 40, SEND_GATE_CHECK_COST_MS = 2, SEND_ACCEPT_WINDOW_MS = 2000, SEND_ACCEPT_WINDOWS = 3, SEND_BUDGET_SLACK_MS = 2000;
|
|
90641
|
+
var DIALOG_KINDS, BOOT_DIALOG_KINDS, DIALOG_PREFIX = "dialog:", MAYBE_SUBMITTED_MARKER = "check the conversation before sending", BOX_STAYED_EMPTY, SEND_READY_WAIT_DEFAULT_MS = 1e4, SEND_READY_WAIT_MAX_MS = 60000, SEND_TYPED_CHUNK_RUNES = 32, SEND_TYPED_CHUNK_GAP_MS = 8, SEND_KEY_GAP_MS = 20, SEND_SETTLE_MS = 150, SEND_VERIFY_MIN_MS = 1200, SEND_VERIFY_STEP_MS = 40, SEND_GATE_CHECK_COST_MS = 2, SEND_ACCEPT_WINDOW_MS = 2000, SEND_ACCEPT_WINDOWS = 3, SEND_BUDGET_SLACK_MS = 2000, EVIDENCED_WRITES_VERSION = "0.20.5";
|
|
90606
90642
|
var init_input_gate = __esm(() => {
|
|
90607
90643
|
DIALOG_KINDS = new Set([
|
|
90608
90644
|
"permission",
|
|
@@ -112987,7 +113023,9 @@ var init_process_identity = __esm(() => {
|
|
|
112987
113023
|
import { spawn as spawn2 } from "child_process";
|
|
112988
113024
|
import { randomBytes as randomBytes15 } from "crypto";
|
|
112989
113025
|
import {
|
|
113026
|
+
accessSync as accessSync3,
|
|
112990
113027
|
chmodSync as chmodSync4,
|
|
113028
|
+
constants as fsConstants2,
|
|
112991
113029
|
lstatSync as lstatSync7,
|
|
112992
113030
|
mkdirSync as mkdirSync24,
|
|
112993
113031
|
mkdtempSync as mkdtempSync2,
|
|
@@ -112995,7 +113033,7 @@ import {
|
|
|
112995
113033
|
statSync as statSync18,
|
|
112996
113034
|
writeFileSync as writeFileSync18
|
|
112997
113035
|
} from "fs";
|
|
112998
|
-
import { join as join53, resolve as resolve5 } from "path";
|
|
113036
|
+
import { isAbsolute as isAbsolute3, join as join53, resolve as resolve5 } from "path";
|
|
112999
113037
|
function uid() {
|
|
113000
113038
|
return typeof process.getuid === "function" ? process.getuid() : 0;
|
|
113001
113039
|
}
|
|
@@ -113057,6 +113095,29 @@ function mintPaneId(kind, label) {
|
|
|
113057
113095
|
function isStrippedFromChildEnv(key) {
|
|
113058
113096
|
return STRIPPED_CHILD_VARS.includes(key) || key.startsWith("MAGMUX_") || TERMINAL_IDENTITY_VARS.includes(key) || TERMINAL_IDENTITY_PREFIXES.some((p) => key.startsWith(p)) || MULTIPLEXER_IDENTITY_PREFIXES.some((p) => key.startsWith(p)) || MULTIPLEXER_IDENTITY_VARS.includes(key) || HOST_IDENTITY_VARS.includes(key);
|
|
113059
113097
|
}
|
|
113098
|
+
function claudePathIn(base, named) {
|
|
113099
|
+
const rest = named.startsWith("./") ? named.slice(2) : named;
|
|
113100
|
+
if (rest === "" || isAbsolute3(rest))
|
|
113101
|
+
return null;
|
|
113102
|
+
if (rest.split("/").some((part) => part === "" || part === "." || part === ".."))
|
|
113103
|
+
return null;
|
|
113104
|
+
const abs = base.endsWith("/") ? `${base}${rest}` : `${base}/${rest}`;
|
|
113105
|
+
try {
|
|
113106
|
+
if (!statSync18(abs).isFile())
|
|
113107
|
+
return null;
|
|
113108
|
+
accessSync3(abs, fsConstants2.X_OK);
|
|
113109
|
+
return abs;
|
|
113110
|
+
} catch {
|
|
113111
|
+
return null;
|
|
113112
|
+
}
|
|
113113
|
+
}
|
|
113114
|
+
function paneClaudePath(base, named) {
|
|
113115
|
+
const real = claudePathIn(base, named);
|
|
113116
|
+
if (real === null) {
|
|
113117
|
+
throw new PaneClaudePathError(`CLAUDE_PATH ${named} names no executable file in ${base}`);
|
|
113118
|
+
}
|
|
113119
|
+
return real;
|
|
113120
|
+
}
|
|
113060
113121
|
function buildPaneEnv(input) {
|
|
113061
113122
|
const env = {};
|
|
113062
113123
|
for (const [k, v] of Object.entries(input.parentEnv)) {
|
|
@@ -113064,6 +113125,9 @@ function buildPaneEnv(input) {
|
|
|
113064
113125
|
continue;
|
|
113065
113126
|
env[k] = v;
|
|
113066
113127
|
}
|
|
113128
|
+
if (env.CLAUDE_PATH && !isAbsolute3(env.CLAUDE_PATH)) {
|
|
113129
|
+
env.CLAUDE_PATH = paneClaudePath(input.serverCwd ?? process.cwd(), env.CLAUDE_PATH);
|
|
113130
|
+
}
|
|
113067
113131
|
env.COLUMNS = String(input.cols ?? DEFAULT_PANE_COLS);
|
|
113068
113132
|
env.LINES = String(input.rows ?? DEFAULT_PANE_ROWS);
|
|
113069
113133
|
if (input.parentEnv.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC === undefined)
|
|
@@ -113512,7 +113576,7 @@ function spawnReplayMagmux(input) {
|
|
|
113512
113576
|
proc.on("error", () => {});
|
|
113513
113577
|
return proc;
|
|
113514
113578
|
}
|
|
113515
|
-
var SOCK_ROOT, PaneRootError, OWNER_START36, TERMINAL_IDENTITY_VARS, TERMINAL_IDENTITY_PREFIXES, MULTIPLEXER_IDENTITY_PREFIXES, MULTIPLEXER_IDENTITY_VARS, HOST_IDENTITY_VARS, LINUX_ENV_STRING_LIMIT = 131000, PaneEnvTooLargeError, REPLAY_ENV_ALLOWLIST, MAX_USER_SETTINGS_BYTES, OWN_ARGV, TRANSPORT_BREAKERS, IDENTITY_BREAKERS, PRINT_ONLY_FLAGS, MODE_FLAGS, SUBCOMMAND_WORDS, CLAUDE_CODE_VALUE_FLAGS, KNOWN_CLAUDISH_FLAGS, MIN_MAGMUX_VERSION = "0.20.3", MagmuxUnavailableError, magmuxCache, magmuxProbes, MAGMUX_NEEDS = "a read-only view socket, a socket at any path depth, and the Claude Code input gate bound to a named transcript", MAGMUX_VERSION_TIMEOUT_MS = 5000, VERSION_PATTERN, EXIT_DRAIN_MS = 100, ClaudishNotFoundError, SHELL_SHIM = `#!/bin/sh
|
|
113579
|
+
var SOCK_ROOT, PaneRootError, OWNER_START36, TERMINAL_IDENTITY_VARS, TERMINAL_IDENTITY_PREFIXES, MULTIPLEXER_IDENTITY_PREFIXES, MULTIPLEXER_IDENTITY_VARS, HOST_IDENTITY_VARS, LINUX_ENV_STRING_LIMIT = 131000, PaneEnvTooLargeError, PaneClaudePathError, REPLAY_ENV_ALLOWLIST, MAX_USER_SETTINGS_BYTES, OWN_ARGV, TRANSPORT_BREAKERS, IDENTITY_BREAKERS, PRINT_ONLY_FLAGS, MODE_FLAGS, SUBCOMMAND_WORDS, CLAUDE_CODE_VALUE_FLAGS, KNOWN_CLAUDISH_FLAGS, MIN_MAGMUX_VERSION = "0.20.3", MagmuxUnavailableError, magmuxCache, magmuxProbes, MAGMUX_NEEDS = "a read-only view socket, a socket at any path depth, and the Claude Code input gate bound to a named transcript", MAGMUX_VERSION_TIMEOUT_MS = 5000, VERSION_PATTERN, EXIT_DRAIN_MS = 100, ClaudishNotFoundError, SHELL_SHIM = `#!/bin/sh
|
|
113516
113580
|
[ "$1" = -l ] && shift
|
|
113517
113581
|
exec /bin/sh "$@"
|
|
113518
113582
|
`, FATAL_MAGMUX_STDERR;
|
|
@@ -113568,6 +113632,9 @@ var init_pane_launch = __esm(() => {
|
|
|
113568
113632
|
PaneEnvTooLargeError = class PaneEnvTooLargeError extends Error {
|
|
113569
113633
|
code = "pane_lost";
|
|
113570
113634
|
};
|
|
113635
|
+
PaneClaudePathError = class PaneClaudePathError extends Error {
|
|
113636
|
+
code = "no_claude_binary";
|
|
113637
|
+
};
|
|
113571
113638
|
REPLAY_ENV_ALLOWLIST = [
|
|
113572
113639
|
"HOME",
|
|
113573
113640
|
"PATH",
|
|
@@ -114569,26 +114636,29 @@ function mainCheckoutRoot(cwd, readFile, pathKind) {
|
|
|
114569
114636
|
const kind = pathKind(entry);
|
|
114570
114637
|
if (kind === "dir")
|
|
114571
114638
|
return dir;
|
|
114572
|
-
if (kind === "file")
|
|
114573
|
-
|
|
114574
|
-
if (gitDir === undefined)
|
|
114575
|
-
return dir;
|
|
114576
|
-
let common;
|
|
114577
|
-
try {
|
|
114578
|
-
common = readFile(join54(gitDir, "commondir")).trim();
|
|
114579
|
-
} catch {
|
|
114580
|
-
return dir;
|
|
114581
|
-
}
|
|
114582
|
-
if (!common)
|
|
114583
|
-
return dir;
|
|
114584
|
-
return dirname20(resolve6(gitDir, common));
|
|
114585
|
-
}
|
|
114639
|
+
if (kind === "file")
|
|
114640
|
+
return linkedCheckoutRoot(dir, entry, readFile, pathKind);
|
|
114586
114641
|
const parent = dirname20(dir);
|
|
114587
114642
|
if (parent === dir)
|
|
114588
114643
|
return;
|
|
114589
114644
|
dir = parent;
|
|
114590
114645
|
}
|
|
114591
114646
|
}
|
|
114647
|
+
function linkedCheckoutRoot(dir, entry, readFile, pathKind) {
|
|
114648
|
+
const gitDir = gitDirOfFile(entry, readFile);
|
|
114649
|
+
if (gitDir === undefined)
|
|
114650
|
+
return dir;
|
|
114651
|
+
const commondir = join54(gitDir, "commondir");
|
|
114652
|
+
if (pathKind(commondir) !== "file")
|
|
114653
|
+
return dir;
|
|
114654
|
+
let common;
|
|
114655
|
+
try {
|
|
114656
|
+
common = readFile(commondir).trim();
|
|
114657
|
+
} catch {
|
|
114658
|
+
return dir;
|
|
114659
|
+
}
|
|
114660
|
+
return common ? dirname20(resolve6(gitDir, common)) : dir;
|
|
114661
|
+
}
|
|
114592
114662
|
function gitDirOfFile(entry, readFile) {
|
|
114593
114663
|
let text;
|
|
114594
114664
|
try {
|
|
@@ -114602,7 +114672,9 @@ function gitDirOfFile(entry, readFile) {
|
|
|
114602
114672
|
function statPathKind(path) {
|
|
114603
114673
|
try {
|
|
114604
114674
|
const stat = statSync19(path);
|
|
114605
|
-
|
|
114675
|
+
if (stat.isDirectory())
|
|
114676
|
+
return "dir";
|
|
114677
|
+
return stat.isFile() ? "file" : undefined;
|
|
114606
114678
|
} catch {
|
|
114607
114679
|
return;
|
|
114608
114680
|
}
|
|
@@ -115809,7 +115881,7 @@ function setupSignalHandlers(tempSettingsPath, quiet, onCleanup, onDeadline) {
|
|
|
115809
115881
|
claudeCodeStopped: () => claudeCodeStopped
|
|
115810
115882
|
};
|
|
115811
115883
|
}
|
|
115812
|
-
async function findClaudeBinary(env = process.env) {
|
|
115884
|
+
async function findClaudeBinary(env = process.env, signal) {
|
|
115813
115885
|
const isWindows = process.platform === "win32";
|
|
115814
115886
|
if (env.CLAUDE_PATH) {
|
|
115815
115887
|
if (existsSync38(env.CLAUDE_PATH)) {
|
|
@@ -115848,33 +115920,57 @@ async function findClaudeBinary(env = process.env) {
|
|
|
115848
115920
|
}
|
|
115849
115921
|
}
|
|
115850
115922
|
}
|
|
115851
|
-
|
|
115852
|
-
|
|
115853
|
-
|
|
115854
|
-
|
|
115855
|
-
|
|
115856
|
-
|
|
115923
|
+
const lines = await shellLookup(isWindows ? "where claude" : "command -v claude", signal, true);
|
|
115924
|
+
if (lines === null)
|
|
115925
|
+
return null;
|
|
115926
|
+
if (isWindows) {
|
|
115927
|
+
const cmdPath = lines.find((line) => line.endsWith(".cmd"));
|
|
115928
|
+
if (cmdPath)
|
|
115929
|
+
return cmdPath;
|
|
115930
|
+
}
|
|
115931
|
+
return lines[0] ?? null;
|
|
115932
|
+
}
|
|
115933
|
+
function shellLookup(shellCommand, signal, allLines) {
|
|
115934
|
+
if (signal?.aborted)
|
|
115935
|
+
return Promise.resolve(null);
|
|
115936
|
+
const isWindows = process.platform === "win32";
|
|
115937
|
+
return new Promise((settle) => {
|
|
115938
|
+
let proc;
|
|
115939
|
+
try {
|
|
115940
|
+
proc = spawn3(shellCommand, [], {
|
|
115941
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
115942
|
+
shell: true,
|
|
115943
|
+
detached: !isWindows
|
|
115944
|
+
});
|
|
115945
|
+
} catch {
|
|
115946
|
+
settle(null);
|
|
115947
|
+
return;
|
|
115948
|
+
}
|
|
115857
115949
|
let output = "";
|
|
115950
|
+
let aborted = false;
|
|
115858
115951
|
proc.stdout?.on("data", (data) => {
|
|
115859
115952
|
output += data.toString();
|
|
115860
115953
|
});
|
|
115861
|
-
const
|
|
115862
|
-
|
|
115863
|
-
|
|
115864
|
-
|
|
115865
|
-
|
|
115866
|
-
|
|
115867
|
-
|
|
115868
|
-
|
|
115869
|
-
|
|
115870
|
-
|
|
115871
|
-
|
|
115872
|
-
|
|
115873
|
-
|
|
115874
|
-
|
|
115875
|
-
|
|
115876
|
-
|
|
115877
|
-
|
|
115954
|
+
const onAbort = () => {
|
|
115955
|
+
aborted = true;
|
|
115956
|
+
try {
|
|
115957
|
+
if (!isWindows && proc.pid !== undefined)
|
|
115958
|
+
process.kill(-proc.pid, "SIGKILL");
|
|
115959
|
+
else
|
|
115960
|
+
proc.kill("SIGKILL");
|
|
115961
|
+
} catch {}
|
|
115962
|
+
};
|
|
115963
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
115964
|
+
const done = (code) => {
|
|
115965
|
+
signal?.removeEventListener("abort", onAbort);
|
|
115966
|
+
const lines = output.trim() ? output.trim().split(/\r?\n/) : [];
|
|
115967
|
+
if (aborted || code !== 0 || lines.length === 0)
|
|
115968
|
+
return settle(null);
|
|
115969
|
+
settle(allLines ? lines : lines[0]);
|
|
115970
|
+
};
|
|
115971
|
+
proc.on("error", () => done(null));
|
|
115972
|
+
proc.on("close", done);
|
|
115973
|
+
});
|
|
115878
115974
|
}
|
|
115879
115975
|
async function checkClaudeInstalled() {
|
|
115880
115976
|
const binary = await findClaudeBinary();
|
|
@@ -118542,9 +118638,271 @@ var init_team_orchestrator = __esm(() => {
|
|
|
118542
118638
|
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.";
|
|
118543
118639
|
});
|
|
118544
118640
|
|
|
118641
|
+
// src/mcp-session/probe-launch-vars.ts
|
|
118642
|
+
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;
|
|
118643
|
+
var init_probe_launch_vars = __esm(() => {
|
|
118644
|
+
PROBE_PLUGIN_VARS = [
|
|
118645
|
+
"CLAUDE_CODE_PLUGIN_CACHE_DIR",
|
|
118646
|
+
"CLAUDE_CODE_PLUGIN_SEED_DIR",
|
|
118647
|
+
"CLAUDE_CODE_PLUGIN_DIRS",
|
|
118648
|
+
"CLAUDE_CODE_PLUGIN_USE_ZIP_CACHE"
|
|
118649
|
+
];
|
|
118650
|
+
PROBE_MODE_VARS = [
|
|
118651
|
+
"CLAUDE_CODE_RESTRICTED",
|
|
118652
|
+
"CLAUDE_CODE_SAFE_MODE",
|
|
118653
|
+
"CLAUDE_CODE_SIMPLE",
|
|
118654
|
+
"CLAUDE_CODE_RESTRICT_PERSONAL_CONFIG",
|
|
118655
|
+
"CLAUDE_CODE_DISABLE_BUNDLED_SKILLS",
|
|
118656
|
+
"CLAUDE_CODE_DISABLE_POLICY_SKILLS",
|
|
118657
|
+
"CLAUDE_CODE_DISABLE_CLAUDE_API_SKILL",
|
|
118658
|
+
"CLAUDE_CODE_DISABLE_CLAUDE_CODE_SKILL",
|
|
118659
|
+
"CLAUDE_CODE_SKIP_PLUGIN_MCP_SERVERS",
|
|
118660
|
+
"CLAUDE_CODE_SKIP_PLUGIN_MCP_SERVERS_EXCEPT",
|
|
118661
|
+
"CLAUDE_CODE_SKIP_PLUGIN_LOCAL_MCP_SERVERS",
|
|
118662
|
+
"CLAUDE_CODE_SKIP_PLUGIN_MCP_BUNDLES",
|
|
118663
|
+
"ENABLE_CLAUDEAI_MCP_SERVERS"
|
|
118664
|
+
];
|
|
118665
|
+
CALLER_LAUNCH_ENV_KEYS = [
|
|
118666
|
+
"CLAUDE_CONFIG_DIR",
|
|
118667
|
+
...PROBE_PLUGIN_VARS,
|
|
118668
|
+
...PROBE_MODE_VARS
|
|
118669
|
+
];
|
|
118670
|
+
PROBE_REFUSAL_ENV_KEYS = [PROBE_COWORK_SWITCH];
|
|
118671
|
+
HOST_READ_ENV_KEYS = [...CALLER_LAUNCH_ENV_KEYS, ...PROBE_REFUSAL_ENV_KEYS];
|
|
118672
|
+
});
|
|
118673
|
+
|
|
118674
|
+
// src/mcp-session/host-launch.ts
|
|
118675
|
+
import { readFileSync as readFileSync46, readlinkSync } from "fs";
|
|
118676
|
+
function bindDarwin() {
|
|
118677
|
+
const { dlopen, FFIType, ptr } = __require("bun:ffi");
|
|
118678
|
+
const lib = dlopen("libSystem.B.dylib", {
|
|
118679
|
+
sysctl: {
|
|
118680
|
+
args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.u64],
|
|
118681
|
+
returns: FFIType.i32
|
|
118682
|
+
},
|
|
118683
|
+
proc_pidinfo: {
|
|
118684
|
+
args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
|
|
118685
|
+
returns: FFIType.i32
|
|
118686
|
+
}
|
|
118687
|
+
});
|
|
118688
|
+
const sysctl = (name, out, len) => lib.symbols.sysctl(ptr(name), name.length, ptr(out), ptr(len), null, 0n);
|
|
118689
|
+
return {
|
|
118690
|
+
argmax() {
|
|
118691
|
+
const out = new Int32Array(1);
|
|
118692
|
+
const len = new BigUint64Array([4n]);
|
|
118693
|
+
return sysctl(new Int32Array([CTL_KERN, KERN_ARGMAX]), out, len) === 0 ? out[0] : null;
|
|
118694
|
+
},
|
|
118695
|
+
procargs(pid, size) {
|
|
118696
|
+
const buf = Buffer.alloc(size);
|
|
118697
|
+
const len = new BigUint64Array([BigInt(size)]);
|
|
118698
|
+
if (sysctl(new Int32Array([CTL_KERN, KERN_PROCARGS2, pid]), buf, len) !== 0)
|
|
118699
|
+
return null;
|
|
118700
|
+
return buf.subarray(0, Number(len[0]));
|
|
118701
|
+
},
|
|
118702
|
+
cwd(pid) {
|
|
118703
|
+
const buf = Buffer.alloc(VNODEPATHINFO_BYTES);
|
|
118704
|
+
const got = lib.symbols.proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0n, ptr(buf), buf.length);
|
|
118705
|
+
if (got !== buf.length)
|
|
118706
|
+
return null;
|
|
118707
|
+
return cwdOfVnodePathInfo(buf);
|
|
118708
|
+
}
|
|
118709
|
+
};
|
|
118710
|
+
}
|
|
118711
|
+
function cwdOfVnodePathInfo(buf) {
|
|
118712
|
+
if (buf.length !== VNODEPATHINFO_BYTES)
|
|
118713
|
+
return null;
|
|
118714
|
+
const field = buf.subarray(VNODE_INFO_BYTES, VNODE_INFO_BYTES + MAXPATHLEN);
|
|
118715
|
+
const end = field.indexOf(0);
|
|
118716
|
+
if (end <= 0)
|
|
118717
|
+
return null;
|
|
118718
|
+
return field.toString("utf8", 0, end);
|
|
118719
|
+
}
|
|
118720
|
+
function darwin() {
|
|
118721
|
+
if (darwinBinding !== undefined)
|
|
118722
|
+
return darwinBinding;
|
|
118723
|
+
try {
|
|
118724
|
+
darwinBinding = bindDarwin();
|
|
118725
|
+
} catch {
|
|
118726
|
+
darwinBinding = null;
|
|
118727
|
+
}
|
|
118728
|
+
return darwinBinding;
|
|
118729
|
+
}
|
|
118730
|
+
function argvOfProcargs(buf) {
|
|
118731
|
+
return procargsLayout(buf)?.argv ?? null;
|
|
118732
|
+
}
|
|
118733
|
+
function procargsLayout(buf) {
|
|
118734
|
+
if (buf.length < 4)
|
|
118735
|
+
return null;
|
|
118736
|
+
const argc = buf.readInt32LE(0);
|
|
118737
|
+
if (argc < 1)
|
|
118738
|
+
return null;
|
|
118739
|
+
const pathEnd = buf.indexOf(0, 4);
|
|
118740
|
+
if (pathEnd < 0)
|
|
118741
|
+
return null;
|
|
118742
|
+
let i = 4 + Math.ceil((pathEnd - 4 + 1) / EXEC_PATH_ALIGN) * EXEC_PATH_ALIGN;
|
|
118743
|
+
if (i >= buf.length || buf[i] === 0)
|
|
118744
|
+
return null;
|
|
118745
|
+
for (let pad = pathEnd;pad < i; pad++)
|
|
118746
|
+
if (buf[pad] !== 0)
|
|
118747
|
+
return null;
|
|
118748
|
+
const argv = [];
|
|
118749
|
+
for (let k = 0;k < argc; k++) {
|
|
118750
|
+
const end = buf.indexOf(0, i);
|
|
118751
|
+
if (end < 0)
|
|
118752
|
+
return null;
|
|
118753
|
+
argv.push(buf.toString("utf8", i, end));
|
|
118754
|
+
i = end + 1;
|
|
118755
|
+
}
|
|
118756
|
+
return { argv, end: i };
|
|
118757
|
+
}
|
|
118758
|
+
function hostEnvOf(entries) {
|
|
118759
|
+
const env = {};
|
|
118760
|
+
for (const key of HOST_ENV_KEYS) {
|
|
118761
|
+
const prefix = Buffer.from(`${key}=`);
|
|
118762
|
+
const entry = entries.find((e) => e.subarray(0, prefix.length).equals(prefix));
|
|
118763
|
+
if (entry === undefined)
|
|
118764
|
+
continue;
|
|
118765
|
+
const raw = entry.subarray(prefix.length);
|
|
118766
|
+
const value = raw.toString("utf8");
|
|
118767
|
+
if (!Buffer.from(value, "utf8").equals(raw))
|
|
118768
|
+
return null;
|
|
118769
|
+
env[key] = value;
|
|
118770
|
+
}
|
|
118771
|
+
return env;
|
|
118772
|
+
}
|
|
118773
|
+
function hostEnvOfProcargs(buf) {
|
|
118774
|
+
const layout = procargsLayout(buf);
|
|
118775
|
+
if (!layout)
|
|
118776
|
+
return null;
|
|
118777
|
+
const entries = [];
|
|
118778
|
+
for (let i = layout.end;; ) {
|
|
118779
|
+
const end = buf.indexOf(0, i);
|
|
118780
|
+
if (end < 0)
|
|
118781
|
+
return null;
|
|
118782
|
+
if (end === i)
|
|
118783
|
+
break;
|
|
118784
|
+
entries.push(buf.subarray(i, end));
|
|
118785
|
+
i = end + 1;
|
|
118786
|
+
}
|
|
118787
|
+
return hostEnvOf(entries);
|
|
118788
|
+
}
|
|
118789
|
+
function hostEnvOfEnviron(raw) {
|
|
118790
|
+
if (raw.length === 0 || raw[raw.length - 1] !== 0)
|
|
118791
|
+
return null;
|
|
118792
|
+
const entries = [];
|
|
118793
|
+
for (let i = 0;i < raw.length; ) {
|
|
118794
|
+
const end = raw.indexOf(0, i);
|
|
118795
|
+
entries.push(raw.subarray(i, end));
|
|
118796
|
+
i = end + 1;
|
|
118797
|
+
}
|
|
118798
|
+
return hostEnvOf(entries);
|
|
118799
|
+
}
|
|
118800
|
+
function readDarwin(pid) {
|
|
118801
|
+
const binding = darwin();
|
|
118802
|
+
if (!binding)
|
|
118803
|
+
return null;
|
|
118804
|
+
const size = binding.argmax();
|
|
118805
|
+
if (size === null || size <= 0)
|
|
118806
|
+
return null;
|
|
118807
|
+
const raw = binding.procargs(pid, size);
|
|
118808
|
+
const argv = raw ? argvOfProcargs(raw) : null;
|
|
118809
|
+
const cwd = binding.cwd(pid);
|
|
118810
|
+
if (!raw || !argv || !cwd)
|
|
118811
|
+
return null;
|
|
118812
|
+
return { argv, cwd, env: hostEnvOfProcargs(raw) };
|
|
118813
|
+
}
|
|
118814
|
+
function argvOfCmdline(raw) {
|
|
118815
|
+
if (raw.length === 0 || raw[raw.length - 1] !== 0)
|
|
118816
|
+
return null;
|
|
118817
|
+
const argv = raw.toString("utf8", 0, raw.length - 1).split("\x00");
|
|
118818
|
+
if (argv.length > 1 && argv.slice(1).every((arg) => arg === ""))
|
|
118819
|
+
return null;
|
|
118820
|
+
return argv;
|
|
118821
|
+
}
|
|
118822
|
+
function readLinux(pid) {
|
|
118823
|
+
try {
|
|
118824
|
+
const argv = argvOfCmdline(readFileSync46(`/proc/${pid}/cmdline`));
|
|
118825
|
+
if (!argv)
|
|
118826
|
+
return null;
|
|
118827
|
+
const cwd = readlinkSync(`/proc/${pid}/cwd`);
|
|
118828
|
+
let env;
|
|
118829
|
+
try {
|
|
118830
|
+
env = hostEnvOfEnviron(readFileSync46(`/proc/${pid}/environ`));
|
|
118831
|
+
} catch {
|
|
118832
|
+
env = null;
|
|
118833
|
+
}
|
|
118834
|
+
return { argv, cwd, env };
|
|
118835
|
+
} catch {
|
|
118836
|
+
return null;
|
|
118837
|
+
}
|
|
118838
|
+
}
|
|
118839
|
+
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) => {
|
|
118840
|
+
if (!Number.isInteger(pid) || pid <= 1 || pid > PID_MAX)
|
|
118841
|
+
return null;
|
|
118842
|
+
try {
|
|
118843
|
+
if (process.platform === "darwin")
|
|
118844
|
+
return readDarwin(pid);
|
|
118845
|
+
if (process.platform === "linux")
|
|
118846
|
+
return readLinux(pid);
|
|
118847
|
+
} catch {}
|
|
118848
|
+
return null;
|
|
118849
|
+
};
|
|
118850
|
+
var init_host_launch = __esm(() => {
|
|
118851
|
+
init_probe_launch_vars();
|
|
118852
|
+
HOST_ENV_KEYS = HOST_READ_ENV_KEYS;
|
|
118853
|
+
VNODEPATHINFO_BYTES = 2 * (VNODE_INFO_BYTES + MAXPATHLEN);
|
|
118854
|
+
PID_MAX = 2 ** 31 - 1;
|
|
118855
|
+
});
|
|
118856
|
+
|
|
118545
118857
|
// src/mcp-session/inherited-settings.ts
|
|
118546
|
-
import {
|
|
118547
|
-
import {
|
|
118858
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
118859
|
+
import {
|
|
118860
|
+
chmodSync as chmodSync7,
|
|
118861
|
+
closeSync as closeSync16,
|
|
118862
|
+
existsSync as existsSync41,
|
|
118863
|
+
lstatSync as lstatSync9,
|
|
118864
|
+
openSync as openSync16,
|
|
118865
|
+
readFileSync as readFileSync47,
|
|
118866
|
+
readSync as readSync7,
|
|
118867
|
+
readdirSync as readdirSync12,
|
|
118868
|
+
realpathSync as realpathSync8,
|
|
118869
|
+
statSync as statSync23,
|
|
118870
|
+
statfsSync,
|
|
118871
|
+
writeFileSync as writeFileSync22
|
|
118872
|
+
} from "fs";
|
|
118873
|
+
import { userInfo } from "os";
|
|
118874
|
+
import {
|
|
118875
|
+
basename as basename8,
|
|
118876
|
+
delimiter as delimiter2,
|
|
118877
|
+
dirname as dirname23,
|
|
118878
|
+
isAbsolute as isAbsolute4,
|
|
118879
|
+
join as join58,
|
|
118880
|
+
parse as parse8,
|
|
118881
|
+
relative,
|
|
118882
|
+
resolve as resolve8,
|
|
118883
|
+
sep as sep2
|
|
118884
|
+
} from "path";
|
|
118885
|
+
function regularPathKind(path) {
|
|
118886
|
+
try {
|
|
118887
|
+
const stat = statSync23(path);
|
|
118888
|
+
if (stat.isDirectory())
|
|
118889
|
+
return "dir";
|
|
118890
|
+
return stat.isFile() ? "file" : undefined;
|
|
118891
|
+
} catch {
|
|
118892
|
+
return;
|
|
118893
|
+
}
|
|
118894
|
+
}
|
|
118895
|
+
function isRegularFile(path) {
|
|
118896
|
+
return regularPathKind(path) === "file";
|
|
118897
|
+
}
|
|
118898
|
+
function withServerListsAsArrays(layer) {
|
|
118899
|
+
for (const key of ["enabledMcpjsonServers", "disabledMcpjsonServers"]) {
|
|
118900
|
+
const value = layer[key];
|
|
118901
|
+
if (typeof value === "string" && SERVER_NAME.test(value))
|
|
118902
|
+
layer[key] = [value];
|
|
118903
|
+
}
|
|
118904
|
+
return layer;
|
|
118905
|
+
}
|
|
118548
118906
|
function isPlainObject7(value) {
|
|
118549
118907
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
118550
118908
|
}
|
|
@@ -118576,8 +118934,8 @@ function parseLayer(text, source) {
|
|
|
118576
118934
|
let parsed;
|
|
118577
118935
|
try {
|
|
118578
118936
|
parsed = JSON.parse(text);
|
|
118579
|
-
} catch
|
|
118580
|
-
throw new Error(`invalid_args: settings ${source} is not valid JSON
|
|
118937
|
+
} catch {
|
|
118938
|
+
throw new Error(`invalid_args: settings ${source} is not valid JSON`);
|
|
118581
118939
|
}
|
|
118582
118940
|
if (!isPlainObject7(parsed)) {
|
|
118583
118941
|
throw new Error(`invalid_args: settings ${source} is not a JSON object`);
|
|
@@ -118586,23 +118944,20 @@ function parseLayer(text, source) {
|
|
|
118586
118944
|
}
|
|
118587
118945
|
function readSettingsValue(value) {
|
|
118588
118946
|
if (value.trim().startsWith("{"))
|
|
118589
|
-
return parseLayer(value, value);
|
|
118947
|
+
return parseLayer(value, "inline --settings value");
|
|
118948
|
+
if (regularPathKind(value) === undefined && existsSync41(value)) {
|
|
118949
|
+
throw new Error(`invalid_args: settings ${value} cannot be read (not a regular file)`);
|
|
118950
|
+
}
|
|
118590
118951
|
let text;
|
|
118591
118952
|
try {
|
|
118592
|
-
text =
|
|
118953
|
+
text = readFileSync47(value, "utf-8");
|
|
118593
118954
|
} catch (err) {
|
|
118594
118955
|
throw new Error(`invalid_args: settings ${value} cannot be read (${err.message})`);
|
|
118595
118956
|
}
|
|
118596
118957
|
return parseLayer(text, value);
|
|
118597
118958
|
}
|
|
118598
|
-
function buildInheritedSettingsLayer(setupFrom, callerFlags) {
|
|
118599
|
-
const layers =
|
|
118600
|
-
for (const name of ["settings.json", "settings.local.json"]) {
|
|
118601
|
-
const file = join58(setupFrom, ".claude", name);
|
|
118602
|
-
if (!existsSync41(file))
|
|
118603
|
-
continue;
|
|
118604
|
-
layers.push(parseLayer(readFileSync46(file, "utf-8"), file));
|
|
118605
|
-
}
|
|
118959
|
+
function buildInheritedSettingsLayer(setupFrom, callerFlags, options = {}) {
|
|
118960
|
+
const layers = settingsFilesFor(realOrResolved(setupFrom), options.settingSources ?? null).filter(isRegularFile).map((file) => withServerListsAsArrays(parseLayer(readText(file), file)));
|
|
118606
118961
|
const restFlags = [];
|
|
118607
118962
|
for (let i = 0;i < callerFlags.length; i++) {
|
|
118608
118963
|
const flag = callerFlags[i];
|
|
@@ -118610,10 +118965,10 @@ function buildInheritedSettingsLayer(setupFrom, callerFlags) {
|
|
|
118610
118965
|
const value = callerFlags[i + 1];
|
|
118611
118966
|
if (value === undefined)
|
|
118612
118967
|
throw new Error("invalid_args: --settings needs a value");
|
|
118613
|
-
layers.push(readSettingsValue(value));
|
|
118968
|
+
layers.push(withServerListsAsArrays(readSettingsValue(value)));
|
|
118614
118969
|
i++;
|
|
118615
118970
|
} else if (flag.startsWith("--settings=")) {
|
|
118616
|
-
layers.push(readSettingsValue(flag.slice("--settings=".length)));
|
|
118971
|
+
layers.push(withServerListsAsArrays(readSettingsValue(flag.slice("--settings=".length))));
|
|
118617
118972
|
} else {
|
|
118618
118973
|
restFlags.push(flag);
|
|
118619
118974
|
}
|
|
@@ -118625,6 +118980,420 @@ function buildInheritedSettingsLayer(setupFrom, callerFlags) {
|
|
|
118625
118980
|
delete layer.permissions.additionalDirectories;
|
|
118626
118981
|
return { layer, restFlags };
|
|
118627
118982
|
}
|
|
118983
|
+
function settingsFilesFor(setupReal, sources) {
|
|
118984
|
+
const loads = (source) => sources === null || sources.has(source);
|
|
118985
|
+
return [
|
|
118986
|
+
...loads("project") ? [join58(setupReal, ".claude", "settings.json")] : [],
|
|
118987
|
+
...loads("local") ? localSettingsFiles(setupReal, readText, regularPathKind).map(([file]) => file) : []
|
|
118988
|
+
];
|
|
118989
|
+
}
|
|
118990
|
+
function launchSettingsFiles(dir) {
|
|
118991
|
+
return settingsFilesFor(realOrResolved(dir), null);
|
|
118992
|
+
}
|
|
118993
|
+
function launchSettingsFilesByTier(dir, sources) {
|
|
118994
|
+
const real = realOrResolved(dir);
|
|
118995
|
+
const loads = (source) => sources === null || sources.has(source);
|
|
118996
|
+
return {
|
|
118997
|
+
project: loads("project") ? settingsFilesFor(real, new Set(["project"])) : [],
|
|
118998
|
+
local: loads("local") ? settingsFilesFor(real, new Set(["local"])) : []
|
|
118999
|
+
};
|
|
119000
|
+
}
|
|
119001
|
+
function readText(path) {
|
|
119002
|
+
return readFileSync47(path, "utf-8");
|
|
119003
|
+
}
|
|
119004
|
+
function realOrResolved(path) {
|
|
119005
|
+
const missing = [];
|
|
119006
|
+
let current = resolve8(path);
|
|
119007
|
+
for (;; ) {
|
|
119008
|
+
try {
|
|
119009
|
+
return join58(realpathSync8(current), ...missing.reverse());
|
|
119010
|
+
} catch {
|
|
119011
|
+
const parent = dirname23(current);
|
|
119012
|
+
if (parent === current)
|
|
119013
|
+
return resolve8(path);
|
|
119014
|
+
missing.push(basename8(current));
|
|
119015
|
+
current = parent;
|
|
119016
|
+
}
|
|
119017
|
+
}
|
|
119018
|
+
}
|
|
119019
|
+
function isWithin(path, parent) {
|
|
119020
|
+
const rel = relative(realOrResolved(parent), realOrResolved(path));
|
|
119021
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep2}`) && !isAbsolute4(rel);
|
|
119022
|
+
}
|
|
119023
|
+
function writePrivateJson(path, value) {
|
|
119024
|
+
if (existsSync41(path))
|
|
119025
|
+
chmodSync7(path, 384);
|
|
119026
|
+
writeFileSync22(path, `${JSON.stringify(value, null, 2)}
|
|
119027
|
+
`, { encoding: "utf-8", mode: 384 });
|
|
119028
|
+
}
|
|
119029
|
+
function readMcpJson(file) {
|
|
119030
|
+
let text;
|
|
119031
|
+
try {
|
|
119032
|
+
if (statSync23(file).size > MCP_JSON_MAX_BYTES) {
|
|
119033
|
+
log(`[mcp-session] MCP config skipped: ${file} is larger than ${MCP_JSON_MAX_BYTES} bytes`);
|
|
119034
|
+
return null;
|
|
119035
|
+
}
|
|
119036
|
+
text = readText(file);
|
|
119037
|
+
} catch (err) {
|
|
119038
|
+
const code = err.code;
|
|
119039
|
+
log(`[mcp-session] MCP config skipped: ${file} cannot be read${code ? ` (${code})` : ""}`);
|
|
119040
|
+
return null;
|
|
119041
|
+
}
|
|
119042
|
+
if (!text.trim())
|
|
119043
|
+
return {};
|
|
119044
|
+
let parsed;
|
|
119045
|
+
try {
|
|
119046
|
+
parsed = JSON.parse(text);
|
|
119047
|
+
} catch {
|
|
119048
|
+
log(`[mcp-session] MCP config skipped: ${file} is not valid JSON`);
|
|
119049
|
+
return null;
|
|
119050
|
+
}
|
|
119051
|
+
const servers = isPlainObject7(parsed) ? parsed.mcpServers ?? {} : undefined;
|
|
119052
|
+
if (!isPlainObject7(servers)) {
|
|
119053
|
+
log(`[mcp-session] MCP config skipped: ${file} is not {"mcpServers": {...}} JSON`);
|
|
119054
|
+
return null;
|
|
119055
|
+
}
|
|
119056
|
+
return servers;
|
|
119057
|
+
}
|
|
119058
|
+
function isConnectorDownloadsName(segment) {
|
|
119059
|
+
const folded = segment.toLowerCase().replaceAll("\u017F", "s").replace(INVISIBLE_FORMAT_CHARS, "");
|
|
119060
|
+
return segment.length >= CONNECTOR_DOWNLOADS.length && CONNECTOR_DOWNLOADS_NAME.test(folded);
|
|
119061
|
+
}
|
|
119062
|
+
function inConnectorDownloads(dir) {
|
|
119063
|
+
return dir.split(/[\\/]/).some(isConnectorDownloadsName);
|
|
119064
|
+
}
|
|
119065
|
+
function inBrowserDownloads(dir) {
|
|
119066
|
+
return BROWSER_DOWNLOADS_ROOTS.some((root) => dir === root || dir.startsWith(`${root}/`));
|
|
119067
|
+
}
|
|
119068
|
+
function isAutofsMapRoot(dir, env, platform = process.platform, statfs = statfsSync) {
|
|
119069
|
+
const listed = env.CLAUDE_CODE_AUTOMOUNT_ROOTS?.split(delimiter2).some((root) => isAbsolute4(root) && resolve8(root) === dir);
|
|
119070
|
+
if (listed)
|
|
119071
|
+
return true;
|
|
119072
|
+
if (platform !== "linux" || dir === "/" || dirname23(dir) !== "/")
|
|
119073
|
+
return false;
|
|
119074
|
+
try {
|
|
119075
|
+
return statfs(dir).type === AUTOFS_SUPER_MAGIC;
|
|
119076
|
+
} catch {
|
|
119077
|
+
return false;
|
|
119078
|
+
}
|
|
119079
|
+
}
|
|
119080
|
+
function mcpJsonWalkDirs(start, walk) {
|
|
119081
|
+
let current = resolve8(start);
|
|
119082
|
+
const root = walk.root === undefined ? parse8(current).root : resolve8(walk.root);
|
|
119083
|
+
const dirs = [];
|
|
119084
|
+
while (current !== root) {
|
|
119085
|
+
const skipped = inConnectorDownloads(current) || inBrowserDownloads(current) || isAutofsMapRoot(current, walk.env);
|
|
119086
|
+
if (!skipped)
|
|
119087
|
+
dirs.push(current);
|
|
119088
|
+
const parent = dirname23(current);
|
|
119089
|
+
if (parent === current)
|
|
119090
|
+
break;
|
|
119091
|
+
current = parent;
|
|
119092
|
+
}
|
|
119093
|
+
return dirs;
|
|
119094
|
+
}
|
|
119095
|
+
function walkUpMcpJsonServers(setupReal, childReal, env) {
|
|
119096
|
+
const files = mcpJsonWalkDirs(setupReal, { env }).filter((dir) => !isWithin(childReal, dir)).map((dir) => join58(dir, ".mcp.json")).filter(isRegularFile);
|
|
119097
|
+
const servers = {};
|
|
119098
|
+
for (const file of files.reverse())
|
|
119099
|
+
Object.assign(servers, readMcpJson(file) ?? {});
|
|
119100
|
+
return servers;
|
|
119101
|
+
}
|
|
119102
|
+
function globalConfigProjectEntry(env, projectKey, cwd) {
|
|
119103
|
+
const file = claudeCodeGlobalConfigPath(env, cwd);
|
|
119104
|
+
if (!isRegularFile(file))
|
|
119105
|
+
return null;
|
|
119106
|
+
let parsed;
|
|
119107
|
+
try {
|
|
119108
|
+
parsed = JSON.parse(readText(file));
|
|
119109
|
+
} catch {
|
|
119110
|
+
log(`[mcp-session] local-scope MCP servers skipped: ${file} is unreadable or not valid JSON`);
|
|
119111
|
+
return null;
|
|
119112
|
+
}
|
|
119113
|
+
const projects = isPlainObject7(parsed) ? parsed.projects : undefined;
|
|
119114
|
+
const entry = isPlainObject7(projects) ? projects[projectKey] : undefined;
|
|
119115
|
+
return isPlainObject7(entry) ? entry : null;
|
|
119116
|
+
}
|
|
119117
|
+
function serverNameList(value, acceptString) {
|
|
119118
|
+
if (Array.isArray(value))
|
|
119119
|
+
return value.filter((v) => typeof v === "string");
|
|
119120
|
+
return acceptString && typeof value === "string" && SERVER_NAME.test(value) ? [value] : [];
|
|
119121
|
+
}
|
|
119122
|
+
function disabledListOf(file, acceptString) {
|
|
119123
|
+
if (!isRegularFile(file))
|
|
119124
|
+
return [];
|
|
119125
|
+
try {
|
|
119126
|
+
const parsed = JSON.parse(readText(file));
|
|
119127
|
+
return isPlainObject7(parsed) ? serverNameList(parsed.disabledMcpjsonServers, acceptString) : [];
|
|
119128
|
+
} catch {
|
|
119129
|
+
log(`[mcp-session] disabledMcpjsonServers not read: ${file} is unreadable or not valid JSON`);
|
|
119130
|
+
return [];
|
|
119131
|
+
}
|
|
119132
|
+
}
|
|
119133
|
+
function readJsonPolicy(path, maxBytes) {
|
|
119134
|
+
try {
|
|
119135
|
+
const stat = statSync23(path);
|
|
119136
|
+
if (!stat.isFile())
|
|
119137
|
+
return null;
|
|
119138
|
+
if (stat.size > maxBytes)
|
|
119139
|
+
return "oversize";
|
|
119140
|
+
const parsed = JSON.parse(readText(path));
|
|
119141
|
+
return isPlainObject7(parsed) ? parsed : null;
|
|
119142
|
+
} catch {
|
|
119143
|
+
return null;
|
|
119144
|
+
}
|
|
119145
|
+
}
|
|
119146
|
+
function readPlistPolicy(path, readPlist) {
|
|
119147
|
+
if (!isRegularFile(path))
|
|
119148
|
+
return "skipped";
|
|
119149
|
+
const text = readPlist(path);
|
|
119150
|
+
if (text === null)
|
|
119151
|
+
return "skipped";
|
|
119152
|
+
try {
|
|
119153
|
+
const parsed = JSON.parse(text);
|
|
119154
|
+
return { taken: isPlainObject7(parsed) ? parsed : null };
|
|
119155
|
+
} catch {
|
|
119156
|
+
return { taken: null };
|
|
119157
|
+
}
|
|
119158
|
+
}
|
|
119159
|
+
function managedSettingsFiles(file, dropInDir) {
|
|
119160
|
+
const files = file ? [file] : [];
|
|
119161
|
+
if (dropInDir && regularPathKind(dropInDir) === "dir") {
|
|
119162
|
+
let names = [];
|
|
119163
|
+
try {
|
|
119164
|
+
names = readdirSync12(dropInDir);
|
|
119165
|
+
} catch {
|
|
119166
|
+
log(`[mcp-session] managed drop-ins not read: ${dropInDir} cannot be listed`);
|
|
119167
|
+
}
|
|
119168
|
+
const dropIns = names.filter((name) => name.endsWith(".json") && !name.startsWith("."));
|
|
119169
|
+
files.push(...dropIns.sort().map((name) => join58(dropInDir, name)));
|
|
119170
|
+
}
|
|
119171
|
+
return files;
|
|
119172
|
+
}
|
|
119173
|
+
function remoteSettingsPath(managed, env, cwd) {
|
|
119174
|
+
if (managed.remoteSettingsFile === null) {
|
|
119175
|
+
return join58(claudeCodeConfigDir(env, cwd), REMOTE_SETTINGS_FILE);
|
|
119176
|
+
}
|
|
119177
|
+
return managed.remoteSettingsFile;
|
|
119178
|
+
}
|
|
119179
|
+
function hybridSettingsDirOf(managed, env, cwd) {
|
|
119180
|
+
if (managed.hybridSettingsDir === null)
|
|
119181
|
+
return join58(claudeCodeConfigDir(env, cwd), "state");
|
|
119182
|
+
return managed.hybridSettingsDir;
|
|
119183
|
+
}
|
|
119184
|
+
function readManagedPolicy(managed, env, cwd) {
|
|
119185
|
+
const objects = [];
|
|
119186
|
+
const oversize = [];
|
|
119187
|
+
const remote = remoteSettingsPath(managed, env, cwd);
|
|
119188
|
+
if (remote !== undefined) {
|
|
119189
|
+
const value = readJsonPolicy(remote, REMOTE_SETTINGS_MAX_BYTES);
|
|
119190
|
+
if (value !== null && value !== "oversize")
|
|
119191
|
+
objects.push({ path: remote, value });
|
|
119192
|
+
}
|
|
119193
|
+
const readPlist = managed.readPlist ?? plutilJson;
|
|
119194
|
+
for (const plist of managed.managedPreferencePlists ?? []) {
|
|
119195
|
+
const read = readPlistPolicy(plist, readPlist);
|
|
119196
|
+
if (read === "skipped")
|
|
119197
|
+
continue;
|
|
119198
|
+
if (read.taken !== null)
|
|
119199
|
+
objects.push({ path: plist, value: read.taken });
|
|
119200
|
+
break;
|
|
119201
|
+
}
|
|
119202
|
+
for (const path of managedSettingsFiles(managed.managedSettingsFile, managed.managedSettingsDropInDir)) {
|
|
119203
|
+
const value = readJsonPolicy(path, MANAGED_FILE_MAX_BYTES);
|
|
119204
|
+
if (value === "oversize")
|
|
119205
|
+
oversize.push(path);
|
|
119206
|
+
else if (value !== null)
|
|
119207
|
+
objects.push({ path, value });
|
|
119208
|
+
}
|
|
119209
|
+
return { objects, oversize };
|
|
119210
|
+
}
|
|
119211
|
+
function pathPresent(path) {
|
|
119212
|
+
try {
|
|
119213
|
+
lstatSync9(path);
|
|
119214
|
+
return true;
|
|
119215
|
+
} catch (err) {
|
|
119216
|
+
const code = err.code;
|
|
119217
|
+
return code !== "ENOENT" && code !== "ENOTDIR";
|
|
119218
|
+
}
|
|
119219
|
+
}
|
|
119220
|
+
function presentEntries(dir, keep) {
|
|
119221
|
+
if (!pathPresent(dir))
|
|
119222
|
+
return [];
|
|
119223
|
+
try {
|
|
119224
|
+
return readdirSync12(dir).filter(keep).sort().map((name) => join58(dir, name));
|
|
119225
|
+
} catch {
|
|
119226
|
+
return [dir];
|
|
119227
|
+
}
|
|
119228
|
+
}
|
|
119229
|
+
function remoteSettingsSetsNothing(path) {
|
|
119230
|
+
try {
|
|
119231
|
+
const stat = lstatSync9(path);
|
|
119232
|
+
if (!stat.isFile() || stat.size > REMOTE_SETTINGS_MAX_BYTES)
|
|
119233
|
+
return false;
|
|
119234
|
+
const parsed = JSON.parse(readText(path));
|
|
119235
|
+
return isPlainObject7(parsed) && Object.keys(parsed).every((key) => key.startsWith("$"));
|
|
119236
|
+
} catch {
|
|
119237
|
+
return false;
|
|
119238
|
+
}
|
|
119239
|
+
}
|
|
119240
|
+
function managedPolicySourcePresent(managed, env, cwd) {
|
|
119241
|
+
const remote = remoteSettingsPath(managed, env, cwd);
|
|
119242
|
+
if (remote !== undefined && pathPresent(remote) && !remoteSettingsSetsNothing(remote)) {
|
|
119243
|
+
return remote;
|
|
119244
|
+
}
|
|
119245
|
+
const files = [...managed.managedPreferencePlists ?? [], managed.managedSettingsFile];
|
|
119246
|
+
for (const path of files)
|
|
119247
|
+
if (path !== undefined && pathPresent(path))
|
|
119248
|
+
return path;
|
|
119249
|
+
const dropInDir = managed.managedSettingsDropInDir;
|
|
119250
|
+
const dropIn = dropInDir ? presentEntries(dropInDir, () => true)[0] : undefined;
|
|
119251
|
+
if (dropIn !== undefined)
|
|
119252
|
+
return dropIn;
|
|
119253
|
+
if (managed.managedMcpFile !== undefined && pathPresent(managed.managedMcpFile)) {
|
|
119254
|
+
return managed.managedMcpFile;
|
|
119255
|
+
}
|
|
119256
|
+
const hybridDir = hybridSettingsDirOf(managed, env, cwd);
|
|
119257
|
+
const hybrid = hybridDir ? presentEntries(hybridDir, (n) => n.startsWith("hybrid-settings") && n.endsWith(".json"))[0] : undefined;
|
|
119258
|
+
if (hybrid !== undefined)
|
|
119259
|
+
return hybrid;
|
|
119260
|
+
return managed.registryPolicyKeys?.[0];
|
|
119261
|
+
}
|
|
119262
|
+
function sideloadFlagsDisabledBy(policy) {
|
|
119263
|
+
return policy.objects.find(({ value }) => value.disableSideloadFlags === true)?.path;
|
|
119264
|
+
}
|
|
119265
|
+
function managedPolicyBlocksMcpConfig(policy) {
|
|
119266
|
+
const oversize = policy.oversize[0];
|
|
119267
|
+
if (oversize !== undefined) {
|
|
119268
|
+
log(`[mcp-session] no MCP server handed over: ${oversize} is larger than claudish reads, so claudish cannot tell whether it sets disableSideloadFlags`);
|
|
119269
|
+
return true;
|
|
119270
|
+
}
|
|
119271
|
+
const path = sideloadFlagsDisabledBy(policy);
|
|
119272
|
+
if (path === undefined)
|
|
119273
|
+
return false;
|
|
119274
|
+
log(`[mcp-session] no MCP server handed over: ${path} sets disableSideloadFlags, and Claude Code refuses --mcp-config while it does`);
|
|
119275
|
+
return true;
|
|
119276
|
+
}
|
|
119277
|
+
function registryPolicyState(answer) {
|
|
119278
|
+
if (answer === null)
|
|
119279
|
+
return "unknown";
|
|
119280
|
+
const listed = REG_SETTINGS_LINE.test(answer.stdout);
|
|
119281
|
+
if (answer.status === 0 && listed)
|
|
119282
|
+
return "present";
|
|
119283
|
+
if (answer.status === 1 && !listed)
|
|
119284
|
+
return "absent";
|
|
119285
|
+
return "unknown";
|
|
119286
|
+
}
|
|
119287
|
+
function registryPolicyBlocksMcpConfig(managed) {
|
|
119288
|
+
const read = managed.readRegistry ?? regQuery;
|
|
119289
|
+
for (const key of managed.registryPolicyKeys ?? []) {
|
|
119290
|
+
const state = registryPolicyState(read(key));
|
|
119291
|
+
if (state === "absent")
|
|
119292
|
+
continue;
|
|
119293
|
+
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`);
|
|
119294
|
+
return true;
|
|
119295
|
+
}
|
|
119296
|
+
return false;
|
|
119297
|
+
}
|
|
119298
|
+
function comparableServerName(name) {
|
|
119299
|
+
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
119300
|
+
}
|
|
119301
|
+
function isDisabledBy(name, disabled) {
|
|
119302
|
+
return disabled.some((entry) => entry === name || !entry.startsWith("plugin:") && !name.startsWith("plugin:") && comparableServerName(entry) === comparableServerName(name));
|
|
119303
|
+
}
|
|
119304
|
+
function managedPreferencePlistsFor(username) {
|
|
119305
|
+
const root = "/Library/Managed Preferences";
|
|
119306
|
+
const plists = [];
|
|
119307
|
+
const unsafe = [...username].some((ch) => {
|
|
119308
|
+
const code = ch.charCodeAt(0);
|
|
119309
|
+
return ch === "/" || code <= 31 || code === 127;
|
|
119310
|
+
});
|
|
119311
|
+
if (!["", ".", ".."].includes(username) && !unsafe) {
|
|
119312
|
+
plists.push(join58(root, username, `${MANAGED_PREFERENCE_DOMAIN}.plist`));
|
|
119313
|
+
}
|
|
119314
|
+
plists.push(join58(root, `${MANAGED_PREFERENCE_DOMAIN}.plist`));
|
|
119315
|
+
return plists;
|
|
119316
|
+
}
|
|
119317
|
+
function currentUsername() {
|
|
119318
|
+
try {
|
|
119319
|
+
return userInfo().username;
|
|
119320
|
+
} catch {
|
|
119321
|
+
return "";
|
|
119322
|
+
}
|
|
119323
|
+
}
|
|
119324
|
+
function realManagedPaths(platform = process.platform) {
|
|
119325
|
+
const managedSettingsFile = managedSettingsPath();
|
|
119326
|
+
const dir = dirname23(managedSettingsFile);
|
|
119327
|
+
return {
|
|
119328
|
+
managedSettingsFile,
|
|
119329
|
+
managedSettingsDropInDir: join58(dir, "managed-settings.d"),
|
|
119330
|
+
managedMcpFile: join58(dir, "managed-mcp.json"),
|
|
119331
|
+
managedPreferencePlists: platform === "darwin" ? managedPreferencePlistsFor(currentUsername()) : [],
|
|
119332
|
+
remoteSettingsFile: null,
|
|
119333
|
+
hybridSettingsDir: null,
|
|
119334
|
+
registryPolicyKeys: platform === "win32" ? [...WINDOWS_POLICY_KEYS] : []
|
|
119335
|
+
};
|
|
119336
|
+
}
|
|
119337
|
+
function managedMcpPresent(file) {
|
|
119338
|
+
if (!file || !existsSync41(file))
|
|
119339
|
+
return false;
|
|
119340
|
+
log(`[mcp-session] no MCP server handed over: ${file} is present, and Claude Code refuses --mcp-config while it is`);
|
|
119341
|
+
return true;
|
|
119342
|
+
}
|
|
119343
|
+
function managedPolicyRefusesMcpConfig(managed, policy) {
|
|
119344
|
+
if (managedMcpPresent(managed.managedMcpFile))
|
|
119345
|
+
return true;
|
|
119346
|
+
if (registryPolicyBlocksMcpConfig(managed))
|
|
119347
|
+
return true;
|
|
119348
|
+
return managedPolicyBlocksMcpConfig(policy);
|
|
119349
|
+
}
|
|
119350
|
+
function mainCheckoutKey(dir) {
|
|
119351
|
+
return realOrResolved(mainCheckoutRoot(dir, readText, regularPathKind) ?? dir);
|
|
119352
|
+
}
|
|
119353
|
+
function sharesMainCheckout(a, b) {
|
|
119354
|
+
return mainCheckoutKey(realOrResolved(a)) === mainCheckoutKey(realOrResolved(b));
|
|
119355
|
+
}
|
|
119356
|
+
function buildInheritedMcpConfig(setupFrom, childCwd, layer, env, options = {}) {
|
|
119357
|
+
const setupReal = realOrResolved(setupFrom);
|
|
119358
|
+
const childReal = realOrResolved(childCwd);
|
|
119359
|
+
const sources = options.settingSources ?? null;
|
|
119360
|
+
const loads = (source) => sources === null || sources.has(source);
|
|
119361
|
+
const projectGate = !isWithin(childReal, setupReal) && loads("project");
|
|
119362
|
+
const setupMain = mainCheckoutKey(setupReal);
|
|
119363
|
+
const sharedMain = setupMain === mainCheckoutKey(childReal);
|
|
119364
|
+
const localGate = !sharedMain && loads("local");
|
|
119365
|
+
if (!projectGate && !localGate)
|
|
119366
|
+
return null;
|
|
119367
|
+
const policy = readManagedPolicy(options, env, childReal);
|
|
119368
|
+
if (managedPolicyRefusesMcpConfig(options, policy))
|
|
119369
|
+
return null;
|
|
119370
|
+
const entry = globalConfigProjectEntry(env, setupMain, childReal);
|
|
119371
|
+
const localDefined = isPlainObject7(entry?.mcpServers) ? entry.mcpServers : {};
|
|
119372
|
+
const projectServers = projectGate ? walkUpMcpJsonServers(setupReal, childReal, env) : {};
|
|
119373
|
+
const userFile = userSettingsFile(env.CLAUDE_CONFIG_DIR, env.HOME ?? "", childReal);
|
|
119374
|
+
const disabled = [
|
|
119375
|
+
...serverNameList(layer?.disabledMcpjsonServers, true),
|
|
119376
|
+
...serverNameList(entry?.disabledMcpjsonServers, true),
|
|
119377
|
+
...loads("user") ? disabledListOf(userFile, true) : [],
|
|
119378
|
+
...policy.objects.flatMap(({ value }) => serverNameList(value.disabledMcpjsonServers, false))
|
|
119379
|
+
];
|
|
119380
|
+
const turnedOff = serverNameList(entry?.disabledMcpServers, false);
|
|
119381
|
+
const definedLocally = sharedMain && loads("local") ? Object.keys(localDefined) : [];
|
|
119382
|
+
const withheld = (name) => isDisabledBy(name, disabled) || definedLocally.includes(name);
|
|
119383
|
+
for (const name of Object.keys(projectServers).filter(withheld))
|
|
119384
|
+
delete projectServers[name];
|
|
119385
|
+
const localServers = localGate ? localDefined : {};
|
|
119386
|
+
const mcpServers = Object.fromEntries(Object.entries({ ...projectServers, ...localServers }).filter(([name]) => !turnedOff.includes(name)));
|
|
119387
|
+
return Object.keys(mcpServers).length > 0 ? { mcpServers } : null;
|
|
119388
|
+
}
|
|
119389
|
+
function inheritedMcpFor(setupFrom, childCwd, layer, callerFlags, env, managed) {
|
|
119390
|
+
if (!setupFrom || callerFlags.includes("--strict-mcp-config"))
|
|
119391
|
+
return null;
|
|
119392
|
+
return buildInheritedMcpConfig(setupFrom, childCwd, layer, env, {
|
|
119393
|
+
settingSources: enabledSettingSources(callerFlags),
|
|
119394
|
+
...managed
|
|
119395
|
+
});
|
|
119396
|
+
}
|
|
118628
119397
|
function resolveSetupFrom(arg, workDir, serverCwd) {
|
|
118629
119398
|
if (arg === null)
|
|
118630
119399
|
return;
|
|
@@ -118639,7 +119408,67 @@ function resolveSetupFrom(arg, workDir, serverCwd) {
|
|
|
118639
119408
|
}
|
|
118640
119409
|
return setupFrom === resolve8(workDir ?? serverCwd) ? undefined : setupFrom;
|
|
118641
119410
|
}
|
|
118642
|
-
var
|
|
119411
|
+
var SERVER_NAME, MCP_JSON_MAX_BYTES, CONNECTOR_DOWNLOADS = "connector-downloads", CONNECTOR_DOWNLOADS_NAME, INVISIBLE_FORMAT_CHARS, BROWSER_DOWNLOADS_ROOTS, AUTOFS_SUPER_MAGIC = 391, PLUTIL = "/usr/bin/plutil", PLUTIL_TIMEOUT_MS = 5000, PLUTIL_MAX_BYTES, REMOTE_SETTINGS_MAX_BYTES, MANAGED_FILE_MAX_BYTES, plutilJson = (path) => {
|
|
119412
|
+
const plutil = (args) => spawnSync3(PLUTIL, [...args, "--", path], {
|
|
119413
|
+
encoding: "utf-8",
|
|
119414
|
+
timeout: PLUTIL_TIMEOUT_MS,
|
|
119415
|
+
killSignal: "SIGKILL",
|
|
119416
|
+
maxBuffer: PLUTIL_MAX_BYTES,
|
|
119417
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
119418
|
+
});
|
|
119419
|
+
const run = plutil(["-convert", "json", "-o", "-"]);
|
|
119420
|
+
if (run.error || run.signal !== null)
|
|
119421
|
+
return null;
|
|
119422
|
+
if (run.status === 0 && typeof run.stdout === "string")
|
|
119423
|
+
return run.stdout;
|
|
119424
|
+
const lint = plutil(["-lint", "-s"]);
|
|
119425
|
+
if (lint.error || lint.signal !== null || lint.status === 0)
|
|
119426
|
+
return null;
|
|
119427
|
+
let fd;
|
|
119428
|
+
try {
|
|
119429
|
+
fd = openSync16(path, "r");
|
|
119430
|
+
readSync7(fd, Buffer.alloc(1), 0, 1, 0);
|
|
119431
|
+
} catch {
|
|
119432
|
+
return null;
|
|
119433
|
+
} finally {
|
|
119434
|
+
if (fd !== undefined)
|
|
119435
|
+
closeSync16(fd);
|
|
119436
|
+
}
|
|
119437
|
+
return "";
|
|
119438
|
+
}, REG_TIMEOUT_MS = 5000, REG_SETTINGS_LINE, regQuery = (key) => {
|
|
119439
|
+
const root = process.env.SystemRoot ?? "C:\\Windows";
|
|
119440
|
+
const run = spawnSync3(`${root}\\System32\\reg.exe`, ["query", key, "/v", "Settings"], {
|
|
119441
|
+
encoding: "utf-8",
|
|
119442
|
+
timeout: REG_TIMEOUT_MS,
|
|
119443
|
+
killSignal: "SIGKILL",
|
|
119444
|
+
windowsHide: true,
|
|
119445
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
119446
|
+
});
|
|
119447
|
+
if (run.error)
|
|
119448
|
+
return null;
|
|
119449
|
+
return { status: run.status, stdout: run.stdout ?? "", stderr: run.stderr ?? "" };
|
|
119450
|
+
}, REMOTE_SETTINGS_FILE = "remote-settings.json", MANAGED_PREFERENCE_DOMAIN = "com.anthropic.claudecode", WINDOWS_POLICY_KEYS;
|
|
119451
|
+
var init_inherited_settings = __esm(() => {
|
|
119452
|
+
init_claude_code_facts();
|
|
119453
|
+
init_claude_runner();
|
|
119454
|
+
init_logger();
|
|
119455
|
+
SERVER_NAME = /^[A-Za-z0-9_-]+$/;
|
|
119456
|
+
MCP_JSON_MAX_BYTES = 2 * 1024 * 1024;
|
|
119457
|
+
CONNECTOR_DOWNLOADS_NAME = /^connector-downloads[. ]*(?::.*)?$/;
|
|
119458
|
+
INVISIBLE_FORMAT_CHARS = /[\u200C-\u200F\u202A-\u202E\u206A-\u206F\uFEFF]/g;
|
|
119459
|
+
BROWSER_DOWNLOADS_ROOTS = [
|
|
119460
|
+
"/mnt/user-data/browser-downloads",
|
|
119461
|
+
"/mnt/user-data/desktop-browser-downloads"
|
|
119462
|
+
];
|
|
119463
|
+
PLUTIL_MAX_BYTES = 2 * 1024 * 1024;
|
|
119464
|
+
REMOTE_SETTINGS_MAX_BYTES = 8 * 1024 * 1024;
|
|
119465
|
+
MANAGED_FILE_MAX_BYTES = 8 * 1024 * 1024;
|
|
119466
|
+
REG_SETTINGS_LINE = /^[ \t]+Settings[ \t]+REG_/im;
|
|
119467
|
+
WINDOWS_POLICY_KEYS = [
|
|
119468
|
+
"HKLM\\SOFTWARE\\Policies\\ClaudeCode",
|
|
119469
|
+
"HKCU\\SOFTWARE\\Policies\\ClaudeCode"
|
|
119470
|
+
];
|
|
119471
|
+
});
|
|
118643
119472
|
|
|
118644
119473
|
// src/mcp-session/parent-session.ts
|
|
118645
119474
|
import { readFile as readFile7 } from "fs/promises";
|
|
@@ -118695,6 +119524,979 @@ var init_parent_session = __esm(() => {
|
|
|
118695
119524
|
CLAUDE_ID_RE = /^[A-Za-z0-9_-]{8,128}$/;
|
|
118696
119525
|
});
|
|
118697
119526
|
|
|
119527
|
+
// src/mcp-session/plugin-probe.ts
|
|
119528
|
+
import { spawn as spawn4 } from "child_process";
|
|
119529
|
+
import {
|
|
119530
|
+
constants as constants5,
|
|
119531
|
+
closeSync as closeSync17,
|
|
119532
|
+
fstatSync as fstatSync5,
|
|
119533
|
+
lstatSync as lstatSync10,
|
|
119534
|
+
mkdtempSync as mkdtempSync4,
|
|
119535
|
+
openSync as openSync17,
|
|
119536
|
+
readFileSync as readFileSync48,
|
|
119537
|
+
readdirSync as readdirSync13,
|
|
119538
|
+
rmSync as rmSync15,
|
|
119539
|
+
statSync as statSync24
|
|
119540
|
+
} from "fs";
|
|
119541
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
119542
|
+
import { basename as basename9, isAbsolute as isAbsolute5, join as join60, resolve as resolve9 } from "path";
|
|
119543
|
+
function passes(flags, flag) {
|
|
119544
|
+
return flags.some((t) => t === flag || t.startsWith(`${flag}=`));
|
|
119545
|
+
}
|
|
119546
|
+
function passesBeforeEnd(flags, flag) {
|
|
119547
|
+
const at = flags.indexOf(flag);
|
|
119548
|
+
const end = flags.indexOf("--");
|
|
119549
|
+
return at !== -1 && (end === -1 || at < end);
|
|
119550
|
+
}
|
|
119551
|
+
function pluginLoadingFlags(flags, base) {
|
|
119552
|
+
const out = [];
|
|
119553
|
+
const push = (flag, value) => out.push(flag, PLUGIN_PATH_FLAGS.includes(flag) ? resolve9(base, value) : value);
|
|
119554
|
+
const takesValue = (flag) => PLUGIN_PATH_FLAGS.includes(flag) || PLUGIN_VALUE_FLAGS.includes(flag);
|
|
119555
|
+
for (let i = 0;i < flags.length; i++) {
|
|
119556
|
+
const token = flags[i];
|
|
119557
|
+
if (PLUGIN_BOOLEAN_FLAGS.includes(token)) {
|
|
119558
|
+
out.push(token);
|
|
119559
|
+
continue;
|
|
119560
|
+
}
|
|
119561
|
+
if (takesValue(token)) {
|
|
119562
|
+
const value = flags[i + 1];
|
|
119563
|
+
if (value !== undefined)
|
|
119564
|
+
push(token, value);
|
|
119565
|
+
i++;
|
|
119566
|
+
continue;
|
|
119567
|
+
}
|
|
119568
|
+
const eq = token.indexOf("=");
|
|
119569
|
+
const flag = eq > 0 ? token.slice(0, eq) : "";
|
|
119570
|
+
if (takesValue(flag))
|
|
119571
|
+
push(flag, token.slice(eq + 1));
|
|
119572
|
+
}
|
|
119573
|
+
return out;
|
|
119574
|
+
}
|
|
119575
|
+
function pluginProbeArgs(settingsFile, launchFlags, base) {
|
|
119576
|
+
const quiet = QUIET_FLAGS.map((flag) => flag === "<settings file>" ? settingsFile : flag);
|
|
119577
|
+
return [...quiet, ...pluginLoadingFlags(launchFlags, base), "-p", "/effort"];
|
|
119578
|
+
}
|
|
119579
|
+
function isProbeParentVar(key) {
|
|
119580
|
+
return PROBE_PARENT_VARS.includes(key) || /^LC_[A-Z]+$/.test(key);
|
|
119581
|
+
}
|
|
119582
|
+
function pluginProbeEnv(parentEnv) {
|
|
119583
|
+
const env = {};
|
|
119584
|
+
for (const [key, value] of Object.entries(parentEnv)) {
|
|
119585
|
+
if (value !== undefined && isProbeParentVar(key))
|
|
119586
|
+
env[key] = value;
|
|
119587
|
+
}
|
|
119588
|
+
env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
|
|
119589
|
+
env[PROBE_HOST_MANAGED_MARKER] = "1";
|
|
119590
|
+
env.ANTHROPIC_BASE_URL = PLUGIN_PROBE_BASE_URL;
|
|
119591
|
+
return env;
|
|
119592
|
+
}
|
|
119593
|
+
function isPlainObject8(value) {
|
|
119594
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
119595
|
+
}
|
|
119596
|
+
function pluginProbeSettings(layer) {
|
|
119597
|
+
const base = structuredClone(layer ?? {});
|
|
119598
|
+
for (const key of ["hooks", ...COMMAND_SETTINGS])
|
|
119599
|
+
delete base[key];
|
|
119600
|
+
if (isPlainObject8(base.env)) {
|
|
119601
|
+
const closed = new Set(Object.keys(PROBE_SETTINGS_ENV));
|
|
119602
|
+
base.env = Object.fromEntries(Object.entries(base.env).filter(([key]) => !closed.has(key.toUpperCase())));
|
|
119603
|
+
} else {
|
|
119604
|
+
delete base.env;
|
|
119605
|
+
}
|
|
119606
|
+
return mergeSettingsLayers(base, { disableAllHooks: true, env: { ...PROBE_SETTINGS_ENV } });
|
|
119607
|
+
}
|
|
119608
|
+
function readRegularFile(path) {
|
|
119609
|
+
let fd;
|
|
119610
|
+
try {
|
|
119611
|
+
fd = openSync17(path, constants5.O_RDONLY | constants5.O_NONBLOCK);
|
|
119612
|
+
} catch (err) {
|
|
119613
|
+
const code = err.code;
|
|
119614
|
+
return code === "ENOENT" || code === "ENOTDIR" ? null : "unreadable";
|
|
119615
|
+
}
|
|
119616
|
+
try {
|
|
119617
|
+
if (!fstatSync5(fd).isFile())
|
|
119618
|
+
return "unreadable";
|
|
119619
|
+
return readFileSync48(fd, "utf-8");
|
|
119620
|
+
} catch {
|
|
119621
|
+
return "unreadable";
|
|
119622
|
+
} finally {
|
|
119623
|
+
closeSync17(fd);
|
|
119624
|
+
}
|
|
119625
|
+
}
|
|
119626
|
+
function commandSettingIn(paths, keys) {
|
|
119627
|
+
for (const path of paths) {
|
|
119628
|
+
const text = readRegularFile(path);
|
|
119629
|
+
if (text === null)
|
|
119630
|
+
continue;
|
|
119631
|
+
if (text === "unreadable")
|
|
119632
|
+
return { path };
|
|
119633
|
+
let parsed;
|
|
119634
|
+
try {
|
|
119635
|
+
parsed = JSON.parse(text);
|
|
119636
|
+
} catch {
|
|
119637
|
+
return { path };
|
|
119638
|
+
}
|
|
119639
|
+
if (!isPlainObject8(parsed))
|
|
119640
|
+
return { path };
|
|
119641
|
+
const key = keys.find((k) => parsed[k] !== undefined && parsed[k] !== null);
|
|
119642
|
+
if (key !== undefined)
|
|
119643
|
+
return { path, key };
|
|
119644
|
+
}
|
|
119645
|
+
return;
|
|
119646
|
+
}
|
|
119647
|
+
function initPluginsOf(event) {
|
|
119648
|
+
const list = isPlainObject8(event) ? event.plugins : undefined;
|
|
119649
|
+
if (!Array.isArray(list))
|
|
119650
|
+
return null;
|
|
119651
|
+
const plugins = [];
|
|
119652
|
+
for (const item of list) {
|
|
119653
|
+
if (!isPlainObject8(item))
|
|
119654
|
+
return null;
|
|
119655
|
+
const { name, path, source, version } = item;
|
|
119656
|
+
if (typeof name !== "string" || typeof path !== "string" || typeof source !== "string") {
|
|
119657
|
+
return null;
|
|
119658
|
+
}
|
|
119659
|
+
if (version !== undefined && typeof version !== "string")
|
|
119660
|
+
return null;
|
|
119661
|
+
plugins.push({ name, path, source, ...version !== undefined ? { version } : {} });
|
|
119662
|
+
}
|
|
119663
|
+
return plugins;
|
|
119664
|
+
}
|
|
119665
|
+
function manifestNames(path, name) {
|
|
119666
|
+
const manifest = join60(path, ".claude-plugin", "plugin.json");
|
|
119667
|
+
try {
|
|
119668
|
+
if (!statSync24(manifest).isFile())
|
|
119669
|
+
return false;
|
|
119670
|
+
const parsed = JSON.parse(readFileSync48(manifest, "utf-8"));
|
|
119671
|
+
return isPlainObject8(parsed) && parsed.name === name;
|
|
119672
|
+
} catch {
|
|
119673
|
+
return false;
|
|
119674
|
+
}
|
|
119675
|
+
}
|
|
119676
|
+
function pluginsToHandOver(caller, child) {
|
|
119677
|
+
const childPaths = new Map(child.map((p) => [p.source, p.path]));
|
|
119678
|
+
const childInline = new Set(child.filter((p) => p.source.endsWith("@inline")).map((p) => p.name));
|
|
119679
|
+
const seen = new Set;
|
|
119680
|
+
const plugins = [];
|
|
119681
|
+
for (const p of caller) {
|
|
119682
|
+
if (p.source.endsWith("@inline") || !isAbsolute5(p.path))
|
|
119683
|
+
continue;
|
|
119684
|
+
if (childPaths.get(p.source) === p.path || seen.has(p.path))
|
|
119685
|
+
continue;
|
|
119686
|
+
if (childInline.has(p.name)) {
|
|
119687
|
+
log(`[mcp-session] plugin ${p.source} not handed over: the child loads ${p.name} from its own --plugin-dir`);
|
|
119688
|
+
continue;
|
|
119689
|
+
}
|
|
119690
|
+
if (!manifestNames(p.path, p.name)) {
|
|
119691
|
+
log(`[mcp-session] plugin ${p.source} not handed over: its copy has no .claude-plugin/plugin.json naming it ${p.name}`);
|
|
119692
|
+
continue;
|
|
119693
|
+
}
|
|
119694
|
+
seen.add(p.path);
|
|
119695
|
+
plugins.push({ id: p.source, version: p.version, path: p.path });
|
|
119696
|
+
}
|
|
119697
|
+
return plugins;
|
|
119698
|
+
}
|
|
119699
|
+
function withoutLayerDisabled(plugins, layer) {
|
|
119700
|
+
const enabled = isPlainObject8(layer?.enabledPlugins) ? layer.enabledPlugins : {};
|
|
119701
|
+
return plugins.filter((p) => {
|
|
119702
|
+
if (!Object.hasOwn(enabled, p.id) || enabled[p.id] === true)
|
|
119703
|
+
return true;
|
|
119704
|
+
log(`[mcp-session] plugin ${p.id} not handed over: the child's settings turn it off`);
|
|
119705
|
+
return false;
|
|
119706
|
+
});
|
|
119707
|
+
}
|
|
119708
|
+
function probeLineEvent(line, afterInit) {
|
|
119709
|
+
let event;
|
|
119710
|
+
try {
|
|
119711
|
+
event = JSON.parse(line);
|
|
119712
|
+
} catch {
|
|
119713
|
+
return null;
|
|
119714
|
+
}
|
|
119715
|
+
if (!isPlainObject8(event))
|
|
119716
|
+
return null;
|
|
119717
|
+
if (event.type === "assistant") {
|
|
119718
|
+
if (!afterInit)
|
|
119719
|
+
return { kind: "fail", cause: "assistant_before_init" };
|
|
119720
|
+
const model = isPlainObject8(event.message) ? event.message.model : undefined;
|
|
119721
|
+
return model === "<synthetic>" ? null : { kind: "fail", cause: "turns" };
|
|
119722
|
+
}
|
|
119723
|
+
if (event.type === "result") {
|
|
119724
|
+
const success = event.subtype === "success" && event.is_error === false;
|
|
119725
|
+
return { kind: "result", success, turns: event.num_turns };
|
|
119726
|
+
}
|
|
119727
|
+
if (event.type !== "system" || event.subtype !== "init" || afterInit)
|
|
119728
|
+
return null;
|
|
119729
|
+
const plugins = initPluginsOf(event);
|
|
119730
|
+
return plugins ? { kind: "init", plugins } : { kind: "fail", cause: "plugins_malformed" };
|
|
119731
|
+
}
|
|
119732
|
+
function groupAlive(pgid) {
|
|
119733
|
+
try {
|
|
119734
|
+
process.kill(-pgid, 0);
|
|
119735
|
+
return true;
|
|
119736
|
+
} catch (err) {
|
|
119737
|
+
return err.code === "EPERM";
|
|
119738
|
+
}
|
|
119739
|
+
}
|
|
119740
|
+
function killProbe(child) {
|
|
119741
|
+
try {
|
|
119742
|
+
if (child.pid !== undefined)
|
|
119743
|
+
process.kill(-child.pid, "SIGKILL");
|
|
119744
|
+
} catch {
|
|
119745
|
+
try {
|
|
119746
|
+
child.kill("SIGKILL");
|
|
119747
|
+
} catch {}
|
|
119748
|
+
}
|
|
119749
|
+
}
|
|
119750
|
+
async function lookupBinary(findBinary, env, stopMs, hardMs, signal) {
|
|
119751
|
+
const stop = new AbortController;
|
|
119752
|
+
const timer = setTimeout(() => stop.abort(), Math.max(0, stopMs));
|
|
119753
|
+
const onAbort = () => stop.abort();
|
|
119754
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
119755
|
+
let hardTimer;
|
|
119756
|
+
const outlived = new Promise((settle) => {
|
|
119757
|
+
hardTimer = setTimeout(() => settle("outlived"), Math.max(0, hardMs));
|
|
119758
|
+
});
|
|
119759
|
+
let binary;
|
|
119760
|
+
try {
|
|
119761
|
+
const found = Promise.resolve().then(() => findBinary(env, stop.signal)).catch(() => null);
|
|
119762
|
+
binary = await Promise.race([found, outlived]);
|
|
119763
|
+
} finally {
|
|
119764
|
+
clearTimeout(timer);
|
|
119765
|
+
clearTimeout(hardTimer);
|
|
119766
|
+
signal?.removeEventListener("abort", onAbort);
|
|
119767
|
+
}
|
|
119768
|
+
if (binary === "outlived") {
|
|
119769
|
+
stop.abort();
|
|
119770
|
+
log("[mcp-session] the plugin probe's binary lookup outlived the probe's deadline after it was stopped; the probe answers without it");
|
|
119771
|
+
}
|
|
119772
|
+
if (signal?.aborted)
|
|
119773
|
+
return "aborted";
|
|
119774
|
+
if (stop.signal.aborted)
|
|
119775
|
+
return "timeout";
|
|
119776
|
+
return binary === "outlived" ? "timeout" : binary;
|
|
119777
|
+
}
|
|
119778
|
+
function pluginProbeRunner(findBinary, serverDir = () => process.cwd()) {
|
|
119779
|
+
return async (request) => {
|
|
119780
|
+
const { signal } = request;
|
|
119781
|
+
const deadline = Date.now() + request.timeoutMs;
|
|
119782
|
+
const killAt = deadline - Math.min(PROBE_REAP_MS, Math.floor(request.timeoutMs / 4));
|
|
119783
|
+
if (signal?.aborted)
|
|
119784
|
+
return { ok: false, cause: "aborted" };
|
|
119785
|
+
const base = serverDir();
|
|
119786
|
+
const named = request.env.CLAUDE_PATH;
|
|
119787
|
+
const claudePath = named ? startablePath(base, named) : undefined;
|
|
119788
|
+
if (claudePath === null)
|
|
119789
|
+
return { ok: false, cause: "no_claude_binary" };
|
|
119790
|
+
const env = claudePath ? { ...request.env, CLAUDE_PATH: claudePath } : request.env;
|
|
119791
|
+
const binary = await lookupBinary(findBinary, env, killAt - Date.now(), deadline - Date.now(), signal);
|
|
119792
|
+
if (binary === "timeout" || binary === "aborted")
|
|
119793
|
+
return { ok: false, cause: binary };
|
|
119794
|
+
const path = binary ? startablePath(base, binary) : null;
|
|
119795
|
+
if (path === null)
|
|
119796
|
+
return { ok: false, cause: "no_claude_binary" };
|
|
119797
|
+
return runProbe(path, request, deadline, killAt);
|
|
119798
|
+
};
|
|
119799
|
+
}
|
|
119800
|
+
function startablePath(base, named) {
|
|
119801
|
+
return isAbsolute5(named) ? named : claudePathIn(base, named);
|
|
119802
|
+
}
|
|
119803
|
+
function runProbe(binary, request, deadline, killAt) {
|
|
119804
|
+
const { signal } = request;
|
|
119805
|
+
return new Promise((settle) => {
|
|
119806
|
+
let child;
|
|
119807
|
+
try {
|
|
119808
|
+
child = spawn4(binary, request.args, {
|
|
119809
|
+
cwd: request.cwd,
|
|
119810
|
+
env: request.env,
|
|
119811
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
119812
|
+
detached: true
|
|
119813
|
+
});
|
|
119814
|
+
} catch {
|
|
119815
|
+
settle({ ok: false, cause: "spawn_failed" });
|
|
119816
|
+
return;
|
|
119817
|
+
}
|
|
119818
|
+
const pgid = child.pid;
|
|
119819
|
+
let plugins = null;
|
|
119820
|
+
let turns = null;
|
|
119821
|
+
let failure = null;
|
|
119822
|
+
let exitCode = null;
|
|
119823
|
+
let exited = false;
|
|
119824
|
+
let stdoutDone = false;
|
|
119825
|
+
let pending = "";
|
|
119826
|
+
let bytes = 0;
|
|
119827
|
+
let settled = false;
|
|
119828
|
+
let poll;
|
|
119829
|
+
const verdict = () => {
|
|
119830
|
+
if (failure)
|
|
119831
|
+
return { ok: false, cause: failure };
|
|
119832
|
+
if (!plugins)
|
|
119833
|
+
return { ok: false, cause: "exited_before_init" };
|
|
119834
|
+
if (exitCode !== 0)
|
|
119835
|
+
return { ok: false, cause: "nonzero_exit" };
|
|
119836
|
+
if (!turns)
|
|
119837
|
+
return { ok: false, cause: "no_result" };
|
|
119838
|
+
if (turns.value !== 0)
|
|
119839
|
+
return { ok: false, cause: "turns" };
|
|
119840
|
+
return { ok: true, plugins };
|
|
119841
|
+
};
|
|
119842
|
+
const finish = () => {
|
|
119843
|
+
if (settled)
|
|
119844
|
+
return;
|
|
119845
|
+
settled = true;
|
|
119846
|
+
clearTimeout(killTimer);
|
|
119847
|
+
clearTimeout(deadlineTimer);
|
|
119848
|
+
clearInterval(poll);
|
|
119849
|
+
signal?.removeEventListener("abort", onAbort);
|
|
119850
|
+
child.stdout?.destroy();
|
|
119851
|
+
settle(verdict());
|
|
119852
|
+
};
|
|
119853
|
+
const settleWhenGone = () => {
|
|
119854
|
+
if (settled || !exited || !stdoutDone)
|
|
119855
|
+
return;
|
|
119856
|
+
if (pgid === undefined || !groupAlive(pgid))
|
|
119857
|
+
return finish();
|
|
119858
|
+
if (!poll) {
|
|
119859
|
+
poll = setInterval(() => {
|
|
119860
|
+
if (pgid === undefined || !groupAlive(pgid))
|
|
119861
|
+
finish();
|
|
119862
|
+
}, GROUP_POLL_MS);
|
|
119863
|
+
}
|
|
119864
|
+
};
|
|
119865
|
+
const fail = (cause) => {
|
|
119866
|
+
failure ??= cause;
|
|
119867
|
+
killProbe(child);
|
|
119868
|
+
stdoutDone = true;
|
|
119869
|
+
settleWhenGone();
|
|
119870
|
+
};
|
|
119871
|
+
const readLine = (line) => {
|
|
119872
|
+
const event = probeLineEvent(line, plugins !== null);
|
|
119873
|
+
if (!event)
|
|
119874
|
+
return;
|
|
119875
|
+
if (event.kind === "fail")
|
|
119876
|
+
return fail(event.cause);
|
|
119877
|
+
if (event.kind === "init") {
|
|
119878
|
+
plugins = event.plugins;
|
|
119879
|
+
return;
|
|
119880
|
+
}
|
|
119881
|
+
if (plugins === null || turns !== null || !event.success)
|
|
119882
|
+
return fail("bad_result");
|
|
119883
|
+
turns = { value: event.turns };
|
|
119884
|
+
};
|
|
119885
|
+
const onAbort = () => fail("aborted");
|
|
119886
|
+
const killTimer = setTimeout(() => fail("timeout"), Math.max(0, killAt - Date.now()));
|
|
119887
|
+
const deadlineTimer = setTimeout(() => {
|
|
119888
|
+
failure ??= "timeout";
|
|
119889
|
+
finish();
|
|
119890
|
+
}, Math.max(0, deadline - Date.now()));
|
|
119891
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
119892
|
+
child.stdout?.setEncoding("utf8");
|
|
119893
|
+
child.stdout?.on("data", (chunk) => {
|
|
119894
|
+
if (failure)
|
|
119895
|
+
return;
|
|
119896
|
+
bytes += Buffer.byteLength(chunk);
|
|
119897
|
+
if (bytes > PROBE_OUTPUT_MAX_BYTES)
|
|
119898
|
+
return fail("output_too_large");
|
|
119899
|
+
pending += chunk;
|
|
119900
|
+
for (let nl = pending.indexOf(`
|
|
119901
|
+
`);nl >= 0 && !failure; nl = pending.indexOf(`
|
|
119902
|
+
`)) {
|
|
119903
|
+
readLine(pending.slice(0, nl));
|
|
119904
|
+
pending = pending.slice(nl + 1);
|
|
119905
|
+
}
|
|
119906
|
+
});
|
|
119907
|
+
child.stdout?.on("close", () => {
|
|
119908
|
+
if (!failure && pending)
|
|
119909
|
+
readLine(pending);
|
|
119910
|
+
pending = "";
|
|
119911
|
+
stdoutDone = true;
|
|
119912
|
+
settleWhenGone();
|
|
119913
|
+
});
|
|
119914
|
+
child.on("error", () => {
|
|
119915
|
+
if (child.pid === undefined) {
|
|
119916
|
+
failure ??= "spawn_failed";
|
|
119917
|
+
exited = true;
|
|
119918
|
+
stdoutDone = true;
|
|
119919
|
+
finish();
|
|
119920
|
+
}
|
|
119921
|
+
});
|
|
119922
|
+
child.on("exit", (code) => {
|
|
119923
|
+
exitCode = code;
|
|
119924
|
+
exited = true;
|
|
119925
|
+
killProbe(child);
|
|
119926
|
+
settleWhenGone();
|
|
119927
|
+
});
|
|
119928
|
+
});
|
|
119929
|
+
}
|
|
119930
|
+
function policyPlatformOf(platform, env, readProcVersion) {
|
|
119931
|
+
if (platform === "win32")
|
|
119932
|
+
return "windows";
|
|
119933
|
+
if (platform !== "linux")
|
|
119934
|
+
return "other";
|
|
119935
|
+
if (env.WSL_DISTRO_NAME || env.WSL_INTEROP)
|
|
119936
|
+
return "wsl";
|
|
119937
|
+
try {
|
|
119938
|
+
const version = readProcVersion().toLowerCase();
|
|
119939
|
+
return version.includes("microsoft") || version.includes("wsl") ? "wsl" : "other";
|
|
119940
|
+
} catch {
|
|
119941
|
+
return "other";
|
|
119942
|
+
}
|
|
119943
|
+
}
|
|
119944
|
+
function hostPolicyPlatform(env) {
|
|
119945
|
+
return policyPlatformOf(process.platform, env, () => readFileSync48("/proc/version", "utf-8"));
|
|
119946
|
+
}
|
|
119947
|
+
function isClaudeProgram(program) {
|
|
119948
|
+
const name = basename9(program);
|
|
119949
|
+
return name === "claude" || name === "claude.exe" || /[/\\]claude[/\\]versions[/\\][^/\\]+$/.test(program);
|
|
119950
|
+
}
|
|
119951
|
+
function callerLaunchFlags(argv) {
|
|
119952
|
+
const program = argv[0];
|
|
119953
|
+
if (program === undefined)
|
|
119954
|
+
return null;
|
|
119955
|
+
let flags;
|
|
119956
|
+
if (isClaudeProgram(program)) {
|
|
119957
|
+
flags = argv.slice(1);
|
|
119958
|
+
} else if (/^(node|nodejs|bun)(\.exe)?$/.test(basename9(program))) {
|
|
119959
|
+
const script = argv[1];
|
|
119960
|
+
if (!script || !/[/\\]@anthropic-ai[/\\]claude-code[/\\]cli\.m?js$/.test(script))
|
|
119961
|
+
return null;
|
|
119962
|
+
flags = argv.slice(2);
|
|
119963
|
+
} else {
|
|
119964
|
+
return null;
|
|
119965
|
+
}
|
|
119966
|
+
if (FLAGLESS_SUBCOMMANDS.includes(flags[0] ?? ""))
|
|
119967
|
+
return null;
|
|
119968
|
+
if (flags.some((t) => t.startsWith("--bg-")))
|
|
119969
|
+
return null;
|
|
119970
|
+
return flags;
|
|
119971
|
+
}
|
|
119972
|
+
function claudeEnvTrue(value) {
|
|
119973
|
+
if (!value)
|
|
119974
|
+
return false;
|
|
119975
|
+
return ["1", "true", "yes", "on"].includes(value.toLowerCase().trim());
|
|
119976
|
+
}
|
|
119977
|
+
function callerModeRefusal(flags, effective) {
|
|
119978
|
+
const beforeEnd = (flag) => passesBeforeEnd(flags, flag);
|
|
119979
|
+
const mode = (on, name) => on ? {
|
|
119980
|
+
outcome: "caller_mode_unmodelled",
|
|
119981
|
+
line: `the caller runs in ${name}, which keeps its plugin list but runs none of those plugins' commands or skills, so a copy handed over would give the child what the caller does not run`
|
|
119982
|
+
} : undefined;
|
|
119983
|
+
if (effective.everOn(PROBE_COWORK_SWITCH) || beforeEnd("--cowork")) {
|
|
119984
|
+
return coworkRefusal("the caller's");
|
|
119985
|
+
}
|
|
119986
|
+
if (effective.movesConfigDir) {
|
|
119987
|
+
return {
|
|
119988
|
+
outcome: "caller_mode_unmodelled",
|
|
119989
|
+
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"
|
|
119990
|
+
};
|
|
119991
|
+
}
|
|
119992
|
+
if (effective.movesRestricted) {
|
|
119993
|
+
return {
|
|
119994
|
+
outcome: "caller_mode_unmodelled",
|
|
119995
|
+
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"
|
|
119996
|
+
};
|
|
119997
|
+
}
|
|
119998
|
+
return mode(effective.mayBeOn("CLAUDE_CODE_SAFE_MODE") || beforeEnd("--safe-mode"), "safe mode") ?? mode(effective.mayBeOn("CLAUDE_CODE_SIMPLE") || beforeEnd("--bare"), "bare mode");
|
|
119999
|
+
}
|
|
120000
|
+
function envStringsOf(layer) {
|
|
120001
|
+
if (layer.env === undefined)
|
|
120002
|
+
return {};
|
|
120003
|
+
if (!isPlainObject8(layer.env))
|
|
120004
|
+
return;
|
|
120005
|
+
const env = {};
|
|
120006
|
+
for (const [key, value] of Object.entries(layer.env)) {
|
|
120007
|
+
if (typeof value === "string")
|
|
120008
|
+
env[key] = value;
|
|
120009
|
+
else if (typeof value === "number" || typeof value === "boolean")
|
|
120010
|
+
env[key] = String(value);
|
|
120011
|
+
}
|
|
120012
|
+
return env;
|
|
120013
|
+
}
|
|
120014
|
+
function envOfSettingsFile(path) {
|
|
120015
|
+
const text = readRegularFile(path);
|
|
120016
|
+
if (text === null || text === "unreadable")
|
|
120017
|
+
return text;
|
|
120018
|
+
try {
|
|
120019
|
+
const parsed = JSON.parse(text);
|
|
120020
|
+
if (!isPlainObject8(parsed))
|
|
120021
|
+
return "unreadable";
|
|
120022
|
+
return envStringsOf(parsed) ?? "unreadable";
|
|
120023
|
+
} catch {
|
|
120024
|
+
return "unreadable";
|
|
120025
|
+
}
|
|
120026
|
+
}
|
|
120027
|
+
function projectAndLocalFiles(cwd, flags, sources) {
|
|
120028
|
+
const root = lastFlagValue(flags, "--project-config-root");
|
|
120029
|
+
const dirs = [cwd, ...root && root !== "missing" ? [resolve9(cwd, root)] : []];
|
|
120030
|
+
const tiers = dirs.map((dir) => launchSettingsFilesByTier(dir, sources));
|
|
120031
|
+
return [...tiers.flatMap((t) => t.project), ...tiers.flatMap((t) => t.local)];
|
|
120032
|
+
}
|
|
120033
|
+
function callerEffectiveEnv(launch, home) {
|
|
120034
|
+
const { flags, cwd, hostEnv } = launch;
|
|
120035
|
+
const restricted = passesBeforeEnd(flags, "--restricted") || claudeEnvTrue(hostEnv.CLAUDE_CODE_RESTRICTED);
|
|
120036
|
+
const sources = restricted ? new Set : enabledSettingSources(flags);
|
|
120037
|
+
const unreadable = (what) => ({
|
|
120038
|
+
outcome: "caller_settings_unreadable",
|
|
120039
|
+
line: `${what} cannot be read or parsed, so claudish cannot tell which launch mode its env block sets for the caller`
|
|
120040
|
+
});
|
|
120041
|
+
const layers = [];
|
|
120042
|
+
if (sources === null || sources.has("user")) {
|
|
120043
|
+
const file = userSettingsFile(hostEnv.CLAUDE_CONFIG_DIR, home, cwd);
|
|
120044
|
+
const env = envOfSettingsFile(file);
|
|
120045
|
+
if (env === "unreadable")
|
|
120046
|
+
return unreadable(`the caller's user settings ${file}`);
|
|
120047
|
+
if (env)
|
|
120048
|
+
layers.push({ env, mayBeDropped: false });
|
|
120049
|
+
}
|
|
120050
|
+
for (const file of projectAndLocalFiles(cwd, flags, sources)) {
|
|
120051
|
+
const env = envOfSettingsFile(file);
|
|
120052
|
+
if (env === "unreadable")
|
|
120053
|
+
return unreadable(`the caller's settings ${file}`);
|
|
120054
|
+
if (env)
|
|
120055
|
+
layers.push({ env, mayBeDropped: true });
|
|
120056
|
+
}
|
|
120057
|
+
if (launch.layer) {
|
|
120058
|
+
const env = envStringsOf(launch.layer);
|
|
120059
|
+
if (env === undefined)
|
|
120060
|
+
return unreadable("the caller's own --settings");
|
|
120061
|
+
layers.push({ env, mayBeDropped: false });
|
|
120062
|
+
}
|
|
120063
|
+
const passed = {};
|
|
120064
|
+
for (const key of CALLER_LAUNCH_ENV_KEYS) {
|
|
120065
|
+
let value = hostEnv[key];
|
|
120066
|
+
if (!LAUNCH_ONLY_KEYS.includes(key)) {
|
|
120067
|
+
for (const layer of layers)
|
|
120068
|
+
if (!layer.mayBeDropped && key in layer.env)
|
|
120069
|
+
value = layer.env[key];
|
|
120070
|
+
}
|
|
120071
|
+
if (value !== undefined)
|
|
120072
|
+
passed[key] = value;
|
|
120073
|
+
}
|
|
120074
|
+
const valuesOf = (env, key) => Object.entries(env).filter(([k]) => k.toUpperCase() === key);
|
|
120075
|
+
const mayBeOn = (key) => {
|
|
120076
|
+
let possible = new Set([hostEnv[key]]);
|
|
120077
|
+
for (const layer of layers) {
|
|
120078
|
+
const set = valuesOf(layer.env, key).map(([, v]) => v);
|
|
120079
|
+
if (set.length === 0)
|
|
120080
|
+
continue;
|
|
120081
|
+
possible = layer.mayBeDropped ? new Set([...possible, ...set]) : new Set(set);
|
|
120082
|
+
}
|
|
120083
|
+
return [...possible].some(claudeEnvTrue);
|
|
120084
|
+
};
|
|
120085
|
+
const everOn = (key) => claudeEnvTrue(hostEnv[key]) || layers.some((layer) => valuesOf(layer.env, key).some(([, v]) => claudeEnvTrue(v)));
|
|
120086
|
+
const movesConfigDir = layers.some((layer) => valuesOf(layer.env, "CLAUDE_CONFIG_DIR").some(([, v]) => v !== hostEnv.CLAUDE_CONFIG_DIR));
|
|
120087
|
+
const movesRestricted = layers.some((layer) => valuesOf(layer.env, "CLAUDE_CODE_RESTRICTED").some(([, v]) => claudeEnvTrue(v) !== restricted));
|
|
120088
|
+
return { passed, mayBeOn, everOn, movesConfigDir, movesRestricted };
|
|
120089
|
+
}
|
|
120090
|
+
function childCoworkRefusal(input, childReal) {
|
|
120091
|
+
const on = (env) => Object.entries(env ?? {}).some(([k, v]) => k.toUpperCase() === PROBE_COWORK_SWITCH && typeof v === "string" && claudeEnvTrue(v));
|
|
120092
|
+
const sources = enabledSettingSources(input.childFlags);
|
|
120093
|
+
const files = [
|
|
120094
|
+
...sources === null || sources.has("user") ? [userSettingsFile(input.env.CLAUDE_CONFIG_DIR, input.env.HOME ?? "", childReal)] : [],
|
|
120095
|
+
...projectAndLocalFiles(childReal, input.childFlags, sources)
|
|
120096
|
+
];
|
|
120097
|
+
const layerEnv = isPlainObject8(input.layer?.env) ? envStringsOf(input.layer) : undefined;
|
|
120098
|
+
const found = passes(input.childFlags, "--cowork") || on(input.env) || on(layerEnv) || files.some((file) => {
|
|
120099
|
+
const env = envOfSettingsFile(file);
|
|
120100
|
+
return env !== null && env !== "unreadable" && on(env);
|
|
120101
|
+
});
|
|
120102
|
+
return found ? coworkRefusal("the child's") : undefined;
|
|
120103
|
+
}
|
|
120104
|
+
function coworkRefusal(whose) {
|
|
120105
|
+
return {
|
|
120106
|
+
outcome: "caller_mode_unmodelled",
|
|
120107
|
+
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`
|
|
120108
|
+
};
|
|
120109
|
+
}
|
|
120110
|
+
function launchFlagRefusal(flags, whose) {
|
|
120111
|
+
if (passes(flags, "--managed-settings")) {
|
|
120112
|
+
return {
|
|
120113
|
+
outcome: "managed_policy_present",
|
|
120114
|
+
line: `${whose} launch passes --managed-settings, a managed policy source`
|
|
120115
|
+
};
|
|
120116
|
+
}
|
|
120117
|
+
if (passes(flags, "--plugin-url")) {
|
|
120118
|
+
return {
|
|
120119
|
+
outcome: "plugin_url",
|
|
120120
|
+
line: `${whose} launch passes --plugin-url, which the plugin probe never downloads, so it cannot tell which marketplace copies that plugin shadows`
|
|
120121
|
+
};
|
|
120122
|
+
}
|
|
120123
|
+
const initialize = INITIALIZE_FLAGS.find((flag) => passes(flags, flag));
|
|
120124
|
+
if (initialize !== undefined) {
|
|
120125
|
+
return {
|
|
120126
|
+
outcome: "await_initialize",
|
|
120127
|
+
line: `${whose} launch passes ${initialize}, under which Claude Code reads settings, plugins or MCP servers from its stdin, which the plugin probe never sees`
|
|
120128
|
+
};
|
|
120129
|
+
}
|
|
120130
|
+
return;
|
|
120131
|
+
}
|
|
120132
|
+
function managedPolicyRefusal(input, probes) {
|
|
120133
|
+
if (input.policyPlatform !== "other") {
|
|
120134
|
+
const where = input.policyPlatform === "windows" ? "Windows" : "WSL";
|
|
120135
|
+
return {
|
|
120136
|
+
outcome: "managed_policy_present",
|
|
120137
|
+
line: `claudish does not read the managed policy on ${where}, so no plugin probe runs there`
|
|
120138
|
+
};
|
|
120139
|
+
}
|
|
120140
|
+
let present;
|
|
120141
|
+
for (const { cwd, env } of probes) {
|
|
120142
|
+
present ??= managedPolicySourcePresent(input.managed, env, cwd);
|
|
120143
|
+
}
|
|
120144
|
+
if (present === undefined)
|
|
120145
|
+
return;
|
|
120146
|
+
return {
|
|
120147
|
+
outcome: "managed_policy_present",
|
|
120148
|
+
line: `the managed policy source ${present} exists, and no plugin probe runs beside a managed policy`
|
|
120149
|
+
};
|
|
120150
|
+
}
|
|
120151
|
+
function workDirRefusal(childReal, childFlags) {
|
|
120152
|
+
const found = projectCommandSetting(childReal, childFlags, COMMAND_SETTINGS);
|
|
120153
|
+
if (found === undefined)
|
|
120154
|
+
return;
|
|
120155
|
+
return {
|
|
120156
|
+
outcome: "work_dir_command_setting",
|
|
120157
|
+
line: found.key === undefined ? `${found.path} cannot be parsed, so claudish cannot tell whether it defines a command the work_dir probe would run` : `${found.path} sets ${found.key}, a command the work_dir probe would run without the trust dialog`
|
|
120158
|
+
};
|
|
120159
|
+
}
|
|
120160
|
+
function projectCommandSetting(cwd, flags, keys) {
|
|
120161
|
+
const root = lastFlagValue(flags, "--project-config-root");
|
|
120162
|
+
const dirs = [cwd, ...root && root !== "missing" ? [resolve9(cwd, root)] : []];
|
|
120163
|
+
let found;
|
|
120164
|
+
for (const dir of dirs)
|
|
120165
|
+
found ??= commandSettingIn(launchSettingsFiles(dir), keys);
|
|
120166
|
+
return found;
|
|
120167
|
+
}
|
|
120168
|
+
function callerProjectRefusal(callerReal, flags) {
|
|
120169
|
+
const found = projectCommandSetting(callerReal, flags, USER_STARTUP_HELPERS);
|
|
120170
|
+
if (found === undefined)
|
|
120171
|
+
return;
|
|
120172
|
+
return {
|
|
120173
|
+
outcome: "caller_command_setting",
|
|
120174
|
+
line: found.key === undefined ? `${found.path} cannot be parsed, so claudish cannot tell whether the caller probe would run a helper from it` : `${found.path} sets ${found.key}, a helper the caller probe's boot can run before any model turn`
|
|
120175
|
+
};
|
|
120176
|
+
}
|
|
120177
|
+
function userSettingsRefusal(probes) {
|
|
120178
|
+
const files = probes.flatMap(({ cwd, flags, env }) => {
|
|
120179
|
+
const sources = enabledSettingSources(flags);
|
|
120180
|
+
if (sources !== null && !sources.has("user"))
|
|
120181
|
+
return [];
|
|
120182
|
+
return [userSettingsFile(env.CLAUDE_CONFIG_DIR, env.HOME ?? "", cwd)];
|
|
120183
|
+
});
|
|
120184
|
+
const found = commandSettingIn([...new Set(files)], USER_STARTUP_HELPERS);
|
|
120185
|
+
if (found === undefined)
|
|
120186
|
+
return;
|
|
120187
|
+
return {
|
|
120188
|
+
outcome: "user_command_setting",
|
|
120189
|
+
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`
|
|
120190
|
+
};
|
|
120191
|
+
}
|
|
120192
|
+
function lastFlagValue(flags, flag) {
|
|
120193
|
+
let value;
|
|
120194
|
+
for (let i = 0;i < flags.length; i++) {
|
|
120195
|
+
const token = flags[i];
|
|
120196
|
+
if (token === flag) {
|
|
120197
|
+
value = flags[i + 1] ?? "missing";
|
|
120198
|
+
i++;
|
|
120199
|
+
} else if (token.startsWith(`${flag}=`)) {
|
|
120200
|
+
value = token.slice(flag.length + 1);
|
|
120201
|
+
}
|
|
120202
|
+
}
|
|
120203
|
+
return value;
|
|
120204
|
+
}
|
|
120205
|
+
function readCallerLaunch(input) {
|
|
120206
|
+
const { setupReal } = input;
|
|
120207
|
+
let launch;
|
|
120208
|
+
try {
|
|
120209
|
+
launch = input.readHostLaunch(input.hostPid);
|
|
120210
|
+
} catch {
|
|
120211
|
+
launch = null;
|
|
120212
|
+
}
|
|
120213
|
+
const flags = launch ? callerLaunchFlags(launch.argv) : null;
|
|
120214
|
+
if (!launch || !flags) {
|
|
120215
|
+
return {
|
|
120216
|
+
outcome: "caller_argv_unreadable",
|
|
120217
|
+
line: `the launch of the caller's process ${input.hostPid} cannot be read as a Claude Code argv, so the caller probe cannot be started with the caller's flags`
|
|
120218
|
+
};
|
|
120219
|
+
}
|
|
120220
|
+
const refusal = launchFlagRefusal(flags, "the caller's");
|
|
120221
|
+
if (refusal)
|
|
120222
|
+
return refusal;
|
|
120223
|
+
const hostEnv = launch.env;
|
|
120224
|
+
if (!hostEnv) {
|
|
120225
|
+
return {
|
|
120226
|
+
outcome: "caller_env_unreadable",
|
|
120227
|
+
line: `the launch environment of the caller's process ${input.hostPid} cannot be read, so the caller probe cannot be given the caller's CLAUDE_CONFIG_DIR, plugin variables and launch mode switches`
|
|
120228
|
+
};
|
|
120229
|
+
}
|
|
120230
|
+
const settings = lastFlagValue(flags, "--settings");
|
|
120231
|
+
let layer = null;
|
|
120232
|
+
if (settings !== undefined) {
|
|
120233
|
+
try {
|
|
120234
|
+
if (settings === "missing")
|
|
120235
|
+
throw new Error("no value");
|
|
120236
|
+
const inline = settings.trim().startsWith("{");
|
|
120237
|
+
layer = readSettingsValue(inline ? settings : resolve9(launch.cwd, settings));
|
|
120238
|
+
} catch {
|
|
120239
|
+
return {
|
|
120240
|
+
outcome: "caller_settings_unreadable",
|
|
120241
|
+
line: "the caller's own --settings cannot be read or parsed, so claudish cannot tell which plugins it turns off"
|
|
120242
|
+
};
|
|
120243
|
+
}
|
|
120244
|
+
}
|
|
120245
|
+
const effective = callerEffectiveEnv({ flags, cwd: launch.cwd, layer, hostEnv }, input.env.HOME ?? "");
|
|
120246
|
+
if ("outcome" in effective)
|
|
120247
|
+
return effective;
|
|
120248
|
+
const unmodelled = callerModeRefusal(flags, effective);
|
|
120249
|
+
if (unmodelled)
|
|
120250
|
+
return unmodelled;
|
|
120251
|
+
if (setupReal !== undefined && !sharesMainCheckout(setupReal, launch.cwd)) {
|
|
120252
|
+
return {
|
|
120253
|
+
outcome: "setup_from_not_caller",
|
|
120254
|
+
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"
|
|
120255
|
+
};
|
|
120256
|
+
}
|
|
120257
|
+
return { flags, cwd: launch.cwd, layer, hostEnv: effective.passed };
|
|
120258
|
+
}
|
|
120259
|
+
function callerEnvOf(env, hostEnv) {
|
|
120260
|
+
const out = { ...env };
|
|
120261
|
+
for (const key of CALLER_LAUNCH_ENV_KEYS) {
|
|
120262
|
+
const value = hostEnv[key];
|
|
120263
|
+
if (value === undefined)
|
|
120264
|
+
delete out[key];
|
|
120265
|
+
else
|
|
120266
|
+
out[key] = value;
|
|
120267
|
+
}
|
|
120268
|
+
return out;
|
|
120269
|
+
}
|
|
120270
|
+
function refused(refusal) {
|
|
120271
|
+
log(`[mcp-session] no plugin handed over: ${refusal.line}`);
|
|
120272
|
+
return { plugins: [], outcome: refusal.outcome };
|
|
120273
|
+
}
|
|
120274
|
+
function pidAlive2(pid) {
|
|
120275
|
+
try {
|
|
120276
|
+
process.kill(pid, 0);
|
|
120277
|
+
return true;
|
|
120278
|
+
} catch (err) {
|
|
120279
|
+
return err.code === "EPERM";
|
|
120280
|
+
}
|
|
120281
|
+
}
|
|
120282
|
+
function sweepStaleProbeDirs(sweep = {}) {
|
|
120283
|
+
const root = sweep.root ?? tmpdir3();
|
|
120284
|
+
const now = sweep.now ?? Date.now();
|
|
120285
|
+
const alive = sweep.alive ?? pidAlive2;
|
|
120286
|
+
let names;
|
|
120287
|
+
try {
|
|
120288
|
+
names = readdirSync13(root);
|
|
120289
|
+
} catch {
|
|
120290
|
+
return;
|
|
120291
|
+
}
|
|
120292
|
+
const uid = process.getuid?.();
|
|
120293
|
+
for (const name of names) {
|
|
120294
|
+
const match = PROBE_DIR_NAME.exec(name);
|
|
120295
|
+
if (!match)
|
|
120296
|
+
continue;
|
|
120297
|
+
const path = join60(root, name);
|
|
120298
|
+
try {
|
|
120299
|
+
const stat = lstatSync10(path);
|
|
120300
|
+
if (!stat.isDirectory() || uid !== undefined && stat.uid !== uid)
|
|
120301
|
+
continue;
|
|
120302
|
+
const pid = match[1] === undefined ? undefined : Number(match[1]);
|
|
120303
|
+
const ownerGone = pid !== undefined && pid > 0 && !alive(pid);
|
|
120304
|
+
if (!ownerGone && now - stat.mtimeMs <= STALE_PROBE_DIR_MS)
|
|
120305
|
+
continue;
|
|
120306
|
+
rmSync15(path, { recursive: true, force: true });
|
|
120307
|
+
} catch {}
|
|
120308
|
+
}
|
|
120309
|
+
}
|
|
120310
|
+
async function inheritedPluginsFor(input) {
|
|
120311
|
+
const { setupReal } = input;
|
|
120312
|
+
if (!setupReal)
|
|
120313
|
+
return null;
|
|
120314
|
+
const childReal = realOrResolved(input.childCwd);
|
|
120315
|
+
if (sharesMainCheckout(setupReal, childReal))
|
|
120316
|
+
return null;
|
|
120317
|
+
const early = launchFlagRefusal(input.childFlags, "the child's") ?? managedPolicyRefusal(input, [
|
|
120318
|
+
{ cwd: setupReal, env: input.env },
|
|
120319
|
+
{ cwd: childReal, env: input.env }
|
|
120320
|
+
]) ?? childCoworkRefusal(input, childReal);
|
|
120321
|
+
const caller = early ?? readCallerLaunch(input);
|
|
120322
|
+
if ("outcome" in caller)
|
|
120323
|
+
return refused(caller);
|
|
120324
|
+
const callerReal = realOrResolved(caller.cwd);
|
|
120325
|
+
const callerEnv = callerEnvOf(input.env, caller.hostEnv);
|
|
120326
|
+
const refusal = managedPolicyRefusal(input, [{ cwd: callerReal, env: callerEnv }]) ?? workDirRefusal(childReal, input.childFlags) ?? callerProjectRefusal(callerReal, caller.flags) ?? userSettingsRefusal([
|
|
120327
|
+
{ cwd: callerReal, flags: caller.flags, env: callerEnv },
|
|
120328
|
+
{ cwd: childReal, flags: input.childFlags, env: input.env }
|
|
120329
|
+
]);
|
|
120330
|
+
if (refusal)
|
|
120331
|
+
return refused(refusal);
|
|
120332
|
+
const launch = caller;
|
|
120333
|
+
const runner = input.runner ?? spawnPluginProbe;
|
|
120334
|
+
const root = input.probeTmpRoot ?? tmpdir3();
|
|
120335
|
+
sweepStaleProbeDirs({ root, ...input.pidAlive ? { alive: input.pidAlive } : {} });
|
|
120336
|
+
let dir;
|
|
120337
|
+
let results;
|
|
120338
|
+
try {
|
|
120339
|
+
dir = mkdtempSync4(join60(root, `${PROBE_DIR_PREFIX}${process.pid}-`));
|
|
120340
|
+
const callerSettings = join60(dir, "caller-settings.json");
|
|
120341
|
+
const childSettings = join60(dir, "child-settings.json");
|
|
120342
|
+
writePrivateJson(callerSettings, pluginProbeSettings(launch.layer));
|
|
120343
|
+
writePrivateJson(childSettings, pluginProbeSettings(input.layer));
|
|
120344
|
+
const request = (cwd, args, env) => ({
|
|
120345
|
+
cwd,
|
|
120346
|
+
args,
|
|
120347
|
+
env: pluginProbeEnv(env),
|
|
120348
|
+
timeoutMs: input.timeoutMs ?? PLUGIN_PROBE_TIMEOUT_MS,
|
|
120349
|
+
...input.signal ? { signal: input.signal } : {}
|
|
120350
|
+
});
|
|
120351
|
+
const settled = await Promise.allSettled([
|
|
120352
|
+
runner(request(callerReal, pluginProbeArgs(callerSettings, launch.flags, callerReal), callerEnv)),
|
|
120353
|
+
runner(request(childReal, pluginProbeArgs(childSettings, input.childFlags, childReal), input.env))
|
|
120354
|
+
]);
|
|
120355
|
+
results = settled.map((s) => s.status === "fulfilled" ? s.value : { ok: false, cause: "spawn_failed" });
|
|
120356
|
+
} catch {
|
|
120357
|
+
results = [{ ok: false, cause: "spawn_failed" }];
|
|
120358
|
+
} finally {
|
|
120359
|
+
if (dir)
|
|
120360
|
+
rmSync15(dir, { recursive: true, force: true });
|
|
120361
|
+
}
|
|
120362
|
+
const [callerResult, childResult] = results;
|
|
120363
|
+
const failed = results.find((r) => !r.ok);
|
|
120364
|
+
if (failed || !callerResult?.ok || !childResult?.ok) {
|
|
120365
|
+
const cause = failed?.cause ?? "spawn_failed";
|
|
120366
|
+
log(`[mcp-session] no plugin handed over: the plugin probe failed (${cause})`);
|
|
120367
|
+
return { plugins: [], outcome: cause };
|
|
120368
|
+
}
|
|
120369
|
+
const plugins = pluginsToHandOver(callerResult.plugins, childResult.plugins);
|
|
120370
|
+
return { plugins: withoutLayerDisabled(plugins, input.layer), outcome: "ok" };
|
|
120371
|
+
}
|
|
120372
|
+
var PLUGIN_PROBE_TIMEOUT_MS = 1e4, PLUGIN_PROBE_BASE_URL = "http://127.0.0.1:9", PROBE_OUTPUT_MAX_BYTES, PROBE_REAP_MS = 2000, GROUP_POLL_MS = 20, QUIET_FLAGS, PLUGIN_PATH_FLAGS, INITIALIZE_FLAGS, PLUGIN_VALUE_FLAGS, PLUGIN_BOOLEAN_FLAGS, PROBE_PROVIDER_SWITCHES, PROVIDER_BASE_URLS, PROBE_STARTUP_HELPER_SWITCHES, PROBE_FIRST_PARTY_SWITCHES, PROBE_HOST_MANAGED_MARKER = "CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST", PROBE_HOST_HANDOFF_VARS, PROBE_SETTINGS_EMPTY_VARS, PROBE_PARENT_VARS, PROBE_SETTINGS_ENV, COMMAND_SETTINGS, USER_STARTUP_HELPERS, spawnPluginProbe, FLAGLESS_SUBCOMMANDS, LAUNCH_ONLY_KEYS, PROBE_DIR_PREFIX = "claudish-plugin-probe-", PROBE_DIR_NAME, STALE_PROBE_DIR_MS;
|
|
120373
|
+
var init_plugin_probe = __esm(() => {
|
|
120374
|
+
init_claude_runner();
|
|
120375
|
+
init_logger();
|
|
120376
|
+
init_pane_launch();
|
|
120377
|
+
init_inherited_settings();
|
|
120378
|
+
init_probe_launch_vars();
|
|
120379
|
+
PROBE_OUTPUT_MAX_BYTES = 32 * 1024 * 1024;
|
|
120380
|
+
QUIET_FLAGS = [
|
|
120381
|
+
"--output-format",
|
|
120382
|
+
"stream-json",
|
|
120383
|
+
"--verbose",
|
|
120384
|
+
"--settings",
|
|
120385
|
+
"<settings file>",
|
|
120386
|
+
"--strict-mcp-config",
|
|
120387
|
+
"--no-session-persistence"
|
|
120388
|
+
];
|
|
120389
|
+
PLUGIN_PATH_FLAGS = ["--plugin-dir", "--plugin-dir-no-mcp", "--project-config-root"];
|
|
120390
|
+
INITIALIZE_FLAGS = [
|
|
120391
|
+
"--await-initialize",
|
|
120392
|
+
"--initialize-fields",
|
|
120393
|
+
"--managed-settings-in-initialize"
|
|
120394
|
+
];
|
|
120395
|
+
PLUGIN_VALUE_FLAGS = ["--setting-sources"];
|
|
120396
|
+
PLUGIN_BOOLEAN_FLAGS = ["--safe-mode", "--bare", "--restricted"];
|
|
120397
|
+
PROBE_PROVIDER_SWITCHES = [
|
|
120398
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
120399
|
+
"CLAUDE_CODE_USE_VERTEX",
|
|
120400
|
+
"CLAUDE_CODE_USE_FOUNDRY",
|
|
120401
|
+
"CLAUDE_CODE_USE_ANTHROPIC_AWS",
|
|
120402
|
+
"CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD",
|
|
120403
|
+
"CLAUDE_CODE_USE_MANTLE",
|
|
120404
|
+
"CLAUDE_CODE_USE_GATEWAY"
|
|
120405
|
+
];
|
|
120406
|
+
PROVIDER_BASE_URLS = [
|
|
120407
|
+
"ANTHROPIC_BEDROCK_BASE_URL",
|
|
120408
|
+
"ANTHROPIC_VERTEX_BASE_URL",
|
|
120409
|
+
"ANTHROPIC_FOUNDRY_BASE_URL",
|
|
120410
|
+
"ANTHROPIC_AWS_BASE_URL",
|
|
120411
|
+
"ANTHROPIC_GOOGLE_CLOUD_BASE_URL",
|
|
120412
|
+
"ANTHROPIC_BEDROCK_MANTLE_BASE_URL"
|
|
120413
|
+
];
|
|
120414
|
+
PROBE_STARTUP_HELPER_SWITCHES = [
|
|
120415
|
+
"CLAUDE_CODE_ENABLE_PROXY_AUTH_HELPER",
|
|
120416
|
+
"CLAUDE_CODE_ENABLE_TELEMETRY"
|
|
120417
|
+
];
|
|
120418
|
+
PROBE_FIRST_PARTY_SWITCHES = [
|
|
120419
|
+
"_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL",
|
|
120420
|
+
"CLAUDE_CODE_CLIENT_DATA_URL"
|
|
120421
|
+
];
|
|
120422
|
+
PROBE_HOST_HANDOFF_VARS = [
|
|
120423
|
+
"CLAUDE_CODE_HOST_CREDS_FILE",
|
|
120424
|
+
"CLAUDE_CODE_HOST_AUTH_ENV_VAR",
|
|
120425
|
+
"CLAUDE_CODE_HOST_AUTH_ASK_AT_START",
|
|
120426
|
+
"CLAUDE_CODE_HOST_AUTH_REFRESH_TIMEOUT_MS",
|
|
120427
|
+
"CLAUDE_CODE_SDK_HAS_HOST_AUTH_REFRESH",
|
|
120428
|
+
"CLAUDE_CODE_LAUNCHER_RUNS_API_KEY_HELPER",
|
|
120429
|
+
"CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR",
|
|
120430
|
+
"CLAUDE_CODE_API_KEY_FILE_DESCRIPTOR",
|
|
120431
|
+
"CLAUDE_CODE_GATEWAY_TOKEN_FILE_DESCRIPTOR",
|
|
120432
|
+
"CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR",
|
|
120433
|
+
"CLAUDE_BG_AUTH_SNAPSHOT_PATH",
|
|
120434
|
+
"CLAUDE_CODE_OAUTH_REFRESH_TOKEN",
|
|
120435
|
+
"CLAUDE_CODE_SESSION_ACCESS_TOKEN",
|
|
120436
|
+
"CLAUDE_SESSION_INGRESS_TOKEN_FILE"
|
|
120437
|
+
];
|
|
120438
|
+
PROBE_SETTINGS_EMPTY_VARS = [
|
|
120439
|
+
"ANTHROPIC_API_KEY",
|
|
120440
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
120441
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
120442
|
+
...PROBE_HOST_HANDOFF_VARS,
|
|
120443
|
+
...PROBE_PROVIDER_SWITCHES,
|
|
120444
|
+
...PROVIDER_BASE_URLS,
|
|
120445
|
+
...PROBE_STARTUP_HELPER_SWITCHES,
|
|
120446
|
+
...PROBE_FIRST_PARTY_SWITCHES,
|
|
120447
|
+
PROBE_HOST_MANAGED_MARKER
|
|
120448
|
+
];
|
|
120449
|
+
PROBE_PARENT_VARS = [
|
|
120450
|
+
"PATH",
|
|
120451
|
+
"HOME",
|
|
120452
|
+
"USER",
|
|
120453
|
+
"LOGNAME",
|
|
120454
|
+
"SHELL",
|
|
120455
|
+
"TMPDIR",
|
|
120456
|
+
"LANG",
|
|
120457
|
+
"TERM",
|
|
120458
|
+
"XDG_CONFIG_HOME",
|
|
120459
|
+
"XDG_DATA_HOME",
|
|
120460
|
+
"XDG_CACHE_HOME",
|
|
120461
|
+
"CLAUDE_CONFIG_DIR",
|
|
120462
|
+
"CLAUDE_PATH",
|
|
120463
|
+
...PROBE_PLUGIN_VARS,
|
|
120464
|
+
...PROBE_MODE_VARS
|
|
120465
|
+
];
|
|
120466
|
+
PROBE_SETTINGS_ENV = {
|
|
120467
|
+
ANTHROPIC_BASE_URL: PLUGIN_PROBE_BASE_URL,
|
|
120468
|
+
...Object.fromEntries(PROBE_SETTINGS_EMPTY_VARS.map((key) => [key, ""])),
|
|
120469
|
+
[PROBE_HOST_MANAGED_MARKER]: "1"
|
|
120470
|
+
};
|
|
120471
|
+
COMMAND_SETTINGS = [
|
|
120472
|
+
"apiKeyHelper",
|
|
120473
|
+
"awsAuthRefresh",
|
|
120474
|
+
"awsCredentialExport",
|
|
120475
|
+
"fileSuggestion",
|
|
120476
|
+
"gcpAuthRefresh",
|
|
120477
|
+
"otelHeadersHelper",
|
|
120478
|
+
"processWrapper",
|
|
120479
|
+
"policyHelpers",
|
|
120480
|
+
"proxyAuthHelper",
|
|
120481
|
+
"statusLine",
|
|
120482
|
+
"subagentStatusLine"
|
|
120483
|
+
];
|
|
120484
|
+
USER_STARTUP_HELPERS = [
|
|
120485
|
+
"apiKeyHelper",
|
|
120486
|
+
"awsAuthRefresh",
|
|
120487
|
+
"awsCredentialExport",
|
|
120488
|
+
"gcpAuthRefresh",
|
|
120489
|
+
"otelHeadersHelper",
|
|
120490
|
+
"policyHelpers",
|
|
120491
|
+
"proxyAuthHelper"
|
|
120492
|
+
];
|
|
120493
|
+
spawnPluginProbe = pluginProbeRunner(findClaudeBinary);
|
|
120494
|
+
FLAGLESS_SUBCOMMANDS = ["bg-spare", "bg-pty-host", "daemon"];
|
|
120495
|
+
LAUNCH_ONLY_KEYS = ["CLAUDE_CONFIG_DIR", "CLAUDE_CODE_RESTRICTED"];
|
|
120496
|
+
PROBE_DIR_NAME = /^claudish-plugin-probe-(?:(\d{1,10})-)?[A-Za-z0-9]{6}$/;
|
|
120497
|
+
STALE_PROBE_DIR_MS = 10 * 60000;
|
|
120498
|
+
});
|
|
120499
|
+
|
|
118698
120500
|
// src/mcp-session/scrollback-buffer.ts
|
|
118699
120501
|
class ScrollbackBuffer {
|
|
118700
120502
|
lines;
|
|
@@ -118756,25 +120558,50 @@ var init_scrollback_buffer = __esm(() => {
|
|
|
118756
120558
|
import { randomUUID as randomUUID9 } from "crypto";
|
|
118757
120559
|
import {
|
|
118758
120560
|
appendFileSync as appendFileSync7,
|
|
118759
|
-
closeSync as
|
|
120561
|
+
closeSync as closeSync18,
|
|
118760
120562
|
createWriteStream,
|
|
118761
120563
|
existsSync as existsSync42,
|
|
118762
120564
|
mkdirSync as mkdirSync27,
|
|
118763
|
-
openSync as
|
|
118764
|
-
readFileSync as
|
|
118765
|
-
readSync as
|
|
120565
|
+
openSync as openSync18,
|
|
120566
|
+
readFileSync as readFileSync49,
|
|
120567
|
+
readSync as readSync8,
|
|
118766
120568
|
renameSync as renameSync10,
|
|
118767
|
-
rmSync as
|
|
118768
|
-
statSync as
|
|
118769
|
-
writeFileSync as
|
|
120569
|
+
rmSync as rmSync16,
|
|
120570
|
+
statSync as statSync25,
|
|
120571
|
+
writeFileSync as writeFileSync23
|
|
118770
120572
|
} from "fs";
|
|
118771
|
-
import { join as
|
|
120573
|
+
import { join as join61, resolve as resolve10, sep as sep3 } from "path";
|
|
118772
120574
|
function normaliseTimeoutSeconds(raw) {
|
|
118773
120575
|
const n = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
|
|
118774
120576
|
if (typeof n !== "number" || !Number.isFinite(n))
|
|
118775
120577
|
return DEFAULT_TIMEOUT;
|
|
118776
120578
|
return Math.min(MAX_TIMEOUT, Math.max(1, Math.round(n)));
|
|
118777
120579
|
}
|
|
120580
|
+
function inheritedLayerFor(setupFrom, callerFlags) {
|
|
120581
|
+
if (!setupFrom)
|
|
120582
|
+
return { setupReal: undefined, layer: null, restFlags: [...callerFlags] };
|
|
120583
|
+
const setupReal = realOrResolved(setupFrom);
|
|
120584
|
+
const settingSources = enabledSettingSources(callerFlags);
|
|
120585
|
+
return { setupReal, ...buildInheritedSettingsLayer(setupReal, callerFlags, { settingSources }) };
|
|
120586
|
+
}
|
|
120587
|
+
function pluginRecordOf(handover) {
|
|
120588
|
+
if (!handover)
|
|
120589
|
+
return {};
|
|
120590
|
+
const { plugins, outcome } = handover;
|
|
120591
|
+
return {
|
|
120592
|
+
...plugins.length > 0 ? { inheritedPlugins: plugins.map(({ id, version }) => ({ id, version })) } : {},
|
|
120593
|
+
pluginProbe: outcome
|
|
120594
|
+
};
|
|
120595
|
+
}
|
|
120596
|
+
function pluginDirFlags(handover) {
|
|
120597
|
+
return (handover?.plugins ?? []).flatMap((p) => ["--plugin-dir", p.path]);
|
|
120598
|
+
}
|
|
120599
|
+
function writeInheritedFiles(sessionDir, layer, mcp) {
|
|
120600
|
+
if (layer)
|
|
120601
|
+
writePrivateJson(join61(sessionDir, INHERITED_SETTINGS), layer);
|
|
120602
|
+
if (mcp)
|
|
120603
|
+
writePrivateJson(join61(sessionDir, INHERITED_MCP), mcp);
|
|
120604
|
+
}
|
|
118778
120605
|
function sessionEventFor(snap) {
|
|
118779
120606
|
switch (snap.state) {
|
|
118780
120607
|
case "STARTING":
|
|
@@ -118865,7 +120692,7 @@ function toMetaRecord(info, cwd) {
|
|
|
118865
120692
|
}
|
|
118866
120693
|
function writeJsonAtomic(path, value) {
|
|
118867
120694
|
const tmp = `${path}.tmp`;
|
|
118868
|
-
|
|
120695
|
+
writeFileSync23(tmp, JSON.stringify(value, null, 2), "utf-8");
|
|
118869
120696
|
renameSync10(tmp, path);
|
|
118870
120697
|
}
|
|
118871
120698
|
function anomalyKey(a) {
|
|
@@ -118875,21 +120702,21 @@ function anomalyKey(a) {
|
|
|
118875
120702
|
function readTailText(path, maxBytes) {
|
|
118876
120703
|
let fd = null;
|
|
118877
120704
|
try {
|
|
118878
|
-
const size =
|
|
120705
|
+
const size = statSync25(path).size;
|
|
118879
120706
|
if (size === 0)
|
|
118880
120707
|
return { text: "", truncated: false };
|
|
118881
120708
|
const start = Math.max(0, size - maxBytes);
|
|
118882
120709
|
const length = size - start;
|
|
118883
120710
|
const buf = Buffer.alloc(length);
|
|
118884
|
-
fd =
|
|
118885
|
-
|
|
120711
|
+
fd = openSync18(path, "r");
|
|
120712
|
+
readSync8(fd, buf, 0, length, start);
|
|
118886
120713
|
return { text: buf.toString("utf-8"), truncated: start > 0 };
|
|
118887
120714
|
} catch {
|
|
118888
120715
|
return null;
|
|
118889
120716
|
} finally {
|
|
118890
120717
|
if (fd !== null) {
|
|
118891
120718
|
try {
|
|
118892
|
-
|
|
120719
|
+
closeSync18(fd);
|
|
118893
120720
|
} catch {}
|
|
118894
120721
|
}
|
|
118895
120722
|
}
|
|
@@ -118906,7 +120733,7 @@ function readTailLines2(path, maxBytes) {
|
|
|
118906
120733
|
}
|
|
118907
120734
|
function fileSize2(path) {
|
|
118908
120735
|
try {
|
|
118909
|
-
return
|
|
120736
|
+
return statSync25(path).size;
|
|
118910
120737
|
} catch {
|
|
118911
120738
|
return 0;
|
|
118912
120739
|
}
|
|
@@ -118915,7 +120742,7 @@ function readJsonObject(path, maxBytes) {
|
|
|
118915
120742
|
try {
|
|
118916
120743
|
if (fileSize2(path) > maxBytes)
|
|
118917
120744
|
return null;
|
|
118918
|
-
const parsed = JSON.parse(
|
|
120745
|
+
const parsed = JSON.parse(readFileSync49(path, "utf-8"));
|
|
118919
120746
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
118920
120747
|
return null;
|
|
118921
120748
|
return parsed;
|
|
@@ -118941,7 +120768,7 @@ function dropLeadingFragment(tail) {
|
|
|
118941
120768
|
return firstBreak === -1 ? tail.text : tail.text.slice(firstBreak + 1);
|
|
118942
120769
|
}
|
|
118943
120770
|
function diskAccounting(sessionDir) {
|
|
118944
|
-
const stats = readTokenStatsAt(
|
|
120771
|
+
const stats = readTokenStatsAt(join61(sessionDir, "tokens.json"));
|
|
118945
120772
|
return {
|
|
118946
120773
|
tokensIn: stats?.billed_input_tokens ?? null,
|
|
118947
120774
|
tokensOut: stats?.output_tokens ?? null,
|
|
@@ -119001,6 +120828,8 @@ class SessionManager {
|
|
|
119001
120828
|
paneTimings;
|
|
119002
120829
|
starting = 0;
|
|
119003
120830
|
pendingStarts = new Set;
|
|
120831
|
+
startAbort = new AbortController;
|
|
120832
|
+
shuttingDown = false;
|
|
119004
120833
|
_hostPid;
|
|
119005
120834
|
_launcherPid;
|
|
119006
120835
|
teamRunStarts = new Map;
|
|
@@ -119011,6 +120840,11 @@ class SessionManager {
|
|
|
119011
120840
|
magmuxBinary;
|
|
119012
120841
|
feed;
|
|
119013
120842
|
claims;
|
|
120843
|
+
managedPaths;
|
|
120844
|
+
pluginProbe;
|
|
120845
|
+
pluginProbeTimeoutMs;
|
|
120846
|
+
readHostLaunch;
|
|
120847
|
+
pluginPolicyPlatform;
|
|
119014
120848
|
constructor(options) {
|
|
119015
120849
|
const host = options?.hostPid !== undefined ? { hostPid: options.hostPid } : hostPidFrom(process.env, process.ppid);
|
|
119016
120850
|
this._hostPid = host.hostPid;
|
|
@@ -119027,6 +120861,11 @@ class SessionManager {
|
|
|
119027
120861
|
this.magmuxBinary = options?.magmuxBinary;
|
|
119028
120862
|
this.feed = options?.feed;
|
|
119029
120863
|
this.claims = options?.claims;
|
|
120864
|
+
this.managedPaths = options?.managedPaths ?? realManagedPaths();
|
|
120865
|
+
this.pluginProbe = options?.pluginProbe;
|
|
120866
|
+
this.pluginProbeTimeoutMs = options?.pluginProbeTimeoutMs;
|
|
120867
|
+
this.readHostLaunch = options?.readHostLaunch ?? readHostLaunch;
|
|
120868
|
+
this.pluginPolicyPlatform = options?.pluginPolicyPlatform;
|
|
119030
120869
|
}
|
|
119031
120870
|
hookEngine() {
|
|
119032
120871
|
if (!this.hookEnginePromise)
|
|
@@ -119045,7 +120884,7 @@ class SessionManager {
|
|
|
119045
120884
|
let dir = "";
|
|
119046
120885
|
for (let attempt = 0;; attempt++) {
|
|
119047
120886
|
id = `team-${randomUUID9().replace(/-/g, "").slice(0, 8)}`;
|
|
119048
|
-
dir =
|
|
120887
|
+
dir = join61(this.sessionsDir, id);
|
|
119049
120888
|
try {
|
|
119050
120889
|
mkdirSync27(dir);
|
|
119051
120890
|
break;
|
|
@@ -119060,7 +120899,7 @@ class SessionManager {
|
|
|
119060
120899
|
sessionId: id,
|
|
119061
120900
|
parentClaudeSessionId: opts.parentClaudeSessionId,
|
|
119062
120901
|
startedAt,
|
|
119063
|
-
teamPath:
|
|
120902
|
+
teamPath: resolve10(opts.teamPath),
|
|
119064
120903
|
slots: opts.slots
|
|
119065
120904
|
});
|
|
119066
120905
|
this.teamRunStarts.set(id, startedAt);
|
|
@@ -119077,9 +120916,9 @@ class SessionManager {
|
|
|
119077
120916
|
if (dir === null)
|
|
119078
120917
|
throw new Error("not a record id");
|
|
119079
120918
|
const completedAt = new Date().toISOString();
|
|
119080
|
-
const startedAt = this.teamRunStarts.get(record) ?? metaString(readJsonObject(
|
|
120919
|
+
const startedAt = this.teamRunStarts.get(record) ?? metaString(readJsonObject(join61(dir, "spawn.json"), META_READ_LIMIT)?.startedAt) ?? completedAt;
|
|
119081
120920
|
const elapsedMs = Date.parse(completedAt) - Date.parse(startedAt);
|
|
119082
|
-
writeJsonAtomic(
|
|
120921
|
+
writeJsonAtomic(join61(dir, "meta.json"), {
|
|
119083
120922
|
kind: "team",
|
|
119084
120923
|
status: outcome.status,
|
|
119085
120924
|
startedAt,
|
|
@@ -119111,9 +120950,14 @@ class SessionManager {
|
|
|
119111
120950
|
startedAt,
|
|
119112
120951
|
...rest
|
|
119113
120952
|
};
|
|
119114
|
-
writeJsonAtomic(
|
|
120953
|
+
writeJsonAtomic(join61(dir, "spawn.json"), body);
|
|
120954
|
+
}
|
|
120955
|
+
refuseWhileShuttingDown() {
|
|
120956
|
+
if (this.shuttingDown)
|
|
120957
|
+
throw new Error("MCP server is shutting down: no session started");
|
|
119115
120958
|
}
|
|
119116
120959
|
async createSession(opts) {
|
|
120960
|
+
this.refuseWhileShuttingDown();
|
|
119117
120961
|
if (this.activeSessions + this.starting >= this.maxSessions) {
|
|
119118
120962
|
throw new Error(`Max sessions (${this.maxSessions}) reached`);
|
|
119119
120963
|
}
|
|
@@ -119124,7 +120968,7 @@ class SessionManager {
|
|
|
119124
120968
|
const flagCheck = checkChildFlags(callerFlags);
|
|
119125
120969
|
if (!flagCheck.ok)
|
|
119126
120970
|
throw new Error(`invalid_args: ${flagCheck.message}`);
|
|
119127
|
-
const inherited =
|
|
120971
|
+
const { setupReal, ...inherited } = inheritedLayerFor(opts.setupFrom, callerFlags);
|
|
119128
120972
|
let flags = callerFlags;
|
|
119129
120973
|
const readAvailable = !flagsRemoveRead(flags);
|
|
119130
120974
|
if (opts.prompt) {
|
|
@@ -119133,6 +120977,8 @@ class SessionManager {
|
|
|
119133
120977
|
throw new Error(`invalid_args: ${refusal}`);
|
|
119134
120978
|
}
|
|
119135
120979
|
const parentEnv = opts.parentEnv ?? this.parentEnv;
|
|
120980
|
+
const childCwd = opts.cwd ?? process.cwd();
|
|
120981
|
+
const inheritedMcp = inheritedMcpFor(setupReal, childCwd, inherited.layer, callerFlags, parentEnv, this.managedPaths);
|
|
119136
120982
|
this.starting++;
|
|
119137
120983
|
let counted = true;
|
|
119138
120984
|
const uncount = () => {
|
|
@@ -119140,46 +120986,64 @@ class SessionManager {
|
|
|
119140
120986
|
this.starting--;
|
|
119141
120987
|
counted = false;
|
|
119142
120988
|
};
|
|
120989
|
+
const { signal } = this.startAbort;
|
|
120990
|
+
let releaseStart = () => {};
|
|
120991
|
+
const tracked = new Promise((done) => {
|
|
120992
|
+
releaseStart = done;
|
|
120993
|
+
});
|
|
120994
|
+
this.pendingStarts.add(tracked);
|
|
119143
120995
|
try {
|
|
119144
120996
|
await assertMagmuxAvailable(this.magmuxBinary);
|
|
120997
|
+
this.refuseWhileShuttingDown();
|
|
120998
|
+
const plugins = await inheritedPluginsFor({
|
|
120999
|
+
setupReal,
|
|
121000
|
+
childCwd,
|
|
121001
|
+
layer: inherited.layer,
|
|
121002
|
+
childFlags: callerFlags,
|
|
121003
|
+
env: parentEnv,
|
|
121004
|
+
managed: this.managedPaths,
|
|
121005
|
+
hostPid: this._hostPid,
|
|
121006
|
+
readHostLaunch: this.readHostLaunch,
|
|
121007
|
+
policyPlatform: this.pluginPolicyPlatform ?? hostPolicyPlatform(parentEnv),
|
|
121008
|
+
runner: this.pluginProbe,
|
|
121009
|
+
timeoutMs: this.pluginProbeTimeoutMs,
|
|
121010
|
+
signal
|
|
121011
|
+
});
|
|
121012
|
+
this.refuseWhileShuttingDown();
|
|
119145
121013
|
reservePanes(1, sockRootFor(parentEnv));
|
|
119146
121014
|
let entry;
|
|
119147
121015
|
try {
|
|
119148
|
-
entry = this.recordSession(opts, inherited.layer);
|
|
121016
|
+
entry = this.recordSession(opts, inherited.layer, inheritedMcp, plugins);
|
|
119149
121017
|
} catch (err) {
|
|
119150
121018
|
releasePaneReservations(1);
|
|
119151
121019
|
throw err;
|
|
119152
121020
|
}
|
|
119153
121021
|
if (inherited.layer) {
|
|
119154
|
-
flags = [...inherited.restFlags, "--settings",
|
|
121022
|
+
flags = [...inherited.restFlags, "--settings", join61(entry.sessionDir, INHERITED_SETTINGS)];
|
|
119155
121023
|
}
|
|
121024
|
+
flags = [...pluginDirFlags(plugins), ...flags];
|
|
121025
|
+
if (inheritedMcp)
|
|
121026
|
+
flags = ["--mcp-config", join61(entry.sessionDir, INHERITED_MCP), ...flags];
|
|
119156
121027
|
this.sessions.set(entry.info.sessionId, entry);
|
|
119157
121028
|
uncount();
|
|
119158
|
-
|
|
119159
|
-
const tracked = started.catch(() => {
|
|
119160
|
-
return;
|
|
119161
|
-
});
|
|
119162
|
-
this.pendingStarts.add(tracked);
|
|
119163
|
-
try {
|
|
119164
|
-
await started;
|
|
119165
|
-
} finally {
|
|
119166
|
-
this.pendingStarts.delete(tracked);
|
|
119167
|
-
}
|
|
121029
|
+
await this.startPane(entry, opts, { flags, readAvailable, parentEnv });
|
|
119168
121030
|
return entry.info.sessionId;
|
|
119169
121031
|
} finally {
|
|
121032
|
+
this.pendingStarts.delete(tracked);
|
|
121033
|
+
releaseStart();
|
|
119170
121034
|
uncount();
|
|
119171
121035
|
}
|
|
119172
121036
|
}
|
|
119173
|
-
recordSession(opts, inheritedLayer) {
|
|
121037
|
+
recordSession(opts, inheritedLayer, inheritedMcp, plugins) {
|
|
119174
121038
|
const sessionId = opts.sessionId ?? randomUUID9().slice(0, 8);
|
|
119175
121039
|
const claudeSessionId = randomUUID9();
|
|
119176
121040
|
const timeout = normaliseTimeoutSeconds(opts.timeoutSeconds);
|
|
119177
121041
|
const agentRequested = requestedAgentOf(opts.claudishFlags ?? []);
|
|
119178
121042
|
const startedAt = new Date().toISOString();
|
|
119179
|
-
const sessionDir = opts.sessionDir ??
|
|
121043
|
+
const sessionDir = opts.sessionDir ?? join61(this.sessionsDir, sessionId);
|
|
119180
121044
|
mkdirSync27(sessionDir, { recursive: true });
|
|
119181
121045
|
if (opts.prompt)
|
|
119182
|
-
|
|
121046
|
+
writeFileSync23(join61(sessionDir, "prompt.md"), opts.prompt, "utf-8");
|
|
119183
121047
|
this.writeSpawnRecord(sessionDir, {
|
|
119184
121048
|
kind: "session",
|
|
119185
121049
|
sessionId,
|
|
@@ -119189,17 +121053,16 @@ class SessionManager {
|
|
|
119189
121053
|
timeoutSeconds: timeout,
|
|
119190
121054
|
claudeSessionId,
|
|
119191
121055
|
...opts.setupFrom ? { setupFrom: opts.setupFrom } : {},
|
|
121056
|
+
inheritedMcpServers: inheritedMcp ? Object.keys(inheritedMcp.mcpServers) : undefined,
|
|
121057
|
+
...pluginRecordOf(plugins),
|
|
119192
121058
|
...agentRequested ? { agentRequested } : {},
|
|
119193
121059
|
taskType: opts.taskType
|
|
119194
121060
|
});
|
|
119195
|
-
|
|
119196
|
-
writeFileSync22(join60(sessionDir, INHERITED_SETTINGS), `${JSON.stringify(inheritedLayer, null, 2)}
|
|
119197
|
-
`, { encoding: "utf-8", mode: 384 });
|
|
119198
|
-
}
|
|
121061
|
+
writeInheritedFiles(sessionDir, inheritedLayer, inheritedMcp);
|
|
119199
121062
|
const cwd = opts.cwd ?? process.cwd();
|
|
119200
121063
|
const parentEnv = opts.parentEnv ?? this.parentEnv;
|
|
119201
121064
|
const spawnModel = opts.spawnModel ?? null;
|
|
119202
|
-
const tokenFile = opts.tokenFile ??
|
|
121065
|
+
const tokenFile = opts.tokenFile ?? join61(sessionDir, "tokens.json");
|
|
119203
121066
|
return {
|
|
119204
121067
|
info: {
|
|
119205
121068
|
sessionId,
|
|
@@ -119238,18 +121101,18 @@ class SessionManager {
|
|
|
119238
121101
|
},
|
|
119239
121102
|
session: null,
|
|
119240
121103
|
scrollback: new ScrollbackBuffer(this.scrollbackCapacity),
|
|
119241
|
-
outputLogStream: createWriteStream(
|
|
121104
|
+
outputLogStream: createWriteStream(join61(sessionDir, "output.log")),
|
|
119242
121105
|
sessionDir,
|
|
119243
121106
|
cwd,
|
|
119244
121107
|
tokenFile,
|
|
119245
|
-
eventLogPath:
|
|
121108
|
+
eventLogPath: join61(sessionDir, "events.jsonl"),
|
|
119246
121109
|
eventLogBytes: 0,
|
|
119247
|
-
upstreamErrorLogPath:
|
|
121110
|
+
upstreamErrorLogPath: join61(sessionDir, "upstream-errors.jsonl"),
|
|
119248
121111
|
eventRing: [],
|
|
119249
121112
|
proseBytes: 0,
|
|
119250
121113
|
answeredTurns: new Map,
|
|
119251
121114
|
inboxPath: null,
|
|
119252
|
-
waitLogPath:
|
|
121115
|
+
waitLogPath: join61(sessionDir, "waits.jsonl"),
|
|
119253
121116
|
waitLogBytes: 0,
|
|
119254
121117
|
waitSince: null,
|
|
119255
121118
|
ended: false,
|
|
@@ -119357,7 +121220,7 @@ class SessionManager {
|
|
|
119357
121220
|
if (!entry.inboxPath)
|
|
119358
121221
|
return;
|
|
119359
121222
|
try {
|
|
119360
|
-
|
|
121223
|
+
rmSync16(entry.inboxPath, { force: true });
|
|
119361
121224
|
} catch {}
|
|
119362
121225
|
}
|
|
119363
121226
|
failNeverSpawned(entry, err) {
|
|
@@ -119461,7 +121324,7 @@ class SessionManager {
|
|
|
119461
121324
|
try {
|
|
119462
121325
|
const text = screenLines.join(`
|
|
119463
121326
|
`).replace(/\s+$/, "");
|
|
119464
|
-
|
|
121327
|
+
writeFileSync23(join61(entry.sessionDir, "screen.txt"), `${redactSecrets(text)}
|
|
119465
121328
|
`, "utf-8");
|
|
119466
121329
|
} catch {}
|
|
119467
121330
|
}
|
|
@@ -119475,7 +121338,7 @@ class SessionManager {
|
|
|
119475
121338
|
entry.waitSince = null;
|
|
119476
121339
|
}
|
|
119477
121340
|
try {
|
|
119478
|
-
writeJsonAtomic(
|
|
121341
|
+
writeJsonAtomic(join61(entry.sessionDir, "meta.json"), toMetaRecord(entry.info, entry.cwd));
|
|
119479
121342
|
} catch (err) {
|
|
119480
121343
|
process.stderr.write(`[claudish] session ${entry.info.sessionId}: could not write meta.json: ` + `${err instanceof Error ? err.message : String(err)}
|
|
119481
121344
|
`);
|
|
@@ -119740,13 +121603,13 @@ class SessionManager {
|
|
|
119740
121603
|
if (sessionDir === null)
|
|
119741
121604
|
return null;
|
|
119742
121605
|
try {
|
|
119743
|
-
if (!
|
|
121606
|
+
if (!statSync25(sessionDir).isDirectory())
|
|
119744
121607
|
return null;
|
|
119745
121608
|
} catch {
|
|
119746
121609
|
return null;
|
|
119747
121610
|
}
|
|
119748
|
-
const spawnPath =
|
|
119749
|
-
const metaPath =
|
|
121611
|
+
const spawnPath = join61(sessionDir, "spawn.json");
|
|
121612
|
+
const metaPath = join61(sessionDir, "meta.json");
|
|
119750
121613
|
const spawnRecord = readJsonObject(spawnPath, META_READ_LIMIT);
|
|
119751
121614
|
if (spawnRecord?.kind === "team")
|
|
119752
121615
|
return null;
|
|
@@ -119837,9 +121700,11 @@ class SessionManager {
|
|
|
119837
121700
|
if (!record)
|
|
119838
121701
|
return null;
|
|
119839
121702
|
const info = record.info;
|
|
119840
|
-
return sessionRowOf(info, upstreamRecordsFor(info,
|
|
121703
|
+
return sessionRowOf(info, upstreamRecordsFor(info, join61(record.sessionDir, "upstream-errors.jsonl")));
|
|
119841
121704
|
}
|
|
119842
121705
|
async shutdownAll() {
|
|
121706
|
+
this.shuttingDown = true;
|
|
121707
|
+
this.startAbort.abort();
|
|
119843
121708
|
await Promise.all([...this.pendingStarts]);
|
|
119844
121709
|
const pending = [];
|
|
119845
121710
|
for (const entry of this.sessions.values()) {
|
|
@@ -119866,11 +121731,11 @@ class SessionManager {
|
|
|
119866
121731
|
diskSessionDir(sessionId) {
|
|
119867
121732
|
if (!SESSION_ID_RE.test(sessionId))
|
|
119868
121733
|
return null;
|
|
119869
|
-
const root =
|
|
119870
|
-
const dir =
|
|
119871
|
-
if (dir !==
|
|
121734
|
+
const root = resolve10(this.sessionsDir);
|
|
121735
|
+
const dir = resolve10(root, sessionId);
|
|
121736
|
+
if (dir !== join61(root, sessionId))
|
|
119872
121737
|
return null;
|
|
119873
|
-
if (!dir.startsWith(root +
|
|
121738
|
+
if (!dir.startsWith(root + sep3))
|
|
119874
121739
|
return null;
|
|
119875
121740
|
return dir;
|
|
119876
121741
|
}
|
|
@@ -119880,17 +121745,17 @@ class SessionManager {
|
|
|
119880
121745
|
return null;
|
|
119881
121746
|
let dirMtimeMs;
|
|
119882
121747
|
try {
|
|
119883
|
-
const stat =
|
|
121748
|
+
const stat = statSync25(sessionDir);
|
|
119884
121749
|
if (!stat.isDirectory())
|
|
119885
121750
|
return null;
|
|
119886
121751
|
dirMtimeMs = stat.mtimeMs;
|
|
119887
121752
|
} catch {
|
|
119888
121753
|
return null;
|
|
119889
121754
|
}
|
|
119890
|
-
const spawnRecord = readJsonObject(
|
|
121755
|
+
const spawnRecord = readJsonObject(join61(sessionDir, "spawn.json"), META_READ_LIMIT);
|
|
119891
121756
|
if (spawnRecord?.kind === "team")
|
|
119892
121757
|
return null;
|
|
119893
|
-
const meta = readJsonObject(
|
|
121758
|
+
const meta = readJsonObject(join61(sessionDir, "meta.json"), META_READ_LIMIT);
|
|
119894
121759
|
if (meta?.kind === "team")
|
|
119895
121760
|
return null;
|
|
119896
121761
|
const partial = meta === null;
|
|
@@ -119912,7 +121777,7 @@ class SessionManager {
|
|
|
119912
121777
|
return stored;
|
|
119913
121778
|
}
|
|
119914
121779
|
diskOutput(record, tailLines) {
|
|
119915
|
-
const tail = readTailText(
|
|
121780
|
+
const tail = readTailText(join61(record.sessionDir, "output.log"), OUTPUT_TAIL_BYTES);
|
|
119916
121781
|
const buffer = new ScrollbackBuffer(this.scrollbackCapacity);
|
|
119917
121782
|
if (tail?.text)
|
|
119918
121783
|
buffer.append(dropLeadingFragment(tail));
|
|
@@ -119932,12 +121797,12 @@ class SessionManager {
|
|
|
119932
121797
|
}
|
|
119933
121798
|
diskDiagnostics(record, limit) {
|
|
119934
121799
|
const { sessionDir, info } = record;
|
|
119935
|
-
const eventLogPath =
|
|
119936
|
-
const upstreamErrorLogPath =
|
|
119937
|
-
const outputLogPath =
|
|
121800
|
+
const eventLogPath = join61(sessionDir, "events.jsonl");
|
|
121801
|
+
const upstreamErrorLogPath = join61(sessionDir, "upstream-errors.jsonl");
|
|
121802
|
+
const outputLogPath = join61(sessionDir, "output.log");
|
|
119938
121803
|
const events = readTailLines2(eventLogPath, EVENT_TAIL_BYTES);
|
|
119939
121804
|
const outputTail = readTailText(outputLogPath, OUTPUT_TAIL_BYTES);
|
|
119940
|
-
const screen = readTailText(
|
|
121805
|
+
const screen = readTailText(join61(sessionDir, "screen.txt"), SCREEN_READ_BYTES);
|
|
119941
121806
|
return {
|
|
119942
121807
|
sessionId: info.sessionId,
|
|
119943
121808
|
state: info.state,
|
|
@@ -120189,8 +122054,9 @@ function diskInfo(d) {
|
|
|
120189
122054
|
function diskCaptureSource(v) {
|
|
120190
122055
|
return v === "transcript" || v === "screen" || v === "none" ? v : null;
|
|
120191
122056
|
}
|
|
120192
|
-
var DEFAULT_MAX_SESSIONS = 20, DEFAULT_SCROLLBACK = 2000, DEFAULT_TIMEOUT = 600, MAX_TIMEOUT = 3600, TERMINAL_RETENTION_MS, MAX_TERMINAL_SESSIONS = 50, EVENT_LOG_LIMIT, WAIT_LOG_LIMIT, EVENT_RING_SIZE = 200, EVENT_PREVIEW_CHARS = 800, DEFAULT_EVENT_LIMIT = 40, UPSTREAM_ERROR_TAIL_BYTES, SPAWN_RECORD_SCHEMA = 1, INHERITED_SETTINGS = "inherited-settings.json", NON_TOOL_ACTIVITY, META_STATUS, STATE_OF_10_4_STATUS, SESSION_ID_RE, META_READ_LIMIT, OUTPUT_TAIL_BYTES, EVENT_TAIL_BYTES, SCREEN_READ_BYTES, NO_TERMINAL_RECORD = "claudish_no_terminal_record", CLAUDISH_NOTE_PREFIX = "[claudish] ", metaString = (v) => typeof v === "string" && v.length > 0 ? v : null, optionalParent = (id) => id ? { parentClaudeSessionId: id } : {}, metaNumber = (v) => typeof v === "number" && Number.isFinite(v) ? v : null, metaReason = (v) => typeof v === "string" && FAILURE_REASONS.includes(v) ? v : null;
|
|
122057
|
+
var DEFAULT_MAX_SESSIONS = 20, DEFAULT_SCROLLBACK = 2000, DEFAULT_TIMEOUT = 600, MAX_TIMEOUT = 3600, TERMINAL_RETENTION_MS, MAX_TERMINAL_SESSIONS = 50, EVENT_LOG_LIMIT, WAIT_LOG_LIMIT, EVENT_RING_SIZE = 200, EVENT_PREVIEW_CHARS = 800, DEFAULT_EVENT_LIMIT = 40, UPSTREAM_ERROR_TAIL_BYTES, SPAWN_RECORD_SCHEMA = 1, INHERITED_SETTINGS = "inherited-settings.json", INHERITED_MCP = "inherited-mcp.json", NON_TOOL_ACTIVITY, META_STATUS, STATE_OF_10_4_STATUS, SESSION_ID_RE, META_READ_LIMIT, OUTPUT_TAIL_BYTES, EVENT_TAIL_BYTES, SCREEN_READ_BYTES, NO_TERMINAL_RECORD = "claudish_no_terminal_record", CLAUDISH_NOTE_PREFIX = "[claudish] ", metaString = (v) => typeof v === "string" && v.length > 0 ? v : null, optionalParent = (id) => id ? { parentClaudeSessionId: id } : {}, metaNumber = (v) => typeof v === "number" && Number.isFinite(v) ? v : null, metaReason = (v) => typeof v === "string" && FAILURE_REASONS.includes(v) ? v : null;
|
|
120193
122058
|
var init_session_manager = __esm(() => {
|
|
122059
|
+
init_claude_runner();
|
|
120194
122060
|
init_config();
|
|
120195
122061
|
init_upstream_error_capture();
|
|
120196
122062
|
init_hooks();
|
|
@@ -120208,8 +122074,10 @@ var init_session_manager = __esm(() => {
|
|
|
120208
122074
|
init_token_watch();
|
|
120209
122075
|
init_view_claims();
|
|
120210
122076
|
init_home_dir();
|
|
122077
|
+
init_host_launch();
|
|
120211
122078
|
init_inherited_settings();
|
|
120212
122079
|
init_parent_session();
|
|
122080
|
+
init_plugin_probe();
|
|
120213
122081
|
init_scrollback_buffer();
|
|
120214
122082
|
TERMINAL_RETENTION_MS = 30 * 60000;
|
|
120215
122083
|
EVENT_LOG_LIMIT = 4 * 1024 * 1024;
|
|
@@ -120242,8 +122110,8 @@ var init_session_manager = __esm(() => {
|
|
|
120242
122110
|
});
|
|
120243
122111
|
|
|
120244
122112
|
// src/view/history.ts
|
|
120245
|
-
import { closeSync as
|
|
120246
|
-
import { join as
|
|
122113
|
+
import { closeSync as closeSync19, openSync as openSync19, readSync as readSync9, readdirSync as readdirSync14, statSync as statSync26 } from "fs";
|
|
122114
|
+
import { join as join62 } from "path";
|
|
120247
122115
|
function finishedDetail(promptSummary) {
|
|
120248
122116
|
return {
|
|
120249
122117
|
prompt_summary: promptSummary,
|
|
@@ -120264,28 +122132,28 @@ function readJson(path) {
|
|
|
120264
122132
|
function readHead(path, bytes) {
|
|
120265
122133
|
let fd = null;
|
|
120266
122134
|
try {
|
|
120267
|
-
fd =
|
|
122135
|
+
fd = openSync19(path, "r");
|
|
120268
122136
|
const buf = Buffer.alloc(bytes);
|
|
120269
|
-
const n =
|
|
122137
|
+
const n = readSync9(fd, buf, 0, bytes, 0);
|
|
120270
122138
|
return buf.subarray(0, n).toString("utf8");
|
|
120271
122139
|
} catch {
|
|
120272
122140
|
return null;
|
|
120273
122141
|
} finally {
|
|
120274
122142
|
if (fd !== null)
|
|
120275
|
-
|
|
122143
|
+
closeSync19(fd);
|
|
120276
122144
|
}
|
|
120277
122145
|
}
|
|
120278
122146
|
function runDirs(sessionsDir) {
|
|
120279
122147
|
let names;
|
|
120280
122148
|
try {
|
|
120281
|
-
names =
|
|
122149
|
+
names = readdirSync14(sessionsDir);
|
|
120282
122150
|
} catch {
|
|
120283
122151
|
return [];
|
|
120284
122152
|
}
|
|
120285
122153
|
const dated = [];
|
|
120286
122154
|
for (const name of names) {
|
|
120287
122155
|
try {
|
|
120288
|
-
const st =
|
|
122156
|
+
const st = statSync26(join62(sessionsDir, name));
|
|
120289
122157
|
if (st.isDirectory())
|
|
120290
122158
|
dated.push({ name, mtimeMs: st.mtimeMs });
|
|
120291
122159
|
} catch {}
|
|
@@ -120322,7 +122190,7 @@ function teamItems(spawn) {
|
|
|
120322
122190
|
return { runId: run.run_id, items };
|
|
120323
122191
|
}
|
|
120324
122192
|
function runItems(sessions, dir, name, seenRuns) {
|
|
120325
|
-
const spawn = readJson(
|
|
122193
|
+
const spawn = readJson(join62(dir, "spawn.json"));
|
|
120326
122194
|
if (spawn?.kind === "team" || name.startsWith("team-")) {
|
|
120327
122195
|
const team = spawn ? teamItems(spawn) : null;
|
|
120328
122196
|
if (!team || seenRuns.has(team.runId) || team.items.length === 0)
|
|
@@ -120330,12 +122198,12 @@ function runItems(sessions, dir, name, seenRuns) {
|
|
|
120330
122198
|
seenRuns.add(team.runId);
|
|
120331
122199
|
return team.items;
|
|
120332
122200
|
}
|
|
120333
|
-
if (!spawn && readJson(
|
|
122201
|
+
if (!spawn && readJson(join62(dir, "meta.json")) === null)
|
|
120334
122202
|
return null;
|
|
120335
122203
|
const row = sessions.diskSessionRow(name);
|
|
120336
122204
|
if (!row)
|
|
120337
122205
|
return null;
|
|
120338
|
-
const prompt = readHead(
|
|
122206
|
+
const prompt = readHead(join62(dir, "prompt.md"), PROMPT_HEAD_BYTES);
|
|
120339
122207
|
return [sessionItem(row, prompt ? promptSummaryOf(prompt) : null)];
|
|
120340
122208
|
}
|
|
120341
122209
|
function readHistory(o = {}) {
|
|
@@ -120348,7 +122216,7 @@ function readHistory(o = {}) {
|
|
|
120348
122216
|
for (const name of runDirs(sessionsDir)) {
|
|
120349
122217
|
if (runs >= limit)
|
|
120350
122218
|
break;
|
|
120351
|
-
const items = runItems(sessions,
|
|
122219
|
+
const items = runItems(sessions, join62(sessionsDir, name), name, seenRuns);
|
|
120352
122220
|
if (!items)
|
|
120353
122221
|
continue;
|
|
120354
122222
|
out.push(...items);
|
|
@@ -120363,15 +122231,15 @@ function findRecordedItem(target, o = {}) {
|
|
|
120363
122231
|
const id = target.slice(2);
|
|
120364
122232
|
if (!id || id.includes("/") || id.startsWith("."))
|
|
120365
122233
|
return null;
|
|
120366
|
-
const items = runItems(sessions,
|
|
122234
|
+
const items = runItems(sessions, join62(sessionsDir, id), id, new Set);
|
|
120367
122235
|
return items?.find((i) => i.target === target) ?? null;
|
|
120368
122236
|
}
|
|
120369
122237
|
if (!target.startsWith("t:"))
|
|
120370
122238
|
return null;
|
|
120371
122239
|
const seenRuns = new Set;
|
|
120372
122240
|
for (const name of runDirs(sessionsDir)) {
|
|
120373
|
-
const dir =
|
|
120374
|
-
if (!name.startsWith("team-") && readJson(
|
|
122241
|
+
const dir = join62(sessionsDir, name);
|
|
122242
|
+
if (!name.startsWith("team-") && readJson(join62(dir, "spawn.json"))?.kind !== "team")
|
|
120375
122243
|
continue;
|
|
120376
122244
|
const found = runItems(sessions, dir, name, seenRuns)?.find((i) => i.target === target);
|
|
120377
122245
|
if (found)
|
|
@@ -120423,7 +122291,7 @@ class LineBuffer {
|
|
|
120423
122291
|
|
|
120424
122292
|
// src/view/view-client.ts
|
|
120425
122293
|
import { connect } from "net";
|
|
120426
|
-
import { basename as
|
|
122294
|
+
import { basename as basename10 } from "path";
|
|
120427
122295
|
function dial(path) {
|
|
120428
122296
|
return new Promise((resolve, reject) => {
|
|
120429
122297
|
const sock = connect(path);
|
|
@@ -120573,7 +122441,7 @@ class ViewClient {
|
|
|
120573
122441
|
}
|
|
120574
122442
|
async redial() {
|
|
120575
122443
|
let wait = RECONNECT_FIRST_MS;
|
|
120576
|
-
const name =
|
|
122444
|
+
const name = basename10(this.path);
|
|
120577
122445
|
while (!this.ended) {
|
|
120578
122446
|
if (!endpointOwnerAlive(name, await readProcessTableAsync())) {
|
|
120579
122447
|
this.end("server_gone");
|
|
@@ -120622,10 +122490,10 @@ var init_view_client = __esm(() => {
|
|
|
120622
122490
|
});
|
|
120623
122491
|
|
|
120624
122492
|
// src/view/feed-relay.ts
|
|
120625
|
-
import { chmodSync as
|
|
120626
|
-
import { dirname as
|
|
122493
|
+
import { chmodSync as chmodSync8, readFileSync as readFileSync50, renameSync as renameSync11, rmSync as rmSync17, writeFileSync as writeFileSync24 } from "fs";
|
|
122494
|
+
import { dirname as dirname24, join as join63 } from "path";
|
|
120627
122495
|
function defaultFeedPath(root) {
|
|
120628
|
-
return
|
|
122496
|
+
return join63(root, FEED_DIR, FEED_FILE);
|
|
120629
122497
|
}
|
|
120630
122498
|
function ownStamp() {
|
|
120631
122499
|
return {
|
|
@@ -120647,7 +122515,7 @@ function connectAsRelay(path) {
|
|
|
120647
122515
|
}
|
|
120648
122516
|
function readFeedStamp(path) {
|
|
120649
122517
|
try {
|
|
120650
|
-
const parsed = JSON.parse(
|
|
122518
|
+
const parsed = JSON.parse(readFileSync50(path, "utf8"));
|
|
120651
122519
|
const r = parsed.relay;
|
|
120652
122520
|
if (r && typeof r.pid === "number" && typeof r.start36 === "string")
|
|
120653
122521
|
return r;
|
|
@@ -120693,7 +122561,7 @@ class FeedRelay {
|
|
|
120693
122561
|
}
|
|
120694
122562
|
async start() {
|
|
120695
122563
|
ensureSockRoot(this.o.root);
|
|
120696
|
-
if (
|
|
122564
|
+
if (dirname24(this.path) === join63(this.o.root, FEED_DIR))
|
|
120697
122565
|
ensurePrivateSubdir(this.o.root, FEED_DIR);
|
|
120698
122566
|
const other = readFeedStamp(this.path);
|
|
120699
122567
|
if (other && !this.isOwn(other) && stampAlive(other, await readProcessTableAsync()))
|
|
@@ -120720,10 +122588,10 @@ class FeedRelay {
|
|
|
120720
122588
|
for (const s of this.servers.values())
|
|
120721
122589
|
s.conn.close();
|
|
120722
122590
|
this.servers.clear();
|
|
120723
|
-
|
|
122591
|
+
rmSync17(this.tmpPath(), { force: true });
|
|
120724
122592
|
const stamp = readFeedStamp(this.path);
|
|
120725
122593
|
if (stamp && this.isOwn(stamp))
|
|
120726
|
-
|
|
122594
|
+
rmSync17(this.path, { force: true });
|
|
120727
122595
|
}
|
|
120728
122596
|
nextWrite() {
|
|
120729
122597
|
return new Promise((resolve) => {
|
|
@@ -120894,9 +122762,9 @@ class FeedRelay {
|
|
|
120894
122762
|
...body
|
|
120895
122763
|
};
|
|
120896
122764
|
const tmp = this.tmpPath();
|
|
120897
|
-
|
|
122765
|
+
writeFileSync24(tmp, `${JSON.stringify(file)}
|
|
120898
122766
|
`, { mode: 384 });
|
|
120899
|
-
|
|
122767
|
+
chmodSync8(tmp, 384);
|
|
120900
122768
|
renameSync11(tmp, this.path);
|
|
120901
122769
|
this.lastKey = key;
|
|
120902
122770
|
this.lastWriteAt = this.now();
|
|
@@ -120946,19 +122814,19 @@ var init_feed_relay = __esm(() => {
|
|
|
120946
122814
|
|
|
120947
122815
|
// src/pane/pane-registry.ts
|
|
120948
122816
|
import {
|
|
120949
|
-
constants as
|
|
120950
|
-
accessSync as
|
|
122817
|
+
constants as constants6,
|
|
122818
|
+
accessSync as accessSync4,
|
|
120951
122819
|
existsSync as existsSync43,
|
|
120952
|
-
lstatSync as
|
|
120953
|
-
readFileSync as
|
|
120954
|
-
readdirSync as
|
|
122820
|
+
lstatSync as lstatSync11,
|
|
122821
|
+
readFileSync as readFileSync51,
|
|
122822
|
+
readdirSync as readdirSync15,
|
|
120955
122823
|
renameSync as renameSync12,
|
|
120956
|
-
rmSync as
|
|
122824
|
+
rmSync as rmSync18,
|
|
120957
122825
|
rmdirSync as rmdirSync3,
|
|
120958
122826
|
unlinkSync as unlinkSync12,
|
|
120959
|
-
writeFileSync as
|
|
122827
|
+
writeFileSync as writeFileSync25
|
|
120960
122828
|
} from "fs";
|
|
120961
|
-
import { dirname as
|
|
122829
|
+
import { dirname as dirname25, join as join64 } from "path";
|
|
120962
122830
|
function ownerStartOfSelf() {
|
|
120963
122831
|
if (ownStart)
|
|
120964
122832
|
return ownStart;
|
|
@@ -120979,12 +122847,12 @@ function ownerAlive(owner, table) {
|
|
|
120979
122847
|
return !minted || startedAt(row, minted.startMs);
|
|
120980
122848
|
}
|
|
120981
122849
|
function recordsDir(root) {
|
|
120982
|
-
return
|
|
122850
|
+
return join64(root, "panes");
|
|
120983
122851
|
}
|
|
120984
122852
|
function writeRecord(root, rec) {
|
|
120985
122853
|
const p = recordPathOf(root, rec.paneId);
|
|
120986
122854
|
const tmp = `${p}.tmp-${process.pid}`;
|
|
120987
|
-
|
|
122855
|
+
writeFileSync25(tmp, `${JSON.stringify(rec)}
|
|
120988
122856
|
`, { mode: 384 });
|
|
120989
122857
|
renameSync12(tmp, p);
|
|
120990
122858
|
}
|
|
@@ -120992,7 +122860,7 @@ function readRecord2(root, paneId) {
|
|
|
120992
122860
|
if (!isValidPaneId(paneId))
|
|
120993
122861
|
return null;
|
|
120994
122862
|
try {
|
|
120995
|
-
return validRecord(JSON.parse(
|
|
122863
|
+
return validRecord(JSON.parse(readFileSync51(recordPathOf(root, paneId), "utf8")), paneId);
|
|
120996
122864
|
} catch {
|
|
120997
122865
|
return null;
|
|
120998
122866
|
}
|
|
@@ -121049,7 +122917,7 @@ function validForkRef(v) {
|
|
|
121049
122917
|
function readRecords(root) {
|
|
121050
122918
|
let names;
|
|
121051
122919
|
try {
|
|
121052
|
-
names =
|
|
122920
|
+
names = readdirSync15(recordsDir(root)).filter((n) => n.endsWith(".json"));
|
|
121053
122921
|
} catch {
|
|
121054
122922
|
return [];
|
|
121055
122923
|
}
|
|
@@ -121063,16 +122931,16 @@ function readRecords(root) {
|
|
|
121063
122931
|
}
|
|
121064
122932
|
function readGroupFile(ctlDir) {
|
|
121065
122933
|
try {
|
|
121066
|
-
return parseGroupFile(
|
|
122934
|
+
return parseGroupFile(readFileSync51(join64(ctlDir, "group"), "utf8"));
|
|
121067
122935
|
} catch {
|
|
121068
122936
|
return null;
|
|
121069
122937
|
}
|
|
121070
122938
|
}
|
|
121071
122939
|
function writeGroupFile(ctlDir, snap) {
|
|
121072
|
-
const p =
|
|
122940
|
+
const p = join64(ctlDir, "group");
|
|
121073
122941
|
const tmp = `${p}.tmp`;
|
|
121074
122942
|
try {
|
|
121075
|
-
|
|
122943
|
+
writeFileSync25(tmp, formatGroupFile(snap), { mode: 384 });
|
|
121076
122944
|
renameSync12(tmp, p);
|
|
121077
122945
|
} catch {}
|
|
121078
122946
|
}
|
|
@@ -121080,22 +122948,22 @@ function removeForkRecord(fork, forkUuid) {
|
|
|
121080
122948
|
if (!isForkRecordPath(fork.projectsRoot, fork.path, forkUuid))
|
|
121081
122949
|
return;
|
|
121082
122950
|
try {
|
|
121083
|
-
|
|
122951
|
+
rmSync18(fork.path, { force: true });
|
|
121084
122952
|
if (fork.removeProjectDir)
|
|
121085
|
-
rmdirSync3(
|
|
122953
|
+
rmdirSync3(dirname25(fork.path));
|
|
121086
122954
|
} catch {}
|
|
121087
122955
|
}
|
|
121088
122956
|
function removePaneFiles(root, f) {
|
|
121089
122957
|
if (f.fork && f.sessionUuid)
|
|
121090
122958
|
removeForkRecord(f.fork, f.sessionUuid);
|
|
121091
122959
|
if (isPaneSockPath(root, f.sockPath, f.paneId))
|
|
121092
|
-
|
|
122960
|
+
rmSync18(f.sockPath, { force: true });
|
|
121093
122961
|
const view = viewSockPathOf(root, f.paneId);
|
|
121094
122962
|
if (isPaneViewSockPath(root, view, f.paneId))
|
|
121095
|
-
|
|
122963
|
+
rmSync18(view, { force: true });
|
|
121096
122964
|
for (const d of [f.launcherDir, f.turnDir])
|
|
121097
122965
|
if (d && isLaunchDirPath(root, d))
|
|
121098
|
-
|
|
122966
|
+
rmSync18(d, { recursive: true, force: true });
|
|
121099
122967
|
const rec = recordPathOf(root, f.paneId);
|
|
121100
122968
|
if (isPaneRecordPath(root, rec, f.paneId))
|
|
121101
122969
|
deleteRecord(root, f.paneId);
|
|
@@ -121318,14 +123186,14 @@ function dialErrno(reported, sockPath) {
|
|
|
121318
123186
|
return reported;
|
|
121319
123187
|
let isSocket;
|
|
121320
123188
|
try {
|
|
121321
|
-
isSocket =
|
|
123189
|
+
isSocket = lstatSync11(sockPath).isSocket();
|
|
121322
123190
|
} catch (e) {
|
|
121323
123191
|
return e.code ?? "unknown";
|
|
121324
123192
|
}
|
|
121325
123193
|
if (!isSocket)
|
|
121326
123194
|
return "ENOTSOCK";
|
|
121327
123195
|
try {
|
|
121328
|
-
|
|
123196
|
+
accessSync4(sockPath, constants6.W_OK);
|
|
121329
123197
|
} catch {
|
|
121330
123198
|
return "EACCES";
|
|
121331
123199
|
}
|
|
@@ -121363,11 +123231,11 @@ async function sweepRecordlessSocket(root, name, out) {
|
|
|
121363
123231
|
const owner = ownerOfSocketId(id);
|
|
121364
123232
|
if (!owner || ownerAlive(owner, table))
|
|
121365
123233
|
return;
|
|
121366
|
-
const sockPath =
|
|
123234
|
+
const sockPath = join64(root, name);
|
|
121367
123235
|
const magmuxMayLive = !table || table.some((r) => isPaneMagmuxCommand(r.command, id));
|
|
121368
123236
|
const probe = await probeSocket(sockPath, magmuxMayLive);
|
|
121369
123237
|
if (probe.state === "stale") {
|
|
121370
|
-
|
|
123238
|
+
rmSync18(sockPath, { force: true });
|
|
121371
123239
|
out.cleaned.push(id);
|
|
121372
123240
|
return;
|
|
121373
123241
|
}
|
|
@@ -121393,13 +123261,13 @@ async function sweepRecordlessSocket(root, name, out) {
|
|
|
121393
123261
|
if (mag)
|
|
121394
123262
|
signal(mag.pid, "SIGKILL");
|
|
121395
123263
|
await Bun.sleep(300);
|
|
121396
|
-
|
|
123264
|
+
rmSync18(sockPath, { force: true });
|
|
121397
123265
|
(mag ? out.reaped : out.kept).push(id);
|
|
121398
123266
|
}
|
|
121399
123267
|
function sweepRecordlessViewSockets(root, out) {
|
|
121400
123268
|
let names = [];
|
|
121401
123269
|
try {
|
|
121402
|
-
names =
|
|
123270
|
+
names = readdirSync15(root).filter((n) => /^magmux-c\d+-[A-Za-z0-9_-]+\.view$/.test(n));
|
|
121403
123271
|
} catch {
|
|
121404
123272
|
return;
|
|
121405
123273
|
}
|
|
@@ -121417,7 +123285,7 @@ function sweepRecordlessViewSockets(root, out) {
|
|
|
121417
123285
|
const view = viewSockPathOf(root, id);
|
|
121418
123286
|
if (!isPaneViewSockPath(root, view, id))
|
|
121419
123287
|
continue;
|
|
121420
|
-
|
|
123288
|
+
rmSync18(view, { force: true });
|
|
121421
123289
|
out.cleaned.push(id);
|
|
121422
123290
|
}
|
|
121423
123291
|
}
|
|
@@ -121432,7 +123300,7 @@ function sweepDeadFeed(root, out) {
|
|
|
121432
123300
|
const now = readFeedStamp(path);
|
|
121433
123301
|
if (!now || now.pid !== stamp.pid || now.start36 !== stamp.start36 || now.started_at !== stamp.started_at)
|
|
121434
123302
|
return;
|
|
121435
|
-
|
|
123303
|
+
rmSync18(path, { force: true });
|
|
121436
123304
|
out.cleaned.push("feed/feed.json");
|
|
121437
123305
|
}
|
|
121438
123306
|
async function ensureSwept(root) {
|
|
@@ -121451,7 +123319,7 @@ async function sweepOrphanPanes(root = sockRootFor()) {
|
|
|
121451
123319
|
const known = new Set(readRecords(root).map((r) => r.paneId));
|
|
121452
123320
|
let names = [];
|
|
121453
123321
|
try {
|
|
121454
|
-
names =
|
|
123322
|
+
names = readdirSync15(root).filter((n) => /^magmux-c\d+-[A-Za-z0-9_-]+\.sock$/.test(n));
|
|
121455
123323
|
} catch {
|
|
121456
123324
|
names = [];
|
|
121457
123325
|
}
|
|
@@ -121513,20 +123381,20 @@ var init_exit_evidence = __esm(() => {
|
|
|
121513
123381
|
});
|
|
121514
123382
|
|
|
121515
123383
|
// src/pane/gate-binding.ts
|
|
121516
|
-
import { realpathSync as
|
|
121517
|
-
import { basename as
|
|
123384
|
+
import { realpathSync as realpathSync9 } from "fs";
|
|
123385
|
+
import { basename as basename11, dirname as dirname26, join as join65, resolve as resolve11 } from "path";
|
|
121518
123386
|
function normaliseTranscriptPath(p) {
|
|
121519
|
-
const abs =
|
|
123387
|
+
const abs = resolve11(p);
|
|
121520
123388
|
const tail = [];
|
|
121521
123389
|
let cur = abs;
|
|
121522
123390
|
for (;; ) {
|
|
121523
123391
|
try {
|
|
121524
|
-
return tail.length ?
|
|
123392
|
+
return tail.length ? join65(realpathSync9(cur), ...tail.reverse()) : realpathSync9(cur);
|
|
121525
123393
|
} catch {
|
|
121526
|
-
const parent =
|
|
123394
|
+
const parent = dirname26(cur);
|
|
121527
123395
|
if (parent === cur)
|
|
121528
123396
|
return abs;
|
|
121529
|
-
tail.push(
|
|
123397
|
+
tail.push(basename11(cur));
|
|
121530
123398
|
cur = parent;
|
|
121531
123399
|
}
|
|
121532
123400
|
}
|
|
@@ -121615,7 +123483,7 @@ async function captureGroupBeforeReap(h) {
|
|
|
121615
123483
|
}
|
|
121616
123484
|
refreshGroupOf(h, table);
|
|
121617
123485
|
}
|
|
121618
|
-
async function
|
|
123486
|
+
async function groupAlive2(h) {
|
|
121619
123487
|
if (!h.group)
|
|
121620
123488
|
return false;
|
|
121621
123489
|
const table = await readProcessTableAsync();
|
|
@@ -121639,7 +123507,7 @@ async function groupBackstop(h) {
|
|
|
121639
123507
|
for (const target of targets)
|
|
121640
123508
|
signalQuietly(target, sig);
|
|
121641
123509
|
const end = Date.now() + (sig === "SIGTERM" ? ms(h, 2000, 500) : 1000);
|
|
121642
|
-
while (Date.now() < end && await
|
|
123510
|
+
while (Date.now() < end && await groupAlive2(h))
|
|
121643
123511
|
await Bun.sleep(150);
|
|
121644
123512
|
}
|
|
121645
123513
|
}
|
|
@@ -121657,7 +123525,7 @@ async function endWatcher(h) {
|
|
|
121657
123525
|
w.kill("SIGKILL");
|
|
121658
123526
|
}
|
|
121659
123527
|
async function verifyAndClean(h) {
|
|
121660
|
-
const groupGone = !await
|
|
123528
|
+
const groupGone = !await groupAlive2(h);
|
|
121661
123529
|
const magGone = !alive(h.magmux());
|
|
121662
123530
|
h.client()?.close();
|
|
121663
123531
|
if (groupGone && magGone) {
|
|
@@ -121743,8 +123611,8 @@ var init_scroll_input = __esm(() => {
|
|
|
121743
123611
|
});
|
|
121744
123612
|
|
|
121745
123613
|
// src/pane/session-registry.ts
|
|
121746
|
-
import { readFileSync as
|
|
121747
|
-
import { join as
|
|
123614
|
+
import { readFileSync as readFileSync52, readdirSync as readdirSync16 } from "fs";
|
|
123615
|
+
import { join as join66 } from "path";
|
|
121748
123616
|
function parseRegistryRecord(raw) {
|
|
121749
123617
|
let parsed;
|
|
121750
123618
|
try {
|
|
@@ -121771,7 +123639,7 @@ function parseRegistryRecord(raw) {
|
|
|
121771
123639
|
version: typeof r.version === "string" ? r.version : null
|
|
121772
123640
|
};
|
|
121773
123641
|
}
|
|
121774
|
-
function
|
|
123642
|
+
function pidAlive3(pid) {
|
|
121775
123643
|
try {
|
|
121776
123644
|
process.kill(pid, 0);
|
|
121777
123645
|
return true;
|
|
@@ -121789,9 +123657,9 @@ class SessionRegistry {
|
|
|
121789
123657
|
isAlive;
|
|
121790
123658
|
constructor(o) {
|
|
121791
123659
|
this.o = o;
|
|
121792
|
-
this.dir =
|
|
123660
|
+
this.dir = join66(o.configDir, "sessions");
|
|
121793
123661
|
this.now = o.now ?? Date.now;
|
|
121794
|
-
this.isAlive = o.isAlive ??
|
|
123662
|
+
this.isAlive = o.isAlive ?? pidAlive3;
|
|
121795
123663
|
}
|
|
121796
123664
|
read() {
|
|
121797
123665
|
if (this.pid !== null) {
|
|
@@ -121806,7 +123674,7 @@ class SessionRegistry {
|
|
|
121806
123674
|
this.lastScanAt = now;
|
|
121807
123675
|
let names;
|
|
121808
123676
|
try {
|
|
121809
|
-
names =
|
|
123677
|
+
names = readdirSync16(this.dir);
|
|
121810
123678
|
} catch {
|
|
121811
123679
|
return null;
|
|
121812
123680
|
}
|
|
@@ -121825,7 +123693,7 @@ class SessionRegistry {
|
|
|
121825
123693
|
readPid(pid) {
|
|
121826
123694
|
let raw;
|
|
121827
123695
|
try {
|
|
121828
|
-
raw =
|
|
123696
|
+
raw = readFileSync52(join66(this.dir, `${pid}.json`), "utf8");
|
|
121829
123697
|
} catch {
|
|
121830
123698
|
return null;
|
|
121831
123699
|
}
|
|
@@ -121974,8 +123842,8 @@ var init_view_socket = __esm(() => {
|
|
|
121974
123842
|
});
|
|
121975
123843
|
|
|
121976
123844
|
// src/pane/pane-session.ts
|
|
121977
|
-
import { readFileSync as
|
|
121978
|
-
import { join as
|
|
123845
|
+
import { readFileSync as readFileSync53, realpathSync as realpathSync10, rmSync as rmSync19, statSync as statSync27, writeFileSync as writeFileSync26 } from "fs";
|
|
123846
|
+
import { join as join67 } from "path";
|
|
121979
123847
|
function clearKeyCount(line, attempts, cols) {
|
|
121980
123848
|
const cells = 2 * Math.max(1, attempts) * Bun.stringWidth(line);
|
|
121981
123849
|
const halfRow = Math.max(1, Math.floor((cols - 4) / 2));
|
|
@@ -122060,6 +123928,7 @@ class PaneSessionImpl {
|
|
|
122060
123928
|
viewSock = null;
|
|
122061
123929
|
appliedSize;
|
|
122062
123930
|
supportsResize = false;
|
|
123931
|
+
magmuxVersion = "";
|
|
122063
123932
|
resizeWaiters = [];
|
|
122064
123933
|
resizeDraining = false;
|
|
122065
123934
|
lastSentSize = null;
|
|
@@ -122157,7 +124026,7 @@ class PaneSessionImpl {
|
|
|
122157
124026
|
});
|
|
122158
124027
|
this.secondaryQuietMs = o.timings?.secondaryQuietMs ?? SECONDARY_QUIET_MS;
|
|
122159
124028
|
this.corroborationMs = o.timings?.corroborationMs ?? CORROBORATION_MS;
|
|
122160
|
-
this.follower = new TranscriptFollower(o.transcriptPath,
|
|
124029
|
+
this.follower = new TranscriptFollower(o.transcriptPath, join67(o.transcriptPath.replace(/\.jsonl$/, ""), "subagents"));
|
|
122161
124030
|
this.registry = new SessionRegistry({
|
|
122162
124031
|
configDir: claudeCodeConfigDir(o.parentEnv ?? process.env, o.cwd),
|
|
122163
124032
|
sessionUuid: o.sessionUuid
|
|
@@ -122204,7 +124073,7 @@ class PaneSessionImpl {
|
|
|
122204
124073
|
return this.spawnFailed(new Error("magmux did not start"));
|
|
122205
124074
|
this.magmux = proc;
|
|
122206
124075
|
try {
|
|
122207
|
-
|
|
124076
|
+
writeFileSync26(join67(this.ctlDir, "magmux.pid"), `${proc.pid}
|
|
122208
124077
|
`, { mode: 384 });
|
|
122209
124078
|
} catch {}
|
|
122210
124079
|
updateRecord(this.root, this.paneId, { magmuxPid: proc.pid });
|
|
@@ -122263,6 +124132,7 @@ class PaneSessionImpl {
|
|
|
122263
124132
|
this.gateTrusted = false;
|
|
122264
124133
|
this.gate = null;
|
|
122265
124134
|
const magmuxVersion = caps.ok ? String(caps.result.version ?? "") : "";
|
|
124135
|
+
this.magmuxVersion = magmuxVersion;
|
|
122266
124136
|
if (caps.ok) {
|
|
122267
124137
|
const v = magmuxVersion;
|
|
122268
124138
|
if (caps.result.protocol !== 1 || !versionAtLeast(v, MIN_MAGMUX_VERSION)) {
|
|
@@ -123330,7 +125200,8 @@ ${gate}`
|
|
|
123330
125200
|
return;
|
|
123331
125201
|
}
|
|
123332
125202
|
if (seen?.match === "prefix") {
|
|
123333
|
-
|
|
125203
|
+
const alone = adm.writtenPart !== null && writtenPartShown(adm.writtenPart, seen);
|
|
125204
|
+
this.anomaly(alone ? "box_drawn_written_part" : "box_drawn_other_after_mismatch");
|
|
123334
125205
|
this.noteReadWhole(adm);
|
|
123335
125206
|
adm.writtenPart = null;
|
|
123336
125207
|
markClearFirst(adm);
|
|
@@ -123776,7 +125647,7 @@ ${screenTailOf(this.screen)}` });
|
|
|
123776
125647
|
if (!out.stopped)
|
|
123777
125648
|
return;
|
|
123778
125649
|
this.anomaly(`typing_stopped:${out.stopped.reason}`);
|
|
123779
|
-
adm.writtenPart = writtenPrefix(adm.line, out.stopped.writes);
|
|
125650
|
+
adm.writtenPart = writtenPrefix(adm.line, out.stopped.writes, versionAtLeast(this.magmuxVersion, EVIDENCED_WRITES_VERSION));
|
|
123780
125651
|
}
|
|
123781
125652
|
noteTyping(adm, step, out) {
|
|
123782
125653
|
adm.writtenPart = null;
|
|
@@ -124515,7 +126386,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124515
126386
|
if (!p)
|
|
124516
126387
|
return 0;
|
|
124517
126388
|
try {
|
|
124518
|
-
return
|
|
126389
|
+
return statSync27(p).size;
|
|
124519
126390
|
} catch {
|
|
124520
126391
|
return 0;
|
|
124521
126392
|
}
|
|
@@ -124524,7 +126395,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124524
126395
|
const p = this.errorLogPath();
|
|
124525
126396
|
if (p && this.errorLogSize() > st.errorLogSize) {
|
|
124526
126397
|
try {
|
|
124527
|
-
const text =
|
|
126398
|
+
const text = readFileSync53(p, "utf8").slice(st.errorLogSize).trim();
|
|
124528
126399
|
return { status: null, category: "upstream_error_log", text };
|
|
124529
126400
|
} catch {}
|
|
124530
126401
|
}
|
|
@@ -125119,16 +126990,24 @@ function drawEnded(now, goneCounts, quietMs, partOnly) {
|
|
|
125119
126990
|
return null;
|
|
125120
126991
|
if (ended !== null)
|
|
125121
126992
|
return ended;
|
|
125122
|
-
|
|
126993
|
+
if (quietMs < DRAW_SETTLE_MS)
|
|
126994
|
+
return null;
|
|
126995
|
+
return writtenPartShown(partOnly, now) || writtenPartAfterOther(partOnly, now) ? "settled" : null;
|
|
126996
|
+
}
|
|
126997
|
+
function writtenPartAfterOther(part, now) {
|
|
126998
|
+
if (!now || now.match !== "prefix")
|
|
126999
|
+
return false;
|
|
127000
|
+
const shown = trimTrailingSpaces(part);
|
|
127001
|
+
if (shown === "" || !boxEndsWith(now.text, shown))
|
|
127002
|
+
return false;
|
|
127003
|
+
const spaces = part.length - shown.length;
|
|
127004
|
+
return spaces === 0 || now.cursorGap === spaces;
|
|
125123
127005
|
}
|
|
125124
127006
|
function unprovenSpaces(now, part) {
|
|
125125
127007
|
if (!now || !part.endsWith(" ") || writtenPartShown(part, now))
|
|
125126
127008
|
return false;
|
|
125127
127009
|
return part.replace(/\s+/g, "").startsWith(now.text.replace(/\s+/g, ""));
|
|
125128
127010
|
}
|
|
125129
|
-
function isWrittenPart(now, part, quietMs) {
|
|
125130
|
-
return quietMs >= DRAW_SETTLE_MS && writtenPartShown(part, now);
|
|
125131
|
-
}
|
|
125132
127011
|
function writtenPartShown(part, now) {
|
|
125133
127012
|
if (!now || now.match !== "prefix")
|
|
125134
127013
|
return false;
|
|
@@ -125281,7 +127160,7 @@ function preparePane(o, root, parentEnv) {
|
|
|
125281
127160
|
try {
|
|
125282
127161
|
const paneId = mintPaneId(o.kind, o.label);
|
|
125283
127162
|
const sockPath = sockPathOf(root, paneId);
|
|
125284
|
-
const cwd =
|
|
127163
|
+
const cwd = realpathSync10(o.cwd);
|
|
125285
127164
|
const launch = o.claudishSpawn ?? resolveClaudishLaunch(parentEnv);
|
|
125286
127165
|
dirs = createLaunchDirs(root);
|
|
125287
127166
|
const argv = buildClaudishPaneArgv(o.spawnModel, o.sessionUuid, dirs.turnDir, o.callerFlags, o.spawnPinned === true);
|
|
@@ -125298,7 +127177,7 @@ function preparePane(o, root, parentEnv) {
|
|
|
125298
127177
|
} catch (e) {
|
|
125299
127178
|
for (const d of dirs ? [dirs.ctlDir, dirs.turnDir] : [])
|
|
125300
127179
|
if (isLaunchDirPath(root, d))
|
|
125301
|
-
|
|
127180
|
+
rmSync19(d, { recursive: true, force: true });
|
|
125302
127181
|
if (e.code)
|
|
125303
127182
|
throw e;
|
|
125304
127183
|
throw new PaneStartError("pane_lost", e instanceof Error ? e.message : String(e));
|
|
@@ -125435,8 +127314,8 @@ var init_pane_session = __esm(() => {
|
|
|
125435
127314
|
});
|
|
125436
127315
|
|
|
125437
127316
|
// src/pane/replay-pane.ts
|
|
125438
|
-
import { rmSync as
|
|
125439
|
-
import { join as
|
|
127317
|
+
import { rmSync as rmSync20, writeFileSync as writeFileSync27 } from "fs";
|
|
127318
|
+
import { join as join68 } from "path";
|
|
125440
127319
|
async function waitUntil(pred, ms) {
|
|
125441
127320
|
const end = Date.now() + ms;
|
|
125442
127321
|
while (!pred() && Date.now() < end)
|
|
@@ -125549,7 +127428,7 @@ class ReplayPane {
|
|
|
125549
127428
|
return failed(new Error("magmux did not start"));
|
|
125550
127429
|
this.magmuxProc = proc;
|
|
125551
127430
|
try {
|
|
125552
|
-
|
|
127431
|
+
writeFileSync27(join68(this.ctlDir, "magmux.pid"), `${proc.pid}
|
|
125553
127432
|
`, { mode: 384 });
|
|
125554
127433
|
} catch {}
|
|
125555
127434
|
updateRecord(this.root, this.paneId, { magmuxPid: proc.pid });
|
|
@@ -126021,7 +127900,7 @@ async function startReplayPane(o) {
|
|
|
126021
127900
|
} catch (e) {
|
|
126022
127901
|
for (const d of dirs ? [dirs.ctlDir, dirs.turnDir] : [])
|
|
126023
127902
|
if (isLaunchDirPath(root, d))
|
|
126024
|
-
|
|
127903
|
+
rmSync20(d, { recursive: true, force: true });
|
|
126025
127904
|
throw e;
|
|
126026
127905
|
}
|
|
126027
127906
|
const pane = new ReplayPane(o, {
|
|
@@ -126466,18 +128345,18 @@ var init_transcript_redaction = __esm(() => {
|
|
|
126466
128345
|
|
|
126467
128346
|
// src/pane/transcript-page.ts
|
|
126468
128347
|
import {
|
|
126469
|
-
constants as
|
|
126470
|
-
closeSync as
|
|
126471
|
-
fstatSync as
|
|
126472
|
-
lstatSync as
|
|
126473
|
-
openSync as
|
|
126474
|
-
readSync as
|
|
126475
|
-
readdirSync as
|
|
126476
|
-
readlinkSync,
|
|
126477
|
-
realpathSync as
|
|
126478
|
-
statSync as
|
|
128348
|
+
constants as constants7,
|
|
128349
|
+
closeSync as closeSync20,
|
|
128350
|
+
fstatSync as fstatSync6,
|
|
128351
|
+
lstatSync as lstatSync12,
|
|
128352
|
+
openSync as openSync20,
|
|
128353
|
+
readSync as readSync10,
|
|
128354
|
+
readdirSync as readdirSync17,
|
|
128355
|
+
readlinkSync as readlinkSync2,
|
|
128356
|
+
realpathSync as realpathSync11,
|
|
128357
|
+
statSync as statSync28
|
|
126479
128358
|
} from "fs";
|
|
126480
|
-
import { basename as
|
|
128359
|
+
import { basename as basename12, dirname as dirname27, join as join69, sep as sep4 } from "path";
|
|
126481
128360
|
function isUuid(v) {
|
|
126482
128361
|
return typeof v === "string" && UUID_RE.test(v);
|
|
126483
128362
|
}
|
|
@@ -126524,7 +128403,7 @@ class LineScanner {
|
|
|
126524
128403
|
return null;
|
|
126525
128404
|
const n = Math.min(READ_CHUNK, this.size - at);
|
|
126526
128405
|
const b = Buffer.alloc(n);
|
|
126527
|
-
const got =
|
|
128406
|
+
const got = readSync10(this.fd, b, 0, n, at);
|
|
126528
128407
|
if (got <= 0)
|
|
126529
128408
|
return null;
|
|
126530
128409
|
this.chunk = got < n ? b.subarray(0, got) : b;
|
|
@@ -126559,12 +128438,12 @@ function absentPage(from) {
|
|
|
126559
128438
|
}
|
|
126560
128439
|
function closeQuietly(fd) {
|
|
126561
128440
|
try {
|
|
126562
|
-
|
|
128441
|
+
closeSync20(fd);
|
|
126563
128442
|
} catch {}
|
|
126564
128443
|
}
|
|
126565
128444
|
function readTranscriptPageFd(fd, from, limits) {
|
|
126566
128445
|
const lim = { ...DEFAULT_PAGE_LIMITS, ...limits };
|
|
126567
|
-
const st =
|
|
128446
|
+
const st = fstatSync6(fd);
|
|
126568
128447
|
if (!st.isFile())
|
|
126569
128448
|
return absentPage(from);
|
|
126570
128449
|
const size = st.size;
|
|
@@ -126572,7 +128451,7 @@ function readTranscriptPageFd(fd, from, limits) {
|
|
|
126572
128451
|
throw new ContractErrorException("invalid_args", "'since' is past the end of the transcript");
|
|
126573
128452
|
if (from.offset > 0) {
|
|
126574
128453
|
const b = Buffer.alloc(1);
|
|
126575
|
-
const got =
|
|
128454
|
+
const got = readSync10(fd, b, 0, 1, from.offset - 1);
|
|
126576
128455
|
if (got !== 1 || b[0] !== 10)
|
|
126577
128456
|
throw new ContractErrorException("invalid_args", "'since' is not at a line start");
|
|
126578
128457
|
}
|
|
@@ -126621,15 +128500,15 @@ function locateTranscriptByUuid(projectsRoot, uuid) {
|
|
|
126621
128500
|
return null;
|
|
126622
128501
|
let dirs;
|
|
126623
128502
|
try {
|
|
126624
|
-
dirs =
|
|
128503
|
+
dirs = readdirSync17(projectsRoot);
|
|
126625
128504
|
} catch {
|
|
126626
128505
|
return null;
|
|
126627
128506
|
}
|
|
126628
128507
|
let hit = null;
|
|
126629
128508
|
for (const d of dirs) {
|
|
126630
|
-
const p =
|
|
128509
|
+
const p = join69(projectsRoot, d, `${uuid}.jsonl`);
|
|
126631
128510
|
try {
|
|
126632
|
-
if (!
|
|
128511
|
+
if (!statSync28(p).isFile())
|
|
126633
128512
|
continue;
|
|
126634
128513
|
} catch {
|
|
126635
128514
|
continue;
|
|
@@ -126657,7 +128536,7 @@ function writerLiveness(pid) {
|
|
|
126657
128536
|
}
|
|
126658
128537
|
function fileAgeMs(path, now = Date.now()) {
|
|
126659
128538
|
try {
|
|
126660
|
-
return now -
|
|
128539
|
+
return now - statSync28(path).mtimeMs;
|
|
126661
128540
|
} catch {
|
|
126662
128541
|
return null;
|
|
126663
128542
|
}
|
|
@@ -126682,27 +128561,27 @@ function errText(e) {
|
|
|
126682
128561
|
return e instanceof Error ? e.message : String(e);
|
|
126683
128562
|
}
|
|
126684
128563
|
function openContainedTranscript(path, uuid, projectsRoot) {
|
|
126685
|
-
if (
|
|
128564
|
+
if (basename12(path) !== `${uuid}.jsonl`) {
|
|
126686
128565
|
logRejection(path, "basename is not the session uuid");
|
|
126687
128566
|
return null;
|
|
126688
128567
|
}
|
|
126689
128568
|
let real;
|
|
126690
128569
|
let root;
|
|
126691
128570
|
try {
|
|
126692
|
-
real =
|
|
126693
|
-
root =
|
|
128571
|
+
real = realpathSync11(path);
|
|
128572
|
+
root = realpathSync11(projectsRoot);
|
|
126694
128573
|
} catch (e) {
|
|
126695
128574
|
if (!isEnoent(e))
|
|
126696
128575
|
logRejection(path, errText(e));
|
|
126697
128576
|
return null;
|
|
126698
128577
|
}
|
|
126699
|
-
if (!real.startsWith(root +
|
|
128578
|
+
if (!real.startsWith(root + sep4)) {
|
|
126700
128579
|
logRejection(path, "outside the Claude Code projects directory");
|
|
126701
128580
|
return null;
|
|
126702
128581
|
}
|
|
126703
128582
|
let fd;
|
|
126704
128583
|
try {
|
|
126705
|
-
fd =
|
|
128584
|
+
fd = openSync20(real, OPEN_FLAGS);
|
|
126706
128585
|
} catch (e) {
|
|
126707
128586
|
if (e?.code === "ELOOP")
|
|
126708
128587
|
logRejection(path, "the transcript became a symlink");
|
|
@@ -126711,15 +128590,15 @@ function openContainedTranscript(path, uuid, projectsRoot) {
|
|
|
126711
128590
|
return null;
|
|
126712
128591
|
}
|
|
126713
128592
|
try {
|
|
126714
|
-
const st =
|
|
128593
|
+
const st = fstatSync6(fd);
|
|
126715
128594
|
if (!st.isFile()) {
|
|
126716
128595
|
logRejection(path, "not a regular file");
|
|
126717
128596
|
closeQuietly(fd);
|
|
126718
128597
|
return null;
|
|
126719
128598
|
}
|
|
126720
|
-
const parent =
|
|
126721
|
-
const named =
|
|
126722
|
-
if (
|
|
128599
|
+
const parent = dirname27(real);
|
|
128600
|
+
const named = lstatSync12(real);
|
|
128601
|
+
if (realpathSync11(parent) !== parent || !named.isFile() || named.dev !== st.dev || named.ino !== st.ino || !kernelPathMatches(fd, real)) {
|
|
126723
128602
|
logRejection(path, "the opened file is not the one under the projects directory");
|
|
126724
128603
|
closeQuietly(fd);
|
|
126725
128604
|
return null;
|
|
@@ -126737,7 +128616,7 @@ function kernelPathMatches(fd, real) {
|
|
|
126737
128616
|
return true;
|
|
126738
128617
|
let kernel;
|
|
126739
128618
|
try {
|
|
126740
|
-
kernel =
|
|
128619
|
+
kernel = readlinkSync2(`/proc/self/fd/${fd}`);
|
|
126741
128620
|
} catch {
|
|
126742
128621
|
return true;
|
|
126743
128622
|
}
|
|
@@ -126750,7 +128629,7 @@ function transcriptHeadCwd(path, uuid, projectsRoot) {
|
|
|
126750
128629
|
let text;
|
|
126751
128630
|
try {
|
|
126752
128631
|
const buf = Buffer.alloc(HEAD_CWD_MAX_BYTES);
|
|
126753
|
-
const n =
|
|
128632
|
+
const n = readSync10(fd, buf, 0, HEAD_CWD_MAX_BYTES, 0);
|
|
126754
128633
|
text = buf.toString("utf8", 0, n);
|
|
126755
128634
|
} catch {
|
|
126756
128635
|
return null;
|
|
@@ -126832,7 +128711,7 @@ var init_transcript_page = __esm(() => {
|
|
|
126832
128711
|
maxEntryBytes: 32 * 1024 * 1024
|
|
126833
128712
|
};
|
|
126834
128713
|
READ_CHUNK = 1024 * 1024;
|
|
126835
|
-
OPEN_FLAGS =
|
|
128714
|
+
OPEN_FLAGS = constants7.O_RDONLY | (constants7.O_NOFOLLOW ?? 0) | (constants7.O_NONBLOCK ?? 0);
|
|
126836
128715
|
loggedRejections = new Set;
|
|
126837
128716
|
HEAD_CWD_MAX_BYTES = 256 * 1024;
|
|
126838
128717
|
});
|
|
@@ -126862,7 +128741,7 @@ var init_pane = __esm(() => {
|
|
|
126862
128741
|
});
|
|
126863
128742
|
|
|
126864
128743
|
// src/view/kernel-lock.ts
|
|
126865
|
-
import { constants as
|
|
128744
|
+
import { constants as constants8, closeSync as closeSync21, fstatSync as fstatSync7, openSync as openSync21, statSync as statSync29, unlinkSync as unlinkSync13 } from "fs";
|
|
126866
128745
|
function bindFlock() {
|
|
126867
128746
|
const library = process.platform === "darwin" ? "libSystem.B.dylib" : process.platform === "linux" ? "libc.so.6" : null;
|
|
126868
128747
|
if (!library)
|
|
@@ -126905,7 +128784,7 @@ function lockOf(fd, path) {
|
|
|
126905
128784
|
return;
|
|
126906
128785
|
open = false;
|
|
126907
128786
|
try {
|
|
126908
|
-
|
|
128787
|
+
closeSync21(fd);
|
|
126909
128788
|
} catch {}
|
|
126910
128789
|
}
|
|
126911
128790
|
};
|
|
@@ -126915,23 +128794,23 @@ function tryAcquire(path) {
|
|
|
126915
128794
|
if (!lib)
|
|
126916
128795
|
throw new KernelLockUnavailable("flock is not available in this process");
|
|
126917
128796
|
for (let attempt = 0;attempt < 5; attempt++) {
|
|
126918
|
-
const fd =
|
|
128797
|
+
const fd = openSync21(path, constants8.O_RDWR | constants8.O_CREAT | O_CLOEXEC, 384);
|
|
126919
128798
|
if (lib.flock(fd, LOCK_EX | LOCK_NB) !== 0) {
|
|
126920
128799
|
const errno = lib.errno();
|
|
126921
|
-
|
|
128800
|
+
closeSync21(fd);
|
|
126922
128801
|
if (errno === EWOULDBLOCK)
|
|
126923
128802
|
return null;
|
|
126924
128803
|
throw new KernelLockUnavailable(`flock ${path}: errno ${errno}`);
|
|
126925
128804
|
}
|
|
126926
128805
|
let same = false;
|
|
126927
128806
|
try {
|
|
126928
|
-
same =
|
|
128807
|
+
same = fstatSync7(fd).ino === statSync29(path).ino;
|
|
126929
128808
|
} catch {
|
|
126930
128809
|
same = false;
|
|
126931
128810
|
}
|
|
126932
128811
|
if (same)
|
|
126933
128812
|
return lockOf(fd, path);
|
|
126934
|
-
|
|
128813
|
+
closeSync21(fd);
|
|
126935
128814
|
}
|
|
126936
128815
|
throw new KernelLockUnavailable(`flock ${path}: the file keeps being replaced`);
|
|
126937
128816
|
}
|
|
@@ -127121,8 +129000,8 @@ var init_peer_link = __esm(() => {
|
|
|
127121
129000
|
|
|
127122
129001
|
// src/view/replay-registry.ts
|
|
127123
129002
|
import { randomBytes as randomBytes18 } from "crypto";
|
|
127124
|
-
import { readFileSync as
|
|
127125
|
-
import { join as
|
|
129003
|
+
import { readFileSync as readFileSync54, readdirSync as readdirSync18, renameSync as renameSync13, rmSync as rmSync21, writeFileSync as writeFileSync28 } from "fs";
|
|
129004
|
+
import { join as join70 } from "path";
|
|
127126
129005
|
function parseEntry(raw) {
|
|
127127
129006
|
let v;
|
|
127128
129007
|
try {
|
|
@@ -127160,14 +129039,14 @@ class ReplayRegistry {
|
|
|
127160
129039
|
constructor(root, log = () => {}) {
|
|
127161
129040
|
this.root = root;
|
|
127162
129041
|
this.log = log;
|
|
127163
|
-
this.dir =
|
|
129042
|
+
this.dir = join70(root, REPLAYS_DIR);
|
|
127164
129043
|
}
|
|
127165
129044
|
ensure() {
|
|
127166
129045
|
ensureSockRoot(this.root);
|
|
127167
129046
|
return ensurePrivateSubdir(this.root, REPLAYS_DIR);
|
|
127168
129047
|
}
|
|
127169
129048
|
lockPathOf(uuid) {
|
|
127170
|
-
return
|
|
129049
|
+
return join70(this.dir, `${this.key(uuid)}.lock`);
|
|
127171
129050
|
}
|
|
127172
129051
|
tryLock(uuid) {
|
|
127173
129052
|
this.ensure();
|
|
@@ -127175,14 +129054,14 @@ class ReplayRegistry {
|
|
|
127175
129054
|
}
|
|
127176
129055
|
read(uuid) {
|
|
127177
129056
|
try {
|
|
127178
|
-
return parseEntry(
|
|
129057
|
+
return parseEntry(readFileSync54(this.entryPathOf(uuid), "utf8"));
|
|
127179
129058
|
} catch {
|
|
127180
129059
|
return null;
|
|
127181
129060
|
}
|
|
127182
129061
|
}
|
|
127183
129062
|
async withLock(fn, waitMs = REGISTRY_LOCK_WAIT_MS) {
|
|
127184
129063
|
this.ensure();
|
|
127185
|
-
const lock = await waitAcquire(
|
|
129064
|
+
const lock = await waitAcquire(join70(this.dir, "registry.lock"), waitMs);
|
|
127186
129065
|
if (!lock)
|
|
127187
129066
|
return null;
|
|
127188
129067
|
try {
|
|
@@ -127194,12 +129073,12 @@ class ReplayRegistry {
|
|
|
127194
129073
|
writeLocked(uuid, entry) {
|
|
127195
129074
|
const path = this.entryPathOf(uuid);
|
|
127196
129075
|
const tmp = `${path}.${randomBytes18(4).toString("hex")}.tmp`;
|
|
127197
|
-
|
|
129076
|
+
writeFileSync28(tmp, `${JSON.stringify(entry)}
|
|
127198
129077
|
`, { mode: 384, flag: "wx" });
|
|
127199
129078
|
try {
|
|
127200
129079
|
renameSync13(tmp, path);
|
|
127201
129080
|
} catch (e) {
|
|
127202
|
-
|
|
129081
|
+
rmSync21(tmp, { force: true });
|
|
127203
129082
|
throw e;
|
|
127204
129083
|
}
|
|
127205
129084
|
}
|
|
@@ -127220,7 +129099,7 @@ class ReplayRegistry {
|
|
|
127220
129099
|
const e = this.read(uuid);
|
|
127221
129100
|
if (!e || e.replay_id !== replayId)
|
|
127222
129101
|
return false;
|
|
127223
|
-
|
|
129102
|
+
rmSync21(this.entryPathOf(uuid), { force: true });
|
|
127224
129103
|
return true;
|
|
127225
129104
|
});
|
|
127226
129105
|
if (!done)
|
|
@@ -127230,7 +129109,7 @@ class ReplayRegistry {
|
|
|
127230
129109
|
async sweep() {
|
|
127231
129110
|
let names;
|
|
127232
129111
|
try {
|
|
127233
|
-
names =
|
|
129112
|
+
names = readdirSync18(this.dir);
|
|
127234
129113
|
} catch {
|
|
127235
129114
|
return [];
|
|
127236
129115
|
}
|
|
@@ -127244,7 +129123,7 @@ class ReplayRegistry {
|
|
|
127244
129123
|
if (!held)
|
|
127245
129124
|
continue;
|
|
127246
129125
|
try {
|
|
127247
|
-
await this.withLock(() =>
|
|
129126
|
+
await this.withLock(() => rmSync21(this.entryPathOf(uuid), { force: true }));
|
|
127248
129127
|
} finally {
|
|
127249
129128
|
held.close();
|
|
127250
129129
|
}
|
|
@@ -127254,18 +129133,18 @@ class ReplayRegistry {
|
|
|
127254
129133
|
await this.withLock(() => {
|
|
127255
129134
|
let now;
|
|
127256
129135
|
try {
|
|
127257
|
-
now =
|
|
129136
|
+
now = readdirSync18(this.dir);
|
|
127258
129137
|
} catch {
|
|
127259
129138
|
return;
|
|
127260
129139
|
}
|
|
127261
129140
|
for (const name of now)
|
|
127262
129141
|
if (name.endsWith(".tmp"))
|
|
127263
|
-
|
|
129142
|
+
rmSync21(join70(this.dir, name), { force: true });
|
|
127264
129143
|
});
|
|
127265
129144
|
return swept;
|
|
127266
129145
|
}
|
|
127267
129146
|
entryPathOf(uuid) {
|
|
127268
|
-
return
|
|
129147
|
+
return join70(this.dir, `${this.key(uuid)}.json`);
|
|
127269
129148
|
}
|
|
127270
129149
|
key(uuid) {
|
|
127271
129150
|
const k = uuid.toLowerCase();
|
|
@@ -127286,8 +129165,8 @@ var init_replay_registry = __esm(() => {
|
|
|
127286
129165
|
|
|
127287
129166
|
// src/mcp-session/replay-manager.ts
|
|
127288
129167
|
import { randomBytes as randomBytes19, randomUUID as randomUUID10 } from "crypto";
|
|
127289
|
-
import { constants as
|
|
127290
|
-
import { dirname as
|
|
129168
|
+
import { constants as constants9, accessSync as accessSync5, closeSync as closeSync22, existsSync as existsSync44, realpathSync as realpathSync12, statSync as statSync30 } from "fs";
|
|
129169
|
+
import { dirname as dirname28, resolve as resolve12 } from "path";
|
|
127291
129170
|
function unavailable2(reason, message) {
|
|
127292
129171
|
return new ContractErrorException("replay_unavailable", message, reason);
|
|
127293
129172
|
}
|
|
@@ -127300,19 +129179,19 @@ function elsewhere(endpoint, replayId) {
|
|
|
127300
129179
|
function replayCwd(own) {
|
|
127301
129180
|
if (own) {
|
|
127302
129181
|
try {
|
|
127303
|
-
if (
|
|
127304
|
-
return
|
|
129182
|
+
if (statSync30(own).isDirectory())
|
|
129183
|
+
return realpathSync12(own);
|
|
127305
129184
|
} catch {}
|
|
127306
129185
|
}
|
|
127307
|
-
return
|
|
129186
|
+
return realpathSync12(process.cwd());
|
|
127308
129187
|
}
|
|
127309
129188
|
async function replayClaudeBinary(env) {
|
|
127310
|
-
const named = env.CLAUDE_PATH ?
|
|
129189
|
+
const named = env.CLAUDE_PATH ? resolve12(env.CLAUDE_PATH) : "";
|
|
127311
129190
|
if (named) {
|
|
127312
129191
|
try {
|
|
127313
|
-
if (!
|
|
129192
|
+
if (!statSync30(named).isFile())
|
|
127314
129193
|
throw new Error("not a file");
|
|
127315
|
-
|
|
129194
|
+
accessSync5(named, constants9.X_OK);
|
|
127316
129195
|
} catch {
|
|
127317
129196
|
throw new Error(`CLAUDE_PATH ${named} is not an executable file`);
|
|
127318
129197
|
}
|
|
@@ -127328,7 +129207,7 @@ function callerOf(opener) {
|
|
|
127328
129207
|
}
|
|
127329
129208
|
function isRecordGone(path) {
|
|
127330
129209
|
try {
|
|
127331
|
-
|
|
129210
|
+
statSync30(path);
|
|
127332
129211
|
return false;
|
|
127333
129212
|
} catch (e) {
|
|
127334
129213
|
return e.code === "ENOENT";
|
|
@@ -127354,7 +129233,7 @@ class ReplayManager {
|
|
|
127354
129233
|
this.options = options;
|
|
127355
129234
|
this.parentEnv = options.parentEnv ?? process.env;
|
|
127356
129235
|
this.readyMs = options.readyMs ?? REPLAY_READY_MS;
|
|
127357
|
-
this.root =
|
|
129236
|
+
this.root = resolve12(options.sockRoot ?? sockRootFor(this.parentEnv));
|
|
127358
129237
|
this.peersValue = options.peers ?? null;
|
|
127359
129238
|
this.sharedValue = options.shared ?? null;
|
|
127360
129239
|
}
|
|
@@ -127611,7 +129490,7 @@ class ReplayManager {
|
|
|
127611
129490
|
const uuid = slot.uuid;
|
|
127612
129491
|
const forkUuid = randomUUID10();
|
|
127613
129492
|
const cwd = replayCwd(target.cwd);
|
|
127614
|
-
const projectsRoot =
|
|
129493
|
+
const projectsRoot = resolve12(target.projectsRoot);
|
|
127615
129494
|
const forkPath = transcriptPathFor(cwd, forkUuid, projectsRoot);
|
|
127616
129495
|
const entry = {
|
|
127617
129496
|
kind: "owned",
|
|
@@ -127639,8 +129518,8 @@ class ReplayManager {
|
|
|
127639
129518
|
cwd,
|
|
127640
129519
|
projectsRoot,
|
|
127641
129520
|
forkPath,
|
|
127642
|
-
removeProjectDir: !existsSync44(
|
|
127643
|
-
configDir:
|
|
129521
|
+
removeProjectDir: !existsSync44(dirname28(forkPath)),
|
|
129522
|
+
configDir: dirname28(projectsRoot),
|
|
127644
129523
|
cols: size.cols ?? DEFAULT_PANE_COLS,
|
|
127645
129524
|
rows: size.rows ?? DEFAULT_PANE_ROWS
|
|
127646
129525
|
});
|
|
@@ -127941,7 +129820,7 @@ class ReplayManager {
|
|
|
127941
129820
|
const fd = openContainedTranscript(path, uuid, target.projectsRoot);
|
|
127942
129821
|
if (fd === null)
|
|
127943
129822
|
throw noRecord("the session's Claude Code record is gone");
|
|
127944
|
-
|
|
129823
|
+
closeSync22(fd);
|
|
127945
129824
|
return uuid;
|
|
127946
129825
|
}
|
|
127947
129826
|
itemOf(e) {
|
|
@@ -128633,10 +130512,10 @@ var init_claude_launch = __esm(() => {
|
|
|
128633
130512
|
});
|
|
128634
130513
|
|
|
128635
130514
|
// src/mcp/run-prompt-claude-code.ts
|
|
128636
|
-
import { spawn as
|
|
128637
|
-
import { mkdirSync as mkdirSync28, mkdtempSync as
|
|
128638
|
-
import { tmpdir as
|
|
128639
|
-
import { join as
|
|
130515
|
+
import { spawn as spawn5 } from "child_process";
|
|
130516
|
+
import { mkdirSync as mkdirSync28, mkdtempSync as mkdtempSync5, rmSync as rmSync22, writeFileSync as writeFileSync29 } from "fs";
|
|
130517
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
130518
|
+
import { join as join71 } from "path";
|
|
128640
130519
|
function claudeCodePrintArgv(model, systemPromptFile, opts = {}) {
|
|
128641
130520
|
const head = [
|
|
128642
130521
|
PRINT_FLAGS[0],
|
|
@@ -128772,14 +130651,14 @@ async function runPromptViaClaudeCode(model, prompt, systemPrompt, opts = {}) {
|
|
|
128772
130651
|
} catch (e) {
|
|
128773
130652
|
throw new Error(`cannot start claudish (${parentEnv.CLAUDISH_BIN?.trim() || "claudish"}): ${e instanceof Error ? e.message : String(e)}`);
|
|
128774
130653
|
}
|
|
128775
|
-
const root =
|
|
130654
|
+
const root = mkdtempSync5(join71(tmpdir4(), "claudish-run-prompt-"));
|
|
128776
130655
|
try {
|
|
128777
|
-
const cwd =
|
|
130656
|
+
const cwd = join71(root, "cwd");
|
|
128778
130657
|
mkdirSync28(cwd, { mode: 448 });
|
|
128779
130658
|
let systemPromptFile;
|
|
128780
130659
|
if (typeof systemPrompt === "string" && systemPrompt.length > 0) {
|
|
128781
|
-
systemPromptFile =
|
|
128782
|
-
|
|
130660
|
+
systemPromptFile = join71(root, "system-prompt.txt");
|
|
130661
|
+
writeFileSync29(systemPromptFile, systemPrompt, { mode: 384 });
|
|
128783
130662
|
}
|
|
128784
130663
|
const argv = claudeCodePrintArgv(model, systemPromptFile, {
|
|
128785
130664
|
subscriptionPin: opts.subscriptionPin === true
|
|
@@ -128809,14 +130688,14 @@ async function runPromptViaClaudeCode(model, prompt, systemPrompt, opts = {}) {
|
|
|
128809
130688
|
answer.auth = auth;
|
|
128810
130689
|
return answer;
|
|
128811
130690
|
} finally {
|
|
128812
|
-
|
|
130691
|
+
rmSync22(root, { recursive: true, force: true });
|
|
128813
130692
|
}
|
|
128814
130693
|
}
|
|
128815
130694
|
function runChild(launch, argv, cwd, env, prompt, signal) {
|
|
128816
130695
|
return new Promise((resolvePromise, reject) => {
|
|
128817
130696
|
let proc;
|
|
128818
130697
|
try {
|
|
128819
|
-
proc =
|
|
130698
|
+
proc = spawn5(launch.command, [...launch.prefixArgs, ...argv], {
|
|
128820
130699
|
cwd,
|
|
128821
130700
|
env,
|
|
128822
130701
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -128889,7 +130768,7 @@ var init_run_prompt_claude_code = __esm(() => {
|
|
|
128889
130768
|
ENV.CLAUDISH_PANE_CHILD
|
|
128890
130769
|
];
|
|
128891
130770
|
inFlight5 = new Set;
|
|
128892
|
-
EMPTY_PRINT_CWD =
|
|
130771
|
+
EMPTY_PRINT_CWD = join71(tmpdir4(), "claudish-run-prompt-settings-check");
|
|
128893
130772
|
});
|
|
128894
130773
|
|
|
128895
130774
|
// src/providers/bundled-list.ts
|
|
@@ -129887,14 +131766,14 @@ var init_view_server = __esm(() => {
|
|
|
129887
131766
|
});
|
|
129888
131767
|
|
|
129889
131768
|
// src/mcp-server.ts
|
|
129890
|
-
import { existsSync as existsSync45, readFileSync as
|
|
131769
|
+
import { existsSync as existsSync45, readFileSync as readFileSync55, readdirSync as readdirSync19 } from "fs";
|
|
129891
131770
|
import { homedir as homedir42 } from "os";
|
|
129892
|
-
import { dirname as
|
|
131771
|
+
import { dirname as dirname29, join as join72, resolve as resolve13 } from "path";
|
|
129893
131772
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
129894
131773
|
async function loadAllModels(forceRefresh = false) {
|
|
129895
131774
|
if (!forceRefresh && existsSync45(OPENROUTER_MODELS_CACHE_PATH)) {
|
|
129896
131775
|
try {
|
|
129897
|
-
const cacheData = JSON.parse(
|
|
131776
|
+
const cacheData = JSON.parse(readFileSync55(OPENROUTER_MODELS_CACHE_PATH, "utf-8"));
|
|
129898
131777
|
const lastUpdated = new Date(cacheData.lastUpdated);
|
|
129899
131778
|
const ageInDays = (Date.now() - lastUpdated.getTime()) / (1000 * 60 * 60 * 24);
|
|
129900
131779
|
if (ageInDays <= CACHE_MAX_AGE_DAYS) {
|
|
@@ -129914,7 +131793,7 @@ async function loadAllModels(forceRefresh = false) {
|
|
|
129914
131793
|
log(`[mcp] OpenRouter models fetch failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
129915
131794
|
try {
|
|
129916
131795
|
if (existsSync45(OPENROUTER_MODELS_CACHE_PATH)) {
|
|
129917
|
-
const cacheData = JSON.parse(
|
|
131796
|
+
const cacheData = JSON.parse(readFileSync55(OPENROUTER_MODELS_CACHE_PATH, "utf-8"));
|
|
129918
131797
|
return cacheData.models || [];
|
|
129919
131798
|
}
|
|
129920
131799
|
} catch (cacheErr) {
|
|
@@ -131355,7 +133234,7 @@ This searched OpenRouter's listing only. Subscription wire ids and catalog alias
|
|
|
131355
133234
|
let stderrFull = stderr_snippet || "";
|
|
131356
133235
|
if (error_log_path) {
|
|
131357
133236
|
try {
|
|
131358
|
-
stderrFull =
|
|
133237
|
+
stderrFull = readFileSync55(error_log_path, "utf-8");
|
|
131359
133238
|
} catch {}
|
|
131360
133239
|
}
|
|
131361
133240
|
const sessionData = {};
|
|
@@ -131363,26 +133242,26 @@ This searched OpenRouter's listing only. Subscription wire ids and catalog alias
|
|
|
131363
133242
|
const sp = session_path;
|
|
131364
133243
|
for (const file of ["status.json", "manifest.json", "input.md"]) {
|
|
131365
133244
|
try {
|
|
131366
|
-
sessionData[file] =
|
|
133245
|
+
sessionData[file] = readFileSync55(join72(sp, file), "utf-8");
|
|
131367
133246
|
} catch {}
|
|
131368
133247
|
}
|
|
131369
133248
|
try {
|
|
131370
|
-
const errorDir =
|
|
133249
|
+
const errorDir = join72(sp, "errors");
|
|
131371
133250
|
if (existsSync45(errorDir)) {
|
|
131372
|
-
for (const f of
|
|
133251
|
+
for (const f of readdirSync19(errorDir)) {
|
|
131373
133252
|
if (f.endsWith(".log")) {
|
|
131374
133253
|
try {
|
|
131375
|
-
sessionData[`errors/${f}`] =
|
|
133254
|
+
sessionData[`errors/${f}`] = readFileSync55(join72(errorDir, f), "utf-8");
|
|
131376
133255
|
} catch {}
|
|
131377
133256
|
}
|
|
131378
133257
|
}
|
|
131379
133258
|
}
|
|
131380
133259
|
} catch {}
|
|
131381
133260
|
try {
|
|
131382
|
-
for (const f of
|
|
133261
|
+
for (const f of readdirSync19(sp)) {
|
|
131383
133262
|
if (f.startsWith("response-") && f.endsWith(".md")) {
|
|
131384
133263
|
try {
|
|
131385
|
-
const content =
|
|
133264
|
+
const content = readFileSync55(join72(sp, f), "utf-8");
|
|
131386
133265
|
sessionData[f] = content.slice(0, 200) + (content.length > 200 ? "... (truncated)" : "");
|
|
131387
133266
|
} catch {}
|
|
131388
133267
|
}
|
|
@@ -131391,9 +133270,9 @@ This searched OpenRouter's listing only. Subscription wire ids and catalog alias
|
|
|
131391
133270
|
}
|
|
131392
133271
|
let version = "unknown";
|
|
131393
133272
|
try {
|
|
131394
|
-
const pkgPath =
|
|
133273
|
+
const pkgPath = join72(__dirname3, "../package.json");
|
|
131395
133274
|
if (existsSync45(pkgPath)) {
|
|
131396
|
-
version = JSON.parse(
|
|
133275
|
+
version = JSON.parse(readFileSync55(pkgPath, "utf-8")).version;
|
|
131397
133276
|
}
|
|
131398
133277
|
} catch {}
|
|
131399
133278
|
const report = {
|
|
@@ -131584,7 +133463,7 @@ Report manually at https://github.com/anthropics/claudish/issues${autoSendHint}`
|
|
|
131584
133463
|
const { specs, stripped } = strippedProviders([args.model], new Set(args.user_required_provider === true ? [args.model] : []));
|
|
131585
133464
|
const requestedModel = specs[0];
|
|
131586
133465
|
const choice = await modelChoiceStop([{ given: args.model, spec: requestedModel }], new Set(args.user_required_model === true ? [args.model] : []), "with user_required_model: true", {
|
|
131587
|
-
projectRulesReadable: typeof args.work_dir !== "string" ||
|
|
133466
|
+
projectRulesReadable: typeof args.work_dir !== "string" || resolve13(args.work_dir) === process.cwd()
|
|
131588
133467
|
});
|
|
131589
133468
|
if (choice)
|
|
131590
133469
|
return choice;
|
|
@@ -131594,7 +133473,7 @@ Report manually at https://github.com/anthropics/claudish/issues${autoSendHint}`
|
|
|
131594
133473
|
}
|
|
131595
133474
|
const workDir = args.work_dir;
|
|
131596
133475
|
const plan = await prehydrateCredentialsForSpawn([requestedModel], {
|
|
131597
|
-
pin: workDir === undefined ||
|
|
133476
|
+
pin: workDir === undefined || resolve13(workDir) === process.cwd()
|
|
131598
133477
|
});
|
|
131599
133478
|
const parentClaudeSessionId = await parentSessionForCall({
|
|
131600
133479
|
hostPid: sessionManager.hostPid
|
|
@@ -132011,6 +133890,7 @@ async function main() {
|
|
|
132011
133890
|
const viewFeed = new ViewFeed;
|
|
132012
133891
|
const viewClaims = new ViewClaims({ notify: (target) => viewFeed.changed(target, true) });
|
|
132013
133892
|
const sessionManager = new SessionManager({ feed: viewFeed, claims: viewClaims });
|
|
133893
|
+
sweepStaleProbeDirs();
|
|
132014
133894
|
replays.setViewServices({ feed: viewFeed, claims: viewClaims });
|
|
132015
133895
|
setViewServices({ feed: viewFeed, claims: viewClaims });
|
|
132016
133896
|
const progressIntervalMs = resolveProgressIntervalMs();
|
|
@@ -132161,6 +134041,7 @@ var init_mcp_server = __esm(() => {
|
|
|
132161
134041
|
init_mcp_session();
|
|
132162
134042
|
init_inherited_settings();
|
|
132163
134043
|
init_parent_session();
|
|
134044
|
+
init_plugin_probe();
|
|
132164
134045
|
init_nested_mode();
|
|
132165
134046
|
init_progress_heartbeat();
|
|
132166
134047
|
init_run_prompt_claude_code();
|
|
@@ -132195,9 +134076,9 @@ var init_mcp_server = __esm(() => {
|
|
|
132195
134076
|
init_view_server();
|
|
132196
134077
|
init_preflight_chain();
|
|
132197
134078
|
__filename3 = fileURLToPath3(import.meta.url);
|
|
132198
|
-
__dirname3 =
|
|
132199
|
-
CLAUDISH_CACHE_DIR =
|
|
132200
|
-
OPENROUTER_MODELS_CACHE_PATH =
|
|
134079
|
+
__dirname3 = dirname29(__filename3);
|
|
134080
|
+
CLAUDISH_CACHE_DIR = join72(homedir42(), ".claudish");
|
|
134081
|
+
OPENROUTER_MODELS_CACHE_PATH = join72(CLAUDISH_CACHE_DIR, "openrouter-models.json");
|
|
132201
134082
|
NEXT_STEP = {
|
|
132202
134083
|
cancelled: "you stopped this slot; nothing is wrong with it. Re-run it if you still want its vote",
|
|
132203
134084
|
timeout: "grid mode only \u2014 magmux ended the pane. The orchestrator has no deadline",
|
|
@@ -132224,7 +134105,7 @@ var init_mcp_server = __esm(() => {
|
|
|
132224
134105
|
});
|
|
132225
134106
|
|
|
132226
134107
|
// src/serve-command.ts
|
|
132227
|
-
import { existsSync as existsSync46, readFileSync as
|
|
134108
|
+
import { existsSync as existsSync46, readFileSync as readFileSync56 } from "fs";
|
|
132228
134109
|
function parseServeArgs(args) {
|
|
132229
134110
|
const out = {};
|
|
132230
134111
|
for (let i = 0;i < args.length; i++) {
|
|
@@ -132248,7 +134129,7 @@ function loadModelMap(path) {
|
|
|
132248
134129
|
}
|
|
132249
134130
|
let raw;
|
|
132250
134131
|
try {
|
|
132251
|
-
raw =
|
|
134132
|
+
raw = readFileSync56(path, "utf-8");
|
|
132252
134133
|
} catch (e) {
|
|
132253
134134
|
throw new Error(`failed to read --models file ${path}: ${e instanceof Error ? e.message : String(e)}`);
|
|
132254
134135
|
}
|
|
@@ -132359,9 +134240,9 @@ var init_serve_command = __esm(() => {
|
|
|
132359
134240
|
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';
|
|
132360
134241
|
|
|
132361
134242
|
// src/hooks/observer/corpus.ts
|
|
132362
|
-
import { appendFileSync as appendFileSync8, readFileSync as
|
|
134243
|
+
import { appendFileSync as appendFileSync8, readFileSync as readFileSync57, readdirSync as readdirSync20, statSync as statSync31 } from "fs";
|
|
132363
134244
|
import { homedir as homedir43 } from "os";
|
|
132364
|
-
import { join as
|
|
134245
|
+
import { join as join73 } from "path";
|
|
132365
134246
|
function directoryOf2(filePath) {
|
|
132366
134247
|
const slash = filePath.lastIndexOf("/");
|
|
132367
134248
|
return slash > 0 ? filePath.slice(0, slash) : undefined;
|
|
@@ -132383,7 +134264,7 @@ function writeTargetsOf(row) {
|
|
|
132383
134264
|
function replayTranscript(file) {
|
|
132384
134265
|
let text;
|
|
132385
134266
|
try {
|
|
132386
|
-
text =
|
|
134267
|
+
text = readFileSync57(file, "utf8");
|
|
132387
134268
|
} catch {
|
|
132388
134269
|
return [];
|
|
132389
134270
|
}
|
|
@@ -132435,18 +134316,18 @@ function listTranscripts(root) {
|
|
|
132435
134316
|
const files = [];
|
|
132436
134317
|
let projects;
|
|
132437
134318
|
try {
|
|
132438
|
-
projects =
|
|
134319
|
+
projects = readdirSync20(root);
|
|
132439
134320
|
} catch {
|
|
132440
134321
|
return files;
|
|
132441
134322
|
}
|
|
132442
134323
|
for (const project of projects) {
|
|
132443
|
-
const dir =
|
|
134324
|
+
const dir = join73(root, project);
|
|
132444
134325
|
try {
|
|
132445
|
-
if (!
|
|
134326
|
+
if (!statSync31(dir).isDirectory())
|
|
132446
134327
|
continue;
|
|
132447
|
-
for (const f of
|
|
134328
|
+
for (const f of readdirSync20(dir)) {
|
|
132448
134329
|
if (f.endsWith(".jsonl"))
|
|
132449
|
-
files.push(
|
|
134330
|
+
files.push(join73(dir, f));
|
|
132450
134331
|
}
|
|
132451
134332
|
} catch {}
|
|
132452
134333
|
}
|
|
@@ -132459,7 +134340,7 @@ function buildCorpus(options = {}) {
|
|
|
132459
134340
|
for (const f of files)
|
|
132460
134341
|
records.push(...replayTranscript(f));
|
|
132461
134342
|
if (options.write && records.length > 0) {
|
|
132462
|
-
const outputPath = options.outputPath ??
|
|
134343
|
+
const outputPath = options.outputPath ?? join73(homedir43(), ".claudish", "behavior-divergences.jsonl");
|
|
132463
134344
|
try {
|
|
132464
134345
|
appendFileSync8(outputPath, `${records.map((r) => JSON.stringify(r)).join(`
|
|
132465
134346
|
`)}
|
|
@@ -132476,9 +134357,9 @@ var init_corpus = __esm(() => {
|
|
|
132476
134357
|
});
|
|
132477
134358
|
|
|
132478
134359
|
// src/hooks-command.ts
|
|
132479
|
-
import { existsSync as existsSync47, mkdirSync as mkdirSync29, readFileSync as
|
|
134360
|
+
import { existsSync as existsSync47, mkdirSync as mkdirSync29, readFileSync as readFileSync58, writeFileSync as writeFileSync30 } from "fs";
|
|
132480
134361
|
import { homedir as homedir44 } from "os";
|
|
132481
|
-
import { join as
|
|
134362
|
+
import { join as join74, resolve as resolve14 } from "path";
|
|
132482
134363
|
function severityColor(sev) {
|
|
132483
134364
|
if (sev === "fix")
|
|
132484
134365
|
return green(sev);
|
|
@@ -132568,7 +134449,7 @@ async function check(file, json) {
|
|
|
132568
134449
|
console.error("Usage: claudish hooks check <file> [--json]");
|
|
132569
134450
|
return 1;
|
|
132570
134451
|
}
|
|
132571
|
-
const path =
|
|
134452
|
+
const path = resolve14(process.cwd(), file);
|
|
132572
134453
|
const notes = [];
|
|
132573
134454
|
const loaded = await loadUserHooks({
|
|
132574
134455
|
modules: [path],
|
|
@@ -132601,10 +134482,10 @@ async function check(file, json) {
|
|
|
132601
134482
|
return valid ? 0 : 1;
|
|
132602
134483
|
}
|
|
132603
134484
|
function init(dirArg) {
|
|
132604
|
-
const dir = dirArg ?
|
|
134485
|
+
const dir = dirArg ? resolve14(process.cwd(), dirArg) : join74(homedir44(), ".claudish", "hooks");
|
|
132605
134486
|
const files = [
|
|
132606
|
-
[
|
|
132607
|
-
[
|
|
134487
|
+
[join74(dir, "example-hook.ts"), EXAMPLE_HOOK],
|
|
134488
|
+
[join74(dir, "claudish-hooks.d.ts"), HOOKS_AMBIENT_DTS]
|
|
132608
134489
|
];
|
|
132609
134490
|
const existing = files.filter(([path]) => existsSync47(path)).map(([path]) => path);
|
|
132610
134491
|
if (existing.length > 0) {
|
|
@@ -132614,7 +134495,7 @@ function init(dirArg) {
|
|
|
132614
134495
|
}
|
|
132615
134496
|
mkdirSync29(dir, { recursive: true });
|
|
132616
134497
|
for (const [path, text] of files)
|
|
132617
|
-
|
|
134498
|
+
writeFileSync30(path, text, { flag: "wx" });
|
|
132618
134499
|
console.log(`
|
|
132619
134500
|
wrote ${files.map(([p]) => p).join(`
|
|
132620
134501
|
wrote `)}
|
|
@@ -132697,7 +134578,7 @@ function telemetry(action, json) {
|
|
|
132697
134578
|
try {
|
|
132698
134579
|
const path = outboxPath();
|
|
132699
134580
|
if (existsSync47(path))
|
|
132700
|
-
pending =
|
|
134581
|
+
pending = readFileSync58(path, "utf8").split(`
|
|
132701
134582
|
`).filter(Boolean).length;
|
|
132702
134583
|
} catch {}
|
|
132703
134584
|
if (json) {
|
|
@@ -132804,10 +134685,10 @@ var init_hooks_command = __esm(() => {
|
|
|
132804
134685
|
});
|
|
132805
134686
|
|
|
132806
134687
|
// src/team-grid.ts
|
|
132807
|
-
import { spawn as
|
|
132808
|
-
import { existsSync as existsSync48, readFileSync as
|
|
134688
|
+
import { spawn as spawn6 } from "child_process";
|
|
134689
|
+
import { existsSync as existsSync48, readFileSync as readFileSync59, writeFileSync as writeFileSync31 } from "fs";
|
|
132809
134690
|
import { connect as netConnect3 } from "net";
|
|
132810
|
-
import { join as
|
|
134691
|
+
import { join as join75 } from "path";
|
|
132811
134692
|
import { setTimeout as wait } from "timers/promises";
|
|
132812
134693
|
function paneRouteLine(explanation) {
|
|
132813
134694
|
const origin = describeRouteExplanation(explanation);
|
|
@@ -132957,9 +134838,9 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
132957
134838
|
const keep = opts?.keep ?? false;
|
|
132958
134839
|
const manifest = setupSession(sessionPath, models, input);
|
|
132959
134840
|
const startedAt = new Date().toISOString();
|
|
132960
|
-
const gridfilePath =
|
|
132961
|
-
const prompt =
|
|
132962
|
-
const rawPrompt =
|
|
134841
|
+
const gridfilePath = join75(sessionPath, "gridfile.txt");
|
|
134842
|
+
const prompt = readFileSync59(join75(sessionPath, "input.md"), "utf-8").replace(/'/g, "'\\''").replace(/\n/g, " ");
|
|
134843
|
+
const rawPrompt = readFileSync59(join75(sessionPath, "input.md"), "utf-8");
|
|
132963
134844
|
const usedBannerColors = new Set;
|
|
132964
134845
|
const routeLines = mode === "interactive" ? new Map : await resolvePaneRouteLines(Object.values(manifest.models).map((entry) => entry.model));
|
|
132965
134846
|
const gridLines = Object.entries(manifest.models).map(([anonId]) => {
|
|
@@ -132971,7 +134852,7 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
132971
134852
|
const header = buildPaneHeader(model, routeLines.get(model) ?? "", rawPrompt, bg);
|
|
132972
134853
|
return `${header} claudish --model ${model} -y --quiet '${prompt}'`;
|
|
132973
134854
|
});
|
|
132974
|
-
|
|
134855
|
+
writeFileSync31(gridfilePath, `${gridLines.join(`
|
|
132975
134856
|
`)}
|
|
132976
134857
|
`, "utf-8");
|
|
132977
134858
|
const magmuxPath = findMagmuxBinary();
|
|
@@ -132979,7 +134860,7 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
132979
134860
|
if (!keep && mode === "default") {
|
|
132980
134861
|
spawnArgs.push("-w");
|
|
132981
134862
|
}
|
|
132982
|
-
const proc =
|
|
134863
|
+
const proc = spawn6(magmuxPath, spawnArgs, {
|
|
132983
134864
|
stdio: "inherit",
|
|
132984
134865
|
env: { ...process.env }
|
|
132985
134866
|
});
|
|
@@ -132991,8 +134872,8 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
132991
134872
|
});
|
|
132992
134873
|
const [{ results }] = await Promise.all([subscription, procExit]);
|
|
132993
134874
|
const status = buildTeamStatus(manifest, startedAt, results?.panes ?? null);
|
|
132994
|
-
const statusPath =
|
|
132995
|
-
|
|
134875
|
+
const statusPath = join75(sessionPath, "status.json");
|
|
134876
|
+
writeFileSync31(statusPath, JSON.stringify(status, null, 2), "utf-8");
|
|
132996
134877
|
return status;
|
|
132997
134878
|
}
|
|
132998
134879
|
var BANNER_BG_COLORS;
|
|
@@ -133011,8 +134892,8 @@ var init_team_grid = __esm(() => {
|
|
|
133011
134892
|
});
|
|
133012
134893
|
|
|
133013
134894
|
// src/team-cli.ts
|
|
133014
|
-
import { readFileSync as
|
|
133015
|
-
import { join as
|
|
134895
|
+
import { readFileSync as readFileSync60 } from "fs";
|
|
134896
|
+
import { join as join76 } from "path";
|
|
133016
134897
|
async function runPaneTeam(sessionPath, models, input, opts) {
|
|
133017
134898
|
installPaneShutdownHooks({ exitAfter: true });
|
|
133018
134899
|
try {
|
|
@@ -133157,7 +135038,7 @@ async function teamCommand(args) {
|
|
|
133157
135038
|
}
|
|
133158
135039
|
case "judge": {
|
|
133159
135040
|
await judgeResponses(sessionPath, { judges });
|
|
133160
|
-
console.log(
|
|
135041
|
+
console.log(readFileSync60(join76(sessionPath, "verdict.md"), "utf-8"));
|
|
133161
135042
|
break;
|
|
133162
135043
|
}
|
|
133163
135044
|
case "run-and-judge": {
|
|
@@ -133173,7 +135054,7 @@ async function teamCommand(args) {
|
|
|
133173
135054
|
});
|
|
133174
135055
|
printStatus(status);
|
|
133175
135056
|
await judgeResponses(sessionPath, { judges });
|
|
133176
|
-
console.log(
|
|
135057
|
+
console.log(readFileSync60(join76(sessionPath, "verdict.md"), "utf-8"));
|
|
133177
135058
|
break;
|
|
133178
135059
|
}
|
|
133179
135060
|
case "status": {
|
|
@@ -134855,12 +136736,12 @@ var init_view_cli = __esm(() => {
|
|
|
134855
136736
|
});
|
|
134856
136737
|
|
|
134857
136738
|
// src/herdr/herdr-cli.ts
|
|
134858
|
-
import { spawnSync as
|
|
134859
|
-
import { copyFileSync as copyFileSync3, existsSync as existsSync49, mkdirSync as mkdirSync30, readdirSync as
|
|
136739
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
136740
|
+
import { copyFileSync as copyFileSync3, existsSync as existsSync49, mkdirSync as mkdirSync30, readdirSync as readdirSync21, renameSync as renameSync14, statSync as statSync32 } from "fs";
|
|
134860
136741
|
import { homedir as homedir45 } from "os";
|
|
134861
|
-
import { dirname as
|
|
136742
|
+
import { dirname as dirname30, join as join77, resolve as resolve15 } from "path";
|
|
134862
136743
|
function spawnHerdrApp(args) {
|
|
134863
|
-
const r =
|
|
136744
|
+
const r = spawnSync4("herdr-app", args, { encoding: "utf-8", timeout: 1e4 });
|
|
134864
136745
|
if (r.error)
|
|
134865
136746
|
return null;
|
|
134866
136747
|
return { code: r.status, stdout: r.stdout, stderr: r.stderr };
|
|
@@ -134900,10 +136781,10 @@ function showPanelCommand(rest, out, deps) {
|
|
|
134900
136781
|
function findBuiltAppMod(from = import.meta.dir) {
|
|
134901
136782
|
let dir = from;
|
|
134902
136783
|
for (let i = 0;i < 5; i++) {
|
|
134903
|
-
const candidate =
|
|
134904
|
-
if (existsSync49(
|
|
136784
|
+
const candidate = join77(dir, BUILT_MOD_DIR);
|
|
136785
|
+
if (existsSync49(join77(candidate, "main.js")) && existsSync49(join77(candidate, "mod.json")))
|
|
134905
136786
|
return candidate;
|
|
134906
|
-
const up =
|
|
136787
|
+
const up = dirname30(dir);
|
|
134907
136788
|
if (up === dir)
|
|
134908
136789
|
break;
|
|
134909
136790
|
dir = up;
|
|
@@ -134913,25 +136794,25 @@ function findBuiltAppMod(from = import.meta.dir) {
|
|
|
134913
136794
|
function herdrAppHome(env) {
|
|
134914
136795
|
const given = env.HERDR_APP_HOME?.trim();
|
|
134915
136796
|
if (given)
|
|
134916
|
-
return
|
|
134917
|
-
return
|
|
136797
|
+
return resolve15(given);
|
|
136798
|
+
return join77(env.HOME?.trim() || homedir45(), ".config", "herdr-app");
|
|
134918
136799
|
}
|
|
134919
136800
|
function isModFile(name) {
|
|
134920
136801
|
return !name.startsWith(".") && name !== "jsconfig.json" && !name.endsWith(".d.ts");
|
|
134921
136802
|
}
|
|
134922
136803
|
function installAppMod(source, appHome) {
|
|
134923
|
-
if (!existsSync49(
|
|
136804
|
+
if (!existsSync49(join77(source, "main.js")) || !existsSync49(join77(source, "mod.json")))
|
|
134924
136805
|
throw new Error(`${source} holds no built mod (main.js and mod.json); run \`bun run build\``);
|
|
134925
|
-
if (!existsSync49(appHome) || !
|
|
136806
|
+
if (!existsSync49(appHome) || !statSync32(appHome).isDirectory())
|
|
134926
136807
|
throw new Error(`${appHome} does not exist: start Herdr.app once so it creates its home, then run this again`);
|
|
134927
|
-
const dest =
|
|
136808
|
+
const dest = join77(appHome, "mods", APP_MOD_NAME);
|
|
134928
136809
|
mkdirSync30(dest, { recursive: true });
|
|
134929
|
-
const files =
|
|
136810
|
+
const files = readdirSync21(source).filter((f) => isModFile(f) && statSync32(join77(source, f)).isFile());
|
|
134930
136811
|
files.sort((a, b) => a === "mod.json" ? -1 : b === "mod.json" ? 1 : a.localeCompare(b));
|
|
134931
136812
|
for (const f of files) {
|
|
134932
|
-
const hidden =
|
|
134933
|
-
copyFileSync3(
|
|
134934
|
-
renameSync14(hidden,
|
|
136813
|
+
const hidden = join77(dest, `.${f}.installing`);
|
|
136814
|
+
copyFileSync3(join77(source, f), hidden);
|
|
136815
|
+
renameSync14(hidden, join77(dest, f));
|
|
134935
136816
|
}
|
|
134936
136817
|
return dest;
|
|
134937
136818
|
}
|
|
@@ -134939,7 +136820,7 @@ function installCommand(rest, out, deps) {
|
|
|
134939
136820
|
const err = deps.err ?? ((s) => process.stderr.write(s));
|
|
134940
136821
|
let from;
|
|
134941
136822
|
if (rest[0] === "--from" && rest[1] && rest.length === 2)
|
|
134942
|
-
from =
|
|
136823
|
+
from = resolve15(rest[1]);
|
|
134943
136824
|
else if (rest.length > 0) {
|
|
134944
136825
|
err(USAGE4);
|
|
134945
136826
|
return 2;
|
|
@@ -135009,7 +136890,7 @@ var init_herdr_cli = __esm(() => {
|
|
|
135009
136890
|
""
|
|
135010
136891
|
].join(`
|
|
135011
136892
|
`);
|
|
135012
|
-
BUILT_MOD_DIR =
|
|
136893
|
+
BUILT_MOD_DIR = join77("herdr-app-mod", APP_MOD_NAME);
|
|
135013
136894
|
});
|
|
135014
136895
|
|
|
135015
136896
|
// src/auth/credentials/source.ts
|
|
@@ -137240,10 +139121,10 @@ var init_account_command = __esm(() => {
|
|
|
137240
139121
|
});
|
|
137241
139122
|
|
|
137242
139123
|
// src/auth/antigravity-oauth.ts
|
|
137243
|
-
import { spawnSync as
|
|
139124
|
+
import { spawnSync as spawnSync5 } from "child_process";
|
|
137244
139125
|
import { existsSync as existsSync50, unlinkSync as unlinkSync14 } from "fs";
|
|
137245
139126
|
import { homedir as homedir46 } from "os";
|
|
137246
|
-
import { join as
|
|
139127
|
+
import { join as join78 } from "path";
|
|
137247
139128
|
async function defaultSuggestModel() {
|
|
137248
139129
|
try {
|
|
137249
139130
|
const token = await getValidAntigravityAccessToken();
|
|
@@ -137267,14 +139148,14 @@ async function defaultConfirmInstall() {
|
|
|
137267
139148
|
});
|
|
137268
139149
|
}
|
|
137269
139150
|
function defaultRunInstall() {
|
|
137270
|
-
const res =
|
|
139151
|
+
const res = spawnSync5("bash", ["-c", INSTALL_CMD], { stdio: "inherit" });
|
|
137271
139152
|
return !res.error && res.status === 0;
|
|
137272
139153
|
}
|
|
137273
139154
|
function defaultRunAgyAuth(agyPath, interactive) {
|
|
137274
139155
|
if (interactive) {
|
|
137275
|
-
|
|
139156
|
+
spawnSync5(agyPath, [], { stdio: "inherit" });
|
|
137276
139157
|
} else {
|
|
137277
|
-
|
|
139158
|
+
spawnSync5(agyPath, ["-p", "hello", "--print-timeout", "3m"], { stdio: "inherit" });
|
|
137278
139159
|
}
|
|
137279
139160
|
}
|
|
137280
139161
|
async function pollForToken(deps) {
|
|
@@ -137362,7 +139243,7 @@ No session detected yet. Starting the Antigravity CLI interactively \u2014
|
|
|
137362
139243
|
async logout(deps) {
|
|
137363
139244
|
deleteSharedAntigravityToken(deps);
|
|
137364
139245
|
try {
|
|
137365
|
-
const tokenFile =
|
|
139246
|
+
const tokenFile = join78(homedir46(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
137366
139247
|
if (existsSync50(tokenFile))
|
|
137367
139248
|
unlinkSync14(tokenFile);
|
|
137368
139249
|
} catch {}
|
|
@@ -145577,7 +147458,7 @@ __export(exports_tui, {
|
|
|
145577
147458
|
loginCommand: () => loginCommand2,
|
|
145578
147459
|
startConfigTui: () => startConfigTui
|
|
145579
147460
|
});
|
|
145580
|
-
import { spawnSync as
|
|
147461
|
+
import { spawnSync as spawnSync6 } from "child_process";
|
|
145581
147462
|
import { createCliRenderer as createCliRenderer3 } from "@opentui/core";
|
|
145582
147463
|
import { createRoot as createRoot3 } from "@opentui/react";
|
|
145583
147464
|
import { jsxDEV as jsxDEV28 } from "@opentui/react/jsx-dev-runtime";
|
|
@@ -145620,13 +147501,13 @@ Launching: ${command}
|
|
|
145620
147501
|
`);
|
|
145621
147502
|
let result;
|
|
145622
147503
|
if (action.kind === "gcloud-adc") {
|
|
145623
|
-
result =
|
|
147504
|
+
result = spawnSync6(gcloudCommand(process.platform), ["auth", "application-default", "login"], {
|
|
145624
147505
|
stdio: "inherit",
|
|
145625
147506
|
shell: process.platform === "win32"
|
|
145626
147507
|
});
|
|
145627
147508
|
} else {
|
|
145628
147509
|
const login = loginCommand2(action.slug, process.execPath, process.argv[1], getConfigFileOverride());
|
|
145629
|
-
result =
|
|
147510
|
+
result = spawnSync6(login.command, login.args, { stdio: "inherit" });
|
|
145630
147511
|
}
|
|
145631
147512
|
if (result.error) {
|
|
145632
147513
|
if (action.kind === "gcloud-adc" && result.error.code === "ENOENT") {
|
|
@@ -146268,18 +148149,18 @@ var init_model_lineup = __esm(() => {
|
|
|
146268
148149
|
});
|
|
146269
148150
|
|
|
146270
148151
|
// src/diag-output.ts
|
|
146271
|
-
import { createWriteStream as createWriteStream2, mkdirSync as mkdirSync31, unlinkSync as unlinkSync15, writeFileSync as
|
|
148152
|
+
import { createWriteStream as createWriteStream2, mkdirSync as mkdirSync31, unlinkSync as unlinkSync15, writeFileSync as writeFileSync32 } from "fs";
|
|
146272
148153
|
import { homedir as homedir47 } from "os";
|
|
146273
|
-
import { join as
|
|
148154
|
+
import { join as join79 } from "path";
|
|
146274
148155
|
function getClaudishDir() {
|
|
146275
|
-
const dir =
|
|
148156
|
+
const dir = join79(homedir47(), ".claudish");
|
|
146276
148157
|
try {
|
|
146277
148158
|
mkdirSync31(dir, { recursive: true });
|
|
146278
148159
|
} catch {}
|
|
146279
148160
|
return dir;
|
|
146280
148161
|
}
|
|
146281
148162
|
function getDiagLogPath() {
|
|
146282
|
-
return
|
|
148163
|
+
return join79(getClaudishDir(), `diag-${process.pid}.log`);
|
|
146283
148164
|
}
|
|
146284
148165
|
|
|
146285
148166
|
class LogFileDiagOutput {
|
|
@@ -146288,7 +148169,7 @@ class LogFileDiagOutput {
|
|
|
146288
148169
|
constructor() {
|
|
146289
148170
|
this.logPath = getDiagLogPath();
|
|
146290
148171
|
try {
|
|
146291
|
-
|
|
148172
|
+
writeFileSync32(this.logPath, `--- claudish diag session ${new Date().toISOString()} ---
|
|
146292
148173
|
`);
|
|
146293
148174
|
} catch {}
|
|
146294
148175
|
this.stream = createWriteStream2(this.logPath, { flags: "a" });
|
|
@@ -146690,7 +148571,7 @@ var init_advisor_startup = __esm(() => {
|
|
|
146690
148571
|
});
|
|
146691
148572
|
|
|
146692
148573
|
// src/session/conversation.ts
|
|
146693
|
-
import { closeSync as
|
|
148574
|
+
import { closeSync as closeSync23, openSync as openSync22, readSync as readSync11, statSync as statSync33 } from "fs";
|
|
146694
148575
|
import { StringDecoder } from "string_decoder";
|
|
146695
148576
|
function looksLikeTurn(line) {
|
|
146696
148577
|
const assistant = line.includes('"type":"assistant"');
|
|
@@ -146745,8 +148626,8 @@ function readConversation(file, opts = {}) {
|
|
|
146745
148626
|
};
|
|
146746
148627
|
let fd = null;
|
|
146747
148628
|
try {
|
|
146748
|
-
const size =
|
|
146749
|
-
fd =
|
|
148629
|
+
const size = statSync33(file).size;
|
|
148630
|
+
fd = openSync22(file, "r");
|
|
146750
148631
|
const buf = Buffer.allocUnsafe(chunkBytes);
|
|
146751
148632
|
const decoder = new StringDecoder("utf-8");
|
|
146752
148633
|
let pending = "";
|
|
@@ -146778,7 +148659,7 @@ function readConversation(file, opts = {}) {
|
|
|
146778
148659
|
take({ role: raw.role, text, elided });
|
|
146779
148660
|
};
|
|
146780
148661
|
while (pos < size) {
|
|
146781
|
-
const n =
|
|
148662
|
+
const n = readSync11(fd, buf, 0, Math.min(chunkBytes, size - pos), pos);
|
|
146782
148663
|
if (n <= 0)
|
|
146783
148664
|
break;
|
|
146784
148665
|
pos += n;
|
|
@@ -146802,7 +148683,7 @@ function readConversation(file, opts = {}) {
|
|
|
146802
148683
|
} catch {} finally {
|
|
146803
148684
|
if (fd !== null) {
|
|
146804
148685
|
try {
|
|
146805
|
-
|
|
148686
|
+
closeSync23(fd);
|
|
146806
148687
|
} catch {}
|
|
146807
148688
|
}
|
|
146808
148689
|
}
|
|
@@ -148371,10 +150252,10 @@ var init_resume_picker_run = __esm(() => {
|
|
|
148371
150252
|
|
|
148372
150253
|
// src/launcher/model-setting-ledger-path.ts
|
|
148373
150254
|
import { homedir as homedir48 } from "os";
|
|
148374
|
-
import { join as
|
|
150255
|
+
import { join as join80 } from "path";
|
|
148375
150256
|
function modelSettingLedgerPath(env = process.env) {
|
|
148376
150257
|
const home = env.HOME && env.HOME.length > 0 ? env.HOME : homedir48();
|
|
148377
|
-
return
|
|
150258
|
+
return join80(home, ".claudish", MODEL_SETTING_LEDGER_FILE);
|
|
148378
150259
|
}
|
|
148379
150260
|
var MODEL_SETTING_LEDGER_FILE = "model-setting-restore.json";
|
|
148380
150261
|
var init_model_setting_ledger_path = () => {};
|
|
@@ -148382,32 +150263,32 @@ var init_model_setting_ledger_path = () => {};
|
|
|
148382
150263
|
// src/launcher/model-setting-restore.ts
|
|
148383
150264
|
import { randomUUID as randomUUID12 } from "crypto";
|
|
148384
150265
|
import {
|
|
148385
|
-
closeSync as
|
|
150266
|
+
closeSync as closeSync24,
|
|
148386
150267
|
fchmodSync as fchmodSync2,
|
|
148387
150268
|
fsyncSync as fsyncSync4,
|
|
148388
|
-
openSync as
|
|
148389
|
-
readFileSync as
|
|
148390
|
-
readdirSync as
|
|
148391
|
-
realpathSync as
|
|
150269
|
+
openSync as openSync23,
|
|
150270
|
+
readFileSync as readFileSync61,
|
|
150271
|
+
readdirSync as readdirSync22,
|
|
150272
|
+
realpathSync as realpathSync13,
|
|
148392
150273
|
renameSync as renameSync15,
|
|
148393
|
-
rmSync as
|
|
148394
|
-
statSync as
|
|
150274
|
+
rmSync as rmSync23,
|
|
150275
|
+
statSync as statSync34,
|
|
148395
150276
|
unlinkSync as unlinkSync16,
|
|
148396
150277
|
writeSync as writeSync8
|
|
148397
150278
|
} from "fs";
|
|
148398
150279
|
import { homedir as homedir49 } from "os";
|
|
148399
|
-
import { basename as
|
|
150280
|
+
import { basename as basename13, dirname as dirname31, join as join81, resolve as resolve16 } from "path";
|
|
148400
150281
|
function canonicalSettingsPath(path) {
|
|
148401
|
-
let head =
|
|
150282
|
+
let head = resolve16(path);
|
|
148402
150283
|
const rest = [];
|
|
148403
150284
|
for (;; ) {
|
|
148404
150285
|
try {
|
|
148405
|
-
return
|
|
150286
|
+
return join81(realpathSync13.native(head), ...rest);
|
|
148406
150287
|
} catch {
|
|
148407
|
-
const parent =
|
|
150288
|
+
const parent = dirname31(head);
|
|
148408
150289
|
if (parent === head)
|
|
148409
|
-
return
|
|
148410
|
-
rest.unshift(
|
|
150290
|
+
return join81(head, ...rest);
|
|
150291
|
+
rest.unshift(basename13(head));
|
|
148411
150292
|
head = parent;
|
|
148412
150293
|
}
|
|
148413
150294
|
}
|
|
@@ -148446,7 +150327,7 @@ function detectIndent(text) {
|
|
|
148446
150327
|
const m = text.match(/^\{\s*?\n([ \t]+)\S/);
|
|
148447
150328
|
return m?.[1] ? m[1] : 2;
|
|
148448
150329
|
}
|
|
148449
|
-
function
|
|
150330
|
+
function isPlainObject9(value) {
|
|
148450
150331
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
148451
150332
|
}
|
|
148452
150333
|
function restoreSettingsFile(settingsKey, entry, deps = realRestoreFs, fence = () => true) {
|
|
@@ -148470,7 +150351,7 @@ function nextSettingsText(text, entry) {
|
|
|
148470
150351
|
} catch {
|
|
148471
150352
|
return { outcome: "unparsable" };
|
|
148472
150353
|
}
|
|
148473
|
-
if (!
|
|
150354
|
+
if (!isPlainObject9(parsed))
|
|
148474
150355
|
return { outcome: "unparsable" };
|
|
148475
150356
|
const decision = restoreDecision(parsed.model, entry);
|
|
148476
150357
|
if (decision.action === "leave")
|
|
@@ -148502,7 +150383,7 @@ function restoreRound(settingsKey, target, entry, deps, fence) {
|
|
|
148502
150383
|
const planned = nextSettingsText(text, entry);
|
|
148503
150384
|
if ("outcome" in planned)
|
|
148504
150385
|
return planned.outcome;
|
|
148505
|
-
const temp =
|
|
150386
|
+
const temp = join81(dirname31(target), `${TEMP_PREFIX}${deps.pid ?? process.pid}-${randomUUID12()}`);
|
|
148506
150387
|
try {
|
|
148507
150388
|
deps.writeNew(temp, planned.next, statA.mode & 4095);
|
|
148508
150389
|
} catch {
|
|
@@ -148535,7 +150416,7 @@ function restoreRound(settingsKey, target, entry, deps, fence) {
|
|
|
148535
150416
|
function readLedger2(path) {
|
|
148536
150417
|
let text;
|
|
148537
150418
|
try {
|
|
148538
|
-
text =
|
|
150419
|
+
text = readFileSync61(path, "utf8");
|
|
148539
150420
|
} catch (err) {
|
|
148540
150421
|
if (errnoOf(err) === "ENOENT")
|
|
148541
150422
|
return { ok: true, ledger: { version: 1, entries: {} } };
|
|
@@ -148549,7 +150430,7 @@ function readLedger2(path) {
|
|
|
148549
150430
|
log(`[model-restore] ledger unparsable (${path}): ${err.message}`);
|
|
148550
150431
|
return { ok: false, reason: "unparsable" };
|
|
148551
150432
|
}
|
|
148552
|
-
if (parsed?.version !== 1 || !
|
|
150433
|
+
if (parsed?.version !== 1 || !isPlainObject9(parsed.entries)) {
|
|
148553
150434
|
log(`[model-restore] ledger of unknown shape (${path})`);
|
|
148554
150435
|
return { ok: false, reason: "unknown-shape" };
|
|
148555
150436
|
}
|
|
@@ -148568,7 +150449,7 @@ function writeLedger(path, ledger, fence) {
|
|
|
148568
150449
|
return false;
|
|
148569
150450
|
}
|
|
148570
150451
|
if (Object.keys(ledger.entries).length === 0) {
|
|
148571
|
-
|
|
150452
|
+
rmSync23(path, { force: true });
|
|
148572
150453
|
return true;
|
|
148573
150454
|
}
|
|
148574
150455
|
atomicWriteFileSync(path, `${JSON.stringify(ledger, null, 2)}
|
|
@@ -148673,14 +150554,14 @@ function settleEntry(ctx, ledger, key, silent, fence) {
|
|
|
148673
150554
|
}
|
|
148674
150555
|
}
|
|
148675
150556
|
function removeOrphanTemps(ctx, key, table) {
|
|
148676
|
-
const dirs = new Set([
|
|
150557
|
+
const dirs = new Set([dirname31(key)]);
|
|
148677
150558
|
try {
|
|
148678
|
-
dirs.add(
|
|
150559
|
+
dirs.add(dirname31(ctx.fs.realpath(key)));
|
|
148679
150560
|
} catch {}
|
|
148680
150561
|
for (const dir of dirs) {
|
|
148681
150562
|
let names;
|
|
148682
150563
|
try {
|
|
148683
|
-
names =
|
|
150564
|
+
names = readdirSync22(dir);
|
|
148684
150565
|
} catch {
|
|
148685
150566
|
continue;
|
|
148686
150567
|
}
|
|
@@ -148694,7 +150575,7 @@ function removeOrphanTemps(ctx, key, table) {
|
|
|
148694
150575
|
if (live)
|
|
148695
150576
|
continue;
|
|
148696
150577
|
try {
|
|
148697
|
-
unlinkSync16(
|
|
150578
|
+
unlinkSync16(join81(dir, name));
|
|
148698
150579
|
} catch {}
|
|
148699
150580
|
}
|
|
148700
150581
|
}
|
|
@@ -148772,7 +150653,7 @@ function readOriginal(ctx, key) {
|
|
|
148772
150653
|
}
|
|
148773
150654
|
try {
|
|
148774
150655
|
const parsed = JSON.parse(text);
|
|
148775
|
-
if (!
|
|
150656
|
+
if (!isPlainObject9(parsed))
|
|
148776
150657
|
return null;
|
|
148777
150658
|
return "model" in parsed ? { present: true, value: parsed.model } : { present: false };
|
|
148778
150659
|
} catch {
|
|
@@ -148948,17 +150829,17 @@ var init_model_setting_restore = __esm(() => {
|
|
|
148948
150829
|
init_model_setting_ledger_path();
|
|
148949
150830
|
GIVE_UP_AFTER_MS = 14 * 24 * 60 * 60 * 1000;
|
|
148950
150831
|
realRestoreFs = {
|
|
148951
|
-
realpath: (path) =>
|
|
148952
|
-
readFile: (path) =>
|
|
148953
|
-
stat: (path) => toFileStat(
|
|
150832
|
+
realpath: (path) => realpathSync13.native(path),
|
|
150833
|
+
readFile: (path) => readFileSync61(path),
|
|
150834
|
+
stat: (path) => toFileStat(statSync34(path)),
|
|
148954
150835
|
writeNew: (path, data, mode) => {
|
|
148955
|
-
const fd =
|
|
150836
|
+
const fd = openSync23(path, "wx", mode);
|
|
148956
150837
|
try {
|
|
148957
150838
|
fchmodSync2(fd, mode);
|
|
148958
150839
|
writeWholeSync(fd, data);
|
|
148959
150840
|
fsyncSync4(fd);
|
|
148960
150841
|
} finally {
|
|
148961
|
-
|
|
150842
|
+
closeSync24(fd);
|
|
148962
150843
|
}
|
|
148963
150844
|
},
|
|
148964
150845
|
rename: (from, to) => renameSync15(from, to),
|
|
@@ -149009,11 +150890,11 @@ var exports_session_stats = {};
|
|
|
149009
150890
|
__export(exports_session_stats, {
|
|
149010
150891
|
readSessionStats: () => readSessionStats
|
|
149011
150892
|
});
|
|
149012
|
-
import { readFileSync as
|
|
150893
|
+
import { readFileSync as readFileSync62 } from "fs";
|
|
149013
150894
|
function readSessionStats(port, opts) {
|
|
149014
150895
|
let raw;
|
|
149015
150896
|
try {
|
|
149016
|
-
raw = JSON.parse(
|
|
150897
|
+
raw = JSON.parse(readFileSync62(resolveTokenFilePath(port), "utf-8"));
|
|
149017
150898
|
} catch {
|
|
149018
150899
|
return null;
|
|
149019
150900
|
}
|
|
@@ -149400,8 +151281,8 @@ init_launch_env();
|
|
|
149400
151281
|
init_op_source();
|
|
149401
151282
|
init_startup_trace();
|
|
149402
151283
|
init_picker_cancelled();
|
|
149403
|
-
import { existsSync as existsSync51, readFileSync as
|
|
149404
|
-
import { join as
|
|
151284
|
+
import { existsSync as existsSync51, readFileSync as readFileSync63 } from "fs";
|
|
151285
|
+
import { join as join82, resolve as resolve17 } from "path";
|
|
149405
151286
|
|
|
149406
151287
|
// src/tui/runtime/should-open-picker.ts
|
|
149407
151288
|
function noModelConfigured(gate) {
|
|
@@ -149418,7 +151299,7 @@ function requiresExplicitModel(gate, tty) {
|
|
|
149418
151299
|
var autoloadDropped = [...droppedAtLaunch, ...takeLauncherDropped(process.env)];
|
|
149419
151300
|
var dotenvText;
|
|
149420
151301
|
try {
|
|
149421
|
-
dotenvText =
|
|
151302
|
+
dotenvText = readFileSync63(join82(process.cwd(), ".env"));
|
|
149422
151303
|
} catch {}
|
|
149423
151304
|
if (dotenvText !== undefined) {
|
|
149424
151305
|
await Promise.resolve().then(() => init_dotenv_allowlist());
|
|
@@ -149535,7 +151416,7 @@ async function applyOpImport() {
|
|
|
149535
151416
|
async function applyConfigOverride() {
|
|
149536
151417
|
await Promise.resolve();
|
|
149537
151418
|
const plan = planConfigOverride(process.argv.slice(2), process.env, {
|
|
149538
|
-
resolve:
|
|
151419
|
+
resolve: resolve17,
|
|
149539
151420
|
exists: existsSync51
|
|
149540
151421
|
});
|
|
149541
151422
|
if (plan.kind === "none")
|
|
@@ -149817,14 +151698,14 @@ async function runCli() {
|
|
|
149817
151698
|
if (cliConfig.team && cliConfig.team.length > 0) {
|
|
149818
151699
|
let prompt = cliConfig.claudeArgs.join(" ");
|
|
149819
151700
|
if (cliConfig.inputFile) {
|
|
149820
|
-
prompt =
|
|
151701
|
+
prompt = readFileSync63(cliConfig.inputFile, "utf-8");
|
|
149821
151702
|
}
|
|
149822
151703
|
if (!prompt.trim()) {
|
|
149823
151704
|
console.error("Error: --team requires a prompt (positional args or -f <file>)");
|
|
149824
151705
|
process.exit(1);
|
|
149825
151706
|
}
|
|
149826
151707
|
const mode = cliConfig.teamMode ?? "default";
|
|
149827
|
-
const sessionPath =
|
|
151708
|
+
const sessionPath = join82(process.cwd(), `.claudish-team-${Date.now()}`);
|
|
149828
151709
|
if (mode === "json") {
|
|
149829
151710
|
await Promise.resolve().then(() => init_pane());
|
|
149830
151711
|
await Promise.resolve().then(() => init_team_orchestrator());
|
|
@@ -149844,9 +151725,9 @@ async function runCli() {
|
|
|
149844
151725
|
const status = await runModels(sessionPath);
|
|
149845
151726
|
const result = { ...status, responses: {} };
|
|
149846
151727
|
for (const anonId of Object.keys(status.models)) {
|
|
149847
|
-
const responsePath =
|
|
151728
|
+
const responsePath = join82(sessionPath, `response-${anonId}.md`);
|
|
149848
151729
|
try {
|
|
149849
|
-
const raw =
|
|
151730
|
+
const raw = readFileSync63(responsePath, "utf-8").trim();
|
|
149850
151731
|
try {
|
|
149851
151732
|
result.responses[anonId] = JSON.parse(raw);
|
|
149852
151733
|
} catch {
|