diff --git a/harness/README.md b/harness/README.md
index 5a0a741..38e415e 100644
--- a/harness/README.md
+++ b/harness/README.md
@@ -36,7 +36,7 @@ page *Harness-parity* in LLeMbas CLI's wiki.
| `display.md` | Display (3.7.0): one display in every client — a tool call's title, its four states, the duration and the facts beside it, the kinds of block; how `stopped` and `failed` stay on a finished reply; what the approval, question and plan cards offer; numbers in the client's locale |
| `quirks.json` | What real servers do, and how both harnesses cope |
| `conformance/.json` | Cases with their expected results, run by both test suites |
-| `acp.md` | The link between them: ACP plus every `_lembas/*` method, field and capability; scheduled work on a linked computer (3.5.0) and the two types of schedule, Chat and Agentic (3.9.0); the model last used in a directory (3.9.0) |
+| `acp.md` | The link between them: ACP plus every `_lembas/*` method, field and capability; scheduled work on a linked computer (3.5.0) and the two types of schedule, Chat and Agentic (3.9.0); the model last used in a directory (3.9.0); a turn the harness starts by itself, over the link (3.10.0) |
## Vocabulary
@@ -79,6 +79,34 @@ page *Harness-parity* in LLeMbas CLI's wiki.
approval in plan mode and answers its `unavailable` text outside it. Their permission key is
`plan` (`permission/defaults.json`), which a rule written for the former `todo` key still reaches.
+## 3.10.0
+
+Written with the CLI's implementation, after a turn the harness started was found to be half a turn
+over the link. A new capability and two fields; one prompt text made plainer; no tool.
+
+- **A turn the harness starts is a turn like any other over the link** (`acp.md`, section of that
+ name; capability `harness_turns`; `conformance/reattach.json`, 9 cases). A note that wakes an idle
+ session — a finished job's, a subagent's or a team's report — already had an id of its own on
+ its `task` and `prompt` events. What is new is everything a client asks *about* it:
+ `_lembas/session/status` says `busy` and names it (`turnId`, then `lastTurnId`, kept across a
+ restart); `_lembas/steer` is accepted while it runs, and a message it ended before taking in
+ comes back as **`unsent` on its `task` end event** (it has no prompt's answer to carry it);
+ `session/cancel` stops it; a `session/prompt` that arrives meanwhile **waits its turn** and is
+ listed in `queued`; compacting and rewinding are refused while it runs; the link is not closed
+ under it. **`_lembas/session/history` marks its user turn `machine`**, with its `turnId` and the
+ whole note as `text`. Written down as well: the order of such a turn's events, that turns never
+ overlap, and what two notes in a row are (one turn with both, or two turns one after the other).
+- **The client's side**: the row of such a turn is never sent to the device as a prompt — not on
+ seeing it, and not on reattaching when the device no longer knows its id; then what the history
+ has for that id is imported. `conformance/reattach.json` is that decision, for a person's turn
+ and for the harness's.
+- **Clarified, not changed**: on a `machine` turn's `prompt` event, `text` is the line a transcript
+ shows (`⏎ ` and the note's first line), not the whole note.
+- **`blocks/team_lead.md`**, one bullet more: the main agent does not wait for a report or ask for
+ one; a report starts its next turn by itself, and when the reports it needs are in it answers the
+ person in that turn, unasked, and never tells the person to ask again. A session keeps the system
+ prompt it was started with (`context.md` §10), so only sessions started after the change read it.
+
## 3.9.0
Written ahead of the implementations; the CLI carries it in the same round. A new capability and
diff --git a/harness/VERSION b/harness/VERSION
index a5c4c76..30291cb 100644
--- a/harness/VERSION
+++ b/harness/VERSION
@@ -1 +1 @@
-3.9.0
+3.10.0
diff --git a/harness/acp.md b/harness/acp.md
index a741abe..6a18c51 100644
--- a/harness/acp.md
+++ b/harness/acp.md
@@ -69,6 +69,7 @@ change to the protocol is a change here first, then in both projects.
| `tree` | spec 3.4.0 (`subagents.md` §5–§13): the `team` event; `_lembas/team`, `_lembas/team/transcript`, `_lembas/team/findings`, `_lembas/team/stop`; `subagent` on `session/request_permission` |
| `scheduled` | spec 3.5.0 (*Scheduled work on a linked computer*, below): `scheduled` in `_meta.lembas` of `session/new` and `session/prompt` read, and the run's outcome in the prompt's answer; `scheduled` on `session/request_permission`; `_lembas/monitor`; `limits.scheduled` in `_lembas/hello` and `initialize`. Listed by every build that has it, whatever the setting says: whether this device *accepts* scheduled work is `limits.scheduled` |
| `directory_model` | spec 3.9.0 (*The model last used in a directory*, below): `model` on a `Dir` of `_lembas/directories`' answer; `list: false` in its params |
+| `harness_turns` | spec 3.10.0 (*A turn the harness starts*, below): such a turn is a turn in `_lembas/session/status` (`busy`, `turnId`, then `lastTurnId`), takes `_lembas/steer`, hands back `unsent` on its `task` end, makes a prompt wait, and is in `_lembas/session/history` as a user turn with `machine` |
| `reports` | spec 3.8.0 (`reports.md` §6): `scheduled.notify` in `_meta.lembas` of `session/new` and `session/prompt` read; `report_write` offered to the model of a schedule's run that notifies; the report the run wrote carried in the prompt's answer (`scheduled.report`); the status `silent` no longer given to a turn whose request said `notify` |
## Standard ACP, as used here
@@ -196,7 +197,8 @@ message id). The device keeps, per session, the last 200 ids it accepted with th
and every terminal use alike, so they outlive a restart and a session moving between a terminal and
the service in either direction; files untouched for 30 days are pruned — and **a prompt with a known turnId does not run again**: it gets the
original's answer — when that one is done, or at once if it is. Without a `turnId` the device makes
-one. A prompt that arrives while the session works waits its turn.
+one. A prompt that arrives while the session works waits its turn — behind a turn the harness
+started as behind any other (*A turn the harness starts*).
Result: `{ stopReason: "end_turn" | "max_turn_requests" | "max_tokens" | "cancelled", _meta: { lembas: { turnId, … } } }`,
where `_meta.lembas` may also carry:
@@ -216,7 +218,8 @@ Params: `{ sessionId, modeId }`, lowered to `remote.max_mode`. Result `{}`.
### `session/cancel` — client → agent (notification)
-Params: `{ sessionId }`. Stops the running turn.
+Params: `{ sessionId }`. Stops the running turn, whoever started it: the client's prompt, a turn
+typed in a terminal, or one the harness started. Prompts waiting behind it still run.
### `session/update` — agent → client (notification)
@@ -609,6 +612,60 @@ for a schedule's run on a device (*Scheduled work*, *The run's model*).
(`kind: client` — the model a chat or a run starts on, from what was named, what the directory
says, the models the person has and the default.)
+## A turn the harness starts (spec 3.10.0)
+
+Capability `harness_turns`. A note that reaches an idle session — a finished job's, a subagent's
+report or message, a team's report or message — **wakes** it: the harness starts a turn by itself,
+with the note as its user message (`loop.json` `jobs`, `team.md` §7). Nobody typed it and no
+`session/prompt` began it. **Over the link it is a turn like any other**:
+
+- **Its id.** The device makes one for it — a new one for every such turn, the same from its start
+ to its end — and says it on the turn's `task` start, on its `prompt` event (with `machine: true`)
+ and on its `task` end. A client tells two harness turns in a row apart by it.
+- **Its events, in order.** `task` start, `prompt`, the turn's own events (steps, text, tool calls),
+ `task` end. A job's note is said first, as `job_note`, before the `task` start of the turn it
+ starts. **Turns never overlap**: no event of the next turn — its `task` start included — comes
+ before this one's `task` end, whoever started either.
+- **Two notes in a row.** A note that arrives while any turn runs — the first note's turn included —
+ starts no turn: it goes to the model at that turn's next step (a `job_note` says so, where it is
+ a job's) and the turn carries on with it, even past what would have been its last step. A note
+ that arrives after the turn's end starts the next turn. So two subagents finishing one after the
+ other are one turn with both notes or two turns one after the other, by when the second finished;
+ never two at once.
+- **Status** (`_lembas/session/status`): `busy: true` and `turnId` its id while it runs;
+ `lastTurnId` its id once it has ended, kept across a restart as any finished turn is.
+- **Steer** (`_lembas/steer`): accepted while it runs, taken in at its next step, said with
+ `steered`. A message it ended before taking in comes back as `unsent` on its `task` end event —
+ it has no prompt's answer to carry it — and the client sends it next, as it does a prompt's
+ `unsent`. With no client listening the message stays, and goes in at the next turn's first step;
+ so it does in a session a terminal runs, where it stays in the terminal's own queue.
+- **Stop** (`session/cancel`): stops it. Notes it had not given the model yet start no further turn:
+ they go in with the person's next message.
+- **A prompt** (`session/prompt`) that arrives while it runs waits its turn — it is in `queued` —
+ and runs after the turn's `task` end. A prompt carrying the harness turn's own id does not run:
+ the id is known, and the answer is `null` (the turn has none of this side's).
+- **Compacting and rewinding** (`_lembas/session/compact`, `_lembas/session/rewind`) are refused
+ while it runs, as during any turn. Once it has ended it is rewound by its id like any turn.
+- **History** (`_lembas/session/history`): its user turn is there, with its `turnId`, `machine: true`
+ and the whole note as `text`; the reply follows it.
+- **The link** is not closed for a change of limits while one runs (*`_lembas/hello`*: "once no
+ session is working").
+- **Scheduled sessions.** A turn a schedule's job wakes is the schedule's work: it does not run on
+ an interactive-only model (`interactive.md`), and the device says so in a `notice` instead.
+
+**The client's side.** The row it keeps for such a turn is the harness's (`machine`), keyed by the
+turn's id; the reply after it is filled from the events between that id's `prompt` and its `task`
+end, and from nowhere else. The client **never sends the row to the device as a prompt** — not
+when it first sees it, and not when it reattaches and the device does not know the id any more (a
+device restarted in the middle of the turn): then it imports what `history` has after the user turn
+with that id, and closes the reply as it stands. `conformance/reattach.json` gives the decision for
+a row with turn T from what `status` says.
+
+A device without `harness_turns` (before 3.10.0) runs these turns the same way and says `prompt`
+with `machine` and both `task` events with the id, but its `status` says `busy: false` and names no
+turn while one runs, it refuses a steer then, and a prompt sent then fails (`-32603`); a client
+follows such a turn by its `task` events alone and sends nothing to the session until its end.
+
## `_lembas/*` methods
Direction is who sends it. "→ result" marks a request; the others are notifications.
@@ -641,8 +698,8 @@ client hears the new limits.
| Event | Fields |
|---|---|
-| `prompt` | `text` (as the person sees it: a command's name, not its body), `turnId`, `attachments?: [{ name, mimeType, size }]`, `machine?: true` (capability `jobs`) — the turn was started by the harness, not typed: a finished job's or subagent's note, or a subagent's message, beginning with its mark (`loop.json` `jobs.marks`); a client shows it as such and sends it to no model of its own |
-| `task` | `state: "start" \| "end"`, `turnId` — every turn has one: the client's, or one made here for a turn typed in a terminal |
+| `prompt` | `text` (as the person sees it: a command's name, not its body), `turnId`, `attachments?: [{ name, mimeType, size }]`, `machine?: true` (capability `jobs`) — the turn was started by the harness, not typed: a finished job's or subagent's note, a subagent's message, or a team's report or message (`team.md` §7), each a note beginning with its mark (`loop.json` `jobs.marks`, `team.marks`). `text` is then the line a transcript shows for it — `⏎ ` and the note's first line: for a job's note the line after its mark, for a team's note the mark itself, which names who reports; the whole note is `text` of the `job_note` before it, where a job's, and of the turn in `history`. A client shows it as the harness's and sends it to no model of its own, and never back to the device as a prompt (*A turn the harness starts*) |
+| `task` | `state: "start" \| "end"`, `turnId` — every turn has one: the client's, or one made here for a turn typed in a terminal or started by the harness. `unsent?: string[]` (capability `harness_turns`) on the `end` of a turn the harness started: the `_lembas/steer` messages that turn ended before taking in, as `unsent` in a prompt's answer — send them next |
| `steered` | `texts`, `ids?` — the `_lembas/steer` message ids taken in at this step |
| `mode` | `mode` |
| `model` | `ref` (the device's ref, above), `effort` (one of the model's levels: an effort, `"off"` or `"default"`), `connection` (the device connection it is spoken to through) and **`instance: boolean`** — true exactly when that connection is the login of **this link's** instance, i.e. the model is one the instance serves (its served id is `ref`, or `ref` less a leading `/`). Whenever either changes, for any reason: `/model`, `/effort`, the settings tool, a fallback, `_lembas/configure` |
@@ -716,13 +773,17 @@ Params `{ sessionId, model?: , effort?: , agents?: { min
Params `{ sessionId, text, messageId? }`: a message for the running task, given to the model at its
next step. Result `{ queued: number }`. `-32602` when nothing runs: send it as a prompt instead.
+"Runs" is any turn — the client's prompt, a terminal's, or one the harness started (capability
+`harness_turns`; a device without it refuses a steer during a harness turn).
### `_lembas/session/history` — client → agent → result
Params `{ sessionId }`. Result `{ sessionId, title, root, turns }`, each turn
-`{ role: "user", text, turnId?, attachments?: [{ name, mimeType, size }] }` (`turnId`
-the turn the message started — the client's, or the one made for a turn typed in a terminal — kept
-with the message in the store; `attachments`, and the text without them) or `{ role: "assistant", text, reasoning, tools: [{ id, name, args, output?, isError? }] }`.
+`{ role: "user", text, turnId?, attachments?: [{ name, mimeType, size }], machine?: true }` (`turnId`
+the turn the message started — the client's, or the one made for a turn typed in a terminal or
+started by the harness — kept with the message in the store; `attachments`, and the text without
+them; `machine` (capability `harness_turns`) on a turn the harness started, whose `text` is the
+whole note, beginning with its mark) or `{ role: "assistant", text, reasoning, tools: [{ id, name, args, output?, isError? }] }`.
### `_lembas/session/status` — client → agent → result
@@ -732,7 +793,10 @@ Params `{ sessionId }`. Result
without waiting for the next change; `progress` the main agent's progress object or `null` (capability `progress`), and `tree` the subagent tree or `null` when the session has none (capability `tree`), for the same reason; `jobs` the session's background jobs, `JobInfo[]` running first (capability `jobs`), for the same reason; the turn fields with capability `turns`: the turn running now, the ones waiting, the last
one finished (for a session not open, `held: "none"`, the last one it finished before). **Reattaching** after a restart or a dropped link, for an incomplete row with turn T:
T running → follow it; T queued → wait, and follow it when it starts; T done → import it from
-`history`; T unknown → send the prompt again (safe: the device deduplicates).
+`history`; T unknown → send the prompt again (safe: the device deduplicates) — unless the row is a
+turn the harness started, which is never sent: import what `history` has for T
+(`conformance/reattach.json`). `busy` is true, and `turnId` names the turn, for **every** turn that
+runs — a harness turn included, with capability `harness_turns`.
### `_lembas/jobs` — client → agent → result (capability `jobs`)
diff --git a/harness/conformance/reattach.json b/harness/conformance/reattach.json
new file mode 100644
index 0000000..2493f83
--- /dev/null
+++ b/harness/conformance/reattach.json
@@ -0,0 +1,124 @@
+{
+ "about": "Spec 3.10.0 (acp.md, `_lembas/session/status` and *A turn the harness starts*): the client's rule for an incomplete row after a restart or a dropped link. `turn`: the row's turn id T; `machine`: the row is a turn the harness started (its `prompt` event said `machine`); `status`: what `_lembas/session/status` answered — `busy`, `turnId` (the turn running now), `queued`, `lastTurnId`. The result `do`: `follow` — T runs: take its events until its `task` end; `wait` — T is queued: follow it when it starts; `import` — read the reply after the user turn with T from `_lembas/session/history` (for a harness turn the device does not know any more: whatever is there, and nothing when nothing is); `resend` — send the prompt again with T. A harness turn is never resent: its text is a note, not a person's words. LLeMbas: services/device_link.py; CLI: acp/turns.ts reattach (the client's rule, kept there for these cases).",
+ "cases": [
+ {
+ "about": "The person's turn still runs: followed.",
+ "turn": "t7",
+ "status": {
+ "busy": true,
+ "turnId": "t7",
+ "queued": [],
+ "lastTurnId": "t6"
+ },
+ "expect": {
+ "do": "follow"
+ }
+ },
+ {
+ "about": "A harness turn still runs — status names it as it names any turn: followed.",
+ "turn": "h2",
+ "machine": true,
+ "status": {
+ "busy": true,
+ "turnId": "h2",
+ "queued": [],
+ "lastTurnId": "t7"
+ },
+ "expect": {
+ "do": "follow"
+ }
+ },
+ {
+ "about": "The person's prompt waits behind a harness turn: waited for, then followed.",
+ "turn": "t8",
+ "status": {
+ "busy": true,
+ "turnId": "h2",
+ "queued": [
+ "t8"
+ ],
+ "lastTurnId": "t7"
+ },
+ "expect": {
+ "do": "wait"
+ }
+ },
+ {
+ "about": "The person's turn was the last to finish: imported from the history.",
+ "turn": "t7",
+ "status": {
+ "busy": false,
+ "queued": [],
+ "lastTurnId": "t7"
+ },
+ "expect": {
+ "do": "import"
+ }
+ },
+ {
+ "about": "A harness turn was the last to finish: imported by its id.",
+ "turn": "h2",
+ "machine": true,
+ "status": {
+ "busy": false,
+ "queued": [],
+ "lastTurnId": "h2"
+ },
+ "expect": {
+ "do": "import"
+ }
+ },
+ {
+ "about": "The device does not know the person's turn: the prompt is sent again, and the device runs it once.",
+ "turn": "t9",
+ "status": {
+ "busy": false,
+ "queued": [],
+ "lastTurnId": "t7"
+ },
+ "expect": {
+ "do": "resend"
+ }
+ },
+ {
+ "about": "The same while a harness turn runs: sent again, and it waits its turn there.",
+ "turn": "t9",
+ "status": {
+ "busy": true,
+ "turnId": "h3",
+ "queued": [],
+ "lastTurnId": "t7"
+ },
+ "expect": {
+ "do": "resend"
+ }
+ },
+ {
+ "about": "A harness turn the device no longer knows (it restarted in the middle of it): never sent — what the history has for it is all there is.",
+ "turn": "h2",
+ "machine": true,
+ "status": {
+ "busy": false,
+ "queued": [],
+ "lastTurnId": "t7"
+ },
+ "expect": {
+ "do": "import"
+ }
+ },
+ {
+ "about": "The first of two harness turns in a row, while the second runs and a person's turn finished in between: imported, not sent, and not taken for the one that runs.",
+ "turn": "h2",
+ "machine": true,
+ "status": {
+ "busy": true,
+ "turnId": "h3",
+ "queued": [],
+ "lastTurnId": "t8"
+ },
+ "expect": {
+ "do": "import"
+ }
+ }
+ ]
+}
diff --git a/harness/prompts/blocks/team_lead.md b/harness/prompts/blocks/team_lead.md
index 634cf9e..956154e 100644
--- a/harness/prompts/blocks/team_lead.md
+++ b/harness/prompts/blocks/team_lead.md
@@ -12,3 +12,4 @@ You are the main agent of this session. You can add subagents with team_add: age
- A subagent whose context fills saves its findings and ends. Read them with team_findings, then replace it (team_replace) if its part is not done.
- Step in when a subagent is stuck, when two disagree, or when the plan has to change: decide, and tell those it concerns (team_assign for new work).
- Review every report against what you asked for — read the work itself where it matters — and send back what is not done. Then give your own answer to the person.
+- You do not wait for a report or ask for one. End your turn when you have nothing left to do but wait; each report arrives by itself, as a message marked as a team report, and starts your next turn. When the reports you need are in, answer the person in that turn, unasked — never tell the person to ask again for the result.
diff --git a/src/acp/turns.ts b/src/acp/turns.ts
index f2bc589..a096f42 100644
--- a/src/acp/turns.ts
+++ b/src/acp/turns.ts
@@ -116,6 +116,17 @@ export function sessionTurns(sessionId: string): TurnLog {
return new TurnLog(sessionTurnFile(sessionId))
}
+/** The client's rule (LLeMbas applies it; kept here so both suites answer the same cases,
+ * conformance/reattach.json): what to do with an incomplete row of turn `turn` after a restart or
+ * a dropped link, from what `_lembas/session/status` says. A turn the harness started (`machine`)
+ * is never sent to the device: what its history has for it is all there is. */
+export function reattach(o: { turn: string; machine?: boolean; status: { turnId?: string; queued?: readonly string[]; lastTurnId?: string } }): { do: "follow" | "wait" | "import" | "resend" } {
+ if (o.status.turnId === o.turn) return { do: "follow" }
+ if (o.status.queued?.includes(o.turn)) return { do: "wait" }
+ if (o.status.lastTurnId === o.turn || o.machine) return { do: "import" }
+ return { do: "resend" }
+}
+
export class TurnLog {
private entries = new Map>()
private values = new Map()
diff --git a/tests/conformance.ts b/tests/conformance.ts
index 5b3cfeb..2915766 100644
--- a/tests/conformance.ts
+++ b/tests/conformance.ts
@@ -39,6 +39,7 @@ import { fillPrompt as fillText } from "../src/prompt/fill.ts"
import { isSilent, judgeCase, monitorHash, notifyInstruction, reportResult, reportTool, runLeaves, scheduledMode, stripSentinel } from "../src/acp/scheduled.ts"
import { clientModel, records, startModel, type SessionKind } from "../src/session/lastmodel.ts"
+import { reattach } from "../src/acp/turns.ts"
import { background, scheduledRefusal, twin, type BackgroundCall, type Listed } from "../src/provider/interactive.ts"
type Case = Record
@@ -56,6 +57,8 @@ function readableUnder(grants: Record | undefined, path: string)
}
export const AREAS: Record unknown> = {
+ // Spec 3.10.0: a row reattached after a restart or a dropped link — the client's rule (src/acp/turns.ts).
+ reattach: (c) => reattach({ turn: c.turn as string, machine: c.machine === true, status: c.status as { turnId?: string; queued?: string[]; lastTurnId?: string } }),
// Spec 3.9.0: the model last used in a directory (src/session/lastmodel.ts).
last_model: (c) => {
const str = (k: string) => (typeof c[k] === "string" ? (c[k] as string) : undefined)