fix(cli): honor --yolo/--auto in mini and attach modes#42
Conversation
The auto-approve flags (--auto/--yolo/--dangerously-skip-permissions) were only handled by the non-interactive run loop and the main TUI; the mini interactive runtime ignored them (runMini hardcoded auto:false) and attach had no such flag. Thread auto through runMini, the tui/attach mini branches, and the interactive runtime into the session stream transport, which now replies "once" to every permission request when auto is on (questions still block; explicit deny rules still win). Also add the flags to attach and forward auto to the attach full-TUI. Adds a stream-transport regression test and updates the attach help snapshot.
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe CLI adds auto-approval flags and propagates the resolved setting through ChangesAuto Permission Approval
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant runMini
participant InteractiveRuntime
participant StreamTransport
participant SDK
CLI->>runMini: pass auto flag
runMini->>InteractiveRuntime: forward auto
InteractiveRuntime->>StreamTransport: create transport with auto
StreamTransport->>SDK: reply permission request with once
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/opencode/src/cli/cmd/attach.ts (1)
108-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the repeated auto-flag combination into a shared helper.
args.auto || args.yolo || args["dangerously-skip-permissions"]is duplicated here (twice) and again intui.tsandrun.ts. If the combination logic ever changes (e.g., a new hidden alias is added), each call site must be updated in lockstep or behavior silently diverges betweenattach,tui, andrun.♻️ Suggested shared helper
// e.g. in packages/opencode/src/cli/cmd/run/types.ts export function resolveAutoApprove(args: { auto?: boolean yolo?: boolean "dangerously-skip-permissions"?: boolean }): boolean { return Boolean(args.auto || args.yolo || args["dangerously-skip-permissions"]) }Then each call site becomes
auto: resolveAutoApprove(args).As per coding guidelines, "Do not extract single-use helpers preemptively; inline logic unless the helper is reused..." — since this expression is reused across at least four call sites, extraction is justified.
Also applies to: 158-158
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/opencode/src/cli/cmd/attach.ts` at line 108, Extract the repeated auto-approval expression into a shared resolveAutoApprove helper, using the existing argument names and returning a boolean. Replace both occurrences in attach.ts and the corresponding usages in tui.ts and run.ts with this helper, ensuring all call sites preserve the current behavior and import the shared symbol.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/opencode/src/cli/cmd/run/stream.transport.ts`:
- Around line 528-535: Update the auto-approval flow around
input.sdk.permission.reply so --auto/--yolo also processes permission requests
already pending from bootstrap or replay, not only live permission.asked events.
Handle reply failures with the session’s retry or error-propagation path instead
of swallowing them, ensuring failed requests do not remain silently blocked.
---
Nitpick comments:
In `@packages/opencode/src/cli/cmd/attach.ts`:
- Line 108: Extract the repeated auto-approval expression into a shared
resolveAutoApprove helper, using the existing argument names and returning a
boolean. Replace both occurrences in attach.ts and the corresponding usages in
tui.ts and run.ts with this helper, ensuring all call sites preserve the current
behavior and import the shared symbol.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c5ecb365-dc11-4c45-b949-766bff6b7366
⛔ Files ignored due to path filters (1)
packages/opencode/test/cli/help/__snapshots__/help-snapshots.test.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (7)
packages/opencode/src/cli/cmd/attach.tspackages/opencode/src/cli/cmd/run.tspackages/opencode/src/cli/cmd/run/runtime.tspackages/opencode/src/cli/cmd/run/stream.transport.tspackages/opencode/src/cli/cmd/run/types.tspackages/opencode/src/cli/cmd/tui.tspackages/opencode/test/cli/run/stream.transport.test.ts
| // YOLO: auto-approve permission requests without surfacing a prompt. | ||
| // Questions are left to the user; explicit deny rules already reject | ||
| // server-side before a permission.asked is ever emitted. | ||
| if (input.auto && event.type === "permission.asked") { | ||
| void input.sdk.permission.reply({ requestID: event.properties.id, reply: "once" }).catch(() => {}) | ||
| return | ||
| } | ||
|
|
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="packages/opencode/src/cli/cmd/run/stream.transport.ts"
echo "== outline =="
ast-grep outline "$FILE" --view expanded || true
echo
echo "== line count =="
wc -l "$FILE"
echo
echo "== relevant slice around 480-620 =="
sed -n '480,620p' "$FILE" | cat -nRepository: CreatorGhost/TheCode
Length of output: 7901
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="packages/opencode/src/cli/cmd/run/stream.transport.ts"
echo "== search for blocker/permission handling =="
rg -n "permission|blocker|seedBlocker|trackBlocker|auto" "$FILE"
echo
echo "== broader related symbols in file =="
sed -n '1,260p' "$FILE" | cat -nRepository: CreatorGhost/TheCode
Length of output: 12163
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="packages/opencode/src/cli/cmd/run/stream.transport.ts"
python3 - <<'PY'
from pathlib import Path
p = Path("packages/opencode/src/cli/cmd/run/stream.transport.ts")
text = p.read_text()
for needle in [
"seedBlocker(",
"trackBlocker(",
"applyEvent(",
"bootstrap(",
"replayOnResize(",
"permission.reply",
]:
idxs = [i for i in range(len(text)) if text.startswith(needle, i)]
print(f"{needle}: {len(idxs)}")
for i in idxs[:5]:
line = text.count("\n", 0, i) + 1
print(" line", line)
PYRepository: CreatorGhost/TheCode
Length of output: 397
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="packages/opencode/src/cli/cmd/run/stream.transport.ts"
# Show the exact implementation around permission handling and bootstrapping.
sed -n '260,420p' "$FILE" | cat -n
echo
sed -n '420,620p' "$FILE" | cat -nRepository: CreatorGhost/TheCode
Length of output: 12835
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="packages/opencode/src/cli/cmd/run/stream.transport.ts"
echo "== bootstrap permissions around 600-640 =="
sed -n '600,640p' "$FILE" | cat -n
echo
echo "== replay permissions around 790-815 =="
sed -n '790,815p' "$FILE" | cat -n
echo
echo "== resize restore around 1118-1140 =="
sed -n '1118,1140p' "$FILE" | cat -n
echo
echo "== applyEvent call site around 920-1015 =="
sed -n '920,1015p' "$FILE" | cat -n
echo
echo "== replayOnResize implementation around 1038-1088 =="
sed -n '1038,1088p' "$FILE" | cat -nRepository: CreatorGhost/TheCode
Length of output: 10695
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="packages/opencode/src/cli/cmd/run/stream.transport.ts"
python3 - <<'PY'
from pathlib import Path
p = Path("packages/opencode/src/cli/cmd/run/stream.transport.ts")
lines = p.read_text().splitlines()
for start, end, label in [
(600, 640, "bootstrap permissions"),
(790, 815, "replay permissions"),
(1118, 1140, "resize restore"),
(920, 1015, "applyEvent call site"),
(1038, 1088, "replayOnResize implementation"),
]:
print(f"== {label} ==")
for i in range(start-1, min(end, len(lines))):
print(f"{i+1:5d}: {lines[i]}")
print()
PYRepository: CreatorGhost/TheCode
Length of output: 10616
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="packages/opencode/src/cli/cmd/run/stream.transport.ts"
python3 - <<'PY'
from pathlib import Path
p = Path("packages/opencode/src/cli/cmd/run/stream.transport.ts")
lines = p.read_text().splitlines()
for start, end, label in [
(620, 640, "bootstrap permissions"),
(798, 810, "replay permissions"),
(1124, 1136, "resize restore"),
(930, 950, "applyEvent call site"),
(1040, 1080, "replayOnResize implementation"),
]:
print(f"== {label} ==")
for i in range(start-1, min(end, len(lines))):
print(f"{i+1:5d}: {lines[i]}")
print()
PYRepository: CreatorGhost/TheCode
Length of output: 5041
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect how permission.asked / permission.replied are reduced into SessionData.
FILE="packages/opencode/src/cli/cmd/run/session-data.ts"
echo "== outline =="
ast-grep outline "$FILE" --view expanded || true
echo
echo "== relevant permission-related slices =="
rg -n "permission\.asked|permission\.replied|question\.asked|question\.replied|question\.rejected|blocker|permissions|questions" "$FILE"
echo
python3 - <<'PY'
from pathlib import Path
p = Path("packages/opencode/src/cli/cmd/run/session-data.ts")
lines = p.read_text().splitlines()
for start, end in [(1, 260), (260, 520)]:
print(f"== lines {start}-{end} ==")
for i in range(start-1, min(end, len(lines))):
print(f"{i+1:5d}: {lines[i]}")
print()
PYRepository: CreatorGhost/TheCode
Length of output: 22229
Auto-reply existing permission blockers and handle reply failures
- Swallowing
permission.reply(...)errors leaves the request pending with no retry path; if the auto-reply fails, the session stays blocked. --auto/--yoloonly applies to livepermission.askedevents. Pending permissions seeded during bootstrap/replay still bypass auto-approval, so resumed sessions can remain blocked.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/opencode/src/cli/cmd/run/stream.transport.ts` around lines 528 -
535, Update the auto-approval flow around input.sdk.permission.reply so
--auto/--yolo also processes permission requests already pending from bootstrap
or replay, not only live permission.asked events. Handle reply failures with the
session’s retry or error-propagation path instead of swallowing them, ensuring
failed requests do not remain silently blocked.
What
The auto-approve permission flags (
--auto,--yolo,--dangerously-skip-permissions) already work for the non-interactiverunloop and the main TUI, but were ignored by the mini interactive runtime and absent fromattach. This closes those gaps.Changes
stream.transport.ts: whenautois set, the session transport replies"once"to everypermission.askedinstead of surfacing a footer prompt. Questions still block; explicitdenyrules still win (the server rejects them before ever emittingpermission.asked).autothroughrunInteractiveMode/runInteractiveLocalMode→runInteractiveRuntime→createSessionTransport.runMininow forwardsauto(was hardcodedfalse);run's interactive path passes it in.tuiandattachmini branches forward the resolved flag torunMini.attachgains--auto/--yolo/--dangerously-skip-permissionsand forwardsautoto the full-TUI path too.Tests
onceto apermission.asked.--autoflag.Summary by CodeRabbit
New Features
--autoto enable automatic approval, with additional hidden compatibility flags.Tests