@openagt/agent-runner 0.0.1
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/LICENSE +21 -0
- package/bin/agent-runner +11 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +208 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +62 -0
- package/dist/config.js.map +1 -0
- package/dist/ended.d.ts +66 -0
- package/dist/ended.d.ts.map +1 -0
- package/dist/ended.js +114 -0
- package/dist/ended.js.map +1 -0
- package/dist/git-host.d.ts +31 -0
- package/dist/git-host.d.ts.map +1 -0
- package/dist/git-host.js +26 -0
- package/dist/git-host.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +39 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +104 -0
- package/dist/init.js.map +1 -0
- package/dist/live-card.d.ts +27 -0
- package/dist/live-card.d.ts.map +1 -0
- package/dist/live-card.js +56 -0
- package/dist/live-card.js.map +1 -0
- package/dist/names.d.ts +12 -0
- package/dist/names.d.ts.map +1 -0
- package/dist/names.js +12 -0
- package/dist/names.js.map +1 -0
- package/dist/parent.d.ts +47 -0
- package/dist/parent.d.ts.map +1 -0
- package/dist/parent.js +52 -0
- package/dist/parent.js.map +1 -0
- package/dist/records.d.ts +81 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +89 -0
- package/dist/records.js.map +1 -0
- package/dist/run-lock.d.ts +29 -0
- package/dist/run-lock.d.ts.map +1 -0
- package/dist/run-lock.js +80 -0
- package/dist/run-lock.js.map +1 -0
- package/dist/run.d.ts +169 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +462 -0
- package/dist/run.js.map +1 -0
- package/dist/runner.d.ts +148 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +208 -0
- package/dist/runner.js.map +1 -0
- package/dist/sweep.d.ts +46 -0
- package/dist/sweep.d.ts.map +1 -0
- package/dist/sweep.js +83 -0
- package/dist/sweep.js.map +1 -0
- package/dist/test-repo.d.ts +18 -0
- package/dist/test-repo.d.ts.map +1 -0
- package/dist/test-repo.js +49 -0
- package/dist/test-repo.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAIA,OAAO,EAAY,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAKtH,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAY3C,iFAAiF;AACjF,eAAO,MAAM,YAAY,aAAa,CAAA;AAEtC,+EAA+E;AAC/E,eAAO,MAAM,YAAY,YAAI,aAAa,EAAE,OAAO,CAAU,CAAA;AAC7D,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,UAAU,CAE7D;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAQ3K;AAED,6MAA6M;AAC7M,wBAAgB,OAAO,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,EAAE,CAUjD;AAED,0GAA0G;AA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,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAEvH;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,EAClG,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,SAAS,CAAA;CAAO,GAC1C,OAAO,CAAC,UAAU,CAAC,CAerB;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,MAAM,CAQvF"}
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { closeSync, mkdirSync, openSync } from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { probeCli } from '@openagt/agent-driver';
|
|
6
|
+
import { ClaudeCodeDriver, claudeCodeReady } from '@openagt/agent-driver-claude';
|
|
7
|
+
import { CodexDriver, codexReady } from '@openagt/agent-driver-codex';
|
|
8
|
+
import { findRun } from '@openagt/skill-logs';
|
|
9
|
+
import { readPersonal } from './config.js';
|
|
10
|
+
import { resumeRun, runCommand, runIdFrom } from './run.js';
|
|
11
|
+
import { acquireRunLock, handOverRunLock, isPidAlive, releaseRunLock, runStderrPath } from './run-lock.js';
|
|
12
|
+
/**
|
|
13
|
+
* The tool's process side: a run in this process, the same run detached in its own process and
|
|
14
|
+
* answered at once, a resume either way, and whether a run can start here at all. State in files
|
|
15
|
+
* throughout; nothing waits in memory.
|
|
16
|
+
*/
|
|
17
|
+
/** This package's executable, for the processes it spawns: the bin beside `dist/`. */
|
|
18
|
+
const BIN = fileURLToPath(new URL('../bin/agent-runner', import.meta.url));
|
|
19
|
+
/** The environment name the tickets skill reads the claiming agent's id from. */
|
|
20
|
+
export const AGENT_ID_ENV = 'AGENT_ID';
|
|
21
|
+
/** The coding agents a run can be on, by the name the run's record carries. */
|
|
22
|
+
export const DRIVER_NAMES = ['claude-code', 'codex'];
|
|
23
|
+
export function isDriverName(name) {
|
|
24
|
+
return DRIVER_NAMES.includes(name);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether a run on `driver` can start on this machine, asked before it spends a checkout: the
|
|
28
|
+
* coding agent's CLI is installed and logged in (a problem when not: the session would die
|
|
29
|
+
* before its first turn). Warnings: running as root, and on Codex, skills in `~/.agents/skills`
|
|
30
|
+
* it cannot keep out and `memory` on that does nothing while `skills` is off. What a dashboard's check hook runs, and what a
|
|
31
|
+
* person's run and a scheduler's tick refuse on. The git host is not probed: a project with no
|
|
32
|
+
* git host package runs fine, and one whose git host cannot answer says so in the run's own log.
|
|
33
|
+
*/
|
|
34
|
+
export async function readyToRun(repo, driver, deps = {}) {
|
|
35
|
+
const opts = { probe: deps.probe ?? probeCli, ...(deps.isRoot ? { isRoot: deps.isRoot } : {}) };
|
|
36
|
+
switch (driver) {
|
|
37
|
+
case 'claude-code':
|
|
38
|
+
return claudeCodeReady(opts);
|
|
39
|
+
case 'codex':
|
|
40
|
+
return codexReady({ ...opts, personal: await readPersonal(repo, () => { }), ...(deps.agentsSkills !== undefined ? { agentsSkills: deps.agentsSkills } : {}) });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The command line of a spawned run: the model, the coding agent, the follow-up, the publish level, the parent and the base named only when the run has them, so the run's own defaults apply otherwise. */
|
|
44
|
+
export function runArgs(run) {
|
|
45
|
+
const args = ['run', run.prompt, '--id', run.id];
|
|
46
|
+
if (run.mark)
|
|
47
|
+
args.push('--mark');
|
|
48
|
+
if (run.model !== undefined)
|
|
49
|
+
args.push('--model', run.model);
|
|
50
|
+
if (run.driver !== undefined)
|
|
51
|
+
args.push('--driver', run.driver);
|
|
52
|
+
if (run.then !== undefined)
|
|
53
|
+
args.push('--then', run.then);
|
|
54
|
+
if (run.publish !== undefined)
|
|
55
|
+
args.push('--publish', run.publish);
|
|
56
|
+
if (run.parent !== undefined)
|
|
57
|
+
args.push('--parent', run.parent);
|
|
58
|
+
if (run.base !== undefined)
|
|
59
|
+
args.push('--base', run.base);
|
|
60
|
+
return args;
|
|
61
|
+
}
|
|
62
|
+
/** The command line of a spawned resume: the text as the argument, or the answer. */
|
|
63
|
+
export function resumeArgs(run) {
|
|
64
|
+
const args = ['run', '--resume', run.id];
|
|
65
|
+
if (run.text !== undefined)
|
|
66
|
+
args.push(run.text);
|
|
67
|
+
if (run.answer !== undefined)
|
|
68
|
+
args.push('--answer', run.answer);
|
|
69
|
+
if (run.model !== undefined)
|
|
70
|
+
args.push('--model', run.model);
|
|
71
|
+
return args;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The run's process, detached from whoever started it: `agent-runner run <prompt> --id <id>`, its
|
|
75
|
+
* stderr kept. The run's lock is taken here before the process exists and handed to it once it
|
|
76
|
+
* does, so the sweep never finds the run with neither a lock nor a checkout while it boots.
|
|
77
|
+
*/
|
|
78
|
+
export async function spawnRun(repo, run) {
|
|
79
|
+
await acquireRunLock(repo, run.id, { pid: process.pid, isAlive: isPidAlive });
|
|
80
|
+
try {
|
|
81
|
+
const child = await spawnDetached(repo, run.id, runArgs(run));
|
|
82
|
+
await handOverRunLock(repo, run.id, process.pid, child);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
await releaseRunLock(repo, run.id, process.pid);
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** A resumed run's process, detached the same way: `agent-runner run --resume <id> …`. */
|
|
90
|
+
export async function spawnResume(repo, run) {
|
|
91
|
+
await spawnDetached(repo, run.id, resumeArgs(run));
|
|
92
|
+
}
|
|
93
|
+
/** Spawn a detached process of this tool for the run `id`; resolves with its pid once it is spawned. */
|
|
94
|
+
async function spawnDetached(repo, id, args) {
|
|
95
|
+
const stderrPath = runStderrPath(repo, id);
|
|
96
|
+
mkdirSync(dirname(stderrPath), { recursive: true });
|
|
97
|
+
const fd = openSync(stderrPath, 'a');
|
|
98
|
+
const child = spawn(process.execPath, [BIN, ...args], {
|
|
99
|
+
cwd: repo,
|
|
100
|
+
detached: true,
|
|
101
|
+
stdio: ['ignore', 'ignore', fd],
|
|
102
|
+
env: { ...process.env, [AGENT_ID_ENV]: id },
|
|
103
|
+
});
|
|
104
|
+
closeSync(fd);
|
|
105
|
+
child.unref();
|
|
106
|
+
await new Promise((resolve, reject) => {
|
|
107
|
+
child.once('spawn', resolve);
|
|
108
|
+
child.once('error', reject);
|
|
109
|
+
});
|
|
110
|
+
return child.pid;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A person's run, answered at once: the run's process spawned detached, the id returned. What a
|
|
114
|
+
* dashboard's start hook runs: it needs the id back now, not when the agent ends. The run's process
|
|
115
|
+
* writes its own marker: pushing it takes seconds, and the page waits on the id.
|
|
116
|
+
*/
|
|
117
|
+
export async function detachRun(repo, opts, deps = {}) {
|
|
118
|
+
const now = opts.now ?? (() => new Date());
|
|
119
|
+
const id = runIdFrom(now().toISOString());
|
|
120
|
+
const driver = opts.driver ?? 'claude-code';
|
|
121
|
+
const model = opts.model;
|
|
122
|
+
const named = { ...(opts.then !== undefined ? { then: opts.then } : {}), ...(opts.publish !== undefined ? { publish: opts.publish } : {}), ...(opts.parent !== undefined ? { parent: opts.parent } : {}), ...(opts.base !== undefined ? { base: opts.base } : {}) };
|
|
123
|
+
await (deps.spawn ?? spawnRun)(repo, { id, prompt: opts.prompt, mark: true, driver, ...(model !== undefined ? { model } : {}), ...named });
|
|
124
|
+
return { id, driver, ...(model !== undefined ? { model } : {}) };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* An ended run continued in its own process, and answered at once: what a dashboard's resume
|
|
128
|
+
* hook runs. A run this project has no record of is refused here, while someone is still
|
|
129
|
+
* listening; everything after is the resumed run's own record.
|
|
130
|
+
*/
|
|
131
|
+
export async function detachResume(repo, opts, deps = {}) {
|
|
132
|
+
if (!(await findRun(repo, opts.id)))
|
|
133
|
+
throw new Error(`no run ${opts.id} in this project`);
|
|
134
|
+
await (deps.spawn ?? spawnResume)(repo, opts);
|
|
135
|
+
return { id: opts.id };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A run of the real project, in this process, on the coding agent named (Claude Code when none is). A
|
|
139
|
+
* scheduler's run comes with its id and its marker already on the branch; a person's run mints its
|
|
140
|
+
* id here and marks itself. A follow-up it names runs on the same coding agent. The model is the
|
|
141
|
+
* one given; none given, the coding agent starts on its own default. A parent it names that has
|
|
142
|
+
* ended by the time this run ends is continued in a process of its own.
|
|
143
|
+
*/
|
|
144
|
+
export async function runProject(repo, opts) {
|
|
145
|
+
const id = opts.id ?? runIdFrom(new Date().toISOString());
|
|
146
|
+
const driver = opts.driver ?? 'claude-code';
|
|
147
|
+
const setup = await readPersonal(repo, opts.log ?? (() => { }));
|
|
148
|
+
return runCommand(repo, {
|
|
149
|
+
prompt: opts.prompt,
|
|
150
|
+
id,
|
|
151
|
+
// A run given its id was marked by whoever spawned it, unless it was told to mark itself.
|
|
152
|
+
marked: opts.id !== undefined && opts.mark !== true,
|
|
153
|
+
...(opts.model !== undefined ? { model: opts.model } : {}),
|
|
154
|
+
driver: driverFor(driver, id, setup),
|
|
155
|
+
...(opts.then !== undefined ? { then: opts.then, nextDriver: (next) => driverFor(driver, next, setup) } : {}),
|
|
156
|
+
...(opts.publish !== undefined ? { publish: opts.publish } : {}),
|
|
157
|
+
...(opts.parent !== undefined ? { parent: opts.parent } : {}),
|
|
158
|
+
...(opts.base !== undefined ? { base: opts.base } : {}),
|
|
159
|
+
resume: resumeDetached(repo),
|
|
160
|
+
...(opts.log ? { log: opts.log } : {}),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** How a run's ended parent is continued: in a process of its own, with the line it is told. */
|
|
164
|
+
export function resumeDetached(repo) {
|
|
165
|
+
return (id, line) => spawnResume(repo, { id, ...line });
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Continue an ended run of the real project, in this process: the user's text, or the answer to
|
|
169
|
+
* the question it ended on. The coding agent is the one the run's record names: the session
|
|
170
|
+
* to resume is its own.
|
|
171
|
+
*/
|
|
172
|
+
export async function resumeProject(repo, opts, deps = {}) {
|
|
173
|
+
const card = await findRun(repo, opts.id);
|
|
174
|
+
const recorded = card?.driver ?? 'claude-code';
|
|
175
|
+
if (!isDriverName(recorded))
|
|
176
|
+
throw new Error(`run ${opts.id} is on ${recorded}, which agent-runner cannot start`);
|
|
177
|
+
const setup = await readPersonal(repo, opts.log ?? (() => { }));
|
|
178
|
+
return resumeRun(repo, {
|
|
179
|
+
id: opts.id,
|
|
180
|
+
...(opts.text !== undefined ? { text: opts.text } : {}),
|
|
181
|
+
...(opts.answer !== undefined ? { answer: opts.answer } : {}),
|
|
182
|
+
...(opts.model !== undefined ? { model: opts.model } : {}),
|
|
183
|
+
driver: (deps.driverFor ?? driverFor)(recorded, opts.id, setup),
|
|
184
|
+
nextDriver: next => (deps.driverFor ?? driverFor)(recorded, next, setup),
|
|
185
|
+
resume: resumeDetached(repo),
|
|
186
|
+
...(opts.log ? { log: opts.log } : {}),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The coding agent a run is on, unrestricted either way: Claude Code with permissions bypassed, Codex
|
|
191
|
+
* with full access. The run's agent, when asked to publish, pushes its branch and opens its pull request itself, which
|
|
192
|
+
* Codex's default sandbox (the workspace only) does not allow. The run's id is in the agent's
|
|
193
|
+
* environment, so the claim it makes names the run (the tickets skill reads `AGENT_ID`).
|
|
194
|
+
*
|
|
195
|
+
* The coding agent starts with the person's own setup, as when started by hand, less the parts
|
|
196
|
+
* this machine's config turns off (`personal:` in `config.ts`). How a part is turned off is the
|
|
197
|
+
* adapter's own business.
|
|
198
|
+
*/
|
|
199
|
+
export function driverFor(name, id, personal) {
|
|
200
|
+
const env = { ...process.env, [AGENT_ID_ENV]: id };
|
|
201
|
+
switch (name) {
|
|
202
|
+
case 'claude-code':
|
|
203
|
+
return new ClaudeCodeDriver({ permissionMode: 'bypassPermissions', env, personal });
|
|
204
|
+
case 'codex':
|
|
205
|
+
return new CodexDriver({ sandbox: 'danger-full-access', env, personal });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAwE,MAAM,uBAAuB,CAAA;AACtH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAChF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SA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AAgB,CAAC,EAAE,cAAc,EAAE,mBAAmB,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAA;QACrF,KAAK,OAAO;YACV,OAAO,IAAI,WAAW,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5E,CAAC;AACH,CAAC"}
|
package/dist/sweep.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type GitRunner } from '@openagt/agent-data';
|
|
2
|
+
import { type LogsDeps } from '@openagt/skill-logs';
|
|
3
|
+
import { type ParentDeps } from './parent.js';
|
|
4
|
+
/**
|
|
5
|
+
* The belt (#1774): what a run's own process could not do because it died. A scheduler runs it on
|
|
6
|
+
* every tick, before anything is decided, and it acts only for this machine — a pid means nothing on another.
|
|
7
|
+
*
|
|
8
|
+
* A checkout whose live card says `running` under a dead pid is a run that died mid-work: its
|
|
9
|
+
* record is written `failed` from what it left, and the checkout is reclaimed under the branches
|
|
10
|
+
* rule (a dirty tree stays). A checkout whose card says the run ended is one whose process died
|
|
11
|
+
* between the end and the record, or whose checkout held uncommitted work: recorded again, idempotent,
|
|
12
|
+
* and reclaimed again; a run that ended `waiting` keeps its checkout for the answer. A running
|
|
13
|
+
* card on the branch from this machine with no checkout behind it is a run that never started:
|
|
14
|
+
* `failed` with the stderr the spawn left, else `stopped`.
|
|
15
|
+
*
|
|
16
|
+
* A run whose lock a live process holds is that process's: it is booting, working, recording,
|
|
17
|
+
* reclaiming, or resuming, and the sweep does not touch it.
|
|
18
|
+
*
|
|
19
|
+
* A run this sweep ends, one that died mid-work or never started, tells its parent when its record
|
|
20
|
+
* names one (`parent.ts`): its own process is not there to. A run that had ended by itself told
|
|
21
|
+
* its parent then, or died just before it could; the sweep does not tell again.
|
|
22
|
+
*/
|
|
23
|
+
export interface SweepDeps {
|
|
24
|
+
host: string;
|
|
25
|
+
isAlive: (pid: number) => boolean;
|
|
26
|
+
now?: () => Date;
|
|
27
|
+
git?: GitRunner;
|
|
28
|
+
logs?: LogsDeps;
|
|
29
|
+
log?: (line: string) => void;
|
|
30
|
+
/** How an ended parent is continued, in its own process; absent, only a working parent is told. */
|
|
31
|
+
resume?: ParentDeps['resume'];
|
|
32
|
+
}
|
|
33
|
+
export interface SweepResult {
|
|
34
|
+
/** Runs whose record this sweep wrote, and the status it gave them. */
|
|
35
|
+
recorded: {
|
|
36
|
+
id: string;
|
|
37
|
+
status: string;
|
|
38
|
+
}[];
|
|
39
|
+
reclaimed: string[];
|
|
40
|
+
kept: {
|
|
41
|
+
id: string;
|
|
42
|
+
reason: string;
|
|
43
|
+
}[];
|
|
44
|
+
}
|
|
45
|
+
export declare function sweep(repo: string, deps: SweepDeps): Promise<SweepResult>;
|
|
46
|
+
//# sourceMappingURL=sweep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep.d.ts","sourceRoot":"","sources":["../src/sweep.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAEnE,OAAO,EAAY,KAAK,QAAQ,EAAgB,MAAM,qBAAqB,CAAA;AAI3E,OAAO,EAA8B,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAEzE;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;IACjC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAA;IAChB,GAAG,CAAC,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5B,mGAAmG;IACnG,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,QAAQ,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC1C,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CACvC;AAED,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAkD/E"}
|
package/dist/sweep.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { nodeGitRunner } from '@openagt/agent-data';
|
|
3
|
+
import { agentBranchName, reclaimWorktree, worktreeDirEntries, worktreePath } from '@openagt/skill-branches';
|
|
4
|
+
import { listRuns } from '@openagt/skill-logs';
|
|
5
|
+
import { endLiveCard, readLiveCard, readLiveDiary } from './live-card.js';
|
|
6
|
+
import { lockHolder, runStderrPath } from './run-lock.js';
|
|
7
|
+
import { recordBranchGone, recordRun, runnerMark, startOf } from './records.js';
|
|
8
|
+
import { childEndedLine, tellParent } from './parent.js';
|
|
9
|
+
export async function sweep(repo, deps) {
|
|
10
|
+
const git = deps.git ?? nodeGitRunner();
|
|
11
|
+
const now = deps.now ?? (() => new Date());
|
|
12
|
+
const logs = deps.logs ?? {};
|
|
13
|
+
const result = { recorded: [], reclaimed: [], kept: [] };
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
const telling = { host: deps.host, isAlive: deps.isAlive, ...(deps.resume ? { resume: deps.resume } : {}), log: deps.log ?? (() => { }) };
|
|
16
|
+
const tell = async (card, detail, branch) => {
|
|
17
|
+
const parent = runnerMark(card)?.parent;
|
|
18
|
+
if (parent !== undefined)
|
|
19
|
+
await tellParent(repo, parent, childEndedLine({ id: card.id, status: card.status, detail, ...(branch !== undefined ? { branch } : {}), ...(card.pr ? { pr: card.pr } : {}) }), telling);
|
|
20
|
+
};
|
|
21
|
+
// Checkouts first: the live card is the truth about a run this machine started.
|
|
22
|
+
for (const entry of await worktreeDirEntries(repo).catch(() => [])) {
|
|
23
|
+
let card = await readLiveCard(entry.path, entry.agentId);
|
|
24
|
+
const mark = card && runnerMark(card);
|
|
25
|
+
if (!card || !mark || mark.host !== deps.host)
|
|
26
|
+
continue;
|
|
27
|
+
seen.add(card.id);
|
|
28
|
+
if (await lockHolder(repo, card.id, deps.isAlive))
|
|
29
|
+
continue;
|
|
30
|
+
const died = card.status === 'running';
|
|
31
|
+
if (died)
|
|
32
|
+
card = await endLiveCard(entry.path, card, 'failed', DIED_DETAIL, now().toISOString());
|
|
33
|
+
const diary = await readLiveDiary(entry.path, card.id);
|
|
34
|
+
const written = await recordRun(repo, card, diary, logs);
|
|
35
|
+
if (written.ok || written.committed)
|
|
36
|
+
result.recorded.push({ id: card.id, status: card.status });
|
|
37
|
+
if (card.status === 'waiting') {
|
|
38
|
+
result.kept.push({ id: card.id, reason: 'waiting' });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const reclaimed = await reclaimWorktree(repo, entry.path, { birthBranch: agentBranchName(entry.agentId), ...startOf(card), git });
|
|
42
|
+
if (reclaimed.ok) {
|
|
43
|
+
result.reclaimed.push(card.id);
|
|
44
|
+
await recordBranchGone(repo, card, diary, reclaimed.branchesDeleted, logs);
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
result.kept.push({ id: card.id, reason: reclaimed.reason });
|
|
48
|
+
if (died)
|
|
49
|
+
await tell(card, DIED_DETAIL, reclaimed.ok && card.branch !== undefined && reclaimed.branchesDeleted?.includes(card.branch) ? undefined : card.branch);
|
|
50
|
+
}
|
|
51
|
+
// Then the branch: a running card of this machine's with nothing on disk never started.
|
|
52
|
+
for (const card of await listRuns(repo, {}, logs)) {
|
|
53
|
+
if (card.status !== 'running' || seen.has(card.id))
|
|
54
|
+
continue;
|
|
55
|
+
const mark = runnerMark(card);
|
|
56
|
+
if (!mark || mark.host !== deps.host)
|
|
57
|
+
continue;
|
|
58
|
+
if (await lockHolder(repo, card.id, deps.isAlive))
|
|
59
|
+
continue;
|
|
60
|
+
if (await checkoutExists(repo, card.id))
|
|
61
|
+
continue; // a checkout with no live card yet: the run is opening it
|
|
62
|
+
const stderr = (await readFile(runStderrPath(repo, card.id), 'utf8').catch(() => '')).trim();
|
|
63
|
+
const ended = stderr ? failedStart(card, stderr, now()) : gone(card, now());
|
|
64
|
+
const written = await recordRun(repo, ended.card, ended.diary, logs);
|
|
65
|
+
if (written.ok || written.committed)
|
|
66
|
+
result.recorded.push({ id: card.id, status: ended.card.status });
|
|
67
|
+
await tell(ended.card, ended.diary[0].detail, undefined);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/** The detail of a run whose process died mid-work. */
|
|
72
|
+
const DIED_DETAIL = 'its process died before the run ended';
|
|
73
|
+
async function checkoutExists(repo, id) {
|
|
74
|
+
return stat(worktreePath(repo, id)).then(s => s.isDirectory(), () => false);
|
|
75
|
+
}
|
|
76
|
+
function failedStart(card, stderr, now) {
|
|
77
|
+
const detail = `its process died before the run started: ${stderr.split('\n').slice(-5).join('\n')}`;
|
|
78
|
+
return { card: { ...card, status: 'failed', endedAt: now.toISOString() }, diary: [{ kind: 'ended', status: 'failed', detail, at: now.toISOString() }] };
|
|
79
|
+
}
|
|
80
|
+
function gone(card, now) {
|
|
81
|
+
return { card: { ...card, status: 'stopped', endedAt: now.toISOString() }, diary: [{ kind: 'ended', status: 'stopped', detail: 'its process is gone and left no checkout', at: now.toISOString() }] };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=sweep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep.js","sourceRoot":"","sources":["../src/sweep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE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,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,CAAA;AAClK,CAAC;AAED,SAAS,IAAI,CAAC,IAAa,EAAE,GAAS;IACpC,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,SAAkB,EAAE,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,0CAA0C,EAAE,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,CAAA;AAChN,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type AnyDiaryLine } from '@openagt/skill-logs';
|
|
2
|
+
/**
|
|
3
|
+
* A project for the tests: one commit on `main`, a bare `origin`, the `agent-data` branch born
|
|
4
|
+
* on origin, a tracked `.claude/skills/work-queue`. Real git, because the records, the checkouts
|
|
5
|
+
* and the reclaim rule are git.
|
|
6
|
+
*/
|
|
7
|
+
export declare const git: import("@openagt/agent-data").GitRunner;
|
|
8
|
+
export declare const RETRIED_RM: {
|
|
9
|
+
readonly recursive: true;
|
|
10
|
+
readonly force: true;
|
|
11
|
+
readonly maxRetries: 10;
|
|
12
|
+
};
|
|
13
|
+
export declare function testRepo(): Promise<string>;
|
|
14
|
+
/** The repository and its origin go together. */
|
|
15
|
+
export declare function removeRepo(repo: string): Promise<void>;
|
|
16
|
+
/** A run's diary with each line's time checked and taken off: what is left is what happened. */
|
|
17
|
+
export declare function readUntimedDiary(repo: string, id: string): Promise<AnyDiaryLine[]>;
|
|
18
|
+
//# sourceMappingURL=test-repo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-repo.d.ts","sourceRoot":"","sources":["../src/test-repo.ts"],"names":[],"mappings":"AAKA,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElE;;;;GAIG;AAEH,eAAO,MAAM,GAAG,yCAAkB,CAAA;AAElC,eAAO,MAAM,UAAU;aAAK,SAAS;aAAQ,KAAK;aAAQ,UAAU,EAAE,EAAE;CAAW,CAAA;AAEnF,wBAAsB,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAsBhD;AAED,iDAAiD;AACjD,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;AAED,gGAAgG;AAChG,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAMxF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, realpath, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { strict as assert } from 'node:assert';
|
|
5
|
+
import { DATA_BRANCH, nodeGitRunner } from '@openagt/agent-data';
|
|
6
|
+
import { readDiary } from '@openagt/skill-logs';
|
|
7
|
+
/**
|
|
8
|
+
* A project for the tests: one commit on `main`, a bare `origin`, the `agent-data` branch born
|
|
9
|
+
* on origin, a tracked `.claude/skills/work-queue`. Real git, because the records, the checkouts
|
|
10
|
+
* and the reclaim rule are git.
|
|
11
|
+
*/
|
|
12
|
+
export const git = nodeGitRunner();
|
|
13
|
+
export const RETRIED_RM = { recursive: true, force: true, maxRetries: 10 };
|
|
14
|
+
export async function testRepo() {
|
|
15
|
+
const base = await realpath(await mkdtemp(join(tmpdir(), 'agent-runner-')));
|
|
16
|
+
const repo = join(base, 'repo');
|
|
17
|
+
const origin = join(base, 'origin.git');
|
|
18
|
+
await mkdir(repo);
|
|
19
|
+
await git(['init', '-q', '-b', 'main'], repo);
|
|
20
|
+
await git(['config', 'user.email', 'tester@example.com'], repo);
|
|
21
|
+
await git(['config', 'user.name', 'tester'], repo);
|
|
22
|
+
await writeFile(join(repo, 'README.md'), '# t\n');
|
|
23
|
+
await mkdir(join(repo, '.claude', 'skills', 'work-queue'), { recursive: true });
|
|
24
|
+
await writeFile(join(repo, '.claude', 'skills', 'work-queue', 'SKILL.md'), '---\nname: work-queue\n---\nWork one queued task.\n');
|
|
25
|
+
await git(['add', '-A'], repo);
|
|
26
|
+
await git(['commit', '-q', '-m', 'init'], repo);
|
|
27
|
+
await git(['init', '-q', '--bare', origin], base);
|
|
28
|
+
await git(['remote', 'add', 'origin', origin], repo);
|
|
29
|
+
await git(['push', '-q', '-u', 'origin', 'main'], repo);
|
|
30
|
+
// The data branch, parentless, as the skills make it.
|
|
31
|
+
const tree = (await git(['hash-object', '-t', 'tree', '/dev/null'], repo)).trim();
|
|
32
|
+
const commit = (await git(['commit-tree', tree, '-m', `create the ${DATA_BRANCH} branch`], repo)).trim();
|
|
33
|
+
await git(['push', '-q', 'origin', `${commit}:refs/heads/${DATA_BRANCH}`], repo);
|
|
34
|
+
await git(['fetch', '-q', 'origin'], repo);
|
|
35
|
+
return repo;
|
|
36
|
+
}
|
|
37
|
+
/** The repository and its origin go together. */
|
|
38
|
+
export async function removeRepo(repo) {
|
|
39
|
+
await rm(dirname(repo), RETRIED_RM);
|
|
40
|
+
}
|
|
41
|
+
/** A run's diary with each line's time checked and taken off: what is left is what happened. */
|
|
42
|
+
export async function readUntimedDiary(repo, id) {
|
|
43
|
+
const lines = (await readDiary(repo, id)) ?? assert.fail(`no diary for ${id}`);
|
|
44
|
+
return lines.map(({ at, ...line }) => {
|
|
45
|
+
assert.equal(typeof at === 'string' && new Date(at).toISOString(), at, `a time on ${line.kind}`);
|
|
46
|
+
return line;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=test-repo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-repo.js","sourceRoot":"","sources":["../src/test-repo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO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AAC,CAAA;IAChF,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;IAC1C,OAAO,IAAI,CAAA;AACb,CAAC;AAED,iDAAiD;AACjD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY;IAC3C,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAA;AACrC,CAAC;AAED,gGAAgG;AAChG,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAY,EAAE,EAAU;IAC7D,MAAM,KAAK,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAA;IAC9E,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;QACnC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,aAAa,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAChG,OAAO,IAAoB,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openagt/agent-runner",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Run one coding agent from start to end: its own checkout, one prompt, the agent's own loop, a run record on the project's agent-data branch; resume a run that ended on a question; and the sweep a scheduler runs to record the runs whose process died.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/framework/the-framework.git",
|
|
9
|
+
"directory": "packages/agent-runner"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22.12.0"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"bin/agent-runner"
|
|
18
|
+
],
|
|
19
|
+
"bin": {
|
|
20
|
+
"agent-runner": "bin/agent-runner"
|
|
21
|
+
},
|
|
22
|
+
"framework": {
|
|
23
|
+
"hooks": "agent-runner"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"yaml": "^2.5.0",
|
|
34
|
+
"@openagt/agent-driver-claude": "0.0.1",
|
|
35
|
+
"@openagt/agent-driver-codex": "0.0.1",
|
|
36
|
+
"@openagt/agent-data": "0.0.1",
|
|
37
|
+
"@openagt/skill-branches": "0.0.1",
|
|
38
|
+
"@openagt/skill-logs": "0.0.1",
|
|
39
|
+
"@openagt/agent-driver": "0.0.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
43
|
+
"typescript": "^7.0.2"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.build.json",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "tsc -p tsconfig.test.json && node --test --test-timeout=60000 'dist-test/**/*.test.js'",
|
|
52
|
+
"clean": "rm -rf dist dist-test"
|
|
53
|
+
}
|
|
54
|
+
}
|