@xship/cli 0.0.186 → 0.0.188

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.
@@ -4,6 +4,7 @@
4
4
  "agy_models": [
5
5
  "gemini-4-argon",
6
6
  "gemini-4-carbon-medium",
7
+ "gemini-4-hydrogen",
7
8
  "gemini-3.8-flash",
8
9
  "gemini-3.7-flash",
9
10
  "gemini-3.6-flash",
@@ -102,9 +103,9 @@
102
103
  "groups": [
103
104
  "Claude 官方特供版"
104
105
  ],
105
- "hint": "支持 Fable,完美缓存,只能在 Claude Code、IDE 官方插件和桌面端中使用",
106
+ "hint": "其他模型照常能用;Claude 支持 Fable,完美缓存,只能在 Claude Code、IDE 官方插件和桌面端中使用",
106
107
  "id": "claude-special",
107
- "label": "使用 Claude 官方特供版"
108
+ "label": "Claude 用官方版"
108
109
  }
109
110
  ]
110
111
  },
@@ -137,6 +138,9 @@
137
138
  "video": false,
138
139
  "vision": true
139
140
  },
141
+ "clients": {
142
+ "codex": false
143
+ },
140
144
  "context_window": 1000000,
141
145
  "description": "100 万上下文 | 长时 Agent 编程 | 知识工作",
142
146
  "endpoint_types": [
@@ -176,6 +180,9 @@
176
180
  "video": false,
177
181
  "vision": true
178
182
  },
183
+ "clients": {
184
+ "codex": false
185
+ },
179
186
  "context_window": 1000000,
180
187
  "description": "100 万上下文 | Agent 编程 | 速度与成本均衡",
181
188
  "endpoint_types": [
@@ -215,6 +222,9 @@
215
222
  "video": false,
216
223
  "vision": true
217
224
  },
225
+ "clients": {
226
+ "codex": false
227
+ },
218
228
  "context_window": 1000000,
219
229
  "description": "100 万上下文 | 高难度推理 | 长时 Agent 与多步研究",
220
230
  "endpoint_types": [
@@ -255,6 +265,9 @@
255
265
  "video": false,
256
266
  "vision": true
257
267
  },
268
+ "clients": {
269
+ "codex": false
270
+ },
258
271
  "context_window": 1000000,
259
272
  "description": "100 万上下文 | 长时 Agent 与多步研究",
260
273
  "endpoint_types": [
@@ -294,6 +307,9 @@
294
307
  "video": false,
295
308
  "vision": true
296
309
  },
310
+ "clients": {
311
+ "codex": false
312
+ },
297
313
  "context_window": 1000000,
298
314
  "description": "100 万上下文 | 高强度推理 | 长时 Agent",
299
315
  "endpoint_types": [
@@ -333,6 +349,9 @@
333
349
  "video": false,
334
350
  "vision": true
335
351
  },
352
+ "clients": {
353
+ "codex": false
354
+ },
336
355
  "context_window": 1000000,
337
356
  "description": "100 万上下文 | Agent 编程",
338
357
  "endpoint_types": [
@@ -372,6 +391,9 @@
372
391
  "video": false,
373
392
  "vision": true
374
393
  },
394
+ "clients": {
395
+ "codex": false
396
+ },
375
397
  "context_window": 1000000,
376
398
  "description": "100 万上下文 | Agent 编程 | 工具调用",
377
399
  "endpoint_types": [
@@ -411,6 +433,9 @@
411
433
  "video": false,
412
434
  "vision": true
413
435
  },
436
+ "clients": {
437
+ "codex": false
438
+ },
414
439
  "context_window": 1000000,
415
440
  "description": "100 万上下文 | 推理 | 编程",
416
441
  "endpoint_types": [
@@ -450,6 +475,9 @@
450
475
  "video": false,
451
476
  "vision": true
452
477
  },
478
+ "clients": {
479
+ "codex": false
480
+ },
453
481
  "context_window": 1000000,
454
482
  "description": "100 万上下文 | 推理 | 编程",
455
483
  "endpoint_types": [
@@ -488,6 +516,9 @@
488
516
  "video": false,
489
517
  "vision": true
490
518
  },
519
+ "clients": {
520
+ "codex": false
521
+ },
491
522
  "context_window": 200000,
492
523
  "description": "20 万上下文(部分分组无 1M)| 推理 | 编程",
493
524
  "endpoint_types": [
@@ -526,6 +557,9 @@
526
557
  "video": false,
527
558
  "vision": true
528
559
  },
560
+ "clients": {
561
+ "codex": false
562
+ },
529
563
  "context_window": 200000,
530
564
  "description": "20 万上下文(部分分组无 1M)| Agent 编程",
531
565
  "endpoint_types": [
@@ -864,6 +898,44 @@
864
898
  "name": "Kimi K3",
865
899
  "recommended": false
866
900
  },
901
+ {
902
+ "capabilities": {
903
+ "contextWindowTokens": 1000000,
904
+ "functionCall": true,
905
+ "imageOutput": false,
906
+ "inputModalities": [
907
+ "text",
908
+ "image",
909
+ "video"
910
+ ],
911
+ "maxOutput": 131072,
912
+ "outputModalities": [
913
+ "text"
914
+ ],
915
+ "reasoning": true,
916
+ "reasoningEfforts": [
917
+ "none",
918
+ "low",
919
+ "high",
920
+ "xhigh"
921
+ ],
922
+ "structuredOutput": true,
923
+ "video": true,
924
+ "vision": true
925
+ },
926
+ "context_window": 1000000,
927
+ "description": "100 万上下文 | 深度推理 | 视觉理解",
928
+ "endpoint_types": [
929
+ "openai"
930
+ ],
931
+ "group": "",
932
+ "group_name": "",
933
+ "hidden": false,
934
+ "id": "qwen4-max",
935
+ "max_output_tokens": 131072,
936
+ "name": "Qwen 4 Max",
937
+ "recommended": false
938
+ },
867
939
  {
868
940
  "capabilities": {
869
941
  "contextWindowTokens": 1000000,
@@ -1089,6 +1161,121 @@
1089
1161
  "name": "GPT-6 Astra",
1090
1162
  "recommended": true
1091
1163
  },
1164
+ {
1165
+ "capabilities": {
1166
+ "contextWindowTokens": 1050000,
1167
+ "functionCall": true,
1168
+ "imageOutput": false,
1169
+ "inputModalities": [
1170
+ "text",
1171
+ "image"
1172
+ ],
1173
+ "knowledgeCutoff": "2026-05-18",
1174
+ "maxOutput": 128000,
1175
+ "outputModalities": [
1176
+ "text"
1177
+ ],
1178
+ "reasoning": true,
1179
+ "reasoningEfforts": [
1180
+ "low",
1181
+ "medium",
1182
+ "high",
1183
+ "xhigh",
1184
+ "max"
1185
+ ],
1186
+ "search": true,
1187
+ "settings": {
1188
+ "disabledParams": [
1189
+ "temperature",
1190
+ "top_p",
1191
+ "frequency_penalty",
1192
+ "presence_penalty"
1193
+ ],
1194
+ "extendParams": [
1195
+ "reasoningEffort"
1196
+ ],
1197
+ "searchImpl": "internal"
1198
+ },
1199
+ "streaming": true,
1200
+ "structuredOutput": true,
1201
+ "video": false,
1202
+ "vision": true
1203
+ },
1204
+ "clients": {
1205
+ "codex": true
1206
+ },
1207
+ "context_window": 1050000,
1208
+ "description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 高难度编程与专业工作",
1209
+ "endpoint_types": [
1210
+ "openai",
1211
+ "openai-response"
1212
+ ],
1213
+ "group": "",
1214
+ "group_name": "",
1215
+ "hidden": false,
1216
+ "id": "gpt-6.2-astra",
1217
+ "max_output_tokens": 128000,
1218
+ "name": "GPT-6.2 Astra",
1219
+ "recommended": false
1220
+ },
1221
+ {
1222
+ "capabilities": {
1223
+ "contextWindowTokens": 1050000,
1224
+ "defaultReasoningEffort": "medium",
1225
+ "functionCall": true,
1226
+ "imageOutput": false,
1227
+ "inputModalities": [
1228
+ "text",
1229
+ "image"
1230
+ ],
1231
+ "knowledgeCutoff": "2026-06-01",
1232
+ "maxOutput": 128000,
1233
+ "outputModalities": [
1234
+ "text"
1235
+ ],
1236
+ "reasoning": true,
1237
+ "reasoningEfforts": [
1238
+ "low",
1239
+ "medium",
1240
+ "high",
1241
+ "xhigh",
1242
+ "max"
1243
+ ],
1244
+ "search": true,
1245
+ "settings": {
1246
+ "disabledParams": [
1247
+ "temperature",
1248
+ "top_p",
1249
+ "frequency_penalty",
1250
+ "presence_penalty"
1251
+ ],
1252
+ "extendParams": [
1253
+ "reasoningEffort"
1254
+ ],
1255
+ "searchImpl": "internal"
1256
+ },
1257
+ "streaming": true,
1258
+ "structuredOutput": true,
1259
+ "video": false,
1260
+ "vision": true
1261
+ },
1262
+ "clients": {
1263
+ "codex": true
1264
+ },
1265
+ "context_window": 1050000,
1266
+ "description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 复杂编程与专业工作",
1267
+ "endpoint_types": [
1268
+ "openai",
1269
+ "openai-response"
1270
+ ],
1271
+ "group": "",
1272
+ "group_name": "",
1273
+ "hidden": false,
1274
+ "id": "gpt-6.2-sol",
1275
+ "max_output_tokens": 128000,
1276
+ "name": "GPT-6.2 Sol",
1277
+ "recommended": false
1278
+ },
1092
1279
  {
1093
1280
  "capabilities": {
1094
1281
  "contextWindowTokens": 1050000,
@@ -1695,6 +1882,44 @@
1695
1882
  "name": "Kimi K3",
1696
1883
  "recommended": false
1697
1884
  },
1885
+ {
1886
+ "capabilities": {
1887
+ "contextWindowTokens": 1000000,
1888
+ "functionCall": true,
1889
+ "imageOutput": false,
1890
+ "inputModalities": [
1891
+ "text",
1892
+ "image",
1893
+ "video"
1894
+ ],
1895
+ "maxOutput": 131072,
1896
+ "outputModalities": [
1897
+ "text"
1898
+ ],
1899
+ "reasoning": true,
1900
+ "reasoningEfforts": [
1901
+ "none",
1902
+ "low",
1903
+ "high",
1904
+ "xhigh"
1905
+ ],
1906
+ "structuredOutput": true,
1907
+ "video": true,
1908
+ "vision": true
1909
+ },
1910
+ "context_window": 1000000,
1911
+ "description": "100 万上下文 | 深度推理 | 视觉理解",
1912
+ "endpoint_types": [
1913
+ "openai"
1914
+ ],
1915
+ "group": "",
1916
+ "group_name": "",
1917
+ "hidden": false,
1918
+ "id": "qwen4-max",
1919
+ "max_output_tokens": 131072,
1920
+ "name": "Qwen 4 Max",
1921
+ "recommended": false
1922
+ },
1698
1923
  {
1699
1924
  "capabilities": {
1700
1925
  "contextWindowTokens": 1000000,
@@ -1981,6 +2206,88 @@
1981
2206
  "name": "Gemini 4 Carbon",
1982
2207
  "recommended": false
1983
2208
  },
2209
+ {
2210
+ "capabilities": {
2211
+ "contextWindowTokens": 1048576,
2212
+ "functionCall": true,
2213
+ "imageOutput": false,
2214
+ "inputModalities": [
2215
+ "text",
2216
+ "image",
2217
+ "video",
2218
+ "audio"
2219
+ ],
2220
+ "knowledgeCutoff": "2026-03-31",
2221
+ "maxOutput": 65536,
2222
+ "outputModalities": [
2223
+ "text"
2224
+ ],
2225
+ "reasoning": true,
2226
+ "reasoningEfforts": [
2227
+ "low",
2228
+ "medium",
2229
+ "high",
2230
+ "xhigh"
2231
+ ],
2232
+ "structuredOutput": true,
2233
+ "video": true,
2234
+ "vision": true
2235
+ },
2236
+ "context_window": 1048576,
2237
+ "description": "100 万上下文 | 复杂编码 | Agent 任务",
2238
+ "endpoint_types": [
2239
+ "gemini",
2240
+ "openai"
2241
+ ],
2242
+ "group": "",
2243
+ "group_name": "",
2244
+ "hidden": false,
2245
+ "id": "gemini-4-neon",
2246
+ "max_output_tokens": 65536,
2247
+ "name": "Gemini 4 Neon",
2248
+ "recommended": false
2249
+ },
2250
+ {
2251
+ "capabilities": {
2252
+ "contextWindowTokens": 1048576,
2253
+ "functionCall": true,
2254
+ "imageOutput": false,
2255
+ "inputModalities": [
2256
+ "text",
2257
+ "image",
2258
+ "video",
2259
+ "audio"
2260
+ ],
2261
+ "knowledgeCutoff": "2026-03-31",
2262
+ "maxOutput": 65536,
2263
+ "outputModalities": [
2264
+ "text"
2265
+ ],
2266
+ "reasoning": true,
2267
+ "reasoningEfforts": [
2268
+ "low",
2269
+ "medium",
2270
+ "high",
2271
+ "xhigh"
2272
+ ],
2273
+ "structuredOutput": true,
2274
+ "video": true,
2275
+ "vision": true
2276
+ },
2277
+ "context_window": 1048576,
2278
+ "description": "100 万上下文 | 快速推理 | 编码与 Agent",
2279
+ "endpoint_types": [
2280
+ "gemini",
2281
+ "openai"
2282
+ ],
2283
+ "group": "",
2284
+ "group_name": "",
2285
+ "hidden": false,
2286
+ "id": "gemini-4-hydrogen",
2287
+ "max_output_tokens": 65536,
2288
+ "name": "Gemini 4 Hydrogen",
2289
+ "recommended": false
2290
+ },
1984
2291
  {
1985
2292
  "capabilities": {
1986
2293
  "contextWindowTokens": 1048576,
@@ -2222,7 +2529,7 @@
2222
2529
  "tool": "gemini"
2223
2530
  }
2224
2531
  ],
2225
- "revision": "2026-11-11T08:32:41Z-17",
2532
+ "revision": "2026-11-20T09:26:26Z-10",
2226
2533
  "schema": 1,
2227
2534
  "tools": {
2228
2535
  "claude": {
package/dist/brand.json CHANGED
@@ -11,6 +11,8 @@
11
11
  "id": "xship",
12
12
  "installMirror": {
13
13
  "agy": "https://cnb.cool/lib/mirrors/-/releases/download/agy",
14
+ "chatgptDesktop": "https://cnb.cool/lib/mirrors/-/releases/download/chatgpt-desktop",
15
+ "claudeDesktop": "https://cnb.cool/lib/mirrors/-/releases/download/claude-desktop",
14
16
  "scripts": "https://cnb.cool/lib/install/-/git/raw/main"
15
17
  },
16
18
  "links": {
@@ -4,6 +4,7 @@
4
4
  "agy_models": [
5
5
  "gemini-4-argon",
6
6
  "gemini-4-carbon-medium",
7
+ "gemini-4-hydrogen",
7
8
  "gemini-3.8-flash",
8
9
  "gemini-3.7-flash",
9
10
  "gemini-3.6-flash",
@@ -102,9 +103,9 @@
102
103
  "groups": [
103
104
  "Claude 官方特供版"
104
105
  ],
105
- "hint": "支持 Fable,完美缓存,只能在 Claude Code、IDE 官方插件和桌面端中使用",
106
+ "hint": "其他模型照常能用;Claude 支持 Fable,完美缓存,只能在 Claude Code、IDE 官方插件和桌面端中使用",
106
107
  "id": "claude-special",
107
- "label": "使用 Claude 官方特供版"
108
+ "label": "Claude 用官方版"
108
109
  }
109
110
  ]
110
111
  },
@@ -137,6 +138,9 @@
137
138
  "video": false,
138
139
  "vision": true
139
140
  },
141
+ "clients": {
142
+ "codex": false
143
+ },
140
144
  "context_window": 1000000,
141
145
  "description": "100 万上下文 | 长时 Agent 编程 | 知识工作",
142
146
  "endpoint_types": [
@@ -176,6 +180,9 @@
176
180
  "video": false,
177
181
  "vision": true
178
182
  },
183
+ "clients": {
184
+ "codex": false
185
+ },
179
186
  "context_window": 1000000,
180
187
  "description": "100 万上下文 | Agent 编程 | 速度与成本均衡",
181
188
  "endpoint_types": [
@@ -215,6 +222,9 @@
215
222
  "video": false,
216
223
  "vision": true
217
224
  },
225
+ "clients": {
226
+ "codex": false
227
+ },
218
228
  "context_window": 1000000,
219
229
  "description": "100 万上下文 | 高难度推理 | 长时 Agent 与多步研究",
220
230
  "endpoint_types": [
@@ -255,6 +265,9 @@
255
265
  "video": false,
256
266
  "vision": true
257
267
  },
268
+ "clients": {
269
+ "codex": false
270
+ },
258
271
  "context_window": 1000000,
259
272
  "description": "100 万上下文 | 长时 Agent 与多步研究",
260
273
  "endpoint_types": [
@@ -294,6 +307,9 @@
294
307
  "video": false,
295
308
  "vision": true
296
309
  },
310
+ "clients": {
311
+ "codex": false
312
+ },
297
313
  "context_window": 1000000,
298
314
  "description": "100 万上下文 | 高强度推理 | 长时 Agent",
299
315
  "endpoint_types": [
@@ -333,6 +349,9 @@
333
349
  "video": false,
334
350
  "vision": true
335
351
  },
352
+ "clients": {
353
+ "codex": false
354
+ },
336
355
  "context_window": 1000000,
337
356
  "description": "100 万上下文 | Agent 编程",
338
357
  "endpoint_types": [
@@ -372,6 +391,9 @@
372
391
  "video": false,
373
392
  "vision": true
374
393
  },
394
+ "clients": {
395
+ "codex": false
396
+ },
375
397
  "context_window": 1000000,
376
398
  "description": "100 万上下文 | Agent 编程 | 工具调用",
377
399
  "endpoint_types": [
@@ -411,6 +433,9 @@
411
433
  "video": false,
412
434
  "vision": true
413
435
  },
436
+ "clients": {
437
+ "codex": false
438
+ },
414
439
  "context_window": 1000000,
415
440
  "description": "100 万上下文 | 推理 | 编程",
416
441
  "endpoint_types": [
@@ -450,6 +475,9 @@
450
475
  "video": false,
451
476
  "vision": true
452
477
  },
478
+ "clients": {
479
+ "codex": false
480
+ },
453
481
  "context_window": 1000000,
454
482
  "description": "100 万上下文 | 推理 | 编程",
455
483
  "endpoint_types": [
@@ -488,6 +516,9 @@
488
516
  "video": false,
489
517
  "vision": true
490
518
  },
519
+ "clients": {
520
+ "codex": false
521
+ },
491
522
  "context_window": 200000,
492
523
  "description": "20 万上下文(部分分组无 1M)| 推理 | 编程",
493
524
  "endpoint_types": [
@@ -526,6 +557,9 @@
526
557
  "video": false,
527
558
  "vision": true
528
559
  },
560
+ "clients": {
561
+ "codex": false
562
+ },
529
563
  "context_window": 200000,
530
564
  "description": "20 万上下文(部分分组无 1M)| Agent 编程",
531
565
  "endpoint_types": [
@@ -864,6 +898,44 @@
864
898
  "name": "Kimi K3",
865
899
  "recommended": false
866
900
  },
901
+ {
902
+ "capabilities": {
903
+ "contextWindowTokens": 1000000,
904
+ "functionCall": true,
905
+ "imageOutput": false,
906
+ "inputModalities": [
907
+ "text",
908
+ "image",
909
+ "video"
910
+ ],
911
+ "maxOutput": 131072,
912
+ "outputModalities": [
913
+ "text"
914
+ ],
915
+ "reasoning": true,
916
+ "reasoningEfforts": [
917
+ "none",
918
+ "low",
919
+ "high",
920
+ "xhigh"
921
+ ],
922
+ "structuredOutput": true,
923
+ "video": true,
924
+ "vision": true
925
+ },
926
+ "context_window": 1000000,
927
+ "description": "100 万上下文 | 深度推理 | 视觉理解",
928
+ "endpoint_types": [
929
+ "openai"
930
+ ],
931
+ "group": "",
932
+ "group_name": "",
933
+ "hidden": false,
934
+ "id": "qwen4-max",
935
+ "max_output_tokens": 131072,
936
+ "name": "Qwen 4 Max",
937
+ "recommended": false
938
+ },
867
939
  {
868
940
  "capabilities": {
869
941
  "contextWindowTokens": 1000000,
@@ -1089,6 +1161,121 @@
1089
1161
  "name": "GPT-6 Astra",
1090
1162
  "recommended": true
1091
1163
  },
1164
+ {
1165
+ "capabilities": {
1166
+ "contextWindowTokens": 1050000,
1167
+ "functionCall": true,
1168
+ "imageOutput": false,
1169
+ "inputModalities": [
1170
+ "text",
1171
+ "image"
1172
+ ],
1173
+ "knowledgeCutoff": "2026-05-18",
1174
+ "maxOutput": 128000,
1175
+ "outputModalities": [
1176
+ "text"
1177
+ ],
1178
+ "reasoning": true,
1179
+ "reasoningEfforts": [
1180
+ "low",
1181
+ "medium",
1182
+ "high",
1183
+ "xhigh",
1184
+ "max"
1185
+ ],
1186
+ "search": true,
1187
+ "settings": {
1188
+ "disabledParams": [
1189
+ "temperature",
1190
+ "top_p",
1191
+ "frequency_penalty",
1192
+ "presence_penalty"
1193
+ ],
1194
+ "extendParams": [
1195
+ "reasoningEffort"
1196
+ ],
1197
+ "searchImpl": "internal"
1198
+ },
1199
+ "streaming": true,
1200
+ "structuredOutput": true,
1201
+ "video": false,
1202
+ "vision": true
1203
+ },
1204
+ "clients": {
1205
+ "codex": true
1206
+ },
1207
+ "context_window": 1050000,
1208
+ "description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 高难度编程与专业工作",
1209
+ "endpoint_types": [
1210
+ "openai",
1211
+ "openai-response"
1212
+ ],
1213
+ "group": "",
1214
+ "group_name": "",
1215
+ "hidden": false,
1216
+ "id": "gpt-6.2-astra",
1217
+ "max_output_tokens": 128000,
1218
+ "name": "GPT-6.2 Astra",
1219
+ "recommended": false
1220
+ },
1221
+ {
1222
+ "capabilities": {
1223
+ "contextWindowTokens": 1050000,
1224
+ "defaultReasoningEffort": "medium",
1225
+ "functionCall": true,
1226
+ "imageOutput": false,
1227
+ "inputModalities": [
1228
+ "text",
1229
+ "image"
1230
+ ],
1231
+ "knowledgeCutoff": "2026-06-01",
1232
+ "maxOutput": 128000,
1233
+ "outputModalities": [
1234
+ "text"
1235
+ ],
1236
+ "reasoning": true,
1237
+ "reasoningEfforts": [
1238
+ "low",
1239
+ "medium",
1240
+ "high",
1241
+ "xhigh",
1242
+ "max"
1243
+ ],
1244
+ "search": true,
1245
+ "settings": {
1246
+ "disabledParams": [
1247
+ "temperature",
1248
+ "top_p",
1249
+ "frequency_penalty",
1250
+ "presence_penalty"
1251
+ ],
1252
+ "extendParams": [
1253
+ "reasoningEffort"
1254
+ ],
1255
+ "searchImpl": "internal"
1256
+ },
1257
+ "streaming": true,
1258
+ "structuredOutput": true,
1259
+ "video": false,
1260
+ "vision": true
1261
+ },
1262
+ "clients": {
1263
+ "codex": true
1264
+ },
1265
+ "context_window": 1050000,
1266
+ "description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 复杂编程与专业工作",
1267
+ "endpoint_types": [
1268
+ "openai",
1269
+ "openai-response"
1270
+ ],
1271
+ "group": "",
1272
+ "group_name": "",
1273
+ "hidden": false,
1274
+ "id": "gpt-6.2-sol",
1275
+ "max_output_tokens": 128000,
1276
+ "name": "GPT-6.2 Sol",
1277
+ "recommended": false
1278
+ },
1092
1279
  {
1093
1280
  "capabilities": {
1094
1281
  "contextWindowTokens": 1050000,
@@ -1695,6 +1882,44 @@
1695
1882
  "name": "Kimi K3",
1696
1883
  "recommended": false
1697
1884
  },
1885
+ {
1886
+ "capabilities": {
1887
+ "contextWindowTokens": 1000000,
1888
+ "functionCall": true,
1889
+ "imageOutput": false,
1890
+ "inputModalities": [
1891
+ "text",
1892
+ "image",
1893
+ "video"
1894
+ ],
1895
+ "maxOutput": 131072,
1896
+ "outputModalities": [
1897
+ "text"
1898
+ ],
1899
+ "reasoning": true,
1900
+ "reasoningEfforts": [
1901
+ "none",
1902
+ "low",
1903
+ "high",
1904
+ "xhigh"
1905
+ ],
1906
+ "structuredOutput": true,
1907
+ "video": true,
1908
+ "vision": true
1909
+ },
1910
+ "context_window": 1000000,
1911
+ "description": "100 万上下文 | 深度推理 | 视觉理解",
1912
+ "endpoint_types": [
1913
+ "openai"
1914
+ ],
1915
+ "group": "",
1916
+ "group_name": "",
1917
+ "hidden": false,
1918
+ "id": "qwen4-max",
1919
+ "max_output_tokens": 131072,
1920
+ "name": "Qwen 4 Max",
1921
+ "recommended": false
1922
+ },
1698
1923
  {
1699
1924
  "capabilities": {
1700
1925
  "contextWindowTokens": 1000000,
@@ -1981,6 +2206,88 @@
1981
2206
  "name": "Gemini 4 Carbon",
1982
2207
  "recommended": false
1983
2208
  },
2209
+ {
2210
+ "capabilities": {
2211
+ "contextWindowTokens": 1048576,
2212
+ "functionCall": true,
2213
+ "imageOutput": false,
2214
+ "inputModalities": [
2215
+ "text",
2216
+ "image",
2217
+ "video",
2218
+ "audio"
2219
+ ],
2220
+ "knowledgeCutoff": "2026-03-31",
2221
+ "maxOutput": 65536,
2222
+ "outputModalities": [
2223
+ "text"
2224
+ ],
2225
+ "reasoning": true,
2226
+ "reasoningEfforts": [
2227
+ "low",
2228
+ "medium",
2229
+ "high",
2230
+ "xhigh"
2231
+ ],
2232
+ "structuredOutput": true,
2233
+ "video": true,
2234
+ "vision": true
2235
+ },
2236
+ "context_window": 1048576,
2237
+ "description": "100 万上下文 | 复杂编码 | Agent 任务",
2238
+ "endpoint_types": [
2239
+ "gemini",
2240
+ "openai"
2241
+ ],
2242
+ "group": "",
2243
+ "group_name": "",
2244
+ "hidden": false,
2245
+ "id": "gemini-4-neon",
2246
+ "max_output_tokens": 65536,
2247
+ "name": "Gemini 4 Neon",
2248
+ "recommended": false
2249
+ },
2250
+ {
2251
+ "capabilities": {
2252
+ "contextWindowTokens": 1048576,
2253
+ "functionCall": true,
2254
+ "imageOutput": false,
2255
+ "inputModalities": [
2256
+ "text",
2257
+ "image",
2258
+ "video",
2259
+ "audio"
2260
+ ],
2261
+ "knowledgeCutoff": "2026-03-31",
2262
+ "maxOutput": 65536,
2263
+ "outputModalities": [
2264
+ "text"
2265
+ ],
2266
+ "reasoning": true,
2267
+ "reasoningEfforts": [
2268
+ "low",
2269
+ "medium",
2270
+ "high",
2271
+ "xhigh"
2272
+ ],
2273
+ "structuredOutput": true,
2274
+ "video": true,
2275
+ "vision": true
2276
+ },
2277
+ "context_window": 1048576,
2278
+ "description": "100 万上下文 | 快速推理 | 编码与 Agent",
2279
+ "endpoint_types": [
2280
+ "gemini",
2281
+ "openai"
2282
+ ],
2283
+ "group": "",
2284
+ "group_name": "",
2285
+ "hidden": false,
2286
+ "id": "gemini-4-hydrogen",
2287
+ "max_output_tokens": 65536,
2288
+ "name": "Gemini 4 Hydrogen",
2289
+ "recommended": false
2290
+ },
1984
2291
  {
1985
2292
  "capabilities": {
1986
2293
  "contextWindowTokens": 1048576,
@@ -2222,7 +2529,7 @@
2222
2529
  "tool": "gemini"
2223
2530
  }
2224
2531
  ],
2225
- "revision": "2026-11-11T08:32:41Z-17",
2532
+ "revision": "2026-11-20T09:26:26Z-10",
2226
2533
  "schema": 1,
2227
2534
  "tools": {
2228
2535
  "claude": {
@@ -1 +1 @@
1
- import{chmodSync as e,copyFileSync as t,existsSync as r,lstatSync as n,mkdirSync as o,readdirSync as s,readFileSync as a,readlinkSync as i,renameSync as l,rmSync as c,symlinkSync as u,writeFileSync as p}from"fs";import{homedir as d}from"os";import{basename as m,dirname as f,join as h,sep as g}from"path";import{spawnSync as _}from"child_process";import y from"chalk";import{checkForUpdate as v,readLocalPackage as x,UPDATE_SOURCES as w}from"../commands/update.js";import{i18n as k}from"./i18n.js";import{isColorEnabled as S}from"./runtime-options.js";import{logger as b}from"../utils/logger.js";import{isHelpRequest as $}from"./cli-help.js";import{brand as I,brandEnvName as E}from"./brand.js";import{flushTelemetry as P,track as j}from"./telemetry.js";import{processAlive as N}from"../utils/process-alive.js";import{endedByInterrupt as A}from"./signals.js";export const INSTALL_RETRY_INTERVAL_MS=36e5;export const INSTALL_TIMEOUT_MS=45e3;function T(e,t){return S()?e(t):t}export function resolveUpdateCachePath(e=process.env){const t=e[E("CONFIG_DIR")]?.trim();if(t)return h(t,"update-state.json");const r=e[E("TEST_HOME")]?.trim();return h(r||d(),I().configDirName,"update-state.json")}export function isGlobalPackageInstall(e){return e.split(g).includes("node_modules")}export function isNpxExecution(e=process.env){return"exec"===e.npm_command||"npx"===e.npm_lifecycle_event}export function isPnpmGlobalInstall(e){return e.includes(`${g}.pnpm${g}`)||e.includes(`${g}pnpm${g}global${g}`)}export function resolveNpmGlobalPrefix(e){const t=`${g}node_modules${g}`,r=e.indexOf(t);if(r<0)return null;const n=e.slice(0,r);return n.endsWith(`${g}lib`)?f(n):n}export function shouldSkipStartupUpdate(e,t=process.env){return"1"===t[E("SKIP_AUTO_UPDATE")]||"1"===t[E("DISABLE_AUTO_UPDATE")]||(!(!["--json","--non-interactive","--dry-run","--help","-h","--version","-v"].some(t=>e.includes(t))&&!$(e))||e.includes("update")||e.includes("completion"))}function R(t,r,n,s,a){try{o(f(t),{recursive:!0,mode:448});const i=`${t}.tmp-${process.pid}`,c={package_name:r,checked_at:n,latest:s.latest,source:s.source,registry:s.registry,errors:s.errors,...void 0===a?{}:{install_attempted_at:a,install_attempted_version:s.latest||void 0}};p(i,JSON.stringify(c),{encoding:"utf-8",mode:384}),l(i,t),e(t,384)}catch(e){b.warn("Failed to persist update check cache:",e)}}export function windowsShellCommand(e,t){return[e,...t.map(e=>`"${e}"`)].join(" ")}export const defaultInstallRunner=(e,t)=>{const r={stdio:"inherit",timeout:45e3,killSignal:"SIGTERM"};return"win32"===process.platform?_(windowsShellCommand(e,t),{...r,shell:!0}):_(e,t,r)};const U=(e,t)=>_(process.execPath,[process.argv[1],...e],{stdio:"inherit",env:t}),D="-update-";function O(e,t){const r=`.${t}${D}`;return s(e).filter(e=>e.startsWith(r)).map(t=>{const n=/^(old-)?(\d+)$/.exec(t.slice(r.length));return{path:h(e,t),old:Boolean(n?.[1]),pid:n?Number(n[2]):null}})}export function recoverInterruptedSwap(e){try{if(r(e)||!r(f(e)))return!1;const t=O(f(e),m(e)).filter(e=>e.old&&null!==e.pid&&!N(e.pid)).filter(e=>r(h(e.path,"package.json"))).sort((e,t)=>n(t.path).mtimeMs-n(e.path).mtimeMs);return 0!==t.length&&(C(t[0].path,e),!0)}catch(e){return b.warn("Failed to restore the package an interrupted update moved aside:",e),!1}}function C(e,t){for(let r=0;;r++)try{return void l(e,t)}catch(e){const t=e.code;if(r>=9||"EPERM"!==t&&"EACCES"!==t&&"EBUSY"!==t)throw e;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,200)}}export function swapStagedPackage(e,s,l,p,d){const g=p.split("/"),_=[h(e,"node_modules",...g),h(e,"lib","node_modules",...g)].find(e=>r(h(e,"package.json")));if(!_)return!1;const y=JSON.parse(a(h(_,"package.json"),"utf-8"));if(y.version!==d)return!1;recoverInterruptedSwap(l);const v=h(f(l),`.${m(l)}${D}old-${process.pid}`),x=r(l);x&&C(l,v);try{C(_,l)}catch(e){throw x&&C(v,l),e}c(v,{recursive:!0,force:!0,maxRetries:3});const w="string"==typeof y.bin?[g[g.length-1]]:Object.keys(y.bin||{});for(const[r,a]of[[h(e,"bin"),h(s,"bin")],[e,s]])for(const e of w.flatMap(e=>["",".cmd",".ps1"].map(t=>e+t))){const s=h(r,e),l=h(a,e),c=n(s,{throwIfNoEntry:!1});if(!n(l,{throwIfNoEntry:!1})&&c&&!c.isDirectory())try{o(a,{recursive:!0}),c.isSymbolicLink()?u(i(s),l):t(s,l)}catch(e){b.warn("Failed to restore command shim:",e)}}return!0}export async function runStartupUpdate(e,t={}){const n=t.env||process.env,o=t.localPackage||x(),s=t.globalInstall??isGlobalPackageInstall(o.root),i=t.npx??isNpxExecution(n);if(!s||i||shouldSkipStartupUpdate(e,n))return{status:"skipped",handled:!1,source:null};const l=t.now??Date.now(),u=t.cachePath||resolveUpdateCachePath(n),p=function(e,t){try{if(!r(e))return null;const n=JSON.parse(a(e,"utf-8"));return n.package_name===t.name&&Number.isFinite(n.checked_at)?n:null}catch{return null}}(u,o);let d=function(e,t,r){if(!e||e.latest)return null;const n=r-e.checked_at;if(n<0||n>=6e5)return null;const o=Array.isArray(e.errors)?e.errors:[];return{current:t.version,latest:null,up_to_date:null,source:e.source,registry:e.registry,errors:o,error:o.map(e=>`${e.source}: ${e.error}`).join("; ")||"unknown"}}(p,o,l),_=null;if(d||(d=await v({localPackage:o,fetchFn:t.fetchFn}),d.latest&&p?.install_attempted_version===d.latest&&Number.isFinite(p.install_attempted_at)&&(_=p.install_attempted_at),R(u,o.name,l,d,_??void 0)),!d.latest)return{status:"unavailable",handled:!1,source:null};if(d.up_to_date)return{status:"current",handled:!1,source:d.source};if(null!==_&&l>=_&&l-_<36e5)return{status:"update_failed",handled:!1,source:d.source};const S=t.output||console.log,b=t.errorOutput||console.error,$=t.installRunner||defaultInstallRunner,I=isPnpmGlobalInstall(o.root),C=I?"win32"===process.platform?"pnpm.cmd":"pnpm":"win32"===process.platform?"npm.cmd":"npm",M=I?null:resolveNpmGlobalPrefix(o.root),F=o.root,G=M&&F.endsWith(g+o.name.split("/").join(g))?h(f(F),`.${m(F)}${D}${process.pid}`):null;G&&(recoverInterruptedSwap(F),function(e,t){try{for(const r of O(e,t))null!==r.pid&&r.pid!==process.pid&&N(r.pid)||c(r.path,{recursive:!0,force:!0})}catch{}}(f(F),m(F))),R(u,o.name,l,d,l),S(T(y.cyan,k.t("update.auto_installing",{version:d.latest})));const L={from:o.version,to:d.latest,staged:Boolean(G)};j("self-update","start",{detail:L}),await P();const B=[...d.registry?[d.registry]:[],...w.map(e=>e.registry).filter(e=>e!==d.registry)],J=Date.now();let W=null,K="unknown",Y=0;for(const e of B){if(Date.now()-J>=45e3)break;Y++;const t=$(C,I?["add","--global",`${o.name}@${d.latest}`,"--registry",e]:["install","--global",...G?["--prefix",G]:M?["--prefix",M]:[],`${o.name}@${d.latest}`,"--registry",e,"--no-audit","--no-fund","--fetch-timeout=15000","--fetch-retries=1","--fetch-retry-mintimeout=1000","--fetch-retry-maxtimeout=3000"]);if(0===t.status){if(!G){W=e;break}try{if(!swapStagedPackage(G,M,F,o.name,d.latest)){K="staged install incomplete";continue}W=e;break}catch(e){K=e instanceof Error?e.message:String(e);break}finally{c(G,{recursive:!0,force:!0,maxRetries:3})}}else if(K=t.error?.message||`exit ${t.status??"unknown"}`,G&&c(G,{recursive:!0,force:!0,maxRetries:3}),A(t)){K="interrupted";break}}const H=Date.now()-J;if(j("self-update",W?"ok":H>=45e3?"timeout":"fail",{duration_ms:H,...W?{}:{error:K},detail:{...L,attempts:Y,registry:W}}),await P(),!W)return b(T(y.yellow,k.t("update.auto_failed",{error:K}))),{status:"update_failed",handled:!1,source:d.source};S(T(y.green,k.t("update.auto_installed",{version:d.latest})));const V=(t.reexecRunner||U)(e,{...n,[E("SKIP_AUTO_UPDATE")]:"1"});return V.error?(b(T(y.yellow,k.t("update.reexec_failed",{error:V.error.message}))),{status:"update_failed",handled:!1,source:d.source}):(process.exitCode=V.status??1,j("command","skip",{duration_ms:Date.now()-J,detail:{reason:"self-update-rerun",exit_code:process.exitCode}}),{status:"reexecuted",handled:!0,source:d.source})}
1
+ import{chmodSync as e,copyFileSync as t,existsSync as r,lstatSync as n,mkdirSync as o,readdirSync as s,readFileSync as a,readlinkSync as i,renameSync as l,rmSync as c,symlinkSync as u,writeFileSync as p}from"fs";import{homedir as d}from"os";import{basename as m,dirname as f,join as h,sep as g}from"path";import{spawnSync as _}from"child_process";import y from"chalk";import{checkForUpdate as v,readLocalPackage as x,UPDATE_SOURCES as w}from"../commands/update.js";import{i18n as k}from"./i18n.js";import{isColorEnabled as S}from"./runtime-options.js";import{logger as b}from"../utils/logger.js";import{isHelpRequest as $}from"./cli-help.js";import{brand as I,brandEnvName as j}from"./brand.js";import{flushTelemetry as E,track as P}from"./telemetry.js";import{processAlive as N}from"../utils/process-alive.js";import{endedByInterrupt as A}from"./signals.js";import{npmCacheArgs as T}from"./npm-cache.js";export const INSTALL_RETRY_INTERVAL_MS=36e5;export const INSTALL_TIMEOUT_MS=45e3;function R(e,t){return S()?e(t):t}export function resolveUpdateCachePath(e=process.env){const t=e[j("CONFIG_DIR")]?.trim();if(t)return h(t,"update-state.json");const r=e[j("TEST_HOME")]?.trim();return h(r||d(),I().configDirName,"update-state.json")}export function isGlobalPackageInstall(e){return e.split(g).includes("node_modules")}export function isNpxExecution(e=process.env){return"exec"===e.npm_command||"npx"===e.npm_lifecycle_event}export function isPnpmGlobalInstall(e){return e.includes(`${g}.pnpm${g}`)||e.includes(`${g}pnpm${g}global${g}`)}export function resolveNpmGlobalPrefix(e){const t=`${g}node_modules${g}`,r=e.indexOf(t);if(r<0)return null;const n=e.slice(0,r);return n.endsWith(`${g}lib`)?f(n):n}export function shouldSkipStartupUpdate(e,t=process.env){return"1"===t[j("SKIP_AUTO_UPDATE")]||"1"===t[j("DISABLE_AUTO_UPDATE")]||(!(!["--json","--non-interactive","--dry-run","--help","-h","--version","-v"].some(t=>e.includes(t))&&!$(e))||e.includes("update")||e.includes("completion"))}function U(t,r,n,s,a){try{o(f(t),{recursive:!0,mode:448});const i=`${t}.tmp-${process.pid}`,c={package_name:r,checked_at:n,latest:s.latest,source:s.source,registry:s.registry,errors:s.errors,...void 0===a?{}:{install_attempted_at:a,install_attempted_version:s.latest||void 0}};p(i,JSON.stringify(c),{encoding:"utf-8",mode:384}),l(i,t),e(t,384)}catch(e){b.warn("Failed to persist update check cache:",e)}}export function windowsShellCommand(e,t){return[e,...t.map(e=>`"${e}"`)].join(" ")}export const defaultInstallRunner=(e,t)=>{const r={stdio:"inherit",timeout:45e3,killSignal:"SIGTERM"};return"win32"===process.platform?_(windowsShellCommand(e,t),{...r,shell:!0}):_(e,t,r)};const D=(e,t)=>_(process.execPath,[process.argv[1],...e],{stdio:"inherit",env:t}),O="-update-";function C(e,t){const r=`.${t}${O}`;return s(e).filter(e=>e.startsWith(r)).map(t=>{const n=/^(old-)?(\d+)$/.exec(t.slice(r.length));return{path:h(e,t),old:Boolean(n?.[1]),pid:n?Number(n[2]):null}})}export function recoverInterruptedSwap(e){try{if(r(e)||!r(f(e)))return!1;const t=C(f(e),m(e)).filter(e=>e.old&&null!==e.pid&&!N(e.pid)).filter(e=>r(h(e.path,"package.json"))).sort((e,t)=>n(t.path).mtimeMs-n(e.path).mtimeMs);return 0!==t.length&&(M(t[0].path,e),!0)}catch(e){return b.warn("Failed to restore the package an interrupted update moved aside:",e),!1}}function M(e,t){for(let r=0;;r++)try{return void l(e,t)}catch(e){const t=e.code;if(r>=9||"EPERM"!==t&&"EACCES"!==t&&"EBUSY"!==t)throw e;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,200)}}export function swapStagedPackage(e,s,l,p,d){const g=p.split("/"),_=[h(e,"node_modules",...g),h(e,"lib","node_modules",...g)].find(e=>r(h(e,"package.json")));if(!_)return!1;const y=JSON.parse(a(h(_,"package.json"),"utf-8"));if(y.version!==d)return!1;recoverInterruptedSwap(l);const v=h(f(l),`.${m(l)}${O}old-${process.pid}`),x=r(l);x&&M(l,v);try{M(_,l)}catch(e){throw x&&M(v,l),e}c(v,{recursive:!0,force:!0,maxRetries:3});const w="string"==typeof y.bin?[g[g.length-1]]:Object.keys(y.bin||{});for(const[r,a]of[[h(e,"bin"),h(s,"bin")],[e,s]])for(const e of w.flatMap(e=>["",".cmd",".ps1"].map(t=>e+t))){const s=h(r,e),l=h(a,e),c=n(s,{throwIfNoEntry:!1});if(!n(l,{throwIfNoEntry:!1})&&c&&!c.isDirectory())try{o(a,{recursive:!0}),c.isSymbolicLink()?u(i(s),l):t(s,l)}catch(e){b.warn("Failed to restore command shim:",e)}}return!0}export async function runStartupUpdate(e,t={}){const n=t.env||process.env,o=t.localPackage||x(),s=t.globalInstall??isGlobalPackageInstall(o.root),i=t.npx??isNpxExecution(n);if(!s||i||shouldSkipStartupUpdate(e,n))return{status:"skipped",handled:!1,source:null};const l=t.now??Date.now(),u=t.cachePath||resolveUpdateCachePath(n),p=function(e,t){try{if(!r(e))return null;const n=JSON.parse(a(e,"utf-8"));return n.package_name===t.name&&Number.isFinite(n.checked_at)?n:null}catch{return null}}(u,o);let d=function(e,t,r){if(!e||e.latest)return null;const n=r-e.checked_at;if(n<0||n>=6e5)return null;const o=Array.isArray(e.errors)?e.errors:[];return{current:t.version,latest:null,up_to_date:null,source:e.source,registry:e.registry,errors:o,error:o.map(e=>`${e.source}: ${e.error}`).join("; ")||"unknown"}}(p,o,l),_=null;if(d||(d=await v({localPackage:o,fetchFn:t.fetchFn}),d.latest&&p?.install_attempted_version===d.latest&&Number.isFinite(p.install_attempted_at)&&(_=p.install_attempted_at),U(u,o.name,l,d,_??void 0)),!d.latest)return{status:"unavailable",handled:!1,source:null};if(d.up_to_date)return{status:"current",handled:!1,source:d.source};if(null!==_&&l>=_&&l-_<36e5)return{status:"update_failed",handled:!1,source:d.source};const S=t.output||console.log,b=t.errorOutput||console.error,$=t.installRunner||defaultInstallRunner,I=isPnpmGlobalInstall(o.root),M=I?"win32"===process.platform?"pnpm.cmd":"pnpm":"win32"===process.platform?"npm.cmd":"npm",F=I?null:resolveNpmGlobalPrefix(o.root),G=o.root,L=F&&G.endsWith(g+o.name.split("/").join(g))?h(f(G),`.${m(G)}${O}${process.pid}`):null;L&&(recoverInterruptedSwap(G),function(e,t){try{for(const r of C(e,t))null!==r.pid&&r.pid!==process.pid&&N(r.pid)||c(r.path,{recursive:!0,force:!0})}catch{}}(f(G),m(G))),U(u,o.name,l,d,l),S(R(y.cyan,k.t("update.auto_installing",{version:d.latest})));const B={from:o.version,to:d.latest,staged:Boolean(L)};P("self-update","start",{detail:B}),await E();const J=[...d.registry?[d.registry]:[],...w.map(e=>e.registry).filter(e=>e!==d.registry)],W=Date.now();let K=null,Y="unknown",H=0;for(const e of J){if(Date.now()-W>=45e3)break;H++;const t=$(M,I?["add","--global",`${o.name}@${d.latest}`,"--registry",e]:["install","--global",...L?["--prefix",L]:F?["--prefix",F]:[],`${o.name}@${d.latest}`,"--registry",e,"--no-audit","--no-fund","--fetch-timeout=15000","--fetch-retries=1","--fetch-retry-mintimeout=1000","--fetch-retry-maxtimeout=3000",...T(f(u))]);if(0===t.status){if(!L){K=e;break}try{if(!swapStagedPackage(L,F,G,o.name,d.latest)){Y="staged install incomplete";continue}K=e;break}catch(e){Y=e instanceof Error?e.message:String(e);break}finally{c(L,{recursive:!0,force:!0,maxRetries:3})}}else if(Y=t.error?.message||`exit ${t.status??"unknown"}`,L&&c(L,{recursive:!0,force:!0,maxRetries:3}),A(t)){Y="interrupted";break}}const V=Date.now()-W;if(P("self-update",K?"ok":V>=45e3?"timeout":"fail",{duration_ms:V,...K?{}:{error:Y},detail:{...B,attempts:H,registry:K}}),await E(),!K)return b(R(y.yellow,k.t("update.auto_failed",{error:Y}))),{status:"update_failed",handled:!1,source:d.source};S(R(y.green,k.t("update.auto_installed",{version:d.latest})));const q=(t.reexecRunner||D)(e,{...n,[j("SKIP_AUTO_UPDATE")]:"1"});return q.error?(b(R(y.yellow,k.t("update.reexec_failed",{error:q.error.message}))),{status:"update_failed",handled:!1,source:d.source}):(process.exitCode=q.status??1,P("command","skip",{duration_ms:Date.now()-W,detail:{reason:"self-update-rerun",exit_code:process.exitCode}}),{status:"reexecuted",handled:!0,source:d.source})}
@@ -1 +1 @@
1
- import{spawnSync as t}from"child_process";import{existsSync as e,mkdirSync as o,readFileSync as n,readdirSync as r,realpathSync as a,rmSync as s,statSync as i,writeFileSync as l}from"fs";import{delimiter as c,dirname as u,isAbsolute as p,join as d,sep as m}from"path";import{fileURLToPath as f}from"url";import g from"chalk";import{brand as h,CLI_NAME as w}from"./brand.js";import{configManager as v}from"./config.js";import{i18n as y}from"./i18n.js";import{appLatest as b,appStatus as _,appStatusWith as $,cachedAppStatus as P,getApp as x}from"./app-update.js";import{compareVersions as A}from"./model-registry.js";import{isJsonMode as k}from"./runtime-options.js";import{maskSecrets as D,track as S}from"./telemetry.js";import{failureContext as j,lastCommandExit as L,lastCommandOutput as E,runWatched as C}from"./tool-upgrade.js";import{runInstallScript as R,traceSummary as T}from"./install-script.js";import{atomicWriteFile as M}from"./tools/backup.js";import{getAdapter as N}from"./tools/registry.js";import{findInstallsIncludingNative as O,forgetInstalls as U,NPM_MIRROR as I,npmMirrorVersion as B}from"./tools/tool-installs.js";import{toolHome as F}from"./tools/types.js";import{logger as J}from"../utils/logger.js";let V=null;export function parseManifest(t){const e=JSON.parse(t);if(1!==e.schema||!Array.isArray(e.components))throw new Error("components.json: schema must be 1 with a components list");const o=new Set;for(const t of e.components){if(!t.id||!t.name||!["runtime","cli","app"].includes(t.category))throw new Error(`components.json: bad entry ${JSON.stringify(t.id)}`);for(const e of[t.id,...t.aliases??[]]){if(o.has(e))throw new Error(`components.json: duplicate name ${e}`);o.add(e)}if("runtime"===t.category&&(!t.detect||"script"!==t.install.type))throw new Error(`components.json: runtime ${t.id} needs detect + a script`);if("cli"===t.category&&!t.adapter)throw new Error(`components.json: cli ${t.id} needs an adapter`);if("app"===t.category&&!t.app)throw new Error(`components.json: app ${t.id} needs an app id`)}for(const t of e.components)for(const e of t.requires)if(!o.has(e))throw new Error(`components.json: ${t.id} requires unknown ${e}`);return e}function H(){return V||(V=parseManifest(n(function(){const t=u(f(import.meta.url)),o=[d(t,"..","..","components.json"),d(t,"..","components.json"),d(t,"components.json")],n=o.find(t=>e(t));if(!n)throw new Error(`components.json not found, searched: ${o.join(", ")}`);return n}(),"utf-8"))),V}export function setComponentManifestForTests(t){V=null===t?null:parseManifest(t)}export function listComponents(){return H().components}export function resolveComponent(t){const e=t.trim().toLowerCase();return listComponents().find(t=>t.id===e||(t.aliases??[]).includes(e))}let W=null;export function componentPlatform(){return W??process.platform}export function expandUrl(t){const e=h().installMirror??{};let o=!1;const n=t.replace(/\{(scripts|agy|devtools)\}/g,(t,n)=>{const r="devtools"===n?H().devtools:e[n];return r||(o=!0),r??""});return o?null:n}export function componentSource(t,e=componentPlatform()){return(t.sources[e]??t.sources.all??"").replace(/\{(scripts|agy|devtools)\}/g,(t,e)=>("devtools"===e?H().devtools:h().installMirror?.[e])??t)}export function installBlocker(t=process.env,e=componentPlatform()){return"win32"===e?/\\system32\\config\\systemprofile/i.test(t.USERPROFILE??"")||t.USERNAME?.endsWith("$")?"system":null:0===(G??process.getuid?.())&&t.SUDO_USER&&"root"!==t.SUDO_USER?"sudo":null}let G=null,q=!0,K=e=>{const o=/\.(cmd|bat)$/i.test(e)?t(`"${e}" --version`,{encoding:"utf-8",timeout:1e4,windowsHide:!0,shell:!0,stdio:["ignore","pipe","pipe"]}):t(e,["--version"],{encoding:"utf-8",timeout:1e4,windowsHide:!0,stdio:["ignore","pipe","pipe"]});return`${o.stdout??""}${o.stderr??""}`},X=()=>0===t("xcode-select",["-p"],{stdio:"ignore",timeout:1e4}).status;function Z(t){try{return a(t)}catch{return t}}function z(t,e){return"win32"===e?[`${t}.exe`,`${t}.cmd`]:[t]}export function knownRuntimePaths(t,e=componentPlatform(),o=process.env){const n=F();if("node"===t){if("win32"===e){const t=o.FNM_DIR||d(o.APPDATA||d(n,"AppData","Roaming"),"fnm");return[d(t,"aliases","default","node.exe"),d(o.LOCALAPPDATA||d(n,"AppData","Local"),"Programs","nodejs","node.exe")]}return[d(Y(e,o),"aliases","default","bin","node"),"/opt/homebrew/bin/node","/usr/local/bin/node","/usr/bin/node"]}if("uv"===t)return"win32"===e?[d(n,".local","bin","uv.exe"),d(n,".cargo","bin","uv.exe")]:[d(o.UV_INSTALL_DIR||d(n,".local","bin"),"uv"),d(n,".cargo","bin","uv"),"/opt/homebrew/bin/uv","/usr/local/bin/uv"];if("git"===t){if("win32"===e){const t=o.LOCALAPPDATA||d(n,"AppData","Local");return[d(t,"Programs","Git","cmd","git.exe"),d(o.ProgramFiles||"C:\\Program Files","Git","cmd","git.exe")]}return["/opt/homebrew/bin/git","/usr/local/bin/git","/usr/bin/git"]}return[]}function Y(t,o){if(o.FNM_DIR)return o.FNM_DIR;const n=F();if("win32"===t)return d(o.APPDATA||d(n,"AppData","Roaming"),"fnm");const r=d(n,".local","share","fnm"),a=d(n,"Library","Application Support","fnm");return"darwin"===t&&!e(r)&&e(a)?a:r}let Q=()=>{const e=e=>{const o=`${t("reg",["query",e,"/v","Path"],{encoding:"utf-8",timeout:1e4,windowsHide:!0,stdio:["ignore","pipe","ignore"]}).stdout??""}`.split(/\r?\n/).find(t=>/\sREG_(EXPAND_)?SZ\s/.test(t));return o?o.replace(/^.*?REG_(EXPAND_)?SZ\s+/,""):""};return[e("HKCU\\Environment"),e("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment")].flatMap(t=>{return(e=t,e.replace(/%([^%]+)%/g,(t,e)=>process.env[e]??t)).split(";");var e}).map(t=>t.trim().replace(/^"|"$/g,"")).filter(Boolean)},tt=null;export function probeRuntime(t,e=componentPlatform()){const o=t.detect,n=new RegExp(o.pattern),r=new Set,a=[],s=o=>{if(!function(t){try{return i(t).isFile()}catch{return!1}}(o))return;if("darwin"===e&&"git"===t.id&&"/usr/bin/git"===o&&!X())return;const s=Z(o),l="win32"===e?s.toLowerCase():s;if(r.has(l))return;r.add(l);const c=n.exec(K(o));c&&a.push({path:o,version:c[1]??null})},l=(process.env.PATH??"").split("win32"===e?";":c);"win32"===e&&l.push(...tt??=st(()=>Q())??[]);for(const t of l)if(t&&p(t))for(const n of z(o.command,e))s(d(t,n));for(const o of knownRuntimePaths(t.id,e))(q||o.startsWith(F()))&&s(o);return a}export function scriptTarget(t,e=componentPlatform(),o=process.env){const n=F();return"node"===t?"win32"===e?d(Y(e,o),"aliases","default","node.exe"):d(Y(e,o),"aliases","default","bin","node"):"uv"===t?d(o.UV_INSTALL_DIR||d(n,".local","bin"),"win32"===e?"uv.exe":"uv"):"git"===t&&"win32"===e?d(o.LOCALAPPDATA||d(n,"AppData","Local"),"Programs","Git","cmd","git.exe"):null}export function runtimeManager(t,e,o=componentPlatform(),n=process.env){const r=Z(e),a=t=>"win32"===o?t.replace(/\//g,"\\").toLowerCase():t,s=a(r),i=a(e),l="win32"===o?"\\":"\\"===m?"/":m,c=t=>s.includes(a(t))||i.includes(a(t)),p=t=>s.startsWith(a(t)+l)||i.startsWith(a(t)+l),f=F(),g=/[\\/](Cellar|Caskroom|homebrew)[\\/]/i.test(r)||/^\/opt\/homebrew\//.test(e)||/^\/usr\/local\/(Cellar|opt)\//.test(r);if("node"===t)return c(`${l}fnm${l}`)||p(Y(o,n))?{by:"fnm",auto:!0}:g?{by:"brew",auto:!1,hint:"brew upgrade node"}:c(`${l}.nvm${l}`)?{by:"nvm",auto:!1,hint:"nvm install --lts --reinstall-packages-from=current"}:c(`${l}nvm${l}`)&&"win32"===o?{by:"nvm",auto:!1,hint:"nvm install lts"}:c(`${l}.volta${l}`)||c(`${l}volta${l}`)?{by:"volta",auto:!1,hint:"volta install node@lts"}:c(`${l}scoop${l}`)?{by:"scoop",auto:!1,hint:"scoop update nodejs-lts"}:c(`${l}.asdf${l}`)?{by:"asdf",auto:!1,hint:"asdf install nodejs latest"}:c(`${l}mise${l}`)?{by:"mise",auto:!1,hint:"mise use -g node@lts"}:{by:"system",auto:!1};if("uv"===t)return[n.UV_INSTALL_DIR,d(f,".local","bin"),d(f,".cargo","bin")].filter(Boolean).some(t=>a(u(e))===a(t)||a(u(r))===a(t))?{by:"standalone",auto:!0}:g?{by:"brew",auto:!1,hint:"brew upgrade uv"}:c("pipx")?{by:"pipx",auto:!1,hint:"pipx upgrade uv"}:c(`${l}scoop${l}`)?{by:"scoop",auto:!1,hint:"scoop update uv"}:c("winget")?{by:"winget",auto:!1,hint:"winget upgrade astral-sh.uv"}:c("site-packages")||c(`${l}python`)?{by:"pip",auto:!1,hint:"pip install -U uv"}:{by:"other",auto:!1};if("git"===t){if("win32"===o){const t=n.LOCALAPPDATA||d(f,"AppData","Local");return p(d(t,"Programs","Git"))?{by:"git-for-windows-user",auto:!0}:c(`${l}scoop${l}`)?{by:"scoop",auto:!1,hint:"scoop update git"}:{by:"git-for-windows",auto:!1,hint:"git update-git-for-windows"}}return g?{by:"brew",auto:!1,hint:"brew upgrade git"}:"darwin"===o?{by:"xcode",auto:!1,hint:"softwareupdate --list"}:{by:"system",auto:!1}}return{by:"other",auto:!1}}function et(){return d(v.getConfigDir(),"component-releases.json")}function ot(){try{const t=JSON.parse(n(et(),"utf-8"));return t&&"object"==typeof t?t:{}}catch{return{}}}function nt(t,e){try{o(v.getConfigDir(),{recursive:!0}),l(et(),JSON.stringify({...ot(),[t]:e},null,2))}catch(t){J.logError("components.writeCache",t)}}let rt=async(t,e=15e3)=>{const o=await fetch(t,{signal:AbortSignal.timeout(e)});if(!o.ok)throw new Error(`HTTP ${o.status} ${t}`);return o.text()};const at=/(\d+\.\d+\.\d+)/;export function latestNodeLts(t){const e=JSON.parse(t).find(t=>"string"==typeof t.lts&&t.lts&&"string"==typeof t.version);if(!e)throw new Error("no LTS release in the Node index");return e.version.replace(/^v/,"")}export function devtoolsVersion(t,e){const o=t.split(/\r?\n/).find(t=>t.startsWith(`${e}=`)),n=o?at.exec(o.slice(e.length+1)):null;if(!n)throw new Error(`${e} is not in versions.txt`);return n[1]}export async function latestVersion(t,e={}){const o=componentPlatform(),n=`${t.id}:${o}`,r=ot()[n],a=r&&Date.now()-r.checked_at<(r.version?36e5:6e5);if(r&&a&&!e.refresh)return{version:r.version??null,...r.error?{error:r.error}:{}};try{const e=await async function(t,e){const o=t.latest;switch(o.type){case"node-lts":return latestNodeLts(await rt(o.url));case"devtools":return o.platforms&&!o.platforms.includes(e)?null:devtoolsVersion(await rt(`${H().devtools}/versions.txt`),o.key);case"npm":{if(o.staleTag){const e=N(t.adapter??"")?.installSpec,o=e?await B(e):"latest";if("latest"!==o)return o}const e=JSON.parse(await rt(`${I}/${o.package}/latest`));if(!e.version)throw new Error(`no version for ${o.package}`);return e.version}case"version-file":{const t=expandUrl(o.url);if(!t)return null;const e=at.exec(await rt(t));if(!e)throw new Error(`no version in ${t}`);return e[1]}default:return null}}(t,o);return e&&nt(n,{version:e,checked_at:Date.now()}),{version:e}}catch(e){const o=e instanceof Error?e.message:String(e);return J.logError(`components.latest(${t.id})`,e),nt(n,{error:o,checked_at:Date.now()}),{version:r?.version??null,error:o}}}export async function prefetchLatest(t,e={}){const o=componentPlatform(),n=await Promise.all(t.map(async t=>t.platforms.includes(o)?"app"===t.category?[t.id,x(t.app)?await b(t.app,e):{version:null}]:[t.id,await latestVersion(t,e)]:[t.id,{version:null}]));return new Map(n)}export async function componentStatus(t,e={}){const o=componentPlatform(),n={id:t.id,name:t.name,category:t.category,supported:t.platforms.includes(o),source:componentSource(t,o)},r={...n,installed:!1,current:null,latest:null,outdated:!1,path:null,managed_by:null,auto_upgrade:!1,blocker:n.supported?installBlocker():"unsupported_platform"};if(!n.supported)return r;if("app"===t.category){const o=x(t.app);if(!o)return{...r,blocker:"unsupported_platform"};const n=e.latest?$(t.app,e.latest):e.offline?P(t.app):await _(t.app,{refresh:e.refresh});return{...r,installed:n.installed,current:n.current,latest:n.latest,outdated:n.outdated,path:n.installed?st(()=>o.appInstaller.installedPath()):null,managed_by:n.installed?"app":null,auto_upgrade:n.installed&&!n.blocker,blocker:n.blocker??installBlocker(),...n.error?{error:n.error}:{}}}let a=null,s=null,i=null;if("cli"===t.category){const e=N(t.adapter)?.installSpec,o=e?O(e)[0]:void 0;o&&(a=o.version,s=o.path,i={by:o.kind,auto:!0})}else{const e=probeRuntime(t,o)[0];e&&(a=e.version,s=e.path,i=runtimeManager(t.id,e.path,o))}const{version:l,error:c}=e.latest?e.latest:e.offline?{version:ot()[`${t.id}:${o}`]?.version??null,error:void 0}:await latestVersion(t,{refresh:e.refresh}),u=l?ot()[`${t.id}:${o}:ceiling`]:void 0,p=Boolean(u?.version&&u.error===l&&a&&A(a,u.version)>=0);return{...r,installed:Boolean(s),current:a,latest:l,outdated:Boolean(a&&l&&A(a,l)<0&&!p),...p?{capped_at:u.version}:{},path:s,managed_by:i?.by??null,auto_upgrade:i?.auto??!1,...i?.hint?{hint:i.hint}:{},...c?{error:c}:{}}}function st(t){try{return t()}catch{return null}}const it={idleMs:18e4,timeoutMs:36e5};let lt,ct=async(t,e)=>(lt=await R({name:(/([a-z0-9-]+)\.(?:ps1|sh)$/i.exec(t)?.[1]??"runtime").toLowerCase(),url:t,platform:componentPlatform(),limits:{...it,env:e},output:E,run:(t,e,o)=>C(t,e,o)}),"ok"===lt.outcome),ut=async(t,e)=>"ok"===await C(t,e,it);function pt(t){k()?process.stderr.write(t+"\n"):console.log(t)}export function globalPackages(t,e=componentPlatform()){const o=u(Z(t)),a="win32"===e?d(o,"node_modules"):d(u(o),"lib","node_modules"),s=[],i=(t,e)=>{try{const o=JSON.parse(n(d(t,"package.json"),"utf-8"));o.version&&s.push({name:e,version:o.version})}catch{}};let l=[];try{l=r(a)}catch{return s}for(const t of l)if(!t.startsWith(".")&&"npm"!==t&&"corepack"!==t)if(t.startsWith("@"))try{for(const e of r(d(a,t)))e.startsWith(".")||i(d(a,t,e),`${t}/${e}`)}catch{}else i(d(a,t),t);return s}function dt(t,e,o={}){const n=["installed","upgraded","reinstalled","up_to_date","already_installed"].includes(e);return{tool:t.id,category:t.category,current:t.current,latest:t.latest,result:e,version_after:null,ok:n,...o}}function mt(t){return`${w} upgrade ${t}`}export async function runRuntime(t,e,n={}){const r=Date.now(),a=componentPlatform(),s=await componentStatus(t,{refresh:!0}),i=t.name;if(!s.supported)return pt(g.yellow(" ! "+y.t("components.unsupported_platform",{tool:i}))),dt(s,"unavailable",{reason:"unsupported_platform"});if(s.blocker)return pt(g.yellow(" ! "+function(t,e){return y.t(`components.blocked_${t}`,{tool:e})}(s.blocker,i))),dt(s,"unavailable",{reason:s.blocker});const l=function(t){if("script"!==t.install.type)return null;const e=h().installMirror?.scripts;return e?`${e}/${t.install.script}.${"win32"===componentPlatform()?"ps1":"sh"}`:null}(t);if(s.installed&&!n.force){const o=g.gray(`(${s.path})`);if(s.latest&&!s.outdated)return pt(g.green(" √ "+y.t("components.up_to_date",{tool:i,current:s.current??"?"}))+o),"upgrade"===e&&pt(g.gray(" "+y.t("components.force_hint",{command:`${mt(t.id)} --force`}))),dt(s,"install"===e?"already_installed":"up_to_date");if("install"===e)return pt(g.green(" √ "+y.t("components.already_installed",{tool:i,current:s.current??"?"}))+o),s.outdated&&pt(g.yellow(" ! "+upgradeAdvice(s))),dt(s,"already_installed",s.outdated?{hint:upgradeAdvice(s)}:{});if(!s.latest)return pt(g.yellow(" ! "+y.t("components.no_latest",{tool:i,current:s.current??"?",how:gt(s)}))),dt(s,"manual",{reason:s.error??"no_latest",hint:s.hint});if(!s.auto_upgrade)return pt(g.yellow(" ! "+upgradeAdvice(s))),dt(s,"manual",{hint:s.hint})}if(!l)return pt(g.yellow(" ! "+y.t("components.no_mirror",{tool:i}))),dt(s,"unavailable",{reason:"no_mirror"});s.installed&&!s.auto_upgrade&&pt(g.yellow(" ! "+y.t("components.force_beside",{tool:i,path:s.path??"?",by:s.managed_by??"?"})));const p={};s.installed&&"script"===t.install.type&&Object.assign(p,t.install.forceEnv??{}),"uv"===t.id&&s.installed&&s.auto_upgrade&&s.path&&(p.UV_INSTALL_DIR=u(s.path));const d=t.upgrade?.migrateGlobalPackages&&s.installed&&"fnm"===s.managed_by&&s.path,m=d?globalPackages(s.path,a):[],f=d?Z(s.path):null;pt(g.gray(" "+y.t(s.installed?"components.upgrading":"components.installing",{tool:i,latest:s.latest??"",source:s.source}))),S(`component:${t.id}`,"start",{detail:{mode:e,force:Boolean(n.force),current:s.current}}),d&&m.length&&f&&function(t){try{o(v.getConfigDir(),{recursive:!0}),M(wt(),JSON.stringify({...t,noted_at:Date.now()},null,2),384)}catch(t){J.logError("components: note migration",t)}}({packages:m,old_node:f}),lt=void 0;const w=await ct(l,p);U(),tt=null;const b=probeRuntime(t,a),_=scriptTarget(t.id,a,{...process.env,...p}),$=(_?b.find(t=>{return e=t.path,o=_,"win32"===a?Z(e).toLowerCase()===Z(o).toLowerCase():Z(e)===Z(o);var e,o}):void 0)??b.find(e=>runtimeManager(t.id,e.path,a).auto)??b[0];if(!w||!$){vt();const e=lt;return S(`component:${t.id}`,"fail",{duration_ms:Date.now()-r,error:D(E())||void 0,detail:{reason:w?"not_found_after":"script_failed",...e?{how:e.how,...e.fileProblem?{file_problem:e.fileProblem}:{},...T(e.trace)}:{},...L(),...j()}}),pt(g.red(" × "+y.t("components.script_failed",{tool:i,command:(s.installed?mt:ft)(t.id)}))),dt(s,"failed",{reason:w?"not_found_after":"script_failed"})}let P;d&&m.length&&f&&Z($.path)!==f&&(P=await ht(m,$.path,a)?"done":"failed"),"failed"!==P&&vt();const x=b[0];x&&x.path!==$.path&&x.version&&$.version&&A(x.version,$.version)<0&&pt(g.yellow(" ! "+y.t("components.path_shadowed",{tool:i,active:x.path,version:$.version,path:$.path}))),s.latest&&$.version&&A($.version,s.latest)<0&&(nt(`${t.id}:${a}:ceiling`,{version:$.version,error:s.latest,checked_at:Date.now()}),pt(g.yellow(" ! "+y.t("components.capped",{tool:i,latest:s.latest,version:$.version})))),S(`component:${t.id}`,"ok",{duration_ms:Date.now()-r,detail:{version:$.version,...P?{migration:P}:{}}});const k=s.installed?n.force&&!s.outdated?"reinstalled":"upgraded":"installed";var C;return pt(g.green(" √ "+("installed"===k?y.t("components.installed",{tool:i,version:$.version??"?"}):"reinstalled"===k?y.t("components.reinstalled",{tool:i,version:$.version??"?"}):y.t("components.upgraded",{tool:i,from:s.current??"?",to:$.version??"?"})))+g.gray(`(${$.path})`)),C=u($.path),(process.env.PATH??"").split("win32"===componentPlatform()?";":c).some(t=>"win32"===componentPlatform()?t.toLowerCase()===C.toLowerCase():t===C)||pt(g.gray(" "+y.t("components.new_terminal"))),dt(s,k,{version_after:$.version})}function ft(t){return`${w} install ${t}`}function gt(t){return t.hint?t.hint:y.t(`components.how_${t.managed_by??"other"}`,{tool:t.name})}export function upgradeAdvice(t){return t.auto_upgrade?y.t("components.outdated_auto",{tool:t.name,current:t.current??"?",latest:t.latest??"?",command:mt(t.id)}):y.t("components.outdated_manual",{tool:t.name,current:t.current??"?",latest:t.latest??"?",by:t.managed_by??"?",how:gt(t),command:`${mt(t.id)} --force`})}async function ht(t,e,o){const n=new Set(globalPackages(e,o).map(t=>t.name)),r=t.filter(t=>!n.has(t.name));if(!r.length)return!0;pt(g.gray(" "+y.t("components.migrating_globals",{packages:r.map(t=>t.name).join("、")})));const a=function(t,e){const o=u(Z(t));return d(o,"win32"===e?"npm.cmd":"npm")}(e,o),s=["install","-g",...r.map(t=>`${t.name}@${t.version}`),`--registry=${I}`,"--no-fund","--no-audit","--loglevel=error"];return!!await ut(a,s)||(pt(g.yellow(" ! "+y.t("components.migrate_failed",{command:[a,...s].join(" ")}))),!1)}const wt=()=>d(v.getConfigDir(),"node-migration.json");function vt(){try{s(wt(),{force:!0})}catch(t){J.logError("components: clear migration",t)}}export async function resumePendingMigration(){let t;try{if(!e(wt()))return"none";t=JSON.parse(n(wt(),"utf-8"))}catch{return vt(),"none"}const o=componentPlatform(),r=listComponents().find(t=>"node"===t.id),a=r?probeRuntime(r,o).find(t=>"fnm"===runtimeManager("node",t.path,o).by):void 0;if(!Array.isArray(t.packages)||"number"!=typeof t.noted_at||Date.now()-t.noted_at>2592e6||!a||Z(a.path)===t.old_node)return vt(),"none";S("component:node","start",{detail:{mode:"resume-migration"}});const s=await ht(t.packages,a.path,o);return s&&vt(),S("component:node",s?"ok":"fail",{detail:{mode:"resume-migration",migration:s?"done":"failed"}}),s?"done":"failed"}export function setComponentDepsForTests(t){void 0!==t.platform&&(W=t.platform),void 0!==t.uid&&(G=t.uid),void 0!==t.systemPaths&&(q=t.systemPaths),t.registryPath&&(Q=t.registryPath,tt=null),t.versionRunner&&(K=t.versionRunner),t.macDeveloperTools&&(X=t.macDeveloperTools),t.fetchText&&(rt=t.fetchText),t.scriptRunner&&(ct=t.scriptRunner),t.commandRunner&&(ut=t.commandRunner)}
1
+ import{spawnSync as t}from"child_process";import{existsSync as e,mkdirSync as o,readFileSync as n,readdirSync as r,realpathSync as a,rmSync as s,statSync as i,writeFileSync as l}from"fs";import{delimiter as c,dirname as u,isAbsolute as p,join as d,sep as m}from"path";import{fileURLToPath as f}from"url";import g from"chalk";import{brand as h,CLI_NAME as w}from"./brand.js";import{configManager as v}from"./config.js";import{npmCacheArgs as y}from"./npm-cache.js";import{i18n as b}from"./i18n.js";import{appLatest as _,appStatus as $,appStatusWith as P,cachedAppStatus as x,getApp as A}from"./app-update.js";import{compareVersions as k}from"./model-registry.js";import{isJsonMode as D}from"./runtime-options.js";import{maskSecrets as S,track as j}from"./telemetry.js";import{failureContext as L,lastCommandExit as E,lastCommandOutput as C,runWatched as R}from"./tool-upgrade.js";import{runInstallScript as T,traceSummary as M}from"./install-script.js";import{atomicWriteFile as N}from"./tools/backup.js";import{getAdapter as O}from"./tools/registry.js";import{findInstallsIncludingNative as U,forgetInstalls as I,NPM_MIRROR as B,npmMirrorVersion as F}from"./tools/tool-installs.js";import{toolHome as J}from"./tools/types.js";import{logger as V}from"../utils/logger.js";let H=null;export function parseManifest(t){const e=JSON.parse(t);if(1!==e.schema||!Array.isArray(e.components))throw new Error("components.json: schema must be 1 with a components list");const o=new Set;for(const t of e.components){if(!t.id||!t.name||!["runtime","cli","app"].includes(t.category))throw new Error(`components.json: bad entry ${JSON.stringify(t.id)}`);for(const e of[t.id,...t.aliases??[]]){if(o.has(e))throw new Error(`components.json: duplicate name ${e}`);o.add(e)}if("runtime"===t.category&&(!t.detect||"script"!==t.install.type))throw new Error(`components.json: runtime ${t.id} needs detect + a script`);if("cli"===t.category&&!t.adapter)throw new Error(`components.json: cli ${t.id} needs an adapter`);if("app"===t.category&&!t.app)throw new Error(`components.json: app ${t.id} needs an app id`)}for(const t of e.components)for(const e of t.requires)if(!o.has(e))throw new Error(`components.json: ${t.id} requires unknown ${e}`);return e}function W(){return H||(H=parseManifest(n(function(){const t=u(f(import.meta.url)),o=[d(t,"..","..","components.json"),d(t,"..","components.json"),d(t,"components.json")],n=o.find(t=>e(t));if(!n)throw new Error(`components.json not found, searched: ${o.join(", ")}`);return n}(),"utf-8"))),H}export function setComponentManifestForTests(t){H=null===t?null:parseManifest(t)}export function listComponents(){return W().components}export function resolveComponent(t){const e=t.trim().toLowerCase();return listComponents().find(t=>t.id===e||(t.aliases??[]).includes(e))}let G=null;export function componentPlatform(){return G??process.platform}export function expandUrl(t){const e=h().installMirror??{};let o=!1;const n=t.replace(/\{(scripts|agy|devtools)\}/g,(t,n)=>{const r="devtools"===n?W().devtools:e[n];return r||(o=!0),r??""});return o?null:n}export function componentSource(t,e=componentPlatform()){return(t.sources[e]??t.sources.all??"").replace(/\{(scripts|agy|devtools)\}/g,(t,e)=>("devtools"===e?W().devtools:h().installMirror?.[e])??t)}export function installBlocker(t=process.env,e=componentPlatform()){return"win32"===e?/\\system32\\config\\systemprofile/i.test(t.USERPROFILE??"")||t.USERNAME?.endsWith("$")?"system":null:0===(q??process.getuid?.())&&t.SUDO_USER&&"root"!==t.SUDO_USER?"sudo":null}let q=null,K=!0,X=e=>{const o=/\.(cmd|bat)$/i.test(e)?t(`"${e}" --version`,{encoding:"utf-8",timeout:1e4,windowsHide:!0,shell:!0,stdio:["ignore","pipe","pipe"]}):t(e,["--version"],{encoding:"utf-8",timeout:1e4,windowsHide:!0,stdio:["ignore","pipe","pipe"]});return`${o.stdout??""}${o.stderr??""}`},Z=()=>0===t("xcode-select",["-p"],{stdio:"ignore",timeout:1e4}).status;function z(t){try{return a(t)}catch{return t}}function Y(t,e){return"win32"===e?[`${t}.exe`,`${t}.cmd`]:[t]}export function knownRuntimePaths(t,e=componentPlatform(),o=process.env){const n=J();if("node"===t){if("win32"===e){const t=o.FNM_DIR||d(o.APPDATA||d(n,"AppData","Roaming"),"fnm");return[d(t,"aliases","default","node.exe"),d(o.LOCALAPPDATA||d(n,"AppData","Local"),"Programs","nodejs","node.exe")]}return[d(Q(e,o),"aliases","default","bin","node"),"/opt/homebrew/bin/node","/usr/local/bin/node","/usr/bin/node"]}if("uv"===t)return"win32"===e?[d(n,".local","bin","uv.exe"),d(n,".cargo","bin","uv.exe")]:[d(o.UV_INSTALL_DIR||d(n,".local","bin"),"uv"),d(n,".cargo","bin","uv"),"/opt/homebrew/bin/uv","/usr/local/bin/uv"];if("git"===t){if("win32"===e){const t=o.LOCALAPPDATA||d(n,"AppData","Local");return[d(t,"Programs","Git","cmd","git.exe"),d(o.ProgramFiles||"C:\\Program Files","Git","cmd","git.exe")]}return["/opt/homebrew/bin/git","/usr/local/bin/git","/usr/bin/git"]}return[]}function Q(t,o){if(o.FNM_DIR)return o.FNM_DIR;const n=J();if("win32"===t)return d(o.APPDATA||d(n,"AppData","Roaming"),"fnm");const r=d(n,".local","share","fnm"),a=d(n,"Library","Application Support","fnm");return"darwin"===t&&!e(r)&&e(a)?a:r}let tt=()=>{const e=e=>{const o=`${t("reg",["query",e,"/v","Path"],{encoding:"utf-8",timeout:1e4,windowsHide:!0,stdio:["ignore","pipe","ignore"]}).stdout??""}`.split(/\r?\n/).find(t=>/\sREG_(EXPAND_)?SZ\s/.test(t));return o?o.replace(/^.*?REG_(EXPAND_)?SZ\s+/,""):""};return[e("HKCU\\Environment"),e("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment")].flatMap(t=>{return(e=t,e.replace(/%([^%]+)%/g,(t,e)=>process.env[e]??t)).split(";");var e}).map(t=>t.trim().replace(/^"|"$/g,"")).filter(Boolean)},et=null;export function probeRuntime(t,e=componentPlatform()){const o=t.detect,n=new RegExp(o.pattern),r=new Set,a=[],s=o=>{if(!function(t){try{return i(t).isFile()}catch{return!1}}(o))return;if("darwin"===e&&"git"===t.id&&"/usr/bin/git"===o&&!Z())return;const s=z(o),l="win32"===e?s.toLowerCase():s;if(r.has(l))return;r.add(l);const c=n.exec(X(o));c&&a.push({path:o,version:c[1]??null})},l=(process.env.PATH??"").split("win32"===e?";":c);"win32"===e&&l.push(...et??=it(()=>tt())??[]);for(const t of l)if(t&&p(t))for(const n of Y(o.command,e))s(d(t,n));for(const o of knownRuntimePaths(t.id,e))(K||o.startsWith(J()))&&s(o);return a}export function scriptTarget(t,e=componentPlatform(),o=process.env){const n=J();return"node"===t?"win32"===e?d(Q(e,o),"aliases","default","node.exe"):d(Q(e,o),"aliases","default","bin","node"):"uv"===t?d(o.UV_INSTALL_DIR||d(n,".local","bin"),"win32"===e?"uv.exe":"uv"):"git"===t&&"win32"===e?d(o.LOCALAPPDATA||d(n,"AppData","Local"),"Programs","Git","cmd","git.exe"):null}export function runtimeManager(t,e,o=componentPlatform(),n=process.env){const r=z(e),a=t=>"win32"===o?t.replace(/\//g,"\\").toLowerCase():t,s=a(r),i=a(e),l="win32"===o?"\\":"\\"===m?"/":m,c=t=>s.includes(a(t))||i.includes(a(t)),p=t=>s.startsWith(a(t)+l)||i.startsWith(a(t)+l),f=J(),g=/[\\/](Cellar|Caskroom|homebrew)[\\/]/i.test(r)||/^\/opt\/homebrew\//.test(e)||/^\/usr\/local\/(Cellar|opt)\//.test(r);if("node"===t)return c(`${l}fnm${l}`)||p(Q(o,n))?{by:"fnm",auto:!0}:g?{by:"brew",auto:!1,hint:"brew upgrade node"}:c(`${l}.nvm${l}`)?{by:"nvm",auto:!1,hint:"nvm install --lts --reinstall-packages-from=current"}:c(`${l}nvm${l}`)&&"win32"===o?{by:"nvm",auto:!1,hint:"nvm install lts"}:c(`${l}.volta${l}`)||c(`${l}volta${l}`)?{by:"volta",auto:!1,hint:"volta install node@lts"}:c(`${l}scoop${l}`)?{by:"scoop",auto:!1,hint:"scoop update nodejs-lts"}:c(`${l}.asdf${l}`)?{by:"asdf",auto:!1,hint:"asdf install nodejs latest"}:c(`${l}mise${l}`)?{by:"mise",auto:!1,hint:"mise use -g node@lts"}:{by:"system",auto:!1};if("uv"===t)return[n.UV_INSTALL_DIR,d(f,".local","bin"),d(f,".cargo","bin")].filter(Boolean).some(t=>a(u(e))===a(t)||a(u(r))===a(t))?{by:"standalone",auto:!0}:g?{by:"brew",auto:!1,hint:"brew upgrade uv"}:c("pipx")?{by:"pipx",auto:!1,hint:"pipx upgrade uv"}:c(`${l}scoop${l}`)?{by:"scoop",auto:!1,hint:"scoop update uv"}:c("winget")?{by:"winget",auto:!1,hint:"winget upgrade astral-sh.uv"}:c("site-packages")||c(`${l}python`)?{by:"pip",auto:!1,hint:"pip install -U uv"}:{by:"other",auto:!1};if("git"===t){if("win32"===o){const t=n.LOCALAPPDATA||d(f,"AppData","Local");return p(d(t,"Programs","Git"))?{by:"git-for-windows-user",auto:!0}:c(`${l}scoop${l}`)?{by:"scoop",auto:!1,hint:"scoop update git"}:{by:"git-for-windows",auto:!1,hint:"git update-git-for-windows"}}return g?{by:"brew",auto:!1,hint:"brew upgrade git"}:"darwin"===o?{by:"xcode",auto:!1,hint:"softwareupdate --list"}:{by:"system",auto:!1}}return{by:"other",auto:!1}}function ot(){return d(v.getConfigDir(),"component-releases.json")}function nt(){try{const t=JSON.parse(n(ot(),"utf-8"));return t&&"object"==typeof t?t:{}}catch{return{}}}function rt(t,e){try{o(v.getConfigDir(),{recursive:!0}),l(ot(),JSON.stringify({...nt(),[t]:e},null,2))}catch(t){V.logError("components.writeCache",t)}}let at=async(t,e=15e3)=>{const o=await fetch(t,{signal:AbortSignal.timeout(e)});if(!o.ok)throw new Error(`HTTP ${o.status} ${t}`);return o.text()};const st=/(\d+\.\d+\.\d+)/;export function latestNodeLts(t){const e=JSON.parse(t).find(t=>"string"==typeof t.lts&&t.lts&&"string"==typeof t.version);if(!e)throw new Error("no LTS release in the Node index");return e.version.replace(/^v/,"")}export function devtoolsVersion(t,e){const o=t.split(/\r?\n/).find(t=>t.startsWith(`${e}=`)),n=o?st.exec(o.slice(e.length+1)):null;if(!n)throw new Error(`${e} is not in versions.txt`);return n[1]}export async function latestVersion(t,e={}){const o=componentPlatform(),n=`${t.id}:${o}`,r=nt()[n],a=r&&Date.now()-r.checked_at<(r.version?36e5:6e5);if(r&&a&&!e.refresh)return{version:r.version??null,...r.error?{error:r.error}:{}};try{const e=await async function(t,e){const o=t.latest;switch(o.type){case"node-lts":return latestNodeLts(await at(o.url));case"devtools":return o.platforms&&!o.platforms.includes(e)?null:devtoolsVersion(await at(`${W().devtools}/versions.txt`),o.key);case"npm":{if(o.staleTag){const e=O(t.adapter??"")?.installSpec,o=e?await F(e):"latest";if("latest"!==o)return o}const e=JSON.parse(await at(`${B}/${o.package}/latest`));if(!e.version)throw new Error(`no version for ${o.package}`);return e.version}case"version-file":{const t=expandUrl(o.url);if(!t)return null;const e=st.exec(await at(t));if(!e)throw new Error(`no version in ${t}`);return e[1]}default:return null}}(t,o);return e&&rt(n,{version:e,checked_at:Date.now()}),{version:e}}catch(e){const o=e instanceof Error?e.message:String(e);return V.logError(`components.latest(${t.id})`,e),rt(n,{error:o,checked_at:Date.now()}),{version:r?.version??null,error:o}}}export async function prefetchLatest(t,e={}){const o=componentPlatform(),n=await Promise.all(t.map(async t=>t.platforms.includes(o)?"app"===t.category?[t.id,A(t.app)?await _(t.app,e):{version:null}]:[t.id,await latestVersion(t,e)]:[t.id,{version:null}]));return new Map(n)}export async function componentStatus(t,e={}){const o=componentPlatform(),n={id:t.id,name:t.name,category:t.category,supported:t.platforms.includes(o),source:componentSource(t,o)},r={...n,installed:!1,current:null,latest:null,outdated:!1,path:null,managed_by:null,auto_upgrade:!1,blocker:n.supported?installBlocker():"unsupported_platform"};if(!n.supported)return r;if("app"===t.category){const o=A(t.app);if(!o)return{...r,blocker:"unsupported_platform"};const n=e.latest?P(t.app,e.latest):e.offline?x(t.app):await $(t.app,{refresh:e.refresh});return{...r,installed:n.installed,current:n.current,latest:n.latest,outdated:n.outdated,path:n.installed?it(()=>o.appInstaller.installedPath()):null,managed_by:n.installed?"app":null,auto_upgrade:n.installed&&!n.blocker,blocker:n.blocker??installBlocker(),...n.error?{error:n.error}:{}}}let a=null,s=null,i=null;if("cli"===t.category){const e=O(t.adapter)?.installSpec,o=e?U(e)[0]:void 0;o&&(a=o.version,s=o.path,i={by:o.kind,auto:!0})}else{const e=probeRuntime(t,o)[0];e&&(a=e.version,s=e.path,i=runtimeManager(t.id,e.path,o))}const{version:l,error:c}=e.latest?e.latest:e.offline?{version:nt()[`${t.id}:${o}`]?.version??null,error:void 0}:await latestVersion(t,{refresh:e.refresh}),u=l?nt()[`${t.id}:${o}:ceiling`]:void 0,p=Boolean(u?.version&&u.error===l&&a&&k(a,u.version)>=0);return{...r,installed:Boolean(s),current:a,latest:l,outdated:Boolean(a&&l&&k(a,l)<0&&!p),...p?{capped_at:u.version}:{},path:s,managed_by:i?.by??null,auto_upgrade:i?.auto??!1,...i?.hint?{hint:i.hint}:{},...c?{error:c}:{}}}function it(t){try{return t()}catch{return null}}const lt={idleMs:18e4,timeoutMs:36e5};let ct,ut=async(t,e)=>(ct=await T({name:(/([a-z0-9-]+)\.(?:ps1|sh)$/i.exec(t)?.[1]??"runtime").toLowerCase(),url:t,platform:componentPlatform(),limits:{...lt,env:e},output:C,run:(t,e,o)=>R(t,e,o)}),"ok"===ct.outcome),pt=async(t,e)=>"ok"===await R(t,e,lt);function dt(t){D()?process.stderr.write(t+"\n"):console.log(t)}export function globalPackages(t,e=componentPlatform()){const o=u(z(t)),a="win32"===e?d(o,"node_modules"):d(u(o),"lib","node_modules"),s=[],i=(t,e)=>{try{const o=JSON.parse(n(d(t,"package.json"),"utf-8"));o.version&&s.push({name:e,version:o.version})}catch{}};let l=[];try{l=r(a)}catch{return s}for(const t of l)if(!t.startsWith(".")&&"npm"!==t&&"corepack"!==t)if(t.startsWith("@"))try{for(const e of r(d(a,t)))e.startsWith(".")||i(d(a,t,e),`${t}/${e}`)}catch{}else i(d(a,t),t);return s}function mt(t,e,o={}){const n=["installed","upgraded","reinstalled","up_to_date","already_installed"].includes(e);return{tool:t.id,category:t.category,current:t.current,latest:t.latest,result:e,version_after:null,ok:n,...o}}function ft(t){return`${w} upgrade ${t}`}export async function runRuntime(t,e,n={}){const r=Date.now(),a=componentPlatform(),s=await componentStatus(t,{refresh:!0}),i=t.name;if(!s.supported)return dt(g.yellow(" ! "+b.t("components.unsupported_platform",{tool:i}))),mt(s,"unavailable",{reason:"unsupported_platform"});if(s.blocker)return dt(g.yellow(" ! "+function(t,e){return b.t(`components.blocked_${t}`,{tool:e})}(s.blocker,i))),mt(s,"unavailable",{reason:s.blocker});const l=function(t){if("script"!==t.install.type)return null;const e=h().installMirror?.scripts;return e?`${e}/${t.install.script}.${"win32"===componentPlatform()?"ps1":"sh"}`:null}(t);if(s.installed&&!n.force){const o=g.gray(`(${s.path})`);if(s.latest&&!s.outdated)return dt(g.green(" √ "+b.t("components.up_to_date",{tool:i,current:s.current??"?"}))+o),"upgrade"===e&&dt(g.gray(" "+b.t("components.force_hint",{command:`${ft(t.id)} --force`}))),mt(s,"install"===e?"already_installed":"up_to_date");if("install"===e)return dt(g.green(" √ "+b.t("components.already_installed",{tool:i,current:s.current??"?"}))+o),s.outdated&&dt(g.yellow(" ! "+upgradeAdvice(s))),mt(s,"already_installed",s.outdated?{hint:upgradeAdvice(s)}:{});if(!s.latest)return dt(g.yellow(" ! "+b.t("components.no_latest",{tool:i,current:s.current??"?",how:ht(s)}))),mt(s,"manual",{reason:s.error??"no_latest",hint:s.hint});if(!s.auto_upgrade)return dt(g.yellow(" ! "+upgradeAdvice(s))),mt(s,"manual",{hint:s.hint})}if(!l)return dt(g.yellow(" ! "+b.t("components.no_mirror",{tool:i}))),mt(s,"unavailable",{reason:"no_mirror"});s.installed&&!s.auto_upgrade&&dt(g.yellow(" ! "+b.t("components.force_beside",{tool:i,path:s.path??"?",by:s.managed_by??"?"})));const p={};s.installed&&"script"===t.install.type&&Object.assign(p,t.install.forceEnv??{}),"uv"===t.id&&s.installed&&s.auto_upgrade&&s.path&&(p.UV_INSTALL_DIR=u(s.path));const d=t.upgrade?.migrateGlobalPackages&&s.installed&&"fnm"===s.managed_by&&s.path,m=d?globalPackages(s.path,a):[],f=d?z(s.path):null;dt(g.gray(" "+b.t(s.installed?"components.upgrading":"components.installing",{tool:i,latest:s.latest??"",source:s.source}))),j(`component:${t.id}`,"start",{detail:{mode:e,force:Boolean(n.force),current:s.current}}),d&&m.length&&f&&function(t){try{o(v.getConfigDir(),{recursive:!0}),N(vt(),JSON.stringify({...t,noted_at:Date.now()},null,2),384)}catch(t){V.logError("components: note migration",t)}}({packages:m,old_node:f}),ct=void 0;const w=await ut(l,p);I(),et=null;const y=probeRuntime(t,a),_=scriptTarget(t.id,a,{...process.env,...p}),$=(_?y.find(t=>{return e=t.path,o=_,"win32"===a?z(e).toLowerCase()===z(o).toLowerCase():z(e)===z(o);var e,o}):void 0)??y.find(e=>runtimeManager(t.id,e.path,a).auto)??y[0];if(!w||!$){yt();const e=ct;return j(`component:${t.id}`,"fail",{duration_ms:Date.now()-r,error:S(C())||void 0,detail:{reason:w?"not_found_after":"script_failed",...e?{how:e.how,...e.fileProblem?{file_problem:e.fileProblem}:{},...M(e.trace)}:{},...E(),...L()}}),dt(g.red(" × "+b.t("components.script_failed",{tool:i,command:(s.installed?ft:gt)(t.id)}))),mt(s,"failed",{reason:w?"not_found_after":"script_failed"})}let P;d&&m.length&&f&&z($.path)!==f&&(P=await wt(m,$.path,a)?"done":"failed"),"failed"!==P&&yt();const x=y[0];x&&x.path!==$.path&&x.version&&$.version&&k(x.version,$.version)<0&&dt(g.yellow(" ! "+b.t("components.path_shadowed",{tool:i,active:x.path,version:$.version,path:$.path}))),s.latest&&$.version&&k($.version,s.latest)<0&&(rt(`${t.id}:${a}:ceiling`,{version:$.version,error:s.latest,checked_at:Date.now()}),dt(g.yellow(" ! "+b.t("components.capped",{tool:i,latest:s.latest,version:$.version})))),j(`component:${t.id}`,"ok",{duration_ms:Date.now()-r,detail:{version:$.version,...P?{migration:P}:{}}});const A=s.installed?n.force&&!s.outdated?"reinstalled":"upgraded":"installed";var D;return dt(g.green(" √ "+("installed"===A?b.t("components.installed",{tool:i,version:$.version??"?"}):"reinstalled"===A?b.t("components.reinstalled",{tool:i,version:$.version??"?"}):b.t("components.upgraded",{tool:i,from:s.current??"?",to:$.version??"?"})))+g.gray(`(${$.path})`)),D=u($.path),(process.env.PATH??"").split("win32"===componentPlatform()?";":c).some(t=>"win32"===componentPlatform()?t.toLowerCase()===D.toLowerCase():t===D)||dt(g.gray(" "+b.t("components.new_terminal"))),mt(s,A,{version_after:$.version})}function gt(t){return`${w} install ${t}`}function ht(t){return t.hint?t.hint:b.t(`components.how_${t.managed_by??"other"}`,{tool:t.name})}export function upgradeAdvice(t){return t.auto_upgrade?b.t("components.outdated_auto",{tool:t.name,current:t.current??"?",latest:t.latest??"?",command:ft(t.id)}):b.t("components.outdated_manual",{tool:t.name,current:t.current??"?",latest:t.latest??"?",by:t.managed_by??"?",how:ht(t),command:`${ft(t.id)} --force`})}async function wt(t,e,o){const n=new Set(globalPackages(e,o).map(t=>t.name)),r=t.filter(t=>!n.has(t.name));if(!r.length)return!0;dt(g.gray(" "+b.t("components.migrating_globals",{packages:r.map(t=>t.name).join("、")})));const a=function(t,e){const o=u(z(t));return d(o,"win32"===e?"npm.cmd":"npm")}(e,o),s=["install","-g",...r.map(t=>`${t.name}@${t.version}`),`--registry=${B}`,"--no-fund","--no-audit","--loglevel=error",...y(v.getConfigDir())];return!!await pt(a,s)||(dt(g.yellow(" ! "+b.t("components.migrate_failed",{command:[a,...s].join(" ")}))),!1)}const vt=()=>d(v.getConfigDir(),"node-migration.json");function yt(){try{s(vt(),{force:!0})}catch(t){V.logError("components: clear migration",t)}}export async function resumePendingMigration(){let t;try{if(!e(vt()))return"none";t=JSON.parse(n(vt(),"utf-8"))}catch{return yt(),"none"}const o=componentPlatform(),r=listComponents().find(t=>"node"===t.id),a=r?probeRuntime(r,o).find(t=>"fnm"===runtimeManager("node",t.path,o).by):void 0;if(!Array.isArray(t.packages)||"number"!=typeof t.noted_at||Date.now()-t.noted_at>2592e6||!a||z(a.path)===t.old_node)return yt(),"none";j("component:node","start",{detail:{mode:"resume-migration"}});const s=await wt(t.packages,a.path,o);return s&&yt(),j("component:node",s?"ok":"fail",{detail:{mode:"resume-migration",migration:s?"done":"failed"}}),s?"done":"failed"}export function setComponentDepsForTests(t){void 0!==t.platform&&(G=t.platform),void 0!==t.uid&&(q=t.uid),void 0!==t.systemPaths&&(K=t.systemPaths),t.registryPath&&(tt=t.registryPath,et=null),t.versionRunner&&(X=t.versionRunner),t.macDeveloperTools&&(Z=t.macDeveloperTools),t.fetchText&&(at=t.fetchText),t.scriptRunner&&(ut=t.scriptRunner),t.commandRunner&&(pt=t.commandRunner)}
@@ -0,0 +1 @@
1
+ import{closeSync as t,existsSync as r,openSync as e,readFileSync as c,unlinkSync as n}from"fs";import{dirname as o,join as s}from"path";import{toolHome as i}from"./tools/types.js";export function npmCacheDir(t=process.env,r=process.platform){const e=p(t,"npm_config_cache");if(e)return e;const n=i(),o=function(t,r){let e;try{e=c(t,"utf8")}catch{return""}let n="";for(const t of e.split(/\r?\n/)){const e=t.trim();if(!e||e.startsWith(";")||e.startsWith("#"))continue;const c=/^cache\s*=\s*(.*)$/.exec(e);c&&(n=c[1].trim().replace(/^(["'])(.*)\1$/,"$2").replace(/\$\{([^}]+)\}/g,(t,e)=>r[e]??""),(n.startsWith("~/")||n.startsWith("~\\"))&&(n=s(i(),n.slice(2))))}return n}(p(t,"npm_config_userconfig")||s(n,".npmrc"),t);return o||("win32"===r?s(t.LOCALAPPDATA||s(n,"AppData","Local"),"npm-cache"):s(n,".npm"))}function p(t,r){const e=Object.keys(t).find(t=>t.toLowerCase()===r);return e?(t[e]??"").trim():""}export function canWriteNpmCache(c){let i=s(c,"_cacache","tmp");for(;!r(i);){const t=o(i);if(t===i)return!0;i=t}const p=s(i,`.write-test-${process.pid}-${Date.now()}`);try{return t(e(p,"wx")),n(p),!0}catch(t){const r=t.code;return!("EPERM"===r||"EACCES"===r||"EBUSY"===r)}}let a=null;export function npmCacheArgs(t,r=process.env){const e=npmCacheDir(r),c=`${e}\n${t}`;if(a?.key===c)return a.args;const n=canWriteNpmCache(e)?[]:[`--cache=${s(t,"npm-cache")}`];return a={key:c,args:n},n}export function resetNpmCacheArgsForTests(){a=null}
@@ -1 +1 @@
1
- import{chmodSync as t,existsSync as n,readFileSync as o,realpathSync as r,unlinkSync as e}from"fs";import{join as s}from"path";import{logger as i}from"../utils/logger.js";import{getShellRcFilePath as c}from"./env-cleanup.js";import{broadcastEnvChange as f,deleteWindowsEnv as u,readWindowsEnv as p,setUserEnv as l}from"./windows-env.js";import{atomicWriteFile as m,backupBeforeWrite as a}from"./tools/backup.js";import{toolHome as $}from"./tools/types.js";import{CLI_NAME as d}from"./brand.js";const h=t=>`# ${d}:${t}`;function j(){const t=$(),o=new Set,r=c();r&&o.add(r);for(const r of[".zshrc",".bashrc"]){const e=s(t,r);n(e)&&o.add(e)}return[...o]}function v(t,n,o){const r=`"${function(t){const n=$();return t.startsWith(n+"/")?`$HOME/${t.slice(n.length+1)}`:t}(n)}"`;return t.endsWith(".fish")?`test -f ${r}; and source ${r} ${h(o)}`:`[ -f ${r} ] && . ${r} ${h(o)}`}function w(t,o){const e=n(t)?r(t):t;a(e),m(e,o)}function E(t,n){return t.split("\n").filter(t=>!t.trimEnd().endsWith(h(n))).join("\n")}function b(t,n){if(/['\r\n]/.test(n))throw new Error(`${t} contains a quote or newline and cannot be written to a shell env file`)}export function writePersistentEnv(r,e,s){for(const[t,n]of Object.entries(s))b(t,n);const i=Object.entries(s).map(([t,n])=>`export ${t}='${n}'`).join("\n");a(e),m(e,`# Written by ${d}. Loaded from your shell profile.\n${i}\n`,384),t(e,384);for(const[t,n]of Object.entries(s))process.env[t]=n;if("win32"===process.platform){for(const[t,n]of Object.entries(s))l(t,n);return f(),{rcFiles:[]}}const c=[];for(const t of j()){const s=n(t)?o(t,"utf-8"):"",i=v(t,e,r);if(s.split("\n").some(t=>t.trimEnd()===i)){c.push(t);continue}const f=E(s,r).replace(/\n*$/,"");w(t,`${f?f+"\n\n":""}${i}\n`),c.push(t)}return{rcFiles:c}}export function removePersistentEnv(t,r,s){const c=readPersistentEnvFile(r);let l=!1;if("win32"===process.platform){let t=!1;for(const n of s)if(void 0!==c[n]&&p("user",n)===c[n])try{u("user",n),t=!0}catch(t){l=!0,i.logError("persistentEnv.remove",t)}t&&f()}else for(const r of j()){if(!n(r))continue;const e=o(r,"utf-8"),s=E(e,t);s!==e&&w(r,s)}!l&&n(r)&&(a(r),e(r))}export function readPersistentEnvFile(t){const r={};if(!n(t))return r;for(const n of o(t,"utf-8").split("\n")){const t=n.match(/^export ([A-Z_][A-Z0-9_]*)='([^']*)'$/);t&&(r[t[1]]=t[2])}return r}
1
+ import{chmodSync as t,existsSync as n,readFileSync as e,realpathSync as o,unlinkSync as r}from"fs";import{join as s}from"path";import{logger as i}from"../utils/logger.js";import{getShellRcFilePath as c}from"./env-cleanup.js";import{broadcastEnvChange as f,deleteWindowsEnv as p,readWindowsEnv as u,setUserEnv as l}from"./windows-env.js";import{atomicWriteFile as m,backupBeforeWrite as a}from"./tools/backup.js";import{toolHome as $}from"./tools/types.js";import{CLI_NAME as d}from"./brand.js";const h=t=>`# ${d}:${t}`;function v(){const t=$(),e=new Set,o=c();o&&e.add(o);for(const o of[".zshrc",".bashrc"]){const r=s(t,o);n(r)&&e.add(r)}return[...e]}function j(t,n,e){const o=`"${function(t){const n=$();return t.startsWith(n+"/")?`$HOME/${t.slice(n.length+1)}`:t}(n)}"`;return t.endsWith(".fish")?`test -f ${o}; and source ${o} ${h(e)}`:`[ -f ${o} ] && . ${o} ${h(e)}`}function E(t,e){const r=n(t)?o(t):t;a(r),m(r,e)}function w(t,n){return t.split("\n").filter(t=>!t.trimEnd().endsWith(h(n))).join("\n")}function b(t,n){if(/['\r\n]/.test(n))throw new Error(`${t} contains a quote or newline and cannot be written to a shell env file`)}export function writePersistentEnv(o,r,s){for(const[t,n]of Object.entries(s))b(t,n);const i=Object.entries(s).map(([t,n])=>`export ${t}='${n}'`).join("\n");a(r),m(r,`# Written by ${d}. Loaded from your shell profile.\n${i}\n`,384),t(r,384);for(const[t,n]of Object.entries(s))process.env[t]=n;if("win32"===process.platform){for(const[t,n]of Object.entries(s))l(t,n);return f(),{rcFiles:[]}}const c=[];for(const t of v()){const s=n(t)?e(t,"utf-8"):"",i=j(t,r,o);if(s.split("\n").some(t=>t.trimEnd()===i)){c.push(t);continue}const f=w(s,o).replace(/\n*$/,"");E(t,`${f?f+"\n\n":""}${i}\n`),c.push(t)}return{rcFiles:c}}export function removePersistentEnv(t,o,s){const c=readPersistentEnvFile(o);let l=!1;if("win32"===process.platform){let t=!1;for(const n of s)if(void 0!==c[n]&&u("user",n)===c[n])try{p("user",n),t=!0}catch(t){l=!0,i.logError("persistentEnv.remove",t)}t&&f()}else for(const o of v()){if(!n(o))continue;const r=e(o,"utf-8"),s=w(r,t);s!==r&&E(o,s)}!l&&n(o)&&(a(o),r(o))}export function persistentEnvApplied(t){return"win32"!==process.platform||Object.entries(readPersistentEnvFile(t)).every(([t,n])=>u("user",t)===n)}export function readPersistentEnvFile(t){const o={};if(!n(t))return o;for(const n of e(t,"utf-8").split("\n")){const t=n.match(/^export ([A-Z_][A-Z0-9_]*)='([^']*)'$/);t&&(o[t[1]]=t[2])}return o}
@@ -1 +1 @@
1
- import{spawn as t,spawnSync as e}from"child_process";import{rmSync as o}from"fs";import{dirname as r,join as n}from"path";import a from"chalk";import i from"inquirer";import{i18n as s}from"./i18n.js";import{logger as l}from"../utils/logger.js";import{compareVersions as p,getToolMinVersion as c}from"./model-registry.js";import{getAdapter as u}from"./tools/registry.js";import{findInstalls as m,findInstallsIncludingNative as d,forgetInstalls as g,installLabel as f,npmMirrorInstallCommand as w,npmMirrorVersion as h,npmUninstallCommand as _}from"./tools/tool-installs.js";import{toolHome as v}from"./tools/types.js";import{isJsonMode as y,isNonInteractive as k,shouldAutoConfirm as b}from"./runtime-options.js";import{flushTelemetry as x,maskHome as j,maskSecrets as T,track as C}from"./telemetry.js";import{windowsSecurityProducts as D}from"./windows-security.js";import{isWindowsPowerShell as $,powerShellEnv as E}from"./powershell-env.js";import{diagnoseMissing as M,runInstallScript as P,traceSummary as S}from"./install-script.js";import{endedByInterrupt as I}from"./signals.js";let O="ok",U={};export function lastCommandExit(){return U}let A="";const W=t=>{A=(A+t.toString("utf-8")).slice(-3e3)};export function outputTail(t){return t.replace(/\x1b\[[0-9;?]*[A-Za-z]/g,"").split(/\r?\n/).map(t=>t.split("\r").pop().trimEnd()).filter(Boolean).join("\n").slice(-1500)}export function lastCommandOutput(){return outputTail(A)}export function lastCommandInterrupted(){return I({status:U.exit_code,signal:U.signal})}let q=async(t,o,r={})=>(console.log(a.gray("$ ")+[t,...o].join(" ")),A="",U={},r.idleMs?O=await runWatched(t,o,r):(await x(1e3),O=function(t,o,r){const n=z(t)?e(F(t,o),{stdio:H(),shell:!0,timeout:r}):e(t,o,{stdio:H(),timeout:r,env:B(t)});return n.error&&l.logError(`upgrade: ${t}`,n.error),U={exit_code:n.status,signal:n.signal,...n.error?{spawn_error:String(n.error.message)}:{}},"ETIMEDOUT"===n.error?.code?"timeout":0===n.status?"ok":"fail"}(t,o,r.timeoutMs)),"ok"===O);const z=t=>"win32"===process.platform&&!/\.exe$/i.test(t),B=t=>$(t)?E():process.env,F=(t,e)=>[t,...e].map(t=>/\s/.test(t)?`"${t}"`:t).join(" "),H=()=>["inherit",y()?2:"inherit","inherit"];export function runWatched(e,o,r){return new Promise(n=>{const a=r.env?{...B(e),...r.env}:B(e),i=z(e)?t(F(e,o),{stdio:["inherit","pipe","pipe"],shell:!0,env:a}):t(e,o,{stdio:["inherit","pipe","pipe"],env:a});let s;const p=t=>{s=t,i.kill()};let c;const u=()=>{clearTimeout(c),r.idleMs&&(c=setTimeout(()=>p("stalled"),r.idleMs))},m=r.timeoutMs?setTimeout(()=>p("timeout"),r.timeoutMs):void 0;u(),i.stdout?.on("data",t=>{(y()?process.stderr:process.stdout).write(t),W(t),u()}),i.stderr?.on("data",t=>{process.stderr.write(t),W(t),u()});const d=t=>{clearTimeout(c),clearTimeout(m),n(t)};i.on("error",t=>{l.logError(`upgrade: ${e}`,t),U={...U,spawn_error:String(t.message)},d(s??"fail")}),i.on("close",(t,e)=>{U={...U,exit_code:t,signal:e},s&&(y()?process.stderr:process.stdout).write("\n"),d(s??(0===t?"ok":"fail"))})})}export function setUpgradeRunnerForTests(t){q=async(e,o,r)=>{const n=await t(e,o,r);return O="string"==typeof n?n:n?"ok":"fail","ok"===O}}const N={ok:"install.script_failed_npm",fail:"install.script_failed_npm",stalled:"install.script_stalled_npm",timeout:"install.script_timeout_npm"};let R;export function lastInstallMissing(){return R}export async function mirrorInstall(t,e){if(R=void 0,!t.mirrorScript)return V(t);console.log(a.gray(s.t("install.downloading")));const o=`install-script:${t.command}`,n=Date.now();C(o,"start");const i=await P({name:t.command,url:"win32"===process.platform?t.mirrorScript.ps1:t.mirrorScript.sh,limits:{idleMs:18e4,timeoutMs:36e5},output:lastCommandOutput,run:async(t,e,o)=>(await q(t,e,o),O)});let l,p=i.outcome;if("ok"===p&&e&&(g(),!e.installed())){const t=M(i.trace,e.expectedPaths);"not_on_path"===t.reason&&t.path&&e.addToPath?.(r(t.path))&&e.installed()?l=r(t.path):(R=t,p="fail")}const c="ok"===p;if(C(o,"stalled"===p?"timeout":p,{duration_ms:Date.now()-n,detail:{..."stalled"===p||"timeout"===p?{reason:p}:{},...R?{reason:R.reason,...R.path?{path:j(R.path)}:{}}:{},...l?{path_added:j(l)}:{},how:i.how,...i.fileProblem?{file_problem:i.fileProblem}:{},...S(i.trace),...lastCommandExit(),...c?{output:T(lastCommandOutput())}:{},...c?{}:failureContext()},...c?{}:{error:lastCommandOutput()||(R?"(no output)":void 0)}}),R&&console.log(a.yellow(" ! "+function(t,e){const o=D().join("、");switch(e.reason){case"removed_after_install":return s.t(o?"install.missing_removed_by":"install.missing_removed",{tool:t,path:e.path??"",security:o});case"not_on_path":return s.t("install.missing_not_on_path",{tool:t,path:e.path??""});case"not_downloaded":return s.t("install.missing_not_downloaded",{tool:t});default:return s.t("install.missing_unknown",{tool:t})}}(t.command,R))),c||!t.npmPackage||lastCommandInterrupted())return c;console.log(a.yellow(" ! "+s.t(N[i.outcome],{minutes:String(3)}))),C(o,"fallback");const u=await V(t);return u&&e&&(g(),e.installed()&&(R=void 0)),u&&!R}export function failureContext(){const t=D();return t.length?{security:t}:{}}async function V(t){const e=w(t,await h(t)),[o,...r]=e.split(" "),n=`install-npm:${t.command}`,i=Date.now();C(n,"start");const l=await q(o,r);return C(n,l?"ok":"fail",{duration_ms:Date.now()-i,detail:{...lastCommandExit(),...l?{}:failureContext()}}),l||"win32"===process.platform||console.log(a.yellow(" ! "+s.t("upgrade.npm_permission",{command:e}))),l}async function Y(t,e){switch(e.kind){case"npm":t.npmPackage&&await q("npm",["uninstall","-g",t.npmPackage]);break;case"brew":t.brew&&await q("brew",["uninstall",t.brew]);break;case"native":try{o(e.path,{force:!0});for(const e of t.native?.dataDirs??[])o(n(v(),...e),{recursive:!0,force:!0})}catch(t){l.logError("upgrade: remove native copy",t)}break;default:return!1}return g(),!m(t).some(t=>t.path===e.path)}function Z(t,e){switch(e.kind){case"npm":return _(t);case"brew":return`brew uninstall ${t.brew}`;case"native":return s.t("upgrade.delete_paths",{paths:[e.path,...(t.native?.dataDirs??[]).map(t=>n(v(),...t))].join("、")});default:return s.t("upgrade.delete_paths",{paths:e.path})}}export async function upgradeTool(t){const e=Date.now();C(`upgrade:${t}`,"start");try{const o=await async function(t){const e=u(t),o=e?.installSpec;if(!e||!o)throw new Error(s.t("upgrade.unsupported",{tool:t}));const r=e.displayName;g();const n=m(o);if(console.log(a.bold(`\n${r}`)),0===n.length)console.log(s.t("upgrade.not_installed_installing",{tool:r})),await mirrorInstall(o);else{const t=n[0];console.log(a.gray(" "+s.t("upgrade.current",{copy:f(t)})));const e=await async function(t,e){switch(e.kind){case"native":return q(e.path,t.native?.updateArgs??["update"],{timeoutMs:t.native?.updateTimeoutMs});case"npm":return V(t);case"brew":return!!t.brew&&q("brew",["upgrade",t.brew]);default:return!1}}(o,t);!e&&lastCommandInterrupted()||(e||"other"!==t.kind?e||"npm"===t.kind||"native"===t.kind&&await async function(t){const e=t.native?.mirrorUpdate;if(!e)return!1;console.log(a.yellow(" ! "+s.t("upgrade.native_mirror_trying")));const o=`native-mirror:${t.command}`,r=Date.now();C(o,"start");try{const{version:t,manifestVerified:n}=await e();return C(o,"ok",{duration_ms:Date.now()-r,detail:{version:t,manifest_verified:n}}),console.log(a.green(" √ "+s.t(n?"upgrade.native_mirror_done_verified":"upgrade.native_mirror_done",{version:t}))),!0}catch(t){return l.logError("upgrade: native mirror",t),C(o,"fail",{duration_ms:Date.now()-r,error:t,detail:failureContext()}),console.log(a.yellow(" ! "+s.t("upgrade.native_mirror_failed",{reason:t instanceof Error?t.message:String(t)}))),!1}}(o)||(console.log(a.yellow(" ! "+s.t("upgrade.fallback_mirror"))),await mirrorInstall(o)):console.log(a.yellow(" ! "+s.t("upgrade.unknown_install",{path:t.path}))))}g(),await async function(t,e){const o=m(t);if(o.length<2)return;const r=function(t){return t.reduce((t,e)=>e.version&&(!t.version||p(e.version,t.version)>0)?e:t)}(o),n=o.filter(t=>t!==r);console.log(a.yellow(" ! "+s.t("upgrade.duplicates",{tool:e,keep:f(r),others:n.map(f).join("、")})));let l=b();l||k()||!process.stdin.isTTY||(l=(await i.prompt([{type:"confirm",name:"remove",message:s.t("upgrade.confirm_remove"),default:!0}])).remove);for(const e of n)l&&await Y(t,e)?console.log(a.green(" √ "+s.t("upgrade.removed",{copy:f(e)}))):console.log(a.yellow(" ! "+s.t("upgrade.remove_by_hand",{how:Z(t,e)})))}(o,r),g();const w=d(o)[0];if(!w)return console.log(a.red(" × "+s.t("upgrade.still_missing",{tool:r}))),!1;w.onPath||console.log(a.gray(" "+s.t("components.new_terminal")));const h=c(t);if(h&&w.version&&p(w.version,h)<0){console.log(a.yellow(" ! "+s.t("upgrade.still_old",{copy:f(w),min:h})));for(const t of e.upgradeHints?.(h)??[])console.log(a.yellow(" ! "+t));return!1}return console.log(a.green(" √ "+s.t("upgrade.done",{copy:f(w)}))),!0}(t);return C(`upgrade:${t}`,o?"ok":"fail",{duration_ms:Date.now()-e}),o}catch(o){throw C(`upgrade:${t}`,"fail",{duration_ms:Date.now()-e,error:o}),o}}
1
+ import{spawn as t,spawnSync as o}from"child_process";import{rmSync as e}from"fs";import{dirname as r,join as n}from"path";import a from"chalk";import i from"inquirer";import{i18n as s}from"./i18n.js";import{logger as l}from"../utils/logger.js";import{compareVersions as p,getToolMinVersion as c}from"./model-registry.js";import{getAdapter as m}from"./tools/registry.js";import{findInstalls as u,findInstallsIncludingNative as d,forgetInstalls as g,installLabel as f,npmMirrorInstallCommand as w,npmMirrorVersion as h,npmUninstallCommand as _}from"./tools/tool-installs.js";import{toolHome as v}from"./tools/types.js";import{isJsonMode as y,isNonInteractive as k,shouldAutoConfirm as b}from"./runtime-options.js";import{flushTelemetry as x,maskHome as j,maskSecrets as C,track as T}from"./telemetry.js";import{windowsSecurityProducts as D}from"./windows-security.js";import{isWindowsPowerShell as $,powerShellEnv as E}from"./powershell-env.js";import{diagnoseMissing as M,runInstallScript as P,traceSummary as S}from"./install-script.js";import{endedByInterrupt as I}from"./signals.js";import{npmCacheArgs as O}from"./npm-cache.js";import{configManager as U}from"./config.js";let A="ok",W={};export function lastCommandExit(){return W}let q="";const z=t=>{q=(q+t.toString("utf-8")).slice(-3e3)};export function outputTail(t){return t.replace(/\x1b\[[0-9;?]*[A-Za-z]/g,"").split(/\r?\n/).map(t=>t.split("\r").pop().trimEnd()).filter(Boolean).join("\n").slice(-1500)}export function lastCommandOutput(){return outputTail(q)}export function lastCommandInterrupted(){return I({status:W.exit_code,signal:W.signal})}let B=async(t,e,r={})=>(console.log(a.gray("$ ")+[t,...e].join(" ")),q="",W={},r.idleMs?A=await runWatched(t,e,r):(await x(1e3),A=function(t,e,r){const n=F(t)?o(N(t,e),{stdio:R(),shell:!0,timeout:r}):o(t,e,{stdio:R(),timeout:r,env:H(t)});return n.error&&l.logError(`upgrade: ${t}`,n.error),W={exit_code:n.status,signal:n.signal,...n.error?{spawn_error:String(n.error.message)}:{}},"ETIMEDOUT"===n.error?.code?"timeout":0===n.status?"ok":"fail"}(t,e,r.timeoutMs)),"ok"===A);const F=t=>"win32"===process.platform&&!/\.exe$/i.test(t),H=t=>$(t)?E():process.env,N=(t,o)=>[t,...o].map(t=>/\s/.test(t)?`"${t}"`:t).join(" "),R=()=>["inherit",y()?2:"inherit","inherit"];export function runWatched(o,e,r){return new Promise(n=>{const a=r.env?{...H(o),...r.env}:H(o),i=F(o)?t(N(o,e),{stdio:["inherit","pipe","pipe"],shell:!0,env:a}):t(o,e,{stdio:["inherit","pipe","pipe"],env:a});let s;const p=t=>{s=t,i.kill()};let c;const m=()=>{clearTimeout(c),r.idleMs&&(c=setTimeout(()=>p("stalled"),r.idleMs))},u=r.timeoutMs?setTimeout(()=>p("timeout"),r.timeoutMs):void 0;m(),i.stdout?.on("data",t=>{(y()?process.stderr:process.stdout).write(t),z(t),m()}),i.stderr?.on("data",t=>{process.stderr.write(t),z(t),m()});const d=t=>{clearTimeout(c),clearTimeout(u),n(t)};i.on("error",t=>{l.logError(`upgrade: ${o}`,t),W={...W,spawn_error:String(t.message)},d(s??"fail")}),i.on("close",(t,o)=>{W={...W,exit_code:t,signal:o},s&&(y()?process.stderr:process.stdout).write("\n"),d(s??(0===t?"ok":"fail"))})})}export function setUpgradeRunnerForTests(t){B=async(o,e,r)=>{const n=await t(o,e,r);return A="string"==typeof n?n:n?"ok":"fail","ok"===A}}const V={ok:"install.script_failed_npm",fail:"install.script_failed_npm",stalled:"install.script_stalled_npm",timeout:"install.script_timeout_npm"};let Y;export function lastInstallMissing(){return Y}export async function mirrorInstall(t,o){if(Y=void 0,!t.mirrorScript)return Z(t);console.log(a.gray(s.t("install.downloading")));const e=`install-script:${t.command}`,n=Date.now();T(e,"start");const i=await P({name:t.command,url:"win32"===process.platform?t.mirrorScript.ps1:t.mirrorScript.sh,limits:{idleMs:18e4,timeoutMs:36e5},output:lastCommandOutput,run:async(t,o,e)=>(await B(t,o,e),A)});let l,p=i.outcome;if("ok"===p&&o&&(g(),!o.installed())){const t=M(i.trace,o.expectedPaths);"not_on_path"===t.reason&&t.path&&o.addToPath?.(r(t.path))&&o.installed()?l=r(t.path):(Y=t,p="fail")}const c="ok"===p;if(T(e,"stalled"===p?"timeout":p,{duration_ms:Date.now()-n,detail:{..."stalled"===p||"timeout"===p?{reason:p}:{},...Y?{reason:Y.reason,...Y.path?{path:j(Y.path)}:{}}:{},...l?{path_added:j(l)}:{},how:i.how,...i.fileProblem?{file_problem:i.fileProblem}:{},...S(i.trace),...lastCommandExit(),...c?{output:C(lastCommandOutput())}:{},...c?{}:failureContext()},...c?{}:{error:lastCommandOutput()||(Y?"(no output)":void 0)}}),Y&&console.log(a.yellow(" ! "+function(t,o){const e=D().join("、");switch(o.reason){case"removed_after_install":return s.t(e?"install.missing_removed_by":"install.missing_removed",{tool:t,path:o.path??"",security:e});case"not_on_path":return s.t("install.missing_not_on_path",{tool:t,path:o.path??""});case"not_downloaded":return s.t("install.missing_not_downloaded",{tool:t});default:return s.t("install.missing_unknown",{tool:t})}}(t.command,Y))),c||!t.npmPackage||lastCommandInterrupted())return c;console.log(a.yellow(" ! "+s.t(V[i.outcome],{minutes:String(3)}))),T(e,"fallback");const m=await Z(t);return m&&o&&(g(),o.installed()&&(Y=void 0)),m&&!Y}export function failureContext(){const t=D();return t.length?{security:t}:{}}async function Z(t){const o=w(t,await h(t)),[e,...r]=o.split(" "),n=[...r,...O(U.getConfigDir())],i=`install-npm:${t.command}`,l=Date.now();T(i,"start");const p=await B(e,n);return T(i,p?"ok":"fail",{duration_ms:Date.now()-l,detail:{...lastCommandExit(),...p?{}:failureContext()}}),p||"win32"===process.platform||console.log(a.yellow(" ! "+s.t("upgrade.npm_permission",{command:o}))),p}async function G(t,o){switch(o.kind){case"npm":t.npmPackage&&await B("npm",["uninstall","-g",t.npmPackage]);break;case"brew":t.brew&&await B("brew",["uninstall",t.brew]);break;case"native":try{e(o.path,{force:!0});for(const o of t.native?.dataDirs??[])e(n(v(),...o),{recursive:!0,force:!0})}catch(t){l.logError("upgrade: remove native copy",t)}break;default:return!1}return g(),!u(t).some(t=>t.path===o.path)}function J(t,o){switch(o.kind){case"npm":return _(t);case"brew":return`brew uninstall ${t.brew}`;case"native":return s.t("upgrade.delete_paths",{paths:[o.path,...(t.native?.dataDirs??[]).map(t=>n(v(),...t))].join("、")});default:return s.t("upgrade.delete_paths",{paths:o.path})}}export async function upgradeTool(t){const o=Date.now();T(`upgrade:${t}`,"start");try{const e=await async function(t){const o=m(t),e=o?.installSpec;if(!o||!e)throw new Error(s.t("upgrade.unsupported",{tool:t}));const r=o.displayName;g();const n=u(e);if(console.log(a.bold(`\n${r}`)),0===n.length)console.log(s.t("upgrade.not_installed_installing",{tool:r})),await mirrorInstall(e);else{const t=n[0];console.log(a.gray(" "+s.t("upgrade.current",{copy:f(t)})));const o=await async function(t,o){switch(o.kind){case"native":return B(o.path,t.native?.updateArgs??["update"],{timeoutMs:t.native?.updateTimeoutMs});case"npm":return Z(t);case"brew":return!!t.brew&&B("brew",["upgrade",t.brew]);default:return!1}}(e,t);!o&&lastCommandInterrupted()||(o||"other"!==t.kind?o||"npm"===t.kind||"native"===t.kind&&await async function(t){const o=t.native?.mirrorUpdate;if(!o)return!1;console.log(a.yellow(" ! "+s.t("upgrade.native_mirror_trying")));const e=`native-mirror:${t.command}`,r=Date.now();T(e,"start");try{const{version:t,manifestVerified:n}=await o();return T(e,"ok",{duration_ms:Date.now()-r,detail:{version:t,manifest_verified:n}}),console.log(a.green(" √ "+s.t(n?"upgrade.native_mirror_done_verified":"upgrade.native_mirror_done",{version:t}))),!0}catch(t){return l.logError("upgrade: native mirror",t),T(e,"fail",{duration_ms:Date.now()-r,error:t,detail:failureContext()}),console.log(a.yellow(" ! "+s.t("upgrade.native_mirror_failed",{reason:t instanceof Error?t.message:String(t)}))),!1}}(e)||(console.log(a.yellow(" ! "+s.t("upgrade.fallback_mirror"))),await mirrorInstall(e)):console.log(a.yellow(" ! "+s.t("upgrade.unknown_install",{path:t.path}))))}g(),await async function(t,o){const e=u(t);if(e.length<2)return;const r=function(t){return t.reduce((t,o)=>o.version&&(!t.version||p(o.version,t.version)>0)?o:t)}(e),n=e.filter(t=>t!==r);console.log(a.yellow(" ! "+s.t("upgrade.duplicates",{tool:o,keep:f(r),others:n.map(f).join("、")})));let l=b();l||k()||!process.stdin.isTTY||(l=(await i.prompt([{type:"confirm",name:"remove",message:s.t("upgrade.confirm_remove"),default:!0}])).remove);for(const o of n)l&&await G(t,o)?console.log(a.green(" √ "+s.t("upgrade.removed",{copy:f(o)}))):console.log(a.yellow(" ! "+s.t("upgrade.remove_by_hand",{how:J(t,o)})))}(e,r),g();const w=d(e)[0];if(!w)return console.log(a.red(" × "+s.t("upgrade.still_missing",{tool:r}))),!1;w.onPath||console.log(a.gray(" "+s.t("components.new_terminal")));const h=c(t);if(h&&w.version&&p(w.version,h)<0){console.log(a.yellow(" ! "+s.t("upgrade.still_old",{copy:f(w),min:h})));for(const t of o.upgradeHints?.(h)??[])console.log(a.yellow(" ! "+t));return!1}return console.log(a.green(" √ "+s.t("upgrade.done",{copy:f(w)}))),!0}(t);return T(`upgrade:${t}`,e?"ok":"fail",{duration_ms:Date.now()-o}),e}catch(e){throw T(`upgrade:${t}`,"fail",{duration_ms:Date.now()-o,error:e}),e}}
@@ -1 +1 @@
1
- import{chmodSync as t,existsSync as r,readFileSync as e}from"fs";import{join as n}from"path";import{i18n as o}from"../i18n.js";import{prettyModelName as i}from"../gateway-models.js";import{getAgyRules as a}from"../model-registry.js";import{logger as l}from"../../utils/logger.js";import{readPersistentEnvFile as s,removePersistentEnv as c,writePersistentEnv as u}from"../persistent-env.js";import{backupBeforeWrite as p,atomicWriteFile as m}from"./backup.js";import{findInstalls as d,mirrorInstallCommand as g}from"./tool-installs.js";import{toolHome as y}from"./types.js";import{brand as f,PROVIDER_KEY as h}from"../brand.js";const v="agy",A="AGY_LLM_GATEWAY_URL",_="AGY_LLM_GATEWAY_API_KEY",E="AGY_LLM_GATEWAY_MODELS",j=["GEMINI_API_KEY","GOOGLE_GEMINI_BASE_URL"],w="gemini",K=()=>n(y(),".gemini","antigravity-cli"),b=()=>n(K(),"settings.json"),I=()=>n(K(),`${h}.env`),P=()=>n(y(),".antigravity","settings.json"),M=f().installMirror?.agy,G={command:"agy",native:{binDir:"win32"===process.platform?["AppData","Local","agy","bin"]:[".local","bin"],updateArgs:["update"],dataDirs:[]},...M?{mirrorScript:{sh:`${M}/install.sh`,ps1:`${M}/install.ps1`}}:{}};function L(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function $(t,n){if(!r(t))return{};const o=e(t,"utf-8");if(!o.trim())return{};try{const t=JSON.parse(o);if(!L(t))throw new Error(`${n} root must be an object`);return t}catch(t){throw new Error(`Existing ${n} cannot be parsed; back it up and fix it first: ${t instanceof Error?t.message:String(t)}`)}}const C=()=>$(b(),"~/.gemini/antigravity-cli/settings.json"),N=()=>$(P(),"~/.antigravity/settings.json");function S(r,e,n){p(r),m(r,JSON.stringify(e,null,2)+"\n",n),void 0!==n&&t(r,n)}function Y(t){return(t||"").replace(/\/+$/,"").replace(/\/v1(beta)?$/,"")}const x=/-(minimal|low|medium|high|xhigh|max)$/;function k(t){const r=a().gatewayModels,e=t?r.filter(r=>t.models.includes(r)||t.models.includes(r.replace(x,""))):[];return e.length>0?e:r}function O(t){const r=t.replace(/-preview$/,""),e=x.exec(r)?.[1];return e?`${i(r.replace(x,""))} (${e[0].toUpperCase()}${e.slice(1)})`:i(r)}function U(t){const r=t.gateway;return L(r)&&!0===r.enabled&&"string"==typeof r.apiKey&&r.apiKey.trim()&&"string"==typeof r.url?{url:r.url,apiKey:r.apiKey}:null}function D(t){const r=t.models;return L(r)&&Array.isArray(r.list)?r.list.map(t=>L(t)&&"string"==typeof t.modelId?t.modelId:"").filter(Boolean):[]}function R(){try{if(C().modelProvider!==w)return null}catch{return null}const t=s(I()),r=t.GEMINI_API_KEY;return r&&r.trim()?{apiKey:r,url:t.GOOGLE_GEMINI_BASE_URL??""}:null}function T(t){const r=s(I());return r[A]===t.url&&r[_]===t.apiKey}function B(t,r,e){const n=C(),o=N();o.gateway={...L(o.gateway)?o.gateway:{},enabled:!0,url:r,apiKey:t,wireProtocol:"genai"},o.models={...L(o.models)?o.models:{},defaultModelId:e[0],list:e.map(t=>({modelId:t,displayName:O(t),supportsThinking:!0}))},S(P(),o,384),j.some(t=>void 0!==s(I())[t])&&c(v,I(),j);const i=u(v,I(),{[A]:r,[_]:t,[E]:e.join(",")}).rcFiles;for(const t of j)delete process.env[t];return n.modelProvider===w&&(delete n.modelProvider,S(b(),n)),i}let W=null,J=null;export const antigravityAdapter={name:"agy",displayName:"Antigravity CLI",command:"agy",installCommand:g(G),installSpec:G,configPath:P(),wantsModelCatalog:!0,loadPrivateConfig(t){C(),N();const r=k(t.catalog);W=B(t.apiKey,Y(t.baseUrl),r),J=r},unloadPrivateConfig(){try{const t=N();U(t)&&(delete t.gateway,delete t.models,S(P(),t,384))}catch(t){l.logError("antigravityAdapter.unloadPrivateConfig",t)}try{const t=C();t.modelProvider===w&&(delete t.modelProvider,S(b(),t))}catch(t){l.logError("antigravityAdapter.unloadPrivateConfig",t)}c(v,I(),[A,_,E,...j])},detectCurrentConfig(){try{const t=U(N());if(t)return{apiKey:t.apiKey}}catch{return{apiKey:null}}return{apiKey:R()?.apiKey??null}},listedModels(){try{const t=N(),r=U(t);if(r)return T(r)?D(t):[]}catch{return null}return R()?[]:null},refreshModelMenu(t){const r=N(),e=U(r)??R();if(!e)return;const n=k(t.catalog),o=e.url||Y(t.baseUrl),i=U(r);null!==i&&T(i)&&D(r).join(",")===n.join(",")&&s(I())[E]===n.join(",")&&null===R()||B(e.apiKey,o,n)},getConfig(){try{return N()}catch(t){return l.logError("antigravityAdapter.getConfig",t),null}},applyNotes(){const t=[];if(J&&J.length>0){const r=J.map(O);t.push({kind:"summary",text:o.t("tools.agy.menu_written",{count:String(r.length),list:r.join(o.t("tools.grok.list_separator")),default:r[0]})})}return null===W||0===d(G).length||t.push({kind:"action",text:o.t("tools.agy.open_new_terminal")}),t},backupPaths:()=>[P(),b(),I()],forceResetPaths:()=>[I()]};
1
+ import{chmodSync as t,existsSync as r,readFileSync as e}from"fs";import{join as n}from"path";import{i18n as o}from"../i18n.js";import{prettyModelName as i}from"../gateway-models.js";import{getAgyRules as a}from"../model-registry.js";import{logger as l}from"../../utils/logger.js";import{persistentEnvApplied as s,readPersistentEnvFile as c,removePersistentEnv as u,writePersistentEnv as p}from"../persistent-env.js";import{backupBeforeWrite as m,atomicWriteFile as d}from"./backup.js";import{findInstalls as g,mirrorInstallCommand as y}from"./tool-installs.js";import{toolHome as f}from"./types.js";import{brand as h,PROVIDER_KEY as v}from"../brand.js";const A="agy",_="AGY_LLM_GATEWAY_URL",E="AGY_LLM_GATEWAY_API_KEY",j="AGY_LLM_GATEWAY_MODELS",w=["GEMINI_API_KEY","GOOGLE_GEMINI_BASE_URL"],K="gemini",b=()=>n(f(),".gemini","antigravity-cli"),I=()=>n(b(),"settings.json"),P=()=>n(b(),`${v}.env`),M=()=>n(f(),".antigravity","settings.json"),G=h().installMirror?.agy,L={command:"agy",native:{binDir:"win32"===process.platform?["AppData","Local","agy","bin"]:[".local","bin"],updateArgs:["update"],dataDirs:[]},...G?{mirrorScript:{sh:`${G}/install.sh`,ps1:`${G}/install.ps1`}}:{}};function $(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function C(t,n){if(!r(t))return{};const o=e(t,"utf-8");if(!o.trim())return{};try{const t=JSON.parse(o);if(!$(t))throw new Error(`${n} root must be an object`);return t}catch(t){throw new Error(`Existing ${n} cannot be parsed; back it up and fix it first: ${t instanceof Error?t.message:String(t)}`)}}const N=()=>C(I(),"~/.gemini/antigravity-cli/settings.json"),S=()=>C(M(),"~/.antigravity/settings.json");function Y(r,e,n){m(r),d(r,JSON.stringify(e,null,2)+"\n",n),void 0!==n&&t(r,n)}function x(t){return(t||"").replace(/\/+$/,"").replace(/\/v1(beta)?$/,"")}const k=/-(minimal|low|medium|high|xhigh|max)$/;function O(t){const r=a().gatewayModels,e=t?r.filter(r=>t.models.includes(r)||t.models.includes(r.replace(k,""))):[];return e.length>0?e:r}function U(t){const r=t.replace(/-preview$/,""),e=k.exec(r)?.[1];return e?`${i(r.replace(k,""))} (${e[0].toUpperCase()}${e.slice(1)})`:i(r)}function D(t){const r=t.gateway;return $(r)&&!0===r.enabled&&"string"==typeof r.apiKey&&r.apiKey.trim()&&"string"==typeof r.url?{url:r.url,apiKey:r.apiKey}:null}function R(t){const r=t.models;return $(r)&&Array.isArray(r.list)?r.list.map(t=>$(t)&&"string"==typeof t.modelId?t.modelId:"").filter(Boolean):[]}function T(){try{if(N().modelProvider!==K)return null}catch{return null}const t=c(P()),r=t.GEMINI_API_KEY;return r&&r.trim()?{apiKey:r,url:t.GOOGLE_GEMINI_BASE_URL??""}:null}function B(t){const r=c(P());return r[_]===t.url&&r[E]===t.apiKey}function W(t,r,e){const n=N(),o=S();o.gateway={...$(o.gateway)?o.gateway:{},enabled:!0,url:r,apiKey:t,wireProtocol:"genai"},o.models={...$(o.models)?o.models:{},defaultModelId:e[0],list:e.map(t=>({modelId:t,displayName:U(t),supportsThinking:!0}))},Y(M(),o,384),w.some(t=>void 0!==c(P())[t])&&u(A,P(),w);const i=p(A,P(),{[_]:r,[E]:t,[j]:e.join(",")}).rcFiles;for(const t of w)delete process.env[t];return n.modelProvider===K&&(delete n.modelProvider,Y(I(),n)),i}let J=null,F=null;export const antigravityAdapter={name:"agy",displayName:"Antigravity CLI",command:"agy",installCommand:y(L),installSpec:L,configPath:M(),wantsModelCatalog:!0,loadPrivateConfig(t){N(),S();const r=O(t.catalog);J=W(t.apiKey,x(t.baseUrl),r),F=r},unloadPrivateConfig(){try{const t=S();D(t)&&(delete t.gateway,delete t.models,Y(M(),t,384))}catch(t){l.logError("antigravityAdapter.unloadPrivateConfig",t)}try{const t=N();t.modelProvider===K&&(delete t.modelProvider,Y(I(),t))}catch(t){l.logError("antigravityAdapter.unloadPrivateConfig",t)}u(A,P(),[_,E,j,...w])},detectCurrentConfig(){try{const t=D(S());if(t)return{apiKey:t.apiKey}}catch{return{apiKey:null}}return{apiKey:T()?.apiKey??null}},listedModels(){try{const t=S(),r=D(t);if(r)return B(r)?R(t):[]}catch{return null}return T()?[]:null},refreshModelMenu(t){const r=S(),e=D(r)??T();if(!e)return;const n=O(t.catalog),o=e.url||x(t.baseUrl),i=D(r);null!==i&&B(i)&&R(r).join(",")===n.join(",")&&c(P())[j]===n.join(",")&&s(P())&&null===T()||W(e.apiKey,o,n)},getConfig(){try{return S()}catch(t){return l.logError("antigravityAdapter.getConfig",t),null}},applyNotes(){const t=[];if(F&&F.length>0){const r=F.map(U);t.push({kind:"summary",text:o.t("tools.agy.menu_written",{count:String(r.length),list:r.join(o.t("tools.grok.list_separator")),default:r[0]})})}return null===J||0===g(L).length||t.push({kind:"action",text:o.t("tools.agy.open_new_terminal")}),t},backupPaths:()=>[M(),I(),P()],forceResetPaths:()=>[P()]};
package/dist/models.json CHANGED
@@ -288,6 +288,8 @@
288
288
  "gatewayModels": [
289
289
  "gemini-4-argon",
290
290
  "gemini-4-carbon-medium",
291
+ "gemini-4-hydrogen",
292
+ "gemini-4-neon",
291
293
  "gemini-3.8-flash",
292
294
  "gemini-3.7-flash",
293
295
  "gemini-3.6-flash",
package/models.json CHANGED
@@ -288,6 +288,8 @@
288
288
  "gatewayModels": [
289
289
  "gemini-4-argon",
290
290
  "gemini-4-carbon-medium",
291
+ "gemini-4-hydrogen",
292
+ "gemini-4-neon",
291
293
  "gemini-3.8-flash",
292
294
  "gemini-3.7-flash",
293
295
  "gemini-3.6-flash",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xship/cli",
3
- "version": "0.0.186",
3
+ "version": "0.0.188",
4
4
  "description": "Configure Claude Code, Codex, Grok Build and other coding tools for Xship AI with one command",
5
5
  "main": "dist/index.js",
6
6
  "bin": {