A task run used to work out what the task was while spending its steps: the same file read again to see it once more, the same folder listed twice, a plan formed turn by turn at the price of a model call each. - `planBotTask` spends one turn before the first step 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 bounded JSON plan (`BotTaskPlanSchema`) opens the run as `taskPlanNote` and shows as its first step line. `shouldPlanBotTask` keeps it off short runs and chatroom turns, and a plan that can't be written starts the run the way it always did. - `runTextLoop` answers a read it already made from that answer (`RepeatableToolNames`, `repeatToolCallKey`, `alreadyRanToolNote`) instead of running it again; any non-read tool clears what was remembered, so a file read, edited and read again is read again.
28 lines
871 B
TypeScript
28 lines
871 B
TypeScript
import { BotTaskPlanSchema, type BotTaskPlan } from "./bot-task-plan-schema";
|
|
|
|
/**
|
|
* Reads the plan a planning turn answered with. Models wrap JSON in a code
|
|
* fence or a sentence whatever the prompt says, so the object is cut out
|
|
* of the answer first. Null when it isn't a plan: the run then starts the
|
|
* way it always did, since a plan is an economy and never a gate.
|
|
*/
|
|
export default function parseBotTaskPlan({ text }: { text?: string | null }): BotTaskPlan | null {
|
|
if (!text) return null;
|
|
|
|
const start = text.indexOf("{");
|
|
const end = text.lastIndexOf("}");
|
|
|
|
if (start < 0 || end <= start) return null;
|
|
|
|
let value: unknown;
|
|
|
|
try {
|
|
value = JSON.parse(text.slice(start, end + 1));
|
|
} catch {
|
|
return null;
|
|
}
|
|
|
|
const parsed = BotTaskPlanSchema.safeParse(value);
|
|
|
|
return parsed.success ? parsed.data : null;
|
|
} |