@bakers-build/addon-herdr 0.8.1-next.1 → 0.8.1-next.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.
@@ -6,7 +6,7 @@ export { DEFAULT_OPEN_LAYOUT, type OpenLayout } from './open-layout.js';
6
6
  export type { HerdrExec } from './pane-layout.js';
7
7
  export { envArgs } from './panes.js';
8
8
  export { HerdrWorkspace, type HerdrWorkspaceOptions, herdrWorkspace, } from './workspace.js';
9
- export { parseWorkspaceList, type WorkspaceEntry, } from './workspace-list.js';
9
+ export { parseWorkspaceList, type WorkspaceEntry } from './workspace-list.js';
10
10
  export declare class HerdrExecutor implements BbExecutor {
11
11
  private readonly options;
12
12
  private readonly execHerdr;
@@ -62,6 +62,18 @@ export declare class HerdrExecutor implements BbExecutor {
62
62
  * The branch worktree is untouched (that is `HerdrWorkspace.remove`).
63
63
  */
64
64
  cleanupRun(branch: string, runId: number): Promise<void>;
65
+ /**
66
+ * Whether a pane of the run's tab still runs the run's launch wrapper; a
67
+ * failing `herdr` call throws. After a server restart herdr restores tabs as
68
+ * bare shells, or resumes the agent itself without the run's flags and
69
+ * tools, so an open tab alone does not mean the run lives.
70
+ */
71
+ runAlive(branch: string, runId: number): Promise<boolean>;
72
+ /**
73
+ * The branch workspace's tabs labelled `#<runId>`: after a restart herdr can
74
+ * restore an old run tab beside the relaunched one.
75
+ */
76
+ private runTabs;
65
77
  private commandFor;
66
78
  }
67
79
  export declare function herdrExecutor(options?: HerdrExecutorOptions): ExecutorPlugin;
package/dist/src/index.js CHANGED
@@ -13,7 +13,7 @@ export { envArgs } from './panes.js';
13
13
  // @bakers-build/addon-herdr-workspace was merged in). The package DEFAULT export
14
14
  // stays the executor (below); herdrWorkspace + HerdrWorkspace are named exports.
15
15
  export { HerdrWorkspace, herdrWorkspace, } from './workspace.js';
16
- export { parseWorkspaceList, } from './workspace-list.js';
16
+ export { parseWorkspaceList } from './workspace-list.js';
17
17
  async function defaultExec(args, opts) {
18
18
  return exec('herdr', args, opts);
19
19
  }
@@ -313,21 +313,64 @@ export class HerdrExecutor {
313
313
  * The branch worktree is untouched (that is `HerdrWorkspace.remove`).
314
314
  */
315
315
  async cleanupRun(branch, runId) {
316
- const workspaceId = await this.findWorkspaceByBranch(branch);
317
- if (!workspaceId) {
318
- return;
316
+ // No tab for this run is a quiet best-effort no-op (AC-4).
317
+ for (const tabId of (await this.runTabs(branch, runId)).tabIds) {
318
+ try {
319
+ await this.execHerdr(['tab', 'close', tabId]);
320
+ }
321
+ catch {
322
+ // ignore — best-effort: a failing tab-close must not abort finalisation
323
+ }
319
324
  }
320
- const tabs = parseTabList(await this.execHerdr(['tab', 'list', '--workspace', workspaceId]));
321
- const match = tabs.find((tab) => labelMatchesRun(tab.label, runId));
322
- if (!match) {
323
- return; // no tab for this run — quiet best-effort no-op (AC-4)
325
+ }
326
+ /**
327
+ * Whether a pane of the run's tab still runs the run's launch wrapper; a
328
+ * failing `herdr` call throws. After a server restart herdr restores tabs as
329
+ * bare shells, or resumes the agent itself without the run's flags and
330
+ * tools, so an open tab alone does not mean the run lives.
331
+ */
332
+ async runAlive(branch, runId) {
333
+ const { workspaceId, tabIds } = await this.runTabs(branch, runId);
334
+ if (tabIds.size === 0) {
335
+ return false;
324
336
  }
325
- try {
326
- await this.execHerdr(['tab', 'close', match.tabId]);
337
+ const listed = parseJson(await this.execHerdr(['pane', 'list', '--workspace', workspaceId]), 'pane list');
338
+ const panes = isRecord(listed)
339
+ ? listed.result?.panes
340
+ : undefined;
341
+ for (const pane of Array.isArray(panes) ? panes.filter(isRecord) : []) {
342
+ if (!tabIds.has(pane.tab_id) ||
343
+ typeof pane.pane_id !== 'string') {
344
+ continue;
345
+ }
346
+ const info = parseJson(await this.execHerdr(['pane', 'process-info', '--pane', pane.pane_id]), 'pane process-info');
347
+ const procs = isRecord(info)
348
+ ? info.result?.process_info?.foreground_processes
349
+ : undefined;
350
+ const wrapper = /\/bakers-run-[^/]+\/run\.sh$/;
351
+ if (Array.isArray(procs) &&
352
+ procs.some((p) => isRecord(p) &&
353
+ Array.isArray(p.argv) &&
354
+ p.argv.some((a) => typeof a === 'string' && wrapper.test(a)))) {
355
+ return true;
356
+ }
327
357
  }
328
- catch {
329
- // ignore — best-effort: a failing tab-close must not abort finalisation
358
+ return false;
359
+ }
360
+ /**
361
+ * The branch workspace's tabs labelled `#<runId>`: after a restart herdr can
362
+ * restore an old run tab beside the relaunched one.
363
+ */
364
+ async runTabs(branch, runId) {
365
+ const workspaceId = await this.findWorkspaceByBranch(branch);
366
+ if (!workspaceId) {
367
+ return { workspaceId: '', tabIds: new Set() };
330
368
  }
369
+ const tabs = parseTabList(await this.execHerdr(['tab', 'list', '--workspace', workspaceId]));
370
+ return {
371
+ workspaceId,
372
+ tabIds: new Set(tabs.filter((t) => labelMatchesRun(t.label, runId)).map((t) => t.tabId)),
373
+ };
331
374
  }
332
375
  commandFor(input) {
333
376
  const env = Object.entries(input.env ?? {}).map(([key, value]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-herdr",
3
- "version": "0.8.1-next.1",
3
+ "version": "0.8.1-next.2",
4
4
  "description": "bakers.build herdr integration: spawn executor + per-ticket worktree workspace.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -23,14 +23,14 @@
23
23
  "directory": "bakers-cli/addons/herdr"
24
24
  },
25
25
  "dependencies": {
26
- "@bakers-build/addon-workspace-git": "^0.8.1-next.1"
26
+ "@bakers-build/addon-workspace-git": "^0.8.1-next.2"
27
27
  },
28
28
  "peerDependencies": {
29
- "@bakers-build/conductor": "^0.8.1-next.1",
30
- "@bakers-build/core": "^0.8.1-next.1"
29
+ "@bakers-build/conductor": "^0.8.1-next.2",
30
+ "@bakers-build/core": "^0.8.1-next.2"
31
31
  },
32
32
  "bakersBuild": {
33
- "commit": "c4a887bee37bb2fed14bb9ba15ad0aacf0e26f7e",
33
+ "commit": "0177880667693d1c36c65ffced82d2f3a17cbf2a",
34
34
  "channel": "next"
35
35
  }
36
36
  }