@narumitw/pi-subagents 2.1.4 → 3.0.0
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/README.md +187 -1228
- package/dist/child-communication-bridge.ts +136 -0
- package/dist/child-communication-bridge.ts.map +7 -0
- package/dist/chunks/chunk-UKTWUQRM.js +667 -0
- package/dist/chunks/chunk-UKTWUQRM.js.map +7 -0
- package/dist/index.ts +1448 -1614
- package/dist/index.ts.map +4 -4
- package/docs/design-principles.md +31 -0
- package/docs/ipc-transport-idea.md +103 -0
- package/docs/tools.md +109 -0
- package/package.json +11 -19
- package/src/broker-credentials.ts +71 -0
- package/src/child-communication-bridge.ts +153 -0
- package/src/child-communication-tools.ts +147 -0
- package/src/completion-renderer.ts +60 -0
- package/src/index.ts +1 -1
- package/src/message-broker.ts +628 -0
- package/src/model-output.ts +42 -0
- package/src/process.ts +688 -0
- package/src/runtime.ts +538 -0
- package/src/subagents.ts +33 -34
- package/src/tools.ts +416 -0
- package/src/types.ts +85 -0
- package/src/widget.ts +130 -0
- package/dist/chunks/auto-transport-FUUKFDIG.ts +0 -109
- package/dist/chunks/auto-transport-FUUKFDIG.ts.map +0 -7
- package/dist/chunks/capability-grant-PR72SWWS.ts +0 -19
- package/dist/chunks/capability-grant-PR72SWWS.ts.map +0 -7
- package/dist/chunks/child-peer-bridge.ts +0 -108
- package/dist/chunks/child-peer-bridge.ts.map +0 -7
- package/dist/chunks/chunk-2LMJU25E.ts +0 -1641
- package/dist/chunks/chunk-2LMJU25E.ts.map +0 -7
- package/dist/chunks/chunk-47SK2QYC.ts +0 -56
- package/dist/chunks/chunk-47SK2QYC.ts.map +0 -7
- package/dist/chunks/chunk-4AQSF7AS.ts +0 -29
- package/dist/chunks/chunk-4AQSF7AS.ts.map +0 -7
- package/dist/chunks/chunk-5DGRMKNV.ts +0 -126
- package/dist/chunks/chunk-5DGRMKNV.ts.map +0 -7
- package/dist/chunks/chunk-6H6TBBED.ts +0 -108
- package/dist/chunks/chunk-6H6TBBED.ts.map +0 -7
- package/dist/chunks/chunk-6KJ34M6S.ts +0 -159
- package/dist/chunks/chunk-6KJ34M6S.ts.map +0 -7
- package/dist/chunks/chunk-6NSJVPXX.ts +0 -480
- package/dist/chunks/chunk-6NSJVPXX.ts.map +0 -7
- package/dist/chunks/chunk-7AAJEUSL.ts +0 -238
- package/dist/chunks/chunk-7AAJEUSL.ts.map +0 -7
- package/dist/chunks/chunk-BFK2Z4ZF.ts +0 -189
- package/dist/chunks/chunk-BFK2Z4ZF.ts.map +0 -7
- package/dist/chunks/chunk-BOAXY55Y.ts +0 -153
- package/dist/chunks/chunk-BOAXY55Y.ts.map +0 -7
- package/dist/chunks/chunk-D4CR7T73.ts +0 -353
- package/dist/chunks/chunk-D4CR7T73.ts.map +0 -7
- package/dist/chunks/chunk-FEVPWRMU.ts +0 -300
- package/dist/chunks/chunk-FEVPWRMU.ts.map +0 -7
- package/dist/chunks/chunk-G6VZTCFH.ts +0 -70
- package/dist/chunks/chunk-G6VZTCFH.ts.map +0 -7
- package/dist/chunks/chunk-H3FP6DLR.ts +0 -160
- package/dist/chunks/chunk-H3FP6DLR.ts.map +0 -7
- package/dist/chunks/chunk-HA36LPCO.ts +0 -130
- package/dist/chunks/chunk-HA36LPCO.ts.map +0 -7
- package/dist/chunks/chunk-HOP5FXDT.ts +0 -27
- package/dist/chunks/chunk-HOP5FXDT.ts.map +0 -7
- package/dist/chunks/chunk-IGAMVWFN.ts +0 -139
- package/dist/chunks/chunk-IGAMVWFN.ts.map +0 -7
- package/dist/chunks/chunk-ILEQ27AL.ts +0 -45
- package/dist/chunks/chunk-ILEQ27AL.ts.map +0 -7
- package/dist/chunks/chunk-ITVWPNU4.ts +0 -819
- package/dist/chunks/chunk-ITVWPNU4.ts.map +0 -7
- package/dist/chunks/chunk-IWC32VPY.ts +0 -172
- package/dist/chunks/chunk-IWC32VPY.ts.map +0 -7
- package/dist/chunks/chunk-JSZIP73U.ts +0 -362
- package/dist/chunks/chunk-JSZIP73U.ts.map +0 -7
- package/dist/chunks/chunk-JU6LUNLP.ts +0 -380
- package/dist/chunks/chunk-JU6LUNLP.ts.map +0 -7
- package/dist/chunks/chunk-KMGKCEO4.ts +0 -38
- package/dist/chunks/chunk-KMGKCEO4.ts.map +0 -7
- package/dist/chunks/chunk-LASD73CM.ts +0 -339
- package/dist/chunks/chunk-LASD73CM.ts.map +0 -7
- package/dist/chunks/chunk-LEOYDZI3.ts +0 -22
- package/dist/chunks/chunk-LEOYDZI3.ts.map +0 -7
- package/dist/chunks/chunk-LL4LP2T7.ts +0 -737
- package/dist/chunks/chunk-LL4LP2T7.ts.map +0 -7
- package/dist/chunks/chunk-N2T5IN4X.ts +0 -18
- package/dist/chunks/chunk-N2T5IN4X.ts.map +0 -7
- package/dist/chunks/chunk-N7BLVXKK.ts +0 -73
- package/dist/chunks/chunk-N7BLVXKK.ts.map +0 -7
- package/dist/chunks/chunk-NLT67IZS.ts +0 -322
- package/dist/chunks/chunk-NLT67IZS.ts.map +0 -7
- package/dist/chunks/chunk-NTRPLF46.ts +0 -63
- package/dist/chunks/chunk-NTRPLF46.ts.map +0 -7
- package/dist/chunks/chunk-ONDTY4EL.ts +0 -91
- package/dist/chunks/chunk-ONDTY4EL.ts.map +0 -7
- package/dist/chunks/chunk-OVPHFGKO.ts +0 -1769
- package/dist/chunks/chunk-OVPHFGKO.ts.map +0 -7
- package/dist/chunks/chunk-P7OH4XMF.ts +0 -60
- package/dist/chunks/chunk-P7OH4XMF.ts.map +0 -7
- package/dist/chunks/chunk-PBZMBTNJ.ts +0 -422
- package/dist/chunks/chunk-PBZMBTNJ.ts.map +0 -7
- package/dist/chunks/chunk-PGLSFLYW.ts +0 -52
- package/dist/chunks/chunk-PGLSFLYW.ts.map +0 -7
- package/dist/chunks/chunk-RRR66UWR.ts +0 -28
- package/dist/chunks/chunk-RRR66UWR.ts.map +0 -7
- package/dist/chunks/chunk-RSUXZD6S.ts +0 -275
- package/dist/chunks/chunk-RSUXZD6S.ts.map +0 -7
- package/dist/chunks/chunk-RTCVYIZA.ts +0 -221
- package/dist/chunks/chunk-RTCVYIZA.ts.map +0 -7
- package/dist/chunks/chunk-RY2AEGMZ.ts +0 -34
- package/dist/chunks/chunk-RY2AEGMZ.ts.map +0 -7
- package/dist/chunks/chunk-SWGQLFSD.ts +0 -60
- package/dist/chunks/chunk-SWGQLFSD.ts.map +0 -7
- package/dist/chunks/chunk-TM2R67J3.ts +0 -52
- package/dist/chunks/chunk-TM2R67J3.ts.map +0 -7
- package/dist/chunks/chunk-TMZRHIIK.ts +0 -497
- package/dist/chunks/chunk-TMZRHIIK.ts.map +0 -7
- package/dist/chunks/chunk-TZ34IQ3M.ts +0 -59
- package/dist/chunks/chunk-TZ34IQ3M.ts.map +0 -7
- package/dist/chunks/chunk-UMBPMVJW.ts +0 -22
- package/dist/chunks/chunk-UMBPMVJW.ts.map +0 -7
- package/dist/chunks/chunk-VDG7LTYE.ts +0 -80
- package/dist/chunks/chunk-VDG7LTYE.ts.map +0 -7
- package/dist/chunks/chunk-X4NMONPE.ts +0 -73
- package/dist/chunks/chunk-X4NMONPE.ts.map +0 -7
- package/dist/chunks/chunk-YPJEN6NU.ts +0 -65
- package/dist/chunks/chunk-YPJEN6NU.ts.map +0 -7
- package/dist/chunks/chunk-YU53SHA7.ts +0 -328
- package/dist/chunks/chunk-YU53SHA7.ts.map +0 -7
- package/dist/chunks/completion-delivery-RSJU6BXL.ts +0 -17
- package/dist/chunks/completion-delivery-RSJU6BXL.ts.map +0 -7
- package/dist/chunks/config-status-FKGDECZ3.ts +0 -35
- package/dist/chunks/config-status-FKGDECZ3.ts.map +0 -7
- package/dist/chunks/config-ui-ABHYNGQ7.ts +0 -1212
- package/dist/chunks/config-ui-ABHYNGQ7.ts.map +0 -7
- package/dist/chunks/consult-LJU3IQY5.ts +0 -519
- package/dist/chunks/consult-LJU3IQY5.ts.map +0 -7
- package/dist/chunks/context-QDKLVQXE.ts +0 -11
- package/dist/chunks/context-QDKLVQXE.ts.map +0 -7
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts +0 -130
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts.map +0 -7
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts +0 -17
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +0 -7
- package/dist/chunks/delegation-contract-LA56I5DT.ts +0 -24
- package/dist/chunks/delegation-contract-LA56I5DT.ts.map +0 -7
- package/dist/chunks/discovery-MIFB2U4Y.ts +0 -12
- package/dist/chunks/discovery-MIFB2U4Y.ts.map +0 -7
- package/dist/chunks/execution-Q2JZLKJA.ts +0 -4037
- package/dist/chunks/execution-Q2JZLKJA.ts.map +0 -7
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts +0 -39
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts.map +0 -7
- package/dist/chunks/inspect-UH2TKH6E.ts +0 -634
- package/dist/chunks/inspect-UH2TKH6E.ts.map +0 -7
- package/dist/chunks/peer-communication-KL36Z6CO.ts +0 -294
- package/dist/chunks/peer-communication-KL36Z6CO.ts.map +0 -7
- package/dist/chunks/persistence-UY3PY6E5.ts +0 -348
- package/dist/chunks/persistence-UY3PY6E5.ts.map +0 -7
- package/dist/chunks/registry-BT54L6CY.ts +0 -1445
- package/dist/chunks/registry-BT54L6CY.ts.map +0 -7
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts +0 -81
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts.map +0 -7
- package/dist/chunks/rpc-transport-7R7DVCEB.ts +0 -1222
- package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +0 -7
- package/dist/chunks/runtime-policy-5YELCOVC.ts +0 -15
- package/dist/chunks/runtime-policy-5YELCOVC.ts.map +0 -7
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +0 -19
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +0 -7
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts +0 -13
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts.map +0 -7
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +0 -15
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +0 -7
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts +0 -160
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +0 -7
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +0 -164
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +0 -7
- package/dist/chunks/workspace-WDKLN72J.ts +0 -11
- package/dist/chunks/workspace-WDKLN72J.ts.map +0 -7
- package/docs/async-runtime-protocol.md +0 -84
- package/docs/implementation-notes/pi-subagents-capability-matrix.md +0 -62
- package/docs/implementation-notes/pi-subagents-current-direction.md +0 -99
- package/docs/implementation-notes/pi-subagents-rpc-v1.md +0 -139
- package/docs/pi-subagents-diagrams.md +0 -183
- package/src/adaptive-scheduler.ts +0 -224
- package/src/admission-policy.ts +0 -78
- package/src/agent-projection.ts +0 -53
- package/src/agents/built-ins.ts +0 -71
- package/src/agents/catalog.ts +0 -241
- package/src/agents/discovery.ts +0 -265
- package/src/agents/types.ts +0 -100
- package/src/agents.ts +0 -51
- package/src/auto-transport.ts +0 -121
- package/src/blocking-status.ts +0 -63
- package/src/cached-module-loader.ts +0 -18
- package/src/capabilities.ts +0 -145
- package/src/capability-grant.ts +0 -115
- package/src/capability-router.ts +0 -107
- package/src/child-peer-bridge.ts +0 -124
- package/src/child-peer-tools.ts +0 -132
- package/src/completion-delivery.ts +0 -409
- package/src/completion-render.ts +0 -190
- package/src/completion-requirement.ts +0 -479
- package/src/completion-routing.ts +0 -24
- package/src/config-registration.ts +0 -114
- package/src/config-status.ts +0 -217
- package/src/config-ui.ts +0 -983
- package/src/consult-policy.ts +0 -15
- package/src/consult-registration.ts +0 -125
- package/src/consult-render.ts +0 -194
- package/src/consult-resources.ts +0 -51
- package/src/consult-tool.ts +0 -95
- package/src/consult.ts +0 -566
- package/src/context.ts +0 -126
- package/src/create-stateful-transport.ts +0 -157
- package/src/cwd-policy.ts +0 -183
- package/src/delegation-contract.ts +0 -463
- package/src/execution/budget.ts +0 -56
- package/src/execution/runtime-policy.ts +0 -19
- package/src/execution-plan.ts +0 -322
- package/src/execution-ui.ts +0 -259
- package/src/execution.ts +0 -1679
- package/src/in-process-transport.ts +0 -941
- package/src/inspect-registration.ts +0 -64
- package/src/inspect-render.ts +0 -334
- package/src/inspect-tool.ts +0 -45
- package/src/inspect.ts +0 -769
- package/src/integration-controller.ts +0 -98
- package/src/limits.ts +0 -75
- package/src/orchestration-metrics.ts +0 -116
- package/src/outcome.ts +0 -61
- package/src/panel-child-group.ts +0 -35
- package/src/panel-contract.ts +0 -343
- package/src/panel-evidence.ts +0 -59
- package/src/panel-execution.ts +0 -769
- package/src/panel-failure.ts +0 -56
- package/src/panel-planning.ts +0 -175
- package/src/panel-presets.ts +0 -3
- package/src/panel-prompts.ts +0 -132
- package/src/panel-reconciliation.ts +0 -57
- package/src/panel-render.ts +0 -103
- package/src/parallel-limit-ui.ts +0 -113
- package/src/params.ts +0 -278
- package/src/peer-communication.ts +0 -352
- package/src/peer-transport.ts +0 -49
- package/src/persistence.ts +0 -522
- package/src/pi-args.ts +0 -43
- package/src/pi-invocation.ts +0 -168
- package/src/process-control.ts +0 -43
- package/src/prompt-resources.ts +0 -38
- package/src/prompt-source-safety.ts +0 -48
- package/src/protocol.ts +0 -76
- package/src/registry-types.ts +0 -204
- package/src/registry.ts +0 -1698
- package/src/render-common.ts +0 -252
- package/src/render.ts +0 -704
- package/src/result-contract.ts +0 -431
- package/src/retained-semantic-state.ts +0 -100
- package/src/rpc-timeout-finalization.ts +0 -207
- package/src/rpc-transport-metadata.ts +0 -65
- package/src/rpc-transport.ts +0 -1035
- package/src/rpc-turn-capture.ts +0 -217
- package/src/runner-outcome.ts +0 -31
- package/src/runner-result.ts +0 -55
- package/src/runner-types.ts +0 -102
- package/src/runner-usage.ts +0 -48
- package/src/runner.ts +0 -866
- package/src/safe-text.ts +0 -67
- package/src/semantic-snapshot.ts +0 -214
- package/src/session-guidance-contract.ts +0 -399
- package/src/settings/inspection.ts +0 -302
- package/src/settings/schema.ts +0 -195
- package/src/settings-reader.ts +0 -215
- package/src/settings.ts +0 -452
- package/src/spawn-idempotency.ts +0 -68
- package/src/stateful-agent-view.ts +0 -85
- package/src/stateful-config.ts +0 -13
- package/src/stateful-guidance.ts +0 -29
- package/src/stateful-lifecycle.ts +0 -74
- package/src/stateful-limit-ui.ts +0 -249
- package/src/stateful-limits.ts +0 -96
- package/src/stateful-prompt.ts +0 -49
- package/src/stateful-registration.ts +0 -1320
- package/src/stateful-render.ts +0 -318
- package/src/stateful-safety.ts +0 -47
- package/src/stateful-tool-params.ts +0 -215
- package/src/stateful.ts +0 -12
- package/src/subagent-details.ts +0 -43
- package/src/subagents-extension.ts +0 -372
- package/src/subprocess-transport.ts +0 -145
- package/src/supervision.ts +0 -104
- package/src/task-path.ts +0 -65
- package/src/timeout-checkpoint.ts +0 -305
- package/src/timeout-finalization.ts +0 -75
- package/src/tool-schema-compatibility.ts +0 -73
- package/src/transport-types.ts +0 -74
- package/src/transport-ui.ts +0 -135
- package/src/transport.ts +0 -43
- package/src/turn-budget.ts +0 -109
- package/src/usage-format.ts +0 -42
- package/src/usage-recording-config.ts +0 -13
- package/src/usage-recording-store.ts +0 -183
- package/src/usage-recording.ts +0 -478
- package/src/verification-harness.ts +0 -516
- package/src/verification-policy.ts +0 -67
- package/src/verification-receipt.ts +0 -275
- package/src/verified-execution-benchmark.ts +0 -86
- package/src/verified-execution-contract.ts +0 -191
- package/src/verified-execution-schema.ts +0 -32
- package/src/work-item-ledger.ts +0 -1404
- package/src/work-item-persistence.ts +0 -254
- package/src/workflow-completion-controller.ts +0 -397
- package/src/workflow-planning.ts +0 -172
- package/src/workflow-tree-identity.ts +0 -289
- package/src/workflow-ui.ts +0 -69
- package/src/workflow-verification.ts +0 -296
- package/src/workspace.ts +0 -174
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
import { execFile, spawn } from "node:child_process";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import * as fs from "node:fs";
|
|
4
|
-
import * as os from "node:os";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import { redactPrivateText } from "./context.js";
|
|
8
|
-
import { appendBounded, truncateUtf8 } from "./limits.js";
|
|
9
|
-
import { terminateProcess } from "./process-control.js";
|
|
10
|
-
import type { VerificationCheckReceipt } from "./verification-receipt.js";
|
|
11
|
-
import {
|
|
12
|
-
captureWorkflowTreeIdentity,
|
|
13
|
-
type WorkflowTreeIdentity,
|
|
14
|
-
} from "./workflow-tree-identity.js";
|
|
15
|
-
|
|
16
|
-
const execFileAsync = promisify(execFile);
|
|
17
|
-
const SAFE_COMMANDS = new Set(["git", "node", "npm", "npx"]);
|
|
18
|
-
const MAX_VISIBLE_FILES = 4096;
|
|
19
|
-
const MAX_CHANGED_PATH_BYTES = 8 * 1024;
|
|
20
|
-
const MAX_COPY_BYTES = 64 * 1024 * 1024;
|
|
21
|
-
const MAX_COMMAND_OUTPUT_BYTES = 64 * 1024;
|
|
22
|
-
const MAX_RECORDED_CHECK_OUTPUT_BYTES = 2 * 1024;
|
|
23
|
-
const DEFAULT_CHECK_TIMEOUT_MS = 2 * 60 * 1000;
|
|
24
|
-
const VERIFICATION_KILL_GRACE_MS = 250;
|
|
25
|
-
const VERIFICATION_TERMINATION_DEADLINE_MS = VERIFICATION_KILL_GRACE_MS + 1_000;
|
|
26
|
-
|
|
27
|
-
export interface VerificationCheckRequest {
|
|
28
|
-
id: string;
|
|
29
|
-
command: string;
|
|
30
|
-
args?: string[];
|
|
31
|
-
cwd?: string;
|
|
32
|
-
timeoutMs?: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface VerificationSubmission {
|
|
36
|
-
treeIdentity: WorkflowTreeIdentity;
|
|
37
|
-
baseRepositoryGeneration: string;
|
|
38
|
-
patchDigest: string;
|
|
39
|
-
changedPaths: string[];
|
|
40
|
-
fileVersions: Record<string, string>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface VerificationHarnessResult {
|
|
44
|
-
disposableDirectory: string;
|
|
45
|
-
checks: VerificationCheckReceipt[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function captureVerificationSubmission(
|
|
49
|
-
cwd: string,
|
|
50
|
-
signal?: AbortSignal,
|
|
51
|
-
): Promise<VerificationSubmission> {
|
|
52
|
-
throwIfAborted(signal);
|
|
53
|
-
const repositoryRoot = await resolveRepositoryRoot(cwd, signal);
|
|
54
|
-
const [treeIdentity, head, changed, untracked] = await Promise.all([
|
|
55
|
-
captureWorkflowTreeIdentity(cwd, { signal }),
|
|
56
|
-
git(repositoryRoot, ["rev-parse", "HEAD"], signal),
|
|
57
|
-
git(repositoryRoot, ["diff", "--name-only", "-z", "HEAD", "--"], signal),
|
|
58
|
-
git(repositoryRoot, ["ls-files", "--others", "--exclude-standard", "-z"], signal),
|
|
59
|
-
]);
|
|
60
|
-
throwIfAborted(signal);
|
|
61
|
-
const baseRepositoryGeneration = head.trim();
|
|
62
|
-
if (!/^[a-f0-9]{40,64}$/u.test(baseRepositoryGeneration)) {
|
|
63
|
-
throw new Error("Verification submission has no stable repository generation");
|
|
64
|
-
}
|
|
65
|
-
const changedPaths = uniqueSorted([...splitNul(changed), ...splitNul(untracked)]);
|
|
66
|
-
if (
|
|
67
|
-
changedPaths.length > MAX_VISIBLE_FILES ||
|
|
68
|
-
changedPaths.reduce((total, item) => total + Buffer.byteLength(item, "utf8"), 0) >
|
|
69
|
-
MAX_CHANGED_PATH_BYTES
|
|
70
|
-
) {
|
|
71
|
-
throw new Error("Verification submission exceeded its changed-path limit");
|
|
72
|
-
}
|
|
73
|
-
const fileVersions: Record<string, string> = {};
|
|
74
|
-
for (const relative of changedPaths) {
|
|
75
|
-
throwIfAborted(signal);
|
|
76
|
-
assertSafeRelativePath(relative);
|
|
77
|
-
const candidate = path.join(repositoryRoot, relative);
|
|
78
|
-
try {
|
|
79
|
-
const stat = await fs.promises.lstat(candidate);
|
|
80
|
-
const value = stat.isSymbolicLink()
|
|
81
|
-
? Buffer.from(await fs.promises.readlink(candidate), "utf8")
|
|
82
|
-
: stat.isFile()
|
|
83
|
-
? await readRegularFileNoFollow(candidate, stat, signal)
|
|
84
|
-
: Buffer.from("unsupported", "utf8");
|
|
85
|
-
fileVersions[relative] = createHash("sha256").update(value).digest("hex");
|
|
86
|
-
} catch (error) {
|
|
87
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
88
|
-
fileVersions[relative] = "deleted";
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const patchDigest = createHash("sha256")
|
|
95
|
-
.update("pi-subagents:verification-patch:v1\0")
|
|
96
|
-
.update(baseRepositoryGeneration)
|
|
97
|
-
.update("\0")
|
|
98
|
-
.update(treeIdentity.digest)
|
|
99
|
-
.digest("hex");
|
|
100
|
-
return {
|
|
101
|
-
treeIdentity,
|
|
102
|
-
baseRepositoryGeneration,
|
|
103
|
-
patchDigest,
|
|
104
|
-
changedPaths,
|
|
105
|
-
fileVersions,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function runVerificationChecks(
|
|
110
|
-
cwd: string,
|
|
111
|
-
requests: readonly VerificationCheckRequest[],
|
|
112
|
-
signal?: AbortSignal,
|
|
113
|
-
): Promise<VerificationHarnessResult> {
|
|
114
|
-
validateVerificationChecks(requests);
|
|
115
|
-
throwIfAborted(signal);
|
|
116
|
-
const repositoryRoot = await resolveRepositoryRoot(cwd, signal);
|
|
117
|
-
const disposableDirectory = await createDisposableDirectory(repositoryRoot);
|
|
118
|
-
let registeredWorktree = false;
|
|
119
|
-
try {
|
|
120
|
-
// Treat setup as registered before awaiting so partial Git initialization is also pruned.
|
|
121
|
-
registeredWorktree = true;
|
|
122
|
-
await git(
|
|
123
|
-
repositoryRoot,
|
|
124
|
-
["worktree", "add", "--detach", "--no-checkout", disposableDirectory, "HEAD"],
|
|
125
|
-
signal,
|
|
126
|
-
);
|
|
127
|
-
await copyVisibleSubmission(repositoryRoot, disposableDirectory, signal);
|
|
128
|
-
const checks: VerificationCheckReceipt[] = [];
|
|
129
|
-
for (const request of requests) {
|
|
130
|
-
throwIfAborted(signal);
|
|
131
|
-
checks.push(await runCheck(disposableDirectory, request, signal));
|
|
132
|
-
}
|
|
133
|
-
return { disposableDirectory, checks };
|
|
134
|
-
} finally {
|
|
135
|
-
await cleanupDisposableWorktree(repositoryRoot, disposableDirectory, registeredWorktree);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async function createDisposableDirectory(repositoryRoot: string): Promise<string> {
|
|
140
|
-
const dependencyRoot = path.join(repositoryRoot, "node_modules");
|
|
141
|
-
let parent = os.tmpdir();
|
|
142
|
-
try {
|
|
143
|
-
const stat = await fs.promises.lstat(dependencyRoot);
|
|
144
|
-
if (
|
|
145
|
-
stat.isDirectory() &&
|
|
146
|
-
!stat.isSymbolicLink() &&
|
|
147
|
-
(await isIgnoredDependencyDirectory(repositoryRoot))
|
|
148
|
-
) {
|
|
149
|
-
parent = dependencyRoot;
|
|
150
|
-
}
|
|
151
|
-
} catch (error) {
|
|
152
|
-
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
153
|
-
}
|
|
154
|
-
return fs.promises.mkdtemp(path.join(parent, ".pi-subagents-verification-"));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async function isIgnoredDependencyDirectory(repositoryRoot: string): Promise<boolean> {
|
|
158
|
-
try {
|
|
159
|
-
await execFileAsync(
|
|
160
|
-
"git",
|
|
161
|
-
[
|
|
162
|
-
"-C",
|
|
163
|
-
repositoryRoot,
|
|
164
|
-
"check-ignore",
|
|
165
|
-
"--quiet",
|
|
166
|
-
"node_modules/.pi-subagents-verification-probe",
|
|
167
|
-
],
|
|
168
|
-
{ encoding: "utf8", maxBuffer: 2 * 1024 * 1024 },
|
|
169
|
-
);
|
|
170
|
-
return true;
|
|
171
|
-
} catch (error) {
|
|
172
|
-
if ((error as { code?: string | number }).code === 1) return false;
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function cleanupDisposableWorktree(
|
|
178
|
-
repositoryRoot: string,
|
|
179
|
-
disposableDirectory: string,
|
|
180
|
-
registered: boolean,
|
|
181
|
-
): Promise<void> {
|
|
182
|
-
let removedRegistration = !registered;
|
|
183
|
-
if (registered) {
|
|
184
|
-
try {
|
|
185
|
-
await execFileAsync(
|
|
186
|
-
"git",
|
|
187
|
-
["-C", repositoryRoot, "worktree", "remove", "--force", "--force", disposableDirectory],
|
|
188
|
-
{ encoding: "utf8", maxBuffer: 2 * 1024 * 1024 },
|
|
189
|
-
);
|
|
190
|
-
removedRegistration = true;
|
|
191
|
-
} catch {
|
|
192
|
-
// Remove the directory first, then let Git prune its now-stale registration below.
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
await fs.promises.rm(disposableDirectory, { recursive: true, force: true });
|
|
196
|
-
if (!removedRegistration) {
|
|
197
|
-
try {
|
|
198
|
-
await execFileAsync("git", ["-C", repositoryRoot, "worktree", "prune"], {
|
|
199
|
-
encoding: "utf8",
|
|
200
|
-
maxBuffer: 2 * 1024 * 1024,
|
|
201
|
-
});
|
|
202
|
-
} catch {
|
|
203
|
-
throw new Error("Verification harness could not clean its disposable Git worktree");
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async function copyVisibleSubmission(
|
|
209
|
-
repositoryRoot: string,
|
|
210
|
-
destination: string,
|
|
211
|
-
signal?: AbortSignal,
|
|
212
|
-
): Promise<void> {
|
|
213
|
-
const output = await git(
|
|
214
|
-
repositoryRoot,
|
|
215
|
-
["ls-files", "--cached", "--others", "--exclude-standard", "-z"],
|
|
216
|
-
signal,
|
|
217
|
-
);
|
|
218
|
-
const files = uniqueSorted(splitNul(output));
|
|
219
|
-
if (files.length > MAX_VISIBLE_FILES) {
|
|
220
|
-
throw new Error("Verification disposable copy exceeded its file limit");
|
|
221
|
-
}
|
|
222
|
-
let copiedBytes = 0;
|
|
223
|
-
for (const relative of files) {
|
|
224
|
-
throwIfAborted(signal);
|
|
225
|
-
assertSafeRelativePath(relative);
|
|
226
|
-
const source = path.join(repositoryRoot, relative);
|
|
227
|
-
const target = path.join(destination, relative);
|
|
228
|
-
let stat: fs.Stats;
|
|
229
|
-
try {
|
|
230
|
-
stat = await fs.promises.lstat(source);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") continue;
|
|
233
|
-
throw error;
|
|
234
|
-
}
|
|
235
|
-
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
|
236
|
-
if (stat.isSymbolicLink()) {
|
|
237
|
-
const link = await fs.promises.readlink(source);
|
|
238
|
-
const resolvedLink = path.resolve(path.dirname(target), link);
|
|
239
|
-
if (resolvedLink !== destination && !resolvedLink.startsWith(`${destination}${path.sep}`)) {
|
|
240
|
-
throw new Error("Verification disposable copy rejected an external symlink");
|
|
241
|
-
}
|
|
242
|
-
copiedBytes += Buffer.byteLength(link, "utf8");
|
|
243
|
-
await fs.promises.symlink(link, target);
|
|
244
|
-
} else if (stat.isFile()) {
|
|
245
|
-
if (stat.size > MAX_COPY_BYTES - copiedBytes) {
|
|
246
|
-
throw new Error("Verification disposable copy exceeded its byte limit");
|
|
247
|
-
}
|
|
248
|
-
const bytes = await readRegularFileNoFollow(source, stat, signal);
|
|
249
|
-
copiedBytes += bytes.length;
|
|
250
|
-
await fs.promises.writeFile(target, bytes, { flag: "wx", mode: stat.mode });
|
|
251
|
-
} else {
|
|
252
|
-
throw new Error("Verification disposable copy encountered an unsupported file type");
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
async function readRegularFileNoFollow(
|
|
258
|
-
filePath: string,
|
|
259
|
-
expected: fs.Stats,
|
|
260
|
-
signal?: AbortSignal,
|
|
261
|
-
): Promise<Buffer> {
|
|
262
|
-
throwIfAborted(signal);
|
|
263
|
-
const handle = await fs.promises.open(filePath, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
264
|
-
try {
|
|
265
|
-
const before = await handle.stat();
|
|
266
|
-
if (!before.isFile() || before.dev !== expected.dev || before.ino !== expected.ino) {
|
|
267
|
-
throw new Error("Verification disposable source changed during copy");
|
|
268
|
-
}
|
|
269
|
-
const bytes = await handle.readFile({ signal });
|
|
270
|
-
const after = await handle.stat();
|
|
271
|
-
if (
|
|
272
|
-
after.dev !== before.dev ||
|
|
273
|
-
after.ino !== before.ino ||
|
|
274
|
-
after.size !== before.size ||
|
|
275
|
-
after.mtimeMs !== before.mtimeMs
|
|
276
|
-
) {
|
|
277
|
-
throw new Error("Verification disposable source changed during copy");
|
|
278
|
-
}
|
|
279
|
-
return bytes;
|
|
280
|
-
} finally {
|
|
281
|
-
await handle.close();
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async function runCheck(
|
|
286
|
-
root: string,
|
|
287
|
-
request: VerificationCheckRequest,
|
|
288
|
-
signal?: AbortSignal,
|
|
289
|
-
): Promise<VerificationCheckReceipt> {
|
|
290
|
-
const startedAt = Date.now();
|
|
291
|
-
const checkCwd = path.resolve(root, request.cwd ?? ".");
|
|
292
|
-
if (checkCwd !== root && !checkCwd.startsWith(`${root}${path.sep}`)) {
|
|
293
|
-
throw new Error(`Unsafe verification cwd for ${request.id}`);
|
|
294
|
-
}
|
|
295
|
-
throwIfAborted(signal);
|
|
296
|
-
const result = await executeCheckProcess(
|
|
297
|
-
request.command,
|
|
298
|
-
request.args ?? [],
|
|
299
|
-
checkCwd,
|
|
300
|
-
request.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS,
|
|
301
|
-
signal,
|
|
302
|
-
);
|
|
303
|
-
if (result.aborted) throw abortError();
|
|
304
|
-
const boundedStdout = truncateUtf8(
|
|
305
|
-
redactPrivateText(result.stdout),
|
|
306
|
-
MAX_RECORDED_CHECK_OUTPUT_BYTES,
|
|
307
|
-
);
|
|
308
|
-
const boundedStderr = truncateUtf8(
|
|
309
|
-
redactPrivateText(result.stderr),
|
|
310
|
-
MAX_RECORDED_CHECK_OUTPUT_BYTES,
|
|
311
|
-
);
|
|
312
|
-
return {
|
|
313
|
-
id: request.id,
|
|
314
|
-
command: request.command,
|
|
315
|
-
args: (request.args ?? []).map(redactPrivateText),
|
|
316
|
-
cwd: redactPrivateText(request.cwd ?? "."),
|
|
317
|
-
status: result.exitCode === 0 ? "passed" : "failed",
|
|
318
|
-
exitCode: result.exitCode,
|
|
319
|
-
stdout: boundedStdout.text,
|
|
320
|
-
stderr: boundedStderr.text,
|
|
321
|
-
durationMs: Math.max(0, Date.now() - startedAt),
|
|
322
|
-
truncated: result.truncated || boundedStdout.truncated || boundedStderr.truncated,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
interface CheckProcessResult {
|
|
327
|
-
exitCode: number;
|
|
328
|
-
stdout: string;
|
|
329
|
-
stderr: string;
|
|
330
|
-
truncated: boolean;
|
|
331
|
-
aborted: boolean;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function executeCheckProcess(
|
|
335
|
-
command: string,
|
|
336
|
-
args: readonly string[],
|
|
337
|
-
cwd: string,
|
|
338
|
-
timeoutMs: number,
|
|
339
|
-
signal?: AbortSignal,
|
|
340
|
-
): Promise<CheckProcessResult> {
|
|
341
|
-
return new Promise((resolve) => {
|
|
342
|
-
let stdout = "";
|
|
343
|
-
let stderr = "";
|
|
344
|
-
let truncated = false;
|
|
345
|
-
let aborted = false;
|
|
346
|
-
let timedOut = false;
|
|
347
|
-
let outputExceeded = false;
|
|
348
|
-
let settled = false;
|
|
349
|
-
let timeout: NodeJS.Timeout | undefined;
|
|
350
|
-
let terminationDeadline: NodeJS.Timeout | undefined;
|
|
351
|
-
let cleanupTermination: (() => void) | undefined;
|
|
352
|
-
let abortHandler: (() => void) | undefined;
|
|
353
|
-
const proc = spawn(command, args, {
|
|
354
|
-
cwd,
|
|
355
|
-
detached: process.platform !== "win32",
|
|
356
|
-
shell: false,
|
|
357
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
358
|
-
env: verificationEnvironment(),
|
|
359
|
-
});
|
|
360
|
-
const finish = (exitCode: number) => {
|
|
361
|
-
if (settled) return;
|
|
362
|
-
settled = true;
|
|
363
|
-
if (timeout) clearTimeout(timeout);
|
|
364
|
-
if (terminationDeadline) clearTimeout(terminationDeadline);
|
|
365
|
-
cleanupTermination?.();
|
|
366
|
-
if (signal && abortHandler) signal.removeEventListener("abort", abortHandler);
|
|
367
|
-
resolve({ exitCode, stdout, stderr, truncated, aborted });
|
|
368
|
-
};
|
|
369
|
-
const beginTermination = () => {
|
|
370
|
-
if (cleanupTermination || settled) return;
|
|
371
|
-
cleanupTermination = terminateProcess(proc, VERIFICATION_KILL_GRACE_MS);
|
|
372
|
-
terminationDeadline = setTimeout(() => {
|
|
373
|
-
proc.stdout?.destroy();
|
|
374
|
-
proc.stderr?.destroy();
|
|
375
|
-
finish(aborted ? 130 : timedOut ? 124 : -1);
|
|
376
|
-
}, VERIFICATION_TERMINATION_DEADLINE_MS);
|
|
377
|
-
terminationDeadline.unref();
|
|
378
|
-
};
|
|
379
|
-
const appendOutput = (current: string, chunk: Buffer): string => {
|
|
380
|
-
const appended = appendBounded(current, chunk.toString(), MAX_COMMAND_OUTPUT_BYTES);
|
|
381
|
-
truncated ||= appended.truncated;
|
|
382
|
-
if (appended.truncated && !outputExceeded) {
|
|
383
|
-
outputExceeded = true;
|
|
384
|
-
beginTermination();
|
|
385
|
-
}
|
|
386
|
-
return appended.text;
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
proc.stdout?.on("data", (chunk: Buffer) => {
|
|
390
|
-
stdout = appendOutput(stdout, chunk);
|
|
391
|
-
});
|
|
392
|
-
proc.stderr?.on("data", (chunk: Buffer) => {
|
|
393
|
-
stderr = appendOutput(stderr, chunk);
|
|
394
|
-
});
|
|
395
|
-
proc.once("close", (code) => {
|
|
396
|
-
finish(aborted ? 130 : timedOut ? 124 : outputExceeded ? -1 : (code ?? -1));
|
|
397
|
-
});
|
|
398
|
-
proc.once("error", (error) => {
|
|
399
|
-
const appended = appendBounded(stderr, error.message, MAX_COMMAND_OUTPUT_BYTES);
|
|
400
|
-
stderr = appended.text;
|
|
401
|
-
truncated ||= appended.truncated;
|
|
402
|
-
if (proc.pid) beginTermination();
|
|
403
|
-
else finish(-1);
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
timeout = setTimeout(() => {
|
|
407
|
-
timedOut = true;
|
|
408
|
-
beginTermination();
|
|
409
|
-
}, timeoutMs);
|
|
410
|
-
timeout.unref();
|
|
411
|
-
if (signal) {
|
|
412
|
-
abortHandler = () => {
|
|
413
|
-
aborted = true;
|
|
414
|
-
beginTermination();
|
|
415
|
-
};
|
|
416
|
-
if (signal.aborted) abortHandler();
|
|
417
|
-
else signal.addEventListener("abort", abortHandler, { once: true });
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
export function validateVerificationChecks(requests: readonly VerificationCheckRequest[]): void {
|
|
423
|
-
if (requests.length > 32) throw new Error("Too many deterministic verification checks");
|
|
424
|
-
const ids = new Set<string>();
|
|
425
|
-
for (const request of requests) {
|
|
426
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u.test(request.id) || ids.has(request.id)) {
|
|
427
|
-
throw new Error("Verification checks require unique bounded ids");
|
|
428
|
-
}
|
|
429
|
-
ids.add(request.id);
|
|
430
|
-
if (!SAFE_COMMANDS.has(request.command)) {
|
|
431
|
-
throw new Error(`Unsafe verification command: ${request.command}`);
|
|
432
|
-
}
|
|
433
|
-
if ((request.args?.length ?? 0) > 64)
|
|
434
|
-
throw new Error("Too many verification command arguments");
|
|
435
|
-
if (
|
|
436
|
-
request.args?.some(
|
|
437
|
-
(value) => typeof value !== "string" || value.includes("\0") || value.length > 4096,
|
|
438
|
-
)
|
|
439
|
-
) {
|
|
440
|
-
throw new Error("Unsafe verification command argument");
|
|
441
|
-
}
|
|
442
|
-
if (request.cwd !== undefined) assertSafeRelativePath(request.cwd);
|
|
443
|
-
if (
|
|
444
|
-
request.timeoutMs !== undefined &&
|
|
445
|
-
(!Number.isSafeInteger(request.timeoutMs) ||
|
|
446
|
-
request.timeoutMs < 1 ||
|
|
447
|
-
request.timeoutMs > 600_000)
|
|
448
|
-
) {
|
|
449
|
-
throw new Error("Invalid verification check timeout");
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
async function resolveRepositoryRoot(cwd: string, signal?: AbortSignal): Promise<string> {
|
|
455
|
-
let canonical: string;
|
|
456
|
-
try {
|
|
457
|
-
canonical = await fs.promises.realpath(path.resolve(cwd));
|
|
458
|
-
} catch {
|
|
459
|
-
throw new Error("Verification harness requires a readable Git repository directory");
|
|
460
|
-
}
|
|
461
|
-
const root = (await git(canonical, ["rev-parse", "--show-toplevel"], signal)).trim();
|
|
462
|
-
return fs.promises.realpath(root);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
async function git(cwd: string, args: string[], signal?: AbortSignal): Promise<string> {
|
|
466
|
-
throwIfAborted(signal);
|
|
467
|
-
try {
|
|
468
|
-
const result = await execFileAsync("git", ["-C", cwd, ...args], {
|
|
469
|
-
signal,
|
|
470
|
-
encoding: "utf8",
|
|
471
|
-
maxBuffer: 2 * 1024 * 1024,
|
|
472
|
-
});
|
|
473
|
-
return result.stdout;
|
|
474
|
-
} catch (error) {
|
|
475
|
-
if (signal?.aborted || (error instanceof Error && error.name === "AbortError")) {
|
|
476
|
-
throw abortError();
|
|
477
|
-
}
|
|
478
|
-
throw new Error("Verification harness could not inspect the Git repository");
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
function verificationEnvironment(): NodeJS.ProcessEnv {
|
|
483
|
-
const allowed = ["HOME", "PATH", "TMPDIR", "TEMP", "TMP", "SystemRoot", "WINDIR"];
|
|
484
|
-
return Object.fromEntries(
|
|
485
|
-
allowed.flatMap((key) => (process.env[key] === undefined ? [] : [[key, process.env[key]]])),
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function splitNul(value: string): string[] {
|
|
490
|
-
return value.split("\0").filter(Boolean);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function uniqueSorted(values: string[]): string[] {
|
|
494
|
-
return [...new Set(values)].sort((left, right) => left.localeCompare(right));
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
function assertSafeRelativePath(value: string): void {
|
|
498
|
-
if (
|
|
499
|
-
!value ||
|
|
500
|
-
value.includes("\0") ||
|
|
501
|
-
path.isAbsolute(value) ||
|
|
502
|
-
path.normalize(value).split(path.sep).includes("..")
|
|
503
|
-
) {
|
|
504
|
-
throw new Error("Verification harness encountered an unsafe relative path");
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function throwIfAborted(signal?: AbortSignal): void {
|
|
509
|
-
if (signal?.aborted) throw abortError();
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
function abortError(): Error {
|
|
513
|
-
const error = new Error("Verification harness was cancelled");
|
|
514
|
-
error.name = "AbortError";
|
|
515
|
-
return error;
|
|
516
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { DelegationContract } from "./delegation-contract.js";
|
|
2
|
-
|
|
3
|
-
export interface VerificationRiskInput {
|
|
4
|
-
contract?: DelegationContract;
|
|
5
|
-
integrationOwner: boolean;
|
|
6
|
-
requiredCapabilities: string[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface WorkflowVerificationTaskProjection {
|
|
10
|
-
id: string;
|
|
11
|
-
agent: string;
|
|
12
|
-
dependsOn?: readonly string[];
|
|
13
|
-
verifierFor?: string;
|
|
14
|
-
resultFormat?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function requiresIndependentVerification(input: VerificationRiskInput): boolean {
|
|
18
|
-
return (
|
|
19
|
-
input.contract?.admission?.verificationRequired === true ||
|
|
20
|
-
input.requiredCapabilities.some((capability) =>
|
|
21
|
-
["security-review", "security-implementation", "security-baseline"].includes(capability),
|
|
22
|
-
) ||
|
|
23
|
-
(input.integrationOwner && input.contract?.sideEffectPolicy !== "read-only")
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function validateWorkflowVerificationGraph(
|
|
28
|
-
tasks: readonly WorkflowVerificationTaskProjection[],
|
|
29
|
-
requiredTargetIds: ReadonlySet<string>,
|
|
30
|
-
): void {
|
|
31
|
-
const byId = new Map(tasks.map((task) => [task.id, task]));
|
|
32
|
-
const verifierByTarget = new Map<string, WorkflowVerificationTaskProjection[]>();
|
|
33
|
-
for (const task of tasks) {
|
|
34
|
-
if (!task.verifierFor) continue;
|
|
35
|
-
const target = byId.get(task.verifierFor);
|
|
36
|
-
if (!target) throw new Error(`Workflow verifier ${task.id} targets a missing task`);
|
|
37
|
-
if (target.verifierFor) {
|
|
38
|
-
throw new Error(`Workflow verifier ${task.id} cannot verify another verifier`);
|
|
39
|
-
}
|
|
40
|
-
if (target.resultFormat !== "structured-v2") {
|
|
41
|
-
throw new Error(`Workflow verification target ${target.id} must request structured-v2`);
|
|
42
|
-
}
|
|
43
|
-
if (task.dependsOn?.length !== 1 || task.dependsOn[0] !== target.id) {
|
|
44
|
-
throw new Error(`Workflow verifier ${task.id} must depend directly and only on ${target.id}`);
|
|
45
|
-
}
|
|
46
|
-
if (task.agent === target.agent) {
|
|
47
|
-
throw new Error(`Workflow verifier ${task.id} must use a distinct agent`);
|
|
48
|
-
}
|
|
49
|
-
if (task.resultFormat !== "structured-v2") {
|
|
50
|
-
throw new Error(`Workflow verifier ${task.id} must request structured-v2`);
|
|
51
|
-
}
|
|
52
|
-
const entries = verifierByTarget.get(target.id) ?? [];
|
|
53
|
-
entries.push(task);
|
|
54
|
-
verifierByTarget.set(target.id, entries);
|
|
55
|
-
}
|
|
56
|
-
for (const targetId of requiredTargetIds) {
|
|
57
|
-
const verifiers = verifierByTarget.get(targetId) ?? [];
|
|
58
|
-
if (verifiers.length !== 1) {
|
|
59
|
-
throw new Error(`Workflow task ${targetId} requires exactly one independent verifier`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
for (const [targetId, verifiers] of verifierByTarget) {
|
|
63
|
-
if (verifiers.length !== 1) {
|
|
64
|
-
throw new Error(`Workflow task ${targetId} must have exactly one verifier`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|