@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,108 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
-
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
-
|
|
4
|
-
// src/process-control.ts
|
|
5
|
-
var KILL_GRACE_MS = 5e3;
|
|
6
|
-
function signalProcess(proc, signal) {
|
|
7
|
-
if (process.platform !== "win32" && proc.pid) {
|
|
8
|
-
try {
|
|
9
|
-
process.kill(-proc.pid, signal);
|
|
10
|
-
return;
|
|
11
|
-
} catch {
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
proc.kill(signal);
|
|
16
|
-
} catch {
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function terminateProcess(proc, graceMs = KILL_GRACE_MS) {
|
|
20
|
-
const leaderExited = proc.exitCode !== null || proc.signalCode !== null;
|
|
21
|
-
const capturedOutputClosed = [proc.stdout, proc.stderr].every(
|
|
22
|
-
(stream) => !stream || stream.readableEnded || stream.destroyed
|
|
23
|
-
);
|
|
24
|
-
let closed = leaderExited && capturedOutputClosed;
|
|
25
|
-
const onClose = () => {
|
|
26
|
-
closed = true;
|
|
27
|
-
};
|
|
28
|
-
proc.once("close", onClose);
|
|
29
|
-
if (!closed) signalProcess(proc, "SIGTERM");
|
|
30
|
-
const escalation = setTimeout(() => {
|
|
31
|
-
if (!closed) signalProcess(proc, "SIGKILL");
|
|
32
|
-
}, graceMs);
|
|
33
|
-
escalation.unref();
|
|
34
|
-
return () => {
|
|
35
|
-
clearTimeout(escalation);
|
|
36
|
-
proc.off("close", onClose);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/protocol.ts
|
|
41
|
-
import { StringDecoder } from "node:string_decoder";
|
|
42
|
-
var DEFAULT_MAX_LINE_BYTES = 256 * 1024;
|
|
43
|
-
var JsonLineDecoder = class {
|
|
44
|
-
constructor(options) {
|
|
45
|
-
this.options = options;
|
|
46
|
-
const maxLineBytes = options.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES;
|
|
47
|
-
if (!Number.isSafeInteger(maxLineBytes) || maxLineBytes < 1) {
|
|
48
|
-
throw new Error("JSON line limit must be a positive safe integer");
|
|
49
|
-
}
|
|
50
|
-
this.maxLineBytes = maxLineBytes;
|
|
51
|
-
}
|
|
52
|
-
options;
|
|
53
|
-
buffer = "";
|
|
54
|
-
droppingOversizedLine = false;
|
|
55
|
-
maxLineBytes;
|
|
56
|
-
decoder = new StringDecoder("utf8");
|
|
57
|
-
push(chunk) {
|
|
58
|
-
this.buffer += typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
59
|
-
this.drain(false);
|
|
60
|
-
}
|
|
61
|
-
finish() {
|
|
62
|
-
this.buffer += this.decoder.end();
|
|
63
|
-
this.drain(true);
|
|
64
|
-
this.buffer = "";
|
|
65
|
-
this.droppingOversizedLine = false;
|
|
66
|
-
}
|
|
67
|
-
drain(flush) {
|
|
68
|
-
while (true) {
|
|
69
|
-
const newline = this.buffer.indexOf("\n");
|
|
70
|
-
if (newline < 0) break;
|
|
71
|
-
const line = this.buffer.slice(0, newline).replace(/\r$/, "");
|
|
72
|
-
this.buffer = this.buffer.slice(newline + 1);
|
|
73
|
-
if (this.droppingOversizedLine) {
|
|
74
|
-
this.droppingOversizedLine = false;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
this.processLine(line);
|
|
78
|
-
}
|
|
79
|
-
if (!flush && Buffer.byteLength(this.buffer, "utf8") > this.maxLineBytes) {
|
|
80
|
-
this.options.onOversized?.(Buffer.byteLength(this.buffer, "utf8"));
|
|
81
|
-
this.buffer = "";
|
|
82
|
-
this.droppingOversizedLine = true;
|
|
83
|
-
}
|
|
84
|
-
if (flush && this.buffer.length > 0 && !this.droppingOversizedLine) {
|
|
85
|
-
this.processLine(this.buffer.replace(/\r$/, ""));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
processLine(line) {
|
|
89
|
-
if (!line.trim()) return;
|
|
90
|
-
const bytes = Buffer.byteLength(line, "utf8");
|
|
91
|
-
if (bytes > this.maxLineBytes) {
|
|
92
|
-
this.options.onOversized?.(bytes);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
this.options.onValue(JSON.parse(line));
|
|
97
|
-
} catch {
|
|
98
|
-
this.options.onMalformed?.(line);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export {
|
|
104
|
-
KILL_GRACE_MS,
|
|
105
|
-
terminateProcess,
|
|
106
|
-
JsonLineDecoder
|
|
107
|
-
};
|
|
108
|
-
//# sourceMappingURL=chunk-6H6TBBED.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/process-control.ts", "../../src/protocol.ts"],
|
|
4
|
-
"sourcesContent": ["import type { spawn } from \"node:child_process\";\n\nexport const KILL_GRACE_MS = 5000;\n\nfunction signalProcess(proc: ReturnType<typeof spawn>, signal: NodeJS.Signals): void {\n\tif (process.platform !== \"win32\" && proc.pid) {\n\t\ttry {\n\t\t\tprocess.kill(-proc.pid, signal);\n\t\t\treturn;\n\t\t} catch {\n\t\t\t// Fall back to signaling the immediate child when process-group signaling is unavailable.\n\t\t}\n\t}\n\ttry {\n\t\tproc.kill(signal);\n\t} catch {\n\t\t// The process may already have exited.\n\t}\n}\n\nexport function terminateProcess(\n\tproc: ReturnType<typeof spawn>,\n\tgraceMs = KILL_GRACE_MS,\n): () => void {\n\tconst leaderExited = proc.exitCode !== null || proc.signalCode !== null;\n\tconst capturedOutputClosed = [proc.stdout, proc.stderr].every(\n\t\t(stream) => !stream || stream.readableEnded || stream.destroyed,\n\t);\n\tlet closed = leaderExited && capturedOutputClosed;\n\tconst onClose = () => {\n\t\tclosed = true;\n\t};\n\tproc.once(\"close\", onClose);\n\tif (!closed) signalProcess(proc, \"SIGTERM\");\n\tconst escalation = setTimeout(() => {\n\t\tif (!closed) signalProcess(proc, \"SIGKILL\");\n\t}, graceMs);\n\tescalation.unref();\n\treturn () => {\n\t\tclearTimeout(escalation);\n\t\tproc.off(\"close\", onClose);\n\t};\n}\n", "import { StringDecoder } from \"node:string_decoder\";\n\nconst DEFAULT_MAX_LINE_BYTES = 256 * 1024;\n\nexport interface JsonLineDecoderOptions {\n\tmaxLineBytes?: number;\n\tonValue: (value: unknown) => void;\n\tonMalformed?: (line: string) => void;\n\tonOversized?: (bytes: number) => void;\n}\n\n/** Bounded newline-delimited JSON decoder for child Pi event streams. */\nexport class JsonLineDecoder {\n\tprivate buffer = \"\";\n\tprivate droppingOversizedLine = false;\n\tprivate readonly maxLineBytes: number;\n\tprivate readonly decoder = new StringDecoder(\"utf8\");\n\n\tconstructor(private readonly options: JsonLineDecoderOptions) {\n\t\tconst maxLineBytes = options.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES;\n\t\tif (!Number.isSafeInteger(maxLineBytes) || maxLineBytes < 1) {\n\t\t\tthrow new Error(\"JSON line limit must be a positive safe integer\");\n\t\t}\n\t\tthis.maxLineBytes = maxLineBytes;\n\t}\n\n\tpush(chunk: string | Buffer): void {\n\t\tthis.buffer += typeof chunk === \"string\" ? chunk : this.decoder.write(chunk);\n\t\tthis.drain(false);\n\t}\n\n\tfinish(): void {\n\t\tthis.buffer += this.decoder.end();\n\t\tthis.drain(true);\n\t\tthis.buffer = \"\";\n\t\tthis.droppingOversizedLine = false;\n\t}\n\n\tprivate drain(flush: boolean): void {\n\t\twhile (true) {\n\t\t\tconst newline = this.buffer.indexOf(\"\\n\");\n\t\t\tif (newline < 0) break;\n\t\t\tconst line = this.buffer.slice(0, newline).replace(/\\r$/, \"\");\n\t\t\tthis.buffer = this.buffer.slice(newline + 1);\n\t\t\tif (this.droppingOversizedLine) {\n\t\t\t\tthis.droppingOversizedLine = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.processLine(line);\n\t\t}\n\n\t\tif (!flush && Buffer.byteLength(this.buffer, \"utf8\") > this.maxLineBytes) {\n\t\t\tthis.options.onOversized?.(Buffer.byteLength(this.buffer, \"utf8\"));\n\t\t\tthis.buffer = \"\";\n\t\t\tthis.droppingOversizedLine = true;\n\t\t}\n\n\t\tif (flush && this.buffer.length > 0 && !this.droppingOversizedLine) {\n\t\t\tthis.processLine(this.buffer.replace(/\\r$/, \"\"));\n\t\t}\n\t}\n\n\tprivate processLine(line: string): void {\n\t\tif (!line.trim()) return;\n\t\tconst bytes = Buffer.byteLength(line, \"utf8\");\n\t\tif (bytes > this.maxLineBytes) {\n\t\t\tthis.options.onOversized?.(bytes);\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tthis.options.onValue(JSON.parse(line));\n\t\t} catch {\n\t\t\tthis.options.onMalformed?.(line);\n\t\t}\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAEO,IAAM,gBAAgB;AAE7B,SAAS,cAAc,MAAgC,QAA8B;AACpF,MAAI,QAAQ,aAAa,WAAW,KAAK,KAAK;AAC7C,QAAI;AACH,cAAQ,KAAK,CAAC,KAAK,KAAK,MAAM;AAC9B;AAAA,IACD,QAAQ;AAAA,IAER;AAAA,EACD;AACA,MAAI;AACH,SAAK,KAAK,MAAM;AAAA,EACjB,QAAQ;AAAA,EAER;AACD;AAEO,SAAS,iBACf,MACA,UAAU,eACG;AACb,QAAM,eAAe,KAAK,aAAa,QAAQ,KAAK,eAAe;AACnE,QAAM,uBAAuB,CAAC,KAAK,QAAQ,KAAK,MAAM,EAAE;AAAA,IACvD,CAAC,WAAW,CAAC,UAAU,OAAO,iBAAiB,OAAO;AAAA,EACvD;AACA,MAAI,SAAS,gBAAgB;AAC7B,QAAM,UAAU,MAAM;AACrB,aAAS;AAAA,EACV;AACA,OAAK,KAAK,SAAS,OAAO;AAC1B,MAAI,CAAC,OAAQ,eAAc,MAAM,SAAS;AAC1C,QAAM,aAAa,WAAW,MAAM;AACnC,QAAI,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AO,WAAW,KAAK,QAAQ,MAAM,CAAC;AACjE,WAAK,SAAS;AACd,WAAK,wBAAwB;AAAA,IAC9B;AAEA,QAAI,SAAS,KAAK,OAAO,SAAS,KAAK,CAAC,KAAK,uBAAuB;AACnE,WAAK,YAAY,KAAK,OAAO,QAAQ,OAAO,EAAE,CAAC;AAAA,IAChD;AAAA,EACD;AAAA,EAEQ,YAAY,MAAoB;AACvC,QAAI,CAAC,KAAK,KAAK,EAAG;AAClB,UAAM,QAAQ,OAAO,WAAW,MAAM,MAAM;AAC5C,QAAI,QAAQ,KAAK,cAAc;AAC9B,WAAK,QAAQ,cAAc,KAAK;AAChC;AAAA,IACD;AACA,QAAI;AACH,WAAK,QAAQ,QAAQ,KAAK,MAAM,IAAI,CAAC;AAAA,IACtC,QAAQ;AACP,WAAK,QAAQ,cAAc,IAAI;AAAA,IAChC;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
-
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
-
|
|
4
|
-
// src/workspace.ts
|
|
5
|
-
import { execFile } from "node:child_process";
|
|
6
|
-
import * as fs from "node:fs";
|
|
7
|
-
import * as os from "node:os";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import { promisify } from "node:util";
|
|
10
|
-
var execFileAsync = promisify(execFile);
|
|
11
|
-
var WORKTREE_PREFIX = "pi-subagent-worktree-";
|
|
12
|
-
async function assertWorkspaceIsolationReady(cwd) {
|
|
13
|
-
await resolveWorkspaceBase(cwd);
|
|
14
|
-
}
|
|
15
|
-
var WorkspaceManager = class {
|
|
16
|
-
owned = /* @__PURE__ */ new Map();
|
|
17
|
-
async create(ownerId, cwd) {
|
|
18
|
-
if (this.owned.has(ownerId)) throw new Error(`Workspace owner already exists: ${ownerId}`);
|
|
19
|
-
const { repositoryRoot, relativeCwd } = await resolveWorkspaceBase(cwd);
|
|
20
|
-
const rootPath = await fs.promises.mkdtemp(path.join(os.tmpdir(), WORKTREE_PREFIX));
|
|
21
|
-
let registered = false;
|
|
22
|
-
try {
|
|
23
|
-
await execFileAsync("git", [
|
|
24
|
-
"-C",
|
|
25
|
-
repositoryRoot,
|
|
26
|
-
"worktree",
|
|
27
|
-
"add",
|
|
28
|
-
"--detach",
|
|
29
|
-
rootPath,
|
|
30
|
-
"HEAD"
|
|
31
|
-
]);
|
|
32
|
-
registered = true;
|
|
33
|
-
await fs.promises.writeFile(`${rootPath}.owner`, ownerId, { mode: 384 });
|
|
34
|
-
const workspace = {
|
|
35
|
-
mode: "worktree",
|
|
36
|
-
path: path.join(rootPath, relativeCwd),
|
|
37
|
-
rootPath,
|
|
38
|
-
repositoryRoot
|
|
39
|
-
};
|
|
40
|
-
this.owned.set(ownerId, workspace);
|
|
41
|
-
return workspace;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
if (registered) {
|
|
44
|
-
await execFileAsync("git", [
|
|
45
|
-
"-C",
|
|
46
|
-
repositoryRoot,
|
|
47
|
-
"worktree",
|
|
48
|
-
"remove",
|
|
49
|
-
"--force",
|
|
50
|
-
rootPath
|
|
51
|
-
]).catch(() => void 0);
|
|
52
|
-
}
|
|
53
|
-
await fs.promises.rm(rootPath, { recursive: true, force: true });
|
|
54
|
-
await fs.promises.rm(`${rootPath}.owner`, { force: true });
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async cleanupPersisted(ownerId, cwd) {
|
|
59
|
-
const rootPath = findGeneratedWorktreeRoot(cwd);
|
|
60
|
-
if (!rootPath || !await this.isOwned(rootPath, ownerId)) return;
|
|
61
|
-
let repositoryRoot;
|
|
62
|
-
try {
|
|
63
|
-
const commonDirectory = (await execFileAsync("git", ["-C", rootPath, "rev-parse", "--git-common-dir"])).stdout.trim();
|
|
64
|
-
const resolvedCommonDirectory = await fs.promises.realpath(
|
|
65
|
-
path.resolve(rootPath, commonDirectory)
|
|
66
|
-
);
|
|
67
|
-
repositoryRoot = path.dirname(resolvedCommonDirectory);
|
|
68
|
-
} catch {
|
|
69
|
-
}
|
|
70
|
-
if (repositoryRoot) {
|
|
71
|
-
await execFileAsync("git", [
|
|
72
|
-
"-C",
|
|
73
|
-
repositoryRoot,
|
|
74
|
-
"worktree",
|
|
75
|
-
"remove",
|
|
76
|
-
"--force",
|
|
77
|
-
rootPath
|
|
78
|
-
]).catch(() => void 0);
|
|
79
|
-
}
|
|
80
|
-
await fs.promises.rm(rootPath, { recursive: true, force: true });
|
|
81
|
-
await fs.promises.rm(`${rootPath}.owner`, { force: true });
|
|
82
|
-
if (repositoryRoot) {
|
|
83
|
-
await execFileAsync("git", ["-C", repositoryRoot, "worktree", "prune"]).catch(
|
|
84
|
-
() => void 0
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async cleanup(ownerId) {
|
|
89
|
-
const workspace = this.owned.get(ownerId);
|
|
90
|
-
if (!workspace) return;
|
|
91
|
-
if (!await this.isOwned(workspace.rootPath, ownerId)) {
|
|
92
|
-
throw new Error(`Refusing to clean unowned subagent workspace: ${workspace.rootPath}`);
|
|
93
|
-
}
|
|
94
|
-
this.owned.delete(ownerId);
|
|
95
|
-
await execFileAsync("git", [
|
|
96
|
-
"-C",
|
|
97
|
-
workspace.repositoryRoot,
|
|
98
|
-
"worktree",
|
|
99
|
-
"remove",
|
|
100
|
-
"--force",
|
|
101
|
-
workspace.rootPath
|
|
102
|
-
]).catch(async () => {
|
|
103
|
-
await fs.promises.rm(workspace.rootPath, { recursive: true, force: true });
|
|
104
|
-
await execFileAsync("git", ["-C", workspace.repositoryRoot, "worktree", "prune"]).catch(
|
|
105
|
-
() => void 0
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
await fs.promises.rm(`${workspace.rootPath}.owner`, { force: true });
|
|
109
|
-
}
|
|
110
|
-
async cleanupAll() {
|
|
111
|
-
const results = await Promise.allSettled(
|
|
112
|
-
[...this.owned.keys()].map((ownerId) => this.cleanup(ownerId))
|
|
113
|
-
);
|
|
114
|
-
const failures = results.filter((result) => result.status === "rejected");
|
|
115
|
-
if (failures.length > 0) {
|
|
116
|
-
throw new AggregateError(
|
|
117
|
-
failures.map((failure) => failure.reason),
|
|
118
|
-
`Failed to clean ${failures.length} subagent workspace(s)`
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async isOwned(rootPath, ownerId) {
|
|
123
|
-
if (!path.basename(rootPath).startsWith(WORKTREE_PREFIX)) return false;
|
|
124
|
-
try {
|
|
125
|
-
return await fs.promises.readFile(`${rootPath}.owner`, "utf8") === ownerId;
|
|
126
|
-
} catch {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
async function resolveWorkspaceBase(cwd) {
|
|
132
|
-
const resolvedCwd = await fs.promises.realpath(path.resolve(cwd));
|
|
133
|
-
const reportedRepositoryRoot = (await execFileAsync("git", ["-C", resolvedCwd, "rev-parse", "--show-toplevel"])).stdout.trim();
|
|
134
|
-
const repositoryRoot = await fs.promises.realpath(reportedRepositoryRoot);
|
|
135
|
-
const relativeCwd = path.relative(repositoryRoot, resolvedCwd);
|
|
136
|
-
if (relativeCwd.startsWith("..") || path.isAbsolute(relativeCwd)) {
|
|
137
|
-
throw new Error("Subagent cwd is outside the Git repository");
|
|
138
|
-
}
|
|
139
|
-
const status = (await execFileAsync("git", ["-C", repositoryRoot, "status", "--porcelain"])).stdout;
|
|
140
|
-
if (status.trim()) {
|
|
141
|
-
throw new Error("Isolated subagent workspace requires a clean Git repository");
|
|
142
|
-
}
|
|
143
|
-
return { repositoryRoot, relativeCwd };
|
|
144
|
-
}
|
|
145
|
-
function findGeneratedWorktreeRoot(cwd) {
|
|
146
|
-
let current = path.resolve(cwd);
|
|
147
|
-
while (true) {
|
|
148
|
-
if (path.basename(current).startsWith(WORKTREE_PREFIX)) return current;
|
|
149
|
-
const parent = path.dirname(current);
|
|
150
|
-
if (parent === current) return void 0;
|
|
151
|
-
current = parent;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export {
|
|
156
|
-
assertWorkspaceIsolationReady,
|
|
157
|
-
WorkspaceManager
|
|
158
|
-
};
|
|
159
|
-
//# sourceMappingURL=chunk-6KJ34M6S.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/workspace.ts"],
|
|
4
|
-
"sourcesContent": ["import { execFile } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { promisify } from \"node:util\";\n\nconst execFileAsync = promisify(execFile);\nconst WORKTREE_PREFIX = \"pi-subagent-worktree-\";\n\nexport interface IsolatedWorkspace {\n\tmode: \"worktree\";\n\tpath: string;\n\trootPath: string;\n\trepositoryRoot: string;\n}\n\nexport async function assertWorkspaceIsolationReady(cwd: string): Promise<void> {\n\tawait resolveWorkspaceBase(cwd);\n}\n\nexport class WorkspaceManager {\n\tprivate readonly owned = new Map<string, IsolatedWorkspace>();\n\n\tasync create(ownerId: string, cwd: string): Promise<IsolatedWorkspace> {\n\t\tif (this.owned.has(ownerId)) throw new Error(`Workspace owner already exists: ${ownerId}`);\n\t\tconst { repositoryRoot, relativeCwd } = await resolveWorkspaceBase(cwd);\n\t\tconst rootPath = await fs.promises.mkdtemp(path.join(os.tmpdir(), WORKTREE_PREFIX));\n\t\tlet registered = false;\n\t\ttry {\n\t\t\tawait execFileAsync(\"git\", [\n\t\t\t\t\"-C\",\n\t\t\t\trepositoryRoot,\n\t\t\t\t\"worktree\",\n\t\t\t\t\"add\",\n\t\t\t\t\"--detach\",\n\t\t\t\trootPath,\n\t\t\t\t\"HEAD\",\n\t\t\t]);\n\t\t\tregistered = true;\n\t\t\tawait fs.promises.writeFile(`${rootPath}.owner`, ownerId, { mode: 0o600 });\n\t\t\tconst workspace = {\n\t\t\t\tmode: \"worktree\" as const,\n\t\t\t\tpath: path.join(rootPath, relativeCwd),\n\t\t\t\trootPath,\n\t\t\t\trepositoryRoot,\n\t\t\t};\n\t\t\tthis.owned.set(ownerId, workspace);\n\t\t\treturn workspace;\n\t\t} catch (error) {\n\t\t\tif (registered) {\n\t\t\t\tawait execFileAsync(\"git\", [\n\t\t\t\t\t\"-C\",\n\t\t\t\t\trepositoryRoot,\n\t\t\t\t\t\"worktree\",\n\t\t\t\t\t\"remove\",\n\t\t\t\t\t\"--force\",\n\t\t\t\t\trootPath,\n\t\t\t\t]).catch(() => undefined);\n\t\t\t}\n\t\t\tawait fs.promises.rm(rootPath, { recursive: true, force: true });\n\t\t\tawait fs.promises.rm(`${rootPath}.owner`, { force: true });\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync cleanupPersisted(ownerId: string, cwd: string): Promise<void> {\n\t\tconst rootPath = findGeneratedWorktreeRoot(cwd);\n\t\tif (!rootPath || !(await this.isOwned(rootPath, ownerId))) return;\n\t\tlet repositoryRoot: string | undefined;\n\t\ttry {\n\t\t\tconst commonDirectory = (\n\t\t\t\tawait execFileAsync(\"git\", [\"-C\", rootPath, \"rev-parse\", \"--git-common-dir\"])\n\t\t\t).stdout.trim();\n\t\t\tconst resolvedCommonDirectory = await fs.promises.realpath(\n\t\t\t\tpath.resolve(rootPath, commonDirectory),\n\t\t\t);\n\t\t\trepositoryRoot = path.dirname(resolvedCommonDirectory);\n\t\t} catch {\n\t\t\t// The ownership marker still permits bounded filesystem cleanup below.\n\t\t}\n\t\tif (repositoryRoot) {\n\t\t\tawait execFileAsync(\"git\", [\n\t\t\t\t\"-C\",\n\t\t\t\trepositoryRoot,\n\t\t\t\t\"worktree\",\n\t\t\t\t\"remove\",\n\t\t\t\t\"--force\",\n\t\t\t\trootPath,\n\t\t\t]).catch(() => undefined);\n\t\t}\n\t\tawait fs.promises.rm(rootPath, { recursive: true, force: true });\n\t\tawait fs.promises.rm(`${rootPath}.owner`, { force: true });\n\t\tif (repositoryRoot) {\n\t\t\tawait execFileAsync(\"git\", [\"-C\", repositoryRoot, \"worktree\", \"prune\"]).catch(\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync cleanup(ownerId: string): Promise<void> {\n\t\tconst workspace = this.owned.get(ownerId);\n\t\tif (!workspace) return;\n\t\tif (!(await this.isOwned(workspace.rootPath, ownerId))) {\n\t\t\tthrow new Error(`Refusing to clean unowned subagent workspace: ${workspace.rootPath}`);\n\t\t}\n\t\tthis.owned.delete(ownerId);\n\t\tawait execFileAsync(\"git\", [\n\t\t\t\"-C\",\n\t\t\tworkspace.repositoryRoot,\n\t\t\t\"worktree\",\n\t\t\t\"remove\",\n\t\t\t\"--force\",\n\t\t\tworkspace.rootPath,\n\t\t]).catch(async () => {\n\t\t\tawait fs.promises.rm(workspace.rootPath, { recursive: true, force: true });\n\t\t\tawait execFileAsync(\"git\", [\"-C\", workspace.repositoryRoot, \"worktree\", \"prune\"]).catch(\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t});\n\t\tawait fs.promises.rm(`${workspace.rootPath}.owner`, { force: true });\n\t}\n\n\tasync cleanupAll(): Promise<void> {\n\t\tconst results = await Promise.allSettled(\n\t\t\t[...this.owned.keys()].map((ownerId) => this.cleanup(ownerId)),\n\t\t);\n\t\tconst failures = results.filter((result) => result.status === \"rejected\");\n\t\tif (failures.length > 0) {\n\t\t\tthrow new AggregateError(\n\t\t\t\tfailures.map((failure) => (failure as PromiseRejectedResult).reason),\n\t\t\t\t`Failed to clean ${failures.length} subagent workspace(s)`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async isOwned(rootPath: string, ownerId: string): Promise<boolean> {\n\t\tif (!path.basename(rootPath).startsWith(WORKTREE_PREFIX)) return false;\n\t\ttry {\n\t\t\treturn (await fs.promises.readFile(`${rootPath}.owner`, \"utf8\")) === ownerId;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\nasync function resolveWorkspaceBase(\n\tcwd: string,\n): Promise<{ repositoryRoot: string; relativeCwd: string }> {\n\tconst resolvedCwd = await fs.promises.realpath(path.resolve(cwd));\n\tconst reportedRepositoryRoot = (\n\t\tawait execFileAsync(\"git\", [\"-C\", resolvedCwd, \"rev-parse\", \"--show-toplevel\"])\n\t).stdout.trim();\n\tconst repositoryRoot = await fs.promises.realpath(reportedRepositoryRoot);\n\tconst relativeCwd = path.relative(repositoryRoot, resolvedCwd);\n\tif (relativeCwd.startsWith(\"..\") || path.isAbsolute(relativeCwd)) {\n\t\tthrow new Error(\"Subagent cwd is outside the Git repository\");\n\t}\n\tconst status = (await execFileAsync(\"git\", [\"-C\", repositoryRoot, \"status\", \"--porcelain\"]))\n\t\t.stdout;\n\tif (status.trim()) {\n\t\tthrow new Error(\"Isolated subagent workspace requires a clean Git repository\");\n\t}\n\treturn { repositoryRoot, relativeCwd };\n}\n\nfunction findGeneratedWorktreeRoot(cwd: string): string | undefined {\n\tlet current = path.resolve(cwd);\n\twhile (true) {\n\t\tif (path.basename(current).startsWith(WORKTREE_PREFIX)) return current;\n\t\tconst parent = path.dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAAA,SAAS,gBAAgB;AACzB,YAAY,QAAQ;AACpB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,iBAAiB;AAE1B,IAAM,gBAAgB,UAAU,QAAQ;AACxC,IAAM,kBAAkB;AASxB,eAAsB,8BAA8B,KAA4B;AAC/E,QAAM,qBAAqB,GAAG;AAC/B;AAEO,IAAM,mBAAN,MAAuB;AAAA,EACZ,QAAQ,oBAAI,IAA+B;AAAA,EAE5D,MAAM,OAAO,SAAiB,KAAyC;AACtE,QAAI,KAAK,MAAM,IAAI,OAAO,EAAG,OAAM,IAAI,MAAM,mCAAmC,OAAO,EAAE;AACzF,UAAM,EAAE,gBAA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