codex-copilot-dx 0.6.5 → 0.6.7
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 +12 -3
- package/bin/cli.mjs +17 -3
- package/package.json +1 -1
- package/scripts/benchmark.mjs +58 -1
- package/src/adapter.mjs +1 -0
- package/src/cli-auth.mjs +101 -14
- package/src/cli-models.mjs +74 -12
- package/src/cli-options.mjs +43 -16
- package/src/cli-table.mjs +114 -0
- package/src/copilot-client.mjs +3 -1
- package/src/doctor.mjs +9 -8
- package/src/http-transport.mjs +114 -13
- package/src/image-optimization.mjs +33 -11
- package/src/legacy-command-warning.mjs +3 -2
- package/src/models.mjs +14 -10
- package/src/observability.mjs +18 -1
- package/src/pm-studio-setup.mjs +28 -4
- package/src/pm-studio-status.mjs +177 -25
- package/src/profile-routing.mjs +7 -16
- package/src/profile-runtime.mjs +12 -3
- package/src/response-history.mjs +12 -2
- package/src/responses-byte-budget.mjs +53 -26
- package/src/responses-chat-payload.mjs +35 -16
- package/src/responses-content.mjs +36 -4
- package/src/responses-handler.mjs +47 -27
- package/src/responses-image-limit.mjs +16 -2
- package/src/responses-image-pressure.mjs +10 -4
- package/src/responses-request.mjs +28 -10
- package/src/usage.mjs +104 -9
package/README.md
CHANGED
|
@@ -37,6 +37,10 @@ breaking release. For a one-off run without a global install, use
|
|
|
37
37
|
`npm exec --yes --package=codex-copilot-dx@latest -- ccdx`.
|
|
38
38
|
Run `ccdx <command> --help` (including `auth login claude --help` and
|
|
39
39
|
`pms status --help`) for command-specific behavior and side-effect details.
|
|
40
|
+
The read-only `usage`, `models`, `auth status`, and `pms status` commands use
|
|
41
|
+
aligned tables in interactive terminals. Redirected or piped output keeps the
|
|
42
|
+
legacy plain-text layout for script compatibility; use `--format table` or
|
|
43
|
+
`--format plain` to choose explicitly.
|
|
40
44
|
|
|
41
45
|
To query the models currently advertised as selectable for the saved Codex
|
|
42
46
|
Copilot account, run:
|
|
@@ -47,7 +51,8 @@ ccdx models
|
|
|
47
51
|
|
|
48
52
|
This performs a fresh, read-only GitHub Copilot model-directory lookup without
|
|
49
53
|
starting the adapter, opening device login, reading the local model cache, or
|
|
50
|
-
consuming an inference request. It lists model IDs
|
|
54
|
+
consuming an inference request. It lists model IDs in a provider, API, and
|
|
55
|
+
preview-status table with their
|
|
51
56
|
advertised API capabilities and reports the live Claude/Anthropic count. A model
|
|
52
57
|
being advertised does not guarantee that a later inference request will avoid
|
|
53
58
|
quota, rate-limit, or policy enforcement.
|
|
@@ -120,8 +125,8 @@ ccdx auth login claude --reauth --github-login <personal-github-login>
|
|
|
120
125
|
ccdx pms setup
|
|
121
126
|
```
|
|
122
127
|
|
|
123
|
-
Inspect the installed version, exact patch
|
|
124
|
-
and relay without changing files:
|
|
128
|
+
Inspect the installed version, exact patch manifest plus executable/signing
|
|
129
|
+
integrity, isolated Claude profile, and live relay routing without changing files:
|
|
125
130
|
|
|
126
131
|
```bash
|
|
127
132
|
ccdx pms status
|
|
@@ -384,6 +389,10 @@ The adapter records token usage metadata to `~/.local/share/codex-copilot-dx/usa
|
|
|
384
389
|
ccdx usage
|
|
385
390
|
```
|
|
386
391
|
|
|
392
|
+
The summary covers the retained current usage log and its single rotated
|
|
393
|
+
backup, not an unbounded lifetime history. Its table reports recorded usage
|
|
394
|
+
responses and per-model input, cache-read, output, and total token metadata.
|
|
395
|
+
|
|
387
396
|
### Debug logging
|
|
388
397
|
|
|
389
398
|
Set `CCDX_LOG_PATH=1` to mirror terminal logs to `~/.local/share/codex-copilot-dx/debug.log`, or set `CCDX_LOG_PATH` to a custom file. Add `CCDX_LOG_LEVEL=debug` to include upstream request attempts, retry causes, status codes, and timings. Debug logs do not include prompts, completions, request bodies, or authorization tokens.
|
package/bin/cli.mjs
CHANGED
|
@@ -47,7 +47,10 @@ if (CLI.command === "version") {
|
|
|
47
47
|
process.exit(0);
|
|
48
48
|
}
|
|
49
49
|
if (CLI.command === "usage") {
|
|
50
|
-
await printUsageSummary(
|
|
50
|
+
await printUsageSummary({
|
|
51
|
+
format: CLI.outputFormat || "auto",
|
|
52
|
+
output: process.stdout,
|
|
53
|
+
});
|
|
51
54
|
process.exit(0);
|
|
52
55
|
}
|
|
53
56
|
if (CLI.command === "auth") {
|
|
@@ -59,6 +62,8 @@ if (CLI.command === "auth") {
|
|
|
59
62
|
reauth: CLI.reauth,
|
|
60
63
|
expectedLogin: CLI.expectedLogin,
|
|
61
64
|
commandName: CLI_NAME,
|
|
65
|
+
format: CLI.outputFormat || "auto",
|
|
66
|
+
output: process.stdout,
|
|
62
67
|
});
|
|
63
68
|
if (result.output) console.log(result.output);
|
|
64
69
|
if (result.action === "login") {
|
|
@@ -97,7 +102,11 @@ if (CLI.command === "status") {
|
|
|
97
102
|
if (CLI.command === "models") {
|
|
98
103
|
try {
|
|
99
104
|
const catalog = await fetchLiveCopilotModels({ profile: CLI.profile });
|
|
100
|
-
console.log(formatLiveCopilotModels(catalog, {
|
|
105
|
+
console.log(formatLiveCopilotModels(catalog, {
|
|
106
|
+
commandName: CLI_NAME,
|
|
107
|
+
format: CLI.outputFormat || "auto",
|
|
108
|
+
output: process.stdout,
|
|
109
|
+
}));
|
|
101
110
|
process.exit(0);
|
|
102
111
|
} catch (e) {
|
|
103
112
|
console.error(status("err", e.message));
|
|
@@ -127,7 +136,11 @@ if (CLI.command === "pms") {
|
|
|
127
136
|
try {
|
|
128
137
|
if (CLI.action === "status") {
|
|
129
138
|
const { runPmStudioStatus } = await import("../src/pm-studio-status.mjs");
|
|
130
|
-
const result = await runPmStudioStatus({
|
|
139
|
+
const result = await runPmStudioStatus({
|
|
140
|
+
commandName: CLI_NAME,
|
|
141
|
+
format: CLI.outputFormat || "auto",
|
|
142
|
+
output: process.stdout,
|
|
143
|
+
});
|
|
131
144
|
process.exit(result.ok ? 0 : 1);
|
|
132
145
|
}
|
|
133
146
|
const { runPmStudioSetup } = await import("../src/pm-studio-setup.mjs");
|
|
@@ -316,6 +329,7 @@ try {
|
|
|
316
329
|
codexModelRegistry: profileModels.codexRegistry,
|
|
317
330
|
claudeModelRegistry: profileModels.claudeRegistry,
|
|
318
331
|
claudeMode: profileRuntime.claudeMode,
|
|
332
|
+
isClaudeProfileCurrent: profileRuntime.isClaudeProfileCurrent,
|
|
319
333
|
showRequestId: CLI.showRequestId,
|
|
320
334
|
upstreamTimeoutMs: RUNTIME.upstreamTimeoutMs,
|
|
321
335
|
streamHandshakeTimeoutMs: RUNTIME.streamHandshakeTimeoutMs,
|
package/package.json
CHANGED
package/scripts/benchmark.mjs
CHANGED
|
@@ -23,6 +23,14 @@ function runProbe(source) {
|
|
|
23
23
|
return JSON.parse(result.stdout.trim());
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function median(values) {
|
|
27
|
+
const ordered = [...values].sort((left, right) => left - right);
|
|
28
|
+
const middle = Math.floor(ordered.length / 2);
|
|
29
|
+
return ordered.length % 2 === 0
|
|
30
|
+
? (ordered[middle - 1] + ordered[middle]) / 2
|
|
31
|
+
: ordered[middle];
|
|
32
|
+
}
|
|
33
|
+
|
|
26
34
|
function deterministicPixels(byteLength, initialSeed) {
|
|
27
35
|
const pixels = Buffer.alloc(byteLength);
|
|
28
36
|
let seed = initialSeed;
|
|
@@ -154,7 +162,7 @@ function largePayloadProbe(targetMiB, concurrency) {
|
|
|
154
162
|
}
|
|
155
163
|
|
|
156
164
|
function largeTokenCountProbe(mode) {
|
|
157
|
-
|
|
165
|
+
const samples = Array.from({ length: 3 }, () => runProbe(`
|
|
158
166
|
const text = "a ".repeat(2 * 1024 * 1024);
|
|
159
167
|
const started = performance.now();
|
|
160
168
|
let tokens;
|
|
@@ -174,6 +182,51 @@ function largeTokenCountProbe(mode) {
|
|
|
174
182
|
rss_mib: +(memory.rss / 1048576).toFixed(1),
|
|
175
183
|
heap_used_mib: +(memory.heapUsed / 1048576).toFixed(1),
|
|
176
184
|
}));
|
|
185
|
+
`));
|
|
186
|
+
return {
|
|
187
|
+
input_mib: samples[0].input_mib,
|
|
188
|
+
tokens: samples[0].tokens,
|
|
189
|
+
elapsed_ms: +median(samples.map((sample) => sample.elapsed_ms)).toFixed(1),
|
|
190
|
+
rss_mib: +median(samples.map((sample) => sample.rss_mib)).toFixed(1),
|
|
191
|
+
heap_used_mib: +median(samples.map((sample) => sample.heap_used_mib)).toFixed(1),
|
|
192
|
+
samples: samples.length,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function toolOutputParseCacheProbe() {
|
|
197
|
+
return runProbe(`
|
|
198
|
+
import { enforceResponsesImageLimit } from "./src/responses-image-limit.mjs";
|
|
199
|
+
import { responsesHistoricalImageStats } from "./src/responses-byte-budget.mjs";
|
|
200
|
+
import { prepareResponsesChatPayload } from "./src/responses-chat-payload.mjs";
|
|
201
|
+
|
|
202
|
+
const item = {
|
|
203
|
+
type: "function_call_output",
|
|
204
|
+
call_id: "call_benchmark",
|
|
205
|
+
output: JSON.stringify([{ type: "input_text", text: "x".repeat(8 * 1024 * 1024) }]),
|
|
206
|
+
};
|
|
207
|
+
const source = item.output;
|
|
208
|
+
const originalParse = JSON.parse;
|
|
209
|
+
let parseCalls = 0;
|
|
210
|
+
JSON.parse = function countedParse(value, ...args) {
|
|
211
|
+
if (value === source) parseCalls += 1;
|
|
212
|
+
return originalParse.call(this, value, ...args);
|
|
213
|
+
};
|
|
214
|
+
const started = performance.now();
|
|
215
|
+
try {
|
|
216
|
+
enforceResponsesImageLimit([item]);
|
|
217
|
+
responsesHistoricalImageStats([item], 1);
|
|
218
|
+
await prepareResponsesChatPayload({
|
|
219
|
+
body: { model: "gpt-4o", input: [item] },
|
|
220
|
+
currentInputStart: 1,
|
|
221
|
+
}, { payloadOptions: { maxBytes: 30 * 1024 * 1024 } });
|
|
222
|
+
} finally {
|
|
223
|
+
JSON.parse = originalParse;
|
|
224
|
+
}
|
|
225
|
+
process.stdout.write(JSON.stringify({
|
|
226
|
+
output_mib: +(Buffer.byteLength(source) / 1048576).toFixed(1),
|
|
227
|
+
parse_calls: parseCalls,
|
|
228
|
+
elapsed_ms: +(performance.now() - started).toFixed(1),
|
|
229
|
+
}));
|
|
177
230
|
`);
|
|
178
231
|
}
|
|
179
232
|
|
|
@@ -373,6 +426,7 @@ if (checkMode) {
|
|
|
373
426
|
proxy: largeTokenCountProbe("proxy"),
|
|
374
427
|
materialized_array: largeTokenCountProbe("array"),
|
|
375
428
|
};
|
|
429
|
+
report.tool_output_parse_cache = toolOutputParseCacheProbe();
|
|
376
430
|
report.large_payload_peak = [
|
|
377
431
|
largePayloadProbe(5, 4),
|
|
378
432
|
largePayloadProbe(30, 1),
|
|
@@ -409,6 +463,9 @@ if (checkMode) {
|
|
|
409
463
|
if (proxy.heap_used_mib > array.heap_used_mib * 0.75) {
|
|
410
464
|
failures.push(`token counter heap regression: proxy=${proxy.heap_used_mib}MiB array=${array.heap_used_mib}MiB`);
|
|
411
465
|
}
|
|
466
|
+
if (report.tool_output_parse_cache.parse_calls !== 1) {
|
|
467
|
+
failures.push(`stringified tool output parsed ${report.tool_output_parse_cache.parse_calls} times instead of once`);
|
|
468
|
+
}
|
|
412
469
|
for (const payload of report.large_payload_peak) {
|
|
413
470
|
if (payload.admission_max_active_mib > payload.admission_budget_mib) {
|
|
414
471
|
failures.push(`request admission exceeded its budget at ${payload.target_request_mib}MiB x${payload.concurrency}`);
|
package/src/adapter.mjs
CHANGED
package/src/cli-auth.mjs
CHANGED
|
@@ -21,8 +21,15 @@ import {
|
|
|
21
21
|
normalizeGithubIdentity,
|
|
22
22
|
} from "./github-identity.mjs";
|
|
23
23
|
import { saveModelCache } from "./model-cache.mjs";
|
|
24
|
+
import { isClaudeCopilotModel } from "./models.mjs";
|
|
24
25
|
import { profileRouting } from "./profile-routing.mjs";
|
|
25
26
|
import { status } from "./status.mjs";
|
|
27
|
+
import {
|
|
28
|
+
cliOutputFormat,
|
|
29
|
+
cliOutputWidth,
|
|
30
|
+
formatResponsiveCliTable,
|
|
31
|
+
terminalCell,
|
|
32
|
+
} from "./cli-table.mjs";
|
|
26
33
|
|
|
27
34
|
const CLIENT_ID = "Iv1.b507a08c87ecfe98";
|
|
28
35
|
const SCOPE = "read:user";
|
|
@@ -145,17 +152,7 @@ async function codexIdentity({ home, fetchImpl, signal }) {
|
|
|
145
152
|
function claudeModels(payload) {
|
|
146
153
|
const models = Array.isArray(payload) ? payload : payload?.data;
|
|
147
154
|
if (!Array.isArray(models)) throw new Error("Claude account model catalog contained no model list");
|
|
148
|
-
return models.filter(
|
|
149
|
-
const id = String(model?.id || "").trim();
|
|
150
|
-
const vendor = String(model?.vendor || model?.owned_by || "").trim().toLowerCase();
|
|
151
|
-
const policy = String(model?.policy?.state || "").trim().toLowerCase();
|
|
152
|
-
const endpoints = Array.isArray(model?.supported_endpoints) ? model.supported_endpoints : [];
|
|
153
|
-
return Boolean(id)
|
|
154
|
-
&& (id.toLowerCase().startsWith("claude-") || vendor === "anthropic")
|
|
155
|
-
&& model?.model_picker_enabled === true
|
|
156
|
-
&& (!policy || policy === "enabled")
|
|
157
|
-
&& (endpoints.includes("/chat/completions") || endpoints.includes("/v1/messages"));
|
|
158
|
-
});
|
|
155
|
+
return models.filter(isClaudeCopilotModel);
|
|
159
156
|
}
|
|
160
157
|
|
|
161
158
|
function catalogModels(payload) {
|
|
@@ -488,7 +485,7 @@ function onlineStatusLine(name, profile) {
|
|
|
488
485
|
return status("ok", `${name} online: ${account}${online.models} models, ${online.claudeModels} Claude`);
|
|
489
486
|
}
|
|
490
487
|
|
|
491
|
-
|
|
488
|
+
function authStatusPlainLines(snapshot, { commandName }) {
|
|
492
489
|
const claudeLabel = snapshot.profiles.claude.configured
|
|
493
490
|
? `${accountLabel(snapshot.profiles.claude)} [isolated profile]`
|
|
494
491
|
: "inherits Codex [no isolated profile]";
|
|
@@ -502,7 +499,95 @@ export function formatAuthStatus(snapshot = authStatus(), { commandName = "ccdx"
|
|
|
502
499
|
status(claudeKind, `Claude: ${claudeLabel}`),
|
|
503
500
|
onlineStatusLine("Claude", snapshot.profiles.claude),
|
|
504
501
|
status("info", `Routing: responses -> ${snapshot.routing.responses}; messages -> ${snapshot.routing.messages}`),
|
|
505
|
-
].filter(Boolean)
|
|
502
|
+
].filter(Boolean);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function authTableOnline(profile) {
|
|
506
|
+
const online = profile.online;
|
|
507
|
+
if (!online) return { state: "[INFO] not checked", models: "—", claudeModels: "—" };
|
|
508
|
+
if (online.inherited) return { state: "[INFO] inherits Codex", models: "—", claudeModels: "—" };
|
|
509
|
+
if (!online.ok) {
|
|
510
|
+
const httpStatus = online.httpStatus ? ` (HTTP ${online.httpStatus})` : "";
|
|
511
|
+
return {
|
|
512
|
+
state: `[WARN] ${online.reason || "unavailable"}${httpStatus}`,
|
|
513
|
+
models: "—",
|
|
514
|
+
claudeModels: "—",
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
return {
|
|
518
|
+
state: `[OK] verified${online.login ? ` as ${online.login}` : ""}`,
|
|
519
|
+
models: Number.isFinite(online.models) ? String(online.models) : "—",
|
|
520
|
+
claudeModels: Number.isFinite(online.claudeModels) ? String(online.claudeModels) : "—",
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function authTableRow(name, profile, { claude = false } = {}) {
|
|
525
|
+
const inherited = claude && !profile.configured;
|
|
526
|
+
const online = authTableOnline(profile);
|
|
527
|
+
const local = inherited
|
|
528
|
+
? "[INFO] inherits Codex"
|
|
529
|
+
: profile.valid
|
|
530
|
+
? "[OK] ready"
|
|
531
|
+
: `[WARN] ${accountLabel(profile)}`;
|
|
532
|
+
const account = inherited ? "inherits Codex" : accountLabel(profile);
|
|
533
|
+
const mode = inherited ? "inherited" : claude ? "isolated" : "legacy path";
|
|
534
|
+
return {
|
|
535
|
+
profile: name,
|
|
536
|
+
account,
|
|
537
|
+
mode,
|
|
538
|
+
local,
|
|
539
|
+
online: online.state,
|
|
540
|
+
models: online.models,
|
|
541
|
+
claudeModels: online.claudeModels,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export function formatAuthStatus(snapshot = authStatus(), {
|
|
546
|
+
commandName = "ccdx",
|
|
547
|
+
format = "plain",
|
|
548
|
+
output = process.stdout,
|
|
549
|
+
width = cliOutputWidth(output),
|
|
550
|
+
} = {}) {
|
|
551
|
+
const plainLines = authStatusPlainLines(snapshot, { commandName });
|
|
552
|
+
if (cliOutputFormat(format, output) === "plain") {
|
|
553
|
+
return plainLines.join("\n");
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const rows = [
|
|
557
|
+
authTableRow("Codex", snapshot.profiles.codex),
|
|
558
|
+
authTableRow("Claude", snapshot.profiles.claude, { claude: true }),
|
|
559
|
+
];
|
|
560
|
+
const table = formatResponsiveCliTable({
|
|
561
|
+
columns: [
|
|
562
|
+
{ key: "profile", label: "PROFILE" },
|
|
563
|
+
{ key: "account", label: "ACCOUNT" },
|
|
564
|
+
{ key: "mode", label: "MODE" },
|
|
565
|
+
{ key: "local", label: "LOCAL" },
|
|
566
|
+
{ key: "online", label: "ONLINE" },
|
|
567
|
+
{ key: "models", label: "MODELS", align: "right" },
|
|
568
|
+
{ key: "claudeModels", label: "CLAUDE", align: "right" },
|
|
569
|
+
],
|
|
570
|
+
compactColumns: [
|
|
571
|
+
{ key: "profile", label: "PROFILE" },
|
|
572
|
+
{ key: "local", label: "LOCAL" },
|
|
573
|
+
{ key: "online", label: "ONLINE" },
|
|
574
|
+
],
|
|
575
|
+
rows,
|
|
576
|
+
width,
|
|
577
|
+
});
|
|
578
|
+
if (format === "auto" && table.overflow) {
|
|
579
|
+
return plainLines.map((line) => terminalCell(line, { fallback: "" })).join("\n");
|
|
580
|
+
}
|
|
581
|
+
const lines = [
|
|
582
|
+
`${commandName} auth status`,
|
|
583
|
+
"",
|
|
584
|
+
table.output,
|
|
585
|
+
];
|
|
586
|
+
if (table.compact) {
|
|
587
|
+
lines.push("", "Details:", ...plainLines.slice(1, -1).map((line) => terminalCell(line, { fallback: "" })));
|
|
588
|
+
}
|
|
589
|
+
lines.push(terminalCell(plainLines.at(-1), { fallback: "" }));
|
|
590
|
+
return lines.join("\n");
|
|
506
591
|
}
|
|
507
592
|
|
|
508
593
|
export async function runAuthCommand({
|
|
@@ -512,11 +597,13 @@ export async function runAuthCommand({
|
|
|
512
597
|
reauth = false,
|
|
513
598
|
expectedLogin = "",
|
|
514
599
|
commandName = "ccdx",
|
|
600
|
+
format = "plain",
|
|
601
|
+
output = process.stdout,
|
|
515
602
|
...options
|
|
516
603
|
} = {}) {
|
|
517
604
|
if (action === "status") {
|
|
518
605
|
const snapshot = online ? await authStatusOnline(options) : authStatus(options);
|
|
519
|
-
return { action, output: formatAuthStatus(snapshot, { commandName }), snapshot };
|
|
606
|
+
return { action, output: formatAuthStatus(snapshot, { commandName, format, output }), snapshot };
|
|
520
607
|
}
|
|
521
608
|
if (profile !== AUTH_PROFILE_CLAUDE) throw new Error("Only the isolated Claude profile can be changed by this command");
|
|
522
609
|
if (action === "login") return { action, ...(await authorizeClaudeProfile({ ...options, reauth, expectedLogin })) };
|
package/src/cli-models.mjs
CHANGED
|
@@ -6,7 +6,17 @@ import {
|
|
|
6
6
|
readAuthProfileCredentials,
|
|
7
7
|
} from "./auth-profile.mjs";
|
|
8
8
|
import { buildHeaders, DEFAULT_API_BASE, FALLBACK_VSCODE_VERSION } from "./copilot.mjs";
|
|
9
|
+
import {
|
|
10
|
+
isClaudeCopilotCatalogEntry,
|
|
11
|
+
isClaudeCopilotModel,
|
|
12
|
+
} from "./models.mjs";
|
|
9
13
|
import { status } from "./status.mjs";
|
|
14
|
+
import {
|
|
15
|
+
cliOutputFormat,
|
|
16
|
+
cliOutputWidth,
|
|
17
|
+
formatResponsiveCliTable,
|
|
18
|
+
terminalCell,
|
|
19
|
+
} from "./cli-table.mjs";
|
|
10
20
|
|
|
11
21
|
const DEFAULT_MODELS_TIMEOUT_MS = 10000;
|
|
12
22
|
const SUPPORTED_ENDPOINTS = [
|
|
@@ -37,11 +47,15 @@ export function selectableCopilotModels(payload) {
|
|
|
37
47
|
const models = [];
|
|
38
48
|
const seen = new Set();
|
|
39
49
|
for (const model of data) {
|
|
40
|
-
if (model
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
if (isClaudeCopilotCatalogEntry(model)) {
|
|
51
|
+
if (!isClaudeCopilotModel(model)) continue;
|
|
52
|
+
} else {
|
|
53
|
+
if (model?.model_picker_enabled !== true) continue;
|
|
54
|
+
const policyState = safeText(model?.policy?.state).toLowerCase();
|
|
55
|
+
if (policyState && policyState !== "enabled") continue;
|
|
56
|
+
const capabilityType = safeText(model?.capabilities?.type).toLowerCase();
|
|
57
|
+
if (capabilityType && capabilityType !== "chat") continue;
|
|
58
|
+
}
|
|
45
59
|
|
|
46
60
|
const id = safeText(model?.id);
|
|
47
61
|
const endpoints = endpointLabels(model);
|
|
@@ -158,22 +172,22 @@ export async function fetchLiveCopilotModels({
|
|
|
158
172
|
}
|
|
159
173
|
}
|
|
160
174
|
|
|
161
|
-
|
|
162
|
-
const models = Array.isArray(catalog?.models) ? catalog.models : [];
|
|
163
|
-
const profile = catalog?.profile === AUTH_PROFILE_CLAUDE ? AUTH_PROFILE_CLAUDE : AUTH_PROFILE_CODEX;
|
|
175
|
+
function liveCatalogHeader(catalog, { commandName, profile, models }) {
|
|
164
176
|
const responses = models.filter((model) => model.endpoints.includes("responses")).length;
|
|
165
177
|
const chat = models.filter((model) => model.endpoints.includes("chat")).length;
|
|
166
|
-
const claude = models.filter(
|
|
167
|
-
|
|
168
|
-
const lines = [
|
|
178
|
+
const claude = models.filter(isClaudeCopilotCatalogEntry).length;
|
|
179
|
+
return [
|
|
169
180
|
`${commandName} models${profile === AUTH_PROFILE_CLAUDE ? " --profile claude" : ""}`,
|
|
170
181
|
status("ok", `Live catalog from ${safeText(catalog?.upstreamHost, "GitHub Copilot")}: ${models.length} selectable of ${Number(catalog?.advertised) || 0} advertised`),
|
|
171
182
|
status("info", `Responses: ${responses}; Chat: ${chat}; Claude/Anthropic: ${claude}`),
|
|
172
183
|
];
|
|
184
|
+
}
|
|
173
185
|
|
|
186
|
+
function formatLiveCopilotModelsPlain(catalog, { commandName, profile, models }, { sanitize = false } = {}) {
|
|
187
|
+
const lines = liveCatalogHeader(catalog, { commandName, profile, models });
|
|
174
188
|
if (!models.length) {
|
|
175
189
|
lines.push(status("warn", "No selectable models were advertised for this account"));
|
|
176
|
-
return lines.join("\n");
|
|
190
|
+
return (sanitize ? lines.map((line) => terminalCell(line, { fallback: "" })) : lines).join("\n");
|
|
177
191
|
}
|
|
178
192
|
|
|
179
193
|
let vendor = "";
|
|
@@ -185,5 +199,53 @@ export function formatLiveCopilotModels(catalog, { commandName = "ccdx" } = {})
|
|
|
185
199
|
const flags = [...model.endpoints, ...(model.preview ? ["preview"] : [])];
|
|
186
200
|
lines.push(` ${model.id} [${flags.join(", ")}]`);
|
|
187
201
|
}
|
|
202
|
+
return (sanitize ? lines.map((line) => terminalCell(line, { fallback: "" })) : lines).join("\n");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function formatLiveCopilotModels(catalog, {
|
|
206
|
+
commandName = "ccdx",
|
|
207
|
+
format = "plain",
|
|
208
|
+
output = process.stdout,
|
|
209
|
+
width = cliOutputWidth(output),
|
|
210
|
+
} = {}) {
|
|
211
|
+
const models = Array.isArray(catalog?.models) ? catalog.models : [];
|
|
212
|
+
const profile = catalog?.profile === AUTH_PROFILE_CLAUDE ? AUTH_PROFILE_CLAUDE : AUTH_PROFILE_CODEX;
|
|
213
|
+
const context = { commandName, profile, models };
|
|
214
|
+
if (cliOutputFormat(format, output) === "plain") {
|
|
215
|
+
return formatLiveCopilotModelsPlain(catalog, context);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const lines = liveCatalogHeader(catalog, context);
|
|
219
|
+
if (!models.length) {
|
|
220
|
+
lines.push(status("warn", "No selectable models were advertised for this account"));
|
|
221
|
+
return lines.join("\n");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const rows = models.map((model) => ({
|
|
225
|
+
vendor: model.vendor,
|
|
226
|
+
model: model.id,
|
|
227
|
+
vendorModel: `${model.vendor}/${model.id}`,
|
|
228
|
+
apis: model.endpoints.join(", "),
|
|
229
|
+
preview: model.preview ? "yes" : "no",
|
|
230
|
+
}));
|
|
231
|
+
const table = formatResponsiveCliTable({
|
|
232
|
+
columns: [
|
|
233
|
+
{ key: "vendor", label: "VENDOR" },
|
|
234
|
+
{ key: "model", label: "MODEL" },
|
|
235
|
+
{ key: "apis", label: "APIS" },
|
|
236
|
+
{ key: "preview", label: "PREVIEW" },
|
|
237
|
+
],
|
|
238
|
+
compactColumns: [
|
|
239
|
+
{ key: "vendorModel", label: "VENDOR/MODEL" },
|
|
240
|
+
{ key: "apis", label: "APIS" },
|
|
241
|
+
{ key: "preview", label: "PREVIEW" },
|
|
242
|
+
],
|
|
243
|
+
rows,
|
|
244
|
+
width,
|
|
245
|
+
});
|
|
246
|
+
if (format === "auto" && table.overflow) {
|
|
247
|
+
return formatLiveCopilotModelsPlain(catalog, context, { sanitize: true });
|
|
248
|
+
}
|
|
249
|
+
lines.push("", table.output);
|
|
188
250
|
return lines.join("\n");
|
|
189
251
|
}
|
package/src/cli-options.mjs
CHANGED
|
@@ -60,6 +60,18 @@ function checkedProfile(value, { allowAll = false } = {}) {
|
|
|
60
60
|
return profile;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
function checkedOutputFormat(value) {
|
|
64
|
+
const format = value || "";
|
|
65
|
+
if (!new Set(["table", "plain"]).has(format)) {
|
|
66
|
+
throw new Error(`Format must be table or plain: ${value}`);
|
|
67
|
+
}
|
|
68
|
+
return format;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function outputFormatOption(value) {
|
|
72
|
+
return value ? { outputFormat: checkedOutputFormat(value) } : {};
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
function baseCommand(command, extra = {}) {
|
|
64
76
|
return {
|
|
65
77
|
command,
|
|
@@ -137,28 +149,42 @@ export function parseCliArgs(args = []) {
|
|
|
137
149
|
return baseCommand("status");
|
|
138
150
|
}
|
|
139
151
|
if (command === "usage") {
|
|
140
|
-
|
|
141
|
-
return baseCommand("usage");
|
|
152
|
+
const options = parseOptions(rest, new Map([["--format", "value"]]));
|
|
153
|
+
return baseCommand("usage", outputFormatOption(options["--format"]));
|
|
142
154
|
}
|
|
143
155
|
if (PM_COMMANDS.has(command)) {
|
|
144
156
|
const [action, ...pmsArgs] = rest;
|
|
145
157
|
if (!action) throw new Error("Missing pms action: expected setup or status");
|
|
146
158
|
if (!new Set(["setup", "status"]).has(action)) throw new Error(`Unknown pms action: ${action}`);
|
|
147
|
-
if (
|
|
148
|
-
|
|
159
|
+
if (action === "setup") {
|
|
160
|
+
if (pmsArgs.length) unexpectedArgs(pmsArgs);
|
|
161
|
+
return baseCommand("pms", { action });
|
|
162
|
+
}
|
|
163
|
+
const options = parseOptions(pmsArgs, new Map([["--format", "value"]]));
|
|
164
|
+
return baseCommand("pms", {
|
|
165
|
+
action,
|
|
166
|
+
...outputFormatOption(options["--format"]),
|
|
167
|
+
});
|
|
149
168
|
}
|
|
150
169
|
if (command === "models") {
|
|
151
|
-
const options = parseOptions(rest, new Map([
|
|
170
|
+
const options = parseOptions(rest, new Map([
|
|
171
|
+
["--profile", "value"],
|
|
172
|
+
["--format", "value"],
|
|
173
|
+
]));
|
|
152
174
|
return {
|
|
153
175
|
...baseCommand("models"),
|
|
154
176
|
profile: checkedProfile(options["--profile"]),
|
|
177
|
+
...outputFormatOption(options["--format"]),
|
|
155
178
|
};
|
|
156
179
|
}
|
|
157
180
|
if (command === "auth") {
|
|
158
181
|
const [action, ...authArgs] = rest;
|
|
159
182
|
if (!action) throw new Error("Missing auth action: expected status or login");
|
|
160
183
|
if (action === "status") {
|
|
161
|
-
const options = parseOptions(authArgs, new Map([
|
|
184
|
+
const options = parseOptions(authArgs, new Map([
|
|
185
|
+
["--online", "flag"],
|
|
186
|
+
["--format", "value"],
|
|
187
|
+
]));
|
|
162
188
|
return {
|
|
163
189
|
...baseCommand("auth"),
|
|
164
190
|
action: "status",
|
|
@@ -166,6 +192,7 @@ export function parseCliArgs(args = []) {
|
|
|
166
192
|
online: Boolean(options["--online"]),
|
|
167
193
|
expectedLogin: "",
|
|
168
194
|
reauth: false,
|
|
195
|
+
...outputFormatOption(options["--format"]),
|
|
169
196
|
};
|
|
170
197
|
}
|
|
171
198
|
if (action === "login") {
|
|
@@ -259,16 +286,16 @@ export function cliCommandName() {
|
|
|
259
286
|
function topicHelp(name, topic) {
|
|
260
287
|
const sections = {
|
|
261
288
|
start: `Usage:\n ${name} [start] [--configure-claude-app] [--show-request-id]\n\nStarts or reuses the local adapter, updates Codex and Claude Code configuration, and attempts to open Codex or ChatGPT when auto-launch is enabled and supported.\n--configure-claude-app also creates or updates the managed Claude App gateway profile.`,
|
|
262
|
-
auth: `Usage:\n ${name} auth status [--online]\n ${name} auth login claude [--github-login <login>] [--reauth]\n\nShows the two account profiles or configures the isolated Claude account. Device login starts only when no reusable local Copilot credential is available or --reauth is used.`,
|
|
263
|
-
"auth status": `Usage:\n ${name} auth status [--online]\n\nShows account routing without exposing credentials. --online also verifies both configured Copilot entitlements and model catalogs.`,
|
|
289
|
+
auth: `Usage:\n ${name} auth status [--online] [--format table|plain]\n ${name} auth login claude [--github-login <login>] [--reauth]\n\nShows the two account profiles or configures the isolated Claude account. Device login starts only when no reusable local Copilot credential is available or --reauth is used.`,
|
|
290
|
+
"auth status": `Usage:\n ${name} auth status [--online] [--format table|plain]\n\nShows account routing without exposing credentials. --online also verifies both configured Copilot entitlements and model catalogs. Interactive terminals use a table by default.`,
|
|
264
291
|
"auth login": `Usage:\n ${name} auth login claude [--github-login <login>] [--reauth]\n\nReuses a compatible local Copilot credential when possible. --reauth forces GitHub Device Flow.`,
|
|
265
292
|
doctor: `Usage:\n ${name} doctor [--online] [--compat] [--profile codex|claude|all]\n\nChecks local credentials, client configuration, PM Studio state, and the adapter. --online validates account entitlement; --compat sends minimal inference requests and consumes a small amount of Copilot usage.`,
|
|
266
293
|
status: `Usage:\n ${name} status\n\nShows bounded runtime, routing, performance, cache, queue, and PM relay metrics from a running adapter.`,
|
|
267
|
-
models: `Usage:\n ${name} models [--profile codex|claude]\n\nPerforms a fresh, read-only Copilot model-directory lookup for one saved profile.`,
|
|
268
|
-
pms: `Usage:\n ${name} pms status\n ${name} pms setup\n ${name} pm-studio status\n ${name} pm-studio setup\n\nInspects or installs the version-locked PM Studio loopback patch. setup modifies the installed app only after all preflight checks pass.`,
|
|
294
|
+
models: `Usage:\n ${name} models [--profile codex|claude] [--format table|plain]\n\nPerforms a fresh, read-only Copilot model-directory lookup for one saved profile. Interactive terminals use a table by default.`,
|
|
295
|
+
pms: `Usage:\n ${name} pms status [--format table|plain]\n ${name} pms setup\n ${name} pm-studio status [--format table|plain]\n ${name} pm-studio setup\n\nInspects or installs the version-locked PM Studio loopback patch. setup modifies the installed app only after all preflight checks pass.`,
|
|
269
296
|
"pms setup": `Usage:\n ${name} pms setup\n\nBacks up, patches, verifies, and ad-hoc signs an exactly supported PM Studio bundle. Unknown versions and drift are never modified.`,
|
|
270
|
-
"pms status": `Usage:\n ${name} pms status\n\nRead-only inspection of the installed PM Studio version, patch integrity, Claude profile, and relay availability.`,
|
|
271
|
-
usage: `Usage:\n ${name} usage\n\nSummarizes local token usage metadata without reading prompt or completion content.`,
|
|
297
|
+
"pms status": `Usage:\n ${name} pms status [--format table|plain]\n\nRead-only inspection of the installed PM Studio version, patch integrity, Claude profile, and relay availability. Interactive terminals use a table by default.`,
|
|
298
|
+
usage: `Usage:\n ${name} usage [--format table|plain]\n\nSummarizes local token usage metadata without reading prompt or completion content. Interactive terminals use a table by default.`,
|
|
272
299
|
"auto-review-model": `Usage:\n ${name} auto-review-model\n\nInteractively selects an enabled Responses model for Codex Auto-review.`,
|
|
273
300
|
update: `Usage:\n ${name} update [npm|github]\n\nUpdates the global package from the configured npm registry or GitHub main. With no source, an interactive terminal prompts for one.`,
|
|
274
301
|
version: `Usage:\n ${name} --version`,
|
|
@@ -282,14 +309,14 @@ export function cliHelp(commandName = "ccdx", topic = "") {
|
|
|
282
309
|
if (normalizedTopic) return topicHelp(name, normalizedTopic);
|
|
283
310
|
return `Usage:
|
|
284
311
|
${name} [start] [--configure-claude-app] [--show-request-id]
|
|
285
|
-
${name} auth status [--online]
|
|
312
|
+
${name} auth status [--online] [--format table|plain]
|
|
286
313
|
${name} auth login claude [--github-login <login>] [--reauth]
|
|
287
314
|
${name} doctor [--online] [--compat] [--profile codex|claude|all]
|
|
288
315
|
${name} status
|
|
289
|
-
${name} models [--profile codex|claude]
|
|
290
|
-
${name} pms status
|
|
316
|
+
${name} models [--profile codex|claude] [--format table|plain]
|
|
317
|
+
${name} pms status [--format table|plain]
|
|
291
318
|
${name} pms setup
|
|
292
|
-
${name} usage
|
|
319
|
+
${name} usage [--format table|plain]
|
|
293
320
|
${name} auto-review-model
|
|
294
321
|
${name} update [npm|github]
|
|
295
322
|
${name} --version
|