Skip to content

Commit 32dcec1

Browse files
committed
PL7: an agent finishes what it planned. A task marked done with a checkbox unticked or a subtask open is refused by the plan tools (plan_close, plan_update's state), naming each by place or id, as Org's org-enforce-todo-dependencies refuses; plan_close's all: true ticks them and closes the subtasks with it, and ticked in the same call it closes. Shane 11-16: "i notice often that it makes tasks but never completes them itself": v0.1.5's agent closed five tasks with every box unticked, so the list read 0/4 on finished work. docs/plan.feature PL7 says the rest, which is the app's (raea-feed plan-finish: raea asks an agent to settle its own open tasks each time it stops).
Checked: bun test (org, edit, extend, tools) 33 of 33; the app's vitest 1621 with these files; e2e chat-plan in raea's window, where a real ACP stand-in's close without all is refused and its retry with all: true closes.
1 parent 3a646fa commit 32dcec1

3 files changed

Lines changed: 142 additions & 5 deletions

File tree

‎docs/plan.feature‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ Feature: Plans: a project's plan.org, kept by its agents
2525
# (Rust, engine/cli), so reference/files.md, generated from it, doesn't list one; the page makes it on the first
2626
# write. The brief page (BriefView, unmounted) still draws a brief's own ## Tasks. Compositions can't import
2727
# @raea/task until sdk/tsconfig.base.json and raea's bundler map it.
28+
# 11-16: PL7, agents finish what they plan (raea-feed plan-finish: plan/keeper.ts, PlanKeeper.tsx; sdk/task tools.ts).
29+
# Checked in raea's window: e2e chat-plan 2 of 2 with a real ACP stand-in planning through the tool port, and
30+
# chat-goal, respawn, todo, outside, heads, primary, consolidate, ai-login unchanged; vitest 1621; sdk/task 33.
2831

2932
Background:
3033
Given the app's code is apps/app (raea-feed), the SDK sdk/task, the skill skills/raea/plan.md in raea-skills
3134
And the plan's tests: sdk/task/test/*.test.ts (PL2, PL3, PL5, PL6), apps/app src/plan/plan.test.ts (PL1c, PL4, PL4c,
3235
PL5), src/plan/agent.test.ts (PL5a, PL5b), host/plan.test.ts (PL4, PL5), src/feed/todo.test.ts and outside.test.ts
33-
(PL4b), e2e/todo.spec.ts (PL4b)
36+
(PL4b), e2e/todo.spec.ts (PL4b), apps/app src/plan/keeper.test.ts and e2e/chat-plan.spec.ts (PL7)
3437

3538
Rule: PL1. A project's plan is plan.org at the top of its folder
3639
# Why there: it's the project's own file, versioned with it in the workspace's repo, found by anyone who opens the
@@ -198,3 +201,60 @@ Feature: Plans: a project's plan.org, kept by its agents
198201
Then usePlan(text or source) gives the plan, its text and edit; useView a registered view; TaskLine, PlanOutline,
199202
Agenda and BoardLanes draw them, with toggled for a checkbox's edit
200203
And none of it uses a dynamic import or dangerouslySetInnerHTML, so raea's window bundle (one IIFE) holds it
204+
205+
Rule: PL7. An agent finishes what it planned
206+
# Shane, 2026-11-16: "i notice often that it makes tasks but never completes them itself". His plans that morning:
207+
# TarotChess's agent posted a first pass and left its own follow-ups TODO (frame rate, a clipping score, a dark
208+
# encode); Cadence's said "all six masters are finished and posted" over a plan still saying Track MAKING and Build,
209+
# Render and Masters TODO (it had woken itself on a render's report, a turn raea sends no plan with); v0.1.5's
210+
# closed five tasks with every checkbox unticked, so the list read 0/4 on finished work; and its last turn ended
211+
# with Film v2's tasks MAKING, "waiting on three helpers", when the session stopped under them. Nothing asked any
212+
# of them to go on: only a /goal does that, and only when the person sets one.
213+
214+
@done
215+
Scenario: PL7a. Each time an agent stops with tasks of its own open, raea asks it to settle them
216+
Given a chat in a project whose agent's turn ends (apps/app src/plan/PlanKeeper.tsx, beside GoalKeeper)
217+
And tasks of its own are TODO or MAKING in the plan, read from the file first
218+
Then raea's next turn to it lists them by id ("[raea plan] Ask N: ...") and says how each is settled: closed with
219+
the item it made, done now and closed, REVIEW saying what it needs from the person, dropped with why, or a
220+
line starting "WAITING:" naming the job of its own that will report back
221+
And it asks again each time the agent stops while one is TODO or MAKING; REVIEW is the person's, and ends it
222+
And the rule each turn carries says the same: finish what you planned; before you stop, every task of yours is
223+
closed, REVIEW or waiting on a job; close what a job finished when it reports back in a turn you started
224+
225+
@done
226+
Scenario: PL7b. The asks stop
227+
Then they stop when none of its tasks is TODO or MAKING, or pause, saying why, when the person presses Stop, its
228+
session closes or the turn fails, its reply has a WAITING: line, two asks in a row leave the plan as it was, or
229+
12 have gone since the person's last message
230+
And the person's next message starts them again from nothing, and Continue over the composer asks at once
231+
And a chat with an open /goal is the goal's: its checks keep it going, and the plan's asks wait until it's met
232+
233+
@done
234+
Scenario: PL7c. Which tasks are the agent's
235+
Then a task is the chat's when its agent (or the chat) holds it; or nobody holds it and it stands on an item the
236+
chat posted (its :ITEM:, or a note's item in its :FROM:: an agent writing plan.org by hand leaves :AGENT: out);
237+
or nobody holds it and it's MAKING while no other agent holds open work
238+
And a task nobody holds otherwise is the person's (written in the to-do list or Emacs, moved from a brief): never
239+
pushed on whoever is chatting; one SCHEDULED for a later day waits for that day
240+
241+
@done
242+
Scenario: PL7d. Done means its checkboxes and subtasks are done
243+
When an agent marks a task done (plan_close, or plan_update's state) while a checkbox under it is unticked or a
244+
subtask open, as Org's org-enforce-todo-dependencies refuses
245+
Then the tool refuses, naming each by its place or id, and nothing is written
246+
And plan_close with all: true ticks them and closes the subtasks with it; ticked in the same call, it closes
247+
And dropped closes whatever is under it as it is; the person's own check-off in the to-do list isn't refused
248+
249+
@done
250+
Scenario: PL7e. A post names what's still open
251+
Given an agent's feed_post in a project
252+
Then its answer carries the agent's open tasks and asks it to close what the post finished, with the item, so a
253+
turn the agent started itself (a job reporting back carries no plan) still closes them
254+
255+
@done
256+
Scenario: PL7f. Seen in the chat
257+
Then each ask is a small line of its own ("Finishing the plan (2): 3 open"), never the marker in the person's words
258+
And over the composer, while it asks or after it pauses with tasks open, one line: "Plan 3 of its tasks open",
259+
"Finishing · ask 2" with × to stop asking until the next message, or "Paused · Continue" with why on hover
260+

‎sdk/task/src/tools.ts‎

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// and how to make edits on it, and these turn a tool's input into plan edits (edit.ts) and its answer into the open
44
// tasks with their ids. The app's page answers them through its plans, a headless run on the folder's plan.org.
55
import { planDigest } from "./digest.ts"
6-
import type { PlanEdit, TaskFields } from "./edit.ts"
7-
import { isClosed, readPlan } from "./model.ts"
6+
import { applyEdits, type PlanEdit, type TaskFields } from "./edit.ts"
7+
import { find, isClosed, readPlan, type Plan, type State, type Task } from "./model.ts"
88

99
export const PLAN_TOOLS = ["plan_read", "plan_add", "plan_update", "plan_close"] as const
1010
export type PlanTool = (typeof PLAN_TOOLS)[number]
@@ -82,6 +82,54 @@ export function planToolEdits(tool: Exclude<PlanTool, "plan_read">, input: Recor
8282
})
8383
}
8484

85+
/** The state a keyword or state name means in this plan. */
86+
const meant = (plan: Plan, state: string): State | undefined => plan.words.get(state) ?? plan.words.get(state.toUpperCase()) ?? (state.toLowerCase() as State)
87+
88+
/** A task and what is still open under it: its unticked checkboxes, by place, and every open task below it. */
89+
function openUnder(plan: Plan, t: Task): { boxes: number[]; tasks: Task[] } {
90+
const tasks: Task[] = []
91+
const walk = (ref: string) => {
92+
for (const r of find(plan, ref)?.children ?? []) {
93+
const k = find(plan, r)
94+
if (k?.state && !isClosed(k.state)) tasks.push(k)
95+
if (k) walk(k.ref)
96+
}
97+
}
98+
walk(t.ref)
99+
return { boxes: t.checks.flatMap((c, i) => (c.done ? [] : [i])), tasks }
100+
}
101+
102+
const quoted = (s: string) => `"${s.length > 40 ? `${s.slice(0, 39)}…` : s}"`
103+
104+
/** The tasks a call marks done while work under them is still open (Org's org-enforce-todo-dependencies and its
105+
* checkbox twin: a DONE that still shows [0/4] says the work isn't done). Each is refused, naming what's open, unless
106+
* `all` says every one of them is done: then they are ticked and closed with it, after the call's own edits. */
107+
function closesOpen(text: string, edits: PlanEdit[], all: boolean, tool: PlanTool): PlanEdit[] {
108+
const before = readPlan(text)
109+
const done = edits.flatMap((e, i) => (e.op === "state" && meant(before, e.state) === "done" && meant(before, find(before, e.ref)?.keyword ?? "") !== "done" ? [i] : []))
110+
if (!done.length) return []
111+
const dry = applyEdits(text, edits)
112+
const fix: PlanEdit[] = []
113+
for (const i of done) {
114+
const t = find(dry.plan, dry.refs[i])
115+
if (!t) continue
116+
const left = openUnder(dry.plan, t)
117+
if (!left.boxes.length && !left.tasks.length) continue
118+
if (!all) {
119+
const parts = [
120+
...(left.boxes.length ? [`${left.boxes.length} unticked checkbox${left.boxes.length > 1 ? "es" : ""} (${left.boxes.map((b) => `${b} ${quoted(t.checks[b].text)}`).join(", ")})`] : []),
121+
...(left.tasks.length ? [`${left.tasks.length} open subtask${left.tasks.length > 1 ? "s" : ""} (${left.tasks.map((k) => `${k.ref} ${quoted(k.text)}`).join(", ")})`] : []),
122+
]
123+
const how = tool === "plan_close" ? "or close it with all: true when every one is done" : "or close it with plan_close and all: true when every one is done"
124+
throw new Error(`${t.ref} still has ${parts.join(" and ")}: tick what's done (plan_update check), close or move what's left, ${how}`)
125+
}
126+
const state = (edits[i] as Extract<PlanEdit, { op: "state" }>).state
127+
for (const k of [t, ...left.tasks]) for (const b of openUnder(dry.plan, k).boxes) fix.push({ op: "check", ref: k.ref, index: b, done: true })
128+
for (const k of left.tasks) fix.push({ op: "state", ref: k.ref, state })
129+
}
130+
return fix
131+
}
132+
85133
/** A tool answered: plan_read gives the open tasks by id (and the whole text with full), giving any task without an id
86134
* one first; an edit gives the ids it touched and the open tasks after it. */
87135
export async function answerPlanTool(tool: PlanTool, input: Record<string, unknown>, h: PlanToolHost): Promise<unknown> {
@@ -97,6 +145,11 @@ export async function answerPlanTool(tool: PlanTool, input: Record<string, unkno
97145
const close = edits[0]
98146
if (tool === "plan_close" && close.op === "state" && !/^(done|dropped)$/i.test(close.state) && !isClosed(readPlan(h.text()).words.get(close.state)))
99147
throw new Error(`state: done or dropped, or a closing keyword of the plan's; ${close.state} doesn't close (plan_update sets it)`)
100-
const r = await h.apply(edits)
148+
// a task marked done with work still open under it: every task named by id first, so the ids a dry run reads are the
149+
// ones the file keeps
150+
let text = h.text()
151+
if (edits.some((e) => e.op === "state") && readPlan(text).tasks.some((t) => !t.id)) text = (await h.apply([])).text
152+
const fix = closesOpen(text, edits, tool === "plan_close" && input.all === true, tool)
153+
const r = await h.apply([...edits, ...fix])
101154
return { file, ids: [...new Set(r.refs.filter(Boolean))], open: planDigest(readPlan(r.text)) }
102155
}

‎sdk/task/test/tools.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe("an agent's plan tools", () => {
6161

6262
test("plan_close closes with CLOSED, the item it made and a note; dropped keeps the task", async () => {
6363
const h = host()
64-
await answerPlanTool("plan_close", { id: "t-door", item: "i-door-3", note: "Warm key at 3200K." }, h)
64+
await answerPlanTool("plan_close", { id: "t-door", item: "i-door-3", note: "Warm key at 3200K.", all: true }, h)
6565
expect(h.now()).toContain("** DONE Light the door\nCLOSED: [2026-11-14 Sat 16:40]")
6666
expect(h.now()).toContain(":ITEM: i-door-3")
6767
expect(h.now()).toContain("Warm key at 3200K.")
@@ -88,4 +88,28 @@ describe("an agent's plan tools", () => {
8888
expect(r.open).not.toMatch(/#\d/)
8989
expect(h.now()).toContain("** TODO Written in Emacs\n:PROPERTIES:\n:ID: t-new1\n:END:\n")
9090
})
91+
92+
test("done with its checkboxes unticked or a subtask open is refused, naming them; all: true ticks and closes them with it", async () => {
93+
const h = host()
94+
await expect(answerPlanTool("plan_close", { id: "t-door" }, h)).rejects.toThrow(/t-door still has 2 unticked checkboxes \(0 "warm key", 1 "cool fill"\): tick what's done \(plan_update check\), close or move what's left, or close it with all: true/)
95+
await expect(answerPlanTool("plan_update", { changes: [{ id: "t-door", state: "done" }] }, h)).rejects.toThrow(/or close it with plan_close and all: true/)
96+
expect(h.now()).toBe(START)
97+
// ticked in the same call, in either order, it closes
98+
await answerPlanTool("plan_update", { changes: [{ id: "t-door", check: 0 }, { id: "t-door", check: 1, state: "done" }] }, h)
99+
expect(find(readPlan(h.now()), "t-door")).toMatchObject({ state: "done", progress: { done: 2, total: 2 } })
100+
// dropped leaves what's open as it was
101+
const d = host()
102+
await answerPlanTool("plan_close", { id: "t-door", state: "dropped" }, d)
103+
expect(find(readPlan(d.now()), "t-door")!.progress).toEqual({ done: 0, total: 2 })
104+
// an open subtask, and its own checkbox, the same
105+
const sub = host(`${START}*** TODO Rim light\n:PROPERTIES:\n:ID: t-rim\n:END:\n- [ ] gel\n`)
106+
await expect(answerPlanTool("plan_close", { id: "t-door", all: false }, sub)).rejects.toThrow(/2 unticked checkboxes .* and 1 open subtask \(t-rim "Rim light"\)/)
107+
await answerPlanTool("plan_close", { id: "t-door", all: true }, sub)
108+
const p = readPlan(sub.now())
109+
expect([find(p, "t-door")!.state, find(p, "t-rim")!.state, find(p, "t-rim")!.checks[0].done, find(p, "t-door")!.checks.every((c) => c.done)]).toEqual(["done", "done", true, true])
110+
// a task already done isn't asked again (a note added to it, say)
111+
const was = host(START.replace("** TODO", "** DONE"))
112+
await answerPlanTool("plan_close", { id: "t-door", note: "Kept." }, was)
113+
expect(was.now()).toContain("Kept.")
114+
})
91115
})

0 commit comments

Comments
 (0)