@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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/bin/agent-runner +11 -0
  3. package/dist/cli.d.ts +19 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +208 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config.d.ts +17 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +62 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/ended.d.ts +66 -0
  12. package/dist/ended.d.ts.map +1 -0
  13. package/dist/ended.js +114 -0
  14. package/dist/ended.js.map +1 -0
  15. package/dist/git-host.d.ts +31 -0
  16. package/dist/git-host.d.ts.map +1 -0
  17. package/dist/git-host.js +26 -0
  18. package/dist/git-host.js.map +1 -0
  19. package/dist/index.d.ts +13 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +13 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/init.d.ts +39 -0
  24. package/dist/init.d.ts.map +1 -0
  25. package/dist/init.js +104 -0
  26. package/dist/init.js.map +1 -0
  27. package/dist/live-card.d.ts +27 -0
  28. package/dist/live-card.d.ts.map +1 -0
  29. package/dist/live-card.js +56 -0
  30. package/dist/live-card.js.map +1 -0
  31. package/dist/names.d.ts +12 -0
  32. package/dist/names.d.ts.map +1 -0
  33. package/dist/names.js +12 -0
  34. package/dist/names.js.map +1 -0
  35. package/dist/parent.d.ts +47 -0
  36. package/dist/parent.d.ts.map +1 -0
  37. package/dist/parent.js +52 -0
  38. package/dist/parent.js.map +1 -0
  39. package/dist/records.d.ts +81 -0
  40. package/dist/records.d.ts.map +1 -0
  41. package/dist/records.js +89 -0
  42. package/dist/records.js.map +1 -0
  43. package/dist/run-lock.d.ts +29 -0
  44. package/dist/run-lock.d.ts.map +1 -0
  45. package/dist/run-lock.js +80 -0
  46. package/dist/run-lock.js.map +1 -0
  47. package/dist/run.d.ts +169 -0
  48. package/dist/run.d.ts.map +1 -0
  49. package/dist/run.js +462 -0
  50. package/dist/run.js.map +1 -0
  51. package/dist/runner.d.ts +148 -0
  52. package/dist/runner.d.ts.map +1 -0
  53. package/dist/runner.js +208 -0
  54. package/dist/runner.js.map +1 -0
  55. package/dist/sweep.d.ts +46 -0
  56. package/dist/sweep.d.ts.map +1 -0
  57. package/dist/sweep.js +83 -0
  58. package/dist/sweep.js.map +1 -0
  59. package/dist/test-repo.d.ts +18 -0
  60. package/dist/test-repo.d.ts.map +1 -0
  61. package/dist/test-repo.js +49 -0
  62. package/dist/test-repo.js.map +1 -0
  63. package/package.json +54 -0
package/dist/run.js ADDED
@@ -0,0 +1,462 @@
1
+ import { hostname } from 'node:os';
2
+ import { mkdir, stat, writeFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { AgentExitError, continuationPrompt, logDiaryFile, parseQuestion, promptOf, takeInbox } from '@openagt/agent-driver';
5
+ import { nodeGitRunner } from '@openagt/agent-data';
6
+ import { agentBranchName, attachCheckout, createCheckout, reclaimWorktree, worktreeBranch, worktreePath } from '@openagt/skill-branches';
7
+ import { findRun, readDiary } from '@openagt/skill-logs';
8
+ import { hideLiveDir, inboxPath, liveDir, readLiveCard, readLiveDiary } from './live-card.js';
9
+ import { forReaders, lasting, markerCard, recordBranchGone, recordRun, runnerMark, startOf, writeMarker } from './records.js';
10
+ import { projectGitHost } from './git-host.js';
11
+ import { acquireRunLock, isPidAlive, releaseRunLock } from './run-lock.js';
12
+ import { runEndedLine } from './ended.js';
13
+ import { childEndedLine, tellParent } from './parent.js';
14
+ /**
15
+ * One run (#1774): a checkout from the branches package, a session from agent-driver, the prompt
16
+ * once, and the agent's own loop to the end. No system prompt and no gates: the
17
+ * command's skill file is the whole instruction, and the agent publishes its own work, when asked
18
+ * to, through the skills in its checkout. How far it takes its work is the run's publish level
19
+ * (`run --publish <commit|branch|pr|merge>`), said in one sentence after the prompt: commit the work,
20
+ * and from there push the branch, open its pull request, or set it to merge once its checks pass.
21
+ * The sentence follows every message the agent is sent, a queued one too, and the record keeps it
22
+ * apart from the message. A run with no level gets its prompt as written, and its agent commits
23
+ * only when the prompt asks.
24
+ * This process records the run and reclaims the checkout when the
25
+ * agent stops; a run that dies is caught by the sweep, which a scheduler runs on every tick.
26
+ *
27
+ * The session keeps the run's live record itself, the card and the diary under `.the-framework/`
28
+ * in the checkout, in the run record's shape; this process adds its mark, the pid and the host,
29
+ * and copies the two files onto the branch unchanged when the run ends. What reaches the agent
30
+ * from outside comes through the session's inbox: a line waiting when a turn ends becomes the
31
+ * next turn; when the last turn ended on a question and nothing waited, the run ends `waiting`,
32
+ * keeps its checkout, and the answer resumes it (`resumeRun`): the same run, the same record,
33
+ * continued.
34
+ *
35
+ * SIGINT or SIGTERM to this process stops the run: the agent's whole process tree is ended
36
+ * through the driver, the run is recorded `stopped`, the checkout reclaimed. That is what a
37
+ * dashboard's Stop sends, the pid being on the live card; nothing else steers a run.
38
+ *
39
+ * One-shot: `agent-runner run <prompt>` runs on its own. A scheduler's tick spawns the same thing
40
+ * with the marker already written and the id chosen.
41
+ *
42
+ * A run may name a follow-up (`run --then <prompt>`): once it ends done with a pull request, a
43
+ * fresh agent, a run of its own with its own record, works on the same branch from the prompt,
44
+ * the first run's id after it. The first agent is told, in a line after its prompt, to publish its
45
+ * work without arming the pull request's merge, whatever level the run was given; the follow-up
46
+ * is given no level, its prompt says what it publishes; the follow-up ending done is when this
47
+ * process merges it, through the project's git host (`git-host.ts`). A follow-up that fails or is
48
+ * stopped leaves the request open, for a person.
49
+ *
50
+ * The pull request a run's branch has is read back the same way, through the git host the project
51
+ * declares; a project with no git host package records none.
52
+ *
53
+ * A run may be started for another run, its parent (`run --parent <id>`), and from a branch other
54
+ * than origin's default (`run --base <ref>`); both are on its record for its whole life. When it
55
+ * ends, however it ends, its parent is told (`parent.ts`).
56
+ *
57
+ * A run that makes its own branch writes down the commit the branch was made at, on its record
58
+ * for its whole life: the run's own work is what came after it, which is how it is still told
59
+ * apart once it is merged. A run given a branch that exists (a follow-up's) writes none: that
60
+ * branch's work began with another run.
61
+ */
62
+ /** The detail a stopped run's record carries. */
63
+ export const STOPPED_DETAIL = 'stopped by a signal to its process';
64
+ const COMMIT_OPENING = 'When you finish, if you changed any file, commit your work';
65
+ const PUBLISH_OPENING = `${COMMIT_OPENING}, push your branch`;
66
+ /** The sentence after a prompt that says how far to take the work, every level starting with the commit; how is the business of the skills in the checkout. */
67
+ export const PUBLISH_LINES = {
68
+ commit: `${COMMIT_OPENING}.`,
69
+ branch: `${PUBLISH_OPENING} and open no pull request.`,
70
+ pr: `${PUBLISH_OPENING} and open its pull request.`,
71
+ merge: `${PUBLISH_OPENING} and open its pull request, set to merge on its own once its checks pass.`,
72
+ };
73
+ /** The sentence when a follow-up is coming: the agent publishes its work, this process merges the request later. */
74
+ export const HOLD_MERGE_LINE = `${PUBLISH_OPENING} and open its pull request, but do not arm its merge: it is merged for you once a follow-up is done.`;
75
+ /**
76
+ * The sentence a run adds after every prompt of its agent, the first and each message after it:
77
+ * that of its publish level, the hold sentence instead when the run names a follow-up, none for a
78
+ * run with neither. The session sends it after the prompt and writes it down apart from it, so a
79
+ * reader shows the person's words as the person wrote them.
80
+ */
81
+ export function addedLine(publish, then) {
82
+ return then !== undefined ? HOLD_MERGE_LINE : publish !== undefined ? PUBLISH_LINES[publish] : undefined;
83
+ }
84
+ /** The sentence as a session takes it: named, or left out. */
85
+ function addedOf(publish, then) {
86
+ const added = addedLine(publish, then);
87
+ return added !== undefined ? { added } : {};
88
+ }
89
+ /** Filesystem-safe, time-ordered id from an ISO start: the shape the dashboard sorts runs by. */
90
+ export function runIdFrom(startedAt) {
91
+ return startedAt.replace(/[:.]/g, '-');
92
+ }
93
+ /** The model as a card or a session takes it: named, or left out so the tool starts on its own default. */
94
+ function modelOf(model) {
95
+ return model !== undefined ? { model } : {};
96
+ }
97
+ export async function runCommand(repo, opts) {
98
+ const outcome = await runOnce(repo, opts);
99
+ return opts.then !== undefined ? followUp(repo, outcome, opts.then, opts) : outcome;
100
+ }
101
+ async function runOnce(repo, opts) {
102
+ const git = opts.git ?? nodeGitRunner();
103
+ const now = opts.now ?? (() => new Date());
104
+ const clock = () => now().toISOString();
105
+ const host = opts.host ?? hostname();
106
+ const pid = opts.pid ?? process.pid;
107
+ const startedAt = clock();
108
+ const id = opts.id ?? runIdFrom(startedAt);
109
+ let mark = { host, pid, ...lasting(opts) };
110
+ const log = opts.log ?? (() => { });
111
+ const logs = opts.logs ?? {};
112
+ const isAlive = opts.isAlive ?? isPidAlive;
113
+ const telling = { host, isAlive, ...(opts.resume ? { resume: opts.resume } : {}), log };
114
+ await acquireRunLock(repo, id, { pid, isAlive });
115
+ try {
116
+ // A person's run marks itself; a scheduler's run was marked before it was spawned. The marker
117
+ // is pushed while the checkout is made and the agent starts: pushing takes seconds, and the
118
+ // person watching the run waits on the agent. It never writes `.git/config`, so the agent's own
119
+ // git is never locked out by it. The run's record waits on it, so it lands after.
120
+ const marking = opts.marked
121
+ ? Promise.resolve()
122
+ : writeMarker(repo, markerCard({ id, startedAt, prompt: opts.prompt, driver: opts.driver.id, ...modelOf(opts.model), mark }), logs).then(marked => {
123
+ if (!marked.ok && !marked.committed)
124
+ log(`[agent-runner] the run's record could not be written: ${marked.error}`);
125
+ }, err => log(`[agent-runner] the run's record could not be written: ${errorMessage(err)}`));
126
+ // The checkout: the branches package's one sequence, on a fresh branch or the one given.
127
+ // Without one there is no run, and the record says so instead of a marker left running.
128
+ let checkout;
129
+ try {
130
+ checkout = opts.branch !== undefined ? await attachCheckout(repo, { agentId: id, branch: opts.branch }, git) : await createCheckout(repo, { agentId: id, ...(opts.base !== undefined ? { base: opts.base } : {}) }, git);
131
+ }
132
+ catch (err) {
133
+ const detail = `could not create a checkout: ${errorMessage(err)}`;
134
+ const endedAt = clock();
135
+ await marking;
136
+ await recordRun(repo, { ...markerCard({ id, startedAt, prompt: opts.prompt, driver: opts.driver.id, ...modelOf(opts.model), mark }), status: 'failed', endedAt }, [{ kind: 'ended', status: 'failed', detail, at: endedAt }], logs);
137
+ if (opts.parent !== undefined)
138
+ await tellParent(repo, opts.parent, childEndedLine({ id, status: 'failed', detail }), telling);
139
+ return { id, status: 'failed', checkout: { reclaimed: false, reason: 'no checkout' }, detail };
140
+ }
141
+ // Only a branch this run made: one it was given holds another run's work, begun elsewhere.
142
+ if (opts.branch === undefined)
143
+ mark = { ...mark, ...(await startCommit(checkout.path, git)) };
144
+ // Awaited here, not returned: the lock is let go in `finally`, and a bare `return` of the
145
+ // promise would run that before the session ends, leaving the run to the sweep.
146
+ return await session(repo, {
147
+ id,
148
+ checkout,
149
+ card: { id, startedAt, status: 'running', intent: opts.prompt, driver: opts.driver.id, ...modelOf(opts.model), branch: checkout.branch, caller: { runner: mark, pid, host, ...forReaders(mark), kind: 'prompt', workspace: checkout.path } },
150
+ prompt: opts.prompt,
151
+ ...addedOf(opts.publish, opts.then),
152
+ driver: opts.driver,
153
+ ...modelOf(opts.model),
154
+ ...(opts.branchPr ? { prBefore: opts.branchPr } : {}),
155
+ continued: false,
156
+ marking,
157
+ telling,
158
+ git,
159
+ gitHost: opts.gitHost ?? projectGitHost,
160
+ logs,
161
+ log,
162
+ clock,
163
+ });
164
+ }
165
+ finally {
166
+ await releaseRunLock(repo, id, pid).catch(() => { });
167
+ }
168
+ }
169
+ /**
170
+ * Continue an ended run: the same id, the same record, the same branch. The checkout is the one
171
+ * the run kept, or a new one attached to its branch; a branch that went with the checkout, for
172
+ * holding nothing, starts again from the base the record names, or origin's default branch. The session resumes by the id the
173
+ * record carries; the diary goes on from where it stopped. The prompt is the user's text, or the
174
+ * continuation of the question the run ended on with the given answer. The sentence of the publish
175
+ * level the record keeps is said again after it. A run whose work was landed, its branch gone
176
+ * with that, is no longer recorded as landed once it is on a branch made again: what it does from
177
+ * here is not. A follow-up the record names is still owed: the
178
+ * agent is told again not to arm the merge, and the follow-up runs once this ends done.
179
+ */
180
+ export async function resumeRun(repo, opts) {
181
+ const resumed = await resumeOnce(repo, opts);
182
+ return resumed.then !== undefined ? followUp(repo, resumed.outcome, resumed.then, { ...opts, ...(resumed.model !== undefined ? { model: resumed.model } : {}) }) : resumed.outcome;
183
+ }
184
+ async function resumeOnce(repo, opts) {
185
+ const git = opts.git ?? nodeGitRunner();
186
+ const now = opts.now ?? (() => new Date());
187
+ const clock = () => now().toISOString();
188
+ const host = opts.host ?? hostname();
189
+ const pid = opts.pid ?? process.pid;
190
+ const logs = opts.logs ?? {};
191
+ const log = opts.log ?? (() => { });
192
+ const id = opts.id;
193
+ const isAlive = opts.isAlive ?? isPidAlive;
194
+ // Another process of this run, the one that ended it and still records and reclaims, or a
195
+ // resume started just before this one, goes first: this one waits, then reads the run as that
196
+ // one left it.
197
+ await acquireRunLock(repo, id, { pid, isAlive });
198
+ try {
199
+ const card = await findRun(repo, opts.id, logs);
200
+ if (!card)
201
+ throw new Error(`no run ${opts.id}`);
202
+ // Every process of this run is gone by now, so a record still saying running is one whose
203
+ // process died before it could end it: the sweep's to close first.
204
+ if (card.status === 'running')
205
+ throw new Error(`run ${opts.id} is still recorded running`);
206
+ const previous = runnerMark(card);
207
+ if (!previous)
208
+ throw new Error(`run ${opts.id} is not this tool's`);
209
+ const diary = (await readDiary(repo, opts.id, logs)) ?? [];
210
+ const sessionId = typeof card.caller?.['sessionId'] === 'string' ? card.caller['sessionId'] : undefined;
211
+ let prompt;
212
+ if (opts.answer !== undefined) {
213
+ const question = [...diary].reverse().find(line => line.kind === 'question');
214
+ const title = typeof question?.['title'] === 'string' ? question['title'] : 'your question';
215
+ prompt = continuationPrompt(title, opts.answer);
216
+ }
217
+ else if (opts.text) {
218
+ prompt = opts.text;
219
+ }
220
+ else {
221
+ throw new Error('a text or an answer is needed to resume a run');
222
+ }
223
+ const branch = card.branch ?? agentBranchName(opts.id);
224
+ const path = worktreePath(repo, opts.id);
225
+ const kept = await stat(path).then(s => s.isDirectory(), () => false);
226
+ const checkout = kept ? { path, branch } : await attachCheckout(repo, { agentId: opts.id, branch, ...(previous.base !== undefined ? { base: previous.base } : {}) }, git);
227
+ // A branch that was gone everywhere was just made again, from where it starts as that is now:
228
+ // that is where the run's own work begins. One still on origin came back with its work.
229
+ const restarted = checkout.again ? await startCommit(checkout.path, git) : {};
230
+ // The record is written running again over the ended one, so every reader sees the run in flight.
231
+ const mark = { host, pid, ...lasting(previous), ...restarted };
232
+ const runningCard = { ...card, status: 'running', caller: { ...card.caller, runner: mark, pid, host, ...forReaders(mark), workspace: checkout.path } };
233
+ delete runningCard.endedAt;
234
+ // A record that says its work was landed lost its branch to that. On a branch made again the
235
+ // work is new and not landed: left on the record, every reader would go on saying it is.
236
+ if (checkout.again)
237
+ delete runningCard.caller?.['landed'];
238
+ const reopened = await recordRun(repo, runningCard, diary, logs);
239
+ if (!reopened.ok && !reopened.committed)
240
+ log(`[agent-runner] the run's record could not be written: ${reopened.error}`);
241
+ const model = opts.model ?? card.model;
242
+ const outcome = await session(repo, {
243
+ id: opts.id,
244
+ checkout,
245
+ card: { ...runningCard },
246
+ priorDiary: diary,
247
+ prompt,
248
+ ...addedOf(previous.publish, previous.then),
249
+ driver: opts.driver,
250
+ ...modelOf(model),
251
+ continued: true,
252
+ ...(sessionId !== undefined ? { resumeSessionId: sessionId } : {}),
253
+ telling: { host, isAlive, ...(opts.resume ? { resume: opts.resume } : {}), log },
254
+ git,
255
+ gitHost: opts.gitHost ?? projectGitHost,
256
+ logs,
257
+ log,
258
+ clock,
259
+ });
260
+ return { outcome, ...(previous.then !== undefined ? { then: previous.then } : {}), ...modelOf(model) };
261
+ }
262
+ finally {
263
+ await releaseRunLock(repo, id, pid).catch(() => { });
264
+ }
265
+ }
266
+ /**
267
+ * The follow-up a run named, once the run ended done with a pull request: a fresh agent on the
268
+ * run's branch, a run of its own, given the prompt and the first run's id. When it ends done the
269
+ * first run's request is merged through the project's git host; otherwise the request stays open. A
270
+ * run that did not end done, or opened no request, has nothing to follow up.
271
+ */
272
+ async function followUp(repo, first, then, opts) {
273
+ if (first.status !== 'done' || !first.pr || !first.branch)
274
+ return first;
275
+ const id = runIdFrom((opts.now ?? (() => new Date()))().toISOString());
276
+ const next = await runCommand(repo, {
277
+ prompt: `${then} ${first.id}`,
278
+ id,
279
+ branch: first.branch,
280
+ branchPr: first.pr,
281
+ driver: opts.nextDriver ? opts.nextDriver(id) : opts.driver,
282
+ ...pick(opts, ['model', 'host', 'pid', 'isAlive', 'now', 'git', 'gitHost', 'logs', 'log']),
283
+ });
284
+ if (next.status !== 'done')
285
+ return { ...first, then: next };
286
+ return { ...first, then: { ...next, merge: await (opts.gitHost ?? projectGitHost).mergeRequest(repo, first.pr.number) } };
287
+ }
288
+ function pick(from, keys) {
289
+ const picked = {};
290
+ for (const key of keys)
291
+ if (from[key] !== undefined)
292
+ picked[key] = from[key];
293
+ return picked;
294
+ }
295
+ /** The session, its end, the record and the reclaim: the part a fresh run and a continued one share. */
296
+ async function session(repo, run) {
297
+ const dir = liveDir(run.checkout.path);
298
+ const inbox = inboxPath(run.checkout.path);
299
+ if (run.priorDiary) {
300
+ await mkdir(dir, { recursive: true });
301
+ await writeFile(join(dir, logDiaryFile(run.id)), run.priorDiary.map(line => JSON.stringify(line) + '\n').join(''));
302
+ }
303
+ // A checkout with an untracked directory in it is a dirty tree, which the branches rule never reclaims.
304
+ await hideLiveDir(run.checkout.path).catch(() => { });
305
+ // A signal stops the run: the first aborts the session, which ends the agent's process tree.
306
+ // The handlers stay until this process is done, so a second signal, or one that comes while the
307
+ // run records and reclaims, is ignored instead of killing the process halfway through a write.
308
+ const stop = new AbortController();
309
+ const onSignal = () => stop.abort();
310
+ process.on('SIGINT', onSignal);
311
+ process.on('SIGTERM', onSignal);
312
+ try {
313
+ return await sessionToEnd(repo, run, dir, inbox, stop.signal);
314
+ }
315
+ finally {
316
+ process.off('SIGINT', onSignal);
317
+ process.off('SIGTERM', onSignal);
318
+ }
319
+ }
320
+ async function sessionToEnd(repo, run, dir, inbox, stopped) {
321
+ const { id: _id, status: _status, endedAt: _endedAt, ...startCard } = run.card;
322
+ let status = 'done';
323
+ let detail;
324
+ let branch = run.checkout.branch;
325
+ let pr;
326
+ let question;
327
+ let lastWords = '';
328
+ let driverSession;
329
+ try {
330
+ driverSession = await run.driver.start({
331
+ cwd: run.checkout.path,
332
+ ...(run.model !== undefined ? { model: run.model } : {}),
333
+ signal: stopped,
334
+ ...(run.resumeSessionId !== undefined ? { resumeSessionId: run.resumeSessionId } : {}),
335
+ log: { dir, card: { id: run.id, ...startCard }, continue: run.continued },
336
+ });
337
+ }
338
+ catch (err) {
339
+ status = 'failed';
340
+ detail = errorMessage(err);
341
+ }
342
+ try {
343
+ // The prompts this process owes the agent: the run's own, then the lines that reached the
344
+ // inbox after the last turn took it but while the card still said running. Whoever wrote
345
+ // them was told the run has them, so this process sends them before it lets the run go.
346
+ let prompts = [run.prompt];
347
+ let resume = run.continued;
348
+ while (driverSession) {
349
+ status = 'done';
350
+ detail = undefined;
351
+ question = undefined;
352
+ let failure;
353
+ let lastText = '';
354
+ try {
355
+ for (const [i, prompt] of prompts.entries()) {
356
+ // Only the last one drains the inbox: a line written meanwhile comes after these.
357
+ const last = i === prompts.length - 1;
358
+ const turn = await driverSession.prompt(prompt, { ...(last ? { inbox } : {}), ...(resume ? { resume: true } : {}), ...(run.added !== undefined ? { added: run.added } : {}) });
359
+ lastText = turn.text;
360
+ lastWords = turn.text;
361
+ resume = true;
362
+ }
363
+ }
364
+ catch (err) {
365
+ status = 'failed';
366
+ detail = errorMessage(err);
367
+ failure = err;
368
+ }
369
+ if (stopped.aborted) {
370
+ status = 'stopped';
371
+ detail = STOPPED_DETAIL;
372
+ }
373
+ else if (status === 'done') {
374
+ // The last turn asked and nothing waited in the inbox: the run ends here, waiting, and
375
+ // keeps its checkout for the answer to resume it.
376
+ question = parseQuestion(lastText)?.title;
377
+ if (question !== undefined)
378
+ status = 'waiting';
379
+ }
380
+ // Where the work ended up: the agent renames its branch itself, and the pull request it
381
+ // opened, if any, is read back off the branch through the project's git host.
382
+ branch = (await worktreeBranch(run.checkout.path, run.git).catch(() => undefined)) ?? run.checkout.branch;
383
+ pr = await run.gitHost.requestOfBranch(repo, branch).catch(() => undefined);
384
+ const live = driverSession.log;
385
+ if (!live)
386
+ break;
387
+ await live.patch({ branch, ...(pr ? { pr } : {}) });
388
+ // The ended line leaves out a reason the diary already holds: the agent's error line, written
389
+ // just before its process exited, says it, so the ended line says only that the agent exited.
390
+ await live.end(status, status === 'failed' && failure instanceof AgentExitError ? failure.exit : detail);
391
+ await live.settled();
392
+ // The card says ended now, so a line written from here on goes to the project's resume
393
+ // hook, which waits for this process. What is in the inbox was written before: this
394
+ // process's to send. A stopped run was stopped on purpose; what reached it is dropped.
395
+ if (status === 'stopped' || stopped.aborted)
396
+ break;
397
+ const late = await takeInbox(inbox);
398
+ if (late.length === 0)
399
+ break;
400
+ prompts = late.map(promptOf);
401
+ await live.reopen();
402
+ }
403
+ }
404
+ finally {
405
+ await driverSession?.dispose().catch(() => { });
406
+ }
407
+ // The record: the two files the session kept, copied onto the branch unchanged.
408
+ const live = driverSession?.log;
409
+ const card = (await readLiveCard(run.checkout.path, run.id)) ?? { ...run.card, status, endedAt: run.clock(), branch, ...(pr ? { pr } : {}) };
410
+ const diary = live ? await readLiveDiary(run.checkout.path, run.id) : [...(run.priorDiary ?? []), { kind: 'ended', status, ...(detail !== undefined ? { detail } : {}), at: card.endedAt ?? run.clock() }];
411
+ await run.marking;
412
+ const recorded = await recordRun(repo, card, diary, run.logs);
413
+ if (!recorded.ok && !recorded.committed)
414
+ run.log(`[agent-runner] the run's record could not be written: ${recorded.error}`);
415
+ // The person's line, when this end needs them: a question, or a pull request new to this session.
416
+ await runEndedLine(repo, { id: run.id, prompt: run.card.intent ?? '', status, ...(question !== undefined ? { question } : {}), ...(pr ? { pr } : {}), ...((run.prBefore ?? run.card.pr) ? { prBefore: run.prBefore ?? run.card.pr } : {}) }, { log: run.log });
417
+ // The run's parent, when it has one, is told how it ended, once the branch it would be pointed
418
+ // at is known to have stayed: an empty one goes with the checkout.
419
+ const parent = runnerMark(run.card)?.parent;
420
+ const tell = async (branchStayed) => {
421
+ if (parent === undefined)
422
+ return;
423
+ const line = childEndedLine({ id: run.id, status, ...(detail !== undefined ? { detail } : {}), ...(question !== undefined ? { question } : {}), ...(branchStayed ? { branch } : {}), ...(pr ? { pr } : {}), lastWords });
424
+ await tellParent(repo, parent, line, run.telling);
425
+ };
426
+ // The checkout goes once its branch holds everything in it (the branches rule), and the branch
427
+ // stays on this machine: nothing is pushed here, publishing is the agent's when it was asked, the person's otherwise. A dirty tree
428
+ // keeps the checkout, and the sweep tries again later. A waiting run keeps it on purpose: the
429
+ // answer resumes the run there.
430
+ if (status === 'waiting') {
431
+ await tell(true);
432
+ return outcomeOf(run.id, status, branch, pr, card.cost, { reclaimed: false, reason: 'waiting' }, detail);
433
+ }
434
+ const reclaimed = await reclaimWorktree(repo, run.checkout.path, { birthBranch: agentBranchName(run.id), ...startOf(run.card), git: run.git });
435
+ if (reclaimed.ok) {
436
+ const rewritten = await recordBranchGone(repo, card, diary, reclaimed.branchesDeleted, run.logs);
437
+ if (rewritten && !rewritten.ok && !rewritten.committed)
438
+ run.log(`[agent-runner] the run's record could not be written: ${rewritten.error}`);
439
+ }
440
+ await tell(!(reclaimed.ok && reclaimed.branchesDeleted?.includes(branch)));
441
+ return outcomeOf(run.id, status, branch, pr, card.cost, reclaimed.ok ? { reclaimed: true } : { reclaimed: false, reason: reclaimed.reason }, detail);
442
+ }
443
+ /** The commit a checkout just made is at: where the run's own work begins. Nothing when git cannot say. */
444
+ async function startCommit(checkout, git) {
445
+ const commit = (await git(['rev-parse', '--verify', '--quiet', 'HEAD^{commit}'], checkout).catch(() => '')).trim();
446
+ return commit ? { baseCommit: commit } : {};
447
+ }
448
+ function outcomeOf(id, status, branch, pr, cost, checkout, detail) {
449
+ return {
450
+ id,
451
+ status,
452
+ branch,
453
+ ...(pr ? { pr } : {}),
454
+ ...(cost !== undefined ? { cost } : {}),
455
+ checkout,
456
+ ...(detail !== undefined ? { detail } : {}),
457
+ };
458
+ }
459
+ function errorMessage(err) {
460
+ return err instanceof Error ? err.message : String(err);
461
+ }
462
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAsD,MAAM,uBAAuB,CAAA;AAChL,OAAO,EAAE,aAAa,EAAkB,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACxI,OAAO,EAAE,OAAO,EAAE,SAAS,EAAkE,MAAM,qBAAqB,CAAA;AACxH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC7F,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAiC,MAAM,cAAc,CAAA;AAC5J,OAAO,EAAE,cAAc,EAAmC,MAAM,eAAe,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAA;AAEzE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;QACR,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAA;AACH,CAAC;AAED,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACzD,CAAC"}
@@ -0,0 +1,148 @@
1
+ import { type CliProbe, type Driver, type DriverReadiness, type PersonalSetup } from '@openagt/agent-driver';
2
+ import { type RunOutcome } from './run.js';
3
+ import type { Publish } from './records.js';
4
+ /** The environment name the tickets skill reads the claiming agent's id from. */
5
+ export declare const AGENT_ID_ENV = "AGENT_ID";
6
+ /** The coding agents a run can be on, by the name the run's record carries. */
7
+ export declare const DRIVER_NAMES: readonly ['claude-code', 'codex'];
8
+ export type DriverName = (typeof DRIVER_NAMES)[number];
9
+ export declare function isDriverName(name: string): name is DriverName;
10
+ /**
11
+ * Whether a run on `driver` can start on this machine, asked before it spends a checkout: the
12
+ * coding agent's CLI is installed and logged in (a problem when not: the session would die
13
+ * before its first turn). Warnings: running as root, and on Codex, skills in `~/.agents/skills`
14
+ * it cannot keep out and `memory` on that does nothing while `skills` is off. What a dashboard's check hook runs, and what a
15
+ * person's run and a scheduler's tick refuse on. The git host is not probed: a project with no
16
+ * git host package runs fine, and one whose git host cannot answer says so in the run's own log.
17
+ */
18
+ export declare function readyToRun(repo: string, driver: DriverName, deps?: {
19
+ probe?: CliProbe;
20
+ isRoot?: () => boolean;
21
+ agentsSkills?: string;
22
+ }): Promise<DriverReadiness>;
23
+ /** 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. */
24
+ export declare function runArgs(run: SpawnedRun): string[];
25
+ /** A run spawned in its own process, its marker already on the branch unless it is to write it itself. */
26
+ export interface SpawnedRun {
27
+ id: string;
28
+ prompt: string;
29
+ /** The run writes its own marker: a person's detached start, answered before the marker is pushed. */
30
+ mark?: boolean;
31
+ model?: string;
32
+ driver?: DriverName;
33
+ /** The follow-up's prompt (`run --then`); a person's start only. */
34
+ then?: string;
35
+ /** How far the run publishes (`run --publish`): a schedule line's level for a scheduler's run, the person's pick for a detached start. */
36
+ publish?: Publish;
37
+ /** The run this one is started for (`run --parent`). */
38
+ parent?: string;
39
+ /** The branch this run's branch starts from (`run --base`). */
40
+ base?: string;
41
+ }
42
+ /** The command line of a spawned resume: the text as the argument, or the answer. */
43
+ export declare function resumeArgs(run: {
44
+ id: string;
45
+ text?: string;
46
+ answer?: string;
47
+ model?: string;
48
+ }): string[];
49
+ /**
50
+ * The run's process, detached from whoever started it: `agent-runner run <prompt> --id <id>`, its
51
+ * stderr kept. The run's lock is taken here before the process exists and handed to it once it
52
+ * does, so the sweep never finds the run with neither a lock nor a checkout while it boots.
53
+ */
54
+ export declare function spawnRun(repo: string, run: SpawnedRun): Promise<void>;
55
+ /** A resumed run's process, detached the same way: `agent-runner run --resume <id> …`. */
56
+ export declare function spawnResume(repo: string, run: {
57
+ id: string;
58
+ text?: string;
59
+ answer?: string;
60
+ model?: string;
61
+ }): Promise<void>;
62
+ /**
63
+ * A person's run, answered at once: the run's process spawned detached, the id returned. What a
64
+ * dashboard's start hook runs: it needs the id back now, not when the agent ends. The run's process
65
+ * writes its own marker: pushing it takes seconds, and the page waits on the id.
66
+ */
67
+ export declare function detachRun(repo: string, opts: {
68
+ prompt: string;
69
+ model?: string;
70
+ driver?: DriverName;
71
+ then?: string;
72
+ publish?: Publish;
73
+ parent?: string;
74
+ base?: string;
75
+ now?: () => Date;
76
+ }, deps?: {
77
+ spawn?: typeof spawnRun;
78
+ }): Promise<{
79
+ id: string;
80
+ driver: DriverName;
81
+ model?: string;
82
+ }>;
83
+ /**
84
+ * An ended run continued in its own process, and answered at once: what a dashboard's resume
85
+ * hook runs. A run this project has no record of is refused here, while someone is still
86
+ * listening; everything after is the resumed run's own record.
87
+ */
88
+ export declare function detachResume(repo: string, opts: {
89
+ id: string;
90
+ text?: string;
91
+ answer?: string;
92
+ model?: string;
93
+ }, deps?: {
94
+ spawn?: typeof spawnResume;
95
+ }): Promise<{
96
+ id: string;
97
+ }>;
98
+ /**
99
+ * A run of the real project, in this process, on the coding agent named (Claude Code when none is). A
100
+ * scheduler's run comes with its id and its marker already on the branch; a person's run mints its
101
+ * id here and marks itself. A follow-up it names runs on the same coding agent. The model is the
102
+ * one given; none given, the coding agent starts on its own default. A parent it names that has
103
+ * ended by the time this run ends is continued in a process of its own.
104
+ */
105
+ export declare function runProject(repo: string, opts: {
106
+ prompt: string;
107
+ id?: string;
108
+ mark?: boolean;
109
+ model?: string;
110
+ driver?: DriverName;
111
+ then?: string;
112
+ publish?: Publish;
113
+ parent?: string;
114
+ base?: string;
115
+ log?: (line: string) => void;
116
+ }): Promise<RunOutcome>;
117
+ /** How a run's ended parent is continued: in a process of its own, with the line it is told. */
118
+ export declare function resumeDetached(repo: string): (id: string, line: {
119
+ text: string;
120
+ } | {
121
+ answer: string;
122
+ }) => Promise<void>;
123
+ /**
124
+ * Continue an ended run of the real project, in this process: the user's text, or the answer to
125
+ * the question it ended on. The coding agent is the one the run's record names: the session
126
+ * to resume is its own.
127
+ */
128
+ export declare function resumeProject(repo: string, opts: {
129
+ id: string;
130
+ text?: string;
131
+ answer?: string;
132
+ model?: string;
133
+ log?: (line: string) => void;
134
+ }, deps?: {
135
+ driverFor?: typeof driverFor;
136
+ }): Promise<RunOutcome>;
137
+ /**
138
+ * The coding agent a run is on, unrestricted either way: Claude Code with permissions bypassed, Codex
139
+ * with full access. The run's agent, when asked to publish, pushes its branch and opens its pull request itself, which
140
+ * Codex's default sandbox (the workspace only) does not allow. The run's id is in the agent's
141
+ * environment, so the claim it makes names the run (the tickets skill reads `AGENT_ID`).
142
+ *
143
+ * The coding agent starts with the person's own setup, as when started by hand, less the parts
144
+ * this machine's config turns off (`personal:` in `config.ts`). How a part is turned off is the
145
+ * adapter's own business.
146
+ */
147
+ export declare function driverFor(name: DriverName, id: string, personal: PersonalSetup): Driver;
148
+ //# sourceMappingURL=runner.d.ts.map