opencode-dev-framework 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -24
- package/bin/df +33 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +38 -0
- package/dist/goal.js +4 -29
- package/dist/index.js +26 -2
- package/dist/installer.d.ts +72 -0
- package/dist/installer.js +180 -1
- package/package.json +1 -1
- package/templates/.opencode/skills/project-config/SKILL.md +101 -0
package/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# opencode-dev-framework
|
|
2
2
|
|
|
3
|
+
AI agents finish by *saying* they're done — and prose rules ("be
|
|
4
|
+
thorough", "run the tests") are interpretation surface a capable agent
|
|
5
|
+
routes around. This plugin replaces assertion with evidence: guardrails
|
|
6
|
+
that deny instead of advise, a completion gate that re-runs your checks
|
|
7
|
+
at the idle boundary, and verified goals whose contract requires a
|
|
8
|
+
tool-result PASS on the final tree. Exit codes don't negotiate.
|
|
9
|
+
|
|
3
10
|
An [OpenCode](https://opencode.ai) plugin that enforces project-specific
|
|
4
11
|
quality gates during AI coding sessions — and verifies whole tasks, not just
|
|
5
12
|
edits, through `/df-goal`. Inspired by
|
|
@@ -22,11 +29,26 @@ npm install opencode-dev-framework
|
|
|
22
29
|
```
|
|
23
30
|
|
|
24
31
|
```bash
|
|
25
|
-
npx df init
|
|
32
|
+
npx df init --wizard
|
|
26
33
|
```
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
Three ways in, same gate out — pick by how much attention you want to spend:
|
|
36
|
+
|
|
37
|
+
- **Wizard (recommended).** `--wizard` scaffolds, trial-runs the detected
|
|
38
|
+
commands, and hands your session agent a brief: what was detected, what
|
|
39
|
+
passed, Makefile targets worth mapping to wrappers, at most 3 open
|
|
40
|
+
questions. The agent resolves what it can, asks only genuinely
|
|
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
|
|
30
52
|
the agent for a small edit. You will see the plugin working: the edit is
|
|
31
53
|
checked against guardrails before it lands, your linter runs on the edited
|
|
32
54
|
file, and when the session goes idle the completion gate runs your
|
|
@@ -77,29 +99,48 @@ Every session runs the same loop — constitution, guardrails, lint, gate —
|
|
|
77
99
|
whether or not it starts under `/df-goal`. A goal just wraps that loop in
|
|
78
100
|
native verification:
|
|
79
101
|
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
```text
|
|
103
|
+
user prompt
|
|
104
|
+
(plain or /df-goal plan)
|
|
105
|
+
|
|
|
106
|
+
v
|
|
107
|
+
agent implements
|
|
108
|
+
|
|
|
109
|
+
v
|
|
110
|
+
tool.execute.before
|
|
111
|
+
/ \
|
|
112
|
+
allow deny: protected / dangerous / pre-flight
|
|
113
|
+
| |
|
|
114
|
+
v v
|
|
115
|
+
edit lands BLOCKED before landing
|
|
116
|
+
|
|
|
117
|
+
v
|
|
118
|
+
per-edit lint + change tracker
|
|
119
|
+
/ \
|
|
120
|
+
v v
|
|
121
|
+
agent runs dev_framework_verify session idle
|
|
122
|
+
| |
|
|
123
|
+
v v
|
|
124
|
+
verdict completion gate (same full contract)
|
|
125
|
+
/ \ | | | |
|
|
126
|
+
PASS FAIL PASS within max_blocks past max_blocks identical x3, no new edits
|
|
127
|
+
| | | | | |
|
|
128
|
+
v v v v v v
|
|
129
|
+
gate green loops back done synthetic STAND DOWN (honest unmet report)
|
|
130
|
+
(in a goal: to agent continuation
|
|
131
|
+
evidence implements |
|
|
132
|
+
into /goal) v
|
|
133
|
+
loops back to agent implements
|
|
134
|
+
|
|
135
|
+
wrappers (dotted lines in the diagram version):
|
|
136
|
+
/df-goal plan (optional) ── delegates once, appends contract ──> native /goal (owns objective + review)
|
|
137
|
+
native /goal ── wraps the loop, drives turns ──> agent implements
|
|
101
138
|
```
|
|
102
139
|
|
|
140
|
+
The diagram version of this flow (rendered on GitHub) lives in
|
|
141
|
+
[`docs/user/enforcement.md`](docs/user/enforcement.md#flow) — update both
|
|
142
|
+
together.
|
|
143
|
+
|
|
103
144
|
## Profiles
|
|
104
145
|
|
|
105
146
|
| Profile | Guardrails | Gate failures | Lint on edit | Pre-flight | Review required | Notes |
|
package/bin/df
CHANGED
|
@@ -6,12 +6,18 @@ import { readFile } from "node:fs/promises";
|
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import {
|
|
9
|
+
buildWizardBrief,
|
|
10
|
+
formatTrialRun,
|
|
11
|
+
formatWizardBrief,
|
|
9
12
|
installTemplates,
|
|
10
13
|
resolveTargetDir,
|
|
11
14
|
setProfileInFile,
|
|
12
15
|
statusTemplates,
|
|
16
|
+
trialRunDetectedCommands,
|
|
13
17
|
writeDetectedConfig,
|
|
14
18
|
} from "../dist/installer.js";
|
|
19
|
+
import { detectProject } from "../dist/detect.js";
|
|
20
|
+
import { runCommand } from "../dist/host.js";
|
|
15
21
|
|
|
16
22
|
async function getVersion() {
|
|
17
23
|
const packagePath = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
|
|
@@ -29,7 +35,12 @@ Usage:
|
|
|
29
35
|
df version Print the plugin version
|
|
30
36
|
df help Show this help
|
|
31
37
|
|
|
38
|
+
df init --wizard [dir] Scaffold, trial-run, and print an agent-handoff
|
|
39
|
+
brief (detection, trial results, Makefile targets,
|
|
40
|
+
open questions) for the project-config skill.
|
|
41
|
+
|
|
32
42
|
Options:
|
|
43
|
+
--wizard Print the wizard brief after init (agent-led handoff)
|
|
33
44
|
--overwrite-existing Overwrite files that already exist (non-interactive)
|
|
34
45
|
--skip-existing Skip files that already exist (non-interactive)
|
|
35
46
|
`);
|
|
@@ -122,6 +133,28 @@ async function main() {
|
|
|
122
133
|
console.log(line);
|
|
123
134
|
}
|
|
124
135
|
console.log(`\nConfig: ${configResult.action}`);
|
|
136
|
+
if (flags.has("--wizard")) {
|
|
137
|
+
try {
|
|
138
|
+
const brief = await buildWizardBrief(targetDir, runCommand);
|
|
139
|
+
for (const line of ["", ...formatWizardBrief(brief)]) {
|
|
140
|
+
console.log(line);
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.log(`\n${formatBriefSkipped(error)}`);
|
|
144
|
+
}
|
|
145
|
+
} else if (configResult.action === "created" || configResult.action === "overwritten") {
|
|
146
|
+
try {
|
|
147
|
+
const { commands } = detectProject(targetDir);
|
|
148
|
+
const trial = await trialRunDetectedCommands(targetDir, commands, runCommand);
|
|
149
|
+
for (const line of ["", ...formatTrialRun(trial)]) {
|
|
150
|
+
console.log(line);
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.log(
|
|
154
|
+
`\nTrial-run: skipped (${error instanceof Error ? error.message : String(error)}) — verify commands manually`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
125
158
|
}
|
|
126
159
|
|
|
127
160
|
main().catch((error) => {
|
package/dist/config.d.ts
CHANGED
|
@@ -37,6 +37,21 @@ export declare function resolveConfig(raw: Config, configPath?: string): Resolve
|
|
|
37
37
|
* directly.
|
|
38
38
|
*/
|
|
39
39
|
export declare function hasMeaningfulChecks(config: ResolvedConfig): boolean;
|
|
40
|
+
export type ConfigEnforceability = {
|
|
41
|
+
ok: true;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
error: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Enforceability bar shared by `/df-goal` and init validation (plan 15):
|
|
48
|
+
* a blocking profile plus at least one meaningful check. Every failure
|
|
49
|
+
* names the exact cause and points at the alternatives. The native-`/goal`
|
|
50
|
+
* availability check stays in `checkGoalAvailability` (`src/goal.ts`) —
|
|
51
|
+
* this is the config half only, so agent-drafted configs can be validated
|
|
52
|
+
* without a live core.
|
|
53
|
+
*/
|
|
54
|
+
export declare function checkConfigEnforceable(config: ResolvedConfig): ConfigEnforceability;
|
|
40
55
|
/** Clear the per-session config cache (mainly for tests). */
|
|
41
56
|
export declare function clearConfigCache(): void;
|
|
42
57
|
/**
|
package/dist/config.js
CHANGED
|
@@ -381,6 +381,44 @@ export function hasMeaningfulChecks(config) {
|
|
|
381
381
|
}
|
|
382
382
|
return false;
|
|
383
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Enforceability bar shared by `/df-goal` and init validation (plan 15):
|
|
386
|
+
* a blocking profile plus at least one meaningful check. Every failure
|
|
387
|
+
* names the exact cause and points at the alternatives. The native-`/goal`
|
|
388
|
+
* availability check stays in `checkGoalAvailability` (`src/goal.ts`) —
|
|
389
|
+
* this is the config half only, so agent-drafted configs can be validated
|
|
390
|
+
* without a live core.
|
|
391
|
+
*/
|
|
392
|
+
export function checkConfigEnforceable(config) {
|
|
393
|
+
if (config.profile === "off") {
|
|
394
|
+
return {
|
|
395
|
+
ok: false,
|
|
396
|
+
error: 'Cannot start a verified goal: profile is "off", so verification would be vacuous. ' +
|
|
397
|
+
"Enable a blocking profile (standard or strict), or use native /goal directly " +
|
|
398
|
+
"for an unverified objective.",
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
if (!config.gate?.block_on_failure) {
|
|
402
|
+
const found = config.gate?.block_on_failure;
|
|
403
|
+
return {
|
|
404
|
+
ok: false,
|
|
405
|
+
error: `Cannot start a verified goal: gate.block_on_failure is ${String(found)}, ` +
|
|
406
|
+
"but /df-goal requires it to be true. Advisory mode must not gain a blocking " +
|
|
407
|
+
"side channel through /df-goal. Enable a blocking profile (standard or strict), " +
|
|
408
|
+
"or use native /goal directly.",
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (!hasMeaningfulChecks(config)) {
|
|
412
|
+
return {
|
|
413
|
+
ok: false,
|
|
414
|
+
error: "Cannot start a verified goal: the resolved configuration provides no meaningful " +
|
|
415
|
+
"completion check (no typecheck/test command, no changed-file lint, no acceptance " +
|
|
416
|
+
"commands, and no review requirement). Configure at least one check, or use native " +
|
|
417
|
+
"/goal directly for a purely semantic objective.",
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
return { ok: true };
|
|
421
|
+
}
|
|
384
422
|
function validateConfig(data, configPath) {
|
|
385
423
|
const result = configSchema.safeParse(data);
|
|
386
424
|
if (!result.success) {
|
package/dist/goal.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* (`isNativeGoalListed`) lives here. Unit tests drive these functions
|
|
15
15
|
* with a stub delegate.
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { checkConfigEnforceable } from "./config.js";
|
|
18
18
|
/**
|
|
19
19
|
* Native `/goal` objective limit. Counts JS `text.length` (UTF-16 code
|
|
20
20
|
* units) — confirmed by the Phase 0 spike against core `goal.ts`
|
|
@@ -90,34 +90,9 @@ export function checkGoalAvailability(config, nativeGoalAvailable) {
|
|
|
90
90
|
"without verification where native /goal exists.",
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
error: 'Cannot start a verified goal: profile is "off", so verification would be vacuous. ' +
|
|
97
|
-
"Enable a blocking profile (standard or strict), or use native /goal directly " +
|
|
98
|
-
"for an unverified objective.",
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
if (!config.gate?.block_on_failure) {
|
|
102
|
-
const found = config.gate?.block_on_failure;
|
|
103
|
-
return {
|
|
104
|
-
ok: false,
|
|
105
|
-
error: `Cannot start a verified goal: gate.block_on_failure is ${String(found)}, ` +
|
|
106
|
-
"but /df-goal requires it to be true. Advisory mode must not gain a blocking " +
|
|
107
|
-
"side channel through /df-goal. Enable a blocking profile (standard or strict), " +
|
|
108
|
-
"or use native /goal directly.",
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (!hasMeaningfulChecks(config)) {
|
|
112
|
-
return {
|
|
113
|
-
ok: false,
|
|
114
|
-
error: "Cannot start a verified goal: the resolved configuration provides no meaningful " +
|
|
115
|
-
"completion check (no typecheck/test command, no changed-file lint, no acceptance " +
|
|
116
|
-
"commands, and no review requirement). Configure at least one check, or use native " +
|
|
117
|
-
"/goal directly for a purely semantic objective.",
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return { ok: true };
|
|
93
|
+
// Config half of the bar lives in `checkConfigEnforceable` (plan 15) so
|
|
94
|
+
// init validation reuses the identical messages.
|
|
95
|
+
return checkConfigEnforceable(config);
|
|
121
96
|
}
|
|
122
97
|
/**
|
|
123
98
|
* Validate, wrap, and delegate exactly once. Native delegation errors
|
package/dist/index.js
CHANGED
|
@@ -619,7 +619,7 @@ const plugin = Plugin.define({
|
|
|
619
619
|
trackRegistration(await ctx.tool.transform((editor) => {
|
|
620
620
|
editor.add({
|
|
621
621
|
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.",
|
|
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.",
|
|
623
623
|
input: {
|
|
624
624
|
type: "object",
|
|
625
625
|
properties: {
|
|
@@ -631,11 +631,15 @@ const plugin = Plugin.define({
|
|
|
631
631
|
type: "boolean",
|
|
632
632
|
description: "Overwrite existing files that differ from templates",
|
|
633
633
|
},
|
|
634
|
+
wizard: {
|
|
635
|
+
type: "boolean",
|
|
636
|
+
description: "Append a wizard brief for agent-led handoff to the project-config skill",
|
|
637
|
+
},
|
|
634
638
|
},
|
|
635
639
|
additionalProperties: false,
|
|
636
640
|
},
|
|
637
641
|
async execute(input) {
|
|
638
|
-
const { installTemplates, writeDetectedConfig } = await import("./installer.js");
|
|
642
|
+
const { buildWizardBrief, formatBriefSkipped, formatTrialRun, formatWizardBrief, installTemplates, trialRunDetectedCommands, writeDetectedConfig, } = await import("./installer.js");
|
|
639
643
|
const args = input;
|
|
640
644
|
const targetDir = args.directory ?? directory;
|
|
641
645
|
const result = await installTemplates(targetDir, {
|
|
@@ -657,6 +661,26 @@ const plugin = Plugin.define({
|
|
|
657
661
|
lines.push("", "Created files:", ...result.created.map((f) => `- ${f}`));
|
|
658
662
|
if (result.overwritten.length > 0)
|
|
659
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
|
+
}
|
|
660
684
|
return { content: lines.join("\n") };
|
|
661
685
|
},
|
|
662
686
|
});
|
package/dist/installer.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RunCommand } from "./host.js";
|
|
1
2
|
import type { Profile } from "./types.js";
|
|
2
3
|
/** Directory containing the project templates shipped with the package. */
|
|
3
4
|
export declare const TEMPLATES_DIR: string;
|
|
@@ -41,8 +42,79 @@ export interface ConfigWriteResult {
|
|
|
41
42
|
* `installTemplates`.
|
|
42
43
|
*/
|
|
43
44
|
export declare function writeDetectedConfig(targetDir: string, options?: InstallOptions): Promise<ConfigWriteResult>;
|
|
45
|
+
/** Bounded trial-run timeout (seconds): init UX, not a gate suite. */
|
|
46
|
+
export declare const TRIAL_RUN_TIMEOUT_SECONDS = 120;
|
|
47
|
+
export interface TrialRunResult {
|
|
48
|
+
name: "test" | "typecheck";
|
|
49
|
+
command: string;
|
|
50
|
+
ok: boolean;
|
|
51
|
+
exitCode: number;
|
|
52
|
+
timedOut: boolean;
|
|
53
|
+
durationMs: number;
|
|
54
|
+
/** Spawn failure detail (run threw instead of resolving). */
|
|
55
|
+
error?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Run each runnable detected command once to verify the guess (plan 15).
|
|
59
|
+
* Only `test`/`typecheck` run bare — lint/format templates carry
|
|
60
|
+
* `{file}`/`{dir}` placeholders and are reported as unverified by the
|
|
61
|
+
* caller skipping them (absent or empty commands are skipped, not failed).
|
|
62
|
+
* The two trials run concurrently; each is bounded by `timeout` seconds.
|
|
63
|
+
* Report-only by construction: results annotate, never throw — including
|
|
64
|
+
* for runners that reject despite the host never-rejects contract.
|
|
65
|
+
*/
|
|
66
|
+
export declare function trialRunDetectedCommands(directory: string, commands: {
|
|
67
|
+
test?: string;
|
|
68
|
+
typecheck?: string;
|
|
69
|
+
}, run: RunCommand, opts?: {
|
|
70
|
+
timeout?: number;
|
|
71
|
+
}): Promise<TrialRunResult[]>;
|
|
72
|
+
/** Render trial-run results as CLI/tool output lines. */
|
|
73
|
+
export declare function formatTrialRun(results: TrialRunResult[]): string[];
|
|
44
74
|
/** Resolve a user-supplied directory (default cwd) to an absolute path. */
|
|
45
75
|
export declare function resolveTargetDir(dir?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* List Makefile target names (plan 16). Names only, no semantics: the
|
|
78
|
+
* agent decides which (if any) are canonical wrappers. Capped at 30.
|
|
79
|
+
* Grouped targets (`lint test: deps`) split into both names; pattern
|
|
80
|
+
* rules, dot-directives, assignments, and make keywords never match.
|
|
81
|
+
* Probes GNUmakefile/makefile/Makefile in GNU make precedence order.
|
|
82
|
+
* Empty when no makefile exists or none is readable — report-only.
|
|
83
|
+
*/
|
|
84
|
+
export declare function listMakefileTargets(directory: string): Promise<string[]>;
|
|
85
|
+
export interface WizardBrief {
|
|
86
|
+
language: string | null;
|
|
87
|
+
commands: {
|
|
88
|
+
test?: string;
|
|
89
|
+
typecheck?: string;
|
|
90
|
+
};
|
|
91
|
+
trial: TrialRunResult[];
|
|
92
|
+
makeTargets: string[];
|
|
93
|
+
enforceability: {
|
|
94
|
+
ok: true;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
error: string;
|
|
98
|
+
};
|
|
99
|
+
/** Open questions for the agent, capped at 3 — never exhaustive. */
|
|
100
|
+
questions: string[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Build the agent-handoff brief (plan 16): detection, trial-run, Makefile
|
|
104
|
+
* target names, and the shared enforceability verdict in one bundle. The
|
|
105
|
+
* LLM session agent is the wizard's presenter — this is the machine side,
|
|
106
|
+
* hints only, and the project-config skill still verifies everything by
|
|
107
|
+
* running. Trial/target failures annotate, never throw; a nonexistent
|
|
108
|
+
* directory rejects via detection, so both callers isolate the brief in
|
|
109
|
+
* try/catch (see `formatBriefSkipped`).
|
|
110
|
+
*/
|
|
111
|
+
export declare function buildWizardBrief(directory: string, run: RunCommand, opts?: {
|
|
112
|
+
timeout?: number;
|
|
113
|
+
}): Promise<WizardBrief>;
|
|
114
|
+
/** Shared report-only fallback when the brief itself cannot be built. */
|
|
115
|
+
export declare function formatBriefSkipped(error: unknown): string;
|
|
116
|
+
/** Render the wizard brief as CLI/tool output lines, ending in the handoff. */
|
|
117
|
+
export declare function formatWizardBrief(brief: WizardBrief): string[];
|
|
46
118
|
/**
|
|
47
119
|
* Set the top-level `profile:` key in a config file. Edits the raw text
|
|
48
120
|
* instead of re-serializing the YAML so user comments and formatting survive.
|
package/dist/installer.js
CHANGED
|
@@ -2,7 +2,8 @@ import { promises as fs } from "node:fs";
|
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { createInterface } from "node:readline";
|
|
5
|
-
import {
|
|
5
|
+
import { splitCommand } from "./command-utils.js";
|
|
6
|
+
import { checkConfigEnforceable, DEFAULT_PROTECT, resolveConfig } from "./config.js";
|
|
6
7
|
import { detectProject } from "./detect.js";
|
|
7
8
|
/** Directory containing the project templates shipped with the package. */
|
|
8
9
|
export const TEMPLATES_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "templates");
|
|
@@ -271,10 +272,188 @@ export async function writeDetectedConfig(targetDir, options = {}) {
|
|
|
271
272
|
}
|
|
272
273
|
return { action: "skipped" };
|
|
273
274
|
}
|
|
275
|
+
/** Bounded trial-run timeout (seconds): init UX, not a gate suite. */
|
|
276
|
+
export const TRIAL_RUN_TIMEOUT_SECONDS = 120;
|
|
277
|
+
/**
|
|
278
|
+
* Run each runnable detected command once to verify the guess (plan 15).
|
|
279
|
+
* Only `test`/`typecheck` run bare — lint/format templates carry
|
|
280
|
+
* `{file}`/`{dir}` placeholders and are reported as unverified by the
|
|
281
|
+
* caller skipping them (absent or empty commands are skipped, not failed).
|
|
282
|
+
* The two trials run concurrently; each is bounded by `timeout` seconds.
|
|
283
|
+
* Report-only by construction: results annotate, never throw — including
|
|
284
|
+
* for runners that reject despite the host never-rejects contract.
|
|
285
|
+
*/
|
|
286
|
+
export async function trialRunDetectedCommands(directory, commands, run, opts = {}) {
|
|
287
|
+
const entries = [
|
|
288
|
+
["test", commands.test],
|
|
289
|
+
["typecheck", commands.typecheck],
|
|
290
|
+
];
|
|
291
|
+
const runnable = [];
|
|
292
|
+
for (const [name, template] of entries) {
|
|
293
|
+
if (typeof template === "string" && template !== "")
|
|
294
|
+
runnable.push({ name, command: template });
|
|
295
|
+
}
|
|
296
|
+
return Promise.all(runnable.map(async ({ name, command }) => {
|
|
297
|
+
const started = Date.now();
|
|
298
|
+
let result;
|
|
299
|
+
try {
|
|
300
|
+
result = await run(splitCommand(command), {
|
|
301
|
+
cwd: directory,
|
|
302
|
+
timeout: opts.timeout ?? TRIAL_RUN_TIMEOUT_SECONDS,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
return {
|
|
307
|
+
name,
|
|
308
|
+
command,
|
|
309
|
+
ok: false,
|
|
310
|
+
exitCode: 127,
|
|
311
|
+
timedOut: false,
|
|
312
|
+
durationMs: Date.now() - started,
|
|
313
|
+
error: error instanceof Error ? error.message : String(error),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
name,
|
|
318
|
+
command,
|
|
319
|
+
ok: result.exitCode === 0 && !result.timedOut,
|
|
320
|
+
exitCode: result.exitCode,
|
|
321
|
+
timedOut: result.timedOut,
|
|
322
|
+
durationMs: Date.now() - started,
|
|
323
|
+
};
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
/** Render trial-run results as CLI/tool output lines. */
|
|
327
|
+
export function formatTrialRun(results) {
|
|
328
|
+
if (results.length === 0) {
|
|
329
|
+
return ["Trial-run: no runnable commands detected — verify manually."];
|
|
330
|
+
}
|
|
331
|
+
return [
|
|
332
|
+
"Trial-run:",
|
|
333
|
+
...results.map((r) => {
|
|
334
|
+
const secs = (r.durationMs / 1000).toFixed(1);
|
|
335
|
+
if (r.error !== undefined) {
|
|
336
|
+
return ` ${r.name} (${r.command}): ERROR (${r.error}) — verify this command`;
|
|
337
|
+
}
|
|
338
|
+
const status = r.ok ? "PASS" : `FAIL (exit ${r.exitCode}${r.timedOut ? ", timed out" : ""})`;
|
|
339
|
+
const suffix = r.ok ? "" : " — verify this command";
|
|
340
|
+
return ` ${r.name} (${r.command}): ${status} (${secs}s)${suffix}`;
|
|
341
|
+
}),
|
|
342
|
+
];
|
|
343
|
+
}
|
|
274
344
|
/** Resolve a user-supplied directory (default cwd) to an absolute path. */
|
|
275
345
|
export function resolveTargetDir(dir) {
|
|
276
346
|
return resolve(dir ?? process.cwd());
|
|
277
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* List Makefile target names (plan 16). Names only, no semantics: the
|
|
350
|
+
* agent decides which (if any) are canonical wrappers. Capped at 30.
|
|
351
|
+
* Grouped targets (`lint test: deps`) split into both names; pattern
|
|
352
|
+
* rules, dot-directives, assignments, and make keywords never match.
|
|
353
|
+
* Probes GNUmakefile/makefile/Makefile in GNU make precedence order.
|
|
354
|
+
* Empty when no makefile exists or none is readable — report-only.
|
|
355
|
+
*/
|
|
356
|
+
export async function listMakefileTargets(directory) {
|
|
357
|
+
let content = null;
|
|
358
|
+
for (const name of ["GNUmakefile", "makefile", "Makefile"]) {
|
|
359
|
+
try {
|
|
360
|
+
content = await fs.readFile(join(directory, name), "utf8");
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
// Not present or unreadable — try the next name.
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (content === null)
|
|
368
|
+
return [];
|
|
369
|
+
const keywords = /^(export|unexport|override|define|endef|ifeq|ifneq|ifdef|ifndef|else|endif|include|-include|sinclude)$/;
|
|
370
|
+
const namePattern = /^[A-Za-z0-9_][A-Za-z0-9_.%-]*$/;
|
|
371
|
+
const targets = [];
|
|
372
|
+
for (const line of content.split("\n")) {
|
|
373
|
+
// Leading char excludes comments, recipes, dot-directives, and `%`
|
|
374
|
+
// pattern rules; `[^:=]` keeps the match left of any assignment.
|
|
375
|
+
const match = /^([^:#=\s][^:=]*?)\s*:(?!=)/.exec(line);
|
|
376
|
+
if (match === null)
|
|
377
|
+
continue;
|
|
378
|
+
for (const token of match[1].split(/\s+/)) {
|
|
379
|
+
if (!namePattern.test(token) || keywords.test(token) || targets.includes(token))
|
|
380
|
+
continue;
|
|
381
|
+
targets.push(token);
|
|
382
|
+
if (targets.length >= 30)
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
if (targets.length >= 30)
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
return targets;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Build the agent-handoff brief (plan 16): detection, trial-run, Makefile
|
|
392
|
+
* target names, and the shared enforceability verdict in one bundle. The
|
|
393
|
+
* LLM session agent is the wizard's presenter — this is the machine side,
|
|
394
|
+
* hints only, and the project-config skill still verifies everything by
|
|
395
|
+
* running. Trial/target failures annotate, never throw; a nonexistent
|
|
396
|
+
* directory rejects via detection, so both callers isolate the brief in
|
|
397
|
+
* try/catch (see `formatBriefSkipped`).
|
|
398
|
+
*/
|
|
399
|
+
export async function buildWizardBrief(directory, run, opts = {}) {
|
|
400
|
+
const { language, commands } = detectProject(directory);
|
|
401
|
+
const [trial, makeTargets] = await Promise.all([
|
|
402
|
+
trialRunDetectedCommands(directory, commands, run, opts),
|
|
403
|
+
listMakefileTargets(directory),
|
|
404
|
+
]);
|
|
405
|
+
const enforceability = checkConfigEnforceable(resolveConfig({ profile: "standard", commands }));
|
|
406
|
+
const questions = [];
|
|
407
|
+
if (makeTargets.length > 0) {
|
|
408
|
+
const shown = makeTargets.slice(0, 8).join(", ");
|
|
409
|
+
questions.push(`Makefile targets detected (${shown}${makeTargets.length > 8 ? ", …" : ""}) — ` +
|
|
410
|
+
"do canonical wrappers (e.g. make check/test/lint) replace the guessed bare commands?");
|
|
411
|
+
}
|
|
412
|
+
for (const t of trial) {
|
|
413
|
+
if (t.ok || questions.length >= 3)
|
|
414
|
+
continue;
|
|
415
|
+
questions.push(`Trial-run flagged ${t.name} (${t.command}) — verify the real command before trusting the guess.`);
|
|
416
|
+
}
|
|
417
|
+
if (enforceability.ok === false && questions.length < 3) {
|
|
418
|
+
questions.push(`Draft is not enforceable: ${enforceability.error}`);
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
language,
|
|
422
|
+
commands,
|
|
423
|
+
trial,
|
|
424
|
+
makeTargets,
|
|
425
|
+
enforceability,
|
|
426
|
+
questions: questions.slice(0, 3),
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/** Shared report-only fallback when the brief itself cannot be built. */
|
|
430
|
+
export function formatBriefSkipped(error) {
|
|
431
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
432
|
+
return `Wizard brief: skipped (${detail}) — verify commands manually`;
|
|
433
|
+
}
|
|
434
|
+
/** Render the wizard brief as CLI/tool output lines, ending in the handoff. */
|
|
435
|
+
export function formatWizardBrief(brief) {
|
|
436
|
+
const guessed = `Guessed commands: test=${brief.commands.test ?? "(none)"}, typecheck=${brief.commands.typecheck ?? "(none)"}`;
|
|
437
|
+
const lines = [
|
|
438
|
+
"Wizard brief (machine-generated hints — verify by running, see the project-config skill):",
|
|
439
|
+
`Detected language: ${brief.language ?? "(unknown)"}`,
|
|
440
|
+
guessed,
|
|
441
|
+
...formatTrialRun(brief.trial),
|
|
442
|
+
brief.makeTargets.length > 0
|
|
443
|
+
? `Makefile targets: ${brief.makeTargets.join(", ")}`
|
|
444
|
+
: "Makefile targets: (none — no Makefile)",
|
|
445
|
+
brief.enforceability.ok
|
|
446
|
+
? "Enforceability: draft passes the shared bar (blocking profile + real checks)."
|
|
447
|
+
: `Enforceability: FAIL — ${brief.enforceability.error}`,
|
|
448
|
+
];
|
|
449
|
+
if (brief.questions.length > 0) {
|
|
450
|
+
lines.push("Open questions (at most 3):", ...brief.questions.map((q, i) => ` ${i + 1}. ${q}`));
|
|
451
|
+
}
|
|
452
|
+
lines.push("", "Handoff: follow the project-config skill (templates/.opencode/skills/project-config/SKILL.md) " +
|
|
453
|
+
"to resolve the questions above, run the real commands, and present " +
|
|
454
|
+
".opencode-dev-framework.yml + hardening.md for review. Do not write without review.");
|
|
455
|
+
return lines;
|
|
456
|
+
}
|
|
278
457
|
/**
|
|
279
458
|
* Set the top-level `profile:` key in a config file. Edits the raw text
|
|
280
459
|
* instead of re-serializing the YAML so user comments and formatting survive.
|
package/package.json
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: project-config
|
|
3
|
+
description: >
|
|
4
|
+
Draft an opencode-dev-framework configuration for the current project:
|
|
5
|
+
read its build files and CI, map the real verification commands, and
|
|
6
|
+
propose the yml plus a hardening draft for user review. Use when setting
|
|
7
|
+
up the plugin on a new project instead of hand-writing the config.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Project Configuration
|
|
11
|
+
|
|
12
|
+
Write the plugin config the project deserves — derived from its actual
|
|
13
|
+
build system, not guessed. You propose; the user disposes.
|
|
14
|
+
|
|
15
|
+
## When to use
|
|
16
|
+
|
|
17
|
+
Setting up the plugin on a project for the first time, instead of
|
|
18
|
+
hand-writing `.opencode-dev-framework.yml` or trusting `df init`
|
|
19
|
+
detection alone. Also when the existing config smells wrong — gate
|
|
20
|
+
passing vacuously, commands that don't match CI, a red tree nobody can
|
|
21
|
+
explain.
|
|
22
|
+
|
|
23
|
+
## Wizard brief (when `df init --wizard` ran first)
|
|
24
|
+
|
|
25
|
+
The brief hands you machine-generated hints: detected language, guessed
|
|
26
|
+
commands with trial-run results, Makefile target names, the shared
|
|
27
|
+
enforceability verdict, and at most 3 open questions. Treat it as a
|
|
28
|
+
starting brief, not findings:
|
|
29
|
+
|
|
30
|
+
+ Re-run every command yourself before trusting it — trial results go
|
|
31
|
+
stale, and a PASS can still hide a semantic gap (e.g. a typecheck
|
|
32
|
+
that skips generated artifacts).
|
|
33
|
+
+ The Makefile target list is names only; you decide which are
|
|
34
|
+
canonical wrappers.
|
|
35
|
+
+ Answer the brief's questions first, then do your own pass — the
|
|
36
|
+
brief doesn't know about CI tiebreakers or env-gated suites.
|
|
37
|
+
|
|
38
|
+
Interaction budget: resolve everything resolvable yourself; come back
|
|
39
|
+
with the review diff plus at most 3 questions, all genuinely
|
|
40
|
+
user-only. Never interrogate mid-run — proceed on safe defaults and
|
|
41
|
+
list assumptions.
|
|
42
|
+
|
|
43
|
+
## Steps
|
|
44
|
+
|
|
45
|
+
1. **Read the build truth, in authority order.** CI workflow first (it is
|
|
46
|
+
the tiebreaker when scripts disagree), then the build files for the
|
|
47
|
+
project's ecosystem — `Makefile`, `package.json` scripts, `go.mod`
|
|
48
|
+
toolchains, `pyproject.toml` / `tox.ini` / `noxfile.py`, `Cargo.toml`
|
|
49
|
+
+ `.cargo/config.toml`, `pom.xml` / `build.gradle(.kts)`, `Rakefile`,
|
|
50
|
+
`composer.json`, `CMakeLists.txt` (+ CTest), Bazel (`BUILD`,
|
|
51
|
+
`WORKSPACE`, `MODULE.bazel`), `meson.build`, `SConstruct` — then
|
|
52
|
+
CONTRIBUTING and existing lint configs. (`build.ninja` is generated
|
|
53
|
+
output; find what generates it instead of reading it.) You are
|
|
54
|
+
looking for: the full verification command(s), per-language
|
|
55
|
+
lint/format invocations, integration tests with special needs (docker,
|
|
56
|
+
network, credentials), generated assets and how they rebuild, and
|
|
57
|
+
paths that must never be edited.
|
|
58
|
+
|
|
59
|
+
2. **Prefer wrappers over bare tools.** If the project verifies via
|
|
60
|
+
`make check`, `npm run verify`, or a CI job, the config's `commands`
|
|
61
|
+
must invoke the wrapper — never reconstruct it from bare tool calls
|
|
62
|
+
that skip steps. Note ordering traps (generated code must rebuild
|
|
63
|
+
before typecheck; lint before test when the suite counts warnings).
|
|
64
|
+
|
|
65
|
+
3. **Place what doesn't fit unit scope in `gate.acceptance`.**
|
|
66
|
+
Integration suites, contract tests, docs lint, vulnerability scans —
|
|
67
|
+
each as a named acceptance check with its real command.
|
|
68
|
+
|
|
69
|
+
4. **Draft `hardening.md`** from what you observed, in the five sections
|
|
70
|
+
from `docs/user/hardening.md`: the project way to build, full
|
|
71
|
+
verification before done, fresh review cadence, scope discipline,
|
|
72
|
+
executing plans under `/df-goal`. Exact commands and paths. No vague
|
|
73
|
+
injunctions ("be thorough") — those get interpreted minimally.
|
|
74
|
+
|
|
75
|
+
5. **Self-check before presenting.** The draft must satisfy the
|
|
76
|
+
enforceability bar: a blocking profile (`standard`/`strict`, i.e.
|
|
77
|
+
`gate.block_on_failure: true`) and at least one real check
|
|
78
|
+
(typecheck/test command, changed-file lint, non-empty
|
|
79
|
+
`gate.acceptance`, or `gate.require_review`). A draft with none of
|
|
80
|
+
these is vacuous — fix it, don't present it.
|
|
81
|
+
|
|
82
|
+
6. **Present the full diff for review. Never write without review, never
|
|
83
|
+
commit.** The user owns the merge. Say plainly which commands you
|
|
84
|
+
verified by running, which you inferred from files, and which need
|
|
85
|
+
the user's confirmation.
|
|
86
|
+
|
|
87
|
+
## Output
|
|
88
|
+
|
|
89
|
+
+ The proposed `.opencode-dev-framework.yml` and `hardening.md` content
|
|
90
|
+
as a reviewable diff, each command annotated verified-by-running,
|
|
91
|
+
inferred-from-files, or needs-confirmation.
|
|
92
|
+
+ The enforceability self-check result (blocking profile + at least one
|
|
93
|
+
real check, or the deficiencies fixed before presenting).
|
|
94
|
+
|
|
95
|
+
## What stays out
|
|
96
|
+
|
|
97
|
+
+ Secrets, tokens, internal URLs, customer names — the config and the
|
|
98
|
+
hardening file are designed to be committable.
|
|
99
|
+
+ Anything the gate already enforces (don't restate the config inside
|
|
100
|
+
the hardening file).
|
|
101
|
+
+ Auto-commit. The skill ends at the reviewed diff.
|