@firefunc-agent/runner 0.9.5 → 0.9.7

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.
@@ -0,0 +1,85 @@
1
+ import { blockedEnginesReport, noEngineCanRun, runnableEngines, } from './unattended.js';
2
+ export const ENGINE_RESCAN_MS = 120_000;
3
+ export function engineWatch(deps) {
4
+ const now = deps.now ?? (() => Date.now());
5
+ const everyMs = deps.everyMs ?? ENGINE_RESCAN_MS;
6
+ let installed = deps.installed;
7
+ let blocked = deps.blocksOf(installed);
8
+ let lastScan = now();
9
+ return {
10
+ get installed() {
11
+ return installed;
12
+ },
13
+ get blocked() {
14
+ return blocked;
15
+ },
16
+ get engines() {
17
+ return runnableEngines(installed, blocked);
18
+ },
19
+ blockedReport: () => blockedEnginesReport(blocked),
20
+ rescan() {
21
+ if (now() - lastScan < everyMs)
22
+ return;
23
+ lastScan = now();
24
+ let found;
25
+ try {
26
+ found = deps.scan();
27
+ }
28
+ catch {
29
+ return;
30
+ }
31
+ if (found.join(',') === installed.join(','))
32
+ return;
33
+ const added = found.filter((e) => !installed.includes(e));
34
+ const gone = installed.filter((e) => !found.includes(e));
35
+ installed = found;
36
+ const nowBlocked = deps.blocksOf(found);
37
+ const newly = nowBlocked.filter((b) => !blocked.some((x) => x.engine === b.engine));
38
+ if (newly.length)
39
+ deps.onNewlyBlocked?.(newly);
40
+ blocked = nowBlocked;
41
+ if (added.length)
42
+ deps.log?.(`engines now available: ${added.join(', ')}`);
43
+ if (gone.length)
44
+ deps.log?.(`engines no longer on PATH: ${gone.join(', ')}`);
45
+ },
46
+ };
47
+ }
48
+ export function claimPause(deps) {
49
+ let wasBlocked = false;
50
+ let pausedOn = null;
51
+ return () => {
52
+ deps.watch.rescan();
53
+ const runnable = deps.watch.engines;
54
+ if (noEngineCanRun(runnable, deps.watch.blocked)) {
55
+ if (!wasBlocked) {
56
+ deps.log('no engine on this machine can run unattended as this user — claiming no work; the Machines page in FireFunc shows why and the fix');
57
+ }
58
+ wasBlocked = true;
59
+ return true;
60
+ }
61
+ if (wasBlocked)
62
+ deps.log(`${runnable.join(', ')} can run unattended here — claiming work`);
63
+ wasBlocked = false;
64
+ const engines = runnable.length > 0 ? runnable : ['claude_code'];
65
+ const spent = engines.map((e) => deps.isLimited(e));
66
+ const all = spent.every((l) => l !== null);
67
+ if (all && !pausedOn) {
68
+ const until = spent
69
+ .map((l) => l.until)
70
+ .sort()
71
+ .at(-1);
72
+ deps.log(`the plan's usage limit is spent on every engine here — claiming no work until ${until}`);
73
+ }
74
+ else if (!all && pausedOn) {
75
+ const free = engines.filter((_, i) => spent[i] === null);
76
+ const wasSpent = pausedOn;
77
+ deps.log(free.some((e) => wasSpent.includes(e))
78
+ ? "the plan's usage limit has reset — claiming work again"
79
+ : `${free.join(', ')} ${free.length === 1 ? 'is' : 'are'} not waiting out a plan limit — claiming work again`);
80
+ }
81
+ pausedOn = all ? engines : null;
82
+ return all;
83
+ };
84
+ }
85
+ //# sourceMappingURL=engine-watch.js.map
@@ -46,6 +46,24 @@ function claudeEnding(streamJson) {
46
46
  }
47
47
  return undefined;
48
48
  }
49
+ const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
50
+ function claudeUnattendedBlock(ctx) {
51
+ if (ctx.permissionMode !== 'bypassPermissions')
52
+ return null;
53
+ if (ctx.platform === 'win32' || ctx.uid !== 0)
54
+ return null;
55
+ if (ctx.env.IS_SANDBOX === '1')
56
+ return null;
57
+ const bubblewrap = (ctx.env.CLAUDE_CODE_BUBBLEWRAP ?? '').trim().toLowerCase();
58
+ if (TRUTHY.has(bubblewrap))
59
+ return null;
60
+ return {
61
+ code: 'runs_as_root',
62
+ reason: 'the runner runs as root, and Claude Code refuses --permission-mode bypassPermissions as root or under sudo.',
63
+ fix: 'Run the runner as a normal user: stop it, then start it (or install its service) from an account that is not root.',
64
+ detail: 'Claude Code will not run as root — run the runner as a normal user',
65
+ };
66
+ }
49
67
  const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9-]{7,79}$/;
50
68
  function claudeSessionId(streamJson) {
51
69
  let id = null;
@@ -234,6 +252,14 @@ export const claudeAdapter = {
234
252
  }
235
253
  return null;
236
254
  },
255
+ unattendedBlock(ctx) {
256
+ try {
257
+ return claudeUnattendedBlock(ctx);
258
+ }
259
+ catch {
260
+ return null;
261
+ }
262
+ },
237
263
  readBudget(cfg) {
238
264
  return readClaudeBudget(cfg);
239
265
  },
@@ -61,8 +61,9 @@ export const copilotCliAdapter = {
61
61
  ];
62
62
  if (ctx.model)
63
63
  args.push('--model', ctx.model);
64
- if (ctx.effort)
65
- args.push('--effort', ctx.effort);
64
+ const effort = ctx.ultracode || ctx.effort === 'ultracode' ? 'xhigh' : ctx.effort;
65
+ if (effort)
66
+ args.push('--effort', effort);
66
67
  if (ctx.maxBudgetUsd)
67
68
  args.push('--max-ai-credits', String(ctx.maxBudgetUsd));
68
69
  if (ctx.attachDir && ctx.attachPaths.length)
@@ -1,6 +1,6 @@
1
1
  import type { AgentAdapter, EngineId } from './types.js';
2
2
  import type { RunnerConfig } from '../config.js';
3
- export type { AgentAdapter, EngineId, Invocation, InvocationContext } from './types.js';
3
+ export type { AgentAdapter, EngineId, Invocation, InvocationContext, UnattendedBlock, UnattendedContext, } from './types.js';
4
4
  export { claudeAdapter } from './claude.js';
5
5
  export { codexAdapter } from './codex.js';
6
6
  export { geminiAdapter } from './gemini.js';
@@ -19,6 +19,18 @@ export type InvocationContext = {
19
19
  cfg: RunnerConfig;
20
20
  resumeSessionId?: string;
21
21
  };
22
+ export type UnattendedContext = {
23
+ uid: number | null;
24
+ platform: NodeJS.Platform;
25
+ env: NodeJS.ProcessEnv;
26
+ permissionMode: string;
27
+ };
28
+ export type UnattendedBlock = {
29
+ code: 'runs_as_root';
30
+ reason: string;
31
+ fix: string;
32
+ detail: string;
33
+ };
22
34
  export type Invocation = {
23
35
  bin: string;
24
36
  args: string[];
@@ -48,6 +60,7 @@ export interface AgentAdapter {
48
60
  summarize(stdout: string): string;
49
61
  authFailureHint(text: string): string | null;
50
62
  rateLimitHint(text: string): string | null;
63
+ unattendedBlock?(ctx: UnattendedContext): UnattendedBlock | null;
51
64
  ending?(stdout: string): EngineEnding | undefined;
52
65
  meter?(stdout: string): RunUsage | null;
53
66
  planLimit?(stdout: string, now: Date): PlanLimit | null;
@@ -74,7 +74,7 @@ const SPEC_FIELDS = "The spec is the composer's own agent body, as JSON (firefun
74
74
  ' tool_grants { <tool or MCP server slug>: { read, write } } — only tools the\n' +
75
75
  " project has bound. Left out: the template's, or GitHub read+write\n" +
76
76
  ' deliverables [{ id, action: "tool.action", params, gate, position }]\n' +
77
- ' guardrails left out: Preview (dry_run_mode true, auto_merge false)\n' +
77
+ ' guardrails left out: Autonomous (dry_run_mode false, auto_merge false)\n' +
78
78
  ' caps { runs_per_day, max_in_flight } — left out: { runs_per_day: 5 }\n' +
79
79
  ' description, schedule, skills (installed slugs), engine, engine_firmness\n' +
80
80
  "The API checks it the way the composer's Save does and refuses what it would refuse,\n" +
@@ -139,7 +139,13 @@ function activationLines(body, opts) {
139
139
  else if (r.ready === true)
140
140
  lines.push('', 'Nothing is missing for it to be activated.');
141
141
  }
142
- if (typeof r.machinesOnline === 'number') {
142
+ if (typeof r.machinesServing === 'number') {
143
+ const all = typeof r.machinesOnline === 'number' && r.machinesOnline !== r.machinesServing
144
+ ? ` (${r.machinesOnline} online in the workspace)`
145
+ : '';
146
+ lines.push(`Machines online that serve its project now: ${r.machinesServing}${all}`);
147
+ }
148
+ else if (typeof r.machinesOnline === 'number') {
143
149
  lines.push(`Machines online for this workspace now: ${r.machinesOnline}`);
144
150
  }
145
151
  if (notes.length)
@@ -27,7 +27,13 @@ function printTask(ctx, t) {
27
27
  ` agent: ${agent ? `${text(agent.name)}${agent.handle ? ` (@${String(agent.handle)})` : ''}` : text(t.workflowId)}`,
28
28
  ` project: ${project ? text(project.name) : text(t.projectId)}`,
29
29
  ];
30
- if (t.error)
30
+ const hold = heldBy(t.hold);
31
+ if (hold) {
32
+ lines.push(...wrap(hold.said, 78, ' held: ', ' '));
33
+ if (hold.fix)
34
+ lines.push(...wrap(hold.fix, 78, ' fix: ', ' '));
35
+ }
36
+ else if (t.error)
31
37
  lines.push(` error: ${text(t.error)}`);
32
38
  const prs = Array.isArray(t.pullRequests) ? t.pullRequests : [];
33
39
  for (const pr of prs)
@@ -64,6 +70,19 @@ function printTask(ctx, t) {
64
70
  }
65
71
  ctx.io.stdout.write(`${lines.join('\n')}\n`);
66
72
  }
73
+ function heldBy(v) {
74
+ if (!v || typeof v !== 'object')
75
+ return null;
76
+ const h = v;
77
+ const said = typeof h.detail === 'string' && h.detail.trim()
78
+ ? h.detail
79
+ : typeof h.reason === 'string' && h.reason
80
+ ? h.reason
81
+ : null;
82
+ if (!said)
83
+ return null;
84
+ return { said, fix: typeof h.fix === 'string' && h.fix.trim() ? h.fix : null };
85
+ }
67
86
  function verdictWord(v) {
68
87
  const word = v?.word;
69
88
  if (typeof word !== 'string' || !word)
package/dist/job.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { RunnerApi, ClaimedJob } from './api.js';
2
2
  import { type RunnerConfig } from './config.js';
3
3
  import type { SessionViewer } from './viewer.js';
4
+ import type { UnattendedContext } from './engines/types.js';
4
5
  import { type LimitGate } from './limit.js';
5
6
  export declare function resolveRepoPath(repo: string | null | undefined, cfg: RunnerConfig): string | null;
6
7
  export declare function cloneDestination(repo: string, cfg: RunnerConfig): string | null;
@@ -10,4 +11,5 @@ export declare function runJob(job: ClaimedJob, cfg: RunnerConfig, api: RunnerAp
10
11
  devServerPort?: number;
11
12
  limits?: LimitGate;
12
13
  now?: () => Date;
14
+ unattended?: Partial<UnattendedContext>;
13
15
  }): Promise<void>;