opencode-dev-framework 0.1.28 → 0.1.29
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 +9 -5
- package/dist/index.d.ts +18 -4
- package/dist/index.js +56 -21
- package/dist/registry.d.ts +4 -0
- package/dist/registry.js +8 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -202,11 +202,15 @@ itself).
|
|
|
202
202
|
|
|
203
203
|
## Limitations
|
|
204
204
|
|
|
205
|
-
- **The completion gate blocks only in newer OpenCode versions.**
|
|
206
|
-
`
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
- **The completion gate blocks only in newer OpenCode versions.** Newer
|
|
206
|
+
builds support the `session.stopping` hook (OpenCode PR #44712) and
|
|
207
|
+
the earlier `experimental.session.stopping` hook (PR #41811); either
|
|
208
|
+
lets the plugin keep the session running until checks pass. The new
|
|
209
|
+
hook uses a fail-closed `{ stop, message }` contract and applies only
|
|
210
|
+
to natural loop exits; OpenCode core also caps continuations at 3
|
|
211
|
+
regardless of `gate.max_blocks`. In older OpenCode versions the gate
|
|
212
|
+
runs on `session.idle` and reports failures loudly but cannot force
|
|
213
|
+
the agent to keep working.
|
|
210
214
|
- **Guardrails run inside OpenCode.** The `tool.execute.before` hook runs
|
|
211
215
|
after OpenCode's own permission system; it adds project rules on top, it
|
|
212
216
|
does not replace OpenCode permissions.
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - event (session.idle) -> completion gate fallback (advisory logging)
|
|
8
8
|
* - experimental.chat.system.transform -> constitution injection + session mapping
|
|
9
9
|
* - experimental.session.stopping -> blocking completion gate (OpenCode >= PR #41811)
|
|
10
|
+
* - session.stopping -> same blocking gate, new contract (OpenCode PR #44712)
|
|
10
11
|
* - config hook -> registers /df-profile and /df-verify prompt commands
|
|
11
12
|
* - command.execute.before -> handles /df-profile, /df-verify, and unknown /df-*
|
|
12
13
|
*/
|
|
@@ -16,10 +17,17 @@ import { type RunCommand } from "./host.js";
|
|
|
16
17
|
import { type LogFn } from "./logger.js";
|
|
17
18
|
import type { ResolvedConfig } from "./types.js";
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* OpenCode exposes two competing "loop continuation" hooks that are not yet in
|
|
21
|
+
* the published `@opencode-ai/plugin` types, so we declare both locally and use
|
|
22
|
+
* whichever the runtime supports:
|
|
23
|
+
*
|
|
24
|
+
* - `experimental.session.stopping` (OpenCode PR #41811): plugin pushes text
|
|
25
|
+
* into `output.context`; presence keeps the session running.
|
|
26
|
+
* - `session.stopping` (OpenCode PR #44712): fail-closed contract. The default
|
|
27
|
+
* `stop: true` lets the session end; setting `stop: false` with a non-empty
|
|
28
|
+
* `message` injects a synthetic user turn and continues the loop. The hook
|
|
29
|
+
* fires only on natural loop exit and OpenCode core enforces its own
|
|
30
|
+
* re-entry cap (3) regardless of `gate.max_blocks`.
|
|
23
31
|
*/
|
|
24
32
|
export interface HooksWithStopping extends Hooks {
|
|
25
33
|
"experimental.session.stopping"?: (input: {
|
|
@@ -27,6 +35,12 @@ export interface HooksWithStopping extends Hooks {
|
|
|
27
35
|
}, output: {
|
|
28
36
|
context: string[];
|
|
29
37
|
}) => Promise<void>;
|
|
38
|
+
"session.stopping"?: (input: {
|
|
39
|
+
sessionID: string;
|
|
40
|
+
}, output: {
|
|
41
|
+
stop: boolean;
|
|
42
|
+
message?: string;
|
|
43
|
+
}) => Promise<void>;
|
|
30
44
|
}
|
|
31
45
|
/**
|
|
32
46
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - event (session.idle) -> completion gate fallback (advisory logging)
|
|
8
8
|
* - experimental.chat.system.transform -> constitution injection + session mapping
|
|
9
9
|
* - experimental.session.stopping -> blocking completion gate (OpenCode >= PR #41811)
|
|
10
|
+
* - session.stopping -> same blocking gate, new contract (OpenCode PR #44712)
|
|
10
11
|
* - config hook -> registers /df-profile and /df-verify prompt commands
|
|
11
12
|
* - command.execute.before -> handles /df-profile, /df-verify, and unknown /df-*
|
|
12
13
|
*/
|
|
@@ -57,6 +58,47 @@ async function reloadConfigIfChanged(state) {
|
|
|
57
58
|
// Config file missing/unreadable — keep the current state.
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Shared completion-gate runner for the two loop-continuation hooks
|
|
63
|
+
* (`experimental.session.stopping` and `session.stopping`). The two hooks
|
|
64
|
+
* differ only in how they signal continuation to the runtime, so all gate and
|
|
65
|
+
* block-counting logic lives here and each hook translates the verdict into its
|
|
66
|
+
* own output contract. `state` must already be resolved and have had
|
|
67
|
+
* `reloadConfigIfChanged` applied by the caller.
|
|
68
|
+
*/
|
|
69
|
+
async function runStoppingGate(state, sessionID) {
|
|
70
|
+
if (!state.config.gate || state.config.profile === "off") {
|
|
71
|
+
return { decision: "pass" };
|
|
72
|
+
}
|
|
73
|
+
const changedFiles = state.tracker.getChangedFiles();
|
|
74
|
+
const report = await runGate(state.run, state.config, changedFiles, { cwd: state.directory });
|
|
75
|
+
if (!report.ran || report.ok) {
|
|
76
|
+
state.tracker.clearChangedFiles();
|
|
77
|
+
state.blockCounts.delete(sessionID);
|
|
78
|
+
return { decision: "pass" };
|
|
79
|
+
}
|
|
80
|
+
const maxBlocks = state.config.gate.max_blocks ?? 3;
|
|
81
|
+
const blockCount = (state.blockCounts.get(sessionID) ?? 0) + 1;
|
|
82
|
+
state.blockCounts.set(sessionID, blockCount);
|
|
83
|
+
if (blockCount > maxBlocks) {
|
|
84
|
+
// Standing down: clear the tracker so the session.idle fallback does
|
|
85
|
+
// not re-run the same failing gate commands a second time.
|
|
86
|
+
state.tracker.clearChangedFiles();
|
|
87
|
+
await safeLog(state, "warn", `completion gate has blocked ${maxBlocks} times; standing down but checks are still failing`, { failedSteps: report.failedSteps.map((step) => step.name) });
|
|
88
|
+
return { decision: "standdown", failedSteps: report.failedSteps.map((step) => step.name) };
|
|
89
|
+
}
|
|
90
|
+
const summary = summarizeGate(report);
|
|
91
|
+
await safeLog(state, "error", summary, {
|
|
92
|
+
failedSteps: report.failedSteps.map((step) => step.name),
|
|
93
|
+
});
|
|
94
|
+
return { decision: "blocked", summary, blockCount, maxBlocks };
|
|
95
|
+
}
|
|
96
|
+
/** The continuation message both stopping hooks inject on a gate block. */
|
|
97
|
+
function stoppingMessage(verdict) {
|
|
98
|
+
return (`opencode-dev-framework completion gate blocked you from finishing (block ${verdict.blockCount}/${verdict.maxBlocks}). ` +
|
|
99
|
+
`The following checks failed:\n\n${verdict.summary}\n\n` +
|
|
100
|
+
`Fix the underlying cause and continue. Do NOT disable, skip, or weaken these checks to make them pass.`);
|
|
101
|
+
}
|
|
60
102
|
/**
|
|
61
103
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
62
104
|
* the plugin) so tests can inject a stubbed command runner and tracker.
|
|
@@ -157,33 +199,26 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
157
199
|
return;
|
|
158
200
|
}
|
|
159
201
|
await reloadConfigIfChanged(state);
|
|
160
|
-
|
|
202
|
+
const verdict = await runStoppingGate(state, input.sessionID);
|
|
203
|
+
if (verdict.decision !== "blocked") {
|
|
161
204
|
return;
|
|
162
205
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
206
|
+
output.context.push(stoppingMessage(verdict));
|
|
207
|
+
},
|
|
208
|
+
"session.stopping": async (input, output) => {
|
|
209
|
+
const state = getStateForSession(input.sessionID);
|
|
210
|
+
if (!state) {
|
|
168
211
|
return;
|
|
169
212
|
}
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
if (blockCount > maxBlocks) {
|
|
174
|
-
// Standing down: clear the tracker so the session.idle fallback does
|
|
175
|
-
// not re-run the same failing gate commands a second time.
|
|
176
|
-
state.tracker.clearChangedFiles();
|
|
177
|
-
await safeLog(state, "warn", `completion gate has blocked ${maxBlocks} times; standing down but checks are still failing`, { failedSteps: report.failedSteps.map((step) => step.name) });
|
|
213
|
+
await reloadConfigIfChanged(state);
|
|
214
|
+
const verdict = await runStoppingGate(state, input.sessionID);
|
|
215
|
+
if (verdict.decision !== "blocked") {
|
|
178
216
|
return;
|
|
179
217
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
output.context.push(`opencode-dev-framework completion gate blocked you from finishing (block ${blockCount}/${maxBlocks}). ` +
|
|
185
|
-
`The following checks failed:\n\n${summary}\n\n` +
|
|
186
|
-
`Fix the underlying cause and continue. Do NOT disable, skip, or weaken these checks to make them pass.`);
|
|
218
|
+
// Fail-closed contract: leave `stop: true` on pass/standdown; only a
|
|
219
|
+
// real block sets `stop: false` with a continuation message.
|
|
220
|
+
output.stop = false;
|
|
221
|
+
output.message = stoppingMessage(verdict);
|
|
187
222
|
},
|
|
188
223
|
event: async ({ event }) => {
|
|
189
224
|
// session.deleted must run even without hook state so the session map
|
package/dist/registry.d.ts
CHANGED
|
@@ -43,3 +43,7 @@ export declare function setSessionDirectory(sessionID: string, directory: string
|
|
|
43
43
|
export declare function getDirectoryForSession(sessionID: string): string | null;
|
|
44
44
|
/** Forget a session's directory mapping (called on `session.deleted`). */
|
|
45
45
|
export declare function clearSessionDirectory(sessionID: string): void;
|
|
46
|
+
/** Reset all in-memory registries. Intended for test cleanup between
|
|
47
|
+
* test runs so stale session-to-directory mappings do not bleed
|
|
48
|
+
* `getStateForSession` into the next test. */
|
|
49
|
+
export declare function resetRegistry(): void;
|
package/dist/registry.js
CHANGED
|
@@ -58,3 +58,11 @@ export function getDirectoryForSession(sessionID) {
|
|
|
58
58
|
export function clearSessionDirectory(sessionID) {
|
|
59
59
|
sessionToDirectory.delete(sessionID);
|
|
60
60
|
}
|
|
61
|
+
/** Reset all in-memory registries. Intended for test cleanup between
|
|
62
|
+
* test runs so stale session-to-directory mappings do not bleed
|
|
63
|
+
* `getStateForSession` into the next test. */
|
|
64
|
+
export function resetRegistry() {
|
|
65
|
+
sessionToDirectory.clear();
|
|
66
|
+
hookRegistry.clear();
|
|
67
|
+
activeDirectory = null;
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-dev-framework",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -41,7 +41,12 @@
|
|
|
41
41
|
"lint:fix": "biome lint --write .",
|
|
42
42
|
"format:check": "biome format .",
|
|
43
43
|
"format:fix": "biome format --write .",
|
|
44
|
-
"lint:md": "markdownlint-cli2 \"**/*.md\""
|
|
44
|
+
"lint:md": "markdownlint-cli2 \"**/*.md\"",
|
|
45
|
+
"release": "./scripts/release.sh",
|
|
46
|
+
"release:patch": "./scripts/release.sh patch",
|
|
47
|
+
"release:minor": "./scripts/release.sh minor",
|
|
48
|
+
"release:major": "./scripts/release.sh major",
|
|
49
|
+
"dev:clean": "rm -rf ~/.cache/opencode/packages/opencode-dev-framework* && npm run build"
|
|
45
50
|
},
|
|
46
51
|
"keywords": [
|
|
47
52
|
"opencode",
|