@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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { resolveActivationLedgerHome, tryHomeFromAkRolesPath, } from "./activation-ledger-topology.js";
|
|
2
2
|
import { isAuditEscalationProjection } from "./audit-escalation.js";
|
|
3
|
-
import { acceptedFacts, isTerminatingToolName, } from "./package-contracts/terminating-tools.js";
|
|
4
3
|
import { runIdFromRunDirectory } from "./run-terminal-artifacts.js";
|
|
5
4
|
import { readSitianRecords, resolveSitianRecordPathInLedger, sitianReport } from "./sitian-facade.js";
|
|
6
5
|
import { isCorrectableExecuteError } from "./submission-correctable-error.js";
|
|
@@ -9,8 +8,6 @@ import { failOnInfrastructureFailureDeclaration } from "./package-contracts/term
|
|
|
9
8
|
* Admitted run identity for the ledger subject.
|
|
10
9
|
* Prefer AK_ROLE_RUN_DIR via sole runDirectory→runId parser (public-CLI correlation);
|
|
11
10
|
* otherwise session header id. Never a shared "unbound" bucket.
|
|
12
|
-
* Session-path layout fallback omitted: bare Pi and public CLI both expose header id
|
|
13
|
-
* when a session exists; missing both is infrastructure, not a third guess.
|
|
14
11
|
*/
|
|
15
12
|
function runIdentity(context) {
|
|
16
13
|
const directory = process.env.AK_ROLE_RUN_DIR;
|
|
@@ -25,10 +22,8 @@ function runIdentity(context) {
|
|
|
25
22
|
throw new Error("提交账需要已受理的 run 身份");
|
|
26
23
|
}
|
|
27
24
|
/**
|
|
28
|
-
* Court-turn attempt identity (#637 same-ticket re-summons
|
|
29
|
-
*
|
|
30
|
-
* (summons / message / open-court continue). Bare resume and first mint omit it so
|
|
31
|
-
* the session-stable id keeps sole-final per attempt.
|
|
25
|
+
* Court-turn attempt identity (#637 same-ticket re-summons).
|
|
26
|
+
* Recording tag only — does not gate acceptance or block further submissions (#836).
|
|
32
27
|
*/
|
|
33
28
|
export const COURT_ATTEMPT_ENV = "AK_ROLE_COURT_ATTEMPT";
|
|
34
29
|
function attemptIdentity(context, runId) {
|
|
@@ -37,22 +32,6 @@ function attemptIdentity(context, runId) {
|
|
|
37
32
|
return courtAttempt;
|
|
38
33
|
return context.sessionManager.getHeader?.()?.id ?? context.sessionManager.getLeafId?.() ?? `${runId}:initial`;
|
|
39
34
|
}
|
|
40
|
-
function isAcceptedProjection(value) {
|
|
41
|
-
if (typeof value !== "object" || value === null)
|
|
42
|
-
return false;
|
|
43
|
-
const candidate = value;
|
|
44
|
-
return candidate.kind === "accepted" && typeof candidate.role === "string" && typeof candidate.status === "string" && typeof candidate.decisiveFacts === "object" && candidate.decisiveFacts !== null;
|
|
45
|
-
}
|
|
46
|
-
function isAuditEscalationTerminalProjection(value) {
|
|
47
|
-
if (typeof value !== "object" || value === null)
|
|
48
|
-
return false;
|
|
49
|
-
const candidate = value;
|
|
50
|
-
return (candidate.kind === "audit_escalation" &&
|
|
51
|
-
typeof candidate.role === "string" &&
|
|
52
|
-
candidate.status === "audit_escalation" &&
|
|
53
|
-
typeof candidate.decisiveFacts === "object" &&
|
|
54
|
-
candidate.decisiveFacts !== null);
|
|
55
|
-
}
|
|
56
35
|
function submissionRecordFile(cwd, runId, home) {
|
|
57
36
|
const ledgerHome = resolveActivationLedgerHome(home);
|
|
58
37
|
return resolveSitianRecordPathInLedger({
|
|
@@ -77,6 +56,12 @@ function resolveReadScope(homeOrScope) {
|
|
|
77
56
|
return { home: homeOrScope };
|
|
78
57
|
return homeOrScope;
|
|
79
58
|
}
|
|
59
|
+
function recordsForAttempt(owned, attemptId) {
|
|
60
|
+
// #836: courtAttempt is a recording tag for new courts, not a visibility gate.
|
|
61
|
+
void attemptId;
|
|
62
|
+
return owned;
|
|
63
|
+
}
|
|
64
|
+
/** Recording tag a row was written under — subject first, historical payload fallback. */
|
|
80
65
|
function recordAttemptId(record) {
|
|
81
66
|
if (typeof record.subject === "object" && record.subject !== null) {
|
|
82
67
|
const fromSubject = record.subject.attemptId;
|
|
@@ -90,45 +75,84 @@ function recordAttemptId(record) {
|
|
|
90
75
|
}
|
|
91
76
|
return undefined;
|
|
92
77
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
/**
|
|
79
|
+
* True when the given attemptId itself already produced a sealed or
|
|
80
|
+
* audit-escalation submission (#836 r12 class 2). This is a separate
|
|
81
|
+
* freshness signal, not a presentation filter — `recordsForAttempt` above
|
|
82
|
+
* stays a pass-through so every original payload keeps presenting honestly
|
|
83
|
+
* (#836: attemptId is a recording tag, not a visibility gate). Settlement
|
|
84
|
+
* consumes this only to stop a prior attempt's stale acceptance from
|
|
85
|
+
* outranking the current attempt's own real host-turn failure signal
|
|
86
|
+
* (#637 original intent, restored narrowly).
|
|
87
|
+
*/
|
|
88
|
+
export async function hasFreshAttemptSubmission(cwd, runId, attemptId, home) {
|
|
89
|
+
const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
|
|
90
|
+
return owned.some((record) => {
|
|
91
|
+
if (recordAttemptId(record) !== attemptId)
|
|
92
|
+
return false;
|
|
93
|
+
if (record.kind === "sealed")
|
|
94
|
+
return true;
|
|
95
|
+
if (record.kind === "outcome") {
|
|
96
|
+
const payload = record.payload;
|
|
97
|
+
return payload?.type === "outcome" && payload.outcome === "audit-escalation";
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
});
|
|
97
101
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const record = scoped[index];
|
|
108
|
-
if (record?.kind !== "sealed")
|
|
109
|
-
continue;
|
|
110
|
-
const payload = record.payload;
|
|
111
|
-
if (payload?.type === "sealed" && isAcceptedProjection(payload.projection))
|
|
112
|
-
return payload.projection;
|
|
113
|
-
}
|
|
102
|
+
function isTerminalRoleName(value) {
|
|
103
|
+
return typeof value === "string" && value.length > 0;
|
|
104
|
+
}
|
|
105
|
+
function recordedRole(payload) {
|
|
106
|
+
if (isTerminalRoleName(payload.role))
|
|
107
|
+
return payload.role;
|
|
108
|
+
// Historical rows stored role only inside the deleted projection envelope.
|
|
109
|
+
if (isTerminalRoleName(payload.projection?.role))
|
|
110
|
+
return payload.projection.role;
|
|
114
111
|
return undefined;
|
|
115
112
|
}
|
|
116
|
-
/**
|
|
117
|
-
|
|
113
|
+
/**
|
|
114
|
+
* All recorded role submissions in ledger order (#836 multi-submit).
|
|
115
|
+
* `accepted` is the original payload; never rebuilt from a status/facts envelope.
|
|
116
|
+
*/
|
|
117
|
+
export async function readRecordedSubmissionRows(cwd, runId, homeOrScope) {
|
|
118
118
|
const scope = resolveReadScope(homeOrScope);
|
|
119
119
|
const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope.home);
|
|
120
120
|
const scoped = recordsForAttempt(owned, scope.attemptId);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (record
|
|
121
|
+
const out = [];
|
|
122
|
+
for (const record of scoped) {
|
|
123
|
+
if (record.kind === "sealed") {
|
|
124
|
+
const payload = record.payload;
|
|
125
|
+
if (payload?.type !== "sealed" || payload.accepted === undefined)
|
|
126
|
+
continue;
|
|
127
|
+
const role = recordedRole(payload);
|
|
128
|
+
if (role === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
out.push({ role, kind: "accepted", accepted: payload.accepted });
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (record.kind !== "outcome")
|
|
124
134
|
continue;
|
|
125
135
|
const payload = record.payload;
|
|
126
|
-
if (payload?.type !== "outcome" || payload.outcome !== "audit-escalation")
|
|
136
|
+
if (payload?.type !== "outcome" || payload.outcome !== "audit-escalation" || payload.accepted === undefined) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const role = recordedRole(payload);
|
|
140
|
+
if (role === undefined)
|
|
127
141
|
continue;
|
|
128
|
-
|
|
129
|
-
return payload.projection;
|
|
142
|
+
out.push({ role, kind: "audit-escalation", accepted: payload.accepted });
|
|
130
143
|
}
|
|
131
|
-
return
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* All raw role payloads in ledger order (#836 multi-submit).
|
|
148
|
+
* Returns `accepted` bytes as stored — unknown, never re-wrapped.
|
|
149
|
+
*/
|
|
150
|
+
export async function readRecordedSubmissions(cwd, runId, homeOrScope) {
|
|
151
|
+
return (await readRecordedSubmissionRows(cwd, runId, homeOrScope)).map((row) => row.accepted);
|
|
152
|
+
}
|
|
153
|
+
/** True when the run has at least one recorded accepted or audit-escalation payload. */
|
|
154
|
+
export async function hasRecordedSubmission(cwd, runId, homeOrScope) {
|
|
155
|
+
return (await readRecordedSubmissionRows(cwd, runId, homeOrScope)).length > 0;
|
|
132
156
|
}
|
|
133
157
|
/** Latest non-final outcome on the run ledger (settlement residual precedence). */
|
|
134
158
|
export async function readLatestSubmissionOutcome(cwd, runId, homeOrScope) {
|
|
@@ -146,36 +170,25 @@ export async function readLatestSubmissionOutcome(cwd, runId, homeOrScope) {
|
|
|
146
170
|
}
|
|
147
171
|
return undefined;
|
|
148
172
|
}
|
|
149
|
-
function sealedAttemptIdFromRecord(record) {
|
|
150
|
-
if (record.kind !== "sealed")
|
|
151
|
-
return undefined;
|
|
152
|
-
const payload = record.payload;
|
|
153
|
-
return payload?.type === "sealed" && typeof payload.attemptId === "string" && payload.attemptId.length > 0
|
|
154
|
-
? payload.attemptId
|
|
155
|
-
: undefined;
|
|
156
|
-
}
|
|
157
173
|
async function restoreState(cwd, runId, home) {
|
|
158
174
|
const { file, owned } = await readOwnedSubmissionRecords(cwd, runId, home);
|
|
159
175
|
const last = owned.at(-1);
|
|
160
|
-
const sealedAttemptIds = new Set();
|
|
161
|
-
for (const record of owned) {
|
|
162
|
-
const attemptId = sealedAttemptIdFromRecord(record);
|
|
163
|
-
if (attemptId !== undefined)
|
|
164
|
-
sealedAttemptIds.add(attemptId);
|
|
165
|
-
}
|
|
166
176
|
return {
|
|
167
177
|
...(last === undefined ? {} : { prior: { identity: last.identity, recordFile: file, kind: last.kind, level: last.level } }),
|
|
168
|
-
sealedAttemptIds,
|
|
169
178
|
sequence: owned.reduce((maximum, record) => {
|
|
170
179
|
const payload = record.payload;
|
|
171
180
|
return payload?.type === "candidate" && typeof payload.sequence === "number" ? Math.max(maximum, payload.sequence) : maximum;
|
|
172
181
|
}, 0),
|
|
173
182
|
};
|
|
174
183
|
}
|
|
175
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* Submission ledger host — record only (#836).
|
|
186
|
+
* Each terminating submission is appended with the role's original payload.
|
|
187
|
+
* No sole-final, no seal barrier, no context.abort(), no details rewrite.
|
|
188
|
+
* Host end (turn close / exit code) is the final; ledger contents are presented as-is.
|
|
189
|
+
*/
|
|
176
190
|
export function createSubmissionLedgerHost(host, outputTools, failInfrastructure = (error) => { throw error; }, projectClosure = () => undefined, options) {
|
|
177
191
|
const states = new Map();
|
|
178
|
-
const rounds = new Map();
|
|
179
192
|
const resolveHomeFromContext = (context) => {
|
|
180
193
|
if (options?.home !== undefined)
|
|
181
194
|
return options.home;
|
|
@@ -191,9 +204,6 @@ export function createSubmissionLedgerHost(host, outputTools, failInfrastructure
|
|
|
191
204
|
return pending;
|
|
192
205
|
})();
|
|
193
206
|
const appendFor = (state, context, runId, attemptId, event) => {
|
|
194
|
-
// Home only — must match submissionRecordFile topology (cwd + runId hash under
|
|
195
|
-
// ledger home). Do not pass sessionParent: that nests under the session dir and
|
|
196
|
-
// breaks restoreState reads which resolve the hash path without sessionParent.
|
|
197
207
|
const home = resolveHomeFromContext(context);
|
|
198
208
|
const pointer = sitianReport({
|
|
199
209
|
level: "event",
|
|
@@ -208,61 +218,15 @@ export function createSubmissionLedgerHost(host, outputTools, failInfrastructure
|
|
|
208
218
|
state.prior = pointer;
|
|
209
219
|
return pointer;
|
|
210
220
|
};
|
|
211
|
-
host.on("tool_execution_start", async ({ toolCallId, toolName }, context) => {
|
|
212
|
-
try {
|
|
213
|
-
const runId = runIdentity(context);
|
|
214
|
-
const attemptId = attemptIdentity(context, runId);
|
|
215
|
-
const state = await stateFor(context, runId);
|
|
216
|
-
if (state.sealedAttemptIds.has(attemptId)) {
|
|
217
|
-
appendFor(state, context, runId, attemptId, { type: "post-seal-anomaly", attemptId, toolCallId, toolName });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
failInfrastructure(error, context);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
221
|
host.on("turn_end", async (event, context) => {
|
|
225
222
|
try {
|
|
226
223
|
const runId = runIdentity(context);
|
|
227
224
|
const attemptId = attemptIdentity(context, runId);
|
|
228
|
-
const candidates = rounds.get(attemptId);
|
|
229
|
-
if (candidates === undefined)
|
|
230
|
-
return;
|
|
231
|
-
rounds.delete(attemptId);
|
|
232
225
|
const state = await stateFor(context, runId);
|
|
233
226
|
const calls = event.calls.map(({ toolCallId: id, toolName: name }) => ({ id, name }));
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (!sole) {
|
|
237
|
-
for (const candidate of candidates)
|
|
238
|
-
appendFor(state, context, runId, attemptId, { type: "outcome", attemptId, toolCallId: candidate.toolCallId, outcome: "correctable-rejection", code: "non-sole-round" });
|
|
239
|
-
if (host.deliverSubmissionRejection === undefined) {
|
|
240
|
-
throw new Error("宿主未提供模型可见的交卷封驳接缝");
|
|
241
|
-
}
|
|
242
|
-
context.abort();
|
|
243
|
-
await host.deliverSubmissionRejection({
|
|
244
|
-
kind: "correctable-rejection",
|
|
245
|
-
code: "non-sole-round",
|
|
246
|
-
toolCallIds: candidates.map(({ toolCallId }) => toolCallId),
|
|
247
|
-
});
|
|
248
|
-
return;
|
|
227
|
+
if (calls.length > 0) {
|
|
228
|
+
appendFor(state, context, runId, attemptId, { type: "roundContext", attemptId, calls });
|
|
249
229
|
}
|
|
250
|
-
const candidate = candidates[0];
|
|
251
|
-
if (candidate.auditProjection !== undefined) {
|
|
252
|
-
appendFor(state, context, runId, attemptId, { type: "outcome", attemptId, toolCallId: candidate.toolCallId, outcome: "audit-escalation", projection: candidate.auditProjection });
|
|
253
|
-
await projectClosure(candidate.auditProjection, context);
|
|
254
|
-
context.abort();
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
const details = typeof candidate.result.details === "object" && candidate.result.details !== null ? candidate.result.details : {};
|
|
258
|
-
const status = acceptedFacts(candidate.toolName, details).status;
|
|
259
|
-
if (typeof status !== "string" || status.length === 0)
|
|
260
|
-
throw new Error("提交账封账缺少 acceptedFacts.status");
|
|
261
|
-
const projection = { kind: "accepted", role: candidate.role, status, decisiveFacts: details };
|
|
262
|
-
appendFor(state, candidate.context, runId, attemptId, { type: "sealed", attemptId, toolCallId: candidate.toolCallId, accepted: candidate.result.details, projection });
|
|
263
|
-
state.sealedAttemptIds.add(attemptId);
|
|
264
|
-
await projectClosure(projection, context);
|
|
265
|
-
context.abort();
|
|
266
230
|
}
|
|
267
231
|
catch (error) {
|
|
268
232
|
failInfrastructure(error, context);
|
|
@@ -281,16 +245,17 @@ export function createSubmissionLedgerHost(host, outputTools, failInfrastructure
|
|
|
281
245
|
const attemptId = attemptIdentity(context, runId);
|
|
282
246
|
const state = await stateFor(context, runId);
|
|
283
247
|
const append = (event) => appendFor(state, context, runId, attemptId, event);
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
248
|
+
// #541 / #575: shared infra-declaration fail lives on the ledger seam.
|
|
249
|
+
// #641 chain②: seats may bounce a misdeclared infrastructure failure
|
|
250
|
+
// as correctable (2.1/2.2/2.3 keep paths).
|
|
251
|
+
append({
|
|
252
|
+
type: "candidate",
|
|
253
|
+
attemptId,
|
|
254
|
+
toolCallId,
|
|
255
|
+
toolName: tool.name,
|
|
256
|
+
sequence: ++state.sequence,
|
|
257
|
+
params,
|
|
258
|
+
});
|
|
294
259
|
let result;
|
|
295
260
|
try {
|
|
296
261
|
failOnInfrastructureFailureDeclaration(params, {
|
|
@@ -301,8 +266,6 @@ export function createSubmissionLedgerHost(host, outputTools, failInfrastructure
|
|
|
301
266
|
result = await tool.execute(toolCallId, params, signal, update, context);
|
|
302
267
|
}
|
|
303
268
|
catch (error) {
|
|
304
|
-
// #753: gate no longer throws GatekeeperEscalationError to select parent
|
|
305
|
-
// next-step. Officer bounce|escalate returns as correctable with raw receipt.
|
|
306
269
|
if (isCorrectableExecuteError(error)) {
|
|
307
270
|
append({
|
|
308
271
|
type: "outcome",
|
|
@@ -311,6 +274,7 @@ export function createSubmissionLedgerHost(host, outputTools, failInfrastructure
|
|
|
311
274
|
outcome: "correctable-rejection",
|
|
312
275
|
code: "typed-bounce",
|
|
313
276
|
diagnostic: error instanceof Error ? error.message : String(error),
|
|
277
|
+
accepted: params,
|
|
314
278
|
});
|
|
315
279
|
throw error;
|
|
316
280
|
}
|
|
@@ -321,52 +285,45 @@ export function createSubmissionLedgerHost(host, outputTools, failInfrastructure
|
|
|
321
285
|
toolCallId,
|
|
322
286
|
outcome: "infrastructure",
|
|
323
287
|
diagnostic: error instanceof Error ? error.message : String(error),
|
|
288
|
+
accepted: params,
|
|
324
289
|
});
|
|
325
290
|
throw error;
|
|
326
291
|
}
|
|
327
292
|
}
|
|
328
|
-
// #
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
293
|
+
// #836: ledger authority is the LLM tool-call params as-is (角色原话), never result.details.
|
|
294
|
+
// Machine facts on result.details stay on the tool-result face returned to the model.
|
|
295
|
+
if (isAuditEscalationProjection(result.details) || isAuditEscalationProjection(params)) {
|
|
296
|
+
const closed = {
|
|
297
|
+
role,
|
|
298
|
+
kind: "audit_escalation",
|
|
299
|
+
accepted: params,
|
|
300
|
+
};
|
|
301
|
+
append({
|
|
302
|
+
type: "outcome",
|
|
303
|
+
attemptId,
|
|
334
304
|
toolCallId,
|
|
335
|
-
|
|
305
|
+
outcome: "audit-escalation",
|
|
336
306
|
role,
|
|
337
|
-
|
|
338
|
-
context,
|
|
339
|
-
auditProjection: {
|
|
340
|
-
kind: "audit_escalation",
|
|
341
|
-
role,
|
|
342
|
-
status: "audit_escalation",
|
|
343
|
-
decisiveFacts: result.details,
|
|
344
|
-
},
|
|
307
|
+
accepted: params,
|
|
345
308
|
});
|
|
346
|
-
|
|
347
|
-
// The role's own acceptance text must reach the model: an empty
|
|
348
|
-
// result reads as "nothing happened" on hosts without terminate
|
|
349
|
-
// semantics (grok build kept resubmitting, #750 evidence).
|
|
350
|
-
return {
|
|
351
|
-
content: result.content,
|
|
352
|
-
details: { submissionDisposition: "pending-round-closure" },
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
if (result.terminate !== true) {
|
|
356
|
-
append({ type: "outcome", attemptId, toolCallId, outcome: "correctable-rejection", code: "non-terminate" });
|
|
309
|
+
await projectClosure(closed, context);
|
|
357
310
|
return result;
|
|
358
311
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
candidates.push({ toolCallId, toolName: tool.name, role, result, context });
|
|
365
|
-
rounds.set(attemptId, candidates);
|
|
366
|
-
return {
|
|
367
|
-
content: result.content,
|
|
368
|
-
details: { submissionDisposition: "pending-round-closure" },
|
|
312
|
+
// Terminating-tool wrap records every call; terminate flag does not withhold params.
|
|
313
|
+
const closed = {
|
|
314
|
+
role,
|
|
315
|
+
kind: "accepted",
|
|
316
|
+
accepted: params,
|
|
369
317
|
};
|
|
318
|
+
append({
|
|
319
|
+
type: "sealed",
|
|
320
|
+
attemptId,
|
|
321
|
+
toolCallId,
|
|
322
|
+
role,
|
|
323
|
+
accepted: params,
|
|
324
|
+
});
|
|
325
|
+
await projectClosure(closed, context);
|
|
326
|
+
return result;
|
|
370
327
|
},
|
|
371
328
|
});
|
|
372
329
|
},
|
|
@@ -11,13 +11,6 @@ export const TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC = "diagnostic";
|
|
|
11
11
|
function isRecord(value) {
|
|
12
12
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
13
|
}
|
|
14
|
-
const SOURCE_KINDS = new Set([
|
|
15
|
-
"cc-session",
|
|
16
|
-
"issue-body-comment",
|
|
17
|
-
"adr-decision-key",
|
|
18
|
-
"ticket-decree-block",
|
|
19
|
-
]);
|
|
20
|
-
const BASIS_METHODS = new Set(["llm-semantic"]);
|
|
21
14
|
const DIAGNOSTIC_KINDS = new Set([
|
|
22
15
|
"collector-failed",
|
|
23
16
|
"issue-source-failed",
|
|
@@ -60,51 +53,11 @@ export function projectTicketProvenanceDiagnostic(value) {
|
|
|
60
53
|
export function projectTicketProvenanceEntry(value) {
|
|
61
54
|
if (!isRecord(value))
|
|
62
55
|
return undefined;
|
|
63
|
-
// Diagnostics are a separate projection — never body entries.
|
|
64
56
|
if (value.recordClass === TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC) {
|
|
65
57
|
return undefined;
|
|
66
58
|
}
|
|
67
|
-
if (
|
|
68
|
-
return undefined;
|
|
69
|
-
if (typeof value.basis.method !== "string" || !BASIS_METHODS.has(value.basis.method)) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
if (typeof value.sourceKind !== "string" || !SOURCE_KINDS.has(value.sourceKind)) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
if (!isRecord(value.sourceRef))
|
|
76
|
-
return undefined;
|
|
77
|
-
if (typeof value.transcript !== "string" || value.transcript.length === 0) {
|
|
59
|
+
if (typeof value.sourceKind !== "string" || typeof value.transcript !== "string") {
|
|
78
60
|
return undefined;
|
|
79
61
|
}
|
|
80
|
-
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
const basis = {
|
|
84
|
-
method: value.basis.method,
|
|
85
|
-
...(Array.isArray(value.basis.anchors)
|
|
86
|
-
? {
|
|
87
|
-
anchors: value.basis.anchors.filter((item) => typeof item === "string"),
|
|
88
|
-
}
|
|
89
|
-
: {}),
|
|
90
|
-
...(typeof value.basis.note === "string" ? { note: value.basis.note } : {}),
|
|
91
|
-
};
|
|
92
|
-
const sourceRef = {
|
|
93
|
-
...(typeof value.sourceRef.sessionFile === "string"
|
|
94
|
-
? { sessionFile: value.sourceRef.sessionFile }
|
|
95
|
-
: {}),
|
|
96
|
-
...(typeof value.sourceRef.entryId === "string" ||
|
|
97
|
-
typeof value.sourceRef.entryId === "number"
|
|
98
|
-
? { entryId: value.sourceRef.entryId }
|
|
99
|
-
: {}),
|
|
100
|
-
...(typeof value.sourceRef.path === "string" ? { path: value.sourceRef.path } : {}),
|
|
101
|
-
...(typeof value.sourceRef.url === "string" ? { url: value.sourceRef.url } : {}),
|
|
102
|
-
};
|
|
103
|
-
return {
|
|
104
|
-
basis,
|
|
105
|
-
sourceKind: value.sourceKind,
|
|
106
|
-
sourceRef,
|
|
107
|
-
transcript: value.transcript,
|
|
108
|
-
timestamp: value.timestamp,
|
|
109
|
-
};
|
|
62
|
+
return value;
|
|
110
63
|
}
|