tracehub 0.5.6 → 0.5.8
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 +5 -4
- package/dist/client/upload.js +19 -3
- package/dist/git/global-hooks.js +33 -13
- package/dist/git/hooks.js +10 -2
- package/dist/protocol/trace.js +8 -1
- package/dist/trace/build.js +69 -4
- package/dist/transcript/parseClaude.js +9 -1
- package/dist/transcript/parseCodex.js +66 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ Everything is computed on the developer's machine, redacted there, checked again
|
|
|
78
78
|
Set it up once with `setup` (the other commands are under [Commands](#commands)). Run it in your terminal:
|
|
79
79
|
|
|
80
80
|
```sh
|
|
81
|
-
npx --yes tracehub@0.5.
|
|
81
|
+
npx --yes tracehub@0.5.8 setup
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
Setup is a form of three steps. Each step saves what you chose before the next one starts; cancelling (Ctrl-C) keeps the steps already done.
|
|
@@ -89,7 +89,7 @@ Setup is a form of three steps. Each step saves what you chose before the next o
|
|
|
89
89
|
|
|
90
90
|
It ends with a summary of the account, the allowed rules and the hooks, and what is left to do. Setup needs an interactive terminal; without one it exits 1.
|
|
91
91
|
|
|
92
|
-
To skip npx on every commit, install it globally instead: `npm install -g tracehub@0.5.
|
|
92
|
+
To skip npx on every commit, install it globally instead: `npm install -g tracehub@0.5.8`, then `tracehub setup`.
|
|
93
93
|
|
|
94
94
|
### Git hooks
|
|
95
95
|
|
|
@@ -110,7 +110,7 @@ Setup installs global Git hooks: it points the global `core.hooksPath` at `~/.co
|
|
|
110
110
|
### Uninstall
|
|
111
111
|
|
|
112
112
|
```sh
|
|
113
|
-
npx --yes tracehub@0.5.
|
|
113
|
+
npx --yes tracehub@0.5.8 uninstall
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
Lists what it removes and asks first (default no); with nothing set up it says so and asks nothing. Then it removes the global Git hooks and restores your previous global `core.hooksPath` setting, deletes the permission rules (`consent.json`) and signs you out (`auth.json`). It asks before deleting the deny list and the current repository's `.git/tracehub` (its markers, including ones not uploaded yet). Other repositories keep their `.git/tracehub`; delete it by hand if you want. Before signing out it asks TraceHub to forget this machine's rules (see [Consent registry](#consent-registry)); when TraceHub can't be reached it says that TraceHub still lists them, and goes on. If the global hooks setting was changed by another tool since setup, uninstall leaves the hooks alone, still removes the rest, and exits 1.
|
|
@@ -182,6 +182,7 @@ The trace of a session at a commit, built from the session's file up to the mark
|
|
|
182
182
|
- **Turns.** A turn starts at each user prompt; its messages are the user's (the prompt, then any steering) and the agent's text replies. The replies after the commit that finish the commit's turn are included; the next prompt is not.
|
|
183
183
|
- **Changes.** Each turn lists the files its edit tools changed, as paths in the repository with lines added and removed. Edits outside the repository are left out.
|
|
184
184
|
- **Runs.** A subagent (a Claude Code subagent, a Codex sub-thread, an OpenCode task) is a run under the turn whose call launched it, else under the last turn that started before it did. A run has its own turns: the prompt the parent gave it, its replies and its changes.
|
|
185
|
+
- **Delegated sessions.** A session or subagent whose output contains a line `<agent>-session: <id>` (where agent is claude, codex or opencode) shows that session's turns as a run inside it when the session is on the uploading machine.
|
|
185
186
|
- **The sourcemap** of the commit's added lines (see [The sourcemap](#the-sourcemap)).
|
|
186
187
|
- **Context conversations** the session's first message, its subagents' briefs or the marker name (see [Context conversations](#context-conversations)).
|
|
187
188
|
- The title Claude Code gave the session, the model, and when the commit was made.
|
|
@@ -436,7 +437,7 @@ Do not try it with the session you are working in: what is uploaded stays in the
|
|
|
436
437
|
|
|
437
438
|
```sh
|
|
438
439
|
gh repo create assistant-ui/tracehub-playground --private --clone && cd tracehub-playground
|
|
439
|
-
npx --yes tracehub@0.5.
|
|
440
|
+
npx --yes tracehub@0.5.8 setup # allow this repository, install the hooks
|
|
440
441
|
|
|
441
442
|
# open a fresh agent session in this directory, ask it for something harmless
|
|
442
443
|
export TRACEHUB_ID=claude:<throwaway session id>
|
package/dist/client/upload.js
CHANGED
|
@@ -7,7 +7,7 @@ import { fetchAll, readProviders } from "../local/providers.js";
|
|
|
7
7
|
import { claudeSubagentLabel, listSubagents } from "../local/subagents.js";
|
|
8
8
|
import { formatSessionRef, parseSessionRef, sessionName, } from "../protocol/sessionRef.js";
|
|
9
9
|
import { redactValue, } from "../redact/redact.js";
|
|
10
|
-
import { buildTrace } from "../trace/build.js";
|
|
10
|
+
import { buildTrace, namedSessions, parseSessionLines, } from "../trace/build.js";
|
|
11
11
|
import { firstLine } from "./errors.js";
|
|
12
12
|
function subagentsOf(ref, file) {
|
|
13
13
|
if (isClaudeSubagent(ref))
|
|
@@ -73,14 +73,30 @@ export async function uploadMarkers(client, target, stateDir, cwd, root, markers
|
|
|
73
73
|
}
|
|
74
74
|
try {
|
|
75
75
|
const sha = marker.commit ?? commitOfTrace(cwd, marker.traceId);
|
|
76
|
+
const lines = sessionLines(ref, file);
|
|
77
|
+
const subagents = subagentsOf(ref, file);
|
|
78
|
+
const transcripts = [
|
|
79
|
+
parseSessionLines(ref.agent, ref.id, lines, isClaudeSubagent(ref)),
|
|
80
|
+
...subagents.map((s) => parseSessionLines(ref.agent, s.id, s.lines, true)),
|
|
81
|
+
];
|
|
82
|
+
const named = new Map(transcripts
|
|
83
|
+
.flatMap((t) => namedSessions(t))
|
|
84
|
+
.map((r) => [formatSessionRef(r), r]));
|
|
85
|
+
const delegated = [];
|
|
86
|
+
for (const session of named.values()) {
|
|
87
|
+
const file = findSessionFile(session);
|
|
88
|
+
if (file)
|
|
89
|
+
delegated.push({ ...session, lines: sessionLines(session, file) });
|
|
90
|
+
}
|
|
76
91
|
const built = buildTrace({
|
|
77
92
|
agent: ref.agent,
|
|
78
93
|
id: ref.id,
|
|
79
|
-
lines
|
|
94
|
+
lines,
|
|
80
95
|
cut: marker.line,
|
|
81
96
|
committedAt: marker.ts,
|
|
82
97
|
since: previousCommit(all, marker),
|
|
83
|
-
subagents
|
|
98
|
+
subagents,
|
|
99
|
+
delegated,
|
|
84
100
|
root,
|
|
85
101
|
added: sha ? addedLines(cwd, sha) : new Map(),
|
|
86
102
|
...(isClaudeSubagent(ref)
|
package/dist/git/global-hooks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
2
2
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
|
-
import { hookBlock, hookRunner, hookVersion, legacyHookBlock, sameRunner, } from "./hooks.js";
|
|
4
|
+
import { hookBlock, hookRunner, hookVersion, legacyHookBlock, repoNpxHookBlock, sameRunner, } from "./hooks.js";
|
|
5
5
|
const HOOKS = [
|
|
6
6
|
"applypatch-msg",
|
|
7
7
|
"pre-applypatch",
|
|
@@ -61,22 +61,40 @@ function globalPath(cwd, env, expand = false) {
|
|
|
61
61
|
throw new Error("Multiple global core.hooksPath values require manual setup.");
|
|
62
62
|
return paths[0];
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
// The tracehub blocks a hook of this manifest may hold, the one this
|
|
65
|
+
// release writes first.
|
|
66
|
+
function blocks(hook, manifest) {
|
|
67
|
+
if (hook !== "prepare-commit-msg" && hook !== "pre-push")
|
|
68
|
+
return [""];
|
|
69
|
+
const version = manifest.cliVersion;
|
|
70
|
+
if (manifest.runner === undefined)
|
|
71
|
+
return [legacyHookBlock(hook, version)];
|
|
72
|
+
if (manifest.runner === null)
|
|
73
|
+
return [hookBlock(hook, version, null), repoNpxHookBlock(hook, version)];
|
|
74
|
+
return [hookBlock(hook, version, manifest.runner)];
|
|
75
|
+
}
|
|
76
|
+
// The lines that find the hooks to delegate to and open the delegation, the
|
|
77
|
+
// form this release writes first. Without a repository (git init runs
|
|
78
|
+
// reference-transaction before it has one) there is nothing to delegate to.
|
|
79
|
+
function lookups(hook, manifest) {
|
|
80
|
+
const recursive = `[ "$tracehub_hooks/${hook}" -ef "$0" ]`;
|
|
81
|
+
if (manifest.delegate !== null)
|
|
82
|
+
return [
|
|
83
|
+
`tracehub_hooks=${quote(manifest.delegate)}\nif ${recursive}; then`,
|
|
84
|
+
];
|
|
85
|
+
return [
|
|
86
|
+
`tracehub_hooks=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null) && tracehub_hooks="$tracehub_hooks/hooks"\nif [ -z "$tracehub_hooks" ]; then\n :\nelif ${recursive}; then`,
|
|
87
|
+
`tracehub_hooks="$(git rev-parse --path-format=absolute --git-common-dir)/hooks"\nif ${recursive}; then`,
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
function source(hook, manifest, block = blocks(hook, manifest)[0], lookup = lookups(hook, manifest)[0]) {
|
|
73
91
|
// An installed push-to-checkout hook replaces Git's built-in updateInstead behavior.
|
|
74
92
|
const fallback = hook === "push-to-checkout"
|
|
75
93
|
? 'cd "$GIT_WORK_TREE" || exit 1\ngit update-index -q --ignore-submodules --refresh || exit 1\ngit diff-files --quiet --ignore-submodules -- || exit 1\ngit diff --cached --quiet --ignore-submodules -- || exit 1\nexec git read-tree -u -m "$1"\n'
|
|
76
94
|
: hook === "fsmonitor-watchman" || hook === "proc-receive"
|
|
77
95
|
? "exit 1\n"
|
|
78
96
|
: "";
|
|
79
|
-
return `#!/bin/sh\n# tracehub global dispatcher\n${block}${
|
|
97
|
+
return `#!/bin/sh\n# tracehub global dispatcher\n${block}${lookup}\n printf '%s\\n' 'tracehub: recursive hook delegation skipped; review core.hooksPath' >&2\nelif [ -x "$tracehub_hooks/${hook}" ]; then\n exec "$tracehub_hooks/${hook}" "$@"\nfi\n${fallback}`;
|
|
80
98
|
}
|
|
81
99
|
function inheritedSystemPath(cwd, env) {
|
|
82
100
|
const result = spawnSync("git", ["config", "--show-scope", "--path", "--get-all", "core.hooksPath"], { cwd, env, encoding: "utf8" });
|
|
@@ -121,7 +139,8 @@ function verifyFiles(directory, manifest) {
|
|
|
121
139
|
!lstatSync(path).isFile() ||
|
|
122
140
|
lstatSync(path).isSymbolicLink() ||
|
|
123
141
|
(lstatSync(path).mode & 0o777) !== 0o755 ||
|
|
124
|
-
|
|
142
|
+
!blocks(hook, manifest).some((block) => lookups(hook, manifest).some((lookup) => readFileSync(path, "utf8") ===
|
|
143
|
+
source(hook, manifest, block, lookup))))
|
|
125
144
|
throw new Error(`Global dispatcher changed; preserve it and repair manually: ${path}`);
|
|
126
145
|
}
|
|
127
146
|
}
|
|
@@ -174,7 +193,8 @@ export function installGlobalHooks(directory, cwd, env = process.env, runner = h
|
|
|
174
193
|
next.cliVersion = hookVersion();
|
|
175
194
|
if (current.cliVersion === next.cliVersion &&
|
|
176
195
|
current.runner !== undefined &&
|
|
177
|
-
sameRunner(current.runner, runner)
|
|
196
|
+
sameRunner(current.runner, runner) &&
|
|
197
|
+
HOOKS.every((hook) => readFileSync(join(directory, hook), "utf8") === source(hook, next)))
|
|
178
198
|
return "unchanged";
|
|
179
199
|
for (const hook of HOOKS)
|
|
180
200
|
writeFileSync(join(directory, hook), source(hook, next));
|
package/dist/git/hooks.js
CHANGED
|
@@ -51,9 +51,17 @@ function invocation(hook, version, runner, stdin) {
|
|
|
51
51
|
export function hookBlock(hook, version = hookVersion(), runner = hookRunner()) {
|
|
52
52
|
if (!VERSION.test(version))
|
|
53
53
|
throw new Error("Invalid tracehub hook version.");
|
|
54
|
+
return wrap(hook, (stdin) => invocation(hook, version, runner, stdin));
|
|
55
|
+
}
|
|
56
|
+
// The npx block of releases that ran npx inside the repository: recognized
|
|
57
|
+
// so the next setup can rewrite it.
|
|
58
|
+
export function repoNpxHookBlock(hook, version) {
|
|
59
|
+
return wrap(hook, (stdin) => `npx --yes --prefer-offline tracehub@${version} hook ${hook} "$@" ${stdin} || ${warning(`the ${hook} hook could not run tracehub@${version}; run "tracehub setup" to repair the hooks`)}`);
|
|
60
|
+
}
|
|
61
|
+
function wrap(hook, invoke) {
|
|
54
62
|
const body = hook === "pre-push"
|
|
55
|
-
? `if tracehub_input=$(mktemp); then\n if cat > "$tracehub_input"; then\n${indent(
|
|
56
|
-
:
|
|
63
|
+
? `if tracehub_input=$(mktemp); then\n if cat > "$tracehub_input"; then\n${indent(invoke('< "$tracehub_input"'), 4)}\n else\n printf '%s\\n' 'tracehub: unable to preserve push input; trace upload skipped' >&2\n fi\n exec < "$tracehub_input"\n rm -f "$tracehub_input"\nelse\n printf '%s\\n' 'tracehub: unable to preserve push input; trace upload skipped' >&2\nfi`
|
|
64
|
+
: invoke("</dev/null");
|
|
57
65
|
return `${START}\n${body}\n${END}\n`;
|
|
58
66
|
}
|
|
59
67
|
const indent = (text, n) => text
|
package/dist/protocol/trace.js
CHANGED
|
@@ -61,7 +61,14 @@ function parseRun(raw, depth) {
|
|
|
61
61
|
if (!isObject(raw) || !isString(raw["label"]))
|
|
62
62
|
return undefined;
|
|
63
63
|
const turns = all(raw["turns"], (t) => parseTurn(t, depth));
|
|
64
|
-
|
|
64
|
+
const agent = raw["agent"];
|
|
65
|
+
return turns
|
|
66
|
+
? {
|
|
67
|
+
label: raw["label"].slice(0, 200),
|
|
68
|
+
turns,
|
|
69
|
+
...(AGENTS.includes(agent) ? { agent } : {}),
|
|
70
|
+
}
|
|
71
|
+
: undefined;
|
|
65
72
|
}
|
|
66
73
|
function parseSourcemap(raw) {
|
|
67
74
|
if (!isObject(raw))
|
package/dist/trace/build.js
CHANGED
|
@@ -3,6 +3,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "no
|
|
|
3
3
|
import { gitDir, repoRoot } from "../git/git.js";
|
|
4
4
|
import { ranInside } from "../local/discover.js";
|
|
5
5
|
import { contextRefsIn } from "../protocol/context.js";
|
|
6
|
+
import { AGENTS, formatSessionRef, } from "../protocol/sessionRef.js";
|
|
6
7
|
import { lineHash, } from "../protocol/trace.js";
|
|
7
8
|
import { redactValue, } from "../redact/redact.js";
|
|
8
9
|
import { parseClaude } from "../transcript/parseClaude.js";
|
|
@@ -20,6 +21,21 @@ export function parseSessionLines(agent, id, lines, sidechain = false) {
|
|
|
20
21
|
return parseOpencode(lines, id);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
24
|
+
export function namedSessions(transcript) {
|
|
25
|
+
const refs = new Map();
|
|
26
|
+
const pattern = new RegExp(`^(${AGENTS.join("|")})-session: ([A-Za-z0-9_-]+)\\s*$`, "gm");
|
|
27
|
+
for (const event of transcript.events) {
|
|
28
|
+
if (event.kind !== "tool_result" && event.kind !== "assistant")
|
|
29
|
+
continue;
|
|
30
|
+
for (const match of event.text.matchAll(pattern)) {
|
|
31
|
+
const ref = { agent: match[1], id: match[2] };
|
|
32
|
+
if (ref.agent === transcript.agent && ref.id === transcript.id)
|
|
33
|
+
continue;
|
|
34
|
+
refs.set(formatSessionRef(ref), ref);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [...refs.values()];
|
|
38
|
+
}
|
|
23
39
|
function realOrSelf(path) {
|
|
24
40
|
try {
|
|
25
41
|
return realpathSync(path);
|
|
@@ -60,6 +76,7 @@ function addChange(turn, path, added, removed) {
|
|
|
60
76
|
function turnsOf(events, cwd, prefix, ctx, children) {
|
|
61
77
|
const turns = [];
|
|
62
78
|
const callTurn = new Map();
|
|
79
|
+
const eventTurn = new Map();
|
|
63
80
|
for (const event of events) {
|
|
64
81
|
if (event.kind === "tool_result")
|
|
65
82
|
continue;
|
|
@@ -68,6 +85,7 @@ function turnsOf(events, cwd, prefix, ctx, children) {
|
|
|
68
85
|
turns.push({ at: event.ts, messages: [], changes: [], runs: [] });
|
|
69
86
|
const turn = turns.at(-1);
|
|
70
87
|
const index = turns.length - 1;
|
|
88
|
+
eventTurn.set(event, index);
|
|
71
89
|
if (event.kind === "user")
|
|
72
90
|
turn.messages.push({ role: "user", at: event.ts, text: event.text });
|
|
73
91
|
else if (event.kind === "assistant")
|
|
@@ -90,7 +108,11 @@ function turnsOf(events, cwd, prefix, ctx, children) {
|
|
|
90
108
|
// A subagent goes under the turn whose call launched it, else under the
|
|
91
109
|
// last turn that started before it did.
|
|
92
110
|
for (const child of children) {
|
|
93
|
-
let index = child.
|
|
111
|
+
let index = child.event && child.event.kind !== "tool_result"
|
|
112
|
+
? eventTurn.get(child.event)
|
|
113
|
+
: child.callId === undefined
|
|
114
|
+
? undefined
|
|
115
|
+
: callTurn.get(child.callId);
|
|
94
116
|
if (index === undefined) {
|
|
95
117
|
index = turns.length - 1;
|
|
96
118
|
while (index > 0 && Date.parse(turns[index].at) > child.startMs)
|
|
@@ -101,7 +123,7 @@ function turnsOf(events, cwd, prefix, ctx, children) {
|
|
|
101
123
|
continue;
|
|
102
124
|
const runPrefix = `${prefix}${index}.${turn.runs.length}.`;
|
|
103
125
|
const childCwd = child.transcript.cwd || cwd;
|
|
104
|
-
const runTurns = turnsOf(child.transcript.events, childCwd, runPrefix, ctx,
|
|
126
|
+
const runTurns = turnsOf(child.transcript.events, childCwd, runPrefix, ctx, child.children);
|
|
105
127
|
const first = runTurns[0];
|
|
106
128
|
if (child.prompt && !first?.messages.some((m) => m.role === "user")) {
|
|
107
129
|
const at = first?.at ?? turn.at;
|
|
@@ -115,7 +137,11 @@ function turnsOf(events, cwd, prefix, ctx, children) {
|
|
|
115
137
|
runs: [],
|
|
116
138
|
});
|
|
117
139
|
}
|
|
118
|
-
const run = {
|
|
140
|
+
const run = {
|
|
141
|
+
label: child.label,
|
|
142
|
+
turns: runTurns,
|
|
143
|
+
...(child.agent ? { agent: child.agent } : {}),
|
|
144
|
+
};
|
|
119
145
|
const times = child.transcript.events
|
|
120
146
|
.map((e) => Date.parse(e.ts))
|
|
121
147
|
.filter((ms) => !Number.isNaN(ms));
|
|
@@ -237,8 +263,47 @@ export function buildTrace(input, opts = {}) {
|
|
|
237
263
|
prompt: spawn?.prompt ?? "",
|
|
238
264
|
callId,
|
|
239
265
|
startMs: Number.isNaN(start) ? Infinity : start,
|
|
266
|
+
children: [],
|
|
240
267
|
};
|
|
241
268
|
});
|
|
269
|
+
const session = { ...before, events };
|
|
270
|
+
const owners = [
|
|
271
|
+
...children.map((child) => ({
|
|
272
|
+
transcript: child.transcript,
|
|
273
|
+
children: child.children,
|
|
274
|
+
})),
|
|
275
|
+
{ transcript: session, children },
|
|
276
|
+
].map((owner) => ({ ...owner, named: namedSessions(owner.transcript) }));
|
|
277
|
+
for (const delegated of input.delegated ?? []) {
|
|
278
|
+
const matches = owners.flatMap((owner) => {
|
|
279
|
+
if (!owner.named.some((r) => r.agent === delegated.agent && r.id === delegated.id))
|
|
280
|
+
return [];
|
|
281
|
+
const pattern = new RegExp(`^${delegated.agent}-session: ${delegated.id}\\s*$`, "m");
|
|
282
|
+
const event = owner.transcript.events.find((e) => (e.kind === "tool_result" || e.kind === "assistant") &&
|
|
283
|
+
pattern.test(e.text));
|
|
284
|
+
return event ? [{ ...owner, event }] : [];
|
|
285
|
+
});
|
|
286
|
+
const subagents = matches
|
|
287
|
+
.filter((m) => m.transcript !== session)
|
|
288
|
+
.sort((a, b) => Date.parse(a.event.ts) - Date.parse(b.event.ts));
|
|
289
|
+
const owner = subagents[0] ?? matches.find((m) => m.transcript === session);
|
|
290
|
+
if (!owner ||
|
|
291
|
+
owner.children.some((c) => c.agent === delegated.agent && c.transcript.id === delegated.id))
|
|
292
|
+
continue;
|
|
293
|
+
const transcript = sliceTranscript(parseSessionLines(delegated.agent, delegated.id, delegated.lines, false), cutoffMs);
|
|
294
|
+
if (!transcript.events.length)
|
|
295
|
+
continue;
|
|
296
|
+
owner.children.push({
|
|
297
|
+
transcript,
|
|
298
|
+
label: delegated.agent,
|
|
299
|
+
agent: delegated.agent,
|
|
300
|
+
prompt: "",
|
|
301
|
+
callId: owner.event.kind === "tool_result" ? owner.event.callId : undefined,
|
|
302
|
+
startMs: Date.parse(owner.event.ts),
|
|
303
|
+
event: owner.event,
|
|
304
|
+
children: [],
|
|
305
|
+
});
|
|
306
|
+
}
|
|
242
307
|
// A file counts as the repository's when it is in a checkout of it: this
|
|
243
308
|
// one, or a worktree that shares its git directory.
|
|
244
309
|
const common = gitDir(input.root);
|
|
@@ -264,7 +329,7 @@ export function buildTrace(input, opts = {}) {
|
|
|
264
329
|
}
|
|
265
330
|
}
|
|
266
331
|
};
|
|
267
|
-
const roots = (dir) => [input.root, realOrSelf(input.root)
|
|
332
|
+
const roots = (dir) => [nearest(dir), input.root, realOrSelf(input.root)].filter((r) => !!r);
|
|
268
333
|
const ctx = { roots, written: [], ends: new Map() };
|
|
269
334
|
const cwd = before.cwd || input.root;
|
|
270
335
|
let turns = turnsOf(events, cwd, "", ctx, children.filter((c) => c.transcript.events.length));
|
|
@@ -74,7 +74,15 @@ function readAssistantLine(t, line) {
|
|
|
74
74
|
t.events.push({ kind: "assistant", ts, text: block.text, turnId });
|
|
75
75
|
}
|
|
76
76
|
else if (block.type === "tool_use") {
|
|
77
|
-
|
|
77
|
+
const message = block.name === "SubagentHandback" && block.input
|
|
78
|
+
? block.input.message
|
|
79
|
+
: undefined;
|
|
80
|
+
if (typeof message === "string" && message !== "") {
|
|
81
|
+
t.events.push({ kind: "assistant", ts, text: message, turnId });
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
readToolCall(t, block, ts, turnId);
|
|
85
|
+
}
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
}
|
|
@@ -102,6 +102,69 @@ function readToolResult(r, ts, payload) {
|
|
|
102
102
|
text: textOf(payload["output"]),
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
|
+
function contentLines(value) {
|
|
106
|
+
if (typeof value !== "string")
|
|
107
|
+
return [];
|
|
108
|
+
const lines = value.split("\n");
|
|
109
|
+
if (lines.at(-1) === "")
|
|
110
|
+
lines.pop();
|
|
111
|
+
return lines;
|
|
112
|
+
}
|
|
113
|
+
function readFileChange(r, ts, payload) {
|
|
114
|
+
const item = payload["item"];
|
|
115
|
+
if (!item || typeof item !== "object")
|
|
116
|
+
return;
|
|
117
|
+
const change = item;
|
|
118
|
+
if (change["type"] !== "FileChange" || change["status"] !== "completed")
|
|
119
|
+
return;
|
|
120
|
+
const changes = change["changes"];
|
|
121
|
+
if (!changes || typeof changes !== "object" || Array.isArray(changes))
|
|
122
|
+
return;
|
|
123
|
+
const entries = Object.entries(changes);
|
|
124
|
+
const edits = [];
|
|
125
|
+
for (const [path, value] of entries) {
|
|
126
|
+
if (!value || typeof value !== "object")
|
|
127
|
+
continue;
|
|
128
|
+
const file = value;
|
|
129
|
+
const edit = {
|
|
130
|
+
path: stringOf(file["move_path"]) ?? path,
|
|
131
|
+
removed: [],
|
|
132
|
+
added: [],
|
|
133
|
+
};
|
|
134
|
+
switch (file["type"]) {
|
|
135
|
+
case "add":
|
|
136
|
+
edit.added = contentLines(file["content"]);
|
|
137
|
+
break;
|
|
138
|
+
case "delete":
|
|
139
|
+
edit.removed = contentLines(file["content"]);
|
|
140
|
+
break;
|
|
141
|
+
case "update": {
|
|
142
|
+
const diff = file["unified_diff"];
|
|
143
|
+
if (typeof diff !== "string")
|
|
144
|
+
continue;
|
|
145
|
+
for (const line of diff.split("\n")) {
|
|
146
|
+
if (line.startsWith("+"))
|
|
147
|
+
edit.added.push(line.slice(1));
|
|
148
|
+
else if (line.startsWith("-"))
|
|
149
|
+
edit.removed.push(line.slice(1));
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
default:
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
edits.push(edit);
|
|
157
|
+
}
|
|
158
|
+
r.transcript.events.push({
|
|
159
|
+
kind: "tool_call",
|
|
160
|
+
ts,
|
|
161
|
+
name: "apply_patch",
|
|
162
|
+
arg: entries[0]?.[0] ?? "",
|
|
163
|
+
callId: String(change["id"] ?? ""),
|
|
164
|
+
turnId: r.turnId,
|
|
165
|
+
edits,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
105
168
|
function readResponseItem(r, ts, payload) {
|
|
106
169
|
switch (payload["type"]) {
|
|
107
170
|
case "message":
|
|
@@ -129,6 +192,9 @@ function readLine(r, line) {
|
|
|
129
192
|
}
|
|
130
193
|
return;
|
|
131
194
|
case "event_msg":
|
|
195
|
+
if (payload["type"] === "item_completed") {
|
|
196
|
+
readFileChange(r, ts, payload);
|
|
197
|
+
}
|
|
132
198
|
if (payload["type"] === "task_started") {
|
|
133
199
|
r.turnId = String(payload["turn_id"] ?? r.turnId);
|
|
134
200
|
r.active = true;
|