@akagilnc/pi-workflow-roles 0.1.4586 → 0.1.4631

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.
Files changed (63) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +3 -3
  3. package/dist/acp-host/production-host.js +1184 -717
  4. package/dist/activation-ledger-topology.js +0 -4
  5. package/dist/archivist-record-topology.js +27 -35
  6. package/dist/headless-host/description.js +7 -4
  7. package/dist/headless-host/production-host.js +998 -595
  8. package/dist/migrate-book-topology.js +3 -6
  9. package/dist/navigator-attendance.js +146 -241
  10. package/dist/navigator-public-session.js +81 -15
  11. package/dist/package-contracts/navigator-output.js +30 -12
  12. package/dist/pi/role-turn-host.js +0 -3
  13. package/dist/public-cli/auto-resume.js +26 -0
  14. package/dist/public-cli/judge-run.js +2 -2
  15. package/dist/public-cli/main.js +1119 -870
  16. package/dist/public-cli/option-definitions.js +1 -1
  17. package/dist/public-cli/post-admission.js +103 -9
  18. package/dist/public-cli/process-cancel.js +57 -0
  19. package/dist/public-cli/run-lifecycle.js +29 -7
  20. package/dist/public-cli/settlement.js +46 -32
  21. package/dist/public-cli/terminal.js +8 -27
  22. package/dist/public-role-summons.js +22 -4
  23. package/dist/submission-ledger.js +56 -23
  24. package/package.json +1 -1
  25. package/resources/836-deleted-machine-instruction-inventory.md +2 -0
  26. package/resources/navigator-route-playbook.md +9 -0
  27. package/scripts/build-package.mjs +6 -2
  28. package/src/acp-host/role-turn-host.ts +129 -13
  29. package/src/activation-ledger-topology.ts +1 -6
  30. package/src/activation-ledger.ts +5 -236
  31. package/src/analyst-entry.ts +19 -2
  32. package/src/analyst-ledger.ts +111 -6
  33. package/src/archivist-record-entry.ts +1 -1
  34. package/src/headless-host/description.ts +17 -7
  35. package/src/headless-host/role-turn-host.ts +42 -11
  36. package/src/navigator-attendance.ts +290 -425
  37. package/src/navigator-public-session.ts +126 -25
  38. package/src/navigator-role.ts +2 -2
  39. package/src/package-contracts/navigator-output.ts +41 -25
  40. package/src/pi/role-turn-host.ts +0 -3
  41. package/src/public-cli/auto-resume.ts +34 -0
  42. package/src/public-cli/cli.ts +30 -0
  43. package/src/public-cli/coder-run.ts +2 -2
  44. package/src/public-cli/fixer-run.ts +2 -2
  45. package/src/public-cli/judge-run.ts +2 -2
  46. package/src/public-cli/main.ts +25 -3
  47. package/src/public-cli/merger-run.ts +2 -2
  48. package/src/public-cli/option-definitions.ts +1 -1
  49. package/src/public-cli/post-admission.ts +175 -7
  50. package/src/public-cli/process-cancel.ts +75 -0
  51. package/src/public-cli/run-lifecycle.ts +37 -7
  52. package/src/public-cli/settlement.ts +42 -33
  53. package/src/public-cli/terminal.ts +12 -37
  54. package/src/public-role-summons.ts +34 -5
  55. package/src/role-envelope.ts +89 -4
  56. package/src/role-runtime.ts +78 -65
  57. package/src/submission-ledger.ts +63 -21
  58. package/dist/activation-reconciliation.js +0 -61
  59. package/dist/public-cli/command-renderer.js +0 -5
  60. package/dist/public-command-renderer.js +0 -29
  61. package/src/activation-reconciliation.ts +0 -163
  62. package/src/public-cli/command-renderer.ts +0 -9
  63. package/src/public-command-renderer.ts +0 -55
@@ -338,6 +338,59 @@ async function restoreState(cwd, runId, scope) {
338
338
  }, 0),
339
339
  };
340
340
  }
341
+ /** Sole HostContext-derived session parent for ledger restore/append (never process.env). */
342
+ function sessionParentFromHostContext(context) {
343
+ const runDirectory = runDirectoryFromHostContext(context);
344
+ if (runDirectory !== undefined)
345
+ return join(runDirectory, "session", "session.jsonl");
346
+ const sessionFile = context.sessionManager.getSessionFile?.();
347
+ if (typeof sessionFile === "string" && sessionFile.length > 0)
348
+ return sessionFile;
349
+ const sessionDir = context.sessionManager.getSessionDir?.();
350
+ if (typeof sessionDir === "string" && sessionDir.length > 0) {
351
+ return join(sessionDir, "session.jsonl");
352
+ }
353
+ return undefined;
354
+ }
355
+ function homeFromHostContext(context, home) {
356
+ if (home !== undefined)
357
+ return home;
358
+ const sessionParent = sessionParentFromHostContext(context);
359
+ return sessionParent !== undefined ? tryHomeFromAkRolesPath(sessionParent) : undefined;
360
+ }
361
+ /**
362
+ * #959: seal one accepted submission without a model tool call.
363
+ * Same ledger row shape and priorEventId chain as the terminating-tool wrap.
364
+ * Used when a prose-exit seat (navigator) harvests the final assistant text.
365
+ */
366
+ export async function sealAcceptedSubmission(options) {
367
+ const runId = runIdentity(options.context);
368
+ const attemptId = attemptIdentity(options.context, runId);
369
+ const sessionParent = sessionParentFromHostContext(options.context);
370
+ const home = homeFromHostContext(options.context, options.home);
371
+ const state = await restoreState(options.context.cwd, runId, {
372
+ ...(home === undefined ? {} : { home }),
373
+ ...(sessionParent === undefined ? {} : { sessionParent }),
374
+ });
375
+ const pointer = sitianReport({
376
+ level: "event",
377
+ kind: "sealed",
378
+ subject: { runId, attemptId },
379
+ ...(state.prior === undefined ? {} : { priorEventId: state.prior.identity }),
380
+ payload: {
381
+ type: "sealed",
382
+ attemptId,
383
+ toolCallId: options.toolCallId,
384
+ role: options.role,
385
+ accepted: options.accepted,
386
+ },
387
+ source: "role-runtime",
388
+ cwd: options.context.cwd,
389
+ ...(home !== undefined ? { home } : {}),
390
+ ...(sessionParent === undefined ? {} : { sessionParent }),
391
+ });
392
+ state.prior = pointer;
393
+ }
341
394
  /**
342
395
  * Submission ledger host — record only (#836).
343
396
  * Each terminating submission is appended with the role's original payload.
@@ -346,30 +399,10 @@ async function restoreState(cwd, runId, scope) {
346
399
  */
347
400
  export function createSubmissionLedgerHost(host, outputTools, failInfrastructure = (error) => { throw error; }, projectClosure = () => undefined, options) {
348
401
  const states = new Map();
349
- /** Sole HostContext-derived run coordinate for restore and append (never process.env). */
350
- const sessionParentFromContext = (context) => {
351
- const runDirectory = runDirectoryFromHostContext(context);
352
- if (runDirectory !== undefined) {
353
- return join(runDirectory, "session", "session.jsonl");
354
- }
355
- const sessionFile = context.sessionManager.getSessionFile?.();
356
- if (typeof sessionFile === "string" && sessionFile.length > 0)
357
- return sessionFile;
358
- const sessionDir = context.sessionManager.getSessionDir?.();
359
- if (typeof sessionDir === "string" && sessionDir.length > 0) {
360
- return join(sessionDir, "session.jsonl");
361
- }
362
- return undefined;
363
- };
364
- const resolveHomeFromContext = (context) => {
365
- if (options?.home !== undefined)
366
- return options.home;
367
- const sessionParent = sessionParentFromContext(context);
368
- return sessionParent !== undefined ? tryHomeFromAkRolesPath(sessionParent) : undefined;
369
- };
402
+ const resolveHomeFromContext = (context) => homeFromHostContext(context, options?.home);
370
403
  const stateFor = (context, runId) => states.get(runId) ?? (() => {
371
404
  const home = resolveHomeFromContext(context);
372
- const sessionParent = sessionParentFromContext(context);
405
+ const sessionParent = sessionParentFromHostContext(context);
373
406
  const pending = restoreState(context.cwd, runId, {
374
407
  ...(home === undefined ? {} : { home }),
375
408
  ...(sessionParent === undefined ? {} : { sessionParent }),
@@ -379,7 +412,7 @@ export function createSubmissionLedgerHost(host, outputTools, failInfrastructure
379
412
  })();
380
413
  const appendFor = (state, context, runId, attemptId, event) => {
381
414
  const home = resolveHomeFromContext(context);
382
- const sessionParent = sessionParentFromContext(context);
415
+ const sessionParent = sessionParentFromHostContext(context);
383
416
  const pointer = sitianReport({
384
417
  level: "event",
385
418
  kind: event.type,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akagilnc/pi-workflow-roles",
3
- "version": "0.1.4586",
3
+ "version": "0.1.4631",
4
4
  "description": "Soul-bound workflow roles for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -14,5 +14,7 @@
14
14
  | `run-lifecycle.ts` A4.2 | `重新读 <path>` | 前轮已删改写。 |
15
15
  | `submission-correctable-error.ts` A4.5 | `终局交卷并非本轮唯一工具调用。` | 删。Pi/ACP `deliverSubmissionRejection` 不再注入该句。 |
16
16
  | `role-runtime.ts` 催交 | `本会话尚无已接受的 typed 回执。` | **留**(轮次/预算,Q2)。 |
17
+ | `navigator-attendance.ts` early prepare 开场 | `父衙门进行中。请在本宿主会话熟悉下列材料并待命;结算结果送达后,再给出下一步建议。本轮不要提交最终路线建议。` | #959 迁入 `resources/navigator-route-playbook.md`「到场阶段」;代码只留中立指针句「本轮为待命轮。」 |
18
+ | `navigator-attendance.ts` settlement feed 开场 | `父衙门结算已送达。请根据下列材料给出下一步建议。` | #959 迁入同手册;代码只留中立指针句「本轮为结算投喂轮。」 |
17
19
 
18
20
  催交句与 2.1–2.3 打回文、重问三句不在删除列。
@@ -1,3 +1,12 @@
1
+ ## 到场阶段(#959 / ADR 0073)
2
+
3
+ 代码只传中立阶段指针句与 typed 材料;阶段行为说明住本手册,随案附卷。
4
+
5
+ - **待命轮**:父衙门进行中。请在本宿主会话熟悉下列材料并待命;结算结果送达后,再给出下一步建议。本轮不要提交最终路线建议。
6
+ - **结算投喂轮**:父衙门结算已送达。请根据下列材料给出下一步建议。
7
+
8
+ Early 待命轮的输出由执行机制丢弃;最终路线建议只在结算投喂轮给出。
9
+
1
10
  ## 宿主轴(与角色命令面)
2
11
 
3
12
  游奕使自动出席,亦可 `ak-role navigator` 直调(自动出席不变)。主会话宿主由公开角色的 host 轴决定:调用 `--host` → 席位 `config set-host` → 默认 `pi`。配置默认 host 后,调用者仍用与 Pi 相同的 `ak-role <role> …` 命令面;游奕使随该宿主下的角色跑次出席,席位模型走 run 目录 `institutional-resolution.json` 的 navigator 座(显式 `config set navigator` 优先,否则继承父席有效模型),不再依赖父宿主 ExtensionContext。
@@ -5,7 +5,6 @@ import { build } from "esbuild";
5
5
 
6
6
  const entries = [
7
7
  "packaged-role-registry",
8
- "public-command-renderer",
9
8
  "work-subject-identity",
10
9
  "navigator-invocation-identity",
11
10
  // Static import of navigator-invocation-identity (#603: non-bundle graph closure).
@@ -20,8 +19,11 @@ const entries = [
20
19
  "pi/in-process-session",
21
20
  "activation-ledger-git",
22
21
  "activation-ledger-topology",
23
- "activation-reconciliation",
24
22
  "archivist-record-entry",
23
+ // Pure subject nest topology — static import of archivist-record-entry;
24
+ // cold discovery without SessionManager (#636). Keep listed while that
25
+ // relative edge remains (#857 removal left the import graph open).
26
+ "archivist-record-topology",
25
27
  // Session material loaders used by published non-bundle roots.
26
28
  "session-opening-materials",
27
29
  // Value-import closure of published non-bundle roots (build-package-only loadable).
@@ -205,6 +207,8 @@ export async function buildPackageArtifacts() {
205
207
  await mkdir(pluginDir, { recursive: true });
206
208
  await cp("resources/method-host-plugin/.claude-plugin", join(pluginDir, ".claude-plugin"), { recursive: true });
207
209
  await cp("resources/methods", join(pluginDir, "skills"), { recursive: true });
210
+ // Packaged handbook/playbook paths resolve via injected packageRoot (#962) —
211
+ // do not mirror resources/ into dist/resources (one authority, no parallel copy).
208
212
  }
209
213
 
210
214
  const isMain =
@@ -9,6 +9,10 @@ import {
9
9
  } from "../external-host-turn-loop.ts";
10
10
 
11
11
  import { reportHostSessionEvent } from "../host-session-record.ts";
12
+ import {
13
+ NAVIGATOR_OUTPUT_TOOL_NAME,
14
+ navigatorProseFromUnknown,
15
+ } from "../package-contracts/navigator-output.ts";
12
16
  import {
13
17
  renderSystemPromptOverride,
14
18
  type PreparedRoleTurn,
@@ -16,6 +20,53 @@ import {
16
20
  } from "../prepared-role-turn.ts";
17
21
  import { acpModelId, type AcpHostDescription } from "./description.ts";
18
22
 
23
+ /**
24
+ * #959: collect free-form agent text from ACP session/update stream.
25
+ * Used only when the navigator seat spoke prose without calling the output tool.
26
+ * ACP agent speech is only agent_message / agent_message_chunk — never user,
27
+ * thought, or other *_message kinds (load replay must not poison the bucket).
28
+ *
29
+ * Standard ACP nests under params.update: { sessionUpdate, content }.
30
+ * Flat params.sessionUpdate / string params.update remain accepted for host variants.
31
+ */
32
+ function acpAgentTextChunk(params: Readonly<Record<string, unknown>>): string | undefined {
33
+ let kind: unknown;
34
+ let content: unknown;
35
+ let textFallback: unknown;
36
+
37
+ const nested = params.update;
38
+ if (typeof nested === "object" && nested !== null && !Array.isArray(nested)) {
39
+ const record = nested as Record<string, unknown>;
40
+ kind = record.sessionUpdate;
41
+ content = record.content;
42
+ textFallback = record.text;
43
+ } else {
44
+ kind = params.sessionUpdate ?? nested;
45
+ content = params.content;
46
+ textFallback = params.text;
47
+ }
48
+
49
+ if (kind !== "agent_message_chunk" && kind !== "agent_message") return undefined;
50
+ if (typeof content === "string" && content.length > 0) return content;
51
+ if (typeof content === "object" && content !== null && !Array.isArray(content)) {
52
+ const record = content as Record<string, unknown>;
53
+ if (typeof record.text === "string" && record.text.length > 0) return record.text;
54
+ }
55
+ if (Array.isArray(content)) {
56
+ const parts: string[] = [];
57
+ for (const part of content) {
58
+ if (typeof part === "string" && part.length > 0) parts.push(part);
59
+ else if (typeof part === "object" && part !== null) {
60
+ const record = part as Record<string, unknown>;
61
+ if (typeof record.text === "string" && record.text.length > 0) parts.push(record.text);
62
+ }
63
+ }
64
+ if (parts.length > 0) return parts.join("");
65
+ }
66
+ if (typeof textFallback === "string" && textFallback.length > 0) return textFallback;
67
+ return undefined;
68
+ }
69
+
19
70
  /** ACP v1 surface used by the generic ACP adapter. Protocol details stay in this module. */
20
71
  export interface AcpConnection {
21
72
  request(method: string, params: Readonly<Record<string, unknown>>): Promise<Readonly<Record<string, unknown>>>;
@@ -43,7 +94,13 @@ export type AcpRoleTurnHostConfig = Readonly<{
43
94
  prepare(request: RoleTurnRequest): Promise<PreparedRoleTurn>;
44
95
  }>;
45
96
 
46
- function failure(cause: "activation" | "session" | "output", name: string, code: string, details?: Readonly<Record<string, unknown>>): RoleTurnResult {
97
+ function failure(
98
+ cause: "activation" | "session" | "output",
99
+ name: string,
100
+ code: string,
101
+ details?: Readonly<Record<string, unknown>>,
102
+ diagnostic?: string,
103
+ ): RoleTurnResult {
47
104
  return {
48
105
  code: null,
49
106
  stderr: "",
@@ -51,11 +108,27 @@ function failure(cause: "activation" | "session" | "output", name: string, code:
51
108
  knownFailure: {
52
109
  cause,
53
110
  identity: { name, code },
111
+ ...(diagnostic === undefined ? {} : { diagnostic }),
54
112
  ...(details === undefined ? {} : { details }),
55
113
  },
56
114
  };
57
115
  }
58
116
 
117
+ /** Success→dispose failure; existing failure keeps primary cause + cleanup detail. */
118
+ function withCleanupFailure(outcome: RoleTurnResult, cleanupError: unknown): RoleTurnResult {
119
+ const message = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
120
+ if (outcome.knownFailure === undefined) {
121
+ return failure("session", "AcpDisposeFailure", "dispose-failed", { cleanupError: message }, message);
122
+ }
123
+ return {
124
+ ...outcome,
125
+ knownFailure: {
126
+ ...outcome.knownFailure,
127
+ details: { ...(outcome.knownFailure.details ?? {}), cleanupError: message },
128
+ },
129
+ };
130
+ }
131
+
59
132
  type RpcReply = { readonly id?: unknown; readonly method?: unknown; readonly params?: unknown; readonly result?: unknown; readonly error?: unknown };
60
133
 
61
134
  function acpError(code: string, message: string, cause?: unknown): Error & { readonly code: string } {
@@ -182,10 +255,12 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
182
255
  let connection: AcpConnection | undefined;
183
256
  let sessionId: string | undefined;
184
257
  let accepted = false;
258
+ // Mutable so dispose failure can outrank a clean turn (headless withCleanupFailure face).
259
+ let outcome: RoleTurnResult = failure("session", "AcpNoOutcome", "no-outcome");
185
260
  try {
186
261
  if (prepared.mcpServers.length === 0) {
187
- return failure("activation", "UncontrolledAcpSession", "ak-config-missing");
188
- }
262
+ outcome = failure("activation", "UncontrolledAcpSession", "ak-config-missing");
263
+ } else {
189
264
  connection = await config.connect(request);
190
265
  // Live host-session records: ACP session/update → sitian sole entry (#811).
191
266
  // One abort + one race helper + one outer projection — write failure ends
@@ -214,8 +289,17 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
214
289
  ): Promise<Readonly<Record<string, unknown>>> =>
215
290
  raceAgainstHostAbort(connection!.request(method, params), recordAbort.signal, "host-session-record-failed");
216
291
 
292
+ // #959: navigator free-form agent text — only while session/prompt is in flight.
293
+ // session/load replays history via session/update; those must not enter the bucket
294
+ // (resume / set_model load would otherwise prepend prior turns as "this turn" prose).
295
+ const agentProseChunks: string[] = [];
296
+ let collectAgentProse = false;
217
297
  connection.onNotification?.((method, params) => {
218
298
  if (method !== "session/update" || hostSessionRecordFailure !== undefined) return;
299
+ if (collectAgentProse) {
300
+ const chunk = acpAgentTextChunk(params);
301
+ if (chunk !== undefined) agentProseChunks.push(chunk);
302
+ }
219
303
  try {
220
304
  reportHostSessionEvent({
221
305
  host: config.hostName,
@@ -243,11 +327,11 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
243
327
  if (request.model !== undefined && availableModels !== undefined && !availableModels.some((entry) =>
244
328
  typeof entry === "object" && entry !== null
245
329
  && (entry as { modelId?: unknown }).modelId === acpModelId(config.modelPassing, request.model))) {
246
- return failure("activation", "AcpHostModelMismatch", "host-model-mismatch", {
330
+ outcome = failure("activation", "AcpHostModelMismatch", "host-model-mismatch", {
247
331
  provider: request.model.provider,
248
332
  model: request.model.model,
249
333
  });
250
- }
334
+ } else {
251
335
 
252
336
  const sessionBindParams = {
253
337
  cwd: request.cwd,
@@ -269,15 +353,19 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
269
353
  sessionId = await loadSession(boundSessionId);
270
354
  }
271
355
  }
356
+ let sessionReady = true;
272
357
  if (sessionId === undefined) {
273
358
  const session = await rpc("session/new", sessionBindParams);
274
359
  sessionId = typeof session.sessionId === "string" ? session.sessionId : undefined;
275
360
  if (sessionId === undefined || sessionId === "") {
276
- return failure("session", "AcpSessionFailure", "session-id-missing");
361
+ outcome = failure("session", "AcpSessionFailure", "session-id-missing");
362
+ sessionReady = false;
363
+ } else {
364
+ await config.sessionIdentity.bind(request.principal, sessionId);
277
365
  }
278
- await config.sessionIdentity.bind(request.principal, sessionId);
279
366
  }
280
367
 
368
+ if (sessionReady) {
281
369
  // set_model seat provider:model (#778); may rebuild agent — re-bind via loadSession.
282
370
  if (config.modelPassing === "set_model" && request.model !== undefined && sessionId !== undefined) {
283
371
  await rpc("session/set_model", {
@@ -300,6 +388,9 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
300
388
  if (abortSignal !== undefined) abortParts.push(abortSignal);
301
389
  const combinedAbort = AbortSignal.any(abortParts);
302
390
  let result: Readonly<Record<string, unknown>>;
391
+ // Open the prose gate only for this prompt round; clear any stale chunks first.
392
+ agentProseChunks.length = 0;
393
+ collectAgentProse = prepared.terminatingToolName === NAVIGATOR_OUTPUT_TOOL_NAME;
303
394
  try {
304
395
  result = await raceAgainstHostAbort(
305
396
  activeConnection.request("session/prompt", {
@@ -310,17 +401,33 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
310
401
  "ACP host aborted",
311
402
  );
312
403
  } catch (error) {
404
+ collectAgentProse = false;
405
+ agentProseChunks.length = 0;
313
406
  if (hostSessionRecordFailure !== undefined) {
314
407
  return { status: "terminal", result: hostSessionRecordResult() };
315
408
  }
316
409
  throw error;
317
410
  }
411
+ collectAgentProse = false;
318
412
  if (result.stopReason === "refusal") {
413
+ agentProseChunks.length = 0;
319
414
  return {
320
415
  status: "terminal",
321
416
  result: failure("output", "AcpRefusal", "refusal", { sessionId }),
322
417
  };
323
418
  }
419
+ // #959: navigator prose exit when the model spoke without the output tool.
420
+ // Tool path still wins via MCP; ingest is a no-op once the tool already sealed.
421
+ // Emptiness via shared projector; payload keeps original bytes (LLM 原话过手).
422
+ if (prepared.terminatingToolName === NAVIGATOR_OUTPUT_TOOL_NAME) {
423
+ const prose = agentProseChunks.join("");
424
+ agentProseChunks.length = 0;
425
+ if (navigatorProseFromUnknown(prose) !== undefined) {
426
+ await prepared.ingestStructuredOutput({ prose });
427
+ }
428
+ } else {
429
+ agentProseChunks.length = 0;
430
+ }
324
431
  return { status: "delivered", stderr: activeConnection.stderr?.() ?? "" };
325
432
  },
326
433
  async afterAccepted() {
@@ -328,14 +435,19 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
328
435
  accepted = true;
329
436
  },
330
437
  });
331
- if (hostSessionRecordFailure !== undefined) return hostSessionRecordResult();
332
- return turnResult;
438
+ outcome = hostSessionRecordFailure !== undefined ? hostSessionRecordResult() : turnResult;
439
+ } // sessionReady
440
+ } // model match else
333
441
  } catch (error) {
334
442
  // recordAbort races setup RPCs via raceAgainstHostAbort (host-aborted code);
335
443
  // noteHostSessionRecordFailure always sets the typed failure before aborting.
336
- if (hostSessionRecordFailure !== undefined) return hostSessionRecordResult();
337
- throw error;
444
+ if (hostSessionRecordFailure !== undefined) {
445
+ outcome = hostSessionRecordResult();
446
+ } else {
447
+ throw error;
448
+ }
338
449
  }
450
+ } // mcpServers else
339
451
  } finally {
340
452
  if (connection !== undefined) {
341
453
  if (sessionId !== undefined && !accepted) {
@@ -345,8 +457,12 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
345
457
  try { await connection.close(); }
346
458
  catch { /* keep turn result */ }
347
459
  }
348
- try { await prepared.dispose?.(); }
349
- catch { /* keep turn result */ }
460
+ try {
461
+ await prepared.dispose?.();
462
+ } catch (cleanupError) {
463
+ outcome = withCleanupFailure(outcome, cleanupError);
464
+ }
350
465
  }
466
+ return outcome;
351
467
  });
352
468
  }
@@ -91,11 +91,6 @@ export function activationBookDirectory(ledgerHome: string, bookKey: string): st
91
91
  return join(ledgerHome, "books", bookKey);
92
92
  }
93
93
 
94
- /** Append-only waiting ledger path for one book. */
95
- export function activationWaitingLedgerPath(ledgerHome: string, bookKey: string): string {
96
- return join(activationBookDirectory(ledgerHome, bookKey), "waiting.jsonl");
97
- }
98
-
99
94
  /** True when candidate resolves strictly inside root (boundary-safe; not a string-prefix check). */
100
95
  export function pathContainedIn(root: string, candidate: string): boolean {
101
96
  const rel = relative(root, candidate);
@@ -323,7 +318,7 @@ export function ensureRealDirectoryTree(root: string, targetDir: string): string
323
318
 
324
319
  /**
325
320
  * Reject a pre-existing ledger-file symlink before open/write follows it.
326
- * A computed book may only append to its own regular waiting.jsonl — any symlink,
321
+ * A computed book path may only write its own regular file — any symlink,
327
322
  * including a target still inside the machine ledger home (cross-book redirect),
328
323
  * violates ADR 0048 partition identity. Missing paths are admitted (O_CREAT).
329
324
  */