opencode-dev-framework 0.1.18 → 0.1.27
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 +49 -16
- package/dist/commands.d.ts +21 -0
- package/dist/commands.js +27 -0
- package/dist/format-status.d.ts +12 -1
- package/dist/format-status.js +30 -7
- package/dist/index.d.ts +3 -4
- package/dist/index.js +69 -102
- package/dist/protect.d.ts +2 -2
- package/dist/protect.js +29 -38
- package/dist/registry.d.ts +16 -9
- package/dist/tools.js +4 -5
- package/package.json +20 -3
- package/rules/40-delegation.md +6 -2
- package/templates/.opencode/agents/code-reviewer.md +80 -0
- package/templates/.opencode/skills/code-review/SKILL.md +67 -0
- package/templates/.opencode/skills/peer-review/SKILL.md +29 -23
- package/tui.tsx +192 -0
- package/dist/messenger.d.ts +0 -9
- package/dist/messenger.js +0 -28
package/README.md
CHANGED
|
@@ -30,12 +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.**
|
|
34
|
-
|
|
35
|
-
`/df-status` and `/df-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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.
|
|
39
43
|
|
|
40
44
|
## Profiles
|
|
41
45
|
|
|
@@ -52,7 +56,7 @@ reimplemented as an OpenCode-native plugin.
|
|
|
52
56
|
npm install opencode-dev-framework
|
|
53
57
|
```
|
|
54
58
|
|
|
55
|
-
Then add
|
|
59
|
+
Then add the plugin to your project's `opencode.json`:
|
|
56
60
|
|
|
57
61
|
```json
|
|
58
62
|
{
|
|
@@ -60,6 +64,11 @@ Then add it to your project's `opencode.json`:
|
|
|
60
64
|
}
|
|
61
65
|
```
|
|
62
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
|
+
|
|
63
72
|
Finally, scaffold the project-level files (agents, skills, local rules directory,
|
|
64
73
|
and default config) into your repo with the bundled `df` CLI:
|
|
65
74
|
|
|
@@ -79,7 +88,21 @@ profile from the shell; `df version` prints the plugin version.
|
|
|
79
88
|
## Local development and testing
|
|
80
89
|
|
|
81
90
|
To test the plugin from source without publishing to npm, point OpenCode at the
|
|
82
|
-
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):
|
|
83
106
|
|
|
84
107
|
```json
|
|
85
108
|
{
|
|
@@ -88,7 +111,8 @@ local repository path in your project's `opencode.json`:
|
|
|
88
111
|
```
|
|
89
112
|
|
|
90
113
|
The path must be the **repository root** (where `package.json` lives). OpenCode
|
|
91
|
-
loads `dist/index.js
|
|
114
|
+
loads the server plugin from `dist/index.js` and the TUI plugin from `tui.tsx`,
|
|
115
|
+
so rebuild after every source change:
|
|
92
116
|
|
|
93
117
|
```bash
|
|
94
118
|
npm run build
|
|
@@ -156,16 +180,25 @@ complete example.
|
|
|
156
180
|
|
|
157
181
|
## Slash commands
|
|
158
182
|
|
|
159
|
-
|
|
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:
|
|
160
186
|
|
|
161
|
-
- `/df-status` — shows the current profile, guardrails, completion gate,
|
|
162
|
-
configured commands
|
|
163
|
-
- `/df-
|
|
164
|
-
- `/df-profile
|
|
165
|
-
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.
|
|
166
196
|
|
|
167
197
|
You can still run `df init` to install the bundled agents, skills, and default
|
|
168
|
-
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).
|
|
169
202
|
|
|
170
203
|
## Limitations
|
|
171
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
|
+
}>;
|
package/dist/commands.js
ADDED
|
@@ -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
|
+
}
|
package/dist/format-status.d.ts
CHANGED
|
@@ -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
|
|
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;
|
package/dist/format-status.js
CHANGED
|
@@ -28,12 +28,12 @@ function formatRules(rules) {
|
|
|
28
28
|
return lines.join("\n");
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Render
|
|
31
|
+
* Render the config-only portion of the status summary.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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
|
|
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,14 +7,13 @@
|
|
|
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-
|
|
11
|
-
* - command.execute.before -> handles
|
|
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";
|
|
15
15
|
import { type RunCommand } from "./host.js";
|
|
16
16
|
import { type LogFn } from "./logger.js";
|
|
17
|
-
import { type SendMessageFn } from "./messenger.js";
|
|
18
17
|
import type { ResolvedConfig } from "./types.js";
|
|
19
18
|
/**
|
|
20
19
|
* The `experimental.session.stopping` hook was added in OpenCode PR #41811
|
|
@@ -33,6 +32,6 @@ export interface HooksWithStopping extends Hooks {
|
|
|
33
32
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
34
33
|
* the plugin) so tests can inject a stubbed command runner and tracker.
|
|
35
34
|
*/
|
|
36
|
-
export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null,
|
|
35
|
+
export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null, configMtime?: number): HooksWithStopping;
|
|
37
36
|
export declare const devFramework: Plugin;
|
|
38
37
|
export default devFramework;
|
package/dist/index.js
CHANGED
|
@@ -7,31 +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-
|
|
11
|
-
* - command.execute.before -> handles
|
|
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
|
-
import { createMessenger } from "./messenger.js";
|
|
21
20
|
import { checkToolCall } from "./protect.js";
|
|
22
|
-
import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory,
|
|
21
|
+
import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory, } from "./registry.js";
|
|
23
22
|
import { injectConstitution, loadConstitution } from "./rules.js";
|
|
24
|
-
import { setProfileInFile } from "./installer.js";
|
|
25
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
|
+
}
|
|
26
48
|
/**
|
|
27
49
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
28
50
|
* the plugin) so tests can inject a stubbed command runner and tracker.
|
|
29
51
|
*/
|
|
30
|
-
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) {
|
|
31
53
|
// All hook state — including the project directory — lives in the registry
|
|
32
54
|
// and is looked up at call time. OpenCode's Effect runtime stripped closure
|
|
33
55
|
// captures in production (config/log/run came back undefined), so hooks must
|
|
34
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
|
+
};
|
|
35
66
|
setHookState(ctx.directory, {
|
|
36
67
|
directory: ctx.directory,
|
|
37
68
|
config,
|
|
@@ -40,7 +71,8 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
40
71
|
tracker,
|
|
41
72
|
constitution,
|
|
42
73
|
blockCounts: new Map(),
|
|
43
|
-
|
|
74
|
+
showToast,
|
|
75
|
+
configMtime,
|
|
44
76
|
});
|
|
45
77
|
return {
|
|
46
78
|
tool: buildTools(ctx),
|
|
@@ -48,105 +80,27 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
48
80
|
const typedConfig = opencodeConfig;
|
|
49
81
|
const state = getHookState(ctx.directory);
|
|
50
82
|
if (state) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
typedConfig.command["df-profile"] = {
|
|
61
|
-
template: "",
|
|
62
|
-
description: "Change the dev-framework profile (off, advisory, standard, strict)",
|
|
63
|
-
};
|
|
64
|
-
typedConfig.command["df-verify"] = {
|
|
65
|
-
template: "",
|
|
66
|
-
description: "Run the dev-framework completion gate manually",
|
|
67
|
-
};
|
|
68
|
-
typedConfig.command["df-help"] = {
|
|
69
|
-
template: "",
|
|
70
|
-
description: "List the available dev-framework slash commands",
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
"command.execute.before": async (input, output) => {
|
|
74
|
-
const state = getStateForSession(input.sessionID);
|
|
75
|
-
if (!state) {
|
|
76
|
-
const fallback = "[opencode-dev-framework] plugin state is not available for this session.";
|
|
77
|
-
output.parts.length = 0;
|
|
78
|
-
output.parts.push({ type: "text", text: fallback });
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const directory = state.directory;
|
|
82
|
-
const reply = async (text) => {
|
|
83
|
-
if (state.sendMessage) {
|
|
84
|
-
output.parts.length = 0;
|
|
85
|
-
await state.sendMessage(input.sessionID, text);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
output.parts.length = 0;
|
|
89
|
-
output.parts.push({ type: "text", text });
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
if (input.command === "df-help" || input.command === "df") {
|
|
93
|
-
await reply(`df — opencode-dev-framework commands
|
|
94
|
-
|
|
95
|
-
/df-status Show the current dev-framework state
|
|
96
|
-
/df-profile Change the profile to off, advisory, standard, or strict
|
|
97
|
-
/df-verify Run the completion gate manually
|
|
98
|
-
/df-help Show this message`);
|
|
99
|
-
await state.log("info", "df-help command executed", { directory });
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (input.command === "df-status") {
|
|
103
|
-
await reply(renderStatus(state.config, state));
|
|
104
|
-
await state.log("info", "df-status command executed", { directory });
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (input.command === "df-profile") {
|
|
108
|
-
const profile = input.arguments.trim().toLowerCase();
|
|
109
|
-
const validProfiles = ["off", "advisory", "standard", "strict"];
|
|
110
|
-
if (!validProfiles.includes(profile)) {
|
|
111
|
-
await reply(`Invalid profile "${profile}". Valid values: ${validProfiles.join(", ")}.`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const configPath = join(state.directory, ".opencode-dev-framework.yml");
|
|
115
|
-
await setProfileInFile(configPath, profile);
|
|
116
|
-
clearConfigCache();
|
|
117
|
-
const nextConfig = loadConfig(state.directory);
|
|
118
|
-
const { constitution } = await loadConstitution(nextConfig, state.directory);
|
|
119
|
-
updateHookState(state.directory, { config: nextConfig, constitution });
|
|
120
|
-
await reply(`opencode-dev-framework profile set to "${profile}". Change applied immediately.`);
|
|
121
|
-
await state.log("info", "df-profile command executed", { directory, profile });
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (input.command === "df-verify") {
|
|
125
|
-
const changedFiles = state.tracker.getChangedFiles();
|
|
126
|
-
const report = await runGate(state.run, state.config, changedFiles, {
|
|
127
|
-
cwd: state.directory,
|
|
128
|
-
});
|
|
129
|
-
const summary = summarizeGate(report);
|
|
130
|
-
await reply(summary);
|
|
131
|
-
const level = report.ok ? "info" : "error";
|
|
132
|
-
await state.log(level, "df-verify command executed", {
|
|
133
|
-
directory,
|
|
134
|
-
ok: report.ok,
|
|
135
|
-
ran: report.ran,
|
|
136
|
-
});
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
// Unknown /df-* command — give a helpful response.
|
|
140
|
-
if (input.command.startsWith("df-")) {
|
|
141
|
-
await reply(`Unknown command /${input.command}. Try /df-help.`);
|
|
142
|
-
await state.log("warn", "unknown df command", { directory, command: input.command });
|
|
83
|
+
// OpenCode's native `permission` is a per-agent tool-to-mode object
|
|
84
|
+
// (e.g. `{ edit: "deny", bash: "deny" }`), not an array. Adopt it when
|
|
85
|
+
// it is a plain object; anything else (array, string, undefined) is
|
|
86
|
+
// ignored so the guardrail falls back to its own evaluation. See
|
|
87
|
+
// hostDenies in protect.ts.
|
|
88
|
+
const perm = typedConfig.permission;
|
|
89
|
+
state.hostPermissions =
|
|
90
|
+
perm !== undefined && typeof perm === "object" && !Array.isArray(perm) ? perm : undefined;
|
|
143
91
|
}
|
|
92
|
+
// `df-profile`, `df-verify`, `df-status`, and `df-help` are all registered
|
|
93
|
+
// as TUI commands (keymap layer with `slashName`) in `tui.tsx`. TUI
|
|
94
|
+
// commands never insert text into the chat stream, so they cannot leak
|
|
95
|
+
// into a model turn. No server prompt command is registered here — such
|
|
96
|
+
// commands always produce a model turn, which is exactly what we avoid.
|
|
144
97
|
},
|
|
145
98
|
"experimental.chat.system.transform": async (input, output) => {
|
|
146
99
|
const state = getStateForSession(input.sessionID);
|
|
147
100
|
if (!state) {
|
|
148
101
|
return;
|
|
149
102
|
}
|
|
103
|
+
await reloadConfigIfChanged(state);
|
|
150
104
|
if (input.sessionID) {
|
|
151
105
|
setSessionDirectory(input.sessionID, state.directory);
|
|
152
106
|
}
|
|
@@ -161,6 +115,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
161
115
|
if (!state) {
|
|
162
116
|
throw new Error("[opencode-dev-framework] plugin state is not available; guardrail cannot evaluate this tool call");
|
|
163
117
|
}
|
|
118
|
+
await reloadConfigIfChanged(state);
|
|
164
119
|
const result = checkToolCall(state.config, input.tool, output.args, state.directory, state.hostPermissions);
|
|
165
120
|
if (result.decision === "allow") {
|
|
166
121
|
return;
|
|
@@ -180,7 +135,11 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
180
135
|
},
|
|
181
136
|
"experimental.session.stopping": async (input, output) => {
|
|
182
137
|
const state = getStateForSession(input.sessionID);
|
|
183
|
-
if (!state
|
|
138
|
+
if (!state) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
await reloadConfigIfChanged(state);
|
|
142
|
+
if (!state.config.gate || state.config.profile === "off") {
|
|
184
143
|
return;
|
|
185
144
|
}
|
|
186
145
|
const changedFiles = state.tracker.getChangedFiles();
|
|
@@ -222,6 +181,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
222
181
|
if (!state) {
|
|
223
182
|
return;
|
|
224
183
|
}
|
|
184
|
+
await reloadConfigIfChanged(state);
|
|
225
185
|
if (event.type === "file.edited") {
|
|
226
186
|
const filePath = event.properties.file;
|
|
227
187
|
state.tracker.add(filePath, state.directory);
|
|
@@ -327,6 +287,13 @@ export const devFramework = async (ctx) => {
|
|
|
327
287
|
if (warning) {
|
|
328
288
|
await log("warn", warning);
|
|
329
289
|
}
|
|
330
|
-
|
|
290
|
+
let configMtime;
|
|
291
|
+
try {
|
|
292
|
+
configMtime = (await stat(join(ctx.directory, ".opencode-dev-framework.yml"))).mtimeMs;
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// Config file may not exist yet; reloadConfigIfChanged will pick it up.
|
|
296
|
+
}
|
|
297
|
+
return buildHooks(ctx, config, log, runCommand, createChangedFileTracker(), constitution, configMtime);
|
|
331
298
|
};
|
|
332
299
|
export default devFramework;
|
package/dist/protect.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* shell commands. Pure functions — the OpenCode hook wiring lives in
|
|
4
4
|
* src/index.ts.
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { OpenCodePermission } from "./registry.js";
|
|
7
7
|
import type { ResolvedConfig } from "./types.js";
|
|
8
8
|
export type GuardDecision = "allow" | "warn" | "deny";
|
|
9
9
|
export interface GuardResult {
|
|
@@ -41,4 +41,4 @@ export declare function matchDangerousCommand(command: string): DangerousCommand
|
|
|
41
41
|
* `protect_off: true`), when the tool is not guarded, or when nothing
|
|
42
42
|
* matched. Otherwise returns `deny` or `warn` per `protect_mode`.
|
|
43
43
|
*/
|
|
44
|
-
export declare function checkToolCall(config: ResolvedConfig, tool: string, args: unknown, directory?: string, hostPermissions?:
|
|
44
|
+
export declare function checkToolCall(config: ResolvedConfig, tool: string, args: unknown, directory?: string, hostPermissions?: OpenCodePermission): GuardResult;
|
package/dist/protect.js
CHANGED
|
@@ -79,44 +79,35 @@ export function matchProtectedPath(config, filePath, directory) {
|
|
|
79
79
|
export function matchDangerousCommand(command) {
|
|
80
80
|
return DANGEROUS_COMMANDS.find(({ pattern }) => pattern.test(command));
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Check whether the host OpenCode config already denies this tool.
|
|
84
|
+
*
|
|
85
|
+
* OpenCode's native `permission` config is a tool-to-mode object (e.g.
|
|
86
|
+
* `{ edit: "deny", bash: "deny" }`). The plugin consults it only to avoid
|
|
87
|
+
* double-blocking: if OpenCode already globally denies the tool a call
|
|
88
|
+
* targets, the plugin stands down and lets OpenCode enforce the denial itself.
|
|
89
|
+
*
|
|
90
|
+
* The mapping from this plugin's tool names to OpenCode's permission keys is:
|
|
91
|
+
* - file tools (edit/write/patch) -> `edit`
|
|
92
|
+
* - shell tools (bash/shell) -> `bash`
|
|
93
|
+
*
|
|
94
|
+
* Only a literal `"deny"` mode stands the plugin down. OpenCode's `bash` may
|
|
95
|
+
* instead be an object map (per-command), whose keys are ambiguous, so we
|
|
96
|
+
* conservatively keep guarding there — at worst redundant noise, never a
|
|
97
|
+
* crash or a missed block. Any non-object input (array, string, undefined) is
|
|
98
|
+
* ignored, falling back to the plugin's own evaluation.
|
|
99
|
+
*/
|
|
100
|
+
function hostDenies(tool, hostPermissions) {
|
|
101
|
+
if (hostPermissions === undefined ||
|
|
102
|
+
typeof hostPermissions !== "object" ||
|
|
103
|
+
Array.isArray(hostPermissions)) {
|
|
97
104
|
return false;
|
|
98
105
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (perm.permission && !permissionMatchesTool(perm.permission, tool)) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (perm.pattern) {
|
|
107
|
-
const matcher = picomatch(perm.pattern, { dot: true });
|
|
108
|
-
let candidate = target;
|
|
109
|
-
if (directory !== undefined && isAbsolute(target)) {
|
|
110
|
-
candidate = relative(directory, target);
|
|
111
|
-
}
|
|
112
|
-
candidate = candidate.replace(/^\.\//, "");
|
|
113
|
-
if (!matcher(candidate) && !matcher(basename(candidate))) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
106
|
+
const key = FILE_TOOLS.has(tool) ? "edit" : SHELL_TOOLS.has(tool) ? "bash" : undefined;
|
|
107
|
+
if (key === undefined) {
|
|
108
|
+
return false;
|
|
118
109
|
}
|
|
119
|
-
return
|
|
110
|
+
return hostPermissions[key] === "deny";
|
|
120
111
|
}
|
|
121
112
|
function enforce(config, reason, matchedPattern) {
|
|
122
113
|
if (config.protect_mode === "deny") {
|
|
@@ -140,9 +131,9 @@ export function checkToolCall(config, tool, args, directory, hostPermissions) {
|
|
|
140
131
|
if (filePath === undefined) {
|
|
141
132
|
return { decision: "allow" };
|
|
142
133
|
}
|
|
143
|
-
// If the host permission model already denies this
|
|
134
|
+
// If the host permission model already denies this tool, do not duplicate
|
|
144
135
|
// the block here.
|
|
145
|
-
if (hostDenies(tool,
|
|
136
|
+
if (hostDenies(tool, hostPermissions)) {
|
|
146
137
|
return { decision: "allow" };
|
|
147
138
|
}
|
|
148
139
|
const pattern = matchProtectedPath(config, filePath, directory);
|
|
@@ -156,7 +147,7 @@ export function checkToolCall(config, tool, args, directory, hostPermissions) {
|
|
|
156
147
|
if (command === undefined) {
|
|
157
148
|
return { decision: "allow" };
|
|
158
149
|
}
|
|
159
|
-
if (hostDenies(tool,
|
|
150
|
+
if (hostDenies(tool, hostPermissions)) {
|
|
160
151
|
return { decision: "allow" };
|
|
161
152
|
}
|
|
162
153
|
const dangerous = matchDangerousCommand(command);
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { ChangedFileTracker } from "./gate.js";
|
|
2
2
|
import type { RunCommand } from "./host.js";
|
|
3
3
|
import type { LogFn } from "./logger.js";
|
|
4
|
-
import type { SendMessageFn } from "./messenger.js";
|
|
5
4
|
import type { ResolvedConfig } from "./types.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* OpenCode's native `permission` config is a per-agent, tool-to-mode object
|
|
7
|
+
* (e.g. `{ edit: "deny", bash: "deny", read: "allow", task: {...} }`), not an
|
|
8
|
+
* array. The plugin consults it only to avoid double-blocking: when OpenCode
|
|
9
|
+
* already globally denies a tool, the guardrail stands down and lets OpenCode
|
|
10
|
+
* enforce the denial. Path-scoped rules (e.g. "deny writes to .env") are not
|
|
11
|
+
* expressible in OpenCode's permission model, so the plugin keeps guarding
|
|
12
|
+
* those itself.
|
|
13
|
+
*/
|
|
14
|
+
export type OpenCodePermission = Record<string, unknown>;
|
|
11
15
|
export interface HookState {
|
|
12
16
|
/** Project directory this state belongs to. Stored here (rather than
|
|
13
17
|
* closure-captured by hooks) so every hook invocation is self-contained. */
|
|
@@ -22,9 +26,12 @@ export interface HookState {
|
|
|
22
26
|
/** Cached result of checking whether `pre-commit` is available. */
|
|
23
27
|
precommitAvailable?: boolean;
|
|
24
28
|
/** Snapshot of host permissions from OpenCode's effective config. */
|
|
25
|
-
hostPermissions?:
|
|
26
|
-
/**
|
|
27
|
-
|
|
29
|
+
hostPermissions?: OpenCodePermission;
|
|
30
|
+
/** Show a non-chat TUI toast (used for slash-command results). */
|
|
31
|
+
showToast?: (message: string, variant?: "info" | "success" | "warning" | "error") => void;
|
|
32
|
+
/** mtime (ms) of the config file at last load; used to detect out-of-process
|
|
33
|
+
* edits (e.g. a `/df-profile` change made from the TUI module). */
|
|
34
|
+
configMtime?: number;
|
|
28
35
|
}
|
|
29
36
|
export declare function setBaseDirectory(directory: string): void;
|
|
30
37
|
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,
|
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.1.27",
|
|
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
|
-
"
|
|
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/rules/40-delegation.md
CHANGED
|
@@ -20,6 +20,10 @@ a description and ask them to report findings; do not ask them to edit product c
|
|
|
20
20
|
- **`test-grounder`** — audits whether your claims are backed by evidence: is there a
|
|
21
21
|
test that fails without the change? do the cited commands actually pass? did you
|
|
22
22
|
verify the edge cases? Use it before declaring a task done.
|
|
23
|
+
- **`code-reviewer`** — checks changed code for correctness defects: logic errors,
|
|
24
|
+
unsafe edge cases, security issues, and concurrency/resource leaks. Use it after
|
|
25
|
+
a batch of edits, alongside `style-enforcer` and `pattern-guardian`, before the
|
|
26
|
+
completion gate. (Investigation-only, like the others.)
|
|
23
27
|
|
|
24
28
|
You may also ask the built-in review or planning agents for a general high-signal
|
|
25
29
|
second opinion — the best moment is after planning, before implementing, and again
|
|
@@ -42,8 +46,8 @@ checks yourself with the skills in this section.
|
|
|
42
46
|
## Skills
|
|
43
47
|
|
|
44
48
|
For explicit, repeatable workflows you can invoke the bundled skills:
|
|
45
|
-
**`peer-review`**, **`ground-in-tests`**, and
|
|
46
|
-
steps above so you run them consistently.
|
|
49
|
+
**`peer-review`**, **`code-review`**, **`ground-in-tests`**, and
|
|
50
|
+
**`match-patterns`**. They codify the steps above so you run them consistently.
|
|
47
51
|
|
|
48
52
|
## Acting on feedback
|
|
49
53
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-reviewer
|
|
3
|
+
description: >
|
|
4
|
+
Correctness reviewer. Scans changed code for bugs, logic errors, security
|
|
5
|
+
issues, and unsafe edge cases — independent of style and pattern concerns.
|
|
6
|
+
Use after a batch of edits and before declaring a non-trivial change done.
|
|
7
|
+
Investigation only — never edits.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
You are the **code-reviewer**: your only job is to catch correctness problems in
|
|
11
|
+
changed code — the things that break at runtime, corrupt data, leak resources,
|
|
12
|
+
or let attackers in. Style and pattern concerns belong to other reviewers
|
|
13
|
+
(`style-enforcer`, `pattern-guardian`); you focus on whether the code is
|
|
14
|
+
*correct and safe*.
|
|
15
|
+
|
|
16
|
+
## Your mission
|
|
17
|
+
|
|
18
|
+
Given a set of changed files (a diff), find genuine defects:
|
|
19
|
+
|
|
20
|
+
1. **Logic errors** — wrong conditions, off-by-one, inverted booleans,
|
|
21
|
+
unreachable branches, operator precedence mistakes, assumptions that don't
|
|
22
|
+
hold (e.g. "this can't be null"), mutation of shared state, stale closures,
|
|
23
|
+
swapped arguments.
|
|
24
|
+
2. **Edge cases** — empty input, zero, negative, max, missing keys, first/last
|
|
25
|
+
element, concurrent callers, retries, partial failure, encoding/Unicode,
|
|
26
|
+
timezones, locale.
|
|
27
|
+
3. **Security** — unvalidated input, injection (SQL / command / XML / path),
|
|
28
|
+
path traversal, insecure defaults, secrets committed or logged, authorization
|
|
29
|
+
checks skipped, unsafe deserialization, weak randomness, TOCTOU.
|
|
30
|
+
4. **Concurrency & resources** — races, deadlocks, missing locks, leaked
|
|
31
|
+
handles / connections / goroutines, blocking calls on hot paths, unbounded
|
|
32
|
+
growth, forgetting to close / await / release.
|
|
33
|
+
5. **Correctness vs intent** — does the change actually do what the surrounding
|
|
34
|
+
code and the task say it should? Watch for copy-paste that silently changed
|
|
35
|
+
behavior, or a "fix" that breaks an adjacent path.
|
|
36
|
+
6. **Red flags** — leftover debug code, `console.log` / `print` left in,
|
|
37
|
+
TODO/FIXME that ships a known-broken path, commented-out code hiding a real
|
|
38
|
+
fix, swallowed errors (`catch {}`), assertions that can't fail.
|
|
39
|
+
|
|
40
|
+
## How to work
|
|
41
|
+
|
|
42
|
+
1. Get the change scope via git:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git --no-pager diff --staged
|
|
46
|
+
git --no-pager diff
|
|
47
|
+
# if the tree is clean, review the branch: git --no-pager diff main...HEAD
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
2. Read the changed files in full — a defect often spans the edit boundary, so
|
|
51
|
+
the surrounding function matters as much as the diff hunk.
|
|
52
|
+
3. For each suspicion, read enough context to confirm it is real. Do not flag
|
|
53
|
+
hypotheticals you haven't verified against the code.
|
|
54
|
+
4. If the project has tests, you may run the relevant ones to confirm a defect
|
|
55
|
+
reproduces (or to check a fix), but prefer reporting findings with evidence.
|
|
56
|
+
|
|
57
|
+
## Output
|
|
58
|
+
|
|
59
|
+
Report only genuine, actionable defects against the changed code. For each:
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
## Bug: [short title]
|
|
63
|
+
**Where:** path/to/file.ext:line
|
|
64
|
+
**Severity:** Blocking | Should-fix | Note
|
|
65
|
+
**Evidence:** the code path / input that triggers it
|
|
66
|
+
**Impact:** what actually breaks
|
|
67
|
+
**Fix:** the concrete correction (do not implement it)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
If the changed code is correct, say exactly: "No correctness issues — changes
|
|
71
|
+
look sound." If you found only minor notes, list them under **Note**.
|
|
72
|
+
|
|
73
|
+
## Hard rules
|
|
74
|
+
|
|
75
|
+
- **Investigation only. Never use `edit` or `create`. Never modify files.**
|
|
76
|
+
- Every finding must be a real defect you verified against the code, with a file
|
|
77
|
+
and line. No style nits, no "consider using X" preferences — those belong to
|
|
78
|
+
other reviewers.
|
|
79
|
+
- High bar, high signal. A wrong or speculative report is worse than silence.
|
|
80
|
+
- All file paths in your report must be absolute.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-review
|
|
3
|
+
description: >
|
|
4
|
+
Standalone correctness review of the current changes. Delegates to the
|
|
5
|
+
code-reviewer agent for bugs, logic errors, security, and resource/concurrency
|
|
6
|
+
issues, then drives the blocking findings to resolution. Use directly (instead
|
|
7
|
+
of the broader peer-review pass) when you want a focused correctness audit —
|
|
8
|
+
e.g. after a batch of edits, before a commit, or when the user asks for a
|
|
9
|
+
code review.
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Code Review
|
|
13
|
+
|
|
14
|
+
A focused, correctness-first audit of what you just changed — independent of
|
|
15
|
+
style and pattern concerns (those live in `style-enforcer` / `pattern-guardian`
|
|
16
|
+
and the broader `peer-review` pass).
|
|
17
|
+
|
|
18
|
+
## When to use
|
|
19
|
+
|
|
20
|
+
- After a non-trivial batch of edits and before you declare it done.
|
|
21
|
+
- Before committing or opening a PR.
|
|
22
|
+
- When the user explicitly asks for a code review or "check my changes".
|
|
23
|
+
- As a lighter-weight alternative to the full peer-review pass when you only
|
|
24
|
+
care about correctness.
|
|
25
|
+
|
|
26
|
+
## Steps
|
|
27
|
+
|
|
28
|
+
1. **Scope the change.** Get exactly what changed:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
git --no-pager diff --staged
|
|
32
|
+
git --no-pager diff
|
|
33
|
+
# if the tree is clean, review the branch: git --no-pager diff main...HEAD
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
If there is nothing to review, say so and stop.
|
|
37
|
+
|
|
38
|
+
2. **Run the code-reviewer pass.** Delegate to the **code-reviewer** agent,
|
|
39
|
+
giving it the diff scope and the paths that changed. The agent is
|
|
40
|
+
investigation-only: it returns `Blocking` / `Should-fix` / `Note` findings
|
|
41
|
+
with absolute file paths and line numbers, and never edits.
|
|
42
|
+
|
|
43
|
+
If the `code-reviewer` agent is not installed in this project (or cannot be
|
|
44
|
+
invoked in the current environment), perform the pass yourself inline: read
|
|
45
|
+
the diff in full, and for each changed file check for logic errors, unsafe
|
|
46
|
+
edge cases, security issues, and concurrency/resource leaks, reporting the
|
|
47
|
+
same `Blocking` / `Should-fix` / `Note` findings.
|
|
48
|
+
|
|
49
|
+
3. **Triage.** Drop duplicates and anything non-actionable. Group by severity:
|
|
50
|
+
**Blocking**, **Should-fix**, **Note**.
|
|
51
|
+
|
|
52
|
+
4. **Act, don't just report.** For every **Blocking** and **Should-fix** item:
|
|
53
|
+
fix it now (you may edit here — the agent may not), or state precisely why
|
|
54
|
+
it does not apply. Do not produce a list of issues you then leave
|
|
55
|
+
unaddressed.
|
|
56
|
+
|
|
57
|
+
5. **Confirm.** Re-run the code-reviewer pass after non-trivial fixes, until no
|
|
58
|
+
blocking items remain.
|
|
59
|
+
|
|
60
|
+
## Output
|
|
61
|
+
|
|
62
|
+
A short list grouped by **Blocking / Should-fix / Note**, and for each the
|
|
63
|
+
action you took. If the review found nothing, say "Code review clean — no
|
|
64
|
+
blocking issues."
|
|
65
|
+
|
|
66
|
+
> For the broader review (consistency + style + correctness together), use the
|
|
67
|
+
> **peer-review** skill instead.
|
|
@@ -3,7 +3,7 @@ name: peer-review
|
|
|
3
3
|
description: >
|
|
4
4
|
Run a continuous-peer-review pass over the current changes to prevent
|
|
5
5
|
fragmentation and drift before completion. Orchestrates the pattern-guardian,
|
|
6
|
-
style-enforcer, and
|
|
6
|
+
style-enforcer, and code-reviewer agents, then consolidates only the
|
|
7
7
|
blocking items. Use after a batch of edits and before declaring a non-trivial
|
|
8
8
|
change done.
|
|
9
9
|
---
|
|
@@ -20,34 +20,40 @@ whenever the user asks for a review of the current changes.
|
|
|
20
20
|
|
|
21
21
|
## Steps
|
|
22
22
|
|
|
23
|
-
1. **Scope the change.** Determine exactly what changed:
|
|
23
|
+
1. **Scope the change.** Determine exactly what changed:
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
```bash
|
|
26
|
+
git --no-pager diff --staged
|
|
27
|
+
git --no-pager diff
|
|
28
|
+
# if the tree is clean, review the branch: git --no-pager diff main...HEAD
|
|
29
|
+
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
If there is nothing to review, say so and stop.
|
|
32
32
|
|
|
33
|
-
2. **Run the specialists in parallel.** Delegate each as a subagent, giving
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
2. **Run the specialists in parallel.** Delegate each as a subagent, giving
|
|
34
|
+
each the diff scope and the relevant file paths:
|
|
35
|
+
- **pattern-guardian** — duplication, re-invented helpers, divergent
|
|
36
|
+
conventions, a second way to do a thing, unjustified new dependencies.
|
|
37
|
+
- **style-enforcer** — adherence to the project style guide / lint config /
|
|
38
|
+
local conventions on the changed files.
|
|
39
|
+
- **code-reviewer** — general correctness: bugs, logic errors, security,
|
|
40
|
+
resource/concurrency issues. High bar, high signal only.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
If the `code-reviewer` agent is not installed in this project (or cannot be
|
|
43
|
+
invoked in the current environment), perform that correctness pass yourself
|
|
44
|
+
inline: read the diff in full, and for each changed file check for logic
|
|
45
|
+
errors, unsafe edge cases, security issues, and concurrency/resource leaks,
|
|
46
|
+
reporting the same `Blocking` / `Should-fix` / `Note` findings.
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
issues you then leave unaddressed.
|
|
48
|
+
3. **Consolidate.** Merge their findings. Drop duplicates and anything
|
|
49
|
+
non-actionable. Group by severity: **Blocking**, **Should-fix**, **Note**.
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
4. **Act, don't summarize.** For every Blocking and Should-fix item: fix it
|
|
52
|
+
now, or state precisely why it does not apply. Do not produce a report of
|
|
53
|
+
issues you then leave unaddressed.
|
|
54
|
+
|
|
55
|
+
5. **Confirm.** Re-run the relevant specialist if you made non-trivial fixes,
|
|
56
|
+
until no blocking items remain.
|
|
51
57
|
|
|
52
58
|
## Output
|
|
53
59
|
|
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;
|
package/dist/messenger.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
export type SendMessageFn = (sessionID: string, text: string) => Promise<void>;
|
|
3
|
-
/**
|
|
4
|
-
* Create a messenger that posts a chat message without it being treated as a
|
|
5
|
-
* user turn. OpenCode's `client.session.prompt` with `noReply: true` and an
|
|
6
|
-
* `ignored: true` text part shows the message in the conversation UI but does
|
|
7
|
-
* not feed it back to the model as input.
|
|
8
|
-
*/
|
|
9
|
-
export declare function createMessenger(client: PluginInput["client"]): SendMessageFn;
|
package/dist/messenger.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a messenger that posts a chat message without it being treated as a
|
|
3
|
-
* user turn. OpenCode's `client.session.prompt` with `noReply: true` and an
|
|
4
|
-
* `ignored: true` text part shows the message in the conversation UI but does
|
|
5
|
-
* not feed it back to the model as input.
|
|
6
|
-
*/
|
|
7
|
-
export function createMessenger(client) {
|
|
8
|
-
const typedClient = client;
|
|
9
|
-
const prompt = typedClient?.session?.prompt;
|
|
10
|
-
if (!prompt) {
|
|
11
|
-
return async () => { };
|
|
12
|
-
}
|
|
13
|
-
return async (sessionID, text) => {
|
|
14
|
-
await prompt({
|
|
15
|
-
path: { id: sessionID },
|
|
16
|
-
body: {
|
|
17
|
-
noReply: true,
|
|
18
|
-
parts: [
|
|
19
|
-
{
|
|
20
|
-
type: "text",
|
|
21
|
-
text,
|
|
22
|
-
ignored: true,
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
}
|