@firefunc-agent/runner 0.9.0 → 0.9.4
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/README.md +90 -28
- package/dist/activity.d.ts +4 -1
- package/dist/activity.js +94 -8
- package/dist/api.d.ts +24 -0
- package/dist/api.js +74 -5
- package/dist/brief.d.ts +5 -0
- package/dist/brief.js +21 -0
- package/dist/build-info.json +2 -2
- package/dist/cli.js +10 -2
- package/dist/config.d.ts +2 -0
- package/dist/cut.d.ts +45 -0
- package/dist/cut.js +105 -0
- package/dist/daemon.d.ts +16 -0
- package/dist/daemon.js +156 -35
- package/dist/declined.d.ts +11 -0
- package/dist/declined.js +27 -0
- package/dist/engines/claude.js +129 -1
- package/dist/engines/types.d.ts +10 -0
- package/dist/exec.d.ts +3 -0
- package/dist/exec.js +48 -5
- package/dist/firefunc/agents.js +59 -7
- package/dist/firefunc/client.d.ts +1 -0
- package/dist/firefunc/client.js +3 -0
- package/dist/firefunc/configure.d.ts +6 -0
- package/dist/firefunc/configure.js +409 -0
- package/dist/firefunc/main.js +45 -7
- package/dist/firefunc/output.d.ts +1 -0
- package/dist/firefunc/output.js +24 -1
- package/dist/firefunc/tasks.js +32 -4
- package/dist/firefunc/version.js +2 -17
- package/dist/held.d.ts +18 -0
- package/dist/held.js +95 -0
- package/dist/job.d.ts +3 -0
- package/dist/job.js +437 -76
- package/dist/keep-local.d.ts +6 -1
- package/dist/keep-local.js +171 -4
- package/dist/limit.d.ts +30 -0
- package/dist/limit.js +258 -0
- package/dist/locks.d.ts +14 -0
- package/dist/locks.js +164 -0
- package/dist/mcp-proxy.d.ts +21 -0
- package/dist/mcp-proxy.js +180 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +31 -2
- package/dist/orphans.d.ts +40 -0
- package/dist/orphans.js +235 -0
- package/dist/pool.d.ts +7 -0
- package/dist/pool.js +57 -9
- package/dist/pr-title.d.ts +11 -0
- package/dist/pr-title.js +63 -0
- package/dist/recover.d.ts +10 -0
- package/dist/recover.js +104 -0
- package/dist/session-stream.d.ts +8 -1
- package/dist/session-stream.js +9 -1
- package/dist/skills.d.ts +11 -0
- package/dist/skills.js +164 -0
- package/dist/stopped.d.ts +3 -0
- package/dist/stopped.js +10 -0
- package/dist/usage.d.ts +49 -0
- package/dist/usage.js +389 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +17 -0
- package/dist/worktrees.d.ts +15 -0
- package/dist/worktrees.js +96 -0
- package/package.json +1 -1
- package/skill/firefunc/SKILL.md +63 -8
package/dist/firefunc/main.js
CHANGED
|
@@ -3,6 +3,7 @@ import { agentCommands } from './agents.js';
|
|
|
3
3
|
import { authCommands } from './auth.js';
|
|
4
4
|
import { catalogCommands } from './catalog.js';
|
|
5
5
|
import { ApiClient } from './client.js';
|
|
6
|
+
import { configureCommands } from './configure.js';
|
|
6
7
|
import { DEFAULT_API_URL, resolveCredentials } from './config.js';
|
|
7
8
|
import { hideSecrets, looksLikeSecret } from './io.js';
|
|
8
9
|
import { printError } from './output.js';
|
|
@@ -15,6 +16,7 @@ export const COMMANDS = [
|
|
|
15
16
|
...catalogCommands,
|
|
16
17
|
...agentCommands,
|
|
17
18
|
...taskCommands,
|
|
19
|
+
...configureCommands,
|
|
18
20
|
...skillCommands,
|
|
19
21
|
];
|
|
20
22
|
const GROUPS = ['templates', 'projects', 'connections', 'skills', 'agents', 'tasks', 'skill'];
|
|
@@ -37,6 +39,21 @@ const SECTIONS = [
|
|
|
37
39
|
],
|
|
38
40
|
],
|
|
39
41
|
['Tasks', ['run', 'tasks list', 'tasks get', 'tasks watch', 'tasks states']],
|
|
42
|
+
[
|
|
43
|
+
'Configure the workspace (writes need workspace:configure)',
|
|
44
|
+
[
|
|
45
|
+
'skills directory',
|
|
46
|
+
'skills install',
|
|
47
|
+
'skills create',
|
|
48
|
+
'skills update',
|
|
49
|
+
'projects instructions get',
|
|
50
|
+
'projects instructions set',
|
|
51
|
+
'projects sources get',
|
|
52
|
+
'projects sources set',
|
|
53
|
+
'projects repos get',
|
|
54
|
+
'projects repos set',
|
|
55
|
+
],
|
|
56
|
+
],
|
|
40
57
|
['Claude Code', ['skill install', 'skill show']],
|
|
41
58
|
];
|
|
42
59
|
const COMMON_OPTIONS = [
|
|
@@ -62,11 +79,12 @@ function topHelp() {
|
|
|
62
79
|
out.push(` ${p.padEnd(w)}${byPath(p)?.summary ?? ''}`);
|
|
63
80
|
out.push('');
|
|
64
81
|
}
|
|
65
|
-
out.push('Agents are created as DRAFTS: each comes back with a link that opens it in the composer,', 'and a person activates it there. A key granted agents:activate may activate one here.', '', 'Every command takes --json for scripts and agents. Exit codes: 0 done; 1 refused or', 'failed (the reason and the fix on stderr); 2 the command line was wrong.', '', 'Environment:', ' FIREFUNC_API_KEY a workspace key to use instead of the one "login" saved', ` FIREFUNC_API_URL the API address (default ${DEFAULT_API_URL})`, ' FIREFUNC_CONFIG_DIR where "login" keeps the key (default ~/.firefunc)', '', 'Start: make a key in FireFunc → Settings → API keys, then: firefunc login', '');
|
|
82
|
+
out.push('Agents are created as DRAFTS: each comes back with a link that opens it in the composer,', 'and a person activates it there. A key granted agents:activate may activate one here.', 'Skills and a project’s instructions, repositories and claims are changed only with a key', 'granted workspace:configure.', '', 'Every command takes --json for scripts and agents. Exit codes: 0 done; 1 refused or', 'failed (the reason and the fix on stderr); 2 the command line was wrong.', '', 'Environment:', ' FIREFUNC_API_KEY a workspace key to use instead of the one "login" saved', ` FIREFUNC_API_URL the API address (default ${DEFAULT_API_URL})`, ' FIREFUNC_CONFIG_DIR where "login" keeps the key (default ~/.firefunc)', '', 'Start: make a key in FireFunc → Settings → API keys, then: firefunc login', '');
|
|
66
83
|
return out.join('\n');
|
|
67
84
|
}
|
|
85
|
+
const inGroup = (group) => COMMANDS.filter((c) => c.path.join(' ').startsWith(`${group} `));
|
|
68
86
|
function groupHelp(group) {
|
|
69
|
-
const cmds =
|
|
87
|
+
const cmds = inGroup(group);
|
|
70
88
|
const w = Math.max(...cmds.map((c) => c.path.join(' ').length)) + 2;
|
|
71
89
|
return [
|
|
72
90
|
`Usage: firefunc ${group} <command> [options]`,
|
|
@@ -107,7 +125,7 @@ function commandWords(argv) {
|
|
|
107
125
|
continue;
|
|
108
126
|
}
|
|
109
127
|
words.push({ word: a, index: i });
|
|
110
|
-
if (words.length ===
|
|
128
|
+
if (words.length === 3)
|
|
111
129
|
break;
|
|
112
130
|
}
|
|
113
131
|
return words;
|
|
@@ -134,9 +152,14 @@ export async function runFirefunc(argv, io) {
|
|
|
134
152
|
}
|
|
135
153
|
if (words[0].word === 'help') {
|
|
136
154
|
const rest = argv.filter((a) => !a.startsWith('-')).slice(1);
|
|
137
|
-
const c = byPath(rest.slice(0,
|
|
155
|
+
const c = byPath(rest.slice(0, 3).join(' ')) ??
|
|
156
|
+
byPath(rest.slice(0, 2).join(' ')) ??
|
|
157
|
+
byPath(rest[0] ?? '');
|
|
158
|
+
const sub = rest.slice(0, 2).join(' ');
|
|
138
159
|
if (c)
|
|
139
160
|
io.stdout.write(commandHelp(c));
|
|
161
|
+
else if (rest.length >= 2 && inGroup(sub).length)
|
|
162
|
+
io.stdout.write(groupHelp(sub));
|
|
140
163
|
else if (rest[0] && GROUPS.includes(rest[0]))
|
|
141
164
|
io.stdout.write(groupHelp(rest[0]));
|
|
142
165
|
else if (!rest.length)
|
|
@@ -145,13 +168,28 @@ export async function runFirefunc(argv, io) {
|
|
|
145
168
|
throw new UsageError(`No command "${shown(rest)}".`);
|
|
146
169
|
return 0;
|
|
147
170
|
}
|
|
148
|
-
const [first, second] = words;
|
|
149
|
-
let command =
|
|
150
|
-
let used = command ? [first.index, second.index] : [];
|
|
171
|
+
const [first, second, third] = words;
|
|
172
|
+
let command = third ? byPath(`${first.word} ${second.word} ${third.word}`) : undefined;
|
|
173
|
+
let used = command ? [first.index, second.index, third.index] : [];
|
|
174
|
+
if (!command && second) {
|
|
175
|
+
command = byPath(`${first.word} ${second.word}`);
|
|
176
|
+
used = command ? [first.index, second.index] : [];
|
|
177
|
+
}
|
|
151
178
|
if (!command) {
|
|
152
179
|
command = byPath(first.word);
|
|
153
180
|
used = command ? [first.index] : [];
|
|
154
181
|
}
|
|
182
|
+
const sub = second ? `${first.word} ${second.word}` : '';
|
|
183
|
+
if (!command && sub && inGroup(sub).length) {
|
|
184
|
+
if (wantsHelp && (!third || !byPath(`${sub} ${third.word}`))) {
|
|
185
|
+
io.stdout.write(groupHelp(sub));
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
const verbs = inGroup(sub).map((c) => c.path[2]);
|
|
189
|
+
throw new UsageError(third
|
|
190
|
+
? `Unknown command "${shown([first.word, second.word, third.word])}": say ${verbs.join(' or ')}.`
|
|
191
|
+
: `Say what to do with "${sub}": ${verbs.join(' or ')}.`, `firefunc ${sub}`);
|
|
192
|
+
}
|
|
155
193
|
if (!command && GROUPS.includes(first.word)) {
|
|
156
194
|
const sub = second?.word;
|
|
157
195
|
const list = byPath(`${first.word} list`);
|
|
@@ -3,6 +3,7 @@ export declare function quietWhenReaderLeaves(stdout: NodeJS.EventEmitter, stder
|
|
|
3
3
|
export declare function printJson(io: Io, value: unknown): void;
|
|
4
4
|
export declare const dash = "\u2014";
|
|
5
5
|
export declare function text(v: unknown): string;
|
|
6
|
+
export declare function wrap(paragraph: string, width: number, first?: string, rest?: string): string[];
|
|
6
7
|
export type Column<T> = {
|
|
7
8
|
head: string;
|
|
8
9
|
get: (row: T) => unknown;
|
package/dist/firefunc/output.js
CHANGED
|
@@ -2,7 +2,10 @@ import { ApiRefusal, ApiUnreachable } from './client.js';
|
|
|
2
2
|
import { UsageError } from './args.js';
|
|
3
3
|
import { Refusal } from './io.js';
|
|
4
4
|
export function quietWhenReaderLeaves(stdout, stderr, exit) {
|
|
5
|
-
const epipe = (err) =>
|
|
5
|
+
const epipe = (err) => {
|
|
6
|
+
const code = err?.code;
|
|
7
|
+
return code === 'EPIPE' || code === 'ENOTCONN';
|
|
8
|
+
};
|
|
6
9
|
stdout.on('error', (err) => {
|
|
7
10
|
if (!epipe(err))
|
|
8
11
|
throw err;
|
|
@@ -28,6 +31,26 @@ export function text(v) {
|
|
|
28
31
|
return v.length ? v.map(text).join(', ') : dash;
|
|
29
32
|
return JSON.stringify(v);
|
|
30
33
|
}
|
|
34
|
+
export function wrap(paragraph, width, first = '', rest = first) {
|
|
35
|
+
const indent = /^\s*/.exec(paragraph)?.[0] ?? '';
|
|
36
|
+
const words = paragraph.trim().split(/\s+/).filter(Boolean);
|
|
37
|
+
const out = [];
|
|
38
|
+
let line = '';
|
|
39
|
+
let lead = first + indent;
|
|
40
|
+
for (const word of words) {
|
|
41
|
+
if (line && lead.length + line.length + 1 + word.length > width) {
|
|
42
|
+
out.push(lead + line);
|
|
43
|
+
line = word;
|
|
44
|
+
lead = rest + indent;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
line = line ? `${line} ${word}` : word;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (line || !out.length)
|
|
51
|
+
out.push(lead + line);
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
31
54
|
function clip(s, max) {
|
|
32
55
|
const one = s.replace(/\s+/g, ' ').trim();
|
|
33
56
|
return one.length > max ? `${one.slice(0, max - 1)}…` : one;
|
package/dist/firefunc/tasks.js
CHANGED
|
@@ -3,7 +3,7 @@ import { pick, listIn } from './catalog.js';
|
|
|
3
3
|
import { ApiRefusal, ApiUnreachable } from './client.js';
|
|
4
4
|
import { enc, readInputFile } from './command.js';
|
|
5
5
|
import { Refusal } from './io.js';
|
|
6
|
-
import { printJson, table, text } from './output.js';
|
|
6
|
+
import { printJson, table, text, wrap } from './output.js';
|
|
7
7
|
const TASK_TYPES = ['task', 'feature', 'refactor', 'chore', 'bug'];
|
|
8
8
|
const STOPS_FOR_A_PERSON = [
|
|
9
9
|
'resolved',
|
|
@@ -34,15 +34,42 @@ function printTask(ctx, t) {
|
|
|
34
34
|
lines.push(` pull request: ${text(pr.url)} (${text(pr.state)})`);
|
|
35
35
|
if (t.externalUrl)
|
|
36
36
|
lines.push(` source: ${text(t.externalUrl)}`);
|
|
37
|
+
const verdict = verdictWord(t.verdict);
|
|
38
|
+
if (verdict)
|
|
39
|
+
lines.push(` verdict: ${verdict}`);
|
|
37
40
|
const runs = Array.isArray(t.runs) ? t.runs : [];
|
|
38
41
|
if (runs.length) {
|
|
39
42
|
lines.push(` runs: ${runs.length}`);
|
|
40
43
|
for (const r of runs.slice(0, 5)) {
|
|
41
|
-
|
|
44
|
+
const word = verdictWord(r.verdict);
|
|
45
|
+
lines.push(` ${text(r.id)} ${text(r.state)} ${text(r.engine)}${word ? ` ${word}` : ''}${r.error ? ` ${text(r.error)}` : ''}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const findings = Array.isArray(t.findings) ? t.findings : [];
|
|
49
|
+
if (findings.length) {
|
|
50
|
+
lines.push(` findings: ${findings.length}`);
|
|
51
|
+
for (const f of findings) {
|
|
52
|
+
const severity = typeof f.severity === 'string' && f.severity ? `[${f.severity}] ` : '';
|
|
53
|
+
const beyond = f.beyondTask === true ? ' (beyond the task)' : '';
|
|
54
|
+
lines.push(...wrap(`${severity}${text(f.title)}${beyond}`, 76, ' - ', ' '));
|
|
55
|
+
if (typeof f.url === 'string' && f.url)
|
|
56
|
+
lines.push(` ${f.url}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (typeof t.answer === 'string' && t.answer.trim()) {
|
|
60
|
+
lines.push('', 'Answer:');
|
|
61
|
+
for (const para of t.answer.replace(/\r\n/g, '\n').split('\n')) {
|
|
62
|
+
lines.push(...(para.trim() ? wrap(para, 78, ' ', ' ') : ['']));
|
|
42
63
|
}
|
|
43
64
|
}
|
|
44
65
|
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
45
66
|
}
|
|
67
|
+
function verdictWord(v) {
|
|
68
|
+
const word = v?.word;
|
|
69
|
+
if (typeof word !== 'string' || !word)
|
|
70
|
+
return null;
|
|
71
|
+
return v.blocking === true ? `${word} (blocking)` : word;
|
|
72
|
+
}
|
|
46
73
|
async function stopStates(api) {
|
|
47
74
|
const stops = new Set(STOPS_FOR_A_PERSON);
|
|
48
75
|
try {
|
|
@@ -97,7 +124,7 @@ async function watchTask(ctx, id, opts) {
|
|
|
97
124
|
io.stdout.write(`${mmss(io.now() - started)} ${state}\n`);
|
|
98
125
|
last = state;
|
|
99
126
|
}
|
|
100
|
-
if (state && (stops.has(state) || isFailure(state)))
|
|
127
|
+
if (state && (task?.settled === true || stops.has(state) || isFailure(state)))
|
|
101
128
|
break;
|
|
102
129
|
if (io.now() - started >= opts.timeoutMs) {
|
|
103
130
|
throw new Refusal(`Task ${id} is still ${state ?? 'unread'} after ${Math.round(opts.timeoutMs / 60_000)} min of watching` +
|
|
@@ -233,7 +260,7 @@ export const taskCommands = [
|
|
|
233
260
|
},
|
|
234
261
|
{
|
|
235
262
|
path: ['tasks', 'get'],
|
|
236
|
-
summary: 'One task: its state, runs and
|
|
263
|
+
summary: 'One task: its state, runs, pull requests, and what the agent answered',
|
|
237
264
|
usage: 'tasks get <task id>',
|
|
238
265
|
positional: { min: 1, max: 1 },
|
|
239
266
|
async run(ctx) {
|
|
@@ -249,6 +276,7 @@ export const taskCommands = [
|
|
|
249
276
|
usage: 'tasks watch <task id> [--interval <seconds>] [--timeout <minutes>]',
|
|
250
277
|
details: "Stops when the agent's part is over: resolved, a pull request open for review, parked\n" +
|
|
251
278
|
'for a person (needs_human, requires_human, quota_exceeded), rejected, or failed.\n' +
|
|
279
|
+
"When it stops, prints the task with the agent's answer, its verdict and its findings.\n" +
|
|
252
280
|
'Exit 0 when it stopped, 1 when it failed (the state ends in _failed) or the watch ran\n' +
|
|
253
281
|
'out of time. Network loss is waited out; a refusal ends the watch.\n' +
|
|
254
282
|
'Under --json, prints only the final { task } — nothing while it waits.',
|
package/dist/firefunc/version.js
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
1
|
import { dirname, join } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (const file of [
|
|
7
|
-
join(here, '..', 'build-info.json'),
|
|
8
|
-
join(here, '..', '..', 'package.json'),
|
|
9
|
-
]) {
|
|
10
|
-
try {
|
|
11
|
-
const v = JSON.parse(readFileSync(file, 'utf8')).version;
|
|
12
|
-
if (v)
|
|
13
|
-
return v;
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return '0.0.0';
|
|
19
|
-
})();
|
|
3
|
+
import { RUNNER_VERSION } from '../version.js';
|
|
4
|
+
export const CLI_VERSION = RUNNER_VERSION;
|
|
20
5
|
export function packageRoot() {
|
|
21
6
|
return join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
22
7
|
}
|
package/dist/held.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type HeldRun = {
|
|
2
|
+
runId: string;
|
|
3
|
+
pid: number;
|
|
4
|
+
claimedAt: string;
|
|
5
|
+
worktree?: string;
|
|
6
|
+
repoPath?: string;
|
|
7
|
+
scratch?: string[];
|
|
8
|
+
engineGroup?: number;
|
|
9
|
+
engineStartedAt?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function heldDir(runnerDir: string): string;
|
|
12
|
+
export declare function recordHeld(runnerDir: string, runId: string, pid?: number): void;
|
|
13
|
+
export declare function updateHeld(runnerDir: string, runId: string, patch: Partial<Omit<HeldRun, 'runId' | 'pid' | 'claimedAt'>>): void;
|
|
14
|
+
export declare function releaseHeld(runnerDir: string, runId: string): void;
|
|
15
|
+
export declare function listHeld(runnerDir: string): HeldRun[];
|
|
16
|
+
export declare function heldByGoneProcesses(runnerDir: string, self?: number): HeldRun[];
|
|
17
|
+
export declare function heldByLiveProcesses(runnerDir: string, self?: number): string[];
|
|
18
|
+
export declare function liveWorktrees(runnerDir: string): Set<string>;
|
package/dist/held.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isAlive } from './orphans.js';
|
|
4
|
+
const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
|
|
5
|
+
export function heldDir(runnerDir) {
|
|
6
|
+
return join(runnerDir, 'held');
|
|
7
|
+
}
|
|
8
|
+
function fileFor(runnerDir, runId) {
|
|
9
|
+
return typeof runId === 'string' && RUN_ID.test(runId)
|
|
10
|
+
? join(heldDir(runnerDir), `${runId}.json`)
|
|
11
|
+
: null;
|
|
12
|
+
}
|
|
13
|
+
function write(file, rec) {
|
|
14
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
15
|
+
writeFileSync(tmp, `${JSON.stringify(rec, null, 2)}\n`, { mode: 0o600 });
|
|
16
|
+
renameSync(tmp, file);
|
|
17
|
+
}
|
|
18
|
+
export function recordHeld(runnerDir, runId, pid = process.pid) {
|
|
19
|
+
const file = fileFor(runnerDir, runId);
|
|
20
|
+
if (!file)
|
|
21
|
+
return;
|
|
22
|
+
try {
|
|
23
|
+
mkdirSync(heldDir(runnerDir), { recursive: true, mode: 0o700 });
|
|
24
|
+
write(file, { runId, pid, claimedAt: new Date().toISOString() });
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function updateHeld(runnerDir, runId, patch) {
|
|
30
|
+
const file = fileFor(runnerDir, runId);
|
|
31
|
+
if (!file || !existsSync(file))
|
|
32
|
+
return;
|
|
33
|
+
try {
|
|
34
|
+
const rec = JSON.parse(readFileSync(file, 'utf8'));
|
|
35
|
+
const scratch = patch.scratch
|
|
36
|
+
? [...new Set([...(rec.scratch ?? []), ...patch.scratch])]
|
|
37
|
+
: rec.scratch;
|
|
38
|
+
write(file, { ...rec, ...patch, ...(scratch ? { scratch } : {}) });
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function releaseHeld(runnerDir, runId) {
|
|
44
|
+
const file = fileFor(runnerDir, runId);
|
|
45
|
+
if (!file)
|
|
46
|
+
return;
|
|
47
|
+
try {
|
|
48
|
+
unlinkSync(file);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function listHeld(runnerDir) {
|
|
54
|
+
const dir = heldDir(runnerDir);
|
|
55
|
+
if (!existsSync(dir))
|
|
56
|
+
return [];
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const name of readdirSync(dir)) {
|
|
59
|
+
if (!name.endsWith('.json'))
|
|
60
|
+
continue;
|
|
61
|
+
try {
|
|
62
|
+
const rec = JSON.parse(readFileSync(join(dir, name), 'utf8'));
|
|
63
|
+
if (rec &&
|
|
64
|
+
typeof rec.runId === 'string' &&
|
|
65
|
+
RUN_ID.test(rec.runId) &&
|
|
66
|
+
Number.isInteger(rec.pid)) {
|
|
67
|
+
out.push(rec);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return out.sort((a, b) => a.claimedAt.localeCompare(b.claimedAt));
|
|
74
|
+
}
|
|
75
|
+
export function heldByGoneProcesses(runnerDir, self = process.pid) {
|
|
76
|
+
return listHeld(runnerDir).filter((r) => r.pid !== self && !isAlive(r.pid));
|
|
77
|
+
}
|
|
78
|
+
export function heldByLiveProcesses(runnerDir, self = process.pid) {
|
|
79
|
+
return listHeld(runnerDir)
|
|
80
|
+
.filter((r) => r.pid === self || isAlive(r.pid))
|
|
81
|
+
.map((r) => r.runId);
|
|
82
|
+
}
|
|
83
|
+
export function liveWorktrees(runnerDir) {
|
|
84
|
+
const out = new Set();
|
|
85
|
+
for (const r of listHeld(runnerDir)) {
|
|
86
|
+
if (!isAlive(r.pid))
|
|
87
|
+
continue;
|
|
88
|
+
if (r.worktree)
|
|
89
|
+
out.add(r.worktree);
|
|
90
|
+
for (const s of r.scratch ?? [])
|
|
91
|
+
out.add(s);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=held.js.map
|
package/dist/job.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { RunnerApi, ClaimedJob } from './api.js';
|
|
2
2
|
import { type RunnerConfig } from './config.js';
|
|
3
3
|
import type { SessionViewer } from './viewer.js';
|
|
4
|
+
import { type LimitGate } from './limit.js';
|
|
4
5
|
export declare function resolveRepoPath(repo: string | null | undefined, cfg: RunnerConfig): string | null;
|
|
5
6
|
export declare function cloneDestination(repo: string, cfg: RunnerConfig): string | null;
|
|
6
7
|
export declare function rememberRepoPath(repo: string, path: string, cfg: RunnerConfig): void;
|
|
7
8
|
export declare function hasGh(cwd: string): Promise<boolean>;
|
|
8
9
|
export declare function runJob(job: ClaimedJob, cfg: RunnerConfig, api: RunnerApi, viewer?: SessionViewer, opts?: {
|
|
9
10
|
devServerPort?: number;
|
|
11
|
+
limits?: LimitGate;
|
|
12
|
+
now?: () => Date;
|
|
10
13
|
}): Promise<void>;
|