@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.
- 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/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,80 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* selects a prior run by ticket number; gate same-parent re-summons keep
|
|
7
|
-
* parentRunPath resume (#747 / ADR 0079 gate face). Explicit `ak-role new` mints
|
|
8
|
-
* fresh; explicit `ak-role resume <runId>` continues a named run.
|
|
2
|
+
* Court diarist station for the shared countersign entry (#572 / ADR 0074 /
|
|
3
|
+
* ADR 0075 / #742 / #771). The public seat itself admits and settles through
|
|
4
|
+
* instruction-seat-run. This module only summons 起居郎 and refreshes a bound
|
|
5
|
+
* court diary.
|
|
9
6
|
*
|
|
10
7
|
* Court admission auto-runs 起居郎 so the 起居郎 LLM asserts the court target;
|
|
11
8
|
* mechanical layer only verifies; countersign reuses that typed identity for bind
|
|
12
9
|
* (ADR 0075 / 0081). Code never matches instruction text against book-known
|
|
13
10
|
* numbers. Who may call 起居郎 and in what order is not written into law
|
|
14
|
-
* (ADR 0075 不规定谁调用起居郎、顺序归调用者)
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* precondition and does not rewrite or reject host resume (#987).
|
|
18
|
-
*
|
|
19
|
-
* Wiring (#771 / #863 / #987): gate parentRunPath resume (when present) runs
|
|
20
|
-
* before identity mint; public path without parentRunPath always materializes a
|
|
21
|
-
* new run after identity. 起居郎 escalate (认不出) and typed failure terminals
|
|
22
|
-
* (incl. verification failure) settle as countersign controlled failure — never
|
|
23
|
-
* wash into 真无票. Only a true missing lawful typed terminal stays unbound and
|
|
24
|
-
* continues the body (r5 unbound-continue). Bound refresh hands the typed key to
|
|
25
|
-
* 起居郎 so freeze loads issue face (ADR 0075: 每次过庭都跑是调用者用法 / typed handoff).
|
|
11
|
+
* (ADR 0075 不规定谁调用起居郎、顺序归调用者). 起居录 path delivery is owned once by
|
|
12
|
+
* post-admission (#709 / ADR 0081). Bound refresh hands the typed key to 起居郎
|
|
13
|
+
* so freeze loads issue face (ADR 0075: 每次过庭都跑是调用者用法 / typed handoff).
|
|
26
14
|
*/
|
|
27
|
-
import {
|
|
28
|
-
import type {
|
|
29
|
-
DurablePrincipalAuthority,
|
|
30
|
-
RoleTurnRequest,
|
|
31
|
-
} from "../host-contracts.ts";
|
|
32
|
-
import {
|
|
33
|
-
engineSessionMaterialFromOptions,
|
|
34
|
-
pickEngineAxis,
|
|
35
|
-
} from "../package-resources/engine-material.ts";
|
|
36
|
-
import { CliUsageError } from "./cli-errors.ts";
|
|
15
|
+
import type { DurablePrincipalAuthority } from "../host-contracts.ts";
|
|
37
16
|
import { projectCourtTicketNumbers } from "../diarist-contracts.ts";
|
|
38
17
|
import { readableGateItem } from "../readable-gate-item.ts";
|
|
39
18
|
import { isSafePositiveTicketNumber } from "../run-ticket-number.ts";
|
|
19
|
+
import type { AdmittedCountersignInvocation } from "./invocation.ts";
|
|
40
20
|
import {
|
|
41
|
-
admitCountersignInvocation,
|
|
42
|
-
bindAdmittedTicketNumber,
|
|
43
|
-
bindCourtTicketNumbersOnAdmitted,
|
|
44
|
-
buildCountersignTransportPrompt,
|
|
45
|
-
materializeCountersignInvocation,
|
|
46
|
-
persistAdmittedSourceRunPath,
|
|
47
|
-
relocateAdmittedRunToTicket,
|
|
48
|
-
withPreparedAttachments,
|
|
49
|
-
type AdmittedCountersignInvocation,
|
|
50
|
-
type ParseCountersignArgvResult,
|
|
51
|
-
} from "./invocation.ts";
|
|
52
|
-
import {
|
|
53
|
-
prepareSummonsResumeMaterials,
|
|
54
|
-
presentControlledFailure,
|
|
55
|
-
runPostAdmissionOneShot,
|
|
56
21
|
type PostAdmissionEnv,
|
|
57
|
-
runPostAdmissionSeatResume,
|
|
58
|
-
resumeTurnRequestProjectionOptions,
|
|
59
22
|
StationChildExhaustedError,
|
|
60
23
|
} from "./post-admission.ts";
|
|
61
|
-
import {
|
|
62
|
-
loadResumableCountersignRun,
|
|
63
|
-
markRunAdmitted,
|
|
64
|
-
type PublicResumeRequest,
|
|
65
|
-
type RunWriterLease,
|
|
66
|
-
} from "./run-lifecycle.ts";
|
|
67
|
-
import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.ts";
|
|
68
|
-
import {
|
|
69
|
-
presentStructuralRejection,
|
|
70
|
-
trySettleCountersignTerminalResult,
|
|
71
|
-
} from "./settlement.ts";
|
|
72
24
|
import type { CliIo } from "./cli-io.ts";
|
|
73
|
-
import type {
|
|
74
|
-
import {
|
|
75
|
-
projectRoleTurnRequest,
|
|
76
|
-
type RoleTurnRequestProjectionOptions,
|
|
77
|
-
} from "./turn-request.ts";
|
|
25
|
+
import type { TerminalRoleOutcome } from "./terminal.ts";
|
|
78
26
|
|
|
79
27
|
export type CountersignRunEnv = PostAdmissionEnv & {
|
|
80
28
|
principalAuthority: DurablePrincipalAuthority;
|
|
@@ -104,30 +52,11 @@ export type CountersignRunEnv = PostAdmissionEnv & {
|
|
|
104
52
|
/**
|
|
105
53
|
* #747 / #987 gate same-parent resume key (Secretariat source run directory).
|
|
106
54
|
* When set, re-summons resume the prior 给事中 under this parent before mint.
|
|
55
|
+
* Absent on an ordinary public summons, which always mints.
|
|
107
56
|
*/
|
|
108
57
|
parentRunPath?: string;
|
|
109
58
|
};
|
|
110
59
|
|
|
111
|
-
/** Project admitted invocation onto the host-neutral turn request. */
|
|
112
|
-
export function buildCountersignTurnRequest(
|
|
113
|
-
admitted: AdmittedCountersignInvocation,
|
|
114
|
-
options: RoleTurnRequestProjectionOptions,
|
|
115
|
-
): RoleTurnRequest {
|
|
116
|
-
return projectRoleTurnRequest(
|
|
117
|
-
admitted,
|
|
118
|
-
{
|
|
119
|
-
activation: {
|
|
120
|
-
role: "countersign" as const,
|
|
121
|
-
// Admitted typed binding rides the turn activation seam to the Notary gate.
|
|
122
|
-
...(admitted.ticketNumber === undefined
|
|
123
|
-
? {}
|
|
124
|
-
: { ticketNumber: admitted.ticketNumber }),
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
options,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
60
|
/** 起居郎 identity outcome — escalate stays distinct from missing terminal. */
|
|
132
61
|
export type CourtDiaristIdentity =
|
|
133
62
|
| {
|
|
@@ -393,8 +322,8 @@ export async function invokeCourtDiarist(
|
|
|
393
322
|
*
|
|
394
323
|
* Missing ticketNumber (true-unbound / identity deferred) skips the refresh
|
|
395
324
|
* station — no diary is minted for a true-unbound run. First-entry identity
|
|
396
|
-
* lives on
|
|
397
|
-
*
|
|
325
|
+
* lives on the shared countersign entry (typed 起居郎 key for bind). Bound refresh:
|
|
326
|
+
* 起居郎 failure propagates (失败诚实).
|
|
398
327
|
* Path delivery onto materials is not this station's job — post-admission owns it.
|
|
399
328
|
*/
|
|
400
329
|
export async function runCountersignCourtDiaristStation(
|
|
@@ -407,7 +336,7 @@ export async function runCountersignCourtDiaristStation(
|
|
|
407
336
|
return;
|
|
408
337
|
}
|
|
409
338
|
// Production court refresh (ADR 0075: 每次过庭都跑是调用者用法) only under a known ticket identity.
|
|
410
|
-
// First-entry unbound identity is owned by
|
|
339
|
+
// First-entry unbound identity is owned by the shared countersign entry.
|
|
411
340
|
if (admitted.ticketNumber === undefined) return;
|
|
412
341
|
|
|
413
342
|
// #871: refresh every member of the typed co-review set; single-ticket face
|
|
@@ -452,367 +381,3 @@ export async function runCountersignCourtDiaristStation(
|
|
|
452
381
|
}
|
|
453
382
|
}
|
|
454
383
|
}
|
|
455
|
-
|
|
456
|
-
export async function runPublicCountersign(
|
|
457
|
-
argv: readonly string[],
|
|
458
|
-
env: CountersignRunEnv,
|
|
459
|
-
io: CliIo,
|
|
460
|
-
parseCountersignArgv: (args: readonly string[]) => ParseCountersignArgvResult,
|
|
461
|
-
): Promise<{
|
|
462
|
-
exitCode: number;
|
|
463
|
-
admitted?: AdmittedCountersignInvocation;
|
|
464
|
-
terminal?: TerminalResult;
|
|
465
|
-
}> {
|
|
466
|
-
let parsed: ParseCountersignArgvResult;
|
|
467
|
-
try {
|
|
468
|
-
parsed = parseCountersignArgv(argv);
|
|
469
|
-
} catch (error) {
|
|
470
|
-
if (error instanceof CliUsageError) {
|
|
471
|
-
presentStructuralRejection(error, io);
|
|
472
|
-
return { exitCode: 2 };
|
|
473
|
-
}
|
|
474
|
-
throw error;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
let admitted: AdmittedCountersignInvocation;
|
|
478
|
-
const gateParentRunPath =
|
|
479
|
-
typeof env.parentRunPath === "string" && env.parentRunPath.trim() !== ""
|
|
480
|
-
? env.parentRunPath
|
|
481
|
-
: undefined;
|
|
482
|
-
if (gateParentRunPath !== undefined) {
|
|
483
|
-
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction ?? parsed.instruction;
|
|
484
|
-
const resumed = await tryResumeSameTicketSeatRun({
|
|
485
|
-
home: env.home,
|
|
486
|
-
projectRoot: resolve(parsed.project ?? env.cwd),
|
|
487
|
-
role: "countersign",
|
|
488
|
-
parentRunPath: gateParentRunPath,
|
|
489
|
-
freshSummons: env.freshSummons,
|
|
490
|
-
summons: {
|
|
491
|
-
sourceRunPath: gateParentRunPath,
|
|
492
|
-
instruction: resumeInstruction,
|
|
493
|
-
instructionEmpty: resumeInstruction.trim() === "",
|
|
494
|
-
},
|
|
495
|
-
resume: (runId, materials) =>
|
|
496
|
-
runPublicCountersignResume(
|
|
497
|
-
{ runId, ...(materials === undefined ? {} : { summons: materials }) },
|
|
498
|
-
env,
|
|
499
|
-
io,
|
|
500
|
-
),
|
|
501
|
-
});
|
|
502
|
-
if (resumed !== undefined) return resumed;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
try {
|
|
506
|
-
admitted = await admitCountersignInvocation({
|
|
507
|
-
home: env.home,
|
|
508
|
-
principalAuthority: env.principalAuthority,
|
|
509
|
-
cwd: env.cwd,
|
|
510
|
-
instruction: parsed.instruction,
|
|
511
|
-
attachmentPaths: parsed.attachmentPaths,
|
|
512
|
-
...(parsed.project === undefined ? {} : { project: parsed.project }),
|
|
513
|
-
...(env.createRunId === undefined
|
|
514
|
-
? {}
|
|
515
|
-
: { createRunId: env.createRunId }),
|
|
516
|
-
...(env.model === undefined ? {} : { model: env.model }),
|
|
517
|
-
...(env.correlationId === undefined
|
|
518
|
-
? {}
|
|
519
|
-
: { correlationId: env.correlationId }),
|
|
520
|
-
deferPersistence: true,
|
|
521
|
-
});
|
|
522
|
-
} catch (error) {
|
|
523
|
-
if (error instanceof CliUsageError) {
|
|
524
|
-
presentStructuralRejection(error, io);
|
|
525
|
-
return { exitCode: 2 };
|
|
526
|
-
}
|
|
527
|
-
throw error;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// One owner spans prepare, lookup/load/resume or new-run materialization.
|
|
531
|
-
// It preserves both causes when its final cleanup also fails.
|
|
532
|
-
try {
|
|
533
|
-
return await withPreparedAttachments(
|
|
534
|
-
parsed.attachmentPaths,
|
|
535
|
-
async (preparedAttachments) => {
|
|
536
|
-
const materializeAdmission = async (): Promise<void> => {
|
|
537
|
-
await materializeCountersignInvocation(admitted, {
|
|
538
|
-
home: env.home,
|
|
539
|
-
principalAuthority: env.principalAuthority,
|
|
540
|
-
preparedAttachments,
|
|
541
|
-
...(env.model === undefined ? {} : { model: env.model }),
|
|
542
|
-
});
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
// #747 / #987: gate same-parent resume before identity mint. Public entry
|
|
546
|
-
// without parentRunPath never selects a prior run by ticket number.
|
|
547
|
-
// #637 / #771: ticket identity is the 起居郎 LLM typed assertion (never
|
|
548
|
-
// mechanical matching of summons text). Resolve that typed key before
|
|
549
|
-
// materializing a first-mint run. Controlled failures materialize below so
|
|
550
|
-
// they still have a durable page. The test seam `runCourtDiaristStation`
|
|
551
|
-
// defers identity to beforeDispatch; generic hook failures stay on the
|
|
552
|
-
// parent call-local budget, exhausted nested station children still skip
|
|
553
|
-
// parent auto-resume (#840 父子不层叠).
|
|
554
|
-
let typedTicket: number | undefined;
|
|
555
|
-
let typedCourtTicketNumbers: readonly number[] | undefined;
|
|
556
|
-
let identityDiaristRan = false;
|
|
557
|
-
|
|
558
|
-
if (env.runCourtDiaristStation === undefined) {
|
|
559
|
-
let outcome: CourtDiaristInvocationResult;
|
|
560
|
-
try {
|
|
561
|
-
outcome = await invokeCourtDiarist(
|
|
562
|
-
{
|
|
563
|
-
instruction: parsed.instruction,
|
|
564
|
-
projectRoot: admitted.projectRoot,
|
|
565
|
-
failureLabel: "unbound summons",
|
|
566
|
-
// #969: parent durable ticket is the bind key (not a resume lookup).
|
|
567
|
-
...(env.boundTicketNumber === undefined
|
|
568
|
-
? {}
|
|
569
|
-
: { boundTicketNumber: env.boundTicketNumber }),
|
|
570
|
-
},
|
|
571
|
-
env,
|
|
572
|
-
io,
|
|
573
|
-
);
|
|
574
|
-
} catch (error) {
|
|
575
|
-
await materializeAdmission();
|
|
576
|
-
await markRunAdmitted(admitted, env.principalAuthority);
|
|
577
|
-
return await presentControlledFailure(
|
|
578
|
-
admitted,
|
|
579
|
-
{ timedOut: false, code: null, stderr: "", thrown: error },
|
|
580
|
-
countersignAdapters(),
|
|
581
|
-
env.principalAuthority,
|
|
582
|
-
io,
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
identityDiaristRan = true;
|
|
586
|
-
|
|
587
|
-
if (outcome.identity.kind === "escalate") {
|
|
588
|
-
// 御批: 识别不了就上抛 — materialize and settle this countersign run.
|
|
589
|
-
// Diagnostic relays diarist escalate payload facts (#953).
|
|
590
|
-
await materializeAdmission();
|
|
591
|
-
await markRunAdmitted(admitted, env.principalAuthority);
|
|
592
|
-
return await presentControlledFailure(
|
|
593
|
-
admitted,
|
|
594
|
-
{
|
|
595
|
-
timedOut: false,
|
|
596
|
-
code: null,
|
|
597
|
-
stderr: "",
|
|
598
|
-
thrown: new Error(outcome.identity.diagnostic),
|
|
599
|
-
},
|
|
600
|
-
countersignAdapters(),
|
|
601
|
-
env.principalAuthority,
|
|
602
|
-
io,
|
|
603
|
-
);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
// Typed failure terminal (verification / infra / non-zero without escalate)
|
|
607
|
-
// is not 真无票 — settle controlled failure on the admitted run (失败诚实).
|
|
608
|
-
// Only a true missing lawful typed terminal keeps the r5 unbound-continue.
|
|
609
|
-
if (outcome.failedWithoutEscalate !== undefined) {
|
|
610
|
-
await materializeAdmission();
|
|
611
|
-
await markRunAdmitted(admitted, env.principalAuthority);
|
|
612
|
-
return await presentControlledFailure(
|
|
613
|
-
admitted,
|
|
614
|
-
{
|
|
615
|
-
timedOut: false,
|
|
616
|
-
code: null,
|
|
617
|
-
stderr: "",
|
|
618
|
-
thrown: new Error(outcome.failedWithoutEscalate.diagnostic),
|
|
619
|
-
},
|
|
620
|
-
countersignAdapters(),
|
|
621
|
-
env.principalAuthority,
|
|
622
|
-
io,
|
|
623
|
-
);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// Missing lawful 起居郎 terminal is not countersign body failure: leave
|
|
627
|
-
// unbound and continue (true-unbound face) — unless parent gate handoff
|
|
628
|
-
// already carries the durable board ticket (#969). Escalate / typed
|
|
629
|
-
// failure above; bound refresh still fails honest via station.
|
|
630
|
-
if (outcome.identity.kind === "ticket") {
|
|
631
|
-
// #969: parent durable handoff wins over 起居郎 re-assert when both
|
|
632
|
-
// present (receipt/assert mismatch → parent bind key).
|
|
633
|
-
typedTicket = isSafePositiveTicketNumber(env.boundTicketNumber)
|
|
634
|
-
? env.boundTicketNumber
|
|
635
|
-
: outcome.identity.ticketNumber;
|
|
636
|
-
// #871: identity may hand a co-review set; absent field defaults to [main].
|
|
637
|
-
typedCourtTicketNumbers = outcome.identity.courtTicketNumbers;
|
|
638
|
-
} else if (isSafePositiveTicketNumber(env.boundTicketNumber)) {
|
|
639
|
-
// Parent board handoff present; 起居郎 returned true-unbound — still
|
|
640
|
-
// bind under the parent key (omitted receipt ticketNumber path).
|
|
641
|
-
typedTicket = env.boundTicketNumber;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// No prior same-parent run was selected. Materialize this invocation now;
|
|
646
|
-
// true-unbound, first-ticket and deferred test-seam paths all retain their
|
|
647
|
-
// own durable page. Public re-summons without parentRunPath always mint.
|
|
648
|
-
await materializeAdmission();
|
|
649
|
-
await markRunAdmitted(admitted, env.principalAuthority);
|
|
650
|
-
|
|
651
|
-
if (gateParentRunPath !== undefined) {
|
|
652
|
-
await persistAdmittedSourceRunPath(admitted, gateParentRunPath);
|
|
653
|
-
admitted = { ...admitted, sourceRunPath: gateParentRunPath };
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
if (identityDiaristRan && typedTicket !== undefined) {
|
|
657
|
-
try {
|
|
658
|
-
await bindAdmittedTicketNumber(admitted, typedTicket);
|
|
659
|
-
await relocateAdmittedRunToTicket(admitted, env.principalAuthority);
|
|
660
|
-
// First court: explicit set wins; omitted field → single-ticket face [main].
|
|
661
|
-
// Set persistence is outside beforeDispatch — route write failures into the
|
|
662
|
-
// same controlled-failure settlement as station children (#871 B7).
|
|
663
|
-
await bindCourtTicketNumbersOnAdmitted(
|
|
664
|
-
admitted,
|
|
665
|
-
typedCourtTicketNumbers ?? [typedTicket],
|
|
666
|
-
);
|
|
667
|
-
} catch (error) {
|
|
668
|
-
return await presentControlledFailure(
|
|
669
|
-
admitted,
|
|
670
|
-
{
|
|
671
|
-
timedOut: false,
|
|
672
|
-
code: null,
|
|
673
|
-
stderr: "",
|
|
674
|
-
thrown: error,
|
|
675
|
-
},
|
|
676
|
-
countersignAdapters(),
|
|
677
|
-
env.principalAuthority,
|
|
678
|
-
io,
|
|
679
|
-
);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
const turnProjection: RoleTurnRequestProjectionOptions = {
|
|
684
|
-
packageRoot: env.packageRoot,
|
|
685
|
-
home: env.home,
|
|
686
|
-
agentDir: env.agentDir,
|
|
687
|
-
...(env.model === undefined ? {} : { model: env.model }),
|
|
688
|
-
...pickEngineAxis(env),
|
|
689
|
-
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
690
|
-
...(env.correlationId === undefined || env.correlationId.trim() === ""
|
|
691
|
-
? {}
|
|
692
|
-
: { correlationId: env.correlationId }),
|
|
693
|
-
continuation: {
|
|
694
|
-
kind: "initial",
|
|
695
|
-
// #969/#879: gate path first mint carries parent payload as dialogue content;
|
|
696
|
-
// ordinary public entry keeps package transport prompt.
|
|
697
|
-
prompt: (env.reviewReask ?? env.gateReviewInstruction)
|
|
698
|
-
?? buildCountersignTransportPrompt(
|
|
699
|
-
admitted,
|
|
700
|
-
engineSessionMaterialFromOptions({
|
|
701
|
-
...pickEngineAxis(env),
|
|
702
|
-
packageRoot: env.packageRoot,
|
|
703
|
-
}),
|
|
704
|
-
),
|
|
705
|
-
},
|
|
706
|
-
};
|
|
707
|
-
// Mutable shell: ticket bind re-projects activation before executeTurn.
|
|
708
|
-
const turnRequest = buildCountersignTurnRequest(
|
|
709
|
-
admitted,
|
|
710
|
-
turnProjection,
|
|
711
|
-
);
|
|
712
|
-
|
|
713
|
-
const result = await runPostAdmissionOneShot({
|
|
714
|
-
admitted,
|
|
715
|
-
env,
|
|
716
|
-
io,
|
|
717
|
-
request: turnRequest,
|
|
718
|
-
adapters: countersignAdapters({
|
|
719
|
-
beforeDispatch: async (admittedSeat, lease) => {
|
|
720
|
-
// Dossier pointer delivery rides post-admission after this hook (#709).
|
|
721
|
-
if (!identityDiaristRan) {
|
|
722
|
-
// Test seam (or any deferred identity): station owns assert + bind.
|
|
723
|
-
await runCountersignCourtDiaristStation(admittedSeat, env, io);
|
|
724
|
-
} else if (typedTicket !== undefined) {
|
|
725
|
-
await runCountersignCourtDiaristStation(admittedSeat, env, io);
|
|
726
|
-
}
|
|
727
|
-
await relocateAdmittedRunToTicket(
|
|
728
|
-
admittedSeat,
|
|
729
|
-
env.principalAuthority,
|
|
730
|
-
lease,
|
|
731
|
-
);
|
|
732
|
-
Object.assign(
|
|
733
|
-
turnRequest,
|
|
734
|
-
buildCountersignTurnRequest(admittedSeat, turnProjection),
|
|
735
|
-
);
|
|
736
|
-
},
|
|
737
|
-
}),
|
|
738
|
-
...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
|
|
739
|
-
});
|
|
740
|
-
await relocateAdmittedRunToTicket(admitted, env.principalAuthority);
|
|
741
|
-
return result;
|
|
742
|
-
},
|
|
743
|
-
);
|
|
744
|
-
} catch (error) {
|
|
745
|
-
if (error instanceof CliUsageError) {
|
|
746
|
-
presentStructuralRejection(error, io);
|
|
747
|
-
return { exitCode: 2 };
|
|
748
|
-
}
|
|
749
|
-
throw error;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
function countersignAdapters(options?: {
|
|
754
|
-
beforeDispatch?: (
|
|
755
|
-
admitted: AdmittedCountersignInvocation,
|
|
756
|
-
lease?: RunWriterLease,
|
|
757
|
-
) => void | Promise<void>;
|
|
758
|
-
}) {
|
|
759
|
-
return {
|
|
760
|
-
trySettle: (
|
|
761
|
-
admitted: AdmittedCountersignInvocation,
|
|
762
|
-
authority: DurablePrincipalAuthority,
|
|
763
|
-
scope?: { readonly courtAttemptId?: string },
|
|
764
|
-
) => trySettleCountersignTerminalResult(admitted, authority, scope),
|
|
765
|
-
// Accepted receipts and failure terminals both present via shared path.
|
|
766
|
-
shouldPresentSettled: () => true,
|
|
767
|
-
...(options?.beforeDispatch === undefined
|
|
768
|
-
? {}
|
|
769
|
-
: { beforeDispatch: options.beforeDispatch }),
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* Resume a previously admitted Countersign run (#599 / DK-3 / #637 / #987).
|
|
775
|
-
* Restores role/ticket/session identity. Gate
|
|
776
|
-
* same-parent and explicit `ak-role resume <runId>` share this entry; summons
|
|
777
|
-
* may carry this turn's instruction. Manual resume forwards only the caller's
|
|
778
|
-
* message bytes. 起居录 path delivery remains
|
|
779
|
-
* post-admission's single mount (#709).
|
|
780
|
-
*/
|
|
781
|
-
export async function runPublicCountersignResume(
|
|
782
|
-
request: PublicResumeRequest,
|
|
783
|
-
env: CountersignRunEnv,
|
|
784
|
-
io: CliIo,
|
|
785
|
-
): Promise<{
|
|
786
|
-
exitCode: number;
|
|
787
|
-
admitted?: AdmittedCountersignInvocation;
|
|
788
|
-
terminal?: TerminalResult;
|
|
789
|
-
}> {
|
|
790
|
-
return await runPostAdmissionSeatResume({
|
|
791
|
-
request,
|
|
792
|
-
env,
|
|
793
|
-
io,
|
|
794
|
-
load: (effective) =>
|
|
795
|
-
loadResumableCountersignRun(
|
|
796
|
-
env.home,
|
|
797
|
-
effective.runId,
|
|
798
|
-
env.principalAuthority,
|
|
799
|
-
),
|
|
800
|
-
buildTurnRequest: async (admitted, effective) => {
|
|
801
|
-
const summonsPrepared = await prepareSummonsResumeMaterials(
|
|
802
|
-
admitted.runDirectory,
|
|
803
|
-
effective.summons,
|
|
804
|
-
);
|
|
805
|
-
return buildCountersignTurnRequest(
|
|
806
|
-
admitted,
|
|
807
|
-
resumeTurnRequestProjectionOptions(
|
|
808
|
-
admitted,
|
|
809
|
-
effective,
|
|
810
|
-
env,
|
|
811
|
-
summonsPrepared,
|
|
812
|
-
),
|
|
813
|
-
);
|
|
814
|
-
},
|
|
815
|
-
adapters: countersignAdapters(),
|
|
816
|
-
...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
|
|
817
|
-
});
|
|
818
|
-
}
|