@goah/cli 0.13.2 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ import {
15
15
  renderDashboard,
16
16
  runSupervisorDaemon,
17
17
  selectRecoveryEvents
18
- } from "./chunk-QBD6EJ2Z.js";
18
+ } from "./chunk-SQJZ5OFH.js";
19
19
  import "./chunk-4KA63VNZ.js";
20
20
  import "./chunk-KAO7WIXG.js";
21
21
  import "./chunk-R6I3VKME.js";
@@ -304,6 +304,7 @@ type HandoffValidationResult = {
304
304
  token: string;
305
305
  goalId: string;
306
306
  goalRevision: number;
307
+ messageItemId: string;
307
308
  } | {
308
309
  accepted: false;
309
310
  fatal: boolean;
@@ -312,6 +313,7 @@ type HandoffValidationResult = {
312
313
  };
313
314
  interface HandoffValidationRequest {
314
315
  handoff: AgentHandoff;
316
+ candidateMessageId: string;
315
317
  candidateMessage: string;
316
318
  }
317
319
  interface TurnOutput {
@@ -418,9 +420,6 @@ interface TurnContext {
418
420
  activeGoal: GoalSnapshot | null;
419
421
  goalCommitment: GoalCommitment | null;
420
422
  }
421
- interface AssistantResponse {
422
- content: string;
423
- }
424
423
  /** Canonical user-visible assistant prose. Raw provider events remain unchanged. */
425
424
  declare function normalizeAssistantText(text: string): string;
426
425
  interface RunRequest {
@@ -436,7 +435,7 @@ interface RunRequest {
436
435
  }
437
436
  type RunnerCandidateResult = {
438
437
  outcome: "completed";
439
- response: AssistantResponse;
438
+ finalMessageId: string;
440
439
  handoff?: TurnOutput;
441
440
  } | {
442
441
  outcome: "abnormal";
@@ -514,7 +513,8 @@ interface Ledger extends EventStore {
514
513
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
515
514
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
516
515
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
517
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
516
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
517
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
518
518
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
519
519
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
520
520
  putMails(mail: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
@@ -554,4 +554,4 @@ declare function assertTurnOutput(value: TurnOutput): void;
554
554
  declare function assertGoalSnapshot(value: GoalSnapshot): void;
555
555
 
556
556
  export { assertAgentHandoff, assertGoalSnapshot, assertGoalTransition, assertHandoff, assertTurnOutput, assertWakeTransition, goalAutomaticTarget, goalCommitment, goalRoute, humanInboxRoute, humanRequestRoute, noGoalCommitment, normalizeAssistantText, specialistAutomaticTarget, specialistInboxRoute };
557
- export type { AgentCapability, AgentHandoff, AgentProfile, AgentRole, AssistantResponse, AutomaticTarget, CommittedTurnOutput, DelegationRequest, DelegationResult, GoalChangeAuthority, GoalChangeMetadata, GoalChangeOperation, GoalChangedData, GoalCommitment, GoalCompletionRequest, GoalHandoff, GoalOutcome, GoalPhase, GoalSnapshot, Handoff, HandoffCommit, HandoffValidationIssue, HandoffValidationRequest, HandoffValidationResult, HumanTurnAdmissionRequest, HumanTurnAdmissionResult, Ledger, MailLevel, MailRoute, MailSnapshot, ReassignmentRequest, ReassignmentResult, RunRequest, Runner, RunnerCandidateResult, RunnerChoice, RunnerCommandResult, RunnerConfigurator, RunnerControlMethod, RunnerDiagnostic, RunnerHandle, RunnerManifest, RunnerProfile, RunnerRpcMethod, RunnerSetupInteraction, RunnerSetupProgress, RunnerSetupTransaction, RunnerTraceEvent, ScheduleSnapshot, ScheduleStatus, SpecialistRole, TeamMemberMotion, TeamMemberView, ThreadSnapshot, TurnContext, TurnItemSnapshot, TurnItemStatus, TurnItemType, TurnOutput, TurnSnapshot, TurnStatus, TurnTrigger, TurnTriggerKind, WakeSnapshot, WakeStatus, WakeTriggerSnapshot, WakeTriggerStatus, WorkRecordDiff, WorkRecordSnapshot, WorkRecordUpdateRequest };
557
+ export type { AgentCapability, AgentHandoff, AgentProfile, AgentRole, AutomaticTarget, CommittedTurnOutput, DelegationRequest, DelegationResult, GoalChangeAuthority, GoalChangeMetadata, GoalChangeOperation, GoalChangedData, GoalCommitment, GoalCompletionRequest, GoalHandoff, GoalOutcome, GoalPhase, GoalSnapshot, Handoff, HandoffCommit, HandoffValidationIssue, HandoffValidationRequest, HandoffValidationResult, HumanTurnAdmissionRequest, HumanTurnAdmissionResult, Ledger, MailLevel, MailRoute, MailSnapshot, ReassignmentRequest, ReassignmentResult, RunRequest, Runner, RunnerCandidateResult, RunnerChoice, RunnerCommandResult, RunnerConfigurator, RunnerControlMethod, RunnerDiagnostic, RunnerHandle, RunnerManifest, RunnerProfile, RunnerRpcMethod, RunnerSetupInteraction, RunnerSetupProgress, RunnerSetupTransaction, RunnerTraceEvent, ScheduleSnapshot, ScheduleStatus, SpecialistRole, TeamMemberMotion, TeamMemberView, ThreadSnapshot, TurnContext, TurnItemSnapshot, TurnItemStatus, TurnItemType, TurnOutput, TurnSnapshot, TurnStatus, TurnTrigger, TurnTriggerKind, WakeSnapshot, WakeStatus, WakeTriggerSnapshot, WakeTriggerStatus, WorkRecordDiff, WorkRecordSnapshot, WorkRecordUpdateRequest };
@@ -2,7 +2,7 @@ import { createRequire as __goahCreateRequire } from "node:module";
2
2
  const require = __goahCreateRequire(import.meta.url);
3
3
  import {
4
4
  runProcessWorker
5
- } from "./chunk-7E7V6OIU.js";
5
+ } from "./chunk-EK6BTCFG.js";
6
6
  import "./chunk-6M3OOCKO.js";
7
7
  import "./chunk-K26BVR6O.js";
8
8
  import "./chunk-IIJQ3DW4.js";
@@ -32,6 +32,7 @@ await runProcessWorker(async (request, emit, rpc) => {
32
32
  const steps = triggerSteps ?? byAgent[request.agent] ?? JSON.parse(process.env.GOAH_FAUX_STEPS ?? "[]");
33
33
  let goalCommitment = request.turn?.goalCommitment;
34
34
  let recordUpdated = false;
35
+ let messageSequence = 0;
35
36
  for (const step of steps) {
36
37
  if (step.write) {
37
38
  const path = join(process.cwd(), step.write.path);
@@ -54,8 +55,11 @@ await runProcessWorker(async (request, emit, rpc) => {
54
55
  await new Promise((resolve) => setTimeout(resolve, step.delayMs));
55
56
  if (step.hang)
56
57
  await new Promise(() => void 0);
57
- if (step.response !== void 0)
58
- return { outcome: "completed", response: { content: step.response } };
58
+ if (step.response !== void 0) {
59
+ const finalMessageId = `faux:${request.execution.id}:attempt:${request.execution.attempt}:message:${++messageSequence}`;
60
+ emit({ type: "message.assistant.completed", data: { message: { id: finalMessageId, role: "assistant", content: [{ type: "text", text: step.response }] }, commitState: "committed" } });
61
+ return { outcome: "completed", finalMessageId };
62
+ }
59
63
  if (step.handoff) {
60
64
  const draft = step.handoff;
61
65
  if (goalCommitment && !recordUpdated) {
@@ -64,16 +68,19 @@ await runProcessWorker(async (request, emit, rpc) => {
64
68
  const evidence = sourceSeqs(request.context);
65
69
  await rpc("work_record.update", { expectedRevision: Number(record.recordRevision ?? 0), content: handoffRecord(draft.handoff, request.execution.id), reason: "record faux Goal progress", evidence: evidence.length ? [Math.max(...evidence)] : [] });
66
70
  }
67
- const validation = await rpc("goal.handoff.validate", { handoff: draft.handoff, candidateMessage: draft.response.content });
68
- emit({ type: "message.assistant.completed", data: { message: { id: `faux:${request.execution.id}:handoff:${validation.attemptId}`, role: "assistant", content: [{ type: "text", text: draft.response.content }], stopReason: "toolUse" }, commitState: "provisional" } });
71
+ const messageItemId = `faux:${request.execution.id}:attempt:${request.execution.attempt}:message:${++messageSequence}`;
72
+ const validation = await rpc("goal.handoff.validate", { handoff: draft.handoff, candidateMessageId: messageItemId, candidateMessage: draft.response.content });
73
+ emit({ type: "message.assistant.completed", data: { message: { id: messageItemId, role: "assistant", content: [{ type: "text", text: draft.response.content }], stopReason: "toolUse" }, commitState: "provisional" } });
69
74
  if (!validation.accepted) {
70
75
  emit({ type: "runner.handoff_rejected", data: { attemptId: validation.attemptId, issues: validation.issues } });
71
76
  if (validation.fatal)
72
77
  return { outcome: "abnormal", reason: validation.issues.map((issue) => issue.message).join("; ") };
73
78
  continue;
74
79
  }
80
+ if (validation.messageItemId !== messageItemId)
81
+ return { outcome: "abnormal", reason: "Handoff validation returned a different assistant message identity" };
75
82
  const output = { validationAttemptId: validation.attemptId, validationToken: validation.token, handoff: draft.handoff };
76
- return { outcome: "completed", response: draft.response, handoff: output };
83
+ return { outcome: "completed", finalMessageId: messageItemId, handoff: output };
77
84
  }
78
85
  }
79
86
  return { outcome: "abnormal", reason: "faux worker stopped without handoff" };
package/dist/index.d.ts CHANGED
@@ -337,9 +337,6 @@ interface TurnContext {
337
337
  activeGoal: GoalSnapshot | null;
338
338
  goalCommitment: GoalCommitment | null;
339
339
  }
340
- interface AssistantResponse {
341
- content: string;
342
- }
343
340
  interface RunRequest {
344
341
  agent: string;
345
342
  execution: TurnSnapshot;
@@ -353,7 +350,7 @@ interface RunRequest {
353
350
  }
354
351
  type RunnerCandidateResult = {
355
352
  outcome: "completed";
356
- response: AssistantResponse;
353
+ finalMessageId: string;
357
354
  handoff?: TurnOutput;
358
355
  } | {
359
356
  outcome: "abnormal";
@@ -431,7 +428,8 @@ interface Ledger extends EventStore {
431
428
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
432
429
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
433
430
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
434
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
431
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
432
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
435
433
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
436
434
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
437
435
  putMails(mail: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
@@ -518,7 +516,8 @@ declare class SqliteLedger implements Ledger {
518
516
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
519
517
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
520
518
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
521
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
519
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
520
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
522
521
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
523
522
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
524
523
  putMails(mails: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
package/dist/index.js CHANGED
@@ -31,11 +31,11 @@ import {
31
31
  updateWorkspaceRunnerProfile,
32
32
  writeDefaultConfig,
33
33
  writeDefaultRunnerProfile
34
- } from "./chunk-KJ4HJCTK.js";
35
- import "./chunk-D2DVAH37.js";
36
- import "./chunk-YH6YJ2IB.js";
37
- import "./chunk-QBD6EJ2Z.js";
38
- import "./chunk-7E7V6OIU.js";
34
+ } from "./chunk-5PZFP5CO.js";
35
+ import "./chunk-R6GKCNTB.js";
36
+ import "./chunk-CDELLMIJ.js";
37
+ import "./chunk-SQJZ5OFH.js";
38
+ import "./chunk-EK6BTCFG.js";
39
39
  import "./chunk-6M3OOCKO.js";
40
40
  import "./chunk-K26BVR6O.js";
41
41
  import "./chunk-IIJQ3DW4.js";
package/dist/pi-worker.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-XALZLRYK.js";
6
6
  import {
7
7
  runProcessWorker
8
- } from "./chunk-7E7V6OIU.js";
8
+ } from "./chunk-EK6BTCFG.js";
9
9
  import {
10
10
  createPiModel,
11
11
  fauxAssistantMessage,
@@ -35,6 +35,9 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
35
35
  import { delimiter, dirname, join, resolve, sep } from "node:path";
36
36
  import { homedir, tmpdir } from "node:os";
37
37
  import { fileURLToPath } from "node:url";
38
+ var GOAL_TURN_POLICY = `A Goal commitment starts a sustained work session, not a short status round. Continue working while any safe, useful action can be executed now with current tools and authority. Use the Work Record as a durable checkpoint whenever the semantic state changes; updating it does not end the Turn. Planning, partial progress, decomposition, or scheduling a future Wake are not by themselves reasons to stop. Before Handoff, ask whether another useful action can be completed without new authority, unavailable data, another Agent's result, or the passage of time; if yes, do it now.
39
+
40
+ Call handoff exactly once, only at a genuine control boundary: the current actionable frontier is exhausted after meaningful work, an explicit external wait is required, a real blocker prevents safe progress, or completion evidence is ready for review. Use outcome progress only for the first case, waiting only for the second, blocked only for the third, and completion_proposed only for the fourth. Write a concise human-readable assistant message describing what happened, and keep Handoff machine-readable with only outcome and evidence. Treat the supplied context as authoritative.`;
38
41
  function compactMessages(messages, maxRecent = 8) {
39
42
  if (messages.length <= maxRecent + 1)
40
43
  return messages;
@@ -100,8 +103,10 @@ Follow the current Goal and explicit tools.
100
103
  `;
101
104
  const finalResponse = fauxAssistantMessage([fauxText(String(handoff.message ?? `Goal work recorded with outcome ${outcome}.`)), fauxToolCall("handoff", { outcome, evidence: handoffEvidence })], { stopReason: "toolUse" });
102
105
  const recordResponse = fauxAssistantMessage(fauxToolCall("work_record_update", { expectedRevision: Number(current.recordRevision ?? 0), content: record, reason: "record faux Goal progress", evidence: evidence.length ? [Math.max(...evidence)] : [] }), { stopReason: "toolUse" });
106
+ const narratedScheduleResponse = fauxAssistantMessage([fauxText(String(handoff.message ?? "Work Record updated; the next wake is scheduled.")), fauxToolCall("schedule_wake", { at: new Date(Date.parse(request.execution.startedAt) + 6e4).toISOString(), reason: "continue Goal work" })], { stopReason: "toolUse" });
107
+ const toolOnlyHandoff = fauxAssistantMessage(fauxToolCall("handoff", { outcome, evidence: handoffEvidence }), { stopReason: "toolUse" });
103
108
  const fatalBatch = fauxAssistantMessage([fauxText("Stale completion attempt."), fauxToolCall("handoff", { outcome, evidence: handoffEvidence }), fauxToolCall("write", { path: "fatal.txt", content: "must not be written" })], { stopReason: "toolUse" });
104
- faux.setResponses(process.env.GOAH_PI_FAUX_FATAL_BATCH === "1" ? [fatalBatch] : process.env.GOAH_PI_FAUX_HANDOFF_REPAIR === "1" ? [fauxAssistantMessage([fauxText("Premature completion attempt."), fauxToolCall("handoff", { outcome, evidence: handoffEvidence })], { stopReason: "toolUse" }), recordResponse, finalResponse] : [recordResponse, finalResponse]);
109
+ faux.setResponses(process.env.GOAH_PI_FAUX_FATAL_BATCH === "1" ? [fatalBatch] : process.env.GOAH_PI_FAUX_HANDOFF_REPAIR === "1" ? [fauxAssistantMessage([fauxText("Premature completion attempt."), fauxToolCall("handoff", { outcome, evidence: handoffEvidence })], { stopReason: "toolUse" }), recordResponse, finalResponse] : process.env.GOAH_PI_FAUX_TOOL_ONLY_HANDOFF === "1" ? [recordResponse, narratedScheduleResponse, toolOnlyHandoff] : [recordResponse, finalResponse]);
105
110
  } else if (!goalState.bound) {
106
111
  faux.setResponses([fauxAssistantMessage([fauxText(process.env.GOAH_PI_FAUX_RESPONSE ?? "Hello from Goah.")])]);
107
112
  } else {
@@ -113,7 +118,7 @@ Follow the current Goal and explicit tools.
113
118
  let output = null;
114
119
  let acceptedHandoff = null;
115
120
  let revokedReason = "";
116
- let response = "";
121
+ let lastReadableMessage = null;
117
122
  let responseFailure = "";
118
123
  let compactions = 0;
119
124
  let messageCounter = 0;
@@ -125,7 +130,7 @@ Follow the current Goal and explicit tools.
125
130
  const existing = messageIds.get(message);
126
131
  if (existing)
127
132
  return existing;
128
- const id = `message:${++messageCounter}`;
133
+ const id = `${request.execution.id}:attempt:${request.execution.attempt}:message:${++messageCounter}`;
129
134
  messageIds.set(message, id);
130
135
  return id;
131
136
  };
@@ -145,8 +150,11 @@ Follow the current Goal and explicit tools.
145
150
  const sourceSeqs = Array.isArray(contextRecord.sourceSeqs) ? contextRecord.sourceSeqs.filter((value) => Number.isInteger(value)) : [];
146
151
  const basePrompt = process.env.GOAH_PI_SYSTEM_PROMPT ?? suppliedPrompt ?? (request.turn?.trigger.kind === "user_message" ? "You are Goah's primary Agent. Respond naturally to the Human." : `You are Goah Agent ${request.agent}. Inspect the supplied context and respond appropriately.`);
147
152
  const systemPrompt = goalState.bound ? `${basePrompt}
148
- This Turn has a Goal commitment. You must update its Work Record, write a concise human-readable assistant message describing what happened, and call handoff exactly once with only machine-readable outcome and evidence. The message and Handoff are separate outputs. Treat the supplied context as authoritative.` : request.turn?.trigger.kind === "user_message" ? `${basePrompt}
149
- The active Goal, when supplied, is context rather than an assignment. Finish with an ordinary response unless a Goal tool establishes a commitment during this Turn. After commitment, update that Goal's Work Record, write a concise human-readable assistant message, and call handoff exactly once with separate machine-readable outcome and evidence. Treat the supplied context as authoritative.` : `${basePrompt}
153
+
154
+ ${GOAL_TURN_POLICY}` : request.turn?.trigger.kind === "user_message" ? `${basePrompt}
155
+ The active Goal, when supplied, is context rather than an assignment. Finish with an ordinary response unless a Goal tool establishes a commitment during this Turn. If a Goal commitment is established, follow this policy for the rest of the Turn:
156
+
157
+ ${GOAL_TURN_POLICY}` : `${basePrompt}
150
158
  This Turn has no Goal commitment. Finish with an ordinary response and do not call handoff. Treat the supplied context as authoritative.`;
151
159
  const agent = new Agent({
152
160
  initialState: {
@@ -196,10 +204,16 @@ This Turn has no Goal commitment. Finish with an ordinary response and do not ca
196
204
  acceptedHandoff = null;
197
205
  output = null;
198
206
  const handoff = args;
207
+ const currentText = assistantResponseText(assistantMessage);
208
+ const candidate = currentText ? { id: idFor(assistantMessage), text: currentText } : lastReadableMessage;
199
209
  try {
200
- const result = await rpc("goal.handoff.validate", { handoff, candidateMessage: assistantResponseText(assistantMessage) });
210
+ const result = await rpc("goal.handoff.validate", { handoff, candidateMessageId: candidate?.id ?? "", candidateMessage: candidate?.text ?? "" });
201
211
  if (result.accepted) {
202
- acceptedHandoff = { attemptId: result.attemptId, token: result.token, handoff };
212
+ if (!candidate || result.messageItemId !== candidate.id) {
213
+ revokedReason = "Handoff validation returned a different assistant message identity";
214
+ return { block: true, reason: revokedReason, terminate: true };
215
+ }
216
+ acceptedHandoff = { attemptId: result.attemptId, token: result.token, messageItemId: result.messageItemId, handoff };
203
217
  return;
204
218
  }
205
219
  const reason = result.issues.map((issue) => `- ${issue.message}`).join("\n");
@@ -234,11 +248,14 @@ ${reason}`, terminate: result.fatal };
234
248
  } else if (event.type === "message_update") {
235
249
  emit({ type: "message.assistant.delta", data: { messageId: idFor(event.message), delta: JSON.parse(JSON.stringify(event.assistantMessageEvent)) } });
236
250
  } else if (event.type === "message_end" && event.message.role === "assistant") {
237
- response = assistantResponseText(event.message);
251
+ const messageId = idFor(event.message);
252
+ const text = assistantResponseText(event.message);
253
+ if (text)
254
+ lastReadableMessage = { id: messageId, text };
238
255
  if ((event.message.stopReason === "error" || event.message.stopReason === "aborted") && event.message.errorMessage)
239
256
  responseFailure = event.message.errorMessage;
240
257
  const handoffIntent = hasAgentToolCall(event.message, "handoff");
241
- emit({ type: "message.assistant.completed", data: { message: transcriptMessage(event.message, idFor(event.message)), commitState: handoffIntent ? "provisional" : "committed" } });
258
+ emit({ type: "message.assistant.completed", data: { message: transcriptMessage(event.message, messageId), commitState: handoffIntent ? "provisional" : "committed" } });
242
259
  } else if (event.type === "tool_execution_start")
243
260
  emit({ type: "tool.called", data: { callId: event.toolCallId, name: event.toolName, arguments: JSON.parse(JSON.stringify(event.args)) } });
244
261
  else if (event.type === "tool_execution_end")
@@ -262,13 +279,17 @@ Runner root: ${root}. Manage local files directly when the goal requires them.`)
262
279
  }
263
280
  if (revokedReason)
264
281
  return { outcome: "abnormal", reason: revokedReason };
282
+ const finalMessage = lastReadableMessage;
265
283
  if (!goalState.bound)
266
- return response ? { outcome: "completed", response: { content: response } } : { outcome: "abnormal", reason: responseFailure || "Pi worker exited without a response" };
284
+ return finalMessage ? { outcome: "completed", finalMessageId: finalMessage.id } : { outcome: "abnormal", reason: responseFailure || "Pi worker exited without a response" };
267
285
  if (responseFailure)
268
286
  return { outcome: "abnormal", reason: responseFailure };
269
287
  if (!output)
270
288
  return { outcome: "abnormal", reason: "Pi worker exited without an accepted Handoff" };
271
- return { outcome: "completed", response: { content: response }, handoff: output };
289
+ const finalHandoff = acceptedHandoff;
290
+ if (!finalHandoff)
291
+ return { outcome: "abnormal", reason: "Pi worker exited without an accepted Handoff message" };
292
+ return { outcome: "completed", finalMessageId: finalHandoff.messageItemId, handoff: output };
272
293
  });
273
294
  }
274
295
  function snapshotModelConfig(options) {
@@ -294,7 +315,7 @@ function createTools(root, handoff, rpc, capabilities, goalState, protectedPaths
294
315
  const handoffTool = {
295
316
  name: "handoff",
296
317
  label: "Handoff",
297
- description: "Record a structured handoff and end a Turn with a Goal commitment.",
318
+ description: "End the current Goal Turn at a genuine control boundary. Do not call while another safe and useful action can be completed now. Planning, partial progress, a Work Record update, or a scheduled Wake does not by itself justify Handoff.",
298
319
  parameters: typebox_exports.Object({
299
320
  outcome: typebox_exports.Union([typebox_exports.Literal("progress"), typebox_exports.Literal("waiting"), typebox_exports.Literal("blocked"), typebox_exports.Literal("completion_proposed")]),
300
321
  evidence: typebox_exports.Array(typebox_exports.Number())
@@ -488,7 +509,7 @@ function createRpcTools(rpc, allowed, onResult) {
488
509
  ["ledger.search", tool("ledger_search", "Search durable ledger facts.", "ledger.search", typebox_exports.Object({ query: typebox_exports.String(), limit: typebox_exports.Optional(typebox_exports.Number()) }))],
489
510
  ["memory.append", tool("memory_append", "Append a durable working-memory note that is injected into your future wakes. Record procedural knowledge, active hypotheses, and abandoned approaches with the reason; keep notes concise.", "memory.append", typebox_exports.Object({ note: typebox_exports.String() }))],
490
511
  ["mail.send", tool("send_mail", "Send durable Mail to another Goal owner. goalId is required and routes the Mail into that owner's next committed Turn. Human communication must use request_human.", "mail.send", typebox_exports.Object({ to: typebox_exports.String(), goalId: typebox_exports.String(), level: typebox_exports.Union([typebox_exports.Literal("fyi"), typebox_exports.Literal("decision"), typebox_exports.Literal("emergency")]), body: typebox_exports.Any() }))],
491
- ["schedule.set", tool("schedule_wake", "Schedule this agent's next wake.", "schedule.set", typebox_exports.Object({ at: typebox_exports.String(), reason: typebox_exports.String() }))],
512
+ ["schedule.set", tool("schedule_wake", "Schedule genuinely time-dependent future observation. Scheduling does not end the current Turn; continue all useful work that can be completed before waiting.", "schedule.set", typebox_exports.Object({ at: typebox_exports.String(), reason: typebox_exports.String() }))],
492
513
  ["team.list", tool("team_list", "Read the ledger-derived team roster and liveness state.", "team.list", typebox_exports.Object({}))],
493
514
  ["goal.get", tool("get_goal", "Read the active Goal visible to this Turn. Visibility does not establish a Goal commitment.", "goal.get", typebox_exports.Object({}))],
494
515
  ["goal.create", tool("create_goal", "Create a Root Goal from durable Human intent and bind this Turn. Do not use for greetings, questions, or routine single-turn work.", "goal.create", typebox_exports.Object({ objective: typebox_exports.String(), id: typebox_exports.Optional(typebox_exports.String()) }))],
@@ -87,6 +87,7 @@ type HandoffValidationResult = {
87
87
  token: string;
88
88
  goalId: string;
89
89
  goalRevision: number;
90
+ messageItemId: string;
90
91
  } | {
91
92
  accepted: false;
92
93
  fatal: boolean;
@@ -181,9 +182,6 @@ interface TurnContext {
181
182
  activeGoal: GoalSnapshot | null;
182
183
  goalCommitment: GoalCommitment | null;
183
184
  }
184
- interface AssistantResponse {
185
- content: string;
186
- }
187
185
  interface RunRequest {
188
186
  agent: string;
189
187
  execution: TurnSnapshot;
@@ -197,7 +195,7 @@ interface RunRequest {
197
195
  }
198
196
  type RunnerCandidateResult = {
199
197
  outcome: "completed";
200
- response: AssistantResponse;
198
+ finalMessageId: string;
201
199
  handoff?: TurnOutput;
202
200
  } | {
203
201
  outcome: "abnormal";
@@ -267,14 +265,17 @@ interface EnvSpecSource {
267
265
  */
268
266
  declare function resolveEnvSpec(spec: Record<string, string> | undefined, source: EnvSpecSource | undefined): Record<string, string>;
269
267
 
268
+ interface PiAssistantResponse {
269
+ content: string;
270
+ }
270
271
  interface PiStep {
271
272
  trace?: Array<{
272
273
  type: string;
273
274
  data: JsonValue;
274
275
  }>;
275
- response?: AssistantResponse;
276
+ response?: PiAssistantResponse;
276
277
  handoff?: {
277
- response: AssistantResponse;
278
+ response: PiAssistantResponse;
278
279
  handoff: AgentHandoff;
279
280
  };
280
281
  stopped?: boolean;
@@ -339,4 +340,4 @@ type WorkerRun = (request: WorkerRequest, emit: (event: {
339
340
  declare function runProcessWorker(run: WorkerRun): Promise<void>;
340
341
 
341
342
  export { LOCAL_PROVIDERS, PiRunnerAdapter, ProcessRunner, createPiProcessRunner, defaultAuthFile, modelCatalog, piConfig, piEnvironment, piRunnerConfigurator, piWorkerPath, providerCatalog, resolveEnvSpec, runProcessWorker, verificationWorkerPath };
342
- export type { ModelSummary, PiDriver, PiRunnerConfig, PiRunnerSession, PiStep, ProcessRunnerOptions, ProviderSummary, WorkerControls, WorkerRpc, WorkerRun };
343
+ export type { ModelSummary, PiAssistantResponse, PiDriver, PiRunnerConfig, PiRunnerSession, PiStep, ProcessRunnerOptions, ProviderSummary, WorkerControls, WorkerRpc, WorkerRun };
package/dist/runner-pi.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  resolveEnvSpec,
12
12
  runProcessWorker,
13
13
  verificationWorkerPath
14
- } from "./chunk-7E7V6OIU.js";
14
+ } from "./chunk-EK6BTCFG.js";
15
15
  import {
16
16
  LOCAL_PROVIDERS,
17
17
  defaultAuthFile,
@@ -3,8 +3,8 @@ const require = __goahCreateRequire(import.meta.url);
3
3
  import {
4
4
  runnerManifests,
5
5
  runnerPlugin
6
- } from "./chunk-D2DVAH37.js";
7
- import "./chunk-7E7V6OIU.js";
6
+ } from "./chunk-R6GKCNTB.js";
7
+ import "./chunk-EK6BTCFG.js";
8
8
  import "./chunk-6M3OOCKO.js";
9
9
  import "./chunk-K26BVR6O.js";
10
10
  import "./chunk-IIJQ3DW4.js";
package/dist/sqlite.d.ts CHANGED
@@ -320,7 +320,8 @@ interface Ledger extends EventStore {
320
320
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
321
321
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
322
322
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
323
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
323
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
324
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
324
325
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
325
326
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
326
327
  putMails(mail: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
@@ -408,7 +409,8 @@ declare class SqliteLedger implements Ledger {
408
409
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
409
410
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
410
411
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
411
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
412
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
413
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
412
414
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
413
415
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
414
416
  putMails(mails: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
package/dist/sqlite.js CHANGED
@@ -3,7 +3,7 @@ const require = __goahCreateRequire(import.meta.url);
3
3
  import {
4
4
  SQLITE_SCHEMA_VERSION,
5
5
  SqliteLedger
6
- } from "./chunk-YH6YJ2IB.js";
6
+ } from "./chunk-CDELLMIJ.js";
7
7
  import "./chunk-4KA63VNZ.js";
8
8
  import "./chunk-KAO7WIXG.js";
9
9
  import "./chunk-R6I3VKME.js";
@@ -304,9 +304,6 @@ interface TurnContext {
304
304
  activeGoal: GoalSnapshot | null;
305
305
  goalCommitment: GoalCommitment | null;
306
306
  }
307
- interface AssistantResponse {
308
- content: string;
309
- }
310
307
  interface RunRequest {
311
308
  agent: string;
312
309
  execution: TurnSnapshot;
@@ -320,7 +317,7 @@ interface RunRequest {
320
317
  }
321
318
  type RunnerCandidateResult = {
322
319
  outcome: "completed";
323
- response: AssistantResponse;
320
+ finalMessageId: string;
324
321
  handoff?: TurnOutput;
325
322
  } | {
326
323
  outcome: "abnormal";
@@ -398,7 +395,8 @@ interface Ledger extends EventStore {
398
395
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
399
396
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
400
397
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
401
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
398
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
399
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
402
400
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
403
401
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
404
402
  putMails(mail: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
@@ -15,7 +15,7 @@ import {
15
15
  renderDashboard,
16
16
  runSupervisorDaemon,
17
17
  selectRecoveryEvents
18
- } from "./chunk-QBD6EJ2Z.js";
18
+ } from "./chunk-SQJZ5OFH.js";
19
19
  import "./chunk-4KA63VNZ.js";
20
20
  import "./chunk-KAO7WIXG.js";
21
21
  import "./chunk-R6I3VKME.js";
package/dist/testkit.d.ts CHANGED
@@ -269,6 +269,7 @@ type HandoffValidationResult = {
269
269
  token: string;
270
270
  goalId: string;
271
271
  goalRevision: number;
272
+ messageItemId: string;
272
273
  } | {
273
274
  accepted: false;
274
275
  fatal: boolean;
@@ -296,9 +297,6 @@ interface TurnContext {
296
297
  activeGoal: GoalSnapshot | null;
297
298
  goalCommitment: GoalCommitment | null;
298
299
  }
299
- interface AssistantResponse {
300
- content: string;
301
- }
302
300
  interface RunRequest {
303
301
  agent: string;
304
302
  execution: TurnSnapshot;
@@ -370,7 +368,8 @@ interface Ledger extends EventStore {
370
368
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
371
369
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
372
370
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
373
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
371
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
372
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
374
373
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
375
374
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
376
375
  putMails(mail: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
@@ -457,7 +456,8 @@ declare class SqliteLedger implements Ledger {
457
456
  renewTurnLease(id: string, leaseToken: string, leaseUntil: string, now: string): TurnSnapshot;
458
457
  appendTurnEvent(input: EventInput, leaseToken: string): EventRecord;
459
458
  repairTurnAttempt(id: string, reason: string, now: string, actor: string): TurnItemSnapshot[];
460
- finishTurn(id: string, status: "completed" | "failed" | "interrupted", error: JsonValue | null, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
459
+ finishTurn(id: string, status: "failed" | "interrupted", error: JsonValue, now: string, actor: string): TurnSnapshot;
460
+ commitTurnResponse(id: string, responseItemId: string, now: string, actor: string, mailIds?: string[]): TurnSnapshot;
461
461
  releaseTurnProcess(id: string, actor: string): TurnSnapshot;
462
462
  putMail(mail: MailSnapshot, actor: string, wakeId?: string): EventRecord;
463
463
  putMails(mails: MailSnapshot[], actor: string, wakeId?: string): EventRecord[];
@@ -491,14 +491,17 @@ declare class SqliteLedger implements Ledger {
491
491
  rebuildProjections(): void;
492
492
  }
493
493
 
494
+ interface PiAssistantResponse {
495
+ content: string;
496
+ }
494
497
  interface PiStep {
495
498
  trace?: Array<{
496
499
  type: string;
497
500
  data: JsonValue;
498
501
  }>;
499
- response?: AssistantResponse;
502
+ response?: PiAssistantResponse;
500
503
  handoff?: {
501
- response: AssistantResponse;
504
+ response: PiAssistantResponse;
502
505
  handoff: AgentHandoff;
503
506
  };
504
507
  stopped?: boolean;
package/dist/testkit.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire as __goahCreateRequire } from "node:module";
2
2
  const require = __goahCreateRequire(import.meta.url);
3
3
  import {
4
4
  SqliteLedger
5
- } from "./chunk-YH6YJ2IB.js";
5
+ } from "./chunk-CDELLMIJ.js";
6
6
  import "./chunk-4KA63VNZ.js";
7
7
  import "./chunk-KAO7WIXG.js";
8
8
  import "./chunk-R6I3VKME.js";
@@ -107,6 +107,10 @@ function assertLedgerConformance(create) {
107
107
  throw new Error("ledger conformance: consumed Wake did not link its Turn");
108
108
  if (ledger.wakeTriggers("z").some((trigger) => trigger.status !== "resolved"))
109
109
  throw new Error("ledger conformance: consumed Wake retained pending triggers");
110
+ ledger.putTurnItem({ id: "turn:a:answer", turnId: turn.id, ordinal: 1, type: "assistant_message", status: "completed", data: { text: "verified" }, createdAt: clock.now().toISOString(), completedAt: clock.now().toISOString() }, "a");
111
+ ledger.commitTurnResponse(turn.id, "turn:a:answer", clock.now().toISOString(), "supervisor");
112
+ if (ledger.turn(turn.id)?.status !== "completed" || !ledger.readStream(`turn:${turn.id}`).some((item) => item.type === "response.committed" && item.data.messageItemId === "turn:a:answer"))
113
+ throw new Error("ledger conformance: canonical Assistant response was not committed");
110
114
  if (first.event.ts !== clock.now().toISOString())
111
115
  throw new Error("ledger conformance: injected clock was ignored");
112
116
  const informational = ledger.appendEvent({ streamId: "conformance:events", ts: clock.now().toISOString(), actor: "a", type: "transcript.conformance_info", data: {}, ignorable: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goah/cli",
3
- "version": "0.13.2",
3
+ "version": "0.13.4",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",