@akagilnc/pi-workflow-roles 0.1.3932 → 0.1.3975
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/CLAUDE.md +1 -1
- package/dist/acp-host/production-host.js +2389 -6018
- package/dist/analyst-gate-cycles-read.js +15 -19
- package/dist/audit-escalation.js +16 -46
- package/dist/auditor-dossier-tool.js +7 -62
- package/dist/collector-identity.js +0 -157
- package/dist/collector-ledger.js +2 -42
- package/dist/compliance-transport.js +40 -14
- package/dist/diarist-contracts.js +2 -40
- package/dist/doctor-contracts.js +39 -108
- package/dist/doctor-evidence.js +1 -5
- package/dist/engine-detour-tool.js +1 -1
- package/dist/gatekeeper-role.js +49 -38
- package/dist/headless-host/production-host.js +4814 -8450
- package/dist/host-contracts.js +0 -5
- package/dist/merger-contracts.js +4 -6
- package/dist/navigator-attendance.js +30 -52
- package/dist/navigator-invocation-identity.js +0 -1
- package/dist/navigator-public-session.js +2 -1
- package/dist/notary-contracts.js +4 -10
- package/dist/package-contracts/auditor-output.js +5 -23
- package/dist/package-contracts/fixer-output.js +25 -49
- package/dist/package-contracts/gatekeeper-output.js +3 -13
- package/dist/package-contracts/navigator-output.js +4 -7
- package/dist/package-contracts/reviewer-output.js +1 -95
- package/dist/package-contracts/terminating-tools.js +33 -144
- package/dist/package-contracts/worker-output.js +1 -3
- package/dist/public-cli/auto-resume.js +30 -68
- package/dist/public-cli/case-dossier-delivery.js +5 -17
- package/dist/public-cli/diarist-run.js +9 -4
- package/dist/public-cli/inspector-run.js +2 -8
- package/dist/public-cli/instruction-seat-run.js +3 -7
- package/dist/public-cli/invocation.js +5 -2
- package/dist/public-cli/main.js +6068 -6964
- package/dist/public-cli/notary-run.js +1 -8
- package/dist/public-cli/post-admission.js +314 -113
- package/dist/public-cli/run-lifecycle.js +14 -38
- package/dist/public-cli/settlement.js +209 -390
- package/dist/public-cli/terminal.js +51 -45
- package/dist/public-role-summons.js +1 -12
- package/dist/reviewer-dispatch.js +12 -258
- package/dist/submission-correctable-error.js +0 -12
- package/dist/submission-errors.js +6 -1
- package/dist/submission-ledger.js +125 -168
- package/dist/ticket-provenance-contracts.js +2 -49
- package/dist/ticket-provenance.js +82 -31
- package/extensions/role-runtime.ts +1 -6
- package/package.json +1 -1
- package/resources/836-deleted-machine-instruction-inventory.md +18 -0
- package/src/acp-host/role-turn-host.ts +8 -3
- package/src/analyst-gate-cycles-read.ts +17 -29
- package/src/audit-escalation.ts +20 -50
- package/src/auditor-dossier-tool.ts +5 -103
- package/src/canonical-skill-binding.ts +3 -2
- package/src/collector-identity.ts +0 -179
- package/src/collector-ledger.ts +3 -46
- package/src/collector-role.ts +32 -61
- package/src/collector-tool-schemas.ts +20 -14
- package/src/compliance-transport.ts +55 -17
- package/src/countersign-role.ts +17 -8
- package/src/diarist-contracts.ts +3 -36
- package/src/diarist-role.ts +13 -7
- package/src/diarist.ts +4 -16
- package/src/doctor-contracts.ts +73 -94
- package/src/doctor-evidence.ts +1 -1
- package/src/doctor-role.ts +3 -3
- package/src/engine-detour-tool.ts +4 -1
- package/src/external-host-turn-loop.ts +9 -3
- package/src/gatekeeper-pass-envelope.ts +7 -12
- package/src/gatekeeper-role.ts +56 -50
- package/src/gleaner-left-role.ts +4 -2
- package/src/headless-host/role-turn-host.ts +4 -5
- package/src/host-contracts.ts +3 -8
- package/src/judge-role.ts +19 -13
- package/src/merger-contracts.ts +10 -6
- package/src/merger-role.ts +1 -5
- package/src/navigator-attendance.ts +37 -74
- package/src/navigator-invocation-identity.ts +0 -6
- package/src/navigator-public-session.ts +2 -1
- package/src/notary-contracts.ts +7 -10
- package/src/package-contracts/auditor-output.ts +4 -21
- package/src/package-contracts/fixer-output.ts +34 -52
- package/src/package-contracts/gatekeeper-output.ts +5 -22
- package/src/package-contracts/navigator-output.ts +7 -7
- package/src/package-contracts/reviewer-output.ts +2 -150
- package/src/package-contracts/terminating-tools.ts +32 -147
- package/src/package-contracts/worker-output.ts +0 -1
- package/src/pi/adapter.ts +3 -8
- package/src/public-cli/auto-resume.ts +41 -94
- package/src/public-cli/case-dossier-delivery.ts +5 -15
- package/src/public-cli/countersign-run.ts +14 -6
- package/src/public-cli/diarist-run.ts +11 -9
- package/src/public-cli/inspector-run.ts +2 -18
- package/src/public-cli/instruction-seat-run.ts +3 -17
- package/src/public-cli/invocation.ts +5 -2
- package/src/public-cli/merger-run.ts +1 -1
- package/src/public-cli/notary-run.ts +1 -18
- package/src/public-cli/post-admission.ts +385 -115
- package/src/public-cli/run-lifecycle.ts +13 -44
- package/src/public-cli/settlement.ts +314 -562
- package/src/public-cli/terminal.ts +66 -72
- package/src/public-role-summons.ts +5 -30
- package/src/reviewer-dispatch.ts +29 -331
- package/src/reviewer-role.ts +16 -83
- package/src/role-envelope.ts +16 -24
- package/src/role-runtime-dependencies.ts +1 -6
- package/src/role-runtime.ts +65 -201
- package/src/submission-correctable-error.ts +0 -14
- package/src/submission-errors.ts +6 -1
- package/src/submission-ledger.ts +187 -187
- package/src/ticket-provenance-contracts.ts +4 -60
- package/src/ticket-provenance.ts +98 -32
- package/src/worker-role.ts +35 -36
- package/dist/activation-ledger-session.js +0 -105
- package/dist/activation-ledger.js +0 -139
- package/dist/activation-trace.js +0 -33
- package/dist/atomic-write.js +0 -23
- package/dist/auditor-role.js +0 -12
- package/dist/canonical-skill-binding.js +0 -61
- package/dist/collector-handbook.js +0 -142
- package/dist/collector-receipt.js +0 -107
- package/dist/collector-role.js +0 -566
- package/dist/collector-tool-schemas.js +0 -107
- package/dist/countersign-role.js +0 -28
- package/dist/diarist-role.js +0 -44
- package/dist/diarist.js +0 -66
- package/dist/doctor-role.js +0 -75
- package/dist/fixer-bash-seatbelt.js +0 -13
- package/dist/gatekeeper-pass-envelope.js +0 -77
- package/dist/gleaner-left-role.js +0 -26
- package/dist/inspector-role.js +0 -29
- package/dist/judge-role.js +0 -104
- package/dist/merger-role.js +0 -55
- package/dist/navigator-role.js +0 -12
- package/dist/notary-role.js +0 -134
- package/dist/oauth-keepalive.js +0 -158
- package/dist/pi/adapter.js +0 -223
- package/dist/reviewer-agent.js +0 -122
- package/dist/reviewer-child-executor.js +0 -194
- package/dist/reviewer-construction.js +0 -103
- package/dist/reviewer-execution-ledger.js +0 -166
- package/dist/reviewer-failure-diagnostic.js +0 -17
- package/dist/reviewer-role.js +0 -159
- package/dist/reviewer-scope-prompt.js +0 -21
- package/dist/reviewer-settlement.js +0 -66
- package/dist/reviewer-workspace.js +0 -132
- package/dist/role-runtime.js +0 -1604
- package/dist/stderr-jsonl.js +0 -26
- package/dist/tool-execution-observation.js +0 -141
- package/dist/worker-role.js +0 -345
- package/dist/worker-submission-gates.js +0 -305
- package/src/collector-receipt.ts +0 -140
- package/src/diagnostic-tail.ts +0 -18
- package/src/reviewer-agent.ts +0 -135
- package/src/reviewer-child-executor.ts +0 -252
- package/src/reviewer-construction.ts +0 -195
- package/src/reviewer-execution-ledger.ts +0 -212
- package/src/reviewer-failure-diagnostic.ts +0 -18
- package/src/reviewer-scope-prompt.ts +0 -24
- package/src/reviewer-settlement.ts +0 -74
- package/src/reviewer-workspace.ts +0 -105
- package/src/shape-unreadable-failure.ts +0 -49
|
@@ -2,14 +2,13 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
|
|
4
4
|
import { loadCanonicalSkillBinding as loadHomeCanonicalSkillBinding } from "./canonical-skill-binding.ts";
|
|
5
|
-
import { createGhCollectorGitHubTransport
|
|
5
|
+
import { createGhCollectorGitHubTransport } from "./collector-github.ts";
|
|
6
6
|
import { createPiDoctorAuditor } from "./doctor-auditor.ts";
|
|
7
7
|
import { loadDoctorCase } from "./doctor-evidence.ts";
|
|
8
8
|
import { createNativeNavigatorSessionFactory, createNavigatorAttendance } from "./navigator-attendance.ts";
|
|
9
9
|
import { loadNavigatorWorkContext } from "./navigator-work-context.ts";
|
|
10
10
|
import { loadNotarySourceRunLocator } from "./notary-source-run.ts";
|
|
11
11
|
import { loadPackagedCanonicalSkillBinding } from "./package-resources/method-skill-binding.ts";
|
|
12
|
-
import { createPerDispatchReviewerAgent } from "./reviewer-agent.ts";
|
|
13
12
|
import { formatNavigatorRoleHelp, type RoleRuntimeDependencies } from "./role-runtime.ts";
|
|
14
13
|
import { createReviewerPinnedGitReader } from "./reviewer-pinned-git.ts";
|
|
15
14
|
import { loadAuditorSoulFromSubjectInput } from "./auditor-soul.ts";
|
|
@@ -25,7 +24,6 @@ const collectorHandbookSeedPath = fileURLToPath(
|
|
|
25
24
|
/** Host-neutral packaged role runtime deps for the parent-process envelope. */
|
|
26
25
|
export function createRoleRuntimeDependencies(packageRoot: string): RoleRuntimeDependencies {
|
|
27
26
|
const doctorAuditor = createPiDoctorAuditor();
|
|
28
|
-
const reviewerAgent = createPerDispatchReviewerAgent({ packageRoot });
|
|
29
27
|
const navigatorSessionFactory = createNativeNavigatorSessionFactory();
|
|
30
28
|
return {
|
|
31
29
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
@@ -35,7 +33,6 @@ export function createRoleRuntimeDependencies(packageRoot: string): RoleRuntimeD
|
|
|
35
33
|
loadCoderTask: (path) => readFile(path, "utf8"),
|
|
36
34
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
37
35
|
createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
|
|
38
|
-
createReviewerIssueFetcher: () => createGhIssueSoftFetcher(),
|
|
39
36
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
40
37
|
loadCollectorHandbookSeed: () => readFile(collectorHandbookSeedPath, "utf8"),
|
|
41
38
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
@@ -63,8 +60,6 @@ export function createRoleRuntimeDependencies(packageRoot: string): RoleRuntimeD
|
|
|
63
60
|
},
|
|
64
61
|
// #590: doctor compliance still on disposeCompliance path; judge→auditor is gate queue (#756).
|
|
65
62
|
auditDoctorCompliance: (options) => doctorAuditor(options),
|
|
66
|
-
runReviewerDispatch: (dispatch, options) => reviewerAgent.run(dispatch, options),
|
|
67
|
-
shutdownReviewerAgent: () => reviewerAgent.shutdown(),
|
|
68
63
|
loadNavigatorWorkContext: (options) => loadNavigatorWorkContext({
|
|
69
64
|
context: options.context,
|
|
70
65
|
role: options.role,
|
package/src/role-runtime.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type RoleEnvelopeHost,
|
|
8
8
|
type RoleHost,
|
|
9
9
|
} from "./host-contracts.ts";
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
import { Value } from "typebox/value";
|
|
12
12
|
import { sitianReport } from "./sitian-facade.ts";
|
|
13
13
|
import { createSubmissionLedgerHost } from "./submission-ledger.ts";
|
|
@@ -97,7 +97,7 @@ import {
|
|
|
97
97
|
import { AUDITOR_ACCEPTED_TEXT } from "./package-contracts/auditor-output.ts";
|
|
98
98
|
import { GATEKEEPER_ACCEPTED_TEXT } from "./package-contracts/gatekeeper-output.ts";
|
|
99
99
|
import { NAVIGATOR_ACCEPTED_TEXT } from "./package-contracts/navigator-output.ts";
|
|
100
|
-
import {
|
|
100
|
+
import { formatNavigatorReport, NAVIGATOR_EVENT_TYPE, navigatorSubjectKey, navigatorUnavailableError, subjectPath, type NavigatorAttendance, type NavigatorAttendanceOptions, type NavigatorEvent, type NavigatorPhase, type NavigatorReport, type NavigatorSettlement, type NavigatorSubjectProvenance, type NavigatorTargetRole, type NavigatorWorkContext } from "./navigator-attendance.ts";
|
|
101
101
|
import {
|
|
102
102
|
buildNavigatorInfrastructureFailureFact,
|
|
103
103
|
classifyPackagedRoleTerminalResult,
|
|
@@ -117,11 +117,7 @@ import {
|
|
|
117
117
|
type ReviewerActivation,
|
|
118
118
|
type ReviewerAdmittedInputs,
|
|
119
119
|
} from "./reviewer-role.ts";
|
|
120
|
-
import type {
|
|
121
|
-
import type { ReviewerDispatchRunResult } from "./reviewer-agent.ts";
|
|
122
|
-
import {
|
|
123
|
-
type ReviewerSpecDisposition,
|
|
124
|
-
} from "./reviewer-construction.ts";
|
|
120
|
+
import type { ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
|
|
125
121
|
import type { GatekeeperNonPassResult } from "./gatekeeper-role.ts";
|
|
126
122
|
|
|
127
123
|
/**
|
|
@@ -247,24 +243,13 @@ function decodeReviewerAdmittedInputs(getFlag: (name: string) => unknown): Revie
|
|
|
247
243
|
function assembleReviewerParentSystemPrompt(input: {
|
|
248
244
|
baseSystemPrompt: string;
|
|
249
245
|
soul: string;
|
|
250
|
-
specDisposition?: ReviewerSpecDisposition;
|
|
251
246
|
}): string {
|
|
252
|
-
const specDispositionNote =
|
|
253
|
-
input.specDisposition === "skipped-missing"
|
|
254
|
-
? [
|
|
255
|
-
"",
|
|
256
|
-
"<reviewer_spec_disposition>",
|
|
257
|
-
"权威 Spec 不存在;未启动 Spec 取证腿。",
|
|
258
|
-
"</reviewer_spec_disposition>",
|
|
259
|
-
]
|
|
260
|
-
: [];
|
|
261
247
|
return [
|
|
262
248
|
input.baseSystemPrompt,
|
|
263
249
|
"",
|
|
264
250
|
"<reviewer_soul>",
|
|
265
251
|
input.soul,
|
|
266
252
|
"</reviewer_soul>",
|
|
267
|
-
...specDispositionNote,
|
|
268
253
|
].join("\n");
|
|
269
254
|
}
|
|
270
255
|
import {
|
|
@@ -391,7 +376,7 @@ export {
|
|
|
391
376
|
type FixerOutput,
|
|
392
377
|
type WorkerOutput,
|
|
393
378
|
} from "./worker-role.ts";
|
|
394
|
-
export { fixerOutputSchema, validateFixerOutput
|
|
379
|
+
export { fixerOutputSchema, validateFixerOutput } from "./package-contracts/fixer-output.ts";
|
|
395
380
|
export type { FixerBlocker, FixerClassResult, FixerPhase, FixerTestEvidence } from "./package-contracts/fixer-output.ts";
|
|
396
381
|
export { fixerPrerequisiteSchema, fixerPrerequisitesSchema, parseFixerPrerequisites, validateFixerPrerequisites } from "./package-contracts/fixer-packet.ts";
|
|
397
382
|
export type { FixerInvocationInput, FixerPrerequisite } from "./package-contracts/fixer-packet.ts";
|
|
@@ -415,15 +400,8 @@ export {
|
|
|
415
400
|
COLLECTOR_REQUEST_TOOL,
|
|
416
401
|
COLLECTOR_WAIT_TOOL,
|
|
417
402
|
} from "./collector-role.ts";
|
|
418
|
-
export type {
|
|
419
|
-
|
|
420
|
-
ReviewerTargetSnapshot,
|
|
421
|
-
ReviewerUsage,
|
|
422
|
-
ReviewerWorkspaceDisposition,
|
|
423
|
-
} from "./reviewer-execution-ledger.ts";
|
|
424
|
-
export type { AcceptedReviewerDispatch, AcceptedReviewerExecution, ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
|
|
425
|
-
export type { ReviewerDispatchRunResult } from "./reviewer-agent.ts";
|
|
426
|
-
export type { CollectorReceipt } from "./collector-receipt.ts";
|
|
403
|
+
export type { ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
|
|
404
|
+
export type { CollectorReceipt } from "./package-contracts/collector-output.ts";
|
|
427
405
|
export type { CollectorGitHubTransport } from "./collector-github.ts";
|
|
428
406
|
export type { CollectorClock } from "./collector-evidence.ts";
|
|
429
407
|
export * from "./navigator-attendance.ts";
|
|
@@ -479,31 +457,10 @@ function activationStage(role: PackagedRole, runtime: ActivationRuntime): { id:
|
|
|
479
457
|
case "judge": return { id: "load-and-install", run: async () => runtime.judge.activate() };
|
|
480
458
|
case "fixer": return { id: "load-and-install", run: async () => runtime.fixer.activate() };
|
|
481
459
|
case "coder": return { id: "load-and-install", run: async () => runtime.coder.activate(runtime.context) };
|
|
482
|
-
case "reviewer": return { id: "load-
|
|
483
|
-
// Envelope owns flag decode inside the activation stage (trace + fail-closed path).
|
|
460
|
+
case "reviewer": return { id: "load-and-install", run: async () => {
|
|
484
461
|
const admitted = runtime.decodeReviewerAdmitted();
|
|
485
462
|
const activation = await runtime.reviewer.activate(runtime.context, admitted);
|
|
486
463
|
runtime.bindReviewerParent(activation);
|
|
487
|
-
const result = await activation.dispatcher.dispatch(activation.fixedBaseRevision, { context: runtime.context });
|
|
488
|
-
if (result.status !== "accepted") {
|
|
489
|
-
const rejection = new ExplicitInternalActivationError(
|
|
490
|
-
`Fixed Reviewer dispatch was not accepted: ${result.status}: ${result.diagnostic}`,
|
|
491
|
-
{
|
|
492
|
-
knownCause: "activation",
|
|
493
|
-
name: "ReviewerDispatchRejectionError",
|
|
494
|
-
},
|
|
495
|
-
);
|
|
496
|
-
// Pi stderr cannot carry the structured violations. Do not mask a durable
|
|
497
|
-
// write failure: its infrastructure cause is truer than the unwritten page.
|
|
498
|
-
const runDir = process.env.AK_ROLE_RUN_DIR;
|
|
499
|
-
if (typeof runDir === "string" && runDir.trim() !== "") {
|
|
500
|
-
recordReviewerDispatchRejectionSync(runDir, {
|
|
501
|
-
diagnostic: rejection.message,
|
|
502
|
-
violations: result.violations,
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
throw rejection;
|
|
506
|
-
}
|
|
507
464
|
} };
|
|
508
465
|
case "collector": return { id: "load-and-install", run: async () => runtime.collector.activate(runtime.context, runtime.event) };
|
|
509
466
|
case "doctor": return { id: "load-and-install", run: async () => runtime.doctor.activate() };
|
|
@@ -616,8 +573,6 @@ export type RoleRuntimeDependencies = {
|
|
|
616
573
|
loadCoderTask?(path: string): Promise<string>;
|
|
617
574
|
loadReviewerSoul?(): Promise<string>;
|
|
618
575
|
createReviewerPinnedGitReader?(): Promise<ReviewerPinnedGitReader>;
|
|
619
|
-
/** Shared-seam issue-fetch capability for Reviewer Spec self-fetch (#343). */
|
|
620
|
-
createReviewerIssueFetcher?(): ReviewerIssueFetcher;
|
|
621
576
|
loadCollectorSoul?(): Promise<string>;
|
|
622
577
|
/** #677: optional packaged seed for first-use general bot handbook. */
|
|
623
578
|
loadCollectorHandbookSeed?(): Promise<string>;
|
|
@@ -642,16 +597,6 @@ export type RoleRuntimeDependencies = {
|
|
|
642
597
|
loadCanonicalSkillBinding?(
|
|
643
598
|
name: "tdd" | "code-review",
|
|
644
599
|
): Promise<AnyCanonicalSkillBinding>;
|
|
645
|
-
runReviewerDispatch?(
|
|
646
|
-
dispatch: AcceptedReviewerExecution,
|
|
647
|
-
options: {
|
|
648
|
-
context: HostContext;
|
|
649
|
-
signal?: AbortSignal;
|
|
650
|
-
/** Request-scoped RoleHost flag reader for engine axis (#818). */
|
|
651
|
-
getFlag?: (name: string) => boolean | string | undefined;
|
|
652
|
-
},
|
|
653
|
-
): Promise<ReviewerDispatchRunResult>;
|
|
654
|
-
shutdownReviewerAgent?(): Promise<void>;
|
|
655
600
|
activationClock?(): string;
|
|
656
601
|
activationTraceWriter?: (record: ActivationTraceRecord) => void | Promise<void>;
|
|
657
602
|
/** Wall-clock ISO timestamps for tool-execution observation records; defaults to activationClock/Date. */
|
|
@@ -728,7 +673,7 @@ export function publicNavigatorSettlement(role: string, phase: NavigatorPhase, e
|
|
|
728
673
|
}
|
|
729
674
|
|
|
730
675
|
export async function projectClosedSubmissionLifecycle(
|
|
731
|
-
|
|
676
|
+
closed: import("./submission-ledger.ts").ClosedSubmission,
|
|
732
677
|
context: HostContext,
|
|
733
678
|
phase: NavigatorPhase,
|
|
734
679
|
recordAccepted: () => void,
|
|
@@ -736,12 +681,12 @@ export async function projectClosedSubmissionLifecycle(
|
|
|
736
681
|
): Promise<void> {
|
|
737
682
|
recordAccepted();
|
|
738
683
|
const closure = {
|
|
739
|
-
toolName: navigatorOutputTool(
|
|
684
|
+
toolName: navigatorOutputTool(closed.role)!,
|
|
740
685
|
isError: false,
|
|
741
|
-
details:
|
|
686
|
+
details: closed.accepted,
|
|
742
687
|
};
|
|
743
688
|
context.sessionManager.appendCustomEntry?.("ak-role-submission-closure", closure);
|
|
744
|
-
await settle(publicNavigatorSettlement(
|
|
689
|
+
await settle(publicNavigatorSettlement(closed.role, phase, closure));
|
|
745
690
|
}
|
|
746
691
|
|
|
747
692
|
/**
|
|
@@ -934,7 +879,7 @@ export function createAuditorRoleRuntime(
|
|
|
934
879
|
*/
|
|
935
880
|
function readDiaristTicketAssertion(
|
|
936
881
|
submitted: Record<string, unknown> | undefined,
|
|
937
|
-
): { kind: "true-unbound" } | { kind: "ticket"; ticketNumber: number } {
|
|
882
|
+
): { kind: "true-unbound" } | { kind: "ticket"; ticketNumber: number } | { kind: "invalid" } {
|
|
938
883
|
if (submitted === undefined || !("ticketNumber" in submitted)) {
|
|
939
884
|
return { kind: "true-unbound" };
|
|
940
885
|
}
|
|
@@ -949,9 +894,7 @@ function readDiaristTicketAssertion(
|
|
|
949
894
|
return { kind: "ticket", ticketNumber: n };
|
|
950
895
|
}
|
|
951
896
|
}
|
|
952
|
-
|
|
953
|
-
"diarist ticketNumber must be a safe integer >= 1, null, or absent",
|
|
954
|
-
);
|
|
897
|
+
return { kind: "invalid" };
|
|
955
898
|
}
|
|
956
899
|
|
|
957
900
|
/** Run coordinates + optional pre-bound ticket from durable pages (#779). */
|
|
@@ -1010,61 +953,22 @@ export function createDiaristRoleRuntime(
|
|
|
1010
953
|
parameters !== null && typeof parameters === "object" && !Array.isArray(parameters)
|
|
1011
954
|
? (parameters as Record<string, unknown>)
|
|
1012
955
|
: undefined;
|
|
1013
|
-
|
|
1014
|
-
// LLM cannot identify the court target — escalate without machine facts.
|
|
1015
|
-
// Strip sitian (锚定宪法) and ticketNumber (must not leak into
|
|
1016
|
-
// caller-visible admitted typed key via decisiveFacts mirror).
|
|
1017
|
-
if (submitted?.status === "escalate") {
|
|
1018
|
-
if (!("sitian" in submitted) && !("ticketNumber" in submitted)) {
|
|
1019
|
-
return submitted;
|
|
1020
|
-
}
|
|
1021
|
-
const stripped = { ...submitted };
|
|
1022
|
-
delete stripped.sitian;
|
|
1023
|
-
delete stripped.ticketNumber;
|
|
1024
|
-
return stripped;
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
956
|
const assertion = readDiaristTicketAssertion(submitted);
|
|
1028
957
|
const coords = readDiaristRunCoordinates();
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
? coords.boundTicketNumber
|
|
1035
|
-
: assertion.kind === "ticket"
|
|
1036
|
-
? assertion.ticketNumber
|
|
1037
|
-
: undefined;
|
|
1038
|
-
|
|
1039
|
-
// true-unbound → 无录 (no volume). Cannot-identify must arrive as
|
|
1040
|
-
// status=escalate above — never as silent unbound.
|
|
1041
|
-
if (ticketNumber === undefined) {
|
|
1042
|
-
if (submitted === undefined || !("sitian" in submitted)) {
|
|
1043
|
-
return { ...(submitted ?? { receipt: parameters }), ticketNumber: null };
|
|
958
|
+
// #836 7.3: pre-bound ticket is material for the LLM, not an override.
|
|
959
|
+
const ticketNumber = assertion.kind === "ticket" ? assertion.ticketNumber : undefined;
|
|
960
|
+
if (ticketNumber !== undefined) {
|
|
961
|
+
if (coords.boundTicketNumber === undefined) {
|
|
962
|
+
await bindTicketNumberOnRunDirectory(coords.runDirectory, ticketNumber);
|
|
1044
963
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
if (coords.boundTicketNumber === undefined) {
|
|
1054
|
-
await bindTicketNumberOnRunDirectory(coords.runDirectory, ticketNumber);
|
|
964
|
+
await commitDiaristEntries({
|
|
965
|
+
ticketNumber,
|
|
966
|
+
cwd: coords.projectRoot,
|
|
967
|
+
home: coords.home,
|
|
968
|
+
entries: projectDiaristEntries(parameters),
|
|
969
|
+
});
|
|
1055
970
|
}
|
|
1056
|
-
|
|
1057
|
-
const facts = await commitDiaristEntries({
|
|
1058
|
-
ticketNumber,
|
|
1059
|
-
cwd: coords.projectRoot,
|
|
1060
|
-
home: coords.home,
|
|
1061
|
-
entries: projectDiaristEntries(parameters),
|
|
1062
|
-
});
|
|
1063
|
-
return {
|
|
1064
|
-
...(submitted ?? { receipt: parameters }),
|
|
1065
|
-
ticketNumber,
|
|
1066
|
-
sitian: facts,
|
|
1067
|
-
};
|
|
971
|
+
return parameters;
|
|
1068
972
|
},
|
|
1069
973
|
},
|
|
1070
974
|
dependencies,
|
|
@@ -1136,14 +1040,14 @@ export function createRoleRuntimeExtension(
|
|
|
1136
1040
|
dependencies: RoleRuntimeDependencies,
|
|
1137
1041
|
): (envelopeHost: RoleEnvelopeHost) => void {
|
|
1138
1042
|
return (envelopeHost) => {
|
|
1139
|
-
let projectClosedSubmission: (
|
|
1043
|
+
let projectClosedSubmission: (closed: import("./submission-ledger.ts").ClosedSubmission, context: HostContext) => Promise<void> = async () => {
|
|
1140
1044
|
throw new Error("角色终局投射接缝尚未初始化");
|
|
1141
1045
|
};
|
|
1142
1046
|
const roleHost = createSubmissionLedgerHost(
|
|
1143
1047
|
envelopeHost.host,
|
|
1144
1048
|
new Map(PACKAGED_ROLE_REGISTRY.map(({ role, outputTool }) => [outputTool, role])),
|
|
1145
1049
|
failInfrastructure,
|
|
1146
|
-
async (
|
|
1050
|
+
async (closed, context) => projectClosedSubmission(closed, context),
|
|
1147
1051
|
);
|
|
1148
1052
|
roleHost.registerFlag(ROLE_FLAG.name, ROLE_FLAG.definition);
|
|
1149
1053
|
// Reviewer transport flags: shared envelope owns registration (ADR 0018).
|
|
@@ -1225,15 +1129,36 @@ export function createRoleRuntimeExtension(
|
|
|
1225
1129
|
};
|
|
1226
1130
|
pendingNavigatorPresentation = { event, report };
|
|
1227
1131
|
}
|
|
1228
|
-
await
|
|
1132
|
+
// 过时不候: do not await sidecar teardown — parent court must close.
|
|
1133
|
+
// Dispose failure is recorded, not washed; it must not re-block the court.
|
|
1134
|
+
void Promise.resolve(attendance.dispose()).then(
|
|
1135
|
+
undefined,
|
|
1136
|
+
(error) => {
|
|
1137
|
+
try {
|
|
1138
|
+
sitianReport({
|
|
1139
|
+
level: "event",
|
|
1140
|
+
kind: "navigator-dispose-failure",
|
|
1141
|
+
payload: {
|
|
1142
|
+
diagnostic: error instanceof Error ? error.message : String(error),
|
|
1143
|
+
},
|
|
1144
|
+
source: "role-runtime",
|
|
1145
|
+
});
|
|
1146
|
+
} catch (recordError) {
|
|
1147
|
+
envelopeHost.appendEntry?.("ak-navigator-dispose-failure", {
|
|
1148
|
+
diagnostic: error instanceof Error ? error.message : String(error),
|
|
1149
|
+
recordFailure: recordError instanceof Error ? recordError.message : String(recordError),
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
},
|
|
1153
|
+
);
|
|
1229
1154
|
})();
|
|
1230
1155
|
pendingNavigatorSettlement = pending;
|
|
1231
1156
|
await pending;
|
|
1232
1157
|
};
|
|
1233
|
-
projectClosedSubmission = async (
|
|
1234
|
-
|
|
1158
|
+
projectClosedSubmission = async (closed, context) => projectClosedSubmissionLifecycle(
|
|
1159
|
+
closed,
|
|
1235
1160
|
context,
|
|
1236
|
-
navigatorPhase(roleHost,
|
|
1161
|
+
navigatorPhase(roleHost, closed.role),
|
|
1237
1162
|
() => receiptDelivery.recordAccepted(),
|
|
1238
1163
|
settleNavigatorProjection,
|
|
1239
1164
|
);
|
|
@@ -1278,6 +1203,10 @@ export function createRoleRuntimeExtension(
|
|
|
1278
1203
|
// Soft session_start placeholders (no materials yet) recover here; hard
|
|
1279
1204
|
// contextError from true loader failures stays poisoned and honest.
|
|
1280
1205
|
if (navigatorWorkContext.subjectProvenance === "placeholder") {
|
|
1206
|
+
// Navigator's own input bootstrap, not a rewrite of another role's
|
|
1207
|
+
// output payload (#836 targets the latter): the human's own raw
|
|
1208
|
+
// prompt bytes, copied verbatim into Navigator's work context when
|
|
1209
|
+
// nothing else has supplied a subject yet.
|
|
1281
1210
|
const subject = event.prompt.trim();
|
|
1282
1211
|
if (subject !== "") {
|
|
1283
1212
|
const root = subjectPath(ctx.sessionManager.getSessionDir(), ctx.cwd);
|
|
@@ -1300,53 +1229,23 @@ export function createRoleRuntimeExtension(
|
|
|
1300
1229
|
// Envelope-owned Reviewer expansion capture + parent prompt assembly (no role-module callback).
|
|
1301
1230
|
if (role === "reviewer" && activeReviewerParent !== undefined) {
|
|
1302
1231
|
if (!reviewerExpansionCaptured) {
|
|
1303
|
-
if (
|
|
1304
|
-
|
|
1305
|
-
|| activeReviewerParent.skillBinding.captureExpansion(
|
|
1232
|
+
if (reviewerOriginalRequest !== undefined) {
|
|
1233
|
+
activeReviewerParent.skillBinding.captureExpansion(
|
|
1306
1234
|
roleHost.capabilities?.skillExpansion(event.prompt),
|
|
1307
1235
|
reviewerOriginalRequest,
|
|
1308
|
-
) === undefined
|
|
1309
|
-
) {
|
|
1310
|
-
failInfrastructure(
|
|
1311
|
-
new Error("Canonical code-review Skill expansion did not match the captured request"),
|
|
1312
|
-
ctx,
|
|
1313
1236
|
);
|
|
1314
1237
|
}
|
|
1315
1238
|
reviewerExpansionCaptured = true;
|
|
1316
1239
|
}
|
|
1317
|
-
const specDisposition = activeReviewerParent.getSpecDisposition();
|
|
1318
1240
|
return {
|
|
1319
1241
|
systemPrompt: assembleReviewerParentSystemPrompt({
|
|
1320
1242
|
baseSystemPrompt: event.systemPrompt,
|
|
1321
1243
|
soul: activeReviewerParent.soul,
|
|
1322
|
-
...(specDisposition === undefined ? {} : { specDisposition }),
|
|
1323
1244
|
}),
|
|
1324
1245
|
};
|
|
1325
1246
|
}
|
|
1326
1247
|
// #676 E / J1: collector materials + drift gates share this envelope hook (no parallel register).
|
|
1327
1248
|
if (role === "collector" && activeCollector !== undefined) {
|
|
1328
|
-
const options = event.systemPromptOptions;
|
|
1329
|
-
if (options.skills && options.skills.length > 0) {
|
|
1330
|
-
failInfrastructure(
|
|
1331
|
-
activeCollector.ledger.latchFatal("通进司检测到系统提示中的环境 skills"),
|
|
1332
|
-
ctx,
|
|
1333
|
-
);
|
|
1334
|
-
}
|
|
1335
|
-
if (options.contextFiles && options.contextFiles.length > 0) {
|
|
1336
|
-
failInfrastructure(
|
|
1337
|
-
activeCollector.ledger.latchFatal("通进司检测到系统提示中的环境 context files"),
|
|
1338
|
-
ctx,
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1341
|
-
if (
|
|
1342
|
-
typeof options.appendSystemPrompt === "string"
|
|
1343
|
-
&& options.appendSystemPrompt.trim().length > 0
|
|
1344
|
-
) {
|
|
1345
|
-
failInfrastructure(
|
|
1346
|
-
activeCollector.ledger.latchFatal("通进司检测到 appendSystemPrompt 漂移"),
|
|
1347
|
-
ctx,
|
|
1348
|
-
);
|
|
1349
|
-
}
|
|
1350
1249
|
if (!collectorFirstDispatchDone) {
|
|
1351
1250
|
collectorFirstDispatchDone = true;
|
|
1352
1251
|
activeCollector.ledger.recordActivation(activeCollector.clock);
|
|
@@ -1379,7 +1278,7 @@ export function createRoleRuntimeExtension(
|
|
|
1379
1278
|
const reason = (event.content ?? [])
|
|
1380
1279
|
.map((part) => part.type === "text" && "text" in part ? part.text : "")
|
|
1381
1280
|
.join("")
|
|
1382
|
-
.trim()
|
|
1281
|
+
.trim();
|
|
1383
1282
|
receiptDelivery.recordRejected(reason);
|
|
1384
1283
|
}
|
|
1385
1284
|
// Accepted/human terminal projection belongs exclusively to typed ledger
|
|
@@ -1391,7 +1290,7 @@ export function createRoleRuntimeExtension(
|
|
|
1391
1290
|
// Persist typed infrastructure-failure fact onto the role session toolResult so
|
|
1392
1291
|
// exact-session restart shares the same durable completion classification.
|
|
1393
1292
|
if (infrastructureDetails !== undefined) {
|
|
1394
|
-
return {
|
|
1293
|
+
return { isError: true };
|
|
1395
1294
|
}
|
|
1396
1295
|
// Submission non-pass: throw kept message text for the model; project the
|
|
1397
1296
|
// envelope-bound structured result onto session details at this tool_result seam.
|
|
@@ -1405,11 +1304,7 @@ export function createRoleRuntimeExtension(
|
|
|
1405
1304
|
// a second file, grep, or nesting step. Receipt details stay contract-pure;
|
|
1406
1305
|
// unavailable/no-advice leave the settlement untouched.
|
|
1407
1306
|
if (event.isError) return;
|
|
1408
|
-
|
|
1409
|
-
if (decorated === undefined) return;
|
|
1410
|
-
return {
|
|
1411
|
-
content: decorated.content as typeof event.content,
|
|
1412
|
-
};
|
|
1307
|
+
return;
|
|
1413
1308
|
});
|
|
1414
1309
|
// Queue receipt delivery before `agent_settled`: that event means Pi has
|
|
1415
1310
|
// already decided no queued continuation will run, so a triggerTurn there is
|
|
@@ -1419,9 +1314,10 @@ export function createRoleRuntimeExtension(
|
|
|
1419
1314
|
const lastMessage = event.messages.at(-1);
|
|
1420
1315
|
if (lastMessage?.role === "assistant"
|
|
1421
1316
|
&& (lastMessage.stopReason === "error" || lastMessage.stopReason === "aborted")) {
|
|
1422
|
-
//
|
|
1423
|
-
|
|
1424
|
-
|
|
1317
|
+
// Abort after an already-recorded receipt must not un-accept or催交.
|
|
1318
|
+
if (receiptDelivery.nextAction() !== "accepted") {
|
|
1319
|
+
receiptDelivery.stopForInfrastructure();
|
|
1320
|
+
}
|
|
1425
1321
|
return;
|
|
1426
1322
|
}
|
|
1427
1323
|
if (receiptDelivery.nextAction() === "request-delivery") {
|
|
@@ -1606,21 +1502,6 @@ export function createRoleRuntimeExtension(
|
|
|
1606
1502
|
}
|
|
1607
1503
|
return dependencies.loadCanonicalSkillBinding(name);
|
|
1608
1504
|
},
|
|
1609
|
-
...(dependencies.createReviewerIssueFetcher === undefined
|
|
1610
|
-
? {}
|
|
1611
|
-
: { fetchIssue: dependencies.createReviewerIssueFetcher() }),
|
|
1612
|
-
async runDispatch(dispatch, options) {
|
|
1613
|
-
if (dependencies.runReviewerDispatch === undefined) throw new Error("Reviewer runtime dependencies are not configured");
|
|
1614
|
-
// #818: request-scoped engine flag reaches axis sub-session via same RoleHost
|
|
1615
|
-
// that parent registerEngineDetourTool reads — never ambient process.env.
|
|
1616
|
-
return dependencies.runReviewerDispatch(dispatch, {
|
|
1617
|
-
...options,
|
|
1618
|
-
getFlag: (name) => roleHost.getFlag(name),
|
|
1619
|
-
});
|
|
1620
|
-
},
|
|
1621
|
-
...(dependencies.shutdownReviewerAgent === undefined
|
|
1622
|
-
? {}
|
|
1623
|
-
: { shutdownAgent: dependencies.shutdownReviewerAgent }),
|
|
1624
1505
|
},
|
|
1625
1506
|
hostActions,
|
|
1626
1507
|
);
|
|
@@ -1767,23 +1648,6 @@ export function createRoleRuntimeExtension(
|
|
|
1767
1648
|
`Collector does not support session_start reason ${event.reason}`,
|
|
1768
1649
|
);
|
|
1769
1650
|
}
|
|
1770
|
-
// #676 J4: ambient skill/prompt/template commands fail closed at activation.
|
|
1771
|
-
const commands = roleHost.getCommands?.() ?? [];
|
|
1772
|
-
const ambientCommands = commands.filter((command) => {
|
|
1773
|
-
const name = command.name.toLowerCase();
|
|
1774
|
-
return (
|
|
1775
|
-
name.includes("skill")
|
|
1776
|
-
|| name.includes("prompt")
|
|
1777
|
-
|| name.startsWith("template")
|
|
1778
|
-
);
|
|
1779
|
-
});
|
|
1780
|
-
if (ambientCommands.length > 0) {
|
|
1781
|
-
throw new Error(
|
|
1782
|
-
`Collector detected ambient instruction commands: ${
|
|
1783
|
-
ambientCommands.map((c) => c.name).join(", ")
|
|
1784
|
-
}`,
|
|
1785
|
-
);
|
|
1786
|
-
}
|
|
1787
1651
|
// Business tools behind admission barrier (inert-without-role invariant).
|
|
1788
1652
|
// First activation: fail closed if a required name is already occupied.
|
|
1789
1653
|
// Later activations reuse the once-registered tools (registerBusinessTools is idempotent).
|
|
@@ -6,20 +6,6 @@ import {
|
|
|
6
6
|
WorkerUnfinishedReasonReminderError,
|
|
7
7
|
} from "./submission-errors.ts";
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Mechanical non-sole resume text — one shared authority for Pi followUp and
|
|
11
|
-
* ACP/headless closeRound retry (#813). Officer bounce/escalate use projected
|
|
12
|
-
* receipt text instead; this string is only the round-shape correction.
|
|
13
|
-
*/
|
|
14
|
-
export const NON_SOLE_ROUND_RESUME_MESSAGE =
|
|
15
|
-
"终局交卷并非本轮唯一工具调用。";
|
|
16
|
-
|
|
17
|
-
/** Resume text for mechanical deliverSubmissionRejection codes (no officer receipt). */
|
|
18
|
-
export function mechanicalSubmissionRejectionResumeMessage(code: string): string {
|
|
19
|
-
if (code === "non-sole-round") return NON_SOLE_ROUND_RESUME_MESSAGE;
|
|
20
|
-
return code;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
9
|
/** Shared, unforgeable identity for submission errors that the same session may correct. */
|
|
24
10
|
const correctableSubmissionErrorBrand = Symbol("ak-roles.correctable-submission-error");
|
|
25
11
|
|
package/src/submission-errors.ts
CHANGED
|
@@ -15,7 +15,12 @@ function gatekeeperNonPassMessage(result: GatekeeperNonPassResult): string {
|
|
|
15
15
|
if (result.status === "bounce" || result.status === "escalate") {
|
|
16
16
|
return serializeReceipt(result.receipt);
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
if (result.status === "transport_failure") {
|
|
19
|
+
const head = `门下省 ${result.status}(${result.stage}):${result.reason}`;
|
|
20
|
+
return result.submission === undefined
|
|
21
|
+
? head
|
|
22
|
+
: `${head}\n${serializeReceipt(result.submission)}`;
|
|
23
|
+
}
|
|
19
24
|
return `门下省 ${result.status}(${result.stage}):${result.reason}`;
|
|
20
25
|
}
|
|
21
26
|
|