From 85c411c82c5a98c5da4a7ac0b8429a5dcd87e8ee Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 07:05:11 +0000 Subject: [PATCH 1/5] feat(spec)!: a declared-gated action on an AI door is confirmed by a person through MCP elicitation The action-confirmation contract is amended: for an action declaring ai.requiresConfirmation: true, invoked through the MCP run_action or resume_run tool, the server elicits the person's confirmation from a client that advertised elicitation at initialize. A client without it is refused, the caller's own confirm member never counts, and an AI service account is refused as before. Each elicitation answer and its refusal reason is stated. Contract only: the doors implement it in the next change. Claude-Session: https://claude.ai/code/session_01FEkQ5kZuoX9F5S7p84Dwue Co-Authored-By: Claude --- .../33689-ai-action-confirmation-elicited.md | 29 ++++ packages/spec/api-surface/contracts.json | 3 + packages/spec/export-origins/contracts.json | 3 + .../action-confirmation-contract.pin.test.ts | 100 +++++++++++ packages/spec/src/contracts/ai-service.ts | 162 ++++++++++++++++++ ...8.action-requires-confirmation-elicited.ts | 39 +++++ 6 files changed, 336 insertions(+) create mode 100644 .changeset/33689-ai-action-confirmation-elicited.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts diff --git a/.changeset/33689-ai-action-confirmation-elicited.md b/.changeset/33689-ai-action-confirmation-elicited.md new file mode 100644 index 00000000000..eda5c34b36c --- /dev/null +++ b/.changeset/33689-ai-action-confirmation-elicited.md @@ -0,0 +1,29 @@ +--- +'@objectstack/spec': minor +--- + +feat(spec)!: a declared-gated action on an AI door is confirmed by a person through MCP elicitation, never by the caller's own `confirm: true` + +Clause-②: yes (narrowing) — the contract stops counting a caller's `confirm: true` on an action declaring `ai.requiresConfirmation: true` and refuses an MCP client that did not advertise `elicitation`; `@objectstack/spec/contracts` gains `AI_ACTION_CONFIRMATION_CAPABILITY`, `ACTION_CONFIRMATION_REFUSAL_REASONS`, `ActionConfirmationRefusalReason` and the optional `ActionConfirmationRequiredDetails.reason`. +Metadata-protocol: semantic +Skills-docs: follow-up — `skills/objectstack-ai/SKILL.md` (the MCP tool table: `run_action` / `resume_run` "refused with the same 428 unless the call sends `confirm: true`") teaches the member contract; it moves with the change that implements the doors, together with the MCP-served skill text (`packages/mcp/src/skill-md.ts`, `ui/apps/console/src/pages/developer/objectstack-skill.ts`) and the `ToolSchema` prescription in `packages/spec/src/ai/tool.zod.ts`, which describe the door that runs today. + + + +**BREAKING** for an MCP client, an agent or a script that runs an action declaring `ai.requiresConfirmation: true` through `run_action` or `resume_run` by sending `confirm: true` itself. Ruled by the account owner: 「3826 照建议(征询版)」. + +The contract in `@objectstack/spec/contracts` (`AI_ACTION_CONFIRMATION_CAPABILITY`, `contracts/ai-service.ts`) now says: + +- The server asks the person: after every other gate passes and before anything runs, it sends one MCP `elicitation/create` request (form mode) to the client the call arrived on, naming the action, the object and the record. +- The door reads the `elicitation` capability the client sent at `initialize`. A client that did not advertise it is refused with `428 ACTION_CONFIRMATION_REQUIRED` and `details.reason: 'elicitation_unsupported'`; the message tells the person to use a client that supports confirmation, or to act in the app. +- `accept` runs the call once, under the caller's permissions, and nothing is stored for the next call. `decline`, `cancel` (an error answer or a dropped connection included) and no answer within the door's bound are refused with reason `declined`, `cancelled` or `timed_out`, and nothing runs. +- The caller's `confirm` never counts on such a call, with or without an elicitation. +- An AI service account acting for itself is refused whatever it sends, unchanged (ADR-0151 D3 rule 3), now with reason `service_account`; no elicitation is sent to it. +- Outside the amendment: the MCP `delete_record` and `delete_records` gates still read `confirm: true`, and REST `/actions` stays outside the gate for a person. + +The doors switch in the change that implements this contract; until then they still gate on the member, and a refusal without `details.reason` comes from such a door. The semantic entry `action-requires-confirmation-elicited` carries the same notice into the upgrade guide and `os migrate meta`. + +What changes for a caller: + +- FROM confirm with the person yourself, then send `confirm: true` on `run_action` / `resume_run` TO advertise `elicitation` (form mode) at `initialize` and let the server ask the person; send no `confirm`. +- FROM a script or agent that runs a gated action unattended with `confirm: true` TO no replacement: a person runs the action, in an elicitation-capable client or in the app, or the action's author declares `ai.requiresConfirmation: false` where it is safe unattended. diff --git a/packages/spec/api-surface/contracts.json b/packages/spec/api-surface/contracts.json index d337bbb0eb7..44ddbf0a6dc 100644 --- a/packages/spec/api-surface/contracts.json +++ b/packages/spec/api-surface/contracts.json @@ -2,6 +2,7 @@ "description": "Every exported `name (kind)` of one published entry point of @objectstack/spec — the breadth half of the ADR-0059 backward-compatibility gate. Sharded by entry point (#5837) so two PRs touching different entry points never share a file. Reads the BUILT dist/*.d.ts: regenerate with `pnpm --filter @objectstack/spec gen:api-surface` after a real build.", "entry": "./contracts", "exports": [ + "ACTION_CONFIRMATION_REFUSAL_REASONS (const)", "AIActionConfirmation (interface)", "AIConversation (interface)", "AIMessage (type)", @@ -14,6 +15,7 @@ "AIToolCall (type)", "AIToolDefinition (interface)", "AIToolResult (type)", + "AI_ACTION_CONFIRMATION_CAPABILITY (const)", "AI_ACTION_CONFIRMATION_MEMBER (const)", "APPROVAL_ACTION_KINDS (const)", "APPROVAL_ACTION_KIND_LABELS (const)", @@ -23,6 +25,7 @@ "APPROVAL_STATUS_LABELS (const)", "AUDIT_CHECKPOINT_SIGNER_SERVICE (const)", "AUDIT_CHECKPOINT_SINK_SERVICE (const)", + "ActionConfirmationRefusalReason (type)", "ActionConfirmationRequiredDetails (interface)", "AdapterContext (interface)", "AdapterSearchOptions (interface)", diff --git a/packages/spec/export-origins/contracts.json b/packages/spec/export-origins/contracts.json index 41d842b1fb3..b5caf2d31e1 100644 --- a/packages/spec/export-origins/contracts.json +++ b/packages/spec/export-origins/contracts.json @@ -2,6 +2,7 @@ "description": "Which SOURCE DECLARATION each name exported by one public entry point of @objectstack/spec resolves to, after its alias chain is unwound: `# ()`. Two exports share an origin string iff they are the same declaration — so equal origins across two entries are a harmless re-export, and different origins under one name are the #4411 dual-source trap. Generated from src/ (no build needed) and read by the export-surface pin tests, which compare against it instead of each building their own ts.createProgram — that was ~55s of compilation per CI lap and a non-deterministic timeout that ejected unrelated PRs from the merge queue (#4796). Sharded by entry point (#5837) so two retirement PRs never share a file. Carries NO line numbers: the pins asserted the line as `\\d+`, and recording it would rewrite this artifact on every edit that shifts a line in any .zod.ts. Regenerate with `pnpm --filter @objectstack/spec gen:export-origins` and read the diff.", "entry": "./contracts", "exports": { + "ACTION_CONFIRMATION_REFUSAL_REASONS": "src/contracts/ai-service.ts#ACTION_CONFIRMATION_REFUSAL_REASONS (const)", "AIActionConfirmation": "src/contracts/ai-service.ts#AIActionConfirmation (interface)", "AIConversation": "src/contracts/ai-service.ts#AIConversation (interface)", "AIMessage": "src/contracts/ai-service.ts#AIMessage (type)", @@ -14,6 +15,7 @@ "AIToolCall": "src/contracts/ai-service.ts#AIToolCall (type)", "AIToolDefinition": "src/contracts/ai-service.ts#AIToolDefinition (interface)", "AIToolResult": "src/contracts/ai-service.ts#AIToolResult (type)", + "AI_ACTION_CONFIRMATION_CAPABILITY": "src/contracts/ai-service.ts#AI_ACTION_CONFIRMATION_CAPABILITY (const)", "AI_ACTION_CONFIRMATION_MEMBER": "src/contracts/ai-service.ts#AI_ACTION_CONFIRMATION_MEMBER (const)", "APPROVAL_ACTION_KINDS": "src/contracts/approval-service.ts#APPROVAL_ACTION_KINDS (const)", "APPROVAL_ACTION_KIND_LABELS": "src/contracts/approval-service.ts#APPROVAL_ACTION_KIND_LABELS (const)", @@ -23,6 +25,7 @@ "APPROVAL_STATUS_LABELS": "src/contracts/approval-service.ts#APPROVAL_STATUS_LABELS (const)", "AUDIT_CHECKPOINT_SIGNER_SERVICE": "src/contracts/audit-checkpoint.ts#AUDIT_CHECKPOINT_SIGNER_SERVICE (const)", "AUDIT_CHECKPOINT_SINK_SERVICE": "src/contracts/audit-checkpoint.ts#AUDIT_CHECKPOINT_SINK_SERVICE (const)", + "ActionConfirmationRefusalReason": "src/contracts/ai-service.ts#ActionConfirmationRefusalReason (type)", "ActionConfirmationRequiredDetails": "src/contracts/ai-service.ts#ActionConfirmationRequiredDetails (interface)", "AdapterContext": "src/contracts/knowledge-adapter.ts#AdapterContext (interface)", "AdapterSearchOptions": "src/contracts/knowledge-adapter.ts#AdapterSearchOptions (interface)", diff --git a/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts b/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts index 8af09e5d5fb..1658ce8f1fe 100644 --- a/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts +++ b/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts @@ -46,9 +46,16 @@ import { ErrorCode, standardSynonymOf, } from '../api/error-code-ledger.zod'; +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + import { + ACTION_CONFIRMATION_REFUSAL_REASONS, + AI_ACTION_CONFIRMATION_CAPABILITY, AI_ACTION_CONFIRMATION_MEMBER, type AIActionConfirmation, + type ActionConfirmationRefusalReason, type ActionConfirmationRequiredDetails, } from './ai-service'; @@ -137,3 +144,96 @@ describe('action-confirmation contract — an unconfirmed gated action is refuse expect(String(stringy.confirm)).toBe('true'); }); }); + +/** + * The amended contract: a person confirms a declared-gated action through MCP + * elicitation, and the caller's own `confirm` never counts (ruling + * 「3826 照建议(征询版)」, objectstack-ai/cloud#3826 item 6). + * + * Pinned here: the capability's spelling, the CLOSED refusal-reason set, that + * `details.reason` is typed to it and stays optional while the member gates + * still answer without it, that the amendment adds no second refusal code, + * and that the contract's own text names every reason and every elicitation + * answer, so the tuple and the prose cannot drift apart. NOT pinned: any door + * behaviour, which the implementing change lands and pins. + */ +describe('action-confirmation contract, as amended: a person confirms through elicitation', () => { + const HERE = dirname(fileURLToPath(import.meta.url)); + const CONTRACT_SOURCE = join(HERE, 'ai-service.ts'); + + /** The capability constant's docblock, comment gutters folded into spaces. */ + function capabilityProse(): string { + const source = readFileSync(CONTRACT_SOURCE, 'utf8'); + const at = source.indexOf('export const AI_ACTION_CONFIRMATION_CAPABILITY'); + expect(at, '`AI_ACTION_CONFIRMATION_CAPABILITY` moved — re-anchor this pin').toBeGreaterThan(-1); + const open = source.lastIndexOf('/**', at); + return source.slice(open, at).replace(/\n\s*\*\s?/g, ' ').replace(/\s+/g, ' '); + } + + it('the capability is MCP\'s own spelling, one exported constant', () => { + expect(AI_ACTION_CONFIRMATION_CAPABILITY).toBe('elicitation'); + // Control: it is not the member; the two travel on different channels. + expect(AI_ACTION_CONFIRMATION_CAPABILITY).not.toBe(AI_ACTION_CONFIRMATION_MEMBER); + }); + + it('the refusal reasons are a CLOSED set of exactly five', () => { + expect([...ACTION_CONFIRMATION_REFUSAL_REASONS]).toEqual([ + 'elicitation_unsupported', + 'declined', + 'cancelled', + 'timed_out', + 'service_account', + ]); + // Control: an accepted elicitation is not a refusal, so it is no reason. + expect((ACTION_CONFIRMATION_REFUSAL_REASONS as readonly string[]).includes('accepted')).toBe(false); + }); + + it('`details.reason` is typed to the closed set, and optional', () => { + const declined = asDetails({ + actionName: 'archive_account', + objectName: 'account', + confirmationMember: AI_ACTION_CONFIRMATION_MEMBER, + reason: 'declined', + }); + expect(declined.reason).toBe('declined'); + // Optional: a member gate (the MCP delete tools, a door before the + // implementing change) still answers without it. + const memberGate = asDetails({ actionName: 'delete_record', confirmationMember: AI_ACTION_CONFIRMATION_MEMBER }); + expect(memberGate.reason).toBeUndefined(); + + const nearMiss = asDetails({ + actionName: 'archive_account', + confirmationMember: AI_ACTION_CONFIRMATION_MEMBER, + // @ts-expect-error — not a reason the contract names; the set is closed. + reason: 'denied', + }); + expect(String(nearMiss.reason)).toBe('denied'); + const reason: ActionConfirmationRefusalReason = 'timed_out'; + expect(ACTION_CONFIRMATION_REFUSAL_REASONS).toContain(reason); + }); + + it('the amendment keeps ONE refusal code: no second code is registered for it', () => { + const all = Object.values(ERROR_CODE_LEDGER).flat() as string[]; + expect(all).toContain(CODE); + // Every reason rides `details.reason` under the one registered code. + expect(all.filter((code) => /ELICIT|CONFIRMATION_(DECLINED|CANCELLED|TIMED_OUT|UNSUPPORTED)/.test(code))).toEqual([]); + }); + + it('the contract text names every reason and every elicitation answer', () => { + const prose = capabilityProse(); + expect(prose.length, 'the capability docblock read empty').toBeGreaterThan(3000); + for (const reason of ACTION_CONFIRMATION_REFUSAL_REASONS) { + expect(prose, `the contract no longer states the \`${reason}\` case`).toContain(`\`${reason}\``); + } + for (const answer of ['`accept`', '`decline`', '`cancel`', 'Timed out']) { + expect(prose, `the contract no longer says what ${answer} does`).toContain(answer); + } + expect(prose, 'the contract dropped "the caller\'s `confirm` never counts"').toMatch(/The caller's `confirm` never counts/); + expect(prose, 'the contract dropped the unchanged AI service account rule').toMatch( + /An AI service account: unchanged\*\* \(ADR-0151 D3 rule 3\)/, + ); + expect(prose, 'the refusal for a client without elicitation no longer names the remedy').toMatch( + /use a client that supports confirmation, or to perform the action in the app/, + ); + }); +}); diff --git a/packages/spec/src/contracts/ai-service.ts b/packages/spec/src/contracts/ai-service.ts index f4bff0446d5..054fd397a1d 100644 --- a/packages/spec/src/contracts/ai-service.ts +++ b/packages/spec/src/contracts/ai-service.ts @@ -238,6 +238,14 @@ export interface AIToolDefinition { * — there is no header there for it to ride on. A free-form header would * also be an OPEN channel, which is the one thing a safety member must not * be. + * + * ## Amended: on a declared-gated action the member no longer confirms + * + * The confirmation of an action declaring `ai.requiresConfirmation: true` is + * now a person's answer to an MCP elicitation the server sends, and the + * member never counts on such a call (see + * {@link AI_ACTION_CONFIRMATION_CAPABILITY}, which also says when the doors + * switch). The MCP `delete_record` and `delete_records` gates still read it. */ export const AI_ACTION_CONFIRMATION_MEMBER = 'confirm'; @@ -246,6 +254,18 @@ export const AI_ACTION_CONFIRMATION_MEMBER = 'confirm'; * member, declared once here and mixed into each door's own request shape * rather than restated by it. * + * ## Amended: the member contract is the FROM half + * + * For an action declaring `ai.requiresConfirmation: true`, the contract is + * now confirmation by elicitation ({@link AI_ACTION_CONFIRMATION_CAPABILITY}): + * the server asks the person through the client, and the caller's own + * `confirm` never counts. What follows describes the member contract the + * doors enforce until the change that implements the amendment; the + * predicate section (the DECLARED flag, never the listing heuristic) and the + * AI service account rule carry over unchanged. The MCP `delete_record` and + * `delete_records` gates are outside the amendment and keep reading the + * member as described below. + * * ## What the member means * * `confirm: true` asserts that the human in the loop has approved THIS call. @@ -374,10 +394,152 @@ export interface ActionConfirmationRequiredDetails { * the refusal instead of restating it. An AI service account's refusal * carries it too, but no retry of that account's succeeds: a person runs * the action (ADR-0151 D3 rule 3). + * + * Under the elicitation contract ({@link AI_ACTION_CONFIRMATION_CAPABILITY}) + * no retry with the member runs a declared-gated action: the member + * confers nothing there, and `reason` says what the caller can do. */ confirmationMember: typeof AI_ACTION_CONFIRMATION_MEMBER; + /** + * Which case of the elicitation contract refused the call; see + * {@link ActionConfirmationRefusalReason}. Every door implementing that + * contract sets it on a declared-gated refusal. A refusal without it comes + * from a member gate: a door before the implementing change, or the MCP + * `delete_record` / `delete_records` gate. + */ + reason?: ActionConfirmationRefusalReason; } +// --------------------------------------------------------------------------- +// Action Confirmation by Elicitation — the amended contract +// --------------------------------------------------------------------------- + +/** + * The MCP client capability a person's confirmation travels through: + * `elicitation`, which an MCP client advertises in the `capabilities` of its + * `initialize` request. + * + * ONE exported constant for the same reason {@link AI_ACTION_CONFIRMATION_MEMBER} + * is one: the door that reads the capability, the refusal that names it and + * the client that must advertise it have to agree on its spelling. + * + * ## Why the contract was amended + * + * Under the member contract ({@link AIActionConfirmation}) the confirmation of + * a declared-gated action is the caller's own `confirm: true`, an + * unverifiable claim: the gate made FORGETTING loud and did not prove a + * person. Measured on published 18.4.0, an agent sent `confirm: true` itself + * on an irreversible action in 2 of 6 runs, reading the person's instruction + * as consent. The account owner ruled the fix (「3826 照建议(征询版)」, on + * objectstack-ai/cloud#3826, phase 1, card 1 of its item-6 chain): the SERVER + * asks the person, through the client, and the caller's own answer never + * counts. + * + * ## The contract + * + * 1. **Which calls.** A call on an action whose author declared + * `ai.requiresConfirmation: true` (the DECLARED flag, never the listing + * heuristic; {@link AIActionConfirmation} keeps that predicate), through an + * AI door: the MCP `run_action` tool, and the MCP `resume_run` tool for the + * candidate action it would run. Every caller is covered, OAuth token or + * API key, a person or an agent acting for one (`onBehalfOf`). + * 2. **Who confirms: a person, through elicitation.** After every other + * admission gate has passed, so nobody is asked to confirm a call that is + * refused anyway, and before anything dispatches, the server sends ONE + * MCP `elicitation/create` request in form mode to the client the call + * arrived on, for that call. Its message names the action and the object + * and record it runs on. The person's answer is the result's `action` + * alone; any `content` the client returns is not read. + * 3. **Which clients.** The door reads the `elicitation` capability the client + * sent in its `initialize` request, for the session the call rides on. Form + * mode is what is asked, and an empty `elicitation: {}` reads as form mode + * (MCP 2025-11-25). A client that did not advertise it is REFUSED before + * anything is asked or run, with + * {@link ActionConfirmationRefusalReason} `elicitation_unsupported`; the + * message tells the person to use a client that supports confirmation, or + * to perform the action in the app. A door that cannot carry an elicitation + * to the client refuses the same way. Neither ever falls back to the + * member. + * 4. **What each answer does.** Only `accept` confirms. + * - `accept`: the call dispatches as any admitted call does, exactly once, + * under the caller's permissions. The confirmation covers that one call: + * nothing is stored, and the next call is asked again. + * - `decline`: the person said no. Refused, reason `declined`; nothing runs. + * The caller does not retry unless the person asks again. + * - `cancel`: the person dismissed the question without choosing. Refused, + * reason `cancelled`; nothing runs. An error answer to the elicitation + * request, or a connection that drops before an answer, is read the same + * way. + * - Timed out: no answer within the door's bound, which the implementing + * door names. Refused, reason `timed_out`; nothing runs, and an answer + * that arrives later runs nothing. + * 5. **The caller's `confirm` never counts.** On a declared-gated call the + * member ({@link AI_ACTION_CONFIRMATION_MEMBER}) confers nothing: not with + * an elicitation, not in place of one, and not for a client that cannot + * elicit. An agent cannot answer for the person by sending it. + * 6. **An AI service account: unchanged** (ADR-0151 D3 rule 3). An agent + * principal acting for itself, with no `onBehalfOf`, is refused whatever it + * sends, reason `service_account`. No elicitation is sent to it: no person + * stands behind the account, and its own client could answer one. + * + * Every refusal keeps the registered envelope: `428`, + * `ACTION_CONFIRMATION_REQUIRED`, and `error.details` shaped as + * {@link ActionConfirmationRequiredDetails}, whose `reason` says which of the + * cases above it is. Nothing is parked or queued, as before: a refused call + * did not run, and no record was read or written for it. + * + * ## Its bounds + * + * - The MCP `delete_record` and `delete_records` gates are not declared-gated + * actions: they read the member, as {@link AIActionConfirmation} describes, + * until a decision moves them. + * - REST `/actions` stays outside the gate for a person, as before. + * + * ## When it binds + * + * This text is the contract from the release that carries it. The doors + * implement it in the change that enforces it, which also moves the shipped + * prescriptions that describe the member. Until that change, the doors + * still gate on the member as {@link AIActionConfirmation} describes, and that + * reading is the FROM half of the breaking note. + * + * The door has to hold what the rules above need: the client's `initialize` + * capabilities for the session, and a way to send a request to the client + * while the call is open. The long-lived stdio server holds both. The + * stateless Streamable HTTP door (`handleHttpRequest` in + * `packages/mcp/src/mcp-server-runtime.ts`) builds a fresh server per request, + * issues no session id and answers in JSON, so as built it holds neither, and + * by rule 3 it refuses until the implementing change gives it both. + */ +export const AI_ACTION_CONFIRMATION_CAPABILITY = 'elicitation'; + +/** + * Why a declared-gated call was refused under the elicitation contract + * ({@link AI_ACTION_CONFIRMATION_CAPABILITY}), carried as + * {@link ActionConfirmationRequiredDetails.reason}. A CLOSED set: + * + * - `elicitation_unsupported`: the client did not advertise `elicitation` at + * `initialize`, or the door cannot carry one. Retrying from that client + * cannot succeed: the person uses a client that supports confirmation, or + * performs the action in the app. + * - `declined`: the person answered no. + * - `cancelled`: the person dismissed the question, the client answered the + * elicitation request with an error, or the connection dropped first. + * - `timed_out`: no answer within the door's bound. + * - `service_account`: an AI service account, which never confirms an action + * for itself (ADR-0151 D3 rule 3). A person runs the action. + */ +export const ACTION_CONFIRMATION_REFUSAL_REASONS = [ + 'elicitation_unsupported', + 'declined', + 'cancelled', + 'timed_out', + 'service_account', +] as const; + +/** One member of {@link ACTION_CONFIRMATION_REFUSAL_REASONS}. */ +export type ActionConfirmationRefusalReason = (typeof ACTION_CONFIRMATION_REFUSAL_REASONS)[number]; + // --------------------------------------------------------------------------- // IAIService // --------------------------------------------------------------------------- diff --git a/packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts b/packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts new file mode 100644 index 00000000000..34c082703ee --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts @@ -0,0 +1,39 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// The confirmation contract of `ai.requiresConfirmation: true` is amended +// (`AI_ACTION_CONFIRMATION_CAPABILITY`, `contracts/ai-service.ts`): a person +// confirms through MCP elicitation, and the caller's own `confirm: true` stops +// counting. A structured TODO, not a D2 conversion: nothing an author wrote is +// rewritten or refused, and whether a gated action still needs a person, and +// which clients its users run, is the author's judgement. +export const entry: SemanticMigration = { + id: 'action-requires-confirmation-elicited', + surface: + 'objects[].actions[].ai.requiresConfirmation and actions[].ai.requiresConfirmation set to `true` — ' + + 'what the declaration asks of a caller on the MCP `run_action` and `resume_run` tools', + replacement: + 'Keep the declaration where a person must approve the call. What changes is who confirms: the server asks ' + + 'the person through the MCP client with an elicitation (`elicitation/create`, form mode), and only an ' + + 'accepted answer runs the action. A client that did not advertise the `elicitation` capability at ' + + '`initialize` is refused with `ACTION_CONFIRMATION_REQUIRED` (428) and `details.reason` ' + + '`elicitation_unsupported`; a declined, cancelled or unanswered question is refused the same way with ' + + 'reason `declined`, `cancelled` or `timed_out`, and nothing runs. The caller\'s own `confirm: true` no ' + + 'longer confirms anything. An AI service account acting for itself is still refused whatever it sends. ' + + 'The doors switch in the change that implements the contract: a refusal carrying no `details.reason` ' + + 'comes from a door that still reads the member.', + reason: + '`confirm: true` was the caller\'s own claim that a person approved, and nothing could check it: an agent ' + + 'could send it for an irreversible action on reading the person\'s instruction as consent, and measured ' + + 'runs did exactly that. The gate made forgetting loud and did not prove a person. The server asking the ' + + 'person through the client, with the caller unable to answer for them, is what makes the declaration mean ' + + 'what an author who wrote it meant. No mechanical move applies: the metadata is unchanged, and the work is ' + + 'on the client side and in the author\'s decision about each gated action. ADR-0011 / ADR-0151 / ADR-0087.', + acceptanceCriteria: + 'For every action declaring `ai.requiresConfirmation: true`, decide again that a person must approve each AI ' + + 'call; if not, declare `false` knowingly. Tell the people who run those actions through an MCP client that ' + + 'the client must support elicitation, or that they perform the action in the app. A script or agent that ' + + 'sent `confirm: true` to run such an action unattended stops working by design: it is refused, and a person ' + + 'runs the action. Done when no caller relies on its own `confirm: true` for a declared-gated action.', +}; From 464e733d7fa0048040e16a8528fc938a41249129 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 08:20:07 +0000 Subject: [PATCH 2/5] fix(spec): the amended confirmation contract hands an unelicitable call to the app before any refusal A client that cannot be elicited is handed to the host's optional pending-confirmation service (IActionConfirmationService) and answered with a pending id; only a host without the service refuses. The person is asked after every admission gate, a confirmation-refused call may have read its subject, the reason set and pins follow the amended rule, and the semantic entry and changeset speak of the doors' switch conditionally. Claude-Session: https://claude.ai/code/session_01FEkQ5kZuoX9F5S7p84Dwue Co-Authored-By: Claude --- .../33689-ai-action-confirmation-elicited.md | 29 +- .../action-confirmation-contract.pin.test.ts | 77 ++++- packages/spec/src/contracts/ai-service.ts | 281 ++++++++++++------ ...8.action-requires-confirmation-elicited.ts | 48 +-- 4 files changed, 301 insertions(+), 134 deletions(-) diff --git a/.changeset/33689-ai-action-confirmation-elicited.md b/.changeset/33689-ai-action-confirmation-elicited.md index eda5c34b36c..2358ecdf1e2 100644 --- a/.changeset/33689-ai-action-confirmation-elicited.md +++ b/.changeset/33689-ai-action-confirmation-elicited.md @@ -2,28 +2,29 @@ '@objectstack/spec': minor --- -feat(spec)!: a declared-gated action on an AI door is confirmed by a person through MCP elicitation, never by the caller's own `confirm: true` +feat(spec)!: a declared-gated action on an AI door is confirmed by a person, elicited in the MCP client or handed off to the app, never by the caller's own `confirm: true` -Clause-②: yes (narrowing) — the contract stops counting a caller's `confirm: true` on an action declaring `ai.requiresConfirmation: true` and refuses an MCP client that did not advertise `elicitation`; `@objectstack/spec/contracts` gains `AI_ACTION_CONFIRMATION_CAPABILITY`, `ACTION_CONFIRMATION_REFUSAL_REASONS`, `ActionConfirmationRefusalReason` and the optional `ActionConfirmationRequiredDetails.reason`. +Clause-②: yes (narrowing) — once the doors implement the contract, a caller's `confirm: true` stops counting on an action declaring `ai.requiresConfirmation: true`; `@objectstack/spec/contracts` gains `AI_ACTION_CONFIRMATION_CAPABILITY`, `ACTION_CONFIRMATION_REFUSAL_REASONS`, `ActionConfirmationRefusalReason`, `ActionConfirmationHandOff`, `ActionConfirmationPending`, `IActionConfirmationService` and the optional `ActionConfirmationRequiredDetails.reason`. Metadata-protocol: semantic -Skills-docs: follow-up — `skills/objectstack-ai/SKILL.md` (the MCP tool table: `run_action` / `resume_run` "refused with the same 428 unless the call sends `confirm: true`") teaches the member contract; it moves with the change that implements the doors, together with the MCP-served skill text (`packages/mcp/src/skill-md.ts`, `ui/apps/console/src/pages/developer/objectstack-skill.ts`) and the `ToolSchema` prescription in `packages/spec/src/ai/tool.zod.ts`, which describe the door that runs today. +Skills-docs: follow-up — `skills/objectstack-ai/SKILL.md` (the MCP tool table: `run_action` / `resume_run` "refused with the same 428 unless the call sends `confirm: true`") teaches the member contract, which is still the door's behaviour in this release; it moves with the change that implements the doors, together with the MCP-served skill text (`packages/mcp/src/skill-md.ts`, `ui/apps/console/src/pages/developer/objectstack-skill.ts`) and the `ToolSchema` prescription in `packages/spec/src/ai/tool.zod.ts`. -**BREAKING** for an MCP client, an agent or a script that runs an action declaring `ai.requiresConfirmation: true` through `run_action` or `resume_run` by sending `confirm: true` itself. Ruled by the account owner: 「3826 照建议(征询版)」. +**BREAKING, when the implementing change ships**, for an MCP client, an agent or a script that runs an action declaring `ai.requiresConfirmation: true` through `run_action` or `resume_run` by sending `confirm: true` itself. Ruled by the account owner: 「3826 照建议(征询版)」, amended 「我开始重新接受你说的主流方案,就是推送到客户的手机端」 and 「比如最简单的我可以先推送到邮件」. -The contract in `@objectstack/spec/contracts` (`AI_ACTION_CONFIRMATION_CAPABILITY`, `contracts/ai-service.ts`) now says: +⚠ In the release that carries this changeset nothing changes at any door: `run_action` and `resume_run` still run a declared-gated action on `confirm: true` and refuse it without, over stdio and Streamable HTTP alike. Keep sending `confirm: true` until a release's changelog says the doors confirm by elicitation. What ships now is the contract the doors move to, in `@objectstack/spec/contracts` (`AI_ACTION_CONFIRMATION_CAPABILITY`, `contracts/ai-service.ts`): -- The server asks the person: after every other gate passes and before anything runs, it sends one MCP `elicitation/create` request (form mode) to the client the call arrived on, naming the action, the object and the record. -- The door reads the `elicitation` capability the client sent at `initialize`. A client that did not advertise it is refused with `428 ACTION_CONFIRMATION_REQUIRED` and `details.reason: 'elicitation_unsupported'`; the message tells the person to use a client that supports confirmation, or to act in the app. -- `accept` runs the call once, under the caller's permissions, and nothing is stored for the next call. `decline`, `cancel` (an error answer or a dropped connection included) and no answer within the door's bound are refused with reason `declined`, `cancelled` or `timed_out`, and nothing runs. -- The caller's `confirm` never counts on such a call, with or without an elicitation. -- An AI service account acting for itself is refused whatever it sends, unchanged (ADR-0151 D3 rule 3), now with reason `service_account`; no elicitation is sent to it. +- After every admission gate (the subject load included) and before anything runs, the person is asked, in three steps: **elicit** when the client advertised `elicitation` at `initialize` and the door can carry it (one `elicitation/create`, form mode); otherwise **hand off** to the host's pending-confirmation service (`IActionConfirmationService`), answering `status: 'pending_confirmation'` with a pending id and a plain message, the person then approving or rejecting in the app, where the action runs as them with every gate and permission re-checked; **refuse** only when the host has no such service (`428 ACTION_CONFIRMATION_REQUIRED`, `details.reason: 'no_confirmation_service'`). +- An elicited `accept` runs the call once; `decline`, `cancel` (an error answer or a dropped connection included) and no answer within the door's bound are refused with reason `declined`, `cancelled` or `timed_out`. A call refused at confirmation may have read its subject and writes nothing. +- The approve and reject doors of the pending-confirmation service refuse an AI identity. +- The caller's `confirm` never counts on such a call. +- An AI service account acting for itself is refused whatever it sends, unchanged (ADR-0151 D3 rule 3), with reason `service_account` on every door; it is neither elicited nor handed off. +- An elicited `accept` proves the client answered, not that a person did; a hand-off is decided by a person in the app. - Outside the amendment: the MCP `delete_record` and `delete_records` gates still read `confirm: true`, and REST `/actions` stays outside the gate for a person. -The doors switch in the change that implements this contract; until then they still gate on the member, and a refusal without `details.reason` comes from such a door. The semantic entry `action-requires-confirmation-elicited` carries the same notice into the upgrade guide and `os migrate meta`. +The semantic entry `action-requires-confirmation-elicited` carries the same notice, with the same timing, into the upgrade guide and `os migrate meta`. -What changes for a caller: +What changes for a caller, from the release whose doors implement it: -- FROM confirm with the person yourself, then send `confirm: true` on `run_action` / `resume_run` TO advertise `elicitation` (form mode) at `initialize` and let the server ask the person; send no `confirm`. -- FROM a script or agent that runs a gated action unattended with `confirm: true` TO no replacement: a person runs the action, in an elicitation-capable client or in the app, or the action's author declares `ai.requiresConfirmation: false` where it is safe unattended. +- FROM confirm with the person yourself, then send `confirm: true` on `run_action` / `resume_run` TO advertise `elicitation` (form mode) at `initialize` and let the server ask the person, or, from a client that cannot, relay the pending answer's message and let the person decide in the app; `confirm` then confers nothing. +- FROM a script or agent that runs a gated action unattended with `confirm: true` TO a pending answer the person decides in the app (or a refusal on a host with no pending-confirmation service); where the action is safe unattended, its author declares `ai.requiresConfirmation: false`. diff --git a/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts b/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts index 1658ce8f1fe..3912f1dffc7 100644 --- a/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts +++ b/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts @@ -55,8 +55,11 @@ import { AI_ACTION_CONFIRMATION_CAPABILITY, AI_ACTION_CONFIRMATION_MEMBER, type AIActionConfirmation, + type ActionConfirmationHandOff, + type ActionConfirmationPending, type ActionConfirmationRefusalReason, type ActionConfirmationRequiredDetails, + type IActionConfirmationService, } from './ai-service'; /** The refusal code the contract names. */ @@ -146,18 +149,23 @@ describe('action-confirmation contract — an unconfirmed gated action is refuse }); /** - * The amended contract: a person confirms a declared-gated action through MCP - * elicitation, and the caller's own `confirm` never counts (ruling - * 「3826 照建议(征询版)」, objectstack-ai/cloud#3826 item 6). + * The amended contract: a person confirms a declared-gated action, through + * MCP elicitation when the client can be asked and through a hand-off to the + * host's pending-confirmation service otherwise, refused only when the host + * has none; the caller's own `confirm` never counts (ruling + * 「3826 照建议(征询版)」, objectstack-ai/cloud#3826 item 6, as amended on + * the card). * - * Pinned here: the capability's spelling, the CLOSED refusal-reason set, that - * `details.reason` is typed to it and stays optional while the member gates - * still answer without it, that the amendment adds no second refusal code, - * and that the contract's own text names every reason and every elicitation - * answer, so the tuple and the prose cannot drift apart. NOT pinned: any door - * behaviour, which the implementing change lands and pins. + * Pinned here: the capability's spelling, the CLOSED refusal-reason set (a + * hand-off is not in it), that `details.reason` is typed to it and stays + * optional while the member gates still answer without it, the pending + * answer's discriminant and the hand-off seam's shape, that the amendment adds + * no second refusal code, and that the contract's own text names every reason, + * every answer and the three steps, so the types and the prose cannot drift + * apart. NOT pinned: any door behaviour, which the implementing change lands + * and pins. */ -describe('action-confirmation contract, as amended: a person confirms through elicitation', () => { +describe('action-confirmation contract, as amended: a person confirms, elicited or handed off', () => { const HERE = dirname(fileURLToPath(import.meta.url)); const CONTRACT_SOURCE = join(HERE, 'ai-service.ts'); @@ -178,14 +186,18 @@ describe('action-confirmation contract, as amended: a person confirms through el it('the refusal reasons are a CLOSED set of exactly five', () => { expect([...ACTION_CONFIRMATION_REFUSAL_REASONS]).toEqual([ - 'elicitation_unsupported', 'declined', 'cancelled', 'timed_out', + 'no_confirmation_service', 'service_account', ]); - // Control: an accepted elicitation is not a refusal, so it is no reason. - expect((ACTION_CONFIRMATION_REFUSAL_REASONS as readonly string[]).includes('accepted')).toBe(false); + // Controls: an accepted elicitation and a hand-off are not refusals, and a + // client that cannot elicit is handed off rather than refused for that. + const reasons = ACTION_CONFIRMATION_REFUSAL_REASONS as readonly string[]; + for (const notARefusal of ['accepted', 'pending_confirmation', 'elicitation_unsupported']) { + expect(reasons.includes(notARefusal), `${notARefusal} must not be a refusal reason`).toBe(false); + } }); it('`details.reason` is typed to the closed set, and optional', () => { @@ -212,6 +224,34 @@ describe('action-confirmation contract, as amended: a person confirms through el expect(ACTION_CONFIRMATION_REFUSAL_REASONS).toContain(reason); }); + it('a hand-off answers with the pending discriminant, through an optional host seam', () => { + const pending: ActionConfirmationPending = { + status: 'pending_confirmation', + pendingId: 'pc_1', + message: 'A confirmation was sent to you.', + actionName: 'archive_account', + objectName: 'account', + }; + expect(pending.status).toBe('pending_confirmation'); + const wrongStatus: ActionConfirmationPending = { + // @ts-expect-error — the discriminant is one literal; the in-app chat's + // older `pending_approval` envelope is not this answer. + status: 'pending_approval', + pendingId: 'pc_1', + message: 'm', + actionName: 'archive_account', + }; + expect(String(wrongStatus.status)).toBe('pending_approval'); + + const handOff: ActionConfirmationHandOff = { + actionName: 'archive_account', objectName: 'account', recordId: 'a1', params: {}, door: 'mcp', + }; + const service: IActionConfirmationService = { + submit: async (h) => ({ pendingId: `pc_${h.actionName}` }), + }; + return expect(service.submit(handOff, {} as never)).resolves.toEqual({ pendingId: 'pc_archive_account' }); + }); + it('the amendment keeps ONE refusal code: no second code is registered for it', () => { const all = Object.values(ERROR_CODE_LEDGER).flat() as string[]; expect(all).toContain(CODE); @@ -225,9 +265,18 @@ describe('action-confirmation contract, as amended: a person confirms through el for (const reason of ACTION_CONFIRMATION_REFUSAL_REASONS) { expect(prose, `the contract no longer states the \`${reason}\` case`).toContain(`\`${reason}\``); } - for (const answer of ['`accept`', '`decline`', '`cancel`', 'Timed out']) { + for (const answer of ['`accept`', '`decline`', '`cancel`', 'timed out', 'then approved in the app', 'then rejected in the app']) { expect(prose, `the contract no longer says what ${answer} does`).toContain(answer); } + for (const step of ['**Elicit**', '**Hand off**', '**Refuse**, only when the host has no pending-confirmation service']) { + expect(prose, `the contract dropped the step ${step}`).toContain(step); + } + expect(prose, 'the contract dropped the AI-identity refusal on the approve and reject doors').toMatch( + /approve and reject doors of the pending-confirmation service refuse an AI identity/, + ); + expect(prose, 'the contract dropped the re-check at approval').toMatch(/every gate and permission re-checked/); + expect(prose, 'the contract dropped the trust bound of an elicited answer').toMatch(/proves that the CLIENT answered, not that a person did/); + expect(prose, 'the contract claims a refused call read nothing again').not.toMatch(/no record was read/); expect(prose, 'the contract dropped "the caller\'s `confirm` never counts"').toMatch(/The caller's `confirm` never counts/); expect(prose, 'the contract dropped the unchanged AI service account rule').toMatch( /An AI service account: unchanged\*\* \(ADR-0151 D3 rule 3\)/, diff --git a/packages/spec/src/contracts/ai-service.ts b/packages/spec/src/contracts/ai-service.ts index 054fd397a1d..f259f76ae2d 100644 --- a/packages/spec/src/contracts/ai-service.ts +++ b/packages/spec/src/contracts/ai-service.ts @@ -239,13 +239,15 @@ export interface AIToolDefinition { * also be an OPEN channel, which is the one thing a safety member must not * be. * - * ## Amended: on a declared-gated action the member no longer confirms + * ## Amended: on a declared-gated action the member stops confirming * - * The confirmation of an action declaring `ai.requiresConfirmation: true` is - * now a person's answer to an MCP elicitation the server sends, and the - * member never counts on such a call (see - * {@link AI_ACTION_CONFIRMATION_CAPABILITY}, which also says when the doors - * switch). The MCP `delete_record` and `delete_records` gates still read it. + * The amended contract ({@link AI_ACTION_CONFIRMATION_CAPABILITY}) has a + * person confirm an action declaring `ai.requiresConfirmation: true`, through + * an elicitation or a hand-off to the app, and the member never counts on such + * a call. That is what the doors enforce from the change that implements the + * amendment; until it ships they still gate on the member as described above + * and in {@link AIActionConfirmation}. The MCP `delete_record` and + * `delete_records` gates are outside the amendment and keep reading it. */ export const AI_ACTION_CONFIRMATION_MEMBER = 'confirm'; @@ -257,9 +259,10 @@ export const AI_ACTION_CONFIRMATION_MEMBER = 'confirm'; * ## Amended: the member contract is the FROM half * * For an action declaring `ai.requiresConfirmation: true`, the contract is - * now confirmation by elicitation ({@link AI_ACTION_CONFIRMATION_CAPABILITY}): - * the server asks the person through the client, and the caller's own - * `confirm` never counts. What follows describes the member contract the + * now a person's confirmation ({@link AI_ACTION_CONFIRMATION_CAPABILITY}): + * the server elicits it through the client, or hands the call to the host's + * pending-confirmation service for the person to decide in the app, and the + * caller's own `confirm` never counts. What follows describes the member contract the * doors enforce until the change that implements the amendment; the * predicate section (the DECLARED flag, never the listing heuristic) and the * AI service account rule carry over unchanged. The MCP `delete_record` and @@ -395,33 +398,35 @@ export interface ActionConfirmationRequiredDetails { * carries it too, but no retry of that account's succeeds: a person runs * the action (ADR-0151 D3 rule 3). * - * Under the elicitation contract ({@link AI_ACTION_CONFIRMATION_CAPABILITY}) - * no retry with the member runs a declared-gated action: the member - * confers nothing there, and `reason` says what the caller can do. + * Under the amended contract ({@link AI_ACTION_CONFIRMATION_CAPABILITY}), + * once the doors implement it, no retry with the member runs a + * declared-gated action: the member confers nothing there, and `reason` + * says what the caller can do. */ confirmationMember: typeof AI_ACTION_CONFIRMATION_MEMBER; /** - * Which case of the elicitation contract refused the call; see + * Which case of the amended contract refused the call; see * {@link ActionConfirmationRefusalReason}. Every door implementing that - * contract sets it on a declared-gated refusal. A refusal without it comes - * from a member gate: a door before the implementing change, or the MCP - * `delete_record` / `delete_records` gate. + * contract sets it on a declared-gated refusal, the AI service account's + * included on every door. A refusal without it comes from a member gate: + * a door before the implementing change, or the MCP `delete_record` / + * `delete_records` gate. */ reason?: ActionConfirmationRefusalReason; } // --------------------------------------------------------------------------- -// Action Confirmation by Elicitation — the amended contract +// Action Confirmation by Elicitation or Hand-off — the amended contract // --------------------------------------------------------------------------- /** - * The MCP client capability a person's confirmation travels through: - * `elicitation`, which an MCP client advertises in the `capabilities` of its - * `initialize` request. + * The MCP client capability a person's in-client confirmation travels + * through: `elicitation`, which an MCP client advertises in the + * `capabilities` of its `initialize` request. * * ONE exported constant for the same reason {@link AI_ACTION_CONFIRMATION_MEMBER} - * is one: the door that reads the capability, the refusal that names it and - * the client that must advertise it have to agree on its spelling. + * is one: the door that reads the capability and the client that advertises + * it have to agree on its spelling. * * ## Why the contract was amended * @@ -430,10 +435,12 @@ export interface ActionConfirmationRequiredDetails { * unverifiable claim: the gate made FORGETTING loud and did not prove a * person. Measured on published 18.4.0, an agent sent `confirm: true` itself * on an irreversible action in 2 of 6 runs, reading the person's instruction - * as consent. The account owner ruled the fix (「3826 照建议(征询版)」, on - * objectstack-ai/cloud#3826, phase 1, card 1 of its item-6 chain): the SERVER - * asks the person, through the client, and the caller's own answer never - * counts. + * as consent. The account owner ruled the fix on objectstack-ai/cloud#3826 + * (「3826 照建议(征询版)」, phase 1, card 1 of its item-6 chain) and amended + * it on the card that carries this contract (「我开始重新接受你说的主流方案,就是推送到客户的手机端」, + * 「比如最简单的我可以先推送到邮件」): the server asks the person, in the + * client when the client can be asked and in the app otherwise, and the + * caller's own answer never counts. * * ## The contract * @@ -441,52 +448,87 @@ export interface ActionConfirmationRequiredDetails { * `ai.requiresConfirmation: true` (the DECLARED flag, never the listing * heuristic; {@link AIActionConfirmation} keeps that predicate), through an * AI door: the MCP `run_action` tool, and the MCP `resume_run` tool for the - * candidate action it would run. Every caller is covered, OAuth token or - * API key, a person or an agent acting for one (`onBehalfOf`). - * 2. **Who confirms: a person, through elicitation.** After every other - * admission gate has passed, so nobody is asked to confirm a call that is - * refused anyway, and before anything dispatches, the server sends ONE - * MCP `elicitation/create` request in form mode to the client the call - * arrived on, for that call. Its message names the action and the object - * and record it runs on. The person's answer is the result's `action` - * alone; any `content` the client returns is not read. - * 3. **Which clients.** The door reads the `elicitation` capability the client - * sent in its `initialize` request, for the session the call rides on. Form - * mode is what is asked, and an empty `elicitation: {}` reads as form mode - * (MCP 2025-11-25). A client that did not advertise it is REFUSED before - * anything is asked or run, with - * {@link ActionConfirmationRefusalReason} `elicitation_unsupported`; the - * message tells the person to use a client that supports confirmation, or - * to perform the action in the app. A door that cannot carry an elicitation - * to the client refuses the same way. Neither ever falls back to the - * member. - * 4. **What each answer does.** Only `accept` confirms. - * - `accept`: the call dispatches as any admitted call does, exactly once, - * under the caller's permissions. The confirmation covers that one call: - * nothing is stored, and the next call is asked again. - * - `decline`: the person said no. Refused, reason `declined`; nothing runs. - * The caller does not retry unless the person asks again. - * - `cancel`: the person dismissed the question without choosing. Refused, - * reason `cancelled`; nothing runs. An error answer to the elicitation - * request, or a connection that drops before an answer, is read the same - * way. - * - Timed out: no answer within the door's bound, which the implementing - * door names. Refused, reason `timed_out`; nothing runs, and an answer - * that arrives later runs nothing. + * candidate action it would run. Every caller acting for a person is + * covered, OAuth token or API key, a person or an agent acting for one + * (`onBehalfOf`). + * 2. **When the person is asked.** After EVERY admission gate has passed, + * the subject load and the caller-scope subject verdict included, so + * nobody is asked to confirm a call that is refused anyway, and before + * anything dispatches. A call refused at confirmation, or never confirmed, + * may therefore have READ its subject under the caller's permissions; it + * writes nothing. + * 3. **How the person is asked — three steps, in order.** + * 1. **Elicit**, when the client advertised `elicitation` at `initialize` + * for the session the call rides on and the door can carry a request to + * it while the call is open. The server sends ONE MCP + * `elicitation/create` request in form mode, naming the action, the + * object and the record it runs on (its id, and its title when the + * subject load read one). An empty `elicitation: {}` reads as form mode + * (MCP 2025-11-25). The answer is the result's `action` alone; any + * `content` is not read. + * 2. **Hand off**, otherwise: the door hands the call to the host's + * pending-confirmation service ({@link IActionConfirmationService}) and + * answers the caller with {@link ActionConfirmationPending}: a pending + * id and a plain message that a confirmation was sent to the person. + * Nothing runs then. The host shows the pending item to the person in + * the app and notifies them (an emailed link, for example); the person + * signs in and approves or rejects it there. + * 3. **Refuse**, only when the host has no pending-confirmation service: + * reason `no_confirmation_service`. The message tells the person to use + * a client that supports confirmation, or to perform the action in the + * app. + * A door or a client that cannot elicit is never refused for that alone: + * it takes step 2, or step 3 when the host has no service. No step ever + * falls back to the member. + * 4. **What each answer does.** + * - Elicited `accept`: the call dispatches as any admitted call does, + * exactly once, under the caller's permissions. The confirmation covers + * that one call: nothing is stored, and the next call is asked again. + * - Elicited `decline`: the person said no. Refused, reason `declined`; + * nothing runs. The caller does not retry unless the person asks again. + * - Elicited `cancel`: the person dismissed the question without choosing. + * Refused, reason `cancelled`; nothing runs. An error answer to the + * elicitation request, or a connection that drops before an answer, is + * read the same way. + * - Elicitation timed out: no answer within the door's bound, which the + * implementing door names. Refused, reason `timed_out`; nothing runs, + * and an answer that arrives later runs nothing. + * - Handed off, then approved in the app: the action runs as the person + * who approved it, through the same admitted sequence, every gate and + * permission re-checked at that moment; a refusal there runs nothing and + * is recorded on the pending item. + * - Handed off, then rejected in the app: nothing runs. + * The approve and reject doors of the pending-confirmation service refuse + * an AI identity: an agent principal (`principalKind: 'agent'`, with or + * without `onBehalfOf`), and any call that arrives through an AI door. A + * person decides; an agent never decides for one. * 5. **The caller's `confirm` never counts.** On a declared-gated call the * member ({@link AI_ACTION_CONFIRMATION_MEMBER}) confers nothing: not with - * an elicitation, not in place of one, and not for a client that cannot - * elicit. An agent cannot answer for the person by sending it. + * an elicitation, not in place of one, not in place of a hand-off, and not + * when the host has no service. * 6. **An AI service account: unchanged** (ADR-0151 D3 rule 3). An agent * principal acting for itself, with no `onBehalfOf`, is refused whatever it - * sends, reason `service_account`. No elicitation is sent to it: no person - * stands behind the account, and its own client could answer one. + * sends, reason `service_account`. It is neither elicited (no person stands + * behind the account, and its own client could answer) nor handed off. The + * one admitted sequence asks this rule at every door that runs an action, + * so REST `/actions` and a host door carry the same `reason` on that + * refusal. * * Every refusal keeps the registered envelope: `428`, * `ACTION_CONFIRMATION_REQUIRED`, and `error.details` shaped as - * {@link ActionConfirmationRequiredDetails}, whose `reason` says which of the - * cases above it is. Nothing is parked or queued, as before: a refused call - * did not run, and no record was read or written for it. + * {@link ActionConfirmationRequiredDetails}, whose `reason` says which case + * above it is. A hand-off is not a refusal: it is the successful answer + * {@link ActionConfirmationPending}. + * + * ## What an answer proves + * + * An elicited `accept` proves that the CLIENT answered, not that a person + * did. The amendment closes the measured hole, an agent model answering for + * the person inside a client that would have asked its user; a caller that + * writes its own client can advertise `elicitation` and answer `accept` + * itself, bounded by its credentials as before. A hand-off is decided by a + * person signed in to the app, through doors that refuse an AI identity, and + * is the stronger of the two. * * ## Its bounds * @@ -499,47 +541,116 @@ export interface ActionConfirmationRequiredDetails { * * This text is the contract from the release that carries it. The doors * implement it in the change that enforces it, which also moves the shipped - * prescriptions that describe the member. Until that change, the doors - * still gate on the member as {@link AIActionConfirmation} describes, and that - * reading is the FROM half of the breaking note. + * prescriptions that describe the member. Until that change ships, every door + * still gates on the member as {@link AIActionConfirmation} describes: the + * MCP `run_action` and `resume_run` tools run a declared-gated action on + * `confirm: true`, over stdio and over Streamable HTTP alike, and that reading + * is the FROM half of the breaking note. * - * The door has to hold what the rules above need: the client's `initialize` - * capabilities for the session, and a way to send a request to the client - * while the call is open. The long-lived stdio server holds both. The - * stateless Streamable HTTP door (`handleHttpRequest` in + * Measured at the amendment: the long-lived stdio server keeps the client's + * `initialize` capabilities and can send a request to the client while a call + * is open. The Streamable HTTP door (`handleHttpRequest` in * `packages/mcp/src/mcp-server-runtime.ts`) builds a fresh server per request, - * issues no session id and answers in JSON, so as built it holds neither, and - * by rule 3 it refuses until the implementing change gives it both. + * issues no session id and answers in JSON, so as built it can do neither: + * under step 2 its callers are handed off. Whether, and how, that door comes + * to elicit is the implementing change's decision. */ export const AI_ACTION_CONFIRMATION_CAPABILITY = 'elicitation'; /** - * Why a declared-gated call was refused under the elicitation contract + * Why a declared-gated call was refused under the amended contract * ({@link AI_ACTION_CONFIRMATION_CAPABILITY}), carried as - * {@link ActionConfirmationRequiredDetails.reason}. A CLOSED set: + * {@link ActionConfirmationRequiredDetails.reason}. A CLOSED set; a hand-off is + * not among them, because it is not a refusal: * - * - `elicitation_unsupported`: the client did not advertise `elicitation` at - * `initialize`, or the door cannot carry one. Retrying from that client - * cannot succeed: the person uses a client that supports confirmation, or - * performs the action in the app. - * - `declined`: the person answered no. - * - `cancelled`: the person dismissed the question, the client answered the - * elicitation request with an error, or the connection dropped first. - * - `timed_out`: no answer within the door's bound. + * - `declined`: the person answered an elicitation with no. + * - `cancelled`: the person dismissed the elicitation, the client answered it + * with an error, or the connection dropped first. + * - `timed_out`: no answer to the elicitation within the door's bound. + * - `no_confirmation_service`: the client could not be elicited and the host + * has no pending-confirmation service ({@link IActionConfirmationService}). + * The person uses a client that supports confirmation, or performs the + * action in the app. * - `service_account`: an AI service account, which never confirms an action * for itself (ADR-0151 D3 rule 3). A person runs the action. */ export const ACTION_CONFIRMATION_REFUSAL_REASONS = [ - 'elicitation_unsupported', 'declined', 'cancelled', 'timed_out', + 'no_confirmation_service', 'service_account', ] as const; /** One member of {@link ACTION_CONFIRMATION_REFUSAL_REASONS}. */ export type ActionConfirmationRefusalReason = (typeof ACTION_CONFIRMATION_REFUSAL_REASONS)[number]; +/** + * The call an AI door hands to the host's pending-confirmation service (step 2 + * of {@link AI_ACTION_CONFIRMATION_CAPABILITY}): enough to show the person what + * they are asked to approve, and to run it again, as them, once they do. + */ +export interface ActionConfirmationHandOff { + /** The declarative action name the call addressed. */ + actionName: string; + /** The object the action operates on; omitted for object-less actions. */ + objectName?: string; + /** The package namespace the call qualified the action with, if any. */ + namespace?: string; + /** The record the action runs on, when it takes one. */ + recordId?: string; + /** The action params the call carried, after the door's own checks. */ + params: Record; + /** The AI door the call arrived through, e.g. `mcp`. */ + door: string; +} + +/** + * The answer an AI door gives the caller when it hands a declared-gated call + * off (step 2 of {@link AI_ACTION_CONFIRMATION_CAPABILITY}). A success, not a + * refusal: the call was accepted for a person's decision, and nothing has run. + */ +export interface ActionConfirmationPending { + /** The discriminant: the call waits on a person's confirmation in the app. */ + status: 'pending_confirmation'; + /** The pending item's id in the host's pending-confirmation service. */ + pendingId: string; + /** A plain message for the person: a confirmation was sent to them, and where to answer it. */ + message: string; + /** The declarative action name the call addressed. */ + actionName: string; + /** The object the action operates on; omitted for object-less actions. */ + objectName?: string; +} + +/** + * The host's pending-confirmation service: the hand-off seam of the amended + * contract ({@link AI_ACTION_CONFIRMATION_CAPABILITY}, step 2). OPTIONAL — a + * host without one refuses, reason `no_confirmation_service` (step 3), which + * is the case of a bare open-source deployment. + * + * The service owns what happens after the hand-off: it stores the pending + * item, shows it to the person in the app and notifies them, and serves the + * approve and reject doors. Those doors refuse an AI identity (an agent + * principal, with or without `onBehalfOf`, and any call through an AI door). + * On approval the action runs as the approving person through the same + * admitted sequence, every gate and permission re-checked; on rejection + * nothing runs. A host may build it over its own pending-action store; the + * `held` outcome of {@link IAIService.approvePendingAction} is the existing + * precedent for a write that waits on a person outside the conversation. + */ +export interface IActionConfirmationService { + /** + * Record `handOff` for the person the caller acts for, notify them, and + * return the pending item's id. Runs nothing. + * + * @param handOff - The call to confirm + * @param context - The caller's execution context: who is asked, and as + * whose call the item is recorded + */ + submit(handOff: ActionConfirmationHandOff, context: ExecutionContext): Promise<{ pendingId: string }>; +} + // --------------------------------------------------------------------------- // IAIService // --------------------------------------------------------------------------- diff --git a/packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts b/packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts index 34c082703ee..d8061a43dd9 100644 --- a/packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts +++ b/packages/spec/src/migrations/entries/semantic/18.action-requires-confirmation-elicited.ts @@ -4,36 +4,42 @@ import type { SemanticMigration } from '../../types.js'; // The confirmation contract of `ai.requiresConfirmation: true` is amended // (`AI_ACTION_CONFIRMATION_CAPABILITY`, `contracts/ai-service.ts`): a person -// confirms through MCP elicitation, and the caller's own `confirm: true` stops -// counting. A structured TODO, not a D2 conversion: nothing an author wrote is -// rewritten or refused, and whether a gated action still needs a person, and -// which clients its users run, is the author's judgement. +// confirms, elicited in the MCP client or handed off to the app, and the +// caller's own `confirm: true` stops counting once the doors implement it. A +// structured TODO, not a D2 conversion: nothing an author wrote is rewritten +// or refused, and whether a gated action still needs a person is the author's +// judgement. Written conditionally on purpose: in the release that first +// carries this entry the doors still gate on `confirm: true`. export const entry: SemanticMigration = { id: 'action-requires-confirmation-elicited', surface: 'objects[].actions[].ai.requiresConfirmation and actions[].ai.requiresConfirmation set to `true` — ' + 'what the declaration asks of a caller on the MCP `run_action` and `resume_run` tools', replacement: - 'Keep the declaration where a person must approve the call. What changes is who confirms: the server asks ' - + 'the person through the MCP client with an elicitation (`elicitation/create`, form mode), and only an ' - + 'accepted answer runs the action. A client that did not advertise the `elicitation` capability at ' - + '`initialize` is refused with `ACTION_CONFIRMATION_REQUIRED` (428) and `details.reason` ' - + '`elicitation_unsupported`; a declined, cancelled or unanswered question is refused the same way with ' - + 'reason `declined`, `cancelled` or `timed_out`, and nothing runs. The caller\'s own `confirm: true` no ' - + 'longer confirms anything. An AI service account acting for itself is still refused whatever it sends. ' - + 'The doors switch in the change that implements the contract: a refusal carrying no `details.reason` ' - + 'comes from a door that still reads the member.', + 'Read this against your runtime first. Until the release whose changelog says the AI doors confirm by ' + + 'elicitation, `run_action` and `resume_run` still run a declared-gated action on the caller\'s ' + + '`confirm: true`, and a call without it is refused with `ACTION_CONFIRMATION_REQUIRED` (428): keep sending ' + + 'it there. From that release, keep the declaration where a person must approve the call; what changes is ' + + 'who confirms. The server asks the person in the MCP client with an elicitation (`elicitation/create`, ' + + 'form mode) when the client advertised the `elicitation` capability at `initialize`; otherwise it hands ' + + 'the call to the host\'s pending-confirmation service, answers `status: \'pending_confirmation\'` with a ' + + 'pending id, and the person approves or rejects it in the app, where it runs as them with every ' + + 'permission re-checked. Only a host with no such service refuses, with `details.reason` ' + + '`no_confirmation_service`. From then on the caller\'s own `confirm: true` confirms nothing.', reason: '`confirm: true` was the caller\'s own claim that a person approved, and nothing could check it: an agent ' + 'could send it for an irreversible action on reading the person\'s instruction as consent, and measured ' + 'runs did exactly that. The gate made forgetting loud and did not prove a person. The server asking the ' - + 'person through the client, with the caller unable to answer for them, is what makes the declaration mean ' - + 'what an author who wrote it meant. No mechanical move applies: the metadata is unchanged, and the work is ' - + 'on the client side and in the author\'s decision about each gated action. ADR-0011 / ADR-0151 / ADR-0087.', + + 'person, in the client or in the app, with the caller unable to answer for them, is what makes the ' + + 'declaration mean what an author who wrote it meant. No mechanical move applies: the metadata is ' + + 'unchanged, and the work is on the client side and in the author\'s decision about each gated action. ' + + 'ADR-0011 / ADR-0151 / ADR-0087.', acceptanceCriteria: - 'For every action declaring `ai.requiresConfirmation: true`, decide again that a person must approve each AI ' - + 'call; if not, declare `false` knowingly. Tell the people who run those actions through an MCP client that ' - + 'the client must support elicitation, or that they perform the action in the app. A script or agent that ' - + 'sent `confirm: true` to run such an action unattended stops working by design: it is refused, and a person ' - + 'runs the action. Done when no caller relies on its own `confirm: true` for a declared-gated action.', + 'Now: for every action declaring `ai.requiresConfirmation: true`, decide again that a person must approve ' + + 'each AI call; if not, declare `false` knowingly. Once your runtime confirms by elicitation (its changelog ' + + 'says so; a refusal then carries `details.reason`): an MCP client that supports elicitation asks the ' + + 'person in place; any other caller gets a pending answer and the person decides in the app, provided the ' + + 'host runs a pending-confirmation service; a script or agent that ran such an action unattended on its ' + + 'own `confirm: true` no longer runs it, and a person does. Done when no caller relies on its own ' + + '`confirm: true` for a declared-gated action on a runtime that has switched.', }; From c0ebf0c35bbbebb02860e107d4d58f052f67b613 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 08:21:45 +0000 Subject: [PATCH 3/5] chore(spec): regenerate the contracts api-surface and export-origins baselines Claude-Session: https://claude.ai/code/session_01FEkQ5kZuoX9F5S7p84Dwue Co-Authored-By: Claude --- packages/spec/api-surface/contracts.json | 3 +++ packages/spec/export-origins/contracts.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/spec/api-surface/contracts.json b/packages/spec/api-surface/contracts.json index 44ddbf0a6dc..990dcf30c2d 100644 --- a/packages/spec/api-surface/contracts.json +++ b/packages/spec/api-surface/contracts.json @@ -25,6 +25,8 @@ "APPROVAL_STATUS_LABELS (const)", "AUDIT_CHECKPOINT_SIGNER_SERVICE (const)", "AUDIT_CHECKPOINT_SINK_SERVICE (const)", + "ActionConfirmationHandOff (interface)", + "ActionConfirmationPending (interface)", "ActionConfirmationRefusalReason (type)", "ActionConfirmationRequiredDetails (interface)", "AdapterContext (interface)", @@ -138,6 +140,7 @@ "HttpResponseObserver (type)", "IAIConversationService (interface)", "IAIService (interface)", + "IActionConfirmationService (interface)", "IAdvancedServiceRegistry (interface)", "IAnalyticsService (interface)", "IAppLifecycleService (interface)", diff --git a/packages/spec/export-origins/contracts.json b/packages/spec/export-origins/contracts.json index b5caf2d31e1..00cc24f305f 100644 --- a/packages/spec/export-origins/contracts.json +++ b/packages/spec/export-origins/contracts.json @@ -25,6 +25,8 @@ "APPROVAL_STATUS_LABELS": "src/contracts/approval-service.ts#APPROVAL_STATUS_LABELS (const)", "AUDIT_CHECKPOINT_SIGNER_SERVICE": "src/contracts/audit-checkpoint.ts#AUDIT_CHECKPOINT_SIGNER_SERVICE (const)", "AUDIT_CHECKPOINT_SINK_SERVICE": "src/contracts/audit-checkpoint.ts#AUDIT_CHECKPOINT_SINK_SERVICE (const)", + "ActionConfirmationHandOff": "src/contracts/ai-service.ts#ActionConfirmationHandOff (interface)", + "ActionConfirmationPending": "src/contracts/ai-service.ts#ActionConfirmationPending (interface)", "ActionConfirmationRefusalReason": "src/contracts/ai-service.ts#ActionConfirmationRefusalReason (type)", "ActionConfirmationRequiredDetails": "src/contracts/ai-service.ts#ActionConfirmationRequiredDetails (interface)", "AdapterContext": "src/contracts/knowledge-adapter.ts#AdapterContext (interface)", @@ -138,6 +140,7 @@ "HttpResponseObserver": "src/contracts/http-server.ts#HttpResponseObserver (type)", "IAIConversationService": "src/contracts/ai-service.ts#IAIConversationService (interface)", "IAIService": "src/contracts/ai-service.ts#IAIService (interface)", + "IActionConfirmationService": "src/contracts/ai-service.ts#IActionConfirmationService (interface)", "IAdvancedServiceRegistry": "src/contracts/service-registry.ts#IAdvancedServiceRegistry (interface)", "IAnalyticsService": "src/contracts/analytics-service.ts#IAnalyticsService (interface)", "IAppLifecycleService": "src/contracts/app-lifecycle-service.ts#IAppLifecycleService (interface)", From 836e1ff9840a874b38ef04d74d85fc3e2b08307c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:30:46 +0000 Subject: [PATCH 4/5] feat(spec): the confirmation hand-off carries a resume_run's run, names its service slot, and takes a person's signed-in session to decide Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5kZuoX9F5S7p84Dwue --- .../33689-ai-action-confirmation-elicited.md | 8 +- .../action-confirmation-contract.pin.test.ts | 59 ++++++++++-- packages/spec/src/contracts/ai-service.ts | 94 ++++++++++++++----- 3 files changed, 125 insertions(+), 36 deletions(-) diff --git a/.changeset/33689-ai-action-confirmation-elicited.md b/.changeset/33689-ai-action-confirmation-elicited.md index 2358ecdf1e2..b4c235240a3 100644 --- a/.changeset/33689-ai-action-confirmation-elicited.md +++ b/.changeset/33689-ai-action-confirmation-elicited.md @@ -4,7 +4,7 @@ feat(spec)!: a declared-gated action on an AI door is confirmed by a person, elicited in the MCP client or handed off to the app, never by the caller's own `confirm: true` -Clause-②: yes (narrowing) — once the doors implement the contract, a caller's `confirm: true` stops counting on an action declaring `ai.requiresConfirmation: true`; `@objectstack/spec/contracts` gains `AI_ACTION_CONFIRMATION_CAPABILITY`, `ACTION_CONFIRMATION_REFUSAL_REASONS`, `ActionConfirmationRefusalReason`, `ActionConfirmationHandOff`, `ActionConfirmationPending`, `IActionConfirmationService` and the optional `ActionConfirmationRequiredDetails.reason`. +Clause-②: yes (narrowing) — once the doors implement the contract, a caller's `confirm: true` stops counting on an action declaring `ai.requiresConfirmation: true`; `@objectstack/spec/contracts` gains `AI_ACTION_CONFIRMATION_CAPABILITY`, `ACTION_CONFIRMATION_REFUSAL_REASONS`, `ActionConfirmationRefusalReason`, `ActionConfirmationHandOff`, `ActionConfirmationPending`, `IActionConfirmationService`, `ACTION_CONFIRMATION_SERVICE` and the optional `ActionConfirmationRequiredDetails.reason`. Metadata-protocol: semantic Skills-docs: follow-up — `skills/objectstack-ai/SKILL.md` (the MCP tool table: `run_action` / `resume_run` "refused with the same 428 unless the call sends `confirm: true`") teaches the member contract, which is still the door's behaviour in this release; it moves with the change that implements the doors, together with the MCP-served skill text (`packages/mcp/src/skill-md.ts`, `ui/apps/console/src/pages/developer/objectstack-skill.ts`) and the `ToolSchema` prescription in `packages/spec/src/ai/tool.zod.ts`. @@ -14,12 +14,12 @@ Skills-docs: follow-up — `skills/objectstack-ai/SKILL.md` (the MCP tool table: ⚠ In the release that carries this changeset nothing changes at any door: `run_action` and `resume_run` still run a declared-gated action on `confirm: true` and refuse it without, over stdio and Streamable HTTP alike. Keep sending `confirm: true` until a release's changelog says the doors confirm by elicitation. What ships now is the contract the doors move to, in `@objectstack/spec/contracts` (`AI_ACTION_CONFIRMATION_CAPABILITY`, `contracts/ai-service.ts`): -- After every admission gate (the subject load included) and before anything runs, the person is asked, in three steps: **elicit** when the client advertised `elicitation` at `initialize` and the door can carry it (one `elicitation/create`, form mode); otherwise **hand off** to the host's pending-confirmation service (`IActionConfirmationService`), answering `status: 'pending_confirmation'` with a pending id and a plain message, the person then approving or rejecting in the app, where the action runs as them with every gate and permission re-checked; **refuse** only when the host has no such service (`428 ACTION_CONFIRMATION_REQUIRED`, `details.reason: 'no_confirmation_service'`). +- After every admission gate (the subject load included) and before anything runs, the person is asked, in three steps: **elicit** when the client advertised `elicitation` at `initialize` and the door can carry it (one `elicitation/create`, form mode); otherwise **hand off** to the host's pending-confirmation service (`IActionConfirmationService`, registered under `ACTION_CONFIRMATION_SERVICE` = `'ai.actionConfirmation'`), answering `status: 'pending_confirmation'` with a pending id and a plain message, the person the call ran as, and only they, then approving or rejecting in the app, where the action runs as them with every gate and permission re-checked; a handed-off `resume_run` carries its run id and values (`ActionConfirmationHandOff.run`), and approving it resumes that parked run, never a new one; **refuse** only when the host registers no such service (`428 ACTION_CONFIRMATION_REQUIRED`, `details.reason: 'no_confirmation_service'`). - An elicited `accept` runs the call once; `decline`, `cancel` (an error answer or a dropped connection included) and no answer within the door's bound are refused with reason `declined`, `cancelled` or `timed_out`. A call refused at confirmation may have read its subject and writes nothing. -- The approve and reject doors of the pending-confirmation service refuse an AI identity. +- The approve and reject doors of the pending-confirmation service take a person's signed-in session to the app and nothing else: they refuse an AI identity, and an API key, token or other service credential, whoever it resolves to. When a pending item lapses, and how the caller learns its outcome, are the host's to define. - The caller's `confirm` never counts on such a call. - An AI service account acting for itself is refused whatever it sends, unchanged (ADR-0151 D3 rule 3), with reason `service_account` on every door; it is neither elicited nor handed off. -- An elicited `accept` proves the client answered, not that a person did; a hand-off is decided by a person in the app. +- An elicited `accept` proves the client answered, not that a person did; an approved hand-off proves a signed-in session to the app answered, not that a person did. - Outside the amendment: the MCP `delete_record` and `delete_records` gates still read `confirm: true`, and REST `/actions` stays outside the gate for a person. The semantic entry `action-requires-confirmation-elicited` carries the same notice, with the same timing, into the upgrade guide and `os migrate meta`. diff --git a/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts b/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts index 3912f1dffc7..b2e0bdce8f0 100644 --- a/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts +++ b/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts @@ -52,6 +52,7 @@ import { fileURLToPath } from 'node:url'; import { ACTION_CONFIRMATION_REFUSAL_REASONS, + ACTION_CONFIRMATION_SERVICE, AI_ACTION_CONFIRMATION_CAPABILITY, AI_ACTION_CONFIRMATION_MEMBER, type AIActionConfirmation, @@ -156,10 +157,12 @@ describe('action-confirmation contract — an unconfirmed gated action is refuse * 「3826 照建议(征询版)」, objectstack-ai/cloud#3826 item 6, as amended on * the card). * - * Pinned here: the capability's spelling, the CLOSED refusal-reason set (a + * Pinned here: the capability's spelling, the service slot the hand-off seam + * is registered under, the CLOSED refusal-reason set (a * hand-off is not in it), that `details.reason` is typed to it and stays * optional while the member gates still answer without it, the pending - * answer's discriminant and the hand-off seam's shape, that the amendment adds + * answer's discriminant and the hand-off seam's shape (a `resume_run` call + * carries its run), that the amendment adds * no second refusal code, and that the contract's own text names every reason, * every answer and the three steps, so the types and the prose cannot drift * apart. NOT pinned: any door behaviour, which the implementing change lands @@ -184,6 +187,14 @@ describe('action-confirmation contract, as amended: a person confirms, elicited expect(AI_ACTION_CONFIRMATION_CAPABILITY).not.toBe(AI_ACTION_CONFIRMATION_MEMBER); }); + it('the hand-off seam has ONE service slot a door and a host agree on', () => { + expect(ACTION_CONFIRMATION_SERVICE).toBe('ai.actionConfirmation'); + // Step 3 turns on that slot, by name, and on nothing else. + expect(capabilityProse()).toContain( + '**Refuse**, only when the host registers no service under {@link ACTION_CONFIRMATION_SERVICE}', + ); + }); + it('the refusal reasons are a CLOSED set of exactly five', () => { expect([...ACTION_CONFIRMATION_REFUSAL_REASONS]).toEqual([ 'declined', @@ -224,7 +235,7 @@ describe('action-confirmation contract, as amended: a person confirms, elicited expect(ACTION_CONFIRMATION_REFUSAL_REASONS).toContain(reason); }); - it('a hand-off answers with the pending discriminant, through an optional host seam', () => { + it('a hand-off answers with the pending discriminant, through an optional host seam', async () => { const pending: ActionConfirmationPending = { status: 'pending_confirmation', pendingId: 'pc_1', @@ -246,10 +257,23 @@ describe('action-confirmation contract, as amended: a person confirms, elicited const handOff: ActionConfirmationHandOff = { actionName: 'archive_account', objectName: 'account', recordId: 'a1', params: {}, door: 'mcp', }; + // A `resume_run` hand-off carries the parked run and the screen's values, + // so approving it resumes THAT run rather than starting a new one. + const resumeHandOff: ActionConfirmationHandOff = { + actionName: 'approve_discount', params: {}, door: 'mcp', + run: { runId: 'run_7', values: { discount: 12 } }, + }; + const runWithoutValues: ActionConfirmationHandOff = { + actionName: 'approve_discount', params: {}, door: 'mcp', + // @ts-expect-error — the run leg carries the values it resumes with. + run: { runId: 'run_7' }, + }; + expect(runWithoutValues.run?.runId).toBe('run_7'); const service: IActionConfirmationService = { - submit: async (h) => ({ pendingId: `pc_${h.actionName}` }), + submit: async (h) => ({ pendingId: h.run ? `pc_resume_${h.run.runId}` : `pc_${h.actionName}` }), }; - return expect(service.submit(handOff, {} as never)).resolves.toEqual({ pendingId: 'pc_archive_account' }); + await expect(service.submit(handOff, {} as never)).resolves.toEqual({ pendingId: 'pc_archive_account' }); + await expect(service.submit(resumeHandOff, {} as never)).resolves.toEqual({ pendingId: 'pc_resume_run_7' }); }); it('the amendment keeps ONE refusal code: no second code is registered for it', () => { @@ -268,20 +292,37 @@ describe('action-confirmation contract, as amended: a person confirms, elicited for (const answer of ['`accept`', '`decline`', '`cancel`', 'timed out', 'then approved in the app', 'then rejected in the app']) { expect(prose, `the contract no longer says what ${answer} does`).toContain(answer); } - for (const step of ['**Elicit**', '**Hand off**', '**Refuse**, only when the host has no pending-confirmation service']) { + for (const step of ['**Elicit**', '**Hand off**', '**Refuse**, only when the host registers no service']) { expect(prose, `the contract dropped the step ${step}`).toContain(step); } - expect(prose, 'the contract dropped the AI-identity refusal on the approve and reject doors').toMatch( - /approve and reject doors of the pending-confirmation service refuse an AI identity/, + expect(prose, 'the approve and reject doors no longer take only a person\'s signed-in session').toMatch( + /approve and reject doors of the pending-confirmation service take a person's signed-in session to the app and nothing else/, + ); + expect(prose, 'the contract dropped the AI-identity refusal on the approve and reject doors').toMatch(/They refuse an AI identity/); + expect(prose, 'the approve and reject doors no longer refuse a credential that resolves to the person').toMatch( + /also refuse an API key, a delegated or OAuth token and any other service credential, whoever it resolves to/, + ); + expect(prose, 'the contract no longer says who decides a pending item').toMatch( + /The person who approves or rejects is the person the call ran as .*and nobody else/, + ); + expect(prose, 'the contract no longer leaves lapse and outcome delivery to the host').toMatch( + /When a pending item lapses, and how the caller learns its outcome, are the host's to define and outside this contract/, + ); + expect(prose, 'approving a handed-off resume_run no longer resumes the parked run').toMatch( + /approving it resumes THAT parked run with the values the call carried, as the approver, who must be the run's owner as today; it never starts a new run/, ); expect(prose, 'the contract dropped the re-check at approval').toMatch(/every gate and permission re-checked/); expect(prose, 'the contract dropped the trust bound of an elicited answer').toMatch(/proves that the CLIENT answered, not that a person did/); + expect(prose, 'the contract dropped the trust bound of an approved hand-off').toMatch( + /An approval of a hand-off proves that a signed-in session to the app answered, not that a person did/, + ); + expect(prose, 'the contract claims a hand-off proves a person again').not.toMatch(/is the stronger of the two/); expect(prose, 'the contract claims a refused call read nothing again').not.toMatch(/no record was read/); expect(prose, 'the contract dropped "the caller\'s `confirm` never counts"').toMatch(/The caller's `confirm` never counts/); expect(prose, 'the contract dropped the unchanged AI service account rule').toMatch( /An AI service account: unchanged\*\* \(ADR-0151 D3 rule 3\)/, ); - expect(prose, 'the refusal for a client without elicitation no longer names the remedy').toMatch( + expect(prose, 'the refusal for a host without the pending-confirmation service no longer names the remedy').toMatch( /use a client that supports confirmation, or to perform the action in the app/, ); }); diff --git a/packages/spec/src/contracts/ai-service.ts b/packages/spec/src/contracts/ai-service.ts index f259f76ae2d..c73c190e56b 100644 --- a/packages/spec/src/contracts/ai-service.ts +++ b/packages/spec/src/contracts/ai-service.ts @@ -467,15 +467,22 @@ export interface ActionConfirmationRequiredDetails { * (MCP 2025-11-25). The answer is the result's `action` alone; any * `content` is not read. * 2. **Hand off**, otherwise: the door hands the call to the host's - * pending-confirmation service ({@link IActionConfirmationService}) and + * pending-confirmation service ({@link IActionConfirmationService}, the + * service registered under {@link ACTION_CONFIRMATION_SERVICE}) and * answers the caller with {@link ActionConfirmationPending}: a pending * id and a plain message that a confirmation was sent to the person. * Nothing runs then. The host shows the pending item to the person in * the app and notifies them (an emailed link, for example); the person - * signs in and approves or rejects it there. - * 3. **Refuse**, only when the host has no pending-confirmation service: - * reason `no_confirmation_service`. The message tells the person to use - * a client that supports confirmation, or to perform the action in the + * signs in and approves or rejects it there. The person who approves or + * rejects is the person the call ran as (its `userId`, the person an + * agent acts for), and nobody else: another user who can see the item + * cannot decide it. When a pending item lapses, + * and how the caller learns its outcome, are the host's to define and + * outside this contract. + * 3. **Refuse**, only when the host registers no service under + * {@link ACTION_CONFIRMATION_SERVICE}: reason + * `no_confirmation_service`. The message tells the person to use a + * client that supports confirmation, or to perform the action in the * app. * A door or a client that cannot elicit is never refused for that alone: * it takes step 2, or step 3 when the host has no service. No step ever @@ -496,12 +503,20 @@ export interface ActionConfirmationRequiredDetails { * - Handed off, then approved in the app: the action runs as the person * who approved it, through the same admitted sequence, every gate and * permission re-checked at that moment; a refusal there runs nothing and - * is recorded on the pending item. + * is recorded on the pending item. A handed-off `resume_run` call + * carries its run ({@link ActionConfirmationHandOff.run}): approving it + * resumes THAT parked run with the values the call carried, as the + * approver, who must be the run's owner as today; it never starts a new + * run of the flow. * - Handed off, then rejected in the app: nothing runs. - * The approve and reject doors of the pending-confirmation service refuse - * an AI identity: an agent principal (`principalKind: 'agent'`, with or - * without `onBehalfOf`), and any call that arrives through an AI door. A - * person decides; an agent never decides for one. + * The approve and reject doors of the pending-confirmation service take a + * person's signed-in session to the app and nothing else. They refuse an + * AI identity: an agent principal (`principalKind: 'agent'`, with or + * without `onBehalfOf`), and any call that arrives through an AI door. They + * also refuse an API key, a delegated or OAuth token and any other service + * credential, whoever it resolves to: a person's own API key resolves as + * that person, and is refused there all the same. A person decides; an + * agent, a script or a credential never decides for one. * 5. **The caller's `confirm` never counts.** On a declared-gated call the * member ({@link AI_ACTION_CONFIRMATION_MEMBER}) confers nothing: not with * an elicitation, not in place of one, not in place of a hand-off, and not @@ -526,9 +541,15 @@ export interface ActionConfirmationRequiredDetails { * did. The amendment closes the measured hole, an agent model answering for * the person inside a client that would have asked its user; a caller that * writes its own client can advertise `elicitation` and answer `accept` - * itself, bounded by its credentials as before. A hand-off is decided by a - * person signed in to the app, through doors that refuse an AI identity, and - * is the stronger of the two. + * itself, bounded by its credentials as before. + * + * An approval of a hand-off proves that a signed-in session to the app + * answered, not that a person did: the approve and reject doors refuse every + * credential but a person's session, so a caller holding only the person's + * API key or token cannot approve its own hand-off, and one that holds the + * person's session (their password, or a browser they are signed in to) can, + * bounded by that session as any action in the app is. Each answer is as + * strong as what it takes to give it; neither proves a human. * * ## Its bounds * @@ -568,7 +589,8 @@ export const AI_ACTION_CONFIRMATION_CAPABILITY = 'elicitation'; * with an error, or the connection dropped first. * - `timed_out`: no answer to the elicitation within the door's bound. * - `no_confirmation_service`: the client could not be elicited and the host - * has no pending-confirmation service ({@link IActionConfirmationService}). + * registers no pending-confirmation service ({@link IActionConfirmationService}) + * under {@link ACTION_CONFIRMATION_SERVICE}. * The person uses a client that supports confirmation, or performs the * action in the app. * - `service_account`: an AI service account, which never confirms an action @@ -603,6 +625,18 @@ export interface ActionConfirmationHandOff { params: Record; /** The AI door the call arrived through, e.g. `mcp`. */ door: string; + /** + * The parked run a `resume_run` call continues: present exactly when the + * call is a `resume_run`, absent for `run_action`. Approval resumes this + * run with `values`, as the approver, who must be the run's owner; it + * never starts a new run, and `params` is then empty. + */ + run?: { + /** The paused run the call resumes. */ + runId: string; + /** The screen's field values the call carried. */ + values: Record; + }; } /** @@ -623,19 +657,33 @@ export interface ActionConfirmationPending { objectName?: string; } +/** + * The service slot a {@link IActionConfirmationService} is registered under + * (step 2 of {@link AI_ACTION_CONFIRMATION_CAPABILITY}). The open build ships + * none; with none registered, a door that cannot elicit refuses, reason + * `no_confirmation_service` (step 3). + */ +export const ACTION_CONFIRMATION_SERVICE = 'ai.actionConfirmation'; + /** * The host's pending-confirmation service: the hand-off seam of the amended - * contract ({@link AI_ACTION_CONFIRMATION_CAPABILITY}, step 2). OPTIONAL — a - * host without one refuses, reason `no_confirmation_service` (step 3), which - * is the case of a bare open-source deployment. + * contract ({@link AI_ACTION_CONFIRMATION_CAPABILITY}, step 2), registered + * under {@link ACTION_CONFIRMATION_SERVICE}. OPTIONAL — a host without one + * refuses, reason `no_confirmation_service` (step 3), which is the case of a + * bare open-source deployment. * * The service owns what happens after the hand-off: it stores the pending - * item, shows it to the person in the app and notifies them, and serves the - * approve and reject doors. Those doors refuse an AI identity (an agent - * principal, with or without `onBehalfOf`, and any call through an AI door). - * On approval the action runs as the approving person through the same - * admitted sequence, every gate and permission re-checked; on rejection - * nothing runs. A host may build it over its own pending-action store; the + * item, shows it to the person the call ran as in the app and notifies them, + * and serves the approve and reject doors. Only that person decides the item. + * Those doors take a person's signed-in session and nothing else: they refuse + * an AI identity (an agent principal, with or without `onBehalfOf`, and any + * call through an AI door) and an API key, token or other service credential, + * whoever it resolves to. On approval the action runs as the approving person + * through the same admitted sequence, every gate and permission re-checked; a + * hand-off that carries a run ({@link ActionConfirmationHandOff.run}) resumes + * that run instead of starting one. On rejection nothing runs. When an item + * lapses, and how the caller learns its outcome, are the host's to define. A + * host may build it over its own pending-action store; the * `held` outcome of {@link IAIService.approvePendingAction} is the existing * precedent for a write that waits on a person outside the conversation. */ From c126efd64cfbedd2a534d2e91a045feba00cc695 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:32:11 +0000 Subject: [PATCH 5/5] chore(spec): regenerate the contracts api-surface and export-origins baselines Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5kZuoX9F5S7p84Dwue --- packages/spec/api-surface/contracts.json | 1 + packages/spec/export-origins/contracts.json | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/spec/api-surface/contracts.json b/packages/spec/api-surface/contracts.json index 990dcf30c2d..062f768ad51 100644 --- a/packages/spec/api-surface/contracts.json +++ b/packages/spec/api-surface/contracts.json @@ -3,6 +3,7 @@ "entry": "./contracts", "exports": [ "ACTION_CONFIRMATION_REFUSAL_REASONS (const)", + "ACTION_CONFIRMATION_SERVICE (const)", "AIActionConfirmation (interface)", "AIConversation (interface)", "AIMessage (type)", diff --git a/packages/spec/export-origins/contracts.json b/packages/spec/export-origins/contracts.json index 00cc24f305f..136cdb67531 100644 --- a/packages/spec/export-origins/contracts.json +++ b/packages/spec/export-origins/contracts.json @@ -3,6 +3,7 @@ "entry": "./contracts", "exports": { "ACTION_CONFIRMATION_REFUSAL_REASONS": "src/contracts/ai-service.ts#ACTION_CONFIRMATION_REFUSAL_REASONS (const)", + "ACTION_CONFIRMATION_SERVICE": "src/contracts/ai-service.ts#ACTION_CONFIRMATION_SERVICE (const)", "AIActionConfirmation": "src/contracts/ai-service.ts#AIActionConfirmation (interface)", "AIConversation": "src/contracts/ai-service.ts#AIConversation (interface)", "AIMessage": "src/contracts/ai-service.ts#AIMessage (type)",