codex-copilot-dx 1.3.13 → 1.3.14

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.
Files changed (52) hide show
  1. package/README.md +2 -2
  2. package/bin/cli.mjs +5 -10
  3. package/docs/ARCHITECTURE.md +9 -6
  4. package/docs/REFERENCE.md +19 -35
  5. package/package.json +1 -1
  6. package/src/access-settings.mjs +2 -1
  7. package/src/adapter.mjs +14 -4
  8. package/src/claude-capability-config.mjs +2 -2
  9. package/src/claude-client-config.mjs +5 -3
  10. package/src/cli-command-spec.mjs +4 -11
  11. package/src/cli-image.mjs +24 -180
  12. package/src/cli-management.mjs +21 -6
  13. package/src/cli-options.mjs +1 -1
  14. package/src/cli-secret.mjs +39 -0
  15. package/src/cli-tools.mjs +1 -1
  16. package/src/client-integration.mjs +13 -12
  17. package/src/client-model-plan.mjs +3 -1
  18. package/src/config.mjs +9 -54
  19. package/src/connection-runtime.mjs +24 -3
  20. package/src/copilot-client.mjs +16 -1
  21. package/src/dashboard/connections.js +41 -10
  22. package/src/dashboard/console.js +6 -4
  23. package/src/dashboard/features.js +19 -29
  24. package/src/dashboard/index.html +3 -3
  25. package/src/dashboard/language.js +8 -7
  26. package/src/dashboard/ui.css +6 -0
  27. package/src/dashboard/ui.js +11 -2
  28. package/src/dashboard/usage.js +10 -5
  29. package/src/dashboard-api.mjs +2 -1
  30. package/src/doctor.mjs +4 -5
  31. package/src/image-models.mjs +20 -0
  32. package/src/image-retirement.mjs +33 -0
  33. package/src/image-setup.mjs +16 -105
  34. package/src/legacy-image-guidance.mjs +73 -0
  35. package/src/live-models.mjs +2 -1
  36. package/src/native-images.mjs +111 -0
  37. package/src/observability.mjs +2 -0
  38. package/src/optional-routes.mjs +4 -13
  39. package/src/provider-metadata.mjs +5 -4
  40. package/src/provider-runtime.mjs +2 -1
  41. package/src/service-control.mjs +6 -7
  42. package/src/service-worker.mjs +2 -2
  43. package/src/image-mcp.mjs +0 -328
  44. package/src/image-provider-config.mjs +0 -194
  45. package/src/image-provider.mjs +0 -369
  46. package/src/image-readiness.mjs +0 -55
  47. package/src/image-references.mjs +0 -50
  48. package/src/image-skill/SKILL.md +0 -28
  49. package/src/image-skill/references/editing.md +0 -15
  50. package/src/image-skill/references/helper.md +0 -27
  51. package/src/image-skill.mjs +0 -142
  52. package/src/image-tool-client.mjs +0 -150
@@ -1,142 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { createHash } from "node:crypto";
4
- import { atomicWriteFilePairSync, atomicWriteFileSync } from "./atomic-file.mjs";
5
- import { adapterBaseUrl } from "./running-adapter.mjs";
6
-
7
- const SKILL_MARKER = /<!-- ccdx:image-skill:([a-f0-9]{64}) -->\n/;
8
- const HELPER_MARKER = /^\/\/ ccdx:image-helper:([a-f0-9]{64})\n/;
9
- const REFERENCE_MARKER = /^<!-- ccdx:image-reference:([a-f0-9]{64}) -->\n/;
10
- const REFERENCE_FILES = ["editing.md", "helper.md"];
11
-
12
- function digest(content) {
13
- return createHash("sha256").update(content).digest("hex");
14
- }
15
-
16
- function quote(value) {
17
- return `'${String(value).replaceAll("'", "'\\''")}'`;
18
- }
19
-
20
- function conflict(message) {
21
- return Object.assign(new Error(message), { code: "CCDX_IMAGE_SKILL_CONFLICT" });
22
- }
23
-
24
- function directoryCheck(directory) {
25
- try {
26
- if (!fs.lstatSync(directory).isDirectory()) throw conflict(`CCDX image skill path is not a regular directory: ${directory}`);
27
- } catch (error) {
28
- if (error?.code !== "ENOENT") throw error;
29
- }
30
- }
31
-
32
- function ownedSnapshot(filePath, marker, preserveUnowned = false) {
33
- try {
34
- const stat = fs.lstatSync(filePath);
35
- if (!stat.isFile()) throw conflict(`Refusing to replace an unowned CCDX image skill path: ${filePath}`);
36
- const content = fs.readFileSync(filePath, "utf8");
37
- const match = marker.exec(content);
38
- if (!match || digest(content.replace(marker, "")) !== match[1]) {
39
- throw conflict(`Preserving an existing or modified image skill file: ${filePath}`);
40
- }
41
- return { content, mode: stat.mode & 0o777 };
42
- } catch (error) {
43
- if (error?.code === "ENOENT") return null;
44
- if (preserveUnowned && error?.code === "CCDX_IMAGE_SKILL_CONFLICT") return { unowned: true };
45
- throw error;
46
- }
47
- }
48
-
49
- function removeFile(filePath) {
50
- try { fs.unlinkSync(filePath); }
51
- catch (error) { if (error?.code !== "ENOENT") throw error; }
52
- }
53
-
54
- function removeEmptyDirectories(skillDirectory) {
55
- for (const directory of [path.join(skillDirectory, "scripts"), path.join(skillDirectory, "references"), skillDirectory]) {
56
- try { fs.rmdirSync(directory); }
57
- catch (error) { if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(error?.code)) throw error; }
58
- }
59
- }
60
-
61
- export function updateImageSkill({
62
- enabled,
63
- codexPath,
64
- adapterPort = 2026,
65
- adapterHost = "127.0.0.1",
66
- nodePath = process.execPath,
67
- } = {}) {
68
- const skillDirectory = path.join(path.dirname(codexPath), "skills", "ccdx-image");
69
- const skillPath = path.join(skillDirectory, "SKILL.md");
70
- const helperPath = path.join(skillDirectory, "scripts", "generate.mjs");
71
- const references = REFERENCE_FILES.map((name) => ({ name, filePath: path.join(skillDirectory, "references", name) }));
72
- try {
73
- directoryCheck(skillDirectory);
74
- directoryCheck(path.dirname(helperPath));
75
- directoryCheck(path.join(skillDirectory, "references"));
76
- } catch (error) {
77
- if (!enabled && error?.code === "CCDX_IMAGE_SKILL_CONFLICT") {
78
- return { changed: false, preserved: true, skillPath, rollback: () => {} };
79
- }
80
- throw error;
81
- }
82
- const previousSkill = ownedSnapshot(skillPath, SKILL_MARKER, !enabled);
83
- const previousHelper = ownedSnapshot(helperPath, HELPER_MARKER, !enabled);
84
- for (const reference of references) reference.previous = ownedSnapshot(reference.filePath, REFERENCE_MARKER, !enabled);
85
- const snapshots = [[skillPath, previousSkill], [helperPath, previousHelper], ...references.map(({ filePath, previous }) => [filePath, previous])];
86
- const touched = [];
87
- let rolledBack = false;
88
- const rollback = () => {
89
- if (rolledBack) return;
90
- for (const [filePath, snapshot] of touched) {
91
- if (snapshot) atomicWriteFileSync(filePath, snapshot.content, { mode: snapshot.mode, preserveMode: false });
92
- else removeFile(filePath);
93
- }
94
- removeEmptyDirectories(skillDirectory);
95
- rolledBack = true;
96
- };
97
- if (!enabled) {
98
- const preserved = snapshots.some(([, snapshot]) => snapshot?.unowned);
99
- if (!snapshots.some(([, snapshot]) => snapshot?.content)) return { changed: false, preserved, skillPath, rollback: () => {} };
100
- try {
101
- for (const [filePath, snapshot] of snapshots) {
102
- if (!snapshot?.content) continue;
103
- touched.push([filePath, snapshot]);
104
- removeFile(filePath);
105
- }
106
- removeEmptyDirectories(skillDirectory);
107
- } catch (error) {
108
- rollback();
109
- throw error;
110
- }
111
- return { changed: true, preserved, skillPath, rollback };
112
- }
113
- const host = ["0.0.0.0", "::", "[::]"].includes(adapterHost) ? (adapterHost === "0.0.0.0" ? "127.0.0.1" : "::1") : adapterHost;
114
- const endpoint = `${adapterBaseUrl(host, adapterPort)}/mcp/image`;
115
- const skillBody = fs.readFileSync(new URL("./image-skill/SKILL.md", import.meta.url), "utf8");
116
- for (const reference of references) {
117
- const body = fs.readFileSync(new URL(`./image-skill/references/${reference.name}`, import.meta.url), "utf8")
118
- .replaceAll("{{NODE}}", () => quote(nodePath)).replaceAll("{{HELPER}}", () => quote(helperPath));
119
- reference.content = `<!-- ccdx:image-reference:${digest(body)} -->\n${body}`;
120
- }
121
- const skillContent = skillBody.replace("# CCDX image generation", `<!-- ccdx:image-skill:${digest(skillBody)} -->\n# CCDX image generation`);
122
- const helperBody = `${fs.readFileSync(new URL("./image-tool-client.mjs", import.meta.url), "utf8")}\ntry {\n await runImageToolClient({ endpoint: ${JSON.stringify(endpoint)} });\n} catch (error) {\n console.error(String(error?.message || "Image generation failed").replace(/[\\u0000-\\u001f\\u007f-\\u009f]/g, " ").slice(0, 1000));\n process.exitCode = 1;\n}\n`;
123
- const helperContent = `// ccdx:image-helper:${digest(helperBody)}\n${helperBody}`;
124
- if (previousSkill?.content === skillContent && previousHelper?.content === helperContent
125
- && references.every(({ previous, content }) => previous?.content === content)) {
126
- return { changed: false, skillPath, rollback: () => {} };
127
- }
128
- try {
129
- // Install conditional resources before publishing the skill entrypoint.
130
- for (const { filePath, previous, content } of references) {
131
- if (previous?.content === content) continue;
132
- touched.push([filePath, previous]);
133
- atomicWriteFileSync(filePath, content, { mode: 0o600, preserveMode: false });
134
- }
135
- atomicWriteFilePairSync(helperPath, helperContent, skillPath, skillContent, { mode: 0o600 });
136
- touched.push([helperPath, previousHelper], [skillPath, previousSkill]);
137
- } catch (error) {
138
- rollback();
139
- throw error;
140
- }
141
- return { changed: true, skillPath, rollback };
142
- }
@@ -1,150 +0,0 @@
1
- import fs from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { randomUUID } from "node:crypto";
5
-
6
- const IMAGE_SIZES = new Set(["1024x1024", "1536x1024", "1024x1536"]);
7
- const IMAGE_EXTENSIONS = new Map([["image/png", ".png"], ["image/jpeg", ".jpg"], ["image/webp", ".webp"]]);
8
- const MAX_IMAGE_BYTES = 32 * 1024 * 1024;
9
- const MAX_RESPONSE_BYTES = 48 * 1024 * 1024;
10
- const IMAGE_ID = /^ccdx_img_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
11
- const USAGE = "Usage: generate.mjs --prompt <text> [--image-id <previous-CCDX-image-id>] [--size 1024x1024|1536x1024|1024x1536] [--out <new-file>]";
12
-
13
- export function parseImageToolArgs(args = []) {
14
- if (args.length === 1 && ["--help", "-h"].includes(args[0])) return { help: true };
15
- const values = {};
16
- for (let index = 0; index < args.length; index += 2) {
17
- const option = args[index];
18
- if (!["--prompt", "--image-id", "--size", "--out"].includes(option) || option in values) throw new Error(USAGE);
19
- if (typeof args[index + 1] !== "string" || !args[index + 1].trim()) throw new Error(`Missing value for ${option}`);
20
- values[option] = args[index + 1];
21
- }
22
- const prompt = String(values["--prompt"] || "").trim();
23
- if (!prompt || prompt.length > 16_000) throw new Error("Image prompt must contain 1 to 16000 characters");
24
- const imageId = values["--image-id"]?.trim();
25
- if (imageId !== undefined && !IMAGE_ID.test(imageId)) throw new Error("Invalid CCDX image ID");
26
- const size = values["--size"] ? values["--size"].trim().toLowerCase() : (imageId ? undefined : "1024x1024");
27
- if (size !== undefined && !IMAGE_SIZES.has(size)) throw new Error("Unsupported image size");
28
- return { prompt, size, out: values["--out"], imageId };
29
- }
30
-
31
- function localImageEndpoint(value) {
32
- const endpoint = new URL(value);
33
- const host = endpoint.hostname.replace(/^\[|\]$/g, "");
34
- const localAddresses = Object.values(os.networkInterfaces()).flat().filter(Boolean).map(({ address }) => address);
35
- const local = host === "localhost" || host === "::1" || /^127\.\d+\.\d+\.\d+$/.test(host) || localAddresses.includes(host);
36
- if (!local || endpoint.protocol !== "http:" || endpoint.username || endpoint.password
37
- || endpoint.pathname !== "/mcp/image" || endpoint.search || endpoint.hash) {
38
- throw new Error("The CCDX image helper requires the configured local /mcp/image endpoint");
39
- }
40
- return endpoint.href;
41
- }
42
-
43
- function cleanError(value) {
44
- return String(value || "Image generation failed").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 1000);
45
- }
46
-
47
- async function readRpcResponse(response, expectedId) {
48
- if (!response.ok) throw new Error(`CCDX image service returned HTTP ${response.status}`);
49
- const declared = Number(response.headers.get("content-length"));
50
- if (Number.isFinite(declared) && declared > MAX_RESPONSE_BYTES) {
51
- await response.body?.cancel();
52
- throw new Error("CCDX image response exceeds the size limit");
53
- }
54
- const chunks = [];
55
- let bytes = 0;
56
- for await (const chunk of response.body) {
57
- bytes += chunk.byteLength;
58
- if (bytes > MAX_RESPONSE_BYTES) throw new Error("CCDX image response exceeds the size limit");
59
- chunks.push(Buffer.from(chunk));
60
- }
61
- let body;
62
- try { body = JSON.parse(Buffer.concat(chunks, bytes).toString("utf8")); }
63
- catch { throw new Error("CCDX image service returned invalid JSON"); }
64
- if (body?.jsonrpc !== "2.0" || body.id !== expectedId) throw new Error("CCDX image service returned an invalid JSON-RPC response");
65
- if (body.error) throw new Error(cleanError(body.error.message));
66
- if (!body.result || typeof body.result !== "object") throw new Error("CCDX image service returned no result");
67
- return body.result;
68
- }
69
-
70
- function assertNewOutput(filePath) {
71
- try {
72
- fs.lstatSync(filePath);
73
- throw new Error(`Image output already exists: ${filePath}`);
74
- } catch (error) {
75
- if (error?.code !== "ENOENT") throw error;
76
- }
77
- }
78
-
79
- export async function runImageToolClient({
80
- endpoint,
81
- args = process.argv.slice(2),
82
- cwd = process.cwd(),
83
- fetchImpl = fetch,
84
- output = process.stdout,
85
- metadataOutput = process.stderr,
86
- signal = AbortSignal.timeout(210_000),
87
- } = {}) {
88
- const options = parseImageToolArgs(args);
89
- if (options.help) {
90
- output.write(`${USAGE}\n`);
91
- return null;
92
- }
93
- const url = localImageEndpoint(endpoint);
94
- const requestedOutput = options.out ? path.resolve(cwd, options.out) : null;
95
- if (requestedOutput) assertNewOutput(requestedOutput);
96
- const directory = requestedOutput ? path.dirname(requestedOutput) : path.resolve(cwd, "output", "imagegen");
97
- fs.mkdirSync(directory, { recursive: true });
98
- fs.accessSync(directory, fs.constants.W_OK);
99
- const headers = { "Content-Type": "application/json", Accept: "application/json, text/event-stream" };
100
- const post = (body) => fetchImpl(url, {
101
- method: "POST", headers, body: JSON.stringify(body), redirect: "error", signal,
102
- });
103
- try {
104
- const initialized = await post({
105
- jsonrpc: "2.0", id: 1, method: "initialize",
106
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "ccdx-image-helper", version: "1" } },
107
- });
108
- const sessionId = initialized.headers.get("mcp-session-id");
109
- const server = await readRpcResponse(initialized, 1);
110
- if (server.serverInfo?.name !== "ccdx-image") throw new Error("The configured local service is not CCDX image generation");
111
- headers["MCP-Protocol-Version"] = server.protocolVersion || "2025-06-18";
112
- if (sessionId) headers["Mcp-Session-Id"] = sessionId;
113
- const notified = await post({ jsonrpc: "2.0", method: "notifications/initialized" });
114
- await notified.body?.cancel();
115
- if (!notified.ok) throw new Error(`CCDX image initialization returned HTTP ${notified.status}`);
116
- } catch (error) {
117
- const code = error.cause?.code || error.code;
118
- const detail = ["EPERM", "EACCES"].includes(code)
119
- ? "Local network access was denied. Request normal execution permission for this helper command."
120
- : cleanError(error.message);
121
- throw Object.assign(new Error(`Image ${options.imageId ? "editing" : "generation"} has not started: ${detail}`), { code: "CCDX_IMAGE_NOT_STARTED" });
122
- }
123
- const argumentsValue = { prompt: options.prompt };
124
- if (options.size !== undefined) argumentsValue.size = options.size;
125
- if (options.imageId) argumentsValue.image_id = options.imageId;
126
- const result = await readRpcResponse(await post({
127
- jsonrpc: "2.0", id: 2, method: "tools/call",
128
- params: { name: options.imageId ? "edit_image" : "generate_image", arguments: argumentsValue, _meta: { "ccdx/client_saves_image": true } },
129
- }), 2);
130
- if (result.isError) {
131
- throw new Error(cleanError(result.content?.find((part) => part.type === "text")?.text));
132
- }
133
- const image = result.content?.find((part) => part.type === "image");
134
- const extension = IMAGE_EXTENSIONS.get(image?.mimeType);
135
- if (!extension || typeof image.data !== "string" || !image.data
136
- || image.data.length > Math.ceil(MAX_IMAGE_BYTES / 3) * 4
137
- || !/^[A-Za-z0-9+/]+={0,2}$/.test(image.data)) {
138
- throw new Error("CCDX image service returned an invalid image");
139
- }
140
- const bytes = Buffer.from(image.data, "base64");
141
- if (!bytes.length || bytes.length > MAX_IMAGE_BYTES || bytes.toString("base64") !== image.data) {
142
- throw new Error("CCDX image service returned an invalid image");
143
- }
144
- const filePath = requestedOutput || path.join(directory, `image-${randomUUID()}${extension}`);
145
- fs.writeFileSync(filePath, bytes, { flag: "wx", mode: 0o600 });
146
- output.write(`${filePath}\n`);
147
- const imageId = result._meta?.["ccdx/image_id"];
148
- if (typeof imageId === "string" && IMAGE_ID.test(imageId)) metadataOutput.write(`CCDX image_id: ${imageId}\n`);
149
- return filePath;
150
- }