opencode-dev-framework 0.4.0 → 0.5.1
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/README.md +58 -42
- package/dist/block-store.d.ts +7 -23
- package/dist/block-store.js +7 -61
- package/dist/detect.js +1 -1
- package/dist/format-status.d.ts +8 -0
- package/dist/format-status.js +37 -12
- package/dist/gate.d.ts +5 -5
- package/dist/gate.js +5 -5
- package/dist/harness.d.ts +6 -8
- package/dist/harness.js +6 -8
- package/dist/index.d.ts +22 -13
- package/dist/index.js +148 -138
- package/dist/lint.d.ts +5 -3
- package/dist/lint.js +8 -5
- package/dist/registry.d.ts +6 -9
- package/dist/runtime-status.d.ts +29 -0
- package/dist/runtime-status.js +75 -0
- package/package.json +1 -1
- package/tui.tsx +32 -4
package/README.md
CHANGED
|
@@ -18,18 +18,20 @@ reimplemented as an OpenCode-native plugin.
|
|
|
18
18
|
- **Per-edit lint.** Runs your configured linter on each file the agent edits
|
|
19
19
|
and reports failures loudly. Optionally delegates per-file linting to
|
|
20
20
|
`pre-commit run --files` when `precommit: auto` is set.
|
|
21
|
-
- **Completion gate.**
|
|
22
|
-
|
|
21
|
+
- **Completion gate.** At the would-go-idle boundary (`session.hook("experimental.idle")`,
|
|
22
|
+
with an `idle` alias registered for a future rename), runs typecheck, tests,
|
|
23
|
+
and (optionally) lint on changed files — changed files are
|
|
23
24
|
tracked from edit events and cross-checked against `git status`, so the gate cannot
|
|
24
25
|
silently skip due to an event-shape mismatch. In `standard`/`strict`, sessions that
|
|
25
26
|
changed files must also produce a **peer-review artifact**
|
|
26
27
|
(`.opencode/opencode-dev-framework/review.md`) covering the delegation rule's review
|
|
27
|
-
cadence. On failure inside `gate.max_blocks` the plugin
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
the
|
|
32
|
-
(idle
|
|
28
|
+
cadence. On failure inside `gate.max_blocks` the plugin admits a synthetic
|
|
29
|
+
continuation in the same execution with the failure summary. The
|
|
30
|
+
`event.subscribe` idle net catches the boundaries the hook skips
|
|
31
|
+
(interruption, failure, steer-parked drains) — deduped so one boundary never
|
|
32
|
+
runs the gate twice, synthetic-first with `prompt` only as fallback.
|
|
33
|
+
`/df-status` shows `Continuation (idle): active` once the hook has completed
|
|
34
|
+
an evaluation, else the event-subscribe fallback.
|
|
33
35
|
- **Pre-flight gate (optional).** When a `preflight:` task list is configured, edit
|
|
34
36
|
tools are **denied** (standard/strict) until the agent writes its pre-flight findings
|
|
35
37
|
to `.opencode/opencode-dev-framework/preflight.md`. Use it for work that requires
|
|
@@ -60,14 +62,15 @@ reimplemented as an OpenCode-native plugin.
|
|
|
60
62
|
|
|
61
63
|
## Enforcement layers
|
|
62
64
|
|
|
63
|
-
How each mechanism is enforced on OpenCode `v2` (
|
|
65
|
+
How each mechanism is enforced on OpenCode `v2` (idle hook landed via
|
|
66
|
+
[`anomalyco/opencode#59437`](https://github.com/anomalyco/opencode/pull/59437)):
|
|
64
67
|
|
|
65
68
|
| Mechanism | Primary layer | Backstop / fallback | Strength |
|
|
66
69
|
| --------- | ------------- | ------------------- | -------- |
|
|
67
70
|
| Pre-flight gate | `tool.execute.before` deny | — | **Hard block** on every build: the edit never lands. |
|
|
68
71
|
| Protected paths + dangerous commands | `tool.execute.before` deny/throw | `permission.evaluate` native layer (deny) | **Hard block** via the backstop; the native layer is defense-in-depth (the pipeline runs before-hooks first, so it only sees calls the backstop passed). |
|
|
69
72
|
| Per-edit lint | `tool.execute.after` track + lint | `filesystem.changed` event (this release) | Report-only: the edit already landed, so failures log loudly but never throw. |
|
|
70
|
-
| Completion gate | `session.idle`
|
|
73
|
+
| Completion gate | `session.hook("experimental.idle")` (+ `idle` alias) → `session.synthetic` (same execution) | `event.subscribe` idle net for the boundaries the hook skips (deduped; synthetic-first, `prompt` fallback) | **Async, bounded** by `gate.max_blocks`. `/df-status` shows `Continuation (idle): active` vs the event-subscribe fallback. `execute.before` stays the only true hard wall. |
|
|
71
74
|
|
|
72
75
|
## Install
|
|
73
76
|
|
|
@@ -106,27 +109,19 @@ profile from the shell; `df version` prints the plugin version.
|
|
|
106
109
|
## Local development and testing
|
|
107
110
|
|
|
108
111
|
To test the plugin from source without publishing to npm, point OpenCode at the
|
|
109
|
-
local repository
|
|
110
|
-
The TUI module (`/df-status`, `/df-help` modals) is **not** auto-discovered for
|
|
111
|
-
local filesystem paths — it only loads when the package is listed in the TUI
|
|
112
|
-
config. OpenCode reads `tui.json` from the global config dir
|
|
113
|
-
(`~/.config/opencode/tui.json`) and the project dir (`.opencode/tui.json`).
|
|
114
|
-
|
|
115
|
-
`opencode.jsonc`:
|
|
112
|
+
local repository **root** in your project's `opencode.jsonc`:
|
|
116
113
|
|
|
117
114
|
```json
|
|
118
115
|
{
|
|
119
|
-
"plugins": [{ "package": "/home/jerome/opencode-dev-framework
|
|
116
|
+
"plugins": [{ "package": "/home/jerome/opencode-dev-framework" }]
|
|
120
117
|
}
|
|
121
118
|
```
|
|
122
119
|
|
|
123
|
-
The path
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
all. Rebuild after every source change (`npm run build`) since OpenCode
|
|
129
|
-
loads `dist/index.js` directly:
|
|
120
|
+
The root path resolves through the package's `exports` map, so one entry
|
|
121
|
+
loads **both** parts: the server (`dist/index.js` — hooks, guardrails, gate,
|
|
122
|
+
custom tools) and the TUI (`tui.tsx` — `/df-status`, `/df-help` modals).
|
|
123
|
+
Rebuild after every source change (`npm run build`) since OpenCode loads the
|
|
124
|
+
compiled `dist/` output:
|
|
130
125
|
|
|
131
126
|
```bash
|
|
132
127
|
npm run build
|
|
@@ -134,10 +129,22 @@ npm run build
|
|
|
134
129
|
|
|
135
130
|
### Important caveats
|
|
136
131
|
|
|
137
|
-
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
- Register the plugin **exactly once** per project. Plugin arrays **merge**
|
|
133
|
+
across config files (global `opencode.jsonc`, project `./opencode.jsonc`,
|
|
134
|
+
`./.opencode/opencode.json[c]`), so a second entry in another file —
|
|
135
|
+
even one pointing at a different path of the same repo such as `dist/`
|
|
136
|
+
— loads the same plugin ID twice and the duplicate fails with
|
|
137
|
+
`Duplicate plugin ID: opencode-dev-framework` (check
|
|
138
|
+
`opencode api get "/api/plugin?location[directory]=/path/to/project"`).
|
|
139
|
+
If a session loads an unexpected plugin source, check all three locations.
|
|
140
|
+
- Do **not** point the entry at `dist/` directly: a bare directory without
|
|
141
|
+
`package.json`/`exports` resolves only the server part, so the TUI
|
|
142
|
+
commands (`/df-status`, `/df-help`) never load. (On OpenCode `v2.0.x` the
|
|
143
|
+
entrypoint resolved as `<dir>/index.js` and ignored `package.json`, which
|
|
144
|
+
is why older revisions of this section recommended `dist/` — verified on
|
|
145
|
+
`v2.2.0` that the root path resolves correctly through `exports`. The
|
|
146
|
+
`.opencode/tui.json` listing from that era is likewise no longer needed:
|
|
147
|
+
one `plugins` entry loads every part.)
|
|
141
148
|
- OpenCode caches downloaded plugins in
|
|
142
149
|
`~/.cache/opencode/packages/opencode-dev-framework*/`. If you previously
|
|
143
150
|
loaded a published version and then switch to a local source, clear that
|
|
@@ -160,7 +167,7 @@ commands:
|
|
|
160
167
|
typecheck: "go build ./..."
|
|
161
168
|
test: "go test ./..."
|
|
162
169
|
lint:
|
|
163
|
-
".go": "golangci-lint run {
|
|
170
|
+
".go": "golangci-lint run {dir}"
|
|
164
171
|
|
|
165
172
|
protect:
|
|
166
173
|
- ".env*"
|
|
@@ -205,12 +212,16 @@ complete example.
|
|
|
205
212
|
|
|
206
213
|
## Slash commands
|
|
207
214
|
|
|
208
|
-
All
|
|
215
|
+
All five slash commands are **TUI commands** registered by the bundled `./tui`
|
|
209
216
|
companion module (see *Local development* above for the `tui.json` requirement).
|
|
210
217
|
They open instantly and **never** feed text back to the LLM:
|
|
211
218
|
|
|
212
219
|
- `/df-status` — shows the current profile, guardrails, completion gate, and
|
|
213
220
|
configured commands in a modal dialog.
|
|
221
|
+
- `/df-runtime` — shows the plugin version and live hook/gate runtime state
|
|
222
|
+
(which idle-hook method the core accepted, dispatch history) in a modal
|
|
223
|
+
dialog. Read from a snapshot the server writes per project; reports
|
|
224
|
+
"not reported yet" before the first session instead of guessing.
|
|
214
225
|
- `/df-help` — lists the available dev-framework commands in a modal dialog.
|
|
215
226
|
- `/df-profile` — opens a profile picker (off / advisory / standard / strict) in
|
|
216
227
|
a modal dialog; selecting one switches the active profile immediately (written
|
|
@@ -227,24 +238,29 @@ itself).
|
|
|
227
238
|
|
|
228
239
|
## Limitations
|
|
229
240
|
|
|
230
|
-
- **Post-flight enforcement
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
241
|
+
- **Post-flight enforcement is a same-execution continuation, not a veto.**
|
|
242
|
+
At the would-go-idle boundary the `experimental.idle` hook (landed via
|
|
243
|
+
[`anomalyco/opencode#59437`](https://github.com/anomalyco/opencode/pull/59437))
|
|
244
|
+
runs the gate, and on failure inside `gate.max_blocks` admits a synthetic
|
|
245
|
+
continuation in the same execution. The `event.subscribe` idle net covers
|
|
246
|
+
the boundaries the hook skips (interruption, failure, steer-parked drains),
|
|
247
|
+
deduped so one boundary never runs the gate twice. On builds without the
|
|
248
|
+
hook only the net applies. `/df-status` shows which lever completed an
|
|
249
|
+
evaluation (`Continuation (idle): active` vs the event-subscribe fallback).
|
|
250
|
+
The user can always close the session, so treat the gate
|
|
251
|
+
as the strongest available enforcement, not an unbreakable lock. The missing piece — a pre-terminal vote hook — is proposed upstream ([`anomalyco/opencode#54487`](https://github.com/anomalyco/opencode/pull/54487), open); until it lands, the above is the enforcement story. The **pre-flight**
|
|
239
252
|
gate, by contrast, is a genuine hard block on every build: it denies edit tools in
|
|
240
253
|
`tool.execute.before`, before the edit lands.
|
|
241
254
|
- **Guardrails run inside OpenCode.** The `tool.execute.before` hook runs
|
|
242
255
|
after OpenCode's own permission system; it adds project rules on top, it
|
|
243
256
|
does not replace OpenCode permissions.
|
|
244
257
|
- **Formatting and linting are delegated.** The plugin does not reimplement
|
|
245
|
-
formatters or linters; you declare your
|
|
258
|
+
formatters or linters; you declare your linter commands in
|
|
246
259
|
`.opencode-dev-framework.yml` and the plugin runs them on edited files and
|
|
247
|
-
at the completion gate.
|
|
260
|
+
at the completion gate. Formatting is OpenCode core's job (`formatter` in
|
|
261
|
+
`opencode.json`, off by default) — the plugin's `commands.format` /
|
|
262
|
+
`on_edit.format` are accepted but ignored, deliberately not duplicated.
|
|
263
|
+
The plugin does not automatically rewrite `opencode.json`
|
|
248
264
|
formatter/permission fragments.
|
|
249
265
|
|
|
250
266
|
## Development
|
package/dist/block-store.d.ts
CHANGED
|
@@ -9,27 +9,21 @@
|
|
|
9
9
|
* a broken storage backend degrades to pre-Phase-23 behavior instead of
|
|
10
10
|
* breaking the gate.
|
|
11
11
|
*
|
|
12
|
-
* Stored values are only block counts (`number`)
|
|
13
|
-
*
|
|
14
|
-
* hook; pre-Phase-27 `true` reads back as the legacy level).
|
|
15
|
-
* Never store secrets, prompts, or file contents here.
|
|
12
|
+
* Stored values are only block counts (`number`). Never store secrets,
|
|
13
|
+
* prompts, or file contents here.
|
|
16
14
|
*
|
|
17
15
|
* Key namespacing: counts are keyed `df:blocks:<sessionID>` (OpenCode
|
|
18
16
|
* session IDs are globally unique, so this is safe even if storage is
|
|
19
|
-
* shared across projects)
|
|
17
|
+
* shared across projects).
|
|
18
|
+
*
|
|
19
|
+
* Historical note: pre-cutover builds persisted a `df:stopSupported` flag
|
|
20
|
+
* recording which stopping probe fired. The idle-first cutover removed
|
|
21
|
+
* that API; a stale key left by an older install is simply never read.
|
|
20
22
|
*/
|
|
21
23
|
import type { Context } from "@opencode/plugin/promise/plugin";
|
|
22
24
|
/** Minimal storage surface we need (subset of `Context["storage"]`). */
|
|
23
25
|
export type StorageLike = Pick<Context["storage"], "get" | "set" | "remove">;
|
|
24
26
|
export declare const BLOCK_COUNT_KEY_PREFIX = "df:blocks:";
|
|
25
|
-
export declare const STOP_SUPPORTED_KEY = "df:stopSupported";
|
|
26
|
-
/**
|
|
27
|
-
* Which pre-terminal hook fired. `stopping` is the legacy V1-shape probe
|
|
28
|
-
* (PR #44712); `experimental.stopping` is the V2 contract (single mutable
|
|
29
|
-
* event, `decision` grant). The new hook outranks the old: once it has
|
|
30
|
-
* fired, the level never downgrades back to the legacy probe.
|
|
31
|
-
*/
|
|
32
|
-
export type StopHookKind = "stopping" | "experimental.stopping";
|
|
33
27
|
export interface BlockStore {
|
|
34
28
|
get(sessionID: string): Promise<number>;
|
|
35
29
|
/** Read, add one, persist, and return the new count. */
|
|
@@ -37,16 +31,6 @@ export interface BlockStore {
|
|
|
37
31
|
clear(sessionID: string): Promise<void>;
|
|
38
32
|
/** Live entries (mirrors the L1 map; used by tests). */
|
|
39
33
|
readonly size: number;
|
|
40
|
-
getStopSupported(): Promise<boolean>;
|
|
41
|
-
/**
|
|
42
|
-
* Record that a stopping hook fired. Defaults to the legacy `stopping`
|
|
43
|
-
* probe (preserves pre-Phase-27 call sites); pass
|
|
44
|
-
* `"experimental.stopping"` for the V2 hook. Monotonic: a stored new-hook
|
|
45
|
-
* level is never downgraded by a later legacy-probe call.
|
|
46
|
-
*/
|
|
47
|
-
setStopSupported(kind?: StopHookKind): Promise<void>;
|
|
48
|
-
/** Which hook fired, or null when neither has (legacy `true` reads as the old probe). */
|
|
49
|
-
getStopKind(): Promise<StopHookKind | null>;
|
|
50
34
|
/** True once any storage call has failed (in-memory fallback in use). */
|
|
51
35
|
isDegraded(): boolean;
|
|
52
36
|
}
|
package/dist/block-store.js
CHANGED
|
@@ -9,39 +9,21 @@
|
|
|
9
9
|
* a broken storage backend degrades to pre-Phase-23 behavior instead of
|
|
10
10
|
* breaking the gate.
|
|
11
11
|
*
|
|
12
|
-
* Stored values are only block counts (`number`)
|
|
13
|
-
*
|
|
14
|
-
* hook; pre-Phase-27 `true` reads back as the legacy level).
|
|
15
|
-
* Never store secrets, prompts, or file contents here.
|
|
12
|
+
* Stored values are only block counts (`number`). Never store secrets,
|
|
13
|
+
* prompts, or file contents here.
|
|
16
14
|
*
|
|
17
15
|
* Key namespacing: counts are keyed `df:blocks:<sessionID>` (OpenCode
|
|
18
16
|
* session IDs are globally unique, so this is safe even if storage is
|
|
19
|
-
* shared across projects)
|
|
17
|
+
* shared across projects).
|
|
18
|
+
*
|
|
19
|
+
* Historical note: pre-cutover builds persisted a `df:stopSupported` flag
|
|
20
|
+
* recording which stopping probe fired. The idle-first cutover removed
|
|
21
|
+
* that API; a stale key left by an older install is simply never read.
|
|
20
22
|
*/
|
|
21
23
|
export const BLOCK_COUNT_KEY_PREFIX = "df:blocks:";
|
|
22
|
-
export const STOP_SUPPORTED_KEY = "df:stopSupported";
|
|
23
24
|
function blockKey(sessionID) {
|
|
24
25
|
return `${BLOCK_COUNT_KEY_PREFIX}${sessionID}`;
|
|
25
26
|
}
|
|
26
|
-
function asStopKind(value) {
|
|
27
|
-
if (value === "experimental.stopping")
|
|
28
|
-
return "experimental.stopping";
|
|
29
|
-
// Legacy boolean flag (pre-Phase-27) means the old probe fired.
|
|
30
|
-
if (value === true || value === "stopping")
|
|
31
|
-
return "stopping";
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
function stopKindRank(kind) {
|
|
35
|
-
return kind === "experimental.stopping" ? 1 : 0;
|
|
36
|
-
}
|
|
37
|
-
/** Monotonic max: a third hook level later only touches this function. */
|
|
38
|
-
function maxStopKind(current, next) {
|
|
39
|
-
if (current === null)
|
|
40
|
-
return next;
|
|
41
|
-
if (next === null)
|
|
42
|
-
return current;
|
|
43
|
-
return stopKindRank(next) > stopKindRank(current) ? next : current;
|
|
44
|
-
}
|
|
45
27
|
/** Accept only sane counts; anything else (foreign/corrupt value) is treated as missing. */
|
|
46
28
|
function asCount(value) {
|
|
47
29
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
@@ -50,7 +32,6 @@ function asCount(value) {
|
|
|
50
32
|
}
|
|
51
33
|
export function createBlockStore(storage, memory) {
|
|
52
34
|
const counts = memory ?? new Map();
|
|
53
|
-
let stopMemory = null;
|
|
54
35
|
let degraded = false;
|
|
55
36
|
async function readCount(sessionID) {
|
|
56
37
|
if (storage == null)
|
|
@@ -68,19 +49,6 @@ export function createBlockStore(storage, memory) {
|
|
|
68
49
|
return counts.get(sessionID) ?? 0;
|
|
69
50
|
}
|
|
70
51
|
}
|
|
71
|
-
async function readStopKind() {
|
|
72
|
-
// Single read-through: memory holds a level, but storage may hold a
|
|
73
|
-
// higher one written by a newer setup sharing the backend — take the max.
|
|
74
|
-
if (storage != null) {
|
|
75
|
-
try {
|
|
76
|
-
stopMemory = maxStopKind(stopMemory, asStopKind(await storage.get(STOP_SUPPORTED_KEY)));
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
degraded = true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return stopMemory;
|
|
83
|
-
}
|
|
84
52
|
async function writeCount(sessionID, count) {
|
|
85
53
|
counts.set(sessionID, count);
|
|
86
54
|
if (storage == null)
|
|
@@ -115,28 +83,6 @@ export function createBlockStore(storage, memory) {
|
|
|
115
83
|
get size() {
|
|
116
84
|
return counts.size;
|
|
117
85
|
},
|
|
118
|
-
async getStopSupported() {
|
|
119
|
-
return (await readStopKind()) !== null;
|
|
120
|
-
},
|
|
121
|
-
getStopKind() {
|
|
122
|
-
return readStopKind();
|
|
123
|
-
},
|
|
124
|
-
async setStopSupported(kind = "stopping") {
|
|
125
|
-
// Monotonic: never downgrade a recorded new-hook level. The storage
|
|
126
|
-
// read is required, not redundant — without it a fresh process would
|
|
127
|
-
// blind-write its own (possibly lower) level over a stored higher one.
|
|
128
|
-
stopMemory = maxStopKind(stopMemory, kind) ?? kind;
|
|
129
|
-
if (storage == null)
|
|
130
|
-
return;
|
|
131
|
-
try {
|
|
132
|
-
const next = maxStopKind(asStopKind(await storage.get(STOP_SUPPORTED_KEY)), stopMemory) ?? kind;
|
|
133
|
-
stopMemory = next;
|
|
134
|
-
await storage.set(STOP_SUPPORTED_KEY, next);
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
degraded = true;
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
86
|
isDegraded() {
|
|
141
87
|
return degraded;
|
|
142
88
|
},
|
package/dist/detect.js
CHANGED
|
@@ -81,7 +81,7 @@ export function detectProject(directory) {
|
|
|
81
81
|
result.commands.test = "go test ./...";
|
|
82
82
|
result.commands.typecheck = "go build ./...";
|
|
83
83
|
result.commands.format = "gofumpt -w {file}";
|
|
84
|
-
result.commands.lint = "golangci-lint run {
|
|
84
|
+
result.commands.lint = "golangci-lint run {dir}";
|
|
85
85
|
return result;
|
|
86
86
|
}
|
|
87
87
|
if (has.pyProject || has.requirements) {
|
package/dist/format-status.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HookState } from "./registry.js";
|
|
2
|
+
import type { RuntimeStatus } from "./runtime-status.js";
|
|
2
3
|
import type { ResolvedConfig } from "./types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Render the config-only portion of the status summary.
|
|
@@ -18,3 +19,10 @@ export declare function renderHelp(): string;
|
|
|
18
19
|
* slash-command handler.
|
|
19
20
|
*/
|
|
20
21
|
export declare function renderStatus(config: ResolvedConfig, state?: HookState | null): string;
|
|
22
|
+
/**
|
|
23
|
+
* Render the runtime snapshot for the TUI `/df-runtime` command: plugin
|
|
24
|
+
* version, which session-hook method the core accepted, and dispatch
|
|
25
|
+
* history. A null snapshot (server hasn't reported yet) renders as such —
|
|
26
|
+
* never as a negative claim about the hook.
|
|
27
|
+
*/
|
|
28
|
+
export declare function renderRuntimeStatus(snapshot: RuntimeStatus | null): string;
|
package/dist/format-status.js
CHANGED
|
@@ -54,7 +54,7 @@ export function renderConfigStatus(config) {
|
|
|
54
54
|
}
|
|
55
55
|
lines.push("");
|
|
56
56
|
lines.push("On edit:");
|
|
57
|
-
lines.push(` format: ${config.on_edit.format}`);
|
|
57
|
+
lines.push(` format: ${config.on_edit.format} (ignored — formatting is OpenCode core's job)`);
|
|
58
58
|
lines.push(` lint: ${config.on_edit.lint}`);
|
|
59
59
|
lines.push(` precommit: ${config.precommit}`);
|
|
60
60
|
lines.push("");
|
|
@@ -90,7 +90,7 @@ export function renderConfigStatus(config) {
|
|
|
90
90
|
lines.push(config.commands.test_changed ? ` ${config.commands.test_changed}` : " (not configured)");
|
|
91
91
|
lines.push(" lint:");
|
|
92
92
|
lines.push(formatCommandMap(config.commands.lint, " "));
|
|
93
|
-
lines.push(" format:");
|
|
93
|
+
lines.push(" format: (ignored — formatting is OpenCode core's job)");
|
|
94
94
|
lines.push(formatCommandMap(config.commands.format, " "));
|
|
95
95
|
lines.push("");
|
|
96
96
|
lines.push("Constitution rules:");
|
|
@@ -111,6 +111,7 @@ export function renderHelp() {
|
|
|
111
111
|
lines.push("/df-profile Change the profile to off, advisory, standard, or strict");
|
|
112
112
|
lines.push("/df-verify Run the completion gate manually");
|
|
113
113
|
lines.push("/df-help Show this message");
|
|
114
|
+
lines.push("/df-runtime Show plugin version and live hook/gate runtime state");
|
|
114
115
|
return lines.join("\n");
|
|
115
116
|
}
|
|
116
117
|
/**
|
|
@@ -122,19 +123,15 @@ export function renderHelp() {
|
|
|
122
123
|
export function renderStatus(config, state) {
|
|
123
124
|
const lines = [renderConfigStatus(config)];
|
|
124
125
|
if (state) {
|
|
125
|
-
// Enforcement level:
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
// hook has fired, a late legacy dispatch never downgrades the level.
|
|
126
|
+
// Enforcement level: the `experimental.idle` hook (same-execution
|
|
127
|
+
// synthetic continuation) once it has completed an evaluation, else
|
|
128
|
+
// the `event.subscribe` idle re-prompt net.
|
|
129
129
|
lines.push("");
|
|
130
|
-
if (
|
|
131
|
-
lines.push(`
|
|
132
|
-
}
|
|
133
|
-
else if (state.stopHookKind === "experimental.stopping") {
|
|
134
|
-
lines.push(`Hard stop (experimental.stopping): active — gate failures continue the turn with steer text`);
|
|
130
|
+
if (state.continuationLevel === "idle") {
|
|
131
|
+
lines.push(`Continuation (idle): active — gate failures continue the same execution via synthetic`);
|
|
135
132
|
}
|
|
136
133
|
else {
|
|
137
|
-
lines.push(`
|
|
134
|
+
lines.push(`Continuation (idle): not dispatched — event-subscribe fallback`);
|
|
138
135
|
}
|
|
139
136
|
if (config.precommit === "auto") {
|
|
140
137
|
lines.push(` pre-commit binary available: ${state.precommitAvailable === true ? "yes" : state.precommitAvailable === false ? "no" : "not checked yet"}`);
|
|
@@ -157,3 +154,31 @@ export function renderStatus(config, state) {
|
|
|
157
154
|
}
|
|
158
155
|
return lines.join("\n");
|
|
159
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Render the runtime snapshot for the TUI `/df-runtime` command: plugin
|
|
159
|
+
* version, which session-hook method the core accepted, and dispatch
|
|
160
|
+
* history. A null snapshot (server hasn't reported yet) renders as such —
|
|
161
|
+
* never as a negative claim about the hook.
|
|
162
|
+
*/
|
|
163
|
+
export function renderRuntimeStatus(snapshot) {
|
|
164
|
+
const lines = ["dev-framework runtime", ""];
|
|
165
|
+
if (snapshot === null) {
|
|
166
|
+
lines.push("No runtime snapshot reported yet — open a session in this");
|
|
167
|
+
lines.push("project so the server plugin can record hook state.");
|
|
168
|
+
return lines.join("\n");
|
|
169
|
+
}
|
|
170
|
+
lines.push(`Framework: v${snapshot.frameworkVersion} (snapshot as of ${snapshot.updatedAt})`);
|
|
171
|
+
lines.push(snapshot.idleHookVia === "none"
|
|
172
|
+
? "Idle hook: not registered — event-subscribe fallback only"
|
|
173
|
+
: `Idle hook: registered via ${snapshot.idleHookVia}`);
|
|
174
|
+
if (snapshot.continuation === "idle") {
|
|
175
|
+
lines.push("Continuation: active — gate failures continue the same execution");
|
|
176
|
+
}
|
|
177
|
+
else if (snapshot.continuation === "fallback") {
|
|
178
|
+
lines.push("Continuation: event-subscribe fallback fired for a skipped boundary");
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
lines.push("Continuation: armed — registered, not yet dispatched");
|
|
182
|
+
}
|
|
183
|
+
return lines.join("\n");
|
|
184
|
+
}
|
package/dist/gate.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Completion gate: run typecheck / test / lint-changed commands when the
|
|
3
|
-
* session
|
|
3
|
+
* session goes idle, plus the changed-file tracking that feeds it.
|
|
4
4
|
*
|
|
5
5
|
* The gate runs from two call sites:
|
|
6
|
-
* - `
|
|
7
|
-
*
|
|
8
|
-
* - `session.idle`
|
|
9
|
-
*
|
|
6
|
+
* - `experimental.idle` hook: same-execution synthetic continuation on
|
|
7
|
+
* failure, up to `gate.max_blocks`.
|
|
8
|
+
* - `session.idle` event net: re-prompt fallback for the boundaries the
|
|
9
|
+
* hook skips.
|
|
10
10
|
*/
|
|
11
11
|
import type { CommandResult, RunCommand } from "./host.js";
|
|
12
12
|
import type { ResolvedConfig } from "./types.js";
|
package/dist/gate.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Completion gate: run typecheck / test / lint-changed commands when the
|
|
3
|
-
* session
|
|
3
|
+
* session goes idle, plus the changed-file tracking that feeds it.
|
|
4
4
|
*
|
|
5
5
|
* The gate runs from two call sites:
|
|
6
|
-
* - `
|
|
7
|
-
*
|
|
8
|
-
* - `session.idle`
|
|
9
|
-
*
|
|
6
|
+
* - `experimental.idle` hook: same-execution synthetic continuation on
|
|
7
|
+
* failure, up to `gate.max_blocks`.
|
|
8
|
+
* - `session.idle` event net: re-prompt fallback for the boundaries the
|
|
9
|
+
* hook skips.
|
|
10
10
|
*/
|
|
11
11
|
import { isAbsolute, relative } from "node:path";
|
|
12
12
|
import { splitCommand } from "./command-utils.js";
|
package/dist/harness.d.ts
CHANGED
|
@@ -8,15 +8,13 @@
|
|
|
8
8
|
* configured, edit tools are denied (standard/strict) until the agent has
|
|
9
9
|
* written the pre-flight artifact. This is a true hard gate: it runs in
|
|
10
10
|
* `tool.execute.before`, before the edit lands. This is the only fully hard
|
|
11
|
-
* enforcement
|
|
12
|
-
* hook.
|
|
11
|
+
* enforcement — the idle continuation can only steer, never deny.
|
|
13
12
|
* - **Post-flight**: the completion verdict runner. It unions event-tracked
|
|
14
13
|
* changed files with `git status --porcelain` (robust against event-shape
|
|
15
14
|
* mismatches), runs the command gate, and — when `gate.require_review` is
|
|
16
15
|
* set — requires a peer-review artifact for sessions that changed files.
|
|
17
|
-
* The verdict is consumed by
|
|
18
|
-
*
|
|
19
|
-
* (re-prompt).
|
|
16
|
+
* The verdict is consumed by the `experimental.idle` hook (same-execution
|
|
17
|
+
* synthetic continuation) and the `session.idle` event net (re-prompt).
|
|
20
18
|
*/
|
|
21
19
|
import type { BlockStore } from "./block-store.js";
|
|
22
20
|
import { type ChangedFileTracker } from "./gate.js";
|
|
@@ -84,8 +82,8 @@ export interface CompletionDeps {
|
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
84
|
* Evaluate the completion gate + review requirement and update block state.
|
|
87
|
-
* Pure orchestration: both the `
|
|
88
|
-
*
|
|
89
|
-
* either
|
|
85
|
+
* Pure orchestration: both the `experimental.idle` hook and the
|
|
86
|
+
* `session.idle` event net feed their outcome from here so one session's
|
|
87
|
+
* block count applies to either lever.
|
|
90
88
|
*/
|
|
91
89
|
export declare function evaluateCompletion(deps: CompletionDeps): Promise<CompletionVerdict>;
|
package/dist/harness.js
CHANGED
|
@@ -8,15 +8,13 @@
|
|
|
8
8
|
* configured, edit tools are denied (standard/strict) until the agent has
|
|
9
9
|
* written the pre-flight artifact. This is a true hard gate: it runs in
|
|
10
10
|
* `tool.execute.before`, before the edit lands. This is the only fully hard
|
|
11
|
-
* enforcement
|
|
12
|
-
* hook.
|
|
11
|
+
* enforcement — the idle continuation can only steer, never deny.
|
|
13
12
|
* - **Post-flight**: the completion verdict runner. It unions event-tracked
|
|
14
13
|
* changed files with `git status --porcelain` (robust against event-shape
|
|
15
14
|
* mismatches), runs the command gate, and — when `gate.require_review` is
|
|
16
15
|
* set — requires a peer-review artifact for sessions that changed files.
|
|
17
|
-
* The verdict is consumed by
|
|
18
|
-
*
|
|
19
|
-
* (re-prompt).
|
|
16
|
+
* The verdict is consumed by the `experimental.idle` hook (same-execution
|
|
17
|
+
* synthetic continuation) and the `session.idle` event net (re-prompt).
|
|
20
18
|
*/
|
|
21
19
|
import { readFile } from "node:fs/promises";
|
|
22
20
|
import { join } from "node:path";
|
|
@@ -126,9 +124,9 @@ function reviewMissingMessage(changedFiles) {
|
|
|
126
124
|
}
|
|
127
125
|
/**
|
|
128
126
|
* Evaluate the completion gate + review requirement and update block state.
|
|
129
|
-
* Pure orchestration: both the `
|
|
130
|
-
*
|
|
131
|
-
* either
|
|
127
|
+
* Pure orchestration: both the `experimental.idle` hook and the
|
|
128
|
+
* `session.idle` event net feed their outcome from here so one session's
|
|
129
|
+
* block count applies to either lever.
|
|
132
130
|
*/
|
|
133
131
|
export async function evaluateCompletion(deps) {
|
|
134
132
|
const { run, config, directory, sessionID, tracker, blockCounts } = deps;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
* - ctx.event.subscribe() -> file tracking + gate enforcement via re-prompt
|
|
12
12
|
* - ctx.tool.transform(...) -> custom tools
|
|
13
13
|
*
|
|
14
|
-
* Gate enforcement: no synchronous
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
|
|
15
|
+
* (same execution) we run the gate and if it fails inside budget we admit
|
|
16
|
+
* `ctx.session.synthetic({ sessionID, text: stoppingMessage })` — the
|
|
17
|
+
* continuation runs before the session goes idle (see
|
|
18
|
+
* docs/plans/12-idle-hook-cutover.md). The `event.subscribe` idle net
|
|
19
|
+
* stays as a deduped fallback for the boundaries the hook skips.
|
|
18
20
|
*/
|
|
19
21
|
import { Plugin } from "@opencode/plugin";
|
|
20
|
-
import { type BlockStore
|
|
22
|
+
import { type BlockStore } from "./block-store.js";
|
|
21
23
|
import { type ChangedFileTracker } from "./gate.js";
|
|
22
24
|
import { type RunCommand } from "./host.js";
|
|
23
25
|
import { type LogFn } from "./logger.js";
|
|
@@ -43,15 +45,22 @@ export interface HookState {
|
|
|
43
45
|
precommitAvailable?: boolean;
|
|
44
46
|
configMtime?: number;
|
|
45
47
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* the
|
|
48
|
+
* Which lever completed a gate evaluation most recently in this process:
|
|
49
|
+
* `"idle"` once the `experimental.idle` hook has (same-execution
|
|
50
|
+
* continuation active), `"fallback"` when only the `event.subscribe`
|
|
51
|
+
* idle re-prompt net has. Absent until either fires. Memory-only: a
|
|
52
|
+
* reload re-derives it on the next idle boundary. `/df-status` renders
|
|
53
|
+
* the active level.
|
|
52
54
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
continuationLevel?: "idle" | "fallback";
|
|
56
|
+
/**
|
|
57
|
+
* Dedup map for the idle-first cutover: sessionID → `Date.now()` at the
|
|
58
|
+
* last COMPLETED hook evaluation (pass, blocked-admitted, and standdown
|
|
59
|
+
* all stamp; throw/early-return do not). The `event.subscribe` idle net
|
|
60
|
+
* skips when the stamp is fresh so one boundary never runs the gate
|
|
61
|
+
* twice. Memory-only; worst case on reload is one extra suite run.
|
|
62
|
+
*/
|
|
63
|
+
lastIdleHandled: Map<string, number>;
|
|
55
64
|
}
|
|
56
65
|
declare const plugin: Plugin.Plugin;
|
|
57
66
|
export default plugin;
|