pi-cowboy 0.0.0 → 0.3.2
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/LICENSE +21 -0
- package/README.md +281 -2
- package/agents/explore.toml +40 -0
- package/dist/agents/agent-assets.js +261 -0
- package/dist/agents/agent-cleanup.js +284 -0
- package/dist/agents/agent-discovery.js +108 -0
- package/dist/agents/agent-host.js +10 -0
- package/dist/agents/agent-manager.js +367 -0
- package/dist/agents/agent-reviver.js +64 -0
- package/dist/agents/agent-runner.js +288 -0
- package/dist/agents/agent-spawn-store.js +57 -0
- package/dist/agents/agent-template.js +46 -0
- package/dist/agents/agent-types.js +144 -0
- package/dist/agents/batch.js +92 -0
- package/dist/agents/cleanup-policy.js +194 -0
- package/dist/agents/cleanup-report.js +128 -0
- package/dist/agents/default-agents.js +19 -0
- package/dist/agents/harness/pi-bolt.js +15 -0
- package/dist/agents/harness/pi-compatible.js +68 -0
- package/dist/agents/harness/pig.js +16 -0
- package/dist/agents/harness/registry.js +27 -0
- package/dist/agents/harness.js +32 -0
- package/dist/agents/result-file-permissions.js +29 -0
- package/dist/agents/run-state.js +270 -0
- package/dist/agents/schemas/cleanup-batch.schema.js +19 -0
- package/dist/agents/schemas/cowboy-agents.schema.js +39 -0
- package/dist/agents/schemas/merge-batch.schema.js +25 -0
- package/dist/agents/schemas/steer-batch.schema.js +22 -0
- package/dist/agents/schemas/stop-batch.schema.js +18 -0
- package/dist/agents/spawn-defaults.js +70 -0
- package/dist/agents/subagent-session.js +601 -0
- package/dist/agents/tool-cleanup.js +57 -0
- package/dist/agents/tool-execution.js +125 -0
- package/dist/agents/tool-merge.js +190 -0
- package/dist/agents/tool-result.js +17 -0
- package/dist/agents/tool-steer.js +89 -0
- package/dist/agents/types.js +1 -0
- package/dist/availability.js +38 -0
- package/dist/config/config-io.js +261 -0
- package/dist/config/config-store.js +321 -0
- package/dist/config/config-validation.js +173 -0
- package/dist/config/layered-config.js +117 -0
- package/dist/config/types.js +23 -0
- package/dist/cow-support-launch.js +43 -0
- package/dist/events.js +146 -0
- package/dist/extension-toggle.js +28 -0
- package/dist/harness-availability-launch.js +23 -0
- package/dist/index.js +52 -0
- package/dist/infrastructure/exec-path.js +35 -0
- package/dist/infrastructure/git/cow-clone.js +398 -0
- package/dist/infrastructure/git/git-materializer.js +342 -0
- package/dist/infrastructure/git/git-merger.js +234 -0
- package/dist/infrastructure/git/git-retention.js +43 -0
- package/dist/infrastructure/git/git-runner.js +145 -0
- package/dist/infrastructure/git/git-worktree.js +143 -0
- package/dist/infrastructure/git/index.js +11 -0
- package/dist/infrastructure/git-client.js +11 -0
- package/dist/infrastructure/herdr/agent-stopper.js +60 -0
- package/dist/infrastructure/herdr/agents.js +329 -0
- package/dist/infrastructure/herdr/herdr-client.js +36 -0
- package/dist/infrastructure/herdr/herdr-transport.js +158 -0
- package/dist/infrastructure/herdr/index.js +15 -0
- package/dist/infrastructure/herdr/panes.js +174 -0
- package/dist/infrastructure/herdr/polling.js +44 -0
- package/dist/infrastructure/herdr/worktrees.js +76 -0
- package/dist/infrastructure/herdr-client.js +6 -0
- package/dist/infrastructure/herdr-host.js +163 -0
- package/dist/logger.js +79 -0
- package/dist/models/model-groups.js +72 -0
- package/dist/models/model-precedence.js +50 -0
- package/dist/models/model-request.js +108 -0
- package/dist/orchestrators/briefing-section.js +14 -0
- package/dist/orchestrators/context.js +116 -0
- package/dist/orchestrators/cues.js +90 -0
- package/dist/orchestrators/default-orchestrators.js +36 -0
- package/dist/orchestrators/orchestrator-discovery.js +68 -0
- package/dist/orchestrators/orchestrator-template.js +43 -0
- package/dist/orchestrators/orchestrator-types.js +78 -0
- package/dist/orchestrators/protocol.js +292 -0
- package/dist/orchestrators/types.js +7 -0
- package/dist/paths.js +66 -0
- package/dist/pi-settings.js +7 -0
- package/dist/predicates.js +25 -0
- package/dist/prompt/prompts.js +110 -0
- package/dist/prompt/skill-loader.js +153 -0
- package/dist/prompt/subagent-system-prompt.js +173 -0
- package/dist/registration.js +220 -0
- package/dist/shell.js +225 -0
- package/dist/spawn/cow-support.js +53 -0
- package/dist/spawn/herdr-launcher.js +80 -0
- package/dist/spawn/repo-lock.js +34 -0
- package/dist/spawn/sandbox.js +286 -0
- package/dist/spawn/spawn-coordinator.js +255 -0
- package/dist/spawn/spawn-id.js +39 -0
- package/dist/spawn/worktree-policy.js +137 -0
- package/dist/status-note.js +30 -0
- package/dist/subagent/ipc-protocol.js +68 -0
- package/dist/subagent/ipc.js +110 -0
- package/dist/subagent/pane-supervisor.js +24 -0
- package/dist/subagent/socket-ipc.js +240 -0
- package/dist/subagent/supervisor.js +315 -0
- package/dist/task-registry.js +258 -0
- package/dist/templates/template-files.js +84 -0
- package/dist/types.js +84 -0
- package/dist/ui/action-report.js +21 -0
- package/dist/ui/format.js +47 -0
- package/dist/ui/indicator.js +480 -0
- package/dist/ui/menu/helpers.js +227 -0
- package/dist/ui/menu/menu-agent-settings.js +182 -0
- package/dist/ui/menu/menu-agent-status.js +444 -0
- package/dist/ui/menu/menu-concurrency.js +226 -0
- package/dist/ui/menu/menu-model-settings.js +244 -0
- package/dist/ui/menu/menu-spawn-defaults.js +71 -0
- package/dist/ui/menu/menu-spawn-wizard.js +367 -0
- package/dist/ui/menu/menu-spawn-worktree.js +107 -0
- package/dist/ui/menu/menu-system-prompt.js +104 -0
- package/dist/ui/menu/menu-worktree-command.js +150 -0
- package/dist/ui/menu/menus.js +187 -0
- package/dist/ui/menu/model-picker.js +160 -0
- package/dist/ui/menu/screen-host.js +87 -0
- package/dist/ui/menu/submenus/confirm.js +23 -0
- package/dist/ui/menu/submenus/model-select.js +42 -0
- package/dist/ui/menu/submenus/name-field.js +43 -0
- package/dist/ui/menu/submenus/numeric-input.js +61 -0
- package/dist/ui/menu/submenus/target-select.js +129 -0
- package/dist/ui/menu/submenus/text-editor.js +49 -0
- package/dist/ui/menu/submenus/worktree-command-name.js +73 -0
- package/dist/ui/menu/submenus/worktree-name.js +53 -0
- package/dist/ui/menu/wrappers/settings-list.js +101 -0
- package/dist/ui/searchable-select.js +147 -0
- package/dist/ui/types.js +1 -0
- package/dist/utils.js +70 -0
- package/docs/assets/grazing.png +0 -0
- package/docs/assets/herdr-containers.png +0 -0
- package/docs/assets/logo-transparent.png +0 -0
- package/orchestrators/with-code-review.toml +20 -0
- package/package.json +109 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* herdr-launcher.ts — git-side worktree creation with rollback on every failure.
|
|
3
|
+
* Herdr adoption (`worktree open`) is out of scope — see AgentHost.hostAt.
|
|
4
|
+
*/
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
// Git HOW lives in git-client.ts; orchestration stays here.
|
|
7
|
+
import { GitError, deleteCreatedBranch, gitProbe, gitRun, materializeWorktree, removeGitWorktree, resolveMainCheckout, worktreeAddArgs, GIT_WORKTREE_TIMEOUT_MS, } from "../infrastructure/git-client.js";
|
|
8
|
+
import { DEFAULT_WORKTREE_CHECKOUT_TYPE, DEFAULT_WORKTREE_MATERIALIZATION, } from "./worktree-policy.js";
|
|
9
|
+
/** Whether `branch` was already in the repo before the add. `worktree add -b` refuses a branch that exists, so a branch absent here and present after a failed add is this call's to prune; one that existed belongs to the caller. A probe that cannot run answers true, so a transport failure never deletes. */
|
|
10
|
+
async function branchExisted(pi, repoCwd, branch) {
|
|
11
|
+
const probe = await gitRun(pi, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`], repoCwd, GIT_WORKTREE_TIMEOUT_MS);
|
|
12
|
+
if (probe === undefined)
|
|
13
|
+
return true;
|
|
14
|
+
return probe.code === 0;
|
|
15
|
+
}
|
|
16
|
+
export async function createWorktreeCheckout(pi, options) {
|
|
17
|
+
const branch = options.branch.trim();
|
|
18
|
+
if (branch === "") {
|
|
19
|
+
throw new GitError("worktree checkout requires a branch name");
|
|
20
|
+
}
|
|
21
|
+
// Herdr rejects a linked worktree as the adoption source: start from the main checkout.
|
|
22
|
+
const mainRoot = await resolveMainCheckout(pi, options.repoCwd);
|
|
23
|
+
const wtPath = path.resolve(options.path);
|
|
24
|
+
const materializationStrategy = options.materialization ?? DEFAULT_WORKTREE_MATERIALIZATION;
|
|
25
|
+
const dirtyCheckout = options.dirtyCheckout ?? DEFAULT_WORKTREE_CHECKOUT_TYPE;
|
|
26
|
+
// Copy-on-write adds with `--no-checkout`; materializeWorktree below populates the tree.
|
|
27
|
+
const existedBefore = await branchExisted(pi, mainRoot, branch);
|
|
28
|
+
const add = await gitRun(pi, [
|
|
29
|
+
"worktree",
|
|
30
|
+
"add",
|
|
31
|
+
...worktreeAddArgs(materializationStrategy),
|
|
32
|
+
"-b",
|
|
33
|
+
branch,
|
|
34
|
+
wtPath,
|
|
35
|
+
options.base ?? "HEAD",
|
|
36
|
+
], mainRoot, GIT_WORKTREE_TIMEOUT_MS);
|
|
37
|
+
if (add === undefined || add.code !== 0) {
|
|
38
|
+
await removeGitWorktree(pi, mainRoot, wtPath);
|
|
39
|
+
// git can create the ref before it fails. The two later failure paths
|
|
40
|
+
// prune it unconditionally; this one prunes only a branch it created, so a
|
|
41
|
+
// collision with a caller's branch leaves that branch alone.
|
|
42
|
+
if (!existedBefore) {
|
|
43
|
+
await deleteCreatedBranch(pi, branch, mainRoot);
|
|
44
|
+
}
|
|
45
|
+
throw new GitError(add === undefined
|
|
46
|
+
? `git worktree add for "${branch}" could not run (worktree removed)`
|
|
47
|
+
: `git worktree add for "${branch}" failed (worktree removed): ${(add.stderr || add.stdout || `exit ${add.code}`).slice(0, 300)}`);
|
|
48
|
+
}
|
|
49
|
+
// A worktree on any other branch is not ours to keep: a spawn there would commit onto another task's branch.
|
|
50
|
+
const actualBranch = await gitProbe(pi, ["branch", "--show-current"], wtPath);
|
|
51
|
+
if (actualBranch !== branch) {
|
|
52
|
+
await removeGitWorktree(pi, mainRoot, wtPath);
|
|
53
|
+
// The branch is this call's own — the add minted it under the requested name —
|
|
54
|
+
// and no host has seen the checkout, so no attachment can hold it.
|
|
55
|
+
await deleteCreatedBranch(pi, branch, mainRoot);
|
|
56
|
+
throw new GitError(actualBranch === undefined
|
|
57
|
+
? `worktree created at ${wtPath} but its branch could not be verified (worktree removed)`
|
|
58
|
+
: `worktree created at ${wtPath} is on branch "${actualBranch || "(detached)"}", not the requested "${branch}" (worktree removed). The branch "${actualBranch}" still exists.`);
|
|
59
|
+
}
|
|
60
|
+
// Materialize before the subagent pane starts, so it always sees the final checkout.
|
|
61
|
+
let outcome;
|
|
62
|
+
try {
|
|
63
|
+
outcome = await materializeWorktree(pi, wtPath, materializationStrategy, dirtyCheckout);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
await removeGitWorktree(pi, mainRoot, wtPath);
|
|
67
|
+
await deleteCreatedBranch(pi, branch, mainRoot);
|
|
68
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
69
|
+
throw new GitError(`worktree created but ${materializationStrategy} materialization failed (worktree removed): ${msg}`);
|
|
70
|
+
}
|
|
71
|
+
// A fallback still leaves a usable worktree, but not the one the setting asked
|
|
72
|
+
// for: the spawn has nothing to tell the user about it, so tell them here.
|
|
73
|
+
if (outcome.kind === "cow-fallback") {
|
|
74
|
+
const dropped = dirtyCheckout === "dirty"
|
|
75
|
+
? " The parent's uncommitted work was not carried over."
|
|
76
|
+
: "";
|
|
77
|
+
options.notify?.(`[cowboy] ${outcome.reason}${dropped} Nothing is shared with the parent checkout.`, "warning");
|
|
78
|
+
}
|
|
79
|
+
return { path: wtPath, branch, repoCwd: mainRoot, materialization: outcome };
|
|
80
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* repo-lock.ts — one worktree creation at a time per repository.
|
|
3
|
+
*
|
|
4
|
+
* `git worktree add` registers its worktree by creating `.git/worktrees/<id>/` and
|
|
5
|
+
* only then writing `commondir` into it, truncate-then-write. The file is empty for
|
|
6
|
+
* that instant, and git treats an empty one as fatal ("failed to read
|
|
7
|
+
* .git/worktrees/<id>/commondir: Undefined error: 0") in any process enumerating
|
|
8
|
+
* worktrees during it — including `git worktree add` itself, which lists the
|
|
9
|
+
* existing worktrees before creating its own. Concurrent creations in one
|
|
10
|
+
* repository therefore collide, so they queue here.
|
|
11
|
+
*
|
|
12
|
+
* Keys are per repository: repositories never wait on each other, and a caller
|
|
13
|
+
* holds at most one key at a time (a spawn only ever touches its own repo), so
|
|
14
|
+
* there is no lock ordering to deadlock on.
|
|
15
|
+
*/
|
|
16
|
+
/** Serializes `fn` per key: calls sharing a key run in arrival order, never concurrently. */
|
|
17
|
+
export class RepoLock {
|
|
18
|
+
/** Tail of each key's queue — the settlement of the last run admitted for it. */
|
|
19
|
+
tails = new Map();
|
|
20
|
+
async run(key, fn) {
|
|
21
|
+
const queued = (this.tails.get(key) ?? Promise.resolve()).then(fn);
|
|
22
|
+
// The queue holds settlement, not the value, so one failure cannot block the runs behind it.
|
|
23
|
+
const tail = queued.then(() => undefined, () => undefined);
|
|
24
|
+
this.tails.set(key, tail);
|
|
25
|
+
try {
|
|
26
|
+
return await queued;
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
// Only the last run clears the key; a queued run has already replaced the tail.
|
|
30
|
+
if (this.tails.get(key) === tail)
|
|
31
|
+
this.tails.delete(key);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sandbox.ts — all-or-nothing execution-environment transaction.
|
|
3
|
+
* createAdoptedWorktree: git worktree create, then host adoption; either returns an adopted checkout or throws unwound.
|
|
4
|
+
* allocate: that unit plus the spawn's own naming, repo fallback, and sandbox state around it.
|
|
5
|
+
* teardown: binds agent-cleanup.ts over cleanupDeps; retention rules live in cleanup-policy.ts / git-client.ts.
|
|
6
|
+
* Never shells out directly — see herdr-launcher.ts and git-client.ts.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { deleteCreatedBranch, deleteWorktreeBranch, formatRetentionClause, isWorktreeDirty, removeGitWorktree, resolveMainCheckout, } from "../infrastructure/git-client.js";
|
|
11
|
+
import { createWorktreeTeardown, } from "../agents/agent-cleanup.js";
|
|
12
|
+
import { errorMessage } from "../utils.js";
|
|
13
|
+
import { getRepoLock } from "../shell.js";
|
|
14
|
+
import { buildWorktreeBranch, resolveWorktreeRoot, } from "./worktree-policy.js";
|
|
15
|
+
import { createWorktreeCheckout, } from "./herdr-launcher.js";
|
|
16
|
+
/**
|
|
17
|
+
* The identity a repository's lock is keyed by: the directory's own, not the
|
|
18
|
+
* name it was reached by. One repository has several paths — a symlinked home,
|
|
19
|
+
* a bind mount — and `path.resolve` follows neither, so two spellings would
|
|
20
|
+
* each take a lock, which is the collision `RepoLock` exists to prevent.
|
|
21
|
+
*
|
|
22
|
+
* Device and inode name the directory itself, and unlike a path they survive
|
|
23
|
+
* both. A root that cannot be stat'ed has no identity yet; its resolved path
|
|
24
|
+
* keeps distinct unreachable roots distinct.
|
|
25
|
+
*/
|
|
26
|
+
function canonicalRepoKey(repoRoot) {
|
|
27
|
+
try {
|
|
28
|
+
const stats = fs.statSync(repoRoot, { bigint: true });
|
|
29
|
+
return `${stats.dev}:${stats.ino}`;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return path.resolve(repoRoot);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// --- Sandbox ---
|
|
36
|
+
/** One delegation's execution environment. `allocate` is total; `teardown` is the only destroy path. */
|
|
37
|
+
export class AgentSandbox {
|
|
38
|
+
/** Pinned `cow-<task>-<id>` branch; also names the agent. */
|
|
39
|
+
branch;
|
|
40
|
+
/** Whether the subagent session may load the target project's resources. */
|
|
41
|
+
projectTrusted;
|
|
42
|
+
host;
|
|
43
|
+
placement;
|
|
44
|
+
current = { kind: "bound" };
|
|
45
|
+
constructor(host, placement, branch, projectTrusted) {
|
|
46
|
+
this.host = host;
|
|
47
|
+
this.placement = placement;
|
|
48
|
+
this.branch = branch;
|
|
49
|
+
this.projectTrusted = projectTrusted;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Provision a sandbox: git create (phase 1), then host adoption (phase 2), both inside
|
|
53
|
+
* `createAdoptedWorktree`'s boundary, so the caller never sees a half-provisioned sandbox.
|
|
54
|
+
* Outside a git repository, falls back to the parent cwd with a warning.
|
|
55
|
+
*/
|
|
56
|
+
static async allocate(pi, request) {
|
|
57
|
+
const { naming, parentCwd, worktreeRoot, materialization, dirtyCheckout, notify, host, } = request;
|
|
58
|
+
const branch = naming.kind === "generated"
|
|
59
|
+
? buildWorktreeBranch(naming.taskSlug, naming.id)
|
|
60
|
+
: naming.branch.trim();
|
|
61
|
+
// A generated name is valid by construction; an explicit one must at least
|
|
62
|
+
// name something (git rejects an unusable branch name itself).
|
|
63
|
+
if (naming.kind === "explicit" && branch === "") {
|
|
64
|
+
throw new Error("explicit worktree naming requires a branch name");
|
|
65
|
+
}
|
|
66
|
+
// Outside a git repository no worktree is possible.
|
|
67
|
+
let repoRoot;
|
|
68
|
+
try {
|
|
69
|
+
repoRoot = await resolveMainCheckout(pi, parentCwd);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
notify?.(`[cowboy] Parent is not inside a git repository — spawning in the parent cwd without a worktree`, "warning");
|
|
73
|
+
return new AgentSandbox(host, { kind: "parent-cwd" }, branch, true);
|
|
74
|
+
}
|
|
75
|
+
const worktree = await createAdoptedWorktree(pi, {
|
|
76
|
+
repoCwd: repoRoot,
|
|
77
|
+
path: path.join(resolveWorktreeRoot(worktreeRoot, repoRoot), branch),
|
|
78
|
+
branch,
|
|
79
|
+
materialization,
|
|
80
|
+
dirtyCheckout,
|
|
81
|
+
notify,
|
|
82
|
+
host,
|
|
83
|
+
});
|
|
84
|
+
return new AgentSandbox(host, {
|
|
85
|
+
kind: "worktree",
|
|
86
|
+
checkout: {
|
|
87
|
+
path: worktree.path,
|
|
88
|
+
branch: worktree.branch,
|
|
89
|
+
repoCwd: worktree.repoCwd,
|
|
90
|
+
},
|
|
91
|
+
ref: worktree.ref,
|
|
92
|
+
}, branch, true);
|
|
93
|
+
}
|
|
94
|
+
/** Current lifecycle state of the environment. */
|
|
95
|
+
get state() {
|
|
96
|
+
return this.current;
|
|
97
|
+
}
|
|
98
|
+
/** Verified checkout path + branch, or undefined for the parent-cwd fallback. */
|
|
99
|
+
get worktree() {
|
|
100
|
+
return this.placement.kind === "worktree"
|
|
101
|
+
? {
|
|
102
|
+
path: this.placement.checkout.path,
|
|
103
|
+
branch: this.placement.checkout.branch,
|
|
104
|
+
}
|
|
105
|
+
: undefined;
|
|
106
|
+
}
|
|
107
|
+
/** The adopted host address, or undefined for the parent-cwd fallback. */
|
|
108
|
+
get hostRef() {
|
|
109
|
+
return this.placement.kind === "worktree" ? this.placement.ref : undefined;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Tear down in order — placement, worktree, then branch-prune-if-merged. Retention is
|
|
113
|
+
* not re-derived here; a second teardown of a destroyed sandbox reports `absent`.
|
|
114
|
+
*/
|
|
115
|
+
async teardown(pi, opts) {
|
|
116
|
+
const placement = this.placement;
|
|
117
|
+
if (placement.kind === "parent-cwd") {
|
|
118
|
+
this.current = { kind: "destroyed" };
|
|
119
|
+
return { kind: "absent" };
|
|
120
|
+
}
|
|
121
|
+
if (this.current.kind === "destroyed") {
|
|
122
|
+
return { kind: "absent", path: placement.checkout.path };
|
|
123
|
+
}
|
|
124
|
+
const outcome = await createWorktreeTeardown(cleanupDeps(pi, this.host)).removeWorktree({
|
|
125
|
+
kind: "adopted",
|
|
126
|
+
worktree: {
|
|
127
|
+
workspaceId: placement.ref.workspaceId,
|
|
128
|
+
worktreePath: placement.checkout.path,
|
|
129
|
+
repoCwd: placement.checkout.repoCwd,
|
|
130
|
+
branchName: placement.checkout.branch,
|
|
131
|
+
},
|
|
132
|
+
pane: {
|
|
133
|
+
paneId: placement.ref.paneId,
|
|
134
|
+
origin: placement.ref.paneCreated === true ? "self-created" : "adopted",
|
|
135
|
+
},
|
|
136
|
+
ref: placement.ref,
|
|
137
|
+
}, opts);
|
|
138
|
+
this.current = stateAfterTeardown(outcome);
|
|
139
|
+
return outcome;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** Map a teardown outcome onto the sandbox's next state. */
|
|
143
|
+
function stateAfterTeardown(outcome) {
|
|
144
|
+
switch (outcome.kind) {
|
|
145
|
+
case "kept":
|
|
146
|
+
return { kind: "preserved", reason: outcome.reason };
|
|
147
|
+
case "removed":
|
|
148
|
+
case "absent":
|
|
149
|
+
return { kind: "destroyed" };
|
|
150
|
+
case "removal-failed":
|
|
151
|
+
return { kind: "teardown-failed", detail: outcome.detail };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// --- Worktree creation and adoption ---
|
|
155
|
+
/**
|
|
156
|
+
* Create a git worktree and adopt it in the host — the half a spawn and the
|
|
157
|
+
* `/cowboy worktree` command share. The two phases unwind inside this boundary:
|
|
158
|
+
* a failed adoption removes the worktree and its branch, so no caller is left
|
|
159
|
+
* with a worktree the host does not know about. Creating and adopting is
|
|
160
|
+
* serialized per repository (concurrent `git worktree add`s race on
|
|
161
|
+
* `.git/worktrees/<id>/commondir`, and the loser dies — see RepoLock); nothing
|
|
162
|
+
* else is, so a spawn whose checkout is ready goes on to launch while the next
|
|
163
|
+
* checkout is being created.
|
|
164
|
+
*/
|
|
165
|
+
export async function createAdoptedWorktree(pi, request) {
|
|
166
|
+
const target = path.resolve(request.path);
|
|
167
|
+
// Both directories are created: a configured root that is missing is a
|
|
168
|
+
// first-run setup state, and a branch name may add a level of its own.
|
|
169
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
170
|
+
return getRepoLock().run(canonicalRepoKey(request.repoCwd), () => adoptWorktree(pi, request.host, { ...request, path: target }));
|
|
171
|
+
}
|
|
172
|
+
/** Phases 1 and 2: create the checkout, then adopt it. Both unwind inside this boundary. */
|
|
173
|
+
async function adoptWorktree(pi, host, request) {
|
|
174
|
+
const { repoCwd, path: target, branch, materialization, dirtyCheckout, notify, } = request;
|
|
175
|
+
// Phase 1: git worktree add on the branch plus materialization.
|
|
176
|
+
let created;
|
|
177
|
+
try {
|
|
178
|
+
created = await createWorktreeCheckout(pi, {
|
|
179
|
+
repoCwd,
|
|
180
|
+
path: target,
|
|
181
|
+
branch,
|
|
182
|
+
materialization,
|
|
183
|
+
dirtyCheckout,
|
|
184
|
+
notify,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
// The create's own failure paths prune the branch they minted; the checkout
|
|
189
|
+
// they may have left behind is this boundary's to remove.
|
|
190
|
+
throw createFailureMessage(err, await removeFailedCheckout(pi, repoCwd, target));
|
|
191
|
+
}
|
|
192
|
+
// Phase 2: adoption. The host never destroys filesystem state, so a failed adoption rolls back here.
|
|
193
|
+
let ref;
|
|
194
|
+
try {
|
|
195
|
+
ref = await host.hostAt({
|
|
196
|
+
unit: "pane",
|
|
197
|
+
cwd: created.path,
|
|
198
|
+
// Herdr's echoed label (the repo name) is identical across parallel spawns — name by branch instead.
|
|
199
|
+
label: branch,
|
|
200
|
+
name: branch,
|
|
201
|
+
checkout: {
|
|
202
|
+
path: created.path,
|
|
203
|
+
repoCwd,
|
|
204
|
+
branch: created.branch,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
const checkout = await removeFailedCheckout(pi, repoCwd, created.path);
|
|
210
|
+
// The branch is this create's own — the add minted it moments ago and nothing
|
|
211
|
+
// has committed on it — so it goes by name, without the guards that keep a
|
|
212
|
+
// caller's branch or an unmerged one.
|
|
213
|
+
const branch = await deleteCreatedBranch(pi, created.branch, repoCwd);
|
|
214
|
+
throw createFailureMessage(err, `${checkout}. ${formatLaunchedBranchOutcome(created.branch, branch)}`);
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
path: created.path,
|
|
218
|
+
branch: created.branch,
|
|
219
|
+
repoCwd,
|
|
220
|
+
materialization: created.materialization,
|
|
221
|
+
ref,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
// --- Allocation failure ---
|
|
225
|
+
/** Bind direct herdr and git functions to the teardown orchestrator; the host never destroys filesystem state. */
|
|
226
|
+
function cleanupDeps(pi, host) {
|
|
227
|
+
return {
|
|
228
|
+
isWorktreeDirty: (worktreePath) => isWorktreeDirty(pi, worktreePath),
|
|
229
|
+
worktreeExists: async (worktreePath) => fs.existsSync(worktreePath),
|
|
230
|
+
removeWorktree: (ref) => host.release(ref, "worktree-association"),
|
|
231
|
+
removeGitWorktree: async (worktreePath, repoCwd) => {
|
|
232
|
+
await removeGitWorktree(pi, repoCwd, worktreePath);
|
|
233
|
+
return !fs.existsSync(worktreePath);
|
|
234
|
+
},
|
|
235
|
+
deleteBranch: (options) => deleteWorktreeBranch(pi, options, (candidate) => host.isAttached(candidate, { repoCwd: options.repoCwd })),
|
|
236
|
+
closePane: async (ref) => {
|
|
237
|
+
await host.release(ref, "placement");
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Remove the checkout a failed create may have left behind, and report what
|
|
243
|
+
* became of it. Nothing in such a checkout is anyone's work: under `dirty` it holds
|
|
244
|
+
* a copy of the parent's, which the parent still has.
|
|
245
|
+
*/
|
|
246
|
+
async function removeFailedCheckout(pi, repoCwd, worktreePath) {
|
|
247
|
+
await removeGitWorktree(pi, repoCwd, worktreePath);
|
|
248
|
+
return fs.existsSync(worktreePath)
|
|
249
|
+
? `worktree ${worktreePath} NOT removed — inspect it manually`
|
|
250
|
+
: `worktree ${worktreePath} removed`;
|
|
251
|
+
}
|
|
252
|
+
/** The error a failed create is reported with, plus the cleanup that ran with it. */
|
|
253
|
+
function createFailureMessage(reason, cleanup) {
|
|
254
|
+
return new Error(`could not create the herdr worktree: ${errorMessage(reason)}\n\nLaunch-failure cleanup: ${cleanup}.`);
|
|
255
|
+
}
|
|
256
|
+
/** Branch verdict for the launch-failure cleanup note. */
|
|
257
|
+
function formatLaunchedBranchOutcome(branchName, branch) {
|
|
258
|
+
switch (branch.kind) {
|
|
259
|
+
case "deleted":
|
|
260
|
+
return `branch ${branchName} deleted`;
|
|
261
|
+
case "kept":
|
|
262
|
+
return `branch ${branchName} kept (${branch.reason})`;
|
|
263
|
+
case "delete-failed":
|
|
264
|
+
return `branch ${branchName} NOT deleted — ${branch.detail}`;
|
|
265
|
+
case "not-applicable":
|
|
266
|
+
return `branch ${branchName} already gone`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/** Render a teardown outcome as the trailing note of a launch error. A kept tree has no spawn, so only manual inspection can remove it. */
|
|
270
|
+
export function formatLaunchCleanupNote(outcome) {
|
|
271
|
+
switch (outcome.kind) {
|
|
272
|
+
case "removed":
|
|
273
|
+
return outcome.via === "herdr"
|
|
274
|
+
? `Launch-failure cleanup: worktree ${outcome.path} removed — its herdr workspace, tab, and pane were closed with it. ${formatLaunchedBranchOutcome(outcome.branchName, outcome.branch)}.`
|
|
275
|
+
: // The git-side verdict only. Whether a herdr pane survived belongs to
|
|
276
|
+
// the adoption error that precedes this note, which names it.
|
|
277
|
+
`Launch-failure cleanup: worktree ${outcome.path} removed. ${formatLaunchedBranchOutcome(outcome.branchName, outcome.branch)}.`;
|
|
278
|
+
case "kept":
|
|
279
|
+
return (`Launch-failure cleanup: worktree ${outcome.path} KEPT — ${formatRetentionClause(outcome.reason)}. ` +
|
|
280
|
+
`No agent spawn exists for it, so extension cleanup cannot see it — inspect and remove it manually.`);
|
|
281
|
+
case "removal-failed":
|
|
282
|
+
return `Launch-failure cleanup FAILED for worktree ${outcome.path}: ${outcome.detail} — it may still exist, and no agent spawn exists for it, so inspect it manually.`;
|
|
283
|
+
case "absent":
|
|
284
|
+
return `Launch-failure cleanup: no worktree residue was left behind.`;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* spawn-coordinator.ts — shell-bound spawn orchestration and nudge emitter.
|
|
3
|
+
* Delegates dedup/admission to task-registry.ts; keeps what the registry's shell-free
|
|
4
|
+
* design excludes: rejection-to-error conversion, spawnCtx capture, awaiting, nudging,
|
|
5
|
+
* and the launch announcement naming the new agent's id.
|
|
6
|
+
* Admission is non-destructive: a duplicate is rejected and the existing attempt keeps running.
|
|
7
|
+
*/
|
|
8
|
+
import { getPiInstance, getRuntime } from "../shell.js";
|
|
9
|
+
import { hasOutcome, lifecycleStatus, } from "../types.js";
|
|
10
|
+
import { buildAgentDetails, formatResultContent, } from "../orchestrators/protocol.js";
|
|
11
|
+
import { findTaskDedup, TaskAlreadyInFlightError, } from "../task-registry.js";
|
|
12
|
+
import { isExtensionEnabled } from "../extension-toggle.js";
|
|
13
|
+
import { actionReport } from "../ui/action-report.js";
|
|
14
|
+
// Re-exported for the spawn suite.
|
|
15
|
+
export { findTaskDedup, TaskAlreadyInFlightError } from "../task-registry.js";
|
|
16
|
+
// --- Constants ---
|
|
17
|
+
/** Nudge batch window (ms). */
|
|
18
|
+
const NUDGE_DELAY_MS = 200;
|
|
19
|
+
// --- SpawnCoordinator ---
|
|
20
|
+
export class SpawnCoordinator {
|
|
21
|
+
manager;
|
|
22
|
+
/** Background agent ids; every settlement of one nudges. */
|
|
23
|
+
backgroundAgentIds = new Set();
|
|
24
|
+
/** Pending nudge agent ids. */
|
|
25
|
+
pendingNudges = new Set();
|
|
26
|
+
/** Pending later reports by agent id, each with the report to carry. */
|
|
27
|
+
pendingFollowUps = new Map();
|
|
28
|
+
nudgeTimer = null;
|
|
29
|
+
/** Set during dispose to block nudge emission after session replacement. */
|
|
30
|
+
disposed = false;
|
|
31
|
+
/** Unified admission layer, shared with the manager. */
|
|
32
|
+
registry;
|
|
33
|
+
constructor(manager) {
|
|
34
|
+
this.manager = manager;
|
|
35
|
+
// One registry per manager: admission is the manager's own, never a second one.
|
|
36
|
+
this.registry = manager.getRegistry();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Spawn + wire tracking + (foreground) await. Converts an admit rejection into
|
|
40
|
+
* TaskAlreadyInFlightError; a rejection ends nothing but this request.
|
|
41
|
+
*/
|
|
42
|
+
async spawn(ctx, intent) {
|
|
43
|
+
// Dedup verifies only: a duplicate rejects the new request and leaves the existing attempt untouched.
|
|
44
|
+
const admission = await this.registry.admit(intent);
|
|
45
|
+
if (admission.status === "rejected") {
|
|
46
|
+
// The registry only rejects on dedup, so a rejection implies a task slug.
|
|
47
|
+
throw await this.inFlightError(intent.taskSlug, admission);
|
|
48
|
+
}
|
|
49
|
+
const agentId = admission.agentId;
|
|
50
|
+
const spawn = this.manager.getSpawn(agentId);
|
|
51
|
+
// Keeps the UI-notify fallback reachable for later nudges.
|
|
52
|
+
spawn.execution.spawnCtx = ctx;
|
|
53
|
+
// Ahead of the foreground branch, which blocks on settlement — announcing
|
|
54
|
+
// after it would report a launch only once the run is over.
|
|
55
|
+
this.announceSpawn(ctx, spawn);
|
|
56
|
+
if (intent.runInBackground) {
|
|
57
|
+
this.backgroundAgentIds.add(agentId);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await spawn.execution.promise;
|
|
61
|
+
}
|
|
62
|
+
return { agentId, spawn };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Announce an admitted spawn, naming the id stop/cleanup/steer take. Reached
|
|
66
|
+
* by every spawn, and the only report the spawn wizard gives: its run returns
|
|
67
|
+
* no tool result to read.
|
|
68
|
+
*/
|
|
69
|
+
announceSpawn(ctx, spawn) {
|
|
70
|
+
if (!ctx.hasUI)
|
|
71
|
+
return;
|
|
72
|
+
const lifecycle = spawn.lifecycle;
|
|
73
|
+
// A spawn aborted on admission never launched: there is nothing to report.
|
|
74
|
+
if (hasOutcome(lifecycle))
|
|
75
|
+
return;
|
|
76
|
+
const verb = lifecycle.phase === "queued" ? "Queued" : "Spawned";
|
|
77
|
+
actionReport(ctx.ui).succeeded(`${verb} agent ${spawn.id} (${spawn.display.type})`);
|
|
78
|
+
}
|
|
79
|
+
/** Reconstruct the dedup evidence behind an admit rejection so the error names the conflict. */
|
|
80
|
+
async inFlightError(taskSlug, rejection) {
|
|
81
|
+
// Another tool call in this session owns the task.
|
|
82
|
+
const spawn = this.manager.getSpawn(rejection.conflictingId);
|
|
83
|
+
if (spawn) {
|
|
84
|
+
return new TaskAlreadyInFlightError({ kind: "spawn", spawn }, taskSlug);
|
|
85
|
+
}
|
|
86
|
+
// Herdr conflict: re-read the live registry; the rejection carries only the id.
|
|
87
|
+
const herdrAttempts = await getRuntime().host.findAttempts(taskSlug);
|
|
88
|
+
const dedup = findTaskDedup([], herdrAttempts);
|
|
89
|
+
if (dedup.kind !== "none") {
|
|
90
|
+
return new TaskAlreadyInFlightError(dedup, taskSlug);
|
|
91
|
+
}
|
|
92
|
+
// The conflict vanished mid-read; still suppress the duplicate delegation.
|
|
93
|
+
const attempt = { name: rejection.conflictingId };
|
|
94
|
+
return new TaskAlreadyInFlightError({ kind: "herdr", attempt }, taskSlug);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Drop everything one agent still has queued: the parent asked for the
|
|
98
|
+
* teardown itself, so neither a settlement's nudge nor a report already in
|
|
99
|
+
* the batch may announce assets the teardown is removing. A report that
|
|
100
|
+
* arrives after this is queued afresh, not swallowed.
|
|
101
|
+
*/
|
|
102
|
+
dropNudge(agentId) {
|
|
103
|
+
this.pendingNudges.delete(agentId);
|
|
104
|
+
this.pendingFollowUps.delete(agentId);
|
|
105
|
+
}
|
|
106
|
+
/** Schedule a nudge, coalescing rapid completions within the batch window. */
|
|
107
|
+
scheduleNudge(agentId) {
|
|
108
|
+
this.pendingNudges.add(agentId);
|
|
109
|
+
this.ensureNudgeTimer();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A settled agent reported again: it kept working after writing its result, or
|
|
113
|
+
* a message reached its pane without reviving it. The report is news the
|
|
114
|
+
* recorded result does not carry, so it is delivered apart from that result.
|
|
115
|
+
*/
|
|
116
|
+
onAgentFollowUp(spawn, deliverable) {
|
|
117
|
+
if (!this.backgroundAgentIds.has(spawn.id))
|
|
118
|
+
return;
|
|
119
|
+
this.pendingFollowUps.set(spawn.id, deliverable);
|
|
120
|
+
this.ensureNudgeTimer();
|
|
121
|
+
}
|
|
122
|
+
/** One batch window serves both kinds of news; whichever is pending rides it. */
|
|
123
|
+
ensureNudgeTimer() {
|
|
124
|
+
if (this.nudgeTimer)
|
|
125
|
+
return;
|
|
126
|
+
this.nudgeTimer = setTimeout(() => {
|
|
127
|
+
this.nudgeTimer = null;
|
|
128
|
+
const settlements = [...this.pendingNudges];
|
|
129
|
+
this.pendingNudges.clear();
|
|
130
|
+
const followUps = [...this.pendingFollowUps];
|
|
131
|
+
this.pendingFollowUps.clear();
|
|
132
|
+
for (const id of settlements) {
|
|
133
|
+
this.emitIndividualNudge(id);
|
|
134
|
+
}
|
|
135
|
+
for (const [id, deliverable] of followUps) {
|
|
136
|
+
this.emitFollowUp(id, deliverable);
|
|
137
|
+
}
|
|
138
|
+
}, NUDGE_DELAY_MS);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Nudge on every settlement of a background agent — a revived run notifies on each
|
|
142
|
+
* settlement, not just the first. Only dispose clears the set.
|
|
143
|
+
*/
|
|
144
|
+
onAgentComplete(spawn) {
|
|
145
|
+
if (!this.backgroundAgentIds.has(spawn.id))
|
|
146
|
+
return;
|
|
147
|
+
// A stop the parent ordered itself is not news: stop_cowboy_agent returned that
|
|
148
|
+
// same settlement to the caller that made the call.
|
|
149
|
+
if (stoppedByParent(spawn))
|
|
150
|
+
return;
|
|
151
|
+
this.scheduleNudge(spawn.id);
|
|
152
|
+
}
|
|
153
|
+
dispose() {
|
|
154
|
+
if (this.nudgeTimer) {
|
|
155
|
+
clearTimeout(this.nudgeTimer);
|
|
156
|
+
this.nudgeTimer = null;
|
|
157
|
+
}
|
|
158
|
+
this.pendingNudges.clear();
|
|
159
|
+
this.pendingFollowUps.clear();
|
|
160
|
+
this.backgroundAgentIds.clear();
|
|
161
|
+
this.disposed = true;
|
|
162
|
+
}
|
|
163
|
+
// ── Private ──
|
|
164
|
+
/** Deliver a settled agent's later report, named as news beyond its result. */
|
|
165
|
+
emitFollowUp(agentId, deliverable) {
|
|
166
|
+
// Skip if disposed: pi may be stale after session replacement.
|
|
167
|
+
if (this.disposed)
|
|
168
|
+
return;
|
|
169
|
+
if (!isExtensionEnabled())
|
|
170
|
+
return;
|
|
171
|
+
const pi = getPiInstance();
|
|
172
|
+
const spawn = this.manager.getSpawn(agentId);
|
|
173
|
+
if (!spawn)
|
|
174
|
+
return;
|
|
175
|
+
const details = buildAgentDetails(spawn, {
|
|
176
|
+
includeRunInfo: true,
|
|
177
|
+
includeStatus: true,
|
|
178
|
+
});
|
|
179
|
+
const headline = `[Cowboy agent "${spawn.display.type}" ${spawn.id} reported again after settling]`;
|
|
180
|
+
try {
|
|
181
|
+
// The run's own result is already with the parent; this is what came after it.
|
|
182
|
+
pi.sendMessage({
|
|
183
|
+
customType: "subagent-result",
|
|
184
|
+
content: `${headline}\n\n${deliverable}`,
|
|
185
|
+
details,
|
|
186
|
+
display: true,
|
|
187
|
+
}, {
|
|
188
|
+
deliverAs: "followUp",
|
|
189
|
+
triggerTurn: true,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// sendMessage failed — fall back to the captured spawning-session context.
|
|
194
|
+
const spawnCtx = spawn.execution.spawnCtx;
|
|
195
|
+
if (spawnCtx) {
|
|
196
|
+
try {
|
|
197
|
+
spawnCtx.ui.notify(`${headline} New report available`, "info");
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// Spawn ctx may also be stale after session replacement.
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
emitIndividualNudge(agentId) {
|
|
206
|
+
// Skip if disposed: pi may be stale after session replacement.
|
|
207
|
+
if (this.disposed)
|
|
208
|
+
return;
|
|
209
|
+
// The one emission point, so a settlement whose batch window straddles the
|
|
210
|
+
// switch is silenced too; the settlement is not replayed on re-enable.
|
|
211
|
+
if (!isExtensionEnabled())
|
|
212
|
+
return;
|
|
213
|
+
// Read pi at call time for a fresh reference after reload.
|
|
214
|
+
const pi = getPiInstance();
|
|
215
|
+
const spawn = this.manager.getSpawn(agentId);
|
|
216
|
+
if (!spawn)
|
|
217
|
+
return;
|
|
218
|
+
const details = buildAgentDetails(spawn, {
|
|
219
|
+
includeRunInfo: true,
|
|
220
|
+
includeStatus: true,
|
|
221
|
+
});
|
|
222
|
+
try {
|
|
223
|
+
// Queued as a follow-up: a parent turn in progress finishes on its own terms,
|
|
224
|
+
// so a completion never interrupts work the orchestrator already started.
|
|
225
|
+
pi.sendMessage({
|
|
226
|
+
customType: "subagent-result",
|
|
227
|
+
content: `[Cowboy agent "${spawn.display.type}" ${spawn.id} ${lifecycleStatus(spawn.lifecycle)}]\n\n${formatResultContent(spawn)}`,
|
|
228
|
+
details,
|
|
229
|
+
display: true,
|
|
230
|
+
}, {
|
|
231
|
+
deliverAs: "followUp",
|
|
232
|
+
triggerTurn: true,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// sendMessage failed — fall back to the captured spawning-session context.
|
|
237
|
+
const spawnCtx = spawn.execution.spawnCtx;
|
|
238
|
+
if (spawnCtx) {
|
|
239
|
+
try {
|
|
240
|
+
spawnCtx.ui.notify(`[Cowboy agent "${spawn.display.type}" ${lifecycleStatus(spawn.lifecycle)}] Result available`, "info");
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
// Spawn ctx may also be stale after session replacement.
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Whether a settlement is a stop the parent agent requested through its own tool. */
|
|
250
|
+
function stoppedByParent(spawn) {
|
|
251
|
+
const lifecycle = spawn.lifecycle;
|
|
252
|
+
return (hasOutcome(lifecycle) &&
|
|
253
|
+
lifecycle.status === "stopped" &&
|
|
254
|
+
lifecycle.stop.initiator === "agent");
|
|
255
|
+
}
|