Skip to content

fix(config): keep a tools-derived legacy shell deny off the renamed wildcard (Refs #780) - #805

Closed
agenteinstinct1-max wants to merge 21 commits into
dev-vibecodedfrom
arena/97632e3a-silvercode
Closed

agenteinstinct1-max wants to merge 21 commits into
dev-vibecodedfrom
arena/97632e3a-silvercode

Conversation

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator

What this fixes

packages/core canonicalises a legacy tools: { bash: false } into a shell: "deny" permission rule. That canonical deny must survive an unrelated, rename-recruited s*: "allow" wildcard, while every explicit shell rule keeps plain written (last-wins) order.

The canonical map alone cannot express that distinction: the inherited deny and an explicit shell: "deny" produce the identical ruleset { shell: "deny", "s*": "allow" }. This PR carries the distinction as internal provenance instead of changing the representation.

Approach

  • The config value, layer merge, HTTP API, and SDK wire stay canonical shell. Nothing is published as bash.
  • Provenance is a non-enumerable symbol on the permission record (@opencode/config-permission/derived-shell-deny) plus one on the folded tools map (@opencode/config/tools-legacy-shell-deny). Symbols are skipped by Object.keys, spread, JSON.stringify, and schema encode — verified: keys ["shell","s*"], JSON {"shell":"deny","s*":"allow"}, Schema.encodeSync(ConfigPermissionV1.Info) identical.
  • The mark is attached at the two places where the legacy spelling is still visible: the raw config layer decoded in config.ts (agent/mode records) and the real fold (foldTools, carryToolsProvenance), then re-carried across every rebuild point (mergeConfig, mergeAgentRecords, orderConfigPermissions/orderRecordPermissions). No policy inference at evaluation time.
  • permission.fromConfig reads the marker and maps a derived deny to the legacy bash rule, which the unchanged wildcard.ts clamp already refuses to let a recruited s* lift. An explicit write clears the marker (carryDerivedShellDeny).
  • No global deny clamp, no wildcard change, no ordering-policy redesign, no assert weakening. clearDerivedShellRename keeps its original per-spelling contract and packages/core/test/config/permission.test.ts is untouched.

Verdict table (all asserted in test/config/config.test.ts)

config result
tools:{bash:false} + s*:allow (top-level) deny
tools:{bash:false} + s*:allow (agent) deny
explicit shell:deny + s*:allow (top-level) allow
explicit shell:deny + s*:allow (agent) allow
tools:{bash:false} + *:allow allow
tools:{bash:false} + shell:allow allow
tools:{bash:false} + s*:allow, query skill allow

Additions only in tests (104 lines, no edits to existing expectations, incl. the migration deny case returning { shell: "deny", webfetch: "deny" }).

Verification (exact head 7e68c08cc)

  • packages/opencode full suite: 5003 pass, 25 skip, 1 todo, 0 fail — 342 files, 1378 s, exit 0.
  • packages/core full suite: 1535 pass, 3 skip, 0 fail — 169 files, exit 0 (includes the original clearDerivedShellRename contract).
  • packages/tui full suite: 826 pass, 5 skip, 0 fail — 108 files.
  • packages/llm: 303 pass, 30 skip, 0 fail.
  • Pre-push hook (.husky/pre-push) run verbatim: exit 0, 17/17 typecheck tasks successful (serial, 3072 MB heap; no repo ceiling change).
  • Wire check: test/server/httpapi-config.test.ts + httpapi-global.test.ts pass; schema encode and JSON.stringify contain no bash key.

A one-off test/cli/launcher.test.ts SIGINT failure appeared in the first full run (that file is untouched here). Controls: same file passes in isolation on this head and on base 75c9d61, and the re-run full head suite and a full base-75c9d61 suite (4933 pass, 0 fail) are green. Attributed to suite-load flake, not this change.

Merge

Branch merged the accepted tip 75c9d61e9 normally (no force/rebase/tree assembly). One conflict in packages/tui/src/routes/session/index.tsx resolved by keeping the incoming ACTIVITY_DETAIL_INDENT block and this branch's canonical shell wording; TUI suite is green on the merged head.

Supersedes the bash-representation approach in #795/#800 (not published).

agenteinstinct1-max and others added 21 commits November 1, 2026 11:30
Early durable checkpoint — slice 1 of the #780 rename:
- ShellID.ToolID and the V2 core tool now publish "shell"; core tool file
  bash.ts -> shell.ts (ShellTool), no doubled registration.
- CORE_TOOLS drops the stale "bash" duplicate.
- Model-facing prompt text says shell (and truthfully describes a fresh
  process per call) for pwsh/cmd/POSIX profiles.
- Permission compatibility: Wildcard.matchAction treats legacy "bash" as an
  alias subject for canonical "shell" in V1 evaluate/disabled/ask, V2
  evaluate, Policy.evaluate, whollyDisabled, and llm preapproved matching —
  wildcard semantics and findLast precedence unchanged, so a legacy deny
  cannot degrade to ask. Config schema gains typed "shell", keeps "bash".
- Core tool test renamed to tool-shell.test.ts incl. a legacy bash-deny case.

Remaining: ACP/CLI/TUI labels + legacy history recognition, generated
SDK/schema contracts, opencode test/tree update, fake-provider catalog
coverage, full package suites.

Co-authored-by: arena-agent <[email protected]>
…s (Refs #780)

Slice 2 checkpoint:
- ACP/CLI run/TUI/github handler recognize canonical "shell" and keep
  rendering legacy persisted "bash" parts (no re-execution, no doubled
  rendering); synthetic shell-mode commits now carry tool "shell".
- TUI activity grouping kind bash -> shell with legacy tool id mapped to
  the same kind; permission prompt, tips text say shell.
- Model-facing system/agent prompts and grep tool text reference the
  shell tool by its new name.
- CLI agent create lists canonical "shell" permission (help snapshot
  regenerated; single owned line).
- Generated contracts via canonical generator, owned delta only
  (PermissionConfig gains "shell" in openapi.json + SDK v2 types);
  pre-existing baseline drift in generated files left untouched.
- Tests updated to canonical shell (fake providers call "shell"); legacy
  fixtures kept where they simulate persisted history; run-process legacy
  {bash: ask/deny} config kept deliberately as runtime back-compat proof.

Verified so far: core suite 1515+ pass after location-layer expectation
update (1 remaining file fix included), opencode previously-failing 26
tests across 10 files now pass file-by-file. Full re-runs + TUI pending.

Co-authored-by: arena-agent <[email protected]>
…prompts

- permission/next.test.ts: order-preservation tests now evaluate the
  canonical "shell" action against legacy "bash" config; new tests pin
  legacy deny (no ask broadening), per-pattern rules, wildcard permission
  patterns ("ba*"), last-wins order across spellings, and disabled().
- core permission.test.ts: V2 saved legacy "bash" approvals apply to
  "shell" assertions; configured legacy deny keeps precedence.
- registry/catalog tests: model-facing catalog publishes exactly one
  "shell" and no "bash"; CORE_TOOLS likewise.
- shell-prompt.test.ts: every profile says "shell tool call", never
  "bash tool call"/"given bash command"/"persistent shell session";
  POSIX intro says fresh shell process.
- tui activity tests: kind expectations bash -> shell; legacy tool id
  "bash" asserted to group as shell.
- customize-opencode skill doc: permission examples/known keys say
  "shell" (legacy "bash" noted as honored alias).

Co-authored-by: arena-agent <[email protected]>
The repo-wide formatter run inside the contract generator had rewrapped
unrelated regions of these two owned files. Restored from baseline and
re-applied only the semantic rename edits; behavior unchanged (activity
tests + tui typecheck re-verified).

Co-authored-by: arena-agent <[email protected]>
…name (Refs #780)

Review follow-up for the #780 rename, addressing the REQUEST CHANGES
findings on 18ceca2 with RED/GREEN regression tests:

- HIGH config merge: config layers merge by object key, so keeping both
  the legacy 'bash' and canonical 'shell' permission keys let an older
  layer outrank a newer one purely by key position (a later deny lost
  to an earlier allow). Fold 'bash' into 'shell' as each layer is
  decoded (ConfigPermissionV1.canonicalize, order-preserving; two rule
  objects deep-merge per pattern, otherwise the later entry wins), and
  canonicalize again at the merge choke points (mergeConfig operands,
  OPENCODE_PERMISSION, tools->permissions, agent tools/permission) so
  layered global/project/local, managed (MDM), env, and agent cases all
  resolve by layer order exactly as pre-rename configs did. No blanket
  deny: findLast semantics are preserved.
- HIGH doom_loop: doom_loop rules key on the tool id, so match their
  resources with matchAction in the V1 evaluator, V2 Permission, and
  Policy: a legacy {bash: deny} pattern (or 'ba*') gates the renamed
  'shell' tool again, with wildcard + findLast semantics unchanged and
  no deny->ask conversion. Non-doom resources are unaffected.
- MED tool-name lists: tool_search defer/always_load now match with
  matchAction (legacy 'bash' hits 'shell'); V2 context protection
  compares canonical spellings so tools:['bash'] protects new shell
  calls and tools:['shell'] protects archived bash calls.
- MED Zen: fingerprint names stay wire constants, but a fingerprint
  tool counts as caller-provided when the catalog carries its canonical
  spelling; a hallucinated 'bash' call now reaches the runtime
  invalid-tool repair (and satisfies no required tool_choice check)
  instead of being silently stripped as gateway-injected. Zero shell
  execution proven by a new end-to-end fake-provider control.
- LOW: CLI run summary says 'shell completed'; tips name shell
  permissions; builtin TUI renderer test covers 'shell'.
- LSP: an already-settled publish (quiet for the full debounce window)
  resolves synchronously instead of depending on timer scheduling
  latency; the debounce quiet-period guarantee for fresh publishes,
  the 1000ms test bound, and all budgets are unchanged.

Co-authored-by: arena-agent <[email protected]>
Config decode now stores canonical 'shell' rules, so a permission query
under the legacy 'bash' name must resolve them too: matchAction treats
the two spellings as one action identity in both directions (previously
only a canonical query matched legacy-spelled patterns). This restores
agent/task evaluations that ask for 'bash' against canonicalized
rulesets. Updates the remaining test expectations that encoded the
pre-canonicalization 'bash' key in decoded config (tools migration,
key order, managed-plist).

Co-authored-by: arena-agent <[email protected]>
Captured from the real binary at the current head (--mini --demo):
/permission shell renders the canonical 'Shell command' permission
prompt and /fmt shell renders the shell tool part; neither surface
mentions the pre-rename bash identity.

Co-authored-by: arena-agent <[email protected]>
…eaning (Refs #780)

Second exact-review follow-up (REQUEST CHANGES on fe6fd39), RED/GREEN:

1. Ordered permission merge: folding bash->shell at decode (previous
   follow-up) collapsed two keys into the first key's position, so
   {bash:ask, *:allow, shell:deny} evaluated allow and nested pattern
   order was lost; plain mergeDeep has the same retention across layers.
   Decode no longer folds (written key order/spelling preserved), and
   every permission merge (mergeConfig top-level + agent.* + mode.*,
   agent-dir loads, mode conversion, OPENCODE_PERMISSION, tools->perms,
   agent tools+explicit) now uses ConfigPermissionV1.merge: rule-sequence
   semantics where a key/pattern written by a later layer takes that
   layer's position, and a flat action promotes to the * pattern instead
   of replacing inner patterns. Layering now evaluates as the
   concatenation of the layers' rule sequences.
2. Legacy tools records: fold the bash key to shell per layer before
   merging (mergeConfig operands, agent/mode records), so
   tools {shell:false} / {bash:true} / managed {shell:false} resolves by
   layer order (deny), in both spelling orders.
3. Agent normalize: explicit permission merges over the tools-derived
   layer with the ordered merge instead of Object.assign, so
   tools{bash:true} + permission{*:allow, shell:deny} keeps the explicit
   order and evaluates deny (allow-last control covered).
4. Wildcard meaning: union alias matching let a legacy s* (written when
   it covered skill) recruit the renamed shell tool and bypass an
   explicit bash:deny ordered before it. matchAction now preserves each
   pattern's written meaning: literal patterns match either exact
   spelling in written order (explicit re-permits still win), wildcard
   patterns match against the legacy spelling only (ba* still gates
   shell; s*/sh* do not capture it — fail-closed to ask). Applies
   uniformly to V1 evaluate, V2 Permission, Policy, doom_loop resources,
   and tool-name lists.

Also adds the archived-history control: a persisted completed
tool:'bash' part is replayed from stored output and never re-executed
under the new name.

Co-authored-by: arena-agent <[email protected]>
…ansient state (Refs #780)

Windows CI at fe6fd39 failed exactly one test: 'remote connection HTTP
failures set error and clear syncing' expected status 'error' but still
saw 'connecting' when its 1500ms poll expired. Causal trace: the sync
loop sets 'error' only after the first 503 round-trip (fiber scheduling
plus real in-process HTTP on a runner executing seven suites in
parallel) and flips back to 'connecting' after the 1s retry backoff, so
the test raced both the first-transition latency and a transient state
with a fixed wall-clock polling window. Product behavior is correct
(error is set and emitted on HTTP failure; setStatus updates state
before emitting).

The test now registers for the Status 'error' event via the product's
own waitEvent (same 5000ms bound Workspace uses internally) before
starting sync, joins it, and then makes the same status()/isSyncing
assertions. No assertion or product deadline changed; the wait is now
condition-driven and completes as soon as the transition happens. The
history-failure sibling had the identical latent race and gets the same
wait.

Co-authored-by: arena-agent <[email protected]>
… clamp (Refs #780)

Parent review of c3cdbfb rejected redefining wildcard behavior: matching
s*/sh* against the legacy spelling only silently broke canonical
wildcard use. Source-grounded contract (issue #780 + repo semantics):
rules match with Wildcard.match and resolve with findLast, and a
configured deny must never silently broaden. Production rulesets also
always carry defaults ('*': allow) before user rules, so any
extension/tier scheme that sidelines canonical wildcards whenever a
legacy-visible rule exists would disable them in practice.

Minimal compatible semantics, implemented as Wildcard.winningRule and
used by V1 evaluate, V2 Permission.evaluate, Policy.evaluate,
Permission.disabled, and the preapproved/wholly-disabled lookups:
- matchAction is plain union matching again: a pattern matches if it
  matches any spelling of the tool name; findLast order is untouched.
  Canonical s*/sh* name shell (including as carve-outs over '*'
  defaults), legacy ba* still gates it, exact-name re-permits win by
  written order.
- One clamp: when the winning rule matched the tool only because of the
  rename (a wildcard matching the canonical name but no legacy
  spelling — recruitedByRename; exact spellings of either name never
  count as recruited) and the same rules evaluated under the legacy
  name yield a deny, the legacy deny stands. Only deny is clamped;
  narrowing and ask->allow order are unchanged. Applies to the
  doom_loop resource dimension the same way.

So {bash:deny, s*:allow} stays deny, {*:ask, s*:allow} allows, and
{s*:deny} disables shell — canonical behavior with legacy negative
scope intact.

Co-authored-by: arena-agent <[email protected]>
…by event (Refs #780)

Parent review: the previous waitEvent timeout of 5000 changed the
observation bound (original poll: 1500ms); a deadline increase needs
explicit authority. Restore the identical 1500ms bound and assertions:
the test subscribes for the Status 'error' event before starting sync
and joins it, so the transient error state (the loop flips back to
'connecting' after the 1s retry backoff) cannot be missed by a level
poll, and the status()/isSyncing assertions run in the same instant
the transition is recorded (setStatus updates state before emitting).

Raw-log note for the fe6fd39 Windows failure: no 'failed to connect to
global sync' warning appears before teardown, indicating the first
transition had not fired inside the window on that loaded runner. This
change removes the structural level-poll miss at the same bound; a
first transition slower than 1500ms under CI load remains possible and
would need a separately authorized bound change.

Co-authored-by: arena-agent <[email protected]>
… to the bash/shell pair (Refs #780)

Independent review of the successor head reproduced a HIGH: the earlier
ordered permission merge repositioned every key a later layer wrote, so
global edit {'*': allow, 'src/**': deny} + project edit {'*': allow}
flipped src paths from base deny to allow — the rename was silently
changing the pre-existing deep-merge precedence contract for permissions
it does not involve (same for external_directory secrets, and flat
actions were being promoted/merged instead of replacing records
wholesale).

Restore remeda mergeDeep / Object.assign everywhere (mergeConfig,
agent-record merge, OPENCODE_PERMISSION, tools-derived merge, agent
normalize) and delete ConfigPermissionV1.merge. The only remaining
rename-specific ordering is between the two spellings of the renamed
permission itself:

- ConfigPermissionV1.orderShellRename(merged, source): after a base
  merge, permutes / within the key slots they already
  occupy so their relative order follows last write (global shell ->
  project bash -> local shell must keep local precedence). A spelling
  never crosses  or any unrelated key; single-layer written order
  is preserved exactly.
- ConfigPermissionV1.clearDerivedShellRename: in tools-derived records
  (agent normalize, top-level tools), an explicit / entry
  replaces the synthetic derived slot at its own written position.

update/updateGlobal apply the same pair ordering after their mergeDeep
so a written config evaluates the same way it loads (JSON path; the
jsonc text patch still relies on load-time ordering).

Inner pattern positions keep base semantics uniformly, including for
shell itself; new regression tests pin the reviewer cases (edit,
external_directory, wholesale replace, shell pattern position) and the
round-3 cross-spelling layer precedence stays green.

Co-authored-by: arena-agent <[email protected]>
…atalog (Refs #780)

Independent review HIGH: #780 coverage only exercised the JSON/stream
response guards with a toy one-tool catalog, never the outbound
createFetch path with the catalog the app actually publishes.

- requests: send a CORE_TOOLS-shaped catalog (shell, glob, grep, read,
  tool_search, edit, write; web tools deferred) through createFetch
  against a fake gateway enforcing exactly the acceptance rules
  documented in opencode-zen.ts, including the 2026-10-14 revision
  (session required, streaming only, synthetic empty-schema quartet
  rejected, tool catalogs without a web tool rejected, tool-less
  accepted). Assert the wire carries the caller catalog verbatim plus
  appended web tools: canonical shell, no hidden bash. A control test
  proves the fake rejects session-less, non-streamed, synthetic-stub,
  and webless requests so the pass is not vacuous. No in-repo source
  documents a tool-name allowlist on the live gateway; this proves the
  adapter satisfies every documented rule, not live acceptance of the
  shell name (unverifiable without a live request, which this does not
  make).
- injected guard: hallucinated bash preservation through the SSE
  aggregation path (previously only JSON and streamed paths covered).
- end to end (fake gateway HTTP server + AI SDK): the renamed shell
  tool dispatches and executes for generateText and streamText with
  the expected wire catalog; negative control — a catalog with glob,
  grep, read but no shell still strips a bash call, proving canonical
  membership is what preserves it.
- Align the ZEN_FINGERPRINT_TOOLS comment with the 2026-10-14 gate
  revision it contradicted; the constant and wire names are unchanged.

Co-authored-by: arena-agent <[email protected]>
…op paths (Refs #780)

Independent-review MEDs: the write paths and doom_loop were only covered
at unit level.

- update/updateGlobal roundtrips: an existing file carrying both
  spellings plus an unrelated edit record is rewritten so the
  patch-written spelling is ordered after its sibling (the file
  evaluates the way load orders it), while the edit record keeps base
  deep-merge pattern positions.
- V1 doom_loop: config permission {doom_loop: deny} gates the renamed
  shell tool through real agent resolution, using exactly the query the
  doom detector issues (patterns: [toolName]); default stays ask.
- V2: opencode.json permissions with a legacy bash doom_loop resource
  load through the location and land on resolved AgentV2 rulesets,
  gating shell. (Authored experimental.policies remain limited to
  provider.use actions by ConfigExperimental.PolicyAction, so Policy-
  level doom stays programmatic and unit-covered.)

Co-authored-by: arena-agent <[email protected]>
…632e3a-silvercode

# Conflicts:
#	packages/tui/src/routes/session/index.tsx

Co-authored-by: arena-agent <[email protected]>
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot closed this Nov 2, 2026
agenteinstinct1-max added a commit that referenced this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant