Send a choice asked in prose back to an ask_user card

A reply that ends with a question asking the user to pick, over a numbered or bulleted list of options, is faulted unless the run made an ask_user card. The prompts now say a choice list in the text is not an ask, and that free-form details stay in the message while the choice goes on the card.
This commit is contained in:
2026-11-21 13:02:30 +01:00
parent ed67d6919c
commit eaae3b9e50
7 changed files with 174 additions and 10 deletions
+1 -1
View File
@@ -129,7 +129,7 @@ Every run also gets `RequestScopeNote` (`src/data/harness-prompts.ts`): the user
- Every model turn is a step in `bots_queue_updates` (tool names, never arguments; `describe-job-step.ts`, labels in `JobStepToolLabels`), pushed as `server:bot-job-update` by the live relay only. Steps feed the live working row alone: the `clear-job-steps` cron deletes them `AppData.BotJobStepsKeepMs` after the job ends, however it ended, keeping their count on `bots_queue.steps`. Never delete them the moment a job ends (the relay would miss the last ones). A job queued by a tool (`enqueueBotJob`, the `queueBotTask` path) wakes the queue and pushes `server:bot-updated` itself, so a run queued behind another on the same computer shows and starts at once instead of waiting for the poll; a failed run closes its own `bot_tasks` row (`notifyBotJobFailed`), since a row left `active` kept a conversation's progress on a run that had failed months before (a queued run creates it `active`; only complete, cancel and stop closed it before).
- **A task run plans before it starts:** `planBotTask` (from `run-bot-task`) spends one turn, no tools, on the very system prompt the run then sends, so the provider's cache serves it and it costs little more than the plan. The answer is a bounded JSON plan (`BotTaskPlanSchema`, caps in `AppData.BotTaskPlan*`) that opens the run as `taskPlanNote` and shows as its first step line; `shouldPlanBotTask` keeps it off short runs (`AppData.BotTaskPlanMinSteps`). A plan that can't be written or read starts the run unplanned, never blocks it. **The wrap up is told what is on disk:** a task run passes `Params.wrap_up_note`, which runs `worktreeSummary` over the run's folders (`git status --porcelain` and `git diff --stat` per repository, nested ones included, at most 5) and puts the machine's own account in front of the wrap-up prompt, so the report is written from the tree and not from the run's memory of writing it. **The files the brief names are checked once, before the run starts** (`namedFilesNote`, over `namedFiles`): a path that isn't on the computer but is still in the bot's files is handed over as its `[file:ID]` with `export_file`, and one with no copy anywhere says plainly not to go looking through the machine or the user's accounts. It is the app's answer, not the run's guess: a source a rebuild took off the computer once cost a run thirty turns probing the container and then the user's own accounts for a copy the app was holding the whole time.
- **A reply ends with `send_reply`:** a reply run's answer is not its prose. The last turn must be `send_reply({status:"done"|"working"|"blocked", work?, message?})` with the message beside it or in its `message`/`text` argument (`replyTextFromCall`: a model that wrote the message into the call instead of the turn lost six production answers to "doesn't take text"), and assistant text with no tool call is a draft the loop returns to the model (`replyDraftNote`, up to `AppData.HarnessReplyDraftsMax`) rather than a message the user sees. A bare `send_reply` does not ship that draft on the first pass (`replyNoTextNote`): the model writes the whole message again in that turn, which is also the only turn that may call `suggest_next_steps` or `ask_user` beside it (any other tool is `replyClosingMixedNote` and unsent). A message written in the turn that put a card up (`ask_user`/`suggest_next_steps` with no `send_reply`) is kept as `card_text` and goes out with the call that closes it: that sentence is what the card belongs under, and asking for it again left the model with nothing to say (session 146). A review send-back clears `draft_text` and `card_text` and the reminder flag, so a refused answer is never carried again (the same faulted text went out on every bare `send_reply` and used up the rewrite budget). A draft that stops in a table, a fence or a bare marker (`unfinishedAnswerText`) is sent back once and never carried. A run that still ends with no message fails saying so rather than that its answer was wrong (`unsentAnswerMessage`). `status:"working"` must queue `work` (`{title,instructions,computer_id?,separate?,max_steps?}`, through `queueBotTask`, the same guards and brief as `start_task`) or follow a run already started from this reply, so a message that says work is running can only exist when the job does; `done` and `blocked` carry no work, and `work` beside either is refused. `start_task` is not a reply tool (it stays in task runs for a hand-off), `send_reply` is a closing tool beside `ask_user`/`suggest_next_steps`, and a task report ends the same way. If the run never closes, the job fails honestly and the thread offers Retry; work queued earlier in the run is cancelled with the unsent message. The review reads the status: a `done`/`blocked` message that says work is under way is faulted even when some unrelated run is open, and `hasOpenWork` takes the current `job_id` (`exclude_job_id`) so a task report can't count its own job as open work.
- **A bot can't vouch for itself:** a run's tool calls (`tool_uses`, names and ok, never arguments) go to the wrap-up turn when steps run out and onto the result message as `bot_messages.tool_log`; history follows each recorded bot message with an `[App record: ...]` line (`botMessagesToHarness`), and copies of that line in an answer are stripped (`stripAppRecords`, which shares the line shape with `appRecordLines`). Before a reply or a task report goes out, `reviewBotReply` (the loop's `review`, wired for both by `reviewRunAnswer`) sends it back when it names a `[file:ID]`/`[task:ID]`/`[graphic:ID]` that doesn't exist for the user, a task named in plain prose (`task #16`, `mentionedTaskIds`) whose row is gone (a row the user cannot open is left alone), a `[setting:...]` ref the app can't resolve (`unresolvedSettingRefs`), a `[suggestion:ID]`/`[question:ID]`/`[plan:ID]` ref it wrote itself (`AppCardRefTools`: the app adds those from the tool that made the card, so a written one is made up or copied from an earlier message and the user reads "not available"; `stripCardRefs` keeps them out of the answer and out of the model's own history, since the stored text carries the ref the app appended under it, which is how one began writing `[question:24]` at a card it never made), a `[proposal:]`/`[hook-proposal:]` ref no row backs (the model guessed `[proposal:19]` 85 s before that row existed, and the user was told three times a proposal had gone out when none had), or says work is under way, that a report will follow, or that it is about to do the work ("Let me check", "I'll connect and inspect", "next I'll", "Starting the conversion run now") (`claimsWorkUnderWay`, which reads a promise only when its own sentence is the commitment, so an offer waiting on the user is left alone) with no run this reply started and nothing open from the session: bots wrote "I'm scanning now" plus made-up results in one answer, and a reply promising to check the articles and then starting nothing left the user waiting for a report nobody would send. It also faults the app's own state described from nothing (`replyAppStateClaims`, skipped when `read_message_usage`/`read_settings` answered): how the model "routing" resolves or which model the tool sends, a run "killed" or "stopped" (Stop is the user's), and the model rest called unlimited or restart-only, each written by a bot that had only an `HTTP 404` to go on and told the user a model and a mechanism nobody had configured. Review runs on every answer it writes, up to `AppData.HarnessReviewRewrites` rewrites (a repeat of the faulted message is told so, `repeatedAnswerNote`); past that the answer is never sent and the job fails instead (`review_note` -> `BotJobFatalError`, a reply and a task report alike; a rewrite that lands on the wrap up is reviewed there and refused, not sent on), since a model that kept writing the same thing sends the claim anyway. **A fault must be something the bot can stop making:** only a whole line in the app's own record shape naming tools this reply didn't call is a forgery (`unsupportedAppRecordLines`) - the same text quoted inside a sentence is the bot naming its mistake, and job #468 faulted three rewrites in a row for that quote alone, so the lie stayed and the correction never reached the user. No fault note may itself contain the shape it faults or a `claimsWorkUnderWay` phrase. Tool names copied into a list (`WorkStartingTools`, `AppCardRefToolNames`, `WritingToolNames`, `WrapUp*ToolNames`) are pinned to the tools the harness declares by `src/harness/tools/tool-name-lists.test.ts` (`ask_crew` outlived its rename to `ask_bot`, so a reply that really had asked the crew was faulted for saying so). A long bot message whose run called no tools shows "No tools used" (`MessageNoToolsChip`).
- **A bot can't vouch for itself:** a run's tool calls (`tool_uses`, names and ok, never arguments) go to the wrap-up turn when steps run out and onto the result message as `bot_messages.tool_log`; history follows each recorded bot message with an `[App record: ...]` line (`botMessagesToHarness`), and copies of that line in an answer are stripped (`stripAppRecords`, which shares the line shape with `appRecordLines`). Before a reply or a task report goes out, `reviewBotReply` (the loop's `review`, wired for both by `reviewRunAnswer`) sends it back when it names a `[file:ID]`/`[task:ID]`/`[graphic:ID]` that doesn't exist for the user, a task named in plain prose (`task #16`, `mentionedTaskIds`) whose row is gone (a row the user cannot open is left alone), a `[setting:...]` ref the app can't resolve (`unresolvedSettingRefs`), a `[suggestion:ID]`/`[question:ID]`/`[plan:ID]` ref it wrote itself (`AppCardRefTools`: the app adds those from the tool that made the card, so a written one is made up or copied from an earlier message and the user reads "not available"; `stripCardRefs` keeps them out of the answer and out of the model's own history, since the stored text carries the ref the app appended under it, which is how one began writing `[question:24]` at a card it never made), a `[proposal:]`/`[hook-proposal:]` ref no row backs (the model guessed `[proposal:19]` 85 s before that row existed, and the user was told three times a proposal had gone out when none had), asks the user to choose in the text (a question with a numbered or bulleted list of options under it, `proseChoiceQuestion`) without an `ask_user` call in the run, so they would retype an option instead of clicking one (session 133 shipped two), or says work is under way, that a report will follow, or that it is about to do the work ("Let me check", "I'll connect and inspect", "next I'll", "Starting the conversion run now") (`claimsWorkUnderWay`, which reads a promise only when its own sentence is the commitment, so an offer waiting on the user is left alone) with no run this reply started and nothing open from the session: bots wrote "I'm scanning now" plus made-up results in one answer, and a reply promising to check the articles and then starting nothing left the user waiting for a report nobody would send. It also faults the app's own state described from nothing (`replyAppStateClaims`, skipped when `read_message_usage`/`read_settings` answered): how the model "routing" resolves or which model the tool sends, a run "killed" or "stopped" (Stop is the user's), and the model rest called unlimited or restart-only, each written by a bot that had only an `HTTP 404` to go on and told the user a model and a mechanism nobody had configured. Review runs on every answer it writes, up to `AppData.HarnessReviewRewrites` rewrites (a repeat of the faulted message is told so, `repeatedAnswerNote`); past that the answer is never sent and the job fails instead (`review_note` -> `BotJobFatalError`, a reply and a task report alike; a rewrite that lands on the wrap up is reviewed there and refused, not sent on), since a model that kept writing the same thing sends the claim anyway. **A fault must be something the bot can stop making:** only a whole line in the app's own record shape naming tools this reply didn't call is a forgery (`unsupportedAppRecordLines`) - the same text quoted inside a sentence is the bot naming its mistake, and job #468 faulted three rewrites in a row for that quote alone, so the lie stayed and the correction never reached the user. No fault note may itself contain the shape it faults or a `claimsWorkUnderWay` phrase. Tool names copied into a list (`WorkStartingTools`, `AppCardRefToolNames`, `WritingToolNames`, `WrapUp*ToolNames`) are pinned to the tools the harness declares by `src/harness/tools/tool-name-lists.test.ts` (`ask_crew` outlived its rename to `ask_bot`, so a reply that really had asked the crew was faulted for saying so). A long bot message whose run called no tools shows "No tools used" (`MessageNoToolsChip`).
- **A reply's `send_reply` work and `start_task`/`delegate_task` jobs are runs, not tasks:** their results say `Run #<job id>` and that `list_tasks` doesn't show them (bots sent users to the tracker for them). `queueBotTask` refuses a second open run in its session on the same computer unless `separate` (it would only wait behind it) and says how many runs are ahead on that computer. Its `max_steps` (`params.max_steps`) caps the run below the install's limit; the brief alone never did. Nothing wakes a bot when a run ends, so different follow-up work is queued at once with `separate`, never promised for later (`send_reply`'s work, `start_task`, `chatReplyNote`).
- **Replies take in messages sent mid-run** (`incoming`, `IncomingMessagesNote`, redraft); separate requests are acknowledged with `send_message` (interim). A queued reply finishes silently only when a finished reply already read every user message (`hasUnansweredMessage`), never by who wrote last; a retry (`params.retry_of`) always runs. **Task runs take them in too** (`taskIncoming`, only runs the user follows: no routines, hook calls or rooms): everything the user wrote since the run was queued, at the start, between steps, past a report not yet out and by the wrap up (`incoming_notes`, `TaskIncomingNote`); a correction changes the work, anything else is left to the chat, and crew messages to the reply they wake. A reply is told which runs open in its session hear the user (`openRunsNote`), so a correction never starts a second run.
+3 -1
View File
@@ -306,7 +306,9 @@ Be proactive about moving the work forward, but let the user steer it: whenever
- before work that is hard to undo, costly or seen by others;
- to offer the next step once you've answered or reported: the concrete next steps as options, only when a real decision or new direction remains for the user. Never interrupt an approved workflow with next-step questions when the user already gave their instruction.
When you're unsure whether to ask, ask. Give options that are concrete and distinct, put the one you'd suggest first and say so in it ("Staging (suggested)"). Ask everything you need in one card, then wait for their answers before acting on what you asked. Don't ask about what they already said, what you can find out yourself, or details that don't change the result (a file name, wording they can tweak later): just do those. If they skip the questions, don't guess: do only the part that's clear and say what you still need.`;
When you're unsure whether to ask, ask. Give options that are concrete and distinct, put the one you'd suggest first and say so in it ("Staging (suggested)"). Ask everything you need in one card, then wait for their answers before acting on what you asked. Don't ask about what they already said, what you can find out yourself, or details that don't change the result (a file name, wording they can tweak later): just do those. If they skip the questions, don't guess: do only the part that's clear and say what you still need.
Never write the choice itself in the message: a numbered or bulleted list of options under a question ("Which would you like?") is not an ask, it is a card the user has to answer by retyping. When the reply also needs free-form details the card can't collect (names, addresses, a table of fields), keep those details in the text and put the choice on the card, in the same turn as send_reply.`;
/**
* Added to every run: bots can show a concept as a visual the chat
@@ -47,7 +47,7 @@ export default function askUserTool({
return {
name: "ask_user",
description: `Ask the user multiple-choice questions, shown as a card in the chat they answer in a click. Use it whenever what happens next is theirs to decide: when the request is ambiguous or leaves out something that changes the result (which target, which items, how far to go), before something that is hard to undo, costly or visible to others, and to offer the next step once you've answered or reported (the concrete next steps as options, your suggestion first). When you're unsure whether to ask, ask. Call it in the same turn as send_reply, with the message beside that call: a later turn cannot add the card, because that turn would replace the answer. Don't ask what they already told you, what you can find out yourself, or details that don't change the result. Put every question in one call (at most one per run). Their answers arrive as their next message${
description: `Ask the user multiple-choice questions, shown as a card in the chat they answer in a click. Use it whenever what happens next is theirs to decide: when the request is ambiguous or leaves out something that changes the result (which target, which items, how far to go), before something that is hard to undo, costly or visible to others, and to offer the next step once you've answered or reported (the concrete next steps as options, your suggestion first). When you're unsure whether to ask, ask. Call it in the same turn as send_reply, with the message beside that call: a later turn cannot add the card, because that turn would replace the answer. Don't ask what they already told you, what you can find out yourself, or details that don't change the result. Put every question in one call (at most one per run). A choice written as a numbered or bulleted list in your message is not asked: the options go on the card, and only free-form details the card can't collect stay in the text. Their answers arrive as their next message${
in_task
? `. In a task, ask, then stop working on what you asked about and finish your report; the card goes out with it.`
: `: after asking, end your reply and wait; don't act on what you asked about until they answer.`
+56
View File
@@ -0,0 +1,56 @@
import { describe, expect, test } from "bun:test";
import proseChoiceQuestion from "./prose-choice-question";
describe("proseChoiceQuestion", () => {
test("finds the numbered choice from session 133", () => {
const text = `I need a few things to start the filing.
**What would you like to do?**
1. **Provide the details now** (I'll start name reservation immediately)
2. **Get a template** to fill and send back
3. **Use an accredited CAC agent** you already work with
Let me know your name choices and preferred approach.`;
expect(proseChoiceQuestion({ text })).toEqual({
question: "What would you like to do?",
options: 3,
});
});
test("finds the Option A and B list", () => {
const text = `The plan is already complete at a planning level.
Which would you like?
- **Option A:** Flesh out Steps 3-6 with more operational detail
- **Option B:** Pause planning and execute Step 2 later`;
expect(proseChoiceQuestion({ text })?.options).toBe(2);
});
test("leaves a plain follow-up question alone", () => {
expect(proseChoiceQuestion({ text: "The audit is done. Want me to send it?" })).toBeNull();
});
test("leaves a section heading over facts alone", () => {
const text = `What's included?
- Hosting for a year
- A domain name`;
expect(proseChoiceQuestion({ text })).toBeNull();
});
test("ignores a question and list inside a code fence", () => {
const text = "Example config:\n```\nWhich mode?\n- fast\n- safe\n```";
expect(proseChoiceQuestion({ text })).toBeNull();
});
test("needs a choice cue in the question", () => {
const text = `What changed?
- The header
- The footer`;
expect(proseChoiceQuestion({ text })).toBeNull();
});
});
+75
View File
@@ -0,0 +1,75 @@
/**
* A choice the model wrote into its answer instead of on an `ask_user`
* card: a question asking the user to pick, with a list of options under
* it. Only the shape matters here; the review decides whether a card was
* actually made.
*/
type ProseChoiceQuestion = {
/**
* The question line, without markdown emphasis.
*/
question: string;
/**
* How many options the list offered.
*/
options: number;
};
type Params = {
text: string;
};
/**
* A question that asks the user to choose, rather than one that heads a
* section ("What's included?" over a list of facts).
*/
const ChoiceCue = /\b(which|would you like|choose|pick|prefer|option)\b/i;
const ListItem = /^\s*(?:[-*+]|\d{1,2}[.)])\s+\S/;
const Fence = /^\s*(?:```|~~~)/;
/**
* Finds the answer's closing choice, written as prose: the last question
* that asks the user to pick, with at least two list items directly under
* it. A reply that ends this way with no `ask_user` call makes the user
* retype an option instead of clicking one; session 133 shipped two of
* them ("What would you like to do?" with three numbered choices, and
* "Which would you like?" with Option A and B).
*
* The list must follow the question in the same block, and the question
* must carry a choice cue, so "Want me to send it?" or a heading over a
* table of facts is left alone. Fenced code is never read as an ask.
*/
export default function proseChoiceQuestion({ text }: Params): ProseChoiceQuestion | null {
const lines = text.split("\n");
let in_fence = false;
for (let index = lines.length - 1; index >= 0; index -= 1) {
const line = lines[index]!;
if (Fence.test(line)) {
in_fence = !in_fence;
continue;
}
if (in_fence || !line.includes("?") || !ChoiceCue.test(line)) continue;
const question = line.replace(/\*\*|__/g, "").trim();
let options = 0;
for (let next = index + 1; next < lines.length && next <= index + 16; next += 1) {
const item = lines[next]!;
if (Fence.test(item)) break;
if (!item.trim()) continue;
if (item.trim() == "---") break;
if (!ListItem.test(item)) break;
options += 1;
}
if (options >= 2) return { question, options };
}
return null;
}
+21 -7
View File
@@ -434,12 +434,26 @@ describe("replyClaimProblems: the app's own state", () => {
expect(problems.length).toBe(1);
});
test("leaves the error it was given, word for word, alone", () => {
expect(
replyClaimProblems({
text: "qwen-image-3.0-pro: Alibaba Cloud Token Plan: HTTP 404 at POST https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/images/generations - no endpoint at that address; check the provider's base URL",
tool_uses: [],
}),
).toEqual([]);
test("faults a choice list asked in the text instead of on a card", () => {
const text = `Which would you like?
- **Option A:** Deepen the planning for Steps 3-6
- **Option B:** Pause planning and execute Step 2 later`;
const problems = replyClaimProblems({ text, tool_uses: [] });
expect(problems.length).toBe(1);
expect(problems[0]).toContain("ask_user");
});
test("passes the same choice once ask_user made the card", () => {
const text = `Which would you like?
- **Option A:** Deepen the planning for Steps 3-6
- **Option B:** Pause planning and execute Step 2 later`;
expect(replyClaimProblems({ text, tool_uses: [{ name: "ask_user", ok: true }] })).toEqual([]);
});
test("leaves an ordinary follow-up question alone", () => {
expect(replyClaimProblems({ text: "The audit is done. Want me to send it?", tool_uses: [] })).toEqual([]);
});
});
+17
View File
@@ -3,6 +3,7 @@ import type { ReplyStatus } from "@/src/dict/reply-status-dict";
import claimsWorkUnderWay from "./claims-work-under-way";
import unsupportedAppRecordLines from "./app-record-claims";
import replyAppStateClaims, { AppStateTools } from "./reply-app-state-claims";
import proseChoiceQuestion from "./prose-choice-question";
type Params = {
text: string;
@@ -176,6 +177,22 @@ export default function replyClaimProblems({
);
}
/**
* A choice asked in the text instead of on an `ask_user` card: the user
* would have to retype an option. Both runs in session 133 sent a
* numbered choice under "What would you like to do?" and "Which would
* you like?" with no card, so the ask was a paragraph, not a click.
* Free-form details the card can't collect stay in the message; the
* choice itself belongs on the card.
*/
const prose_choice = proseChoiceQuestion({ text });
if (prose_choice && !tool_uses.some((use) => use.name == "ask_user" && use.ok)) {
problems.push(
`It asks the user to choose in the text ("${prose_choice.question}") with ${prose_choice.options} options. A choice written as a list makes them retype an option; ask_user puts the same question on a card they answer in a click, with your suggestion first. Call ask_user in the same turn as send_reply with those options, keep only free-form details the card can't hold (names, addresses, a table) in the message, and don't repeat the options in the text.`,
);
}
const started = tool_uses.some((use) => use.ok && WorkStartingTools.includes(use.name));
/**
* A run that reached for `start_task` and was refused was not making the