@usesketchbook/opencode-plugin 0.0.0-stage → 0.1.0-rc.1

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 (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -2
  3. package/dist/generated/baseline-manifest.d.ts +2 -0
  4. package/dist/generated/baseline-manifest.js +1590 -0
  5. package/dist/generated/catalog-baseline.d.ts +2 -0
  6. package/dist/generated/catalog-baseline.js +255 -0
  7. package/dist/gui-experimental.cjs +111 -0
  8. package/dist/gui.d.ts +22 -0
  9. package/dist/gui.js +34 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +20 -0
  12. package/dist/rpc.d.ts +1173 -0
  13. package/dist/rpc.js +212 -0
  14. package/dist/server/catalog.d.ts +9 -0
  15. package/dist/server/catalog.js +74 -0
  16. package/dist/server/decision-guard-hooks.d.ts +2 -0
  17. package/dist/server/decision-guard-hooks.js +57 -0
  18. package/dist/server/decision-guards.d.ts +11 -0
  19. package/dist/server/decision-guards.js +36 -0
  20. package/dist/server/engine.d.ts +6 -0
  21. package/dist/server/engine.js +38 -0
  22. package/dist/server/guard-hooks.d.ts +3 -0
  23. package/dist/server/guard-hooks.js +35 -0
  24. package/dist/server/guards.d.ts +13 -0
  25. package/dist/server/guards.js +42 -0
  26. package/dist/server/operations.d.ts +93 -0
  27. package/dist/server/operations.js +300 -0
  28. package/dist/server/permissions.d.ts +29 -0
  29. package/dist/server/permissions.js +97 -0
  30. package/dist/server/rpc.d.ts +126 -0
  31. package/dist/server/rpc.js +308 -0
  32. package/dist/server/runner.d.ts +27 -0
  33. package/dist/server/runner.js +136 -0
  34. package/dist/server/schema.d.ts +4 -0
  35. package/dist/server/schema.js +66 -0
  36. package/dist/server/tools.d.ts +2 -0
  37. package/dist/server/tools.js +176 -0
  38. package/dist/server/tui.d.ts +70 -0
  39. package/dist/server/tui.js +172 -0
  40. package/dist/shared/catalog.d.ts +52 -0
  41. package/dist/shared/catalog.js +84 -0
  42. package/dist/shared/envelope.d.ts +24 -0
  43. package/dist/shared/envelope.js +28 -0
  44. package/dist/shared/manifest.d.ts +53 -0
  45. package/dist/shared/manifest.js +135 -0
  46. package/dist/test/baseline.test.d.ts +1 -0
  47. package/dist/test/baseline.test.js +11 -0
  48. package/dist/test/catalog.test.d.ts +1 -0
  49. package/dist/test/catalog.test.js +232 -0
  50. package/dist/test/decision-guards.test.d.ts +1 -0
  51. package/dist/test/decision-guards.test.js +30 -0
  52. package/dist/test/engine.test.d.ts +1 -0
  53. package/dist/test/engine.test.js +23 -0
  54. package/dist/test/fixtures.d.ts +12 -0
  55. package/dist/test/fixtures.js +55 -0
  56. package/dist/test/guard-hooks.integration.test.d.ts +1 -0
  57. package/dist/test/guard-hooks.integration.test.js +321 -0
  58. package/dist/test/guard-hooks.test.d.ts +1 -0
  59. package/dist/test/guard-hooks.test.js +14 -0
  60. package/dist/test/guards.test.d.ts +1 -0
  61. package/dist/test/guards.test.js +24 -0
  62. package/dist/test/gui.test.d.ts +1 -0
  63. package/dist/test/gui.test.js +61 -0
  64. package/dist/test/manifest.test.d.ts +1 -0
  65. package/dist/test/manifest.test.js +86 -0
  66. package/dist/test/operations.test.d.ts +1 -0
  67. package/dist/test/operations.test.js +263 -0
  68. package/dist/test/parity.test.d.ts +1 -0
  69. package/dist/test/parity.test.js +56 -0
  70. package/dist/test/permissions.integration.test.d.ts +1 -0
  71. package/dist/test/permissions.integration.test.js +535 -0
  72. package/dist/test/permissions.test.d.ts +1 -0
  73. package/dist/test/permissions.test.js +42 -0
  74. package/dist/test/rpc.test.d.ts +1 -0
  75. package/dist/test/rpc.test.js +389 -0
  76. package/dist/test/runner.test.d.ts +1 -0
  77. package/dist/test/runner.test.js +47 -0
  78. package/dist/test/schema.test.d.ts +1 -0
  79. package/dist/test/schema.test.js +51 -0
  80. package/dist/test/tui.test.d.ts +1 -0
  81. package/dist/test/tui.test.js +226 -0
  82. package/dist/tprobe.d.ts +1 -0
  83. package/dist/tprobe.js +2 -0
  84. package/dist/tui.d.ts +10 -0
  85. package/dist/tui.js +21 -0
  86. package/dist/views/operations.d.ts +50 -0
  87. package/dist/views/operations.js +80 -0
  88. package/package.json +71 -4
@@ -0,0 +1,389 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { rm, readFile, writeFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import { RPC_ERROR_CODES, RpcMethodError, createSketchbookRpcHandlers, getOperation, resetOperations, setupRpc, } from "../server/rpc.js";
6
+ import { makeEngineProject, STUB_ENGINE_VERSION } from "./fixtures.js";
7
+ import { SketchbookRpc } from "../rpc.js";
8
+ const capabilitiesEnvelope = `${JSON.stringify(JSON.stringify({
9
+ ok: true,
10
+ command: "capabilities",
11
+ changed: [],
12
+ warnings: [],
13
+ errors: [],
14
+ next: null,
15
+ data: {
16
+ protocolVersion: "1.0.0",
17
+ envelopeVersion: 1,
18
+ engine: { name: "@usesketchbook/cli", version: STUB_ENGINE_VERSION },
19
+ groups: { project: "Project" },
20
+ commands: [
21
+ {
22
+ name: "mutate",
23
+ group: "project",
24
+ summary: "A mutating test command.",
25
+ usage: "sketchbook mutate",
26
+ args: [{ name: "target", required: true, description: "Target" }],
27
+ options: { yes: { type: "boolean", description: "Confirm" } },
28
+ examples: [],
29
+ mutates: true,
30
+ dryRun: true,
31
+ risk: "write",
32
+ },
33
+ ],
34
+ },
35
+ }))}`;
36
+ const echoProject = async () => {
37
+ const dir = await makeEngineProject("sketchbook-plugin-rpc-");
38
+ await writeFile(join(dir, "node_modules/@usesketchbook/cli/harness/cli.mjs"), `#!/usr/bin/env node
39
+ const [, , command, ...rest] = process.argv;
40
+ if (command === "capabilities") {
41
+ process.stdout.write(${capabilitiesEnvelope});
42
+ } else {
43
+ process.stdout.write(
44
+ JSON.stringify({
45
+ ok: true,
46
+ command,
47
+ changed: [],
48
+ warnings: [],
49
+ errors: [],
50
+ next: null,
51
+ data: rest,
52
+ }),
53
+ );
54
+ }
55
+ `);
56
+ return dir;
57
+ };
58
+ // An engine that reports every invocation to runs.log, prints five progress
59
+ // lines on stderr (stdout stays a parseable JSON envelope), serves the
60
+ // capabilities manifest, and optionally pauses before finishing.
61
+ const observableProject = async ({ delayMs = 0 } = {}) => {
62
+ const dir = await makeEngineProject("sketchbook-plugin-rpc-obs-");
63
+ await writeFile(join(dir, "node_modules/@usesketchbook/cli/harness/cli.mjs"), `#!/usr/bin/env node
64
+ import { appendFileSync } from "node:fs";
65
+ import { join } from "node:path";
66
+ const [, , command, ...rest] = process.argv;
67
+ appendFileSync(join(process.cwd(), "runs.log"), command + "\\n");
68
+ if (command === "capabilities") {
69
+ process.stdout.write(${capabilitiesEnvelope});
70
+ } else {
71
+ if (${delayMs}) await new Promise((resolve) => setTimeout(resolve, ${delayMs}));
72
+ for (let i = 1; i <= 5; i++) {
73
+ process.stderr.write("line-" + i + "\\n");
74
+ }
75
+ process.stdout.write(
76
+ JSON.stringify({
77
+ ok: true,
78
+ command,
79
+ changed: [],
80
+ warnings: [],
81
+ errors: [],
82
+ next: null,
83
+ data: rest,
84
+ }),
85
+ );
86
+ }
87
+ `);
88
+ return dir;
89
+ };
90
+ const envFor = (root, permission) => {
91
+ const events = { progress: [], operation: [] };
92
+ return {
93
+ env: {
94
+ root,
95
+ permission,
96
+ emit: (name, data) => {
97
+ events[name].push({ ...data });
98
+ },
99
+ },
100
+ events,
101
+ };
102
+ };
103
+ const rejectsType = (promise, type, code) => assert.rejects(promise, (error) => {
104
+ assert.equal(error.type, type);
105
+ if (code)
106
+ assert.equal(error.data?.code, code);
107
+ return true;
108
+ });
109
+ test("the RPC definition exposes the full method and event surface", () => {
110
+ const names = Object.keys(SketchbookRpc.methods).sort();
111
+ assert.deepEqual(names, ["apply", "cancel", "capabilities", "preview", "run", "status"]);
112
+ assert.deepEqual(Object.keys(SketchbookRpc.events).sort(), ["operation", "progress"]);
113
+ for (const method of Object.values(SketchbookRpc.methods)) {
114
+ assert.ok(method.errors, "every Sketchbook method declares its typed errors");
115
+ assert.ok(Object.keys(method.errors).every((name) => name.startsWith("sketchbook_")));
116
+ }
117
+ });
118
+ test("setupRpc registers the surface without executing the engine", async () => {
119
+ const dir = await observableProject();
120
+ try {
121
+ resetOperations();
122
+ const registered = [];
123
+ const ctx = {
124
+ location: { directory: dir },
125
+ permission: undefined,
126
+ rpc: {
127
+ register: async (definition, handlers) => {
128
+ registered.push(definition, handlers);
129
+ return {
130
+ events: { emit: async () => { } },
131
+ dispose: async () => { },
132
+ };
133
+ },
134
+ },
135
+ };
136
+ await setupRpc(ctx);
137
+ assert.equal(registered.length, 2);
138
+ const [definition, handlers] = registered;
139
+ assert.equal(definition.id, "sketchbook");
140
+ assert.equal(Object.keys(definition.methods).length, 6);
141
+ // Nothing ran: no engine invocation and no tracked operation.
142
+ assert.equal(Object.keys(handlers).length, 6);
143
+ const ran = await readFile(join(dir, "runs.log"), "utf8").then(() => true, () => false);
144
+ assert.equal(ran, false, "plugin setup must not execute the engine");
145
+ }
146
+ finally {
147
+ await rm(dir, { recursive: true, force: true });
148
+ }
149
+ });
150
+ test("run executes an operation and reports the envelope", async () => {
151
+ resetOperations();
152
+ const dir = await echoProject();
153
+ try {
154
+ const { env, events } = envFor(dir);
155
+ const handlers = createSketchbookRpcHandlers(env);
156
+ // Dry-run-capable mutations preview by default.
157
+ const previewed = await handlers.run({ command: "mutate", args: ["target"], options: { yes: true } }, {});
158
+ assert.equal(previewed.ok, true);
159
+ assert.equal(previewed.dryRun, true);
160
+ assert.equal(typeof previewed.operationID, "string");
161
+ assert.equal(events.operation.at(-1)?.status, "completed");
162
+ // An explicit dryRun: false applies.
163
+ const applied = await handlers.run({ command: "mutate", args: ["target"], dryRun: false }, {});
164
+ assert.equal(applied.dryRun, false);
165
+ assert.equal(applied.envelope.data[0], "target");
166
+ }
167
+ finally {
168
+ await rm(dir, { recursive: true, force: true });
169
+ }
170
+ });
171
+ test("capabilities loads the manifest and validates its shape", async () => {
172
+ resetOperations();
173
+ const dir = await echoProject();
174
+ try {
175
+ const { env } = envFor(dir);
176
+ const handlers = createSketchbookRpcHandlers(env);
177
+ const output = await handlers.capabilities({}, {});
178
+ assert.equal(output.protocolVersion, "1.0.0");
179
+ assert.equal(output.envelopeVersion, 1);
180
+ assert.ok(Array.isArray(output.commands));
181
+ }
182
+ finally {
183
+ await rm(dir, { recursive: true, force: true });
184
+ }
185
+ });
186
+ test("preview creates a stable, applyable preview and apply reports the applied plan", async () => {
187
+ resetOperations();
188
+ const dir = await echoProject();
189
+ try {
190
+ const { env } = envFor(dir);
191
+ const handlers = createSketchbookRpcHandlers(env);
192
+ const preview = await handlers.preview({ command: "mutate", args: ["target"], options: { yes: true } }, {});
193
+ assert.equal(preview.dryRun, true);
194
+ assert.equal(preview.preview.status, "pending");
195
+ const again = await handlers.preview({ command: "mutate", args: ["target"], options: { yes: true } }, {});
196
+ // Envelope stability: identical operations serialize identically apart
197
+ // from their operation IDs.
198
+ const strip = (value) => JSON.stringify({
199
+ ...value,
200
+ operationID: undefined,
201
+ engine: undefined,
202
+ preview: { ...value.preview, id: undefined },
203
+ });
204
+ assert.equal(strip(preview), strip(again));
205
+ assert.equal(preview.preview.fingerprint, again.preview.fingerprint);
206
+ const applied = await handlers.apply({ operationID: preview.preview.id }, {});
207
+ assert.equal(applied.ok, true);
208
+ assert.equal(applied.dryRun, undefined);
209
+ }
210
+ finally {
211
+ await rm(dir, { recursive: true, force: true });
212
+ }
213
+ });
214
+ test("run emits progress events with strictly increasing sequences in order", async () => {
215
+ resetOperations();
216
+ const dir = await observableProject();
217
+ try {
218
+ const { env, events } = envFor(dir);
219
+ const handlers = createSketchbookRpcHandlers(env);
220
+ const output = await handlers.run({ command: "mutate", args: ["t"] }, {});
221
+ const progress = events.progress.filter((event) => event.operationID === output.operationID);
222
+ // Five stderr progress lines plus the final stdout envelope line.
223
+ assert.equal(progress.length, 6);
224
+ progress.forEach((event, index) => {
225
+ assert.equal(event.sequence, index + 1, "sequences are 1..n in emission order");
226
+ if (index < 5) {
227
+ assert.equal(event.line, `line-${index + 1}`);
228
+ assert.equal(event.source, "stderr");
229
+ }
230
+ else {
231
+ assert.equal(event.source, "stdout");
232
+ }
233
+ });
234
+ assert.deepEqual(progress.map((event) => event.sequence), [...progress.map((event) => event.sequence)].sort((a, b) => a - b));
235
+ }
236
+ finally {
237
+ await rm(dir, { recursive: true, force: true });
238
+ }
239
+ });
240
+ test("cancel stops a running operation and reports the cancelled state", async () => {
241
+ resetOperations();
242
+ const dir = await observableProject({ delayMs: 500 });
243
+ try {
244
+ const { env, events } = envFor(dir);
245
+ const handlers = createSketchbookRpcHandlers(env);
246
+ const running = handlers.run({ command: "mutate", args: ["t"], timeoutMs: 10_000 }, {});
247
+ // Give the child process time to start.
248
+ await new Promise((resolve) => setTimeout(resolve, 100));
249
+ const status = await handlers.status({}, {});
250
+ const runningEntry = status.operations[0];
251
+ assert.ok(runningEntry, "the running operation is tracked");
252
+ assert.equal(runningEntry.status, "running");
253
+ const cancelled = await handlers.cancel({ operationID: runningEntry.operationID }, {});
254
+ assert.equal(cancelled.cancelled, true);
255
+ assert.equal(cancelled.status, "cancelled");
256
+ await rejectsType(running, "sketchbook_cancelled", RPC_ERROR_CODES.cancelled);
257
+ assert.equal(getOperation(runningEntry.operationID)?.status, "cancelled");
258
+ assert.equal(events.operation.at(-1)?.status, "cancelled");
259
+ }
260
+ finally {
261
+ await rm(dir, { recursive: true, force: true });
262
+ }
263
+ });
264
+ test("cancel on an unknown operation is a typed not-found error", async () => {
265
+ resetOperations();
266
+ const dir = await echoProject();
267
+ try {
268
+ const { env } = envFor(dir);
269
+ const handlers = createSketchbookRpcHandlers(env);
270
+ await rejectsType(handlers.cancel({ operationID: "nope" }, {}), "sketchbook_not_found", RPC_ERROR_CODES.notFound);
271
+ await rejectsType(handlers.status({ operationID: "nope" }, {}), "sketchbook_not_found", RPC_ERROR_CODES.notFound);
272
+ }
273
+ finally {
274
+ await rm(dir, { recursive: true, force: true });
275
+ }
276
+ });
277
+ test("cancel on a finished operation reports it without cancelling", async () => {
278
+ resetOperations();
279
+ const dir = await echoProject();
280
+ try {
281
+ const { env } = envFor(dir);
282
+ const handlers = createSketchbookRpcHandlers(env);
283
+ const output = await handlers.run({ command: "mutate", args: ["t"] }, {});
284
+ const result = await handlers.cancel({ operationID: output.operationID }, {});
285
+ assert.equal(result.cancelled, false);
286
+ assert.equal(result.status, "completed");
287
+ }
288
+ finally {
289
+ await rm(dir, { recursive: true, force: true });
290
+ }
291
+ });
292
+ test("cancelling before the engine starts is a typed cancellation", async () => {
293
+ resetOperations();
294
+ const dir = await observableProject();
295
+ try {
296
+ const { env } = envFor(dir);
297
+ const handlers = createSketchbookRpcHandlers(env);
298
+ // A pre-aborted call signal must propagate before the engine spawns.
299
+ const controller = new AbortController();
300
+ controller.abort();
301
+ const abortSignal = controller.signal;
302
+ await rejectsType(handlers.run({ command: "mutate", args: ["t"] }, { signal: abortSignal }), "sketchbook_cancelled", RPC_ERROR_CODES.cancelled);
303
+ }
304
+ finally {
305
+ await rm(dir, { recursive: true, force: true });
306
+ }
307
+ });
308
+ test("unknown commands and subcommands produce typed operation errors", async () => {
309
+ resetOperations();
310
+ const dir = await echoProject();
311
+ try {
312
+ const { env } = envFor(dir);
313
+ const handlers = createSketchbookRpcHandlers(env);
314
+ await rejectsType(handlers.run({ command: "missing" }, {}), "sketchbook_operation", "SKETCHBOOK_OPERATION_ERROR");
315
+ }
316
+ finally {
317
+ await rm(dir, { recursive: true, force: true });
318
+ }
319
+ });
320
+ test("timeouts and output limits map to typed errors", async () => {
321
+ resetOperations();
322
+ const slow = await observableProject({ delayMs: 500 });
323
+ const loud = await echoProject();
324
+ try {
325
+ const slowHandlers = createSketchbookRpcHandlers(envFor(slow).env);
326
+ await rejectsType(slowHandlers.run({ command: "mutate", args: ["t"], timeoutMs: 50 }, {}), "sketchbook_timeout", RPC_ERROR_CODES.timeout);
327
+ const loudHandlers = createSketchbookRpcHandlers(envFor(loud).env);
328
+ await rejectsType(loudHandlers.run({ command: "mutate", args: ["t"], maxOutputBytes: 8 }, {}), "sketchbook_output_limit", RPC_ERROR_CODES.outputLimit);
329
+ }
330
+ finally {
331
+ await rm(slow, { recursive: true, force: true });
332
+ await rm(loud, { recursive: true, force: true });
333
+ }
334
+ });
335
+ test("stale previews apply with a typed stale-preview error and no write", async () => {
336
+ resetOperations();
337
+ const dir = await echoProject();
338
+ try {
339
+ const { env } = envFor(dir);
340
+ const handlers = createSketchbookRpcHandlers(env);
341
+ await rejectsType(handlers.apply({ operationID: "never-created" }, {}), "sketchbook_stale_preview", RPC_ERROR_CODES.stalePreview);
342
+ }
343
+ finally {
344
+ await rm(dir, { recursive: true, force: true });
345
+ }
346
+ });
347
+ test("permission denials surface as typed permission errors", async () => {
348
+ resetOperations();
349
+ const dir = await echoProject();
350
+ try {
351
+ const permission = {
352
+ assert: async () => {
353
+ throw new Error("sketchbook.run denied by policy");
354
+ },
355
+ };
356
+ const { env } = envFor(dir, permission);
357
+ const handlers = createSketchbookRpcHandlers(env);
358
+ await rejectsType(handlers.run({ command: "mutate", args: ["t"] }, {}), "sketchbook_permission", RPC_ERROR_CODES.permission);
359
+ }
360
+ finally {
361
+ await rm(dir, { recursive: true, force: true });
362
+ }
363
+ });
364
+ test("failed engines produce typed operation errors with the engine message", async () => {
365
+ resetOperations();
366
+ const dir = await makeEngineProject("sketchbook-plugin-rpc-fail-");
367
+ await writeFile(join(dir, "node_modules/@usesketchbook/cli/harness/cli.mjs"), `#!/usr/bin/env node
368
+ process.stderr.write("engine exploded\\n");
369
+ process.exitCode = 1;
370
+ `);
371
+ try {
372
+ const { env } = envFor(dir);
373
+ const handlers = createSketchbookRpcHandlers(env);
374
+ await assert.rejects(handlers.run({ command: "mutate", args: ["t"] }, {}), (error) => {
375
+ assert.equal(error.type, "sketchbook_operation");
376
+ assert.equal(error.data.code, "SKETCHBOOK_OPERATION_ERROR");
377
+ assert.match(error.message, /engine exploded/);
378
+ return true;
379
+ });
380
+ }
381
+ finally {
382
+ await rm(dir, { recursive: true, force: true });
383
+ }
384
+ });
385
+ test("RpcMethodError carries the SKETCHBOOK_* code it reports", () => {
386
+ const error = new RpcMethodError(RPC_ERROR_CODES.notFound, "nope");
387
+ assert.equal(error.code, RPC_ERROR_CODES.notFound);
388
+ assert.match(error.message, /nope/);
389
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { rm } from "node:fs/promises";
4
+ import { runSketchbook } from "../server/runner.js";
5
+ import { makeEngineProject } from "./fixtures.js";
6
+ const withProject = async (run, prefix = "sketchbook-plugin-runner-", options = {}) => {
7
+ const dir = await makeEngineProject(prefix, options);
8
+ try {
9
+ await run(dir);
10
+ }
11
+ finally {
12
+ await rm(dir, { recursive: true, force: true });
13
+ }
14
+ };
15
+ test("runSketchbook invokes capabilities and returns an envelope", () => withProject(async (dir) => {
16
+ const result = await runSketchbook({ root: dir, command: "capabilities" });
17
+ assert.equal(result.envelope.ok, true);
18
+ assert.equal(result.envelope.command, "capabilities");
19
+ assert.ok(Array.isArray(result.envelope.changed));
20
+ assert.equal(result.engine.source, "project");
21
+ }));
22
+ test("runSketchbook forwards cancellation through AbortSignal", () => withProject(async (dir) => {
23
+ const controller = new AbortController();
24
+ controller.abort();
25
+ await assert.rejects(runSketchbook({ root: dir, command: "capabilities", signal: controller.signal }), /killed|abort/);
26
+ }));
27
+ test("runSketchbook reports progress lines", () => withProject(async (dir) => {
28
+ const lines = [];
29
+ await runSketchbook({
30
+ root: dir,
31
+ command: "capabilities",
32
+ onLine: (line, source) => lines.push({ line, source }),
33
+ });
34
+ assert.ok(lines.some((l) => l.source === "stdout"));
35
+ }));
36
+ test("runSketchbook treats exit code 2 as success with flags", () => withProject(async (dir) => {
37
+ const result = await runSketchbook({ root: dir, command: "capabilities" });
38
+ assert.equal(result.envelope.ok, true);
39
+ assert.equal(result.envelope.command, "capabilities");
40
+ assert.equal(result.engine.source, "project");
41
+ }, "sketchbook-plugin-runner-flags-", { exitCode: 2 }));
42
+ test("runSketchbook enforces a timeout", () => withProject(async (dir) => {
43
+ await assert.rejects(runSketchbook({ root: dir, command: "capabilities", timeoutMs: 10 }), /timed out/);
44
+ }, "sketchbook-plugin-runner-timeout-", { delayMs: 200 }));
45
+ test("runSketchbook enforces an output limit", () => withProject(async (dir) => {
46
+ await assert.rejects(runSketchbook({ root: dir, command: "capabilities", maxOutputBytes: 100 }), /output exceeded/);
47
+ }, "sketchbook-plugin-runner-output-", { outputBytes: 1024 }));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { commandInputSchema } from "../server/schema.js";
4
+ const command = (overrides) => ({
5
+ name: "test",
6
+ group: "meta",
7
+ summary: "A test command.",
8
+ usage: "sketchbook test",
9
+ args: [],
10
+ options: {},
11
+ examples: [],
12
+ mutates: false,
13
+ ...overrides,
14
+ });
15
+ const props = (schema) => (schema.properties ?? {});
16
+ test("commandInputSchema marks required args as required", () => {
17
+ const schema = commandInputSchema(command({
18
+ args: [
19
+ { name: "source", required: true, description: "Source path" },
20
+ { name: "target", required: false, description: "Target path" },
21
+ ],
22
+ }));
23
+ assert.deepEqual(schema.required, ["source"]);
24
+ assert.equal(props(schema).source?.type, "string");
25
+ assert.equal(props(schema).target?.type, "string");
26
+ });
27
+ test("commandInputSchema represents subcommands as an enum", () => {
28
+ const schema = commandInputSchema(command({
29
+ subcommands: [
30
+ { name: "list", usage: "test list", summary: "List", mutates: false, examples: [] },
31
+ { name: "add", usage: "test add", summary: "Add", mutates: true, examples: [] },
32
+ ],
33
+ }));
34
+ assert.deepEqual(schema.required, ["subcommand"]);
35
+ assert.deepEqual(props(schema).subcommand?.enum, ["list", "add"]);
36
+ });
37
+ test("commandInputSchema maps boolean and string options", () => {
38
+ const schema = commandInputSchema(command({
39
+ options: {
40
+ verbose: { type: "boolean", description: "Verbose output" },
41
+ format: { type: "string", description: "Output format", value: "json" },
42
+ },
43
+ }));
44
+ assert.equal(props(schema).verbose?.type, "boolean");
45
+ assert.equal(props(schema).format?.type, "string");
46
+ assert.deepEqual(props(schema).format?.enum, ["json"]);
47
+ });
48
+ test("commandInputSchema includes dryRun when supported", () => {
49
+ const schema = commandInputSchema(command({ dryRun: true }));
50
+ assert.equal(props(schema).dryRun?.type, "boolean");
51
+ });
@@ -0,0 +1 @@
1
+ export {};