@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.
Files changed (63) hide show
  1. package/INSTALL.md +77 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +10 -0
  4. package/README.md +46 -2
  5. package/README.zh.md +38 -0
  6. package/THIRD_PARTY_NOTICES.md +69 -0
  7. package/bin/qoder-openpencil.mjs +90 -0
  8. package/package.json +71 -4
  9. package/platforms.json +65 -0
  10. package/plugins/openpencil/.mcp.json +10 -0
  11. package/plugins/openpencil/.qoder-plugin/plugin.json +19 -0
  12. package/plugins/openpencil/CONNECTORS.md +9 -0
  13. package/plugins/openpencil/LICENSE +21 -0
  14. package/plugins/openpencil/NOTICE +10 -0
  15. package/plugins/openpencil/assets/icon.png +0 -0
  16. package/plugins/openpencil/assets/logo.png +0 -0
  17. package/plugins/openpencil/mcp.json +11 -0
  18. package/plugins/openpencil/plugin.json +19 -0
  19. package/plugins/openpencil/scripts/browser-launch.mjs +37 -0
  20. package/plugins/openpencil/scripts/canvas-codegen.mjs +141 -0
  21. package/plugins/openpencil/scripts/canvas-controller.mjs +293 -0
  22. package/plugins/openpencil/scripts/canvas-images.mjs +93 -0
  23. package/plugins/openpencil/scripts/canvas-panel.mjs +82 -0
  24. package/plugins/openpencil/scripts/canvas-selection.mjs +61 -0
  25. package/plugins/openpencil/scripts/document-format.mjs +48 -0
  26. package/plugins/openpencil/scripts/editor-runtime.mjs +453 -0
  27. package/plugins/openpencil/scripts/editor-session.mjs +230 -0
  28. package/plugins/openpencil/scripts/launch-mcp +22 -0
  29. package/plugins/openpencil/scripts/launch-mcp.cmd +21 -0
  30. package/plugins/openpencil/scripts/mcp-bridge.mjs +70 -0
  31. package/plugins/openpencil/scripts/runtime-install.mjs +128 -0
  32. package/plugins/openpencil/scripts/transport.mjs +138 -0
  33. package/plugins/openpencil/skills/openpencil-design/SKILL.md +125 -0
  34. package/plugins/openpencil/skills/openpencil-design/references/codegen.md +34 -0
  35. package/plugins/openpencil/skills/openpencil-design/references/images.md +54 -0
  36. package/plugins/openpencil/skills/openpencil-design/references/node-schema.md +208 -0
  37. package/plugins/openpencil/skills/openpencil-setup/SKILL.md +59 -0
  38. package/plugins/openpencil/ui/app.html +226 -0
  39. package/plugins/openpencil/ui/codegen.js +80 -0
  40. package/plugins/openpencil/ui/panel.css +311 -0
  41. package/plugins/openpencil/ui/panel.html +11 -0
  42. package/plugins/openpencil/ui/panel.js +219 -0
  43. package/plugins/openpencil/ui/selection.js +19 -0
  44. package/scripts/build-editor-runtime.mjs +35 -0
  45. package/scripts/canvas.mjs +75 -0
  46. package/scripts/check-package.mjs +81 -0
  47. package/scripts/check-release-version.mjs +53 -0
  48. package/scripts/collab-bootstrap-config.mjs +66 -0
  49. package/scripts/configure-runtime.mjs +15 -0
  50. package/scripts/host-config.mjs +352 -0
  51. package/scripts/managed-handshake.mjs +23 -0
  52. package/scripts/node-registration.mjs +17 -0
  53. package/scripts/pack-package.mjs +41 -0
  54. package/scripts/pack-plugin.mjs +166 -0
  55. package/scripts/platforms.mjs +84 -0
  56. package/scripts/plugin-host-check.mjs +174 -0
  57. package/scripts/publish-release.mjs +294 -0
  58. package/scripts/registry-convergence.mjs +40 -0
  59. package/scripts/setup.mjs +147 -0
  60. package/scripts/stage-editor-runtime.mjs +189 -0
  61. package/scripts/sync-platform-versions.mjs +63 -0
  62. package/scripts/verify-platform-packages.mjs +270 -0
  63. package/scripts/verify-selective-install.mjs +219 -0
@@ -0,0 +1,219 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { mkdtemp, readFile, readdir, realpath, rm, stat, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { basename, join, resolve } from 'node:path';
6
+ import { pathToFileURL } from 'node:url';
7
+ import { openPencil, platforms } from './platforms.mjs';
8
+
9
+ const artifactRoot = resolve(process.argv[2] ?? 'artifacts');
10
+ const reports = await readReports(artifactRoot);
11
+ const expectedNames = new Set(['@zseven-w/qoder-openpencil', ...platforms.map(platform => platform.packageName)]);
12
+ if (reports.length !== expectedNames.size) {
13
+ throw new Error(`expected exactly ${expectedNames.size} package reports, found ${reports.length}`);
14
+ }
15
+ const reportsByName = new Map();
16
+ for (const report of reports) {
17
+ if (!expectedNames.has(report.name)) throw new Error(`unexpected package report ${report.name}`);
18
+ if (reportsByName.has(report.name)) throw new Error(`duplicate package report ${report.name}`);
19
+ await verifyReportIntegrity(report);
20
+ reportsByName.set(report.name, report);
21
+ }
22
+ const rootReport = reportsByName.get('@zseven-w/qoder-openpencil');
23
+ if (rootReport === undefined) throw new Error('root package tarball is missing');
24
+ for (const report of reports) {
25
+ if (report.version !== rootReport.version) throw new Error(`${report.name} version differs from root ${rootReport.version}`);
26
+ }
27
+
28
+ const optionalDependencies = Object.fromEntries(platforms.map(platform => {
29
+ const report = reportsByName.get(platform.packageName);
30
+ if (report === undefined) throw new Error(`${platform.packageName} tarball is missing`);
31
+ return [platform.packageName, pathToFileURL(join(report.directory, report.filename)).href];
32
+ }));
33
+
34
+ for (const platform of platforms) await verifySelection(platform, optionalDependencies, rootReport);
35
+ for (const platform of platforms.filter(platform => platform.os === 'linux')) {
36
+ await verifyUnsupportedLibc(platform, optionalDependencies, rootReport);
37
+ }
38
+ await verifyOmitted(optionalDependencies, rootReport);
39
+ process.stdout.write('verified npm selective installation for six atomic runtimes, Linux musl rejection, --omit=optional, and CLI entrypoint\n');
40
+
41
+ async function verifySelection(platform, dependencies, root) {
42
+ const directory = await createConsumer(dependencies, root);
43
+ try {
44
+ const args = [
45
+ 'install',
46
+ '--ignore-scripts',
47
+ '--package-lock=false',
48
+ '--no-audit',
49
+ '--no-fund',
50
+ '--offline',
51
+ `--os=${platform.os}`,
52
+ `--cpu=${platform.cpu}`,
53
+ ];
54
+ if (platform.libc !== undefined) args.push(`--libc=${platform.libc}`);
55
+ runNpm(args, directory);
56
+ const installed = await installedRuntimePackages(directory);
57
+ const expected = basename(platform.packageName);
58
+ if (installed.length !== 1 || installed[0] !== expected) {
59
+ throw new Error(`${platform.id}: expected ${expected}, installed ${installed.join(', ') || 'nothing'}`);
60
+ }
61
+ const installedRoot = await realpath(join(directory, 'node_modules', '@zseven-w', 'qoder-openpencil'));
62
+ if (!(await stat(join(installedRoot, 'plugins', 'openpencil', 'scripts', 'launch-mcp'))).isFile()) {
63
+ throw new Error(`${platform.id}: installed root package is missing plugins/openpencil/scripts/launch-mcp`);
64
+ }
65
+ const cli = spawnSync(process.execPath, [join(installedRoot, 'bin', 'qoder-openpencil.mjs'), '--version'], {
66
+ cwd: directory,
67
+ encoding: 'utf8',
68
+ });
69
+ if (cli.status !== 0 || cli.stdout.trim() !== root.version) {
70
+ throw new Error(`${platform.id}: installed CLI --version returned ${JSON.stringify(cli.stdout.trim())}, expected ${root.version}`);
71
+ }
72
+ const runtime = resolveInstalledRuntime(directory, platform);
73
+ const packageRoot = await realpath(join(directory, 'node_modules', '@zseven-w', expected));
74
+ const expectedRuntime = {
75
+ binary: join(packageRoot, 'bin', platform.binaryName),
76
+ webBundleDir: join(packageRoot, 'bin', 'web-bundle'),
77
+ canvasKitDir: join(packageRoot, 'bin', 'web-bundle', 'canvaskit'),
78
+ openPencilVersion: openPencil.version,
79
+ revision: openPencil.revision,
80
+ source: 'optional-package',
81
+ };
82
+ if (JSON.stringify(runtime) !== JSON.stringify(expectedRuntime)) {
83
+ throw new Error(`${platform.id}: root resolver selected ${JSON.stringify(runtime)}, expected ${JSON.stringify(expectedRuntime)}`);
84
+ }
85
+ } finally {
86
+ await rm(directory, { recursive: true, force: true });
87
+ }
88
+ }
89
+
90
+ async function verifyUnsupportedLibc(platform, dependencies, root) {
91
+ const directory = await createConsumer(dependencies, root);
92
+ try {
93
+ runNpm([
94
+ 'install',
95
+ '--ignore-scripts',
96
+ '--package-lock=false',
97
+ '--no-audit',
98
+ '--no-fund',
99
+ '--offline',
100
+ `--os=${platform.os}`,
101
+ `--cpu=${platform.cpu}`,
102
+ '--libc=musl',
103
+ ], directory);
104
+ const installed = await installedRuntimePackages(directory);
105
+ if (installed.length !== 0) {
106
+ throw new Error(`${platform.id}/musl: expected no glibc runtime, installed ${installed.join(', ')}`);
107
+ }
108
+ if (tryResolveInstalledRuntime(directory, platform) !== undefined) {
109
+ throw new Error(`${platform.id}/musl: resolver unexpectedly found a runtime`);
110
+ }
111
+ } finally {
112
+ await rm(directory, { recursive: true, force: true });
113
+ }
114
+ }
115
+
116
+ async function verifyOmitted(dependencies, root) {
117
+ const directory = await createConsumer(dependencies, root);
118
+ try {
119
+ runNpm([
120
+ 'install',
121
+ '--ignore-scripts',
122
+ '--package-lock=false',
123
+ '--no-audit',
124
+ '--no-fund',
125
+ '--offline',
126
+ '--omit=optional',
127
+ ], directory);
128
+ const installed = await installedRuntimePackages(directory);
129
+ if (installed.length !== 0) throw new Error(`--omit=optional installed ${installed.join(', ')}`);
130
+ if (tryResolveInstalledRuntime(directory, platforms[0]) !== undefined) {
131
+ throw new Error('--omit=optional unexpectedly resolved an editor runtime');
132
+ }
133
+ } finally {
134
+ await rm(directory, { recursive: true, force: true });
135
+ }
136
+ }
137
+
138
+ async function createConsumer(optionalDependencies, root) {
139
+ const directory = await mkdtemp(join(tmpdir(), 'qoder-openpencil-install-'));
140
+ await writeFile(join(directory, 'package.json'), JSON.stringify({
141
+ name: 'qoder-openpencil-install-smoke',
142
+ private: true,
143
+ version: '0.0.0',
144
+ dependencies: {
145
+ '@zseven-w/qoder-openpencil': pathToFileURL(join(root.directory, root.filename)).href,
146
+ },
147
+ optionalDependencies,
148
+ }, null, 2) + '\n');
149
+ return directory;
150
+ }
151
+
152
+ function runNpm(args, cwd) {
153
+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
154
+ const result = spawnSync(npm, args, {
155
+ cwd,
156
+ encoding: 'utf8',
157
+ env: { ...process.env, npm_config_cache: join(tmpdir(), 'qoder-openpencil-npm-cache') },
158
+ shell: process.platform === 'win32',
159
+ });
160
+ if (result.status !== 0) throw new Error(`npm ${args.join(' ')} failed:\n${result.stderr || result.stdout}`);
161
+ }
162
+
163
+ function resolveInstalledRuntime(directory, platform) {
164
+ const output = runResolver(directory, platform, false);
165
+ if (output === '') throw new Error(`${platform.id}: root resolver did not find the installed runtime`);
166
+ return JSON.parse(output);
167
+ }
168
+
169
+ function tryResolveInstalledRuntime(directory, platform) {
170
+ const output = runResolver(directory, platform, true);
171
+ return output === '' ? undefined : JSON.parse(output);
172
+ }
173
+
174
+ function runResolver(directory, platform, optional) {
175
+ const method = optional ? 'tryResolveEditorRuntime' : 'resolveEditorRuntime';
176
+ const source = [
177
+ "const { dirname, join } = require('node:path');",
178
+ "const { pathToFileURL } = require('node:url');",
179
+ "const manifest = require.resolve('@zseven-w/qoder-openpencil/package.json', { paths: [process.cwd()] });",
180
+ "import(pathToFileURL(join(dirname(manifest), 'plugins', 'openpencil', 'scripts', 'editor-runtime.mjs')).href).then(mod => {",
181
+ ` const value = mod.${method}({ platform: ${JSON.stringify(platform.os)}, arch: ${JSON.stringify(platform.cpu)}, env: {} });`,
182
+ " process.stdout.write(value === undefined ? '' : JSON.stringify(value));",
183
+ '}).catch(error => { console.error(error); process.exitCode = 1; });',
184
+ ].join(' ');
185
+ const result = spawnSync(process.execPath, ['-e', source], { cwd: directory, encoding: 'utf8' });
186
+ if (result.status !== 0) throw new Error(`root resolver failed for ${platform.id}:\n${result.stderr || result.stdout}`);
187
+ return result.stdout.trim();
188
+ }
189
+
190
+ async function installedRuntimePackages(directory) {
191
+ try {
192
+ return (await readdir(join(directory, 'node_modules', '@zseven-w')))
193
+ .filter(name => name.startsWith('qoder-openpencil-') && name !== 'qoder-openpencil')
194
+ .sort();
195
+ } catch {
196
+ return [];
197
+ }
198
+ }
199
+
200
+ async function verifyReportIntegrity(report) {
201
+ const tarball = await readFile(join(report.directory, report.filename));
202
+ const integrity = `sha512-${createHash('sha512').update(tarball).digest('base64')}`;
203
+ const shasum = createHash('sha1').update(tarball).digest('hex');
204
+ if (report.integrity !== integrity || report.shasum !== shasum) {
205
+ throw new Error(`${report.name}@${report.version}: report integrity does not match tarball`);
206
+ }
207
+ }
208
+
209
+ async function readReports(directory) {
210
+ const output = [];
211
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
212
+ const path = join(directory, entry.name);
213
+ if (entry.isDirectory()) output.push(...await readReports(path));
214
+ else if (entry.name.endsWith('.tgz.json')) {
215
+ output.push({ ...JSON.parse(await readFile(path, 'utf8')), directory });
216
+ }
217
+ }
218
+ return output;
219
+ }