@stallforge/cli 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/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # CLI
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Author tooling for creating, testing, validating and publishing plugins.
4
+
5
+ Shared check tools live in the sibling `contracts` repository.
6
+
7
+ The SDK scan used by validate is a guardrail and not a sandbox.
8
+
9
+ ## Commands
10
+
11
+ - `create NAME [--type example|payment] [--slot SLOT] [--scope-value VALUE] [--license SPDX] [--dir FOLDER]` — make a plugin from a template
12
+ - `dev [DIR] [--once] [--call HANDLER] [--input JSON]` — load the plugin in the test host and reload on change
13
+ - `test [DIR]` — run the unit tests and the slot suite of every claimed slot
14
+ - `validate [DIR_OR_BUNDLE_FOLDER]` — check the manifest, the SDK range, the bundle scan and capability use
15
+ - `publish [DIR] [--out FOLDER] [--source-tag TAG]` — build the bundle twice and write the bundle folder and registry entry
16
+ - `doctor [DIR]` — check this machine and the plugin in the folder
17
+
18
+ ## Bundle layout
19
+
20
+ `publish` writes one folder per plugin version under the output root (default `dist/`):
21
+
22
+ ```
23
+ dist/NAME-VERSION/
24
+ index.mjs single-file ES module, minified, no source map, nothing external except node: built-ins
25
+ plugin.json the source manifest with entry set to index.mjs; every other key and the key order unchanged;
26
+ serialized as JSON.stringify(value, null, 2) plus one newline (UTF-8, LF)
27
+ registry-entry.json serialized the same way
28
+ ```
29
+
30
+ `bundle.sha256` is the SHA-256 of the exact bytes of `index.mjs`; `manifest.sha256` is the SHA-256 of the exact bytes of `plugin.json` as written; both are lower-case hex. The same source builds to the same bundle bytes in any folder (two builds in different temporary folders are compared on every publish).
31
+
32
+ ## Checks
33
+
34
+ - `npm test`
35
+ - `npm run lint`
36
+ - `npm run format`
37
+ - `npm run typecheck`
38
+ - `npm run brand:check`
39
+ - `npm run plan-ids:check`
package/bin/cli.mjs ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from '../src/main.mjs';
3
+
4
+ process.exitCode = await run(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@stallforge/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Author tooling: create, dev, test, validate, publish and doctor for plugins.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=24.15.0"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./types/index.d.ts",
13
+ "default": "./src/index.mjs"
14
+ },
15
+ "./bundle": {
16
+ "types": "./types/bundle.d.ts",
17
+ "default": "./src/lib/bundle.mjs"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "bin",
23
+ "src",
24
+ "types"
25
+ ],
26
+ "scripts": {
27
+ "test": "node --test \"test/**/*.test.mjs\"",
28
+ "lint": "biome check .",
29
+ "format": "biome check --write .",
30
+ "typecheck": "tsc -p tsconfig.json",
31
+ "brand:check": "node ../contracts/tools/brand-check.mjs --root .",
32
+ "plan-ids:check": "node ../contracts/tools/no-plan-ids.mjs --root .",
33
+ "prepare": "husky"
34
+ },
35
+ "devDependencies": {
36
+ "@biomejs/biome": "2.6.9",
37
+ "@commitlint/cli": "21.3.0",
38
+ "@commitlint/config-conventional": "21.3.0",
39
+ "@types/node": "26.6.11",
40
+ "husky": "9.1.7",
41
+ "typescript": "7.0.2"
42
+ },
43
+ "bin": {
44
+ "stallforge": "./bin/cli.mjs"
45
+ },
46
+ "imports": {
47
+ "#contracts/*": "@stallforge/contracts/*",
48
+ "#sdk": "@stallforge/plugin-sdk",
49
+ "#sdk/*": "@stallforge/plugin-sdk/*"
50
+ },
51
+ "dependencies": {
52
+ "@stallforge/contracts": "0.2.0",
53
+ "@stallforge/plugin-sdk": "0.2.0",
54
+ "@stallforge/plugin-template": "0.1.0",
55
+ "rolldown": "1.3.4"
56
+ },
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "https://github.com/stallforge/cli"
60
+ }
61
+ }
@@ -0,0 +1,117 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parseArgs } from 'node:util';
4
+ import { SLOTS } from '#contracts/src/manifest/validate.mjs';
5
+ import { exampleOf, getShape } from '#contracts/src/slot-shapes/index.mjs';
6
+ import { SDK_VERSION } from '#sdk';
7
+ import own from '../../package.json' with { type: 'json' };
8
+ import { CLI_NAME, CLI_PACKAGE, SDK_PACKAGE } from '../lib/names.mjs';
9
+ import { loadTemplates } from '../lib/templates.mjs';
10
+ import { UsageError } from '../lib/usage.mjs';
11
+
12
+ const NAME = /^[a-z][a-z0-9-]{0,62}$/;
13
+ const LICENSE = /^[A-Za-z0-9.+() -]{1,100}$/;
14
+ const GENERATED = ['plugin.json', 'src/index.ts', 'test/plugin.test.ts'];
15
+
16
+ // A plugin that claims a registry slot: the manifest claim uses the registry mode, and each registry handler gets a stub
17
+ // that answers with the shape's example output, so the slot suite tells the author what is left to implement.
18
+ function slotFiles(slot, name, values, scopeValue) {
19
+ const claim = { slot: slot.name, mode: slot.mode, ...(slot.scope === null ? {} : { scope_value: scopeValue }) };
20
+ const manifest = {
21
+ manifest_version: 0,
22
+ name,
23
+ version: '0.1.0',
24
+ license: values.LICENSE,
25
+ type: slot.name,
26
+ sdk: values.SDK_RANGE,
27
+ entry: 'src/index.ts',
28
+ capabilities: [],
29
+ slots: [claim],
30
+ };
31
+ const shape = getShape(slot.name);
32
+ const stubs = (slot.handlers ?? []).map(
33
+ (handler) =>
34
+ ` async ${handler}(_input, _ctx) {\n return ${JSON.stringify(exampleOf(shape, handler)?.output ?? null)};\n },`,
35
+ );
36
+ const source = [
37
+ `import type { Handlers, PluginContext, PluginModule } from '${SDK_PACKAGE}';`,
38
+ '',
39
+ 'export default {',
40
+ ' async activate(_ctx: PluginContext) {},',
41
+ ' async dispose() {},',
42
+ '} satisfies PluginModule;',
43
+ '',
44
+ 'export const handlers: Handlers = {',
45
+ ...stubs,
46
+ '};',
47
+ '',
48
+ ].join('\n');
49
+ return [
50
+ { path: 'plugin.json', text: `${JSON.stringify(manifest, null, 2)}\n` },
51
+ { path: 'src/index.ts', text: source },
52
+ ];
53
+ }
54
+
55
+ export async function create(argv, ctx) {
56
+ const { values, positionals } = parseArgs({
57
+ args: argv,
58
+ allowPositionals: true,
59
+ options: {
60
+ type: { type: 'string', default: 'example' },
61
+ slot: { type: 'string' },
62
+ 'scope-value': { type: 'string' },
63
+ license: { type: 'string', default: 'MIT-0' },
64
+ dir: { type: 'string' },
65
+ },
66
+ });
67
+ const [name] = positionals;
68
+ if (!name)
69
+ throw new UsageError(
70
+ `usage: ${CLI_NAME} create NAME [--type TEMPLATE] [--slot SLOT] [--scope-value VALUE] [--license SPDX] [--dir FOLDER]`,
71
+ );
72
+ if (!NAME.test(name))
73
+ throw new UsageError(
74
+ `"${name}" is not a valid plugin name; use lower case letters, digits and hyphens, starting with a letter (at most 63 characters)`,
75
+ );
76
+ if (!LICENSE.test(values.license)) throw new UsageError(`"${values.license}" is not a valid license identifier`);
77
+ const templates = await loadTemplates();
78
+ const types = templates.listTemplates();
79
+ if (!types.includes(values.type))
80
+ throw new UsageError(`unknown template "${values.type}"; available: ${types.join(', ')}`);
81
+ /** @type {{ name: string, mode: string, handlers?: string[] | null, scope?: string | null } | null} */
82
+ let slot = null;
83
+ if (values.slot !== undefined) {
84
+ slot = SLOTS.slots.find((item) => item.name === values.slot) ?? null;
85
+ if (!slot)
86
+ throw new UsageError(
87
+ `unknown slot "${values.slot}"; slots are: ${SLOTS.slots.map((item) => item.name).join(', ')}`,
88
+ );
89
+ if (values.type !== 'example')
90
+ throw new UsageError('--slot starts from the example template; the payment template already claims its slot');
91
+ if (slot.scope !== null && values['scope-value'] === undefined)
92
+ throw new UsageError(`slot ${slot.name} is scoped to ${slot.scope}; pass --scope-value VALUE`);
93
+ }
94
+ const target = path.resolve(ctx.cwd, values.dir ?? name);
95
+ if (fs.existsSync(target) && fs.readdirSync(target).length > 0)
96
+ throw new Error(`${target} already exists and is not empty`);
97
+ const vars = {
98
+ PLUGIN_NAME: name,
99
+ LICENSE: values.license,
100
+ SDK_PACKAGE,
101
+ SDK_RANGE: `^${SDK_VERSION}`,
102
+ CLI_PACKAGE,
103
+ CLI_RANGE: `^${own.version}`,
104
+ CLI_NAME,
105
+ };
106
+ const files = templates.templateFiles(values.type).filter((file) => slot === null || !GENERATED.includes(file.path));
107
+ const written = files.map((file) => ({ path: file.path, text: templates.renderTemplate(file.text, vars) }));
108
+ if (slot) written.push(...slotFiles(slot, name, vars, values['scope-value']));
109
+ for (const file of written) {
110
+ const out = path.join(target, file.path);
111
+ fs.mkdirSync(path.dirname(out), { recursive: true });
112
+ fs.writeFileSync(out, file.text);
113
+ }
114
+ ctx.out(`${name}: created ${written.length} files in ${target}`);
115
+ ctx.out(`next: cd ${path.relative(ctx.cwd, target) || '.'} && npm install && ${CLI_NAME} test`);
116
+ return 0;
117
+ }
@@ -0,0 +1,106 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parseArgs } from 'node:util';
4
+ import { createTestkitAdapter } from '#sdk/conformance';
5
+ import { readManifest } from '../lib/inspect.mjs';
6
+
7
+ const IGNORED = /(^|[\\/])(node_modules|dist|\.git)([\\/]|$)/;
8
+
9
+ // One plugin in the SDK testkit host. load() replaces the running copy; the loader gives every load a fresh module.
10
+ export function createSession(dir, ctx) {
11
+ const adapter = createTestkitAdapter();
12
+ /** @type {import("../../types/shims/conformance.d.ts").HostHandle | null} */
13
+ let host = null;
14
+ let name = path.basename(dir);
15
+ async function stop() {
16
+ if (!host) return;
17
+ const current = host;
18
+ host = null;
19
+ try {
20
+ await current.unload(name);
21
+ } catch {
22
+ // the host is closed next
23
+ }
24
+ await current.close();
25
+ }
26
+ async function load() {
27
+ await stop();
28
+ const read = readManifest(dir);
29
+ name = read.name;
30
+ for (const error of read.errors) ctx.err(`error: ${error}`);
31
+ if (!read.manifest) return false;
32
+ host = await adapter.create();
33
+ const result = await host.load(dir);
34
+ if (result.state !== 'active') {
35
+ for (const error of result.errors) ctx.err(`error: ${name}: ${error}`);
36
+ await stop();
37
+ return false;
38
+ }
39
+ ctx.out(`${name}: active (${read.manifest.capabilities.join(', ') || 'no capabilities'})`);
40
+ return read.errors.length === 0;
41
+ }
42
+ async function call(handler, input) {
43
+ if (!host) throw new Error(`${name} is not loaded`);
44
+ try {
45
+ ctx.out(JSON.stringify(await host.callHandler(name, handler, input)));
46
+ return true;
47
+ } catch (error) {
48
+ const err = /** @type {{ code?: string, message?: string }} */ (error);
49
+ ctx.err(`error: ${name}: ${handler} failed with ${err?.code ?? 'error'}: ${err?.message ?? ''}`);
50
+ return false;
51
+ } finally {
52
+ const current = host;
53
+ if (current) {
54
+ for (const row of await current.audit()) {
55
+ if (row.outcome === 'denied') ctx.err(`denied: ${row.plugin}: ${row.action} ${JSON.stringify(row.details)}`);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ return { load, call, stop };
61
+ }
62
+
63
+ export async function dev(argv, ctx) {
64
+ const { values, positionals } = parseArgs({
65
+ args: argv,
66
+ allowPositionals: true,
67
+ options: { once: { type: 'boolean' }, call: { type: 'string' }, input: { type: 'string' } },
68
+ });
69
+ const dir = path.resolve(ctx.cwd, positionals[0] ?? '.');
70
+ const session = createSession(dir, ctx);
71
+ let ok = await session.load();
72
+ if (ok && values.call !== undefined)
73
+ ok = await session.call(values.call, values.input === undefined ? {} : JSON.parse(values.input));
74
+ if (values.once || values.call !== undefined) {
75
+ await session.stop();
76
+ return ok ? 0 : 1;
77
+ }
78
+ const controller = new AbortController();
79
+ const signal = ctx.signal ?? controller.signal;
80
+ if (!ctx.signal) process.once('SIGINT', () => controller.abort());
81
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
82
+ let timer;
83
+ let busy = Promise.resolve();
84
+ const watcher = fs.watch(dir, { recursive: true }, (_event, file) => {
85
+ if (file && IGNORED.test(String(file))) return;
86
+ clearTimeout(timer);
87
+ timer = setTimeout(() => {
88
+ busy = busy.then(async () => {
89
+ ctx.out(`${path.basename(dir)}: change detected, reloading`);
90
+ await session.load();
91
+ ctx.out('reload finished');
92
+ });
93
+ }, 150);
94
+ });
95
+ watcher.on('error', () => {});
96
+ ctx.out(`watching ${dir}; press Ctrl+C to stop`);
97
+ await new Promise((resolve) => {
98
+ if (signal.aborted) resolve(undefined);
99
+ else signal.addEventListener('abort', () => resolve(undefined), { once: true });
100
+ });
101
+ clearTimeout(timer);
102
+ watcher.close();
103
+ await busy;
104
+ await session.stop();
105
+ return 0;
106
+ }
@@ -0,0 +1,48 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { sdkSatisfies } from '#contracts/src/manifest/sdk-range.mjs';
4
+ import { SLOTS } from '#contracts/src/manifest/validate.mjs';
5
+ import { SDK_VERSION } from '#sdk';
6
+ import own from '../../package.json' with { type: 'json' };
7
+ import { BUNDLER, BUNDLER_PIN, BUNDLER_VERSION } from '../lib/build.mjs';
8
+ import { readManifest } from '../lib/inspect.mjs';
9
+ import { SDK_PACKAGE } from '../lib/names.mjs';
10
+ import { loadTemplates } from '../lib/templates.mjs';
11
+
12
+ // The author side of the health check: this machine, the pinned tools and the plugin in the folder.
13
+ export async function doctor(argv, ctx) {
14
+ const dir = path.resolve(ctx.cwd, argv[0] ?? '.');
15
+ const types = (await loadTemplates()).listTemplates();
16
+ const rows = [
17
+ {
18
+ id: 'node',
19
+ ok: sdkSatisfies(own.engines.node, process.versions.node),
20
+ detail: `${process.version}, needs ${own.engines.node}`,
21
+ },
22
+ {
23
+ id: 'type-stripping',
24
+ ok: Boolean(process.features.typescript),
25
+ detail: `process.features.typescript is ${JSON.stringify(process.features.typescript ?? null)}`,
26
+ },
27
+ {
28
+ id: 'bundler',
29
+ ok: BUNDLER_VERSION === BUNDLER_PIN,
30
+ detail: `${BUNDLER} ${BUNDLER_VERSION} installed, ${BUNDLER_PIN} pinned`,
31
+ },
32
+ { id: 'sdk', ok: true, detail: `${SDK_PACKAGE} ${SDK_VERSION}` },
33
+ { id: 'templates', ok: types.length >= 2, detail: types.join(', ') },
34
+ {
35
+ id: 'slots',
36
+ ok: SLOTS.slots.every((slot) => Array.isArray(slot.handlers)),
37
+ detail: `${SLOTS.slots.length} slots in the registry, each with a handler list`,
38
+ },
39
+ ];
40
+ if (fs.existsSync(path.join(dir, 'plugin.json'))) {
41
+ const read = readManifest(dir);
42
+ rows.push({ id: 'plugin', ok: read.errors.length === 0, detail: read.errors[0] ?? `${read.name} reads cleanly` });
43
+ } else {
44
+ rows.push({ id: 'plugin', ok: true, detail: 'no plugin.json here, plugin checks skipped' });
45
+ }
46
+ for (const row of rows) ctx.out(`${row.ok ? 'ok ' : 'FAIL'} ${row.id}: ${row.detail}`);
47
+ return rows.every((row) => row.ok) ? 0 : 1;
48
+ }
@@ -0,0 +1,42 @@
1
+ import path from 'node:path';
2
+ import { parseArgs } from 'node:util';
3
+ import { writeBundle } from '../lib/bundle.mjs';
4
+ import { checkPlugin } from '../lib/check.mjs';
5
+ import { report } from '../lib/report.mjs';
6
+ import { UsageError } from '../lib/usage.mjs';
7
+
8
+ const TAG = /^[A-Za-z0-9._/-]{1,100}$/;
9
+
10
+ // Builds twice, refuses on any problem, then writes the bundle folder. Nothing is pushed or sent anywhere.
11
+ export async function publish(argv, ctx) {
12
+ const { values, positionals } = parseArgs({
13
+ args: argv,
14
+ allowPositionals: true,
15
+ options: { out: { type: 'string' }, 'source-tag': { type: 'string' } },
16
+ });
17
+ if (values['source-tag'] !== undefined && !TAG.test(values['source-tag']))
18
+ throw new UsageError(`"${values['source-tag']}" is not a valid source tag`);
19
+ const dir = path.resolve(ctx.cwd, positionals[0] ?? '.');
20
+ const result = await checkPlugin(dir, { builds: 2 });
21
+ report(ctx, result);
22
+ if (result.errors.length > 0 || !result.bundle) {
23
+ ctx.err(`${result.name}: publish stopped, nothing was written`);
24
+ return 1;
25
+ }
26
+ const written = writeBundle({
27
+ outRoot: path.resolve(dir, values.out ?? 'dist'),
28
+ raw: result.raw,
29
+ manifest: result.manifest,
30
+ bundle: result.bundle,
31
+ sourceTag: values['source-tag'] ?? null,
32
+ });
33
+ const { entry } = written;
34
+ ctx.out(`${result.name}: wrote ${written.dir}`);
35
+ ctx.out(
36
+ `${result.name}: bundle sha256 ${entry.bundle.sha256} (${entry.bundle.bytes} bytes), manifest sha256 ${entry.manifest.sha256}`,
37
+ );
38
+ ctx.out(
39
+ `${result.name}: two clean builds matched byte for byte (${entry.toolchain.bundler} ${entry.toolchain.version})`,
40
+ );
41
+ return 0;
42
+ }
@@ -0,0 +1,83 @@
1
+ import { spawn } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { parseArgs } from 'node:util';
6
+ import { runSlotSuite } from '#sdk/slot-suites';
7
+ import { buildBundle } from '../lib/build.mjs';
8
+ import { BUNDLE_FILES, manifestText } from '../lib/bundle.mjs';
9
+ import { readManifest } from '../lib/inspect.mjs';
10
+
11
+ // The author's own tests run in a child process with the plain Node test runner: no mocks, no extra framework.
12
+ // NODE_TEST_CONTEXT is removed so a run started from inside another test run reports on its own.
13
+ function runUnitTests(dir, ctx) {
14
+ return new Promise((resolve) => {
15
+ const env = { ...process.env };
16
+ delete env.NODE_TEST_CONTEXT;
17
+ const child = spawn(process.execPath, ['--test', 'test/**/*.test.*'], {
18
+ cwd: dir,
19
+ env,
20
+ stdio: ['ignore', 'pipe', 'pipe'],
21
+ });
22
+ let stdout = '';
23
+ let stderr = '';
24
+ child.stdout.on('data', (chunk) => {
25
+ stdout += chunk;
26
+ });
27
+ child.stderr.on('data', (chunk) => {
28
+ stderr += chunk;
29
+ });
30
+ child.on('close', (code) => {
31
+ if (stdout) ctx.out(stdout.trimEnd());
32
+ if (stderr) ctx.err(stderr.trimEnd());
33
+ resolve(code ?? 1);
34
+ });
35
+ });
36
+ }
37
+
38
+ export async function test(argv, ctx) {
39
+ const { positionals } = parseArgs({ args: argv, allowPositionals: true, options: {} });
40
+ const dir = path.resolve(ctx.cwd, positionals[0] ?? '.');
41
+ const read = readManifest(dir);
42
+ for (const error of read.errors) ctx.err(`error: ${error}`);
43
+ if (!read.manifest) return 1;
44
+ let code = read.errors.length > 0 ? 1 : 0;
45
+
46
+ if (fs.existsSync(path.join(dir, 'test'))) {
47
+ if ((await runUnitTests(dir, ctx)) !== 0) {
48
+ ctx.err(`error: ${read.name}: the unit tests failed`);
49
+ code = 1;
50
+ }
51
+ } else {
52
+ ctx.out(`${read.name}: no test folder, unit tests not run`);
53
+ }
54
+
55
+ const claims = read.manifest.slots;
56
+ if (claims.length === 0) {
57
+ ctx.out(`${read.name}: no slot claimed, slot suite not run`);
58
+ return code;
59
+ }
60
+ if (read.manifest.entry === undefined) return 1;
61
+ // The suite runs against the built bundle in the shipped layout, so what passes is what ships.
62
+ const work = fs.mkdtempSync(path.join(os.tmpdir(), 'suite-'));
63
+ try {
64
+ fs.writeFileSync(path.join(work, BUNDLE_FILES.bundle), await buildBundle(dir, read.manifest.entry));
65
+ fs.writeFileSync(path.join(work, BUNDLE_FILES.manifest), manifestText(read.raw));
66
+ for (const claim of claims) {
67
+ const result = await runSlotSuite(claim.slot, work);
68
+ const passed = result.results.filter((item) => item.status === 'pass').length;
69
+ for (const item of result.results.filter((entry) => entry.status !== 'pass')) {
70
+ ctx.err(`error: ${read.name}: slot ${claim.slot}: ${item.part}/${item.id} ${item.status}: ${item.message}`);
71
+ }
72
+ ctx.out(`${read.name}: slot ${claim.slot}: ${passed} of ${result.results.length} checks passed`);
73
+ if (!result.ok) code = 1;
74
+ }
75
+ } catch (error) {
76
+ const err = /** @type {{ message?: string }} */ (error);
77
+ ctx.err(`error: ${read.name}: build failed: ${String(err?.message ?? error).split('\n')[0]}`);
78
+ code = 1;
79
+ } finally {
80
+ fs.rmSync(work, { recursive: true, force: true });
81
+ }
82
+ return code;
83
+ }
@@ -0,0 +1,35 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parseArgs } from 'node:util';
4
+ import { BUNDLE_FILES, verifyBundle } from '../lib/bundle.mjs';
5
+ import { checkPlugin, scanBundle } from '../lib/check.mjs';
6
+ import { readManifest } from '../lib/inspect.mjs';
7
+ import { report } from '../lib/report.mjs';
8
+
9
+ // A published bundle folder: integrity, manifest, SDK range and scan of the shipped file.
10
+ function checkBundleFolder(dir) {
11
+ const verified = verifyBundle(dir);
12
+ const read = readManifest(dir);
13
+ const errors = [...new Set([...verified.problems, ...read.errors])];
14
+ const warnings = [];
15
+ const file = path.join(dir, BUNDLE_FILES.bundle);
16
+ if (read.manifest && fs.existsSync(file)) {
17
+ const scanned = scanBundle({ name: read.name, manifest: read.manifest, bundleText: fs.readFileSync(file, 'utf8') });
18
+ errors.push(...scanned.errors);
19
+ warnings.push(...scanned.warnings);
20
+ }
21
+ return { name: read.name, errors, warnings };
22
+ }
23
+
24
+ export async function validate(argv, ctx) {
25
+ const { positionals } = parseArgs({ args: argv, allowPositionals: true, options: {} });
26
+ const dir = path.resolve(ctx.cwd, positionals[0] ?? '.');
27
+ const result = fs.existsSync(path.join(dir, BUNDLE_FILES.entry)) ? checkBundleFolder(dir) : await checkPlugin(dir);
28
+ report(ctx, result);
29
+ if (result.errors.length > 0) {
30
+ ctx.err(`${result.name}: ${result.errors.length} problem(s), not valid`);
31
+ return 1;
32
+ }
33
+ ctx.out(`${result.name}: valid (${result.warnings.length} warning(s))`);
34
+ return 0;
35
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import pkg from '../package.json' with { type: 'json' };
2
+
3
+ export function cliVersion() {
4
+ return pkg.version;
5
+ }
6
+
7
+ export { checkPlugin } from './lib/check.mjs';
8
+ export { readManifest } from './lib/inspect.mjs';
9
+ export { run } from './main.mjs';
@@ -0,0 +1,35 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { rolldown } from 'rolldown';
5
+ import own from '../../package.json' with { type: 'json' };
6
+ import { SDK_PACKAGE } from './names.mjs';
7
+ import { packageInfo } from './package-info.mjs';
8
+
9
+ export const BUNDLER = 'rolldown';
10
+ export const BUNDLER_PIN = own.dependencies.rolldown;
11
+ export const BUNDLER_VERSION = packageInfo(BUNDLER).version;
12
+
13
+ // One clean build to a temporary folder; returns the bytes of the single file. The second build of a publish uses
14
+ // a different, longer folder name so the folder cannot leak into the output unnoticed. Settings are fixed here
15
+ // (single-file ES module, minified, no source map, node platform); a plugin has no bundler setting of its own.
16
+ export async function buildBundle(dir, entry, index = 0) {
17
+ const out = fs.mkdtempSync(
18
+ path.join(os.tmpdir(), index === 0 ? 'bundle-' : 'bundle-second-build-in-a-longer-folder-name-'),
19
+ );
20
+ const file = path.join(out, 'index.mjs');
21
+ let bundle;
22
+ try {
23
+ bundle = await rolldown({
24
+ input: path.resolve(dir, entry),
25
+ platform: 'node',
26
+ external: [SDK_PACKAGE],
27
+ logLevel: 'silent',
28
+ });
29
+ await bundle.write({ file, format: 'esm', minify: true, sourcemap: false });
30
+ return fs.readFileSync(file);
31
+ } finally {
32
+ await bundle?.close();
33
+ fs.rmSync(out, { recursive: true, force: true });
34
+ }
35
+ }
@@ -0,0 +1,107 @@
1
+ import { createHash } from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { validateManifestText } from '#contracts/src/manifest/validate.mjs';
5
+ import { BUNDLER, BUNDLER_VERSION } from './build.mjs';
6
+
7
+ export const BUNDLE_FORMAT = 1;
8
+ export const BUNDLE_FILES = Object.freeze({
9
+ bundle: 'index.mjs',
10
+ manifest: 'plugin.json',
11
+ entry: 'registry-entry.json',
12
+ });
13
+
14
+ export const sha256 = (data) => createHash('sha256').update(data).digest('hex');
15
+ export const bundleDirName = (manifest) => `${manifest.name}-${manifest.version}`;
16
+ // The source manifest with only the entry changed; key order is kept so the same source gives the same bytes.
17
+ export const manifestText = (raw) => `${JSON.stringify({ ...raw, entry: BUNDLE_FILES.bundle }, null, 2)}\n`;
18
+ const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
19
+
20
+ /** @param {{ manifest: any, bundle: Uint8Array, manifestBytes: Uint8Array, sourceTag?: string | null }} input */
21
+ export function registryEntry({ manifest, bundle, manifestBytes, sourceTag = null }) {
22
+ return {
23
+ format: BUNDLE_FORMAT,
24
+ name: manifest.name,
25
+ version: manifest.version,
26
+ type: manifest.type,
27
+ license: manifest.license,
28
+ sdk: manifest.sdk,
29
+ capabilities: [...manifest.capabilities].sort(byText),
30
+ network_domains: [...manifest.network.domains].sort(byText),
31
+ slots: manifest.slots.map((item) => ({ slot: item.slot, mode: item.mode })).sort((a, b) => byText(a.slot, b.slot)),
32
+ bundle: { file: BUNDLE_FILES.bundle, sha256: sha256(bundle), bytes: bundle.length },
33
+ manifest: { file: BUNDLE_FILES.manifest, sha256: sha256(manifestBytes), bytes: manifestBytes.length },
34
+ toolchain: { bundler: BUNDLER, version: BUNDLER_VERSION, format: 'esm', minify: true },
35
+ source_tag: sourceTag,
36
+ };
37
+ }
38
+
39
+ // Replaces only outRoot/NAME-VERSION. Nothing is sent anywhere.
40
+ /** @param {{ outRoot: string, raw: any, manifest: any, bundle: Uint8Array, sourceTag?: string | null }} input */
41
+ export function writeBundle({ outRoot, raw, manifest, bundle, sourceTag = null }) {
42
+ const dir = path.join(outRoot, bundleDirName(manifest));
43
+ fs.rmSync(dir, { recursive: true, force: true });
44
+ fs.mkdirSync(dir, { recursive: true });
45
+ const manifestBytes = Buffer.from(manifestText(raw));
46
+ const entry = registryEntry({ manifest, bundle, manifestBytes, sourceTag });
47
+ fs.writeFileSync(path.join(dir, BUNDLE_FILES.bundle), bundle);
48
+ fs.writeFileSync(path.join(dir, BUNDLE_FILES.manifest), manifestBytes);
49
+ fs.writeFileSync(path.join(dir, BUNDLE_FILES.entry), `${JSON.stringify(entry, null, 2)}\n`);
50
+ return { dir, entry };
51
+ }
52
+
53
+ // Integrity and consistency of a bundle folder. Does not scan the code (validate does that).
54
+ export function verifyBundle(dir) {
55
+ const problems = [];
56
+ const read = (file) => {
57
+ try {
58
+ return fs.readFileSync(path.join(dir, file));
59
+ } catch {
60
+ problems.push(`${file} is missing`);
61
+ return null;
62
+ }
63
+ };
64
+ const entryBytes = read(BUNDLE_FILES.entry);
65
+ const bundle = read(BUNDLE_FILES.bundle);
66
+ const manifestBytes = read(BUNDLE_FILES.manifest);
67
+ /** @type {any} */
68
+ let entry = null;
69
+ if (entryBytes) {
70
+ try {
71
+ entry = JSON.parse(entryBytes.toString('utf8'));
72
+ } catch (error) {
73
+ const err = /** @type {{ message?: string }} */ (error);
74
+ problems.push(`${BUNDLE_FILES.entry} is not valid JSON (${err.message})`);
75
+ }
76
+ }
77
+ const label = typeof entry?.name === 'string' ? entry.name : path.basename(path.resolve(dir));
78
+ if (entry && bundle && manifestBytes) {
79
+ if (entry.format !== BUNDLE_FORMAT)
80
+ problems.push(`${BUNDLE_FILES.entry}: format ${entry.format} is not ${BUNDLE_FORMAT}`);
81
+ if (entry.bundle?.sha256 !== sha256(bundle))
82
+ problems.push(
83
+ `${BUNDLE_FILES.bundle}: sha256 ${sha256(bundle)} does not match the registry entry (${entry.bundle?.sha256})`,
84
+ );
85
+ if (entry.bundle?.bytes !== bundle.length)
86
+ problems.push(`${BUNDLE_FILES.bundle}: ${bundle.length} bytes, the registry entry says ${entry.bundle?.bytes}`);
87
+ if (entry.manifest?.sha256 !== sha256(manifestBytes))
88
+ problems.push(
89
+ `${BUNDLE_FILES.manifest}: sha256 ${sha256(manifestBytes)} does not match the registry entry (${entry.manifest?.sha256})`,
90
+ );
91
+ const check = validateManifestText(manifestBytes.toString('utf8'));
92
+ if (!check.ok) {
93
+ problems.push(...check.errors.map((error) => `${BUNDLE_FILES.manifest}: ${error}`));
94
+ } else {
95
+ const manifest = check.manifest;
96
+ if (manifest.entry !== BUNDLE_FILES.bundle)
97
+ problems.push(`${BUNDLE_FILES.manifest}: entry is ${manifest.entry}, a bundle needs ${BUNDLE_FILES.bundle}`);
98
+ if (entry.name !== manifest.name || entry.version !== manifest.version)
99
+ problems.push(
100
+ `${BUNDLE_FILES.entry} names ${entry.name} ${entry.version} but ${BUNDLE_FILES.manifest} is ${manifest.name} ${manifest.version}`,
101
+ );
102
+ if (JSON.stringify(entry.capabilities) !== JSON.stringify([...manifest.capabilities].sort(byText)))
103
+ problems.push(`${BUNDLE_FILES.entry}: capabilities differ from ${BUNDLE_FILES.manifest}`);
104
+ }
105
+ }
106
+ return { ok: problems.length === 0, problems: problems.map((problem) => `${label}: ${problem}`), entry };
107
+ }
@@ -0,0 +1,97 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { scan } from '#sdk/scan';
4
+ import { BUNDLER, BUNDLER_PIN, BUNDLER_VERSION, buildBundle } from './build.mjs';
5
+ import { sha256 } from './bundle.mjs';
6
+ import { readManifest } from './inspect.mjs';
7
+ import { SDK_PACKAGE } from './names.mjs';
8
+
9
+ const CAPABILITY_RULES = new Set(['undeclared-capability', 'unused-capability']);
10
+ const where = (name, finding) =>
11
+ `${name}: index.mjs:${finding.line}:${finding.column} ${finding.rule}: ${finding.message}`;
12
+
13
+ export function rebuildProblem(name, hashes) {
14
+ return new Set(hashes).size > 1
15
+ ? `${name}: rebuild differs: clean builds gave ${hashes.join(' and ')}; a bundle must rebuild byte for byte`
16
+ : null;
17
+ }
18
+
19
+ // Scans the built bundle (what ships) and, when given, the source entry (capability use survives there in full).
20
+ // Capability findings are derived here so every message names the capability.
21
+ /** @param {{ name: string, manifest: any, bundleText: string, sourceText?: string | null }} input */
22
+ export function scanBundle({ name, manifest, bundleText, sourceText = null }) {
23
+ const declared = manifest.capabilities;
24
+ const bundle = scan(bundleText, { capabilities: declared });
25
+ const used = new Set(bundle.used_capabilities);
26
+ if (sourceText !== null)
27
+ for (const item of scan(sourceText, { capabilities: declared, allowRelative: true }).used_capabilities)
28
+ used.add(item);
29
+ const errors = bundle.errors
30
+ .filter((finding) => !CAPABILITY_RULES.has(finding.rule))
31
+ .map((finding) => where(name, finding));
32
+ for (const capability of [...used].sort()) {
33
+ if (!declared.includes(capability))
34
+ errors.push(`${name}: undeclared-capability: the code uses ${capability} but plugin.json does not declare it`);
35
+ }
36
+ if (bundle.imports.includes(SDK_PACKAGE)) {
37
+ errors.push(
38
+ `${name}: sdk-runtime-import: the bundle imports ${SDK_PACKAGE} at run time; the host passes the SDK in through ctx, so import types only (import type)`,
39
+ );
40
+ }
41
+ const warnings = declared
42
+ .filter((capability) => !used.has(capability))
43
+ .map((capability) => `${name}: unused-capability: plugin.json declares ${capability} but the code never uses it`);
44
+ return { errors, warnings, used: [...used].sort() };
45
+ }
46
+
47
+ // Manifest, SDK range, build, scan and capability use of a plugin source folder. builds is 1 for validate and 2 for publish.
48
+ export async function checkPlugin(dir, { builds = 1 } = {}) {
49
+ const read = readManifest(dir);
50
+ /** @type {{ name: string, raw: any, manifest: any, errors: string[], warnings: string[], bundle: Buffer | null, used: string[] }} */
51
+ const result = {
52
+ name: read.name,
53
+ raw: read.raw,
54
+ manifest: read.manifest,
55
+ errors: [...read.errors],
56
+ warnings: [],
57
+ bundle: null,
58
+ used: [],
59
+ };
60
+ if (!read.manifest || read.manifest.entry === undefined) return result;
61
+ const entryFile = path.resolve(dir, read.manifest.entry);
62
+ if (!fs.existsSync(entryFile)) {
63
+ result.errors.push(`${read.name}: entry: ${read.manifest.entry} does not exist`);
64
+ return result;
65
+ }
66
+ if (BUNDLER_VERSION !== BUNDLER_PIN) {
67
+ result.errors.push(
68
+ `${read.name}: ${BUNDLER} ${BUNDLER_VERSION} is installed but ${BUNDLER_PIN} is pinned; install the pinned version before building`,
69
+ );
70
+ return result;
71
+ }
72
+ const hashes = [];
73
+ try {
74
+ for (let index = 0; index < builds; index += 1) {
75
+ const bytes = await buildBundle(dir, read.manifest.entry, index);
76
+ hashes.push(sha256(bytes));
77
+ if (index === 0) result.bundle = bytes;
78
+ }
79
+ } catch (error) {
80
+ const err = /** @type {{ message?: string }} */ (error);
81
+ result.errors.push(`${read.name}: build failed: ${String(err?.message ?? error).split('\n')[0]}`);
82
+ result.bundle = null;
83
+ return result;
84
+ }
85
+ const different = rebuildProblem(read.name, hashes);
86
+ if (different) result.errors.push(different);
87
+ const scanned = scanBundle({
88
+ name: read.name,
89
+ manifest: read.manifest,
90
+ bundleText: /** @type {Buffer} */ (result.bundle).toString('utf8'),
91
+ sourceText: fs.readFileSync(entryFile, 'utf8'),
92
+ });
93
+ result.errors.push(...scanned.errors);
94
+ result.warnings.push(...scanned.warnings);
95
+ result.used = scanned.used;
96
+ return result;
97
+ }
@@ -0,0 +1,38 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { explainRange, sdkSatisfies } from '#contracts/src/manifest/sdk-range.mjs';
4
+ import { validateManifestText } from '#contracts/src/manifest/validate.mjs';
5
+ import { SDK_VERSION } from '#sdk';
6
+
7
+ // Reads and checks plugin.json in a folder. Every error line starts with the plugin name.
8
+ export function readManifest(dir) {
9
+ const label = path.basename(path.resolve(dir));
10
+ let text;
11
+ try {
12
+ text = fs.readFileSync(path.join(dir, 'plugin.json'), 'utf8');
13
+ } catch {
14
+ return {
15
+ name: label,
16
+ raw: null,
17
+ manifest: null,
18
+ errors: [`${label}: plugin.json was not found in ${path.resolve(dir)}`],
19
+ };
20
+ }
21
+ let raw = null;
22
+ try {
23
+ raw = JSON.parse(text);
24
+ } catch {
25
+ // validateManifestText reports the parse error below
26
+ }
27
+ /** @type {any} */
28
+ const parsed = raw;
29
+ const name = typeof parsed?.name === 'string' ? parsed.name : label;
30
+ const check = validateManifestText(text);
31
+ if (!check.ok) return { name, raw, manifest: null, errors: check.errors.map((error) => `${name}: ${error}`) };
32
+ /** @type {any} */
33
+ const manifest = check.manifest;
34
+ const errors = [];
35
+ if (!sdkSatisfies(manifest.sdk, SDK_VERSION)) errors.push(`${name}: sdk: ${explainRange(manifest.sdk, SDK_VERSION)}`);
36
+ if (manifest.entry === undefined) errors.push(`${name}: entry: a plugin needs an entry file to build a bundle`);
37
+ return { name, raw, manifest, errors };
38
+ }
@@ -0,0 +1,7 @@
1
+ // Package names and the command name come from the brand module; no other source file writes them.
2
+ import { brand } from '#contracts/brand';
3
+
4
+ export const SDK_PACKAGE = `${brand.packageScope}/plugin-sdk`;
5
+ export const TEMPLATE_PACKAGE = `${brand.packageScope}/plugin-template`;
6
+ export const CLI_PACKAGE = `${brand.packageScope}/cli`;
7
+ export const CLI_NAME = brand.cliName;
@@ -0,0 +1,19 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ // Finds the folder, name and version of an installed package from any specifier that resolves from here.
6
+ export function packageInfo(specifier) {
7
+ let dir = path.dirname(fileURLToPath(import.meta.resolve(specifier)));
8
+ for (;;) {
9
+ const file = path.join(dir, 'package.json');
10
+ if (fs.existsSync(file)) {
11
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
12
+ if (pkg.name && (specifier === pkg.name || specifier.startsWith(`${pkg.name}/`)))
13
+ return { name: pkg.name, version: pkg.version, root: dir };
14
+ }
15
+ const up = path.dirname(dir);
16
+ if (up === dir) throw new Error(`cannot find the package of ${specifier}`);
17
+ dir = up;
18
+ }
19
+ }
@@ -0,0 +1,4 @@
1
+ export function report(ctx, result) {
2
+ for (const warning of result.warnings) ctx.out(`warning: ${warning}`);
3
+ for (const error of result.errors) ctx.err(`error: ${error}`);
4
+ }
@@ -0,0 +1,6 @@
1
+ import { TEMPLATE_PACKAGE } from './names.mjs';
2
+
3
+ // The template package is a dependency; its folder is found with import.meta.resolve, never by a relative path.
4
+ export async function loadTemplates() {
5
+ return import(import.meta.resolve(TEMPLATE_PACKAGE));
6
+ }
@@ -0,0 +1 @@
1
+ export class UsageError extends Error {}
package/src/main.mjs ADDED
@@ -0,0 +1,61 @@
1
+ import own from '../package.json' with { type: 'json' };
2
+ import { create } from './commands/create.mjs';
3
+ import { dev } from './commands/dev.mjs';
4
+ import { doctor } from './commands/doctor.mjs';
5
+ import { publish } from './commands/publish.mjs';
6
+ import { test } from './commands/test.mjs';
7
+ import { validate } from './commands/validate.mjs';
8
+ import { CLI_NAME } from './lib/names.mjs';
9
+ import { UsageError } from './lib/usage.mjs';
10
+
11
+ const COMMANDS = { create, dev, test, validate, publish, doctor };
12
+ const SUMMARY = {
13
+ create: 'make a plugin from a template',
14
+ dev: 'load the plugin in the test host and reload on change',
15
+ test: 'run the unit tests and the slot suite of every claimed slot',
16
+ validate: 'check the manifest, the SDK range, the bundle scan and capability use',
17
+ publish: 'build the bundle twice and write the bundle folder and registry entry',
18
+ doctor: 'check this machine and the plugin in the folder',
19
+ };
20
+
21
+ export const usage = () =>
22
+ [
23
+ `usage: ${CLI_NAME} COMMAND [options]`,
24
+ '',
25
+ ...Object.keys(COMMANDS).map((name) => ` ${name.padEnd(9)}${SUMMARY[name]}`),
26
+ ].join('\n');
27
+
28
+ // Returns the exit code: 0 ok, 1 a check or an operation failed, 2 usage error.
29
+ export async function run(argv, overrides = {}) {
30
+ const ctx = {
31
+ cwd: process.cwd(),
32
+ out: (line) => process.stdout.write(`${line}\n`),
33
+ err: (line) => process.stderr.write(`${line}\n`),
34
+ ...overrides,
35
+ };
36
+ const [name, ...rest] = argv;
37
+ if (name === undefined) {
38
+ ctx.err(usage());
39
+ return 2;
40
+ }
41
+ if (name === 'help' || name === '--help' || name === '-h') {
42
+ ctx.out(usage());
43
+ return 0;
44
+ }
45
+ if (name === '--version' || name === '-v') {
46
+ ctx.out(own.version);
47
+ return 0;
48
+ }
49
+ if (!Object.hasOwn(COMMANDS, name)) {
50
+ ctx.err(`unknown command "${name}"`);
51
+ ctx.err(usage());
52
+ return 2;
53
+ }
54
+ try {
55
+ return await COMMANDS[name](rest, ctx);
56
+ } catch (error) {
57
+ const err = /** @type {{ message?: string, code?: string }} */ (error);
58
+ ctx.err(`${CLI_NAME} ${name}: ${err.message}`);
59
+ return error instanceof UsageError || String(err?.code).startsWith('ERR_PARSE_ARGS') ? 2 : 1;
60
+ }
61
+ }
@@ -0,0 +1,38 @@
1
+ export declare const BUNDLE_FORMAT: 1;
2
+ export declare const BUNDLE_FILES: {
3
+ readonly bundle: 'index.mjs';
4
+ readonly manifest: 'plugin.json';
5
+ readonly entry: 'registry-entry.json';
6
+ };
7
+ export declare function sha256(data: string | Uint8Array): string;
8
+ export declare function bundleDirName(manifest: { name: string; version: string }): string;
9
+ export declare function manifestText(raw: Record<string, unknown>): string;
10
+ export interface RegistryEntry {
11
+ format: 1;
12
+ name: string;
13
+ version: string;
14
+ type: string;
15
+ license: string;
16
+ sdk: string;
17
+ capabilities: string[];
18
+ network_domains: string[];
19
+ slots: { slot: string; mode: 'exclusive' | 'multi' | 'fan-out' }[];
20
+ bundle: { file: 'index.mjs'; sha256: string; bytes: number };
21
+ manifest: { file: 'plugin.json'; sha256: string; bytes: number };
22
+ toolchain: { bundler: string; version: string; format: 'esm'; minify: true };
23
+ source_tag: string | null;
24
+ }
25
+ export declare function registryEntry(input: {
26
+ manifest: Record<string, any>;
27
+ bundle: Uint8Array;
28
+ manifestBytes: Uint8Array;
29
+ sourceTag?: string | null;
30
+ }): RegistryEntry;
31
+ export declare function writeBundle(input: {
32
+ outRoot: string;
33
+ raw: Record<string, unknown>;
34
+ manifest: Record<string, any>;
35
+ bundle: Uint8Array;
36
+ sourceTag?: string | null;
37
+ }): { dir: string; entry: RegistryEntry };
38
+ export declare function verifyBundle(dir: string): { ok: boolean; problems: string[]; entry: RegistryEntry | null };
@@ -0,0 +1,24 @@
1
+ export interface CommandContext {
2
+ cwd: string;
3
+ out(line: string): void;
4
+ err(line: string): void;
5
+ signal?: AbortSignal;
6
+ }
7
+ export interface PluginCheck {
8
+ name: string;
9
+ raw: Record<string, unknown> | null;
10
+ manifest: Record<string, any> | null;
11
+ errors: string[];
12
+ warnings: string[];
13
+ bundle: Buffer | null;
14
+ used: string[];
15
+ }
16
+ export declare function cliVersion(): string;
17
+ export declare function run(argv: string[], context?: Partial<CommandContext>): Promise<number>;
18
+ export declare function checkPlugin(dir: string, options?: { builds?: number }): Promise<PluginCheck>;
19
+ export declare function readManifest(dir: string): {
20
+ name: string;
21
+ raw: Record<string, unknown> | null;
22
+ manifest: Record<string, any> | null;
23
+ errors: string[];
24
+ };
@@ -0,0 +1,8 @@
1
+ declare const brand: {
2
+ displayName: string;
3
+ slug: string;
4
+ packageScope: string;
5
+ cliName: string;
6
+ };
7
+ export default brand;
8
+ export { brand };
@@ -0,0 +1,11 @@
1
+ export interface HostHandle {
2
+ load(dir: string): Promise<{ state: string; errors: string[] }>;
3
+ unload(name: string): Promise<unknown>;
4
+ callHandler(plugin: string, handler: string, input?: unknown): Promise<unknown>;
5
+ audit(): Promise<{ plugin: string; action: string; outcome: string; details: unknown }[]>;
6
+ close(): Promise<void>;
7
+ }
8
+ export interface HostAdapter {
9
+ create(): Promise<HostHandle>;
10
+ }
11
+ export function createTestkitAdapter(): HostAdapter;
@@ -0,0 +1,18 @@
1
+ export const SLOTS: {
2
+ slots: { name: string; mode: string; handlers?: string[] | null; scope?: string | null }[];
3
+ };
4
+ export function sdkSatisfies(range: string, version: string): boolean;
5
+ export function explainRange(range: string, version: string): string;
6
+ export function validateManifestText(text: string): {
7
+ ok: boolean;
8
+ errors: string[];
9
+ manifest?: any;
10
+ };
11
+ export function getShape(slot: string): any;
12
+ export function exampleOf(slot: string, handler: string): any;
13
+ export const brand: {
14
+ displayName: string;
15
+ slug: string;
16
+ packageScope: string;
17
+ cliName: string;
18
+ };
@@ -0,0 +1,2 @@
1
+ export function sdkSatisfies(range: string, version: string): boolean;
2
+ export function explainRange(range: string, version: string): string;
@@ -0,0 +1,8 @@
1
+ export function scan(
2
+ text: string,
3
+ options?: { capabilities?: string[]; allowRelative?: boolean },
4
+ ): {
5
+ errors: { line: number; column: number; rule: string; message: string }[];
6
+ used_capabilities: string[];
7
+ imports: string[];
8
+ };
@@ -0,0 +1 @@
1
+ export const SDK_VERSION: string;
@@ -0,0 +1,2 @@
1
+ export function getShape(slot: string): any;
2
+ export function exampleOf(slot: string, handler: string): any;
@@ -0,0 +1,9 @@
1
+ export function runSlotSuite(
2
+ slot: string,
3
+ dir: string,
4
+ options?: unknown,
5
+ ): Promise<{
6
+ slot: string;
7
+ ok: boolean;
8
+ results: { id: string; status: string; message: string; part: string }[];
9
+ }>;
@@ -0,0 +1,13 @@
1
+ export const SLOTS: {
2
+ slots: {
3
+ name: string;
4
+ mode: string;
5
+ handlers?: string[] | null;
6
+ scope?: string | null;
7
+ }[];
8
+ };
9
+ export function validateManifestText(text: string): {
10
+ ok: boolean;
11
+ errors: string[];
12
+ manifest?: any;
13
+ };