@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,275 +0,0 @@
|
|
|
1
|
-
import { type Static, Type } from "typebox";
|
|
2
|
-
import { Check } from "typebox/value";
|
|
3
|
-
import { redactPrivateText } from "./context.js";
|
|
4
|
-
import { truncateUtf8 } from "./limits.js";
|
|
5
|
-
import {
|
|
6
|
-
WORKFLOW_TREE_IDENTITY_VERSION,
|
|
7
|
-
type WorkflowTreeIdentity,
|
|
8
|
-
} from "./workflow-tree-identity.js";
|
|
9
|
-
|
|
10
|
-
export const VERIFICATION_RECEIPT_VERSION = "pi-subagents:verification-receipt:v1" as const;
|
|
11
|
-
export type VerificationReceiptDecision = "accept" | "rework" | "reject";
|
|
12
|
-
|
|
13
|
-
const MAX_FIELD_BYTES = 4 * 1024;
|
|
14
|
-
const MAX_OUTPUT_BYTES = 2 * 1024;
|
|
15
|
-
const MAX_RECEIPT_BYTES = 12 * 1024;
|
|
16
|
-
const MAX_LIST_ITEMS = 64;
|
|
17
|
-
const MAX_RECORD_ITEMS = 64;
|
|
18
|
-
const ID_PATTERN = "^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$";
|
|
19
|
-
const SHA_PATTERN = "^[a-f0-9]{64}$";
|
|
20
|
-
const REPOSITORY_GENERATION_PATTERN = "^[a-f0-9]{40,64}$";
|
|
21
|
-
|
|
22
|
-
const BoundedId = Type.String({ pattern: ID_PATTERN, maxLength: 256 });
|
|
23
|
-
const Sha256 = Type.String({ pattern: SHA_PATTERN, maxLength: 64 });
|
|
24
|
-
const BoundedText = Type.String({ minLength: 1, maxLength: MAX_FIELD_BYTES });
|
|
25
|
-
const TreeIdentitySchema = Type.Object(
|
|
26
|
-
{
|
|
27
|
-
version: Type.Literal(WORKFLOW_TREE_IDENTITY_VERSION),
|
|
28
|
-
kind: Type.Union([Type.Literal("git-commit"), Type.Literal("git-dirty")]),
|
|
29
|
-
digest: Sha256,
|
|
30
|
-
},
|
|
31
|
-
{ additionalProperties: false },
|
|
32
|
-
);
|
|
33
|
-
const StringRecordSchema = Type.Record(
|
|
34
|
-
Type.String({ minLength: 1, maxLength: 4096 }),
|
|
35
|
-
Type.String({ minLength: 1, maxLength: MAX_FIELD_BYTES }),
|
|
36
|
-
{ maxProperties: MAX_RECORD_ITEMS },
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
export const VerificationCheckReceiptSchema = Type.Object(
|
|
40
|
-
{
|
|
41
|
-
id: BoundedId,
|
|
42
|
-
command: Type.String({ minLength: 1, maxLength: 256 }),
|
|
43
|
-
args: Type.Array(Type.String({ maxLength: 4096 }), { maxItems: 64 }),
|
|
44
|
-
cwd: Type.String({ minLength: 1, maxLength: 4096 }),
|
|
45
|
-
status: Type.Union([Type.Literal("passed"), Type.Literal("failed")]),
|
|
46
|
-
exitCode: Type.Integer({ minimum: -1, maximum: 255 }),
|
|
47
|
-
stdout: Type.String({ maxLength: MAX_OUTPUT_BYTES }),
|
|
48
|
-
stderr: Type.String({ maxLength: MAX_OUTPUT_BYTES }),
|
|
49
|
-
durationMs: Type.Integer({ minimum: 0 }),
|
|
50
|
-
truncated: Type.Boolean(),
|
|
51
|
-
},
|
|
52
|
-
{ additionalProperties: false },
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
export const VerificationReceiptSchema = Type.Object(
|
|
56
|
-
{
|
|
57
|
-
version: Type.Literal(VERIFICATION_RECEIPT_VERSION),
|
|
58
|
-
decision: Type.Union([Type.Literal("accept"), Type.Literal("rework"), Type.Literal("reject")]),
|
|
59
|
-
targetTaskId: BoundedId,
|
|
60
|
-
targetTaskGeneration: Type.Integer({ minimum: 1 }),
|
|
61
|
-
targetExecutionPlanId: Sha256,
|
|
62
|
-
verifierTaskId: BoundedId,
|
|
63
|
-
verifierTaskGeneration: Type.Integer({ minimum: 1 }),
|
|
64
|
-
verifierExecutionPlanId: Sha256,
|
|
65
|
-
verifierAgent: BoundedId,
|
|
66
|
-
beforeTreeIdentity: TreeIdentitySchema,
|
|
67
|
-
afterTreeIdentity: TreeIdentitySchema,
|
|
68
|
-
baseRepositoryGeneration: Type.String({
|
|
69
|
-
pattern: REPOSITORY_GENERATION_PATTERN,
|
|
70
|
-
maxLength: 64,
|
|
71
|
-
}),
|
|
72
|
-
patchDigest: Sha256,
|
|
73
|
-
changedPaths: Type.Array(Type.String({ minLength: 1, maxLength: 4096 }), {
|
|
74
|
-
maxItems: MAX_LIST_ITEMS,
|
|
75
|
-
}),
|
|
76
|
-
allowedScopes: Type.Array(Type.String({ minLength: 1, maxLength: 4096 }), {
|
|
77
|
-
minItems: 1,
|
|
78
|
-
maxItems: MAX_LIST_ITEMS,
|
|
79
|
-
}),
|
|
80
|
-
dependencyVersions: StringRecordSchema,
|
|
81
|
-
readSetVersions: StringRecordSchema,
|
|
82
|
-
acceptanceCriteria: Type.Array(BoundedText, { maxItems: MAX_LIST_ITEMS }),
|
|
83
|
-
requiredEvidenceIds: Type.Array(BoundedId, { maxItems: MAX_LIST_ITEMS }),
|
|
84
|
-
evidence: StringRecordSchema,
|
|
85
|
-
checks: Type.Array(VerificationCheckReceiptSchema, { maxItems: 32 }),
|
|
86
|
-
summary: BoundedText,
|
|
87
|
-
findings: Type.Array(BoundedText, { maxItems: MAX_LIST_ITEMS }),
|
|
88
|
-
createdAt: Type.Number({ minimum: 0 }),
|
|
89
|
-
sourceTruncated: Type.Boolean(),
|
|
90
|
-
},
|
|
91
|
-
{ additionalProperties: false },
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
export type VerificationCheckReceipt = Static<typeof VerificationCheckReceiptSchema>;
|
|
95
|
-
export type VerificationReceipt = Static<typeof VerificationReceiptSchema>;
|
|
96
|
-
export type CreateVerificationReceiptInput = Omit<VerificationReceipt, "version">;
|
|
97
|
-
|
|
98
|
-
export function createVerificationReceipt(
|
|
99
|
-
input: CreateVerificationReceiptInput,
|
|
100
|
-
): VerificationReceipt {
|
|
101
|
-
const receipt: VerificationReceipt = {
|
|
102
|
-
version: VERIFICATION_RECEIPT_VERSION,
|
|
103
|
-
decision: input.decision,
|
|
104
|
-
targetTaskId: input.targetTaskId,
|
|
105
|
-
targetTaskGeneration: input.targetTaskGeneration,
|
|
106
|
-
targetExecutionPlanId: input.targetExecutionPlanId,
|
|
107
|
-
verifierTaskId: input.verifierTaskId,
|
|
108
|
-
verifierTaskGeneration: input.verifierTaskGeneration,
|
|
109
|
-
verifierExecutionPlanId: input.verifierExecutionPlanId,
|
|
110
|
-
verifierAgent: input.verifierAgent,
|
|
111
|
-
beforeTreeIdentity: structuredClone(input.beforeTreeIdentity),
|
|
112
|
-
afterTreeIdentity: structuredClone(input.afterTreeIdentity),
|
|
113
|
-
baseRepositoryGeneration: input.baseRepositoryGeneration,
|
|
114
|
-
patchDigest: input.patchDigest,
|
|
115
|
-
changedPaths: boundList(input.changedPaths, MAX_FIELD_BYTES),
|
|
116
|
-
allowedScopes: boundList(input.allowedScopes, MAX_FIELD_BYTES),
|
|
117
|
-
dependencyVersions: boundRecord(input.dependencyVersions),
|
|
118
|
-
readSetVersions: boundRecord(input.readSetVersions),
|
|
119
|
-
acceptanceCriteria: boundList(input.acceptanceCriteria, MAX_FIELD_BYTES),
|
|
120
|
-
requiredEvidenceIds: boundList(input.requiredEvidenceIds, 256),
|
|
121
|
-
evidence: boundRecord(input.evidence),
|
|
122
|
-
checks: input.checks.slice(0, 32).map(boundCheck),
|
|
123
|
-
summary: boundRequired(input.summary, MAX_FIELD_BYTES, "summary"),
|
|
124
|
-
findings: boundList(input.findings, MAX_FIELD_BYTES),
|
|
125
|
-
createdAt: input.createdAt,
|
|
126
|
-
sourceTruncated:
|
|
127
|
-
input.sourceTruncated ||
|
|
128
|
-
input.checks.length > 32 ||
|
|
129
|
-
input.checks.some(
|
|
130
|
-
(check) =>
|
|
131
|
-
check.truncated ||
|
|
132
|
-
check.args.length > 64 ||
|
|
133
|
-
check.args.some((value) => Buffer.byteLength(value, "utf8") > 4096) ||
|
|
134
|
-
Buffer.byteLength(check.stdout, "utf8") > MAX_OUTPUT_BYTES ||
|
|
135
|
-
Buffer.byteLength(check.stderr, "utf8") > MAX_OUTPUT_BYTES,
|
|
136
|
-
) ||
|
|
137
|
-
input.requiredEvidenceIds.some((value) => Buffer.byteLength(value, "utf8") > 256) ||
|
|
138
|
-
[
|
|
139
|
-
input.changedPaths,
|
|
140
|
-
input.allowedScopes,
|
|
141
|
-
input.acceptanceCriteria,
|
|
142
|
-
input.requiredEvidenceIds,
|
|
143
|
-
input.findings,
|
|
144
|
-
].some(
|
|
145
|
-
(values) =>
|
|
146
|
-
values.length > MAX_LIST_ITEMS ||
|
|
147
|
-
values.some((value) => Buffer.byteLength(value, "utf8") > MAX_FIELD_BYTES),
|
|
148
|
-
) ||
|
|
149
|
-
[input.dependencyVersions, input.readSetVersions, input.evidence].some(
|
|
150
|
-
(value) =>
|
|
151
|
-
Object.keys(value).length > MAX_RECORD_ITEMS ||
|
|
152
|
-
Object.entries(value).some(
|
|
153
|
-
([key, item]) =>
|
|
154
|
-
Buffer.byteLength(key, "utf8") > 4096 ||
|
|
155
|
-
Buffer.byteLength(item, "utf8") > MAX_FIELD_BYTES,
|
|
156
|
-
),
|
|
157
|
-
),
|
|
158
|
-
};
|
|
159
|
-
assertReceiptSemantics(receipt);
|
|
160
|
-
if (!Check(VerificationReceiptSchema, receipt)) {
|
|
161
|
-
throw new Error("Verification receipt contains invalid executor metadata");
|
|
162
|
-
}
|
|
163
|
-
if (Buffer.byteLength(JSON.stringify(receipt), "utf8") > MAX_RECEIPT_BYTES) {
|
|
164
|
-
throw new Error("Verification receipt exceeded its total size limit");
|
|
165
|
-
}
|
|
166
|
-
return receipt;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function isVerificationReceipt(value: unknown): value is VerificationReceipt {
|
|
170
|
-
if (
|
|
171
|
-
!Check(VerificationReceiptSchema, value) ||
|
|
172
|
-
Buffer.byteLength(JSON.stringify(value), "utf8") > MAX_RECEIPT_BYTES
|
|
173
|
-
) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
assertReceiptSemantics(value as VerificationReceipt);
|
|
178
|
-
return true;
|
|
179
|
-
} catch {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function assertReceiptSemantics(receipt: VerificationReceipt): void {
|
|
185
|
-
if (
|
|
186
|
-
receipt.beforeTreeIdentity.kind !== receipt.afterTreeIdentity.kind ||
|
|
187
|
-
receipt.beforeTreeIdentity.digest !== receipt.afterTreeIdentity.digest
|
|
188
|
-
) {
|
|
189
|
-
throw new Error("Verification receipt rejected submitted-state drift");
|
|
190
|
-
}
|
|
191
|
-
const missingEvidence = receipt.requiredEvidenceIds.filter((id) => !receipt.evidence[id]);
|
|
192
|
-
if (receipt.decision === "accept" && missingEvidence.length > 0) {
|
|
193
|
-
throw new Error(
|
|
194
|
-
`Verification receipt is missing required evidence: ${missingEvidence.join(", ")}`,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
if (receipt.decision === "accept" && receipt.checks.some((check) => check.status !== "passed")) {
|
|
198
|
-
throw new Error("Verification receipt cannot accept a failed check");
|
|
199
|
-
}
|
|
200
|
-
if (receipt.decision === "rework" && receipt.findings.length === 0) {
|
|
201
|
-
throw new Error("Verification receipt rework requires a concrete finding");
|
|
202
|
-
}
|
|
203
|
-
if (receipt.decision === "reject" && receipt.findings.length === 0) {
|
|
204
|
-
throw new Error("Verification receipt reject requires a concrete finding");
|
|
205
|
-
}
|
|
206
|
-
for (const values of [
|
|
207
|
-
receipt.changedPaths,
|
|
208
|
-
receipt.allowedScopes,
|
|
209
|
-
receipt.acceptanceCriteria,
|
|
210
|
-
receipt.requiredEvidenceIds,
|
|
211
|
-
receipt.findings,
|
|
212
|
-
]) {
|
|
213
|
-
if (new Set(values).size !== values.length) {
|
|
214
|
-
throw new Error("Verification receipt contains duplicate bounded values");
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (new Set(receipt.checks.map((check) => check.id)).size !== receipt.checks.length) {
|
|
218
|
-
throw new Error("Verification receipt contains duplicate check ids");
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function boundCheck(check: VerificationCheckReceipt): VerificationCheckReceipt {
|
|
223
|
-
const stdout = boundOptional(check.stdout, MAX_OUTPUT_BYTES);
|
|
224
|
-
const stderr = boundOptional(check.stderr, MAX_OUTPUT_BYTES);
|
|
225
|
-
return {
|
|
226
|
-
id: boundRequired(check.id, 256, "check id"),
|
|
227
|
-
command: boundRequired(check.command, 256, "check command"),
|
|
228
|
-
args: check.args.slice(0, 64).map((value) => boundOptional(value, 4096).value),
|
|
229
|
-
cwd: boundRequired(check.cwd, 4096, "check cwd"),
|
|
230
|
-
status: check.status,
|
|
231
|
-
exitCode: check.exitCode,
|
|
232
|
-
stdout: stdout.value,
|
|
233
|
-
stderr: stderr.value,
|
|
234
|
-
durationMs: Math.max(0, Math.floor(check.durationMs)),
|
|
235
|
-
truncated: check.truncated || stdout.truncated || stderr.truncated || check.args.length > 64,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function boundList(values: readonly string[], maxItemBytes: number): string[] {
|
|
240
|
-
const result: string[] = [];
|
|
241
|
-
const seen = new Set<string>();
|
|
242
|
-
for (const value of values.slice(0, MAX_LIST_ITEMS)) {
|
|
243
|
-
const bounded = boundOptional(value, maxItemBytes).value;
|
|
244
|
-
if (!bounded || seen.has(bounded)) continue;
|
|
245
|
-
seen.add(bounded);
|
|
246
|
-
result.push(bounded);
|
|
247
|
-
}
|
|
248
|
-
return result;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function boundRecord(value: Record<string, string>): Record<string, string> {
|
|
252
|
-
const entries = Object.entries(value).slice(0, MAX_RECORD_ITEMS);
|
|
253
|
-
return Object.fromEntries(
|
|
254
|
-
entries.map(([key, item]) => [
|
|
255
|
-
boundRequired(key, 4096, "record key"),
|
|
256
|
-
boundRequired(item, MAX_FIELD_BYTES, "record value"),
|
|
257
|
-
]),
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function boundRequired(value: string, maxBytes: number, label: string): string {
|
|
262
|
-
const bounded = boundOptional(value, maxBytes).value;
|
|
263
|
-
if (!bounded) throw new Error(`Verification receipt requires ${label}`);
|
|
264
|
-
return bounded;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function boundOptional(value: string, maxBytes: number): { value: string; truncated: boolean } {
|
|
268
|
-
const redacted = redactPrivateText(value).trim();
|
|
269
|
-
const bounded = truncateUtf8(redacted, maxBytes);
|
|
270
|
-
return { value: bounded.text, truncated: bounded.truncated };
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export function sameReceiptTree(left: WorkflowTreeIdentity, right: WorkflowTreeIdentity): boolean {
|
|
274
|
-
return left.kind === right.kind && left.digest === right.digest;
|
|
275
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
export const VERIFIED_EXECUTION_BENCHMARK_VERSION =
|
|
2
|
-
"pi-subagents:verified-execution-benchmark:v1" as const;
|
|
3
|
-
|
|
4
|
-
export interface VerifiedExecutionBenchmarkCase {
|
|
5
|
-
id: string;
|
|
6
|
-
shouldAccept: boolean;
|
|
7
|
-
workerSelfReport: boolean;
|
|
8
|
-
independentVerifier: boolean;
|
|
9
|
-
exactTreeVerification: boolean;
|
|
10
|
-
workerCostUnits: number;
|
|
11
|
-
verifierCostUnits: number;
|
|
12
|
-
deterministicCostUnits: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface VerifiedExecutionBenchmarkArmResult {
|
|
16
|
-
arm: "worker-self-report" | "independent-verifier" | "deterministic-exact-tree";
|
|
17
|
-
falseAcceptances: number;
|
|
18
|
-
falseRejections: number;
|
|
19
|
-
accepted: number;
|
|
20
|
-
costUnits: number;
|
|
21
|
-
addedCostUnits: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface VerifiedExecutionBenchmarkResult {
|
|
25
|
-
version: typeof VERIFIED_EXECUTION_BENCHMARK_VERSION;
|
|
26
|
-
matchedCases: number;
|
|
27
|
-
arms: VerifiedExecutionBenchmarkArmResult[];
|
|
28
|
-
qualityClaim: false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function evaluateVerifiedExecutionBenchmark(
|
|
32
|
-
cases: readonly VerifiedExecutionBenchmarkCase[],
|
|
33
|
-
): VerifiedExecutionBenchmarkResult {
|
|
34
|
-
if (cases.length < 1 || new Set(cases.map((item) => item.id)).size !== cases.length) {
|
|
35
|
-
throw new Error("Verified execution benchmark requires unique matched cases");
|
|
36
|
-
}
|
|
37
|
-
for (const item of cases) {
|
|
38
|
-
if (
|
|
39
|
-
!item.id ||
|
|
40
|
-
[item.workerCostUnits, item.verifierCostUnits, item.deterministicCostUnits].some(
|
|
41
|
-
(value) => !Number.isFinite(value) || value < 0,
|
|
42
|
-
)
|
|
43
|
-
) {
|
|
44
|
-
throw new Error("Verified execution benchmark contains invalid bounded cost evidence");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const baselineCost = cases.reduce((sum, item) => sum + item.workerCostUnits, 0);
|
|
48
|
-
const arm = (
|
|
49
|
-
name: VerifiedExecutionBenchmarkArmResult["arm"],
|
|
50
|
-
accepted: (item: VerifiedExecutionBenchmarkCase) => boolean,
|
|
51
|
-
cost: (item: VerifiedExecutionBenchmarkCase) => number,
|
|
52
|
-
): VerifiedExecutionBenchmarkArmResult => {
|
|
53
|
-
const acceptedCases = cases.filter(accepted);
|
|
54
|
-
const costUnits = cases.reduce((sum, item) => sum + cost(item), 0);
|
|
55
|
-
return {
|
|
56
|
-
arm: name,
|
|
57
|
-
falseAcceptances: acceptedCases.filter((item) => !item.shouldAccept).length,
|
|
58
|
-
falseRejections: cases.filter((item) => item.shouldAccept && !accepted(item)).length,
|
|
59
|
-
accepted: acceptedCases.length,
|
|
60
|
-
costUnits,
|
|
61
|
-
addedCostUnits: costUnits - baselineCost,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
return {
|
|
65
|
-
version: VERIFIED_EXECUTION_BENCHMARK_VERSION,
|
|
66
|
-
matchedCases: cases.length,
|
|
67
|
-
arms: [
|
|
68
|
-
arm(
|
|
69
|
-
"worker-self-report",
|
|
70
|
-
(item) => item.workerSelfReport,
|
|
71
|
-
(item) => item.workerCostUnits,
|
|
72
|
-
),
|
|
73
|
-
arm(
|
|
74
|
-
"independent-verifier",
|
|
75
|
-
(item) => item.independentVerifier,
|
|
76
|
-
(item) => item.workerCostUnits + item.verifierCostUnits,
|
|
77
|
-
),
|
|
78
|
-
arm(
|
|
79
|
-
"deterministic-exact-tree",
|
|
80
|
-
(item) => item.exactTreeVerification,
|
|
81
|
-
(item) => item.workerCostUnits + item.verifierCostUnits + item.deterministicCostUnits,
|
|
82
|
-
),
|
|
83
|
-
],
|
|
84
|
-
qualityClaim: false,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { normalizeDelegationContract } from "./delegation-contract.js";
|
|
2
|
-
import {
|
|
3
|
-
type VerificationCheckRequest,
|
|
4
|
-
validateVerificationChecks,
|
|
5
|
-
} from "./verification-harness.js";
|
|
6
|
-
import type { VerifiedExecutionContract } from "./verified-execution-schema.js";
|
|
7
|
-
import type { ResolvedWorkflowTask } from "./workflow-planning.js";
|
|
8
|
-
|
|
9
|
-
export type { VerifiedExecutionContract } from "./verified-execution-schema.js";
|
|
10
|
-
export { VerifiedExecutionContractSchema } from "./verified-execution-schema.js";
|
|
11
|
-
|
|
12
|
-
export interface PreparedVerifiedWorkflow {
|
|
13
|
-
tasks: ResolvedWorkflowTask[];
|
|
14
|
-
targetTaskId: string;
|
|
15
|
-
verifierTaskId: string;
|
|
16
|
-
maxReworkCycles: 0 | 1;
|
|
17
|
-
checks: VerificationCheckRequest[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function prepareVerifiedWorkflow(
|
|
21
|
-
inputTasks: readonly ResolvedWorkflowTask[],
|
|
22
|
-
contract: VerifiedExecutionContract,
|
|
23
|
-
): PreparedVerifiedWorkflow {
|
|
24
|
-
const tasks = inputTasks.map((task) => structuredClone(task));
|
|
25
|
-
const primary = tasks.filter((task) => !task.verifierFor);
|
|
26
|
-
const mutating = primary.filter((task) => sideEffectPolicy(task) === "mutating");
|
|
27
|
-
if (mutating.length < 1) {
|
|
28
|
-
throw new Error("Verified execution requires at least one mutating workflow task");
|
|
29
|
-
}
|
|
30
|
-
if (mutating.length > 2) {
|
|
31
|
-
throw new Error("Verified execution permits at most two mutating workflow tasks");
|
|
32
|
-
}
|
|
33
|
-
const explicitOwners = primary.filter((task) => task.integrationOwner === true);
|
|
34
|
-
if (explicitOwners.length > 1)
|
|
35
|
-
throw new Error("Verified execution requires one integration owner");
|
|
36
|
-
const target = explicitOwners[0] ?? mutating.at(-1);
|
|
37
|
-
if (!target || sideEffectPolicy(target) === "read-only") {
|
|
38
|
-
throw new Error("Verified execution requires a mutating integration owner");
|
|
39
|
-
}
|
|
40
|
-
if (
|
|
41
|
-
mutating.some((task) => task.id !== target.id && !dependsTransitively(target, task.id, primary))
|
|
42
|
-
) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
"Verified execution integration owner must depend on every other mutating task",
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
target.integrationOwner = true;
|
|
48
|
-
target.resultFormat = "structured-v2";
|
|
49
|
-
if ((target.writePaths?.length ?? 0) === 0) {
|
|
50
|
-
throw new Error("Verified execution integration owner requires an explicit write scope");
|
|
51
|
-
}
|
|
52
|
-
const verifiers = tasks.filter((task) => task.verifierFor === target.id);
|
|
53
|
-
if (verifiers.length > 1) {
|
|
54
|
-
throw new Error(`Verified execution target ${target.id} has multiple verifiers`);
|
|
55
|
-
}
|
|
56
|
-
let verifier = verifiers[0];
|
|
57
|
-
if (!verifier) {
|
|
58
|
-
verifier = synthesizeVerifier(tasks, target, contract.verifierAgent);
|
|
59
|
-
tasks.push(verifier);
|
|
60
|
-
} else {
|
|
61
|
-
validateExplicitVerifier(verifier, target, contract.verifierAgent);
|
|
62
|
-
verifier = enforceVerifierAuthority(verifier, target);
|
|
63
|
-
const index = tasks.findIndex((task) => task.id === verifier?.id);
|
|
64
|
-
tasks[index] = verifier;
|
|
65
|
-
}
|
|
66
|
-
if (verifier.agent === target.agent) {
|
|
67
|
-
throw new Error("Verified execution requires a distinct verifier agent");
|
|
68
|
-
}
|
|
69
|
-
if (tasks.length > 64) throw new Error("Verified execution exceeded the workflow task limit");
|
|
70
|
-
validateVerificationChecks(contract.checks ?? []);
|
|
71
|
-
return {
|
|
72
|
-
tasks,
|
|
73
|
-
targetTaskId: target.id,
|
|
74
|
-
verifierTaskId: verifier.id,
|
|
75
|
-
maxReworkCycles: contract.maxReworkCycles === 0 ? 0 : 1,
|
|
76
|
-
checks: (contract.checks ?? []).map((check) => ({
|
|
77
|
-
id: check.id,
|
|
78
|
-
command: check.command,
|
|
79
|
-
...(check.args ? { args: [...check.args] } : {}),
|
|
80
|
-
...(check.cwd ? { cwd: check.cwd } : {}),
|
|
81
|
-
...(check.timeoutMs ? { timeoutMs: check.timeoutMs } : {}),
|
|
82
|
-
})),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function synthesizeVerifier(
|
|
87
|
-
tasks: readonly ResolvedWorkflowTask[],
|
|
88
|
-
target: ResolvedWorkflowTask,
|
|
89
|
-
agent: string,
|
|
90
|
-
): ResolvedWorkflowTask {
|
|
91
|
-
if (agent === target.agent)
|
|
92
|
-
throw new Error("Verified execution requires a distinct verifier agent");
|
|
93
|
-
let id = `verify-${target.id}`;
|
|
94
|
-
for (let suffix = 2; tasks.some((task) => task.id === id); suffix++) {
|
|
95
|
-
id = `verify-${target.id}-${suffix}`;
|
|
96
|
-
}
|
|
97
|
-
return enforceVerifierAuthority(
|
|
98
|
-
{
|
|
99
|
-
id,
|
|
100
|
-
agent,
|
|
101
|
-
task: `Independently verify ${target.id} against its original objective, acceptance criteria, required evidence, deterministic check receipts, and exact submitted state.`,
|
|
102
|
-
dependsOn: [target.id],
|
|
103
|
-
verifierFor: target.id,
|
|
104
|
-
resultFormat: "structured-v2",
|
|
105
|
-
},
|
|
106
|
-
target,
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function validateExplicitVerifier(
|
|
111
|
-
verifier: ResolvedWorkflowTask,
|
|
112
|
-
target: ResolvedWorkflowTask,
|
|
113
|
-
configuredAgent: string,
|
|
114
|
-
): void {
|
|
115
|
-
if (verifier.agent !== configuredAgent) {
|
|
116
|
-
throw new Error("Verified execution verifier does not match verifierAgent");
|
|
117
|
-
}
|
|
118
|
-
if (verifier.agent === target.agent) {
|
|
119
|
-
throw new Error("Verified execution requires a distinct verifier agent");
|
|
120
|
-
}
|
|
121
|
-
if (verifier.dependsOn?.length !== 1 || verifier.dependsOn[0] !== target.id) {
|
|
122
|
-
throw new Error("Verified execution verifier must depend directly and only on its target");
|
|
123
|
-
}
|
|
124
|
-
if (verifier.resultFormat !== "structured-v2") {
|
|
125
|
-
throw new Error("Verified execution verifier requires structured-v2");
|
|
126
|
-
}
|
|
127
|
-
const delegation = normalizeDelegationContract(verifier.contract);
|
|
128
|
-
if (delegation?.sideEffectPolicy !== "read-only") {
|
|
129
|
-
throw new Error("Verified execution rejects mutable verifier authority");
|
|
130
|
-
}
|
|
131
|
-
const requestedTools = delegation.requestedAuthority?.tools ?? [];
|
|
132
|
-
if (requestedTools.some((tool) => !["read", "grep", "find", "ls"].includes(tool))) {
|
|
133
|
-
throw new Error("Verified execution rejects verifier shell or custom tool authority");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function enforceVerifierAuthority(
|
|
138
|
-
verifier: ResolvedWorkflowTask,
|
|
139
|
-
target: ResolvedWorkflowTask,
|
|
140
|
-
): ResolvedWorkflowTask {
|
|
141
|
-
return {
|
|
142
|
-
...verifier,
|
|
143
|
-
cwd: target.cwd,
|
|
144
|
-
dependsOn: [target.id],
|
|
145
|
-
verifierFor: target.id,
|
|
146
|
-
integrationOwner: false,
|
|
147
|
-
resultFormat: "structured-v2",
|
|
148
|
-
requiredTools: ["read"],
|
|
149
|
-
writePaths: [],
|
|
150
|
-
readPaths: unique([...(target.readPaths ?? []), ...(target.writePaths ?? [])]),
|
|
151
|
-
contract: {
|
|
152
|
-
version: "pi-subagents:delegation:v2",
|
|
153
|
-
level: "full",
|
|
154
|
-
taskId: verifier.id,
|
|
155
|
-
objective: verifier.task,
|
|
156
|
-
dependencies: [{ taskId: target.id }],
|
|
157
|
-
requiredInputs: [],
|
|
158
|
-
requestedAuthority: {
|
|
159
|
-
tools: ["read"],
|
|
160
|
-
},
|
|
161
|
-
acceptanceCriteria: [...(target.acceptanceCriteria ?? [])],
|
|
162
|
-
requiredEvidence: normalizeDelegationContract(target.contract)?.requiredEvidence ?? [],
|
|
163
|
-
sideEffectPolicy: "read-only",
|
|
164
|
-
enforcement: "enforce",
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function sideEffectPolicy(task: ResolvedWorkflowTask): "read-only" | "idempotent" | "mutating" {
|
|
170
|
-
return normalizeDelegationContract(task.contract)?.sideEffectPolicy ?? "mutating";
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function dependsTransitively(
|
|
174
|
-
task: ResolvedWorkflowTask,
|
|
175
|
-
targetId: string,
|
|
176
|
-
tasks: readonly ResolvedWorkflowTask[],
|
|
177
|
-
seen = new Set<string>(),
|
|
178
|
-
): boolean {
|
|
179
|
-
if (seen.has(task.id)) return false;
|
|
180
|
-
seen.add(task.id);
|
|
181
|
-
const dependencies = task.dependsOn ?? [];
|
|
182
|
-
if (dependencies.includes(targetId)) return true;
|
|
183
|
-
return dependencies.some((id) => {
|
|
184
|
-
const dependency = tasks.find((candidate) => candidate.id === id);
|
|
185
|
-
return dependency ? dependsTransitively(dependency, targetId, tasks, seen) : false;
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function unique(values: readonly string[]): string[] {
|
|
190
|
-
return [...new Set(values)];
|
|
191
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
|
-
import { type Static, Type } from "typebox";
|
|
3
|
-
|
|
4
|
-
const VerificationCheckSchema = Type.Object(
|
|
5
|
-
{
|
|
6
|
-
id: Type.String({
|
|
7
|
-
minLength: 1,
|
|
8
|
-
maxLength: 256,
|
|
9
|
-
pattern: "^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$",
|
|
10
|
-
}),
|
|
11
|
-
command: StringEnum(["git", "node", "npm", "npx"] as const),
|
|
12
|
-
args: Type.Optional(Type.Array(Type.String({ maxLength: 4096 }), { maxItems: 64 })),
|
|
13
|
-
cwd: Type.Optional(Type.String({ minLength: 1, maxLength: 4096 })),
|
|
14
|
-
timeoutMs: Type.Optional(Type.Integer({ minimum: 1, maximum: 600_000 })),
|
|
15
|
-
},
|
|
16
|
-
{ additionalProperties: false },
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export const VerifiedExecutionContractSchema = Type.Object(
|
|
20
|
-
{
|
|
21
|
-
verifierAgent: Type.String({ minLength: 1, maxLength: 256 }),
|
|
22
|
-
maxReworkCycles: Type.Optional(Type.Integer({ minimum: 0, maximum: 1, default: 1 })),
|
|
23
|
-
checks: Type.Optional(Type.Array(VerificationCheckSchema, { maxItems: 32 })),
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
additionalProperties: false,
|
|
27
|
-
description:
|
|
28
|
-
"Explicitly gate mutating workflow success on executor-owned deterministic checks, one least-authority independent verifier, exact submitted-state identity, and managed integration acceptance.",
|
|
29
|
-
},
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
export type VerifiedExecutionContract = Static<typeof VerifiedExecutionContractSchema>;
|