@letsrebase/verify 0.0.0-stage → 0.1.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.
Files changed (49) hide show
  1. package/.claude/commands/rebase-verify.md +118 -0
  2. package/LICENSE +21 -0
  3. package/PRIVACY.md +113 -0
  4. package/README.md +209 -2
  5. package/SECURITY.md +33 -0
  6. package/bin/rebase-verify.mjs +699 -0
  7. package/package.json +38 -4
  8. package/share/practices.json +224 -0
  9. package/share/tech-labels.json +57 -0
  10. package/share/tech-lexicon.json +62 -0
  11. package/src/adapters/claude-code.mjs +225 -0
  12. package/src/adapters/codex.mjs +476 -0
  13. package/src/adapters/cursor.mjs +584 -0
  14. package/src/adapters/kimi.mjs +594 -0
  15. package/src/adapters/omp.mjs +59 -0
  16. package/src/adapters/opencode.mjs +439 -0
  17. package/src/adapters/pi.mjs +414 -0
  18. package/src/adapters/tool-vocab.mjs +15 -0
  19. package/src/agent-run.mjs +10 -0
  20. package/src/agentic-literacy.mjs +211 -0
  21. package/src/agents/acp.mjs +364 -0
  22. package/src/agents/json-answer.mjs +72 -0
  23. package/src/agents/registry.mjs +370 -0
  24. package/src/agents/run.mjs +131 -0
  25. package/src/ai-relationship.mjs +95 -0
  26. package/src/consistency.mjs +357 -0
  27. package/src/days.mjs +45 -0
  28. package/src/digest.mjs +501 -0
  29. package/src/distribution.mjs +54 -0
  30. package/src/enrich.mjs +118 -0
  31. package/src/fingerprint.mjs +134 -0
  32. package/src/forensics.mjs +178 -0
  33. package/src/groundedness.mjs +347 -0
  34. package/src/hub.mjs +136 -0
  35. package/src/intensity.mjs +132 -0
  36. package/src/live-status.mjs +79 -0
  37. package/src/practices-llm.mjs +90 -0
  38. package/src/practices-rules.mjs +295 -0
  39. package/src/practices-sample.mjs +111 -0
  40. package/src/practices.mjs +272 -0
  41. package/src/profile-llm.mjs +249 -0
  42. package/src/profile.mjs +497 -0
  43. package/src/redact.mjs +97 -0
  44. package/src/sources.mjs +91 -0
  45. package/src/submit.mjs +65 -0
  46. package/src/system-text.mjs +3 -0
  47. package/src/tech-usage.mjs +88 -0
  48. package/src/trajectory.mjs +264 -0
  49. package/src/wizard.mjs +411 -0
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@letsrebase/verify",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Work profile: build a tamper-evident, PII-redacted work profile from your coding-agent logs and send it to rebase for review.",
5
+ "type": "module",
6
+ "bin": {
7
+ "rebase-verify": "bin/rebase-verify.mjs"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "bin/",
14
+ "src/",
15
+ "share/",
16
+ ".claude/commands/",
17
+ "README.md",
18
+ "PRIVACY.md",
19
+ "SECURITY.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "test": "node --test test/*.test.mjs",
24
+ "lexicon": "node scripts/emit-tech-lexicon.mjs",
25
+ "practices": "node scripts/emit-practices.mjs"
26
+ },
27
+ "engines": {
28
+ "node": ">=20.12"
29
+ },
30
+ "license": "MIT",
31
+ "homepage": "https://github.com/letsrebase/verify",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/letsrebase/verify.git"
35
+ },
36
+ "dependencies": {
37
+ "@agentclientprotocol/sdk": "2.8.0",
38
+ "@clack/prompts": "1.9.0"
39
+ }
40
+ }
@@ -0,0 +1,224 @@
1
+ {
2
+ "notes": [
3
+ "rebase-verify reads each command up to its first 240 characters, so a check at the end of a long chained command can be missed.",
4
+ "Paths are compared lower-cased, with a backslash read as a forward slash, and are read relative to the project folder of the session, so a folder above the project named test or specs changes nothing.",
5
+ "Sessions with no time are left out, as they cannot be placed in a month.",
6
+ "Leading environment assignments and runner wrappers such as npx, uv run, python -m and pnpm exec are skipped before a command is matched.",
7
+ "Two runs count as the same check when their command words match: the words before the first flag or path, wrappers dropped, so a narrower run of the same check (pytest tests/a.py after pytest) is the same command.",
8
+ "A failed command that holds a check counts as a failed check, and in a chain such as npm test && git push the exit status cannot say which part failed, so the chain counts as its first check.",
9
+ "Options that list files or statistics instead of the diff, such as git diff --stat and --name-only, and git show <rev>:<path>, are not read as a diff appearing."
10
+ ],
11
+ "practices": [
12
+ {
13
+ "definition": "After the last file edit before a git commit, a check ran in the session: tests, a linter, a type check or a build.",
14
+ "denominator": "Sessions with a commit.",
15
+ "id": "checks_before_commit",
16
+ "method": "code"
17
+ },
18
+ {
19
+ "definition": "Both a source file and a test file were edited in the session.",
20
+ "denominator": "Sessions that edited a source file.",
21
+ "id": "tests_with_changes",
22
+ "method": "code"
23
+ },
24
+ {
25
+ "definition": "A check command (tests, a linter, a type check or a build) failed, files were edited, and then the same check succeeded in the session.",
26
+ "denominator": "Sessions where a check command failed.",
27
+ "id": "failure_reproduced_before_fix",
28
+ "method": "code"
29
+ },
30
+ {
31
+ "definition": "A planning step came before the first file edit in the session: plan mode, a task list, or writing a plan or spec file.",
32
+ "denominator": "Sessions with an edit.",
33
+ "id": "plan_before_edit",
34
+ "method": "code"
35
+ },
36
+ {
37
+ "definition": "Before a commit or a pull request, the diff appeared in the session (git diff, git show or gh pr diff), whoever asked for it; the session cannot show whether anyone read it.",
38
+ "denominator": "Sessions with a commit or a pull request.",
39
+ "id": "reviews_changes",
40
+ "method": "code"
41
+ },
42
+ {
43
+ "definition": "A design document (an ADR, RFC, spec or design file, by path) was written or edited in the session.",
44
+ "denominator": "Sessions with an edit.",
45
+ "id": "design_documents",
46
+ "method": "code"
47
+ },
48
+ {
49
+ "definition": "A dependency audit or a security scanner ran in the session.",
50
+ "denominator": "Sessions with an edit.",
51
+ "id": "security_checks",
52
+ "method": "code"
53
+ },
54
+ {
55
+ "definition": "asks for options or trade-offs before choosing one",
56
+ "id": "asks_for_alternatives",
57
+ "method": "model",
58
+ "negative": [
59
+ "Use Redis for the queue.",
60
+ "What does this function return when the list is empty?"
61
+ ],
62
+ "positive": [
63
+ "Before we pick a queue library, give me two or three options with their trade-offs.",
64
+ "Is there another way to do this besides a cron job? Compare them for me."
65
+ ],
66
+ "tone": "Tone, feelings, politeness and wording quality are never grounds for a yes."
67
+ },
68
+ {
69
+ "definition": "rejects or corrects what the agent proposed or did, and says why",
70
+ "id": "pushes_back_with_reason",
71
+ "method": "model",
72
+ "negative": [
73
+ "No, not like that.",
74
+ "Why did you choose a map here instead of a list?"
75
+ ],
76
+ "positive": [
77
+ "No, don't mock the database here: the bug was in the real query, so the test would hide it.",
78
+ "That rename breaks the public API for existing users, revert it."
79
+ ],
80
+ "tone": "Tone, feelings, politeness and wording quality are never grounds for a yes."
81
+ },
82
+ {
83
+ "definition": "states acceptance criteria, the expected behaviour, or the check that proves it",
84
+ "id": "states_done_criteria",
85
+ "method": "model",
86
+ "negative": [
87
+ "Make the export work.",
88
+ "Make sure it works properly when you are done."
89
+ ],
90
+ "positive": [
91
+ "Done when the export returns all rows and the integration test for empty results passes.",
92
+ "It should redirect to /login when the session expires; I'll check that by hand."
93
+ ],
94
+ "tone": "Tone, feelings, politeness and wording quality are never grounds for a yes."
95
+ },
96
+ {
97
+ "definition": "cuts, splits or defers part of the work explicitly",
98
+ "id": "limits_scope",
99
+ "method": "model",
100
+ "negative": [
101
+ "Do the backend and the UI and the docs.",
102
+ "Can you also look at the other files while you are there?"
103
+ ],
104
+ "positive": [
105
+ "Only do the backend for now; leave the UI for a separate change.",
106
+ "Skip the refactor, just fix the crash in this PR."
107
+ ],
108
+ "tone": "Tone, feelings, politeness and wording quality are never grounds for a yes."
109
+ }
110
+ ],
111
+ "rubric": "rebase-practices/v1",
112
+ "rules": {
113
+ "checks": [
114
+ "^(?:py\\.test|pytest)(?=\\s|$)",
115
+ "^ruff\\s+check(?=\\s|$)",
116
+ "^(?:mypy|pyright|flake8|pylint)(?=\\s|$)",
117
+ "^go\\s+(?:test|vet|build)(?=\\s|$)",
118
+ "^golangci-lint\\s+run(?=\\s|$)",
119
+ "^cargo\\s+(?:test|clippy|check|build|nextest)(?=\\s|$)",
120
+ "^(?:mvn|\\.\\/mvnw)\\s+(?:\\S+\\s+)*?(?:test|verify|package)(?=\\s|$)",
121
+ "^(?:gradle|\\.\\/gradlew)\\s+(?:\\S+\\s+)*?(?:test|check|build)(?=\\s|$)",
122
+ "^dotnet\\s+(?:test|build)(?=\\s|$)",
123
+ "^(?:\\.\\/)?(?:vendor\\/bin\\/)?(?:phpunit|phpstan|pest)(?=\\s|$)",
124
+ "^(?:bundle\\s+exec\\s+)?(?:rspec|rubocop)(?=\\s|$)",
125
+ "^tsc(?=\\s|$)",
126
+ "^(?:eslint|biome\\s+(?:check|lint|ci))(?=\\s|$)",
127
+ "^vitest(?=\\s|$)",
128
+ "^jest(?=\\s|$)",
129
+ "^(?:playwright|cypress)\\s+(?:test|run)(?=\\s|$)",
130
+ "^node\\s+(?:\\S+\\s+)*?--test(?=\\s|$)",
131
+ "^(?:npm|pnpm|yarn|bun)\\s+(?:run\\s+)?(?:test|tests|lint|typecheck|type-check|check|build|ci)(?=\\s|$)",
132
+ "^make\\s+(?:test|tests|check|lint|build|ci)(?=\\s|$)"
133
+ ],
134
+ "commit": [
135
+ "^git(?:\\s+(?:-C\\s+\\S+|-c\\s+\\S+|--no-pager))*\\s+commit(?=\\s|$)"
136
+ ],
137
+ "designPaths": [
138
+ "(?:^|\\/)adr\\/",
139
+ "(?:^|\\/)(?:rfcs\\/|docs\\/rfc\\/)",
140
+ "(?:^|\\/)docs\\/design\\/",
141
+ "(?:^|\\/)specs\\/",
142
+ "(?:^|\\/)(?:adr-[^/]*|[^/]*-adr\\.md)$",
143
+ "(?:^|\\/)rfc[^/]*$",
144
+ "(?:^|\\/)(?:[^/]*-design|design)\\.md$",
145
+ "(?:^|\\/)[^/]*-spec\\.md$"
146
+ ],
147
+ "diff": [
148
+ "^git(?:\\s+(?:-C\\s+\\S+|-c\\s+\\S+|--no-pager))*\\s+diff(?=\\s|$)(?!.*\\s--(?:stat|numstat|shortstat|name-only|name-status)\\b)",
149
+ "^git(?:\\s+(?:-C\\s+\\S+|-c\\s+\\S+|--no-pager))*\\s+show(?=\\s|$)(?!.*\\s--(?:stat|numstat|shortstat|name-only|name-status)\\b)(?!.*\\s[^\\s-]\\S*:\\S)",
150
+ "^gh\\s+pr\\s+diff(?=\\s|$)"
151
+ ],
152
+ "editTools": [
153
+ "Edit",
154
+ "Write",
155
+ "NotebookEdit",
156
+ "MultiEdit"
157
+ ],
158
+ "planPaths": [
159
+ "(?:^|\\/)plans\\/",
160
+ "(?:^|\\/)(?:[^/]*-plan|plan)\\.md$",
161
+ "(?:^|\\/)specs\\/",
162
+ "(?:^|\\/)[^/]*-spec\\.md$"
163
+ ],
164
+ "planningTools": [
165
+ "ExitPlanMode",
166
+ "TodoWrite"
167
+ ],
168
+ "pullRequest": [
169
+ "^gh\\s+pr\\s+create(?=\\s|$)"
170
+ ],
171
+ "security": [
172
+ "^(?:npm|pnpm|yarn|bun)\\s+audit(?=\\s|$)",
173
+ "^(?:pip-audit|safety\\s+check|bandit)(?=\\s|$)",
174
+ "^cargo\\s+(?:audit|deny)(?=\\s|$)",
175
+ "^(?:trivy|semgrep|gitleaks|trufflehog|snyk|grype|osv-scanner|brakeman|bundler-audit|govulncheck)(?=\\s|$)"
176
+ ],
177
+ "sourceExclusions": [
178
+ "\\.config\\.[^/]+$",
179
+ "\\.d\\.[cm]?ts$",
180
+ "(?:^|\\/)conftest\\.py$",
181
+ "(?:^|\\/)setup\\.py$",
182
+ "(?:^|\\/)docs\\/"
183
+ ],
184
+ "sourceExtensions": [
185
+ "js",
186
+ "mjs",
187
+ "cjs",
188
+ "jsx",
189
+ "ts",
190
+ "mts",
191
+ "cts",
192
+ "tsx",
193
+ "vue",
194
+ "svelte",
195
+ "py",
196
+ "go",
197
+ "rs",
198
+ "java",
199
+ "kt",
200
+ "kts",
201
+ "scala",
202
+ "rb",
203
+ "php",
204
+ "cs",
205
+ "c",
206
+ "cc",
207
+ "cpp",
208
+ "h",
209
+ "hpp",
210
+ "swift",
211
+ "m",
212
+ "dart",
213
+ "ex",
214
+ "exs",
215
+ "lua"
216
+ ],
217
+ "testPaths": [
218
+ "(?:^|\\/)(?:tests?|__tests__|spec)\\/",
219
+ "\\.(?:test|spec)\\.[^/]+$",
220
+ "_test\\.[^/]+$",
221
+ "(?:^|\\/)test_[^/]*\\.py$"
222
+ ]
223
+ }
224
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "$comment": "GENERATED — do not edit by hand. Source: src/digest.mjs labelVocabulary(), every technology label the stack detection can emit, sorted. Regenerate with `npm run lexicon`. Vendored verbatim by the rebase hub (projects/hub/packages/core/src/rebase_core/work_profiles/tech-labels.json), whose intake keeps a techUsage row only when its name is one of these.",
3
+ "labels": [
4
+ "Anthropic SDK",
5
+ "Cloudflare",
6
+ "Cloudinary",
7
+ "docx/mammoth",
8
+ "Drizzle",
9
+ "ElevenLabs",
10
+ "FastAPI",
11
+ "Firebase/Firestore",
12
+ "Framer Motion",
13
+ "Go",
14
+ "Google Gemini",
15
+ "Inngest (event-driven jobs)",
16
+ "Java",
17
+ "Kotlin",
18
+ "MDX",
19
+ "Next.js/React",
20
+ "NextAuth",
21
+ "OpenAI",
22
+ "PHP",
23
+ "Playwright (E2E)",
24
+ "Postgres",
25
+ "PostHog (analytics)",
26
+ "Prisma",
27
+ "Protobuf",
28
+ "Puppeteer (PDF)",
29
+ "pytest",
30
+ "Python",
31
+ "Radix UI",
32
+ "React Hook Form",
33
+ "React-PDF",
34
+ "Recharts",
35
+ "Resend (email)",
36
+ "Ruby",
37
+ "Rust",
38
+ "shadcn/ui",
39
+ "Shell",
40
+ "SQL",
41
+ "Strapi (headless CMS)",
42
+ "Stripe",
43
+ "Supabase",
44
+ "Svelte",
45
+ "Swift",
46
+ "Tailwind",
47
+ "Terraform",
48
+ "TipTap (rich text)",
49
+ "Turborepo (monorepo)",
50
+ "TypeScript",
51
+ "Vercel",
52
+ "Vite",
53
+ "Vitest",
54
+ "Vue",
55
+ "Zod"
56
+ ]
57
+ }
@@ -0,0 +1,62 @@
1
+ {
2
+ "$comment": "GENERATED — do not edit by hand. Source: src/groundedness.mjs TECH_LEXICON (TECH_NAMES + digest labelVocabulary(), splitTech-tokenised, stoplist-filtered). Regenerate with `npm run lexicon`. Vendored verbatim by play-new-dashboard (src/lib/apply-tech-lexicon.json) so the intake recompute extracts the same tech anchors.",
3
+ "tokens": [
4
+ "anthropic",
5
+ "brevo",
6
+ "cloudflare",
7
+ "cloudinary",
8
+ "docx",
9
+ "drizzle",
10
+ "elevenlabs",
11
+ "eslint",
12
+ "fastapi",
13
+ "firebase",
14
+ "firestore",
15
+ "framer",
16
+ "gemini",
17
+ "inngest",
18
+ "java",
19
+ "jest",
20
+ "kotlin",
21
+ "mammoth",
22
+ "mdx",
23
+ "next.js",
24
+ "nextauth",
25
+ "node",
26
+ "openai",
27
+ "php",
28
+ "playwright",
29
+ "postgres",
30
+ "posthog",
31
+ "prisma",
32
+ "protobuf",
33
+ "puppeteer",
34
+ "pytest",
35
+ "python",
36
+ "radix",
37
+ "react",
38
+ "react-pdf",
39
+ "recharts",
40
+ "resend",
41
+ "ruby",
42
+ "rust",
43
+ "sdk",
44
+ "shadcn",
45
+ "sql",
46
+ "strapi",
47
+ "stripe",
48
+ "supabase",
49
+ "svelte",
50
+ "swift",
51
+ "tailwind",
52
+ "terraform",
53
+ "tiptap",
54
+ "turborepo",
55
+ "typescript",
56
+ "vercel",
57
+ "vite",
58
+ "vitest",
59
+ "vue",
60
+ "zod"
61
+ ]
62
+ }
@@ -0,0 +1,225 @@
1
+ // Claude Code adapter: reads ~/.claude/projects/**/*.jsonl and normalises it
2
+ // into the shared session model consumed by fingerprint.mjs / forensics.mjs.
3
+ //
4
+ // Hashing runs on the RAW bytes (provenance manifest). Redaction of text runs
5
+ // here too, but only on human-readable fields — never on the structural fields
6
+ // the forensics depend on (timestamps, uuids, token usage).
7
+
8
+ import { readdirSync, readFileSync, statSync } from "node:fs";
9
+ import { join, relative } from "node:path";
10
+ import { createHash } from "node:crypto";
11
+ import { redactText, countRedactions } from "../redact.mjs";
12
+
13
+ const sha256 = (buf) => createHash("sha256").update(buf).digest("hex");
14
+ const shortHash = (s) => sha256(s).slice(0, 8);
15
+
16
+ // Canonicalise paths to POSIX separators. The path-based analysis downstream
17
+ // (repo clustering in digest.mjs, area extraction, skill/agent detection in
18
+ // agentic-literacy.mjs) is written against "/"; on Windows the logged paths
19
+ // use "\", so without this every path regex silently misses. cwdRaw is left
20
+ // untouched — it stays the real OS path used for local filesystem access.
21
+ const toPosix = (s) => (typeof s === "string" ? s.replace(/\\/g, "/") : s);
22
+ // Re-exported so other adapters (e.g. opencode) can reuse the same
23
+ // path canonicalisation instead of re-implementing it.
24
+ export { toPosix };
25
+
26
+ // Exported so other adapters (e.g. codex, pi) can reuse the same recursive
27
+ // .jsonl walk instead of re-implementing it.
28
+ export function* walk(dir) {
29
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
30
+ const full = join(dir, entry.name);
31
+ if (entry.isDirectory()) yield* walk(full);
32
+ else if (entry.isFile() && entry.name.endsWith(".jsonl")) yield full;
33
+ }
34
+ }
35
+
36
+ /** Pull the readable text out of a message.content that may be string or block array. */
37
+ function extractContent(content) {
38
+ const toolUses = [];
39
+ const toolResults = [];
40
+ let text = "";
41
+ let thinkingChars = 0;
42
+ let signatureChars = 0;
43
+
44
+ if (typeof content === "string") {
45
+ text = content;
46
+ } else if (Array.isArray(content)) {
47
+ for (const b of content) {
48
+ if (!b || typeof b !== "object") continue;
49
+ switch (b.type) {
50
+ case "text":
51
+ text += (b.text || "") + "\n";
52
+ break;
53
+ case "thinking":
54
+ // Redacted thinking exposes only a signature; use its length as a
55
+ // reasoning-depth proxy when the thinking text itself is withheld.
56
+ thinkingChars += (b.thinking || "").length;
57
+ signatureChars += (b.signature || "").length;
58
+ break;
59
+ case "tool_use": {
60
+ const inp = b.input || {};
61
+ toolUses.push({
62
+ id: b.id,
63
+ name: b.name,
64
+ path: toPosix(redactText(inp.file_path || inp.path || "")),
65
+ cmd: b.name === "Bash" ? redactText(String(inp.command || "").slice(0, 240)) : "",
66
+ q: redactText(String(inp.query || inp.url || "").slice(0, 200)),
67
+ });
68
+ break;
69
+ }
70
+ case "tool_result": {
71
+ const c = b.content;
72
+ const bytes =
73
+ typeof c === "string"
74
+ ? c.length
75
+ : Array.isArray(c)
76
+ ? c.reduce((n, x) => n + (x?.text?.length || 0), 0)
77
+ : 0;
78
+ toolResults.push({ forId: b.tool_use_id, isError: !!b.is_error, bytes });
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ return { text, thinkingChars, signatureChars, toolUses, toolResults };
85
+ }
86
+
87
+ export function readClaudeCode(root) {
88
+ const files = [];
89
+ const records = [];
90
+
91
+ for (const path of walk(root)) {
92
+ const buf = readFileSync(path);
93
+ const lines = buf.toString("utf8").split("\n").filter((l) => l.trim());
94
+ let malformed = 0;
95
+ const parsed = [];
96
+ for (const line of lines) {
97
+ try {
98
+ parsed.push(JSON.parse(line));
99
+ } catch {
100
+ malformed++;
101
+ }
102
+ }
103
+ const relPath = relative(root, path);
104
+ files.push({
105
+ relPath,
106
+ sha256: sha256(buf),
107
+ bytes: statSync(path).size,
108
+ lines: lines.length,
109
+ malformed,
110
+ });
111
+ for (const r of parsed) records.push({ ...r, _file: relPath });
112
+ }
113
+
114
+ // Group into sessions.
115
+ const sessions = new Map();
116
+ let redactionHits = 0;
117
+ let redactedChars = 0;
118
+ // Compaction summaries: when Claude Code asks the model to summarise the
119
+ // session, the assistant reply is a dense self-portrait of how that work
120
+ // went. We collect them here for the narrative step.
121
+ const compactionSummaries = [];
122
+ let lastUserWasCompactionRequest = false;
123
+
124
+ for (const r of records) {
125
+ const sid = r.sessionId;
126
+ if (!sid) continue;
127
+ if (!sessions.has(sid)) {
128
+ sessions.set(sid, {
129
+ source: "claude-code",
130
+ sessionId: sid,
131
+ projectLabel: r.cwd ? `project-${shortHash(r.cwd)}` : "project-unknown",
132
+ cwdRedacted: toPosix(redactText(r.cwd || "")),
133
+ cwdRaw: r.cwd || "", // local-only, for repo enrichment; never sent in the bundle
134
+
135
+ gitBranch: r.gitBranch,
136
+ cliVersions: new Set(),
137
+ models: new Set(),
138
+ messages: [],
139
+ chain: [], // {uuid, parentUuid, ts}
140
+ firstTs: null,
141
+ lastTs: null,
142
+ });
143
+ }
144
+ const s = sessions.get(sid);
145
+ if (r.version) s.cliVersions.add(r.version);
146
+ if (r.timestamp) {
147
+ if (!s.firstTs || r.timestamp < s.firstTs) s.firstTs = r.timestamp;
148
+ if (!s.lastTs || r.timestamp > s.lastTs) s.lastTs = r.timestamp;
149
+ }
150
+ // Backfill cwd from later records: many session-opening records
151
+ // (permission-mode, file-history-snapshot, summaries) carry no cwd, so
152
+ // the first message wins only if it actually has one. Without this fix
153
+ // sessions cluster as "unknown".
154
+ if (!s.cwdRaw && r.cwd) {
155
+ s.cwdRaw = r.cwd;
156
+ s.cwdRedacted = toPosix(redactText(r.cwd));
157
+ s.projectLabel = `project-${shortHash(r.cwd)}`;
158
+ }
159
+ if (!s.gitBranch && r.gitBranch) s.gitBranch = r.gitBranch;
160
+ if (r.uuid) s.chain.push({ uuid: r.uuid, parentUuid: r.parentUuid ?? null, ts: r.timestamp });
161
+
162
+ if ((r.type === "user" || r.type === "assistant") && r.message && typeof r.message === "object") {
163
+ const m = r.message;
164
+ if (m.model && m.model !== "<synthetic>") s.models.add(m.model);
165
+ const { text, thinkingChars, signatureChars, toolUses, toolResults } = extractContent(m.content);
166
+ redactionHits += countRedactions(text);
167
+ const textRedacted = redactText(text);
168
+ redactedChars += text.length - textRedacted.length;
169
+
170
+ // Catch compaction summaries: a user prompt that asks for a session
171
+ // summary followed by the assistant's reply. Already redacted.
172
+ if (r.type === "user" && /Your task is to create a detailed summary of the conversation/i.test(text)) {
173
+ lastUserWasCompactionRequest = true;
174
+ } else if (r.type === "assistant" && lastUserWasCompactionRequest) {
175
+ if (textRedacted.length > 200) compactionSummaries.push(textRedacted.slice(0, 3000));
176
+ lastUserWasCompactionRequest = false;
177
+ } else if (r.type === "user") {
178
+ lastUserWasCompactionRequest = false;
179
+ }
180
+ s.messages.push({
181
+ role: r.type,
182
+ ts: r.timestamp,
183
+ uuid: r.uuid,
184
+ parentUuid: r.parentUuid ?? null,
185
+ model: m.model || null,
186
+ messageId: m.id || null,
187
+ requestId: r.requestId || null,
188
+ textRedacted,
189
+ textLen: text.length,
190
+ thinkingChars,
191
+ signatureChars,
192
+ toolUses,
193
+ toolResults,
194
+ // Records that are not the person typing: sub-agent briefs, injected
195
+ // context, compaction summaries. Carried only when the log says so.
196
+ ...(r.isSidechain === true ? { isSidechain: true } : {}),
197
+ ...(r.isMeta === true ? { isMeta: true } : {}),
198
+ ...(r.isCompactSummary === true ? { isCompactSummary: true } : {}),
199
+ usage: m.usage
200
+ ? {
201
+ input: m.usage.input_tokens || 0,
202
+ output: m.usage.output_tokens || 0,
203
+ cacheRead: m.usage.cache_read_input_tokens || 0,
204
+ cacheCreate: m.usage.cache_creation_input_tokens || 0,
205
+ }
206
+ : null,
207
+ });
208
+ }
209
+ }
210
+
211
+ const sessionList = [...sessions.values()].map((s) => ({
212
+ ...s,
213
+ cliVersions: [...s.cliVersions],
214
+ models: [...s.models],
215
+ }));
216
+
217
+ return {
218
+ source: "claude-code",
219
+ root,
220
+ files,
221
+ sessions: sessionList,
222
+ compactionSummaries,
223
+ redaction: { hits: redactionHits, charsRemoved: redactedChars },
224
+ };
225
+ }