@akagilnc/pi-workflow-roles 0.1.5079 → 0.1.5096

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 (64) hide show
  1. package/dist/acp-host/production-host.js +348 -301
  2. package/dist/atomic-write.js +13 -19
  3. package/dist/auditor-soul.js +2 -1
  4. package/dist/doctor-contracts.js +1 -1
  5. package/dist/gatekeeper-role.js +2 -16
  6. package/dist/headless-host/production-host.js +380 -333
  7. package/dist/merger-contracts.js +1 -1
  8. package/dist/migrate-book-topology.js +18 -14
  9. package/dist/navigator-attendance.js +28 -143
  10. package/dist/navigator-invocation-identity.js +2 -0
  11. package/dist/navigator-public-session.js +13 -1
  12. package/dist/navigator-work-base.js +113 -0
  13. package/dist/notary-contracts.js +0 -2
  14. package/dist/package-contracts/fixer-output.js +1 -1
  15. package/dist/package-contracts/gatekeeper-output.js +1 -1
  16. package/dist/package-contracts/navigator-output.js +1 -1
  17. package/dist/package-contracts/terminating-infrastructure.js +3 -3
  18. package/dist/packaged-role-registry.js +9 -5
  19. package/dist/public-cli/countersign-run.js +1 -1
  20. package/dist/public-cli/invocation.js +6 -3
  21. package/dist/public-cli/main.js +46 -22
  22. package/dist/public-cli/settlement.js +20 -1
  23. package/dist/receipt-delivery-policy.js +9 -2
  24. package/dist/review-submission.js +3 -3
  25. package/docs/adr/0057-schema-narrowing-cuts-the-required-set-not-the-declared-set.md +9 -0
  26. package/extensions/role-runtime.ts +0 -27
  27. package/package.json +2 -1
  28. package/resources/836-deleted-machine-instruction-inventory.md +3 -3
  29. package/resources/collector-bot-handbook.md +4 -0
  30. package/resources/navigator-route-playbook.md +4 -6
  31. package/scripts/build-package.mjs +4 -0
  32. package/souls/coder-output-guide.md +1 -0
  33. package/src/auditor-soul.ts +2 -1
  34. package/src/collector-role.ts +6 -7
  35. package/src/collector-tool-schemas.ts +5 -5
  36. package/src/diarist-role.ts +2 -2
  37. package/src/doctor-contracts.ts +1 -1
  38. package/src/gatekeeper-role.ts +1 -18
  39. package/src/gleaner-left-role.ts +2 -2
  40. package/src/inspector-role.ts +1 -1
  41. package/src/judge-role.ts +1 -1
  42. package/src/merger-contracts.ts +1 -1
  43. package/src/navigator-attendance.ts +38 -164
  44. package/src/navigator-invocation-identity.ts +2 -0
  45. package/src/navigator-public-session.ts +17 -1
  46. package/src/navigator-role.ts +4 -0
  47. package/src/navigator-session-contracts.ts +2 -0
  48. package/src/navigator-work-base.ts +123 -0
  49. package/src/notary-contracts.ts +0 -4
  50. package/src/package-contracts/fixer-output.ts +1 -1
  51. package/src/package-contracts/gatekeeper-output.ts +3 -3
  52. package/src/package-contracts/navigator-output.ts +1 -1
  53. package/src/package-contracts/terminating-infrastructure.ts +3 -6
  54. package/src/packaged-role-registry.ts +5 -1
  55. package/src/public-cli/countersign-run.ts +1 -1
  56. package/src/public-cli/invocation.ts +6 -3
  57. package/src/public-cli/settlement.ts +21 -0
  58. package/src/receipt-delivery-policy.ts +9 -1
  59. package/src/review-submission.ts +3 -3
  60. package/src/reviewer-role.ts +3 -3
  61. package/src/role-runtime-dependencies.ts +1 -5
  62. package/src/role-runtime.ts +52 -38
  63. package/src/secretariat-role.ts +3 -3
  64. package/src/worker-role.ts +3 -3
@@ -23,6 +23,7 @@ import {
23
23
  durableSessionPointer,
24
24
  resolveBookKeyFromGit,
25
25
  } from "./activation-ledger.ts";
26
+ import { readPackageMaterial } from "./session-opening-materials.ts";
26
27
  import { writeStderrJsonlRecord } from "./stderr-jsonl.ts";
27
28
  import {
28
29
  createToolExecutionObservationFace,
@@ -38,7 +39,7 @@ import {
38
39
  } from "./engine-detour.ts";
39
40
  import { engineSessionMaterialFromOptions } from "./package-resources/engine-material.ts";
40
41
  import { registerEngineDetourTool } from "./engine-detour-tool.ts";
41
- import { createReceiptDeliveryPolicy, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, RECEIPT_DELIVERY_PROMPT } from "./receipt-delivery-policy.ts";
42
+ import { createReceiptDeliveryPolicy, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE } from "./receipt-delivery-policy.ts";
42
43
  import type { CollectorClock } from "./collector-evidence.ts";
43
44
  import type { CollectorGitHubTransport } from "./collector-github.ts";
44
45
  import {
@@ -98,7 +99,8 @@ import {
98
99
  type AuditorRuntimeDependencies,
99
100
  } from "./auditor-role.ts";
100
101
 
101
- import { formatNavigatorReport, NAVIGATOR_EVENT_TYPE, navigatorSubjectKey, navigatorUnavailableError, subjectPath, type NavigatorAttendance, type NavigatorAttendanceOptions, type NavigatorEvent, type NavigatorPhase, type NavigatorReport, type NavigatorSettlement, type NavigatorSubjectProvenance, type NavigatorTargetRole, type NavigatorWorkContext } from "./navigator-attendance.ts";
102
+ import { formatNavigatorReport, NAVIGATOR_EVENT_TYPE, NAVIGATOR_ROUTE_PLAYBOOK_FAILURE_ENTRY, navigatorSubjectKey, navigatorUnavailableError, subjectPath, type NavigatorAttendance, type NavigatorAttendanceOptions, type NavigatorEvent, type NavigatorPhase, type NavigatorReport, type NavigatorSettlement, type NavigatorSubjectProvenance, type NavigatorWorkContext } from "./navigator-attendance.ts";
103
+ import { loadNavigatorWorkBaseSuffix } from "./navigator-work-base.ts";
102
104
  import {
103
105
  buildNavigatorInfrastructureFailureFact,
104
106
  classifyPackagedRoleTerminalResult,
@@ -108,7 +110,7 @@ import {
108
110
  } from "./navigator-invocation-identity.ts";
109
111
  import { recordTypedProviderHttpStatus } from "./typed-provider-http.ts";
110
112
  import { NAVIGATOR_POST_ROLE_GRACE_MS, raceNavigatorGrace } from "./public-cli/settlement.ts";
111
- import { PACKAGED_ROLE_REGISTRY, isOfficerReviewSeat, packagedRoleActivationFlags, packagedRoleInputFlag, packagedRoleMetadata, packagedRoleOutputTool, packagedRolePhaseFlag, type PackagedRole } from "./packaged-role-registry.ts";
113
+ import { PACKAGED_ROLE_REGISTRY, isOfficerReviewSeat, packagedRoleActivationFlags, packagedRoleMetadata, packagedRoleOutputTool, packagedRolePhaseFlag, type PackagedRole } from "./packaged-role-registry.ts";
112
114
  import { isAuditEscalationProjection } from "./audit-escalation.ts";
113
115
  import {
114
116
  createJudgeRoleRuntime,
@@ -301,7 +303,6 @@ import {
301
303
  NOTARY_OUTPUT_TOOL,
302
304
  INSPECTOR_OUTPUT_TOOL,
303
305
  GatekeeperDecisionError,
304
- createGatekeeperOutputTool,
305
306
  runGatekeeper,
306
307
  gateOfficerForSubject,
307
308
  } from "./gatekeeper-role.ts";
@@ -309,7 +310,6 @@ export {
309
310
  NOTARY_OUTPUT_TOOL,
310
311
  INSPECTOR_OUTPUT_TOOL,
311
312
  GatekeeperDecisionError,
312
- createGatekeeperOutputTool,
313
313
  runGatekeeper,
314
314
  gateOfficerForSubject,
315
315
  };
@@ -452,29 +452,7 @@ export const ROLE_FLAG = {
452
452
  },
453
453
  } as const;
454
454
 
455
- /** Host-neutral in-process role help for Navigator prepare (Pi and Grok share this). */
456
- export function formatNavigatorRoleHelp(role: NavigatorTargetRole): string {
457
- const metadata = packagedRoleMetadata(role);
458
- const lines = [
459
- `Usage: ak-role ${role}`,
460
- ROLE_FLAG.definition.description,
461
- ];
462
- const inputFlag = packagedRoleInputFlag(role);
463
- if (inputFlag !== undefined) {
464
- lines.push(` --${inputFlag} <value> ${role} input material`);
465
- }
466
- const phaseFlag = packagedRolePhaseFlag(role);
467
- if (phaseFlag !== undefined && metadata !== undefined) {
468
- lines.push(
469
- ` --${phaseFlag} <value> ${role} phase: ${(metadata.phases.filter((p) => p !== null) as string[]).join(" | ")}`,
470
- );
471
- }
472
- lines.push(`Public next-command form: ak-role ${role}`);
473
- return lines.join("\n");
474
- }
475
-
476
- type NavigatorAttendanceDependency = Omit<NavigatorAttendance, "knownRoutePlaybookReadFailure"> &
477
- Partial<Pick<NavigatorAttendance, "knownRoutePlaybookReadFailure">>;
455
+ type NavigatorAttendanceDependency = NavigatorAttendance;
478
456
 
479
457
  export type RoleRuntimeDependencies = {
480
458
  /** Package root for packaged engine-note resolution (#879). */
@@ -754,7 +732,7 @@ export function createNavigatorRoleRuntime(
754
732
  roleHost: RoleHost,
755
733
  dependencies: NavigatorRuntimeDependencies,
756
734
  ) {
757
- return createFiledOfficerRuntime(
735
+ const base = createFiledOfficerRuntime(
758
736
  roleHost,
759
737
  {
760
738
  role: "navigator",
@@ -763,6 +741,43 @@ export function createNavigatorRoleRuntime(
763
741
  },
764
742
  dependencies,
765
743
  );
744
+ let playbookBound = false;
745
+ return {
746
+ async activate() {
747
+ await base.activate();
748
+ if (playbookBound) return;
749
+ playbookBound = true;
750
+ // Standing system prompt, not a per-turn user message. Native read failure
751
+ // is the explanation (ADR 0061); no code-written sentence.
752
+ const loadRoutePlaybook = dependencies.loadRoutePlaybook
753
+ ?? (() => readPackageMaterial("resources/navigator-route-playbook.md"));
754
+ let playbookRead: Promise<string> | undefined;
755
+ roleHost.on("before_agent_start", async (event) => {
756
+ const basePrompt = typeof event.systemPrompt === "string" ? event.systemPrompt : "";
757
+ const parts: string[] = [];
758
+ try {
759
+ playbookRead ??= loadRoutePlaybook();
760
+ const content = await playbookRead;
761
+ dependencies.recordRoutePlaybookReadFailure?.(undefined);
762
+ if (content.trim() !== "") parts.push(content);
763
+ } catch (error) {
764
+ const message = error instanceof Error ? error.message : String(error);
765
+ if (message.trim() !== "") {
766
+ dependencies.recordRoutePlaybookReadFailure?.(message);
767
+ parts.push(message);
768
+ }
769
+ }
770
+ const prompt = typeof event.prompt === "string" ? event.prompt : "";
771
+ const work = await loadNavigatorWorkBaseSuffix(prompt);
772
+ if (work !== undefined && work.trim() !== "") parts.push(work);
773
+ if (parts.length === 0) return;
774
+ const text = parts.join("\n\n");
775
+ return {
776
+ systemPrompt: basePrompt.trim() === "" ? text : `${basePrompt}\n\n${text}`,
777
+ };
778
+ });
779
+ },
780
+ };
766
781
  }
767
782
 
768
783
  /** #675: public 审刑院 seat on the shared filed-officer envelope. */
@@ -1311,13 +1326,11 @@ export function createRoleRuntimeExtension(
1311
1326
  const raced = await raceNavigatorGrace(settlePromise, NAVIGATOR_POST_ROLE_GRACE_MS);
1312
1327
  if (raced.status !== "timeout") return;
1313
1328
  if (pendingNavigatorPresentation === undefined) {
1314
- const routePlaybookReadFailure = attendance.knownRoutePlaybookReadFailure?.();
1315
1329
  const report: NavigatorReport = {
1316
1330
  disposition: "unavailable",
1317
1331
  unavailableReason: "Navigator exceeded post-role delivery grace",
1318
1332
  unavailableSource: "unknown",
1319
1333
  unavailableCause: "unknown",
1320
- ...(routePlaybookReadFailure === undefined ? {} : { routePlaybookReadFailure }),
1321
1334
  };
1322
1335
  const event: NavigatorEvent = {
1323
1336
  version: 1,
@@ -1329,7 +1342,6 @@ export function createRoleRuntimeExtension(
1329
1342
  unavailableReason: "Navigator exceeded post-role delivery grace",
1330
1343
  unavailableSource: "unknown",
1331
1344
  unavailableCause: "unknown",
1332
- ...(routePlaybookReadFailure === undefined ? {} : { routePlaybookReadFailure }),
1333
1345
  };
1334
1346
  pendingNavigatorPresentation = { event, report };
1335
1347
  }
@@ -1600,7 +1612,7 @@ export function createRoleRuntimeExtension(
1600
1612
  } catch {}
1601
1613
  envelopeHost.sendMessage({
1602
1614
  customType: "ak-receipt-delivery-prompt",
1603
- content: RECEIPT_DELIVERY_PROMPT,
1615
+ content: JSON.stringify(receiptDelivery.deliveryState()),
1604
1616
  display: false,
1605
1617
  }, { triggerTurn: true, deliverAs: "followUp" });
1606
1618
  } else if (receiptDelivery.nextAction() === "no-receipt" && !noReceiptRecorded) {
@@ -1773,6 +1785,11 @@ export function createRoleRuntimeExtension(
1773
1785
  });
1774
1786
  const navigator = createNavigatorRoleRuntime(roleHost, {
1775
1787
  loadSoul: () => requireRoleSoul("navigator"),
1788
+ recordRoutePlaybookReadFailure: (message) => {
1789
+ envelopeHost.appendEntry(NAVIGATOR_ROUTE_PLAYBOOK_FAILURE_ENTRY, {
1790
+ message: message ?? "",
1791
+ });
1792
+ },
1776
1793
  });
1777
1794
  const auditor = createAuditorRoleRuntime(roleHost, {
1778
1795
  loadSoul: () => requireRoleSoul("auditor"),
@@ -2159,11 +2176,8 @@ export function createRoleRuntimeExtension(
2159
2176
  pendingNavigatorPresentation = { event: navigatorEvent, report };
2160
2177
  },
2161
2178
  });
2162
- // Warm live help during activation so prepare is not help-bound under load.
2163
- // Concrete work context also starts full preparation so session create
2164
- // overlaps the role run. Placeholder subjects wait for before_agent_start
2165
- // (user prompt may replace the subject key) but still inherit warm help.
2166
- navigatorAttendance.warmHelp?.();
2179
+ // Concrete work context starts standby attendance (record only, no model).
2180
+ // Placeholder subjects wait for before_agent_start (user prompt may replace the subject key).
2167
2181
  if (
2168
2182
  navigatorWorkContext.contextError === undefined &&
2169
2183
  navigatorWorkContext.subjectProvenance !== "placeholder"
@@ -12,12 +12,12 @@ import { SECRETARIAT_OUTPUT_TOOL_NAME, type SecretariatVerdict } from "./secreta
12
12
  export { SECRETARIAT_OUTPUT_TOOL_NAME } from "./secretariat-contracts.ts";
13
13
  export type { SecretariatVerdict };
14
14
 
15
- /** 中书省终局回执形状;形状指引,非 schema 闸。 */
15
+ /** 中书省终局回执形状。 */
16
16
  export const secretariatVerdictSchema = withTerminatingOutputDeclarations(
17
17
  Type.Object(
18
18
  {
19
19
  secretariatStatus: Type.Unknown({
20
- description: "converged | escalate(终局形状指引,非闸)",
20
+ description: "converged | escalate",
21
21
  }),
22
22
  ticketNumber: Type.Optional(
23
23
  Type.Number({ description: "本票号;署时指向最终正文所在票" }),
@@ -44,7 +44,7 @@ export type SecretariatVerdictParameters = Static<typeof secretariatVerdictSchem
44
44
  export const SECRETARIAT_OUTPUT_TOOL_SPEC = {
45
45
  name: SECRETARIAT_OUTPUT_TOOL_NAME,
46
46
  label: "中书省输出",
47
- description: "中书省终局回执(署或上呈);给事中封驳须改票重送,不在此终局。",
47
+ description: "中书省终局回执。",
48
48
  promptSnippet: "中书省终局回执",
49
49
  parameters: secretariatVerdictSchema,
50
50
  } as const;
@@ -48,7 +48,7 @@ export type { WorkerOutput };
48
48
  // One shared description across every variant
49
49
  // so openToolObjectFromUnion's identical-declaration collapse drops none of it.
50
50
  const CODER_STATUS_DESCRIPTION =
51
- "planned | completed | refused | partially_completed | unfinished — 形状指引,非 schema 闸;completed 回执含 TDD、同模式、引入回归、行为事实四项证据;unfinished 缺前置或违宪约束致本局未完成时可用,缺待决 owner 决定或答复属缺前置。" as const;
51
+ "planned | completed | refused | partially_completed | unfinished。unfinished:缺前置或违宪约束致本局未完成。" as const;
52
52
  const coderOutputVariants = Type.Union([
53
53
  Type.Object({
54
54
  status: Type.Unknown({ description: CODER_STATUS_DESCRIPTION }),
@@ -254,7 +254,7 @@ export function createFixerRoleRuntime(
254
254
  pi.registerTool({
255
255
  name: FIXER_OUTPUT_TOOL_NAME,
256
256
  label: "修内司输出",
257
- description: "提交修内司终局回执;基础设施失败走 abort,不经本工具。",
257
+ description: "提交修内司终局回执。",
258
258
  promptSnippet: "提交修内司终局回执",
259
259
  parameters: fixerOutputSchema,
260
260
  async execute(toolCallId: string, parameters: unknown, _signal: AbortSignal | undefined, _onUpdate: unknown, ctx: HostContext): Promise<HostToolResult<unknown>> {
@@ -381,7 +381,7 @@ export function createCoderRoleRuntime(
381
381
  pi.registerTool({
382
382
  name: CODER_OUTPUT_TOOL_NAME,
383
383
  label: "将作监输出",
384
- description: "提交将作监终局回执;本工具无 escalate 通道。",
384
+ description: "提交将作监终局回执。",
385
385
  promptSnippet: "提交将作监终局回执",
386
386
  parameters: coderOutputSchema,
387
387
  async execute(toolCallId: string, parameters: unknown, _signal: AbortSignal | undefined, _onUpdate: unknown, ctx: HostContext): Promise<HostToolResult<unknown>> {