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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -2
  3. package/agents/explore.toml +40 -0
  4. package/dist/agents/agent-assets.js +261 -0
  5. package/dist/agents/agent-cleanup.js +284 -0
  6. package/dist/agents/agent-discovery.js +108 -0
  7. package/dist/agents/agent-host.js +10 -0
  8. package/dist/agents/agent-manager.js +367 -0
  9. package/dist/agents/agent-reviver.js +64 -0
  10. package/dist/agents/agent-runner.js +288 -0
  11. package/dist/agents/agent-spawn-store.js +57 -0
  12. package/dist/agents/agent-template.js +46 -0
  13. package/dist/agents/agent-types.js +144 -0
  14. package/dist/agents/batch.js +92 -0
  15. package/dist/agents/cleanup-policy.js +194 -0
  16. package/dist/agents/cleanup-report.js +128 -0
  17. package/dist/agents/default-agents.js +19 -0
  18. package/dist/agents/harness/pi-bolt.js +15 -0
  19. package/dist/agents/harness/pi-compatible.js +68 -0
  20. package/dist/agents/harness/pig.js +16 -0
  21. package/dist/agents/harness/registry.js +27 -0
  22. package/dist/agents/harness.js +32 -0
  23. package/dist/agents/result-file-permissions.js +29 -0
  24. package/dist/agents/run-state.js +270 -0
  25. package/dist/agents/schemas/cleanup-batch.schema.js +19 -0
  26. package/dist/agents/schemas/cowboy-agents.schema.js +39 -0
  27. package/dist/agents/schemas/merge-batch.schema.js +25 -0
  28. package/dist/agents/schemas/steer-batch.schema.js +22 -0
  29. package/dist/agents/schemas/stop-batch.schema.js +18 -0
  30. package/dist/agents/spawn-defaults.js +70 -0
  31. package/dist/agents/subagent-session.js +601 -0
  32. package/dist/agents/tool-cleanup.js +57 -0
  33. package/dist/agents/tool-execution.js +125 -0
  34. package/dist/agents/tool-merge.js +190 -0
  35. package/dist/agents/tool-result.js +17 -0
  36. package/dist/agents/tool-steer.js +89 -0
  37. package/dist/agents/types.js +1 -0
  38. package/dist/availability.js +38 -0
  39. package/dist/config/config-io.js +261 -0
  40. package/dist/config/config-store.js +321 -0
  41. package/dist/config/config-validation.js +173 -0
  42. package/dist/config/layered-config.js +117 -0
  43. package/dist/config/types.js +23 -0
  44. package/dist/cow-support-launch.js +43 -0
  45. package/dist/events.js +146 -0
  46. package/dist/extension-toggle.js +28 -0
  47. package/dist/harness-availability-launch.js +23 -0
  48. package/dist/index.js +52 -0
  49. package/dist/infrastructure/exec-path.js +35 -0
  50. package/dist/infrastructure/git/cow-clone.js +398 -0
  51. package/dist/infrastructure/git/git-materializer.js +342 -0
  52. package/dist/infrastructure/git/git-merger.js +234 -0
  53. package/dist/infrastructure/git/git-retention.js +43 -0
  54. package/dist/infrastructure/git/git-runner.js +145 -0
  55. package/dist/infrastructure/git/git-worktree.js +143 -0
  56. package/dist/infrastructure/git/index.js +11 -0
  57. package/dist/infrastructure/git-client.js +11 -0
  58. package/dist/infrastructure/herdr/agent-stopper.js +60 -0
  59. package/dist/infrastructure/herdr/agents.js +329 -0
  60. package/dist/infrastructure/herdr/herdr-client.js +36 -0
  61. package/dist/infrastructure/herdr/herdr-transport.js +158 -0
  62. package/dist/infrastructure/herdr/index.js +15 -0
  63. package/dist/infrastructure/herdr/panes.js +174 -0
  64. package/dist/infrastructure/herdr/polling.js +44 -0
  65. package/dist/infrastructure/herdr/worktrees.js +76 -0
  66. package/dist/infrastructure/herdr-client.js +6 -0
  67. package/dist/infrastructure/herdr-host.js +163 -0
  68. package/dist/logger.js +79 -0
  69. package/dist/models/model-groups.js +72 -0
  70. package/dist/models/model-precedence.js +50 -0
  71. package/dist/models/model-request.js +108 -0
  72. package/dist/orchestrators/briefing-section.js +14 -0
  73. package/dist/orchestrators/context.js +116 -0
  74. package/dist/orchestrators/cues.js +90 -0
  75. package/dist/orchestrators/default-orchestrators.js +36 -0
  76. package/dist/orchestrators/orchestrator-discovery.js +68 -0
  77. package/dist/orchestrators/orchestrator-template.js +43 -0
  78. package/dist/orchestrators/orchestrator-types.js +78 -0
  79. package/dist/orchestrators/protocol.js +292 -0
  80. package/dist/orchestrators/types.js +7 -0
  81. package/dist/paths.js +66 -0
  82. package/dist/pi-settings.js +7 -0
  83. package/dist/predicates.js +25 -0
  84. package/dist/prompt/prompts.js +110 -0
  85. package/dist/prompt/skill-loader.js +153 -0
  86. package/dist/prompt/subagent-system-prompt.js +173 -0
  87. package/dist/registration.js +220 -0
  88. package/dist/shell.js +225 -0
  89. package/dist/spawn/cow-support.js +53 -0
  90. package/dist/spawn/herdr-launcher.js +80 -0
  91. package/dist/spawn/repo-lock.js +34 -0
  92. package/dist/spawn/sandbox.js +286 -0
  93. package/dist/spawn/spawn-coordinator.js +255 -0
  94. package/dist/spawn/spawn-id.js +39 -0
  95. package/dist/spawn/worktree-policy.js +137 -0
  96. package/dist/status-note.js +30 -0
  97. package/dist/subagent/ipc-protocol.js +68 -0
  98. package/dist/subagent/ipc.js +110 -0
  99. package/dist/subagent/pane-supervisor.js +24 -0
  100. package/dist/subagent/socket-ipc.js +240 -0
  101. package/dist/subagent/supervisor.js +315 -0
  102. package/dist/task-registry.js +258 -0
  103. package/dist/templates/template-files.js +84 -0
  104. package/dist/types.js +84 -0
  105. package/dist/ui/action-report.js +21 -0
  106. package/dist/ui/format.js +47 -0
  107. package/dist/ui/indicator.js +480 -0
  108. package/dist/ui/menu/helpers.js +227 -0
  109. package/dist/ui/menu/menu-agent-settings.js +182 -0
  110. package/dist/ui/menu/menu-agent-status.js +444 -0
  111. package/dist/ui/menu/menu-concurrency.js +226 -0
  112. package/dist/ui/menu/menu-model-settings.js +244 -0
  113. package/dist/ui/menu/menu-spawn-defaults.js +71 -0
  114. package/dist/ui/menu/menu-spawn-wizard.js +367 -0
  115. package/dist/ui/menu/menu-spawn-worktree.js +107 -0
  116. package/dist/ui/menu/menu-system-prompt.js +104 -0
  117. package/dist/ui/menu/menu-worktree-command.js +150 -0
  118. package/dist/ui/menu/menus.js +187 -0
  119. package/dist/ui/menu/model-picker.js +160 -0
  120. package/dist/ui/menu/screen-host.js +87 -0
  121. package/dist/ui/menu/submenus/confirm.js +23 -0
  122. package/dist/ui/menu/submenus/model-select.js +42 -0
  123. package/dist/ui/menu/submenus/name-field.js +43 -0
  124. package/dist/ui/menu/submenus/numeric-input.js +61 -0
  125. package/dist/ui/menu/submenus/target-select.js +129 -0
  126. package/dist/ui/menu/submenus/text-editor.js +49 -0
  127. package/dist/ui/menu/submenus/worktree-command-name.js +73 -0
  128. package/dist/ui/menu/submenus/worktree-name.js +53 -0
  129. package/dist/ui/menu/wrappers/settings-list.js +101 -0
  130. package/dist/ui/searchable-select.js +147 -0
  131. package/dist/ui/types.js +1 -0
  132. package/dist/utils.js +70 -0
  133. package/docs/assets/grazing.png +0 -0
  134. package/docs/assets/herdr-containers.png +0 -0
  135. package/docs/assets/logo-transparent.png +0 -0
  136. package/orchestrators/with-code-review.toml +20 -0
  137. package/package.json +109 -3
@@ -0,0 +1,145 @@
1
+ /**
2
+ * git-runner.ts — Layer 1: the git transport.
3
+ *
4
+ * The only place that shells out through `pi.exec` and the only place that
5
+ * knows a git failure's shape: `run` reports it as data, `exec` throws a
6
+ * `GitError`. Layers above compose these primitives and never touch `pi.exec`.
7
+ */
8
+ import * as fs from "node:fs";
9
+ import * as path from "node:path";
10
+ import { GIT_EXEC_TIMEOUT_MS } from "../../utils.js";
11
+ // --- Constants ---
12
+ /** Probe budget (ms) — status/rev-parse on big checkouts. */
13
+ const PROBE_TIMEOUT_MS = 30_000;
14
+ /** Worktree add/remove and checkout-completion budget (ms). */
15
+ export const GIT_WORKTREE_TIMEOUT_MS = 60_000;
16
+ // --- Error type ---
17
+ /** A failed git step. */
18
+ export class GitError extends Error {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = "GitError";
22
+ }
23
+ }
24
+ // --- Transport ---
25
+ /** Raw git process I/O, bound to one `pi` instance. */
26
+ export class GitCommandRunner {
27
+ pi;
28
+ constructor(pi) {
29
+ this.pi = pi;
30
+ }
31
+ /** Run git; `undefined` when `pi.exec` itself fails (transport/timeout). */
32
+ async run(args, cwd, timeoutMs = GIT_EXEC_TIMEOUT_MS) {
33
+ try {
34
+ const result = await this.pi.exec("git", [...args], {
35
+ cwd,
36
+ timeout: timeoutMs,
37
+ });
38
+ return {
39
+ code: result.code,
40
+ stdout: result.stdout.trim(),
41
+ stderr: result.stderr.trim(),
42
+ };
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ /** Trimmed stdout, or `undefined` when the question could not be answered. */
49
+ async probe(args, cwd, options = {}) {
50
+ const result = await this.run(args, cwd, options.timeoutMs ?? PROBE_TIMEOUT_MS);
51
+ if (result === undefined || result.code !== 0)
52
+ return undefined;
53
+ return result.stdout;
54
+ }
55
+ /** Trimmed stdout; throws `GitError` on any failure. */
56
+ async exec(args, cwd, timeoutMs) {
57
+ const result = await this.run(args, cwd, timeoutMs);
58
+ if (result === undefined) {
59
+ throw new GitError(`git ${args.join(" ")} failed in ${cwd}: the command could not be run`);
60
+ }
61
+ if (result.code !== 0) {
62
+ throw new GitError(`git ${args.join(" ")} failed in ${cwd} (exit ${result.code}): ${(result.stderr ||
63
+ result.stdout ||
64
+ `exit code ${result.code}`)
65
+ .trim()
66
+ .slice(0, 500)}`);
67
+ }
68
+ return result.stdout;
69
+ }
70
+ /** Whether git exits zero; "could not run" is no. */
71
+ async test(args, cwd, timeoutMs) {
72
+ const result = await this.run(args, cwd, timeoutMs);
73
+ return result !== undefined && result.code === 0;
74
+ }
75
+ /**
76
+ * Non-empty output lines; `undefined` when the probe failed, so a transport
77
+ * error is never mistaken for "no lines".
78
+ */
79
+ async lines(args, cwd, delimiter = "\n") {
80
+ const output = await this.probe(args, cwd);
81
+ if (output === undefined)
82
+ return undefined;
83
+ return output.split(delimiter).filter((line) => line !== "");
84
+ }
85
+ /**
86
+ * Run a bundled helper program through `pi.exec`. A helper that never started
87
+ * reports exit 1 with the transport error in `stderr` — one failure path.
88
+ */
89
+ async helper(command, args, options) {
90
+ try {
91
+ const result = await this.pi.exec(command, [...args], {
92
+ ...(options.cwd === undefined ? {} : { cwd: options.cwd }),
93
+ timeout: options.timeoutMs,
94
+ });
95
+ return {
96
+ code: result.code,
97
+ stdout: result.stdout,
98
+ stderr: result.stderr,
99
+ };
100
+ }
101
+ catch (err) {
102
+ return {
103
+ code: 1,
104
+ stdout: "",
105
+ stderr: err instanceof Error ? err.message : String(err),
106
+ };
107
+ }
108
+ }
109
+ }
110
+ // --- Free-function facade ---
111
+ /** `run` for callers holding a pi instance rather than a runner. */
112
+ export async function gitRun(pi, args, cwd, timeoutMs = GIT_EXEC_TIMEOUT_MS) {
113
+ return new GitCommandRunner(pi).run(args, cwd, timeoutMs);
114
+ }
115
+ /** `probe` for callers holding a pi instance rather than a runner. */
116
+ export async function gitProbe(pi, args, cwd) {
117
+ return new GitCommandRunner(pi).probe(args, cwd);
118
+ }
119
+ /**
120
+ * Repo layout from `git rev-parse --git-common-dir` output. A relative answer
121
+ * resolves against the probed cwd; the main root is the common dir's parent.
122
+ */
123
+ export function locateMainCheckout(commonDirOutput, cwd) {
124
+ const commonDir = path.isAbsolute(commonDirOutput)
125
+ ? commonDirOutput
126
+ : path.resolve(cwd, commonDirOutput);
127
+ return { commonDir, mainRoot: path.dirname(commonDir) };
128
+ }
129
+ /**
130
+ * Main checkout root for any in-repo cwd. Herdr rejects a linked worktree as an
131
+ * adoption source, and the caller may itself sit in one — hence the common-dir
132
+ * resolution. Throws GitError outside a git repository.
133
+ */
134
+ export async function resolveMainCheckout(pi, repoCwd) {
135
+ const runner = new GitCommandRunner(pi);
136
+ const common = await runner.probe(["rev-parse", "--git-common-dir"], repoCwd);
137
+ if (common === undefined) {
138
+ throw new GitError(`cannot create worktree: ${repoCwd} is not inside a git repository`);
139
+ }
140
+ const { mainRoot } = locateMainCheckout(common, repoCwd);
141
+ if (!fs.existsSync(path.join(mainRoot, ".git"))) {
142
+ throw new GitError(`cannot create worktree: main checkout not found for ${repoCwd}`);
143
+ }
144
+ return mainRoot;
145
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * git-worktree.ts — Layer 2: one git worktree as an entity, and the repo's set
3
+ * of them.
4
+ *
5
+ * Binds path (and branch, when known) to the transport. No policy here: dirty
6
+ * worktrees are interpreted in git-retention.ts, branch deletion policy in
7
+ * git-merger.ts.
8
+ */
9
+ import { GIT_EXEC_TIMEOUT_MS } from "../../utils.js";
10
+ import { GitError, GitCommandRunner, GIT_WORKTREE_TIMEOUT_MS, } from "./git-runner.js";
11
+ /** Budget (ms) for the read-only questions a picker asks: a scan must stay snappy. */
12
+ const WORKTREE_SCAN_TIMEOUT_MS = 5_000;
13
+ /** One linked worktree checkout on disk. */
14
+ export class GitWorktree {
15
+ runner;
16
+ path;
17
+ branch;
18
+ constructor(runner,
19
+ /** Absolute path of the checkout. */
20
+ path,
21
+ /** Branch the checkout carries, when the caller knows it. */
22
+ branch) {
23
+ this.runner = runner;
24
+ this.path = path;
25
+ this.branch = branch;
26
+ }
27
+ /**
28
+ * `git status --porcelain`, trimmed. `undefined` means "could not tell" —
29
+ * callers must treat it as dirty, never clean.
30
+ */
31
+ async status(options) {
32
+ return this.runner.probe(["status", "--porcelain"], this.path, options);
33
+ }
34
+ /** Whether the checkout has uncommitted changes; `undefined` is not clean. */
35
+ async isDirty() {
36
+ const status = await this.status({ timeoutMs: GIT_EXEC_TIMEOUT_MS });
37
+ if (status === undefined)
38
+ return undefined;
39
+ return status !== "";
40
+ }
41
+ /**
42
+ * Best-effort `git worktree remove [--force]`; never throws. Defaults to
43
+ * running from the worktree itself, which git allows.
44
+ */
45
+ async remove(force = true, cwd = this.path) {
46
+ await this.runner.run(force
47
+ ? ["worktree", "remove", "--force", this.path]
48
+ : ["worktree", "remove", this.path], cwd, GIT_WORKTREE_TIMEOUT_MS);
49
+ }
50
+ }
51
+ /** Best-effort `git worktree remove --force`; never throws. */
52
+ export async function removeGitWorktree(pi, repoCwd, wtPath) {
53
+ await new GitWorktree(new GitCommandRunner(pi), wtPath).remove(true, repoCwd);
54
+ }
55
+ /**
56
+ * Whether `branch` resolves to a ref in `repoCwd`. A question that cannot be
57
+ * asked throws: an unanswered probe must not read as "no such branch".
58
+ */
59
+ export async function refExists(runner, branch, repoCwd) {
60
+ const verify = await runner.run(["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`], repoCwd);
61
+ if (verify === undefined) {
62
+ throw new GitError(`git rev-parse --verify refs/heads/${branch} could not run in ${repoCwd}`);
63
+ }
64
+ return verify.code === 0;
65
+ }
66
+ /** Run `branch -D` and shape its outcome; whether the ref should be deleted is the caller's question. */
67
+ export async function deleteBranchRef(runner, branch, repoCwd) {
68
+ const del = await runner.run(["branch", "-D", "--", branch], repoCwd);
69
+ if (del === undefined) {
70
+ throw new GitError(`git branch -D ${branch} could not run in ${repoCwd}`);
71
+ }
72
+ if (del.code !== 0) {
73
+ return {
74
+ kind: "delete-failed",
75
+ detail: (del.stderr || del.stdout || `git branch -D exited ${del.code}`)
76
+ .trim()
77
+ .slice(0, 200),
78
+ };
79
+ }
80
+ return { kind: "deleted" };
81
+ }
82
+ /**
83
+ * Delete a branch by name — the undo of a `git worktree add` that minted it,
84
+ * and the policy-free counterpart of git-merger.ts's `deleteWorktreeBranch`.
85
+ * The only question asked is whether the ref is there: nothing has committed on
86
+ * a branch this fresh, and git refuses the deletion itself while a checkout
87
+ * still holds it.
88
+ */
89
+ export async function deleteCreatedBranch(pi, branch, repoCwd) {
90
+ const runner = new GitCommandRunner(pi);
91
+ try {
92
+ if (!(await refExists(runner, branch, repoCwd))) {
93
+ return { kind: "not-applicable" };
94
+ }
95
+ return await deleteBranchRef(runner, branch, repoCwd);
96
+ }
97
+ catch (err) {
98
+ return {
99
+ kind: "delete-failed",
100
+ detail: err instanceof Error ? err.message : String(err),
101
+ };
102
+ }
103
+ }
104
+ /**
105
+ * Parse `git worktree list --porcelain` output (blank-line-separated blocks):
106
+ * `worktree <path>`, `HEAD <sha>`, `branch refs/heads/<name>` or `detached`.
107
+ */
108
+ function parseWorktreeList(output) {
109
+ const entries = [];
110
+ for (const block of output.split(/\n\n+/)) {
111
+ if (!block.trim())
112
+ continue;
113
+ let path = "";
114
+ let branch = null;
115
+ let isDetached = false;
116
+ for (const line of block.split("\n")) {
117
+ if (line.startsWith("worktree ")) {
118
+ path = line.slice("worktree ".length);
119
+ }
120
+ else if (line.startsWith("branch refs/heads/")) {
121
+ branch = line.slice("branch refs/heads/".length);
122
+ }
123
+ else if (line === "detached") {
124
+ isDetached = true;
125
+ }
126
+ }
127
+ if (path)
128
+ entries.push({ path, branch, isDetached });
129
+ }
130
+ return entries;
131
+ }
132
+ /** The repo's checkouts: the main one first, linked ones after. Null when git cannot answer. */
133
+ export async function listGitWorktrees(pi, repoCwd) {
134
+ const output = await new GitCommandRunner(pi).probe(["worktree", "list", "--porcelain"], repoCwd, { timeoutMs: WORKTREE_SCAN_TIMEOUT_MS });
135
+ if (output === undefined)
136
+ return null;
137
+ return parseWorktreeList(output);
138
+ }
139
+ /** Whether `cwd` is inside a git repository (the same `rev-parse` probe the worktree validator runs). */
140
+ export async function isGitRepo(pi, cwd) {
141
+ const commonDir = await new GitCommandRunner(pi).probe(["rev-parse", "--git-common-dir"], cwd, { timeoutMs: WORKTREE_SCAN_TIMEOUT_MS });
142
+ return commonDir !== undefined && commonDir !== "";
143
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * index.ts — Barrel for the git infrastructure folder.
3
+ *
4
+ * Layer 1 git-runner.ts → Layer 2 git-worktree.ts → Layer 3 git-materializer.ts,
5
+ * git-merger.ts, git-retention.ts. Importers use `../git-client.js`.
6
+ */
7
+ export * from "./git-runner.js";
8
+ export * from "./git-worktree.js";
9
+ export * from "./git-materializer.js";
10
+ export * from "./git-merger.js";
11
+ export * from "./git-retention.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * git-client.ts — the git/filesystem plane (see `./git/`).
3
+ *
4
+ * Canonical import path: re-exports the whole surface as one module, so
5
+ * importers never need to know which layer owns an operation.
6
+ *
7
+ * Layer 1 git/git-runner.ts (transport)
8
+ * Layer 2 git/git-worktree.ts (entity)
9
+ * Layer 3 git/git-materializer.ts, git-merger.ts, git-retention.ts
10
+ */
11
+ export * from "./git/index.js";
@@ -0,0 +1,60 @@
1
+ /**
2
+ * agent-stopper.ts — Layer 3: interrupt, then confirm the agent is gone.
3
+ *
4
+ * One invariant: a stop is never reported done until herdr's registry agrees the
5
+ * agent is gone. Interrupt first (best effort) so pi can exit on its own and
6
+ * leave the pane reusable; the pane is never closed (worktree removal after a
7
+ * stop needs the placement to survive). Only called for an explicit stop — never
8
+ * on its own, never while admitting a spawn.
9
+ */
10
+ import { HerdrAgents } from "./agents.js";
11
+ import { HerdrTransport } from "./herdr-transport.js";
12
+ import { keepPolling, pollUntil, settled } from "./polling.js";
13
+ /** Interrupt grace window (ms). */
14
+ const DEFAULT_INTERRUPT_GRACE_MS = 8_000;
15
+ /** Registry-gone confirmation window after the grace window (ms). */
16
+ const DEFAULT_CONFIRM_MS = 15_000;
17
+ /** Registry-gone probe interval (ms). */
18
+ const GONE_POLL_INTERVAL_MS = 1_000;
19
+ /**
20
+ * Stop agents until herdr's registry confirms them gone. The pane id is the only
21
+ * reliable agent target (herdr 0.8.x drops the custom `agent start` name).
22
+ */
23
+ export class HerdrAgentStopper {
24
+ agents;
25
+ constructor(agents) {
26
+ this.agents = agents;
27
+ }
28
+ /** Stop the agent on `paneId`; true when the registry confirmed it gone. */
29
+ async stopAgentAndWait(paneId, opts) {
30
+ const interruptGraceMs = opts?.interruptGraceMs ?? DEFAULT_INTERRUPT_GRACE_MS;
31
+ const confirmMs = opts?.confirmMs ?? DEFAULT_CONFIRM_MS;
32
+ await this.agents.interruptAgent(paneId);
33
+ if (await this.waitUntilAgentGone(paneId, interruptGraceMs))
34
+ return true;
35
+ return this.waitUntilAgentGone(paneId, confirmMs);
36
+ }
37
+ /** True once herdr's registry no longer lists the agent on `paneId`. */
38
+ async waitUntilAgentGone(paneId, timeoutMs) {
39
+ const gone = await pollUntil(async () => {
40
+ try {
41
+ // Only an empty response confirms absence; a failed probe is unknown.
42
+ if (!(await this.agents.getAgentInfo(paneId)))
43
+ return settled(true);
44
+ }
45
+ catch {
46
+ // A transient CLI/server failure authorizes no replacement launch.
47
+ }
48
+ return keepPolling();
49
+ }, { intervalMs: GONE_POLL_INTERVAL_MS, timeoutMs });
50
+ return gone ?? false;
51
+ }
52
+ }
53
+ /** Kill state machine over the shared transport for one pi instance. */
54
+ export function createHerdrAgentStopper(pi) {
55
+ const transport = new HerdrTransport(pi);
56
+ return new HerdrAgentStopper(new HerdrAgents(transport));
57
+ }
58
+ export async function stopAgentAndWait(pi, paneId, opts) {
59
+ return createHerdrAgentStopper(pi).stopAgentAndWait(paneId, opts);
60
+ }