@narumitw/pi-subagents 2.1.3 → 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 +181 -1250
- 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 -1598
- 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 -153
- package/docs/pi-subagents-diagrams.md +0 -183
- package/src/adaptive-scheduler.ts +0 -224
- package/src/admission-benchmark.ts +0 -95
- 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/async-subagent-benchmark.ts +0 -532
- 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 -355
- 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,296 +0,0 @@
|
|
|
1
|
-
import { redactPrivateText } from "./context.js";
|
|
2
|
-
import { truncateUtf8 } from "./limits.js";
|
|
3
|
-
import type { StructuredSubagentResultV2 } from "./result-contract.js";
|
|
4
|
-
import { isWorkflowTreeIdentity, type WorkflowTreeIdentity } from "./workflow-tree-identity.js";
|
|
5
|
-
|
|
6
|
-
export const WORKFLOW_VERIFICATION_VERSION = "pi-subagents:workflow-verification:v1" as const;
|
|
7
|
-
export type WorkflowVerificationDecision = "accept" | "rework" | "reject";
|
|
8
|
-
const MAX_FIELD_BYTES = 2 * 1024;
|
|
9
|
-
const MAX_ITEMS = 32;
|
|
10
|
-
const MAX_EVIDENCE_BYTES = 6 * 1024;
|
|
11
|
-
const MAX_LIMITATION_BYTES = 4 * 1024;
|
|
12
|
-
const MAX_INSTRUCTION_LIST_BYTES = 8 * 1024;
|
|
13
|
-
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u;
|
|
14
|
-
const PLAN_PATTERN = /^[a-f0-9]{64}$/u;
|
|
15
|
-
|
|
16
|
-
export interface WorkflowVerificationReceipt {
|
|
17
|
-
version: typeof WORKFLOW_VERIFICATION_VERSION;
|
|
18
|
-
decision: WorkflowVerificationDecision;
|
|
19
|
-
targetTaskId: string;
|
|
20
|
-
targetTaskGeneration: number;
|
|
21
|
-
targetExecutionPlanId: string;
|
|
22
|
-
verifierTaskId: string;
|
|
23
|
-
verifierTaskGeneration: number;
|
|
24
|
-
verifierExecutionPlanId: string;
|
|
25
|
-
treeIdentity: WorkflowTreeIdentity;
|
|
26
|
-
summary: string;
|
|
27
|
-
evidence: string[];
|
|
28
|
-
limitations: string[];
|
|
29
|
-
createdAt: number;
|
|
30
|
-
truncated: boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface WorkflowVerificationContext {
|
|
34
|
-
targetTaskId: string;
|
|
35
|
-
targetTaskGeneration: number;
|
|
36
|
-
targetExecutionPlanId: string;
|
|
37
|
-
verifierTaskId: string;
|
|
38
|
-
verifierTaskGeneration: number;
|
|
39
|
-
verifierExecutionPlanId: string;
|
|
40
|
-
treeIdentity: WorkflowTreeIdentity;
|
|
41
|
-
createdAt?: number;
|
|
42
|
-
sourceTruncated?: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function createWorkflowVerificationReceipt(
|
|
46
|
-
result: StructuredSubagentResultV2,
|
|
47
|
-
context: WorkflowVerificationContext,
|
|
48
|
-
): WorkflowVerificationReceipt {
|
|
49
|
-
validateContext(context);
|
|
50
|
-
const decision = verdict(result);
|
|
51
|
-
const boundedSummary = bound(result.summary);
|
|
52
|
-
if (!boundedSummary.value) throw new Error("Workflow verification verdict requires a summary");
|
|
53
|
-
const evidenceSource = [
|
|
54
|
-
...result.claims.flatMap((claim) => claim.evidence),
|
|
55
|
-
...result.verification.flatMap((item) => [item.summary, ...(item.evidence ?? [])]),
|
|
56
|
-
];
|
|
57
|
-
const evidence = boundList(evidenceSource, MAX_EVIDENCE_BYTES);
|
|
58
|
-
const limitations = boundList(
|
|
59
|
-
[...result.limitations, ...result.unresolvedDependencies],
|
|
60
|
-
MAX_LIMITATION_BYTES,
|
|
61
|
-
);
|
|
62
|
-
if (decision === "rework" && limitations.values.length === 0) {
|
|
63
|
-
throw new Error("Workflow verification rework requires a limitation or unresolved dependency");
|
|
64
|
-
}
|
|
65
|
-
if (decision === "reject" && evidence.values.length === 0) {
|
|
66
|
-
throw new Error("Workflow verification reject requires evidence");
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
version: WORKFLOW_VERIFICATION_VERSION,
|
|
70
|
-
decision,
|
|
71
|
-
targetTaskId: context.targetTaskId,
|
|
72
|
-
targetTaskGeneration: context.targetTaskGeneration,
|
|
73
|
-
targetExecutionPlanId: context.targetExecutionPlanId,
|
|
74
|
-
verifierTaskId: context.verifierTaskId,
|
|
75
|
-
verifierTaskGeneration: context.verifierTaskGeneration,
|
|
76
|
-
verifierExecutionPlanId: context.verifierExecutionPlanId,
|
|
77
|
-
treeIdentity: structuredClone(context.treeIdentity),
|
|
78
|
-
summary: boundedSummary.value,
|
|
79
|
-
evidence: evidence.values,
|
|
80
|
-
limitations: limitations.values,
|
|
81
|
-
createdAt: context.createdAt ?? Date.now(),
|
|
82
|
-
truncated:
|
|
83
|
-
context.sourceTruncated === true ||
|
|
84
|
-
boundedSummary.truncated ||
|
|
85
|
-
evidence.truncated ||
|
|
86
|
-
limitations.truncated,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function workflowVerificationInstruction(
|
|
91
|
-
targetTaskId: string,
|
|
92
|
-
treeIdentity: WorkflowTreeIdentity,
|
|
93
|
-
requirements: {
|
|
94
|
-
acceptanceCriteria?: readonly string[];
|
|
95
|
-
requiredEvidence?: readonly string[];
|
|
96
|
-
} = {},
|
|
97
|
-
): string {
|
|
98
|
-
if (!ID_PATTERN.test(targetTaskId) || !isWorkflowTreeIdentity(treeIdentity)) {
|
|
99
|
-
throw new Error("Workflow verification instruction received invalid executor metadata");
|
|
100
|
-
}
|
|
101
|
-
const acceptanceCriteria = boundList(
|
|
102
|
-
requirements.acceptanceCriteria ?? [],
|
|
103
|
-
MAX_INSTRUCTION_LIST_BYTES,
|
|
104
|
-
).values;
|
|
105
|
-
const requiredEvidence = boundList(
|
|
106
|
-
requirements.requiredEvidence ?? [],
|
|
107
|
-
MAX_INSTRUCTION_LIST_BYTES,
|
|
108
|
-
).values;
|
|
109
|
-
return [
|
|
110
|
-
"You are the independent verifier for one staged workflow result.",
|
|
111
|
-
`Target task: ${JSON.stringify(targetTaskId)}.`,
|
|
112
|
-
`Acceptance criteria: ${JSON.stringify(acceptanceCriteria)}.`,
|
|
113
|
-
`Required evidence: ${JSON.stringify(requiredEvidence)}.`,
|
|
114
|
-
`Exact Git-visible tree identity: ${treeIdentity.version}:${treeIdentity.kind}:${treeIdentity.digest}.`,
|
|
115
|
-
"Do not modify the repository; the executor will reject acceptance if the tree identity changes.",
|
|
116
|
-
"Return the requested pi-subagents:result:v2 object with exactly one verdict encoding.",
|
|
117
|
-
'Accept only with status "completed", reasonCode "verification-accepted", at least one passed verification item, no failed verification item, and no unresolved dependency.',
|
|
118
|
-
'Request rework only with status "partial" or "needs-input", reasonCode "verification-rework", and a concrete limitation or unresolved dependency.',
|
|
119
|
-
'Reject only with status "failed" or "abstained", reasonCode "verification-rejected", and concrete evidence.',
|
|
120
|
-
"Agreement, confidence, and the implementation worker's own verification claims are not proof.",
|
|
121
|
-
].join("\n");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function isWorkflowVerificationReceipt(
|
|
125
|
-
value: unknown,
|
|
126
|
-
): value is WorkflowVerificationReceipt {
|
|
127
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
128
|
-
const receipt = value as Partial<WorkflowVerificationReceipt>;
|
|
129
|
-
if (
|
|
130
|
-
Object.keys(value as Record<string, unknown>).some(
|
|
131
|
-
(key) =>
|
|
132
|
-
![
|
|
133
|
-
"version",
|
|
134
|
-
"decision",
|
|
135
|
-
"targetTaskId",
|
|
136
|
-
"targetTaskGeneration",
|
|
137
|
-
"targetExecutionPlanId",
|
|
138
|
-
"verifierTaskId",
|
|
139
|
-
"verifierTaskGeneration",
|
|
140
|
-
"verifierExecutionPlanId",
|
|
141
|
-
"treeIdentity",
|
|
142
|
-
"summary",
|
|
143
|
-
"evidence",
|
|
144
|
-
"limitations",
|
|
145
|
-
"createdAt",
|
|
146
|
-
"truncated",
|
|
147
|
-
].includes(key),
|
|
148
|
-
)
|
|
149
|
-
) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return (
|
|
153
|
-
receipt.version === WORKFLOW_VERIFICATION_VERSION &&
|
|
154
|
-
(receipt.decision !== "rework" ||
|
|
155
|
-
(Array.isArray(receipt.limitations) && receipt.limitations.length > 0)) &&
|
|
156
|
-
(receipt.decision !== "reject" ||
|
|
157
|
-
(Array.isArray(receipt.evidence) && receipt.evidence.length > 0)) &&
|
|
158
|
-
["accept", "rework", "reject"].includes(String(receipt.decision)) &&
|
|
159
|
-
typeof receipt.targetTaskId === "string" &&
|
|
160
|
-
ID_PATTERN.test(receipt.targetTaskId) &&
|
|
161
|
-
Number.isSafeInteger(receipt.targetTaskGeneration) &&
|
|
162
|
-
Number(receipt.targetTaskGeneration) >= 1 &&
|
|
163
|
-
typeof receipt.targetExecutionPlanId === "string" &&
|
|
164
|
-
PLAN_PATTERN.test(receipt.targetExecutionPlanId) &&
|
|
165
|
-
typeof receipt.verifierTaskId === "string" &&
|
|
166
|
-
ID_PATTERN.test(receipt.verifierTaskId) &&
|
|
167
|
-
Number.isSafeInteger(receipt.verifierTaskGeneration) &&
|
|
168
|
-
Number(receipt.verifierTaskGeneration) >= 1 &&
|
|
169
|
-
typeof receipt.verifierExecutionPlanId === "string" &&
|
|
170
|
-
PLAN_PATTERN.test(receipt.verifierExecutionPlanId) &&
|
|
171
|
-
isWorkflowTreeIdentity(receipt.treeIdentity) &&
|
|
172
|
-
typeof receipt.summary === "string" &&
|
|
173
|
-
receipt.summary.length > 0 &&
|
|
174
|
-
Buffer.byteLength(receipt.summary, "utf8") <= MAX_FIELD_BYTES &&
|
|
175
|
-
validStrings(receipt.evidence, MAX_EVIDENCE_BYTES) &&
|
|
176
|
-
validStrings(receipt.limitations, MAX_LIMITATION_BYTES) &&
|
|
177
|
-
typeof receipt.createdAt === "number" &&
|
|
178
|
-
Number.isFinite(receipt.createdAt) &&
|
|
179
|
-
receipt.createdAt >= 0 &&
|
|
180
|
-
typeof receipt.truncated === "boolean"
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function verdict(result: StructuredSubagentResultV2): WorkflowVerificationDecision {
|
|
185
|
-
if (result.version !== "pi-subagents:result:v2") {
|
|
186
|
-
throw new Error("Workflow verification requires structured-v2");
|
|
187
|
-
}
|
|
188
|
-
if (result.reasonCode === "verification-accepted" && result.status === "completed") {
|
|
189
|
-
if (result.verification.some((item) => item.status === "failed")) {
|
|
190
|
-
throw new Error("Workflow verification accept cannot contain failed evidence");
|
|
191
|
-
}
|
|
192
|
-
if (!result.verification.some((item) => item.status === "passed")) {
|
|
193
|
-
throw new Error("Workflow verification accept requires passed evidence");
|
|
194
|
-
}
|
|
195
|
-
if (result.unresolvedDependencies.length > 0) {
|
|
196
|
-
throw new Error("Workflow verification accept cannot contain unresolved dependencies");
|
|
197
|
-
}
|
|
198
|
-
return "accept";
|
|
199
|
-
}
|
|
200
|
-
if (
|
|
201
|
-
result.reasonCode === "verification-rework" &&
|
|
202
|
-
(result.status === "partial" || result.status === "needs-input")
|
|
203
|
-
) {
|
|
204
|
-
return "rework";
|
|
205
|
-
}
|
|
206
|
-
if (
|
|
207
|
-
result.reasonCode === "verification-rejected" &&
|
|
208
|
-
(result.status === "failed" || result.status === "abstained")
|
|
209
|
-
) {
|
|
210
|
-
return "reject";
|
|
211
|
-
}
|
|
212
|
-
throw new Error("Workflow verification result does not contain a valid verdict");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function validateContext(context: WorkflowVerificationContext): void {
|
|
216
|
-
for (const [label, value] of [
|
|
217
|
-
["target task", context.targetTaskId],
|
|
218
|
-
["verifier task", context.verifierTaskId],
|
|
219
|
-
] as const) {
|
|
220
|
-
if (!ID_PATTERN.test(value))
|
|
221
|
-
throw new Error(`Workflow verification has an invalid ${label} id`);
|
|
222
|
-
}
|
|
223
|
-
for (const [label, value] of [
|
|
224
|
-
["target", context.targetTaskGeneration],
|
|
225
|
-
["verifier", context.verifierTaskGeneration],
|
|
226
|
-
] as const) {
|
|
227
|
-
if (!Number.isSafeInteger(value) || value < 1) {
|
|
228
|
-
throw new Error(`Workflow verification has an invalid ${label} task generation`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
for (const value of [context.targetExecutionPlanId, context.verifierExecutionPlanId]) {
|
|
232
|
-
if (!PLAN_PATTERN.test(value)) {
|
|
233
|
-
throw new Error("Workflow verification has an invalid execution plan identity");
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if (!isWorkflowTreeIdentity(context.treeIdentity)) {
|
|
237
|
-
throw new Error("Workflow verification has an invalid tree identity");
|
|
238
|
-
}
|
|
239
|
-
if (context.sourceTruncated !== undefined && typeof context.sourceTruncated !== "boolean") {
|
|
240
|
-
throw new Error("Workflow verification has an invalid truncation state");
|
|
241
|
-
}
|
|
242
|
-
if (
|
|
243
|
-
context.createdAt !== undefined &&
|
|
244
|
-
(!Number.isFinite(context.createdAt) || context.createdAt < 0)
|
|
245
|
-
) {
|
|
246
|
-
throw new Error("Workflow verification has an invalid creation time");
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function bound(value: string): { value: string; truncated: boolean } {
|
|
251
|
-
const redacted = redactPrivateText(value).trim();
|
|
252
|
-
const truncated = truncateUtf8(redacted, MAX_FIELD_BYTES);
|
|
253
|
-
return { value: truncated.text, truncated: truncated.truncated };
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function boundList(
|
|
257
|
-
values: readonly string[],
|
|
258
|
-
maxTotalBytes: number,
|
|
259
|
-
): { values: string[]; truncated: boolean } {
|
|
260
|
-
let truncated = values.length > MAX_ITEMS;
|
|
261
|
-
let remaining = maxTotalBytes;
|
|
262
|
-
const result: string[] = [];
|
|
263
|
-
const seen = new Set<string>();
|
|
264
|
-
for (const raw of values.slice(0, MAX_ITEMS)) {
|
|
265
|
-
if (remaining < 1) {
|
|
266
|
-
truncated = true;
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
const redacted = redactPrivateText(raw).trim();
|
|
270
|
-
const item = truncateUtf8(redacted, Math.min(MAX_FIELD_BYTES, remaining));
|
|
271
|
-
truncated ||= item.truncated;
|
|
272
|
-
if (!item.text || seen.has(item.text)) continue;
|
|
273
|
-
seen.add(item.text);
|
|
274
|
-
result.push(item.text);
|
|
275
|
-
remaining -= Buffer.byteLength(item.text, "utf8");
|
|
276
|
-
}
|
|
277
|
-
return { values: result, truncated };
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function validStrings(value: unknown, maxTotalBytes: number): value is string[] {
|
|
281
|
-
return (
|
|
282
|
-
Array.isArray(value) &&
|
|
283
|
-
value.length <= MAX_ITEMS &&
|
|
284
|
-
value.reduce(
|
|
285
|
-
(total, item) =>
|
|
286
|
-
total + (typeof item === "string" ? Buffer.byteLength(item, "utf8") : maxTotalBytes + 1),
|
|
287
|
-
0,
|
|
288
|
-
) <= maxTotalBytes &&
|
|
289
|
-
value.every(
|
|
290
|
-
(item) =>
|
|
291
|
-
typeof item === "string" &&
|
|
292
|
-
item.length > 0 &&
|
|
293
|
-
Buffer.byteLength(item, "utf8") <= MAX_FIELD_BYTES,
|
|
294
|
-
)
|
|
295
|
-
);
|
|
296
|
-
}
|
package/src/workspace.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as os from "node:os";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
|
-
|
|
7
|
-
const execFileAsync = promisify(execFile);
|
|
8
|
-
const WORKTREE_PREFIX = "pi-subagent-worktree-";
|
|
9
|
-
|
|
10
|
-
export interface IsolatedWorkspace {
|
|
11
|
-
mode: "worktree";
|
|
12
|
-
path: string;
|
|
13
|
-
rootPath: string;
|
|
14
|
-
repositoryRoot: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function assertWorkspaceIsolationReady(cwd: string): Promise<void> {
|
|
18
|
-
await resolveWorkspaceBase(cwd);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class WorkspaceManager {
|
|
22
|
-
private readonly owned = new Map<string, IsolatedWorkspace>();
|
|
23
|
-
|
|
24
|
-
async create(ownerId: string, cwd: string): Promise<IsolatedWorkspace> {
|
|
25
|
-
if (this.owned.has(ownerId)) throw new Error(`Workspace owner already exists: ${ownerId}`);
|
|
26
|
-
const { repositoryRoot, relativeCwd } = await resolveWorkspaceBase(cwd);
|
|
27
|
-
const rootPath = await fs.promises.mkdtemp(path.join(os.tmpdir(), WORKTREE_PREFIX));
|
|
28
|
-
let registered = false;
|
|
29
|
-
try {
|
|
30
|
-
await execFileAsync("git", [
|
|
31
|
-
"-C",
|
|
32
|
-
repositoryRoot,
|
|
33
|
-
"worktree",
|
|
34
|
-
"add",
|
|
35
|
-
"--detach",
|
|
36
|
-
rootPath,
|
|
37
|
-
"HEAD",
|
|
38
|
-
]);
|
|
39
|
-
registered = true;
|
|
40
|
-
await fs.promises.writeFile(`${rootPath}.owner`, ownerId, { mode: 0o600 });
|
|
41
|
-
const workspace = {
|
|
42
|
-
mode: "worktree" as const,
|
|
43
|
-
path: path.join(rootPath, relativeCwd),
|
|
44
|
-
rootPath,
|
|
45
|
-
repositoryRoot,
|
|
46
|
-
};
|
|
47
|
-
this.owned.set(ownerId, workspace);
|
|
48
|
-
return workspace;
|
|
49
|
-
} catch (error) {
|
|
50
|
-
if (registered) {
|
|
51
|
-
await execFileAsync("git", [
|
|
52
|
-
"-C",
|
|
53
|
-
repositoryRoot,
|
|
54
|
-
"worktree",
|
|
55
|
-
"remove",
|
|
56
|
-
"--force",
|
|
57
|
-
rootPath,
|
|
58
|
-
]).catch(() => undefined);
|
|
59
|
-
}
|
|
60
|
-
await fs.promises.rm(rootPath, { recursive: true, force: true });
|
|
61
|
-
await fs.promises.rm(`${rootPath}.owner`, { force: true });
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async cleanupPersisted(ownerId: string, cwd: string): Promise<void> {
|
|
67
|
-
const rootPath = findGeneratedWorktreeRoot(cwd);
|
|
68
|
-
if (!rootPath || !(await this.isOwned(rootPath, ownerId))) return;
|
|
69
|
-
let repositoryRoot: string | undefined;
|
|
70
|
-
try {
|
|
71
|
-
const commonDirectory = (
|
|
72
|
-
await execFileAsync("git", ["-C", rootPath, "rev-parse", "--git-common-dir"])
|
|
73
|
-
).stdout.trim();
|
|
74
|
-
const resolvedCommonDirectory = await fs.promises.realpath(
|
|
75
|
-
path.resolve(rootPath, commonDirectory),
|
|
76
|
-
);
|
|
77
|
-
repositoryRoot = path.dirname(resolvedCommonDirectory);
|
|
78
|
-
} catch {
|
|
79
|
-
// The ownership marker still permits bounded filesystem cleanup below.
|
|
80
|
-
}
|
|
81
|
-
if (repositoryRoot) {
|
|
82
|
-
await execFileAsync("git", [
|
|
83
|
-
"-C",
|
|
84
|
-
repositoryRoot,
|
|
85
|
-
"worktree",
|
|
86
|
-
"remove",
|
|
87
|
-
"--force",
|
|
88
|
-
rootPath,
|
|
89
|
-
]).catch(() => undefined);
|
|
90
|
-
}
|
|
91
|
-
await fs.promises.rm(rootPath, { recursive: true, force: true });
|
|
92
|
-
await fs.promises.rm(`${rootPath}.owner`, { force: true });
|
|
93
|
-
if (repositoryRoot) {
|
|
94
|
-
await execFileAsync("git", ["-C", repositoryRoot, "worktree", "prune"]).catch(
|
|
95
|
-
() => undefined,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async cleanup(ownerId: string): Promise<void> {
|
|
101
|
-
const workspace = this.owned.get(ownerId);
|
|
102
|
-
if (!workspace) return;
|
|
103
|
-
if (!(await this.isOwned(workspace.rootPath, ownerId))) {
|
|
104
|
-
throw new Error(`Refusing to clean unowned subagent workspace: ${workspace.rootPath}`);
|
|
105
|
-
}
|
|
106
|
-
this.owned.delete(ownerId);
|
|
107
|
-
await execFileAsync("git", [
|
|
108
|
-
"-C",
|
|
109
|
-
workspace.repositoryRoot,
|
|
110
|
-
"worktree",
|
|
111
|
-
"remove",
|
|
112
|
-
"--force",
|
|
113
|
-
workspace.rootPath,
|
|
114
|
-
]).catch(async () => {
|
|
115
|
-
await fs.promises.rm(workspace.rootPath, { recursive: true, force: true });
|
|
116
|
-
await execFileAsync("git", ["-C", workspace.repositoryRoot, "worktree", "prune"]).catch(
|
|
117
|
-
() => undefined,
|
|
118
|
-
);
|
|
119
|
-
});
|
|
120
|
-
await fs.promises.rm(`${workspace.rootPath}.owner`, { force: true });
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async cleanupAll(): Promise<void> {
|
|
124
|
-
const results = await Promise.allSettled(
|
|
125
|
-
[...this.owned.keys()].map((ownerId) => this.cleanup(ownerId)),
|
|
126
|
-
);
|
|
127
|
-
const failures = results.filter((result) => result.status === "rejected");
|
|
128
|
-
if (failures.length > 0) {
|
|
129
|
-
throw new AggregateError(
|
|
130
|
-
failures.map((failure) => (failure as PromiseRejectedResult).reason),
|
|
131
|
-
`Failed to clean ${failures.length} subagent workspace(s)`,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
private async isOwned(rootPath: string, ownerId: string): Promise<boolean> {
|
|
137
|
-
if (!path.basename(rootPath).startsWith(WORKTREE_PREFIX)) return false;
|
|
138
|
-
try {
|
|
139
|
-
return (await fs.promises.readFile(`${rootPath}.owner`, "utf8")) === ownerId;
|
|
140
|
-
} catch {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async function resolveWorkspaceBase(
|
|
147
|
-
cwd: string,
|
|
148
|
-
): Promise<{ repositoryRoot: string; relativeCwd: string }> {
|
|
149
|
-
const resolvedCwd = await fs.promises.realpath(path.resolve(cwd));
|
|
150
|
-
const reportedRepositoryRoot = (
|
|
151
|
-
await execFileAsync("git", ["-C", resolvedCwd, "rev-parse", "--show-toplevel"])
|
|
152
|
-
).stdout.trim();
|
|
153
|
-
const repositoryRoot = await fs.promises.realpath(reportedRepositoryRoot);
|
|
154
|
-
const relativeCwd = path.relative(repositoryRoot, resolvedCwd);
|
|
155
|
-
if (relativeCwd.startsWith("..") || path.isAbsolute(relativeCwd)) {
|
|
156
|
-
throw new Error("Subagent cwd is outside the Git repository");
|
|
157
|
-
}
|
|
158
|
-
const status = (await execFileAsync("git", ["-C", repositoryRoot, "status", "--porcelain"]))
|
|
159
|
-
.stdout;
|
|
160
|
-
if (status.trim()) {
|
|
161
|
-
throw new Error("Isolated subagent workspace requires a clean Git repository");
|
|
162
|
-
}
|
|
163
|
-
return { repositoryRoot, relativeCwd };
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function findGeneratedWorktreeRoot(cwd: string): string | undefined {
|
|
167
|
-
let current = path.resolve(cwd);
|
|
168
|
-
while (true) {
|
|
169
|
-
if (path.basename(current).startsWith(WORKTREE_PREFIX)) return current;
|
|
170
|
-
const parent = path.dirname(current);
|
|
171
|
-
if (parent === current) return undefined;
|
|
172
|
-
current = parent;
|
|
173
|
-
}
|
|
174
|
-
}
|