opencode-dev-framework 1.6.0 → 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 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
- npm install opencode-dev-framework
21
+ opencode plugin add opencode-dev-framework
22
22
  ```
23
23
 
24
- ```json
25
- // opencode.jsonc
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
- ```bash
32
- npx df init --wizard
28
+ ```text
29
+ /df-init
33
30
  ```
34
31
 
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
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
@@ -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/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 { buildWizardBrief, formatBriefSkipped, formatTrialRun, formatWizardBrief, installTemplates, trialRunDetectedCommands, writeDetectedConfig, } = await import("./installer.js");
664
+ const { runInitScaffold, scaffoldReportLines } = await import("./init.js");
662
665
  const args = input;
663
666
  const targetDir = args.directory ?? directory;
664
- const result = await installTemplates(targetDir, {
665
- overwriteExisting: args.overwrite ?? false,
666
- skipExisting: !(args.overwrite ?? false),
667
+ const scaffold = await runInitScaffold(targetDir, state.run, {
668
+ wizard: args.wizard,
669
+ overwrite: args.overwrite,
667
670
  });
668
- const configResult = await writeDetectedConfig(targetDir, {
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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 `df init --wizard` ran first)
23
+ ## Wizard brief (when setup ran first)
24
24
 
25
- The brief hands you machine-generated hints: detected language, guessed
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: