@bakers-build/addon-herdr-core 0.9.1-next.5 → 0.9.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/index.d.ts +11 -3
- package/dist/src/index.js +31 -21
- package/dist/src/preset.d.ts +1 -0
- package/dist/src/preset.js +1 -0
- package/dist/src/resize-forwarding.d.ts +1 -0
- package/dist/src/resize-forwarding.js +66 -0
- package/package.json +6 -5
package/dist/src/index.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { type LaunchWatchOptions } from '@bakers-build/addon-herdr/shared';
|
|
2
2
|
import type { BbExecutor, ExecutorCapabilities, ExecutorPlugin, SpawnedSession, SpawnRunInput } from '@bakers-build/conductor/contract';
|
|
3
3
|
import { type ConductorLogger } from '@bakers-build/core';
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Runs `hc <args>` with optional stdin; resolves with stdout, rejects on a
|
|
6
|
+
* non-zero exit.
|
|
7
|
+
*/
|
|
8
|
+
export type HcExec = (args: string[], input?: string) => Promise<string>;
|
|
6
9
|
export interface HerdrCoreExecutorOptions {
|
|
7
10
|
/** Fallback agent command when the conductor supplies none. Default `claude`. */
|
|
8
11
|
command?: string;
|
|
9
12
|
/** As for herdr: `start_timeout_ms` (default 60 s), then `timeout_ms` (4 s). */
|
|
10
13
|
launch_watch?: Omit<LaunchWatchOptions, 'readPane'>;
|
|
11
14
|
}
|
|
12
|
-
/** The oldest `hc` whose `run
|
|
15
|
+
/** The oldest `hc` whose `terminal.run` (`no_parent`, `outlive_parent`, `size`) this addon uses. */
|
|
13
16
|
export declare const MIN_HC_VERSION = "0.1.18";
|
|
14
17
|
/** `hc` is not on PATH. */
|
|
15
18
|
export declare class HcNotFound extends Error {
|
|
@@ -48,6 +51,11 @@ export declare class HerdrCoreExecutor implements BbExecutor {
|
|
|
48
51
|
* leave an agent running.
|
|
49
52
|
*/
|
|
50
53
|
cleanupRun(branch: string, runId: number): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* One `terminal.run` over `hc connect`, the background start (`run --bg`).
|
|
56
|
+
* hc answers an error with exit 0, so the reply decides.
|
|
57
|
+
*/
|
|
58
|
+
private terminalRun;
|
|
51
59
|
/** `hc kill` (when live) then `hc rm`; each step best-effort. */
|
|
52
60
|
private drop;
|
|
53
61
|
private commandFor;
|
package/dist/src/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
2
3
|
import { watchLaunch, writeLaunchScript, } from '@bakers-build/addon-herdr/shared';
|
|
3
4
|
import { ExecError, exec, shellQuote, } from '@bakers-build/core';
|
|
4
|
-
/** The oldest `hc` whose `run
|
|
5
|
+
/** The oldest `hc` whose `terminal.run` (`no_parent`, `outlive_parent`, `size`) this addon uses. */
|
|
5
6
|
export const MIN_HC_VERSION = '0.1.18';
|
|
6
7
|
/** `hc` is not on PATH. */
|
|
7
8
|
export class HcNotFound extends Error {
|
|
@@ -11,9 +12,9 @@ export class HcNotFound extends Error {
|
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
/** The real CLI, resolved through PATH. */
|
|
14
|
-
export const defaultHc = async (args) => {
|
|
15
|
+
export const defaultHc = async (args, input) => {
|
|
15
16
|
try {
|
|
16
|
-
return await exec('hc', args);
|
|
17
|
+
return await exec('hc', args, input === undefined ? {} : { input });
|
|
17
18
|
}
|
|
18
19
|
catch (err) {
|
|
19
20
|
const cause = (err instanceof ExecError ? err.cause : err);
|
|
@@ -22,6 +23,8 @@ export const defaultHc = async (args) => {
|
|
|
22
23
|
throw err;
|
|
23
24
|
}
|
|
24
25
|
};
|
|
26
|
+
/** Built beside this module; forwards pane resizes to a sandboxed agent. */
|
|
27
|
+
const RESIZE_FORWARDER = fileURLToPath(new URL('./resize-forwarding.js', import.meta.url));
|
|
25
28
|
const noopLogger = {
|
|
26
29
|
debug() { },
|
|
27
30
|
info() { },
|
|
@@ -101,25 +104,21 @@ export class HerdrCoreExecutor {
|
|
|
101
104
|
try {
|
|
102
105
|
// The run's env travels inside the 0600 launch script, never in argv.
|
|
103
106
|
launch = writeLaunchScript(this.commandFor(input));
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
'
|
|
108
|
-
|
|
109
|
-
'--cwd',
|
|
110
|
-
input.workspacePath,
|
|
111
|
-
'--name',
|
|
107
|
+
// hc's CLI cannot set the start size, its API can: hc's headless default
|
|
108
|
+
// (200x120) rewraps the agent's first draw in any smaller pane.
|
|
109
|
+
await this.terminalRun({
|
|
110
|
+
argv: [process.execPath, RESIZE_FORWARDER, 'sh', launch.wrapPath],
|
|
111
|
+
cwd: input.workspacePath,
|
|
112
112
|
name,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
]);
|
|
113
|
+
labels: {
|
|
114
|
+
'bakers.branch': input.ticket.branchName,
|
|
115
|
+
'bakers.run': String(input.run.id),
|
|
116
|
+
'bakers.ticket': input.ticket.identifier,
|
|
117
|
+
},
|
|
118
|
+
no_parent: true,
|
|
119
|
+
outlive_parent: true,
|
|
120
|
+
size: { cols: 80, rows: 24 },
|
|
121
|
+
});
|
|
123
122
|
started = true;
|
|
124
123
|
await watchLaunch(launch, {
|
|
125
124
|
...(this.options.launch_watch ?? {}),
|
|
@@ -165,6 +164,17 @@ export class HerdrCoreExecutor {
|
|
|
165
164
|
this.logger.warn({ branch, runId, err: String(err) }, 'herdr-core cleanup failed (best-effort)');
|
|
166
165
|
}
|
|
167
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* One `terminal.run` over `hc connect`, the background start (`run --bg`).
|
|
169
|
+
* hc answers an error with exit 0, so the reply decides.
|
|
170
|
+
*/
|
|
171
|
+
async terminalRun(params) {
|
|
172
|
+
const reply = JSON.parse(await this.hc(['connect', '--json'], `${JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'terminal.run', params })}\n`));
|
|
173
|
+
if (reply.error) {
|
|
174
|
+
const kind = reply.error.data?.kind ?? 'error';
|
|
175
|
+
throw new Error(`hc terminal.run failed (${kind}): ${reply.error.message ?? 'no message'}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
168
178
|
/** `hc kill` (when live) then `hc rm`; each step best-effort. */
|
|
169
179
|
async drop(terminal, live) {
|
|
170
180
|
if (live) {
|
package/dist/src/preset.d.ts
CHANGED
package/dist/src/preset.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node resize-forwarding.js <cmd> [args...]`: runs the command on this
|
|
3
|
+
* terminal and passes every SIGWINCH on to all its descendants. The kernel
|
|
4
|
+
* sends SIGWINCH only to the pty's foreground process group, so an agent in
|
|
5
|
+
* its own session (bwrap `--new-session`) would never redraw on a resize.
|
|
6
|
+
* Exits with the command's code, or 128+n when signal n ended it.
|
|
7
|
+
*/
|
|
8
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
9
|
+
import { constants } from 'node:os';
|
|
10
|
+
const [command, ...args] = process.argv.slice(2);
|
|
11
|
+
if (!command) {
|
|
12
|
+
console.error('usage: resize-forwarding <command> [args...]');
|
|
13
|
+
process.exit(2);
|
|
14
|
+
}
|
|
15
|
+
const child = spawn(command, args, { stdio: 'inherit' });
|
|
16
|
+
function descendants(root) {
|
|
17
|
+
const children = new Map();
|
|
18
|
+
// `ps -A -o pid=,ppid=` reads the same on Linux and macOS.
|
|
19
|
+
for (const line of execFileSync('ps', ['-A', '-o', 'pid=,ppid='], {
|
|
20
|
+
encoding: 'utf8',
|
|
21
|
+
}).split('\n')) {
|
|
22
|
+
const [pid, ppid] = line.trim().split(/\s+/).map(Number);
|
|
23
|
+
if (pid && ppid !== undefined) {
|
|
24
|
+
children.set(ppid, [...(children.get(ppid) ?? []), pid]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const found = [];
|
|
28
|
+
const todo = [root];
|
|
29
|
+
for (let pid = todo.pop(); pid !== undefined; pid = todo.pop()) {
|
|
30
|
+
for (const kid of children.get(pid) ?? []) {
|
|
31
|
+
found.push(kid);
|
|
32
|
+
todo.push(kid);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
process.on('SIGWINCH', () => {
|
|
38
|
+
if (child.pid === undefined)
|
|
39
|
+
return;
|
|
40
|
+
let pids = [child.pid];
|
|
41
|
+
try {
|
|
42
|
+
pids = [child.pid, ...descendants(child.pid)];
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// No usable `ps`: the child alone still hears the resize; never end the run over it.
|
|
46
|
+
}
|
|
47
|
+
// The foreground group already got one; a second SIGWINCH only redraws again.
|
|
48
|
+
for (const pid of pids) {
|
|
49
|
+
try {
|
|
50
|
+
process.kill(pid, 'SIGWINCH');
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Gone between `ps` and the signal.
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
// Like the launch wrapper: the stop key is for the agent, not for us.
|
|
58
|
+
process.on('SIGINT', () => { });
|
|
59
|
+
process.on('SIGQUIT', () => { });
|
|
60
|
+
child.on('error', (err) => {
|
|
61
|
+
console.error(`resize-forwarding: ${command}: ${err.message}`);
|
|
62
|
+
process.exit(127);
|
|
63
|
+
});
|
|
64
|
+
child.on('exit', (code, signal) => {
|
|
65
|
+
process.exit(code ?? 128 + (signal ? constants.signals[signal] : 0));
|
|
66
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-herdr-core",
|
|
3
|
-
"version": "0.9.1-next.
|
|
3
|
+
"version": "0.9.1-next.7",
|
|
4
4
|
"description": "bakers.build herdr-core integration: executor running each agent in a herdr-core (hc) terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
"directory": "bakers-cli/addons/herdr-core"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@bakers-build/addon-herdr": "^0.9.1-next.
|
|
25
|
+
"@bakers-build/addon-herdr": "^0.9.1-next.7",
|
|
26
|
+
"@bakers-build/addon-workspace-git": "^0.9.1-next.7"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"@bakers-build/conductor": "^0.9.1-next.
|
|
29
|
-
"@bakers-build/core": "^0.9.1-next.
|
|
29
|
+
"@bakers-build/conductor": "^0.9.1-next.7",
|
|
30
|
+
"@bakers-build/core": "^0.9.1-next.7"
|
|
30
31
|
},
|
|
31
32
|
"bakersBuild": {
|
|
32
|
-
"commit": "
|
|
33
|
+
"commit": "03781c6f8dc8c4c3d87fdcf12ae37df35abc6286",
|
|
33
34
|
"channel": "next"
|
|
34
35
|
}
|
|
35
36
|
}
|