@akagilnc/pi-workflow-roles 0.1.4802 → 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 (142) 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/src/acp-host/role-turn-host.ts +4 -1
  64. package/src/analyst-metric-families/acceptance-success-rework.ts +3 -2
  65. package/src/auditor-role.ts +1 -2
  66. package/src/auditor-soul.ts +1 -1
  67. package/src/collector-role.ts +2 -2
  68. package/src/countersign-contracts.ts +0 -1
  69. package/src/countersign-role.ts +1 -1
  70. package/src/diarist-contracts.ts +0 -1
  71. package/src/diarist-role.ts +0 -1
  72. package/src/doctor-auditor.ts +1 -2
  73. package/src/doctor-contracts.ts +1 -1
  74. package/src/doctor-role.ts +3 -2
  75. package/src/external-host-turn-loop.ts +1 -1
  76. package/src/factory-board.ts +10 -7
  77. package/src/gatekeeper-role.ts +16 -10
  78. package/src/gleaner-left-contracts.ts +0 -1
  79. package/src/gleaner-left-role.ts +0 -1
  80. package/src/headless-host/role-turn-host.ts +7 -1
  81. package/src/host-contracts.ts +10 -6
  82. package/src/inspector-contracts.ts +0 -1
  83. package/src/inspector-role.ts +0 -2
  84. package/src/institutional-resolution.ts +6 -4
  85. package/src/judge-role.ts +3 -3
  86. package/src/merger-contracts.ts +0 -1
  87. package/src/merger-role.ts +2 -2
  88. package/src/navigator-public-session.ts +7 -6
  89. package/src/navigator-work-context.ts +6 -8
  90. package/src/notary-contracts.ts +0 -1
  91. package/src/notary-role.ts +2 -3
  92. package/src/package-contracts/auditor-output.ts +0 -1
  93. package/src/package-contracts/collector-output.ts +0 -1
  94. package/src/package-contracts/fixer-output.ts +0 -1
  95. package/src/package-contracts/gatekeeper-output.ts +0 -1
  96. package/src/package-contracts/judge-output.ts +0 -1
  97. package/src/package-contracts/navigator-output.ts +0 -1
  98. package/src/package-contracts/reviewer-output.ts +0 -1
  99. package/src/package-contracts/terminating-tools.ts +27 -99
  100. package/src/package-contracts/worker-output.ts +0 -2
  101. package/src/packaged-role-registry.ts +604 -35
  102. package/src/pi/role-turn-host.ts +2 -1
  103. package/src/public-cli/cli.ts +64 -259
  104. package/src/public-cli/config.ts +18 -10
  105. package/src/public-cli/countersign-run.ts +14 -449
  106. package/src/public-cli/instruction-seat-run.ts +758 -277
  107. package/src/public-cli/invocation.ts +1097 -2051
  108. package/src/public-cli/option-definitions.ts +62 -127
  109. package/src/public-cli/post-admission.ts +47 -2
  110. package/src/public-cli/run-lifecycle.ts +303 -613
  111. package/src/public-cli/seat-ticket-binding.ts +6 -0
  112. package/src/public-cli/settlement.ts +399 -1185
  113. package/src/public-cli/turn-request.ts +92 -1
  114. package/src/public-role-summons.ts +44 -128
  115. package/src/reviewer-role.ts +3 -2
  116. package/src/role-activation-flags.ts +20 -41
  117. package/src/role-runtime-dependencies.ts +25 -26
  118. package/src/role-runtime.ts +121 -232
  119. package/src/secretariat-contracts.ts +0 -1
  120. package/src/secretariat-role.ts +0 -2
  121. package/src/session-identity.ts +23 -8
  122. package/src/session-opening-materials.ts +2 -1
  123. package/src/worker-role.ts +3 -4
  124. package/dist/doctor-auditor.js +0 -25
  125. package/dist/public-cli/diarist-run.js +0 -130
  126. package/dist/public-cli/doctor-run.js +0 -87
  127. package/dist/public-cli/inspector-run.js +0 -151
  128. package/dist/public-cli/judge-run.js +0 -114
  129. package/dist/public-cli/notary-run.js +0 -174
  130. package/dist/public-cli/reviewer-run.js +0 -339
  131. package/src/public-cli/coder-run.ts +0 -255
  132. package/src/public-cli/collector-run.ts +0 -189
  133. package/src/public-cli/diarist-run.ts +0 -233
  134. package/src/public-cli/doctor-run.ts +0 -167
  135. package/src/public-cli/fixer-run.ts +0 -265
  136. package/src/public-cli/gleaner-left-run.ts +0 -167
  137. package/src/public-cli/inspector-run.ts +0 -261
  138. package/src/public-cli/judge-run.ts +0 -196
  139. package/src/public-cli/merger-run.ts +0 -294
  140. package/src/public-cli/notary-run.ts +0 -279
  141. package/src/public-cli/reviewer-run.ts +0 -480
  142. package/src/public-cli/secretariat-run.ts +0 -265
@@ -1,255 +0,0 @@
1
- /**
2
- * Public Coder Role run: admit → post-admission coordinator → settle Terminal result (#109 / #517).
3
- * #109: package-owned TDD method, default apply / explicit plan, shared #106 success interface.
4
- * #526: execution via RoleTurnHost; argv is Pi adapter internal.
5
- */
6
- import type {
7
- DurablePrincipalAuthority,
8
- MethodBinding,
9
- RoleTurnKnownFailure,
10
- RoleTurnRequest,
11
- } from "../host-contracts.ts";
12
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.ts";
13
- import {
14
- loadPackagedMethodSkillMaterial,
15
- resolvePackagedMethodSkillPath,
16
- type PackagedMethodSkillProvenance,
17
- } from "../package-resources/method-skill.ts";
18
- import { CliUsageError } from "./cli-errors.ts";
19
- import {
20
- admitCoderInvocation,
21
- buildCoderTransportPrompt,
22
- type AdmittedCoderInvocation,
23
- } from "./invocation.ts";
24
- import {
25
- buildAutoResumeContinuationPrompt,
26
- loadResumableCoderRun,
27
- markRunAdmitted,
28
- type PublicResumeRequest,
29
- } from "./run-lifecycle.ts";
30
- import {
31
- presentStructuralRejection,
32
- trySettleCoderTerminalResult,
33
- } from "./settlement.ts";
34
- import type { CliIo } from "./cli-io.ts";
35
- import type { TerminalResult } from "./terminal.ts";
36
- import {
37
- projectRoleTurnRequest,
38
- type RoleTurnRequestProjectionOptions,
39
- } from "./turn-request.ts";
40
- import {
41
- presentControlledFailure,
42
- resolveResumeMethodMaterialAdapters,
43
- runPostAdmissionResumable,
44
- runPostAdmissionSeatResume,
45
- type PostAdmissionAdapters,
46
- type PostAdmissionEnv,
47
- resumeTurnRequestProjectionOptions,
48
- } from "./post-admission.ts";
49
-
50
- export type CoderRunEnv = PostAdmissionEnv & {
51
- createRunId?: () => string;
52
- };
53
-
54
- function coderMethods(
55
- phase: string,
56
- packageRoot: string,
57
- ): readonly MethodBinding[] {
58
- return phase === "apply"
59
- ? [{ kind: "skill", path: resolvePackagedMethodSkillPath(packageRoot, "tdd") }]
60
- : [];
61
- }
62
-
63
- /** Project admitted Coder invocation onto the host-neutral turn request. */
64
- export function buildCoderTurnRequest(
65
- admitted: AdmittedCoderInvocation,
66
- options: RoleTurnRequestProjectionOptions,
67
- ): RoleTurnRequest {
68
- return projectRoleTurnRequest(
69
- admitted,
70
- {
71
- activation: {
72
- role: "coder",
73
- phase: admitted.phase,
74
- taskPath: admitted.taskPath,
75
- },
76
- methods: coderMethods(admitted.phase, options.packageRoot),
77
- },
78
- options,
79
- );
80
- }
81
-
82
- function coderAdapters(
83
- methodProvenance?: PackagedMethodSkillProvenance,
84
- ): PostAdmissionAdapters<AdmittedCoderInvocation> {
85
- return {
86
- trySettle: (admitted, authority, scope) =>
87
- trySettleCoderTerminalResult(
88
- admitted,
89
- authority,
90
- {
91
- ...(methodProvenance === undefined ? {} : { methodProvenance }),
92
- },
93
- scope,
94
- ),
95
- };
96
- }
97
-
98
- export async function runPublicCoder(
99
- argv: readonly string[],
100
- env: CoderRunEnv,
101
- io: CliIo,
102
- parseCoderArgv: (args: readonly string[]) => {
103
- phase: "plan" | "apply";
104
- instruction: string;
105
- attachmentPaths: string[];
106
- project?: string;
107
- },
108
- ): Promise<{
109
- exitCode: number;
110
- admitted?: AdmittedCoderInvocation;
111
- terminal?: TerminalResult;
112
- }> {
113
- let admitted: AdmittedCoderInvocation;
114
- try {
115
- const parsed = parseCoderArgv(argv);
116
- admitted = await admitCoderInvocation({
117
- home: env.home,
118
- principalAuthority: env.principalAuthority,
119
- cwd: env.cwd,
120
- phase: parsed.phase,
121
- instruction: parsed.instruction,
122
- attachmentPaths: parsed.attachmentPaths,
123
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
124
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
125
- ...(env.model === undefined ? {} : { model: env.model }),
126
- });
127
- } catch (error) {
128
- if (error instanceof CliUsageError) {
129
- presentStructuralRejection(error, io);
130
- return { exitCode: 2 };
131
- }
132
- throw error;
133
- }
134
-
135
- await markRunAdmitted(admitted, env.principalAuthority);
136
-
137
- let methodProvenance: PackagedMethodSkillProvenance | undefined;
138
- if (admitted.phase === "apply") {
139
- try {
140
- const material = await loadPackagedMethodSkillMaterial(
141
- env.packageRoot,
142
- "tdd",
143
- );
144
- methodProvenance = material.provenance;
145
- } catch (error) {
146
- return (await presentControlledFailure(
147
- admitted,
148
- {
149
- timedOut: false,
150
- code: null,
151
- stderr: "",
152
- thrown: error,
153
- knownCause: "activation",
154
- },
155
- coderAdapters(),
156
- env.principalAuthority,
157
- io,
158
- )) as { exitCode: number; admitted: AdmittedCoderInvocation; terminal: TerminalResult };
159
- }
160
- }
161
-
162
- return await runPostAdmissionResumable({
163
- admitted,
164
- env,
165
- io,
166
- buildInitialRequest: () =>
167
- buildCoderTurnRequest(admitted, {
168
- packageRoot: env.packageRoot,
169
- home: env.home,
170
- agentDir: env.agentDir,
171
- ...(env.model === undefined ? {} : { model: env.model }),
172
- ...pickEngineAxis(env),
173
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
174
- ...(admitted.correlationId === undefined && env.correlationId === undefined
175
- ? {}
176
- : { correlationId: admitted.correlationId ?? env.correlationId }),
177
- continuation: {
178
- kind: "initial",
179
- prompt: buildCoderTransportPrompt(
180
- admitted,
181
- engineSessionMaterialFromOptions({
182
- ...pickEngineAxis(env),
183
- packageRoot: env.packageRoot,
184
- }),
185
- ),
186
- },
187
- }),
188
- buildResumeRequest: () =>
189
- buildCoderTurnRequest(admitted, {
190
- packageRoot: env.packageRoot,
191
- home: env.home,
192
- agentDir: env.agentDir,
193
- ...(env.model === undefined ? {} : { model: env.model }),
194
- ...pickEngineAxis(env),
195
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
196
- ...(admitted.correlationId === undefined && env.correlationId === undefined
197
- ? {}
198
- : { correlationId: admitted.correlationId ?? env.correlationId }),
199
- continuation: {
200
- kind: "resume",
201
- prompt: buildAutoResumeContinuationPrompt({
202
- packageRoot: env.packageRoot,
203
- ...pickEngineAxis(env),
204
- }),
205
- },
206
- }),
207
- adapters: coderAdapters(methodProvenance),
208
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
209
- });
210
- }
211
-
212
- /**
213
- * Resume a previously admitted Coder Role run after a typed HTTP 429.
214
- * Restores role/phase/task/session identity; model override is temporary.
215
- */
216
- export async function runPublicCoderResume(
217
- request: PublicResumeRequest,
218
- env: CoderRunEnv,
219
- io: CliIo,
220
- ): Promise<{
221
- exitCode: number;
222
- admitted?: AdmittedCoderInvocation;
223
- terminal?: TerminalResult;
224
- }> {
225
- return await runPostAdmissionSeatResume({
226
- request,
227
- env,
228
- io,
229
- load: (effective) =>
230
- loadResumableCoderRun(env.home, effective.runId, env.principalAuthority),
231
- buildTurnRequest: (admitted, effective) =>
232
- buildCoderTurnRequest(
233
- admitted,
234
- resumeTurnRequestProjectionOptions(admitted, effective, env),
235
- ),
236
- adapters: coderAdapters(),
237
- // Apply-only method; plan resume keeps empty provenance (same as initial).
238
- afterAdmittedLoad: (admitted) =>
239
- resolveResumeMethodMaterialAdapters({
240
- admitted,
241
- authority: env.principalAuthority,
242
- io,
243
- shouldLoad: admitted.phase === "apply",
244
- loadMaterial: () =>
245
- loadPackagedMethodSkillMaterial(env.packageRoot, "tdd"),
246
- adaptersWith: (material) => coderAdapters(material.provenance),
247
- emptyAdapters: coderAdapters(),
248
- knownCause: "activation",
249
- }),
250
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
251
- });
252
- }
253
-
254
- // Re-export for tests that assert typed credential failure channel shape.
255
- export type { RoleTurnKnownFailure, PackagedMethodSkillProvenance };
@@ -1,189 +0,0 @@
1
- /**
2
- * Public Collector Role run: admit a structured PR target → explicit Internal activate
3
- * → settle Terminal result (#112 / #517). #633: manual resume continues the exact
4
- * session. Lifecycle is the shared post-admission coordinator.
5
- */
6
- import type { DurablePrincipalAuthority, RoleTurnRequest } from "../host-contracts.ts";
7
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.ts";
8
- import { CliUsageError } from "./cli-errors.ts";
9
- import {
10
- admitCollectorInvocation,
11
- buildCollectorTransportPrompt,
12
- type AdmittedCollectorInvocation,
13
- type ParseCollectorArgvResult,
14
- } from "./invocation.ts";
15
- import {
16
- runPostAdmissionOneShot,
17
- type PostAdmissionAdapters,
18
- type PostAdmissionEnv,
19
- runPostAdmissionSeatResume,
20
- resumeTurnRequestProjectionOptions,
21
- } from "./post-admission.ts";
22
- import {
23
- loadResumableCollectorRun,
24
- markRunAdmitted,
25
- type PublicResumeRequest,
26
- } from "./run-lifecycle.ts";
27
- import {
28
- presentStructuralRejection,
29
- readCollectorInfrastructureFailure,
30
- trySettleCollectorTerminalResult,
31
- } from "./settlement.ts";
32
- import type { CliIo } from "./cli-io.ts";
33
- import type { TerminalResult } from "./terminal.ts";
34
- import {
35
- projectRoleTurnRequest,
36
- type RoleTurnRequestProjectionOptions,
37
- } from "./turn-request.ts";
38
-
39
- export type CollectorRunEnv = PostAdmissionEnv & {
40
- createRunId?: () => string;
41
- };
42
-
43
- /** Project admitted invocation onto the host-neutral turn request. */
44
- export function buildCollectorTurnRequest(
45
- admitted: AdmittedCollectorInvocation,
46
- options: RoleTurnRequestProjectionOptions,
47
- ): RoleTurnRequest {
48
- return projectRoleTurnRequest(
49
- admitted,
50
- {
51
- activation: {
52
- role: "collector" as const,
53
- repo: admitted.repository.display,
54
- // #676 A: omit pr when unbound — role binds via ak_collector_bind_target.
55
- ...(admitted.prNumber === undefined ? {} : { pr: String(admitted.prNumber) }),
56
- ...(admitted.requestManifestPath === undefined ? {} : { requestManifestPath: admitted.requestManifestPath }),
57
- ...(admitted.waitWindowMs === undefined ? {} : { waitMs: String(admitted.waitWindowMs) }),
58
- },
59
- },
60
- options,
61
- );
62
- }
63
-
64
- export async function runPublicCollector(
65
- argv: readonly string[],
66
- env: CollectorRunEnv,
67
- io: CliIo,
68
- parseCollectorArgv: (args: readonly string[]) => ParseCollectorArgvResult,
69
- ): Promise<{
70
- exitCode: number;
71
- admitted?: AdmittedCollectorInvocation;
72
- terminal?: TerminalResult;
73
- }> {
74
- let admitted: AdmittedCollectorInvocation;
75
- try {
76
- const parsed = parseCollectorArgv(argv);
77
- admitted = await admitCollectorInvocation({
78
- home: env.home,
79
- principalAuthority: env.principalAuthority,
80
- cwd: env.cwd,
81
- ...(parsed.prNumber === undefined ? {} : { prNumber: parsed.prNumber }),
82
- instruction: parsed.instruction,
83
- attachmentPaths: parsed.attachmentPaths,
84
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
85
- ...(parsed.repo === undefined ? {} : { repo: parsed.repo }),
86
- ...(parsed.requestManifestPath === undefined ? {} : { requestManifestPath: parsed.requestManifestPath }),
87
- ...(parsed.waitWindowMs === undefined ? {} : { waitWindowMs: parsed.waitWindowMs }),
88
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
89
- ...(env.model === undefined ? {} : { model: env.model }),
90
- });
91
- } catch (error) {
92
- if (error instanceof CliUsageError) {
93
- presentStructuralRejection(error, io);
94
- return { exitCode: 2 };
95
- }
96
- throw error;
97
- }
98
-
99
- await markRunAdmitted(admitted, env.principalAuthority);
100
-
101
- const turnRequest = buildCollectorTurnRequest(admitted, {
102
- packageRoot: env.packageRoot,
103
- home: env.home,
104
- agentDir: env.agentDir,
105
- ...(env.model === undefined ? {} : { model: env.model }),
106
- ...pickEngineAxis(env),
107
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
108
- ...(admitted.correlationId === undefined && env.correlationId === undefined
109
- ? {}
110
- : { correlationId: admitted.correlationId ?? env.correlationId }),
111
- continuation: {
112
- kind: "initial",
113
- prompt: buildCollectorTransportPrompt(
114
- admitted,
115
- engineSessionMaterialFromOptions({
116
- ...pickEngineAxis(env),
117
- packageRoot: env.packageRoot,
118
- }),
119
- ),
120
- },
121
- });
122
-
123
- return await runPostAdmissionOneShot({
124
- admitted,
125
- env,
126
- io,
127
- request: turnRequest,
128
- adapters: collectorAdapters(),
129
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
130
- });
131
- }
132
-
133
- function collectorAdapters(): PostAdmissionAdapters<AdmittedCollectorInvocation> {
134
- return {
135
- trySettle: (admitted, authority, scope) =>
136
- trySettleCollectorTerminalResult(admitted, authority, scope),
137
- shouldPresentSettled: () => true,
138
- resolveRunnerKnownFailure: async ({ result, sessionFile }) => {
139
- const infrastructureFailure = await readCollectorInfrastructureFailure(sessionFile);
140
- return (
141
- result.knownFailure ??
142
- (infrastructureFailure === undefined
143
- ? undefined
144
- : {
145
- ...(infrastructureFailure.cause === undefined
146
- ? {}
147
- : { cause: infrastructureFailure.cause }),
148
- diagnostic: infrastructureFailure.diagnostic,
149
- ...(infrastructureFailure.identity === undefined
150
- ? {}
151
- : { identity: infrastructureFailure.identity }),
152
- })
153
- );
154
- },
155
- };
156
- }
157
-
158
- /**
159
- * Resume a previously admitted Collector run (#633). Repository/PR identity
160
- * restores from the durable admitted request; the session principal reopens.
161
- */
162
- export async function runPublicCollectorResume(
163
- request: PublicResumeRequest,
164
- env: CollectorRunEnv,
165
- io: CliIo,
166
- ): Promise<{
167
- exitCode: number;
168
- admitted?: AdmittedCollectorInvocation;
169
- terminal?: TerminalResult;
170
- }> {
171
- return await runPostAdmissionSeatResume({
172
- request,
173
- env,
174
- io,
175
- load: (effective) =>
176
- loadResumableCollectorRun(
177
- env.home,
178
- effective.runId,
179
- env.principalAuthority,
180
- ),
181
- buildTurnRequest: (admitted, effective) =>
182
- buildCollectorTurnRequest(
183
- admitted,
184
- resumeTurnRequestProjectionOptions(admitted, effective, env),
185
- ),
186
- adapters: collectorAdapters(),
187
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
188
- });
189
- }
@@ -1,233 +0,0 @@
1
- /**
2
- * Public Diarist (起居郎) Role run — #708 / ADR 0075(起居郎是 LLM 角色)/ #779.
3
- * Same admit → post-admission → settle shape as the other instruction seats.
4
- * Semantic collection is the role's own turn: LLM finds materials itself
5
- * (no frozen candidate catalog, no path/attachment burden on the caller).
6
- * Who calls it and in what order is the caller's business (ADR 0010; ADR 0075 不规定调用顺序).
7
- */
8
- import type { DurablePrincipalAuthority, RoleTurnRequest } from "../host-contracts.ts";
9
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.ts";
10
- import { CliUsageError } from "./cli-errors.ts";
11
- import {
12
- admitDiaristInvocation,
13
- bindAdmittedTicketNumber,
14
- buildInstructionTransportPrompt,
15
- relocateAdmittedRunToTicket,
16
- recordAdmittedCorrelation,
17
- type AdmittedDiaristInvocation,
18
- type ParseDiaristArgvResult,
19
- } from "./invocation.ts";
20
- import {
21
- prepareSummonsResumeMaterials,
22
- runPostAdmissionOneShot,
23
- runPostAdmissionSeatResume,
24
- resumeTurnRequestProjectionOptions,
25
- type PostAdmissionAdapters,
26
- type PostAdmissionEnv,
27
- } from "./post-admission.ts";
28
- import {
29
- loadResumableDiaristRun,
30
- markRunAdmitted,
31
- type PublicResumeRequest,
32
- type RunWriterLease,
33
- } from "./run-lifecycle.ts";
34
- import {
35
- presentStructuralRejection,
36
- trySettleDiaristTerminalResult,
37
- } from "./settlement.ts";
38
- import type { CliIo } from "./cli-io.ts";
39
- import type { TerminalResult } from "./terminal.ts";
40
- import {
41
- projectRoleTurnRequest,
42
- type RoleTurnRequestProjectionOptions,
43
- } from "./turn-request.ts";
44
- import { readBoardTicketNumber } from "../run-ticket-number.ts";
45
-
46
- export type DiaristRunEnv = PostAdmissionEnv & {
47
- principalAuthority: DurablePrincipalAuthority;
48
- createRunId?: () => string;
49
- /**
50
- * Typed handoff from a caller that already holds a verified ticket key
51
- * (countersign refresh / post-assert). Never derived from summons prose.
52
- * When set: same-ticket resume under that key, else bind before the turn
53
- * so identity is already on the run pages (ADR 0075 / 0081).
54
- */
55
- boundTicketNumber?: number;
56
- };
57
-
58
- /** Project admitted invocation onto the host-neutral turn request. */
59
- export function buildDiaristTurnRequest(
60
- admitted: AdmittedDiaristInvocation,
61
- options: RoleTurnRequestProjectionOptions,
62
- ): RoleTurnRequest {
63
- return projectRoleTurnRequest(
64
- admitted,
65
- { activation: { role: "diarist" as const } },
66
- options,
67
- );
68
- }
69
-
70
- /**
71
- * Board-bound ticket on pages → memory bind + unbound→ticket relocate under lease.
72
- * Shared by resume (interrupted board-bound unbound) and post-turn first assert.
73
- */
74
- async function bindAndRelocateDiaristIfBoardBound(
75
- admitted: AdmittedDiaristInvocation,
76
- authority: DiaristRunEnv["principalAuthority"],
77
- lease?: RunWriterLease,
78
- ): Promise<void> {
79
- const boardTicket = await readBoardTicketNumber(admitted.runDirectory);
80
- if (boardTicket === undefined) return;
81
- if (admitted.ticketNumber === undefined) {
82
- await bindAdmittedTicketNumber(admitted, boardTicket);
83
- }
84
- await relocateAdmittedRunToTicket(admitted, authority, lease);
85
- }
86
-
87
- function diaristAdapters(
88
- env: DiaristRunEnv,
89
- ): PostAdmissionAdapters<AdmittedDiaristInvocation> {
90
- return {
91
- trySettle: (admitted, authority, scope) =>
92
- trySettleDiaristTerminalResult(admitted, authority, scope),
93
- shouldPresentSettled: () => true,
94
- // Resume interrupted state: board ticket already on pages, run still under unbound/.
95
- beforeDispatch: async (admitted, lease) => {
96
- if (env.correlationId !== undefined && env.correlationId.trim() !== "") {
97
- await recordAdmittedCorrelation(admitted, env.correlationId);
98
- }
99
- await bindAndRelocateDiaristIfBoardBound(admitted, env.principalAuthority, lease);
100
- },
101
- // First post-turn assert: accept hook wrote board pages; relocate before lease release.
102
- afterDispatch: async (admitted, lease) => {
103
- await bindAndRelocateDiaristIfBoardBound(admitted, env.principalAuthority, lease);
104
- },
105
- };
106
- }
107
-
108
- export async function runPublicDiarist(
109
- argv: readonly string[],
110
- env: DiaristRunEnv,
111
- io: CliIo,
112
- parseDiaristArgv: (args: readonly string[]) => ParseDiaristArgvResult,
113
- ): Promise<{
114
- exitCode: number;
115
- admitted?: AdmittedDiaristInvocation;
116
- terminal?: TerminalResult;
117
- }> {
118
- let parsed: ParseDiaristArgvResult;
119
- try {
120
- parsed = parseDiaristArgv(argv);
121
- } catch (error) {
122
- if (error instanceof CliUsageError) {
123
- presentStructuralRejection(error, io);
124
- return { exitCode: 2 };
125
- }
126
- throw error;
127
- }
128
-
129
- // #637 / #771 / ADR 0075 / #779 / #987: ticket identity is the LLM's typed
130
- // assertion on this turn, OR a typed handoff key already held by the caller
131
- // (countersign refresh bind). Code never pre-judges the summons text and never
132
- // freezes a candidate catalog. Public same-ticket resume-by-ticketNumber was
133
- // deleted (#987 Result 7); callers continue an existing diarist run only via
134
- // explicit `ak-role resume <runId>`. Handoff ticket remains a bind key only.
135
-
136
- const handoffTicket = env.boundTicketNumber;
137
-
138
- let admitted: AdmittedDiaristInvocation;
139
- try {
140
- admitted = await admitDiaristInvocation({
141
- home: env.home,
142
- principalAuthority: env.principalAuthority,
143
- cwd: env.cwd,
144
- instruction: parsed.instruction,
145
- attachmentPaths: parsed.attachmentPaths,
146
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
147
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
148
- ...(env.model === undefined ? {} : { model: env.model }),
149
- ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
150
- ...(handoffTicket === undefined ? {} : { assertedTicketNumber: handoffTicket }),
151
- });
152
- } catch (error) {
153
- if (error instanceof CliUsageError) {
154
- presentStructuralRejection(error, io);
155
- return { exitCode: 2 };
156
- }
157
- throw error;
158
- }
159
-
160
- await markRunAdmitted(admitted, env.principalAuthority);
161
-
162
-
163
- const turnProjection: RoleTurnRequestProjectionOptions = {
164
- packageRoot: env.packageRoot,
165
- home: env.home,
166
- agentDir: env.agentDir,
167
- ...(env.model === undefined ? {} : { model: env.model }),
168
- ...pickEngineAxis(env),
169
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
170
- ...(env.correlationId === undefined || env.correlationId.trim() === ""
171
- ? {}
172
- : { correlationId: env.correlationId }),
173
- continuation: {
174
- kind: "initial",
175
- prompt: buildInstructionTransportPrompt(
176
- admitted,
177
- engineSessionMaterialFromOptions({
178
- ...pickEngineAxis(env),
179
- packageRoot: env.packageRoot,
180
- }),
181
- ),
182
- },
183
- };
184
- const turnRequest = buildDiaristTurnRequest(admitted, turnProjection);
185
-
186
- return await runPostAdmissionOneShot({
187
- admitted,
188
- env,
189
- io,
190
- request: turnRequest,
191
- adapters: diaristAdapters(env),
192
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
193
- });
194
- }
195
-
196
- /**
197
- * Resume a previously admitted Diarist run (#708 / ADR 0079 同票传召 = resume).
198
- * LLM re-finds materials; entry identity keeps the volume idempotent.
199
- */
200
- export async function runPublicDiaristResume(
201
- request: PublicResumeRequest,
202
- env: DiaristRunEnv,
203
- io: CliIo,
204
- ): Promise<{
205
- exitCode: number;
206
- admitted?: AdmittedDiaristInvocation;
207
- terminal?: TerminalResult;
208
- }> {
209
- return await runPostAdmissionSeatResume({
210
- request,
211
- env,
212
- io,
213
- load: (effective) =>
214
- loadResumableDiaristRun(env.home, effective.runId, env.principalAuthority),
215
- buildTurnRequest: async (admitted, effective) => {
216
- const summonsPrepared = await prepareSummonsResumeMaterials(
217
- admitted.runDirectory,
218
- effective.summons,
219
- );
220
- return buildDiaristTurnRequest(
221
- admitted,
222
- resumeTurnRequestProjectionOptions(
223
- admitted,
224
- effective,
225
- env,
226
- summonsPrepared,
227
- ),
228
- );
229
- },
230
- adapters: diaristAdapters(env),
231
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
232
- });
233
- }