@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
@@ -1,294 +0,0 @@
1
- /**
2
- * Public Merger Role run: read Git materials → force package merge-only method
3
- * → post-admission coordinator → settle Terminal result (#114 / #517 / #827).
4
- * #526: execution via RoleTurnHost; argv is Pi adapter internal.
5
- */
6
- import type {
7
- MethodBinding,
8
- RoleTurnKnownFailure,
9
- RoleTurnRequest,
10
- } from "../host-contracts.ts";
11
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.ts";
12
- import {
13
- loadPackagedMethodSkillMaterial,
14
- resolvePackagedMethodSkillPath,
15
- type PackagedMethodSkillMaterial,
16
- type PackagedMethodSkillProvenance,
17
- } from "../package-resources/method-skill.ts";
18
- import { CliUsageError } from "./cli-errors.ts";
19
- import {
20
- admitMergerInvocation,
21
- buildMergerTransportPrompt,
22
- type AdmittedMergerInvocation,
23
- } from "./invocation.ts";
24
- import {
25
- loadResumableMergerRun,
26
- markRunAdmitted,
27
- buildAutoResumeContinuationPrompt,
28
- type PublicResumeRequest,
29
- } from "./run-lifecycle.ts";
30
- import {
31
- isLawfulTypedTerminalOutcome,
32
- presentStructuralRejection,
33
- trySettleMergerTerminalResult,
34
- } from "./settlement.ts";
35
- import type { CliIo } from "./cli-io.ts";
36
- import type { TerminalResult } from "./terminal.ts";
37
- import {
38
- projectRoleTurnRequest,
39
- type RoleTurnRequestProjectionOptions,
40
- } from "./turn-request.ts";
41
- import {
42
- presentControlledFailure,
43
- resolveResumeMethodMaterialAdapters,
44
- runPostAdmissionResumable,
45
- runPostAdmissionSeatResume,
46
- type PostAdmissionAdapters,
47
- type PostAdmissionEnv,
48
- resumeTurnRequestProjectionOptions,
49
- } from "./post-admission.ts";
50
-
51
- export type MergerRunEnv = PostAdmissionEnv & {
52
- createRunId?: () => string;
53
- };
54
-
55
- function mergerMethods(packageRoot: string): readonly MethodBinding[] {
56
- return [
57
- {
58
- kind: "skill",
59
- path: resolvePackagedMethodSkillPath(packageRoot, "resolving-merge-conflicts"),
60
- },
61
- ];
62
- }
63
-
64
- /** Project admitted Merger invocation onto the host-neutral turn request. */
65
- export function buildMergerTurnRequest(
66
- admitted: AdmittedMergerInvocation,
67
- options: RoleTurnRequestProjectionOptions,
68
- ): RoleTurnRequest {
69
- return projectRoleTurnRequest(
70
- admitted,
71
- {
72
- activation: {
73
- role: "merger",
74
- inputPath: admitted.mergerInputPath,
75
- },
76
- methods: mergerMethods(options.packageRoot),
77
- },
78
- options,
79
- );
80
- }
81
-
82
- function mergerAdapters(
83
- packageRoot: string,
84
- methodMaterial?: PackagedMethodSkillMaterial,
85
- ): PostAdmissionAdapters<AdmittedMergerInvocation> {
86
- return {
87
- trySettle: (admitted, authority, scope) =>
88
- methodMaterial === undefined
89
- ? Promise.resolve(undefined)
90
- : trySettleMergerTerminalResult(
91
- admitted,
92
- authority,
93
- {
94
- methodProvenance: methodMaterial.provenance,
95
- methodSkillPath: methodMaterial.skillPath,
96
- methodSkillConfiguredPath: resolvePackagedMethodSkillPath(
97
- packageRoot,
98
- "resolving-merge-conflicts",
99
- ),
100
- },
101
- scope,
102
- ),
103
- shouldPresentSettled: (t) =>
104
- isLawfulTypedTerminalOutcome(t.roleOutcome),
105
- };
106
- }
107
-
108
- async function loadMergerMethodMaterial(
109
- packageRoot: string,
110
- ): Promise<PackagedMethodSkillMaterial> {
111
- return await loadPackagedMethodSkillMaterial(
112
- packageRoot,
113
- "resolving-merge-conflicts",
114
- );
115
- }
116
-
117
- function mergerTurnOptions(
118
- admitted: AdmittedMergerInvocation,
119
- env: MergerRunEnv,
120
- ): {
121
- packageRoot: string;
122
- home: string;
123
- agentDir: string;
124
- model?: import("./config.ts").SeatModelConfig;
125
- engine?: string;
126
- engineModel?: string;
127
- timeoutMs?: number;
128
- correlationId?: string;
129
- } {
130
- return {
131
- packageRoot: env.packageRoot,
132
- home: env.home,
133
- agentDir: env.agentDir,
134
- ...(env.model === undefined ? {} : { model: env.model }),
135
- ...pickEngineAxis(env),
136
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
137
- ...(admitted.correlationId === undefined && env.correlationId === undefined
138
- ? {}
139
- : { correlationId: admitted.correlationId ?? env.correlationId }),
140
- };
141
- }
142
-
143
- export async function runPublicMerger(
144
- argv: readonly string[],
145
- env: MergerRunEnv,
146
- io: CliIo,
147
- parseMergerArgv: (args: readonly string[]) => {
148
- instruction: string;
149
- attachmentPaths: string[];
150
- project?: string;
151
- },
152
- ): Promise<{
153
- exitCode: number;
154
- admitted?: AdmittedMergerInvocation;
155
- terminal?: TerminalResult;
156
- }> {
157
- let parsed: {
158
- instruction: string;
159
- attachmentPaths: string[];
160
- project?: string;
161
- };
162
- try {
163
- parsed = parseMergerArgv(argv);
164
- } catch (error) {
165
- if (error instanceof CliUsageError) {
166
- presentStructuralRejection(error, io);
167
- return { exitCode: 2 };
168
- }
169
- throw error;
170
- }
171
-
172
- let admitted: AdmittedMergerInvocation;
173
- try {
174
- admitted = await admitMergerInvocation({
175
- home: env.home,
176
- principalAuthority: env.principalAuthority,
177
- cwd: env.cwd,
178
- instruction: parsed.instruction,
179
- attachmentPaths: parsed.attachmentPaths,
180
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
181
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
182
- ...(env.model === undefined ? {} : { model: env.model }),
183
- });
184
- } catch (error) {
185
- if (error instanceof CliUsageError) {
186
- presentStructuralRejection(error, io);
187
- return { exitCode: 2 };
188
- }
189
- throw error;
190
- }
191
-
192
- await markRunAdmitted(admitted, env.principalAuthority);
193
-
194
- let methodMaterial: PackagedMethodSkillMaterial;
195
- try {
196
- methodMaterial = await loadMergerMethodMaterial(env.packageRoot);
197
- } catch (error) {
198
- return (await presentControlledFailure(
199
- admitted,
200
- {
201
- timedOut: false,
202
- code: null,
203
- stderr: "",
204
- thrown: error,
205
- knownCause: "activation",
206
- },
207
- mergerAdapters(env.packageRoot),
208
- env.principalAuthority,
209
- io,
210
- )) as { exitCode: number; admitted: AdmittedMergerInvocation; terminal: TerminalResult };
211
- }
212
-
213
- return await runPostAdmissionResumable({
214
- admitted,
215
- env,
216
- io,
217
- buildInitialRequest: () =>
218
- buildMergerTurnRequest(admitted, {
219
- ...mergerTurnOptions(admitted, env),
220
- continuation: {
221
- kind: "initial",
222
- prompt: buildMergerTransportPrompt(
223
- admitted,
224
- engineSessionMaterialFromOptions({
225
- ...pickEngineAxis(env),
226
- packageRoot: env.packageRoot,
227
- }),
228
- ),
229
- },
230
- }),
231
- buildResumeRequest: () =>
232
- buildMergerTurnRequest(admitted, {
233
- packageRoot: env.packageRoot,
234
- home: env.home,
235
- agentDir: env.agentDir,
236
- ...(env.model === undefined ? {} : { model: env.model }),
237
- ...pickEngineAxis(env),
238
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
239
- ...(admitted.correlationId === undefined && env.correlationId === undefined
240
- ? {}
241
- : { correlationId: admitted.correlationId ?? env.correlationId }),
242
- continuation: {
243
- kind: "resume",
244
- prompt: buildAutoResumeContinuationPrompt({
245
- packageRoot: env.packageRoot,
246
- ...pickEngineAxis(env),
247
- }),
248
- },
249
- }),
250
- adapters: mergerAdapters(env.packageRoot, methodMaterial),
251
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
252
- });
253
- }
254
-
255
- /**
256
- * Resume a previously admitted Merger Role run after a typed HTTP 429.
257
- * Restores derived input/session identity; model override is temporary.
258
- */
259
- export async function runPublicMergerResume(
260
- request: PublicResumeRequest,
261
- env: MergerRunEnv,
262
- io: CliIo,
263
- ): Promise<{
264
- exitCode: number;
265
- admitted?: AdmittedMergerInvocation;
266
- terminal?: TerminalResult;
267
- }> {
268
- return await runPostAdmissionSeatResume({
269
- request,
270
- env,
271
- io,
272
- load: (effective) =>
273
- loadResumableMergerRun(env.home, effective.runId, env.principalAuthority),
274
- buildTurnRequest: (admitted, effective) =>
275
- buildMergerTurnRequest(
276
- admitted,
277
- resumeTurnRequestProjectionOptions(admitted, effective, env),
278
- ),
279
- adapters: mergerAdapters(env.packageRoot),
280
- afterAdmittedLoad: (admitted) =>
281
- resolveResumeMethodMaterialAdapters({
282
- admitted,
283
- authority: env.principalAuthority,
284
- io,
285
- loadMaterial: () => loadMergerMethodMaterial(env.packageRoot),
286
- adaptersWith: (material) => mergerAdapters(env.packageRoot, material),
287
- emptyAdapters: mergerAdapters(env.packageRoot),
288
- knownCause: "activation",
289
- }),
290
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
291
- });
292
- }
293
-
294
- export type { RoleTurnKnownFailure, PackagedMethodSkillProvenance };
@@ -1,279 +0,0 @@
1
- /**
2
- * Public Notary Role run: admit source-run locator → shared post-admission coordinator
3
- * → settle Terminal result (#448 / #517). Explicit new has zero caller
4
- * prompt/attachment; explicit resume accepts the shared optional caller message.
5
- * Lifecycle is the shared post-admission seam; this module keeps only Notary adapters.
6
- * #637 / #747: same-parent (--source-run) re-summons resume the seat's previous run.
7
- */
8
- import type { DurablePrincipalAuthority, RoleTurnRequest } from "../host-contracts.ts";
9
- import {
10
- NotarySourceRunError,
11
- resolveNotarySourceRunLocator,
12
- } from "../notary-source-run.ts";
13
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.ts";
14
- import { CliUsageError } from "./cli-errors.ts";
15
- import {
16
- admitNotaryInvocation,
17
- buildNotaryTransportPrompt,
18
- type AdmittedNotaryInvocation,
19
- type ParseNotaryArgvResult,
20
- } from "./invocation.ts";
21
- import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.ts";
22
- import {
23
- prepareSummonsResumeMaterials,
24
- runPostAdmissionOneShot,
25
- type PostAdmissionAdapters,
26
- type PostAdmissionEnv,
27
- runPostAdmissionSeatResume,
28
- resumeTurnRequestProjectionOptions,
29
- } from "./post-admission.ts";
30
- import {
31
- loadResumableNotaryRun,
32
- markRunAdmitted,
33
- type PublicResumeRequest,
34
- type SameTicketSummonsMaterials,
35
- } from "./run-lifecycle.ts";
36
- import {
37
- presentStructuralRejection,
38
- trySettleNotaryTerminalResult,
39
- } from "./settlement.ts";
40
- import type { CliIo } from "./cli-io.ts";
41
- import type { TerminalResult } from "./terminal.ts";
42
- import {
43
- projectRoleTurnRequest,
44
- type RoleTurnRequestProjectionOptions,
45
- } from "./turn-request.ts";
46
-
47
- export type NotaryRunEnv = PostAdmissionEnv & {
48
- principalAuthority: DurablePrincipalAuthority;
49
- createRunId?: () => string;
50
- /**
51
- * #753 nested gate re-ask: plain-language instruction on same-ticket resume.
52
- * Only set by summonPublicRole when the prior officer reply was not three-state.
53
- * Never a public CLI argv — external callers still have zero prompt.
54
- */
55
- reviewReask?: string;
56
- /**
57
- * #879 gate summons: verbatim parent-submission body for officer dialogue content.
58
- * Rides summons.instruction / first-mint prompt when reviewReask is absent.
59
- * Binding pointer stays --source-run (independent machine material).
60
- */
61
- gateReviewInstruction?: string;
62
- };
63
-
64
- /** Project admitted invocation onto the host-neutral turn request. */
65
- export function buildNotaryTurnRequest(
66
- admitted: AdmittedNotaryInvocation,
67
- options: RoleTurnRequestProjectionOptions,
68
- ): RoleTurnRequest {
69
- return projectRoleTurnRequest(
70
- admitted,
71
- {
72
- activation: {
73
- role: "notary" as const,
74
- sourceRun: admitted.sourceRunPath,
75
- // Ticket from source-run admitted form rides activation → flag → role read surface (#635).
76
- ...(admitted.ticketNumber === undefined
77
- ? {}
78
- : { ticketNumber: admitted.ticketNumber }),
79
- },
80
- },
81
- options,
82
- );
83
- }
84
-
85
- export async function runPublicNotary(
86
- argv: readonly string[],
87
- env: NotaryRunEnv,
88
- io: CliIo,
89
- parseNotaryArgv: (args: readonly string[]) => ParseNotaryArgvResult,
90
- ): Promise<{
91
- exitCode: number;
92
- admitted?: AdmittedNotaryInvocation;
93
- terminal?: TerminalResult;
94
- }> {
95
- let parsed: ParseNotaryArgvResult;
96
- try {
97
- parsed = parseNotaryArgv(argv);
98
- } catch (error) {
99
- if (error instanceof CliUsageError) {
100
- presentStructuralRejection(error, io);
101
- return { exitCode: 2 };
102
- }
103
- throw error;
104
- }
105
-
106
- // #637: same ticket → resume prior notary run with this summons' source-run pointer.
107
- // Source-run structural failures stay usage rejections; lookup/resume failures surface
108
- // (no bare catch→fresh). Only true absence of a prior run mints new.
109
- const projectRoot = parsed.project ?? env.cwd;
110
- let source;
111
- try {
112
- source = await resolveNotarySourceRunLocator({
113
- projectRoot,
114
- sourceRun: parsed.sourceRun,
115
- home: env.home,
116
- });
117
- } catch (error) {
118
- if (error instanceof NotarySourceRunError) {
119
- presentStructuralRejection(new CliUsageError(error.message, { cause: error }), io);
120
- return { exitCode: 2 };
121
- }
122
- throw error;
123
- }
124
- // #747: officer resume key is this parent source-run path (not ticket number).
125
- // #753/#879: gate re-ask and verbatim submission body share summons.instruction
126
- // (reask wins when both present; no parallel stack). Binding stays sourceRunPath.
127
- {
128
- const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
129
- const summons: SameTicketSummonsMaterials = {
130
- sourceRunPath: source.runDirectory,
131
- sourceRun: source,
132
- ...(resumeInstruction === undefined
133
- ? {}
134
- : { instruction: resumeInstruction, instructionEmpty: false }),
135
- };
136
- const resumed = await tryResumeSameTicketSeatRun({
137
- home: env.home,
138
- projectRoot,
139
- role: "notary",
140
- parentRunPath: source.runDirectory,
141
- freshSummons: env.freshSummons,
142
- summons,
143
- resume: (runId, materials) =>
144
- runPublicNotaryResume(
145
- { runId, ...(materials === undefined ? {} : { summons: materials }) },
146
- env,
147
- io,
148
- ),
149
- });
150
- if (resumed !== undefined) return resumed;
151
- }
152
-
153
- let admitted: AdmittedNotaryInvocation;
154
- try {
155
- admitted = await admitNotaryInvocation({
156
- home: env.home,
157
- principalAuthority: env.principalAuthority,
158
- cwd: env.cwd,
159
- sourceRun: parsed.sourceRun,
160
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
161
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
162
- ...(env.model === undefined ? {} : { model: env.model }),
163
- ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
164
- });
165
- } catch (error) {
166
- if (error instanceof CliUsageError) {
167
- presentStructuralRejection(error, io);
168
- return { exitCode: 2 };
169
- }
170
- throw error;
171
- }
172
-
173
- await markRunAdmitted(admitted, env.principalAuthority);
174
-
175
- const engineMaterial = engineSessionMaterialFromOptions({
176
- ...pickEngineAxis(env),
177
- packageRoot: env.packageRoot,
178
- });
179
- const turnRequest = buildNotaryTurnRequest(admitted, {
180
- packageRoot: env.packageRoot,
181
- home: env.home,
182
- agentDir: env.agentDir,
183
- ...(env.model === undefined ? {} : { model: env.model }),
184
- ...pickEngineAxis(env),
185
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
186
- ...(env.correlationId === undefined || env.correlationId.trim() === ""
187
- ? {}
188
- : { correlationId: env.correlationId }),
189
- continuation: {
190
- kind: "initial",
191
- // #879: gate path first mint carries parent payload as dialogue content;
192
- // external zero-prompt kickoff unchanged when no body/reask.
193
- prompt: (env.reviewReask ?? env.gateReviewInstruction)
194
- ?? buildNotaryTransportPrompt(admitted, engineMaterial),
195
- },
196
- });
197
-
198
- return await runPostAdmissionOneShot({
199
- admitted,
200
- env,
201
- io,
202
- request: turnRequest,
203
- adapters: notaryAdapters(),
204
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
205
- });
206
- }
207
-
208
- function notaryAdapters(): PostAdmissionAdapters<AdmittedNotaryInvocation> {
209
- return {
210
- trySettle: (admitted, authority, scope) => trySettleNotaryTerminalResult(admitted, authority, scope),
211
- // Accepted receipts and failure terminals both present via shared path.
212
- shouldPresentSettled: () => true,
213
- };
214
- }
215
-
216
- /**
217
- * Resume a previously admitted Notary run (#633 / #637). Manual resume restores
218
- * source-run from the durable admitted request. Same-ticket re-summons deliver
219
- * this turn's source-run activation pointer while reopening the same session.
220
- */
221
- export async function runPublicNotaryResume(
222
- request: PublicResumeRequest,
223
- env: NotaryRunEnv,
224
- io: CliIo,
225
- ): Promise<{
226
- exitCode: number;
227
- admitted?: AdmittedNotaryInvocation;
228
- terminal?: TerminalResult;
229
- }> {
230
- return await runPostAdmissionSeatResume({
231
- request,
232
- env,
233
- io,
234
- load: async (effective) => {
235
- const loaded = await loadResumableNotaryRun(
236
- env.home,
237
- effective.runId,
238
- env.principalAuthority,
239
- );
240
- const summons = effective.summons;
241
- if (
242
- summons?.sourceRunPath !== undefined &&
243
- summons.sourceRun !== undefined
244
- ) {
245
- return {
246
- admitted: {
247
- ...loaded.admitted,
248
- sourceRunPath: summons.sourceRunPath,
249
- sourceRun: summons.sourceRun,
250
- },
251
- };
252
- }
253
- return loaded;
254
- },
255
- buildTurnRequest: async (admitted, effective) => {
256
- // #755: review continuation is plain dialogue / resume envelope — no
257
- //「重新读」candidate line, no engine handbook packaging.
258
- // #753: non-three-state re-ask rides as summons.instruction (人话重问).
259
- const summonsPrepared =
260
- effective.summons === undefined
261
- ? undefined
262
- : await prepareSummonsResumeMaterials(
263
- admitted.runDirectory,
264
- effective.summons,
265
- );
266
- return buildNotaryTurnRequest(
267
- admitted,
268
- resumeTurnRequestProjectionOptions(
269
- admitted,
270
- effective,
271
- env,
272
- summonsPrepared,
273
- ),
274
- );
275
- },
276
- adapters: notaryAdapters(),
277
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
278
- });
279
- }