@narumitw/pi-subagents 3.0.0 → 3.0.2
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 +35 -100
- package/dist/child-communication-bridge.ts +3 -8
- package/dist/child-communication-bridge.ts.map +2 -2
- package/dist/chunks/{chunk-UKTWUQRM.js → chunk-7JQOB375.ts} +7 -22
- package/dist/chunks/chunk-7JQOB375.ts.map +7 -0
- package/dist/index.ts +16 -49
- package/dist/index.ts.map +2 -2
- package/package.json +53 -54
- package/src/broker-credentials.ts +48 -48
- package/src/child-communication-bridge.ts +115 -123
- package/src/child-communication-tools.ts +105 -111
- package/src/completion-renderer.ts +46 -48
- package/src/message-broker.ts +531 -561
- package/src/model-output.ts +25 -28
- package/src/process.ts +595 -616
- package/src/runtime.ts +454 -478
- package/src/subagents.ts +20 -23
- package/src/tools.ts +305 -319
- package/src/types.ts +41 -58
- package/src/widget.ts +85 -91
- package/dist/chunks/chunk-UKTWUQRM.js.map +0 -7
package/dist/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
sanitizeTerminalText,
|
|
11
11
|
serializeBrokerCredentials,
|
|
12
12
|
validateMessage
|
|
13
|
-
} from "./chunks/chunk-
|
|
13
|
+
} from "./chunks/chunk-7JQOB375.ts";
|
|
14
14
|
|
|
15
15
|
// src/completion-renderer.ts
|
|
16
16
|
import { getMarkdownTheme, keyText } from "@earendil-works/pi-coding-agent";
|
|
@@ -52,11 +52,7 @@ function registerCompletionRenderer(pi) {
|
|
|
52
52
|
})
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
return createCompletionBox(
|
|
56
|
-
children,
|
|
57
|
-
options.outputPad,
|
|
58
|
-
(text) => theme.bg("customMessageBg", text)
|
|
59
|
-
);
|
|
55
|
+
return createCompletionBox(children, options.outputPad, (text) => theme.bg("customMessageBg", text));
|
|
60
56
|
});
|
|
61
57
|
}
|
|
62
58
|
|
|
@@ -327,9 +323,7 @@ async function executeProcess(invocation, request) {
|
|
|
327
323
|
env: {
|
|
328
324
|
...globalThis.process.env,
|
|
329
325
|
...brokerCredentialEnvironment(),
|
|
330
|
-
PI_SUBAGENT_DEPTH: String(
|
|
331
|
-
(Number.parseInt(globalThis.process.env.PI_SUBAGENT_DEPTH ?? "0", 10) || 0) + 1
|
|
332
|
-
)
|
|
326
|
+
PI_SUBAGENT_DEPTH: String((Number.parseInt(globalThis.process.env.PI_SUBAGENT_DEPTH ?? "0", 10) || 0) + 1)
|
|
333
327
|
}
|
|
334
328
|
});
|
|
335
329
|
} catch (error2) {
|
|
@@ -417,10 +411,7 @@ async function executeProcess(invocation, request) {
|
|
|
417
411
|
request.signal
|
|
418
412
|
).catch((error2) => {
|
|
419
413
|
if (settled || terminating) return;
|
|
420
|
-
errorMessage = truncateText(
|
|
421
|
-
error2 instanceof Error ? error2.message : String(error2),
|
|
422
|
-
MAX_ERROR_BYTES
|
|
423
|
-
).text;
|
|
414
|
+
errorMessage = truncateText(error2 instanceof Error ? error2.message : String(error2), MAX_ERROR_BYTES).text;
|
|
424
415
|
terminate(1);
|
|
425
416
|
});
|
|
426
417
|
});
|
|
@@ -515,15 +506,15 @@ function resolvePiInvocation(args) {
|
|
|
515
506
|
}
|
|
516
507
|
const declared = manifest.bin.pi;
|
|
517
508
|
if (path.isAbsolute(declared)) throw new Error("Pi core bin.pi must be package-relative.");
|
|
509
|
+
if (globalThis.process.versions.bun && /^pi(?:\.exe)?$/iu.test(path.basename(globalThis.process.execPath)) && path.dirname(fs.realpathSync(globalThis.process.execPath)) === packageDirectory) {
|
|
510
|
+
return { command: globalThis.process.execPath, args };
|
|
511
|
+
}
|
|
518
512
|
const cliPath = fs.realpathSync(path.resolve(packageDirectory, declared));
|
|
519
513
|
const relative2 = path.relative(packageDirectory, cliPath);
|
|
520
514
|
if (relative2 === ".." || relative2.startsWith(`..${path.sep}`) || path.isAbsolute(relative2)) {
|
|
521
515
|
throw new Error("Pi core bin.pi escapes its package directory.");
|
|
522
516
|
}
|
|
523
517
|
if (!fs.statSync(cliPath).isFile()) throw new Error("Pi core bin.pi is not a file.");
|
|
524
|
-
if (globalThis.process.versions.bun && /^pi(?:\.exe)?$/iu.test(path.basename(globalThis.process.execPath)) && path.dirname(fs.realpathSync(globalThis.process.execPath)) === packageDirectory) {
|
|
525
|
-
return { command: globalThis.process.execPath, args };
|
|
526
|
-
}
|
|
527
518
|
return { command: globalThis.process.execPath, args: [cliPath, ...args] };
|
|
528
519
|
}
|
|
529
520
|
function signalPosixProcess(process2, signal) {
|
|
@@ -680,16 +671,7 @@ var TERMINAL_JOB_STATES = /* @__PURE__ */ new Set([
|
|
|
680
671
|
"timed_out",
|
|
681
672
|
"cancelled"
|
|
682
673
|
]);
|
|
683
|
-
var CHILD_CORE_TOOL_NAMES = [
|
|
684
|
-
"read",
|
|
685
|
-
"bash",
|
|
686
|
-
"powershell",
|
|
687
|
-
"edit",
|
|
688
|
-
"write",
|
|
689
|
-
"grep",
|
|
690
|
-
"find",
|
|
691
|
-
"ls"
|
|
692
|
-
];
|
|
674
|
+
var CHILD_CORE_TOOL_NAMES = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
|
|
693
675
|
var DEFAULT_SUBAGENT_TOOLS = ["read", "grep", "find", "ls"];
|
|
694
676
|
var SUBAGENT_THINKING_LEVELS = [
|
|
695
677
|
"off",
|
|
@@ -814,8 +796,7 @@ var SubagentRuntime = class {
|
|
|
814
796
|
communication,
|
|
815
797
|
signal: controller.signal,
|
|
816
798
|
onControl: (control) => {
|
|
817
|
-
if (job.state !== "running" || job.stopRequest || job.generation !== this.generation)
|
|
818
|
-
return;
|
|
799
|
+
if (job.state !== "running" || job.stopRequest || job.generation !== this.generation) return;
|
|
819
800
|
job.control = control;
|
|
820
801
|
job.resolveControl(control);
|
|
821
802
|
}
|
|
@@ -1057,10 +1038,7 @@ var SubagentRuntime = class {
|
|
|
1057
1038
|
if (this.jobs.delete(job.jobId)) this.omittedJobs++;
|
|
1058
1039
|
}
|
|
1059
1040
|
const terminal = [...this.jobs.values()].filter((job) => isTerminal(job.state)).sort((left, right) => (left.finishedAt ?? 0) - (right.finishedAt ?? 0));
|
|
1060
|
-
for (const job of terminal.slice(
|
|
1061
|
-
0,
|
|
1062
|
-
Math.max(0, terminal.length - MAX_RETAINED_TERMINAL_JOBS)
|
|
1063
|
-
)) {
|
|
1041
|
+
for (const job of terminal.slice(0, Math.max(0, terminal.length - MAX_RETAINED_TERMINAL_JOBS))) {
|
|
1064
1042
|
if (this.jobs.delete(job.jobId)) this.omittedJobs++;
|
|
1065
1043
|
}
|
|
1066
1044
|
}
|
|
@@ -1137,9 +1115,7 @@ var SpawnParameters = Type.Object(
|
|
|
1137
1115
|
description: "Child thinking level. Defaults to the main agent's effective level."
|
|
1138
1116
|
})
|
|
1139
1117
|
),
|
|
1140
|
-
timeout: Type.Optional(
|
|
1141
|
-
Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })
|
|
1142
|
-
)
|
|
1118
|
+
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" }))
|
|
1143
1119
|
},
|
|
1144
1120
|
{ additionalProperties: false }
|
|
1145
1121
|
);
|
|
@@ -1156,9 +1132,7 @@ var CancelParameters = Type.Object(
|
|
|
1156
1132
|
var WaitParameters = Type.Object(
|
|
1157
1133
|
{
|
|
1158
1134
|
jobId: Type.String({ description: "Job to wait for.", maxLength: MAX_IDENTIFIER_LENGTH }),
|
|
1159
|
-
timeout: Type.Optional(
|
|
1160
|
-
Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })
|
|
1161
|
-
)
|
|
1135
|
+
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" }))
|
|
1162
1136
|
},
|
|
1163
1137
|
{ additionalProperties: false }
|
|
1164
1138
|
);
|
|
@@ -1204,9 +1178,7 @@ function registerSubagentTools(pi, dependencies = {}) {
|
|
|
1204
1178
|
const task = validateTask(params.task, "subagent_spawn");
|
|
1205
1179
|
const tools = resolveTools(params.tools);
|
|
1206
1180
|
const model = resolveChildModel(ctx);
|
|
1207
|
-
const thinkingLevel = resolveThinkingLevel(
|
|
1208
|
-
params.thinkingLevel ?? ctx.thinkingLevel ?? pi.getThinkingLevel()
|
|
1209
|
-
);
|
|
1181
|
+
const thinkingLevel = resolveThinkingLevel(params.thinkingLevel ?? ctx.thinkingLevel ?? pi.getThinkingLevel());
|
|
1210
1182
|
resolveTimeoutMs(params.timeout);
|
|
1211
1183
|
return toolResult(
|
|
1212
1184
|
runtime.start({
|
|
@@ -1253,9 +1225,7 @@ function registerSubagentTools(pi, dependencies = {}) {
|
|
|
1253
1225
|
prepareArguments: prepareWaitArguments,
|
|
1254
1226
|
async execute(_toolCallId, params, signal) {
|
|
1255
1227
|
const timeoutMs = resolveTimeoutMs(params.timeout);
|
|
1256
|
-
return toolResult(
|
|
1257
|
-
await runtime.wait(requiredIdentifier(params.jobId, "jobId"), timeoutMs, signal)
|
|
1258
|
-
);
|
|
1228
|
+
return toolResult(await runtime.wait(requiredIdentifier(params.jobId, "jobId"), timeoutMs, signal));
|
|
1259
1229
|
}
|
|
1260
1230
|
});
|
|
1261
1231
|
pi.registerTool({
|
|
@@ -1354,13 +1324,10 @@ function resolveTools(value) {
|
|
|
1354
1324
|
}
|
|
1355
1325
|
function resolveChildModel(ctx) {
|
|
1356
1326
|
const model = ctx.model;
|
|
1357
|
-
if (!model)
|
|
1358
|
-
throw new Error("Subagent model is unavailable because no main-agent model is selected.");
|
|
1327
|
+
if (!model) throw new Error("Subagent model is unavailable because no main-agent model is selected.");
|
|
1359
1328
|
const provider = sanitizeTerminalText(model.provider).slice(0, 128);
|
|
1360
1329
|
if (ctx.modelRegistry.getRegisteredProviderIds().includes(model.provider)) {
|
|
1361
|
-
throw new Error(
|
|
1362
|
-
`Subagent model provider ${provider} is unavailable because children disable parent extensions.`
|
|
1363
|
-
);
|
|
1330
|
+
throw new Error(`Subagent model provider ${provider} is unavailable because children disable parent extensions.`);
|
|
1364
1331
|
}
|
|
1365
1332
|
if (ctx.modelRegistry.getProviderAuthStatus(model.provider).source === "runtime") {
|
|
1366
1333
|
throw new Error(
|