@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.
- package/dist/src/config.d.ts +5 -11
- package/dist/src/fs.d.ts +2 -15
- package/dist/src/fs.js +5 -48
- package/dist/src/index.d.ts +14 -165
- package/dist/src/index.js +56 -485
- package/dist/src/open-layout.d.ts +96 -0
- package/dist/src/open-layout.js +162 -0
- package/dist/src/panes.d.ts +2 -20
- package/dist/src/panes.js +4 -66
- package/dist/src/preset.d.ts +0 -1
- package/dist/src/preset.js +3 -6
- package/dist/src/shared.d.ts +2 -1
- package/dist/src/shared.js +2 -1
- package/dist/src/workspace.d.ts +13 -113
- package/dist/src/workspace.js +23 -185
- package/dist/src/worktrees.d.ts +67 -0
- package/dist/src/worktrees.js +223 -0
- package/package.json +5 -5
- package/dist/src/agent-host.d.ts +0 -45
- package/dist/src/agent-host.js +0 -9
- package/dist/src/agents.d.ts +0 -3
- package/dist/src/agents.js +0 -132
- package/dist/src/process-host.d.ts +0 -6
- package/dist/src/process-host.js +0 -46
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { OpenWorkspaceContext } from '@bakers-build/conductor/contract';
|
|
2
|
+
import type { ConductorLogger } from '@bakers-build/core';
|
|
3
|
+
import { type PaneSpec } from './config.js';
|
|
4
|
+
import { type HerdrExec } from './pane-layout.js';
|
|
5
|
+
/**
|
|
6
|
+
* Layout applied to a fresh worktree's initial (root) pane (BB-139): `command`
|
|
7
|
+
* launches a tool in the main pane (e.g. `spiceedit`) so the human lands in an
|
|
8
|
+
* editor instead of a bare shell; `panes[]` are optional splits off it. Same
|
|
9
|
+
* shape as the executor's per-state layout minus `tabLabel` — there is only ONE
|
|
10
|
+
* open layout, not a per-ticket-state map.
|
|
11
|
+
*
|
|
12
|
+
* BB-234: `{identifier}`, `{branch}`, `{title}` and `{worktreePath}` expand in
|
|
13
|
+
* `command` **and** in every `panes[].command`. The root command is rendered
|
|
14
|
+
* here before the finished layout reaches `applyPaneLayout` — that shared
|
|
15
|
+
* helper types its root command VERBATIM on purpose, because its other caller
|
|
16
|
+
* (the run tab) pre-assembles `KEY='value' <agent>` env prefixes whose values
|
|
17
|
+
* may legitimately contain braces (spec D2).
|
|
18
|
+
*
|
|
19
|
+
* BB-374: `tabLabel` / `panelLabel` are chrome strings applied after the
|
|
20
|
+
* layout via `herdr tab rename` / `herdr pane rename` ("panel label" = pane
|
|
21
|
+
* label). Defaults ship when keys are absent on an active layout; `open: {}`
|
|
22
|
+
* remains the full opt-out (no command, no splits, no labels). The overview
|
|
23
|
+
* **tab** default is `{identifier} · {title}` with `{title}` capped at
|
|
24
|
+
* {@link OPEN_TAB_TITLE_MAX} so the always-visible tab bar stays readable;
|
|
25
|
+
* the pane/panel label still gets the full title.
|
|
26
|
+
*
|
|
27
|
+
* Unset → {@link DEFAULT_OPEN_LAYOUT}, the ticket deep link. `{}` → the bare
|
|
28
|
+
* empty tab (`applyPaneLayout` issues no calls for an empty layout).
|
|
29
|
+
*/
|
|
30
|
+
export interface OpenLayout {
|
|
31
|
+
command?: string;
|
|
32
|
+
panes?: PaneSpec[];
|
|
33
|
+
/**
|
|
34
|
+
* Overview tab label template. Default: `{identifier} · {title}` (title
|
|
35
|
+
* truncated to {@link OPEN_TAB_TITLE_MAX} when rendering).
|
|
36
|
+
*/
|
|
37
|
+
tabLabel?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Overview root-pane label template (`herdr pane rename`). Default:
|
|
40
|
+
* `{identifier} · {title}` (full title).
|
|
41
|
+
*/
|
|
42
|
+
panelLabel?: string;
|
|
43
|
+
}
|
|
44
|
+
/** Max `{title}` length substituted into the overview **tab** label (BB-374). */
|
|
45
|
+
export declare const OPEN_TAB_TITLE_MAX = 30;
|
|
46
|
+
/** Cap overview-tab `{title}` and append `...` when truncated. */
|
|
47
|
+
export declare function truncateOpenTabTitle(title: string): string;
|
|
48
|
+
/** Default overview tab chrome (BB-374) — always-visible tab bar identity. */
|
|
49
|
+
export declare const DEFAULT_OPEN_TAB_LABEL = "{identifier} \u00B7 {title}";
|
|
50
|
+
/** Default overview pane/panel label template (BB-374). */
|
|
51
|
+
export declare const DEFAULT_OPEN_PANEL_LABEL = "{identifier} \u00B7 {title}";
|
|
52
|
+
/**
|
|
53
|
+
* The shipped default open layout (BB-234): a fresh worktree's initial pane
|
|
54
|
+
* renders the ticket it belongs to instead of an anonymous shell prompt.
|
|
55
|
+
*
|
|
56
|
+
* It lives in **code, not config**, because a default each repo has to opt into
|
|
57
|
+
* would leave the defect in place for every other consumer of this addon; the
|
|
58
|
+
* addon already ships opinionated defaults of this kind (`BUILTIN_DEFAULTS` in
|
|
59
|
+
* `./config.js`), and `bakers ui` is a command of the very host that ships it.
|
|
60
|
+
*
|
|
61
|
+
* `open: {}` is the documented opt-out back to the pre-BB-234 bare tab, so
|
|
62
|
+
* the default is not a one-way door.
|
|
63
|
+
*/
|
|
64
|
+
export declare const DEFAULT_OPEN_LAYOUT: OpenLayout;
|
|
65
|
+
/** `open: {}` — the opt-out back to the bare tab: no command, splits or labels. */
|
|
66
|
+
export declare function isEmptyLayout(open: OpenLayout): boolean;
|
|
67
|
+
/** A workspace's initial pane, and its tab when herdr reported one. */
|
|
68
|
+
export interface RootPane {
|
|
69
|
+
paneId: string;
|
|
70
|
+
tabId?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The root pane of a `worktree create`/`worktree open` response
|
|
74
|
+
* (`result.root_pane`, tab id from it or `result.tab`), or null when the
|
|
75
|
+
* response carries none.
|
|
76
|
+
*/
|
|
77
|
+
export declare function parseRootPane(output: string, command: string): RootPane | null;
|
|
78
|
+
/**
|
|
79
|
+
* The first pane of `herdr pane list --workspace <id>` — the initial pane of a
|
|
80
|
+
* workspace that was just created and has no other pane yet.
|
|
81
|
+
*
|
|
82
|
+
* shortcut: assumes `result.panes[]` with `pane_id`/`tab_id`, like `tab list`'s
|
|
83
|
+
* `result.tabs[]`; not yet confirmed against a live herdr, upgrade when the
|
|
84
|
+
* live check shows another shape.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseFirstPane(output: string): RootPane | null;
|
|
87
|
+
/**
|
|
88
|
+
* Apply `open` to a fresh worktree's root pane — by default (BB-234) the
|
|
89
|
+
* ticket's `bakers ui` deep link, so the tab shows the ticket instead of a
|
|
90
|
+
* bare shell. The splits get the worktree checkout as their cwd. BB-374 then
|
|
91
|
+
* renames the overview tab and root pane.
|
|
92
|
+
*
|
|
93
|
+
* Best-effort: a broken layout is logged and swallowed so a startup-command
|
|
94
|
+
* failure can NEVER wedge dispatch.
|
|
95
|
+
*/
|
|
96
|
+
export declare function applyOpenLayout(execHerdr: HerdrExec, logger: ConductorLogger, open: OpenLayout, root: RootPane, path: string, ctx: OpenWorkspaceContext): Promise<void>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { renderTemplate } from './config.js';
|
|
2
|
+
import { applyPaneLayout, isRecord, parseJson, } from './pane-layout.js';
|
|
3
|
+
/** Max `{title}` length substituted into the overview **tab** label (BB-374). */
|
|
4
|
+
export const OPEN_TAB_TITLE_MAX = 30;
|
|
5
|
+
/** Cap overview-tab `{title}` and append `...` when truncated. */
|
|
6
|
+
export function truncateOpenTabTitle(title) {
|
|
7
|
+
if (title.length <= OPEN_TAB_TITLE_MAX) {
|
|
8
|
+
return title;
|
|
9
|
+
}
|
|
10
|
+
return `${title.slice(0, OPEN_TAB_TITLE_MAX)}...`;
|
|
11
|
+
}
|
|
12
|
+
/** Default overview tab chrome (BB-374) — always-visible tab bar identity. */
|
|
13
|
+
export const DEFAULT_OPEN_TAB_LABEL = '{identifier} · {title}';
|
|
14
|
+
/** Default overview pane/panel label template (BB-374). */
|
|
15
|
+
export const DEFAULT_OPEN_PANEL_LABEL = '{identifier} · {title}';
|
|
16
|
+
/**
|
|
17
|
+
* The shipped default open layout (BB-234): a fresh worktree's initial pane
|
|
18
|
+
* renders the ticket it belongs to instead of an anonymous shell prompt.
|
|
19
|
+
*
|
|
20
|
+
* It lives in **code, not config**, because a default each repo has to opt into
|
|
21
|
+
* would leave the defect in place for every other consumer of this addon; the
|
|
22
|
+
* addon already ships opinionated defaults of this kind (`BUILTIN_DEFAULTS` in
|
|
23
|
+
* `./config.js`), and `bakers ui` is a command of the very host that ships it.
|
|
24
|
+
*
|
|
25
|
+
* `open: {}` is the documented opt-out back to the pre-BB-234 bare tab, so
|
|
26
|
+
* the default is not a one-way door.
|
|
27
|
+
*/
|
|
28
|
+
export const DEFAULT_OPEN_LAYOUT = {
|
|
29
|
+
command: 'bakers ui --ticket {identifier}',
|
|
30
|
+
tabLabel: DEFAULT_OPEN_TAB_LABEL,
|
|
31
|
+
panelLabel: DEFAULT_OPEN_PANEL_LABEL,
|
|
32
|
+
};
|
|
33
|
+
/** `open: {}` — the opt-out back to the bare tab: no command, splits or labels. */
|
|
34
|
+
export function isEmptyLayout(open) {
|
|
35
|
+
return (open.command === undefined &&
|
|
36
|
+
!open.panes?.length &&
|
|
37
|
+
open.tabLabel === undefined &&
|
|
38
|
+
open.panelLabel === undefined);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The root pane of a `worktree create`/`worktree open` response
|
|
42
|
+
* (`result.root_pane`, tab id from it or `result.tab`), or null when the
|
|
43
|
+
* response carries none.
|
|
44
|
+
*/
|
|
45
|
+
export function parseRootPane(output, command) {
|
|
46
|
+
const parsed = parseJson(output, command);
|
|
47
|
+
if (!isRecord(parsed) || !isRecord(parsed.result))
|
|
48
|
+
return null;
|
|
49
|
+
const result = parsed.result;
|
|
50
|
+
const paneId = result.root_pane?.pane_id;
|
|
51
|
+
if (typeof paneId !== 'string' || !paneId)
|
|
52
|
+
return null;
|
|
53
|
+
const tabIdRaw = result.root_pane?.tab_id ?? result.tab?.tab_id;
|
|
54
|
+
const tabId = typeof tabIdRaw === 'string' && tabIdRaw ? tabIdRaw : undefined;
|
|
55
|
+
return tabId !== undefined ? { paneId, tabId } : { paneId };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The first pane of `herdr pane list --workspace <id>` — the initial pane of a
|
|
59
|
+
* workspace that was just created and has no other pane yet.
|
|
60
|
+
*
|
|
61
|
+
* shortcut: assumes `result.panes[]` with `pane_id`/`tab_id`, like `tab list`'s
|
|
62
|
+
* `result.tabs[]`; not yet confirmed against a live herdr, upgrade when the
|
|
63
|
+
* live check shows another shape.
|
|
64
|
+
*/
|
|
65
|
+
export function parseFirstPane(output) {
|
|
66
|
+
const parsed = parseJson(output, 'pane list');
|
|
67
|
+
const panes = isRecord(parsed)
|
|
68
|
+
? parsed.result?.panes
|
|
69
|
+
: undefined;
|
|
70
|
+
if (!Array.isArray(panes))
|
|
71
|
+
return null;
|
|
72
|
+
const first = panes.find((p) => isRecord(p) && typeof p.pane_id === 'string' && p.pane_id);
|
|
73
|
+
if (!first)
|
|
74
|
+
return null;
|
|
75
|
+
return typeof first.tab_id === 'string' && first.tab_id
|
|
76
|
+
? { paneId: first.pane_id, tabId: first.tab_id }
|
|
77
|
+
: { paneId: first.pane_id };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Apply `open` to a fresh worktree's root pane — by default (BB-234) the
|
|
81
|
+
* ticket's `bakers ui` deep link, so the tab shows the ticket instead of a
|
|
82
|
+
* bare shell. The splits get the worktree checkout as their cwd. BB-374 then
|
|
83
|
+
* renames the overview tab and root pane.
|
|
84
|
+
*
|
|
85
|
+
* Best-effort: a broken layout is logged and swallowed so a startup-command
|
|
86
|
+
* failure can NEVER wedge dispatch.
|
|
87
|
+
*/
|
|
88
|
+
export async function applyOpenLayout(execHerdr, logger, open, root, path, ctx) {
|
|
89
|
+
try {
|
|
90
|
+
// Render the ROOT command here (spec D2). `applyPaneLayout` types its
|
|
91
|
+
// root command verbatim for the run tab's brace-bearing env-prefixed
|
|
92
|
+
// agent command, so templating it there would corrupt that; the split
|
|
93
|
+
// commands it already renders from the same `vars`.
|
|
94
|
+
const vars = {
|
|
95
|
+
identifier: ctx.identifier,
|
|
96
|
+
branch: ctx.branch,
|
|
97
|
+
title: ctx.title,
|
|
98
|
+
worktreePath: path,
|
|
99
|
+
};
|
|
100
|
+
const layout = {
|
|
101
|
+
...open,
|
|
102
|
+
...(open.command !== undefined
|
|
103
|
+
? { command: renderTemplate(open.command, vars) }
|
|
104
|
+
: {}),
|
|
105
|
+
};
|
|
106
|
+
await applyPaneLayout(execHerdr, root.paneId, layout, path, vars);
|
|
107
|
+
await applyOverviewLabels(execHerdr, logger, open, root, vars);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
logger.warn({ branch: ctx.branch, worktree: path, err: String(err) }, 'herdr open-layout failed (best-effort, ignored)');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Best-effort overview tab + pane renames (BB-374). Skipped for the
|
|
115
|
+
* `open: {}` opt-out. A missing tab id falls back to `pane get`.
|
|
116
|
+
*/
|
|
117
|
+
async function applyOverviewLabels(execHerdr, logger, open, root, vars) {
|
|
118
|
+
if (isEmptyLayout(open)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Tab bar is always visible; cap title length and mark truncation with
|
|
122
|
+
// `...`. Pane/panel label keeps the full title for pane borders.
|
|
123
|
+
const tabVars = {
|
|
124
|
+
...vars,
|
|
125
|
+
title: truncateOpenTabTitle(vars.title ?? ''),
|
|
126
|
+
};
|
|
127
|
+
const tabLabel = renderTemplate(open.tabLabel ?? DEFAULT_OPEN_TAB_LABEL, tabVars);
|
|
128
|
+
const panelLabel = renderTemplate(open.panelLabel ?? DEFAULT_OPEN_PANEL_LABEL, vars);
|
|
129
|
+
let tabId = root.tabId;
|
|
130
|
+
if (!tabId) {
|
|
131
|
+
try {
|
|
132
|
+
tabId = (await resolveTabIdForPane(execHerdr, root.paneId)) ?? undefined;
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
logger.warn({ paneId: root.paneId, err: String(err) }, 'herdr overview tab id lookup failed (best-effort, ignored)');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (tabId) {
|
|
139
|
+
try {
|
|
140
|
+
await execHerdr(['tab', 'rename', tabId, tabLabel]);
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
logger.warn({ tabId, err: String(err) }, 'herdr overview tab rename failed (best-effort, ignored)');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
await execHerdr(['pane', 'rename', root.paneId, panelLabel]);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
logger.warn({ paneId: root.paneId, err: String(err) }, 'herdr overview pane rename failed (best-effort, ignored)');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** `pane get <id>` → `result.pane.tab_id` when present. */
|
|
154
|
+
async function resolveTabIdForPane(execHerdr, paneId) {
|
|
155
|
+
const output = await execHerdr(['pane', 'get', paneId, '--json']);
|
|
156
|
+
const parsed = parseJson(output, 'pane get');
|
|
157
|
+
const tabId = isRecord(parsed)
|
|
158
|
+
? parsed.result?.pane
|
|
159
|
+
?.tab_id
|
|
160
|
+
: undefined;
|
|
161
|
+
return typeof tabId === 'string' && tabId ? tabId : null;
|
|
162
|
+
}
|
package/dist/src/panes.d.ts
CHANGED
|
@@ -1,31 +1,13 @@
|
|
|
1
|
-
/** A herdr pane and the tab it sits in. */
|
|
2
|
-
export interface HerdrPaneRef {
|
|
3
|
-
paneId: string;
|
|
4
|
-
tabId: string;
|
|
5
|
-
}
|
|
6
|
-
/** A herdr pane plus its label. */
|
|
7
|
-
export interface HerdrPaneInfo extends HerdrPaneRef {
|
|
8
|
-
label: string;
|
|
9
|
-
}
|
|
10
1
|
/**
|
|
11
2
|
* Marker exported into an AGENT pane's interactive shell, so a user's opt-in
|
|
12
3
|
* shell init can recognise an agent-run pane at startup and isolate its history
|
|
13
4
|
* (BB-64). It is a plain `BB_*` env entry on purpose: it rides {@link envArgs}
|
|
14
5
|
* like every other pane var instead of adding a second mechanism.
|
|
15
6
|
*
|
|
16
|
-
* AGENT panes only — the executor's per-run tab and its layout panes
|
|
17
|
-
*
|
|
18
|
-
* human's landing pane, and the opt-in unsets `HISTFILE`. See
|
|
7
|
+
* AGENT panes only — the executor's per-run tab and its layout panes. NOT the
|
|
8
|
+
* workspace's own open-layout pane: that one is the human's landing pane, and the opt-in unsets `HISTFILE`. See
|
|
19
9
|
* `docs/conductor/node.md` § Agent-pane shell marker.
|
|
20
10
|
*/
|
|
21
11
|
export declare const AGENT_SHELL_ENV: Record<string, string>;
|
|
22
12
|
/** BB_* env vars as `--env KEY=VALUE` args (never dump the full environment). */
|
|
23
13
|
export declare function envArgs(env: Record<string, string | undefined>): string[];
|
|
24
|
-
/** `{ paneId, tabId }` from a `herdr tab create` envelope. */
|
|
25
|
-
export declare function parseTabCreate(output: string): HerdrPaneRef;
|
|
26
|
-
/** `{ paneId, tabId }` from a `result.pane` envelope (pane current / split). */
|
|
27
|
-
export declare function parsePaneInfo(output: string): HerdrPaneRef;
|
|
28
|
-
/** The id of the first tab whose label equals `label`, else null. */
|
|
29
|
-
export declare function findTabIdByLabel(output: string, label: string): string | null;
|
|
30
|
-
/** Panes in `tabId` as `[{ paneId, tabId, label }]` from a `pane list` envelope. */
|
|
31
|
-
export declare function parsePanesInTab(output: string, tabId: string): HerdrPaneInfo[];
|
package/dist/src/panes.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
// Herdr pane
|
|
2
|
-
//
|
|
3
|
-
// and herdr-internal; the conductor/TUI never see these pane shapes.
|
|
4
|
-
function isRecord(v) {
|
|
5
|
-
return typeof v === 'object' && v !== null;
|
|
6
|
-
}
|
|
1
|
+
// Herdr pane env helpers (BB-190, BB-64): the agent-shell marker and the
|
|
2
|
+
// `--env` args every pane launch passes. Kept small and herdr-internal.
|
|
7
3
|
/**
|
|
8
4
|
* Marker exported into an AGENT pane's interactive shell, so a user's opt-in
|
|
9
5
|
* shell init can recognise an agent-run pane at startup and isolate its history
|
|
10
6
|
* (BB-64). It is a plain `BB_*` env entry on purpose: it rides {@link envArgs}
|
|
11
7
|
* like every other pane var instead of adding a second mechanism.
|
|
12
8
|
*
|
|
13
|
-
* AGENT panes only — the executor's per-run tab and its layout panes
|
|
14
|
-
*
|
|
15
|
-
* human's landing pane, and the opt-in unsets `HISTFILE`. See
|
|
9
|
+
* AGENT panes only — the executor's per-run tab and its layout panes. NOT the
|
|
10
|
+
* workspace's own open-layout pane: that one is the human's landing pane, and the opt-in unsets `HISTFILE`. See
|
|
16
11
|
* `docs/conductor/node.md` § Agent-pane shell marker.
|
|
17
12
|
*/
|
|
18
13
|
export const AGENT_SHELL_ENV = {
|
|
@@ -28,60 +23,3 @@ export function envArgs(env) {
|
|
|
28
23
|
}
|
|
29
24
|
return out;
|
|
30
25
|
}
|
|
31
|
-
/** `{ paneId, tabId }` from a `herdr tab create` envelope. */
|
|
32
|
-
export function parseTabCreate(output) {
|
|
33
|
-
const parsed = JSON.parse(output);
|
|
34
|
-
const result = isRecord(parsed)
|
|
35
|
-
? parsed.result
|
|
36
|
-
: undefined;
|
|
37
|
-
const paneId = result?.root_pane?.pane_id;
|
|
38
|
-
const tabId = result?.tab?.tab_id;
|
|
39
|
-
if (typeof paneId !== 'string' || typeof tabId !== 'string') {
|
|
40
|
-
throw new Error('herdr tab create returned invalid schema');
|
|
41
|
-
}
|
|
42
|
-
return { paneId, tabId };
|
|
43
|
-
}
|
|
44
|
-
/** `{ paneId, tabId }` from a `result.pane` envelope (pane current / split). */
|
|
45
|
-
export function parsePaneInfo(output) {
|
|
46
|
-
const parsed = JSON.parse(output);
|
|
47
|
-
const pane = isRecord(parsed)
|
|
48
|
-
? parsed.result
|
|
49
|
-
?.pane
|
|
50
|
-
: undefined;
|
|
51
|
-
const paneId = pane?.pane_id;
|
|
52
|
-
const tabId = pane?.tab_id;
|
|
53
|
-
if (typeof paneId !== 'string' || typeof tabId !== 'string') {
|
|
54
|
-
throw new Error('herdr returned no pane info');
|
|
55
|
-
}
|
|
56
|
-
return { paneId, tabId };
|
|
57
|
-
}
|
|
58
|
-
/** The id of the first tab whose label equals `label`, else null. */
|
|
59
|
-
export function findTabIdByLabel(output, label) {
|
|
60
|
-
const parsed = JSON.parse(output);
|
|
61
|
-
const tabs = isRecord(parsed)
|
|
62
|
-
? parsed.result?.tabs
|
|
63
|
-
: undefined;
|
|
64
|
-
if (!Array.isArray(tabs))
|
|
65
|
-
return null;
|
|
66
|
-
const match = tabs
|
|
67
|
-
.filter(isRecord)
|
|
68
|
-
.find((t) => t.label === label && typeof t.tab_id === 'string');
|
|
69
|
-
return match ? match.tab_id : null;
|
|
70
|
-
}
|
|
71
|
-
/** Panes in `tabId` as `[{ paneId, tabId, label }]` from a `pane list` envelope. */
|
|
72
|
-
export function parsePanesInTab(output, tabId) {
|
|
73
|
-
const parsed = JSON.parse(output);
|
|
74
|
-
const panes = isRecord(parsed)
|
|
75
|
-
? parsed.result?.panes
|
|
76
|
-
: undefined;
|
|
77
|
-
if (!Array.isArray(panes))
|
|
78
|
-
return [];
|
|
79
|
-
return panes
|
|
80
|
-
.filter(isRecord)
|
|
81
|
-
.filter((p) => typeof p.pane_id === 'string' && p.tab_id === tabId)
|
|
82
|
-
.map((p) => ({
|
|
83
|
-
paneId: p.pane_id,
|
|
84
|
-
tabId,
|
|
85
|
-
label: typeof p.label === 'string' ? p.label : '',
|
|
86
|
-
}));
|
|
87
|
-
}
|
package/dist/src/preset.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Preset } from '@bakers-build/conductor/contract';
|
|
2
2
|
export declare const executors: Preset['executors'];
|
|
3
3
|
export declare const workspaces: Preset['workspaces'];
|
|
4
|
-
export declare const processHosts: Preset['processHosts'];
|
|
5
4
|
export declare const hooks: Preset['hooks'];
|
|
6
5
|
export declare const scopes: Preset['scopes'];
|
package/dist/src/preset.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { herdrFrozenMarker } from './frozen-marker.js';
|
|
2
2
|
import { herdrExecutor, herdrWorkspace } from './index.js';
|
|
3
|
-
import { herdrProcessHost } from './process-host.js';
|
|
4
3
|
export const executors = (acc, opts) => [
|
|
5
4
|
...acc,
|
|
6
5
|
herdrExecutor(opts),
|
|
@@ -9,10 +8,8 @@ export const workspaces = (acc, opts) => [
|
|
|
9
8
|
...acc,
|
|
10
9
|
herdrWorkspace(opts),
|
|
11
10
|
];
|
|
12
|
-
export const processHosts = (acc) => [
|
|
13
|
-
...acc,
|
|
14
|
-
herdrProcessHost,
|
|
15
|
-
];
|
|
16
11
|
export const hooks = (acc) => [...acc, herdrFrozenMarker];
|
|
17
|
-
// Hook listeners
|
|
12
|
+
// Hook listeners belong to one project (no machine hook listeners, BB-599). A
|
|
13
|
+
// machine picks herdr as its executor through the machine.config.js `executor`
|
|
14
|
+
// slot instead.
|
|
18
15
|
export const scopes = ['project'];
|
package/dist/src/shared.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { renderTemplate } from './config.js';
|
|
2
2
|
export { restoreWritable } from './fs.js';
|
|
3
3
|
export { type LaunchScript, type LaunchWatchOptions, watchLaunch, writeLaunchScript, } from './launch-script.js';
|
|
4
|
-
export { truncateOpenTabTitle
|
|
4
|
+
export { truncateOpenTabTitle } from './open-layout.js';
|
|
5
|
+
export { validateBranch } from './workspace.js';
|
|
5
6
|
/** Runs `git <args>`; resolves with stdout, rejects on non-zero exit. */
|
|
6
7
|
export type BaseRefGitExec = (args: string[]) => Promise<string>;
|
|
7
8
|
/**
|
package/dist/src/shared.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
export { renderTemplate } from './config.js';
|
|
5
5
|
export { restoreWritable } from './fs.js';
|
|
6
6
|
export { watchLaunch, writeLaunchScript, } from './launch-script.js';
|
|
7
|
-
export { truncateOpenTabTitle
|
|
7
|
+
export { truncateOpenTabTitle } from './open-layout.js';
|
|
8
|
+
export { validateBranch } from './workspace.js';
|
|
8
9
|
/**
|
|
9
10
|
* Resolve (and fetch) the base ref a NEW worktree branch is created from, so a
|
|
10
11
|
* run starts from the pushed remote state, not the host's local branch.
|
package/dist/src/workspace.d.ts
CHANGED
|
@@ -1,70 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type WorktreeGitExec } from '@bakers-build/addon-workspace-git';
|
|
2
|
+
import type { BbWorkspace, EnsuredWorkspace, WorkspacePlugin, WorktreeTeardown } from '@bakers-build/conductor/contract';
|
|
2
3
|
import type { ConductorLogger } from '@bakers-build/core';
|
|
3
|
-
import type { AgentLaunchHost } from './agent-host.js';
|
|
4
|
-
import { type PaneSpec } from './config.js';
|
|
5
4
|
import { type RootGitExec } from './root-anchor.js';
|
|
6
5
|
export type HerdrExec = (args: string[]) => Promise<string>;
|
|
7
6
|
export type GitExec = (args: string[]) => Promise<string>;
|
|
8
|
-
/**
|
|
9
|
-
* Layout applied to the workspace's initial (root) pane on a FRESH worktree open
|
|
10
|
-
* (BB-139): `command` launches a tool in the main pane (e.g. `spiceedit`) so
|
|
11
|
-
* the human lands in an editor instead of a bare shell; `panes[]` are optional
|
|
12
|
-
* splits off it. Same shape as the executor's per-state layout minus `tabLabel`
|
|
13
|
-
* — there is only ONE open layout, not a per-ticket-state map.
|
|
14
|
-
*
|
|
15
|
-
* BB-234: `{identifier}`, `{branch}` and `{worktreePath}` expand in `command`
|
|
16
|
-
* **and** in every `panes[].command`. The root command is rendered here, by
|
|
17
|
-
* `ensure`, before the finished layout reaches `applyPaneLayout` — that shared
|
|
18
|
-
* helper types its root command VERBATIM on purpose, because its other caller
|
|
19
|
-
* (the executor) pre-assembles `KEY='value' <agent>` env prefixes whose values
|
|
20
|
-
* may legitimately contain braces (spec D2).
|
|
21
|
-
*
|
|
22
|
-
* BB-374: `tabLabel` / `panelLabel` are chrome strings applied after the
|
|
23
|
-
* layout via `herdr tab rename` / `herdr pane rename` ("panel label" = pane
|
|
24
|
-
* label). Defaults ship when keys are absent on an active layout; `open: {}`
|
|
25
|
-
* remains the full opt-out (no command, no splits, no labels). The overview
|
|
26
|
-
* **tab** default is `{identifier} · {title}` with `{title}` capped at
|
|
27
|
-
* {@link OPEN_TAB_TITLE_MAX} so the always-visible tab bar stays readable;
|
|
28
|
-
* the pane/panel label still gets the full title.
|
|
29
|
-
*
|
|
30
|
-
* Unset → {@link DEFAULT_OPEN_LAYOUT}, the ticket deep link. `{}` → the bare
|
|
31
|
-
* empty tab (`applyPaneLayout` issues no calls for an empty layout).
|
|
32
|
-
*/
|
|
33
|
-
export interface OpenLayout {
|
|
34
|
-
command?: string;
|
|
35
|
-
panes?: PaneSpec[];
|
|
36
|
-
/**
|
|
37
|
-
* Overview tab label template. Default: `{identifier} · {title}` (title
|
|
38
|
-
* truncated to {@link OPEN_TAB_TITLE_MAX} when rendering).
|
|
39
|
-
*/
|
|
40
|
-
tabLabel?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Overview root-pane label template (`herdr pane rename`). Default:
|
|
43
|
-
* `{identifier} · {title}` (full title).
|
|
44
|
-
*/
|
|
45
|
-
panelLabel?: string;
|
|
46
|
-
}
|
|
47
|
-
/** Max `{title}` length substituted into the overview **tab** label (BB-374). */
|
|
48
|
-
export declare const OPEN_TAB_TITLE_MAX = 30;
|
|
49
|
-
/** Cap overview-tab `{title}` and append `...` when truncated. */
|
|
50
|
-
export declare function truncateOpenTabTitle(title: string): string;
|
|
51
|
-
/** Default overview tab chrome (BB-374) — always-visible tab bar identity. */
|
|
52
|
-
export declare const DEFAULT_OPEN_TAB_LABEL = "{identifier} \u00B7 {title}";
|
|
53
|
-
/** Default overview pane/panel label template (BB-374). */
|
|
54
|
-
export declare const DEFAULT_OPEN_PANEL_LABEL = "{identifier} \u00B7 {title}";
|
|
55
|
-
/**
|
|
56
|
-
* The shipped default open layout (BB-234): a fresh worktree's initial pane
|
|
57
|
-
* renders the ticket it belongs to instead of an anonymous shell prompt.
|
|
58
|
-
*
|
|
59
|
-
* It lives in **code, not config**, because a default each repo has to opt into
|
|
60
|
-
* would leave the defect in place for every other consumer of this addon; the
|
|
61
|
-
* addon already ships opinionated defaults of this kind (`BUILTIN_DEFAULTS` in
|
|
62
|
-
* `./config.js`), and `bakers ui` is a command of the very host that ships it.
|
|
63
|
-
*
|
|
64
|
-
* `open: {}` is the documented opt-out back to the pre-BB-234 bare tab, so
|
|
65
|
-
* the default is not a one-way door.
|
|
66
|
-
*/
|
|
67
|
-
export declare const DEFAULT_OPEN_LAYOUT: OpenLayout;
|
|
68
7
|
export interface HerdrWorkspaceOptions {
|
|
69
8
|
/** Main clone (a git repo): herdr `--cwd` target + worktree base. */
|
|
70
9
|
root: string;
|
|
@@ -76,17 +15,13 @@ export interface HerdrWorkspaceOptions {
|
|
|
76
15
|
* so runs start from the pushed remote state, not the host's local branch.
|
|
77
16
|
*/
|
|
78
17
|
baseBranch?: string;
|
|
79
|
-
/**
|
|
80
|
-
* Startup layout for the initial pane, applied on a FRESH worktree open only
|
|
81
|
-
* (BB-139). Unset → {@link DEFAULT_OPEN_LAYOUT} (`bakers ui --ticket <ID>`,
|
|
82
|
-
* BB-234); `{}` → the bare empty tab is left unchanged.
|
|
83
|
-
*/
|
|
84
|
-
open?: OpenLayout;
|
|
85
18
|
/** Overrideable herdr exec fn — defaults to the real `herdr` binary. */
|
|
86
19
|
execHerdr?: HerdrExec;
|
|
87
20
|
/** Overrideable git exec fn — defaults to the real `git` binary. */
|
|
88
21
|
execGit?: GitExec;
|
|
89
|
-
/**
|
|
22
|
+
/** Overrideable git runner in a cwd, for the teardown fallback. */
|
|
23
|
+
runGit?: WorktreeGitExec;
|
|
24
|
+
/** Optional logger for the teardown (defaults to noop). */
|
|
90
25
|
logger?: ConductorLogger;
|
|
91
26
|
/**
|
|
92
27
|
* Default `false`: before creating a worktree, set `branch.autoSetupMerge=false`
|
|
@@ -102,23 +37,15 @@ export declare class HerdrWorkspace implements BbWorkspace {
|
|
|
102
37
|
private readonly execGit;
|
|
103
38
|
private readonly root;
|
|
104
39
|
private readonly worktreeDir;
|
|
105
|
-
private readonly open;
|
|
106
40
|
private readonly logger;
|
|
107
|
-
|
|
108
|
-
* Root panes captured by a FRESH `ensure` create, keyed by worktree path,
|
|
109
|
-
* awaiting {@link applyOpenLayout} (BB-237). One-shot: consumed on apply.
|
|
110
|
-
* Optional `tabId` powers the BB-374 overview tab rename.
|
|
111
|
-
*/
|
|
112
|
-
private readonly pendingRootPanes;
|
|
113
|
-
/** Herdr-backed intent-level agent host for `bakers ui` (BB-190). */
|
|
114
|
-
readonly agentHost: AgentLaunchHost;
|
|
41
|
+
private readonly runGit;
|
|
115
42
|
constructor(options: HerdrWorkspaceOptions);
|
|
116
43
|
/**
|
|
117
44
|
* Ensure the branch's worktree + herdr workspace exist.
|
|
118
45
|
*
|
|
119
|
-
* `_identifier` is unused HERE: the worktree is located by branch, and
|
|
120
|
-
*
|
|
121
|
-
*
|
|
46
|
+
* `_identifier` is unused HERE: the worktree is located by branch, and the
|
|
47
|
+
* open layout — the one thing that consumed the identifier, to render
|
|
48
|
+
* `{identifier}` (BB-234) — is applied by `HerdrExecutor.openWorkspace`,
|
|
122
49
|
* which takes it on its own `ctx`. The parameter stays because it is the
|
|
123
50
|
* `BbWorkspace.ensure` contract position (the git workspace does use it).
|
|
124
51
|
* It is still taken as-passed rather than parsed back out of `branch`, which
|
|
@@ -126,37 +53,11 @@ export declare class HerdrWorkspace implements BbWorkspace {
|
|
|
126
53
|
*/
|
|
127
54
|
ensure(_identifier: string, branch?: string, baseRefOverride?: string): Promise<EnsuredWorkspace>;
|
|
128
55
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* The pane's cwd is the worktree checkout, passed explicitly on the splits
|
|
133
|
-
* (the root pane's cwd is already the checkout).
|
|
134
|
-
*
|
|
135
|
-
* BB-374 then renames the overview tab (`{identifier} · {title}` with title
|
|
136
|
-
* capped at {@link OPEN_TAB_TITLE_MAX}) and root pane (full
|
|
137
|
-
* `{identifier} · {title}`) — fresh-create only, same gate as the layout.
|
|
138
|
-
*
|
|
139
|
-
* NO stored pane ⇒ silent no-op. That is the reused-worktree case: `ensure`
|
|
140
|
-
* took the reuse branch, there is no fresh root pane, and re-applying would
|
|
141
|
-
* start a duplicate editor process on reattach (BB-139). The capture is
|
|
142
|
-
* one-shot — consumed here — so a repeat call cannot double-apply and the map
|
|
143
|
-
* cannot grow without bound.
|
|
144
|
-
*
|
|
145
|
-
* Best-effort — mirrors the `fetchBaseRef` pattern: a broken layout is logged
|
|
146
|
-
* and swallowed so a startup-command failure can NEVER wedge dispatch.
|
|
147
|
-
*/
|
|
148
|
-
applyOpenLayout(path: string, ctx: {
|
|
149
|
-
identifier: string;
|
|
150
|
-
branch: string;
|
|
151
|
-
title: string;
|
|
152
|
-
}): Promise<void>;
|
|
153
|
-
/**
|
|
154
|
-
* Best-effort overview tab + pane renames (BB-374). Skipped for the
|
|
155
|
-
* `open: {}` opt-out. A missing create-time tab id falls back to `pane get`.
|
|
56
|
+
* Tear down the branch's worktree and its herdr workspace
|
|
57
|
+
* (`herdr worktree remove --force`); a worktree herdr no longer tracks is
|
|
58
|
+
* torn down with git alone. See {@link removeHerdrWorktree}.
|
|
156
59
|
*/
|
|
157
|
-
|
|
158
|
-
/** `pane get <id>` → `result.pane.tab_id` when present. */
|
|
159
|
-
private resolveTabIdForPane;
|
|
60
|
+
remove(branch: string, worktreePath?: string): Promise<WorktreeTeardown>;
|
|
160
61
|
}
|
|
161
62
|
export declare function herdrWorkspace(opts?: {
|
|
162
63
|
/**
|
|
@@ -166,7 +67,6 @@ export declare function herdrWorkspace(opts?: {
|
|
|
166
67
|
root?: string;
|
|
167
68
|
worktreeDir?: string;
|
|
168
69
|
baseBranch?: string;
|
|
169
|
-
open?: OpenLayout;
|
|
170
70
|
autoSetupMerge?: boolean;
|
|
171
71
|
/** Overrideable git exec for root derivation (tests). */
|
|
172
72
|
execGit?: RootGitExec;
|