mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
The rules are raea/goal's (sdk/goal), run by `raea goal check` at four moments: the hook after a save, every render's end, raea cloud's publish, and the Stop hook. Rust's cut and goal gates and the box's word, sound, frame and place checks are packs (MK30-MK39); runtime/cut-plan, runtime/goal-plan, raea make status and the box's check code are gone with no alias (MK41). brief.ts is the one registered root (MK43): raea runs it, and every file that imports raea must be reached from it (the registered check, an error at publish and done). Its tasks are its `plan` (MK44), read from its run and written back where each is written by `raea goal tasks`, the one path for the app, agents and the box. Its `goal` is one goal or a workflow of several (MK46), each with its step, after and rules, checked and reported alone. Taste lines and signed asks run inside the loop (MK47). `raea goal check|tasks|seen|judge|gates|next` is the loop; `raea make clothes|motion|solid|wear|splat|physics|bake| sao|tokensynth|sounds|component|blockout|...` the asset tools (MK45). Old names are refused with where they went. docs/make.feature is docs/goal.feature; tools/legacy-names.sh holds the old names out. raea's Node mode on JavaScriptCore now gives a CommonJS package's names as named exports (React's jsx), loads a file a tool imports by URL, keeps process.exit's code from a promise callback, and reads stdin as fd 0, so the goal runner runs on the shipped binary.
127 lines
7.2 KiB
TypeScript
127 lines
7.2 KiB
TypeScript
// PL5: a plan's tools for an agent (src/tools.ts), answered on a plan in memory the way the app and a headless run do.
|
|
import { describe, expect, test } from "vitest"
|
|
import { answerPlanTool, find, planToolEdits, type PlanToolHost } from "../src"
|
|
import { applyEdits, readPlan, value } from "./text"
|
|
|
|
const NOW = new Date(2026, 10, 14, 16, 40)
|
|
const START = `import { plan } from "raea/task"
|
|
|
|
export default plan({
|
|
title: "Stay",
|
|
keywords: ["TODO MAKING REVIEW | DONE DROPPED"],
|
|
tasks: [
|
|
{
|
|
title: "Look",
|
|
tasks: [
|
|
{
|
|
id: "t-door",
|
|
keyword: "TODO",
|
|
title: "Light the door",
|
|
notes: ["- [ ] warm key", "- [ ] cool fill"],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
`
|
|
/** START with another task under Light the door, or beside it */
|
|
const withTask = (task: string, under = true) => (under ? START.replace(`"- [ ] cool fill"],\n`, `"- [ ] cool fill"],\n tasks: [${task}],\n`) : START.replace(" },\n ],\n },\n ],", ` },\n ${task},\n ],\n },\n ],`))
|
|
|
|
/** A host on a plan in memory: the page's and a box's, minus `raea make tasks` (the brief run, the edit written back). */
|
|
function host(text = START): PlanToolHost & { now: () => string } {
|
|
let n = 0
|
|
let at = text
|
|
return {
|
|
who: "a-light",
|
|
plan: () => value(at),
|
|
apply: (edits) => {
|
|
const r = applyEdits(at, edits, { now: NOW, newId: () => `t-new${++n}` })
|
|
at = r.text
|
|
return r
|
|
},
|
|
now: () => at,
|
|
}
|
|
}
|
|
|
|
describe("an agent's plan tools", () => {
|
|
test("plan_read gives the open tasks by id, and the whole file with full", async () => {
|
|
const h = host()
|
|
const r = (await answerPlanTool("plan_read", {}, h)) as { file: string; open: string; plan?: unknown }
|
|
expect(r.file).toBe("plan.ts")
|
|
expect(r.open).toContain("t-door TODO Light the door")
|
|
expect(r.plan).toBeUndefined()
|
|
expect(((await answerPlanTool("plan_read", { full: true }, h)) as { plan: unknown }).plan).toEqual(value(START))
|
|
})
|
|
|
|
test("plan_add writes tasks under their stage, held by the agent that asked unless it names others", async () => {
|
|
const h = host()
|
|
const r = (await answerPlanTool("plan_add", { tasks: [{ title: "Grade the hall", under: "Look", priority: "A", deadline: "2026-11-20", tags: ["look"] }, { title: "Score it", agents: ["a-score"] }] }, h)) as { ids: string[] }
|
|
expect(r.ids).toEqual(["t-new1", "t-new2"])
|
|
const plan = readPlan(h.now())
|
|
expect(find(plan, "t-new1")).toMatchObject({ stage: "Look", level: 2, priority: "A", agents: ["a-light"], tags: ["look"], deadline: { date: "2026-11-20" } })
|
|
expect(find(plan, "t-new2")).toMatchObject({ level: 1, agents: ["a-score"] })
|
|
expect(h.now()).toContain('keyword: "TODO",\n priority: "A",\n title: "Grade the hall",')
|
|
})
|
|
|
|
test("plan_update marks, ticks, adds a checkbox, moves and sets fields by id", async () => {
|
|
const h = host()
|
|
await answerPlanTool("plan_update", { changes: [{ id: "t-door", state: "making", check: 0, add_check: "rim light", item: "i-door-2" }] }, h)
|
|
const t = find(readPlan(h.now()), "t-door")!
|
|
expect([t.keyword, t.item, t.checks.map((c) => `${c.done ? "x" : " "} ${c.text}`)]).toEqual(["MAKING", "i-door-2", ["x warm key", " cool fill", " rim light"]])
|
|
expect(t.progress).toEqual({ done: 1, total: 3 })
|
|
})
|
|
|
|
test("plan_close closes with CLOSED, the item it made and a note; dropped keeps the task", async () => {
|
|
const h = host()
|
|
await answerPlanTool("plan_close", { id: "t-door", item: "i-door-3", note: "Warm key at 3200K.", all: true }, h)
|
|
expect(find(readPlan(h.now()), "t-door")).toMatchObject({ keyword: "DONE", closed: { date: "2026-11-14", time: "16:40" }, item: "i-door-3" })
|
|
expect(h.now()).toContain("Warm key at 3200K.")
|
|
const d = host()
|
|
await answerPlanTool("plan_close", { id: "t-door", state: "dropped" }, d)
|
|
expect(find(readPlan(d.now()), "t-door")!.state).toBe("dropped")
|
|
})
|
|
|
|
test("a wrong input or a task that isn't there is said, and nothing is written", async () => {
|
|
const h = host()
|
|
expect(() => planToolEdits("plan_add", { tasks: [] }, "a")).toThrow(/at least one/)
|
|
expect(() => planToolEdits("plan_update", { changes: [{ id: "t-door" }] }, "a")).toThrow(/nothing to change/)
|
|
expect(() => planToolEdits("plan_close", { id: "t-door", state: "making" }, "a")).toThrow(/done or dropped/)
|
|
await expect(answerPlanTool("plan_close", { id: "t-door", state: "MAKING" }, h)).rejects.toThrow(/MAKING doesn't close/)
|
|
await expect(answerPlanTool("plan_close", { id: "t-gone" }, h)).rejects.toThrow(/no task t-gone/)
|
|
await expect(answerPlanTool("plan_add", { tasks: [{ title: "x", under: "t-gone" }] }, h)).rejects.toThrow(/no task t-gone/)
|
|
expect(h.now()).toBe(START)
|
|
})
|
|
|
|
test("plan_read gives a task written by hand without an id one first, so the agent never names a task by its place", async () => {
|
|
const h = host(withTask(`{ keyword: "TODO", title: "Written by hand" }`, false))
|
|
const r = (await answerPlanTool("plan_read", {}, h)) as { open: string }
|
|
expect(r.open).toContain("t-new1 TODO Written by hand")
|
|
expect(r.open).not.toMatch(/#\d/)
|
|
expect(h.now()).toContain('id: "t-new1",\n keyword: "TODO",\n title: "Written by hand",')
|
|
})
|
|
|
|
test("done with its checkboxes unticked or a subtask open is refused, naming them; all: true ticks and closes them with it", async () => {
|
|
const h = host()
|
|
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/)
|
|
await expect(answerPlanTool("plan_update", { changes: [{ id: "t-door", state: "done" }] }, h)).rejects.toThrow(/or close it with plan_close and all: true/)
|
|
expect(h.now()).toBe(START)
|
|
// ticked in the same call, in either order, it closes
|
|
await answerPlanTool("plan_update", { changes: [{ id: "t-door", check: 0 }, { id: "t-door", check: 1, state: "done" }] }, h)
|
|
expect(find(readPlan(h.now()), "t-door")).toMatchObject({ state: "done", progress: { done: 2, total: 2 } })
|
|
// dropped leaves what's open as it was
|
|
const d = host()
|
|
await answerPlanTool("plan_close", { id: "t-door", state: "dropped" }, d)
|
|
expect(find(readPlan(d.now()), "t-door")!.progress).toEqual({ done: 0, total: 2 })
|
|
// an open subtask, and its own checkbox, the same
|
|
const sub = host(withTask(`{ id: "t-rim", keyword: "TODO", title: "Rim light", notes: ["- [ ] gel"] }`))
|
|
await expect(answerPlanTool("plan_close", { id: "t-door", all: false }, sub)).rejects.toThrow(/2 unticked checkboxes .* and 1 open subtask \(t-rim "Rim light"\)/)
|
|
await answerPlanTool("plan_close", { id: "t-door", all: true }, sub)
|
|
const p = readPlan(sub.now())
|
|
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])
|
|
// a task already done isn't asked again (a note added to it, say)
|
|
const was = host(START.replace('keyword: "TODO"', 'keyword: "DONE"'))
|
|
await answerPlanTool("plan_close", { id: "t-door", note: "Kept." }, was)
|
|
expect(was.now()).toContain("Kept.")
|
|
})
|
|
})
|