Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .changeset/33808-ai-door-confirmation-in-app.md
Original file line number Diff line number Diff line change
@@ -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`.

<!-- adr-0087: registered in-app-pending-action-decided-by-person -->

**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.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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/,
);
});
});
63 changes: 63 additions & 0 deletions packages/spec/src/contracts/ai-service.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 ` <member>?(`, 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/);
});
});
Loading
Loading