@herbertgao/pi-extensions 2026.11.16 → 2026.11.17
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/CHANGELOG.md +13 -0
- package/node_modules/@herbertgao/pi-agency/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-agency/README.md +3 -1
- package/node_modules/@herbertgao/pi-agency/package.json +1 -1
- package/node_modules/@herbertgao/pi-agency/src/index.ts +151 -9
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +7 -2
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +7 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/agent-color.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +82 -1
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +107 -2
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +9 -2
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @herbertgao/pi-extensions
|
|
2
2
|
|
|
3
|
+
## 2026.11.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#398](https://github.com/HerbertGao/pi-extensions/pull/398) [`1eccc1a`](https://github.com/HerbertGao/pi-extensions/commit/1eccc1ab99247b9b1f1772ea027f3b8c48cf23ba) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Raise the promoted dependency floors to what the bundled packages require: `nanoid@^5.1.16`, `turndown@^7.2.4`, and `undici@^8.12.3`. The installed versions already meet these floors, so this changes no resolved package today; it removes ranges that could resolve below a bundled package's own requirement, including the patched `undici` floor `pi-antigravity` needs.
|
|
8
|
+
|
|
9
|
+
- [#397](https://github.com/HerbertGao/pi-extensions/pull/397) [`42647d1`](https://github.com/HerbertGao/pi-extensions/commit/42647d16b171f766da6135fc937bd087e005a161) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Label an `Agent` run by identity: a registered type (Code Reviewer) keeps its type name while a named generic run shows its own `name`, in both the ccstyle transcript row and the pi-subagents badges. The `name` parameter accepts any characters — labels show it as given, `@handles` are slugged. `agency_register` seats catalog personas as session-scoped agent types over the new `subagents:rpc:register-agents` bus channels: the persona body becomes the system prompt, the card name and color become the label and badge, and the types vanish at the next session start without ever shadowing file-loaded agents.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`42647d1`](https://github.com/HerbertGao/pi-extensions/commit/42647d16b171f766da6135fc937bd087e005a161)]:
|
|
12
|
+
- @herbertgao/pi-agency@0.1.4
|
|
13
|
+
- @herbertgao/pi-cc-extensions@1.0.21
|
|
14
|
+
- @herbertgao/pi-subagents@0.26.1
|
|
15
|
+
|
|
3
16
|
## 2026.11.16
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @herbertgao/pi-agency
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#397](https://github.com/HerbertGao/pi-extensions/pull/397) [`42647d1`](https://github.com/HerbertGao/pi-extensions/commit/42647d16b171f766da6135fc937bd087e005a161) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Label an `Agent` run by identity: a registered type (Code Reviewer) keeps its type name while a named generic run shows its own `name`, in both the ccstyle transcript row and the pi-subagents badges. The `name` parameter accepts any characters — labels show it as given, `@handles` are slugged. `agency_register` seats catalog personas as session-scoped agent types over the new `subagents:rpc:register-agents` bus channels: the persona body becomes the system prompt, the card name and color become the label and badge, and the types vanish at the next session start without ever shadowing file-loaded agents.
|
|
8
|
+
|
|
3
9
|
## 0.1.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -24,7 +24,9 @@ The catalog location is fixed at `~/.agency-agents`. `agency_dispatch` also need
|
|
|
24
24
|
- `max_turns` is omitted unless you pass it, so a run decides when it is done; set it only to bound a runaway.
|
|
25
25
|
- `record_dir` must be absolute and used by one dispatch at a time. It receives `<id>.prompt.txt` and `<id>.return.txt` with mode `0600`. The call fails before any dispatch if one of those files already exists.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
`agency_register({ personas, tools? })` registers catalog personas as session-scoped pi-subagents agent types over its RPC bus and returns the type names to pass as `subagent_type`. The persona body becomes the type's system prompt, the card name becomes the label, and the card color becomes the badge — a seat shows as `MCP Builder` with its color instead of `general-purpose`. `tools: "none"` gives the type no tools at all; the default `"builtin"` keeps pi's built-in tools. Types vanish at the next session start, never shadow file-loaded agents, and need `@herbertgao/pi-subagents` on the event bus — an older or upstream pi-subagents answers nothing and the call fails, so the seat falls back to carrying the persona file's absolute path.
|
|
28
|
+
|
|
29
|
+
All three tools return `structuredContent`, so codemode scripts receive objects instead of text.
|
|
28
30
|
|
|
29
31
|
```js
|
|
30
32
|
const { results } = await tools.agency_search({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from "node:crypto"
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto"
|
|
2
2
|
import {
|
|
3
3
|
existsSync,
|
|
4
4
|
mkdirSync,
|
|
@@ -129,8 +129,11 @@ export function searchCatalog(
|
|
|
129
129
|
.slice(0, limit)
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
/** A catalog persona
|
|
133
|
-
export function
|
|
132
|
+
/** A catalog persona, frontmatter and body, path-guarded like every loader here. */
|
|
133
|
+
export function loadPersonaEntry(
|
|
134
|
+
root: string,
|
|
135
|
+
persona: string,
|
|
136
|
+
): { name: string; description: string; color?: string; body: string } {
|
|
134
137
|
const base = realRoot(root)
|
|
135
138
|
const file = realpathSync(isAbsolute(persona) ? persona : join(base, persona))
|
|
136
139
|
if (!file.startsWith(base + sep) || !file.endsWith(".md")) {
|
|
@@ -143,7 +146,21 @@ export function loadPersona(root: string, persona: string): string {
|
|
|
143
146
|
if (/<\/?persona>/i.test(body)) {
|
|
144
147
|
throw new Error(`${persona} contains a reserved <persona> delimiter`)
|
|
145
148
|
}
|
|
146
|
-
return
|
|
149
|
+
return {
|
|
150
|
+
name: frontmatter.name,
|
|
151
|
+
description:
|
|
152
|
+
typeof frontmatter.description === "string"
|
|
153
|
+
? frontmatter.description
|
|
154
|
+
: `${persona} has no persona description`,
|
|
155
|
+
color:
|
|
156
|
+
typeof frontmatter.color === "string" ? frontmatter.color : undefined,
|
|
157
|
+
body,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A catalog persona's body without frontmatter. */
|
|
162
|
+
export function loadPersona(root: string, persona: string): string {
|
|
163
|
+
return loadPersonaEntry(root, persona).body
|
|
147
164
|
}
|
|
148
165
|
|
|
149
166
|
/** Fills `{{persona}}` and `{{shared}}` in one pass, so inserted text is never rescanned or `$`-expanded. */
|
|
@@ -200,7 +217,53 @@ export function dropPlaceholders(args: unknown): any {
|
|
|
200
217
|
)
|
|
201
218
|
}
|
|
202
219
|
|
|
203
|
-
|
|
220
|
+
/** The slice of pi's event bus the RPC client needs — same shape pi-subagents handles. */
|
|
221
|
+
export interface AgencyEvents {
|
|
222
|
+
on(event: string, handler: (data: unknown) => void): () => void
|
|
223
|
+
emit(event: string, data: unknown): void
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export type AgencyToolsOptions = {
|
|
227
|
+
/** pi.events; agency_register needs it to reach pi-subagents' RPC bus. */
|
|
228
|
+
events?: AgencyEvents
|
|
229
|
+
/** Reply timeout for the register RPC; tests shrink it. */
|
|
230
|
+
rpcTimeoutMs?: number
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Call pi-subagents' register-agents RPC and await its reply envelope. */
|
|
234
|
+
export async function rpcRegisterAgents(
|
|
235
|
+
events: AgencyEvents,
|
|
236
|
+
agents: Array<Record<string, string>>,
|
|
237
|
+
tools: "none" | "builtin",
|
|
238
|
+
timeoutMs: number,
|
|
239
|
+
): Promise<void> {
|
|
240
|
+
const requestId = randomUUID()
|
|
241
|
+
const channel = `subagents:rpc:register-agents:reply:${requestId}`
|
|
242
|
+
return new Promise((resolve, reject) => {
|
|
243
|
+
let timer: ReturnType<typeof setTimeout>
|
|
244
|
+
const unsub = events.on(channel, (raw) => {
|
|
245
|
+
clearTimeout(timer)
|
|
246
|
+
unsub()
|
|
247
|
+
const reply = raw as { success: true } | { success: false; error: string }
|
|
248
|
+
if (reply.success) resolve()
|
|
249
|
+
else reject(new Error(reply.error))
|
|
250
|
+
})
|
|
251
|
+
timer = setTimeout(() => {
|
|
252
|
+
unsub()
|
|
253
|
+
reject(
|
|
254
|
+
new Error(
|
|
255
|
+
`pi-subagents did not answer register-agents within ${timeoutMs}ms; it may be missing or too old for ephemeral agent types`,
|
|
256
|
+
),
|
|
257
|
+
)
|
|
258
|
+
}, timeoutMs)
|
|
259
|
+
events.emit("subagents:rpc:register-agents", { requestId, agents, tools })
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function agencyTools(
|
|
264
|
+
root = CATALOG_ROOT,
|
|
265
|
+
options: AgencyToolsOptions = {},
|
|
266
|
+
) {
|
|
204
267
|
const search = defineTool({
|
|
205
268
|
name: "agency_search",
|
|
206
269
|
label: "Agency Search",
|
|
@@ -397,7 +460,7 @@ export function agencyTools(root = CATALOG_ROOT) {
|
|
|
397
460
|
for (const run of runs) record(`${run.id}.prompt.txt`, run.prompt)
|
|
398
461
|
}
|
|
399
462
|
|
|
400
|
-
const
|
|
463
|
+
const spawnOptions = Object.fromEntries(
|
|
401
464
|
Object.entries({
|
|
402
465
|
model: params.model,
|
|
403
466
|
thinking: params.thinking,
|
|
@@ -414,7 +477,7 @@ export function agencyTools(root = CATALOG_ROOT) {
|
|
|
414
477
|
prompt: run.prompt,
|
|
415
478
|
run_in_background: false,
|
|
416
479
|
isolated: params.isolated ?? true,
|
|
417
|
-
...
|
|
480
|
+
...spawnOptions,
|
|
418
481
|
}),
|
|
419
482
|
),
|
|
420
483
|
)
|
|
@@ -475,11 +538,90 @@ export function agencyTools(root = CATALOG_ROOT) {
|
|
|
475
538
|
},
|
|
476
539
|
})
|
|
477
540
|
|
|
478
|
-
|
|
541
|
+
const register = defineTool({
|
|
542
|
+
name: "agency_register",
|
|
543
|
+
label: "Agency Register",
|
|
544
|
+
description:
|
|
545
|
+
"Register catalog personas as session-scoped pi-subagents agent types and return the type names to pass as `subagent_type` to Agent. The persona's body becomes the type's system prompt, its card name becomes the agent's label, and its card color becomes the badge — so a seat shows as its persona instead of general-purpose. `tools: \"none\"` gives the type no tools at all (advisory seats); the default `\"builtin\"` keeps pi's built-in tools. Types vanish at the next session start and never shadow agents loaded from files. Needs pi-subagents on the session's event bus; if it is missing or too old the call fails and a seat can still be given the persona file's absolute path instead.",
|
|
546
|
+
promptSnippet: "Seat catalog personas as labeled, colored agent types",
|
|
547
|
+
prepareArguments: dropPlaceholders,
|
|
548
|
+
promptGuidelines: [
|
|
549
|
+
"For Agency Agents personas, use agency_search to pick the seat, agency_register to turn it into a session-scoped agent type, and one Agent call per seat with that type; without registration the call carries the persona's absolute path instead. Reach for agency_dispatch only for bulk work that does not need a run per row.",
|
|
550
|
+
],
|
|
551
|
+
parameters: Type.Object({
|
|
552
|
+
personas: Type.Array(Type.String(), {
|
|
553
|
+
minItems: 1,
|
|
554
|
+
description:
|
|
555
|
+
"Persona files relative to the catalog, e.g. security/security-appsec-engineer.md, or absolute paths inside it.",
|
|
556
|
+
}),
|
|
557
|
+
tools: Type.Optional(
|
|
558
|
+
Type.Union([Type.Literal("none"), Type.Literal("builtin")], {
|
|
559
|
+
description:
|
|
560
|
+
'The type\'s tool surface: "none" for tool-less advisory seats, "builtin" (default) for pi\'s built-in tools.',
|
|
561
|
+
}),
|
|
562
|
+
),
|
|
563
|
+
}),
|
|
564
|
+
outputSchema: Type.Object({
|
|
565
|
+
results: Type.Array(
|
|
566
|
+
Type.Object({
|
|
567
|
+
persona: Type.String(),
|
|
568
|
+
type: Type.String(),
|
|
569
|
+
color: NullableString,
|
|
570
|
+
tools: Type.Union([Type.Literal("none"), Type.Literal("builtin")]),
|
|
571
|
+
}),
|
|
572
|
+
),
|
|
573
|
+
}),
|
|
574
|
+
async execute(_toolCallId, params) {
|
|
575
|
+
const events = options.events
|
|
576
|
+
if (!events) {
|
|
577
|
+
throw new Error("agency_register needs the pi.events bus")
|
|
578
|
+
}
|
|
579
|
+
const tools = params.tools ?? "builtin"
|
|
580
|
+
const entries = params.personas.map((persona) => {
|
|
581
|
+
const card = loadPersonaEntry(root, persona)
|
|
582
|
+
return { persona, card }
|
|
583
|
+
})
|
|
584
|
+
await rpcRegisterAgents(
|
|
585
|
+
events,
|
|
586
|
+
entries.map(({ card }) => ({
|
|
587
|
+
name: card.name,
|
|
588
|
+
description: card.description,
|
|
589
|
+
systemPrompt: card.body,
|
|
590
|
+
...(card.color ? { color: card.color } : {}),
|
|
591
|
+
})),
|
|
592
|
+
tools,
|
|
593
|
+
options.rpcTimeoutMs ?? 2000,
|
|
594
|
+
)
|
|
595
|
+
const results = entries.map(({ persona, card }) => ({
|
|
596
|
+
persona,
|
|
597
|
+
type: card.name,
|
|
598
|
+
color: card.color ?? null,
|
|
599
|
+
tools,
|
|
600
|
+
}))
|
|
601
|
+
const text =
|
|
602
|
+
results
|
|
603
|
+
.map(
|
|
604
|
+
(result) =>
|
|
605
|
+
`- ${result.persona} → subagent_type: ${result.type}${result.color ? ` (${result.color})` : ""} [${result.tools}]`,
|
|
606
|
+
)
|
|
607
|
+
.join("\n") +
|
|
608
|
+
"\n\nTypes vanish at the next session start; after a session switch or resume, register again before spawning."
|
|
609
|
+
return {
|
|
610
|
+
content: [{ type: "text", text }],
|
|
611
|
+
details: {},
|
|
612
|
+
structuredContent: { results },
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
})
|
|
616
|
+
|
|
617
|
+
return { search, dispatch, register }
|
|
479
618
|
}
|
|
480
619
|
|
|
481
620
|
export default function piAgency(pi: ExtensionAPI): void {
|
|
482
|
-
const { search, dispatch } = agencyTools(
|
|
621
|
+
const { search, dispatch, register } = agencyTools(CATALOG_ROOT, {
|
|
622
|
+
events: pi.events,
|
|
623
|
+
})
|
|
483
624
|
pi.registerTool(search)
|
|
484
625
|
pi.registerTool(dispatch)
|
|
626
|
+
pi.registerTool(register)
|
|
485
627
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @herbertgao/pi-cc-extensions
|
|
2
2
|
|
|
3
|
+
## 1.0.21-local.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#397](https://github.com/HerbertGao/pi-extensions/pull/397) [`42647d1`](https://github.com/HerbertGao/pi-extensions/commit/42647d16b171f766da6135fc937bd087e005a161) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Label an `Agent` run by identity: a registered type (Code Reviewer) keeps its type name while a named generic run shows its own `name`, in both the ccstyle transcript row and the pi-subagents badges. The `name` parameter accepts any characters — labels show it as given, `@handles` are slugged. `agency_register` seats catalog personas as session-scoped agent types over the new `subagents:rpc:register-agents` bus channels: the persona body becomes the system prompt, the card name and color become the label and badge, and the types vanish at the next session start without ever shadowing file-loaded agents.
|
|
8
|
+
|
|
3
9
|
## 1.0.21-local.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -269,11 +269,16 @@ export function toolCallSummary(
|
|
|
269
269
|
return { main: title, detail: "", payload: clip(args.agent_id) };
|
|
270
270
|
}
|
|
271
271
|
if (name === "agent" || name === "agents") {
|
|
272
|
-
|
|
272
|
+
// general-purpose 是无身份的默认类型,命名运行的 name 优先;其余类型(Code Reviewer 等)
|
|
273
|
+
// 自身就是身份,类型名优先于 name。`·` 分隔后描述作灰色载荷:单卡与组内行同一写法。
|
|
274
|
+
const type = args.subagent_type ?? args.agent_type ?? args.agent;
|
|
275
|
+
const displayName =
|
|
276
|
+
typeof type === "string" && type.toLowerCase() !== "general-purpose"
|
|
277
|
+
? type
|
|
278
|
+
: (args.name ?? type);
|
|
273
279
|
const description =
|
|
274
280
|
typeof args.description === "string" ? oneLine(args.description, clipLimit()) : "";
|
|
275
281
|
if (typeof displayName === "string" && displayName) {
|
|
276
|
-
// 类型进标题,`·` 分隔后描述作灰色载荷:单卡与组内行同一写法。
|
|
277
282
|
return {
|
|
278
283
|
main: `${title} ${displayName}`,
|
|
279
284
|
detail: "",
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.26.1-local.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#397](https://github.com/HerbertGao/pi-extensions/pull/397) [`42647d1`](https://github.com/HerbertGao/pi-extensions/commit/42647d16b171f766da6135fc937bd087e005a161) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Label an `Agent` run by identity: a registered type (Code Reviewer) keeps its type name while a named generic run shows its own `name`, in both the ccstyle transcript row and the pi-subagents badges. The `name` parameter accepts any characters — labels show it as given, `@handles` are slugged. `agency_register` seats catalog personas as session-scoped agent types over the new `subagents:rpc:register-agents` bus channels: the persona body becomes the system prompt, the card name and color become the label and badge, and the types vanish at the next session start without ever shadowing file-loaded agents.
|
|
8
|
+
|
|
3
9
|
## 0.26.1-local.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Driving subagents from another extension
|
|
2
2
|
|
|
3
|
-
Another pi extension can spawn a subagent, listen for subagent completion, read the result, steer and stop the run — all over the `pi.events` bus, without importing this package directly.
|
|
3
|
+
Another pi extension can spawn a subagent, listen for subagent completion, read the result, steer and stop the run — all over the `pi.events` bus, without importing this package directly. Seven request/reply channels (`subagents:rpc:ping`, `subagents:rpc:spawn`, `subagents:rpc:stop`, `subagents:rpc:consume`, `subagents:rpc:steer`, `subagents:rpc:register-agents`, `subagents:rpc:unregister-agents`), the lifecycle events in README's [event table](../README.md#events), one per-message usage event (`subagents:usage`), one terminal `subagents:disposed`, and one in-process registry at `Symbol.for("pi-subagents:manager")`.
|
|
4
4
|
|
|
5
5
|
The thing worth understanding up front is that **the bus is in-process.** Every "RPC" call here is a synchronous `pi.events.emit` into the same event loop, and every reply comes back the same way. That single fact explains most of what follows: why `signal` and the `on*` callbacks work on a spawn payload at all, why a `consume` fired inside a `subagents:completed` handler lands _before_ the notification decision has been made, and why none of this survives a real process boundary.
|
|
6
6
|
|
|
@@ -138,6 +138,12 @@ One related thing that lives nowhere else: on every top-level settle, pi-subagen
|
|
|
138
138
|
|
|
139
139
|
It takes an id only, enforces the same top-level ownership guard as stop, and answers `Agent is not running` for a record that has settled. A message queued before the agent's session exists is flushed when the session is created, exactly as the tool's steer is. A successful steer emits `subagents:steered` `{ id, message }`, as every steer path does. Like `consume`, it is outside the `ping` version handshake: an older build has no handler and the request times out on your side, so give it a timeout and treat expiry as "not available here".
|
|
140
140
|
|
|
141
|
+
## Registering session-scoped agent types
|
|
142
|
+
|
|
143
|
+
`subagents:rpc:register-agents` `{ requestId, agents: [{ name, description, systemPrompt, color? }], tools?: "none" | "builtin" }` registers ephemeral agent types — spawnable immediately as `subagent_type`, surviving every agent-file reload, and cleared on the next `session_start`. The payload is deliberately narrow: the system prompt is applied in replace mode, extension and skill access is refused, and the only tool choice is none or the built-ins. A file-loaded agent with the same name (case-insensitively) wins — the overlay never shadows the user's own agents. `subagents:rpc:unregister-agents` `{ requestId, names }` removes types by name; file-backed types are untouched.
|
|
144
|
+
|
|
145
|
+
Like `consume` and `steer`, both channels are outside the `ping` version handshake: an older build has no handler and never replies, so give the call a timeout and treat expiry as "not available here". The intended caller is `@herbertgao/pi-agency`, which seats an Agency Agents catalog persona this way — the persona body as system prompt, the card name as the agent's label, the card color as its badge.
|
|
146
|
+
|
|
141
147
|
## The manager registry
|
|
142
148
|
|
|
143
149
|
`globalThis[Symbol.for("pi-subagents:manager")]` (`MANAGER_KEY` and `registryEntry`, `src/index.ts`) is a second integration surface — the standard Node cross-package singleton pattern, no bus involved:
|
|
@@ -192,15 +192,19 @@ export function renderAgentName(
|
|
|
192
192
|
type: string | undefined,
|
|
193
193
|
theme: AgentNameTheme,
|
|
194
194
|
style: AgentNameStyle = {},
|
|
195
|
-
/** A run's own name
|
|
195
|
+
/** A run's own name. It outranks only the generic default type; a real type
|
|
196
|
+
* (Code Reviewer) is itself the identity and keeps its own label. */
|
|
196
197
|
label?: string,
|
|
197
198
|
): string {
|
|
198
199
|
if (!type) {
|
|
199
200
|
return renderAgentNameLabel(label ?? "Agent", undefined, theme, style)
|
|
200
201
|
}
|
|
201
202
|
const config = getConfig(type)
|
|
203
|
+
// general-purpose is the identity-less default: a run's name is the better
|
|
204
|
+
// label there. Any other type is itself the identity and wins over the name.
|
|
205
|
+
const generic = type.toLowerCase() === "general-purpose"
|
|
202
206
|
return renderAgentNameLabel(
|
|
203
|
-
label ?? config.displayName,
|
|
207
|
+
generic ? (label ?? config.displayName) : config.displayName,
|
|
204
208
|
config.color,
|
|
205
209
|
theme,
|
|
206
210
|
style,
|
|
@@ -86,14 +86,95 @@ export function buildAgentRegistry(
|
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Register agents into the unified registry.
|
|
89
|
-
* Starts with DEFAULT_AGENTS, then overlays user agents (overrides defaults with same name)
|
|
89
|
+
* Starts with DEFAULT_AGENTS, then overlays user agents (overrides defaults with same name),
|
|
90
|
+
* then the ephemeral overlay (see `registerEphemeralAgents`).
|
|
90
91
|
* Disabled agents (enabled === false) are kept in the registry but excluded from spawning.
|
|
91
92
|
*/
|
|
92
93
|
export function registerAgents(userAgents: Map<string, AgentConfig>): void {
|
|
93
94
|
agents.clear()
|
|
95
|
+
// The rebuilt registry is file/default-backed throughout, so no key in it
|
|
96
|
+
// is ours any more — drop ownership before the overlay re-applies.
|
|
97
|
+
ephemeralOwned.clear()
|
|
94
98
|
for (const [name, config] of buildAgentRegistry(userAgents)) {
|
|
95
99
|
agents.set(name, config)
|
|
96
100
|
}
|
|
101
|
+
overlayEphemeral(agents)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Ephemeral agents: registered at runtime by another extension over the RPC
|
|
106
|
+
* bus (pi-agency seating a catalog persona), overlaid after every file load so
|
|
107
|
+
* they survive `reloadCustomAgents()` — which runs before every spawn and
|
|
108
|
+
* would otherwise wipe them. A file-loaded agent with the same name wins: user
|
|
109
|
+
* files are the authority and an ephemeral overlay never shadows them. The
|
|
110
|
+
* overlay is cleared on each session_start, so a type lives for the current
|
|
111
|
+
* session only.
|
|
112
|
+
*/
|
|
113
|
+
const ephemeralAgents = new Map<string, AgentConfig>()
|
|
114
|
+
/** Registry keys currently served by the ephemeral overlay (not file-backed). */
|
|
115
|
+
const ephemeralOwned = new Set<string>()
|
|
116
|
+
|
|
117
|
+
/** Overlay the ephemeral types onto a registry; returns the names applied. */
|
|
118
|
+
function overlayEphemeral(registry: Map<string, AgentConfig>): string[] {
|
|
119
|
+
const applied: string[] = []
|
|
120
|
+
for (const [name, config] of ephemeralAgents) {
|
|
121
|
+
const key = resolveKeyIn(registry, name)
|
|
122
|
+
// A key we do not own is file- or default-backed: the user's type wins
|
|
123
|
+
// and this registration is skipped — never a silent shadow. A key we own
|
|
124
|
+
// is our own previous entry, replaced in place. Both checks are
|
|
125
|
+
// case-insensitive, like spawn resolution.
|
|
126
|
+
if (key !== undefined && !ephemeralOwned.has(key)) continue
|
|
127
|
+
if (key !== undefined && key !== name) {
|
|
128
|
+
registry.delete(key)
|
|
129
|
+
ephemeralOwned.delete(key)
|
|
130
|
+
}
|
|
131
|
+
registry.set(name, config)
|
|
132
|
+
ephemeralOwned.add(name)
|
|
133
|
+
applied.push(name)
|
|
134
|
+
}
|
|
135
|
+
return applied
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Register session-scoped agent types at runtime; spawnable immediately.
|
|
139
|
+
* Returns the names actually applied, so a caller can fail loudly when a name
|
|
140
|
+
* collides with a file-loaded or default type instead of shadowing it. */
|
|
141
|
+
export function registerEphemeralAgents(
|
|
142
|
+
entries: Map<string, AgentConfig>,
|
|
143
|
+
): string[] {
|
|
144
|
+
for (const [name, config] of entries) {
|
|
145
|
+
// A case-variant of an existing ephemeral key replaces it in place, so
|
|
146
|
+
// one persona cannot leave a second, unreachable entry behind.
|
|
147
|
+
const existing = resolveKeyIn(ephemeralAgents, name)
|
|
148
|
+
if (existing !== undefined && existing !== name)
|
|
149
|
+
ephemeralAgents.delete(existing)
|
|
150
|
+
ephemeralAgents.set(name, config)
|
|
151
|
+
}
|
|
152
|
+
const applied = overlayEphemeral(agents)
|
|
153
|
+
// A skipped name collided with a file/default type: drop it from the store
|
|
154
|
+
// as well, so it cannot silently apply later if that type disappears.
|
|
155
|
+
for (const name of entries.keys()) {
|
|
156
|
+
if (!applied.includes(name)) ephemeralAgents.delete(name)
|
|
157
|
+
}
|
|
158
|
+
// Report only this call's names: the overlay re-applies the whole store, so
|
|
159
|
+
// returning `applied` would list types the caller never sent.
|
|
160
|
+
return [...entries.keys()].filter((name) => applied.includes(name))
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Remove ephemeral types by name (case-insensitive); file-backed types stay. */
|
|
164
|
+
export function unregisterEphemeralAgents(names: readonly string[]): void {
|
|
165
|
+
for (const name of names) {
|
|
166
|
+
const key = resolveKeyIn(ephemeralAgents, name)
|
|
167
|
+
if (!key) continue
|
|
168
|
+
ephemeralAgents.delete(key)
|
|
169
|
+
if (ephemeralOwned.delete(key)) agents.delete(key)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Drop every ephemeral type; file-backed types stay. Called on session_start. */
|
|
174
|
+
export function clearEphemeralAgents(): void {
|
|
175
|
+
for (const key of ephemeralOwned) agents.delete(key)
|
|
176
|
+
ephemeralOwned.clear()
|
|
177
|
+
ephemeralAgents.clear()
|
|
97
178
|
}
|
|
98
179
|
|
|
99
180
|
/** Case-insensitive key resolution within a registry. */
|
|
@@ -14,9 +14,13 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { isTopLevelAgent } from "./agent-manager.js"
|
|
17
|
+
import {
|
|
18
|
+
registerEphemeralAgents,
|
|
19
|
+
unregisterEphemeralAgents,
|
|
20
|
+
} from "./agent-types.js"
|
|
17
21
|
import { type ModelRegistry, resolveModel } from "./model-resolver.js"
|
|
18
22
|
import { checkModelScope } from "./model-scope.js"
|
|
19
|
-
import type { AgentRecord } from "./types.js"
|
|
23
|
+
import type { AgentConfig, AgentRecord } from "./types.js"
|
|
20
24
|
|
|
21
25
|
/** Minimal event bus interface needed by the RPC handlers. */
|
|
22
26
|
export interface EventBus {
|
|
@@ -78,6 +82,8 @@ export interface RpcHandle {
|
|
|
78
82
|
unsubStop: () => void
|
|
79
83
|
unsubConsume: () => void
|
|
80
84
|
unsubSteer: () => void
|
|
85
|
+
unsubRegisterAgents: () => void
|
|
86
|
+
unsubUnregisterAgents: () => void
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
/**
|
|
@@ -105,6 +111,45 @@ function handleRpc<P extends { requestId: string }>(
|
|
|
105
111
|
})
|
|
106
112
|
}
|
|
107
113
|
|
|
114
|
+
/** Validate one register-agents payload entry into an AgentConfig. Narrow on
|
|
115
|
+
* purpose: no tool allowlist beyond none/builtin, no extension or skill access,
|
|
116
|
+
* replace-mode system prompt — a persona is role text, not an executable agent
|
|
117
|
+
* definition. */
|
|
118
|
+
export function ephemeralAgentConfig(
|
|
119
|
+
candidate: unknown,
|
|
120
|
+
index: number,
|
|
121
|
+
): [string, AgentConfig] {
|
|
122
|
+
if (typeof candidate !== "object" || candidate === null)
|
|
123
|
+
throw new Error(`agents[${index}] must be an object`)
|
|
124
|
+
const { name, description, systemPrompt, color } = candidate as Record<
|
|
125
|
+
string,
|
|
126
|
+
unknown
|
|
127
|
+
>
|
|
128
|
+
if (typeof name !== "string" || !name.trim() || name.length > 64)
|
|
129
|
+
throw new Error(`agents[${index}].name must be 1-64 characters`)
|
|
130
|
+
if (typeof description !== "string" || !description.trim())
|
|
131
|
+
throw new Error(`agents[${index}].description must be a non-empty string`)
|
|
132
|
+
if (typeof systemPrompt !== "string" || !systemPrompt.trim())
|
|
133
|
+
throw new Error(`agents[${index}].systemPrompt must be a non-empty string`)
|
|
134
|
+
if (color !== undefined && (typeof color !== "string" || !color))
|
|
135
|
+
throw new Error(
|
|
136
|
+
`agents[${index}].color must be a non-empty string when given`,
|
|
137
|
+
)
|
|
138
|
+
const trimmed = name.trim()
|
|
139
|
+
return [
|
|
140
|
+
trimmed,
|
|
141
|
+
{
|
|
142
|
+
name: trimmed,
|
|
143
|
+
description,
|
|
144
|
+
systemPrompt,
|
|
145
|
+
color: typeof color === "string" ? color : undefined,
|
|
146
|
+
promptMode: "replace",
|
|
147
|
+
extensions: false,
|
|
148
|
+
skills: false,
|
|
149
|
+
},
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
|
|
108
153
|
/**
|
|
109
154
|
* Register ping, spawn, stop, consume, and steer RPC handlers on the event bus.
|
|
110
155
|
* Returns unsub functions for cleanup.
|
|
@@ -247,5 +292,65 @@ export function registerRpcHandlers(deps: RpcDeps): RpcHandle {
|
|
|
247
292
|
throw new Error("Agent is not running")
|
|
248
293
|
})
|
|
249
294
|
|
|
250
|
-
|
|
295
|
+
// Register session-scoped agent types from another extension (pi-agency
|
|
296
|
+
// seating a catalog persona). Additive like consume/steer: outside the ping
|
|
297
|
+
// version handshake — an older pi-subagents simply never replies and the
|
|
298
|
+
// caller's timeout is the discovery signal.
|
|
299
|
+
const unsubRegisterAgents = handleRpc<{
|
|
300
|
+
requestId: string
|
|
301
|
+
agents: unknown[]
|
|
302
|
+
tools?: unknown
|
|
303
|
+
}>(events, "subagents:rpc:register-agents", ({ agents, tools }) => {
|
|
304
|
+
if (!Array.isArray(agents) || agents.length === 0)
|
|
305
|
+
throw new Error("register-agents requires a non-empty agents array")
|
|
306
|
+
if (tools !== undefined && tools !== "none" && tools !== "builtin")
|
|
307
|
+
throw new Error('tools must be "none" or "builtin"')
|
|
308
|
+
const builtinToolNames = tools === "none" ? [] : undefined
|
|
309
|
+
const entries = new Map<string, AgentConfig>()
|
|
310
|
+
const seen = new Map<string, number>()
|
|
311
|
+
agents.forEach((candidate, index) => {
|
|
312
|
+
const [name, config] = ephemeralAgentConfig(candidate, index)
|
|
313
|
+
const lower = name.toLowerCase()
|
|
314
|
+
const firstIndex = seen.get(lower)
|
|
315
|
+
if (firstIndex !== undefined)
|
|
316
|
+
throw new Error(
|
|
317
|
+
`agents[${index}].name "${name}" duplicates agents[${firstIndex}]`,
|
|
318
|
+
)
|
|
319
|
+
seen.set(lower, index)
|
|
320
|
+
entries.set(name, { ...config, builtinToolNames })
|
|
321
|
+
})
|
|
322
|
+
const applied = registerEphemeralAgents(entries)
|
|
323
|
+
// A skipped name collides with a file-loaded or default type: fail loudly
|
|
324
|
+
// rather than let the caller spawn that type believing it is the persona.
|
|
325
|
+
const skipped = [...entries.keys()].filter(
|
|
326
|
+
(name) => !applied.includes(name),
|
|
327
|
+
)
|
|
328
|
+
if (skipped.length > 0)
|
|
329
|
+
throw new Error(
|
|
330
|
+
`agent type already exists: ${skipped.map((name) => `"${name}"`).join(", ")}` +
|
|
331
|
+
(applied.length > 0
|
|
332
|
+
? ` (applied: ${applied.map((name) => `"${name}"`).join(", ")})`
|
|
333
|
+
: ""),
|
|
334
|
+
)
|
|
335
|
+
return { agents: applied }
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
const unsubUnregisterAgents = handleRpc<{
|
|
339
|
+
requestId: string
|
|
340
|
+
names: unknown
|
|
341
|
+
}>(events, "subagents:rpc:unregister-agents", ({ names }) => {
|
|
342
|
+
if (!Array.isArray(names) || names.some((n) => typeof n !== "string"))
|
|
343
|
+
throw new Error("unregister-agents requires an array of type names")
|
|
344
|
+
unregisterEphemeralAgents(names)
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
unsubPing,
|
|
349
|
+
unsubSpawn,
|
|
350
|
+
unsubStop,
|
|
351
|
+
unsubConsume,
|
|
352
|
+
unsubSteer,
|
|
353
|
+
unsubRegisterAgents,
|
|
354
|
+
unsubUnregisterAgents,
|
|
355
|
+
}
|
|
251
356
|
}
|
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
steerAgent,
|
|
55
55
|
} from "./agent-runner.js"
|
|
56
56
|
import {
|
|
57
|
+
clearEphemeralAgents,
|
|
57
58
|
formatAgentTypeList,
|
|
58
59
|
getAgentConfig,
|
|
59
60
|
getAvailableTypes,
|
|
@@ -1151,6 +1152,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
1151
1152
|
// resumed session all land here, and any of them may follow a `pi install`
|
|
1152
1153
|
// that added a package the cached root list predates.
|
|
1153
1154
|
invalidatePackageCache()
|
|
1155
|
+
// Ephemeral types live for the current session only: a new or resumed
|
|
1156
|
+
// session starts clean, so a persona's registration never outlives the
|
|
1157
|
+
// run that seated it.
|
|
1158
|
+
clearEphemeralAgents()
|
|
1154
1159
|
reloadCustomAgents()
|
|
1155
1160
|
if (ctx.hasUI) {
|
|
1156
1161
|
widget.setUICtx(ctx.ui)
|
|
@@ -1501,6 +1506,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1501
1506
|
rpcHandle?.unsubPing()
|
|
1502
1507
|
rpcHandle?.unsubConsume()
|
|
1503
1508
|
rpcHandle?.unsubSteer()
|
|
1509
|
+
rpcHandle?.unsubRegisterAgents()
|
|
1510
|
+
rpcHandle?.unsubUnregisterAgents()
|
|
1504
1511
|
rpcHandle = undefined
|
|
1505
1512
|
currentCtx = undefined
|
|
1506
1513
|
// Only release the global slot if this activation claimed it — a child
|
|
@@ -2197,11 +2204,11 @@ Terse command-style prompts produce shallow, generic work.
|
|
|
2197
2204
|
name: Type.Optional(
|
|
2198
2205
|
Type.String({
|
|
2199
2206
|
description:
|
|
2200
|
-
'Optional memorable name for this agent, e.g. "auth-audit", so it can be addressed as `@name` at the prompt and by steer_subagent / get_subagent_result.
|
|
2207
|
+
'Optional memorable name for this agent, e.g. "auth-audit", so it can be addressed as `@name` at the prompt and by steer_subagent / get_subagent_result. Any characters are accepted; the `@handle` is slugged from it (lowercase letters, digits, `_`, `-`) while UI labels show it as given, spaces included. Worth setting when several agents of the same type run at once; omit for one-off work. The agent stays reachable by its type either way.',
|
|
2201
2208
|
}),
|
|
2202
2209
|
),
|
|
2203
2210
|
subagent_type: Type.String({
|
|
2204
|
-
description: `The type of specialized agent to use. Available types: ${getAvailableTypes().join(", ")}. Custom agents from .pi/agents/*.md (project) or ${getAgentDir()}/agents/*.md (global) are also available.`,
|
|
2211
|
+
description: `The type of specialized agent to use. Available types: ${getAvailableTypes().join(", ")}. Custom agents from .pi/agents/*.md (project) or ${getAgentDir()}/agents/*.md (global) are also available, as are types another tool registered for this session — a list outside this description is usable, not invalid.`,
|
|
2205
2212
|
}),
|
|
2206
2213
|
model: Type.Optional(
|
|
2207
2214
|
Type.String({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herbertgao/pi-extensions",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.17",
|
|
4
4
|
"description": "Aggregate installer for HerbertGao-maintained Pi extensions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extensions",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"@ast-grep/cli": "0.51.1",
|
|
40
40
|
"@ast-grep/napi": "^0.51.0",
|
|
41
41
|
"@dietrichgebert/ponytail": "5.3.3",
|
|
42
|
-
"@herbertgao/pi-agency": "0.1.
|
|
42
|
+
"@herbertgao/pi-agency": "0.1.4",
|
|
43
43
|
"@herbertgao/pi-bark": "0.2.2",
|
|
44
|
-
"@herbertgao/pi-cc-extensions": "1.0.21-local.
|
|
44
|
+
"@herbertgao/pi-cc-extensions": "1.0.21-local.2",
|
|
45
45
|
"@herbertgao/pi-impeccable": "0.6.0",
|
|
46
46
|
"@herbertgao/pi-inline-skill-commands": "0.1.1",
|
|
47
|
-
"@herbertgao/pi-subagents": "0.26.1-local.
|
|
47
|
+
"@herbertgao/pi-subagents": "0.26.1-local.2",
|
|
48
48
|
"@herbertgao/sol-pi": "0.4.3",
|
|
49
49
|
"@juicesharp/rpiv-ask-user-question": "2.15.0",
|
|
50
50
|
"@juicesharp/rpiv-config": "^2.15.0",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"js-yaml": "^5.2.2",
|
|
74
74
|
"linkedom": "^0.16.0",
|
|
75
75
|
"minimatch": "^11.0.4",
|
|
76
|
-
"nanoid": "^5.
|
|
76
|
+
"nanoid": "^5.1.16",
|
|
77
77
|
"p-limit": "^6.1.0",
|
|
78
78
|
"pi-antigravity": "0.14.0",
|
|
79
79
|
"pi-commandcode-provider": "0.8.6",
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
"pi-web-access": "0.48.0",
|
|
85
85
|
"pidusage": "^4.0.1",
|
|
86
86
|
"promise.try": "^2.0.1",
|
|
87
|
-
"turndown": "^7.2.
|
|
87
|
+
"turndown": "^7.2.4",
|
|
88
88
|
"turndown-plugin-gfm": "^1.0.2",
|
|
89
89
|
"unbash": "4.0.10",
|
|
90
|
-
"undici": "^8.
|
|
90
|
+
"undici": "^8.12.3",
|
|
91
91
|
"unpdf": "^1.6.2",
|
|
92
92
|
"vscode-jsonrpc": "^10.0.0",
|
|
93
93
|
"ws": "^8.21.0",
|