@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.
- package/README.md +2 -0
- package/dist/activity.d.ts +1 -0
- package/dist/activity.js +1 -1
- package/dist/api-fallback.d.ts +9 -0
- package/dist/api-fallback.js +55 -0
- package/dist/api.d.ts +138 -0
- package/dist/api.js +153 -4
- package/dist/ask/index.d.ts +20 -0
- package/dist/ask/index.js +64 -0
- package/dist/ask-first.d.ts +59 -0
- package/dist/ask-first.js +126 -0
- package/dist/brief.d.ts +2 -0
- package/dist/brief.js +6 -0
- package/dist/build-info.json +2 -2
- package/dist/config.d.ts +2 -0
- package/dist/cut.d.ts +3 -1
- package/dist/cut.js +15 -4
- package/dist/daemon.js +51 -5
- package/dist/engines/claude.js +10 -4
- package/dist/engines/copilot.js +3 -2
- package/dist/firefunc/agents.js +1 -1
- package/dist/git-auth.d.ts +1 -0
- package/dist/git-auth.js +9 -1
- package/dist/job.js +1324 -804
- package/dist/keep-local.d.ts +1 -0
- package/dist/keep-local.js +3 -0
- package/dist/limit.d.ts +1 -0
- package/dist/limit.js +4 -1
- package/dist/locks.d.ts +3 -0
- package/dist/locks.js +46 -13
- package/dist/plan-phase/index.d.ts +11 -0
- package/dist/plan-phase/index.js +46 -0
- package/dist/pool.js +4 -2
- package/dist/pr-title.d.ts +5 -0
- package/dist/pr-title.js +18 -0
- package/dist/reference-files.d.ts +27 -0
- package/dist/reference-files.js +202 -0
- package/dist/run-attachments.d.ts +79 -0
- package/dist/run-attachments.js +276 -0
- package/dist/secret-scan.d.ts +1 -1
- package/dist/secret-scan.js +3 -0
- package/dist/secret-values.d.ts +17 -0
- package/dist/secret-values.js +81 -0
- package/dist/trail/chain.d.ts +12 -0
- package/dist/trail/chain.js +89 -0
- package/dist/trail/deltas.d.ts +34 -0
- package/dist/trail/deltas.js +206 -0
- package/dist/trail/index.d.ts +27 -0
- package/dist/trail/index.js +128 -0
- package/dist/trail/keys.d.ts +14 -0
- package/dist/trail/keys.js +61 -0
- package/dist/trail/recorder.d.ts +118 -0
- package/dist/trail/recorder.js +697 -0
- package/dist/trail/rules.d.ts +30 -0
- package/dist/trail/rules.js +158 -0
- package/dist/trail/stream.d.ts +41 -0
- package/dist/trail/stream.js +86 -0
- package/package.json +1 -1
- package/skill/firefunc/SKILL.md +3 -3
package/README.md
CHANGED
|
@@ -56,6 +56,8 @@ That's it. When your QA files a bug (labeled for FireFunc), it appears here with
|
|
|
56
56
|
- **Scans what it is about to push for secrets, on this machine**, and refuses the push on a key, a token or a private key (0.8.3+) — see [The secret scan before a push](#the-secret-scan-before-a-push).
|
|
57
57
|
- Refuses to push a commit that contains a `.env` file or the run's MCP config, whatever the agent committed.
|
|
58
58
|
- Writes the agent's skills to `.claude/skills/<slug>/SKILL.md` and keeps them out of every commit **by their real path** (0.9.1+): when the repository keeps `.claude/skills` as a link into a folder it tracks (`.claude/skills -> ../.agents/skills`), the skill lands in that folder and is kept out there — by a `.gitignore` inside each skill folder (that worktree only; your clone's `.git/info/exclude` is not written), in what the runner stages, and at the push, which is refused if the agent committed one anyway. A folder already in the checkout under the same name — in any case, on a disk that ignores case — is never written into (the run sees the repository's, and the log names it), and a link that leads out of the checkout is refused: nothing is written outside the worktree. Runners before 0.9.1 appended `.claude/skills/` to your clone's `.git/info/exclude`; that line can be deleted.
|
|
59
|
+
- **A signed trail of every step, and runs that wait for a person** (0.9.9). The runner records each step the engine takes — its type, timing, outcome and the paths and line counts it touched, never a line of code — as a hash-chained trail signed with this machine's own key, and sends it to FireFunc, which countersigns it. An agent may ask a person a question mid-run, or report its plan for approval before it works: the session is then parked here (worktree and session kept, nothing pushed) and resumed in the same worktree with the answer.
|
|
60
|
+
- **An agent's own environment variables and reference files** (0.9.8). When the agent carries them, the runner asks FireFunc for them for the run it holds (`POST /channel/runs/<id>/agent-env` and `/reference-files` — answered only while that run is live for this machine). The variables are set in the **engine's** environment only — your setup and background commands never see them — and every value FireFunc marks secret is replaced by `[secret NAME]` in everything the runner sends to FireFunc (events, steps, results, a result kept to deliver later) and everything it logs or keeps (the terminal, the session log, the local viewer); a push whose added lines contain one is refused (`agent_secret`). The files are downloaded from addresses signed for minutes, checked against the size and SHA-256 FireFunc recorded, and written to `.firefunc/reference/` in the worktree by the skills' rules: never into a folder the checkout already has, a `.gitignore` of `*` inside, excluded from staging and refused at the push. The brief tells the agent the variables' names (never a value) and where the files are.
|
|
59
61
|
- Runs Claude with `--permission-mode bypassPermissions` (the default; override with `permissionMode` in the config or per job) **without** `--dangerously-skip-permissions`, which hangs non-interactive daemons. Note what that mode means: the agent is not asked to confirm anything, so the bounds that matter are the ones passed alongside it — `--disallowedTools` for every tool the chain withheld, and `--strict-mcp-config` so the run's servers are the ones FireFunc chose rather than whatever the machine happens to have.
|
|
60
62
|
- **Claims no work an engine cannot run here** (0.9.6). Claude Code refuses that mode as root or under sudo — the default user of most containers — and exits before doing anything, so a runner started as root used to fail every run it claimed. The runner now asks at start (and whenever it finds a newly installed CLI) whether each engine can run unattended as its user: one that cannot is not offered to FireFunc, which hands this machine none of its work, the log and `firefunc-runner status` say why with the fix, and the Machines page in FireFunc shows it too. A run that reaches it anyway is answered at once, without starting the engine, as the machine not being ready — not as the task's failure. The fix: run the runner as a normal user.
|
|
61
63
|
- A per-job timeout (default 20 min) prevents a stuck run from hanging the daemon. An agent's own time budget (FireFunc sends it as `maxMinutes`, 0.9.3) is honoured under the `jobTimeoutMinutes` you set, and in its place when you set none; the engine is told how long it has.
|
package/dist/activity.d.ts
CHANGED
package/dist/activity.js
CHANGED
|
@@ -167,7 +167,7 @@ export function createActivityReporter(opts) {
|
|
|
167
167
|
const cap = opts.cap ?? 1500;
|
|
168
168
|
const holdMs = opts.holdMs ?? 2000;
|
|
169
169
|
const intervalMs = opts.intervalMs ?? 1500;
|
|
170
|
-
let seq = 0;
|
|
170
|
+
let seq = Math.max(0, Math.floor(opts.seqStart ?? 0));
|
|
171
171
|
let sent = 0;
|
|
172
172
|
let pending = [];
|
|
173
173
|
let inflight = null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RunnerConfig } from './config.js';
|
|
2
|
+
export declare function apiKeyFile(cfg: Pick<RunnerConfig, 'claudeApiKeyFile'>, dir?: string): string;
|
|
3
|
+
export declare function fallbackKey(cfg: Pick<RunnerConfig, 'claudeApiKeyFallback' | 'claudeApiKeyFile'>, dir?: string): string | null;
|
|
4
|
+
export declare function fallbackUntil(dir?: string, now?: Date): Date | null;
|
|
5
|
+
export declare function startFallback(resetsAt: string | null, dir?: string, now?: Date): Date;
|
|
6
|
+
export declare function claudeApiKeyNow(cfg: Pick<RunnerConfig, 'claudeUseApiKey' | 'claudeApiKeyFallback' | 'claudeApiKeyFile'>, dir?: string, now?: Date): {
|
|
7
|
+
key: string | null;
|
|
8
|
+
why: 'opted-in' | 'fallback' | null;
|
|
9
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { runnerDir } from './config.js';
|
|
4
|
+
const DEFAULT_WINDOW_MS = 6 * 60 * 60_000;
|
|
5
|
+
export function apiKeyFile(cfg, dir = runnerDir()) {
|
|
6
|
+
return cfg.claudeApiKeyFile ?? join(dir, 'anthropic-api-key');
|
|
7
|
+
}
|
|
8
|
+
export function fallbackKey(cfg, dir = runnerDir()) {
|
|
9
|
+
if (!cfg.claudeApiKeyFallback)
|
|
10
|
+
return null;
|
|
11
|
+
const file = apiKeyFile(cfg, dir);
|
|
12
|
+
try {
|
|
13
|
+
if (!existsSync(file) || statSync(file).size > 4096)
|
|
14
|
+
return null;
|
|
15
|
+
const key = readFileSync(file, 'utf8').trim();
|
|
16
|
+
return key.length >= 20 && !/\s/.test(key) ? key : null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function stateFile(dir) {
|
|
23
|
+
return join(dir, 'api-fallback.json');
|
|
24
|
+
}
|
|
25
|
+
export function fallbackUntil(dir = runnerDir(), now = new Date()) {
|
|
26
|
+
try {
|
|
27
|
+
const raw = JSON.parse(readFileSync(stateFile(dir), 'utf8'));
|
|
28
|
+
const until = raw.until ? new Date(raw.until) : null;
|
|
29
|
+
return until && !Number.isNaN(until.getTime()) && until.getTime() > now.getTime()
|
|
30
|
+
? until
|
|
31
|
+
: null;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function startFallback(resetsAt, dir = runnerDir(), now = new Date()) {
|
|
38
|
+
const reset = resetsAt ? new Date(resetsAt) : null;
|
|
39
|
+
const until = reset && !Number.isNaN(reset.getTime()) && reset.getTime() > now.getTime()
|
|
40
|
+
? reset
|
|
41
|
+
: new Date(now.getTime() + DEFAULT_WINDOW_MS);
|
|
42
|
+
const held = fallbackUntil(dir, now);
|
|
43
|
+
const end = held && held.getTime() > until.getTime() ? held : until;
|
|
44
|
+
writeFileSync(stateFile(dir), JSON.stringify({ until: end.toISOString() }), { mode: 0o600 });
|
|
45
|
+
return end;
|
|
46
|
+
}
|
|
47
|
+
export function claudeApiKeyNow(cfg, dir = runnerDir(), now = new Date()) {
|
|
48
|
+
if (cfg.claudeUseApiKey)
|
|
49
|
+
return { key: null, why: 'opted-in' };
|
|
50
|
+
const key = fallbackKey(cfg, dir);
|
|
51
|
+
if (key && fallbackUntil(dir, now))
|
|
52
|
+
return { key, why: 'fallback' };
|
|
53
|
+
return { key: null, why: null };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=api-fallback.js.map
|
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ChangeSummary } from './ask-first.js';
|
|
1
2
|
import type { RunUsage } from './usage.js';
|
|
2
3
|
export type ClaimedJob = {
|
|
3
4
|
runId: string;
|
|
@@ -8,6 +9,19 @@ export type ClaimedJob = {
|
|
|
8
9
|
toolsOnly?: boolean;
|
|
9
10
|
continuesBranch?: boolean;
|
|
10
11
|
review?: boolean;
|
|
12
|
+
askFirst?: boolean;
|
|
13
|
+
askFirstStep?: {
|
|
14
|
+
kind: 'publish';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'revise';
|
|
17
|
+
note: string;
|
|
18
|
+
round: number;
|
|
19
|
+
};
|
|
20
|
+
askPerson?: boolean;
|
|
21
|
+
planFirst?: boolean;
|
|
22
|
+
planRound?: number;
|
|
23
|
+
planApproved?: boolean;
|
|
24
|
+
parkStep?: ParkStep;
|
|
11
25
|
baseBranch?: string | null;
|
|
12
26
|
externalId: string | null;
|
|
13
27
|
title: string | null;
|
|
@@ -27,6 +41,27 @@ export type ClaimedJob = {
|
|
|
27
41
|
description?: string | null;
|
|
28
42
|
content: string;
|
|
29
43
|
}[];
|
|
44
|
+
agentEnv?: {
|
|
45
|
+
name: string;
|
|
46
|
+
secret: boolean;
|
|
47
|
+
}[];
|
|
48
|
+
referenceFiles?: {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
size: number;
|
|
52
|
+
sha256: string;
|
|
53
|
+
}[];
|
|
54
|
+
runAttachments?: {
|
|
55
|
+
folder?: string;
|
|
56
|
+
maxFiles?: number;
|
|
57
|
+
maxFileBytes?: number;
|
|
58
|
+
maxTotalBytes?: number;
|
|
59
|
+
types?: string[];
|
|
60
|
+
};
|
|
61
|
+
trail?: {
|
|
62
|
+
detail?: string;
|
|
63
|
+
off?: boolean;
|
|
64
|
+
};
|
|
30
65
|
contextPack?: unknown;
|
|
31
66
|
mcpConfig?: unknown;
|
|
32
67
|
maxMinutes?: number | null;
|
|
@@ -52,6 +87,26 @@ export type SecretScanReport = {
|
|
|
52
87
|
}>;
|
|
53
88
|
head?: string;
|
|
54
89
|
};
|
|
90
|
+
export type ParkStep = {
|
|
91
|
+
kind: 'answer';
|
|
92
|
+
seq: number;
|
|
93
|
+
question: string;
|
|
94
|
+
answer: string;
|
|
95
|
+
by: string | null;
|
|
96
|
+
} | {
|
|
97
|
+
kind: 'stop';
|
|
98
|
+
reason: string;
|
|
99
|
+
} | {
|
|
100
|
+
kind: 'plan_go';
|
|
101
|
+
round: number;
|
|
102
|
+
steps: string[];
|
|
103
|
+
by: string | null;
|
|
104
|
+
} | {
|
|
105
|
+
kind: 'plan_revise';
|
|
106
|
+
round: number;
|
|
107
|
+
note: string;
|
|
108
|
+
by: string | null;
|
|
109
|
+
};
|
|
55
110
|
export type ResultPayload = ({
|
|
56
111
|
status: 'pr_opened';
|
|
57
112
|
pr: {
|
|
@@ -68,6 +123,19 @@ export type ResultPayload = ({
|
|
|
68
123
|
} | {
|
|
69
124
|
status: 'failed';
|
|
70
125
|
error: string;
|
|
126
|
+
} | {
|
|
127
|
+
status: 'awaiting_approval';
|
|
128
|
+
changes: ChangeSummary;
|
|
129
|
+
head: string;
|
|
130
|
+
summary?: string;
|
|
131
|
+
} | {
|
|
132
|
+
status: 'parked';
|
|
133
|
+
park: {
|
|
134
|
+
kind: 'question' | 'plan';
|
|
135
|
+
seq: number;
|
|
136
|
+
changedFiles?: number;
|
|
137
|
+
};
|
|
138
|
+
summary?: string;
|
|
71
139
|
}) & {
|
|
72
140
|
secretScan?: SecretScanReport;
|
|
73
141
|
usage?: RunUsage;
|
|
@@ -118,6 +186,9 @@ export declare class RunnerApi {
|
|
|
118
186
|
engine: string;
|
|
119
187
|
code: string;
|
|
120
188
|
}>;
|
|
189
|
+
awaitingRuns?: string[];
|
|
190
|
+
}, opts?: {
|
|
191
|
+
onDiscard?: (runIds: string[]) => void;
|
|
121
192
|
}): Promise<ClaimedJob | null>;
|
|
122
193
|
repos(): Promise<string[]>;
|
|
123
194
|
probe(): Promise<boolean>;
|
|
@@ -133,6 +204,68 @@ export declare class RunnerApi {
|
|
|
133
204
|
token: string;
|
|
134
205
|
expiresAt?: string;
|
|
135
206
|
} | null>;
|
|
207
|
+
agentEnv(runId: string): Promise<{
|
|
208
|
+
env: Array<{
|
|
209
|
+
name: string;
|
|
210
|
+
value: string;
|
|
211
|
+
secret: boolean;
|
|
212
|
+
}>;
|
|
213
|
+
missing: Array<{
|
|
214
|
+
name: string;
|
|
215
|
+
reason: string;
|
|
216
|
+
fix: string;
|
|
217
|
+
}>;
|
|
218
|
+
} | {
|
|
219
|
+
refused: {
|
|
220
|
+
reason: string;
|
|
221
|
+
fix: string;
|
|
222
|
+
};
|
|
223
|
+
}>;
|
|
224
|
+
referenceFiles(runId: string): Promise<{
|
|
225
|
+
files: Array<{
|
|
226
|
+
name: string;
|
|
227
|
+
size: number;
|
|
228
|
+
sha256: string;
|
|
229
|
+
url: string;
|
|
230
|
+
}>;
|
|
231
|
+
missing: Array<{
|
|
232
|
+
name: string;
|
|
233
|
+
reason: string;
|
|
234
|
+
fix: string;
|
|
235
|
+
}>;
|
|
236
|
+
} | {
|
|
237
|
+
refused: {
|
|
238
|
+
reason: string;
|
|
239
|
+
fix: string;
|
|
240
|
+
};
|
|
241
|
+
}>;
|
|
242
|
+
offerAttachment(runId: string, file: {
|
|
243
|
+
name: string;
|
|
244
|
+
size: number;
|
|
245
|
+
sha256: string;
|
|
246
|
+
contentType: string;
|
|
247
|
+
}): Promise<{
|
|
248
|
+
id: string;
|
|
249
|
+
upload: {
|
|
250
|
+
url: string;
|
|
251
|
+
headers: Record<string, string>;
|
|
252
|
+
};
|
|
253
|
+
} | {
|
|
254
|
+
refused: {
|
|
255
|
+
reason: string;
|
|
256
|
+
fix: string;
|
|
257
|
+
status: number;
|
|
258
|
+
};
|
|
259
|
+
}>;
|
|
260
|
+
completeAttachment(runId: string, attachmentId: string): Promise<{
|
|
261
|
+
ok: true;
|
|
262
|
+
} | {
|
|
263
|
+
refused: {
|
|
264
|
+
reason: string;
|
|
265
|
+
fix: string;
|
|
266
|
+
status: number;
|
|
267
|
+
};
|
|
268
|
+
}>;
|
|
136
269
|
event(runId: string, event: RunnerEvent, detail?: Record<string, unknown>): Promise<void>;
|
|
137
270
|
activity(runId: string, steps: Array<{
|
|
138
271
|
seq: number;
|
|
@@ -141,5 +274,10 @@ export declare class RunnerApi {
|
|
|
141
274
|
label: string;
|
|
142
275
|
detail?: Record<string, unknown>;
|
|
143
276
|
}>): Promise<void>;
|
|
277
|
+
trail(runId: string, batch: unknown): Promise<'ok' | 'gone' | 'refused'>;
|
|
278
|
+
parkCheck(runId: string): Promise<{
|
|
279
|
+
kind: 'question' | 'plan';
|
|
280
|
+
seq: number;
|
|
281
|
+
} | null>;
|
|
144
282
|
result(runId: string, payload: ResultPayload): Promise<void>;
|
|
145
283
|
}
|
package/dist/api.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RUNNER_VERSION } from './version.js';
|
|
2
|
+
import { blankSecretsDeep } from './secret-values.js';
|
|
2
3
|
export const REPORTED_SUMMARY_MAX = 65_536;
|
|
3
4
|
export const OLDER_API_SUMMARY_MAX = 4000;
|
|
4
5
|
export function cutText(text, max) {
|
|
@@ -66,7 +67,7 @@ export class RunnerApi {
|
|
|
66
67
|
headers() {
|
|
67
68
|
return { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' };
|
|
68
69
|
}
|
|
69
|
-
async claim(meta) {
|
|
70
|
+
async claim(meta, opts = {}) {
|
|
70
71
|
const ctrl = new AbortController();
|
|
71
72
|
const timer = setTimeout(() => ctrl.abort(), 35_000);
|
|
72
73
|
try {
|
|
@@ -83,6 +84,11 @@ export class RunnerApi {
|
|
|
83
84
|
if (!res.ok)
|
|
84
85
|
throw new Error(`claim failed: ${res.status}`);
|
|
85
86
|
const body = (await res.json());
|
|
87
|
+
if (Array.isArray(body.discard) && opts.onDiscard) {
|
|
88
|
+
const ids = body.discard.filter((x) => typeof x === 'string');
|
|
89
|
+
if (ids.length > 0)
|
|
90
|
+
opts.onDiscard(ids);
|
|
91
|
+
}
|
|
86
92
|
return body.job ?? null;
|
|
87
93
|
}
|
|
88
94
|
finally {
|
|
@@ -160,27 +166,145 @@ export class RunnerApi {
|
|
|
160
166
|
return null;
|
|
161
167
|
}
|
|
162
168
|
}
|
|
169
|
+
async agentEnv(runId) {
|
|
170
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/agent-env`, {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
headers: this.headers(),
|
|
173
|
+
body: '{}',
|
|
174
|
+
});
|
|
175
|
+
const body = (await res.json().catch(() => null));
|
|
176
|
+
if (!res.ok || !body?.ok) {
|
|
177
|
+
return {
|
|
178
|
+
refused: {
|
|
179
|
+
reason: typeof body?.reason === 'string'
|
|
180
|
+
? body.reason
|
|
181
|
+
: `FireFunc answered ${res.status} when the run asked for its environment variables.`,
|
|
182
|
+
fix: typeof body?.fix === 'string' ? body.fix : 'Re-run the task.',
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const env = Array.isArray(body.env)
|
|
187
|
+
? body.env.flatMap((e) => {
|
|
188
|
+
const o = e;
|
|
189
|
+
return o && typeof o.name === 'string' && typeof o.value === 'string'
|
|
190
|
+
? [{ name: o.name, value: o.value, secret: o.secret === true }]
|
|
191
|
+
: [];
|
|
192
|
+
})
|
|
193
|
+
: [];
|
|
194
|
+
return { env, missing: missingOf(body.missing) };
|
|
195
|
+
}
|
|
196
|
+
async referenceFiles(runId) {
|
|
197
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/reference-files`, {
|
|
198
|
+
method: 'POST',
|
|
199
|
+
headers: this.headers(),
|
|
200
|
+
body: '{}',
|
|
201
|
+
});
|
|
202
|
+
const body = (await res.json().catch(() => null));
|
|
203
|
+
if (!res.ok || !body?.ok) {
|
|
204
|
+
return {
|
|
205
|
+
refused: {
|
|
206
|
+
reason: typeof body?.reason === 'string'
|
|
207
|
+
? body.reason
|
|
208
|
+
: `FireFunc answered ${res.status} when the run asked for its reference files.`,
|
|
209
|
+
fix: typeof body?.fix === 'string' ? body.fix : 'Re-run the task.',
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const files = Array.isArray(body.files)
|
|
214
|
+
? body.files.flatMap((f) => {
|
|
215
|
+
const o = f;
|
|
216
|
+
return o &&
|
|
217
|
+
typeof o.name === 'string' &&
|
|
218
|
+
typeof o.size === 'number' &&
|
|
219
|
+
typeof o.sha256 === 'string' &&
|
|
220
|
+
typeof o.url === 'string'
|
|
221
|
+
? [{ name: o.name, size: o.size, sha256: o.sha256, url: o.url }]
|
|
222
|
+
: [];
|
|
223
|
+
})
|
|
224
|
+
: [];
|
|
225
|
+
return { files, missing: missingOf(body.missing) };
|
|
226
|
+
}
|
|
227
|
+
async offerAttachment(runId, file) {
|
|
228
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/attachments`, {
|
|
229
|
+
method: 'POST',
|
|
230
|
+
headers: this.headers(),
|
|
231
|
+
body: JSON.stringify(file),
|
|
232
|
+
});
|
|
233
|
+
const body = (await res.json().catch(() => null));
|
|
234
|
+
if (!res.ok ||
|
|
235
|
+
!body?.ok ||
|
|
236
|
+
typeof body.attachment?.id !== 'string' ||
|
|
237
|
+
typeof body.upload?.url !== 'string') {
|
|
238
|
+
return { refused: refusalOf(res.status, body, 'offered a picture') };
|
|
239
|
+
}
|
|
240
|
+
const headers = {};
|
|
241
|
+
if (body.upload.headers && typeof body.upload.headers === 'object') {
|
|
242
|
+
for (const [k, v] of Object.entries(body.upload.headers)) {
|
|
243
|
+
if (typeof v === 'string')
|
|
244
|
+
headers[k] = v;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return { id: body.attachment.id, upload: { url: body.upload.url, headers } };
|
|
248
|
+
}
|
|
249
|
+
async completeAttachment(runId, attachmentId) {
|
|
250
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/attachments/${attachmentId}/complete`, { method: 'POST', headers: this.headers(), body: '{}' });
|
|
251
|
+
const body = (await res.json().catch(() => null));
|
|
252
|
+
if (!res.ok || !body?.ok) {
|
|
253
|
+
return { refused: refusalOf(res.status, body, 'asked for a picture to be checked') };
|
|
254
|
+
}
|
|
255
|
+
return { ok: true };
|
|
256
|
+
}
|
|
163
257
|
async event(runId, event, detail) {
|
|
164
258
|
await fetch(`${this.apiUrl}/channel/runs/${runId}/events`, {
|
|
165
259
|
method: 'POST',
|
|
166
260
|
headers: this.headers(),
|
|
167
|
-
body: JSON.stringify({ event, detail }),
|
|
261
|
+
body: JSON.stringify(blankSecretsDeep({ event, detail })),
|
|
168
262
|
}).catch(() => { });
|
|
169
263
|
}
|
|
170
264
|
async activity(runId, steps) {
|
|
171
265
|
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/activity`, {
|
|
172
266
|
method: 'POST',
|
|
173
267
|
headers: this.headers(),
|
|
174
|
-
body: JSON.stringify({ steps }),
|
|
268
|
+
body: JSON.stringify(blankSecretsDeep({ steps })),
|
|
175
269
|
});
|
|
176
270
|
if (!res.ok)
|
|
177
271
|
throw new Error(`activity post failed: ${res.status}`);
|
|
178
272
|
}
|
|
273
|
+
async trail(runId, batch) {
|
|
274
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/trail`, {
|
|
275
|
+
method: 'POST',
|
|
276
|
+
headers: this.headers(),
|
|
277
|
+
body: JSON.stringify(batch),
|
|
278
|
+
});
|
|
279
|
+
if (res.ok)
|
|
280
|
+
return 'ok';
|
|
281
|
+
if (res.status === 404) {
|
|
282
|
+
const body = (await res.json().catch(() => null));
|
|
283
|
+
return body?.error === 'run_not_found' ? 'refused' : 'gone';
|
|
284
|
+
}
|
|
285
|
+
if (res.status >= 500)
|
|
286
|
+
throw new Error(`trail post failed: ${res.status}`);
|
|
287
|
+
return 'refused';
|
|
288
|
+
}
|
|
289
|
+
async parkCheck(runId) {
|
|
290
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/park-check`, {
|
|
291
|
+
method: 'POST',
|
|
292
|
+
headers: this.headers(),
|
|
293
|
+
body: '{}',
|
|
294
|
+
});
|
|
295
|
+
if (!res.ok)
|
|
296
|
+
return null;
|
|
297
|
+
const body = (await res.json().catch(() => null));
|
|
298
|
+
const p = body?.park;
|
|
299
|
+
return p && (p.kind === 'question' || p.kind === 'plan') && typeof p.seq === 'number'
|
|
300
|
+
? { kind: p.kind, seq: p.seq }
|
|
301
|
+
: null;
|
|
302
|
+
}
|
|
179
303
|
async result(runId, payload) {
|
|
180
304
|
const post = (body) => fetch(`${this.apiUrl}/channel/runs/${runId}/result`, {
|
|
181
305
|
method: 'POST',
|
|
182
306
|
headers: this.headers(),
|
|
183
|
-
body: JSON.stringify(body),
|
|
307
|
+
body: JSON.stringify(blankSecretsDeep(body)),
|
|
184
308
|
});
|
|
185
309
|
let res = await post(payload);
|
|
186
310
|
let sent = { ...payload };
|
|
@@ -202,4 +326,29 @@ export class RunnerApi {
|
|
|
202
326
|
throw new Error(`result report failed: ${res.status}`);
|
|
203
327
|
}
|
|
204
328
|
}
|
|
329
|
+
function refusalOf(status, body, what) {
|
|
330
|
+
return {
|
|
331
|
+
reason: typeof body?.reason === 'string'
|
|
332
|
+
? body.reason
|
|
333
|
+
: `FireFunc answered ${status} when the run ${what}.`,
|
|
334
|
+
fix: typeof body?.fix === 'string' ? body.fix : 'Re-run the task.',
|
|
335
|
+
status,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function missingOf(raw) {
|
|
339
|
+
return Array.isArray(raw)
|
|
340
|
+
? raw.flatMap((m) => {
|
|
341
|
+
const o = m;
|
|
342
|
+
return o && typeof o.name === 'string'
|
|
343
|
+
? [
|
|
344
|
+
{
|
|
345
|
+
name: o.name,
|
|
346
|
+
reason: typeof o.reason === 'string' ? o.reason : '',
|
|
347
|
+
fix: typeof o.fix === 'string' ? o.fix : '',
|
|
348
|
+
},
|
|
349
|
+
]
|
|
350
|
+
: [];
|
|
351
|
+
})
|
|
352
|
+
: [];
|
|
353
|
+
}
|
|
205
354
|
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ParkStep } from '../api.js';
|
|
2
|
+
import type { KeptChange } from '../ask-first.js';
|
|
3
|
+
import type { CutSession } from '../cut.js';
|
|
4
|
+
import { type Phase } from '../plan-phase/index.js';
|
|
5
|
+
export type ParkReason = {
|
|
6
|
+
kind: 'question' | 'plan';
|
|
7
|
+
seq: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function parkReasonFor(input: {
|
|
10
|
+
askPerson: boolean;
|
|
11
|
+
phase: Phase;
|
|
12
|
+
planRound: number;
|
|
13
|
+
check: () => Promise<{
|
|
14
|
+
kind: 'question' | 'plan';
|
|
15
|
+
seq: number;
|
|
16
|
+
} | null>;
|
|
17
|
+
}): Promise<ParkReason | null>;
|
|
18
|
+
export declare function stepBrief(step: ParkStep, phase: Phase): string;
|
|
19
|
+
export declare function resumeFromParked(kept: KeptChange, promptHash: string): CutSession;
|
|
20
|
+
export declare function parkedLine(runId: string, why: ParkReason): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { planGoBrief, planPhaseBrief } from '../plan-phase/index.js';
|
|
2
|
+
export async function parkReasonFor(input) {
|
|
3
|
+
if (input.askPerson) {
|
|
4
|
+
const q = await input.check().catch(() => null);
|
|
5
|
+
if (q && q.kind === 'question')
|
|
6
|
+
return { kind: 'question', seq: q.seq };
|
|
7
|
+
}
|
|
8
|
+
if (input.phase === 'plan')
|
|
9
|
+
return { kind: 'plan', seq: Math.max(1, input.planRound) };
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
export function stepBrief(step, phase) {
|
|
13
|
+
switch (step.kind) {
|
|
14
|
+
case 'answer':
|
|
15
|
+
return [
|
|
16
|
+
`${step.by ?? 'A person'} answered the question you asked:`,
|
|
17
|
+
'',
|
|
18
|
+
`> ${step.question.replace(/\n/g, '\n> ')}`,
|
|
19
|
+
'',
|
|
20
|
+
'Their answer:',
|
|
21
|
+
'',
|
|
22
|
+
step.answer.trim(),
|
|
23
|
+
'',
|
|
24
|
+
phase === 'plan'
|
|
25
|
+
? 'Go on planning from where you stopped, in this same checkout, using that answer — change nothing — then report the plan with report_plan and end the session.'
|
|
26
|
+
: 'Go on with the task from where you stopped, in this same checkout, using that answer.',
|
|
27
|
+
].join('\n');
|
|
28
|
+
case 'plan_go':
|
|
29
|
+
return planGoBrief(step.steps, step.by);
|
|
30
|
+
case 'plan_revise':
|
|
31
|
+
return planPhaseBrief(step.round, step.note);
|
|
32
|
+
case 'stop':
|
|
33
|
+
return step.reason;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function resumeFromParked(kept, promptHash) {
|
|
37
|
+
return {
|
|
38
|
+
workItemId: kept.workItemId,
|
|
39
|
+
runId: kept.runId,
|
|
40
|
+
engine: kept.engine,
|
|
41
|
+
sessionId: kept.sessionId ?? '',
|
|
42
|
+
repo: kept.repo || null,
|
|
43
|
+
branch: kept.branch,
|
|
44
|
+
base: kept.base,
|
|
45
|
+
worktree: kept.worktree,
|
|
46
|
+
repoPath: kept.repoPath,
|
|
47
|
+
...(kept.readHead ? { readHead: kept.readHead } : {}),
|
|
48
|
+
resetsAt: null,
|
|
49
|
+
cutAt: kept.keptAt,
|
|
50
|
+
keepUntil: kept.keepUntil,
|
|
51
|
+
promptHash,
|
|
52
|
+
review: kept.review === true,
|
|
53
|
+
toolsOnly: kept.toolsOnly === true,
|
|
54
|
+
continuesBranch: kept.continuesBranch,
|
|
55
|
+
...(kept.sessionReport ? { usage: kept.sessionReport } : {}),
|
|
56
|
+
...(kept.writtenSkills ? { writtenSkills: kept.writtenSkills } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function parkedLine(runId, why) {
|
|
60
|
+
return why.kind === 'question'
|
|
61
|
+
? `${runId} asked a person a question (question ${why.seq}) — the session and its worktree are kept here until FireFunc hands back the answer`
|
|
62
|
+
: `${runId} made its plan (round ${why.seq}) — the session and its worktree are kept here until a person approves it; nothing was changed`;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RunUsage } from './usage.js';
|
|
2
|
+
import type { WrittenSkills } from './skills.js';
|
|
3
|
+
import type { ChangeKind } from './pr-title.js';
|
|
4
|
+
export type KeptChange = {
|
|
5
|
+
runId: string;
|
|
6
|
+
workItemId: string;
|
|
7
|
+
engine: string;
|
|
8
|
+
sessionId: string | null;
|
|
9
|
+
repo: string;
|
|
10
|
+
branch: string;
|
|
11
|
+
base: string;
|
|
12
|
+
worktree: string;
|
|
13
|
+
repoPath: string | null;
|
|
14
|
+
continuesBranch: boolean;
|
|
15
|
+
readHead?: string;
|
|
16
|
+
head: string;
|
|
17
|
+
round: number;
|
|
18
|
+
title: string;
|
|
19
|
+
kind: ChangeKind;
|
|
20
|
+
summary: string | null;
|
|
21
|
+
keptAt: string;
|
|
22
|
+
keepUntil: string;
|
|
23
|
+
writtenSkills?: WrittenSkills;
|
|
24
|
+
attemptUsage?: RunUsage;
|
|
25
|
+
sessionReport?: RunUsage;
|
|
26
|
+
park?: {
|
|
27
|
+
kind: 'question' | 'plan';
|
|
28
|
+
seq: number;
|
|
29
|
+
phase: 'plan' | 'work';
|
|
30
|
+
};
|
|
31
|
+
activitySeq?: number;
|
|
32
|
+
review?: boolean;
|
|
33
|
+
toolsOnly?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare const KEEP_DAYS = 15;
|
|
36
|
+
export declare function keptDir(runnerDir: string): string;
|
|
37
|
+
export declare function keepUntilFrom(at: number): string;
|
|
38
|
+
export declare function saveKept(runnerDir: string, rec: KeptChange): boolean;
|
|
39
|
+
export declare function listKept(runnerDir: string): KeptChange[];
|
|
40
|
+
export declare function keptFor(runnerDir: string, runId: string): KeptChange | null;
|
|
41
|
+
export declare function dropKept(runnerDir: string, runId: string): void;
|
|
42
|
+
export declare function keptRunIds(runnerDir: string): string[];
|
|
43
|
+
export declare function keptChangeWorktrees(runnerDir: string): Set<string>;
|
|
44
|
+
export declare function expiredKept(runnerDir: string, now?: number): KeptChange[];
|
|
45
|
+
export type ChangeSummary = {
|
|
46
|
+
files: Array<{
|
|
47
|
+
path: string;
|
|
48
|
+
added: number | null;
|
|
49
|
+
removed: number | null;
|
|
50
|
+
}>;
|
|
51
|
+
filesChanged: number;
|
|
52
|
+
added: number;
|
|
53
|
+
removed: number;
|
|
54
|
+
truncated: boolean;
|
|
55
|
+
};
|
|
56
|
+
export declare const FILES_MAX = 300;
|
|
57
|
+
export declare function parseNumstat(out: string): ChangeSummary;
|
|
58
|
+
export declare function changesOf(worktree: string, from: string, branch: string): Promise<ChangeSummary | null>;
|
|
59
|
+
export declare function reviseBrief(note: string, round: number): string;
|