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
10 changes: 10 additions & 0 deletions .changeset/35908-scenario-confirm-first-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/scenarios': patch
---

Clause-②: no
Metadata-protocol: none

feat(scenarios): the build prompt's confirm-first line asks the build to lock the change a gated action makes

A confirm-gated agent action (`ai.requiresConfirmation`) guards its own door only; the gate is not widened to the raw data door, so an agent that met the gate could still write the target state with a plain record update. The build contract's line for each confirm-first action now also asks the build to lock that change: when the action changes fields of its row, those fields are made not editable for each person who runs it, at the stage the action acts on (a field permission `when` in their permission set), and the action writes them elevated, so the same people's other changes to those fields still land. An action that deletes its row locks nothing, and its people keep their delete right. Lines for actions that are not confirm-gated are unchanged.
25 changes: 24 additions & 1 deletion packages/qa/scenarios/src/runner/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,29 @@ function rowOwnership(card: Card): string[] {
return lines;
}

/**
* What a confirm-gated agent action's line asks of the build. The gate
* (`ai.requiresConfirmation`) guards the action's own door only, and it is not
* widened to the raw data door (`update_record`), so without a lock an agent
* that meets the gate can write the target state directly. The lock is the one
* the objectstack-ai skill teaches (pitfall "Gating the action, not the
* state"): the fields made not editable for the people who run the action,
* written elevated by the action itself.
*
* Two limits keep it from denying a card's own operations: it is scoped to the
* stage the action acts on (a field permission `when`), so the same people's
* other changes to those fields still land (a team lead's resolve, refused by
* validation, meets no lock before the ticket is resolved); and an action that
* deletes its row locks nothing, since the same people's plain deletes are
* applied operations on several cards.
*/
const CONFIRM_FIRST_LOCK =
'confirm first; the confirmation guards this action’s own door only, so also lock the change it makes: ' +
'if it changes fields of its row, make those fields not editable for each person who runs it, at the stage it acts on ' +
'(a field permission `when` in their permission set), and have the action write them elevated, ' +
'so a plain record update cannot make that change while those people’s other changes to the same fields still land; ' +
'an action that deletes its row locks nothing, and those people keep their delete right';

/** The runner's contract, appended to every build prompt. */
export function dataContract(card: Card): string {
const lines: string[] = [];
Expand Down Expand Up @@ -461,7 +484,7 @@ export function dataContract(card: Card): string {
if (card.run.agentActions?.length) {
lines.push('');
lines.push('Business actions an AI agent may call (expose each to AI; ask before acting where marked):');
for (const a of card.run.agentActions) lines.push(`- \`${a.name}\` on \`${a.object}\`: ${a.summary}${a.confirm ? ' (confirm first)' : ''}`);
for (const a of card.run.agentActions) lines.push(`- \`${a.name}\` on \`${a.object}\`: ${a.summary}${a.confirm ? ` (${CONFIRM_FIRST_LOCK})` : ''}`);
}
return lines.join('\n');
}
Expand Down
43 changes: 43 additions & 0 deletions packages/qa/scenarios/test/runner/units.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,49 @@ describe('namespace-relative cards', () => {
});
});

describe('the build contract asks for a stage-scoped field lock on a confirm-first action, and on no other action', () => {
// The gate guards the action's own door only and is not widened to `update_record`, so the
// line asks the build to lock the change itself. The fragments below are what the build reads.
const LOCK = 'lock the change it makes';
const STAGE = 'at the stage it acts on (a field permission `when` in their permission set)';
const DELETE_EXEMPT = 'an action that deletes its row locks nothing, and those people keep their delete right';
const actionLines = (contract: string): string[] => contract.split('\n').filter((l) => / on `[a-z0-9_]+`: /.test(l) && l.startsWith('- `'));

it('service_desk: the confirm-first `close_ticket` line carries the lock; `log_ticket`, `reply_to_customer` and `resolve_ticket` do not', () => {
const desk = namespacedScenario(load(resolve(HERE, '../../../../../docs/qa/scenarios/service_desk.json'))).card;
const lines = actionLines(dataContract(desk));
expect(lines).toHaveLength(4);
const close = lines.find((l) => l.includes('close_ticket` on '))!;
expect(close).toContain(': Close a resolved ticket for good; irreversible. (confirm first; ');
for (const fragment of [LOCK, STAGE, DELETE_EXEMPT]) expect(close).toContain(fragment);
for (const plain of lines.filter((l) => l !== close)) {
expect(plain).not.toContain('confirm first');
expect(plain).not.toContain(LOCK);
}
});

it('every card: each confirm-gated action line asks for the lock, and each plain one asks for nothing', () => {
const files = ['asset_lifecycle', 'crm_account_with_contacts', 'invoice_with_line_items', 'leave_balances', 'order_to_cash', 'project_with_tasks', 'requisition_to_receipt', 'service_desk', 'travel_expense'];
let gated = 0;
for (const f of files) {
const card = namespacedScenario(load(resolve(HERE, `../../../../../docs/qa/scenarios/${f}.json`))).card;
const lines = actionLines(dataContract(card));
expect(lines, f).toHaveLength(card.run.agentActions!.length);
card.run.agentActions!.forEach((a, i) => {
if (a.confirm) {
gated += 1;
expect(lines[i], `${f} ${a.name}`).toContain(`(confirm first; `);
expect(lines[i], `${f} ${a.name}`).toContain(LOCK);
expect(lines[i], `${f} ${a.name}`).toContain(DELETE_EXEMPT);
} else {
expect(lines[i], `${f} ${a.name}`).not.toContain(LOCK);
}
});
}
expect(gated).toBe(9);
});
});

// ── The seed's load plan ────────────────────────────────────────────────────

const SCENARIOS_DIR = resolve(HERE, '../../../../../docs/qa/scenarios');
Expand Down
Loading