opencode-dev-framework 1.6.0 → 1.8.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 +38 -42
- package/dist/format-status.js +1 -0
- package/dist/harness.d.ts +20 -6
- package/dist/harness.js +49 -13
- package/dist/index.d.ts +3 -0
- package/dist/index.js +76 -41
- package/dist/init.d.ts +62 -0
- package/dist/init.js +143 -0
- package/dist/review.d.ts +16 -1
- package/dist/review.js +47 -0
- package/package.json +1 -1
- package/templates/.opencode/skills/project-config/SKILL.md +3 -2
package/README.md
CHANGED
|
@@ -11,54 +11,45 @@ An [OpenCode](https://opencode.ai) plugin that enforces project-specific
|
|
|
11
11
|
quality gates during AI coding sessions — and verifies whole tasks, not just
|
|
12
12
|
edits, through `/df-goal`. Inspired by
|
|
13
13
|
[anticomputer/dev-framework](https://github.com/anticomputer/dev-framework),
|
|
14
|
-
reimplemented
|
|
14
|
+
reimplemented for OpenCode (the original supports Copilot, Claude, and Codex).
|
|
15
15
|
|
|
16
16
|
## Quickstart
|
|
17
17
|
|
|
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
|
-
|
|
28
|
-
}
|
|
24
|
+
In any project, run:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
/df-init
|
|
29
28
|
```
|
|
30
29
|
|
|
30
|
+
It scaffolds the templates, writes a detected config, trial-runs it, and
|
|
31
|
+
hands your session agent a brief — what was detected, what passed, Makefile
|
|
32
|
+
targets worth mapping to wrappers, at most 3 open questions. The agent
|
|
33
|
+
resolves what it can, asks only genuinely user-only questions, and ends with
|
|
34
|
+
a config + `hardening.md` draft for your review. Budget ~5 minutes,
|
|
35
|
+
review-only at the end; imperfections assumed, manual always possible.
|
|
36
|
+
|
|
37
|
+
Prefer a shell? Same thing non-interactively — for CI, dotfiles, and
|
|
38
|
+
scripted runs:
|
|
39
|
+
|
|
31
40
|
```bash
|
|
32
|
-
npx df init
|
|
41
|
+
npx df init
|
|
33
42
|
```
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
user-only questions, and ends with a config + hardening draft for your
|
|
42
|
-
review. Budget ~5 minutes, review-only at the end; imperfections
|
|
43
|
-
assumed, manual always possible.
|
|
44
|
-
- **Fast.** `df init` alone: scaffold + trial-run with PASS/FAIL per
|
|
45
|
-
command. Good guesses arrive verified, bad ones arrive flagged — but
|
|
46
|
-
mapping wrappers (e.g. `make check`) is on you.
|
|
47
|
-
- **Thorough.** Ask the agent to follow the `project-config` skill from
|
|
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
|
|
53
|
-
checked against guardrails before it lands, your linter runs on the edited
|
|
54
|
-
file, and when the session goes idle the completion gate runs your
|
|
44
|
+
Conflicts need `--overwrite-existing` or `--skip-existing` — everything
|
|
45
|
+
else is under `npx df init --help`.
|
|
46
|
+
|
|
47
|
+
Then ask the agent for a small edit. You will see the plugin working: the
|
|
48
|
+
edit is checked against guardrails before it lands, your linter runs on the
|
|
49
|
+
edited file, and when the session goes idle the completion gate runs your
|
|
55
50
|
typecheck/tests. `/df-status` shows the live state at any time. Start with
|
|
56
51
|
`profile: advisory` if you want to observe before enforcing.
|
|
57
52
|
|
|
58
|
-
Requires OpenCode `v2.x` — tested on `v2.0.26` and `v2.2.0`. On
|
|
59
|
-
`v1.18.18–1.18.31` use the `v1` branch (`plugin` key). Stuck? See
|
|
60
|
-
[`docs/user/troubleshooting.md`](docs/user/troubleshooting.md).
|
|
61
|
-
|
|
62
53
|
## What it does
|
|
63
54
|
|
|
64
55
|
- **Constitution injection.** Adds a project quality bar to the system prompt
|
|
@@ -163,22 +154,27 @@ How each layer is enforced, and what it honestly cannot do:
|
|
|
163
154
|
| `/df-help` | Instant modal: lists the dev-framework commands. |
|
|
164
155
|
| `/df-profile` | Instant modal picker (or `/df-profile <name>`): switches profile now, written to config. |
|
|
165
156
|
| `/df-verify` | Runs the verification suite manually; pass/fail summary in a modal. |
|
|
157
|
+
| `/df-init` | Server-side command: scaffolds templates, writes the detected config, trial-runs it, hands the brief to the agent. |
|
|
166
158
|
| `/df-goal <objective>` | Server-side command: starts a **verified** native goal (requires native `/goal`, a blocking profile, and at least one real check). |
|
|
167
159
|
|
|
168
|
-
The
|
|
169
|
-
|
|
160
|
+
The TUI commands open instantly and never feed the LLM; `/df-init` and
|
|
161
|
+
`/df-goal` are server-side and drive the session. Full reference:
|
|
170
162
|
[`docs/user/commands.md`](docs/user/commands.md).
|
|
171
163
|
|
|
172
164
|
## Limitations (short version)
|
|
173
165
|
|
|
174
|
-
The completion gate **steers, it does not veto**: it continues the turn
|
|
175
|
-
synthetic message at the idle boundary
|
|
176
|
-
when the failure repeats with no new edits)
|
|
177
|
-
can always close the session.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
166
|
+
- The completion gate **steers, it does not veto**: it continues the turn
|
|
167
|
+
via a synthetic message at the idle boundary — bounded by
|
|
168
|
+
`gate.max_blocks` (fewer when the failure repeats with no new edits) —
|
|
169
|
+
and you can always close the session.
|
|
170
|
+
- A genuine pre-stop veto is proposed upstream
|
|
171
|
+
([`anomalyco/opencode#54487`](https://github.com/anomalyco/opencode/pull/54487),
|
|
172
|
+
open) — if it lands, the gate vetoes there instead of continuing.
|
|
173
|
+
- The **pre-flight** gate is the one genuine hard block today.
|
|
174
|
+
- Guardrails add to OpenCode permissions, never replace them.
|
|
175
|
+
- Formatters and linters are yours — the plugin runs them, it does not
|
|
176
|
+
reimplement them.
|
|
177
|
+
|
|
182
178
|
Full story: [`docs/user/enforcement.md`](docs/user/enforcement.md).
|
|
183
179
|
|
|
184
180
|
## Troubleshooting
|
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
|
@@ -43,12 +43,26 @@ export type ArtifactState = "missing" | "empty" | "present";
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function artifactState(directory: string, relPath: string): Promise<ArtifactState>;
|
|
45
45
|
/**
|
|
46
|
-
* Grade the peer-review artifact including substance (plan 17 §3)
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* Grade the peer-review artifact including substance (plan 17 §3) and
|
|
47
|
+
* freshness (plan 18): a substantive review of the wrong task reports
|
|
48
|
+
* `stale` unless it names every file this session changed. Never throws
|
|
49
|
+
* — unreadable files count as missing. Thin or template content names the
|
|
50
|
+
* duty-escape on the record instead of passing a checkbox note.
|
|
50
51
|
*/
|
|
51
|
-
export declare function readReviewState(directory: string): Promise<ReviewState>;
|
|
52
|
+
export declare function readReviewState(directory: string, changedFiles?: string[]): Promise<ReviewState>;
|
|
53
|
+
/**
|
|
54
|
+
* Files the freshness check covers: everything the session changed except
|
|
55
|
+
* the plugin's own bookkeeping, which the agent did not author — the
|
|
56
|
+
* review artifact itself (always tracked once written; self-reference
|
|
57
|
+
* would be absurd) and the runtime snapshot (plugin-written every
|
|
58
|
+
* continuation; surfaces via git where `.opencode/` is not ignored).
|
|
59
|
+
*/
|
|
60
|
+
export declare function coverableChangedFiles(directory: string, changedFiles: string[]): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Uncovered files for the stale-review message. Empty when the artifact is
|
|
63
|
+
* unreadable — that path already reports `missing`, never `stale`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function uncoveredReviewFiles(directory: string, changedFiles: string[]): Promise<string[]>;
|
|
52
66
|
/**
|
|
53
67
|
* Parse `git status --porcelain=v1` output into repo-relative changed paths.
|
|
54
68
|
* Handles renames (`R old -> new` — keeps the new path) and dedupes.
|
|
@@ -168,7 +182,7 @@ export interface CompletionInspection {
|
|
|
168
182
|
changedFiles: string[];
|
|
169
183
|
report: GateReport;
|
|
170
184
|
reviewRequired: boolean;
|
|
171
|
-
/** Substance-graded review state (
|
|
185
|
+
/** Substance- and freshness-graded review state (plans 17 §3, 18): only `present` satisfies the duty. */
|
|
172
186
|
reviewState: ReviewState;
|
|
173
187
|
reviewMissing: boolean;
|
|
174
188
|
/** True when the gate short-circuited on `skip_unchanged` with no files. */
|
package/dist/harness.js
CHANGED
|
@@ -19,7 +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";
|
|
22
|
+
import { assessReviewContent, findUncoveredFiles, normalizeReviewPath, staleReviewMessage, templateReviewMessage, thinReviewMessage, } from "./review.js";
|
|
23
|
+
import { RUNTIME_STATUS_DIR, RUNTIME_STATUS_FILE } from "./runtime-status.js";
|
|
23
24
|
import { diffWeakening } from "./weakening.js";
|
|
24
25
|
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
25
26
|
export const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
@@ -47,12 +48,13 @@ export async function artifactState(directory, relPath) {
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
|
-
* Grade the peer-review artifact including substance (plan 17 §3)
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* Grade the peer-review artifact including substance (plan 17 §3) and
|
|
52
|
+
* freshness (plan 18): a substantive review of the wrong task reports
|
|
53
|
+
* `stale` unless it names every file this session changed. Never throws
|
|
54
|
+
* — unreadable files count as missing. Thin or template content names the
|
|
55
|
+
* duty-escape on the record instead of passing a checkbox note.
|
|
54
56
|
*/
|
|
55
|
-
export async function readReviewState(directory) {
|
|
57
|
+
export async function readReviewState(directory, changedFiles = []) {
|
|
56
58
|
let content;
|
|
57
59
|
try {
|
|
58
60
|
content = await readFile(join(directory, REVIEW_ARTIFACT_REL), "utf8");
|
|
@@ -60,7 +62,37 @@ export async function readReviewState(directory) {
|
|
|
60
62
|
catch {
|
|
61
63
|
return "missing";
|
|
62
64
|
}
|
|
63
|
-
|
|
65
|
+
const substance = assessReviewContent(content);
|
|
66
|
+
if (substance !== "present")
|
|
67
|
+
return substance;
|
|
68
|
+
return findUncoveredFiles(content, coverableChangedFiles(directory, changedFiles)).length > 0
|
|
69
|
+
? "stale"
|
|
70
|
+
: "present";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Files the freshness check covers: everything the session changed except
|
|
74
|
+
* the plugin's own bookkeeping, which the agent did not author — the
|
|
75
|
+
* review artifact itself (always tracked once written; self-reference
|
|
76
|
+
* would be absurd) and the runtime snapshot (plugin-written every
|
|
77
|
+
* continuation; surfaces via git where `.opencode/` is not ignored).
|
|
78
|
+
*/
|
|
79
|
+
export function coverableChangedFiles(directory, changedFiles) {
|
|
80
|
+
const owned = new Set([REVIEW_ARTIFACT_REL, `${RUNTIME_STATUS_DIR}/${RUNTIME_STATUS_FILE}`]);
|
|
81
|
+
return changedFiles.map((f) => normalizeReviewPath(f, directory)).filter((f) => !owned.has(f));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Uncovered files for the stale-review message. Empty when the artifact is
|
|
85
|
+
* unreadable — that path already reports `missing`, never `stale`.
|
|
86
|
+
*/
|
|
87
|
+
export async function uncoveredReviewFiles(directory, changedFiles) {
|
|
88
|
+
let content;
|
|
89
|
+
try {
|
|
90
|
+
content = await readFile(join(directory, REVIEW_ARTIFACT_REL), "utf8");
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
return findUncoveredFiles(content, coverableChangedFiles(directory, changedFiles));
|
|
64
96
|
}
|
|
65
97
|
/**
|
|
66
98
|
* Parse `git status --porcelain=v1` output into repo-relative changed paths.
|
|
@@ -289,7 +321,9 @@ export async function inspectCompletion(deps) {
|
|
|
289
321
|
lintLimiter: deps.lintLimiter,
|
|
290
322
|
});
|
|
291
323
|
const gateFailed = report.ran && !report.ok;
|
|
292
|
-
const reviewState = reviewRequired
|
|
324
|
+
const reviewState = reviewRequired
|
|
325
|
+
? await readReviewState(directory, changedFiles)
|
|
326
|
+
: "present";
|
|
293
327
|
const reviewMissing = reviewRequired && reviewState !== "present";
|
|
294
328
|
const ok = !gateFailed && !reviewMissing && !weakened;
|
|
295
329
|
const baseSummary = gateFailed
|
|
@@ -298,11 +332,13 @@ export async function inspectCompletion(deps) {
|
|
|
298
332
|
? thinReviewMessage(changedFiles)
|
|
299
333
|
: reviewState === "template"
|
|
300
334
|
? templateReviewMessage(changedFiles)
|
|
301
|
-
:
|
|
302
|
-
?
|
|
303
|
-
:
|
|
304
|
-
?
|
|
305
|
-
:
|
|
335
|
+
: reviewState === "stale"
|
|
336
|
+
? staleReviewMessage(changedFiles, await uncoveredReviewFiles(directory, changedFiles))
|
|
337
|
+
: reviewMissing
|
|
338
|
+
? reviewMissingMessage(changedFiles)
|
|
339
|
+
: report.ran
|
|
340
|
+
? `completion gate passed\n${summarizeGate(report)}`
|
|
341
|
+
: `completion gate passed (${report.reason ?? "nothing to run"})`;
|
|
306
342
|
const summary = weakened ? `${weakeningSection(weakenings)}\n\n${baseSummary}` : baseSummary;
|
|
307
343
|
if (deps.passCache !== undefined) {
|
|
308
344
|
if (!gateFailed && !reviewMissing && !weakened && report.ran && fingerprint !== null) {
|
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
|
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
|
|
@@ -638,7 +641,7 @@ const plugin = Plugin.define({
|
|
|
638
641
|
trackRegistration(await ctx.tool.transform((editor) => {
|
|
639
642
|
editor.add({
|
|
640
643
|
name: "dev_framework_init",
|
|
641
|
-
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.",
|
|
642
645
|
input: {
|
|
643
646
|
type: "object",
|
|
644
647
|
properties: {
|
|
@@ -658,49 +661,14 @@ const plugin = Plugin.define({
|
|
|
658
661
|
additionalProperties: false,
|
|
659
662
|
},
|
|
660
663
|
async execute(input) {
|
|
661
|
-
const {
|
|
664
|
+
const { runInitScaffold, scaffoldReportLines } = await import("./init.js");
|
|
662
665
|
const args = input;
|
|
663
666
|
const targetDir = args.directory ?? directory;
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
+
const scaffold = await runInitScaffold(targetDir, state.run, {
|
|
668
|
+
wizard: args.wizard,
|
|
669
|
+
overwrite: args.overwrite,
|
|
667
670
|
});
|
|
668
|
-
|
|
669
|
-
overwriteExisting: args.overwrite ?? false,
|
|
670
|
-
skipExisting: !(args.overwrite ?? false),
|
|
671
|
-
});
|
|
672
|
-
const lines = [
|
|
673
|
-
`Installed opencode-dev-framework templates into ${targetDir}.`,
|
|
674
|
-
`Created: ${result.created.length} file(s)`,
|
|
675
|
-
`Overwritten: ${result.overwritten.length} file(s)`,
|
|
676
|
-
`Skipped: ${result.skipped.length} file(s)`,
|
|
677
|
-
`Config: ${configResult.action}`,
|
|
678
|
-
];
|
|
679
|
-
if (result.created.length > 0)
|
|
680
|
-
lines.push("", "Created files:", ...result.created.map((f) => `- ${f}`));
|
|
681
|
-
if (result.overwritten.length > 0)
|
|
682
|
-
lines.push("", "Overwritten files:", ...result.overwritten.map((f) => `- ${f}`));
|
|
683
|
-
if (args.wizard === true) {
|
|
684
|
-
try {
|
|
685
|
-
const brief = await buildWizardBrief(targetDir, state.run);
|
|
686
|
-
lines.push("", ...formatWizardBrief(brief));
|
|
687
|
-
}
|
|
688
|
-
catch (error) {
|
|
689
|
-
lines.push("", formatBriefSkipped(error));
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
else if (configResult.action === "created" || configResult.action === "overwritten") {
|
|
693
|
-
try {
|
|
694
|
-
const { detectProject } = await import("./detect.js");
|
|
695
|
-
const { commands } = detectProject(targetDir);
|
|
696
|
-
const trial = await trialRunDetectedCommands(targetDir, commands, state.run);
|
|
697
|
-
lines.push("", ...formatTrialRun(trial));
|
|
698
|
-
}
|
|
699
|
-
catch (error) {
|
|
700
|
-
lines.push("", `Trial-run: skipped (${error instanceof Error ? error.message : String(error)}) — verify commands manually`);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return { content: lines.join("\n") };
|
|
671
|
+
return { content: scaffoldReportLines(scaffold, targetDir).join("\n") };
|
|
704
672
|
},
|
|
705
673
|
});
|
|
706
674
|
editor.add({
|
|
@@ -862,6 +830,73 @@ const plugin = Plugin.define({
|
|
|
862
830
|
error: String(err),
|
|
863
831
|
});
|
|
864
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
|
+
}
|
|
865
900
|
// 4) Event subscription — file tracking + gate enforcement net.
|
|
866
901
|
// Runs the gate on `session.idle` for the boundaries the §1b hook
|
|
867
902
|
// skipped (interruption, failure, steer-parked drains) or for builds
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared per-project setup flow: the `/df-init` server command and the
|
|
3
|
+
* `dev_framework_init` custom tool are two callers of one implementation.
|
|
4
|
+
* The deterministic half (scaffold templates, detected config, trial-run,
|
|
5
|
+
* brief) runs in code; the judgment half (resolve the brief, draft config
|
|
6
|
+
* + hardening, present the diff) rides back to the agent as prompt text.
|
|
7
|
+
*
|
|
8
|
+
* Note: `bin/df` intentionally keeps its own orchestration of the same
|
|
9
|
+
* installer primitives — the CLI prompts interactively on conflicts
|
|
10
|
+
* (TTY), while everything here is non-interactive by construction.
|
|
11
|
+
*/
|
|
12
|
+
import type { RunCommand } from "./host.js";
|
|
13
|
+
export interface InitScaffoldOptions {
|
|
14
|
+
wizard?: boolean;
|
|
15
|
+
/** Rewrite files that differ from the templates (default: skip them). */
|
|
16
|
+
overwrite?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface InitScaffold {
|
|
19
|
+
created: string[];
|
|
20
|
+
overwritten: string[];
|
|
21
|
+
skipped: string[];
|
|
22
|
+
configAction: string;
|
|
23
|
+
/** Trial-run lines (non-wizard) or wizard-brief lines, for the report. */
|
|
24
|
+
detailLines: string[];
|
|
25
|
+
/** True when this run changed anything (templates or config). */
|
|
26
|
+
fresh: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare function runInitScaffold(directory: string, run: RunCommand, options?: InitScaffoldOptions): Promise<InitScaffold>;
|
|
29
|
+
export declare function scaffoldReportLines(scaffold: InitScaffold, directory: string): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Compose the prompt text the `/df-init` command submits back to the
|
|
32
|
+
* session. A fresh scaffold hands the agent the brief plus standing
|
|
33
|
+
* instructions; a re-run on an already-configured project reports
|
|
34
|
+
* status. Skipped files may be identical OR differing-but-preserved —
|
|
35
|
+
* the counts cannot tell them apart, so the status says so instead of
|
|
36
|
+
* claiming everything is current.
|
|
37
|
+
*/
|
|
38
|
+
export declare function composeInitPrompt(scaffold: InitScaffold, directory: string, warnings?: string[]): string;
|
|
39
|
+
export interface InitCommandDeps {
|
|
40
|
+
directory: string;
|
|
41
|
+
run: RunCommand;
|
|
42
|
+
delivery: unknown;
|
|
43
|
+
/** Throws when the owning setup/state went stale mid-scaffold. */
|
|
44
|
+
checkAlive: () => void;
|
|
45
|
+
/** Reload the project config after scaffolding; throws on invalid config. */
|
|
46
|
+
reload: () => Promise<void>;
|
|
47
|
+
/** Deliver the handoff to the session; throws on transport failure. */
|
|
48
|
+
deliver: (text: string, delivery: unknown) => Promise<void>;
|
|
49
|
+
/** Side-channel observe (warn on reload failure). Never throws. */
|
|
50
|
+
note: (level: "warn", message: string, extra?: Record<string, unknown>) => Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Execute the `/df-init` command with injected dependencies (pure policy,
|
|
54
|
+
* testable without a plugin context). Scaffold first, re-check liveness
|
|
55
|
+
* across the long await (file IO + trial-runs), reload the just-written
|
|
56
|
+
* config, then deliver the handoff. A reload failure degrades to a
|
|
57
|
+
* warning inside the prompt — `/df-init` is the command you run to fix
|
|
58
|
+
* a broken setup, so it must not fail on exactly the broken setups.
|
|
59
|
+
* A delivery failure throws: the scaffold succeeded, only the handoff
|
|
60
|
+
* back failed, and the message says how to recover.
|
|
61
|
+
*/
|
|
62
|
+
export declare function runInitCommand(deps: InitCommandDeps): Promise<void>;
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared per-project setup flow: the `/df-init` server command and the
|
|
3
|
+
* `dev_framework_init` custom tool are two callers of one implementation.
|
|
4
|
+
* The deterministic half (scaffold templates, detected config, trial-run,
|
|
5
|
+
* brief) runs in code; the judgment half (resolve the brief, draft config
|
|
6
|
+
* + hardening, present the diff) rides back to the agent as prompt text.
|
|
7
|
+
*
|
|
8
|
+
* Note: `bin/df` intentionally keeps its own orchestration of the same
|
|
9
|
+
* installer primitives — the CLI prompts interactively on conflicts
|
|
10
|
+
* (TTY), while everything here is non-interactive by construction.
|
|
11
|
+
*/
|
|
12
|
+
import { detectProject } from "./detect.js";
|
|
13
|
+
import { buildWizardBrief, formatBriefSkipped, formatTrialRun, formatWizardBrief, installTemplates, trialRunDetectedCommands, writeDetectedConfig, } from "./installer.js";
|
|
14
|
+
export async function runInitScaffold(directory, run, options = {}) {
|
|
15
|
+
const overwrite = options.overwrite ?? false;
|
|
16
|
+
const io = { overwriteExisting: overwrite, skipExisting: !overwrite };
|
|
17
|
+
const result = await installTemplates(directory, io);
|
|
18
|
+
const configResult = await writeDetectedConfig(directory, io);
|
|
19
|
+
const fresh = result.created.length > 0 ||
|
|
20
|
+
result.overwritten.length > 0 ||
|
|
21
|
+
configResult.action === "created" ||
|
|
22
|
+
configResult.action === "overwritten";
|
|
23
|
+
// Detail work runs only when something changed: rebuilding the wizard
|
|
24
|
+
// brief (detection + real command executions) on a no-op re-run would
|
|
25
|
+
// burn minutes to restate what the report already says. Non-wizard
|
|
26
|
+
// keeps its exact historical trigger (config created/overwritten).
|
|
27
|
+
const detailLines = [];
|
|
28
|
+
const wantDetail = options.wizard === true
|
|
29
|
+
? fresh
|
|
30
|
+
: configResult.action === "created" || configResult.action === "overwritten";
|
|
31
|
+
if (wantDetail) {
|
|
32
|
+
if (options.wizard === true) {
|
|
33
|
+
try {
|
|
34
|
+
const brief = await buildWizardBrief(directory, run);
|
|
35
|
+
detailLines.push("", ...formatWizardBrief(brief));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
detailLines.push("", formatBriefSkipped(error));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
try {
|
|
43
|
+
const { commands } = detectProject(directory);
|
|
44
|
+
const trial = await trialRunDetectedCommands(directory, commands, run);
|
|
45
|
+
detailLines.push("", ...formatTrialRun(trial));
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
detailLines.push("", `Trial-run: skipped (${error instanceof Error ? error.message : String(error)}) — verify commands manually`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
created: result.created,
|
|
54
|
+
overwritten: result.overwritten,
|
|
55
|
+
skipped: result.skipped,
|
|
56
|
+
configAction: configResult.action,
|
|
57
|
+
detailLines,
|
|
58
|
+
fresh,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function scaffoldReportLines(scaffold, directory) {
|
|
62
|
+
return [
|
|
63
|
+
`Installed opencode-dev-framework templates into ${directory}.`,
|
|
64
|
+
`Created: ${scaffold.created.length} file(s)`,
|
|
65
|
+
`Overwritten: ${scaffold.overwritten.length} file(s)`,
|
|
66
|
+
`Skipped: ${scaffold.skipped.length} file(s)`,
|
|
67
|
+
`Config: ${scaffold.configAction}`,
|
|
68
|
+
...(scaffold.created.length > 0
|
|
69
|
+
? ["", "Created files:", ...scaffold.created.map((f) => `- ${f}`)]
|
|
70
|
+
: []),
|
|
71
|
+
...(scaffold.overwritten.length > 0
|
|
72
|
+
? ["", "Overwritten files:", ...scaffold.overwritten.map((f) => `- ${f}`)]
|
|
73
|
+
: []),
|
|
74
|
+
...scaffold.detailLines,
|
|
75
|
+
...(!scaffold.fresh
|
|
76
|
+
? ["", "Already configured: nothing changed, so no brief was rebuilt."]
|
|
77
|
+
: []),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Compose the prompt text the `/df-init` command submits back to the
|
|
82
|
+
* session. A fresh scaffold hands the agent the brief plus standing
|
|
83
|
+
* instructions; a re-run on an already-configured project reports
|
|
84
|
+
* status. Skipped files may be identical OR differing-but-preserved —
|
|
85
|
+
* the counts cannot tell them apart, so the status says so instead of
|
|
86
|
+
* claiming everything is current.
|
|
87
|
+
*/
|
|
88
|
+
export function composeInitPrompt(scaffold, directory, warnings = []) {
|
|
89
|
+
const warningLines = warnings.length > 0 ? [...warnings.map((w) => `Warning: ${w}`), ""] : [];
|
|
90
|
+
if (!scaffold.fresh) {
|
|
91
|
+
return [
|
|
92
|
+
`opencode-dev-framework is already set up in ${directory}: ` +
|
|
93
|
+
`config ${scaffold.configAction}, ${scaffold.skipped.length} template file(s) left untouched.`,
|
|
94
|
+
"Untouched means identical or differing-but-preserved — differing files were NOT refreshed.",
|
|
95
|
+
...warningLines,
|
|
96
|
+
"Verify with /df-status and a small probe edit; change nothing unless the user asks.",
|
|
97
|
+
].join("\n");
|
|
98
|
+
}
|
|
99
|
+
return [
|
|
100
|
+
...scaffoldReportLines(scaffold, directory),
|
|
101
|
+
...warningLines,
|
|
102
|
+
"",
|
|
103
|
+
"Set up opencode-dev-framework for this project from the report and brief above. " +
|
|
104
|
+
"Follow the project-config skill to resolve the open questions — ask at most 3 genuinely " +
|
|
105
|
+
"user-only questions, resolve the rest yourself by reading the repo and running the commands — " +
|
|
106
|
+
"then present .opencode-dev-framework.yml + hardening.md for review. Do not commit unreviewed.",
|
|
107
|
+
].join("\n");
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Execute the `/df-init` command with injected dependencies (pure policy,
|
|
111
|
+
* testable without a plugin context). Scaffold first, re-check liveness
|
|
112
|
+
* across the long await (file IO + trial-runs), reload the just-written
|
|
113
|
+
* config, then deliver the handoff. A reload failure degrades to a
|
|
114
|
+
* warning inside the prompt — `/df-init` is the command you run to fix
|
|
115
|
+
* a broken setup, so it must not fail on exactly the broken setups.
|
|
116
|
+
* A delivery failure throws: the scaffold succeeded, only the handoff
|
|
117
|
+
* back failed, and the message says how to recover.
|
|
118
|
+
*/
|
|
119
|
+
export async function runInitCommand(deps) {
|
|
120
|
+
const scaffold = await runInitScaffold(deps.directory, deps.run, { wizard: true });
|
|
121
|
+
deps.checkAlive();
|
|
122
|
+
const warnings = [];
|
|
123
|
+
try {
|
|
124
|
+
await deps.reload();
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
128
|
+
warnings.push(`the new config could not be reloaded (${detail}) — the session keeps its previous contract; restart or fix the config and re-run.`);
|
|
129
|
+
await deps.note("warn", "df-init scaffolded but the config could not be reloaded", {
|
|
130
|
+
directory: deps.directory,
|
|
131
|
+
error: detail,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const text = composeInitPrompt(scaffold, deps.directory, warnings);
|
|
135
|
+
try {
|
|
136
|
+
await deps.deliver(text, deps.delivery);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
140
|
+
throw new Error(`df-init scaffolded ${scaffold.created.length} file(s) (config ${scaffold.configAction}) ` +
|
|
141
|
+
`but the handoff back to the session failed (${detail}); retry /df-init — a re-run reports status without touching anything.`);
|
|
142
|
+
}
|
|
143
|
+
}
|
package/dist/review.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const REVIEW_MIN_CHARS = 200;
|
|
|
3
3
|
/** Whitespace-separated-token floor for a substantive review. */
|
|
4
4
|
export declare const REVIEW_MIN_WORDS = 30;
|
|
5
5
|
/** Review artifact state with substance gradations. */
|
|
6
|
-
export type ReviewState = "missing" | "empty" | "thin" | "template" | "present";
|
|
6
|
+
export type ReviewState = "missing" | "empty" | "thin" | "template" | "stale" | "present";
|
|
7
7
|
/**
|
|
8
8
|
* Assess already-read review content. Pure. Order matters: empty,
|
|
9
9
|
* then template markers (a short file with TODOs reports the more
|
|
@@ -12,3 +12,18 @@ export type ReviewState = "missing" | "empty" | "thin" | "template" | "present";
|
|
|
12
12
|
export declare function assessReviewContent(content: string): Exclude<ReviewState, "missing">;
|
|
13
13
|
export declare function thinReviewMessage(changedFiles: string[]): string;
|
|
14
14
|
export declare function templateReviewMessage(changedFiles: string[]): string;
|
|
15
|
+
/**
|
|
16
|
+
* Normalize a changed-file entry to the repo-relative `/`-separated form
|
|
17
|
+
* reviews are matched against. Tracker and git entries already arrive
|
|
18
|
+
* repo-relative; absolute entries under the project still match by
|
|
19
|
+
* relativizing, and separators normalize so Windows-style paths match.
|
|
20
|
+
*/
|
|
21
|
+
export declare function normalizeReviewPath(file: string, directory: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Changed files the review text does not cover (plan 18). A file counts as
|
|
24
|
+
* covered when the review names it — relative or absolute (absolute paths
|
|
25
|
+
* contain the relative form). Boundary-guarded so `b-a.ts` does not cover
|
|
26
|
+
* `a.ts` and `a.tsx` does not cover `a.ts`. Pure.
|
|
27
|
+
*/
|
|
28
|
+
export declare function findUncoveredFiles(content: string, files: string[]): string[];
|
|
29
|
+
export declare function staleReviewMessage(changedFiles: string[], uncovered: string[]): string;
|
package/dist/review.js
CHANGED
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
* it only puts checkboxing on the record for honest-but-eager
|
|
15
15
|
* agents.
|
|
16
16
|
*
|
|
17
|
+
* Freshness (plan 18) sits beside substance: a substantive review of
|
|
18
|
+
* the *wrong task* fails as `stale` unless it names every file this
|
|
19
|
+
* session changed. Same out-of-scope line — deliberate misnaming
|
|
20
|
+
* (naming files without reviewing them) is sabotage, not eagerness.
|
|
21
|
+
*
|
|
17
22
|
* The artifact path literal mirrors `REVIEW_ARTIFACT_REL` in
|
|
18
23
|
* `harness.ts` (kept inline to avoid a module cycle; both are
|
|
19
24
|
* pinned by tests).
|
|
@@ -86,3 +91,45 @@ export function templateReviewMessage(changedFiles) {
|
|
|
86
91
|
`and resolutions, with every placeholder replaced by real findings.\n\n` +
|
|
87
92
|
reviewCadenceReminder());
|
|
88
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Escape a literal for embedding in a RegExp.
|
|
96
|
+
*/
|
|
97
|
+
function escapeRegExp(literal) {
|
|
98
|
+
return literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Normalize a changed-file entry to the repo-relative `/`-separated form
|
|
102
|
+
* reviews are matched against. Tracker and git entries already arrive
|
|
103
|
+
* repo-relative; absolute entries under the project still match by
|
|
104
|
+
* relativizing, and separators normalize so Windows-style paths match.
|
|
105
|
+
*/
|
|
106
|
+
export function normalizeReviewPath(file, directory) {
|
|
107
|
+
let rel = file;
|
|
108
|
+
if (rel.startsWith(directory) &&
|
|
109
|
+
(rel[directory.length] === "/" || rel[directory.length] === "\\")) {
|
|
110
|
+
rel = rel.slice(directory.length + 1);
|
|
111
|
+
}
|
|
112
|
+
return rel.replace(/\\/g, "/");
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Changed files the review text does not cover (plan 18). A file counts as
|
|
116
|
+
* covered when the review names it — relative or absolute (absolute paths
|
|
117
|
+
* contain the relative form). Boundary-guarded so `b-a.ts` does not cover
|
|
118
|
+
* `a.ts` and `a.tsx` does not cover `a.ts`. Pure.
|
|
119
|
+
*/
|
|
120
|
+
export function findUncoveredFiles(content, files) {
|
|
121
|
+
return files.filter((file) => {
|
|
122
|
+
const pattern = new RegExp(`(?<![\\w-])${escapeRegExp(file)}(?![\\w-])`);
|
|
123
|
+
return !pattern.test(content);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
export function staleReviewMessage(changedFiles, uncovered) {
|
|
127
|
+
const files = changedFiles.map((f) => ` - ${f}`).join("\n");
|
|
128
|
+
const missing = uncovered.map((f) => ` - ${f}`).join("\n");
|
|
129
|
+
return (`opencode-dev-framework completion gate — the peer-review artifact is substantive ` +
|
|
130
|
+
`but stale: it does not cover this session's changes. Not mentioned:\n${missing}\n\n` +
|
|
131
|
+
`This session changed files:\n${files}\n\n` +
|
|
132
|
+
`Rewrite ${REVIEW_REL} fresh for THIS session's changes — scope, findings, ` +
|
|
133
|
+
`and resolutions, naming every file above.\n\n` +
|
|
134
|
+
reviewCadenceReminder());
|
|
135
|
+
}
|
package/package.json
CHANGED
|
@@ -20,9 +20,10 @@ detection alone. Also when the existing config smells wrong — gate
|
|
|
20
20
|
passing vacuously, commands that don't match CI, a red tree nobody can
|
|
21
21
|
explain.
|
|
22
22
|
|
|
23
|
-
## Wizard brief (when
|
|
23
|
+
## Wizard brief (when setup ran first)
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
`/df-init`, `dev_framework_init` (with `wizard: true`), or `df init --wizard`
|
|
26
|
+
hand you machine-generated hints before this skill runs: detected language, guessed
|
|
26
27
|
commands with trial-run results, Makefile target names, the shared
|
|
27
28
|
enforceability verdict, and at most 3 open questions. Treat it as a
|
|
28
29
|
starting brief, not findings:
|