@zseven-w/qoder-openpencil 0.0.0-stage → 0.1.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/INSTALL.md +77 -0
- package/LICENSE +21 -0
- package/NOTICE +10 -0
- package/README.md +46 -2
- package/README.zh.md +38 -0
- package/THIRD_PARTY_NOTICES.md +69 -0
- package/bin/qoder-openpencil.mjs +90 -0
- package/package.json +71 -4
- package/platforms.json +65 -0
- package/plugins/openpencil/.mcp.json +10 -0
- package/plugins/openpencil/.qoder-plugin/plugin.json +19 -0
- package/plugins/openpencil/CONNECTORS.md +9 -0
- package/plugins/openpencil/LICENSE +21 -0
- package/plugins/openpencil/NOTICE +10 -0
- package/plugins/openpencil/assets/icon.png +0 -0
- package/plugins/openpencil/assets/logo.png +0 -0
- package/plugins/openpencil/mcp.json +11 -0
- package/plugins/openpencil/plugin.json +19 -0
- package/plugins/openpencil/scripts/browser-launch.mjs +37 -0
- package/plugins/openpencil/scripts/canvas-codegen.mjs +141 -0
- package/plugins/openpencil/scripts/canvas-controller.mjs +293 -0
- package/plugins/openpencil/scripts/canvas-images.mjs +93 -0
- package/plugins/openpencil/scripts/canvas-panel.mjs +82 -0
- package/plugins/openpencil/scripts/canvas-selection.mjs +61 -0
- package/plugins/openpencil/scripts/document-format.mjs +48 -0
- package/plugins/openpencil/scripts/editor-runtime.mjs +453 -0
- package/plugins/openpencil/scripts/editor-session.mjs +230 -0
- package/plugins/openpencil/scripts/launch-mcp +22 -0
- package/plugins/openpencil/scripts/launch-mcp.cmd +21 -0
- package/plugins/openpencil/scripts/mcp-bridge.mjs +70 -0
- package/plugins/openpencil/scripts/runtime-install.mjs +128 -0
- package/plugins/openpencil/scripts/transport.mjs +138 -0
- package/plugins/openpencil/skills/openpencil-design/SKILL.md +125 -0
- package/plugins/openpencil/skills/openpencil-design/references/codegen.md +34 -0
- package/plugins/openpencil/skills/openpencil-design/references/images.md +54 -0
- package/plugins/openpencil/skills/openpencil-design/references/node-schema.md +208 -0
- package/plugins/openpencil/skills/openpencil-setup/SKILL.md +59 -0
- package/plugins/openpencil/ui/app.html +226 -0
- package/plugins/openpencil/ui/codegen.js +80 -0
- package/plugins/openpencil/ui/panel.css +311 -0
- package/plugins/openpencil/ui/panel.html +11 -0
- package/plugins/openpencil/ui/panel.js +219 -0
- package/plugins/openpencil/ui/selection.js +19 -0
- package/scripts/build-editor-runtime.mjs +35 -0
- package/scripts/canvas.mjs +75 -0
- package/scripts/check-package.mjs +81 -0
- package/scripts/check-release-version.mjs +53 -0
- package/scripts/collab-bootstrap-config.mjs +66 -0
- package/scripts/configure-runtime.mjs +15 -0
- package/scripts/host-config.mjs +352 -0
- package/scripts/managed-handshake.mjs +23 -0
- package/scripts/node-registration.mjs +17 -0
- package/scripts/pack-package.mjs +41 -0
- package/scripts/pack-plugin.mjs +166 -0
- package/scripts/platforms.mjs +84 -0
- package/scripts/plugin-host-check.mjs +174 -0
- package/scripts/publish-release.mjs +294 -0
- package/scripts/registry-convergence.mjs +40 -0
- package/scripts/setup.mjs +147 -0
- package/scripts/stage-editor-runtime.mjs +189 -0
- package/scripts/sync-platform-versions.mjs +63 -0
- package/scripts/verify-platform-packages.mjs +270 -0
- package/scripts/verify-selective-install.mjs +219 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { CANVAS_URI } from '../plugins/openpencil/scripts/canvas-controller.mjs';
|
|
6
|
+
import { inspectQoderRegistration, launcherPathForPlugin } from './host-config.mjs';
|
|
7
|
+
|
|
8
|
+
const defaultPluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../plugins/openpencil');
|
|
9
|
+
|
|
10
|
+
/** Spawn the launcher under a minimal GUI-like PATH and verify MCP handshake, Qoder entrypoints, and UI resource. */
|
|
11
|
+
export async function probeLauncher({
|
|
12
|
+
command,
|
|
13
|
+
args = [],
|
|
14
|
+
cwd,
|
|
15
|
+
env = process.env,
|
|
16
|
+
timeoutMs = 15_000,
|
|
17
|
+
} = {}) {
|
|
18
|
+
const minimalPath = process.platform === 'win32'
|
|
19
|
+
? (env.SystemRoot ? `${env.SystemRoot}\\System32;${env.SystemRoot}` : env.PATH || '')
|
|
20
|
+
: '/usr/bin:/bin';
|
|
21
|
+
const isWindowsCmd = process.platform === 'win32' && /\.cmd$/i.test(command);
|
|
22
|
+
const spawnCmd = isWindowsCmd ? (env.COMSPEC || 'cmd.exe') : command;
|
|
23
|
+
const spawnArgs = isWindowsCmd ? ['/d', '/c', command, ...args] : args;
|
|
24
|
+
const child = spawn(spawnCmd, spawnArgs, {
|
|
25
|
+
cwd,
|
|
26
|
+
env: {
|
|
27
|
+
HOME: env.HOME,
|
|
28
|
+
USERPROFILE: env.USERPROFILE,
|
|
29
|
+
SystemRoot: env.SystemRoot,
|
|
30
|
+
SystemDrive: env.SystemDrive,
|
|
31
|
+
COMSPEC: env.COMSPEC,
|
|
32
|
+
PATHEXT: env.PATHEXT,
|
|
33
|
+
TMPDIR: env.TMPDIR,
|
|
34
|
+
TEMP: env.TEMP,
|
|
35
|
+
OPENPENCIL_QODER_STATE_DIR: env.OPENPENCIL_QODER_STATE_DIR,
|
|
36
|
+
OPENPENCIL_EDITOR_RUNTIME_DIR: env.OPENPENCIL_EDITOR_RUNTIME_DIR,
|
|
37
|
+
PATH: minimalPath,
|
|
38
|
+
},
|
|
39
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
40
|
+
});
|
|
41
|
+
const closed = new Promise(resolveClosed => {
|
|
42
|
+
child.once('close', resolveClosed);
|
|
43
|
+
child.once('error', resolveClosed);
|
|
44
|
+
});
|
|
45
|
+
let stderr = '';
|
|
46
|
+
child.stderr.setEncoding('utf8');
|
|
47
|
+
child.stderr.on('data', chunk => { stderr = (stderr + chunk).slice(-8192); });
|
|
48
|
+
|
|
49
|
+
const replies = new Map();
|
|
50
|
+
let buffer = '';
|
|
51
|
+
child.stdout.setEncoding('utf8');
|
|
52
|
+
child.stdout.on('data', chunk => {
|
|
53
|
+
buffer += chunk;
|
|
54
|
+
let newline;
|
|
55
|
+
while ((newline = buffer.indexOf('\n')) !== -1) {
|
|
56
|
+
const line = buffer.slice(0, newline).trim();
|
|
57
|
+
buffer = buffer.slice(newline + 1);
|
|
58
|
+
if (!line) continue;
|
|
59
|
+
try {
|
|
60
|
+
const message = JSON.parse(line);
|
|
61
|
+
const waiter = replies.get(message.id);
|
|
62
|
+
if (waiter) {
|
|
63
|
+
replies.delete(message.id);
|
|
64
|
+
clearTimeout(waiter.timer);
|
|
65
|
+
waiter.resolve(message);
|
|
66
|
+
}
|
|
67
|
+
} catch { /* Handled by timeout if malformed. */ }
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const rpc = (id, method, params = {}) => new Promise((resolvePromise, rejectPromise) => {
|
|
72
|
+
const timer = setTimeout(() => {
|
|
73
|
+
replies.delete(id);
|
|
74
|
+
rejectPromise(new Error(`Launcher timed out waiting for ${method}${stderr ? `: ${stderr.trim()}` : ''}`));
|
|
75
|
+
}, timeoutMs);
|
|
76
|
+
replies.set(id, { resolve: resolvePromise, reject: rejectPromise, timer });
|
|
77
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const init = await rpc(1, 'initialize', { protocolVersion: '2025-11-25', clientInfo: { name: 'qoder-host-check', version: '1.0.0' }, capabilities: {} });
|
|
82
|
+
if (init.error || !init.result?.capabilities?.tools) {
|
|
83
|
+
throw new Error(`MCP initialize failed: ${init.error?.message || 'missing capabilities'}`);
|
|
84
|
+
}
|
|
85
|
+
const toolsReply = await rpc(2, 'tools/list', {});
|
|
86
|
+
const tools = toolsReply.result?.tools || [];
|
|
87
|
+
const toolNames = tools.map(tool => tool.name);
|
|
88
|
+
for (const required of ['open_canvas', 'canvas_open_browser', 'canvas_status', 'canvas_selection', 'canvas_save', 'canvas_import_image']) {
|
|
89
|
+
if (!toolNames.includes(required)) throw new Error(`Missing required canvas tool: ${required}`);
|
|
90
|
+
}
|
|
91
|
+
const openTool = tools.find(tool => tool.name === 'open_canvas');
|
|
92
|
+
const entrypoints = openTool?._meta?.['qoder/ui']?.entrypoints?.map(entry => entry.type) || [];
|
|
93
|
+
if (!entrypoints.includes('global') || !entrypoints.includes('thread')) {
|
|
94
|
+
throw new Error('open_canvas is missing required qoder/ui global and thread entrypoints');
|
|
95
|
+
}
|
|
96
|
+
const resourcesReply = await rpc(3, 'resources/list', {});
|
|
97
|
+
const resource = (resourcesReply.result?.resources || []).find(item => item.uri === CANVAS_URI);
|
|
98
|
+
if (!resource || resource.mimeType !== 'text/html;profile=mcp-app') {
|
|
99
|
+
throw new Error(`Missing MCP App UI resource ${CANVAS_URI}`);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
ok: true,
|
|
103
|
+
serverInfo: init.result.serverInfo,
|
|
104
|
+
canvasTools: toolNames.filter(name => name === 'open_canvas' || name.startsWith('canvas_')),
|
|
105
|
+
qoderEntrypoints: entrypoints,
|
|
106
|
+
resourceUri: resource.uri,
|
|
107
|
+
mimeType: resource.mimeType,
|
|
108
|
+
};
|
|
109
|
+
} finally {
|
|
110
|
+
child.stdin.end();
|
|
111
|
+
if (process.platform !== 'win32') {
|
|
112
|
+
child.kill('SIGTERM');
|
|
113
|
+
}
|
|
114
|
+
const killTimer = setTimeout(() => {
|
|
115
|
+
if (process.platform === 'win32' && child.pid) {
|
|
116
|
+
const killer = spawn('taskkill', ['/pid', String(child.pid), '/t', '/f'], { stdio: 'ignore' });
|
|
117
|
+
killer.on('error', () => { child.kill(); });
|
|
118
|
+
} else {
|
|
119
|
+
child.kill('SIGKILL');
|
|
120
|
+
}
|
|
121
|
+
}, 1000);
|
|
122
|
+
let fallbackTimer;
|
|
123
|
+
const fallback = new Promise(resolveFallback => {
|
|
124
|
+
fallbackTimer = setTimeout(resolveFallback, 3000);
|
|
125
|
+
});
|
|
126
|
+
await Promise.race([closed, fallback]);
|
|
127
|
+
clearTimeout(killTimer);
|
|
128
|
+
clearTimeout(fallbackTimer);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function verifyPluginHost({ configDir, pluginRoot = defaultPluginRoot, env = process.env, home } = {}) {
|
|
133
|
+
const registration = await inspectQoderRegistration({ configDir, env, home });
|
|
134
|
+
const installedRoot = registration.pluginRecord?.installPath;
|
|
135
|
+
const command = installedRoot
|
|
136
|
+
? launcherPathForPlugin(installedRoot)
|
|
137
|
+
: (registration.mcpEntry?.command || launcherPathForPlugin(pluginRoot));
|
|
138
|
+
const args = installedRoot
|
|
139
|
+
? []
|
|
140
|
+
: (Array.isArray(registration.mcpEntry?.args) ? registration.mcpEntry.args : []);
|
|
141
|
+
const cwd = installedRoot || registration.mcpEntry?.cwd || resolve(pluginRoot);
|
|
142
|
+
if (!existsSync(command)) {
|
|
143
|
+
throw new Error(`Registered launcher does not exist: ${command}`);
|
|
144
|
+
}
|
|
145
|
+
const probe = await probeLauncher({ command, args, cwd, env });
|
|
146
|
+
return {
|
|
147
|
+
ok: true,
|
|
148
|
+
pluginRegistered: registration.pluginRegistered,
|
|
149
|
+
pluginEnabled: registration.pluginEnabled,
|
|
150
|
+
mcpSettingsRegistered: registration.mcpSettingsRegistered,
|
|
151
|
+
configDir: registration.configDir,
|
|
152
|
+
command,
|
|
153
|
+
skills: registration.skills,
|
|
154
|
+
probe,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export async function runHostCheck(args = process.argv.slice(2)) {
|
|
159
|
+
let configDir;
|
|
160
|
+
for (let i = 0; i < args.length; i++) {
|
|
161
|
+
if (args[i] === '--config-dir' && args[i + 1]) configDir = args[++i];
|
|
162
|
+
else throw new Error('Usage: qoder-openpencil host-check [--config-dir PATH]');
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
console.log(JSON.stringify(await verifyPluginHost({ configDir }), null, 2));
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error(`OpenPencil Qoder host check failed: ${error.message}`);
|
|
168
|
+
process.exitCode = 1;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
173
|
+
await runHostCheck(process.argv.slice(2));
|
|
174
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
|
+
import { publishAndVerify } from './registry-convergence.mjs';
|
|
9
|
+
import { platforms } from './platforms.mjs';
|
|
10
|
+
|
|
11
|
+
if (process.argv.includes('--self-test')) runSelfTest();
|
|
12
|
+
else await main(resolve(process.argv[2] ?? 'artifacts'));
|
|
13
|
+
|
|
14
|
+
async function main(artifactRoot) {
|
|
15
|
+
const reports = await readReports(artifactRoot);
|
|
16
|
+
const expectedNames = ['@zseven-w/qoder-openpencil', ...platforms.map(platform => platform.packageName)];
|
|
17
|
+
if (reports.length !== expectedNames.length) {
|
|
18
|
+
throw new Error(`expected exactly ${expectedNames.length} package reports, found ${reports.length}`);
|
|
19
|
+
}
|
|
20
|
+
const byName = new Map();
|
|
21
|
+
for (const report of reports) {
|
|
22
|
+
if (!expectedNames.includes(report.name)) throw new Error(`unexpected package report ${report.name}`);
|
|
23
|
+
if (byName.has(report.name)) throw new Error(`duplicate package report ${report.name}`);
|
|
24
|
+
await verifyReportIntegrity(report);
|
|
25
|
+
byName.set(report.name, report);
|
|
26
|
+
}
|
|
27
|
+
const root = byName.get('@zseven-w/qoder-openpencil');
|
|
28
|
+
if (root === undefined) throw new Error('root package tarball is missing');
|
|
29
|
+
const native = platforms.map(platform => {
|
|
30
|
+
const report = byName.get(platform.packageName);
|
|
31
|
+
if (report === undefined) throw new Error(`${platform.packageName} tarball is missing`);
|
|
32
|
+
return report;
|
|
33
|
+
});
|
|
34
|
+
for (const report of [...native, root]) {
|
|
35
|
+
if (report.version !== root.version) throw new Error(`${report.name} version differs from root ${root.version}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Every release takes `latest`, prereleases included (see qoder-release.yml).
|
|
39
|
+
const tag = 'latest';
|
|
40
|
+
const releaseReports = [...native, root];
|
|
41
|
+
// Complete read-only preflight before the first registry mutation so an old,
|
|
42
|
+
// partially published release cannot move a shared latest tag backward.
|
|
43
|
+
const canRepairExistingTag = Boolean(process.env.NODE_AUTH_TOKEN?.trim());
|
|
44
|
+
preflightRelease(releaseReports, tag, report => readReleaseState(report, tag), canRepairExistingTag);
|
|
45
|
+
for (const report of releaseReports) await publishOrVerify(report, tag, canRepairExistingTag);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function publishOrVerify(report, tag, canRepairExistingTag) {
|
|
49
|
+
const specifier = `${report.name}@${report.version}`;
|
|
50
|
+
const { existing, currentTag } = readReleaseState(report, tag);
|
|
51
|
+
assertSafeReleaseState(report, tag, { existing, currentTag }, canRepairExistingTag);
|
|
52
|
+
if (existing !== undefined) {
|
|
53
|
+
if (existing !== report.integrity) {
|
|
54
|
+
throw new Error(`${specifier} already exists with different integrity (${existing} != ${report.integrity})`);
|
|
55
|
+
}
|
|
56
|
+
const action = tagAction(currentTag, report.version, true);
|
|
57
|
+
if (action === 'advance') {
|
|
58
|
+
runNpm(['dist-tag', 'add', specifier, tag]);
|
|
59
|
+
await waitForDistTag(report.name, report.version, tag);
|
|
60
|
+
process.stdout.write(`${specifier} already published with matching integrity; advanced dist-tag ${tag}\n`);
|
|
61
|
+
} else {
|
|
62
|
+
process.stdout.write(
|
|
63
|
+
`${specifier} already published with matching integrity; `
|
|
64
|
+
+ (action === 'skip-newer'
|
|
65
|
+
? `kept newer dist-tag ${tag}=${currentTag}\n`
|
|
66
|
+
: `dist-tag ${tag} already matches\n`),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const action = tagAction(currentTag, report.version, false);
|
|
73
|
+
if (action === 'refuse-missing-older' || action === 'refuse-inconsistent') {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`${specifier} is not published while dist-tag ${tag} points to ${JSON.stringify(currentTag)}; `
|
|
76
|
+
+ 'refusing to publish because the shared tag would move backward or registry state is inconsistent',
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const tarball = join(report.directory, report.filename);
|
|
81
|
+
await publishAndVerify({
|
|
82
|
+
specifier, version: report.version, integrity: report.integrity, tag,
|
|
83
|
+
publish: () => npmResult(['publish', tarball, '--access=public', `--tag=${tag}`, '--provenance']),
|
|
84
|
+
readState: () => ({ integrity: registryIntegrity(specifier), tag: distTagVersion(report.name, tag) }),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function readReleaseState(report, tag) {
|
|
89
|
+
return {
|
|
90
|
+
existing: registryIntegrity(`${report.name}@${report.version}`),
|
|
91
|
+
currentTag: distTagVersion(report.name, tag),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function assertSafeReleaseState(report, tag, state, canRepairExistingTag) {
|
|
96
|
+
const specifier = `${report.name}@${report.version}`;
|
|
97
|
+
if (state.existing !== undefined && state.existing !== report.integrity) {
|
|
98
|
+
throw new Error(`${specifier} already exists with different integrity (${state.existing} != ${report.integrity})`);
|
|
99
|
+
}
|
|
100
|
+
const action = tagAction(state.currentTag, report.version, state.existing !== undefined);
|
|
101
|
+
if (action === 'refuse-missing-older' || action === 'refuse-inconsistent') {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`${specifier} is not published while dist-tag ${tag} points to ${JSON.stringify(state.currentTag)}; `
|
|
104
|
+
+ 'refusing the entire seven-package release before mutation because the shared tag would move backward or registry state is inconsistent',
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (action === 'advance' && state.existing !== undefined && !canRepairExistingTag) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`${specifier} needs dist-tag ${tag} recovery before the release can continue: recovery requires NPM_TOKEN `
|
|
110
|
+
+ '(NODE_AUTH_TOKEN); trusted publishing covers new npm publish but not npm dist-tag add',
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return action;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function preflightRelease(reports, tag, stateFor, canRepairExistingTag) {
|
|
117
|
+
const states = new Map();
|
|
118
|
+
for (const report of reports) {
|
|
119
|
+
const state = stateFor(report);
|
|
120
|
+
const action = assertSafeReleaseState(report, tag, state, canRepairExistingTag);
|
|
121
|
+
states.set(report.name, { ...state, action });
|
|
122
|
+
}
|
|
123
|
+
return states;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function distTagVersion(name, tag) {
|
|
127
|
+
const result = npmResult(['view', name, 'dist-tags', '--json']);
|
|
128
|
+
if (result.status !== 0) {
|
|
129
|
+
const output = result.stderr + result.stdout;
|
|
130
|
+
if (/E404|404 Not Found/u.test(output)) return undefined;
|
|
131
|
+
throw new Error(`npm view ${name} dist-tags failed:\n${output}`);
|
|
132
|
+
}
|
|
133
|
+
const tags = JSON.parse(result.stdout);
|
|
134
|
+
return tags?.[tag];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function waitForDistTag(name, version, tag) {
|
|
138
|
+
let current;
|
|
139
|
+
for (let attempt = 1; attempt <= 30; attempt += 1) {
|
|
140
|
+
current = distTagVersion(name, tag);
|
|
141
|
+
if (current === version) return;
|
|
142
|
+
process.stdout.write(`${name}: waiting for dist-tag ${tag}=${version}; current=${JSON.stringify(current)} (${attempt}/30)\n`);
|
|
143
|
+
if (attempt < 30) await delay(10_000);
|
|
144
|
+
}
|
|
145
|
+
throw new Error(`${name}: dist-tag ${tag} did not converge to ${version}; current=${JSON.stringify(current)}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function tagAction(current, target, exists) {
|
|
149
|
+
if (current === undefined) return exists ? 'advance' : 'publish-shared';
|
|
150
|
+
const comparison = compareSemVer(current, target);
|
|
151
|
+
if (comparison > 0) return exists ? 'skip-newer' : 'refuse-missing-older';
|
|
152
|
+
if (comparison === 0) return exists ? 'skip-equal' : 'refuse-inconsistent';
|
|
153
|
+
return exists ? 'advance' : 'publish-shared';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function compareSemVer(left, right) {
|
|
157
|
+
const a = parseSemVer(left);
|
|
158
|
+
const b = parseSemVer(right);
|
|
159
|
+
for (const field of ['major', 'minor', 'patch']) {
|
|
160
|
+
if (a[field] !== b[field]) return a[field] < b[field] ? -1 : 1;
|
|
161
|
+
}
|
|
162
|
+
if (a.prerelease.length === 0 || b.prerelease.length === 0) {
|
|
163
|
+
if (a.prerelease.length === b.prerelease.length) return 0;
|
|
164
|
+
return a.prerelease.length === 0 ? 1 : -1;
|
|
165
|
+
}
|
|
166
|
+
const count = Math.max(a.prerelease.length, b.prerelease.length);
|
|
167
|
+
for (let index = 0; index < count; index += 1) {
|
|
168
|
+
const leftId = a.prerelease[index];
|
|
169
|
+
const rightId = b.prerelease[index];
|
|
170
|
+
if (leftId === undefined || rightId === undefined) {
|
|
171
|
+
if (leftId === rightId) return 0;
|
|
172
|
+
return leftId === undefined ? -1 : 1;
|
|
173
|
+
}
|
|
174
|
+
if (leftId === rightId) continue;
|
|
175
|
+
const leftNumeric = /^\d+$/u.test(leftId);
|
|
176
|
+
const rightNumeric = /^\d+$/u.test(rightId);
|
|
177
|
+
if (leftNumeric && rightNumeric) return BigInt(leftId) < BigInt(rightId) ? -1 : 1;
|
|
178
|
+
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
|
|
179
|
+
return leftId < rightId ? -1 : 1;
|
|
180
|
+
}
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function parseSemVer(value) {
|
|
185
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u.exec(value);
|
|
186
|
+
if (match === null) throw new Error(`registry returned invalid semantic version ${JSON.stringify(value)}`);
|
|
187
|
+
const prerelease = match[4]?.split('.') ?? [];
|
|
188
|
+
if (prerelease.some(identifier => /^\d+$/u.test(identifier) && identifier.length > 1 && identifier.startsWith('0'))) {
|
|
189
|
+
throw new Error(`registry returned invalid semantic version ${JSON.stringify(value)}`);
|
|
190
|
+
}
|
|
191
|
+
return { major: BigInt(match[1]), minor: BigInt(match[2]), patch: BigInt(match[3]), prerelease };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function runSelfTest() {
|
|
195
|
+
const comparisons = [
|
|
196
|
+
['0.3.13-rc.2', '0.3.13-rc.10', -1],
|
|
197
|
+
['0.3.13-rc.10', '0.3.13', -1],
|
|
198
|
+
['1.0.0-alpha', '1.0.0-alpha.1', -1],
|
|
199
|
+
['1.0.0-alpha.1', '1.0.0-alpha.beta', -1],
|
|
200
|
+
['1.2.3', '1.2.3', 0],
|
|
201
|
+
['2.0.0', '1.99.99', 1],
|
|
202
|
+
];
|
|
203
|
+
for (const [left, right, expected] of comparisons) {
|
|
204
|
+
assert.equal(Math.sign(compareSemVer(left, right)), expected, `${left} versus ${right}`);
|
|
205
|
+
assert.equal(Math.sign(compareSemVer(right, left)), expected === 0 ? 0 : -expected, `${right} versus ${left}`);
|
|
206
|
+
}
|
|
207
|
+
assert.equal(tagAction(undefined, '0.3.14-rc.3', true), 'advance');
|
|
208
|
+
assert.equal(tagAction('0.3.14-rc.2', '0.3.14-rc.3', true), 'advance');
|
|
209
|
+
assert.equal(tagAction('0.3.14-rc.3', '0.3.14-rc.3', true), 'skip-equal');
|
|
210
|
+
assert.equal(tagAction('0.3.14-rc.4', '0.3.14-rc.3', true), 'skip-newer');
|
|
211
|
+
assert.equal(tagAction(undefined, '0.3.14-rc.3', false), 'publish-shared');
|
|
212
|
+
assert.equal(tagAction('0.3.14-rc.2', '0.3.14-rc.3', false), 'publish-shared');
|
|
213
|
+
assert.equal(tagAction('0.3.14-rc.3', '0.3.14-rc.3', false), 'refuse-inconsistent');
|
|
214
|
+
assert.equal(tagAction('0.3.14-rc.4', '0.3.14-rc.3', false), 'refuse-missing-older');
|
|
215
|
+
|
|
216
|
+
const fixtureReports = [
|
|
217
|
+
{ name: 'native-first', version: '0.3.14-rc.3', integrity: 'sha512-first' },
|
|
218
|
+
{ name: 'root-last', version: '0.3.14-rc.3', integrity: 'sha512-root' },
|
|
219
|
+
];
|
|
220
|
+
let mutations = 0;
|
|
221
|
+
assert.throws(() => {
|
|
222
|
+
preflightRelease(fixtureReports, 'next', report => (
|
|
223
|
+
report.name === 'native-first'
|
|
224
|
+
? { existing: undefined, currentTag: '0.3.14-rc.2' }
|
|
225
|
+
: { existing: undefined, currentTag: '0.3.14-rc.4' }
|
|
226
|
+
), false);
|
|
227
|
+
for (const _report of fixtureReports) mutations += 1;
|
|
228
|
+
}, /refusing the entire seven-package release before mutation/);
|
|
229
|
+
assert.equal(mutations, 0, 'a later preflight refusal must prevent every publish mutation');
|
|
230
|
+
|
|
231
|
+
assert.throws(
|
|
232
|
+
() => preflightRelease(
|
|
233
|
+
fixtureReports,
|
|
234
|
+
'next',
|
|
235
|
+
report => ({ existing: report.integrity, currentTag: '0.3.14-rc.2' }),
|
|
236
|
+
false,
|
|
237
|
+
),
|
|
238
|
+
/recovery requires NPM_TOKEN.*trusted publishing covers new npm publish but not npm dist-tag add/,
|
|
239
|
+
);
|
|
240
|
+
const repairPlan = preflightRelease(
|
|
241
|
+
fixtureReports,
|
|
242
|
+
'next',
|
|
243
|
+
report => ({ existing: report.integrity, currentTag: '0.3.14-rc.2' }),
|
|
244
|
+
true,
|
|
245
|
+
);
|
|
246
|
+
assert.equal(repairPlan.get('root-last')?.action, 'advance');
|
|
247
|
+
process.stdout.write('publish release SemVer/dist-tag fixtures passed\n');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function registryIntegrity(specifier) {
|
|
251
|
+
const result = npmResult(['view', specifier, 'dist.integrity', '--json']);
|
|
252
|
+
if (result.status === 0) {
|
|
253
|
+
const value = JSON.parse(result.stdout);
|
|
254
|
+
return typeof value === 'string' ? value : undefined;
|
|
255
|
+
}
|
|
256
|
+
const output = result.stderr + result.stdout;
|
|
257
|
+
if (/E404|404 Not Found/u.test(output)) return undefined;
|
|
258
|
+
throw new Error(`npm view ${specifier} failed:\n${output}`);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function runNpm(args) {
|
|
262
|
+
const result = npmResult(args);
|
|
263
|
+
if (result.status !== 0) throw new Error(`npm ${args.join(' ')} failed:\n${result.stderr || result.stdout}`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function npmResult(args) {
|
|
267
|
+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
268
|
+
return spawnSync(npm, args, {
|
|
269
|
+
encoding: 'utf8',
|
|
270
|
+
env: { ...process.env, npm_config_cache: join(tmpdir(), 'qoder-openpencil-npm-cache') },
|
|
271
|
+
shell: process.platform === 'win32',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function verifyReportIntegrity(report) {
|
|
276
|
+
const tarball = await readFile(join(report.directory, report.filename));
|
|
277
|
+
const integrity = `sha512-${createHash('sha512').update(tarball).digest('base64')}`;
|
|
278
|
+
const shasum = createHash('sha1').update(tarball).digest('hex');
|
|
279
|
+
if (report.integrity !== integrity || report.shasum !== shasum) {
|
|
280
|
+
throw new Error(`${report.name}@${report.version}: report integrity does not match tarball`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function readReports(directory) {
|
|
285
|
+
const output = [];
|
|
286
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
287
|
+
const path = join(directory, entry.name);
|
|
288
|
+
if (entry.isDirectory()) output.push(...await readReports(path));
|
|
289
|
+
else if (entry.name.endsWith('.tgz.json')) {
|
|
290
|
+
output.push({ ...JSON.parse(await readFile(path, 'utf8')), directory });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return output;
|
|
294
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
|
|
3
|
+
export const REGISTRY_TIMEOUT_MS = 30 * 60 * 1000;
|
|
4
|
+
|
|
5
|
+
// A staged conflict is an acknowledgement to wait, never proof of publication.
|
|
6
|
+
// Only matching visible integrity AND the expected tag complete the release.
|
|
7
|
+
export async function publishAndVerify({
|
|
8
|
+
specifier, version, integrity, tag, publish, readState,
|
|
9
|
+
timeoutMs = REGISTRY_TIMEOUT_MS, pollMs = 10_000,
|
|
10
|
+
now = Date.now, wait = delay, log = line => process.stdout.write(line + '\n'),
|
|
11
|
+
}) {
|
|
12
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || !Number.isFinite(pollMs) || pollMs <= 0) {
|
|
13
|
+
throw new Error('registry convergence timeout and poll interval must be positive');
|
|
14
|
+
}
|
|
15
|
+
const result = publish();
|
|
16
|
+
if (result.status !== 0) {
|
|
17
|
+
const output = String(result.stderr ?? '') + String(result.stdout ?? '');
|
|
18
|
+
if (!/409/u.test(output) || !/Cannot publish over previously staged version/iu.test(output)) {
|
|
19
|
+
throw new Error(`${specifier}: npm publish failed: ${output || result.error?.message || result.signal || result.status}`);
|
|
20
|
+
}
|
|
21
|
+
log(`${specifier} is already staged; waiting for registry confirmation`);
|
|
22
|
+
}
|
|
23
|
+
const deadline = now() + timeoutMs;
|
|
24
|
+
let state;
|
|
25
|
+
for (;;) {
|
|
26
|
+
state = readState();
|
|
27
|
+
if (state.integrity !== undefined && state.integrity !== integrity) {
|
|
28
|
+
throw new Error(`${specifier} became visible with unexpected integrity ${state.integrity}`);
|
|
29
|
+
}
|
|
30
|
+
if (state.integrity === integrity && state.tag === version) {
|
|
31
|
+
log(`${specifier} published with matching integrity and dist-tag ${tag}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const remaining = deadline - now();
|
|
35
|
+
if (remaining <= 0) break;
|
|
36
|
+
log(`${specifier}: waiting for registry integrity and ${tag}=${version}; tag=${JSON.stringify(state.tag)}`);
|
|
37
|
+
await wait(Math.min(pollMs, remaining));
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`${specifier}: registry confirmation timed out after ${timeoutMs}ms; expected integrity ${integrity} and ${tag}=${version}, last state=${JSON.stringify(state)}`);
|
|
40
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { mkdtemp, writeFile, readFile, rm } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { activatePackageRuntime, ensureRuntime } from '../plugins/openpencil/scripts/runtime-install.mjs';
|
|
6
|
+
import { CanvasController } from '../plugins/openpencil/scripts/canvas-controller.mjs';
|
|
7
|
+
import { EditorSession } from '../plugins/openpencil/scripts/editor-session.mjs';
|
|
8
|
+
import { registerNode } from './node-registration.mjs';
|
|
9
|
+
import { verifyPluginHost } from './plugin-host-check.mjs';
|
|
10
|
+
import { packQoderPlugin } from './pack-plugin.mjs';
|
|
11
|
+
import {
|
|
12
|
+
installQoderMcpSettings,
|
|
13
|
+
installQoderPlugin,
|
|
14
|
+
installQoderSkills,
|
|
15
|
+
renderQoderConnectorConfig,
|
|
16
|
+
uninstallQoderMcpSettings,
|
|
17
|
+
uninstallQoderPlugin,
|
|
18
|
+
uninstallQoderSkills,
|
|
19
|
+
} from './host-config.mjs';
|
|
20
|
+
|
|
21
|
+
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
22
|
+
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
23
|
+
|
|
24
|
+
export async function verifyRuntime(runtimeRoot) {
|
|
25
|
+
const dir = await mkdtemp(join(tmpdir(), 'openpencil-qoder-check-'));
|
|
26
|
+
const filePath = join(dir, 'setup-check.op');
|
|
27
|
+
const controller = new CanvasController({ runtimeRoot });
|
|
28
|
+
try {
|
|
29
|
+
await writeFile(filePath, JSON.stringify({
|
|
30
|
+
version: '0.8.6',
|
|
31
|
+
children: [{ type: 'frame', id: 'setup-check', name: 'Installation check', width: 400, height: 300, children: [] }],
|
|
32
|
+
}));
|
|
33
|
+
const opened = await controller.open({ filePath });
|
|
34
|
+
if (!(await fetch(opened.structuredContent.panelUrl)).ok) throw new Error('Canvas panel did not load.');
|
|
35
|
+
const reply = await controller.dispatch({
|
|
36
|
+
jsonrpc: '2.0',
|
|
37
|
+
id: 1,
|
|
38
|
+
method: 'tools/call',
|
|
39
|
+
params: { name: 'update_node', arguments: { nodeId: 'setup-check', data: { name: 'Verified installation' } } },
|
|
40
|
+
});
|
|
41
|
+
if (reply.error || reply.result?.isError) throw new Error('Native editor modification failed.');
|
|
42
|
+
await controller.call('canvas_save', { filePath });
|
|
43
|
+
if (!(await readFile(filePath, 'utf8')).includes('Verified installation')) throw new Error('Saved edit was missing.');
|
|
44
|
+
await controller.close();
|
|
45
|
+
const reopened = await EditorSession.start({ filePath, allowOrigin: 'http://127.0.0.1:1', runtimeRoot });
|
|
46
|
+
try {
|
|
47
|
+
if (!JSON.stringify((await reopened.document()).document).includes('Verified installation')) {
|
|
48
|
+
throw new Error('Saved document did not reopen.');
|
|
49
|
+
}
|
|
50
|
+
} finally {
|
|
51
|
+
await reopened.close();
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
await controller.close();
|
|
55
|
+
await rm(dir, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseArgs(args) {
|
|
60
|
+
const options = {
|
|
61
|
+
runtimeOnly: false,
|
|
62
|
+
repairRuntime: false,
|
|
63
|
+
mcpSettings: false,
|
|
64
|
+
printConfig: false,
|
|
65
|
+
uninstall: false,
|
|
66
|
+
packPlugin: false,
|
|
67
|
+
packOutput: undefined,
|
|
68
|
+
configDir: undefined,
|
|
69
|
+
};
|
|
70
|
+
for (let i = 0; i < args.length; i++) {
|
|
71
|
+
const arg = args[i];
|
|
72
|
+
if (arg === '--runtime-only') options.runtimeOnly = true;
|
|
73
|
+
else if (arg === '--repair-runtime') options.repairRuntime = true;
|
|
74
|
+
else if (arg === '--mcp-settings') options.mcpSettings = true;
|
|
75
|
+
else if (arg === '--print-config') options.printConfig = true;
|
|
76
|
+
else if (arg === '--uninstall') options.uninstall = true;
|
|
77
|
+
else if (arg === '--pack-plugin') {
|
|
78
|
+
options.packPlugin = true;
|
|
79
|
+
if (args[i + 1] && !args[i + 1].startsWith('--')) options.packOutput = args[++i];
|
|
80
|
+
} else if (arg === '--config-dir' && args[i + 1]) {
|
|
81
|
+
options.configDir = args[++i];
|
|
82
|
+
} else {
|
|
83
|
+
throw new Error('Usage: qoder-openpencil setup [--runtime-only] [--repair-runtime] [--config-dir PATH] [--mcp-settings] [--pack-plugin [PATH]] [--print-config] [--uninstall]');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return options;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function runSetup(args = process.argv.slice(2)) {
|
|
90
|
+
if (Number(process.versions.node.split('.')[0]) < 22) throw new Error('OpenPencil requires Node.js 22 or later.');
|
|
91
|
+
const options = parseArgs(args);
|
|
92
|
+
const pluginRoot = join(root, 'plugins', 'openpencil');
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
if (options.printConfig) {
|
|
96
|
+
console.log(JSON.stringify(renderQoderConnectorConfig({ pluginRoot }), null, 2));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (options.uninstall) {
|
|
100
|
+
const plugin = await uninstallQoderPlugin({ configDir: options.configDir });
|
|
101
|
+
const mcpSettings = await uninstallQoderMcpSettings({ configDir: options.configDir });
|
|
102
|
+
const skills = await uninstallQoderSkills({ configDir: options.configDir });
|
|
103
|
+
console.log(JSON.stringify({ ok: true, uninstalled: true, plugin, mcpSettings, skills }, null, 2));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const runtime = options.repairRuntime ? await activatePackageRuntime() : await ensureRuntime();
|
|
107
|
+
await verifyRuntime(runtime.root);
|
|
108
|
+
let plugin = null;
|
|
109
|
+
let mcpSettings = null;
|
|
110
|
+
let skills = null;
|
|
111
|
+
let pluginZip = null;
|
|
112
|
+
let pluginHost = null;
|
|
113
|
+
if (!options.runtimeOnly) {
|
|
114
|
+
await registerNode();
|
|
115
|
+
if (options.mcpSettings) {
|
|
116
|
+
mcpSettings = await installQoderMcpSettings({ configDir: options.configDir, pluginRoot });
|
|
117
|
+
skills = await installQoderSkills({ configDir: options.configDir, pluginRoot, version: pkg.version });
|
|
118
|
+
} else {
|
|
119
|
+
plugin = await installQoderPlugin({ configDir: options.configDir, pluginRoot, version: pkg.version });
|
|
120
|
+
}
|
|
121
|
+
if (options.packPlugin) {
|
|
122
|
+
pluginZip = await packQoderPlugin({ pluginRoot, ...(options.packOutput ? { outputPath: options.packOutput } : {}) });
|
|
123
|
+
}
|
|
124
|
+
pluginHost = await verifyPluginHost({ configDir: options.configDir, pluginRoot });
|
|
125
|
+
}
|
|
126
|
+
console.log(JSON.stringify({
|
|
127
|
+
ok: true,
|
|
128
|
+
runtime: runtime.version,
|
|
129
|
+
source: runtime.source ?? 'custom',
|
|
130
|
+
platform: `${process.platform}-${process.arch}`,
|
|
131
|
+
verified: ['panel', 'native-edit', 'save', 'reopen'],
|
|
132
|
+
plugin,
|
|
133
|
+
mcpSettings,
|
|
134
|
+
skills,
|
|
135
|
+
pluginZip,
|
|
136
|
+
pluginHost,
|
|
137
|
+
next: 'Restart Qoder or reload Extensions -> Installed, then open OpenPencil Canvas from More (Global tab), the session sidebar (+ -> Apps), or by asking Qoder to design with OpenPencil.',
|
|
138
|
+
}, null, 2));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(`OpenPencil Qoder setup failed: ${error.message}`);
|
|
141
|
+
process.exitCode = 1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
146
|
+
await runSetup(process.argv.slice(2));
|
|
147
|
+
}
|