@firefunc-agent/runner 0.9.6 → 0.9.14

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 (59) hide show
  1. package/README.md +2 -0
  2. package/dist/activity.d.ts +1 -0
  3. package/dist/activity.js +1 -1
  4. package/dist/api-fallback.d.ts +9 -0
  5. package/dist/api-fallback.js +55 -0
  6. package/dist/api.d.ts +138 -0
  7. package/dist/api.js +153 -4
  8. package/dist/ask/index.d.ts +20 -0
  9. package/dist/ask/index.js +64 -0
  10. package/dist/ask-first.d.ts +59 -0
  11. package/dist/ask-first.js +126 -0
  12. package/dist/brief.d.ts +2 -0
  13. package/dist/brief.js +6 -0
  14. package/dist/build-info.json +2 -2
  15. package/dist/config.d.ts +2 -0
  16. package/dist/cut.d.ts +3 -1
  17. package/dist/cut.js +15 -4
  18. package/dist/daemon.js +51 -5
  19. package/dist/engines/claude.js +10 -4
  20. package/dist/engines/copilot.js +3 -2
  21. package/dist/firefunc/agents.js +1 -1
  22. package/dist/git-auth.d.ts +1 -0
  23. package/dist/git-auth.js +9 -1
  24. package/dist/job.js +1324 -804
  25. package/dist/keep-local.d.ts +1 -0
  26. package/dist/keep-local.js +3 -0
  27. package/dist/limit.d.ts +1 -0
  28. package/dist/limit.js +4 -1
  29. package/dist/locks.d.ts +3 -0
  30. package/dist/locks.js +46 -13
  31. package/dist/plan-phase/index.d.ts +11 -0
  32. package/dist/plan-phase/index.js +46 -0
  33. package/dist/pool.js +4 -2
  34. package/dist/pr-title.d.ts +5 -0
  35. package/dist/pr-title.js +18 -0
  36. package/dist/reference-files.d.ts +27 -0
  37. package/dist/reference-files.js +202 -0
  38. package/dist/run-attachments.d.ts +79 -0
  39. package/dist/run-attachments.js +276 -0
  40. package/dist/secret-scan.d.ts +1 -1
  41. package/dist/secret-scan.js +3 -0
  42. package/dist/secret-values.d.ts +17 -0
  43. package/dist/secret-values.js +81 -0
  44. package/dist/trail/chain.d.ts +12 -0
  45. package/dist/trail/chain.js +89 -0
  46. package/dist/trail/deltas.d.ts +34 -0
  47. package/dist/trail/deltas.js +206 -0
  48. package/dist/trail/index.d.ts +27 -0
  49. package/dist/trail/index.js +128 -0
  50. package/dist/trail/keys.d.ts +14 -0
  51. package/dist/trail/keys.js +61 -0
  52. package/dist/trail/recorder.d.ts +118 -0
  53. package/dist/trail/recorder.js +697 -0
  54. package/dist/trail/rules.d.ts +30 -0
  55. package/dist/trail/rules.js +158 -0
  56. package/dist/trail/stream.d.ts +41 -0
  57. package/dist/trail/stream.js +86 -0
  58. package/package.json +1 -1
  59. package/skill/firefunc/SKILL.md +3 -3
@@ -0,0 +1,126 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { exec } from './exec.js';
4
+ const DAY = 86_400_000;
5
+ export const KEEP_DAYS = 15;
6
+ const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
7
+ export function keptDir(runnerDir) {
8
+ return join(runnerDir, 'kept');
9
+ }
10
+ function fileFor(runnerDir, runId) {
11
+ return typeof runId === 'string' && RUN_ID.test(runId)
12
+ ? join(keptDir(runnerDir), `${runId}.json`)
13
+ : null;
14
+ }
15
+ export function keepUntilFrom(at) {
16
+ return new Date(at + KEEP_DAYS * DAY).toISOString();
17
+ }
18
+ export function saveKept(runnerDir, rec) {
19
+ const file = fileFor(runnerDir, rec.runId);
20
+ if (!file)
21
+ return false;
22
+ try {
23
+ mkdirSync(keptDir(runnerDir), { recursive: true, mode: 0o700 });
24
+ const tmp = `${file}.${process.pid}.tmp`;
25
+ writeFileSync(tmp, `${JSON.stringify(rec, null, 2)}\n`, { mode: 0o600 });
26
+ renameSync(tmp, file);
27
+ return true;
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ }
33
+ export function listKept(runnerDir) {
34
+ const dir = keptDir(runnerDir);
35
+ if (!existsSync(dir))
36
+ return [];
37
+ const out = [];
38
+ for (const name of readdirSync(dir)) {
39
+ if (!name.endsWith('.json'))
40
+ continue;
41
+ try {
42
+ const rec = JSON.parse(readFileSync(join(dir, name), 'utf8'));
43
+ if (rec &&
44
+ typeof rec.runId === 'string' &&
45
+ typeof rec.worktree === 'string' &&
46
+ typeof rec.branch === 'string' &&
47
+ typeof rec.head === 'string' &&
48
+ typeof rec.keepUntil === 'string') {
49
+ out.push(rec);
50
+ }
51
+ }
52
+ catch {
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+ export function keptFor(runnerDir, runId) {
58
+ const file = fileFor(runnerDir, runId);
59
+ if (!file || !existsSync(file))
60
+ return null;
61
+ return listKept(runnerDir).find((k) => k.runId === runId) ?? null;
62
+ }
63
+ export function dropKept(runnerDir, runId) {
64
+ const file = fileFor(runnerDir, runId);
65
+ if (!file)
66
+ return;
67
+ try {
68
+ unlinkSync(file);
69
+ }
70
+ catch {
71
+ }
72
+ }
73
+ export function keptRunIds(runnerDir) {
74
+ return listKept(runnerDir)
75
+ .map((k) => k.runId)
76
+ .sort();
77
+ }
78
+ export function keptChangeWorktrees(runnerDir) {
79
+ return new Set(listKept(runnerDir).map((k) => k.worktree));
80
+ }
81
+ export function expiredKept(runnerDir, now = Date.now()) {
82
+ return listKept(runnerDir).filter((k) => Date.parse(k.keepUntil) <= now);
83
+ }
84
+ export const FILES_MAX = 300;
85
+ export function parseNumstat(out) {
86
+ const files = [];
87
+ let added = 0;
88
+ let removed = 0;
89
+ let count = 0;
90
+ for (const entry of out.split('\0')) {
91
+ const m = /^(-|\d+)\t(-|\d+)\t([\s\S]+)$/.exec(entry.replace(/^\n+/, ''));
92
+ if (!m)
93
+ continue;
94
+ count += 1;
95
+ const a = m[1] === '-' ? null : Number(m[1]);
96
+ const r = m[2] === '-' ? null : Number(m[2]);
97
+ added += a ?? 0;
98
+ removed += r ?? 0;
99
+ if (files.length < FILES_MAX)
100
+ files.push({ path: m[3].slice(0, 1024), added: a, removed: r });
101
+ }
102
+ return { files, filesChanged: count, added, removed, truncated: count > files.length };
103
+ }
104
+ export async function changesOf(worktree, from, branch) {
105
+ const r = await exec('git', [
106
+ '-C',
107
+ worktree,
108
+ '-c',
109
+ 'core.quotepath=off',
110
+ 'diff',
111
+ '--numstat',
112
+ '--no-renames',
113
+ '-z',
114
+ `${from}...refs/heads/${branch}`,
115
+ ], { timeoutMs: 120_000 }).catch(() => null);
116
+ if (!r || r.code !== 0)
117
+ return null;
118
+ return parseNumstat(r.stdout);
119
+ }
120
+ export function reviseBrief(note, round) {
121
+ return (`A person looked at the change you made on this task and asked for changes before anything is pushed (round ${round}). ` +
122
+ `Their note:\n\n${note.trim()}\n\n` +
123
+ 'Make those changes in this same checkout, on top of what you already did. Nothing has been pushed yet: ' +
124
+ 'when you finish, the person is asked again.');
125
+ }
126
+ //# sourceMappingURL=ask-first.js.map
package/dist/brief.d.ts CHANGED
@@ -3,6 +3,8 @@ import type { RunnerConfig } from './config.js';
3
3
  export declare function engineRules(opts: {
4
4
  minutes: number;
5
5
  heavy: boolean;
6
+ device?: boolean;
7
+ attach?: boolean;
6
8
  }): string;
7
9
  export declare function continueToFinishBrief(open: string[]): string;
8
10
  export declare function scanBeforePush(worktree: string, from: string, branch: string): Promise<{
package/dist/brief.js CHANGED
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { exec, execOut } from './exec.js';
5
5
  import { resolveRepoPath } from './job.js';
6
+ import { ATTACH_RULE } from './run-attachments.js';
6
7
  import { changeReads, hardFirst, refusesPush, scanAddedLines, secretRefusal, uniqueHits, } from './secret-scan.js';
7
8
  function out(msg) {
8
9
  process.stdout.write(`${msg}\n`);
@@ -15,6 +16,11 @@ export function engineRules(opts) {
15
16
  if (opts.heavy) {
16
17
  lines.push('- Other sessions on this machine may be working in this same repository. Run a heavy command — a build or type-check of the whole project, the full test suite — as `"$FIREFUNC_HEAVY" <command>`: it waits for any other heavy command in this repository to finish first, so they take turns instead of running at once.');
17
18
  }
19
+ if (opts.device) {
20
+ lines.push('- The device (an Android emulator or a connected phone) is shared by every session on this machine. Run all device work — starting, restarting or stopping the emulator, installing on it, driving it, recording its screen — through `"$FIREFUNC_DEVICE" <command>` (wrap several steps in one `"$FIREFUNC_DEVICE" sh -c \'…\'`), not through $FIREFUNC_HEAVY. Build the APK first, outside the device lock, so you never hold one lock while waiting for the other. If an emulator is already running, use it as it is; never kill a process you did not start, and put back any setting you changed on it (airplane mode, network, proxy) before you let go.');
21
+ }
22
+ if (opts.attach)
23
+ lines.push(ATTACH_RULE);
18
24
  lines.push(`- You have at most ${opts.minutes} minutes; the session is stopped when they run out. Leave time to finish and to say what you proved.`);
19
25
  return `${lines.join('\n')}\n\n`;
20
26
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.9.6",
3
- "builtAt": "2026-10-02T17:48:54.080Z"
2
+ "version": "0.9.14",
3
+ "builtAt": "2026-10-16T17:30:06.883Z"
4
4
  }
package/dist/config.d.ts CHANGED
@@ -32,6 +32,8 @@ export type RunnerConfig = {
32
32
  maxBudgetUsd?: number;
33
33
  claudeCodeOAuthToken?: string;
34
34
  claudeUseApiKey?: boolean;
35
+ claudeApiKeyFallback?: boolean;
36
+ claudeApiKeyFile?: string;
35
37
  claudeArgs?: string[];
36
38
  jobTimeoutMinutes?: number;
37
39
  mcpRelay?: boolean;
package/dist/cut.d.ts CHANGED
@@ -20,6 +20,7 @@ export type CutSession = {
20
20
  continuesBranch: boolean;
21
21
  usage?: RunUsage;
22
22
  writtenSkills?: WrittenSkills;
23
+ reason?: 'plan_limit' | 'timeout';
23
24
  };
24
25
  export declare function cutDir(runnerDir: string): string;
25
26
  export declare function promptHash(prompt: string): string;
@@ -42,4 +43,5 @@ export declare function cutFor(runnerDir: string, key: CutKey, now?: number): {
42
43
  } | null;
43
44
  export declare function expiredCuts(runnerDir: string, now?: number): CutSession[];
44
45
  export declare function keptWorktrees(runnerDir: string): Set<string>;
45
- export declare function resumeAfterResetBrief(prompt: string, briefChanged: boolean): string;
46
+ export declare function cutWorktrees(runnerDir: string): Set<string>;
47
+ export declare function resumeAfterResetBrief(prompt: string, briefChanged: boolean, reason?: CutSession['reason']): string;
package/dist/cut.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
3
3
  import { join } from 'node:path';
4
+ import { keptChangeWorktrees } from './ask-first.js';
4
5
  const DAY = 86_400_000;
5
6
  const ITEM_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
6
7
  export function cutDir(runnerDir) {
@@ -91,12 +92,22 @@ export function expiredCuts(runnerDir, now = Date.now()) {
91
92
  return listCuts(runnerDir).filter((c) => Date.parse(c.keepUntil) <= now);
92
93
  }
93
94
  export function keptWorktrees(runnerDir) {
95
+ return new Set([
96
+ ...listCuts(runnerDir).map((c) => c.worktree),
97
+ ...keptChangeWorktrees(runnerDir),
98
+ ]);
99
+ }
100
+ export function cutWorktrees(runnerDir) {
94
101
  return new Set(listCuts(runnerDir).map((c) => c.worktree));
95
102
  }
96
- export function resumeAfterResetBrief(prompt, briefChanged) {
97
- return ("Your session on this task was stopped by the plan's usage limit, which has now reset. " +
98
- 'The worktree still holds everything you did — check `git status` and `git diff`, then ' +
99
- 'continue from where you stopped and finish the task.' +
103
+ export function resumeAfterResetBrief(prompt, briefChanged, reason = 'plan_limit') {
104
+ return ((reason === 'timeout'
105
+ ? "Your previous attempt on this task reached this machine's time limit before it finished. " +
106
+ 'The worktree still holds everything you did — check `git status` and `git diff`, then ' +
107
+ 'continue from where you stopped and finish the task; do not redo what is already done.'
108
+ : "Your session on this task was stopped by the plan's usage limit, which has now reset. " +
109
+ 'The worktree still holds everything you did — check `git status` and `git diff`, then ' +
110
+ 'continue from where you stopped and finish the task.') +
100
111
  (briefChanged
101
112
  ? ' FireFunc sent this run a brief that differs from the one you started with; it follows, and where the two differ, follow this one.\n\n' +
102
113
  prompt
package/dist/daemon.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { existsSync, rmSync } from 'node:fs';
2
+ import { blankSecrets } from './secret-values.js';
2
3
  import { flushPendingResults, listPendingResults } from './pending.js';
3
- import { runnerDir } from './config.js';
4
+ import { flushPendingTrails } from './trail/index.js';
5
+ import { loadConfig, runnerDir } from './config.js';
4
6
  import { hostname, platform } from 'node:os';
5
7
  import { RunnerApi } from './api.js';
6
8
  import { availableEngines, getAdapter, supportedEngines } from './engines/index.js';
@@ -10,15 +12,17 @@ import { runJobPool } from './pool.js';
10
12
  import { machineLogins } from './machine-logins.js';
11
13
  import { RUNNER_VERSION } from './version.js';
12
14
  import { LimitGate } from './limit.js';
15
+ import { fallbackKey } from './api-fallback.js';
13
16
  import { heldByLiveProcesses, liveWorktrees, recordHeld, releaseHeld } from './held.js';
14
17
  import { recoverPreviousProcess } from './recover.js';
15
- import { dropCut, expiredCuts, keptWorktrees } from './cut.js';
18
+ import { cutWorktrees, dropCut, expiredCuts, keptWorktrees } from './cut.js';
19
+ import { dropKept, expiredKept, keptFor, keptRunIds } from './ask-first.js';
16
20
  import { removeRunnerWorktree, sweepLeftoverWorktrees } from './worktrees.js';
17
21
  import { signalEngineGroups } from './orphans.js';
18
22
  import { engineBlocks, unattendedContext } from './unattended.js';
19
23
  import { claimPause, engineWatch } from './engine-watch.js';
20
24
  function log(msg) {
21
- console.log(`[firefunc-runner] ${new Date().toISOString()} ${msg}`);
25
+ console.log(`[firefunc-runner] ${new Date().toISOString()} ${blankSecrets(msg)}`);
22
26
  }
23
27
  export function claimState(s) {
24
28
  const held = [...new Set([...s.holding, ...s.pending])].sort();
@@ -121,6 +125,13 @@ export async function startDaemon(cfg) {
121
125
  });
122
126
  let serverMax = 1;
123
127
  const refreshConfig = async () => {
128
+ const saved = loadConfig();
129
+ if (saved) {
130
+ cfg.maxParallel = saved.maxParallel;
131
+ cfg.jobTimeoutMinutes = saved.jobTimeoutMinutes;
132
+ cfg.claudeApiKeyFallback = saved.claudeApiKeyFallback;
133
+ cfg.claudeApiKeyFile = saved.claudeApiKeyFile;
134
+ }
124
135
  const c = await api.config();
125
136
  if (c)
126
137
  serverMax = Math.max(1, Math.floor(c.maxParallel));
@@ -193,6 +204,33 @@ export async function startDaemon(cfg) {
193
204
  };
194
205
  await dropExpiredCuts().catch(() => { });
195
206
  let lastCutSweep = Date.now();
207
+ const letGo = async (k, why) => {
208
+ if (holding.has(k.runId))
209
+ return;
210
+ log(`the change kept for ${k.runId} ${why} — removing it from this machine`);
211
+ if (!cutWorktrees(rdir).has(k.worktree)) {
212
+ if (k.repoPath && existsSync(k.repoPath)) {
213
+ await removeRunnerWorktree(k.repoPath, k.worktree, log).catch(() => { });
214
+ }
215
+ else {
216
+ try {
217
+ rmSync(k.worktree, { recursive: true, force: true });
218
+ }
219
+ catch {
220
+ }
221
+ }
222
+ }
223
+ dropKept(rdir, k.runId);
224
+ };
225
+ const onDiscard = (runIds) => {
226
+ for (const id of runIds) {
227
+ const k = keptFor(rdir, id);
228
+ if (k)
229
+ void letGo(k, 'is no longer waiting in FireFunc');
230
+ }
231
+ };
232
+ for (const k of expiredKept(rdir))
233
+ await letGo(k, 'was not answered in time').catch(() => { });
196
234
  try {
197
235
  const checkouts = Object.values(cfg.repos ?? {}).filter((p) => existsSync(p));
198
236
  const removed = await sweepLeftoverWorktrees(checkouts, {
@@ -206,6 +244,7 @@ export async function startDaemon(cfg) {
206
244
  catch {
207
245
  }
208
246
  const gate = new LimitGate(LimitGate.fileIn(rdir));
247
+ gate.waive = (engine) => engine === 'claude_code' && fallbackKey(cfg, rdir) !== null;
209
248
  const limitReports = () => gate.active().map((l) => ({ engine: l.engine, kind: 'plan', resetsAt: l.resetsAt }));
210
249
  const paused = claimPause({ watch: declared, isLimited: (e) => gate.isLimited(e), log });
211
250
  const claimBody = (extra = {}) => ({
@@ -222,6 +261,7 @@ export async function startDaemon(cfg) {
222
261
  expiresAt: l.expiresAt,
223
262
  ...(l.detail ? { detail: l.detail } : {}),
224
263
  })),
264
+ awaitingRuns: keptRunIds(rdir),
225
265
  ...claimState({
226
266
  holding: [...holding, ...heldByLiveProcesses(rdir)],
227
267
  pending: pendingIds(),
@@ -252,7 +292,9 @@ export async function startDaemon(cfg) {
252
292
  heartbeat: async ({ draining, paused: waitingOutLimit }) => {
253
293
  if (waitingOutLimit && heartbeatIgnored)
254
294
  return null;
255
- const job = await api.claim(claimBody({ heartbeat: true, draining })).catch(() => null);
295
+ const job = await api
296
+ .claim(claimBody({ heartbeat: true, draining }), { onDiscard })
297
+ .catch(() => null);
256
298
  if (job) {
257
299
  heartbeatIgnored = true;
258
300
  log(`FireFunc handed ${job.runId} to a heartbeat — running it`);
@@ -264,12 +306,16 @@ export async function startDaemon(cfg) {
264
306
  if (flushed && (flushed.delivered || flushed.refused)) {
265
307
  log(`pending results: ${flushed.delivered} delivered, ${flushed.refused} refused, ${flushed.kept} kept`);
266
308
  }
309
+ await flushPendingTrails(rdir, (runId, batch) => api.trail(runId, batch)).catch(() => null);
267
310
  declared.rescan();
268
311
  if (Date.now() - lastCutSweep > 10 * 60_000) {
269
312
  lastCutSweep = Date.now();
270
313
  await dropExpiredCuts().catch(() => { });
314
+ for (const k of expiredKept(rdir)) {
315
+ await letGo(k, 'was not answered in time').catch(() => { });
316
+ }
271
317
  }
272
- const job = await api.claim(claimBody());
318
+ const job = await api.claim(claimBody(), { onDiscard });
273
319
  lostRuns = [];
274
320
  backoffMs = 2_000;
275
321
  return job;
@@ -3,6 +3,7 @@ import { readClaudeBudget } from './claude-budget.js';
3
3
  import { readClaudeUsage } from '../usage.js';
4
4
  import { mcpFromContext } from '../mcp.js';
5
5
  import { readClaudeLimit } from '../limit.js';
6
+ import { claudeApiKeyNow } from '../api-fallback.js';
6
7
  import { commandName } from '../keep-local.js';
7
8
  function claudeSummary(streamJson) {
8
9
  const lines = streamJson.trim().split('\n');
@@ -191,14 +192,19 @@ export const claudeAdapter = {
191
192
  args.push('--mcp-config', mcp.configPath, '--strict-mcp-config');
192
193
  }
193
194
  args.push(...(cfg.claudeArgs ?? []));
195
+ const billing = claudeApiKeyNow(cfg);
194
196
  const env = cfg.claudeUseApiKey
195
197
  ? ctx.runEnv
196
- : { ...ctx.runEnv, ANTHROPIC_API_KEY: undefined };
198
+ : billing.key
199
+ ? { ...ctx.runEnv, ANTHROPIC_API_KEY: billing.key }
200
+ : { ...ctx.runEnv, ANTHROPIC_API_KEY: undefined };
197
201
  const authLogLine = cfg.claudeUseApiKey
198
202
  ? 'ANTHROPIC_API_KEY (API billing — opted in)'
199
- : cfg.claudeCodeOAuthToken
200
- ? 'subscription token'
201
- : 'your machine Claude login (API key hidden — subscription billing)';
203
+ : billing.key
204
+ ? 'ANTHROPIC_API_KEY (API billing — the plan is spent, until it resets)'
205
+ : cfg.claudeCodeOAuthToken
206
+ ? 'subscription token'
207
+ : 'your machine Claude login (API key hidden — subscription billing)';
202
208
  return {
203
209
  bin: this.bin(cfg),
204
210
  args,
@@ -61,8 +61,9 @@ export const copilotCliAdapter = {
61
61
  ];
62
62
  if (ctx.model)
63
63
  args.push('--model', ctx.model);
64
- if (ctx.effort)
65
- args.push('--effort', ctx.effort);
64
+ const effort = ctx.ultracode || ctx.effort === 'ultracode' ? 'xhigh' : ctx.effort;
65
+ if (effort)
66
+ args.push('--effort', effort);
66
67
  if (ctx.maxBudgetUsd)
67
68
  args.push('--max-ai-credits', String(ctx.maxBudgetUsd));
68
69
  if (ctx.attachDir && ctx.attachPaths.length)
@@ -74,7 +74,7 @@ const SPEC_FIELDS = "The spec is the composer's own agent body, as JSON (firefun
74
74
  ' tool_grants { <tool or MCP server slug>: { read, write } } — only tools the\n' +
75
75
  " project has bound. Left out: the template's, or GitHub read+write\n" +
76
76
  ' deliverables [{ id, action: "tool.action", params, gate, position }]\n' +
77
- ' guardrails left out: Preview (dry_run_mode true, auto_merge false)\n' +
77
+ ' guardrails left out: Autonomous (dry_run_mode false, auto_merge false)\n' +
78
78
  ' caps { runs_per_day, max_in_flight } — left out: { runs_per_day: 5 }\n' +
79
79
  ' description, schedule, skills (installed slugs), engine, engine_firmness\n' +
80
80
  "The API checks it the way the composer's Save does and refuses what it would refuse,\n" +
@@ -18,6 +18,7 @@ export declare function openDraftPr(args: {
18
18
  title: string;
19
19
  body: string;
20
20
  cred: GitCredential;
21
+ update?: boolean;
21
22
  }): Promise<{
22
23
  url: string;
23
24
  number: number;
package/dist/git-auth.js CHANGED
@@ -69,8 +69,16 @@ export async function openDraftPr(args) {
69
69
  if (list.ok) {
70
70
  const rows = (await list.json());
71
71
  const hit = rows.find((r) => typeof r.html_url === 'string' && Number.isFinite(r.number));
72
- if (hit)
72
+ if (hit) {
73
+ if (args.update) {
74
+ await fetch(`https://api.github.com/repos/${repo}/pulls/${Number(hit.number)}`, {
75
+ method: 'PATCH',
76
+ headers,
77
+ body: JSON.stringify({ title, body }),
78
+ }).catch(() => undefined);
79
+ }
73
80
  return { url: hit.html_url, number: Number(hit.number) };
81
+ }
74
82
  }
75
83
  }
76
84
  return { error: `github refused to open the pull request (${res.status})` };