pi-cowboy 0.8.5 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -18
- package/dist/agents/agent-manager.js +32 -150
- package/dist/types.js +1 -1
- package/dist/ui/menu/menu-agent-status.js +8 -82
- package/package.json +3 -2
- package/orchestrators/with-code-review.toml +0 -20
package/README.md
CHANGED
|
@@ -10,10 +10,10 @@ pi-cowboy is an agent orchestrator for [pi](https://pi.dev). It is designed for
|
|
|
10
10
|
|
|
11
11
|
- **Improved code understanding:** Give each agent a smaller, isolated subtask. A single focused task with clear guidance leaves little room for error; a long list of tasks and expectations creates more room for drift and over-engineering. Smaller tasks therefore improve code quality and yield results that are easier to review: each agent commits to its own branch, so a subtask is reviewed and merged on its own, separately from the others.
|
|
12
12
|
|
|
13
|
-
- **Foreign harness support:** pi-cowboy can orchestrate Claude Code, Codex, OpenCode, and more: start work on Pi, continue on Claude Code, finish on OpenCode.
|
|
13
|
+
- **Foreign harness support:** pi-cowboy can orchestrate Claude Code, Codex, OpenCode, and more: start work on Pi, continue on Claude Code, finish on OpenCode. Do you need support for something else? Create an issue on [Github](https://github.com/electric-dragon-80000v/pi-cowboy/issues/new).
|
|
14
14
|
|
|
15
15
|
- **Parallel work with minimal disk overhead:** Multiple agents can edit, build, and run tests concurrently without interfering with each other. Copy-on-write unlocks more parallelism by reducing the disk overhead of the worktrees.
|
|
16
|
-
The numbers below are from a Git repository containing 153,607 files in total. The tracked files occupy 479
|
|
16
|
+
The numbers below are from a Git repository containing 153,607 files in total. The tracked files occupy 479 MiB, while the repository is 27 GiB in total, including untracked files.
|
|
17
17
|
|
|
18
18
|
| Method | Including untracked | Size on disk |
|
|
19
19
|
| ------------------------------ | ------------------- | ------------ |
|
|
@@ -73,9 +73,9 @@ Depending on your concurrency settings, some of the tasks queue. The default glo
|
|
|
73
73
|
|
|
74
74
|
Each agent runs as a separate pi process in its own Herdr workspace. Open a workspace at any time to monitor the agent or to steer it.
|
|
75
75
|
|
|
76
|
-
Three Herdr terms recur below: a **workspace** is the outermost Herdr container and holds tabs, a **tab** holds panes, and a **pane** is one terminal session
|
|
76
|
+
Three Herdr terms recur below: a **workspace** is the outermost Herdr container and holds tabs, a **tab** holds panes, and a **pane** is one terminal session, the one the agent's pi process runs in. pi-cowboy gives each agent its own workspace and tab, and puts the agent in that tab's root pane. pi-cowboy needs a git repository because each agent works in a worktree of it; outside a repository the extension stays inactive for that session. The pane id is the durable handle `cleanup_cowboy_agent` uses to find that pane again.
|
|
77
77
|
|
|
78
|
-
The agents work in separate git worktrees placed under
|
|
78
|
+
The agents work in separate git worktrees placed under `<agent dir>/pi-cowboy/worktrees/` (`~/.pi/agent` by default).
|
|
79
79
|
|
|
80
80
|
##### Agent completion
|
|
81
81
|
|
|
@@ -137,7 +137,7 @@ If pi-cowboy cannot remove one of them, it reports the failure and completes the
|
|
|
137
137
|
|
|
138
138
|
<code>/cowboy enable # Enables pi-cowboy</code><br>
|
|
139
139
|
|
|
140
|
-
<code>/cowboy disable
|
|
140
|
+
<code>/cowboy disable # Disables pi-cowboy</code>
|
|
141
141
|
|
|
142
142
|
## Tools
|
|
143
143
|
|
|
@@ -163,7 +163,7 @@ Delegates one or more tasks to cowboy agents. Each cowboy agent runs in its own
|
|
|
163
163
|
### `steer_cowboy_agent`
|
|
164
164
|
|
|
165
165
|
Sends a message to one or more agents. `steer_cowboy_agent` revives a settled agent for another turn: the same agent in its pane picks the message up, and you get another completion message when it settles again.
|
|
166
|
-
A queued agent cannot be steered
|
|
166
|
+
A queued agent cannot be steered, because it has no pane yet. Neither can an agent whose pane is gone (cleaned up), whose id is unknown, or that is being cleaned up.
|
|
167
167
|
|
|
168
168
|
| Parameter | Required | Description |
|
|
169
169
|
| ------------- | -------- | ------------------------------------- |
|
|
@@ -201,16 +201,16 @@ A removal that fails does not throw. The branch is removed only after you have m
|
|
|
201
201
|
|
|
202
202
|
## Model resolution
|
|
203
203
|
|
|
204
|
-
A model set in the `cowboy_agent` call wins over everything; below it come the session per-type override, the config per-type override, the agent template, the session default, the launching harness's default, and finally
|
|
204
|
+
A model set in the `cowboy_agent` call wins over everything; below it come the session per-type override, the config per-type override, the agent template, the session default, the launching harness's default, and finally, under the pi family, the model of the parent session. The authoritative order is in [Configuration](docs/Configuration.md#model-keys).
|
|
205
205
|
|
|
206
206
|
## Concurrency
|
|
207
207
|
|
|
208
208
|
A running agent holds a place in every concurrency limit that applies to it. pi-cowboy releases those places when the agent settles, then the next queued agent starts. You can define concurrency limits as follows:
|
|
209
209
|
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
210
|
+
- Per model: `concurrency.models["<provider>/<model-id>"]`
|
|
211
|
+
- Per provider: `concurrency.providers.<provider>`
|
|
212
|
+
- Per harness: `concurrency.harnesses.<harness-id>`
|
|
213
|
+
- Global: `concurrency.default` (default `4`), which every agent counts against
|
|
214
214
|
|
|
215
215
|
The levels are independent: an agent whose model, provider, and harness all have limits counts against all of them and against the global limit, so you have to free room at every level that applies.
|
|
216
216
|
pi-cowboy starts the first waiting agent whose every level has room: an agent that waits for one limit to clear does not hold back an agent behind it.
|
|
@@ -264,6 +264,10 @@ You can switch orchestrators during a session at `/cowboy` > `Default orchestrat
|
|
|
264
264
|
|
|
265
265
|
Orchestrator templates also allow you to customize how the agent communicates with the orchestrator. See [Orchestrator Templates](docs/Orchestrator%20Templates.md) for more details.
|
|
266
266
|
|
|
267
|
+
### Foreign harnesses
|
|
268
|
+
|
|
269
|
+
pi-cowboy can also orchestrate Codex, Claude Code, and OpenCode. It auto-detects them, so you can reference them directly (e.g., "Launch an OpenCode agent for this task") or configure them as defaults in your [settings](docs/Configuration.md#agentharnesstype) and [agent templates](docs/Agent%20Templates.md).
|
|
270
|
+
|
|
267
271
|
## FAQ
|
|
268
272
|
|
|
269
273
|
### Why is my agent queued, not running?
|
|
@@ -280,15 +284,9 @@ It can be. For a single small task the overhead can cost more time than the task
|
|
|
280
284
|
|
|
281
285
|
To avoid the overhead, pi-cowboy has support for [pig](https://github.com/MichaelKinsy/PiG), a drop-in replacement for pi written in Go, and for [pi-bolt](https://github.com/opensec-git/Pi-Bolt), faster, lighter Pi variant compiled ahead of time. They start up fast and have a lower memory footprint. See `agent.harnessType` in [Configuration](docs/Configuration.md).
|
|
282
286
|
|
|
283
|
-
pi-cowboy can also launch [opencode](https://opencode.ai), where its binary is on `PATH`. Set `harness_type = "opencode"` in a template, or pass `harness_type` on a `cowboy_agent` call, and the agent runs opencode instead of pi.
|
|
284
|
-
|
|
285
|
-
pi-cowboy can also launch [codex](https://developers.openai.com/codex), where its binary is on `PATH`. Set `harness_type = "codex"` in a template, or pass `harness_type` on a `cowboy_agent` call, and the agent runs codex instead of pi.
|
|
286
|
-
|
|
287
|
-
pi-cowboy can also launch [Claude Code](https://code.claude.com/docs), where its `claude` binary is on `PATH`. Set `harness_type = "claude"` in a template, or pass `harness_type` on a `cowboy_agent` call, and the agent runs the interactive Claude Code TUI instead of pi. Its model catalogue is claude's own (`anthropic/sonnet`, `anthropic/opus`, `anthropic/haiku`), and its tool lists are written in claude's own tool names under `[harness.claude]`.
|
|
288
|
-
|
|
289
287
|
### I don't like the emojis, can I turn them off?
|
|
290
288
|
|
|
291
|
-
|
|
289
|
+
Yes. You can disable both the cowboy and the grazing in settings. See [Configuration](docs/Configuration.md).
|
|
292
290
|
|
|
293
291
|
## References
|
|
294
292
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* agent-manager.ts — Fleet controller for independently running subagents.
|
|
3
|
-
* Exports AgentManager
|
|
4
|
-
* types.
|
|
3
|
+
* Exports AgentManager; re-exports spawn and steer types.
|
|
5
4
|
*/
|
|
6
5
|
import { getAgentSpawns, getCoordinatorOrNull, getPiInstance, getSessionCtx, } from "../shell.js";
|
|
7
6
|
import { subagentResultFileFor } from "../paths.js";
|
|
@@ -9,11 +8,10 @@ import { createHerdrRuntime } from "../infrastructure/herdr-host.js";
|
|
|
9
8
|
import { HerdrTaskRegistry } from "../task-registry.js";
|
|
10
9
|
import { createLogger } from "../logger.js";
|
|
11
10
|
import { errorMessage } from "../utils.js";
|
|
12
|
-
import { ACTIVE_AGENT_PHASES, ALL_AGENT_PHASES, hasOutcome, lifecycleStartTime,
|
|
11
|
+
import { ACTIVE_AGENT_PHASES, ALL_AGENT_PHASES, hasOutcome, lifecycleStartTime, } from "../types.js";
|
|
13
12
|
import { FileDeliverable } from "../subagent/deliverable.js";
|
|
14
13
|
import { removeResultArtifacts } from "../subagent/result-artifacts.js";
|
|
15
14
|
import { createCleanup } from "./agent-cleanup.js";
|
|
16
|
-
import { harnessFor } from "./harness/registry.js";
|
|
17
15
|
import { createHerdrAgentAssets, } from "./agent-assets.js";
|
|
18
16
|
import { DISPOSE_QUEUED_MESSAGE, SubagentSession, } from "./subagent-session.js";
|
|
19
17
|
import { resolveHarnessType } from "./spawn-defaults.js";
|
|
@@ -22,41 +20,27 @@ export const defaultAgentManagerTransport = {
|
|
|
22
20
|
createHost: (pi) => createHerdrRuntime(pi).host,
|
|
23
21
|
createDeliverable: (resultFile) => new FileDeliverable(resultFile),
|
|
24
22
|
};
|
|
23
|
+
const log = createLogger("manager");
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* The keep reason a cleanup report carries for a spawn that stays listed. A
|
|
26
|
+
* refusal for a live or contested run names no worktree state, so only a
|
|
27
|
+
* dirty or unverifiable reason is recordable; an unconfirmed removal is
|
|
28
|
+
* recorded as unverifiable with the removal's detail.
|
|
29
29
|
*/
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
kind: "owned",
|
|
46
|
-
target: host === undefined
|
|
47
|
-
? { kind: "detached", worktree: target, pane: null }
|
|
48
|
-
: {
|
|
49
|
-
kind: "adopted",
|
|
50
|
-
worktree: { ...target, workspaceId: host.workspaceId },
|
|
51
|
-
pane: null,
|
|
52
|
-
ref: host,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
const log = createLogger("manager");
|
|
57
|
-
function isTerminal(spawn) {
|
|
58
|
-
const status = lifecycleStatus(spawn.lifecycle);
|
|
59
|
-
return status !== "spawned" && status !== "queued";
|
|
30
|
+
function retentionForReport(report) {
|
|
31
|
+
if (report.outcome.kind === "refused") {
|
|
32
|
+
const reason = report.outcome.reason;
|
|
33
|
+
return reason.kind === "dirty" || reason.kind === "unverifiable"
|
|
34
|
+
? reason
|
|
35
|
+
: undefined;
|
|
36
|
+
}
|
|
37
|
+
if (report.worktree.kind === "removal-failed") {
|
|
38
|
+
return {
|
|
39
|
+
kind: "unverifiable",
|
|
40
|
+
detail: `the removal was not confirmed (${report.worktree.detail})`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
60
44
|
}
|
|
61
45
|
/** Fleet controller; each session owns exactly one lifecycle. */
|
|
62
46
|
export class AgentManager {
|
|
@@ -67,8 +51,8 @@ export class AgentManager {
|
|
|
67
51
|
onFollowUp;
|
|
68
52
|
/**
|
|
69
53
|
* Teardowns in flight, by agent id. One teardown owns an id's artifacts at a
|
|
70
|
-
* time: a
|
|
71
|
-
*
|
|
54
|
+
* time: a cleanup that arrives while one runs waits for it instead of racing
|
|
55
|
+
* it for the same checkout.
|
|
72
56
|
*/
|
|
73
57
|
teardowns = new Map();
|
|
74
58
|
/** The resource limiter the fleet drives directly; sessions charge their capacity to it. */
|
|
@@ -220,89 +204,6 @@ export class AgentManager {
|
|
|
220
204
|
.list(phases)
|
|
221
205
|
.sort((a, b) => lifecycleStartTime(b.lifecycle) - lifecycleStartTime(a.lifecycle));
|
|
222
206
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Clear a terminal spawn: tear its owned checkout down first and drop the
|
|
225
|
-
* spawn only once the removal is confirmed. A kept or failed removal leaves
|
|
226
|
-
* the spawn listed, with the reason recorded, so the caller can report it and
|
|
227
|
-
* the operator can retry it. Spawn-keyed so a spawn whose session is gone
|
|
228
|
-
* stays clearable.
|
|
229
|
-
*/
|
|
230
|
-
async clear(id) {
|
|
231
|
-
const spawn = getAgentSpawns().get(id);
|
|
232
|
-
if (!spawn)
|
|
233
|
-
return { kind: "refused", reason: "unknown-id" };
|
|
234
|
-
if (!isTerminal(spawn))
|
|
235
|
-
return { kind: "refused", reason: "not-terminal" };
|
|
236
|
-
// The first teardown's verdict is the answer for every clear that arrives
|
|
237
|
-
// while it runs; a second removal of the same checkout would race the first.
|
|
238
|
-
if (this.teardowns.has(id))
|
|
239
|
-
return { kind: "refused", reason: "in-flight" };
|
|
240
|
-
// Claimed in the same turn as the check: the invoked removal runs only
|
|
241
|
-
// its synchronous prefix and returns a pending promise, so a clear
|
|
242
|
-
// arriving while one runs still reads the claim instead of duplicating it.
|
|
243
|
-
const removal = this.runClearRemoval(spawn);
|
|
244
|
-
this.teardowns.set(id, removal);
|
|
245
|
-
try {
|
|
246
|
-
return await removal;
|
|
247
|
-
}
|
|
248
|
-
finally {
|
|
249
|
-
// A cleanup may have queued behind this removal and taken the id over.
|
|
250
|
-
if (this.teardowns.get(id) === removal)
|
|
251
|
-
this.teardowns.delete(id);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* One clear's work, in order: the harness's state leaves the checkout
|
|
256
|
-
* before the removal path probes or removes anything (see cleanupAgent's
|
|
257
|
-
* teardown), then the owned checkout goes.
|
|
258
|
-
*/
|
|
259
|
-
async runClearRemoval(spawn) {
|
|
260
|
-
if (spawn.execution.harness !== undefined) {
|
|
261
|
-
await this.teardownHarnessState(spawn);
|
|
262
|
-
}
|
|
263
|
-
const address = removalAddressFor(spawn);
|
|
264
|
-
if (address.kind === "none") {
|
|
265
|
-
this.dropSpawn(spawn);
|
|
266
|
-
return { kind: "cleared" };
|
|
267
|
-
}
|
|
268
|
-
if (address.kind === "unaddressable") {
|
|
269
|
-
const reason = {
|
|
270
|
-
kind: "unverifiable",
|
|
271
|
-
detail: "the run recorded no repository cwd",
|
|
272
|
-
};
|
|
273
|
-
this.recordRetention(spawn, reason);
|
|
274
|
-
return { kind: "kept", path: address.path, reason };
|
|
275
|
-
}
|
|
276
|
-
return this.runRemoval(spawn, address.target);
|
|
277
|
-
}
|
|
278
|
-
/** Tear one owned checkout down and settle the spawn on what it did. */
|
|
279
|
-
async runRemoval(spawn, target) {
|
|
280
|
-
const outcome = await createCleanup(this.assets()).removeWorktree(target);
|
|
281
|
-
switch (outcome.kind) {
|
|
282
|
-
case "removed":
|
|
283
|
-
case "absent":
|
|
284
|
-
this.dropSpawn(spawn);
|
|
285
|
-
return { kind: "cleared" };
|
|
286
|
-
case "kept":
|
|
287
|
-
this.recordRetention(spawn, outcome.reason);
|
|
288
|
-
return { kind: "kept", path: outcome.path, reason: outcome.reason };
|
|
289
|
-
case "removal-failed":
|
|
290
|
-
this.recordRetention(spawn, {
|
|
291
|
-
kind: "unverifiable",
|
|
292
|
-
detail: `the removal was not confirmed (${outcome.detail})`,
|
|
293
|
-
});
|
|
294
|
-
log.warn("worktree removal failed after clear", {
|
|
295
|
-
spawnId: spawn.id,
|
|
296
|
-
path: outcome.path,
|
|
297
|
-
detail: outcome.detail,
|
|
298
|
-
});
|
|
299
|
-
return {
|
|
300
|
-
kind: "removal-failed",
|
|
301
|
-
path: outcome.path,
|
|
302
|
-
detail: outcome.detail,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
207
|
async abort(id, initiator) {
|
|
307
208
|
return (await this.sessions.get(id)?.abort(initiator)) ?? false;
|
|
308
209
|
}
|
|
@@ -338,38 +239,11 @@ export class AgentManager {
|
|
|
338
239
|
*/
|
|
339
240
|
recordRetention(spawn, reason) {
|
|
340
241
|
const lifecycle = spawn.lifecycle;
|
|
341
|
-
//
|
|
242
|
+
// The reason lives on the ended phases; an active spawn records none.
|
|
342
243
|
if (hasOutcome(lifecycle)) {
|
|
343
244
|
lifecycle.worktreeRetentionReason = reason;
|
|
344
245
|
}
|
|
345
246
|
}
|
|
346
|
-
/**
|
|
347
|
-
* Tear down the harness recorded at launch — never a re-resolution: the
|
|
348
|
-
* harness that prepared the pane is the one that undoes its state.
|
|
349
|
-
* Best-effort and ordered before the dirty probe — see Harness.teardown.
|
|
350
|
-
*/
|
|
351
|
-
async teardownHarnessState(spawn) {
|
|
352
|
-
const harnessId = spawn.execution.harness;
|
|
353
|
-
if (harnessId === undefined)
|
|
354
|
-
return;
|
|
355
|
-
try {
|
|
356
|
-
await harnessFor(harnessId).teardown({
|
|
357
|
-
pi: getPiInstance(),
|
|
358
|
-
paneId: spawn.execution.host?.paneId ?? null,
|
|
359
|
-
cwd: spawn.display.worktree?.kind === "owned"
|
|
360
|
-
? spawn.display.worktree.path
|
|
361
|
-
: null,
|
|
362
|
-
subagentId: spawn.id,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
catch (error) {
|
|
366
|
-
log.warn("harness teardown failed before worktree removal", {
|
|
367
|
-
spawnId: spawn.id,
|
|
368
|
-
harness: harnessId,
|
|
369
|
-
error: errorMessage(error),
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
247
|
/**
|
|
374
248
|
* Drop runtime session and store entry for good, and with them the run's
|
|
375
249
|
* staging directory. The removal is keyed on the id, not the session: a
|
|
@@ -408,6 +282,14 @@ export class AgentManager {
|
|
|
408
282
|
getSpawn: (rid) => this.getSpawn(rid),
|
|
409
283
|
dropSpawn: (spawn) => this.dropSpawn(spawn),
|
|
410
284
|
}, opts);
|
|
285
|
+
// A spawn the teardown kept stays listed with the reason its checkout
|
|
286
|
+
// survived; a dropped spawn has no record left to annotate.
|
|
287
|
+
const kept = this.getSpawn(id);
|
|
288
|
+
if (kept !== undefined) {
|
|
289
|
+
const retention = retentionForReport(report);
|
|
290
|
+
if (retention !== undefined)
|
|
291
|
+
this.recordRetention(kept, retention);
|
|
292
|
+
}
|
|
411
293
|
// A teardown that finished the run takes the staging directory with it even
|
|
412
294
|
// when its spawn is kept (a failed or unconfirmed removal): the artifacts
|
|
413
295
|
// are ephemeral, and a later retry does not read them. A refusal removed
|
package/dist/types.js
CHANGED
|
@@ -21,7 +21,7 @@ const PHASE_IS_OVER = {
|
|
|
21
21
|
function phasesWhere(over) {
|
|
22
22
|
return Object.keys(PHASE_IS_OVER).filter((phase) => PHASE_IS_OVER[phase] === over);
|
|
23
23
|
}
|
|
24
|
-
/** Spawns still in flight: the runs stop
|
|
24
|
+
/** Spawns still in flight: the runs stop and steer act on. */
|
|
25
25
|
export const ACTIVE_AGENT_PHASES = phasesWhere(false);
|
|
26
26
|
/** Ended spawns — settled, or ended before they ever launched — retained until an explicit drop. */
|
|
27
27
|
export const TERMINAL_AGENT_PHASES = phasesWhere(true);
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
import { matchesKey, SelectList, truncateToWidth, visibleWidth, } from "@earendil-works/pi-tui";
|
|
8
8
|
import { ALL_AGENT_PHASES, hasOutcome, isActivePhase, lifecycleResult, lifecycleStartTime, lifecycleStatus, } from "../../types.js";
|
|
9
9
|
import { errorMessage } from "../../utils.js";
|
|
10
|
-
import { formatRetentionClause } from "../../infrastructure/git-client.js";
|
|
11
10
|
import { getDisplayName, agentBulletPrefix, formatMs, statusIcon, } from "../format.js";
|
|
12
11
|
import { getManagerOrNull, getRuntime } from "../../shell.js";
|
|
13
12
|
import { cleanupNeedsAttention, summarizeCleanupReport, } from "../../agents/cleanup-report.js";
|
|
@@ -195,57 +194,6 @@ function cleanupAgentsOffMenu(ctx, ids) {
|
|
|
195
194
|
}
|
|
196
195
|
})();
|
|
197
196
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Clear agents without holding the menu open, and report each one as its
|
|
200
|
-
* teardown lands. A clear that leaves its worktree behind keeps the spawn
|
|
201
|
-
* listed, so the report names it and why.
|
|
202
|
-
*/
|
|
203
|
-
function clearAgentsOffMenu(ctx, ids) {
|
|
204
|
-
const manager = getManagerOrNull();
|
|
205
|
-
const subject = agentSubject(ids);
|
|
206
|
-
const action = actionReport(ctx.ui);
|
|
207
|
-
if (!manager) {
|
|
208
|
-
action.failed(`Failed to clear ${subject}`, "manager unavailable");
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
void (async () => {
|
|
212
|
-
for (const id of ids) {
|
|
213
|
-
let outcome;
|
|
214
|
-
try {
|
|
215
|
-
outcome = await manager.clear(id);
|
|
216
|
-
}
|
|
217
|
-
catch (err) {
|
|
218
|
-
action.failed(`Failed to clear agent ${id}`, err);
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
switch (outcome.kind) {
|
|
222
|
-
case "cleared":
|
|
223
|
-
action.succeeded(`Cleaned up agent ${id}`);
|
|
224
|
-
break;
|
|
225
|
-
case "kept":
|
|
226
|
-
action.succeeded(`Kept agent ${id}'s worktree — ${formatRetentionClause(outcome.reason)} (${outcome.path})`, "warning");
|
|
227
|
-
break;
|
|
228
|
-
case "removal-failed":
|
|
229
|
-
action.failed(`Failed to clear agent ${id}`, `${outcome.detail} (${outcome.path})`);
|
|
230
|
-
break;
|
|
231
|
-
case "refused":
|
|
232
|
-
action.failed(`Failed to clear agent ${id}`, refusalText(outcome.reason));
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
})();
|
|
237
|
-
}
|
|
238
|
-
/** Why a clear refused, in the menu's words. */
|
|
239
|
-
function refusalText(reason) {
|
|
240
|
-
switch (reason) {
|
|
241
|
-
case "unknown-id":
|
|
242
|
-
return "no such agent";
|
|
243
|
-
case "not-terminal":
|
|
244
|
-
return "the agent is not settled";
|
|
245
|
-
case "in-flight":
|
|
246
|
-
return "another teardown is already running";
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
197
|
/**
|
|
250
198
|
* Per-agent actions submenu for a delegating component.
|
|
251
199
|
* @param done — return to the parent agent list.
|
|
@@ -282,13 +230,6 @@ export function buildAgentActionsList(ctx, spawn, theme, done, setActive, onClos
|
|
|
282
230
|
items.push({ value: "stop", label: "Stop" });
|
|
283
231
|
}
|
|
284
232
|
else {
|
|
285
|
-
items.push({
|
|
286
|
-
value: "clear",
|
|
287
|
-
label: "Clear",
|
|
288
|
-
description: spawn.display.worktree?.kind === "owned"
|
|
289
|
-
? "Clear agent and remove its worktree"
|
|
290
|
-
: undefined,
|
|
291
|
-
});
|
|
292
233
|
items.push({
|
|
293
234
|
value: "cleanup",
|
|
294
235
|
label: "Clean up",
|
|
@@ -316,11 +257,6 @@ export function buildAgentActionsList(ctx, spawn, theme, done, setActive, onClos
|
|
|
316
257
|
done();
|
|
317
258
|
stopAgentsOffMenu(ctx, [spawn.id]);
|
|
318
259
|
}
|
|
319
|
-
else if (item.value === "clear") {
|
|
320
|
-
actionReport(ctx.ui).pending(`Clearing agent ${id}`);
|
|
321
|
-
onClose();
|
|
322
|
-
clearAgentsOffMenu(ctx, [spawn.id]);
|
|
323
|
-
}
|
|
324
260
|
else if (item.value === "cleanup") {
|
|
325
261
|
// The spawn record goes with the artifacts, so the list it came from is
|
|
326
262
|
// stale either way: close, and report the teardown when it lands.
|
|
@@ -333,13 +269,13 @@ export function buildAgentActionsList(ctx, spawn, theme, done, setActive, onClos
|
|
|
333
269
|
return list;
|
|
334
270
|
}
|
|
335
271
|
export async function showAgentStatusMenu(ctx) {
|
|
336
|
-
// Settled spawns outlive their session, so list
|
|
272
|
+
// Settled spawns outlive their session, so list them here.
|
|
337
273
|
const agents = getManagerOrNull()?.listAgents(ALL_AGENT_PHASES) ?? [];
|
|
338
274
|
if (agents.length === 0) {
|
|
339
275
|
ctx.ui.notify("No agents have been spawned this session", "info");
|
|
340
276
|
return;
|
|
341
277
|
}
|
|
342
|
-
// Active work is never
|
|
278
|
+
// Active work is never cleaned up (ADR-0006).
|
|
343
279
|
const activeAgents = agents.filter((r) => isActivePhase(r.lifecycle.phase));
|
|
344
280
|
const finished = agents.filter((r) => !isActivePhase(r.lifecycle.phase));
|
|
345
281
|
const completed = agents.filter((r) => hasOutcome(r.lifecycle) && r.lifecycle.status === "completed");
|
|
@@ -378,22 +314,18 @@ export async function showAgentStatusMenu(ctx) {
|
|
|
378
314
|
});
|
|
379
315
|
}
|
|
380
316
|
if (finished.length > 0) {
|
|
381
|
-
// "Clear done" only when completed agents exist; clearing removes worktrees.
|
|
382
317
|
items.push({ value: SEPARATOR_ID, label: " " });
|
|
383
318
|
items.push({
|
|
384
319
|
value: "__cleanup-finished",
|
|
385
320
|
label: `Clean up ${finished.length} settled agent(s)`,
|
|
386
321
|
});
|
|
322
|
+
// The completed-only filter over the same path; only when one exists.
|
|
387
323
|
if (completed.length > 0) {
|
|
388
324
|
items.push({
|
|
389
|
-
value: "
|
|
390
|
-
label:
|
|
325
|
+
value: "__cleanup-completed",
|
|
326
|
+
label: `Clean up ${completed.length} completed agent(s)`,
|
|
391
327
|
});
|
|
392
328
|
}
|
|
393
|
-
items.push({
|
|
394
|
-
value: "__clear-all",
|
|
395
|
-
label: "Clear all (remove worktrees)",
|
|
396
|
-
});
|
|
397
329
|
}
|
|
398
330
|
return items;
|
|
399
331
|
};
|
|
@@ -414,16 +346,10 @@ export async function showAgentStatusMenu(ctx) {
|
|
|
414
346
|
cleanupAgentsOffMenu(ctx, finished.map((r) => r.id));
|
|
415
347
|
return;
|
|
416
348
|
}
|
|
417
|
-
if (item.value === "
|
|
418
|
-
actionReport(ctx.ui).pending(`
|
|
419
|
-
close();
|
|
420
|
-
clearAgentsOffMenu(ctx, finished.map((r) => r.id));
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
if (item.value === "__clear-done") {
|
|
424
|
-
actionReport(ctx.ui).pending(`Clearing ${completed.length} completed agent(s)`);
|
|
349
|
+
if (item.value === "__cleanup-completed") {
|
|
350
|
+
actionReport(ctx.ui).pending(`Cleaning up ${completed.length} completed agent(s)`);
|
|
425
351
|
close();
|
|
426
|
-
|
|
352
|
+
cleanupAgentsOffMenu(ctx, completed.map((r) => r.id));
|
|
427
353
|
return;
|
|
428
354
|
}
|
|
429
355
|
const spawn = agents.find((r) => r.id === item.value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cowboy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"packageManager": "pnpm@12.9.1",
|
|
6
6
|
"description": "Agent orchestrator for pi: can manage Codex, Claude Code, OpenCode, pi, pig and pi-bolt as subagents. Runs subagents in background Herdr panes, isolated in copy-on-write Git worktrees.",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"!dist/**/*.d.ts",
|
|
37
37
|
"agents/",
|
|
38
38
|
"orchestrators/",
|
|
39
|
+
"!orchestrators/with-code-review.toml",
|
|
39
40
|
"README.md",
|
|
40
41
|
"LICENSE"
|
|
41
42
|
],
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"test:integration": "pnpm run build && vitest run --project integration-no-cow --project integration-cow",
|
|
56
57
|
"test:integration-no-cow": "pnpm run build && vitest run --project integration-no-cow",
|
|
57
58
|
"test:integration-cow": "pnpm run build && vitest run --project integration-cow",
|
|
58
|
-
"dev:install": "pi remove . 2>/dev/null; pi install
|
|
59
|
+
"dev:install": "DEV_LINK=\"$HOME/.pi/agent/pi-cowboy-dev\"; ln -sfn \"$PWD/dev\" \"$DEV_LINK\" && { pi remove . 2>/dev/null; pi remove \"$DEV_LINK\" 2>/dev/null; pi install \"$DEV_LINK\"; }",
|
|
59
60
|
"lint": "oxlint",
|
|
60
61
|
"lint:fix": "oxlint --fix",
|
|
61
62
|
"commitlint": "commitlint",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
name = "with code review"
|
|
2
|
-
display_name = "with code review"
|
|
3
|
-
guidance = "If you make changes to the code: before committing them, launch the code review tool. Once the code is approved by the user, commit the changes to your branch. Never make any commits without user approval"
|
|
4
|
-
|
|
5
|
-
[cues]
|
|
6
|
-
spawned = '''
|
|
7
|
-
Success! You delegated to an agent. A notification will arrive when done - USER: do not poll, don't check status and don't duplicate the delegated work!{{#has_worktree}}
|
|
8
|
-
(Worktree: {{worktree_path}} (branch {{worktree_branch}}) — the agent's commits land on that branch, never on main. Merge it with the merge_cowboy_branch tool when done, then remove the worktree with cleanup_cowboy_agent.){{/has_worktree}}
|
|
9
|
-
|
|
10
|
-
Agent ID: {{agent_id}}'''
|
|
11
|
-
queued = '''
|
|
12
|
-
Agent QUEUED — the concurrency limit is reached ({{queue_running}} {{queue_running_label}} already spawned), so this task is waiting for a slot. It is NOT spawned yet: the process has not started. It will start automatically when another agent settles; you'll get a message when it starts and when it settles. Do NOT re-delegate — this task IS in flight.{{#has_worktree}}
|
|
13
|
-
(Worktree: {{worktree_path}} (branch {{worktree_branch}}) — the agent's commits land on that branch, never on main. Merge it with the merge_cowboy_branch tool when done, then remove the worktree with cleanup_cowboy_agent.){{/has_worktree}}
|
|
14
|
-
|
|
15
|
-
Agent ID: {{agent_id}}'''
|
|
16
|
-
settled = '''
|
|
17
|
-
{{result}}{{#error}}
|
|
18
|
-
|
|
19
|
-
Error: {{error}}{{/error}}{{#has_worktree}}
|
|
20
|
-
(Worktree: {{worktree_path}} (branch {{worktree_branch}}){{#retention}} — KEPT: {{retention}}{{/retention}}.{{#process_alive}} The agent process and its herdr pane stay until you call cleanup_cowboy_agent — its pane is closed, which ends that process.{{/process_alive}} {{#retention}}Clean the worktree up, then call cleanup_cowboy_agent to remove it.{{/retention}}{{^retention}}The worktree stays until you call cleanup_cowboy_agent to remove it — call it once the branch is merged or rejected.{{/retention}}){{/has_worktree}}{{status_note}}'''
|