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.
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { AppData } from "@/src/data/app-data";
|
|
import parseBotTaskPlan from "./parse-bot-task-plan";
|
|
|
|
const plan = {
|
|
goal: "Ship the release notes",
|
|
gather: ["docs/changelog.md"],
|
|
steps: ["Read the changelog", "Write the notes", "Publish them"],
|
|
done: "The notes are on the site",
|
|
};
|
|
|
|
describe("parseBotTaskPlan", () => {
|
|
test("reads a plan", () => {
|
|
expect(parseBotTaskPlan({ text: JSON.stringify(plan) })).toEqual(plan);
|
|
});
|
|
|
|
test("tolerates a code fence and a sentence around the object", () => {
|
|
const fenced = `Here is the plan:\n\`\`\`json\n${JSON.stringify(plan)}\n\`\`\`\nReady.`;
|
|
|
|
expect(parseBotTaskPlan({ text: fenced })).toEqual(plan);
|
|
});
|
|
|
|
test("fills what a plan may leave out", () => {
|
|
expect(parseBotTaskPlan({ text: `{"goal":"G","steps":["one"]}` })).toEqual({
|
|
goal: "G",
|
|
gather: [],
|
|
steps: ["one"],
|
|
done: "",
|
|
});
|
|
});
|
|
|
|
test("is null when it isn't a plan", () => {
|
|
expect(parseBotTaskPlan({})).toBeNull();
|
|
expect(parseBotTaskPlan({ text: null })).toBeNull();
|
|
expect(parseBotTaskPlan({ text: "" })).toBeNull();
|
|
expect(parseBotTaskPlan({ text: "I will just do it." })).toBeNull();
|
|
expect(parseBotTaskPlan({ text: "{nope" })).toBeNull();
|
|
expect(parseBotTaskPlan({ text: `{"goal":"G"}` })).toBeNull();
|
|
expect(parseBotTaskPlan({ text: `{"goal":"","steps":["one"]}` })).toBeNull();
|
|
expect(parseBotTaskPlan({ text: `{"goal":"G","steps":[]}` })).toBeNull();
|
|
});
|
|
|
|
test("caps how much a plan may ask for", () => {
|
|
const too_many = {
|
|
goal: "G",
|
|
steps: Array.from({ length: AppData.BotTaskPlanMaxSteps + 1 }, (_, index) => `step ${index}`),
|
|
};
|
|
|
|
expect(parseBotTaskPlan({ text: JSON.stringify(too_many) })).toBeNull();
|
|
expect(
|
|
parseBotTaskPlan({
|
|
text: JSON.stringify({ ...too_many, steps: too_many.steps.slice(1), goal: "x".repeat(AppData.BotTaskPlanTextMaxChars + 1) }),
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
}); |