pi-herdr-agents 0.0.1

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.
Files changed (49) hide show
  1. package/AGENTS.md +116 -0
  2. package/CONTEXT.md +159 -0
  3. package/LICENSE +21 -0
  4. package/README.md +874 -0
  5. package/RELEASING.md +139 -0
  6. package/agents/adversarial-reviewer.md +80 -0
  7. package/agents/claude-reviewer.md +23 -0
  8. package/agents/planner.md +539 -0
  9. package/agents/poteto.md +32 -0
  10. package/agents/reviewer.md +164 -0
  11. package/agents/scout.md +106 -0
  12. package/agents/visual-tester.md +224 -0
  13. package/agents/worker.md +132 -0
  14. package/config.json.example +8 -0
  15. package/docs/README.md +42 -0
  16. package/docs/adr/0001-btw-ephemeral-side-questions.md +142 -0
  17. package/docs/adr/0002-agent-workflow-skill-runtime-taxonomy.md +265 -0
  18. package/docs/adr/0003-installable-role-packs.md +135 -0
  19. package/docs/adr/0004-require-active-user-approval-for-workflow-execution.md +17 -0
  20. package/docs/adr/0005-parent-owns-workflow-script-authority.md +17 -0
  21. package/docs/adr/0006-limit-v1-execution-effects-to-isolated-worktrees.md +18 -0
  22. package/docs/adr/0007-require-fresh-review-for-workflow-scripts.md +19 -0
  23. package/docs/orchestrated-review-workflow-plan.md +479 -0
  24. package/docs/research/pdw-architecture-assessment.md +525 -0
  25. package/docs/research/pi-workflows-sol-advisor.md +255 -0
  26. package/docs/research/worktree-subagent-orchestration.md +317 -0
  27. package/docs/worktree-subagents.md +196 -0
  28. package/examples/role-pack/extension.ts +18 -0
  29. package/examples/role-pack/package.json +16 -0
  30. package/examples/role-pack/roles/example-reviewer.md +12 -0
  31. package/package.json +58 -0
  32. package/pi-extension/subagents/activity.ts +511 -0
  33. package/pi-extension/subagents/completion.ts +177 -0
  34. package/pi-extension/subagents/herdr.ts +541 -0
  35. package/pi-extension/subagents/index.ts +4730 -0
  36. package/pi-extension/subagents/lifecycle.ts +477 -0
  37. package/pi-extension/subagents/model-config.ts +95 -0
  38. package/pi-extension/subagents/plan-skill.md +262 -0
  39. package/pi-extension/subagents/plugin/.claude-plugin/plugin.json +5 -0
  40. package/pi-extension/subagents/plugin/hooks/hooks.json +15 -0
  41. package/pi-extension/subagents/plugin/hooks/on-stop.sh +68 -0
  42. package/pi-extension/subagents/runtime-routing.ts +313 -0
  43. package/pi-extension/subagents/session.ts +216 -0
  44. package/pi-extension/subagents/status.ts +513 -0
  45. package/pi-extension/subagents/subagent-done.ts +326 -0
  46. package/pi-extension/subagents/terminal.ts +163 -0
  47. package/pi-extension/subagents/workflow-worker.js +56 -0
  48. package/pi-extension/subagents/workflow.ts +1210 -0
  49. package/skills/orchestrate/SKILL.md +184 -0
@@ -0,0 +1,142 @@
1
+ # ADR-0001: Add `/btw` as an ephemeral side-question child
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-07-31
5
+ - **Decision owners:** `acrnm`
6
+ - **Scope:** `giuseppecrj/pi-herdr-agents`
7
+ - **Decision baseline:** legacy source commit `77d7d029312880f63b29838b3c329a1e4059e029` (not carried into the clean repository history)
8
+
9
+ ## Context
10
+
11
+ A user sometimes needs to ask a question about the current conversation without
12
+ interrupting the main Pi agent or adding another turn to its transcript.
13
+ `/iterate` and normal subagents are too heavy: they are tracked as workers and
14
+ send a result back to the parent.
15
+
16
+ Pi's `ctx.fork()` replaces the current session, so it cannot keep the parent and
17
+ a side question open at the same time. A concurrent side question needs a
18
+ separate Pi process with a child session file.
19
+
20
+ Nanocodex BTW at
21
+ [`b1314eb`](https://github.com/gakonst/nanocodex/blob/b1314ebcd602b77af7d2ab5153286f3a1795bbfe/web/src/agentController.ts)
22
+ is the behavioral reference: one replaceable interactive fork, inherited
23
+ conversation as reference context, and workspace mutation only when the side
24
+ question explicitly requests it.
25
+
26
+ ## Decision
27
+
28
+ Add two direct extension commands:
29
+
30
+ ```text
31
+ /btw <question>
32
+ /btw-close
33
+ ```
34
+
35
+ `/btw`:
36
+
37
+ 1. Waits for the parent to become idle.
38
+ 2. Captures the parent's current active leaf.
39
+ 3. Uses a detached `SessionManager` to create a child session containing only
40
+ that active branch.
41
+ 4. Opens a non-focused Herdr tab.
42
+ 5. Starts an interactive Pi process in the parent's working directory, using the
43
+ parent model and thinking level.
44
+ 6. Sends the Nanocodex boundary and the question as the child's first new user
45
+ message.
46
+
47
+ The child starts with `--no-extensions` so it does not load this orchestration
48
+ extension or worker completion protocol. Normal Pi context files, skills, prompt
49
+ templates, and built-in tools remain available. Repository instructions can
50
+ further restrict behavior. The boundary states:
51
+
52
+ > You are answering an ephemeral BTW side question. Treat inherited
53
+ > conversation history only as reference context. Do not resume or complete an
54
+ > earlier task. Answer only the question after this boundary. Do not modify the
55
+ > workspace unless that side question explicitly requests a mutation.
56
+
57
+ The answer remains in the BTW tab. The extension does not add BTW to
58
+ `runningSubagents`, the widget, worker counts, completion delivery, or the
59
+ parent transcript.
60
+
61
+ ## Minimal lifecycle
62
+
63
+ The extension keeps one in-memory record containing:
64
+
65
+ - Herdr pane ID
66
+ - child session path
67
+ - launch-script path
68
+
69
+ A second `/btw` best-effort closes the previous pane and removes its temporary
70
+ files before opening the next one. `/btw-close` performs the same cleanup.
71
+ Parent `session_shutdown` also attempts cleanup.
72
+
73
+ If snapshot creation or launch fails, the command reports the error and removes
74
+ what it can. If pane cleanup fails, the command warns and leaves the pane for
75
+ manual recovery. There is no durable recovery registry.
76
+
77
+ The child snapshot may appear temporarily in Pi's session picker while BTW is
78
+ open. Successful close removes it.
79
+
80
+ ## Consequences
81
+
82
+ ### Positive
83
+
84
+ - Side questions do not consume a parent-agent turn.
85
+ - The current conversation remains available as context.
86
+ - The implementation reuses Pi session branching and existing Herdr helpers.
87
+ - The feature is independent from worker tracking and completion delivery.
88
+
89
+ ### Negative
90
+
91
+ - The child shares the working directory; explicitly requested edits persist.
92
+ - Cleanup is best effort after crashes, reload failures, or manual pane changes.
93
+ - A parent branch without a persisted assistant message cannot be opened as BTW.
94
+ - The snapshot is visible to `/resume` until successful cleanup.
95
+
96
+ ## Deliberately deferred
97
+
98
+ - Durable cleanup or crash recovery
99
+ - Process observers and completion delivery
100
+ - Worktree isolation
101
+ - Multiple or named BTW panes
102
+ - Tab-split ownership
103
+ - Automatic merge, commit, push, or PR behavior
104
+ - A generalized child-session manager
105
+
106
+ Add these only if real usage demonstrates a need.
107
+
108
+ ## Verification
109
+
110
+ Unit tests must prove:
111
+
112
+ - active-branch snapshotting excludes abandoned siblings;
113
+ - snapshotting does not modify the parent session;
114
+ - an unpersisted child snapshot fails closed;
115
+ - the launch command uses `--no-extensions`, the parent runtime, and the BTW
116
+ boundary without worker-control arguments;
117
+ - empty `/btw` and idle `/btw-close` are harmless and do not steer the parent.
118
+
119
+ Herdr integration must prove:
120
+
121
+ - `/btw` opens a non-focused tab;
122
+ - the child can answer from the latest completed parent context;
123
+ - the parent session receives no BTW result or follow-up turn;
124
+ - a second `/btw` replaces the first child;
125
+ - `/btw-close` closes the child.
126
+
127
+ Run:
128
+
129
+ ```sh
130
+ npm test
131
+ npm run lint
132
+ git diff --check
133
+ npm run test:integration
134
+ npm pack --dry-run
135
+ ```
136
+
137
+ ## References
138
+
139
+ - [Pi Herdr Agents](https://github.com/giuseppecrj/pi-herdr-agents)
140
+ - [Nanocodex BTW controller](https://github.com/gakonst/nanocodex/blob/b1314ebcd602b77af7d2ab5153286f3a1795bbfe/web/src/agentController.ts)
141
+ - [Pi extension API](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/extensions.md)
142
+ - [Pi session format](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/session-format.md)
@@ -0,0 +1,265 @@
1
+ # ADR-0002: Adopt the agent, workflow, skill, and runtime taxonomy
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-08-02
5
+ - **Decision owners:** `acrnm`
6
+ - **Scope:** `giuseppecrj/pi-herdr-agents`
7
+ - **Historical tracking:** legacy issues #4 and #5 (not carried into the clean repository)
8
+
9
+ ## Decision
10
+
11
+ Keep `pi-herdr-agents` small: it owns **agent execution**, not a second
12
+ skill system or a general workflow engine.
13
+
14
+ Use these terms consistently:
15
+
16
+ - **Agent role** — A reusable child-agent responsibility with an operating
17
+ prompt and capability limits. Owned by this package or a project override;
18
+ sometimes user-facing through `/subagent`.
19
+ - **Workflow** — A named recipe that composes roles, order, artifacts, and
20
+ runtime policy to achieve an outcome. Owned by the parent/orchestrator and
21
+ user-facing.
22
+ - **Skill** — A Pi-native instruction set that teaches the current agent a
23
+ reusable procedure. It may invoke workflows or roles. Owned by Pi or the
24
+ skill author and user-facing.
25
+ - **Runtime** — How a role executes: Pi or an external CLI, plus model and
26
+ thinking selection. Owned by invocation/configuration and not user-facing.
27
+ - **Adapter** — An internal, runtime-specific role used by a workflow, such as
28
+ the Claude review pass. Owned by this package and not user-facing.
29
+
30
+ An agent role is **not** a workflow merely because it can spawn other agents.
31
+ A coordinator role is allowed when it owns an interactive or multi-stage child
32
+ session. A workflow is the user-intent layer above it.
33
+
34
+ ## Why this is needed
35
+
36
+ The package has a sound execution model but exposes mixed concepts on the same
37
+ surface:
38
+
39
+ - Agent definitions are discovered from package, global, and project folders,
40
+ with project definitions overriding global and bundled definitions.
41
+ - The bundled list includes reusable roles (`scout`, `worker`, `reviewer`), a
42
+ multi-stage orchestration (`adversarial-reviewer`), and a Claude-specific
43
+ implementation (`claude-reviewer`).
44
+ - The extension can request Pi skills, select model defaults, and start
45
+ sessions, but it has no first-class workflow definition or agent-definition
46
+ schema validation.
47
+
48
+ That makes `/subagent list` technically accurate but semantically unclear: it
49
+ is a list of executable definitions, not a list of comparable user tasks.
50
+
51
+ ## Standard
52
+
53
+ ### 1. Agent roles have one responsibility
54
+
55
+ An agent definition answers: **what responsibility can this child take on,
56
+ and under which constraints?** It must not promise a broad product outcome.
57
+
58
+ A bundled role should have:
59
+
60
+ - a stable, verb-first or noun-role name (`scout`, `reviewer`, `worker`);
61
+ - a description stating its input and output, not its implementation;
62
+ - the minimum tools and skills needed for that responsibility;
63
+ - explicit `spawning`, `auto-exit`, and interaction behavior when it matters;
64
+ - a report or handoff contract in its body; and
65
+ - no user-specific model ID unless the role cannot function without that
66
+ runtime.
67
+
68
+ Use an agent role directly when a caller has already chosen the task and needs
69
+ one bounded child responsibility. Examples: inspect a module, review a diff,
70
+ or implement a specified change.
71
+
72
+ `planner` is a coordinator role: it may delegate factual gaps because that is
73
+ part of planning. `reviewer`, `scout`, and `worker` are leaf roles and should
74
+ keep `spawning: false`.
75
+
76
+ ### 2. Workflows own user intent and composition
77
+
78
+ A workflow answers: **what result does the user want, and which roles run in
79
+ what order to produce it?** It owns:
80
+
81
+ - entry-point name and user-facing description;
82
+ - required context and optional inputs;
83
+ - role selection, sequence, and fan-out;
84
+ - artifact locations and aggregation;
85
+ - runtime-selection policy; and
86
+ - completion and verification criteria.
87
+
88
+ The package already exposes these workflow surfaces:
89
+
90
+ - **Planning** — `/plan`, a user-facing command backed by `plan-skill.md` that
91
+ coordinates scout, interactive planner, workers, and reviewer.
92
+ - **Iteration** — `/iterate`, a user-facing command that forks the current
93
+ session for focused work.
94
+ - **Side question** — `/btw` and `/btw-close`, user-facing commands that manage
95
+ an ephemeral interactive side session.
96
+ - **Adversarial review** — `adversarial-reviewer`, a user-facing orchestration
97
+ agent that is incorrectly presented as an agent rather than a workflow.
98
+ - **Approved review runner** — `herdr_workflow`, a low-level control tool for
99
+ exact approved project-local JavaScript. It is an execution surface, not the
100
+ user-facing workflow recipe.
101
+ - **Orchestrated review authoring** — bundled native `/skill:orchestrate`, which
102
+ teaches the parent to author and approve the first-flow review workflow.
103
+
104
+ An orchestration agent remains a compatibility implementation detail—not a
105
+ general pattern for new roles. Do not add more user-outcome orchestration
106
+ prompts to `agents/` just because `subagent` is an available launcher.
107
+
108
+ The next user-facing review surface should be a workflow named for the outcome,
109
+ not a child implementation:
110
+
111
+ - **Review** — one or more evidence-backed review passes against a supplied
112
+ base/ref and rubric.
113
+ - **Adversarial review** — independent multi-runtime passes followed by
114
+ verification of proposed findings.
115
+
116
+ Whether these become commands, Pi skills, or a parent prompt is a separate UX
117
+ decision. The workflow contract should be settled before adding a new command.
118
+
119
+ ### 3. Skills remain outside this package's taxonomy
120
+
121
+ A skill teaches the current Pi agent how to act. It is not an agent definition,
122
+ even if it causes `subagent` calls. This package should:
123
+
124
+ - accept the existing `skills` agent field as a dependency declaration;
125
+ - document required skill names and prerequisites; and
126
+ - not discover, install, version, or duplicate Pi skills.
127
+
128
+ A package-owned `plan-skill.md` should be described as the instruction backing
129
+ the package's `/plan` workflow, not as a second kind of subagent definition.
130
+
131
+ ### 4. Runtimes are selected by policy, not role identity
132
+
133
+ A role describes the work; a runtime describes how one invocation performs it.
134
+ For Pi-backed agents, the current model-resolution chain is the correct
135
+ foundation: explicit invocation choice, agent default, per-agent configuration,
136
+ global configuration, then the parent model. Claude CLI adapters instead use
137
+ `cli` and `cli-model`; do not set a Pi `model` on an adapter expecting it to
138
+ select the CLI model.
139
+
140
+ Apply these rules:
141
+
142
+ 1. Prefer per-invocation `model` and `thinking` for a workflow's deliberate
143
+ diversity or cost/quality policy.
144
+ 2. Use ignored local `config.json` for a person's durable role preferences.
145
+ 3. Leave bundled Pi-role `model` unset unless a particular model is a functional
146
+ prerequisite.
147
+ 4. Treat `cli` and `cli-model` as a runtime adapter concern, not a review or
148
+ planning policy.
149
+ 5. State runtime prerequisites before launch and fail closed when a required
150
+ runtime is unavailable.
151
+
152
+ This preserves the useful multi-model review behavior without baking a
153
+ particular vendor choice into the generic `reviewer` role.
154
+
155
+ ### 5. Internal adapters are hidden from task discovery
156
+
157
+ An adapter exists to satisfy a workflow's runtime contract, not to ask a user
158
+ what they want to do. It should use `disable-model-invocation: true` and have a
159
+ name that makes its internal nature clear.
160
+
161
+ `claude-reviewer` is the current example. It uses
162
+ `disable-model-invocation: true`: hidden adapters remain explicitly invokable
163
+ by exact name, including from the existing adversarial-review orchestrator.
164
+
165
+ ### 6. Agent frontmatter is a constrained contract
166
+
167
+ The package should document and validate the frontmatter it consumes. Do not
168
+ silently add fields that are neither parsed nor documented. In particular,
169
+ standardize on `skills` (plural); compatibility support for `skill` can remain
170
+ until a documented deprecation date.
171
+
172
+ The current parser is permissive: unsupported or unknown frontmatter may be
173
+ ignored instead of rejected. The README therefore provides a complete template,
174
+ a checklist, and a list/launch smoke-test procedure rather than promising schema
175
+ validation that does not exist yet.
176
+
177
+ For a future validation pass, require at least `name` and `description`, reject
178
+ unknown package-owned fields, validate tool/skill list syntax, and report the
179
+ source path in errors. The authoring template must cover the complete existing
180
+ README frontmatter reference (`tools`, `deny-tools`, `thinking`, `system-prompt`,
181
+ `spawning`, `auto-exit`, `interactive`, `session-mode`, `cwd`, `cli`,
182
+ `cli-model`, and `disable-model-invocation`) rather than introduce a partial
183
+ second schema. Keep extension fields separate from arbitrary prompt metadata so
184
+ project authors can still add their own namespaced fields.
185
+
186
+ ## Current mapping
187
+
188
+ - `scout` — Leaf agent role. Keep.
189
+ - `worker` — Leaf agent role. Keep.
190
+ - `reviewer` — Leaf agent role. Keep as the model-neutral review pass.
191
+ - `planner` — Coordinator agent role. Keep; `/plan` remains the workflow that
192
+ invokes it.
193
+ - `poteto` — Coordinator agent role. Keep only if its distinct autonomous
194
+ engineering responsibility remains intentional.
195
+ - `visual-tester` — Leaf agent role with skill prerequisite. Keep its
196
+ `chrome-cdp` dependency declared through canonical `skills` metadata.
197
+ - `claude-reviewer` — Hidden internal runtime adapter. Workflows can still
198
+ invoke it by exact name.
199
+ - `adversarial-reviewer` — Workflow implementation pending a workflow surface.
200
+ Do not clone this pattern for new outcomes; migrate its user contract to an
201
+ adversarial-review workflow.
202
+ - `plan-skill.md` — Planning workflow instruction. Document by workflow purpose,
203
+ not agent type.
204
+ - `skills/orchestrate/SKILL.md` — Bundled native authoring skill for the first
205
+ review workflow; exposed with the package through Pi skills metadata.
206
+
207
+ ## Small migration plan
208
+
209
+ Phases 1 and 2 are implemented in the current package. Phase 3 remains
210
+ conditional on repeated registry needs; the low-level `herdr_workflow` runner is
211
+ not a general workflow registry.
212
+
213
+ ### Phase 1 — establish the contract (documentation only)
214
+
215
+ 1. Adopt this vocabulary in the README and agent-authoring reference.
216
+ 2. Add a short agent-authoring template and a checklist for role authors.
217
+ 3. Audit bundled frontmatter for undocumented or unconsumed keys, including
218
+ `scout`'s `output` metadata and `visual-tester`'s compatibility `skill` key.
219
+ 4. Document every current workflow—planning, iteration, side questions, and
220
+ adversarial review—with its roles, artifacts, prerequisites, and runtime
221
+ policy in one place.
222
+ 5. Mark `claude-reviewer` with `disable-model-invocation: true`; this is an
223
+ existing visibility control, not new framework work.
224
+
225
+ ### Phase 2 — improve discovery without a new framework
226
+
227
+ 1. Make `subagents_list` show the source for every visible definition.
228
+ 2. Keep `/subagent` focused on directly runnable roles; describe workflows in
229
+ the command/skill documentation that owns them.
230
+
231
+ ### Phase 3 — add a workflow registry only when two surfaces need the same mechanics
232
+
233
+ If `/plan` and adversarial review need the same registration, discovery, and
234
+ artifact mechanics, add the smallest explicit workflow registry. It should
235
+ compose existing roles and call `subagent`; it must not reimplement session,
236
+ worktree, model-resolution, or completion lifecycle logic.
237
+
238
+ Do not add a workflow engine, durable scheduler, or another configuration
239
+ language before that repeated need exists.
240
+
241
+ ## Acceptance criteria
242
+
243
+ - A user can distinguish a workflow from a directly runnable role before
244
+ launching either.
245
+ - `subagents_list` does not advertise internal runtime adapters as peer tasks.
246
+ - A role author can create and smoke-test a valid definition from one documented
247
+ template; schema-level frontmatter errors remain a deferred validation pass.
248
+ - A workflow can select different authenticated runtimes per child without
249
+ changing generic role definitions.
250
+ - Existing project/global override precedence and runtime-resolution behavior
251
+ remain unchanged.
252
+ - No behavior is added to the package solely to duplicate Pi's skill system.
253
+
254
+ ## Evidence
255
+
256
+ This decision is based on the current implementation:
257
+
258
+ - `pi-extension/subagents/index.ts` parses and discovers agent definitions in
259
+ package → global → project load order (later definitions win), so effective
260
+ priority is project > global > package; it also launches child sessions.
261
+ - `pi-extension/subagents/model-config.ts` provides per-agent and global model
262
+ defaults; launch-time arguments remain the appropriate workflow override.
263
+ - `README.md` documents `/plan`, `/iterate`, `/btw`, agent discovery,
264
+ frontmatter, and runtime precedence.
265
+ - `agents/` contains the mixed role/coordinator/adapter set mapped above.
@@ -0,0 +1,135 @@
1
+ # ADR-0003: Discover installable role packs through Pi's event bus
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-08-02
5
+ - **Decision owners:** `acrnm`
6
+ - **Scope:** `giuseppecrj/pi-herdr-agents`
7
+
8
+ ## Decision
9
+
10
+ Treat Pi packages as the plugin system for third-party subagent roles.
11
+ A role pack ships Markdown role definitions plus a small Pi extension that
12
+ responds synchronously to:
13
+
14
+ ```text
15
+ pi-herdr-subagents:roles:discover:v1
16
+ ```
17
+
18
+ That event name is a stable protocol identifier and is not renamed with the package.
19
+
20
+ The discovery request exposes one operation:
21
+
22
+ ```ts
23
+ register(path: string): void
24
+ ```
25
+
26
+ `path` is an absolute Markdown file or a directory whose direct `.md` children
27
+ are role definitions. `pi-herdr-agents` reads and validates those files when
28
+ roles are listed or launched.
29
+
30
+ Role packs use the existing agent-definition format. The filename stem is the
31
+ canonical role name; `name` frontmatter is optional and, when present, must
32
+ match the stem. `description` is required for contributed roles.
33
+
34
+ ## Why
35
+
36
+ Pi already owns package installation, updates, project trust, enablement, and
37
+ removal. Reusing `pi install` avoids a second package manager and keeps package
38
+ security expectations explicit.
39
+
40
+ Pi currently discovers only extensions, skills, prompts, and themes. It does
41
+ not expose custom package resources or installed package roots to extensions.
42
+ The inter-extension event bus is the smallest public seam that lets separately
43
+ installed packages contribute roles without scanning Pi's private npm or Git
44
+ directories.
45
+
46
+ Pull-based discovery is load-order independent: every extension factory has
47
+ registered its listeners before a user lists or launches a role. Synchronous
48
+ registration matches Pi's non-awaiting event bus and keeps role lookup local and
49
+ deterministic. Each contributor must retain the unsubscribe function returned by
50
+ `pi.events.on()` and invoke it from `session_shutdown`; Pi reuses its event bus
51
+ across reloads, so listener cleanup prevents removed or updated packs from
52
+ leaving stale roles.
53
+
54
+ ## Catalog and precedence
55
+
56
+ Listing and exact-name launch use one resolved catalog. Collection order is:
57
+
58
+ 1. bundled package roles;
59
+ 2. registered role-pack definitions;
60
+ 3. global definitions;
61
+ 4. project definitions.
62
+
63
+ Effective precedence remains:
64
+
65
+ ```text
66
+ project > global > package
67
+ ```
68
+
69
+ Role-pack definitions remain in the `package` source layer and add package name,
70
+ version, and path provenance. Global and project definitions can intentionally
71
+ override them.
72
+
73
+ Within the package layer:
74
+
75
+ - bundled roles are protected fallbacks;
76
+ - a role pack colliding with a bundled name is rejected;
77
+ - a name contributed by multiple role packs is disabled;
78
+ - collisions never resolve through incidental extension load order.
79
+
80
+ Invalid registrations do not suppress unrelated roles. Listing surfaces report
81
+ concise diagnostics, and an exact-name launch reports the matching diagnostic
82
+ instead of treating an invalid contribution as a bare agent.
83
+
84
+ ## Reload and security
85
+
86
+ Role files are read on each list or launch, so editing Markdown does not require
87
+ `/reload`. Installing, removing, updating, or changing a role-pack extension
88
+ uses Pi's normal reload flow. Contributor `session_shutdown` cleanup removes the
89
+ old event listener before replacement extensions register. Already-running
90
+ children retain their resolved role and lifecycle.
91
+
92
+ This is not a sandbox. Pi packages and extensions already execute with the
93
+ user's permissions. The host accepts only explicitly registered paths, performs
94
+ no network access or package installation, and does not evaluate role Markdown
95
+ as code.
96
+
97
+ ## Rejected alternatives
98
+
99
+ ### Scan Pi package directories
100
+
101
+ Rejected because npm/Git install paths are private Pi implementation details and
102
+ would bypass package filtering, trust, and provenance.
103
+
104
+ ### Add a second plugin installer or settings inventory
105
+
106
+ Rejected because it duplicates Pi's package state and creates two update/removal
107
+ flows.
108
+
109
+ ### Share an SDK module between packages
110
+
111
+ Rejected because Pi packages have separate module roots. A mandatory helper
112
+ would create fragile runtime coupling or bundle duplicate host code.
113
+
114
+ ### General contribution manifests for workflows and adapters
115
+
116
+ Deferred. ADR-0002 keeps skills in Pi and prohibits a speculative workflow
117
+ engine. The v1 seam contributes roles only. Future concrete contribution types
118
+ should receive their own explicitly versioned contract when repeated need
119
+ exists.
120
+
121
+ ### Pure Markdown packages
122
+
123
+ This is the preferred long-term authoring experience but requires a Pi-core
124
+ custom-resource or contribution hook. If Pi gains one, role packs can remove
125
+ the bridge extension without changing their Markdown definitions or user-facing
126
+ commands.
127
+
128
+ ## Consequences
129
+
130
+ - Installing a role pack remains `pi install <source>`.
131
+ - Authors write one tiny event listener until Pi supports custom resources.
132
+ - The public event name is versioned; breaking changes require a new channel.
133
+ - Package identity is derived from the nearest `package.json`, avoiding repeated
134
+ manifest metadata in the registration call.
135
+ - The existing global and project authoring paths remain compatible.
@@ -0,0 +1,17 @@
1
+ # ADR-0004: Require active user approval for workflow-script execution
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-08-03
5
+ - **Scope:** `giuseppecrj/pi-herdr-agents`
6
+
7
+ ## Context
8
+
9
+ An approved workflow script launches child agents with bounded capabilities. A persisted `approved` field could become stale, be copied to changed bytes or another repository, or be executed by a later parent session without the user seeing the exact strategy.
10
+
11
+ ## Decision
12
+
13
+ For v1, execution requires the user to reply `APPROVE <8-character SHA-256 prefix>` after preparation in the same active parent session for one exact workflow-script revision. Preparation binds the session and branch position, complete script hash, canonical repository root and Git common directory, exact committed base, materialized source evidence, resolved role behavior, runtimes, and effective tools. Start revalidates that complete policy before consuming approval once. The run journal is created only at start, and its first event records the full approval binding and approving user-entry ID. Persisted and cross-session approval are deferred.
14
+
15
+ ## Consequences
16
+
17
+ The runner must fail closed when approval predates preparation, comes from another session, or any bound byte, repository identity, source evidence, or policy changed. Read-only discovery remains a separate pre-approval activity. Preparation creates no run effect, and no workflow child can start before approval is recorded as the journal's first event.
@@ -0,0 +1,17 @@
1
+ # ADR-0005: Keep workflow-script authority with the parent
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-08-03
5
+ - **Scope:** `giuseppecrj/pi-herdr-agents`
6
+
7
+ ## Context
8
+
9
+ Children can discover facts and recommend work, but allowing them to author or revise the workflow script after planning makes it unclear which strategy the user approved and permits unbounded dynamic fan-out.
10
+
11
+ ## Decision
12
+
13
+ For v1, only the parent may author or revise `workflow.js`. Children return findings, evidence, help requests, or non-executable draft artifacts; they cannot change the strategy or its policy envelope.
14
+
15
+ ## Consequences
16
+
17
+ The runner accepts only a parent-authored workflow script. Any material child recommendation must be evaluated by the parent and, when it changes the approved strategy or policy envelope, requires a revised script and renewed user approval.
@@ -0,0 +1,18 @@
1
+ # ADR-0006: Limit the first workflow to read-only effects
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-08-03
5
+ - **Scope:** `giuseppecrj/pi-herdr-agents`
6
+ - **Filename note:** The historical filename still says `isolated-worktrees`; the decision is the read-only first-flow effect boundary.
7
+
8
+ ## Context
9
+
10
+ The first production workflow exists to prove approved JavaScript orchestration, fresh review, evidence, and lifecycle behavior. Writer worktrees, commits, candidate handoffs, and external-system actions add separate ownership and recovery questions that are not needed to validate that runtime.
11
+
12
+ ## Decision
13
+
14
+ The first workflow permits only fresh read-only Pi nodes against one runner-owned detached checkout pinned to the approved committed source. It cannot write files, create commits, mutate the parent checkout, integrate work, or mutate external systems.
15
+
16
+ ## Consequences
17
+
18
+ The bundled skill must not author writer nodes for this flow. Ticket mutation, deployment, messaging, publishing, PR actions, merges, commits, and cleanup remain explicit parent or upstream operations. A later writer workflow requires separate prototype evidence, acceptance criteria, and approval before this boundary changes.
@@ -0,0 +1,19 @@
1
+ # ADR-0007: Require fresh review in skill-authored review workflows
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-08-03
5
+ - **Scope:** `giuseppecrj/pi-herdr-agents`
6
+
7
+ ## Context
8
+
9
+ The first workflow reviews an exact source or candidate. The parent author and any prior workers can share assumptions, so its useful result needs independent examination without inherited implementation context.
10
+
11
+ ## Decision
12
+
13
+ The bundled `orchestrate` skill authors every v1 review workflow with independent fresh read-only review nodes followed by one fresh review synthesizer. Each reviewer and the synthesizer receive the exact source or candidate evidence rather than inherited implementation context. The synthesizer receives every explicit reviewer success or failure and returns the task-specific result.
14
+
15
+ The runtime remains task-agnostic: it enforces the approved capability envelope and operational evidence but does not infer prompts, impose a fixed review receipt, or prove JavaScript data flow. Exact-script human approval is the task-semantics boundary.
16
+
17
+ ## Consequences
18
+
19
+ The skill must not present a script for approval when it omits independent review or synthesis. Worker self-review, inherited-context review, filtered failures, and parent-side synthesis do not satisfy the policy. The trade-off is that the runner does not independently certify review completeness; adding such certification would require the fixed task state machine rejected for v1.