@akagilnc/pi-workflow-roles 0.1.1751
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/LICENSE +202 -0
- package/README.md +104 -0
- package/README.zh-CN.md +133 -0
- package/THIRD_PARTY_NOTICES.md +60 -0
- package/dist/activation-ledger-git.js +68 -0
- package/dist/activation-ledger-session.js +120 -0
- package/dist/activation-ledger-topology.js +239 -0
- package/dist/activation-reconciliation.js +61 -0
- package/dist/audit-escalation.js +108 -0
- package/dist/auditor-dossier-tool.js +35 -0
- package/dist/canonical-json.js +78 -0
- package/dist/compliance-transport.js +77 -0
- package/dist/doctor-contracts.js +172 -0
- package/dist/dossier-resolution.js +103 -0
- package/dist/evidence-child-executor.js +661 -0
- package/dist/exact-utf8.js +12 -0
- package/dist/git-object-id.js +7 -0
- package/dist/in-process-session.js +50 -0
- package/dist/merger-contracts.js +76 -0
- package/dist/navigator-attendance.js +995 -0
- package/dist/navigator-invocation-identity.js +220 -0
- package/dist/open-tool-schema.js +39 -0
- package/dist/package-contracts/collector-output.js +50 -0
- package/dist/package-contracts/fixer-output.js +72 -0
- package/dist/package-contracts/fixer-packet.js +77 -0
- package/dist/package-contracts/judge-output.js +17 -0
- package/dist/package-contracts/reviewer-output.js +82 -0
- package/dist/package-contracts/terminating-tools.js +173 -0
- package/dist/package-contracts/worker-output.js +13 -0
- package/dist/package-owned-tool-idle.js +104 -0
- package/dist/packaged-role-registry.js +34 -0
- package/dist/public-cli/main.js +23867 -0
- package/dist/public-command-renderer.js +20 -0
- package/dist/reviewer-agent.js +93 -0
- package/dist/reviewer-child-executor.js +23 -0
- package/dist/reviewer-construction.js +95 -0
- package/dist/reviewer-dispatch.js +77 -0
- package/dist/reviewer-execution-ledger.js +160 -0
- package/dist/reviewer-failure-diagnostic.js +17 -0
- package/dist/reviewer-git-snapshot.js +38 -0
- package/dist/reviewer-pinned-git.js +146 -0
- package/dist/reviewer-preflight-error.js +15 -0
- package/dist/reviewer-prompt-identity.js +10 -0
- package/dist/reviewer-scope-prompt.js +21 -0
- package/dist/reviewer-workspace.js +151 -0
- package/dist/sha256.js +5 -0
- package/dist/sitian-record-entry.js +33 -0
- package/dist/stderr-jsonl.js +26 -0
- package/dist/stream-idle-guard.js +75 -0
- package/dist/tool-execution-observation.js +141 -0
- package/dist/uuidv7.js +21 -0
- package/dist/work-subject-identity.js +53 -0
- package/extensions/role-runtime.ts +303 -0
- package/package.json +69 -0
- package/packets/fixer-prerequisites.json +6 -0
- package/packets/fixer-repair.md +5 -0
- package/packets/judge-apply.md +77 -0
- package/packets/judge-authority.md +64 -0
- package/packets/judge-plan.md +55 -0
- package/packets/judge-review.md +49 -0
- package/packets/judge-submission.md +34 -0
- package/resources/methods/code-review/SKILL.md +92 -0
- package/resources/methods/code-review/agents/openai.yaml +3 -0
- package/resources/methods/code-review/provenance.json +26 -0
- package/resources/methods/diagnosing-bugs/SKILL.md +134 -0
- package/resources/methods/diagnosing-bugs/agents/openai.yaml +3 -0
- package/resources/methods/diagnosing-bugs/provenance.json +31 -0
- package/resources/methods/diagnosing-bugs/scripts/hitl-loop.template.sh +41 -0
- package/resources/methods/resolving-merge-conflicts/SKILL.md +14 -0
- package/resources/methods/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/resources/methods/resolving-merge-conflicts/provenance.json +26 -0
- package/resources/methods/tdd/SKILL.md +38 -0
- package/resources/methods/tdd/agents/openai.yaml +3 -0
- package/resources/methods/tdd/mocking.md +59 -0
- package/resources/methods/tdd/provenance.json +36 -0
- package/resources/methods/tdd/tests.md +77 -0
- package/resources/navigator-route-playbook.md +32 -0
- package/schemas/tool-execution-observation.schema.json +107 -0
- package/scripts/build-package.mjs +65 -0
- package/scripts/generate-tool-execution-observation-schema.ts +7 -0
- package/souls/coder.md +10 -0
- package/souls/collector.md +11 -0
- package/souls/doctor-auditor.md +23 -0
- package/souls/doctor.md +8 -0
- package/souls/fixer-auditor.md +33 -0
- package/souls/fixer.md +13 -0
- package/souls/judge-auditor.md +33 -0
- package/souls/judge.md +74 -0
- package/souls/merger.md +5 -0
- package/souls/navigator.md +5 -0
- package/souls/reviewer-auditor.md +25 -0
- package/souls/reviewer.md +11 -0
- package/src/activation-ledger-git.ts +96 -0
- package/src/activation-ledger-session.ts +188 -0
- package/src/activation-ledger-topology.ts +301 -0
- package/src/activation-ledger.ts +240 -0
- package/src/activation-reconciliation.ts +163 -0
- package/src/activation-trace.ts +38 -0
- package/src/audit-escalation.ts +177 -0
- package/src/auditor-dossier-tool.ts +48 -0
- package/src/auditor-soul.ts +28 -0
- package/src/canonical-json.ts +74 -0
- package/src/canonical-skill-binding.ts +107 -0
- package/src/collector-config.ts +89 -0
- package/src/collector-evidence.ts +461 -0
- package/src/collector-github.ts +656 -0
- package/src/collector-identity.ts +161 -0
- package/src/collector-ledger.ts +827 -0
- package/src/collector-receipt.ts +87 -0
- package/src/collector-role.ts +592 -0
- package/src/collector-tool-schemas.ts +19 -0
- package/src/compliance-transport.ts +130 -0
- package/src/doctor-auditor.ts +53 -0
- package/src/doctor-contracts.ts +166 -0
- package/src/doctor-evidence.ts +47 -0
- package/src/doctor-role.ts +18 -0
- package/src/dossier-resolution.ts +137 -0
- package/src/evidence-child-executor.ts +775 -0
- package/src/exact-utf8.ts +9 -0
- package/src/factory-board.ts +1822 -0
- package/src/git-object-id.ts +11 -0
- package/src/human-format.ts +65 -0
- package/src/in-process-session.ts +78 -0
- package/src/judge-auditor.ts +55 -0
- package/src/judge-recording-anti-forge.ts +53 -0
- package/src/judge-role.ts +160 -0
- package/src/merger-contracts.ts +71 -0
- package/src/merger-git-state.ts +76 -0
- package/src/merger-role.ts +60 -0
- package/src/navigator-attendance.ts +1254 -0
- package/src/navigator-invocation-identity.ts +446 -0
- package/src/open-tool-schema.ts +46 -0
- package/src/package-contracts/collector-output.ts +109 -0
- package/src/package-contracts/fixer-output.ts +81 -0
- package/src/package-contracts/fixer-packet.ts +93 -0
- package/src/package-contracts/judge-output.ts +39 -0
- package/src/package-contracts/reviewer-output.ts +115 -0
- package/src/package-contracts/terminating-tools.ts +259 -0
- package/src/package-contracts/worker-output.ts +36 -0
- package/src/package-owned-tool-idle.ts +134 -0
- package/src/package-resources/method-skill-binding.ts +87 -0
- package/src/package-resources/method-skill.ts +358 -0
- package/src/packaged-role-registry.ts +36 -0
- package/src/public-cli/cli-errors.ts +11 -0
- package/src/public-cli/cli-io.ts +4 -0
- package/src/public-cli/cli.ts +912 -0
- package/src/public-cli/coder-run.ts +575 -0
- package/src/public-cli/collector-run.ts +375 -0
- package/src/public-cli/command-renderer.ts +8 -0
- package/src/public-cli/config.ts +346 -0
- package/src/public-cli/doctor-run.ts +355 -0
- package/src/public-cli/explicit-internal.ts +274 -0
- package/src/public-cli/fixer-run.ts +587 -0
- package/src/public-cli/host-pi-runtime.ts +112 -0
- package/src/public-cli/invocation.ts +1958 -0
- package/src/public-cli/judge-run.ts +507 -0
- package/src/public-cli/main.ts +15 -0
- package/src/public-cli/merger-run.ts +681 -0
- package/src/public-cli/public-run-credentials.ts +71 -0
- package/src/public-cli/registry.ts +153 -0
- package/src/public-cli/reviewer-run.ts +561 -0
- package/src/public-cli/run-lifecycle.ts +884 -0
- package/src/public-cli/settlement.ts +3765 -0
- package/src/public-cli/terminal.ts +325 -0
- package/src/public-command-renderer.ts +43 -0
- package/src/reviewer-agent.ts +94 -0
- package/src/reviewer-auditor.ts +53 -0
- package/src/reviewer-child-executor.ts +31 -0
- package/src/reviewer-construction.ts +137 -0
- package/src/reviewer-dispatch.ts +94 -0
- package/src/reviewer-execution-ledger.ts +206 -0
- package/src/reviewer-failure-diagnostic.ts +18 -0
- package/src/reviewer-git-snapshot.ts +53 -0
- package/src/reviewer-pinned-git.ts +144 -0
- package/src/reviewer-preflight-error.ts +14 -0
- package/src/reviewer-prompt-identity.ts +17 -0
- package/src/reviewer-role.ts +193 -0
- package/src/reviewer-scope-prompt.ts +24 -0
- package/src/reviewer-settlement.ts +63 -0
- package/src/reviewer-workspace.ts +111 -0
- package/src/role-runtime.ts +884 -0
- package/src/sha256.ts +6 -0
- package/src/sitian-record-entry.ts +57 -0
- package/src/stderr-jsonl.ts +28 -0
- package/src/stream-idle-guard.ts +98 -0
- package/src/ticket-snapshot.ts +662 -0
- package/src/ticket-trajectory.ts +1000 -0
- package/src/tool-execution-observation.ts +168 -0
- package/src/uuidv7.ts +1 -0
- package/src/work-subject-identity.ts +94 -0
- package/src/worker-role.ts +434 -0
- package/src/worker-submission-gates.ts +225 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned terminating tool registry.
|
|
3
|
+
* Package roles share these terminating leaves.
|
|
4
|
+
*/
|
|
5
|
+
import { COLLECTOR_ACCEPTED_TEXT, COLLECTOR_OUTPUT_TOOL, validateAcceptedCollectorReceipt, } from "./collector-output.js";
|
|
6
|
+
import { JUDGE_ACCEPTED_TEXT, JUDGE_OUTPUT_TOOL_NAME, validateAcceptedJudgeDetails, } from "./judge-output.js";
|
|
7
|
+
import { REVIEWER_ACCEPTED_TEXT, REVIEWER_OUTPUT_TOOL_NAME, projectReviewerIntentToReceipt, validateReviewerIntent, validateRuntimeReviewerReceipt, } from "./reviewer-output.js";
|
|
8
|
+
import { isAuditEscalationResult } from "../audit-escalation.js";
|
|
9
|
+
import { DOCTOR_OUTPUT_TOOL_NAME, validateDoctorSubmissionShape, validateRecordedDoctorOutput } from "../doctor-contracts.js";
|
|
10
|
+
import { MERGER_ACCEPTED_TEXT, MERGER_OUTPUT_TOOL_NAME, validateMergerOutput } from "../merger-contracts.js";
|
|
11
|
+
import { CODER_ACCEPTED_TEXT, CODER_OUTPUT_TOOL_NAME, FIXER_ACCEPTED_TEXT, FIXER_OUTPUT_TOOL_NAME, validateAcceptedWorkerDetails, } from "./worker-output.js";
|
|
12
|
+
export { CODER_ACCEPTED_TEXT, CODER_OUTPUT_TOOL_NAME, COLLECTOR_ACCEPTED_TEXT, COLLECTOR_OUTPUT_TOOL, FIXER_ACCEPTED_TEXT, FIXER_OUTPUT_TOOL_NAME, JUDGE_ACCEPTED_TEXT, JUDGE_OUTPUT_TOOL_NAME, REVIEWER_ACCEPTED_TEXT, REVIEWER_OUTPUT_TOOL_NAME, MERGER_ACCEPTED_TEXT, MERGER_OUTPUT_TOOL_NAME, validateAcceptedCollectorReceipt, validateAcceptedJudgeDetails, projectReviewerIntentToReceipt, validateReviewerIntent, validateRuntimeReviewerReceipt, validateAcceptedWorkerDetails, validateDoctorSubmissionShape, validateRecordedDoctorOutput, validateMergerOutput, };
|
|
13
|
+
export const TERMINATING_TOOL_NAMES = [
|
|
14
|
+
CODER_OUTPUT_TOOL_NAME,
|
|
15
|
+
FIXER_OUTPUT_TOOL_NAME,
|
|
16
|
+
REVIEWER_OUTPUT_TOOL_NAME,
|
|
17
|
+
JUDGE_OUTPUT_TOOL_NAME,
|
|
18
|
+
COLLECTOR_OUTPUT_TOOL,
|
|
19
|
+
DOCTOR_OUTPUT_TOOL_NAME,
|
|
20
|
+
MERGER_OUTPUT_TOOL_NAME,
|
|
21
|
+
];
|
|
22
|
+
export function isTerminatingToolName(name) {
|
|
23
|
+
return TERMINATING_TOOL_NAMES.includes(name);
|
|
24
|
+
}
|
|
25
|
+
export function acceptedTextFor(toolName) {
|
|
26
|
+
switch (toolName) {
|
|
27
|
+
case CODER_OUTPUT_TOOL_NAME:
|
|
28
|
+
return CODER_ACCEPTED_TEXT;
|
|
29
|
+
case FIXER_OUTPUT_TOOL_NAME:
|
|
30
|
+
return FIXER_ACCEPTED_TEXT;
|
|
31
|
+
case REVIEWER_OUTPUT_TOOL_NAME:
|
|
32
|
+
return REVIEWER_ACCEPTED_TEXT;
|
|
33
|
+
case JUDGE_OUTPUT_TOOL_NAME:
|
|
34
|
+
return JUDGE_ACCEPTED_TEXT;
|
|
35
|
+
case COLLECTOR_OUTPUT_TOOL:
|
|
36
|
+
return COLLECTOR_ACCEPTED_TEXT;
|
|
37
|
+
case DOCTOR_OUTPUT_TOOL_NAME:
|
|
38
|
+
return "Doctor output accepted";
|
|
39
|
+
case MERGER_OUTPUT_TOOL_NAME:
|
|
40
|
+
return MERGER_ACCEPTED_TEXT;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class AcceptedDetailsContractError extends Error {
|
|
44
|
+
constructor(message, options) {
|
|
45
|
+
super(message, options);
|
|
46
|
+
this.name = "AcceptedDetailsContractError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function safeProperty(candidate, property) {
|
|
50
|
+
try {
|
|
51
|
+
return candidate?.[property];
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function validateAcceptedDetails(toolName, details) {
|
|
58
|
+
const candidate = details !== null && typeof details === "object" && !Array.isArray(details)
|
|
59
|
+
? details
|
|
60
|
+
: undefined;
|
|
61
|
+
let auditEscalation = false;
|
|
62
|
+
try {
|
|
63
|
+
auditEscalation = isAuditEscalationResult(details);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Hostile getters are not recognizable audit escalation evidence.
|
|
67
|
+
}
|
|
68
|
+
if (auditEscalation || safeProperty(candidate, "kind") === "audit_escalation") {
|
|
69
|
+
throw new AcceptedDetailsContractError("audit escalation is not an accepted role receipt");
|
|
70
|
+
}
|
|
71
|
+
const discriminator = safeProperty(candidate, toolName === JUDGE_OUTPUT_TOOL_NAME ? "judgeStatus" : "status");
|
|
72
|
+
const lawfulStatuses = {
|
|
73
|
+
[CODER_OUTPUT_TOOL_NAME]: ["planned", "completed", "refused", "unfinished"],
|
|
74
|
+
[FIXER_OUTPUT_TOOL_NAME]: ["planned", "completed", "refused", "partially_completed", "unfinished"],
|
|
75
|
+
[REVIEWER_OUTPUT_TOOL_NAME]: ["completed", "refused"],
|
|
76
|
+
[JUDGE_OUTPUT_TOOL_NAME]: ["converged", "continue", "escalate"],
|
|
77
|
+
[COLLECTOR_OUTPUT_TOOL]: [],
|
|
78
|
+
[DOCTOR_OUTPUT_TOOL_NAME]: ["completed", "refused"],
|
|
79
|
+
[MERGER_OUTPUT_TOOL_NAME]: ["completed", "escalate"],
|
|
80
|
+
};
|
|
81
|
+
const collectorDiscriminator = toolName === COLLECTOR_OUTPUT_TOOL && Array.isArray(candidate?.groups);
|
|
82
|
+
const runtimeBindingMissing = (toolName === DOCTOR_OUTPUT_TOOL_NAME && discriminator === "completed" && !(candidate?.cost !== null && typeof candidate?.cost === "object")) ||
|
|
83
|
+
(toolName === REVIEWER_OUTPUT_TOOL_NAME && candidate?.version !== 2);
|
|
84
|
+
if (runtimeBindingMissing || (!collectorDiscriminator && (typeof discriminator !== "string" || !lawfulStatuses[toolName].includes(discriminator)))) {
|
|
85
|
+
throw new AcceptedDetailsContractError("terminating receipt has no recognized execution discriminator");
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
switch (toolName) {
|
|
89
|
+
case CODER_OUTPUT_TOOL_NAME:
|
|
90
|
+
return validateAcceptedWorkerDetails(details, "Coder");
|
|
91
|
+
case FIXER_OUTPUT_TOOL_NAME:
|
|
92
|
+
return validateAcceptedWorkerDetails(details, "Fixer");
|
|
93
|
+
case REVIEWER_OUTPUT_TOOL_NAME:
|
|
94
|
+
return validateRuntimeReviewerReceipt(details);
|
|
95
|
+
case JUDGE_OUTPUT_TOOL_NAME:
|
|
96
|
+
return validateAcceptedJudgeDetails(details);
|
|
97
|
+
case COLLECTOR_OUTPUT_TOOL:
|
|
98
|
+
return validateAcceptedCollectorReceipt(details);
|
|
99
|
+
case DOCTOR_OUTPUT_TOOL_NAME:
|
|
100
|
+
return validateRecordedDoctorOutput(details);
|
|
101
|
+
case MERGER_OUTPUT_TOOL_NAME:
|
|
102
|
+
return validateMergerOutput(details);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof Error && error.constructor === Error)
|
|
107
|
+
throw new AcceptedDetailsContractError(error.message, { cause: error });
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function validateAcceptedLifecycle(toolName, argumentsValue, detailsValue) {
|
|
112
|
+
const details = validateAcceptedDetails(toolName, detailsValue);
|
|
113
|
+
if (toolName === DOCTOR_OUTPUT_TOOL_NAME) {
|
|
114
|
+
const testimony = validateDoctorSubmissionShape(argumentsValue);
|
|
115
|
+
if (testimony.status === "refused") {
|
|
116
|
+
if (!deepEqual(testimony, details))
|
|
117
|
+
throw new Error("accepted tool lifecycle details mismatch");
|
|
118
|
+
return details;
|
|
119
|
+
}
|
|
120
|
+
const receipt = details;
|
|
121
|
+
if (receipt.status !== "completed")
|
|
122
|
+
throw new Error("accepted tool lifecycle details mismatch");
|
|
123
|
+
const { cost: _runtimeCost, ...projected } = receipt;
|
|
124
|
+
if (!deepEqual(testimony, projected))
|
|
125
|
+
throw new Error("accepted tool lifecycle details mismatch");
|
|
126
|
+
return details;
|
|
127
|
+
}
|
|
128
|
+
const argumentsDetails = validateAcceptedDetails(toolName, argumentsValue);
|
|
129
|
+
if (!deepEqual(argumentsDetails, details))
|
|
130
|
+
throw new Error("accepted tool lifecycle details mismatch");
|
|
131
|
+
return details;
|
|
132
|
+
}
|
|
133
|
+
export function acceptedFacts(toolName, details) {
|
|
134
|
+
switch (toolName) {
|
|
135
|
+
case CODER_OUTPUT_TOOL_NAME:
|
|
136
|
+
case FIXER_OUTPUT_TOOL_NAME:
|
|
137
|
+
case REVIEWER_OUTPUT_TOOL_NAME:
|
|
138
|
+
case DOCTOR_OUTPUT_TOOL_NAME: return { status: details.status };
|
|
139
|
+
case JUDGE_OUTPUT_TOOL_NAME: return { status: details.judgeStatus };
|
|
140
|
+
case MERGER_OUTPUT_TOOL_NAME: {
|
|
141
|
+
const output = details;
|
|
142
|
+
return { status: output.status, ...(output.status === "completed" && typeof output.mergeCommitId === "string" ? { commit: output.mergeCommitId } : {}) };
|
|
143
|
+
}
|
|
144
|
+
case COLLECTOR_OUTPUT_TOOL:
|
|
145
|
+
return { status: "collected" };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Deep structural equality for lifecycle agreement checks. */
|
|
149
|
+
export function deepEqual(a, b) {
|
|
150
|
+
if (Object.is(a, b))
|
|
151
|
+
return true;
|
|
152
|
+
if (typeof a !== typeof b)
|
|
153
|
+
return false;
|
|
154
|
+
if (a === null || b === null)
|
|
155
|
+
return a === b;
|
|
156
|
+
if (Array.isArray(a)) {
|
|
157
|
+
if (!Array.isArray(b) || a.length !== b.length)
|
|
158
|
+
return false;
|
|
159
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
160
|
+
}
|
|
161
|
+
if (typeof a === "object") {
|
|
162
|
+
if (typeof b !== "object" || b === null || Array.isArray(b))
|
|
163
|
+
return false;
|
|
164
|
+
const aKeys = Object.keys(a).sort();
|
|
165
|
+
const bKeys = Object.keys(b).sort();
|
|
166
|
+
if (aKeys.length !== bKeys.length)
|
|
167
|
+
return false;
|
|
168
|
+
if (!aKeys.every((key, index) => key === bKeys[index]))
|
|
169
|
+
return false;
|
|
170
|
+
return aKeys.every((key) => deepEqual(a[key], b[key]));
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Package-owned independent Coder and Fixer output leaves. */
|
|
2
|
+
export { FIXER_ACCEPTED_TEXT, FIXER_OUTPUT_TOOL_NAME, fixerOutputSchema, validateFixerOutput, validateFixerOutputForPacket, } from "./fixer-output.js";
|
|
3
|
+
export { fixerPrerequisiteSchema, fixerPrerequisitesSchema, parseFixerPrerequisites, validateFixerPrerequisites } from "./fixer-packet.js";
|
|
4
|
+
import { validateFixerOutput } from "./fixer-output.js";
|
|
5
|
+
export const CODER_OUTPUT_TOOL_NAME = "ak_coder_output";
|
|
6
|
+
export const CODER_ACCEPTED_TEXT = "Coder report accepted";
|
|
7
|
+
export function validateAcceptedCoderDetails(output) {
|
|
8
|
+
return output;
|
|
9
|
+
}
|
|
10
|
+
/** Structural production validator for an accepted current leaf. */
|
|
11
|
+
export function validateAcceptedWorkerDetails(output, roleLabel = "Coder") {
|
|
12
|
+
return roleLabel === "Fixer" ? validateFixerOutput(output) : validateAcceptedCoderDetails(output);
|
|
13
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { DEFAULT_STREAM_IDLE_TIMEOUT_MS, createStreamIdleGuard, } from "./stream-idle-guard.js";
|
|
2
|
+
import { isProducingToolUpdate } from "./tool-execution-observation.js";
|
|
3
|
+
export const PACKAGE_OWNED_TOOL_IDLE_TIMEOUT_MS = DEFAULT_STREAM_IDLE_TIMEOUT_MS;
|
|
4
|
+
export const PACKAGE_OWNED_TOOL_IDLE_TIMEOUT_CODE = "AK_PACKAGE_OWNED_TOOL_IDLE_TIMEOUT";
|
|
5
|
+
const WRAPPED = Symbol.for("ak.packageOwnedToolIdleWrapped");
|
|
6
|
+
export class PackageOwnedToolIdleTimeoutError extends Error {
|
|
7
|
+
code = PACKAGE_OWNED_TOOL_IDLE_TIMEOUT_CODE;
|
|
8
|
+
idleTimeoutMs = PACKAGE_OWNED_TOOL_IDLE_TIMEOUT_MS;
|
|
9
|
+
constructor() {
|
|
10
|
+
super(`package-owned tool idle timeout after ${PACKAGE_OWNED_TOOL_IDLE_TIMEOUT_MS}ms`);
|
|
11
|
+
this.name = "PackageOwnedToolIdleTimeoutError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Package-tool activity includes content production and host-only details
|
|
16
|
+
* progress. Keep the observation-plane oracle separate: its stderr heartbeat
|
|
17
|
+
* contract remains content-driven. Pi's known execute-entry placeholder
|
|
18
|
+
* (`content: [], details: undefined`) is not activity.
|
|
19
|
+
*/
|
|
20
|
+
function isPackageOwnedToolActivityUpdate(partialResult) {
|
|
21
|
+
if (isProducingToolUpdate(partialResult))
|
|
22
|
+
return true;
|
|
23
|
+
if (typeof partialResult !== "object" || partialResult === null)
|
|
24
|
+
return false;
|
|
25
|
+
const details = partialResult.details;
|
|
26
|
+
if (details === undefined || details === null)
|
|
27
|
+
return false;
|
|
28
|
+
if (typeof details === "string")
|
|
29
|
+
return details.length > 0;
|
|
30
|
+
if (Array.isArray(details))
|
|
31
|
+
return details.length > 0;
|
|
32
|
+
if (typeof details === "object")
|
|
33
|
+
return Reflect.ownKeys(details).length > 0;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Single shared execute wrapper for package-owned tool definitions.
|
|
38
|
+
* Idempotent: wrapping twice returns the same protected definition.
|
|
39
|
+
*/
|
|
40
|
+
export function wrapPackageOwnedToolDefinition(tool) {
|
|
41
|
+
// Mark the execute function, not the tool object — callers may spread tool fields
|
|
42
|
+
// onto a new definition with a different execute (e.g. auditor customTools).
|
|
43
|
+
if (tool.execute[WRAPPED] === true)
|
|
44
|
+
return tool;
|
|
45
|
+
const originalExecute = tool.execute.bind(tool);
|
|
46
|
+
const wrappedExecute = function packageOwnedToolIdleExecute(...args) {
|
|
47
|
+
const signal = args[2];
|
|
48
|
+
const onUpdate = args[3];
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
let settled = false;
|
|
51
|
+
const idle = createStreamIdleGuard({
|
|
52
|
+
idleTimeoutMs: PACKAGE_OWNED_TOOL_IDLE_TIMEOUT_MS,
|
|
53
|
+
});
|
|
54
|
+
const settle = (deliver) => {
|
|
55
|
+
if (settled)
|
|
56
|
+
return;
|
|
57
|
+
settled = true;
|
|
58
|
+
idle.signal.removeEventListener("abort", onIdle);
|
|
59
|
+
idle.dispose();
|
|
60
|
+
deliver();
|
|
61
|
+
};
|
|
62
|
+
const onIdle = () => {
|
|
63
|
+
settle(() => reject(new PackageOwnedToolIdleTimeoutError()));
|
|
64
|
+
};
|
|
65
|
+
idle.signal.addEventListener("abort", onIdle, { once: true });
|
|
66
|
+
const guardedOnUpdate = onUpdate === undefined
|
|
67
|
+
? undefined
|
|
68
|
+
: (partialResult) => {
|
|
69
|
+
if (settled)
|
|
70
|
+
return;
|
|
71
|
+
if (isPackageOwnedToolActivityUpdate(partialResult))
|
|
72
|
+
idle.poke();
|
|
73
|
+
onUpdate(partialResult);
|
|
74
|
+
};
|
|
75
|
+
const callArgs = args.slice();
|
|
76
|
+
// Preserve the original signal at args[2]; timeout must not abort it.
|
|
77
|
+
callArgs[2] = signal;
|
|
78
|
+
callArgs[3] = guardedOnUpdate;
|
|
79
|
+
void Promise.resolve()
|
|
80
|
+
.then(() => originalExecute(...callArgs))
|
|
81
|
+
.then((result) => settle(() => resolve(result)), (error) => settle(() => reject(error)));
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
wrappedExecute[WRAPPED] = true;
|
|
85
|
+
return {
|
|
86
|
+
...tool,
|
|
87
|
+
execute: wrappedExecute,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Install the shared registration surface on an ExtensionAPI once.
|
|
92
|
+
* All subsequent pi.registerTool calls for package-owned tools are wrapped.
|
|
93
|
+
*/
|
|
94
|
+
export function installPackageOwnedToolRegistration(pi) {
|
|
95
|
+
const current = pi.registerTool;
|
|
96
|
+
if (current[WRAPPED] === true)
|
|
97
|
+
return;
|
|
98
|
+
const original = current.bind(pi);
|
|
99
|
+
const installed = ((tool) => {
|
|
100
|
+
original(wrapPackageOwnedToolDefinition(tool));
|
|
101
|
+
});
|
|
102
|
+
installed[WRAPPED] = true;
|
|
103
|
+
pi.registerTool = installed;
|
|
104
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { COLLECTOR_OUTPUT_TOOL } from "./package-contracts/collector-output.js";
|
|
2
|
+
import { JUDGE_OUTPUT_TOOL_NAME } from "./package-contracts/judge-output.js";
|
|
3
|
+
import { REVIEWER_OUTPUT_TOOL_NAME } from "./package-contracts/reviewer-output.js";
|
|
4
|
+
import { CODER_OUTPUT_TOOL_NAME, FIXER_OUTPUT_TOOL_NAME } from "./package-contracts/worker-output.js";
|
|
5
|
+
import { DOCTOR_OUTPUT_TOOL_NAME } from "./doctor-contracts.js";
|
|
6
|
+
import { MERGER_OUTPUT_TOOL_NAME } from "./merger-contracts.js";
|
|
7
|
+
const PACKAGED_ROLE_REGISTRY = [
|
|
8
|
+
{ role: "judge", phases: [null], outputTool: JUDGE_OUTPUT_TOOL_NAME, inputFlag: void 0, phaseFlag: void 0, activationStage: "load-and-install" },
|
|
9
|
+
{ role: "fixer", phases: ["plan", "apply"], outputTool: FIXER_OUTPUT_TOOL_NAME, inputFlag: "ak-fix-packet", phaseFlag: "ak-fixer-phase", activationStage: "load-and-install" },
|
|
10
|
+
{ role: "coder", phases: ["plan", "apply"], outputTool: CODER_OUTPUT_TOOL_NAME, inputFlag: "ak-coder-task", phaseFlag: "ak-coder-phase", activationStage: "load-and-install" },
|
|
11
|
+
{ role: "reviewer", phases: [null], outputTool: REVIEWER_OUTPUT_TOOL_NAME, inputFlag: void 0, phaseFlag: void 0, activationStage: "load-and-install" },
|
|
12
|
+
{ role: "collector", phases: [null], outputTool: COLLECTOR_OUTPUT_TOOL, inputFlag: "ak-collector-repo", phaseFlag: void 0, activationStage: "load-and-install" },
|
|
13
|
+
{ role: "doctor", phases: [null], outputTool: DOCTOR_OUTPUT_TOOL_NAME, inputFlag: "ak-doctor-case", phaseFlag: void 0, activationStage: "load-and-install" },
|
|
14
|
+
{ role: "merger", phases: [null], outputTool: MERGER_OUTPUT_TOOL_NAME, inputFlag: "ak-merger-input", phaseFlag: void 0, activationStage: "prepare-git-and-install" }
|
|
15
|
+
];
|
|
16
|
+
function packagedRoleMetadata(role) {
|
|
17
|
+
return PACKAGED_ROLE_REGISTRY.find((entry) => entry.role === role);
|
|
18
|
+
}
|
|
19
|
+
function packagedRoleInputFlag(role) {
|
|
20
|
+
return packagedRoleMetadata(role)?.inputFlag;
|
|
21
|
+
}
|
|
22
|
+
function packagedRolePhaseFlag(role) {
|
|
23
|
+
return packagedRoleMetadata(role)?.phaseFlag;
|
|
24
|
+
}
|
|
25
|
+
function packagedRoleOutputTool(role) {
|
|
26
|
+
return packagedRoleMetadata(role)?.outputTool;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
PACKAGED_ROLE_REGISTRY,
|
|
30
|
+
packagedRoleInputFlag,
|
|
31
|
+
packagedRoleMetadata,
|
|
32
|
+
packagedRoleOutputTool,
|
|
33
|
+
packagedRolePhaseFlag
|
|
34
|
+
};
|