@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.
- package/dist/acp-host/production-host.js +19434 -18218
- package/dist/analyst-book-key.js +63 -0
- package/dist/analyst-cohort.js +167 -0
- package/dist/analyst-entry.js +320 -0
- package/dist/analyst-index.js +247 -0
- package/dist/analyst-ledger.js +561 -0
- package/dist/analyst-median.js +16 -0
- package/dist/analyst-metric-families/acceptance-success-rework.js +249 -0
- package/dist/analyst-metric-families/b2-frame-buckets-actions.js +189 -0
- package/dist/analyst-metric-families/gate-cycles.js +77 -0
- package/dist/analyst-metric-families/leg-wall-clock.js +56 -0
- package/dist/analyst-metric-families/round-timeline.js +126 -0
- package/dist/analyst-metric-families.js +23 -0
- package/dist/analyst-metric-family.js +11 -0
- package/dist/analyst-model-groups.js +135 -0
- package/dist/analyst-page.js +182 -0
- package/dist/atomic-write.js +23 -0
- package/dist/auditor-soul.js +1 -1
- package/dist/countersign-contracts.js +0 -2
- package/dist/diarist-contracts.js +0 -1
- package/dist/doctor-contracts.js +2 -2
- package/dist/gatekeeper-role.js +15 -16
- package/dist/gleaner-left-contracts.js +0 -2
- package/dist/headless-host/production-host.js +16967 -15749
- package/dist/host-contracts.js +0 -4
- package/dist/inspector-contracts.js +0 -2
- package/dist/institutional-resolution.js +4 -2
- package/dist/merger-contracts.js +0 -2
- package/dist/migrate-book-topology.js +3908 -3089
- package/dist/navigator-public-session.js +4 -3
- package/dist/notary-contracts.js +0 -2
- package/dist/package-contracts/auditor-output.js +0 -1
- package/dist/package-contracts/collector-output.js +0 -2
- package/dist/package-contracts/fixer-output.js +0 -2
- package/dist/package-contracts/gatekeeper-output.js +0 -2
- package/dist/package-contracts/judge-output.js +0 -2
- package/dist/package-contracts/navigator-output.js +0 -2
- package/dist/package-contracts/reviewer-output.js +0 -2
- package/dist/package-contracts/terminating-tools.js +32 -92
- package/dist/package-contracts/worker-output.js +0 -4
- package/dist/packaged-role-registry.js +518 -36
- package/dist/pi/role-turn-host.js +2 -1
- package/dist/public-cli/analyst-run.js +185 -0
- package/dist/public-cli/cli.js +885 -0
- package/dist/public-cli/config.js +12 -9
- package/dist/public-cli/countersign-run.js +4 -311
- package/dist/public-cli/instruction-seat-run.js +628 -158
- package/dist/public-cli/invocation.js +806 -1550
- package/dist/public-cli/main.js +6962 -9882
- package/dist/public-cli/option-definitions.js +51 -99
- package/dist/public-cli/post-admission.js +30 -2
- package/dist/public-cli/run-lifecycle.js +234 -353
- package/dist/public-cli/seat-ticket-binding.js +6 -0
- package/dist/public-cli/settlement.js +261 -675
- package/dist/public-cli/turn-request.js +76 -0
- package/dist/public-role-summons.js +38 -112
- package/dist/role-activation-flags.js +23 -45
- package/dist/secretariat-contracts.js +0 -2
- package/dist/session-identity.js +17 -8
- package/dist/session-opening-materials.js +3 -2
- package/extensions/role-runtime.ts +6 -80
- package/package.json +1 -1
- package/souls/coder.md +1 -2
- package/src/acp-host/role-turn-host.ts +4 -1
- package/src/analyst-metric-families/acceptance-success-rework.ts +3 -2
- package/src/auditor-role.ts +1 -2
- package/src/auditor-soul.ts +1 -1
- package/src/collector-role.ts +2 -2
- package/src/countersign-contracts.ts +0 -1
- package/src/countersign-role.ts +1 -1
- package/src/diarist-contracts.ts +0 -1
- package/src/diarist-role.ts +0 -1
- package/src/doctor-auditor.ts +1 -2
- package/src/doctor-contracts.ts +1 -1
- package/src/doctor-role.ts +3 -2
- package/src/external-host-turn-loop.ts +1 -1
- package/src/factory-board.ts +10 -7
- package/src/gatekeeper-role.ts +16 -10
- package/src/gleaner-left-contracts.ts +0 -1
- package/src/gleaner-left-role.ts +0 -1
- package/src/headless-host/role-turn-host.ts +7 -1
- package/src/host-contracts.ts +10 -6
- package/src/inspector-contracts.ts +0 -1
- package/src/inspector-role.ts +0 -2
- package/src/institutional-resolution.ts +6 -4
- package/src/judge-role.ts +3 -3
- package/src/merger-contracts.ts +0 -1
- package/src/merger-role.ts +2 -2
- package/src/navigator-public-session.ts +7 -6
- package/src/navigator-work-context.ts +6 -8
- package/src/notary-contracts.ts +0 -1
- package/src/notary-role.ts +2 -3
- package/src/package-contracts/auditor-output.ts +0 -1
- package/src/package-contracts/collector-output.ts +0 -1
- package/src/package-contracts/fixer-output.ts +0 -1
- package/src/package-contracts/gatekeeper-output.ts +0 -1
- package/src/package-contracts/judge-output.ts +0 -1
- package/src/package-contracts/navigator-output.ts +0 -1
- package/src/package-contracts/reviewer-output.ts +0 -1
- package/src/package-contracts/terminating-tools.ts +27 -99
- package/src/package-contracts/worker-output.ts +0 -2
- package/src/packaged-role-registry.ts +604 -35
- package/src/pi/role-turn-host.ts +2 -1
- package/src/public-cli/cli.ts +64 -259
- package/src/public-cli/config.ts +18 -10
- package/src/public-cli/countersign-run.ts +14 -449
- package/src/public-cli/instruction-seat-run.ts +758 -277
- package/src/public-cli/invocation.ts +1097 -2051
- package/src/public-cli/option-definitions.ts +62 -127
- package/src/public-cli/post-admission.ts +47 -2
- package/src/public-cli/run-lifecycle.ts +303 -613
- package/src/public-cli/seat-ticket-binding.ts +6 -0
- package/src/public-cli/settlement.ts +399 -1185
- package/src/public-cli/turn-request.ts +92 -1
- package/src/public-role-summons.ts +44 -128
- package/src/reviewer-role.ts +3 -2
- package/src/role-activation-flags.ts +20 -41
- package/src/role-runtime-dependencies.ts +25 -26
- package/src/role-runtime.ts +121 -232
- package/src/secretariat-contracts.ts +0 -1
- package/src/secretariat-role.ts +0 -2
- package/src/session-identity.ts +23 -8
- package/src/session-opening-materials.ts +2 -1
- package/src/worker-role.ts +3 -4
- package/dist/doctor-auditor.js +0 -25
- package/dist/public-cli/diarist-run.js +0 -130
- package/dist/public-cli/doctor-run.js +0 -87
- package/dist/public-cli/inspector-run.js +0 -151
- package/dist/public-cli/judge-run.js +0 -114
- package/dist/public-cli/notary-run.js +0 -174
- package/dist/public-cli/reviewer-run.js +0 -339
- package/src/public-cli/coder-run.ts +0 -255
- package/src/public-cli/collector-run.ts +0 -189
- package/src/public-cli/diarist-run.ts +0 -233
- package/src/public-cli/doctor-run.ts +0 -167
- package/src/public-cli/fixer-run.ts +0 -265
- package/src/public-cli/gleaner-left-run.ts +0 -167
- package/src/public-cli/inspector-run.ts +0 -261
- package/src/public-cli/judge-run.ts +0 -196
- package/src/public-cli/merger-run.ts +0 -294
- package/src/public-cli/notary-run.ts +0 -279
- package/src/public-cli/reviewer-run.ts +0 -480
- 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
|
-
}
|