@usesketchbook/opencode-plugin 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/LICENSE +21 -0
- package/README.md +123 -2
- package/dist/generated/baseline-manifest.d.ts +2 -0
- package/dist/generated/baseline-manifest.js +1590 -0
- package/dist/generated/catalog-baseline.d.ts +2 -0
- package/dist/generated/catalog-baseline.js +255 -0
- package/dist/gui-experimental.cjs +111 -0
- package/dist/gui.d.ts +22 -0
- package/dist/gui.js +34 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/rpc.d.ts +1173 -0
- package/dist/rpc.js +212 -0
- package/dist/server/catalog.d.ts +9 -0
- package/dist/server/catalog.js +74 -0
- package/dist/server/decision-guard-hooks.d.ts +2 -0
- package/dist/server/decision-guard-hooks.js +57 -0
- package/dist/server/decision-guards.d.ts +11 -0
- package/dist/server/decision-guards.js +36 -0
- package/dist/server/engine.d.ts +6 -0
- package/dist/server/engine.js +38 -0
- package/dist/server/guard-hooks.d.ts +3 -0
- package/dist/server/guard-hooks.js +35 -0
- package/dist/server/guards.d.ts +13 -0
- package/dist/server/guards.js +42 -0
- package/dist/server/operations.d.ts +93 -0
- package/dist/server/operations.js +300 -0
- package/dist/server/permissions.d.ts +29 -0
- package/dist/server/permissions.js +97 -0
- package/dist/server/rpc.d.ts +126 -0
- package/dist/server/rpc.js +308 -0
- package/dist/server/runner.d.ts +27 -0
- package/dist/server/runner.js +136 -0
- package/dist/server/schema.d.ts +4 -0
- package/dist/server/schema.js +66 -0
- package/dist/server/tools.d.ts +2 -0
- package/dist/server/tools.js +176 -0
- package/dist/server/tui.d.ts +70 -0
- package/dist/server/tui.js +172 -0
- package/dist/shared/catalog.d.ts +52 -0
- package/dist/shared/catalog.js +84 -0
- package/dist/shared/envelope.d.ts +24 -0
- package/dist/shared/envelope.js +28 -0
- package/dist/shared/manifest.d.ts +53 -0
- package/dist/shared/manifest.js +135 -0
- package/dist/test/baseline.test.d.ts +1 -0
- package/dist/test/baseline.test.js +11 -0
- package/dist/test/catalog.test.d.ts +1 -0
- package/dist/test/catalog.test.js +232 -0
- package/dist/test/decision-guards.test.d.ts +1 -0
- package/dist/test/decision-guards.test.js +30 -0
- package/dist/test/engine.test.d.ts +1 -0
- package/dist/test/engine.test.js +23 -0
- package/dist/test/fixtures.d.ts +12 -0
- package/dist/test/fixtures.js +55 -0
- package/dist/test/guard-hooks.integration.test.d.ts +1 -0
- package/dist/test/guard-hooks.integration.test.js +321 -0
- package/dist/test/guard-hooks.test.d.ts +1 -0
- package/dist/test/guard-hooks.test.js +14 -0
- package/dist/test/guards.test.d.ts +1 -0
- package/dist/test/guards.test.js +24 -0
- package/dist/test/gui.test.d.ts +1 -0
- package/dist/test/gui.test.js +61 -0
- package/dist/test/manifest.test.d.ts +1 -0
- package/dist/test/manifest.test.js +86 -0
- package/dist/test/operations.test.d.ts +1 -0
- package/dist/test/operations.test.js +263 -0
- package/dist/test/parity.test.d.ts +1 -0
- package/dist/test/parity.test.js +56 -0
- package/dist/test/permissions.integration.test.d.ts +1 -0
- package/dist/test/permissions.integration.test.js +535 -0
- package/dist/test/permissions.test.d.ts +1 -0
- package/dist/test/permissions.test.js +42 -0
- package/dist/test/rpc.test.d.ts +1 -0
- package/dist/test/rpc.test.js +389 -0
- package/dist/test/runner.test.d.ts +1 -0
- package/dist/test/runner.test.js +47 -0
- package/dist/test/schema.test.d.ts +1 -0
- package/dist/test/schema.test.js +51 -0
- package/dist/test/tui.test.d.ts +1 -0
- package/dist/test/tui.test.js +226 -0
- package/dist/tprobe.d.ts +1 -0
- package/dist/tprobe.js +2 -0
- package/dist/tui.d.ts +10 -0
- package/dist/tui.js +21 -0
- package/dist/views/operations.d.ts +50 -0
- package/dist/views/operations.js +80 -0
- package/package.json +71 -4
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Shared, standalone copy of the CLI capabilities manifest types.
|
|
2
|
+
// Keeping this file independent of deep CLI imports lets the plugin validate
|
|
3
|
+
// manifests from bundled and project engines without assuming their layout.
|
|
4
|
+
export const AUTOMATION_PROTOCOL_VERSION = "1.0.0";
|
|
5
|
+
export const ENVELOPE_VERSION = 1;
|
|
6
|
+
export const COMMAND_RISKS = [
|
|
7
|
+
"read",
|
|
8
|
+
"write",
|
|
9
|
+
"delete",
|
|
10
|
+
"external-write",
|
|
11
|
+
"install",
|
|
12
|
+
"upgrade",
|
|
13
|
+
"privileged",
|
|
14
|
+
];
|
|
15
|
+
export class CompatibilityError extends Error {
|
|
16
|
+
code = "SKETCHBOOK_INCOMPATIBLE_MANIFEST";
|
|
17
|
+
}
|
|
18
|
+
const fail = (message) => {
|
|
19
|
+
throw new CompatibilityError(message);
|
|
20
|
+
};
|
|
21
|
+
const object = (value, message) => value && typeof value === "object" && !Array.isArray(value)
|
|
22
|
+
? value
|
|
23
|
+
: fail(message);
|
|
24
|
+
const string = (value, message) => typeof value === "string" && value ? value : fail(message);
|
|
25
|
+
const boolean = (value, message) => typeof value === "boolean" ? value : fail(message);
|
|
26
|
+
const array = (value, message) => Array.isArray(value) ? value : fail(message);
|
|
27
|
+
function validateArg(value, context) {
|
|
28
|
+
const arg = object(value, `${context} must be an object`);
|
|
29
|
+
return {
|
|
30
|
+
name: string(arg.name, `${context}.name must be a non-empty string`),
|
|
31
|
+
required: boolean(arg.required, `${context}.required must be a boolean`),
|
|
32
|
+
description: string(arg.description, `${context}.description must be a non-empty string`),
|
|
33
|
+
...(arg.variadic === undefined ? {} : { variadic: boolean(arg.variadic, `${context}.variadic must be a boolean`) }),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function validateOption(value, context) {
|
|
37
|
+
const option = object(value, `${context} must be an object`);
|
|
38
|
+
const type = option.type === "boolean" || option.type === "string"
|
|
39
|
+
? option.type
|
|
40
|
+
: fail(`${context}.type must be "boolean" or "string"`);
|
|
41
|
+
return {
|
|
42
|
+
type,
|
|
43
|
+
description: string(option.description, `${context}.description must be a non-empty string`),
|
|
44
|
+
...(option.value === undefined ? {} : { value: string(option.value, `${context}.value must be a non-empty string`) }),
|
|
45
|
+
...(option.short === undefined ? {} : { short: string(option.short, `${context}.short must be a non-empty string`) }),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function validateRisk(value, context) {
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (typeof value !== "string" || !COMMAND_RISKS.includes(value)) {
|
|
52
|
+
return fail(`${context}.risk must be one of ${COMMAND_RISKS.join(", ")}`);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function validateSubcommand(value, context) {
|
|
57
|
+
const subcommand = object(value, `${context} must be an object`);
|
|
58
|
+
return {
|
|
59
|
+
name: string(subcommand.name, `${context}.name must be a non-empty string`),
|
|
60
|
+
usage: string(subcommand.usage, `${context}.usage must be a non-empty string`),
|
|
61
|
+
summary: string(subcommand.summary, `${context}.summary must be a non-empty string`),
|
|
62
|
+
mutates: boolean(subcommand.mutates, `${context}.mutates must be a boolean`),
|
|
63
|
+
risk: validateRisk(subcommand.risk, context),
|
|
64
|
+
examples: array(subcommand.examples, `${context}.examples must be an array`),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function validateCommand(value, context) {
|
|
68
|
+
const command = object(value, `${context} must be an object`);
|
|
69
|
+
const name = string(command.name, `${context}.name must be a non-empty string`);
|
|
70
|
+
const options = object(command.options, `${context}.options must be an object`);
|
|
71
|
+
const subcommands = command.subcommands === undefined
|
|
72
|
+
? undefined
|
|
73
|
+
: array(command.subcommands, `${context}.subcommands must be an array`).map((subcommand, index) => validateSubcommand(subcommand, `${context}.subcommands[${index}]`));
|
|
74
|
+
return {
|
|
75
|
+
name,
|
|
76
|
+
group: string(command.group, `${context}.group must be a non-empty string`),
|
|
77
|
+
summary: string(command.summary, `${context}.summary must be a non-empty string`),
|
|
78
|
+
usage: string(command.usage, `${context}.usage must be a non-empty string`),
|
|
79
|
+
args: array(command.args, `${context}.args must be an array`).map((arg, index) => validateArg(arg, `${context}.args[${index}]`)),
|
|
80
|
+
options: Object.fromEntries(Object.entries(options).map(([key, option]) => [
|
|
81
|
+
key,
|
|
82
|
+
validateOption(option, `${context}.options.${key}`),
|
|
83
|
+
])),
|
|
84
|
+
examples: array(command.examples, `${context}.examples must be an array`),
|
|
85
|
+
mutates: boolean(command.mutates, `${context}.mutates must be a boolean`),
|
|
86
|
+
risk: validateRisk(command.risk, context),
|
|
87
|
+
...(command.dryRun === undefined ? {} : { dryRun: boolean(command.dryRun, `${context}.dryRun must be a boolean`) }),
|
|
88
|
+
...(command.interactiveOnly === undefined
|
|
89
|
+
? {}
|
|
90
|
+
: { interactiveOnly: boolean(command.interactiveOnly, `${context}.interactiveOnly must be a boolean`) }),
|
|
91
|
+
...(command.project === undefined ? {} : { project: boolean(command.project, `${context}.project must be a boolean`) }),
|
|
92
|
+
...(subcommands ? { subcommands } : {}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export function validateManifest(value) {
|
|
96
|
+
const manifest = object(value, "capabilities manifest must be an object");
|
|
97
|
+
if (manifest.protocolVersion !== AUTOMATION_PROTOCOL_VERSION) {
|
|
98
|
+
throw new CompatibilityError(`unsupported automation protocol version ${manifest.protocolVersion ?? "missing"}; expected ${AUTOMATION_PROTOCOL_VERSION}`);
|
|
99
|
+
}
|
|
100
|
+
if (manifest.envelopeVersion !== ENVELOPE_VERSION) {
|
|
101
|
+
throw new CompatibilityError(`unsupported envelope version ${manifest.envelopeVersion ?? "missing"}; expected ${ENVELOPE_VERSION}`);
|
|
102
|
+
}
|
|
103
|
+
const engine = object(manifest.engine, "manifest.engine must be an object");
|
|
104
|
+
const engineName = string(engine.name, "manifest.engine.name must be a non-empty string");
|
|
105
|
+
const engineVersion = string(engine.version, "manifest.engine.version must be a non-empty string");
|
|
106
|
+
if (!engineName || !engineVersion) {
|
|
107
|
+
throw new CompatibilityError("manifest missing engine name or version");
|
|
108
|
+
}
|
|
109
|
+
const groups = object(manifest.groups, "manifest.groups must be an object");
|
|
110
|
+
const commands = array(manifest.commands, "manifest.commands must be an array").map((command, index) => validateCommand(command, `manifest.commands[${index}]`));
|
|
111
|
+
const names = new Set();
|
|
112
|
+
for (const command of commands) {
|
|
113
|
+
if (names.has(command.name)) {
|
|
114
|
+
throw new CompatibilityError(`manifest has duplicate command ${command.name}`);
|
|
115
|
+
}
|
|
116
|
+
names.add(command.name);
|
|
117
|
+
if (!(command.group in groups)) {
|
|
118
|
+
throw new CompatibilityError(`command ${command.name} has unknown group ${command.group}`);
|
|
119
|
+
}
|
|
120
|
+
const subcommandNames = new Set();
|
|
121
|
+
for (const subcommand of command.subcommands ?? []) {
|
|
122
|
+
if (subcommandNames.has(subcommand.name)) {
|
|
123
|
+
throw new CompatibilityError(`command ${command.name} has duplicate subcommand ${subcommand.name}`);
|
|
124
|
+
}
|
|
125
|
+
subcommandNames.add(subcommand.name);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
protocolVersion: manifest.protocolVersion,
|
|
130
|
+
envelopeVersion: manifest.envelopeVersion,
|
|
131
|
+
engine: { name: engineName, version: engineVersion },
|
|
132
|
+
groups: groups,
|
|
133
|
+
commands,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { BASELINE_MANIFEST } from "../generated/baseline-manifest.js";
|
|
4
|
+
import { validateManifest } from "../shared/manifest.js";
|
|
5
|
+
test("the bundled baseline manifest is current and non-empty", () => {
|
|
6
|
+
const manifest = validateManifest(BASELINE_MANIFEST);
|
|
7
|
+
assert.equal(manifest.protocolVersion, "1.0.0");
|
|
8
|
+
assert.equal(manifest.envelopeVersion, 1);
|
|
9
|
+
assert.ok(manifest.commands.length > 0);
|
|
10
|
+
assert.ok(manifest.commands.some((command) => command.name === "capabilities"));
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { cwd } from "node:process";
|
|
6
|
+
import { CATALOG_BASELINE } from "../generated/catalog-baseline.js";
|
|
7
|
+
import { CatalogValidationError, loadCatalogBaseline, renderCommandBody, validateCatalog, } from "../shared/catalog.js";
|
|
8
|
+
import { setupCatalogSurfaces } from "../server/catalog.js";
|
|
9
|
+
const repoRoot = join(cwd(), "..", "..");
|
|
10
|
+
const squish = (text) => text.replaceAll(/\s+/g, " ").trim();
|
|
11
|
+
const readSource = (source) => {
|
|
12
|
+
const path = join(repoRoot, source);
|
|
13
|
+
assert.ok(existsSync(path), `${source} should exist in the shared catalog`);
|
|
14
|
+
return readFileSync(path, "utf8");
|
|
15
|
+
};
|
|
16
|
+
test("the bundled catalog baseline is valid and non-empty", () => {
|
|
17
|
+
const baseline = loadCatalogBaseline();
|
|
18
|
+
assert.equal(baseline.source, "harness/templates/agent-catalog");
|
|
19
|
+
assert.ok(baseline.skills.length >= 10);
|
|
20
|
+
assert.ok(baseline.commands.length >= 10);
|
|
21
|
+
assert.ok(baseline.skills.some((skill) => skill.briefs.length > 0));
|
|
22
|
+
});
|
|
23
|
+
test("every generated skill matches its shared catalog source", () => {
|
|
24
|
+
for (const skill of CATALOG_BASELINE.skills) {
|
|
25
|
+
const source = readSource(skill.source);
|
|
26
|
+
assert.ok(squish(source).includes(squish(skill.description)), `description of ${skill.name} comes from ${skill.source}`);
|
|
27
|
+
assert.ok(squish(source).includes(squish(skill.content)), `content of ${skill.name} comes from ${skill.source}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
test("every generated command matches its shared catalog source", () => {
|
|
31
|
+
for (const command of CATALOG_BASELINE.commands) {
|
|
32
|
+
const source = readSource(command.source);
|
|
33
|
+
assert.ok(squish(source).includes(squish(command.description)), `description of ${command.name} comes from ${command.source}`);
|
|
34
|
+
assert.ok(squish(source).includes(squish(command.content)), `content of ${command.name} comes from ${command.source}`);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
test("agent briefs stay nested under their skill's agents directory", () => {
|
|
38
|
+
for (const skill of CATALOG_BASELINE.skills) {
|
|
39
|
+
for (const brief of skill.briefs) {
|
|
40
|
+
assert.ok(brief.source.startsWith(`${skill.source.slice(0, -"SKILL.md".length)}agents/`));
|
|
41
|
+
const source = readSource(brief.source);
|
|
42
|
+
assert.ok(squish(source).includes(squish(brief.description)), `description of ${brief.name} comes from ${brief.source}`);
|
|
43
|
+
assert.ok(squish(source).includes(squish(brief.content)), `content of ${brief.name} comes from ${brief.source}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
test("generated descriptions are present for every surface", () => {
|
|
48
|
+
for (const skill of CATALOG_BASELINE.skills) {
|
|
49
|
+
assert.ok(skill.description.trim().length > 20, `skill ${skill.name} has a real description`);
|
|
50
|
+
for (const brief of skill.briefs) {
|
|
51
|
+
assert.ok(brief.description.trim().length > 20, `brief ${brief.name} has a real description`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const command of CATALOG_BASELINE.commands) {
|
|
55
|
+
assert.ok(command.description.trim().length > 20, `command ${command.name} has a real description`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
test("no duplicate skill, command or agent brief ids", () => {
|
|
59
|
+
const skills = CATALOG_BASELINE.skills.map((skill) => skill.name);
|
|
60
|
+
assert.equal(new Set(skills).size, skills.length);
|
|
61
|
+
const commands = CATALOG_BASELINE.commands.map((command) => command.name);
|
|
62
|
+
assert.equal(new Set(commands).size, commands.length);
|
|
63
|
+
for (const skill of CATALOG_BASELINE.skills) {
|
|
64
|
+
const briefs = skill.briefs.map((brief) => brief.name);
|
|
65
|
+
assert.equal(new Set(briefs).size, briefs.length);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
test("skills that must not auto-invoke are marked, the rest are", () => {
|
|
69
|
+
for (const skill of CATALOG_BASELINE.skills) {
|
|
70
|
+
if (skill.name === "forge-me-a-skill" || skill.name === "hammock") {
|
|
71
|
+
assert.equal(skill.autoinvoke, false, `${skill.name} is a workflow editor`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
assert.equal(skill.autoinvoke, true);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
test("validation fails on invalid catalog entries", () => {
|
|
79
|
+
const valid = CATALOG_BASELINE;
|
|
80
|
+
const missingDescription = {
|
|
81
|
+
...valid,
|
|
82
|
+
skills: [{ ...valid.skills[0], description: " " }],
|
|
83
|
+
};
|
|
84
|
+
assert.throws(() => validateCatalog(missingDescription), CatalogValidationError);
|
|
85
|
+
const emptyContent = {
|
|
86
|
+
...valid,
|
|
87
|
+
commands: [{ ...valid.commands[0], content: "" }],
|
|
88
|
+
};
|
|
89
|
+
assert.throws(() => validateCatalog(emptyContent), CatalogValidationError);
|
|
90
|
+
const badName = {
|
|
91
|
+
...valid,
|
|
92
|
+
skills: [{ ...valid.skills[0], name: "Bad Name" }],
|
|
93
|
+
};
|
|
94
|
+
assert.throws(() => validateCatalog(badName), CatalogValidationError);
|
|
95
|
+
const duplicateSkill = {
|
|
96
|
+
...valid,
|
|
97
|
+
skills: [valid.skills[0], valid.skills[0]],
|
|
98
|
+
};
|
|
99
|
+
assert.throws(() => validateCatalog(duplicateSkill), /Duplicate skill name/);
|
|
100
|
+
const duplicateBrief = {
|
|
101
|
+
...valid,
|
|
102
|
+
skills: [
|
|
103
|
+
{
|
|
104
|
+
...valid.skills[0],
|
|
105
|
+
briefs: [valid.skills[0].briefs[0], valid.skills[0].briefs[0]],
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
assert.throws(() => validateCatalog(duplicateBrief), /Duplicate agent brief/);
|
|
110
|
+
const duplicateCommand = {
|
|
111
|
+
...valid,
|
|
112
|
+
commands: [valid.commands[0], valid.commands[0]],
|
|
113
|
+
};
|
|
114
|
+
assert.throws(() => validateCatalog(duplicateCommand), /Duplicate command name/);
|
|
115
|
+
const emptyBaseline = { source: valid.source, skills: [], commands: [] };
|
|
116
|
+
assert.throws(() => validateCatalog(emptyBaseline), CatalogValidationError);
|
|
117
|
+
const missingAutoinvoke = {
|
|
118
|
+
...valid,
|
|
119
|
+
skills: [{ ...valid.skills[0], autoinvoke: undefined }],
|
|
120
|
+
};
|
|
121
|
+
assert.throws(() => validateCatalog(missingAutoinvoke), /autoinvoke/);
|
|
122
|
+
});
|
|
123
|
+
test("renderCommandBody substitutes <input> with the arguments", () => {
|
|
124
|
+
assert.equal(renderCommandBody('Add the component "<input>".', "Card"), 'Add the component "Card".');
|
|
125
|
+
// No placeholder: the arguments are appended, never dropped.
|
|
126
|
+
assert.equal(renderCommandBody("Run the checks.", "--all"), "Run the checks.\n\n--all");
|
|
127
|
+
assert.equal(renderCommandBody("Run the checks.", ""), "Run the checks.");
|
|
128
|
+
});
|
|
129
|
+
function makeContext(_baseline) {
|
|
130
|
+
const captured = { skills: [], commands: [], agents: [], prompted: [] };
|
|
131
|
+
const ctx = {
|
|
132
|
+
skill: {
|
|
133
|
+
transform: async (callback) => {
|
|
134
|
+
callback({
|
|
135
|
+
list: () => [],
|
|
136
|
+
add: (skill) => captured.skills.push(skill),
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
command: {
|
|
141
|
+
transform: async (callback) => {
|
|
142
|
+
callback({ add: (definition) => captured.commands.push(definition) });
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
agent: {
|
|
146
|
+
transform: async (callback) => {
|
|
147
|
+
const list = [];
|
|
148
|
+
const byID = new Map();
|
|
149
|
+
callback({
|
|
150
|
+
list: () => list,
|
|
151
|
+
update: (id, update) => {
|
|
152
|
+
let agent = byID.get(id);
|
|
153
|
+
if (!agent) {
|
|
154
|
+
agent = { id };
|
|
155
|
+
byID.set(id, agent);
|
|
156
|
+
list.push(agent);
|
|
157
|
+
}
|
|
158
|
+
update(agent);
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
captured.agents.push(...list);
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
session: {
|
|
165
|
+
prompt: async (input) => {
|
|
166
|
+
captured.prompted.push(input);
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
return { ctx, captured };
|
|
171
|
+
}
|
|
172
|
+
test("setupCatalogSurfaces registers every skill, command and subagent from the baseline", async () => {
|
|
173
|
+
const { ctx, captured } = makeContext(CATALOG_BASELINE);
|
|
174
|
+
await setupCatalogSurfaces(ctx, CATALOG_BASELINE);
|
|
175
|
+
assert.equal(captured.skills.length, CATALOG_BASELINE.skills.length);
|
|
176
|
+
const skillIDs = captured.skills.map((skill) => skill.id);
|
|
177
|
+
assert.deepEqual([...skillIDs].sort(), [...CATALOG_BASELINE.skills.map((skill) => skill.name)].sort());
|
|
178
|
+
assert.equal(captured.commands.length, CATALOG_BASELINE.commands.length);
|
|
179
|
+
assert.deepEqual(captured.commands.map((command) => command.name).sort(), CATALOG_BASELINE.commands.map((command) => command.name).sort());
|
|
180
|
+
const expectedBriefs = CATALOG_BASELINE.skills.flatMap((skill) => skill.briefs);
|
|
181
|
+
assert.equal(captured.agents.length, expectedBriefs.length);
|
|
182
|
+
const agentIDs = captured.agents.map((agent) => agent.id);
|
|
183
|
+
assert.equal(new Set(agentIDs).size, agentIDs.length);
|
|
184
|
+
for (const agent of captured.agents) {
|
|
185
|
+
assert.equal(agent.mode, "subagent");
|
|
186
|
+
assert.ok((agent.system ?? "").trim().length > 0);
|
|
187
|
+
assert.equal(agent.hidden, false);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
test("agents register through update(), even when list() returns a copy", async () => {
|
|
191
|
+
// A real OpenCode 2.4 host returns a copy from list(); mutating it is a
|
|
192
|
+
// silent no-op. Regression test for the pushAgent bug found on-host.
|
|
193
|
+
const { ctx, captured } = makeContext(CATALOG_BASELINE);
|
|
194
|
+
ctx.agent.transform = async (callback) => {
|
|
195
|
+
callback({
|
|
196
|
+
list: () => [{ id: "build" }, { id: "explore" }], // fresh copies every call
|
|
197
|
+
update: (id, update) => {
|
|
198
|
+
const agent = { id };
|
|
199
|
+
update(agent);
|
|
200
|
+
captured.agents.push(agent);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
await setupCatalogSurfaces(ctx, CATALOG_BASELINE);
|
|
205
|
+
const expectedBriefs = CATALOG_BASELINE.skills.flatMap((skill) => skill.briefs);
|
|
206
|
+
assert.equal(captured.agents.length, expectedBriefs.length);
|
|
207
|
+
for (const agent of captured.agents) {
|
|
208
|
+
assert.equal(agent.mode, "subagent");
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
test("slash commands execute by prompting the session with the rendered body", async () => {
|
|
212
|
+
const { ctx, captured } = makeContext(CATALOG_BASELINE);
|
|
213
|
+
await setupCatalogSurfaces(ctx, CATALOG_BASELINE);
|
|
214
|
+
const add = captured.commands.find((command) => command.name === "add");
|
|
215
|
+
assert.ok(add, "the add command from the catalog is registered");
|
|
216
|
+
assert.match(add.description, /^Sketchbook: /);
|
|
217
|
+
await add.execute({ sessionID: "ses_test", prompt: { text: "Card --blank" } });
|
|
218
|
+
assert.equal(captured.prompted.length, 1);
|
|
219
|
+
assert.equal(captured.prompted[0].sessionID, "ses_test");
|
|
220
|
+
assert.ok(captured.prompted[0].text.includes("Card --blank"));
|
|
221
|
+
assert.ok(!captured.prompted[0].text.includes("<input>"), "the placeholder is replaced");
|
|
222
|
+
});
|
|
223
|
+
test("registration skips surfaces the location already provides", async () => {
|
|
224
|
+
const { ctx, captured } = makeContext(CATALOG_BASELINE);
|
|
225
|
+
const existing = CATALOG_BASELINE.skills[0].name;
|
|
226
|
+
ctx.skill.transform = async (callback) => {
|
|
227
|
+
callback({ list: () => [{ id: existing }], add: (skill) => captured.skills.push(skill) });
|
|
228
|
+
};
|
|
229
|
+
await setupCatalogSurfaces(ctx, CATALOG_BASELINE);
|
|
230
|
+
assert.ok(!captured.skills.some((skill) => skill.id === existing));
|
|
231
|
+
assert.equal(captured.skills.length, CATALOG_BASELINE.skills.length - 1);
|
|
232
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { inspectDecisionEdits, inspectDecisionWrite, settledDecisions, } from "../server/decision-guards.js";
|
|
4
|
+
const accepted = `### SB-0001 · 2026-01-01 · Use a native button
|
|
5
|
+
**Status:** accepted
|
|
6
|
+
**Decision:** Use a native button.
|
|
7
|
+
`;
|
|
8
|
+
const proposed = `### SB-0002 · 2026-01-02 · Try a div
|
|
9
|
+
**Status:** proposed
|
|
10
|
+
**Decision:** Use a div.
|
|
11
|
+
`;
|
|
12
|
+
const log = `# Decisions\n\n${accepted}\n${proposed}`;
|
|
13
|
+
test("only accepted decisions are settled", () => {
|
|
14
|
+
assert.equal(settledDecisions(log).length, 1);
|
|
15
|
+
assert.match(settledDecisions(log)[0] ?? "", /SB-0001/);
|
|
16
|
+
});
|
|
17
|
+
test("a write may add or edit proposed entries but not drop accepted ones", () => {
|
|
18
|
+
assert.equal(inspectDecisionWrite(log, log + "\n### SB-0003 · New\n").allowed, true);
|
|
19
|
+
assert.equal(inspectDecisionWrite(log, log.replace(accepted, "")).allowed, false);
|
|
20
|
+
});
|
|
21
|
+
test("an edit may add a whole new entry but not reword a settled one", () => {
|
|
22
|
+
const ok = inspectDecisionEdits(log, [
|
|
23
|
+
{ oldString: "**Decision:** Use a native button.", newString: "**Decision:** Use a native button.\n### SB-0003 · New\n" },
|
|
24
|
+
]);
|
|
25
|
+
assert.equal(ok.allowed, true);
|
|
26
|
+
const changed = inspectDecisionEdits(log, [
|
|
27
|
+
{ oldString: "**Decision:** Use a native button.", newString: "**Decision:** Use a div." },
|
|
28
|
+
]);
|
|
29
|
+
assert.equal(changed.allowed, false);
|
|
30
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { rm } from "node:fs/promises";
|
|
4
|
+
import { resolveEngine } from "../server/engine.js";
|
|
5
|
+
import { makeEngineProject, STUB_ENGINE_VERSION } from "./fixtures.js";
|
|
6
|
+
test("resolveEngine prefers a project-installed CLI", async () => {
|
|
7
|
+
const dir = await makeEngineProject("sketchbook-plugin-engine-");
|
|
8
|
+
try {
|
|
9
|
+
const engine = resolveEngine(dir);
|
|
10
|
+
assert.equal(engine.source, "project");
|
|
11
|
+
assert.ok(engine.path.endsWith("harness/cli.mjs"));
|
|
12
|
+
assert.equal(engine.version, STUB_ENGINE_VERSION);
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
await rm(dir, { recursive: true, force: true });
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
test("resolveEngine falls back to the bundled CLI outside a project", () => {
|
|
19
|
+
const engine = resolveEngine("/nonexistent/path");
|
|
20
|
+
assert.equal(engine.source, "bundled");
|
|
21
|
+
assert.ok(engine.path.endsWith("harness/cli.mjs"));
|
|
22
|
+
assert.ok(engine.version);
|
|
23
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const STUB_ENGINE_VERSION = "0.0.0-test";
|
|
2
|
+
export interface StubOptions {
|
|
3
|
+
exitCode?: number;
|
|
4
|
+
delayMs?: number;
|
|
5
|
+
outputBytes?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates a temporary project with a minimal installed Sketchbook CLI stub.
|
|
9
|
+
* The stub is enough for engine resolution and envelope plumbing tests without
|
|
10
|
+
* depending on the published package or the current checkout.
|
|
11
|
+
*/
|
|
12
|
+
export declare function makeEngineProject(prefix?: string, options?: StubOptions): Promise<string>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
export const STUB_ENGINE_VERSION = "0.0.0-test";
|
|
5
|
+
const stubCliSource = ({ exitCode = 0, delayMs = 0, outputBytes = 0 }) => {
|
|
6
|
+
const exitLine = exitCode === 0 ? "" : ` process.exitCode = ${exitCode};\n`;
|
|
7
|
+
const delayLine = delayMs === 0 ? "" : ` await new Promise((resolve) => setTimeout(resolve, ${delayMs}));\n`;
|
|
8
|
+
const successCondition = outputBytes === 0 ? `command === "capabilities" && json` : "true";
|
|
9
|
+
const successOutput = outputBytes === 0
|
|
10
|
+
? ` process.stdout.write(
|
|
11
|
+
JSON.stringify({
|
|
12
|
+
ok: true,
|
|
13
|
+
command: "capabilities",
|
|
14
|
+
changed: [],
|
|
15
|
+
warnings: [],
|
|
16
|
+
errors: [],
|
|
17
|
+
next: null,
|
|
18
|
+
data: {
|
|
19
|
+
protocolVersion: "1.0.0",
|
|
20
|
+
envelopeVersion: 1,
|
|
21
|
+
engine: { name: "@usesketchbook/cli", version: "${STUB_ENGINE_VERSION}" },
|
|
22
|
+
groups: {},
|
|
23
|
+
commands: [],
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
`
|
|
28
|
+
: ` process.stdout.write("x".repeat(${outputBytes}));
|
|
29
|
+
`;
|
|
30
|
+
return `#!/usr/bin/env node
|
|
31
|
+
const [, , command, ...rest] = process.argv;
|
|
32
|
+
const json = rest.includes("--json");
|
|
33
|
+
${delayLine}if (${successCondition}) {
|
|
34
|
+
${successOutput}${exitLine}} else {
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Creates a temporary project with a minimal installed Sketchbook CLI stub.
|
|
41
|
+
* The stub is enough for engine resolution and envelope plumbing tests without
|
|
42
|
+
* depending on the published package or the current checkout.
|
|
43
|
+
*/
|
|
44
|
+
export async function makeEngineProject(prefix = "sketchbook-plugin-", options = {}) {
|
|
45
|
+
const dir = await mkdtemp(join(tmpdir(), prefix));
|
|
46
|
+
const engineDir = join(dir, "node_modules", "@usesketchbook", "cli");
|
|
47
|
+
await mkdir(join(engineDir, "harness"), { recursive: true });
|
|
48
|
+
await writeFile(join(engineDir, "package.json"), JSON.stringify({ name: "@usesketchbook/cli", version: STUB_ENGINE_VERSION, private: true }));
|
|
49
|
+
await writeFile(join(engineDir, "harness", "cli.mjs"), stubCliSource(options));
|
|
50
|
+
await writeFile(join(dir, "package.json"), JSON.stringify({
|
|
51
|
+
name: "test-project",
|
|
52
|
+
dependencies: { "@usesketchbook/cli": `^${STUB_ENGINE_VERSION}` },
|
|
53
|
+
}));
|
|
54
|
+
return dir;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|