Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
214852a
fix: quote $ARGUMENTS in cancel/result/status commands
JohnnyVicious Apr 12, 2026
6665b2d
fix: declare model: sonnet in opencode-rescue agent frontmatter
JohnnyVicious Apr 12, 2026
260d84b
fix: scope /opencode:cancel default to current Claude session
JohnnyVicious Apr 12, 2026
cad21e8
fix: enforce hard wall-clock timeout on runTrackedJob
JohnnyVicious Apr 12, 2026
a4e0097
fix: reconcile dead-PID jobs on every status read
JohnnyVicious Apr 12, 2026
e196f88
fix: avoid embedding large diffs in review prompts
JohnnyVicious Apr 12, 2026
f8d3fcc
fix: respect \$SHELL on Windows when spawning child processes
JohnnyVicious Apr 12, 2026
3535f56
fix: migrate tmpdir state to CLAUDE_PLUGIN_DATA + fix /tmp literal
JohnnyVicious Apr 12, 2026
a1019be
feat: pass last review findings to rescue automatically
JohnnyVicious Apr 12, 2026
1c61980
feat: throttle controls for stop-time review gate
JohnnyVicious Apr 12, 2026
23f7fef
feat: --worktree flag for isolated write-capable rescue tasks
JohnnyVicious Apr 12, 2026
c9c4e74
fix: address pr51 review findings
JohnnyVicious Apr 12, 2026
83e22a9
Merge remote-tracking branch 'origin/main' into feat/codex-port-batch
JohnnyVicious Apr 12, 2026
88b3532
fix: keep tracked job timeout referenced
JohnnyVicious Apr 12, 2026
d299b96
fix: address pr51 review conversations
JohnnyVicious Apr 12, 2026
328576e
fix: add exclusive file lock to updateState for concurrency safety
JohnnyVicious Apr 12, 2026
485d25c
fix: address brownfield discovery bugs
JohnnyVicious Apr 12, 2026
05e70f3
fix: polish pr51 follow-up fixes
JohnnyVicious Apr 12, 2026
892493c
fix: address Copilot PR#51 review comments
JohnnyVicious Apr 12, 2026
b49da73
fix: keep reading fallback state while migrate lock is held
JohnnyVicious Apr 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/opencode/agents/opencode-rescue.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: opencode-rescue
description: Proactively use when Claude Code is stuck, wants a second implementation or diagnosis pass, needs a deeper root-cause investigation, or should hand a substantial coding task to OpenCode through the shared runtime
model: sonnet
tools: Bash
skills:
- opencode-runtime
Expand Down Expand Up @@ -28,6 +29,7 @@ Forwarding rules:
- Leave `--agent` unset unless the user explicitly requests a specific agent (build or plan).
- Leave model unset by default. Only add `--model` or `--free` when the user explicitly asks for a specific model or a free-tier pick. `--free` and `--model` are mutually exclusive.
- Treat `--agent <value>`, `--model <value>`, and `--free` as runtime controls and do not include them in the task text you pass through.
- If the request includes `--worktree`, pass `--worktree` through to `task`. This runs OpenCode in an isolated git worktree instead of editing the working directory in-place.
- Default to a write-capable OpenCode run by adding `--write` unless the user explicitly asks for read-only behavior or only wants review, diagnosis, or research without edits.
- Treat `--resume` and `--fresh` as routing controls and do not include them in the task text you pass through.
- `--resume` means add `--resume-last`.
Expand Down
4 changes: 3 additions & 1 deletion plugins/opencode/commands/cancel.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ allowed-tools: Bash(node:*)
Run the cancel command and return output verbatim.

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" cancel $ARGUMENTS
node "${CLAUDE_PLUGIN_ROOT}/scripts/safe-command.mjs" cancel <<'OPENCODE_ARGS'
$ARGUMENTS
OPENCODE_ARGS
```

- Return the command stdout verbatim, exactly as-is.
Expand Down
28 changes: 24 additions & 4 deletions plugins/opencode/commands/rescue.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
description: Delegate investigation, an explicit fix request, or follow-up rescue work to the OpenCode rescue subagent
argument-hint: "[--background|--wait] [--resume|--fresh] [--model <provider/model> | --free] [--agent <build|plan>] [what OpenCode should investigate, solve, or continue]"
argument-hint: "[--background|--wait] [--worktree] [--resume|--fresh] [--model <provider/model> | --free] [--agent <build|plan>] [what OpenCode should investigate, solve, or continue]"
context: fork
allowed-tools: Bash(node:*)
allowed-tools: Bash(node:*), AskUserQuestion
---

Route this request to the `opencode:opencode-rescue` subagent.
Expand All @@ -18,6 +18,7 @@ Execution mode:
- If neither flag is present, default to foreground.
- `--background` and `--wait` are execution flags for Claude Code. Do not forward them to `task`, and do not treat them as part of the natural-language task text.
- `--model`, `--free`, and `--agent` are runtime-selection flags. Preserve them for the forwarded `task` call, but do not treat them as part of the natural-language task text. `--free` tells the companion to pick a random first-party `opencode/*` free-tier model from `opencode models`; it is restricted to `opencode/*` because OpenRouter free models have inconsistent tool-use support. `--free` is mutually exclusive with `--model`.
- `--worktree` is an isolation flag. Preserve it for the forwarded `task` call, but do not treat it as part of the natural-language task text. When present, OpenCode runs in an isolated git worktree instead of editing the working directory in-place.
- If the request includes `--resume`, do not ask whether to continue. The user already chose.
- If the request includes `--fresh`, do not ask whether to continue. The user already chose.
- Otherwise, before starting OpenCode, check for a resumable rescue session from this Claude session by running:
Expand All @@ -43,7 +44,26 @@ Operating rules:
- Do not paraphrase, summarize, rewrite, or add commentary before or after it.
- Do not ask the subagent to inspect files, monitor progress, poll `/opencode:status`, fetch `/opencode:result`, call `/opencode:cancel`, summarize output, or do follow-up work of its own.
- Leave `--agent` unset unless the user explicitly asks for a specific agent (build or plan).
- Leave the model unset unless the user explicitly asks for one.
- Leave the model unset unless the user explicitly asks for a specific model or `--free`.
- Leave `--resume` and `--fresh` in the forwarded request. The subagent handles that routing when it builds the `task` command.
- If the helper reports that OpenCode is missing or unauthenticated, stop and tell the user to run `/opencode:setup`.
- If the user did not supply a request, ask what OpenCode should investigate or fix.
- If the user did not supply a request, check for a saved review from `/opencode:review` or `/opencode:adversarial-review`:

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" last-review
```

- If stdout is `LAST_REVIEW_AVAILABLE`, use `AskUserQuestion` exactly once with two options:
- `Fix issues from last review (Recommended)` — prepend the saved review content as context for the rescue task
- `Describe a new task` — ask what OpenCode should investigate or fix
- If the user chooses to fix from last review, read the saved review via:

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" last-review --content
```

and include its stdout verbatim in the forwarded task text, prefixed with:

`The following issues were found in a prior OpenCode review. Please fix them:\n\n`

- If stdout is `NO_LAST_REVIEW`, ask what OpenCode should investigate or fix.
4 changes: 3 additions & 1 deletion plugins/opencode/commands/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ allowed-tools: Bash(node:*)
Run the result command and return output verbatim.

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" result $ARGUMENTS
node "${CLAUDE_PLUGIN_ROOT}/scripts/safe-command.mjs" result <<'OPENCODE_ARGS'
$ARGUMENTS
OPENCODE_ARGS
```

- Return the command stdout verbatim, exactly as-is.
Expand Down
10 changes: 7 additions & 3 deletions plugins/opencode/commands/setup.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
description: Check whether the local OpenCode CLI is ready and optionally toggle the stop-time review gate
argument-hint: '[--enable-review-gate|--disable-review-gate]'
argument-hint: '[--enable-review-gate|--disable-review-gate] [--review-gate-max <n|off>] [--review-gate-cooldown <minutes|off>]'
allowed-tools: Bash(node:*), Bash(npm:*), Bash(brew:*), Bash(curl:*), AskUserQuestion
---

Run:

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" setup --json $ARGUMENTS
node "${CLAUDE_PLUGIN_ROOT}/scripts/safe-command.mjs" setup <<'OPENCODE_ARGS'
$ARGUMENTS
OPENCODE_ARGS
```

If the result says OpenCode is unavailable:
Expand All @@ -25,7 +27,9 @@ npm install -g opencode-ai
- Then rerun:

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" setup --json $ARGUMENTS
node "${CLAUDE_PLUGIN_ROOT}/scripts/safe-command.mjs" setup <<'OPENCODE_ARGS'
$ARGUMENTS
OPENCODE_ARGS
```

If OpenCode is already installed:
Expand Down
4 changes: 3 additions & 1 deletion plugins/opencode/commands/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ allowed-tools: Bash(node:*)
Run the status command and return output verbatim.

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" status $ARGUMENTS
node "${CLAUDE_PLUGIN_ROOT}/scripts/safe-command.mjs" status <<'OPENCODE_ARGS'
$ARGUMENTS
OPENCODE_ARGS
```

- Return the command stdout verbatim, exactly as-is.
Expand Down
4 changes: 4 additions & 0 deletions plugins/opencode/prompts/adversarial-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ Before finalizing, check that each finding is:
- actionable for an engineer fixing the issue
</final_check>

<review_collection_guidance>
{{REVIEW_COLLECTION_GUIDANCE}}
</review_collection_guidance>

<repository_context>
{{REVIEW_INPUT}}
</repository_context>
5 changes: 3 additions & 2 deletions plugins/opencode/scripts/lib/fs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export function appendLine(filePath, line) {
export function tailLines(filePath, n = 10) {
try {
const content = fs.readFileSync(filePath, "utf8");
const lines = content.split("\n").filter(Boolean);
return lines.slice(-n);
const lines = content.split("\n");
const nonEmpty = lines.filter((line) => line.length > 0);
return nonEmpty.slice(-n);
} catch {
return [];
}
Expand Down
Loading