diff --git a/.changeset/33808-ai-door-confirmation-in-app.md b/.changeset/33808-ai-door-confirmation-in-app.md new file mode 100644 index 00000000000..c19a4a182f2 --- /dev/null +++ b/.changeset/33808-ai-door-confirmation-in-app.md @@ -0,0 +1,30 @@ +--- +'@objectstack/spec': minor +--- + +feat(spec)!: the AI-door confirmation rule binds every AI door, the in-app assistant included, through its own pending-action channel + +Clause-②: no (narrowing) — once the in-app door implements the contract, a holder of `ai:approve` can no longer approve or reject someone else's in-app pending action, and the in-app approve and reject doors refuse every credential but a person's signed-in session to the app; nothing is widened, and no export, type or signature changes. +Metadata-protocol: semantic +Skills-docs: follow-up — `skills/objectstack-ai/SKILL.md` (the "AI Pending Actions" paragraph: "an operator approves or rejects in Studio's AI Pending Actions inbox (or via `GET/POST /api/v1/ai/pending-actions/...`)") still describes today's queue, which is the door's behaviour in this release; it moves with the change that implements the in-app door, together with `content/docs/api/client-sdk.mdx` ("deciding takes `ai:approve`") and the `client.ai.pendingActions` docblock in `packages/client/src/index.ts`. + + + +**BREAKING, when the implementing change ships**, for an inbox operator or administrator who approves or rejects another user's in-app AI pending action, and for a script, integration or host that decides pending actions on an API key or token. Ruled on the AI-door confirmation decision (record 6893484458): 「B 同一规则,两套流程暂留」. + +⚠ In the release that carries this changeset nothing changes at any door. The in-app assistant still runs ADR-0011's queue as documented: any holder of `ai:approve` may decide an item, the approve and reject routes take whatever credential they authenticate, and an approved item is re-dispatched as before. What ships now is the contract that door moves to, in `@objectstack/spec/contracts` (`AI_ACTION_CONFIRMATION_CAPABILITY` and the `IAIService` pending-action members, `contracts/ai-service.ts`): + +- Rule 1 covers every AI door that starts an action declaring `ai.requiresConfirmation: true`: the MCP `run_action` and `resume_run` tools and the in-app assistant's action tools. +- The in-app door keeps its own channel, the inline pending-approval card and the inbox (`IAIService.proposePendingAction` / `approvePendingAction` / `rejectPendingAction`, unchanged). When that channel is not wired, the door does not offer a declared-gated action as a tool at all. +- Who decides: only the person the call ran as. Holding `ai:approve`, or any other permission, does not let another user decide an item; a host that wants a second person to approve the write uses the existing `held` outcome. +- Which credential: the approve and reject doors take a person's signed-in session to the app and nothing else; an API key, token, other service credential or AI identity is refused, whoever it resolves to. +- As whom it runs: an approved item runs as that person, never as a synthetic AI principal, with every gate and permission re-checked at the moment of approval. +- The three points bind every item in the in-app queue, whichever trigger queued it (the declared flag or the destructive heuristic): a pending row does not record why it was queued, and the queue has one decider rule. +- Neither the model's own confirmation nor the caller's `confirm` counts. The in-app queue and the pending-confirmation service (`IActionConfirmationService`) stay two seams. + +The semantic entry `in-app-pending-action-decided-by-person` carries the same notice, with the same timing, into the upgrade guide and `os migrate meta`. + +What changes for a caller, from the release whose in-app door implements it: + +- FROM an operator or administrator approving another user's in-app pending action in the inbox TO the person the call ran as approving it; a second approver is a `held` item in the approvals engine. +- FROM approving or rejecting through `POST /api/v1/ai/pending-actions/:id/approve|reject` with an API key or bearer token TO the person's signed-in session to the app. 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 b2e0bdce8f0..b6dd6777c6e 100644 --- a/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts +++ b/packages/spec/src/contracts/action-confirmation-contract.pin.test.ts @@ -165,7 +165,9 @@ describe('action-confirmation contract — an unconfirmed gated action is refuse * 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 + * apart. Also pinned: that the rule binds every AI door, the in-app assistant + * included, which keeps its own channel under the same three points (who + * decides, which credential, as whom it runs; #33689 Q1 ruled B). NOT pinned: any door behaviour, which the implementing change lands * and pins. */ describe('action-confirmation contract, as amended: a person confirms, elicited or handed off', () => { @@ -326,4 +328,54 @@ describe('action-confirmation contract, as amended: a person confirms, elicited /use a client that supports confirmation, or to perform the action in the app/, ); }); + + it('the rule binds EVERY AI door, the in-app assistant included, through its own channel', () => { + // #33689 Q1, ruled B (record 6893484458, 「B 同一规则,两套流程暂留」): one + // rule for every AI door; the in-app queue stays its own channel. + const prose = capabilityProse(); + expect(prose, 'rule 1 no longer covers every AI door').toMatch( + /through EVERY AI door that starts one: the MCP `run_action` tool, the MCP `resume_run` tool for the candidate action it would run, and the in-app assistant's action tools/, + ); + // Control: the MCP-only reading of rule 1 is gone, not merely joined. + expect(prose, 'rule 1 reads as MCP-only again').not.toMatch( + /through an AI door: the MCP `run_action` tool, and the MCP `resume_run` tool for the candidate action it would run\. Every caller/, + ); + expect(prose, 'the in-app door lost its section').toContain('## The in-app assistant door: the same rule, its own channel'); + expect(prose, 'the in-app door no longer withholds a declared-gated action when its channel is not wired').toMatch( + /When that channel is not wired .* the door does not offer a declared-gated action as a tool at all/, + ); + expect(prose, 'the in-app door no longer limits the decision to the person the call ran as').toMatch( + /\*\*Who decides\.\*\* Only the person the call ran as .* approves or rejects the item\. Holding `ai:approve`, or any other permission, does not let another user decide it\./, + ); + expect(prose, 'the second-person path is no longer the existing held outcome').toMatch( + /A host that wants a second person to approve the write uses the existing `held` outcome/, + ); + expect(prose, 'the in-app deciding doors no longer take only a signed-in session').toMatch( + /\*\*Which credential\.\*\* The approve and reject doors take a person's signed-in session to the app and nothing else/, + ); + expect(prose, 'the in-app deciding doors no longer refuse a credential or an AI identity').toMatch( + /an API key, a delegated or OAuth token and any other service credential are refused, whoever it resolves to, and so is an AI identity/, + ); + expect(prose, 'an approved in-app item no longer runs as the person with every gate re-checked').toMatch( + /\*\*As whom it runs\.\*\* An approved item runs as that person, never as a synthetic AI principal, through the same admitted sequence as any action call, every gate and permission re-checked/, + ); + expect(prose, 'the in-app door no longer says the model\'s own confirmation does not count').toMatch( + /Neither the model's own confirmation nor the caller's `confirm` counts/, + ); + expect(prose, 'the three points no longer bind every in-app queued item, whichever trigger queued it').toMatch( + /The three points bind EVERY item in the in-app queue, whichever trigger queued it: an action declaring `ai\.requiresConfirmation: true`, or one the destructive heuristic gates/, + ); + expect(prose, 'the contract no longer says why the in-app queue has one decider rule').toMatch( + /A pending row does not record why it was queued, and the queue has one decider rule/, + ); + // Control: the MCP doors' reach is still the DECLARED flag alone; the + // in-app queue's wider reach must not leak into rule 1. + expect(prose, 'rule 1 lost its DECLARED-flag predicate').toMatch( + /`ai\.requiresConfirmation: true` \(the DECLARED flag, never the listing heuristic;/, + ); + expect(prose, 'the contract claims the two seams were merged').toMatch(/stay two seams; the rule that binds them is one/); + expect(prose, 'the FROM half of the in-app door is no longer stated').toMatch( + /The in-app door likewise runs ADR-0011's queue as documented until its implementing change ships: any holder of `ai:approve` may decide an item/, + ); + }); }); diff --git a/packages/spec/src/contracts/ai-service.test.ts b/packages/spec/src/contracts/ai-service.test.ts index ff1c553435b..4fed3b1ec97 100644 --- a/packages/spec/src/contracts/ai-service.test.ts +++ b/packages/spec/src/contracts/ai-service.test.ts @@ -1,4 +1,7 @@ import { describe, it, expect } from 'vitest'; +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; import type { IAIService, AIResult, @@ -445,3 +448,63 @@ describe('approvePendingAction held outcome', () => { expect(status).toBe('held'); }); }); + +/** + * The in-app assistant door's three points, stated on the pending-action + * members themselves (#33689 Q1, ruled B: one rule for every AI door, the + * in-app queue kept as its own channel). The members' signatures do not move, + * so what is pinned is the docblock text an implementer reads beside them: + * who decides, which credential, and as whom the approved action runs. + */ +describe('IAIService pending-action members state the in-app door\'s three points', () => { + const HERE = dirname(fileURLToPath(import.meta.url)); + const SOURCE = readFileSync(join(HERE, 'ai-service.ts'), 'utf8'); + + /** The docblock above ` ?(`, comment gutters folded into spaces. */ + function memberDoc(member: string): string { + const at = SOURCE.indexOf(` ${member}?(`); + expect(at, `\`${member}\` moved — re-anchor this pin`).toBeGreaterThan(-1); + const open = SOURCE.lastIndexOf('/**', at); + const close = SOURCE.indexOf('*/', open); + expect(close, `\`${member}\` has no docblock directly above it`).toBeLessThan(at); + return SOURCE.slice(open, close).replace(/\n\s*\*\s?/g, ' ').replace(/\s+/g, ' '); + } + + it('proposePendingAction names the channel and binds all three points from the moment it is recorded', () => { + const doc = memberDoc('proposePendingAction'); + expect(doc).toMatch(/in-app assistant door's channel of the confirmation rule/); + expect(doc).toMatch(/\*\*Who decides:\*\* only the person the call ran as, recorded as `proposedBy`; no other user decides it, whatever permission they hold, `ai:approve` included/); + expect(doc).toMatch(/\*\*Which credential:\*\* the item is decided on that person's signed-in session to the app, never on an API key, token or AI identity/); + expect(doc).toMatch(/\*\*As whom it runs:\*\* once approved, as that person, every gate and permission re-checked/); + // A declared-gated action is queued, not only the destructive heuristic. + expect(doc).toMatch(/declares `ai\.requiresConfirmation: true`/); + }); + + it('approvePendingAction refuses another user and a non-session credential, and runs as the person', () => { + const doc = memberDoc('approvePendingAction'); + expect(doc).toMatch(/`actorId` must be the person the call ran as \(the row's `proposed_by`\)\. Another user is refused whatever permission they hold, `ai:approve` included/); + expect(doc).toMatch(/admits only a person's signed-in session to the app; an API key, a delegated or OAuth token, any other service credential and an AI identity are refused/); + expect(doc).toMatch(/the re-dispatch runs as that person, through the same admitted sequence as any action call, every gate and permission re-checked at this moment/); + // The second-person path is `held`, never a second decider. + expect(doc).toMatch(/second person to approve the write does not let that person decide the item: it uses `held`/); + // Control: the held outcome text this pin sits beside is still there, so + // the anchor read the right docblock. + expect(doc).toMatch(/`held` is the third outcome/); + }); + + it('rejectPendingAction binds the deciding points and runs nothing', () => { + const doc = memberDoc('rejectPendingAction'); + expect(doc).toMatch(/Nothing runs\./); + expect(doc).toMatch(/`actorId` must be the person the call ran as \(the row's `proposed_by`\), whatever permission another user holds, `ai:approve` included/); + expect(doc).toMatch(/admits only that person's signed-in session to the app, never an API key, token or AI identity/); + }); + + it('the read member is not a deciding door: listPendingActions carries none of the three points', () => { + // Control leg: the helper does not answer every member with the same + // text. Listing is not deciding, and the ruling moved no read. + const doc = memberDoc('listPendingActions'); + expect(doc).toMatch(/Inbox query/); + expect(doc).not.toMatch(/Who decides/); + expect(doc).not.toMatch(/signed-in session/); + }); +}); diff --git a/packages/spec/src/contracts/ai-service.ts b/packages/spec/src/contracts/ai-service.ts index c73c190e56b..3f1c8285307 100644 --- a/packages/spec/src/contracts/ai-service.ts +++ b/packages/spec/src/contracts/ai-service.ts @@ -446,11 +446,15 @@ export interface ActionConfirmationRequiredDetails { * * 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 acting for a person is - * covered, OAuth token or API key, a person or an agent acting for one - * (`onBehalfOf`). + * heuristic; {@link AIActionConfirmation} keeps that predicate), through + * EVERY AI door that starts one: the MCP `run_action` tool, the MCP + * `resume_run` tool for the candidate action it would run, and the in-app + * assistant's action tools (the actions-as-tools runtime of ADR-0011). Every + * caller acting for a person is covered, OAuth token, API key or a session + * to the app, a person or an agent acting for one (`onBehalfOf`). Rules 2 + * to 4 below are the MCP doors' channel. The in-app door asks through its + * own channel, under "The in-app assistant door" below; rules 5 and 6 bind + * it as written. * 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 @@ -535,6 +539,51 @@ export interface ActionConfirmationRequiredDetails { * above it is. A hand-off is not a refusal: it is the successful answer * {@link ActionConfirmationPending}. * + * ## The in-app assistant door: the same rule, its own channel + * + * Ruled on #33689 (record 6893484458, 「B 同一规则,两套流程暂留」): the rule + * binds every AI door, the in-app assistant included, and the in-app door + * keeps its own channel. Merging the two channels was not ruled. + * + * The in-app assistant asks through the pending-action queue of + * {@link IAIService}: the call is recorded as a pending action + * ({@link IAIService.proposePendingAction}), the tool answers the model + * `pending_approval`, and the person is shown the item as an inline + * pending-approval card in the conversation and in the inbox. Nothing runs + * until the item is decided. When that channel is not wired (no AI service + * that records pending actions, or the host has not turned the queue on), + * the door does not offer a declared-gated action as a tool at all: it is + * neither run unconfirmed nor offered and then refused. Three points bind the + * in-app door, the same three that bind a hand-off: + * + * 1. **Who decides.** Only the person the call ran as (the conversation's + * user, the person an agent acts for) approves or rejects the item. Holding + * `ai:approve`, or any other permission, does not let another user decide + * it. A host that wants a second person to approve the write uses the + * existing `held` outcome of {@link IAIService.approvePendingAction}: the + * person approves, and the write waits on the approvals engine. + * 2. **Which credential.** The approve and reject doors take a person's + * signed-in session to the app and nothing else, exactly as the + * pending-confirmation service's doors do (rule 4): an API key, a delegated + * or OAuth token and any other service credential are refused, whoever it + * resolves to, and so is an AI identity (an agent principal, with or + * without `onBehalfOf`, and any call that arrives through an AI door). + * 3. **As whom it runs.** An approved item runs as that person, never as a + * synthetic AI principal, through the same admitted sequence as any action + * call, every gate and permission re-checked at the moment of approval. A + * refusal there runs nothing and is recorded on the item as `failed`. + * + * The three points bind EVERY item in the in-app queue, whichever trigger + * queued it: an action declaring `ai.requiresConfirmation: true`, or one the + * destructive heuristic gates (ADR-0011's confirmation table). A pending row + * does not record why it was queued, and the queue has one decider rule; an + * administrator who is to approve as well does so through `held`, never by + * deciding the person's item. + * + * Neither the model's own confirmation nor the caller's `confirm` counts + * (rule 5): the item waits for the person. An approval proves what an approved + * hand-off proves, that a signed-in session to the app answered. + * * ## What an answer proves * * An elicited `accept` proves that the CLIENT answered, not that a person @@ -557,6 +606,9 @@ export interface ActionConfirmationRequiredDetails { * 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. + * - The in-app door's pending-action queue and the pending-confirmation + * service ({@link IActionConfirmationService}) stay two seams; the rule + * that binds them is one. * * ## When it binds * @@ -566,7 +618,12 @@ export interface ActionConfirmationRequiredDetails { * 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. + * is the FROM half of the breaking note. The in-app door likewise runs + * ADR-0011's queue as documented until its implementing change ships: any + * holder of `ai:approve` may decide an item, the approve and reject doors take + * whatever credential they authenticate, and an approved item is re-dispatched + * through the pre-registered dispatcher of ADR-0011's invocation flow. That + * reading is the FROM half for the in-app door's three points. * * 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 @@ -788,11 +845,25 @@ export interface IAIService { * Persist a proposed AI-initiated action that requires human approval * before execution. Used by the actions-as-tools runtime when the * picked action is dangerous (delete / danger variant / has - * `confirmText`) and `enableActionApproval` is on. + * `confirmText`) or declares `ai.requiresConfirmation: true`, and + * `enableActionApproval` is on. * * Implementations write a row to `ai_pending_actions` and return * its id. The caller (the tool handler) immediately returns a * `{ status: 'pending_approval' }` envelope to the LLM. + * + * This is the in-app assistant door's channel of the confirmation rule + * ({@link AI_ACTION_CONFIRMATION_CAPABILITY}, "The in-app assistant + * door"), and its three points bind the item from the moment it is + * recorded: + * + * 1. **Who decides:** only the person the call ran as, recorded as + * `proposedBy`; no other user decides it, whatever permission they + * hold, `ai:approve` included. + * 2. **Which credential:** the item is decided on that person's signed-in + * session to the app, never on an API key, token or AI identity. + * 3. **As whom it runs:** once approved, as that person, every gate and + * permission re-checked. */ proposePendingAction?(input: ProposePendingActionInput): Promise<{ id: string }>; @@ -802,6 +873,24 @@ export interface IAIService { * required. Updates the row to `executed` (or `failed`) and returns * the outcome. * + * The three points of the in-app assistant door + * ({@link AI_ACTION_CONFIRMATION_CAPABILITY}) bind it: + * + * 1. **Who decides:** `actorId` must be the person the call ran as (the + * row's `proposed_by`). Another user is refused whatever permission + * they hold, `ai:approve` included, and the row stays `pending`. + * 2. **Which credential:** the door that calls this member admits only a + * person's signed-in session to the app; an API key, a delegated or + * OAuth token, any other service credential and an AI identity are + * refused before it is called, whoever they resolve to. + * 3. **As whom it runs:** the re-dispatch runs as that person, through + * the same admitted sequence as any action call, every gate and + * permission re-checked at this moment. A refusal there runs nothing + * and the row is `failed`. + * + * A host that wants a second person to approve the write does not let + * that person decide the item: it uses `held`, below. + * * `held` is the third outcome: the confirmation was accepted, and the * write waits on an approval outside the conversation, because a host * policy held it for a human approver. Nothing has been written yet, @@ -818,6 +907,15 @@ export interface IAIService { /** * Reject a pending action. The row transitions to `rejected` and the * optional `reason` is stored so the next LLM turn can surface it. + * Nothing runs. + * + * The deciding points of the in-app assistant door + * ({@link AI_ACTION_CONFIRMATION_CAPABILITY}) bind it as they bind + * {@link IAIService.approvePendingAction}: `actorId` must be the person + * the call ran as (the row's `proposed_by`), whatever permission another + * user holds, `ai:approve` included; and the door that calls this member + * admits only that person's signed-in session to the app, never an API + * key, token or AI identity. */ rejectPendingAction?(id: string, actorId: string, reason?: string): Promise; diff --git a/packages/spec/src/migrations/entries/semantic/18.in-app-pending-action-decided-by-person.ts b/packages/spec/src/migrations/entries/semantic/18.in-app-pending-action-decided-by-person.ts new file mode 100644 index 00000000000..5bbc4211470 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.in-app-pending-action-decided-by-person.ts @@ -0,0 +1,43 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// The confirmation rule of `AI_ACTION_CONFIRMATION_CAPABILITY` +// (`contracts/ai-service.ts`) now binds the in-app assistant door too, through +// its own pending-action queue (`IAIService.proposePendingAction` / +// `approvePendingAction` / `rejectPendingAction`): only the person the call ran +// as decides an item, only on a signed-in session, and the approved action runs +// as that person with every gate re-checked. A structured TODO, not a D2 +// conversion: nothing an author wrote is rewritten or refused. Written +// conditionally on purpose: in the release that first carries this entry the +// in-app door still runs its queue as before. +export const entry: SemanticMigration = { + id: 'in-app-pending-action-decided-by-person', + surface: + 'objects[].actions[].ai.requiresConfirmation and actions[].ai.requiresConfirmation set to `true`, ' + + 'and every other action the in-app assistant queues for approval — who may approve or reject the ' + + 'pending action (`/api/v1/ai/pending-actions/:id/approve` and `/reject`, `IAIService.approvePendingAction` ' + + 'and `rejectPendingAction`)', + replacement: + 'Read this against your runtime first. Until the release whose changelog says the in-app assistant door ' + + 'enforces it, any holder of `ai:approve` may approve or reject an item in the AI pending-actions inbox, on ' + + 'whatever credential the route accepts. From that release, only the person the assistant call ran as ' + + 'approves or rejects their own item, on their signed-in session to the app; an API key, a token or an AI ' + + 'identity is refused, and the approved action runs as that person with every gate and permission ' + + 're-checked. Where a second person, such as an administrator, must also approve the write, route it ' + + 'through the approvals engine (the `held` outcome) instead of letting them decide the item.', + reason: + 'One `ai.requiresConfirmation: true` declaration has to mean one rule on every AI door. Under the in-app ' + + 'queue as first built, any user holding `ai:approve` could decide another person\'s pending action, from ' + + 'any credential the route accepted, and the approved action was re-dispatched rather than re-checked as ' + + 'that person: a side path around the confirmation the author declared. No mechanical move applies: the ' + + 'metadata is unchanged, and the work is in who operates the inbox and how a host routes a second ' + + 'approver. ADR-0011 / ADR-0087.', + acceptanceCriteria: + 'Now: list who decides in-app pending actions today (inbox operators, scripts or integrations on an API ' + + 'key or token) and, where someone other than the requesting person must approve, plan a `held` route ' + + 'through the approvals engine. Once your runtime enforces it (its changelog says so): each person ' + + 'approves or rejects their own items in the app while signed in, and no script, integration or other ' + + 'user decides them. Done when nothing relies on deciding another person\'s item or on deciding with a ' + + 'non-session credential.', +};