@akagilnc/pi-workflow-roles 0.1.5663 → 0.1.5671

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.
@@ -649,27 +649,61 @@ var init_gatekeeper_output = __esm({
649
649
  var navigator_output_exports = {};
650
650
  __export(navigator_output_exports, {
651
651
  NAVIGATOR_OUTPUT_TOOL_NAME: () => NAVIGATOR_OUTPUT_TOOL_NAME,
652
+ byStatusToPlainObject: () => byStatusToPlainObject,
653
+ mergePreparedAdvice: () => mergePreparedAdvice,
654
+ navigatorAdviceBodySchema: () => navigatorAdviceBodySchema,
655
+ navigatorAdviceFields: () => navigatorAdviceFields,
652
656
  navigatorOutputSchema: () => navigatorOutputSchema,
653
657
  navigatorProseFromUnknown: () => navigatorProseFromUnknown,
658
+ pickPreparedProse: () => pickPreparedProse,
659
+ preparedAdviceFromUnknown: () => preparedAdviceFromUnknown,
654
660
  projectLawfulNavigatorOutput: () => projectLawfulNavigatorOutput,
655
661
  validateRecordedNavigatorOutput: () => validateRecordedNavigatorOutput
656
662
  });
657
663
  import { Type as Type6 } from "typebox";
664
+ function nonEmptyProse(value) {
665
+ if (typeof value === "string") {
666
+ return value.trim() === "" ? void 0 : value;
667
+ }
668
+ if (value === void 0 || value === null) return void 0;
669
+ if (typeof value === "object") {
670
+ const text2 = JSON.stringify(value);
671
+ if (text2 === void 0 || text2.trim() === "" || text2 === "{}" || text2 === "[]") return void 0;
672
+ return text2;
673
+ }
674
+ const text = String(value);
675
+ return text.trim() === "" ? void 0 : text;
676
+ }
677
+ function setStatusProse(target, key, prose) {
678
+ const prior = target.get(key);
679
+ target.set(key, prior === void 0 ? prose : `${prior}
680
+
681
+ ${prose}`);
682
+ }
683
+ function byStatusFromUnknown(value) {
684
+ const out = /* @__PURE__ */ new Map();
685
+ if (!isRecord(value)) return out;
686
+ for (const [key, raw] of Object.entries(value)) {
687
+ const prose = nonEmptyProse(raw);
688
+ if (prose !== void 0) out.set(key, prose);
689
+ }
690
+ return out;
691
+ }
692
+ function byStatusToPlainObject(byStatus) {
693
+ return Object.fromEntries(byStatus);
694
+ }
658
695
  function projectLawfulNavigatorOutput(value) {
659
696
  if (value === void 0 || value === null) return void 0;
660
697
  if (typeof value === "string") return { prose: value };
661
698
  if (isRecord(value)) {
662
699
  if (typeof value.prose === "string") return { prose: value.prose };
663
700
  if (value.prose !== void 0 && value.prose !== null) {
664
- return { prose: typeof value.prose === "string" ? value.prose : String(value.prose) };
701
+ const serialized = nonEmptyProse(value.prose);
702
+ if (serialized !== void 0) return { prose: serialized };
665
703
  }
666
704
  const keys = Object.keys(value);
667
705
  if (keys.length === 0) return { prose: "" };
668
- try {
669
- return { prose: JSON.stringify(value) };
670
- } catch {
671
- return { prose: String(value) };
672
- }
706
+ return { prose: JSON.stringify(value) };
673
707
  }
674
708
  return { prose: String(value) };
675
709
  }
@@ -686,7 +720,58 @@ function navigatorProseFromUnknown(value) {
686
720
  const trimmed = projected.prose.trim();
687
721
  return trimmed === "" ? void 0 : projected.prose;
688
722
  }
689
- var NAVIGATOR_OUTPUT_TOOL_NAME, navigatorOutputSchema;
723
+ function preparedAdviceFromUnknown(value) {
724
+ if (value === void 0 || value === null) return void 0;
725
+ if (typeof value === "string") {
726
+ const prose2 = nonEmptyProse(value);
727
+ return prose2 === void 0 ? void 0 : { byStatus: /* @__PURE__ */ new Map(), prose: prose2 };
728
+ }
729
+ if (!isRecord(value)) {
730
+ const prose2 = nonEmptyProse(value);
731
+ return prose2 === void 0 ? void 0 : { byStatus: /* @__PURE__ */ new Map(), prose: prose2 };
732
+ }
733
+ const byStatus = byStatusFromUnknown(value.byStatus);
734
+ const hasProseField = Object.prototype.hasOwnProperty.call(value, "prose");
735
+ const hasByStatusField = Object.prototype.hasOwnProperty.call(value, "byStatus");
736
+ const prose = nonEmptyProse(value.prose);
737
+ if (byStatus.size === 0 && prose === void 0) {
738
+ if (hasProseField || hasByStatusField) return void 0;
739
+ const keys = Object.keys(value);
740
+ if (keys.length === 0) return void 0;
741
+ const text = JSON.stringify(value);
742
+ return text.trim() === "" || text === "{}" ? void 0 : { byStatus: /* @__PURE__ */ new Map(), prose: text };
743
+ }
744
+ return {
745
+ byStatus,
746
+ ...prose === void 0 ? {} : { prose }
747
+ };
748
+ }
749
+ function mergePreparedAdvice(prior, next) {
750
+ if (prior === void 0) return next;
751
+ if (next === void 0) return prior;
752
+ const byStatus = new Map(prior.byStatus);
753
+ for (const [key, prose2] of next.byStatus) {
754
+ setStatusProse(byStatus, key, prose2);
755
+ }
756
+ const proseParts = [prior.prose, next.prose].filter((part) => typeof part === "string" && part.trim() !== "");
757
+ const prose = proseParts.length === 0 ? void 0 : proseParts.join("\n\n");
758
+ if (byStatus.size === 0 && prose === void 0) return void 0;
759
+ return {
760
+ byStatus,
761
+ ...prose === void 0 ? {} : { prose }
762
+ };
763
+ }
764
+ function pickPreparedProse(prepared, status) {
765
+ if (prepared === void 0) return void 0;
766
+ if (prepared.byStatus.size > 0) {
767
+ if (status === void 0) return void 0;
768
+ const hit = prepared.byStatus.get(status);
769
+ return typeof hit === "string" && hit.trim() !== "" ? hit : void 0;
770
+ }
771
+ const prose = prepared.prose;
772
+ return typeof prose === "string" && prose.trim() !== "" ? prose : void 0;
773
+ }
774
+ var NAVIGATOR_OUTPUT_TOOL_NAME, navigatorAdviceFields, navigatorAdviceBodySchema, navigatorOutputSchema;
690
775
  var init_navigator_output = __esm({
691
776
  "src/package-contracts/navigator-output.ts"() {
692
777
  "use strict";
@@ -694,15 +779,16 @@ var init_navigator_output = __esm({
694
779
  init_open_tool_schema();
695
780
  init_terminating_infrastructure();
696
781
  NAVIGATOR_OUTPUT_TOOL_NAME = "ak_navigator_output";
697
- navigatorOutputSchema = withTerminatingOutputDeclarations(
698
- openToolObject(
699
- Type6.Object({
700
- prose: Type6.Unknown({
701
- 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"
702
- })
703
- })
704
- )
705
- );
782
+ navigatorAdviceFields = {
783
+ prose: Type6.Unknown({
784
+ description: "\u5355\u6761\u6563\u6587\u5EFA\u8BAE\u3002\u65E0\u72B6\u6001\u5206\u53C9\u65F6\u4F7F\u7528\uFF1B\u539F\u6837\u5448\u73B0\u3002"
785
+ }),
786
+ byStatus: Type6.Unknown({
787
+ description: "\u6309\u4E3B\u8859\u95E8\u7ED3\u5C40 status \u9884\u5199\u7684\u6563\u6587\u5EFA\u8BAE\u3002\u952E\u4E3A status \u5B57\u9762\u91CF\uFF0C\u503C\u4E3A\u5EFA\u8BAE\u6B63\u6587\u3002\u7ED3\u7B97\u65F6\u4EE3\u7801\u53EA\u6309\u5B9E\u9645 status \u53D6\u5BF9\u5E94\u539F\u6587\uFF0C\u4E0D\u89E3\u6790\u5EFA\u8BAE\u8BED\u4E49\u3002"
788
+ })
789
+ };
790
+ navigatorAdviceBodySchema = openToolObject(Type6.Object(navigatorAdviceFields));
791
+ navigatorOutputSchema = withTerminatingOutputDeclarations(navigatorAdviceBodySchema);
706
792
  }
707
793
  });
708
794
 
@@ -12310,6 +12396,7 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
12310
12396
  ...options.courtAttemptId === void 0 || options.courtAttemptId.length === 0 ? {} : { courtAttemptId: options.courtAttemptId },
12311
12397
  ...options.invocationScopeId === void 0 || options.invocationScopeId.length === 0 ? {} : { invocationScopeId: options.invocationScopeId },
12312
12398
  ...options.stationChild === void 0 ? {} : { stationChild: options.stationChild },
12399
+ ...options.navigatorByStatusPrepare === void 0 ? {} : { navigatorByStatusPrepare: options.navigatorByStatusPrepare },
12313
12400
  ...options.deliveryRequestLimit === void 0 ? {} : { deliveryRequestLimit: options.deliveryRequestLimit }
12314
12401
  };
12315
12402
  }
@@ -13285,6 +13372,9 @@ async function dispatchPostAdmissionTurn(input) {
13285
13372
  if (env.stationChild !== void 0) {
13286
13373
  turnRequest = { ...turnRequest, stationChild: env.stationChild };
13287
13374
  }
13375
+ if (env.navigatorByStatusPrepare === true) {
13376
+ turnRequest = { ...turnRequest, navigatorByStatusPrepare: true };
13377
+ }
13288
13378
  if (typeof env.host === "string" && env.host.trim() !== "") {
13289
13379
  turnRequest = { ...turnRequest, host: env.host.trim() };
13290
13380
  }
@@ -13543,6 +13633,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
13543
13633
  prompt
13544
13634
  },
13545
13635
  ...env.stationChild === void 0 ? {} : { stationChild: env.stationChild },
13636
+ ...env.navigatorByStatusPrepare === true ? { navigatorByStatusPrepare: true } : {},
13546
13637
  // #1132: one configured ceiling, already resolved by the caller (#422).
13547
13638
  deliveryRequestLimit: deliveryLimitFromConfig(env.autoResumeLimit)
13548
13639
  };
@@ -13555,6 +13646,7 @@ function roleTurnOptions(env, admitted, continuation) {
13555
13646
  ...correlationId === void 0 || correlationId.trim() === "" ? {} : { correlationId },
13556
13647
  continuation,
13557
13648
  ...env.stationChild === void 0 ? {} : { stationChild: env.stationChild },
13649
+ ...env.navigatorByStatusPrepare === true ? { navigatorByStatusPrepare: true } : {},
13558
13650
  // #1132: one configured ceiling, already resolved by the caller (#422).
13559
13651
  deliveryRequestLimit: deliveryLimitFromConfig(env.autoResumeLimit)
13560
13652
  };
@@ -18789,6 +18881,7 @@ async function summonPublicRole(options) {
18789
18881
  // Nested court stations keep station-child semantics; dual-lens
18790
18882
  // ordinary Reviewer axes opt out (#946 / ADR 0082).
18791
18883
  ...options.stationChild === false ? {} : { stationChild: true },
18884
+ ...options.navigatorByStatusPrepare === true ? { navigatorByStatusPrepare: true } : {},
18792
18885
  // Forward composition-root adapters so nested stations (e.g.
18793
18886
  // secretariat → diarist) select the same faux/production table (#924).
18794
18887
  ...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
@@ -20371,7 +20464,7 @@ init_navigator_invocation_identity();
20371
20464
  init_packaged_role_registry();
20372
20465
  init_activation_ledger_topology();
20373
20466
  import { resolve as resolve14 } from "node:path";
20374
- import { Type as Type18 } from "typebox";
20467
+ import "typebox";
20375
20468
 
20376
20469
  // src/navigator-public-session.ts
20377
20470
  init_host_session_record();
@@ -20596,7 +20689,6 @@ async function navigatorHostRunResumable(home, runId) {
20596
20689
  }
20597
20690
  function createNativeNavigatorSessionFactory(deps) {
20598
20691
  return async ({ context, tool }) => {
20599
- let thinkingLevel;
20600
20692
  const entries = [];
20601
20693
  let providerFailure;
20602
20694
  let noReceipt;
@@ -20624,6 +20716,9 @@ function createNativeNavigatorSessionFactory(deps) {
20624
20716
  role: "navigator",
20625
20717
  argv: [text],
20626
20718
  cwd: context.cwd,
20719
+ // Attendance prepare always asks for structured byStatus (#1160).
20720
+ // Direct `ak-role navigator` never sets this flag.
20721
+ navigatorByStatusPrepare: true,
20627
20722
  ...summonHome === void 0 ? {} : { home: summonHome },
20628
20723
  ...context.signal === void 0 ? {} : { signal: context.signal }
20629
20724
  };
@@ -20682,17 +20777,23 @@ function createNativeNavigatorSessionFactory(deps) {
20682
20777
  if (outcome.kind !== "accepted") {
20683
20778
  return;
20684
20779
  }
20685
- const { navigatorProseFromUnknown: navigatorProseFromUnknown2 } = await Promise.resolve().then(() => (init_navigator_output(), navigator_output_exports));
20686
- const proseParts = [];
20780
+ const {
20781
+ byStatusToPlainObject: byStatusToPlainObject2,
20782
+ mergePreparedAdvice: mergePreparedAdvice2,
20783
+ preparedAdviceFromUnknown: preparedAdviceFromUnknown2
20784
+ } = await Promise.resolve().then(() => (init_navigator_output(), navigator_output_exports));
20785
+ let prepared = void 0;
20687
20786
  for (const payload of outcome.payloads ?? []) {
20688
- const prose = navigatorProseFromUnknown2(payload);
20689
- if (prose !== void 0) proseParts.push(prose);
20787
+ prepared = mergePreparedAdvice2(prepared, preparedAdviceFromUnknown2(payload));
20690
20788
  }
20691
- if (proseParts.length === 0) return;
20789
+ if (prepared === void 0) return;
20692
20790
  if (disposed) return;
20693
20791
  await tool.execute(
20694
20792
  "navigator-public-prepare",
20695
- { prose: proseParts.join("\n\n") },
20793
+ {
20794
+ ...prepared.prose === void 0 ? {} : { prose: prepared.prose },
20795
+ ...prepared.byStatus.size === 0 ? {} : { byStatus: byStatusToPlainObject2(prepared.byStatus) }
20796
+ },
20696
20797
  void 0,
20697
20798
  void 0,
20698
20799
  context
@@ -20721,16 +20822,13 @@ function createNativeNavigatorSessionFactory(deps) {
20721
20822
  });
20722
20823
  },
20723
20824
  entries: () => entries,
20724
- setModel: async (next, nextThinking) => {
20725
- let nextParsed;
20825
+ setModel: async (next) => {
20726
20826
  try {
20727
- nextParsed = parseNavigatorModelSetting(next);
20827
+ parseNavigatorModelSetting(next);
20728
20828
  } catch (error) {
20729
20829
  throw navigatorUnavailableError("model", error);
20730
20830
  }
20731
- thinkingLevel = nextThinking ?? nextParsed.thinkingLevel;
20732
20831
  },
20733
- getThinkingLevel: () => thinkingLevel,
20734
20832
  dispose: async () => {
20735
20833
  disposed = true;
20736
20834
  }
@@ -20752,11 +20850,7 @@ function resolveNavigatorAuthorityMaterial(roleInput, fileAuthority) {
20752
20850
  return void 0;
20753
20851
  }
20754
20852
  var NAVIGATOR_TARGETS = PACKAGED_ROLE_REGISTRY.map(({ role, phases }) => ({ role, phases }));
20755
- var prepareSchema = Type18.Object({
20756
- prose: Type18.Optional(Type18.Unknown({
20757
- description: "\u6E38\u5955\u4F7F\u6563\u6587\u5EFA\u8BAE\uFF0C\u539F\u6837\u5448\u73B0\u3002\u4E0D\u8981\u6C42 candidates/next \u7ED3\u6784\u3002"
20758
- }))
20759
- }, { additionalProperties: true });
20853
+ var prepareSchema = navigatorAdviceBodySchema;
20760
20854
  var INVOCATION_ENTRY = NAVIGATOR_INVOCATION_ENTRY;
20761
20855
  var SETTLEMENT_ENTRY = "ak-navigator-settlement";
20762
20856
  function rejectedPrepareReason(entries, start) {
@@ -20781,8 +20875,8 @@ function rejectedPrepareReason(entries, start) {
20781
20875
  }
20782
20876
  return reason;
20783
20877
  }
20784
- function normalizePrepareProse(value) {
20785
- return navigatorProseFromUnknown(value);
20878
+ function normalizePreparedAdvice(value) {
20879
+ return preparedAdviceFromUnknown(value);
20786
20880
  }
20787
20881
  function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
20788
20882
  if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
@@ -20832,7 +20926,7 @@ function createNavigatorAttendance(options) {
20832
20926
  let subject = options.subject;
20833
20927
  let authority = options.authority;
20834
20928
  let contextError = options.contextError;
20835
- let preparedProse;
20929
+ let preparedAdvice;
20836
20930
  const invocationPrincipal = options.invocationId ?? mintNavigatorInvocationId();
20837
20931
  let activeInvocationId = invocationPrincipal;
20838
20932
  let outputSink;
@@ -20857,7 +20951,6 @@ function createNavigatorAttendance(options) {
20857
20951
  unavailableCause: failure.unavailableCause
20858
20952
  };
20859
20953
  };
20860
- let prepareBoundSettlement;
20861
20954
  const loadMaterialsAndSession = async (invocationId) => {
20862
20955
  if (contextError !== void 0) throw navigatorUnavailableError("context", contextError);
20863
20956
  if (typeof authority !== "string" || authority.trim() === "") {
@@ -20928,29 +21021,32 @@ function createNavigatorAttendance(options) {
20928
21021
  if (session === void 0) throw new Error("Navigator session was not created");
20929
21022
  return session;
20930
21023
  };
20931
- const prepare = async (existingSession) => {
20932
- const boundSettlement = prepareBoundSettlement;
20933
- prepareBoundSettlement = void 0;
21024
+ const prepare = async () => {
20934
21025
  const invocationId = invocationPrincipal;
20935
21026
  activeInvocationId = invocationId;
20936
21027
  let output;
20937
21028
  let prepareBatchRejected = false;
20938
21029
  outputSink = (value) => {
21030
+ const next = normalizePreparedAdvice(value);
20939
21031
  if (output === void 0) {
20940
21032
  output = value;
20941
21033
  return;
20942
21034
  }
20943
- const prior = normalizePrepareProse(output) ?? "";
20944
- const next = normalizePrepareProse(value) ?? "";
20945
- const merged = [prior, next].filter((part) => part.trim() !== "").join("\n\n");
20946
- output = { prose: merged };
21035
+ const merged = mergePreparedAdvice(normalizePreparedAdvice(output), next);
21036
+ output = {
21037
+ ...merged?.prose === void 0 ? {} : { prose: merged.prose },
21038
+ ...merged === void 0 || merged.byStatus.size === 0 ? {} : { byStatus: byStatusToPlainObject(merged.byStatus) }
21039
+ };
20947
21040
  };
20948
- const activeSession = existingSession ?? await loadMaterialsAndSession(invocationId);
20949
- if (boundSettlement === void 0) return void 0;
21041
+ const activeSession = await loadMaterialsAndSession(invocationId);
20950
21042
  const request = JSON.stringify({
20951
- ...boundSettlement,
21043
+ kind: "prepare",
21044
+ role: options.role,
21045
+ phase: options.phase,
20952
21046
  invocationId,
20953
- subjectKey
21047
+ subjectKey,
21048
+ subject,
21049
+ authority
20954
21050
  });
20955
21051
  try {
20956
21052
  try {
@@ -20984,27 +21080,21 @@ function createNavigatorAttendance(options) {
20984
21080
  }
20985
21081
  };
20986
21082
  await promptAllowingRejectedPrepare(request);
20987
- if (boundSettlement !== void 0) {
20988
- while (output === void 0 && prepareBatchRejected && delivery.nextAction() === "request-delivery") {
20989
- delivery.recordDeliveryRequest();
20990
- await promptAllowingRejectedPrepare(JSON.stringify(delivery.deliveryState()));
20991
- }
20992
- if (output === void 0 && delivery.nextAction() === "request-delivery") {
20993
- delivery.closeBudget();
20994
- }
20995
- if (output === void 0 && delivery.nextAction() === "no-receipt" && activeSession.providerFailure?.() === void 0) {
20996
- preparedProse = void 0;
20997
- return void 0;
20998
- }
21083
+ while (output === void 0 && prepareBatchRejected && delivery.nextAction() === "request-delivery") {
21084
+ delivery.recordDeliveryRequest();
21085
+ await promptAllowingRejectedPrepare(JSON.stringify(delivery.deliveryState()));
21086
+ }
21087
+ if (output === void 0 && delivery.nextAction() === "request-delivery") {
21088
+ delivery.closeBudget();
21089
+ }
21090
+ if (output === void 0 && delivery.nextAction() === "no-receipt" && activeSession.providerFailure?.() === void 0) {
21091
+ preparedAdvice = void 0;
21092
+ return void 0;
20999
21093
  }
21000
21094
  } catch (error) {
21001
21095
  throw error instanceof NavigatorUnavailableError ? error : navigatorUnavailableError("transport", error);
21002
21096
  }
21003
21097
  if (output === void 0) {
21004
- if (boundSettlement === void 0) {
21005
- preparedProse = void 0;
21006
- return void 0;
21007
- }
21008
21098
  const nativeFailure = [...activeSession.entries()].reverse().find((entry) => {
21009
21099
  if (!isRecord(entry) || entry.type !== "message" || !isRecord(entry.message)) return false;
21010
21100
  return entry.message.role === "assistant" && typeof entry.message.errorMessage === "string" && entry.message.errorMessage.trim() !== "";
@@ -21016,12 +21106,8 @@ function createNavigatorAttendance(options) {
21016
21106
  const cause = providerFailure?.cause ?? source;
21017
21107
  throw navigatorUnavailableError(source, errorMessage, cause);
21018
21108
  }
21019
- if (boundSettlement === void 0) {
21020
- preparedProse = void 0;
21021
- return void 0;
21022
- }
21023
- preparedProse = normalizePrepareProse(output);
21024
- return preparedProse;
21109
+ preparedAdvice = normalizePreparedAdvice(output);
21110
+ return preparedAdvice;
21025
21111
  } finally {
21026
21112
  const playbookFailure = activeSession.routePlaybookReadFailure?.();
21027
21113
  observedRoutePlaybookFailure = typeof playbookFailure === "string" && playbookFailure.trim() !== "" ? playbookFailure : void 0;
@@ -21045,6 +21131,7 @@ function createNavigatorAttendance(options) {
21045
21131
  prepare() {
21046
21132
  if (disposed || preparation !== void 0) return;
21047
21133
  preparationFailure = void 0;
21134
+ preparedAdvice = void 0;
21048
21135
  preparationInFlight = true;
21049
21136
  preparation = prepare().finally(() => {
21050
21137
  preparationInFlight = false;
@@ -21082,24 +21169,8 @@ function createNavigatorAttendance(options) {
21082
21169
  };
21083
21170
  async function settleOnce(settlement) {
21084
21171
  if (disposed) return;
21085
- observedRoutePlaybookFailure = void 0;
21086
21172
  const invocationId = activeInvocationId ?? invocationPrincipal;
21087
21173
  let report;
21088
- if (sessionReady !== void 0) {
21089
- try {
21090
- await sessionReady;
21091
- } catch (error) {
21092
- preparationFailure ??= error;
21093
- }
21094
- }
21095
- if (preparation !== void 0) {
21096
- try {
21097
- await preparation;
21098
- } catch (error) {
21099
- preparationFailure ??= error;
21100
- }
21101
- preparation = void 0;
21102
- }
21103
21174
  const settlementFact = {
21104
21175
  invocationId,
21105
21176
  subjectKey,
@@ -21108,8 +21179,14 @@ function createNavigatorAttendance(options) {
21108
21179
  kind: settlement.kind,
21109
21180
  ..."status" in settlement && settlement.status !== void 0 ? { status: settlement.status } : {}
21110
21181
  };
21111
- let drainedProse;
21112
21182
  if (settlement.kind === "arrival") {
21183
+ if (sessionReady !== void 0) {
21184
+ try {
21185
+ await sessionReady;
21186
+ } catch (error) {
21187
+ preparationFailure ??= error;
21188
+ }
21189
+ }
21113
21190
  session?.appendEntry(SETTLEMENT_ENTRY, settlementFact);
21114
21191
  if (preparationFailure !== void 0) {
21115
21192
  report = unavailable(invocationId, preparationFailure);
@@ -21120,35 +21197,32 @@ function createNavigatorAttendance(options) {
21120
21197
  };
21121
21198
  }
21122
21199
  } else {
21123
- if (session !== void 0) preparationFailure = void 0;
21124
- let coldSession;
21125
- if (session === void 0 && preparationFailure === void 0) {
21200
+ if (sessionReady !== void 0) {
21126
21201
  try {
21127
- coldSession = await loadMaterialsAndSession(invocationId);
21202
+ await sessionReady;
21128
21203
  } catch (error) {
21129
- preparationFailure = error;
21204
+ preparationFailure ??= error;
21130
21205
  }
21131
21206
  }
21132
- session?.appendEntry(SETTLEMENT_ENTRY, settlementFact);
21133
- if (preparationFailure === void 0) {
21134
- prepareBoundSettlement = settlement;
21135
- preparation = prepare(coldSession);
21136
- void preparation.catch((error) => {
21137
- preparationFailure = error;
21138
- });
21207
+ if (preparation !== void 0) {
21139
21208
  try {
21140
- drainedProse = await preparation;
21209
+ await preparation;
21141
21210
  } catch (error) {
21142
21211
  preparationFailure ??= error;
21143
21212
  }
21144
21213
  preparation = void 0;
21145
21214
  }
21215
+ session?.appendEntry(SETTLEMENT_ENTRY, settlementFact);
21146
21216
  if (preparationFailure !== void 0) {
21147
21217
  report = unavailable(invocationId, preparationFailure);
21148
- } else if (typeof drainedProse === "string" && drainedProse.trim() !== "") {
21149
- report = { disposition: "advice", prose: drainedProse };
21150
21218
  } else {
21151
- report = { disposition: "no-advice" };
21219
+ const status = "status" in settlement ? settlement.status : void 0;
21220
+ const picked = pickPreparedProse(preparedAdvice, status);
21221
+ if (typeof picked === "string" && picked.trim() !== "") {
21222
+ report = { disposition: "advice", prose: picked };
21223
+ } else {
21224
+ report = { disposition: "no-advice" };
21225
+ }
21152
21226
  }
21153
21227
  }
21154
21228
  if (observedRoutePlaybookFailure !== void 0) {
@@ -21177,8 +21251,9 @@ function createNavigatorAttendance(options) {
21177
21251
  }
21178
21252
  preparation = void 0;
21179
21253
  sessionReady = void 0;
21180
- preparedProse = void 0;
21254
+ preparedAdvice = void 0;
21181
21255
  preparationFailure = void 0;
21256
+ observedRoutePlaybookFailure = void 0;
21182
21257
  }
21183
21258
  }
21184
21259
 
@@ -21296,18 +21371,18 @@ import { join as join30 } from "node:path";
21296
21371
  import { Value as Value3 } from "typebox/value";
21297
21372
 
21298
21373
  // src/activation-trace.ts
21299
- import { Type as Type19 } from "typebox";
21300
- var causeSchema = Type19.Object({
21301
- identity: Type19.String({ minLength: 1 }),
21302
- name: Type19.String({ minLength: 1 }),
21303
- message: Type19.String(),
21304
- evidenceId: Type19.Optional(Type19.String({ minLength: 1 }))
21374
+ import { Type as Type18 } from "typebox";
21375
+ var causeSchema = Type18.Object({
21376
+ identity: Type18.String({ minLength: 1 }),
21377
+ name: Type18.String({ minLength: 1 }),
21378
+ message: Type18.String(),
21379
+ evidenceId: Type18.Optional(Type18.String({ minLength: 1 }))
21305
21380
  }, { additionalProperties: false });
21306
- var activationTraceRecordSchema = Type19.Object({
21307
- role: Type19.String({ minLength: 1 }),
21308
- stageId: Type19.String({ pattern: "^[a-z][a-z0-9-]*$" }),
21309
- status: Type19.Literal("failed"),
21310
- timestamp: Type19.String({ format: "date-time" }),
21381
+ var activationTraceRecordSchema = Type18.Object({
21382
+ role: Type18.String({ minLength: 1 }),
21383
+ stageId: Type18.String({ pattern: "^[a-z][a-z0-9-]*$" }),
21384
+ status: Type18.Literal("failed"),
21385
+ timestamp: Type18.String({ format: "date-time" }),
21311
21386
  cause: causeSchema
21312
21387
  }, { additionalProperties: false });
21313
21388
  var activationCauseEvidence = 0;
@@ -21472,10 +21547,10 @@ init_engine_material();
21472
21547
  init_engine_detour();
21473
21548
  init_engine_detour_usage();
21474
21549
  init_run_terminal_artifacts();
21475
- import { Type as Type20 } from "typebox";
21476
- var engineDetourArgsSchema = Type20.Object(
21550
+ import { Type as Type19 } from "typebox";
21551
+ var engineDetourArgsSchema = Type19.Object(
21477
21552
  {
21478
- argv: Type20.Array(Type20.String({ minLength: 1 }), {
21553
+ argv: Type19.Array(Type19.String({ minLength: 1 }), {
21479
21554
  minItems: 1,
21480
21555
  description: "\u9996\u9879\u4E3A PATH \u4E2D\u7684\u53EF\u6267\u884C\u6587\u4EF6\uFF0C\u5176\u4F59\u9879\u4E3A\u53C2\u6570\u3002"
21481
21556
  })
@@ -25017,6 +25092,7 @@ function createHeadlessRoleTurnHost(config) {
25017
25092
  const prepared = await config.prepare(request);
25018
25093
  const systemPrompt = renderSystemPromptOverride(prepared.systemPrompt);
25019
25094
  const codex = isCodexExecDescription(config.description);
25095
+ const navigatorProseExit = prepared.terminatingToolName === NAVIGATOR_OUTPUT_TOOL_NAME && request.navigatorByStatusPrepare !== true;
25020
25096
  let outcome = externalHostFailure("session", "HeadlessNoOutcome", "no-outcome");
25021
25097
  try {
25022
25098
  let sessionId = await resolveBoundHostSessionId(request, config.sessionIdentity);
@@ -25045,7 +25121,7 @@ function createHeadlessRoleTurnHost(config) {
25045
25121
  await writeFile6(systemPromptPath, systemPrompt, "utf8");
25046
25122
  let deliveredSchema;
25047
25123
  if (codex) {
25048
- if (prepared.terminatingToolName !== NAVIGATOR_OUTPUT_TOOL_NAME) {
25124
+ if (!navigatorProseExit) {
25049
25125
  outputSchemaPath = join31(inputsDirectory, "output-schema.json");
25050
25126
  deliveredSchema = closeJsonSchemaForCodex(prepared.jsonSchema);
25051
25127
  await writeFile6(outputSchemaPath, `${JSON.stringify(deliveredSchema, null, 2)}
@@ -25059,7 +25135,7 @@ function createHeadlessRoleTurnHost(config) {
25059
25135
  `,
25060
25136
  "utf8"
25061
25137
  );
25062
- if (prepared.terminatingToolName !== NAVIGATOR_OUTPUT_TOOL_NAME) deliveredSchema = prepared.jsonSchema;
25138
+ if (!navigatorProseExit) deliveredSchema = prepared.jsonSchema;
25063
25139
  }
25064
25140
  startedWithSchema = deliveredSchema;
25065
25141
  } catch (setupError) {
@@ -25088,8 +25164,8 @@ function createHeadlessRoleTurnHost(config) {
25088
25164
  args = buildTurnArgs({
25089
25165
  description: config.description,
25090
25166
  systemPromptPath,
25091
- // #959: navigator prose exit — no closed JSON schema on claude either.
25092
- ...prepared.terminatingToolName === NAVIGATOR_OUTPUT_TOOL_NAME ? {} : { jsonSchema: prepared.jsonSchema },
25167
+ // Direct navigator prose exit omits --json-schema; byStatus prepare mounts it.
25168
+ ...navigatorProseExit ? {} : { jsonSchema: prepared.jsonSchema },
25093
25169
  mcpServers: prepared.mcpServers,
25094
25170
  ...mcpConfigPath === void 0 ? {} : { mcpConfigPath },
25095
25171
  ...outputSchemaPath === void 0 ? {} : { outputSchemaPath },
@@ -25212,10 +25288,9 @@ function createHeadlessRoleTurnHost(config) {
25212
25288
  ...observation.failureEvent === void 0 ? {} : { details: observation.failureEvent }
25213
25289
  });
25214
25290
  }
25215
- const navigator = prepared.terminatingToolName === NAVIGATOR_OUTPUT_TOOL_NAME;
25216
25291
  const deliverReply = async () => {
25217
25292
  if (!observation.turnCompleted || observation.finalMessage === void 0) return void 0;
25218
- if (navigator) {
25293
+ if (navigatorProseExit) {
25219
25294
  if (observation.finalMessage.trim() === "") return void 0;
25220
25295
  await prepared.ingestStructuredOutput({ prose: observation.finalMessage });
25221
25296
  return deliveredFromSpawned(spawned);
@@ -25253,7 +25328,7 @@ function createHeadlessRoleTurnHost(config) {
25253
25328
  }
25254
25329
  if (envelope.structured_output !== void 0) {
25255
25330
  await prepared.ingestStructuredOutput(envelope.structured_output);
25256
- } else if (prepared.terminatingToolName === NAVIGATOR_OUTPUT_TOOL_NAME && typeof envelope.result === "string" && envelope.result.trim() !== "") {
25331
+ } else if (navigatorProseExit && typeof envelope.result === "string" && envelope.result.trim() !== "") {
25257
25332
  await prepared.ingestStructuredOutput({ prose: envelope.result });
25258
25333
  }
25259
25334
  return deliveredFromSpawned(spawned);
@@ -8584,7 +8584,7 @@ var init_gatekeeper_output = __esm({
8584
8584
  });
8585
8585
 
8586
8586
  // src/package-contracts/navigator-output.ts
8587
- var NAVIGATOR_OUTPUT_TOOL_NAME, navigatorOutputSchema;
8587
+ var NAVIGATOR_OUTPUT_TOOL_NAME, navigatorAdviceFields, navigatorAdviceBodySchema, navigatorOutputSchema;
8588
8588
  var init_navigator_output = __esm({
8589
8589
  "src/package-contracts/navigator-output.ts"() {
8590
8590
  "use strict";
@@ -8593,15 +8593,16 @@ var init_navigator_output = __esm({
8593
8593
  init_open_tool_schema();
8594
8594
  init_terminating_infrastructure();
8595
8595
  NAVIGATOR_OUTPUT_TOOL_NAME = "ak_navigator_output";
8596
- navigatorOutputSchema = withTerminatingOutputDeclarations(
8597
- openToolObject(
8598
- typebox_exports.Object({
8599
- prose: typebox_exports.Unknown({
8600
- 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"
8601
- })
8602
- })
8603
- )
8604
- );
8596
+ navigatorAdviceFields = {
8597
+ prose: typebox_exports.Unknown({
8598
+ description: "\u5355\u6761\u6563\u6587\u5EFA\u8BAE\u3002\u65E0\u72B6\u6001\u5206\u53C9\u65F6\u4F7F\u7528\uFF1B\u539F\u6837\u5448\u73B0\u3002"
8599
+ }),
8600
+ byStatus: typebox_exports.Unknown({
8601
+ description: "\u6309\u4E3B\u8859\u95E8\u7ED3\u5C40 status \u9884\u5199\u7684\u6563\u6587\u5EFA\u8BAE\u3002\u952E\u4E3A status \u5B57\u9762\u91CF\uFF0C\u503C\u4E3A\u5EFA\u8BAE\u6B63\u6587\u3002\u7ED3\u7B97\u65F6\u4EE3\u7801\u53EA\u6309\u5B9E\u9645 status \u53D6\u5BF9\u5E94\u539F\u6587\uFF0C\u4E0D\u89E3\u6790\u5EFA\u8BAE\u8BED\u4E49\u3002"
8602
+ })
8603
+ };
8604
+ navigatorAdviceBodySchema = openToolObject(typebox_exports.Object(navigatorAdviceFields));
8605
+ navigatorOutputSchema = withTerminatingOutputDeclarations(navigatorAdviceBodySchema);
8605
8606
  }
8606
8607
  });
8607
8608