codex-copilot-dx 1.2.32 → 1.3.0
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/README.md +65 -113
- package/bin/cli.mjs +61 -103
- package/docs/ARCHITECTURE.md +51 -3
- package/docs/README.md +9 -76
- package/docs/REFERENCE.md +137 -1827
- package/package.json +11 -4
- package/src/access-settings.mjs +2 -2
- package/src/adapter.mjs +1 -1
- package/src/auth-credentials.mjs +1 -1
- package/src/auto-review-model.mjs +2 -2
- package/src/cli-animation.mjs +2 -2
- package/src/cli-auth.mjs +3 -3
- package/src/cli-cache.mjs +2 -2
- package/src/cli-command-spec.mjs +325 -0
- package/src/cli-image.mjs +4 -4
- package/src/cli-limits.mjs +2 -2
- package/src/cli-m365.mjs +1 -1
- package/src/cli-management.mjs +344 -0
- package/src/cli-options.mjs +73 -443
- package/src/cli-status.mjs +7 -7
- package/src/cli-tools.mjs +3 -2
- package/src/client-integration.mjs +7 -3
- package/src/config.mjs +4 -3
- package/src/connection-runtime.mjs +1414 -350
- package/src/copilot-token-session.mjs +1 -1
- package/src/dashboard/connections.js +23 -4
- package/src/dashboard/ui.css +9 -2
- package/src/dashboard-api.mjs +5 -5
- package/src/doctor.mjs +4 -4
- package/src/image-mcp.mjs +2 -2
- package/src/native-prediction-fix.mjs +1 -1
- package/src/native-prediction-profile.mjs +1 -1
- package/src/native-prediction-windows.mjs +1 -1
- package/src/native-prediction.mjs +6 -6
- package/src/nightly-update.mjs +2 -2
- package/src/provider-runtime.mjs +1 -1
- package/src/providers/m365-accounts.mjs +1 -1
- package/src/release-install.mjs +11 -15
- package/src/service-control.mjs +1 -1
- package/src/settings-preferences.mjs +6 -4
- package/src/startup-ui.mjs +34 -2
- package/src/terminal-console.mjs +32 -30
- package/src/terminal-state.mjs +69 -0
- package/src/usage.mjs +5 -5
- package/src/windows-command.mjs +2 -2
- package/bin/codex-copilot-dx.mjs +0 -11
- package/src/cli-models.mjs +0 -94
- package/src/legacy-command-warning.mjs +0 -38
package/src/cli-options.mjs
CHANGED
|
@@ -1,357 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseManagedCommand, managedCommandHelp, rootCommandHelp } from "./cli-command-spec.mjs";
|
|
2
2
|
import { MAX_TIMER_DELAY_MS } from "./runtime-config.mjs";
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"--
|
|
13
|
-
"--
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"cache",
|
|
28
|
-
"limits",
|
|
29
|
-
"animation",
|
|
30
|
-
"enable-image",
|
|
31
|
-
"disable-image",
|
|
32
|
-
"image-status",
|
|
33
|
-
"auto-review-model",
|
|
34
|
-
"suggestion",
|
|
35
|
-
"prediction",
|
|
36
|
-
"m365",
|
|
37
|
-
"update",
|
|
38
|
-
"version",
|
|
39
|
-
]);
|
|
40
|
-
|
|
41
|
-
function unexpectedArgs(args) {
|
|
42
|
-
throw new Error(`Unexpected argument${args.length === 1 ? "" : "s"}: ${args.join(" ")}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function parseOptions(args, schema) {
|
|
46
|
-
const parsed = {};
|
|
47
|
-
const seen = new Set();
|
|
48
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
49
|
-
const option = args[index];
|
|
50
|
-
const kind = schema.get(option);
|
|
51
|
-
if (!kind || seen.has(option)) unexpectedArgs([option]);
|
|
52
|
-
seen.add(option);
|
|
53
|
-
if (kind === "flag") {
|
|
54
|
-
parsed[option] = true;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const value = args[index + 1];
|
|
59
|
-
if (value === undefined || !String(value).trim() || String(value).startsWith("-")) {
|
|
60
|
-
throw new Error(`Enter a value for ${option}`);
|
|
61
|
-
}
|
|
62
|
-
parsed[option] = value;
|
|
63
|
-
index += 1;
|
|
64
|
-
}
|
|
65
|
-
return parsed;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function checkedOutputFormat(value) {
|
|
69
|
-
const format = value || "";
|
|
70
|
-
if (!new Set(["table", "plain"]).has(format)) {
|
|
71
|
-
throw new Error(`Format must be table or plain: ${value}`);
|
|
72
|
-
}
|
|
73
|
-
return format;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function outputFormatOption(value) {
|
|
77
|
-
return value ? { outputFormat: checkedOutputFormat(value) } : {};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function baseCommand(command, extra = {}) {
|
|
81
|
-
return {
|
|
82
|
-
command,
|
|
83
|
-
showRequestId: false,
|
|
84
|
-
online: false,
|
|
85
|
-
compat: false,
|
|
86
|
-
...extra,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function checkedHelpTopic(parts = []) {
|
|
91
|
-
const normalized = parts.map((part, index) => {
|
|
92
|
-
return part;
|
|
93
|
-
}).join(" ");
|
|
94
|
-
if (!HELP_TOPICS.has(normalized)) throw new Error(`Unknown help topic: ${parts.join(" ")}`);
|
|
95
|
-
return normalized;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function helpCommand(parts = []) {
|
|
99
|
-
return baseCommand("help", { helpTopic: checkedHelpTopic(parts) });
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function nestedHelp(command, rest) {
|
|
103
|
-
if (!rest.length || !HELP_COMMANDS.has(rest.at(-1))) return null;
|
|
104
|
-
const args = rest.slice(0, -1);
|
|
105
|
-
if (command === "auth") {
|
|
106
|
-
if (args.length > 1) unexpectedArgs(args.slice(1));
|
|
107
|
-
return helpCommand(["auth", ...args]);
|
|
108
|
-
}
|
|
109
|
-
if (args.length) unexpectedArgs(args);
|
|
110
|
-
return helpCommand([command]);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function parseStartOptions(args) {
|
|
114
|
-
if (args.some((option) => RETIRED_CLAUDE_OPTIONS.has(option))) {
|
|
115
|
-
return baseCommand("retired", { integration: "Claude App and Claude Code" });
|
|
116
|
-
}
|
|
117
|
-
const seen = new Set();
|
|
118
|
-
for (const option of args) {
|
|
119
|
-
const kind = START_OPTIONS.get(option);
|
|
120
|
-
if (!kind || seen.has(kind)) unexpectedArgs([option]);
|
|
121
|
-
seen.add(kind);
|
|
122
|
-
}
|
|
123
|
-
return baseCommand("start", {
|
|
124
|
-
showRequestId: seen.has("show-request-id"),
|
|
125
|
-
...(seen.has("no-browser") ? { noBrowser: true } : {}),
|
|
126
|
-
...(seen.has("verbose") ? { verbose: true } : {}),
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function parseCliArgs(args = []) {
|
|
131
|
-
const [command, ...rest] = args;
|
|
132
|
-
if (!command) return baseCommand("start");
|
|
133
|
-
if (command === "reauth") return parseCliArgs(["auth", "reauth", ...rest]);
|
|
134
|
-
if (command === "source") { if (rest.length === 1 && HELP_COMMANDS.has(rest[0])) return helpCommand(["source"]);return parseCliArgs(["m365", "switch", ...rest]); }
|
|
135
|
-
if (command === "web") { if (rest.length === 1 && HELP_COMMANDS.has(rest[0])) return helpCommand(["web"]);if (rest.length) unexpectedArgs(rest);return baseCommand("web"); }
|
|
136
|
-
if (command === "image") {
|
|
137
|
-
if (rest.length === 1 && HELP_COMMANDS.has(rest[0])) return helpCommand(["image"]);
|
|
138
|
-
const [action = "status", ...extra] = rest;
|
|
139
|
-
if (!["status", "pause", "resume"].includes(action)) throw new Error("Choose image status, pause or resume.");
|
|
140
|
-
if (extra.length) unexpectedArgs(extra);
|
|
141
|
-
return baseCommand("image", { action });
|
|
142
|
-
}
|
|
143
|
-
if (command === "doctor" && ["network", "report"].includes(rest[0]) && rest.length === 2 && HELP_COMMANDS.has(rest[1])) return helpCommand(["doctor", rest[0]]);
|
|
144
|
-
if (HELP_COMMANDS.has(command)) {
|
|
145
|
-
const topic = rest;
|
|
146
|
-
if (topic.length > 2) unexpectedArgs(topic.slice(2));
|
|
147
|
-
return helpCommand(topic);
|
|
148
|
-
}
|
|
149
|
-
const profileOptionIndex = rest.indexOf("--profile");
|
|
150
|
-
const requestedProfile = profileOptionIndex >= 0 ? rest[profileOptionIndex + 1] : "";
|
|
151
|
-
const retiredClaudeInvocation = RETIRED_CLAUDE_OPTIONS.has(command)
|
|
152
|
-
|| (command === "start" && rest.some((option) => RETIRED_CLAUDE_OPTIONS.has(option)))
|
|
153
|
-
|| (command === "auth" && rest[0] === "login" && rest[1] === "claude")
|
|
154
|
-
|| (command === "models" && requestedProfile === "claude")
|
|
155
|
-
|| (command === "doctor" && rest[0] !== "config" && ["claude", "all"].includes(requestedProfile));
|
|
156
|
-
if (PM_COMMANDS.has(command)) return baseCommand("retired", { integration: "PM Studio" });
|
|
157
|
-
if (retiredClaudeInvocation) {
|
|
158
|
-
return baseCommand("retired", { integration: "Claude App and Claude Code" });
|
|
159
|
-
}
|
|
160
|
-
if ((command === "doctor" || command === "--doctor") && rest[0] === "config") {
|
|
161
|
-
if (rest.length === 2 && HELP_COMMANDS.has(rest[1])) return helpCommand(["doctor", "config"]);
|
|
162
|
-
if (rest.length > 1) unexpectedArgs(rest.slice(1));
|
|
163
|
-
return baseCommand("doctor", { configOnly: true });
|
|
164
|
-
}
|
|
165
|
-
const requestedHelp = nestedHelp(command, rest);
|
|
166
|
-
if (requestedHelp) return requestedHelp;
|
|
167
|
-
if (VERSION_COMMANDS.has(command)) {
|
|
168
|
-
if (rest.length) unexpectedArgs(rest);
|
|
169
|
-
return baseCommand("version");
|
|
170
|
-
}
|
|
171
|
-
if (command === "start") return parseStartOptions(rest);
|
|
172
|
-
if (command === "m365") {
|
|
173
|
-
const [action = "status", ...args] = rest;
|
|
174
|
-
if (!["status", "models", "switch", "on", "off", "remove", "accounts", "account"].includes(action)) throw new Error("Choose status, models, accounts, account, switch, on, off or remove");
|
|
175
|
-
let provider, remaining = args;
|
|
176
|
-
if (action === "switch" && args[0] && !args[0].startsWith("--")) { provider = args[0];remaining = args.slice(1); }
|
|
177
|
-
if (provider && !["github", "m365"].includes(provider) && !/^api_[a-z0-9_-]{1,60}$/.test(provider)) throw new Error("Choose github, m365 or a listed API source ID");
|
|
178
|
-
const values = parseOptions(remaining, new Map(action === "switch" ? [["--model", "value"], ["--auto-review-model", "value"]] : action === "account" ? [["--id", "value"]] : []));
|
|
179
|
-
if (values["--id"] && !/^[a-f0-9]{64}$/.test(values["--id"])) throw new Error("Use an account ID from ccdx m365 accounts");
|
|
180
|
-
return baseCommand("m365", { action, provider, model: values["--model"], autoReviewModel: values["--auto-review-model"], ...(values["--id"] ? { accountId: values["--id"] } : {}) });
|
|
181
|
-
}
|
|
182
|
-
if (command === "status" || command === "--status") {
|
|
183
|
-
if (rest.length) unexpectedArgs(rest);
|
|
184
|
-
return baseCommand("status");
|
|
185
|
-
}
|
|
186
|
-
if (command === "usage") {
|
|
187
|
-
const options = parseOptions(rest, new Map([["--format", "value"], ["--provider", "value"]]));
|
|
188
|
-
if (options["--provider"] && !isProviderId(options["--provider"])) throw new Error("Enter a valid source ID.");
|
|
189
|
-
return baseCommand("usage", { ...outputFormatOption(options["--format"]), ...(options["--provider"] ? { provider: options["--provider"] } : {}) });
|
|
190
|
-
}
|
|
191
|
-
if (command === "cache") {
|
|
192
|
-
let cacheArgs = rest;
|
|
193
|
-
if (rest.length === 1 && /^-\d+$/.test(rest[0])) {
|
|
194
|
-
cacheArgs = ["--limit", rest[0].slice(1)];
|
|
195
|
-
} else if (rest[0] === "-clean") {
|
|
196
|
-
cacheArgs = ["--clean", ...rest.slice(1)];
|
|
197
|
-
}
|
|
198
|
-
const options = parseOptions(cacheArgs, new Map([
|
|
199
|
-
["--limit", "value"],
|
|
200
|
-
["--clean", "flag"],
|
|
201
|
-
["--history", "flag"],
|
|
202
|
-
["--yes", "flag"],
|
|
203
|
-
]));
|
|
204
|
-
if (options["--limit"] && options["--clean"]) {
|
|
205
|
-
throw new Error("Use either --limit or --clean.");
|
|
206
|
-
}
|
|
207
|
-
if ((options["--history"] || options["--yes"]) && !options["--clean"]) {
|
|
208
|
-
throw new Error("--history and --yes require --clean");
|
|
209
|
-
}
|
|
210
|
-
const rawLimit = options["--limit"];
|
|
211
|
-
if (rawLimit && rawLimit !== "default" && !/^\d+$/.test(rawLimit)) {
|
|
212
|
-
throw new Error(`Cache limit must be an integer MiB value or default: ${rawLimit}`);
|
|
213
|
-
}
|
|
214
|
-
return baseCommand("cache", {
|
|
215
|
-
action: rawLimit ? "limit" : options["--clean"] ? "clean" : "status",
|
|
216
|
-
limitMib: rawLimit && rawLimit !== "default" ? Number(rawLimit) : undefined,
|
|
217
|
-
resetLimit: rawLimit === "default",
|
|
218
|
-
history: Boolean(options["--history"]),
|
|
219
|
-
yes: Boolean(options["--yes"]),
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
if (command === "limits") {
|
|
223
|
-
const limitArgs = rest.length === 1 && /^-\d+$/.test(rest[0])
|
|
224
|
-
? ["--decoded", rest[0].slice(1)]
|
|
225
|
-
: rest;
|
|
226
|
-
const options = parseOptions(limitArgs, new Map([["--decoded", "value"]]));
|
|
227
|
-
const rawLimit = options["--decoded"];
|
|
228
|
-
if (rawLimit && rawLimit !== "default" && !/^\d+$/.test(rawLimit)) {
|
|
229
|
-
throw new Error(`Decoded request-body limit must be an integer MiB value or default: ${rawLimit}`);
|
|
230
|
-
}
|
|
231
|
-
return baseCommand("limits", {
|
|
232
|
-
action: rawLimit ? "set" : "status",
|
|
233
|
-
limitMib: rawLimit && rawLimit !== "default" ? Number(rawLimit) : undefined,
|
|
234
|
-
resetLimit: rawLimit === "default",
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
if (PM_COMMANDS.has(command)) {
|
|
238
|
-
return baseCommand("retired", { integration: "PM Studio" });
|
|
239
|
-
}
|
|
240
|
-
if (command === "models") {
|
|
241
|
-
const options = parseOptions(rest, new Map([
|
|
242
|
-
["--profile", "value"],
|
|
243
|
-
["--format", "value"],
|
|
244
|
-
]));
|
|
245
|
-
const profile = options["--profile"];
|
|
246
|
-
if (profile === "claude") {
|
|
247
|
-
return baseCommand("retired", { integration: "Claude App and Claude Code" });
|
|
248
|
-
}
|
|
249
|
-
if (profile && profile !== "codex") throw new Error(`Profile must be codex: ${profile}`);
|
|
250
|
-
return {
|
|
251
|
-
...baseCommand("models"),
|
|
252
|
-
...outputFormatOption(options["--format"]),
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
if (command === "auth") {
|
|
256
|
-
const [action = "status", ...authArgs] = rest;
|
|
257
|
-
if (["login", "reauth", "check", "logout"].includes(action)) {
|
|
258
|
-
const values = authArgs[0] === "github" || authArgs[0] === "codex" ? authArgs.slice(1) : authArgs;
|
|
259
|
-
const options = parseOptions(values, new Map(action === "logout" ? [["--yes", "flag"]]
|
|
260
|
-
: action === "check" ? [["--format", "value"]] : [["--login", "value"], ["--reauth", "flag"]]));
|
|
261
|
-
if (options["--login"] && !/^[a-z\d_-]{1,39}$/i.test(options["--login"])) throw new Error("Enter a GitHub account name.");
|
|
262
|
-
return baseCommand("auth", { action, ...(options["--yes"] ? { yes: true } : {}),
|
|
263
|
-
...(options["--reauth"] ? { reauth: true } : {}), ...(options["--login"] ? { expectedLogin: options["--login"] } : {}),
|
|
264
|
-
...(options["--format"] ? outputFormatOption(options["--format"]) : {}) });
|
|
265
|
-
}
|
|
266
|
-
if (action === "status") {
|
|
267
|
-
const options = parseOptions(authArgs, new Map([
|
|
268
|
-
["--online", "flag"],
|
|
269
|
-
["--format", "value"],
|
|
270
|
-
]));
|
|
271
|
-
return {
|
|
272
|
-
...baseCommand("auth"),
|
|
273
|
-
action: "status",
|
|
274
|
-
profile: "",
|
|
275
|
-
online: Boolean(options["--online"]),
|
|
276
|
-
expectedLogin: "",
|
|
277
|
-
reauth: false,
|
|
278
|
-
...outputFormatOption(options["--format"]),
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
throw new Error(`Unknown auth action: ${action}`);
|
|
282
|
-
}
|
|
283
|
-
if (command === "animation") {
|
|
284
|
-
if (rest.length) unexpectedArgs(rest);
|
|
285
|
-
return baseCommand("animation");
|
|
286
|
-
}
|
|
287
|
-
if (command === "prediction") {
|
|
288
|
-
const [action = "status", ...extra] = rest;
|
|
289
|
-
if (!["on", "off", "status", "fix", "pause", "resume"].includes(action)) throw new Error("Choose prediction on, off, status, fix, pause or resume.");
|
|
290
|
-
if (extra.length) unexpectedArgs(extra);
|
|
291
|
-
return baseCommand("prediction", { action });
|
|
292
|
-
}
|
|
293
|
-
if (command === "suggestion") {
|
|
294
|
-
const [action = "status", model, ...extra] = rest;
|
|
295
|
-
if (!["on", "off", "model", "status"].includes(action)) throw new Error("Suggestion action must be on, off, model, or status");
|
|
296
|
-
if (extra.length || (model !== undefined && action !== "model")) unexpectedArgs(rest.slice(1));
|
|
297
|
-
if (["on", "model"].includes(action)) throw new Error("The CCDX prediction panel has been retired; use ccdx prediction for the separate optional native feature");
|
|
298
|
-
return baseCommand("suggestion", { action });
|
|
299
|
-
}
|
|
300
|
-
if (command === "enable-image" || command === "disable-image" || command === "image-status") {
|
|
301
|
-
if (rest.length) unexpectedArgs(rest);
|
|
302
|
-
return baseCommand("image", {
|
|
303
|
-
action: command === "enable-image" ? "enable" : command === "disable-image" ? "disable" : "status",
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
if (command === "auto-review-model") {
|
|
307
|
-
if (rest.length) unexpectedArgs(rest);
|
|
308
|
-
return baseCommand("auto-review-model");
|
|
309
|
-
}
|
|
310
|
-
if (command === "update") {
|
|
311
|
-
const permission = rest.filter(value => value === "--allow-remote");
|
|
312
|
-
if (permission.length > 1) throw new Error("--allow-remote may be specified only once");
|
|
313
|
-
const sources = rest.filter(value => value !== "--allow-remote");
|
|
314
|
-
if (sources.length > 1) unexpectedArgs(sources.slice(1));
|
|
315
|
-
const source = sources[0];
|
|
316
|
-
if (source && !new Set(["npm", "github", "gh"]).has(source)) {
|
|
317
|
-
throw new Error(`Choose npm or github. Received: ${source}`);
|
|
318
|
-
}
|
|
319
|
-
return {
|
|
320
|
-
...baseCommand("update"),
|
|
321
|
-
updateSource: source === "gh" ? "github" : source,
|
|
322
|
-
allowRemote: permission.length === 1,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
if (command === "doctor" || command === "--doctor") {
|
|
326
|
-
if (["network", "report"].includes(rest[0])) {
|
|
327
|
-
if (rest.length > 1) unexpectedArgs(rest.slice(1));
|
|
328
|
-
return baseCommand("doctor", { tool: rest[0] });
|
|
329
|
-
}
|
|
330
|
-
const options = parseOptions(rest, new Map([
|
|
331
|
-
["--online", "flag"],
|
|
332
|
-
["--compat", "flag"],
|
|
333
|
-
["--fix", "flag"],
|
|
334
|
-
["--json", "flag"],
|
|
335
|
-
["--profile", "value"],
|
|
336
|
-
]));
|
|
337
|
-
const profile = options["--profile"];
|
|
338
|
-
if (profile === "claude" || profile === "all") {
|
|
339
|
-
return baseCommand("retired", { integration: "Claude App and Claude Code" });
|
|
340
|
-
}
|
|
341
|
-
if (profile && profile !== "codex") throw new Error(`Profile must be codex: ${profile}`);
|
|
342
|
-
return {
|
|
343
|
-
...baseCommand("doctor"),
|
|
344
|
-
online: Boolean(options["--online"]),
|
|
345
|
-
compat: Boolean(options["--compat"]),
|
|
346
|
-
...(options["--fix"] ? { fix: true } : {}),
|
|
347
|
-
...(options["--json"] ? { json: true } : {}),
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
if (RETIRED_CLAUDE_OPTIONS.has(command)) {
|
|
351
|
-
return baseCommand("retired", { integration: "Claude App and Claude Code" });
|
|
352
|
-
}
|
|
353
|
-
if (START_OPTIONS.has(command)) return parseStartOptions([command, ...rest]);
|
|
354
|
-
throw new Error(`Unknown command or option: ${command}`);
|
|
4
|
+
const base = value => ({ command: "manage", showRequestId: false, online: false, compat: false, ...value });
|
|
5
|
+
export function parseCliArgs(input = []) {
|
|
6
|
+
let args = [...input];
|
|
7
|
+
if (
|
|
8
|
+
!args.length ||
|
|
9
|
+
(args[0].startsWith("--") && ["--no-browser", "--verbose", "--show-request-id"].includes(args[0]))
|
|
10
|
+
)
|
|
11
|
+
args.unshift("start");
|
|
12
|
+
if (["--version", "-v"].includes(args[0])) args[0] = "version";
|
|
13
|
+
const help = ["help", "--help", "-h"].includes(args[0])
|
|
14
|
+
? args.slice(1)
|
|
15
|
+
: ["--help", "-h"].includes(args.at(-1))
|
|
16
|
+
? args.slice(0, -1)
|
|
17
|
+
: null;
|
|
18
|
+
if (help) {
|
|
19
|
+
if (help.length && managedCommandHelp(help) === null)
|
|
20
|
+
throw new Error(`Unknown help topic: ${help.join(" ")}`);
|
|
21
|
+
return base({ command: "help", helpTopic: help.join(" ") });
|
|
22
|
+
}
|
|
23
|
+
if (["app", "config", "source"].includes(args[0]) && args.length === 1)
|
|
24
|
+
return base({ command: "help", helpTopic: args[0] });
|
|
25
|
+
const parsed = parseManagedCommand(args);
|
|
26
|
+
return base(parsed.dispatch || parsed);
|
|
355
27
|
}
|
|
356
28
|
|
|
357
29
|
function integerEnv(env, name, fallback, { min, max = Number.MAX_SAFE_INTEGER }) {
|
|
@@ -376,12 +48,30 @@ export function parseAdapterAddressOptions(env = process.env) {
|
|
|
376
48
|
export function parseRuntimeOptions(env = process.env) {
|
|
377
49
|
return {
|
|
378
50
|
...parseAdapterAddressOptions(env),
|
|
379
|
-
modelRefreshTimeoutMs: integerEnv(env, "CCDX_MODEL_REFRESH_TIMEOUT_MS", 5000, {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
51
|
+
modelRefreshTimeoutMs: integerEnv(env, "CCDX_MODEL_REFRESH_TIMEOUT_MS", 5000, {
|
|
52
|
+
min: 1,
|
|
53
|
+
max: MAX_TIMER_DELAY_MS,
|
|
54
|
+
}),
|
|
55
|
+
existingAdapterTimeoutMs: integerEnv(env, "CCDX_EXISTING_ADAPTER_TIMEOUT_MS", 500, {
|
|
56
|
+
min: 1,
|
|
57
|
+
max: MAX_TIMER_DELAY_MS,
|
|
58
|
+
}),
|
|
59
|
+
modelRefreshIntervalMs: integerEnv(env, "CCDX_MODEL_REFRESH_INTERVAL_MS", 2 * 60 * 60 * 1000, {
|
|
60
|
+
min: 0,
|
|
61
|
+
max: MAX_TIMER_DELAY_MS,
|
|
62
|
+
}),
|
|
63
|
+
upstreamTimeoutMs: integerEnv(env, "CCDX_UPSTREAM_TIMEOUT_MS", 120000, {
|
|
64
|
+
min: 1,
|
|
65
|
+
max: MAX_TIMER_DELAY_MS,
|
|
66
|
+
}),
|
|
67
|
+
streamHandshakeTimeoutMs: integerEnv(env, "CCDX_STREAM_HANDSHAKE_TIMEOUT_MS", 120000, {
|
|
68
|
+
min: 1,
|
|
69
|
+
max: MAX_TIMER_DELAY_MS,
|
|
70
|
+
}),
|
|
71
|
+
streamIdleTimeoutMs: integerEnv(env, "CCDX_STREAM_IDLE_TIMEOUT_MS", 120000, {
|
|
72
|
+
min: 1,
|
|
73
|
+
max: MAX_TIMER_DELAY_MS,
|
|
74
|
+
}),
|
|
385
75
|
shutdownTimeoutMs: integerEnv(env, "CCDX_SHUTDOWN_TIMEOUT_MS", 5000, { min: 1, max: MAX_TIMER_DELAY_MS }),
|
|
386
76
|
};
|
|
387
77
|
}
|
|
@@ -389,7 +79,10 @@ export function parseRuntimeOptions(env = process.env) {
|
|
|
389
79
|
export function parseAdapterProbeOptions(env = process.env) {
|
|
390
80
|
return {
|
|
391
81
|
...parseAdapterAddressOptions(env),
|
|
392
|
-
existingAdapterTimeoutMs: integerEnv(env, "CCDX_EXISTING_ADAPTER_TIMEOUT_MS", 500, {
|
|
82
|
+
existingAdapterTimeoutMs: integerEnv(env, "CCDX_EXISTING_ADAPTER_TIMEOUT_MS", 500, {
|
|
83
|
+
min: 1,
|
|
84
|
+
max: MAX_TIMER_DELAY_MS,
|
|
85
|
+
}),
|
|
393
86
|
};
|
|
394
87
|
}
|
|
395
88
|
|
|
@@ -397,89 +90,26 @@ export function cliCommandName() {
|
|
|
397
90
|
return "ccdx";
|
|
398
91
|
}
|
|
399
92
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
"
|
|
409
|
-
|
|
410
|
-
"auth status": `Usage:\n ${name} auth status [--online] [--format table|plain]\n\n- Shows the saved GitHub Copilot account without exposing credentials.\n- --online also verifies its entitlement and model catalog.\n- Interactive terminals use a table by default.`,
|
|
411
|
-
doctor: `Usage:\n ${name} doctor [--online] [--compat] [--fix] [--json]\n ${name} doctor config\n\n- Checks credentials, managed configuration, command launchers, adapter, enabled optional features and observed client catalog.\n- Default is read-only; no inference requests.\n- --online validates account entitlement; --compat sends minimal inference requests and consumes a small amount of Copilot usage, requiring successful model completion rather than HTTP 200 alone.\n- --fix repairs owned Windows launchers and managed config, imports a verified existing credential only if none is saved, and asks the running adapter to repair enabled predictions once.\n- No interactive login, client program edits, forced App restarts, policy changes or optional feature activation.\n- Missing-credential repair can contact GitHub without --online.\n- Changed existing config is backed up to config.toml.ccdx-doctor.bak.\n- Partial repairs exit 1.\n- --json emits a redacted report, including before_checks for repairs.\n- App-internal cache and visible predictions are not externally verified.\n- The config subcommand remains strictly read-only.`,
|
|
412
|
-
"doctor config": `Usage:\n ${name} doctor config\n\n- Reads ~/.codex/config.toml, checks TOML syntax and CCDX-managed settings, and previews the existing startup writer's changes.\n- Does not merge Codex profiles or validate the complete installed Codex schema.\n- No authentication, network requests, file writes, or adapter/GUI startup.\n- Existing context_management=false is valid.\n- Exit 1 for errors, 0 for OK/warnings; unsupported arguments exit 2.`,
|
|
413
|
-
status: `Usage:\n ${name} status\n\n- Shows bounded runtime, routing, performance, queue, and cache metrics from a running adapter.`,
|
|
414
|
-
models: `Usage:\n ${name} models [--format table|plain]\n\n- Shows GPT models for the selected Codex provider.\n- GitHub performs a fresh read-only lookup; M365 uses its isolated catalog in the running service.\n- Interactive terminals use a table by default.`,
|
|
415
|
-
usage: `Usage:\n ${name} usage [--format table|plain] [--provider ID]\n\n- Summarizes local token usage metadata without reading prompt or completion content.\n- Optional provider filtering separates sources; default totals include all recorded sources.\n- Interactive terminals use a table by default.`,
|
|
416
|
-
cache: `Usage:\n ${name} cache\n ${name} cache --limit <MiB|default>\n ${name} cache --clean [--history] [--yes]\n\n- Shows runtime cache use, saves and applies the shared response-history limit, or clears the rebuildable image-transform cache.\n- --history also clears in-memory response history for all tasks and can make their next continuation fail, so interactive confirmation or --yes is required.\n- Generated image files and saved Codex transcripts are never deleted.\n- Short aliases: -128 sets 128 MiB and -clean equals --clean.`,
|
|
417
|
-
limits: `Usage:\n ${name} limits\n ${name} limits --decoded <MiB|default>\n\n- Shows configured and running request-body limits, or saves a decoded request-body limit from 128 to 512 MiB.\n- The raw-body limit is unchanged.\n- Restart ccdx to apply a saved change; no conversation or cache is cleared.\n- Short alias: -256 sets 256 MiB.`,
|
|
418
|
-
animation: `Usage:\n ${name} animation\n\n- Previews all terminal activity animations together and selects the saved theme.\n- Running CCDX 1.1.0+ applies it live; older services need a restart.`,
|
|
419
|
-
"enable-image": `Usage:\n ${name} enable-image\n\n- Interactively configures an HTTPS image API endpoint (base URLs are also accepted) and API key, detects its supported image model and protocol, installs CCDX image guidance, and checks the local image tool for Codex App without generating an image.\n- A blank key preserves the saved key only for the same origin; a new origin requires explicit key entry.\n- Concurrent unrelated config edits are preserved.`,
|
|
420
|
-
"disable-image": `Usage:\n ${name} disable-image\n\n- Disables the local CCDX image tool and removes its stored API credential and unmodified CCDX image guidance.`,
|
|
421
|
-
"image-status": `Usage:\n ${name} image-status\n\n- Shows provider configuration and locally advertised generation/editing tools without generating an image or exposing its API key.`,
|
|
422
|
-
"auto-review-model": `Usage:\n ${name} auto-review-model\n\n- Select a Responses model, then an advertised reasoning effort.\n- Enter keeps the default/current choice; q cancels both steps without saving.\n- Effort 0 follows the client (low when omitted).\n- Settings apply only to Auto-review on the next request; no client patch or restart is required for adapters running 0.9.13 or newer.`,
|
|
423
|
-
"suggestion": `The CCDX prediction panel has been retired. Run ${name} suggestion off to safely remove unchanged CCDX registrations. This cleanup does not change native predictions; see ${name} prediction --help for that separate opt-in feature.`,
|
|
424
|
-
m365: `Usage:\n ${name} m365 [status|models|accounts|account|on|off|remove]\n ${name} m365 account [--id ID]\n ${name} m365 switch [github|m365] [--model ID] [--auto-review-model ID]\n\n- M365 is discovered silently at startup on supported managed environments.\n- accounts lists local company accounts without requesting tokens.\n- account chooses a company account; --id supports scripts. A running updated service is required.\n- Saved bindings stay selected. Otherwise an exact Windows sign-in match, then a single company account, is used.\n- Changing accounts applies to M365 in Codex and Claude; start a new conversation.\n- Claude uses /anthropic on the same local port.\n- Codex stays on GitHub unless you explicitly switch.\n- M365 switching requires a running compatible adapter and available GPT/Auto-review choices; it never substitutes unavailable models.\n- Select an available model in Codex after switching an existing thread.\n- Off restores only owned Claude settings and selects GitHub.\n- Remove also clears the CCDX M365 profile, retaining a disabled preference and historical usage.\n- System Microsoft sign-in, GitHub credentials, predictions and images are preserved.`,
|
|
425
|
-
prediction: `Usage:\n ${name} prediction [status|on|off|fix|pause|resume]\n\n- Pause/resume only pauses adaptation; trust and route setup are kept.\n- Resume does not activate a feature that has not been set up.\n- Optional native next-message predictions; off by default. macOS and Windows.\n- Windows requires the registered official MSIX App, an initialized profile, Windows PowerShell and .NET Framework 4.7.2+; Git/OpenSSL is not required for prediction setup.\n- Quit Codex before on/off, then restart ccdx.\n- On adds private App-profile certificate trust and an App-only route for chatgpt.com and ab.chatgpt.com.\n- HTTPS on those hosts is decrypted locally; only prediction configuration is changed.\n- No client program files, OS trust, account permissions, MCP or Hooks are changed.\n- Static HTTP/HTTPS/SOCKS5 proxies and bypass rules are preserved.\n- Windows supports company PAC/WPAD; macOS dynamic PAC/WPAD remains unsupported.\n- Static IPv4/IPv6 CIDRs match URL IP literals without DNS.\n- The bridge port persists across restarts/updates; a busy saved port disables only predictions.\n- Launch/reuse checks the App's actual route; an older random or missing route may require one full App quit.\n- Official prediction configuration is preserved; the conversation's model is used.\n- App updates require another compatibility check.\n- Status distinguishes saved preference and observed config traffic from unverified candidate visibility.\n- Fix asks a compatible running CCDX adapter to repair the enabled bridge once on its saved port.\n- It never enables predictions, renews certificates or force-restarts Codex.\n- Healthy unchanged bridges are retained.\n- Fix rechecks system proxy settings.\n- Changed routes may need a normal App relaunch to reload cached PAC; failed rechecks preserve the previous bridge with a nonzero exit.\n- Process environment variables and Node trust are not hot-reloaded; changed trust inputs need a CCDX service restart.\n- Startup, status and doctor share sanitized environment diagnostics.\n- Missing App routes require a normal full quit and ccdx launch; partial repair exits 1.\n- An older adapter must first be upgraded and restarted once to gain this repair endpoint.`,
|
|
426
|
-
update: `Usage:\n ${name} update [npm|github] [--allow-remote]\n\n- Updates the global package from the configured npm registry or the latest stable GitHub release.\n- With no source, an interactive terminal prompts for one.\n- Windows uses system cmd.exe to run npm.cmd without changing PowerShell policy; use the .cmd entrypoint if scripts are blocked.\n- GitHub verifies a Release tarball; Git is not required. Dependencies use the configured npm registry.\n- By default npm's remote-download policy is preserved.\n- If npm reports EALLOWREMOTE for a trusted mirror tarball, --allow-remote explicitly permits URL dependencies for this one installation's entire dependency tree; it is not a hostname allowlist.\n- No .npmrc, registry or persistent policy is changed. GitHub updates retry once offline with a verified same-version platform package only after EALLOWREMOTE; other errors are not retried.\n- Use this only if company policy permits it.\n- Restart the running adapter after installation.`,
|
|
427
|
-
version: `Usage:\n ${name} --version`,
|
|
428
|
-
};
|
|
429
|
-
return sections[topic];
|
|
430
|
-
}
|
|
431
|
-
|
|
93
|
+
const integrationNotes = {
|
|
94
|
+
prediction:
|
|
95
|
+
"Optional native suggestions are off by default. Windows requires the initialized official MSIX App profile, Windows PowerShell and .NET Framework 4.7.2+; Git/OpenSSL is not required. The bridge port persists across restarts/updates; a busy saved port disables predictions only. Setup/removal requires Codex to be closed, then a normal CCDX restart. HTTPS on chatgpt.com and ab.chatgpt.com is decrypted locally; only prediction configuration is changed. App-profile trust and routing are used; no OS trust or client program files are changed. Proxy/PAC policy is preserved. Repair never enables predictions or force-restarts Codex. Environment trust changes require a service restart.",
|
|
96
|
+
image:
|
|
97
|
+
"Setup configures the image API and private credential without generating an image. An empty key keeps the saved key only for the same origin. Pause keeps credentials; remove deletes the stored image credential and unchanged CCDX guidance.",
|
|
98
|
+
review:
|
|
99
|
+
"Select an available model and reasoning level. Enter keeps the choice; q cancels without saving. The next review request uses the saved choice.",
|
|
100
|
+
doctor:
|
|
101
|
+
"Default checks are read-only and do not send inference. --online checks access; --compat sends minimal inference and consumes usage. --fix changes only owned configuration and launchers, backs up changed config, and never enables optional features or force-restarts Apps. Missing-credential repair can contact GitHub. Partial repairs exit 1.",
|
|
102
|
+
};
|
|
432
103
|
export function cliHelp(commandName = "ccdx", topic = "") {
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
${name} web
|
|
445
|
-
${name} source [github|m365]
|
|
446
|
-
${name} image [status|pause|resume]
|
|
447
|
-
${name} status
|
|
448
|
-
${name} models [--format table|plain]
|
|
449
|
-
${name} usage [--format table|plain] [--provider ID]
|
|
450
|
-
${name} cache [--limit <MiB|default> | --clean [--history] [--yes]]
|
|
451
|
-
${name} limits [--decoded <MiB|default>]
|
|
452
|
-
${name} animation
|
|
453
|
-
${name} enable-image
|
|
454
|
-
${name} disable-image
|
|
455
|
-
${name} image-status
|
|
456
|
-
${name} auto-review-model
|
|
457
|
-
${name} prediction [status|on|off|fix|pause|resume]
|
|
458
|
-
${name} m365 [status|models|accounts|account|switch|on|off|remove]
|
|
459
|
-
${name} update [npm|github] [--allow-remote]
|
|
460
|
-
${name} --version
|
|
461
|
-
${name} --help
|
|
462
|
-
|
|
463
|
-
Commands:
|
|
464
|
-
start Start or reuse the adapter and configure Codex
|
|
465
|
-
auth Manage GitHub sign-in and check access
|
|
466
|
-
web Open local account and repair tools
|
|
467
|
-
source Choose a Codex model source
|
|
468
|
-
image Inspect, pause or resume image requests
|
|
469
|
-
doctor Diagnose local config; optional live and inference checks
|
|
470
|
-
status Show runtime routing, performance, queue, and cache health
|
|
471
|
-
models Show the selected Codex provider's GPT model catalog
|
|
472
|
-
usage Summarize locally recorded token usage
|
|
473
|
-
cache Inspect, size, or clear bounded runtime caches
|
|
474
|
-
limits Inspect or configure the decoded request-body limit
|
|
475
|
-
animation Select the terminal activity animation
|
|
476
|
-
enable-image Configure and enable the optional image provider
|
|
477
|
-
disable-image Disable the image provider and remove its credential
|
|
478
|
-
image-status Show the optional image provider status
|
|
479
|
-
auto-review-model Select the Codex Auto-review model and reasoning effort
|
|
480
|
-
prediction Toggle optional native next-message predictions
|
|
481
|
-
m365 Manage M365 Claude access and the optional Codex backup
|
|
482
|
-
update Update the global package from npm or GitHub
|
|
483
|
-
|
|
484
|
-
Run ${name} <command> --help for command details.`;
|
|
104
|
+
if (!topic) return rootCommandHelp();
|
|
105
|
+
const parts = topic.split(" "),
|
|
106
|
+
help = managedCommandHelp(parts);
|
|
107
|
+
if (help === null) throw new Error(`Unknown help topic: ${topic}`);
|
|
108
|
+
const feature =
|
|
109
|
+
parts[0] === "app" && parts[1] === "codex"
|
|
110
|
+
? parts[2]
|
|
111
|
+
: parts[0] === "doctor" && parts.length === 1
|
|
112
|
+
? "doctor"
|
|
113
|
+
: null;
|
|
114
|
+
return help + (integrationNotes[feature] ? "\n\n" + integrationNotes[feature] : "");
|
|
485
115
|
}
|
package/src/cli-status.mjs
CHANGED
|
@@ -134,7 +134,7 @@ export async function readAdapterStatus({
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
export function formatAdapterStatus({ baseUrl, data }, { commandName = "ccdx", cliVersion = data.version } = {}) {
|
|
137
|
+
export function formatAdapterStatus({ baseUrl, data }, { commandName = "ccdx", cliVersion = data.version, scoped = false } = {}) {
|
|
138
138
|
const requests = data.requests || {};
|
|
139
139
|
const performance = data.stream_performance?.by_route?.responses || {};
|
|
140
140
|
const terminalOutcomes = performance.terminal_outcomes?.totals;
|
|
@@ -154,7 +154,7 @@ export function formatAdapterStatus({ baseUrl, data }, { commandName = "ccdx", c
|
|
|
154
154
|
const lines = [
|
|
155
155
|
`${commandName} status`,
|
|
156
156
|
adapterLine,
|
|
157
|
-
status("info",
|
|
157
|
+
status("info", `${scoped ? "HTTP requests" : "Requests"}: ${count(requests.completed)}/${count(requests.total)} completed, ${count(requests.active)} active, ${count(requests.status_4xx)} 4xx, ${count(requests.status_5xx)} 5xx, ${count(requests.aborted)} aborted`),
|
|
158
158
|
status("info", `Responses stream: TTFT avg ${firstOutputLatency(performance.ttft_ms)} (${count(performance.ttft_ms?.samples)} samples), output avg ${outputRate(performance.output_tokens_per_second)} (${count(performance.output_tokens_per_second?.samples)} samples; gateway estimate)`),
|
|
159
159
|
...(terminalOutcomes ? [status("info", `Model outcomes: ${count(terminalOutcomes.completed)} completed, ${count(terminalOutcomes.incomplete)} incomplete, ${count(terminalOutcomes.failed)} failed, ${count(terminalOutcomes.cancelled)} cancelled, ${count(terminalOutcomes.unknown)} without terminal`)] : []),
|
|
160
160
|
status("info", `Admission: ${count(admission.activeRequests)} active, ${count(admission.queued)} queued, ${count(admission.rejected)} rejected, ${count(admission.timedOut)} timed out, wait avg ${latency(admission.waitMsAvg)}`),
|
|
@@ -205,19 +205,19 @@ export function formatAdapterStatus({ baseUrl, data }, { commandName = "ccdx", c
|
|
|
205
205
|
lines.push(status("warn", `HTTP ${count(failure.http_status)} ${terminalCell(failure.model)} ${terminalCell(failure.code)}${failure.reason ? ` reason=${terminalCell(failure.reason)}` : ""}${failure.parameter ? ` param=${terminalCell(failure.parameter)}` : ""}; ${terminalCell(failure.origin)}; ${count(failure.upstream_attempts)} attempts`));
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
lines.push(status("info",
|
|
208
|
+
lines.push(status("info", `${scoped ? "Codex models" : "Models"}: ${count(models.models)} total; Copilot token ${copilot.token_cached ? `cached (${duration(copilot.token_expires_in_ms)} remaining)` : "not cached"}`));
|
|
209
209
|
const prediction = data.client_integrations?.prediction;
|
|
210
210
|
if (prediction) {
|
|
211
|
-
lines.push(status("info",
|
|
212
|
-
if (prediction.launch_route) lines.push(status("info",
|
|
211
|
+
lines.push(status("info", `${scoped ? "Codex predictions" : "Native predictions"}: ${prediction.configured ? "on" : "off"}; bridge ${prediction.bridge}; client route ${prediction.client_route}; visible candidate unknown`));
|
|
212
|
+
if (prediction.launch_route) lines.push(status("info", `${scoped ? "Codex prediction route" : "Prediction self-check"}: App route ${prediction.launch_route}; persistent route ${prediction.persistence || "unknown"}; ${count(prediction.recovery?.recovered)} bridge recoveries, ${count(prediction.recovery?.attempts)}/3 attempts used`));
|
|
213
213
|
if (prediction.reason) lines.push(status("warn", terminalCell(prediction.reason).slice(0, 400)));
|
|
214
214
|
if (prediction.environment) lines.push(status("info", formatPredictionEnvironment(prediction.environment)));
|
|
215
215
|
}
|
|
216
216
|
if (data.profiles?.codex) {
|
|
217
|
-
lines.push(status("info",
|
|
217
|
+
lines.push(status("info", `${scoped ? "GitHub profile for Codex" : "Profile"}: ${profileSummary("Codex", data.profiles.codex)}`));
|
|
218
218
|
}
|
|
219
219
|
if (data.routing?.responses) {
|
|
220
|
-
lines.push(status("info",
|
|
220
|
+
lines.push(status("info", `${scoped ? "Codex routing" : "Routing"}: /v1/responses -> ${routingTarget(data.routing.responses)}`));
|
|
221
221
|
}
|
|
222
222
|
if (data.providers?.m365) {
|
|
223
223
|
const m365 = data.providers.m365;
|
package/src/cli-tools.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { adapterBaseUrl, checkRunningAdapter } from "./running-adapter.mjs";
|
|
2
2
|
import { isLoopbackHost } from "./security.mjs";
|
|
3
3
|
import { readBoundedResponseText } from "./upstream-body.mjs";
|
|
4
|
+
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
4
5
|
import { writeServicePreference } from "./user-settings.mjs";
|
|
5
6
|
|
|
6
|
-
export async function dashboardToolRequest({ host = "127.0.0.1", port = 2026, path = "account", body, fetchImpl = fetch, timeoutMs = 5000 } = {}) {
|
|
7
|
+
export async function dashboardToolRequest({ host = "127.0.0.1", port = 2026, path = "account", body, fetchImpl = fetch, timeoutMs = 5000, detailedErrors = false } = {}) {
|
|
7
8
|
const baseUrl = adapterBaseUrl(isLoopbackHost(host) ? host : "127.0.0.1", port);
|
|
8
9
|
const running = await checkRunningAdapter({ host, port, fetchImpl, timeoutMs });
|
|
9
10
|
if (!running.ok) throw new Error("Start or restart CCDX to use this tool.");
|
|
@@ -11,7 +12,7 @@ export async function dashboardToolRequest({ host = "127.0.0.1", port = 2026, pa
|
|
|
11
12
|
headers: { "X-CCDX-Dashboard": "1", Origin: baseUrl, ...(body ? { "Content-Type": "application/json" } : {}) },
|
|
12
13
|
...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout(timeoutMs) });
|
|
13
14
|
const data = JSON.parse(await readBoundedResponseText(response, { maxBytes: 1024 * 1024, label: "Local tool response" }));
|
|
14
|
-
if (!response.ok) throw new Error("Local tool is unavailable. Restart the updated CCDX service.");
|
|
15
|
+
if (!response.ok) throw Object.assign(new Error(detailedErrors && typeof data.error === "string" ? redactDiagnosticText(data.error.slice(0, 300)) : "Local tool is unavailable. Restart the updated CCDX service."), { statusCode: response.status, code: /^(?:ccdx|m365|auth)_[a-z0-9_]+$/.test(data.code || data.error || "") ? data.code || data.error : "ccdx_tool_unavailable" });
|
|
15
16
|
return data;
|
|
16
17
|
}
|
|
17
18
|
|