Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

feat(pair): send the token and team findings to the onboarding page

Shrish Dwivedi864042957325
diff --git a/src/cli.ts b/src/cli.ts
index 97a670b0..9623bbf6 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -1705,6 +1705,15 @@ async function runInitCommand(dir: string, opts: InitOptions, progress?: InitPro
});
}
+ // With --pair, one lookup measured against reading the files whole: the
+ // page's token step. It needs the map, so it follows the build.
+ let tokens: ReturnType<typeof tokensOnOneLookup> = null;
+ if (pair) {
+ pair.phase("tokens", "running", "", "Measuring one lookup against reading the files");
+ tokens = tokensOnOneLookup(repo, { contextDir: program.opts<GlobalOpts>().dir });
+ pair.phase("tokens", "done", tokens ? `${tokens.pct}% fewer` : "skipped", tokens ? `One lookup used ${tokens.pct}% fewer tokens than reading ${tokens.files} file${tokens.files === 1 ? "" : "s"}` : undefined);
+ }
+
if (!verbose) {
// Warnings and removals in full, whatever else is folded.
const removed = [...new Set(reports.flatMap((r) => r.retracted))];
@@ -1857,6 +1866,14 @@ async function runInitCommand(dir: string, opts: InitOptions, progress?: InitPro
// Hand what was found to the review page, and leave a child waiting for
// the person to connect and review there.
if (pair) {
+ // Teammates' branches on this person's files, checked against the
+ // learnings just saved and the repo's own: synchronous, so the finding
+ // exists before the page is told the read is done.
+ pair.phase("team", "running", "", "Checking your team's branches");
+ const teamNotes = listNotes(repo, { branches: false }).filter((n) => n.scope === "repo" && !n.ref);
+ const teammates = teammatesFromGit(repo, { learnings: teamNotes });
+ pair.phase("team", "done", `${teammates.length} ${teammates.length === 1 ? "person" : "people"}`);
+ pair.findings({ tokens, sessions: pastRead?.sessions, teammates });
await pair.finish(repo);
pair.handOff(repo);
console.error(`✓ Trail has what it found · review it in the browser: ${pair.url}`);
diff --git a/src/cloud/pair.ts b/src/cloud/pair.ts
index c53be9ee..eba96030 100644
--- a/src/cloud/pair.ts
+++ b/src/cloud/pair.ts
@@ -17,6 +17,7 @@ import { graftCliPath } from "../claude/paths.js";
import { noteAuthor } from "../notes/git-facts.js";
import { repoName, repoPlace } from "../notes/home.js";
import { newState, pickerRepos } from "./nudge.js";
+import type { TeammateSummary, TokensSummary } from "./onboarding.js";
import { dropActivity, learningsPayload, syncRepo } from "./workspace-sync.js";
import { claimHandoff, fetchMe, isError, postHandoffProgress, readCloud, registerHandoff, trailUrl, writeCloud, type Cloud } from "./workspace.js";
@@ -25,7 +26,7 @@ export function validPairCode(code: string): boolean {
return /^[A-Za-z0-9-]{6,64}$/.test(code.trim());
}
-export type PhaseId = "install" | "files" | "prs" | "decisions" | "learnings";
+export type PhaseId = "install" | "files" | "tokens" | "prs" | "decisions" | "team" | "learnings";
type PhaseStatus = "todo" | "running" | "done";
interface Phase {
id: PhaseId;
@@ -34,6 +35,17 @@ interface Phase {
count: string;
}
+/**
+ * What init found out beyond the learnings, for the onboarding page: one
+ * lookup's token saving, the sessions read, and teammates' branches on this
+ * person's files. An empty `teammates` list means "checked, none".
+ */
+export interface PairFindings {
+ tokens?: TokensSummary | null;
+ sessions?: number;
+ teammates?: TeammateSummary[];
+}
+
/** The most found learnings one progress call may carry. */
const FOUND_PER_CALL = 200;
@@ -57,8 +69,10 @@ export class PairRun {
this.phases = [
{ id: "install", label: "Install Trail-code", status: "done", count: version },
{ id: "files", label: "Map the code", status: "todo", count: "" },
+ { id: "tokens", label: "Measure one lookup", status: "todo", count: "" },
{ id: "prs", label: "Read pull request reviews", status: "todo", count: "" },
{ id: "decisions", label: "Read past Claude sessions", status: "todo", count: "" },
+ { id: "team", label: "Check your team's branches", status: "todo", count: "" },
{ id: "learnings", label: "Write learnings", status: "todo", count: "" },
];
}
@@ -94,6 +108,15 @@ export class PairRun {
this.send({ phases: this.phases, ...(log ? { log: [log] } : {}) });
}
+ /** Send what init found beyond the learnings; keys left undefined (or a null `tokens`) are left out. */
+ findings(f: PairFindings): void {
+ const out: Record<string, unknown> = {};
+ if (f.tokens) out.tokens = f.tokens;
+ if (f.sessions !== undefined) out.sessions = f.sessions;
+ if (f.teammates !== undefined) out.teammates = f.teammates;
+ this.send({ findings: out });
+ }
+
/** Hand over the repo's learnings for review, then say the read is done. */
finish(repo: string): Promise<void> {
const place = repoPlace(repo);
diff --git a/test/trail-pair.test.ts b/test/trail-pair.test.ts
index c1421f8f..5222aa21 100644
--- a/test/trail-pair.test.ts
+++ b/test/trail-pair.test.ts
@@ -14,6 +14,7 @@ import { join } from "node:path";
import { BRAND_ENV } from "../src/brand.js";
import { writeNote } from "../src/notes/notes.js";
import { finishPair, PairRun, validPairCode } from "../src/cloud/pair.js";
+import { teammatesFromGit } from "../src/cloud/onboarding.js";
import { readCloud } from "../src/cloud/workspace.js";
import { tmpRepo } from "./helpers.js";
@@ -137,3 +138,64 @@ test("an expired link stops the child without uploading", async () => {
assert.equal(outcome, "expired");
assert.equal(t.calls.some((c) => c.path === "/api/cli/learnings"), false);
});
+
+const progressCalls = (t: { calls: Call[] }) => t.calls.filter((c) => c.path === "/api/cli/handoffs/progress");
+const okTrail = () => fakeTrail((c) => (c.path === "/api/cli/handoffs" ? { status: 201, body: { url: "http://trail.test/connect?state=s" } } : { status: 202, body: {} }));
+
+test("phases include tokens and team in order", async () => {
+ freshHome();
+ const t = okTrail();
+ const run = await PairRun.start(repo(), "X4GM5OQU4NIA65ZR", { agent: "claude", version: "0.23.1", fetchImpl: t.fetch });
+ assert.ok(run instanceof PairRun);
+ await run.flush();
+ const phases = progressCalls(t)[0]!.body.phases as { id: string; label: string }[];
+ assert.deepEqual(phases.map((p) => p.id), ["install", "files", "tokens", "prs", "decisions", "team", "learnings"]);
+ assert.equal(phases.find((p) => p.id === "tokens")!.label, "Measure one lookup");
+ assert.equal(phases.find((p) => p.id === "team")!.label, "Check your team's branches");
+});
+
+test("findings ride on progress", async () => {
+ freshHome();
+ const dir = repo();
+ const t = okTrail();
+ const run = await PairRun.start(dir, "X4GM5OQU4NIA65ZR", { agent: "claude", version: "0.23.1", fetchImpl: t.fetch });
+ assert.ok(run instanceof PairRun);
+ run.findings({
+ tokens: { question: "how Do works", symbol: "Do", saved: 15392, pack: 2048, baseline: 17440, pct: 88, files: 3 },
+ sessions: 3,
+ teammates: [{ name: "Sam", email: "[email protected]", branch: "sam/retry", files: ["client.go"], change: "Raise retries to 10", pushed_at: "2026-10-21T14:20:00Z" }],
+ });
+ await run.finish(dir);
+ const withFindings = progressCalls(t).filter((c) => c.body.findings);
+ assert.equal(withFindings.length, 1);
+ const f = withFindings[0]!.body.findings as { tokens: { pct: number }; teammates: { branch: string }[]; sessions: number };
+ assert.equal(f.tokens.pct, 88);
+ assert.equal(f.teammates[0]!.branch, "sam/retry");
+ assert.equal(f.sessions, 3);
+});
+
+test("findings leave out what is undefined or null", async () => {
+ freshHome();
+ const t = okTrail();
+ const run = await PairRun.start(repo(), "X4GM5OQU4NIA65ZR", { agent: "claude", version: "0.23.1", fetchImpl: t.fetch });
+ assert.ok(run instanceof PairRun);
+ run.findings({ tokens: null, sessions: undefined, teammates: [] });
+ await run.flush();
+ const f = progressCalls(t).find((c) => c.body.findings)!.body.findings as Record<string, unknown>;
+ assert.deepEqual(Object.keys(f), ["teammates"]);
+ assert.deepEqual(f.teammates, []);
+});
+
+test("teammates absent on a repo without origin", async () => {
+ freshHome();
+ const dir = tmpRepo("pair-no-origin");
+ git(dir, ["init", "-q", "-b", "main"]);
+ assert.deepEqual(teammatesFromGit(dir), []);
+ const t = okTrail();
+ const run = await PairRun.start(repo(), "X4GM5OQU4NIA65ZR", { agent: "claude", version: "0.23.1", fetchImpl: t.fetch });
+ assert.ok(run instanceof PairRun);
+ run.findings({ teammates: [] });
+ await run.flush();
+ const f = progressCalls(t).find((c) => c.body.findings)!.body.findings as { teammates: unknown[] };
+ assert.deepEqual(f.teammates, []);
+});