opencode-dev-framework 1.9.5 → 1.10.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 +137 -33
- package/bin/df +94 -4
- package/cordis.patch.yml +17 -0
- package/dist/adapters/dsh/extract.d.ts +47 -0
- package/dist/adapters/dsh/extract.js +62 -0
- package/dist/adapters/dsh/index.d.ts +332 -0
- package/dist/adapters/dsh/index.js +1643 -0
- package/dist/adapters/opencode/index.d.ts +30 -0
- package/dist/{index.js → adapters/opencode/index.js} +120 -235
- package/dist/{block-store.d.ts → core/block-store.d.ts} +10 -3
- package/dist/{commands.js → core/commands.js} +4 -2
- package/dist/{config.d.ts → core/config.d.ts} +16 -4
- package/dist/{config.js → core/config.js} +102 -10
- package/dist/{format-status.d.ts → core/format-status.d.ts} +13 -2
- package/dist/{format-status.js → core/format-status.js} +30 -7
- package/dist/{gate.d.ts → core/gate.d.ts} +9 -1
- package/dist/{gate.js → core/gate.js} +14 -2
- package/dist/{goal.d.ts → core/goal.d.ts} +4 -3
- package/dist/{goal.js → core/goal.js} +4 -3
- package/dist/{harness.d.ts → core/harness.d.ts} +10 -5
- package/dist/{harness.js → core/harness.js} +119 -32
- package/dist/{init.d.ts → core/init.d.ts} +18 -1
- package/dist/{init.js → core/init.js} +33 -8
- package/dist/core/install-dsh.d.ts +67 -0
- package/dist/core/install-dsh.js +235 -0
- package/dist/{installer.d.ts → core/installer.d.ts} +32 -2
- package/dist/{installer.js → core/installer.js} +129 -12
- package/dist/{lint.d.ts → core/lint.d.ts} +43 -2
- package/dist/{lint.js → core/lint.js} +89 -2
- package/dist/core/paths.d.ts +35 -0
- package/dist/core/paths.js +41 -0
- package/dist/{protect.d.ts → core/protect.d.ts} +18 -4
- package/dist/{protect.js → core/protect.js} +85 -34
- package/dist/{registry.d.ts → core/registry.d.ts} +9 -1
- package/dist/{review.js → core/review.js} +14 -6
- package/dist/{rules.d.ts → core/rules.d.ts} +3 -2
- package/dist/{rules.js → core/rules.js} +21 -5
- package/dist/core/run-hooks.d.ts +138 -0
- package/dist/core/run-hooks.js +196 -0
- package/dist/{runtime-status.d.ts → core/runtime-status.d.ts} +5 -4
- package/dist/{runtime-status.js → core/runtime-status.js} +29 -17
- package/dist/{types.d.ts → core/types.d.ts} +17 -0
- package/dist/{update.d.ts → core/update.d.ts} +12 -4
- package/dist/{update.js → core/update.js} +28 -12
- package/dist/{weakening.js → core/weakening.js} +2 -1
- package/package.json +16 -6
- package/rules/40-delegation.md +13 -2
- package/templates/.opencode/agents/style-enforcer.md +1 -1
- package/templates/.opencode/agents/test-grounder.md +1 -1
- package/templates/.opencode/skills/ground-in-tests/SKILL.md +1 -1
- package/templates/.opencode/skills/project-config/SKILL.md +2 -2
- package/tui.tsx +6 -6
- package/dist/index.d.ts +0 -101
- /package/dist/{block-store.js → core/block-store.js} +0 -0
- /package/dist/{command-utils.d.ts → core/command-utils.d.ts} +0 -0
- /package/dist/{command-utils.js → core/command-utils.js} +0 -0
- /package/dist/{commands.d.ts → core/commands.d.ts} +0 -0
- /package/dist/{detect.d.ts → core/detect.d.ts} +0 -0
- /package/dist/{detect.js → core/detect.js} +0 -0
- /package/dist/{host.d.ts → core/host.d.ts} +0 -0
- /package/dist/{host.js → core/host.js} +0 -0
- /package/dist/{logger.d.ts → core/logger.d.ts} +0 -0
- /package/dist/{logger.js → core/logger.js} +0 -0
- /package/dist/{registry.js → core/registry.js} +0 -0
- /package/dist/{review.d.ts → core/review.d.ts} +0 -0
- /package/dist/{roster.d.ts → core/roster.d.ts} +0 -0
- /package/dist/{roster.js → core/roster.js} +0 -0
- /package/dist/{types.js → core/types.js} +0 -0
- /package/dist/{weakening.d.ts → core/weakening.d.ts} +0 -0
- /package/templates/{.opencode/opencode-dev-framework → .dev-framework}/rules/.gitkeep +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* opencode-dev-framework V2 plugin entry point.
|
|
3
|
+
*
|
|
4
|
+
* V2 framework (opencode v2): Plugin.define({ id, setup(ctx) })
|
|
5
|
+
* - ctx.session.hook("context"/"generate"/"compaction"/"title", ...) -> constitution injection
|
|
6
|
+
* - ctx.permission.hook("evaluate", ...) -> native permission layer (Phase 25;
|
|
7
|
+
* observe-only spike in 25.1, enforcing mapper from 25.2)
|
|
8
|
+
* - ctx.tool.hook("execute.before", ...) -> guardrails (backstop from Phase 25)
|
|
9
|
+
* - ctx.tool.hook("execute.after", ...) -> per-edit lint + change tracking
|
|
10
|
+
* (`filesystem.changed` stays as a fallback this release; see Phase 24)
|
|
11
|
+
* - ctx.event.subscribe() -> file tracking + gate enforcement via re-prompt
|
|
12
|
+
* - ctx.tool.transform(...) -> custom tools
|
|
13
|
+
* - ctx.command.transform(...) -> server-side `/df-goal` verified-goal
|
|
14
|
+
* wrapper (thin adapter delegating to native `/goal`; see src/goal.ts)
|
|
15
|
+
* - ctx.command.transform(...) -> server-side `/df-init` project setup
|
|
16
|
+
* (deterministic scaffold in code, handoff back via session.prompt;
|
|
17
|
+
* see src/init.ts)
|
|
18
|
+
* - ctx.command.transform(...) -> server-side `/df-update` template drift
|
|
19
|
+
* check (detection only, handoff back via session.prompt; see src/update.ts)
|
|
20
|
+
*
|
|
21
|
+
* Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
|
|
22
|
+
* (same execution) we run the gate and if it fails inside budget we admit
|
|
23
|
+
* `ctx.session.synthetic({ sessionID, text: stoppingMessage })` — the
|
|
24
|
+
* continuation runs before the session goes idle (see
|
|
25
|
+
* docs/plans/12-idle-hook-cutover.md). The `event.subscribe` idle net
|
|
26
|
+
* stays as a deduped fallback for the boundaries the hook skips.
|
|
27
|
+
*/
|
|
28
|
+
import { Plugin } from "@opencode/plugin";
|
|
29
|
+
declare const plugin: Plugin.Plugin;
|
|
30
|
+
export default plugin;
|
|
@@ -28,158 +28,21 @@
|
|
|
28
28
|
import { stat } from "node:fs/promises";
|
|
29
29
|
import { join } from "node:path";
|
|
30
30
|
import { Plugin } from "@opencode/plugin";
|
|
31
|
-
import { createBlockStore, createStuckSnapshotStore
|
|
32
|
-
import {
|
|
33
|
-
import { createChangedFileTracker } from "
|
|
34
|
-
import {
|
|
35
|
-
import { runCommand } from "
|
|
36
|
-
import { createLintLimiter
|
|
37
|
-
import { createLogger } from "
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
let fallbackLog = async () => { };
|
|
47
|
-
/**
|
|
48
|
-
* Minimum interval between config-mtime checks. Every hook fire calls
|
|
49
|
-
* `reloadConfigIfChanged`, but the config file almost never changes
|
|
50
|
-
* mid-session, so a 1s staleness window is invisible.
|
|
51
|
-
*/
|
|
52
|
-
const CONFIG_RELOAD_MIN_INTERVAL_MS = 1000;
|
|
53
|
-
function safeLog(state, level, message, extra) {
|
|
54
|
-
const fn = state && typeof state.log === "function" ? state.log : fallbackLog;
|
|
55
|
-
return fn(level, message, extra);
|
|
56
|
-
}
|
|
57
|
-
async function reloadConfigIfChanged(state) {
|
|
58
|
-
// Throttle mtime checks: every hook fire calls this, but the config file
|
|
59
|
-
// almost never changes mid-session. A 1s staleness window is invisible.
|
|
60
|
-
const now = Date.now();
|
|
61
|
-
if (now - state.lastConfigCheck < CONFIG_RELOAD_MIN_INTERVAL_MS) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
state.lastConfigCheck = now;
|
|
65
|
-
const primary = join(state.directory, ".opencode-dev-framework.yml");
|
|
66
|
-
const fallback = join(state.directory, ".dev-framework.yml");
|
|
67
|
-
// check both names; stat whichever exists
|
|
68
|
-
let configPath = null;
|
|
69
|
-
let mtime;
|
|
70
|
-
for (const p of [primary, fallback]) {
|
|
71
|
-
try {
|
|
72
|
-
const s = await stat(p);
|
|
73
|
-
configPath = p;
|
|
74
|
-
mtime = s.mtimeMs;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// continue
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (!configPath || mtime === undefined) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (state.configMtime !== undefined && state.configMtime === mtime) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
try {
|
|
88
|
-
clearConfigCache();
|
|
89
|
-
const next = loadConfig(state.directory);
|
|
90
|
-
const { constitution } = await loadConstitution(next, state.directory);
|
|
91
|
-
state.config = next;
|
|
92
|
-
state.constitution = constitution;
|
|
93
|
-
state.configMtime = mtime;
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
// keep current state on read failure
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Turn a completion verdict into the continuation message fed back to the
|
|
101
|
-
* agent when blocked. Shared by the `experimental.idle` hook (same
|
|
102
|
-
* execution, via synthetic) and the `event.subscribe` idle re-prompt
|
|
103
|
-
* fallback so wording (and block counting) is identical on every
|
|
104
|
-
* enforcement level.
|
|
105
|
-
*/
|
|
106
|
-
function continuationMessage(verdict) {
|
|
107
|
-
const why = verdict.reason === "review"
|
|
108
|
-
? "the peer-review requirement is unmet"
|
|
109
|
-
: verdict.reason === "weakened"
|
|
110
|
-
? "the completion contract was weakened mid-session"
|
|
111
|
-
: "the repo's checks are failing";
|
|
112
|
-
return (`opencode-dev-framework completion gate blocked you from finishing because ${why} ` +
|
|
113
|
-
`(block ${verdict.blockCount}/${verdict.maxBlocks}).\n\n${verdict.summary}\n\n` +
|
|
114
|
-
`Fix the underlying cause and continue. Do NOT disable, skip, or weaken these checks to ` +
|
|
115
|
-
`get past the gate. If a failure is pre-existing and unrelated to your work, prove it ` +
|
|
116
|
-
`(show it fails on a clean tree) and report it to the user.`);
|
|
117
|
-
}
|
|
118
|
-
/** Log pass/standdown verdicts; returns the continuation message when blocked. */
|
|
119
|
-
async function actOnVerdict(state, verdict) {
|
|
120
|
-
if (verdict.decision === "pass") {
|
|
121
|
-
if (verdict.note) {
|
|
122
|
-
await safeLog(state, "info", verdict.note, { changedFiles: verdict.changedFiles });
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
if (verdict.decision === "standdown") {
|
|
127
|
-
// evaluateCompletion already logged the stand-down loudly.
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
return continuationMessage(verdict);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Per-edit lint flow, shared by the `execute.after` hook (primary) and the
|
|
134
|
-
* `filesystem.changed` fallback. Skipped files log at debug; passes at info;
|
|
135
|
-
* failures log loudly at error (the edit already landed, so unlike
|
|
136
|
-
* `execute.before` this never throws — it only reports).
|
|
137
|
-
*/
|
|
138
|
-
async function runPerEditLint(state, filePath) {
|
|
139
|
-
if (!state.config.on_edit.lint)
|
|
140
|
-
return;
|
|
141
|
-
if (state.config.precommit === "auto" && state.precommitAvailable === undefined) {
|
|
142
|
-
state.precommitAvailable = await detectPreCommitAvailability(state.run, state.directory);
|
|
143
|
-
}
|
|
144
|
-
const outcome = await state.lintLimiter.run(() => lintFile(state.run, state.config, filePath, {
|
|
145
|
-
cwd: state.directory,
|
|
146
|
-
timeout: state.config.gate?.timeout,
|
|
147
|
-
precommitAvailable: state.precommitAvailable,
|
|
148
|
-
}));
|
|
149
|
-
if (outcome.skipped) {
|
|
150
|
-
await safeLog(state, "debug", summarizeLint(outcome), {
|
|
151
|
-
filePath,
|
|
152
|
-
reason: outcome.reason,
|
|
153
|
-
});
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (!isLintFailure(outcome)) {
|
|
157
|
-
await safeLog(state, "info", summarizeLint(outcome), { filePath });
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
await safeLog(state, "error", summarizeLint(outcome), {
|
|
161
|
-
filePath,
|
|
162
|
-
command: outcome.command?.join(" "),
|
|
163
|
-
stdout: outcome.result?.stdout,
|
|
164
|
-
stderr: outcome.result?.stderr,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
/** Assemble the completion verdict with the state's live dependencies. */
|
|
168
|
-
function runCompletion(state, sessionID) {
|
|
169
|
-
return evaluateCompletion({
|
|
170
|
-
run: state.run,
|
|
171
|
-
config: state.config,
|
|
172
|
-
directory: state.directory,
|
|
173
|
-
sessionID,
|
|
174
|
-
tracker: state.tracker,
|
|
175
|
-
blockCounts: state.blocks,
|
|
176
|
-
stuckSnapshots: state.stuckSnapshots,
|
|
177
|
-
lintLimiter: state.lintLimiter,
|
|
178
|
-
passCache: state.passCache,
|
|
179
|
-
baseline: state.initialEnforceable,
|
|
180
|
-
log: (level, message, extra) => safeLog(state, level, message, extra),
|
|
181
|
-
});
|
|
182
|
-
}
|
|
31
|
+
import { createBlockStore, createStuckSnapshotStore } from "../../core/block-store.js";
|
|
32
|
+
import { CONFIG_FILE_PRECEDENCE, loadConfig } from "../../core/config.js";
|
|
33
|
+
import { createChangedFileTracker } from "../../core/gate.js";
|
|
34
|
+
import { artifactStateFirst, childArtifactDenial, createPassCache, isReviewArtifact, preflightBlockReason, } from "../../core/harness.js";
|
|
35
|
+
import { runCommand } from "../../core/host.js";
|
|
36
|
+
import { createLintLimiter } from "../../core/lint.js";
|
|
37
|
+
import { createLogger } from "../../core/logger.js";
|
|
38
|
+
import { PREFLIGHT_ARTIFACT_REL, PREFLIGHT_RELS } from "../../core/paths.js";
|
|
39
|
+
import { checkToolCall, extractCommand, extractFilePath, extractRedirectTargets, FILE_TOOLS, SHELL_TOOLS, toPermissionGuard, } from "../../core/protect.js";
|
|
40
|
+
import { clearSessionDirectory, hasSeenSessionStart, markSessionStartSeen, resolveChildSession, } from "../../core/registry.js";
|
|
41
|
+
import { findRosterIndex, renderDutyRoster, rosterPresent } from "../../core/roster.js";
|
|
42
|
+
import { constitutionPresent, loadConstitution } from "../../core/rules.js";
|
|
43
|
+
import { actOnVerdict, getActiveState, reloadConfigIfChanged, runCompletion, runPerEditLint, safeLog, setActiveState, setFallbackLog, stampIdleHandled, stampRuntimeStatus, wasIdleHandledRecently, } from "../../core/run-hooks.js";
|
|
44
|
+
import { checkTemplateUpdates, driftMentionLine } from "../../core/update.js";
|
|
45
|
+
import { snapshotEnforceable } from "../../core/weakening.js";
|
|
183
46
|
/**
|
|
184
47
|
* Build the host session lookup for child detection, defensively: older
|
|
185
48
|
* cores (and stub contexts in tests) may not expose `session.get`, in
|
|
@@ -195,40 +58,6 @@ function childSessionGetter(ctx) {
|
|
|
195
58
|
// could throw on `this`-dependent adapters and fail open to top-level).
|
|
196
59
|
return (id) => session.get({ sessionID: id });
|
|
197
60
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Record a completed idle-hook evaluation for the dedup map. Stamp ONLY on
|
|
200
|
-
* the completed-evaluation paths (pass, blocked-admitted, standdown);
|
|
201
|
-
* throw/early-return paths must not stamp so the subscriber net retries.
|
|
202
|
-
*/
|
|
203
|
-
function stampIdleHandled(state, sessionID) {
|
|
204
|
-
state.lastIdleHandled.set(sessionID, Date.now());
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Best-effort runtime snapshot for `/df-runtime`: hook state plus template
|
|
208
|
-
* drift, fire-and-forget (never throws, never blocks the caller).
|
|
209
|
-
*/
|
|
210
|
-
function stampRuntimeStatus(directory, idleHookVia, continuation) {
|
|
211
|
-
void (async () => {
|
|
212
|
-
let templates;
|
|
213
|
-
try {
|
|
214
|
-
templates = summarizeDrift(await checkTemplateUpdates(directory));
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
// Best-effort: the snapshot renders without template state.
|
|
218
|
-
}
|
|
219
|
-
await writeRuntimeStatus(directory, { idleHookVia, continuation, templates });
|
|
220
|
-
})();
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* True when the idle hook completed an evaluation for this session inside
|
|
224
|
-
* `windowMs`. The hook itself uses a short window (same-boundary
|
|
225
|
-
* double-fire guard for the dual key registration below); the subscriber
|
|
226
|
-
* net uses the full window (one boundary, one gate run).
|
|
227
|
-
*/
|
|
228
|
-
function wasIdleHandledRecently(state, sessionID, windowMs = 5_000) {
|
|
229
|
-
const at = state.lastIdleHandled.get(sessionID);
|
|
230
|
-
return at !== undefined && Date.now() - at < windowMs;
|
|
231
|
-
}
|
|
232
61
|
// Helpers to normalize V2 event shapes (data vs properties vs direct)
|
|
233
62
|
function getEventSessionID(event) {
|
|
234
63
|
const e = event;
|
|
@@ -289,7 +118,7 @@ const plugin = Plugin.define({
|
|
|
289
118
|
id: "opencode-dev-framework",
|
|
290
119
|
async setup(ctx) {
|
|
291
120
|
const log = createLogger();
|
|
292
|
-
|
|
121
|
+
setFallbackLog(log);
|
|
293
122
|
const directory = ctx.location.directory;
|
|
294
123
|
let config;
|
|
295
124
|
try {
|
|
@@ -306,13 +135,15 @@ const plugin = Plugin.define({
|
|
|
306
135
|
await log("warn", warning);
|
|
307
136
|
}
|
|
308
137
|
let configMtime;
|
|
309
|
-
for (const name of
|
|
138
|
+
for (const name of CONFIG_FILE_PRECEDENCE) {
|
|
310
139
|
try {
|
|
311
|
-
|
|
312
|
-
|
|
140
|
+
const mtimeMs = (await stat(join(directory, name))).mtimeMs;
|
|
141
|
+
if (configMtime === undefined || mtimeMs > configMtime) {
|
|
142
|
+
configMtime = mtimeMs;
|
|
143
|
+
}
|
|
313
144
|
}
|
|
314
145
|
catch {
|
|
315
|
-
//
|
|
146
|
+
// name absent
|
|
316
147
|
}
|
|
317
148
|
}
|
|
318
149
|
const tracker = createChangedFileTracker();
|
|
@@ -336,7 +167,7 @@ const plugin = Plugin.define({
|
|
|
336
167
|
lastConfigCheck: 0,
|
|
337
168
|
lastIdleHandled: new Map(),
|
|
338
169
|
};
|
|
339
|
-
|
|
170
|
+
setActiveState(state);
|
|
340
171
|
// Child-session detection for the review-duty guard (plan 23 phase 1):
|
|
341
172
|
// one cached host lookup per session lifetime; undefined on older
|
|
342
173
|
// cores, where every session reads as top-level (behavior unchanged).
|
|
@@ -367,7 +198,7 @@ const plugin = Plugin.define({
|
|
|
367
198
|
// while the global may be cleared). See issue #1 follow-up.
|
|
368
199
|
// 1) Constitution injection — per model request (V1: experimental.chat.system.transform -> V2: session.hook("context", ...))
|
|
369
200
|
trackRegistration(await ctx.session.hook("context", async (event) => {
|
|
370
|
-
if (
|
|
201
|
+
if (getActiveState() !== state)
|
|
371
202
|
return;
|
|
372
203
|
await reloadConfigIfChanged(state);
|
|
373
204
|
if (state.config.profile === "off")
|
|
@@ -400,7 +231,7 @@ const plugin = Plugin.define({
|
|
|
400
231
|
// 1a) Startup template-drift mention — once per session, best-effort.
|
|
401
232
|
// First `context` sighting of a sessionID is session startup (plugin
|
|
402
233
|
// `setup()` has no session to mention into). Drifted installs get one
|
|
403
|
-
// line pointing at
|
|
234
|
+
// line pointing at `dev_framework_update`; current and empty trees stay silent.
|
|
404
235
|
// Never throws into prompt assembly; never writes.
|
|
405
236
|
const startupID = getEventSessionID(event);
|
|
406
237
|
if (startupID !== undefined && !hasSeenSessionStart(startupID)) {
|
|
@@ -423,7 +254,7 @@ const plugin = Plugin.define({
|
|
|
423
254
|
// (no-op if model doesn't need it; cheap)
|
|
424
255
|
for (const kind of ["generate", "compaction", "title"]) {
|
|
425
256
|
trackRegistration(await ctx.session.hook(kind, async (event) => {
|
|
426
|
-
if (
|
|
257
|
+
if (getActiveState() !== state)
|
|
427
258
|
return;
|
|
428
259
|
const constitution = state.constitution;
|
|
429
260
|
if (state.config.profile === "off" || !constitution)
|
|
@@ -454,7 +285,7 @@ const plugin = Plugin.define({
|
|
|
454
285
|
// key the core accepted, so the TUI can report the hook method.
|
|
455
286
|
let idleHookVia = "none";
|
|
456
287
|
const handleIdleContinuation = async (event) => {
|
|
457
|
-
if (
|
|
288
|
+
if (getActiveState() !== state)
|
|
458
289
|
return;
|
|
459
290
|
if (event === null || typeof event !== "object")
|
|
460
291
|
return;
|
|
@@ -574,7 +405,7 @@ const plugin = Plugin.define({
|
|
|
574
405
|
// already warned for the same call.
|
|
575
406
|
try {
|
|
576
407
|
trackRegistration(await ctx.permission.hook("evaluate", async (event) => {
|
|
577
|
-
if (
|
|
408
|
+
if (getActiveState() !== state)
|
|
578
409
|
return;
|
|
579
410
|
await reloadConfigIfChanged(state);
|
|
580
411
|
if (state.config.profile === "off")
|
|
@@ -596,7 +427,7 @@ const plugin = Plugin.define({
|
|
|
596
427
|
// Pre-flight (mirrors execute.before; the artifact itself stays
|
|
597
428
|
// writable). Deny/warn per profile, exactly like the backstop.
|
|
598
429
|
if (state.config.preflight.length > 0 && action === "edit") {
|
|
599
|
-
const artifact = await
|
|
430
|
+
const artifact = await artifactStateFirst(state.directory, PREFLIGHT_RELS);
|
|
600
431
|
const reason = preflightBlockReason(state.config, "edit", target, artifact);
|
|
601
432
|
if (reason !== null) {
|
|
602
433
|
if (state.config.profile === "advisory") {
|
|
@@ -678,8 +509,8 @@ const plugin = Plugin.define({
|
|
|
678
509
|
// captured `state` throughout also closes the teardown race where the
|
|
679
510
|
// global is cleared between awaits. See issue #1.
|
|
680
511
|
trackRegistration(await ctx.tool.hook("execute.before", async (event) => {
|
|
681
|
-
if (
|
|
682
|
-
if (
|
|
512
|
+
if (getActiveState() !== state) {
|
|
513
|
+
if (getActiveState() === null) {
|
|
683
514
|
await safeLog(null, "warn", "[opencode-dev-framework] plugin state is not available; allowing tool call (fail-open after teardown)", { tool: event.tool });
|
|
684
515
|
}
|
|
685
516
|
return;
|
|
@@ -721,8 +552,8 @@ const plugin = Plugin.define({
|
|
|
721
552
|
// edits are denied (standard/strict) until the pre-flight artifact
|
|
722
553
|
// exists. This is a true hard gate — it runs before the edit lands.
|
|
723
554
|
if (state.config.preflight.length > 0) {
|
|
724
|
-
const artifact = await
|
|
725
|
-
const reason = preflightBlockReason(state.config, toolName, extractFilePath(input), artifact);
|
|
555
|
+
const artifact = await artifactStateFirst(state.directory, PREFLIGHT_RELS);
|
|
556
|
+
const reason = preflightBlockReason(state.config, toolName, extractFilePath(input), artifact, state.directory);
|
|
726
557
|
if (reason !== null) {
|
|
727
558
|
const extra = { tool: toolName, sessionID, artifact: PREFLIGHT_ARTIFACT_REL };
|
|
728
559
|
if (state.config.profile === "advisory") {
|
|
@@ -754,7 +585,7 @@ const plugin = Plugin.define({
|
|
|
754
585
|
// is nothing reliable to lint); read-only tools never touch the tracker.
|
|
755
586
|
// The edit already landed, so this hook only reports — it never throws.
|
|
756
587
|
trackRegistration(await ctx.tool.hook("execute.after", async (event) => {
|
|
757
|
-
if (
|
|
588
|
+
if (getActiveState() !== state)
|
|
758
589
|
return;
|
|
759
590
|
await reloadConfigIfChanged(state);
|
|
760
591
|
if (state.config.profile === "off")
|
|
@@ -764,7 +595,10 @@ const plugin = Plugin.define({
|
|
|
764
595
|
return;
|
|
765
596
|
if (!FILE_TOOLS.has(event.tool))
|
|
766
597
|
return;
|
|
767
|
-
|
|
598
|
+
// Out-of-tree absolute paths (sibling repos, home dir) are outside
|
|
599
|
+
// the gate's jurisdiction: not tracked, not linted.
|
|
600
|
+
if (!state.tracker.add(filePath, state.directory))
|
|
601
|
+
return;
|
|
768
602
|
if (event.status !== "completed") {
|
|
769
603
|
await safeLog(state, "debug", `tracked ${filePath} from failed ${event.tool} call (lint skipped)`, { tool: event.tool, sessionID: event.sessionID, filePath });
|
|
770
604
|
return;
|
|
@@ -795,7 +629,7 @@ const plugin = Plugin.define({
|
|
|
795
629
|
additionalProperties: false,
|
|
796
630
|
},
|
|
797
631
|
async execute(input) {
|
|
798
|
-
const { runInitScaffold, scaffoldReportLines } = await import("
|
|
632
|
+
const { runInitScaffold, scaffoldReportLines } = await import("../../core/init.js");
|
|
799
633
|
const args = input;
|
|
800
634
|
const targetDir = args.directory ?? directory;
|
|
801
635
|
const scaffold = await runInitScaffold(targetDir, state.run, {
|
|
@@ -824,9 +658,9 @@ const plugin = Plugin.define({
|
|
|
824
658
|
additionalProperties: false,
|
|
825
659
|
},
|
|
826
660
|
async execute(input) {
|
|
827
|
-
const { clearConfigCache: ccc, loadConfig: lc } = await import("
|
|
828
|
-
const { changeProfile } = await import("
|
|
829
|
-
const { loadConstitution: lc2 } = await import("
|
|
661
|
+
const { clearConfigCache: ccc, loadConfig: lc } = await import("../../core/config.js");
|
|
662
|
+
const { changeProfile } = await import("../../core/commands.js");
|
|
663
|
+
const { loadConstitution: lc2 } = await import("../../core/rules.js");
|
|
830
664
|
const args = input;
|
|
831
665
|
const targetDir = args.directory ?? directory;
|
|
832
666
|
const profile = args.profile.trim().toLowerCase();
|
|
@@ -844,9 +678,10 @@ const plugin = Plugin.define({
|
|
|
844
678
|
state.config = newConfig;
|
|
845
679
|
state.constitution = newConstitution;
|
|
846
680
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
681
|
+
const liveState = getActiveState();
|
|
682
|
+
if (liveState && liveState !== state && liveState.directory === targetDir) {
|
|
683
|
+
liveState.config = newConfig;
|
|
684
|
+
liveState.constitution = newConstitution;
|
|
850
685
|
}
|
|
851
686
|
return { content: `${message} Change applied immediately.` };
|
|
852
687
|
},
|
|
@@ -865,10 +700,11 @@ const plugin = Plugin.define({
|
|
|
865
700
|
additionalProperties: false,
|
|
866
701
|
},
|
|
867
702
|
async execute(input) {
|
|
868
|
-
const { verifyGate } = await import("
|
|
703
|
+
const { verifyGate } = await import("../../core/commands.js");
|
|
869
704
|
const args = input;
|
|
870
705
|
const targetDir = args.directory ?? directory;
|
|
871
|
-
const
|
|
706
|
+
const liveState = getActiveState();
|
|
707
|
+
const live = liveState && liveState.directory === targetDir ? liveState : null;
|
|
872
708
|
const own = state.directory === targetDir ? state : null;
|
|
873
709
|
const holder = live ?? own;
|
|
874
710
|
// Live tracker's changed files beat the TUI's empty default: a
|
|
@@ -893,10 +729,11 @@ const plugin = Plugin.define({
|
|
|
893
729
|
additionalProperties: false,
|
|
894
730
|
},
|
|
895
731
|
async execute(input) {
|
|
896
|
-
const { renderStatus } = await import("
|
|
732
|
+
const { renderStatus } = await import("../../core/format-status.js");
|
|
897
733
|
const args = input;
|
|
898
734
|
const targetDir = args.directory ?? directory;
|
|
899
|
-
const
|
|
735
|
+
const liveState = getActiveState();
|
|
736
|
+
const live = liveState && liveState.directory === targetDir ? liveState : null;
|
|
900
737
|
const own = state.directory === targetDir ? state : null;
|
|
901
738
|
const cfg = (live ?? own)?.config ?? loadConfig(targetDir);
|
|
902
739
|
// renderStatus expects HookState? pass live ?? own (may be null for other dirs)
|
|
@@ -905,6 +742,52 @@ const plugin = Plugin.define({
|
|
|
905
742
|
};
|
|
906
743
|
},
|
|
907
744
|
});
|
|
745
|
+
editor.add({
|
|
746
|
+
name: "dev_framework_update",
|
|
747
|
+
description: "Check the framework deployment for drift (bundled templates, including the skill set) and return the per-file refresh/add brief. Use when the setup may be stale; present each file for review before editing, exactly like /df-update, and never commit unreviewed.",
|
|
748
|
+
input: {
|
|
749
|
+
type: "object",
|
|
750
|
+
properties: {
|
|
751
|
+
directory: {
|
|
752
|
+
type: "string",
|
|
753
|
+
description: "Project directory (defaults to current project)",
|
|
754
|
+
},
|
|
755
|
+
},
|
|
756
|
+
additionalProperties: false,
|
|
757
|
+
},
|
|
758
|
+
async execute(input) {
|
|
759
|
+
const { checkTemplateUpdates, composeUpdatePrompt, needsAgentHandoff } = await import("../../core/update.js");
|
|
760
|
+
const args = input;
|
|
761
|
+
const targetDir = args.directory ?? directory;
|
|
762
|
+
const drift = await checkTemplateUpdates(targetDir);
|
|
763
|
+
if (!needsAgentHandoff(drift)) {
|
|
764
|
+
return { content: "templates current" };
|
|
765
|
+
}
|
|
766
|
+
return { content: composeUpdatePrompt(drift, targetDir) };
|
|
767
|
+
},
|
|
768
|
+
});
|
|
769
|
+
editor.add({
|
|
770
|
+
name: "dev_framework_runtime",
|
|
771
|
+
description: "Show the live framework runtime snapshot for the project (hook registration, gate continuation posture, template drift). Read-only; use to inspect gate state mid-session.",
|
|
772
|
+
input: {
|
|
773
|
+
type: "object",
|
|
774
|
+
properties: {
|
|
775
|
+
directory: {
|
|
776
|
+
type: "string",
|
|
777
|
+
description: "Project directory (defaults to current project)",
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
additionalProperties: false,
|
|
781
|
+
},
|
|
782
|
+
async execute(input) {
|
|
783
|
+
const { renderRuntimeStatus } = await import("../../core/format-status.js");
|
|
784
|
+
const { readRuntimeStatus } = await import("../../core/runtime-status.js");
|
|
785
|
+
const args = input;
|
|
786
|
+
const targetDir = args.directory ?? directory;
|
|
787
|
+
const snapshot = await readRuntimeStatus(targetDir);
|
|
788
|
+
return { content: renderRuntimeStatus(snapshot) };
|
|
789
|
+
},
|
|
790
|
+
});
|
|
908
791
|
}));
|
|
909
792
|
// 3b) Verified-goal wrapper — server-side `/df-goal` through
|
|
910
793
|
// `ctx.command.transform` (see src/goal.ts for the pure policy). Thin
|
|
@@ -920,12 +803,12 @@ const plugin = Plugin.define({
|
|
|
920
803
|
name: "df-goal",
|
|
921
804
|
description: "Start a verified native goal: appends a dev_framework_verify contract to the objective and delegates to native /goal exactly once. Requires native /goal, a blocking profile, and at least one configured completion check.",
|
|
922
805
|
execute: async (invocation) => {
|
|
923
|
-
if (
|
|
806
|
+
if (getActiveState() !== state) {
|
|
924
807
|
throw new Error("Cannot start a verified goal: the plugin session state changed " +
|
|
925
808
|
"(teardown or reload raced the command); retry /df-goal.");
|
|
926
809
|
}
|
|
927
810
|
await reloadConfigIfChanged(state);
|
|
928
|
-
const { extractObjectiveText, isNativeGoalListed, runGoalCommand } = await import("
|
|
811
|
+
const { extractObjectiveText, isNativeGoalListed, runGoalCommand } = await import("../../core/goal.js");
|
|
929
812
|
let nativeGoalAvailable = false;
|
|
930
813
|
try {
|
|
931
814
|
nativeGoalAvailable = isNativeGoalListed(await ctx.command.list());
|
|
@@ -978,36 +861,38 @@ const plugin = Plugin.define({
|
|
|
978
861
|
name: "df-init",
|
|
979
862
|
description: "Set up opencode-dev-framework for the current project: scaffold templates, write the detected config, trial-run it, and hand the brief to the agent. Safe to re-run; reports status when already configured.",
|
|
980
863
|
execute: async (invocation) => {
|
|
981
|
-
if (
|
|
864
|
+
if (getActiveState() !== state) {
|
|
982
865
|
throw new Error("Cannot start project setup: the plugin session state changed " +
|
|
983
866
|
"(teardown or reload raced the command); retry /df-init.");
|
|
984
867
|
}
|
|
985
|
-
const { runInitCommand } = await import("
|
|
868
|
+
const { runInitCommand } = await import("../../core/init.js");
|
|
986
869
|
const delivered = await runInitCommand({
|
|
987
870
|
directory: state.directory,
|
|
988
871
|
run: state.run,
|
|
989
872
|
delivery: invocation.delivery,
|
|
990
873
|
checkAlive: () => {
|
|
991
|
-
if (
|
|
874
|
+
if (getActiveState() !== state) {
|
|
992
875
|
throw new Error("Project setup was superseded mid-scaffold (teardown or reload raced the command); " +
|
|
993
876
|
"retry /df-init — a re-run reports status without touching anything.");
|
|
994
877
|
}
|
|
995
878
|
},
|
|
996
879
|
reload: async () => {
|
|
997
|
-
const { clearConfigCache: ccc, loadConfig: lc } = await import("
|
|
998
|
-
const { loadConstitution: lc2 } = await import("
|
|
880
|
+
const { clearConfigCache: ccc, loadConfig: lc } = await import("../../core/config.js");
|
|
881
|
+
const { loadConstitution: lc2 } = await import("../../core/rules.js");
|
|
999
882
|
ccc();
|
|
1000
883
|
const newConfig = lc(state.directory);
|
|
1001
884
|
const { constitution: newConstitution } = await lc2(newConfig, state.directory);
|
|
1002
885
|
state.config = newConfig;
|
|
1003
886
|
state.constitution = newConstitution;
|
|
1004
|
-
for (const name of
|
|
887
|
+
for (const name of CONFIG_FILE_PRECEDENCE) {
|
|
1005
888
|
try {
|
|
1006
|
-
|
|
1007
|
-
|
|
889
|
+
const mtimeMs = (await stat(join(state.directory, name))).mtimeMs;
|
|
890
|
+
if (state.configMtime === undefined || mtimeMs > state.configMtime) {
|
|
891
|
+
state.configMtime = mtimeMs;
|
|
892
|
+
}
|
|
1008
893
|
}
|
|
1009
894
|
catch {
|
|
1010
|
-
//
|
|
895
|
+
// name absent
|
|
1011
896
|
}
|
|
1012
897
|
}
|
|
1013
898
|
},
|
|
@@ -1046,16 +931,16 @@ const plugin = Plugin.define({
|
|
|
1046
931
|
name: "df-update",
|
|
1047
932
|
description: "Check the project's installed templates against the shipped set and hand the drift to the agent: refresh differing files, add missing ones, each with user approval. Detection only, never writes.",
|
|
1048
933
|
execute: async (invocation) => {
|
|
1049
|
-
if (
|
|
934
|
+
if (getActiveState() !== state) {
|
|
1050
935
|
throw new Error("Cannot check for updates: the plugin session state changed " +
|
|
1051
936
|
"(teardown or reload raced the command); retry /df-update.");
|
|
1052
937
|
}
|
|
1053
|
-
const { runUpdateCommand } = await import("
|
|
938
|
+
const { runUpdateCommand } = await import("../../core/update.js");
|
|
1054
939
|
const delivered = await runUpdateCommand({
|
|
1055
940
|
directory: state.directory,
|
|
1056
941
|
delivery: invocation.delivery,
|
|
1057
942
|
checkAlive: () => {
|
|
1058
|
-
if (
|
|
943
|
+
if (getActiveState() !== state) {
|
|
1059
944
|
throw new Error("Update check was superseded mid-run (teardown or reload raced the command); " +
|
|
1060
945
|
"retry /df-update — it only reads, never writes.");
|
|
1061
946
|
}
|
|
@@ -1092,7 +977,7 @@ const plugin = Plugin.define({
|
|
|
1092
977
|
for await (const rawEvent of ctx.event.subscribe({ signal: controller.signal })) {
|
|
1093
978
|
// Stale-loop guard: a previous setup's loop must exit rather than
|
|
1094
979
|
// hijack a newer setup's state (duplicate gate re-prompts / lint).
|
|
1095
|
-
if (
|
|
980
|
+
if (getActiveState() !== state)
|
|
1096
981
|
return;
|
|
1097
982
|
const event = rawEvent;
|
|
1098
983
|
const type = event.type;
|
|
@@ -1110,7 +995,7 @@ const plugin = Plugin.define({
|
|
|
1110
995
|
continue;
|
|
1111
996
|
}
|
|
1112
997
|
if (isFilesystemChangedEvent(type)) {
|
|
1113
|
-
if (
|
|
998
|
+
if (getActiveState() !== state)
|
|
1114
999
|
return;
|
|
1115
1000
|
await reloadConfigIfChanged(state);
|
|
1116
1001
|
if (state.config.profile === "off")
|
|
@@ -1130,7 +1015,7 @@ const plugin = Plugin.define({
|
|
|
1130
1015
|
continue;
|
|
1131
1016
|
}
|
|
1132
1017
|
if (isIdleEvent(event)) {
|
|
1133
|
-
if (
|
|
1018
|
+
if (getActiveState() !== state)
|
|
1134
1019
|
return;
|
|
1135
1020
|
await reloadConfigIfChanged(state);
|
|
1136
1021
|
if (state.config.profile === "off")
|
|
@@ -1206,7 +1091,7 @@ const plugin = Plugin.define({
|
|
|
1206
1091
|
// Unregister every hook/transform registered by this setup() so a
|
|
1207
1092
|
// teardown/reload (e.g. session_move into a worktree) does not leave
|
|
1208
1093
|
// stale closures alive. Disposal failures are ignored — the
|
|
1209
|
-
// stale-hook guard (`
|
|
1094
|
+
// stale-hook guard (`getActiveState() !== state` → no-op / fail-open) keeps
|
|
1210
1095
|
// the session usable regardless.
|
|
1211
1096
|
for (const registration of registrations) {
|
|
1212
1097
|
try {
|
|
@@ -1218,8 +1103,8 @@ const plugin = Plugin.define({
|
|
|
1218
1103
|
}
|
|
1219
1104
|
// Only clear the singleton if it is still ours; a newer setup() may
|
|
1220
1105
|
// already have replaced it (reload race).
|
|
1221
|
-
if (
|
|
1222
|
-
|
|
1106
|
+
if (getActiveState() === state) {
|
|
1107
|
+
setActiveState(null);
|
|
1223
1108
|
}
|
|
1224
1109
|
};
|
|
1225
1110
|
},
|
|
@@ -22,9 +22,16 @@
|
|
|
22
22
|
* recording which stopping probe fired. The idle-first cutover removed
|
|
23
23
|
* that API; a stale key left by an older install is simply never read.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Minimal storage surface we need. Structurally matches the host plugin's
|
|
27
|
+
* storage domain (`get`/`set`/`remove` over string keys); deliberately
|
|
28
|
+
* declared locally so core imports nothing host-specific (not even types).
|
|
29
|
+
*/
|
|
30
|
+
export interface StorageLike {
|
|
31
|
+
get(key: string): Promise<unknown>;
|
|
32
|
+
set(key: string, value: unknown): Promise<void>;
|
|
33
|
+
remove(key: string): Promise<void>;
|
|
34
|
+
}
|
|
28
35
|
export declare const BLOCK_COUNT_KEY_PREFIX = "df:blocks:";
|
|
29
36
|
export declare const STUCK_SNAPSHOT_KEY_PREFIX = "df:stuck:";
|
|
30
37
|
export interface BlockStore {
|