@narumitw/pi-subagents 0.41.0 → 0.43.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 +96 -26
- package/package.json +2 -2
- package/src/agents.ts +33 -8
- package/src/config-ui.ts +85 -21
- package/src/consult-policy.ts +15 -0
- package/src/consult.ts +688 -0
- package/src/execution.ts +8 -2
- package/src/inspect.ts +405 -0
- package/src/limits.ts +1 -0
- package/src/params.ts +2 -0
- package/src/registry.ts +75 -0
- package/src/runner.ts +160 -22
- package/src/safe-text.ts +67 -0
- package/src/settings.ts +88 -1
- package/src/stateful.ts +24 -12
- package/src/subagents.ts +43 -4
package/src/subagents.ts
CHANGED
|
@@ -13,26 +13,40 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
type ConsultResourcePolicy,
|
|
18
|
+
discoverAgentCatalog,
|
|
19
|
+
formatAgentCatalog,
|
|
20
|
+
type SubagentSettings,
|
|
21
|
+
} from "./agents.js";
|
|
17
22
|
import { registerSubagentConfigCommand } from "./config-ui.js";
|
|
23
|
+
import { registerSubagentConsult } from "./consult.js";
|
|
18
24
|
import { executeSubagent } from "./execution.js";
|
|
25
|
+
import { registerSubagentInspect } from "./inspect.js";
|
|
19
26
|
import { SubagentParams } from "./params.js";
|
|
20
27
|
import { renderSubagentCall, renderSubagentResult } from "./render.js";
|
|
21
28
|
import type { SubagentDetails } from "./runner.js";
|
|
22
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
consumeSubagentSettingsNotice,
|
|
31
|
+
DEFAULT_CONSULT_RESOURCE_POLICY,
|
|
32
|
+
readSubagentSettings,
|
|
33
|
+
} from "./settings.js";
|
|
23
34
|
import { registerStatefulSubagents } from "./stateful.js";
|
|
24
35
|
|
|
25
36
|
export default function (pi: ExtensionAPI) {
|
|
26
37
|
const settings = readSubagentSettings();
|
|
38
|
+
let currentSettings: SubagentSettings | undefined = settings;
|
|
27
39
|
const blockingEnabled = settings?.blocking?.enabled !== false;
|
|
28
40
|
const refreshBlockingCatalog = blockingEnabled ? registerBlockingSubagent(pi) : () => undefined;
|
|
29
41
|
let refreshStatefulCatalog: (catalog: string) => void = () => undefined;
|
|
42
|
+
let refreshConsultCatalog: (catalog: string) => void = () => undefined;
|
|
30
43
|
|
|
31
44
|
pi.on("session_start", (_event, ctx) => {
|
|
32
45
|
// Preserve a one-shot migration notice from extension load while refreshing
|
|
33
46
|
// validation against settings that may have changed before this session.
|
|
34
47
|
const loadNotice = consumeSubagentSettingsNotice();
|
|
35
48
|
const refreshedSettings = readSubagentSettings();
|
|
49
|
+
currentSettings = refreshedSettings;
|
|
36
50
|
const refreshedNotice = consumeSubagentSettingsNotice();
|
|
37
51
|
const notice = [
|
|
38
52
|
...new Set([loadNotice, refreshedNotice].filter((value) => value !== undefined)),
|
|
@@ -44,6 +58,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
44
58
|
).text;
|
|
45
59
|
refreshBlockingCatalog(catalog);
|
|
46
60
|
refreshStatefulCatalog(catalog);
|
|
61
|
+
refreshConsultCatalog(catalog);
|
|
47
62
|
});
|
|
48
63
|
|
|
49
64
|
const statefulRuntime = registerStatefulSubagents(pi, {
|
|
@@ -51,9 +66,29 @@ export default function (pi: ExtensionAPI) {
|
|
|
51
66
|
settings: settings?.stateful,
|
|
52
67
|
});
|
|
53
68
|
refreshStatefulCatalog = statefulRuntime.setAgentCatalog;
|
|
69
|
+
const getBlockingEnabled = () => blockingEnabled;
|
|
70
|
+
const getConsultResourcePolicy = () =>
|
|
71
|
+
currentSettings?.consult?.resources ?? DEFAULT_CONSULT_RESOURCE_POLICY;
|
|
72
|
+
registerSubagentInspect(pi, {
|
|
73
|
+
...statefulRuntime,
|
|
74
|
+
getBlockingEnabled,
|
|
75
|
+
getConsultResourcePolicy,
|
|
76
|
+
});
|
|
77
|
+
if (blockingEnabled) {
|
|
78
|
+
refreshConsultCatalog = registerSubagentConsult(pi, {
|
|
79
|
+
getSettings: () => currentSettings,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
54
82
|
registerSubagentConfigCommand(pi, {
|
|
55
83
|
...statefulRuntime,
|
|
56
|
-
getBlockingEnabled
|
|
84
|
+
getBlockingEnabled,
|
|
85
|
+
getConsultResourcePolicy,
|
|
86
|
+
setConsultResourcePolicy(value: ConsultResourcePolicy) {
|
|
87
|
+
currentSettings = {
|
|
88
|
+
...(currentSettings ?? {}),
|
|
89
|
+
consult: { ...(currentSettings?.consult ?? {}), resources: value },
|
|
90
|
+
};
|
|
91
|
+
},
|
|
57
92
|
});
|
|
58
93
|
}
|
|
59
94
|
|
|
@@ -63,7 +98,7 @@ function registerBlockingSubagent(pi: ExtensionAPI): (catalog: string) => void {
|
|
|
63
98
|
"Run specialized subagents as a blocking operation with isolated contexts.",
|
|
64
99
|
"The call blocks the main agent until every worker and optional aggregator finishes, so queued steering waits.",
|
|
65
100
|
"Modes: single (agent + task), parallel (tasks array), chain (sequential with {previous} placeholder).",
|
|
66
|
-
"Parallel mode may include an aggregator fan-in step that receives all task outputs.",
|
|
101
|
+
"Parallel mode may include an aggregator fan-in step that receives all task outputs. Use subagent_consult instead for one synchronous child that must be executor-constrained to read-only tools.",
|
|
67
102
|
'Default agent scope is "user" (from ~/.pi/agent/agents).',
|
|
68
103
|
'To enable project-local agents in .pi/agents, pass agentScope: "both" (or "project") as a top-level argument for that call.',
|
|
69
104
|
].join(" ");
|
|
@@ -118,8 +153,11 @@ export { parsePositiveInteger } from "./execution.js";
|
|
|
118
153
|
export { formatTokens, formatUsageStats } from "./render.js";
|
|
119
154
|
export { buildPiArgs } from "./runner.js";
|
|
120
155
|
export {
|
|
156
|
+
DEFAULT_CONSULT_RESOURCE_POLICY,
|
|
121
157
|
inspectCompletionDeliverySettings,
|
|
158
|
+
inspectConsultResourceSettings,
|
|
122
159
|
inspectDelegationWorkflowSettings,
|
|
160
|
+
inspectSubagentSettings,
|
|
123
161
|
normalizeAgentSettings,
|
|
124
162
|
normalizeSubagentSettings,
|
|
125
163
|
readSubagentSettings,
|
|
@@ -130,5 +168,6 @@ export {
|
|
|
130
168
|
uniqueToolNames,
|
|
131
169
|
updateAgentToolsSetting,
|
|
132
170
|
updateCompletionDeliverySetting,
|
|
171
|
+
updateConsultResourceSetting,
|
|
133
172
|
updateDelegationWorkflowSetting,
|
|
134
173
|
} from "./settings.js";
|