@firefunc-agent/runner 0.9.7 → 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 (55) 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 +121 -0
  7. package/dist/api.js +147 -3
  8. package/dist/ask/index.d.ts +20 -0
  9. package/dist/ask/index.js +64 -0
  10. package/dist/ask-first.d.ts +8 -0
  11. package/dist/brief.d.ts +2 -0
  12. package/dist/brief.js +6 -0
  13. package/dist/build-info.json +2 -2
  14. package/dist/config.d.ts +2 -0
  15. package/dist/cut.d.ts +2 -1
  16. package/dist/cut.js +8 -4
  17. package/dist/daemon.js +14 -2
  18. package/dist/engines/claude.js +10 -4
  19. package/dist/git-auth.d.ts +1 -0
  20. package/dist/git-auth.js +9 -1
  21. package/dist/job.js +415 -38
  22. package/dist/keep-local.d.ts +1 -0
  23. package/dist/keep-local.js +3 -0
  24. package/dist/limit.d.ts +1 -0
  25. package/dist/limit.js +4 -1
  26. package/dist/locks.d.ts +3 -0
  27. package/dist/locks.js +46 -13
  28. package/dist/plan-phase/index.d.ts +11 -0
  29. package/dist/plan-phase/index.js +46 -0
  30. package/dist/pool.js +4 -2
  31. package/dist/pr-title.d.ts +5 -0
  32. package/dist/pr-title.js +18 -0
  33. package/dist/reference-files.d.ts +27 -0
  34. package/dist/reference-files.js +202 -0
  35. package/dist/run-attachments.d.ts +79 -0
  36. package/dist/run-attachments.js +276 -0
  37. package/dist/secret-scan.d.ts +1 -1
  38. package/dist/secret-scan.js +3 -0
  39. package/dist/secret-values.d.ts +17 -0
  40. package/dist/secret-values.js +81 -0
  41. package/dist/trail/chain.d.ts +12 -0
  42. package/dist/trail/chain.js +89 -0
  43. package/dist/trail/deltas.d.ts +34 -0
  44. package/dist/trail/deltas.js +206 -0
  45. package/dist/trail/index.d.ts +27 -0
  46. package/dist/trail/index.js +128 -0
  47. package/dist/trail/keys.d.ts +14 -0
  48. package/dist/trail/keys.js +61 -0
  49. package/dist/trail/recorder.d.ts +118 -0
  50. package/dist/trail/recorder.js +697 -0
  51. package/dist/trail/rules.d.ts +30 -0
  52. package/dist/trail/rules.js +158 -0
  53. package/dist/trail/stream.d.ts +41 -0
  54. package/dist/trail/stream.js +86 -0
  55. package/package.json +1 -1
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.
@@ -24,6 +24,7 @@ export declare function createActivityReporter(opts: {
24
24
  now?: () => Date;
25
25
  writeTools?: ReadonlySet<string>;
26
26
  holdMs?: number;
27
+ seqStart?: number;
27
28
  }): {
28
29
  push: (ev: SessionEvent) => void;
29
30
  flush: (final?: boolean) => Promise<void>;
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
@@ -17,6 +17,11 @@ export type ClaimedJob = {
17
17
  note: string;
18
18
  round: number;
19
19
  };
20
+ askPerson?: boolean;
21
+ planFirst?: boolean;
22
+ planRound?: number;
23
+ planApproved?: boolean;
24
+ parkStep?: ParkStep;
20
25
  baseBranch?: string | null;
21
26
  externalId: string | null;
22
27
  title: string | null;
@@ -36,6 +41,27 @@ export type ClaimedJob = {
36
41
  description?: string | null;
37
42
  content: string;
38
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
+ };
39
65
  contextPack?: unknown;
40
66
  mcpConfig?: unknown;
41
67
  maxMinutes?: number | null;
@@ -61,6 +87,26 @@ export type SecretScanReport = {
61
87
  }>;
62
88
  head?: string;
63
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
+ };
64
110
  export type ResultPayload = ({
65
111
  status: 'pr_opened';
66
112
  pr: {
@@ -82,6 +128,14 @@ export type ResultPayload = ({
82
128
  changes: ChangeSummary;
83
129
  head: string;
84
130
  summary?: string;
131
+ } | {
132
+ status: 'parked';
133
+ park: {
134
+ kind: 'question' | 'plan';
135
+ seq: number;
136
+ changedFiles?: number;
137
+ };
138
+ summary?: string;
85
139
  }) & {
86
140
  secretScan?: SecretScanReport;
87
141
  usage?: RunUsage;
@@ -150,6 +204,68 @@ export declare class RunnerApi {
150
204
  token: string;
151
205
  expiresAt?: string;
152
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
+ }>;
153
269
  event(runId: string, event: RunnerEvent, detail?: Record<string, unknown>): Promise<void>;
154
270
  activity(runId: string, steps: Array<{
155
271
  seq: number;
@@ -158,5 +274,10 @@ export declare class RunnerApi {
158
274
  label: string;
159
275
  detail?: Record<string, unknown>;
160
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>;
161
282
  result(runId: string, payload: ResultPayload): Promise<void>;
162
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) {
@@ -165,27 +166,145 @@ export class RunnerApi {
165
166
  return null;
166
167
  }
167
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
+ }
168
257
  async event(runId, event, detail) {
169
258
  await fetch(`${this.apiUrl}/channel/runs/${runId}/events`, {
170
259
  method: 'POST',
171
260
  headers: this.headers(),
172
- body: JSON.stringify({ event, detail }),
261
+ body: JSON.stringify(blankSecretsDeep({ event, detail })),
173
262
  }).catch(() => { });
174
263
  }
175
264
  async activity(runId, steps) {
176
265
  const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/activity`, {
177
266
  method: 'POST',
178
267
  headers: this.headers(),
179
- body: JSON.stringify({ steps }),
268
+ body: JSON.stringify(blankSecretsDeep({ steps })),
180
269
  });
181
270
  if (!res.ok)
182
271
  throw new Error(`activity post failed: ${res.status}`);
183
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
+ }
184
303
  async result(runId, payload) {
185
304
  const post = (body) => fetch(`${this.apiUrl}/channel/runs/${runId}/result`, {
186
305
  method: 'POST',
187
306
  headers: this.headers(),
188
- body: JSON.stringify(body),
307
+ body: JSON.stringify(blankSecretsDeep(body)),
189
308
  });
190
309
  let res = await post(payload);
191
310
  let sent = { ...payload };
@@ -207,4 +326,29 @@ export class RunnerApi {
207
326
  throw new Error(`result report failed: ${res.status}`);
208
327
  }
209
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
+ }
210
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
@@ -23,6 +23,14 @@ export type KeptChange = {
23
23
  writtenSkills?: WrittenSkills;
24
24
  attemptUsage?: RunUsage;
25
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;
26
34
  };
27
35
  export declare const KEEP_DAYS = 15;
28
36
  export declare function keptDir(runnerDir: string): string;
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.7",
3
- "builtAt": "2026-10-06T13:04:16.103Z"
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;
@@ -43,4 +44,4 @@ export declare function cutFor(runnerDir: string, key: CutKey, now?: number): {
43
44
  export declare function expiredCuts(runnerDir: string, now?: number): CutSession[];
44
45
  export declare function keptWorktrees(runnerDir: string): Set<string>;
45
46
  export declare function cutWorktrees(runnerDir: string): Set<string>;
46
- export declare function resumeAfterResetBrief(prompt: string, briefChanged: boolean): string;
47
+ export declare function resumeAfterResetBrief(prompt: string, briefChanged: boolean, reason?: CutSession['reason']): string;
package/dist/cut.js CHANGED
@@ -100,10 +100,14 @@ export function keptWorktrees(runnerDir) {
100
100
  export function cutWorktrees(runnerDir) {
101
101
  return new Set(listCuts(runnerDir).map((c) => c.worktree));
102
102
  }
103
- export function resumeAfterResetBrief(prompt, briefChanged) {
104
- return ("Your session on this task was stopped by the plan's usage limit, which has now reset. " +
105
- 'The worktree still holds everything you did — check `git status` and `git diff`, then ' +
106
- '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.') +
107
111
  (briefChanged
108
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' +
109
113
  prompt