pi-herdsman 0.22.2 → 0.23.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/dist/index.js +180 -4
- package/dist/index.js.map +3 -3
- package/dist/integrations/pi-codex-context-sharing.js +42 -0
- package/dist/integrations/pi-codex-context-sharing.js.map +7 -0
- package/docs/guides/customizing-agents.md +32 -0
- package/docs/reference/agent.md +46 -0
- package/package.json +8 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// extension/integrations/pi-codex-context-sharing.ts
|
|
2
|
+
import { connectCodexContextSharing } from "@howaboua/pi-codex-conversion/context-sharing";
|
|
3
|
+
var BOOTSTRAP_EVENT = "pi-herdsman:managed-agent-bootstrap";
|
|
4
|
+
var PARTICIPANT_ID = "pi-codex/context-sharing";
|
|
5
|
+
function register(pi) {
|
|
6
|
+
const connection = connectCodexContextSharing(pi);
|
|
7
|
+
const offBootstrap = pi.events.on(BOOTSTRAP_EVENT, (value) => {
|
|
8
|
+
const event = value;
|
|
9
|
+
if (event?.protocol !== 1) return;
|
|
10
|
+
if (event.phase === "prepare") {
|
|
11
|
+
event.register(PARTICIPANT_ID, async () => {
|
|
12
|
+
const service = connection.service;
|
|
13
|
+
if (!service?.canCreateChild(event.context)) return void 0;
|
|
14
|
+
const identity = service.describe(event.context);
|
|
15
|
+
if (identity?.storage !== "remote") return void 0;
|
|
16
|
+
const { binding, adopt } = await service.createChild(event.context, {
|
|
17
|
+
name: event.agent
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
payload: JSON.stringify(binding),
|
|
21
|
+
commit: adopt
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (event.participant?.id !== PARTICIPANT_ID) return;
|
|
27
|
+
event.accept(async () => {
|
|
28
|
+
const service = connection.service;
|
|
29
|
+
if (!service)
|
|
30
|
+
throw new Error("Pi Codex Conversion context sharing is unavailable");
|
|
31
|
+
await service.bind(event.context, JSON.parse(event.participant.payload));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
pi.on("session_shutdown", () => {
|
|
35
|
+
offBootstrap();
|
|
36
|
+
connection.dispose();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
register as default
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=pi-codex-context-sharing.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../extension/integrations/pi-codex-context-sharing.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n ExtensionAPI,\n ExtensionContext,\n} from \"@earendil-works/pi-coding-agent\";\nimport { connectCodexContextSharing } from \"@howaboua/pi-codex-conversion/context-sharing\";\n\nconst BOOTSTRAP_EVENT = \"pi-herdsman:managed-agent-bootstrap\";\nconst PARTICIPANT_ID = \"pi-codex/context-sharing\";\n\ntype Preparation = {\n payload: string;\n commit?: () => void | Promise<void>;\n};\n\ntype PrepareEvent = {\n protocol: 1;\n phase: \"prepare\";\n context: ExtensionContext;\n agent: string;\n register(\n id: string,\n prepare: () => Preparation | undefined | Promise<Preparation | undefined>,\n ): void;\n};\n\ntype InitializeEvent = {\n protocol: 1;\n phase: \"initialize\";\n context: ExtensionContext;\n agent: string;\n participant: {\n id: string;\n payload: string;\n };\n accept(initialize: () => void | Promise<void>): void;\n};\n\ntype BootstrapEvent = PrepareEvent | InitializeEvent;\n\nexport default function register(pi: ExtensionAPI): void {\n const connection = connectCodexContextSharing(pi);\n\n const offBootstrap = pi.events.on(BOOTSTRAP_EVENT, (value) => {\n const event = value as BootstrapEvent;\n if (event?.protocol !== 1) return;\n\n if (event.phase === \"prepare\") {\n event.register(PARTICIPANT_ID, async () => {\n const service = connection.service;\n if (!service?.canCreateChild(event.context)) return undefined;\n\n const identity = service.describe(event.context);\n if (identity?.storage !== \"remote\") return undefined;\n\n const { binding, adopt } = await service.createChild(event.context, {\n name: event.agent,\n });\n\n return {\n payload: JSON.stringify(binding),\n commit: adopt,\n };\n });\n return;\n }\n\n if (event.participant?.id !== PARTICIPANT_ID) return;\n\n event.accept(async () => {\n const service = connection.service;\n if (!service)\n throw new Error(\"Pi Codex Conversion context sharing is unavailable\");\n\n await service.bind(event.context, JSON.parse(event.participant.payload));\n });\n });\n\n pi.on(\"session_shutdown\", () => {\n offBootstrap();\n connection.dispose();\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,kCAAkC;AAE3C,IAAM,kBAAkB;AACxB,IAAM,iBAAiB;AAgCR,SAAR,SAA0B,IAAwB;AACvD,QAAM,aAAa,2BAA2B,EAAE;AAEhD,QAAM,eAAe,GAAG,OAAO,GAAG,iBAAiB,CAAC,UAAU;AAC5D,UAAM,QAAQ;AACd,QAAI,OAAO,aAAa,EAAG;AAE3B,QAAI,MAAM,UAAU,WAAW;AAC7B,YAAM,SAAS,gBAAgB,YAAY;AACzC,cAAM,UAAU,WAAW;AAC3B,YAAI,CAAC,SAAS,eAAe,MAAM,OAAO,EAAG,QAAO;AAEpD,cAAM,WAAW,QAAQ,SAAS,MAAM,OAAO;AAC/C,YAAI,UAAU,YAAY,SAAU,QAAO;AAE3C,cAAM,EAAE,SAAS,MAAM,IAAI,MAAM,QAAQ,YAAY,MAAM,SAAS;AAAA,UAClE,MAAM,MAAM;AAAA,QACd,CAAC;AAED,eAAO;AAAA,UACL,SAAS,KAAK,UAAU,OAAO;AAAA,UAC/B,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,QAAI,MAAM,aAAa,OAAO,eAAgB;AAE9C,UAAM,OAAO,YAAY;AACvB,YAAM,UAAU,WAAW;AAC3B,UAAI,CAAC;AACH,cAAM,IAAI,MAAM,oDAAoD;AAEtE,YAAM,QAAQ,KAAK,MAAM,SAAS,KAAK,MAAM,MAAM,YAAY,OAAO,CAAC;AAAA,IACzE,CAAC;AAAA,EACH,CAAC;AAED,KAAG,GAAG,oBAAoB,MAAM;AAC9B,iBAAa;AACb,eAAW,QAAQ;AAAA,EACrB,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -362,3 +362,35 @@ session.
|
|
|
362
362
|
- [Agent-definition schema](../reference/agent-definition-schema.md)
|
|
363
363
|
- [`/agents` commands](../reference/commands.md)
|
|
364
364
|
- [Agent definitions](agent-definitions.md)
|
|
365
|
+
|
|
366
|
+
## Optional Pi Codex Conversion context sharing
|
|
367
|
+
|
|
368
|
+
The Herdsman adapter for Pi Codex Conversion (PCC) is optional and supports
|
|
369
|
+
Remote storage only. PCC's `shareSubagentContext` setting remains authoritative.
|
|
370
|
+
Load the adapter in both the delegating controller and each participating fresh
|
|
371
|
+
managed child; it is shipped at
|
|
372
|
+
`dist/integrations/pi-codex-context-sharing.js` but is not loaded by default.
|
|
373
|
+
For a normal npm Pi installation, reference it explicitly, for example:
|
|
374
|
+
|
|
375
|
+
```text
|
|
376
|
+
~/.pi/agent/npm/node_modules/pi-herdsman/dist/integrations/pi-codex-context-sharing.js
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
When a managed Agent definition uses `noExtensions: true`, list both PCC and the
|
|
380
|
+
Herdsman adapter in that definition's `extensions`:
|
|
381
|
+
|
|
382
|
+
```yaml
|
|
383
|
+
---
|
|
384
|
+
name: shared-worker
|
|
385
|
+
noExtensions: true
|
|
386
|
+
extensions:
|
|
387
|
+
- "~/.pi/agent/npm/node_modules/@howaboua/pi-codex-conversion/dist/index.js"
|
|
388
|
+
- "~/.pi/agent/npm/node_modules/pi-herdsman/dist/integrations/pi-codex-context-sharing.js"
|
|
389
|
+
---
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
An explicit `tools` allowlist must independently permit the tools needed by the
|
|
393
|
+
current PCC execution mode. The adapter does not modify tools or PCC execution
|
|
394
|
+
mode; consult PCC for mode-specific requirements. PCC restores the saved
|
|
395
|
+
context identity on continuation, so no adapter rebind is needed. Local and
|
|
396
|
+
Tree storage are not supported because they require ongoing context routing.
|
package/docs/reference/agent.md
CHANGED
|
@@ -42,6 +42,52 @@ session.
|
|
|
42
42
|
Each accepted definition delegation creates one agent generation for one
|
|
43
43
|
assignment. The terminal result is delivered once and the agent is cleaned up.
|
|
44
44
|
|
|
45
|
+
## Managed-agent bootstrap extension contract
|
|
46
|
+
|
|
47
|
+
Extensions that are already loaded in both the delegating controller and a
|
|
48
|
+
child may participate in fresh initialization through Pi's event bus channel
|
|
49
|
+
`pi-herdsman:managed-agent-bootstrap`. The protocol version is `1`. This is
|
|
50
|
+
available only for fresh `delegate_agent`; continuation never prepares,
|
|
51
|
+
initializes, or commits bootstrap participants.
|
|
52
|
+
|
|
53
|
+
During synchronous `prepare` event dispatch, listeners may synchronously call
|
|
54
|
+
`register(id, prepare)`. IDs must be unique within a spawn and match
|
|
55
|
+
`^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$`. Herdsman then sequentially awaits each
|
|
56
|
+
registered callback. Return `undefined` to opt out, or return an opaque string
|
|
57
|
+
payload and optional parent-side commit callback:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
pi.events.on("pi-herdsman:managed-agent-bootstrap", (value) => {
|
|
61
|
+
const event = value as any;
|
|
62
|
+
if (event.protocol !== 1 || event.phase !== "prepare") return;
|
|
63
|
+
event.register("example/child-state", async () => {
|
|
64
|
+
const prepared = await prepareChild(event.agent);
|
|
65
|
+
return {
|
|
66
|
+
payload: serialize(prepared),
|
|
67
|
+
commit: () => adoptChild(prepared),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Preparation must be safe to abandon if launch fails; durable parent-side
|
|
74
|
+
finalization belongs in the optional commit callback.
|
|
75
|
+
|
|
76
|
+
For each prepared participant, the child receives an `initialize` event before
|
|
77
|
+
Herdsman writes its normal `state.json` readiness record. Exactly one matching
|
|
78
|
+
child extension must synchronously call `accept(initialize)` during event
|
|
79
|
+
dispatch; Herdsman invokes and awaits that initializer before readiness. The
|
|
80
|
+
participant owns payload serialization, compatibility, and interpretation.
|
|
81
|
+
The aggregate bootstrap sidecar is limited to 64 KiB.
|
|
82
|
+
|
|
83
|
+
A prepared participant without exactly one child initializer, a rejected or
|
|
84
|
+
throwing initializer, a build/identity mismatch, invalid participant data, or
|
|
85
|
+
an oversized payload fails startup. No task is delivered and the existing
|
|
86
|
+
startup rollback applies. After normal child readiness and identity/integration
|
|
87
|
+
validation, Herdsman awaits parent commit callbacks before it delivers the
|
|
88
|
+
first assignment. Bootstrap storage is transient and removed before readiness.
|
|
89
|
+
With no participant data, delegation follows its ordinary startup path.
|
|
90
|
+
|
|
45
91
|
## `continue_agent`
|
|
46
92
|
|
|
47
93
|
```json
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-herdsman",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -75,12 +75,14 @@
|
|
|
75
75
|
"@earendil-works/pi-ai": "*",
|
|
76
76
|
"@earendil-works/pi-coding-agent": "*",
|
|
77
77
|
"@earendil-works/pi-tui": "*",
|
|
78
|
+
"@howaboua/pi-codex-conversion": "^3.0.45",
|
|
78
79
|
"typebox": "*"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
82
|
"@earendil-works/pi-ai": "1.1.0",
|
|
82
83
|
"@earendil-works/pi-coding-agent": "1.1.0",
|
|
83
84
|
"@earendil-works/pi-tui": "1.1.0",
|
|
85
|
+
"@howaboua/pi-codex-conversion": "3.0.45",
|
|
84
86
|
"esbuild": "^0.28.2",
|
|
85
87
|
"typebox": "^1.3.7"
|
|
86
88
|
},
|
|
@@ -97,5 +99,10 @@
|
|
|
97
99
|
],
|
|
98
100
|
"publishConfig": {
|
|
99
101
|
"registry": "https://registry.npmjs.org/"
|
|
102
|
+
},
|
|
103
|
+
"peerDependenciesMeta": {
|
|
104
|
+
"@howaboua/pi-codex-conversion": {
|
|
105
|
+
"optional": true
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
108
|
}
|