@a2f0/agent-tool 0.1.68 → 0.1.69
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/package.json +1 -1
- package/src/config.ts +3 -2
- package/src/doctor.ts +2 -1
- package/src/review/solicitOpencodeReview.ts +64 -27
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -135,8 +135,9 @@ export function parseConfig(source: string): AgentToolConfig {
|
|
|
135
135
|
}
|
|
136
136
|
const variants = object(result.review.opencodeVariants, "review.opencodeVariants");
|
|
137
137
|
keys(variants, ["low", "medium", "high", "xhigh", "max"], "review.opencodeVariants");
|
|
138
|
-
|
|
139
|
-
if (typeof
|
|
138
|
+
// OpenCode 2 takes the model as provider/model#variant, so neither part may contain '#'.
|
|
139
|
+
for (const value of Object.values(variants)) if (typeof value !== "string" || !/^[^\s#]+$/.test(value)) invalid("review.opencodeVariants");
|
|
140
|
+
if (typeof result.review.opencodeModel !== "string" || !/^[^\s/#]+\/[^\s#]+$/.test(result.review.opencodeModel)) invalid("review.opencodeModel");
|
|
140
141
|
if (!Number.isSafeInteger(result.review.timeoutMs) || result.review.timeoutMs < 1000 || result.review.timeoutMs > 3_600_000) invalid("review.timeoutMs");
|
|
141
142
|
const packageDirs = (dirs: unknown): boolean => strings(dirs) && !dirs.some(dir => dir !== "." && (path.isAbsolute(dir) || dir.includes("\\") || dir.split("/").some(part => !part || part === "." || part === "..")));
|
|
142
143
|
if (result.versions.packages !== null && !packageDirs(result.versions.packages)) invalid("versions.packages");
|
package/src/doctor.ts
CHANGED
|
@@ -6,7 +6,8 @@ const specifications = [
|
|
|
6
6
|
{ name: "gh", help: ["pr", "checks", "--help"], flags: ["--json"] },
|
|
7
7
|
{ name: "claude", help: ["--help"], flags: ["--safe-mode", "--permission-mode", "--effort"] },
|
|
8
8
|
{ name: "codex", help: ["exec", "--help"], flags: ["--ignore-user-config", "--ignore-rules", "--strict-config", "--ephemeral", "--output-last-message"] },
|
|
9
|
-
|
|
9
|
+
// OpenCode 2: the variant rides in --model as provider/model#variant, and --standalone runs a private server.
|
|
10
|
+
{ name: "opencode", help: ["run", "--help"], flags: ["--standalone", "--agent", "--archived", "provider/model#variant"] },
|
|
10
11
|
];
|
|
11
12
|
|
|
12
13
|
/** Probe only local versions and flags; never launch a model or print credentials. */
|
|
@@ -37,7 +37,7 @@ const OPENCODE_MODEL = DEFAULT_CONFIG.review.opencodeModel;
|
|
|
37
37
|
const OPENCODE_REVIEW_AGENT = "agent-tool-review";
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* Map the shared effort vocabulary to a
|
|
40
|
+
* Map the shared effort vocabulary to a variant deepseek-v4-pro accepts.
|
|
41
41
|
* The skill's levels are `low | medium | high | xhigh | max`; this model's
|
|
42
42
|
* variants are `low | medium | high | max`, so `xhigh` collapses onto `max`.
|
|
43
43
|
*/
|
|
@@ -67,6 +67,12 @@ export function resolveOpencodeVariant(
|
|
|
67
67
|
* resolves it, because on macOS the temp dir is a symlink (`/var` →
|
|
68
68
|
* `/private/var`) and the model may pass either spelling; a denied spelling
|
|
69
69
|
* only costs the model a retry, but both spellings allowed costs nothing.
|
|
70
|
+
*
|
|
71
|
+
* OpenCode 2 normalizes this `permission` map into its ordered `permissions`
|
|
72
|
+
* rules, renaming `bash` to `shell` and `task` to `subagent` and keeping the
|
|
73
|
+
* order, so the default deny still precedes the allows; tools it added since,
|
|
74
|
+
* such as `browser`, fall under the default deny. `opencode debug agents
|
|
75
|
+
* --standalone` with the review's environment shows the effective rules.
|
|
70
76
|
*/
|
|
71
77
|
export function buildOpencodeInlineConfig(snapshotRoot: string, model = OPENCODE_MODEL): string {
|
|
72
78
|
const normalized = path.resolve(snapshotRoot).replaceAll("\\", "/");
|
|
@@ -105,27 +111,61 @@ export function buildOpencodeInlineConfig(snapshotRoot: string, model = OPENCODE
|
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
/**
|
|
108
|
-
* Build the `opencode run` argv for a non-interactive review. The
|
|
109
|
-
* over stdin (opencode reads stdin when no message positional is
|
|
110
|
-
* large diff never hits argv limits
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* `--
|
|
114
|
-
*
|
|
114
|
+
* Build the OpenCode 2 `opencode run` argv for a non-interactive review. The
|
|
115
|
+
* prompt goes over stdin (opencode reads stdin when no message positional is
|
|
116
|
+
* given), so a large diff never hits argv limits, and the variant rides in the
|
|
117
|
+
* model as `provider/model#variant`, OpenCode 2's replacement for `--variant`.
|
|
118
|
+
*
|
|
119
|
+
* `--standalone` is what keeps the confinement in force. By default `run`
|
|
120
|
+
* attaches to the shared background service, a server started earlier with its
|
|
121
|
+
* own environment and the user's global config, which never sees the inline
|
|
122
|
+
* config below: the reviewer agent would not exist there, or would not be
|
|
123
|
+
* confined. A standalone server is a private child that inherits this run's
|
|
124
|
+
* environment and working directory and exits with it. It also stands in for
|
|
125
|
+
* OpenCode 1's `--pure`: plugins load only from config, and the empty config
|
|
126
|
+
* directory with project config off leaves none to load. `--archived` keeps
|
|
127
|
+
* review sessions out of the user's session lists. Opencode has no per-run
|
|
128
|
+
* flag for permissions, and `--auto` would only *add* authority, never remove it.
|
|
115
129
|
*/
|
|
116
130
|
export function buildOpencodeReviewArgs(variant: string, model = OPENCODE_MODEL): string[] {
|
|
117
131
|
return [
|
|
118
132
|
"run",
|
|
119
133
|
"--model",
|
|
120
|
-
model
|
|
121
|
-
"--variant",
|
|
122
|
-
variant,
|
|
134
|
+
`${model}#${variant}`,
|
|
123
135
|
"--agent",
|
|
124
136
|
OPENCODE_REVIEW_AGENT,
|
|
125
|
-
"--
|
|
137
|
+
"--standalone",
|
|
138
|
+
"--archived",
|
|
126
139
|
];
|
|
127
140
|
}
|
|
128
141
|
|
|
142
|
+
/**
|
|
143
|
+
* The reviewer's environment: the caller's, with the inline config and
|
|
144
|
+
* OpenCode's outside configuration turned off. `directory` is the empty,
|
|
145
|
+
* non-repository directory the reviewer runs in. OpenCode 2 takes a session's
|
|
146
|
+
* directory from `PWD` before its working directory, and an inherited `PWD`
|
|
147
|
+
* names the checkout agent-tool runs from, so `PWD` is pinned too. The same
|
|
148
|
+
* directory is the config directory, which in OpenCode 2 replaces the global
|
|
149
|
+
* `~/.config/opencode` (its config, plugins, and MCP servers) outright.
|
|
150
|
+
* Project config and Claude Code compatibility (`~/.claude` skills, config,
|
|
151
|
+
* and CLAUDE.md instructions) are off, both spellings of the project switch
|
|
152
|
+
* are set because the newer one takes precedence, and an inherited
|
|
153
|
+
* `OPENCODE_CONFIG`, which would load one more config file, is dropped.
|
|
154
|
+
*/
|
|
155
|
+
export function buildOpencodeReviewEnv(env: ReviewerEnv, snapshotRoot: string, directory: string, model = OPENCODE_MODEL): ReviewerEnv {
|
|
156
|
+
const reviewEnv: ReviewerEnv = {
|
|
157
|
+
...env,
|
|
158
|
+
PWD: directory,
|
|
159
|
+
OPENCODE_CONFIG_CONTENT: buildOpencodeInlineConfig(snapshotRoot, model),
|
|
160
|
+
OPENCODE_CONFIG_DIR: directory,
|
|
161
|
+
OPENCODE_CONFIG_PROJECT_DISABLE: "1",
|
|
162
|
+
OPENCODE_DISABLE_PROJECT_CONFIG: "1",
|
|
163
|
+
OPENCODE_DISABLE_CLAUDE_CODE: "1",
|
|
164
|
+
};
|
|
165
|
+
delete reviewEnv.OPENCODE_CONFIG;
|
|
166
|
+
return reviewEnv;
|
|
167
|
+
}
|
|
168
|
+
|
|
129
169
|
/**
|
|
130
170
|
* Run `opencode run` over an already-built review prompt and relay whatever it
|
|
131
171
|
* prints to stdout — the final message alone, since run mode keeps its TUI
|
|
@@ -139,16 +179,17 @@ export function buildOpencodeReviewArgs(variant: string, model = OPENCODE_MODEL)
|
|
|
139
179
|
* stderr tail is relayed so the error is still diagnosable (the Codex path
|
|
140
180
|
* makes the same trade-off).
|
|
141
181
|
*
|
|
142
|
-
* The reviewer runs from a fresh, empty,
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* live in its data
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
182
|
+
* The reviewer runs on a private standalone server from a fresh, empty,
|
|
183
|
+
* non-repository directory (`buildOpencodeReviewEnv`), so nothing
|
|
184
|
+
* branch-controlled loads: not the snapshot's or checkout's `AGENTS.md` or
|
|
185
|
+
* `opencode.json`, and not a `.opencode/` directory. `OPENCODE_CONFIG_DIR`
|
|
186
|
+
* points at that same empty directory, so no user-defined agents, commands,
|
|
187
|
+
* plugins, or MCP servers from `~/.config/opencode` ride along either. That
|
|
188
|
+
* directory is *config* only: opencode's credentials live in its data
|
|
189
|
+
* directory (`~/.local/share/opencode/auth.json` on macOS), which
|
|
190
|
+
* `OPENCODE_CONFIG_DIR` does not touch, so the provider auth the review needs
|
|
191
|
+
* still resolves. Skills in `~/.agents/skills` are still discovered, but the
|
|
192
|
+
* inline config denies the skill tool and every read outside the snapshot.
|
|
152
193
|
*/
|
|
153
194
|
export async function spawnOpencodeReview(
|
|
154
195
|
prompt: string,
|
|
@@ -176,11 +217,7 @@ export async function spawnOpencodeReview(
|
|
|
176
217
|
// Neutral cwd: opencode would otherwise load the snapshot's
|
|
177
218
|
// branch-controlled config and instructions into the reviewer.
|
|
178
219
|
cwd: outDir,
|
|
179
|
-
env:
|
|
180
|
-
...env,
|
|
181
|
-
OPENCODE_CONFIG_CONTENT: buildOpencodeInlineConfig(snapshotRoot, model),
|
|
182
|
-
OPENCODE_CONFIG_DIR: outDir,
|
|
183
|
-
},
|
|
220
|
+
env: buildOpencodeReviewEnv(env, snapshotRoot, outDir, model),
|
|
184
221
|
},
|
|
185
222
|
));
|
|
186
223
|
const exitCode = spawnExitCode("opencode", result);
|