Ask to save a file in Plan mode instead of handing it over
A Plan mode reply that says the write tool is missing, or asks the user to save the document themselves, is faulted: Plan mode is what stops the save, and answering an ask_user card runs with the save allowed. The prompt now tells the bot to ask once with that card rather than paste the whole document.
This commit is contained in:
@@ -93,7 +93,7 @@ Enables SQLite foreign keys (`enableForeignKeys`), `bunextInit()`, `ensureDocker
|
||||
- **Routes:** `/admin/bots` reopens the last visited bot's own chat (cookie `cobble_last_visited_bot_id`, `<bot>` or `<bot>:<workspace>`; the landing uses only the bot) if still reachable, else coordinator (super admin) / latest bot / first workspace / empty. Workspace and conversation pages record the visit per user (`recordWorkspaceVisit`/`workspace_user_visits`, `recordBotVisit`/`bot_user_visits`) and the rail lists both latest visited first (`last_visited_at`, `orderByLastVisit`; recorded before the crew is read, so the conversation opened is already on top in that render, and its bot leads whatever the visits say (`pinned_id`); a workspace nobody visited yet ranks by its creation, so a new one leads); it never decides the landing. Settings and the rail pages get the cookie's conversation, workspace included, as root prop `last_conversation` (`grabLastConversation`, access-checked, only on those paths: `isPagesRailPath`), shown above their rail list as the way back (`RailLastConversation`). `/admin/bots/[bot_id]` conversation (header, thread and composer at 760px, no right panel; `?session_id=` opens another of the user's sessions there: a closed one is reopened, except a carried-over one, which shows with `SessionMovedBar` instead of the composer, pointing where the conversation went on); `/admin/bots/[bot_id]/models`; `/admin/workspaces/[id]` dashboard; `/admin/workspaces/[id]/bots/[bot_id]` same conversation scoped to the workspace.
|
||||
- **No model:** while the bot has no text model there (`bot_text_model` null, kept live by the models modal), the thread shows `NoModelNotice` (centred when empty): super admins get Connect a provider / Guided setup, others are told the super admin sets it up.
|
||||
- **Conversation loading:** pages render everything server-side (`grabConversationProps`) **except the history**, which the client loads (`api/admin/bots/conversation-history`, merged with what's already shown, refetched on bfcache restore) and pages older messages on scroll. Rail lists go through `railBots`/`railWorkspaces` (no prompts/memory, previews cut). Every return to the page (window focus, a hidden tab visible, back online: `use-refocus`, `AppData.RefocusGapMs`) reads the crew again (`use-live-crew-refresh` -> `api/admin/bots/live-crew` -> `cobble:live-crew-refreshed`, taken by `useLiveBots`/`useLiveWorkspaces`) and the session's latest messages plus its bot's face, task and the step its reply is on (`session-messages`, `use-reply-catch-up`; the history's own `step` seeds that row on load, `use-reply-progress`, and a row only ever moves forward in `bots_queue_updates` ids), and the page polls the same while a reply is due (read with the live face, never the page's): pushes missed while the phone slept left threads thinking and faces stale until a reload. On a phone, pulling the thread up past its bottom lifts the newest message off the edge, opening just enough room for a lone refresh icon (a ghost button, no label; no deeper, however far the drag goes), and letting go only reloads once that full room has been held for half a second, which lights the icon (`AppData.PullToRefreshHoldMs`: an exhausted thread reaches the limit by accident too easily) and then turns it into its spinner for at least a second (`AppData.PullToRefreshMinLoadingMs`) while the conversation and the rail are read again (`use-pull-to-refresh` writes that room straight onto the content as the finger moves, never through a render, and owns the gesture until release; the gesture is a plain state machine in `(utils)/pull-to-refresh-gesture.ts`, its steps tested without a browser, which takes the pull's anchor the moment the thread reaches its end, so one swipe that runs out of conversation hands over instead of stopping dead, and reads the end with `AppData.PullToRefreshEndSlackPx` of slack through `atThreadEnd`, since a phone's fractional device pixel ratio leaves the content a hair short and demanding an exact zero made the whole gesture do nothing; `PullToRefreshIndicator`; dragged back down before the release, the icon hides at the travel that showed it).
|
||||
- **Sending:** `api/admin/bots/send-message.ts` -> `enqueueBotReply` -> `wakeBotsQueue`. **Never import `src/bots-queue/index.ts` from a page or API route** (pulls the bunext runtime into page bundles). Optimistic bubble in `pending_messages` until the saved message replaces it. A message is capped at the app setting `bot_message_max_chars` (Settings > General, default `AppData.BotMessageMaxChars`, counted on the trimmed markdown, up to `BotMessageMaxCharsMax`), checked by the composer before it sends (the reason shows under the input) and again by the route (`messageTooLongMessage` says how far over it is and to attach the text as a file). Once stored, a message is never cut: it goes into every turn whole. A message sent in **Plan mode** (`bot_messages.plan_mode`, turned on by Tab anywhere on the conversation page or the composer's Plan button, remembered per conversation in `localStorage`) is answered by a planning run: `run-bot-reply` holds the tools to `PlanModeToolNames` (reads and the plan/question/suggestion cards, never `load_tools`), `send_reply` refuses `work` and `working`, and the computer and browser notes are left out; Retry and Run again copy the flag from the message they answer.
|
||||
- **Sending:** `api/admin/bots/send-message.ts` -> `enqueueBotReply` -> `wakeBotsQueue`. **Never import `src/bots-queue/index.ts` from a page or API route** (pulls the bunext runtime into page bundles). Optimistic bubble in `pending_messages` until the saved message replaces it. A message is capped at the app setting `bot_message_max_chars` (Settings > General, default `AppData.BotMessageMaxChars`, counted on the trimmed markdown, up to `BotMessageMaxCharsMax`), checked by the composer before it sends (the reason shows under the input) and again by the route (`messageTooLongMessage` says how far over it is and to attach the text as a file). Once stored, a message is never cut: it goes into every turn whole. A message sent in **Plan mode** (`bot_messages.plan_mode`, turned on by Tab anywhere on the conversation page or the composer's Plan button, remembered per conversation in `localStorage`) is answered by a planning run: `run-bot-reply` holds the tools to `PlanModeToolNames` (reads and the plan/question/suggestion cards, never `load_tools`), `send_reply` refuses `work` and `working`, and the computer and browser notes are left out; Retry and Run again copy the flag from the message they answer. A Plan mode reply whose result belongs in a file or another place outside the chat may not paste it or say a write tool is missing: it says the mode stops the save and asks with `ask_user` whether to save it (the answer runs without the mode), and `planModeFileEscape` sends a reply back when it hands the save to the user instead.
|
||||
- **Composer:** Tiptap editor reading/writing markdown, drafts in `localStorage`, `@` bots / `#` workspaces written as `[bot:ID]`/`[workspace:ID]`. Enter sends (Mod+Enter in lists/code). **Up/Down walk the user's own earlier messages** (`use-composer-history`, from `composerHistoryTexts` over the thread's user messages, never a crew message): Up recalls the newest from an empty input and older ones from there, Down comes forward again and back to what was being typed, a keystroke takes the input back, an open mention menu or a selection keeps the arrows. A clear button (X, disabled while the input is empty) empties the text without sending, keeping the quote and the picked files. Ordered lists are read back from digit markers only (`composer-ordered-list`): Tiptap also takes `a.`/`i.`, so a recalled "Ok. Do that." came back as item 401 with "Ok." eaten. `@tiptap/react` needs `use-sync-external-store`; the app ships an ESM stand-in in `packages/use-sync-external-store-esm` (file dependency + override; the Dockerfile copies `packages/` before `bun install`).
|
||||
- **Rendering:** markdown via `react-markdown` + `remark-gfm`, raw HTML never rendered, component map in `[bot_id]/(data)/message-markdown-components.tsx`. Inline refs, all linked by `link-computer-refs.ts` and rendered by chips in `(partials)/`: `[bot:ID]`, `[workspace:ID]`, `[computer:ID]`, `[file:ID]` (a saved file), `[folder:<volume>:<owner>:<path>]` (opens `FolderPreviewModal`, the files browser's listing over the chat, files opening their own preview; a modified click or its Open in Files goes to `/admin/files`), `[take-over:ID:mode]`, `[secret:ID]` (masked env, Reveal/Copy), `[suggestion:ID]` (its suggested next steps, buttons that fill the composer), `[plan:ID]` (a plan, as its card: steps, the one being worked, and the buttons to approve or change them), `[graphic:ID]` (a bot graphic, framed inline), `[task:ID]` (a tracker task, opening `TaskDetailModal`), `[setting:<section>:<field>]` (`SettingRefChip`: the exact Settings > General page and field to change, from `src/dict/general-settings-dict.ts`; every group of that page also has its own page under `/admin/settings/general/<section>`, and its fields are anchors). A plan, questions, a proposal, a hook proposal and a secret request show in full under the message, as the card the user acts on, never behind a chip: they are blocks, so `MarkdownParagraph` (`(partials)/markdown-paragraph.tsx`) lifts those refs out of the paragraph they were written in (`isCardRefHref` in `(utils)/card-ref-href.ts`), which React would otherwise refuse inside a `p`. Parsers in `src/utils/*-ref.ts`. A chip reads its own row through `(utils)/ref-view-loader.ts`, which keeps only what it read: a read that failed or hung is retried (`AppData.BotRefViewRetryDelaysMs`, each after `BotRefViewTimeoutMs`), so a chip pushed with a run shows its steps or card without a reload, and a chip whose card the user just decided (`primeRefView`) tells every other chip naming the same ref, since a thread can carry the same card twice and the others otherwise went on saying "Waiting for you" until a reload (`subscribeRefView`; `useBotPlan` instead re-reads on `server:bot-plan`). Anywhere else that renders bot-written markdown with `MessageMarkdownComponents` (a workspace's context on its dashboard, a task's description and notes through `TaskMarkdown`) runs it through `linkComputerRefs` and provides `CrewBotsContext`/`CrewWorkspacesContext` too. A ref quoted alone in a code span still links; one inside longer code stays literal (`linkComputerRefs` splits out code first). A file chip opens a file from another bot's folder for a user who reaches that folder (`userReachesFileScope`, the same rule as its bytes), so answers another bot passed on keep working.
|
||||
- **Message images:** a bot message shows the images it's about under its text (`MessageImages` in `(partials)/`, on `BotMessageLine` and `CrewMessageLine`): its image attachments plus every image `[file:ID]` it names (`liveFileRefIds`, which keeps the renderer's code rules), deduped when a named file is also attached (`file_id`). Each is a `MessageAttachment` thumbnail opening the shared `FilePreviewModal`; in a thread its gallery is the whole conversation (`sessionImageGallery` + `SessionGalleryContext` from `MessageThread`): every image in the session, bot and user, in message order, deduped by URL, falling back to the message's own images outside a thread. Non-image files and unreachable refs show nothing. Named files resolve through `useBotFile`/`useReferencedFiles` (page props first, then the cached `api/admin/bots/files` read shared with `FileRefChip`). A thumbnail URL serves the original when no smaller copy was made (`mediaServeWritePath`), since bot files keep no thumbnail.
|
||||
|
||||
@@ -28,6 +28,11 @@ type Params = {
|
||||
* its report, so it must not count as work that is still to come.
|
||||
*/
|
||||
job_id?: number | string;
|
||||
/**
|
||||
* The reply was sent with Plan mode on, so the writing tools are left
|
||||
* out on purpose (`PlanModeToolNames`).
|
||||
*/
|
||||
plan_mode?: boolean;
|
||||
/**
|
||||
* What the reply declared with `send_reply`.
|
||||
*/
|
||||
@@ -51,7 +56,7 @@ type Params = {
|
||||
* one wrote `[suggestion:11]` after the last real one was `[suggestion:10]`
|
||||
* and the user got buttons reading "not available".
|
||||
*/
|
||||
export default async function reviewBotReply({ text, tool_uses, bot_id, user_id, session_id, job_id, status, scopes }: Params) {
|
||||
export default async function reviewBotReply({ text, tool_uses, bot_id, user_id, session_id, job_id, plan_mode, status, scopes }: Params) {
|
||||
if (!text.trim()) return null;
|
||||
|
||||
const missing_file_ids: number[] = [];
|
||||
@@ -129,6 +134,7 @@ export default async function reviewBotReply({ text, tool_uses, bot_id, user_id,
|
||||
written_card_refs,
|
||||
has_open_work: await hasOpenWork({ bot_id, session_id, exclude_job_id: job_id }),
|
||||
status,
|
||||
plan_mode,
|
||||
});
|
||||
|
||||
if (!problems.length) return null;
|
||||
|
||||
@@ -8,6 +8,11 @@ type Params = {
|
||||
user_id: number | string;
|
||||
session_id: number | string;
|
||||
job_id?: number | string;
|
||||
/**
|
||||
* The run is a reply with Plan mode on (`PlanModeToolNames`), so a file
|
||||
* can't be saved until the user leaves the mode or answers a card.
|
||||
*/
|
||||
plan_mode?: boolean;
|
||||
scopes: StorageScope[];
|
||||
};
|
||||
|
||||
@@ -17,7 +22,7 @@ type Params = {
|
||||
* record (`reviewBotReply`). One place so a task report is held to the
|
||||
* same record as a chat reply.
|
||||
*/
|
||||
export default function reviewRunAnswer({ bot_id, user_id, session_id, job_id, scopes }: Params) {
|
||||
export default function reviewRunAnswer({ bot_id, user_id, session_id, job_id, plan_mode, scopes }: Params) {
|
||||
return ({ text, tool_uses, status }: { text: string; tool_uses: HarnessToolUse[]; status?: ReplyStatus }) =>
|
||||
reviewBotReply({ text, tool_uses, bot_id, user_id, session_id, job_id, status, scopes });
|
||||
reviewBotReply({ text, tool_uses, bot_id, user_id, session_id, job_id, plan_mode, status, scopes });
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ export default async function runBotReply({
|
||||
* the app would carry the plan on past work nobody did.
|
||||
*/
|
||||
const review_answer = ({ text, tool_uses, status }: { text: string; tool_uses: HarnessToolUse[]; status?: ReplyStatus }) =>
|
||||
reviewRunAnswer({ bot_id: bot.id!, user_id, session_id, scopes, job_id: job.id })({ text, tool_uses, status }).then((note) => {
|
||||
reviewRunAnswer({ bot_id: bot.id!, user_id, session_id, scopes, job_id: job.id, plan_mode })({ text, tool_uses, status }).then((note) => {
|
||||
if (note) return note;
|
||||
|
||||
return planStepReviewNote({ plan, on_step: on_plan_step, tool_uses, status });
|
||||
|
||||
@@ -1045,6 +1045,7 @@ The user sent this message with Plan mode on. This reply plans, reads and asks;
|
||||
- When the work is several pieces that build on each other, write the plan with create_plan (3 to 6 steps) and let them approve it. Nothing in it starts until they do, and working its steps is a later reply.
|
||||
- When a choice is theirs, ask it with ask_user instead of picking for them.
|
||||
- Nothing is written, run or changed in this mode: no files written, no tasks, schedules, hooks, memory or instructions changed, no secrets, no crew changes, no computers, browsers, MCP servers or custom tools. Don't say you did any of that, and don't say a run is under way.
|
||||
- When the result belongs in a file or somewhere outside the chat (a document, a task, a memory), don't paste it and never say a tool is missing: Plan mode is what stops the save. Say so in one sentence and ask once with ask_user whether to save it, with "Save it and send the file" first; their answer runs with the save allowed, so write it then. A short template they asked to read can stay in the message.
|
||||
- End with send_reply: done sends the plan or the answer, blocked says what stopped you. Work can't be queued here.
|
||||
- Say what you would do and what it depends on, not that you are doing it.`;
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import planModeFileEscape from "./plan-mode-file-escape";
|
||||
|
||||
describe("planModeFileEscape", () => {
|
||||
test("faults a made-up missing write tool", () => {
|
||||
expect(
|
||||
planModeFileEscape({
|
||||
text: "Since I don't have a `write_file` tool available in this environment, here's the complete document for you to save:",
|
||||
}),
|
||||
).toBe("missing_tool");
|
||||
});
|
||||
|
||||
test("faults a write tool called unavailable", () => {
|
||||
expect(planModeFileEscape({ text: "write_file is not available in this environment." })).toBe("missing_tool");
|
||||
});
|
||||
|
||||
test("faults asking the user to save it", () => {
|
||||
expect(planModeFileEscape({ text: "Here is the roadmap for you to save." })).toBe("save_it_yourself");
|
||||
});
|
||||
|
||||
test("faults telling the user they will have to save the document", () => {
|
||||
expect(planModeFileEscape({ text: "You'll need to save the document yourself." })).toBe("save_it_yourself");
|
||||
});
|
||||
|
||||
test("leaves an offer to save alone", () => {
|
||||
expect(
|
||||
planModeFileEscape({
|
||||
text: "Plan mode stops me saving files. Shall I save it as a document once you turn it off?",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
test("leaves a short template alone", () => {
|
||||
expect(planModeFileEscape({ text: "Here is the template:\n\n# Company\nName: [NAME]" })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
type Params = {
|
||||
text: string;
|
||||
};
|
||||
|
||||
export type PlanModeFileEscape = "missing_tool" | "save_it_yourself";
|
||||
|
||||
/**
|
||||
* The claim that the app has no way to write a file, or the request that the
|
||||
* user save it, in a reply sent with Plan mode on. The tool exists and Plan
|
||||
* mode is the only thing that stops it, so the answer should have asked to
|
||||
* save instead of handing over the document. 969 in session 133 said "Since
|
||||
* I don't have a write_file tool available in this environment, here's the
|
||||
* complete document for you to save" and pasted the whole roadmap.
|
||||
*/
|
||||
const MissingWriteTool =
|
||||
/\b(?:don'?t|do not|doesn'?t|didn'?t)\s+(?:have|get|see)\b[^.!?\n]{0,40}\b(?:write_file|write tools?|file[- ]writing tools?)\b/i;
|
||||
|
||||
const WriteToolUnavailable =
|
||||
/\b(?:write_file|write tools?)\b[^.!?\n]{0,30}\b(?:not available|isn'?t available|unavailable|no such tool)\b/i;
|
||||
|
||||
const SaveItYourself =
|
||||
/\b(?:for you to save|save (?:it|this|the (?:document|file|report)) yourself|you(?:'ll| will)? (?:need|have) to save (?:it|this|the (?:document|file|report))|copy (?:it|this) into (?:a|your) (?:file|document|doc))\b/i;
|
||||
|
||||
/**
|
||||
* What in a Plan mode answer gives the write back to the user instead of
|
||||
* asking to leave the mode: a made-up missing tool, or an instruction to
|
||||
* save the document themselves. Null when the answer asks, or when it only
|
||||
* says Plan mode stops it and offers to save.
|
||||
*/
|
||||
export default function planModeFileEscape({ text }: Params): PlanModeFileEscape | null {
|
||||
if (MissingWriteTool.test(text) || WriteToolUnavailable.test(text)) return "missing_tool";
|
||||
|
||||
if (SaveItYourself.test(text)) return "save_it_yourself";
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -456,4 +456,30 @@ describe("replyClaimProblems: the app's own state", () => {
|
||||
test("leaves an ordinary follow-up question alone", () => {
|
||||
expect(replyClaimProblems({ text: "The audit is done. Want me to send it?", tool_uses: [] })).toEqual([]);
|
||||
});
|
||||
|
||||
test("faults a Plan mode answer that hands the save back to the user", () => {
|
||||
const text = "Since I don't have a `write_file` tool available in this environment, here's the complete document for you to save:";
|
||||
|
||||
const problems = replyClaimProblems({ text, tool_uses: [], plan_mode: true });
|
||||
|
||||
expect(problems.length).toBe(1);
|
||||
expect(problems[0]).toContain("Plan mode");
|
||||
expect(problems[0]).toContain("ask_user");
|
||||
});
|
||||
|
||||
test("the same words outside Plan mode are not about the mode", () => {
|
||||
const text = "Here is the document for you to save.";
|
||||
|
||||
expect(replyClaimProblems({ text, tool_uses: [] })).toEqual([]);
|
||||
});
|
||||
|
||||
test("passes a Plan mode answer that offers to save it", () => {
|
||||
expect(
|
||||
replyClaimProblems({
|
||||
text: "Plan mode stops me saving files. Shall I save it as a document once you turn it off?",
|
||||
tool_uses: [],
|
||||
plan_mode: true,
|
||||
}),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ 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";
|
||||
import planModeFileEscape from "./plan-mode-file-escape";
|
||||
|
||||
type Params = {
|
||||
text: string;
|
||||
@@ -62,6 +63,12 @@ type Params = {
|
||||
* with a run behind it.
|
||||
*/
|
||||
status?: ReplyStatus;
|
||||
/**
|
||||
* The reply is running with Plan mode on: the tools that write are left
|
||||
* out on purpose, so a file can't be saved until the user leaves the
|
||||
* mode or answers an `ask_user` card (which runs with the save allowed).
|
||||
*/
|
||||
plan_mode?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -111,6 +118,7 @@ export default function replyClaimProblems({
|
||||
missing_hook_proposal_ids = [],
|
||||
has_open_work,
|
||||
status,
|
||||
plan_mode,
|
||||
}: Params): string[] {
|
||||
const problems: string[] = [];
|
||||
|
||||
@@ -193,6 +201,20 @@ export default function replyClaimProblems({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A document handed over in Plan mode with the write given back to the
|
||||
* user: a made-up missing tool, or an instruction to save it themselves.
|
||||
* The tool exists and the mode is what stops it, so the answer asked the
|
||||
* wrong thing; 969 pasted the whole roadmap this way.
|
||||
*/
|
||||
const file_escape = plan_mode ? planModeFileEscape({ text }) : null;
|
||||
|
||||
if (file_escape) {
|
||||
problems.push(
|
||||
`It is Plan mode, and the answer ${file_escape == "missing_tool" ? "says there is no write tool" : "asks the user to save the document themselves"}. write_file exists and Plan mode is the only thing stopping it. Don't paste the document and don't call the tool missing: say in one sentence that Plan mode stops the save, and call ask_user with "Save it and send the file" first; their answer runs with the save allowed, so write the file then. A short template the user asked to read can stay in the message.`,
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user