@akagilnc/pi-workflow-roles 0.1.4528 → 0.1.4620

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 (55) hide show
  1. package/README.md +5 -4
  2. package/README.zh-CN.md +6 -5
  3. package/dist/acp-host/production-host.js +1834 -637
  4. package/dist/archivist-record-topology.js +27 -35
  5. package/dist/headless-host/description.js +7 -4
  6. package/dist/headless-host/production-host.js +1652 -519
  7. package/dist/migrate-book-topology.js +8 -11
  8. package/dist/navigator-attendance.js +146 -241
  9. package/dist/navigator-public-session.js +81 -15
  10. package/dist/package-contracts/navigator-output.js +30 -12
  11. package/dist/public-cli/invocation.js +10 -4
  12. package/dist/public-cli/judge-run.js +2 -2
  13. package/dist/public-cli/main.js +879 -410
  14. package/dist/public-cli/option-definitions.js +6 -6
  15. package/dist/public-cli/post-admission.js +25 -10
  16. package/dist/public-cli/reviewer-run.js +339 -0
  17. package/dist/public-cli/run-lifecycle.js +29 -7
  18. package/dist/public-cli/settlement.js +46 -32
  19. package/dist/public-cli/terminal.js +17 -27
  20. package/dist/public-cli/turn-request.js +1 -1
  21. package/dist/public-role-summons.js +370 -20
  22. package/dist/submission-ledger.js +56 -23
  23. package/package.json +1 -1
  24. package/resources/836-deleted-machine-instruction-inventory.md +2 -0
  25. package/resources/navigator-route-playbook.md +9 -0
  26. package/scripts/build-package.mjs +6 -1
  27. package/src/acp-host/role-turn-host.ts +129 -13
  28. package/src/headless-host/description.ts +17 -7
  29. package/src/headless-host/role-turn-host.ts +42 -11
  30. package/src/host-contracts.ts +0 -1
  31. package/src/navigator-attendance.ts +290 -425
  32. package/src/navigator-public-session.ts +126 -25
  33. package/src/navigator-role.ts +2 -2
  34. package/src/package-contracts/navigator-output.ts +41 -25
  35. package/src/public-cli/coder-run.ts +2 -2
  36. package/src/public-cli/fixer-run.ts +2 -2
  37. package/src/public-cli/invocation.ts +19 -9
  38. package/src/public-cli/judge-run.ts +2 -2
  39. package/src/public-cli/merger-run.ts +2 -2
  40. package/src/public-cli/option-definitions.ts +6 -6
  41. package/src/public-cli/post-admission.ts +41 -10
  42. package/src/public-cli/reviewer-run.ts +238 -53
  43. package/src/public-cli/run-lifecycle.ts +37 -7
  44. package/src/public-cli/settlement.ts +42 -34
  45. package/src/public-cli/terminal.ts +39 -37
  46. package/src/public-cli/turn-request.ts +7 -1
  47. package/src/public-role-summons.ts +544 -22
  48. package/src/reviewer-role.ts +1 -2
  49. package/src/role-envelope.ts +89 -4
  50. package/src/role-runtime.ts +76 -16
  51. package/src/submission-ledger.ts +63 -21
  52. package/dist/public-cli/command-renderer.js +0 -5
  53. package/dist/public-command-renderer.js +0 -29
  54. package/src/public-cli/command-renderer.ts +0 -9
  55. package/src/public-command-renderer.ts +0 -55
@@ -8670,11 +8670,8 @@ var init_navigator_output = __esm({
8670
8670
  navigatorOutputSchema = withTerminatingOutputDeclarations(
8671
8671
  openToolObject(
8672
8672
  typebox_exports.Object({
8673
- status: typebox_exports.Unknown({
8674
- description: "advice \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8"
8675
- }),
8676
- candidates: typebox_exports.Unknown({
8677
- description: "\u6392\u597D\u5E8F\u7684\u8DEF\u7EBF\u5EFA\u8BAE\u6570\u7EC4\uFF0C\u5143\u7D20\u542B next/phase/reason \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8"
8673
+ prose: typebox_exports.Unknown({
8674
+ description: "\u6E38\u5955\u4F7F\u6563\u6587\u5EFA\u8BAE\uFF0C\u539F\u6837\u5448\u73B0\u3002\u4E0D\u8981\u6C42 candidates/next \u7B49\u7ED3\u6784\u5316\u5B57\u6BB5\u3002\u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8"
8678
8675
  })
8679
8676
  })
8680
8677
  )
@@ -14532,12 +14529,12 @@ var init_option_definitions = __esm({
14532
14529
  canonical: "--lens",
14533
14530
  aliases: [],
14534
14531
  valueMetavar: "completeness|correctness",
14535
- required: true,
14532
+ required: false,
14536
14533
  repeatable: false,
14537
14534
  form: "option",
14538
14535
  description: {
14539
- en: "Required single review lens: completeness or correctness (no default).",
14540
- zh: "\u5FC5\u586B\u5355 lens\uFF1Acompleteness \u6216 correctness\uFF08\u65E0\u9ED8\u8BA4\u503C\uFF09\u3002"
14536
+ en: "Optional single-lens override: completeness or correctness; omitted runs both in parallel.",
14537
+ zh: "\u53EF\u9009\u5355 lens \u8986\u76D6\uFF1Acompleteness \u6216 correctness\uFF1B\u7701\u7565\u65F6\u5E76\u884C\u8FD0\u884C\u4E24\u8F74\u3002"
14541
14538
  }
14542
14539
  },
14543
14540
  {
@@ -14743,9 +14740,9 @@ var init_option_definitions = __esm({
14743
14740
  },
14744
14741
  reviewer: {
14745
14742
  command: "reviewer",
14746
- summary: "Fixed-target single-lens review (completeness or correctness).",
14743
+ summary: "Fixed-target parallel two-lens review, with an optional single-lens override.",
14747
14744
  usage: [
14748
- "ak-role reviewer --base <revision> --lens completeness|correctness --authority-ref <ref> [options] <instruction>"
14745
+ "ak-role reviewer --base <revision> [--lens completeness|correctness] --authority-ref <ref> [options] <instruction>"
14749
14746
  ],
14750
14747
  examples: [
14751
14748
  'ak-role reviewer --base main --lens completeness --authority-ref docs/adr/0001.md "Review the branch."',
@@ -14796,7 +14793,7 @@ var init_option_definitions = __esm({
14796
14793
  },
14797
14794
  navigator: {
14798
14795
  command: "navigator",
14799
- summary: "Direct Navigator (\u6E38\u5955\u4F7F) route advice: ordered next-role candidates.",
14796
+ summary: "Direct Navigator (\u6E38\u5955\u4F7F) free-form prose route advice.",
14800
14797
  usage: ["ak-role navigator [options] [instruction]"],
14801
14798
  examples: [
14802
14799
  'ak-role navigator "\u521A\u5B8C\u6210 coder apply \u6536\u655B\uFF0C\u4E0B\u4E00\u6B65\uFF1F"'
@@ -8,7 +8,7 @@ import {
8
8
  NAVIGATOR_INVOCATION_ENTRY,
9
9
  mintNavigatorInvocationId
10
10
  } from "./navigator-invocation-identity.js";
11
- import { PACKAGED_ROLE_REGISTRY, packagedRoleMetadata } from "./packaged-role-registry.js";
11
+ import { PACKAGED_ROLE_REGISTRY } from "./packaged-role-registry.js";
12
12
  import {
13
13
  activationBookDirectory,
14
14
  resolveActivationLedgerHome
@@ -30,9 +30,9 @@ import {
30
30
  writeNavigatorModelSetting
31
31
  } from "./navigator-session-contracts.js";
32
32
  import { sitianReport } from "./sitian-facade.js";
33
- import { renderPublicAkRoleCommand } from "./public-command-renderer.js";
34
33
  import { issueRoot, subjectPath } from "./work-subject-identity.js";
35
34
  import { createReceiptDeliveryPolicy, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, RECEIPT_DELIVERY_PROMPT } from "./receipt-delivery-policy.js";
35
+ import { navigatorProseFromUnknown } from "./package-contracts/navigator-output.js";
36
36
  const NAVIGATOR_EVENT_TYPE = "ak-navigator-attendance";
37
37
  const NAVIGATOR_PREPARE_ACCEPTED_TEXT = "\u6E38\u5955\u4F7F\u51C6\u5907\u5DF2\u63A5\u53D7";
38
38
  function resolveNavigatorAuthorityMaterial(roleInput, fileAuthority) {
@@ -42,15 +42,13 @@ function resolveNavigatorAuthorityMaterial(roleInput, fileAuthority) {
42
42
  }
43
43
  const NAVIGATOR_TARGETS = PACKAGED_ROLE_REGISTRY.map(({ role, phases }) => ({ role, phases }));
44
44
  const prepareSchema = Type.Object({
45
- candidates: Type.Optional(Type.Unknown({
46
- description: "\u65B9\u5411\u5019\u9009\uFF1Bcandidates[].next.role \u5FC5\u586B\uFF0Cphase \u53EF\u9009\uFF0Croute/matches/reason/command \u53EF\u9009\u4E0A\u4E0B\u6587\uFF0C\u975E\u53D7\u7406\u95F8"
45
+ prose: Type.Optional(Type.Unknown({
46
+ description: "\u6E38\u5955\u4F7F\u6563\u6587\u5EFA\u8BAE\uFF0C\u539F\u6837\u5448\u73B0\u3002\u4E0D\u8981\u6C42 candidates/next \u7ED3\u6784\u3002\u975E\u53D7\u7406\u95F8"
47
47
  }))
48
48
  }, { additionalProperties: true });
49
- const ROUTE_ENTRY = "ak-navigator-route";
50
49
  const CONTEXT_ENTRY = "ak-navigator-context";
51
50
  const INVOCATION_ENTRY = NAVIGATOR_INVOCATION_ENTRY;
52
51
  const SETTLEMENT_ENTRY = "ak-navigator-settlement";
53
- const targetRoles = new Set(NAVIGATOR_TARGETS.map(({ role }) => role));
54
52
  const unavailableKeys = /* @__PURE__ */ new Set(["context", "session", "model", "thinking", "auth", "quota", "transport", "unknown"]);
55
53
  function unavailableKey(value) {
56
54
  return typeof value === "string" && unavailableKeys.has(value) ? value : void 0;
@@ -80,73 +78,8 @@ function rejectedPrepareReason(entries, start) {
80
78
  }
81
79
  return reason;
82
80
  }
83
- function targetIsValid(value) {
84
- if (!exactRecord(value) || !targetRoles.has(String(value.role))) return false;
85
- const metadata = packagedRoleMetadata(String(value.role));
86
- return metadata !== void 0 && metadata.phases.includes(value.phase);
87
- }
88
- function normalizeTarget(value) {
89
- if (!exactRecord(value)) return void 0;
90
- const role = typeof value.role === "string" ? value.role.trim() : "";
91
- if (role === "") return void 0;
92
- if (value.phase === void 0 || value.phase === null) {
93
- return { role, phase: null };
94
- }
95
- if (value.phase === "plan" || value.phase === "apply") {
96
- return { role, phase: value.phase };
97
- }
98
- return { role, phase: null };
99
- }
100
- function normalizeMatches(value) {
101
- if (!exactRecord(value)) return void 0;
102
- if (typeof value.role !== "string" || value.role.trim() === "") return void 0;
103
- if (value.kind !== "accepted") return void 0;
104
- let phase;
105
- if (value.phase === void 0 || value.phase === null) phase = null;
106
- else if (value.phase === "plan" || value.phase === "apply") phase = value.phase;
107
- else return void 0;
108
- if (value.statuses !== void 0) {
109
- if (!Array.isArray(value.statuses) || value.statuses.some((status) => typeof status !== "string" || status.trim() === "")) {
110
- return void 0;
111
- }
112
- return {
113
- role: value.role,
114
- phase,
115
- kind: "accepted",
116
- statuses: [...value.statuses]
117
- };
118
- }
119
- return { role: value.role, phase, kind: "accepted" };
120
- }
121
- function normalizeCandidate(value) {
122
- if (!exactRecord(value)) return void 0;
123
- const next = normalizeTarget(value.next);
124
- const route = Array.isArray(value.route) ? value.route.map(normalizeTarget).filter((target) => target !== void 0) : void 0;
125
- const matches = normalizeMatches(value.matches);
126
- const id = typeof value.id === "string" && value.id.trim() !== "" ? value.id : void 0;
127
- const reason = typeof value.reason === "string" && value.reason.trim() !== "" ? value.reason : void 0;
128
- const command = typeof value.command === "string" ? value.command : void 0;
129
- return {
130
- ...id === void 0 ? {} : { id },
131
- ...matches === void 0 ? {} : { matches },
132
- ...route === void 0 || route.length === 0 ? {} : { route },
133
- ...next === void 0 ? {} : { next },
134
- ...reason === void 0 ? {} : { reason },
135
- ...command === void 0 ? {} : { command }
136
- };
137
- }
138
- function normalizePrepareOutput(value) {
139
- if (!exactRecord(value) || !Array.isArray(value.candidates)) return [];
140
- return value.candidates.map(normalizeCandidate).filter((candidate) => candidate !== void 0);
141
- }
142
- function routeEqual(a, b) {
143
- return a !== void 0 && a.length === b.length && a.every((target, index) => target.role === b[index].role && target.phase === b[index].phase);
144
- }
145
- function routeText(route) {
146
- return route.map((target) => target.phase === null ? target.role : `${target.role} ${target.phase}`).join(" \u2192 ");
147
- }
148
- function targetText(target) {
149
- return target.phase === null ? target.role : `${target.role} ${target.phase}`;
81
+ function normalizePrepareProse(value) {
82
+ return navigatorProseFromUnknown(value);
150
83
  }
151
84
  function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
152
85
  if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
@@ -168,7 +101,7 @@ function createNavigatorPrepareTool(onOutput) {
168
101
  return {
169
102
  name: NAVIGATOR_PREPARE_TOOL_NAME,
170
103
  label: "\u6E38\u5955\u4F7F\u51C6\u5907",
171
- description: "\u63D0\u4EA4\u6E38\u5955\u4F7F\u65B9\u5411\u5EFA\u8BAE\u3002",
104
+ description: "\u63D0\u4EA4\u6E38\u5955\u4F7F\u6563\u6587\u5EFA\u8BAE\u3002",
172
105
  parameters: prepareSchema,
173
106
  async execute(_id, value) {
174
107
  onOutput(value);
@@ -176,34 +109,6 @@ function createNavigatorPrepareTool(onOutput) {
176
109
  }
177
110
  };
178
111
  }
179
- function selectNavigatorCandidate(candidates, settlement) {
180
- if (settlement.kind !== "accepted") return void 0;
181
- const usable = candidates.filter((candidate) => candidate.next !== void 0);
182
- if (usable.length === 0) return void 0;
183
- const rolePhaseMatched = usable.filter(
184
- (candidate) => candidate.matches !== void 0 && candidate.matches.role === settlement.role && candidate.matches.phase === settlement.phase
185
- );
186
- if (rolePhaseMatched.length > 0) {
187
- if (settlement.status !== void 0) {
188
- const statusSpecific = rolePhaseMatched.find(
189
- (candidate) => candidate.matches?.statuses !== void 0 && candidate.matches.statuses.includes(settlement.status)
190
- );
191
- if (statusSpecific !== void 0) {
192
- return { candidate: statusSpecific, matchedToSettlement: true };
193
- }
194
- }
195
- const rolePhaseGeneric = rolePhaseMatched.find(
196
- (candidate) => candidate.matches?.statuses === void 0
197
- );
198
- if (rolePhaseGeneric !== void 0) {
199
- return { candidate: rolePhaseGeneric, matchedToSettlement: true };
200
- }
201
- return void 0;
202
- }
203
- const unbound = usable.find((candidate) => candidate.matches === void 0);
204
- if (unbound === void 0) return void 0;
205
- return { candidate: unbound, matchedToSettlement: false };
206
- }
207
112
  function formatNavigatorReport(report) {
208
113
  const playbookFailure = report.routePlaybookReadFailure === void 0 ? [] : [`\u8DEF\u4E66\u8BFB\u53D6\u5931\u8D25\uFF1A${report.routePlaybookReadFailure}`];
209
114
  if (report.disposition === "no-advice") return playbookFailure.join("\n");
@@ -213,42 +118,24 @@ function formatNavigatorReport(report) {
213
118
  if (report.disposition === "arrival") {
214
119
  return [...playbookFailure, ...report.arrivalMessage ? [report.arrivalMessage] : []].join("\n");
215
120
  }
216
- return [
217
- ...playbookFailure,
218
- ...report.route === void 0 ? [] : [`\u8DEF\u7EBF\uFF1A${routeText(report.route)}`],
219
- ...report.next === void 0 ? [] : [`\u4E0B\u4E00\u6B65\uFF1A${targetText(report.next)}`],
220
- ...report.reason === void 0 || report.reason.trim() === "" ? [] : [`\u7406\u7531\uFF1A${report.reason}`],
221
- ...report.command === void 0 || report.command.trim() === "" ? [] : [`\u547D\u4EE4\uFF1A${report.command}`]
222
- ].join("\n");
223
- }
224
- function settlementNavigationFromEvent(event) {
225
- if (event.disposition !== "recommendation") return void 0;
226
- if (event.next === void 0) return void 0;
227
- return {
228
- disposition: "recommendation",
229
- ...event.route === void 0 ? {} : { route: event.route },
230
- next: event.next,
231
- ...event.reason === void 0 ? {} : { reason: event.reason },
232
- ...event.command === void 0 ? {} : { command: event.command }
233
- };
121
+ return [...playbookFailure, ...report.prose ? [report.prose] : []].join("\n");
234
122
  }
235
123
  function createNavigatorAttendance(options) {
236
124
  let preparation;
125
+ let preparationInFlight = false;
237
126
  let sessionReady;
238
127
  let session;
239
128
  let subjectKey = options.subjectKey;
240
129
  let subject = options.subject;
241
130
  let authority = options.authority;
242
131
  let contextError = options.contextError;
243
- let candidates;
132
+ let preparedProse;
244
133
  const invocationPrincipal = options.invocationId ?? mintNavigatorInvocationId();
245
134
  let activeInvocationId = invocationPrincipal;
246
- let previousRoute;
247
135
  let outputSink;
248
136
  let settlementTail = Promise.resolve();
249
137
  let settlementFailure;
250
138
  let preparationFailure;
251
- let preparationNoReceipt = false;
252
139
  let routePlaybookReadFailure;
253
140
  let disposed = false;
254
141
  let warmedHelp;
@@ -275,12 +162,7 @@ function createNavigatorAttendance(options) {
275
162
  };
276
163
  let routePlaybookSettlement;
277
164
  let prepareBoundSettlement;
278
- const prepare = async () => {
279
- const boundSettlement = prepareBoundSettlement;
280
- prepareBoundSettlement = void 0;
281
- preparationNoReceipt = false;
282
- const invocationId = invocationPrincipal;
283
- activeInvocationId = invocationId;
165
+ const loadMaterialsAndSession = async (invocationId) => {
284
166
  if (contextError !== void 0) throw navigatorUnavailableError("context", contextError);
285
167
  if (typeof authority !== "string" || authority.trim() === "") {
286
168
  throw navigatorUnavailableError(
@@ -338,21 +220,6 @@ function createNavigatorAttendance(options) {
338
220
  const helpContext = help.map(({ role, help: text }) => `<role_help role="${role}">
339
221
  ${text}
340
222
  </role_help>`).join("\n");
341
- let output;
342
- let prepareBatchRejected = false;
343
- outputSink = (value) => {
344
- if (output === void 0) {
345
- output = value;
346
- return;
347
- }
348
- const prior2 = output.candidates;
349
- const next = value.candidates;
350
- const merged = [
351
- ...Array.isArray(prior2) ? prior2 : prior2 === void 0 ? [] : [prior2],
352
- ...Array.isArray(next) ? next : next === void 0 ? [] : [next]
353
- ];
354
- output = { ...value, candidates: merged };
355
- };
356
223
  const tool = createNavigatorPrepareTool((value) => {
357
224
  outputSink?.(value);
358
225
  });
@@ -360,7 +227,12 @@ ${text}
360
227
  sessionReady = (async () => {
361
228
  let created;
362
229
  try {
363
- created = await options.createSession({ context: options.context, subject: subjectKey, ...options.modelSettingPath === void 0 ? {} : { modelSettingPath: options.modelSettingPath }, tool });
230
+ created = await options.createSession({
231
+ context: options.context,
232
+ subject: subjectKey,
233
+ ...options.modelSettingPath === void 0 ? {} : { modelSettingPath: options.modelSettingPath },
234
+ tool
235
+ });
364
236
  } catch (error) {
365
237
  throw navigatorUnavailableError("session", error);
366
238
  }
@@ -391,12 +263,27 @@ ${text}
391
263
  session.appendEntry(INVOCATION_ENTRY, { invocationId, role: options.role, phase: options.phase, subjectKey });
392
264
  }
393
265
  if (disposed) throw navigatorUnavailableError("session", new Error("Navigator attendance was disposed"));
394
- const activeSession = session;
395
- if (activeSession === void 0) throw new Error("Navigator session was not created");
396
- const prior = activeSession.entries().filter((entry) => exactRecord(entry) && entry.type === "custom" && entry.customType === ROUTE_ENTRY && exactRecord(entry.data) && entry.data.subjectKey === subjectKey).at(-1)?.data;
397
- if (exactRecord(prior) && Array.isArray(prior.route) && prior.route.every((target) => targetIsValid(target))) {
398
- previousRoute = prior.route.map((target) => ({ role: target.role, phase: target.phase }));
399
- }
266
+ if (session === void 0) throw new Error("Navigator session was not created");
267
+ return { soul, routePlaybook, helpContext, modelSetting, model, help, activeSession: session };
268
+ };
269
+ const prepare = async (materialsBundle) => {
270
+ const boundSettlement = prepareBoundSettlement;
271
+ prepareBoundSettlement = void 0;
272
+ const invocationId = invocationPrincipal;
273
+ activeInvocationId = invocationId;
274
+ let output;
275
+ let prepareBatchRejected = false;
276
+ outputSink = (value) => {
277
+ if (output === void 0) {
278
+ output = value;
279
+ return;
280
+ }
281
+ const prior = normalizePrepareProse(output) ?? "";
282
+ const next = normalizePrepareProse(value) ?? "";
283
+ const merged = [prior, next].filter((part) => part.trim() !== "").join("\n\n");
284
+ output = { prose: merged };
285
+ };
286
+ const { soul, routePlaybook, helpContext, help, activeSession } = materialsBundle ?? await loadMaterialsAndSession(invocationId);
400
287
  const publicSettlementHistory = activeSession.entries().filter((entry) => exactRecord(entry) && entry.type === "custom" && entry.customType === SETTLEMENT_ENTRY && exactRecord(entry.data)).map((entry) => entry.data);
401
288
  const projection = {
402
289
  subjectKey,
@@ -404,13 +291,12 @@ ${text}
404
291
  authority,
405
292
  currentRole: { role: options.role, phase: options.phase },
406
293
  ...boundSettlement === void 0 ? {} : { currentSettlement: boundSettlement },
407
- priorRoute: exactRecord(prior) && Array.isArray(prior.route) && prior.route.every((target) => targetIsValid(target)) ? prior.route.map((target) => ({ role: target.role, phase: target.phase })) : null,
408
294
  publicSettlementHistory,
409
295
  liveRoleHelp: help
410
296
  };
411
297
  activeSession.appendEntry(CONTEXT_ENTRY, projection);
412
- const request = [
413
- "\u672C\u6B21\u5BFC\u822A\u6750\u6599\u5982\u4E0B\uFF1A",
298
+ const request = boundSettlement === void 0 ? [
299
+ "\u672C\u8F6E\u4E3A\u5F85\u547D\u8F6E\u3002",
414
300
  `<navigator_soul>
415
301
  ${soul}
416
302
  </navigator_soul>`,
@@ -426,12 +312,32 @@ ${authority}
426
312
  `<current_role>
427
313
  ${JSON.stringify({ role: options.role, phase: options.phase })}
428
314
  </current_role>`,
429
- ...boundSettlement === void 0 ? [] : [`<current_settlement>
315
+ `<public_settlement_history>
316
+ ${JSON.stringify(projection.publicSettlementHistory)}
317
+ </public_settlement_history>`,
318
+ `<live_role_help>
319
+ ${helpContext}
320
+ </live_role_help>`
321
+ ].join("\n\n") : [
322
+ "\u672C\u8F6E\u4E3A\u7ED3\u7B97\u6295\u5582\u8F6E\u3002",
323
+ `<navigator_soul>
324
+ ${soul}
325
+ </navigator_soul>`,
326
+ ...routePlaybookReadFailure === void 0 ? [`<route_playbook>
327
+ ${routePlaybook}
328
+ </route_playbook>`] : ["\u53EF\u9009\u8DEF\u7EBF\u624B\u518C\u672A\u80FD\u8BFB\u53D6\u3002"],
329
+ `<work_subject>
330
+ ${subject}
331
+ </work_subject>`,
332
+ `<controlling_authority>
333
+ ${authority}
334
+ </controlling_authority>`,
335
+ `<current_role>
336
+ ${JSON.stringify({ role: options.role, phase: options.phase })}
337
+ </current_role>`,
338
+ `<current_settlement>
430
339
  ${JSON.stringify(boundSettlement)}
431
- </current_settlement>`],
432
- `<prior_route>
433
- ${JSON.stringify(prior ?? null)}
434
- </prior_route>`,
340
+ </current_settlement>`,
435
341
  `<public_settlement_history>
436
342
  ${JSON.stringify(projection.publicSettlementHistory)}
437
343
  </public_settlement_history>`,
@@ -472,20 +378,30 @@ ${helpContext}
472
378
  if (deliveryRequest && output === void 0) delivery.recordDeliveryRequest();
473
379
  };
474
380
  await promptAllowingRejectedPrepare(request, false);
475
- while (output === void 0 && delivery.nextAction() === "request-delivery") {
476
- await promptAllowingRejectedPrepare(RECEIPT_DELIVERY_PROMPT, true);
477
- }
478
- if (output === void 0 && delivery.nextAction() === "no-receipt" && activeSession.providerFailure?.() === void 0) {
479
- const facts = delivery.facts({ runPointer: activeSession.recordPointer(), attemptPointer: invocationId });
480
- activeSession.appendEntry(NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, facts);
481
- preparationNoReceipt = true;
482
- candidates = [];
483
- return candidates;
381
+ if (boundSettlement !== void 0) {
382
+ while (output === void 0 && prepareBatchRejected && delivery.nextAction() === "request-delivery") {
383
+ await promptAllowingRejectedPrepare(RECEIPT_DELIVERY_PROMPT, true);
384
+ }
385
+ if (output === void 0 && delivery.nextAction() === "request-delivery") {
386
+ while (delivery.nextAction() === "request-delivery") {
387
+ delivery.recordDeliveryRequest();
388
+ }
389
+ }
390
+ if (output === void 0 && delivery.nextAction() === "no-receipt" && activeSession.providerFailure?.() === void 0) {
391
+ const facts = delivery.facts({ runPointer: activeSession.recordPointer(), attemptPointer: invocationId });
392
+ activeSession.appendEntry(NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, facts);
393
+ preparedProse = void 0;
394
+ return void 0;
395
+ }
484
396
  }
485
397
  } catch (error) {
486
398
  throw error instanceof NavigatorUnavailableError ? error : navigatorUnavailableError("transport", error);
487
399
  }
488
400
  if (output === void 0) {
401
+ if (boundSettlement === void 0) {
402
+ preparedProse = void 0;
403
+ return void 0;
404
+ }
489
405
  const nativeFailure = [...activeSession.entries()].reverse().find((entry) => {
490
406
  if (!exactRecord(entry) || entry.type !== "message" || !exactRecord(entry.message)) return false;
491
407
  return entry.message.role === "assistant" && typeof entry.message.errorMessage === "string" && entry.message.errorMessage.trim() !== "";
@@ -497,8 +413,12 @@ ${helpContext}
497
413
  const cause = providerFailure?.cause ?? source;
498
414
  throw navigatorUnavailableError(source, errorMessage, cause);
499
415
  }
500
- candidates = normalizePrepareOutput(output);
501
- return candidates;
416
+ if (boundSettlement === void 0) {
417
+ preparedProse = void 0;
418
+ return void 0;
419
+ }
420
+ preparedProse = normalizePrepareProse(output);
421
+ return preparedProse;
502
422
  } finally {
503
423
  outputSink = void 0;
504
424
  }
@@ -509,7 +429,6 @@ ${helpContext}
509
429
  if (next.subjectKey !== subjectKey && session !== void 0) {
510
430
  const previous = session;
511
431
  session = void 0;
512
- previousRoute = void 0;
513
432
  closing = previous.dispose();
514
433
  }
515
434
  subjectKey = next.subjectKey;
@@ -531,13 +450,16 @@ ${helpContext}
531
450
  prepare() {
532
451
  if (disposed || preparation !== void 0) return;
533
452
  preparationFailure = void 0;
534
- preparation = prepare();
453
+ preparationInFlight = true;
454
+ preparation = prepare().finally(() => {
455
+ preparationInFlight = false;
456
+ });
535
457
  void preparation.catch((error) => {
536
458
  preparationFailure = error;
537
459
  });
538
460
  },
539
461
  isPreparing() {
540
- return preparation !== void 0 || sessionReady !== void 0;
462
+ return preparationInFlight;
541
463
  },
542
464
  knownRoutePlaybookReadFailure() {
543
465
  return routePlaybookReadFailure;
@@ -561,81 +483,70 @@ ${helpContext}
561
483
  if (disposed) return;
562
484
  const invocationId = activeInvocationId ?? invocationPrincipal;
563
485
  let report;
564
- if (settlement.kind === "human_decision" || settlement.kind === "role_infrastructure_failure") {
565
- if (sessionReady !== void 0) {
566
- try {
567
- await sessionReady;
568
- } catch (error) {
569
- preparationFailure ??= error;
570
- }
486
+ if (sessionReady !== void 0) {
487
+ try {
488
+ await sessionReady;
489
+ } catch (error) {
490
+ preparationFailure ??= error;
571
491
  }
572
- if (preparation !== void 0) {
573
- try {
574
- await preparation;
575
- } catch (error) {
576
- preparationFailure ??= error;
577
- }
492
+ }
493
+ if (preparation !== void 0) {
494
+ try {
495
+ await preparation;
496
+ } catch (error) {
497
+ preparationFailure ??= error;
578
498
  }
579
- session?.appendEntry(SETTLEMENT_ENTRY, { invocationId, subjectKey, role: settlement.role, phase: settlement.phase, kind: settlement.kind, ...settlement.kind === "human_decision" ? { status: settlement.status } : {} });
499
+ preparation = void 0;
500
+ }
501
+ const settlementFact = {
502
+ invocationId,
503
+ subjectKey,
504
+ role: settlement.role,
505
+ phase: settlement.phase,
506
+ kind: settlement.kind,
507
+ ..."status" in settlement && settlement.status !== void 0 ? { status: settlement.status } : {}
508
+ };
509
+ let drainedProse;
510
+ if (settlement.kind === "arrival") {
511
+ session?.appendEntry(SETTLEMENT_ENTRY, settlementFact);
580
512
  if (preparationFailure !== void 0) {
581
513
  report = unavailable(invocationId, preparationFailure);
582
514
  } else {
583
- report = { disposition: "no-advice" };
515
+ report = {
516
+ disposition: "arrival",
517
+ ...settlement.message === void 0 ? {} : { arrivalMessage: settlement.message }
518
+ };
584
519
  }
585
- } else if (settlement.kind === "arrival") {
586
- if (sessionReady !== void 0) {
520
+ } else {
521
+ if (session !== void 0) preparationFailure = void 0;
522
+ let coldMaterials;
523
+ if (session === void 0 && preparationFailure === void 0) {
587
524
  try {
588
- await sessionReady;
525
+ coldMaterials = await loadMaterialsAndSession(invocationId);
589
526
  } catch (error) {
590
- preparationFailure ??= error;
527
+ preparationFailure = error;
591
528
  }
592
529
  }
593
- if (preparation !== void 0) {
530
+ session?.appendEntry(SETTLEMENT_ENTRY, settlementFact);
531
+ if (preparationFailure === void 0) {
532
+ prepareBoundSettlement = settlement;
533
+ preparation = prepare(coldMaterials);
534
+ void preparation.catch((error) => {
535
+ preparationFailure = error;
536
+ });
594
537
  try {
595
- await preparation;
538
+ drainedProse = await preparation;
596
539
  } catch (error) {
597
540
  preparationFailure ??= error;
598
541
  }
542
+ preparation = void 0;
599
543
  }
600
- report = preparationFailure === void 0 ? { disposition: "arrival", ...settlement.message === void 0 ? {} : { arrivalMessage: settlement.message } } : unavailable(invocationId, preparationFailure);
601
- } else if (preparation === void 0) {
602
- report = unavailable(invocationId, "Navigator preparation did not start");
603
- } else {
604
- try {
605
- if (sessionReady !== void 0) await sessionReady;
606
- let prepared = await preparation;
607
- session?.appendEntry(SETTLEMENT_ENTRY, { invocationId, subjectKey, role: settlement.role, phase: settlement.phase, kind: settlement.kind, ...settlement.status === void 0 ? {} : { status: settlement.status } });
608
- let selected = selectNavigatorCandidate(prepared, settlement);
609
- if (selected?.candidate.next !== void 0 && !selected.matchedToSettlement) {
610
- if (disposed) return;
611
- prepareBoundSettlement = settlement;
612
- prepared = await prepare();
613
- if (disposed) return;
614
- selected = selectNavigatorCandidate(prepared, settlement);
615
- }
616
- const selectedCandidate = selected?.candidate;
617
- if (selectedCandidate?.next === void 0 && preparationNoReceipt) {
618
- report = { disposition: "no-advice" };
619
- } else if (selectedCandidate?.next === void 0) {
620
- throw new Error("Navigator prepared no machine-usable next direction");
621
- } else {
622
- const selectedRoute = selectedCandidate.route;
623
- const routeChanged = selectedRoute !== void 0 && !routeEqual(previousRoute, selectedRoute);
624
- const command = typeof selectedCandidate.command === "string" && selectedCandidate.command.trim() !== "" ? selectedCandidate.command : renderPublicAkRoleCommand(selectedCandidate.next);
625
- report = {
626
- disposition: "recommendation",
627
- ...routeChanged ? { route: selectedRoute } : {},
628
- next: selectedCandidate.next,
629
- ...selectedCandidate.reason === void 0 ? {} : { reason: selectedCandidate.reason },
630
- ...command === void 0 ? {} : { command }
631
- };
632
- if (selectedRoute !== void 0) {
633
- previousRoute = selectedRoute;
634
- session?.appendEntry(ROUTE_ENTRY, { invocationId, subjectKey, route: selectedRoute });
635
- }
636
- }
637
- } catch (error) {
638
- report = unavailable(invocationId, error);
544
+ if (preparationFailure !== void 0) {
545
+ report = unavailable(invocationId, preparationFailure);
546
+ } else if (typeof drainedProse === "string" && drainedProse.trim() !== "") {
547
+ report = { disposition: "advice", prose: drainedProse };
548
+ } else {
549
+ report = { disposition: "no-advice" };
639
550
  }
640
551
  }
641
552
  await routePlaybookSettlement;
@@ -649,10 +560,7 @@ ${helpContext}
649
560
  role: options.role,
650
561
  phase: options.phase,
651
562
  subjectKey,
652
- ...report.route === void 0 ? {} : { route: report.route },
653
- ...report.next === void 0 ? {} : { next: report.next },
654
- ...report.reason === void 0 ? {} : { reason: report.reason },
655
- ...report.command === void 0 ? {} : { command: report.command },
563
+ ...report.prose === void 0 ? {} : { prose: report.prose },
656
564
  ...report.unavailableReason === void 0 ? {} : { unavailableReason: report.unavailableReason },
657
565
  ...report.unavailableSource === void 0 ? {} : { unavailableSource: report.unavailableSource },
658
566
  ...report.unavailableCause === void 0 ? {} : { unavailableCause: report.unavailableCause },
@@ -668,9 +576,8 @@ ${helpContext}
668
576
  }
669
577
  preparation = void 0;
670
578
  sessionReady = void 0;
671
- candidates = void 0;
579
+ preparedProse = void 0;
672
580
  preparationFailure = void 0;
673
- preparationNoReceipt = false;
674
581
  routePlaybookSettlement = void 0;
675
582
  routePlaybookReadFailure = void 0;
676
583
  }
@@ -707,8 +614,6 @@ export {
707
614
  registerNavigatorModelCommand,
708
615
  resolveNavigatorAuthorityMaterial,
709
616
  resolveNavigatorSeatSelection,
710
- selectNavigatorCandidate,
711
- settlementNavigationFromEvent,
712
617
  subjectPath,
713
618
  writeNavigatorModelSetting
714
619
  };