Skip to content

Commit cc7cc87

Browse files
committed
docs: tighten the plugin READMEs
They had accumulated padding: hedging, restated context, and the same explanation repeated per package. Lead with what the reader does, push mechanism below it, and state facts instead of narrating reasoning. Prose only; every code fence is byte-identical. The technical caveats are compressed rather than dropped, since several exist because a review forced the removal of an overclaim. Also corrects a caching claim in the reviewer README: a model ask verdict is cached (source uncertain is in CACHEABLE), while timeout, error and parse failures are retried.
1 parent 3af4ce1 commit cc7cc87

4 files changed

Lines changed: 123 additions & 151 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ opencode plugin add @joonix/opencode-commands
1919
opencode plugin list
2020
```
2121

22-
Append `@<version>` to pin a release. The package README files cover configuration and behavior.
23-
24-
Git specifications do not work for this repository: OpenCode's installer ignores npm's `::path:`
25-
subdirectory selector and installs the repository root, which is not a plugin package.
22+
Append `@<version>` to pin a release; each package README covers configuration and behavior. Git
23+
specifications do not work here: OpenCode's installer ignores npm's `::path:` subdirectory selector
24+
and installs the repository root, which is not a plugin package.
2625

2726
## Update
2827

@@ -37,8 +36,9 @@ unaffected by it.
3736

3837
## Local development
3938

40-
Requires Bun 1.2.22 or newer and OpenCode 2.0.4 or newer. Clone the repository and configure any
41-
package by its directory path:
39+
Requires Bun 1.2.22 or newer and OpenCode 2.0.4 or newer. Configure a package by its directory path,
40+
which shadows the published package. Use directory entries for every package you develop locally;
41+
mixing one with an npm entry runs two versions of this repository side by side.
4242

4343
```jsonc
4444
{
@@ -50,18 +50,12 @@ package by its directory path:
5050
}
5151
```
5252

53-
A directory entry shadows the published package, so use it for every package you develop locally:
54-
mixing a local checkout with an npm entry runs two different versions of this repository side by
55-
side.
56-
5753
```sh
5854
bun install --frozen-lockfile
5955
make test
6056
make test-load
6157
```
6258

63-
`make test-load` requires an installed `opencode2` executable and uses disposable configuration and
64-
data directories.
65-
66-
Maintainers publish with `make publish`, which runs the suite first. Bump each package `version`
67-
beforehand; a version already on the registry fails the publish.
59+
`make test-load` needs an installed `opencode2` executable and uses disposable configuration and data
60+
directories. Maintainers publish with `make publish`, which runs the suite first; bump each package
61+
`version` beforehand, since a version already on the registry fails the publish.

‎packages/commands/README.md‎

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
# opencode-commands
22

3-
An OpenCode V2 plugin for overriding and adding terminal slash commands. It currently ships one
4-
command: a `/clear` that empties the current session in place instead of starting a new one.
3+
An OpenCode V2 plugin that overrides and adds terminal slash commands. It ships one: a `/clear` that
4+
empties the current session in place instead of starting a new one.
55

66
Requires OpenCode V2 (verified against 2.0.4) and Bun.
77

88
## What it does
99

10-
- **`/clear` clears the session you are in.** It deletes every message in the session and leaves you
11-
in the same session: same session id, same title, same tab. You can keep prompting immediately.
12-
- **`/new` is untouched.** OpenCode ships `/clear` as an alias of its `session.new` command, so the
13-
built-in `/clear` starts a fresh session and leaves the old transcript behind. This plugin takes
14-
over that alias only. `/new`, its command-palette entry, and `<leader>n` all still run OpenCode's
15-
own new-session code.
16-
- **Your files are left alone.** Clearing removes the conversation, not your work. Edits the agent
17-
made to your working tree stay as they are. See the limitation below for the one case where
18-
another client can still move files underneath it.
19-
20-
Queued prompts and the session's instruction state are cleared along with the messages, because the
21-
server drops them at the same boundary.
10+
- **`/clear` clears the session you are in.** Every message is deleted and you stay put: same
11+
session id, title and tab, ready for the next prompt. Queued prompts and instruction state go with
12+
the messages; the server drops them at the same boundary.
13+
- **Your files are left alone.** The agent's edits to your working tree survive, except in the
14+
shared-session case below.
15+
- **`/new` is untouched.** OpenCode ships `/clear` as an alias of `session.new`; the plugin takes
16+
over that alias only. `/new`, its command-palette entry, and `<leader>n` still run OpenCode's own
17+
new-session code.
2218

2319
## Install
2420

2521
```sh
2622
opencode plugin add @joonix/opencode-commands
2723
```
2824

29-
The CLI adds the plugin to your global OpenCode configuration. Append `@<version>` to pin a release.
30-
The plugin takes no options. It registers `joonix.commands` on the server and `joonix.commands.tui`
31-
in the terminal, which is what a `plugins` disable selector such as `-joonix.commands.tui` or
32-
`-joonix.*` matches.
25+
Append `@<version>` to pin a release. The plugin takes no options. It registers `joonix.commands` on
26+
the server and `joonix.commands.tui` in the terminal, the ids matched by a `plugins` disable
27+
selector such as `-joonix.commands.tui` or `-joonix.*`.
3328

34-
Plugin list changes can take effect one service generation later: after editing the config, restart
35-
the background service (`opencode service restart`) and expect the new set on the following start.
29+
Plugin list changes can take effect one service generation later: restart the background service
30+
(`opencode service restart`) and expect the new set on the following start.
3631

3732
## Update
3833

@@ -41,51 +36,43 @@ opencode plugin check # report package plugins that have a newer release
4136
opencode plugin update # update package plugins to their latest release
4237
```
4338

44-
`update` applies to package entries. A pinned `@<version>` entry stays pinned, and a directory entry
45-
tracks the checkout rather than the registry, so neither is changed by it. The running service picks
46-
up the new version on its own; restart it only if the change does not appear.
39+
Pinned `@<version>` entries and directory entries are left alone. The running service picks up the
40+
new version on its own; restart it only if the change does not appear.
4741

4842
## How the override works
4943

5044
OpenCode has no delete-message API. Committing a revert staged at the session's first message is the
51-
supported equivalent: the server deletes every message and queued inbox item at or after that
52-
boundary and resets instruction state, then the TUI prunes its own copy from the same event.
53-
54-
Three details make that safe rather than merely working:
55-
56-
- **`files: false` when staging.** Otherwise the host restores file snapshots from the boundary and
57-
clearing the transcript would revert the agent's edits along with it.
58-
- **A revert that is already staged gets committed first.** Staging restores a pending revert's files
59-
from its original snapshot regardless of `files: false`, so staging on top of a pending `/undo`
60-
would discard anything edited since. Committing it keeps the working tree as it currently looks,
61-
and the messages it excluded are ones the clear is about to delete anyway.
45+
supported equivalent: the server deletes every message and queued inbox item from that boundary on
46+
and resets instruction state, and the TUI prunes its copy from the same event. Four details make
47+
that safe:
48+
49+
- **Staged with `files: false`.** That is what keeps the working tree out of it; otherwise the host
50+
restores file snapshots from the boundary and reverts the agent's edits with the transcript.
51+
- **An already staged revert is committed first.** Staging restores a pending revert's files from its
52+
original snapshot regardless of `files: false`, so staging over a pending `/undo` would discard
53+
anything edited since. Committing leaves the working tree as it is and drops only messages the
54+
clear deletes anyway.
6255
- **The boundary comes from the server, not the TUI store.** That store holds only the newest page of
63-
messages, so its first entry is not the session's first message. The plugin asks for the oldest
64-
message explicitly; using the store would silently leave everything older in place.
65-
66-
If the commit fails after staging succeeded, the plugin cancels the staged revert. A revert left
67-
staged is committed automatically when the next prompt is submitted, which would delete the
68-
transcript later without being asked again. It only cancels a revert that is still its own, so a
69-
failure cannot discard work another client staged in the meantime.
56+
messages, so using it would silently leave everything older in place.
57+
- **A failed commit cancels its own staged revert.** A revert left staged is committed on the next
58+
prompt, deleting the transcript unasked; only the plugin's own revert is cancelled.
7059

71-
## Limitation: a shared session
60+
Slash completion is keyed by command id, not by slash name, so a second command named `clear` would
61+
list two `/clear` entries. The plugin instead redeclares the host's `session.new` in a
62+
higher-priority layer without the `clear` alias and returns `false`, which rejects that entry so
63+
dispatch falls through to OpenCode's real handler and `/new` keeps working.
7264

73-
A session can have several clients attached, and OpenCode has no atomic stage-and-commit for
74-
reverts. Between staging and committing, another client can replace the staged revert. The plugin
75-
checks that the staged revert is still the one it asked for and refuses to commit if it is not, so
76-
it will not apply somebody else's boundary or clear only part of a transcript.
65+
### Limitation: a shared session
7766

78-
The one case it cannot defend against is a revert staged by another client in the moment between
79-
this plugin reading the session and staging its own: OpenCode restores that revert's recorded files
80-
as part of staging, regardless of `files: false`. This window is inherent to the revert API and
81-
affects the built-in `/undo` the same way. In practice it requires two clients acting on one session
82-
at the same instant.
67+
Several clients can attach to one session, and OpenCode has no atomic stage-and-commit for reverts.
68+
Between staging and committing, another client can replace the staged revert; the plugin verifies
69+
the staged revert is still its own and refuses to commit otherwise, so it never applies somebody
70+
else's boundary, clears part of a transcript, or discards work another client staged.
8371

84-
Taking over the `/clear` name needs one extra step. Slash completion is keyed by command id rather
85-
than by slash name, so registering a second command named `clear` would simply list two `/clear`
86-
entries. Instead the plugin redeclares the host's `session.new` in a higher-priority layer, omitting
87-
the `clear` alias, and returns `false` from it. Returning `false` rejects that entry, so dispatch
88-
continues down the chain to OpenCode's real handler and `/new` keeps working normally.
72+
The undefended window is a revert another client stages between the plugin reading the session and
73+
staging its own: OpenCode restores that revert's recorded files as part of staging, regardless of
74+
`files: false`. That window is inherent to the revert API, affects the built-in `/undo` equally, and
75+
needs two clients acting on one session at the same instant.
8976

9077
## Develop
9178

@@ -94,10 +81,9 @@ make test # tsc --noEmit and bun test
9481
make test-load # loads the plugin in a throwaway OpenCode config and asserts it loaded
9582
```
9683

97-
Entry resolution depends on how the plugin is configured. A package entry such as
98-
`@joonix/opencode-commands` resolves through the `exports` map to `src/index.ts` and `src/tui.tsx`. A
99-
directory entry, used when developing against a local checkout, resolves `<dir>` instead, so the
100-
`index.ts` and `tui.tsx` files at the package root re-export `src/` to keep that path working.
84+
`make test` covers the clear sequence against a fake client. The command wiring (which slash names
85+
appear, and that `/new` still falls through) is only exercised by running the TUI.
10186

102-
`make test` covers the clear sequence against a fake client. The command wiring itself (which slash
103-
names appear, and that `/new` still falls through) is only exercised by running the TUI.
87+
A package entry such as `@joonix/opencode-commands` resolves through the `exports` map to
88+
`src/index.ts` and `src/tui.tsx`; a directory entry resolves `<dir>`, so the `index.ts` and
89+
`tui.tsx` files at the package root re-export `src/` to keep that path working.

0 commit comments

Comments
 (0)