@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,226 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { setupTui, TUI_COMMAND_IDS } from "../server/tui.js";
|
|
4
|
+
import { formatApplyResult, formatOperationProgress, formatPreviewPlan, formatStatusOverview, } from "../views/operations.js";
|
|
5
|
+
/** Records every handler invocation so tests can prove setup runs nothing. */
|
|
6
|
+
function fakeHandlers(overrides = {}) {
|
|
7
|
+
const calls = [];
|
|
8
|
+
const tracked = (name, impl) => async (...args) => {
|
|
9
|
+
calls.push(name);
|
|
10
|
+
return impl(...args);
|
|
11
|
+
};
|
|
12
|
+
const handlers = {
|
|
13
|
+
capabilities: tracked("capabilities", async () => ({
|
|
14
|
+
protocolVersion: "1.0.0",
|
|
15
|
+
envelopeVersion: 1,
|
|
16
|
+
engine: { name: "@usesketchbook/cli", version: "9.9.9" },
|
|
17
|
+
commands: [{ name: "init", summary: "Initialize." }],
|
|
18
|
+
})),
|
|
19
|
+
run: tracked("run", async () => ({})),
|
|
20
|
+
preview: tracked("preview", async () => ({
|
|
21
|
+
ok: true,
|
|
22
|
+
operationID: "op_preview",
|
|
23
|
+
command: "init",
|
|
24
|
+
dryRun: true,
|
|
25
|
+
envelope: { ok: true, changed: ["sketchbook.config.json"], warnings: [], errors: [] },
|
|
26
|
+
preview: { id: "p1", fingerprint: "abc123", status: "ready" },
|
|
27
|
+
})),
|
|
28
|
+
apply: tracked("apply", async () => ({
|
|
29
|
+
ok: true,
|
|
30
|
+
operationID: "op_preview",
|
|
31
|
+
command: "init",
|
|
32
|
+
envelope: { ok: true, changed: ["sketchbook.config.json"] },
|
|
33
|
+
})),
|
|
34
|
+
cancel: tracked("cancel", async () => ({})),
|
|
35
|
+
status: tracked("status", async () => ({
|
|
36
|
+
ok: true,
|
|
37
|
+
operations: [
|
|
38
|
+
{
|
|
39
|
+
operationID: "op_1",
|
|
40
|
+
command: "init",
|
|
41
|
+
status: "running",
|
|
42
|
+
progressCount: 4,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
operationID: "op_2",
|
|
46
|
+
command: "check",
|
|
47
|
+
status: "completed",
|
|
48
|
+
progressCount: 2,
|
|
49
|
+
finishedAt: "2026-01-01T00:00:00.000Z",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
})),
|
|
53
|
+
...overrides,
|
|
54
|
+
};
|
|
55
|
+
return { handlers, calls };
|
|
56
|
+
}
|
|
57
|
+
function makeTuiContext(handlers) {
|
|
58
|
+
const dialog = {
|
|
59
|
+
alerts: [],
|
|
60
|
+
confirms: [],
|
|
61
|
+
selections: [],
|
|
62
|
+
confirmAnswer: true,
|
|
63
|
+
selectAnswer: undefined,
|
|
64
|
+
};
|
|
65
|
+
const keymapLayers = [];
|
|
66
|
+
const ctx = {
|
|
67
|
+
location: { directory: "/proj" },
|
|
68
|
+
keymap: {
|
|
69
|
+
layer: (factory) => {
|
|
70
|
+
keymapLayers.push(factory());
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
ui: {
|
|
74
|
+
dialog: {
|
|
75
|
+
alert: async (options) => {
|
|
76
|
+
dialog.alerts.push(options);
|
|
77
|
+
},
|
|
78
|
+
confirm: async (options) => {
|
|
79
|
+
dialog.confirms.push(options);
|
|
80
|
+
return dialog.confirmAnswer;
|
|
81
|
+
},
|
|
82
|
+
select: async (options) => {
|
|
83
|
+
dialog.selections.push(options);
|
|
84
|
+
return dialog.selectAnswer;
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
...(handlers ? { __handlers: handlers } : {}),
|
|
89
|
+
};
|
|
90
|
+
return { ctx, dialog, keymapLayers };
|
|
91
|
+
}
|
|
92
|
+
test("setupTui registers the status, operations, and apply commands without executing the engine", async () => {
|
|
93
|
+
const { handlers, calls } = fakeHandlers();
|
|
94
|
+
const { ctx, keymapLayers } = makeTuiContext();
|
|
95
|
+
const report = await setupTui(ctx, { handlers });
|
|
96
|
+
assert.equal(report.supported, true);
|
|
97
|
+
assert.deepEqual(report.missing, []);
|
|
98
|
+
assert.deepEqual([...report.commands].sort(), Object.values(TUI_COMMAND_IDS).sort());
|
|
99
|
+
assert.equal(keymapLayers.length, 1);
|
|
100
|
+
const layer = keymapLayers[0];
|
|
101
|
+
assert.deepEqual(layer.commands.map((command) => command.id).sort(), Object.values(TUI_COMMAND_IDS).sort());
|
|
102
|
+
for (const command of layer.commands) {
|
|
103
|
+
assert.equal(command.palette, true);
|
|
104
|
+
}
|
|
105
|
+
// Registration is pure: no RPC method ran during setup.
|
|
106
|
+
assert.equal(calls.length, 0, "TUI setup must not invoke any RPC method");
|
|
107
|
+
});
|
|
108
|
+
test("the status command shows the overview from capabilities and status", async () => {
|
|
109
|
+
const { handlers, calls } = fakeHandlers();
|
|
110
|
+
const { ctx, dialog, keymapLayers } = makeTuiContext();
|
|
111
|
+
await setupTui(ctx, { handlers });
|
|
112
|
+
calls.length = 0;
|
|
113
|
+
const layer = keymapLayers[0];
|
|
114
|
+
const status = layer.commands.find((command) => command.id === TUI_COMMAND_IDS.status);
|
|
115
|
+
status.run();
|
|
116
|
+
await Promise.resolve();
|
|
117
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
118
|
+
assert.ok(calls.includes("capabilities"));
|
|
119
|
+
assert.ok(calls.includes("status"));
|
|
120
|
+
assert.equal(dialog.alerts.length, 1);
|
|
121
|
+
assert.match(dialog.alerts[0].title, /Sketchbook — status/);
|
|
122
|
+
assert.match(dialog.alerts[0].message, /Engine: @usesketchbook\/cli@9\.9\.9/);
|
|
123
|
+
assert.match(dialog.alerts[0].message, /Operations \(2\)/);
|
|
124
|
+
assert.match(dialog.alerts[0].message, /Status: running/);
|
|
125
|
+
});
|
|
126
|
+
test("the operations command lists every operation with its progress", async () => {
|
|
127
|
+
const { handlers } = fakeHandlers();
|
|
128
|
+
const { ctx, dialog, keymapLayers } = makeTuiContext();
|
|
129
|
+
await setupTui(ctx, { handlers });
|
|
130
|
+
const layer = keymapLayers[0];
|
|
131
|
+
const operations = layer.commands.find((command) => command.id === TUI_COMMAND_IDS.operations);
|
|
132
|
+
operations.run();
|
|
133
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
134
|
+
assert.equal(dialog.alerts.length, 1);
|
|
135
|
+
assert.match(dialog.alerts[0].message, /init · op_1/);
|
|
136
|
+
assert.match(dialog.alerts[0].message, /Progress: █{4}·{8} \(4 lines\)/);
|
|
137
|
+
assert.match(dialog.alerts[0].message, /check · op_2/);
|
|
138
|
+
});
|
|
139
|
+
test("the apply flow previews, confirms, and applies", async () => {
|
|
140
|
+
const { handlers, calls } = fakeHandlers();
|
|
141
|
+
const { ctx, dialog, keymapLayers } = makeTuiContext();
|
|
142
|
+
dialog.selectAnswer = "init";
|
|
143
|
+
dialog.confirmAnswer = true;
|
|
144
|
+
await setupTui(ctx, { handlers });
|
|
145
|
+
calls.length = 0;
|
|
146
|
+
const layer = keymapLayers[0];
|
|
147
|
+
const apply = layer.commands.find((command) => command.id === TUI_COMMAND_IDS.apply);
|
|
148
|
+
apply.run();
|
|
149
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
150
|
+
assert.deepEqual(calls, ["capabilities", "preview", "apply"]);
|
|
151
|
+
assert.equal(dialog.selections.length, 1);
|
|
152
|
+
assert.match(dialog.confirms[0].message, /Fingerprint: abc123/);
|
|
153
|
+
assert.match(dialog.confirms[0].message, /nothing was written yet/);
|
|
154
|
+
const final = dialog.alerts.at(-1);
|
|
155
|
+
assert.match(final.message, /Applied init \(op_preview\)/);
|
|
156
|
+
});
|
|
157
|
+
test("discarding the confirmation never applies", async () => {
|
|
158
|
+
const { handlers, calls } = fakeHandlers();
|
|
159
|
+
const { ctx, dialog, keymapLayers } = makeTuiContext();
|
|
160
|
+
dialog.selectAnswer = "init";
|
|
161
|
+
dialog.confirmAnswer = false;
|
|
162
|
+
await setupTui(ctx, { handlers });
|
|
163
|
+
calls.length = 0;
|
|
164
|
+
const layer = keymapLayers[0];
|
|
165
|
+
layer.commands.find((command) => command.id === TUI_COMMAND_IDS.apply).run();
|
|
166
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
167
|
+
assert.ok(calls.includes("preview"));
|
|
168
|
+
assert.ok(!calls.includes("apply"), "a discarded preview must not be applied");
|
|
169
|
+
assert.match(dialog.alerts.at(-1).message, /nothing was written/);
|
|
170
|
+
});
|
|
171
|
+
test("the apply flow surfaces preview and apply failures without throwing", async () => {
|
|
172
|
+
const { handlers } = fakeHandlers({
|
|
173
|
+
preview: async () => {
|
|
174
|
+
throw new Error("SKETCHBOOK_PERMISSION_DENIED");
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
const { ctx, dialog, keymapLayers } = makeTuiContext();
|
|
178
|
+
dialog.selectAnswer = "init";
|
|
179
|
+
await setupTui(ctx, { handlers });
|
|
180
|
+
const layer = keymapLayers[0];
|
|
181
|
+
layer.commands.find((command) => command.id === TUI_COMMAND_IDS.apply).run();
|
|
182
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
183
|
+
assert.match(dialog.alerts.at(-1).message, /Preview failed: SKETCHBOOK_PERMISSION_DENIED/);
|
|
184
|
+
});
|
|
185
|
+
test("setupTui degrades gracefully when the host lacks TUI APIs", async () => {
|
|
186
|
+
const { handlers, calls } = fakeHandlers();
|
|
187
|
+
const report = await setupTui({ location: { directory: "/proj" } }, { handlers });
|
|
188
|
+
assert.equal(report.supported, false);
|
|
189
|
+
assert.deepEqual([...report.commands], []);
|
|
190
|
+
assert.deepEqual([...report.missing].sort(), ["keymap.layer", "ui.dialog"]);
|
|
191
|
+
assert.equal(calls.length, 0, "no RPC work when the host has no TUI APIs");
|
|
192
|
+
const partial = await setupTui({ ui: {} }, { handlers });
|
|
193
|
+
assert.equal(partial.supported, false);
|
|
194
|
+
assert.ok(partial.missing.includes("ui.dialog"));
|
|
195
|
+
});
|
|
196
|
+
test("the shared view formatters render the RPC results both surfaces show", () => {
|
|
197
|
+
const overview = formatStatusOverview({
|
|
198
|
+
engine: { name: "@usesketchbook/cli", version: "1.0.0" },
|
|
199
|
+
protocolVersion: "1.0.0",
|
|
200
|
+
envelopeVersion: 1,
|
|
201
|
+
commandCount: 3,
|
|
202
|
+
operations: [
|
|
203
|
+
{ operationID: "op_1", command: "init", status: "completed", progressCount: 1 },
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
assert.match(overview.join("\n"), /Engine: @usesketchbook\/cli@1\.0\.0/);
|
|
207
|
+
assert.match(overview.join("\n"), /Commands: 3/);
|
|
208
|
+
const empty = formatStatusOverview({});
|
|
209
|
+
assert.match(empty.join("\n"), /Engine: not detected/);
|
|
210
|
+
const preview = formatPreviewPlan({ command: "init", ok: true, changed: ["a"], warnings: ["w1"], errors: [] }, { fingerprint: "f1" });
|
|
211
|
+
assert.match(preview.join("\n"), /Changed paths: 1/);
|
|
212
|
+
assert.match(preview.join("\n"), /! w1/);
|
|
213
|
+
const applied = formatApplyResult({
|
|
214
|
+
command: "init",
|
|
215
|
+
operationID: "op_1",
|
|
216
|
+
envelope: { changed: ["a", "b"] },
|
|
217
|
+
});
|
|
218
|
+
assert.match(applied.join("\n"), /Changed paths: 2/);
|
|
219
|
+
const failed = formatOperationProgress({
|
|
220
|
+
operationID: "op_9",
|
|
221
|
+
command: "check",
|
|
222
|
+
status: "failed",
|
|
223
|
+
progressCount: 3,
|
|
224
|
+
});
|
|
225
|
+
assert.match(failed.join("\n"), /Status: failed/);
|
|
226
|
+
});
|
package/dist/tprobe.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/tprobe.js
ADDED
package/dist/tui.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
/**
|
|
3
|
+
* The Sketchbook TUI plugin: status overview, operation progress, and the
|
|
4
|
+
* preview/apply workflow, all over the shared RPC surface. Degrades
|
|
5
|
+
* gracefully when the host context lacks TUI APIs (headless or older host):
|
|
6
|
+
* setup reports the gap instead of throwing so the server plugin is never
|
|
7
|
+
* destabilized.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: Plugin.Definition;
|
|
10
|
+
export default _default;
|
package/dist/tui.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
import { setupTui } from "./server/tui.js";
|
|
3
|
+
/**
|
|
4
|
+
* The Sketchbook TUI plugin: status overview, operation progress, and the
|
|
5
|
+
* preview/apply workflow, all over the shared RPC surface. Degrades
|
|
6
|
+
* gracefully when the host context lacks TUI APIs (headless or older host):
|
|
7
|
+
* setup reports the gap instead of throwing so the server plugin is never
|
|
8
|
+
* destabilized.
|
|
9
|
+
*/
|
|
10
|
+
export default Plugin.define({
|
|
11
|
+
id: "sketchbook.tui",
|
|
12
|
+
async setup(ctx) {
|
|
13
|
+
const report = await setupTui(ctx);
|
|
14
|
+
if (!report.supported) {
|
|
15
|
+
// Host without TUI APIs: nothing was registered and nothing threw.
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// keymap layers are removed by the host when the plugin deactivates;
|
|
19
|
+
// there is nothing further to dispose.
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared view sources for the Sketchbook TUI routes and the experimental
|
|
3
|
+
* Desktop UI. Pure formatters over RPC results (plain records): no host APIs,
|
|
4
|
+
* no engine access, no I/O. Both surfaces render the same text so a workflow
|
|
5
|
+
* reads the same everywhere; the TUI presents lines in dialogs and the
|
|
6
|
+
* Desktop panel renders the same lines as a read-only view.
|
|
7
|
+
*/
|
|
8
|
+
export interface StatusOperationView {
|
|
9
|
+
operationID: string;
|
|
10
|
+
command: string;
|
|
11
|
+
status: string;
|
|
12
|
+
startedAt?: string;
|
|
13
|
+
finishedAt?: string;
|
|
14
|
+
progressCount?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface StatusOverviewInput {
|
|
17
|
+
engine?: {
|
|
18
|
+
name?: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
} | null;
|
|
21
|
+
protocolVersion?: string;
|
|
22
|
+
envelopeVersion?: number;
|
|
23
|
+
commandCount?: number;
|
|
24
|
+
operations?: StatusOperationView[];
|
|
25
|
+
}
|
|
26
|
+
/** The status overview: engine, protocol, command surface, recent operations. */
|
|
27
|
+
export declare function formatStatusOverview(input: StatusOverviewInput): string[];
|
|
28
|
+
/** One operation's progress view: identity, status, and a coarse progress meter. */
|
|
29
|
+
export declare function formatOperationProgress(operation: StatusOperationView): string[];
|
|
30
|
+
export interface PreviewPlanView {
|
|
31
|
+
ok?: boolean;
|
|
32
|
+
command?: string;
|
|
33
|
+
changed?: unknown[];
|
|
34
|
+
warnings?: unknown[];
|
|
35
|
+
errors?: unknown[];
|
|
36
|
+
}
|
|
37
|
+
export interface PreviewView {
|
|
38
|
+
operationID?: string;
|
|
39
|
+
fingerprint?: string;
|
|
40
|
+
status?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Formats a dry-run preview for review before the apply confirmation. */
|
|
43
|
+
export declare function formatPreviewPlan(plan: PreviewPlanView, preview?: PreviewView): string[];
|
|
44
|
+
/** Formats a successful apply result. */
|
|
45
|
+
export declare function formatApplyResult(result: {
|
|
46
|
+
ok?: boolean;
|
|
47
|
+
command?: string;
|
|
48
|
+
operationID?: string;
|
|
49
|
+
envelope?: PreviewPlanView;
|
|
50
|
+
}): string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared view sources for the Sketchbook TUI routes and the experimental
|
|
3
|
+
* Desktop UI. Pure formatters over RPC results (plain records): no host APIs,
|
|
4
|
+
* no engine access, no I/O. Both surfaces render the same text so a workflow
|
|
5
|
+
* reads the same everywhere; the TUI presents lines in dialogs and the
|
|
6
|
+
* Desktop panel renders the same lines as a read-only view.
|
|
7
|
+
*/
|
|
8
|
+
/** The status overview: engine, protocol, command surface, recent operations. */
|
|
9
|
+
export function formatStatusOverview(input) {
|
|
10
|
+
const lines = [];
|
|
11
|
+
const engine = input.engine;
|
|
12
|
+
if (engine?.name) {
|
|
13
|
+
lines.push(`Engine: ${engine.name}${engine.version ? `@${engine.version}` : ""}`);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
lines.push("Engine: not detected");
|
|
17
|
+
}
|
|
18
|
+
if (input.protocolVersion)
|
|
19
|
+
lines.push(`Protocol: v${input.protocolVersion}`);
|
|
20
|
+
if (input.envelopeVersion !== undefined)
|
|
21
|
+
lines.push(`Envelope: v${input.envelopeVersion}`);
|
|
22
|
+
if (input.commandCount !== undefined)
|
|
23
|
+
lines.push(`Commands: ${input.commandCount}`);
|
|
24
|
+
const operations = input.operations ?? [];
|
|
25
|
+
if (operations.length === 0) {
|
|
26
|
+
lines.push("Operations: none in this session");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
lines.push(`Operations (${operations.length}):`);
|
|
30
|
+
for (const operation of operations.slice(-8)) {
|
|
31
|
+
lines.push(...formatOperationProgress(operation).map((line) => ` ${line}`));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return lines;
|
|
35
|
+
}
|
|
36
|
+
const PROGRESS_BAR_WIDTH = 12;
|
|
37
|
+
/** One operation's progress view: identity, status, and a coarse progress meter. */
|
|
38
|
+
export function formatOperationProgress(operation) {
|
|
39
|
+
const lines = [`${operation.command} · ${operation.operationID}`];
|
|
40
|
+
lines.push(`Status: ${operation.status}`);
|
|
41
|
+
const count = operation.progressCount ?? 0;
|
|
42
|
+
if (operation.status === "running") {
|
|
43
|
+
const filled = Math.min(PROGRESS_BAR_WIDTH, count);
|
|
44
|
+
const meter = `${"█".repeat(filled)}${"·".repeat(PROGRESS_BAR_WIDTH - filled)}`;
|
|
45
|
+
lines.push(`Progress: ${meter} (${count} line${count === 1 ? "" : "s"})`);
|
|
46
|
+
}
|
|
47
|
+
else if (count > 0) {
|
|
48
|
+
lines.push(`Progress: ${count} line${count === 1 ? "" : "s"} of output`);
|
|
49
|
+
}
|
|
50
|
+
if (operation.finishedAt)
|
|
51
|
+
lines.push(`Finished: ${operation.finishedAt}`);
|
|
52
|
+
return lines;
|
|
53
|
+
}
|
|
54
|
+
/** Formats a dry-run preview for review before the apply confirmation. */
|
|
55
|
+
export function formatPreviewPlan(plan, preview) {
|
|
56
|
+
const lines = [];
|
|
57
|
+
lines.push(`Preview of ${plan.command ?? "operation"}: ${plan.ok === false ? "FAILED" : "no errors"}`);
|
|
58
|
+
if (preview?.fingerprint)
|
|
59
|
+
lines.push(`Fingerprint: ${preview.fingerprint}`);
|
|
60
|
+
lines.push(`Changed paths: ${(plan.changed ?? []).length}`);
|
|
61
|
+
const warnings = plan.warnings ?? [];
|
|
62
|
+
if (warnings.length > 0)
|
|
63
|
+
lines.push(`Warnings (${warnings.length}):`);
|
|
64
|
+
for (const warning of warnings.slice(0, 5))
|
|
65
|
+
lines.push(` ! ${String(warning)}`);
|
|
66
|
+
const errors = plan.errors ?? [];
|
|
67
|
+
if (errors.length > 0)
|
|
68
|
+
lines.push(`Errors (${errors.length}):`);
|
|
69
|
+
for (const error of errors.slice(0, 5))
|
|
70
|
+
lines.push(` x ${String(error)}`);
|
|
71
|
+
lines.push("Applying runs the same command for real; nothing was written yet.");
|
|
72
|
+
return lines;
|
|
73
|
+
}
|
|
74
|
+
/** Formats a successful apply result. */
|
|
75
|
+
export function formatApplyResult(result) {
|
|
76
|
+
return [
|
|
77
|
+
`Applied ${result.command ?? "operation"} (${result.operationID ?? "unknown"}).`,
|
|
78
|
+
`Changed paths: ${(result.envelope?.changed ?? []).length}`,
|
|
79
|
+
];
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usesketchbook/opencode-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenCode V2 plugin for Sketchbook: design-system tools, skills, and UI surfaces.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Davecelot/sketchbook.git",
|
|
13
|
+
"directory": "plugins/opencode"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./rpc": {
|
|
21
|
+
"types": "./dist/rpc.d.ts",
|
|
22
|
+
"import": "./dist/rpc.js"
|
|
23
|
+
},
|
|
24
|
+
"./tui": {
|
|
25
|
+
"types": "./dist/tui.d.ts",
|
|
26
|
+
"import": "./dist/tui.js"
|
|
27
|
+
},
|
|
28
|
+
"./gui-experimental": {
|
|
29
|
+
"types": "./dist/gui.d.ts",
|
|
30
|
+
"import": "./dist/gui.js",
|
|
31
|
+
"require": "./dist/gui-experimental.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json && npm run -s build:gui",
|
|
41
|
+
"build:gui": "node scripts/build-gui.mjs",
|
|
42
|
+
"test": "node --test dist/test/*.test.js",
|
|
43
|
+
"generate:baseline": "node scripts/generate-baseline-manifest.mjs",
|
|
44
|
+
"generate:catalog": "node scripts/generate-catalog-baseline.mjs",
|
|
45
|
+
"sync": "npm run generate:baseline && npm run generate:catalog",
|
|
46
|
+
"prepack": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@opencode/plugin": "2.4.3",
|
|
50
|
+
"@usesketchbook/cli": "^0.10.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.0.0",
|
|
54
|
+
"esbuild": "^0.28.2",
|
|
55
|
+
"typescript": "^6.0.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@opentui/core": ">=0.8.0",
|
|
59
|
+
"@opentui/solid": ">=0.8.0",
|
|
60
|
+
"solid-js": ">=1.9.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"@opentui/core": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"@opentui/solid": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"solid-js": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|