Auto-clear completed todo trees

This commit is contained in:
jb
2026-08-26 18:07:46 -04:00
parent 91a019de29
commit fbe8baf18c
9 changed files with 283 additions and 17 deletions
+6 -2
View File
@@ -7,15 +7,17 @@ import { registerTaskTools } from "../src/tools.ts";
function registeredTools(state = new TaskState()) {
const tools = new Map<string, any>();
let changes = 0;
const autoClearRestarts: boolean[] = [];
const pi = {
registerTool(tool: any) {
tools.set(tool.name, tool);
},
};
registerTaskTools(pi as never, state, () => {
registerTaskTools(pi as never, state, (_ctx, restartAutoClear = false) => {
changes += 1;
autoClearRestarts.push(restartAutoClear);
});
return { tools, state, changes: () => changes };
return { tools, state, changes: () => changes, autoClearRestarts };
}
async function execute(tool: any, params: unknown) {
@@ -209,6 +211,7 @@ test("set_tasks appends optional-description tasks and persists a complete snaps
assert.equal(result.details.snapshot.tasks[0].description, undefined);
assert.equal(result.details.snapshot.nextId, 3);
assert.equal(harness.changes(), 1);
assert.deepEqual(harness.autoClearRestarts, [false]);
});
test("set_tasks atomically replaces or clears the tree and resets IDs", async () => {
@@ -232,6 +235,7 @@ test("set_tasks atomically replaces or clears the tree and resets IDs", async ()
});
assert.equal(cleared.content[0].text, "Cleared task tree. Task IDs reset to 1.");
assert.deepEqual(harness.state.snapshot(), { tasks: [], nextId: 1 });
assert.deepEqual(harness.autoClearRestarts, [false, true, true]);
});
test("tool validation errors preserve atomic state", async () => {