Skip to content

fix(tool): publish the host-shell tool as shell instead of bash - #795

Closed
agenteinstinct1-max wants to merge 17 commits into
dev-vibecodedfrom
arena/6d4b9534-silvercode
Closed

agenteinstinct1-max wants to merge 17 commits into
dev-vibecodedfrom
arena/6d4b9534-silvercode

Conversation

@agenteinstinct1-max

@agenteinstinct1-max agenteinstinct1-max commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #780

Successor draft to #787, which was auto-closed by the compliance bot for a missing template. #780 is still open and this PR is not ready to merge: it carries the full published head of #787 (recovered by ordinary ancestry) plus review follow-ups, currently at 14515e9, and remains under active review.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The model-facing shell tool was published as bash even though it runs the host shell (zsh, sh, fish, PowerShell, cmd), and its descriptions claimed a "persistent shell session" when it actually spawns a fresh process per call. This PR publishes the tool as shell (single registration, no bash alias entry), corrects the model-facing wording, and updates the core tool ID, CORE_TOOLS, schema/SDK contracts, TUI/CLI/ACP surfaces, and history rendering. Concepts that genuinely are bash (tree-sitter grammar, bash-language-server, interpreter kinds in ShellID, the Zen fingerprint wire names) are unchanged.

Compatibility is preserved for configs and stored data written before the rename: permission.bash allow/deny rules (including per-pattern rules like "git *": "allow" and wildcard keys) still match the renamed tool through wildcard matching, saved grants keep working, and history parts stored with tool: "bash" render/replay from stored output without re-executing. A configured legacy deny must never silently fall back to the default ask.

Status of the independent-review findings (not claiming scope complete):

  • Ordered permission merge (fixed, c382a09). A review reproduced that the earlier rewrite flipped unrelated permissions from base verdicts (global edit {'*': allow, 'src/**': deny} + project edit {'*': allow} went from deny to allow). Base remeda mergeDeep / Object.assign semantics are restored everywhere; the only rename-specific ordering left is between the bash/shell spellings themselves (last write wins between them, permuted within their own key slots — they never cross * or unrelated keys), plus clearing the synthetic tools-derived slot when config writes the spelling explicitly. The reviewer cases (edit, external_directory, wholesale string replace, shell pattern position) are regression tests. update/updateGlobal apply the same pair ordering and have roundtrip tests (14515e9).
  • Zen wire gate (covered, bc54cc0; one gap remains). End-to-end fake-gateway tests now drive createFetch with the published catalog (canonical shell, web tools deferred): a fake enforcing exactly the gate rules documented in opencode-zen.ts accepts the adapter output (with a control proving the fake rejects non-compliant requests), shell executes through the AI SDK against a local gateway, hallucinated bash is preserved for invalid repair (negative control: stripped when the catalog has no shell). No in-repo source documents a tool-name allowlist on the live gateway, so whether it accepts the shell name is unverifiable without a live request, which this PR does not make.
  • doom_loop config reachability (covered where reachable, 14515e9). Config-level tests now cover V1 agent resolution (doom_loop: deny gates shell) and V2 permissions from opencode.json landing on resolved agents (legacy bash resource gates shell). Authored experimental.policies cannot express doom rules today (PolicyAction only allows provider.use), so Policy-level doom stays programmatic/unit-covered; widening authored actions is out of scope here.
  • SDK v1 types (no change, by policy). packages/sdk/js/src/gen has been frozen since v2 SDK anomalyco/opencode#5216 (documented in sdk-v1-smoke.test.ts); the canonical generator only emits v2 from the live OpenAPI, where PermissionConfig carries shell + legacy bash. The frozen v1 types still show the old summary shape; unfreezing them is a maintainer decision, not part of this rename.
  • Wildcard deny-clamp (pending review). A wildcard matching only via the new name (e.g. s* recruiting shell) cannot lift a deny that applied under bash; canonical wildcards and written order otherwise behave normally. This is an implementation judgment that still needs fresh exact independent review at this head — not self-approved.
  • Test-infrastructure timeouts (unresolved). Full-suite runs on the 2-vCPU sandbox still produce rotating 5000ms test-timeout failures in child-process tests (2 at this head, listed below). Recorded, not waived; no budgets or assertions were loosened.
  • Workspace sync test bound. The error-state wait is event-driven at the original 1500ms bound; the original CI failure's first transition exceeded that window on a loaded runner, which only an authorized bound change would cure — not taken.

How did you verify your code works?

Sequential bun test --timeout30000 --only-failures (Bun 1.3.14) at 14515e9: core 1532 pass / 3 skip / 0 fail; TUI 786 / 4 / 0; SDK 5 / 0; LLM 303 / 30 / 0; opencode 4979 / 25 skip / 1 todo / 2 fail — both failures are literal this test timed out after 5000ms child-process cases (TUI worker integration, snapshot deleted-files), the recurring sandbox timeout class noted above. Typechecks (core tsgo, opencode tsc, TUI, SDK) all exit 0. Targeted suites this round: test/config/config.test.ts + test/agent/agent.test.ts 174/0 (layered merge contracts, update/updateGlobal roundtrips, doom via agent resolution), test/provider/opencode-zen.test.ts 90/0 (fake-gateway wire contract, aggregated/streamed/JSON guards, end-to-end shell dispatch), core test/location-layer.test.ts 5/0 (configured permissions from a real opencode.json gating shell via a legacy bash doom resource), core permission/policy/wildcard 23/0. A fresh exact-head independent review is still required before merge.

Screenshots / recordings

TUI permission prompt and rendering for the renamed tool (assets committed in this PR's ancestry):

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

agenteinstinct1-max and others added 14 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]>
@github-actions

github-actions Bot commented Nov 1, 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.

agenteinstinct1-max and others added 3 commits November 1, 2026 20:50
… 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]>
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