@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Davecelot
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @usesketchbook/opencode-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An OpenCode V2 plugin that brings Sketchbook into OpenCode as a first-class way to use the design system.
|
|
4
|
+
|
|
5
|
+
The plugin is a thin, permission-aware adapter over the Sketchbook CLI. It discovers the project's installed engine, reads its `capabilities` manifest, and registers the matching OpenCode tools, skills, commands, and UI surfaces. The CLI stays the source of truth; the plugin does not reimplement Sketchbook operations.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
### Engine discovery
|
|
10
|
+
|
|
11
|
+
When OpenCode loads the plugin in a location, the plugin resolves which Sketchbook CLI to run:
|
|
12
|
+
|
|
13
|
+
1. **Project engine.** If the location has a `package.json`, the plugin resolves `@usesketchbook/cli` from it, the way Node resolves any dependency. Your project's pinned version is what runs.
|
|
14
|
+
2. **Bundled engine.** Without a project, the plugin falls back to the `@usesketchbook/cli` it ships as a dependency. This is what makes `sketchbook init` work in an empty directory.
|
|
15
|
+
|
|
16
|
+
Every tool result and RPC response reports which engine ran (`source: "project" | "bundled"` with its path and version), so you can always tell where an operation came from.
|
|
17
|
+
|
|
18
|
+
### The capabilities manifest
|
|
19
|
+
|
|
20
|
+
The plugin never hard-codes the CLI's command list. It runs `sketchbook capabilities --json` and validates the returned manifest: the automation protocol version, the JSON envelope version, and a machine-readable description of every command — arguments, options, subcommands, whether it mutates, its risk level, and whether it supports `--dry-run`.
|
|
21
|
+
|
|
22
|
+
Validation is all-or-nothing. A missing, malformed, or version-incompatible manifest raises a single compatibility error (`SKETCHBOOK_INCOMPATIBLE_MANIFEST`) instead of registering a partial tool set. In practice this means:
|
|
23
|
+
|
|
24
|
+
- **New CLI commands** appear in the plugin without a plugin release, as long as the protocol and envelope versions are unchanged.
|
|
25
|
+
- **Protocol or metadata changes** need a new plugin version; the old one refuses to guess.
|
|
26
|
+
|
|
27
|
+
Registration itself uses a bundled baseline manifest generated from the CLI at plugin build time, so loading the plugin never executes a project-local engine. Operations and the `sketchbook capabilities` tool load and validate the active engine on first use, then cache it per location and engine version.
|
|
28
|
+
|
|
29
|
+
### Permissions
|
|
30
|
+
|
|
31
|
+
The plugin composes OpenCode's built-in permission checks with custom `sketchbook.*` actions, so you can allow or prompt on Sketchbook separately from general file edits:
|
|
32
|
+
|
|
33
|
+
| Action | When it is asserted |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `sketchbook.run` | Every Sketchbook tool call |
|
|
36
|
+
| `sketchbook.mutate` | Operations whose risk is above `read` |
|
|
37
|
+
| `sketchbook.delete` | `delete`-risk operations |
|
|
38
|
+
| `sketchbook.external` | Operations that write outside the project |
|
|
39
|
+
| `sketchbook.install` | Operations that install packages |
|
|
40
|
+
| `sketchbook.upgrade` | Operations that upgrade Sketchbook itself |
|
|
41
|
+
| `sketchbook.privileged` | Privileged operations |
|
|
42
|
+
| `sketchbook.init` | `init`, which may create a directory |
|
|
43
|
+
| `sketchbook.engine` | Running a project-local engine (engine trust) |
|
|
44
|
+
| `edit`, `external_directory` | Composed on top: file mutations also assert `edit`, and targets outside the active location also assert `external_directory` |
|
|
45
|
+
|
|
46
|
+
Risk comes from the selected subcommand first, then the command, then a conservative mutation-based default for older manifests. Sketchbook tools are never a way around OpenCode's own boundaries.
|
|
47
|
+
|
|
48
|
+
## Tool surfaces
|
|
49
|
+
|
|
50
|
+
### Tools
|
|
51
|
+
|
|
52
|
+
The plugin registers a `sketchbook` tool namespace, one tool per capabilities command (interactive-only commands get native TUI/Desktop experiences instead), plus:
|
|
53
|
+
|
|
54
|
+
- `sketchbook capabilities` — return the active engine's full manifest.
|
|
55
|
+
- `sketchbook apply_preview` — apply a stored preview after revalidating it (see below).
|
|
56
|
+
|
|
57
|
+
Mutation tools preview by default and return a preview ID and fingerprint in their metadata.
|
|
58
|
+
|
|
59
|
+
### Typed RPC
|
|
60
|
+
|
|
61
|
+
For programmatic clients, the plugin exposes a typed RPC interface (`SketchbookRpc`) with the methods `capabilities`, `run`, `preview`, `apply`, `cancel`, and `status`, and the events `progress` and `operation`. Errors are typed and coded (`SKETCHBOOK_STALE_PREVIEW`, `SKETCHBOOK_TIMEOUT`, `SKETCHBOOK_PERMISSION_DENIED`, …), so clients never parse message text. Import it from `@usesketchbook/opencode-plugin/rpc`; the TUI routes live in `./tui` and the experimental Desktop UI in `./gui-experimental`.
|
|
62
|
+
|
|
63
|
+
### Skills, commands, and subagents
|
|
64
|
+
|
|
65
|
+
The plugin embeds the shared Sketchbook agent catalog as OpenCode surfaces: skills, `/sketchbook-*` slash commands, and one native subagent per skill agent brief. All of it is generated from the same catalog source the harness renders other client projections from — nothing is copied by hand. Project-owned skills and commands take precedence: the plugin skips any surface name your location already provides.
|
|
66
|
+
|
|
67
|
+
## Previews and stale detection
|
|
68
|
+
|
|
69
|
+
Mutating operations that support `--dry-run` follow a two-step flow:
|
|
70
|
+
|
|
71
|
+
1. **Preview.** The tool runs the operation as a dry run, stores the plan in a preview store keyed by an operation ID, and records a SHA-256 fingerprint of the plan plus the exact operation (root, engine version, command, arguments).
|
|
72
|
+
2. **Apply.** `sketchbook apply_preview` re-runs the same operation as a dry run. Only if the fresh fingerprint matches the stored one does it apply for real.
|
|
73
|
+
|
|
74
|
+
Apply is rejected as stale (`SKETCHBOOK_STALE_PREVIEW`) when the preview is unknown, already applied, made in a different location, made with a different engine version, or when the project changed since the preview was made. Marked-stale previews are never applied; make a new preview instead. One mutation runs at a time per project location, and a preview created in one project cannot be applied in another.
|
|
75
|
+
|
|
76
|
+
## Installation and configuration
|
|
77
|
+
|
|
78
|
+
Install the plugin the way you install any OpenCode V2 npm plugin — add `@usesketchbook/opencode-plugin` to your OpenCode plugins and restart OpenCode. The plugin requires no configuration and never writes your project or global OpenCode config; permissions are managed through OpenCode's own permission settings.
|
|
79
|
+
|
|
80
|
+
To use the project engine, add the CLI to your project:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npm install --save-dev @usesketchbook/cli
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Verify what the plugin sees by calling the `sketchbook capabilities` tool in a session: it returns the manifest of the engine the plugin resolved for your location, engine version included.
|
|
87
|
+
|
|
88
|
+
## Status
|
|
89
|
+
|
|
90
|
+
The CLI's `capabilities` command ships in `@usesketchbook/cli` 0.10.0 and later. The plugin is preparing its first prerelease; see [the release checklist](../../docs/opencode-plugin-release.md) for how the packages ship.
|
|
91
|
+
|
|
92
|
+
## Development
|
|
93
|
+
|
|
94
|
+
From the repository root:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
npm install
|
|
98
|
+
npm run build --workspace @usesketchbook/opencode-plugin
|
|
99
|
+
npm test --workspace @usesketchbook/opencode-plugin
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The plugin is built as an npm workspace under `plugins/opencode`. Unit tests use a temporary CLI stub so they do not depend on the published package or the current checkout.
|
|
103
|
+
|
|
104
|
+
From the repository root, two npm scripts cover the plugin locally (there is no hosted CI; the pre-push hook runs `test:plugin` alongside the other gates):
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
npm run test:plugin # build and test the plugin
|
|
108
|
+
npm run check:plugin # regenerate the baselines from the CLI, fail if they drifted, then build and test
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Sandbox scenarios
|
|
112
|
+
|
|
113
|
+
End-to-end scenarios against the packed npm artifacts live in a separate `sketchbook-test` checkout. They are opt-in and never part of the default checks. With `sketchbook-test` beside this repository:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
npm run sandbox:scenarios
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The command runs `run-scenarios.sh` there and writes its report to that checkout's `reports/`. Point `SKETCHBOOK_SANDBOX` at a different checkout when needed. See [the release checklist](../../docs/opencode-plugin-release.md) for where this step belongs.
|
|
120
|
+
|
|
121
|
+
Two generated files in `src/generated/` must stay in sync with the CLI (`npm run sync --workspace @usesketchbook/opencode-plugin` regenerates both; the `check:plugin` script fails when they drift):
|
|
122
|
+
|
|
123
|
+
- `baseline-manifest.ts` — the tool registry baseline, generated from `sketchbook capabilities --json`.
|
|
124
|
+
- `catalog-baseline.ts` — the skills/commands/subagents baseline, generated from the harness agent catalog.
|