tracehub 0.5.8 → 0.5.10
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 +19 -84
- package/dist/cli/args.js +15 -0
- package/dist/cli/commands/backfill.js +24 -58
- package/dist/cli/commands/context.js +11 -30
- package/dist/cli/commands/hook.js +24 -33
- package/dist/cli/commands/providers.js +0 -5
- package/dist/cli/commands/setup.js +0 -5
- package/dist/cli/commands/show.js +262 -0
- package/dist/cli/commands/uninstall.js +0 -5
- package/dist/cli/remote.js +11 -4
- package/dist/cli/repo.js +8 -8
- package/dist/cli/ui.js +1 -1
- package/dist/cli/usage.js +18 -0
- package/dist/cli.js +11 -2
- package/dist/client/github.js +14 -17
- package/dist/client/tracehub.js +25 -9
- package/dist/client/uploadPolicy.js +2 -10
- package/dist/git/git.js +15 -1
- package/dist/git/trailers.js +8 -21
- package/dist/local/backfill.js +3 -3
- package/dist/local/discover.js +7 -20
- package/dist/local/files.js +23 -0
- package/dist/local/providers.js +2 -3
- package/dist/local/subagents.js +5 -8
- package/dist/protocol/harness.js +56 -0
- package/dist/protocol/pages.js +1 -0
- package/dist/protocol/trace.js +18 -1
- package/dist/protocol/trailers.js +26 -0
- package/dist/redact/deny.js +2 -2
- package/dist/trace/build.js +110 -33
- package/dist/transcript/parseClaude.js +7 -4
- package/package.json +13 -18
package/dist/local/backfill.js
CHANGED
|
@@ -18,8 +18,8 @@ export function checkoutsNamed(command, home = "") {
|
|
|
18
18
|
const LOOKBACK_MS = 7 * 24 * 3600_000;
|
|
19
19
|
// The commit's time is in whole seconds, its session's in milliseconds.
|
|
20
20
|
const SLACK_MS = 60_000;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const HIGH = 7;
|
|
22
|
+
const MEDIUM = 4;
|
|
23
23
|
// The session's events with the line each one came from; parsed one line at
|
|
24
24
|
// a time, as commitBoundary reads them.
|
|
25
25
|
export function candidateOf(ref, file, lines, opts = {}) {
|
|
@@ -76,7 +76,7 @@ function editedPath(path, cwd, files) {
|
|
|
76
76
|
return files.find((f) => full === f || full.endsWith(`/${f}`));
|
|
77
77
|
}
|
|
78
78
|
const TRUNK = new Set(["main", "master", "HEAD", "develop"]);
|
|
79
|
-
|
|
79
|
+
function confidenceOf(score, tied) {
|
|
80
80
|
if (tied && score >= HIGH)
|
|
81
81
|
return "high";
|
|
82
82
|
if (score >= MEDIUM)
|
package/dist/local/discover.js
CHANGED
|
@@ -3,7 +3,7 @@ import { isAbsolute, join } from "node:path";
|
|
|
3
3
|
import { parseClaude } from "../transcript/parseClaude.js";
|
|
4
4
|
import { codexSessionMeta } from "../transcript/parseCodex.js";
|
|
5
5
|
import { openCommitCalls } from "./commitBoundary.js";
|
|
6
|
-
import { fileEntry, firstLineOf, listDir } from "./files.js";
|
|
6
|
+
import { fileEntry, firstLineOf, listDir, walkClaudeTranscripts, } from "./files.js";
|
|
7
7
|
import { completeLines } from "./lines.js";
|
|
8
8
|
import { hasOpencodeSession, listOpencodeSessions, } from "./opencode.js";
|
|
9
9
|
import { claudeProjectsDir, codexSessionsDir, encodeClaudeCwd, home, opencodeDb, } from "./paths.js";
|
|
@@ -116,22 +116,9 @@ export function isClaudeSubagent(ref) {
|
|
|
116
116
|
// ~/.claude/projects/*/<session id>/subagents/agent-<id>.jsonl, for the
|
|
117
117
|
// files written to since sinceMs.
|
|
118
118
|
function* walkClaudeSubagentFiles(sinceMs) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (session.endsWith(".jsonl"))
|
|
123
|
-
continue;
|
|
124
|
-
const dir = join(base, project, session, "subagents");
|
|
125
|
-
for (const name of listDir(dir)) {
|
|
126
|
-
if (!/^agent-[A-Za-z0-9_-]+\.jsonl$/.test(name))
|
|
127
|
-
continue;
|
|
128
|
-
const entry = fileEntry(join(dir, name));
|
|
129
|
-
if (!entry || entry.mtimeMs <= sinceMs)
|
|
130
|
-
continue;
|
|
131
|
-
const parent = join(base, project, `${session}.jsonl`);
|
|
132
|
-
yield { ...entry, id: name.slice(0, -".jsonl".length), parent };
|
|
133
|
-
}
|
|
134
|
-
}
|
|
119
|
+
for (const entry of walkClaudeTranscripts(claudeProjectsDir())) {
|
|
120
|
+
if (entry.parent && entry.mtimeMs > sinceMs)
|
|
121
|
+
yield { ...entry, parent: entry.parent };
|
|
135
122
|
}
|
|
136
123
|
}
|
|
137
124
|
// The ways a command can name the repository's checkout.
|
|
@@ -171,11 +158,11 @@ export function subagentWork(lines, root, sinceMs) {
|
|
|
171
158
|
}
|
|
172
159
|
// How far back subagents filed under other projects are read: they are
|
|
173
160
|
// read whole, so only the recent ones.
|
|
174
|
-
|
|
161
|
+
const SUBAGENT_WINDOW_MS = DAY_MS;
|
|
175
162
|
// The subagents of sessions that ran outside the repository, written to
|
|
176
163
|
// recently, that name the repository somewhere. A subagent of a session
|
|
177
164
|
// inside it is a run of that session's trace instead.
|
|
178
|
-
function
|
|
165
|
+
function discoverClaudeSubagents(repoRoot, sinceMs) {
|
|
179
166
|
const from = Math.max(sinceMs, Date.now() - SUBAGENT_WINDOW_MS);
|
|
180
167
|
const parents = new Map();
|
|
181
168
|
const found = [];
|
|
@@ -246,7 +233,7 @@ export function discoverActiveSessions(repoRoot, sinceMs) {
|
|
|
246
233
|
repoRoot,
|
|
247
234
|
sinceMs,
|
|
248
235
|
claudeFiles: listClaudeFiles(repoRoot),
|
|
249
|
-
claudeSubagents:
|
|
236
|
+
claudeSubagents: discoverClaudeSubagents(repoRoot, sinceMs),
|
|
250
237
|
codexFiles: listCodexFiles(sinceMs),
|
|
251
238
|
opencodeSessions: listOpencodeSessions(sinceMs),
|
|
252
239
|
});
|
package/dist/local/files.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename, join } from "node:path";
|
|
1
2
|
import { closeSync, existsSync, openSync, readdirSync, readFileSync, readSync, statSync, } from "node:fs";
|
|
2
3
|
// A JSON object read from a file; anything else (missing, malformed, an
|
|
3
4
|
// array) reads as an empty object.
|
|
@@ -53,3 +54,25 @@ export function firstLineOf(file) {
|
|
|
53
54
|
closeSync(fd);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
57
|
+
export function* walkClaudeTranscripts(projectsDir, sessionFile) {
|
|
58
|
+
const sessions = sessionFile
|
|
59
|
+
? [sessionFile]
|
|
60
|
+
: listDir(projectsDir).flatMap((project) => listDir(join(projectsDir, project)).map((name) => join(projectsDir, project, name)));
|
|
61
|
+
for (const path of sessions) {
|
|
62
|
+
if (!sessionFile && path.endsWith(".jsonl")) {
|
|
63
|
+
const entry = fileEntry(path);
|
|
64
|
+
if (entry)
|
|
65
|
+
yield { ...entry, id: basename(path, ".jsonl") };
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const parent = sessionFile ?? `${path}.jsonl`;
|
|
69
|
+
const dir = join(sessionFile ? sessionFile.replace(/\.jsonl$/, "") : path, "subagents");
|
|
70
|
+
for (const name of listDir(dir).sort()) {
|
|
71
|
+
if (!/^agent-[A-Za-z0-9_-]+\.jsonl$/.test(name))
|
|
72
|
+
continue;
|
|
73
|
+
const entry = fileEntry(join(dir, name));
|
|
74
|
+
if (entry)
|
|
75
|
+
yield { ...entry, id: basename(name, ".jsonl"), parent };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/local/providers.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
4
|
-
import { writeFileSync } from "node:fs";
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
|
|
5
4
|
import { dirname } from "node:path";
|
|
6
5
|
import { conversationOf, parseContextEntries, parseContextRef, PROVIDER_NAME, } from "../protocol/context.js";
|
|
7
6
|
import { providersFile } from "./paths.js";
|
|
@@ -53,7 +52,7 @@ export function providerArgv(provider, id) {
|
|
|
53
52
|
}
|
|
54
53
|
// An entry without an id is named by its content, so attaching it twice
|
|
55
54
|
// replaces it rather than adding it again.
|
|
56
|
-
|
|
55
|
+
function contentId(entry) {
|
|
57
56
|
const key = JSON.stringify([
|
|
58
57
|
entry.author,
|
|
59
58
|
entry.at,
|
package/dist/local/subagents.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { basename, dirname, join } from "node:path";
|
|
2
2
|
import { codexSessionMeta } from "../transcript/parseCodex.js";
|
|
3
3
|
import { walkCodexFiles } from "./discover.js";
|
|
4
|
-
import { firstLineOf,
|
|
4
|
+
import { firstLineOf, walkClaudeTranscripts, readJsonObject } from "./files.js";
|
|
5
5
|
import { listOpencodeSubagents } from "./opencode.js";
|
|
6
6
|
const DEFAULT_KIND = "subagent";
|
|
7
7
|
// Claude Code keeps subagent transcripts beside the parent session file, in
|
|
@@ -21,18 +21,15 @@ export function claudeSubagentLabel(file) {
|
|
|
21
21
|
}
|
|
22
22
|
// An optional agent-<id>.meta.json says how the parent launched the subagent.
|
|
23
23
|
export function listClaudeSubagents(sessionFile) {
|
|
24
|
-
const dir = claudeSubagentDir(sessionFile);
|
|
25
24
|
const subagents = [];
|
|
26
|
-
for (const
|
|
27
|
-
const id =
|
|
28
|
-
|
|
29
|
-
continue;
|
|
30
|
-
const meta = readJsonObject(join(dir, `agent-${id}.meta.json`));
|
|
25
|
+
for (const entry of walkClaudeTranscripts("", sessionFile)) {
|
|
26
|
+
const id = entry.id.slice("agent-".length);
|
|
27
|
+
const meta = readJsonObject(entry.file.replace(/\.jsonl$/, ".meta.json"));
|
|
31
28
|
const toolUseId = stringField(meta, "toolUseId");
|
|
32
29
|
subagents.push({
|
|
33
30
|
id,
|
|
34
31
|
kind: stringField(meta, "agentType") ?? DEFAULT_KIND,
|
|
35
|
-
file:
|
|
32
|
+
file: entry.file,
|
|
36
33
|
...(toolUseId ? { toolUseId } : {}),
|
|
37
34
|
});
|
|
38
35
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Text an agent's harness wrote into the user's side of a session: a CI
|
|
2
|
+
// event, a task notification, a reminder, a command's output. It is not
|
|
3
|
+
// what the person typed, so it reads as the system's. A message counts
|
|
4
|
+
// only when it starts with one of these wrappers, closed; a tag a person
|
|
5
|
+
// wrote mid-text leaves the message theirs.
|
|
6
|
+
const LABELS = {
|
|
7
|
+
"ci-monitor-event": "CI monitor",
|
|
8
|
+
"task-notification": "Task notification",
|
|
9
|
+
"system-reminder": "System reminder",
|
|
10
|
+
"command-name": "Command",
|
|
11
|
+
"command-message": "Command",
|
|
12
|
+
"command-args": "Command",
|
|
13
|
+
"local-command-stdout": "Command output",
|
|
14
|
+
"local-command-stderr": "Command output",
|
|
15
|
+
"local-command-caveat": "Command output",
|
|
16
|
+
"bash-input": "Shell",
|
|
17
|
+
"bash-stdout": "Shell output",
|
|
18
|
+
"bash-stderr": "Shell output",
|
|
19
|
+
"user-prompt-submit-hook": "Hook",
|
|
20
|
+
};
|
|
21
|
+
const WRAPPER = /^\s*<([a-z]+(?:-[a-z]+)+)(?:\s[^>]*)?>/;
|
|
22
|
+
const INTERRUPT = /^\s*\[Request interrupted by user[^\]]*\]\s*$/;
|
|
23
|
+
const HOOK = /^\s*(Stop|SubagentStop|PreToolUse|PostToolUse|UserPromptSubmit|SessionStart|PreCompact|Notification) hook (?:feedback|blocking error)[^:\n]*:/;
|
|
24
|
+
const oneLine = (text) => text
|
|
25
|
+
.replace(/<[^>]+>/g, " ")
|
|
26
|
+
.split("\n")
|
|
27
|
+
.map((l) => l.replace(/\s+/g, " ").trim())
|
|
28
|
+
.find(Boolean) ?? "";
|
|
29
|
+
const inner = (text, tag) => new RegExp(`<${tag}(?:\\s[^>]*)?>([\\s\\S]*?)</${tag}>`).exec(text)?.[1];
|
|
30
|
+
function summaryOf(tag, text) {
|
|
31
|
+
if (tag === "task-notification")
|
|
32
|
+
return oneLine(inner(text, "summary") ?? inner(text, "status") ?? "");
|
|
33
|
+
if (tag.startsWith("command-")) {
|
|
34
|
+
const name = inner(text, "command-name")?.trim();
|
|
35
|
+
const args = inner(text, "command-args")?.trim();
|
|
36
|
+
if (name)
|
|
37
|
+
return [name, args].filter(Boolean).join(" ");
|
|
38
|
+
}
|
|
39
|
+
return oneLine(inner(text, tag) ?? text);
|
|
40
|
+
}
|
|
41
|
+
// The event a user message is, when the harness wrote it.
|
|
42
|
+
export function harnessEvent(text) {
|
|
43
|
+
if (INTERRUPT.test(text))
|
|
44
|
+
return { label: "Interrupted", summary: "Request interrupted by user" };
|
|
45
|
+
const hook = HOOK.exec(text);
|
|
46
|
+
if (hook)
|
|
47
|
+
return {
|
|
48
|
+
label: "Hook",
|
|
49
|
+
summary: oneLine(text.slice(hook[0].length)) || `${hook[1]} hook`,
|
|
50
|
+
};
|
|
51
|
+
const tag = WRAPPER.exec(text)?.[1];
|
|
52
|
+
const label = tag && LABELS[tag];
|
|
53
|
+
if (!tag || !label || !text.includes(`</${tag}>`))
|
|
54
|
+
return undefined;
|
|
55
|
+
return { label, summary: summaryOf(tag, text) };
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/protocol/trace.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseContext } from "./context.js";
|
|
2
|
+
import { harnessEvent } from "./harness.js";
|
|
2
3
|
import { AGENTS } from "./sessionRef.js";
|
|
3
4
|
// FNV-1a 64 of the trimmed line, as 16 hex characters; blank lines have none.
|
|
4
5
|
export function lineHash(line) {
|
|
@@ -25,10 +26,26 @@ function parseMessage(raw) {
|
|
|
25
26
|
if (!isObject(raw))
|
|
26
27
|
return undefined;
|
|
27
28
|
const { role, at, text } = raw;
|
|
28
|
-
if ((role !== "user" && role !== "agent"
|
|
29
|
+
if ((role !== "user" && role !== "agent" && role !== "system") ||
|
|
30
|
+
!isTime(at) ||
|
|
31
|
+
!isString(text))
|
|
29
32
|
return undefined;
|
|
30
33
|
return { role, at, text: text.slice(0, MAX_TEXT) };
|
|
31
34
|
}
|
|
35
|
+
// The turns with each user message the harness wrote as the system's, for
|
|
36
|
+
// traces uploaded before the CLI told them apart.
|
|
37
|
+
export function withSystemMessages(turns) {
|
|
38
|
+
return turns.map((turn) => ({
|
|
39
|
+
...turn,
|
|
40
|
+
messages: turn.messages.map((m) => m.role === "user" && harnessEvent(m.text)
|
|
41
|
+
? { ...m, role: "system" }
|
|
42
|
+
: m),
|
|
43
|
+
runs: turn.runs.map((run) => ({
|
|
44
|
+
...run,
|
|
45
|
+
turns: withSystemMessages(run.turns),
|
|
46
|
+
})),
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
32
49
|
function parseChange(raw) {
|
|
33
50
|
if (!isObject(raw))
|
|
34
51
|
return undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const WEB_URL = "https://tracehub.aui.dev";
|
|
2
|
+
const ID = /^[0-9a-f]{16}$/;
|
|
3
|
+
const LINE = /^[ \t]*Assisted-by:[ \t]*(?:\S*\/)?([0-9a-f]{16})[ \t]*$/gm;
|
|
4
|
+
const PULL = /^[ \t]*Assisted-by:[ \t]*\S*\/pr\/([\w.-]+)\/([\w.-]+)\/([1-9]\d{0,9})[ \t]*$/gm;
|
|
5
|
+
export function isTraceId(s) {
|
|
6
|
+
return ID.test(s);
|
|
7
|
+
}
|
|
8
|
+
export function traceUrl(target, id, base = WEB_URL) {
|
|
9
|
+
return `${base}/t/${target.owner.toLowerCase()}/${target.repo.toLowerCase()}/${id}`;
|
|
10
|
+
}
|
|
11
|
+
// Squashed commits put trailers in the body, where git's trailer parser no longer sees them.
|
|
12
|
+
export function traceIds(message) {
|
|
13
|
+
return [...new Set([...message.matchAll(LINE)].map((m) => m[1]))];
|
|
14
|
+
}
|
|
15
|
+
export function pullUrl(target, number, base = WEB_URL) {
|
|
16
|
+
return `${base}/pr/${target.owner.toLowerCase()}/${target.repo.toLowerCase()}/${number}`;
|
|
17
|
+
}
|
|
18
|
+
// The pull requests of the repository a message links to: a squash merge
|
|
19
|
+
// names its pull request once instead of each squashed commit's trace.
|
|
20
|
+
export function pullNumbers(message, target) {
|
|
21
|
+
const numbers = [...message.matchAll(PULL)]
|
|
22
|
+
.filter((m) => m[1].toLowerCase() === target.owner.toLowerCase() &&
|
|
23
|
+
m[2].toLowerCase() === target.repo.toLowerCase())
|
|
24
|
+
.map((m) => Number(m[3]));
|
|
25
|
+
return [...new Set(numbers)];
|
|
26
|
+
}
|
package/dist/redact/deny.js
CHANGED
|
@@ -3,11 +3,11 @@ import { join } from "node:path";
|
|
|
3
3
|
import { configDir } from "../local/paths.js";
|
|
4
4
|
// The deny list is edited by hand: one literal per line. A shorter line would
|
|
5
5
|
// mask ordinary words, so it is ignored.
|
|
6
|
-
|
|
6
|
+
const DENY_MIN_LENGTH = 6;
|
|
7
7
|
export function denyFile() {
|
|
8
8
|
return join(configDir(), "deny.txt");
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
function parseDenyList(text) {
|
|
11
11
|
return [
|
|
12
12
|
...new Set(text
|
|
13
13
|
.split("\n")
|
package/dist/trace/build.js
CHANGED
|
@@ -80,28 +80,40 @@ function turnsOf(events, cwd, prefix, ctx, children) {
|
|
|
80
80
|
for (const event of events) {
|
|
81
81
|
if (event.kind === "tool_result")
|
|
82
82
|
continue;
|
|
83
|
-
const opens = event.kind === "user" && !event.steering;
|
|
83
|
+
const opens = (event.kind === "user" && !event.steering) || event.kind === "system";
|
|
84
84
|
if (opens || !turns.length)
|
|
85
85
|
turns.push({ at: event.ts, messages: [], changes: [], runs: [] });
|
|
86
86
|
const turn = turns.at(-1);
|
|
87
87
|
const index = turns.length - 1;
|
|
88
88
|
eventTurn.set(event, index);
|
|
89
|
-
if (event.kind === "user")
|
|
90
|
-
turn.messages.push({ role:
|
|
89
|
+
if (event.kind === "user" || event.kind === "system")
|
|
90
|
+
turn.messages.push({ role: event.kind, at: event.ts, text: event.text });
|
|
91
91
|
else if (event.kind === "assistant")
|
|
92
92
|
turn.messages.push({ role: "agent", at: event.ts, text: event.text });
|
|
93
93
|
else {
|
|
94
94
|
if (event.callId)
|
|
95
95
|
callTurn.set(event.callId, index);
|
|
96
96
|
for (const edit of event.edits ?? []) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
if (!path)
|
|
97
|
+
const file = ctx.file(edit.path, cwd);
|
|
98
|
+
if (!file)
|
|
100
99
|
continue;
|
|
101
|
-
|
|
100
|
+
const { path, home } = file;
|
|
101
|
+
const change = {
|
|
102
|
+
turn,
|
|
103
|
+
added: edit.added.length,
|
|
104
|
+
removed: edit.removed.length,
|
|
105
|
+
};
|
|
106
|
+
if (home)
|
|
107
|
+
addChange(turn, path, change.added, change.removed);
|
|
102
108
|
const hashes = new Set(edit.added.map(lineHash).filter((h) => h !== undefined));
|
|
103
109
|
const ts = Date.parse(event.ts);
|
|
104
|
-
ctx.written.push({
|
|
110
|
+
ctx.written.push({
|
|
111
|
+
turn: `${prefix}${index}`,
|
|
112
|
+
ts,
|
|
113
|
+
path,
|
|
114
|
+
hashes,
|
|
115
|
+
...(!home ? { change } : {}),
|
|
116
|
+
});
|
|
105
117
|
}
|
|
106
118
|
}
|
|
107
119
|
}
|
|
@@ -123,6 +135,7 @@ function turnsOf(events, cwd, prefix, ctx, children) {
|
|
|
123
135
|
continue;
|
|
124
136
|
const runPrefix = `${prefix}${index}.${turn.runs.length}.`;
|
|
125
137
|
const childCwd = child.transcript.cwd || cwd;
|
|
138
|
+
const start = ctx.written.length;
|
|
126
139
|
const runTurns = turnsOf(child.transcript.events, childCwd, runPrefix, ctx, child.children);
|
|
127
140
|
const first = runTurns[0];
|
|
128
141
|
if (child.prompt && !first?.messages.some((m) => m.role === "user")) {
|
|
@@ -147,6 +160,9 @@ function turnsOf(events, cwd, prefix, ctx, children) {
|
|
|
147
160
|
.filter((ms) => !Number.isNaN(ms));
|
|
148
161
|
if (times.length)
|
|
149
162
|
ctx.ends.set(run, Math.max(...times));
|
|
163
|
+
const written = ctx.written.slice(start);
|
|
164
|
+
if (written.length && written.every((w) => w.change))
|
|
165
|
+
ctx.foreignOnly.add(run);
|
|
150
166
|
turn.runs.push(run);
|
|
151
167
|
}
|
|
152
168
|
return turns;
|
|
@@ -161,6 +177,7 @@ function sourcemapOf(written, added) {
|
|
|
161
177
|
for (const w of ordered)
|
|
162
178
|
byPath.set(w.path, [...(byPath.get(w.path) ?? []), w]);
|
|
163
179
|
const map = {};
|
|
180
|
+
const attributed = new Set();
|
|
164
181
|
for (const [path, lines] of added) {
|
|
165
182
|
const edits = byPath.get(path);
|
|
166
183
|
if (!edits)
|
|
@@ -170,10 +187,15 @@ function sourcemapOf(written, added) {
|
|
|
170
187
|
if (!hash)
|
|
171
188
|
continue;
|
|
172
189
|
const last = [...edits].reverse().find((w) => w.hashes.has(hash));
|
|
173
|
-
if (last)
|
|
190
|
+
if (last) {
|
|
174
191
|
(map[path] ??= {})[hash] = last.turn;
|
|
192
|
+
attributed.add(last);
|
|
193
|
+
}
|
|
175
194
|
}
|
|
176
195
|
}
|
|
196
|
+
for (const { path, change } of attributed)
|
|
197
|
+
if (change)
|
|
198
|
+
addChange(change.turn, path, change.added, change.removed);
|
|
177
199
|
return map;
|
|
178
200
|
}
|
|
179
201
|
// The part of a session that made one commit, so a long session that
|
|
@@ -181,38 +203,75 @@ function sourcemapOf(written, added) {
|
|
|
181
203
|
// that wrote the commit's lines, and the turns with messages since the
|
|
182
204
|
// session's previous commit. A turn kept only for a run keeps its prompt
|
|
183
205
|
// and its messages since that commit. Without attributed lines, the runs
|
|
184
|
-
// active since that commit stay
|
|
185
|
-
// kept
|
|
186
|
-
|
|
206
|
+
// active since that commit stay, except those that only worked in another
|
|
207
|
+
// checkout. A kept prompt keeps the reply it answers, the last agent message
|
|
208
|
+
// of the turn before, in a turn of its own when that turn is out of scope.
|
|
209
|
+
// The sourcemap's turn paths follow the kept turns.
|
|
210
|
+
function scopeToCommit(turns, sourcemap, sinceMs, ends, foreignOnly) {
|
|
187
211
|
const hits = new Set(Object.values(sourcemap).flatMap((lines) => Object.values(lines)));
|
|
188
|
-
const
|
|
189
|
-
const kept = [];
|
|
190
|
-
turns.forEach((turn, i) => {
|
|
212
|
+
const decisions = turns.map((turn, i) => {
|
|
191
213
|
const own = hits.has(`${i}`);
|
|
192
214
|
const recent = i === turns.length - 1 ||
|
|
193
215
|
[turn.at, ...turn.messages.map((m) => m.at)].some((at) => Date.parse(at) >= sinceMs);
|
|
194
|
-
const runs =
|
|
195
|
-
turn.runs.forEach((run, j) => {
|
|
216
|
+
const runs = turn.runs.flatMap((run, j) => {
|
|
196
217
|
const prefix = `${i}.${j}.`;
|
|
197
218
|
const wrote = [...hits].filter((h) => h.startsWith(prefix));
|
|
198
219
|
if (!wrote.length &&
|
|
199
|
-
(hits.size > 0 ||
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
220
|
+
(hits.size > 0 ||
|
|
221
|
+
foreignOnly.has(run) ||
|
|
222
|
+
!((ends.get(run) ?? -Infinity) > sinceMs)))
|
|
223
|
+
return [];
|
|
224
|
+
return [{ run, index: j, wrote }];
|
|
204
225
|
});
|
|
205
226
|
if (!own && !recent && !runs.length)
|
|
227
|
+
return undefined;
|
|
228
|
+
return {
|
|
229
|
+
own,
|
|
230
|
+
recent,
|
|
231
|
+
messages: own
|
|
232
|
+
? turn.messages
|
|
233
|
+
: turn.messages.filter((m, k) => (k === 0 && m.role !== "agent") || Date.parse(m.at) >= sinceMs),
|
|
234
|
+
runs,
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
decisions.forEach((decision, i) => {
|
|
238
|
+
if (!decision || i === 0 || decision.messages[0]?.role !== "user")
|
|
206
239
|
return;
|
|
207
|
-
|
|
240
|
+
const previous = turns[i - 1];
|
|
241
|
+
const reply = [...previous.messages]
|
|
242
|
+
.reverse()
|
|
243
|
+
.find((m) => m.role === "agent");
|
|
244
|
+
if (!reply)
|
|
245
|
+
return;
|
|
246
|
+
const prior = decisions[i - 1];
|
|
247
|
+
if (prior)
|
|
248
|
+
prior.messages = previous.messages.filter((m) => m === reply || prior.messages.includes(m));
|
|
249
|
+
else
|
|
250
|
+
decisions[i - 1] = {
|
|
251
|
+
own: false,
|
|
252
|
+
recent: false,
|
|
253
|
+
messages: [reply],
|
|
254
|
+
runs: [],
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
const paths = new Map();
|
|
258
|
+
const kept = [];
|
|
259
|
+
decisions.forEach((decision, i) => {
|
|
260
|
+
if (!decision)
|
|
261
|
+
return;
|
|
262
|
+
const turn = turns[i];
|
|
263
|
+
if (decision.own)
|
|
208
264
|
paths.set(`${i}`, `${kept.length}`);
|
|
265
|
+
decision.runs.forEach(({ index, wrote }, j) => {
|
|
266
|
+
const prefix = `${i}.${index}.`;
|
|
267
|
+
for (const h of wrote)
|
|
268
|
+
paths.set(h, `${kept.length}.${j}.${h.slice(prefix.length)}`);
|
|
269
|
+
});
|
|
209
270
|
kept.push({
|
|
210
271
|
at: turn.at,
|
|
211
|
-
messages:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
changes: own || recent ? turn.changes : [],
|
|
215
|
-
runs,
|
|
272
|
+
messages: decision.messages,
|
|
273
|
+
changes: decision.own || decision.recent ? turn.changes : [],
|
|
274
|
+
runs: decision.runs.map(({ run }) => run),
|
|
216
275
|
});
|
|
217
276
|
});
|
|
218
277
|
const scoped = {};
|
|
@@ -246,7 +305,7 @@ export function buildTrace(input, opts = {}) {
|
|
|
246
305
|
const before = parseSessionLines(agent, id, lines.slice(0, cut), sidechain);
|
|
247
306
|
const events = [...before.events];
|
|
248
307
|
for (const event of whole.events.slice(before.events.length)) {
|
|
249
|
-
if (event.kind === "user" && !event.steering)
|
|
308
|
+
if ((event.kind === "user" && !event.steering) || event.kind === "system")
|
|
250
309
|
break;
|
|
251
310
|
if (event.kind === "assistant")
|
|
252
311
|
events.push(event);
|
|
@@ -329,8 +388,24 @@ export function buildTrace(input, opts = {}) {
|
|
|
329
388
|
}
|
|
330
389
|
}
|
|
331
390
|
};
|
|
332
|
-
const
|
|
333
|
-
const ctx = {
|
|
391
|
+
const commitRoot = realOrSelf(input.root);
|
|
392
|
+
const ctx = {
|
|
393
|
+
file: (path, cwd) => {
|
|
394
|
+
const abs = isAbsolute(path) ? path : resolve(cwd, path);
|
|
395
|
+
const checkout = nearest(dirname(abs));
|
|
396
|
+
const roots = [checkout, input.root, commitRoot].filter((r) => !!r);
|
|
397
|
+
const relative = repoPath(abs, cwd, roots);
|
|
398
|
+
return relative
|
|
399
|
+
? {
|
|
400
|
+
path: relative,
|
|
401
|
+
home: !checkout || realOrSelf(checkout) === commitRoot,
|
|
402
|
+
}
|
|
403
|
+
: undefined;
|
|
404
|
+
},
|
|
405
|
+
written: [],
|
|
406
|
+
ends: new Map(),
|
|
407
|
+
foreignOnly: new Set(),
|
|
408
|
+
};
|
|
334
409
|
const cwd = before.cwd || input.root;
|
|
335
410
|
let turns = turnsOf(events, cwd, "", ctx, children.filter((c) => c.transcript.events.length));
|
|
336
411
|
// A session that ran outside the repository (a coordinator whose
|
|
@@ -340,6 +415,9 @@ export function buildTrace(input, opts = {}) {
|
|
|
340
415
|
// whatever cwd its lines carry over from its parent, and so does a
|
|
341
416
|
// session that made the commit itself (`cd <checkout> && git commit`).
|
|
342
417
|
const outside = !sidechain && !input.committer && !ownCheckout(cwd);
|
|
418
|
+
if (outside)
|
|
419
|
+
ctx.written = ctx.written.filter((w) => w.turn.includes("."));
|
|
420
|
+
const sourcemap = sourcemapOf(ctx.written, input.added);
|
|
343
421
|
if (outside) {
|
|
344
422
|
turns = turns.map((turn) => ({
|
|
345
423
|
at: turn.at,
|
|
@@ -350,7 +428,6 @@ export function buildTrace(input, opts = {}) {
|
|
|
350
428
|
// its label: the label is the coordinator's own description.
|
|
351
429
|
changed(run.turns) ? run : { label: "", turns: [] }),
|
|
352
430
|
}));
|
|
353
|
-
ctx.written = ctx.written.filter((w) => w.turn.includes("."));
|
|
354
431
|
if (!turns.some((turn) => turn.runs.some((run) => run.turns.length)))
|
|
355
432
|
return undefined;
|
|
356
433
|
}
|
|
@@ -360,7 +437,7 @@ export function buildTrace(input, opts = {}) {
|
|
|
360
437
|
? sessionTitle(lines.slice(0, cut))
|
|
361
438
|
: undefined;
|
|
362
439
|
const since = Date.parse(input.since ?? "");
|
|
363
|
-
const scoped = scopeToCommit(turns,
|
|
440
|
+
const scoped = scopeToCommit(turns, sourcemap, Number.isNaN(since) ? -Infinity : since, ctx.ends, ctx.foreignOnly);
|
|
364
441
|
// The session's first message names its conversation even when its turn
|
|
365
442
|
// is out of scope; a run's brief counts only for the runs in scope.
|
|
366
443
|
const first = turns[0]?.messages.find((m) => m.role === "user");
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { harnessEvent } from "../protocol/harness.js";
|
|
1
2
|
import { editsOf, firstArg, parseJsonl, } from "./transcript.js";
|
|
2
|
-
|
|
3
|
+
// What the harness injected that stays on the machine: local output and
|
|
4
|
+
// reminders. Other harness text (a CI event) is uploaded as the system's.
|
|
5
|
+
const INJECTED_PREFIX = /^\s*<(command-message|command-name|command-args|local-command-stdout|local-command-stderr|local-command-caveat|system-reminder|task-notification|bash-input|bash-stdout|bash-stderr|user-prompt-submit-hook)/;
|
|
3
6
|
function cleanUserText(text) {
|
|
4
7
|
return text
|
|
5
8
|
.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, "")
|
|
@@ -35,9 +38,9 @@ function readUserLine(t, line) {
|
|
|
35
38
|
t.events.push({ kind: "tool_result", ts, callId, text });
|
|
36
39
|
}
|
|
37
40
|
const text = cleanUserText(blockText(content));
|
|
38
|
-
if (text
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
+
if (!text || INJECTED_PREFIX.test(text))
|
|
42
|
+
return;
|
|
43
|
+
t.events.push({ kind: harnessEvent(text) ? "system" : "user", ts, text });
|
|
41
44
|
}
|
|
42
45
|
const SPAWN_TOOLS = ["Task", "Agent"];
|
|
43
46
|
function readToolCall(t, block, ts, turnId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tracehub",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "Attach coding-agent sessions (Claude Code, Codex, OpenCode) to git commits and pull requests, redacted.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,17 +14,6 @@
|
|
|
14
14
|
"dist",
|
|
15
15
|
"README.md"
|
|
16
16
|
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc && chmod +x dist/cli.js",
|
|
19
|
-
"typecheck": "tsc --noEmit -p tsconfig.test.json",
|
|
20
|
-
"format": "oxfmt --check",
|
|
21
|
-
"format:fix": "oxfmt",
|
|
22
|
-
"test": "tsc -p tsconfig.test.json && vitest run",
|
|
23
|
-
"test:coverage": "tsc -p tsconfig.test.json && vitest run --coverage --coverage.reporter=text --coverage.reporter=html --coverage.reporter=json-summary",
|
|
24
|
-
"prepack": "npm run build",
|
|
25
|
-
"docs:install": "pnpm --dir docs install",
|
|
26
|
-
"docs:dev": "pnpm --dir docs dev"
|
|
27
|
-
},
|
|
28
17
|
"devDependencies": {
|
|
29
18
|
"@types/node": "^26.6.6",
|
|
30
19
|
"@vitest/coverage-v8": "^5.0.5",
|
|
@@ -46,14 +35,20 @@
|
|
|
46
35
|
"dependencies": {
|
|
47
36
|
"@clack/prompts": "^1.8.1"
|
|
48
37
|
},
|
|
49
|
-
"allowScripts": {
|
|
50
|
-
"fsevents@2.3.3": true
|
|
51
|
-
},
|
|
52
38
|
"devEngines": {
|
|
53
39
|
"packageManager": {
|
|
54
|
-
"name": "
|
|
55
|
-
"version": ">=
|
|
40
|
+
"name": "pnpm",
|
|
41
|
+
"version": ">=12",
|
|
56
42
|
"onFail": "error"
|
|
57
43
|
}
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc && chmod +x dist/cli.js",
|
|
47
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json && tsc -p tsconfig.shared.json",
|
|
48
|
+
"format": "oxfmt --check",
|
|
49
|
+
"format:fix": "oxfmt",
|
|
50
|
+
"test": "tsc -p tsconfig.test.json && vitest run",
|
|
51
|
+
"test:coverage": "tsc -p tsconfig.test.json && vitest run --coverage --coverage.reporter=text --coverage.reporter=html --coverage.reporter=json-summary",
|
|
52
|
+
"docs:dev": "pnpm --filter tracehub-docs dev"
|
|
58
53
|
}
|
|
59
|
-
}
|
|
54
|
+
}
|