opencode-dev-framework 0.1.13 → 0.1.16
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 +26 -12
- package/bin/df +4 -3
- package/dist/command-utils.d.ts +12 -0
- package/dist/command-utils.js +46 -0
- package/dist/format-status.d.ts +9 -0
- package/dist/format-status.js +109 -0
- package/dist/gate.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +127 -13
- package/dist/installer.js +1 -1
- package/dist/lint.js +1 -1
- package/dist/logger.d.ts +4 -0
- package/dist/logger.js +21 -0
- package/dist/protect.d.ts +2 -1
- package/dist/protect.js +48 -1
- package/dist/registry.d.ts +10 -0
- package/dist/registry.js +22 -2
- package/dist/rules.d.ts +3 -2
- package/dist/rules.js +9 -3
- package/dist/tools.js +16 -0
- package/package.json +1 -1
- package/rules/00-activation.md +10 -16
- package/rules/40-delegation.md +6 -4
- package/dist/config-to-opencode.d.ts +0 -51
- package/dist/config-to-opencode.js +0 -124
- package/templates/.opencode/commands/df-profile.md +0 -7
- package/templates/.opencode/commands/df-verify.md +0 -8
package/README.md
CHANGED
|
@@ -24,14 +24,16 @@ reimplemented as an OpenCode-native plugin.
|
|
|
24
24
|
(up to `gate.max_blocks` times) so the agent must fix the failures. In older
|
|
25
25
|
versions the gate reports loudly via `session.idle`.
|
|
26
26
|
- **Custom tools.** `dev_framework_init` scaffolds project-level agents,
|
|
27
|
-
skills,
|
|
28
|
-
in-session without restarting
|
|
27
|
+
skills, local rules directory, and config; `dev_framework_set_profile` changes the profile
|
|
28
|
+
in-session without restarting; `dev_framework_status` reports the current
|
|
29
|
+
profile, guardrails, gate, and tracked changed files.
|
|
29
30
|
- **CLI installer.** `df init` auto-detects your language and writes a config
|
|
30
31
|
with sensible commands; `df profile <name>` changes the profile from the
|
|
31
32
|
shell; `df status` / `df version` report template state and the version.
|
|
32
|
-
- **Slash
|
|
33
|
-
|
|
34
|
-
|
|
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.
|
|
35
37
|
|
|
36
38
|
## Profiles
|
|
37
39
|
|
|
@@ -56,8 +58,8 @@ Then add it to your project's `opencode.json`:
|
|
|
56
58
|
}
|
|
57
59
|
```
|
|
58
60
|
|
|
59
|
-
Finally, scaffold the project-level files (agents, skills,
|
|
60
|
-
config) into your repo with the bundled `df` CLI:
|
|
61
|
+
Finally, scaffold the project-level files (agents, skills, local rules directory,
|
|
62
|
+
and default config) into your repo with the bundled `df` CLI:
|
|
61
63
|
|
|
62
64
|
```bash
|
|
63
65
|
npx df init # if installed locally as a project dependency
|
|
@@ -150,12 +152,18 @@ compatibility, but the native format above is preferred. See
|
|
|
150
152
|
config reference and [`examples/go-service/`](examples/go-service/) for a
|
|
151
153
|
complete example.
|
|
152
154
|
|
|
153
|
-
## Slash
|
|
155
|
+
## Slash commands
|
|
154
156
|
|
|
155
|
-
The
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
The plugin registers three slash commands directly (no template files required):
|
|
158
|
+
|
|
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.
|
|
164
|
+
|
|
165
|
+
You can still run `df init` to install the bundled agents, skills, and default
|
|
166
|
+
config; the commands themselves are provided by the plugin.
|
|
159
167
|
|
|
160
168
|
## Limitations
|
|
161
169
|
|
|
@@ -185,6 +193,12 @@ npm run test
|
|
|
185
193
|
npm run build
|
|
186
194
|
```
|
|
187
195
|
|
|
196
|
+
For persistent debug traces, set `OPENCODE_DEV_FRAMEWORK_LOG_FILE`:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
OPENCODE_DEV_FRAMEWORK_LOG_FILE=/tmp/odf.log opencode run
|
|
200
|
+
```
|
|
201
|
+
|
|
188
202
|
See `AGENTS.md` and `docs/plans/` for the architecture and implementation
|
|
189
203
|
plan.
|
|
190
204
|
|
package/bin/df
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// df — opencode-dev-framework CLI installer.
|
|
3
|
-
// Scaffold project-level agents, skills,
|
|
3
|
+
// Scaffold project-level agents, skills, local rules, and config into a repo.
|
|
4
4
|
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -56,6 +56,9 @@ async function main() {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
const flags = new Set(args.slice(1).filter((arg) => arg.startsWith("--")));
|
|
60
|
+
const positional = args.slice(1).filter((arg) => !arg.startsWith("--"));
|
|
61
|
+
|
|
59
62
|
if (command === "profile") {
|
|
60
63
|
const profile = positional[0];
|
|
61
64
|
const profileDir = resolveTargetDir(positional[1]);
|
|
@@ -79,8 +82,6 @@ async function main() {
|
|
|
79
82
|
return;
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
const flags = new Set(args.slice(1).filter((arg) => arg.startsWith("--")));
|
|
83
|
-
const positional = args.slice(1).filter((arg) => !arg.startsWith("--"));
|
|
84
85
|
const targetDir = resolveTargetDir(positional[0]);
|
|
85
86
|
|
|
86
87
|
if (command === "init" && flags.has("--skip-existing") && flags.has("--overwrite-existing")) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CommandMap } from "./types.js";
|
|
2
|
+
export interface NormalizedCommandMap {
|
|
3
|
+
default?: string;
|
|
4
|
+
byExtension: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Normalize a command map: a plain string becomes the default command; a record
|
|
8
|
+
* may contain a `default` key plus per-extension overrides.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeCommandMap(map: CommandMap | undefined): NormalizedCommandMap;
|
|
11
|
+
/** Split a command string into argv tokens, honoring simple quotes. */
|
|
12
|
+
export declare function splitCommand(command: string): string[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a command map: a plain string becomes the default command; a record
|
|
3
|
+
* may contain a `default` key plus per-extension overrides.
|
|
4
|
+
*/
|
|
5
|
+
export function normalizeCommandMap(map) {
|
|
6
|
+
if (map === undefined) {
|
|
7
|
+
return { byExtension: {} };
|
|
8
|
+
}
|
|
9
|
+
if (typeof map === "string") {
|
|
10
|
+
return { default: map, byExtension: {} };
|
|
11
|
+
}
|
|
12
|
+
const { default: defaultCommand, ...byExtension } = map;
|
|
13
|
+
return defaultCommand === undefined ? { byExtension } : { default: defaultCommand, byExtension };
|
|
14
|
+
}
|
|
15
|
+
/** Split a command string into argv tokens, honoring simple quotes. */
|
|
16
|
+
export function splitCommand(command) {
|
|
17
|
+
const tokens = [];
|
|
18
|
+
let current = "";
|
|
19
|
+
let quote;
|
|
20
|
+
for (const ch of command) {
|
|
21
|
+
if (quote !== undefined) {
|
|
22
|
+
if (ch === quote) {
|
|
23
|
+
quote = undefined;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
current += ch;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (ch === '"' || ch === "'") {
|
|
30
|
+
quote = ch;
|
|
31
|
+
}
|
|
32
|
+
else if (/\s/.test(ch)) {
|
|
33
|
+
if (current !== "") {
|
|
34
|
+
tokens.push(current);
|
|
35
|
+
current = "";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
current += ch;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (current !== "") {
|
|
43
|
+
tokens.push(current);
|
|
44
|
+
}
|
|
45
|
+
return tokens;
|
|
46
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HookState } from "./registry.js";
|
|
2
|
+
import type { ResolvedConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Render a human-readable summary of the current plugin state.
|
|
5
|
+
*
|
|
6
|
+
* Used by the `dev_framework_status` custom tool and by the `/df-status`
|
|
7
|
+
* slash-command handler.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderStatus(config: ResolvedConfig, state?: HookState | null): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
function formatCommandMap(map, indent) {
|
|
2
|
+
if (map === undefined) {
|
|
3
|
+
return `${indent}(not configured)`;
|
|
4
|
+
}
|
|
5
|
+
if (typeof map === "string") {
|
|
6
|
+
return `${indent}${map}`;
|
|
7
|
+
}
|
|
8
|
+
const entries = Object.entries(map);
|
|
9
|
+
if (entries.length === 0) {
|
|
10
|
+
return `${indent}(not configured)`;
|
|
11
|
+
}
|
|
12
|
+
return entries.map(([ext, cmd]) => `${indent}${ext}: ${cmd}`).join("\n");
|
|
13
|
+
}
|
|
14
|
+
function formatRules(rules) {
|
|
15
|
+
if (rules === undefined) {
|
|
16
|
+
return " (bundled rules)";
|
|
17
|
+
}
|
|
18
|
+
const lines = [` mode: ${rules.mode}`];
|
|
19
|
+
if (rules.files.length === 0) {
|
|
20
|
+
lines.push(" files: (none)");
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
lines.push(" files:");
|
|
24
|
+
for (const file of rules.files) {
|
|
25
|
+
lines.push(` - ${file}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return lines.join("\n");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Render a human-readable summary of the current plugin state.
|
|
32
|
+
*
|
|
33
|
+
* Used by the `dev_framework_status` custom tool and by the `/df-status`
|
|
34
|
+
* slash-command handler.
|
|
35
|
+
*/
|
|
36
|
+
export function renderStatus(config, state) {
|
|
37
|
+
const lines = [];
|
|
38
|
+
lines.push(`opencode-dev-framework status`);
|
|
39
|
+
lines.push("");
|
|
40
|
+
lines.push(`Profile: ${config.profile}`);
|
|
41
|
+
lines.push(`Config: ${config.configPath ?? "(none — defaults to off)"}`);
|
|
42
|
+
lines.push("");
|
|
43
|
+
lines.push("Guardrails:");
|
|
44
|
+
lines.push(` protect_mode: ${config.protect_mode}`);
|
|
45
|
+
lines.push(` protect_off: ${config.protect_off}`);
|
|
46
|
+
if (config.protect.length === 0) {
|
|
47
|
+
lines.push(" protected paths: (none)");
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
lines.push(" protected paths:");
|
|
51
|
+
for (const pattern of config.protect) {
|
|
52
|
+
lines.push(` - ${pattern}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
lines.push("");
|
|
56
|
+
lines.push("On edit:");
|
|
57
|
+
lines.push(` format: ${config.on_edit.format}`);
|
|
58
|
+
lines.push(` lint: ${config.on_edit.lint}`);
|
|
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
|
+
lines.push("");
|
|
64
|
+
lines.push("Completion gate:");
|
|
65
|
+
lines.push(` run_typecheck: ${config.gate.run_typecheck}`);
|
|
66
|
+
lines.push(` run_tests: ${config.gate.run_tests}`);
|
|
67
|
+
lines.push(` lint_changed: ${config.gate.lint_changed}`);
|
|
68
|
+
lines.push(` block_on_failure: ${config.gate.block_on_failure}`);
|
|
69
|
+
lines.push(` skip_unchanged: ${config.gate.skip_unchanged}`);
|
|
70
|
+
lines.push(` scope: ${config.gate.scope}`);
|
|
71
|
+
lines.push(` timeout: ${config.gate.timeout ?? "(default)"}`);
|
|
72
|
+
lines.push(` max_blocks: ${config.gate.max_blocks}`);
|
|
73
|
+
lines.push("");
|
|
74
|
+
lines.push("Commands:");
|
|
75
|
+
lines.push(" typecheck:");
|
|
76
|
+
lines.push(formatCommandMap(config.commands.typecheck, " "));
|
|
77
|
+
lines.push(" test:");
|
|
78
|
+
lines.push(formatCommandMap(config.commands.test, " "));
|
|
79
|
+
lines.push(" test_changed:");
|
|
80
|
+
lines.push(config.commands.test_changed ? ` ${config.commands.test_changed}` : " (not configured)");
|
|
81
|
+
lines.push(" lint:");
|
|
82
|
+
lines.push(formatCommandMap(config.commands.lint, " "));
|
|
83
|
+
lines.push(" format:");
|
|
84
|
+
lines.push(formatCommandMap(config.commands.format, " "));
|
|
85
|
+
lines.push("");
|
|
86
|
+
lines.push("Constitution rules:");
|
|
87
|
+
lines.push(formatRules(config.rules));
|
|
88
|
+
if (config.style_guide) {
|
|
89
|
+
lines.push(` style_guide: ${config.style_guide}`);
|
|
90
|
+
}
|
|
91
|
+
if (state) {
|
|
92
|
+
const changedFiles = state.tracker.getChangedFiles();
|
|
93
|
+
lines.push("");
|
|
94
|
+
lines.push(`Changed files tracked: ${changedFiles.length}`);
|
|
95
|
+
if (changedFiles.length > 0) {
|
|
96
|
+
for (const file of changedFiles) {
|
|
97
|
+
lines.push(` - ${file}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (state.blockCounts.size > 0) {
|
|
101
|
+
lines.push("");
|
|
102
|
+
lines.push("Completion gate blocks this session:");
|
|
103
|
+
for (const [sessionID, count] of state.blockCounts) {
|
|
104
|
+
lines.push(` ${sessionID}: ${count}/${config.gate.max_blocks}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return lines.join("\n");
|
|
109
|
+
}
|
package/dist/gate.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* then the agent's turn has already finished, so failures cannot block.
|
|
10
10
|
*/
|
|
11
11
|
import { isAbsolute, relative } from "node:path";
|
|
12
|
-
import { splitCommand } from "./
|
|
12
|
+
import { splitCommand } from "./command-utils.js";
|
|
13
13
|
import { lintFile } from "./lint.js";
|
|
14
14
|
/** Fallback per-command timeout (seconds) when `gate.timeout` is unset. */
|
|
15
15
|
export const DEFAULT_GATE_TIMEOUT_SECONDS = 300;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +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
|
-
* -
|
|
10
|
+
* - config hook -> registers /df-status, /df-verify, /df-profile slash commands
|
|
11
|
+
* - command.execute.before -> handles those slash commands directly
|
|
11
12
|
*/
|
|
12
13
|
import type { Hooks, Plugin, PluginInput } from "@opencode-ai/plugin";
|
|
13
14
|
import { type ChangedFileTracker } from "./gate.js";
|
package/dist/index.js
CHANGED
|
@@ -7,16 +7,20 @@
|
|
|
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
|
-
* -
|
|
10
|
+
* - config hook -> registers /df-status, /df-verify, /df-profile slash commands
|
|
11
|
+
* - command.execute.before -> handles those slash commands directly
|
|
11
12
|
*/
|
|
12
|
-
import {
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { clearConfigCache, loadConfig } from "./config.js";
|
|
13
15
|
import { createChangedFileTracker, runGate, summarizeGate, } from "./gate.js";
|
|
16
|
+
import { renderStatus } from "./format-status.js";
|
|
14
17
|
import { runCommand } from "./host.js";
|
|
15
18
|
import { detectPreCommitAvailability, isLintFailure, lintFile, summarizeLint } from "./lint.js";
|
|
16
19
|
import { createLogger } from "./logger.js";
|
|
17
20
|
import { checkToolCall } from "./protect.js";
|
|
18
|
-
import { clearSessionDirectory,
|
|
21
|
+
import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory, updateHookState, } from "./registry.js";
|
|
19
22
|
import { injectConstitution, loadConstitution } from "./rules.js";
|
|
23
|
+
import { setProfileInFile } from "./installer.js";
|
|
20
24
|
import { buildTools } from "./tools.js";
|
|
21
25
|
/**
|
|
22
26
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
@@ -38,8 +42,98 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
38
42
|
});
|
|
39
43
|
return {
|
|
40
44
|
tool: buildTools(ctx),
|
|
45
|
+
config: async (opencodeConfig) => {
|
|
46
|
+
const typedConfig = opencodeConfig;
|
|
47
|
+
const state = getHookState(ctx.directory);
|
|
48
|
+
if (state) {
|
|
49
|
+
state.hostPermissions = typedConfig.permission ?? [];
|
|
50
|
+
}
|
|
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
|
+
}
|
|
134
|
+
},
|
|
41
135
|
"experimental.chat.system.transform": async (input, output) => {
|
|
42
|
-
const state =
|
|
136
|
+
const state = getStateForSession(input.sessionID);
|
|
43
137
|
if (!state) {
|
|
44
138
|
return;
|
|
45
139
|
}
|
|
@@ -53,11 +147,11 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
53
147
|
}
|
|
54
148
|
},
|
|
55
149
|
"tool.execute.before": async (input, output) => {
|
|
56
|
-
const state =
|
|
150
|
+
const state = getStateForSession(input.sessionID);
|
|
57
151
|
if (!state) {
|
|
58
|
-
|
|
152
|
+
throw new Error("[opencode-dev-framework] plugin state is not available; guardrail cannot evaluate this tool call");
|
|
59
153
|
}
|
|
60
|
-
const result = checkToolCall(state.config, input.tool, output.args, state.directory);
|
|
154
|
+
const result = checkToolCall(state.config, input.tool, output.args, state.directory, state.hostPermissions);
|
|
61
155
|
if (result.decision === "allow") {
|
|
62
156
|
return;
|
|
63
157
|
}
|
|
@@ -75,7 +169,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
75
169
|
throw new Error(`[opencode-dev-framework] ${message}`);
|
|
76
170
|
},
|
|
77
171
|
"experimental.session.stopping": async (input, output) => {
|
|
78
|
-
const state =
|
|
172
|
+
const state = getStateForSession(input.sessionID);
|
|
79
173
|
if (!state?.config.gate || state.config.profile === "off") {
|
|
80
174
|
return;
|
|
81
175
|
}
|
|
@@ -111,9 +205,10 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
111
205
|
clearSessionDirectory(event.properties.info.id);
|
|
112
206
|
return;
|
|
113
207
|
}
|
|
114
|
-
const
|
|
115
|
-
?
|
|
116
|
-
: undefined
|
|
208
|
+
const sessionID = event.type === "session.idle"
|
|
209
|
+
? event.properties.sessionID
|
|
210
|
+
: undefined;
|
|
211
|
+
const state = getStateForSession(sessionID);
|
|
117
212
|
if (!state) {
|
|
118
213
|
return;
|
|
119
214
|
}
|
|
@@ -193,12 +288,31 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
193
288
|
};
|
|
194
289
|
}
|
|
195
290
|
export const devFramework = async (ctx) => {
|
|
196
|
-
const
|
|
291
|
+
const log = createLogger(ctx.client);
|
|
292
|
+
let config;
|
|
293
|
+
try {
|
|
294
|
+
config = loadConfig(ctx.directory);
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
298
|
+
await log("error", message, { directory: ctx.directory });
|
|
299
|
+
const clientTui = ctx.client.tui;
|
|
300
|
+
try {
|
|
301
|
+
await clientTui?.showToast?.({
|
|
302
|
+
type: "error",
|
|
303
|
+
message: `[opencode-dev-framework] ${message}`,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
// TUI may not be available; the log line is enough.
|
|
308
|
+
}
|
|
309
|
+
return {};
|
|
310
|
+
}
|
|
197
311
|
// The off profile registers no hooks at all.
|
|
198
312
|
if (config.profile === "off") {
|
|
199
313
|
return {};
|
|
200
314
|
}
|
|
201
|
-
|
|
315
|
+
setBaseDirectory(ctx.directory);
|
|
202
316
|
const { constitution, warning } = await loadConstitution(config, ctx.directory);
|
|
203
317
|
if (warning) {
|
|
204
318
|
await log("warn", warning);
|
package/dist/installer.js
CHANGED
|
@@ -2,6 +2,7 @@ import { promises as fs } from "node:fs";
|
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { createInterface } from "node:readline";
|
|
5
|
+
import { DEFAULT_PROTECT } from "./config.js";
|
|
5
6
|
import { detectProject } from "./detect.js";
|
|
6
7
|
/** Directory containing the project templates shipped with the package. */
|
|
7
8
|
export const TEMPLATES_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "templates");
|
|
@@ -150,7 +151,6 @@ export async function statusTemplates(targetDir) {
|
|
|
150
151
|
}
|
|
151
152
|
return status;
|
|
152
153
|
}
|
|
153
|
-
const DEFAULT_PROTECT = [".env*", "**/.env*", "**/node_modules/**", "**/vendor/**"];
|
|
154
154
|
function buildDefaultConfigYaml(language, commands, hasPreCommitConfig) {
|
|
155
155
|
const lines = ["# opencode-dev-framework configuration"];
|
|
156
156
|
lines.push("# Edit the commands to match your project's toolchain.");
|
package/dist/lint.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { basename, extname, isAbsolute, relative } from "node:path";
|
|
7
7
|
import picomatch from "picomatch";
|
|
8
|
-
import { normalizeCommandMap, splitCommand } from "./
|
|
8
|
+
import { normalizeCommandMap, splitCommand } from "./command-utils.js";
|
|
9
9
|
/** Fallback per-lint timeout (seconds) when the config sets none. */
|
|
10
10
|
export const DEFAULT_LINT_TIMEOUT_SECONDS = 60;
|
|
11
11
|
/**
|
package/dist/logger.d.ts
CHANGED
|
@@ -10,5 +10,9 @@ export type LogFn = (level: LogLevel, message: string, extra?: Record<string, un
|
|
|
10
10
|
* `app.log` failures fall back to stderr so the failure stays visible
|
|
11
11
|
* (a total swallow made production debugging painful during development),
|
|
12
12
|
* and even stderr failures are ignored as a last resort.
|
|
13
|
+
*
|
|
14
|
+
* If the `OPENCODE_DEV_FRAMEWORK_LOG_FILE` environment variable is set, every
|
|
15
|
+
* log line is also appended to that path as JSON, which is useful when
|
|
16
|
+
* `app.log` is unavailable or when a persistent trace is needed.
|
|
13
17
|
*/
|
|
14
18
|
export declare function createLogger(client: PluginInput["client"]): LogFn;
|
package/dist/logger.js
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Structured logging wrapper around the OpenCode client's app.log API.
|
|
3
3
|
*/
|
|
4
|
+
import { appendFile } from "node:fs/promises";
|
|
4
5
|
export const LOG_SERVICE = "opencode-dev-framework";
|
|
5
6
|
/**
|
|
6
7
|
* Create a logger bound to the OpenCode client. Logging never throws:
|
|
7
8
|
* `app.log` failures fall back to stderr so the failure stays visible
|
|
8
9
|
* (a total swallow made production debugging painful during development),
|
|
9
10
|
* and even stderr failures are ignored as a last resort.
|
|
11
|
+
*
|
|
12
|
+
* If the `OPENCODE_DEV_FRAMEWORK_LOG_FILE` environment variable is set, every
|
|
13
|
+
* log line is also appended to that path as JSON, which is useful when
|
|
14
|
+
* `app.log` is unavailable or when a persistent trace is needed.
|
|
10
15
|
*/
|
|
11
16
|
export function createLogger(client) {
|
|
17
|
+
const filePath = process.env.OPENCODE_DEV_FRAMEWORK_LOG_FILE;
|
|
12
18
|
return async (level, message, extra) => {
|
|
19
|
+
const line = JSON.stringify({
|
|
20
|
+
timestamp: new Date().toISOString(),
|
|
21
|
+
service: LOG_SERVICE,
|
|
22
|
+
level,
|
|
23
|
+
message,
|
|
24
|
+
extra,
|
|
25
|
+
});
|
|
13
26
|
try {
|
|
14
27
|
await client.app.log({ body: { service: LOG_SERVICE, level, message, extra } });
|
|
15
28
|
}
|
|
@@ -21,5 +34,13 @@ export function createLogger(client) {
|
|
|
21
34
|
// Even stderr may be unavailable; truly ignore.
|
|
22
35
|
}
|
|
23
36
|
}
|
|
37
|
+
if (filePath) {
|
|
38
|
+
try {
|
|
39
|
+
await appendFile(filePath, `${line}\n`);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// File logging is best-effort.
|
|
43
|
+
}
|
|
44
|
+
}
|
|
24
45
|
};
|
|
25
46
|
}
|
package/dist/protect.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* shell commands. Pure functions — the OpenCode hook wiring lives in
|
|
4
4
|
* src/index.ts.
|
|
5
5
|
*/
|
|
6
|
+
import type { HostPermission } from "./registry.js";
|
|
6
7
|
import type { ResolvedConfig } from "./types.js";
|
|
7
8
|
export type GuardDecision = "allow" | "warn" | "deny";
|
|
8
9
|
export interface GuardResult {
|
|
@@ -40,4 +41,4 @@ export declare function matchDangerousCommand(command: string): DangerousCommand
|
|
|
40
41
|
* `protect_off: true`), when the tool is not guarded, or when nothing
|
|
41
42
|
* matched. Otherwise returns `deny` or `warn` per `protect_mode`.
|
|
42
43
|
*/
|
|
43
|
-
export declare function checkToolCall(config: ResolvedConfig, tool: string, args: unknown, directory?: string): GuardResult;
|
|
44
|
+
export declare function checkToolCall(config: ResolvedConfig, tool: string, args: unknown, directory?: string, hostPermissions?: HostPermission[]): GuardResult;
|
package/dist/protect.js
CHANGED
|
@@ -79,6 +79,45 @@ 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
|
+
function permissionMatchesTool(permission, tool) {
|
|
83
|
+
if (permission === "*" || permission === tool) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (permission === "edit" && FILE_TOOLS.has(tool)) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (permission === "bash" && SHELL_TOOLS.has(tool)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
/** Check whether the host OpenCode config already denies this tool/target. */
|
|
95
|
+
function hostDenies(tool, target, directory, hostPermissions) {
|
|
96
|
+
if (!hostPermissions || hostPermissions.length === 0) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
for (const perm of hostPermissions) {
|
|
100
|
+
if (perm.action !== "deny") {
|
|
101
|
+
continue;
|
|
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;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
82
121
|
function enforce(config, reason, matchedPattern) {
|
|
83
122
|
if (config.protect_mode === "deny") {
|
|
84
123
|
return { decision: "deny", reason, matchedPattern };
|
|
@@ -92,7 +131,7 @@ function enforce(config, reason, matchedPattern) {
|
|
|
92
131
|
* `protect_off: true`), when the tool is not guarded, or when nothing
|
|
93
132
|
* matched. Otherwise returns `deny` or `warn` per `protect_mode`.
|
|
94
133
|
*/
|
|
95
|
-
export function checkToolCall(config, tool, args, directory) {
|
|
134
|
+
export function checkToolCall(config, tool, args, directory, hostPermissions) {
|
|
96
135
|
if (config.profile === "off" || config.protect_off) {
|
|
97
136
|
return { decision: "allow" };
|
|
98
137
|
}
|
|
@@ -101,6 +140,11 @@ export function checkToolCall(config, tool, args, directory) {
|
|
|
101
140
|
if (filePath === undefined) {
|
|
102
141
|
return { decision: "allow" };
|
|
103
142
|
}
|
|
143
|
+
// If the host permission model already denies this path, do not duplicate
|
|
144
|
+
// the block here.
|
|
145
|
+
if (hostDenies(tool, filePath, directory, hostPermissions)) {
|
|
146
|
+
return { decision: "allow" };
|
|
147
|
+
}
|
|
104
148
|
const pattern = matchProtectedPath(config, filePath, directory);
|
|
105
149
|
if (pattern !== undefined) {
|
|
106
150
|
return enforce(config, `${tool} on protected path "${filePath}" is blocked (matched "${pattern}")`, pattern);
|
|
@@ -112,6 +156,9 @@ export function checkToolCall(config, tool, args, directory) {
|
|
|
112
156
|
if (command === undefined) {
|
|
113
157
|
return { decision: "allow" };
|
|
114
158
|
}
|
|
159
|
+
if (hostDenies(tool, command, directory, hostPermissions)) {
|
|
160
|
+
return { decision: "allow" };
|
|
161
|
+
}
|
|
115
162
|
const dangerous = matchDangerousCommand(command);
|
|
116
163
|
if (dangerous !== undefined) {
|
|
117
164
|
return enforce(config, `bash command blocked: ${dangerous.reason}`, dangerous.pattern.source);
|
package/dist/registry.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { ChangedFileTracker } from "./gate.js";
|
|
|
2
2
|
import type { RunCommand } from "./host.js";
|
|
3
3
|
import type { LogFn } from "./logger.js";
|
|
4
4
|
import type { ResolvedConfig } from "./types.js";
|
|
5
|
+
export interface HostPermission {
|
|
6
|
+
permission?: string;
|
|
7
|
+
pattern?: string;
|
|
8
|
+
action?: "allow" | "deny" | "ask";
|
|
9
|
+
}
|
|
5
10
|
export interface HookState {
|
|
6
11
|
/** Project directory this state belongs to. Stored here (rather than
|
|
7
12
|
* closure-captured by hooks) so every hook invocation is self-contained. */
|
|
@@ -15,9 +20,14 @@ export interface HookState {
|
|
|
15
20
|
blockCounts: Map<string, number>;
|
|
16
21
|
/** Cached result of checking whether `pre-commit` is available. */
|
|
17
22
|
precommitAvailable?: boolean;
|
|
23
|
+
/** Snapshot of host permissions from OpenCode's effective config. */
|
|
24
|
+
hostPermissions?: HostPermission[];
|
|
18
25
|
}
|
|
26
|
+
export declare function setBaseDirectory(directory: string): void;
|
|
27
|
+
export declare function getBaseDirectory(): string | null;
|
|
19
28
|
export declare function setHookState(directory: string, state: HookState): void;
|
|
20
29
|
export declare function getHookState(directoryHint?: string): HookState | null;
|
|
30
|
+
export declare function getStateForSession(sessionID: string | undefined): HookState | null;
|
|
21
31
|
export declare function updateHookState(directory: string, updates: Partial<HookState>): HookState | null;
|
|
22
32
|
export declare function setSessionDirectory(sessionID: string, directory: string): void;
|
|
23
33
|
export declare function getDirectoryForSession(sessionID: string): string | null;
|
package/dist/registry.js
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-directory hook state registry. OpenCode's effect runtime can strip
|
|
3
3
|
* closure variables when invoking hooks asynchronously, so we store the state
|
|
4
|
-
* in module-level maps and look
|
|
4
|
+
* in module-level maps and look up values at call time.
|
|
5
|
+
*
|
|
6
|
+
* `baseDirectory` is the project root set at plugin initialization. Hooks that
|
|
7
|
+
* receive only a session ID can fall back to this directory when the session
|
|
8
|
+
* has not been mapped yet.
|
|
5
9
|
*/
|
|
6
10
|
const hookRegistry = new Map();
|
|
7
11
|
let activeDirectory = null;
|
|
12
|
+
let baseDirectory = null;
|
|
13
|
+
export function setBaseDirectory(directory) {
|
|
14
|
+
baseDirectory = directory;
|
|
15
|
+
}
|
|
16
|
+
export function getBaseDirectory() {
|
|
17
|
+
return baseDirectory;
|
|
18
|
+
}
|
|
8
19
|
export function setHookState(directory, state) {
|
|
9
20
|
hookRegistry.set(directory, state);
|
|
10
21
|
activeDirectory = directory;
|
|
11
22
|
}
|
|
12
23
|
export function getHookState(directoryHint) {
|
|
13
|
-
const directory = directoryHint ?? activeDirectory;
|
|
24
|
+
const directory = directoryHint ?? activeDirectory ?? baseDirectory;
|
|
14
25
|
if (!directory) {
|
|
15
26
|
return null;
|
|
16
27
|
}
|
|
17
28
|
return hookRegistry.get(directory) ?? null;
|
|
18
29
|
}
|
|
30
|
+
export function getStateForSession(sessionID) {
|
|
31
|
+
if (sessionID) {
|
|
32
|
+
const mapped = getDirectoryForSession(sessionID);
|
|
33
|
+
if (mapped) {
|
|
34
|
+
return getHookState(mapped);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return getHookState(baseDirectory ?? undefined);
|
|
38
|
+
}
|
|
19
39
|
export function updateHookState(directory, updates) {
|
|
20
40
|
const state = hookRegistry.get(directory);
|
|
21
41
|
if (!state) {
|
package/dist/rules.d.ts
CHANGED
|
@@ -38,7 +38,8 @@ export interface ConstitutionResult {
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function loadConstitution(config: ResolvedConfig, directory?: string): Promise<ConstitutionResult>;
|
|
40
40
|
/**
|
|
41
|
-
* Appends the constitution to
|
|
42
|
-
* present
|
|
41
|
+
* Appends the constitution to the last system-prompt entry, unless it is already
|
|
42
|
+
* present. This keeps the system prompt compact instead of adding a separate
|
|
43
|
+
* array element each time the transform runs.
|
|
43
44
|
*/
|
|
44
45
|
export declare function injectConstitution(system: string[], constitution: string | null): string[];
|
package/dist/rules.js
CHANGED
|
@@ -170,8 +170,9 @@ export async function loadConstitution(config, directory) {
|
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
|
-
* Appends the constitution to
|
|
174
|
-
* present
|
|
173
|
+
* Appends the constitution to the last system-prompt entry, unless it is already
|
|
174
|
+
* present. This keeps the system prompt compact instead of adding a separate
|
|
175
|
+
* array element each time the transform runs.
|
|
175
176
|
*/
|
|
176
177
|
export function injectConstitution(system, constitution) {
|
|
177
178
|
if (constitution === null) {
|
|
@@ -180,5 +181,10 @@ export function injectConstitution(system, constitution) {
|
|
|
180
181
|
if (system.some((entry) => entry.includes(constitution))) {
|
|
181
182
|
return system;
|
|
182
183
|
}
|
|
183
|
-
|
|
184
|
+
if (system.length === 0) {
|
|
185
|
+
return [constitution];
|
|
186
|
+
}
|
|
187
|
+
const next = [...system];
|
|
188
|
+
next[next.length - 1] = `${next[next.length - 1]}\n\n${constitution}`;
|
|
189
|
+
return next;
|
|
184
190
|
}
|
package/dist/tools.js
CHANGED
|
@@ -4,6 +4,7 @@ import { loadConfig, clearConfigCache } from "./config.js";
|
|
|
4
4
|
import { installTemplates, setProfileInFile, writeDetectedConfig } from "./installer.js";
|
|
5
5
|
import { getHookState, updateHookState } from "./registry.js";
|
|
6
6
|
import { loadConstitution } from "./rules.js";
|
|
7
|
+
import { renderStatus } from "./format-status.js";
|
|
7
8
|
const PROFILES = ["off", "advisory", "standard", "strict"];
|
|
8
9
|
function isProfile(value) {
|
|
9
10
|
return PROFILES.includes(value);
|
|
@@ -76,5 +77,20 @@ export function buildTools(_ctx) {
|
|
|
76
77
|
return `opencode-dev-framework profile set to "${profile}" in ${configPath}. Change applied immediately.`;
|
|
77
78
|
},
|
|
78
79
|
}),
|
|
80
|
+
dev_framework_status: tool({
|
|
81
|
+
description: "Show the current opencode-dev-framework state for the project: active profile, guardrails, completion gate, on-edit behavior, tracked changed files, and block counts.",
|
|
82
|
+
args: {
|
|
83
|
+
directory: tool.schema
|
|
84
|
+
.string()
|
|
85
|
+
.optional()
|
|
86
|
+
.describe("Project directory (defaults to current project)"),
|
|
87
|
+
},
|
|
88
|
+
async execute(args, context) {
|
|
89
|
+
const targetDir = args.directory ?? context.directory;
|
|
90
|
+
const state = getHookState(targetDir);
|
|
91
|
+
const config = state?.config ?? loadConfig(targetDir);
|
|
92
|
+
return renderStatus(config, state);
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
79
95
|
};
|
|
80
96
|
}
|
package/package.json
CHANGED
package/rules/00-activation.md
CHANGED
|
@@ -7,30 +7,24 @@ completion.
|
|
|
7
7
|
|
|
8
8
|
## When these rules apply
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
These rules are injected into your system prompt because the plugin is loaded in this
|
|
11
|
+
project and the current profile is **not** `off`.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
- A file named `.opencode-dev-framework.yml` exists at the root of the working repository.
|
|
14
|
-
|
|
15
|
-
When the framework is active, the plugin injects a `DEV-FRAMEWORK: ACTIVE` banner at
|
|
16
|
-
the start of the session stating the **profile** in effect — `advisory`, `standard`, or
|
|
17
|
-
`strict`:
|
|
13
|
+
The active profile is one of `advisory`, `standard`, or `strict`:
|
|
18
14
|
|
|
19
15
|
- **advisory** — you receive formatting, lint, and review feedback, but nothing blocks.
|
|
20
16
|
Treat it as strong guidance.
|
|
21
17
|
- **standard** — feedback as above, plus a completion gate that runs type-check and
|
|
22
|
-
tests and
|
|
18
|
+
tests and reports failures; protected paths cannot be edited by default.
|
|
23
19
|
- **strict** — as standard, plus lint of changed files must also pass at the gate.
|
|
24
20
|
|
|
25
21
|
Apply the rules with intensity matching the profile, but the disciplines themselves
|
|
26
22
|
(quality bar, matching patterns, grounding in tests) always hold when active.
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
and use the specialist agents and skills described in `40-delegation` as your default
|
|
30
|
-
working loop.
|
|
31
|
-
- **If the session is NOT active** (no banner, no env var, no config file), treat these
|
|
32
|
-
rules as dormant. Do not change your behavior and do not mention the framework.
|
|
33
|
-
Proceed exactly as you normally would.
|
|
24
|
+
## Your obligations while active
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
- Follow every rule in this set as a hard requirement.
|
|
27
|
+
- Use the specialist agents and skills described in `40-delegation` as your default
|
|
28
|
+
working loop whenever they are available in the project.
|
|
29
|
+
- Never disable, bypass, or talk the user out of an active framework gate. If a hook
|
|
30
|
+
blocks completion, fix the underlying problem rather than working around the gate.
|
package/rules/40-delegation.md
CHANGED
|
@@ -6,8 +6,9 @@ rubber-stamp. Catching issues early is cheaper than catching them at the gate.
|
|
|
6
6
|
|
|
7
7
|
## The specialists
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
When the project has the specialist agents installed (under `.opencode/agents/`),
|
|
10
|
+
use them as focused reviewers. Treat them as investigation-only: give them a diff or
|
|
11
|
+
a description and ask them to report findings; do not ask them to edit product code.
|
|
11
12
|
|
|
12
13
|
- **`pattern-guardian`** — checks new/changed code against existing codebase patterns:
|
|
13
14
|
duplication, re-invented helpers, divergent conventions, "second way to do a thing",
|
|
@@ -20,7 +21,7 @@ they do **not** edit code):
|
|
|
20
21
|
test that fails without the change? do the cited commands actually pass? did you
|
|
21
22
|
verify the edge cases? Use it before declaring a task done.
|
|
22
23
|
|
|
23
|
-
You may also
|
|
24
|
+
You may also ask the built-in review or planning agents for a general high-signal
|
|
24
25
|
second opinion — the best moment is after planning, before implementing, and again
|
|
25
26
|
before completion.
|
|
26
27
|
|
|
@@ -35,7 +36,8 @@ before completion.
|
|
|
35
36
|
|
|
36
37
|
Keep delegation proportional: a one-line fix doesn't need the full loop; a new module
|
|
37
38
|
does. Use judgment, but never skip the test-grounding and review steps for behavioral
|
|
38
|
-
changes.
|
|
39
|
+
changes. If the specialist agents are not installed in this project, perform the same
|
|
40
|
+
checks yourself with the skills in this section.
|
|
39
41
|
|
|
40
42
|
## Skills
|
|
41
43
|
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Translate resolved framework config into OpenCode-native config fragments.
|
|
3
|
-
*
|
|
4
|
-
* The plugin never rewrites `opencode.json` on disk; these fragments are
|
|
5
|
-
* returned as plain objects so callers (or tests) can inspect or apply them.
|
|
6
|
-
* See docs/plans/02-architecture.md ("Tool guardrails") and the OpenCode
|
|
7
|
-
* permissions/formatters docs.
|
|
8
|
-
*/
|
|
9
|
-
import type { CommandMap, ResolvedConfig } from "./types.js";
|
|
10
|
-
export type PermissionAction = "allow" | "ask" | "deny";
|
|
11
|
-
export interface PermissionConfig {
|
|
12
|
-
edit?: Record<string, PermissionAction>;
|
|
13
|
-
bash?: Record<string, PermissionAction>;
|
|
14
|
-
}
|
|
15
|
-
export interface FormatterEntry {
|
|
16
|
-
command: string[];
|
|
17
|
-
extensions?: string[];
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export type FormatterConfig = Record<string, FormatterEntry>;
|
|
21
|
-
export interface OpenCodeFragments {
|
|
22
|
-
permission?: PermissionConfig;
|
|
23
|
-
formatter?: FormatterConfig;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Generate an OpenCode `permission` fragment from protected paths.
|
|
27
|
-
*
|
|
28
|
-
* Deny rules are only emitted when protection is active and
|
|
29
|
-
* `protect_mode` is `deny`. In `warn` mode the plugin hook logs a warning
|
|
30
|
-
* instead, since the native permission model has no "warn" action.
|
|
31
|
-
*/
|
|
32
|
-
export declare function generatePermission(config: ResolvedConfig): PermissionConfig;
|
|
33
|
-
interface NormalizedCommandMap {
|
|
34
|
-
default?: string;
|
|
35
|
-
byExtension: Record<string, string>;
|
|
36
|
-
}
|
|
37
|
-
export declare function normalizeCommandMap(map: CommandMap | undefined): NormalizedCommandMap;
|
|
38
|
-
/** Split a command string into argv tokens, honoring simple quotes. */
|
|
39
|
-
export declare function splitCommand(command: string): string[];
|
|
40
|
-
/**
|
|
41
|
-
* Generate an OpenCode `formatter` fragment from `commands.format`.
|
|
42
|
-
* Per-extension overrides become named formatter entries scoped to that
|
|
43
|
-
* extension; a plain string becomes a formatter applying to all files.
|
|
44
|
-
*/
|
|
45
|
-
export declare function generateFormatter(config: ResolvedConfig): FormatterConfig;
|
|
46
|
-
/**
|
|
47
|
-
* Build all OpenCode-native fragments for a resolved config. Empty
|
|
48
|
-
* fragments are omitted from the result.
|
|
49
|
-
*/
|
|
50
|
-
export declare function toOpenCodeFragments(config: ResolvedConfig): OpenCodeFragments;
|
|
51
|
-
export {};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Translate resolved framework config into OpenCode-native config fragments.
|
|
3
|
-
*
|
|
4
|
-
* The plugin never rewrites `opencode.json` on disk; these fragments are
|
|
5
|
-
* returned as plain objects so callers (or tests) can inspect or apply them.
|
|
6
|
-
* See docs/plans/02-architecture.md ("Tool guardrails") and the OpenCode
|
|
7
|
-
* permissions/formatters docs.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Generate an OpenCode `permission` fragment from protected paths.
|
|
11
|
-
*
|
|
12
|
-
* Deny rules are only emitted when protection is active and
|
|
13
|
-
* `protect_mode` is `deny`. In `warn` mode the plugin hook logs a warning
|
|
14
|
-
* instead, since the native permission model has no "warn" action.
|
|
15
|
-
*/
|
|
16
|
-
export function generatePermission(config) {
|
|
17
|
-
if (config.profile === "off" ||
|
|
18
|
-
config.protect_off ||
|
|
19
|
-
config.protect_mode !== "deny" ||
|
|
20
|
-
config.protect.length === 0) {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
const edit = { "*": "allow" };
|
|
24
|
-
for (const glob of config.protect) {
|
|
25
|
-
edit[glob] = "deny";
|
|
26
|
-
}
|
|
27
|
-
return { edit };
|
|
28
|
-
}
|
|
29
|
-
export function normalizeCommandMap(map) {
|
|
30
|
-
if (map === undefined) {
|
|
31
|
-
return { byExtension: {} };
|
|
32
|
-
}
|
|
33
|
-
if (typeof map === "string") {
|
|
34
|
-
return { default: map, byExtension: {} };
|
|
35
|
-
}
|
|
36
|
-
// A `default` key inside the map acts as the fallback command; every other
|
|
37
|
-
// key is a per-extension override.
|
|
38
|
-
const { default: defaultCommand, ...byExtension } = map;
|
|
39
|
-
return defaultCommand === undefined ? { byExtension } : { default: defaultCommand, byExtension };
|
|
40
|
-
}
|
|
41
|
-
/** Split a command string into argv tokens, honoring simple quotes. */
|
|
42
|
-
export function splitCommand(command) {
|
|
43
|
-
const tokens = [];
|
|
44
|
-
let current = "";
|
|
45
|
-
let quote;
|
|
46
|
-
for (const ch of command) {
|
|
47
|
-
if (quote !== undefined) {
|
|
48
|
-
if (ch === quote) {
|
|
49
|
-
quote = undefined;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
current += ch;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (ch === '"' || ch === "'") {
|
|
56
|
-
quote = ch;
|
|
57
|
-
}
|
|
58
|
-
else if (/\s/.test(ch)) {
|
|
59
|
-
if (current !== "") {
|
|
60
|
-
tokens.push(current);
|
|
61
|
-
current = "";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
current += ch;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (current !== "") {
|
|
69
|
-
tokens.push(current);
|
|
70
|
-
}
|
|
71
|
-
return tokens;
|
|
72
|
-
}
|
|
73
|
-
/** Substitute the `{file}` token with OpenCode's `$FILE` placeholder. */
|
|
74
|
-
function substituteFileToken(tokens) {
|
|
75
|
-
return tokens.map((token) => token.replaceAll("{file}", "$FILE"));
|
|
76
|
-
}
|
|
77
|
-
function formatterName(kind, ext) {
|
|
78
|
-
if (ext === undefined) {
|
|
79
|
-
return `dev-framework-${kind}`;
|
|
80
|
-
}
|
|
81
|
-
const suffix = ext.replace(/[^a-zA-Z0-9]/g, "-").replace(/^-+|-+$/g, "");
|
|
82
|
-
return `dev-framework-${kind}-${suffix}`;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Generate an OpenCode `formatter` fragment from `commands.format`.
|
|
86
|
-
* Per-extension overrides become named formatter entries scoped to that
|
|
87
|
-
* extension; a plain string becomes a formatter applying to all files.
|
|
88
|
-
*/
|
|
89
|
-
export function generateFormatter(config) {
|
|
90
|
-
const { default: defaultCommand, byExtension } = normalizeCommandMap(config.commands.format);
|
|
91
|
-
const formatter = {};
|
|
92
|
-
for (const [ext, command] of Object.entries(byExtension)) {
|
|
93
|
-
formatter[formatterName("format", ext)] = {
|
|
94
|
-
command: substituteFileToken(splitCommand(command)),
|
|
95
|
-
extensions: [ext],
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
if (defaultCommand !== undefined) {
|
|
99
|
-
formatter[formatterName("format")] = {
|
|
100
|
-
command: substituteFileToken(splitCommand(defaultCommand)),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return formatter;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Build all OpenCode-native fragments for a resolved config. Empty
|
|
107
|
-
* fragments are omitted from the result.
|
|
108
|
-
*/
|
|
109
|
-
export function toOpenCodeFragments(config) {
|
|
110
|
-
// The off profile disables the plugin entirely: no native fragments.
|
|
111
|
-
if (config.profile === "off") {
|
|
112
|
-
return {};
|
|
113
|
-
}
|
|
114
|
-
const fragments = {};
|
|
115
|
-
const permission = generatePermission(config);
|
|
116
|
-
if (Object.keys(permission).length > 0) {
|
|
117
|
-
fragments.permission = permission;
|
|
118
|
-
}
|
|
119
|
-
const formatter = generateFormatter(config);
|
|
120
|
-
if (Object.keys(formatter).length > 0) {
|
|
121
|
-
fragments.formatter = formatter;
|
|
122
|
-
}
|
|
123
|
-
return fragments;
|
|
124
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Change the dev-framework profile for this session
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Change the dev-framework profile to $ARGUMENTS (one of: off, advisory,
|
|
6
|
-
standard, strict). Use the `dev_framework_set_profile` tool to apply the change
|
|
7
|
-
immediately, or edit `.opencode-dev-framework.yml` and restart OpenCode.
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Run the dev-framework completion gate manually
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Run the dev-framework completion gate for this project. Execute the
|
|
6
|
-
`typecheck`, `test`, and `lint` commands defined in
|
|
7
|
-
`.opencode-dev-framework.yml`, report the results, and suggest fixes for any
|
|
8
|
-
failures.
|