Skip to content

feat(gateway): hard-enforce read-only tools for plan/review mode (P4b gateway)#79

Merged
LightDriverCS merged 2 commits into
mainfrom
aurelius/console-p4b-gateway-tools-mode
Jun 21, 2026
Merged

feat(gateway): hard-enforce read-only tools for plan/review mode (P4b gateway)#79
LightDriverCS merged 2 commits into
mainfrom
aurelius/console-p4b-gateway-tools-mode

Conversation

@Agent-Aurelius

Copy link
Copy Markdown

Intent

Pair PR for the Aurelius Command Console agency mode selector. Plan/Review must hard-restrict the agent to read-only tools at the gateway — not self-honor.

Mechanism

  • /v1/chat/completions (openai-http.ts) reads the x-openclaw-tools-mode header (forwarded by relay-v3 from the operator's mode pick).
  • plan / reviewtoolsAllow = SAFE_READ_ONLY_TOOLS (read, web_search, web_fetch, x_search, memory_search, memory_get).
  • ask / auto / absent / unknown → no restriction (full toolset).
  • toolsAllow threads through buildAgentCommandInputagentCommandFromIngress (AgentCommandIngressOpts already carries toolsAllow) and is enforced by the embedded runner's runtime allow-list (run/attempt.ts "runtime toolsAllow", enforceWhenToolsDisabled: true).

Surfaces touched (17 lines)

  • talk/agent-consult-tool.tsexport SAFE_READ_ONLY_TOOLS (single source of truth).
  • gateway/openai-http.ts — read header → compute toolsAllow → thread via buildAgentCommandInput.

Low-risk

  • No effect unless the header is present — existing traffic unchanged; safe to deploy independently of the mono PR.
  • Reuses the already-enforced toolsAllow lever (same mechanism as realtime-voice consults).

Pairs with

  • mono aurelius/console-p4b-mode (mode selector UI + relay x-openclaw-tools-mode header).

Deploy / verify (operator-coordinated)

  • Gateway runs from a worktree dist → needs a dist rebuild + restart (durability hazard) + rollback. Could not build the full gateway locally; typecheck/build is the gate at the coordinated build.
  • Smoke after deploy: console Plan mode → ask to write a file/send a message → tool refused; Auto → tools work.

Follow-ups

  • ask true per-action approval (today ask = full tools).
  • Optional: mirror on the control-UI chat.send path.

Agent-Aurelius and others added 2 commits June 19, 2026 23:29
The Aurelius Command Console exposes Ask/Auto/Plan/Review agency modes; Plan and
Review must HARD-restrict the agent to read-only tools (not merely self-honor).

The /v1/chat/completions ingress now reads the `x-openclaw-tools-mode` header
(forwarded by relay-v3 from the operator's mode pick). For plan/review it sets
`toolsAllow = SAFE_READ_ONLY_TOOLS` on the agent command input; AgentCommandIngressOpts
already carries `toolsAllow`, which the embedded runner enforces as the runtime
tool allow-list (run/attempt.ts "runtime toolsAllow"). ask/auto (and absent/unknown)
leave the full toolset.

- agent-consult-tool.ts: export SAFE_READ_ONLY_TOOLS (single source of truth;
  previously used only for voice consults).
- openai-http.ts: read the header → compute toolsAllow → thread through
  buildAgentCommandInput → agentCommandFromIngress.

Pairs with the mono-repo console PR that sends the header. No effect unless the
header is present, so safe to deploy independently.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@LightDriverCS
LightDriverCS marked this pull request as ready for review June 20, 2026 06:14
@LightDriverCS
LightDriverCS merged commit 54ffe28 into main Jun 21, 2026
193 of 194 checks passed
Agent-Aurelius added a commit that referenced this pull request Jun 23, 2026
…82)

These power the Aurelius web console under ultracode but were running ONLY as
uncommitted floating patches on the live detached gateway worktree (backed up at
origin/backup/gateway-patches-2026-06-22), NOT on main:
- C1: salvage clean assistant text from leaked raw Claude-CLI stream-json
  (salvageClaudeStreamJsonText in agent-event-assistant-text.ts, applied in
  writeAssistantContentChunk).
- C3: bridge a native AskUserQuestion into the console's openclaw_ask_choice card
  (buildAskChoiceFromArgs + request-scope blob buffering in the
  /v1/chat/completions handler) + extractAskUserQuestionFromClaudeStreamJson.

Merged onto current main (#81); #79's read-only-tools enforcement is preserved
(additive, different code paths). agent-event-assistant-text.ts + cli-runner/
execute.ts were untouched by main so taken whole; openai-http.ts merged
(import superset + salvage in writeAssistantContentChunk + the ask_choice bridge).

Companion to the gateway durability reconcile: once merged, both live gateways
rebuild from this main commit and stop running uncommitted detached patches.

Co-authored-by: Aurelius <[email protected]>
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.

2 participants