@vibeapi/api-helper 0.0.185 → 0.0.187
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-config.snapshot.json +234 -1
- package/dist/client-config.snapshot.json +234 -1
- package/dist/commands/setup.js +1 -1
- package/dist/lib/auto-update.js +1 -1
- package/dist/lib/components.js +1 -1
- package/dist/lib/npm-cache.d.ts +13 -0
- package/dist/lib/npm-cache.js +1 -0
- package/dist/lib/tool-upgrade.js +1 -1
- package/dist/models.json +1 -0
- package/models.json +1 -0
- package/package.json +1 -1
|
@@ -810,6 +810,44 @@
|
|
|
810
810
|
"name": "Kimi K3",
|
|
811
811
|
"recommended": false
|
|
812
812
|
},
|
|
813
|
+
{
|
|
814
|
+
"capabilities": {
|
|
815
|
+
"contextWindowTokens": 1000000,
|
|
816
|
+
"functionCall": true,
|
|
817
|
+
"imageOutput": false,
|
|
818
|
+
"inputModalities": [
|
|
819
|
+
"text",
|
|
820
|
+
"image",
|
|
821
|
+
"video"
|
|
822
|
+
],
|
|
823
|
+
"maxOutput": 131072,
|
|
824
|
+
"outputModalities": [
|
|
825
|
+
"text"
|
|
826
|
+
],
|
|
827
|
+
"reasoning": true,
|
|
828
|
+
"reasoningEfforts": [
|
|
829
|
+
"none",
|
|
830
|
+
"low",
|
|
831
|
+
"high",
|
|
832
|
+
"xhigh"
|
|
833
|
+
],
|
|
834
|
+
"structuredOutput": true,
|
|
835
|
+
"video": true,
|
|
836
|
+
"vision": true
|
|
837
|
+
},
|
|
838
|
+
"context_window": 1000000,
|
|
839
|
+
"description": "100 万上下文 | 深度推理 | 视觉理解",
|
|
840
|
+
"endpoint_types": [
|
|
841
|
+
"openai"
|
|
842
|
+
],
|
|
843
|
+
"group": "",
|
|
844
|
+
"group_name": "",
|
|
845
|
+
"hidden": false,
|
|
846
|
+
"id": "qwen4-max",
|
|
847
|
+
"max_output_tokens": 131072,
|
|
848
|
+
"name": "Qwen 4 Max",
|
|
849
|
+
"recommended": false
|
|
850
|
+
},
|
|
813
851
|
{
|
|
814
852
|
"capabilities": {
|
|
815
853
|
"contextWindowTokens": 1000000,
|
|
@@ -1035,6 +1073,121 @@
|
|
|
1035
1073
|
"name": "GPT-6 Astra",
|
|
1036
1074
|
"recommended": true
|
|
1037
1075
|
},
|
|
1076
|
+
{
|
|
1077
|
+
"capabilities": {
|
|
1078
|
+
"contextWindowTokens": 1050000,
|
|
1079
|
+
"functionCall": true,
|
|
1080
|
+
"imageOutput": false,
|
|
1081
|
+
"inputModalities": [
|
|
1082
|
+
"text",
|
|
1083
|
+
"image"
|
|
1084
|
+
],
|
|
1085
|
+
"knowledgeCutoff": "2026-05-18",
|
|
1086
|
+
"maxOutput": 128000,
|
|
1087
|
+
"outputModalities": [
|
|
1088
|
+
"text"
|
|
1089
|
+
],
|
|
1090
|
+
"reasoning": true,
|
|
1091
|
+
"reasoningEfforts": [
|
|
1092
|
+
"low",
|
|
1093
|
+
"medium",
|
|
1094
|
+
"high",
|
|
1095
|
+
"xhigh",
|
|
1096
|
+
"max"
|
|
1097
|
+
],
|
|
1098
|
+
"search": true,
|
|
1099
|
+
"settings": {
|
|
1100
|
+
"disabledParams": [
|
|
1101
|
+
"temperature",
|
|
1102
|
+
"top_p",
|
|
1103
|
+
"frequency_penalty",
|
|
1104
|
+
"presence_penalty"
|
|
1105
|
+
],
|
|
1106
|
+
"extendParams": [
|
|
1107
|
+
"reasoningEffort"
|
|
1108
|
+
],
|
|
1109
|
+
"searchImpl": "internal"
|
|
1110
|
+
},
|
|
1111
|
+
"streaming": true,
|
|
1112
|
+
"structuredOutput": true,
|
|
1113
|
+
"video": false,
|
|
1114
|
+
"vision": true
|
|
1115
|
+
},
|
|
1116
|
+
"clients": {
|
|
1117
|
+
"codex": true
|
|
1118
|
+
},
|
|
1119
|
+
"context_window": 1050000,
|
|
1120
|
+
"description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 高难度编程与专业工作",
|
|
1121
|
+
"endpoint_types": [
|
|
1122
|
+
"openai",
|
|
1123
|
+
"openai-response"
|
|
1124
|
+
],
|
|
1125
|
+
"group": "",
|
|
1126
|
+
"group_name": "",
|
|
1127
|
+
"hidden": false,
|
|
1128
|
+
"id": "gpt-6.2-astra",
|
|
1129
|
+
"max_output_tokens": 128000,
|
|
1130
|
+
"name": "GPT-6.2 Astra",
|
|
1131
|
+
"recommended": false
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
"capabilities": {
|
|
1135
|
+
"contextWindowTokens": 1050000,
|
|
1136
|
+
"defaultReasoningEffort": "medium",
|
|
1137
|
+
"functionCall": true,
|
|
1138
|
+
"imageOutput": false,
|
|
1139
|
+
"inputModalities": [
|
|
1140
|
+
"text",
|
|
1141
|
+
"image"
|
|
1142
|
+
],
|
|
1143
|
+
"knowledgeCutoff": "2026-06-01",
|
|
1144
|
+
"maxOutput": 128000,
|
|
1145
|
+
"outputModalities": [
|
|
1146
|
+
"text"
|
|
1147
|
+
],
|
|
1148
|
+
"reasoning": true,
|
|
1149
|
+
"reasoningEfforts": [
|
|
1150
|
+
"low",
|
|
1151
|
+
"medium",
|
|
1152
|
+
"high",
|
|
1153
|
+
"xhigh",
|
|
1154
|
+
"max"
|
|
1155
|
+
],
|
|
1156
|
+
"search": true,
|
|
1157
|
+
"settings": {
|
|
1158
|
+
"disabledParams": [
|
|
1159
|
+
"temperature",
|
|
1160
|
+
"top_p",
|
|
1161
|
+
"frequency_penalty",
|
|
1162
|
+
"presence_penalty"
|
|
1163
|
+
],
|
|
1164
|
+
"extendParams": [
|
|
1165
|
+
"reasoningEffort"
|
|
1166
|
+
],
|
|
1167
|
+
"searchImpl": "internal"
|
|
1168
|
+
},
|
|
1169
|
+
"streaming": true,
|
|
1170
|
+
"structuredOutput": true,
|
|
1171
|
+
"video": false,
|
|
1172
|
+
"vision": true
|
|
1173
|
+
},
|
|
1174
|
+
"clients": {
|
|
1175
|
+
"codex": true
|
|
1176
|
+
},
|
|
1177
|
+
"context_window": 1050000,
|
|
1178
|
+
"description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 复杂编程与专业工作",
|
|
1179
|
+
"endpoint_types": [
|
|
1180
|
+
"openai",
|
|
1181
|
+
"openai-response"
|
|
1182
|
+
],
|
|
1183
|
+
"group": "",
|
|
1184
|
+
"group_name": "",
|
|
1185
|
+
"hidden": false,
|
|
1186
|
+
"id": "gpt-6.2-sol",
|
|
1187
|
+
"max_output_tokens": 128000,
|
|
1188
|
+
"name": "GPT-6.2 Sol",
|
|
1189
|
+
"recommended": false
|
|
1190
|
+
},
|
|
1038
1191
|
{
|
|
1039
1192
|
"capabilities": {
|
|
1040
1193
|
"contextWindowTokens": 1050000,
|
|
@@ -1641,6 +1794,44 @@
|
|
|
1641
1794
|
"name": "Kimi K3",
|
|
1642
1795
|
"recommended": false
|
|
1643
1796
|
},
|
|
1797
|
+
{
|
|
1798
|
+
"capabilities": {
|
|
1799
|
+
"contextWindowTokens": 1000000,
|
|
1800
|
+
"functionCall": true,
|
|
1801
|
+
"imageOutput": false,
|
|
1802
|
+
"inputModalities": [
|
|
1803
|
+
"text",
|
|
1804
|
+
"image",
|
|
1805
|
+
"video"
|
|
1806
|
+
],
|
|
1807
|
+
"maxOutput": 131072,
|
|
1808
|
+
"outputModalities": [
|
|
1809
|
+
"text"
|
|
1810
|
+
],
|
|
1811
|
+
"reasoning": true,
|
|
1812
|
+
"reasoningEfforts": [
|
|
1813
|
+
"none",
|
|
1814
|
+
"low",
|
|
1815
|
+
"high",
|
|
1816
|
+
"xhigh"
|
|
1817
|
+
],
|
|
1818
|
+
"structuredOutput": true,
|
|
1819
|
+
"video": true,
|
|
1820
|
+
"vision": true
|
|
1821
|
+
},
|
|
1822
|
+
"context_window": 1000000,
|
|
1823
|
+
"description": "100 万上下文 | 深度推理 | 视觉理解",
|
|
1824
|
+
"endpoint_types": [
|
|
1825
|
+
"openai"
|
|
1826
|
+
],
|
|
1827
|
+
"group": "",
|
|
1828
|
+
"group_name": "",
|
|
1829
|
+
"hidden": false,
|
|
1830
|
+
"id": "qwen4-max",
|
|
1831
|
+
"max_output_tokens": 131072,
|
|
1832
|
+
"name": "Qwen 4 Max",
|
|
1833
|
+
"recommended": false
|
|
1834
|
+
},
|
|
1644
1835
|
{
|
|
1645
1836
|
"capabilities": {
|
|
1646
1837
|
"contextWindowTokens": 1000000,
|
|
@@ -1927,6 +2118,47 @@
|
|
|
1927
2118
|
"name": "Gemini 4 Carbon",
|
|
1928
2119
|
"recommended": false
|
|
1929
2120
|
},
|
|
2121
|
+
{
|
|
2122
|
+
"capabilities": {
|
|
2123
|
+
"contextWindowTokens": 1048576,
|
|
2124
|
+
"functionCall": true,
|
|
2125
|
+
"imageOutput": false,
|
|
2126
|
+
"inputModalities": [
|
|
2127
|
+
"text",
|
|
2128
|
+
"image",
|
|
2129
|
+
"video",
|
|
2130
|
+
"audio"
|
|
2131
|
+
],
|
|
2132
|
+
"knowledgeCutoff": "2026-03-31",
|
|
2133
|
+
"maxOutput": 65536,
|
|
2134
|
+
"outputModalities": [
|
|
2135
|
+
"text"
|
|
2136
|
+
],
|
|
2137
|
+
"reasoning": true,
|
|
2138
|
+
"reasoningEfforts": [
|
|
2139
|
+
"low",
|
|
2140
|
+
"medium",
|
|
2141
|
+
"high",
|
|
2142
|
+
"xhigh"
|
|
2143
|
+
],
|
|
2144
|
+
"structuredOutput": true,
|
|
2145
|
+
"video": true,
|
|
2146
|
+
"vision": true
|
|
2147
|
+
},
|
|
2148
|
+
"context_window": 1048576,
|
|
2149
|
+
"description": "100 万上下文 | 快速推理 | 编码与 Agent",
|
|
2150
|
+
"endpoint_types": [
|
|
2151
|
+
"gemini",
|
|
2152
|
+
"openai"
|
|
2153
|
+
],
|
|
2154
|
+
"group": "",
|
|
2155
|
+
"group_name": "",
|
|
2156
|
+
"hidden": false,
|
|
2157
|
+
"id": "gemini-4-hydrogen",
|
|
2158
|
+
"max_output_tokens": 65536,
|
|
2159
|
+
"name": "Gemini 4 Hydrogen",
|
|
2160
|
+
"recommended": false
|
|
2161
|
+
},
|
|
1930
2162
|
{
|
|
1931
2163
|
"capabilities": {
|
|
1932
2164
|
"contextWindowTokens": 1048576,
|
|
@@ -2168,7 +2400,7 @@
|
|
|
2168
2400
|
"tool": "gemini"
|
|
2169
2401
|
}
|
|
2170
2402
|
],
|
|
2171
|
-
"revision": "2026-11-
|
|
2403
|
+
"revision": "2026-11-17T18:25:13Z-9",
|
|
2172
2404
|
"schema": 1,
|
|
2173
2405
|
"tools": {
|
|
2174
2406
|
"claude": {
|
|
@@ -2189,6 +2421,7 @@
|
|
|
2189
2421
|
"agy_models": [
|
|
2190
2422
|
"gemini-4-argon",
|
|
2191
2423
|
"gemini-4-carbon-medium",
|
|
2424
|
+
"gemini-4-hydrogen",
|
|
2192
2425
|
"gemini-3.8-flash",
|
|
2193
2426
|
"gemini-3.7-flash",
|
|
2194
2427
|
"gemini-3.6-flash",
|
|
@@ -810,6 +810,44 @@
|
|
|
810
810
|
"name": "Kimi K3",
|
|
811
811
|
"recommended": false
|
|
812
812
|
},
|
|
813
|
+
{
|
|
814
|
+
"capabilities": {
|
|
815
|
+
"contextWindowTokens": 1000000,
|
|
816
|
+
"functionCall": true,
|
|
817
|
+
"imageOutput": false,
|
|
818
|
+
"inputModalities": [
|
|
819
|
+
"text",
|
|
820
|
+
"image",
|
|
821
|
+
"video"
|
|
822
|
+
],
|
|
823
|
+
"maxOutput": 131072,
|
|
824
|
+
"outputModalities": [
|
|
825
|
+
"text"
|
|
826
|
+
],
|
|
827
|
+
"reasoning": true,
|
|
828
|
+
"reasoningEfforts": [
|
|
829
|
+
"none",
|
|
830
|
+
"low",
|
|
831
|
+
"high",
|
|
832
|
+
"xhigh"
|
|
833
|
+
],
|
|
834
|
+
"structuredOutput": true,
|
|
835
|
+
"video": true,
|
|
836
|
+
"vision": true
|
|
837
|
+
},
|
|
838
|
+
"context_window": 1000000,
|
|
839
|
+
"description": "100 万上下文 | 深度推理 | 视觉理解",
|
|
840
|
+
"endpoint_types": [
|
|
841
|
+
"openai"
|
|
842
|
+
],
|
|
843
|
+
"group": "",
|
|
844
|
+
"group_name": "",
|
|
845
|
+
"hidden": false,
|
|
846
|
+
"id": "qwen4-max",
|
|
847
|
+
"max_output_tokens": 131072,
|
|
848
|
+
"name": "Qwen 4 Max",
|
|
849
|
+
"recommended": false
|
|
850
|
+
},
|
|
813
851
|
{
|
|
814
852
|
"capabilities": {
|
|
815
853
|
"contextWindowTokens": 1000000,
|
|
@@ -1035,6 +1073,121 @@
|
|
|
1035
1073
|
"name": "GPT-6 Astra",
|
|
1036
1074
|
"recommended": true
|
|
1037
1075
|
},
|
|
1076
|
+
{
|
|
1077
|
+
"capabilities": {
|
|
1078
|
+
"contextWindowTokens": 1050000,
|
|
1079
|
+
"functionCall": true,
|
|
1080
|
+
"imageOutput": false,
|
|
1081
|
+
"inputModalities": [
|
|
1082
|
+
"text",
|
|
1083
|
+
"image"
|
|
1084
|
+
],
|
|
1085
|
+
"knowledgeCutoff": "2026-05-18",
|
|
1086
|
+
"maxOutput": 128000,
|
|
1087
|
+
"outputModalities": [
|
|
1088
|
+
"text"
|
|
1089
|
+
],
|
|
1090
|
+
"reasoning": true,
|
|
1091
|
+
"reasoningEfforts": [
|
|
1092
|
+
"low",
|
|
1093
|
+
"medium",
|
|
1094
|
+
"high",
|
|
1095
|
+
"xhigh",
|
|
1096
|
+
"max"
|
|
1097
|
+
],
|
|
1098
|
+
"search": true,
|
|
1099
|
+
"settings": {
|
|
1100
|
+
"disabledParams": [
|
|
1101
|
+
"temperature",
|
|
1102
|
+
"top_p",
|
|
1103
|
+
"frequency_penalty",
|
|
1104
|
+
"presence_penalty"
|
|
1105
|
+
],
|
|
1106
|
+
"extendParams": [
|
|
1107
|
+
"reasoningEffort"
|
|
1108
|
+
],
|
|
1109
|
+
"searchImpl": "internal"
|
|
1110
|
+
},
|
|
1111
|
+
"streaming": true,
|
|
1112
|
+
"structuredOutput": true,
|
|
1113
|
+
"video": false,
|
|
1114
|
+
"vision": true
|
|
1115
|
+
},
|
|
1116
|
+
"clients": {
|
|
1117
|
+
"codex": true
|
|
1118
|
+
},
|
|
1119
|
+
"context_window": 1050000,
|
|
1120
|
+
"description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 高难度编程与专业工作",
|
|
1121
|
+
"endpoint_types": [
|
|
1122
|
+
"openai",
|
|
1123
|
+
"openai-response"
|
|
1124
|
+
],
|
|
1125
|
+
"group": "",
|
|
1126
|
+
"group_name": "",
|
|
1127
|
+
"hidden": false,
|
|
1128
|
+
"id": "gpt-6.2-astra",
|
|
1129
|
+
"max_output_tokens": 128000,
|
|
1130
|
+
"name": "GPT-6.2 Astra",
|
|
1131
|
+
"recommended": false
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
"capabilities": {
|
|
1135
|
+
"contextWindowTokens": 1050000,
|
|
1136
|
+
"defaultReasoningEffort": "medium",
|
|
1137
|
+
"functionCall": true,
|
|
1138
|
+
"imageOutput": false,
|
|
1139
|
+
"inputModalities": [
|
|
1140
|
+
"text",
|
|
1141
|
+
"image"
|
|
1142
|
+
],
|
|
1143
|
+
"knowledgeCutoff": "2026-06-01",
|
|
1144
|
+
"maxOutput": 128000,
|
|
1145
|
+
"outputModalities": [
|
|
1146
|
+
"text"
|
|
1147
|
+
],
|
|
1148
|
+
"reasoning": true,
|
|
1149
|
+
"reasoningEfforts": [
|
|
1150
|
+
"low",
|
|
1151
|
+
"medium",
|
|
1152
|
+
"high",
|
|
1153
|
+
"xhigh",
|
|
1154
|
+
"max"
|
|
1155
|
+
],
|
|
1156
|
+
"search": true,
|
|
1157
|
+
"settings": {
|
|
1158
|
+
"disabledParams": [
|
|
1159
|
+
"temperature",
|
|
1160
|
+
"top_p",
|
|
1161
|
+
"frequency_penalty",
|
|
1162
|
+
"presence_penalty"
|
|
1163
|
+
],
|
|
1164
|
+
"extendParams": [
|
|
1165
|
+
"reasoningEffort"
|
|
1166
|
+
],
|
|
1167
|
+
"searchImpl": "internal"
|
|
1168
|
+
},
|
|
1169
|
+
"streaming": true,
|
|
1170
|
+
"structuredOutput": true,
|
|
1171
|
+
"video": false,
|
|
1172
|
+
"vision": true
|
|
1173
|
+
},
|
|
1174
|
+
"clients": {
|
|
1175
|
+
"codex": true
|
|
1176
|
+
},
|
|
1177
|
+
"context_window": 1050000,
|
|
1178
|
+
"description": "105 万上下文 | 12.8 万输出 | 文字与图像输入 | 复杂编程与专业工作",
|
|
1179
|
+
"endpoint_types": [
|
|
1180
|
+
"openai",
|
|
1181
|
+
"openai-response"
|
|
1182
|
+
],
|
|
1183
|
+
"group": "",
|
|
1184
|
+
"group_name": "",
|
|
1185
|
+
"hidden": false,
|
|
1186
|
+
"id": "gpt-6.2-sol",
|
|
1187
|
+
"max_output_tokens": 128000,
|
|
1188
|
+
"name": "GPT-6.2 Sol",
|
|
1189
|
+
"recommended": false
|
|
1190
|
+
},
|
|
1038
1191
|
{
|
|
1039
1192
|
"capabilities": {
|
|
1040
1193
|
"contextWindowTokens": 1050000,
|
|
@@ -1641,6 +1794,44 @@
|
|
|
1641
1794
|
"name": "Kimi K3",
|
|
1642
1795
|
"recommended": false
|
|
1643
1796
|
},
|
|
1797
|
+
{
|
|
1798
|
+
"capabilities": {
|
|
1799
|
+
"contextWindowTokens": 1000000,
|
|
1800
|
+
"functionCall": true,
|
|
1801
|
+
"imageOutput": false,
|
|
1802
|
+
"inputModalities": [
|
|
1803
|
+
"text",
|
|
1804
|
+
"image",
|
|
1805
|
+
"video"
|
|
1806
|
+
],
|
|
1807
|
+
"maxOutput": 131072,
|
|
1808
|
+
"outputModalities": [
|
|
1809
|
+
"text"
|
|
1810
|
+
],
|
|
1811
|
+
"reasoning": true,
|
|
1812
|
+
"reasoningEfforts": [
|
|
1813
|
+
"none",
|
|
1814
|
+
"low",
|
|
1815
|
+
"high",
|
|
1816
|
+
"xhigh"
|
|
1817
|
+
],
|
|
1818
|
+
"structuredOutput": true,
|
|
1819
|
+
"video": true,
|
|
1820
|
+
"vision": true
|
|
1821
|
+
},
|
|
1822
|
+
"context_window": 1000000,
|
|
1823
|
+
"description": "100 万上下文 | 深度推理 | 视觉理解",
|
|
1824
|
+
"endpoint_types": [
|
|
1825
|
+
"openai"
|
|
1826
|
+
],
|
|
1827
|
+
"group": "",
|
|
1828
|
+
"group_name": "",
|
|
1829
|
+
"hidden": false,
|
|
1830
|
+
"id": "qwen4-max",
|
|
1831
|
+
"max_output_tokens": 131072,
|
|
1832
|
+
"name": "Qwen 4 Max",
|
|
1833
|
+
"recommended": false
|
|
1834
|
+
},
|
|
1644
1835
|
{
|
|
1645
1836
|
"capabilities": {
|
|
1646
1837
|
"contextWindowTokens": 1000000,
|
|
@@ -1927,6 +2118,47 @@
|
|
|
1927
2118
|
"name": "Gemini 4 Carbon",
|
|
1928
2119
|
"recommended": false
|
|
1929
2120
|
},
|
|
2121
|
+
{
|
|
2122
|
+
"capabilities": {
|
|
2123
|
+
"contextWindowTokens": 1048576,
|
|
2124
|
+
"functionCall": true,
|
|
2125
|
+
"imageOutput": false,
|
|
2126
|
+
"inputModalities": [
|
|
2127
|
+
"text",
|
|
2128
|
+
"image",
|
|
2129
|
+
"video",
|
|
2130
|
+
"audio"
|
|
2131
|
+
],
|
|
2132
|
+
"knowledgeCutoff": "2026-03-31",
|
|
2133
|
+
"maxOutput": 65536,
|
|
2134
|
+
"outputModalities": [
|
|
2135
|
+
"text"
|
|
2136
|
+
],
|
|
2137
|
+
"reasoning": true,
|
|
2138
|
+
"reasoningEfforts": [
|
|
2139
|
+
"low",
|
|
2140
|
+
"medium",
|
|
2141
|
+
"high",
|
|
2142
|
+
"xhigh"
|
|
2143
|
+
],
|
|
2144
|
+
"structuredOutput": true,
|
|
2145
|
+
"video": true,
|
|
2146
|
+
"vision": true
|
|
2147
|
+
},
|
|
2148
|
+
"context_window": 1048576,
|
|
2149
|
+
"description": "100 万上下文 | 快速推理 | 编码与 Agent",
|
|
2150
|
+
"endpoint_types": [
|
|
2151
|
+
"gemini",
|
|
2152
|
+
"openai"
|
|
2153
|
+
],
|
|
2154
|
+
"group": "",
|
|
2155
|
+
"group_name": "",
|
|
2156
|
+
"hidden": false,
|
|
2157
|
+
"id": "gemini-4-hydrogen",
|
|
2158
|
+
"max_output_tokens": 65536,
|
|
2159
|
+
"name": "Gemini 4 Hydrogen",
|
|
2160
|
+
"recommended": false
|
|
2161
|
+
},
|
|
1930
2162
|
{
|
|
1931
2163
|
"capabilities": {
|
|
1932
2164
|
"contextWindowTokens": 1048576,
|
|
@@ -2168,7 +2400,7 @@
|
|
|
2168
2400
|
"tool": "gemini"
|
|
2169
2401
|
}
|
|
2170
2402
|
],
|
|
2171
|
-
"revision": "2026-11-
|
|
2403
|
+
"revision": "2026-11-17T18:25:13Z-9",
|
|
2172
2404
|
"schema": 1,
|
|
2173
2405
|
"tools": {
|
|
2174
2406
|
"claude": {
|
|
@@ -2189,6 +2421,7 @@
|
|
|
2189
2421
|
"agy_models": [
|
|
2190
2422
|
"gemini-4-argon",
|
|
2191
2423
|
"gemini-4-carbon-medium",
|
|
2424
|
+
"gemini-4-hydrogen",
|
|
2192
2425
|
"gemini-3.8-flash",
|
|
2193
2426
|
"gemini-3.7-flash",
|
|
2194
2427
|
"gemini-3.6-flash",
|
package/dist/commands/setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"chalk";import{getAdapter as o}from"../lib/tools/registry.js";import{postApplyPrompts as t}from"../lib/post-apply.js";import{ensureReachableGatewayAddress as l,moveOtherToolsAfterFallback as i,saveGatewayFallback as s,toolsWeConfigured as n}from"./base.js";import{i18n as a}from"../lib/i18n.js";import{configManager as r}from"../lib/config.js";import{toolManager as p,SUPPORTED_TOOLS as d}from"../lib/tool-manager.js";import{validateApiKey as c,fetchModels as u}from"../lib/api-validator.js";import{CODEX_ONE_MILLION_CONTEXT_SETTING as f,setCodexOneMillionContext as m}from"../lib/tools/codex.js";import{resolveModelCatalog as g}from"../lib/model-catalog.js";import{CLAUDE_DESKTOP_FORCE_REGISTRY_SETTING as y,CLAUDE_DESKTOP_HIDE_OFFICIAL_LOGIN_SETTING as k}from"../lib/tools/claude-desktop.js";import{operationError as h,authenticationError as _,networkError as b,EXIT_CODES as w}from"../lib/errors.js";import{canPrompt as v,emitJson as x,hasExplicitYes as C,isColorEnabled as j,isDryRun as $,isJsonMode as T,isNonInteractive as K,shouldAutoConfirm as I}from"../lib/runtime-options.js";import{appsForTools as M,appUpgradeCommand as G,getApp as N}from"../lib/app-update.js";import{join as S}from"path";import{confirmAction as O}from"../lib/confirm.js";import{asksBeforeWriting as A,confirmWritePlan as E,printWritePlan as B,toolWritePlan as D}from"../lib/write-plan.js";import F from"inquirer";import{logger as L}from"../utils/logger.js";import{forgetInstalls as R}from"../lib/tools/tool-installs.js";import{CLI_NAME as q,brandEnv as P}from"../lib/brand.js";import{unsupportedUpgradeTargets as Y,upgradeCommand as V}from"./upgrade.js";export const DEDICATED_KEYS=[{option:"claudekey",tool:"claude-code",need:"claude"},{option:"codexkey",tool:"codex",need:"gpt"},{option:"grokkey",tool:"grok",need:"grok"},{option:"desktopkey",tool:"claude-desktop",need:"claude"},{option:"agykey",tool:"agy",need:"gemini"},{option:"openclawkey",tool:"openclaw",need:"any",hidden:!0},{option:"hermeskey",tool:"hermes",need:"any",hidden:!0},{option:"atomcodekey",tool:"atomcode",need:"any",hidden:!0},{option:"codebuddykey",tool:"codebuddy",need:"any"},{option:"workbuddykey",tool:"workbuddy",need:"any"},{option:"dshkey",tool:"dsh",need:"any"}];async function z(e){const o=await u(e);if(!o.ok)return{hasClaude:!0,hasGpt:!0,hasGrok:!0,hasGemini:!0,probed:!1};const t=o.models.map(e=>e.toLowerCase());return{hasClaude:t.some(e=>e.includes("claude")),hasGpt:t.some(e=>e.startsWith("gpt")||e.includes("gpt-")||/^o\d/.test(e)),hasGrok:t.some(e=>e.includes("grok")),hasGemini:t.some(e=>e.startsWith("gemini")),probed:!0}}function H(e,o){switch(o){case"claude":return e.hasClaude;case"gpt":return e.hasGpt;case"grok":return e.hasGrok;case"gemini":return e.hasGemini;default:return!0}}export function parseOnOff(e){const o=(e??"").trim().toLowerCase();return!!["on","true","show","1","yes","y"].includes(o)||!["off","false","hide","0","no","n"].includes(o)&&void 0}function U(o){console.log(e.green(o))}function W(o){console.log(e.yellow(o))}function J(o){console.error(e.red(o))}let Q=null;function X(e){const o={operation:1,authentication:2,network:3};(!Q||o[e]>o[Q])&&(Q=e)}async function Z(o,t){T()||console.log(e.gray(a.t("setup.validating",{label:o})));const l=await c(t);if(l.valid)return!0;const i=a.t("errors.key_placeholder"),s="--key"===o?`${q} setup --key ${i}`:`${q} setup ${o} ${i}`;let n;if("network_error"===l.error?(X("network"),n=b(a.t("setup.unreachable",{url:r.getBaseUrl(),reason:l.message||"network error"}),`${q} base auto`,"network_error")):"invalid_api_key"===l.error?(X("authentication"),n=_(a.t("setup.invalid_key",{label:o,reason:l.message||"invalid"}),s,"invalid_api_key")):(X("operation"),n=h(a.t("setup.validate_failed",{label:o,reason:l.message||l.error||"unknown"}),s,l.error)),T())throw n;return J(n.message),console.log(e.gray(a.t("errors.next_step",{command:n.hint}))),!1}async function ee(t,l,i={}){const{oneMillion:s,officialLogin:n,desktopRegistry:c,force:u,takeOver:m}=i,g=d[t];try{"claude-desktop"===t&&void 0!==c&&r.setToolSetting("claude-desktop",y,c),"codex"===t&&void 0!==s&&r.setToolSetting("codex",f,s),"claude-desktop"===t&&void 0!==n&&r.setToolSetting("claude-desktop",k,!n),await p.applyPrivateConfig(t,l,r.getModelsForTool(t),{force:u,takeOver:m})}catch(e){if(T())throw h(e instanceof Error?e.message:String(e),`${q} setup --key ${a.t("errors.key_placeholder")}`,"config_write_failed");const o=(e instanceof Error?e.message:String(e)).replace(/\s+/g," ").trim();return J("× "+a.t("setup.apply_failed",{tool:g.displayName,reason:o})),!1}return p.printApplied(t),u&&console.log(e.gray(" "+a.t("config.force_done",{tool:g.displayName,name:t}))),"codex"===t&&void 0!==s&&console.log(e.gray(" "+a.t(s?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))),o(t)?.isInstalled&&!p.isToolInstalled(t)&&console.log(e.yellow(" ! "+a.t("setup.gui_preconfigured",{tool:g.displayName,install:g.installCommand}))),!0}function oe(e){return!o(e)?.isInstalled&&!p.isToolInstalled(e)}async function te(e){if(C())return!0;const o=d[e]?.displayName??e;return v()?O({message:a.t("setup.ask_detected_tool",{tool:o}),defaultValue:!0}):(W(a.t("setup.detected_tool_hint",{tool:o,name:e})),!1)}export async function installMissingApps(o,t,l){const i=M(o).filter(e=>{if(l&&!l.includes(e))return!1;const o=N(e)?.appInstaller;try{return Boolean(o&&!o.blocker()&&!o.installedPath())}catch(o){return L.logError(`setup: app installed? ${e}`,o),!1}});if(0===i.length)return!1;const s=e=>N(e)?.displayName??e;let n=t;if(void 0===n&&!T())if(I())n=!K();else if(v()){const e=i.map(s).join(a.t("setup.list_separator")),o=i.reduce((e,o)=>e+(N(o)?.appInstaller.sizeMb()??0),0);console.log(""),n=(await F.prompt([{type:"confirm",name:"go",message:a.t("setup.install_app_confirm",{tools:e,size:String(o)}),default:!0}])).go}if(!n&&!T())for(const o of i)console.log(e.gray(a.t("setup.install_app_hint",{tool:s(o),command:G(o)})));return Boolean(n)}function le(e){W(a.t("setup.still_missing",{tools:e.map(e=>d[e].displayName).join(a.t("setup.list_separator")),commands:e.map(e=>`${q} config ${e} --yes`).join(a.t("setup.list_separator"))}))}function ie(o,t,l=[]){const i=D(o),s=S(r.getConfigDir(),"config.yaml");if(T())x({dry_run:!0,tools:i,install_first:l,key_file:t?s:null});else{if(0===i.length&&0===l.length){const o=(j()?e.cyan:e=>e)(a.t("runtime.dry_run_label"));return void console.log(`${o} ${a.t("setup.dry_run_none")}`)}B(i,{label:a.t("runtime.dry_run_label"),keyFile:t?s:void 0,installFirst:l})}}function se(e){return Boolean(o(e)?.installSpec||N(e)?.appInstaller)}function ne(e){return M(e).filter(e=>{const o=N(e);if(!o||o.tool===e)return!1;try{return!o.appInstaller.blocker()}catch(o){return L.logError(`setup: app blocker ${e}`,o),!1}})}function ae(e){const o=N(e);let t,l;if(o&&o.tool!==e){try{t=Boolean(o.appInstaller.installedPath())}catch(o){L.logError(`setup: app installed? ${e}`,o),t=!1}l=t?o.installedVersion?.():null}else t=p.isToolInstalled(e),l=t?p.installedVersion(e):null;return t?l?a.t("setup.pick_installed",{version:l}):a.t("setup.pick_installed_plain"):a.t("setup.pick_not_installed")}function re(o,t){return{name:`${N(o)?.displayName??d[o]?.displayName??o} ${e.gray(ae(o))}`,value:o,checked:t}}export function parseUpgradeList(e){const o=(Array.isArray(e)?e:void 0===e?[]:[e]).flatMap(e=>e.split(/[\s,]+/));return[...new Set(o.map(e=>e.trim()).filter(Boolean))]}function pe(){return"darwin"===process.platform||"win32"===process.platform||p.isToolInstalled("claude-desktop")}export async function setupCommand(c){Q=null;const u=DEDICATED_KEYS.map(e=>({...e,apiKey:c[e.option]?.trim()})).filter(e=>Boolean(e.apiKey)),y=void 0!==c.oneMillion||void 0!==c.claudeOfficial||void 0!==c.desktopRegistry;let k=c.key?.trim();const h=c.upgrade??[],_=Y(h);if(_.length>0)return J(a.t("upgrade.unsupported",{tool:_.join(", ")})),void(process.exitCode=w.usage);if(h.length>0&&($()?console.log(a.t("setup.dry_run_upgrade",{tools:h.join(", ")})):(await V(h),R()),!k&&0===u.length&&!y))return;k||0!==u.length||y||!A()||(k=(await F.prompt([{type:"password",name:"key",mask:"*",message:a.t("setup.ask_key")}])).key?.trim()||void 0);const b=void 0!==c.oneMillion,v=void 0!==c.claudeOfficial;let x;if(v&&(x=parseOnOff(c.claudeOfficial),void 0===x))return J(a.t("setup.claude_official_invalid",{value:String(c.claudeOfficial)})),void(process.exitCode=1);const C=void 0!==c.desktopRegistry;let j;if(C&&(j=parseOnOff(c.desktopRegistry),void 0===j))return J(a.t("setup.desktop_registry_invalid",{value:String(c.desktopRegistry)})),void(process.exitCode=1);const M=v||C,G=Boolean(k||u.length>0),N={oneMillion:c.oneMillion,officialLogin:x,desktopRegistry:j,force:c.force};if(!G&&(b||M)&&$())return void ie([...b?["codex"]:[],...M?["claude-desktop"]:[]],!1);if(!G&&(b||M)){if(b){const e=r.getApiKeyForTool("codex");if(e)try{const o=!0===c.oneMillion;r.setToolSetting("codex",f,o);const t=await g(e);m(o,t??void 0),U(a.t(o?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))}catch(e){J(a.t("setup.apply_failed",{tool:d.codex.displayName,reason:e instanceof Error?e.message:String(e)})),process.exitCode=1}else J(a.t("setup.codex_1m_missing_key")),process.exitCode=1}if(M){const e=r.getApiKeyForTool("claude-desktop");e?await ee("claude-desktop",e,{...N,oneMillion:void 0,takeOver:!0})?await t(["claude-desktop"],{apps:{install:!1}}):process.exitCode=1:(J(a.t("setup.desktop_official_login_missing_key")),process.exitCode=1)}return}if(!G)return J(a.t("setup.usage")),void(process.exitCode=1);const O=$(),B=O?null:await l(k||u[0].apiKey,{save:!1}),D=[],X=[];let ae,de=0,ce=0;const ue=new Set,fe=u.map(e=>({tool:e.tool,label:`--${e.option}`,apiKey:e.apiKey,need:e.need}));for(const e of fe){if(!await Z(e.label,e.apiKey)){ce+=1;continue}const o=await z(e.apiKey);!o.probed||H(o,e.need)?(o.probed||W(a.t("setup.probe_failed",{label:e.label})),D.push({tool:e.tool,apiKey:e.apiKey,dedicated:!0}),ue.add(e.tool)):(J(a.t(`setup.key_no_${e.need}`,{label:e.label,tool:d[e.tool].displayName})),ce+=1)}const me=!!k&&await Z("--key",k);k&&!me&&(ae=w[Q??"operation"]);const ge=k&&me?await z(k):void 0;k&&ge&&!ge.probed&&W(a.t("setup.probe_failed",{label:"--key"})),!(k&&ge&&ge.probed)||ge.hasClaude||ge.hasGpt||ge.hasGrok||ge.hasGemini||(J(a.t("setup.key_no_family")),ae=1);const ye=Boolean(k)&&0===u.length&&!c.fromInstaller&&A();if(k&&ge&&void 0===ae){const e=ge.hasClaude||ge.hasGpt||ge.hasGrok||ge.hasGemini,o=[{tool:"claude-code",capable:ge.hasClaude,skipMsg:a.t(pe()?"setup.skip_no_claude_desktop":"setup.skip_no_claude")},{tool:"codex",capable:ge.hasGpt,skipMsg:a.t("setup.skip_no_gpt")},{tool:"grok",capable:ge.hasGrok,skipMsg:a.t("setup.skip_no_grok")},{tool:"claude-desktop",capable:ge.hasClaude&&pe(),skipMsg:"",quiet:!0},{tool:"agy",capable:ge.hasGemini,skipMsg:a.t("setup.skip_no_gemini")},{tool:"codebuddy",capable:e&&p.isToolInstalled("codebuddy"),skipMsg:"",quiet:!0},{tool:"workbuddy",capable:e&&p.isToolInstalled("workbuddy"),skipMsg:"",quiet:!0},{tool:"dsh",capable:e&&p.isToolInstalled("dsh"),skipMsg:"",quiet:!0,ask:!0}];for(const e of o)ue.has(e.tool)||(e.capable?(!e.ask||O||ye||await te(e.tool))&&(D.push({tool:e.tool,apiKey:k,dedicated:!1}),ue.add(e.tool)):e.quiet||W(e.skipMsg))}let ke,he=c.install,_e=[];if(ye&&void 0===ae&&D.length>0){const e=await async function(e,o){console.log("");const{configure:t}=await F.prompt([{type:"checkbox",name:"configure",message:a.t("setup.pick_configure"),choices:e.map(e=>re(e,!0))}]);let l=[];const i=[...e.filter(se),...ne(e)];return o&&i.length>0&&(l=(await F.prompt([{type:"checkbox",name:"upgrade",message:a.t("setup.pick_upgrade"),choices:i.map(e=>re(e,t.includes(e)))}])).upgrade),0===t.length&&0===l.length?(console.log(a.t("setup.pick_none")),null):{configure:t,upgrade:l}}(D.map(e=>e.tool),void 0===c.upgrade);if(!e)return void(process.exitCode=w.cancelled);if(0===e.configure.length)return void await V(e.upgrade);_e=e.upgrade,ke=[],!0!==he&&(he=!1);const o=e.configure.filter(e=>oe(e)&&!_e.includes(e)&&!he);if(o.length>0&&W(a.t("setup.pick_configure_skip",{tools:o.map(e=>d[e].displayName).join(a.t("setup.list_separator"))})),D.splice(0,D.length,...D.filter(t=>e.configure.includes(t.tool)&&!o.includes(t.tool))),0===D.length)return void(_e.length>0&&await V(_e))}const be=Boolean(k&&me&&void 0===ae);if(O)return ie(D.filter(e=>!oe(e.tool)).map(e=>e.tool),D.length>0,D.filter(e=>oe(e.tool)).map(e=>e.tool)),void((ce>0||void 0!==ae)&&(process.exitCode=ae??w[Q??"operation"]));const we=D.filter(e=>!oe(e.tool)),ve=be||D.some(e=>e.dedicated),xe=B?n().filter(e=>!D.some(o=>o.tool===e.tool)):[],Ce=!c.fromInstaller&&A();if((D.length>0||ve)&&!c.fromInstaller&&!await E([...we.map(e=>e.tool),...xe.map(e=>e.tool)],{keyFile:ve?S(r.getConfigDir(),"config.yaml"):void 0,installFirst:D.filter(e=>oe(e.tool)).map(e=>e.tool)}))return void(process.exitCode=w.cancelled);_e.length>0&&(await V(_e),R()),(D.length>0||ve)&&s(),be&&k&&r.setApiKey(k);for(const e of D)oe(e.tool)?(e.dedicated&&r.setToolApiKey(e.tool,e.apiKey),X.push({tool:e.tool,apiKey:e.apiKey})):await ee(e.tool,e.apiKey,{...N,takeOver:e.dedicated||Ce})?(e.dedicated&&r.setToolApiKey(e.tool,e.apiKey),de+=1):(ce+=1,ue.delete(e.tool));const je=D.length>0||ve?await i(xe):[];if(void 0!==ae)return X.length>0&&le(X.map(e=>e.tool)),void(process.exitCode=ae);let $e=[];if(X.length>0){const o=await async function(o,t,l){const i=o.map(e=>e.tool);if(0===i.length)return{still:[],applied:[],failed:[]};const s=i.map(e=>d[e].displayName).join(a.t("setup.list_separator"));let n=t;if(void 0!==n||T()||(I()?n=!K():process.stdin.isTTY&&(console.log(""),n=(await F.prompt([{type:"confirm",name:"go",message:a.t("setup.install_confirm",{tools:s}),default:!0}])).go)),!n){console.log("");for(const o of i)console.log(e.yellow("! "+a.t("setup.install_hint",{tool:d[o].displayName,install:d[o].installCommand})));return T()||console.log(e.gray(a.t("setup.install_all_hint",{cli:q}))),{still:i,applied:[],failed:[]}}const r=[];for(const o of i){console.log(e.bold(`\n${d[o].displayName}`));try{await p.installTool(o)}catch(e){L.logError(`setup: install ${o}`,e)}R(),p.isToolInstalled(o)||r.push(o)}const c=i.filter(e=>!r.includes(e));c.length>0&&console.log("");const u=[],f=[];for(const{tool:e,apiKey:t}of o.filter(e=>c.includes(e.tool)))await ee(e,t,l)?u.push(e):f.push(e);return{still:r,applied:u,failed:f}}(X,he,N);$e=o.still,de+=o.applied.length,ce+=o.failed.length;for(const e of[...$e,...o.failed])ue.delete(e)}if(de>0){const t=[...ue].filter(e=>!o(e)?.isInstalled&&!$e.includes(e)),l=t.map(e=>d[e]?.command).filter(Boolean).join(" / "),i=a.t("setup.done",{count:String(de)});U("\n"+(l?`${i}${a.t("setup.done_commands",{commands:l})}`:i)),$e.length>0&&le($e);for(const e of t){const o=p.ensureNativeOnPath(e);o&&U(a.t("setup.path_added",{tool:d[e].displayName,dir:o}))}const s=t.filter(e=>!p.isOnPath(e));if(s.length>0&&!T()&&"1"!==P("PATH_HINT_BY_CALLER")){const o=s.map(e=>d[e].command).join(" / ");console.log(e.yellow(" ! "+a.t("win32"===process.platform?"setup.path_reload_windows":"setup.path_reload",{commands:o})))}}0===de&&$e.length>0&&le($e),ce>0&&(J(a.t("setup.failed_summary",{count:String(ce)})),T()||console.error(`${q} setup --key ${a.t("errors.key_placeholder")}`)),await t([...ue,...je],{apps:{install:await installMissingApps([...ue],he,ke)}}),(ce>0||0===de&&0===$e.length)&&(process.exitCode=w[Q??"operation"])}
|
|
1
|
+
import e from"chalk";import{getAdapter as o}from"../lib/tools/registry.js";import{postApplyPrompts as t}from"../lib/post-apply.js";import{ensureReachableGatewayAddress as l,moveOtherToolsAfterFallback as i,saveGatewayFallback as s,toolsWeConfigured as n}from"./base.js";import{i18n as a}from"../lib/i18n.js";import{configManager as r}from"../lib/config.js";import{toolManager as p,SUPPORTED_TOOLS as d}from"../lib/tool-manager.js";import{validateApiKey as c,fetchModels as u}from"../lib/api-validator.js";import{CODEX_ONE_MILLION_CONTEXT_SETTING as f,setCodexOneMillionContext as m}from"../lib/tools/codex.js";import{resolveModelCatalog as g}from"../lib/model-catalog.js";import{CLAUDE_DESKTOP_FORCE_REGISTRY_SETTING as y,CLAUDE_DESKTOP_HIDE_OFFICIAL_LOGIN_SETTING as k}from"../lib/tools/claude-desktop.js";import{operationError as h,authenticationError as _,networkError as b,EXIT_CODES as w}from"../lib/errors.js";import{canPrompt as v,emitJson as x,hasExplicitYes as C,isColorEnabled as j,isDryRun as $,isJsonMode as T,isNonInteractive as K,shouldAutoConfirm as I}from"../lib/runtime-options.js";import{appsForTools as M,appUpgradeCommand as G,getApp as N}from"../lib/app-update.js";import{join as S}from"path";import{confirmAction as O}from"../lib/confirm.js";import{asksBeforeWriting as A,confirmWritePlan as E,printWritePlan as B,toolWritePlan as D}from"../lib/write-plan.js";import F from"inquirer";import{logger as L}from"../utils/logger.js";import{forgetInstalls as R}from"../lib/tools/tool-installs.js";import{CLI_NAME as q,brandEnv as P}from"../lib/brand.js";import{unsupportedUpgradeTargets as Y,upgradeCommand as V}from"./upgrade.js";export const DEDICATED_KEYS=[{option:"claudekey",tool:"claude-code",need:"claude"},{option:"codexkey",tool:"codex",need:"gpt"},{option:"grokkey",tool:"grok",need:"grok"},{option:"desktopkey",tool:"claude-desktop",need:"claude"},{option:"agykey",tool:"agy",need:"gemini"},{option:"openclawkey",tool:"openclaw",need:"any",hidden:!0},{option:"hermeskey",tool:"hermes",need:"any",hidden:!0},{option:"atomcodekey",tool:"atomcode",need:"any",hidden:!0},{option:"codebuddykey",tool:"codebuddy",need:"any"},{option:"workbuddykey",tool:"workbuddy",need:"any"},{option:"dshkey",tool:"dsh",need:"any"}];async function z(e){const o=await u(e);if(!o.ok)return{hasClaude:!0,hasGpt:!0,hasGrok:!0,hasGemini:!0,probed:!1};const t=o.models.map(e=>e.toLowerCase());return{hasClaude:t.some(e=>e.includes("claude")),hasGpt:t.some(e=>e.startsWith("gpt")||e.includes("gpt-")||/^o\d/.test(e)),hasGrok:t.some(e=>e.includes("grok")),hasGemini:t.some(e=>e.startsWith("gemini")),probed:!0}}function H(e,o){switch(o){case"claude":return e.hasClaude;case"gpt":return e.hasGpt;case"grok":return e.hasGrok;case"gemini":return e.hasGemini;default:return!0}}export function parseOnOff(e){const o=(e??"").trim().toLowerCase();return!!["on","true","show","1","yes","y"].includes(o)||!["off","false","hide","0","no","n"].includes(o)&&void 0}function U(o){console.log(e.green(o))}function W(o){console.log(e.yellow(o))}function J(o){console.error(e.red(o))}let Q=null;function X(e){const o={operation:1,authentication:2,network:3};(!Q||o[e]>o[Q])&&(Q=e)}async function Z(o,t){T()||console.log(e.gray(a.t("setup.validating",{label:o})));const l=await c(t);if(l.valid)return!0;const i=a.t("errors.key_placeholder"),s="--key"===o?`${q} setup --key ${i}`:`${q} setup ${o} ${i}`;let n;if("network_error"===l.error?(X("network"),n=b(a.t("setup.unreachable",{url:r.getBaseUrl(),reason:l.message||"network error"}),`${q} base auto`,"network_error")):"invalid_api_key"===l.error?(X("authentication"),n=_(a.t("setup.invalid_key",{label:o,reason:l.message||"invalid"}),s,"invalid_api_key")):(X("operation"),n=h(a.t("setup.validate_failed",{label:o,reason:l.message||l.error||"unknown"}),s,l.error)),T())throw n;return J(n.message),console.log(e.gray(a.t("errors.next_step",{command:n.hint}))),!1}async function ee(t,l,i={}){const{oneMillion:s,officialLogin:n,desktopRegistry:c,force:u,takeOver:m}=i,g=d[t];try{"claude-desktop"===t&&void 0!==c&&r.setToolSetting("claude-desktop",y,c),"codex"===t&&void 0!==s&&r.setToolSetting("codex",f,s),"claude-desktop"===t&&void 0!==n&&r.setToolSetting("claude-desktop",k,!n),await p.applyPrivateConfig(t,l,r.getModelsForTool(t),{force:u,takeOver:m})}catch(e){if(T())throw h(e instanceof Error?e.message:String(e),`${q} setup --key ${a.t("errors.key_placeholder")}`,"config_write_failed");const o=(e instanceof Error?e.message:String(e)).replace(/\s+/g," ").trim();return J("× "+a.t("setup.apply_failed",{tool:g.displayName,reason:o})),!1}return p.printApplied(t),u&&console.log(e.gray(" "+a.t("config.force_done",{tool:g.displayName,name:t}))),"codex"===t&&void 0!==s&&console.log(e.gray(" "+a.t(s?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))),o(t)?.isInstalled&&!p.isToolInstalled(t)&&console.log(e.yellow(" ! "+a.t("setup.gui_preconfigured",{tool:g.displayName,install:g.installCommand}))),!0}function oe(e){return!o(e)?.isInstalled&&!p.isToolInstalled(e)}async function te(e){if(C())return!0;const o=d[e]?.displayName??e;return v()?O({message:a.t("setup.ask_detected_tool",{tool:o}),defaultValue:!0}):(W(a.t("setup.detected_tool_hint",{tool:o,name:e})),!1)}export async function installMissingApps(o,t,l){const i=M(o).filter(e=>{if(l&&!l.includes(e))return!1;const o=N(e)?.appInstaller;try{return Boolean(o&&!o.blocker()&&!o.installedPath())}catch(o){return L.logError(`setup: app installed? ${e}`,o),!1}});if(0===i.length)return!1;const s=e=>N(e)?.displayName??e;let n=t;if(void 0===n&&!T())if(I())n=!K();else if(v()){const e=i.map(s).join(a.t("setup.list_separator")),o=i.reduce((e,o)=>e+(N(o)?.appInstaller.sizeMb()??0),0);console.log(""),n=(await F.prompt([{type:"confirm",name:"go",message:a.t("setup.install_app_confirm",{tools:e,size:String(o)}),default:!0}])).go}if(!n&&!T())for(const o of i)console.log(e.gray(a.t("setup.install_app_hint",{tool:s(o),command:G(o)})));return Boolean(n)}function le(e){W(a.t("setup.still_missing",{tools:e.map(e=>d[e].displayName).join(a.t("setup.list_separator")),commands:e.map(e=>`${q} config ${e} --yes`).join(a.t("setup.list_separator"))}))}function ie(o,t,l=[]){const i=D(o),s=S(r.getConfigDir(),"config.yaml");if(T())x({dry_run:!0,tools:i,install_first:l,key_file:t?s:null});else{if(0===i.length&&0===l.length){const o=(j()?e.cyan:e=>e)(a.t("runtime.dry_run_label"));return void console.log(`${o} ${a.t("setup.dry_run_none")}`)}B(i,{label:a.t("runtime.dry_run_label"),keyFile:t?s:void 0,installFirst:l})}}function se(e){return Boolean(o(e)?.installSpec||N(e)?.appInstaller)}function ne(e){return M(e).filter(e=>{const o=N(e);if(!o||o.tool===e)return!1;try{return!o.appInstaller.blocker()}catch(o){return L.logError(`setup: app blocker ${e}`,o),!1}})}function ae(e){const o=N(e);let t,l;if(o&&o.tool!==e){try{t=Boolean(o.appInstaller.installedPath())}catch(o){L.logError(`setup: app installed? ${e}`,o),t=!1}l=t?o.installedVersion?.():null}else t=p.isToolInstalled(e),l=t?p.installedVersion(e):null;return t?l?a.t("setup.pick_installed",{version:l}):a.t("setup.pick_installed_plain"):a.t("setup.pick_not_installed")}function re(o,t){return{name:`${N(o)?.displayName??d[o]?.displayName??o} ${e.gray(ae(o))}`,value:o,checked:t}}export function parseUpgradeList(e){const o=(Array.isArray(e)?e:void 0===e?[]:[e]).flatMap(e=>e.split(/[\s,]+/));return[...new Set(o.map(e=>e.trim()).filter(Boolean))]}function pe(){return"darwin"===process.platform||"win32"===process.platform||p.isToolInstalled("claude-desktop")}export async function setupCommand(c){Q=null;const u=DEDICATED_KEYS.map(e=>({...e,apiKey:c[e.option]?.trim()})).filter(e=>Boolean(e.apiKey)),y=void 0!==c.oneMillion||void 0!==c.claudeOfficial||void 0!==c.desktopRegistry;let k=c.key?.trim();const h=c.upgrade??[],_=Y(h);if(_.length>0)return J(a.t("upgrade.unsupported",{tool:_.join(", ")})),void(process.exitCode=w.usage);if(h.length>0&&($()?console.log(a.t("setup.dry_run_upgrade",{tools:h.join(", ")})):(await V(h),R()),!k&&0===u.length&&!y))return;k||0!==u.length||y||!A()||(k=(await F.prompt([{type:"password",name:"key",mask:"*",message:a.t("setup.ask_key")}])).key?.trim()||void 0);const b=void 0!==c.oneMillion,v=void 0!==c.claudeOfficial;let x;if(v&&(x=parseOnOff(c.claudeOfficial),void 0===x))return J(a.t("setup.claude_official_invalid",{value:String(c.claudeOfficial)})),void(process.exitCode=1);const C=void 0!==c.desktopRegistry;let j;if(C&&(j=parseOnOff(c.desktopRegistry),void 0===j))return J(a.t("setup.desktop_registry_invalid",{value:String(c.desktopRegistry)})),void(process.exitCode=1);const M=v||C,G=Boolean(k||u.length>0),O={oneMillion:c.oneMillion,officialLogin:x,desktopRegistry:j,force:c.force};if(!G&&(b||M)&&$())return void ie([...b?["codex"]:[],...M?["claude-desktop"]:[]],!1);if(!G&&(b||M)){if(b){const e=r.getApiKeyForTool("codex");if(e)try{const o=!0===c.oneMillion;r.setToolSetting("codex",f,o);const t=await g(e);m(o,t??void 0),U(a.t(o?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))}catch(e){J(a.t("setup.apply_failed",{tool:d.codex.displayName,reason:e instanceof Error?e.message:String(e)})),process.exitCode=1}else J(a.t("setup.codex_1m_missing_key")),process.exitCode=1}if(M){const e=r.getApiKeyForTool("claude-desktop");e?await ee("claude-desktop",e,{...O,oneMillion:void 0,takeOver:!0})?await t(["claude-desktop"],{apps:{install:!1}}):process.exitCode=1:(J(a.t("setup.desktop_official_login_missing_key")),process.exitCode=1)}return}if(!G)return J(a.t("setup.usage")),void(process.exitCode=1);const B=$(),D=B?null:await l(k||u[0].apiKey,{save:!1}),X=[],ae=[];let de,ce=0,ue=0;const fe=new Set,me=u.map(e=>({tool:e.tool,label:`--${e.option}`,apiKey:e.apiKey,need:e.need}));for(const e of me){if(!await Z(e.label,e.apiKey)){ue+=1;continue}const o=await z(e.apiKey);!o.probed||H(o,e.need)?(o.probed||W(a.t("setup.probe_failed",{label:e.label})),X.push({tool:e.tool,apiKey:e.apiKey,dedicated:!0}),fe.add(e.tool)):(J(a.t(`setup.key_no_${e.need}`,{label:e.label,tool:d[e.tool].displayName})),ue+=1)}const ge=!!k&&await Z("--key",k);k&&!ge&&(de=w[Q??"operation"]);const ye=k&&ge?await z(k):void 0;k&&ye&&!ye.probed&&W(a.t("setup.probe_failed",{label:"--key"})),!(k&&ye&&ye.probed)||ye.hasClaude||ye.hasGpt||ye.hasGrok||ye.hasGemini||(J(a.t("setup.key_no_family")),de=1);const ke=Boolean(k)&&0===u.length&&!c.fromInstaller&&A();if(k&&ye&&void 0===de){const e=ye.hasClaude||ye.hasGpt||ye.hasGrok||ye.hasGemini,o=[{tool:"claude-code",capable:ye.hasClaude,skipMsg:a.t(pe()?"setup.skip_no_claude_desktop":"setup.skip_no_claude")},{tool:"codex",capable:ye.hasGpt,skipMsg:a.t("setup.skip_no_gpt")},{tool:"grok",capable:ye.hasGrok,skipMsg:a.t("setup.skip_no_grok")},{tool:"claude-desktop",capable:ye.hasClaude&&pe(),skipMsg:"",quiet:!0},{tool:"agy",capable:ye.hasGemini,skipMsg:a.t("setup.skip_no_gemini")},{tool:"codebuddy",capable:e&&p.isToolInstalled("codebuddy"),skipMsg:"",quiet:!0},{tool:"workbuddy",capable:e&&p.isToolInstalled("workbuddy"),skipMsg:"",quiet:!0},{tool:"dsh",capable:e&&p.isToolInstalled("dsh"),skipMsg:"",quiet:!0,ask:!0}];for(const e of o)fe.has(e.tool)||(e.capable?(!e.ask||B||ke||await te(e.tool))&&(X.push({tool:e.tool,apiKey:k,dedicated:!1}),fe.add(e.tool)):e.quiet||W(e.skipMsg))}let he,_e=c.install,be=[];if(ke&&void 0===de&&X.length>0){const e=await async function(e,o){console.log("");const{configure:t}=await F.prompt([{type:"checkbox",name:"configure",message:a.t("setup.pick_configure"),choices:e.map(e=>re(e,!0))}]);let l=[];const i=[...e.filter(se),...ne(e)];if(o&&i.length>0){const e=e=>N(e)?.tool??e;l=(await F.prompt([{type:"checkbox",name:"upgrade",message:a.t("setup.pick_upgrade"),choices:i.map(o=>re(o,t.includes(e(o))))}])).upgrade}return 0===t.length&&0===l.length?(console.log(a.t("setup.pick_none")),null):{configure:t,upgrade:l}}(X.map(e=>e.tool),void 0===c.upgrade);if(!e)return void(process.exitCode=w.cancelled);if(0===e.configure.length)return void await V(e.upgrade);be=e.upgrade,he=[],!0!==_e&&(_e=!1);const o=e.configure.filter(e=>oe(e)&&!be.includes(e)&&!_e);if(o.length>0&&W(a.t("setup.pick_configure_skip",{tools:o.map(e=>d[e].displayName).join(a.t("setup.list_separator"))})),X.splice(0,X.length,...X.filter(t=>e.configure.includes(t.tool)&&!o.includes(t.tool))),0===X.length)return void(be.length>0&&await V(be))}const we=Boolean(k&&ge&&void 0===de);if(B)return ie(X.filter(e=>!oe(e.tool)).map(e=>e.tool),X.length>0,X.filter(e=>oe(e.tool)).map(e=>e.tool)),void((ue>0||void 0!==de)&&(process.exitCode=de??w[Q??"operation"]));const ve=X.filter(e=>!oe(e.tool)),xe=we||X.some(e=>e.dedicated),Ce=D?n().filter(e=>!X.some(o=>o.tool===e.tool)):[],je=!c.fromInstaller&&A();if((X.length>0||xe)&&!c.fromInstaller&&!await E([...ve.map(e=>e.tool),...Ce.map(e=>e.tool)],{keyFile:xe?S(r.getConfigDir(),"config.yaml"):void 0,installFirst:X.filter(e=>oe(e.tool)).map(e=>e.tool)}))return void(process.exitCode=w.cancelled);be.length>0&&(await V(be),R()),(X.length>0||xe)&&s(),we&&k&&r.setApiKey(k);for(const e of X)oe(e.tool)?(e.dedicated&&r.setToolApiKey(e.tool,e.apiKey),ae.push({tool:e.tool,apiKey:e.apiKey})):await ee(e.tool,e.apiKey,{...O,takeOver:e.dedicated||je})?(e.dedicated&&r.setToolApiKey(e.tool,e.apiKey),ce+=1):(ue+=1,fe.delete(e.tool));const $e=X.length>0||xe?await i(Ce):[];if(void 0!==de)return ae.length>0&&le(ae.map(e=>e.tool)),void(process.exitCode=de);let Te=[];if(ae.length>0){const o=await async function(o,t,l){const i=o.map(e=>e.tool);if(0===i.length)return{still:[],applied:[],failed:[]};const s=i.map(e=>d[e].displayName).join(a.t("setup.list_separator"));let n=t;if(void 0!==n||T()||(I()?n=!K():process.stdin.isTTY&&(console.log(""),n=(await F.prompt([{type:"confirm",name:"go",message:a.t("setup.install_confirm",{tools:s}),default:!0}])).go)),!n){console.log("");for(const o of i)console.log(e.yellow("! "+a.t("setup.install_hint",{tool:d[o].displayName,install:d[o].installCommand})));return T()||console.log(e.gray(a.t("setup.install_all_hint",{cli:q}))),{still:i,applied:[],failed:[]}}const r=[];for(const o of i){console.log(e.bold(`\n${d[o].displayName}`));try{await p.installTool(o)}catch(e){L.logError(`setup: install ${o}`,e)}R(),p.isToolInstalled(o)||r.push(o)}const c=i.filter(e=>!r.includes(e));c.length>0&&console.log("");const u=[],f=[];for(const{tool:e,apiKey:t}of o.filter(e=>c.includes(e.tool)))await ee(e,t,l)?u.push(e):f.push(e);return{still:r,applied:u,failed:f}}(ae,_e,O);Te=o.still,ce+=o.applied.length,ue+=o.failed.length;for(const e of[...Te,...o.failed])fe.delete(e)}if(ce>0){const t=[...fe].filter(e=>!o(e)?.isInstalled&&!Te.includes(e)),l=t.map(e=>d[e]?.command).filter(Boolean).join(" / "),i=a.t("setup.done",{count:String(ce)});U("\n"+(l?`${i}${a.t("setup.done_commands",{commands:l})}`:i)),Te.length>0&&le(Te);for(const e of t){const o=p.ensureNativeOnPath(e);o&&U(a.t("setup.path_added",{tool:d[e].displayName,dir:o}))}const s=t.filter(e=>!p.isOnPath(e));if(s.length>0&&!T()&&"1"!==P("PATH_HINT_BY_CALLER")){const o=s.map(e=>d[e].command).join(" / ");console.log(e.yellow(" ! "+a.t("win32"===process.platform?"setup.path_reload_windows":"setup.path_reload",{commands:o})))}}0===ce&&Te.length>0&&le(Te),ue>0&&(J(a.t("setup.failed_summary",{count:String(ue)})),T()||console.error(`${q} setup --key ${a.t("errors.key_placeholder")}`)),await t([...fe,...$e],{apps:{install:await installMissingApps([...fe],_e,he)}}),(ue>0||0===ce&&0===Te.length)&&(process.exitCode=w[Q??"operation"])}
|
package/dist/lib/auto-update.js
CHANGED
|
@@ -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
|
|
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})}
|
package/dist/lib/components.js
CHANGED
|
@@ -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,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* npm's cache this account can't write: "npm config set cache D:\nodejs\node_cache" from a tutorial with that folder
|
|
3
|
+
* made by an administrator (11-18 Windows customer: every `npm install` failed with EPERM under `_cacache\tmp`), or a
|
|
4
|
+
* `~/.npm` left by `sudo npm`. The setting lives in the user's `.npmrc`, so every Node hits it. We don't touch the
|
|
5
|
+
* `.npmrc`; our own npm runs get `--cache=<our dir>/npm-cache` instead. The one-click installers do the same.
|
|
6
|
+
*/
|
|
7
|
+
/** The cache npm will use: `npm_config_cache`, else `cache=` in the user's npmrc, else npm's default. */
|
|
8
|
+
export declare function npmCacheDir(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
|
|
9
|
+
/** Whether a new file can be made where npm makes its temporary files (the closest folder that exists). */
|
|
10
|
+
export declare function canWriteNpmCache(dir: string): boolean;
|
|
11
|
+
/** Extra npm arguments: `--cache=<ownDir>/npm-cache` when npm's own cache can't be written, else none. */
|
|
12
|
+
export declare function npmCacheArgs(ownDir: string, env?: NodeJS.ProcessEnv): string[];
|
|
13
|
+
export declare function resetNpmCacheArgsForTests(): void;
|
|
@@ -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}
|
package/dist/lib/tool-upgrade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as t,spawnSync as
|
|
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}}
|
package/dist/models.json
CHANGED
package/models.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeapi/api-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.187",
|
|
4
4
|
"description": "CLI tool for managing AI coding assistants (Claude Code, Codex, OpenClaw, Hermes, AtomCode, Grok Build) with one unified config",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|