@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.
- package/.claude/commands/rebase-verify.md +118 -0
- package/LICENSE +21 -0
- package/PRIVACY.md +113 -0
- package/README.md +209 -2
- package/SECURITY.md +33 -0
- package/bin/rebase-verify.mjs +699 -0
- package/package.json +38 -4
- package/share/practices.json +224 -0
- package/share/tech-labels.json +57 -0
- package/share/tech-lexicon.json +62 -0
- package/src/adapters/claude-code.mjs +225 -0
- package/src/adapters/codex.mjs +476 -0
- package/src/adapters/cursor.mjs +584 -0
- package/src/adapters/kimi.mjs +594 -0
- package/src/adapters/omp.mjs +59 -0
- package/src/adapters/opencode.mjs +439 -0
- package/src/adapters/pi.mjs +414 -0
- package/src/adapters/tool-vocab.mjs +15 -0
- package/src/agent-run.mjs +10 -0
- package/src/agentic-literacy.mjs +211 -0
- package/src/agents/acp.mjs +364 -0
- package/src/agents/json-answer.mjs +72 -0
- package/src/agents/registry.mjs +370 -0
- package/src/agents/run.mjs +131 -0
- package/src/ai-relationship.mjs +95 -0
- package/src/consistency.mjs +357 -0
- package/src/days.mjs +45 -0
- package/src/digest.mjs +501 -0
- package/src/distribution.mjs +54 -0
- package/src/enrich.mjs +118 -0
- package/src/fingerprint.mjs +134 -0
- package/src/forensics.mjs +178 -0
- package/src/groundedness.mjs +347 -0
- package/src/hub.mjs +136 -0
- package/src/intensity.mjs +132 -0
- package/src/live-status.mjs +79 -0
- package/src/practices-llm.mjs +90 -0
- package/src/practices-rules.mjs +295 -0
- package/src/practices-sample.mjs +111 -0
- package/src/practices.mjs +272 -0
- package/src/profile-llm.mjs +249 -0
- package/src/profile.mjs +497 -0
- package/src/redact.mjs +97 -0
- package/src/sources.mjs +91 -0
- package/src/submit.mjs +65 -0
- package/src/system-text.mjs +3 -0
- package/src/tech-usage.mjs +88 -0
- package/src/trajectory.mjs +264 -0
- package/src/wizard.mjs +411 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// pi (pi.dev) adapter: reads pi's per-project session logs
|
|
2
|
+
// (~/.pi/agent/sessions/<encoded-cwd>/<iso-ts>_<uuid>.jsonl, one file per
|
|
3
|
+
// session) and normalises them into the SAME session model claude-code.mjs,
|
|
4
|
+
// opencode.mjs and codex.mjs produce, so every downstream lens (digest,
|
|
5
|
+
// agentic-literacy, forensics, fingerprint, intensity, distribution) keeps
|
|
6
|
+
// working unchanged.
|
|
7
|
+
//
|
|
8
|
+
// The one structurally pleasant thing about pi's log format: every record
|
|
9
|
+
// already carries a real {id, parentId, timestamp: ISO}. Unlike codex (whose
|
|
10
|
+
// flat event stream has no per-message id and forces us to reconstruct
|
|
11
|
+
// TURNS ourselves), pi hands us the chain directly — so there is NO turn
|
|
12
|
+
// synthesis here. Every `type: "message"` record becomes exactly one entry
|
|
13
|
+
// in session.messages (role "user" | "assistant" | "toolResult"), uuid = the
|
|
14
|
+
// record's own id, parentUuid = its parentId, ts = its timestamp passed
|
|
15
|
+
// through as-is (already ISO). "toolResult" is its own record in pi (unlike
|
|
16
|
+
// Claude Code/opencode, where a tool result is a content BLOCK folded into
|
|
17
|
+
// the calling assistant message) — it becomes its own message row here too,
|
|
18
|
+
// carrying an empty toolUses and a single-element toolResults array, so the
|
|
19
|
+
// shared lenses (which iterate m.toolUses/m.toolResults unconditionally on
|
|
20
|
+
// every message, not just assistant ones — see digest.mjs/forensics.mjs)
|
|
21
|
+
// keep working without special-casing a third role.
|
|
22
|
+
//
|
|
23
|
+
// CRITICAL PRIVACY RULE: pi's model_change record carries `modelId`, which
|
|
24
|
+
// for local models can be a full filesystem path (e.g.
|
|
25
|
+
// "/Users/<name>/.cache/mlx/Qwen3-...") — the OS username lives right there
|
|
26
|
+
// in the model identifier, not in some free-text field an LLM pass might
|
|
27
|
+
// catch later. It is redacted with the same structural redactText() used for
|
|
28
|
+
// cwd, before it ever touches session.models or an assistant message's
|
|
29
|
+
// `model` field. This is the single most important privacy assertion in this
|
|
30
|
+
// adapter (see the "PRIVACY" test).
|
|
31
|
+
//
|
|
32
|
+
// No within-pi subagent rollup (compare opencode.mjs's applyRollup): 64 real
|
|
33
|
+
// sessions on this machine show no delegation/subagent tool at all. This is
|
|
34
|
+
// a deliberate scope cut, not an oversight — revisit if/when pi ships a
|
|
35
|
+
// Task-equivalent tool.
|
|
36
|
+
//
|
|
37
|
+
// FRAMEWORK-INJECTED USER TEXT is filtered per content block, same
|
|
38
|
+
// discipline codex.mjs uses for <environment_context>: pi's skill/attachment
|
|
39
|
+
// machinery re-injects file contents as a synthetic role-"user" text block
|
|
40
|
+
// wrapped ENTIRELY in <file name="...">...</file> (confirmed on a real
|
|
41
|
+
// session on this machine: a skill prompt file surfacing as a promptSample).
|
|
42
|
+
// A block survives only when its trimmed text is not fully wrapped
|
|
43
|
+
// start-to-end; a message where every block is wrapped (or which has none
|
|
44
|
+
// left) is skipped entirely — see extractUserMessageText below.
|
|
45
|
+
//
|
|
46
|
+
// Same structural-capture posture as the other adapters: thinking text, tool
|
|
47
|
+
// output, and compaction-summary overflow are reduced to lengths/booleans/
|
|
48
|
+
// truncated-and-redacted text, never kept in full — see redact.mjs and
|
|
49
|
+
// claude-code.mjs/opencode.mjs/codex.mjs for the shared contract this
|
|
50
|
+
// adapter has to honor.
|
|
51
|
+
|
|
52
|
+
import { readFileSync, existsSync, statSync } from "node:fs";
|
|
53
|
+
import { join, relative, basename, dirname } from "node:path";
|
|
54
|
+
import { homedir } from "node:os";
|
|
55
|
+
import { createHash } from "node:crypto";
|
|
56
|
+
import { redactText, countRedactions } from "../redact.mjs";
|
|
57
|
+
import { toPosix, walk } from "./claude-code.mjs";
|
|
58
|
+
import { AGENT_RUN_MARKER } from "../agent-run.mjs";
|
|
59
|
+
import { fallbackToolName } from "./tool-vocab.mjs";
|
|
60
|
+
|
|
61
|
+
const sha256 = (buf) => createHash("sha256").update(buf).digest("hex");
|
|
62
|
+
const shortHash = (s) => sha256(s).slice(0, 8);
|
|
63
|
+
|
|
64
|
+
// ── Default location ────────────────────────────────────────────────────────
|
|
65
|
+
// pi documents no env-var override for the sessions root (unlike CODEX_HOME
|
|
66
|
+
// or opencode's XDG chain) — --pi-root at the CLI layer is how an override
|
|
67
|
+
// gets applied, not this function. Stated honestly rather than inventing an
|
|
68
|
+
// env var pi doesn't support.
|
|
69
|
+
//
|
|
70
|
+
// The PARENT of sessions/ (auth.json, settings.json, models.json,
|
|
71
|
+
// models-store.json, trust.json — confirmed present on this machine) is
|
|
72
|
+
// never resolved or opened here; only the sessions subdirectory is walked.
|
|
73
|
+
export function defaultPiRoot() {
|
|
74
|
+
return join(homedir(), ".pi", "agent", "sessions");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── Tool vocabulary: pi → canonical (Claude Code) names ─────────────────────
|
|
78
|
+
// bash/edit/read/write/ls are the names actually observed across 64 real
|
|
79
|
+
// sessions on this machine (ls -> Read, matching opencode's list -> Read
|
|
80
|
+
// precedent). glob/grep/task/webfetch/websearch are documented but were never
|
|
81
|
+
// observed here; they're included only because opencode.mjs's TOOL_MAP maps
|
|
82
|
+
// the identical lowercase names, so if pi ever emits them they land on the
|
|
83
|
+
// same canonical name a different source would produce for the same action.
|
|
84
|
+
// Anything else (extension tools, the argument-less "Validation" tool seen in
|
|
85
|
+
// real data) falls through to fallbackToolName, unchanged when it has no
|
|
86
|
+
// "server_tool" shape.
|
|
87
|
+
const TOOL_MAP = {
|
|
88
|
+
bash: "Bash",
|
|
89
|
+
edit: "Edit",
|
|
90
|
+
read: "Read",
|
|
91
|
+
write: "Write",
|
|
92
|
+
ls: "Read",
|
|
93
|
+
glob: "Glob",
|
|
94
|
+
grep: "Grep",
|
|
95
|
+
task: "Task",
|
|
96
|
+
webfetch: "WebFetch",
|
|
97
|
+
websearch: "WebSearch",
|
|
98
|
+
};
|
|
99
|
+
function mapToolWith(map) {
|
|
100
|
+
return (name) => {
|
|
101
|
+
if (!name) return name;
|
|
102
|
+
if (map[name]) return map[name];
|
|
103
|
+
return fallbackToolName(name);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const piMapTool = mapToolWith(TOOL_MAP);
|
|
107
|
+
|
|
108
|
+
// toolCall.arguments is normally an object, but real data has at least one
|
|
109
|
+
// observed case of a non-object shape: a "Validation" call with
|
|
110
|
+
// `arguments: []`. Guard so a malformed/empty-array arguments never throws
|
|
111
|
+
// and just degrades to no path/cmd/q, same posture as codex's function_call
|
|
112
|
+
// argument guard.
|
|
113
|
+
function buildToolUse(id, name, rawArguments, mapTool) {
|
|
114
|
+
const args = rawArguments && typeof rawArguments === "object" && !Array.isArray(rawArguments) ? rawArguments : {};
|
|
115
|
+
const mapped = mapTool(name);
|
|
116
|
+
const path = toPosix(redactText(String(args.path || args.filePath || args.file_path || "")));
|
|
117
|
+
const cmd = mapped === "Bash" ? redactText(String(args.command || args.cmd || "").slice(0, 240)) : "";
|
|
118
|
+
const q = redactText(String(args.query || args.url || args.pattern || "").slice(0, 200));
|
|
119
|
+
return { id, name: mapped, path, cmd, q };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Assistant message content: {type:"thinking", thinking, thinkingSignature},
|
|
123
|
+
// {type:"text", text}, {type:"toolCall", id, name, arguments}. Thinking text
|
|
124
|
+
// and its signature are reduced to lengths only, exactly like Claude Code's
|
|
125
|
+
// redacted-thinking blocks and codex's reasoning summaries — never stored.
|
|
126
|
+
function reduceAssistantContent(content, mapTool) {
|
|
127
|
+
const toolUses = [];
|
|
128
|
+
let text = "";
|
|
129
|
+
let thinkingChars = 0;
|
|
130
|
+
let signatureChars = 0;
|
|
131
|
+
if (Array.isArray(content)) {
|
|
132
|
+
for (const b of content) {
|
|
133
|
+
if (!b || typeof b !== "object") continue;
|
|
134
|
+
switch (b.type) {
|
|
135
|
+
case "text":
|
|
136
|
+
text += (b.text || "") + "\n";
|
|
137
|
+
break;
|
|
138
|
+
case "thinking":
|
|
139
|
+
thinkingChars += (b.thinking || "").length;
|
|
140
|
+
signatureChars += (b.thinkingSignature || "").length;
|
|
141
|
+
break;
|
|
142
|
+
case "toolCall":
|
|
143
|
+
toolUses.push(buildToolUse(b.id, b.name, b.arguments, mapTool));
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { text, thinkingChars, signatureChars, toolUses };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Framework-injected content: pi's skill/attachment machinery re-sends file
|
|
152
|
+
// contents as a synthetic block wrapped ENTIRELY in <file name="...">...
|
|
153
|
+
// </file> (checked per content block — see extractUserMessageText below).
|
|
154
|
+
// The opening tag's attribute value varies per file, hence the regex; the
|
|
155
|
+
// closing tag is a fixed literal. Trimmed text must both match the open-tag
|
|
156
|
+
// pattern from its very start and end with the close tag, so a real block
|
|
157
|
+
// that merely mentions a <file name="..."> tag inline is never dropped.
|
|
158
|
+
const FILE_TAG_OPEN_RE = /^<file name="[^"]*">/;
|
|
159
|
+
const FILE_TAG_CLOSE = "</file>";
|
|
160
|
+
function isFrameworkWrapped(trimmed) {
|
|
161
|
+
return FILE_TAG_OPEN_RE.test(trimmed) && trimmed.endsWith(FILE_TAG_CLOSE);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// User message content: {type:"text", text} blocks only, per the observed
|
|
165
|
+
// shape, filtered per block: a block that survives contributes to the
|
|
166
|
+
// message exactly like the pre-filter extraction did; one that's
|
|
167
|
+
// framework-wrapped is dropped without contributing. Returns null when no
|
|
168
|
+
// block survives (all wrapped, or there were none) so the caller can skip
|
|
169
|
+
// the message entirely.
|
|
170
|
+
function extractUserMessageText(content) {
|
|
171
|
+
if (!Array.isArray(content)) return null;
|
|
172
|
+
let text = "";
|
|
173
|
+
let survived = 0;
|
|
174
|
+
for (const b of content) {
|
|
175
|
+
if (!b || typeof b !== "object" || b.type !== "text") continue;
|
|
176
|
+
const blockText = b.text || "";
|
|
177
|
+
if (isFrameworkWrapped(blockText.trim())) continue;
|
|
178
|
+
survived++;
|
|
179
|
+
text += blockText + "\n";
|
|
180
|
+
}
|
|
181
|
+
return survived > 0 ? text : null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// toolResult.content is an array of {type:"text", text} blocks; bytes is the
|
|
185
|
+
// sum of their .length — the shared `.length` (UTF-16 code units) convention
|
|
186
|
+
// every adapter uses for toolResults[].bytes. The text itself is never stored.
|
|
187
|
+
function toolResultBytes(content) {
|
|
188
|
+
if (!Array.isArray(content)) return 0;
|
|
189
|
+
return content.reduce((n, b) => n + (b && typeof b.text === "string" ? b.text.length : 0), 0);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// {input, output, cacheRead, cacheWrite} -> {input, output, cacheRead,
|
|
193
|
+
// cacheCreate} (RENAME only — cacheWrite is pi's name for the same thing
|
|
194
|
+
// claude-code/opencode call cacheCreate). Absent usage stays null so
|
|
195
|
+
// downstream's `if (m.usage)` gate behaves the same as every other adapter.
|
|
196
|
+
function buildUsage(u) {
|
|
197
|
+
if (!u || typeof u !== "object") return null;
|
|
198
|
+
return { input: u.input || 0, output: u.output || 0, cacheRead: u.cacheRead || 0, cacheCreate: u.cacheWrite || 0 };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Compaction noise floor + max length, mirrored EXACTLY from opencode.mjs's
|
|
202
|
+
// ingestMessage (200-char floor, 3000-char slice) so a "compaction summary"
|
|
203
|
+
// means the same thing regardless of which adapter produced it.
|
|
204
|
+
const COMPACTION_MIN_LEN = 200;
|
|
205
|
+
const COMPACTION_MAX_LEN = 3000;
|
|
206
|
+
|
|
207
|
+
// Directory name = cwd with "/" replaced by "-", wrapped in a leading and
|
|
208
|
+
// trailing "--" (e.g. "/Users/x/proj" -> "--Users-x-proj--"). LOSSY around
|
|
209
|
+
// literal hyphens in path segments (a project dir named "pn-stealth" is
|
|
210
|
+
// indistinguishable from two segments "pn"/"stealth" once decoded) — this is
|
|
211
|
+
// only ever used as a fallback when the session header line is missing or
|
|
212
|
+
// malformed; the header's own `cwd` field always wins when present.
|
|
213
|
+
const DIR_ENCODED_RE = /^--(.+)--$/;
|
|
214
|
+
function decodeDirCwd(dirName) {
|
|
215
|
+
const m = DIR_ENCODED_RE.exec(dirName);
|
|
216
|
+
if (!m || !m[1]) return "";
|
|
217
|
+
return "/" + m[1].replace(/-/g, "/");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// <iso-ish>_<uuid>.jsonl — pull the trailing uuid as a sessionId fallback for
|
|
221
|
+
// when the "session" header record is missing or fails to parse.
|
|
222
|
+
const FILENAME_UUID_RE = /_([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i;
|
|
223
|
+
function sessionIdFromFilename(path) {
|
|
224
|
+
const m = FILENAME_UUID_RE.exec(basename(path));
|
|
225
|
+
return m ? m[1] : basename(path, ".jsonl");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const EMPTY = (root, source = "pi") => ({
|
|
229
|
+
source,
|
|
230
|
+
root: root || null,
|
|
231
|
+
files: [],
|
|
232
|
+
sessions: [],
|
|
233
|
+
compactionSummaries: [],
|
|
234
|
+
redaction: { hits: 0, charsRemoved: 0 },
|
|
235
|
+
stats: { malformedLines: 0, projectDirCount: 0 },
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
export function readPi(root) {
|
|
239
|
+
return readPiFormat(root, { source: "pi" });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// pi's on-disk format is shared by oh-my-pi (omp), a pi fork. The omp adapter
|
|
243
|
+
// calls this with its own source label, tool-name mapper and file filter; real
|
|
244
|
+
// pi goes through readPi above with the defaults, behaviour unchanged.
|
|
245
|
+
export function readPiFormat(root, { source = "pi", mapTool = piMapTool, includeFile = () => true } = {}) {
|
|
246
|
+
if (!root || !existsSync(root)) return EMPTY(root, source);
|
|
247
|
+
|
|
248
|
+
const files = [];
|
|
249
|
+
const sessions = [];
|
|
250
|
+
let redactionHits = 0;
|
|
251
|
+
let redactedChars = 0;
|
|
252
|
+
const compactionSummaries = [];
|
|
253
|
+
let malformedLinesTotal = 0;
|
|
254
|
+
const projectDirs = new Set();
|
|
255
|
+
|
|
256
|
+
for (const path of walk(root)) {
|
|
257
|
+
if (!includeFile(relative(root, path))) continue;
|
|
258
|
+
const buf = readFileSync(path);
|
|
259
|
+
const relPath = relative(root, path);
|
|
260
|
+
const lines = buf.toString("utf8").split("\n").filter((l) => l.trim());
|
|
261
|
+
const records = [];
|
|
262
|
+
let malformed = 0;
|
|
263
|
+
for (const line of lines) {
|
|
264
|
+
try {
|
|
265
|
+
records.push(JSON.parse(line));
|
|
266
|
+
} catch {
|
|
267
|
+
malformed++;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
malformedLinesTotal += malformed;
|
|
271
|
+
|
|
272
|
+
const dirName = basename(dirname(path));
|
|
273
|
+
projectDirs.add(dirName);
|
|
274
|
+
|
|
275
|
+
const session = {
|
|
276
|
+
source,
|
|
277
|
+
sessionId: sessionIdFromFilename(path),
|
|
278
|
+
projectLabel: "project-unknown",
|
|
279
|
+
cwdRedacted: "",
|
|
280
|
+
cwdRaw: "", // local-only; never sent in the bundle
|
|
281
|
+
gitBranch: null, // pi does not record the branch
|
|
282
|
+
cliVersions: new Set(),
|
|
283
|
+
models: new Set(),
|
|
284
|
+
messages: [],
|
|
285
|
+
chain: [], // {uuid, parentUuid, ts}
|
|
286
|
+
firstTs: null,
|
|
287
|
+
lastTs: null,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
let currentModel = null;
|
|
291
|
+
|
|
292
|
+
const stampSessionTs = (ts) => {
|
|
293
|
+
if (!ts) return;
|
|
294
|
+
if (!session.firstTs || ts < session.firstTs) session.firstTs = ts;
|
|
295
|
+
if (!session.lastTs || ts > session.lastTs) session.lastTs = ts;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const setCwd = (cwd) => {
|
|
299
|
+
if (!cwd) return;
|
|
300
|
+
session.cwdRaw = cwd;
|
|
301
|
+
session.cwdRedacted = toPosix(redactText(cwd));
|
|
302
|
+
session.projectLabel = `project-${shortHash(cwd)}`;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// Emit one normalized message per record — no turn synthesis. uuid/
|
|
306
|
+
// parentUuid/ts come straight from the record's own id/parentId/
|
|
307
|
+
// timestamp (already ISO).
|
|
308
|
+
const emit = (role, r, text, extra = {}) => {
|
|
309
|
+
const ts = typeof r.timestamp === "string" ? r.timestamp : null;
|
|
310
|
+
const uuid = r.id;
|
|
311
|
+
const parentUuid = r.parentId ?? null;
|
|
312
|
+
|
|
313
|
+
redactionHits += countRedactions(text);
|
|
314
|
+
const textRedacted = redactText(text);
|
|
315
|
+
redactedChars += text.length - textRedacted.length;
|
|
316
|
+
|
|
317
|
+
session.messages.push({
|
|
318
|
+
role,
|
|
319
|
+
ts,
|
|
320
|
+
uuid,
|
|
321
|
+
parentUuid,
|
|
322
|
+
model: currentModel,
|
|
323
|
+
textRedacted,
|
|
324
|
+
textLen: text.length,
|
|
325
|
+
thinkingChars: extra.thinkingChars || 0,
|
|
326
|
+
signatureChars: extra.signatureChars || 0,
|
|
327
|
+
toolUses: extra.toolUses || [],
|
|
328
|
+
toolResults: extra.toolResults || [],
|
|
329
|
+
usage: extra.usage || null,
|
|
330
|
+
});
|
|
331
|
+
session.chain.push({ uuid, parentUuid, ts });
|
|
332
|
+
stampSessionTs(ts);
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
for (const r of records) {
|
|
336
|
+
if (!r || typeof r !== "object") continue;
|
|
337
|
+
|
|
338
|
+
switch (r.type) {
|
|
339
|
+
case "session": {
|
|
340
|
+
if (r.id) session.sessionId = r.id;
|
|
341
|
+
if (r.version != null) session.cliVersions.add(String(r.version));
|
|
342
|
+
setCwd(r.cwd);
|
|
343
|
+
if (typeof r.timestamp === "string") stampSessionTs(r.timestamp);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case "model_change": {
|
|
347
|
+
if (r.provider && r.modelId) {
|
|
348
|
+
// The privacy-critical line: modelId can be a full local
|
|
349
|
+
// filesystem path for local models (mlx-local et al.) — redact
|
|
350
|
+
// it exactly like a cwd before it ever lands in session.models
|
|
351
|
+
// or an assistant message's `model` field.
|
|
352
|
+
currentModel = `${r.provider}/${redactText(String(r.modelId))}`;
|
|
353
|
+
session.models.add(currentModel);
|
|
354
|
+
}
|
|
355
|
+
if (typeof r.timestamp === "string") stampSessionTs(r.timestamp);
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case "thinking_level_change":
|
|
359
|
+
break; // no structural content worth capturing
|
|
360
|
+
case "compaction": {
|
|
361
|
+
const summary = typeof r.summary === "string" ? r.summary : "";
|
|
362
|
+
redactionHits += countRedactions(summary);
|
|
363
|
+
const redacted = redactText(summary);
|
|
364
|
+
redactedChars += summary.length - redacted.length;
|
|
365
|
+
if (redacted.length > COMPACTION_MIN_LEN) compactionSummaries.push(redacted.slice(0, COMPACTION_MAX_LEN));
|
|
366
|
+
if (typeof r.timestamp === "string") stampSessionTs(r.timestamp);
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
case "message": {
|
|
370
|
+
const m = r.message;
|
|
371
|
+
if (!m || typeof m !== "object") break;
|
|
372
|
+
if (m.role === "user") {
|
|
373
|
+
const text = extractUserMessageText(m.content);
|
|
374
|
+
if (text === null) break; // fully framework-injected <file> dump: skip entirely
|
|
375
|
+
emit("user", r, text);
|
|
376
|
+
} else if (m.role === "assistant") {
|
|
377
|
+
const { text, thinkingChars, signatureChars, toolUses } = reduceAssistantContent(m.content, mapTool);
|
|
378
|
+
emit("assistant", r, text, { thinkingChars, signatureChars, toolUses, usage: buildUsage(m.usage) });
|
|
379
|
+
} else if (m.role === "toolResult") {
|
|
380
|
+
const bytes = toolResultBytes(m.content);
|
|
381
|
+
emit("toolResult", r, "", { toolResults: [{ forId: m.toolCallId, isError: !!m.isError, bytes }] });
|
|
382
|
+
}
|
|
383
|
+
// any other message.role: ignore, forward-compat
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
default:
|
|
387
|
+
break; // unknown record types: ignore, count nothing (forward compat)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Dir-name decode fallback: only when the session header never supplied
|
|
392
|
+
// a cwd (missing/malformed header line). The header always wins when
|
|
393
|
+
// present, even if the directory encodes a different path.
|
|
394
|
+
if (!session.cwdRaw) {
|
|
395
|
+
const decoded = decodeDirCwd(dirName);
|
|
396
|
+
// decodeDirCwd turns the marker's dashes into slashes, so a header-less
|
|
397
|
+
// transcript of one of our own runs keeps its encoded dir name instead.
|
|
398
|
+
if (decoded) setCwd(dirName.includes(AGENT_RUN_MARKER) ? dirName : decoded);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
files.push({ relPath, sha256: sha256(buf), bytes: statSync(path).size, lines: lines.length, malformed, cwdRaw: session.cwdRaw });
|
|
402
|
+
sessions.push({ ...session, cliVersions: [...session.cliVersions], models: [...session.models] });
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return {
|
|
406
|
+
source,
|
|
407
|
+
root,
|
|
408
|
+
files,
|
|
409
|
+
sessions,
|
|
410
|
+
compactionSummaries,
|
|
411
|
+
redaction: { hits: redactionHits, charsRemoved: redactedChars },
|
|
412
|
+
stats: { malformedLines: malformedLinesTotal, projectDirCount: projectDirs.size },
|
|
413
|
+
};
|
|
414
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Shared tool-name fallback: every adapter maps its own tool vocabulary onto
|
|
2
|
+
// the canonical Claude Code names (see opencode.mjs's TOOL_MAP), but names it
|
|
3
|
+
// doesn't recognise still need to land on the SAME "mcp__server__tool" shape.
|
|
4
|
+
// digest.mjs's MUTATION/RESEARCH/DELEGATION sets and agentic-literacy.mjs's
|
|
5
|
+
// MCP detection match exact canonical strings — if each adapter reinvented
|
|
6
|
+
// this rewrite, the string contract could fork source by source. One shared
|
|
7
|
+
// fallback keeps every adapter (opencode today; codex, pi tomorrow) honest.
|
|
8
|
+
export function fallbackToolName(name) {
|
|
9
|
+
if (!name) return name;
|
|
10
|
+
// Anything with a "server_tool" shape is an MCP tool; rewrite to the
|
|
11
|
+
// canonical mcp__server__tool so agentic-literacy's MCP detection lights up.
|
|
12
|
+
const us = name.indexOf("_");
|
|
13
|
+
if (us > 0) return `mcp__${name.slice(0, us)}__${name.slice(us + 1)}`;
|
|
14
|
+
return name;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// rebase-verify's own agent runs (narrative and classification turns) start in
|
|
2
|
+
// a fresh dir named with this marker; transcripts they leave in an agent's
|
|
3
|
+
// session store are never the person's work.
|
|
4
|
+
export const AGENT_RUN_MARKER = "rebase-verify-agent-run-";
|
|
5
|
+
|
|
6
|
+
// Matches a RAW cwd (or any path carrying it). Separate from
|
|
7
|
+
// digest.isEphemeral: os.tmpdir() is not under /tmp on every machine.
|
|
8
|
+
export function isAgentRun(cwd) {
|
|
9
|
+
return typeof cwd === "string" && cwd.includes(AGENT_RUN_MARKER);
|
|
10
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Agentic literacy: USES / BUILDS / DESIGNS — how comfortable the candidate is
|
|
2
|
+
// in the agentic stack, derived deterministically from their Claude Code logs.
|
|
3
|
+
//
|
|
4
|
+
// Privacy rule: NEVER expose names of custom skills, commands, or MCP servers.
|
|
5
|
+
// They can carry client / company / project information. We only export
|
|
6
|
+
// counts, with a binary classification built-in vs custom (whitelist-driven).
|
|
7
|
+
//
|
|
8
|
+
// Three axes:
|
|
9
|
+
// - USES: tool surface — sub-agent delegations, MCP calls, slash commands,
|
|
10
|
+
// skill/command invocations. Distinguishes "uses AI" from "barely uses AI".
|
|
11
|
+
// - BUILDS: files in .claude/ that the candidate has edited (skills,
|
|
12
|
+
// commands, hooks, project memory). Distinguishes "uses AI" from
|
|
13
|
+
// "builds with AI".
|
|
14
|
+
// - DESIGNS: structural patterns in how work is decomposed (ExitPlanMode,
|
|
15
|
+
// TodoWrite, AskUserQuestion). Captures planning style.
|
|
16
|
+
|
|
17
|
+
// ── Whitelists (built-in / public) ────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
// Tools shipped with Claude Code or otherwise standard. Anything outside
|
|
20
|
+
// this list, if it doesn't start with `mcp__`, is treated as a candidate
|
|
21
|
+
// custom tool — but in practice non-MCP tools are all built-in, so this is
|
|
22
|
+
// here for completeness.
|
|
23
|
+
const BUILTIN_TOOLS = new Set([
|
|
24
|
+
// file ops
|
|
25
|
+
"Read", "Write", "Edit", "MultiEdit", "NotebookEdit",
|
|
26
|
+
// shell
|
|
27
|
+
"Bash", "BashOutput", "KillBash",
|
|
28
|
+
// search
|
|
29
|
+
"Grep", "Glob",
|
|
30
|
+
// web
|
|
31
|
+
"WebSearch", "WebFetch",
|
|
32
|
+
// sub-agent
|
|
33
|
+
"Task", "Agent",
|
|
34
|
+
// planning / clarification
|
|
35
|
+
"ExitPlanMode", "TodoWrite", "AskUserQuestion",
|
|
36
|
+
// task system
|
|
37
|
+
"TaskCreate", "TaskUpdate", "TaskStop", "TaskGet", "TaskList", "TaskOutput",
|
|
38
|
+
// scheduling
|
|
39
|
+
"ScheduleWakeup", "CronCreate", "CronDelete", "CronList",
|
|
40
|
+
// worktrees / misc
|
|
41
|
+
"ToolSearch", "Monitor", "EnterPlanMode", "EnterWorktree", "ExitWorktree",
|
|
42
|
+
"ListMcpResourcesTool", "ReadMcpResourceTool", "RemoteTrigger", "SendMessage",
|
|
43
|
+
"PushNotification", "TeamCreate", "TeamDelete",
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
// Slash commands present in any vanilla Claude Code install.
|
|
47
|
+
const BUILTIN_SLASH = new Set([
|
|
48
|
+
"/login", "/exit", "/quit", "/clear", "/help", "/status", "/config", "/init",
|
|
49
|
+
"/mcp", "/memory", "/model", "/tokens", "/resume", "/compact", "/context",
|
|
50
|
+
"/cost", "/tools", "/add-dir", "/add-mcp", "/add-slash-command",
|
|
51
|
+
"/code-review", "/security-review", "/review", "/run", "/verify", "/loop",
|
|
52
|
+
"/schedule", "/simplify",
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
// MCP servers that ship publicly or are widely known integrations. The
|
|
56
|
+
// match is on the second segment of the tool name: `mcp__<server>__<tool>`.
|
|
57
|
+
const PUBLIC_MCP_SERVERS = new Set([
|
|
58
|
+
// Anthropic-hosted Claude.ai MCPs
|
|
59
|
+
"claude_ai_Linear", "claude_ai_Linear_2", "claude_ai_Notion", "claude_ai_Slack",
|
|
60
|
+
"claude_ai_GitHub", "claude_ai_Figma", "claude_ai_Gmail",
|
|
61
|
+
"claude_ai_Google_Calendar", "claude_ai_Google_Drive", "claude_ai_Canva",
|
|
62
|
+
"claude_ai_Miro", "claude_ai_Zapier", "claude_ai_PostHog", "claude_ai_LumaMCP",
|
|
63
|
+
"claude_ai_Windsor_ai",
|
|
64
|
+
// Plugin-shipped public MCPs
|
|
65
|
+
"plugin_supabase_supabase",
|
|
66
|
+
"nanobanana",
|
|
67
|
+
"ide",
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
// Non-Claude sources name the same public servers by their bare config key —
|
|
71
|
+
// opencode emits "github", "gmail", "supabase" (lowercase) where Claude Code
|
|
72
|
+
// records "claude_ai_GitHub" / "plugin_supabase_supabase". Normalise both to a
|
|
73
|
+
// bare lowercase key so the SAME public integration is bucketed public no matter
|
|
74
|
+
// which CLI logged it; otherwise an opencode GitHub MCP reads as a custom /
|
|
75
|
+
// proprietary server (over-reporting, and a cross-source disagreement on the
|
|
76
|
+
// identical tool). This only ever WIDENS public matching — it cannot mislabel a
|
|
77
|
+
// private server as public unless that server is named exactly like a well-known
|
|
78
|
+
// public one.
|
|
79
|
+
const normalizeServer = (s) =>
|
|
80
|
+
String(s).toLowerCase().replace(/^claude_ai_/, "").replace(/^plugin_[^_]+_/, "");
|
|
81
|
+
const PUBLIC_MCP_NORMALIZED = new Set([...PUBLIC_MCP_SERVERS].map(normalizeServer));
|
|
82
|
+
const isPublicServer = (server) =>
|
|
83
|
+
PUBLIC_MCP_SERVERS.has(server) || PUBLIC_MCP_NORMALIZED.has(normalizeServer(server));
|
|
84
|
+
|
|
85
|
+
// ── Helpers ───────────────────────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
function mcpServer(toolName) {
|
|
88
|
+
// mcp__<server>__<tool> — pick segment 2.
|
|
89
|
+
if (!toolName?.startsWith("mcp__")) return null;
|
|
90
|
+
const parts = toolName.split("__");
|
|
91
|
+
return parts[1] || null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Plugin slash commands look like /plugin:command (e.g. /playbook:build).
|
|
95
|
+
// They aren't strictly built-in but they aren't proprietary either; the
|
|
96
|
+
// safest call is to count them as custom (they may reveal an internal plugin
|
|
97
|
+
// the candidate uses, but the prefix can also be a private one).
|
|
98
|
+
function classifySlash(name) {
|
|
99
|
+
if (!name?.startsWith("/")) return "other";
|
|
100
|
+
if (BUILTIN_SLASH.has(name)) return "builtin";
|
|
101
|
+
return "custom";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const PROJECT_FILE_RE = /(?:^|\/)CLAUDE\.md$/;
|
|
105
|
+
const SKILL_RE = /\/\.claude\/skills?\/[^/]+\/(SKILL|skill)\.md$/;
|
|
106
|
+
const COMMAND_RE = /\/\.claude\/commands?\/[^/]+\.md$/;
|
|
107
|
+
const AGENT_RE = /\/\.claude\/agents?\/[^/]+\.md$/;
|
|
108
|
+
const HOOK_RE = /\/\.claude\/(hooks?|settings)\.?(json|md)?$/;
|
|
109
|
+
|
|
110
|
+
// ── Main ──────────────────────────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
export function computeAgenticLiteracy(parsed) {
|
|
113
|
+
// USES
|
|
114
|
+
let subagentCalls = 0;
|
|
115
|
+
let taskTrackingEvents = 0;
|
|
116
|
+
let askUserQuestion = 0;
|
|
117
|
+
let exitPlanMode = 0;
|
|
118
|
+
let todoWrite = 0;
|
|
119
|
+
let builtinSlashCount = 0;
|
|
120
|
+
const customSlashSet = new Set();
|
|
121
|
+
let customSlashInvocations = 0;
|
|
122
|
+
const publicMcpServers = new Set();
|
|
123
|
+
const customMcpServers = new Set();
|
|
124
|
+
const customMcpTools = new Set();
|
|
125
|
+
let customMcpCalls = 0;
|
|
126
|
+
let publicMcpCalls = 0;
|
|
127
|
+
|
|
128
|
+
// BUILDS
|
|
129
|
+
const skillsAuthored = new Set();
|
|
130
|
+
const commandsAuthored = new Set();
|
|
131
|
+
const agentsAuthored = new Set();
|
|
132
|
+
const hooksEdited = new Set();
|
|
133
|
+
const projectMemoryFiles = new Set();
|
|
134
|
+
|
|
135
|
+
// Slash commands appear in user messages wrapped in <command-name>foo</command-name>.
|
|
136
|
+
const SLASH_RE = /<command-name>(\/[\w:-]+)<\/command-name>/g;
|
|
137
|
+
|
|
138
|
+
for (const s of parsed.sessions ?? []) {
|
|
139
|
+
for (const m of s.messages ?? []) {
|
|
140
|
+
// Slash commands invoked
|
|
141
|
+
if (m.role === "user" && m.textRedacted) {
|
|
142
|
+
for (const match of m.textRedacted.matchAll(SLASH_RE)) {
|
|
143
|
+
const cmd = match[1];
|
|
144
|
+
if (classifySlash(cmd) === "builtin") builtinSlashCount++;
|
|
145
|
+
else {
|
|
146
|
+
customSlashSet.add(cmd);
|
|
147
|
+
customSlashInvocations++;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const u of m.toolUses ?? []) {
|
|
153
|
+
const name = u.name;
|
|
154
|
+
if (!name) continue;
|
|
155
|
+
|
|
156
|
+
// Built-in tool counts
|
|
157
|
+
if (name === "Task" || name === "Agent") subagentCalls++;
|
|
158
|
+
else if (name === "AskUserQuestion") askUserQuestion++;
|
|
159
|
+
else if (name === "ExitPlanMode") exitPlanMode++;
|
|
160
|
+
else if (name === "TodoWrite") todoWrite++;
|
|
161
|
+
else if (name === "TaskCreate" || name === "TaskUpdate") taskTrackingEvents++;
|
|
162
|
+
|
|
163
|
+
// MCP classification
|
|
164
|
+
const server = mcpServer(name);
|
|
165
|
+
if (server) {
|
|
166
|
+
if (isPublicServer(server)) {
|
|
167
|
+
publicMcpServers.add(server);
|
|
168
|
+
publicMcpCalls++;
|
|
169
|
+
} else {
|
|
170
|
+
customMcpServers.add(server);
|
|
171
|
+
customMcpTools.add(name);
|
|
172
|
+
customMcpCalls++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// File paths touched (BUILDS)
|
|
177
|
+
const fp = u.path || "";
|
|
178
|
+
if (fp) {
|
|
179
|
+
if (SKILL_RE.test(fp)) skillsAuthored.add(fp);
|
|
180
|
+
else if (COMMAND_RE.test(fp)) commandsAuthored.add(fp);
|
|
181
|
+
else if (AGENT_RE.test(fp)) agentsAuthored.add(fp);
|
|
182
|
+
else if (HOOK_RE.test(fp)) hooksEdited.add(fp);
|
|
183
|
+
else if (PROJECT_FILE_RE.test(fp)) projectMemoryFiles.add(fp);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
uses: {
|
|
191
|
+
subagentDelegations: subagentCalls,
|
|
192
|
+
taskTrackingEvents,
|
|
193
|
+
builtinSlashInvocations: builtinSlashCount,
|
|
194
|
+
customSkillsCommands: { distinct: customSlashSet.size, invocations: customSlashInvocations },
|
|
195
|
+
publicMcp: { servers: publicMcpServers.size, calls: publicMcpCalls },
|
|
196
|
+
customMcp: { servers: customMcpServers.size, tools: customMcpTools.size, calls: customMcpCalls },
|
|
197
|
+
},
|
|
198
|
+
builds: {
|
|
199
|
+
skillsAuthored: skillsAuthored.size,
|
|
200
|
+
commandsAuthored: commandsAuthored.size,
|
|
201
|
+
agentsAuthored: agentsAuthored.size,
|
|
202
|
+
hooksEdited: hooksEdited.size,
|
|
203
|
+
projectMemoryFiles: projectMemoryFiles.size,
|
|
204
|
+
},
|
|
205
|
+
designs: {
|
|
206
|
+
plansFirst: exitPlanMode,
|
|
207
|
+
subtaskTracking: todoWrite,
|
|
208
|
+
clarifies: askUserQuestion,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|