opencode-dev-framework 0.1.16 → 0.1.25

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
@@ -30,10 +30,16 @@ reimplemented as an OpenCode-native plugin.
30
30
  - **CLI installer.** `df init` auto-detects your language and writes a config
31
31
  with sensible commands; `df profile <name>` changes the profile from the
32
32
  shell; `df status` / `df version` report template state and the version.
33
- - **Slash commands.** `/df-status`, `/df-verify`, and `/df-profile` are
34
- registered directly by the plugin so they work without template files.
35
- `/df-status` and `/df-verify` read live in-memory state; `/df-profile`
36
- updates the config and applies the change immediately.
33
+ - **Slash commands.** The plugin registers four commands. None of them feed
34
+ anything to the LLM:
35
+ - `/df-status` and `/df-help` are TUI commands (bundled `./tui` companion module)
36
+ that open an instant modal dialog.
37
+ - `/df-profile <profile>` and `/df-verify` are server-side commands. They are
38
+ registered with an empty template so the argument (e.g. `standard`) is
39
+ captured by the plugin and the model never sees it; the result is shown as a
40
+ toast and the user turn is suppressed.
41
+ - The `dev_framework_init` and `dev_framework_set_profile` custom *tools* remain
42
+ available for in-agent use.
37
43
 
38
44
  ## Profiles
39
45
 
@@ -50,7 +56,7 @@ reimplemented as an OpenCode-native plugin.
50
56
  npm install opencode-dev-framework
51
57
  ```
52
58
 
53
- Then add it to your project's `opencode.json`:
59
+ Then add the plugin to your project's `opencode.json`:
54
60
 
55
61
  ```json
56
62
  {
@@ -58,6 +64,11 @@ Then add it to your project's `opencode.json`:
58
64
  }
59
65
  ```
60
66
 
67
+ On OpenCode 1.18.18+ the `./tui` companion (the `/df-status` and `/df-help`
68
+ modals) is auto-discovered from the npm plugin entry above, so the server and
69
+ TUI parts load together. (On older builds, or if the modals do not appear, also
70
+ add the package to `tui.json` — see *Local development* below.)
71
+
61
72
  Finally, scaffold the project-level files (agents, skills, local rules directory,
62
73
  and default config) into your repo with the bundled `df` CLI:
63
74
 
@@ -77,7 +88,21 @@ profile from the shell; `df version` prints the plugin version.
77
88
  ## Local development and testing
78
89
 
79
90
  To test the plugin from source without publishing to npm, point OpenCode at the
80
- local repository path in your project's `opencode.json`:
91
+ local repository path in your project's `opencode.json` **and** in a `tui.json`.
92
+ The TUI module (`/df-status`, `/df-help` modals) is **not** auto-discovered for
93
+ local filesystem paths — it only loads when the package is listed in the TUI
94
+ config. OpenCode reads `tui.json` from the global config dir
95
+ (`~/.config/opencode/tui.json`) and the project dir (`.opencode/tui.json`).
96
+
97
+ `opencode.json` (server plugin):
98
+
99
+ ```json
100
+ {
101
+ "plugin": ["/home/jerome/opencode-dev-framework"]
102
+ }
103
+ ```
104
+
105
+ `tui.json` (TUI plugin — same path):
81
106
 
82
107
  ```json
83
108
  {
@@ -86,7 +111,8 @@ local repository path in your project's `opencode.json`:
86
111
  ```
87
112
 
88
113
  The path must be the **repository root** (where `package.json` lives). OpenCode
89
- loads `dist/index.js`, so rebuild after every source change:
114
+ loads the server plugin from `dist/index.js` and the TUI plugin from `tui.tsx`,
115
+ so rebuild after every source change:
90
116
 
91
117
  ```bash
92
118
  npm run build
@@ -154,16 +180,25 @@ complete example.
154
180
 
155
181
  ## Slash commands
156
182
 
157
- The plugin registers three slash commands directly (no template files required):
183
+ All four slash commands are **TUI commands** registered by the bundled `./tui`
184
+ companion module (see *Local development* above for the `tui.json` requirement).
185
+ They open instantly and **never** feed text back to the LLM:
158
186
 
159
- - `/df-status` — shows the current profile, guardrails, completion gate,
160
- configured commands, and tracked changed files. Reads live in-memory state.
161
- - `/df-verify` — runs the configured verification suite manually.
162
- - `/df-profile <profile>` — changes the active profile and applies it
163
- immediately.
187
+ - `/df-status` — shows the current profile, guardrails, completion gate, and
188
+ configured commands in a modal dialog.
189
+ - `/df-help` — lists the available dev-framework commands in a modal dialog.
190
+ - `/df-profile` — opens a profile picker (off / advisory / standard / strict) in
191
+ a modal dialog; selecting one switches the active profile immediately (written
192
+ to the config file). Run it **bare** — the argument form
193
+ (`/df-profile standard`) is not wired up in this build.
194
+ - `/df-verify` — runs the configured verification suite (the completion gate)
195
+ manually and shows a pass/fail summary in a modal dialog.
164
196
 
165
197
  You can still run `df init` to install the bundled agents, skills, and default
166
- config; the commands themselves are provided by the plugin.
198
+ config; the commands themselves are provided by the plugin. The
199
+ `dev_framework_init` and `dev_framework_set_profile` custom *tools* remain
200
+ available for in-agent use (e.g. when the model wants to change the profile
201
+ itself).
167
202
 
168
203
  ## Limitations
169
204
 
@@ -0,0 +1,21 @@
1
+ import { type GateReport } from "./gate.js";
2
+ import type { RunCommand } from "./host.js";
3
+ import type { Profile, ResolvedConfig } from "./types.js";
4
+ /**
5
+ * Change the project profile by editing the config file on disk. The server
6
+ * plugin reloads the in-memory config on the next tool call / gate run (see
7
+ * `reloadConfigIfChanged` in index.ts), so the change does not require a
8
+ * restart. Used by both the `/df-profile` TUI command and the
9
+ * `dev_framework_set_profile` custom tool.
10
+ */
11
+ export declare function changeProfile(directory: string, profile: Profile): Promise<string>;
12
+ /**
13
+ * Run the completion gate manually for a project. When `config` is omitted the
14
+ * project config is loaded from disk. `changedFiles` is normally empty for a
15
+ * manual verify (the server's live tracker is not visible from the TUI), so a
16
+ * `scope: changed` gate will report "no changed files".
17
+ */
18
+ export declare function verifyGate(run: RunCommand, directory: string, config?: ResolvedConfig, changedFiles?: string[]): Promise<{
19
+ report: GateReport;
20
+ summary: string;
21
+ }>;
@@ -0,0 +1,27 @@
1
+ import { join } from "node:path";
2
+ import { loadConfig } from "./config.js";
3
+ import { runGate, summarizeGate } from "./gate.js";
4
+ import { setProfileInFile } from "./installer.js";
5
+ /**
6
+ * Change the project profile by editing the config file on disk. The server
7
+ * plugin reloads the in-memory config on the next tool call / gate run (see
8
+ * `reloadConfigIfChanged` in index.ts), so the change does not require a
9
+ * restart. Used by both the `/df-profile` TUI command and the
10
+ * `dev_framework_set_profile` custom tool.
11
+ */
12
+ export async function changeProfile(directory, profile) {
13
+ const configPath = join(directory, ".opencode-dev-framework.yml");
14
+ await setProfileInFile(configPath, profile);
15
+ return `opencode-dev-framework profile set to "${profile}". Change applies on the next tool call / gate run.`;
16
+ }
17
+ /**
18
+ * Run the completion gate manually for a project. When `config` is omitted the
19
+ * project config is loaded from disk. `changedFiles` is normally empty for a
20
+ * manual verify (the server's live tracker is not visible from the TUI), so a
21
+ * `scope: changed` gate will report "no changed files".
22
+ */
23
+ export async function verifyGate(run, directory, config, changedFiles = []) {
24
+ const cfg = config ?? loadConfig(directory);
25
+ const report = await runGate(run, cfg, changedFiles, { cwd: directory });
26
+ return { report, summary: summarizeGate(report) };
27
+ }
@@ -1,9 +1,20 @@
1
1
  import type { HookState } from "./registry.js";
2
2
  import type { ResolvedConfig } from "./types.js";
3
+ /**
4
+ * Render the config-only portion of the status summary.
5
+ *
6
+ * This is shared between the server-side `/df-status` tool and the TUI plugin,
7
+ * which does not have access to live hook state.
8
+ */
9
+ export declare function renderConfigStatus(config: ResolvedConfig): string;
10
+ /**
11
+ * Render a help message listing the available dev-framework slash commands.
12
+ */
13
+ export declare function renderHelp(): string;
3
14
  /**
4
15
  * Render a human-readable summary of the current plugin state.
5
16
  *
6
- * Used by the `dev_framework_status` custom tool and by the `/df-status`
17
+ * Used by the `dev_framework_status` custom tool and by the server-side
7
18
  * slash-command handler.
8
19
  */
9
20
  export declare function renderStatus(config: ResolvedConfig, state?: HookState | null): string;
@@ -28,12 +28,12 @@ function formatRules(rules) {
28
28
  return lines.join("\n");
29
29
  }
30
30
  /**
31
- * Render a human-readable summary of the current plugin state.
31
+ * Render the config-only portion of the status summary.
32
32
  *
33
- * Used by the `dev_framework_status` custom tool and by the `/df-status`
34
- * slash-command handler.
33
+ * This is shared between the server-side `/df-status` tool and the TUI plugin,
34
+ * which does not have access to live hook state.
35
35
  */
36
- export function renderStatus(config, state) {
36
+ export function renderConfigStatus(config) {
37
37
  const lines = [];
38
38
  lines.push(`opencode-dev-framework status`);
39
39
  lines.push("");
@@ -57,9 +57,6 @@ export function renderStatus(config, state) {
57
57
  lines.push(` format: ${config.on_edit.format}`);
58
58
  lines.push(` lint: ${config.on_edit.lint}`);
59
59
  lines.push(` precommit: ${config.precommit}`);
60
- if (state && config.precommit === "auto") {
61
- lines.push(` pre-commit binary available: ${state.precommitAvailable === true ? "yes" : state.precommitAvailable === false ? "no" : "not checked yet"}`);
62
- }
63
60
  lines.push("");
64
61
  lines.push("Completion gate:");
65
62
  lines.push(` run_typecheck: ${config.gate.run_typecheck}`);
@@ -88,7 +85,33 @@ export function renderStatus(config, state) {
88
85
  if (config.style_guide) {
89
86
  lines.push(` style_guide: ${config.style_guide}`);
90
87
  }
88
+ return lines.join("\n");
89
+ }
90
+ /**
91
+ * Render a help message listing the available dev-framework slash commands.
92
+ */
93
+ export function renderHelp() {
94
+ const lines = [];
95
+ lines.push("dev-framework commands");
96
+ lines.push("");
97
+ lines.push("/df-status Show the current dev-framework state");
98
+ lines.push("/df-profile Change the profile to off, advisory, standard, or strict");
99
+ lines.push("/df-verify Run the completion gate manually");
100
+ lines.push("/df-help Show this message");
101
+ return lines.join("\n");
102
+ }
103
+ /**
104
+ * Render a human-readable summary of the current plugin state.
105
+ *
106
+ * Used by the `dev_framework_status` custom tool and by the server-side
107
+ * slash-command handler.
108
+ */
109
+ export function renderStatus(config, state) {
110
+ const lines = [renderConfigStatus(config)];
91
111
  if (state) {
112
+ if (config.precommit === "auto") {
113
+ lines.push(` pre-commit binary available: ${state.precommitAvailable === true ? "yes" : state.precommitAvailable === false ? "no" : "not checked yet"}`);
114
+ }
92
115
  const changedFiles = state.tracker.getChangedFiles();
93
116
  lines.push("");
94
117
  lines.push(`Changed files tracked: ${changedFiles.length}`);
package/dist/index.d.ts CHANGED
@@ -7,8 +7,8 @@
7
7
  * - event (session.idle) -> completion gate fallback (advisory logging)
8
8
  * - experimental.chat.system.transform -> constitution injection + session mapping
9
9
  * - experimental.session.stopping -> blocking completion gate (OpenCode >= PR #41811)
10
- * - config hook -> registers /df-status, /df-verify, /df-profile slash commands
11
- * - command.execute.before -> handles those slash commands directly
10
+ * - config hook -> registers /df-profile and /df-verify prompt commands
11
+ * - command.execute.before -> handles /df-profile, /df-verify, and unknown /df-*
12
12
  */
13
13
  import type { Hooks, Plugin, PluginInput } from "@opencode-ai/plugin";
14
14
  import { type ChangedFileTracker } from "./gate.js";
@@ -32,6 +32,6 @@ export interface HooksWithStopping extends Hooks {
32
32
  * Build the plugin's hooks and custom tools. Exported (rather than inlined in
33
33
  * the plugin) so tests can inject a stubbed command runner and tracker.
34
34
  */
35
- export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null): HooksWithStopping;
35
+ export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null, configMtime?: number): HooksWithStopping;
36
36
  export declare const devFramework: Plugin;
37
37
  export default devFramework;
package/dist/index.js CHANGED
@@ -7,30 +7,62 @@
7
7
  * - event (session.idle) -> completion gate fallback (advisory logging)
8
8
  * - experimental.chat.system.transform -> constitution injection + session mapping
9
9
  * - experimental.session.stopping -> blocking completion gate (OpenCode >= PR #41811)
10
- * - config hook -> registers /df-status, /df-verify, /df-profile slash commands
11
- * - command.execute.before -> handles those slash commands directly
10
+ * - config hook -> registers /df-profile and /df-verify prompt commands
11
+ * - command.execute.before -> handles /df-profile, /df-verify, and unknown /df-*
12
12
  */
13
+ import { stat } from "node:fs/promises";
13
14
  import { join } from "node:path";
14
15
  import { clearConfigCache, loadConfig } from "./config.js";
15
16
  import { createChangedFileTracker, runGate, summarizeGate, } from "./gate.js";
16
- import { renderStatus } from "./format-status.js";
17
17
  import { runCommand } from "./host.js";
18
18
  import { detectPreCommitAvailability, isLintFailure, lintFile, summarizeLint } from "./lint.js";
19
19
  import { createLogger } from "./logger.js";
20
20
  import { checkToolCall } from "./protect.js";
21
- import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory, updateHookState, } from "./registry.js";
21
+ import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory, } from "./registry.js";
22
22
  import { injectConstitution, loadConstitution } from "./rules.js";
23
- import { setProfileInFile } from "./installer.js";
24
23
  import { buildTools } from "./tools.js";
24
+ /**
25
+ * Reload the in-memory config if the config file on disk changed since we last
26
+ * loaded it. This makes out-of-process edits (e.g. a `/df-profile` change made
27
+ * from the TUI module, which writes the file directly) take effect on the next
28
+ * enforcement hook without restarting OpenCode.
29
+ */
30
+ async function reloadConfigIfChanged(state) {
31
+ const configPath = join(state.directory, ".opencode-dev-framework.yml");
32
+ try {
33
+ const stats = await stat(configPath);
34
+ if (state.configMtime !== undefined && state.configMtime === stats.mtimeMs) {
35
+ return;
36
+ }
37
+ clearConfigCache();
38
+ const next = loadConfig(state.directory);
39
+ const { constitution } = await loadConstitution(next, state.directory);
40
+ state.config = next;
41
+ state.constitution = constitution;
42
+ state.configMtime = stats.mtimeMs;
43
+ }
44
+ catch {
45
+ // Config file missing/unreadable — keep the current state.
46
+ }
47
+ }
25
48
  /**
26
49
  * Build the plugin's hooks and custom tools. Exported (rather than inlined in
27
50
  * the plugin) so tests can inject a stubbed command runner and tracker.
28
51
  */
29
- export function buildHooks(ctx, config, log, run = runCommand, tracker = createChangedFileTracker(), constitution = null) {
52
+ export function buildHooks(ctx, config, log, run = runCommand, tracker = createChangedFileTracker(), constitution = null, configMtime) {
30
53
  // All hook state — including the project directory — lives in the registry
31
54
  // and is looked up at call time. OpenCode's Effect runtime stripped closure
32
55
  // captures in production (config/log/run came back undefined), so hooks must
33
56
  // not rely on variables from this scope.
57
+ const showToast = (message, variant = "info") => {
58
+ try {
59
+ const tui = ctx.client.tui;
60
+ tui?.showToast?.({ title: "opencode-dev-framework", message, variant });
61
+ }
62
+ catch {
63
+ // TUI may be unavailable; the log line is enough.
64
+ }
65
+ };
34
66
  setHookState(ctx.directory, {
35
67
  directory: ctx.directory,
36
68
  config,
@@ -39,6 +71,8 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
39
71
  tracker,
40
72
  constitution,
41
73
  blockCounts: new Map(),
74
+ showToast,
75
+ configMtime,
42
76
  });
43
77
  return {
44
78
  tool: buildTools(ctx),
@@ -48,95 +82,18 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
48
82
  if (state) {
49
83
  state.hostPermissions = typedConfig.permission ?? [];
50
84
  }
51
- if (!typedConfig.command) {
52
- typedConfig.command = {};
53
- }
54
- typedConfig.command["df-status"] = {
55
- template: "",
56
- description: "Show the current dev-framework state",
57
- };
58
- typedConfig.command["df-profile"] = {
59
- template: "",
60
- description: "Change the dev-framework profile (off, advisory, standard, strict)",
61
- };
62
- typedConfig.command["df-verify"] = {
63
- template: "",
64
- description: "Run the dev-framework completion gate manually",
65
- };
66
- },
67
- "command.execute.before": async (input, output) => {
68
- const state = getStateForSession(input.sessionID);
69
- if (!state) {
70
- output.parts.length = 0;
71
- output.parts.push({
72
- type: "text",
73
- text: "[opencode-dev-framework] plugin state is not available for this session.",
74
- });
75
- return;
76
- }
77
- const directory = state.directory;
78
- const pushText = (text) => {
79
- output.parts.length = 0;
80
- output.parts.push({ type: "text", text });
81
- };
82
- if (input.command === "df-help" || input.command === "df") {
83
- pushText(`df — opencode-dev-framework commands
84
-
85
- /df-status Show the current dev-framework state
86
- /df-profile Change the profile to off, advisory, standard, or strict
87
- /df-verify Run the completion gate manually
88
- /df-help Show this message`);
89
- await state.log("info", "df-help command executed", { directory });
90
- return;
91
- }
92
- if (input.command === "df-status") {
93
- pushText(renderStatus(state.config, state));
94
- await state.log("info", "df-status command executed", { directory });
95
- return;
96
- }
97
- if (input.command === "df-profile") {
98
- const profile = input.arguments.trim().toLowerCase();
99
- const validProfiles = ["off", "advisory", "standard", "strict"];
100
- if (!validProfiles.includes(profile)) {
101
- pushText(`Invalid profile "${profile}". Valid values: ${validProfiles.join(", ")}.`);
102
- return;
103
- }
104
- const configPath = join(state.directory, ".opencode-dev-framework.yml");
105
- await setProfileInFile(configPath, profile);
106
- clearConfigCache();
107
- const nextConfig = loadConfig(state.directory);
108
- const { constitution } = await loadConstitution(nextConfig, state.directory);
109
- updateHookState(state.directory, { config: nextConfig, constitution });
110
- pushText(`opencode-dev-framework profile set to "${profile}". Change applied immediately.`);
111
- await state.log("info", "df-profile command executed", { directory, profile });
112
- return;
113
- }
114
- if (input.command === "df-verify") {
115
- const changedFiles = state.tracker.getChangedFiles();
116
- const report = await runGate(state.run, state.config, changedFiles, {
117
- cwd: state.directory,
118
- });
119
- const summary = summarizeGate(report);
120
- pushText(summary);
121
- const level = report.ok ? "info" : "error";
122
- await state.log(level, "df-verify command executed", {
123
- directory,
124
- ok: report.ok,
125
- ran: report.ran,
126
- });
127
- return;
128
- }
129
- // Unknown /df-* command — give a helpful response.
130
- if (input.command.startsWith("df-")) {
131
- pushText(`Unknown command /${input.command}. Try /df-help.`);
132
- await state.log("warn", "unknown df command", { directory, command: input.command });
133
- }
85
+ // `df-profile`, `df-verify`, `df-status`, and `df-help` are all registered
86
+ // as TUI commands (keymap layer with `slashName`) in `tui.tsx`. TUI
87
+ // commands never insert text into the chat stream, so they cannot leak
88
+ // into a model turn. No server prompt command is registered here — such
89
+ // commands always produce a model turn, which is exactly what we avoid.
134
90
  },
135
91
  "experimental.chat.system.transform": async (input, output) => {
136
92
  const state = getStateForSession(input.sessionID);
137
93
  if (!state) {
138
94
  return;
139
95
  }
96
+ await reloadConfigIfChanged(state);
140
97
  if (input.sessionID) {
141
98
  setSessionDirectory(input.sessionID, state.directory);
142
99
  }
@@ -151,6 +108,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
151
108
  if (!state) {
152
109
  throw new Error("[opencode-dev-framework] plugin state is not available; guardrail cannot evaluate this tool call");
153
110
  }
111
+ await reloadConfigIfChanged(state);
154
112
  const result = checkToolCall(state.config, input.tool, output.args, state.directory, state.hostPermissions);
155
113
  if (result.decision === "allow") {
156
114
  return;
@@ -170,7 +128,11 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
170
128
  },
171
129
  "experimental.session.stopping": async (input, output) => {
172
130
  const state = getStateForSession(input.sessionID);
173
- if (!state?.config.gate || state.config.profile === "off") {
131
+ if (!state) {
132
+ return;
133
+ }
134
+ await reloadConfigIfChanged(state);
135
+ if (!state.config.gate || state.config.profile === "off") {
174
136
  return;
175
137
  }
176
138
  const changedFiles = state.tracker.getChangedFiles();
@@ -212,6 +174,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
212
174
  if (!state) {
213
175
  return;
214
176
  }
177
+ await reloadConfigIfChanged(state);
215
178
  if (event.type === "file.edited") {
216
179
  const filePath = event.properties.file;
217
180
  state.tracker.add(filePath, state.directory);
@@ -317,6 +280,13 @@ export const devFramework = async (ctx) => {
317
280
  if (warning) {
318
281
  await log("warn", warning);
319
282
  }
320
- return buildHooks(ctx, config, log, runCommand, createChangedFileTracker(), constitution);
283
+ let configMtime;
284
+ try {
285
+ configMtime = (await stat(join(ctx.directory, ".opencode-dev-framework.yml"))).mtimeMs;
286
+ }
287
+ catch {
288
+ // Config file may not exist yet; reloadConfigIfChanged will pick it up.
289
+ }
290
+ return buildHooks(ctx, config, log, runCommand, createChangedFileTracker(), constitution, configMtime);
321
291
  };
322
292
  export default devFramework;
@@ -22,6 +22,11 @@ export interface HookState {
22
22
  precommitAvailable?: boolean;
23
23
  /** Snapshot of host permissions from OpenCode's effective config. */
24
24
  hostPermissions?: HostPermission[];
25
+ /** Show a non-chat TUI toast (used for slash-command results). */
26
+ showToast?: (message: string, variant?: "info" | "success" | "warning" | "error") => void;
27
+ /** mtime (ms) of the config file at last load; used to detect out-of-process
28
+ * edits (e.g. a `/df-profile` change made from the TUI module). */
29
+ configMtime?: number;
25
30
  }
26
31
  export declare function setBaseDirectory(directory: string): void;
27
32
  export declare function getBaseDirectory(): string | null;
package/dist/tools.js CHANGED
@@ -1,10 +1,10 @@
1
- import { join } from "node:path";
2
1
  import { tool } from "@opencode-ai/plugin";
3
2
  import { loadConfig, clearConfigCache } from "./config.js";
4
- import { installTemplates, setProfileInFile, writeDetectedConfig } from "./installer.js";
3
+ import { installTemplates, writeDetectedConfig } from "./installer.js";
5
4
  import { getHookState, updateHookState } from "./registry.js";
6
5
  import { loadConstitution } from "./rules.js";
7
6
  import { renderStatus } from "./format-status.js";
7
+ import { changeProfile } from "./commands.js";
8
8
  const PROFILES = ["off", "advisory", "standard", "strict"];
9
9
  function isProfile(value) {
10
10
  return PROFILES.includes(value);
@@ -64,8 +64,7 @@ export function buildTools(_ctx) {
64
64
  if (!isProfile(profile)) {
65
65
  return `Invalid profile "${args.profile}". Valid values: ${PROFILES.join(", ")}.`;
66
66
  }
67
- const configPath = join(targetDir, ".opencode-dev-framework.yml");
68
- await setProfileInFile(configPath, profile);
67
+ const message = await changeProfile(targetDir, profile);
69
68
  // Reload config and constitution so the change takes effect immediately.
70
69
  clearConfigCache();
71
70
  const config = loadConfig(targetDir);
@@ -74,7 +73,7 @@ export function buildTools(_ctx) {
74
73
  if (state) {
75
74
  updateHookState(targetDir, { config, constitution });
76
75
  }
77
- return `opencode-dev-framework profile set to "${profile}" in ${configPath}. Change applied immediately.`;
76
+ return `${message} Change applied immediately.`;
78
77
  },
79
78
  }),
80
79
  dev_framework_status: tool({
package/package.json CHANGED
@@ -1,11 +1,21 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "0.1.16",
3
+ "version": "0.1.25",
4
4
  "description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./tui": {
15
+ "types": "./dist/tui.d.ts",
16
+ "import": "./tui.tsx"
17
+ }
18
+ },
9
19
  "repository": {
10
20
  "type": "git",
11
21
  "url": "git+https://github.com/jwitmann/opencode-dev-framework.git"
@@ -14,15 +24,19 @@
14
24
  "dist",
15
25
  "bin",
16
26
  "rules",
17
- "templates"
27
+ "templates",
28
+ "tui.tsx"
18
29
  ],
19
30
  "bin": {
20
31
  "df": "bin/df"
21
32
  },
22
33
  "scripts": {
23
34
  "build": "tsc -p tsconfig.json",
24
- "typecheck": "tsc --noEmit -p tsconfig.json",
35
+ "pretypecheck": "npm run build",
36
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.tui.json",
37
+ "typecheck:tui": "tsc --noEmit -p tsconfig.tui.json",
25
38
  "test": "vitest run",
39
+ "pretest": "npm run build",
26
40
  "lint": "biome lint .",
27
41
  "lint:fix": "biome lint --write .",
28
42
  "format:check": "biome format .",
@@ -44,6 +58,9 @@
44
58
  "devDependencies": {
45
59
  "@biomejs/biome": "^2.5.8",
46
60
  "@opencode-ai/plugin": "^1.18.18",
61
+ "@opentui/core": "^0.5.3",
62
+ "@opentui/keymap": "^0.5.3",
63
+ "@opentui/solid": "^0.5.3",
47
64
  "@types/node": "^26.2.0",
48
65
  "@types/picomatch": "^4.0.3",
49
66
  "markdownlint-cli2": "^0.23.2",
package/tui.tsx ADDED
@@ -0,0 +1,192 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ import type { TuiPluginModule } from "@opencode-ai/plugin/tui";
4
+ import { changeProfile, verifyGate } from "./dist/commands.js";
5
+ import { loadConfig } from "./dist/config.js";
6
+ import { runCommand } from "./dist/host.js";
7
+ import { renderConfigStatus, renderHelp } from "./dist/format-status.js";
8
+ import type { Profile } from "./dist/types.js";
9
+
10
+ type TuiApi = Parameters<TuiPluginModule["tui"]>[0];
11
+
12
+ /**
13
+ * OpenCode invokes a slash command's `run` with a keymap `CommandContext`.
14
+ * The trailing slash text (e.g. `standard` in `/df-profile standard`) is
15
+ * available on `ctx.input`. TUI commands are UI-only: they never insert text
16
+ * into the chat stream, so they cannot leak into a model turn.
17
+ */
18
+ type CommandCtx = { input?: string };
19
+
20
+ type DevFrameworkCommand = {
21
+ title: string;
22
+ name: string;
23
+ description: string;
24
+ slashName: string;
25
+ run: (ctx?: CommandCtx) => void | Promise<void>;
26
+ };
27
+
28
+ /**
29
+ * Register dev-framework slash commands.
30
+ *
31
+ * The current OpenCode API is `api.keymap.registerLayer` (a command-palette
32
+ * layer that also wires up `/slash` invocations). This mirrors how DCP
33
+ * registers its commands. The legacy `api.command` v1 API is kept as a
34
+ * fallback (also like DCP). `slashName` makes OpenCode recognize the command
35
+ * **with arguments** and pass the trailing text to `run` via `ctx.input`.
36
+ *
37
+ * All four commands are TUI commands (no server prompt command, which would
38
+ * produce a model turn). Each `run` reads `ctx.input` so both the bare form
39
+ * (e.g. `/df-profile` opens a picker) and the argument form (e.g.
40
+ * `/df-profile standard` applies directly) work without feeding text to the
41
+ * model.
42
+ */
43
+ function registerCommands(api: TuiApi, commands: DevFrameworkCommand[]): void {
44
+ const keymap = (api as { keymap?: { registerLayer?: (layer: unknown) => void } }).keymap;
45
+ if (keymap?.registerLayer) {
46
+ keymap.registerLayer({
47
+ commands: commands.map((command) => ({
48
+ namespace: "palette",
49
+ name: command.name,
50
+ title: command.title,
51
+ desc: command.description,
52
+ category: "dev-framework",
53
+ slashName: command.slashName,
54
+ run: command.run,
55
+ })),
56
+ });
57
+ return;
58
+ }
59
+
60
+ // Legacy v1 API fallback (used on runtimes where keymap.registerLayer is
61
+ // unavailable). Mirrors how DCP registers its commands.
62
+ const commandApi = (api as { command?: { register?: (fn: () => unknown) => void } }).command;
63
+ commandApi?.register?.(() =>
64
+ commands.map((command) => ({
65
+ title: command.title,
66
+ value: command.name,
67
+ description: command.description,
68
+ category: "dev-framework",
69
+ slash: { name: command.slashName },
70
+ onSelect: command.run,
71
+ })),
72
+ );
73
+ }
74
+
75
+ const PROFILES: Profile[] = ["off", "advisory", "standard", "strict"];
76
+
77
+ const tui: TuiPluginModule["tui"] = async (api) => {
78
+ const directory = api.state.path.directory;
79
+
80
+ registerCommands(api, [
81
+ {
82
+ title: "dev-framework status",
83
+ name: "df-status",
84
+ description: "Show the current dev-framework configuration",
85
+ slashName: "df-status",
86
+ run: () => showStatusDialog(api, directory),
87
+ },
88
+ {
89
+ title: "dev-framework help",
90
+ name: "df-help",
91
+ description: "List available dev-framework commands",
92
+ slashName: "df-help",
93
+ run: () => showHelpDialog(api),
94
+ },
95
+ {
96
+ title: "dev-framework profile",
97
+ name: "df-profile",
98
+ description: "Change the active dev-framework profile",
99
+ slashName: "df-profile",
100
+ run: (ctx) => handleProfile(api, directory, ctx?.input),
101
+ },
102
+ {
103
+ title: "dev-framework verify",
104
+ name: "df-verify",
105
+ description: "Run the dev-framework completion gate",
106
+ slashName: "df-verify",
107
+ run: () => handleVerify(api, directory),
108
+ },
109
+ ]);
110
+ };
111
+
112
+ function showStatusDialog(api: TuiApi, directory: string): void {
113
+ const config = loadConfig(directory);
114
+ const DialogAlert = api.ui.DialogAlert;
115
+ api.ui.dialog.replace(() => (
116
+ <DialogAlert
117
+ title="opencode-dev-framework status"
118
+ message={renderConfigStatus(config)}
119
+ onConfirm={() => api.ui.dialog.clear()}
120
+ />
121
+ ));
122
+ }
123
+
124
+ function showHelpDialog(api: TuiApi): void {
125
+ const DialogAlert = api.ui.DialogAlert;
126
+ api.ui.dialog.replace(() => (
127
+ <DialogAlert
128
+ title="dev-framework commands"
129
+ message={renderHelp()}
130
+ onConfirm={() => api.ui.dialog.clear()}
131
+ />
132
+ ));
133
+ }
134
+
135
+ /** Bare `/df-profile` opens a picker; `/df-profile <name>` applies directly. */
136
+ function handleProfile(api: TuiApi, directory: string, input?: string): void {
137
+ // OpenCode passes the command name itself as `ctx.input` for a bare invocation
138
+ // (e.g. "df-profile"), not an empty string. Normalize that back to "bare".
139
+ const raw = (input ?? "").trim();
140
+ const arg = raw === "df-profile" ? "" : raw;
141
+ if (arg && PROFILES.includes(arg as Profile)) {
142
+ void changeProfile(directory, arg as Profile).then((message) => {
143
+ api.ui.toast?.({ message, variant: "success" });
144
+ });
145
+ api.ui.dialog.clear();
146
+ return;
147
+ }
148
+ if (arg) {
149
+ api.ui.toast?.({
150
+ message: `Usage: /df-profile <${PROFILES.join("|")}>`,
151
+ variant: "warning",
152
+ });
153
+ api.ui.dialog.clear();
154
+ return;
155
+ }
156
+ showProfileDialog(api, directory);
157
+ }
158
+
159
+ function showProfileDialog(api: TuiApi, directory: string): void {
160
+ const DialogSelect = api.ui.DialogSelect;
161
+ api.ui.dialog.replace(() => (
162
+ <DialogSelect
163
+ title="dev-framework profile"
164
+ options={PROFILES.map((p) => ({ title: p, value: p }))}
165
+ onSelect={(option) => {
166
+ api.ui.dialog.clear();
167
+ void changeProfile(directory, option.value as Profile).then((message) => {
168
+ api.ui.toast?.({ message, variant: "success" });
169
+ });
170
+ }}
171
+ />
172
+ ));
173
+ }
174
+
175
+ async function handleVerify(api: TuiApi, directory: string): Promise<void> {
176
+ const config = loadConfig(directory);
177
+ const { summary, report } = await verifyGate(runCommand, directory, config);
178
+ const DialogAlert = api.ui.DialogAlert;
179
+ api.ui.dialog.replace(() => (
180
+ <DialogAlert
181
+ title={report.ok ? "dev-framework gate passed" : "dev-framework gate failed"}
182
+ message={summary}
183
+ onConfirm={() => api.ui.dialog.clear()}
184
+ />
185
+ ));
186
+ api.ui.toast?.({ message: summary, variant: report.ok ? "success" : "error" });
187
+ }
188
+
189
+ export default {
190
+ id: "opencode-dev-framework",
191
+ tui,
192
+ } satisfies TuiPluginModule;