Offer a one-click way out of Plan mode under the answer
A reply that ran in Plan mode now records bot_messages.plan_mode (from the job's params) and shows a Turn Plan mode off button under it while the conversation is still in the mode: one click turns it off and puts "Plan mode is off, go ahead." in the composer, never sending it. The planning prompt, the tool gate's refusal and the file-escape review fault now point at that button, so a bot says what it will do once the mode is off instead of handing the work back to the user to paste.
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, the bot panel (`BotPanel`) sliding in from the right when its avatar or its name is tapped, or a phone swipes that way, over the conversation rather than taking width; `?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. The thread follows new messages while it sits at its bottom and offers "Jump to latest" (`ScrollToBottomButton`) when scrolled up; End does what that button does and Home goes back to the top of the messages loaded so far, both keeping away from a field being typed in, an open menu and an open modal (`typingInField`, `scrollThreadToTop`). 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` gates every tool outside `PlanModeToolNames` (`gatePlanModeTools`: the write tools stay listed with their own name, description and schema, and calling one throws the Plan mode reason, never "there is no tool called ...", since only `run` is replaced; `load_tools` is gated too, so a deferred MCP or browser tool can't be pulled in), `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. **Answering or skipping an `ask_user` card is not a way out:** the card carries `bot_questions.plan_mode` from the run that asked, and `postBotQuestionAnswers` runs the answer as a Plan mode reply too (only Tab, or approving a plan, turns the mode off). 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 either writes a plan they approve or tells them to turn Plan mode off, and `planModeFileEscape` sends a reply back when it hands the save to the user instead.
|
||||
- **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` gates every tool outside `PlanModeToolNames` (`gatePlanModeTools`: the write tools stay listed with their own name, description and schema, and calling one throws the Plan mode reason, never "there is no tool called ...", since only `run` is replaced; `load_tools` is gated too, so a deferred MCP or browser tool can't be pulled in), `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. **Answering or skipping an `ask_user` card is not a way out:** the card carries `bot_questions.plan_mode` from the run that asked, and `postBotQuestionAnswers` runs the answer as a Plan mode reply too (only Tab, or approving a plan, turns the mode off). A reply that ran in it carries `bot_messages.plan_mode` (`jobPlanMode` over the job's params) and shows `PlanModeOffButton` under it while the mode is still on: one click turns it off and puts "Plan mode is off, go ahead." in the composer (`turnOffPlanMode`, never sends), which is the click the bot's answer asks for. 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 either writes a plan they approve or tells them to turn Plan mode off, 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.
|
||||
|
||||
+1
-1
@@ -602,7 +602,7 @@ const schema: BUN_SQLITE_DatabaseSchemaType = {
|
||||
},
|
||||
{
|
||||
fieldName: "plan_mode",
|
||||
fieldDescription: `Sent with Plan mode on in the composer: the reply answers with a plan, reads only and changes nothing (no files, tasks, memory, computers, browsers or extensions), a strictly planning run`,
|
||||
fieldDescription: `Sent or answered with Plan mode on: the user's message that asked for a planning run, and the reply it got (which the thread offers to leave the mode under), a run that reads only and changes nothing (no files, tasks, memory, computers, browsers or extensions)`,
|
||||
dataType: "INTEGER",
|
||||
options: [0, 1],
|
||||
defaultValue: 0,
|
||||
|
||||
+1
-1
@@ -422,7 +422,7 @@ export type BUN_SQLITE_COBBLE_BOT_MESSAGES = {
|
||||
*/
|
||||
interim?: 0 | 1 | "";
|
||||
/**
|
||||
* Sent with Plan mode on in the composer: the reply answers with a plan, reads only and changes nothing (no files, tasks, memory, computers, browsers or extensions), a strictly planning run
|
||||
* Sent or answered with Plan mode on: the user's message that asked for a planning run, and the reply it got (which the thread offers to leave the mode under), a run that reads only and changes nothing (no files, tasks, memory, computers, browsers or extensions)
|
||||
*/
|
||||
plan_mode?: 0 | 1 | "";
|
||||
/**
|
||||
|
||||
@@ -1045,7 +1045,8 @@ 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. Approving it ends Plan mode.
|
||||
- When a choice is theirs, ask it with ask_user instead of picking for them. Answering it does not end Plan mode: their answer is another planning turn.
|
||||
- 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. Those tools are still in your list and calling one is refused with the reason, so don't say you did any of it, don't say a run is under way, and don't look for another way in.
|
||||
- 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 either write it as a plan they can approve (its steps save it) or tell them to turn Plan mode off (Tab) and you will write it. A short template they asked to read can stay in the message.
|
||||
- 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 either write it as a plan they can approve (its steps save it) or say what you will do once they turn Plan mode off. A short template they asked to read can stay in the message.
|
||||
- Every answer here carries a Turn Plan mode off button under it, so the way on is one click: say in one sentence what you will do once it is off, and stop there. Never hand the work back to them to paste or do by hand; turning the mode off (that button, or Tab) is the only thing in the way.
|
||||
- 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.`;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import onAskJobEnded from "../asks/on-ask-job-ended";
|
||||
import isUnattendedHookSession from "../bot-hooks/is-unattended-hook-session";
|
||||
import settleInstallRequest from "../install-requests/settle-install-request";
|
||||
import jobTrackerTaskId from "./job-tracker-task-id";
|
||||
import jobPlanMode from "./job-plan-mode";
|
||||
|
||||
type Params = {
|
||||
job_id: number | string;
|
||||
@@ -119,6 +120,7 @@ export default async function completeBotJob({
|
||||
tool_log,
|
||||
task_ids: message_task_ids,
|
||||
plan_id,
|
||||
plan_mode: jobPlanMode({ job }),
|
||||
});
|
||||
|
||||
if (job.id && inserted?.id) {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import jobPlanMode from "./job-plan-mode";
|
||||
|
||||
describe("jobPlanMode", () => {
|
||||
test("a reply queued from a Plan mode message", () => {
|
||||
expect(jobPlanMode({ job: { params: `{"plan_mode":true}` } })).toBe(true);
|
||||
});
|
||||
|
||||
test("a reply queued with other params", () => {
|
||||
expect(jobPlanMode({ job: { params: `{"retry_of":980,"plan_mode":true}` } })).toBe(true);
|
||||
});
|
||||
|
||||
test("an ordinary reply", () => {
|
||||
expect(jobPlanMode({ job: { params: `{"plan_id":4}` } })).toBe(false);
|
||||
});
|
||||
|
||||
test("no params at all, as a task run has", () => {
|
||||
expect(jobPlanMode({ job: { params: undefined } })).toBe(false);
|
||||
expect(jobPlanMode({ job: {} })).toBe(false);
|
||||
});
|
||||
|
||||
test("params it can't read", () => {
|
||||
expect(jobPlanMode({ job: { params: "not json" } })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { BUN_SQLITE_COBBLE_BOTS_QUEUE } from "@/db/types/db";
|
||||
import parseJobJson from "@/src/bots-queue/parse-job-json";
|
||||
|
||||
type Params = {
|
||||
job: Pick<BUN_SQLITE_COBBLE_BOTS_QUEUE, "params">;
|
||||
};
|
||||
|
||||
/**
|
||||
* The reply behind a job ran in Plan mode (`params.plan_mode`, set from the
|
||||
* user's message or a card asked in it). Its answer is recorded with the
|
||||
* flag, so the thread can offer to leave the mode under it.
|
||||
*/
|
||||
export default function jobPlanMode({ job }: Params): boolean {
|
||||
return Boolean(parseJobJson({ text: job.params })?.plan_mode);
|
||||
}
|
||||
@@ -44,6 +44,11 @@ type Params = {
|
||||
* (`carryOverBotSession`): the session it carries on from.
|
||||
*/
|
||||
carried_from_session_id?: number;
|
||||
/**
|
||||
* Set on a bot message whose reply ran in Plan mode: the thread offers
|
||||
* to leave the mode under it.
|
||||
*/
|
||||
plan_mode?: boolean;
|
||||
/**
|
||||
* Set on the app's failure notice: the job that failed
|
||||
* (`notifyBotJobFailed`). The thread offers Retry on a failed reply,
|
||||
@@ -68,6 +73,7 @@ export default async function insertBotMessage({
|
||||
task_ids,
|
||||
plan_id,
|
||||
carried_from_session_id,
|
||||
plan_mode,
|
||||
failed_job_id,
|
||||
}: Params): Promise<BUN_SQLITE_COBBLE_BOT_MESSAGES> {
|
||||
const now = Date.now();
|
||||
@@ -95,6 +101,7 @@ export default async function insertBotMessage({
|
||||
task_ids: task_ids_json,
|
||||
plan_id: plan_id ? Number(plan_id) : undefined,
|
||||
carried_from_session_id,
|
||||
plan_mode: plan_mode ? 1 : 0,
|
||||
failed_job_id,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -56,7 +56,7 @@ describe("Plan mode's tool gate", () => {
|
||||
|
||||
expect(refusal).toContain("Plan mode is on for this reply");
|
||||
expect(refusal).toContain(`${planned_tool.name} did not run`);
|
||||
expect(refusal).toContain("turn Plan mode off (Tab)");
|
||||
expect(refusal).toContain("turn it off (the button under your answer, or Tab)");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ const allowed = new Set<string>(PlanModeToolNames);
|
||||
* instead read as "there is no tool called ...", which was untrue.
|
||||
*/
|
||||
function planModeRefusal({ name }: { name: string }) {
|
||||
return `Plan mode is on for this reply: it plans and reads, and changes nothing, so ${name} did not run and nothing was changed. Say plainly that Plan mode stops it, and that they can turn Plan mode off (Tab) to have it done; otherwise finish with send_reply.`;
|
||||
return `Plan mode is on for this reply: it plans and reads, and changes nothing, so ${name} did not run and nothing was changed. Say plainly that Plan mode stops it, and that they can turn it off (the button under your answer, or Tab) to have it done; otherwise finish with send_reply.`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { BotMessageWithAttachments } from "@/src/types";
|
||||
|
||||
/**
|
||||
* The conversation's reply and reaction handlers, shared by every
|
||||
* message's actions.
|
||||
* message's actions, and the one piece of its own state they read: whether
|
||||
* its next message goes in Plan mode.
|
||||
*/
|
||||
export type BotMessageActions = {
|
||||
onReply: (params: { message: BotMessageWithAttachments }) => void;
|
||||
@@ -19,6 +20,16 @@ export type BotMessageActions = {
|
||||
* in their input, never send it.
|
||||
*/
|
||||
onUseSuggestion: (params: { text: string }) => void;
|
||||
/**
|
||||
* Whether this conversation's next message is in Plan mode, which is
|
||||
* what a reply that ran in it can offer to end.
|
||||
*/
|
||||
plan_mode: boolean;
|
||||
/**
|
||||
* Turn Plan mode off for this conversation and put what to say next in
|
||||
* the user's input, never send it (`PlanModeOffButton`).
|
||||
*/
|
||||
onTurnOffPlanMode: () => void;
|
||||
};
|
||||
|
||||
export const BotMessageActionsContext = React.createContext<BotMessageActions>({
|
||||
@@ -26,4 +37,6 @@ export const BotMessageActionsContext = React.createContext<BotMessageActions>({
|
||||
onReact: () => {},
|
||||
onRetry: () => {},
|
||||
onUseSuggestion: () => {},
|
||||
});
|
||||
plan_mode: false,
|
||||
onTurnOffPlanMode: () => {},
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import turnOffPlanMode, { PlanModeOffPrompt } from "./turn-off-plan-mode";
|
||||
|
||||
function makeHandlers() {
|
||||
const modes: boolean[] = [];
|
||||
const texts: string[] = [];
|
||||
|
||||
return {
|
||||
modes,
|
||||
texts,
|
||||
set_plan_mode: (on: boolean) => modes.push(on),
|
||||
insert_text: (params: { text: string }) => texts.push(params.text),
|
||||
};
|
||||
}
|
||||
|
||||
describe("turnOffPlanMode", () => {
|
||||
test("turns the conversation's mode off", () => {
|
||||
const handlers = makeHandlers();
|
||||
|
||||
turnOffPlanMode({
|
||||
set_plan_mode: handlers.set_plan_mode,
|
||||
insert_text: handlers.insert_text,
|
||||
});
|
||||
|
||||
expect(handlers.modes).toEqual([false]);
|
||||
});
|
||||
|
||||
test("puts the next message in the input instead of sending it", () => {
|
||||
const handlers = makeHandlers();
|
||||
|
||||
turnOffPlanMode({
|
||||
set_plan_mode: handlers.set_plan_mode,
|
||||
insert_text: handlers.insert_text,
|
||||
});
|
||||
|
||||
expect(handlers.texts).toEqual([PlanModeOffPrompt]);
|
||||
expect(PlanModeOffPrompt).toBe("Plan mode is off, go ahead.");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* What the input says after the user turns Plan mode off from a reply's
|
||||
* button: the bot's own offer ("turn it off and I'll do it") is waiting on
|
||||
* one message, so it is written out for them to edit or send.
|
||||
*/
|
||||
export const PlanModeOffPrompt = "Plan mode is off, go ahead.";
|
||||
|
||||
type Params = {
|
||||
/**
|
||||
* The conversation's Plan mode, turned off (`usePlanMode`).
|
||||
*/
|
||||
set_plan_mode: (on: boolean) => void;
|
||||
/**
|
||||
* The composer's input, filled at the cursor (`ComposerHandle.insertText`).
|
||||
*/
|
||||
insert_text: (params: { text: string }) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn Plan mode off for the conversation and put the next message in the
|
||||
* input, never sending it: the button under a Plan mode reply is the click
|
||||
* the bot asked for, and the user still decides what goes and when.
|
||||
*/
|
||||
export default function turnOffPlanMode({ set_plan_mode, insert_text }: Params) {
|
||||
set_plan_mode(false);
|
||||
insert_text({ text: PlanModeOffPrompt });
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import MessagePlanChip from "./message-plan-chip";
|
||||
import MessageTaskChips from "./message-task-chips";
|
||||
import MessageUsageChip from "./message-usage-chip";
|
||||
import NeedsYouChip from "./needs-you-chip";
|
||||
import PlanModeOffButton from "./plan-mode-off-button";
|
||||
import SpeakMessageButton from "./speak-message-button";
|
||||
|
||||
/**
|
||||
@@ -49,7 +50,8 @@ type Props = {
|
||||
* switch the bot to them. A quoted reply sits above it, the images it's
|
||||
* about (attached or named as files) under its text, the tracker tasks
|
||||
* it's about and its reactions below, and a row under it replies, reacts, reads it aloud and shows
|
||||
* why it needs you. Its text can be selected and quoted.
|
||||
* why it needs you, and a reply that ran in Plan mode carries the button
|
||||
* that leaves the mode. Its text can be selected and quoted.
|
||||
*
|
||||
* Memoized: a message only renders (and parses its markdown) again when
|
||||
* it changes, not on every live step of the thread.
|
||||
@@ -85,6 +87,11 @@ function BotMessageLine({ message, bot_name, at, rerun }: Props) {
|
||||
</Markdown>
|
||||
</Stack>
|
||||
<MessageImages message={message} />
|
||||
{message.plan_mode ? (
|
||||
<Row className="gap-2! items-center">
|
||||
<PlanModeOffButton />
|
||||
</Row>
|
||||
) : null}
|
||||
<MessageTaskChips tasks={message.tasks} />
|
||||
{message.plan_id ? <MessagePlanChip plan_id={Number(message.plan_id)} /> : null}
|
||||
{message.id ? (
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { BotMessageActionsContext, type BotMessageActions } from "../(data)/message-actions-context";
|
||||
import PlanModeOffButton from "./plan-mode-off-button";
|
||||
|
||||
type RenderProps = {
|
||||
plan_mode: boolean;
|
||||
};
|
||||
|
||||
function makeActions({ plan_mode }: RenderProps): BotMessageActions {
|
||||
return {
|
||||
onReply: () => {},
|
||||
onReact: () => {},
|
||||
onRetry: () => {},
|
||||
onUseSuggestion: () => {},
|
||||
plan_mode,
|
||||
onTurnOffPlanMode: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
function render({ plan_mode }: RenderProps) {
|
||||
return renderToString(
|
||||
<BotMessageActionsContext.Provider value={makeActions({ plan_mode })}>
|
||||
<PlanModeOffButton />
|
||||
</BotMessageActionsContext.Provider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("PlanModeOffButton", () => {
|
||||
test("offers the way out while the conversation is in Plan mode", () => {
|
||||
const html = render({ plan_mode: true });
|
||||
|
||||
expect(html).toContain("Turn Plan mode off");
|
||||
expect(html).toContain("the next message can write, run and change things");
|
||||
});
|
||||
|
||||
test("shows nothing once the mode is off", () => {
|
||||
expect(render({ plan_mode: false })).not.toContain("Turn Plan mode off");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useContext } from "react";
|
||||
import Button from "@moduletrace/twui/layout/Button";
|
||||
import { CircleOff } from "lucide-react";
|
||||
import { BotMessageActionsContext } from "../(data)/message-actions-context";
|
||||
|
||||
/**
|
||||
* Turns Plan mode off for the conversation, offered under a reply that ran
|
||||
* in it, so the bot's "turn Plan mode off and I'll do it" is one click: the
|
||||
* next message can write and run, and what to send is already in the input
|
||||
* (it never sends on its own). Nothing shows once the mode is off.
|
||||
*/
|
||||
export default function PlanModeOffButton() {
|
||||
const { plan_mode, onTurnOffPlanMode } = useContext(BotMessageActionsContext);
|
||||
|
||||
if (!plan_mode) return null;
|
||||
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
size="smaller"
|
||||
title="Turn Plan mode off: the next message can write, run and change things"
|
||||
beforeIcon={<CircleOff size={14} aria-hidden />}
|
||||
onClick={onTurnOffPlanMode}
|
||||
>
|
||||
Turn Plan mode off
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
type StopBotState,
|
||||
} from "../(data)/stop-bot-context";
|
||||
import reactToBotMessage from "../(functions)/react-to-bot-message";
|
||||
import turnOffPlanMode from "../(functions)/turn-off-plan-mode";
|
||||
import botBusyState from "../(utils)/bot-busy-state";
|
||||
import dropSentMessage from "../(utils)/drop-sent-message";
|
||||
import useBotComputers from "../(hooks)/use-bot-computers";
|
||||
@@ -153,7 +154,7 @@ export default function Conversation() {
|
||||
* left it on this device, and Tab anywhere on the page turns it on and
|
||||
* off.
|
||||
*/
|
||||
const { plan_mode, toggle_plan_mode } = usePlanMode({
|
||||
const { plan_mode, set_plan_mode, toggle_plan_mode } = usePlanMode({
|
||||
bot_id: bot?.id,
|
||||
workspace_id,
|
||||
});
|
||||
@@ -497,7 +498,9 @@ export default function Conversation() {
|
||||
|
||||
/**
|
||||
* Kept the same across renders, so a live step or a face change
|
||||
* doesn't re-render every message (they read it from context).
|
||||
* doesn't re-render every message (they read it from context). It
|
||||
* changes only when Plan mode does, which is what those messages'
|
||||
* button reads.
|
||||
*/
|
||||
const message_actions = useMemo(
|
||||
() => ({
|
||||
@@ -521,8 +524,14 @@ export default function Conversation() {
|
||||
},
|
||||
onUseSuggestion: ({ text }: { text: string }) =>
|
||||
composer.current?.insertText({ text }),
|
||||
plan_mode,
|
||||
onTurnOffPlanMode: () =>
|
||||
turnOffPlanMode({
|
||||
set_plan_mode,
|
||||
insert_text: (params) => composer.current?.insertText(params),
|
||||
}),
|
||||
}),
|
||||
[],
|
||||
[plan_mode, set_plan_mode],
|
||||
);
|
||||
|
||||
if (!bot?.id || !live_bot) return null;
|
||||
|
||||
@@ -464,7 +464,7 @@ describe("replyClaimProblems: the app's own state", () => {
|
||||
|
||||
expect(problems.length).toBe(1);
|
||||
expect(problems[0]).toContain("Plan mode");
|
||||
expect(problems[0]).toContain("turn Plan mode off (Tab)");
|
||||
expect(problems[0]).toContain("turn Plan mode off (the button under the answer, or Tab)");
|
||||
expect(problems[0]).not.toContain("their answer runs with the save allowed");
|
||||
});
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ export default function replyClaimProblems({
|
||||
|
||||
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 either write it as a plan they can approve (its steps save it) or tell them to turn Plan mode off (Tab) and you will write it. Answering a question does not end Plan mode. A short template the user asked to read can stay in the message.`,
|
||||
`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 either write it as a plan they can approve (its steps save it) or say what you will do once they turn Plan mode off (the button under the answer, or Tab). Answering a question does not end Plan mode. A short template the user asked to read can stay in the message.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user