Skip to content

feat: remote-tool confirmation card in the chat; confirmer on interactive turns (#4291, 3/3) - #4321

Merged
mstomar125 merged 6 commits into
mainfrom
issue-4291-confirm-card
Nov 20, 2026
Merged

mstomar125 merged 6 commits into
mainfrom
issue-4291-confirm-card

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Part 3 of 3 of the remote-tool confirmation wiring (#4291; user ruling 2026-11-20: the confirmation is an in-chat card, answered in the same turn, default No). With this, a tool-cli / tool-mcp tool (and a non-GET or credentialed tool-rest tool) is offered to the model on an INTERACTIVE turn, and each call asks the user on a card in the chat.

Agent lane. This touches packages/agent (Michael's lane), the daemon, core's schema and the desktop app. The user's sign-off for the #4291 remote-tool build stands in for Michael's.

Docs first: the node-types.md sheet is docs PR https://github.com/NodeSpaceAI/nodespace-docs/pull/167. node-types:check reads the docs commit, so that PR merges just before bun run merge of this one. node-types:check passes here against that branch.

What it does

  • Schema (minimal). ai-chat-message gains the part kind confirmation and five optional fields: confirmation_id and confirmation_digest (device-local, so another device never sees them), confirmation_status (pending | allowed | denied | expired | cancelled, closed enum), confirmation_arguments (the arguments JSON, whole), confirmation_credentials (references only). A behavior rule keeps the confirmation fields on a confirmation part of an assistant message. Shape record regenerated with a change-log entry (class refuse: an older database is refused until reset), TypeScript regenerated.
  • Daemon. ChatCardUi writes the card as a message at the end of the chat, so it sits after the user's message and before the reply the turn writes when it ends, and sets its status once when the question ends. The card is never part of the conversation the model sees (message_nodes leaves it out of the history and out of "whose turn is it", so a pending card cannot hide the user's message from recovery). A turn's unanswered questions are dropped, and their cards ended, however the turn ends (a guard, a dropped future included); a card left pending by a restart is cancelled during recovery. ConfirmationRequest now also carries the credential references (credential_references: NAME from keychain:x, bearer from env:Y; references only, bounded).
  • Installed on interactive turns only. confirmer_for_turn returns a confirmer only for a turn started by a message the user wrote. A turn recovered after a restart gets none, so a tool that needs confirmation is not offered there. (There is no scheduled/headless chat turn today; if one is added it must pass interactive = false.)
  • Frontend. RemoteToolConfirmationCard, rendered by the native chat viewer in place. It shows: the credentials on their own line from the separate field, always visible; the whole summary (destination) as plain text; the arguments cut to a preview with an expander that shows all of them and their real size in bytes; control, bidi, zero-width, line/paragraph-separator, tag and variation-selector characters shown as visible escapes in BOTH the summary and the arguments through one function (toDisplaySafe, with a shared test vector of one character per class). Two choices in NodeSpace's own words: "Don't allow" (focused when the card appears; Escape and Enter do it) and "Allow once"; allowing is never remembered. A pending card is a live region. It answers at most once.
  • The answer carries the daemon's request id and digest from the card, unchanged (never recomputed) through a new Tauri command local_agent_answer_confirmation. Before the buttons are enabled the card recomputes the digest of what it SHOWS (length-prefixed SHA-256, same as the daemon, with shared vectors) and compares it with the daemon's, and checks that the credential line's references appear in the summary: a card whose text was changed after the daemon wrote it cannot be answered.
  • Other devices. The id and digest are device-local, so another device shows the card as a record ("Waiting on the device that is running this chat") with no choices. Resolved cards show what was asked and how it ended.

Folded in from the #4320 review

spawned::record(pid, leads_own_group): a program started with its own group (process_group(0), or a PTY child) has its group recorded as its pid unconditionally, even if it is gone before the kernel can be read; a program sharing the daemon's group is recorded by pid only, never by group. A real-process test pins that the daemon's group is not recorded (an unrelated same-group process and the test process stay "not a tool"), which is the regression that would refuse the tray-spawned UI. Module docs and this body state the notes: the setsid/setpgid-with-parent-exit limit (the fix is the macOS audit token + code-signature check, a follow-up); the card's id and digest are stored in the chat node, so any same-user tool can read them (nodespace get): the id is not a secret from tools and the peer gate is the only barrier; a UI started from the in-app PTY terminal or by an ACP agent descends from a recorded program and is refused (fail closed, acceptable).

Review round 1 (fixes)

  • What "interactive" means, plainly. A turn is interactive when it starts from a trailing user message on a native chat. Anyone who can write that node (the CLI, MCP, a sync peer, scripts/aichat.ts) starts a turn with the confirmer installed. The real gate is the human click through the app's Tauri command plus the peer gate on the answer RPC, not "who started the turn". A recovered turn is not interactive: TurnOrigin::{UserMessage, Recovered}, with is_interactive pinned by a test.
  • Release order: docs Add end-to-end integration tests for node reference autocomplete flow #167 -> core feat: remote-tool confirmation card in the chat; confirmer on interactive turns (#4291, 3/3) #4321 -> core TAG -> sync re-pin to the TAG commit. Until the re-pin, a sync daemon on the old pin pushes confirmation_id / confirmation_digest to peers: no security impact (a peer's tables do not know those fields) but a peer shows a card it cannot answer.
  • Credential check bug (failed closed). The credential line lists up to 32 references; the summary lists the first 8 and "and N more", and cuts a REST reference differently. The card now checks the first 8 against the summary (the start of each reference) and, when there are more, that the summary says exactly "and N more". Tests: 9+ credentials, a 300+ byte reference; a Rust test that credential_references and environment_note agree.
  • Resolved wording. "You allowed this call. Whether it ran is in the reply below." (the call can still be refused after the yes: the tool changed, the runner failed). Pinned by a test.
  • Shared vectors in Rust. The two digest constants are pinned in Rust; every character of the card's unsafe vector is is_unsafe_for_log; the card's content is exactly the summary and its digest recomputes. Both sides now also cover U+00AD, 034F, 115F/1160, 17B4/17B5, 2061-2064, 206A-206F, 3164, FFA0, FFF9-FFFC and 1D173-1D17A. The card's summary, preview, credentials and full arguments are dir="ltr" with unicode-bidi: isolate.
  • Enable delay and focus. The choices are enabled 500 ms after the card is shown and intact (a stray click cannot answer it; Escape too). Focus goes to "Don't allow" once, when the choices arm; a re-render does not take it back, and a card that cannot be answered never takes focus.
  • Restart. At startup every pending card this daemon wrote (it has a confirmation_id) is cancelled in EVERY native chat, not only stuck ones; a peer's card (no id) is left alone. A status write retries 8 times with backoff.
  • Forged cards, stated truthfully. The agent's create_node and update_node now refuse any conversation record (a chat, a message, or a subtype of a message) so an injected agent cannot write one through its own tools; the daemon's own writer is unaffected. This does NOT make a forged card impossible: recorded tool processes can still write nodes through the CLI / gRPC socket (generic node create and update are not gated), and the card only checks that confirmationId is PRESENT ({:else if !requestId}), not that this daemon issued it. A forged card with any made-up id, or a copy of a real one, renders "You allowed this call. Whether it ran is in the reply below." The forgery is COSMETIC: a forged pending card cannot be answered (the daemon refuses an unknown id), and nothing reads a card's status to grant any capability. The id-less branch ("A question recorded on another device.") protects against a PEER's card only once Sync declares these fields local-only (see the release order). Not done: the daemon exposing which ids it issued.
  • Tests, second pass. The two timing mutants that survived are killed by fake-timer tests: the choices are disabled and an activation answers nothing until the 500 ms delay has passed with the card already intact, then exactly one answer; and focus is not taken back to "Don't allow" when the card re-checks itself with new text (the choices are disabled during the re-check, which drops focus to the page, so the assertion is that focus is not re-stolen). The daemon tests were re-run after cleaning the shared target (a stale nodespace-proto / nodespace-core artifact from another worktree had broken the build): cargo test -p nodespace-daemon --lib -- chat_card only_a_turn passes (12 tests, named in the run); the startup-cancel / peer-card-left-alone and recovered-origin mutants are killed by real failing assertions. A recovery INTEGRATION test (a recovered stuck turn gets no confirmer) is not added: the host reads the real keychain for its approval key, so a test cannot make a remote tool offerable; the call site maps Recovered to a non-interactive turn and the mapping is pinned by TurnOrigin::is_interactive.
  • Subtypes and spellings. refuse_conversation_record also refuses a subtype of ai-chat-message (type_is_a); a case or whitespace variant of the type name is refused as unknown (tested). A subtype-creating test is not written (it needs a schema extending the message type).
  • Smaller. ChatCardUi::present is documented as not cancel-safe between the write and remembering the id (the turn's end and the next start end such a card as cancelled); the card sits in a role="listitem".
  • Tests that run (asked to confirm). cargo test -p nodespace-agent --lib -- spawned::tests::real_processes the_credential_references lists and passes: a_program_sharing_the_daemons_group_does_not_make_that_group_a_tools, a_program_that_leads_its_group_is_recorded_even_if_it_is_gone_before_it_can_be_read, the_credential_references_of_a_binding_are_listed_without_values (plus the new ones above).
  • A 0.3.11 database. It is refused at open with "NodeSpace does not migrate databases between versions: move this database aside and start with a fresh one" (SchemaMismatch's message, naming the missing fields).

Verified

  • Rust: new tests for the card writer (fields, status once, every ending, a missing chat, order before the reply, history and recovery ignore it, cancel pending only), a question asked through the real confirmer and answered with what the card carries, the interactive-only confirmer, the behavior rule, credential references, the schema field list. clippy clean.
  • Frontend: 11 unit tests (display-safe vector, digest vectors, credential check, preview), converter and Tauri command tests, the viewer test (card in place, once, not a message), and 21 tests in real Chromium (credentials line, whole summary, size, focus on Don't allow, Allow/Escape/Enter send the daemon's id and digest once, a forced second activation is ignored, failed and unaccepted answers, a changed summary / arguments / credential line cannot be answered, another device's card and an id-without-digest card are records, expander, escapes, every resolved state, role alert). Light and dark screenshots checked by eye in Chromium with the app stylesheet.
  • Gates: quality:fix, test:changed (types:check, shape:check, node-types:check against the docs branch, rust:test 232 s) pass.
  • Mutants, one batch (Rust 11, frontend 15): history filter, interactive check, status-once, cancel-only-pending, insertion position, summary content, digest field, credentials field, behavior rule, group flag; display-safe function, digest length prefix, credential check, digest recompute-and-refuse, default focus, digest required, "Allow" always sent, Escape, once-guard, summary/arguments escaping, card-as-message filter, converter. All killed except three that are equivalent or covered twice (the cancel-only-pending filter is doubled by the status-once guard; the group flag: the mutant only records an empty group, the real regression is pinned by the shared-group test; the card-as-message filter in the viewer is redundant with the timeline, kept as defence).

NOT verified live

The full path in the real app (Tauri UI -> gRPC -> daemon peer gate -> a model-driven tool call -> card -> answer) was not run: the run-app skill says a scratch launch still replaces the user's per-user launchd job and shares the webview storage, and a tool call needs a model (none loaded). To check by hand: launch with HOME and NODESPACE_HOME both set to one scratch directory, create a tool-cli node (e.g. echo) in that scratch database, enable and approve it on this device, ask a question that makes the model call it, and confirm the card appears in the chat, "Don't allow" is focused, Allow runs it once, a second answer finds nothing, and the card shows the outcome; then check ~/.nodespace gained nothing. The enable-and-approve command is a separate later PR, so approval is written with the existing device key for now.

🤖 Generated with Claude Code

mstomar125 and others added 6 commits November 20, 2026 12:34
…onfirmer, frontend card (local, not pushed)

Remaining: rebase onto the fixed #4320 head and then origin/main; run quality:fix, shape/types/node-types checks, test:changed; mutation batch; PR body.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d cards, restart cancel, shared vectors)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-4291-confirm-card branch from 4ee2218 to 35dcc76 Compare November 20, 2026 11:34
@mstomar125
mstomar125 merged commit 09609dc into main Nov 20, 2026
@mstomar125
mstomar125 deleted the issue-4291-confirm-card branch November 20, 2026 11:34
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.

1 participant