@firefunc-agent/runner 0.9.7 → 0.9.34

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 (178) hide show
  1. package/README.md +169 -10
  2. package/dist/activity.d.ts +1 -0
  3. package/dist/activity.js +1 -1
  4. package/dist/alive.d.ts +40 -0
  5. package/dist/alive.js +138 -0
  6. package/dist/api-fallback.d.ts +11 -0
  7. package/dist/api-fallback.js +80 -0
  8. package/dist/api.d.ts +186 -3
  9. package/dist/api.js +311 -6
  10. package/dist/ask/index.d.ts +20 -0
  11. package/dist/ask/index.js +64 -0
  12. package/dist/ask-first.d.ts +8 -0
  13. package/dist/brief-file.d.ts +15 -0
  14. package/dist/brief-file.js +36 -0
  15. package/dist/brief.d.ts +5 -0
  16. package/dist/brief.js +19 -3
  17. package/dist/build-caches.d.ts +7 -0
  18. package/dist/build-caches.js +63 -0
  19. package/dist/build-info.json +2 -2
  20. package/dist/checkpoint.d.ts +40 -0
  21. package/dist/checkpoint.js +98 -0
  22. package/dist/cli.js +184 -18
  23. package/dist/cloud-boot.d.ts +41 -0
  24. package/dist/cloud-boot.js +239 -0
  25. package/dist/command-activity.d.ts +23 -0
  26. package/dist/command-activity.js +89 -0
  27. package/dist/command-step.d.ts +58 -0
  28. package/dist/command-step.js +248 -0
  29. package/dist/config.d.ts +40 -0
  30. package/dist/config.js +23 -0
  31. package/dist/cut.d.ts +2 -1
  32. package/dist/cut.js +19 -5
  33. package/dist/daemon.js +375 -14
  34. package/dist/device-lease.d.ts +15 -0
  35. package/dist/device-lease.js +608 -0
  36. package/dist/editor/fs-server.d.ts +31 -0
  37. package/dist/editor/fs-server.js +159 -0
  38. package/dist/editor/relay-crypto.d.ts +68 -0
  39. package/dist/editor/relay-crypto.js +191 -0
  40. package/dist/editor/sessions.d.ts +50 -0
  41. package/dist/editor/sessions.js +279 -0
  42. package/dist/editor/worktree-of.d.ts +1 -0
  43. package/dist/editor/worktree-of.js +23 -0
  44. package/dist/editor/ws-client.d.ts +26 -0
  45. package/dist/editor/ws-client.js +227 -0
  46. package/dist/engine-account.d.ts +24 -0
  47. package/dist/engine-account.js +118 -0
  48. package/dist/engine-login.d.ts +12 -0
  49. package/dist/engine-login.js +88 -0
  50. package/dist/engine-models.d.ts +13 -0
  51. package/dist/engine-models.js +71 -0
  52. package/dist/engine-watch.d.ts +1 -0
  53. package/dist/engine-watch.js +22 -6
  54. package/dist/engines/antigravity.js +19 -4
  55. package/dist/engines/claude.js +15 -8
  56. package/dist/engines/codex.js +16 -2
  57. package/dist/engines/copilot.js +12 -0
  58. package/dist/engines/crush.d.ts +2 -0
  59. package/dist/engines/crush.js +58 -0
  60. package/dist/engines/cursor.js +12 -0
  61. package/dist/engines/gemini.js +14 -9
  62. package/dist/engines/index.d.ts +8 -0
  63. package/dist/engines/index.js +73 -1
  64. package/dist/engines/kilo.d.ts +2 -0
  65. package/dist/engines/kilo.js +63 -0
  66. package/dist/engines/opencode.d.ts +9 -0
  67. package/dist/engines/opencode.js +234 -0
  68. package/dist/engines/openhands.d.ts +10 -0
  69. package/dist/engines/openhands.js +271 -0
  70. package/dist/engines/pi.d.ts +10 -0
  71. package/dist/engines/pi.js +248 -0
  72. package/dist/engines/qwen.d.ts +8 -0
  73. package/dist/engines/qwen.js +153 -0
  74. package/dist/engines/sessions.d.ts +6 -0
  75. package/dist/engines/sessions.js +68 -0
  76. package/dist/engines/types.d.ts +3 -3
  77. package/dist/exec.d.ts +1 -0
  78. package/dist/exec.js +10 -4
  79. package/dist/firefunc/agents.d.ts +8 -1
  80. package/dist/firefunc/agents.js +53 -3
  81. package/dist/firefunc/auth.js +72 -19
  82. package/dist/firefunc/cli.js +25 -0
  83. package/dist/firefunc/client.d.ts +5 -1
  84. package/dist/firefunc/client.js +12 -2
  85. package/dist/firefunc/config.d.ts +11 -1
  86. package/dist/firefunc/config.js +6 -4
  87. package/dist/firefunc/io.d.ts +1 -0
  88. package/dist/firefunc/main.js +8 -1
  89. package/dist/firefunc/oauth-login.d.ts +23 -0
  90. package/dist/firefunc/oauth-login.js +304 -0
  91. package/dist/firefunc/tasks.d.ts +4 -0
  92. package/dist/firefunc/tasks.js +89 -2
  93. package/dist/fleet-words.d.ts +2 -0
  94. package/dist/fleet-words.js +7 -0
  95. package/dist/git-auth.d.ts +16 -0
  96. package/dist/git-auth.js +48 -2
  97. package/dist/held.d.ts +3 -0
  98. package/dist/job.d.ts +26 -3
  99. package/dist/job.js +1109 -132
  100. package/dist/keep-awake.d.ts +17 -0
  101. package/dist/keep-awake.js +90 -0
  102. package/dist/keep-local.d.ts +2 -1
  103. package/dist/keep-local.js +8 -3
  104. package/dist/limit.d.ts +10 -1
  105. package/dist/limit.js +264 -4
  106. package/dist/local-checks.d.ts +19 -0
  107. package/dist/local-checks.js +79 -0
  108. package/dist/locks.d.ts +21 -1
  109. package/dist/locks.js +279 -66
  110. package/dist/machine-commands.d.ts +21 -0
  111. package/dist/machine-commands.js +107 -0
  112. package/dist/machine-profile.d.ts +18 -0
  113. package/dist/machine-profile.js +69 -0
  114. package/dist/mcp-init.d.ts +2 -0
  115. package/dist/mcp-init.js +28 -0
  116. package/dist/mcp.d.ts +13 -1
  117. package/dist/mcp.js +23 -2
  118. package/dist/network.js +3 -2
  119. package/dist/orphans.d.ts +4 -0
  120. package/dist/orphans.js +96 -4
  121. package/dist/plan-phase/index.d.ts +11 -0
  122. package/dist/plan-phase/index.js +46 -0
  123. package/dist/pool.d.ts +1 -0
  124. package/dist/pool.js +29 -4
  125. package/dist/pr-title.d.ts +15 -0
  126. package/dist/pr-title.js +33 -0
  127. package/dist/recover.d.ts +3 -1
  128. package/dist/recover.js +27 -7
  129. package/dist/reference-files.d.ts +27 -0
  130. package/dist/reference-files.js +202 -0
  131. package/dist/release-draft.d.ts +79 -0
  132. package/dist/release-draft.js +301 -0
  133. package/dist/resources.d.ts +86 -0
  134. package/dist/resources.js +217 -0
  135. package/dist/restart-idle.d.ts +23 -0
  136. package/dist/restart-idle.js +67 -0
  137. package/dist/run-attachments.d.ts +84 -0
  138. package/dist/run-attachments.js +281 -0
  139. package/dist/run-stops.d.ts +15 -0
  140. package/dist/run-stops.js +90 -0
  141. package/dist/run-temp.d.ts +12 -0
  142. package/dist/run-temp.js +57 -0
  143. package/dist/secret-scan.d.ts +6 -1
  144. package/dist/secret-scan.js +33 -0
  145. package/dist/secret-values.d.ts +17 -0
  146. package/dist/secret-values.js +81 -0
  147. package/dist/self-upgrade.d.ts +36 -0
  148. package/dist/self-upgrade.js +78 -0
  149. package/dist/service.d.ts +7 -1
  150. package/dist/service.js +50 -7
  151. package/dist/sign-in.d.ts +41 -0
  152. package/dist/sign-in.js +239 -0
  153. package/dist/tool-call.d.ts +59 -0
  154. package/dist/tool-call.js +375 -0
  155. package/dist/trail/chain.d.ts +12 -0
  156. package/dist/trail/chain.js +89 -0
  157. package/dist/trail/deltas.d.ts +34 -0
  158. package/dist/trail/deltas.js +206 -0
  159. package/dist/trail/index.d.ts +27 -0
  160. package/dist/trail/index.js +128 -0
  161. package/dist/trail/keys.d.ts +14 -0
  162. package/dist/trail/keys.js +61 -0
  163. package/dist/trail/recorder.d.ts +118 -0
  164. package/dist/trail/recorder.js +697 -0
  165. package/dist/trail/rules.d.ts +30 -0
  166. package/dist/trail/rules.js +158 -0
  167. package/dist/trail/stream.d.ts +41 -0
  168. package/dist/trail/stream.js +86 -0
  169. package/dist/transport.d.ts +26 -0
  170. package/dist/transport.js +118 -0
  171. package/dist/work-dir.d.ts +11 -0
  172. package/dist/work-dir.js +69 -0
  173. package/dist/worktree-report.d.ts +10 -0
  174. package/dist/worktree-report.js +17 -0
  175. package/dist/worktrees.d.ts +16 -1
  176. package/dist/worktrees.js +62 -17
  177. package/package.json +4 -4
  178. package/skill/firefunc/SKILL.md +4 -3
package/dist/api.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ import { type SignInPrefs, type SignInReport } from './sign-in.js';
2
+ import type { ReleaseOffer, ReleaseReport } from './release-draft.js';
3
+ import type { LocalChecksReport } from './local-checks.js';
1
4
  import type { ChangeSummary } from './ask-first.js';
2
5
  import type { RunUsage } from './usage.js';
6
+ import type { ResourcesReport } from './resources.js';
7
+ import type { RelayTicket } from './editor/sessions.js';
3
8
  export type ClaimedJob = {
4
9
  runId: string;
5
10
  workItemId: string;
@@ -7,6 +12,15 @@ export type ClaimedJob = {
7
12
  repo: string | null;
8
13
  branch: string | null;
9
14
  toolsOnly?: boolean;
15
+ checkpoint?: {
16
+ ref: string;
17
+ sha: string;
18
+ at?: string;
19
+ } | null;
20
+ checks?: Array<{
21
+ key: string;
22
+ command: string;
23
+ }>;
10
24
  continuesBranch?: boolean;
11
25
  review?: boolean;
12
26
  askFirst?: boolean;
@@ -17,12 +31,19 @@ export type ClaimedJob = {
17
31
  note: string;
18
32
  round: number;
19
33
  };
34
+ askPerson?: boolean;
35
+ planFirst?: boolean;
36
+ planRound?: number;
37
+ planApproved?: boolean;
38
+ parkStep?: ParkStep;
20
39
  baseBranch?: string | null;
21
40
  externalId: string | null;
22
41
  title: string | null;
23
42
  type: string;
24
43
  engine?: string | null;
25
44
  model?: string | null;
45
+ planModel?: string | null;
46
+ signIn?: 'plan' | 'key' | null;
26
47
  effort?: string | null;
27
48
  permissionMode?: string | null;
28
49
  attachments?: {
@@ -36,11 +57,38 @@ export type ClaimedJob = {
36
57
  description?: string | null;
37
58
  content: string;
38
59
  }[];
60
+ agentEnv?: {
61
+ name: string;
62
+ secret: boolean;
63
+ }[];
64
+ referenceFiles?: {
65
+ id: string;
66
+ name: string;
67
+ size: number;
68
+ sha256: string;
69
+ }[];
70
+ runAttachments?: {
71
+ folder?: string;
72
+ maxFiles?: number;
73
+ maxFileBytes?: number;
74
+ maxTotalBytes?: number;
75
+ types?: string[];
76
+ };
77
+ trail?: {
78
+ detail?: string;
79
+ off?: boolean;
80
+ };
81
+ provenance?: {
82
+ runUrl?: string | null;
83
+ trailers?: string[];
84
+ prFooter?: string | null;
85
+ };
86
+ release?: ReleaseOffer;
39
87
  contextPack?: unknown;
40
88
  mcpConfig?: unknown;
41
89
  maxMinutes?: number | null;
42
90
  };
43
- export type RunnerEvent = 'cloning' | 'fixing' | 'pushing' | 'pr_opened' | 'heartbeat' | 'log';
91
+ export type RunnerEvent = 'cloning' | 'fixing' | 'pushing' | 'pr_opened' | 'heartbeat' | 'log' | 'checkpoint' | 'worktree';
44
92
  export type PlanLimitReport = {
45
93
  kind: 'plan';
46
94
  resetsAt: string | null;
@@ -61,6 +109,26 @@ export type SecretScanReport = {
61
109
  }>;
62
110
  head?: string;
63
111
  };
112
+ export type ParkStep = {
113
+ kind: 'answer';
114
+ seq: number;
115
+ question: string;
116
+ answer: string;
117
+ by: string | null;
118
+ } | {
119
+ kind: 'stop';
120
+ reason: string;
121
+ } | {
122
+ kind: 'plan_go';
123
+ round: number;
124
+ steps: string[];
125
+ by: string | null;
126
+ } | {
127
+ kind: 'plan_revise';
128
+ round: number;
129
+ note: string;
130
+ by: string | null;
131
+ };
64
132
  export type ResultPayload = ({
65
133
  status: 'pr_opened';
66
134
  pr: {
@@ -82,22 +150,37 @@ export type ResultPayload = ({
82
150
  changes: ChangeSummary;
83
151
  head: string;
84
152
  summary?: string;
153
+ } | {
154
+ status: 'parked';
155
+ park: {
156
+ kind: 'question' | 'plan';
157
+ seq: number;
158
+ changedFiles?: number;
159
+ };
160
+ summary?: string;
85
161
  }) & {
86
162
  secretScan?: SecretScanReport;
163
+ localChecks?: LocalChecksReport;
87
164
  usage?: RunUsage;
88
165
  limit?: PlanLimitReport | MachineLimitReport;
89
166
  readHead?: string;
90
167
  openCommandAtEnd?: true;
91
168
  lost?: true;
169
+ release?: ReleaseReport;
92
170
  };
93
171
  export declare const REPORTED_SUMMARY_MAX = 65536;
94
172
  export declare const OLDER_API_SUMMARY_MAX = 4000;
95
173
  export declare function cutText(text: string, max: number): string;
96
- export declare const RESULT_LADDER: readonly ["lost", "openCommandAtEnd", "readHead", "limit", "summary", "usage", "secretScan"];
174
+ export declare const RESULT_LADDER: readonly ["localChecks", "release", "lost", "openCommandAtEnd", "readHead", "limit", "summary", "usage", "secretScan"];
97
175
  export declare class RunnerApi {
98
176
  private readonly apiUrl;
99
- private readonly token;
177
+ private token;
100
178
  constructor(apiUrl: string, token: string);
179
+ setToken(token: string): void;
180
+ rotateToken(): Promise<{
181
+ token: string;
182
+ expiresAt: string | null;
183
+ } | null>;
101
184
  private headers;
102
185
  claim(meta: {
103
186
  version: string;
@@ -132,14 +215,47 @@ export declare class RunnerApi {
132
215
  engine: string;
133
216
  code: string;
134
217
  }>;
218
+ resources?: ResourcesReport;
135
219
  awaitingRuns?: string[];
220
+ toolCallSlots?: number;
221
+ allowsCommands?: boolean;
222
+ commandSlots?: number;
223
+ allowsEditors?: boolean;
224
+ signIn?: SignInReport;
136
225
  }, opts?: {
137
226
  onDiscard?: (runIds: string[]) => void;
227
+ onStop?: (runIds: string[]) => void;
228
+ onUpgrade?: (cmd: {
229
+ version: string;
230
+ requestedAt: string;
231
+ }) => void;
232
+ onToken?: (cmd: {
233
+ rotate: true;
234
+ why: string;
235
+ }) => void;
236
+ onToolCalls?: (calls: unknown[]) => void;
237
+ onCommands?: (commands: unknown[]) => void;
238
+ onStopCommands?: (ids: unknown[]) => void;
239
+ onEditorSessions?: (sessions: unknown[]) => void;
138
240
  }): Promise<ClaimedJob | null>;
241
+ commandResult(id: string, report: unknown): Promise<boolean>;
242
+ private editorPost;
243
+ private static relayOf;
244
+ acceptEditorGrant(grantId: string, body: {
245
+ publicKey: string;
246
+ signature: string;
247
+ machineKey: string;
248
+ }): Promise<RelayTicket | null>;
249
+ editorTicket(grantId: string): Promise<RelayTicket | null>;
250
+ refuseEditorGrant(grantId: string, reason: 'editor_off' | 'no_folder' | 'bad_signature' | 'busy'): Promise<boolean>;
251
+ endEditorGrant(grantId: string, reason: 'runner_ended' | 'task_ended'): Promise<boolean>;
252
+ toolCallResult(id: string, report: unknown): Promise<boolean>;
139
253
  repos(): Promise<string[]>;
140
254
  probe(): Promise<boolean>;
141
255
  config(): Promise<{
142
256
  maxParallel: number;
257
+ requiredCommands: string[] | null;
258
+ signInPrefs: SignInPrefs | null;
143
259
  } | null>;
144
260
  gitCredential(runId: string): Promise<{
145
261
  token: string;
@@ -150,6 +266,68 @@ export declare class RunnerApi {
150
266
  token: string;
151
267
  expiresAt?: string;
152
268
  } | null>;
269
+ agentEnv(runId: string): Promise<{
270
+ env: Array<{
271
+ name: string;
272
+ value: string;
273
+ secret: boolean;
274
+ }>;
275
+ missing: Array<{
276
+ name: string;
277
+ reason: string;
278
+ fix: string;
279
+ }>;
280
+ } | {
281
+ refused: {
282
+ reason: string;
283
+ fix: string;
284
+ };
285
+ }>;
286
+ referenceFiles(runId: string): Promise<{
287
+ files: Array<{
288
+ name: string;
289
+ size: number;
290
+ sha256: string;
291
+ url: string;
292
+ }>;
293
+ missing: Array<{
294
+ name: string;
295
+ reason: string;
296
+ fix: string;
297
+ }>;
298
+ } | {
299
+ refused: {
300
+ reason: string;
301
+ fix: string;
302
+ };
303
+ }>;
304
+ offerAttachment(runId: string, file: {
305
+ name: string;
306
+ size: number;
307
+ sha256: string;
308
+ contentType: string;
309
+ }): Promise<{
310
+ id: string;
311
+ upload: {
312
+ url: string;
313
+ headers: Record<string, string>;
314
+ };
315
+ } | {
316
+ refused: {
317
+ reason: string;
318
+ fix: string;
319
+ status: number;
320
+ };
321
+ }>;
322
+ completeAttachment(runId: string, attachmentId: string): Promise<{
323
+ ok: true;
324
+ } | {
325
+ refused: {
326
+ reason: string;
327
+ fix: string;
328
+ status: number;
329
+ };
330
+ }>;
153
331
  event(runId: string, event: RunnerEvent, detail?: Record<string, unknown>): Promise<void>;
154
332
  activity(runId: string, steps: Array<{
155
333
  seq: number;
@@ -158,5 +336,10 @@ export declare class RunnerApi {
158
336
  label: string;
159
337
  detail?: Record<string, unknown>;
160
338
  }>): Promise<void>;
339
+ trail(runId: string, batch: unknown): Promise<'ok' | 'gone' | 'refused'>;
340
+ parkCheck(runId: string): Promise<{
341
+ kind: 'question' | 'plan';
342
+ seq: number;
343
+ } | null>;
161
344
  result(runId: string, payload: ResultPayload): Promise<void>;
162
345
  }
package/dist/api.js CHANGED
@@ -1,4 +1,7 @@
1
+ import { parseSignInPrefs } from './sign-in.js';
1
2
  import { RUNNER_VERSION } from './version.js';
3
+ import { blankSecretsDeep } from './secret-values.js';
4
+ import { readStopList } from './run-stops.js';
2
5
  export const REPORTED_SUMMARY_MAX = 65_536;
3
6
  export const OLDER_API_SUMMARY_MAX = 4000;
4
7
  export function cutText(text, max) {
@@ -8,6 +11,8 @@ export function cutText(text, max) {
8
11
  return text.slice(0, last >= 0xd800 && last <= 0xdbff ? max - 1 : max);
9
12
  }
10
13
  export const RESULT_LADDER = [
14
+ 'localChecks',
15
+ 'release',
11
16
  'lost',
12
17
  'openCommandAtEnd',
13
18
  'readHead',
@@ -63,6 +68,25 @@ export class RunnerApi {
63
68
  this.token = token;
64
69
  this.apiUrl = apiUrl.replace(/\/+$/, '');
65
70
  }
71
+ setToken(token) {
72
+ this.token = token;
73
+ }
74
+ async rotateToken() {
75
+ const res = await fetch(`${this.apiUrl}/channel/token/rotate`, {
76
+ method: 'POST',
77
+ headers: this.headers(),
78
+ body: '{}',
79
+ });
80
+ if (!res.ok)
81
+ return null;
82
+ const body = (await res.json());
83
+ if (typeof body.token !== 'string' || !body.token.startsWith('ffr_'))
84
+ return null;
85
+ return {
86
+ token: body.token,
87
+ expiresAt: typeof body.expiresAt === 'string' ? body.expiresAt : null,
88
+ };
89
+ }
66
90
  headers() {
67
91
  return { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' };
68
92
  }
@@ -78,22 +102,135 @@ export class RunnerApi {
78
102
  });
79
103
  if (res.status === 204)
80
104
  return null;
81
- if (res.status === 401)
82
- throw new Error('runner token rejected (revoked or wrong API URL)');
105
+ if (res.status === 401) {
106
+ const why = await res.json().catch(() => null);
107
+ throw new Error(`runner token rejected (${refusalWords(why) ?? 'revoked or wrong API URL'})`);
108
+ }
109
+ if (res.status === 426) {
110
+ const why = (await res.json().catch(() => null));
111
+ const up = readUpgrade(why?.upgrade);
112
+ if (up && opts.onUpgrade)
113
+ opts.onUpgrade(up);
114
+ throw new Error(`claim refused: ${refusalWords(why) ?? 'this runner is below the workspace’s minimum version'}`);
115
+ }
83
116
  if (!res.ok)
84
117
  throw new Error(`claim failed: ${res.status}`);
85
118
  const body = (await res.json());
119
+ if (Array.isArray(body.editorSessions) &&
120
+ body.editorSessions.length > 0 &&
121
+ opts.onEditorSessions) {
122
+ opts.onEditorSessions(body.editorSessions);
123
+ }
124
+ if (Array.isArray(body.stopCommands) && body.stopCommands.length > 0 && opts.onStopCommands) {
125
+ opts.onStopCommands(body.stopCommands);
126
+ }
127
+ if (Array.isArray(body.commandSteps) && body.commandSteps.length > 0 && opts.onCommands) {
128
+ opts.onCommands(body.commandSteps);
129
+ }
130
+ if (Array.isArray(body.toolCalls) && body.toolCalls.length > 0 && opts.onToolCalls) {
131
+ opts.onToolCalls(body.toolCalls);
132
+ }
133
+ const up = readUpgrade(body.upgrade);
134
+ if (up && opts.onUpgrade)
135
+ opts.onUpgrade(up);
136
+ const tok = body.token;
137
+ if (tok && tok.rotate === true && opts.onToken) {
138
+ opts.onToken({ rotate: true, why: typeof tok.why === 'string' ? tok.why : 'asked' });
139
+ }
86
140
  if (Array.isArray(body.discard) && opts.onDiscard) {
87
141
  const ids = body.discard.filter((x) => typeof x === 'string');
88
142
  if (ids.length > 0)
89
143
  opts.onDiscard(ids);
90
144
  }
145
+ if (opts.onStop) {
146
+ const ids = readStopList(body);
147
+ if (ids.length > 0)
148
+ opts.onStop(ids);
149
+ }
91
150
  return body.job ?? null;
92
151
  }
93
152
  finally {
94
153
  clearTimeout(timer);
95
154
  }
96
155
  }
156
+ async commandResult(id, report) {
157
+ for (let attempt = 0; attempt < 3; attempt += 1) {
158
+ try {
159
+ const res = await fetch(`${this.apiUrl}/channel/commands/${id}/result`, {
160
+ method: 'POST',
161
+ headers: this.headers(),
162
+ body: JSON.stringify(report),
163
+ signal: AbortSignal.timeout(20_000),
164
+ });
165
+ if (res.ok)
166
+ return true;
167
+ if (res.status < 500 && res.status !== 429)
168
+ return false;
169
+ }
170
+ catch {
171
+ }
172
+ await new Promise((r) => setTimeout(r, 1_000 * (attempt + 1)));
173
+ }
174
+ return false;
175
+ }
176
+ async editorPost(path, body) {
177
+ try {
178
+ const res = await fetch(`${this.apiUrl}/channel/editor-grants/${path}`, {
179
+ method: 'POST',
180
+ headers: this.headers(),
181
+ body: JSON.stringify(body ?? {}),
182
+ signal: AbortSignal.timeout(30_000),
183
+ });
184
+ if (!res.ok)
185
+ return null;
186
+ return (await res.json().catch(() => ({}))) ?? {};
187
+ }
188
+ catch {
189
+ return null;
190
+ }
191
+ }
192
+ static relayOf(body) {
193
+ const r = body?.relay;
194
+ if (!r || typeof r.url !== 'string' || typeof r.ticket !== 'string')
195
+ return null;
196
+ return {
197
+ url: r.url,
198
+ ticket: r.ticket,
199
+ expiresAt: typeof r.expiresAt === 'string' ? r.expiresAt : null,
200
+ };
201
+ }
202
+ async acceptEditorGrant(grantId, body) {
203
+ return RunnerApi.relayOf(await this.editorPost(`${encodeURIComponent(grantId)}/accept`, body));
204
+ }
205
+ async editorTicket(grantId) {
206
+ return RunnerApi.relayOf(await this.editorPost(`${encodeURIComponent(grantId)}/ticket`, {}));
207
+ }
208
+ async refuseEditorGrant(grantId, reason) {
209
+ return (await this.editorPost(`${encodeURIComponent(grantId)}/refuse`, { reason })) !== null;
210
+ }
211
+ async endEditorGrant(grantId, reason) {
212
+ return (await this.editorPost(`${encodeURIComponent(grantId)}/end`, { reason })) !== null;
213
+ }
214
+ async toolCallResult(id, report) {
215
+ for (let attempt = 0; attempt < 3; attempt += 1) {
216
+ try {
217
+ const res = await fetch(`${this.apiUrl}/channel/tool-calls/${id}/result`, {
218
+ method: 'POST',
219
+ headers: this.headers(),
220
+ body: JSON.stringify(report),
221
+ signal: AbortSignal.timeout(20_000),
222
+ });
223
+ if (res.ok)
224
+ return true;
225
+ if (res.status < 500 && res.status !== 429)
226
+ return false;
227
+ }
228
+ catch {
229
+ }
230
+ await new Promise((r) => setTimeout(r, 1_000 * (attempt + 1)));
231
+ }
232
+ return false;
233
+ }
97
234
  async repos() {
98
235
  try {
99
236
  const res = await fetch(`${this.apiUrl}/channel/repos`, { headers: this.headers() });
@@ -123,7 +260,13 @@ export class RunnerApi {
123
260
  if (!res.ok)
124
261
  return null;
125
262
  const body = (await res.json());
126
- return { maxParallel: typeof body.maxParallel === 'number' ? body.maxParallel : 1 };
263
+ return {
264
+ maxParallel: typeof body.maxParallel === 'number' ? body.maxParallel : 1,
265
+ requiredCommands: Array.isArray(body.requiredCommands)
266
+ ? body.requiredCommands.filter((c) => typeof c === 'string')
267
+ : null,
268
+ signInPrefs: parseSignInPrefs(body.signInPrefs),
269
+ };
127
270
  }
128
271
  catch {
129
272
  return null;
@@ -165,27 +308,145 @@ export class RunnerApi {
165
308
  return null;
166
309
  }
167
310
  }
311
+ async agentEnv(runId) {
312
+ const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/agent-env`, {
313
+ method: 'POST',
314
+ headers: this.headers(),
315
+ body: '{}',
316
+ });
317
+ const body = (await res.json().catch(() => null));
318
+ if (!res.ok || !body?.ok) {
319
+ return {
320
+ refused: {
321
+ reason: typeof body?.reason === 'string'
322
+ ? body.reason
323
+ : `FireFunc answered ${res.status} when the run asked for its environment variables.`,
324
+ fix: typeof body?.fix === 'string' ? body.fix : 'Re-run the task.',
325
+ },
326
+ };
327
+ }
328
+ const env = Array.isArray(body.env)
329
+ ? body.env.flatMap((e) => {
330
+ const o = e;
331
+ return o && typeof o.name === 'string' && typeof o.value === 'string'
332
+ ? [{ name: o.name, value: o.value, secret: o.secret === true }]
333
+ : [];
334
+ })
335
+ : [];
336
+ return { env, missing: missingOf(body.missing) };
337
+ }
338
+ async referenceFiles(runId) {
339
+ const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/reference-files`, {
340
+ method: 'POST',
341
+ headers: this.headers(),
342
+ body: '{}',
343
+ });
344
+ const body = (await res.json().catch(() => null));
345
+ if (!res.ok || !body?.ok) {
346
+ return {
347
+ refused: {
348
+ reason: typeof body?.reason === 'string'
349
+ ? body.reason
350
+ : `FireFunc answered ${res.status} when the run asked for its reference files.`,
351
+ fix: typeof body?.fix === 'string' ? body.fix : 'Re-run the task.',
352
+ },
353
+ };
354
+ }
355
+ const files = Array.isArray(body.files)
356
+ ? body.files.flatMap((f) => {
357
+ const o = f;
358
+ return o &&
359
+ typeof o.name === 'string' &&
360
+ typeof o.size === 'number' &&
361
+ typeof o.sha256 === 'string' &&
362
+ typeof o.url === 'string'
363
+ ? [{ name: o.name, size: o.size, sha256: o.sha256, url: o.url }]
364
+ : [];
365
+ })
366
+ : [];
367
+ return { files, missing: missingOf(body.missing) };
368
+ }
369
+ async offerAttachment(runId, file) {
370
+ const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/attachments`, {
371
+ method: 'POST',
372
+ headers: this.headers(),
373
+ body: JSON.stringify(file),
374
+ });
375
+ const body = (await res.json().catch(() => null));
376
+ if (!res.ok ||
377
+ !body?.ok ||
378
+ typeof body.attachment?.id !== 'string' ||
379
+ typeof body.upload?.url !== 'string') {
380
+ return { refused: refusalOf(res.status, body, 'offered a picture') };
381
+ }
382
+ const headers = {};
383
+ if (body.upload.headers && typeof body.upload.headers === 'object') {
384
+ for (const [k, v] of Object.entries(body.upload.headers)) {
385
+ if (typeof v === 'string')
386
+ headers[k] = v;
387
+ }
388
+ }
389
+ return { id: body.attachment.id, upload: { url: body.upload.url, headers } };
390
+ }
391
+ async completeAttachment(runId, attachmentId) {
392
+ const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/attachments/${attachmentId}/complete`, { method: 'POST', headers: this.headers(), body: '{}' });
393
+ const body = (await res.json().catch(() => null));
394
+ if (!res.ok || !body?.ok) {
395
+ return { refused: refusalOf(res.status, body, 'asked for a picture to be checked') };
396
+ }
397
+ return { ok: true };
398
+ }
168
399
  async event(runId, event, detail) {
169
400
  await fetch(`${this.apiUrl}/channel/runs/${runId}/events`, {
170
401
  method: 'POST',
171
402
  headers: this.headers(),
172
- body: JSON.stringify({ event, detail }),
403
+ body: JSON.stringify(blankSecretsDeep({ event, detail })),
173
404
  }).catch(() => { });
174
405
  }
175
406
  async activity(runId, steps) {
176
407
  const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/activity`, {
177
408
  method: 'POST',
178
409
  headers: this.headers(),
179
- body: JSON.stringify({ steps }),
410
+ body: JSON.stringify(blankSecretsDeep({ steps })),
180
411
  });
181
412
  if (!res.ok)
182
413
  throw new Error(`activity post failed: ${res.status}`);
183
414
  }
415
+ async trail(runId, batch) {
416
+ const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/trail`, {
417
+ method: 'POST',
418
+ headers: this.headers(),
419
+ body: JSON.stringify(batch),
420
+ });
421
+ if (res.ok)
422
+ return 'ok';
423
+ if (res.status === 404) {
424
+ const body = (await res.json().catch(() => null));
425
+ return body?.error === 'run_not_found' ? 'refused' : 'gone';
426
+ }
427
+ if (res.status >= 500)
428
+ throw new Error(`trail post failed: ${res.status}`);
429
+ return 'refused';
430
+ }
431
+ async parkCheck(runId) {
432
+ const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/park-check`, {
433
+ method: 'POST',
434
+ headers: this.headers(),
435
+ body: '{}',
436
+ });
437
+ if (!res.ok)
438
+ return null;
439
+ const body = (await res.json().catch(() => null));
440
+ const p = body?.park;
441
+ return p && (p.kind === 'question' || p.kind === 'plan') && typeof p.seq === 'number'
442
+ ? { kind: p.kind, seq: p.seq }
443
+ : null;
444
+ }
184
445
  async result(runId, payload) {
185
446
  const post = (body) => fetch(`${this.apiUrl}/channel/runs/${runId}/result`, {
186
447
  method: 'POST',
187
448
  headers: this.headers(),
188
- body: JSON.stringify(body),
449
+ body: JSON.stringify(blankSecretsDeep(body)),
189
450
  });
190
451
  let res = await post(payload);
191
452
  let sent = { ...payload };
@@ -207,4 +468,48 @@ export class RunnerApi {
207
468
  throw new Error(`result report failed: ${res.status}`);
208
469
  }
209
470
  }
471
+ function refusalOf(status, body, what) {
472
+ return {
473
+ reason: typeof body?.reason === 'string'
474
+ ? body.reason
475
+ : `FireFunc answered ${status} when the run ${what}.`,
476
+ fix: typeof body?.fix === 'string' ? body.fix : 'Re-run the task.',
477
+ status,
478
+ };
479
+ }
480
+ function missingOf(raw) {
481
+ return Array.isArray(raw)
482
+ ? raw.flatMap((m) => {
483
+ const o = m;
484
+ return o && typeof o.name === 'string'
485
+ ? [
486
+ {
487
+ name: o.name,
488
+ reason: typeof o.reason === 'string' ? o.reason : '',
489
+ fix: typeof o.fix === 'string' ? o.fix : '',
490
+ },
491
+ ]
492
+ : [];
493
+ })
494
+ : [];
495
+ }
496
+ function refusalWords(body) {
497
+ if (!body || typeof body !== 'object')
498
+ return null;
499
+ const b = body;
500
+ if (typeof b.message !== 'string')
501
+ return null;
502
+ return typeof b.fix === 'string' ? `${b.message} ${b.fix}` : b.message;
503
+ }
504
+ function readUpgrade(raw) {
505
+ if (!raw || typeof raw !== 'object')
506
+ return null;
507
+ const u = raw;
508
+ if (typeof u.version !== 'string' || !/^(latest|\d+\.\d+\.\d+)$/.test(u.version))
509
+ return null;
510
+ return {
511
+ version: u.version,
512
+ requestedAt: typeof u.requestedAt === 'string' ? u.requestedAt : '',
513
+ };
514
+ }
210
515
  //# 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;