Repository navigation
feat(tui): opt-in persistence and agent visibility for !/!! local shell commands - #103648
fluffyxenia wants to merge 20 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 1:41 PM ET / 17:41 UTC. ClawSweeper reviewWhat this changesThis PR adds consent-gated persistence for TUI-local shell output: Merge readiness⛔ Blocked until stronger real behavior proof is added - 12 items remain Keep this PR open for maintainer product direction rather than cleanup. Current Priority: P2 Review scores
Verification
How this fits togetherThe TUI launches operator-approved local shell commands and displays their output immediately. This PR would additionally send the result through a hidden Gateway RPC into the session transcript, which controls replay on resume and model context on later turns. flowchart LR
Operator[Operator enters ! or !! command] --> TUI[TUI local shell]
TUI --> Consent[Per-session consent]
Consent --> RPC[Hidden Gateway RPC]
RPC --> Transcript[Session transcript]
Transcript --> Replay[TUI resume replay]
Transcript --> Context[Next model context]
Decision needed
Why: The patch adds a new operator consent flow, persistent transcript behavior, model-visible local-machine output, and a Gateway method; implementation correctness cannot decide whether that product and security boundary belongs in core. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +578, Tests +847, Other +47. Total +1472 across 33 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: After explicit sponsorship of the local-shell sharing contract, rebase onto current main, add a stable per-command injection identity, make the canonical transcript owner support the first shared command, and post redacted real behavior proof from the rebased head. Do we have a high-confidence way to reproduce the issue? No high-confidence current-head live reproduction is available. Source inspection does establish two deterministic paths: retries lack an identity to deduplicate the write, and a fresh session returns an actionable persistence error instead of saving the first shared command. Is this the best way to solve the issue? No: the current patch is a plausible implementation, but it should use the canonical current-main transcript persistence shape, provide retry identity, and handle fresh-session creation before maintainers accept the product contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5118b0b915c0. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (17 earlier review cycles; latest 8 shown)
|
|
Proof of behavior, from the committed PTY e2e test (
Terminal excerpt from the passing run (ANSI control sequences stripped; fixture data only): Additional hardening landed while producing this proof:
🤖 Generated with Claude Code |
4dcf642 to
4959742
Compare
4959742 to
f489310
Compare
e4a409f to
4284528
Compare
|
On the open product question (whether The motivating problem is straightforward: today a To be clear, this isn't an attempt to copy any particular client. That said, it's fair to note the pattern is already proven elsewhere: Claude Code's Where this PR deliberately goes further on safety than that precedent:
Happy to adjust semantics/naming if maintainers prefer a different shape; the mechanical layers (transcript role, RPC, consent UI) are largely shape-agnostic. |
4284528 to
ab1a792
Compare
… tail The legacy-order guard pins the last five core method names; appended methods must update the window, same as upstream appends do.
…stream truncation
…ce hits a fresh session
7a293b5 to
140bffa
Compare
Gateway-backed behavior proof — sharing, resume replay, cross-agent isolationEvidence recorded against head Setup — no mocks anywhere in this run:
Formatting disclosure: captures are verbatim except trailing whitespace stripped, consecutive blank lines collapsed, and unrelated conversation/tool sections removed behind explicit 1. Consent gate +
|
| command | persisted excludeFromContext |
submitted as |
|---|---|---|
uname -a |
false |
! |
echo test |
true |
!! |
pwd |
true |
!! |
uname -r |
false |
! |
openclaw --version |
false |
! |
Every row matches the observed agent-visibility behavior in the captures (this query also corrected one operator misremembering — the data is the attestation, not memory).
One semantics nuance found during this verification, disclosed for the product decision: excludeFromContext is context hygiene, not confidentiality. A !! row is excluded from the model's context assembly (proven by the recall answers above), but it remains a session-history row — and an agent that explicitly queries history via the sessions-history tool can see it (observed: the agent's history tool result listed the !!pwd row even as its context-based recall correctly omitted it). The consent prompt originally said "!! stays history-only", which under-communicated this; the branch now words it explicitly: "!! skips the model's context but stays in history the agent can query." If maintainers want hard exclusion from agent-facing history projections too, that's a separate decision — filtering agent-visible history diverges user-visible and agent-visible history views, and the local shell runs on the TUI host either way (anything truly secret shouldn't be typed into an agent client's composer at all).
3. Same-key cross-agent isolation — the P1 finding, reproduced against the fix
The exact P1 shape: session key global (the literal shared key, preserved across agents), share approved under agent main, then agent switched. Five sequential frames; note the header line in each — the session key stays global while the agent changes:
Frame 1 — agent main, session global, consent prompt, selecting share:
openclaw tui - ws://127.0.0.1:18789 - agent main - session global
session global
...
agent main | session global | openrouter/deepseek/deepseek-v4-flash | think high | tokens ?/200k
No
Yes, local only
→ Yes, and share with the agent
Frame 2 — share approved under main; command runs (persistence fails loudly because this fresh session has no completed turn yet — see note below):
local shell: enabled; output is saved to history and `!` output is shared with the agent
[local] $ uname -r
[local] 6.12.75+rpt-rpi-v8
[local] exit 0
[local] not saved to session history: session has no history yet; send the agent a message first
Frame 3 — /agent test (the TUI hops to that agent's own main session; getting back onto the shared key requires an explicit /session global):
session agent:test:main
agent set to test; use /crestodian to return
Frame 4 — agent test, session global again → fresh consent prompt instead of inherited approval:
openclaw tui - ws://127.0.0.1:18789 - agent test (test) - session global
session global
Allow local shell commands for this session?
...
agent test (test) | session global | openrouter/openrouter/auto | tokens ?/200k
No
→ Yes, local only
Yes, and share with the agent
Frame 5 — test answers "Yes, local only"; the command runs and no persistence is attempted (no [local] not saved line, no injected row — local-only means local-only):
local shell: enabled for this session (local only)
[local] $ uname -a
[local] Linux rpi4 6.12.75+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.75-1+rpt1 (2026-03-11) aarch64 GNU/Linux
[local] exit 0
Before the consent-key fix (ab1a792), frame 4 would not have prompted: agent test would have silently inherited main's share approval on the same global key. The regression test for this lives in src/tui/tui-local-shell.test.ts ("re-prompts when a different agent uses the same session key").
An additional capture (not shown) demonstrates the prompt also re-fires across per-agent sessions (agent:test:main after switching from main's session).
Note on frame 2: a session with no completed first turn has no durable transcript entry; persistence into it fails visibly rather than silently dropping the row (same precondition as the existing chat.inject). The actionable message shown in the frame replaced a confusing session not found — a rough edge found and fixed while gathering this evidence (now commit 6662539037 after the rebase).
Summary of what these captures cover: consent gate before first execution; ! output visible to the agent through real Gateway transport with live inference; !! excluded from model context while remaining in history; persisted rows replayed after full TUI restart and queryable via session history; consent never persisted across restarts; share approval not inherited across agents on the same global session key; local-only consent attempts no persistence; fail-visible behavior when the first-turn precondition isn't met.
The branch has since been rebased onto current main (the recurring additive-tail conflicts in the gateway method table / protocol index, plus upstream's chat.ts modularization). Delta between evidence head 7a293b5c35 and the current head: upstream integration, the consent-prompt wording update described above, and a Kotlin protocol-enum regeneration — no behavior change to the feature paths shown here. The captures display the pre-update consent wording because that is what was on screen when they were recorded.
…hanged-file LOC ratchet
…orker-json extraction
…y the test-local mock
121124f to
0f45550
Compare
- record a segment boundary for replayed tool calls even when verbose is off, so a turn's later cumulative text cannot rewrite pre-tool text in place on the default resume path; replay now routes through the same activity-summary path a live verbose-off run uses - truncate the combined tool-card header to the render width (ANSI-aware) instead of letting it wrap and break the condensed card layout - drop the bashExecution history-replay branch: shell persistence and its replay rendering belong to the persistence PR (openclaw#103648)
|
This pull request has been automatically marked as stale due to inactivity. |
|
Not stale — still fully green (CI including mobile), just parked awaiting a maintainer review pass. Real-terminal and gateway-backed proof are already posted above (head |
|
Following up on the sponsorship question ClawSweeper flagged above:
Not asking for a code re-review here — I know the branch is stale against current If the direction is "yes, sponsor it" I'll do the rebase, fix the idempotency and fresh-session issues, and post fresh current-head proof. If it's "no" or "not now," happy to close it out — just don't want it sitting in limbo indefinitely on either side. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
What Problem This Solves
TUI-local
!-prefixed shell commands render a live local echo but are never persisted: closing the TUI loses them, session resume never shows them, and the agent cannot see what the operator ran or what it printed — even though theBashExecutionMessage/excludeFromContextdata model and the LLM-context filtering for it already exist inpackages/agent-core(previously unused by any production code path).Split out of #103147 per review feedback there; that PR now carries only the rendering fixes.
Why This Change Was Made
Operators often run a
!command specifically to show the agent something (Claude Code's own!behaves this way). But local shell output can also be sensitive, so persistence and model visibility must be a deliberate choice, not a silent default:!cmdpersists agent-visible (the agent sees it on its next turn) and!!cmdpersists history-only (excludeFromContext: true, never reaches the model). Both semantics are stated in the consent prompt itself.Implementation: an additive, hidden (
advertise: false,operator.admin)chat.injectBashExecutiongateway RPC modeled onchat.inject, implemented in both TUI backends (embedded calls the shared core directly in-process; gateway goes over the RPC). No live broadcast: the originating client already rendered its own local echo. History replay rendersbashExecutionentries on session resume.Two defects found during review/testing are fixed here as well:
errorandclose; a shared settled-guard ensures one command persists at most once.appendMode: "side"(likechat.inject's assistant bookkeeping rows) so they do not steal the run's active leaf. Without this, persisting a!result mid-run tripped the embedded runner's session-file fence ("session file changed while embedded prompt lock was released") and killed the run. The run adopts side entries into the chain on its next append, so the agent still sees them next turn.User Impact
!commands stay local-only unless the operator opts into sharing at the consent prompt.!output survives session resume and is visible to the agent next turn;!!output survives resume but never reaches the model.!command while the agent is mid-turn no longer kills the run with a session takeover error.Evidence
src/tui/tui-local-shell.test.ts— 12 tests: consent options (local-only default persists nothing; share option persists),!vs!!excludeFromContextround-trip, no-scope/no-backend skips, persistence-failure surfacing, once-only persistence on error-then-close, plus the pre-existing output-cap/UTF-16/cwd guards.src/gateway/server-methods/chat.inject-bash-execution.test.ts— parentId chain preserved,excludeFromContextround-trip, mid-run side-append regression test (fence takeover repro), idle active-append, unresolved-identity failure.src/tui/gateway-chat.test.ts,src/tui/embedded-backend.test.ts— both backend implementations (RPC params/result shapes; embedded in-process delegation and failure surfacing).src/gateway/server-methods-list.test.ts— hidden method not advertised, handler dispatchable.src/tuisuite green locally; protocol schema regenerated (pnpm protocol:gen/protocol:gen:swift— Swift models committed).!/!!visibility split, restart replay, same-key cross-agent isolation, and storage-levelexcludeFromContextverification — feat(tui): opt-in persistence and agent visibility for!/!!local shell commands #103648 (comment) (recorded on head7a293b5c35; later heads carry the LOC-ratchet modularization, proof-artifact cleanup, and consent-wording update — no feature-path behavior change).!vs!!behavior: to follow in a comment.🤖 Generated with Claude Code