Skip to content

fix(permissions): force each CLI's ask mode under the opt-out - #51

Merged
xergioalex merged 7 commits into
mainfrom
fix/ask-mode-explicit-flag
Nov 16, 2026
Merged

xergioalex merged 7 commits into
mainfrom
fix/ask-mode-explicit-flag

Conversation

@xergioalex

Copy link
Copy Markdown
Member

Problem

Under --ask / AGENTKIT_PERMISSIONS=ask, ak omitted the autonomy flag but never set the CLI's permission mode. An account whose own settings default to an autonomous mode still started autonomous — verified live: ak claude @work1 --ask --trust-cwd showed "⏵⏵ auto mode on"; adding -- --permission-mode default showed "⏸ manual mode on". ak pick --json reported launch.permissions: "ask" without delivering it. This blocks the herdr-peers 2.0 brain, which must launch in ask mode.

Fix

  • Explicit ask flag per CLI (providers.toml ask, run.ask for headless). {auto} expands to ask under the opt-out:

    CLI interactive ak run
    claude --permission-mode default same
    codex --ask-for-approval on-request none (codex exec takes no -a)
    grok --permission-mode default same
    cursor, opencode, pi, cline, antigravity none — no ask flag exists; omitting the autonomy flag is their ask mode none

    Values were checked against the installed CLIs (claude 2.1.325 accepts default; it documents manual too, so default works on older and newer versions; grok 1.0.77; codex 0.169.0, where resume takes -a and exec does not).

  • Mode flags after -- can't undo the opt-out. Under the opt-out, a user argument matching ask_conflicts (the autonomy flag, --permission-mode, codex -a/--ask-for-approval/--approve-for-me/-c approval_policy=…/sandbox_mode=…/danger-full-access, cursor --force/-f/--yolo/--auto-review, agy --mode, …), in either --flag value or --flag=value form, is a usage error (exit 2) and launches nothing. Under autonomy these arguments pass through as before.

  • pick-v2 delivers its claim. Under the opt-out, launch.argv ends with --ask, so the command still asks in a pane that doesn't inherit AGENTKIT_PERMISSIONS.

Interface stays 1: the ak run grammar and envelope are unchanged; only the CLI argv built under the opt-out changes.

Verification

  • permissions scope: the exact ask flag for every CLI (via --ask and via env, even with --auto); refusal for 22 conflict cases with exit 2 and no launch; the same arguments pass under autonomy; an unrelated -c model=o3 passes; every CLI declares ask, and its autonomy flag is listed in ask_conflicts; no ask flag is spelled in lib/.
  • run: headless claude/grok carry the ask flag; codex exec carries none.
  • pick-kinds: launch.argv ends with --ask, and launching that argv yields --permission-mode default.
  • Grammar scopes (dispatch, profiles) now use grammar_argv, which strips the posture segment; the permissions scope owns the posture checks.
  • Full bash tests/run.sh: 2749 passed / 0 failed / 1 skipped; public hygiene clean.

Ships in 1.5.0 together with #50.

🤖 Generated with Claude Code

Under --ask or AGENTKIT_PERMISSIONS=ask, ak left the autonomy flag out
but never set the CLI's permission mode, so an account whose own
settings default to an autonomous mode (Claude's defaultMode, Codex's
approval_policy) still started autonomous — verified live: `ak claude
@Work1 --ask --trust-cwd` showed "auto mode on". `ak pick --json`
reported launch.permissions "ask" without delivering it.

- providers.toml gains per-CLI `ask` (the explicit ask flag; [] when the
  CLI has none) and `run.ask` for headless modes that differ: Claude and
  Grok `--permission-mode default`, Codex `--ask-for-approval on-request`
  (interactive; `codex exec` takes none). `{auto}` expands to `ask`
  under the opt-out.
- `ask_conflicts` lists the flags that would set the permission mode
  (the autonomy flag included); under the opt-out a user argument after
  `--` matching one (or `<flag>=…`) is a usage error and launches
  nothing, so the opt-out cannot be undone from the tail.
- pick-v2 under the opt-out appends `--ask` to launch.argv, so the
  suggested command asks where AGENTKIT_PERMISSIONS is not inherited.

Tests: per-CLI ask flag (--ask and env), per-CLI refusal and the
autonomy passthrough, headless claude, pick argv; grammar scopes use
grammar_argv (the posture segment stripped; permissions owns it).
Full suite 2749/0/1, public hygiene clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xergioalex xergioalex added the Ready Ready for review label Nov 16, 2026
xergioalex and others added 4 commits November 16, 2026 09:50
Round two of PR #51, from the independent review:

- The refusal matched only exact tokens and `entry=` prefixes, so codex
  `--sandbox=danger-full-access`, `-sdanger-full-access`,
  `--config=approval_policy=never`, `-capproval_policy=never`,
  `-c 'approval_policy =never'` and cursor clusters (`-fw`) slipped
  through. The matcher now parses `--opt value`, `--opt=value`,
  `-o value`, `-ovalue`, and short clusters where the CLI accepts them
  (`ask_clusters`; `ask_value_opts` keeps a value such as `-pazure` from
  being read as flags). Plain words are never matched (a prompt saying
  `danger-full-access` passes) and a bare `--` ends the options.
- Stricter modes were refused (a regression from main): `ask_values`
  now allows an option only with values no looser than ask — Claude
  `--permission-mode default|manual|plan`, Grok `default|plan`, Codex
  `--sandbox read-only|workspace-write`, Antigravity `--mode plan`.
  `ask_config` refuses codex config overrides of approval_policy and
  sandbox_mode.
- kinds.py validates the new keys and forbids an ask flag on a CLI with
  standalone session modes (they return before `{auto}`).
- Tests: the bypass spellings join the refusal table, an allowed table
  covers stricter modes, unrelated options, `-pazure`, prompt words and
  `-na`; placement asserted for codex -c / -r and grok -c.
- Docs: pick-v2 schema no longer tells callers to append --ask; run.md
  notes the headless ask flag; permissions.md lists what stays allowed;
  providers.toml names Claude's `default` alias.

Full suite 2824/0/1, public hygiene clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the independent re-review of 05ccb31:

- Antigravity parses Go-style flags (`-opt` is `--opt`), so
  `-dangerously-skip-permissions` and `-mode auto` slipped through;
  `ask_single_dash_long` normalises them before matching.
- clap reads `-c=KEY=VALUE` / `-s=VALUE` as the value after `=`; an
  attached short value now drops one leading `=` (refusing
  `-c=sandbox_mode=…`, allowing `-s=read-only`).
- Codex config keys match on their last dotted segment too
  (`profiles.x.sandbox_mode`, `profiles.x.approval_policy`).
- Codex's sandbox is now pinned under the opt-out (`--sandbox
  workspace-write`, interactive and `codex exec`), so an account config
  with sandbox_mode = "danger-full-access" cannot run unprompted
  commands unsandboxed; `ask_yield` lets a stricter `--sandbox`/`-s` the
  user passes replace ak's pair (codex refuses the option twice).
- A bare `--` right after an option that may be waiting for its value is
  read as that value, not as the end of options (`--model -- <flag>`).
- Claude and Grok `dontAsk` (stricter) join the allowed values.
- kinds.py validates ask_yield and ask_single_dash_long.

Full suite 2869/0/1, public hygiene clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the round-three re-review (approved; info items taken):

- `-c sandbox_workspace_write.network_access=true` and
  `-c sandbox_permissions=[…]` widen the sandbox under the opt-out; both
  keys join ask_config, and a key now matches on any segment of its
  dotted path (profiles.x.sandbox_mode, sandbox_workspace_write.*).
- permissions.md: the pinned workspace-write sandbox also applies to an
  account configured read-only; `-s read-only` keeps it.
- run.md: codex exec's headless ask pin is named.

Full suite 2879/0/1, public hygiene clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-flag

Brings in #50 (token metering). Conflicts resolved by keeping both sides:
providers.toml keeps codex run.ask inside [clis.codex.run] ahead of the
new [clis.codex.run.tokens] table; CHANGELOG Unreleased carries Added
(token metering) then Fixed (ask mode). Full suite 2896/0/1, hygiene clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xergioalex

Copy link
Copy Markdown
Member Author

Self-review — final head e062a6a

An independent reviewer applied the vendored ai-diff-reviewer method over four rounds (79994d4 → 05ccb31 → 8e1d9ce → 984263b). e062a6a merges main, which brings in #50 token metering. The two conflicts were resolved by keeping both sides: in providers.toml, codex run.ask precedes the new run.tokens table, and the CHANGELOG lists Added before Fixed. No logic changed in the merge.

Verdict: approve. No finding at Warning or above remains.

What review rounds caught and fixed

  • r1 → 05ccb31: the refusal matched exact tokens only. --sandbox=danger-full-access, -sdanger-full-access, --config=approval_policy=… and cursor clusters (-fw) got through. It is now a structural matcher. Stricter modes (plan, read-only) are allowed again, and plain prompt words are never matched.
  • r2 → 8e1d9ce:
    • Antigravity's Go-style -dangerously-skip-permissions and -mode auto got through. Fixed with ask_single_dash_long.
    • Codex's clap form -c=KEY=VALUE and profile-scoped config keys were matched now.
    • The codex sandbox is now pinned to --sandbox workspace-write, interactively and for exec. Before, an account config set to danger-full-access would run unprompted commands with no sandbox. A stricter -s passed by the user replaces the pin, via ask_yield.
    • A -- right after an option that takes a value is read as that value.
    • dontAsk is now allowed.
  • r3 → 984263b: the sandbox-widening keys sandbox_workspace_write.* and sandbox_permissions are now refused; a key matches on any segment of its dotted name.

Every CLI flag value was checked with --help against claude 2.1.325, codex 0.169.0, grok 1.0.77 and agy 1.5.9. No session was started and no model quota was spent.

Gates

  • Full bash tests/run.sh on the merge: 2896 passed / 0 failed / 1 skipped.
  • Public hygiene: clean.
  • permissions scope: 370 checks. They cover the ask flag per CLI and its placement, 33 refusal spellings, 21 allowed cases, the yield behaviour, and confirm that the flags appear only as data.

Known and accepted

  • A few harmless false refusals remain: --verbose -- <flag> (documented), cursor -wf, codex -c sandbox_mode=read-only.
  • The workspace-write pin also applies to an account configured read-only. Passing -s read-only keeps it read-only; this is documented.

From p2M's second read of the ask semantics:

- Claude: --allowedTools/--allowed-tools ('Bash(*)'), --settings (a file
  or JSON whose permissions.allow or defaultMode loosens) and
  --permission-prompt-tool (hands approvals to a tool that can say yes)
  pre-approve without touching --permission-mode; all refused under the
  opt-out. --permission-prompts is allowed only as `none`.
  --disallowedTools (stricter) stays allowed.
- Grok: --allow and its aliases --allowedTools/--allowed-tools refused.
- docs/permissions.md: for CLIs without an ask flag (cursor, opencode,
  pi, cline, antigravity) ask is the CLI's default, assumed not forced;
  `dontAsk` denies silently, so a caller expecting prompts sees denials.

Full suite 2938/0/1, public hygiene clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xergioalex

Copy link
Copy Markdown
Member Author

Self-review update for final head ca7e87c

Verdict: approve. This head adds one fix on top of the approved e062a6a. It comes from p2M's second read of the ask semantics: the opt-out could be bypassed through pre-approvals, without changing the mode at all.

What is refused now under the opt-out

  • Claude: --allowedTools / --allowed-tools, --settings and --permission-prompt-tool.
  • Claude --permission-prompts: only none is allowed.
  • Grok: --allow and its aliases.
  • Still allowed: --disallowedTools, which is stricter.

Docs

  • CLIs without an ask flag keep their own default. Ask is assumed for them, not forced.
  • dontAsk denies silently.

Delta review

  • Every flag was checked against claude 2.1.325 and grok 1.0.77.
  • The merge did not damage the ask code paths.
  • Refusing --settings outright is a deliberate choice: ak refuses the flag rather than parsing its JSON.

Gates

  • Full bash tests/run.sh: 2938 passed / 0 failed / 1 skipped.
  • Public hygiene: clean.
  • The independent reviewer ran on a git archive export: permissions 412/0, run 85/0, contract 63/0.

Release order (pF): v1.5.0 is tagged only after herdr-peers 2.0.2 (#59). That release accepts the trailing --ask that 1.5.0's pick-v2 launch.argv now carries under the opt-out.

macOS CI failed twice in a row on ca7e87c (and twice on #45, once on
#50) at the same pre-existing check: "the fake usage endpoint did not
start (no port after 30s)" — the server's stderr was discarded, so a
slow start and a crash looked the same. usage_server_start now keeps
the server's stderr, stops waiting as soon as the process is gone,
retries the start once, waits up to 60s per attempt, and puts the
stderr tail in the failure message. Test-only; no runtime change.

Full suite 2938/0/1, public hygiene clean, shellcheck clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xergioalex

Copy link
Copy Markdown
Member Author

Self-review: final head a965551 (test harness only)

Verdict: approve, unchanged. The only change since the approved ca7e87c is in tests/lib.sh; there is no runtime change.

Why: the macOS suite failed twice on ca7e87c at the same check that also failed on #45 and #50: "the fake usage endpoint did not start (no port after 30s)". The server's stderr was discarded, so a slow start and a crash looked identical.

Now usage_server_start:

  • keeps the server's stderr;
  • stops waiting as soon as the process exits;
  • retries the start once, waiting up to 60s per attempt;
  • prints the tail of stderr in the failure message.

Gates: full suite 2938/0/1, public hygiene clean, shellcheck clean.

@xergioalex
xergioalex merged commit ba88f71 into main Nov 16, 2026
11 of 12 checks passed
@xergioalex
xergioalex deleted the fix/ask-mode-explicit-flag branch November 16, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant