Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
82f4f0b
wip(tool): rename public shell tool id from bash to shell (Refs #780)
agenteinstinct1-max Nov 1, 2026
918d984
wip(tool): shell rename across ACP/CLI/TUI/prompts/generated contract…
agenteinstinct1-max Nov 1, 2026
a48f7c6
test(tool): #780 rename coverage — legacy permission alias, catalog, …
agenteinstinct1-max Nov 1, 2026
be54fb3
style(tui): drop formatter churn from session/activity files (Refs #780)
agenteinstinct1-max Nov 1, 2026
18ceca2
merge: integrate accepted dev-vibecoded 50d6a23 (#785) into shell ren…
agenteinstinct1-max Nov 1, 2026
2fc5fd7
fix(shell): preserve layer + rule precedence across the bash/shell re…
agenteinstinct1-max Nov 1, 2026
b60cfc3
test(permission): type the doom_loop ruleset as PermissionV1.Ruleset …
agenteinstinct1-max Nov 1, 2026
eb0aeee
test(core): V1 permission migration now yields canonical shell action…
agenteinstinct1-max Nov 1, 2026
99f3eb2
fix(permission): make bash/shell action aliasing symmetric (Refs #780)
agenteinstinct1-max Nov 1, 2026
fe6fd39
docs(assets): shell permission + fmt TUI evidence for #780 review
agenteinstinct1-max Nov 1, 2026
c3cdbfb
fix(permission): preserve actual rule order and pre-rename wildcard m…
agenteinstinct1-max Nov 1, 2026
1b0a5f0
test(workspace): await the error status event instead of polling a tr…
agenteinstinct1-max Nov 1, 2026
9c71945
fix(permission): union matching with a narrow rename-recruitment deny…
agenteinstinct1-max Nov 1, 2026
ddf78d1
test(workspace): keep the 1500ms bound, observe the error transition …
agenteinstinct1-max Nov 1, 2026
c382a09
fix(config): restore base deep-merge contract, narrow rename ordering…
agenteinstinct1-max Nov 1, 2026
bc54cc0
test(zen): end-to-end fake-gateway contract for the published shell c…
agenteinstinct1-max Nov 1, 2026
14515e9
test(config): update/updateGlobal roundtrips and config-level doom_lo…
agenteinstinct1-max Nov 1, 2026
15ba289
fix(config): order shell permission writes in global JSONC
agenteinstinct1-max Nov 2, 2026
6c29227
fix(config): treat empty shell permission maps as no write
agenteinstinct1-max Nov 2, 2026
ff71b37
fix(config): keep a tools-derived legacy shell deny from a recruited …
agenteinstinct1-max Nov 2, 2026
7e68c08
Merge commit '75c9d61e9ab5a90e4ee0af3e06210305773a08b0' into arena/97…
agenteinstinct1-max Nov 2, 2026
a3e96d8
Merge commit 'cecc80be84c7aa8a5adba27d8baef5b860756458' into arena/a3…
agenteinstinct1-max Nov 2, 2026
823874c
test(cli): synchronize launcher signal fixture
agenteinstinct1-max Nov 2, 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
Binary file added .github/assets/tui-fmt-shell-780.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/assets/tui-permission-shell-780.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 22 additions & 9 deletions packages/core/src/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,28 @@ export class NotFoundError extends Schema.TaggedErrorClass<NotFoundError>()("Per
export type Error = BlockedError | CorrectedError

export function evaluate(action: string, resource: string, ...rulesets: Permission.Ruleset[]): Permission.Rule {
return (
rulesets
.flat()
.findLast((rule) => Wildcard.match(action, rule.action) && Wildcard.match(resource, rule.resource)) ?? {
action,
resource: "*",
effect: "ask",
}
)
const rules = rulesets.flat()
const isDeny = (rule: Permission.Rule) => rule.effect === "deny"
// doom_loop rules key on the tool id, so their resources are action names:
// legacy `bash` patterns must still gate the tool now published as `shell`,
// and the rename clamp applies on that dimension instead (#780).
const winner =
action === "doom_loop"
? Wildcard.winningRule(
rules,
resource,
(rule) => rule.resource,
(rule) => Wildcard.matchAction(action, rule.action),
isDeny,
)
: Wildcard.winningRule(
rules,
action,
(rule) => rule.action,
(rule) => Wildcard.match(resource, rule.resource),
isDeny,
)
return winner ?? { action, resource: "*", effect: "ask" }
}

export function merge(...rulesets: Permission.Ruleset[]): Permission.Ruleset {
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/plugin/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Guidelines:
- Adapt your search approach based on the thoroughness level specified by the caller
- Return file paths as absolute paths in your final response
- For clear communication, avoid using emojis
- Do not create any files, or run bash commands that modify the user's system state in any way
- Do not create any files, or run shell commands that modify the user's system state in any way

Complete the user's search request efficiently and report your findings clearly.`

Expand All @@ -54,7 +54,7 @@ Your output must be:
<rules>
- you MUST use the same language as the user message you are summarizing
- Title must be grammatically correct and read naturally - no word salad
- Never include tool names in the title (e.g. "read tool", "bash tool", "edit tool")
- Never include tool names in the title (e.g. "read tool", "shell tool", "edit tool")
- Focus on the main topic or question the user needs to retrieve
- Vary your phrasing - avoid repetitive patterns like always starting with "Analyzing"
- When a file is mentioned, focus on WHAT the user wants to do WITH the file, not just that they shared it
Expand Down Expand Up @@ -135,7 +135,8 @@ export const Plugin = define({
})

draft.update(AgentV2.ID.make("code"), (item) => {
item.description = "Software-engineering specialist. Runs in Git/project folders with LSP and repo-aware context."
item.description =
"Software-engineering specialist. Runs in Git/project folders with LSP and repo-aware context."
item.system ??= CODE_SYSTEM
item.mode = "all"
item.permissions.push(
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/plugin/skill/customize-opencode.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Every field is optional.

"permission": {
"edit": "deny",
"bash": { "git *": "allow", "*": "ask" }
"shell": { "git *": "allow", "*": "ask" }
},

"formatter": false,
Expand Down Expand Up @@ -237,7 +237,7 @@ Two ways to define an agent. Use the file form for anything non-trivial.
"description": "Reviews PRs for style violations.",
"mode": "subagent",
"model": "anthropic/claude-sonnet-4-6",
"permission": { "edit": "deny", "bash": "ask" },
"permission": { "edit": "deny", "shell": "ask" },
"background": false,
"prompt": "You are a strict PR reviewer..."
}
Expand All @@ -258,7 +258,7 @@ mode: subagent
model: anthropic/claude-sonnet-4-6
permission:
edit: deny
bash: ask
shell: ask
---

You are a strict PR reviewer. Focus on...
Expand Down Expand Up @@ -435,7 +435,7 @@ tokens support `{env:VAR}` interpolation (and `{file:path}`); the shell-style
```json
"permission": {
"edit": "deny",
"bash": { "git *": "allow", "rm *": "deny", "*": "ask" },
"shell": { "git *": "allow", "rm *": "deny", "*": "ask" },
"external_directory": { "~/secrets/**": "deny", "*": "allow" }
}
```
Expand All @@ -450,9 +450,9 @@ rules last.
`permission: "allow"` (a string at the top level) is shorthand for "allow
everything" and is rarely what the user wants.

Known permission keys: `read, edit, glob, grep, list, bash, task,
Known permission keys: `read, edit, glob, grep, list, shell, task,
external_directory, todowrite, question, webfetch, websearch, lsp, doom_loop,
skill`. Some of these (`todowrite,
skill`. (The shell tool was named `bash` before #780; the legacy `bash` permission key is still honored as an alias, but new config should say `shell`.) Some of these (`todowrite,
question, webfetch, websearch, doom_loop`) only accept a flat
action, not a per-pattern object.

Expand Down
26 changes: 21 additions & 5 deletions packages/core/src/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,27 @@ const layer = Layer.effect(
}),
hasStatements: () => statements.length > 0,
evaluate: EffectRuntime.fn("Policy.evaluate")(function* (action, resource, fallback) {
return (
statements.findLast(
(statement) => Wildcard.match(action, statement.action) && Wildcard.match(resource, statement.resource),
)?.effect ?? fallback
)
const isDeny = (statement: Info) => statement.effect === "deny"
// doom_loop resources are tool ids (action names), so legacy `bash`
// patterns must still gate the tool now published as `shell`, and the
// rename clamp applies on that dimension instead (#780).
const winner =
action === "doom_loop"
? Wildcard.winningRule(
statements,
resource,
(statement) => statement.resource,
(statement) => Wildcard.matchAction(action, statement.action),
isDeny,
)
: Wildcard.winningRule(
statements,
action,
(statement) => statement.action,
(statement) => Wildcard.match(resource, statement.resource),
isDeny,
)
return winner?.effect ?? fallback
}),
})
}),
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/session/context-reduction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Model } from "@opencode-ai/llm"
import type { SessionContext } from "@opencode-ai/schema/session-context"
import type { Config } from "../config"
import { Glob } from "../util/glob"
import { Wildcard } from "../util/wildcard"
import { Token } from "../util/token"
import type { SessionMessage } from "./message"

Expand Down Expand Up @@ -67,6 +68,7 @@ const STATE_CHANGING_TOOLS: readonly string[] = [
"apply_patch",
"attachment",
"bash",
"shell",
"edit",
"question",
"todowrite",
Expand Down Expand Up @@ -299,7 +301,9 @@ const protect = (messages: readonly SessionMessage.Message[], policy: Policy): P
const PATH_KEYS = ["file", "filePath", "filename", "path", "source", "target"]

const protectedTool = (tool: SessionMessage.AssistantTool, policy: Policy) => {
if (policy.protection.tools.includes(tool.name)) return true
// #780: policies may spell the shell tool `bash` and archived calls may carry the old
// name; compare canonical spellings so protection crosses the rename both ways.
if (policy.protection.tools.some((name) => Wildcard.canonical(name) === Wildcard.canonical(tool.name))) return true
if (policy.protection.files.length === 0) return false
const input = tool.state.status === "pending" ? undefined : tool.state.input
if (typeof input !== "object" || input === null) return false
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tool/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * as BuiltInTools from "./builtins"

import { makeLocationNode } from "../effect/app-node"
import { Layer } from "effect"
import { BashTool } from "./bash"
import { ShellTool } from "./shell"
import { ApplyPatchTool } from "./apply-patch"
import { EditTool } from "./edit"
import { GlobTool } from "./glob"
Expand Down Expand Up @@ -34,7 +34,7 @@ export const node = makeLocationNode({
layer: Layer.empty,
deps: [
ApplyPatchTool.node,
BashTool.node,
ShellTool.node,
EditTool.node,
GlobTool.node,
GrepTool.node,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tool/narration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export * as NarrationDetector from "./narration"
* Produced by the harness; never generated by the model.
*/
export const GUIDANCE =
"\n\n[SilverCode]\nThis command only described an intended action. It did not perform that action.\nCall the appropriate tool directly instead of using bash to narrate the action."
"\n\n[SilverCode]\nThis command only described an intended action. It did not perform that action.\nCall the appropriate tool directly instead of using the shell tool to narrate the action."

/**
* Narration-verb prefixes that indicate the model is describing an intended
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ const layer = Layer.effect(
).pipe(Layer.provideMerge(registryLayer))

function whollyDisabled(action: string, rules: PermissionV2.Ruleset) {
const rule = rules.findLast((rule) => Wildcard.match(action, rule.action))
const rule = Wildcard.winningRule(
rules,
action,
(candidate) => candidate.action,
() => true,
(candidate) => candidate.effect === "deny",
)
return rule?.resource === "*" && rule.effect === "deny"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * as BashTool from "./bash"
export * as ShellTool from "./shell"

import path from "path"
import { ToolFailure } from "@opencode-ai/llm"
Expand All @@ -17,7 +17,7 @@ import { NarrationDetector } from "./narration"
import { Tool } from "./tool"
import { Tools } from "./tools"

export const name = "bash"
export const name = "shell"
export const DEFAULT_TIMEOUT_MS = 2 * 60 * 1_000
export const MAX_TIMEOUT_MS = 10 * 60 * 1_000
export const MAX_CAPTURE_BYTES = 1024 * 1024
Expand Down Expand Up @@ -80,7 +80,7 @@ const isTimeout = (error: AppProcess.AppProcessError) =>

const shellTokens = (command: string) => command.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) ?? []
const unquote = (value: string) => value.replace(/^(['"])(.*)\1$/, "$2")
const externalCommandDirectories = Effect.fn("BashTool.externalCommandDirectories")(function* (
const externalCommandDirectories = Effect.fn("ShellTool.externalCommandDirectories")(function* (
fs: FSUtil.Interface,
command: string,
cwd: string,
Expand Down Expand Up @@ -147,7 +147,7 @@ const layer = Layer.effectDiscard(
})
const warnings = (yield* externalCommandDirectories(fs, input.command, target.canonical)).map(
(directory) =>
`Command argument references external directory ${path.join(directory, "*").replaceAll("\\", "/")}. Bash runs with host-user filesystem, process, and network authority; this scan is advisory only.`,
`Command argument references external directory ${path.join(directory, "*").replaceAll("\\", "/")}. The shell tool runs with host-user filesystem, process, and network authority; this scan is advisory only.`,
)
yield* permission.assert({
action: name,
Expand Down Expand Up @@ -216,7 +216,7 @@ const layer = Layer.effectDiscard(
)

export const node = makeLocationNode({
name: "tool/bash",
name: "tool/shell",
layer,
deps: [ToolRegistry.node, LocationMutation.node, FSUtil.node, AppProcess.node, Config.node, PermissionV2.node],
})
76 changes: 76 additions & 0 deletions packages/core/src/util/wildcard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,79 @@ export function match(input: string, pattern: string) {

return new RegExp("^" + escaped + "$", process.platform === "win32" ? "si" : "s").test(normalized)
}

/**
* Legacy permission-action aliases. The shell tool was published as "bash"
* before the rename to "shell" (#780); persisted rules, saved grants, and user
* config may still spell the action "bash".
*
* `matchAction` is plain union matching resolved by the caller's `findLast`
* (the contract the rename must preserve): a pattern matches the action if
* it matches any spelling of the tool's name, current or legacy. Canonical
* wildcards therefore keep working (`s*` names `shell` today, `ba*` still
* names it via the legacy spelling), and a legacy `bash` rule can never
* silently stop matching.
*
* The one compatibility hazard union matching creates is *recruitment*: a
* wildcard like `s*` — written when it covered `skill` — now also covers
* `shell`, and ordered after an explicit `bash: deny` it would bypass that
* deny. `recruitedByRename` identifies exactly those matches (a wildcard
* matching the canonical name but no legacy spelling; exact spellings of
* either name are never recruited), and `winningRule` applies the narrow
* clamp the issue's no-broadening contract requires: a rename-recruited
* winner cannot lift a deny that already applied under the legacy name.
* Everything else — canonical carve-outs, narrowing, explicit re-permits by
* exact name — keeps plain written-order semantics.
*/
const LEGACY_ACTION_ALIASES: Readonly<Record<string, readonly string[]>> = { shell: ["bash"] }

export function matchAction(action: string, pattern: string) {
const canonicalName = canonical(action)
const subjects = new Set([action, canonicalName, ...(LEGACY_ACTION_ALIASES[canonicalName] ?? [])])
return [...subjects].some((subject) => match(subject, pattern))
}

/** Plain pre-rename matching: does `pattern` match the action's legacy spelling(s)? */
export function matchesLegacyName(action: string, pattern: string) {
return (LEGACY_ACTION_ALIASES[canonical(action)] ?? []).some((name) => match(name, pattern))
}

/**
* Does `pattern` match the action only because of the rename — a wildcard
* matching the canonical name but no legacy spelling? Exact spellings of
* either name name the tool in whichever era they were written and are
* never recruited.
*/
export function recruitedByRename(action: string, pattern: string) {
const canonicalName = canonical(action)
if ((LEGACY_ACTION_ALIASES[canonicalName] ?? []).length === 0) return false
if (!pattern.includes("*") && !pattern.includes("?")) return false
return match(canonicalName, pattern) && !matchesLegacyName(action, pattern)
}

/**
* The winning rule for an action: plain union matching with `findLast`
* order, plus the rename clamp above. `actionPattern` extracts the pattern
* matched against the (possibly renamed) action/tool name; `restMatches`
* covers the remaining dimensions of the rule (e.g. the resource pattern);
* `isDeny` identifies deny rules. Only deny is clamped, and only when the
* union winner matched the action solely via rename recruitment.
*/
export function winningRule<T>(
rules: readonly T[],
action: string,
actionPattern: (rule: T) => string,
restMatches: (rule: T) => boolean,
isDeny: (rule: T) => boolean,
): T | undefined {
const winner = rules.findLast((rule) => matchAction(action, actionPattern(rule)) && restMatches(rule))
if (!winner || isDeny(winner)) return winner
if (!recruitedByRename(action, actionPattern(winner))) return winner
const legacyWinner = rules.findLast((rule) => matchesLegacyName(action, actionPattern(rule)) && restMatches(rule))
return legacyWinner && isDeny(legacyWinner) ? legacyWinner : winner
}

/** Canonical spelling of a tool/permission name: legacy `bash` folds to `shell` (#780). */
export function canonical(name: string) {
return name === "bash" ? "shell" : name
}
17 changes: 13 additions & 4 deletions packages/core/src/v1/config/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,25 @@ const normalize = (agent: Schema.Schema.Type<typeof AgentSchema>): Schema.Schema
if (!KNOWN_KEYS.has(key)) options[key] = value
}

const permission: ConfigPermissionV1.Info = {}
const derived: ConfigPermissionV1.Info = {}
for (const [tool, enabled] of Object.entries(agent.tools ?? {})) {
const action = enabled ? "allow" : "deny"
if (tool === "write" || tool === "edit" || tool === "patch") {
permission.edit = action
derived.edit = action
continue
}
permission[tool] = action
// #780: `tools: { bash: ... }` is the pre-rename spelling of the shell tool.
derived[tool === "bash" ? "shell" : tool] = action
}
globalThis.Object.assign(permission, agent.permission)
// Base layering: tools-derived entries first, explicit permission assigned
// over them. The only adjustment is #780's: an explicit `bash`/`shell`
// entry lands at its own written position instead of the derived slot's.
// An empty pattern map writes no rule, so it must not clear or overwrite a
// tools-derived deny.
const explicit = ConfigPermissionV1.stripEmptyShellRules(agent.permission)
ConfigPermissionV1.clearDerivedShellRename(derived, explicit)
globalThis.Object.assign(derived, explicit)
const permission = derived

const steps = agent.steps ?? agent.maxSteps
return { ...agent, options, permission, ...(steps !== undefined ? { steps } : {}) }
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/v1/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Info = Schema.Struct({
$schema: Schema.optional(Schema.String).annotate({
description: "JSON schema reference for configuration validation",
}),
shell: Schema.optional(Schema.String).annotate({ description: "Default shell to use for terminal and bash tool" }),
shell: Schema.optional(Schema.String).annotate({ description: "Default shell to use for terminal and shell tool" }),
logLevel: Schema.optional(LogLevelRef).annotate({ description: "Log level" }),
server: Schema.optional(ConfigServerV1.Server).annotate({
description: "Server configuration for silvercode serve and web commands",
Expand Down
Loading
Loading