@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,189 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
chmod,
|
|
4
|
+
copyFile,
|
|
5
|
+
lstat,
|
|
6
|
+
mkdir,
|
|
7
|
+
readdir,
|
|
8
|
+
readFile,
|
|
9
|
+
rm,
|
|
10
|
+
writeFile,
|
|
11
|
+
} from 'node:fs/promises';
|
|
12
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
13
|
+
import { pathToFileURL } from 'node:url';
|
|
14
|
+
import {
|
|
15
|
+
argumentValue,
|
|
16
|
+
openPencil,
|
|
17
|
+
openPencilRoot,
|
|
18
|
+
platformById,
|
|
19
|
+
platformPackageRoot,
|
|
20
|
+
projectRoot,
|
|
21
|
+
runtimeKeyPaths,
|
|
22
|
+
runtimeManifestName,
|
|
23
|
+
} from './platforms.mjs';
|
|
24
|
+
|
|
25
|
+
if (isMain(import.meta.url)) await main();
|
|
26
|
+
|
|
27
|
+
async function main() {
|
|
28
|
+
const requestedPlatform = argumentValue('--platform');
|
|
29
|
+
const id = requestedPlatform ?? `${process.platform}-${process.arch}`;
|
|
30
|
+
const platform = platformById(id);
|
|
31
|
+
const vendorRoot = openPencilRoot;
|
|
32
|
+
const binarySource = await sourcePath(
|
|
33
|
+
'--binary',
|
|
34
|
+
editorBinarySourceCandidates(vendorRoot, platform, requestedPlatform === undefined),
|
|
35
|
+
'binary',
|
|
36
|
+
);
|
|
37
|
+
const pkgSource = await resolveWebBundleSource(vendorRoot, argumentValue('--pkg'));
|
|
38
|
+
const canvasKitSource = await sourcePath('--canvaskit', [
|
|
39
|
+
join(vendorRoot, 'crates', 'op-host-web', 'assets', 'canvaskit'),
|
|
40
|
+
], 'CanvasKit directory');
|
|
41
|
+
const packageRoot = platformPackageRoot(platform);
|
|
42
|
+
|
|
43
|
+
await assertRegularFile(binarySource, '--binary');
|
|
44
|
+
await assertDirectory(pkgSource, '--pkg');
|
|
45
|
+
await assertDirectory(canvasKitSource, '--canvaskit');
|
|
46
|
+
for (const source of [binarySource, pkgSource, canvasKitSource]) {
|
|
47
|
+
if (within(source, packageRoot)) {
|
|
48
|
+
throw new Error(`staging source must not be inside generated package runtime: ${source}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const binaryDestination = join(packageRoot, 'bin', platform.binaryName);
|
|
53
|
+
const pkgDestination = join(packageRoot, 'bin', 'web-bundle');
|
|
54
|
+
const canvasKitDestination = join(pkgDestination, 'canvaskit');
|
|
55
|
+
await rm(join(packageRoot, 'bin'), { recursive: true, force: true });
|
|
56
|
+
await rm(join(packageRoot, 'web'), { recursive: true, force: true });
|
|
57
|
+
await rm(join(packageRoot, runtimeManifestName), { force: true });
|
|
58
|
+
await mkdir(dirname(binaryDestination), { recursive: true });
|
|
59
|
+
await copyFile(binarySource, binaryDestination);
|
|
60
|
+
if (platform.os !== 'win32') await chmod(binaryDestination, 0o755);
|
|
61
|
+
await copyDirectory(pkgSource, pkgDestination, shouldOmitWebFile);
|
|
62
|
+
await copyDirectory(canvasKitSource, canvasKitDestination, shouldOmitWebFile);
|
|
63
|
+
|
|
64
|
+
for (const sourceName of ['LICENSE', 'THIRD_PARTY_NOTICES.md']) {
|
|
65
|
+
await copyFile(join(projectRoot, sourceName), join(packageRoot, sourceName));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const path of runtimeKeyPaths(platform)) {
|
|
69
|
+
await assertRegularFile(join(packageRoot, ...path.split('/')), path);
|
|
70
|
+
}
|
|
71
|
+
const files = {};
|
|
72
|
+
for (const path of await collectRuntimePayloadPaths(packageRoot)) {
|
|
73
|
+
files[path] = await sha256(join(packageRoot, ...path.split('/')));
|
|
74
|
+
}
|
|
75
|
+
const manifest = {
|
|
76
|
+
schemaVersion: 1,
|
|
77
|
+
platform: platform.id,
|
|
78
|
+
packageName: platform.packageName,
|
|
79
|
+
openPencilVersion: openPencil.version,
|
|
80
|
+
openPencilRevision: openPencil.revision,
|
|
81
|
+
files,
|
|
82
|
+
};
|
|
83
|
+
await writeFile(join(packageRoot, runtimeManifestName), JSON.stringify(manifest, null, 2) + '\n');
|
|
84
|
+
process.stdout.write(`staged ${platform.packageName} from OpenPencil ${openPencil.version} (${openPencil.revision})\n`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function editorBinarySourceCandidates(vendorRoot, platform, preferHostBuild) {
|
|
88
|
+
const host = join(vendorRoot, 'target', 'release', platform.binaryName);
|
|
89
|
+
const targeted = join(vendorRoot, 'target', platform.rustTarget, 'release', platform.binaryName);
|
|
90
|
+
return preferHostBuild ? [host, targeted] : [targeted, host];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function resolveWebBundleSource(vendorRoot, explicitPkg) {
|
|
94
|
+
return sourcePath('--pkg', [
|
|
95
|
+
join(vendorRoot, 'crates', 'op-host-web', 'pkg'),
|
|
96
|
+
], 'current web bundle', explicitPkg);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function collectRuntimePayloadPaths(packageRoot) {
|
|
100
|
+
const roots = [join(packageRoot, 'bin')];
|
|
101
|
+
const files = (await Promise.all(roots.map(walkRegularFiles))).flat();
|
|
102
|
+
return files
|
|
103
|
+
.map(path => relative(packageRoot, path).split(sep).join('/'))
|
|
104
|
+
.sort((left, right) => left.localeCompare(right, 'en'));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function sourcePath(name, defaults, label, explicitValue) {
|
|
108
|
+
const value = explicitValue ?? argumentValue(name);
|
|
109
|
+
if (value !== undefined) return resolve(value);
|
|
110
|
+
for (const candidate of defaults) {
|
|
111
|
+
try {
|
|
112
|
+
await lstat(candidate);
|
|
113
|
+
return candidate;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw new Error(`no default ${label} found; checked ${defaults.join(', ')} (override with ${name})`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isMain(url) {
|
|
122
|
+
const entry = process.argv[1];
|
|
123
|
+
return entry !== undefined && pathToFileURL(resolve(entry)).href === url;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function within(candidate, parent) {
|
|
127
|
+
const path = relative(resolve(parent), resolve(candidate));
|
|
128
|
+
return path === '' || (!path.startsWith('..' + sep) && path !== '..' && !isAbsolute(path));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function shouldOmitWebFile(path) {
|
|
132
|
+
const name = basename(path);
|
|
133
|
+
return name.endsWith('.d.ts') || name.endsWith('.opt.wasm');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function copyDirectory(source, destination, omit) {
|
|
137
|
+
await mkdir(destination, { recursive: true });
|
|
138
|
+
const entries = await readdir(source, { withFileTypes: true });
|
|
139
|
+
entries.sort((left, right) => left.name.localeCompare(right.name, 'en'));
|
|
140
|
+
for (const entry of entries) {
|
|
141
|
+
const entrySource = join(source, entry.name);
|
|
142
|
+
if (omit(entrySource)) continue;
|
|
143
|
+
const entryDest = join(destination, entry.name);
|
|
144
|
+
if (entry.isSymbolicLink()) throw new Error(`runtime source must not contain symbolic links: ${entrySource}`);
|
|
145
|
+
if (entry.isDirectory()) await copyDirectory(entrySource, entryDest, omit);
|
|
146
|
+
else if (entry.isFile()) await copyFile(entrySource, entryDest);
|
|
147
|
+
else throw new Error(`unsupported runtime source entry: ${entrySource}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function walkRegularFiles(root) {
|
|
152
|
+
const output = [];
|
|
153
|
+
const entries = await readdir(root, { withFileTypes: true });
|
|
154
|
+
entries.sort((left, right) => left.name.localeCompare(right.name, 'en'));
|
|
155
|
+
for (const entry of entries) {
|
|
156
|
+
const path = join(root, entry.name);
|
|
157
|
+
if (entry.isSymbolicLink()) throw new Error(`runtime payload must not contain symbolic links: ${path}`);
|
|
158
|
+
if (entry.isDirectory()) output.push(...await walkRegularFiles(path));
|
|
159
|
+
else if (entry.isFile()) output.push(path);
|
|
160
|
+
else throw new Error(`unsupported runtime payload entry: ${path}`);
|
|
161
|
+
}
|
|
162
|
+
return output;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function assertDirectory(path, label) {
|
|
166
|
+
let value;
|
|
167
|
+
try {
|
|
168
|
+
value = await lstat(path);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error?.code === 'ENOENT') throw new Error(`${label} directory is missing: ${path}`);
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
if (!value.isDirectory() || value.isSymbolicLink()) throw new Error(`${label} must be a real directory: ${path}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function assertRegularFile(path, label) {
|
|
177
|
+
let value;
|
|
178
|
+
try {
|
|
179
|
+
value = await lstat(path);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (error?.code === 'ENOENT') throw new Error(`${label} file is missing: ${path}`);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
if (!value.isFile() || value.isSymbolicLink()) throw new Error(`${label} must be a regular file: ${path}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function sha256(path) {
|
|
188
|
+
return createHash('sha256').update(await readFile(path)).digest('hex');
|
|
189
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { platforms, projectRoot } from './platforms.mjs';
|
|
4
|
+
|
|
5
|
+
const requested = process.argv[2]?.replace(/^(?:qoder-)?v/u, '');
|
|
6
|
+
const rootPath = join(projectRoot, 'package.json');
|
|
7
|
+
const rootManifest = JSON.parse(await readFile(rootPath, 'utf8'));
|
|
8
|
+
const version = requested ?? rootManifest.version;
|
|
9
|
+
if (typeof version !== 'string' || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(version)) {
|
|
10
|
+
throw new Error(`invalid release version ${JSON.stringify(version)}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
rootManifest.version = version;
|
|
14
|
+
rootManifest.optionalDependencies = Object.fromEntries(
|
|
15
|
+
platforms.map(platform => [platform.packageName, version]),
|
|
16
|
+
);
|
|
17
|
+
await writeFile(rootPath, JSON.stringify(rootManifest, null, 2) + '\n');
|
|
18
|
+
|
|
19
|
+
for (const platform of platforms) {
|
|
20
|
+
const manifestPath = join(projectRoot, 'npm', platform.id, 'package.json');
|
|
21
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
22
|
+
manifest.version = version;
|
|
23
|
+
await writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (const pluginRel of ['plugin.json', '.qoder-plugin/plugin.json']) {
|
|
27
|
+
const pluginPath = join(projectRoot, 'plugins', 'openpencil', pluginRel);
|
|
28
|
+
const pluginManifest = JSON.parse(await readFile(pluginPath, 'utf8'));
|
|
29
|
+
pluginManifest.version = version;
|
|
30
|
+
await writeFile(pluginPath, JSON.stringify(pluginManifest, null, 2) + '\n');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const controllerPath = join(projectRoot, 'plugins', 'openpencil', 'scripts', 'canvas-controller.mjs');
|
|
34
|
+
const controllerBefore = await readFile(controllerPath, 'utf8');
|
|
35
|
+
const controllerAfter = controllerBefore
|
|
36
|
+
.replace(
|
|
37
|
+
/export const CANVAS_URI = 'ui:\/\/openpencil\/canvas\/v[^']+\.html';/u,
|
|
38
|
+
`export const CANVAS_URI = 'ui://openpencil/canvas/v${version}.html';`,
|
|
39
|
+
)
|
|
40
|
+
.replace(
|
|
41
|
+
/serverInfo: \{ name: 'qoder-openpencil', version: '[^']+' \}/u,
|
|
42
|
+
`serverInfo: { name: 'qoder-openpencil', version: '${version}' }`,
|
|
43
|
+
);
|
|
44
|
+
if (
|
|
45
|
+
!controllerAfter.includes(`'ui://openpencil/canvas/v${version}.html'`)
|
|
46
|
+
|| !controllerAfter.includes(`serverInfo: { name: 'qoder-openpencil', version: '${version}' }`)
|
|
47
|
+
) {
|
|
48
|
+
throw new Error('failed to update version markers in plugins/openpencil/scripts/canvas-controller.mjs');
|
|
49
|
+
}
|
|
50
|
+
await writeFile(controllerPath, controllerAfter);
|
|
51
|
+
|
|
52
|
+
const appHtmlPath = join(projectRoot, 'plugins', 'openpencil', 'ui', 'app.html');
|
|
53
|
+
const appHtmlBefore = await readFile(appHtmlPath, 'utf8');
|
|
54
|
+
const appHtmlAfter = appHtmlBefore.replace(
|
|
55
|
+
/appInfo: \{ name: 'OpenPencil Canvas', version: '[^']+' \}/u,
|
|
56
|
+
`appInfo: { name: 'OpenPencil Canvas', version: '${version}' }`,
|
|
57
|
+
);
|
|
58
|
+
if (!appHtmlAfter.includes(`appInfo: { name: 'OpenPencil Canvas', version: '${version}' }`)) {
|
|
59
|
+
throw new Error('failed to update appInfo.version in plugins/openpencil/ui/app.html');
|
|
60
|
+
}
|
|
61
|
+
await writeFile(appHtmlPath, appHtmlAfter);
|
|
62
|
+
|
|
63
|
+
process.stdout.write(`synchronized Qoder root, six runtime packages, and plugin metadata to ${version}\n`);
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdtemp, open, readFile, readdir, rm, stat } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, relative, sep } from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
argumentValue,
|
|
8
|
+
hasFlag,
|
|
9
|
+
openPencil,
|
|
10
|
+
platformById,
|
|
11
|
+
platformPackageRoot,
|
|
12
|
+
platforms,
|
|
13
|
+
projectRoot,
|
|
14
|
+
runtimeKeyPaths,
|
|
15
|
+
runtimeManifestName,
|
|
16
|
+
} from './platforms.mjs';
|
|
17
|
+
import { validatedCollabBootstrapUrls, withoutCollabBootstrapBuildEnv } from './collab-bootstrap-config.mjs';
|
|
18
|
+
import { parseManagedHandshake } from './managed-handshake.mjs';
|
|
19
|
+
|
|
20
|
+
const selectedId = argumentValue('--platform');
|
|
21
|
+
const requireRuntime = hasFlag('--require-runtime');
|
|
22
|
+
const requireCollabBootstrap = hasFlag('--require-collab-bootstrap');
|
|
23
|
+
if (requireRuntime && selectedId === undefined) {
|
|
24
|
+
throw new Error('--require-runtime requires --platform so the staged native daemon can run on its matching runner');
|
|
25
|
+
}
|
|
26
|
+
if (requireCollabBootstrap && !requireRuntime) {
|
|
27
|
+
throw new Error('--require-collab-bootstrap requires --require-runtime');
|
|
28
|
+
}
|
|
29
|
+
const collabBootstrap = requireCollabBootstrap ? validatedCollabBootstrapUrls() : undefined;
|
|
30
|
+
const selectedPlatforms = selectedId === undefined ? platforms : [platformById(selectedId)];
|
|
31
|
+
const rootManifest = JSON.parse(await readFile(join(projectRoot, 'package.json'), 'utf8'));
|
|
32
|
+
const rootLicense = await readFile(join(projectRoot, 'LICENSE'));
|
|
33
|
+
const rootNotices = await readFile(join(projectRoot, 'THIRD_PARTY_NOTICES.md'));
|
|
34
|
+
|
|
35
|
+
assertRootMetadata();
|
|
36
|
+
for (const platform of selectedPlatforms) await verifyPlatformMetadata(platform);
|
|
37
|
+
await verifyRootTarball();
|
|
38
|
+
|
|
39
|
+
if (requireRuntime) {
|
|
40
|
+
const platform = selectedPlatforms[0];
|
|
41
|
+
await verifyStagedRuntime(platform, collabBootstrap);
|
|
42
|
+
await verifyPlatformTarball(platform);
|
|
43
|
+
await smokeRuntime(platform);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
process.stdout.write(`verified ${selectedPlatforms.length} Qoder platform package metadata${requireRuntime ? ' and packaged runtime smoke' : ' (metadata-only)'}\n`);
|
|
47
|
+
|
|
48
|
+
function assertRootMetadata() {
|
|
49
|
+
if (rootManifest.name !== '@zseven-w/qoder-openpencil') throw new Error('unexpected root package name');
|
|
50
|
+
if (rootManifest.private === true) throw new Error('root package must not be private');
|
|
51
|
+
if (rootManifest.publishConfig?.access !== 'public') throw new Error('root package must publish publicly');
|
|
52
|
+
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(rootManifest.version ?? '')) {
|
|
53
|
+
throw new Error(`root package has an invalid release version: ${JSON.stringify(rootManifest.version)}`);
|
|
54
|
+
}
|
|
55
|
+
if (rootManifest.dependencies !== undefined) {
|
|
56
|
+
throw new Error('root package must remain runtime dependency-free outside optionalDependencies');
|
|
57
|
+
}
|
|
58
|
+
if (rootManifest.bin?.['qoder-openpencil'] !== './bin/qoder-openpencil.mjs') {
|
|
59
|
+
throw new Error('root package must expose bin.qoder-openpencil -> ./bin/qoder-openpencil.mjs');
|
|
60
|
+
}
|
|
61
|
+
const expected = Object.fromEntries(platforms.map(platform => [platform.packageName, rootManifest.version]));
|
|
62
|
+
assertRecord(rootManifest.optionalDependencies ?? {}, expected, 'root optionalDependencies');
|
|
63
|
+
for (const requiredFile of ['bin', 'plugins', 'scripts', 'platforms.json', 'THIRD_PARTY_NOTICES.md']) {
|
|
64
|
+
if (!rootManifest.files?.includes(requiredFile)) throw new Error(`root files must publish ${requiredFile}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function verifyPlatformMetadata(platform) {
|
|
69
|
+
const packageRoot = platformPackageRoot(platform);
|
|
70
|
+
const manifest = JSON.parse(await readFile(join(packageRoot, 'package.json'), 'utf8'));
|
|
71
|
+
if (manifest.name !== platform.packageName) throw new Error(`${platform.id}: unexpected package name`);
|
|
72
|
+
if (manifest.version !== rootManifest.version) throw new Error(`${platform.id}: version must match root package`);
|
|
73
|
+
assertList(manifest.os, [platform.os], `${platform.id}: os selector`);
|
|
74
|
+
assertList(manifest.cpu, [platform.cpu], `${platform.id}: cpu selector`);
|
|
75
|
+
if (platform.libc === undefined) {
|
|
76
|
+
if (manifest.libc !== undefined) throw new Error(`${platform.id}: non-Linux package must not declare libc`);
|
|
77
|
+
} else {
|
|
78
|
+
assertList(manifest.libc, [platform.libc], `${platform.id}: libc selector`);
|
|
79
|
+
}
|
|
80
|
+
if (manifest.bin !== undefined) throw new Error(`${platform.id}: runtime packages must not expose a global bin`);
|
|
81
|
+
if (manifest.preferUnplugged !== true) throw new Error(`${platform.id}: preferUnplugged must be true`);
|
|
82
|
+
if (manifest.publishConfig?.access !== 'public') throw new Error(`${platform.id}: scoped package must publish publicly`);
|
|
83
|
+
if (manifest.engines?.node !== rootManifest.engines?.node) throw new Error(`${platform.id}: Node engine must match root package`);
|
|
84
|
+
assertList(
|
|
85
|
+
[...(manifest.files ?? [])].sort(),
|
|
86
|
+
['LICENSE', 'THIRD_PARTY_NOTICES.md', 'bin', runtimeManifestName].sort(),
|
|
87
|
+
`${platform.id}: files`,
|
|
88
|
+
);
|
|
89
|
+
if (manifest.dependencies !== undefined || manifest.optionalDependencies !== undefined) {
|
|
90
|
+
throw new Error(`${platform.id}: atomic runtime package must not have package dependencies`);
|
|
91
|
+
}
|
|
92
|
+
if (manifest.repository?.directory !== `packages/op-qoder/npm/${platform.id}`) {
|
|
93
|
+
throw new Error(`${platform.id}: repository directory drifted`);
|
|
94
|
+
}
|
|
95
|
+
if (!rootLicense.equals(await readFile(join(packageRoot, 'LICENSE')))) throw new Error(`${platform.id}: LICENSE differs from root`);
|
|
96
|
+
if (!rootNotices.equals(await readFile(join(packageRoot, 'THIRD_PARTY_NOTICES.md')))) {
|
|
97
|
+
throw new Error(`${platform.id}: THIRD_PARTY_NOTICES.md differs from root`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function verifyRootTarball() {
|
|
102
|
+
const packed = pack('.', true);
|
|
103
|
+
const forbidden = packed.files
|
|
104
|
+
.map(file => file.path)
|
|
105
|
+
.filter(path => /^(?:vendor|npm|node_modules|target|tests|artifacts|dist|\.git)(?:\/|$)/u.test(path));
|
|
106
|
+
if (forbidden.length > 0) throw new Error(`root tarball leaked development/runtime files: ${forbidden.join(', ')}`);
|
|
107
|
+
for (const required of [
|
|
108
|
+
'package.json',
|
|
109
|
+
'platforms.json',
|
|
110
|
+
'LICENSE',
|
|
111
|
+
'NOTICE',
|
|
112
|
+
'THIRD_PARTY_NOTICES.md',
|
|
113
|
+
'bin/qoder-openpencil.mjs',
|
|
114
|
+
'scripts/pack-plugin.mjs',
|
|
115
|
+
'scripts/host-config.mjs',
|
|
116
|
+
'plugins/openpencil/.qoder-plugin/plugin.json',
|
|
117
|
+
'plugins/openpencil/.mcp.json',
|
|
118
|
+
'plugins/openpencil/CONNECTORS.md',
|
|
119
|
+
'plugins/openpencil/scripts/launch-mcp',
|
|
120
|
+
'plugins/openpencil/scripts/launch-mcp.cmd',
|
|
121
|
+
'plugins/openpencil/scripts/mcp-bridge.mjs',
|
|
122
|
+
]) {
|
|
123
|
+
if (!packed.files.some(file => file.path === required)) throw new Error(`root tarball is missing ${required}`);
|
|
124
|
+
}
|
|
125
|
+
if (process.platform !== 'win32') {
|
|
126
|
+
for (const executable of ['bin/qoder-openpencil.mjs', 'plugins/openpencil/scripts/launch-mcp']) {
|
|
127
|
+
const entry = packed.files.find(file => file.path === executable);
|
|
128
|
+
if (!entry || (entry.mode & 0o111) === 0) throw new Error(`root tarball entry ${executable} must be executable`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function verifyStagedRuntime(platform, bootstrap) {
|
|
134
|
+
if (platform.os !== process.platform || platform.cpu !== process.arch) {
|
|
135
|
+
throw new Error(`${platform.id}: runtime smoke must run on ${platform.os}/${platform.cpu}`);
|
|
136
|
+
}
|
|
137
|
+
const packageRoot = platformPackageRoot(platform);
|
|
138
|
+
const binaryPath = join(packageRoot, 'bin', platform.binaryName);
|
|
139
|
+
const binary = await stat(binaryPath);
|
|
140
|
+
if (!binary.isFile() || binary.size < 100_000) throw new Error(`${platform.id}: binary is missing or implausibly small`);
|
|
141
|
+
if (platform.os !== 'win32' && (binary.mode & 0o777) !== 0o755) throw new Error(`${platform.id}: binary mode must be 0755`);
|
|
142
|
+
await verifyBinaryFormat(binaryPath, platform);
|
|
143
|
+
if (bootstrap !== undefined) {
|
|
144
|
+
const binaryBytes = await readFile(binaryPath);
|
|
145
|
+
for (const [region, url] of Object.entries(bootstrap)) {
|
|
146
|
+
if (!binaryBytes.includes(Buffer.from(url, 'utf8'))) {
|
|
147
|
+
throw new Error(`${platform.id}: native daemon is missing its build-injected ${region} relay bootstrap`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const manifest = JSON.parse(await readFile(join(packageRoot, runtimeManifestName), 'utf8'));
|
|
152
|
+
const payloadFiles = (await walkFiles(join(packageRoot, 'bin'))).map(path => relative(packageRoot, path).split(sep).join('/'));
|
|
153
|
+
assertList(Object.keys(manifest.files ?? {}).sort(), payloadFiles.sort(), `${platform.id}: manifest files`);
|
|
154
|
+
for (const [path, expectedHash] of Object.entries(manifest.files)) {
|
|
155
|
+
const actualHash = await sha256(join(packageRoot, ...path.split('/')));
|
|
156
|
+
if (actualHash !== expectedHash) throw new Error(`${platform.id}: SHA-256 mismatch for ${path}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function verifyPlatformTarball(platform) {
|
|
161
|
+
const temporary = await mkdtemp(join(tmpdir(), `qoder-openpencil-pack-${platform.id}-`));
|
|
162
|
+
try {
|
|
163
|
+
const packed = pack(`./npm/${platform.id}`, false, temporary);
|
|
164
|
+
for (const required of [runtimeManifestName, ...runtimeKeyPaths(platform), 'LICENSE', 'THIRD_PARTY_NOTICES.md']) {
|
|
165
|
+
if (!packed.files.some(file => file.path === required)) throw new Error(`${platform.id}: packed tarball is missing ${required}`);
|
|
166
|
+
}
|
|
167
|
+
const tarball = await stat(join(temporary, packed.filename));
|
|
168
|
+
if (!tarball.isFile() || tarball.size < 100_000) throw new Error(`${platform.id}: npm did not create a plausible tgz`);
|
|
169
|
+
} finally {
|
|
170
|
+
await rm(temporary, { recursive: true, force: true });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function smokeRuntime(platform) {
|
|
175
|
+
const packageRoot = platformPackageRoot(platform);
|
|
176
|
+
const binary = join(packageRoot, 'bin', platform.binaryName);
|
|
177
|
+
const child = spawn(binary, ['--serve-web', '--managed', '--port', '0', '--allow-origin', 'qoder-openpencil://package-smoke'], {
|
|
178
|
+
cwd: packageRoot,
|
|
179
|
+
env: withoutCollabBootstrapBuildEnv(process.env),
|
|
180
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
181
|
+
});
|
|
182
|
+
try {
|
|
183
|
+
const line = await firstLine(child, 10_000);
|
|
184
|
+
const handshake = parseManagedHandshake(line, platform.id);
|
|
185
|
+
if (handshake.version !== openPencil.version) throw new Error(`${platform.id}: unexpected OpenPencil version`);
|
|
186
|
+
const health = await fetch(`http://127.0.0.1:${handshake.port}/api/mcp/server`, { signal: AbortSignal.timeout(10_000) });
|
|
187
|
+
if (!health.ok) throw new Error(`${platform.id}: managed health returned ${health.status}`);
|
|
188
|
+
} finally {
|
|
189
|
+
child.stdin.end();
|
|
190
|
+
child.kill();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function pack(packagePath, dryRun, destination) {
|
|
195
|
+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
196
|
+
const args = ['pack', '--json', '--ignore-scripts'];
|
|
197
|
+
if (dryRun) args.push('--dry-run');
|
|
198
|
+
if (destination !== undefined) args.push('--pack-destination', destination);
|
|
199
|
+
args.push(packagePath);
|
|
200
|
+
const result = spawnSync(npm, args, {
|
|
201
|
+
cwd: projectRoot,
|
|
202
|
+
encoding: 'utf8',
|
|
203
|
+
env: { ...withoutCollabBootstrapBuildEnv(process.env), npm_config_cache: join(tmpdir(), 'qoder-openpencil-npm-cache') },
|
|
204
|
+
shell: process.platform === 'win32',
|
|
205
|
+
});
|
|
206
|
+
if (result.status !== 0) throw new Error(`npm ${args.join(' ')} failed:\n${result.stderr || result.stdout}`);
|
|
207
|
+
return JSON.parse(result.stdout)[0];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async function verifyBinaryFormat(path, platform) {
|
|
211
|
+
const handle = await open(path, 'r');
|
|
212
|
+
const header = Buffer.alloc(512);
|
|
213
|
+
try { await handle.read(header, 0, header.length, 0); } finally { await handle.close(); }
|
|
214
|
+
if (platform.os === 'darwin') {
|
|
215
|
+
if (!header.subarray(0, 4).equals(Buffer.from([0xcf, 0xfa, 0xed, 0xfe]))) throw new Error(`${platform.id}: expected 64-bit Mach-O`);
|
|
216
|
+
} else if (platform.os === 'linux') {
|
|
217
|
+
if (!header.subarray(0, 4).equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]))) throw new Error(`${platform.id}: expected ELF64`);
|
|
218
|
+
} else if (header.toString('ascii', 0, 2) !== 'MZ') {
|
|
219
|
+
throw new Error(`${platform.id}: expected PE/COFF`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async function firstLine(child, timeoutMs) {
|
|
224
|
+
return await new Promise((resolvePromise, rejectPromise) => {
|
|
225
|
+
let buffer = '';
|
|
226
|
+
const timer = setTimeout(() => rejectPromise(new Error('managed daemon handshake timed out')), timeoutMs);
|
|
227
|
+
const finish = (cb, val) => {
|
|
228
|
+
clearTimeout(timer);
|
|
229
|
+
child.stdout.off('data', onData);
|
|
230
|
+
child.off('error', onError);
|
|
231
|
+
child.off('exit', onExit);
|
|
232
|
+
cb(val);
|
|
233
|
+
};
|
|
234
|
+
const onData = chunk => {
|
|
235
|
+
buffer += chunk.toString();
|
|
236
|
+
const nl = buffer.indexOf('\n');
|
|
237
|
+
if (nl !== -1) finish(resolvePromise, buffer.slice(0, nl).trim());
|
|
238
|
+
};
|
|
239
|
+
const onError = error => finish(rejectPromise, error);
|
|
240
|
+
const onExit = code => finish(rejectPromise, new Error(`managed daemon exited ${code} before handshake`));
|
|
241
|
+
child.stdout.on('data', onData);
|
|
242
|
+
child.once('error', onError);
|
|
243
|
+
child.once('exit', onExit);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function walkFiles(root) {
|
|
248
|
+
const output = [];
|
|
249
|
+
const entries = await readdir(root, { withFileTypes: true });
|
|
250
|
+
entries.sort((a, b) => a.name.localeCompare(b.name, 'en'));
|
|
251
|
+
for (const entry of entries) {
|
|
252
|
+
const path = join(root, entry.name);
|
|
253
|
+
if (entry.isSymbolicLink()) throw new Error(`package payload must not contain symbolic links: ${path}`);
|
|
254
|
+
if (entry.isDirectory()) output.push(...await walkFiles(path));
|
|
255
|
+
else if (entry.isFile()) output.push(path);
|
|
256
|
+
}
|
|
257
|
+
return output;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function assertList(actual, expected, label) {
|
|
261
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) throw new Error(`${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function assertRecord(actual, expected, label) {
|
|
265
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) throw new Error(`${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function sha256(path) {
|
|
269
|
+
return createHash('sha256').update(await readFile(path)).digest('hex');
|
|
270
|
+
}
|