@firefunc-agent/runner 0.9.37 → 0.9.40

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 (70) hide show
  1. package/README.md +21 -0
  2. package/dist/activity.d.ts +2 -0
  3. package/dist/activity.js +3 -0
  4. package/dist/alive.d.ts +8 -0
  5. package/dist/alive.js +29 -0
  6. package/dist/api.d.ts +32 -0
  7. package/dist/api.js +18 -2
  8. package/dist/ask-replace.d.ts +6 -0
  9. package/dist/ask-replace.js +49 -0
  10. package/dist/awake-timer.d.ts +8 -0
  11. package/dist/awake-timer.js +30 -0
  12. package/dist/brief.js +2 -2
  13. package/dist/build-info.json +2 -2
  14. package/dist/clean-up.d.ts +29 -0
  15. package/dist/clean-up.js +131 -0
  16. package/dist/cli.js +57 -6
  17. package/dist/config.d.ts +7 -0
  18. package/dist/cut.d.ts +2 -0
  19. package/dist/cut.js +20 -3
  20. package/dist/daemon.js +115 -5
  21. package/dist/disk-reclaim.d.ts +40 -0
  22. package/dist/disk-reclaim.js +95 -0
  23. package/dist/drives.d.ts +29 -0
  24. package/dist/drives.js +270 -0
  25. package/dist/engine-account.d.ts +1 -1
  26. package/dist/engine-account.js +12 -1
  27. package/dist/engines/types.d.ts +1 -1
  28. package/dist/exec.js +5 -6
  29. package/dist/firefunc/automations.js +3 -3
  30. package/dist/firefunc/main.js +1 -1
  31. package/dist/firefunc/oauth-login.js +1 -1
  32. package/dist/gh-repos.d.ts +41 -0
  33. package/dist/gh-repos.js +68 -0
  34. package/dist/git-auth.d.ts +1 -0
  35. package/dist/git-auth.js +1 -1
  36. package/dist/held.d.ts +4 -2
  37. package/dist/held.js +19 -5
  38. package/dist/job.d.ts +1 -0
  39. package/dist/job.js +148 -33
  40. package/dist/keep-local.d.ts +1 -0
  41. package/dist/keep-local.js +63 -0
  42. package/dist/local-tools.d.ts +31 -0
  43. package/dist/local-tools.js +178 -0
  44. package/dist/machine-logins.d.ts +4 -0
  45. package/dist/machine-logins.js +31 -0
  46. package/dist/mcp-login.d.ts +3 -0
  47. package/dist/mcp-login.js +34 -4
  48. package/dist/mcp-tools.d.ts +23 -0
  49. package/dist/mcp-tools.js +122 -0
  50. package/dist/mcp.d.ts +8 -0
  51. package/dist/mcp.js +37 -3
  52. package/dist/pool.d.ts +1 -0
  53. package/dist/pool.js +1 -0
  54. package/dist/pr-title.d.ts +1 -0
  55. package/dist/pr-title.js +7 -0
  56. package/dist/repo-path.d.ts +15 -0
  57. package/dist/repo-path.js +56 -0
  58. package/dist/resources.d.ts +38 -0
  59. package/dist/resources.js +47 -1
  60. package/dist/restart-idle.d.ts +1 -0
  61. package/dist/restart-idle.js +20 -5
  62. package/dist/run-folders.d.ts +25 -0
  63. package/dist/run-folders.js +89 -0
  64. package/dist/viewer.d.ts +1 -1
  65. package/dist/viewer.js +3 -1
  66. package/dist/work-dir.d.ts +30 -0
  67. package/dist/work-dir.js +153 -22
  68. package/dist/worktrees.d.ts +7 -0
  69. package/dist/worktrees.js +26 -5
  70. package/package.json +1 -1
package/dist/drives.js ADDED
@@ -0,0 +1,270 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { accessSync, constants, readdirSync, statSync } from 'node:fs';
3
+ import { homedir, platform, userInfo } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { lstat, readdir } from 'node:fs/promises';
6
+ import { diskOf } from './resources.js';
7
+ import { defaultWorkRoot } from './work-dir.js';
8
+ const TEN_MINUTES = 10 * 60_000;
9
+ export async function dirBytes(dir, budgetMs = 20_000) {
10
+ const until = Date.now() + budgetMs;
11
+ let total = 0;
12
+ const stack = [dir];
13
+ while (stack.length) {
14
+ if (Date.now() > until)
15
+ return null;
16
+ const d = stack.pop();
17
+ let names;
18
+ try {
19
+ names = await readdir(d);
20
+ }
21
+ catch {
22
+ continue;
23
+ }
24
+ for (const n of names) {
25
+ const p = join(d, n);
26
+ try {
27
+ const st = await lstat(p);
28
+ if (st.isDirectory())
29
+ stack.push(p);
30
+ else
31
+ total += st.size;
32
+ }
33
+ catch {
34
+ }
35
+ }
36
+ }
37
+ return total;
38
+ }
39
+ export function parseWmicDrives(out) {
40
+ const lines = out
41
+ .split(/\r?\n/)
42
+ .map((l) => l.trim())
43
+ .filter(Boolean);
44
+ const header = lines.shift();
45
+ if (!header || !/deviceid/i.test(header))
46
+ return [];
47
+ const cols = header.split(/\s+/).map((c) => c.toLowerCase());
48
+ const iId = cols.indexOf('deviceid');
49
+ const iFree = cols.indexOf('freespace');
50
+ const iSize = cols.indexOf('size');
51
+ const rows = [];
52
+ for (const l of lines) {
53
+ const f = l.split(/\s+/);
54
+ const id = f[iId] ?? '';
55
+ const free = Number(f[iFree]);
56
+ const size = Number(f[iSize]);
57
+ if (!/^[A-Za-z]:$/.test(id) || !Number.isFinite(free) || !Number.isFinite(size))
58
+ continue;
59
+ rows.push({ id: id.toUpperCase(), freeBytes: free, totalBytes: size });
60
+ }
61
+ return rows;
62
+ }
63
+ export function parseCimDrives(out) {
64
+ let v;
65
+ try {
66
+ v = JSON.parse(out.trim() || 'null');
67
+ }
68
+ catch {
69
+ return [];
70
+ }
71
+ const list = Array.isArray(v) ? v : v && typeof v === 'object' ? [v] : [];
72
+ const rows = [];
73
+ for (const d of list) {
74
+ const id = typeof d.DeviceID === 'string' ? d.DeviceID : '';
75
+ const num = (x) => typeof x === 'number' || (typeof x === 'string' && x.trim()) ? Number(x) : NaN;
76
+ const free = num(d.FreeSpace);
77
+ const size = num(d.Size);
78
+ if (!/^[A-Za-z]:$/.test(id) || !Number.isFinite(free) || !Number.isFinite(size))
79
+ continue;
80
+ rows.push({ id: id.toUpperCase(), freeBytes: free, totalBytes: size });
81
+ }
82
+ return rows;
83
+ }
84
+ export function parseDfMounts(out) {
85
+ const rows = [];
86
+ for (const line of out.split(/\r?\n/).slice(1)) {
87
+ const m = /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+(.+)$/.exec(line.trim());
88
+ if (!m)
89
+ continue;
90
+ rows.push({
91
+ filesystem: m[1],
92
+ totalBytes: Number(m[2]) * 1024,
93
+ freeBytes: Number(m[4]) * 1024,
94
+ mount: m[5],
95
+ });
96
+ }
97
+ return rows;
98
+ }
99
+ const writable = (p) => {
100
+ try {
101
+ accessSync(p, constants.W_OK);
102
+ return true;
103
+ }
104
+ catch {
105
+ return false;
106
+ }
107
+ };
108
+ export function mountOf(path, mounts) {
109
+ let best = null;
110
+ for (const m of mounts) {
111
+ const prefix = m === '/' ? '/' : `${m}/`;
112
+ if ((path === m || path.startsWith(prefix)) && (!best || m.length > best.length))
113
+ best = m;
114
+ }
115
+ return best;
116
+ }
117
+ export function pickLinuxMounts(mounts, home, user, canWrite = writable) {
118
+ const out = new Set();
119
+ if (mounts.includes('/'))
120
+ out.add('/');
121
+ const h = mountOf(home, mounts);
122
+ if (h)
123
+ out.add(h);
124
+ const under = ['/mnt/', `/media/${user}/`, `/run/media/${user}/`];
125
+ for (const m of mounts) {
126
+ if (under.some((u) => m.startsWith(u)) && canWrite(m))
127
+ out.add(m);
128
+ }
129
+ return [...out];
130
+ }
131
+ function run(cmd, args) {
132
+ try {
133
+ return execFileSync(cmd, args, {
134
+ encoding: 'utf8',
135
+ timeout: 5_000,
136
+ stdio: ['ignore', 'pipe', 'ignore'],
137
+ windowsHide: true,
138
+ });
139
+ }
140
+ catch {
141
+ return null;
142
+ }
143
+ }
144
+ export function readDrives(os = platform()) {
145
+ try {
146
+ const home = homedir();
147
+ const root = defaultWorkRoot();
148
+ const sized = (mount, fallback) => diskOf(mount) ?? fallback ?? null;
149
+ if (os === 'win32') {
150
+ const ps = run('powershell.exe', [
151
+ '-NoProfile',
152
+ '-NonInteractive',
153
+ '-Command',
154
+ 'Get-CimInstance Win32_LogicalDisk -Filter DriveType=3 | Select-Object DeviceID,FreeSpace,Size | ConvertTo-Json -Compress',
155
+ ]);
156
+ let rows = ps ? parseCimDrives(ps) : [];
157
+ if (!rows.length) {
158
+ const w = run('wmic', [
159
+ 'logicaldisk',
160
+ 'where',
161
+ 'drivetype=3',
162
+ 'get',
163
+ 'deviceid,freespace,size',
164
+ ]);
165
+ rows = w ? parseWmicDrives(w) : [];
166
+ }
167
+ const homeDrive = home.slice(0, 2).toUpperCase();
168
+ return rows.flatMap((r) => {
169
+ const d = sized(`${r.id}\\`, r);
170
+ if (!d)
171
+ return [];
172
+ return [
173
+ {
174
+ id: r.id,
175
+ label: r.id,
176
+ path: r.id === homeDrive ? root : `${r.id}\\FireFunc`,
177
+ freeBytes: d.freeBytes,
178
+ totalBytes: d.totalBytes,
179
+ },
180
+ ];
181
+ });
182
+ }
183
+ if (os === 'darwin') {
184
+ const out = [];
185
+ const boot = statSync('/').dev;
186
+ const d = sized('/');
187
+ if (d)
188
+ out.push({ id: '/', label: 'Macintosh HD', path: root, ...d });
189
+ let names = [];
190
+ try {
191
+ names = readdirSync('/Volumes');
192
+ }
193
+ catch {
194
+ names = [];
195
+ }
196
+ for (const n of names) {
197
+ const p = join('/Volumes', n);
198
+ try {
199
+ if (statSync(p).dev === boot || !writable(p))
200
+ continue;
201
+ }
202
+ catch {
203
+ continue;
204
+ }
205
+ const v = sized(p);
206
+ if (v)
207
+ out.push({ id: p, label: n, path: join(p, 'FireFunc'), ...v });
208
+ }
209
+ return out;
210
+ }
211
+ const df = run('df', ['-kP']);
212
+ const rows = df ? parseDfMounts(df) : [];
213
+ const mounts = rows.map((r) => r.mount);
214
+ let user = '';
215
+ try {
216
+ user = userInfo().username;
217
+ }
218
+ catch {
219
+ user = process.env.USER ?? '';
220
+ }
221
+ const homeMount = mountOf(home, mounts);
222
+ return pickLinuxMounts(mounts, home, user).flatMap((m) => {
223
+ const r = rows.find((x) => x.mount === m);
224
+ const d = sized(m, r);
225
+ if (!d)
226
+ return [];
227
+ return [
228
+ {
229
+ id: m,
230
+ label: m === '/' ? 'System' : (m.split('/').pop() ?? m),
231
+ path: m === homeMount ? root : join(m, 'FireFunc'),
232
+ freeBytes: d.freeBytes,
233
+ totalBytes: d.totalBytes,
234
+ },
235
+ ];
236
+ });
237
+ }
238
+ catch {
239
+ return [];
240
+ }
241
+ }
242
+ let drivesAt = -Infinity;
243
+ let drives = [];
244
+ export function driveReport(now = Date.now(), read = readDrives) {
245
+ if (now - drivesAt >= TEN_MINUTES) {
246
+ drives = read();
247
+ drivesAt = now;
248
+ }
249
+ return drives;
250
+ }
251
+ const sizes = new Map();
252
+ export function rootBytes(root, now = Date.now(), walk = (d) => dirBytes(d, 20_000)) {
253
+ const s = sizes.get(root);
254
+ if (!s || (!s.walking && now - s.at >= TEN_MINUTES)) {
255
+ const entry = { at: now, bytes: s?.bytes ?? null, walking: true };
256
+ sizes.set(root, entry);
257
+ void walk(root)
258
+ .then((b) => {
259
+ entry.bytes = b;
260
+ })
261
+ .catch(() => {
262
+ entry.bytes = null;
263
+ })
264
+ .finally(() => {
265
+ entry.walking = false;
266
+ });
267
+ }
268
+ return sizes.get(root).bytes;
269
+ }
270
+ //# sourceMappingURL=drives.js.map
@@ -1,6 +1,6 @@
1
1
  import type { EngineEnding } from './declined.js';
2
2
  import type { EngineId, UnattendedBlock } from './engines/types.js';
3
- export type AccountProblem = 'not_signed_in' | 'api_key_no_credit';
3
+ export type AccountProblem = 'not_signed_in' | 'api_key_no_credit' | 'needs_paid_tier';
4
4
  export declare const ACCOUNT_RETRY_FIRST_MS: number;
5
5
  export declare const ACCOUNT_RETRY_MAX_MS: number;
6
6
  export declare function accountProblemOf(ending: EngineEnding | undefined, opts: {
@@ -7,7 +7,8 @@ function noticeLine(text) {
7
7
  return first && first.length <= 300 ? first : null;
8
8
  }
9
9
  const NO_CREDIT = /\bcredit balance is too low\b/i;
10
- const SIGNED_OUT = /^(?:error:\s*)?(?:not logged in\b|login expired\b|(?:please )?run \/login\b|invalid api key\b|invalid x-api-key\b|oauth (?:access )?token (?:has )?(?:expired|been revoked)\b|failed to authenticate\b|api error: 401\b)|\bauthentication_error\b|\bineligibletiererror\b/i;
10
+ const SIGNED_OUT = /^(?:error:\s*)?(?:not logged in\b|login expired\b|(?:please )?run \/login\b|invalid api key\b|invalid x-api-key\b|oauth (?:access )?token (?:has )?(?:expired|been revoked)\b|failed to authenticate\b|api error: 401\b)|\bauthentication_error\b/i;
11
+ const TIER = /\bineligibletiererror\b|\bnot eligible for\b|\brequires? a paid (?:plan|tier)\b|\bupgrade (?:your|to a) (?:plan|tier)\b/i;
11
12
  export function accountProblemOf(ending, opts) {
12
13
  let line;
13
14
  if (ending) {
@@ -23,6 +24,8 @@ export function accountProblemOf(ending, opts) {
23
24
  return null;
24
25
  if (NO_CREDIT.test(line))
25
26
  return 'api_key_no_credit';
27
+ if (TIER.test(line))
28
+ return 'needs_paid_tier';
26
29
  if (SIGNED_OUT.test(line)) {
27
30
  if (opts.billedKey && /api key|x-api-key/i.test(line))
28
31
  return null;
@@ -40,6 +43,14 @@ export function accountBlock(code, engineName, retryInMinutes) {
40
43
  detail: `${engineName} is not signed in on this machine — run \`claude\` and \`/login\` there`,
41
44
  };
42
45
  }
46
+ if (code === 'needs_paid_tier') {
47
+ return {
48
+ code,
49
+ reason: `${engineName}'s account on this machine is on a tier that cannot run it ("not eligible" — IneligibleTierError), so every run it started would stop the same way.`,
50
+ fix: `Move the account to a paid tier, or give ${engineName} an API key (for Gemini CLI: GEMINI_API_KEY from Google AI Studio). ${again}`,
51
+ detail: `${engineName} needs a paid tier on this machine's account`,
52
+ };
53
+ }
43
54
  return {
44
55
  code,
45
56
  reason: `The Anthropic API key ${engineName} bills on this machine has no credit left ("Credit balance is too low"), so every run it started would stop the same way.`,
@@ -26,7 +26,7 @@ export type UnattendedContext = {
26
26
  permissionMode: string;
27
27
  };
28
28
  export type UnattendedBlock = {
29
- code: 'runs_as_root' | 'not_signed_in' | 'api_key_no_credit';
29
+ code: 'runs_as_root' | 'not_signed_in' | 'api_key_no_credit' | 'needs_paid_tier';
30
30
  reason: string;
31
31
  fix: string;
32
32
  detail: string;
package/dist/exec.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { constants } from 'node:os';
3
3
  import { shellSafe } from './win-shell.js';
4
+ import { awakeTimer } from './awake-timer.js';
4
5
  export function signalExitCode(signal) {
5
6
  const n = signal ? constants.signals[signal] : undefined;
6
7
  return typeof n === 'number' ? 128 + n : 1;
@@ -104,11 +105,11 @@ export function exec(cmd, args, opts = {}) {
104
105
  let timer = null;
105
106
  let timedOut = false;
106
107
  if (opts.timeoutMs) {
107
- timer = setTimeout(() => {
108
+ timer = awakeTimer(opts.timeoutMs, () => {
108
109
  timedOut = true;
109
110
  stop('SIGTERM');
110
111
  setTimeout(() => stop('SIGKILL'), 5_000);
111
- }, opts.timeoutMs);
112
+ }, { tickMs: Math.min(5_000, Math.max(10, Math.floor(opts.timeoutMs / 10))) });
112
113
  }
113
114
  child.stdout?.on('data', (d) => {
114
115
  const s = d.toString();
@@ -117,8 +118,7 @@ export function exec(cmd, args, opts = {}) {
117
118
  });
118
119
  child.stderr?.on('data', (d) => (stderr += d.toString()));
119
120
  child.on('error', (err) => {
120
- if (timer)
121
- clearTimeout(timer);
121
+ timer?.cancel();
122
122
  if (settled)
123
123
  return;
124
124
  settled = true;
@@ -128,8 +128,7 @@ export function exec(cmd, args, opts = {}) {
128
128
  if (settled)
129
129
  return;
130
130
  settled = true;
131
- if (timer)
132
- clearTimeout(timer);
131
+ timer?.cancel();
133
132
  if (exitTimer)
134
133
  clearTimeout(exitTimer);
135
134
  resolve({
@@ -43,7 +43,7 @@ async function printRun(ctx, body) {
43
43
  export const automationCommands = [
44
44
  {
45
45
  path: ['automations', 'list'],
46
- summary: 'The workflows and orchestrations in this workspace',
46
+ summary: 'The automations in this workspace (Steps and Team)',
47
47
  usage: 'automations list [--project <id or name>]',
48
48
  flags: { project: 'string' },
49
49
  flagHelp: [['--project <id or name>', "only this project's automations"]],
@@ -111,7 +111,7 @@ export const automationCommands = [
111
111
  },
112
112
  {
113
113
  path: ['automations', 'create'],
114
- summary: 'Make a workflow or orchestration as a DRAFT (nothing runs until it is published)',
114
+ summary: 'Make an automation as a DRAFT (nothing runs until it is published)',
115
115
  usage: 'automations create --name <name> (--spec <file.json> | --from-template <id> | --kind workflow|orchestration) [--project <id or name>]',
116
116
  flags: {
117
117
  name: 'string',
@@ -127,7 +127,7 @@ export const automationCommands = [
127
127
  '--from-template <id>',
128
128
  'start from a template (automations templates); it brings its agents, paused',
129
129
  ],
130
- ['--kind <kind>', 'an empty workflow or orchestration'],
130
+ ['--kind <kind>', 'an empty automation: workflow (Steps) or orchestration (Team)'],
131
131
  ['--project <id or name>', 'the project it belongs to; left out: the whole workspace'],
132
132
  ],
133
133
  async run(ctx) {
@@ -58,7 +58,7 @@ const SECTIONS = [
58
58
  ],
59
59
  ['Tasks', ['run', 'tasks list', 'tasks get', 'tasks watch', 'tasks states']],
60
60
  [
61
- 'Automations (workflows and orchestrations)',
61
+ 'Automations (Steps and Team)',
62
62
  [
63
63
  'automations list',
64
64
  'automations templates',
@@ -80,7 +80,7 @@ async function register(io, meta) {
80
80
  try {
81
81
  res = await postJson(io, meta.registration_endpoint, {
82
82
  client_name: 'FireFunc CLI',
83
- client_uri: 'https://firefunc.com/docs/connect/',
83
+ client_uri: 'https://firefunc.com/',
84
84
  redirect_uris: [REDIRECT],
85
85
  grant_types: ['authorization_code', 'refresh_token'],
86
86
  response_types: ['code'],
@@ -0,0 +1,41 @@
1
+ export type GhReposReport = {
2
+ state: 'ok' | 'signed_out' | 'no_gh';
3
+ login: string | null;
4
+ checked: string[];
5
+ hidden: string[];
6
+ at: string;
7
+ };
8
+ type Run = (args: string[]) => Promise<{
9
+ code: number;
10
+ stdout: string;
11
+ stderr: string;
12
+ }>;
13
+ export declare function checkGhRepos(repos: readonly string[], run?: Run, now?: Date): Promise<{
14
+ state: "no_gh";
15
+ login: null;
16
+ checked: string[];
17
+ hidden: never[];
18
+ at: string;
19
+ } | {
20
+ state: "signed_out";
21
+ login: null;
22
+ checked: string[];
23
+ hidden: never[];
24
+ at: string;
25
+ } | {
26
+ state: "ok";
27
+ login: string | null;
28
+ checked: string[];
29
+ hidden: string[];
30
+ at: string;
31
+ }>;
32
+ export declare function ghRepoWatch(deps: {
33
+ run?: Run;
34
+ now?: () => number;
35
+ everyMs?: number;
36
+ log?: (msg: string) => void;
37
+ }): {
38
+ update(next: string[] | null): void;
39
+ report(): GhReposReport | null;
40
+ };
41
+ export {};
@@ -0,0 +1,68 @@
1
+ import { exec } from './exec.js';
2
+ const REPO = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;
3
+ const defaultRun = (args) => exec('gh', args, { timeoutMs: 15_000 });
4
+ export async function checkGhRepos(repos, run = defaultRun, now = new Date()) {
5
+ const asked = [...new Set(repos.filter((r) => REPO.test(r)))].slice(0, 40);
6
+ const at = now.toISOString();
7
+ let who;
8
+ try {
9
+ who = await run(['api', 'user', '--jq', '.login']);
10
+ }
11
+ catch {
12
+ return { state: 'no_gh', login: null, checked: asked, hidden: [], at };
13
+ }
14
+ if (who.code !== 0) {
15
+ return {
16
+ state: 'signed_out',
17
+ login: null,
18
+ checked: asked,
19
+ hidden: [],
20
+ at,
21
+ };
22
+ }
23
+ const login = who.stdout.trim() || null;
24
+ const hidden = [];
25
+ for (const repo of asked) {
26
+ const r = await run(['api', `repos/${repo}`, '--jq', '.full_name']).catch(() => null);
27
+ if (r && r.code !== 0 && /HTTP 40[34]|Not Found/i.test(`${r.stderr}${r.stdout}`))
28
+ hidden.push(repo);
29
+ }
30
+ return { state: 'ok', login, checked: asked, hidden, at };
31
+ }
32
+ export function ghRepoWatch(deps) {
33
+ const now = deps.now ?? (() => Date.now());
34
+ const everyMs = deps.everyMs ?? 30 * 60_000;
35
+ let repos = [];
36
+ let last = null;
37
+ let askedAt = 0;
38
+ let busy = false;
39
+ const ask = async () => {
40
+ if (busy || repos.length === 0)
41
+ return;
42
+ busy = true;
43
+ try {
44
+ last = await checkGhRepos(repos, deps.run, new Date(now()));
45
+ askedAt = now();
46
+ if (last.hidden.length)
47
+ deps.log?.(`gh (${last.login ?? 'signed in'}) cannot see ${last.hidden.join(', ')}`);
48
+ }
49
+ finally {
50
+ busy = false;
51
+ }
52
+ };
53
+ return {
54
+ update(next) {
55
+ if (!next)
56
+ return;
57
+ const sorted = [...new Set(next)].sort();
58
+ const changed = sorted.join(',') !== repos.join(',');
59
+ repos = sorted;
60
+ if (changed || now() - askedAt >= everyMs)
61
+ void ask();
62
+ },
63
+ report() {
64
+ return last;
65
+ },
66
+ };
67
+ }
68
+ //# sourceMappingURL=gh-repos.js.map
@@ -19,6 +19,7 @@ export declare function openDraftPr(args: {
19
19
  base: string;
20
20
  title: string;
21
21
  body: string;
22
+ draft?: boolean;
22
23
  cred: GitCredential;
23
24
  update?: boolean;
24
25
  }): Promise<{
package/dist/git-auth.js CHANGED
@@ -56,7 +56,7 @@ export async function openDraftPr(args) {
56
56
  const res = await fetch(`https://api.github.com/repos/${repo}/pulls`, {
57
57
  method: 'POST',
58
58
  headers,
59
- body: JSON.stringify({ title, head, base, body, draft: true }),
59
+ body: JSON.stringify({ title, head, base, body, draft: args.draft !== false }),
60
60
  });
61
61
  if (res.ok) {
62
62
  const j = (await res.json());
package/dist/held.d.ts CHANGED
@@ -16,6 +16,8 @@ export declare function recordHeld(runnerDir: string, runId: string, pid?: numbe
16
16
  export declare function updateHeld(runnerDir: string, runId: string, patch: Partial<Omit<HeldRun, 'runId' | 'pid' | 'claimedAt'>>): void;
17
17
  export declare function releaseHeld(runnerDir: string, runId: string): void;
18
18
  export declare function listHeld(runnerDir: string): HeldRun[];
19
- export declare function heldByGoneProcesses(runnerDir: string, self?: number): HeldRun[];
20
- export declare function heldByLiveProcesses(runnerDir: string, self?: number): string[];
19
+ export declare function bootedAt(now?: number, up?: number): number;
20
+ export declare function claimedBeforeBoot(r: Pick<HeldRun, 'claimedAt'>, boot?: number): boolean;
21
+ export declare function heldByGoneProcesses(runnerDir: string, self?: number, boot?: number): HeldRun[];
22
+ export declare function heldByLiveProcesses(runnerDir: string, self?: number, boot?: number): string[];
21
23
  export declare function liveWorktrees(runnerDir: string): Set<string>;
package/dist/held.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
2
+ import { uptime } from 'node:os';
2
3
  import { join } from 'node:path';
3
4
  import { isAlive } from './orphans.js';
4
5
  const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
@@ -72,18 +73,31 @@ export function listHeld(runnerDir) {
72
73
  }
73
74
  return out.sort((a, b) => a.claimedAt.localeCompare(b.claimedAt));
74
75
  }
75
- export function heldByGoneProcesses(runnerDir, self = process.pid) {
76
- return listHeld(runnerDir).filter((r) => r.pid !== self && !isAlive(r.pid));
76
+ export function bootedAt(now = Date.now(), up = uptime()) {
77
+ return now - up * 1000;
77
78
  }
78
- export function heldByLiveProcesses(runnerDir, self = process.pid) {
79
+ export function claimedBeforeBoot(r, boot = bootedAt()) {
80
+ const at = Date.parse(r.claimedAt);
81
+ return Number.isFinite(at) && at < boot - 60_000;
82
+ }
83
+ function goneRecord(r, self, boot) {
84
+ if (r.pid === self)
85
+ return false;
86
+ return claimedBeforeBoot(r, boot) || !isAlive(r.pid);
87
+ }
88
+ export function heldByGoneProcesses(runnerDir, self = process.pid, boot = bootedAt()) {
89
+ return listHeld(runnerDir).filter((r) => goneRecord(r, self, boot));
90
+ }
91
+ export function heldByLiveProcesses(runnerDir, self = process.pid, boot = bootedAt()) {
79
92
  return listHeld(runnerDir)
80
- .filter((r) => r.pid === self || isAlive(r.pid))
93
+ .filter((r) => !goneRecord(r, self, boot))
81
94
  .map((r) => r.runId);
82
95
  }
83
96
  export function liveWorktrees(runnerDir) {
84
97
  const out = new Set();
98
+ const boot = bootedAt();
85
99
  for (const r of listHeld(runnerDir)) {
86
- if (!isAlive(r.pid))
100
+ if (goneRecord(r, -1, boot))
87
101
  continue;
88
102
  if (r.worktree)
89
103
  out.add(r.worktree);
package/dist/job.d.ts CHANGED
@@ -36,3 +36,4 @@ export declare function waitForStoppedHolder(runnerDir: string, worktree: string
36
36
  pollMs?: number;
37
37
  }): Promise<BranchHolder | null>;
38
38
  export declare function runJob(job: ClaimedJob, cfg: RunnerConfig, api: RunnerApi, viewer?: SessionViewer, opts?: RunJobOptions): Promise<void>;
39
+ export declare function timeoutWords(engineName: string, limitMinutes: number, budget: number | null, machineMinutes: number | undefined): string;