@bakers-build/addon-herdr 0.6.1-next.5 → 0.6.1-next.7

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.
@@ -1,132 +0,0 @@
1
- // Herdr-backed AgentLaunchHost (BB-190) — the INTENT-level agent host. It owns
2
- // the whole layout policy the bakers-ui plugin used to drive from the conductor:
3
- // one durable herdr tab per group, a new agent splits off a live pane, the shown
4
- // agent is zoomed, hiding un-zooms and returns to the caller. The caller speaks
5
- // only launch/list/focus/hide/kill/sendText — never panes, tabs or zoom.
6
- //
7
- // `group` is opaque (bakers passes a project slug); it maps to one tab labelled
8
- // `bakers-agents:<group>`, so a group's agents are listed + hidden together and
9
- // survive a TUI restart (rediscovered from the live tab).
10
- import { rmSync } from 'node:fs';
11
- import { writeLaunchScript } from './launch-script.js';
12
- import { AGENT_SHELL_ENV, envArgs, findTabIdByLabel, parsePaneInfo, parsePanesInTab, parseTabCreate, } from './panes.js';
13
- /** The single tab that holds a group's agent panes. */
14
- const groupTabLabel = (group) => `bakers-agents:${group}`;
15
- export function herdrAgentHost(execHerdr) {
16
- // The caller's home tab, returned to on hide. Captured lazily on the first
17
- // launch — that is when the caller is focused on its own tab (pressing `n`),
18
- // and it keeps construction side-effect-free. Best-effort: a probe failure
19
- // just leaves hide without a home to return to.
20
- let homeTab = null;
21
- const captureHome = async () => {
22
- if (homeTab !== null)
23
- return;
24
- try {
25
- homeTab = parsePaneInfo(await execHerdr(['pane', 'current'])).tabId;
26
- }
27
- catch {
28
- // no home tab known; hide() becomes a no-op focus
29
- }
30
- };
31
- // Cache each group's tab id to skip the `tab list` round-trip once known.
32
- const tabByGroup = new Map();
33
- const resolveTab = async (group) => {
34
- const cached = tabByGroup.get(group);
35
- if (cached)
36
- return cached;
37
- const found = findTabIdByLabel(await execHerdr(['tab', 'list']), groupTabLabel(group));
38
- if (found)
39
- tabByGroup.set(group, found);
40
- return found;
41
- };
42
- return {
43
- async launch({ group, cwd, command, env, label }) {
44
- await captureHome();
45
- // Every pane this host opens holds an agent, so all of them carry the
46
- // agent-shell marker (BB-64) — this is the pane a `bakers ui` user actually
47
- // attaches to. The caller's own env wins on a key clash; the marker is
48
- // merged in, never substituted for it.
49
- const e = { ...AGENT_SHELL_ENV, ...(env ?? {}) };
50
- // Find the group's tab and split off a LIVE pane (newest-first; a stale
51
- // pane — a previous agent died/was closed — is skipped). None survive, or
52
- // no tab yet → create the group tab (its root pane is the agent).
53
- let pane = null;
54
- const tabId = await resolveTab(group);
55
- if (tabId) {
56
- const panes = parsePanesInTab(await execHerdr(['pane', 'list']), tabId);
57
- for (const p of [...panes].reverse()) {
58
- try {
59
- pane = parsePaneInfo(await execHerdr([
60
- 'pane',
61
- 'split',
62
- p.paneId,
63
- '--direction',
64
- 'right',
65
- '--no-focus',
66
- '--cwd',
67
- cwd,
68
- ...envArgs(e),
69
- ]));
70
- break;
71
- }
72
- catch {
73
- // stale pane — try the next
74
- }
75
- }
76
- if (!pane)
77
- tabByGroup.delete(group);
78
- }
79
- if (!pane) {
80
- pane = parseTabCreate(await execHerdr([
81
- 'tab',
82
- 'create',
83
- '--cwd',
84
- cwd,
85
- '--no-focus',
86
- '--label',
87
- groupTabLabel(group),
88
- ...envArgs(e),
89
- ]));
90
- tabByGroup.set(group, pane.tabId);
91
- }
92
- const launch = writeLaunchScript(command);
93
- // ponytail: on success the wrapper's started/exit markers stay in tmp
94
- // (no secrets); a sweep is only worth it if they ever pile up.
95
- await execHerdr(['pane', 'run', pane.paneId, launch.typedCommand]).catch((err) => {
96
- rmSync(launch.dir, { recursive: true, force: true });
97
- throw err;
98
- });
99
- const human = label ?? 'agent';
100
- await execHerdr(['pane', 'rename', pane.paneId, human]).catch(() => { });
101
- await execHerdr(['pane', 'zoom', pane.paneId, '--on']).catch(() => { });
102
- return { id: pane.paneId, group, label: human };
103
- },
104
- async list(group) {
105
- const tabId = await resolveTab(group);
106
- if (!tabId)
107
- return [];
108
- return parsePanesInTab(await execHerdr(['pane', 'list']), tabId).map((p) => ({ id: p.paneId, group, label: p.label }));
109
- },
110
- async focus(id) {
111
- await execHerdr(['pane', 'zoom', id, '--on']);
112
- },
113
- async hide(group) {
114
- // Un-zoom the group's panes (so it reads as the tiled overview next time)
115
- // and return focus to the caller's home tab. The agents keep running.
116
- const tabId = await resolveTab(group);
117
- if (tabId) {
118
- for (const p of parsePanesInTab(await execHerdr(['pane', 'list']), tabId)) {
119
- await execHerdr(['pane', 'zoom', p.paneId, '--off']).catch(() => { });
120
- }
121
- }
122
- if (homeTab)
123
- await execHerdr(['tab', 'focus', homeTab]).catch(() => { });
124
- },
125
- async kill(id) {
126
- await execHerdr(['pane', 'close', id]);
127
- },
128
- async sendText(id, text) {
129
- await execHerdr(['pane', 'send-text', id, text]);
130
- },
131
- };
132
- }
@@ -1,6 +0,0 @@
1
- import type { HerdrHost } from '@bakers-build/conductor/contract';
2
- /**
3
- * Close every herdr workspace whose label equals the conductor handle, then
4
- * create one and `exec env` the pane command so herdr auto-closes on exit.
5
- */
6
- export declare const herdrProcessHost: HerdrHost;
@@ -1,46 +0,0 @@
1
- import { exec } from '@bakers-build/core';
2
- import { isRecord, parseJson } from './pane-layout.js';
3
- import { parseWorkspaceList } from './workspace-list.js';
4
- function parseWorkspaceCreate(output) {
5
- const parsed = parseJson(output, 'workspace create');
6
- const paneId = isRecord(parsed)
7
- ? parsed.result
8
- ?.root_pane?.pane_id
9
- : undefined;
10
- if (typeof paneId !== 'string' || paneId === '') {
11
- throw new Error('herdr workspace create returned no pane id');
12
- }
13
- return paneId;
14
- }
15
- /**
16
- * Close every herdr workspace whose label equals the conductor handle, then
17
- * create one and `exec env` the pane command so herdr auto-closes on exit.
18
- */
19
- export const herdrProcessHost = {
20
- async spawn(label, cwd, cmd) {
21
- const listed = parseWorkspaceList(await exec('herdr', ['workspace', 'list']));
22
- for (const ws of listed) {
23
- if (ws.label === label) {
24
- try {
25
- await exec('herdr', ['workspace', 'close', ws.workspaceId]);
26
- }
27
- catch {
28
- // herdr may already have auto-closed it after a previous stop
29
- }
30
- }
31
- }
32
- const paneId = parseWorkspaceCreate(await exec('herdr', [
33
- 'workspace',
34
- 'create',
35
- '--cwd',
36
- cwd,
37
- '--label',
38
- label,
39
- '--no-focus',
40
- ]));
41
- // `exec env` replaces the pane's login shell (fish-safe VAR=value form)
42
- // so herdr closes the workspace when the conductor exits by any path.
43
- // `env` needs a real `bakers` executable on PATH.
44
- await exec('herdr', ['pane', 'run', paneId, `exec env ${cmd}`]);
45
- },
46
- };