@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
|
@@ -8,14 +8,14 @@ import { appendFile, lstat, mkdir, readFile, readdir, writeFile } from "node:fs/
|
|
|
8
8
|
import { dirname, join } from "node:path";
|
|
9
9
|
import { readAnalystGateCyclesFromAuditorRoles, } from "../analyst-gate-cycles-read.js";
|
|
10
10
|
import { readSitianRecords, resolveSitianRecordPath, sitianReport } from "../sitian-facade.js";
|
|
11
|
-
import {
|
|
11
|
+
import { hasFreshAttemptSubmission, readRecordedSubmissionRows, readRecordedSubmissions, } from "../submission-ledger.js";
|
|
12
12
|
import { isAuditEscalationResult } from "../audit-escalation.js";
|
|
13
13
|
import { AUDITOR_SOUL_ROLES } from "../auditor-soul.js";
|
|
14
14
|
import { DOCTOR_AUDIT_TOOL_NAME } from "../doctor-auditor.js";
|
|
15
15
|
import { JUDGE_AUDIT_TOOL_NAME } from "../judge-auditor.js";
|
|
16
16
|
import { knownFailureFromProviderStop } from "../pi/known-failure.js";
|
|
17
17
|
import { readReviewerDispatchRejection } from "./reviewer-dispatch-rejection.js";
|
|
18
|
-
import {
|
|
18
|
+
import { isV1ResumableProvider, readLatestTypedProviderHttpObservation, readTypedHttp429Observation, } from "./run-lifecycle.js";
|
|
19
19
|
import { AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, COMPLIANCE_RESPONSE_ENTRY_TYPE, readComplianceCandidate, } from "../compliance-transport.js";
|
|
20
20
|
// COMPLIANCE_RESPONSE_ENTRY_TYPE remains for boundRetainedAuditResponse (call/result
|
|
21
21
|
// interval binding on historical session bytes). Provider-stop retain authority is Sitian.
|
|
@@ -24,8 +24,8 @@ import { ENGINE_DETOUR_TOOL_NAME } from "../engine-detour.js";
|
|
|
24
24
|
import { JUDGE_OUTPUT_TOOL_NAME, } from "../package-contracts/judge-output.js";
|
|
25
25
|
import { COLLECTOR_OUTPUT_TOOL, } from "../package-contracts/collector-output.js";
|
|
26
26
|
import { CODER_OUTPUT_TOOL_NAME, FIXER_OUTPUT_TOOL_NAME, } from "../package-contracts/worker-output.js";
|
|
27
|
-
import { validateAcceptedDetails } from "../package-contracts/terminating-tools.js";
|
|
28
27
|
import { DOCTOR_OUTPUT_TOOL_NAME, } from "../doctor-contracts.js";
|
|
28
|
+
import { DOCTOR_CANDIDATE_ENTRY_TYPE } from "../dossier-resolution.js";
|
|
29
29
|
import { REVIEWER_OUTPUT_TOOL_NAME, } from "../package-contracts/reviewer-output.js";
|
|
30
30
|
import { MERGER_OUTPUT_TOOL_NAME, } from "../merger-contracts.js";
|
|
31
31
|
import { NOTARY_OUTPUT_TOOL_NAME, } from "../notary-contracts.js";
|
|
@@ -38,7 +38,7 @@ import { NAVIGATOR_OUTPUT_TOOL_NAME, } from "../package-contracts/navigator-outp
|
|
|
38
38
|
import { AUDITOR_OUTPUT_TOOL_NAME, } from "../package-contracts/auditor-output.js";
|
|
39
39
|
import { observePackagedMethodSkillInvocation, } from "../package-resources/method-skill.js";
|
|
40
40
|
import { classifyPackagedRoleTerminalResult, findLatestDurablePackagedRoleTerminal, hasNavigatorInfrastructureFailureBase, isAcceptedPackagedRoleTerminalResult, isReceiptSettlementBindingClear, NAVIGATOR_INVOCATION_ENTRY, parseInvocationMarkerIdentity, } from "../navigator-invocation-identity.js";
|
|
41
|
-
import { NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, parseNoReceiptLifecycleFacts } from "../receipt-delivery-policy.js";
|
|
41
|
+
import { NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, RECEIPT_DELIVERY_TURN_LIMIT, noReceiptLifecycleFacts, parseNoReceiptLifecycleFacts, } from "../receipt-delivery-policy.js";
|
|
42
42
|
import { ensureRunArtifactsDir, homeFromRunDirectory, } from "./invocation.js";
|
|
43
43
|
/** Ledger reads use the run's machine home — not ambient process HOME (child write vs parent settle). */
|
|
44
44
|
function sealedLedgerHome(admitted) {
|
|
@@ -52,120 +52,95 @@ function ledgerReadScope(admitted, scope) {
|
|
|
52
52
|
: { attemptId: scope.courtAttemptId }),
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export async function sealedAcceptanceRedispatchDisposition(admitted) {
|
|
59
|
-
try {
|
|
60
|
-
if ((await sealedLedgerOutcome(admitted)) !== undefined) {
|
|
61
|
-
return { kind: "block", reason: "sealed-accepted" };
|
|
62
|
-
}
|
|
63
|
-
return { kind: "allow" };
|
|
64
|
-
}
|
|
65
|
-
catch (cause) {
|
|
66
|
-
// Ledger authority must not wash read failure into "unsealed" (#648).
|
|
67
|
-
return { kind: "block", reason: "authority-failed", cause };
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async function auditEscalationLedgerOutcome(admitted, role, scope) {
|
|
71
|
-
const projection = await readAuditEscalationSubmission(admitted.projectRoot, admitted.runId, ledgerReadScope(admitted, scope));
|
|
72
|
-
if (projection?.role !== role)
|
|
55
|
+
function roleOutcomeFromRows(role, rows) {
|
|
56
|
+
const mine = rows.filter((row) => row.role === role);
|
|
57
|
+
if (mine.length === 0)
|
|
73
58
|
return undefined;
|
|
74
|
-
|
|
59
|
+
const payloads = mine.map((row) => row.accepted);
|
|
60
|
+
if (mine.some((row) => row.kind === "audit-escalation")) {
|
|
61
|
+
return { kind: "audit_escalation", role, status: "audit_escalation", payloads };
|
|
62
|
+
}
|
|
63
|
+
return { kind: "accepted", role, payloads };
|
|
75
64
|
}
|
|
76
|
-
async function
|
|
77
|
-
const
|
|
78
|
-
return
|
|
79
|
-
? sealed
|
|
80
|
-
: auditEscalationLedgerOutcome(admitted, role, scope);
|
|
65
|
+
async function sealedLedgerOutcome(admitted, role, scope) {
|
|
66
|
+
const rows = await readRecordedSubmissionRows(admitted.projectRoot, admitted.runId, ledgerReadScope(admitted, scope));
|
|
67
|
+
return roleOutcomeFromRows(role, rows);
|
|
81
68
|
}
|
|
82
|
-
/** Transitional host-session reads remain only for non-sealed failure and audit evidence. */
|
|
83
|
-
function coordinatesFromAdmitted(authority, admitted) {
|
|
84
|
-
return authority.decode(admitted.principal);
|
|
85
|
-
}
|
|
86
|
-
import { exitCodeForTerminalOutcome, formatTerminalResult, isLawfulTypedTerminalOutcome, recommendationNavigatorFact, buildResidualIncompleteTerminalOutcome, redactExactRunId, } from "./terminal.js";
|
|
87
|
-
export { exitCodeForTerminalOutcome, formatTerminalResult, isLawfulTypedTerminalOutcome, };
|
|
88
|
-
/** Presentation bound for one stderr diagnostic line (durable artifact keeps full text). */
|
|
89
|
-
export const CONCISE_DIAGNOSTIC_MAX_CHARS = 480;
|
|
90
69
|
/**
|
|
91
|
-
* True when
|
|
92
|
-
*
|
|
93
|
-
* (
|
|
70
|
+
* True when this court/attempt itself already produced a sealed or
|
|
71
|
+
* audit-escalation submission (#836 r12 class 2). Presentation
|
|
72
|
+
* (submissions/payloads) always stays run-scoped and unfiltered — this is a
|
|
73
|
+
* control-flow signal only, consumed to keep a stale prior-attempt
|
|
74
|
+
* acceptance from outranking this attempt's own real host-turn failure.
|
|
75
|
+
* Absent a courtAttemptId scope there is no distinct prior attempt to stale
|
|
76
|
+
* against, so this defaults true (unchanged behavior for ordinary,
|
|
77
|
+
* non-court dispatches).
|
|
94
78
|
*/
|
|
95
|
-
export function
|
|
96
|
-
if (
|
|
97
|
-
return true;
|
|
98
|
-
if (line.startsWith("event:"))
|
|
99
|
-
return true;
|
|
100
|
-
if (/\btokens?=/.test(line))
|
|
101
|
-
return true;
|
|
102
|
-
if (/\btool_calls?=/.test(line))
|
|
79
|
+
export async function attemptProducedFreshSubmission(admitted, scope) {
|
|
80
|
+
if (scope?.courtAttemptId === undefined || scope.courtAttemptId.length === 0)
|
|
103
81
|
return true;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
82
|
+
return hasFreshAttemptSubmission(admitted.projectRoot, admitted.runId, scope.courtAttemptId, sealedLedgerHome(admitted));
|
|
83
|
+
}
|
|
84
|
+
/** #836: every raw role payload in settle scope (调几次记几次). */
|
|
85
|
+
export async function recordedSubmissionPayloads(admitted, scope) {
|
|
86
|
+
return readRecordedSubmissions(admitted.projectRoot, admitted.runId, ledgerReadScope(admitted, scope));
|
|
87
|
+
}
|
|
88
|
+
export function withSubmissions(terminal, submissions) {
|
|
89
|
+
if (submissions.length === 0)
|
|
90
|
+
return terminal;
|
|
91
|
+
const roleOutcome = terminal.roleOutcome;
|
|
92
|
+
const withPayloads = roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation"
|
|
93
|
+
? { ...roleOutcome, payloads: (roleOutcome.payloads ?? []).length > 0 ? roleOutcome.payloads : submissions }
|
|
94
|
+
: roleOutcome.kind === "failure"
|
|
95
|
+
? { ...roleOutcome, payloads: roleOutcome.payloads ?? submissions }
|
|
96
|
+
: roleOutcome;
|
|
97
|
+
return { ...terminal, roleOutcome: withPayloads, submissions };
|
|
98
|
+
}
|
|
99
|
+
/** Attach full ledger submissions onto any settled terminal (#836). */
|
|
100
|
+
export async function attachRecordedSubmissions(admitted, terminal, scope) {
|
|
101
|
+
return withSubmissions(terminal, await recordedSubmissionPayloads(admitted, scope));
|
|
119
102
|
}
|
|
120
103
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* those footers must not displace the primary diagnostic.
|
|
104
|
+
* Host ended with no recorded submission — lawful no_receipt (exit 0).
|
|
105
|
+
* Does not invent an output failure for an empty ledger.
|
|
124
106
|
*/
|
|
125
|
-
export function
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
107
|
+
export async function settleHostEndedNoReceipt(admitted, authority) {
|
|
108
|
+
const facts = noReceiptLifecycleFacts({
|
|
109
|
+
terminalToolCalled: false,
|
|
110
|
+
rejectedReceipts: [],
|
|
111
|
+
deliveryTurns: RECEIPT_DELIVERY_TURN_LIMIT,
|
|
112
|
+
runPointer: admitted.runDirectory,
|
|
113
|
+
attemptPointer: `current:${admitted.runDirectory}`,
|
|
114
|
+
});
|
|
115
|
+
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
116
|
+
return withOptionalGateProjection({
|
|
117
|
+
roleOutcome: {
|
|
118
|
+
kind: "no_receipt",
|
|
119
|
+
role: admitted.role,
|
|
120
|
+
status: "no-accepted-receipt",
|
|
121
|
+
...facts,
|
|
122
|
+
decisiveFacts: facts,
|
|
123
|
+
},
|
|
124
|
+
navigator: await extractNavigatorFactFromAdmittedSession(coordinates.sessionFile),
|
|
125
|
+
artifacts: [],
|
|
126
|
+
runId: admitted.runId,
|
|
127
|
+
}, coordinates.sessionDirectory);
|
|
140
128
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return `${diagnostic.slice(0, maxChars - 1)}…`;
|
|
129
|
+
async function closedLedgerOutcome(admitted, role, scope) {
|
|
130
|
+
return sealedLedgerOutcome(admitted, role, scope);
|
|
131
|
+
}
|
|
132
|
+
/** Transitional host-session reads remain only for non-sealed failure and audit evidence. */
|
|
133
|
+
function coordinatesFromAdmitted(authority, admitted) {
|
|
134
|
+
return authority.decode(admitted.principal);
|
|
148
135
|
}
|
|
136
|
+
import { exitCodeForTerminalOutcome, formatTerminalResult, isLawfulTypedTerminalOutcome, lastRolePayloadRecord, recommendationNavigatorFact, } from "./terminal.js";
|
|
137
|
+
export { exitCodeForTerminalOutcome, formatTerminalResult, isLawfulTypedTerminalOutcome, };
|
|
149
138
|
/**
|
|
150
|
-
*
|
|
151
|
-
* Prefers the last nonblank line that is not a frame, observation flood, or docs-path footer.
|
|
152
|
-
* Returns the full selected diagnostic (bound only at presentation).
|
|
139
|
+
* Host stderr as recorded — full bytes, no flood filter, no char clip (#836).
|
|
153
140
|
*/
|
|
154
141
|
export function conciseChildDiagnostic(stderr, fallback) {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
.map((line) => line.trim())
|
|
158
|
-
.filter((line) => line.length > 0);
|
|
159
|
-
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
160
|
-
const line = lines[i];
|
|
161
|
-
if (isChildDiagnosticFloodLine(line))
|
|
162
|
-
continue;
|
|
163
|
-
if (isChildDiagnosticHelpFooterLine(line))
|
|
164
|
-
continue;
|
|
165
|
-
// Strip a leading "Error:" label but keep the message identity.
|
|
166
|
-
return line.replace(/^Error:\s*/i, "").trim() || fallback;
|
|
167
|
-
}
|
|
168
|
-
return fallback;
|
|
142
|
+
const trimmed = stderr.trim();
|
|
143
|
+
return trimmed.length > 0 ? stderr : fallback;
|
|
169
144
|
}
|
|
170
145
|
export function formatCliDiagnostic(message) {
|
|
171
146
|
return `ak-role: ${message}\n`;
|
|
@@ -174,14 +149,10 @@ export function formatCliDiagnostic(message) {
|
|
|
174
149
|
* One concise stderr line for humans. Durable Error Artifact / Terminal keep the
|
|
175
150
|
* full original diagnostic — presentation collapses newlines and flood frames.
|
|
176
151
|
*/
|
|
152
|
+
/** #836: full diagnostic on stderr — no first-line clip / flood filter. */
|
|
177
153
|
export function formatFailureStderrDiagnostic(failure) {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const oneLine = selected
|
|
181
|
-
.split(/\r?\n/)
|
|
182
|
-
.map((line) => line.trim())
|
|
183
|
-
.find((line) => line.length > 0) ?? "failure";
|
|
184
|
-
return formatCliDiagnostic(boundConciseDiagnostic(oneLine));
|
|
154
|
+
const text = failure.diagnostic.trim().length > 0 ? failure.diagnostic : "failure";
|
|
155
|
+
return formatCliDiagnostic(text);
|
|
185
156
|
}
|
|
186
157
|
/**
|
|
187
158
|
* #676 B: one cause face for public stderr — Error.message, else object JSON with
|
|
@@ -655,16 +626,15 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
655
626
|
const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
|
|
656
627
|
if (parentId === undefined)
|
|
657
628
|
return undefined;
|
|
658
|
-
const RESUME_ENVELOPE = RESUME_TRANSPORT_ENVELOPE;
|
|
659
|
-
// Keyed prefix on the transport token line only (#600 / 8e767152). Resume may
|
|
660
|
-
// append engine handbook presentation after the token; settlement must not
|
|
661
|
-
// treat those prose lines as a real user turn or key on their shape.
|
|
662
629
|
const isResumeEnvelopeBytes = (value) => {
|
|
663
630
|
if (typeof value !== "string")
|
|
664
631
|
return false;
|
|
632
|
+
if (value.length === 0)
|
|
633
|
+
return true;
|
|
665
634
|
const nl = value.indexOf("\n");
|
|
666
635
|
const firstLine = nl === -1 ? value : value.slice(0, nl);
|
|
667
|
-
|
|
636
|
+
const body = firstLine === "" && nl !== -1 ? value.slice(nl + 1) : value;
|
|
637
|
+
return body.startsWith("本次配置的劳务引擎及其手册:") || body.startsWith("- engine:");
|
|
668
638
|
};
|
|
669
639
|
const isResumeEnvelope = (msg) => {
|
|
670
640
|
if (!isRecord(msg) || msg.role !== "user")
|
|
@@ -1070,35 +1040,6 @@ function safelyRead(object, key) {
|
|
|
1070
1040
|
return { readable: false };
|
|
1071
1041
|
}
|
|
1072
1042
|
}
|
|
1073
|
-
function auditNoReceiptDecisiveFact(candidate) {
|
|
1074
|
-
const projected = safelyRead(candidate, "auditNoReceipt");
|
|
1075
|
-
if (!projected.readable || projected.value === undefined)
|
|
1076
|
-
return {};
|
|
1077
|
-
try {
|
|
1078
|
-
return { auditNoReceipt: parseNoReceiptLifecycleFacts(projected.value) };
|
|
1079
|
-
}
|
|
1080
|
-
catch {
|
|
1081
|
-
return {};
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
/** Keep optional auditNoReceipt parallel fact when present on sealed details. */
|
|
1085
|
-
function withAuditNoReceiptFacts(candidate) {
|
|
1086
|
-
return {
|
|
1087
|
-
...candidate,
|
|
1088
|
-
...auditNoReceiptDecisiveFact(candidate),
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* ADR 0037: a shape-valid Collector receipt may still name the wrong live target.
|
|
1093
|
-
* Public success binds receipt identity to this admitted repository/PR/request manifest
|
|
1094
|
-
* at the existing settlement seam — not a second receipt factory or validator.
|
|
1095
|
-
*/
|
|
1096
|
-
function collectorReceiptBindingFailure(diagnostic) {
|
|
1097
|
-
const error = new Error(diagnostic);
|
|
1098
|
-
error.name = "CollectorReceiptBindingError";
|
|
1099
|
-
error.knownCause = "output";
|
|
1100
|
-
return error;
|
|
1101
|
-
}
|
|
1102
1043
|
function toolResultText(message) {
|
|
1103
1044
|
const content = message.content;
|
|
1104
1045
|
if (typeof content === "string")
|
|
@@ -1254,23 +1195,6 @@ export function extractEngineDetourInfrastructureFailure(entries) {
|
|
|
1254
1195
|
export async function readEngineDetourInfrastructureFailure(sessionFile) {
|
|
1255
1196
|
return readInfrastructureToolFailure(sessionFile, ENGINE_DETOUR_INFRASTRUCTURE_FAILURE_SPEC);
|
|
1256
1197
|
}
|
|
1257
|
-
/**
|
|
1258
|
-
* Compare a validated receipt with the admitted Collector invocation identity.
|
|
1259
|
-
* Throws a typed output failure when any identity field mismatches.
|
|
1260
|
-
*/
|
|
1261
|
-
export function assertCollectorReceiptMatchesAdmitted(receipt, admitted) {
|
|
1262
|
-
if (receipt.repository !== admitted.repository.canonical) {
|
|
1263
|
-
throw collectorReceiptBindingFailure(`Collector receipt repository "${receipt.repository}" does not match admitted repository "${admitted.repository.canonical}"`);
|
|
1264
|
-
}
|
|
1265
|
-
// #676 A: when admission left the target unbound, receipt.prNumber is the role bind.
|
|
1266
|
-
// When admission bound explicitly/head-commit, receipt must match.
|
|
1267
|
-
if (admitted.prNumber !== undefined && receipt.prNumber !== admitted.prNumber) {
|
|
1268
|
-
throw collectorReceiptBindingFailure(`Collector receipt prNumber ${receipt.prNumber} does not match admitted prNumber ${admitted.prNumber}`);
|
|
1269
|
-
}
|
|
1270
|
-
if (receipt.manifestDigest !== admitted.manifestDigest) {
|
|
1271
|
-
throw collectorReceiptBindingFailure(`Collector receipt manifestDigest does not match admitted manifestDigest`);
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
1198
|
function auditToolNameForRole(role) {
|
|
1275
1199
|
switch (role) {
|
|
1276
1200
|
case "judge":
|
|
@@ -1811,20 +1735,7 @@ async function readLawfulSettlementEntries(sessionFile) {
|
|
|
1811
1735
|
* Session-read failures propagate with typed identity.
|
|
1812
1736
|
*/
|
|
1813
1737
|
export async function readLawfulJudgeRoleOutcome(admitted, authority, scope) {
|
|
1814
|
-
|
|
1815
|
-
if (sealed?.role === "judge") {
|
|
1816
|
-
const details = sealed.decisiveFacts;
|
|
1817
|
-
// sealed.status is the sole authority (written by acceptedFacts at seal).
|
|
1818
|
-
return {
|
|
1819
|
-
kind: "accepted",
|
|
1820
|
-
role: "judge",
|
|
1821
|
-
status: sealed.status,
|
|
1822
|
-
// #757: sealed details pass through (judgeStatus already on the receipt).
|
|
1823
|
-
decisiveFacts: withAuditNoReceiptFacts(details),
|
|
1824
|
-
};
|
|
1825
|
-
}
|
|
1826
|
-
// Non-final: consume ledger audit-escalation projection (no JSONL accepted rebuild).
|
|
1827
|
-
return auditEscalationLedgerOutcome(admitted, "judge", scope);
|
|
1738
|
+
return sealedLedgerOutcome(admitted, "judge", scope);
|
|
1828
1739
|
}
|
|
1829
1740
|
/**
|
|
1830
1741
|
* Single lawful-settlement implementation (session → outcome/Navigator/artifacts).
|
|
@@ -1877,10 +1788,9 @@ async function settleLawfulCoderTerminalResult(admitted, authority, options = {}
|
|
|
1877
1788
|
const ledgerOutcome = await closedLedgerOutcome(admitted, "coder", scope);
|
|
1878
1789
|
if (ledgerOutcome === undefined)
|
|
1879
1790
|
return undefined;
|
|
1880
|
-
// #757: sealed facts pass through — no shape re-project / field drop.
|
|
1881
1791
|
const roleOutcome = ledgerOutcome;
|
|
1882
1792
|
const output = ledgerOutcome.kind === "accepted"
|
|
1883
|
-
? ledgerOutcome.
|
|
1793
|
+
? lastRolePayloadRecord(ledgerOutcome.payloads ?? [])
|
|
1884
1794
|
: undefined;
|
|
1885
1795
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
1886
1796
|
const entries = await readLawfulSettlementEntries(coordinates.sessionFile) ?? [];
|
|
@@ -1999,10 +1909,9 @@ async function settleLawfulFixerTerminalResult(admitted, authority, options, sco
|
|
|
1999
1909
|
const ledgerOutcome = await closedLedgerOutcome(admitted, "fixer", scope);
|
|
2000
1910
|
if (ledgerOutcome === undefined)
|
|
2001
1911
|
return undefined;
|
|
2002
|
-
// #757: sealed facts pass through — no shape re-project / field drop.
|
|
2003
1912
|
const roleOutcome = ledgerOutcome;
|
|
2004
1913
|
const output = ledgerOutcome.kind === "accepted"
|
|
2005
|
-
? ledgerOutcome.
|
|
1914
|
+
? lastRolePayloadRecord(ledgerOutcome.payloads ?? [])
|
|
2006
1915
|
: undefined;
|
|
2007
1916
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
2008
1917
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
@@ -2072,8 +1981,8 @@ async function settleLawfulCollectorTerminalResult(admitted, authority, scope) {
|
|
|
2072
1981
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
2073
1982
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
2074
1983
|
const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
|
|
2075
|
-
const roleOutcome = await sealedLedgerOutcome(admitted, scope);
|
|
2076
|
-
if (roleOutcome?.role !== "collector") {
|
|
1984
|
+
const roleOutcome = await sealedLedgerOutcome(admitted, "collector", scope);
|
|
1985
|
+
if (roleOutcome?.role !== "collector" || roleOutcome.kind !== "accepted") {
|
|
2077
1986
|
// Bounded to the current attempt so multi-attempt resume timeout/no-output
|
|
2078
1987
|
// is not masked by a prior wait-tool residual (#633).
|
|
2079
1988
|
const scanStart = currentAttemptStartIndex(entries);
|
|
@@ -2085,41 +1994,26 @@ async function settleLawfulCollectorTerminalResult(admitted, authority, scope) {
|
|
|
2085
1994
|
if (residual === undefined)
|
|
2086
1995
|
continue;
|
|
2087
1996
|
const candidate = residual.candidate;
|
|
2088
|
-
const
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
candidate,
|
|
2096
|
-
diagnostic: residual.diagnostic,
|
|
2097
|
-
}),
|
|
2098
|
-
navigator: { disposition: "no-advice" },
|
|
2099
|
-
artifacts: [],
|
|
2100
|
-
runId: admitted.runId,
|
|
2101
|
-
};
|
|
1997
|
+
const details = isRecord(candidate) ? candidate : { candidate };
|
|
1998
|
+
const failed = await settleFailureTerminalResult(admitted, {
|
|
1999
|
+
cause: "output",
|
|
2000
|
+
diagnostic: residual.diagnostic,
|
|
2001
|
+
details,
|
|
2002
|
+
}, authority);
|
|
2003
|
+
return attachRecordedSubmissions(admitted, failed, scope);
|
|
2102
2004
|
}
|
|
2103
2005
|
return undefined;
|
|
2104
2006
|
}
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
const receipt = roleOutcome.decisiveFacts;
|
|
2108
|
-
assertCollectorReceiptMatchesAdmitted(receipt, admitted);
|
|
2109
|
-
const accepted = {
|
|
2110
|
-
kind: "accepted",
|
|
2111
|
-
role: "collector",
|
|
2112
|
-
status: roleOutcome.status,
|
|
2113
|
-
decisiveFacts: { ...roleOutcome.decisiveFacts },
|
|
2114
|
-
};
|
|
2007
|
+
const receipt = (lastRolePayloadRecord(roleOutcome.payloads ?? []) ?? {});
|
|
2008
|
+
const accepted = roleOutcome;
|
|
2115
2009
|
const navigator = extractNavigatorFact(entries);
|
|
2116
2010
|
const artifacts = await publishCollectorArtifacts(admitted, accepted, coordinates, { collectorReceipt: receipt });
|
|
2117
|
-
return withOptionalGateProjection({
|
|
2011
|
+
return attachRecordedSubmissions(admitted, await withOptionalGateProjection({
|
|
2118
2012
|
roleOutcome: accepted,
|
|
2119
2013
|
navigator,
|
|
2120
2014
|
artifacts,
|
|
2121
2015
|
runId: admitted.runId,
|
|
2122
|
-
}, sessionDirectory);
|
|
2016
|
+
}, sessionDirectory), scope);
|
|
2123
2017
|
}
|
|
2124
2018
|
/** Settle a lawful Collector Terminal from the admitted session. */
|
|
2125
2019
|
export async function settleCollectorTerminalResult(admitted, authority, scope) {
|
|
@@ -2133,6 +2027,39 @@ export async function settleCollectorTerminalResult(admitted, authority, scope)
|
|
|
2133
2027
|
export async function trySettleCollectorTerminalResult(admitted, authority, scope) {
|
|
2134
2028
|
return settleLawfulCollectorTerminalResult(admitted, authority, scope);
|
|
2135
2029
|
}
|
|
2030
|
+
/**
|
|
2031
|
+
* #836: runtime cost is a machine fact recorded beside the role's original
|
|
2032
|
+
* testimony (`ak_doctor_audit_candidate` custom entry), never merged into the
|
|
2033
|
+
* accepted payload itself. Absence (no candidate entry, or entry without a
|
|
2034
|
+
* cost sibling) reads as undefined — never invented.
|
|
2035
|
+
*/
|
|
2036
|
+
function extractDoctorCandidateCostFact(entries) {
|
|
2037
|
+
const scanStart = currentAttemptStartIndex(entries);
|
|
2038
|
+
for (let i = entries.length - 1; i >= scanStart; i -= 1) {
|
|
2039
|
+
const entry = entries[i];
|
|
2040
|
+
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
2041
|
+
const data = entry.data;
|
|
2042
|
+
return isRecord(data) ? data.cost : undefined;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
return undefined;
|
|
2046
|
+
}
|
|
2047
|
+
/**
|
|
2048
|
+
* #836: the auditor's own no-receipt lifecycle facts are a machine fact about
|
|
2049
|
+
* the audit leg, recorded beside (never merged into) the role's accepted
|
|
2050
|
+
* testimony. Absence reads as undefined — never invented.
|
|
2051
|
+
*/
|
|
2052
|
+
function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
2053
|
+
const scanStart = currentAttemptStartIndex(entries);
|
|
2054
|
+
for (let i = entries.length - 1; i >= scanStart; i -= 1) {
|
|
2055
|
+
const entry = entries[i];
|
|
2056
|
+
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
2057
|
+
const data = entry.data;
|
|
2058
|
+
return isRecord(data) ? data.auditNoReceipt : undefined;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
return undefined;
|
|
2062
|
+
}
|
|
2136
2063
|
export async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
|
|
2137
2064
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
2138
2065
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
@@ -2145,6 +2072,9 @@ export async function publishDoctorArtifacts(admitted, roleOutcome, coordinates,
|
|
|
2145
2072
|
...(options.doctorOutput === undefined
|
|
2146
2073
|
? {}
|
|
2147
2074
|
: { receipt: options.doctorOutput }),
|
|
2075
|
+
// Independent machine fields beside the receipt — not merged into it.
|
|
2076
|
+
...(options.cost === undefined ? {} : { cost: options.cost }),
|
|
2077
|
+
...(options.auditNoReceipt === undefined ? {} : { auditNoReceipt: options.auditNoReceipt }),
|
|
2148
2078
|
}, null, 2)}\n`, "utf8");
|
|
2149
2079
|
await writeFile(evidencePath, `${JSON.stringify({
|
|
2150
2080
|
runId: admitted.runId,
|
|
@@ -2168,43 +2098,31 @@ export async function publishDoctorArtifacts(admitted, roleOutcome, coordinates,
|
|
|
2168
2098
|
];
|
|
2169
2099
|
}
|
|
2170
2100
|
async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
|
|
2171
|
-
const sealed = await sealedLedgerOutcome(admitted, scope);
|
|
2101
|
+
const sealed = await sealedLedgerOutcome(admitted, "doctor", scope);
|
|
2172
2102
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
2173
2103
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
2174
2104
|
const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
|
|
2175
|
-
if (sealed
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
const artifacts = await publishDoctorArtifacts(admitted, escalation, coordinates);
|
|
2105
|
+
if (sealed === undefined)
|
|
2106
|
+
return undefined;
|
|
2107
|
+
if (sealed.kind === "audit_escalation") {
|
|
2108
|
+
const artifacts = await publishDoctorArtifacts(admitted, sealed, coordinates);
|
|
2180
2109
|
return withOptionalGateProjection({
|
|
2181
|
-
roleOutcome:
|
|
2110
|
+
roleOutcome: sealed,
|
|
2182
2111
|
navigator: extractNavigatorFact(entries),
|
|
2183
2112
|
artifacts,
|
|
2184
2113
|
runId: admitted.runId,
|
|
2185
2114
|
}, sessionDirectory);
|
|
2186
2115
|
}
|
|
2187
|
-
|
|
2188
|
-
const
|
|
2189
|
-
const roleOutcome = {
|
|
2190
|
-
kind: "accepted",
|
|
2191
|
-
role: "doctor",
|
|
2192
|
-
status: sealed.status,
|
|
2193
|
-
decisiveFacts: { ...sealed.decisiveFacts },
|
|
2194
|
-
};
|
|
2195
|
-
// Bind completed receipt case identity to the admitted Issue evidence case (external fact).
|
|
2196
|
-
if (String(output.status) === "completed") {
|
|
2197
|
-
const completedCase = output.case;
|
|
2198
|
-
if (completedCase.issueNumber !== admitted.caseIdentity.issueNumber ||
|
|
2199
|
-
completedCase.runsPath !== admitted.caseIdentity.runsPath) {
|
|
2200
|
-
const error = new Error("Doctor receipt case identity does not match admitted case identity");
|
|
2201
|
-
error.name = "DoctorReceiptBindingError";
|
|
2202
|
-
error.knownCause = "output";
|
|
2203
|
-
throw error;
|
|
2204
|
-
}
|
|
2205
|
-
}
|
|
2116
|
+
const output = (lastRolePayloadRecord(sealed.payloads ?? []) ?? {});
|
|
2117
|
+
const roleOutcome = sealed;
|
|
2206
2118
|
const navigator = extractNavigatorFact(entries);
|
|
2207
|
-
const
|
|
2119
|
+
const cost = extractDoctorCandidateCostFact(entries);
|
|
2120
|
+
const auditNoReceipt = extractDoctorCandidateAuditNoReceiptFact(entries);
|
|
2121
|
+
const artifacts = await publishDoctorArtifacts(admitted, roleOutcome, coordinates, {
|
|
2122
|
+
doctorOutput: output,
|
|
2123
|
+
...(cost === undefined ? {} : { cost }),
|
|
2124
|
+
...(auditNoReceipt === undefined ? {} : { auditNoReceipt }),
|
|
2125
|
+
});
|
|
2208
2126
|
return withOptionalGateProjection({
|
|
2209
2127
|
roleOutcome,
|
|
2210
2128
|
navigator,
|
|
@@ -2238,51 +2156,46 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
2238
2156
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
2239
2157
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
2240
2158
|
const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
|
|
2159
|
+
const submissions = await recordedSubmissionPayloads(admitted, scope);
|
|
2160
|
+
// Host isError residual wins over any recorded projection (#836 A.3 coexistence).
|
|
2161
|
+
const scanStart = currentAttemptStartIndex(entries);
|
|
2162
|
+
for (let index = entries.length - 1; index >= scanStart; index -= 1) {
|
|
2163
|
+
const message = entries[index]?.message;
|
|
2164
|
+
if (message?.role !== "toolResult")
|
|
2165
|
+
continue;
|
|
2166
|
+
const residual = boundErroredToolCandidate(entries, index, message, spec.toolName);
|
|
2167
|
+
if (residual !== undefined) {
|
|
2168
|
+
const details = isRecord(residual.candidate)
|
|
2169
|
+
? residual.candidate
|
|
2170
|
+
: { candidate: residual.candidate };
|
|
2171
|
+
const failed = await settleFailureTerminalResult(admitted, {
|
|
2172
|
+
cause: "output",
|
|
2173
|
+
diagnostic: residual.diagnostic,
|
|
2174
|
+
details,
|
|
2175
|
+
}, authority);
|
|
2176
|
+
return withSubmissions(failed, submissions);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2241
2179
|
const roleOutcome = await closedLedgerOutcome(admitted, spec.role, scope);
|
|
2242
2180
|
if (roleOutcome?.kind === "audit_escalation") {
|
|
2243
2181
|
const navigator = extractNavigatorFact(entries);
|
|
2244
|
-
return withOptionalGateProjection({
|
|
2182
|
+
return withSubmissions(await withOptionalGateProjection({
|
|
2245
2183
|
roleOutcome,
|
|
2246
2184
|
navigator,
|
|
2247
2185
|
artifacts: [],
|
|
2248
2186
|
runId: admitted.runId,
|
|
2249
|
-
}, sessionDirectory);
|
|
2187
|
+
}, sessionDirectory), submissions);
|
|
2250
2188
|
}
|
|
2251
|
-
if (roleOutcome?.role
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
const message = entries[index]?.message;
|
|
2260
|
-
if (message?.role !== "toolResult")
|
|
2261
|
-
continue;
|
|
2262
|
-
const residual = boundErroredToolCandidate(entries, index, message, spec.toolName);
|
|
2263
|
-
if (residual !== undefined) {
|
|
2264
|
-
// isError residual: retain candidate bytes as details (no shape stamp).
|
|
2265
|
-
const details = isRecord(residual.candidate)
|
|
2266
|
-
? residual.candidate
|
|
2267
|
-
: { candidate: residual.candidate };
|
|
2268
|
-
return settleFailureTerminalResult(admitted, {
|
|
2269
|
-
cause: "output",
|
|
2270
|
-
diagnostic: residual.diagnostic,
|
|
2271
|
-
details,
|
|
2272
|
-
}, authority);
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
return undefined;
|
|
2189
|
+
if (roleOutcome?.role === spec.role) {
|
|
2190
|
+
const navigator = extractNavigatorFact(entries);
|
|
2191
|
+
return withSubmissions(await withOptionalGateProjection({
|
|
2192
|
+
roleOutcome,
|
|
2193
|
+
navigator,
|
|
2194
|
+
artifacts: [],
|
|
2195
|
+
runId: admitted.runId,
|
|
2196
|
+
}, sessionDirectory), submissions);
|
|
2276
2197
|
}
|
|
2277
|
-
|
|
2278
|
-
const acceptedOutcome = roleOutcome;
|
|
2279
|
-
const navigator = extractNavigatorFact(entries);
|
|
2280
|
-
return withOptionalGateProjection({
|
|
2281
|
-
roleOutcome: acceptedOutcome,
|
|
2282
|
-
navigator,
|
|
2283
|
-
artifacts: [],
|
|
2284
|
-
runId: admitted.runId,
|
|
2285
|
-
}, sessionDirectory);
|
|
2198
|
+
return undefined;
|
|
2286
2199
|
}
|
|
2287
2200
|
async function settleLawfulNotaryTerminalResult(admitted, authority, scope) {
|
|
2288
2201
|
// #757: default sealed pass-through — no projectAccepted identity wrapper.
|
|
@@ -2448,10 +2361,6 @@ export async function publishReviewerArtifacts(admitted, roleOutcome, coordinate
|
|
|
2448
2361
|
...(admitted.instructionEmpty
|
|
2449
2362
|
? {}
|
|
2450
2363
|
: { callerProvenance: admitted.instruction }),
|
|
2451
|
-
// Self-fetch Spec bytes + source annotation when primary path produced material (#343).
|
|
2452
|
-
...(options.reviewerReceipt?.specFetchedMaterial === undefined
|
|
2453
|
-
? {}
|
|
2454
|
-
: { specFetchedMaterial: options.reviewerReceipt.specFetchedMaterial }),
|
|
2455
2364
|
attachments: admitted.attachments.map((a) => ({
|
|
2456
2365
|
provenancePath: a.provenancePath,
|
|
2457
2366
|
frozenPath: a.frozenPath,
|
|
@@ -2469,20 +2378,14 @@ export async function publishReviewerArtifacts(admitted, roleOutcome, coordinate
|
|
|
2469
2378
|
];
|
|
2470
2379
|
}
|
|
2471
2380
|
async function settleLawfulReviewerTerminalResult(admitted, authority, options, scope) {
|
|
2472
|
-
const sealed = await sealedLedgerOutcome(admitted, scope);
|
|
2473
|
-
if (sealed?.role !== "reviewer")
|
|
2381
|
+
const sealed = await sealedLedgerOutcome(admitted, "reviewer", scope);
|
|
2382
|
+
if (sealed?.role !== "reviewer" || sealed.kind !== "accepted")
|
|
2474
2383
|
return undefined;
|
|
2475
2384
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
2476
2385
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
2477
2386
|
const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
|
|
2478
|
-
|
|
2479
|
-
const
|
|
2480
|
-
const roleOutcome = {
|
|
2481
|
-
kind: "accepted",
|
|
2482
|
-
role: "reviewer",
|
|
2483
|
-
status: sealed.status,
|
|
2484
|
-
decisiveFacts: { ...sealed.decisiveFacts },
|
|
2485
|
-
};
|
|
2387
|
+
const receipt = lastRolePayloadRecord(sealed.payloads ?? []);
|
|
2388
|
+
const roleOutcome = sealed;
|
|
2486
2389
|
const navigator = extractNavigatorFact(entries);
|
|
2487
2390
|
const methodInvocations = extractReviewerMethodInvocations(entries, {
|
|
2488
2391
|
allowedLocations: [
|
|
@@ -2491,7 +2394,7 @@ async function settleLawfulReviewerTerminalResult(admitted, authority, options,
|
|
|
2491
2394
|
],
|
|
2492
2395
|
});
|
|
2493
2396
|
const artifacts = await publishReviewerArtifacts(admitted, roleOutcome, coordinates, {
|
|
2494
|
-
reviewerReceipt: receipt,
|
|
2397
|
+
...(receipt === undefined ? {} : { reviewerReceipt: receipt }),
|
|
2495
2398
|
methodProvenance: options.methodProvenance,
|
|
2496
2399
|
methodInvocations,
|
|
2497
2400
|
});
|
|
@@ -2583,15 +2486,9 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options, sc
|
|
|
2583
2486
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
2584
2487
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
2585
2488
|
const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
|
|
2586
|
-
const roleOutcome = await sealedLedgerOutcome(admitted, scope);
|
|
2587
|
-
if (roleOutcome?.role !== "merger") {
|
|
2588
|
-
//
|
|
2589
|
-
const latestOutcome = await readLatestSubmissionOutcome(admitted.projectRoot, admitted.runId, ledgerReadScope(admitted, scope));
|
|
2590
|
-
if (latestOutcome?.outcome === "correctable-rejection" && latestOutcome.code === "non-sole-round") {
|
|
2591
|
-
return undefined;
|
|
2592
|
-
}
|
|
2593
|
-
// Residual incomplete: shape/identity fail after the sole-round barrier passed (ledger typed).
|
|
2594
|
-
// Settlement does not re-judge calls.length.
|
|
2489
|
+
const roleOutcome = await sealedLedgerOutcome(admitted, "merger", scope);
|
|
2490
|
+
if (roleOutcome?.role !== "merger" || roleOutcome.kind !== "accepted") {
|
|
2491
|
+
// #836: non-sole-round barrier deleted; residual path is host/session only.
|
|
2595
2492
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
2596
2493
|
const message = entries[index]?.message;
|
|
2597
2494
|
if (message?.role !== "toolResult")
|
|
@@ -2599,55 +2496,33 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options, sc
|
|
|
2599
2496
|
const residual = boundErroredToolCandidate(entries, index, message, MERGER_OUTPUT_TOOL_NAME);
|
|
2600
2497
|
if (residual === undefined)
|
|
2601
2498
|
continue;
|
|
2602
|
-
const
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
return
|
|
2610
|
-
roleOutcome: buildResidualIncompleteTerminalOutcome({
|
|
2611
|
-
role: "merger",
|
|
2612
|
-
candidate: residual.candidate,
|
|
2613
|
-
diagnostic: residual.diagnostic,
|
|
2614
|
-
}),
|
|
2615
|
-
navigator: { disposition: "no-advice" },
|
|
2616
|
-
artifacts: [],
|
|
2617
|
-
runId: admitted.runId,
|
|
2618
|
-
};
|
|
2499
|
+
const candidate = residual.candidate;
|
|
2500
|
+
const details = isRecord(candidate) ? candidate : { candidate };
|
|
2501
|
+
const failed = await settleFailureTerminalResult(admitted, {
|
|
2502
|
+
cause: "output",
|
|
2503
|
+
diagnostic: residual.diagnostic,
|
|
2504
|
+
details,
|
|
2505
|
+
}, authority);
|
|
2506
|
+
return attachRecordedSubmissions(admitted, failed, scope);
|
|
2619
2507
|
}
|
|
2620
2508
|
return undefined;
|
|
2621
2509
|
}
|
|
2622
|
-
|
|
2623
|
-
const
|
|
2624
|
-
const accepted = {
|
|
2625
|
-
kind: "accepted",
|
|
2626
|
-
role: "merger",
|
|
2627
|
-
status: roleOutcome.status,
|
|
2628
|
-
decisiveFacts: { ...roleOutcome.decisiveFacts },
|
|
2629
|
-
};
|
|
2510
|
+
const accepted = roleOutcome;
|
|
2511
|
+
const navigator = extractNavigatorFact(entries);
|
|
2630
2512
|
const methodInvocations = extractMergerMethodInvocations(entries, {
|
|
2631
|
-
allowedLocations: [
|
|
2632
|
-
options.methodSkillPath,
|
|
2633
|
-
options.methodSkillConfiguredPath,
|
|
2634
|
-
],
|
|
2513
|
+
allowedLocations: [options.methodSkillPath, options.methodSkillConfiguredPath],
|
|
2635
2514
|
});
|
|
2636
|
-
// Every invocation must expand the merge-only method before conflict work.
|
|
2637
|
-
if (methodInvocations.length === 0)
|
|
2638
|
-
return undefined;
|
|
2639
|
-
const navigator = extractNavigatorFact(entries);
|
|
2640
2515
|
const artifacts = await publishMergerArtifacts(admitted, accepted, coordinates, {
|
|
2641
|
-
mergerOutput:
|
|
2516
|
+
mergerOutput: (lastRolePayloadRecord(accepted.payloads ?? []) ?? {}),
|
|
2642
2517
|
methodProvenance: options.methodProvenance,
|
|
2643
2518
|
methodInvocations,
|
|
2644
2519
|
});
|
|
2645
|
-
return withOptionalGateProjection({
|
|
2520
|
+
return attachRecordedSubmissions(admitted, await withOptionalGateProjection({
|
|
2646
2521
|
roleOutcome: accepted,
|
|
2647
2522
|
navigator,
|
|
2648
2523
|
artifacts,
|
|
2649
2524
|
runId: admitted.runId,
|
|
2650
|
-
}, sessionDirectory);
|
|
2525
|
+
}, sessionDirectory), scope);
|
|
2651
2526
|
}
|
|
2652
2527
|
/** Settle a lawful Merger Terminal from the admitted session (shared #106 success interface). */
|
|
2653
2528
|
export async function settleMergerTerminalResult(admitted, authority, options, scope) {
|
|
@@ -2818,59 +2693,6 @@ export async function publishFailureArtifacts(admitted, failure, authority) {
|
|
|
2818
2693
|
{ kind: "evidence", path: evidenceWrite.path },
|
|
2819
2694
|
];
|
|
2820
2695
|
}
|
|
2821
|
-
/**
|
|
2822
|
-
* Durably record a controlled failure (Error Artifact first), then return the
|
|
2823
|
-
* Terminal aggregate. Presentation must happen only after this resolves.
|
|
2824
|
-
*/
|
|
2825
|
-
/** Redact exact run ID from any string leaves inside decisive facts (arrays/objects included). */
|
|
2826
|
-
function redactDecisiveFactValue(value, runId) {
|
|
2827
|
-
if (typeof value === "string")
|
|
2828
|
-
return redactExactRunId(value, runId);
|
|
2829
|
-
if (Array.isArray(value)) {
|
|
2830
|
-
return value.map((entry) => redactDecisiveFactValue(entry, runId));
|
|
2831
|
-
}
|
|
2832
|
-
if (typeof value === "object" && value !== null) {
|
|
2833
|
-
const out = {};
|
|
2834
|
-
for (const [key, child] of Object.entries(value)) {
|
|
2835
|
-
out[key] = redactDecisiveFactValue(child, runId);
|
|
2836
|
-
}
|
|
2837
|
-
return out;
|
|
2838
|
-
}
|
|
2839
|
-
return value;
|
|
2840
|
-
}
|
|
2841
|
-
/** Redact exact run ID from decisive facts at the public Terminal boundary. */
|
|
2842
|
-
function redactDecisiveFactsForPublicTerminal(facts, runId) {
|
|
2843
|
-
const out = {};
|
|
2844
|
-
for (const [key, value] of Object.entries(facts)) {
|
|
2845
|
-
out[key] = redactDecisiveFactValue(value, runId);
|
|
2846
|
-
}
|
|
2847
|
-
return out;
|
|
2848
|
-
}
|
|
2849
|
-
/** Redact exact run ID from navigator free-text fields (reason only; commands are registry-owned). */
|
|
2850
|
-
function redactNavigatorFactForPublicTerminal(navigator, runId) {
|
|
2851
|
-
const advisoryDiagnostic = navigator.advisoryDiagnostic === undefined
|
|
2852
|
-
? {}
|
|
2853
|
-
: { advisoryDiagnostic: redactExactRunId(navigator.advisoryDiagnostic, runId) };
|
|
2854
|
-
if (navigator.disposition === "recommendation") {
|
|
2855
|
-
return {
|
|
2856
|
-
...navigator,
|
|
2857
|
-
...advisoryDiagnostic,
|
|
2858
|
-
reason: redactExactRunId(navigator.reason, runId),
|
|
2859
|
-
};
|
|
2860
|
-
}
|
|
2861
|
-
if (navigator.disposition === "unavailable") {
|
|
2862
|
-
return {
|
|
2863
|
-
...navigator,
|
|
2864
|
-
...advisoryDiagnostic,
|
|
2865
|
-
reason: redactExactRunId(navigator.reason, runId),
|
|
2866
|
-
};
|
|
2867
|
-
}
|
|
2868
|
-
return { ...navigator, ...advisoryDiagnostic };
|
|
2869
|
-
}
|
|
2870
|
-
/**
|
|
2871
|
-
* Durably record a controlled failure (Error Artifact first), then return the
|
|
2872
|
-
* Terminal aggregate. Presentation must happen only after this resolves.
|
|
2873
|
-
*/
|
|
2874
2696
|
/**
|
|
2875
2697
|
* Shared controlled-failure Terminal settlement (#107 ownership).
|
|
2876
2698
|
* Role identity comes from the admitted run; no new failure classes are introduced here.
|
|
@@ -2945,19 +2767,16 @@ export async function settleFailureTerminalResult(admitted, failure, authority,
|
|
|
2945
2767
|
// path components, or untrusted free text — only resume.command may carry it
|
|
2946
2768
|
// (AC2 / #108).
|
|
2947
2769
|
if (options.resume !== undefined) {
|
|
2948
|
-
const publicDiagnostic = redactExactRunId(failure.diagnostic, admitted.runId);
|
|
2949
|
-
const publicFacts = redactDecisiveFactsForPublicTerminal({ ...decisiveFacts, diagnostic: publicDiagnostic }, admitted.runId);
|
|
2950
2770
|
const roleOutcome = {
|
|
2951
2771
|
kind: "failure",
|
|
2952
2772
|
role: admitted.role,
|
|
2953
2773
|
cause: failure.cause,
|
|
2954
|
-
diagnostic:
|
|
2955
|
-
decisiveFacts
|
|
2774
|
+
diagnostic: failure.diagnostic,
|
|
2775
|
+
decisiveFacts,
|
|
2956
2776
|
};
|
|
2957
|
-
// #478: resume desensitization stays; gate is additive typed fact only.
|
|
2958
2777
|
return withOptionalGateProjection({
|
|
2959
2778
|
roleOutcome,
|
|
2960
|
-
navigator
|
|
2779
|
+
navigator,
|
|
2961
2780
|
artifacts: [],
|
|
2962
2781
|
resume: options.resume,
|
|
2963
2782
|
}, sessionDirectory);
|