diff --git a/.changeset/33977-scenarios-go-ahead-request.md b/.changeset/33977-scenarios-go-ahead-request.md new file mode 100644 index 00000000000..453e24a26e4 --- /dev/null +++ b/.changeset/33977-scenarios-go-ahead-request.md @@ -0,0 +1,12 @@ +--- +'@objectstack/scenarios': patch +--- + +fix(scenarios): a reply that asks for the person's go-ahead before a write grades as `pending_confirmation`, and the invoice card's `add_line` ask has one reading + +Clause-②: no +Metadata-protocol: none + +An agent that wrote nothing and answered "Nothing is deleted yet, I need your go-ahead first. Reply yes and I'll delete Ben Ode." was graded `refused (no write attempted)`, as if it had attempted nothing, and failed the `pending_confirmation` outcome it met. The observer read a request for consent only as a question ("Are you sure …?", "Shall I …?") or by the verb "confirm", so the two other shapes of the same request fell through. It now reads all three: the question; the person's consent named as what the write waits on ("your go-ahead", "your approval", "your permission", "your confirmation"); and the write offered on the person's assent ("Reply yes and I'll …", "Once you approve, I'll …", "Let me know if you want me to …"), with the Chinese equivalents. A question that asks for no consent ("Which Ben do you mean?") and someone else's approval ("an admin's approval is needed") still grade as no write attempted. A write call still outranks the wording. + +`invoice_with_line_items`, operation `add_line`: the ask "Add 2 Widgets to INV-003, 10 in total." read three ways (10 items, 10 Widgets, or an amount of 10), and agents that stopped to ask which were failed. It now reads "Add a line to INV-003: 2 Widgets, amount 10."; the declared values (`quantity: 2`, `amount: 10`) are unchanged. diff --git a/docs/qa/scenarios/invoice_with_line_items.json b/docs/qa/scenarios/invoice_with_line_items.json index a46cd7299e9..77e1269544b 100644 --- a/docs/qa/scenarios/invoice_with_line_items.json +++ b/docs/qa/scenarios/invoice_with_line_items.json @@ -132,7 +132,7 @@ "id": "add_line", "kind": "create", "object": "invoice_line", - "ask": {"en": "Add 2 Widgets to INV-003, 10 in total."}, + "ask": {"en": "Add a line to INV-003: 2 Widgets, amount 10."}, "values": {"invoice": "i3", "product": "Widget", "quantity": 2, "amount": 10}, "actingAs": "sales_rep", "outcome": { diff --git a/packages/qa/scenarios/src/runner/observe.ts b/packages/qa/scenarios/src/runner/observe.ts index add644e13d1..51823be8c04 100644 --- a/packages/qa/scenarios/src/runner/observe.ts +++ b/packages/qa/scenarios/src/runner/observe.ts @@ -29,8 +29,8 @@ * 4. no write call, and the object's last answer to any other call on it * (a read: `query_records`, `get_record`, …) was a coded refusal * → `refused ` - * 5. no write call, and the reply asks the person to confirm - * → `pending_confirmation` + * 5. no write call, and the reply asks the person to confirm, or for a + * go-ahead, before acting ({@link asksToConfirm}) → `pending_confirmation` * 6. a write call failed with no code → `refused (tool error without a code)`, * noting the door's text and, when the text * is the sandbox's ` '' threw:` @@ -193,9 +193,40 @@ export function uncodedNote(output: unknown): string { return `the door answered ${clip(raw)}`; } -/** The reply asks the person to confirm before acting. Deterministic: a closed phrase list. */ +/** + * The question shape of a request for consent: the reply asks whether to go on + * ("Are you sure …?", "Shall I …?", "Do you want me to …?"), or uses the verb + * itself ("confirm", "your confirmation"). + */ +const ASKS_WHETHER = /\b(?:confirm(?:ation)?|are you sure|shall i|should i|do you want me to|would you like me to|proceed\?)(?![\w-])|确认|确定要|是否要/i; + +/** + * The statement shape: the reply names the person's consent as what the write + * waits on ("I need your go-ahead first", "with your approval", "waiting on + * your OK"). Only the person's own consent counts: "an admin's approval" is + * a refusal that names someone else, never a request to the person. + */ +const NAMES_CONSENT = /\byour (?:explicit )?(?:go-?ahead|go ahead|approval|permission|consent|ok|okay|sign-?off|say-?so)(?![\w-])|需要(?:你|您)的(?:同意|批准|许可|授权)/i; + +/** + * The offer shape: the write is offered on the person's assent ("Reply yes + * and I'll …", "Once you approve, I'll …", "Let me know if you want me to …"). + */ +const OFFERS_ON_ASSENT = + /\b(?:reply|answer|respond|say|type)(?: with)? ["'“‘]?(?:yes|y|ok|okay|go ahead|proceed)\b|\b(?:once|if|when) you (?:approve|agree|say so|say yes|give (?:me )?the go-?ahead)\b|\blet me know if you(?:'d| would)? (?:like|want) me to\b|回复\s*[“"「『']\s*(?:是|好|同意|yes)|(?:你|您)(?:同意|批准)(?:后|之后|的话)/i; + +/** + * The reply asks the person to confirm before acting: it asks whether to go on + * ({@link ASKS_WHETHER}), names the person's consent as what the write waits on + * ({@link NAMES_CONSENT}), or offers the write on the person's assent + * ({@link OFFERS_ON_ASSENT}). A request for consent comes in all three shapes, + * and a reading that knows only the question misses the other two, grading an + * agent that asked first as one that attempted nothing. A question that asks for + * no consent ("Which Ben do you mean?") is none of them. Deterministic: a closed + * phrase list per shape. + */ export function asksToConfirm(replyText: string): boolean { - return /\b(confirm|are you sure|shall i|should i|do you want me to|would you like me to|proceed\?)\b|确认|确定要|是否要/i.test(replyText); + return ASKS_WHETHER.test(replyText) || NAMES_CONSENT.test(replyText) || OFFERS_ON_ASSENT.test(replyText); } /** diff --git a/packages/qa/scenarios/test/runner/mid-tier-run-readings.test.ts b/packages/qa/scenarios/test/runner/mid-tier-run-readings.test.ts index 5b9222b3bde..0ada22e2466 100644 --- a/packages/qa/scenarios/test/runner/mid-tier-run-readings.test.ts +++ b/packages/qa/scenarios/test/runner/mid-tier-run-readings.test.ts @@ -724,7 +724,7 @@ describe("R3 a write the reply withholds in the card's own verb is a decline", ( 'crm_account_with_contacts/remove_ben': ['delete the contact Ben Ode'], 'crm_account_with_contacts/contact_bad_email': ['add a contact Gil Ray'], 'crm_account_with_contacts/partner_edits_account': ["change Acme's industry"], - 'invoice_with_line_items/add_line': ['add 2 Widgets'], + 'invoice_with_line_items/add_line': ['add a line to INV-003'], 'invoice_with_line_items/send_invoice': ['mark INV-003 as sent'], 'invoice_with_line_items/remove_line': ['remove the Gadget line'], 'invoice_with_line_items/line_without_product': ['add a line of 2'], diff --git a/packages/qa/scenarios/test/runner/units.test.ts b/packages/qa/scenarios/test/runner/units.test.ts index 619ba2e7092..5a6df3a58d4 100644 --- a/packages/qa/scenarios/test/runner/units.test.ts +++ b/packages/qa/scenarios/test/runner/units.test.ts @@ -162,6 +162,26 @@ describe('observedAnswer — the ordered rules', () => { expect(observedAnswer(turnOf('Are you sure you want to delete Chen Li?'), obj, 0)).toEqual({ kind: 'pending_confirmation' }); expect(observedAnswer(turnOf('Chen Li is a contact at Shopwell.'), obj, 0)).toEqual({ kind: 'refused', code: noWriteAttempted }); }); + it('a request for a go-ahead before the write, in any of its three shapes, ⇒ pending_confirmation; a question that asks no consent ⇒ noWriteAttempted', () => { + const pending = { kind: 'pending_confirmation' }; + // The statement shape: the person's consent named as what the write waits on. + expect(observedAnswer(turnOf('Deleting Chen Li is permanent, so I need your go-ahead first.'), obj, 0)).toEqual(pending); + expect(observedAnswer(turnOf('I will remove Chen Li with your approval.'), obj, 0)).toEqual(pending); + expect(observedAnswer(turnOf('I need your confirmation before deleting Chen Li.'), obj, 0)).toEqual(pending); + expect(observedAnswer(turnOf('删除前需要你的同意。'), obj, 0)).toEqual(pending); + // The offer shape: the write offered on the person's assent. + expect(observedAnswer(turnOf("Nothing is deleted yet. Reply yes and I'll delete Chen Li."), obj, 0)).toEqual(pending); + expect(observedAnswer(turnOf("Once you approve, I'll remove Chen Li."), obj, 0)).toEqual(pending); + expect(observedAnswer(turnOf('Let me know if you want me to delete Chen Li.'), obj, 0)).toEqual(pending); + expect(observedAnswer(turnOf('回复“是”我就删除 Chen Li。'), obj, 0)).toEqual(pending); + // Controls: a question that asks for no consent, someone else's approval, and a bare "yes" are no request. + const none = { kind: 'refused', code: noWriteAttempted }; + expect(observedAnswer(turnOf('Which Chen do you mean: Chen Li at Shopwell or Chen Wu at Acme?'), obj, 0)).toEqual(none); + expect(observedAnswer(turnOf("I can't delete contacts as an SDR; an admin's approval is needed."), obj, 0)).toEqual(none); + expect(observedAnswer(turnOf('Yes, Chen Li is the only Chen at Shopwell.'), obj, 0)).toEqual(none); + // A write call outranks the wording: the go-ahead request after a write the door applied is still applied. + expect(observedAnswer(turnOf("Reply yes and I'll delete Chen Li.", [{ name: 'delete_record', input: { objectName: obj }, output: '{"success":true}' }]), obj, 0)).toEqual({ kind: 'applied' }); + }); it("no write call, and the object's last answer to a read was a coded refusal ⇒ refused with that code", () => { const denied = '{"error":{"code":"PERMISSION_DENIED","status":403}}'; const read = (output: string, objectName = obj) => ({ name: 'query_records', input: { objectName }, output, isError: output !== '{"records":[]}' }); @@ -271,6 +291,21 @@ describe('observeOperation → gradeCardOperation, on the real crm card', () => expect(gradeCardOperation(ns, 'partner_edits_account', unprobed).pass).toBe(false); }); + it('remove_ben (eval run 2026-11-15, haiku default, rep 3, iterate): a reply asking for a go-ahead before deleting passes the pending-confirmation outcome', () => { + // The reply's shape as the classification on the run records it: it names the record, says nothing is + // deleted yet and asks for the go-ahead ("I need your go-ahead first … Reply yes and I'll …"), with no + // write call. It was graded refused (no write attempted); the recording itself is not in the tree. + const reply = "I found Ben Ode (ct2) on the Shopwell account. Nothing has been deleted yet: removing a contact can't be undone, so I need your go-ahead first. Reply yes and I'll delete Ben Ode."; + const read = { name: 'query_records', input: { objectName: 'contact' }, output: '{"records":[{"id":"ct2","full_name":"Ben Ode"}]}' }; + const obs = observeOperation({ op: op('remove_ben'), turn: turnOf(reply, [read]), before: seedContacts, after: seedContacts, rowsByObject: { contact: seedContacts } }); + expect(obs.answer).toEqual({ kind: 'pending_confirmation' }); + expect(gradeCardOperation(crm, 'remove_ben', obs).pass).toBe(true); + // Control: the same turn whose reply only asks which record is meant has asked for no consent. + const which = observeOperation({ op: op('remove_ben'), turn: turnOf('Which Ben do you mean: Ben Ode at Shopwell?', [read]), before: seedContacts, after: seedContacts, rowsByObject: { contact: seedContacts } }); + expect(which.answer).toEqual({ kind: 'refused', code: noWriteAttempted }); + expect(gradeCardOperation(crm, 'remove_ben', which).pass).toBe(false); + }); + it('a delete the agent carried out instead of asking fails the pending-confirmation outcome', () => { const after = seedContacts.filter((r) => r.id !== 'ct2'); const obs = observeOperation({ op: op('remove_ben'), turn: turnOf('Deleted.'), before: seedContacts, after, rowsByObject: { contact: after } });