@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,11 +2,8 @@ import type {
|
|
|
2
2
|
GitHubMachineIdentity,
|
|
3
3
|
} from "./collector-github.ts";
|
|
4
4
|
import type { CollectorEvidenceRecord, HeadRelation } from "./collector-evidence.ts";
|
|
5
|
-
import type { CollectorSubmissionProjection } from "./package-contracts/collector-output.ts";
|
|
6
5
|
import { CorrectableSubmissionError } from "./submission-correctable-error.ts";
|
|
7
6
|
|
|
8
|
-
export type { CollectorSubmissionProjection };
|
|
9
|
-
|
|
10
7
|
export type CollectorMaterialRef = {
|
|
11
8
|
kind: "review" | "issue_comment" | "review_comment" | "reaction";
|
|
12
9
|
id: number;
|
|
@@ -128,18 +125,6 @@ export class CollectorUnknownEvidenceError extends CorrectableSubmissionError {
|
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
|
|
131
|
-
/**
|
|
132
|
-
* Evidence-binding failure for a finding pointer that resolves to the wrong kind
|
|
133
|
-
* of stored record, lacks a GitHub locator, or has no identity group — not a
|
|
134
|
-
* free-shape gate on the submission envelope.
|
|
135
|
-
*/
|
|
136
|
-
export class CollectorFindingsValidationError extends CorrectableSubmissionError {
|
|
137
|
-
constructor(message: string) {
|
|
138
|
-
super(message);
|
|
139
|
-
this.name = "CollectorFindingsValidationError";
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
128
|
/**
|
|
144
129
|
* #676 D6: non-OPEN targets keep collected materials and must not fire new review
|
|
145
130
|
* requests. Bounce the request as correctable so the seat can still seal output.
|
|
@@ -164,167 +149,3 @@ export class CollectorWaitWindowClosedError extends CorrectableSubmissionError {
|
|
|
164
149
|
this.name = "CollectorWaitWindowClosedError";
|
|
165
150
|
}
|
|
166
151
|
}
|
|
167
|
-
|
|
168
|
-
function candidateRecord(candidate: unknown): Record<string, unknown> | undefined {
|
|
169
|
-
if (candidate === undefined || candidate === null || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
return candidate as Record<string, unknown>;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Canonical top-level keys the collector output projection understands. */
|
|
176
|
-
const COLLECTOR_OUTPUT_CANONICAL_KEYS = new Set([
|
|
177
|
-
"findings",
|
|
178
|
-
"unfinishedReasons",
|
|
179
|
-
"infrastructureFailure",
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
|
-
/** Non-canonical own keys mean content was present but not under a projectable key. */
|
|
183
|
-
function hasNonCanonicalOwnKeys(record: Record<string, unknown>): boolean {
|
|
184
|
-
for (const key of Object.keys(record)) {
|
|
185
|
-
if (!COLLECTOR_OUTPUT_CANONICAL_KEYS.has(key)) return true;
|
|
186
|
-
}
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* #641 chain① / #676: turn model-submitted finding pointer refs into receipt findings.
|
|
192
|
-
* Binds resolvable evidence references only — no pure shape rejection of the
|
|
193
|
-
* candidate envelope. Unknown refs, wrong kinds, missing GitHub locator, and
|
|
194
|
-
* missing identity group stay as binding failures. Unreadable findings content
|
|
195
|
-
* is not washed into "zero findings": projection facts record the gap so
|
|
196
|
-
* downstream can open the session 正本 (第 0 条 / #676 C).
|
|
197
|
-
*/
|
|
198
|
-
export function enrichCollectorFindings(input: {
|
|
199
|
-
candidate: unknown;
|
|
200
|
-
records: readonly CollectorEvidenceRecord[];
|
|
201
|
-
groups: readonly ExtractedCollectorIdentityGroup[];
|
|
202
|
-
targetHead: string;
|
|
203
|
-
repository: string;
|
|
204
|
-
prNumber: number;
|
|
205
|
-
}): {
|
|
206
|
-
findingsSource: CollectorSubmissionProjection["findingsSource"];
|
|
207
|
-
findingsProjectedCount: number;
|
|
208
|
-
findingsUnprojected: boolean;
|
|
209
|
-
} {
|
|
210
|
-
// Candidate present but not a record — content existed, none projected (#676 C).
|
|
211
|
-
if (input.candidate !== undefined && input.candidate !== null && candidateRecord(input.candidate) === undefined) {
|
|
212
|
-
return { findingsSource: "unreadable", findingsProjectedCount: 0, findingsUnprojected: true };
|
|
213
|
-
}
|
|
214
|
-
const record = candidateRecord(input.candidate);
|
|
215
|
-
if (record === undefined) {
|
|
216
|
-
return { findingsSource: "absent", findingsProjectedCount: 0, findingsUnprojected: false };
|
|
217
|
-
}
|
|
218
|
-
if (!Object.hasOwn(record, "findings")) {
|
|
219
|
-
// Non-canonical top-level content is not "absent" — record the projection gap (#676 C).
|
|
220
|
-
if (hasNonCanonicalOwnKeys(record)) {
|
|
221
|
-
return { findingsSource: "unreadable", findingsProjectedCount: 0, findingsUnprojected: true };
|
|
222
|
-
}
|
|
223
|
-
return { findingsSource: "absent", findingsProjectedCount: 0, findingsUnprojected: false };
|
|
224
|
-
}
|
|
225
|
-
const rawFindings = record["findings"];
|
|
226
|
-
if (!Array.isArray(rawFindings)) {
|
|
227
|
-
// Key present but not an array — content exists, none projected. No shape bounce.
|
|
228
|
-
return { findingsSource: "unreadable", findingsProjectedCount: 0, findingsUnprojected: true };
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const byEvidenceId = new Map(input.records.map((evidence) => [evidence.evidenceId, evidence]));
|
|
232
|
-
let projected = 0;
|
|
233
|
-
let unprojected = false;
|
|
234
|
-
for (const raw of rawFindings) {
|
|
235
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
236
|
-
unprojected = true;
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
const item = raw as Record<string, unknown>;
|
|
240
|
-
const evidenceId = item.evidenceId;
|
|
241
|
-
if (typeof evidenceId !== "string" || evidenceId.length === 0) {
|
|
242
|
-
// Present item without a bindable pointer — keep gap fact, do not fabricate.
|
|
243
|
-
unprojected = true;
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
const evidence = byEvidenceId.get(evidenceId);
|
|
247
|
-
if (evidence === undefined) {
|
|
248
|
-
throw new CollectorUnknownEvidenceError(evidenceId);
|
|
249
|
-
}
|
|
250
|
-
if (evidence.kind !== "review" && evidence.kind !== "issue_comment" && evidence.kind !== "review_comment") {
|
|
251
|
-
throw new CollectorFindingsValidationError(`通进司 finding 指针指向不可承 finding 的证据种类 ${evidence.kind}`);
|
|
252
|
-
}
|
|
253
|
-
if (evidence.githubId === undefined) {
|
|
254
|
-
throw new CollectorFindingsValidationError(`通进司 finding 指针证据 ${evidenceId} 缺少 GitHub id`);
|
|
255
|
-
}
|
|
256
|
-
const identity = evidence.machineIdentity ?? null;
|
|
257
|
-
const group = input.groups.find((candidateGroup) => identityKey(candidateGroup.identity) === identityKey(identity));
|
|
258
|
-
if (group === undefined) {
|
|
259
|
-
throw new CollectorFindingsValidationError(`通进司 finding 指针证据 ${evidenceId} 无归属身份组`);
|
|
260
|
-
}
|
|
261
|
-
// Bound finding keeps pointer; non-string category/summary are unprojected field gaps
|
|
262
|
-
// (pointer success ≠ full content projection) — #676 C / 3939511832.
|
|
263
|
-
const category = item.category;
|
|
264
|
-
const summary = item.summary;
|
|
265
|
-
if (Object.hasOwn(item, "category") && typeof category !== "string") unprojected = true;
|
|
266
|
-
if (Object.hasOwn(item, "summary") && typeof summary !== "string") unprojected = true;
|
|
267
|
-
group.findings.push({
|
|
268
|
-
identity,
|
|
269
|
-
source: {
|
|
270
|
-
kind: evidence.kind,
|
|
271
|
-
id: evidence.githubId,
|
|
272
|
-
evidenceId: evidence.evidenceId,
|
|
273
|
-
headRelation: headRelationFor(evidence, input.targetHead),
|
|
274
|
-
},
|
|
275
|
-
...(typeof category === "string" ? { category } : {}),
|
|
276
|
-
...(typeof summary === "string" ? { summary } : {}),
|
|
277
|
-
pointer: {
|
|
278
|
-
repository: input.repository,
|
|
279
|
-
prNumber: input.prNumber,
|
|
280
|
-
commentId: evidence.githubId,
|
|
281
|
-
...(evidence.htmlUrl === undefined ? {} : { htmlUrl: evidence.htmlUrl }),
|
|
282
|
-
...(evidence.authorLogin === undefined ? {} : { authorLogin: evidence.authorLogin }),
|
|
283
|
-
kind: evidence.kind,
|
|
284
|
-
authoritativeTime: evidence.authoritativeTime ?? null,
|
|
285
|
-
...(evidence.commitOid === undefined ? {} : { commitOid: evidence.commitOid }),
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
projected += 1;
|
|
289
|
-
}
|
|
290
|
-
return {
|
|
291
|
-
findingsSource: "array",
|
|
292
|
-
findingsProjectedCount: projected,
|
|
293
|
-
findingsUnprojected: unprojected,
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* #676 D6/C: optional unfinished reasons from the model submission.
|
|
299
|
-
* Project readable strings; record when original content could not fully project
|
|
300
|
-
* (do not wash unreadable unfinishedReasons into "none").
|
|
301
|
-
*/
|
|
302
|
-
export function extractCollectorUnfinishedReasons(candidate: unknown): {
|
|
303
|
-
reasons: string[] | undefined;
|
|
304
|
-
source: CollectorSubmissionProjection["unfinishedReasonsSource"];
|
|
305
|
-
unprojected: boolean;
|
|
306
|
-
} {
|
|
307
|
-
if (candidate !== undefined && candidate !== null && candidateRecord(candidate) === undefined) {
|
|
308
|
-
return { reasons: undefined, source: "unreadable", unprojected: true };
|
|
309
|
-
}
|
|
310
|
-
const record = candidateRecord(candidate);
|
|
311
|
-
if (record === undefined) {
|
|
312
|
-
return { reasons: undefined, source: "absent", unprojected: false };
|
|
313
|
-
}
|
|
314
|
-
if (!Object.hasOwn(record, "unfinishedReasons")) {
|
|
315
|
-
// unfinishedReasons absent is fine when only findings (or nothing) present.
|
|
316
|
-
// Non-canonical keys alone are recorded on the findings projection path.
|
|
317
|
-
return { reasons: undefined, source: "absent", unprojected: false };
|
|
318
|
-
}
|
|
319
|
-
const raw = record["unfinishedReasons"];
|
|
320
|
-
if (!Array.isArray(raw)) {
|
|
321
|
-
return { reasons: undefined, source: "unreadable", unprojected: true };
|
|
322
|
-
}
|
|
323
|
-
const reasons = raw.filter((item): item is string => typeof item === "string");
|
|
324
|
-
const unprojected = reasons.length !== raw.length;
|
|
325
|
-
return {
|
|
326
|
-
reasons: reasons.length > 0 ? reasons : undefined,
|
|
327
|
-
source: "array",
|
|
328
|
-
unprojected,
|
|
329
|
-
};
|
|
330
|
-
}
|
package/src/collector-ledger.ts
CHANGED
|
@@ -51,21 +51,7 @@ export const COLLECTOR_OPERATIONAL_TOOLS = [
|
|
|
51
51
|
COLLECTOR_HANDBOOK_WRITE_TOOL,
|
|
52
52
|
] as const;
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
* #641 chain①: observe context projects at most this many bytes of each
|
|
56
|
-
* material body; the full body stays reachable via the record pointer
|
|
57
|
-
* (evidenceId + htmlUrl) and is preserved in the volume, never unconditionally
|
|
58
|
-
* transcribed into model context or receipt.
|
|
59
|
-
*/
|
|
60
|
-
const COLLECTOR_OBSERVE_BODY_HEAD_BYTES = 512;
|
|
61
|
-
|
|
62
|
-
function utf8SafePrefix(text: string, maxBytes: number): string {
|
|
63
|
-
if (Buffer.byteLength(text, "utf8") <= maxBytes) return text;
|
|
64
|
-
const bytes = Buffer.from(text, "utf8");
|
|
65
|
-
let end = maxBytes;
|
|
66
|
-
while (end > 0 && (bytes[end]! & 0xc0) === 0x80) end -= 1;
|
|
67
|
-
return `${bytes.subarray(0, end).toString("utf8")}…`;
|
|
68
|
-
}
|
|
54
|
+
// #836: observe body truncation deleted (A6.4). Full body is the material.
|
|
69
55
|
|
|
70
56
|
export type ObserveEvidenceEntry = {
|
|
71
57
|
evidenceId: string;
|
|
@@ -103,21 +89,9 @@ export type ObserveModelView = {
|
|
|
103
89
|
}>;
|
|
104
90
|
};
|
|
105
91
|
|
|
106
|
-
/**
|
|
107
|
-
* #641 chain① model-context projection: identical shape to the volume view,
|
|
108
|
-
* with every material body bounded to a head preview. Full bodies remain
|
|
109
|
-
* pointer-reachable (evidenceId/htmlUrl) and stay in the ledger volume
|
|
110
|
-
* (collector-side; provider-visible observe details carry only this bounded
|
|
111
|
-
* projection), never unconditionally transcribed into model context.
|
|
112
|
-
*/
|
|
92
|
+
/** #836: observe context is the full volume view — no body truncation. */
|
|
113
93
|
function projectObserveContextView(modelView: ObserveModelView): ObserveModelView {
|
|
114
|
-
return
|
|
115
|
-
...modelView,
|
|
116
|
-
evidence: modelView.evidence.map((entry) =>
|
|
117
|
-
entry.body === undefined
|
|
118
|
-
? entry
|
|
119
|
-
: { ...entry, body: utf8SafePrefix(entry.body, COLLECTOR_OBSERVE_BODY_HEAD_BYTES) }),
|
|
120
|
-
};
|
|
94
|
+
return modelView;
|
|
121
95
|
}
|
|
122
96
|
|
|
123
97
|
export type CollectorOperationalTool = (typeof COLLECTOR_OPERATIONAL_TOOLS)[number];
|
|
@@ -707,17 +681,6 @@ export function createCollectorLedger(
|
|
|
707
681
|
|
|
708
682
|
bindTarget(prNumber) {
|
|
709
683
|
assertNotFatal();
|
|
710
|
-
if (outputCandidate || pendingOutputCallId !== undefined) {
|
|
711
|
-
throw new Error("通进司已产出输出候选,本局不再受理目标绑定");
|
|
712
|
-
}
|
|
713
|
-
if (!Number.isSafeInteger(prNumber) || prNumber < 1) {
|
|
714
|
-
throw new Error("通进司绑定目标要求正安全整数 PR 号");
|
|
715
|
-
}
|
|
716
|
-
if (config.prNumber !== undefined && config.prNumber !== prNumber) {
|
|
717
|
-
throw new Error(
|
|
718
|
-
`通进司目标已绑定 PR ${config.prNumber},不可改绑为 ${prNumber}`,
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
684
|
config.prNumber = prNumber;
|
|
722
685
|
appendJournal("ak-collector-target-bound", {
|
|
723
686
|
prNumber,
|
|
@@ -727,12 +690,6 @@ export function createCollectorLedger(
|
|
|
727
690
|
|
|
728
691
|
beginOperational(toolName, toolCallId) {
|
|
729
692
|
assertNotFatal();
|
|
730
|
-
if (
|
|
731
|
-
toolName !== COLLECTOR_OUTPUT_TOOL &&
|
|
732
|
-
(outputCandidate || pendingOutputCallId !== undefined)
|
|
733
|
-
) {
|
|
734
|
-
throw new Error("通进司已产出输出候选,本局不再受理操作");
|
|
735
|
-
}
|
|
736
693
|
if (toolName === COLLECTOR_OUTPUT_TOOL) {
|
|
737
694
|
pendingOutputCallId = toolCallId;
|
|
738
695
|
return;
|
package/src/collector-role.ts
CHANGED
|
@@ -44,10 +44,7 @@ import {
|
|
|
44
44
|
type CollectorConfigState,
|
|
45
45
|
type CollectorLedger,
|
|
46
46
|
} from "./collector-ledger.ts";
|
|
47
|
-
|
|
48
|
-
buildCollectorReceipt,
|
|
49
|
-
type CollectorReceipt,
|
|
50
|
-
} from "./collector-receipt.ts";
|
|
47
|
+
|
|
51
48
|
import {
|
|
52
49
|
collectorBindTargetArgsSchema,
|
|
53
50
|
collectorHandbookWriteArgsSchema,
|
|
@@ -64,18 +61,6 @@ import { CollectorUnknownEvidenceError } from "./collector-identity.ts";
|
|
|
64
61
|
|
|
65
62
|
export { CollectorUnknownEvidenceError } from "./collector-identity.ts";
|
|
66
63
|
|
|
67
|
-
/**
|
|
68
|
-
* #641 chain②: normal completion must never declare `infrastructureFailure`.
|
|
69
|
-
* When the runtime can machine-verify a lawful receipt assembly, a declaration
|
|
70
|
-
* is model misuse — bounce it as correctable guidance instead of host failure.
|
|
71
|
-
*/
|
|
72
|
-
export class CollectorNormalCompletionDeclarationError extends CorrectableSubmissionError {
|
|
73
|
-
constructor() {
|
|
74
|
-
super("runtime 已按机器状态核验本局为正常完工(回执可合法组装):正常完工的交件不得填 infrastructureFailure,请省略该字段后重新提交。");
|
|
75
|
-
this.name = "CollectorNormalCompletionDeclarationError";
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
64
|
/** #676 A: role-chosen target could not bind uniquely — correctable, not host failure. */
|
|
80
65
|
export class CollectorTargetBindError extends CorrectableSubmissionError {
|
|
81
66
|
constructor(message: string) {
|
|
@@ -350,15 +335,6 @@ export function createCollectorRoleRuntime(
|
|
|
350
335
|
if (event.toolName === COLLECTOR_OUTPUT_TOOL) {
|
|
351
336
|
activation.ledger.beginOperational(COLLECTOR_OUTPUT_TOOL, event.toolCallId);
|
|
352
337
|
}
|
|
353
|
-
if (
|
|
354
|
-
activation.ledger.outputCandidate &&
|
|
355
|
-
event.toolName !== COLLECTOR_OUTPUT_TOOL
|
|
356
|
-
) {
|
|
357
|
-
return {
|
|
358
|
-
block: true,
|
|
359
|
-
reason: "通进司已产出输出候选,本局不再受理操作",
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
338
|
return undefined;
|
|
363
339
|
},
|
|
364
340
|
|
|
@@ -391,32 +367,40 @@ export function createCollectorRoleRuntime(
|
|
|
391
367
|
}
|
|
392
368
|
|
|
393
369
|
let bound = prNumber;
|
|
370
|
+
let associated: readonly number[] = [];
|
|
394
371
|
if (issueNumber !== undefined) {
|
|
395
|
-
|
|
372
|
+
associated = await listPullRequestNumbersByTicket(createGhApiRunner(), {
|
|
396
373
|
owner: activation.repository.owner,
|
|
397
374
|
repo: activation.repository.repo,
|
|
398
375
|
ticketNumber: issueNumber,
|
|
399
376
|
});
|
|
400
|
-
if (associated.length ===
|
|
401
|
-
|
|
402
|
-
`${activation.repository.canonical} 的 issue #${issueNumber} 无关联 PR;请改用明确 --pr 或其他 issueNumber`,
|
|
403
|
-
);
|
|
377
|
+
if (bound === undefined && associated.length === 1) {
|
|
378
|
+
bound = associated[0]!;
|
|
404
379
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
380
|
+
}
|
|
381
|
+
if (bound === undefined) {
|
|
382
|
+
return {
|
|
383
|
+
content: [{
|
|
384
|
+
type: "text" as const,
|
|
385
|
+
text: JSON.stringify({
|
|
386
|
+
bound: false,
|
|
387
|
+
repository: activation.repository.canonical,
|
|
388
|
+
prNumber: prNumber ?? null,
|
|
389
|
+
issueNumber: issueNumber ?? null,
|
|
390
|
+
associated,
|
|
391
|
+
}),
|
|
392
|
+
}],
|
|
393
|
+
details: {
|
|
394
|
+
bound: false,
|
|
395
|
+
repository: activation.repository.canonical,
|
|
396
|
+
prNumber: prNumber ?? null,
|
|
397
|
+
issueNumber: issueNumber ?? null,
|
|
398
|
+
associated,
|
|
399
|
+
},
|
|
400
|
+
};
|
|
417
401
|
}
|
|
418
402
|
|
|
419
|
-
activation.ledger.bindTarget(bound
|
|
403
|
+
activation.ledger.bindTarget(bound);
|
|
420
404
|
activation.ledger.completeOperational(toolCallId);
|
|
421
405
|
return {
|
|
422
406
|
content: [{
|
|
@@ -424,9 +408,11 @@ export function createCollectorRoleRuntime(
|
|
|
424
408
|
text: `目标已绑定:${activation.repository.canonical}#${bound}`,
|
|
425
409
|
}],
|
|
426
410
|
details: {
|
|
411
|
+
bound: true,
|
|
427
412
|
repository: activation.repository.canonical,
|
|
428
413
|
prNumber: bound,
|
|
429
|
-
|
|
414
|
+
issueNumber: issueNumber ?? null,
|
|
415
|
+
associated,
|
|
430
416
|
},
|
|
431
417
|
};
|
|
432
418
|
} catch (error) {
|
|
@@ -668,36 +654,21 @@ export function createCollectorRoleRuntime(
|
|
|
668
654
|
pi.registerTool({
|
|
669
655
|
name: COLLECTOR_OUTPUT_TOOL,
|
|
670
656
|
label: "通进司输出",
|
|
671
|
-
description: "
|
|
657
|
+
description: "观察完成后提交原交卷。正常完工提交空对象 {}(如需报 finding,填 findings 指针数组);仅在基础设施真实失败时才可填 infrastructureFailure,无失败时必须省略该字段。",
|
|
672
658
|
promptSnippet: "提交通进司回执",
|
|
673
|
-
bounceInfrastructureDeclaration(params) {
|
|
674
|
-
const activation = getActivation();
|
|
675
|
-
if (activation === undefined) return undefined;
|
|
676
|
-
try {
|
|
677
|
-
buildCollectorReceipt(activation.ledger, params, activation.clock);
|
|
678
|
-
} catch {
|
|
679
|
-
return undefined;
|
|
680
|
-
}
|
|
681
|
-
return new CollectorNormalCompletionDeclarationError();
|
|
682
|
-
},
|
|
683
659
|
parameters: outputSchema,
|
|
684
660
|
async execute(toolCallId: string, params: OutputParams, _signal: AbortSignal | undefined, _onUpdate: unknown, ctx: HostContext) {
|
|
685
661
|
const activation = getActivation();
|
|
686
662
|
if (activation === undefined) throw new Error("通进司未激活");
|
|
687
663
|
try {
|
|
688
664
|
activation.ledger.beginOperational(COLLECTOR_OUTPUT_TOOL, toolCallId);
|
|
689
|
-
const receipt: CollectorReceipt = buildCollectorReceipt(
|
|
690
|
-
activation.ledger,
|
|
691
|
-
params,
|
|
692
|
-
activation.clock,
|
|
693
|
-
);
|
|
694
665
|
activation.ledger.recordOutputCandidate();
|
|
695
666
|
return {
|
|
696
667
|
content: [{
|
|
697
668
|
type: "text" as const,
|
|
698
669
|
text: COLLECTOR_ACCEPTED_TEXT,
|
|
699
670
|
}],
|
|
700
|
-
details:
|
|
671
|
+
details: params,
|
|
701
672
|
terminate: true as const,
|
|
702
673
|
};
|
|
703
674
|
} catch (error) {
|
|
@@ -2,24 +2,28 @@ import { Type, type Static } from "typebox";
|
|
|
2
2
|
import { openToolObject } from "./open-tool-schema.ts";
|
|
3
3
|
import { withInfrastructureFailureDeclaration } from "./package-contracts/terminating-infrastructure.ts";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
// #836 r16 class 3: execute() reads no params for this tool
|
|
6
|
+
// (src/collector-role.ts:431-459) — a closed root only rejects the role for
|
|
7
|
+
// saying more; no reader consumes extra fields.
|
|
8
|
+
export const collectorObserveArgsSchema = Type.Object({}, { additionalProperties: true });
|
|
9
|
+
// #836 r16 class 4: the regex was a real provider shape rejection ahead of the
|
|
10
|
+
// ledger's own identity check — src/collector-ledger.ts:911-972 already trims
|
|
11
|
+
// and enforces non-empty/lookup/marker/attemptKey identity on requestId once
|
|
12
|
+
// the tool receives it, so the duplicate pattern-based rejection is deleted
|
|
13
|
+
// (r15b decision, not reopened here).
|
|
11
14
|
export const collectorRequestArgsSchema = Type.Object({
|
|
12
15
|
requestId: Type.String({
|
|
13
16
|
minLength: 1,
|
|
14
|
-
pattern: COLLECTOR_REQUEST_ID_PATTERN.source,
|
|
15
17
|
description: "请求身份(配置 id 或角色判定的稳定 id;首尾无空白)",
|
|
16
18
|
}),
|
|
17
19
|
snapshotId: Type.String({ minLength: 1, description: "最新留存观察快照" }),
|
|
20
|
+
// #836 r16 class 3: body.minLength deleted — manifest-configured requestId
|
|
21
|
+
// ignores body, and the unknown-requestId non-empty condition is a real
|
|
22
|
+
// branch in src/collector-ledger.ts:922-951, not a provider shape gate.
|
|
18
23
|
body: Type.Optional(Type.String({
|
|
19
|
-
minLength: 1,
|
|
20
24
|
description: "角色判定的请求正文;request-manifest 未收录该 requestId 时必填",
|
|
21
25
|
})),
|
|
22
|
-
}, { additionalProperties:
|
|
26
|
+
}, { additionalProperties: true });
|
|
23
27
|
/** UTF-8 byte ceiling per handbook body — keeps next activation materials inside context budget. */
|
|
24
28
|
export const COLLECTOR_HANDBOOK_MAX_BYTES = 64 * 1024;
|
|
25
29
|
export const collectorHandbookWriteArgsSchema = Type.Object({
|
|
@@ -30,28 +34,30 @@ export const collectorHandbookWriteArgsSchema = Type.Object({
|
|
|
30
34
|
body: Type.String({
|
|
31
35
|
description: `手册全文(opaque 工作记忆;整份替换;UTF-8 至多 ${COLLECTOR_HANDBOOK_MAX_BYTES} 字节)`,
|
|
32
36
|
}),
|
|
33
|
-
}, { additionalProperties:
|
|
37
|
+
}, { additionalProperties: true });
|
|
34
38
|
export const collectorReadArgsSchema = Type.Object({
|
|
35
39
|
evidenceId: Type.String({ minLength: 1, description: "observe 返回的材料证据 id(evidenceId)" }),
|
|
36
|
-
}, { additionalProperties:
|
|
40
|
+
}, { additionalProperties: true });
|
|
37
41
|
export const collectorWaitArgsSchema = Type.Object({
|
|
38
42
|
durationMs: Type.Integer({
|
|
39
43
|
minimum: 1,
|
|
40
44
|
description: "等待毫秒;实际睡眠不超过剩余等待窗(#678;无包内单次任意上限)",
|
|
41
45
|
}),
|
|
42
|
-
}, { additionalProperties:
|
|
46
|
+
}, { additionalProperties: true });
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
49
|
* #678 D4: open the wait window at a work step.
|
|
46
50
|
* Omit startedAt for existing-PR trigger-phase end (= now).
|
|
47
51
|
* Pass PR creation success time for new-PR auto-trigger rounds.
|
|
48
52
|
*/
|
|
53
|
+
// #836 r16 class 3: startedAt.minLength deleted — an empty string is already
|
|
54
|
+
// handled as omission by src/collector-role.ts:586-597, so the provider
|
|
55
|
+
// nonblank gate is not load-bearing for any branch.
|
|
49
56
|
export const collectorOpenWaitWindowArgsSchema = Type.Object({
|
|
50
57
|
startedAt: Type.Optional(Type.String({
|
|
51
|
-
minLength: 1,
|
|
52
58
|
description: "等待窗起点 ISO 时间;新建 PR 用创建成功时刻;省略=现在(触发阶段结束)",
|
|
53
59
|
})),
|
|
54
|
-
}, { additionalProperties:
|
|
60
|
+
}, { additionalProperties: true });
|
|
55
61
|
|
|
56
62
|
/**
|
|
57
63
|
* #676 A: role-decided target bind. The model judges task materials and submits
|
|
@@ -5,6 +5,7 @@ import { auditorRunDirectory } from "./auditor-dossier-tool.ts";
|
|
|
5
5
|
import type { HostContext } from "./host-contracts.ts";
|
|
6
6
|
import type { NoReceiptLifecycleFacts } from "./receipt-delivery-policy.ts";
|
|
7
7
|
import type { PublicSummonResult } from "./public-role-summons.ts";
|
|
8
|
+
import { OFFICER_CONCLUSION_REASK } from "./gatekeeper-role.ts";
|
|
8
9
|
|
|
9
10
|
export type ComplianceNoReceipt = NoReceiptLifecycleFacts & { status: "no-receipt"; usage?: Usage };
|
|
10
11
|
/**
|
|
@@ -18,14 +19,23 @@ export type ComplianceReceived = {
|
|
|
18
19
|
readonly reply: unknown;
|
|
19
20
|
readonly usage?: Usage;
|
|
20
21
|
};
|
|
22
|
+
/** Host/engine/record failure — not a role three-state, not `received` (#836 A.3). */
|
|
23
|
+
export type ComplianceTransportFailure = {
|
|
24
|
+
readonly status: "transport_failure";
|
|
25
|
+
readonly diagnostic: string;
|
|
26
|
+
readonly submissions?: readonly unknown[];
|
|
27
|
+
readonly terminal?: unknown;
|
|
28
|
+
readonly usage?: Usage;
|
|
29
|
+
};
|
|
21
30
|
export type ComplianceDecision =
|
|
22
|
-
| { status: "pass"; usage?: Usage }
|
|
23
|
-
| { status: "bounce"; violations: readonly unknown[]; usage?: Usage }
|
|
24
|
-
| { status: "escalate"; conflicts?: unknown; decisionGate?: unknown; usage?: Usage }
|
|
31
|
+
| { status: "pass"; receipt?: unknown; usage?: Usage }
|
|
32
|
+
| { status: "bounce"; violations: readonly unknown[]; receipt?: unknown; usage?: Usage }
|
|
33
|
+
| { status: "escalate"; conflicts?: unknown; decisionGate?: unknown; receipt?: unknown; usage?: Usage }
|
|
25
34
|
| ComplianceNoReceipt
|
|
26
|
-
| ComplianceReceived
|
|
35
|
+
| ComplianceReceived
|
|
36
|
+
| ComplianceTransportFailure;
|
|
27
37
|
/** Zero-projection kickoff — soul already carries dossier-fetch duty; no hand-delivered materials. */
|
|
28
|
-
export const AUDITOR_DOSSIER_PROMPT = "
|
|
38
|
+
export const AUDITOR_DOSSIER_PROMPT = "卷宗指针:" as const;
|
|
29
39
|
|
|
30
40
|
const nonblank = Type.String({ minLength: 1, pattern: "\\S" });
|
|
31
41
|
const decisionGateSchema = Type.Object({ question: nonblank, options: Type.Array(nonblank, { minItems: 1 }) }, { additionalProperties: false });
|
|
@@ -60,11 +70,12 @@ export function tryReadComplianceCandidate(arguments_: unknown, usage?: Usage):
|
|
|
60
70
|
}
|
|
61
71
|
const args = arguments_ as Record<string, unknown>;
|
|
62
72
|
const status = args.status;
|
|
63
|
-
if (status === "pass") return { status, ...(usage === undefined ? {} : { usage }) };
|
|
64
|
-
if (status === "bounce") return { status, violations: readListField(args.violations), ...(usage === undefined ? {} : { usage }) };
|
|
73
|
+
if (status === "pass") return { status, receipt: arguments_, ...(usage === undefined ? {} : { usage }) };
|
|
74
|
+
if (status === "bounce") return { status, violations: readListField(args.violations), receipt: arguments_, ...(usage === undefined ? {} : { usage }) };
|
|
65
75
|
if (status === "escalate") {
|
|
66
76
|
return {
|
|
67
77
|
status,
|
|
78
|
+
receipt: arguments_,
|
|
68
79
|
...(Object.hasOwn(args, "conflicts") ? { conflicts: args.conflicts } : {}),
|
|
69
80
|
...(Object.hasOwn(args, "decisionGate") ? { decisionGate: args.decisionGate } : {}),
|
|
70
81
|
...(usage === undefined ? {} : { usage }),
|
|
@@ -97,6 +108,8 @@ export type AuditorSummon = (
|
|
|
97
108
|
sourceRunDirectory: string,
|
|
98
109
|
/** Parent cancellation forwarded to the nested activation (#675). */
|
|
99
110
|
signal?: AbortSignal,
|
|
111
|
+
/** Plain-language re-ask when the prior reply was not a three-state conclusion. */
|
|
112
|
+
reask?: string,
|
|
100
113
|
) => Promise<PublicSummonResult>;
|
|
101
114
|
|
|
102
115
|
export type RunComplianceAuditOptions = {
|
|
@@ -141,15 +154,30 @@ async function projectAuditorTerminal(summoned: PublicSummonResult): Promise<Com
|
|
|
141
154
|
};
|
|
142
155
|
}
|
|
143
156
|
if (outcome.kind === "failure") {
|
|
144
|
-
|
|
145
|
-
|
|
157
|
+
const rows = outcome.payloads ?? summoned.terminal?.submissions ?? [];
|
|
158
|
+
return {
|
|
159
|
+
status: "transport_failure",
|
|
160
|
+
diagnostic: outcome.diagnostic,
|
|
161
|
+
...(rows.length > 0 ? { submissions: rows } : {}),
|
|
162
|
+
...(summoned.terminal === undefined ? {} : { terminal: summoned.terminal }),
|
|
163
|
+
...(usage === undefined ? {} : { usage }),
|
|
164
|
+
};
|
|
146
165
|
}
|
|
147
166
|
if (outcome.kind === "accepted") {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
167
|
+
const rows = outcome.payloads ?? summoned.terminal?.submissions ?? [];
|
|
168
|
+
if (rows.length === 0) {
|
|
169
|
+
return readComplianceCandidate({}, usage);
|
|
170
|
+
}
|
|
171
|
+
// Queue the latest conclusion; keep every original row on the receipt/reply face.
|
|
172
|
+
const decision = readComplianceCandidate(rows[rows.length - 1], usage);
|
|
173
|
+
if (rows.length === 1) return decision;
|
|
174
|
+
if (decision.status === "pass" || decision.status === "bounce" || decision.status === "escalate") {
|
|
175
|
+
return { ...decision, receipt: rows };
|
|
176
|
+
}
|
|
177
|
+
if (decision.status === "received") {
|
|
178
|
+
return { ...decision, reply: rows };
|
|
179
|
+
}
|
|
180
|
+
return decision;
|
|
153
181
|
}
|
|
154
182
|
// Unknown terminal kind: still not a shape judgment — surface as received reply.
|
|
155
183
|
return {
|
|
@@ -171,6 +199,7 @@ export async function runComplianceAudit(options: RunComplianceAuditOptions): Pr
|
|
|
171
199
|
auditSubject: AuditorSoulRole,
|
|
172
200
|
sourceRunDirectory: string,
|
|
173
201
|
auditSignal?: AbortSignal,
|
|
202
|
+
reask?: string,
|
|
174
203
|
) => {
|
|
175
204
|
// Dynamic import avoids compliance ↔ public-cli circular init (TDZ).
|
|
176
205
|
const { summonPublicRole } = await import("./public-role-summons.ts");
|
|
@@ -185,13 +214,22 @@ export async function runComplianceAudit(options: RunComplianceAuditOptions): Pr
|
|
|
185
214
|
auditSubject,
|
|
186
215
|
"--source-run",
|
|
187
216
|
sourceRunDirectory,
|
|
188
|
-
AUDITOR_DOSSIER_PROMPT
|
|
217
|
+
`${AUDITOR_DOSSIER_PROMPT}${sourceRunDirectory}`,
|
|
189
218
|
],
|
|
190
219
|
cwd: options.context.cwd ?? process.cwd(),
|
|
191
220
|
home,
|
|
192
221
|
...(auditSignal === undefined ? {} : { signal: auditSignal }),
|
|
222
|
+
...(reask === undefined ? {} : { reviewReask: reask }),
|
|
193
223
|
});
|
|
194
224
|
});
|
|
195
|
-
|
|
196
|
-
|
|
225
|
+
let reask: string | undefined;
|
|
226
|
+
for (;;) {
|
|
227
|
+
const summoned = await summon(subject, runDirectory, options.signal, reask);
|
|
228
|
+
const decision = await projectAuditorTerminal(summoned);
|
|
229
|
+
if (decision.status === "received") {
|
|
230
|
+
reask = OFFICER_CONCLUSION_REASK;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
return decision;
|
|
234
|
+
}
|
|
197
235
|
}
|