@luminascale/shepherd 0.0.0-stage → 0.6.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.
Files changed (203) hide show
  1. package/.agents/agents/README.md +12 -0
  2. package/.agents/agents/planner.md +38 -0
  3. package/.agents/agents/reviewer.md +38 -0
  4. package/.agents/agents/scout.md +43 -0
  5. package/.agents/agents/worker.md +33 -0
  6. package/.agents/skills/smoke-test/SKILL.md +155 -0
  7. package/.agents/skills/smoke-test/references/forensics.md +46 -0
  8. package/.agents/skills/smoke-test/scripts/live-smoke-poll.mjs +130 -0
  9. package/.github/workflows/publish.yml +77 -0
  10. package/.pi/prompts/release.md +21 -0
  11. package/.prettierrc +10 -0
  12. package/AGENTS.md +88 -0
  13. package/CONTRIBUTING.md +177 -0
  14. package/LICENSE +201 -0
  15. package/README.md +424 -2
  16. package/docs/README.md +25 -0
  17. package/docs/guides/agent-definitions.md +42 -0
  18. package/docs/guides/diagnostics.md +199 -0
  19. package/docs/guides/tool-reference.md +55 -0
  20. package/docs/manual-tests/ping-pong-peer-messaging.md +147 -0
  21. package/docs/plans/agent-labels.md +257 -0
  22. package/docs/plans/architecture.md +110 -0
  23. package/docs/plans/settings-scope.md +163 -0
  24. package/docs/plans/tool-surface-split.md +278 -0
  25. package/docs/reference/dictionary +26 -0
  26. package/docs/releasing.md +47 -0
  27. package/docs/specs/005-agent-messaging-and-task-lifecycle/baseline.md +115 -0
  28. package/docs/specs/005-agent-messaging-and-task-lifecycle/handoff.md +564 -0
  29. package/docs/specs/005-agent-messaging-and-task-lifecycle/phase10-notes.md +109 -0
  30. package/docs/specs/005-agent-messaging-and-task-lifecycle/phase6-notes.md +69 -0
  31. package/docs/specs/005-agent-messaging-and-task-lifecycle/phase7-notes.md +100 -0
  32. package/docs/specs/005-agent-messaging-and-task-lifecycle/phase8-notes.md +127 -0
  33. package/docs/specs/005-agent-messaging-and-task-lifecycle/phase9-notes.md +104 -0
  34. package/docs/specs/005-agent-messaging-and-task-lifecycle/plan.md +1093 -0
  35. package/docs/specs/005-agent-messaging-and-task-lifecycle/spec.md +583 -0
  36. package/docs/specs/005-agent-messaging-and-task-lifecycle/tasks.md +838 -0
  37. package/docs/specs/006-shepherd-tool-rendering/plan.md +175 -0
  38. package/docs/specs/006-shepherd-tool-rendering/spec.md +469 -0
  39. package/index.ts +599 -0
  40. package/package.json +112 -4
  41. package/scripts/capture-system-prompt.mjs +45 -0
  42. package/scripts/extract-pi-system-prompt.mjs +277 -0
  43. package/scripts/host-impact.mjs +74 -0
  44. package/scripts/resolve-agent.mjs +43 -0
  45. package/scripts/show-shepherd-orchestrator.mjs +58 -0
  46. package/scripts/show-shepherd-prompt.mjs +96 -0
  47. package/scripts/verify-suites.mjs +67 -0
  48. package/specs/001-artifacts/spec.md +436 -0
  49. package/specs/002-simplify-agent-orchestration/plan.md +287 -0
  50. package/specs/002-simplify-agent-orchestration/spec.md +323 -0
  51. package/specs/002-simplify-agent-orchestration/tasks.md +212 -0
  52. package/specs/003-orchestrator-session-artifacts/plan.md +396 -0
  53. package/specs/003-orchestrator-session-artifacts/spec.md +453 -0
  54. package/specs/003-orchestrator-session-artifacts/tasks.md +141 -0
  55. package/specs/004-asynchronous-prompt-watchers/plan.md +139 -0
  56. package/specs/004-asynchronous-prompt-watchers/spec.md +202 -0
  57. package/specs/004-asynchronous-prompt-watchers/tasks.md +126 -0
  58. package/specs/005-per-workspace-settings/plan.md +230 -0
  59. package/specs/005-per-workspace-settings/spec.md +368 -0
  60. package/specs/005-per-workspace-settings/tasks.md +178 -0
  61. package/specs/006-dual-runtime-herdr-durable/intent.md +86 -0
  62. package/specs/006-dual-runtime-herdr-durable/journal.md +80 -0
  63. package/specs/006-dual-runtime-herdr-durable/plan.md +242 -0
  64. package/specs/006-dual-runtime-herdr-durable/spec.md +389 -0
  65. package/specs/006-dual-runtime-herdr-durable/tasks.md +199 -0
  66. package/specs/007-unwatched-completion-notice/journal.md +145 -0
  67. package/specs/007-unwatched-completion-notice/plan.md +186 -0
  68. package/specs/007-unwatched-completion-notice/spec.md +284 -0
  69. package/specs/007-unwatched-completion-notice/tasks.md +147 -0
  70. package/specs/008-remote-machine-sheep/intent.md +174 -0
  71. package/specs/008-remote-machine-sheep/journal.md +57 -0
  72. package/specs/008-remote-machine-sheep/prerequisites.md +219 -0
  73. package/specs/009-hc-runtime/intent.md +44 -0
  74. package/specs/009-hc-runtime/plan.md +49 -0
  75. package/specs/009-hc-runtime/spec.md +118 -0
  76. package/specs/009-hc-runtime/tasks.md +62 -0
  77. package/specs/010-unseen-watch-parity/intent.md +57 -0
  78. package/specs/010-unseen-watch-parity/journal.md +172 -0
  79. package/specs/010-unseen-watch-parity/plan.md +74 -0
  80. package/specs/010-unseen-watch-parity/spec.md +191 -0
  81. package/specs/010-unseen-watch-parity/tasks.md +119 -0
  82. package/specs/011-hc-background-poll/intent.md +57 -0
  83. package/specs/011-hc-background-poll/journal.md +95 -0
  84. package/specs/011-hc-background-poll/plan.md +87 -0
  85. package/specs/011-hc-background-poll/spec.md +141 -0
  86. package/specs/011-hc-background-poll/tasks.md +83 -0
  87. package/specs/012-steer-default/intent.md +12 -0
  88. package/specs/012-steer-default/journal.md +40 -0
  89. package/specs/012-steer-default/plan.md +7 -0
  90. package/specs/012-steer-default/spec.md +42 -0
  91. package/specs/012-steer-default/tasks.md +6 -0
  92. package/specs/013-opencode-shepherd/handoff-t011.md +94 -0
  93. package/specs/013-opencode-shepherd/intent.md +59 -0
  94. package/specs/013-opencode-shepherd/plan.md +204 -0
  95. package/specs/013-opencode-shepherd/spec.md +258 -0
  96. package/specs/013-opencode-shepherd/tasks.md +259 -0
  97. package/src/core/artifact-sessions.ts +835 -0
  98. package/src/core/config.ts +329 -0
  99. package/src/core/discovery.ts +342 -0
  100. package/src/core/herdr.ts +1 -0
  101. package/src/core/host.ts +77 -0
  102. package/src/core/ids.ts +78 -0
  103. package/src/core/lifecycle.ts +1 -0
  104. package/src/core/messaging.ts +1 -0
  105. package/src/core/migration.ts +55 -0
  106. package/src/core/orchestration.ts +1 -0
  107. package/src/core/types.ts +143 -0
  108. package/src/core/unseen-completions.ts +114 -0
  109. package/src/extension/cli.ts +417 -0
  110. package/src/extension/config.ts +1 -0
  111. package/src/extension/settings-ui.ts +296 -0
  112. package/src/extension/shepherd-done.ts +768 -0
  113. package/src/extension/shepherd.ts +2548 -0
  114. package/src/extension/system-prompt.ts +38 -0
  115. package/src/extension/unseen-completions.ts +237 -0
  116. package/src/opencode/actions.ts +794 -0
  117. package/src/opencode/bridge.ts +777 -0
  118. package/src/opencode/display.ts +36 -0
  119. package/src/opencode/fieldnotes.ts +60 -0
  120. package/src/opencode/host.ts +62 -0
  121. package/src/opencode/orphans.ts +162 -0
  122. package/src/opencode/server.ts +458 -0
  123. package/src/runtimes/backend.ts +119 -0
  124. package/src/runtimes/detect.ts +102 -0
  125. package/src/runtimes/hc/hc.ts +527 -0
  126. package/src/runtimes/hc/runtime.ts +1898 -0
  127. package/src/runtimes/herdr/herdr.ts +912 -0
  128. package/src/runtimes/herdr/lifecycle.ts +1712 -0
  129. package/src/runtimes/herdr/messaging.ts +703 -0
  130. package/src/runtimes/herdr/orchestration.ts +1583 -0
  131. package/src/runtimes/herdr/runtime.ts +224 -0
  132. package/src/runtimes/runtime.ts +133 -0
  133. package/src/runtimes/settle-observations.ts +114 -0
  134. package/test/fixtures/context-project/AGENTS.md +2 -0
  135. package/test/fixtures/home/.agents/agents/same.md +6 -0
  136. package/test/fixtures/home/.agents/agents/shared-only.md +6 -0
  137. package/test/fixtures/home/.pi/agent/agents/invalid-thinking.md +6 -0
  138. package/test/fixtures/home/.pi/agent/agents/model-empty.md +7 -0
  139. package/test/fixtures/home/.pi/agent/agents/model-explicit.md +7 -0
  140. package/test/fixtures/home/.pi/agent/agents/omit-context-absent.md +5 -0
  141. package/test/fixtures/home/.pi/agent/agents/omit-context-false.md +6 -0
  142. package/test/fixtures/home/.pi/agent/agents/omit-context-invalid.md +6 -0
  143. package/test/fixtures/home/.pi/agent/agents/omit-context-true.md +6 -0
  144. package/test/fixtures/home/.pi/agent/agents/omit-false.md +6 -0
  145. package/test/fixtures/home/.pi/agent/agents/omit-invalid.md +6 -0
  146. package/test/fixtures/home/.pi/agent/agents/omit-pi-docs.md +7 -0
  147. package/test/fixtures/home/.pi/agent/agents/omit-true.md +6 -0
  148. package/test/fixtures/home/.pi/agent/agents/only-user.md +9 -0
  149. package/test/fixtures/home/.pi/agent/agents/same.md +6 -0
  150. package/test/fixtures/proj/.agents/agents/proj-shared.md +6 -0
  151. package/test/fixtures/proj/.pi/agents/project-pi.md +6 -0
  152. package/test/fixtures/proj/.pi/agents/same.md +6 -0
  153. package/test/helpers/fake-clock.mjs +39 -0
  154. package/test/helpers/feature-contracts.mjs +44 -0
  155. package/test/helpers/test-utils.mjs +44 -0
  156. package/test/verify-artifact-sessions.mjs +258 -0
  157. package/test/verify-backend.mjs +297 -0
  158. package/test/verify-child-mislabel.mjs +135 -0
  159. package/test/verify-child-surface.mjs +321 -0
  160. package/test/verify-cli.mjs +197 -0
  161. package/test/verify-command-ux.mjs +100 -0
  162. package/test/verify-compat.mjs +32 -0
  163. package/test/verify-cross-host-notes.mjs +128 -0
  164. package/test/verify-delegate.mjs +161 -0
  165. package/test/verify-detect.mjs +151 -0
  166. package/test/verify-discovery.mjs +239 -0
  167. package/test/verify-done-nudge.mjs +238 -0
  168. package/test/verify-effective-prompt.mjs +98 -0
  169. package/test/verify-hc-matrix.mjs +246 -0
  170. package/test/verify-hc-poll.mjs +260 -0
  171. package/test/verify-host-docs.mjs +35 -0
  172. package/test/verify-host-impact.mjs +49 -0
  173. package/test/verify-ids.mjs +141 -0
  174. package/test/verify-launch.mjs +183 -0
  175. package/test/verify-message-routing.mjs +560 -0
  176. package/test/verify-messaging.mjs +303 -0
  177. package/test/verify-migration-notice.mjs +69 -0
  178. package/test/verify-multi-wait.mjs +42 -0
  179. package/test/verify-opencode-display.mjs +47 -0
  180. package/test/verify-opencode-fieldnotes.mjs +121 -0
  181. package/test/verify-opencode-notice.mjs +77 -0
  182. package/test/verify-opencode-nudge.mjs +116 -0
  183. package/test/verify-opencode-orphans.mjs +160 -0
  184. package/test/verify-opencode-surface.mjs +107 -0
  185. package/test/verify-packaging.mjs +82 -0
  186. package/test/verify-parent-surface.mjs +118 -0
  187. package/test/verify-phase0.mjs +95 -0
  188. package/test/verify-registry.mjs +124 -0
  189. package/test/verify-rename-migration.mjs +111 -0
  190. package/test/verify-rendering.mjs +379 -0
  191. package/test/verify-session-boundary.mjs +146 -0
  192. package/test/verify-settings.mjs +260 -0
  193. package/test/verify-stale-wait.mjs +339 -0
  194. package/test/verify-status-widget.mjs +377 -0
  195. package/test/verify-status.mjs +172 -0
  196. package/test/verify-task-completion.mjs +156 -0
  197. package/test/verify-task-failures.mjs +201 -0
  198. package/test/verify-task-mislabel.mjs +143 -0
  199. package/test/verify-task-registry.mjs +194 -0
  200. package/test/verify-task-watchers.mjs +217 -0
  201. package/test/verify-tool-schemas.mjs +120 -0
  202. package/test/verify-unseen-completions.mjs +1211 -0
  203. package/test/verify-watchers.mjs +181 -0
package/README.md CHANGED
@@ -1,3 +1,425 @@
1
- # Temporary Holding Version
1
+ # Shepherd
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Farewell to `@luminascale/pi-shepherd`.** This is the last release under
4
+ > the old name. Shepherd is moving to **`@luminascale/shepherd`**; when you are
5
+ > ready, install the new package — settings, agent definitions, registrations,
6
+ > and fieldnotes carry over with no manual migration. The one-time notice you
7
+ > see in your host session points to the same place.
8
+
9
+ Shepherd is a no-fuss extension for native, low-level Herdr agent orchestration. The **Shepherd**—your main session in Pi or OpenCode—can launch and coordinate specialized agents in visible Herdr panes, while shared session fieldnotes (artifacts) let agents share context across delegated work. One package, two host entry points; Pi and OpenCode users never need steps from the other host.
10
+
11
+ ## Choose your host
12
+
13
+ | Track | Install | Verify after restart |
14
+ | --- | --- | --- |
15
+ | **[Pi](#pi-track)** | `pi install npm:@luminascale/shepherd` | `/shepherd agents` |
16
+ | **[OpenCode](#opencode-track)** | add `@luminascale/shepherd` to `plugins` in `opencode.json` | `/shepherd agents` |
17
+
18
+ The tools, opaque ids, agent definitions, and fieldnotes layout are shared. Host-specific differences (install, settings surface, command output) are called out in each track below; the rest of this document applies to both.
19
+
20
+ ## Pi track
21
+
22
+ Install with pi's package installer:
23
+
24
+ ```bash
25
+ pi install npm:@luminascale/shepherd
26
+ ```
27
+
28
+ Reload pi, then verify the extension is available with `/shepherd agents`. You should see the bundled agent definitions, including `scout`, `planner`, `worker`, and `reviewer`.
29
+
30
+ Pi uses the `/shepherd settings` menu for configuration (see [Settings](#settings)), and pi's steer mode for completion notices. No OpenCode setup is required.
31
+
32
+ ## OpenCode track
33
+
34
+ Add the package to your OpenCode plugin list:
35
+
36
+ ```jsonc
37
+ // ~/.config/opencode/opencode.json (or the project-level .opencode/opencode.json)
38
+ {
39
+ "$schema": "https://opencode.ai/config.json",
40
+ "plugins": ["@luminascale/shepherd"]
41
+ }
42
+ ```
43
+
44
+ Restart OpenCode, then verify with `/shepherd agents`. The `shepherd_*` tools and `/shepherd` command have the same names and semantics as in Pi. You do not need to install pi to use Shepherd from OpenCode.
45
+
46
+ OpenCode differences:
47
+
48
+ - Settings are file-based: `~/.config/opencode/pi-shepherd/config.json` (user) and `.shepherd/config.json` (project, with `"projectScope": true`). There is no settings menu yet.
49
+ - Human `/shepherd …` command output is display-only — it renders in full and returns control without starting an assistant turn.
50
+ - Completion notices arrive as normal parent-session messages that wake the model.
51
+ - Fieldnotes are bound to the OpenCode session id and the session's working directory, on the same `.shepherd/sessions/` layout Pi uses.
52
+ - After an OpenCode server restart, sheep keep running but their opaque ids are lost. You get one display-only notice listing the orphaned sheep; use `shepherd({ action: "reap" })` to close them safely (or respawn and close the old panes). Fieldnotes and queued envelopes remain on disk until reaped.
53
+
54
+ ## Key Features
55
+
56
+ - **Native, no-fuss, low-level Herdr agent orchestration** — Shepherd uses native Herdr panes for all agents and simple, open primitives for agent orchestration. Everything is visible and inspectable. Shepherd does not impose a workflow; it gives you the tools to build your own.
57
+ - **Herdr headless support** — work inside Herdr or from a plain terminal while keeping launched agents visible and inspectable in Herdr.
58
+ - **Granular system-prompt and agent-context support** — Shepherd goes beyond standard definitions and utilises pi's open system-prompt. Shepherd agents can be defined with granular control over context for very specific and narrow agent and context control.
59
+ - **Manual agent launch** — start an interactive specialist directly with `/shepherd spawn` and chat with it in its own host session.
60
+ - **Shared session fieldnotes (artifacts)** — give agents a durable shared place to leave notes and share context across delegated work, on the same layout in both hosts.
61
+
62
+ ## Requirements
63
+
64
+ - [Pi](https://github.com/earendil-works/pi) **or** [OpenCode](https://opencode.ai) (see the tracks above)
65
+ - [Herdr](https://github.com/herdrdev/herdr)
66
+ - Node.js 22 or newer
67
+
68
+ ## Available tools
69
+
70
+ pi-shepherd exposes these tools to the Shepherd. You can use them explicitly when you need precise control, but ordinary natural-language requests are the recommended starting point:
71
+
72
+ | Tool | Purpose |
73
+ | --- | --- |
74
+ | `shepherd` | List definitions (`agents`), list active agents (`herd`), or remove stale pane registrations (`prune`) |
75
+ | `shepherd_spawn` | Create an idle persistent agent |
76
+ | `shepherd_delegate` | Start a tracked task; returns immediately with a task ID |
77
+ | `shepherd_message` | Send an asynchronous message (parent or peer); `expectsReply` opens a tracked reply request |
78
+ | `shepherd_watch` | Receive task completion without blocking the current turn (task IDs preferred, legacy prompt IDs still work) |
79
+ | `shepherd_status` | Inspect an agent without focusing its pane; reports process and task state independently |
80
+ | `shepherd_close` | Close an owned agent, cancel its active task, and clear pending requests |
81
+ | `shepherd_read` | Read recent terminal output for diagnostics |
82
+ | `shepherd_prompt` | **Deprecated** one-turn compatibility path; prefer `shepherd_delegate` for tracked work |
83
+
84
+ Child agents additionally see `shepherd_message` (talk to the parent or a peer) and `shepherd_done` (the only normal successful completion of their tracked task).
85
+
86
+ ## Your first delegation
87
+
88
+ You do not need to call Shepherd’s tools yourself. After restarting pi, describe the work you want done in your normal conversation, or nudge the Shepherd to delegate it explicitly. Phrases such as “use Shepherd,” “ask the herd,” “ask a sheep,” “delegate this,” “orchestrate a review,” or “use a subagent” are all natural-language requests; no special syntax is required. For example:
89
+
90
+ > Ask a planner to create an implementation plan for adding authentication, including the relevant files and recommended steps.
91
+
92
+ The Shepherd starts the planner in a visible Herdr tab, gives it the task, collects its result, and reports back to you. This is the recommended one-shot workflow. Shepherd’s structured tools are still available when you need explicit lifecycle control, parallel work, or want to inspect what the Shepherd is doing; see [Placement and lifecycle](#placement-and-lifecycle) below.
93
+
94
+ ### Work directly with a specialist agent
95
+
96
+ If you would rather work with a specialist directly, use the human command surface described in the [Command reference](#command-reference). Switch to the new Herdr tab to chat with the planner. Spawning creates an idle, persistent agent; it does not submit a task. Close interactive agents when you are finished so your Herdr session does not accumulate unnecessary panes.
97
+
98
+ ## Common workflows
99
+
100
+ ### Sequential work
101
+
102
+ Use sequential delegation when one agent’s result should inform the next agent’s task. Describe the handoff in your request:
103
+
104
+ > Ask a planner to create an implementation plan for adding authentication. Once it has finished, give its plan to a worker and ask the worker to implement the feature. Return the implementation result when it is complete.
105
+
106
+ The Shepherd waits for the planner before starting the worker and passes the planner’s result along as context. This is useful for plan-then-implement, research-then-review, or any workflow with a clear handoff.
107
+
108
+ ### Parallel work
109
+
110
+ Use parallel delegation when tasks are independent. Ask the Shepherd to delegate them together:
111
+
112
+ > Ask two scouts to work in parallel: have one research how authentication is implemented and the other research authorization. Wait for both results, then summarize the findings and explain any relevant connections.
113
+
114
+ The Shepherd runs the independent tasks concurrently and combines their results. This is useful for comparing approaches, investigating separate parts of a codebase, or getting multiple reviews of the same change.
115
+
116
+ ### Delegate, then watch
117
+
118
+ The tracked-task workflow is: spawn, delegate, watch, close. `shepherd_delegate` starts the work and returns immediately with a **task ID**; nothing is settled until the child calls `shepherd_done` (or the task fails, is cancelled, or times out).
119
+
120
+ ```text
121
+ shepherd_spawn({ agent: "worker", label: "auth" })
122
+ shepherd_delegate({ target: "<agent ID>", task: "Implement the auth middleware from the plan." })
123
+ shepherd_watch({ id: "<task ID>" })
124
+ ```
125
+
126
+ When the task settles, the watcher delivers a completion notification containing the result. Delivery uses pi's steer mode: if the Shepherd is mid-turn, the notification is injected between tool rounds (before cleanup calls such as `shepherd_close`); if the Shepherd is idle, it triggers a new turn immediately. Watchers finish automatically after all their tasks settle; they do not close agents. Use `shepherd_watch` for non-blocking completion notifications and `shepherd_status` to inspect intermediate task state.
127
+
128
+ Watching is optional, but completion is never silent: a tracked task that settles while no watcher is attached produces one notice. When the Shepherd is mid-turn, the notice is appended at the next settle boundary (one extra model request, never a mid-turn interruption); when the Shepherd is idle, it arrives as a single coalesced wake covering the whole batch. The notice names the settled tasks and the `shepherd_watch({ id: [ … ] })` call that retrieves their full results. It never claims a result is lost — a watcher registered after settlement still receives the result synchronously. `shepherd_watch` on a settled task clears its pending notice, and `shepherd_close` reports any notices it drops for that agent. The notice holds on both backends: an hc terminal settle produces the same wording as a Herdr pane settle (only the opaque task/agent ids differ). On hc, a 250 ms background poll settles queued completions even with no watcher and no messages, and `shepherd_watch` / `shepherd_status` drain first so they never report stale pending/running for an already-settled task.
129
+
130
+ ### Forgotten completion nudges
131
+
132
+ If a child ends its turn while its tracked task is still open — the common slip being finished work with no `shepherd_done` — the child extension notices at that exact boundary and feeds itself one reminder turn asking for a terminal `shepherd_done`. The nudge is deliberately narrow: it only fires for a tracked task the child still holds, never after an aborted or errored turn, and never while a tracked request (`expectsReply`) is outstanding, because ending the turn is how a child waits for an answer.
133
+
134
+ The reminder budget is one turn per task by default (`PI_SHEPHERD_DONE_NUDGES`, `0` disables it). If the task is still open afterwards, the child reports the stall to the parent as a normal Shepherd message instead of inventing a status — the parent then blocks, cancels, or waits for the task deadline. Legacy `shepherd_prompt` runs are unaffected: they settle through the completion sidecar at turn end.
135
+
136
+ ### Messaging between agents
137
+
138
+ Agents in the same project can message each other through the parent broker. The child's `shepherd_message` tool can target `parent` or an owned agent ID. A peer question that requires an answer is sent with `expectsReply: true`:
139
+
140
+ ```text
141
+ shepherd_message({
142
+ target: "<planner agent ID>",
143
+ message: "Which retry backoff should the middleware use?",
144
+ taskId: "<own task ID>",
145
+ expectsReply: true
146
+ })
147
+ ```
148
+
149
+ The angle-bracket values above are documentation placeholders only. At runtime,
150
+ copy the planner's exact `id` from `shepherd_spawn` into `target`; do not use
151
+ `planner`, a display label, or a Herdr pane ID. Invalid targets are rejected.
152
+
153
+ While the answer is outstanding, the sender's task is `waiting` — even though its pi process is `idle` and the child's turn has ended. The reply (correlated by `replyTo`) returns the task to `running`; a `shepherd_done`, cancellation, or the reply deadline settle it. Delivery modes: `followUp` (default) queues the message for the recipient's next turn; `steer` injects it urgently into an active turn. Child requests (`expectsReply: true`) and replies wake the parent at the next safe boundary (between tool rounds when the Shepherd is mid-turn, immediately when it is idle); ordinary informational messages remain passive. A wake-up never interrupts an active tool call.
154
+
155
+ ### Continue working while an agent runs
156
+
157
+ `shepherd_watch({ id: prompt.id })` is also non-blocking for the legacy prompt path; completion arrives as a steered notification.
158
+
159
+ ### Compatibility
160
+
161
+ `shepherd_prompt` is a **deprecated** one-turn compatibility path: each prompt still completes at the end of that child turn (that semantics is unchanged and documented, not silently altered). Use `shepherd_delegate` instead for any work that may need to answer or receive a reply. `shepherd_watch` accepts task IDs (`shepherd_delegate`) and legacy prompt IDs (`shepherd_prompt`) and returns immediately; completions arrive as steered notifications. Use `shepherd_status` to inspect running or waiting tasks.
162
+
163
+ ## Agent definitions
164
+
165
+ Agent definitions are Markdown files, so you can tune an agent’s behavior with granular system-prompt engineering. Define its role, workflow, tools, model, and prompt options in YAML frontmatter and the Markdown body. The supported frontmatter fields are:
166
+
167
+ | Field | Values | Default | Description |
168
+ | --- | --- | --- | --- |
169
+ | **`name`** | String | — | The agent’s name. **Required.** |
170
+ | **`description`** | String | — | A short description shown during discovery. **Required.** |
171
+ | **`tools`** | Comma-separated string or YAML list | pi’s default tools | Tools available to the agent. |
172
+ | **`model`** | Provider-qualified model, `null`, or `default` | Shepherd’s model | Select the model, for example `anthropic/claude-sonnet-4-5`. `null`, `default`, or omission inherits the Shepherd’s model. |
173
+ | **`thinking`** | `default`, `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max` | Shepherd’s level | Select the requested Pi thinking level. `null`, `default`, empty, or omission inherits the Shepherd’s current level. Unsupported levels are clamped by Pi to the child model’s capabilities. |
174
+ | **`omit-system-prompt`** | `true`, `false` | `false` | Omit pi’s built-in system prompt when `true`. |
175
+ | **`omit-pi-documentation`** | `true`, `false` | `false` | Omit pi’s built-in documentation guidance when `true`. |
176
+ | **`omit-context-files`** | `true`, `false` | `false` | Omit automatic `AGENTS.md` and `CLAUDE.md` context-file loading when `true`. |
177
+ | **`user-invocable`** | `true`, `false` | `true` | Indicate whether the agent is intended to be directly invoked by a user. |
178
+
179
+ For example:
180
+
181
+ ```markdown
182
+ ---
183
+ name: tester
184
+ description: Runs and evaluates GUI tests
185
+ tools: read, grep, find
186
+ model: anthropic/claude-sonnet-4-5
187
+ thinking: high
188
+ omit-system-prompt: false
189
+ omit-pi-documentation: true
190
+ omit-context-files: true
191
+ user-invocable: true
192
+ ---
193
+
194
+ You are a focused GUI testing specialist. Report reproducible failures
195
+ with exact steps and useful evidence.
196
+ ```
197
+
198
+ `thinking` is a requested level. Pi clamps it to a level supported by the
199
+ child model, so `xhigh` may become `high`, and a model that cannot
200
+ disable reasoning may not honor `off`. `none` is invalid; use `off` for an
201
+ explicit no-reasoning request. Invalid `thinking` or `model` values cause that definition to be skipped during discovery rather than preventing other agents from loading.
202
+
203
+ ### Bundled definitions and discovery
204
+
205
+ The bundled agent definitions are:
206
+
207
+ - `scout` — fast codebase investigation
208
+ - `planner` — planning and decomposition
209
+ - `worker` — implementation work
210
+ - `reviewer` — review and verification
211
+
212
+ User and project definitions can add or override these names. Discovery precedence is:
213
+
214
+ 1. `~/.pi/agent/agents/`
215
+ 2. `~/.agents/agents/`
216
+ 3. nearest project `.pi/agents/`
217
+ 4. nearest project `.agents/agents/`
218
+ 5. bundled `.pi/agents/`
219
+ 6. bundled `.agents/agents/`
220
+
221
+ Discovery defaults to `both` scope, so repository-controlled definitions are listed alongside user definitions. The confirmation gate (`confirmProjectAgents`) is user-owned and off by default; enable it in `/shepherd settings` when working in untrusted repositories — a project file can never change it. The bundled definitions can be disabled from settings. Agents retain the host user’s normal pi tool permissions.
222
+
223
+ ## Placement and lifecycle
224
+
225
+ By default, `shepherd_spawn` creates a background Herdr tab. You can request a pane or workspace placement:
226
+
227
+ ```text
228
+ shepherd_spawn({
229
+ agent: "worker",
230
+ label: "implementation",
231
+ placement: "pane_right", // pane_right, pane_down, tab, or workspace
232
+ })
233
+ ```
234
+
235
+ The working directory defaults to the Shepherd session and `cwd` can be supplied when spawning. The child model and requested thinking level come from the discovered agent definition; omission, `null`, or `default` inherits the Shepherd session's corresponding setting. Agent scope, project approval, and prompt-shaping options come from Shepherd settings and the discovered definition; they are not spawn overrides.
236
+
237
+ Lifecycle tools use short, opaque, session-scoped IDs:
238
+
239
+ ```text
240
+ shepherd_spawn -> agent ID (for delegate, message, status, close)
241
+ shepherd_delegate -> task ID (for watch, wait, message taskId, shepherd_done)
242
+ shepherd_message -> message ID (answer it with replyTo)
243
+ ```
244
+
245
+ Task IDs identify the unit of work; message IDs identify individual envelopes and only matter when correlating a reply (the answering participant sets the request's message ID as `replyTo`). When the Shepherd answers a child-originated request, the parent resolves its own pending request as soon as that reply is queued, so the child does not need to send a redundant acknowledgment before calling `shepherd_done`. Do not substitute a Herdr pane ID for any of these. Pane IDs are only diagnostic targets for `shepherd_read`.
246
+
247
+ ## Command reference
248
+
249
+ The slash command is useful when you want to manage an agent directly rather than ask the Shepherd to orchestrate a task:
250
+
251
+ ```text
252
+ /shepherd agents # list available definitions
253
+ /shepherd agents both # include project definitions
254
+ /shepherd herd # list active agents
255
+ /shepherd spawn worker # spawn an interactive agent
256
+ /shepherd status worker # inspect an agent
257
+ /shepherd read worker --lines=20
258
+ /shepherd settings
259
+ ```
260
+
261
+ Supported actions are `agents`, `herd`, `prune`, `spawn`, `status`, `read`, and `settings`. `/shepherd list` remains a compatibility alias for `/shepherd agents`. Optional spawn flags include: `--placement pane_right|pane_down|tab|workspace` and `--cwd <path>`.
262
+
263
+ For one-shot delegation, prompting, waiting, parallel work, and opaque-ID lifecycle control, use the structured `shepherd_*` tools instead of manual commands. The old single-tool form such as `shepherd({ action: "prompt", ... })` is no longer supported.
264
+
265
+ ## Settings
266
+
267
+ Open `/shepherd` or `/shepherd settings` to configure pi-shepherd. The menu
268
+ shows the effective values for the current workspace; use the arrow keys and
269
+ Enter to cycle values, `/` to fuzzy-search, and `Esc` to close it.
270
+
271
+ | Option | Values | Default | Description |
272
+ | --- | --- | --- | --- |
273
+ | **Settings scope** (`projectScope`) | `user`, `project` | `user` | Select the settings source for this workspace. A dormant project file is shown as `user (project file dormant)`. |
274
+ | **Agent scope** (`agentScope`) | `user`, `project`, `both` | `both` | Select which agent definition directories are searched. Project agents are repository-controlled; choose `user` to ignore them entirely. |
275
+ | **Include bundled agents** (`includeBundledAgents`) | on, off | on | Include the built-in `scout`, `planner`, `worker`, and `reviewer` definitions in discovery. |
276
+ | **Confirm project agents** (`confirmProjectAgents`) | on, off | off | User-only security gate for project-local agent definitions. A project config cannot change it. Enable it when working in untrusted repositories. |
277
+ | **Keep tab open after done** (`keepOpen`) | on, off | on | Leave the Herdr tab open after an agent completes so its output can be inspected. |
278
+ | **Keep agent alive after done** (`stayOpen`) | on, off | on | Keep the agent's pi process alive after completion so you can continue driving it in its tab. |
279
+ | **Enable fieldnotes** (`fieldnotes`) | on, off | on | Create durable shared session notes for delegated prompts. Changes take effect when the next pi session starts. |
280
+ | **Use sheep emoji** (`emojiSheep`) | on, off | on | Show the animated `🐑` marker beside actively working agents; off uses a plain marker instead. |
281
+ | **Default run timeout** (`timeout`) | `1`, `2`, `5`, `10`, `20`, `30`, or `60` minutes | `60` minutes | Set the default time limit before a Herdr run is reported as timed out. |
282
+ | **Stale wait reminder** (`staleWaitThreshold`) | `off`, `1`, `2`, `5`, `10`, `15`, or `30` minutes | `30` minutes | A task waiting longer than this on a required reply raises one stale-wait reminder. `off` disables reminders; reminders never cancel or block the task. |
283
+ | **Execution backend** (`backend`) | `auto`, `herdr`, `hc` | `auto` | Run where called from — Herdr TUI or hc app. A pin that can't be reached fails cleanly with a setup hint, never a silent fallback. App-side only; the model never decides. |
284
+
285
+ The user layer is stored in `pi-shepherd/config.json` inside the active pi
286
+ agent directory (`~/.pi/agent` by default, or `PI_CODING_AGENT_DIR`). It stores
287
+ personal values only. The project layer is `.shepherd/config.json` in the
288
+ current working directory, with no walk-up. A project file is active only when
289
+ it contains `"projectScope": true`; when active, it is self-contained and
290
+ missing project-owned fields fall back to built-in defaults rather than private
291
+ user values. A project file with `projectScope: false` or no flag is dormant.
292
+
293
+ `confirmProjectAgents` is intentionally user-owned. A committed project file
294
+ may select repository-controlled agent definitions through `agentScope`, but it
295
+ cannot change the confirmation gate in either direction. The gate is off by
296
+ default; a user who wants an approval prompt before a project-local agent runs
297
+ must enable it in the user layer.
298
+
299
+ For example:
300
+
301
+ ```jsonc
302
+ // ~/.pi/agent/pi-shepherd/config.json — personal values
303
+ {
304
+ "agentScope": "both",
305
+ "includeBundledAgents": true,
306
+ "confirmProjectAgents": false,
307
+ "keepOpen": true,
308
+ "stayOpen": true,
309
+ "fieldnotes": true,
310
+ "emojiSheep": true,
311
+ "timeout": 60,
312
+ "staleWaitThreshold": 30
313
+ }
314
+
315
+ // .shepherd/config.json — optional, self-contained project values
316
+ {
317
+ "agentScope": "project",
318
+ "includeBundledAgents": true,
319
+ "keepOpen": true,
320
+ "stayOpen": false,
321
+ "fieldnotes": true,
322
+ "emojiSheep": true,
323
+ "timeout": 30,
324
+ "staleWaitThreshold": 5,
325
+ "projectScope": true
326
+ }
327
+ ```
328
+
329
+ Project settings are intended to be optionally committed. Since `.shepherd/`
330
+ also contains runtime fieldnote sessions, use this pattern when sharing only
331
+ the config:
332
+
333
+ ```gitignore
334
+ .shepherd/*
335
+ !.shepherd/config.json
336
+ ```
337
+
338
+ When a delegated task is **waiting** on a required reply (set with
339
+ `shepherd_message` + `expectsReply`, or set by the child asking another
340
+ participant), it can sit there for a while if the target is busy.
341
+ `staleWaitThreshold` controls how long a task may wait before the parent
342
+ receives a **single** stale-wait reminder naming the task, the question, the
343
+ target, and how long it has been waiting. The reminder is informational: it
344
+ never cancels, times out, or blocks the task. The task's own reply deadline
345
+ (`timeout`) remains the authoritative bound and settles the task as `blocked`
346
+ if the reply never comes. A reply (or the task resuming/completing) clears the
347
+ episode, so the same wait never re-notifies while open.
348
+
349
+ ## Diagnostic tools
350
+
351
+ These commands are primarily useful for contributors and local development checkouts. Use the diagnostic extractor when you need to see the fully assembled prompt that pi will give the Shepherd or a discovered agent:
352
+
353
+ ```bash
354
+ npm run extract:system-prompt -- shepherd
355
+ npm run extract:system-prompt -- agent scout --scope both --cwd /path/to/project
356
+ npm run extract:system-prompt -- agent scout --output /tmp/scout-system.md
357
+ npm run extract:system-prompt -- shepherd --json
358
+ ```
359
+
360
+ This captures the prompt at pi’s `before_agent_start` hook without making a provider request. For the full prompt-composition workflow and troubleshooting, see the [Diagnostics guide](docs/diagnostics.md).
361
+
362
+ ### Inspect active agents
363
+
364
+ ```text
365
+ /shepherd herd
366
+ ```
367
+
368
+ The command lists all active agents currently detected in Herdr. For one agent, use `/shepherd status` or `/shepherd read`.
369
+
370
+ ### Reading status
371
+
372
+ `shepherd_status` reports **process state and task state independently**. A process can be `idle` while its delegated task is still `waiting` on a required reply, and one can be `working` while its task is `running`. When an agent owns an open task the status also includes the task ID, how long it has been `waiting`, the pending request (message) ID, the agent the reply is expected from, and a `stale` flag once a stale-wait reminder has fired.
373
+
374
+ The persistent "below the editor" widget tracks the same two dimensions: it lists agents that are `working` **or** that are idle-but-`waiting` on a required reply (so an idle child parked on a peer reply is never hidden as done). Waiting rows render distinctly, show how long the wait has lasted, and name the agent being waited on; a `stale` wait is flagged. Pane and task IDs never leak into the display — rows use only display names.
375
+
376
+ ## Fieldnotes
377
+
378
+ When fieldnotes are enabled, all agents orchestrated by one Shepherd session in the same project share a durable note session:
379
+
380
+ ```text
381
+ .shepherd/sessions/NNNN-orchestrator-<id>/
382
+ ├── session.json
383
+ ├── shepherd.md
384
+ └── <agent>-NN.md
385
+ ```
386
+
387
+ `shepherd.md` is the shared index, and each delegated prompt receives its own note. Notes are retained after waiting, closing, timeout, or extension restart; pi-shepherd does not automatically delete, archive, commit, or check them out. The fieldnotes setting is session-scoped, so start a new Shepherd session after changing it. Existing agents retain the current session’s behavior.
388
+
389
+ ## Troubleshooting
390
+
391
+ ### An agent is not responding
392
+
393
+ Inspect its state and terminal output:
394
+
395
+ ```text
396
+ /shepherd status <agent>
397
+ /shepherd read <agent>
398
+ ```
399
+
400
+ ### There are too many Herdr panes
401
+
402
+ The slash command does not close lifecycle-managed agents. Use `shepherd_close` with the agent ID returned by `shepherd_spawn`:
403
+
404
+ ```text
405
+ shepherd_close({ id: agent.id })
406
+ ```
407
+
408
+ ### There are stale pane registrations
409
+
410
+ Remove registrations for panes that no longer exist:
411
+
412
+ ```text
413
+ /shepherd prune
414
+ ```
415
+
416
+ ## Herdr runtime and safety
417
+
418
+ pi-shepherd uses the `herdr` CLI and never uses an invisible subprocess fallback. It works inside Herdr or from a plain terminal by ensuring a headless Herdr server is available. Background tabs use `--no-focus`, preserve the requested working directory, and remain visible for inspection.
419
+
420
+ Only panes recorded in pi-shepherd’s created-pane registry may be closed by the extension. Temporary launch and session resources are cleaned only after the child pane is confirmed gone.
421
+
422
+ ## Contributing
423
+
424
+ For development setup, testing instructions, and contribution guidelines, see
425
+ [CONTRIBUTING.md](CONTRIBUTING.md).
package/docs/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Documentation
2
+
3
+ ## Guides
4
+
5
+ User-facing documentation:
6
+
7
+ - [Agent definitions](guides/agent-definitions.md)
8
+ - [Tool reference](guides/tool-reference.md)
9
+ - [Diagnostics](guides/diagnostics.md)
10
+
11
+ ## Reference
12
+
13
+ - [Dictionary](reference/dictionary)
14
+
15
+ ## Plans
16
+
17
+ Implementation plans and design notes are kept separately from stable user documentation:
18
+
19
+ - [Architecture](plans/architecture.md)
20
+ - [Agent labels](plans/agent-labels.md)
21
+ - [Settings scope (historical)](plans/settings-scope.md)
22
+ - [Per-workspace settings specification](../specs/005-per-workspace-settings/spec.md)
23
+ - [Remote machine sheep — intent](../specs/008-remote-machine-sheep/intent.md)
24
+ - [Remote machine sheep — remote prerequisites](../specs/008-remote-machine-sheep/prerequisites.md)
25
+ - [Tool surface split](plans/tool-surface-split.md)
@@ -0,0 +1,42 @@
1
+ # Agent definitions
2
+
3
+ Agent definitions are Markdown files with YAML frontmatter followed by the agent's instructions. They control an agent's role, tools, model, and prompt composition.
4
+
5
+ | Field | Values | Default | Description |
6
+ | --- | --- | --- | --- |
7
+ | `name` | String | — | Agent name. **Required.** |
8
+ | `description` | String | — | Description shown during discovery. **Required.** |
9
+ | `tools` | Comma-separated string or YAML list | pi's default tools | Tools available to the agent. |
10
+ | `model` | Provider-qualified model, `null`, or `default` | Shepherd's model | For example, `anthropic/claude-sonnet-4-5`. Omission, `null`, and `default` inherit the Shepherd's model. |
11
+ | `thinking` | `default`, `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max` | Shepherd's level | Omission, `null`, empty, and `default` inherit the Shepherd's current thinking level. Pi clamps unsupported levels to the child model's capabilities. |
12
+ | `omit-system-prompt` | `true`, `false` | `false` | Omit pi's built-in system prompt. |
13
+ | `omit-pi-documentation` | `true`, `false` | `false` | Omit pi's built-in documentation guidance. |
14
+ | `omit-context-files` | `true`, `false` | `false` | Omit automatic `AGENTS.md` and `CLAUDE.md` loading. |
15
+ | `user-invocable` | `true`, `false` | `true` | Whether the agent is intended for direct user invocation. |
16
+
17
+ Example:
18
+
19
+ ```markdown
20
+ ---
21
+ name: tester
22
+ description: Runs and evaluates GUI tests
23
+ tools: read, grep, find
24
+ model: anthropic/claude-sonnet-4-5
25
+ thinking: high
26
+ omit-system-prompt: false
27
+ omit-pi-documentation: true
28
+ omit-context-files: true
29
+ user-invocable: true
30
+ ---
31
+
32
+ You are a focused GUI testing specialist. Report reproducible failures
33
+ with exact steps and useful evidence.
34
+ ```
35
+
36
+ `thinking` is a requested level. Pi clamps it to a level supported by the
37
+ child model, so `xhigh` may become `high`, and a model that cannot
38
+ disable reasoning may not honor `off`. `none` is invalid; use `off` for an
39
+ explicit no-reasoning request. Invalid `thinking` or `model` values cause that definition to be skipped during discovery rather than preventing other agents from loading.
40
+
41
+ See the [README](../../README.md) for discovery precedence, bundled agents,
42
+ and project-agent approval behavior.