@ai-vibeway/cli 0.0.204 → 0.0.206
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 +155 -1
- package/dist/client-config.snapshot.json +155 -1
- package/dist/commands/addons.js +1 -0
- package/dist/commands/setup.js +1 -1
- package/dist/lib/addons-offer.js +1 -0
- package/dist/lib/addons.js +1 -0
- package/dist/lib/post-apply.js +1 -1
- package/dist/lib/program.js +1 -1
- package/dist/lib/tool-manager.js +1 -1
- package/dist/lib/tools/claude-code.js +1 -1
- package/dist/lib/tools/codex.js +1 -1
- package/dist/lib/tools/dsh.js +1 -1
- package/dist/lib/tools/mcp-config.js +1 -0
- package/dist/lib/tools/workbuddy.js +1 -1
- package/dist/locales/en_US.json +51 -1
- package/dist/locales/zh_CN.json +51 -1
- package/package.json +1 -1
|
@@ -1083,6 +1083,24 @@
|
|
|
1083
1083
|
"recommended": false
|
|
1084
1084
|
},
|
|
1085
1085
|
{
|
|
1086
|
+
"capabilities": {
|
|
1087
|
+
"contextWindowTokens": 1000000,
|
|
1088
|
+
"functionCall": true,
|
|
1089
|
+
"imageOutput": false,
|
|
1090
|
+
"inputModalities": [
|
|
1091
|
+
"text",
|
|
1092
|
+
"image",
|
|
1093
|
+
"video"
|
|
1094
|
+
],
|
|
1095
|
+
"maxOutput": 131072,
|
|
1096
|
+
"outputModalities": [
|
|
1097
|
+
"text"
|
|
1098
|
+
],
|
|
1099
|
+
"reasoning": true,
|
|
1100
|
+
"structuredOutput": true,
|
|
1101
|
+
"video": true,
|
|
1102
|
+
"vision": true
|
|
1103
|
+
},
|
|
1086
1104
|
"context_window": 1000000,
|
|
1087
1105
|
"description": "100 万上下文 | 均衡档",
|
|
1088
1106
|
"endpoint_types": [
|
|
@@ -1092,11 +1110,29 @@
|
|
|
1092
1110
|
"group": "",
|
|
1093
1111
|
"group_name": "",
|
|
1094
1112
|
"hidden": true,
|
|
1113
|
+
"icon": "Qwen.Color",
|
|
1095
1114
|
"id": "qwen3.7-plus",
|
|
1096
1115
|
"name": "Qwen 3.7 Plus",
|
|
1097
1116
|
"recommended": false
|
|
1098
1117
|
},
|
|
1099
1118
|
{
|
|
1119
|
+
"capabilities": {
|
|
1120
|
+
"contextWindowTokens": 1000000,
|
|
1121
|
+
"functionCall": true,
|
|
1122
|
+
"imageOutput": false,
|
|
1123
|
+
"inputModalities": [
|
|
1124
|
+
"text",
|
|
1125
|
+
"image",
|
|
1126
|
+
"video"
|
|
1127
|
+
],
|
|
1128
|
+
"maxOutput": 524288,
|
|
1129
|
+
"outputModalities": [
|
|
1130
|
+
"text"
|
|
1131
|
+
],
|
|
1132
|
+
"reasoning": true,
|
|
1133
|
+
"video": true,
|
|
1134
|
+
"vision": true
|
|
1135
|
+
},
|
|
1100
1136
|
"context_window": 1000000,
|
|
1101
1137
|
"description": "100 万上下文 | Agent 工作流",
|
|
1102
1138
|
"endpoint_types": [
|
|
@@ -1106,9 +1142,50 @@
|
|
|
1106
1142
|
"group": "",
|
|
1107
1143
|
"group_name": "",
|
|
1108
1144
|
"hidden": false,
|
|
1145
|
+
"icon": "Minimax",
|
|
1109
1146
|
"id": "MiniMax-M3",
|
|
1110
1147
|
"name": "MiniMax M3",
|
|
1111
1148
|
"recommended": false
|
|
1149
|
+
},
|
|
1150
|
+
{
|
|
1151
|
+
"capabilities": {
|
|
1152
|
+
"contextWindowTokens": 1000000,
|
|
1153
|
+
"functionCall": true,
|
|
1154
|
+
"imageOutput": false,
|
|
1155
|
+
"inputModalities": [
|
|
1156
|
+
"text"
|
|
1157
|
+
],
|
|
1158
|
+
"knowledgeCutoff": "2026-05-31",
|
|
1159
|
+
"maxOutput": 64000,
|
|
1160
|
+
"outputModalities": [
|
|
1161
|
+
"text"
|
|
1162
|
+
],
|
|
1163
|
+
"reasoning": true,
|
|
1164
|
+
"reasoningEfforts": [
|
|
1165
|
+
"low",
|
|
1166
|
+
"medium",
|
|
1167
|
+
"high",
|
|
1168
|
+
"xhigh",
|
|
1169
|
+
"max"
|
|
1170
|
+
],
|
|
1171
|
+
"structuredOutput": true,
|
|
1172
|
+
"video": false,
|
|
1173
|
+
"vision": false
|
|
1174
|
+
},
|
|
1175
|
+
"context_window": 1000000,
|
|
1176
|
+
"description": "100 万上下文 | Agent 编码",
|
|
1177
|
+
"endpoint_types": [
|
|
1178
|
+
"anthropic",
|
|
1179
|
+
"openai"
|
|
1180
|
+
],
|
|
1181
|
+
"group": "",
|
|
1182
|
+
"group_name": "",
|
|
1183
|
+
"hidden": false,
|
|
1184
|
+
"icon": "Aws.Color",
|
|
1185
|
+
"id": "amazon-ergo",
|
|
1186
|
+
"max_output_tokens": 64000,
|
|
1187
|
+
"name": "Amazon Ergo",
|
|
1188
|
+
"recommended": false
|
|
1112
1189
|
}
|
|
1113
1190
|
],
|
|
1114
1191
|
"codex": [
|
|
@@ -2054,6 +2131,24 @@
|
|
|
2054
2131
|
"recommended": false
|
|
2055
2132
|
},
|
|
2056
2133
|
{
|
|
2134
|
+
"capabilities": {
|
|
2135
|
+
"contextWindowTokens": 1000000,
|
|
2136
|
+
"functionCall": true,
|
|
2137
|
+
"imageOutput": false,
|
|
2138
|
+
"inputModalities": [
|
|
2139
|
+
"text",
|
|
2140
|
+
"image",
|
|
2141
|
+
"video"
|
|
2142
|
+
],
|
|
2143
|
+
"maxOutput": 131072,
|
|
2144
|
+
"outputModalities": [
|
|
2145
|
+
"text"
|
|
2146
|
+
],
|
|
2147
|
+
"reasoning": true,
|
|
2148
|
+
"structuredOutput": true,
|
|
2149
|
+
"video": true,
|
|
2150
|
+
"vision": true
|
|
2151
|
+
},
|
|
2057
2152
|
"context_window": 1000000,
|
|
2058
2153
|
"description": "100 万上下文 | 均衡档",
|
|
2059
2154
|
"endpoint_types": [
|
|
@@ -2063,11 +2158,29 @@
|
|
|
2063
2158
|
"group": "",
|
|
2064
2159
|
"group_name": "",
|
|
2065
2160
|
"hidden": true,
|
|
2161
|
+
"icon": "Qwen.Color",
|
|
2066
2162
|
"id": "qwen3.7-plus",
|
|
2067
2163
|
"name": "Qwen 3.7 Plus",
|
|
2068
2164
|
"recommended": false
|
|
2069
2165
|
},
|
|
2070
2166
|
{
|
|
2167
|
+
"capabilities": {
|
|
2168
|
+
"contextWindowTokens": 1000000,
|
|
2169
|
+
"functionCall": true,
|
|
2170
|
+
"imageOutput": false,
|
|
2171
|
+
"inputModalities": [
|
|
2172
|
+
"text",
|
|
2173
|
+
"image",
|
|
2174
|
+
"video"
|
|
2175
|
+
],
|
|
2176
|
+
"maxOutput": 524288,
|
|
2177
|
+
"outputModalities": [
|
|
2178
|
+
"text"
|
|
2179
|
+
],
|
|
2180
|
+
"reasoning": true,
|
|
2181
|
+
"video": true,
|
|
2182
|
+
"vision": true
|
|
2183
|
+
},
|
|
2071
2184
|
"context_window": 1000000,
|
|
2072
2185
|
"description": "100 万上下文 | Agent 工作流",
|
|
2073
2186
|
"endpoint_types": [
|
|
@@ -2077,6 +2190,7 @@
|
|
|
2077
2190
|
"group": "",
|
|
2078
2191
|
"group_name": "",
|
|
2079
2192
|
"hidden": false,
|
|
2193
|
+
"icon": "Minimax",
|
|
2080
2194
|
"id": "MiniMax-M3",
|
|
2081
2195
|
"name": "MiniMax M3",
|
|
2082
2196
|
"recommended": false
|
|
@@ -2119,6 +2233,46 @@
|
|
|
2119
2233
|
"id": "grok-4.7",
|
|
2120
2234
|
"name": "Grok 4.7",
|
|
2121
2235
|
"recommended": false
|
|
2236
|
+
},
|
|
2237
|
+
{
|
|
2238
|
+
"capabilities": {
|
|
2239
|
+
"contextWindowTokens": 1000000,
|
|
2240
|
+
"functionCall": true,
|
|
2241
|
+
"imageOutput": false,
|
|
2242
|
+
"inputModalities": [
|
|
2243
|
+
"text"
|
|
2244
|
+
],
|
|
2245
|
+
"knowledgeCutoff": "2026-05-31",
|
|
2246
|
+
"maxOutput": 64000,
|
|
2247
|
+
"outputModalities": [
|
|
2248
|
+
"text"
|
|
2249
|
+
],
|
|
2250
|
+
"reasoning": true,
|
|
2251
|
+
"reasoningEfforts": [
|
|
2252
|
+
"low",
|
|
2253
|
+
"medium",
|
|
2254
|
+
"high",
|
|
2255
|
+
"xhigh",
|
|
2256
|
+
"max"
|
|
2257
|
+
],
|
|
2258
|
+
"structuredOutput": true,
|
|
2259
|
+
"video": false,
|
|
2260
|
+
"vision": false
|
|
2261
|
+
},
|
|
2262
|
+
"context_window": 1000000,
|
|
2263
|
+
"description": "100 万上下文 | Agent 编码",
|
|
2264
|
+
"endpoint_types": [
|
|
2265
|
+
"anthropic",
|
|
2266
|
+
"openai"
|
|
2267
|
+
],
|
|
2268
|
+
"group": "",
|
|
2269
|
+
"group_name": "",
|
|
2270
|
+
"hidden": false,
|
|
2271
|
+
"icon": "Aws.Color",
|
|
2272
|
+
"id": "amazon-ergo",
|
|
2273
|
+
"max_output_tokens": 64000,
|
|
2274
|
+
"name": "Amazon Ergo",
|
|
2275
|
+
"recommended": false
|
|
2122
2276
|
}
|
|
2123
2277
|
],
|
|
2124
2278
|
"gemini": [
|
|
@@ -2534,7 +2688,7 @@
|
|
|
2534
2688
|
"tool": "gemini"
|
|
2535
2689
|
}
|
|
2536
2690
|
],
|
|
2537
|
-
"revision": "2026-12-
|
|
2691
|
+
"revision": "2026-12-02T08:58:15Z-17",
|
|
2538
2692
|
"schema": 1,
|
|
2539
2693
|
"tools": {
|
|
2540
2694
|
"claude": {
|
|
@@ -1083,6 +1083,24 @@
|
|
|
1083
1083
|
"recommended": false
|
|
1084
1084
|
},
|
|
1085
1085
|
{
|
|
1086
|
+
"capabilities": {
|
|
1087
|
+
"contextWindowTokens": 1000000,
|
|
1088
|
+
"functionCall": true,
|
|
1089
|
+
"imageOutput": false,
|
|
1090
|
+
"inputModalities": [
|
|
1091
|
+
"text",
|
|
1092
|
+
"image",
|
|
1093
|
+
"video"
|
|
1094
|
+
],
|
|
1095
|
+
"maxOutput": 131072,
|
|
1096
|
+
"outputModalities": [
|
|
1097
|
+
"text"
|
|
1098
|
+
],
|
|
1099
|
+
"reasoning": true,
|
|
1100
|
+
"structuredOutput": true,
|
|
1101
|
+
"video": true,
|
|
1102
|
+
"vision": true
|
|
1103
|
+
},
|
|
1086
1104
|
"context_window": 1000000,
|
|
1087
1105
|
"description": "100 万上下文 | 均衡档",
|
|
1088
1106
|
"endpoint_types": [
|
|
@@ -1092,11 +1110,29 @@
|
|
|
1092
1110
|
"group": "",
|
|
1093
1111
|
"group_name": "",
|
|
1094
1112
|
"hidden": true,
|
|
1113
|
+
"icon": "Qwen.Color",
|
|
1095
1114
|
"id": "qwen3.7-plus",
|
|
1096
1115
|
"name": "Qwen 3.7 Plus",
|
|
1097
1116
|
"recommended": false
|
|
1098
1117
|
},
|
|
1099
1118
|
{
|
|
1119
|
+
"capabilities": {
|
|
1120
|
+
"contextWindowTokens": 1000000,
|
|
1121
|
+
"functionCall": true,
|
|
1122
|
+
"imageOutput": false,
|
|
1123
|
+
"inputModalities": [
|
|
1124
|
+
"text",
|
|
1125
|
+
"image",
|
|
1126
|
+
"video"
|
|
1127
|
+
],
|
|
1128
|
+
"maxOutput": 524288,
|
|
1129
|
+
"outputModalities": [
|
|
1130
|
+
"text"
|
|
1131
|
+
],
|
|
1132
|
+
"reasoning": true,
|
|
1133
|
+
"video": true,
|
|
1134
|
+
"vision": true
|
|
1135
|
+
},
|
|
1100
1136
|
"context_window": 1000000,
|
|
1101
1137
|
"description": "100 万上下文 | Agent 工作流",
|
|
1102
1138
|
"endpoint_types": [
|
|
@@ -1106,9 +1142,50 @@
|
|
|
1106
1142
|
"group": "",
|
|
1107
1143
|
"group_name": "",
|
|
1108
1144
|
"hidden": false,
|
|
1145
|
+
"icon": "Minimax",
|
|
1109
1146
|
"id": "MiniMax-M3",
|
|
1110
1147
|
"name": "MiniMax M3",
|
|
1111
1148
|
"recommended": false
|
|
1149
|
+
},
|
|
1150
|
+
{
|
|
1151
|
+
"capabilities": {
|
|
1152
|
+
"contextWindowTokens": 1000000,
|
|
1153
|
+
"functionCall": true,
|
|
1154
|
+
"imageOutput": false,
|
|
1155
|
+
"inputModalities": [
|
|
1156
|
+
"text"
|
|
1157
|
+
],
|
|
1158
|
+
"knowledgeCutoff": "2026-05-31",
|
|
1159
|
+
"maxOutput": 64000,
|
|
1160
|
+
"outputModalities": [
|
|
1161
|
+
"text"
|
|
1162
|
+
],
|
|
1163
|
+
"reasoning": true,
|
|
1164
|
+
"reasoningEfforts": [
|
|
1165
|
+
"low",
|
|
1166
|
+
"medium",
|
|
1167
|
+
"high",
|
|
1168
|
+
"xhigh",
|
|
1169
|
+
"max"
|
|
1170
|
+
],
|
|
1171
|
+
"structuredOutput": true,
|
|
1172
|
+
"video": false,
|
|
1173
|
+
"vision": false
|
|
1174
|
+
},
|
|
1175
|
+
"context_window": 1000000,
|
|
1176
|
+
"description": "100 万上下文 | Agent 编码",
|
|
1177
|
+
"endpoint_types": [
|
|
1178
|
+
"anthropic",
|
|
1179
|
+
"openai"
|
|
1180
|
+
],
|
|
1181
|
+
"group": "",
|
|
1182
|
+
"group_name": "",
|
|
1183
|
+
"hidden": false,
|
|
1184
|
+
"icon": "Aws.Color",
|
|
1185
|
+
"id": "amazon-ergo",
|
|
1186
|
+
"max_output_tokens": 64000,
|
|
1187
|
+
"name": "Amazon Ergo",
|
|
1188
|
+
"recommended": false
|
|
1112
1189
|
}
|
|
1113
1190
|
],
|
|
1114
1191
|
"codex": [
|
|
@@ -2054,6 +2131,24 @@
|
|
|
2054
2131
|
"recommended": false
|
|
2055
2132
|
},
|
|
2056
2133
|
{
|
|
2134
|
+
"capabilities": {
|
|
2135
|
+
"contextWindowTokens": 1000000,
|
|
2136
|
+
"functionCall": true,
|
|
2137
|
+
"imageOutput": false,
|
|
2138
|
+
"inputModalities": [
|
|
2139
|
+
"text",
|
|
2140
|
+
"image",
|
|
2141
|
+
"video"
|
|
2142
|
+
],
|
|
2143
|
+
"maxOutput": 131072,
|
|
2144
|
+
"outputModalities": [
|
|
2145
|
+
"text"
|
|
2146
|
+
],
|
|
2147
|
+
"reasoning": true,
|
|
2148
|
+
"structuredOutput": true,
|
|
2149
|
+
"video": true,
|
|
2150
|
+
"vision": true
|
|
2151
|
+
},
|
|
2057
2152
|
"context_window": 1000000,
|
|
2058
2153
|
"description": "100 万上下文 | 均衡档",
|
|
2059
2154
|
"endpoint_types": [
|
|
@@ -2063,11 +2158,29 @@
|
|
|
2063
2158
|
"group": "",
|
|
2064
2159
|
"group_name": "",
|
|
2065
2160
|
"hidden": true,
|
|
2161
|
+
"icon": "Qwen.Color",
|
|
2066
2162
|
"id": "qwen3.7-plus",
|
|
2067
2163
|
"name": "Qwen 3.7 Plus",
|
|
2068
2164
|
"recommended": false
|
|
2069
2165
|
},
|
|
2070
2166
|
{
|
|
2167
|
+
"capabilities": {
|
|
2168
|
+
"contextWindowTokens": 1000000,
|
|
2169
|
+
"functionCall": true,
|
|
2170
|
+
"imageOutput": false,
|
|
2171
|
+
"inputModalities": [
|
|
2172
|
+
"text",
|
|
2173
|
+
"image",
|
|
2174
|
+
"video"
|
|
2175
|
+
],
|
|
2176
|
+
"maxOutput": 524288,
|
|
2177
|
+
"outputModalities": [
|
|
2178
|
+
"text"
|
|
2179
|
+
],
|
|
2180
|
+
"reasoning": true,
|
|
2181
|
+
"video": true,
|
|
2182
|
+
"vision": true
|
|
2183
|
+
},
|
|
2071
2184
|
"context_window": 1000000,
|
|
2072
2185
|
"description": "100 万上下文 | Agent 工作流",
|
|
2073
2186
|
"endpoint_types": [
|
|
@@ -2077,6 +2190,7 @@
|
|
|
2077
2190
|
"group": "",
|
|
2078
2191
|
"group_name": "",
|
|
2079
2192
|
"hidden": false,
|
|
2193
|
+
"icon": "Minimax",
|
|
2080
2194
|
"id": "MiniMax-M3",
|
|
2081
2195
|
"name": "MiniMax M3",
|
|
2082
2196
|
"recommended": false
|
|
@@ -2119,6 +2233,46 @@
|
|
|
2119
2233
|
"id": "grok-4.7",
|
|
2120
2234
|
"name": "Grok 4.7",
|
|
2121
2235
|
"recommended": false
|
|
2236
|
+
},
|
|
2237
|
+
{
|
|
2238
|
+
"capabilities": {
|
|
2239
|
+
"contextWindowTokens": 1000000,
|
|
2240
|
+
"functionCall": true,
|
|
2241
|
+
"imageOutput": false,
|
|
2242
|
+
"inputModalities": [
|
|
2243
|
+
"text"
|
|
2244
|
+
],
|
|
2245
|
+
"knowledgeCutoff": "2026-05-31",
|
|
2246
|
+
"maxOutput": 64000,
|
|
2247
|
+
"outputModalities": [
|
|
2248
|
+
"text"
|
|
2249
|
+
],
|
|
2250
|
+
"reasoning": true,
|
|
2251
|
+
"reasoningEfforts": [
|
|
2252
|
+
"low",
|
|
2253
|
+
"medium",
|
|
2254
|
+
"high",
|
|
2255
|
+
"xhigh",
|
|
2256
|
+
"max"
|
|
2257
|
+
],
|
|
2258
|
+
"structuredOutput": true,
|
|
2259
|
+
"video": false,
|
|
2260
|
+
"vision": false
|
|
2261
|
+
},
|
|
2262
|
+
"context_window": 1000000,
|
|
2263
|
+
"description": "100 万上下文 | Agent 编码",
|
|
2264
|
+
"endpoint_types": [
|
|
2265
|
+
"anthropic",
|
|
2266
|
+
"openai"
|
|
2267
|
+
],
|
|
2268
|
+
"group": "",
|
|
2269
|
+
"group_name": "",
|
|
2270
|
+
"hidden": false,
|
|
2271
|
+
"icon": "Aws.Color",
|
|
2272
|
+
"id": "amazon-ergo",
|
|
2273
|
+
"max_output_tokens": 64000,
|
|
2274
|
+
"name": "Amazon Ergo",
|
|
2275
|
+
"recommended": false
|
|
2122
2276
|
}
|
|
2123
2277
|
],
|
|
2124
2278
|
"gemini": [
|
|
@@ -2534,7 +2688,7 @@
|
|
|
2534
2688
|
"tool": "gemini"
|
|
2535
2689
|
}
|
|
2536
2690
|
],
|
|
2537
|
-
"revision": "2026-12-
|
|
2691
|
+
"revision": "2026-12-02T08:58:15Z-17",
|
|
2538
2692
|
"schema": 1,
|
|
2539
2693
|
"tools": {
|
|
2540
2694
|
"claude": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from"chalk";import{addonsInstalled as t,clearAddonsDeclined as n,MCP_NAME as s,removeAddons as r,skillCredentialsPath as e}from"../lib/addons.js";import{printOutcomes as a,runAddonsInstall as l}from"../lib/addons-offer.js";import{CLI_NAME as i}from"../lib/brand.js";import{configManager as d}from"../lib/config.js";import{usageError as m}from"../lib/errors.js";import{i18n as f}from"../lib/i18n.js";import{emitJson as c,isJsonMode as p}from"../lib/runtime-options.js";import{toolManager as u}from"../lib/tool-manager.js";import{listAdapters as g}from"../lib/tools/registry.js";function k(o,t){const n=g().filter(o=>o.addons);return 0===o.length?t?n.filter(o=>u.isToolInstalled(o.name)):n:o.map(o=>{const t=n.find(t=>t.name===o);if(!t)throw m(f.t("addons.unknown_tool",{tool:o}),`${i} addons install ${n.map(o=>o.name).join(" ")}`);return t})}export async function addonsCommand(y,b,_={}){if("install"===y){const t=_.key?.trim();if(t&&!/^sk-[A-Za-z0-9]{8,}$/.test(t))throw m(f.t("addons.bad_key"),`${i} addons install --key ${f.t("errors.key_placeholder")}`);if(!t&&!d.getApiKey())throw m(f.t("addons.no_key"),`${i} addons install --key ${f.t("errors.key_placeholder")}`);const r=k(b,!0);if(0===r.length)return void(p()?c({ok:!0,outcomes:[]}):console.log(o.yellow(f.t("addons.none_installed"))));n();const e=await l(r,t);return void(p()?c({ok:!0,mcp:s,outcomes:e}):console.log(o.gray(" "+f.t("addons.restart_hint"))))}if("remove"===y){const o=k(b,!1),t=r(o,{dropCredentials:0===b.length,baseUrl:d.getBaseUrl()});return void(p()?c({ok:!0,outcomes:t}):a(t))}if("status"===y){const n=k(b,!1).map(o=>({tool:o.name,installed:u.isToolInstalled(o.name),addons:t(o)}));if(p())return void c({ok:!0,mcp:s,credentials:e(d.getBaseUrl()),tools:n});for(const t of n){const n=g().find(o=>o.name===t.tool)?.displayName??t.tool,s=t.installed?t.addons?f.t("addons.status_on"):f.t("addons.status_off"):f.t("addons.status_not_installed");console.log(` ${t.installed&&t.addons?o.green("●"):o.gray("○")} ${n}:${s}`)}return}throw m(f.t("addons.unknown_action",{action:y}),`${i} addons install`)}
|
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 i,moveOtherToolsAfterFallback as l,saveGatewayFallback as s,toolsWeConfigured as a}from"./base.js";import{i18n as n}from"../lib/i18n.js";import{configManager as r,savedApiKeys as c}from"../lib/config.js";import{toolManager as p,SUPPORTED_TOOLS as d}from"../lib/tool-manager.js";import{validateApiKey as u,fetchModels as m}from"../lib/api-validator.js";import{CODEX_ONE_MILLION_CONTEXT_SETTING as f,setCodexOneMillionContext as g}from"../lib/tools/codex.js";import{resolveModelCatalog as h}from"../lib/model-catalog.js";import{CLAUDE_DESKTOP_FORCE_REGISTRY_SETTING as y,CLAUDE_DESKTOP_HIDE_OFFICIAL_LOGIN_SETTING as w}from"../lib/tools/claude-desktop.js";import{operationError as _,authenticationError as k,networkError as b,EXIT_CODES as v}from"../lib/errors.js";import{canPrompt as C,emitJson as x,hasExplicitYes as S,isColorEnabled as j,isDryRun as K,isJsonMode as M,isNonInteractive as $,shouldAutoConfirm as T}from"../lib/runtime-options.js";import{appsForTools as N,appUpgradeCommand as A,getApp as I}from"../lib/app-update.js";import{join as O}from"path";import{confirmAction as E}from"../lib/confirm.js";import{asksBeforeWriting as G,confirmWritePlan as B,printWritePlan as F,toolWritePlan as P}from"../lib/write-plan.js";import q from"inquirer";import{logger as D}from"../utils/logger.js";import{forgetInstalls as L}from"../lib/tools/tool-installs.js";import{CLI_NAME as R,brandEnv as V}from"../lib/brand.js";import{unsupportedUpgradeTargets as Y,upgradeCommand as U}from"./upgrade.js";import{track as z}from"../lib/telemetry.js";import{CCSWITCH_SETTING as H,buildCcSwitchCards as W,ccSwitchContext as J,ccSwitchSelector as Q,ourCcSwitchCards as X,removeCcSwitchCards as Z,isAdditiveCcSwitchApp as ee,inspectCcSwitch as oe,quitCcSwitch as te,writeCcSwitchCards as ie}from"../lib/ccswitch.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 le(e){const o=await m(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 se(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 ae(o){console.log(e.green(o))}function ne(o){console.log(e.yellow(o))}function re(o){console.error(e.red(o))}let ce=null;function pe(e){const o={operation:1,authentication:2,network:3};(!ce||o[e]>o[ce])&&(ce=e)}async function de(o,t){M()||console.log(e.gray(n.t("setup.validating",{label:o})));const i=await u(t);if(i.valid)return!0;const l=n.t("errors.key_placeholder"),s="--key"===o?`${R} setup --key ${l}`:`${R} setup ${o} ${l}`;let a;if("network_error"===i.error?(pe("network"),a=b(n.t("setup.unreachable",{url:r.getBaseUrl(),reason:i.message||"network error"}),`${R} base auto`,"network_error")):"invalid_api_key"===i.error?(pe("authentication"),a=k(n.t("setup.invalid_key",{label:o,reason:i.message||"invalid"}),s,"invalid_api_key")):(pe("operation"),a=_(n.t("setup.validate_failed",{label:o,reason:i.message||i.error||"unknown"}),s,i.error)),M())throw a;return re(a.message),console.log(e.gray(n.t("errors.next_step",{command:a.hint}))),!1}async function ue(t,i,l={}){const{oneMillion:s,officialLogin:a,desktopRegistry:c,force:u,takeOver:m}=l,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!==a&&r.setToolSetting("claude-desktop",w,!a),await p.applyPrivateConfig(t,i,r.getModelsForTool(t),{force:u,takeOver:m})}catch(e){if(M())throw _(e instanceof Error?e.message:String(e),`${R} setup --key ${n.t("errors.key_placeholder")}`,"config_write_failed");const o=(e instanceof Error?e.message:String(e)).replace(/\s+/g," ").trim();return re("× "+n.t("setup.apply_failed",{tool:g.displayName,reason:o})),!1}return p.printApplied(t),u&&console.log(e.gray(" "+n.t("config.force_done",{tool:g.displayName,name:t}))),"codex"===t&&void 0!==s&&console.log(e.gray(" "+n.t(s?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))),o(t)?.isInstalled&&!p.isToolInstalled(t)&&console.log(e.yellow(" ! "+n.t("setup.gui_preconfigured",{tool:g.displayName,install:g.installCommand}))),!0}function me(e){return!o(e)?.isInstalled&&!p.isToolInstalled(e)}async function fe(e){if(S())return!0;const o=d[e]?.displayName??e;return C()?E({message:n.t("setup.ask_detected_tool",{tool:o}),defaultValue:!0}):(ne(n.t("setup.detected_tool_hint",{tool:o,name:e})),!1)}export async function installMissingApps(o,t,i){const l=N(o).filter(e=>{if(i&&!i.includes(e))return!1;const o=I(e)?.appInstaller;try{return Boolean(o&&!o.blocker()&&!o.installedPath())}catch(o){return D.logError(`setup: app installed? ${e}`,o),!1}});if(0===l.length)return!1;const s=e=>I(e)?.displayName??e;let a=t;if(void 0===a&&!M())if(T())a=!$();else if(C()){const e=l.map(s).join(n.t("setup.list_separator")),o=l.reduce((e,o)=>e+(I(o)?.appInstaller.sizeMb()??0),0);console.log(""),a=(await q.prompt([{type:"confirm",name:"go",message:n.t("setup.install_app_confirm",{tools:e,size:String(o)}),default:!0}])).go}if(!a&&!M())for(const o of l)console.log(e.gray(n.t("setup.install_app_hint",{tool:s(o),command:A(o)})));return Boolean(a)}function ge(e){ne(n.t("setup.still_missing",{tools:e.map(e=>d[e].displayName).join(n.t("setup.list_separator")),commands:e.map(e=>`${R} config ${e} --yes`).join(n.t("setup.list_separator"))}))}function he(o,t,i=[]){const l=P(o),s=O(r.getConfigDir(),"config.yaml");if(M())x({dry_run:!0,tools:l,install_first:i,key_file:t?s:null});else{if(0===l.length&&0===i.length){const o=(j()?e.cyan:e=>e)(n.t("runtime.dry_run_label"));return void console.log(`${o} ${n.t("setup.dry_run_none")}`)}F(l,{label:n.t("runtime.dry_run_label"),keyFile:t?s:void 0,installFirst:i})}}function ye(e){return Boolean(o(e)?.installSpec||I(e)?.appInstaller)}function we(e){return N(e).filter(e=>{const o=I(e);if(!o||o.tool===e)return!1;try{return!o.appInstaller.blocker()}catch(o){return D.logError(`setup: app blocker ${e}`,o),!1}})}function _e(e){const o=I(e);let t,i;if(o&&o.tool!==e){try{t=Boolean(o.appInstaller.installedPath())}catch(o){D.logError(`setup: app installed? ${e}`,o),t=!1}i=t?o.installedVersion?.():null}else t=p.isToolInstalled(e),i=t?p.installedVersion(e):null;return t?i?n.t("setup.pick_installed",{version:i}):n.t("setup.pick_installed_plain"):n.t("setup.pick_not_installed")}function ke(o,t){return{name:`${I(o)?.displayName??d[o]?.displayName??o} ${e.gray(_e(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 be(){return"darwin"===process.platform||"win32"===process.platform||p.isToolInstalled("claude-desktop")}export async function prepareCcSwitch(){let e,o=await oe();if("running"===o.problem&&!K()&&(S()||C())&&(S()||await E({message:n.t("ccswitch.ask_quit"),defaultValue:!0}))){const t=te();t&&(e=t.reopen,o=await oe())}if(o.ok||K()&&"running"===o.problem)return{state:o,reopen:e};const t=n.t(`ccswitch.problem_${o.problem}`,{path:o.dbPath,schema:String(o.schema??"?"),node:process.versions.node});if(z("ccswitch","unsupported_schema"===o.problem||"unexpected_tables"===o.problem||"unreadable"===o.problem?"fail":"skip",{detail:{problem:o.problem,schema:o.schema,detail:o.detail,platform:process.platform}}),M())throw _(t,`${R} setup --key ${n.t("errors.key_placeholder")}`,`ccswitch_${o.problem}`);return re(t),e?.(),null}export async function removeFromCcSwitch(t){const i=o(t)?.ccSwitch;if(!i)return"none";const l=d[t].displayName;let s=!1;try{s=i.unloadAsCards?.({savedKeys:c()})??!1}catch(e){D.logError(`removeFromCcSwitch(${t})`,e)}const a=Q(t);if(0===(await X(a)).length)return r.setMachineSetting(t,H,""),s?"removed":"none";const p=await prepareCcSwitch();if(!p)return"blocked";try{const o=await Z(a);return r.setMachineSetting(t,H,""),z("ccswitch","ok",{detail:{mode:"remove",schema:p.state.schema,tools:[t],cards:o}}),console.log(e.green(n.t("ccswitch.removed_cards",{tool:l,count:String(o)}))),"removed"}catch(e){return z("ccswitch","fail",{error:e,detail:{mode:"remove",schema:p.state.schema}}),re("× "+n.t("ccswitch.write_failed",{reason:e instanceof Error?e.message:String(e)})),"blocked"}finally{p.reopen?.()}}export async function setupCommand(u){ce=null;const m=DEDICATED_KEYS.map(e=>({...e,apiKey:u[e.option]?.trim()})).filter(e=>Boolean(e.apiKey)),y=void 0!==u.oneMillion||void 0!==u.claudeOfficial||void 0!==u.desktopRegistry;let w=u.key?.trim();const _=u.upgrade??[],k=Y(_);if(k.length>0)return re(n.t("upgrade.unsupported",{tool:k.join(", ")})),void(process.exitCode=v.usage);if(_.length>0&&(K()?console.log(n.t("setup.dry_run_upgrade",{tools:_.join(", ")})):(await U(_),L()),!w&&0===m.length&&!y))return;w||0!==m.length||y||!G()||(w=(await q.prompt([{type:"password",name:"key",mask:"*",message:n.t("setup.ask_key")}])).key?.trim()||void 0);const b=void 0!==u.oneMillion,x=void 0!==u.claudeOfficial;let j;if(x&&(j=parseOnOff(u.claudeOfficial),void 0===j))return re(n.t("setup.claude_official_invalid",{value:String(u.claudeOfficial)})),void(process.exitCode=1);const N=void 0!==u.desktopRegistry;let A;if(N&&(A=parseOnOff(u.desktopRegistry),void 0===A))return re(n.t("setup.desktop_registry_invalid",{value:String(u.desktopRegistry)})),void(process.exitCode=1);const F=x||N,P=Boolean(w||m.length>0),pe={oneMillion:u.oneMillion,officialLogin:j,desktopRegistry:A,force:u.force};if(!P&&(b||F)&&K())return void he([...b?["codex"]:[],...F?["claude-desktop"]:[]],!1);if(!P&&(b||F)){if(b){const e=r.getApiKeyForTool("codex");if(e)try{const o=!0===u.oneMillion;r.setToolSetting("codex",f,o);const t=await h(e);g(o,t??void 0),ae(n.t(o?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))}catch(e){re(n.t("setup.apply_failed",{tool:d.codex.displayName,reason:e instanceof Error?e.message:String(e)})),process.exitCode=1}else re(n.t("setup.codex_1m_missing_key")),process.exitCode=1}if(F){const e=r.getApiKeyForTool("claude-desktop");e?await ue("claude-desktop",e,{...pe,oneMillion:void 0,takeOver:!0})?await t(["claude-desktop"],{apps:{install:!1}}):process.exitCode=1:(re(n.t("setup.desktop_official_login_missing_key")),process.exitCode=1)}return}if(!P)return re(n.t("setup.usage")),void(process.exitCode=1);const _e=u.ccswitchUse?"use":u.ccswitch?"add":null,ve=_e?await prepareCcSwitch():null;if(_e&&!ve)return void(process.exitCode=1);const Ce=K(),xe=Ce?null:await i(w||m[0].apiKey,{save:!1}),Se=[],je=[];let Ke,Me=0,$e=0;const Te=new Set,Ne=m.map(e=>({tool:e.tool,label:`--${e.option}`,apiKey:e.apiKey,need:e.need}));for(const e of Ne){if(!await de(e.label,e.apiKey)){$e+=1;continue}const o=await le(e.apiKey);!o.probed||se(o,e.need)?(o.probed||ne(n.t("setup.probe_failed",{label:e.label})),Se.push({tool:e.tool,apiKey:e.apiKey,dedicated:!0}),Te.add(e.tool)):(re(n.t(`setup.key_no_${e.need}`,{label:e.label,tool:d[e.tool].displayName})),$e+=1)}const Ae=!!w&&await de("--key",w);w&&!Ae&&(Ke=v[ce??"operation"]);const Ie=w&&Ae?await le(w):void 0;w&&Ie&&!Ie.probed&&ne(n.t("setup.probe_failed",{label:"--key"})),!(w&&Ie&&Ie.probed)||Ie.hasClaude||Ie.hasGpt||Ie.hasGrok||Ie.hasGemini||(re(n.t("setup.key_no_family")),Ke=1);const Oe=Boolean(w)&&0===m.length&&!u.fromInstaller&&G()&&!_e;if(w&&Ie&&void 0===Ke){const e=Ie.hasClaude||Ie.hasGpt||Ie.hasGrok||Ie.hasGemini,o=[{tool:"claude-code",capable:Ie.hasClaude,skipMsg:n.t(be()?"setup.skip_no_claude_desktop":"setup.skip_no_claude")},{tool:"codex",capable:Ie.hasGpt,skipMsg:n.t("setup.skip_no_gpt")},{tool:"grok",capable:Ie.hasGrok,skipMsg:n.t("setup.skip_no_grok")},{tool:"claude-desktop",capable:Ie.hasClaude&&be(),skipMsg:"",quiet:!0},{tool:"agy",capable:Ie.hasGemini,skipMsg:n.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)Te.has(e.tool)||(e.capable?(!e.ask||Ce||Oe||await fe(e.tool))&&(Se.push({tool:e.tool,apiKey:w,dedicated:!1}),Te.add(e.tool)):e.quiet||ne(e.skipMsg))}let Ee,Ge=u.install,Be=[];if(Oe&&void 0===Ke&&Se.length>0){const e=await async function(e,o){console.log("");const{configure:t}=await q.prompt([{type:"checkbox",name:"configure",message:n.t("setup.pick_configure"),choices:e.map(e=>ke(e,!0))}]);let i=[];const l=[...e.filter(ye),...we(e)];if(o&&l.length>0){const e=e=>I(e)?.tool??e;i=(await q.prompt([{type:"checkbox",name:"upgrade",message:n.t("setup.pick_upgrade"),choices:l.map(o=>ke(o,t.includes(e(o))))}])).upgrade}return 0===t.length&&0===i.length?(console.log(n.t("setup.pick_none")),null):{configure:t,upgrade:i}}(Se.map(e=>e.tool),void 0===u.upgrade);if(!e)return void(process.exitCode=v.cancelled);if(0===e.configure.length)return void await U(e.upgrade);Be=e.upgrade,Ee=[],!0!==Ge&&(Ge=!1);const o=e.configure.filter(e=>me(e)&&!Be.includes(e)&&!Ge);if(o.length>0&&ne(n.t("setup.pick_configure_skip",{tools:o.map(e=>d[e].displayName).join(n.t("setup.list_separator"))})),Se.splice(0,Se.length,...Se.filter(t=>e.configure.includes(t.tool)&&!o.includes(t.tool))),0===Se.length)return void(Be.length>0&&await U(Be))}const Fe=Boolean(w&&Ae&&void 0===Ke);if(_e&&ve)return void 0!==Ke&&0===Se.length?(ve.reopen?.(),void(process.exitCode=Ke)):(await async function(i,l,a,c,u,m){const f=i.filter(e=>p.supportsCcSwitch(e.tool)),g=i.filter(e=>!p.supportsCcSwitch(e.tool)),h=e=>e.map(e=>d[e.tool].displayName).join(n.t("setup.list_separator"));if(g.length>0&&ne(n.t("ccswitch.not_supported",{tools:h(g)})),0===f.length)return re(n.t("ccswitch.nothing")),a.reopen?.(),void(process.exitCode=1);const y=f.filter(e=>o(e.tool)?.ccSwitch?.handOver&&!r.getMachineSetting(e.tool,H)&&p.holdsOurConfig(e.tool)),w=n.t(l?"ccswitch.plan_use":"ccswitch.plan_add",{tools:h(f),path:a.state.dbPath})+(y.length>0?"\n"+n.t("ccswitch.plan_handover",{tools:h(y)}):"");if(K())return void console.log(w);if(!m&&G()&&(console.log(w),!await E({message:n.t("ccswitch.confirm"),defaultValue:!0})))return a.reopen?.(),void(process.exitCode=v.cancelled);s(),c();const _=[],k=[];for(const t of f){const i=d[t.tool].displayName,s=o(t.tool).ccSwitch;try{const o=await J(t.tool,t.apiKey,r.getModelsForTool(t.tool)),a=W(t.tool,o);if(0===a.cards.length){ne(n.t("ccswitch.no_models",{tool:i}));continue}if(s.handOver&&p.holdsOurConfig(t.tool)&&(p.unloadPrivateConfig(t.tool),r.getMachineSetting(t.tool,H)||console.log(e.gray(" "+n.t("ccswitch.handed_over",{tool:i})))),l&&me(t.tool))ne(n.t("ccswitch.not_installed_card_only",{tool:i}));else if(l&&s.applyAsCards)s.applyAsCards({...o,takeOver:!0},a.cards),_.push(t.tool);else if(l){if(!await ue(t.tool,t.apiKey,{...u,takeOver:!0}))continue;_.push(t.tool)}k.push({tool:t.tool,group:{...a,current:_.includes(t.tool)}})}catch(e){re("× "+n.t("ccswitch.card_failed",{tool:i,reason:e instanceof Error?e.message:String(e)}))}}try{const o=k.length>0?await ie(k.map(e=>e.group)):[];o.forEach((e,o)=>{const t=k[o].tool,i=d[t].displayName;r.setMachineSetting(t,H,_.includes(t)?"use":"add");const l=String(e.written),s=e.current?ee(e.app)?"ccswitch.done_enabled":"ccswitch.done_use":_.includes(t)&&e.proxyMode?"ccswitch.done_proxy":e.written>1?"ccswitch.done_add_many":"ccswitch.done_add";ae(n.t(s,{tool:i,count:l})),e.skipped.length>0&&ne(n.t("ccswitch.skipped_foreign",{tool:i,ids:e.skipped.join(", ")}))}),z("ccswitch","ok",{detail:{mode:l?"use":"add",schema:a.state.schema,tools:k.map(e=>e.tool)}}),o.some(e=>!e.current)&&console.log(e.gray(" "+n.t("ccswitch.switch_hint")))}catch(e){z("ccswitch","fail",{error:e,detail:{mode:l?"use":"add",schema:a.state.schema}}),re("× "+n.t("ccswitch.write_failed",{reason:e instanceof Error?e.message:String(e)})),process.exitCode=1}a.reopen?.(),_.length>0&&await t(_,{apps:{install:!1}}),k.length<f.length&&(process.exitCode=1)}(Se,"use"===_e,ve,()=>{Fe&&w&&r.setApiKey(w);for(const e of Se)e.dedicated?r.setToolApiKey(e.tool,e.apiKey):r.clearToolApiKey(e.tool)},pe,Boolean(u.fromInstaller)),void(void 0!==Ke&&(process.exitCode=Ke)));if(Ce)return he(Se.filter(e=>!me(e.tool)).map(e=>e.tool),Se.length>0,Se.filter(e=>me(e.tool)).map(e=>e.tool)),void(($e>0||void 0!==Ke)&&(process.exitCode=Ke??v[ce??"operation"]));const Pe=Se.filter(e=>!me(e.tool)),qe=Fe||Se.some(e=>e.dedicated),De=xe?a().filter(e=>!Se.some(o=>o.tool===e.tool)):[],Le=!u.fromInstaller&&G(),Re=Pe.filter(e=>o(e.tool)?.ccSwitch&&r.getMachineSetting(e.tool,H));if(Le&&Re.length>0&&console.log(e.yellow(n.t("ccswitch.plan_reclaim",{tools:Re.map(e=>d[e.tool].displayName).join(n.t("setup.list_separator"))}))),(Se.length>0||qe)&&!u.fromInstaller&&!await B([...Pe.map(e=>e.tool),...De.map(e=>e.tool)],{keyFile:qe?O(r.getConfigDir(),"config.yaml"):void 0,installFirst:Se.filter(e=>me(e.tool)).map(e=>e.tool)}))return void(process.exitCode=v.cancelled);Be.length>0&&(await U(Be),L()),(Se.length>0||qe)&&s(),Fe&&w&&r.setApiKey(w);for(const e of Se)me(e.tool)?(e.dedicated&&r.setToolApiKey(e.tool,e.apiKey),je.push({tool:e.tool,apiKey:e.apiKey,dedicated:e.dedicated})):await ue(e.tool,e.apiKey,{...pe,takeOver:e.dedicated||Le})?(e.dedicated?r.setToolApiKey(e.tool,e.apiKey):r.clearToolApiKey(e.tool),Me+=1):($e+=1,Te.delete(e.tool));const Ve=Se.length>0||qe?await l(De):[];if(void 0!==Ke)return je.length>0&&ge(je.map(e=>e.tool)),void(process.exitCode=Ke);let Ye=[];if(je.length>0){const o=await async function(o,t,i){const l=o.map(e=>e.tool);if(0===l.length)return{still:[],applied:[],failed:[]};const s=l.map(e=>d[e].displayName).join(n.t("setup.list_separator"));let a=t;if(void 0!==a||M()||(T()?a=!$():process.stdin.isTTY&&(console.log(""),a=(await q.prompt([{type:"confirm",name:"go",message:n.t("setup.install_confirm",{tools:s}),default:!0}])).go)),!a){console.log("");for(const o of l)console.log(e.yellow("! "+n.t("setup.install_hint",{tool:d[o].displayName,install:d[o].installCommand})));return M()||console.log(e.gray(n.t("setup.install_all_hint",{cli:R}))),{still:l,applied:[],failed:[]}}const c=[];for(const o of l){console.log(e.bold(`\n${d[o].displayName}`));try{await p.installTool(o)}catch(e){D.logError(`setup: install ${o}`,e)}L(),p.isToolInstalled(o)||c.push(o)}const u=l.filter(e=>!c.includes(e));u.length>0&&console.log("");const m=[],f=[];for(const{tool:e,apiKey:t,dedicated:l}of o.filter(e=>u.includes(e.tool)))await ue(e,t,i)?(m.push(e),l||r.clearToolApiKey(e)):f.push(e);return{still:c,applied:m,failed:f}}(je,Ge,pe);Ye=o.still,Me+=o.applied.length,$e+=o.failed.length;for(const e of[...Ye,...o.failed])Te.delete(e)}if(await async function(t){const i=t.filter(e=>o(e)?.ccSwitch&&r.getMachineSetting(e,H));if(0===i.length)return;const l=[];for(const e of i){r.setMachineSetting(e,H,"");try{o(e).ccSwitch.unloadAsCards?.({savedKeys:c()})}catch(o){D.logError(`reclaimFromCcSwitch(${e})`,o)}(await X(Q(e))).length>0&&l.push(e)}if(0===l.length)return;const s=l.map(e=>d[e].displayName).join(n.t("setup.list_separator"));let a,p=await oe();if("running"===p.problem&&(S()||C())&&(S()||await E({message:n.t("ccswitch.ask_quit_reclaim",{tools:s}),defaultValue:!0}))){const e=te();e&&(a=e.reopen,p=await oe())}if(!p.ok)return ne(n.t("ccswitch.reclaim_left",{tools:s})),z("ccswitch","skip",{detail:{mode:"reclaim",problem:p.problem,schema:p.schema,tools:l}}),void a?.();try{for(const o of l){const t=await Z(Q(o));console.log(e.gray(" "+n.t("ccswitch.reclaimed",{tool:d[o].displayName,count:String(t)})))}z("ccswitch","ok",{detail:{mode:"reclaim",schema:p.schema,tools:l}})}catch(e){z("ccswitch","fail",{error:e,detail:{mode:"reclaim",schema:p.schema}}),ne(n.t("ccswitch.reclaim_left",{tools:s}))}finally{a?.()}}([...Te].filter(e=>!Ye.includes(e))),Me>0){const t=[...Te].filter(e=>!o(e)?.isInstalled&&!Ye.includes(e)),i=t.map(e=>d[e]?.command).filter(Boolean).join(" / "),l=n.t("setup.done",{count:String(Me)});ae("\n"+(i?`${l}${n.t("setup.done_commands",{commands:i})}`:l)),Ye.length>0&&ge(Ye);for(const e of t){const o=p.ensureNativeOnPath(e);o&&ae(n.t("setup.path_added",{tool:d[e].displayName,dir:o}))}const s=t.filter(e=>!p.isOnPath(e));if(s.length>0&&!M()&&"1"!==V("PATH_HINT_BY_CALLER")){const o=s.map(e=>d[e].command).join(" / ");console.log(e.yellow(" ! "+n.t("win32"===process.platform?"setup.path_reload_windows":"setup.path_reload",{commands:o})))}}0===Me&&Ye.length>0&&ge(Ye),$e>0&&(re(n.t("setup.failed_summary",{count:String($e)})),M()||console.error(`${R} setup --key ${n.t("errors.key_placeholder")}`)),await t([...Te,...Ve],{apps:{install:await installMissingApps([...Te],Ge,Ee)}}),($e>0||0===Me&&0===Ye.length)&&(process.exitCode=v[ce??"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 i,moveOtherToolsAfterFallback as l,saveGatewayFallback as s,toolsWeConfigured as a}from"./base.js";import{i18n as n}from"../lib/i18n.js";import{configManager as r,savedApiKeys as c}from"../lib/config.js";import{toolManager as d,SUPPORTED_TOOLS as p}from"../lib/tool-manager.js";import{validateApiKey as u,fetchModels as m}from"../lib/api-validator.js";import{CODEX_ONE_MILLION_CONTEXT_SETTING as f,setCodexOneMillionContext as g}from"../lib/tools/codex.js";import{resolveModelCatalog as h}from"../lib/model-catalog.js";import{CLAUDE_DESKTOP_FORCE_REGISTRY_SETTING as y,CLAUDE_DESKTOP_HIDE_OFFICIAL_LOGIN_SETTING as w}from"../lib/tools/claude-desktop.js";import{operationError as _,authenticationError as k,networkError as b,EXIT_CODES as v}from"../lib/errors.js";import{canPrompt as C,emitJson as x,hasExplicitYes as S,isColorEnabled as j,isDryRun as K,isJsonMode as M,isNonInteractive as $,shouldAutoConfirm as T}from"../lib/runtime-options.js";import{appsForTools as I,appUpgradeCommand as N,getApp as A}from"../lib/app-update.js";import{join as O}from"path";import{confirmAction as E}from"../lib/confirm.js";import{asksBeforeWriting as G,confirmWritePlan as B,printWritePlan as F,toolWritePlan as P}from"../lib/write-plan.js";import q from"inquirer";import{logger as D}from"../utils/logger.js";import{forgetInstalls as L}from"../lib/tools/tool-installs.js";import{CLI_NAME as R,brandEnv as V}from"../lib/brand.js";import{unsupportedUpgradeTargets as Y,upgradeCommand as U}from"./upgrade.js";import{track as z}from"../lib/telemetry.js";import{CCSWITCH_SETTING as H,buildCcSwitchCards as W,ccSwitchContext as J,ccSwitchSelector as Q,ourCcSwitchCards as X,removeCcSwitchCards as Z,isAdditiveCcSwitchApp as ee,inspectCcSwitch as oe,quitCcSwitch as te,writeCcSwitchCards as ie}from"../lib/ccswitch.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 le(e){const o=await m(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 se(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 ae(o){console.log(e.green(o))}function ne(o){console.log(e.yellow(o))}function re(o){console.error(e.red(o))}let ce=null;function de(e){const o={operation:1,authentication:2,network:3};(!ce||o[e]>o[ce])&&(ce=e)}async function pe(o,t){M()||console.log(e.gray(n.t("setup.validating",{label:o})));const i=await u(t);if(i.valid)return!0;const l=n.t("errors.key_placeholder"),s="--key"===o?`${R} setup --key ${l}`:`${R} setup ${o} ${l}`;let a;if("network_error"===i.error?(de("network"),a=b(n.t("setup.unreachable",{url:r.getBaseUrl(),reason:i.message||"network error"}),`${R} base auto`,"network_error")):"invalid_api_key"===i.error?(de("authentication"),a=k(n.t("setup.invalid_key",{label:o,reason:i.message||"invalid"}),s,"invalid_api_key")):(de("operation"),a=_(n.t("setup.validate_failed",{label:o,reason:i.message||i.error||"unknown"}),s,i.error)),M())throw a;return re(a.message),console.log(e.gray(n.t("errors.next_step",{command:a.hint}))),!1}async function ue(t,i,l={}){const{oneMillion:s,officialLogin:a,desktopRegistry:c,force:u,takeOver:m}=l,g=p[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!==a&&r.setToolSetting("claude-desktop",w,!a),await d.applyPrivateConfig(t,i,r.getModelsForTool(t),{force:u,takeOver:m})}catch(e){if(M())throw _(e instanceof Error?e.message:String(e),`${R} setup --key ${n.t("errors.key_placeholder")}`,"config_write_failed");const o=(e instanceof Error?e.message:String(e)).replace(/\s+/g," ").trim();return re("× "+n.t("setup.apply_failed",{tool:g.displayName,reason:o})),!1}return d.printApplied(t),u&&console.log(e.gray(" "+n.t("config.force_done",{tool:g.displayName,name:t}))),"codex"===t&&void 0!==s&&console.log(e.gray(" "+n.t(s?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))),o(t)?.isInstalled&&!d.isToolInstalled(t)&&console.log(e.yellow(" ! "+n.t("setup.gui_preconfigured",{tool:g.displayName,install:g.installCommand}))),!0}function me(e){return!o(e)?.isInstalled&&!d.isToolInstalled(e)}async function fe(e){if(S())return!0;const o=p[e]?.displayName??e;return C()?E({message:n.t("setup.ask_detected_tool",{tool:o}),defaultValue:!0}):(ne(n.t("setup.detected_tool_hint",{tool:o,name:e})),!1)}export async function installMissingApps(o,t,i){const l=I(o).filter(e=>{if(i&&!i.includes(e))return!1;const o=A(e)?.appInstaller;try{return Boolean(o&&!o.blocker()&&!o.installedPath())}catch(o){return D.logError(`setup: app installed? ${e}`,o),!1}});if(0===l.length)return!1;const s=e=>A(e)?.displayName??e;let a=t;if(void 0===a&&!M())if(T())a=!$();else if(C()){const e=l.map(s).join(n.t("setup.list_separator")),o=l.reduce((e,o)=>e+(A(o)?.appInstaller.sizeMb()??0),0);console.log(""),a=(await q.prompt([{type:"confirm",name:"go",message:n.t("setup.install_app_confirm",{tools:e,size:String(o)}),default:!0}])).go}if(!a&&!M())for(const o of l)console.log(e.gray(n.t("setup.install_app_hint",{tool:s(o),command:N(o)})));return Boolean(a)}function ge(e){ne(n.t("setup.still_missing",{tools:e.map(e=>p[e].displayName).join(n.t("setup.list_separator")),commands:e.map(e=>`${R} config ${e} --yes`).join(n.t("setup.list_separator"))}))}function he(o,t,i=[]){const l=P(o),s=O(r.getConfigDir(),"config.yaml");if(M())x({dry_run:!0,tools:l,install_first:i,key_file:t?s:null});else{if(0===l.length&&0===i.length){const o=(j()?e.cyan:e=>e)(n.t("runtime.dry_run_label"));return void console.log(`${o} ${n.t("setup.dry_run_none")}`)}F(l,{label:n.t("runtime.dry_run_label"),keyFile:t?s:void 0,installFirst:i})}}function ye(e){return Boolean(o(e)?.installSpec||A(e)?.appInstaller)}function we(e){return I(e).filter(e=>{const o=A(e);if(!o||o.tool===e)return!1;try{return!o.appInstaller.blocker()}catch(o){return D.logError(`setup: app blocker ${e}`,o),!1}})}function _e(e){const o=A(e);let t,i;if(o&&o.tool!==e){try{t=Boolean(o.appInstaller.installedPath())}catch(o){D.logError(`setup: app installed? ${e}`,o),t=!1}i=t?o.installedVersion?.():null}else t=d.isToolInstalled(e),i=t?d.installedVersion(e):null;return t?i?n.t("setup.pick_installed",{version:i}):n.t("setup.pick_installed_plain"):n.t("setup.pick_not_installed")}function ke(o,t){return{name:`${A(o)?.displayName??p[o]?.displayName??o} ${e.gray(_e(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 be(){return"darwin"===process.platform||"win32"===process.platform||d.isToolInstalled("claude-desktop")}export async function prepareCcSwitch(){let e,o=await oe();if("running"===o.problem&&!K()&&(S()||C())&&(S()||await E({message:n.t("ccswitch.ask_quit"),defaultValue:!0}))){const t=te();t&&(e=t.reopen,o=await oe())}if(o.ok||K()&&"running"===o.problem)return{state:o,reopen:e};const t=n.t(`ccswitch.problem_${o.problem}`,{path:o.dbPath,schema:String(o.schema??"?"),node:process.versions.node});if(z("ccswitch","unsupported_schema"===o.problem||"unexpected_tables"===o.problem||"unreadable"===o.problem?"fail":"skip",{detail:{problem:o.problem,schema:o.schema,detail:o.detail,platform:process.platform}}),M())throw _(t,`${R} setup --key ${n.t("errors.key_placeholder")}`,`ccswitch_${o.problem}`);return re(t),e?.(),null}export async function removeFromCcSwitch(t){const i=o(t)?.ccSwitch;if(!i)return"none";const l=p[t].displayName;let s=!1;try{s=i.unloadAsCards?.({savedKeys:c()})??!1}catch(e){D.logError(`removeFromCcSwitch(${t})`,e)}const a=Q(t);if(0===(await X(a)).length)return r.setMachineSetting(t,H,""),s?"removed":"none";const d=await prepareCcSwitch();if(!d)return"blocked";try{const o=await Z(a);return r.setMachineSetting(t,H,""),z("ccswitch","ok",{detail:{mode:"remove",schema:d.state.schema,tools:[t],cards:o}}),console.log(e.green(n.t("ccswitch.removed_cards",{tool:l,count:String(o)}))),"removed"}catch(e){return z("ccswitch","fail",{error:e,detail:{mode:"remove",schema:d.state.schema}}),re("× "+n.t("ccswitch.write_failed",{reason:e instanceof Error?e.message:String(e)})),"blocked"}finally{d.reopen?.()}}export async function setupCommand(u){ce=null;const m=DEDICATED_KEYS.map(e=>({...e,apiKey:u[e.option]?.trim()})).filter(e=>Boolean(e.apiKey)),y=void 0!==u.oneMillion||void 0!==u.claudeOfficial||void 0!==u.desktopRegistry;let w=u.key?.trim();const _=u.upgrade??[],k=Y(_);if(k.length>0)return re(n.t("upgrade.unsupported",{tool:k.join(", ")})),void(process.exitCode=v.usage);if(_.length>0&&(K()?console.log(n.t("setup.dry_run_upgrade",{tools:_.join(", ")})):(await U(_),L()),!w&&0===m.length&&!y))return;w||0!==m.length||y||!G()||(w=(await q.prompt([{type:"password",name:"key",mask:"*",message:n.t("setup.ask_key")}])).key?.trim()||void 0);const b=void 0!==u.oneMillion,x=void 0!==u.claudeOfficial;let j;if(x&&(j=parseOnOff(u.claudeOfficial),void 0===j))return re(n.t("setup.claude_official_invalid",{value:String(u.claudeOfficial)})),void(process.exitCode=1);const I=void 0!==u.desktopRegistry;let N;if(I&&(N=parseOnOff(u.desktopRegistry),void 0===N))return re(n.t("setup.desktop_registry_invalid",{value:String(u.desktopRegistry)})),void(process.exitCode=1);const F=x||I,P=Boolean(w||m.length>0),de={oneMillion:u.oneMillion,officialLogin:j,desktopRegistry:N,force:u.force};if(!P&&(b||F)&&K())return void he([...b?["codex"]:[],...F?["claude-desktop"]:[]],!1);if(!P&&(b||F)){if(b){const e=r.getApiKeyForTool("codex");if(e)try{const o=!0===u.oneMillion;r.setToolSetting("codex",f,o);const t=await h(e);g(o,t??void 0),ae(n.t(o?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))}catch(e){re(n.t("setup.apply_failed",{tool:p.codex.displayName,reason:e instanceof Error?e.message:String(e)})),process.exitCode=1}else re(n.t("setup.codex_1m_missing_key")),process.exitCode=1}if(F){const e=r.getApiKeyForTool("claude-desktop");e?await ue("claude-desktop",e,{...de,oneMillion:void 0,takeOver:!0})?await t(["claude-desktop"],{apps:{install:!1}}):process.exitCode=1:(re(n.t("setup.desktop_official_login_missing_key")),process.exitCode=1)}return}if(!P)return re(n.t("setup.usage")),void(process.exitCode=1);const _e=u.ccswitchUse?"use":u.ccswitch?"add":null,ve=_e?await prepareCcSwitch():null;if(_e&&!ve)return void(process.exitCode=1);const Ce=K(),xe=Ce?null:await i(w||m[0].apiKey,{save:!1}),Se=[],je=[];let Ke,Me=0,$e=0;const Te=new Set,Ie=m.map(e=>({tool:e.tool,label:`--${e.option}`,apiKey:e.apiKey,need:e.need}));for(const e of Ie){if(!await pe(e.label,e.apiKey)){$e+=1;continue}const o=await le(e.apiKey);!o.probed||se(o,e.need)?(o.probed||ne(n.t("setup.probe_failed",{label:e.label})),Se.push({tool:e.tool,apiKey:e.apiKey,dedicated:!0}),Te.add(e.tool)):(re(n.t(`setup.key_no_${e.need}`,{label:e.label,tool:p[e.tool].displayName})),$e+=1)}const Ne=!!w&&await pe("--key",w);w&&!Ne&&(Ke=v[ce??"operation"]);const Ae=w&&Ne?await le(w):void 0;w&&Ae&&!Ae.probed&&ne(n.t("setup.probe_failed",{label:"--key"})),!(w&&Ae&&Ae.probed)||Ae.hasClaude||Ae.hasGpt||Ae.hasGrok||Ae.hasGemini||(re(n.t("setup.key_no_family")),Ke=1);const Oe=Boolean(w)&&0===m.length&&!u.fromInstaller&&G()&&!_e;if(w&&Ae&&void 0===Ke){const e=Ae.hasClaude||Ae.hasGpt||Ae.hasGrok||Ae.hasGemini,o=[{tool:"claude-code",capable:Ae.hasClaude,skipMsg:n.t(be()?"setup.skip_no_claude_desktop":"setup.skip_no_claude")},{tool:"codex",capable:Ae.hasGpt,skipMsg:n.t("setup.skip_no_gpt")},{tool:"grok",capable:Ae.hasGrok,skipMsg:n.t("setup.skip_no_grok")},{tool:"claude-desktop",capable:Ae.hasClaude&&be(),skipMsg:"",quiet:!0},{tool:"agy",capable:Ae.hasGemini,skipMsg:n.t("setup.skip_no_gemini")},{tool:"codebuddy",capable:e&&d.isToolInstalled("codebuddy"),skipMsg:"",quiet:!0},{tool:"workbuddy",capable:e&&d.isToolInstalled("workbuddy"),skipMsg:"",quiet:!0},{tool:"dsh",capable:e&&d.isToolInstalled("dsh"),skipMsg:"",quiet:!0,ask:!0}];for(const e of o)Te.has(e.tool)||(e.capable?(!e.ask||Ce||Oe||await fe(e.tool))&&(Se.push({tool:e.tool,apiKey:w,dedicated:!1}),Te.add(e.tool)):e.quiet||ne(e.skipMsg))}let Ee,Ge=u.install,Be=[];if(Oe&&void 0===Ke&&Se.length>0){const e=await async function(e,o){console.log("");const{configure:t}=await q.prompt([{type:"checkbox",name:"configure",message:n.t("setup.pick_configure"),choices:e.map(e=>ke(e,!0))}]);let i=[];const l=[...e.filter(ye),...we(e)];if(o&&l.length>0){const e=e=>A(e)?.tool??e;i=(await q.prompt([{type:"checkbox",name:"upgrade",message:n.t("setup.pick_upgrade"),choices:l.map(o=>ke(o,t.includes(e(o))))}])).upgrade}return 0===t.length&&0===i.length?(console.log(n.t("setup.pick_none")),null):{configure:t,upgrade:i}}(Se.map(e=>e.tool),void 0===u.upgrade);if(!e)return void(process.exitCode=v.cancelled);if(0===e.configure.length)return void await U(e.upgrade);Be=e.upgrade,Ee=[],!0!==Ge&&(Ge=!1);const o=e.configure.filter(e=>me(e)&&!Be.includes(e)&&!Ge);if(o.length>0&&ne(n.t("setup.pick_configure_skip",{tools:o.map(e=>p[e].displayName).join(n.t("setup.list_separator"))})),Se.splice(0,Se.length,...Se.filter(t=>e.configure.includes(t.tool)&&!o.includes(t.tool))),0===Se.length)return void(Be.length>0&&await U(Be))}const Fe=Boolean(w&&Ne&&void 0===Ke);if(_e&&ve)return void 0!==Ke&&0===Se.length?(ve.reopen?.(),void(process.exitCode=Ke)):(await async function(i,l,a,c,u,m){const f=i.filter(e=>d.supportsCcSwitch(e.tool)),g=i.filter(e=>!d.supportsCcSwitch(e.tool)),h=e=>e.map(e=>p[e.tool].displayName).join(n.t("setup.list_separator"));if(g.length>0&&ne(n.t("ccswitch.not_supported",{tools:h(g)})),0===f.length)return re(n.t("ccswitch.nothing")),a.reopen?.(),void(process.exitCode=1);const y=f.filter(e=>o(e.tool)?.ccSwitch?.handOver&&!r.getMachineSetting(e.tool,H)&&d.holdsOurConfig(e.tool)),w=n.t(l?"ccswitch.plan_use":"ccswitch.plan_add",{tools:h(f),path:a.state.dbPath})+(y.length>0?"\n"+n.t("ccswitch.plan_handover",{tools:h(y)}):"");if(K())return void console.log(w);if(!m&&G()&&(console.log(w),!await E({message:n.t("ccswitch.confirm"),defaultValue:!0})))return a.reopen?.(),void(process.exitCode=v.cancelled);s(),c();const _=[],k=[];for(const t of f){const i=p[t.tool].displayName,s=o(t.tool).ccSwitch;try{const o=await J(t.tool,t.apiKey,r.getModelsForTool(t.tool)),a=W(t.tool,o);if(0===a.cards.length){ne(n.t("ccswitch.no_models",{tool:i}));continue}if(s.handOver&&d.holdsOurConfig(t.tool)&&(d.unloadPrivateConfig(t.tool),r.getMachineSetting(t.tool,H)||console.log(e.gray(" "+n.t("ccswitch.handed_over",{tool:i})))),l&&me(t.tool))ne(n.t("ccswitch.not_installed_card_only",{tool:i}));else if(l&&s.applyAsCards)s.applyAsCards({...o,takeOver:!0},a.cards),_.push(t.tool);else if(l){if(!await ue(t.tool,t.apiKey,{...u,takeOver:!0}))continue;_.push(t.tool)}k.push({tool:t.tool,group:{...a,current:_.includes(t.tool)}})}catch(e){re("× "+n.t("ccswitch.card_failed",{tool:i,reason:e instanceof Error?e.message:String(e)}))}}try{const o=k.length>0?await ie(k.map(e=>e.group)):[];o.forEach((e,o)=>{const t=k[o].tool,i=p[t].displayName;r.setMachineSetting(t,H,_.includes(t)?"use":"add");const l=String(e.written),s=e.current?ee(e.app)?"ccswitch.done_enabled":"ccswitch.done_use":_.includes(t)&&e.proxyMode?"ccswitch.done_proxy":e.written>1?"ccswitch.done_add_many":"ccswitch.done_add";ae(n.t(s,{tool:i,count:l})),e.skipped.length>0&&ne(n.t("ccswitch.skipped_foreign",{tool:i,ids:e.skipped.join(", ")}))}),z("ccswitch","ok",{detail:{mode:l?"use":"add",schema:a.state.schema,tools:k.map(e=>e.tool)}}),o.some(e=>!e.current)&&console.log(e.gray(" "+n.t("ccswitch.switch_hint")))}catch(e){z("ccswitch","fail",{error:e,detail:{mode:l?"use":"add",schema:a.state.schema}}),re("× "+n.t("ccswitch.write_failed",{reason:e instanceof Error?e.message:String(e)})),process.exitCode=1}a.reopen?.(),_.length>0&&await t(_,{apps:{install:!1}}),k.length<f.length&&(process.exitCode=1)}(Se,"use"===_e,ve,()=>{Fe&&w&&r.setApiKey(w);for(const e of Se)e.dedicated?r.setToolApiKey(e.tool,e.apiKey):r.clearToolApiKey(e.tool)},de,Boolean(u.fromInstaller)),void(void 0!==Ke&&(process.exitCode=Ke)));if(Ce)return he(Se.filter(e=>!me(e.tool)).map(e=>e.tool),Se.length>0,Se.filter(e=>me(e.tool)).map(e=>e.tool)),void(($e>0||void 0!==Ke)&&(process.exitCode=Ke??v[ce??"operation"]));const Pe=Se.filter(e=>!me(e.tool)),qe=Fe||Se.some(e=>e.dedicated),De=xe?a().filter(e=>!Se.some(o=>o.tool===e.tool)):[],Le=!u.fromInstaller&&G(),Re=Pe.filter(e=>o(e.tool)?.ccSwitch&&r.getMachineSetting(e.tool,H));if(Le&&Re.length>0&&console.log(e.yellow(n.t("ccswitch.plan_reclaim",{tools:Re.map(e=>p[e.tool].displayName).join(n.t("setup.list_separator"))}))),(Se.length>0||qe)&&!u.fromInstaller&&!await B([...Pe.map(e=>e.tool),...De.map(e=>e.tool)],{keyFile:qe?O(r.getConfigDir(),"config.yaml"):void 0,installFirst:Se.filter(e=>me(e.tool)).map(e=>e.tool)}))return void(process.exitCode=v.cancelled);Be.length>0&&(await U(Be),L()),(Se.length>0||qe)&&s(),Fe&&w&&r.setApiKey(w);for(const e of Se)me(e.tool)?(e.dedicated&&r.setToolApiKey(e.tool,e.apiKey),je.push({tool:e.tool,apiKey:e.apiKey,dedicated:e.dedicated})):await ue(e.tool,e.apiKey,{...de,takeOver:e.dedicated||Le})?(e.dedicated?r.setToolApiKey(e.tool,e.apiKey):r.clearToolApiKey(e.tool),Me+=1):($e+=1,Te.delete(e.tool));const Ve=Se.length>0||qe?await l(De):[];if(void 0!==Ke)return je.length>0&&ge(je.map(e=>e.tool)),void(process.exitCode=Ke);let Ye=[];if(je.length>0){const o=await async function(o,t,i){const l=o.map(e=>e.tool);if(0===l.length)return{still:[],applied:[],failed:[]};const s=l.map(e=>p[e].displayName).join(n.t("setup.list_separator"));let a=t;if(void 0!==a||M()||(T()?a=!$():process.stdin.isTTY&&(console.log(""),a=(await q.prompt([{type:"confirm",name:"go",message:n.t("setup.install_confirm",{tools:s}),default:!0}])).go)),!a){console.log("");for(const o of l)console.log(e.yellow("! "+n.t("setup.install_hint",{tool:p[o].displayName,install:p[o].installCommand})));return M()||console.log(e.gray(n.t("setup.install_all_hint",{cli:R}))),{still:l,applied:[],failed:[]}}const c=[];for(const o of l){console.log(e.bold(`\n${p[o].displayName}`));try{await d.installTool(o)}catch(e){D.logError(`setup: install ${o}`,e)}L(),d.isToolInstalled(o)||c.push(o)}const u=l.filter(e=>!c.includes(e));u.length>0&&console.log("");const m=[],f=[];for(const{tool:e,apiKey:t,dedicated:l}of o.filter(e=>u.includes(e.tool)))await ue(e,t,i)?(m.push(e),l||r.clearToolApiKey(e)):f.push(e);return{still:c,applied:m,failed:f}}(je,Ge,de);Ye=o.still,Me+=o.applied.length,$e+=o.failed.length;for(const e of[...Ye,...o.failed])Te.delete(e)}if(await async function(t){const i=t.filter(e=>o(e)?.ccSwitch&&r.getMachineSetting(e,H));if(0===i.length)return;const l=[];for(const e of i){r.setMachineSetting(e,H,"");try{o(e).ccSwitch.unloadAsCards?.({savedKeys:c()})}catch(o){D.logError(`reclaimFromCcSwitch(${e})`,o)}(await X(Q(e))).length>0&&l.push(e)}if(0===l.length)return;const s=l.map(e=>p[e].displayName).join(n.t("setup.list_separator"));let a,d=await oe();if("running"===d.problem&&(S()||C())&&(S()||await E({message:n.t("ccswitch.ask_quit_reclaim",{tools:s}),defaultValue:!0}))){const e=te();e&&(a=e.reopen,d=await oe())}if(!d.ok)return ne(n.t("ccswitch.reclaim_left",{tools:s})),z("ccswitch","skip",{detail:{mode:"reclaim",problem:d.problem,schema:d.schema,tools:l}}),void a?.();try{for(const o of l){const t=await Z(Q(o));console.log(e.gray(" "+n.t("ccswitch.reclaimed",{tool:p[o].displayName,count:String(t)})))}z("ccswitch","ok",{detail:{mode:"reclaim",schema:d.schema,tools:l}})}catch(e){z("ccswitch","fail",{error:e,detail:{mode:"reclaim",schema:d.schema}}),ne(n.t("ccswitch.reclaim_left",{tools:s}))}finally{a?.()}}([...Te].filter(e=>!Ye.includes(e))),Me>0){const t=[...Te].filter(e=>!o(e)?.isInstalled&&!Ye.includes(e)),i=t.map(e=>p[e]?.command).filter(Boolean).join(" / "),l=n.t("setup.done",{count:String(Me)});ae("\n"+(i?`${l}${n.t("setup.done_commands",{commands:i})}`:l)),Ye.length>0&&ge(Ye);for(const e of t){const o=d.ensureNativeOnPath(e);o&&ae(n.t("setup.path_added",{tool:p[e].displayName,dir:o}))}const s=t.filter(e=>!d.isOnPath(e));if(s.length>0&&!M()&&"1"!==V("PATH_HINT_BY_CALLER")){const o=s.map(e=>p[e].command).join(" / ");console.log(e.yellow(" ! "+n.t("win32"===process.platform?"setup.path_reload_windows":"setup.path_reload",{commands:o})))}}0===Me&&Ye.length>0&&ge(Ye),$e>0&&(re(n.t("setup.failed_summary",{count:String($e)})),M()||console.error(`${R} setup --key ${n.t("errors.key_placeholder")}`)),await t([...Te,...Ve],{apps:{install:await installMissingApps([...Te],Ge,Ee)},addons:u.addons??(!!u.fromInstaller||void 0)}),($e>0||0===Me&&0===Ye.length)&&(process.exitCode=v[ce??"operation"])}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from"chalk";import t from"inquirer";import{brandEnv as n,CLI_NAME as s}from"./brand.js";import{configManager as e}from"./config.js";import{addonsDeclined as r,addonsInstalled as i,installAddons as l,noteAddonsDeclined as a}from"./addons.js";import{i18n as m}from"./i18n.js";import{canPrompt as d,hasExplicitYes as f,isJsonMode as c}from"./runtime-options.js";import{track as p}from"./telemetry.js";import{toolManager as u}from"./tool-manager.js";import{getAdapter as g}from"./tools/registry.js";export async function offerAddons(e,l){if(!1===l||"1"===n("SKIP_ADDONS"))return;const p=e.map(o=>g(o)).filter(o=>!!o?.addons&&u.isToolInstalled(o.name));if(0===p.length)return;const k=p.map(o=>o.displayName).join("、");let y=!0===l||p.some(i);if(!y){if(r())return;if(f())y=!0;else if(d()&&!c()){const{ok:n}=await t.prompt([{type:"confirm",name:"ok",message:m.t("addons.offer",{tools:k}),default:!0}]);y=n,n||(a(),console.log(o.gray(" "+m.t("addons.declined_hint",{command:`${s} addons install`}))))}else console.log(o.gray(" "+m.t("addons.later_hint",{command:`${s} addons install`})))}y&&await runAddonsInstall(p)}export async function runAddonsInstall(o,t){const n=e.getBaseUrl(),s=t||e.getApiKey()||"",r=new Map;for(const n of o){const o=t||e.getApiKeyForTool(n.name)||s;o&&r.set(o,[...r.get(o)??[],n])}const i=[...r.entries()].sort(([o],[t])=>Number(o===s)-Number(t===s)),a=[];let m;const d=Date.now();for(const[o,t]of i){const s=await l(t,{apiKey:o,baseUrl:n});a.push(...s.outcomes),m??=s.skillError}return p("addons-install",a.some(o=>"written"===o.mcp)?"ok":"fail",{duration_ms:Date.now()-d,detail:{outcomes:a.map(o=>`${o.tool}:${o.mcp}:${o.skill}`).join(","),skill_error:m?"yes":"no"}}),c()||printOutcomes(a,m),a}export function printOutcomes(t,n){for(const n of t){if("absent"===n.mcp&&"absent"===n.skill)continue;const t=g(n.tool)?.displayName??n.tool,s=[m.t(`addons.mcp_${n.mcp}`),m.t(`addons.skill_${n.skill}`)],e="foreign"===n.mcp||"foreign"===n.skill||"modified"===n.skill||"skipped"===n.skill;console.log((e?o.yellow(" ! "):o.green(" √ "))+`${t}:${s.join(",")}`)}n&&console.log(o.yellow(" ! "+m.t("addons.skill_fetch_failed")))}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{spawnSync as e}from"child_process";import{createHash as t}from"crypto";import{existsSync as n,mkdirSync as r,readFileSync as s,readdirSync as o,rmSync as i,statSync as a}from"fs";import{join as l}from"path";import{brand as c,brandEnv as f,PROVIDER_KEY as d}from"./brand.js";import{configManager as u}from"./config.js";import{isOurGatewayUrl as p,noteWrittenGatewayUrl as m}from"./gateway-addresses.js";import{atomicWriteFile as g}from"./tools/backup.js";import{toolHome as y}from"./tools/types.js";import{logger as h}from"../utils/logger.js";export const MCP_NAME=d;const w="ai-models",k=".installed-by.json",b=[22,20];export function gatewayOrigin(e){return e.trim().replace(/\/+$/,"").replace(/\/v1$/,"")}export function mcpUrlOf(e){return`${gatewayOrigin(e)}/mcp`}export function isOurMcpUrl(e){return!("string"!=typeof e||!/\/mcp\/?$/.test(e))&&p(e.replace(/\/mcp\/?$/,""))}const $=e=>t("sha256").update(e).digest("hex");async function S(e){const t=await fetch(e,{signal:AbortSignal.timeout(3e4),headers:{"User-Agent":"addons"}});if(!t.ok)throw new Error(`GET ${e}: HTTP ${t.status}`);const n=await t.text();if(n.length>5242880)throw new Error(`GET ${e}: larger than 5242880 bytes`);return n}const E=e=>"string"==typeof e&&/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(e);export async function fetchSkillBundle(e){const t=`${gatewayOrigin(e)}/api/platform/.well-known/skills`,n=(JSON.parse(await S(`${t}/index.json`)).skills??[]).find(e=>"string"==typeof e.name&&(e.name===w||e.name.endsWith(`-${w}`)));if(!n||"string"!=typeof n.name||!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(n.name))throw new Error("gateway has no ai-models skill");const r=Array.isArray(n.files)?n.files.filter(E):[];if(!r.includes("SKILL.md"))throw new Error("ai-models skill has no SKILL.md");const s={};for(const e of r)s[e]=await S(`${t}/${n.name}/${e}`);return{name:n.name,digest:"string"==typeof n.digest?n.digest:$(JSON.stringify(s)),files:s}}function O(e){try{const t=JSON.parse(s(l(e,k),"utf-8"));return t&&"object"==typeof t.files?t:null}catch{return null}}function A(e,t){for(const[n,r]of Object.entries(t.files))try{if($(s(l(e,n),"utf-8"))!==r)return!1}catch{return!1}return!0}function M(e,t){const n={};for(const r of Object.keys(t.files))n[r]=$(s(l(e,r),"utf-8"));const r={installedBy:d,skill:t.name,digest:t.digest,files:n};g(l(e,k),JSON.stringify(r,null,2)+"\n")}function j(e,t){r(e,{recursive:!0});for(const[n,r]of Object.entries(t.files))g(l(e,n),r,n.endsWith(".mjs")?493:420);M(e,t)}export function skillCredentialsPath(e){const t=gatewayOrigin(e).replace(/^https?:\/\//,"").replace(/[^A-Za-z0-9.-]/g,"_");return l(y(),".config","ai-models",`${t}.json`)}function v(e,t){const r=l(e,t.name);if(!n(r))return j(r,t),"installed";const s=O(r);if(!s)return"foreign";if(!A(r,s))return"modified";if(s.digest===t.digest)return"unchanged";for(const e of Object.keys(s.files))e in t.files||i(l(r,e),{force:!0});return j(r,t),"updated"}function x(e,t){return Object.entries(t.files).every(([t,n])=>{try{return s(l(e,t),"utf-8")===n}catch{return!1}})}function _(t){if("1"===f("SKIP_SKILLS_CLI")||!function(e=process.versions.node){const[t,n]=e.split(".").map(Number);return t>b[0]||t===b[0]&&n>=b[1]}())return!1;const n="win32"===process.platform?"npx.cmd":"npx";for(const r of function(){const e=c().updateRegistries.filter(e=>"cnb"!==e.id);return e.sort((e,t)=>Number("npmmirror"===t.id)-Number("npmmirror"===e.id)),e.map(e=>e.url)}()){const s=e(n,["--yes",`--registry=${r}`,"skills@1.10.0",...t],{stdio:"pipe",timeout:18e4,shell:"win32"===process.platform,env:{...process.env,DISABLE_TELEMETRY:"1",DO_NOT_TRACK:"1",CI:"1",npm_config_registry:r}});if(0===s.status)return!0;h.logError(`addons.skillsCli(${r})`,new Error(`${s.error?.message??""} ${String(s.stderr??"").slice(-500)}`))}return!1}function C(e){if(!n(e))return"absent";let t="absent";for(const n of o(e)){if(n!==w&&!n.endsWith(`-${w}`))continue;const r=l(e,n);if(!a(r).isDirectory())continue;const s=O(r);s&&s.installedBy===d&&(A(r,s)?(i(r,{recursive:!0,force:!0}),"absent"===t&&(t="removed")):t="modified")}return t}export function addonsInstalled(e){const t=e.addons;if(!t)return!1;try{return isOurMcpUrl(t.readMcpUrl(MCP_NAME))||(r=t.skillsDir(),!!n(r)&&o(r).some(e=>(e===w||e.endsWith(`-${w}`))&&O(l(r,e))?.installedBy===d))}catch{return!1}var r}export async function installAddons(e,t){const o=e.filter(e=>e.addons);let i,a=t.bundle??null;if(!a&&o.length>0)try{a=await fetchSkillBundle(t.baseUrl)}catch(e){i=e instanceof Error?e.message:String(e),h.logError("addons.fetchSkillBundle",e)}const c=mcpUrlOf(t.baseUrl);if(m(gatewayOrigin(t.baseUrl)),a)try{!function(e,t){const o=skillCredentialsPath(e),i=JSON.stringify({base_url:gatewayOrigin(e),api_key:t},null,2)+"\n";n(o)&&s(o,"utf-8")===i||(r(l(o,".."),{recursive:!0}),g(o,i,384))}(t.baseUrl,t.apiKey)}catch(e){h.logError("addons.writeSkillCredentials",e)}const f=new Set,d=a?o.filter(e=>e.addons.skillsAgent&&!n(l(e.addons.skillsDir(),a.name))):[];if(a&&d.length>0){const e=[...new Set(d.map(e=>e.addons.skillsAgent))],n=`${gatewayOrigin(t.baseUrl)}/api/platform`,r="win32"===process.platform?["--copy"]:[];if(_(["add",n,"-s",a.name,"-g","-a",...e,"-y",...r]))for(const e of d){const t=l(e.addons.skillsDir(),a.name);if(x(t,a))try{M(t,a),f.add(e.name)}catch(t){h.logError(`addons.writeMarker(${e.name})`,t)}}}const u=new Map,p=[];for(const e of o){const n=e.addons;let r="absent";try{r=n.writeMcp({name:MCP_NAME,url:c,apiKey:t.apiKey})?"written":"foreign"}catch(t){h.logError(`addons.writeMcp(${e.name})`,t)}let s="skipped";if(a){const t=n.skillsDir();try{s=f.has(e.name)?"installed":u.get(t)??v(t,a),u.set(t,s)}catch(t){h.logError(`addons.installSkill(${e.name})`,t)}}p.push({tool:e.name,mcp:r,skill:s})}return{outcomes:p,skillError:i}}export function removeAddons(e,t={}){const r=[...new Set(e.map(e=>e.addons?.skillsAgent).filter(e=>!!e))],s=new Set;for(const t of e){const e=t.addons?.skillsDir();if(e&&n(e))for(const t of o(e))(t===w||t.endsWith(`-${w}`))&&O(l(e,t))?.installedBy===d&&A(l(e,t),O(l(e,t)))&&s.add(t)}const a=new Set;for(const e of s)r.length>0&&_(["remove",e,"-g","-a",...r,"-y"])&&a.add(e);t.dropCredentials&&t.baseUrl&&i(skillCredentialsPath(t.baseUrl),{force:!0});const c=new Map,f=[];for(const t of e.filter(e=>e.addons)){const e=t.addons;let n="absent";try{e.removeMcp(MCP_NAME)&&(n="removed")}catch(e){h.logError(`addons.removeMcp(${t.name})`,e)}let r="absent";try{const t=e.skillsDir();r=c.get(t)??C(t),"absent"===r&&e.skillsAgent&&a.size>0&&(r="removed"),c.set(t,r)}catch(e){h.logError(`addons.removeSkills(${t.name})`,e)}f.push({tool:t.name,mcp:n,skill:r})}return f}const D="addons-declined.json";export function addonsDeclined(){return n(l(u.getConfigDir(),D))}export function noteAddonsDeclined(){g(l(u.getConfigDir(),D),JSON.stringify({declined_at:(new Date).toISOString()})+"\n")}export function clearAddonsDeclined(){i(l(u.getConfigDir(),D),{force:!0})}
|
package/dist/lib/post-apply.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"chalk";import t from"inquirer";import{i18n as e}from"./i18n.js";import{canPrompt as n,hasExplicitYes as
|
|
1
|
+
import o from"chalk";import t from"inquirer";import{i18n as e}from"./i18n.js";import{canPrompt as n,hasExplicitYes as r}from"./runtime-options.js";import{flushTelemetry as l,track as i}from"./telemetry.js";import{toolManager as a}from"./tool-manager.js";import{getAdapter as s}from"./tools/registry.js";import{upgradeTool as p}from"./tool-upgrade.js";import{appsForTools as f,upgradeApp as c}from"./app-update.js";import{offerLatestUpgrades as u}from"./latest-upgrade.js";import{logger as d}from"../utils/logger.js";import{offerAddons as m}from"./addons-offer.js";async function g(o){const{ok:e}=await t.prompt([{type:"confirm",name:"ok",message:o,default:!0}]);return e}export async function runPendingElevations(t){const a=n(),p=r(),f=[];for(const n of t){const t=s(n)?.pendingElevation?.();if(!t)continue;const r=s(n)?.displayName??n;if(!p&&!a){console.log(o.yellow(" ! "+(t.skippedHint??e.t("setup.elevation_skipped",{tool:r})))),i("elevate-registry","skip",{detail:{tool:n,reason:"no_terminal"}}),f.push(n);continue}if(!p&&!await g(t.prompt)){i("elevate-registry","cancel",{detail:{tool:n,reason:"declined"}}),t.failedHint&&console.log(o.yellow(" ! "+t.failedHint)),f.push(n);continue}console.log(o.gray(" "+e.t("setup.elevation_running")));const c=Date.now();i("elevate-registry","start",{detail:{tool:n,asked:!p}}),await l();const u=t.run();i("elevate-registry",u?"ok":"fail",{duration_ms:Date.now()-c,detail:{tool:n,asked:!p}}),console.log(u?o.green(" √ "+e.t("setup.elevation_done",{tool:r})):o.yellow(" ! "+(t.failedHint??e.t("setup.elevation_failed",{tool:r})))),u||f.push(n)}return f}export async function runFollowUps(t){const e=n();for(const n of t){let t,l;try{t=await(s(n)?.followUp?.())}catch(o){d.logError(`postApplyPrompts.followUp(${n})`,o);continue}if(t)if("run"in t&&(r()||e))if(r()||await g(t.prompt)){try{l=await t.run()}catch(e){d.logError(`postApplyPrompts.followUp.run(${n})`,e),i(`follow-up:${n}`,"fail",{error:e}),console.log(o.yellow(" ! "+t.hint));continue}for(const t of l)console.log("action"===t.kind?o.yellow(" ! "+t.text):o.green(" √ "+t.text))}else t.decline();else console.log(o.yellow(" ! "+t.hint))}}export async function postApplyPrompts(t,l={}){const i=new Set;for(const o of l.apps?f(t):[])try{const t=await c(o,{install:l.apps.install,quiet:!0,askBeforeUpgrade:!0});t.upgraded&&t.running&&i.add(o)}catch(t){d.logError(`postApplyPrompts.upgradeApp(${o})`,t)}for(const e of t){const t=await(s(e)?.prepareRuntime?.())??[];for(const e of t)console.log("action"===e.kind?o.yellow(" ! "+e.text):o.green(" √ "+e.text))}await runPendingElevations(t),await runFollowUps(t);try{await m(t,l.addons)}catch(o){d.logError("postApplyPrompts.offerAddons",o)}const y=n(),w=r(),h=y||w?t.filter(o=>s(o)?.installSpec&&a.outdatedVersion(o)):[];if(h.length>0){const o=h.map(o=>s(o)?.displayName??o).join("、");if(w||await g(e.t("setup.offer_upgrade",{tools:o})))for(const o of h)await p(o)}await u(t.filter(o=>s(o)?.installSpec),new Set(h));for(const n of t){const t=s(n);if(i.has(n)||!t?.runningApp?.isRunning())continue;if(w||!y){console.log(o.yellow(" ! "+e.t("setup.reopen_hint",{tool:t.displayName})));continue}if(!await g(e.t("setup.offer_restart",{tool:t.displayName})))continue;const r=t.runningApp.restart();console.log(r?o.green(" √ "+e.t("setup.restarted",{tool:t.displayName})):o.yellow(" ! "+e.t("setup.restart_failed",{tool:t.displayName})))}}
|
package/dist/lib/program.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Command as e,Option as o}from"commander";import{readFileSync as s}from"fs";import{join as t,dirname as n}from"path";import{fileURLToPath as a}from"url";import{i18n as i}from"./i18n.js";import{wizard as r}from"./wizard.js";import{SUPPORTED_TOOLS as c}from"./tool-manager.js";import{DEFAULT_BASE_URL as l}from"./config.js";import{attachCommandHelp as p,helpConfiguration as m}from"./cli-help.js";import{langCommand as u,authCommand as d,doctorCommand as f,configCommand as g,statusCommand as x,refreshCommand as h}from"../commands/index.js";import{logsCommand as y}from"../commands/logs.js";import{completionCommand as $}from"../commands/completion.js";import{benchCommand as b}from"../commands/bench.js";import{updateCommand as k}from"../commands/update.js";import{upgradeCommand as w}from"../commands/upgrade.js";import{installCommand as _,listCommand as v}from"../commands/components.js";import{codexSessionsCommand as j}from"../commands/codex-sessions.js";import{sessionsExportCommand as O,sessionsListCommand as S,sessionsResumeCommand as A,sessionsShowCommand as E}from"../commands/sessions.js";import{setupCommand as G,parseUpgradeList as z,DEDICATED_KEYS as C}from"../commands/setup.js";import{baseCommand as R}from"../commands/base.js";import{usageError as U}from"./errors.js";import{requireTerminal as B}from"./confirm.js";import{brand as I,brandEnv as L,CLI_NAME as N}from"./brand.js";import{asksBeforeWriting as P}from"./write-plan.js";const T=(I().gatewayAddresses[1]??I().gatewayAddresses[0]).url,H=(I().gatewayAddresses[2]??I().gatewayAddresses[0]).url;function K(e,o){return i.t(`help.${e}`,o)}function M(e,o){return{command:e,note:K(o)}}function q(e){const o=K(e);return o===`help.${e}`?"":o}function D(e,o=[]){return{when:q(`${e}.when`),prerequisites:q(`${e}.needs`).split("\n").filter(Boolean),alternatives:o.map(([e,o])=>M(e,o))}}function F(e){return e.helpCommand("help [command]",K("help_command"))}export function buildProgram(){const I=new e;I.name(`${N}`).summary(K("root.summary")).description(K("root.description")).configureHelp(m()).allowExcessArguments(!0).optionsGroup(K("group.global_options")).helpOption("-h, --help",K("global.help")).version(function(){try{const e=n(a(import.meta.url));return JSON.parse(s(t(e,"../../package.json"),"utf-8")).version}catch{return"1.0.0"}}(),"-v, --version",K("global.version")).option("--base <url>",K("global.base")).option("--non-interactive",K("global.non_interactive")).option("--json",K("global.json")).option("-y, --yes",K("global.yes")).option("--dry-run",K("global.dry_run")).option("--no-color",K("global.no_color")),I.configureOutput({writeErr:()=>{},outputError:()=>{}}),I.showSuggestionAfterError(),I.exitOverride(e=>{throw e}),I.commandsGroup(K("group.configure"));const q=I.command("setup").summary(K("setup.summary")).description(K("setup.description")).option("--key <key>",K("setup.opt.key"));for(const e of C){const s=new o(`--${e.option} <key>`,K(`setup.opt.${e.option}`));e.hidden&&s.hideHelp(),q.addOption(s)}q.option("--1m",K("setup.opt.one_m")).option("--no-1m",K("setup.opt.no_one_m")).option("--claude-official <on|off>",K("setup.opt.claude_official")).option("--desktop-registry <on|off>",K("setup.opt.desktop_registry")).option("--force",K("setup.opt.force")).option("--install",K("setup.opt.install")).option("--no-install",K("setup.opt.no_install")).option("--ccswitch",K("setup.opt.ccswitch")).option("--ccswitch-use",K("setup.opt.ccswitch_use")).option("--upgrade <ids>",K("setup.opt.upgrade"),(e,o=[])=>[...o,e]).option("--all",K("setup.opt.all")).action(async e=>{e.key||C.some(o=>e[o.option])||(e.key=L("SETUP_KEY")?.trim()||void 0,e.fromInstaller=Boolean(e.key));const o=Boolean(e.key||C.some(o=>e[o.option])),s=void 0!==e["1m"]||void 0!==e.claudeOfficial||void 0!==e.desktopRegistry,t=i.t("errors.key_placeholder"),n=void 0===e.upgrade?void 0:z(e.upgrade);if(!(o||s||n?.length||P()))throw U(i.t("setup.usage"),`${N} setup --key ${t}`,"missing_key");if(void 0!==e.claudeOfficial&&!["on","off"].includes(String(e.claudeOfficial).toLowerCase()))throw U(i.t("setup.claude_official_invalid",{value:String(e.claudeOfficial)}),`${N} setup --claude-official on|off`,"invalid_value");if(void 0!==e.desktopRegistry&&!["on","off"].includes(String(e.desktopRegistry).toLowerCase()))throw U(i.t("setup.desktop_registry_invalid",{value:String(e.desktopRegistry)}),`${N} setup --desktop-registry on|off`,"invalid_value");await G({key:e.key,...Object.fromEntries(C.map(o=>[o.option,e[o.option]])),all:e.all,oneMillion:e["1m"],claudeOfficial:e.claudeOfficial,desktopRegistry:e.desktopRegistry,force:e.force,install:e.install,upgrade:n,fromInstaller:e.fromInstaller,ccswitch:e.ccswitch,ccswitchUse:e.ccswitchUse})}),p(q,{...D("setup",[[`${N} init`,"setup.alt.init"],[`${N} config <tool>`,"setup.alt.config"],[`${N} auth <key>`,"setup.alt.auth"]]),sections:[{title:K("setup.autodetect_title"),rows:[["Claude",K("setup.autodetect.claude")],["GPT",K("setup.autodetect.gpt")],["Grok",K("setup.autodetect.grok")],["Gemini",K("setup.autodetect.gemini")],[K("setup.autodetect.any_label"),K("setup.autodetect.any")]]}],examples:[M(`${N} setup --key sk-xxx`,"setup.ex.key"),M(`${N} setup --install --key sk-xxx`,"setup.ex.install"),M(`${N} setup --claudekey sk-a --codexkey sk-b --agykey sk-g`,"setup.ex.split"),M(`${N} setup --claudekey sk-xxx --no-install --upgrade claude-code,grok`,"setup.ex.upgrade"),M(`${N} setup --base ${T} --key sk-xxx`,"setup.ex.base")]});const J=I.command("init").summary(K("init.summary")).description(K("init.description")).action(async()=>{B(),await r.runFirstTimeSetup()});p(J,{...D("init",[[`${N} setup --key <key>`,"init.alt.setup"],[`${N}`,"init.alt.menu"]]),examples:[M(`${N} init`,"init.ex.run"),M(`${N} init --base ${T}`,"init.ex.base"),M(`${N}`,"init.ex.menu")]});const Y=I.command("auth").summary(K("auth.summary")).description(K("auth.description")).argument("[token]",K("auth.arg.token")).action(async e=>{const o=[];e&&o.push(e),await d(o)});F(Y);const Q=Y.command("revoke").description(K("auth.revoke")).action(async()=>{await d(["revoke"])});p(Q,{examples:[M(`${N} auth revoke`,"auth.ex.revoke_ask"),M(`${N} auth revoke --yes`,"auth.ex.revoke")]});const V=Y.command("reload <tool>").description(K("auth.reload")).action(async e=>{await d(["reload",e])});p(V,{examples:[M(`${N} auth reload claude-code`,"auth.ex.reload"),M(`${N} auth reload claude-code --json`,"auth.ex.reload_json")]}),p(Y,{...D("auth",[[`${N} setup --key <key>`,"auth.alt.setup"]]),examples:[M(`${N} auth`,"auth.ex.prompt"),M(`${N} auth sk-xxx --non-interactive`,"auth.ex.save"),M(`${N} auth revoke --yes`,"auth.ex.revoke"),M(`${N} auth reload claude-code`,"auth.ex.reload")]});const W=I.command("config").summary(K("config.summary")).description(K("config.description")).argument("[args...]",K("config.arg.args")).option("-f, --force",K("config.opt.force")).allowUnknownOption(!0).action(async(e=[],o={})=>{await g(o.force?[...e,"--force"]:e)});p(W,{...D("config",[[`${N} setup --force --key <key>`,"config.alt.setup"],[`${N} status`,"config.alt.status"]]),sections:[{title:K("config.subcommands_title"),rows:[["<tool>",K("config.sub.tool")],["<tool> --force",K("config.sub.tool_force")],["<tool> --non-interactive",K("config.sub.tool_non_interactive")],["<tool> remove",K("config.sub.tool_remove")],["<tool> restore",K("config.sub.tool_restore")],["<tool> backups",K("config.sub.tool_backups")],["<tool> clear-model",K("config.sub.tool_clear_model")],["tool-model list",K("config.sub.tool_model_list")],["tool-model set <tool> [slot] <model>",K("config.sub.tool_model_set")],["tool-model clear <tool>",K("config.sub.tool_model_clear")],["profile list",K("config.sub.profile_list")],["profile create <name>",K("config.sub.profile_create")],["profile use <name>",K("config.sub.profile_use")],["profile delete <name>",K("config.sub.profile_delete")],["preset list",K("config.sub.preset_list")],["preset save <name>",K("config.sub.preset_save")],["preset use <name>",K("config.sub.preset_use")],["preset delete <name>",K("config.sub.preset_delete")],["backup list",K("config.sub.backup_list")],["backup create [label]",K("config.sub.backup_create")],["backup restore <name>",K("config.sub.backup_restore")]]},{title:K("config.tools_title"),rows:Object.values(c).filter(e=>!e.hidden).map(e=>[e.name,e.displayName])}],examples:[M(`${N} config codex`,"config.ex.menu"),M(`${N} config claude-code --force`,"config.ex.force"),M(`${N} config tool-model set codex gpt-6-astra`,"config.ex.tool_model"),M(`${N} config profile create work`,"config.ex.profile"),M(`${N} config codex remove`,"config.ex.remove")]});const X=I.command("base").summary(K("base.summary")).description(K("base.description")).argument("[target]",K("base.arg.target")).action(async e=>{await R(e)});p(X,{...D("base",[[`${N} doctor`,"base.alt.doctor"],[`${N} bench`,"base.alt.bench"]]),sections:[{title:K("base.targets_title"),rows:[[K("base.target.none_term"),K("base.target.none")],[K("base.target.index_term"),K("base.target.index")],[K("base.target.url_term"),K("base.target.url")],["auto",K("base.target.auto")],["default",K("base.target.default",{url:l})]]}],examples:[M(`${N} base`,"base.ex.list"),M(`${N} base auto`,"base.ex.auto"),M(`${N} base 2`,"base.ex.index"),M(`${N} base ${T}`,"base.ex.url"),M(`${N} base default`,"base.ex.default")]}),I.commandsGroup(K("group.diagnose"));const Z=I.command("status").summary(K("status.summary")).description(K("status.description")).action(async()=>{await x()});p(Z,{...D("status",[[`${N} doctor`,"status.alt.doctor"]]),examples:[M(`${N} status`,"status.ex.show"),M(`${N} status --json`,"status.ex.json")]});const ee=I.command("doctor").summary(K("doctor.summary")).description(K("doctor.description")).option("--deep",K("doctor.opt.deep")).option("--report",K("doctor.opt.report")).action(async e=>{await f({deep:e.deep,report:e.report})});p(ee,{...D("doctor",[[`${N} base auto`,"doctor.alt.base"],[`${N} logs tail`,"doctor.alt.logs"]]),examples:[M(`${N} doctor`,"doctor.ex.run"),M(`${N} doctor --deep`,"doctor.ex.deep"),M(`${N} doctor --report`,"doctor.ex.report")]});const oe=I.command("bench").summary(K("bench.summary")).description(K("bench.description")).option("--samples <n>",K("bench.opt.samples"),"5").option("--stream",K("bench.opt.stream")).option("--model <model>",K("bench.opt.model")).action(async e=>{const o=[];e.samples&&o.push("--samples",e.samples),e.stream&&o.push("--stream"),e.model&&o.push("--model",e.model),await b(o)});p(oe,{...D("bench",[[`${N} base`,"bench.alt.base"]]),examples:[M(`${N} bench`,"bench.ex.run"),M(`${N} bench --samples 3`,"bench.ex.samples"),M(`${N} bench --stream`,"bench.ex.stream"),M(`${N} bench --stream --model gpt-6-astra`,"bench.ex.stream_model"),M(`${N} bench --json`,"bench.ex.json")]});const se=I.command("logs").summary(K("logs.summary")).description(K("logs.description")).argument("[action]",K("logs.arg.action")).argument("[file]",K("logs.arg.file")).action(async(e,o)=>{const s=[];e&&s.push(e),o&&s.push(o),await y(s)});p(se,{...D("logs",[[`${N} doctor`,"logs.alt.doctor"]]),sections:[{title:K("logs.actions_title"),rows:[["list",K("logs.action.list")],["tail [file]",K("logs.action.tail")],["path",K("logs.action.path")]]}],examples:[M(`${N} logs`,"logs.ex.list"),M(`${N} logs tail`,"logs.ex.tail"),M(`${N} logs path`,"logs.ex.path")]}),I.commandsGroup(K("group.maintain"));const te=I.command("list").summary(K("list.summary")).description(K("list.description")).option("--refresh",K("list.opt.refresh")).action(async(e={})=>{await v({refresh:e.refresh})});p(te,{...D("list",[[`${N} doctor`,"list.alt.doctor"]]),examples:[M(`${N} list`,"list.ex.all"),M(`${N} list --refresh`,"list.ex.refresh"),M(`${N} list --json`,"list.ex.json")]});const ne=I.command("install").summary(K("install.summary")).description(K("install.description")).argument("<components...>",K("install.arg.components")).option("--force",K("install.opt.force")).action(async(e,o={})=>{await _(e,{force:o.force})});p(ne,{...D("install",[[`${N} upgrade`,"install.alt.upgrade"],[`${N} setup --key ${i.t("errors.key_placeholder")}`,"install.alt.setup"]]),examples:[M(`${N} install node uv`,"install.ex.runtimes"),M(`${N} install claude-code codex`,"install.ex.clis"),M(`${N} install chatgpt`,"install.ex.app"),M(`${N} install uv --force`,"install.ex.force"),M(`${N} install node uv --yes --json`,"install.ex.json")]});const ae=I.command("upgrade").summary(K("upgrade.summary")).description(K("upgrade.description")).argument("[tools...]",K("upgrade.arg.tools")).option("--force",K("upgrade.opt.force")).action(async(e=[],o={})=>{await w(e,{force:o.force})});p(ae,{...D("upgrade",[[`${N} update`,"upgrade.alt.update"]]),examples:[M(`${N} upgrade`,"upgrade.ex.all"),M(`${N} upgrade codex agy`,"upgrade.ex.many"),M(`${N} upgrade claude-desktop`,"upgrade.ex.desktop"),M(`${N} upgrade chatgpt --force`,"upgrade.ex.force"),M(`${N} upgrade node`,"upgrade.ex.runtime")]});const ie=I.command("refresh").summary(K("refresh.summary")).description(K("refresh.description")).action(async()=>{await h()});p(ie,{...D("refresh",[[`${N} setup --key ${i.t("errors.key_placeholder")}`,"refresh.alt.setup"]]),examples:[M(`${N} refresh`,"refresh.ex.run"),M(`${N} refresh --base ${H}`,"refresh.ex.base")]});const re=I.command("update").summary(K("update.summary")).description(K("update.description")).action(async()=>{await k()});p(re,{...D("update",[[`${N} upgrade`,"update.alt.upgrade"]]),examples:[M(`${N} update`,"update.ex.check"),M(`${N} update --json`,"update.ex.json")]});const ce=I.command("codex").summary(K("codex.summary")).description(K("codex.description"));F(ce);const le=ce.command("sessions").summary(K("codex_sessions.summary")).description(K("codex_sessions.description")).option("--to <provider>",K("codex_sessions.opt.to")).option("--undo <dir>",K("codex_sessions.opt.undo")).action(async e=>{await j(e)});p(ce,{...D("codex"),examples:[M(`${N} codex sessions`,"codex_sessions.ex.move"),M(`${N} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]}),p(le,{...D("codex_sessions",[[`${N} codex sessions --undo <dir>`,"codex_sessions.alt.undo"]]),examples:[M(`${N} codex sessions`,"codex_sessions.ex.move"),M(`${N} codex sessions --to custom`,"codex_sessions.ex.to"),M(`${N} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]});const pe=I.command("sessions").summary(K("sessions.summary")).description(K("sessions.description"));F(pe);const me=pe.command("list",{isDefault:!0}).description(K("sessions.list")).option("--tool <tool>",K("sessions.opt.tool")).option("--dir <path>",K("sessions.opt.dir")).option("--here",K("sessions.opt.here")).option("-n, --limit <count>",K("sessions.opt.limit")).option("--all",K("sessions.opt.all")).action(async e=>{await S(e)}),ue=pe.command("show <id>").description(K("sessions.show")).option("-m, --messages <count>",K("sessions.opt.messages")).action(async(e,o)=>{await E(e,o)}),de=pe.command("resume <id>").description(K("sessions.resume")).option("--run",K("sessions.opt.run")).action(async(e,o)=>{await A(e,o)}),fe=pe.command("export <ids...>").description(K("sessions.export")).option("-o, --output <dir>",K("sessions.opt.output")).option("--tools",K("sessions.opt.tools")).action(async(e,o)=>{await O(e,o)});p(me,{examples:[M(`${N} sessions list`,"sessions.ex.list"),M(`${N} sessions list --tool codex`,"sessions.ex.codex"),M(`${N} sessions list --here --all`,"sessions.ex.here"),M(`${N} sessions list --json`,"sessions.ex.json")]}),p(ue,{examples:[M(`${N} sessions show 01a0f5fe`,"sessions.ex.show"),M(`${N} sessions show 01a0f5fe -m 20`,"sessions.ex.show_more")]}),p(de,{examples:[M(`${N} sessions resume 01a0f5fe`,"sessions.ex.resume_print"),M(`${N} sessions resume 01a0f5fe --run`,"sessions.ex.resume")]}),p(fe,{examples:[M(`${N} sessions export 01a0f5fe 7c2e9d41 -o ./sessions`,"sessions.ex.export"),M(`${N} sessions export 01a0f5fe -o ./sessions --tools`,"sessions.ex.export_tools")]}),p(pe,{...D("sessions",[[`${N} codex sessions`,"sessions.alt.codex_sessions"]]),examples:[M(`${N} sessions`,"sessions.ex.list"),M(`${N} sessions --tool codex --here`,"sessions.ex.here"),M(`${N} sessions show 01a0f5fe`,"sessions.ex.show"),M(`${N} sessions resume 01a0f5fe --run`,"sessions.ex.resume"),M(`${N} sessions export 01a0f5fe 7c2e9d41 -o ./sessions`,"sessions.ex.export")]});const ge=I.command("lang").summary(K("lang.summary")).description(K("lang.description"));F(ge);const xe=ge.command("show").description(K("lang.show")).action(async()=>{await u(["show"])}),he=ge.command("set <locale>").description(K("lang.set")).action(async e=>{await u(["set",e])}),ye=[M(`${N} lang show`,"lang.ex.show"),M(`${N} lang set en_US`,"lang.ex.set_en"),M(`${N} lang set zh_CN`,"lang.ex.set_zh")];p(ge,{...D("lang",[[`${N} enter lang`,"lang.alt.enter"]]),examples:ye}),p(xe,{examples:[ye[0],M(`${N} lang show --json`,"lang.ex.show_json")]}),p(he,{examples:ye.slice(1)});const $e=I.command("completion").summary(K("completion.summary")).description(K("completion.description")).argument("<shell>",K("completion.arg.shell")).action(async e=>{await $([e])});p($e,{...D("completion"),examples:[M(`${N} completion bash > ~/.${N}-completion.bash`,"completion.ex.bash"),M(`${N} completion zsh > ~/.${N}-completion.zsh`,"completion.ex.zsh"),M(`${N} completion fish > ~/.config/fish/completions/${N}.fish`,"completion.ex.fish")]});const be=I.command("enter").summary(K("enter.summary")).description(K("enter.description")).argument("[option]",K("enter.arg.option")).action(async e=>{if(e&&!["lang","language","apikey","api-key","models"].includes(e)||B(),e)switch(e){case"lang":case"language":await r.configLanguage();break;case"apikey":case"api-key":await r.configApiKey();break;case"models":await r.configModels();break;default:await g([e])}else await r.run()});p(be,{...D("enter",[[`${N}`,"enter.alt.menu"],[`${N} config <tool>`,"enter.alt.config"]]),sections:[{title:K("enter.options_title"),rows:[[K("enter.option.none_term"),K("enter.option.none")],["lang",K("enter.option.lang")],["apikey",K("enter.option.apikey")],["models",K("enter.option.models")],["<tool>",K("enter.option.tool")]]}],examples:[M(`${N} enter`,"enter.ex.menu"),M(`${N} enter models`,"enter.ex.models"),M(`${N} enter codex`,"enter.ex.tool")]}),F(I),I.action(async()=>{B(),await r.run()}),p(I,{examples:[M(`${N}`,"root.ex.menu"),M(`${N} setup --key sk-xxx`,"root.ex.setup"),M(`${N} doctor`,"root.ex.doctor"),M(`${N} base auto`,"root.ex.base"),M(`${N} config codex`,"root.ex.config")]});const ke=e=>{for(const o of e.commands)o.helpOption("-h, --help",K("global.help")),ke(o)};return ke(I),I}
|
|
1
|
+
import{Command as e,Option as o}from"commander";import{readFileSync as s}from"fs";import{join as t,dirname as a}from"path";import{fileURLToPath as n}from"url";import{i18n as i}from"./i18n.js";import{wizard as r}from"./wizard.js";import{SUPPORTED_TOOLS as c}from"./tool-manager.js";import{DEFAULT_BASE_URL as l}from"./config.js";import{attachCommandHelp as p,helpConfiguration as d}from"./cli-help.js";import{langCommand as m,authCommand as u,doctorCommand as g,configCommand as f,statusCommand as x,refreshCommand as h}from"../commands/index.js";import{logsCommand as y}from"../commands/logs.js";import{completionCommand as $}from"../commands/completion.js";import{benchCommand as b}from"../commands/bench.js";import{updateCommand as k}from"../commands/update.js";import{upgradeCommand as _}from"../commands/upgrade.js";import{installCommand as w,listCommand as v}from"../commands/components.js";import{codexSessionsCommand as j}from"../commands/codex-sessions.js";import{addonsCommand as O}from"../commands/addons.js";import{sessionsExportCommand as S,sessionsListCommand as A,sessionsResumeCommand as E,sessionsShowCommand as G}from"../commands/sessions.js";import{setupCommand as z,parseUpgradeList as C,DEDICATED_KEYS as R}from"../commands/setup.js";import{baseCommand as U}from"../commands/base.js";import{usageError as B}from"./errors.js";import{requireTerminal as I}from"./confirm.js";import{brand as L,brandEnv as N,CLI_NAME as P}from"./brand.js";import{asksBeforeWriting as T}from"./write-plan.js";const H=(L().gatewayAddresses[1]??L().gatewayAddresses[0]).url,K=(L().gatewayAddresses[2]??L().gatewayAddresses[0]).url;function M(e,o){return i.t(`help.${e}`,o)}function q(e,o){return{command:e,note:M(o)}}function D(e){const o=M(e);return o===`help.${e}`?"":o}function F(e,o=[]){return{when:D(`${e}.when`),prerequisites:D(`${e}.needs`).split("\n").filter(Boolean),alternatives:o.map(([e,o])=>q(e,o))}}function J(e){return e.helpCommand("help [command]",M("help_command"))}export function buildProgram(){const L=new e;L.name(`${P}`).summary(M("root.summary")).description(M("root.description")).configureHelp(d()).allowExcessArguments(!0).optionsGroup(M("group.global_options")).helpOption("-h, --help",M("global.help")).version(function(){try{const e=a(n(import.meta.url));return JSON.parse(s(t(e,"../../package.json"),"utf-8")).version}catch{return"1.0.0"}}(),"-v, --version",M("global.version")).option("--base <url>",M("global.base")).option("--non-interactive",M("global.non_interactive")).option("--json",M("global.json")).option("-y, --yes",M("global.yes")).option("--dry-run",M("global.dry_run")).option("--no-color",M("global.no_color")),L.configureOutput({writeErr:()=>{},outputError:()=>{}}),L.showSuggestionAfterError(),L.exitOverride(e=>{throw e}),L.commandsGroup(M("group.configure"));const D=L.command("setup").summary(M("setup.summary")).description(M("setup.description")).option("--key <key>",M("setup.opt.key"));for(const e of R){const s=new o(`--${e.option} <key>`,M(`setup.opt.${e.option}`));e.hidden&&s.hideHelp(),D.addOption(s)}D.option("--1m",M("setup.opt.one_m")).option("--no-1m",M("setup.opt.no_one_m")).option("--claude-official <on|off>",M("setup.opt.claude_official")).option("--desktop-registry <on|off>",M("setup.opt.desktop_registry")).option("--force",M("setup.opt.force")).option("--install",M("setup.opt.install")).option("--no-install",M("setup.opt.no_install")).option("--addons",M("setup.opt.addons")).option("--no-addons",M("setup.opt.no_addons")).option("--ccswitch",M("setup.opt.ccswitch")).option("--ccswitch-use",M("setup.opt.ccswitch_use")).option("--upgrade <ids>",M("setup.opt.upgrade"),(e,o=[])=>[...o,e]).option("--all",M("setup.opt.all")).action(async e=>{e.key||R.some(o=>e[o.option])||(e.key=N("SETUP_KEY")?.trim()||void 0,e.fromInstaller=Boolean(e.key));const o=Boolean(e.key||R.some(o=>e[o.option])),s=void 0!==e["1m"]||void 0!==e.claudeOfficial||void 0!==e.desktopRegistry,t=i.t("errors.key_placeholder"),a=void 0===e.upgrade?void 0:C(e.upgrade);if(!(o||s||a?.length||T()))throw B(i.t("setup.usage"),`${P} setup --key ${t}`,"missing_key");if(void 0!==e.claudeOfficial&&!["on","off"].includes(String(e.claudeOfficial).toLowerCase()))throw B(i.t("setup.claude_official_invalid",{value:String(e.claudeOfficial)}),`${P} setup --claude-official on|off`,"invalid_value");if(void 0!==e.desktopRegistry&&!["on","off"].includes(String(e.desktopRegistry).toLowerCase()))throw B(i.t("setup.desktop_registry_invalid",{value:String(e.desktopRegistry)}),`${P} setup --desktop-registry on|off`,"invalid_value");await z({key:e.key,addons:e.addons,...Object.fromEntries(R.map(o=>[o.option,e[o.option]])),all:e.all,oneMillion:e["1m"],claudeOfficial:e.claudeOfficial,desktopRegistry:e.desktopRegistry,force:e.force,install:e.install,upgrade:a,fromInstaller:e.fromInstaller,ccswitch:e.ccswitch,ccswitchUse:e.ccswitchUse})}),p(D,{...F("setup",[[`${P} init`,"setup.alt.init"],[`${P} config <tool>`,"setup.alt.config"],[`${P} auth <key>`,"setup.alt.auth"]]),sections:[{title:M("setup.autodetect_title"),rows:[["Claude",M("setup.autodetect.claude")],["GPT",M("setup.autodetect.gpt")],["Grok",M("setup.autodetect.grok")],["Gemini",M("setup.autodetect.gemini")],[M("setup.autodetect.any_label"),M("setup.autodetect.any")]]}],examples:[q(`${P} setup --key sk-xxx`,"setup.ex.key"),q(`${P} setup --install --key sk-xxx`,"setup.ex.install"),q(`${P} setup --claudekey sk-a --codexkey sk-b --agykey sk-g`,"setup.ex.split"),q(`${P} setup --claudekey sk-xxx --no-install --upgrade claude-code,grok`,"setup.ex.upgrade"),q(`${P} setup --base ${H} --key sk-xxx`,"setup.ex.base")]});const Y=L.command("init").summary(M("init.summary")).description(M("init.description")).action(async()=>{I(),await r.runFirstTimeSetup()});p(Y,{...F("init",[[`${P} setup --key <key>`,"init.alt.setup"],[`${P}`,"init.alt.menu"]]),examples:[q(`${P} init`,"init.ex.run"),q(`${P} init --base ${H}`,"init.ex.base"),q(`${P}`,"init.ex.menu")]});const Q=L.command("auth").summary(M("auth.summary")).description(M("auth.description")).argument("[token]",M("auth.arg.token")).action(async e=>{const o=[];e&&o.push(e),await u(o)});J(Q);const V=Q.command("revoke").description(M("auth.revoke")).action(async()=>{await u(["revoke"])});p(V,{examples:[q(`${P} auth revoke`,"auth.ex.revoke_ask"),q(`${P} auth revoke --yes`,"auth.ex.revoke")]});const W=Q.command("reload <tool>").description(M("auth.reload")).action(async e=>{await u(["reload",e])});p(W,{examples:[q(`${P} auth reload claude-code`,"auth.ex.reload"),q(`${P} auth reload claude-code --json`,"auth.ex.reload_json")]}),p(Q,{...F("auth",[[`${P} setup --key <key>`,"auth.alt.setup"]]),examples:[q(`${P} auth`,"auth.ex.prompt"),q(`${P} auth sk-xxx --non-interactive`,"auth.ex.save"),q(`${P} auth revoke --yes`,"auth.ex.revoke"),q(`${P} auth reload claude-code`,"auth.ex.reload")]});const X=L.command("config").summary(M("config.summary")).description(M("config.description")).argument("[args...]",M("config.arg.args")).option("-f, --force",M("config.opt.force")).allowUnknownOption(!0).action(async(e=[],o={})=>{await f(o.force?[...e,"--force"]:e)});p(X,{...F("config",[[`${P} setup --force --key <key>`,"config.alt.setup"],[`${P} status`,"config.alt.status"]]),sections:[{title:M("config.subcommands_title"),rows:[["<tool>",M("config.sub.tool")],["<tool> --force",M("config.sub.tool_force")],["<tool> --non-interactive",M("config.sub.tool_non_interactive")],["<tool> remove",M("config.sub.tool_remove")],["<tool> restore",M("config.sub.tool_restore")],["<tool> backups",M("config.sub.tool_backups")],["<tool> clear-model",M("config.sub.tool_clear_model")],["tool-model list",M("config.sub.tool_model_list")],["tool-model set <tool> [slot] <model>",M("config.sub.tool_model_set")],["tool-model clear <tool>",M("config.sub.tool_model_clear")],["profile list",M("config.sub.profile_list")],["profile create <name>",M("config.sub.profile_create")],["profile use <name>",M("config.sub.profile_use")],["profile delete <name>",M("config.sub.profile_delete")],["preset list",M("config.sub.preset_list")],["preset save <name>",M("config.sub.preset_save")],["preset use <name>",M("config.sub.preset_use")],["preset delete <name>",M("config.sub.preset_delete")],["backup list",M("config.sub.backup_list")],["backup create [label]",M("config.sub.backup_create")],["backup restore <name>",M("config.sub.backup_restore")]]},{title:M("config.tools_title"),rows:Object.values(c).filter(e=>!e.hidden).map(e=>[e.name,e.displayName])}],examples:[q(`${P} config codex`,"config.ex.menu"),q(`${P} config claude-code --force`,"config.ex.force"),q(`${P} config tool-model set codex gpt-6-astra`,"config.ex.tool_model"),q(`${P} config profile create work`,"config.ex.profile"),q(`${P} config codex remove`,"config.ex.remove")]});const Z=L.command("base").summary(M("base.summary")).description(M("base.description")).argument("[target]",M("base.arg.target")).action(async e=>{await U(e)});p(Z,{...F("base",[[`${P} doctor`,"base.alt.doctor"],[`${P} bench`,"base.alt.bench"]]),sections:[{title:M("base.targets_title"),rows:[[M("base.target.none_term"),M("base.target.none")],[M("base.target.index_term"),M("base.target.index")],[M("base.target.url_term"),M("base.target.url")],["auto",M("base.target.auto")],["default",M("base.target.default",{url:l})]]}],examples:[q(`${P} base`,"base.ex.list"),q(`${P} base auto`,"base.ex.auto"),q(`${P} base 2`,"base.ex.index"),q(`${P} base ${H}`,"base.ex.url"),q(`${P} base default`,"base.ex.default")]}),L.commandsGroup(M("group.diagnose"));const ee=L.command("status").summary(M("status.summary")).description(M("status.description")).action(async()=>{await x()});p(ee,{...F("status",[[`${P} doctor`,"status.alt.doctor"]]),examples:[q(`${P} status`,"status.ex.show"),q(`${P} status --json`,"status.ex.json")]});const oe=L.command("doctor").summary(M("doctor.summary")).description(M("doctor.description")).option("--deep",M("doctor.opt.deep")).option("--report",M("doctor.opt.report")).action(async e=>{await g({deep:e.deep,report:e.report})});p(oe,{...F("doctor",[[`${P} base auto`,"doctor.alt.base"],[`${P} logs tail`,"doctor.alt.logs"]]),examples:[q(`${P} doctor`,"doctor.ex.run"),q(`${P} doctor --deep`,"doctor.ex.deep"),q(`${P} doctor --report`,"doctor.ex.report")]});const se=L.command("bench").summary(M("bench.summary")).description(M("bench.description")).option("--samples <n>",M("bench.opt.samples"),"5").option("--stream",M("bench.opt.stream")).option("--model <model>",M("bench.opt.model")).action(async e=>{const o=[];e.samples&&o.push("--samples",e.samples),e.stream&&o.push("--stream"),e.model&&o.push("--model",e.model),await b(o)});p(se,{...F("bench",[[`${P} base`,"bench.alt.base"]]),examples:[q(`${P} bench`,"bench.ex.run"),q(`${P} bench --samples 3`,"bench.ex.samples"),q(`${P} bench --stream`,"bench.ex.stream"),q(`${P} bench --stream --model gpt-6-astra`,"bench.ex.stream_model"),q(`${P} bench --json`,"bench.ex.json")]});const te=L.command("logs").summary(M("logs.summary")).description(M("logs.description")).argument("[action]",M("logs.arg.action")).argument("[file]",M("logs.arg.file")).action(async(e,o)=>{const s=[];e&&s.push(e),o&&s.push(o),await y(s)});p(te,{...F("logs",[[`${P} doctor`,"logs.alt.doctor"]]),sections:[{title:M("logs.actions_title"),rows:[["list",M("logs.action.list")],["tail [file]",M("logs.action.tail")],["path",M("logs.action.path")]]}],examples:[q(`${P} logs`,"logs.ex.list"),q(`${P} logs tail`,"logs.ex.tail"),q(`${P} logs path`,"logs.ex.path")]}),L.commandsGroup(M("group.maintain"));const ae=L.command("list").summary(M("list.summary")).description(M("list.description")).option("--refresh",M("list.opt.refresh")).action(async(e={})=>{await v({refresh:e.refresh})});p(ae,{...F("list",[[`${P} doctor`,"list.alt.doctor"]]),examples:[q(`${P} list`,"list.ex.all"),q(`${P} list --refresh`,"list.ex.refresh"),q(`${P} list --json`,"list.ex.json")]});const ne=L.command("install").summary(M("install.summary")).description(M("install.description")).argument("<components...>",M("install.arg.components")).option("--force",M("install.opt.force")).action(async(e,o={})=>{await w(e,{force:o.force})});p(ne,{...F("install",[[`${P} upgrade`,"install.alt.upgrade"],[`${P} setup --key ${i.t("errors.key_placeholder")}`,"install.alt.setup"]]),examples:[q(`${P} install node uv`,"install.ex.runtimes"),q(`${P} install claude-code codex`,"install.ex.clis"),q(`${P} install chatgpt`,"install.ex.app"),q(`${P} install uv --force`,"install.ex.force"),q(`${P} install node uv --yes --json`,"install.ex.json")]});const ie=L.command("upgrade").summary(M("upgrade.summary")).description(M("upgrade.description")).argument("[tools...]",M("upgrade.arg.tools")).option("--force",M("upgrade.opt.force")).action(async(e=[],o={})=>{await _(e,{force:o.force})});p(ie,{...F("upgrade",[[`${P} update`,"upgrade.alt.update"]]),examples:[q(`${P} upgrade`,"upgrade.ex.all"),q(`${P} upgrade codex agy`,"upgrade.ex.many"),q(`${P} upgrade claude-desktop`,"upgrade.ex.desktop"),q(`${P} upgrade chatgpt --force`,"upgrade.ex.force"),q(`${P} upgrade node`,"upgrade.ex.runtime")]});const re=L.command("addons").summary(M("addons.summary")).description(M("addons.description")).argument("[action]",M("addons.arg.action"),"install").argument("[tools...]",M("addons.arg.tools")).option("--key <key>",M("addons.opt.key")).action(async(e,o=[],s={})=>{await O(e,o,{key:s.key})});p(re,{...F("addons",[[`${P} setup --key ${i.t("errors.key_placeholder")}`,"addons.alt.setup"]]),examples:[q(`${P} addons install`,"addons.ex.install"),q(`${P} addons install claude-code codex`,"addons.ex.some"),q(`${P} addons status`,"addons.ex.status"),q(`${P} addons remove`,"addons.ex.remove")]});const ce=L.command("refresh").summary(M("refresh.summary")).description(M("refresh.description")).action(async()=>{await h()});p(ce,{...F("refresh",[[`${P} setup --key ${i.t("errors.key_placeholder")}`,"refresh.alt.setup"]]),examples:[q(`${P} refresh`,"refresh.ex.run"),q(`${P} refresh --base ${K}`,"refresh.ex.base")]});const le=L.command("update").summary(M("update.summary")).description(M("update.description")).action(async()=>{await k()});p(le,{...F("update",[[`${P} upgrade`,"update.alt.upgrade"]]),examples:[q(`${P} update`,"update.ex.check"),q(`${P} update --json`,"update.ex.json")]});const pe=L.command("codex").summary(M("codex.summary")).description(M("codex.description"));J(pe);const de=pe.command("sessions").summary(M("codex_sessions.summary")).description(M("codex_sessions.description")).option("--to <provider>",M("codex_sessions.opt.to")).option("--undo <dir>",M("codex_sessions.opt.undo")).action(async e=>{await j(e)});p(pe,{...F("codex"),examples:[q(`${P} codex sessions`,"codex_sessions.ex.move"),q(`${P} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]}),p(de,{...F("codex_sessions",[[`${P} codex sessions --undo <dir>`,"codex_sessions.alt.undo"]]),examples:[q(`${P} codex sessions`,"codex_sessions.ex.move"),q(`${P} codex sessions --to custom`,"codex_sessions.ex.to"),q(`${P} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]});const me=L.command("sessions").summary(M("sessions.summary")).description(M("sessions.description"));J(me);const ue=me.command("list",{isDefault:!0}).description(M("sessions.list")).option("--tool <tool>",M("sessions.opt.tool")).option("--dir <path>",M("sessions.opt.dir")).option("--here",M("sessions.opt.here")).option("-n, --limit <count>",M("sessions.opt.limit")).option("--all",M("sessions.opt.all")).action(async e=>{await A(e)}),ge=me.command("show <id>").description(M("sessions.show")).option("-m, --messages <count>",M("sessions.opt.messages")).action(async(e,o)=>{await G(e,o)}),fe=me.command("resume <id>").description(M("sessions.resume")).option("--run",M("sessions.opt.run")).action(async(e,o)=>{await E(e,o)}),xe=me.command("export <ids...>").description(M("sessions.export")).option("-o, --output <dir>",M("sessions.opt.output")).option("--tools",M("sessions.opt.tools")).action(async(e,o)=>{await S(e,o)});p(ue,{examples:[q(`${P} sessions list`,"sessions.ex.list"),q(`${P} sessions list --tool codex`,"sessions.ex.codex"),q(`${P} sessions list --here --all`,"sessions.ex.here"),q(`${P} sessions list --json`,"sessions.ex.json")]}),p(ge,{examples:[q(`${P} sessions show 01a0f5fe`,"sessions.ex.show"),q(`${P} sessions show 01a0f5fe -m 20`,"sessions.ex.show_more")]}),p(fe,{examples:[q(`${P} sessions resume 01a0f5fe`,"sessions.ex.resume_print"),q(`${P} sessions resume 01a0f5fe --run`,"sessions.ex.resume")]}),p(xe,{examples:[q(`${P} sessions export 01a0f5fe 7c2e9d41 -o ./sessions`,"sessions.ex.export"),q(`${P} sessions export 01a0f5fe -o ./sessions --tools`,"sessions.ex.export_tools")]}),p(me,{...F("sessions",[[`${P} codex sessions`,"sessions.alt.codex_sessions"]]),examples:[q(`${P} sessions`,"sessions.ex.list"),q(`${P} sessions --tool codex --here`,"sessions.ex.here"),q(`${P} sessions show 01a0f5fe`,"sessions.ex.show"),q(`${P} sessions resume 01a0f5fe --run`,"sessions.ex.resume"),q(`${P} sessions export 01a0f5fe 7c2e9d41 -o ./sessions`,"sessions.ex.export")]});const he=L.command("lang").summary(M("lang.summary")).description(M("lang.description"));J(he);const ye=he.command("show").description(M("lang.show")).action(async()=>{await m(["show"])}),$e=he.command("set <locale>").description(M("lang.set")).action(async e=>{await m(["set",e])}),be=[q(`${P} lang show`,"lang.ex.show"),q(`${P} lang set en_US`,"lang.ex.set_en"),q(`${P} lang set zh_CN`,"lang.ex.set_zh")];p(he,{...F("lang",[[`${P} enter lang`,"lang.alt.enter"]]),examples:be}),p(ye,{examples:[be[0],q(`${P} lang show --json`,"lang.ex.show_json")]}),p($e,{examples:be.slice(1)});const ke=L.command("completion").summary(M("completion.summary")).description(M("completion.description")).argument("<shell>",M("completion.arg.shell")).action(async e=>{await $([e])});p(ke,{...F("completion"),examples:[q(`${P} completion bash > ~/.${P}-completion.bash`,"completion.ex.bash"),q(`${P} completion zsh > ~/.${P}-completion.zsh`,"completion.ex.zsh"),q(`${P} completion fish > ~/.config/fish/completions/${P}.fish`,"completion.ex.fish")]});const _e=L.command("enter").summary(M("enter.summary")).description(M("enter.description")).argument("[option]",M("enter.arg.option")).action(async e=>{if(e&&!["lang","language","apikey","api-key","models"].includes(e)||I(),e)switch(e){case"lang":case"language":await r.configLanguage();break;case"apikey":case"api-key":await r.configApiKey();break;case"models":await r.configModels();break;default:await f([e])}else await r.run()});p(_e,{...F("enter",[[`${P}`,"enter.alt.menu"],[`${P} config <tool>`,"enter.alt.config"]]),sections:[{title:M("enter.options_title"),rows:[[M("enter.option.none_term"),M("enter.option.none")],["lang",M("enter.option.lang")],["apikey",M("enter.option.apikey")],["models",M("enter.option.models")],["<tool>",M("enter.option.tool")]]}],examples:[q(`${P} enter`,"enter.ex.menu"),q(`${P} enter models`,"enter.ex.models"),q(`${P} enter codex`,"enter.ex.tool")]}),J(L),L.action(async()=>{I(),await r.run()}),p(L,{examples:[q(`${P}`,"root.ex.menu"),q(`${P} setup --key sk-xxx`,"root.ex.setup"),q(`${P} doctor`,"root.ex.doctor"),q(`${P} base auto`,"root.ex.base"),q(`${P} config codex`,"root.ex.config")]});const we=e=>{for(const o of e.commands)o.helpOption("-h, --help",M("global.help")),we(o)};return we(L),L}
|
package/dist/lib/tool-manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{execSync as
|
|
1
|
+
import{execSync as o,spawnSync as t}from"child_process";import{i18n as n}from"./i18n.js";import e from"inquirer";import r from"chalk";import{canPrompt as i,shouldAutoConfirm as a}from"./runtime-options.js";import{logger as l}from"../utils/logger.js";import{configManager as s,savedApiKeys as c}from"./config.js";import{getAdapter as d,listAdapters as p,TOOL_ADAPTERS as u}from"./tools/registry.js";import{backupBeforeWrite as m,listBackups as f,restoreBackup as h}from"./tools/backup.js";import{existsSync as g,rmSync as w}from"fs";import{dirname as P,join as y}from"path";import{toolHome as v}from"./tools/types.js";import{stringWidth as $}from"../utils/string-width.js";import{resolveModelCatalog as T}from"./model-catalog.js";import{compareVersions as C,getToolMinVersion as k}from"./model-registry.js";import{findInstalls as E,forgetInstalls as O,installLabel as S,mirrorInstallCommand as _,npmMirrorInstallCommand as N,npmMirrorVersion as j}from"./tools/tool-installs.js";import{mirrorInstall as M}from"./tool-upgrade.js";import{upgradeApp as U}from"./app-update.js";import{CLI_NAME as b}from"./brand.js";import{track as x,trackStep as I}from"./telemetry.js";import{addUserPathDir as R,broadcastEnvChange as F}from"./windows-env.js";import{removeAddons as L}from"./addons.js";export{C as compareVersions};function D(o){const t=u[o];return{name:t.name,command:t.command,installCommand:t.installCommand,configPath:t.configPath,displayName:t.displayName,...t.hidden?{hidden:!0}:{},...t.isInstalled?{gui:!0}:{}}}export const SUPPORTED_TOOLS=Object.fromEntries(Object.keys(u).map(o=>[o,D(o)]));export class ToolManager{static instance;constructor(){}static getInstance(){return ToolManager.instance||(ToolManager.instance=new ToolManager),ToolManager.instance}isToolInstalled(o){if(!SUPPORTED_TOOLS[o])return!1;const t=d(o);if(t?.isInstalled)try{return t.isInstalled()}catch{return!1}return this.isOnPath(o)||null!==this.nativeLauncher(o)}isOnPath(t){const n=SUPPORTED_TOOLS[t];if(!n)return!1;try{const t="win32"===process.platform?`where ${n.command}`:`which ${n.command}`;return o(t,{stdio:"pipe"}),!0}catch{return!1}}nativeLauncher(o){const t=d(o),n=t?.installSpec?.native?.binDir;if(!t||!n)return null;const e="win32"===process.platform?`${t.command}.exe`:t.command,r=y(v(),...n,e);return g(r)?r:null}ensureNativeOnPath(o){if("win32"!==process.platform||this.isOnPath(o))return null;const t=this.nativeLauncher(o);if(!t)return null;const n=P(t);try{if(!R(n))return null}catch(t){return l.logError(`ensureNativeOnPath: ${o}`,t),null}return F(),process.env.Path=`${process.env.Path??""};${n}`,n}addToPath(o){try{if("win32"===process.platform){if(!R(o))return!1;F(),process.env.Path=`${process.env.Path??""};${o}`}else process.env.PATH=`${process.env.PATH??""}:${o}`;return!0}catch(t){return l.logError(`addToPath: ${o}`,t),!1}}async installTool(o){return I(`install:${o}`,()=>this.installToolNow(o))}async installToolNow(t){const l=SUPPORTED_TOOLS[t];if(!l)throw new Error(`Unknown tool: ${t}`);const s=d(t)?.appInstaller;if(s&&!s.blocker()){const o=await U(t,{install:!0});if("failed"===o.result||"unavailable"===o.result)throw new Error(`Failed to install ${l.displayName}`);return}const c=d(t)?.installSpec;if(c&&(c.mirrorScript||c.npmPackage)){const o=_(c),e={installed:()=>this.isToolInstalled(t),expectedPaths:c.native?[y(v(),...c.native.binDir,"win32"===process.platform?`${c.command}.exe`:c.command)]:[],addToPath:o=>this.addToPath(o)};if(await M(c,e))return O(),void console.log(r.green("√ "+n.t("wizard.tool_installed")));throw console.log(r.red("× "+n.t("wizard.install_failed"))),console.log(r.yellow(" ! "+n.t("install.manual_command",{tool:l.displayName,command:o}))),c.mirrorScript&&c.npmPackage&&console.log(r.yellow(" ! "+n.t("install.manual_npm",{command:N(c,await j(c))}))),new Error(`Failed to install ${l.displayName}`)}const p=l.installCommand;console.log(r.gray("$ ")+r.white(p));try{return o(p,{stdio:"inherit"}),O(),void console.log(r.green("√ "+n.t("wizard.tool_installed")))}catch(o){if(console.log(r.red("× "+n.t("wizard.install_failed"))),!/EACCES|EPERM|permission denied/i.test(`${o?.message??""}${o?.stderr??""}`)&&243!==o?.status&&!p.startsWith("npm "))throw new Error(`Failed to install ${l.displayName}: ${o}`);console.log(r.yellow(" ! "+("win32"===process.platform?n.t("install.permission_windows",{command:p}):n.t("install.permission_unix",{command:p}))))}const{action:u}=!i()||a()?{action:"continue"}:await e.prompt([{type:"list",name:"action",message:n.t("install.what_next"),choices:[{name:n.t("install.installed_continue"),value:"continue"},{name:n.t("install.cancel_install"),value:"cancel"}]}]);if("cancel"===u)throw new Error(n.t("install.user_cancelled"));if(O(),!this.isToolInstalled(t))throw console.log(r.red("× "+n.t("install.still_not_installed",{tool:l.displayName}))),new Error(`${l.displayName} is not installed`);console.log(r.green("√ "+n.t("install.verified_success",{tool:l.displayName})))}getToolConfig(o){const t=d(o);if(!t)throw new Error(`Unknown tool: ${o}`);try{return t.getConfig()}catch(t){return l.warn(`Failed to read config for ${o}:`,t),l.logError(`ToolManager.getToolConfig(${o})`,t),null}}updateToolConfig(o,t){const n=d(o);if(!n)throw new Error(`Unknown tool: ${o}`);if(!n.updateConfig)throw new Error(`Tool ${o} does not support raw config updates`);n.updateConfig(t)}forceResetConfig(o){const t=d(o);if(!t)throw new Error(`Unknown tool: ${o}`);const n=t.forceResetPaths?t.forceResetPaths():this.backupPathsFor(t),e=[];for(const o of n)g(o)&&(m(o),w(o,{force:!0}),e.push(o));return e}loadPrivateConfig(o,t,n,e,r={}){const i=d(o);if(!i)throw new Error(`Unknown tool: ${o}`);r.force&&this.forceResetConfig(o),i.loadPrivateConfig({apiKey:t,baseUrl:s.getBaseUrl(),models:n,settings:s.getToolSettings(o),...e?{catalog:e}:{},...r.takeOver?{takeOver:!0}:{}})}async applyPrivateConfig(o,t,n,e={}){const r=this.installedVersion(o);return I(`apply:${o}`,()=>this.applyPrivateConfigNow(o,t,n,e),{...r?{tool_version:r}:{},...e.force?{force:!0}:{}})}async applyPrivateConfigNow(o,t,n,e){const r=d(o);if(!r)throw new Error(`Unknown tool: ${o}`);const i=r.wantsModelCatalog?await T(t):null,{force:a,takeOver:l}=e;a||l?this.loadPrivateConfig(o,t,n,i??void 0,{force:a,takeOver:l}):i?this.loadPrivateConfig(o,t,n,i):this.loadPrivateConfig(o,t,n)}supportsCcSwitch(o){return Boolean(d(o)?.ccSwitch)}applyNotes(o){const t=d(o);if(!t)return[];const e=[];try{t.applyNotes&&e.push(...t.applyNotes())}catch(t){l.logError(`ToolManager.applyNotes(${o})`,t)}const r=this.outdatedVersion(o);if(r){e.push({kind:"action",text:n.t("tools.version_outdated",{current:r.current,min:r.min,upgrade:t.installSpec?`${b} upgrade ${o}`:t.upgradeCommand||t.installCommand})});for(const o of t.upgradeHints?.(r.min)??[])e.push({kind:"action",text:o})}const i=t.installSpec?E(t.installSpec):[];return i.length>1&&e.push({kind:"action",text:n.t("upgrade.duplicates_note",{count:String(i.length),active:S(i[0]),others:i.slice(1).map(S).join("、"),tool:o})}),e}printApplied(o,t=16){const n=SUPPORTED_TOOLS[o]?.displayName??o,e=this.applyNotes(o);for(const o of e.filter(o=>"detail"===o.kind))l.record(`${n}: ${o.text}`);const i=e.filter(o=>"summary"===o.kind).map(o=>o.text).join(";"),a=" ".repeat(Math.max(1,t-$(n)));console.log(r.green("√ "+n)+(i?a+i:""));for(const o of e.filter(o=>"action"===o.kind))console.log(r.yellow(" ! "+o.text))}installedVersion(o){const n=d(o);if(!n)return null;if(n.installSpec)return E(n.installSpec)[0]?.version??null;if(n.installedVersion)try{return n.installedVersion()}catch(t){return l.logError(`ToolManager.installedVersion(${o})`,t),null}if(n.isInstalled)return null;try{const o={encoding:"utf-8",timeout:1e4,windowsHide:!0,stdio:["ignore","pipe","pipe"]},e=`${("win32"===process.platform?t(`${n.command} --version`,{...o,shell:!0}):t(n.command,["--version"],o)).stdout??""}`.match(/(\d+)\.(\d+)\.(\d+)/);return e?e[0]:null}catch{return null}}outdatedVersion(o){const t=k(o);if(!t)return null;const n=this.installedVersion(o);return n&&C(n,t)<0?{current:n,min:t}:null}unloadPrivateConfig(o){const t=d(o);if(!t)throw new Error(`Unknown tool: ${o}`);try{t.unloadPrivateConfig({savedKeys:c()}),t.addons&&L([t]),x(`remove:${o}`,"ok")}catch(t){throw x(`remove:${o}`,"fail",{error:t}),t}let e=[];try{e=t.unloadNotes?.()??[]}catch(t){l.logError(`ToolManager.unloadNotes(${o})`,t)}return e.length>0?e:[{kind:"action",text:n.t("config.reopen_hint",{tool:t.displayName})}]}async clearPinnedModels(o){const t=d(o);if(!t)throw new Error(`Unknown tool: ${o}`);if(s.setToolModel(o,null),!t.clearPinnedModels)return[];const n=s.getApiKeyForTool(o),e=t.wantsModelCatalog&&n?await T(n):null;return t.clearPinnedModels(e??void 0)}supportsClearPinnedModels(o){return Boolean(d(o)?.clearPinnedModels)}hasPendingElevation(o){return Boolean(d(o)?.pendingElevation?.())}holdsOurConfig(o){const t=d(o);if(!t)return!1;const n=c();return t.holdsOurConfig?t.holdsOurConfig(n):Boolean(t.detectCurrentConfig().apiKey)}detectCurrentConfig(o){const t=d(o);if(!t)throw new Error(`Unknown tool: ${o}`);return t.detectCurrentConfig()}backupPathsFor(o){return o.backupPaths?o.backupPaths():[o.configPath]}listToolBackups(o){const t=d(o);if(!t)throw new Error(`Unknown tool: ${o}`);return this.backupPathsFor(t).map(o=>({file:o,backups:f(o)}))}restorePrivateConfig(o){const t=d(o);if(!t)throw new Error(`Unknown tool: ${o}`);return this.backupPathsFor(t).map(o=>({file:o,result:h(o)}))}getInstalledTools(){return Object.keys(SUPPORTED_TOOLS).filter(o=>this.isToolInstalled(o))}getSupportedTools(){return p().filter(o=>!o.hidden).map(o=>D(o.name))}isGitInstalled(){try{const t="win32"===process.platform?"where git":"which git";return o(t,{stdio:"pipe"}),!0}catch{return!1}}}export const toolManager=ToolManager.getInstance();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e}from"path";import{applyGatewayModels as t,ccSwitchClaudeSettings as o,claudeCodeManager as n}from"../claude-code-manager.js";import{backupBeforeWrite as s}from"./backup.js";import{i18n as a}from"../i18n.js";import{baseModelId as
|
|
1
|
+
import{join as e}from"path";import{applyGatewayModels as t,ccSwitchClaudeSettings as o,claudeCodeManager as n}from"../claude-code-manager.js";import{backupBeforeWrite as s}from"./backup.js";import{i18n as a}from"../i18n.js";import{baseModelId as i}from"../model-catalog.js";import{gatewayModelSpecs as r,prettyModelName as l,vendorNames as c}from"../gateway-models.js";import{toolHome as d}from"./types.js";import{gatewayAddresses as u,normalizeBaseUrl as p}from"../gateway-addresses.js";import{configManager as m,savedApiKeys as f}from"../config.js";import{envCleanupPlan as g,lastEnvCleanup as _,removeEnvSources as h}from"../env-cleanup.js";import{canPrompt as v,hasExplicitYes as j}from"../runtime-options.js";import{maskHome as k}from"../telemetry.js";import{spawnSync as C}from"child_process";import{existsSync as y,readFileSync as A}from"fs";import{detectManagedOverrides as O}from"./claude-managed.js";import{installOfficialPlugins as P}from"./claude-plugins.js";import{jsonMcpAddons as S}from"./mcp-config.js";import{findInstalls as b,mirrorInstallCommand as x,brandInstallScripts as T}from"./tool-installs.js";import{updateNativeFromMirror as N}from"./claude-native-mirror.js";import{brandEnv as U}from"../brand.js";import{claudeFormat as w,claudeProjectFiles as H}from"../sessions/formats.js";const L=e(d(),".claude","settings.json"),R=e(d(),".claude.json");let E,I=null,M=()=>0===C("security",["find-generic-password","-s","Claude Code-credentials"],{stdio:"ignore"}).status;export function setClaudeKeychainProbeForTests(e){M=e}export function claudeAccountLoginPresent(){const t=process.env.CLAUDE_CONFIG_DIR?.trim()||e(d(),".claude");if(y(e(t,".credentials.json")))return!0;if("darwin"!==process.platform||U("TEST_HOME"))return!1;try{return M()}catch{return!1}}function B(){try{const t=JSON.parse(A(e(d(),".claude","settings.json"),"utf-8"));return"string"==typeof t.autoUpdatesChannel?t.autoUpdatesChannel:"latest"}catch{return"latest"}}function D(e){if(!e)return;const t=new Set(e.models);return r("claude-code",e.clientModels,e.clientPersonal).filter(e=>t.has(e.id))}function K(){const e=n.getSettings().env?.ANTHROPIC_BASE_URL;return"string"==typeof e&&e.trim()?claudeCodeAdapter.holdsOurConfig(f())?null:e.trim():null}let F=null;const G={command:"claude",npmPackage:"@anthropic-ai/claude-code",native:{binDir:[".local","bin"],updateArgs:["update"],dataDirs:[[".local","share","claude"]],mirrorUpdate:()=>N(B())},mirrorScript:T("claude-code"),brew:"claude-code"};function J(){return v()&&!j()}export const claudeCodeAdapter={name:"claude-code",displayName:"Claude Code",command:"claude",installCommand:x(G),upgradeCommand:"claude update",installSpec:G,upgradeHints:e=>"stable"===B()?[a.t("tools.claude_code.stable_channel",{min:e})]:[],configPath:L,sessions:{format:w,files:()=>H(e(process.env.CLAUDE_CONFIG_DIR?.trim()||e(d(),".claude"),"projects")),resumeCommand:e=>({command:"claude",args:["--resume",e]})},wantsModelCatalog:!0,addons:S({file:()=>e(d(),".claude.json"),skillsDir:()=>e(d(),".claude","skills"),skillsAgent:"claude-code"}),ccSwitch:{app:"claude",endpointPath:"",cards:e=>[{settingsConfig:o(e.apiKey,e.baseUrl,e.models,e.catalog?.models,D(e.catalog))}]},loadPrivateConfig(t){F=K(),s(L),s(R),E=D(t.catalog),n.loadPrivateConfig(t.apiKey,t.models,t.catalog?.models,E);const o=e(d(),".local","bin","win32"===process.platform?"claude.exe":"claude"),a=b(claudeCodeAdapter.installSpec)[0]?.path??(y(o)?o:null);I=a?P(a,{retry:Boolean(t.takeOver)}):null},holdsOurConfig(e){const t=n.getSettings().env??{},o="string"==typeof t.ANTHROPIC_AUTH_TOKEN?t.ANTHROPIC_AUTH_TOKEN.trim():"",s="string"==typeof t.ANTHROPIC_BASE_URL?p(t.ANTHROPIC_BASE_URL):null;return!(!o||!e.includes(o))||null!==s&&(u().some(e=>e.url===s)||s===p(m.getBaseUrl()))},planNotes(){const e=[],t=K();t&&e.push(a.t("tools.claude_code.plan_replace_provider",{url:t}));for(const t of g())e.push(a.t("tools.claude_code.plan_env_remove",{location:k(t.location),vars:Object.keys(t.vars).join(", ")}));return e},unloadPrivateConfig(e){const t=n.getSettings().env??{};Boolean(t.ANTHROPIC_AUTH_TOKEN||t.ANTHROPIC_BASE_URL)&&!claudeCodeAdapter.holdsOurConfig(e?.savedKeys??[])||(s(L),n.unloadPrivateConfig())},detectCurrentConfig:()=>n.detectCurrentConfig(),getConfig:()=>({settings:n.getSettings(),mcp:n.getMCPConfig()}),updateConfig(e){const t=e||{};t.settings&&n.saveSettings(t.settings),t.mcp&&n.saveMCPConfig(t.mcp)},clearPinnedModels:e=>(s(L),n.clearPinnedModels(e?.models)),listedModels(){const e=n.getSettings().modelPicker;return Array.isArray(e?.options)?e.options.map(e=>i(String(e.model))):null},refreshModelMenu(e){const o=n.getSettings(),a=t(o,D(e.catalog));JSON.stringify(a)!==JSON.stringify(o)&&(s(L),n.saveSettings(a))},async followUp(){const e=_().foreign;if(0===e.length||!J())return null;const t=e.map(e=>`${k(e.location)}(${Object.keys(e.vars).join(", ")})`).join("、");return{prompt:a.t("tools.claude_code.env_foreign_offer",{where:t}),hint:a.t("tools.claude_code.env_foreign",{location:e.map(e=>k(e.location)).join("、"),vars:[...new Set(e.flatMap(e=>Object.keys(e.vars)))].join(", ")}),async run(){const t=h(e),o=t.removed.map(e=>({kind:"summary",text:a.t("tools.claude_code.env_removed_foreign",{location:k(e.location),vars:Object.keys(e.vars).join(", ")})}));t.machineLeft.length>0&&o.push({kind:"action",text:a.t("messages.env_vars_machine_left",{vars:t.machineLeft.join(", ")})});for(const e of t.notBackedUp)o.push({kind:"action",text:a.t("tools.claude_code.env_not_backed_up",{location:k(e.location),vars:Object.keys(e.vars).join(", ")})});return o},decline(){}}},applyNotes(){const e=[];I?.installed.length&&(e.push({kind:"summary",text:a.t("tools.claude_code.plugins_installed",{count:String(I.installed.length)})}),e.push({kind:"detail",text:I.installed.join(", ")})),"git"===I?.skipped?e.push({kind:"action",text:a.t("tools.claude_code.plugins_need_git")}):("marketplace"===I?.skipped||"recent_failure"===I?.skipped||I?.failed.length)&&e.push({kind:"action",text:a.t("tools.claude_code.plugins_failed")}),E&&E.length>0&&(e.push({kind:"summary",text:a.t("tools.claude_code.gateway_models",{count:String(E.length),vendors:c(E.map(e=>e.id)).join(" / ")})}),e.push({kind:"detail",text:E.map(e=>e.name||l(e.id)).join(", ")})),F&&e.push({kind:"summary",text:a.t("tools.claude_code.provider_replaced",{url:F})});const t=_();for(const o of t.removed)e.push({kind:"summary",text:a.t("tools.claude_code.env_removed",{location:k(o.location),vars:Object.keys(o.vars).join(", ")})});for(const o of t.foreign){const t={location:k(o.location),vars:Object.keys(o.vars).join(", ")};e.push(J()?{kind:"detail",text:a.t("tools.claude_code.env_foreign_found",t)}:{kind:"action",text:a.t("tools.claude_code.env_foreign",t)})}t.machineLeft.length>0&&e.push({kind:"action",text:a.t("messages.env_vars_machine_left",{vars:t.machineLeft.join(", ")})});for(const o of t.notBackedUp)e.push({kind:"action",text:a.t("tools.claude_code.env_not_backed_up",{location:k(o.location),vars:Object.keys(o.vars).join(", ")})});const o=n.getLastReplaced();o.length>0&&e.push({kind:"summary",text:a.t("tools.claude_code.replaced_user_models",{values:o.join(", ")})}),"win32"!==process.platform||process.env.CLAUDE_CODE_GIT_BASH_PATH||0===C("where",["git"],{windowsHide:!0,stdio:"ignore"}).status||e.push({kind:"action",text:a.t("tools.claude_code.no_git_bash")}),claudeAccountLoginPresent()&&e.push({kind:"detail",text:a.t("tools.claude_code.account_login_overridden")});for(const t of O())e.push({kind:"action",text:a.t("tools.claude_code.managed_override",{source:t.source,keys:t.keys.join(", ")})});for(const t of n.getLastTierFallbacks())e.push({kind:"detail",text:a.t("tools.claude_code.tier_fallback",{tier:t.tier,from:t.from,to:t.to})});return e},backupPaths:()=>[L,R],forceResetPaths:()=>[L]};
|
package/dist/lib/tools/codex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash as e}from"crypto";import{existsSync as t,readdirSync as o,readFileSync as n,rmSync as r,statSync as s}from"fs";import{join as i}from"path";import*as c from"@iarna/toml";import{logger as d}from"../../utils/logger.js";import{i18n as l}from"../i18n.js";import{backupBeforeWrite as a,atomicWriteFile as u}from"./backup.js";import{codexHome as p,pickModel as m,toolHome as f,withV1 as _}from"./types.js";import{moveSessionsToProvider as g,NO_STATE_DB as x,runningCodexPids as h,SessionMoveError as y}from"../codex-sessions.js";import{codexFormat as k,codexRolloutFiles as b}from"../sessions/formats.js";import{getGatewayModelRules as v,getToolDefaultModel as w}from"../model-registry.js";import{ownsValue as j,recordAfterWrite as S,takeField as C}from"../written-values.js";import{configManager as M,savedApiKeys as O}from"../config.js";import{maskHome as A,track as E}from"../telemetry.js";import{buildCodexCatalog as P,catalogRejections as N,codexCatalogPath as D,fillFromOlderEntries as T,installedCodexBinaries as $,loadBundledCodexModels as I,loadPreviousCodexModels as L,previousGatewayModelIds as J}from"./codex-catalog.js";import{gatewayModelSpecs as R,modelFamily as G}from"../gateway-models.js";import{isOurGatewayUrl as K,noteWrittenGatewayUrl as U}from"../gateway-addresses.js";import{findInstalls as B,mirrorInstallCommand as X,brandInstallScripts as q}from"./tool-installs.js";import{chatgptDesktopApp as W}from"./chatgpt-desktop.js";const z=()=>p(),F=()=>i(z(),"config.toml"),Y="sessions_move_declined",H=["browser_use","browser_use_external","computer_use"],Q="desktop_features_restored";function V(e){if(!0===M.getMachineSetting("codex",Q))return!1;const t=e.features;if(!me(t)||!H.every(e=>!1===t[e]))return!1;for(const e of H)delete t[e];return!0}function Z(){try{M.setMachineSetting("codex",Q,!0)}catch(e){d.logError("codexAdapter.noteFeaturesRestored",e)}}export function forgetDeclinedSessions(){try{const e=M.getMachineSetting("codex",Y);"number"==typeof e&&0!==e&&M.setMachineSetting("codex",Y,0)}catch(e){d.logError("codexAdapter.forgetDeclinedSessions",e)}}export function codexWorkModeOn(){try{const e=_e();return e.model_provider===ne&&me(e.desktop)&&"STEPS_PROSE"===e.desktop.conversationDetailMode}catch{return!1}}function ee(){try{if(me(_e().desktop))return!0}catch{}if("darwin"===process.platform)return["/Applications",i(f(),"Applications")].some(e=>["ChatGPT.app","Codex.app"].some(o=>t(i(e,o))));if("win32"===process.platform){const e=i(process.env.LOCALAPPDATA||i(f(),"AppData","Local"),"Packages");try{return o(e).some(e=>/^OpenAI\.(Codex|ChatGPT)/i.test(e))}catch{return!1}}return t("/usr/lib/chatgpt/ChatGPT")}export function codexConfigPath(){return F()}const te=()=>i(z(),"auth.json"),oe="OPENAI_API_KEY",ne="custom",re="custom",se="high",ie=["gpt-5.5","gpt-5.6-sol","gpt-6-astra"],ce=["high","xhigh"],de={goals:!0,js_repl:!1};let le=[];const ae=1e6,ue=9e5;export const CODEX_ONE_MILLION_CONTEXT_SETTING="one_million_context";function pe(e){return/(?:^|\/)claude(?:-|$)/i.test(e)}function me(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function fe(e,t){return me(e[t])||(e[t]={}),e[t]}function _e(){if(!t(F()))return{};const e=n(F(),"utf-8");if(!e.trim())return{};try{const t=c.parse(e);if(!me(t))throw new Error("config.toml root must be a TOML table");return t}catch(e){throw new Error(`Existing ~/.codex/config.toml cannot be parsed; back it up and fix it first: ${e instanceof Error?e.message:String(e)}`)}}function ge(){if(!t(te()))return{};try{const e=JSON.parse(n(te(),"utf-8"));return me(e)?e:{}}catch{return{}}}let xe=null;function he(e){const t=e.profiles;if(me(t)){for(const[e,o]of Object.entries(t))me(o)&&2===Object.keys(o).length&&o.model_provider===ne&&o.model===e&&delete t[e];0===Object.keys(t).length&&delete e.profiles}}let ye=null;const ke=()=>i(M.getConfigDir(),"codex-catalog-check.json");function be(t,o){const n=e("sha256").update(t);for(const e of o)try{const t=s(e);n.update(`\0${e}\0${t.size}\0${t.mtimeMs}`)}catch{n.update(`\0${e}`)}return n.digest("hex")}function ve(){try{const e=JSON.parse(n(ke(),"utf-8"));return e&&"object"==typeof e?e:{}}catch{return{}}}function we(e){try{u(ke(),JSON.stringify(e)+"\n")}catch(e){d.logError("codexAdapter.writeCheckState",e)}}function je(e){we({wanted:be("",e)})}function Se(){const e=ve();void 0!==e.wanted&&(delete e.wanted,we(e))}function Ce(){const e=ve().wanted;return void 0!==e&&e!==be("",$())}function Me(e){const o=D();t(o)&&n(o,"utf-8")===e||(a(o),u(o,e))}function Oe(e,t){if(0===t.length)return[];const o=be(e,t);if(function(e){return ve().signature===e}(o))return[];const n=N(D(),t);return 0===n.length&&function(e){we({signature:e})}(o),n}function Ae(e,t,o){const n=!1!==t.settings?.one_million_context;!function(e){e.model_context_window===ae&&delete e.model_context_window,e.model_auto_compact_token_limit===ue&&delete e.model_auto_compact_token_limit}(e);const s=()=>{e.model_catalog_json===D()&&delete e.model_catalog_json,n&&(e.model_context_window=ae,e.model_auto_compact_token_limit=ue)},i=I()??L();if(!i)return d.logError("codexAdapter.writeModelCatalog",new Error("no Codex binary found; model catalog skipped")),ye="skipped",E("codex-catalog","skip",{detail:{reason:"no_codex_binary"}}),je($()),void s();const c=t.catalog,l=e=>P({bundled:e,specs:R("codex",c?.clientModels,c?.clientPersonal),...c?.clientPersonal?.includes("codex")?{chosenGpt:(c.clientModels?.codex??[]).filter(e=>!e.hidden).map(e=>e.id)}:{},...c?{keyModels:c.models}:{},gatewayAvailable:c?.models??J(),oneMillion:n,selectedModel:o,..."gateway"===c?.oneMillionSource?{claudeOneMillion:c.oneMillion}:{}}),a=e=>JSON.stringify(e,null,2)+"\n";let u=l(i);Me(a(u));const p=$(),m=Oe(a(u),p);if(m.length>0){const e=Date.now();let t=!1;for(const e of m){const o=I(e.bin);if(o){for(const e of[{models:T(u.models,o)},{models:T(l(o).models,o)}])if(Me(a(e)),0===Oe(a(e),p).length){u=e,t=!0;break}if(t)break}}if(E("codex-catalog",t?"fallback":"fail",{duration_ms:Date.now()-e,error:m[0].error,detail:{rejected_by:m.map(e=>({version:e.version,path:A(e.bin)}))}}),!t)return ye={rejectedBy:m[0]},r(D(),{force:!0}),je(p),void s()}ye={listed:u.models.filter(e=>"list"===e.visibility).map(e=>({id:String(e.slug),name:String(e.display_name??e.slug)}))},e.model_catalog_json=D(),Se()}export function codexCatalogRejection(){let e;try{e=_e()}catch{return null}return e.model_catalog_json===D()&&t(D())?N(D())[0]??null:null}export function setCodexOneMillionContext(e,t){const o=_e(),n=c.stringify(o),r="string"==typeof o.model?o.model:w("codex");Ae(o,{settings:{[CODEX_ONE_MILLION_CONTEXT_SETTING]:e},catalog:t},r);const s=c.stringify(o);s!==n&&(a(F()),u(F(),s))}const Ee={command:"codex",npmPackage:"@openai/codex",native:{binDir:"win32"===process.platform?["AppData","Local","Programs","OpenAI","Codex","bin"]:[".local","bin"],updateArgs:["update"],updateTimeoutMs:12e4,dataDirs:[[".codex","packages","standalone"]]},mirrorScript:q("codex"),brew:"codex"};function Pe(e){const t=me(e.model_providers)?e.model_providers[ne]:void 0;if(!me(t))return null;const o="string"==typeof t.base_url?t.base_url.trim():"";return o&&!K(o)?o:null}let Ne=null;function De(){if("skipped"===ye)return 0===B(Ee).length?[]:[{kind:"action",text:l.t("tools.codex.catalog_skipped")}];if(!ye)return[];if("rejectedBy"in ye){const{bin:e,version:t}=ye.rejectedBy;return[{kind:"action",text:l.t("tools.codex.catalog_rejected",{path:e,version:t??"?"})}]}const e=new Map;for(const t of ye.listed)e.set(G(t.id),(e.get(G(t.id))??0)+1);const t=["gpt","claude","gemini","other","grok"].filter(t=>e.has(t)).map(t=>`${l.t(`tools.model_family.${t}`)} ${e.get(t)}`).join(" · ");return[{kind:"summary",text:l.t("tools.codex.catalog_written",{count:String(ye.listed.length),breakdown:t})},{kind:"detail",text:ye.listed.map(e=>e.name).join(", ")},...codexWorkModeOn()||ee()?[{kind:"action",text:l.t(codexWorkModeOn()?"tools.codex.work_mode_on":"tools.codex.work_mode_hint")}]:[]]}export const codexAdapter={name:"codex",companionApps:[W],displayName:"Codex",command:"codex",installCommand:X(Ee),installSpec:Ee,configPath:F(),sessions:{format:k,files:()=>[...b(i(p(),"sessions")),...b(i(p(),"archived_sessions"))],resumeCommand:e=>({command:"codex",args:["resume",e]})},wantsModelCatalog:!0,listedModels(){const e=_e();if(e.model_catalog_json!==D())return e.model_provider===ne&&Ce()?[]:null;try{return(JSON.parse(n(D(),"utf-8")).models??[]).filter(e=>"list"===e.visibility).map(e=>String(e.slug))}catch{return null}},refreshModelMenu(e){const t=_e();if(t.model_catalog_json!==D()&&(t.model_provider!==ne||!Ce()))return;setCodexOneMillionContext(!1!==e.settings?.one_million_context,e.catalog);const o=_e(),n=function(e,t){const o=me(e.model_providers)?e.model_providers[ne]:void 0;return!(!me(o)||o.base_url!==t||!0===o.supports_standalone_web_search||(o.supports_standalone_web_search=!0,0))}(o,_(e.baseUrl));(V(o)||n)&&(a(F()),u(F(),c.stringify(o))),Z()},async followUp(){if(_e().model_provider!==ne)return null;const e=await g(ne,{dryRun:!0}),t=Math.max(e.moved.length,e.dbRows);if(0===t)return forgetDeclinedSessions(),null;const o=M.getMachineSetting("codex",Y);if("number"==typeof o&&t<=o)return null;const n={count:String(t)};return h().length>0?{hint:l.t("tools.codex.sessions_hidden_running",n)}:{prompt:l.t("tools.codex.sessions_offer",n),hint:l.t("tools.codex.sessions_hidden",n),async run(){if(h().length>0)return[{kind:"action",text:l.t("tools.codex.sessions_hidden_running",n)}];let e;try{e=await g(ne)}catch(e){d.logError("codexAdapter.followUp.run",e);const o=e instanceof y?e.backupDir:null;E("codex-sessions","fail",{error:e,detail:{count:t,backup:Boolean(o)}});const n=A(e instanceof Error?e.message:String(e)).replace(/\s+/g," ").trim();return[{kind:"action",text:l.t("codex_sessions.move_failed",{reason:n})},...o?[{kind:"action",text:l.t("codex_sessions.move_failed_undo",{dir:o})}]:[]]}forgetDeclinedSessions(),E("codex-sessions","ok",{detail:{files:e.moved.length,db_rows:e.dbRows}});const o=[...new Set(e.moved.map(e=>e.from))].join("、")||"-",r=String(Math.max(e.moved.length,e.dbRows)),s=[{kind:"summary",text:l.t("codex_sessions.moved",{count:r,from:o,target:ne})},{kind:"summary",text:l.t("codex_sessions.backup",{dir:e.backupDir??""})}];return e.dbSkipped&&e.dbSkipped!==x&&s.push({kind:"action",text:l.t("codex_sessions.db_skipped",{reason:e.dbSkipped})}),s},decline(){M.setMachineSetting("codex",Y,t)}}},applyNotes(){const e=[];return Ne&&e.push({kind:"summary",text:l.t("tools.codex.provider_replaced",{url:Ne})}),le.length>0&&e.push({kind:"summary",text:l.t("tools.codex.replaced_user_settings",{values:le.join(", ")})}),[...e,...De()]},planNotes(){let e;try{e=_e()}catch{return[]}const t=[],o=Pe(e);return o?t.push(l.t("tools.codex.plan_replace_provider",{url:o})):"string"==typeof e.model_provider&&e.model_provider!==ne&&t.push(l.t("tools.codex.plan_switch_provider",{provider:e.model_provider})),t},ccSwitch:{app:"codex",endpointPath:"/v1",cards(e){const t=w("codex"),o=m(e.models,t),n=pe(o)?t:o,r={};Ae(r,e,n);const s={model_provider:ne,model:n,model_reasoning_effort:se,..."string"==typeof r.model_catalog_json?{model_catalog_json:r.model_catalog_json}:{},model_providers:{[ne]:{name:re,base_url:_(e.baseUrl),wire_api:"responses",requires_openai_auth:!0,supports_standalone_web_search:!0}}};return[{settingsConfig:{auth:{[oe]:e.apiKey},config:c.stringify(s)}}]}},loadPrivateConfig(e){S(()=>{const t=w("codex"),o=m(e.models,t),n=pe(o)?t:o,r=_(e.baseUrl),s=_e();le=[];const i=v().retired,d=(e,t,o,n,r)=>{void 0===t||t===o||"string"==typeof t&&i.includes(t)||j(e,t,n)||le.push(`${r} = ${String(t)}`),C(e,o)};d("codex.model",s.model,n,ie,"model"),s.model=n,s.model_provider=ne,d("codex.model_reasoning_effort",s.model_reasoning_effort,se,ce,"model_reasoning_effort"),s.model_reasoning_effort=se;const l="string"==typeof s.model?s.model:n;Ae(s,e,l);const p=fe(s,"model_providers");Ne=Pe(s),U(r);const f=me(p[ne])?{...p[ne]}:{};delete f.env_key;const{experimental_bearer_token:g,...x}=f;p[ne]={...x,name:re,wire_api:"responses",requires_openai_auth:!0,supports_standalone_web_search:!0,base_url:r},he(s),fe(fe(s,"tui"),"model_availability_nux")[l]=4;const h=fe(s,"features");for(const[e,t]of Object.entries(de))d(`codex.features.${e}`,void 0===h[e]?void 0:String(h[e]),String(t),[String(t)],`features.${e}`),h[e]=t;V(s),a(F()),u(F(),c.stringify(s))}),Z(),function(e){const t=e.trim();if(!t)return;const o={...ge(),auth_mode:"apikey",[oe]:t};a(te()),u(te(),JSON.stringify(o,null,2)+"\n",384)}(e.apiKey)},holdsOurConfig(e){const t=ge()[oe];return"string"==typeof t&&e.includes(t.trim())},unloadPrivateConfig(e){if(xe=function(e){const t=ge(),o="string"==typeof t[oe]?t[oe].trim():"";if(!o)return me(t.tokens)?"chatgpt":null;if(!e.includes(o))return"other_key";const{[oe]:n,auth_mode:s,...i}=t;return a(te()),me(i.tokens)?(u(te(),JSON.stringify({...i,auth_mode:"chatgpt"},null,2)+"\n",384),"chatgpt"):(r(te(),{force:!0}),"signed_out")}(e?.savedKeys??[]),!t(F()))return;let o;try{o=_e()}catch(e){return void d.logError("codexAdapter.unloadPrivateConfig",e)}const n=o.model_providers;me(n)&&me(n[ne])&&K(n[ne].base_url)&&me(n)&&(delete n[ne],0===Object.keys(n).length&&delete o.model_providers,o.model_provider===ne&&delete o.model_provider),o.model_catalog_json===D()&&delete o.model_catalog_json,V(o),he(o),a(F()),u(F(),c.stringify(o)),Z(),Se()},unloadNotes(){switch(xe){case"chatgpt":return[{kind:"action",text:l.t("tools.codex.unload_chatgpt_restored")}];case"other_key":return[{kind:"action",text:l.t("tools.codex.unload_other_key")}];default:return[{kind:"action",text:l.t("tools.codex.unload_sign_in")}]}},detectCurrentConfig(){const e=ge()[oe];return{apiKey:"string"==typeof e&&e.trim()?e.trim():null}},getConfig(){try{return _e()}catch(e){return d.logError("codexAdapter.getConfig",e),null}},backupPaths:()=>[F(),te(),D()]};export function codexAuthProblem(){try{const e=_e(),t=e.model_providers?.[ne];if(e.model_provider!==ne||!t)return null;const o="string"==typeof t.experimental_bearer_token?t.experimental_bearer_token.trim():"";if(o&&!O().includes(o))return"stale_bearer";const n=ge();return!0===t.requires_openai_auth&&"chatgpt"===n.auth_mode?"chatgpt_login":null}catch{return null}}
|
|
1
|
+
import{createHash as e}from"crypto";import{existsSync as t,readdirSync as o,readFileSync as n,rmSync as r,statSync as s}from"fs";import{join as i}from"path";import*as c from"@iarna/toml";import{logger as l}from"../../utils/logger.js";import{i18n as d}from"../i18n.js";import{backupBeforeWrite as a,atomicWriteFile as u}from"./backup.js";import{codexHome as p,pickModel as m,toolHome as f,withV1 as _}from"./types.js";import{codexMcpAddons as g}from"./mcp-config.js";import{moveSessionsToProvider as x,NO_STATE_DB as h,runningCodexPids as y,SessionMoveError as k}from"../codex-sessions.js";import{codexFormat as b,codexRolloutFiles as v}from"../sessions/formats.js";import{getGatewayModelRules as w,getToolDefaultModel as j}from"../model-registry.js";import{ownsValue as S,recordAfterWrite as C,takeField as M}from"../written-values.js";import{configManager as O,savedApiKeys as A}from"../config.js";import{maskHome as E,track as P}from"../telemetry.js";import{buildCodexCatalog as N,catalogRejections as D,codexCatalogPath as T,fillFromOlderEntries as $,installedCodexBinaries as I,loadBundledCodexModels as L,loadPreviousCodexModels as J,previousGatewayModelIds as R}from"./codex-catalog.js";import{gatewayModelSpecs as G,modelFamily as K}from"../gateway-models.js";import{isOurGatewayUrl as U,noteWrittenGatewayUrl as B}from"../gateway-addresses.js";import{findInstalls as X,mirrorInstallCommand as q,brandInstallScripts as W}from"./tool-installs.js";import{chatgptDesktopApp as z}from"./chatgpt-desktop.js";const F=()=>p(),Y=()=>i(F(),"config.toml"),H="sessions_move_declined",Q=["browser_use","browser_use_external","computer_use"],V="desktop_features_restored";function Z(e){if(!0===O.getMachineSetting("codex",V))return!1;const t=e.features;if(!fe(t)||!Q.every(e=>!1===t[e]))return!1;for(const e of Q)delete t[e];return!0}function ee(){try{O.setMachineSetting("codex",V,!0)}catch(e){l.logError("codexAdapter.noteFeaturesRestored",e)}}export function forgetDeclinedSessions(){try{const e=O.getMachineSetting("codex",H);"number"==typeof e&&0!==e&&O.setMachineSetting("codex",H,0)}catch(e){l.logError("codexAdapter.forgetDeclinedSessions",e)}}export function codexWorkModeOn(){try{const e=ge();return e.model_provider===re&&fe(e.desktop)&&"STEPS_PROSE"===e.desktop.conversationDetailMode}catch{return!1}}function te(){try{if(fe(ge().desktop))return!0}catch{}if("darwin"===process.platform)return["/Applications",i(f(),"Applications")].some(e=>["ChatGPT.app","Codex.app"].some(o=>t(i(e,o))));if("win32"===process.platform){const e=i(process.env.LOCALAPPDATA||i(f(),"AppData","Local"),"Packages");try{return o(e).some(e=>/^OpenAI\.(Codex|ChatGPT)/i.test(e))}catch{return!1}}return t("/usr/lib/chatgpt/ChatGPT")}export function codexConfigPath(){return Y()}const oe=()=>i(F(),"auth.json"),ne="OPENAI_API_KEY",re="custom",se="custom",ie="high",ce=["gpt-5.5","gpt-5.6-sol","gpt-6-astra"],le=["high","xhigh"],de={goals:!0,js_repl:!1};let ae=[];const ue=1e6,pe=9e5;export const CODEX_ONE_MILLION_CONTEXT_SETTING="one_million_context";function me(e){return/(?:^|\/)claude(?:-|$)/i.test(e)}function fe(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function _e(e,t){return fe(e[t])||(e[t]={}),e[t]}function ge(){if(!t(Y()))return{};const e=n(Y(),"utf-8");if(!e.trim())return{};try{const t=c.parse(e);if(!fe(t))throw new Error("config.toml root must be a TOML table");return t}catch(e){throw new Error(`Existing ~/.codex/config.toml cannot be parsed; back it up and fix it first: ${e instanceof Error?e.message:String(e)}`)}}function xe(){if(!t(oe()))return{};try{const e=JSON.parse(n(oe(),"utf-8"));return fe(e)?e:{}}catch{return{}}}let he=null;function ye(e){const t=e.profiles;if(fe(t)){for(const[e,o]of Object.entries(t))fe(o)&&2===Object.keys(o).length&&o.model_provider===re&&o.model===e&&delete t[e];0===Object.keys(t).length&&delete e.profiles}}let ke=null;const be=()=>i(O.getConfigDir(),"codex-catalog-check.json");function ve(t,o){const n=e("sha256").update(t);for(const e of o)try{const t=s(e);n.update(`\0${e}\0${t.size}\0${t.mtimeMs}`)}catch{n.update(`\0${e}`)}return n.digest("hex")}function we(){try{const e=JSON.parse(n(be(),"utf-8"));return e&&"object"==typeof e?e:{}}catch{return{}}}function je(e){try{u(be(),JSON.stringify(e)+"\n")}catch(e){l.logError("codexAdapter.writeCheckState",e)}}function Se(e){je({wanted:ve("",e)})}function Ce(){const e=we();void 0!==e.wanted&&(delete e.wanted,je(e))}function Me(){const e=we().wanted;return void 0!==e&&e!==ve("",I())}function Oe(e){const o=T();t(o)&&n(o,"utf-8")===e||(a(o),u(o,e))}function Ae(e,t){if(0===t.length)return[];const o=ve(e,t);if(function(e){return we().signature===e}(o))return[];const n=D(T(),t);return 0===n.length&&function(e){je({signature:e})}(o),n}function Ee(e,t,o){const n=!1!==t.settings?.one_million_context;!function(e){e.model_context_window===ue&&delete e.model_context_window,e.model_auto_compact_token_limit===pe&&delete e.model_auto_compact_token_limit}(e);const s=()=>{e.model_catalog_json===T()&&delete e.model_catalog_json,n&&(e.model_context_window=ue,e.model_auto_compact_token_limit=pe)},i=L()??J();if(!i)return l.logError("codexAdapter.writeModelCatalog",new Error("no Codex binary found; model catalog skipped")),ke="skipped",P("codex-catalog","skip",{detail:{reason:"no_codex_binary"}}),Se(I()),void s();const c=t.catalog,d=e=>N({bundled:e,specs:G("codex",c?.clientModels,c?.clientPersonal),...c?.clientPersonal?.includes("codex")?{chosenGpt:(c.clientModels?.codex??[]).filter(e=>!e.hidden).map(e=>e.id)}:{},...c?{keyModels:c.models}:{},gatewayAvailable:c?.models??R(),oneMillion:n,selectedModel:o,..."gateway"===c?.oneMillionSource?{claudeOneMillion:c.oneMillion}:{}}),a=e=>JSON.stringify(e,null,2)+"\n";let u=d(i);Oe(a(u));const p=I(),m=Ae(a(u),p);if(m.length>0){const e=Date.now();let t=!1;for(const e of m){const o=L(e.bin);if(o){for(const e of[{models:$(u.models,o)},{models:$(d(o).models,o)}])if(Oe(a(e)),0===Ae(a(e),p).length){u=e,t=!0;break}if(t)break}}if(P("codex-catalog",t?"fallback":"fail",{duration_ms:Date.now()-e,error:m[0].error,detail:{rejected_by:m.map(e=>({version:e.version,path:E(e.bin)}))}}),!t)return ke={rejectedBy:m[0]},r(T(),{force:!0}),Se(p),void s()}ke={listed:u.models.filter(e=>"list"===e.visibility).map(e=>({id:String(e.slug),name:String(e.display_name??e.slug)}))},e.model_catalog_json=T(),Ce()}export function codexCatalogRejection(){let e;try{e=ge()}catch{return null}return e.model_catalog_json===T()&&t(T())?D(T())[0]??null:null}export function setCodexOneMillionContext(e,t){const o=ge(),n=c.stringify(o),r="string"==typeof o.model?o.model:j("codex");Ee(o,{settings:{[CODEX_ONE_MILLION_CONTEXT_SETTING]:e},catalog:t},r);const s=c.stringify(o);s!==n&&(a(Y()),u(Y(),s))}const Pe={command:"codex",npmPackage:"@openai/codex",native:{binDir:"win32"===process.platform?["AppData","Local","Programs","OpenAI","Codex","bin"]:[".local","bin"],updateArgs:["update"],updateTimeoutMs:12e4,dataDirs:[[".codex","packages","standalone"]]},mirrorScript:W("codex"),brew:"codex"};function Ne(e){const t=fe(e.model_providers)?e.model_providers[re]:void 0;if(!fe(t))return null;const o="string"==typeof t.base_url?t.base_url.trim():"";return o&&!U(o)?o:null}let De=null;function Te(){if("skipped"===ke)return 0===X(Pe).length?[]:[{kind:"action",text:d.t("tools.codex.catalog_skipped")}];if(!ke)return[];if("rejectedBy"in ke){const{bin:e,version:t}=ke.rejectedBy;return[{kind:"action",text:d.t("tools.codex.catalog_rejected",{path:e,version:t??"?"})}]}const e=new Map;for(const t of ke.listed)e.set(K(t.id),(e.get(K(t.id))??0)+1);const t=["gpt","claude","gemini","other","grok"].filter(t=>e.has(t)).map(t=>`${d.t(`tools.model_family.${t}`)} ${e.get(t)}`).join(" · ");return[{kind:"summary",text:d.t("tools.codex.catalog_written",{count:String(ke.listed.length),breakdown:t})},{kind:"detail",text:ke.listed.map(e=>e.name).join(", ")},...codexWorkModeOn()||te()?[{kind:"action",text:d.t(codexWorkModeOn()?"tools.codex.work_mode_on":"tools.codex.work_mode_hint")}]:[]]}export const codexAdapter={name:"codex",companionApps:[z],displayName:"Codex",command:"codex",installCommand:q(Pe),installSpec:Pe,configPath:Y(),addons:g({file:Y,skillsDir:()=>i(f(),".agents","skills"),skillsAgent:"codex"}),sessions:{format:b,files:()=>[...v(i(p(),"sessions")),...v(i(p(),"archived_sessions"))],resumeCommand:e=>({command:"codex",args:["resume",e]})},wantsModelCatalog:!0,listedModels(){const e=ge();if(e.model_catalog_json!==T())return e.model_provider===re&&Me()?[]:null;try{return(JSON.parse(n(T(),"utf-8")).models??[]).filter(e=>"list"===e.visibility).map(e=>String(e.slug))}catch{return null}},refreshModelMenu(e){const t=ge();if(t.model_catalog_json!==T()&&(t.model_provider!==re||!Me()))return;setCodexOneMillionContext(!1!==e.settings?.one_million_context,e.catalog);const o=ge(),n=function(e,t){const o=fe(e.model_providers)?e.model_providers[re]:void 0;return!(!fe(o)||o.base_url!==t||!0===o.supports_standalone_web_search||(o.supports_standalone_web_search=!0,0))}(o,_(e.baseUrl));(Z(o)||n)&&(a(Y()),u(Y(),c.stringify(o))),ee()},async followUp(){if(ge().model_provider!==re)return null;const e=await x(re,{dryRun:!0}),t=Math.max(e.moved.length,e.dbRows);if(0===t)return forgetDeclinedSessions(),null;const o=O.getMachineSetting("codex",H);if("number"==typeof o&&t<=o)return null;const n={count:String(t)};return y().length>0?{hint:d.t("tools.codex.sessions_hidden_running",n)}:{prompt:d.t("tools.codex.sessions_offer",n),hint:d.t("tools.codex.sessions_hidden",n),async run(){if(y().length>0)return[{kind:"action",text:d.t("tools.codex.sessions_hidden_running",n)}];let e;try{e=await x(re)}catch(e){l.logError("codexAdapter.followUp.run",e);const o=e instanceof k?e.backupDir:null;P("codex-sessions","fail",{error:e,detail:{count:t,backup:Boolean(o)}});const n=E(e instanceof Error?e.message:String(e)).replace(/\s+/g," ").trim();return[{kind:"action",text:d.t("codex_sessions.move_failed",{reason:n})},...o?[{kind:"action",text:d.t("codex_sessions.move_failed_undo",{dir:o})}]:[]]}forgetDeclinedSessions(),P("codex-sessions","ok",{detail:{files:e.moved.length,db_rows:e.dbRows}});const o=[...new Set(e.moved.map(e=>e.from))].join("、")||"-",r=String(Math.max(e.moved.length,e.dbRows)),s=[{kind:"summary",text:d.t("codex_sessions.moved",{count:r,from:o,target:re})},{kind:"summary",text:d.t("codex_sessions.backup",{dir:e.backupDir??""})}];return e.dbSkipped&&e.dbSkipped!==h&&s.push({kind:"action",text:d.t("codex_sessions.db_skipped",{reason:e.dbSkipped})}),s},decline(){O.setMachineSetting("codex",H,t)}}},applyNotes(){const e=[];return De&&e.push({kind:"summary",text:d.t("tools.codex.provider_replaced",{url:De})}),ae.length>0&&e.push({kind:"summary",text:d.t("tools.codex.replaced_user_settings",{values:ae.join(", ")})}),[...e,...Te()]},planNotes(){let e;try{e=ge()}catch{return[]}const t=[],o=Ne(e);return o?t.push(d.t("tools.codex.plan_replace_provider",{url:o})):"string"==typeof e.model_provider&&e.model_provider!==re&&t.push(d.t("tools.codex.plan_switch_provider",{provider:e.model_provider})),t},ccSwitch:{app:"codex",endpointPath:"/v1",cards(e){const t=j("codex"),o=m(e.models,t),n=me(o)?t:o,r={};Ee(r,e,n);const s={model_provider:re,model:n,model_reasoning_effort:ie,..."string"==typeof r.model_catalog_json?{model_catalog_json:r.model_catalog_json}:{},model_providers:{[re]:{name:se,base_url:_(e.baseUrl),wire_api:"responses",requires_openai_auth:!0,supports_standalone_web_search:!0}}};return[{settingsConfig:{auth:{[ne]:e.apiKey},config:c.stringify(s)}}]}},loadPrivateConfig(e){C(()=>{const t=j("codex"),o=m(e.models,t),n=me(o)?t:o,r=_(e.baseUrl),s=ge();ae=[];const i=w().retired,l=(e,t,o,n,r)=>{void 0===t||t===o||"string"==typeof t&&i.includes(t)||S(e,t,n)||ae.push(`${r} = ${String(t)}`),M(e,o)};l("codex.model",s.model,n,ce,"model"),s.model=n,s.model_provider=re,l("codex.model_reasoning_effort",s.model_reasoning_effort,ie,le,"model_reasoning_effort"),s.model_reasoning_effort=ie;const d="string"==typeof s.model?s.model:n;Ee(s,e,d);const p=_e(s,"model_providers");De=Ne(s),B(r);const f=fe(p[re])?{...p[re]}:{};delete f.env_key;const{experimental_bearer_token:g,...x}=f;p[re]={...x,name:se,wire_api:"responses",requires_openai_auth:!0,supports_standalone_web_search:!0,base_url:r},ye(s),_e(_e(s,"tui"),"model_availability_nux")[d]=4;const h=_e(s,"features");for(const[e,t]of Object.entries(de))l(`codex.features.${e}`,void 0===h[e]?void 0:String(h[e]),String(t),[String(t)],`features.${e}`),h[e]=t;Z(s),a(Y()),u(Y(),c.stringify(s))}),ee(),function(e){const t=e.trim();if(!t)return;const o={...xe(),auth_mode:"apikey",[ne]:t};a(oe()),u(oe(),JSON.stringify(o,null,2)+"\n",384)}(e.apiKey)},holdsOurConfig(e){const t=xe()[ne];return"string"==typeof t&&e.includes(t.trim())},unloadPrivateConfig(e){if(he=function(e){const t=xe(),o="string"==typeof t[ne]?t[ne].trim():"";if(!o)return fe(t.tokens)?"chatgpt":null;if(!e.includes(o))return"other_key";const{[ne]:n,auth_mode:s,...i}=t;return a(oe()),fe(i.tokens)?(u(oe(),JSON.stringify({...i,auth_mode:"chatgpt"},null,2)+"\n",384),"chatgpt"):(r(oe(),{force:!0}),"signed_out")}(e?.savedKeys??[]),!t(Y()))return;let o;try{o=ge()}catch(e){return void l.logError("codexAdapter.unloadPrivateConfig",e)}const n=o.model_providers;fe(n)&&fe(n[re])&&U(n[re].base_url)&&fe(n)&&(delete n[re],0===Object.keys(n).length&&delete o.model_providers,o.model_provider===re&&delete o.model_provider),o.model_catalog_json===T()&&delete o.model_catalog_json,Z(o),ye(o),a(Y()),u(Y(),c.stringify(o)),ee(),Ce()},unloadNotes(){switch(he){case"chatgpt":return[{kind:"action",text:d.t("tools.codex.unload_chatgpt_restored")}];case"other_key":return[{kind:"action",text:d.t("tools.codex.unload_other_key")}];default:return[{kind:"action",text:d.t("tools.codex.unload_sign_in")}]}},detectCurrentConfig(){const e=xe()[ne];return{apiKey:"string"==typeof e&&e.trim()?e.trim():null}},getConfig(){try{return ge()}catch(e){return l.logError("codexAdapter.getConfig",e),null}},backupPaths:()=>[Y(),oe(),T()]};export function codexAuthProblem(){try{const e=ge(),t=e.model_providers?.[re];if(e.model_provider!==re||!t)return null;const o="string"==typeof t.experimental_bearer_token?t.experimental_bearer_token.trim():"";if(o&&!A().includes(o))return"stale_bearer";const n=xe();return!0===t.requires_openai_auth&&"chatgpt"===n.auth_mode?"chatgpt_login":null}catch{return null}}
|
package/dist/lib/tools/dsh.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as e,readFileSync as t}from"fs";import{join as r}from"path";import*as n from"js-yaml";import{logger as
|
|
1
|
+
import{existsSync as e,readFileSync as t}from"fs";import{join as r}from"path";import*as n from"js-yaml";import{logger as s}from"../../utils/logger.js";import{API_KEY_ENV as o,BRAND_NAME as i,PROVIDER_KEY as a}from"../brand.js";import{i18n as c}from"../i18n.js";import{modelFamily as d,prettyModelName as l,vendorNames as f}from"../gateway-models.js";import{getToolDefaultModel as p,getToolMenuModels as u}from"../model-registry.js";import{atomicWriteFile as m,backupBeforeWrite as g}from"./backup.js";import{bareModelId as h,menuSpecs as y,usesResponses as v}from"./codebuddy-models.js";import{pickModel as w,toolHome as x,withV1 as b}from"./types.js";import{isOurMcpUrl as k}from"../addons.js";const A=()=>process.env.DSH_HOME?.trim()||r(x(),".dsh"),j=e=>r(A(),"profiles",e,"cordis.patch.yml"),E=()=>r(A(),".credentials.yaml"),C=["web","desktop"],O="llm-pi-ai",M="agent-default-model",S=a,$=`${a}-gpt`,K=`${a}-claude`,P=["off","minimal","low","medium","high","xhigh","max"],L=e=>!!e&&"object"==typeof e&&!Array.isArray(e),U=e=>e===S||e===$||e===K;class _{source;constructor(e){this.source=e}}const D=n.DEFAULT_SCHEMA.extend(new n.Type("tag:yaml.org,2002:js",{kind:"scalar",construct:e=>new _(e??""),instanceOf:_,represent:e=>e.source}));function N(r){if(!e(r))return{entries:[],header:""};const s=t(r,"utf-8"),o=s.match(/^(?:#.*\r?\n)*/)?.[0]??"",i=n.load(s,{schema:D});if(null==i)return{entries:[],header:o};if(!Array.isArray(i))throw new Error(`Existing ${r} must hold a YAML list`);return{entries:i,header:o}}function R(r,s){const o=s.header+n.dump(s.entries,{schema:D,lineWidth:-1,noRefs:!0,sortKeys:!1});e(r)&&t(r,"utf-8")===o||(g(r),m(r,o))}function T(e,t){let r=e.find(e=>e.id===t);return r||(r={id:t},e.push(r)),L(r.config)||(r.config={}),r.config}function H(e){const t=e.find(e=>e.id===O&&L(e.config))?.config;return L(t?.providers)?t.providers:{}}function W(){if(!e(E()))return{version:1,refs:{}};const r=n.load(t(E(),"utf-8"));if(null==r)return{version:1,refs:{}};if(!L(r))throw new Error(`Existing ${E()} must hold a YAML mapping`);return"version"in r?L(r.refs)?r:{...r,refs:{}}:{version:1,refs:r}}function F(e){g(E()),m(E(),n.dump(e,{lineWidth:-1,sortKeys:!1}),384)}function I(e){const t=e.capabilities??{},r={id:e.id,name:e.name??l(e.id)},n=t.contextWindow??e.contextWindow;n&&(r.contextWindow=n);const s=t.maxOutput??e.maxOutputTokens;if(s&&(r.maxTokens=s),t.vision&&(r.input=["text","image"]),e.id.startsWith("deepseek-"))r.compat={thinkingFormat:"deepseek"},r.reasoningEfforts={off:null,high:"high",max:"max"};else if(t.reasoning&&t.reasoningEfforts){const e=t.reasoningEfforts.filter(e=>P.includes(e)&&"off"!==e);e.length>0&&(r.reasoningEfforts=Object.fromEntries(e.map(e=>[e,e])))}return r}function Y(e){return"claude"===d(e.id)?K:v(e)?$:S}function z(e,t){const r=b(t),n={apiKeyEnv:o},s={[S]:{displayName:i,...n,api:"openai-completions",baseURL:r,compat:{supportsDeveloperRole:!1,maxTokensField:"max_tokens"}},[$]:{displayName:`${i} GPT`,...n,api:"openai-responses",baseURL:r},[K]:{displayName:`${i} Claude`,...n,api:"anthropic-messages",baseURL:r.replace(/\/v\d+$/,"")}},a={};for(const[t,r]of Object.entries(s)){const n=e.filter(e=>Y(e)===t).map(I);n.length>0&&(a[t]={...r,models:n})}return a}const B=e=>h(w(e.models,p("dsh"))),G=(e,t)=>y(e,t,u("dsh"));function q(e,t,r,n=N(e)){const s=T(n.entries,O),o=Object.entries(L(s.providers)?s.providers:{}).filter(([e])=>!U(e));s.providers={...Object.fromEntries(o),...z(t,r)},R(e,n)}const J=e=>{const t=e.find(e=>e.id===M)?.config;return!L(t)||"string"!=typeof t.provider||U(t.provider)?null:`${t.provider}/${String(t.model)}`};let Q=null;const V=e=>`mcp-server-${e}`;function X(e){let t=e.find(e=>Array.isArray(e.insert));return t||(t={insert:[]},e.push(t)),t.insert}function Z(e,t){for(const r of e){if(!Array.isArray(r.insert))continue;const e=r.insert,n=e.findIndex(e=>L(e)&&e.id===V(t));if(n>=0)return{rows:e,index:n}}return null}const ee={skillsDir:()=>r(x(),".agents","skills"),skillsAgent:"codex",readMcpUrl(e){for(const t of C){const r=Z(N(j(t)).entries,e),n=r?r.rows[r.index].config?.url:void 0;if(k(n))return n}return null},writeMcp(e){const t=W();t.refs[o]!==e.apiKey&&(t.refs={...t.refs,[o]:e.apiKey},F(t));const r={id:V(e.name),name:"@deepseek-ai/dsh-mcp-manager/server",config:{serverName:e.name,transport:"streamable-http",url:e.url,headers:{Authorization:`Bearer \${credential:${o}}`}}};for(const t of C){const n=j(t),s=N(n),o=Z(s.entries,e.name);if(o){const e=o.rows[o.index].config?.url;if(void 0!==e&&!k(e))return!1;o.rows[o.index]=r}else X(s.entries).push(r);R(n,s)}return!0},removeMcp(t){let r=!1;for(const n of C){const s=j(n);if(!e(s))continue;const o=N(s),i=Z(o.entries,t);i&&k(i.rows[i.index].config?.url)&&(i.rows.splice(i.index,1),o.entries=o.entries.filter(e=>!(Array.isArray(e.insert)&&0===e.insert.length)),R(s,o),r=!0)}return r}};export const dshAdapter={name:"dsh",displayName:"DeepSeek Harness",command:"dsh",installCommand:"npx @deepseek-ai/dsh web",get configPath(){return j("web")},wantsModelCatalog:!0,addons:ee,isInstalled(){if(e(A()))return!0;if("darwin"===process.platform)return["/Applications/DeepSeek Harness.app",r(x(),"Applications","DeepSeek Harness.app")].some(t=>e(t));const t="win32"===process.platform?process.env.LOCALAPPDATA:void 0;return!!t&&e(r(t,"Programs","DeepSeek Harness"))},ccSwitch:{app:"dsh",endpointPath:"/v1",cards(e){const t=z(G(e.catalog,B(e)),e.baseUrl);return Object.entries(t).map(([t,r])=>{const{displayName:n,baseURL:s,apiKeyEnv:o,models:i,...a}=r,c=Object.fromEntries(i.map(({id:e,contextWindow:t,maxTokens:r,input:n,...s})=>[String(e),{...s,...t||r?{limit:{...t?{context:t}:{},...r?{output:r}:{}}}:{},...n?{modalities:{input:n,output:["text"]}}:{}}]));return{id:t,name:String(n),settingsConfig:{name:n,kind:"custom",enabled:!0,...a,options:{baseURL:s,apiKey:e.apiKey},models:c}}})},owns:e=>U(e)},loadPrivateConfig(e){const t=G(e.catalog,B(e));if(0===t.length)throw new Error(c.t("tools.dsh.no_models"));const r=t.find(t=>t.id===B(e))??t[0],n=[];for(const s of C){const o=j(s),i=N(o),a=J(i.entries);a&&!n.includes(a)&&n.push(a);const c=T(i.entries,M);c.provider=Y(r),c.model=r.id,delete c.reasoningEffort,q(o,t,e.baseUrl,i)}const s=W();s.refs={...s.refs,[o]:e.apiKey},F(s),Q={count:t.length,vendors:f(t.map(e=>e.id)),replaced:n}},unloadPrivateConfig(){try{for(const t of C){const r=j(t);if(!e(r))continue;const n=N(r),s=H(n.entries);for(const e of Object.keys(s))U(e)&&delete s[e];const o=n.entries.find(e=>e.id===M)?.config;L(o)&&"string"==typeof o.provider&&U(o.provider)&&(n.entries=n.entries.filter(e=>e.id!==M)),R(r,n)}const t=W(),r=t.refs;o in r&&(delete r[o],F(t))}catch(e){s.logError("dshAdapter.unloadPrivateConfig",e)}},detectCurrentConfig(){try{const e=W().refs[o];return{apiKey:"string"==typeof e&&e?e:null}}catch{return{apiKey:null}}},listedModels(){try{const e=Object.entries(H(N(j("web")).entries)).filter(([e])=>U(e));return 0===e.length?null:e.flatMap(([,e])=>L(e)&&Array.isArray(e.models)?e.models:[]).map(e=>String(e.id))}catch{return null}},refreshModelMenu(e){const t=G(e.catalog,B(e));if(0!==t.length)for(const r of C)q(j(r),t,e.baseUrl)},planNotes(){try{const e=J(N(j("web")).entries);return e?[c.t("tools.dsh.replaces_default",{model:e})]:[]}catch{return[]}},applyNotes(){if(!Q)return[];const e=[{kind:"summary",text:c.t("tools.dsh.menu_written",{count:String(Q.count),list:Q.vendors.join(c.t("tools.codebuddy.list_separator"))})},{kind:"action",text:c.t("tools.dsh.pick_in_app")}];for(const t of Q.replaced)e.push({kind:"detail",text:c.t("tools.dsh.replaced_default",{model:t})});return e},backupPaths:()=>[...C.map(j),E()],forceResetPaths:()=>C.map(j),getConfig(){try{return N(j("web")).entries}catch(e){return s.logError("dshAdapter.getConfig",e),null}}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as r,mkdirSync as e,readFileSync as t}from"fs";import{dirname as n}from"path";import*as i from"@iarna/toml";import{isOurMcpUrl as s}from"../addons.js";import{atomicWriteFile as l,backupBeforeWrite as o}from"./backup.js";const u=r=>!!r&&"object"==typeof r&&!Array.isArray(r);function c(e){if(!r(e))return{};const n=t(e,"utf-8");if(!n.trim())return{};const i=JSON.parse(n);if(!u(i))throw new Error(`${e} must hold a JSON object`);return i}function f(i,s,u){const c=JSON.stringify(s,null,2)+"\n";r(i)&&t(i,"utf-8")===c||(e(n(i),{recursive:!0}),o(i),l(i,c,u))}export function jsonMcpAddons(e){const t=r=>(u(r.mcpServers)||(r.mcpServers={}),r.mcpServers);return{skillsDir:e.skillsDir,skillsAgent:e.skillsAgent,readMcpUrl(r){const n=t(c(e.file()))[r];return u(n)&&s(n.url)?n.url:null},writeMcp(r){const n=c(e.file()),i=t(n),l=i[r.name];return!(u(l)&&void 0!==l.url&&!s(l.url)||(i[r.name]={type:"http",url:r.url,headers:{Authorization:`Bearer ${r.apiKey}`}},f(e.file(),n,384),0))},removeMcp(n){if(!r(e.file()))return!1;const i=c(e.file()),l=t(i);return!(!u(l[n])||!s(l[n].url)||(delete l[n],f(e.file(),i,384),0))}}}export function codexMcpAddons(c){const f=()=>{if(!r(c.file()))return{};const e=t(c.file(),"utf-8");return e.trim()?i.parse(e):{}},p=s=>{const u=i.stringify(s);r(c.file())&&t(c.file(),"utf-8")===u||(e(n(c.file()),{recursive:!0}),o(c.file()),l(c.file(),u,384))},a=r=>(u(r.mcp_servers)||(r.mcp_servers={}),r.mcp_servers);return{skillsDir:c.skillsDir,skillsAgent:c.skillsAgent,readMcpUrl(r){const e=a(f())[r];return u(e)&&s(e.url)?e.url:null},writeMcp(r){const e=f(),t=a(e),n=t[r.name];if(u(n)&&void 0!==n.url&&!s(n.url))return!1;const i=u(n)?n:{};return delete i.bearer_token_env_var,t[r.name]={...i,url:r.url,http_headers:{Authorization:`Bearer ${r.apiKey}`}},p(e),!0},removeMcp(e){if(!r(c.file()))return!1;const t=f(),n=a(t);return!(!u(n[e])||!s(n[e].url)||(delete n[e],0===Object.keys(n).length&&delete t.mcp_servers,p(t),0))}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as t}from"fs";import{join as r}from"path";import{logger as
|
|
1
|
+
import{existsSync as t}from"fs";import{join as r}from"path";import{logger as o}from"../../utils/logger.js";import{i18n as e}from"../i18n.js";import{getToolDefaultModel as n,getToolMenuModels as d}from"../model-registry.js";import{prettyModelName as s,vendorNames as i}from"../gateway-models.js";import{bareModelId as a,foreignIdsReplaced as l,isOurEntry as p,menuSpecs as c,mergeEntries as u,modelEntry as m,ourApiKey as y,ourEntries as f,readModelsFile as g,writeModelsFile as b}from"./codebuddy-models.js";import{pickModel as w,toolHome as k,withV1 as h}from"./types.js";import{BRAND_NAME as C,CLI_NAME as j,PROVIDER_KEY as v}from"../brand.js";import{jsonMcpAddons as _}from"./mcp-config.js";const D=()=>process.env.WORKBUDDY_CONFIG_DIR?.trim()||process.env.CODEBUDDY_CONFIG_DIR?.trim()||r(k(),".workbuddy"),P=()=>r(D(),"models.json"),I="https://www.codebuddy.cn/work/";let K=null;function A(t,r){const o=g(P()),{entries:e,replaced:n}=u(o.entries,r,t.baseUrl,t.apiKey,!0);return b(P(),o,e),n}const B=t=>a(w(t.models,n("workbuddy"))),N=(t,r)=>c(t,r,d("workbuddy"));export const workbuddyAdapter={name:"workbuddy",displayName:"WorkBuddy",command:"workbuddy",installCommand:"darwin"===process.platform?`open ${I}`:I,get configPath(){return P()},wantsModelCatalog:!0,isInstalled:function(){return!!t(D())||"darwin"===process.platform&&["/Applications/WorkBuddy.app",r(k(),"Applications","WorkBuddy.app")].some(r=>t(r))},addons:_({file:()=>r(D(),"mcp.json"),skillsDir:()=>r(D(),"skills")}),ccSwitch:{app:"workbuddy",endpointPath:"/v1",handOver:!0,cards(t){const r=N(t.catalog,B(t)).map(r=>m(r,t.baseUrl,t.apiKey,!0));return[{settingsConfig:{vendor:C,url:`${h(t.baseUrl)}/chat/completions`,apiKey:t.apiKey,models:r}}]},applyAsCards(t,r){const o=g(P()),e=`${v}-${j}`,n=(r[0]?.settingsConfig.models??[]).map(t=>({...t,ccSwitchProviderId:e})),d=o.entries.filter(t=>!(p(t)||t&&"object"==typeof t&&t.ccSwitchProviderId===e));b(P(),o,[...d,...n])}},loadPrivateConfig(t){const r=N(t.catalog,B(t)),o=A(t,r);K={names:r.map(t=>t.name??s(t.id)),vendors:i(r.map(t=>t.id)),replaced:o}},unloadPrivateConfig(){try{const t=g(P());if(0===f(t.entries).length)return;b(P(),t,t.entries.filter(t=>!p(t)))}catch(t){o.logError("workbuddyAdapter.unloadPrivateConfig",t)}},detectCurrentConfig(){try{return{apiKey:y(g(P()).entries)}}catch{return{apiKey:null}}},listedModels(){try{const t=f(g(P()).entries);return t.length>0?t.map(t=>String(t.id)):null}catch{return null}},refreshModelMenu(t){A(t,N(t.catalog,B(t)))},planNotes(){try{const t=g(P()),r=l(t.entries,N(void 0,n("workbuddy")));return r.length>0?[e.t("tools.codebuddy.replaces_models",{path:P(),list:r.join(e.t("tools.codebuddy.list_separator"))})]:[]}catch{return[]}},applyNotes(){if(!K)return[];const t=[{kind:"summary",text:e.t("tools.workbuddy.menu_written",{count:String(K.names.length),list:K.vendors.join(e.t("tools.codebuddy.list_separator"))})},{kind:"action",text:e.t("tools.workbuddy.pick_in_app")}];return K.replaced.length>0&&t.push({kind:"detail",text:e.t("tools.codebuddy.replaced_models",{tool:"workbuddy",list:K.replaced.join(e.t("tools.codebuddy.list_separator"))})}),t},backupPaths:()=>[P()],getConfig(){try{return g(P()).entries}catch(t){return o.logError("workbuddyAdapter.getConfig",t),null}}};
|
package/dist/locales/en_US.json
CHANGED
|
@@ -821,7 +821,9 @@
|
|
|
821
821
|
"upgrade": "Install or update these components first (comma separated, e.g. claude-code,grok; same as the upgrade command), then configure as the other options say",
|
|
822
822
|
"codebuddykey": "API key just for CodeBuddy Code",
|
|
823
823
|
"workbuddykey": "API key just for WorkBuddy",
|
|
824
|
-
"dshkey": "API key just for DeepSeek Harness"
|
|
824
|
+
"dshkey": "API key just for DeepSeek Harness",
|
|
825
|
+
"addons": "also connect MCP and install the ai-models skill (default for one-line installs)",
|
|
826
|
+
"no_addons": "skip MCP and the skill"
|
|
825
827
|
},
|
|
826
828
|
"autodetect_title": "Models the --key can use and the tools configured:",
|
|
827
829
|
"autodetect": {
|
|
@@ -1251,6 +1253,27 @@
|
|
|
1251
1253
|
"see_also": "See also",
|
|
1252
1254
|
"back_to_index": "Command list",
|
|
1253
1255
|
"use_instead": "Use it instead when"
|
|
1256
|
+
},
|
|
1257
|
+
"addons": {
|
|
1258
|
+
"summary": "Connect coding tools to the MCP server and the ai-models skill, or remove them",
|
|
1259
|
+
"description": "Writes the site's MCP server into Claude Code, Codex, DeepSeek Harness and WorkBuddy and installs the ai-models skill (a script for text, image and video models), so the agent can generate images and videos or call other models. The skill is installed with npx skills from a mirror first, and downloaded by {{cli}} itself when that fails.\ninstall without tool names covers every installed tool; remove without tool names removes everything, including the token file the script reads. Only the entries {{cli}} wrote are touched.",
|
|
1260
|
+
"arg": {
|
|
1261
|
+
"action": "install (default), remove or status",
|
|
1262
|
+
"tools": "claude-code, codex, dsh, workbuddy; several allowed, all when omitted"
|
|
1263
|
+
},
|
|
1264
|
+
"opt": {
|
|
1265
|
+
"key": "use this token instead of the saved one"
|
|
1266
|
+
},
|
|
1267
|
+
"when": "When the tools are set up and you want the agent to use the site's image and video models; also how existing users connect.",
|
|
1268
|
+
"alt": {
|
|
1269
|
+
"setup": "install together with the tool configuration"
|
|
1270
|
+
},
|
|
1271
|
+
"ex": {
|
|
1272
|
+
"install": "connect every installed tool",
|
|
1273
|
+
"some": "only Claude Code and Codex",
|
|
1274
|
+
"status": "see which tools are connected",
|
|
1275
|
+
"remove": "remove everything"
|
|
1276
|
+
}
|
|
1254
1277
|
}
|
|
1255
1278
|
},
|
|
1256
1279
|
"errors": {
|
|
@@ -1346,5 +1369,32 @@
|
|
|
1346
1369
|
"error_other_account": "the prompt was approved with another administrator account, so the app was installed for that account: approve with the current account (make it an administrator), or use the app from that account",
|
|
1347
1370
|
"elevate_offer": "Windows requires administrator rights to install {{tool}}. Show the permission prompt now?",
|
|
1348
1371
|
"elevating": "Requesting administrator rights: click Yes in the Windows prompt…"
|
|
1372
|
+
},
|
|
1373
|
+
"addons": {
|
|
1374
|
+
"offer": "Connect {{tools}} to the MCP server and install the ai-models skill? The agent can then generate images and videos or call other models",
|
|
1375
|
+
"declined_hint": "To install later: {{command}}",
|
|
1376
|
+
"later_hint": "To let the agent generate images and videos: {{command}}",
|
|
1377
|
+
"mcp_written": "MCP connected",
|
|
1378
|
+
"mcp_foreign": "an MCP entry with the same name points elsewhere; left alone",
|
|
1379
|
+
"mcp_removed": "MCP removed",
|
|
1380
|
+
"mcp_absent": "no MCP entry",
|
|
1381
|
+
"skill_installed": "skill installed",
|
|
1382
|
+
"skill_updated": "skill updated",
|
|
1383
|
+
"skill_unchanged": "skill up to date",
|
|
1384
|
+
"skill_modified": "skill folder was edited; left alone",
|
|
1385
|
+
"skill_foreign": "another skill with the same name is there; left alone",
|
|
1386
|
+
"skill_removed": "skill removed",
|
|
1387
|
+
"skill_absent": "no skill installed",
|
|
1388
|
+
"skill_skipped": "skill not installed",
|
|
1389
|
+
"skill_fetch_failed": "Could not download the skill from the site; only MCP was connected. Run it again when the network is back",
|
|
1390
|
+
"restart_hint": "Reopen Claude Code, Codex or WorkBuddy if they are running so they pick it up",
|
|
1391
|
+
"unknown_tool": "{{tool}} does not support MCP and skills here",
|
|
1392
|
+
"unknown_action": "Unknown action {{action}}; use install, remove or status",
|
|
1393
|
+
"bad_key": "The token should start with sk-",
|
|
1394
|
+
"no_key": "No token saved yet",
|
|
1395
|
+
"none_installed": "No Claude Code, Codex, DeepSeek Harness or WorkBuddy found on this computer",
|
|
1396
|
+
"status_on": "connected",
|
|
1397
|
+
"status_off": "not connected",
|
|
1398
|
+
"status_not_installed": "not installed"
|
|
1349
1399
|
}
|
|
1350
1400
|
}
|
package/dist/locales/zh_CN.json
CHANGED
|
@@ -821,7 +821,9 @@
|
|
|
821
821
|
"upgrade": "先安装或更新这些组件(逗号分隔,如 claude-code,grok;和 upgrade 命令相同),再按其他参数配置",
|
|
822
822
|
"codebuddykey": "CodeBuddy Code 专属令牌",
|
|
823
823
|
"workbuddykey": "WorkBuddy 专属令牌",
|
|
824
|
-
"dshkey": "DeepSeek Harness 专属令牌"
|
|
824
|
+
"dshkey": "DeepSeek Harness 专属令牌",
|
|
825
|
+
"addons": "配置后接上 MCP、装上 ai-models 技能(一键安装默认装上)",
|
|
826
|
+
"no_addons": "不接 MCP、不装技能"
|
|
825
827
|
},
|
|
826
828
|
"autodetect_title": "--key 能用的模型和自动配置的工具:",
|
|
827
829
|
"autodetect": {
|
|
@@ -1251,6 +1253,27 @@
|
|
|
1251
1253
|
"see_also": "另见",
|
|
1252
1254
|
"back_to_index": "命令列表",
|
|
1253
1255
|
"use_instead": "什么情况下改用它"
|
|
1256
|
+
},
|
|
1257
|
+
"addons": {
|
|
1258
|
+
"summary": "给编码工具接上 MCP、装上 ai-models 技能,或者移除",
|
|
1259
|
+
"description": "把网站的 MCP 服务器写进 Claude Code、Codex、DeepSeek Harness、WorkBuddy 的配置,并装上 ai-models 技能(带一个调用文本、图片、视频模型的脚本),Agent 就能在对话里直接生成图片、视频或调用别的模型。技能先用 npx skills 从国内镜像装,装不上时由 {{cli}} 自己下载。\ninstall 不写工具名时给装着的工具都装;remove 不写工具名时全部移除,连脚本读的令牌文件也删。只改 {{cli}} 写的那一条,你自己的 MCP 和改过的技能不动。",
|
|
1260
|
+
"arg": {
|
|
1261
|
+
"action": "install(默认)、remove 或 status",
|
|
1262
|
+
"tools": "claude-code、codex、dsh、workbuddy,可以写多个;不写就是全部"
|
|
1263
|
+
},
|
|
1264
|
+
"opt": {
|
|
1265
|
+
"key": "用这个令牌,不用已保存的"
|
|
1266
|
+
},
|
|
1267
|
+
"when": "已经配好工具、想让 Agent 直接用网站的图片和视频模型时;老用户接入用这条。",
|
|
1268
|
+
"alt": {
|
|
1269
|
+
"setup": "配置工具时一起装上"
|
|
1270
|
+
},
|
|
1271
|
+
"ex": {
|
|
1272
|
+
"install": "给装着的工具都接上",
|
|
1273
|
+
"some": "只接 Claude Code 和 Codex",
|
|
1274
|
+
"status": "看哪些工具接上了",
|
|
1275
|
+
"remove": "全部移除"
|
|
1276
|
+
}
|
|
1254
1277
|
}
|
|
1255
1278
|
},
|
|
1256
1279
|
"errors": {
|
|
@@ -1346,5 +1369,32 @@
|
|
|
1346
1369
|
"error_other_account": "授权时用的是另一个管理员账号,应用装给了那个账号:用当前账号授权(把当前账号设为管理员),或在那个账号下使用",
|
|
1347
1370
|
"elevate_offer": "Windows 要求用管理员权限安装 {{tool}}。现在弹出授权窗口?",
|
|
1348
1371
|
"elevating": "正在请求管理员权限:在弹出的 Windows 窗口里点「是」…"
|
|
1372
|
+
},
|
|
1373
|
+
"addons": {
|
|
1374
|
+
"offer": "给 {{tools}} 接上 MCP 并装上 ai-models 技能?装好后可以在对话里直接让模型生成图片、视频,或调用别的模型",
|
|
1375
|
+
"declined_hint": "以后想装:{{command}}",
|
|
1376
|
+
"later_hint": "要让 Agent 直接生成图片、视频:{{command}}",
|
|
1377
|
+
"mcp_written": "MCP 已接上",
|
|
1378
|
+
"mcp_foreign": "已有同名的 MCP 条目指向别处,没有改动",
|
|
1379
|
+
"mcp_removed": "MCP 已移除",
|
|
1380
|
+
"mcp_absent": "没有 MCP 条目",
|
|
1381
|
+
"skill_installed": "技能已装好",
|
|
1382
|
+
"skill_updated": "技能已更新",
|
|
1383
|
+
"skill_unchanged": "技能已是最新",
|
|
1384
|
+
"skill_modified": "技能目录被改过,保留不动",
|
|
1385
|
+
"skill_foreign": "技能目录里已有别人的同名技能,没有改动",
|
|
1386
|
+
"skill_removed": "技能已移除",
|
|
1387
|
+
"skill_absent": "没有装技能",
|
|
1388
|
+
"skill_skipped": "技能没装上",
|
|
1389
|
+
"skill_fetch_failed": "从网站下载技能失败,只接上了 MCP;网络恢复后再运行一次就会补装",
|
|
1390
|
+
"restart_hint": "已打开的 Claude Code、Codex、WorkBuddy 要重新打开一次才会读到",
|
|
1391
|
+
"unknown_tool": "{{tool}} 不支持接入 MCP 和技能",
|
|
1392
|
+
"unknown_action": "不认识的操作 {{action}},可以用 install、remove、status",
|
|
1393
|
+
"bad_key": "令牌格式不对,应以 sk- 开头",
|
|
1394
|
+
"no_key": "还没有保存令牌",
|
|
1395
|
+
"none_installed": "这台电脑上没有找到 Claude Code、Codex、DeepSeek Harness 或 WorkBuddy",
|
|
1396
|
+
"status_on": "已接入",
|
|
1397
|
+
"status_off": "未接入",
|
|
1398
|
+
"status_not_installed": "未安装"
|
|
1349
1399
|
}
|
|
1350
1400
|
}
|