passalong 1.0.0 → 1.2.0
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 +3 -1
- package/bin/passalong +58 -20
- package/package.json +1 -1
- package/src/api.js +8 -3
- package/src/hooks.js +5 -5
- package/src/mcp.js +80 -46
- package/src/passalong.js +407 -37
- package/src/runner.js +515 -0
- package/src/update.js +1 -1
- package/src/work.js +4 -4
package/src/runner.js
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
// The runner: `passalong work --watch` (docs/LOOP.md §1a). Left running with a repo checked out,
|
|
2
|
+
// it takes work a person ticked Safe to run alone and starts Claude Code on each piece, with nobody
|
|
3
|
+
// watching.
|
|
4
|
+
//
|
|
5
|
+
// Each piece gets its own git worktree, on a branch of its own, so up to three agents can work at
|
|
6
|
+
// once without touching each other's files, and each one's change arrives as a pull request a
|
|
7
|
+
// person reviews. At most ten runs start in a day. A run that ends without the work done (the agent
|
|
8
|
+
// gave up, said it was blocked, or ran out of time) gives the work back to whoever wrote it, with
|
|
9
|
+
// the agent's last note, and clears its Safe to run alone tick, so it is not tried again unwatched
|
|
10
|
+
// until a person has looked (2026-11-06).
|
|
11
|
+
//
|
|
12
|
+
// Everything that touches git, the clock or a process is passed in, so the tests can run it.
|
|
13
|
+
|
|
14
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
15
|
+
import {
|
|
16
|
+
appendFileSync,
|
|
17
|
+
mkdirSync,
|
|
18
|
+
readdirSync,
|
|
19
|
+
readFileSync,
|
|
20
|
+
statSync,
|
|
21
|
+
writeFileSync,
|
|
22
|
+
} from "node:fs";
|
|
23
|
+
import { hostname, platform } from "node:os";
|
|
24
|
+
import { basename, dirname, join, relative } from "node:path";
|
|
25
|
+
|
|
26
|
+
/** How many agents at once, how many runs a day, and how long one run may take. */
|
|
27
|
+
export const LIMITS = { atOnce: 3, perDay: 10, minutes: 60 };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What an unattended agent may do. `dontAsk` refuses anything not listed here, since there is
|
|
31
|
+
* nobody to ask: read and edit files in its worktree, use Passalong, run the usual build and test
|
|
32
|
+
* tools, commit, push its own branch and open a pull request. Never push anywhere else, force a
|
|
33
|
+
* push, or throw work away.
|
|
34
|
+
*/
|
|
35
|
+
export const PERMISSIONS = {
|
|
36
|
+
allow: [
|
|
37
|
+
"Read",
|
|
38
|
+
"Edit",
|
|
39
|
+
"Write",
|
|
40
|
+
"Glob",
|
|
41
|
+
"Grep",
|
|
42
|
+
"mcp__passalong",
|
|
43
|
+
"Bash(git status*)",
|
|
44
|
+
"Bash(git diff*)",
|
|
45
|
+
"Bash(git log*)",
|
|
46
|
+
"Bash(git show*)",
|
|
47
|
+
"Bash(git add *)",
|
|
48
|
+
"Bash(git commit *)",
|
|
49
|
+
"Bash(git push -u origin passalong/*)",
|
|
50
|
+
"Bash(gh pr create *)",
|
|
51
|
+
"Bash(gh pr view *)",
|
|
52
|
+
"Bash(npm *)",
|
|
53
|
+
"Bash(pnpm *)",
|
|
54
|
+
"Bash(yarn *)",
|
|
55
|
+
"Bash(npx *)",
|
|
56
|
+
"Bash(node *)",
|
|
57
|
+
"Bash(make *)",
|
|
58
|
+
"Bash(python *)",
|
|
59
|
+
"Bash(python3 *)",
|
|
60
|
+
"Bash(pytest *)",
|
|
61
|
+
"Bash(go *)",
|
|
62
|
+
"Bash(cargo *)",
|
|
63
|
+
],
|
|
64
|
+
deny: [
|
|
65
|
+
"Bash(git push --force*)",
|
|
66
|
+
"Bash(git push -f*)",
|
|
67
|
+
"Bash(git push * --force*)",
|
|
68
|
+
"Bash(git reset --hard*)",
|
|
69
|
+
"Bash(rm -rf *)",
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** Where a checkout's origin is hosted, for how a run ends: a pull request or a merge request. */
|
|
74
|
+
export const forgeOf = (remote) => (/gitlab/i.test(String(remote || "")) ? "gitlab" : "github");
|
|
75
|
+
|
|
76
|
+
/** The branch a piece of work's change goes on. */
|
|
77
|
+
export const branchOf = (id) => `passalong/${id}`;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Claude Code, started for one piece of work: headless, refusing anything not allowed above, and
|
|
81
|
+
* with Passalong's MCP server named here, because `passalong setup` registers it for one folder and
|
|
82
|
+
* a fresh worktree is another. The server runs in the worktree, so it is that worktree's agent: the
|
|
83
|
+
* one that took the work. The prompt goes in on stdin.
|
|
84
|
+
*/
|
|
85
|
+
export function claudeCommand({ node = process.execPath, cli } = {}) {
|
|
86
|
+
return {
|
|
87
|
+
command: "claude",
|
|
88
|
+
args: [
|
|
89
|
+
"-p",
|
|
90
|
+
// One JSON event per line as it works, which the runner turns into the steps a person can
|
|
91
|
+
// watch from the hub (describe below). Plain -p prints only the final answer, at the end.
|
|
92
|
+
"--output-format",
|
|
93
|
+
"stream-json",
|
|
94
|
+
"--verbose",
|
|
95
|
+
"--permission-mode",
|
|
96
|
+
"dontAsk",
|
|
97
|
+
"--settings",
|
|
98
|
+
JSON.stringify({ permissions: PERMISSIONS }),
|
|
99
|
+
"--mcp-config",
|
|
100
|
+
JSON.stringify({ mcpServers: { passalong: { command: node, args: [cli, "mcp"] } } }),
|
|
101
|
+
],
|
|
102
|
+
stdin: true,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** What the agent is told: the work itself, and how to finish it as a pull request. */
|
|
107
|
+
export function runnerPrompt(t, branch = branchOf(t.id), { forge = "github" } = {}) {
|
|
108
|
+
// GitLab has no `gh`: a push option opens the merge request, and git prints its link.
|
|
109
|
+
const ship =
|
|
110
|
+
forge === "gitlab"
|
|
111
|
+
? [
|
|
112
|
+
`When it is done, commit what you changed with a message starting "${t.id}: ", then run`,
|
|
113
|
+
`exactly \`git push -u origin ${branch} -o merge_request.create\`, which opens a merge`,
|
|
114
|
+
"request and prints its link. Then call hand_in with id " + t.id + ", `pr` set to that",
|
|
115
|
+
"link (or the commit hash if the push failed, and say why in the note), `note`: one plain",
|
|
116
|
+
]
|
|
117
|
+
: [
|
|
118
|
+
`When it is done, commit what you changed with a message starting "${t.id}: ", then run`,
|
|
119
|
+
`exactly \`git push -u origin ${branch}\` and open a pull request with`,
|
|
120
|
+
`\`gh pr create --fill --head ${branch}\`. Then call hand_in with id ${t.id}, \`pr\` set to the`,
|
|
121
|
+
"pull request's URL (or the commit hash if the push or the pull request failed, and say why in",
|
|
122
|
+
"the note), `note`: one plain",
|
|
123
|
+
];
|
|
124
|
+
return [
|
|
125
|
+
`You hold passalong work ${t.id}, and no other agent can take it while you do. Here it is:`,
|
|
126
|
+
"",
|
|
127
|
+
String(t.markdown || "").trim(),
|
|
128
|
+
"",
|
|
129
|
+
`Do it in this worktree, which is on its own branch, ${branch}. Read it, work out what done`,
|
|
130
|
+
`means, and get there. Call the passalong MCP tool progress with id ${t.id} and a one-line`,
|
|
131
|
+
"status at each milestone; 30 minutes of silence stalls it.",
|
|
132
|
+
"",
|
|
133
|
+
...ship,
|
|
134
|
+
"sentence saying what you did, and `evidence`: what you ran and",
|
|
135
|
+
"what came back, with the commands and the lines that decided it, the test summary, the commit.",
|
|
136
|
+
"Keep that as you go. What you learned about the project goes into its documents",
|
|
137
|
+
"(save_document). If a call says you no longer hold it, stop.",
|
|
138
|
+
"",
|
|
139
|
+
"Nobody reads what you print: this session runs unattended, and anything not allowed is",
|
|
140
|
+
"refused rather than asked.",
|
|
141
|
+
"",
|
|
142
|
+
"When a decision is the person's to make (which of two layouts, which of three fixes), ask",
|
|
143
|
+
`them: call ask with id ${t.id}, one clear question, and \`choices\`: two to four options,`,
|
|
144
|
+
"each with a label and a line of detail. When an option is something to look at, take a",
|
|
145
|
+
"screenshot of it if you can, upload it with add_file, and give its link as that option's",
|
|
146
|
+
"`picture`. Then stop. They pick one with a tap in the hub, and you are started again here to",
|
|
147
|
+
"read their pick (take) and carry on.",
|
|
148
|
+
"",
|
|
149
|
+
"If something only a person can do stands between you and done (a permission, a secret), call",
|
|
150
|
+
`progress with id ${t.id} and a note starting "BLOCKED: " that says exactly what you need,`,
|
|
151
|
+
"and stop. The work goes back to the person who wrote it, with that note.",
|
|
152
|
+
"",
|
|
153
|
+
"Never call pass yourself. If you stop without hand_in, the runner gives the work back",
|
|
154
|
+
"unfinished and shows your last message as the reason, so end with what is done and what",
|
|
155
|
+
"isn't, in plain sentences.",
|
|
156
|
+
].join("\n");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* What an agent is told when its run starts again after a person answered its question: read the
|
|
161
|
+
* answer, then finish exactly as the first run was told to.
|
|
162
|
+
*/
|
|
163
|
+
export function resumePrompt(t, branch = branchOf(t.id), opts = {}) {
|
|
164
|
+
return [
|
|
165
|
+
`You hold passalong work ${t.id} (${t.title || t.id}), and you stopped earlier to ask the person`,
|
|
166
|
+
`a question. They have answered. Call the passalong MCP tool take with id ${t.id} first: their`,
|
|
167
|
+
"answer comes back with it. Then carry on in this worktree, where your earlier changes are, and",
|
|
168
|
+
"finish as before:",
|
|
169
|
+
"",
|
|
170
|
+
runnerPrompt({ ...t, markdown: "" }, branch, opts)
|
|
171
|
+
.split("\n")
|
|
172
|
+
.slice(4)
|
|
173
|
+
.join("\n"),
|
|
174
|
+
].join("\n");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Today, as the runner counts days: the machine's own date. */
|
|
178
|
+
export const dayOf = (now) => {
|
|
179
|
+
const d = new Date(now);
|
|
180
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/** How many runs have started today, kept in `file` beside the rest of the CLI's state. */
|
|
184
|
+
export function runsToday(file, day) {
|
|
185
|
+
try {
|
|
186
|
+
const s = JSON.parse(readFileSync(file, "utf8"));
|
|
187
|
+
return s.day === day ? Number(s.runs) || 0 : 0;
|
|
188
|
+
} catch {
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function countRun(file, day) {
|
|
194
|
+
const runs = runsToday(file, day) + 1;
|
|
195
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
196
|
+
writeFileSync(file, `${JSON.stringify({ day, runs })}\n`);
|
|
197
|
+
return runs;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Where the runs' worktrees and logs live: beside the checkout, never inside it. */
|
|
201
|
+
export const runsDirOf = (root) => join(dirname(root), `${basename(root)}.passalong-runs`);
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Why a run gave its work back, said to whoever wrote it and to the team's channel. It leads with
|
|
205
|
+
* what the agent itself said at the end, which is nearly always the reason ("Not done: I couldn't
|
|
206
|
+
* start the app to take the screenshots"). It said "stopped without finishing (exit 0)", which
|
|
207
|
+
* means nothing to a person, and "the last thing it printed", cut mid-word (2026-11-06).
|
|
208
|
+
*/
|
|
209
|
+
export function passBack({ minutes, timedOut, exit, note, said, branch, failed, machine }) {
|
|
210
|
+
const how = failed
|
|
211
|
+
? `couldn't start it (${failed})`
|
|
212
|
+
: timedOut
|
|
213
|
+
? `ran out of its ${minutes} minutes`
|
|
214
|
+
: exit === 0
|
|
215
|
+
? "ended its run without handing it in"
|
|
216
|
+
: `stopped with an error${exit === undefined || exit === null || exit === "" ? "" : ` (${typeof exit === "number" ? `exit code ${exit}` : exit})`}`;
|
|
217
|
+
const words = sentences(note || said, 600);
|
|
218
|
+
return [
|
|
219
|
+
`The runner's agent ${how}.`,
|
|
220
|
+
words ? `It said: "${words}"` : "It didn't say why.",
|
|
221
|
+
"It's back in To do and no longer marked safe to run alone, so no runner takes it again until someone ticks it.",
|
|
222
|
+
failed ? "" : `What it changed is kept on branch ${branch}${machine ? ` on ${machine}` : ""}.`,
|
|
223
|
+
]
|
|
224
|
+
.filter(Boolean)
|
|
225
|
+
.join(" ");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** At most `max` characters, ended at a sentence or a word rather than mid-word. */
|
|
229
|
+
export function sentences(text, max) {
|
|
230
|
+
const one = String(text ?? "")
|
|
231
|
+
.replace(/\s+/g, " ")
|
|
232
|
+
.trim();
|
|
233
|
+
if (one.length <= max) return one;
|
|
234
|
+
const cut = one.slice(0, max);
|
|
235
|
+
const stop = Math.max(cut.lastIndexOf(". "), cut.lastIndexOf("? "), cut.lastIndexOf("! "));
|
|
236
|
+
if (stop > max * 0.5) return cut.slice(0, stop + 1);
|
|
237
|
+
const space = cut.lastIndexOf(" ");
|
|
238
|
+
return `${(space > max * 0.6 ? cut.slice(0, space) : cut).trimEnd()}…`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The last line an agent printed, from its log: often the reason it stopped. "" when none. */
|
|
242
|
+
export function lastLine(log) {
|
|
243
|
+
try {
|
|
244
|
+
const lines = readFileSync(log, "utf8").trim().split("\n");
|
|
245
|
+
return (lines.at(-1) || "").trim().slice(0, 300);
|
|
246
|
+
} catch {
|
|
247
|
+
return "";
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Run a git command, quietly; its output, trimmed. Throws when git fails. */
|
|
252
|
+
export function git(args) {
|
|
253
|
+
return execFileSync("git", args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Start an agent and wait for it. What it prints is read a line at a time: each becomes a line of
|
|
258
|
+
* `log` a person can read (Claude Code's JSON events made into sentences, anything else as it came),
|
|
259
|
+
* and each thing it does is handed to `onStep`. Killed after `minutes`. Resolves
|
|
260
|
+
* `{ exit, timedOut }`, never rejects: an agent that would not start is a run that ended without
|
|
261
|
+
* the work done.
|
|
262
|
+
*/
|
|
263
|
+
export function runAgent({
|
|
264
|
+
command,
|
|
265
|
+
args,
|
|
266
|
+
stdin,
|
|
267
|
+
prompt,
|
|
268
|
+
cwd,
|
|
269
|
+
log,
|
|
270
|
+
minutes,
|
|
271
|
+
env,
|
|
272
|
+
onStep = () => {},
|
|
273
|
+
}) {
|
|
274
|
+
return new Promise((resolve) => {
|
|
275
|
+
let timedOut = false;
|
|
276
|
+
let child;
|
|
277
|
+
/** What the agent said at the end (Claude Code's result), for why it gave the work back. */
|
|
278
|
+
let said = "";
|
|
279
|
+
const done = (r) => resolve({ ...r, said });
|
|
280
|
+
const write = (text) => {
|
|
281
|
+
try {
|
|
282
|
+
appendFileSync(log, `${clock()} ${text}\n`);
|
|
283
|
+
} catch {}
|
|
284
|
+
};
|
|
285
|
+
try {
|
|
286
|
+
child = spawn(command, stdin ? args : [...args, prompt], {
|
|
287
|
+
cwd,
|
|
288
|
+
env,
|
|
289
|
+
stdio: [stdin ? "pipe" : "ignore", "pipe", "pipe"],
|
|
290
|
+
});
|
|
291
|
+
} catch (err) {
|
|
292
|
+
write(`couldn't start: ${err.message}`);
|
|
293
|
+
return done({ exit: err.message, timedOut });
|
|
294
|
+
}
|
|
295
|
+
const reader = () => {
|
|
296
|
+
let rest = "";
|
|
297
|
+
return (chunk) => {
|
|
298
|
+
rest += chunk;
|
|
299
|
+
const lines = rest.split("\n");
|
|
300
|
+
rest = lines.pop() ?? "";
|
|
301
|
+
for (const line of lines) {
|
|
302
|
+
if (!line.trim()) continue;
|
|
303
|
+
const d = describe(line, cwd);
|
|
304
|
+
if (d.said) said = d.said;
|
|
305
|
+
if (d.log) write(d.log);
|
|
306
|
+
for (const step of d.step ? d.step.split("\n") : []) onStep(step);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
child.stdout?.setEncoding("utf8");
|
|
311
|
+
child.stderr?.setEncoding("utf8");
|
|
312
|
+
child.stdout?.on("data", reader());
|
|
313
|
+
child.stderr?.on("data", reader());
|
|
314
|
+
const timer = setTimeout(
|
|
315
|
+
() => {
|
|
316
|
+
timedOut = true;
|
|
317
|
+
child.kill("SIGTERM");
|
|
318
|
+
},
|
|
319
|
+
minutes * 60 * 1000,
|
|
320
|
+
);
|
|
321
|
+
child.on("error", (err) => {
|
|
322
|
+
clearTimeout(timer);
|
|
323
|
+
write(`couldn't start: ${err.message}`);
|
|
324
|
+
done({ exit: err.message, timedOut });
|
|
325
|
+
});
|
|
326
|
+
child.on("close", (code) => {
|
|
327
|
+
clearTimeout(timer);
|
|
328
|
+
done({ exit: code, timedOut });
|
|
329
|
+
});
|
|
330
|
+
if (stdin) {
|
|
331
|
+
child.stdin.on("error", () => {});
|
|
332
|
+
child.stdin.end(prompt);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const clock = () => new Date().toTimeString().slice(0, 8);
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Take out what looks like a secret before a line leaves the machine: a long run of letters and
|
|
341
|
+
* digits (a token, a key) and the value after token=, secret=, password= or key=. Steps are read by
|
|
342
|
+
* the team in the hub, and an agent's commands can carry what its environment holds.
|
|
343
|
+
*/
|
|
344
|
+
export function hideSecrets(text) {
|
|
345
|
+
return String(text)
|
|
346
|
+
.replace(/\b((?:[a-z_]*_)?(?:token|secret|password|passwd|api_?key|key))=\S+/gi, "$1=[hidden]")
|
|
347
|
+
.replace(/\b(?=[A-Za-z0-9_-]*\d)(?=[A-Za-z0-9_-]*[A-Za-z])[A-Za-z0-9_-]{32,}\b/g, "[hidden]");
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const one = (s, max = 140) => {
|
|
351
|
+
const line =
|
|
352
|
+
String(s ?? "")
|
|
353
|
+
.split("\n")
|
|
354
|
+
.map((l) => l.trim())
|
|
355
|
+
.find(Boolean) ?? "";
|
|
356
|
+
return line.length > max ? `${line.slice(0, max - 1)}…` : line;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/** What one tool call does, in words: "Editing src/deals/form.tsx", "Running `npm test`". */
|
|
360
|
+
export function toolStep(name, input = {}, cwd = "") {
|
|
361
|
+
const path = (p) => {
|
|
362
|
+
if (!p) return "a file";
|
|
363
|
+
const r = cwd ? relative(cwd, String(p)) : String(p);
|
|
364
|
+
return r && !r.startsWith("..") ? r : String(p);
|
|
365
|
+
};
|
|
366
|
+
const said = {
|
|
367
|
+
Read: () => `Reading ${path(input.file_path)}`,
|
|
368
|
+
Edit: () => `Editing ${path(input.file_path)}`,
|
|
369
|
+
MultiEdit: () => `Editing ${path(input.file_path)}`,
|
|
370
|
+
Write: () => `Writing ${path(input.file_path)}`,
|
|
371
|
+
NotebookEdit: () => `Editing ${path(input.notebook_path)}`,
|
|
372
|
+
Bash: () => `Running \`${one(input.command, 120)}\``,
|
|
373
|
+
Grep: () => `Searching for "${one(input.pattern, 80)}"`,
|
|
374
|
+
Glob: () => `Looking for files: ${one(input.pattern, 80)}`,
|
|
375
|
+
WebFetch: () => `Reading ${one(input.url, 120)}`,
|
|
376
|
+
WebSearch: () => `Searching the web for "${one(input.query, 80)}"`,
|
|
377
|
+
TodoWrite: () => {
|
|
378
|
+
const now = (input.todos || []).find((t) => t.status === "in_progress");
|
|
379
|
+
return now ? `Next: ${one(now.activeForm || now.content)}` : "Planning the steps";
|
|
380
|
+
},
|
|
381
|
+
Task: () => `Starting a helper: ${one(input.description, 80)}`,
|
|
382
|
+
Agent: () => `Starting a helper: ${one(input.description, 80)}`,
|
|
383
|
+
mcp__passalong__progress: () => `Progress: ${one(input.note)}`,
|
|
384
|
+
mcp__passalong__hand_in: () => `Handing it in${input.pr ? `: ${one(input.pr)}` : ""}`,
|
|
385
|
+
mcp__passalong__ask: () => `Asking you: ${one(input.question)}`,
|
|
386
|
+
mcp__passalong__take: () => "Reading the work again",
|
|
387
|
+
mcp__passalong__save_document: () =>
|
|
388
|
+
`Writing down what it learned: ${one(input.title || input.path)}`,
|
|
389
|
+
}[name];
|
|
390
|
+
if (said) return said();
|
|
391
|
+
const short = String(name).replace(/^mcp__([^_]+)__/, "$1: ");
|
|
392
|
+
return `Using ${short}`;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* One line the agent printed, as a line of the log and, when it did something, a step.
|
|
397
|
+
*
|
|
398
|
+
* Claude Code's stream-json events become sentences: what it says (its first line), each tool it
|
|
399
|
+
* calls, a tool that failed, and the result at the end. Anything that is not one of those events
|
|
400
|
+
* (another agent, a crash) is kept as it came, and is a step too: it may be the only sign of why a
|
|
401
|
+
* run stopped.
|
|
402
|
+
*/
|
|
403
|
+
export function describe(line, cwd = "") {
|
|
404
|
+
let e;
|
|
405
|
+
try {
|
|
406
|
+
e = JSON.parse(line);
|
|
407
|
+
} catch {
|
|
408
|
+
const text = hideSecrets(one(line, 300));
|
|
409
|
+
return { log: text, step: text };
|
|
410
|
+
}
|
|
411
|
+
if (!e || typeof e !== "object") return { log: hideSecrets(one(line, 300)), step: "" };
|
|
412
|
+
if (e.type === "system" && e.subtype === "init")
|
|
413
|
+
return { log: `started${e.model ? ` (${e.model})` : ""}`, step: "" };
|
|
414
|
+
if (e.type === "assistant") {
|
|
415
|
+
const logs = [];
|
|
416
|
+
const steps = [];
|
|
417
|
+
for (const c of e.message?.content ?? []) {
|
|
418
|
+
if (c.type === "text" && c.text?.trim()) {
|
|
419
|
+
logs.push(hideSecrets(c.text.trim()));
|
|
420
|
+
steps.push(hideSecrets(one(c.text)));
|
|
421
|
+
} else if (c.type === "tool_use") {
|
|
422
|
+
const s = hideSecrets(toolStep(c.name, c.input, cwd));
|
|
423
|
+
logs.push(s);
|
|
424
|
+
steps.push(s);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return { log: logs.join("\n"), step: steps.join("\n") };
|
|
428
|
+
}
|
|
429
|
+
if (e.type === "user") {
|
|
430
|
+
const failed = (e.message?.content ?? []).find((c) => c.type === "tool_result" && c.is_error);
|
|
431
|
+
if (!failed) return { log: "", step: "" };
|
|
432
|
+
const why = Array.isArray(failed.content)
|
|
433
|
+
? failed.content.map((x) => x.text || "").join(" ")
|
|
434
|
+
: failed.content;
|
|
435
|
+
const text = hideSecrets(`That didn't work: ${one(why)}`);
|
|
436
|
+
return { log: text, step: text };
|
|
437
|
+
}
|
|
438
|
+
if (e.type === "result") {
|
|
439
|
+
const how = e.is_error ? "Stopped with an error" : "Finished";
|
|
440
|
+
const text = hideSecrets(`${how}${e.result ? `: ${one(e.result, 200)}` : ""}`);
|
|
441
|
+
// Its whole last message, too: when the work comes back unfinished, this is why.
|
|
442
|
+
return { log: text, step: text, said: hideSecrets(String(e.result || "").trim()) };
|
|
443
|
+
}
|
|
444
|
+
return { log: "", step: "" };
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* The git checkouts a runner started in `cwd` serves: `cwd`'s own when it is inside one, else every
|
|
449
|
+
* checkout in the folders under it, three levels down at most. Worktrees, dependencies, hidden
|
|
450
|
+
* folders and the runner's own run folders are skipped. Those without an `origin` remote are listed
|
|
451
|
+
* apart, since a run ends by pushing its branch there.
|
|
452
|
+
*/
|
|
453
|
+
export function checkoutsIn(cwd, { git: run = git, depth = 3 } = {}) {
|
|
454
|
+
const top = (dir) => {
|
|
455
|
+
try {
|
|
456
|
+
return run(["-C", dir, "rev-parse", "--show-toplevel"]);
|
|
457
|
+
} catch {
|
|
458
|
+
return "";
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
const roots = [];
|
|
462
|
+
const own = top(cwd);
|
|
463
|
+
if (own) roots.push(own);
|
|
464
|
+
else {
|
|
465
|
+
const walk = (dir, left) => {
|
|
466
|
+
let names = [];
|
|
467
|
+
try {
|
|
468
|
+
names = readdirSync(dir);
|
|
469
|
+
} catch {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (names.includes(".git")) {
|
|
473
|
+
// A .git file is a worktree of a checkout found elsewhere, not a repo of its own.
|
|
474
|
+
try {
|
|
475
|
+
if (statSync(join(dir, ".git")).isDirectory()) roots.push(top(dir) || dir);
|
|
476
|
+
} catch {}
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (!left) return;
|
|
480
|
+
for (const n of names.sort()) {
|
|
481
|
+
if (n.startsWith(".") || n === "node_modules" || n.endsWith(".passalong-runs")) continue;
|
|
482
|
+
const p = join(dir, n);
|
|
483
|
+
try {
|
|
484
|
+
if (statSync(p).isDirectory()) walk(p, left - 1);
|
|
485
|
+
} catch {}
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
walk(cwd, depth);
|
|
489
|
+
}
|
|
490
|
+
const found = [];
|
|
491
|
+
const skipped = [];
|
|
492
|
+
for (const root of roots) {
|
|
493
|
+
let remote = "";
|
|
494
|
+
try {
|
|
495
|
+
remote = run(["-C", root, "remote", "get-url", "origin"]);
|
|
496
|
+
} catch {}
|
|
497
|
+
if (remote) found.push({ root, remote });
|
|
498
|
+
else skipped.push(root);
|
|
499
|
+
}
|
|
500
|
+
return { found, skipped };
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** This computer as a person knows it: "Lukman's MacBook Pro" on a Mac, its host name elsewhere. */
|
|
504
|
+
export function machineName() {
|
|
505
|
+
if (platform() === "darwin") {
|
|
506
|
+
try {
|
|
507
|
+
const name = execFileSync("scutil", ["--get", "ComputerName"], {
|
|
508
|
+
encoding: "utf8",
|
|
509
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
510
|
+
}).trim();
|
|
511
|
+
if (name) return name;
|
|
512
|
+
} catch {}
|
|
513
|
+
}
|
|
514
|
+
return hostname();
|
|
515
|
+
}
|
package/src/update.js
CHANGED
|
@@ -81,7 +81,7 @@ export function isNewer(latest, current) {
|
|
|
81
81
|
/** The one line somebody sees, or "" when there is nothing to say. */
|
|
82
82
|
export function noticeFor(latest, current) {
|
|
83
83
|
if (!isNewer(latest, current)) return "";
|
|
84
|
-
return `passalong ${latest} is out (you have ${current})
|
|
84
|
+
return `passalong ${latest} is out (you have ${current}): npm i -g passalong`;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
package/src/work.js
CHANGED
|
@@ -287,19 +287,19 @@ export function validate({ meta, body }) {
|
|
|
287
287
|
const said = String(meta.summary ?? "").trim();
|
|
288
288
|
if (!said)
|
|
289
289
|
errors.push(
|
|
290
|
-
"say it to a person: add `summary:`
|
|
290
|
+
"say it to a person: add `summary:` with one or two plain sentences, no ids or paths, saying what " +
|
|
291
291
|
`this is and whether anybody needs to act (${SUMMARY_MAX} characters at most)`,
|
|
292
292
|
);
|
|
293
293
|
else if (said.length > SUMMARY_MAX)
|
|
294
294
|
errors.push(`summary is ${said.length} characters; ${SUMMARY_MAX} at most`);
|
|
295
295
|
for (const field of RETIRED)
|
|
296
296
|
if (meta[field] !== undefined)
|
|
297
|
-
errors.push(`\`${field}:\` is gone
|
|
297
|
+
errors.push(`\`${field}:\` is gone: work has no kinds; remove the line`);
|
|
298
298
|
// An agent that has a file id but never called add_file writes the id as if it were a link. It
|
|
299
299
|
// publishes, and stores work whose screenshot was never uploaded anywhere.
|
|
300
300
|
for (const target of unreachableImages(body))
|
|
301
301
|
errors.push(
|
|
302
|
-
`${target} is not a URL a reader can load
|
|
302
|
+
`${target} is not a URL a reader can load: attach the image first and use the URL it returns`,
|
|
303
303
|
);
|
|
304
304
|
return errors;
|
|
305
305
|
}
|
|
@@ -402,7 +402,7 @@ export function outlineText(markdown, { id = "", path = "" } = {}) {
|
|
|
402
402
|
(h) => `${" ".repeat(h.level - 1)}- ${h.heading} (${h.chars.toLocaleString("en")} chars)`,
|
|
403
403
|
);
|
|
404
404
|
return [
|
|
405
|
-
`${meta.title || id}
|
|
405
|
+
`${meta.title || id}: ${markdown.length.toLocaleString("en")} characters`,
|
|
406
406
|
meta.summary ? `Summary: ${meta.summary}` : "",
|
|
407
407
|
"",
|
|
408
408
|
"Sections:",
|