@akagilnc/pi-workflow-roles 0.1.4800 → 0.1.4870

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 (143) hide show
  1. package/dist/acp-host/production-host.js +19434 -18218
  2. package/dist/analyst-book-key.js +63 -0
  3. package/dist/analyst-cohort.js +167 -0
  4. package/dist/analyst-entry.js +320 -0
  5. package/dist/analyst-index.js +247 -0
  6. package/dist/analyst-ledger.js +561 -0
  7. package/dist/analyst-median.js +16 -0
  8. package/dist/analyst-metric-families/acceptance-success-rework.js +249 -0
  9. package/dist/analyst-metric-families/b2-frame-buckets-actions.js +189 -0
  10. package/dist/analyst-metric-families/gate-cycles.js +77 -0
  11. package/dist/analyst-metric-families/leg-wall-clock.js +56 -0
  12. package/dist/analyst-metric-families/round-timeline.js +126 -0
  13. package/dist/analyst-metric-families.js +23 -0
  14. package/dist/analyst-metric-family.js +11 -0
  15. package/dist/analyst-model-groups.js +135 -0
  16. package/dist/analyst-page.js +182 -0
  17. package/dist/atomic-write.js +23 -0
  18. package/dist/auditor-soul.js +1 -1
  19. package/dist/countersign-contracts.js +0 -2
  20. package/dist/diarist-contracts.js +0 -1
  21. package/dist/doctor-contracts.js +2 -2
  22. package/dist/gatekeeper-role.js +15 -16
  23. package/dist/gleaner-left-contracts.js +0 -2
  24. package/dist/headless-host/production-host.js +16967 -15749
  25. package/dist/host-contracts.js +0 -4
  26. package/dist/inspector-contracts.js +0 -2
  27. package/dist/institutional-resolution.js +4 -2
  28. package/dist/merger-contracts.js +0 -2
  29. package/dist/migrate-book-topology.js +3908 -3089
  30. package/dist/navigator-public-session.js +4 -3
  31. package/dist/notary-contracts.js +0 -2
  32. package/dist/package-contracts/auditor-output.js +0 -1
  33. package/dist/package-contracts/collector-output.js +0 -2
  34. package/dist/package-contracts/fixer-output.js +0 -2
  35. package/dist/package-contracts/gatekeeper-output.js +0 -2
  36. package/dist/package-contracts/judge-output.js +0 -2
  37. package/dist/package-contracts/navigator-output.js +0 -2
  38. package/dist/package-contracts/reviewer-output.js +0 -2
  39. package/dist/package-contracts/terminating-tools.js +32 -92
  40. package/dist/package-contracts/worker-output.js +0 -4
  41. package/dist/packaged-role-registry.js +518 -36
  42. package/dist/pi/role-turn-host.js +2 -1
  43. package/dist/public-cli/analyst-run.js +185 -0
  44. package/dist/public-cli/cli.js +885 -0
  45. package/dist/public-cli/config.js +12 -9
  46. package/dist/public-cli/countersign-run.js +4 -311
  47. package/dist/public-cli/instruction-seat-run.js +628 -158
  48. package/dist/public-cli/invocation.js +806 -1550
  49. package/dist/public-cli/main.js +6962 -9882
  50. package/dist/public-cli/option-definitions.js +51 -99
  51. package/dist/public-cli/post-admission.js +30 -2
  52. package/dist/public-cli/run-lifecycle.js +234 -353
  53. package/dist/public-cli/seat-ticket-binding.js +6 -0
  54. package/dist/public-cli/settlement.js +261 -675
  55. package/dist/public-cli/turn-request.js +76 -0
  56. package/dist/public-role-summons.js +38 -112
  57. package/dist/role-activation-flags.js +23 -45
  58. package/dist/secretariat-contracts.js +0 -2
  59. package/dist/session-identity.js +17 -8
  60. package/dist/session-opening-materials.js +3 -2
  61. package/extensions/role-runtime.ts +6 -80
  62. package/package.json +1 -1
  63. package/souls/coder.md +1 -2
  64. package/src/acp-host/role-turn-host.ts +4 -1
  65. package/src/analyst-metric-families/acceptance-success-rework.ts +3 -2
  66. package/src/auditor-role.ts +1 -2
  67. package/src/auditor-soul.ts +1 -1
  68. package/src/collector-role.ts +2 -2
  69. package/src/countersign-contracts.ts +0 -1
  70. package/src/countersign-role.ts +1 -1
  71. package/src/diarist-contracts.ts +0 -1
  72. package/src/diarist-role.ts +0 -1
  73. package/src/doctor-auditor.ts +1 -2
  74. package/src/doctor-contracts.ts +1 -1
  75. package/src/doctor-role.ts +3 -2
  76. package/src/external-host-turn-loop.ts +1 -1
  77. package/src/factory-board.ts +10 -7
  78. package/src/gatekeeper-role.ts +16 -10
  79. package/src/gleaner-left-contracts.ts +0 -1
  80. package/src/gleaner-left-role.ts +0 -1
  81. package/src/headless-host/role-turn-host.ts +7 -1
  82. package/src/host-contracts.ts +10 -6
  83. package/src/inspector-contracts.ts +0 -1
  84. package/src/inspector-role.ts +0 -2
  85. package/src/institutional-resolution.ts +6 -4
  86. package/src/judge-role.ts +3 -3
  87. package/src/merger-contracts.ts +0 -1
  88. package/src/merger-role.ts +2 -2
  89. package/src/navigator-public-session.ts +7 -6
  90. package/src/navigator-work-context.ts +6 -8
  91. package/src/notary-contracts.ts +0 -1
  92. package/src/notary-role.ts +2 -3
  93. package/src/package-contracts/auditor-output.ts +0 -1
  94. package/src/package-contracts/collector-output.ts +0 -1
  95. package/src/package-contracts/fixer-output.ts +0 -1
  96. package/src/package-contracts/gatekeeper-output.ts +0 -1
  97. package/src/package-contracts/judge-output.ts +0 -1
  98. package/src/package-contracts/navigator-output.ts +0 -1
  99. package/src/package-contracts/reviewer-output.ts +0 -1
  100. package/src/package-contracts/terminating-tools.ts +27 -99
  101. package/src/package-contracts/worker-output.ts +0 -2
  102. package/src/packaged-role-registry.ts +604 -35
  103. package/src/pi/role-turn-host.ts +2 -1
  104. package/src/public-cli/cli.ts +64 -259
  105. package/src/public-cli/config.ts +18 -10
  106. package/src/public-cli/countersign-run.ts +14 -449
  107. package/src/public-cli/instruction-seat-run.ts +758 -277
  108. package/src/public-cli/invocation.ts +1097 -2051
  109. package/src/public-cli/option-definitions.ts +62 -127
  110. package/src/public-cli/post-admission.ts +47 -2
  111. package/src/public-cli/run-lifecycle.ts +303 -613
  112. package/src/public-cli/seat-ticket-binding.ts +6 -0
  113. package/src/public-cli/settlement.ts +399 -1185
  114. package/src/public-cli/turn-request.ts +92 -1
  115. package/src/public-role-summons.ts +44 -128
  116. package/src/reviewer-role.ts +3 -2
  117. package/src/role-activation-flags.ts +20 -41
  118. package/src/role-runtime-dependencies.ts +25 -26
  119. package/src/role-runtime.ts +121 -232
  120. package/src/secretariat-contracts.ts +0 -1
  121. package/src/secretariat-role.ts +0 -2
  122. package/src/session-identity.ts +23 -8
  123. package/src/session-opening-materials.ts +2 -1
  124. package/src/worker-role.ts +3 -4
  125. package/dist/doctor-auditor.js +0 -25
  126. package/dist/public-cli/diarist-run.js +0 -130
  127. package/dist/public-cli/doctor-run.js +0 -87
  128. package/dist/public-cli/inspector-run.js +0 -151
  129. package/dist/public-cli/judge-run.js +0 -114
  130. package/dist/public-cli/notary-run.js +0 -174
  131. package/dist/public-cli/reviewer-run.js +0 -339
  132. package/src/public-cli/coder-run.ts +0 -255
  133. package/src/public-cli/collector-run.ts +0 -189
  134. package/src/public-cli/diarist-run.ts +0 -233
  135. package/src/public-cli/doctor-run.ts +0 -167
  136. package/src/public-cli/fixer-run.ts +0 -265
  137. package/src/public-cli/gleaner-left-run.ts +0 -167
  138. package/src/public-cli/inspector-run.ts +0 -261
  139. package/src/public-cli/judge-run.ts +0 -196
  140. package/src/public-cli/merger-run.ts +0 -294
  141. package/src/public-cli/notary-run.ts +0 -279
  142. package/src/public-cli/reviewer-run.ts +0 -480
  143. package/src/public-cli/secretariat-run.ts +0 -265
@@ -10,7 +10,6 @@
10
10
  export const SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
11
11
  export const SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME =
12
12
  "ak_secretariat_summon_countersign";
13
- export const SECRETARIAT_ACCEPTED_TEXT = "中书省回执已接受";
14
13
  /**
15
14
  * #969 durable custom entry: 给事中 terminal (署|上呈) for seat settlement projection.
16
15
  * Carries original receipt bytes + nested runId. Envelope persists custom entries
@@ -10,7 +10,6 @@ import { withTerminatingOutputDeclarations } from "./package-contracts/terminati
10
10
  import type { NamedRoleTurnHostAdapter } from "./public-cli/role-turn-host-resolution.ts";
11
11
  import type { PublicSummonResult } from "./public-role-summons.ts";
12
12
  import {
13
- SECRETARIAT_ACCEPTED_TEXT,
14
13
  SECRETARIAT_OUTPUT_TOOL_NAME,
15
14
  SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME,
16
15
  type SecretariatVerdict,
@@ -18,7 +17,6 @@ import {
18
17
  import { runIdFromRunDirectory } from "./run-terminal-artifacts.ts";
19
18
 
20
19
  export {
21
- SECRETARIAT_ACCEPTED_TEXT,
22
20
  SECRETARIAT_OUTPUT_TOOL_NAME,
23
21
  SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME,
24
22
  } from "./secretariat-contracts.ts";
@@ -60,13 +60,28 @@ export function resolveHostAwareSessionAvailability(
60
60
  if (host === undefined || host === DEFAULT_ROLE_TURN_HOST) {
61
61
  return (principal) => principalAuthority.isAvailable(principal);
62
62
  }
63
+ // Unregistered names have no binding file: absence, not a guess at pi.
64
+ return async (principal) =>
65
+ (await readStoredHostSessionId(host, principalAuthority, principal)) !== undefined;
66
+ }
67
+
68
+ /**
69
+ * Native session/thread id already stored for this principal on `host`.
70
+ * Public explicit resume reads it once and hands it to the host adapter.
71
+ * Pi has no separate binding file. A missing file is absence, not the package run id.
72
+ */
73
+ export async function readStoredHostSessionId(
74
+ host: string | undefined,
75
+ authority: DurablePrincipalAuthority,
76
+ principal: DurablePrincipal,
77
+ ): Promise<string | undefined> {
78
+ if (host === undefined || host === DEFAULT_ROLE_TURN_HOST) return undefined;
63
79
  const description = lookupHostDescription(host) ?? lookupHeadlessHostDescription(host);
64
- if (description === undefined) {
65
- // Host selection already fails closed on an unregistered name (#510) long
66
- // before a turn dispatches; mirror the same fail-closed default here
67
- // rather than guessing at pi's binding for a name pi does not own.
68
- return () => Promise.resolve(false);
69
- }
70
- const sessionIdentity = createSessionIdentityAuthority(principalAuthority, description.sessionBindingFile);
71
- return async (principal) => (await sessionIdentity.load(principal)) !== undefined;
80
+ if (description === undefined) return undefined;
81
+ const sessionId = await createSessionIdentityAuthority(
82
+ authority,
83
+ description.sessionBindingFile,
84
+ ).load(principal);
85
+ if (sessionId === undefined || sessionId === "") return undefined;
86
+ return sessionId;
72
87
  }
@@ -14,6 +14,7 @@ import {
14
14
  INSPECTOR_SESSION_MATERIALS,
15
15
  NOTARY_SESSION_MATERIALS,
16
16
  PUBLIC_ROLE_RECORDS,
17
+ packagedRoleSessionMaterials,
17
18
  type PackagedRole,
18
19
  } from "./packaged-role-registry.ts";
19
20
 
@@ -99,7 +100,7 @@ export function loadMainRoleReferenceMaterials(role: MainRoleSession): Promise<s
99
100
  /** Gatekeeper province; notary reuses the public notary materials definition. */
100
101
  export const GATEKEEPER_SESSION_MATERIALS = {
101
102
  // #639: single authority — the public gatekeeper record owns the province list.
102
- gatekeeper: PUBLIC_ROLE_RECORDS.find((entry) => entry.role === "gatekeeper")!.sessionMaterials,
103
+ gatekeeper: packagedRoleSessionMaterials("gatekeeper")!,
103
104
  inspector: INSPECTOR_SESSION_MATERIALS,
104
105
  notary: NOTARY_SESSION_MATERIALS,
105
106
  } as const;
@@ -8,10 +8,9 @@ import type {
8
8
  AnyCanonicalSkillBinding,
9
9
  CanonicalSkillBinding,
10
10
  } from "./canonical-skill-binding.ts";
11
+ import { packagedRoleAcceptedText } from "./packaged-role-registry.ts";
11
12
  import {
12
- CODER_ACCEPTED_TEXT,
13
13
  CODER_OUTPUT_TOOL_NAME,
14
- FIXER_ACCEPTED_TEXT,
15
14
  FIXER_OUTPUT_TOOL_NAME,
16
15
  validateAcceptedWorkerDetails,
17
16
  type CoderOutput,
@@ -296,7 +295,7 @@ export function createFixerRoleRuntime(
296
295
  }
297
296
  const acceptedDetails = output;
298
297
  return {
299
- content: [{ type: "text" as const, text: FIXER_ACCEPTED_TEXT }],
298
+ content: [{ type: "text" as const, text: packagedRoleAcceptedText("fixer") }],
300
299
  details: acceptedDetails,
301
300
  terminate: true as const,
302
301
  };
@@ -436,7 +435,7 @@ export function createCoderRoleRuntime(
436
435
  }
437
436
  const acceptedDetails = output;
438
437
  return {
439
- content: [{ type: "text" as const, text: CODER_ACCEPTED_TEXT }],
438
+ content: [{ type: "text" as const, text: packagedRoleAcceptedText("coder") }],
440
439
  details: acceptedDetails,
441
440
  terminate: true as const,
442
441
  };
@@ -1,25 +0,0 @@
1
- import { auditorRunDirectory } from "./auditor-dossier-tool.js";
2
- import { runComplianceAudit, } from "./compliance-transport.js";
3
- import { readDoctorAuditSubjects, requireAuditMaterials, resolveAuditDossier, } from "./dossier-resolution.js";
4
- export const DOCTOR_AUDIT_TOOL_NAME = "ak_doctor_audit_decision";
5
- /**
6
- * Doctor compliance via public auditor activation (#675 / ADR 0062 / owner r11).
7
- * 审刑院 is an independent role; subject=doctor selects souls/doctor-auditor.md.
8
- */
9
- export function createPiDoctorAuditor() {
10
- return async (options) => {
11
- const dossier = resolveAuditDossier(options.context);
12
- requireAuditMaterials(dossier);
13
- const subjects = readDoctorAuditSubjects(options.context);
14
- requireAuditMaterials(subjects);
15
- return runComplianceAudit({
16
- subject: "doctor",
17
- context: options.context,
18
- ...(auditorRunDirectory(options.context) === undefined
19
- ? {}
20
- : { runDirectory: auditorRunDirectory(options.context) }),
21
- ...(options.signal === undefined ? {} : { signal: options.signal }),
22
- ...(options.summonAuditor === undefined ? {} : { summonAuditor: options.summonAuditor }),
23
- });
24
- };
25
- }
@@ -1,130 +0,0 @@
1
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.js";
2
- import { CliUsageError } from "./cli-errors.js";
3
- import { admitDiaristInvocation, bindAdmittedTicketNumber, buildInstructionTransportPrompt, relocateAdmittedRunToTicket, recordAdmittedCorrelation, } from "./invocation.js";
4
- import { prepareSummonsResumeMaterials, runPostAdmissionOneShot, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
5
- import { loadResumableDiaristRun, markRunAdmitted, } from "./run-lifecycle.js";
6
- import { presentStructuralRejection, trySettleDiaristTerminalResult, } from "./settlement.js";
7
- import { projectRoleTurnRequest, } from "./turn-request.js";
8
- import { readBoardTicketNumber } from "../run-ticket-number.js";
9
- /** Project admitted invocation onto the host-neutral turn request. */
10
- export function buildDiaristTurnRequest(admitted, options) {
11
- return projectRoleTurnRequest(admitted, { activation: { role: "diarist" } }, options);
12
- }
13
- /**
14
- * Board-bound ticket on pages → memory bind + unbound→ticket relocate under lease.
15
- * Shared by resume (interrupted board-bound unbound) and post-turn first assert.
16
- */
17
- async function bindAndRelocateDiaristIfBoardBound(admitted, authority, lease) {
18
- const boardTicket = await readBoardTicketNumber(admitted.runDirectory);
19
- if (boardTicket === undefined)
20
- return;
21
- if (admitted.ticketNumber === undefined) {
22
- await bindAdmittedTicketNumber(admitted, boardTicket);
23
- }
24
- await relocateAdmittedRunToTicket(admitted, authority, lease);
25
- }
26
- function diaristAdapters(env) {
27
- return {
28
- trySettle: (admitted, authority, scope) => trySettleDiaristTerminalResult(admitted, authority, scope),
29
- shouldPresentSettled: () => true,
30
- // Resume interrupted state: board ticket already on pages, run still under unbound/.
31
- beforeDispatch: async (admitted, lease) => {
32
- if (env.correlationId !== undefined && env.correlationId.trim() !== "") {
33
- await recordAdmittedCorrelation(admitted, env.correlationId);
34
- }
35
- await bindAndRelocateDiaristIfBoardBound(admitted, env.principalAuthority, lease);
36
- },
37
- // First post-turn assert: accept hook wrote board pages; relocate before lease release.
38
- afterDispatch: async (admitted, lease) => {
39
- await bindAndRelocateDiaristIfBoardBound(admitted, env.principalAuthority, lease);
40
- },
41
- };
42
- }
43
- export async function runPublicDiarist(argv, env, io, parseDiaristArgv) {
44
- let parsed;
45
- try {
46
- parsed = parseDiaristArgv(argv);
47
- }
48
- catch (error) {
49
- if (error instanceof CliUsageError) {
50
- presentStructuralRejection(error, io);
51
- return { exitCode: 2 };
52
- }
53
- throw error;
54
- }
55
- // #637 / #771 / ADR 0075 / #779 / #987: ticket identity is the LLM's typed
56
- // assertion on this turn, OR a typed handoff key already held by the caller
57
- // (countersign refresh bind). Code never pre-judges the summons text and never
58
- // freezes a candidate catalog. Public same-ticket resume-by-ticketNumber was
59
- // deleted (#987 Result 7); callers continue an existing diarist run only via
60
- // explicit `ak-role resume <runId>`. Handoff ticket remains a bind key only.
61
- const handoffTicket = env.boundTicketNumber;
62
- let admitted;
63
- try {
64
- admitted = await admitDiaristInvocation({
65
- home: env.home,
66
- principalAuthority: env.principalAuthority,
67
- cwd: env.cwd,
68
- instruction: parsed.instruction,
69
- attachmentPaths: parsed.attachmentPaths,
70
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
71
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
72
- ...(env.model === undefined ? {} : { model: env.model }),
73
- ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
74
- ...(handoffTicket === undefined ? {} : { assertedTicketNumber: handoffTicket }),
75
- });
76
- }
77
- catch (error) {
78
- if (error instanceof CliUsageError) {
79
- presentStructuralRejection(error, io);
80
- return { exitCode: 2 };
81
- }
82
- throw error;
83
- }
84
- await markRunAdmitted(admitted, env.principalAuthority);
85
- const turnProjection = {
86
- packageRoot: env.packageRoot,
87
- home: env.home,
88
- agentDir: env.agentDir,
89
- ...(env.model === undefined ? {} : { model: env.model }),
90
- ...pickEngineAxis(env),
91
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
92
- ...(env.correlationId === undefined || env.correlationId.trim() === ""
93
- ? {}
94
- : { correlationId: env.correlationId }),
95
- continuation: {
96
- kind: "initial",
97
- prompt: buildInstructionTransportPrompt(admitted, engineSessionMaterialFromOptions({
98
- ...pickEngineAxis(env),
99
- packageRoot: env.packageRoot,
100
- })),
101
- },
102
- };
103
- const turnRequest = buildDiaristTurnRequest(admitted, turnProjection);
104
- return await runPostAdmissionOneShot({
105
- admitted,
106
- env,
107
- io,
108
- request: turnRequest,
109
- adapters: diaristAdapters(env),
110
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
111
- });
112
- }
113
- /**
114
- * Resume a previously admitted Diarist run (#708 / ADR 0079 同票传召 = resume).
115
- * LLM re-finds materials; entry identity keeps the volume idempotent.
116
- */
117
- export async function runPublicDiaristResume(request, env, io) {
118
- return await runPostAdmissionSeatResume({
119
- request,
120
- env,
121
- io,
122
- load: (effective) => loadResumableDiaristRun(env.home, effective.runId, env.principalAuthority),
123
- buildTurnRequest: async (admitted, effective) => {
124
- const summonsPrepared = await prepareSummonsResumeMaterials(admitted.runDirectory, effective.summons);
125
- return buildDiaristTurnRequest(admitted, resumeTurnRequestProjectionOptions(admitted, effective, env, summonsPrepared));
126
- },
127
- adapters: diaristAdapters(env),
128
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
129
- });
130
- }
@@ -1,87 +0,0 @@
1
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.js";
2
- import { CliUsageError } from "./cli-errors.js";
3
- import { admitDoctorInvocation, buildDoctorTransportPrompt } from "./invocation.js";
4
- import { runPostAdmissionOneShot, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
5
- import { loadResumableDoctorRun, markRunAdmitted, } from "./run-lifecycle.js";
6
- import { presentStructuralRejection, trySettleDoctorTerminalResult, } from "./settlement.js";
7
- import { isLawfulTypedTerminalOutcome, } from "./terminal.js";
8
- import { projectRoleTurnRequest, } from "./turn-request.js";
9
- /** Project admitted invocation onto the host-neutral turn request. */
10
- export function buildDoctorTurnRequest(admitted, options) {
11
- return projectRoleTurnRequest(admitted, {
12
- activation: { role: "doctor", casePath: admitted.caseRunsPath },
13
- }, options);
14
- }
15
- export async function runPublicDoctor(argv, env, io, parseDoctorArgv) {
16
- let admitted;
17
- try {
18
- const parsed = parseDoctorArgv(argv);
19
- admitted = await admitDoctorInvocation({
20
- home: env.home,
21
- principalAuthority: env.principalAuthority,
22
- cwd: env.cwd,
23
- issueNumber: parsed.issueNumber,
24
- instruction: parsed.instruction,
25
- attachmentPaths: parsed.attachmentPaths,
26
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
27
- ...(parsed.runs === undefined ? {} : { runs: parsed.runs }),
28
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
29
- ...(env.model === undefined ? {} : { model: env.model }),
30
- });
31
- }
32
- catch (error) {
33
- if (error instanceof CliUsageError) {
34
- presentStructuralRejection(error, io);
35
- return { exitCode: 2 };
36
- }
37
- throw error;
38
- }
39
- await markRunAdmitted(admitted, env.principalAuthority);
40
- const turnRequest = buildDoctorTurnRequest(admitted, {
41
- packageRoot: env.packageRoot,
42
- home: env.home,
43
- agentDir: env.agentDir,
44
- ...(env.model === undefined ? {} : { model: env.model }),
45
- ...pickEngineAxis(env),
46
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
47
- ...(env.correlationId === undefined || env.correlationId.trim() === ""
48
- ? {}
49
- : { correlationId: env.correlationId }),
50
- continuation: {
51
- kind: "initial",
52
- prompt: buildDoctorTransportPrompt(admitted, engineSessionMaterialFromOptions({
53
- ...pickEngineAxis(env),
54
- packageRoot: env.packageRoot,
55
- })),
56
- },
57
- });
58
- return await runPostAdmissionOneShot({
59
- admitted,
60
- env,
61
- io,
62
- request: turnRequest,
63
- adapters: doctorAdapters(),
64
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
65
- });
66
- }
67
- function doctorAdapters() {
68
- return {
69
- trySettle: (admitted, authority, scope) => trySettleDoctorTerminalResult(admitted, authority, scope),
70
- shouldPresentSettled: (terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome),
71
- };
72
- }
73
- /**
74
- * Resume a previously admitted Doctor run (#633). Issue + retained case
75
- * identity restore from the durable admitted request; the session principal reopens.
76
- */
77
- export async function runPublicDoctorResume(request, env, io) {
78
- return await runPostAdmissionSeatResume({
79
- request,
80
- env,
81
- io,
82
- load: (effective) => loadResumableDoctorRun(env.home, effective.runId, env.principalAuthority),
83
- buildTurnRequest: (admitted, effective) => buildDoctorTurnRequest(admitted, resumeTurnRequestProjectionOptions(admitted, effective, env)),
84
- adapters: doctorAdapters(),
85
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
86
- });
87
- }
@@ -1,151 +0,0 @@
1
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.js";
2
- import { CliUsageError } from "./cli-errors.js";
3
- import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.js";
4
- import { admitInspectorInvocation, buildInspectorTransportPrompt, persistAdmittedSourceRunPath, } from "./invocation.js";
5
- import { prepareSummonsResumeMaterials, runPostAdmissionOneShot, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
6
- import { loadResumableInspectorRun, markRunAdmitted, parentRunPathFromGatePointerInstruction, } from "./run-lifecycle.js";
7
- import { presentStructuralRejection, trySettleInspectorTerminalResult, } from "./settlement.js";
8
- import { projectRoleTurnRequest, } from "./turn-request.js";
9
- function inspectorParentRunPath(admitted) {
10
- if (typeof admitted.sourceRunPath === "string" && admitted.sourceRunPath.trim() !== "") {
11
- return admitted.sourceRunPath;
12
- }
13
- return parentRunPathFromGatePointerInstruction(admitted.instruction);
14
- }
15
- /** Project admitted invocation onto the host-neutral turn request. */
16
- export function buildInspectorTurnRequest(admitted, options) {
17
- const sourceRun = inspectorParentRunPath(admitted);
18
- return projectRoleTurnRequest(admitted, {
19
- activation: {
20
- role: "inspector",
21
- ...(sourceRun === undefined ? {} : { sourceRun }),
22
- },
23
- }, options);
24
- }
25
- export async function runPublicInspector(argv, env, io, parseInspectorArgv) {
26
- let parsed;
27
- try {
28
- parsed = parseInspectorArgv(argv);
29
- }
30
- catch (error) {
31
- if (error instanceof CliUsageError) {
32
- presentStructuralRejection(error, io);
33
- return { exitCode: 2 };
34
- }
35
- throw error;
36
- }
37
- // #747: same parent (卷宗指针) → resume prior inspector run with this summons' materials.
38
- // #771: no mechanical ticket match against instruction text; parent-run path only.
39
- // No bare catch→fresh: lookup/resume failures surface; only true absence mints new.
40
- const projectRoot = parsed.project ?? env.cwd;
41
- // #747: parentRunPath is the pure 卷宗指针 path only — never reask/materials text.
42
- // #753/#786: gate re-ask / verbatim submission body ride summons.instruction on resume.
43
- const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction);
44
- if (parentRunPath !== undefined) {
45
- const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
46
- const summons = {
47
- sourceRunPath: parentRunPath,
48
- ...(resumeInstruction === undefined
49
- ? {
50
- instruction: parsed.instruction,
51
- instructionEmpty: parsed.instruction.trim() === "",
52
- }
53
- : { instruction: resumeInstruction, instructionEmpty: false }),
54
- attachmentPaths: parsed.attachmentPaths,
55
- };
56
- const resumed = await tryResumeSameTicketSeatRun({
57
- home: env.home,
58
- projectRoot,
59
- role: "inspector",
60
- parentRunPath,
61
- freshSummons: env.freshSummons,
62
- summons,
63
- resume: (runId, materials) => runPublicInspectorResume({ runId, ...(materials === undefined ? {} : { summons: materials }) }, env, io),
64
- });
65
- if (resumed !== undefined)
66
- return resumed;
67
- }
68
- let admitted;
69
- try {
70
- admitted = await admitInspectorInvocation({
71
- home: env.home,
72
- principalAuthority: env.principalAuthority,
73
- cwd: env.cwd,
74
- instruction: parsed.instruction,
75
- attachmentPaths: parsed.attachmentPaths,
76
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
77
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
78
- ...(env.model === undefined ? {} : { model: env.model }),
79
- ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
80
- });
81
- }
82
- catch (error) {
83
- if (error instanceof CliUsageError) {
84
- presentStructuralRejection(error, io);
85
- return { exitCode: 2 };
86
- }
87
- throw error;
88
- }
89
- await markRunAdmitted(admitted, env.principalAuthority);
90
- if (parentRunPath !== undefined) {
91
- await persistAdmittedSourceRunPath(admitted, parentRunPath);
92
- admitted = { ...admitted, sourceRunPath: parentRunPath };
93
- }
94
- const engineMaterial = engineSessionMaterialFromOptions({
95
- ...pickEngineAxis(env),
96
- packageRoot: env.packageRoot,
97
- });
98
- const turnRequest = buildInspectorTurnRequest(admitted, {
99
- packageRoot: env.packageRoot,
100
- home: env.home,
101
- agentDir: env.agentDir,
102
- ...(env.model === undefined ? {} : { model: env.model }),
103
- ...pickEngineAxis(env),
104
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
105
- ...(env.correlationId === undefined || env.correlationId.trim() === ""
106
- ? {}
107
- : { correlationId: env.correlationId }),
108
- continuation: {
109
- kind: "initial",
110
- // #879: gate first mint uses parent payload as content; binding stays typed activation.
111
- prompt: (env.reviewReask ?? env.gateReviewInstruction)
112
- ?? buildInspectorTransportPrompt(admitted, engineMaterial),
113
- },
114
- });
115
- return await runPostAdmissionOneShot({
116
- admitted,
117
- env,
118
- io,
119
- request: turnRequest,
120
- adapters: inspectorAdapters(),
121
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
122
- });
123
- }
124
- function inspectorAdapters(options) {
125
- return {
126
- trySettle: (admitted, authority, scope) => trySettleInspectorTerminalResult(admitted, authority, scope),
127
- shouldPresentSettled: () => true,
128
- ...(options?.beforeDispatch === undefined
129
- ? {}
130
- : { beforeDispatch: options.beforeDispatch }),
131
- };
132
- }
133
- /**
134
- * Resume a previously admitted Inspector run (#633 / #637); the session principal reopens.
135
- * Same-ticket summons deliver this turn's instruction + frozen attachments; manual
136
- * resume forwards only caller-supplied message bytes.
137
- */
138
- export async function runPublicInspectorResume(request, env, io) {
139
- return await runPostAdmissionSeatResume({
140
- request,
141
- env,
142
- io,
143
- load: (effective) => loadResumableInspectorRun(env.home, effective.runId, env.principalAuthority),
144
- buildTurnRequest: async (admitted, effective) => {
145
- const summonsPrepared = await prepareSummonsResumeMaterials(admitted.runDirectory, effective.summons);
146
- return buildInspectorTurnRequest(admitted, resumeTurnRequestProjectionOptions(admitted, effective, env, summonsPrepared));
147
- },
148
- adapters: inspectorAdapters(),
149
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
150
- });
151
- }
@@ -1,114 +0,0 @@
1
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.js";
2
- import { CliUsageError } from "./cli-errors.js";
3
- import { admitJudgeInvocation, buildJudgeTransportPrompt, } from "./invocation.js";
4
- import { loadResumableJudgeRun, markRunAdmitted, buildAutoResumeContinuationPrompt, } from "./run-lifecycle.js";
5
- import { presentStructuralRejection, readEngineDetourInfrastructureFailure, trySettleJudgeTerminalResult, } from "./settlement.js";
6
- import { projectRoleTurnRequest, } from "./turn-request.js";
7
- import { runPostAdmissionResumable, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
8
- /** Project admitted invocation onto the host-neutral turn request. */
9
- export function buildJudgeTurnRequest(admitted, options) {
10
- return projectRoleTurnRequest(admitted, { activation: { role: "judge" } }, options);
11
- }
12
- function judgeAdapters() {
13
- return {
14
- trySettle: (admitted, authority, scope) => trySettleJudgeTerminalResult(admitted, authority, scope),
15
- resolveRunnerKnownFailure: async ({ result, sessionFile }) => {
16
- const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
17
- return (result.knownFailure ??
18
- (infrastructureFailure === undefined
19
- ? undefined
20
- : {
21
- ...(infrastructureFailure.cause === undefined
22
- ? {}
23
- : { cause: infrastructureFailure.cause }),
24
- diagnostic: infrastructureFailure.diagnostic,
25
- ...(infrastructureFailure.identity === undefined
26
- ? {}
27
- : { identity: infrastructureFailure.identity }),
28
- }));
29
- },
30
- };
31
- }
32
- export async function runPublicJudge(argv, env, io, parseJudgeArgv) {
33
- let admitted;
34
- try {
35
- const parsed = parseJudgeArgv(argv);
36
- admitted = await admitJudgeInvocation({
37
- home: env.home,
38
- principalAuthority: env.principalAuthority,
39
- cwd: env.cwd,
40
- instruction: parsed.instruction,
41
- attachmentPaths: parsed.attachmentPaths,
42
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
43
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
44
- ...(env.model === undefined ? {} : { model: env.model }),
45
- });
46
- }
47
- catch (error) {
48
- if (error instanceof CliUsageError) {
49
- presentStructuralRejection(error, io);
50
- return { exitCode: 2 };
51
- }
52
- throw error;
53
- }
54
- await markRunAdmitted(admitted, env.principalAuthority);
55
- return await runPostAdmissionResumable({
56
- admitted,
57
- env,
58
- io,
59
- buildInitialRequest: () => buildJudgeTurnRequest(admitted, {
60
- packageRoot: env.packageRoot,
61
- home: env.home,
62
- agentDir: env.agentDir,
63
- ...(env.model === undefined ? {} : { model: env.model }),
64
- ...pickEngineAxis(env),
65
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
66
- ...(admitted.correlationId === undefined && env.correlationId === undefined
67
- ? {}
68
- : { correlationId: admitted.correlationId ?? env.correlationId }),
69
- continuation: {
70
- kind: "initial",
71
- prompt: buildJudgeTransportPrompt(admitted, engineSessionMaterialFromOptions({
72
- ...pickEngineAxis(env),
73
- packageRoot: env.packageRoot,
74
- })),
75
- },
76
- }),
77
- buildResumeRequest: () => buildJudgeTurnRequest(admitted, {
78
- packageRoot: env.packageRoot,
79
- home: env.home,
80
- agentDir: env.agentDir,
81
- ...(env.model === undefined ? {} : { model: env.model }),
82
- ...pickEngineAxis(env),
83
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
84
- ...(admitted.correlationId === undefined && env.correlationId === undefined
85
- ? {}
86
- : { correlationId: admitted.correlationId ?? env.correlationId }),
87
- continuation: {
88
- kind: "resume",
89
- prompt: buildAutoResumeContinuationPrompt({
90
- packageRoot: env.packageRoot,
91
- ...pickEngineAxis(env),
92
- }),
93
- },
94
- }),
95
- adapters: judgeAdapters(),
96
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
97
- });
98
- }
99
- /**
100
- * Resume a previously admitted Role run after a typed HTTP 429 interruption.
101
- * Restores role/project/instruction/attachments/session identity; model override
102
- * is temporary for this invocation only.
103
- */
104
- export async function runPublicResume(request, env, io) {
105
- return await runPostAdmissionSeatResume({
106
- request,
107
- env,
108
- io,
109
- load: (effective) => loadResumableJudgeRun(env.home, effective.runId, env.principalAuthority),
110
- buildTurnRequest: (admitted, effective) => buildJudgeTurnRequest(admitted, resumeTurnRequestProjectionOptions(admitted, effective, env)),
111
- adapters: judgeAdapters(),
112
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
113
- });
114
- }