fixate-on 0.1.0 → 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.
@@ -2,47 +2,41 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "urn:fixate-on:completion-verdict:v1",
4
4
  "title": "fixate-on completion verdict",
5
- "description": "The object a verifier must print on stdout. This is the wire contract of `verifierCommand` and of the project's own `completion-gate-json` make target; 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.",
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
6
  "type": "object",
7
- "additionalProperties": false,
8
- "required": ["schema_version", "task_id", "state", "outstanding", "evidence"],
7
+ "required": ["task_id", "state", "evidence"],
9
8
  "properties": {
10
9
  "schema_version": {
11
- "description": "The contract version. Only 1 exists; a different number is a parse error, not a best-effort read.",
10
+ "description": "The contract version. Defaults to 1 when omitted; any explicit value other than 1 is rejected.",
12
11
  "const": 1
13
12
  },
14
13
  "task_id": {
15
- "description": "The goal or task this verdict is about. Bounded at 256 characters.",
14
+ "description": "The goal or task this verdict is about.",
16
15
  "type": "string",
17
- "minLength": 1,
18
- "maxLength": 256
16
+ "minLength": 1
19
17
  },
20
18
  "state": {
21
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.",
22
20
  "enum": ["COMPLETE", "WORKING", "BLOCKED", "NEEDS_INPUT", "CANCELLED"]
23
21
  },
24
22
  "candidate": {
25
- "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. A command verifier is held to it: an absent or disagreeing value is treated as a mismatch and the verdict is rejected. Bounded at 256 characters.",
26
- "type": "string",
27
- "maxLength": 256
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"
28
25
  },
29
26
  "fingerprint": {
30
- "description": "Identity of the whole tracked and untracked working tree the verifier read, as a digest. Same optionality and same bound as `candidate`.",
31
- "type": "string",
32
- "maxLength": 256
27
+ "description": "Identity of the whole tracked and untracked working tree the verifier read, as a digest. Same optionality as `candidate`.",
28
+ "type": "string"
33
29
  },
34
30
  "outstanding": {
35
- "description": "What remains. MUST be empty for COMPLETE and CANCELLED, and MUST hold at least one item for WORKING, BLOCKED and NEEDS_INPUT — the plugin rejects a state that contradicts its own list. At most 32 items, each 1 to 500 characters.",
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.",
36
32
  "type": "array",
37
- "maxItems": 32,
38
- "items": { "type": "string", "minLength": 1, "maxLength": 500 }
33
+ "items": { "type": "string", "minLength": 1 }
39
34
  },
40
35
  "evidence": {
41
- "description": "What the verifier actually observed, and the only thing that can settle a claim. MUST hold at least one item. At most 64 items, each 1 to 500 characters.",
36
+ "description": "What the verifier actually observed, and the only thing that can settle a claim. MUST hold at least one non-empty string.",
42
37
  "type": "array",
43
38
  "minItems": 1,
44
- "maxItems": 64,
45
- "items": { "type": "string", "minLength": 1, "maxLength": 500 }
39
+ "items": { "type": "string", "minLength": 1 }
46
40
  }
47
41
  },
48
42
  "allOf": [
@@ -52,7 +46,7 @@
52
46
  },
53
47
  {
54
48
  "if": { "properties": { "state": { "enum": ["WORKING", "BLOCKED", "NEEDS_INPUT"] } }, "required": ["state"] },
55
- "then": { "properties": { "outstanding": { "minItems": 1 } } }
49
+ "then": { "required": ["outstanding"], "properties": { "outstanding": { "minItems": 1 } } }
56
50
  }
57
51
  ]
58
52
  }
@@ -1,327 +1,75 @@
1
- # TUI Integration Guide
1
+ # TUI companion
2
2
 
3
- The `fixate-on` provides a dual-mode system: a **server plugin**
4
- that manages goal state and a **TUI companion plugin** that renders
5
- interactive status panels, keyboard controls, and toast notifications.
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).
6
4
 
7
- ## Architecture
5
+ ## Keyboard shortcuts
8
6
 
9
- **Which file loads what:** stock OpenCode v1 loads the server plugin from the
10
- `opencode.json` `plugin` array and the TUI companion ONLY via the `tui.json`
11
- `plugin` array (`~/.config/opencode/tui.json`, overridable with
12
- `$OPENCODE_TUI_CONFIG`).
13
- Registering the companion in `opencode.json` does not load it. With the
14
- companion in `tui.json`, all 11 `Fixate:` palette entries of the v1 companion render
15
- (palette filtered on `fixate:`; the v2 companion registers 13) with chord
16
- hints shown on the six bound actions. One
17
- caveat stands: the chords themselves are not byte-deliverable through
18
- tmux/terminal (`ctrl+shift+g` arrives as `0x07`), so the palette — not the
19
- chord — is the guaranteed path, and every live campaign in
20
- `hack/e2e-harness/` drives the palette. The v1 companion therefore keeps
21
- its slash + state-file surfaces first-class.
7
+ The companion registers chord bindings under the `ctrl+shift+g` prefix so single keystrokes stay out of the prompt input:
22
8
 
23
- On opencode2 the server→TUI channel rides `tool Result.metadata`
24
- (`tool Result.metadata` → `session.tool.success` → `context.data.on` → store),
25
- not `client.tui.publish`. On stock v1 the transport is disk hydration +
26
- a state-file refresh loop plus curated human-readable toasts — the publish
27
- channel is never used as a data transport there (v1 renders every published
28
- toast on screen, so data events would flood the UI).
29
-
30
- ```
31
- OpenCode Host (v1: toast channel)
32
-
33
- Server Plugin (src/plugin.ts) TUI Companion Plugin (src/tui.ts)
34
- - goal state - state store
35
- - state machine - dashboard formatter
36
- - persistence - keymap handlers
37
- - command hooks - toast manager
38
- - broadcaster
39
- | publish
40
- v
41
- Host Event Bus (SSE): client.tui.publish() -> api.event.on("tui.toast.show")
42
- ```
43
-
44
- ## Installation
45
-
46
- Register the server plugin in `opencode.json` and the TUI companion in `tui.json`
47
- (the v1 loader reads them from different files — putting the companion in
48
- `opencode.json` does not load it):
49
-
50
- `opencode.json`:
51
-
52
- ```json
53
- {
54
- "plugin": [
55
- "fixate-on"
56
- ]
57
- }
58
- ```
59
-
60
- `tui.json` (`~/.config/opencode/tui.json`, or `$OPENCODE_TUI_CONFIG`):
61
-
62
- ```json
63
- {
64
- "plugin": [
65
- "fixate-on/tui"
66
- ]
67
- }
68
- ```
69
-
70
- The server plugin (`fixate-on`) manages goal state, persistence,
71
- and the command execution loop. The TUI companion (`fixate-on/tui`)
72
- subscribes to goal lifecycle events and renders interactive panels.
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` |
73
17
 
74
- ## Dual-Mode Command Execution
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.
75
19
 
76
- Slash commands (`/goal status`, `/goal history`, `/goal list`, etc.) operate
77
- in two modes:
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.
78
21
 
79
- ### TUI Mode (companion attached)
22
+ ## Passive command receipts on 2.x
80
23
 
81
- When the TUI companion is registered, the server plugin detects
82
- `client.tui.publish` and sets the `hasTuiCompanion` flag. Command output
83
- includes a header noting the interactive dashboard is available:
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`).
84
25
 
85
- ```
86
- [TUI mode] /status
87
- Active goal: fix the failing tests
88
- Auto-continues sent: 3/10
89
- Context tokens: 12,400/200,000
90
- ...
91
- ```
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.
92
27
 
93
- The TUI companion receives goal lifecycle events in real time via the host
94
- event bus, maintaining a synchronized state store that powers the interactive
95
- dashboard.
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.
96
29
 
97
- ### Server Mode (headless / no TUI)
30
+ A headless client can consume `rpc.fixate-on-output.output` from the event stream or request the latest receipt directly:
98
31
 
99
- When no TUI companion is registered, commands produce plain-text output with
100
- an explicit header indicating the output is routed to the model as a chat
101
- turn:
32
+ ```http
33
+ POST /api/rpc/fixate-on-output/latest?location[directory]=/absolute/workspace
34
+ Content-Type: application/json
102
35
 
36
+ {"input":{"sessionID":"ses_example"}}
103
37
  ```
104
- [Server mode - output routed to model as chat turn] /status
105
- Active goal: fix the failing tests
106
- Auto-continues sent: 3/10
107
- Context tokens: 12,400/200,000
108
- ...
109
- ```
110
-
111
- This is the default behavior when running in headless/automated environments.
112
-
113
- ## Keyboard Shortcuts
114
-
115
- The TUI companion registers two-key chords: the `ctrl+shift+g` prefix, then the
116
- action key. The prefix is what keeps these out of the prompt's way.
117
38
 
118
- | Chord | Action | Description |
119
- |--------------------|-------------|--------------------------------|
120
- | `ctrl+shift+g` `d` | Dashboard | Show the status dashboard |
121
- | `ctrl+shift+g` `p` | Pause | Pause the active goal |
122
- | `ctrl+shift+g` `r` | Resume | Resume the paused goal |
123
- | `ctrl+shift+g` `c` | Clear | Clear the active goal |
124
- | `ctrl+shift+g` `e` | Edit | Edit the goal objective |
125
- | `ctrl+shift+g` `k` | Checkpoint | Add a checkpoint |
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.
126
40
 
127
- **The prefix is not universally deliverable.** On some terminals `ctrl+shift+g`
128
- arrives as `0x07` and the chord never fires. The command palette
129
- (`ctrl+p`, then type `fixate:`) reaches all six actions on every supported host,
130
- and is the path every live campaign in `../hack` takes.
41
+ ## State sync and notifications
131
42
 
132
- The `0x07` behaviour was recorded during product design. The prefix is unclaimed
133
- in common emulators and still undeliverable on some terminals; both can be
134
- true. The chord is an optimisation; the palette is the guarantee.
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`.
135
44
 
136
- Keymaps are optional overrides — the user can interact via `/goal` commands
137
- without ever touching a key (AGENTS.md Principle 4).
45
+ Smoke-test the pairing from a session running the server plugin:
138
46
 
139
- ## State Synchronization
140
-
141
- The server plugin publishes goal lifecycle events over
142
- `pluginOptions.tuiTransport` — the v2 adapter's buffering channel, surfaced
143
- through tool `Result.metadata`. That envelope carries a `fixate-on` marker the
144
- companion filters on:
145
-
146
- ```json
147
- {
148
- "fixate-on": { "events": [ { "kind": "transition", "goalId": "…", "snapshot": { } } ] }
149
- }
47
+ ```sh
48
+ /goal status
49
+ /goal list all
150
50
  ```
151
51
 
152
- `GOAL_TUI_METADATA_KEY` is the property name and `GOAL_TUI_EVENT_TITLE` is the
153
- title used on the equivalent direct event envelope; both are the package name by
154
- design, and both are defined once in `src/tui-state.ts`.
155
-
156
- ### On v1 hosts there is no event transport
157
-
158
- The v1 `client.tui.publish` endpoint renders **every** published envelope as a
159
- visible toast, so the server sends **no** data events on that channel — it is
160
- contractually silent, and a test locks that. On a v1 host the companion instead
161
- reads the persisted state file (`readDiskGoalSnapshots`) on a refresh loop
162
- (`createDiskRefreshLoop`) and curates its own rare, human-readable toasts
163
- (`tui-toast-policy.ts`). Live indicators still update; the source of truth is the
164
- state file rather than an event stream.
165
-
166
- This is why the architecture note above says the publish channel "is never used
167
- as a data transport there". It is not a lesser path — it is the only path that
168
- does not put JSON on a user's screen.
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`.
169
53
 
170
- ### Which moments reach the user
171
-
172
- `createDiskRefreshLoop` synthesises an event per diff, and `tui-toast-policy.ts`
173
- decides which of those are worth a line of text. The rule is the **working
174
- boundary**: a moment that changes whether the goal is working.
54
+ Both companions filter notifications at working boundaries so ongoing turns and token ticks stay quiet:
175
55
 
176
56
  | Moment | Announced |
177
57
  |---|---|
178
- | Goal created or cleared | yes |
179
- | Started working — session resume, sequence auto-promote, resume after a brake | yes |
180
- | Stopped working — stall, deferral, execution error, `/goal pause`, brake, complete, blocked | yes |
181
- | Paused for your next message, and re-armed when your turn ends | no, either half |
182
- | The plugin's own recovery pause while restoring a session | no |
183
- | Every continuation of a goal that is already working | no |
184
- | Token and turn accounting | no |
185
-
186
- The two silent rows follow from the same rule. On every human message
187
- `hooks.ts` pauses each active goal and the idle handler re-arms it, so the user
188
- just spoke and the goal hands the turn straight back; announcing either half
189
- produced two toasts per goal per message sent. The recovery pause is the
190
- plugin's own bookkeeping during hydration. Both are recognised from the stop's
191
- own `stopReason` — the companion sees the pause and remembers which goals are
192
- mid-yield — so no producer had to change to tell a yield from a resume.
193
-
194
- Telling "started" from "still working" needs the status the goal held *before*
195
- the event. A running goal rewrites its persisted state on every turn, so
196
- `status: active` alone cannot say whether the goal just started or is still
197
- going. Both producers send that: the broadcaster as `previousStatus` alongside
198
- its `transition`, and the disk loop from the snapshot it diffed against. An
199
- event with neither is announced only when its snapshot states its own outcome —
200
- `complete`, `blocked`, or a limit-class stop — because an `active` snapshot on
201
- its own cannot distinguish an entry from a continuation, and guessing "entry" is
202
- what a storm looks like.
203
-
204
- `ToastCoalescer` sits between the policy and `ui.toast`. It enforces a 2 s
205
- minimum interval, a 500 ms duplicate window and a bounded queue, **per
206
- session** — a goal settling in one session of a workspace is not silenced by
207
- another session's traffic. When one goal produces a second moment inside the
208
- same window, the newer replaces the older in the queue: the newest state of a
209
- goal is the only one worth saying. A toast already shown is not replaced,
210
- because it cannot be un-shown, so a goal that stops and is resumed in separate
211
- windows is reported twice — once for each thing that actually happened.
212
-
213
- ### On load
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 |
214
64
 
215
- Hydration is silent about moments. A goal recovered from disk does not announce
216
- itself as newly started, because you did not start it — and the refresh loop
217
- refuses to take a baseline from a read that could see neither a state file nor a
218
- state directory, so a state file caught mid-write cannot turn every running goal
219
- into a fresh "Goal started". It is not silent about facts: after the companion's
220
- first authoritative read it emits at most one summary naming how many goals in
221
- the workspace are stopped and waiting on you, grouped by reason. Goals that
222
- resume on their own — `recovery`, `user intervention`, `queued` — are excluded,
223
- because the boundary announcement already covers them. The exclusion for
224
- `user intervention` is conditional: the pause is a promise that the plugin
225
- will re-arm the goal when your turn ends, and on a host that delivers no idle
226
- events the poller is the only thing that can keep that promise. The poller
227
- can refuse — the newest message is yours and no reply has arrived, the reply
228
- carries no id, or the turn never reports itself settled — and each refusal is
229
- correct, because a gate that stops a continuation being injected into a live
230
- turn is protecting against a worse harm than a goal that waits.
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`).
231
66
 
232
- So a yield past `YIELD_PROMISE_MS` (15 minutes, read from the goal's own
233
- persisted clock so a restart cannot forgive it) stops being counted as
234
- self-resolving. It briefs as "it did not pick your message back up", the card
235
- reads `did not re-arm` rather than `re-arms automatically`, and `/goal status`
236
- offers a resume. A yield inside its window is unchanged, which is the half that
237
- matters: the exclusion exists so a goal about to resume is not announced as
238
- though it needed you.
239
-
240
- ### Event Types
241
-
242
- | Kind | Trigger | Payload |
243
- |--------------|----------------------------|-------------------|
244
- | `create` | Goal created | Snapshot |
245
- | `transition` | Status change (pause/resume/complete/block) | Snapshot + `previousStatus`; the server broadcaster also sends `transition` |
246
- | `usage` | Token/turn count updated | Snapshot |
247
- | `remove` | Goal deleted | goalId only |
248
-
249
- ### Resilience
250
-
251
- - **Broadcaster failures are swallowed** — a TUI disconnect cannot break the
252
- state machine.
253
- - **Revision monotonicity** — stale events (lower revision) are ignored for
254
- existing goals.
255
- - **Late subscribers hydrate** from the store's current state (no event
256
- replay needed), and on v1 from the state file on disk.
257
- - **Snapshots are frozen** — the TUI render layer cannot mutate shared state.
258
- - **A disk refresh that races a write** is a read of a partially written file,
259
- not a crash: the next tick re-reads.
260
-
261
- ### Display lag and the staleness floor
262
-
263
- The file-sourced dashboard does not show live memory; it shows the last state
264
- file the server persisted, read on a poll. Three numbers bound how stale that
265
- can be, and they are stated here because the acceptance for state alignment
266
- requires the lag documented with numbers rather than left implicit.
267
-
268
- - **Usage-only churn does not move the gauge.** `updateUsage`
269
- (src/state-machine.ts, `updateUsage`) mutates the in-memory state and deliberately skips
270
- persistence: "No onCommit — usage updates are frequent; persistence happens on
271
- the next semantic transition" (the comment on `updateUsage` in src/state-machine.ts). The dashboard reads
272
- `totalTokens` from the state file (src/tui-views.ts), so during a long
273
- turn that produces only token churn the gauge stays where the last semantic
274
- persist left it. It moves on the next pause/resume/edit/checkpoint or any
275
- lifecycle transition. That lag is by design, not a defect; the alternative is a
276
- disk write per usage event.
277
- - **Staleness floor.** A state-file change reaches the dashboard within one
278
- refresh poll, default 1000 ms (`intervalMs` in src/tui-companion-refresh.ts). A lifecycle
279
- moment reaches a toast within that poll plus the coalescer's 2000 ms
280
- minimum-interval gate (`TOAST_MIN_INTERVAL_MS` in src/tui-toast-policy.ts), with a 500 ms
281
- duplicate-suppression window. So the floor is roughly 1 s for the dashboard
282
- and up to 3 s for a toast after a persist.
283
- - **A WAL-durable removal with a failed snapshot.** `removeGoalOwned`
284
- (src/session-lifecycle.ts) appends a durable removal tombstone to the
285
- ledger, sets the invalidation fence, then persists the snapshot. If that
286
- snapshot write fails, the
287
- on-disk state file still lists the goal, and the fence marker is retained
288
- (`pendingInvalidationCheckpoints`, held by SessionStateManager in
289
- src/session-state-manager.ts) rather
290
- than released. Two things keep this honest: the live removal is broadcast
291
- immediately (`broadcaster.emitRemove`), so
292
- the in-memory store drops the goal at once; and the fence's
293
- `invalidatedGoalIds` is written into the next durable snapshot, so recovery and
294
- any later read treat the goal as removed — it cannot be resurrected or driven.
295
- The v1 companion reads snapshots only, never the ledger, so between a failed
296
- snapshot and the next successful persist there is a bounded window where the
297
- disk-sourced dashboard can still show the goal; the fence, not the display, is
298
- the guarantee, and it holds.
299
-
300
- ## Module Structure
301
-
302
- | Module | Role | Project dependencies |
303
- |---|---|---|
304
- | `src/tui-state.ts` | Snapshot projection, event contract, in-process store (leaf) | `accounting.ts`, `state-machine.ts` |
305
- | `src/tui-components.ts` | Toast helpers + `PRODUCT_DISPLAY_NAME` (leaf) | None |
306
- | `src/tui-views.ts` | Dashboard formatter (pure) | `brake-format.ts`, `status-label.ts`, `tui-analytics.ts`, `tui-components.ts`, `tui-state.ts` |
307
- | `src/tui-dashboard-route.tsx` | Host-native full-screen dashboard route | `tui-components.ts`, `tui-state.ts`, `tui-views.ts` (the card's text comes from `goalCardLines`, which is what makes the attribution and the brake ceiling testable without the host's terminal renderer) |
308
- | `src/tui-toast-policy.ts` | Which store moments deserve a visible toast | `status-label.ts`, `tui-components.ts`, `tui-state.ts`, plus the `GoalStatus` type from `state-machine.ts` |
309
- | `src/tui-action-labels.ts` | Outcome-neutral palette labels and watchdog hints | `tui-components.ts` |
310
- | `src/tui-analytics.ts` | Cost per turn, burn rate, ETA projection (pure) | `accounting.ts`, `tui-components.ts`, `tui-state.ts` |
311
- | `src/tui-sound.ts` | Lifecycle event to attention-sound name (pure) | `state-machine.ts`, `tui-state.ts` |
312
- | `src/tui-disk-state.ts` | Enumerates and reads every session's persisted goal state | `fs-portable.ts` (the bounded, symlink-refusing read), `session-paths.ts` (the layout), `state-machine.ts`, `tui-state.ts` |
313
- | `src/tui-companion-refresh.ts` | v1 disk refresh loop | `tui-disk-state.ts`, `tui-state.ts` |
314
- | `src/tui.ts` | v1 TUI companion entrypoint | `tui-action-labels.ts`, `tui-companion-refresh.ts`, `tui-components.ts`, `tui-disk-state.ts`, `tui-sound.ts`, `tui-state.ts`, `tui-toast-policy.ts`, `tui-views.ts`, plus `@opencode-ai/plugin` and `@opencode-ai/plugin/tui` |
315
- | `src/tui-v2.ts` | v2 TUI companion entrypoint | `tui-action-labels.ts`, `tui-components.ts`, `tui-dashboard-route.tsx`, `tui-disk-state.ts`, `tui-state.ts`, `tui-v2-events.ts`, `tui-views.ts` |
316
- | `src/tui-v2-events.ts` | v2 event-driven truth channels: disk-refresh loop, curated toasts, briefing, tool-metadata subscription | `state-machine.ts`, `tui-action-labels.ts`, `tui-companion-refresh.ts`, `tui-components.ts`, `tui-sound.ts`, `tui-state.ts`, `tui-toast-policy.ts` |
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.
317
68
 
318
- ## Host API Requirements
69
+ ## Host API requirements
319
70
 
320
- - **OpenCode** >= 1.17.18
321
- - **`@opencode-ai/plugin`** >= 1.17.18 < 2
322
- - The host client should expose `ui.toast` / `ui.dialog`. Absent those, the
323
- companion still tracks state and the dashboard, it just cannot show anything.
324
- - **`tui.publish` is not a data transport and never was** — see
325
- [On v1 hosts there is no event transport](#on-v1-hosts-there-is-no-event-transport).
326
- The v2 companion's data channel is the `tuiTransport` option; the v1
327
- companion's is the state file.
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.
package/index.d.ts CHANGED
@@ -37,8 +37,7 @@ export interface UsageSnapshot {
37
37
  // a structural approximation of it does not work: a function parameter is
38
38
  // contravariant, so a hand-written approximation that omits a required field of
39
39
  // GoalTuiEvent makes the only correct implementation fail to compile. These
40
- // mirror src/tui-state.ts, which imports them from src/state-machine.ts; the
41
- // shapes are pinned by test/published-docs-accuracy.test.ts.
40
+ // mirror src/tui-state.ts, which imports them from src/state-machine.ts.
42
41
  /** Goal lifecycle status, as the TUI sees it. */
43
42
  export type GoalStatus =
44
43
  'active' | 'paused' | 'blocked' | 'budgetLimited' | 'finalizing' | 'complete';
@@ -136,24 +135,13 @@ export interface GoalTuiSnapshot {
136
135
  readonly usage: Readonly<UsageSnapshot>;
137
136
  readonly stopReason: string;
138
137
  readonly blockedReason: string;
139
- /** When the goal was last paused; `0` when it is not paused.
140
- *
141
- * Carried on the snapshot because a display surface cannot answer "is this
142
- * yield still holding its promise" without knowing how long the goal has been
143
- * parked. A yield (`stopReason: "user intervention"`) is applied on every human
144
- * message and re-armed on the next idle; where the host delivers no idle, the
145
- * poller may be unable to deliver one, and the goal then sits still while every
146
- * surface still promises it will move. A surface reading only `stopReason` has
147
- * to either promise forever or never promise at all. */
138
+ /** When the elapsed-time clock was paused; `0` while that clock runs.
139
+ * Used to exclude paused intervals from elapsed run time. Ordinary human
140
+ * messages leave the goal active and do not pause that clock. */
148
141
  readonly pausedAt: number;
149
- /** When this stop was applied; `0` when the goal is not stopped. Renewed on
150
- * every stop, unlike `pausedAt`, which the elapsed-time clock stamps once.
151
- *
152
- * Read by the yield-promise bound: a goal yielded to a human message is
153
- * due to re-arm, and on a host that delivers no idle events the poller is
154
- * the only thing that can keep that promise. Past the bound the goal stops
155
- * being reported as self-resolving, so it briefs and `/goal status` offers a
156
- * resume instead of claiming the plugin will restart it. */
142
+ /** When the current stop was applied; `0` when the goal is not stopped.
143
+ * Renewed on each stop, unlike `pausedAt`, which is set once per paused
144
+ * interval. Retained for status snapshots and persisted-state compatibility. */
157
145
  readonly stoppedAt: number;
158
146
  readonly createdAt: number;
159
147
  readonly updatedAt: number;
@@ -238,9 +226,15 @@ export interface JudgeContext {
238
226
  /** Options for the built-in child-session judge, used when `childSessionJudge` is `true`. */
239
227
  export interface JudgeOptions {
240
228
  /** How long, in milliseconds, the built-in judge waits for a verdict from its
241
- * child OpenCode session. On timeout the claim is rejected and the goal is
242
- * paused. Operational failures follow {@link failurePolicy}.
243
- * @default 120000 */
229
+ * child OpenCode session. Verification of a substantial goal can legitimately
230
+ * take minutes, so the default is a generous 30 minutes. Set `0` to disable
231
+ * the deadline entirely (no timer, no child abort; host/provider timeouts
232
+ * still apply). A positive value bounds a hung host operation: on timeout the
233
+ * child is aborted and deleted and the failure is recorded as an attestation
234
+ * fault — retried with backoff under {@link failurePolicy}, never treated as
235
+ * a verdict on the claim. Values above 2147483647 are rejected (they would
236
+ * overflow the runtime timer into an instant abort).
237
+ * @default 1800000 */
244
238
  timeoutMs?: number;
245
239
  /** The result used when the child-session API is unavailable, returns a
246
240
  * malformed response, throws, or times out. A rejected claim or an invalid
@@ -303,13 +297,14 @@ export interface GoalsPluginOptions {
303
297
  * progress, so a hung tool call cannot hold the goal open.
304
298
  * @default 1800000 */
305
299
  maxDurationMs?: number;
306
- /** The maximum context-token budget a goal may use before it is stopped for
307
- * exceeding a limit. Set it for one goal with `--max-tokens`, or with the
308
- * `--budget` shorthand, which takes a `k` or `m` suffix such as `100k` or `1.5m`.
300
+ /** Optional cumulative context-token ceiling. By default, no context-token
301
+ * stop or wrap-up threshold is applied. Set a positive value for one goal
302
+ * with `--max-tokens`, or with the `--budget` shorthand, which takes a `k` or
303
+ * `m` suffix such as `100k` or `1.5m`; zero disables the ceiling.
309
304
  *
310
305
  * The count is cumulative over the whole goal (`totalTokens + compactionBaselineTokens`),
311
- * so compaction does not reduce it. It is a ceiling, not a target.
312
- * @default 1000000 */
306
+ * so compaction does not reduce it.
307
+ * @default 0 */
313
308
  maxTokens?: number;
314
309
  /** The minimum delay, in milliseconds, between two auto-continue prompts. Set it
315
310
  * for one goal with `--cooldown-ms`.
@@ -332,7 +327,9 @@ export interface GoalsPluginOptions {
332
327
  /** The number of consecutive tool-free continuation turns ("talk only" turns)
333
328
  * allowed before the goal is paused. This complements the no-progress check by
334
329
  * catching loops that produce output without using tools. Set it for one goal
335
- * with `--no-tool-turns`. Set the plugin option to `0` to disable the check.
330
+ * with `--no-tool-turns`. Direct replies to human input restart this streak
331
+ * without resetting accumulated turns or token usage. Set the plugin option
332
+ * to `0` to disable the check.
336
333
  * @default 3 */
337
334
  noToolCallTurnsBeforePause?: number;
338
335
  /** The fraction, strictly between 0 and 1, of a budget (turns, duration or
@@ -378,13 +375,13 @@ export interface GoalsPluginOptions {
378
375
  * @default '<cwd>/.opencode/goals' */
379
376
  stateRoot?: string;
380
377
  /** The workspace directory used to resolve `stateRoot` and other relative paths.
381
- * The v2 Context does not expose the host's workspace location to plugins. A v2
382
- * host whose `process.cwd` differs from the project, for example a from-source
383
- * checkout that changes directory before it starts the CLI, must pass the
384
- * workspace path here. When the option is absent the plugin uses
385
- * `process.cwd`, which is correct for v1 hosts and for installed v2 binaries
386
- * that set their own working directory.
387
- * @default process.cwd */
378
+ * On a v2 host the plugin reads the workspace from `ctx.location.directory` when
379
+ * this option is absent; `process.cwd()` is the last fallback, which is correct
380
+ * for v1 hosts and for installed v2 binaries that set their own working
381
+ * directory. Pass the workspace path here only when the host's `process.cwd`
382
+ * differs from the project, for example a from-source checkout that changes
383
+ * directory before it starts the CLI.
384
+ * @default ctx.location.directory on v2, otherwise process.cwd */
388
385
  workspaceDirectory?: string;
389
386
  /** The maximum size, in bytes, of one lifecycle-ledger generation. Each session has
390
387
  * its own ledger at `<sessions>/<sessionID>/state.json.ledger.jsonl`.
@@ -438,9 +435,12 @@ export interface GoalsPluginOptions {
438
435
  * No host-visible channel is used, because the v1 `client.tui.publish` endpoint
439
436
  * shows every envelope as a toast. */
440
437
  tuiTransport?: GoalTuiPublishFn;
441
- /** Whether the plugin installs its `command.execute.before` hook. Set it to
442
- * `false` if you only want auto-continue and persistence, driven through
443
- * {@link registerTools}, and do not want the plugin to own a slash command.
438
+ /** Whether the plugin owns the slash command: through the
439
+ * `command.execute.before` hook on 1.x hosts, and through the v2 Context's
440
+ * `command.transform` (registering its own `goal` command, overriding the
441
+ * built-in `opencode.goal`) on 2.x hosts. Set it to `false` if you only want
442
+ * auto-continue and persistence, driven through {@link registerTools}, and do
443
+ * not want the plugin to own a slash command.
444
444
  * @default true */
445
445
  registerCommand?: boolean;
446
446
  /** Whether the plugin registers the agent-facing goal tools
@@ -455,8 +455,10 @@ export interface GoalsPluginOptions {
455
455
  * is a version floor, not an import.
456
456
  * @default true */
457
457
  registerTools?: boolean;
458
- /** Register the `goal` and `goal-verify` agents through OpenCode's config hook.
459
- * An existing agent with either name is left unchanged.
458
+ /** Register the `goal` and `goal-verify` agents: through OpenCode's config hook
459
+ * on 1.x hosts, and through the v2 Context's `agent.transform` on 2.x hosts
460
+ * (which never call the 1.x config hook). An existing agent with either name
461
+ * is left unchanged.
460
462
  * @default true */
461
463
  registerAgents?: boolean;
462
464
  /** The name of the goal agent the plugin registers. @default "goal" */
@@ -499,12 +501,12 @@ export interface GoalsPluginOptions {
499
501
  * reset by a resume or by a turn that is not blocked.
500
502
  * @default 3 */
501
503
  maxBlockedTurns?: number;
502
- /** Enable advisory phrase triage for premature-exit language. When
503
- * true, the agent's final message is scanned for unfinished-work,
504
- * deferral, permission-seeking, and session-length signals. A match
505
- * adds the triage reason to the recovery prompt but CANNOT block a
506
- * verifier-OK COMPLETE. The triage is advisory and abstaining (:
507
- * patterns.md:340-371, adoption step 9 of 9).
504
+ /** Enable advisory phrase triage for premature-exit language and warm-cache
505
+ * natural-stop triage on OpenCode 2.x. When true, the agent's final message
506
+ * is scanned for unfinished-work, deferral, permission-seeking, and
507
+ * session-length signals (adding the reason to recovery prompts without
508
+ * overriding a verifier `COMPLETE`), and on 2.x idle natural stops can route
509
+ * completion or blocker claims to the configured verifier.
508
510
  * @default true */
509
511
  languageTriage?: boolean;
510
512
  /** Supply a custom completion judge instead of the built-in
@@ -543,9 +545,9 @@ export interface GoalsPluginHooks {
543
545
  * the moment the directory becomes known, so the handback diff reports only
544
546
  * what this goal changed. */
545
547
  'chat.params': (input: unknown) => Promise<void>;
546
- /** Detects user intervention and pauses the active goal immediately, so a
547
- * person answering the assistant stops the continuation loop rather than
548
- * racing it. */
548
+ /** Cancels pending plugin work when a human message arrives. Ordinary input
549
+ * leaves goals active while the host answers; an explicit stop pauses them
550
+ * and requests interruption of an in-flight plugin prompt. */
549
551
  'chat.message': (input: unknown, output: unknown) => Promise<void>;
550
552
  /** Omitted entirely when {@link GoalsPluginOptions.registerCommand} is `false`. */
551
553
  'command.execute.before'?: (input: unknown, output: unknown) => Promise<void>;