Open-source AI browser agent for Chrome and Firefox (monorepo) π§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Re-ask only where the alignment check reads the answer
Claude792573af1120
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ee6ab79f1..dd9b5c301 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,7 +19,7 @@ This changelog was generated from the repository Git history and release tags. V- Providers β Decision accepts a local decision server on another machine on your network, such as `http://192.168.1.51:8091`. **Load available models** and **Test** used to stop with "Decision endpoints require HTTPS outside localhost." for any address but this computer's. Private addresses (10.x, 172.16β31.x, 192.168.x, Tailscale's 100.64β127.x, link-local, IPv6 unique-local) and `.local`, `.home.arpa` and `.internal` names now work over plain HTTP; public addresses still need HTTPS. In Chrome, decision requests to such a server go through the same offscreen proxy as chat models on your network. Vision and speech endpoints already accepted these addresses.- Act can send a photo or video in an Instagram direct message. Instagram's message box keeps its file input hidden, outside any form, deep in a long conversation, where WebBrain's check that an action still targets what the model saw cannot reach it. Every attachment was refused, even with the exact selector WebBrain itself listed for that input, often right after you had confirmed the recipient on WebBrain's card; the model then sent a link to the picture, or said Instagram blocks attachments. With Strict checks off, an upload to the very input WebBrain listed on that page, named by the selector it gave, now goes through with a note to the model, and the recipient checks still apply. A selector WebBrain did not list is still refused, and so is an input the page re-created after the list under the same selector, until WebBrain lists the page's controls again. When clicking "Add Photo or Video" opens a file chooser, WebBrain now names the input with that same selector, and the Instagram site notes say to attach the file to that input instead of clicking the button, and that a link to a picture is not the picture.- Act can attach images and videos to a post on X again. While the post composer is open at x.com/compose/post, the timeline behind it keeps a second, identical file input, and WebBrain's list of the page's controls gave neither input a selector. After the model's first selector matched both, WebBrain refused every later upload until it saw a selector it could not get, so the run ended at its cost limit with nothing attached. The list now gives every file input a selector that matches only that input, scoped to the open dialog where that is what tells them apart, and marks the dialog's input `inDialog`. The X site notes name the dialog's input, and when no selector can single out an input, WebBrain tells the model to report the upload as blocked instead of retrying.-- Act no longer asks you the same question again when the answer is on the page. Asked to post the same thing on LinkedIn while the X post was open, the planner asked which text and files to use, and after βlook at the screen β the sameβ it asked again: the planner works from your words, the page's address and title and a short summary of the chat, never the page itself or your attachments. That summary held only the last ten messages, tool calls and page observations included, each cut to 300 characters, so the earlier answer that named the post's text and your screenshot file had dropped out of it. It now holds the last ten turns of the conversation without the agent's step-by-step notes, gives the latest answer up to 1,200 characters, and names the files you attached earlier. When you have just answered a planner question and the planner wants to ask again, it first takes a second look, told that it cannot see the page while the agent can, and plans the task instead. That second look cannot add anything you did not ask for: posting, sending or a schedule your request did not already carry stays a question for you. When a scheduled task should run, who a message goes to, an account or an amount stay questions too until you give them, and it never takes them from the page. With the Planner on, an answer such as "every five minutes" to a question about a scheduled task, the name of the person to write to or "yes, send it" is planned, because the plan is then checked against your words; with the Planner off, those stay questions. Opening the conversation it asked you to open is planned either way, and a task you asked to repeat is never run just once instead. A planner running Qwen 3, QwQ or DeepSeek R1, which is told not to think so that it answers faster, now thinks during that second look and before any question it would ask you, unless reasoning is turned off for that provider. Chrome and Firefox.+- Act no longer asks you the same question again when the answer is on the page. Asked to post the same thing on LinkedIn while the X post was open, the planner asked which text and files to use, and after βlook at the screen β the sameβ it asked again: the planner works from your words, the page's address and title and a short summary of the chat, never the page itself or your attachments. That summary held only the last ten messages, tool calls and page observations included, each cut to 300 characters, so the earlier answer that named the post's text and your screenshot file had dropped out of it. It now holds the last ten turns of the conversation without the agent's step-by-step notes, gives the latest answer up to 1,200 characters, and names the files you attached earlier. With the Planner on (Try or Strict), when you have just answered a planner question and the planner wants to ask again, it first takes a second look, told that it cannot see the page while the agent can, and plans the task instead; the plan is then checked against your words. So an answer such as "every five minutes" to a question about a scheduled task, the name of the person to write to, "yes, send it" or opening the conversation it asked you to open is planned. It never takes who a message goes to, an account or an amount from the page, never adds a person or a schedule your request did not carry, and never runs a task you asked to repeat just once instead. With the Planner off, nothing checks a plan against your words, so it does not take that second look. A planner running Qwen 3, QwQ or DeepSeek R1, which is told not to think so that it answers faster, now thinks before any question it would ask you, unless reasoning is turned off for that provider. Chrome and Firefox.## [42.3.1] - 2026-10-20diff --git a/docs/architecture.md b/docs/architecture.mdindex b2b076c85..cf6651b57 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -934,7 +934,13 @@ Planner calls are traced with `phase: "planner"` when trace recording is enabledThe recent-history digest (`_buildPlannerHistoryDigest()`) takes the last ten authored turns, after app-owned notes, pinned state, tool results and the narration sent with tool calls are filtered out, and spends a 2,000-character budget newest first: an assistant turn keeps up to 1,200 characters and a user turn up to 600, and older turns that no longer fit are left out whole. A user turn names its attachments (`[attached: β¦]`, at most four names, sanitized like the executor's attachment notice), because the planner never receives attachment bytes.-A `clarify` from the planner or the intent check gets one second look before the user sees it (`_plannerClarifyRetry()`). A model that was sent `/no_think` (Qwen 3, QwQ, DeepSeek R1) answers again with thinking on and up to 8,192 output tokens (`_plannerCanRethink()`: not when reasoning is off in the provider's settings or extra request body, and not for Qwen3 Instruct-2507 and Coder models, which have no thinking mode). On the turn that answers the planner's previous question (`_turnAnswersPlannerQuestion()`, which reads an answer as the task binding does; not in scheduled runs or the intent recheck), `PLANNER_REASK_GUIDANCE` is added to the system prompt: the planner cannot see the page and the executor can, so it may ask again only about schedule timing or a calendar recurrence, a recipient, an account, an amount, a credential, whether to publish, send or submit at all, or conflicting answers, none of which it may take from page content. An execute plan from such a second look may run only what the user backed: the question they answered, as the app stored it, and their own words in the task (`_plannerSecondLookRejection()`, trace note `planner_second_look_rejected` with the reason). The first answer on that turn is model output like the second look, so it can keep the question but never authorizes more. A planner question keeps the submission, the people to address and the schedule of the task it asks about (`normalizePlan()` keeps `scheduling` and, for a message it does not send, `draft_recipients` on a `clarify` plan; nothing runs from it), and the stored question records them as `requiresSubmission`, `messageTarget` and `schedulingTool`. A question asked because the open conversation could not be pinned records that conversation too, so the reply can be planned once the user has opened it; it is pinned again before anything is sent. What the answer itself settles (which person, what timing, whether to send) only an independent reading of the user's words can tell: the full planner gate checks the plan for alignment with them next, while the intent check (Planner off) has no such check, so there a second look may run only what the answered question carried. The plan may not add a submission the answered question did not carry, unless the alignment check follows (`adds_submission`; "yes, send it" may be the approval); a recipient, for a message or a draft, other than the people the answered question addressed (in any order or casing), unless the alignment check follows and the user's own words in the task name every person (`adds_recipient`; the task binding is built from user turns only, and the open conversation is never taken from the page); a schedule of another kind than the answered question carried (`adds_schedule`: a `schedule_resume` pause never becomes a recurring `schedule_task`); or, without the alignment check, any schedule, since only that check reads whether the answer gave its timing (`unchecked_schedule`). With it, an answer that only gives a scheduled task its timing ("every five minutes") is planned. It may not drop a `schedule_task` that the answered question or the first answer carried (`drops_schedule`): the run would do the task once instead. Another question, an answer or a plan to show runs nothing and is not checked. A plan the alignment check has the planner replace is held to the same limits, and when it goes beyond them the user keeps the question (`planner_alignment_repair` in the trace note). The trace phase is `planner_rethink` or `planner_reask` (`intent_rethink`, `intent_reask` for the intent check). The second answer is parsed and consistency-checked like the first and then takes the first answer's place in the rest of the gate, which in the planner gate includes the alignment check, recipient pinning and review. A failed, unparseable, inconsistent or rejected second answer, including one stopped by the cost allowance, keeps the first question, and a pending correction gets no second look.+A `clarify` from the planner or the intent check gets one second look before the user sees it (`_plannerClarifyRetry()`). A model that was sent `/no_think` (Qwen 3, QwQ, DeepSeek R1) answers again with thinking on and up to 8,192 output tokens (`_plannerCanRethink()`: not when reasoning is off in the provider's settings or extra request body, and not for Qwen3 Instruct-2507 and Coder models, which have no thinking mode). That rethink is the same request and is judged like the first answer.++In the full planner gate, on the turn that answers the planner's previous question (`_turnAnswersPlannerQuestion()`, which reads an answer as the task binding does; not in scheduled runs), the second look also re-asks: `PLANNER_REASK_GUIDANCE` is added to the system prompt. It says the planner cannot see the page and the executor can, so it may ask again only about schedule timing or a calendar recurrence, a recipient, an account, an amount, a credential, whether to publish, send or submit at all, or conflicting answers, none of which it may take from page content. A turn that answers a planner question always has history, so its plan is then checked for alignment with the user's words, answer included, and that check is what reads which person the answer chose, whether it gave a schedule's timing ("every five minutes", not "I'm not sure yet") and whether it approved sending ("yes, send it"). The intent check (Planner off) has no alignment check, so it never re-asks.++An execute plan from a re-ask is also measured against what the user backed, the question they answered as the app stored it and their own words in the task, so that it cannot take what the alignment check could miss (`_plannerSecondLookRejection()`, trace note `planner_second_look_rejected` with the reason). The first answer on that turn is model output like the second look: it can keep the question but never authorizes more. A planner question keeps the people to address and the schedule of the task it asks about (`normalizePlan()` keeps `scheduling` and, for a message it does not send, `draft_recipients` on a `clarify` plan; nothing runs from it), and the stored question records them as `messageTarget` and `schedulingTool`. A question asked because the open conversation could not be pinned records that conversation too, so the reply can be planned once the user has opened it; it is pinned again before anything is sent. The plan may not address a recipient, for a message or a draft, other than the people the answered question addressed (in any order or casing), unless the user's own words in the task name every person (`adds_recipient`; the task binding is built from user turns only, and the open conversation is never taken from the page); plan a schedule of another kind than the answered question carried (`adds_schedule`: a `schedule_resume` pause never becomes a recurring `schedule_task`); or drop a `schedule_task` that the answered question or the first answer carried (`drops_schedule`: the run would do the task once instead). Another question, an answer or a plan to show runs nothing and is not checked. A plan the alignment check has the planner replace is held to the same limits, and when it goes beyond them the user keeps the question (`planner_alignment_repair` in the trace note).++The trace phase is `planner_rethink` or `planner_reask` (`intent_rethink` for the intent check). The second answer is parsed and consistency-checked like the first and then takes the first answer's place in the rest of the gate, which in the planner gate includes the alignment check, recipient pinning and review. A failed, unparseable, inconsistent or rejected second answer, including one stopped by the cost allowance, keeps the first question, and a pending correction gets no second look.LLM-request trace events include privacy-safe prompt provenance: the controlledprompt variant, system-prompt and aggregate message character counts, messagediff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 4782dbde5..279005c9b 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -27168,23 +27168,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// For the planner's second look (_plannerClarifyRetry): whether the user// turn at `index` answers the planner's previous question, and what the- // user backed (_plannerSecondLookRejection): the submission, message target- // and schedule tool that question stored, and the user's own words in the- // task. A correction or a scheduled run answers no question.+ // user backed (_plannerSecondLookRejection): the message target and+ // schedule tool that question stored, and the user's own words in the task.+ // A correction or a scheduled run answers no question._plannerQuestionAnswerContext(messages, index, runOptions = {}) {const answersPlannerQuestion = runOptions?.steeringRevision == null&& runOptions?.scheduledRun !== true && runOptions?.scheduledResume !== true&& this._turnAnswersPlannerQuestion(messages, index);if (!answersPlannerQuestion) {- return {- answersPlannerQuestion: false, answeredQuestionRequiresSubmission: false,- answeredQuestionSchedulingTool: null, answeredQuestionMessageTarget: null, taskUserText: '',- };+ return { answersPlannerQuestion: false, answeredQuestionSchedulingTool: null, answeredQuestionMessageTarget: null, taskUserText: '' };}const question = messages[this._plannerClarificationIndexBefore(messages, index)]?.webbrainPlannerClarification || {};return {answersPlannerQuestion: true,- answeredQuestionRequiresSubmission: question.requiresSubmission === true,answeredQuestionSchedulingTool: question.schedulingTool || null,answeredQuestionMessageTarget: normalizeMessageTarget(question.messageTarget),// The task binding is built from user turns only: the request and each@@ -27245,46 +27241,37 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// What a second look told not to re-ask may run, measured against what the// user backed: the question they just answered, as the app stored it (a- // question keeps the submission, the people to address and the schedule of- // the task it asks about), and their own words in the task. The first- // answer on this turn is model output like the second look itself: it may- // keep the question but never authorizes more. Returns why an execute plan- // is rejected, or null. Another question, an answer or a plan to show runs+ // question keeps the people to address and the schedule of the task it+ // asks about), and their own words in the task. The first answer on this+ // turn is model output like the second look itself: it may keep the+ // question but never authorizes more. Returns why an execute plan is+ // rejected, or null. Another question, an answer or a plan to show runs// nothing and passes. A rejected plan leaves the question with the user.- // What the user's answer itself settles (which person, what timing,- // whether to send) only an independent reading of their words can tell.- // The full planner gate checks the plan for alignment with them next- // (alignmentChecks); the intent check (Planner off) has no such check, so- // there a second look may run only what the answered question carried.- // - adds_submission: a submission the answered question did not carry,- // unless the alignment check follows: the answer may be the approval- // ("yes, send it").+ // A second look re-asks only in the full planner gate, whose alignment+ // check then reads the plan against the user's words, answer included. It+ // alone tells which person the answer chose, whether it gave a schedule's+ // timing ("every five minutes", not "I'm not sure yet") and whether it+ // approved sending ("yes, send it"); these rules keep out what it could+ // take from the page or from an earlier model answer.// - adds_recipient: a recipient, for a message or a draft (normalizePlan// keeps a draft's addressees in draft_recipients), other than the people- // the answered question addressed, unless the alignment check follows- // and the user's own words name every person. The open conversation is- // never taken from the page.+ // the answered question addressed, unless the user's own words name every+ // person. The open conversation is never taken from the page.// - adds_schedule: a schedule of another kind than the answered question// carried: a schedule_resume pause never becomes a recurring// schedule_task.- // - unchecked_schedule: a schedule of the kind it carried without the- // alignment check, which alone reads whether the answer gave its timing- // ("every five minutes", not "I'm not sure yet").// - drops_schedule: no schedule_task where the answered question or the// first answer carried one: the run would do the task once instead.- _plannerSecondLookRejection(firstPlan, plan, followUpContext = {}, { alignmentChecks = false } = {}) {+ _plannerSecondLookRejection(firstPlan, plan, followUpContext = {}) {if (plan?.request_kind !== 'execute') return null;- if (plan.requires_submission === true && followUpContext?.answeredQuestionRequiresSubmission !== true- && !alignmentChecks) return 'adds_submission';for (const target of [plan.messaging, plan.draft_recipients]) {if (!target || this._sameMessageTarget(followUpContext?.answeredQuestionMessageTarget, target)) continue;- if (alignmentChecks && target.target_kind === 'named'+ if (target.target_kind === 'named'&& this._userTextNamesRecipients(followUpContext?.taskUserText, target.recipients)) continue;return 'adds_recipient';}const carriedSchedule = followUpContext?.answeredQuestionSchedulingTool || null;if (plan.scheduling && plan.scheduling.tool !== carriedSchedule) return 'adds_schedule';- if (plan.scheduling && !alignmentChecks) return 'unchecked_schedule';if (plan.scheduling?.tool !== 'schedule_task'&& [carriedSchedule, firstPlan?.scheduling?.tool].includes('schedule_task')) return 'drops_schedule';return null;@@ -27300,11 +27287,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Qwen asked for values its prompt says to look up first. The retry lets// it think.// - No re-asking: when the user has just answered the planner's previous- // question, PLANNER_REASK_GUIDANCE reminds the planner that the executor- // can see what it cannot, and leaves a question only for values that have- // to come from the user. An execute plan from it may not add a- // submission, a recipient or a schedule the user did not back, or drop a- // recurring schedule the task carried (_plannerSecondLookRejection).+ // question, in the full planner gate, PLANNER_REASK_GUIDANCE reminds the+ // planner that the executor can see what it cannot, and leaves a question+ // only for values that have to come from the user. An execute plan from+ // it may not add a recipient or a schedule the user did not back, or drop+ // a recurring schedule the task carried (_plannerSecondLookRejection), and+ // the alignment check then reads it against the user's words.// The answer is parsed and checked like the first one, and an execute plan// then goes through alignment, recipient pinning and review like any other.// Returns null to keep the first answer: nothing to retry, or the retry@@ -27312,7 +27300,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// consistency repair.async _plannerClarifyRetry(tabId, provider, plannerMessages, {parseOptions = {}, intentOnly = false, reask = false, portable = false, costState = null, runId = null,- runtimeMode = 'act', onUpdate = null, followUpContext = {}, firstPlan = null, alignmentChecks = false,+ runtimeMode = 'act', onUpdate = null, followUpContext = {}, firstPlan = null,} = {}) {const rethink = this._plannerCanRethink(provider);if (!rethink && !reask) return null;@@ -27343,7 +27331,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dawait this._tracePlannerAttemptResponse(runId, 0, provider, result, phase, 1, startedAt, chatOptions);const plan = parsePlanFromContent(result?.content, parseOptions);if (!plan || this._plannerIntentConsistencyIssue(plan, followUpContext)) return null;- const rejection = reask ? this._plannerSecondLookRejection(firstPlan, plan, followUpContext, { alignmentChecks }) : null;+ const rejection = reask ? this._plannerSecondLookRejection(firstPlan, plan, followUpContext) : null;if (rejection) {this._tracePlannerSecondLookRejection(runId, phase, rejection);return null;@@ -28251,9 +28239,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (this._hasPendingSteering(tabId) || this._steeringGateSuperseded(tabId, runOptions)) {return { proceed: false, steeringSuperseded: true };}+ // A rethink only. The intent check has no alignment check that could+ // read the user's answer, so it never re-asks (_plannerSecondLookRejection).const secondLook = await this._plannerClarifyRetry(tabId, provider, plannerMessages, {- parseOptions: plannerParseOptions, intentOnly: true, firstPlan: plan,- reask: !recheckOnly && followUpContext.answersPlannerQuestion === true,+ parseOptions: plannerParseOptions, intentOnly: true,portable: plannerPortable, costState, runId, runtimeMode, onUpdate, followUpContext,});if (this._checkAbort(tabId)) return { proceed: false, message: '[Stopped by user]', reason: 'cancelled' };@@ -28573,7 +28562,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dhasValidPlannerResponse = true;// History is present on every turn that answers a planner question, so// a plan for it is checked for alignment with the user's words below.+ // Only then may the second look re-ask: that check reads the answer.const checksAlignment = !!(historyDigest || followUpContext.priorUserTask || followUpContext.scratchpadFacts);+ const reask = checksAlignment && followUpContext.answersPlannerQuestion === true;// The question a re-ask second look answered for the user. A plan that// later replaces that answer is held to the same limits, or the user// keeps this question (alignment repair below).@@ -28583,15 +28574,15 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn { proceed: false, steeringSuperseded: true };}const secondLook = await this._plannerClarifyRetry(tabId, provider, plannerMessages, {- parseOptions: plannerParseOptions, reask: followUpContext.answersPlannerQuestion === true, firstPlan: plan,- alignmentChecks: checksAlignment, portable: plannerPortable, costState, runId, runtimeMode, onUpdate, followUpContext,+ parseOptions: plannerParseOptions, reask, firstPlan: plan,+ portable: plannerPortable, costState, runId, runtimeMode, onUpdate, followUpContext,});if (this._checkAbort(tabId)) return { proceed: false, message: '[Stopped by user]' };if (this._hasPendingSteering(tabId) || this._steeringGateSuperseded(tabId, runOptions)) {return { proceed: false, steeringSuperseded: true };}if (secondLook) {- if (followUpContext.answersPlannerQuestion === true) reaskFirstPlan = plan;+ if (reask) reaskFirstPlan = plan;plan = secondLook;}}@@ -28794,7 +28785,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// limits, and is checked for alignment next. Otherwise the user// keeps the question that plan answered.const replacementRejection = reaskFirstPlan- ? this._plannerSecondLookRejection(reaskFirstPlan, plan, followUpContext, { alignmentChecks: true })+ ? this._plannerSecondLookRejection(reaskFirstPlan, plan, followUpContext): null;if (replacementRejection) {this._tracePlannerSecondLookRejection(runId, 'planner_alignment_repair', replacementRejection);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 15f0051d0..d01429a7b 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -24206,23 +24206,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// For the planner's second look (_plannerClarifyRetry): whether the user// turn at `index` answers the planner's previous question, and what the- // user backed (_plannerSecondLookRejection): the submission, message target- // and schedule tool that question stored, and the user's own words in the- // task. A correction or a scheduled run answers no question.+ // user backed (_plannerSecondLookRejection): the message target and+ // schedule tool that question stored, and the user's own words in the task.+ // A correction or a scheduled run answers no question._plannerQuestionAnswerContext(messages, index, runOptions = {}) {const answersPlannerQuestion = runOptions?.steeringRevision == null&& runOptions?.scheduledRun !== true && runOptions?.scheduledResume !== true&& this._turnAnswersPlannerQuestion(messages, index);if (!answersPlannerQuestion) {- return {- answersPlannerQuestion: false, answeredQuestionRequiresSubmission: false,- answeredQuestionSchedulingTool: null, answeredQuestionMessageTarget: null, taskUserText: '',- };+ return { answersPlannerQuestion: false, answeredQuestionSchedulingTool: null, answeredQuestionMessageTarget: null, taskUserText: '' };}const question = messages[this._plannerClarificationIndexBefore(messages, index)]?.webbrainPlannerClarification || {};return {answersPlannerQuestion: true,- answeredQuestionRequiresSubmission: question.requiresSubmission === true,answeredQuestionSchedulingTool: question.schedulingTool || null,answeredQuestionMessageTarget: normalizeMessageTarget(question.messageTarget),// The task binding is built from user turns only: the request and each@@ -24283,46 +24279,37 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// What a second look told not to re-ask may run, measured against what the// user backed: the question they just answered, as the app stored it (a- // question keeps the submission, the people to address and the schedule of- // the task it asks about), and their own words in the task. The first- // answer on this turn is model output like the second look itself: it may- // keep the question but never authorizes more. Returns why an execute plan- // is rejected, or null. Another question, an answer or a plan to show runs+ // question keeps the people to address and the schedule of the task it+ // asks about), and their own words in the task. The first answer on this+ // turn is model output like the second look itself: it may keep the+ // question but never authorizes more. Returns why an execute plan is+ // rejected, or null. Another question, an answer or a plan to show runs// nothing and passes. A rejected plan leaves the question with the user.- // What the user's answer itself settles (which person, what timing,- // whether to send) only an independent reading of their words can tell.- // The full planner gate checks the plan for alignment with them next- // (alignmentChecks); the intent check (Planner off) has no such check, so- // there a second look may run only what the answered question carried.- // - adds_submission: a submission the answered question did not carry,- // unless the alignment check follows: the answer may be the approval- // ("yes, send it").+ // A second look re-asks only in the full planner gate, whose alignment+ // check then reads the plan against the user's words, answer included. It+ // alone tells which person the answer chose, whether it gave a schedule's+ // timing ("every five minutes", not "I'm not sure yet") and whether it+ // approved sending ("yes, send it"); these rules keep out what it could+ // take from the page or from an earlier model answer.// - adds_recipient: a recipient, for a message or a draft (normalizePlan// keeps a draft's addressees in draft_recipients), other than the people- // the answered question addressed, unless the alignment check follows- // and the user's own words name every person. The open conversation is- // never taken from the page.+ // the answered question addressed, unless the user's own words name every+ // person. The open conversation is never taken from the page.// - adds_schedule: a schedule of another kind than the answered question// carried: a schedule_resume pause never becomes a recurring// schedule_task.- // - unchecked_schedule: a schedule of the kind it carried without the- // alignment check, which alone reads whether the answer gave its timing- // ("every five minutes", not "I'm not sure yet").// - drops_schedule: no schedule_task where the answered question or the// first answer carried one: the run would do the task once instead.- _plannerSecondLookRejection(firstPlan, plan, followUpContext = {}, { alignmentChecks = false } = {}) {+ _plannerSecondLookRejection(firstPlan, plan, followUpContext = {}) {if (plan?.request_kind !== 'execute') return null;- if (plan.requires_submission === true && followUpContext?.answeredQuestionRequiresSubmission !== true- && !alignmentChecks) return 'adds_submission';for (const target of [plan.messaging, plan.draft_recipients]) {if (!target || this._sameMessageTarget(followUpContext?.answeredQuestionMessageTarget, target)) continue;- if (alignmentChecks && target.target_kind === 'named'+ if (target.target_kind === 'named'&& this._userTextNamesRecipients(followUpContext?.taskUserText, target.recipients)) continue;return 'adds_recipient';}const carriedSchedule = followUpContext?.answeredQuestionSchedulingTool || null;if (plan.scheduling && plan.scheduling.tool !== carriedSchedule) return 'adds_schedule';- if (plan.scheduling && !alignmentChecks) return 'unchecked_schedule';if (plan.scheduling?.tool !== 'schedule_task'&& [carriedSchedule, firstPlan?.scheduling?.tool].includes('schedule_task')) return 'drops_schedule';return null;@@ -24338,11 +24325,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Qwen asked for values its prompt says to look up first. The retry lets// it think.// - No re-asking: when the user has just answered the planner's previous- // question, PLANNER_REASK_GUIDANCE reminds the planner that the executor- // can see what it cannot, and leaves a question only for values that have- // to come from the user. An execute plan from it may not add a- // submission, a recipient or a schedule the user did not back, or drop a- // recurring schedule the task carried (_plannerSecondLookRejection).+ // question, in the full planner gate, PLANNER_REASK_GUIDANCE reminds the+ // planner that the executor can see what it cannot, and leaves a question+ // only for values that have to come from the user. An execute plan from+ // it may not add a recipient or a schedule the user did not back, or drop+ // a recurring schedule the task carried (_plannerSecondLookRejection), and+ // the alignment check then reads it against the user's words.// The answer is parsed and checked like the first one, and an execute plan// then goes through alignment, recipient pinning and review like any other.// Returns null to keep the first answer: nothing to retry, or the retry@@ -24350,7 +24338,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// consistency repair.async _plannerClarifyRetry(tabId, provider, plannerMessages, {parseOptions = {}, intentOnly = false, reask = false, portable = false, costState = null, runId = null,- runtimeMode = 'act', onUpdate = null, followUpContext = {}, firstPlan = null, alignmentChecks = false,+ runtimeMode = 'act', onUpdate = null, followUpContext = {}, firstPlan = null,} = {}) {const rethink = this._plannerCanRethink(provider);if (!rethink && !reask) return null;@@ -24381,7 +24369,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dawait this._tracePlannerAttemptResponse(runId, 0, provider, result, phase, 1, startedAt, chatOptions);const plan = parsePlanFromContent(result?.content, parseOptions);if (!plan || this._plannerIntentConsistencyIssue(plan, followUpContext)) return null;- const rejection = reask ? this._plannerSecondLookRejection(firstPlan, plan, followUpContext, { alignmentChecks }) : null;+ const rejection = reask ? this._plannerSecondLookRejection(firstPlan, plan, followUpContext) : null;if (rejection) {this._tracePlannerSecondLookRejection(runId, phase, rejection);return null;@@ -25278,9 +25266,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (this._hasPendingSteering(tabId) || this._steeringGateSuperseded(tabId, runOptions)) {return { proceed: false, steeringSuperseded: true };}+ // A rethink only. The intent check has no alignment check that could+ // read the user's answer, so it never re-asks (_plannerSecondLookRejection).const secondLook = await this._plannerClarifyRetry(tabId, provider, plannerMessages, {- parseOptions: plannerParseOptions, intentOnly: true, firstPlan: plan,- reask: !recheckOnly && followUpContext.answersPlannerQuestion === true,+ parseOptions: plannerParseOptions, intentOnly: true,portable: plannerPortable, costState, runId, runtimeMode, onUpdate, followUpContext,});if (this._checkAbort(tabId)) return { proceed: false, message: '[Stopped by user]', reason: 'cancelled' };@@ -25596,7 +25585,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dhasValidPlannerResponse = true;// History is present on every turn that answers a planner question, so// a plan for it is checked for alignment with the user's words below.+ // Only then may the second look re-ask: that check reads the answer.const checksAlignment = !!(historyDigest || followUpContext.priorUserTask || followUpContext.scratchpadFacts);+ const reask = checksAlignment && followUpContext.answersPlannerQuestion === true;// The question a re-ask second look answered for the user. A plan that// later replaces that answer is held to the same limits, or the user// keeps this question (alignment repair below).@@ -25606,15 +25597,15 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn { proceed: false, steeringSuperseded: true };}const secondLook = await this._plannerClarifyRetry(tabId, provider, plannerMessages, {- parseOptions: plannerParseOptions, reask: followUpContext.answersPlannerQuestion === true, firstPlan: plan,- alignmentChecks: checksAlignment, portable: plannerPortable, costState, runId, runtimeMode, onUpdate, followUpContext,+ parseOptions: plannerParseOptions, reask, firstPlan: plan,+ portable: plannerPortable, costState, runId, runtimeMode, onUpdate, followUpContext,});if (this._checkAbort(tabId)) return { proceed: false, message: '[Stopped by user]' };if (this._hasPendingSteering(tabId) || this._steeringGateSuperseded(tabId, runOptions)) {return { proceed: false, steeringSuperseded: true };}if (secondLook) {- if (followUpContext.answersPlannerQuestion === true) reaskFirstPlan = plan;+ if (reask) reaskFirstPlan = plan;plan = secondLook;}}@@ -25817,7 +25808,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// limits, and is checked for alignment next. Otherwise the user// keeps the question that plan answered.const replacementRejection = reaskFirstPlan- ? this._plannerSecondLookRejection(reaskFirstPlan, plan, followUpContext, { alignmentChecks: true })+ ? this._plannerSecondLookRejection(reaskFirstPlan, plan, followUpContext): null;if (replacementRejection) {this._tracePlannerSecondLookRejection(runId, 'planner_alignment_repair', replacementRejection);diff --git a/test/planner-clarify-loop.mjs b/test/planner-clarify-loop.mjsindex fce4eba96..e5488d22b 100644--- a/test/planner-clarify-loop.mjs+++ b/test/planner-clarify-loop.mjs@@ -6,11 +6,13 @@// tool-call narration and names earlier attachments, instead of the last// ten raw messages cut to 300 characters each.// - A planner question gets one second look before the user sees it: a-// planner told not to think (/no_think) thinks, and on the turn that-// answers the planner's previous question the planner is told it cannot-// see the page and may ask again only for values that must come from the-// user. That plan may not add a submission, a recipient or a schedule the-// task did not carry, and then goes through the usual checks.+// planner told not to think (/no_think) thinks, and in the full planner+// gate, on the turn that answers the planner's previous question, the+// planner is told it cannot see the page and may ask again only for values+// that must come from the user. That plan may not take a recipient or a+// schedule the user did not back, and the alignment check then reads it+// against the user's words. The intent check, which has no alignment+// check, never re-asks.import assert from 'node:assert/strict';import { test } from 'node:test';@@ -45,6 +47,9 @@ const ASK_ANSWER = [].join('\n');const QUESTION = 'Which files should be included in the LinkedIn post, and what is the exact text to post?';const SECOND_QUESTION = 'Should I attach only the screenshot, or both photos from the X post?';+// A turn that answers a planner question always has history, so the full+// planner gate checks its plan for alignment, and only then re-asks.+const ANSWERED_DIGEST = `User: Post the same thing on LinkedIn too\nAssistant: ${QUESTION}`;const VLLM_QWEN = {name: 'vllm', model: 'qwen3.8-27b-nvfp4', promptTier: 'full', contextWindow: 131072, supportsTools: true, supportsVision: true,config: { providerName: 'vllm', model: 'qwen3.8-27b-nvfp4', category: 'local' },@@ -95,8 +100,6 @@ const PAUSE = { tool: 'schedule_resume', hint: 'Wait until the deploy finishes,const ALI = { target_kind: 'named', recipients: [{ identity: 'Ali Veli', role: 'to' }] };const OPEN_CHAT = { target_kind: 'active_conversation', recipients: [] };const OPEN_CHAT_CC = { target_kind: 'active_conversation', recipients: [{ identity: 'Ali Veli', role: 'cc' }, { identity: 'Ayse Yilmaz', role: 'cc' }] };-// The question the user answered carried a submission, as the app stored it.-const ASKED = { answeredQuestionRequiresSubmission: true };// The user's words in a task binding: the request and each answer.const userWords = (request, ...answers) => `User task clarified by the latest answer: ${JSON.stringify({ request, answers })}`;@@ -264,16 +267,12 @@ for (const build of ['chrome', 'firefox']) {const invalid = asked({ schedulingTool: 'schedule_everything', messageTarget: { target_kind: 'everyone', recipients: [] } })[2].webbrainPlannerClarification;assert.deepEqual([invalid.schedulingTool, invalid.messageTarget], [null, null], 'only a known tool and a valid target');const context = agent._plannerQuestionAnswerContext(scheduled, 3);- assert.deepEqual([context.answersPlannerQuestion, context.answeredQuestionRequiresSubmission, context.answeredQuestionSchedulingTool,- context.answeredQuestionMessageTarget], [true, false, 'schedule_task', ALI]);- assert.equal(agent._plannerQuestionAnswerContext(asked({ requiresSubmission: true }), 3).answeredQuestionRequiresSubmission, true);+ assert.deepEqual([context.answersPlannerQuestion, context.answeredQuestionSchedulingTool, context.answeredQuestionMessageTarget],+ [true, 'schedule_task', ALI]);assert.match(context.taskUserText, /Check this page for a new release on a schedule[\s\S]*every five minutes/, 'the user\'s words: request and answer');assert.doesNotMatch(context.taskUserText, /How often/, 'never the question');assert.deepEqual(agent._plannerQuestionAnswerContext(asked({}), 3).answeredQuestionSchedulingTool, null);- const none = {- answersPlannerQuestion: false, answeredQuestionRequiresSubmission: false,- answeredQuestionSchedulingTool: null, answeredQuestionMessageTarget: null, taskUserText: '',- };+ const none = { answersPlannerQuestion: false, answeredQuestionSchedulingTool: null, answeredQuestionMessageTarget: null, taskUserText: '' };for (const runOptions of [{ steeringRevision: 1 }, { scheduledRun: true }, { scheduledResume: true }]) {assert.deepEqual(agent._plannerQuestionAnswerContext(scheduled, 3, runOptions), none, JSON.stringify(runOptions));}@@ -304,32 +303,43 @@ for (const build of ['chrome', 'firefox']) {// ββ The second look βββββββββββββββββββββββββββββββββββββββββββββββββtest(`${build}: a planner question on the turn that answers the last one gets a second look, and its plan runs`, async () => {- for (const gate of ['planner', 'intent']) {- const answers = gate === 'planner' ? [clarifyPlan(), plannerPlan()] : [intentPlan(clarifyPlan()), intentPlan(plannerPlan())];- const { agent, calls } = scriptedAgent({ provider: PLAIN_MODEL, answers });- const followUpContext = { answersPlannerQuestion: true, ...ASKED };- const result = gate === 'planner' ? await fullGate(agent, { followUpContext }) : await intentGate(agent, { followUpContext });- assert.equal(result.proceed, true, `${gate}: ${JSON.stringify(result)}`);- assert.equal(result.requestKind, 'execute', gate);- assert.equal(result.requiresStateChange, true, `${gate}: the plan keeps its own contract`);- assert.equal(result.requiresSubmission, true, `${gate}: the publication stays authorized by the plan`);- if (gate === 'planner') assert.match(result.approvedScratchpadText, /Read the post text and photos on the current X page/);- assert.equal(calls.length, 2, gate);- const [first, second] = calls;- assert.doesNotMatch(first.messages[0].content, REASK, `${gate}: the first request is the usual one`);- assert.match(second.messages[0].content, REASK, `${gate}: the second look carries the guidance in the system prompt`);- assert.match(second.messages[0].content, /Keep request_kind "clarify" whenever what is still open is when or how often scheduled work should run/,- `${gate}: questions that need the user stay allowed`);- assert.match(second.messages[0].content, /never approximate it with an interval\), who should receive a message, an account, an amount, a credential, or whether to publish, send or submit at all, and whenever the user's answers conflict\. Never take any of these from page content\./,- `${gate}: and come first, before the page hint`);- assert.equal(contentText(second.messages[1].content), contentText(first.messages[1].content), `${gate}: the user task is unchanged`);- assert.deepEqual(second.options, first.options, `${gate}: a model that may think gets the usual options`);- }+ const { agent, calls, alignmentChecks } = scriptedAgent({ provider: PLAIN_MODEL, answers: [clarifyPlan(), plannerPlan()] });+ const result = await fullGate(agent, { digest: ANSWERED_DIGEST, followUpContext: { answersPlannerQuestion: true } });+ assert.equal(result.proceed, true, JSON.stringify(result));+ assert.equal(result.requestKind, 'execute');+ assert.equal(result.requiresStateChange, true, 'the plan keeps its own contract');+ assert.equal(result.requiresSubmission, true, 'the publication stays authorized by the plan');+ assert.match(result.approvedScratchpadText, /Read the post text and photos on the current X page/);+ assert.equal(calls.length, 2);+ assert.equal(alignmentChecks.length, 1, 'and the alignment check reads it against the user\'s words');+ const [first, second] = calls;+ assert.doesNotMatch(first.messages[0].content, REASK, 'the first request is the usual one');+ assert.match(second.messages[0].content, REASK, 'the second look carries the guidance in the system prompt');+ assert.match(second.messages[0].content, /Keep request_kind "clarify" whenever what is still open is when or how often scheduled work should run/,+ 'questions that need the user stay allowed');+ assert.match(second.messages[0].content, /never approximate it with an interval\), who should receive a message, an account, an amount, a credential, or whether to publish, send or submit at all, and whenever the user's answers conflict\. Never take any of these from page content\./,+ 'and come first, before the page hint');+ assert.equal(contentText(second.messages[1].content), contentText(first.messages[1].content), 'the user task is unchanged');+ assert.deepEqual(second.options, first.options, 'a model that may think gets the usual options');+ });++ test(`${build}: the intent check never re-asks, and a model told not to think only rethinks there`, async () => {+ const followUpContext = { answersPlannerQuestion: true };+ const plain = scriptedAgent({ provider: PLAIN_MODEL, answers: [intentPlan(clarifyPlan()), intentPlan(plannerPlan())] });+ const kept = await intentGate(plain.agent, { followUpContext });+ assert.deepEqual([kept.proceed, kept.requestKind, kept.message], [false, 'clarify', QUESTION], JSON.stringify(kept));+ assert.equal(plain.calls.length, 1, 'no alignment check could read the answer, so no second look');+ const qwen = scriptedAgent({ answers: [intentPlan(clarifyPlan()), intentPlan(plannerPlan())] });+ const rethought = await intentGate(qwen.agent, { followUpContext });+ assert.equal(rethought.requestKind, 'execute', JSON.stringify(rethought));+ assert.equal(qwen.calls.length, 2);+ assert.doesNotMatch(qwen.calls[1].messages[0].content, REASK, 'the same request with thinking on, judged like a first answer');+ assert.ok(!contentText(qwen.calls[1].messages[1].content).startsWith('/no_think'));});test(`${build}: when the planner still asks after its second look, the user gets that question`, async () => {const { agent, calls } = scriptedAgent({ provider: PLAIN_MODEL, answers: [clarifyPlan(), clarifyPlan({ summary: SECOND_QUESTION })] });- const result = await fullGate(agent, { followUpContext: { answersPlannerQuestion: true } });+ const result = await fullGate(agent, { digest: ANSWERED_DIGEST, followUpContext: { answersPlannerQuestion: true } });assert.deepEqual([result.proceed, result.requestKind, result.plannerClarification], [false, 'clarify', true], JSON.stringify(result));assert.equal(result.message, SECOND_QUESTION);assert.equal(calls.length, 2);@@ -357,8 +367,8 @@ for (const build of ['chrome', 'firefox']) {test(`${build}: a no-think model thinks during its second look, and a new plan runs`, async () => {for (const answered of [false, true]) {const { agent, calls } = scriptedAgent({ answers: [clarifyPlan(), plannerPlan()] });- const result = await fullGate(agent, { message: user('Post the same thing on LinkedIn too'),- followUpContext: { answersPlannerQuestion: answered, answeredQuestionRequiresSubmission: answered } });+ const result = await fullGate(agent, { message: user('Post the same thing on LinkedIn too'), digest: answered ? ANSWERED_DIGEST : '',+ followUpContext: { answersPlannerQuestion: answered } });assert.equal(result.proceed, true, JSON.stringify(result));assert.equal(result.requestKind, 'execute');assert.equal(calls.length, 2);@@ -379,7 +389,7 @@ for (const build of ['chrome', 'firefox']) {await fullGate(first.agent);assert.equal(first.calls.length, 1, 'no second look that could not think anyway');const answered = scriptedAgent({ provider, answers: [clarifyPlan(), plannerPlan()] });- const result = await fullGate(answered.agent, { followUpContext: { answersPlannerQuestion: true, ...ASKED } });+ const result = await fullGate(answered.agent, { digest: ANSWERED_DIGEST, followUpContext: { answersPlannerQuestion: true } });assert.equal(result.requestKind, 'execute');const second = answered.calls[1];assert.match(second.messages[0].content, REASK);@@ -390,68 +400,59 @@ for (const build of ['chrome', 'firefox']) {test(`${build}: a second look told not to re-ask runs only what the user backed`, async () => {const named = ALI;const task = { tool: 'schedule_task' };- // A turn that answers a planner question has history, so in the planner- // gate the plan is then checked for alignment with the user's words. The- // intent check (Planner off) has no such check.- const digest = `User: Post the same thing on LinkedIn too\nAssistant: ${QUESTION}`;- // [label, first answer on this turn, second look, what the user backed,- // accepted in the planner gate (its alignment check approves), accepted in the intent check]+ // [label, first answer on this turn, second look, what the user backed, accepted]+ // The alignment check, which follows in the planner gate, approves here:+ // these are the limits it cannot be relied on for.const cases = [- ['a submission nobody asked for', clarifyPlan({ requires_submission: false }), plannerPlan(), {}, true, false],- ['a submission only the first answer on this turn carried', clarifyPlan(), plannerPlan(), {}, true, false],- ['a submission the answered question carried', clarifyPlan({ requires_submission: false }), plannerPlan(), ASKED, true, true],- ['a recipient only the first answer on this turn named', clarifyPlan({ messaging: named }), plannerPlan({ messaging: named }), ASKED, false, false],- ['the recipient the answered question named', clarifyPlan(), plannerPlan({ messaging: named }), { ...ASKED, answeredQuestionMessageTarget: named }, true, true],+ ['a submission, which the alignment check reads against the answer', clarifyPlan({ requires_submission: false }), plannerPlan(), {}, true],+ ['a recipient only the first answer on this turn named', clarifyPlan({ messaging: named }), plannerPlan({ messaging: named }), {}, false],+ ['the recipient the answered question named', clarifyPlan(), plannerPlan({ messaging: named }), { answeredQuestionMessageTarget: named }, true],['the people the answered question named, in another order and casing', clarifyPlan(),plannerPlan({ messaging: { target_kind: 'active_conversation', recipients: [{ identity: 'AYSE YILMAZ', role: 'cc' }, { identity: 'ali veli', role: 'cc' }] } }),- { ...ASKED, answeredQuestionMessageTarget: OPEN_CHAT_CC }, true, true],+ { answeredQuestionMessageTarget: OPEN_CHAT_CC }, true],['someone else in the conversation the answered question addressed', clarifyPlan(),plannerPlan({ messaging: { target_kind: 'active_conversation', recipients: [{ identity: 'Ali Veli', role: 'cc' }, { identity: 'Bob', role: 'cc' }] } }),- { ...ASKED, answeredQuestionMessageTarget: OPEN_CHAT_CC }, false, false],+ { answeredQuestionMessageTarget: OPEN_CHAT_CC }, false],['the open conversation where the answered question named a person', clarifyPlan(), plannerPlan({ messaging: OPEN_CHAT }),- { ...ASKED, answeredQuestionMessageTarget: named }, false, false],+ { answeredQuestionMessageTarget: named }, false],['a draft into the open conversation', clarifyPlan({ requires_submission: false }),- plannerPlan({ requires_submission: false, messaging: OPEN_CHAT }), {}, false, false],+ plannerPlan({ requires_submission: false, messaging: OPEN_CHAT }), {}, false],['a draft for a recipient only the first answer on this turn named', clarifyPlan({ requires_submission: false, messaging: named }),- plannerPlan({ requires_submission: false, messaging: named }), {}, false, false],+ plannerPlan({ requires_submission: false, messaging: named }), {}, false],['a draft for the recipient the answered question named', clarifyPlan({ requires_submission: false }),- plannerPlan({ requires_submission: false, messaging: named }), { answeredQuestionMessageTarget: named }, true, true],+ plannerPlan({ requires_submission: false, messaging: named }), { answeredQuestionMessageTarget: named }, true],['a recipient the user named in the answer', clarifyPlan(), plannerPlan({ messaging: named }),- { ...ASKED, taskUserText: userWords('Send the report to my accountant', 'It is Ali Veli') }, true, false],+ { taskUserText: userWords('Send the report to my accountant', 'It is Ali Veli') }, true],['a recipient only the page could have named', clarifyPlan(), plannerPlan({ messaging: named }),- { ...ASKED, taskUserText: userWords('Send the report to my accountant', 'the one on the screen') }, false, false],+ { taskUserText: userWords('Send the report to my accountant', 'the one on the screen') }, false],['the open conversation, whatever the user wrote', clarifyPlan({ requires_submission: false }),plannerPlan({ requires_submission: false, messaging: OPEN_CHAT }),- { taskUserText: userWords('Draft a reply', 'use the current chat') }, false, false],+ { taskUserText: userWords('Draft a reply', 'use the current chat') }, false],['the open conversation the answered question addressed', clarifyPlan({ requires_submission: false }),- plannerPlan({ requires_submission: false, messaging: OPEN_CHAT }), { answeredQuestionMessageTarget: OPEN_CHAT }, true, true],- ['a schedule the task did not carry', clarifyPlan(), plannerPlan({ scheduling: { ...task, hint: 'Every 43200 minutes.' } }), ASKED, false, false],- ['a schedule only the first answer on this turn carried', clarifyPlan({ scheduling: OPEN_SCHEDULE }), plannerPlan({ scheduling: EVERY_FIVE }), ASKED, false, false],+ plannerPlan({ requires_submission: false, messaging: OPEN_CHAT }), { answeredQuestionMessageTarget: OPEN_CHAT }, true],+ ['a schedule the task did not carry', clarifyPlan(), plannerPlan({ scheduling: { ...task, hint: 'Every 43200 minutes.' } }), {}, false],+ ['a schedule only the first answer on this turn carried', clarifyPlan({ scheduling: OPEN_SCHEDULE }), plannerPlan({ scheduling: EVERY_FIVE }), {}, false],['a schedule the answered question carried', clarifyPlan(), plannerPlan({ scheduling: EVERY_FIVE }),- { ...ASKED, answeredQuestionSchedulingTool: 'schedule_task' }, true, false],+ { answeredQuestionSchedulingTool: 'schedule_task' }, true],['a recurring schedule where the answered question carried only a pause', clarifyPlan(),- plannerPlan({ scheduling: EVERY_FIVE }), { ...ASKED, answeredQuestionSchedulingTool: 'schedule_resume' }, false, false],+ plannerPlan({ scheduling: EVERY_FIVE }), { answeredQuestionSchedulingTool: 'schedule_resume' }, false],['a run without the recurring schedule the answered question carried', clarifyPlan(), plannerPlan(),- { ...ASKED, answeredQuestionSchedulingTool: 'schedule_task' }, false, false],- ['a run without the recurring schedule the first answer on this turn carried', clarifyPlan({ scheduling: OPEN_SCHEDULE }), plannerPlan(), ASKED, false, false],+ { answeredQuestionSchedulingTool: 'schedule_task' }, false],+ ['a run without the recurring schedule the first answer on this turn carried', clarifyPlan({ scheduling: OPEN_SCHEDULE }), plannerPlan(), {}, false],['a run without the pause the answered question carried', clarifyPlan(), plannerPlan(),- { ...ASKED, answeredQuestionSchedulingTool: 'schedule_resume' }, true, true],+ { answeredQuestionSchedulingTool: 'schedule_resume' }, true],];- for (const [label, first, second, extraContext, plannerAccepts, intentAccepts] of cases) {- for (const gate of ['planner', 'intent']) {- const accepted = gate === 'planner' ? plannerAccepts : intentAccepts;- const answers = gate === 'planner' ? [first, second] : [intentPlan(first), intentPlan(second)];- const { agent, calls, alignmentChecks } = scriptedAgent({ provider: PLAIN_MODEL, answers });- const followUpContext = { answersPlannerQuestion: true, ...extraContext };- const result = gate === 'planner' ? await fullGate(agent, { followUpContext, digest }) : await intentGate(agent, { followUpContext });- assert.equal(calls.length, 2, `${gate} ${label}`);- if (accepted) {- assert.equal(result.requestKind, 'execute', `${gate} ${label}: ${JSON.stringify(result)}`);- if (gate === 'planner') assert.equal(alignmentChecks.length, 1, `${gate} ${label}: checked against the user's words`);- if (second.scheduling) assert.equal(result.requiredSchedulingTool, 'schedule_task', `${gate} ${label}`);- } else {- assert.deepEqual([result.proceed, result.requestKind, result.message], [false, 'clarify', QUESTION], `${gate} ${label}: ${JSON.stringify(result)}`);- }+ for (const [label, first, second, extraContext, accepted] of cases) {+ const { agent, calls, alignmentChecks } = scriptedAgent({ provider: PLAIN_MODEL, answers: [first, second] });+ const result = await fullGate(agent, { digest: ANSWERED_DIGEST, followUpContext: { answersPlannerQuestion: true, ...extraContext } });+ assert.equal(calls.length, 2, label);+ if (accepted) {+ assert.equal(result.requestKind, 'execute', `${label}: ${JSON.stringify(result)}`);+ assert.equal(alignmentChecks.length, 1, `${label}: checked against the user's words`);+ if (second.scheduling) assert.equal(result.requiredSchedulingTool, 'schedule_task', label);+ } else {+ assert.deepEqual([result.proceed, result.requestKind, result.message], [false, 'clarify', QUESTION], `${label}: ${JSON.stringify(result)}`);+ assert.equal(alignmentChecks.length, 0, label);}}// A rethink without the guidance is an ordinary plan: a schedule the@@ -467,23 +468,18 @@ for (const build of ['chrome', 'firefox']) {const { parsePlanFromContent } = await import(`../src/${build}/src/agent/planner.js`);const parse = plan => parsePlanFromContent(JSON.stringify(plan), { requireIntent: true, locale: 'en' });const agent = newAgent();- const reason = (second, context = {}, first = clarifyPlan(), options = {}) =>- agent._plannerSecondLookRejection(parse(first), parse(second), context, options);- const checked = { alignmentChecks: true };- assert.equal(reason(plannerPlan()), 'adds_submission', 'a first answer on this turn authorizes nothing');- assert.equal(reason(plannerPlan(), {}, clarifyPlan(), checked), null, 'the alignment check reads a send the answer approved');- assert.equal(reason(plannerPlan({ messaging: ALI }), ASKED, clarifyPlan({ messaging: ALI })), 'adds_recipient');- const namedByUser = { ...ASKED, taskUserText: userWords('Send it to Alice or Ali Veli, ask me which', 'Ali Veli') };- assert.equal(reason(plannerPlan({ messaging: ALI }), namedByUser), 'adds_recipient', 'without the alignment check nothing reads the choice');- assert.equal(reason(plannerPlan({ messaging: ALI }), namedByUser, clarifyPlan(), checked), null);- assert.equal(reason(plannerPlan({ messaging: ALI }), ASKED, clarifyPlan(), checked), 'adds_recipient', 'the check never stands in for a name');+ const reason = (second, context = {}, first = clarifyPlan()) => agent._plannerSecondLookRejection(parse(first), parse(second), context);+ assert.equal(reason(plannerPlan()), null, 'whether the answer approved sending is the alignment check\'s to read');+ assert.equal(reason(plannerPlan({ messaging: ALI }), {}, clarifyPlan({ messaging: ALI })), 'adds_recipient',+ 'a first answer on this turn authorizes no one');+ const namedByUser = { taskUserText: userWords('Send it to my accountant', 'Ali Veli') };+ assert.equal(reason(plannerPlan({ messaging: ALI }), namedByUser), null);assert.equal(reason(plannerPlan({ requires_submission: false, messaging: ALI })), 'adds_recipient', 'a draft\'s recipient too');- assert.equal(reason(plannerPlan({ scheduling: EVERY_FIVE }), ASKED, clarifyPlan({ scheduling: OPEN_SCHEDULE }), checked), 'adds_schedule');- const carried = { ...ASKED, answeredQuestionSchedulingTool: 'schedule_task' };- assert.equal(reason(plannerPlan({ scheduling: EVERY_FIVE }), carried), 'unchecked_schedule', 'without the alignment check nothing reads the timing');- assert.equal(reason(plannerPlan({ scheduling: EVERY_FIVE }), carried, clarifyPlan(), checked), null);- assert.equal(reason(plannerPlan(), carried, clarifyPlan(), checked), 'drops_schedule');- assert.equal(reason(plannerPlan(), ASKED, clarifyPlan({ scheduling: OPEN_SCHEDULE }), checked), 'drops_schedule', 'the first answer may keep the question');+ assert.equal(reason(plannerPlan({ scheduling: EVERY_FIVE }), {}, clarifyPlan({ scheduling: OPEN_SCHEDULE })), 'adds_schedule');+ const carried = { answeredQuestionSchedulingTool: 'schedule_task' };+ assert.equal(reason(plannerPlan({ scheduling: EVERY_FIVE }), carried), null);+ assert.equal(reason(plannerPlan(), carried), 'drops_schedule');+ assert.equal(reason(plannerPlan(), {}, clarifyPlan({ scheduling: OPEN_SCHEDULE })), 'drops_schedule', 'the first answer may keep the question');for (const request_kind of ['clarify', 'respond', 'plan_only']) {const second = request_kind === 'clarify'? clarifyPlan({ summary: SECOND_QUESTION, messaging: ALI, scheduling: EVERY_FIVE })@@ -533,7 +529,7 @@ for (const build of ['chrome', 'firefox']) {test(`${build}: a plan the alignment check has replaced stays within what the user backed`, async () => {const digest = `User: Post the same thing on LinkedIn too\nAssistant: ${QUESTION}`;- const followUpContext = { answersPlannerQuestion: true, ...ASKED };+ const followUpContext = { answersPlannerQuestion: true };for (const [label, replacement, accepted] of [['a replacement that adds a recipient', plannerPlan({ messaging: ALI }), false],['a replacement that adds a recurring schedule', plannerPlan({ scheduling: EVERY_FIVE }), false],@@ -579,7 +575,7 @@ for (const build of ['chrome', 'firefox']) {];for (const [label, retryAnswers, extraContext] of cases) {const { agent, calls } = scriptedAgent({ provider: PLAIN_MODEL, answers: [clarifyPlan(), ...retryAnswers] });- const result = await fullGate(agent, { followUpContext: { answersPlannerQuestion: true, ...extraContext } });+ const result = await fullGate(agent, { digest: ANSWERED_DIGEST, followUpContext: { answersPlannerQuestion: true, ...extraContext } });assert.deepEqual([result.proceed, result.requestKind, result.message], [false, 'clarify', QUESTION], `${label}: ${JSON.stringify(result)}`);assert.equal(calls.length, 2, label);}@@ -589,7 +585,7 @@ for (const build of ['chrome', 'firefox']) {const { agent, calls } = scriptedAgent({answers: [new Error('400 Bad Request: response_format json_schema is not supported'), clarifyPlan(), plannerPlan()],});- const result = await fullGate(agent, { followUpContext: { answersPlannerQuestion: true, ...ASKED } });+ const result = await fullGate(agent, { digest: ANSWERED_DIGEST, followUpContext: { answersPlannerQuestion: true } });assert.equal(result.requestKind, 'execute', JSON.stringify(result));assert.equal(calls.length, 3);assert.equal(calls[1].options.extraBody, undefined, 'fixture: the repair went without request controls');