opencode-dev-framework 0.1.25 → 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/dist/index.js CHANGED
@@ -80,7 +80,14 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
80
80
  const typedConfig = opencodeConfig;
81
81
  const state = getHookState(ctx.directory);
82
82
  if (state) {
83
- state.hostPermissions = typedConfig.permission ?? [];
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;
84
91
  }
85
92
  // `df-profile`, `df-verify`, `df-status`, and `df-help` are all registered
86
93
  // as TUI commands (keymap layer with `slashName`) in `tui.tsx`. TUI
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 { HostPermission } from "./registry.js";
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?: HostPermission[]): GuardResult;
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
- 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) {
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
- 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;
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 false;
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 path, do not duplicate
134
+ // If the host permission model already denies this tool, do not duplicate
144
135
  // the block here.
145
- if (hostDenies(tool, filePath, directory, hostPermissions)) {
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, command, directory, hostPermissions)) {
150
+ if (hostDenies(tool, hostPermissions)) {
160
151
  return { decision: "allow" };
161
152
  }
162
153
  const dangerous = matchDangerousCommand(command);
@@ -2,11 +2,16 @@ 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
+ /**
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>;
10
15
  export interface HookState {
11
16
  /** Project directory this state belongs to. Stored here (rather than
12
17
  * closure-captured by hooks) so every hook invocation is self-contained. */
@@ -21,7 +26,7 @@ export interface HookState {
21
26
  /** Cached result of checking whether `pre-commit` is available. */
22
27
  precommitAvailable?: boolean;
23
28
  /** Snapshot of host permissions from OpenCode's effective config. */
24
- hostPermissions?: HostPermission[];
29
+ hostPermissions?: OpenCodePermission;
25
30
  /** Show a non-chat TUI toast (used for slash-command results). */
26
31
  showToast?: (message: string, variant?: "info" | "success" | "warning" | "error") => void;
27
32
  /** mtime (ms) of the config file at last load; used to detect out-of-process
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "0.1.25",
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",
@@ -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 **`match-patterns`**. They codify the
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 built-in code-review agents, then consolidates only the
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
- ```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
- ```
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
- If there is nothing to review, say so and stop.
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
- 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-review** (built-in) — bugs, logic errors, security,
40
- resource/concurrency issues. High bar, high signal only.
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
- 3. **Consolidate.** Merge their findings. Drop duplicates and anything
43
- non-actionable. Group by severity: **Blocking**, **Should-fix**, **Note**.
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
- 4. **Act, don't summarize.** For every Blocking and Should-fix item: fix it
46
- now, or state precisely why it does not apply. Do not produce a report of
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
- 5. **Confirm.** Re-run the relevant specialist if you made non-trivial fixes,
50
- until no blocking items remain.
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