Skip to content

fix: opencode auto-approve — token-exact --force match + test coverage - #25

Merged
zheng-weihao merged 1 commit into
mainfrom
fix/opencode-autoapprove-token-match
Jul 29, 2026
Merged

zheng-weihao merged 1 commit into
mainfrom
fix/opencode-autoapprove-token-match

Conversation

@zheng-weihao

Copy link
Copy Markdown
Member

Problem

The permission.ask handler parsed the subcommand by token but guarded sync --force with a whole-string substring match (cmd.includes("--force")), so any argument containing that substring — a future --forceful flag, or a value with --force embedded — tripped the destructive-command prompt. Conservative direction only (an extra prompt, never a wrongly-allowed command): a consistency hygiene issue, not a security hole. The shell hook (hooks/auto-approve.sh) already matches with token boundaries (space-padded --force).

Fix

  • Extract the decision into allowsOrbitCommand — a pure helper attached to the default export (same pattern as invokesOrbitCli), matching --force token-exactly, consistent with how the subcommand itself is parsed.
  • Test coverage (new): safe tiers allow / tier-3 (done prune clone config new) prompt / chained, substituted, and non-orbit commands prompt / sync --force prompts / --forceful allows / a whitespace-delimited --force inside quotes conservatively prompts (parity with the shell hook, fail-safe direction). 14/14 pass.
  • spec-hooks: the auto-approve section now contracts token-exact matching, never substring, so future integrations don't reintroduce the substring form.

Test

npm test in .opencode-plugin/ — 14/14. No runtime behavior change beyond removing the false-positive prompts.

…, spec contract

The permission.ask handler parsed the subcommand by token but fell back
to a whole-string substring match for the sync --force guard, so any
argument containing "--force" (a future --forceful flag, a value with
the word embedded) tripped the destructive-command prompt. Conservative
direction only — a consistency hygiene issue, not a hole.

- Extract the decision into allowsOrbitCommand (pure, attached to the
  default export like invokesOrbitCli) with token-exact matching.
- Cover it with tests: safe tiers allow, tier-3/chained/non-orbit
  prompt, sync --force prompts, --forceful allows, quoted --force word
  conservatively prompts (parity with the shell hook's padded match).
- spec-hooks: contract the token-exact rule so future ports don't
  reintroduce substring matching.

Signed-off-by: zheng-weihao <zheng-weihao@outlook.com>
@zheng-weihao
zheng-weihao merged commit c098de3 into main Jul 29, 2026
2 checks passed
@zheng-weihao
zheng-weihao deleted the fix/opencode-autoapprove-token-match branch July 29, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant