composer steering: the general steering machinery (owner arc 2026-10-03)

STEERING, NOT FOLLOW-UPS — pi-agent-core's two rails, used deliberately:
agent.steer() injects at the next response boundary INSIDE the live run
(one logical turn, the model changes course); followUp() would only extend
an ended run — not built. The same rail job markers already ride
(steeringMode 'all', the 2026-09-26 doctrine).

- POST /api/chats/[id]/steer: 404/400 honest guards; no live turn → 409
  and the client silently falls back to a plain text send (the settle
  race); live → steerLiveChat hands the message to the live agent's
  steering queue AND parks it in the userSteers registry — the stranding
  safety net. A steer stranded behind a question termination or abort
  stays parked and rides the chat's NEXT run (handOffEligible), the same
  deliver-or-requeue lifecycle as job markers. Reconciliation at settle:
  delivered ids drop (reconcileUserSteers).
- Client: steer(text) queues + POSTs without flipping any turn state;
  the drain's verbatim message events upsert the real user card by the
  client-minted id (steer_<localid>) and the indicator fold drops the
  line. canSend no longer gates on turnInFlight — Enter mid-turn steers;
  Enter with an empty composer still stops; the square button stays Stop.
- The queued-steer indicator (owner spec): quiet one-liners above the
  composer shell — right-aligned to where its corner rounding starts,
  truncated with an ellipsis, fixed max width, ~half opacity, no
  background, no container. Tunable later.
- Verified from pi-agent-core source: steering drains per completed turn
  inside the loop; injected messages emit message_start/end verbatim;
  finishTurn {action:'end'} (our question stopper) exits BEFORE the
  steering poll — hence the registry.
This commit is contained in:
amosblomqvist
2026-10-03 03:01:51 +03:00
parent a3a048f572
commit 5271ca0e4a
14 changed files with 489 additions and 19 deletions
+23
View File
@@ -76,6 +76,29 @@ export function parseDismissInput(input: unknown): DismissInput {
return { type: "dismiss", toolCallId: i.toolCallId, answer };
}
/** A mid-turn steer (owner arc 2026-10-03): the learner's composer message
* for a RUNNING turn — queued on pi's steering rail (agent.steer, drained
* at the next response boundary INSIDE the same run). NOT a follow-up:
* it never extends an ended run, and it never composes a turn of its own
* (a send with no live turn is a plain text send, which already exists).
* The id is client-minted (steer_<localid>): the queued indicator keys on
* it, and the drain's message events upsert the real card by the same id. */
export type UserSteerInput = { type: "steer"; id: string; text: string };
/** Parse and validate a steer event off a request body. */
export function parseUserSteerInput(input: unknown): UserSteerInput {
if (typeof input !== "object" || input === null) throw new ChatInputError("input must be an object");
const i = input as Record<string, unknown>;
if (i.type !== "steer") throw new ChatInputError(`unknown input type: ${String(i.type)}`);
if (typeof i.id !== "string" || i.id.length === 0) {
throw new ChatInputError("steer input requires a client-minted id");
}
if (typeof i.text !== "string" || i.text.trim().length === 0) {
throw new ChatInputError("steer input requires non-empty text");
}
return { type: "steer", id: i.id, text: i.text };
}
/** The native appends a dismissal makes (pure — same orphan discipline
* as answers: the call must be a DANGLING question call). */
export function dismissAppends(record: { messages: LhMessage[] }, input: DismissInput): LhMessage[] {
+9
View File
@@ -103,6 +103,15 @@ export function newUserMessage(text: string): LhMessage & UserMessage {
};
}
/** A steered user message (mid-turn composer steering, owner 2026-10-03):
* a plain user message with the CLIENT-minted steer id — the same object
* rides agent.steer(), the live stream's message events, and the settled
* record, so the optimistic queued indicator and the transcript card
* upsert by one identity. */
export function newUserSteer(text: string, id: string): LhMessage & UserMessage {
return { id, role: "user", content: text, timestamp: Date.now() };
}
/** The learner's answer — the question call's tool result (fork 1).
* TWO AUDIENCES (owner, tool-result diet 2026-10-02): the MODEL sees the
* compact learner-only record (compactAnswerForModel — the call's own