fixate-on 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joseph Cumines
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,397 @@
1
- # Temporary Holding Version
1
+ # fixate-on
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A session-scoped goal-tracking plugin for [OpenCode](https://opencode.ai/). Run `/goal <objective>` in plain language (no flags required) to keep an objective in context, automatically continue the session when the assistant goes idle, check completion claims with a judge before settling, and stop when a brake is reached.
4
+
5
+ Completion claims require an attestation from a verifier (by default, a read-only judge subagent). Rejected claims trigger bounded recovery continuations listing the remaining issues, and operational verifier errors are recorded as faults and retried with backoff. Mechanical brakes (turn, stall, token, no-progress, no-tool-call, and prompt-failure limits) stop continuations without marking the goal complete or blocked.
6
+
7
+ Supports OpenCode 1.x (`opencode`) and OpenCode 2.x (`opencode2`). See [Compatibility](#compatibility) for runtime and experimental-hook requirements.
8
+
9
+ ## Installation
10
+
11
+ On OpenCode 1.x (`opencode`), register `fixate-on` in `opencode.json`:
12
+
13
+ ```json
14
+ {
15
+ "plugin": ["fixate-on"]
16
+ }
17
+ ```
18
+
19
+ On OpenCode 2.x (`opencode2`), run:
20
+
21
+ ```sh
22
+ opencode2 plugin add fixate-on
23
+ ```
24
+
25
+ That writes `"plugins": ["fixate-on"]` to your global `opencode.json`, and also loads the TUI companion. Either way, the plugin registers the `/goal` command, the `goal` agent, and the read-only `goal-verify` subagent automatically. On 1.x the [TUI companion](#tui-companion) is one further, optional entry.
26
+
27
+ ### OpenCode 1.x vs 2.x
28
+
29
+ One `fixate-on` package supports both OpenCode 1.x (`opencode`) and OpenCode 2.x (`opencode2`), with these config differences:
30
+
31
+ | Setting | OpenCode 1.x (`opencode`) | OpenCode 2.x (`opencode2`) |
32
+ |:---|:---|:---|
33
+ | Server plugin key | `plugin` (string or `[spec, options]`) | `plugins` (string or `{ "package", "options" }`) |
34
+ | Local checkout target | File path to the built bundle (`.../plugin/fixate-on/plugin.js`) | The repository directory (file paths fail with `configured plugin path must be a directory`) |
35
+ | `/goal` command | Auto-registered and intercepted via `command.execute.before` | Registered via `command.transform` (overrides built-in `opencode.goal`); explicit `command.goal` is the fallback for older builds |
36
+ | Agents (`goal`, `goal-verify`) | Registered by the `config` hook | Registered by `agent.transform` |
37
+ | TUI companion | `tui.json` `plugin` array (`fixate-on`) | Loaded automatically with the server plugin |
38
+ | Permission key (shared config) | `permission` (map) | `permissions` (also accepts 1.x `permission`) |
39
+
40
+ If you share one `opencode.json` across both versions, keep the 1.x singular keys (`plugin` and `permission`). OpenCode 2.x accepts and migrates them, whereas checked 1.18.x releases silently drop `plugins` and `permissions`.
41
+
42
+ ### `/goal` on OpenCode 2.x
43
+
44
+ OpenCode 2.x does not expose `command.execute.before`. Instead, the plugin registers `/goal` through `command.transform` (overriding the built-in `opencode.goal`), so `/goal` works without extra command configuration on current 2.x builds.
45
+
46
+ On older 2.x builds where `command.transform` is unavailable, add `command.goal` to `opencode.json` to route arguments through the `goal-command` tool:
47
+
48
+ ```json
49
+ {
50
+ "command": {
51
+ "goal": {
52
+ "description": "Run a goal loop for the objective",
53
+ "template": "Call the goal-command tool exactly once with its subcommand parameter set verbatim to: $ARGUMENTS\nDo not summarize, do not ask for confirmation, and do not perform any other work. Reply with only the tool output.",
54
+ "agent": "build"
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ On OpenCode 1.x this template is unnecessary because `command.execute.before` intercepts `/goal` first, though keeping it in a shared config is harmless.
61
+
62
+ On 2.x, reporting commands and lifecycle receipts use the host's passive event channel so they do not enter the model inbox or start a turn, including while the model is busy. The 2.x TUI companion displays receipts in a dialog for the current session and as session-scoped toasts for other sessions or notices (see [passive command receipts](docs/tui-integration.md#passive-command-receipts-on-2x)). Older hosts without passive RPC require a configured `goalMessenger` option, or the command returns an output-delivery error containing its result. Calls through the `goal-command` tool return output through the standard tool channel.
63
+
64
+ ### TUI companion
65
+
66
+ The optional TUI companion adds an interactive dashboard, command palette actions (`ctrl+p` → `fixate:`), keyboard shortcuts, and lifecycle toasts.
67
+
68
+ On OpenCode 2.x the companion loads automatically with the server plugin; nothing else needs configuring. The host does not pass the server entry's options to the companion, so the companion asks the server plugin which state directory it uses. Add an entry to `cli.json` (`~/.config/opencode/cli.json`) in two cases only: to set companion options such as `logLevel`, or when the TUI connects to a server on another machine or with a different package cache. The host does not install a server's plugins for the TUI in that second case:
69
+
70
+ ```json
71
+ {
72
+ "plugins": [
73
+ { "package": "fixate-on", "options": { "logLevel": "info" } }
74
+ ]
75
+ }
76
+ ```
77
+
78
+ On OpenCode 1.x, add the same package name to `tui.json` (`~/.config/opencode/tui.json` or `$OPENCODE_TUI_CONFIG`), separate from `opencode.json`:
79
+
80
+ ```json
81
+ {
82
+ "plugin": [
83
+ ["fixate-on", { "logLevel": "info" }]
84
+ ]
85
+ }
86
+ ```
87
+
88
+ Use the bare package name in both files. Both hosts parse a subpath such as `fixate-on/tui` as GitHub shorthand and try to clone a repository.
89
+
90
+ If you change the persisted state directory, see [Persistence and state root](#persistence-and-state-root). See [`docs/tui-integration.md`](docs/tui-integration.md) for dashboard usage and keyboard shortcuts.
91
+
92
+ ### Local source
93
+
94
+ Build the bundles first with `bun run bundle` (`plugin/fixate-on/` is generated, gitignored output; keep test files out of OpenCode's auto-loaded plugin directory).
95
+
96
+ On OpenCode 1.x, point `plugin` in `opencode.json` at the built server bundle, and `plugin` in `tui.json` at `tui.js` beside it:
97
+
98
+ ```json
99
+ {
100
+ "plugin": ["file:///absolute/path/to/fixate-on/plugin/fixate-on/plugin.js"]
101
+ }
102
+ ```
103
+
104
+ On OpenCode 2.x (2.2.0 and later), point `plugins` in `opencode.json` at the repository directory. The host resolves the server and companion through `package.json`, as it does for an npm install:
105
+
106
+ ```json
107
+ {
108
+ "plugins": [
109
+ {
110
+ "package": "file:///absolute/path/to/fixate-on",
111
+ "options": {}
112
+ }
113
+ ]
114
+ }
115
+ ```
116
+
117
+ Earlier 2.x builds ignore `exports` in a local directory. There, use a directory with a `server.js` that re-exports `plugin/fixate-on/plugin.js` and a `tui.js` that re-exports `plugin/fixate-on/tui.js`.
118
+
119
+ ## Examples
120
+
121
+ Start with a plain-language objective and add flags only when you want explicit overrides:
122
+
123
+ ```sh
124
+ # Plain-language goal using default brakes
125
+ /goal fix the failing tests and confirm the suite passes
126
+
127
+ # Override turn, stall-duration, and context-token brakes
128
+ /goal "migrate class components to functional" --max-turns=20 --max-minutes 60 --budget 400k
129
+
130
+ # Add success criteria, constraints, and a live file pointer
131
+ /goal "ship the release" --success "tests pass, changelog updated" --constraints "do not modify the public API" --pointer SPEC.md
132
+
133
+ # Queue an ordered multi-goal pipeline
134
+ /goal sequence build the parser; write unit tests; update docs
135
+ ```
136
+
137
+ Inspect or manage goals while a session is running:
138
+
139
+ ```sh
140
+ /goal status # State summary, remaining brakes, and next step
141
+ /goal status --full # Usage breakdown, recovery counters, and recorded claims
142
+ /goal pause # Pause the focused goal
143
+ /goal resume # Resume with a fresh per-run limit window
144
+ /goal handback # Scoped diff, known risks, recorded claims, and review payload
145
+ ```
146
+
147
+ ## `/goal` Command Reference
148
+
149
+ Plain language is the primary interface (`/goal <objective>` works without flags). Subcommands and per-goal flags provide lifecycle control and optional overrides.
150
+
151
+ ### Subcommands
152
+
153
+ | Command | Behavior |
154
+ |:---|:---|
155
+ | `/goal <objective> [flags]` | Sets or replaces the focused goal in the current session. |
156
+ | `/goal add <objective> [flags]` | Creates and focuses a new goal while leaving existing unfinished goals active. |
157
+ | `/goal sequence <obj1>; <obj2>` | Queues multiple objectives (separated by `;` or newlines) as an ordered pipeline. Focuses the first and keeps successors paused (`queued`) until auto-promoted when the active goal settles as `complete`. |
158
+ | `/goal status [--full \| --verbose]` | Shows a plain-language state summary, remaining brakes, and next step. `--full` or `--verbose` adds the usage breakdown, recovery counters, and recorded claims. Alias: `info`. |
159
+ | `/goal list [all]` | Lists numbered live goals and settled goals in the per-session archive, with state markers (`focused` = driven now, `idle` = active between turns, `background` = waiting). Alias: `ls`. |
160
+ | `/goal focus <number \| goalId>` | Switches which goal bare commands and the TUI target. Persisted on disk without altering goal status; unfocused active goals keep running. |
161
+ | `/goal pause [<goalId>]` | Pauses the focused or named goal while retaining its state and history. |
162
+ | `/goal resume [<goalId>]` | Resumes a paused, blocked, or brake-stopped goal, resets the turn count, and starts a fresh window for configured per-run limits while preserving the objective and history. |
163
+ | `/goal edit <new objective>` | Revises the focused goal's objective in place, preserving limits and history and clearing paused or blocked state. If a hard brake already triggered, run `/goal resume` to reset limits. |
164
+ | `/goal checkpoint <note>` | Records a progress note on the focused goal. |
165
+ | `/goal history [--verbose \| --full]` | Displays the lifecycle event trail and latest progress note. `--verbose` and `--full` include bookkeeping entries. Alias: `log`. |
166
+ | `/goal accept [proposalId]` | Applies the focused goal's pending proposal from `propose_goal_change` (objective, success criteria, constraints, and artifact pointers) and clears it. If `proposalId` is supplied, it must match. Alias: `accept-proposal`. |
167
+ | `/goal reject [proposalId]` | Discards the focused goal's pending proposal without changing the goal. If `proposalId` is supplied, it must match. Alias: `reject-proposal`. |
168
+ | `/goal handback` | Returns the handback deliverable for the focused goal: scoped reviewable diff (files, stat, patch), known risks, recorded claims, and external review payload. |
169
+ | `/goal review` | Returns only the external review payload from the focused goal's handback deliverable. Alias: `review-payload`. |
170
+ | `/goal clear [<goalId>]` | Removes live goal state and saved status. Clears immediately when one live goal exists; when multiple live goals exist, requires `<goalId>` (or a unique prefix). Aliases: `stop`, `off`, `reset`, `none`, `cancel`. |
171
+
172
+ Commands that accept `<goalId>` (`pause`, `resume`, `focus`, `clear`) match a full ID or a unique prefix. Ambiguous prefixes return an error.
173
+
174
+ ### Per-goal flags
175
+
176
+ Flags accept `--flag value` or `--flag=value`. Quote multi-word values. Unknown flags, missing values, non-positive integers, or invalid `--mode` values fail with an explicit error instead of being folded into the objective.
177
+
178
+ | Flag | Description |
179
+ |:---|:---|
180
+ | `--success <text>` | Success criteria injected alongside the objective. Alias: `--success-criteria`. |
181
+ | `--constraints <text>` | Constraints or non-goals to respect. Alias: `--non-goals`. |
182
+ | `--pointer <file>` | Artifact pointer; injects live file content into every continuation without editing the goal text. Repeatable and comma-separated. Aliases: `--pointers`, `--artifact-pointer`, `--artifact-pointers`. |
183
+ | `--mode <normal\|ordered>` | Prompt mode for a single goal (`default: normal`; `ordered` preserves step order within the objective). |
184
+ | `--max-turns <n>` | Continuation turn ceiling (cannot be raised by agent tools). |
185
+ | `--max-minutes <n>` | Stall brake in minutes (time without progress). |
186
+ | `--max-duration-ms <n>` | Stall brake in milliseconds (time without progress). |
187
+ | `--max-tokens <n>` | Cumulative context-token ceiling (cannot be raised by agent tools). |
188
+ | `--budget <n>` | Shorthand for `--max-tokens`; accepts `k` and `m` suffixes (for example, `100k`, `1.5m`). |
189
+ | `--token-budget <n>` | Advisory API-cost token budget (`k` and `m` suffixes supported; `null` = unbounded). Triggers a one-time advisory warning when crossed. |
190
+ | `--cooldown-ms <n>` | Minimum delay between continuations in milliseconds (`0` = no delay). |
191
+ | `--no-progress-threshold <n>` | Output-token floor for a stalled turn (`0` = disable no-progress heuristic). |
192
+ | `--no-progress-turns <n>` | Consecutive stalled low-output turns before pausing (`0` = pause on first). |
193
+ | `--no-tool-turns <n>` | Consecutive tool-free continuation turns before pausing (`0` = disabled). |
194
+ | `--max-recovery-turns <n>` | Total bounded recovery turns before pausing with `recovery exhausted` (`default: 12`). |
195
+ | `--max-unchanged-results <n>` | Consecutive unchanged verifier results before pausing with `recovery exhausted` (`default: 3`). |
196
+ | `--max-blocked-turns <n>` | Consecutive `update_goal {status: "blocked"}` calls required before `blocked` is accepted (`default: 3`). |
197
+ | `--verbose` | Renders verbose command output (alias for `--full` on `/goal status`). |
198
+
199
+ ## How It Works
200
+
201
+ ### Sessions, concurrent goals, and forks
202
+
203
+ Goals are **session-scoped**: each goal belongs to one session and is stored in that session's state file. Sharing a single goal across two sessions is rejected.
204
+
205
+ A session can hold multiple goals at once, and every unfinished goal in the session is driven on session idle, including unfocused goals. `/goal <objective>` replaces the focused goal, `/goal add <objective>` adds and focuses a new goal while keeping prior goals active, and `/goal focus <number | goalId>` changes which goal bare commands and the TUI target. In an ordered pipeline created with `/goal sequence`, only the first goal runs; queued successors stay paused until the active goal settles as `complete`, at which point the next queued goal is promoted and focused automatically.
206
+
207
+ When a session is forked, live goals are copied into the fork with new `goalId` values while the parent session keeps its own goals. Copies preserve the objective, success criteria, constraints, artifact pointers, mode, and brake settings; turn counts, token usage, recovery and fault counters, blocked streaks, claims, and pending intents start empty. Settled goals (`complete`, `budgetLimited`) are not copied. On OpenCode 2.x, a durable `session.forked` event carries `parentID` and the fork boundary, triggering the copy automatically. On OpenCode 1.x, forks are created as unrelated top-level sessions without a `parentID`; because the plugin does not guess ancestry from session titles, 1.x forks start without copied goals.
208
+
209
+ If the host cannot read a session (for example, after deletion), failed reads never trigger continuations. After `maxPromptFailures` consecutive failures, the goal pauses with a receipt (`session not found` or `auto-continue failures`).
210
+
211
+ ### Continuation loop and user intervention
212
+
213
+ Active goals are injected into the primary system prompt as user-provided task data, separate from system, developer, tool, and repository policies. When a goal is paused, the plugin omits the objective from the system prompt and requires an explicit `/goal resume`.
214
+
215
+ When the session goes idle, the plugin waits `minDelayMs` and checks that the session is still idle and that no human message, newer assistant turn, Plan-agent switch, rejected permission, abort, or provider error intervened. Continuations preserve the initiating turn's agent, provider/model, and variant. If OpenCode reports itself busy, the plugin defers the continuation without consuming turn budget and retries on the next idle, bounded by `maxPromptFailures`.
216
+
217
+ Sending an ordinary message while a goal is active yields the turn to you. The goal stays **active**, with its objective in the system prompt. The plugin cancels pending continuations and invalidates outstanding completion decisions; OpenCode handles steering the running turn. The loop continues automatically on the next idle after the host has answered your latest message. Direct replies restart the consecutive no-progress and no-tool-call streaks without resetting accumulated turns or token usage.
218
+
219
+ - Whole-message stop imperatives (`"stop"`, `"pause"`, `"hold off"`, matched conservatively so mixed instructions like `"stop the server then fix tests"` remain normal steering) pause with `explicit pause` and require `/goal resume`. An explicit stop also requests host interruption when a plugin prompt is in flight.
220
+
221
+ Messages queued by the host also leave the goal active. The plugin records a notice and history entry, and continues the loop once the turn settles.
222
+
223
+ > A goal persisted as `paused` with the legacy `user intervention` stop reason — from an older plugin version whose message handling paused goals — is not resumed automatically. Run `/goal resume` to continue it.
224
+
225
+ When OpenCode compacts a session, the plugin injects a summary reconstructed from persisted goal state (objective, status, budget usage, recent progress notes, and lifecycle trail) so the goal survives compaction. Because session context is shared, token usage accrues to every unfinished goal in the session.
226
+
227
+ When a brake is reached, the plugin sends one final wrap-up prompt asking the assistant to summarize what is done, what remains, and the next concrete step. The prompt instructs the assistant to call `update_goal {status: "complete"}` only if the objective is satisfied, and to avoid marking the goal `blocked` solely because a brake fired. Run `/goal resume` to continue with a fresh window for configured per-run limits.
228
+
229
+ ### Completion verification
230
+
231
+ The working agent runs workspace checks with its own tools. The plugin does not execute shell commands, Makefile targets, or test suites as verifiers. Every `update_goal {status: "complete"}` claim is evaluated by a judge. On OpenCode 2.x, when an active session stops naturally without calling `update_goal`, warm-cache idle triage (`languageTriage`, enabled by default) checks whether the final reply claims completion or a blocker and hands those claims to the same judge rather than pausing or settling directly.
232
+
233
+ The completion gate selects one verifier in this order:
234
+
235
+ 1. Custom `judge` callback: if configured (`async ({ goal, sessionID, latestText }) => ({ approved, reason })`), it takes precedence over the built-in judge.
236
+ 2. Built-in child-session judge (`childSessionJudge` enabled by default): spawns an isolated session running the hidden `goal-verify` subagent bound to the workspace directory, restricted to `read`, `glob`, and `grep` (`bash`, `edit`, and `write` are denied). On OpenCode 2.x, when session deletion is available, the verifier runs in a detached archived session that inherits the parent session's model (unless `goal-verify` configures its own), avoids `<background-result>` wakeups in the parent, and deletes itself on exit.
237
+ 3. No judge (`childSessionJudge: false` and no custom `judge`): after bounded attempts, the goal settles as unattested with stop reason `completed (no attestation could be obtained)` so queued sequence goals behind it can proceed.
238
+
239
+ Verdicts and faults update goal state as follows:
240
+
241
+ - `COMPLETE`: settles and archives the goal as `complete`.
242
+ - `WORKING`: drives bounded recovery continuations citing the failed evidence and remaining requirements. If cited evidence is later shown to be wrong, the plugin records a visible retraction.
243
+ - `BLOCKED` or `NEEDS_INPUT`: pauses the goal for user input with the judge's findings.
244
+ - `CANCELLED`: settles the goal as an authorized cancellation.
245
+ - Attestation fault (provider error, timeout, or missing child-session ID): recorded as a fault and retried with backoff as a forced continuation; it does not settle or reject the goal.
246
+
247
+ Recovery is bounded by both `--max-recovery-turns` (default `12`) and `--max-unchanged-results` (default `3`, counting consecutive unchanged verifier results for the same workspace state). New workspace changes reset the consecutive-unchanged counter while still counting toward the total recovery budget. Exhausting either bound pauses the goal with stop reason `recovery exhausted` and never synthesizes `COMPLETE`.
248
+
249
+ See [Plugin options](#plugin-options) to configure `childSessionJudge`, `judge`, and `judgeOptions`.
250
+
251
+ ### Agent tools and goal statuses
252
+
253
+ Completion and blocking use structured agent tools (`registerTools: true`). If `registerTools` is `false`, active goals pause with a visible notice instead of continuing without tools.
254
+
255
+ | Tool | Arguments | Behavior |
256
+ |:---|:---|:---|
257
+ | `get_goal` | _(none)_ | Returns the focused goal, remaining token and completion-budget details, or `null` if no goal is focused. |
258
+ | `create_goal` | `objective` (string), `token_budget` (optional positive integer) | Creates an active goal (`token_budget` sets the advisory API-cost ceiling; `null` = unbounded). Fails if an unfinished goal already exists in the session; terminal goals do not block creation. |
259
+ | `update_goal` | `status` (`"complete"` \| `"blocked"`) | Transitions the focused goal. Accepts only `status`. |
260
+ | `list_goals` | _(none)_ | Lists all goals in the current session. |
261
+ | `focus_goal` | `goal_id` (string) | Changes the focused goal in the current session. |
262
+ | `propose_goal_change` | proposal fields | Records a pending proposal for user review via `/goal accept` or `/goal reject`. Agents cannot raise turn or token ceilings directly. |
263
+ | `goal-command` | `subcommand` (string) | *(OpenCode 2.x)* Routes `/goal` invocations into plugin state when wired through `command.goal`. |
264
+
265
+ Goal statuses are `active`, `paused`, `blocked`, `budgetLimited`, and `complete`:
266
+
267
+ - `complete` and `budgetLimited` are terminal. A `budgetLimited` goal cannot be resumed, paused, or moved to `blocked`, and does not block `create_goal`.
268
+ - Calling `update_goal {status: "complete"}` records a pending completion claim that the completion gate evaluates after the current step finishes.
269
+ - Calling `update_goal {status: "blocked"}` captures the blocker reason from the assistant's latest turn text and rejects the transition until the same blocker recurs `maxBlockedTurns` consecutive times (default `3`, configurable via `--max-blocked-turns`). The streak persists across idle turns when re-asserted and resets on `/goal resume` or any non-blocked turn.
270
+
271
+ ## Configuration & Persistence
272
+
273
+ ### Persistence and state root
274
+
275
+ By default (`persistState: true`), each session persists its goals to `.opencode/goals/sessions/<sessionID>/state.json` and a lifecycle ledger to `state.json.ledger.jsonl` (mode `0600` inside an owner-only directory). Add `.opencode/goals/` to `.gitignore`.
276
+
277
+ State root resolution follows this precedence order:
278
+
279
+ 1. `stateRoot` plugin option
280
+ 2. `FIXATE_ON_STATE_ROOT` environment variable
281
+ 3. `<cwd>/.opencode/goals`
282
+
283
+ On OpenCode 2.x the companion asks the server plugin for its resolved state root, so `stateRoot` needs setting only on the server entry in `opencode.json`. A `stateRoot` on the companion's own `cli.json` entry overrides that answer. If the server plugin does not answer, the companion falls back to `FIXATE_ON_STATE_ROOT`, then the default. On OpenCode 1.x the two entries resolve the root independently: pass the identical `stateRoot` to both, or set `FIXATE_ON_STATE_ROOT`.
284
+
285
+ Active goals loaded from disk after a restart open in a `paused` state with a recovery note so unattended continuations do not resume automatically.
286
+
287
+ Because each session persists to its own file, multiple OpenCode processes can share one worktree without locking each other out. If another live process already holds a session's write lease, the plugin still loads with all tools enabled and skips writing that session's state file.
288
+
289
+ ### Plugin options
290
+
291
+ Example option overrides in `opencode.json` (on OpenCode 2.x, pass them under `plugins: [{ "package": ..., "options": { ... } }]`):
292
+
293
+ ```json
294
+ {
295
+ "plugin": [
296
+ [
297
+ "fixate-on",
298
+ {
299
+ "maxTurns": 20,
300
+ "maxTokens": 400000
301
+ }
302
+ ]
303
+ ]
304
+ }
305
+ ```
306
+
307
+ When `maxTurns` or `maxTokens` is `0`, the limit is disabled and renders as `unlimited`.
308
+
309
+ | Option | Default | Description |
310
+ |:---|:---|:---|
311
+ | `maxTurns` | `0` | Continuation turn ceiling (`0` = unlimited). |
312
+ | `maxDurationMs` | `1800000` | Stall brake in ms (30 minutes): time since last progress (completed assistant turn or output-token increase, measured from goal creation before first progress). |
313
+ | `maxTokens` | `0` | Cumulative provider-reported context-token ceiling (`input + output + reasoning + cache read + cache write`; `0` = unlimited). |
314
+ | `minDelayMs` | `1500` | Minimum delay in ms before sending a continuation after idle. |
315
+ | `maxRecentMessages` | `50` | Number of recent session messages scanned to locate the latest assistant turn before continuing. |
316
+ | `noProgressTokenThreshold` | `50` | Output-token floor for treating a turn as stalled. |
317
+ | `noProgressTurnsBeforePause` | `3` | Consecutive stalled low-output turns (with no meaningful progress-note change) before pausing. |
318
+ | `noToolCallTurnsBeforePause` | `3` | Consecutive tool-free continuation turns before pausing. Set to `0` for prose-only workflows. |
319
+ | `budgetWrapupRatio` | `0.8` | Fraction of a positive `maxTokens` ceiling at which to send a wrap-up warning (disabled when `maxTokens` is `0`). |
320
+ | `maxPromptFailures` | `3` | Consecutive prompt dispatch failures, deferrals, or host state read failures before pausing. |
321
+ | `kickoffDelayMs` | `2500` | Delay in ms before the one-shot OpenCode 1.x kickoff probe fires after `/goal` activates a goal. |
322
+ | `warnTurnsRemaining` | `3` | Remaining turns threshold for appending a low-limit warning to continuation prompts. |
323
+ | `warnDurationMsRemaining` | `60000` | Remaining stall-brake ms threshold for appending a low-limit warning. |
324
+ | `warnTokensRemaining` | `25000` | Remaining context-token threshold for appending a low-limit warning. |
325
+ | `childSessionJudge` | `true` | Enables the built-in read-only `goal-verify` child-session judge. |
326
+ | `judge` | _(none)_ | Custom callback `async ({ goal, sessionID, latestText }) => ({ approved, reason })` that takes precedence over `childSessionJudge`. |
327
+ | `judgeOptions.timeoutMs` | `1800000` | Maximum wait in ms (30 minutes) for the built-in judge. Set to `0` to disable the plugin timer (host and provider timeouts still apply). On timeout, the child session is aborted and deleted and an attestation fault is recorded. |
328
+ | `judgeOptions.failurePolicy` | `"reject"` | Fault handling for the built-in judge. `"reject"` fails closed on attestation faults; `"approve"` synthesizes a `WORKING` verdict (never `COMPLETE`) so bounded recovery continues. Ignored when a custom `judge` is set. |
329
+ | `persistState` | `true` | Persists session goals and ledgers to disk. |
330
+ | `stateRoot` | `".opencode/goals"` | Directory for persisted goal state (see [Persistence and state root](#persistence-and-state-root)). |
331
+ | `ledgerMaxBytes` | `2 MiB` | Size limit for each per-session `.ledger.jsonl` file before rotation. |
332
+ | `ledgerRetentionFiles` | `3` | Rotated `.ledger.jsonl` generations retained (`0` discards the active ledger at the size limit). |
333
+ | `resultRetentionMs` | `604800000` | Duration in ms (7 days) that settled goal summaries remain visible in `/goal status`. |
334
+ | `maxStoredResults` | `10` | Maximum number of settled goal summaries retained in memory. |
335
+ | `commandName` | `"goal"` | Slash command name owned by the plugin (leading slash tolerated; user-facing hints follow this name). |
336
+ | `registerCommand` | `true` | Registers the slash command (`command.execute.before` on 1.x, `command.transform` on 2.x). |
337
+ | `registerTools` | `true` | Registers the agent-facing goal tools. |
338
+ | `registerAgents` | `true` | Registers the `goal` and `goal-verify` agents (`config` hook on 1.x, `agent.transform` on 2.x), preserving existing agents with those names and leaving the default agent unchanged. |
339
+ | `goalAgentName` | `"goal"` | Name for the auto-registered goal agent. |
340
+ | `verifierAgentName` | `"goal-verify"` | Name for the auto-registered read-only verifier subagent. |
341
+ | `goalMessages` | `true` | Enables user-visible announcements for verdicts, attestation faults, pauses, recovery turns, and unattested settlements (routed to structured logs and TUI toasts by default). |
342
+ | `goalMessenger` | _(none)_ | Custom `(sessionID, text)` callback for routing announcements and command receipts. |
343
+ | `sdkShape` | `"legacy"` | Session-client argument shape: `"legacy"` (`{ path, body, query }`) or `"flat"` (`{ sessionID, ... }`). |
344
+
345
+ ### Environment variables
346
+
347
+ | Variable | Effect |
348
+ |:---|:---|
349
+ | `FIXATE_ON_STATE_ROOT` | Overrides the persisted state root directory when `stateRoot` is not set (see [Persistence and state root](#persistence-and-state-root)). |
350
+ | `FIXATE_ON_EVENT_LOG` | Optional OpenCode 2.x diagnostic log path (unset by default). When set to a writable file path, appends space-delimited event lines for 2.x adapter events and tool-registration failures. Contains live session and message IDs; treat as sensitive and delete after debugging. |
351
+
352
+ ## Compatibility
353
+
354
+ | Area | Details |
355
+ |:---|:---|
356
+ | Runtime and OS | Bun `>=1.0.0`, OpenCode 1.x (`>=1.17.18`), and OpenCode 2.x. Tested on Linux, macOS, and Windows. The npm install of 0.2.0 was exercised on OpenCode 1.19.6 and 2.4.5; earlier versions in range were compared with host source only (plugin loaders and OpenTUI imports). |
357
+ | Package exports | `.` and `./server` load the server plugin and `./tui` loads the companion, each on both 1.x and 2.x. |
358
+ | Experimental hooks | Relies on `experimental.chat.system.transform` and related lifecycle hooks. Re-test against your exact OpenCode build and provider stack before unattended runs. |
359
+ | Read-only built-in judge | The built-in `goal-verify` subagent only uses `read`, `glob`, and `grep`. It cannot run shell commands and relies on workspace inspection plus evidence cited by the working agent. |
360
+
361
+ For TUI host API requirements, see [`docs/tui-integration.md#host-api-requirements`](docs/tui-integration.md#host-api-requirements).
362
+
363
+ ## Troubleshooting
364
+
365
+ Start by inspecting the current state, stop reason, brake usage, recorded claims, and lifecycle trail:
366
+
367
+ ```sh
368
+ /goal status --full
369
+ /goal list all
370
+ /goal history --verbose
371
+ ```
372
+
373
+ ### Install and host issues
374
+
375
+ | Symptom | Cause | Fix |
376
+ |:---|:---|:---|
377
+ | `configured plugin path must be a directory` | OpenCode 2.x was given a plugin file path | Point `plugins[].package` at the repository directory (see [Local source](#local-source)). |
378
+ | OpenCode 1.x loads no plugins (no error) | `plugins` (plural) was used in a config read by 1.x | Use `plugin` (singular); OpenCode 2.x accepts it too. |
379
+ | OpenCode 1.x ignores permissions | `permissions` (plural) was used in a shared config | Use `permission` (singular); OpenCode 2.x accepts it too. |
380
+ | OpenCode 2.x sends `/goal ...` as plain chat | Host does not expose `command.transform` and no `command.goal` bridge is configured | Add the `command.goal` template from [`/goal` on OpenCode 2.x](#goal-on-opencode-2x). |
381
+ | OpenCode 2.x reports `Invalid V2 TUI plugin module: fixate-on` | `fixate-on` 0.1.0 is installed; its `./tui` was 1.x only | Run `opencode2 plugin update` to move to 0.2.0 or later. |
382
+ | `NpmInstallFailedError`, or an SSH passphrase prompt, at startup | A subpath such as `fixate-on/tui` was configured | Use the bare name `fixate-on` (see [TUI companion](#tui-companion)). |
383
+ | OpenCode 2.x has no `Fixate:` palette entries when connected to a remote server | The TUI's own package cache does not hold the plugin | Add `fixate-on` to `cli.json` on the TUI's machine (see [TUI companion](#tui-companion)). |
384
+ | OpenCode 1.x TUI companion does not appear | `fixate-on` is in `opencode.json` only | Add it to `tui.json` as well (see [TUI companion](#tui-companion)). |
385
+ | Dashboard state differs from `/goal status` | Server plugin and TUI companion resolved different state directories | On 1.x, set the same `stateRoot` on both entries or set `FIXATE_ON_STATE_ROOT`. On 2.x, remove any `stateRoot` from the `cli.json` entry so the companion follows the server (see [Persistence and state root](#persistence-and-state-root)). |
386
+
387
+ ### When a goal does not continue
388
+
389
+ 1. Check whether the pause is self-resolving. Goals paused for `recovery` or `queued` sequence ordering resume automatically. Goals stopped by `explicit pause`, brakes, no-progress or no-tool-call limits, prompt failures, `recovery exhausted`, or a legacy `user intervention` pause from an older version wait for user action.
390
+ 2. Run `/goal resume` after addressing the cause. This resets the turn count and starts a fresh window for configured per-run limits while keeping the objective and history.
391
+ 3. Inspect OpenCode's structured logs for persistence, prompt dispatch, or verifier faults, and verify that the working directory and state root match across server and TUI entries.
392
+
393
+ **Privacy note:** Redact `state.json`, `.ledger.jsonl`, and `FIXATE_ON_EVENT_LOG` files before attaching them to public issues. They contain goal text, progress notes, local paths, and session identifiers.
394
+
395
+ ## License
396
+
397
+ MIT License
@@ -0,0 +1,52 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:fixate-on:completion-verdict:v1",
4
+ "title": "fixate-on completion verdict",
5
+ "description": "The JSON object a verifier must emit. This is the wire contract of the completion gate; the plugin's parser is stricter than this schema in the ways noted in `description` at each constraint. Print one JSON object and nothing else.",
6
+ "type": "object",
7
+ "required": ["task_id", "state", "evidence"],
8
+ "properties": {
9
+ "schema_version": {
10
+ "description": "The contract version. Defaults to 1 when omitted; any explicit value other than 1 is rejected.",
11
+ "const": 1
12
+ },
13
+ "task_id": {
14
+ "description": "The goal or task this verdict is about.",
15
+ "type": "string",
16
+ "minLength": 1
17
+ },
18
+ "state": {
19
+ "description": "The terminal state the verifier is willing to stand behind. COMPLETE: the agreed scope holds on the identified candidate. WORKING: not yet complete, and `outstanding` says what remains. BLOCKED: progress needs authority or an environment change the agent lacks. NEEDS_INPUT: progress needs a material decision from you. CANCELLED: an authorised actor ended the task.",
20
+ "enum": ["COMPLETE", "WORKING", "BLOCKED", "NEEDS_INPUT", "CANCELLED"]
21
+ },
22
+ "candidate": {
23
+ "description": "Identity of the tree the verifier actually read — normally the git HEAD short sha. OPTIONAL, because a model acting as judge cannot compute it; an absent or empty value means 'not claimed' and the host stamps its own capture instead.",
24
+ "type": "string"
25
+ },
26
+ "fingerprint": {
27
+ "description": "Identity of the whole tracked and untracked working tree the verifier read, as a digest. Same optionality as `candidate`.",
28
+ "type": "string"
29
+ },
30
+ "outstanding": {
31
+ "description": "What remains. MUST be empty (or omitted) for COMPLETE and CANCELLED, and MUST hold at least one non-empty string for WORKING, BLOCKED and NEEDS_INPUT.",
32
+ "type": "array",
33
+ "items": { "type": "string", "minLength": 1 }
34
+ },
35
+ "evidence": {
36
+ "description": "What the verifier actually observed, and the only thing that can settle a claim. MUST hold at least one non-empty string.",
37
+ "type": "array",
38
+ "minItems": 1,
39
+ "items": { "type": "string", "minLength": 1 }
40
+ }
41
+ },
42
+ "allOf": [
43
+ {
44
+ "if": { "properties": { "state": { "enum": ["COMPLETE", "CANCELLED"] } }, "required": ["state"] },
45
+ "then": { "properties": { "outstanding": { "maxItems": 0 } } }
46
+ },
47
+ {
48
+ "if": { "properties": { "state": { "enum": ["WORKING", "BLOCKED", "NEEDS_INPUT"] } }, "required": ["state"] },
49
+ "then": { "required": ["outstanding"], "properties": { "outstanding": { "minItems": 1 } } }
50
+ }
51
+ ]
52
+ }
@@ -0,0 +1,75 @@
1
+ # TUI companion
2
+
3
+ Reference for the `fixate-on` TUI companion: keyboard shortcuts, passive command receipts on OpenCode 2.x, state sync, and host API requirements. For installation and slash commands, see [README.md](../README.md#tui-companion) and the [command reference](../README.md#goal-command-reference).
4
+
5
+ ## Keyboard shortcuts
6
+
7
+ The companion registers chord bindings under the `ctrl+shift+g` prefix so single keystrokes stay out of the prompt input:
8
+
9
+ | Chord | Action | Equivalent command |
10
+ |---|---|---|
11
+ | `ctrl+shift+g` `d` | Show dashboard | `/goal list` |
12
+ | `ctrl+shift+g` `p` | Pause goal | `/goal pause` |
13
+ | `ctrl+shift+g` `r` | Resume goal | `/goal resume` |
14
+ | `ctrl+shift+g` `c` | Clear goal | `/goal clear` |
15
+ | `ctrl+shift+g` `e` | Edit objective | `/goal edit` |
16
+ | `ctrl+shift+g` `k` | Save checkpoint | `/goal checkpoint` |
17
+
18
+ Some terminals deliver `ctrl+shift+g` as `0x07` so chords do not fire. Use the command palette (`ctrl+p`, then filter on `fixate:`) or `/goal` slash commands on any terminal.
19
+
20
+ On OpenCode 2.x, while the goal dashboard is open, a modal keymap layer handles `up`/`down` (line scroll) and `pageup`/`pagedown` (half-page scroll) alongside the global `fixate-on.scroll.*` fallback bindings. Both stay inactive when the dashboard is closed so host arrow and page keys are unaffected.
21
+
22
+ ## Passive command receipts on 2.x
23
+
24
+ On OpenCode 2.x, native `/goal` commands and notices never call `session.prompt` or `session.synthetic`. Instead, the server registers the `fixate-on-output` RPC domain and publishes receipts on `rpc.fixate-on-output.output` with `{id, sessionID, text, kind, timestamp}` (`kind` is `command` or `notice`).
25
+
26
+ For the currently open session, command receipts open in a scrollable dialog (`up`/`down`, `pageup`/`pagedown`, `home`/`end`, or mouse wheel to scroll; `escape` or `enter` to close). Notices and receipts for other sessions render as session-scoped toasts.
27
+
28
+ The companion queries the latest receipt at startup and after `server.connected`, using monotonic server timestamps so delayed replays cannot overwrite a newer live receipt and repeated receipt IDs are ignored after display.
29
+
30
+ A headless client can consume `rpc.fixate-on-output.output` from the event stream or request the latest receipt directly:
31
+
32
+ ```http
33
+ POST /api/rpc/fixate-on-output/latest?location[directory]=/absolute/workspace
34
+ Content-Type: application/json
35
+
36
+ {"input":{"sessionID":"ses_example"}}
37
+ ```
38
+
39
+ The `location[directory]` query selects the workspace plugin instance (without it, the host uses the server process directory). The response is `{"output": <receipt or null>}`. This channel is an in-memory display buffer per server process, not a persisted transcript. Hosts without passive RPC can supply `goalMessenger`; when neither channel exists, the command returns an explicit delivery error containing the completed command output.
40
+
41
+ ## State sync and notifications
42
+
43
+ On OpenCode 2.x, live goal metadata arrives over the server's buffering `tuiTransport` alongside a serialized disk reader for persisted state. The server also exposes the `fixate-on-state` RPC (`root` method and `changed` event) so the companion discovers the server's resolved `stateRoot` automatically and rebinds when configuration changes. An explicit `stateRoot` in `cli.json` overrides the server. Without a server answer, the companion falls back to `FIXATE_ON_STATE_ROOT`, then `<cwd>/.opencode/goals`.
44
+
45
+ Smoke-test the pairing from a session running the server plugin:
46
+
47
+ ```sh
48
+ /goal status
49
+ /goal list all
50
+ ```
51
+
52
+ On OpenCode 1.x, `client.tui.publish` renders every published envelope directly on screen, so the server never sends data envelopes on that channel. The 1.x companion reads persisted session state on a serialized disk refresh loop, so both `opencode.json` and `tui.json` must resolve the same `stateRoot`.
53
+
54
+ Both companions filter notifications at working boundaries so ongoing turns and token ticks stay quiet:
55
+
56
+ | Moment | Announced |
57
+ |---|---|
58
+ | Goal created or cleared | Yes |
59
+ | Started working (resume, sequence promotion, resume after brake) | Yes |
60
+ | Stopped working (pause, stall, deferral, error, brake, complete, blocked) | Yes |
61
+ | Internal recovery pause while restoring persisted state on load | No |
62
+ | Ongoing continuations of an already active goal | No |
63
+ | Token and turn accounting updates | No |
64
+
65
+ The disk refresh loop reads archived settlement results alongside live goals, so settled goals announce `Goal complete:` rather than a generic removal, and cleared goals include the objective text. Toasts are coalesced per session so activity in one session does not silence another. After initial load, the companion emits at most one summary toast for goals waiting on user action (including legacy `user intervention` pauses from older plugin versions, which require `/goal resume`).
66
+
67
+ Usage-only token updates stay in memory until the next semantic transition rather than writing disk state on every token tick, so file-sourced dashboard gauges update on lifecycle transitions and poll intervals. Concurrent live store updates always take precedence over in-flight disk reads, and unreadable session files retain their prior snapshots until the next clean read.
68
+
69
+ ## Host API requirements
70
+
71
+ - OpenCode `>=1.17.18 <3` (`engines.opencode`).
72
+ - The package exports one `./tui` entry (`{id, tui, setup}`) serving both host generations without importing host SDKs at runtime.
73
+ - `@opencode-ai/plugin`, `@opentui/solid`, and `solid-js` are optional peers; hosts supply Solid and OpenTUI singletons at runtime so reactive updates stay live.
74
+ - Optional `ui.toast` and `ui.dialog` APIs render notifications and dialogs; without them, state tracking continues silently.
75
+ - On OpenCode 2.x, local plugin paths must point at a directory rather than a file, and the companion registers its palette keymap layer with `mode: "global"` so `Fixate:` commands remain reachable while the command palette is open.