A wake turn is busy, steerable and queued behind, and the history marks it
ci / check (push) Canceled after 0s
ci / check (push) Canceled after 0s
In a session the service holds, "a turn runs" was `prompting`, which only a session/prompt sets. A turn the harness started (a job's note waking the session) therefore read as idle: status said not busy and named no turn, a steer was refused, compact and rewind were let through, the session could be let go of and the link closed under it, and a prompt that arrived meanwhile ran into the engine, failed with "busy" and left the turn log saying the wrong turn had finished. The link's agent now follows every `task` event: a turn no prompt of the client's began is kept in the session's turn log (as a terminal's turns are) and holds the prompt queue until its end. `working()` is the one question status, steer, compact, rewind and letting go ask. A message steered into such a turn and not taken in goes back as `unsent` on its `task` end. `_lembas/session/history` marks the note's user turn `machine`. tests/acp-wake-turn.test.ts: status during the turn, the history, a steer joining it, Stop, a prompt waiting behind it, and two notes in a row — as two turns in order, and as one turn when the second arrives while the first runs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
5 files changed
+322
-14
No files matched your search
@@ -6,6 +6,33 @@ All notable changes to LLeMbas CLI. The format follows
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
Harness spec 3.10.0: a turn the harness starts by itself is a turn like any other over the link.
|
||||
|
||||
### Added
|
||||
|
||||
- **Harness spec 3.10.0: a turn the harness starts** (`harness/acp.md`, capability
|
||||
`harness_turns`). When a background job or a subagent finishes while the session is idle, its
|
||||
note starts a turn by itself. In an agent chat driven from the web, that turn now behaves like
|
||||
one you started: the chat shows it as working and can follow it after a restart or a dropped
|
||||
connection, and the session's history marks the note as the harness's (`machine`) rather than
|
||||
as something you typed. The server uses this from the version that carries spec 3.10.0.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **A message sent while the agent answers a subagent's report is no longer refused.** It joins
|
||||
that turn at its next step, as it does during a turn you started; one the turn ended before
|
||||
taking in is handed back to the web UI to send next instead of being lost.
|
||||
- **A prompt sent while the agent answers a finished job or a subagent's report waits its turn.**
|
||||
It used to fail with `busy`, and left the session's record of which turn was running wrong.
|
||||
- **Compacting or rewinding a session is refused while such a turn runs**, and the service no
|
||||
longer lets go of the session, or closes the link for a change of `remote:` settings, under it.
|
||||
|
||||
### Changed
|
||||
|
||||
- **The main agent is told plainly how reports reach it** (`blocks/team_lead.md`): it does not
|
||||
wait or ask for them, each one starts its next turn, and it then answers you unasked — it never
|
||||
tells you to ask again. Sessions started before this keep the prompt they began with.
|
||||
|
||||
## [2.0.0-beta.12] — 2026-11-18
|
||||
|
||||
Harness spec 3.9.0: the model last used in a directory, Chat and Agentic schedules, models that are for a person's own turns only.
|
||||
|
||||
+62
-12
@@ -182,6 +182,9 @@ export interface Session {
|
||||
off?: () => void
|
||||
/** Prompts that came while it worked: they wait their turn instead of being refused. */
|
||||
queue?: Promise<unknown>
|
||||
/** The turn the harness started by itself and runs now (a note waking the session, acp.md *A turn
|
||||
* the harness starts*): no prompt of the client's began it, and `end` lets the queue move on. */
|
||||
own?: { turnId: string; end: () => void }
|
||||
/** Its turns by id: a prompt sent twice runs once. */
|
||||
turns: TurnLog<PromptResult>
|
||||
/** The command set last sent to the client, to send it again only when it changed. */
|
||||
@@ -195,6 +198,37 @@ export interface Session {
|
||||
scheduled?: ScheduledTurn
|
||||
}
|
||||
|
||||
/** Whether a turn runs in the session now, whoever started it: a prompt of the client's, or the
|
||||
* harness's own (a note waking it). What status, steer, compact, rewind and letting go ask. */
|
||||
export const working = (s: Session): boolean => s.prompting || s.own !== undefined
|
||||
|
||||
/** A `task` event of a turn no prompt of the client's began — the harness's own. It is kept in the
|
||||
* session's turn log as a terminal's turns are (running, then the last one finished, with no
|
||||
* answer of this side's), and it holds the queue: a prompt that arrives meanwhile runs after it,
|
||||
* never beside it. True for such a turn's events. */
|
||||
function ownTurn(s: Session, e: Event): boolean {
|
||||
if (e.type !== "task" || !e.turnId) return false
|
||||
if (e.state === "start") {
|
||||
// While a prompt of the client's runs, every turn is that prompt's.
|
||||
if (s.prompting) return false
|
||||
let end!: () => void
|
||||
const over = new Promise<void>((r) => (end = r))
|
||||
s.own = { turnId: e.turnId, end }
|
||||
s.turns.started(e.turnId)
|
||||
const tail = (s.queue ?? Promise.resolve()).then(() => over)
|
||||
s.queue = tail
|
||||
void tail.then(() => {
|
||||
if (s.queue === tail) s.queue = undefined
|
||||
})
|
||||
return true
|
||||
}
|
||||
if (s.own?.turnId !== e.turnId) return false
|
||||
s.turns.ended(e.turnId)
|
||||
s.own.end()
|
||||
s.own = undefined
|
||||
return true
|
||||
}
|
||||
|
||||
/** What `session/prompt` answers. */
|
||||
export type PromptResult = { stopReason: string; _meta?: { lembas: Record<string, unknown> } }
|
||||
|
||||
@@ -300,6 +334,10 @@ export const CAPABILITIES = [
|
||||
// Harness spec 3.9.0: `model` on a Dir of `_lembas/directories` — the model last used in
|
||||
// exactly that directory — and `list: false`, the directory alone.
|
||||
"directory_model",
|
||||
// Harness spec 3.10.0 (acp.md, *A turn the harness starts*): a turn a note starts by itself is a
|
||||
// turn in `status`, takes a steer, makes a prompt wait, hands back `unsent` on its `task` end
|
||||
// and is in `history` with `machine`.
|
||||
"harness_turns",
|
||||
] as const
|
||||
export const STOP: Record<string, string> = { stop: "end_turn", steps: "max_turn_requests", budget: "max_tokens", cancelled: "cancelled", error: "end_turn" }
|
||||
|
||||
@@ -415,7 +453,7 @@ const ATTACHMENT = { test: (t: string) => /^<(file|directory|shell|image) /.test
|
||||
* not text. */
|
||||
export function historyTurns(messages: Message[], cwd = "") {
|
||||
type Tool = { id: string; name: string; args: string; output?: string; isError?: boolean }
|
||||
type Turn = { role: "user"; text: string; turnId?: string; attachments?: ReturnType<typeof storedAttachments> } | { role: "assistant"; text: string; reasoning: string; tools: Tool[] }
|
||||
type Turn = { role: "user"; text: string; turnId?: string; attachments?: ReturnType<typeof storedAttachments>; machine?: true } | { role: "assistant"; text: string; reasoning: string; tools: Tool[] }
|
||||
const turns: Turn[] = []
|
||||
let reply: Extract<Turn, { role: "assistant" }> | undefined
|
||||
const calls = new Map<string, Tool>()
|
||||
@@ -425,7 +463,8 @@ export function historyTurns(messages: Message[], cwd = "") {
|
||||
const texts = m.parts.map((p) => (p.type === "text" ? p.text : ""))
|
||||
const text = texts.filter((t) => !ATTACHMENT.test(t)).join("\n").trim()
|
||||
const attachments = storedAttachments(texts, cwd)
|
||||
if (text || attachments.length) turns.push({ role: "user", text, ...(m.turnId ? { turnId: m.turnId } : {}), ...(attachments.length ? { attachments } : {}) })
|
||||
// A turn the harness started (a note, with its mark) is in the history as what it is.
|
||||
if (text || attachments.length) turns.push({ role: "user", text, ...(m.turnId ? { turnId: m.turnId } : {}), ...(attachments.length ? { attachments } : {}), ...(m.machine ? { machine: true as const } : {}) })
|
||||
continue
|
||||
}
|
||||
if (!reply) {
|
||||
@@ -827,8 +866,9 @@ export class AcpAgent {
|
||||
s.agent = this
|
||||
this.equipShow(s)
|
||||
s.off = s.app.bus.on((e) => {
|
||||
const own = ownTurn(s, e)
|
||||
if (s.agent !== this) return
|
||||
this.forward(s, e)
|
||||
this.forward(s, e, own)
|
||||
// A turn can change the set (skill_manage made a skill, a command file was written).
|
||||
if (e.type === "task" && e.state === "end") this.sendCommands(s)
|
||||
})
|
||||
@@ -975,18 +1015,18 @@ export class AcpAgent {
|
||||
/** Whether a session runs here, and whether it is working (the hub, before a terminal opens it). */
|
||||
holding(id: string): "busy" | "idle" | undefined {
|
||||
const s = this.sessions.get(id)
|
||||
return s ? (s.prompting ? "busy" : "idle") : undefined
|
||||
return s ? (working(s) ? "busy" : "idle") : undefined
|
||||
}
|
||||
|
||||
/** Whether any session this link runs is working, or has prompts waiting. */
|
||||
anyBusy(): boolean {
|
||||
return [...this.sessions.values()].some((s) => s.prompting || s.queue)
|
||||
return [...this.sessions.values()].some((s) => working(s) || s.queue)
|
||||
}
|
||||
|
||||
/** Let go of an idle session: a terminal carries it on from the store. */
|
||||
drop(id: string) {
|
||||
const s = this.sessions.get(id)
|
||||
if (!s || s.prompting) return
|
||||
if (!s || working(s)) return
|
||||
this.sessions.delete(id)
|
||||
void s.app.close()
|
||||
}
|
||||
@@ -1259,7 +1299,8 @@ export class AcpAgent {
|
||||
sessionId: id,
|
||||
exists: true,
|
||||
held: "here",
|
||||
busy: s.prompting,
|
||||
// Every turn that runs, whoever started it: a wake turn is named like any other.
|
||||
busy: working(s),
|
||||
title: (this.store ??= new Store()).session(id)?.title ?? "",
|
||||
...(s.turns.running ? { turnId: s.turns.running } : {}),
|
||||
queued: s.turns.queued(),
|
||||
@@ -1346,7 +1387,7 @@ export class AcpAgent {
|
||||
const t = this.terminalFor(p)
|
||||
if (t) return t.client.request("hub/rewind", { sessionId: t.sessionId, turnId }, 15_000)
|
||||
const s = this.get(p)
|
||||
if (s.prompting || s.turns.queued().length) throw new RpcError(INVALID_PARAMS, "this session is working — rewind it when the reply is done")
|
||||
if (working(s) || s.turns.queued().length) throw new RpcError(INVALID_PARAMS, "this session is working — rewind it when the reply is done")
|
||||
const reverted = s.app.turns.rewind(turnId)
|
||||
if (reverted === undefined) throw new RpcError(INVALID_PARAMS, `this session has no turn ${turnId}`)
|
||||
s.turns.forget(reverted)
|
||||
@@ -1385,7 +1426,7 @@ export class AcpAgent {
|
||||
const t = this.terminalFor(p)
|
||||
if (t) return t.client.request("hub/compact", { sessionId: t.sessionId }, 600_000)
|
||||
const s = this.get(p)
|
||||
if (s.prompting) throw new RpcError(INVALID_PARAMS, "this session is working — compact it when the reply is done")
|
||||
if (working(s)) throw new RpcError(INVALID_PARAMS, "this session is working — compact it when the reply is done")
|
||||
try {
|
||||
return { summary: await s.app.engine.compact() }
|
||||
} catch (e) {
|
||||
@@ -1416,7 +1457,9 @@ export class AcpAgent {
|
||||
const t = this.terminalFor(p)
|
||||
if (t) return t.client.request("hub/steer", { sessionId: t.sessionId, text, messageId: id }, 15_000)
|
||||
const s = this.get(p)
|
||||
if (!s.prompting) throw new RpcError(INVALID_PARAMS, "this session is not working on anything; send it as a prompt")
|
||||
// Any turn that runs takes it in, the harness's own included: a message typed while the model
|
||||
// answers a subagent's report joins that turn.
|
||||
if (!working(s)) throw new RpcError(INVALID_PARAMS, "this session is not working on anything; send it as a prompt")
|
||||
s.app.engine.enqueue(text, id)
|
||||
return { queued: s.app.engine.queued }
|
||||
}
|
||||
@@ -1515,10 +1558,17 @@ export class AcpAgent {
|
||||
this.peer.notify("session/update", { sessionId: s.id, update })
|
||||
}
|
||||
|
||||
private forward(s: Session, e: Event) {
|
||||
private forward(s: Session, e: Event, own = false) {
|
||||
// A model change says whether the model is this link's instance's: its ref is the
|
||||
// provider's now (`deepseek/x`), so the ref alone no longer tells.
|
||||
const event = e.type === "model" ? { ...e, instance: this.isInstance(e.connection) } : e.type === "team" ? { ...e, tree: treeOf(s.app) } : e
|
||||
let event: Event | Record<string, unknown> = e.type === "model" ? { ...e, instance: this.isInstance(e.connection) } : e.type === "team" ? { ...e, tree: treeOf(s.app) } : e
|
||||
// The end of a turn the harness started has no prompt's answer to carry what was steered into
|
||||
// it too late: it goes back on the event (`unsent`, as in a prompt's answer) — to a client
|
||||
// that hears events; otherwise it stays for the next turn's first step.
|
||||
if (own && e.type === "task" && e.state === "end" && this.lembas && !this.peer.isClosed) {
|
||||
const unsent = s.app.engine.takeInbox()
|
||||
if (unsent.length) event = { ...e, unsent }
|
||||
}
|
||||
if (this.lembas) this.peer.notify("_lembas/event", { sessionId: s.id, event })
|
||||
switch (e.type) {
|
||||
case "text":
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ export class Hub {
|
||||
|
||||
/** Whether anything works here now: a session the link runs, or one a terminal shares mid-turn. */
|
||||
busy(): boolean {
|
||||
return [...this.held.values()].some((s) => s.prompting || s.queue) || [...this.shared.values()].some((s) => s.busy)
|
||||
return [...this.held.values()].some((s) => s.prompting || s.own || s.queue) || [...this.shared.values()].some((s) => s.busy)
|
||||
}
|
||||
|
||||
private announce(s: Shared) {
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
// A turn the harness starts by itself (harness/acp.md, *A turn the harness starts*; spec 3.10.0):
|
||||
// a finished job's note waking an idle session. Over the link it is a turn like any other — status
|
||||
// says busy and names it, a message steered joins it, Stop stops it, a prompt waits for it, the
|
||||
// history keeps it marked `machine` — and two of them never overlap.
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { mkdirSync, mkdtempSync, realpathSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { AcpAgent } from "../src/acp/agent.ts"
|
||||
import { Peer, RpcError, type Transport } from "../src/acp/rpc.ts"
|
||||
import { paths } from "../src/config/paths.ts"
|
||||
import { MARKS } from "../src/jobs/note.ts"
|
||||
import { setTrust } from "../src/project/root.ts"
|
||||
import { delta, fakeProvider, toolCall, type Fake, type Scripted } from "./fake-provider.ts"
|
||||
|
||||
let fake: Fake | undefined
|
||||
afterEach(() => fake?.stop())
|
||||
|
||||
function pair(): [Transport, Transport] {
|
||||
const make = () => ({ msg: (_: string) => {}, end: () => {} })
|
||||
const a = make()
|
||||
const b = make()
|
||||
const side = (me: typeof a, o: typeof a): Transport => ({
|
||||
send: (t) => queueMicrotask(() => o.msg(t)),
|
||||
onMessage: (fn) => (me.msg = fn),
|
||||
onClose: (fn) => (me.end = fn),
|
||||
close: () => (me.end(), o.end()),
|
||||
})
|
||||
return [side(a, b), side(b, a)]
|
||||
}
|
||||
|
||||
async function client(script: Scripted[]) {
|
||||
fake = fakeProvider(script)
|
||||
mkdirSync(paths.config, { recursive: true })
|
||||
writeFileSync(join(paths.config, "connections.yaml"), `connections:\n f:\n type: webui\n url: ${fake.url}\n models: { f/m: {} }\n`, { mode: 0o600 })
|
||||
writeFileSync(join(paths.config, "config.yaml"), "model: f/m\nmode: auto\n")
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), "ph-acp-wake-")))
|
||||
setTrust(dir, "trusted")
|
||||
const [ta, tb] = pair()
|
||||
new AcpAgent(new Peer(ta))
|
||||
const c = new Peer(tb)
|
||||
const events: any[] = []
|
||||
c.on("_lembas/event", (p) => void events.push(p.event))
|
||||
c.handle("session/request_permission", () => ({ outcome: { outcome: "selected", optionId: "once" } }))
|
||||
const init: any = await c.request("initialize", { protocolVersion: 1, clientCapabilities: { _meta: { lembas: { protocol: 3 } } } })
|
||||
const s: any = await c.request("session/new", { cwd: dir, mcpServers: [] })
|
||||
const sid = s.sessionId as string
|
||||
const status = () => c.request<any>("_lembas/session/status", { sessionId: sid })
|
||||
const machine = () => events.filter((e) => e.type === "prompt" && e.machine === true)
|
||||
const ended = (turnId: string) => events.some((e) => e.type === "task" && e.state === "end" && e.turnId === turnId)
|
||||
const release = (flag: string) => writeFileSync(join(dir, flag), "")
|
||||
return { c, events, sid, init, status, machine, ended, release }
|
||||
}
|
||||
|
||||
const SLOW = 20_000
|
||||
const until = async (ok: () => boolean, ms = 8000) => {
|
||||
const end = Date.now() + ms
|
||||
while (Date.now() < end && !ok()) await Bun.sleep(20)
|
||||
return ok()
|
||||
}
|
||||
const said = (p: Promise<unknown>) => p.then(() => undefined, (e) => (e instanceof RpcError ? `${e.code} ${e.message}` : String(e)))
|
||||
const go = (c: Peer, sid: string, text = "go", turnId?: string) =>
|
||||
c.request<any>("session/prompt", { sessionId: sid, prompt: [{ type: "text", text }], ...(turnId ? { _meta: { lembas: { turnId } } } : {}) })
|
||||
|
||||
/** Background commands, each ending when the test lets it (`release`) — so never before the turn
|
||||
* that started it has ended, however slow the machine — and the reply to having started them. */
|
||||
const waitFor = (flag: string) => `until [ -e ${flag} ]; do sleep 0.05; done`
|
||||
const background = (...flags: string[]): Scripted[] => [
|
||||
{ chunks: flags.map((flag, i) => toolCall(i, `t${i + 1}`, "bash", JSON.stringify({ command: waitFor(flag), background: true, description: `wait for ${flag}` }))) },
|
||||
{ chunks: [delta({ content: "Started." })] },
|
||||
]
|
||||
/** A reply that stays open for `ms` after its first words: time to look at the turn while it runs. */
|
||||
const slow = (text: string, ms = 2500): Scripted => ({ chunks: [delta({ content: "… " }), delta({ content: text })], gapMs: ms })
|
||||
|
||||
/** The turns in the order their events came: `start <id>`, `prompt <id>`, `text <words>`, `end <id>`,
|
||||
* with each turn's id replaced by its number. */
|
||||
function order(events: any[]) {
|
||||
const n = new Map<string, number>()
|
||||
const of = (id: string) => n.get(id) ?? (n.set(id, n.size + 1), n.size)
|
||||
const out: string[] = []
|
||||
for (const e of events) {
|
||||
if (e.type === "task") out.push(`${e.state} ${of(e.turnId)}`)
|
||||
else if (e.type === "prompt") out.push(`prompt ${of(e.turnId)}${e.machine ? " machine" : ""}`)
|
||||
else if (e.type === "text" && e.text.trim() && e.text !== "… ") out.push(`text ${e.text}`)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
test("status during a wake turn: busy, and the turn named — an id of its own, the one its prompt and task events carry", async () => {
|
||||
const { c, events, sid, status, machine, ended, release } = await client([...background("f1"), slow("Seen the end.")])
|
||||
const first = await go(c, sid, "go", "web-1")
|
||||
release("f1")
|
||||
expect(await until(() => machine().length === 1)).toBe(true)
|
||||
const m = machine()[0]
|
||||
expect(typeof m.turnId).toBe("string")
|
||||
expect(m.turnId).not.toBe("web-1")
|
||||
expect(first._meta.lembas.turnId).toBe("web-1")
|
||||
// Its `task` start came before its prompt, with the same id.
|
||||
const at = events.indexOf(m)
|
||||
expect(events.slice(0, at).findLast((e) => e.type === "task")).toEqual({ type: "task", state: "start", turnId: m.turnId })
|
||||
const during = await status()
|
||||
expect(during).toMatchObject({ held: "here", busy: true, turnId: m.turnId, queued: [], lastTurnId: "web-1" })
|
||||
expect(await until(() => ended(m.turnId))).toBe(true)
|
||||
const after = await status()
|
||||
expect(after.busy).toBe(false)
|
||||
expect(after.turnId).toBeUndefined()
|
||||
expect(after.lastTurnId).toBe(m.turnId)
|
||||
}, SLOW)
|
||||
|
||||
test("initialize lists the harness_turns capability", async () => {
|
||||
const { init } = await client([])
|
||||
expect(init._meta.lembas.capabilities).toContain("harness_turns")
|
||||
}, SLOW)
|
||||
|
||||
test("the history keeps a wake turn: its note as a user turn marked machine, with the turn's id, and the reply after it", async () => {
|
||||
const { c, sid, machine, ended, release } = await client([...background("f1"), { chunks: [delta({ content: "Seen the end." })] }])
|
||||
await go(c, sid, "go", "web-1")
|
||||
release("f1")
|
||||
expect(await until(() => machine().length === 1 && ended(machine()[0].turnId))).toBe(true)
|
||||
const h: any = await c.request("_lembas/session/history", { sessionId: sid })
|
||||
expect(h.turns.map((t: any) => t.role)).toEqual(["user", "assistant", "user", "assistant"])
|
||||
expect(h.turns[0]).toEqual({ role: "user", text: "go", turnId: "web-1" })
|
||||
expect(h.turns[0].machine).toBeUndefined()
|
||||
const note = h.turns[2]
|
||||
expect(note.machine).toBe(true)
|
||||
expect(note.turnId).toBe(machine()[0].turnId)
|
||||
expect(note.text).toStartWith(`${MARKS.command}\njob1 (${waitFor("f1")}) exited with 0`)
|
||||
expect(h.turns[3].text).toBe("Seen the end.")
|
||||
// The note is never a prompt: its id sent back as one runs nothing, and answers with no answer.
|
||||
const asked = fake!.requests.length
|
||||
expect((await c.request("session/prompt", { sessionId: sid, prompt: [{ type: "text", text: note.text }], _meta: { lembas: { turnId: note.turnId } } })) ?? null).toBeNull()
|
||||
expect(fake!.requests).toHaveLength(asked)
|
||||
expect(machine()).toHaveLength(1)
|
||||
}, SLOW)
|
||||
|
||||
test("a message steered during a wake turn joins it", async () => {
|
||||
const { c, events, sid, machine, ended, release } = await client([...background("f1"), slow("Seen the end."), { chunks: [delta({ content: "And hello." })] }])
|
||||
await go(c, sid)
|
||||
release("f1")
|
||||
expect(await until(() => machine().length === 1)).toBe(true)
|
||||
const m = machine()[0]
|
||||
expect(await c.request<any>("_lembas/steer", { sessionId: sid, text: "and say hello", messageId: "web-2" })).toEqual({ queued: 1 })
|
||||
expect(await until(() => ended(m.turnId))).toBe(true)
|
||||
// Taken in at the turn's next step, inside the turn: before its end, and no turn of its own.
|
||||
const steered = events.findIndex((e) => e.type === "steered")
|
||||
expect(events[steered]).toMatchObject({ texts: ["and say hello"], ids: ["web-2"] })
|
||||
expect(steered).toBeLessThan(events.findIndex((e) => e.type === "task" && e.state === "end" && e.turnId === m.turnId))
|
||||
expect(fake!.requests).toHaveLength(4)
|
||||
expect(String(fake!.requests[3].messages.at(-1).content)).toContain("and say hello")
|
||||
expect(order(events).filter((l) => l.startsWith("prompt"))).toEqual(["prompt 1", "prompt 2 machine"])
|
||||
// The turn's end hands nothing back: the message was taken in.
|
||||
expect(events.find((e) => e.type === "task" && e.state === "end" && e.turnId === m.turnId).unsent).toBeUndefined()
|
||||
}, SLOW)
|
||||
|
||||
test("Stop stops a wake turn; a message it had not taken in comes back on the turn's end", async () => {
|
||||
const { c, events, sid, status, machine, ended, release } = await client([...background("f1"), slow("Never finished.", 5000)])
|
||||
await go(c, sid)
|
||||
release("f1")
|
||||
expect(await until(() => machine().length === 1)).toBe(true)
|
||||
const m = machine()[0]
|
||||
await c.request("_lembas/steer", { sessionId: sid, text: "one more thing" })
|
||||
c.notify("session/cancel", { sessionId: sid })
|
||||
expect(await until(() => ended(m.turnId), 3000)).toBe(true)
|
||||
expect(events.some((e) => e.type === "done" && e.reason === "cancelled")).toBe(true)
|
||||
expect(events.find((e) => e.type === "task" && e.state === "end" && e.turnId === m.turnId)).toEqual({ type: "task", state: "end", turnId: m.turnId, unsent: ["one more thing"] })
|
||||
expect((await status()).busy).toBe(false)
|
||||
// Nothing is left to steer into: said in words.
|
||||
expect(await said(c.request("_lembas/steer", { sessionId: sid, text: "anyone?" }))).toBe("-32602 this session is not working on anything; send it as a prompt")
|
||||
}, SLOW)
|
||||
|
||||
test("a prompt that arrives during a wake turn waits for it: queued in status, run after the turn's end, never beside it", async () => {
|
||||
const { c, events, sid, status, machine, ended, release } = await client([...background("f1"), slow("Seen the end."), { chunks: [delta({ content: "Second answer." })] }])
|
||||
await go(c, sid, "go", "web-1")
|
||||
release("f1")
|
||||
expect(await until(() => machine().length === 1)).toBe(true)
|
||||
const m = machine()[0]
|
||||
const second = go(c, sid, "and now this", "web-2")
|
||||
await Bun.sleep(100)
|
||||
expect(await status()).toMatchObject({ busy: true, turnId: m.turnId, queued: ["web-2"] })
|
||||
expect(ended(m.turnId)).toBe(false)
|
||||
// Neither compacted nor rewound under a turn that runs, whoever started it.
|
||||
expect(await said(c.request("_lembas/session/compact", { sessionId: sid }))).toBe("-32602 this session is working — compact it when the reply is done")
|
||||
expect(await said(c.request("_lembas/session/rewind", { sessionId: sid, turnId: "web-1" }))).toBe("-32602 this session is working — rewind it when the reply is done")
|
||||
expect(await second).toMatchObject({ stopReason: "end_turn", _meta: { lembas: { turnId: "web-2" } } })
|
||||
expect(order(events)).toEqual([
|
||||
"start 1", "prompt 1", "text Started.", "end 1",
|
||||
"start 2", "prompt 2 machine", "text Seen the end.", "end 2",
|
||||
"start 3", "prompt 3", "text Second answer.", "end 3",
|
||||
])
|
||||
expect((await status()).lastTurnId).toBe("web-2")
|
||||
}, SLOW)
|
||||
|
||||
test("two notes one after the other: two turns, each prompt followed by its own events and its own end before the next begins", async () => {
|
||||
const { c, events, sid, machine, ended, release } = await client([...background("f1", "f2"), { chunks: [delta({ content: "First seen." })] }, { chunks: [delta({ content: "Second seen." })] }])
|
||||
await go(c, sid)
|
||||
release("f1")
|
||||
expect(await until(() => machine().length === 1 && ended(machine()[0].turnId))).toBe(true)
|
||||
release("f2")
|
||||
expect(await until(() => machine().length === 2 && ended(machine()[1].turnId))).toBe(true)
|
||||
const [m1, m2] = machine()
|
||||
expect(m1.turnId).not.toBe(m2.turnId)
|
||||
expect(m1.text).toStartWith(`⏎ job1 (${waitFor("f1")})`)
|
||||
expect(m2.text).toStartWith(`⏎ job2 (${waitFor("f2")})`)
|
||||
expect(order(events)).toEqual([
|
||||
"start 1", "prompt 1", "text Started.", "end 1",
|
||||
"start 2", "prompt 2 machine", "text First seen.", "end 2",
|
||||
"start 3", "prompt 3 machine", "text Second seen.", "end 3",
|
||||
])
|
||||
// Each note is said (`job_note`) before the turn it starts.
|
||||
const notes = events.filter((e) => e.type === "job_note")
|
||||
expect(notes.map((n) => n.jobId)).toEqual(["job1", "job2"])
|
||||
expect(events.indexOf(notes[1])).toBeGreaterThan(events.findIndex((e) => e.type === "task" && e.state === "end" && e.turnId === m1.turnId))
|
||||
expect(events.indexOf(notes[1])).toBeLessThan(events.findIndex((e) => e.type === "task" && e.state === "start" && e.turnId === m2.turnId))
|
||||
const h: any = await c.request("_lembas/session/history", { sessionId: sid })
|
||||
expect(h.turns.filter((t: any) => t.machine).map((t: any) => t.turnId)).toEqual([m1.turnId, m2.turnId])
|
||||
}, SLOW)
|
||||
|
||||
test("a second note that arrives while the first one's turn runs joins that turn: one prompt, one end", async () => {
|
||||
const { c, events, sid, machine, release } = await client([...background("f1", "f2"), slow("First seen.", 3000), { chunks: [delta({ content: "Both seen." })] }])
|
||||
await go(c, sid)
|
||||
release("f1")
|
||||
expect(await until(() => machine().length === 1)).toBe(true)
|
||||
release("f2")
|
||||
expect(await until(() => fake!.requests.length === 4 && events.filter((e) => e.type === "task" && e.state === "end").length === 2)).toBe(true)
|
||||
await Bun.sleep(200)
|
||||
expect(machine()).toHaveLength(1)
|
||||
expect(order(events)).toEqual(["start 1", "prompt 1", "text Started.", "end 1", "start 2", "prompt 2 machine", "text First seen.", "text Both seen.", "end 2"])
|
||||
expect(events.filter((e) => e.type === "job_note").map((n) => n.jobId)).toEqual(["job1", "job2"])
|
||||
// The second note went to the model inside the turn, under its mark.
|
||||
expect(String(fake!.requests[3].messages.at(-1).content)).toStartWith(`${MARKS.command}\njob2 `)
|
||||
}, SLOW)
|
||||
+1
-1
@@ -275,7 +275,7 @@ test("the terminal: a real shell through the link, only where remote.terminal sa
|
||||
config(fake.url)
|
||||
const root = project()
|
||||
const off = await client({ roots: [root], maxMode: "edit", approvalTimeoutMs: 50, requireTrust: true })
|
||||
expect(off.init._meta.lembas.capabilities).toEqual(["directories", "configure", "steer", "sessions", "status", "delete", "compact", "title", "files", "commands", "attachments", "ask", "plan", "model", "turns", "context", "library", "plan_state", "rewind", "jobs", "show", "progress", "tree", "agents", "scheduled", "reports", "directory_model"])
|
||||
expect(off.init._meta.lembas.capabilities).toEqual(["directories", "configure", "steer", "sessions", "status", "delete", "compact", "title", "files", "commands", "attachments", "ask", "plan", "model", "turns", "context", "library", "plan_state", "rewind", "jobs", "show", "progress", "tree", "agents", "scheduled", "reports", "directory_model", "harness_turns"])
|
||||
await expect(off.c.request("_lembas/terminal/open", { cwd: root })).rejects.toThrow("lembas remote terminal on")
|
||||
|
||||
const { c, init } = await client({ roots: [root], maxMode: "edit", approvalTimeoutMs: 50, requireTrust: true, terminal: true })
|
||||
|
||||
Reference in new issue
Block a user