opencode-dev-framework 0.3.0 → 0.4.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/README.md +15 -12
- package/dist/block-store.d.ts +19 -2
- package/dist/block-store.js +48 -21
- package/dist/format-status.js +13 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +102 -12
- package/dist/registry.d.ts +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,9 @@ reimplemented as an OpenCode-native plugin.
|
|
|
27
27
|
cadence. On failure inside `gate.max_blocks` the plugin re-prompts the session with
|
|
28
28
|
the failure summary. On OpenCode builds that dispatch the `session.stopping` hook
|
|
29
29
|
(PR #44712) the same verdict vetoes loop exit *before* the agent stops — a true hard
|
|
30
|
-
stop
|
|
30
|
+
stop — and on builds with the V2 `experimental.stopping` hook the failure continues
|
|
31
|
+
the turn with steer text instead; `/df-status` shows which mode is active
|
|
32
|
+
(idle-fallback → legacy probe → new hook).
|
|
31
33
|
- **Pre-flight gate (optional).** When a `preflight:` task list is configured, edit
|
|
32
34
|
tools are **denied** (standard/strict) until the agent writes its pre-flight findings
|
|
33
35
|
to `.opencode/opencode-dev-framework/preflight.md`. Use it for work that requires
|
|
@@ -65,7 +67,7 @@ How each mechanism is enforced on OpenCode `v2` (verified on `v2.0.26`):
|
|
|
65
67
|
| Pre-flight gate | `tool.execute.before` deny | — | **Hard block** on every build: the edit never lands. |
|
|
66
68
|
| 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). |
|
|
67
69
|
| 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. |
|
|
68
|
-
| Completion gate | `session.idle` re-prompt via `session.prompt` | `session.stopping` hard-stop veto, if the core dispatches
|
|
70
|
+
| Completion gate | `session.idle` re-prompt via `session.prompt` | `session.stopping` hard-stop veto / `experimental.stopping` turn-continuation, if the core dispatches either | **Async, bounded** by `gate.max_blocks` (re-prompt, not a veto); hard stop / continuation only on builds with core support. `/df-status` shows which mode is active. |
|
|
69
71
|
|
|
70
72
|
## Install
|
|
71
73
|
|
|
@@ -73,7 +75,7 @@ How each mechanism is enforced on OpenCode `v2` (verified on `v2.0.26`):
|
|
|
73
75
|
npm install opencode-dev-framework
|
|
74
76
|
```
|
|
75
77
|
|
|
76
|
-
Then add the plugin to your project's `opencode.
|
|
78
|
+
Then add the plugin to your project's `opencode.jsonc`:
|
|
77
79
|
|
|
78
80
|
```json
|
|
79
81
|
{
|
|
@@ -104,13 +106,13 @@ profile from the shell; `df version` prints the plugin version.
|
|
|
104
106
|
## Local development and testing
|
|
105
107
|
|
|
106
108
|
To test the plugin from source without publishing to npm, point OpenCode at the
|
|
107
|
-
local repository path in your project's `opencode.
|
|
109
|
+
local repository path in your project's `opencode.jsonc` **and** in a `tui.json`.
|
|
108
110
|
The TUI module (`/df-status`, `/df-help` modals) is **not** auto-discovered for
|
|
109
111
|
local filesystem paths — it only loads when the package is listed in the TUI
|
|
110
112
|
config. OpenCode reads `tui.json` from the global config dir
|
|
111
113
|
(`~/.config/opencode/tui.json`) and the project dir (`.opencode/tui.json`).
|
|
112
114
|
|
|
113
|
-
`opencode.
|
|
115
|
+
`opencode.jsonc`:
|
|
114
116
|
|
|
115
117
|
```json
|
|
116
118
|
{
|
|
@@ -132,10 +134,10 @@ npm run build
|
|
|
132
134
|
|
|
133
135
|
### Important caveats
|
|
134
136
|
|
|
135
|
-
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
- Plugin arrays **merge** across config files (global `opencode.jsonc`,
|
|
138
|
+
project `./opencode.jsonc`, `./.opencode/opencode.jsonc`), so a stale entry
|
|
139
|
+
in another file adds to — never replaces — the registration above. If a
|
|
140
|
+
session loads an unexpected plugin source, check all three locations.
|
|
139
141
|
- OpenCode caches downloaded plugins in
|
|
140
142
|
`~/.cache/opencode/packages/opencode-dev-framework*/`. If you previously
|
|
141
143
|
loaded a published version and then switch to a local source, clear that
|
|
@@ -219,7 +221,7 @@ They open instantly and **never** feed text back to the LLM:
|
|
|
219
221
|
|
|
220
222
|
You can still run `df init` to install the bundled agents, skills, and default
|
|
221
223
|
config; the commands themselves are provided by the plugin. The
|
|
222
|
-
`
|
|
224
|
+
`dev_framework_*` custom *tools* remain
|
|
223
225
|
available for in-agent use (e.g. when the model wants to change the profile
|
|
224
226
|
itself).
|
|
225
227
|
|
|
@@ -229,8 +231,9 @@ itself).
|
|
|
229
231
|
`session.stopping` veto (PR #44712 is open; the earlier PR #41811 was never merged),
|
|
230
232
|
so on failure inside `gate.max_blocks` the plugin re-prompts via
|
|
231
233
|
`ctx.session.prompt()` from the `session.idle` event. The plugin still registers the
|
|
232
|
-
`session.stopping` hook defensively
|
|
233
|
-
|
|
234
|
+
`session.stopping` hook defensively — and the V2 `experimental.stopping` hook
|
|
235
|
+
alongside it: on builds that dispatch either, the same verdict
|
|
236
|
+
vetoes loop exit / continues the turn before the agent stops. `/df-status` shows which
|
|
234
237
|
mode is active. Until then, the user can always close the session, so treat the gate
|
|
235
238
|
as the strongest available enforcement, not an unbreakable lock. The **pre-flight**
|
|
236
239
|
gate, by contrast, is a genuine hard block on every build: it denies edit tools in
|
package/dist/block-store.d.ts
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
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`) and one
|
|
12
|
+
* Stored values are only block counts (`number`) and one stop-level flag
|
|
13
|
+
* (`"stopping"` for the legacy probe, `"experimental.stopping"` for the V2
|
|
14
|
+
* hook; pre-Phase-27 `true` reads back as the legacy level).
|
|
13
15
|
* Never store secrets, prompts, or file contents here.
|
|
14
16
|
*
|
|
15
17
|
* Key namespacing: counts are keyed `df:blocks:<sessionID>` (OpenCode
|
|
@@ -21,6 +23,13 @@ import type { Context } from "@opencode/plugin/promise/plugin";
|
|
|
21
23
|
export type StorageLike = Pick<Context["storage"], "get" | "set" | "remove">;
|
|
22
24
|
export declare const BLOCK_COUNT_KEY_PREFIX = "df:blocks:";
|
|
23
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";
|
|
24
33
|
export interface BlockStore {
|
|
25
34
|
get(sessionID: string): Promise<number>;
|
|
26
35
|
/** Read, add one, persist, and return the new count. */
|
|
@@ -29,7 +38,15 @@ export interface BlockStore {
|
|
|
29
38
|
/** Live entries (mirrors the L1 map; used by tests). */
|
|
30
39
|
readonly size: number;
|
|
31
40
|
getStopSupported(): Promise<boolean>;
|
|
32
|
-
|
|
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>;
|
|
33
50
|
/** True once any storage call has failed (in-memory fallback in use). */
|
|
34
51
|
isDegraded(): boolean;
|
|
35
52
|
}
|
package/dist/block-store.js
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
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`) and one
|
|
12
|
+
* Stored values are only block counts (`number`) and one stop-level flag
|
|
13
|
+
* (`"stopping"` for the legacy probe, `"experimental.stopping"` for the V2
|
|
14
|
+
* hook; pre-Phase-27 `true` reads back as the legacy level).
|
|
13
15
|
* Never store secrets, prompts, or file contents here.
|
|
14
16
|
*
|
|
15
17
|
* Key namespacing: counts are keyed `df:blocks:<sessionID>` (OpenCode
|
|
@@ -21,6 +23,25 @@ export const STOP_SUPPORTED_KEY = "df:stopSupported";
|
|
|
21
23
|
function blockKey(sessionID) {
|
|
22
24
|
return `${BLOCK_COUNT_KEY_PREFIX}${sessionID}`;
|
|
23
25
|
}
|
|
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
|
+
}
|
|
24
45
|
/** Accept only sane counts; anything else (foreign/corrupt value) is treated as missing. */
|
|
25
46
|
function asCount(value) {
|
|
26
47
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
@@ -29,7 +50,7 @@ function asCount(value) {
|
|
|
29
50
|
}
|
|
30
51
|
export function createBlockStore(storage, memory) {
|
|
31
52
|
const counts = memory ?? new Map();
|
|
32
|
-
let stopMemory =
|
|
53
|
+
let stopMemory = null;
|
|
33
54
|
let degraded = false;
|
|
34
55
|
async function readCount(sessionID) {
|
|
35
56
|
if (storage == null)
|
|
@@ -47,6 +68,19 @@ export function createBlockStore(storage, memory) {
|
|
|
47
68
|
return counts.get(sessionID) ?? 0;
|
|
48
69
|
}
|
|
49
70
|
}
|
|
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
|
+
}
|
|
50
84
|
async function writeCount(sessionID, count) {
|
|
51
85
|
counts.set(sessionID, count);
|
|
52
86
|
if (storage == null)
|
|
@@ -82,29 +116,22 @@ export function createBlockStore(storage, memory) {
|
|
|
82
116
|
return counts.size;
|
|
83
117
|
},
|
|
84
118
|
async getStopSupported() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const stored = await storage.get(STOP_SUPPORTED_KEY);
|
|
91
|
-
if (stored === true) {
|
|
92
|
-
stopMemory = true;
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
degraded = true;
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
119
|
+
return (await readStopKind()) !== null;
|
|
120
|
+
},
|
|
121
|
+
getStopKind() {
|
|
122
|
+
return readStopKind();
|
|
101
123
|
},
|
|
102
|
-
async setStopSupported() {
|
|
103
|
-
|
|
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;
|
|
104
129
|
if (storage == null)
|
|
105
130
|
return;
|
|
106
131
|
try {
|
|
107
|
-
await storage.
|
|
132
|
+
const next = maxStopKind(asStopKind(await storage.get(STOP_SUPPORTED_KEY)), stopMemory) ?? kind;
|
|
133
|
+
stopMemory = next;
|
|
134
|
+
await storage.set(STOP_SUPPORTED_KEY, next);
|
|
108
135
|
}
|
|
109
136
|
catch {
|
|
110
137
|
degraded = true;
|
package/dist/format-status.js
CHANGED
|
@@ -122,8 +122,20 @@ export function renderHelp() {
|
|
|
122
122
|
export function renderStatus(config, state) {
|
|
123
123
|
const lines = [renderConfigStatus(config)];
|
|
124
124
|
if (state) {
|
|
125
|
+
// Enforcement level: none (no live state — config-only rendering) →
|
|
126
|
+
// idle-fallback (no hook dispatched yet) → legacy `stopping` probe →
|
|
127
|
+
// V2 `experimental.stopping` hook. The kind is monotonic: once the new
|
|
128
|
+
// hook has fired, a late legacy dispatch never downgrades the level.
|
|
125
129
|
lines.push("");
|
|
126
|
-
|
|
130
|
+
if (!state.stopHookSupported) {
|
|
131
|
+
lines.push(`Hard stop (stopping / experimental.stopping): not dispatched by this OpenCode build — idle re-prompt fallback`);
|
|
132
|
+
}
|
|
133
|
+
else if (state.stopHookKind === "experimental.stopping") {
|
|
134
|
+
lines.push(`Hard stop (experimental.stopping): active — gate failures continue the turn with steer text`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
lines.push(`Hard stop (stopping): active — gate vetoes loop exit (legacy probe)`);
|
|
138
|
+
}
|
|
127
139
|
if (config.precommit === "auto") {
|
|
128
140
|
lines.push(` pre-commit binary available: ${state.precommitAvailable === true ? "yes" : state.precommitAvailable === false ? "no" : "not checked yet"}`);
|
|
129
141
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* agent — async re-injection preserving the enforcement intent (see docs/plans/08-notes).
|
|
18
18
|
*/
|
|
19
19
|
import { Plugin } from "@opencode/plugin";
|
|
20
|
-
import { type BlockStore } from "./block-store.js";
|
|
20
|
+
import { type BlockStore, type StopHookKind } from "./block-store.js";
|
|
21
21
|
import { type ChangedFileTracker } from "./gate.js";
|
|
22
22
|
import { type RunCommand } from "./host.js";
|
|
23
23
|
import { type LogFn } from "./logger.js";
|
|
@@ -43,11 +43,15 @@ export interface HookState {
|
|
|
43
43
|
precommitAvailable?: boolean;
|
|
44
44
|
configMtime?: number;
|
|
45
45
|
/**
|
|
46
|
-
* Set once
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* Set once a stopping hook has actually been invoked by core — i.e. this
|
|
47
|
+
* OpenCode build supports pre-break gate vetoes (hard stops). Until then
|
|
48
|
+
* the idle re-prompt fallback is the only post-flight lever.
|
|
49
|
+
* `stopHookKind` records WHICH hook fired (`stopping` legacy probe vs
|
|
50
|
+
* `experimental.stopping` V2 contract); the new hook outranks the old and
|
|
51
|
+
* the level never downgrades. `/df-status` renders the active level.
|
|
49
52
|
*/
|
|
50
53
|
stopHookSupported?: boolean;
|
|
54
|
+
stopHookKind?: StopHookKind;
|
|
51
55
|
}
|
|
52
56
|
declare const plugin: Plugin.Plugin;
|
|
53
57
|
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -71,9 +71,10 @@ async function reloadConfigIfChanged(state) {
|
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Turn a completion verdict into the continuation message fed back to the
|
|
74
|
-
* agent when blocked. Shared by the `session.stopping` hard-stop path
|
|
75
|
-
*
|
|
76
|
-
*
|
|
74
|
+
* agent when blocked. Shared by the `session.stopping` hard-stop path, the
|
|
75
|
+
* `experimental.stopping` continuation vote, and the `session.idle`
|
|
76
|
+
* re-prompt fallback so wording (and block counting) is identical on every
|
|
77
|
+
* core support level.
|
|
77
78
|
*/
|
|
78
79
|
function continuationMessage(verdict) {
|
|
79
80
|
const why = verdict.reason === "review"
|
|
@@ -146,6 +147,19 @@ function runCompletion(state, sessionID) {
|
|
|
146
147
|
log: (level, message, extra) => safeLog(state, level, message, extra),
|
|
147
148
|
});
|
|
148
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Record that a stopping hook fired at `kind`. Monotonic: the V2
|
|
152
|
+
* `experimental.stopping` level outranks the legacy `stopping` probe, so a
|
|
153
|
+
* late legacy dispatch never downgrades an already-recorded new-hook level
|
|
154
|
+
* (both the in-memory flag and the persisted store upgrade only).
|
|
155
|
+
*/
|
|
156
|
+
async function recordStopLevel(state, kind) {
|
|
157
|
+
if (state.stopHookKind !== "experimental.stopping") {
|
|
158
|
+
state.stopHookKind = kind;
|
|
159
|
+
}
|
|
160
|
+
state.stopHookSupported = true;
|
|
161
|
+
await state.blocks.setStopSupported(kind);
|
|
162
|
+
}
|
|
149
163
|
// Helpers to normalize V2 event shapes (data vs properties vs direct)
|
|
150
164
|
function getEventSessionID(event) {
|
|
151
165
|
const e = event;
|
|
@@ -247,10 +261,12 @@ const plugin = Plugin.define({
|
|
|
247
261
|
configMtime,
|
|
248
262
|
};
|
|
249
263
|
activeState = state;
|
|
250
|
-
// Hydrate the hard-stop probe
|
|
251
|
-
// dispatch `
|
|
252
|
-
// counts (pre-Phase-23 behavior) and is logged,
|
|
253
|
-
|
|
264
|
+
// Hydrate the hard-stop probe level: a previous setup may have seen core
|
|
265
|
+
// dispatch `stopping` or `experimental.stopping`. A storage failure
|
|
266
|
+
// degrades to in-memory counts (pre-Phase-23 behavior) and is logged,
|
|
267
|
+
// never thrown.
|
|
268
|
+
state.stopHookKind = (await blocks.getStopKind()) ?? undefined;
|
|
269
|
+
state.stopHookSupported = state.stopHookKind !== undefined;
|
|
254
270
|
if (blocks.isDegraded()) {
|
|
255
271
|
await log("warn", "ctx.storage is unavailable; gate block counts are in-memory only and reset on reload", { directory });
|
|
256
272
|
}
|
|
@@ -317,9 +333,10 @@ const plugin = Plugin.define({
|
|
|
317
333
|
// The first invocation flips `stopHookSupported` so /df-status can show
|
|
318
334
|
// which enforcement level is active.
|
|
319
335
|
// DEFENSIVE: "stopping" is not in SessionHooks as of 2.0.x; fires only
|
|
320
|
-
// if a future core dispatches it (see PR #44712).
|
|
321
|
-
//
|
|
322
|
-
// compiler guards future SDK
|
|
336
|
+
// if a future core dispatches it (see PR #44712). One of two any-casts
|
|
337
|
+
// in src/ (this probe + the `experimental.stopping` probe in §1c) —
|
|
338
|
+
// all other hooks are fully typed so the compiler guards future SDK
|
|
339
|
+
// upgrades.
|
|
323
340
|
try {
|
|
324
341
|
trackRegistration(
|
|
325
342
|
// biome-ignore lint/suspicious/noExplicitAny: defensive stopping probe, not in SessionHooks (PR #44712)
|
|
@@ -333,8 +350,7 @@ const plugin = Plugin.define({
|
|
|
333
350
|
out.sessionID ??
|
|
334
351
|
getEventSessionID(input) ??
|
|
335
352
|
"unknown";
|
|
336
|
-
state
|
|
337
|
-
await state.blocks.setStopSupported();
|
|
353
|
+
await recordStopLevel(state, "stopping");
|
|
338
354
|
await reloadConfigIfChanged(state);
|
|
339
355
|
if (state.config.profile === "off")
|
|
340
356
|
return;
|
|
@@ -350,6 +366,80 @@ const plugin = Plugin.define({
|
|
|
350
366
|
catch {
|
|
351
367
|
await safeLog(state, "warn", "could not register session.stopping hook; using session.idle re-prompt fallback only");
|
|
352
368
|
}
|
|
369
|
+
// 1c) V2 pre-terminal continuation vote — `experimental.stopping`.
|
|
370
|
+
// Same verdict mapping as §1b, in the new contract shape: gate fail →
|
|
371
|
+
// `decision = { shouldContinue: true, text: message }` (core admits it
|
|
372
|
+
// as a synthetic steer and continues the turn); gate pass/stand-down →
|
|
373
|
+
// leave the fail-closed default (abstain). Registered ALONGSIDE the
|
|
374
|
+
// legacy probe, not replacing it — the same dist keeps working on
|
|
375
|
+
// mainline builds that lack the new core. No provider scoping: the
|
|
376
|
+
// event carries no model, so a providerID option would never fire.
|
|
377
|
+
// `event.continuations` is the pre-increment grant count (core caps at
|
|
378
|
+
// 2 and goes silent past it without calling voters); local policy stays
|
|
379
|
+
// tighter-or-equal via the verdict runner's own max_blocks/stand-down,
|
|
380
|
+
// never fighting the core cap — expect silence after 2 grants.
|
|
381
|
+
// DEFENSIVE: "experimental.stopping" is not in SessionHooks on released
|
|
382
|
+
// cores; fires only on builds dispatching it. Same any-cast pattern as
|
|
383
|
+
// §1b (the only two in src/).
|
|
384
|
+
try {
|
|
385
|
+
trackRegistration(
|
|
386
|
+
// biome-ignore lint/suspicious/noExplicitAny: defensive stopping probe, not in SessionHooks on released cores
|
|
387
|
+
await ctx.session.hook("experimental.stopping",
|
|
388
|
+
// biome-ignore lint/suspicious/noExplicitAny: core dispatches a single mutable event
|
|
389
|
+
async (event) => {
|
|
390
|
+
if (activeState !== state)
|
|
391
|
+
return;
|
|
392
|
+
// Core always dispatches a single mutable event object; a
|
|
393
|
+
// non-object would leave the grant with nowhere to land, so bail
|
|
394
|
+
// (fail-closed is the core's job on malformed dispatch).
|
|
395
|
+
if (event === null || typeof event !== "object")
|
|
396
|
+
return;
|
|
397
|
+
const vote = event;
|
|
398
|
+
const sessionID = (typeof vote.sessionID === "string" && vote.sessionID) ||
|
|
399
|
+
getEventSessionID(event) ||
|
|
400
|
+
"unknown";
|
|
401
|
+
// Never let a voter failure escape into core: on any error
|
|
402
|
+
// abstain (leave the fail-closed default) instead of losing the
|
|
403
|
+
// turn to an undefined core reaction. A throwing voter stops the
|
|
404
|
+
// turn per the contract — that decision belongs to core, not to
|
|
405
|
+
// a logging or gate-backend failure inside this probe.
|
|
406
|
+
try {
|
|
407
|
+
await recordStopLevel(state, "experimental.stopping");
|
|
408
|
+
await reloadConfigIfChanged(state);
|
|
409
|
+
if (state.config.profile === "off")
|
|
410
|
+
return;
|
|
411
|
+
const verdict = await runCompletion(state, sessionID);
|
|
412
|
+
const message = await actOnVerdict(state, verdict);
|
|
413
|
+
await safeLog(state, "info", "experimental.stopping vote", {
|
|
414
|
+
sessionID,
|
|
415
|
+
step: vote.step,
|
|
416
|
+
continuations: vote.continuations,
|
|
417
|
+
decision: verdict.decision,
|
|
418
|
+
});
|
|
419
|
+
if (message !== null) {
|
|
420
|
+
event.decision = {
|
|
421
|
+
shouldContinue: true,
|
|
422
|
+
text: message,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
try {
|
|
428
|
+
await safeLog(state, "warn", "experimental.stopping vote failed; abstaining", {
|
|
429
|
+
sessionID,
|
|
430
|
+
error: error instanceof Error ? error.message : String(error),
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
// best-effort only — the abstain itself must not throw
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}));
|
|
438
|
+
await safeLog(state, "info", "registered experimental.stopping hook; if this OpenCode build dispatches it, gate failures continue the turn with steer text");
|
|
439
|
+
}
|
|
440
|
+
catch {
|
|
441
|
+
await safeLog(state, "warn", "could not register experimental.stopping hook; legacy stopping probe and session.idle re-prompt remain");
|
|
442
|
+
}
|
|
353
443
|
// 2a) Native permission layer (Phase 25): `permission.evaluate` fires
|
|
354
444
|
// with `{action, resources, effect}` (shapes recorded in the 25.1 spike,
|
|
355
445
|
// docs/plans/08-notes.md — never guessed: action "edit" covers
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StopHookKind } from "./block-store.js";
|
|
1
2
|
import type { ChangedFileTracker } from "./gate.js";
|
|
2
3
|
import type { RunCommand } from "./host.js";
|
|
3
4
|
import type { LogFn } from "./logger.js";
|
|
@@ -32,8 +33,14 @@ export interface HookState {
|
|
|
32
33
|
/** mtime (ms) of the config file at last load; used to detect out-of-process
|
|
33
34
|
* edits (e.g. a `/df-profile` change made from the TUI module). */
|
|
34
35
|
configMtime?: number;
|
|
35
|
-
/** True once core has actually dispatched
|
|
36
|
+
/** True once core has actually dispatched a stopping hook (hard stops active). */
|
|
36
37
|
stopHookSupported?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Which hook fired: the legacy `stopping` probe or the V2
|
|
40
|
+
* `experimental.stopping` contract. The new hook outranks the old; absent
|
|
41
|
+
* until either fires (idle re-prompt fallback is the active level).
|
|
42
|
+
*/
|
|
43
|
+
stopHookKind?: StopHookKind;
|
|
37
44
|
}
|
|
38
45
|
export declare function setBaseDirectory(directory: string): void;
|
|
39
46
|
export declare function getBaseDirectory(): string | null;
|