pi-herdsman 0.45.0 → 0.46.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.
@@ -5,6 +5,26 @@
5
5
  Pi Herdsman separates supervision, execution ownership, and physical placement.
6
6
  Those relationships intentionally do not collapse into one global Agent tree.
7
7
 
8
+ ## Emergent workflows, explicit boundaries
9
+
10
+ Pi Herdsman provides coordination tools, not a prescribed execution graph.
11
+ A Lead decides how to decompose its objective into bounded tasks and which
12
+ permitted Agents to delegate them to. A delegation-enabled Agent can repeat
13
+ that process within its own allowlist and the configured depth limit. At
14
+ project scale, a Manager decides which independent, branch-scoped objectives
15
+ to assign to managed Leads; each Lead directs its own Agent tree. The models
16
+ may choose parallel execution for independent work or sequence dependent work,
17
+ reassessing after handoffs instead of following a fixed pipeline.
18
+
19
+ The execution strategy is adaptive; authority is not. Exact-session Agent
20
+ ownership, delegation permissions, current project assignments, verified
21
+ worktree scope, and supervision boundaries remain enforced by Herdsman.
22
+ Agents cannot grant themselves broader authority by choosing a different
23
+ handoff. Users can still specify a workflow or customize Agent definitions,
24
+ but no predetermined handoff order is required. See [Delegation](delegation.md)
25
+ and [Project orchestration](../guides/project-orchestration.md) for the
26
+ respective execution contracts.
27
+
8
28
  ## Roles
9
29
 
10
30
  ```mermaid
@@ -231,6 +231,26 @@ Herdsman, copy normal Pi settings or extensions, or run as part of
231
231
  `npm run validate`. Run selected scenarios according to the change being
232
232
  verified; `npm run smoke` defaults to `core`.
233
233
 
234
+ ## Peer federation acceptance
235
+
236
+ Required peer-federation CI runs the shared core acceptance independently for
237
+ real containerized Managers (`manager-core`) and ordinary Leads (`lead-core`).
238
+ Each verifies one successful request, the exact correlated reply persisted
239
+ once, and A's assistant completion after that reply without another prompt.
240
+ The comprehensive ordinary-Lead acceptance remains manually available as the
241
+ `delivery` phase; it covers managed-Lead exclusion and delivery/recovery checks
242
+ not included in the focused CI gate.
243
+
244
+ Run the focused phases with
245
+ `PEER_SMOKE_PHASE=manager-core node scripts/peer-federation-smoke.mjs` and
246
+ `PEER_SMOKE_PHASE=lead-core node scripts/peer-federation-smoke.mjs`.
247
+ The comprehensive Manager recovery scenario remains the default and is
248
+ manually runnable with
249
+ `node scripts/peer-federation-smoke.mjs`. Run comprehensive ordinary-Lead
250
+ delivery with
251
+ `PEER_SMOKE_PHASE=delivery node scripts/peer-federation-smoke.mjs`.
252
+ A failed federation invocation is not retried automatically.
253
+
234
254
  ## Runtime preflight
235
255
 
236
256
  Before allocating the Herdr environment, the harness validates installed Node,
@@ -140,31 +140,34 @@ worktree. If `node_modules` is absent, run `npm ci` from that checkout.
140
140
  ### Optional setup for newly created worktrees
141
141
 
142
142
  The repository includes a `post-checkout` hook that runs `npm ci` synchronously
143
- when Git creates a new linked worktree. It is not enabled automatically. To
144
- enable it, run these steps from the trusted **primary checkout** (not a linked
145
- worktree).
143
+ when Git creates a new linked worktree. It is not enabled automatically.
146
144
 
147
- First inspect the configured hook directory and its origin:
145
+ For a fresh trusted clone, run this from the **primary checkout** (not a linked
146
+ worktree):
148
147
 
149
148
  ```sh
150
- git config --show-origin --get core.hooksPath
149
+ npm run setup
151
150
  ```
152
151
 
153
- Inspect its existing executable hooks as well; if `core.hooksPath` is unset,
154
- inspect the repository's default hooks directory using
155
- `git rev-parse --git-path hooks`.
156
-
157
- If an existing hook configuration or hook manager would be displaced, retain
158
- that configuration or integrate the script manually; this repository does not
159
- install a dispatcher. `core.hooksPath` selects the whole hooks directory, so
160
- changing it can disable other hooks. If no existing configuration would be
161
- displaced, enable the repository hook locally:
152
+ This configures the hook and installs dependencies. If dependencies are already
153
+ installed, `npm run setup:hooks` enables only the hook. Setup is idempotent.
154
+ When a repository folder is copied with its `.git` directory, setup repairs a
155
+ repository-local `core.hooksPath` pointing to an old `.githooks` directory
156
+ if that directory is missing or its hook files match the current checkout.
157
+ Unrelated hook managers, global settings, and executable default hooks are
158
+ not overridden. Inspect the current hook configuration and its origin with:
162
159
 
163
160
  ```sh
164
- git config --local core.hooksPath "$(pwd -P)/.githooks"
161
+ git config --show-origin --get core.hooksPath
165
162
  ```
166
163
 
167
- This local, optional setting affects only this repository. Its absolute path
164
+ If an existing hook configuration or hook manager would be displaced, retain
165
+ it or integrate `.githooks/post-checkout` manually; the repository does not
166
+ install a dispatcher. `core.hooksPath` selects the whole hooks directory, so
167
+ changing it can disable other hooks.
168
+
169
+ When newly configured, this local, optional setting affects only this
170
+ repository. Its absolute path
168
171
  deliberately points all linked worktrees to the same trusted script; ordinary
169
172
  worktrees share the repository's common Git configuration. Enabling it is an
170
173
  explicit developer trust decision: creating a new linked worktree in this
@@ -51,7 +51,7 @@ Pi to use the bundled `scout` Agent for a read-only reconnaissance task:
51
51
 
52
52
  ```text
53
53
  Use scout to identify this repository's main entry points.
54
- Explain how the application starts. Don't change any files.
54
+ Explain how the application starts.
55
55
  ```
56
56
 
57
57
  Delegation starts after Herdsman accepts the task. The Agent works
@@ -150,7 +150,40 @@ Tailscale provides networking only. SSH remains normal OpenSSH.
150
150
 
151
151
  ## Update
152
152
 
153
- To update Herdsman inside the container, finish active coordination first, then run:
153
+ To update the Pi runtime inside the container, finish active coordination
154
+ first, then run:
155
+
156
+ ```sh
157
+ pi update
158
+ ```
159
+
160
+ Pi downloads the complete official release into an immutable directory under
161
+ `~/.local/share/pi-herdsman/pi/releases/` and atomically selects it. New Pi
162
+ processes use that release; already-running processes continue using their
163
+ original files. The selection survives container restart and recreation and
164
+ takes precedence over the Pi bundled in a newer image. Pulling an image does
165
+ not replace this persistent selection, so review it separately for Pi security
166
+ updates. Forced reinstallations create additional retained release directories;
167
+ the container does not prune them.
168
+
169
+ Pi's `pi update --all` follows upstream behavior: installed packages are
170
+ updated before the Pi runtime, so the operation is not transactional. For
171
+ operationally significant updates, stop coordination and run the Pi update and
172
+ package updates as separate operations.
173
+
174
+ To recover to the image-bundled Pi after stopping work, remove only the
175
+ selection symlink:
176
+
177
+ ```sh
178
+ rm ~/.local/share/pi-herdsman/pi/current
179
+ pi --version
180
+ ```
181
+
182
+ Do not delete the release directories or the persistent home. The bundled
183
+ runtime remains available at `/opt/pi`.
184
+
185
+ To update Herdsman or other installed Pi packages, finish active coordination
186
+ first, then run:
154
187
 
155
188
  ```sh
156
189
  pi update npm:pi-herdsman
@@ -87,9 +87,11 @@ agents: [scout, reviewer]
87
87
  ```
88
88
 
89
89
  An omitted `agents` field leaves Leads unrestricted; `agents: []` disables
90
- fresh delegation. Overlay arrays replace lower-layer arrays, including with
91
- `[]`. Existing owned Agents remain manageable. The policy covers direct
92
- children only and is independent of ordinary tool selection.
90
+ fresh delegation. Existing owned Agents remain manageable. The policy covers
91
+ direct children only and is independent of ordinary tool selection. For
92
+ concrete inherited lists, `agents: [+scout, -reviewer]` modifies the list.
93
+ Leads with an unrestricted implicit default must first use a plain
94
+ `agents: [scout, reviewer]` allowlist before applying modifiers.
93
95
 
94
96
  Ordinary Leads persist their execution mode separately from role/authority
95
97
  state and retain their ordinary tool baseline while a restrictive profile is
@@ -238,7 +240,9 @@ For a matching higher-precedence definition:
238
240
 
239
241
  - omitted fields inherit;
240
242
  - strings and booleans replace;
241
- - arrays replace wholesale, including `[]`;
243
+ - arrays with plain entries replace wholesale, including `[]`;
244
+ - `+name` and `-name` entries modify inherited arrays; in a mixed list,
245
+ plain entries establish the replacement base before ordered modifiers;
242
246
  - the complete effective definition is validated after composition.
243
247
 
244
248
  `enabled` is a boolean that defaults to `true`. Use it in a minimal override to
@@ -407,8 +411,23 @@ The same diagnostic's no-network negative probe can be run with
407
411
  deterministic forbidden `exec_command` call into an empty tool context and
408
412
  asserts Pi returns `Tool exec_command not found` without execution.
409
413
 
410
- Remember that arrays replace the bundled array rather than append to it.
411
- Explicitly include every value you want in the effective array.
414
+ Plain arrays replace the inherited array. Use modifiers to add or remove
415
+ individual values without copying the inherited list. For example, a project
416
+ overlay can adjust an Agent's skills and a private repository overlay can
417
+ remove one inherited extension:
418
+
419
+ ```yaml
420
+ # .pi/agents/reviewer.md
421
+ skills: ["+/absolute/path/to/review/SKILL.md"]
422
+
423
+ # <git-common-dir>/pi-herdsman/agents/reviewer.md
424
+ extensions: ["-./extensions/legacy.ts"]
425
+ ```
426
+
427
+ For tools, a modifier-only list such as `tools: [+codemode, -write]` is
428
+ relative to Pi's ordinary tool selection, not a closed allowlist. Use a plain
429
+ list when a closed allowlist is intended. Tool modifiers accept exact names;
430
+ put wildcard patterns in `excludeTools`.
412
431
 
413
432
  Skill and extension paths are passed to Pi unchanged; unlike body `@file`
414
433
  references, herdr does not resolve them relative to the definition file.
@@ -471,38 +490,6 @@ execution fields from their spawning controller; `continue` restores saved
471
490
  session settings. They do not mutate an already-running agent or the lead Pi
472
491
  session.
473
492
 
474
- ## Optional Pi Codex Conversion context sharing
475
-
476
- The Herdsman adapter for Pi Codex Conversion (PCC) is optional and supports
477
- Remote storage only. PCC's `shareSubagentContext` setting remains authoritative.
478
- Load the adapter in both the delegating controller and each participating fresh
479
- managed child; it is shipped at
480
- `dist/integrations/pi-codex-context-sharing.js` but is not loaded by default.
481
- For a normal npm Pi installation, reference it explicitly, for example:
482
-
483
- ```text
484
- ~/.pi/agent/npm/node_modules/pi-herdsman/dist/integrations/pi-codex-context-sharing.js
485
- ```
486
-
487
- When a managed Agent definition uses `noExtensions: true`, list both PCC and the
488
- Herdsman adapter in that definition's `extensions`:
489
-
490
- ```yaml
491
- ---
492
- name: shared-worker
493
- noExtensions: true
494
- extensions:
495
- - "~/.pi/agent/npm/node_modules/@howaboua/pi-codex-conversion/dist/index.js"
496
- - "~/.pi/agent/npm/node_modules/pi-herdsman/dist/integrations/pi-codex-context-sharing.js"
497
- ---
498
- ```
499
-
500
- An explicit `tools` allowlist must independently permit the tools needed by the
501
- current PCC execution mode. The adapter does not modify tools or PCC execution
502
- mode; consult PCC for mode-specific requirements. PCC restores the saved
503
- context identity on continuation, so no adapter rebind is needed. Local and
504
- Tree storage are not supported because they require ongoing context routing.
505
-
506
493
  ## See also
507
494
 
508
495
  - [Agent-definition schema](../reference/agent-definition-schema.md)
@@ -38,8 +38,33 @@ skills:
38
38
 
39
39
  Unknown frontmatter fields fail validation.
40
40
 
41
- An explicit `tools` list is a closed allowlist. Tool entries cannot use Pi's
42
- `+name` or `-name` modifier syntax, including inside comma-separated values.
41
+ Array fields (`tools`, `excludeTools`, `skills`, `extensions`, and
42
+ `agents`) replace the inherited array when they contain only plain values.
43
+ An empty array explicitly clears the inherited values. A list containing
44
+ `+name` or `-name` entries modifies an inherited array: additions are
45
+ appended once, removals delete matching values, and removing a missing value is
46
+ a no-op. In a mixed list, plain values form the replacement base before the
47
+ modifiers are applied. Tool entries continue to accept comma-separated names;
48
+ the other array fields treat each item as one complete path or name.
49
+
50
+ For example, a matching Agent overlay can add a skill without copying inherited
51
+ skills:
52
+
53
+ ```yaml
54
+ skills: ["+/absolute/path/to/review/SKILL.md"]
55
+ ```
56
+
57
+ A modifier-only `tools` list with no explicit inherited tool list remains
58
+ relative to Pi's normal or active tool selection. It does not create a closed
59
+ allowlist. Explicit removals are enforced at dispatch, including nested Code
60
+ Mode calls; `excludeTools` remains an additional exclusion policy. Tool
61
+ modifiers require exact names (no wildcards). Use a plain `tools` list for a
62
+ closed allowlist, and `excludeTools` for wildcard exclusions.
63
+
64
+ An omitted `agents` field retains each profile's default. Leads remain
65
+ unrestricted when omitted, so a modifier-only `agents` overlay requires an
66
+ explicit inherited allowlist; Manager, Chief, and ordinary Agents default to no
67
+ direct Agent delegation and can add names from that empty default.
43
68
 
44
69
  Bundled Agents and the managed Lead enable Pi's native `codemode` by default.
45
70
  Definitions that specify `noExtensions: true` also load only
@@ -98,44 +98,55 @@ During synchronous `prepare` event dispatch, listeners may synchronously call
98
98
  `register(id, prepare)`. IDs must be unique within a spawn and match
99
99
  `^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$`. Herdsman then sequentially awaits each
100
100
  registered callback. Return `undefined` to opt out, or return an opaque string
101
- payload and optional parent-side commit callback:
101
+ payload and optional parent-side commit callback. A participant that needs the
102
+ child's native Pi session ID may call `reserveChildSessionId()` during
103
+ preparation:
102
104
 
103
105
  ```ts
104
106
  pi.events.on("pi-herdsman:managed-agent-bootstrap", (value) => {
105
107
  const event = value as any;
106
108
  if (event.protocol !== 1 || event.phase !== "prepare") return;
107
- event.register("example/child-state", async () => {
108
- const prepared = await prepareChild(event.agent);
109
+ event.register("example/session-aware", async () => {
110
+ const childSessionId = event.reserveChildSessionId();
109
111
  return {
110
- payload: serialize(prepared),
111
- commit: () => adoptChild(prepared),
112
+ payload: JSON.stringify({ childSessionId }),
113
+ commit: async () => {
114
+ // Optional parent-side finalization after child readiness.
115
+ },
112
116
  };
113
117
  });
114
118
  });
115
119
  ```
116
120
 
117
- Preparation must be safe to abandon if launch fails; durable parent-side
118
- finalization belongs in the optional commit callback.
119
-
120
- For each prepared participant, the child receives an `initialize` event before
121
- Herdsman writes its normal `state.json` identity record. Exactly one matching
122
- child extension must synchronously call `accept(initialize)` during event
123
- dispatch; Herdsman invokes and awaits that initializer before readiness. The
124
- participant owns payload serialization, compatibility, and interpretation.
125
- The aggregate bootstrap sidecar is limited to 64 KiB.
126
-
127
- A prepared participant without exactly one child initializer, a rejected or
128
- throwing initializer, a build/identity mismatch, invalid participant data, or
129
- an oversized payload fails startup. No task is delivered and the existing
130
- startup rollback applies. After normal child readiness and identity/integration
131
- validation, Herdsman awaits parent commit callbacks before it delivers the
132
- first assignment. Bootstrap storage is transient and removed before readiness.
133
- With no participant data, delegation follows its ordinary startup path.
134
-
135
- The child publishes a transient startup outcome after initialization and request
136
- observation are complete. The parent requires a matching ready outcome and
137
- valid state before submitting an assignment; the assignment still requires its
138
- own acknowledgement. Startup outcomes do not establish continuing liveness.
121
+ The reservation is generated by Herdsman, is valid only during preparation,
122
+ and all participants in that delegation receive the same ID. It applies only
123
+ to a fresh child; continuation does not prepare, reserve, initialize, or commit
124
+ bootstrap participants. A reservation is used only if at least one participant
125
+ returns payload data. Herdsman transports opaque data without interpreting
126
+ extension-owned semantics. Preparation must be safe to abandon if launch fails;
127
+ durable parent-side finalization belongs in the optional commit callback.
128
+
129
+ Each prepared participant must implement a matching child `initialize`
130
+ listener and validate its own payload. Exactly one matching child extension
131
+ must synchronously call `accept(initialize)` during event dispatch. Herdsman
132
+ invokes and awaits initializers sequentially after all Pi `session_start`
133
+ handlers have completed, but before publishing managed state or readiness.
134
+ Bootstrap storage is transient and removed before readiness. The participant
135
+ owns payload serialization, compatibility, and interpretation. The aggregate
136
+ bootstrap sidecar is limited to 64 KiB.
137
+
138
+ A missing or duplicate initializer, a rejected or throwing initializer, a
139
+ build/identity mismatch, invalid participant data, or an oversized payload
140
+ fails startup. No task is delivered and the existing startup rollback applies.
141
+ After normal child readiness and identity/integration validation, Herdsman
142
+ awaits parent commit callbacks before it delivers the first assignment. With no
143
+ participant data, delegation follows its ordinary startup path.
144
+
145
+ The child publishes a transient startup outcome only after initialization and
146
+ request observation are complete. The parent requires a matching ready outcome
147
+ and valid state before submitting an assignment; the assignment still requires
148
+ its own acknowledgement. Startup outcomes do not establish continuing
149
+ liveness.
139
150
 
140
151
  ## `continue_agent`
141
152
 
@@ -132,6 +132,32 @@ action. Use `/manager refresh` or `/chief refresh` to validate and apply the
132
132
  active role's definition. Definition files are not watched while a profile is
133
133
  active.
134
134
 
135
+ The `Details…` action appends a read-only inspection entry to the normal Pi chat
136
+ transcript and closes the Definitions menu. The compact entry reports the
137
+ inspection context and preview; use Pi's native `Ctrl+O` expansion to reveal
138
+ sequential instruction sections rendered with Pi's Markdown component.
139
+ Expanded content occupies its natural transcript height and uses ordinary
140
+ terminal scrolling. The inspection snapshot, including applicable context
141
+ text, is saved with the Pi session but is excluded from model context. The
142
+ compact view reports the effective configuration, definition source count,
143
+ selected context-file count, execution context, and preview limitation. The
144
+ expanded sections follow known prompt-input ordering; source headers identify
145
+ instruction files and known runtime contributions. Definition overlays appear
146
+ as concise configuration provenance separate from surviving instruction text. `+` and `-` identify added and removed explicit values;
147
+ `~` identifies changed values or body operations. Context files follow Pi's
148
+ loader order and the Agent's global/project inheritance settings. Configured
149
+ skills and extensions are selections, not proof that those resources loaded.
150
+ For an active Lead or Manager, the expanded view uses the verified role-contract
151
+ producer and current Pi system-prompt options for known context inputs; ordinary
152
+ Lead execution profile text is shown separately. Chief uses its forced-prompt
153
+ producer, which includes applicable global user instructions and excludes
154
+ ordinary project context. Inactive Coordinator profiles are shown prospectively;
155
+ current active contracts are not substituted for them. Managed Lead previews place its append-only definition body and shared guidance
156
+ before inherited context, followed by the verified runtime role section when
157
+ active. Other session-dependent sections are identified as such. The preview
158
+ is not an exact provider prompt: role/session runtime inputs and provider-side
159
+ transformations may add content.
160
+
135
161
  The details view shows applicable effective metadata:
136
162
 
137
163
  - name and description;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-herdsman",
3
- "version": "0.45.0",
3
+ "version": "0.46.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",
@@ -62,6 +62,8 @@
62
62
  }
63
63
  },
64
64
  "scripts": {
65
+ "setup": "npm run setup:hooks && npm ci",
66
+ "setup:hooks": "node scripts/setup-hooks.mjs",
65
67
  "test": "node --experimental-test-module-mocks --import=./scripts/test-env.mjs --test --test-timeout=10000",
66
68
  "smoke": "node scripts/smoke.mjs",
67
69
  "format": "prettier . --write",
@@ -79,20 +81,18 @@
79
81
  "@earendil-works/pi-ai": "*",
80
82
  "@earendil-works/pi-coding-agent": "*",
81
83
  "@earendil-works/pi-tui": "*",
82
- "@howaboua/pi-codex-conversion": "^3.0.45 || ^4.0.0",
83
84
  "typebox": "*"
84
85
  },
85
86
  "devDependencies": {
86
87
  "@earendil-works/pi-ai": "1.5.2",
87
88
  "@earendil-works/pi-coding-agent": "1.5.2",
88
89
  "@earendil-works/pi-tui": "1.5.2",
89
- "@howaboua/pi-codex-conversion": "4.0.4",
90
- "@modelcontextprotocol/sdk": "1.32.0",
91
- "@types/node": "22.19.19",
90
+ "@modelcontextprotocol/sdk": "1.32.2",
91
+ "@types/node": "22.20.5",
92
92
  "@types/proper-lockfile": "4.1.4",
93
93
  "esbuild": "^0.28.2",
94
- "oxlint": "1.90.0",
95
- "prettier": "3.9.10",
94
+ "oxlint": "1.93.0",
95
+ "prettier": "3.10.1",
96
96
  "typebox": "^1.3.7",
97
97
  "typescript": "7.0.2"
98
98
  },
@@ -114,11 +114,6 @@
114
114
  "publishConfig": {
115
115
  "registry": "https://registry.npmjs.org/"
116
116
  },
117
- "peerDependenciesMeta": {
118
- "@howaboua/pi-codex-conversion": {
119
- "optional": true
120
- }
121
- },
122
117
  "dependencies": {
123
118
  "proper-lockfile": "4.1.2"
124
119
  }
@@ -85,9 +85,13 @@ repository`), including which files contribute to the effective
85
85
  definition.
86
86
  - Preserve unrelated frontmatter, body content, and existing source files.
87
87
  - The frontmatter `name` is the definition identity; the filename is not.
88
- - Array fields replace the whole lower-precedence array. Before adding or
89
- removing one array value, inspect the effective array and write the desired
90
- complete replacement.
88
+ - Plain array values replace the inherited array, including `[]`. Use
89
+ `+name` and `-name` entries to add or remove individual inherited values;
90
+ mixed lists use their plain entries as a replacement base before modifiers.
91
+ Modifier-only `tools` lists remain relative to Pi's ordinary selection,
92
+ while plain `tools` lists are closed allowlists. Leads with unrestricted
93
+ implicit `agents` defaults need a concrete allowlist before using
94
+ modifiers.
91
95
  - For additive prompt instructions, prefer an overlay body with
92
96
  `bodyMode: append`; replace the body only when replacement is intended.
93
97
  - Express capability restrictions structurally through definition fields
@@ -1,42 +0,0 @@
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
@@ -1,7 +0,0 @@
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
- }