@firefunc-agent/runner 0.9.0 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +90 -28
  2. package/dist/activity.d.ts +4 -1
  3. package/dist/activity.js +94 -8
  4. package/dist/api.d.ts +24 -0
  5. package/dist/api.js +74 -5
  6. package/dist/brief.d.ts +5 -0
  7. package/dist/brief.js +21 -0
  8. package/dist/build-info.json +2 -2
  9. package/dist/cli.js +10 -2
  10. package/dist/config.d.ts +2 -0
  11. package/dist/cut.d.ts +45 -0
  12. package/dist/cut.js +105 -0
  13. package/dist/daemon.d.ts +16 -0
  14. package/dist/daemon.js +156 -35
  15. package/dist/declined.d.ts +11 -0
  16. package/dist/declined.js +27 -0
  17. package/dist/engines/claude.js +129 -1
  18. package/dist/engines/types.d.ts +10 -0
  19. package/dist/exec.d.ts +3 -0
  20. package/dist/exec.js +48 -5
  21. package/dist/firefunc/agents.js +59 -7
  22. package/dist/firefunc/client.d.ts +1 -0
  23. package/dist/firefunc/client.js +3 -0
  24. package/dist/firefunc/configure.d.ts +6 -0
  25. package/dist/firefunc/configure.js +409 -0
  26. package/dist/firefunc/main.js +45 -7
  27. package/dist/firefunc/output.d.ts +1 -0
  28. package/dist/firefunc/output.js +24 -1
  29. package/dist/firefunc/tasks.js +32 -4
  30. package/dist/firefunc/version.js +2 -17
  31. package/dist/held.d.ts +18 -0
  32. package/dist/held.js +95 -0
  33. package/dist/job.d.ts +3 -0
  34. package/dist/job.js +437 -76
  35. package/dist/keep-local.d.ts +6 -1
  36. package/dist/keep-local.js +171 -4
  37. package/dist/limit.d.ts +30 -0
  38. package/dist/limit.js +258 -0
  39. package/dist/locks.d.ts +14 -0
  40. package/dist/locks.js +164 -0
  41. package/dist/mcp-proxy.d.ts +21 -0
  42. package/dist/mcp-proxy.js +180 -0
  43. package/dist/mcp.d.ts +2 -0
  44. package/dist/mcp.js +31 -2
  45. package/dist/orphans.d.ts +40 -0
  46. package/dist/orphans.js +235 -0
  47. package/dist/pool.d.ts +7 -0
  48. package/dist/pool.js +57 -9
  49. package/dist/pr-title.d.ts +11 -0
  50. package/dist/pr-title.js +63 -0
  51. package/dist/recover.d.ts +10 -0
  52. package/dist/recover.js +104 -0
  53. package/dist/session-stream.d.ts +8 -1
  54. package/dist/session-stream.js +9 -1
  55. package/dist/skills.d.ts +11 -0
  56. package/dist/skills.js +164 -0
  57. package/dist/stopped.d.ts +3 -0
  58. package/dist/stopped.js +10 -0
  59. package/dist/usage.d.ts +49 -0
  60. package/dist/usage.js +389 -0
  61. package/dist/version.d.ts +1 -0
  62. package/dist/version.js +17 -0
  63. package/dist/worktrees.d.ts +15 -0
  64. package/dist/worktrees.js +96 -0
  65. package/package.json +1 -1
  66. package/skill/firefunc/SKILL.md +63 -8
@@ -0,0 +1,96 @@
1
+ import { rmSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { basename, dirname } from 'node:path';
4
+ import { exec } from './exec.js';
5
+ import { killOrphans, reviewCopiesOf } from './orphans.js';
6
+ const RUNNER_WORKTREE_NAME = /^firefunc-[A-Za-z0-9]{6}$/;
7
+ function tempRoots() {
8
+ const t = tmpdir().replace(/\/+$/, '');
9
+ const out = new Set([t]);
10
+ if (t.startsWith('/private/'))
11
+ out.add(t.slice('/private'.length));
12
+ else if (t.startsWith('/var/'))
13
+ out.add(`/private${t}`);
14
+ out.add('/tmp');
15
+ out.add('/private/tmp');
16
+ return out;
17
+ }
18
+ export function canonicalPath(path) {
19
+ const clean = path.replace(/\/+$/, '');
20
+ return /^\/private\/(?:var|tmp)(?:\/|$)/.test(clean) ? clean.slice('/private'.length) : clean;
21
+ }
22
+ export function isRunnerWorktree(path) {
23
+ const clean = path.replace(/\/+$/, '');
24
+ return RUNNER_WORKTREE_NAME.test(basename(clean)) && tempRoots().has(dirname(clean));
25
+ }
26
+ export async function worktreesOf(checkout) {
27
+ const r = await exec('git', ['-C', checkout, 'worktree', 'list', '--porcelain'], {
28
+ timeoutMs: 30_000,
29
+ }).catch(() => null);
30
+ if (!r || r.code !== 0)
31
+ return [];
32
+ const out = [];
33
+ let cur = null;
34
+ for (const line of r.stdout.split('\n')) {
35
+ if (line.startsWith('worktree ')) {
36
+ cur = { path: line.slice('worktree '.length) };
37
+ out.push(cur);
38
+ }
39
+ else if (cur && line.startsWith('branch ')) {
40
+ cur.branch = line.slice('branch '.length).replace(/^refs\/heads\//, '');
41
+ }
42
+ else if (cur && line.startsWith('HEAD ')) {
43
+ cur.head = line.slice('HEAD '.length);
44
+ }
45
+ }
46
+ return out;
47
+ }
48
+ export function staleHolder(stderr) {
49
+ const m = /(?:already checked out at|used by worktree at|already used by worktree at)\s+'([^']+)'/.exec(stderr);
50
+ const path = m?.[1];
51
+ return path && isRunnerWorktree(path) ? path : null;
52
+ }
53
+ export async function removeRunnerWorktree(checkout, path, log) {
54
+ const copies = reviewCopiesOf(path);
55
+ await killOrphans({ roots: [path, ...copies], reviewCopiesOf: basename(path) }, { log }).catch(() => { });
56
+ const removed = await exec('git', ['-C', checkout, 'worktree', 'remove', '--force', path], {
57
+ timeoutMs: 120_000,
58
+ }).catch(() => null);
59
+ if (!removed || removed.code !== 0) {
60
+ try {
61
+ rmSync(path, { recursive: true, force: true });
62
+ }
63
+ catch {
64
+ }
65
+ await exec('git', ['-C', checkout, 'worktree', 'prune'], { timeoutMs: 60_000 }).catch(() => { });
66
+ }
67
+ for (const c of copies) {
68
+ try {
69
+ rmSync(c, { recursive: true, force: true });
70
+ }
71
+ catch {
72
+ }
73
+ }
74
+ }
75
+ export async function sweepLeftoverWorktrees(checkouts, opts) {
76
+ let removed = 0;
77
+ const spare = new Set([...opts.live, ...opts.keep].map(canonicalPath));
78
+ for (const checkout of new Set(checkouts)) {
79
+ try {
80
+ await exec('git', ['-C', checkout, 'worktree', 'prune'], { timeoutMs: 60_000 }).catch(() => { });
81
+ for (const wt of await worktreesOf(checkout)) {
82
+ if (!isRunnerWorktree(wt.path))
83
+ continue;
84
+ if (spare.has(canonicalPath(wt.path)))
85
+ continue;
86
+ opts.log(`removing a worktree a stopped runner left in ${checkout}: ${wt.path}${wt.branch ? ` (${wt.branch})` : ''}`);
87
+ await removeRunnerWorktree(checkout, wt.path, opts.log);
88
+ removed += 1;
89
+ }
90
+ }
91
+ catch {
92
+ }
93
+ }
94
+ return removed;
95
+ }
96
+ //# sourceMappingURL=worktrees.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firefunc-agent/runner",
3
- "version": "0.9.0",
3
+ "version": "0.9.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "FireFunc self-hosted runner — an always-on daemon that runs YOUR local coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI) on work FireFunc routes to it, opens pull requests, and reports back. Your machine, your subscriptions.",
@@ -15,18 +15,22 @@ with a composer link; the person opens it, reviews the agent and activates it.
15
15
 
16
16
  ## Before anything
17
17
 
18
- 1. Check the CLI: `firefunc --version`. It must print 0.9.0 or later.
18
+ 1. Check the CLI: `firefunc --version`. It must print 0.9.1 or later.
19
19
  - Command not found, or an older version: the person installs it with
20
20
  `npm install -g @firefunc-agent/runner@latest`. The `firefunc` command
21
- arrived in 0.9.0 of that package; if npm still installs an older one, the
22
- CLI is not on npm yet. Tell the person that, rather than retrying.
21
+ arrived in 0.9.0 of that package and the workspace commands below
22
+ (`skills install|create|update`, `projects instructions|sources|repos`)
23
+ in 0.9.1; if npm still installs an older one, those are not on npm yet.
24
+ Tell the person that, rather than retrying.
23
25
  2. Check the sign-in: `firefunc whoami --json`.
24
26
  - `not_signed_in`: ask the person to make a key in FireFunc → Settings → API keys
25
27
  and to run `firefunc login` **in their own terminal** (it asks for the key
26
28
  without showing it).
27
29
  3. Read the `scopes` in that answer. `agents:read` lets you look,
28
30
  `agents:write` lets you create and edit drafts, `tasks:write` starts tasks,
29
- `tasks:read` reads them, and `agents:activate` lets the key activate an agent.
31
+ `tasks:read` reads them, `agents:activate` lets the key activate an agent,
32
+ and `workspace:configure` lets it install and write skills and set a
33
+ project's standing instructions, repositories and the work it claims.
30
34
 
31
35
  **Never ask for a key in the chat, and never put one in a command, a file, a
32
36
  commit or your reply.** If the person pastes one anyway, tell them to revoke it
@@ -100,16 +104,17 @@ firefunc agents create --project <project> --name "Sentry triage" --spec - --jso
100
104
  EOF
101
105
  ```
102
106
 
103
- - Without a template, `name`, `workType` (bug, feature, task, chore, story or
104
- refactor) and `trigger` are required. `firefunc agents create --help` lists
107
+ - Without a template, `name` and `trigger` are required. `workType` is
108
+ optional: it defaults to `task`, and `story` makes the agent take a whole
109
+ story instead of having it split. `firefunc agents create --help` lists
105
110
  every field. Take `trigger.source` and
106
111
  `trigger.event` from a tool's `source` and `events` in `connections list`,
107
112
  and deliverable actions from its `actions`. Do not guess them.
108
113
  - Grant only tools that `connections list --project` shows as `bound`. The API
109
114
  refuses anything else and says why.
110
115
  - `skills` may name only installed skills. A directory skill that is not
111
- installed is installed by a template that names it, or by a person on
112
- Settings → Skills.
116
+ installed is installed by a template that names it, by a person on
117
+ Settings → Skills, or by you with `skills install` (see below).
113
118
  - `worksIn: { "repo": null }` makes an agent that works through its tools and
114
119
  opens no pull request (triage, answering, design).
115
120
  - Leave `status` out. The CLI refuses a spec that sets it.
@@ -133,6 +138,50 @@ another project. A draft needs `agents:write`. An active or paused agent also
133
138
  needs `agents:activate`, because the edit reaches its runs. Without that scope
134
139
  the API refuses with `agent_live`: give the person the composer link.
135
140
 
141
+ ## Set up what an agent needs
142
+
143
+ An agent can only carry installed skills and work in repositories its project
144
+ lists, and a project only takes the Jira, Linear or Sentry work it claims.
145
+ When the workspace is missing one of those, these commands set it up. Every
146
+ write needs `workspace:configure`; without it the API refuses with
147
+ `missing_scope`, and you tell the person where to do it themselves
148
+ (Settings → Skills, or the project's Repos & accounts). Change only what the
149
+ person asked for: a skill goes into every run of every agent that carries it,
150
+ and a project's instructions into every run in that project.
151
+
152
+ ```bash
153
+ firefunc skills directory --json # the curated skills and which are installed
154
+ firefunc skills install <slug> --json # install one; already installed changes nothing
155
+ firefunc skills create --file SKILL.md --json # write one (frontmatter name/description; --slug sets the slug)
156
+ firefunc skills update <slug> --file SKILL.md --json
157
+
158
+ firefunc projects instructions get <project> --json
159
+ firefunc projects instructions set <project> --file - --json <<'EOF'
160
+ { "agent": "Keep changes small; never touch migrations.", "commit": "Conventional Commits." }
161
+ EOF
162
+ firefunc projects sources get <project> --json
163
+ firefunc projects sources set <project> --file - --json <<'EOF'
164
+ { "jira": ["ENG"], "linear": ["ENG"] }
165
+ EOF
166
+ firefunc projects repos get <project> --json
167
+ firefunc projects repos set <project> --file - --json <<'EOF'
168
+ { "repos": ["acme/api", "acme/web"], "primaryRepo": "acme/api", "expectedUpdatedAt": "<updatedAt from repos get>" }
169
+ EOF
170
+ ```
171
+
172
+ - `instructions set` replaces all five fields (`agent`, `gather`, `pr_title`,
173
+ `pr_body`, `commit`): a field you leave out is cleared. Read them first and
174
+ send them back with your change.
175
+ - `sources set` merges kind by kind: a kind you leave out is kept, an empty
176
+ list clears it. A key another project claims is refused (`source_claimed`)
177
+ with the project to take it from; tell the person rather than moving it.
178
+ Slack and Figma claims belong to the project's bound account.
179
+ - `repos set` replaces the list and the primary. A repository the project does
180
+ not list yet must be in `available.repos` from `repos get` (the project's
181
+ GitHub account can see it); otherwise it is refused (`repo_not_visible`).
182
+ Send the `updatedAt` from `repos get` as `expectedUpdatedAt` so you never
183
+ overwrite a change made since (`project_changed`).
184
+
136
185
  ## Activating is the person's decision
137
186
 
138
187
  Run `firefunc agents activate <agent> --json` only when **both** are true:
@@ -171,3 +220,9 @@ for a longer watch, set the Bash call's timeout to 600000 and pass
171
220
  `--timeout 9`. A timeout exits 1 with `watch_timeout`, and the task carries on
172
221
  regardless: check it again later with `tasks get`. Report the state the API gave, with the pull request URL when
173
222
  there is one. Do not describe work the task has not reached.
223
+
224
+ A task carries what the agent said and concluded: `answer` (its closing words —
225
+ for an agent that reads and reports, that is the work), `verdict` (`{id, word}`,
226
+ only for an agent that declares verdicts) and `findings` (one line each, with a
227
+ severity). Each is null or empty when nothing was recorded; say so rather than
228
+ guessing. Quote the answer as it came.