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,196 @@
1
+ # Worktree subagents
2
+
3
+ This guide is the operational reference for running writing agents in isolated Git worktrees with `pi-herdr-agents`. For the complete tool API, installation, and status model, see the [README](../README.md). For the product and open-source research behind these choices, see the [research report](research/worktree-subagent-orchestration.md).
4
+
5
+ ## Quick start
6
+
7
+ Run Pi inside Herdr from a Git checkout, then give each independent writing task a unique branch:
8
+
9
+ ```typescript
10
+ subagent({
11
+ name: "Ticket 123",
12
+ agent: "worker",
13
+ cwd: "/path/to/repository",
14
+ worktree: { branch: "ticket/123", base: "main" },
15
+ task: "Implement ticket 123, run its tests, commit the result, and report the commit SHA. Do not push, merge, or remove the worktree.",
16
+ });
17
+ ```
18
+
19
+ `base` is optional. When omitted, the extension resolves the source checkout's committed `HEAD` before creating the worktree.
20
+
21
+ ## When to use a worktree
22
+
23
+ Use one worktree per independent task that may write files or create commits. This prevents workers from overwriting each other's files and indexes.
24
+
25
+ Use an ordinary subagent pane instead when the task is read-only, interactive, or intentionally shares the current checkout:
26
+
27
+ ```typescript
28
+ subagent({
29
+ name: "Scout auth",
30
+ agent: "scout",
31
+ task: "Map the auth flow; do not modify files.",
32
+ });
33
+ ```
34
+
35
+ Worktrees isolate checkouts, indexes, and `HEAD`. They are **not security sandboxes**: worktrees still share the repository's object database and most refs, and the child process has the same host permissions as Pi.
36
+
37
+ ## Launch contract
38
+
39
+ For a worktree launch:
40
+
41
+ - `cwd` selects the source Git repository. A relative tool argument is resolved from the parent Pi process's current directory.
42
+ - `worktree.branch` is a new, unique branch name. Git/Herdr rejects a branch that cannot be created or is already checked out elsewhere.
43
+ - `worktree.base` may be any revision that resolves to a commit in the source repository. It defaults to committed `HEAD`.
44
+ - The extension resolves `base` to an exact SHA, writes an ownership manifest, then calls `herdr worktree create --no-focus`.
45
+ - The child starts at the root of the returned worktree, in that workspace's root pane.
46
+ - Uncommitted and untracked files from the parent checkout are not copied. Commit anything the child must see before spawning it, or pass the needed context in the task.
47
+ - Worktree creation does not steal terminal focus.
48
+
49
+ `worktree` cannot be set in agent frontmatter and is not exposed by the `/subagent <agent> <task>` shorthand. It is selected per call to the `subagent` tool.
50
+
51
+ ## Parent and worker responsibilities
52
+
53
+ | Parent/orchestrator | Worker |
54
+ | --- | --- |
55
+ | Choose a unique branch and committed base | Work only in the provided checkout |
56
+ | Provide complete task context | Read existing code before editing |
57
+ | Review the returned Git metadata and diff | Run relevant verification |
58
+ | Decide how and when to integrate | Commit when the task requests a commit |
59
+ | Push, create a PR, merge, or clean up explicitly | Do not push, merge, switch branches, or remove the worktree unless explicitly authorized |
60
+
61
+ A worker commit is recommended because it gives the parent an exact review and integration unit. Uncommitted worker changes are still retained and reported; they are not discarded.
62
+
63
+ ## Parallel writing pattern
64
+
65
+ Independent tasks can launch concurrently from the same committed base:
66
+
67
+ ```typescript
68
+ subagent({
69
+ name: "API ticket",
70
+ agent: "worker",
71
+ worktree: { branch: "tickets/api", base: "main" },
72
+ task: "Implement the API ticket, test it, and commit. Do not push or merge.",
73
+ });
74
+
75
+ subagent({
76
+ name: "UI ticket",
77
+ agent: "worker",
78
+ worktree: { branch: "tickets/ui", base: "main" },
79
+ task: "Implement the UI ticket, test it, and commit. Do not push or merge.",
80
+ });
81
+ ```
82
+
83
+ Do not parallelize tasks that edit the same behavior, depend on each other's unmerged output, or require ordered migrations. Run those sequentially, or integrate the prerequisite first and use its committed SHA as the next task's base.
84
+
85
+ ## Lifecycle and ownership manifest
86
+
87
+ Before asking Herdr to create resources, the extension writes a manifest under:
88
+
89
+ ```text
90
+ <parent-session-directory>/artifacts/<parent-session-id>/worktree-runs/<run-id>.json
91
+ ```
92
+
93
+ The manifest uses the stable owner identifier `pi-herdr-subagents`, retained for compatibility independently of the npm package name. It records the requested base and branch, observed workspace/pane/path, child session path, timestamps, state, and final Git handoff when available.
94
+
95
+ Possible states are:
96
+
97
+ | State | Meaning |
98
+ | --- | --- |
99
+ | `provisioning` | Intent recorded; Herdr creation not yet confirmed |
100
+ | `provisioned` | Worktree workspace exists |
101
+ | `running` | Child launch command was delivered |
102
+ | `ready_for_review` | Child exited successfully; workspace retained |
103
+ | `needs_help` | Child called `caller_ping`; workspace retained |
104
+ | `failed` | Creation, launch, or execution failed; any created workspace is retained |
105
+
106
+ The manifest supports ownership and inspection; v1 does not provide automatic reconciliation after a full Pi/Herdr restart. Do not edit manifests by hand.
107
+
108
+ ## Completion handoff
109
+
110
+ The parent receives the normal child summary plus:
111
+
112
+ - worktree path
113
+ - Herdr workspace ID
114
+ - branch
115
+ - requested base ref and resolved base SHA
116
+ - head SHA
117
+ - number of commits in `base..HEAD`
118
+ - changed files across committed, staged, unstaged, and untracked work
119
+ - untracked files separately
120
+ - working-tree state: clean, dirty, or conflicted
121
+
122
+ `clean` means there are no staged, unstaged, or untracked files. It does **not** mean the branch has no commits or diff relative to its base.
123
+
124
+ If Git inspection fails, SHA/count/state/file fields are reported as unknown rather than guessed, and the warning is included in the handoff. Inspect the retained workspace directly before integrating or deleting it.
125
+
126
+ ## Review and integration
127
+
128
+ Treat completion as a review handoff, not acceptance. Using the path, workspace ID, and base SHA from the result:
129
+
130
+ ```bash
131
+ herdr workspace focus <workspace-id>
132
+ git -C <worktree-path> status --short
133
+ git -C <worktree-path> log --oneline <base-sha>..HEAD
134
+ git -C <worktree-path> diff --stat <base-sha>...HEAD
135
+ git -C <worktree-path> diff <base-sha>...HEAD
136
+ ```
137
+
138
+ Then:
139
+
140
+ 1. Read the worker summary and test evidence.
141
+ 2. Inspect committed and uncommitted changes.
142
+ 3. Run relevant tests in the worktree.
143
+ 4. Resolve dirty or conflicted state in the worktree.
144
+ 5. Integrate deliberately—merge, cherry-pick, or publish a PR according to the repository's policy.
145
+ 6. Re-run integration checks on the destination branch.
146
+ 7. Remove the worktree only after its useful state is preserved.
147
+
148
+ The extension never pushes, creates a PR, merges, cherry-picks, or changes the parent checkout automatically.
149
+
150
+ ## Failure, help, and restart behavior
151
+
152
+ - **Creation failure:** the manifest is marked failed; no successful worktree handoff is expected.
153
+ - **Launch failure after creation:** the manifest is marked failed and the workspace/path are retained in the error.
154
+ - **Worker failure:** summary and available Git state are returned; the workspace remains open.
155
+ - **`caller_ping`:** the child exits with `needs_help`; continue worktree-bound follow-up in the retained workspace rather than through `subagent_resume`.
156
+ - **Parent `/reload`, `/new`, `/resume`, or `/fork`:** active in-memory watchers transfer to the replacement parent session.
157
+ - **Full process restart or crash:** the worktree remains, but v1 does not automatically rediscover and resume its watcher.
158
+
159
+ `subagent_resume` resumes a session in a new ordinary Herdr pane. It does not reattach the managed worktree lifecycle or produce a new worktree handoff. For worktree follow-up, focus the retained workspace and resume manually from its shell:
160
+
161
+ ```bash
162
+ herdr workspace focus <workspace-id>
163
+ pi --session <child-session-path>
164
+ ```
165
+
166
+ This manual continuation is not watched by the original parent lifecycle. Do not create another managed worktree for a branch that is already checked out.
167
+
168
+ ## Cleanup
169
+
170
+ Cleanup is always explicit. First make sure commits, patches, or uncommitted files are no longer needed. Then remove the Herdr worktree workspace:
171
+
172
+ ```bash
173
+ herdr worktree remove --workspace <workspace-id>
174
+ ```
175
+
176
+ Herdr removes the workspace and linked checkout. Without `--force`, dirty worktrees are protected. Do not use `--force` unless discarding all remaining work is intentional and verified.
177
+
178
+ The branch is a separate Git ref; inspect and delete it separately only when repository policy allows:
179
+
180
+ ```bash
181
+ git branch -d <branch>
182
+ ```
183
+
184
+ Use `git branch -D` only when you have independently verified that discarding unmerged commits is safe.
185
+
186
+ ## Current limits
187
+
188
+ This first version intentionally does not provide:
189
+
190
+ - automatic push, PR creation, merge, or cherry-pick
191
+ - automatic worktree or branch removal
192
+ - worktree-aware `subagent_resume`
193
+ - durable restart reconciliation
194
+ - dependency DAG scheduling or merge queues
195
+ - stacked-branch management
196
+ - multi-repository workspaces
@@ -0,0 +1,18 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ const roles = fileURLToPath(new URL("./roles", import.meta.url));
5
+
6
+ export default function rolePack(pi: ExtensionAPI) {
7
+ const unsubscribe = pi.events.on(
8
+ "pi-herdr-subagents:roles:discover:v1",
9
+ (request) => {
10
+ const discovery = request as {
11
+ apiVersion: number;
12
+ register(path: string): void;
13
+ };
14
+ if (discovery.apiVersion === 1) discovery.register(roles);
15
+ },
16
+ );
17
+ pi.on("session_shutdown", unsubscribe);
18
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@example/pi-herdr-roles",
3
+ "version": "1.0.0",
4
+ "keywords": [
5
+ "pi-package"
6
+ ],
7
+ "type": "module",
8
+ "pi": {
9
+ "extensions": [
10
+ "./extension.ts"
11
+ ]
12
+ },
13
+ "peerDependencies": {
14
+ "@earendil-works/pi-coding-agent": "*"
15
+ }
16
+ }
@@ -0,0 +1,12 @@
1
+ ---
2
+ description: Reviews a bounded change and reports concrete, evidence-backed findings
3
+ tools: read, bash
4
+ spawning: false
5
+ auto-exit: true
6
+ system-prompt: append
7
+ ---
8
+
9
+ # Example Reviewer
10
+
11
+ Review only the requested change. Report concrete findings with file and line
12
+ references. Do not modify files.
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "pi-herdr-agents",
3
+ "version": "0.0.1",
4
+ "description": "Asynchronous Pi subagents and approved review workflows in Herdr, with optional isolated Git worktrees",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "herdr",
9
+ "subagents",
10
+ "agents",
11
+ "worktrees",
12
+ "orchestration"
13
+ ],
14
+ "license": "MIT",
15
+ "author": {
16
+ "name": "Giuseppe Rodriguez",
17
+ "url": "https://github.com/giuseppecrj"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/giuseppecrj/pi-herdr-agents.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/giuseppecrj/pi-herdr-agents/issues"
25
+ },
26
+ "homepage": "https://github.com/giuseppecrj/pi-herdr-agents#readme",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "type": "module",
31
+ "scripts": {
32
+ "lint": "oxlint pi-extension test",
33
+ "test": "node --experimental-strip-types --test test/test.ts test/runtime-routing.test.ts test/release-workflow.test.ts test/workflow.test.ts test/package-skill.test.js",
34
+ "test:integration": "node --experimental-strip-types --test --test-concurrency=1 test/integration/*.test.ts",
35
+ "test:integration:live": "PI_TEST_LIVE=1 node --experimental-strip-types --test --test-concurrency=1 test/integration/*.test.ts"
36
+ },
37
+ "peerDependencies": {
38
+ "@earendil-works/pi-ai": "*",
39
+ "@earendil-works/pi-coding-agent": "*",
40
+ "@earendil-works/pi-tui": "*",
41
+ "@sinclair/typebox": "*"
42
+ },
43
+ "pi": {
44
+ "extensions": [
45
+ "./pi-extension/subagents/index.ts"
46
+ ],
47
+ "skills": [
48
+ "./skills"
49
+ ]
50
+ },
51
+ "devDependencies": {
52
+ "@earendil-works/pi-ai": "^0.83.0",
53
+ "@earendil-works/pi-coding-agent": "^0.83.0",
54
+ "@earendil-works/pi-tui": "^0.83.0",
55
+ "@sinclair/typebox": "^0.34.52",
56
+ "oxlint": "^1.73.0"
57
+ }
58
+ }