opencode-dev-framework 1.5.1 → 1.7.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 +21 -28
- package/dist/format-status.js +1 -0
- package/dist/harness.d.ts +37 -8
- package/dist/harness.js +74 -25
- package/dist/index.d.ts +11 -0
- package/dist/index.js +107 -53
- package/dist/init.d.ts +62 -0
- package/dist/init.js +143 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.js +105 -14
- package/dist/review.d.ts +14 -0
- package/dist/review.js +88 -0
- package/dist/roster.d.ts +26 -0
- package/dist/roster.js +99 -0
- package/dist/weakening.d.ts +36 -0
- package/dist/weakening.js +116 -0
- package/package.json +1 -1
- package/templates/.opencode/skills/project-config/SKILL.md +3 -2
package/README.md
CHANGED
|
@@ -18,38 +18,30 @@ reimplemented as an OpenCode-native plugin.
|
|
|
18
18
|
Five minutes from zero to your first gated session:
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
|
|
21
|
+
opencode plugin add opencode-dev-framework
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"plugins": ["opencode-dev-framework"]
|
|
28
|
-
}
|
|
29
|
-
```
|
|
24
|
+
Then in any project, run `/df-init` — it scaffolds the templates, writes a
|
|
25
|
+
detected config, trial-runs it, and walks you through the rest, ending at a
|
|
26
|
+
config + `hardening.md` diff for your review:
|
|
30
27
|
|
|
31
|
-
```
|
|
32
|
-
|
|
28
|
+
```text
|
|
29
|
+
/df-init
|
|
33
30
|
```
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
- **
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
scratch: reads your Makefile, CI, and CONTRIBUTING, maps the real
|
|
49
|
-
verification commands, drafts `hardening.md`, presents the diff.
|
|
50
|
-
|
|
51
|
-
Then start a session in your project and ask
|
|
52
|
-
the agent for a small edit. You will see the plugin working: the edit is
|
|
32
|
+
Two ways in, same gate out — pick by how much attention you want to spend:
|
|
33
|
+
|
|
34
|
+
- **Conversational (default).** `/df-init` hands your session agent a brief:
|
|
35
|
+
what was detected, what passed, Makefile targets worth mapping to
|
|
36
|
+
wrappers, at most 3 open questions. The agent resolves what it can, asks
|
|
37
|
+
only genuinely user-only questions, and ends with a config + hardening
|
|
38
|
+
draft for your review. Budget ~5 minutes, review-only at the end;
|
|
39
|
+
imperfections assumed, manual always possible.
|
|
40
|
+
- **Scripted.** `npx df init` from a shell: same scaffold, detect, and
|
|
41
|
+
trial-run, no conversation. For CI, dotfiles, and non-interactive runs;
|
|
42
|
+
conflicts need `--overwrite-existing` or `--skip-existing`.
|
|
43
|
+
|
|
44
|
+
Then ask the agent for a small edit. You will see the plugin working: the edit is
|
|
53
45
|
checked against guardrails before it lands, your linter runs on the edited
|
|
54
46
|
file, and when the session goes idle the completion gate runs your
|
|
55
47
|
typecheck/tests. `/df-status` shows the live state at any time. Start with
|
|
@@ -68,7 +60,8 @@ Requires OpenCode `v2.x` — tested on `v2.0.26` and `v2.2.0`. On
|
|
|
68
60
|
- **Per-edit lint.** Runs your linter on each edited file and reports loudly.
|
|
69
61
|
- **Completion gate.** At the would-go-idle boundary, runs typecheck, tests,
|
|
70
62
|
acceptance checks, and (optionally) lint on changed files — plus a required
|
|
71
|
-
peer-review artifact in `standard`/`strict
|
|
63
|
+
substantive peer-review artifact in `standard`/`strict` (length floors, no
|
|
64
|
+
template checkboxes). Failures steer the session
|
|
72
65
|
back with the failure summary, bounded by `gate.max_blocks` (fewer when
|
|
73
66
|
the failure repeats with no new edits — the gate stands down early on
|
|
74
67
|
zero progress).
|
package/dist/format-status.js
CHANGED
|
@@ -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-goal Start a verified native goal (verification contract + native /goal)");
|
|
114
|
+
lines.push("/df-init Set up this project (scaffold, detected config, trial-run, brief)");
|
|
114
115
|
lines.push("/df-help Show this message");
|
|
115
116
|
lines.push("/df-runtime Show plugin version and live hook/gate runtime state");
|
|
116
117
|
return lines.join("\n");
|
package/dist/harness.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ import { type ChangedFileTracker, type GateReport } from "./gate.js";
|
|
|
21
21
|
import type { RunCommand } from "./host.js";
|
|
22
22
|
import type { LintLimiter } from "./lint.js";
|
|
23
23
|
import type { LogFn } from "./logger.js";
|
|
24
|
+
import { type ReviewState } from "./review.js";
|
|
24
25
|
import type { ResolvedConfig } from "./types.js";
|
|
26
|
+
import { type EnforceableSnapshot } from "./weakening.js";
|
|
25
27
|
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
26
28
|
export declare const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
27
29
|
/** Project-relative path of the pre-flight artifact the agent must produce. */
|
|
@@ -40,6 +42,13 @@ export type ArtifactState = "missing" | "empty" | "present";
|
|
|
40
42
|
* Never throws — unreadable files count as missing.
|
|
41
43
|
*/
|
|
42
44
|
export declare function artifactState(directory: string, relPath: string): Promise<ArtifactState>;
|
|
45
|
+
/**
|
|
46
|
+
* Grade the peer-review artifact including substance (plan 17 §3).
|
|
47
|
+
* Never throws — unreadable files count as missing. Thin or
|
|
48
|
+
* template content names the duty-escape on the record instead of
|
|
49
|
+
* passing a checkbox note.
|
|
50
|
+
*/
|
|
51
|
+
export declare function readReviewState(directory: string): Promise<ReviewState>;
|
|
43
52
|
/**
|
|
44
53
|
* Parse `git status --porcelain=v1` output into repo-relative changed paths.
|
|
45
54
|
* Handles renames (`R old -> new` — keeps the new path) and dedupes.
|
|
@@ -69,14 +78,14 @@ export type CompletionVerdict = {
|
|
|
69
78
|
note?: string;
|
|
70
79
|
} | {
|
|
71
80
|
decision: "blocked";
|
|
72
|
-
reason: "gate" | "review";
|
|
81
|
+
reason: "gate" | "review" | "weakened";
|
|
73
82
|
summary: string;
|
|
74
83
|
blockCount: number;
|
|
75
84
|
maxBlocks: number;
|
|
76
85
|
changedFiles: string[];
|
|
77
86
|
} | {
|
|
78
87
|
decision: "standdown";
|
|
79
|
-
reason: "gate" | "review";
|
|
88
|
+
reason: "gate" | "review" | "weakened";
|
|
80
89
|
summary: string;
|
|
81
90
|
changedFiles: string[];
|
|
82
91
|
};
|
|
@@ -94,6 +103,13 @@ export interface CompletionDeps {
|
|
|
94
103
|
lintLimiter?: LintLimiter;
|
|
95
104
|
/** Session pass cache; skips redundant gate suites across idle boundaries. */
|
|
96
105
|
passCache?: PassCache;
|
|
106
|
+
/**
|
|
107
|
+
* Session-start enforceable snapshot (plan 17 §2). When present, a
|
|
108
|
+
* mid-session duty reduction blocks in standard/strict (reason
|
|
109
|
+
* `"weakened"`) and warns in advisory. Absent (e.g. manual
|
|
110
|
+
* `/df-verify`), the live contract evaluates as-is.
|
|
111
|
+
*/
|
|
112
|
+
baseline?: EnforceableSnapshot;
|
|
97
113
|
}
|
|
98
114
|
/**
|
|
99
115
|
* Side-effect-free inputs for a completion inspection, with one deliberate
|
|
@@ -123,6 +139,14 @@ export interface InspectionDeps {
|
|
|
123
139
|
* never are, so loud reporting is preserved.
|
|
124
140
|
*/
|
|
125
141
|
passCache?: PassCache;
|
|
142
|
+
/**
|
|
143
|
+
* Session-start enforceable snapshot (plan 17 §2). When present, a
|
|
144
|
+
* mid-session duty reduction fails the inspection (`ok: false`) with
|
|
145
|
+
* the reductions listed in `weakenings` and leading the summary.
|
|
146
|
+
* Absent (e.g. manual `/df-verify`), the live contract evaluates
|
|
147
|
+
* as-is.
|
|
148
|
+
*/
|
|
149
|
+
baseline?: EnforceableSnapshot;
|
|
126
150
|
}
|
|
127
151
|
/**
|
|
128
152
|
* Fingerprint of the last clean pass. `key` is null when nothing is cached;
|
|
@@ -135,24 +159,29 @@ export interface PassCache {
|
|
|
135
159
|
/** Create an empty pass cache (one per session state). */
|
|
136
160
|
export declare function createPassCache(): PassCache;
|
|
137
161
|
/**
|
|
138
|
-
* Raw completion report. `ok` is the unadjudicated outcome (gate passed
|
|
139
|
-
* review satisfied); profiles, block counting,
|
|
140
|
-
* `evaluateCompletion`, and `verifyGate`
|
|
141
|
-
* PASS/FAIL verdict.
|
|
162
|
+
* Raw completion report. `ok` is the unadjudicated outcome (gate passed,
|
|
163
|
+
* review satisfied, and contract unweakened); profiles, block counting,
|
|
164
|
+
* and stand-down are applied by `evaluateCompletion`, and `verifyGate`
|
|
165
|
+
* reports `ok` verbatim as its PASS/FAIL verdict.
|
|
142
166
|
*/
|
|
143
167
|
export interface CompletionInspection {
|
|
144
168
|
changedFiles: string[];
|
|
145
169
|
report: GateReport;
|
|
146
170
|
reviewRequired: boolean;
|
|
147
|
-
|
|
171
|
+
/** Substance-graded review state (plan 17 §3): only `present` satisfies the duty. */
|
|
172
|
+
reviewState: ReviewState;
|
|
148
173
|
reviewMissing: boolean;
|
|
149
174
|
/** True when the gate short-circuited on `skip_unchanged` with no files. */
|
|
150
175
|
skipped: boolean;
|
|
151
|
-
/**
|
|
176
|
+
/** Mid-session duty reductions vs the session-start snapshot (empty when intact). */
|
|
177
|
+
weakenings: string[];
|
|
178
|
+
/** Raw outcome: gate ok AND review satisfied AND contract unweakened. No profile/policy applied. */
|
|
152
179
|
ok: boolean;
|
|
153
180
|
/** Human- and transcript-readable summary (gate detail or review notice). */
|
|
154
181
|
summary: string;
|
|
155
182
|
}
|
|
183
|
+
/** Lead section for a weakened-contract summary; the live gate detail follows. */
|
|
184
|
+
export declare function weakeningSection(weakenings: string[]): string;
|
|
156
185
|
/**
|
|
157
186
|
* Inspect the current completion state without mutating anything except the
|
|
158
187
|
* opted-in session pass-cache write-through: no tracker clearing, no
|
package/dist/harness.js
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
import { readFile, stat } from "node:fs/promises";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { runGate, summarizeGate } from "./gate.js";
|
|
22
|
+
import { assessReviewContent, templateReviewMessage, thinReviewMessage, } from "./review.js";
|
|
23
|
+
import { diffWeakening } from "./weakening.js";
|
|
22
24
|
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
23
25
|
export const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
24
26
|
/** Project-relative path of the pre-flight artifact the agent must produce. */
|
|
@@ -44,6 +46,22 @@ export async function artifactState(directory, relPath) {
|
|
|
44
46
|
return "missing";
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Grade the peer-review artifact including substance (plan 17 §3).
|
|
51
|
+
* Never throws — unreadable files count as missing. Thin or
|
|
52
|
+
* template content names the duty-escape on the record instead of
|
|
53
|
+
* passing a checkbox note.
|
|
54
|
+
*/
|
|
55
|
+
export async function readReviewState(directory) {
|
|
56
|
+
let content;
|
|
57
|
+
try {
|
|
58
|
+
content = await readFile(join(directory, REVIEW_ARTIFACT_REL), "utf8");
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return "missing";
|
|
62
|
+
}
|
|
63
|
+
return assessReviewContent(content);
|
|
64
|
+
}
|
|
47
65
|
/**
|
|
48
66
|
* Parse `git status --porcelain=v1` output into repo-relative changed paths.
|
|
49
67
|
* Handles renames (`R old -> new` — keeps the new path) and dedupes.
|
|
@@ -179,6 +197,12 @@ async function passCacheKey(config, directory, changedFiles, reviewRequired) {
|
|
|
179
197
|
}
|
|
180
198
|
return `${gateConfig}\n${parts.join("\n")}\nreview:${review}`;
|
|
181
199
|
}
|
|
200
|
+
/** Lead section for a weakened-contract summary; the live gate detail follows. */
|
|
201
|
+
export function weakeningSection(weakenings) {
|
|
202
|
+
const lines = weakenings.map((w) => ` - ${w}`);
|
|
203
|
+
return (`opencode-dev-framework completion contract was weakened mid-session ` +
|
|
204
|
+
`(duties were reduced after the session started):\n${lines.join("\n")}`);
|
|
205
|
+
}
|
|
182
206
|
/**
|
|
183
207
|
* Inspect the current completion state without mutating anything except the
|
|
184
208
|
* opted-in session pass-cache write-through: no tracker clearing, no
|
|
@@ -201,6 +225,7 @@ export async function inspectCompletion(deps) {
|
|
|
201
225
|
reviewState: "present",
|
|
202
226
|
reviewMissing: false,
|
|
203
227
|
skipped: false,
|
|
228
|
+
weakenings: [],
|
|
204
229
|
ok: true,
|
|
205
230
|
summary: "completion gate disabled (profile off or no gate section)",
|
|
206
231
|
};
|
|
@@ -219,6 +244,13 @@ export async function inspectCompletion(deps) {
|
|
|
219
244
|
};
|
|
220
245
|
}
|
|
221
246
|
const reviewRequired = config.gate.require_review && changedFiles.length > 0;
|
|
247
|
+
// Mid-session duty reduction vs the session-start snapshot. Computed
|
|
248
|
+
// before the pass-cache lookup: the fingerprint does not cover the
|
|
249
|
+
// profile, so a weakened contract must never replay a cached pass.
|
|
250
|
+
// Only evaluated when the gate actually runs — a skipped gate (no
|
|
251
|
+
// changed files) has no duties to escape.
|
|
252
|
+
const weakenings = deps.baseline !== undefined ? diffWeakening(deps.baseline, config) : [];
|
|
253
|
+
const weakened = weakenings.length > 0;
|
|
222
254
|
// Fingerprint the tree the gate is about to validate, once. A hit replays
|
|
223
255
|
// the cached pass; a clean run stores this same pre-run key. Storing the
|
|
224
256
|
// pre-run (not post-run) state matters: an edit landing mid-gate-run
|
|
@@ -236,7 +268,8 @@ export async function inspectCompletion(deps) {
|
|
|
236
268
|
if (cachedKey !== undefined &&
|
|
237
269
|
cachedKey !== null &&
|
|
238
270
|
cachedSummary !== undefined &&
|
|
239
|
-
cachedSummary !== null
|
|
271
|
+
cachedSummary !== null &&
|
|
272
|
+
!weakened) {
|
|
240
273
|
if (fingerprint !== null && fingerprint === cachedKey) {
|
|
241
274
|
return {
|
|
242
275
|
changedFiles,
|
|
@@ -245,6 +278,7 @@ export async function inspectCompletion(deps) {
|
|
|
245
278
|
reviewState: "present",
|
|
246
279
|
reviewMissing: false,
|
|
247
280
|
skipped: false,
|
|
281
|
+
weakenings,
|
|
248
282
|
ok: true,
|
|
249
283
|
summary: cachedSummary,
|
|
250
284
|
};
|
|
@@ -255,28 +289,31 @@ export async function inspectCompletion(deps) {
|
|
|
255
289
|
lintLimiter: deps.lintLimiter,
|
|
256
290
|
});
|
|
257
291
|
const gateFailed = report.ran && !report.ok;
|
|
258
|
-
const reviewState = reviewRequired
|
|
259
|
-
? await artifactState(directory, REVIEW_ARTIFACT_REL)
|
|
260
|
-
: "present";
|
|
292
|
+
const reviewState = reviewRequired ? await readReviewState(directory) : "present";
|
|
261
293
|
const reviewMissing = reviewRequired && reviewState !== "present";
|
|
262
|
-
const ok = !gateFailed && !reviewMissing;
|
|
263
|
-
const
|
|
294
|
+
const ok = !gateFailed && !reviewMissing && !weakened;
|
|
295
|
+
const baseSummary = gateFailed
|
|
264
296
|
? summarizeGate(report)
|
|
265
|
-
:
|
|
266
|
-
?
|
|
267
|
-
:
|
|
268
|
-
?
|
|
269
|
-
:
|
|
297
|
+
: reviewState === "thin"
|
|
298
|
+
? thinReviewMessage(changedFiles)
|
|
299
|
+
: reviewState === "template"
|
|
300
|
+
? templateReviewMessage(changedFiles)
|
|
301
|
+
: reviewMissing
|
|
302
|
+
? reviewMissingMessage(changedFiles)
|
|
303
|
+
: report.ran
|
|
304
|
+
? `completion gate passed\n${summarizeGate(report)}`
|
|
305
|
+
: `completion gate passed (${report.reason ?? "nothing to run"})`;
|
|
306
|
+
const summary = weakened ? `${weakeningSection(weakenings)}\n\n${baseSummary}` : baseSummary;
|
|
270
307
|
if (deps.passCache !== undefined) {
|
|
271
|
-
if (!gateFailed && !reviewMissing && report.ran && fingerprint !== null) {
|
|
308
|
+
if (!gateFailed && !reviewMissing && !weakened && report.ran && fingerprint !== null) {
|
|
272
309
|
// Genuinely clean pass that actually ran — store the pre-run
|
|
273
|
-
// fingerprint for the next idle. Advisory problems (gateFailed)
|
|
274
|
-
// missing reviews never store; vacuous
|
|
275
|
-
// store nor clear.
|
|
310
|
+
// fingerprint for the next idle. Advisory problems (gateFailed),
|
|
311
|
+
// missing reviews, and weakened contracts never store; vacuous
|
|
312
|
+
// passes (nothing ran) neither store nor clear.
|
|
276
313
|
deps.passCache.key = fingerprint;
|
|
277
314
|
deps.passCache.summary = summary;
|
|
278
315
|
}
|
|
279
|
-
else if (gateFailed || reviewMissing) {
|
|
316
|
+
else if (gateFailed || reviewMissing || weakened) {
|
|
280
317
|
deps.passCache.key = null;
|
|
281
318
|
deps.passCache.summary = null;
|
|
282
319
|
}
|
|
@@ -287,6 +324,7 @@ export async function inspectCompletion(deps) {
|
|
|
287
324
|
reviewRequired,
|
|
288
325
|
reviewState,
|
|
289
326
|
reviewMissing,
|
|
327
|
+
weakenings,
|
|
290
328
|
skipped: false,
|
|
291
329
|
ok,
|
|
292
330
|
summary,
|
|
@@ -310,11 +348,13 @@ export async function evaluateCompletion(deps) {
|
|
|
310
348
|
trackerFiles: tracker.getChangedFiles(),
|
|
311
349
|
lintLimiter: deps.lintLimiter,
|
|
312
350
|
passCache: deps.passCache,
|
|
351
|
+
baseline: deps.baseline,
|
|
313
352
|
});
|
|
314
353
|
const { changedFiles, report } = inspection;
|
|
315
354
|
const gateFailed = report.ran && !report.ok;
|
|
316
355
|
const reviewMissing = inspection.reviewMissing;
|
|
317
|
-
|
|
356
|
+
const weakened = inspection.weakenings.length > 0;
|
|
357
|
+
if (!gateFailed && !reviewMissing && !weakened) {
|
|
318
358
|
tracker.clearChangedFiles();
|
|
319
359
|
await blockCounts.clear(sessionID);
|
|
320
360
|
await stuckSnapshots.clear(sessionID);
|
|
@@ -326,7 +366,8 @@ export async function evaluateCompletion(deps) {
|
|
|
326
366
|
note: report.ran || inspection.skipped ? inspection.summary : undefined,
|
|
327
367
|
};
|
|
328
368
|
}
|
|
329
|
-
// Advisory: report loudly, never block.
|
|
369
|
+
// Advisory: report loudly, never block. A weakened contract in advisory
|
|
370
|
+
// lands here too — visible in the log and the pass note, never a block.
|
|
330
371
|
if (!config.gate.block_on_failure) {
|
|
331
372
|
const summary = inspection.summary;
|
|
332
373
|
await deps.log("error", `completion gate (advisory — not blocking) saw problems:\n${summary}`);
|
|
@@ -336,7 +377,13 @@ export async function evaluateCompletion(deps) {
|
|
|
336
377
|
note: `completion gate (advisory — not blocking) saw problems:\n${summary}`,
|
|
337
378
|
};
|
|
338
379
|
}
|
|
339
|
-
|
|
380
|
+
// A weakened contract outranks the live gate outcome: the evidence was
|
|
381
|
+
// gathered against moved goalposts, so the verdict names that first.
|
|
382
|
+
const reason = weakened
|
|
383
|
+
? "weakened"
|
|
384
|
+
: gateFailed
|
|
385
|
+
? "gate"
|
|
386
|
+
: "review";
|
|
340
387
|
const summary = inspection.summary;
|
|
341
388
|
const maxBlocks = config.gate.max_blocks ?? 3;
|
|
342
389
|
// No-progress early stand-down (docs/plans/14-stuck-detection.md): consecutive blocked
|
|
@@ -344,12 +391,14 @@ export async function evaluateCompletion(deps) {
|
|
|
344
391
|
// zero information, so stop spending the budget on them. One
|
|
345
392
|
// investigate-then-fix cycle is tolerated (a single repeat still
|
|
346
393
|
// blocks); the third identical evaluation stands down.
|
|
347
|
-
const signature =
|
|
348
|
-
? `
|
|
349
|
-
|
|
350
|
-
.
|
|
351
|
-
|
|
352
|
-
|
|
394
|
+
const signature = weakened
|
|
395
|
+
? `weakened:${[...inspection.weakenings].sort().join("|")}`
|
|
396
|
+
: gateFailed
|
|
397
|
+
? `gate:${report.failedSteps
|
|
398
|
+
.map((s) => s.name)
|
|
399
|
+
.sort()
|
|
400
|
+
.join(",")}`
|
|
401
|
+
: `review:${inspection.reviewState}`;
|
|
353
402
|
const files = [...changedFiles].sort();
|
|
354
403
|
const previous = await stuckSnapshots.get(sessionID);
|
|
355
404
|
const noProgress = previous !== undefined &&
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* - ctx.tool.transform(...) -> custom tools
|
|
13
13
|
* - ctx.command.transform(...) -> server-side `/df-goal` verified-goal
|
|
14
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)
|
|
15
18
|
*
|
|
16
19
|
* Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
|
|
17
20
|
* (same execution) we run the gate and if it fails inside budget we admit
|
|
@@ -28,9 +31,17 @@ import { type RunCommand } from "./host.js";
|
|
|
28
31
|
import { type LintLimiter } from "./lint.js";
|
|
29
32
|
import { type LogFn } from "./logger.js";
|
|
30
33
|
import type { ResolvedConfig } from "./types.js";
|
|
34
|
+
import { type EnforceableSnapshot } from "./weakening.js";
|
|
31
35
|
export interface HookState {
|
|
32
36
|
directory: string;
|
|
33
37
|
config: ResolvedConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Session-start enforceable snapshot (plan 17 §2). Compared against the
|
|
40
|
+
* live config at every gate evaluation so mid-session duty reductions
|
|
41
|
+
* surface in the verdict. Never re-baselined — including across
|
|
42
|
+
* `set_profile` — so a profile downgrade reads as the weakening it is.
|
|
43
|
+
*/
|
|
44
|
+
initialEnforceable: EnforceableSnapshot;
|
|
34
45
|
log: LogFn;
|
|
35
46
|
run: RunCommand;
|
|
36
47
|
tracker: ChangedFileTracker;
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* - ctx.tool.transform(...) -> custom tools
|
|
13
13
|
* - ctx.command.transform(...) -> server-side `/df-goal` verified-goal
|
|
14
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)
|
|
15
18
|
*
|
|
16
19
|
* Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
|
|
17
20
|
* (same execution) we run the gate and if it fails inside budget we admit
|
|
@@ -32,7 +35,9 @@ import { createLintLimiter, detectPreCommitAvailability, isLintFailure, lintFile
|
|
|
32
35
|
import { createLogger } from "./logger.js";
|
|
33
36
|
import { checkToolCall, extractFilePath, FILE_TOOLS, toPermissionGuard } from "./protect.js";
|
|
34
37
|
import { constitutionPresent, loadConstitution } from "./rules.js";
|
|
38
|
+
import { findRosterIndex, renderDutyRoster, rosterPresent } from "./roster.js";
|
|
35
39
|
import { writeRuntimeStatus } from "./runtime-status.js";
|
|
40
|
+
import { snapshotEnforceable } from "./weakening.js";
|
|
36
41
|
let activeState = null;
|
|
37
42
|
let fallbackLog = async () => { };
|
|
38
43
|
/**
|
|
@@ -97,7 +102,9 @@ async function reloadConfigIfChanged(state) {
|
|
|
97
102
|
function continuationMessage(verdict) {
|
|
98
103
|
const why = verdict.reason === "review"
|
|
99
104
|
? "the peer-review requirement is unmet"
|
|
100
|
-
:
|
|
105
|
+
: verdict.reason === "weakened"
|
|
106
|
+
? "the completion contract was weakened mid-session"
|
|
107
|
+
: "the repo's checks are failing";
|
|
101
108
|
return (`opencode-dev-framework completion gate blocked you from finishing because ${why} ` +
|
|
102
109
|
`(block ${verdict.blockCount}/${verdict.maxBlocks}).\n\n${verdict.summary}\n\n` +
|
|
103
110
|
`Fix the underlying cause and continue. Do NOT disable, skip, or weaken these checks to ` +
|
|
@@ -165,6 +172,7 @@ function runCompletion(state, sessionID) {
|
|
|
165
172
|
stuckSnapshots: state.stuckSnapshots,
|
|
166
173
|
lintLimiter: state.lintLimiter,
|
|
167
174
|
passCache: state.passCache,
|
|
175
|
+
baseline: state.initialEnforceable,
|
|
168
176
|
log: (level, message, extra) => safeLog(state, level, message, extra),
|
|
169
177
|
});
|
|
170
178
|
}
|
|
@@ -279,6 +287,7 @@ const plugin = Plugin.define({
|
|
|
279
287
|
const state = {
|
|
280
288
|
directory,
|
|
281
289
|
config,
|
|
290
|
+
initialEnforceable: snapshotEnforceable(config),
|
|
282
291
|
log,
|
|
283
292
|
run: runCommand,
|
|
284
293
|
tracker,
|
|
@@ -325,17 +334,30 @@ const plugin = Plugin.define({
|
|
|
325
334
|
if (state.config.profile === "off")
|
|
326
335
|
return;
|
|
327
336
|
const constitution = state.constitution;
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
337
|
+
if (constitution) {
|
|
338
|
+
// V2 system is Array<SystemPart> {type:"text", text:string}
|
|
339
|
+
const already = constitutionPresent(event.system, constitution);
|
|
340
|
+
if (!already) {
|
|
341
|
+
event.system.push({
|
|
342
|
+
type: "text",
|
|
343
|
+
text: constitution,
|
|
344
|
+
});
|
|
345
|
+
await safeLog(state, "info", "constitution injected into system prompt");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const roster = renderDutyRoster(state.config);
|
|
349
|
+
if (roster) {
|
|
350
|
+
if (!rosterPresent(event.system, roster)) {
|
|
351
|
+
const at = findRosterIndex(event.system);
|
|
352
|
+
if (at >= 0) {
|
|
353
|
+
event.system[at].text = roster;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
event.system.push({ type: "text", text: roster });
|
|
357
|
+
}
|
|
358
|
+
await safeLog(state, "debug", "duty roster injected into system prompt");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
339
361
|
}));
|
|
340
362
|
// Also hook other request kinds so the reminder is not missed on title/generate
|
|
341
363
|
// (no-op if model doesn't need it; cheap)
|
|
@@ -619,7 +641,7 @@ const plugin = Plugin.define({
|
|
|
619
641
|
trackRegistration(await ctx.tool.transform((editor) => {
|
|
620
642
|
editor.add({
|
|
621
643
|
name: "dev_framework_init",
|
|
622
|
-
description: "Scaffold opencode-dev-framework project files (agents, skills, commands, default config) into the current project. Missing files are created; existing files are skipped unless overwrite is true. With wizard:true, appends a wizard brief (detection, trial-run, Makefile targets, open questions) — follow the project-config skill to resolve it and present the config for review.",
|
|
644
|
+
description: "Scaffold opencode-dev-framework project files (agents, skills, commands, default config) into the current project. Missing files are created; existing files are skipped unless overwrite is true. With wizard:true, appends a wizard brief (detection, trial-run, Makefile targets, open questions) when the scaffold changed anything, or a status note when already configured — follow the project-config skill to resolve it and present the config for review.",
|
|
623
645
|
input: {
|
|
624
646
|
type: "object",
|
|
625
647
|
properties: {
|
|
@@ -639,49 +661,14 @@ const plugin = Plugin.define({
|
|
|
639
661
|
additionalProperties: false,
|
|
640
662
|
},
|
|
641
663
|
async execute(input) {
|
|
642
|
-
const {
|
|
664
|
+
const { runInitScaffold, scaffoldReportLines } = await import("./init.js");
|
|
643
665
|
const args = input;
|
|
644
666
|
const targetDir = args.directory ?? directory;
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
667
|
+
const scaffold = await runInitScaffold(targetDir, state.run, {
|
|
668
|
+
wizard: args.wizard,
|
|
669
|
+
overwrite: args.overwrite,
|
|
648
670
|
});
|
|
649
|
-
|
|
650
|
-
overwriteExisting: args.overwrite ?? false,
|
|
651
|
-
skipExisting: !(args.overwrite ?? false),
|
|
652
|
-
});
|
|
653
|
-
const lines = [
|
|
654
|
-
`Installed opencode-dev-framework templates into ${targetDir}.`,
|
|
655
|
-
`Created: ${result.created.length} file(s)`,
|
|
656
|
-
`Overwritten: ${result.overwritten.length} file(s)`,
|
|
657
|
-
`Skipped: ${result.skipped.length} file(s)`,
|
|
658
|
-
`Config: ${configResult.action}`,
|
|
659
|
-
];
|
|
660
|
-
if (result.created.length > 0)
|
|
661
|
-
lines.push("", "Created files:", ...result.created.map((f) => `- ${f}`));
|
|
662
|
-
if (result.overwritten.length > 0)
|
|
663
|
-
lines.push("", "Overwritten files:", ...result.overwritten.map((f) => `- ${f}`));
|
|
664
|
-
if (args.wizard === true) {
|
|
665
|
-
try {
|
|
666
|
-
const brief = await buildWizardBrief(targetDir, state.run);
|
|
667
|
-
lines.push("", ...formatWizardBrief(brief));
|
|
668
|
-
}
|
|
669
|
-
catch (error) {
|
|
670
|
-
lines.push("", formatBriefSkipped(error));
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
else if (configResult.action === "created" || configResult.action === "overwritten") {
|
|
674
|
-
try {
|
|
675
|
-
const { detectProject } = await import("./detect.js");
|
|
676
|
-
const { commands } = detectProject(targetDir);
|
|
677
|
-
const trial = await trialRunDetectedCommands(targetDir, commands, state.run);
|
|
678
|
-
lines.push("", ...formatTrialRun(trial));
|
|
679
|
-
}
|
|
680
|
-
catch (error) {
|
|
681
|
-
lines.push("", `Trial-run: skipped (${error instanceof Error ? error.message : String(error)}) — verify commands manually`);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return { content: lines.join("\n") };
|
|
671
|
+
return { content: scaffoldReportLines(scaffold, targetDir).join("\n") };
|
|
685
672
|
},
|
|
686
673
|
});
|
|
687
674
|
editor.add({
|
|
@@ -843,6 +830,73 @@ const plugin = Plugin.define({
|
|
|
843
830
|
error: String(err),
|
|
844
831
|
});
|
|
845
832
|
}
|
|
833
|
+
// 3c) Per-project setup — server-side `/df-init` through
|
|
834
|
+
// `ctx.command.transform` (same shape as `/df-goal`). Runs the
|
|
835
|
+
// deterministic half in code (scaffold templates, detected config,
|
|
836
|
+
// trial-run, wizard brief) and submits the handoff back through
|
|
837
|
+
// `session.prompt` with the invocation delivery, so the agent does
|
|
838
|
+
// the judgment half (resolve the brief, draft config + hardening,
|
|
839
|
+
// present the diff). Unconditional registration: a project with no
|
|
840
|
+
// config file yet is exactly where init runs.
|
|
841
|
+
try {
|
|
842
|
+
trackRegistration(await ctx.command.transform((editor) => {
|
|
843
|
+
editor.add({
|
|
844
|
+
name: "df-init",
|
|
845
|
+
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.",
|
|
846
|
+
execute: async (invocation) => {
|
|
847
|
+
if (activeState !== state) {
|
|
848
|
+
throw new Error("Cannot start project setup: the plugin session state changed " +
|
|
849
|
+
"(teardown or reload raced the command); retry /df-init.");
|
|
850
|
+
}
|
|
851
|
+
const { runInitCommand } = await import("./init.js");
|
|
852
|
+
await runInitCommand({
|
|
853
|
+
directory: state.directory,
|
|
854
|
+
run: state.run,
|
|
855
|
+
delivery: invocation.delivery,
|
|
856
|
+
checkAlive: () => {
|
|
857
|
+
if (activeState !== state) {
|
|
858
|
+
throw new Error("Project setup was superseded mid-scaffold (teardown or reload raced the command); " +
|
|
859
|
+
"retry /df-init — a re-run reports status without touching anything.");
|
|
860
|
+
}
|
|
861
|
+
},
|
|
862
|
+
reload: async () => {
|
|
863
|
+
const { clearConfigCache: ccc, loadConfig: lc } = await import("./config.js");
|
|
864
|
+
const { loadConstitution: lc2 } = await import("./rules.js");
|
|
865
|
+
ccc();
|
|
866
|
+
const newConfig = lc(state.directory);
|
|
867
|
+
const { constitution: newConstitution } = await lc2(newConfig, state.directory);
|
|
868
|
+
state.config = newConfig;
|
|
869
|
+
state.constitution = newConstitution;
|
|
870
|
+
for (const name of [".opencode-dev-framework.yml", ".dev-framework.yml"]) {
|
|
871
|
+
try {
|
|
872
|
+
state.configMtime = (await stat(join(state.directory, name))).mtimeMs;
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
catch {
|
|
876
|
+
// continue to fallback name
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
},
|
|
880
|
+
deliver: async (text, delivery) => {
|
|
881
|
+
await ctx.session.prompt({
|
|
882
|
+
sessionID: invocation.sessionID,
|
|
883
|
+
text,
|
|
884
|
+
delivery,
|
|
885
|
+
});
|
|
886
|
+
},
|
|
887
|
+
note: async (level, message, extra) => {
|
|
888
|
+
await safeLog(state, level, message, extra);
|
|
889
|
+
},
|
|
890
|
+
});
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
}));
|
|
894
|
+
}
|
|
895
|
+
catch (err) {
|
|
896
|
+
await safeLog(state, "warn", "could not register df-init command; project setup unavailable", {
|
|
897
|
+
error: String(err),
|
|
898
|
+
});
|
|
899
|
+
}
|
|
846
900
|
// 4) Event subscription — file tracking + gate enforcement net.
|
|
847
901
|
// Runs the gate on `session.idle` for the boundaries the §1b hook
|
|
848
902
|
// skipped (interruption, failure, steer-parked drains) or for builds
|