Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
fix(onboarding): teammates only from open branches, token lookup on a meaningful symbol
Shrish Dwivedi0f20d06db5d1
diff --git a/src/cloud/onboarding.ts b/src/cloud/onboarding.tsindex a1773d75..dcf9e634 100644--- a/src/cloud/onboarding.ts+++ b/src/cloud/onboarding.ts@@ -344,9 +344,17 @@ export function headlineOrder(files: string[]): string[] {return files.map((f, i) => ({ f, i, r: rank(f) })).sort((a, b) => a.r - b.r || a.i - b.i).map((x) => x.f);}+const COMMON_UTIL_NAMES = new Set(["cn", "utils", "index", "helpers", "main", "init", "config", "setup", "test"]);++/** Whether a symbol name is worth measuring a lookup on: at least 5 characters and not a common util name. */+export function meaningfulSymbol(name: string): boolean {+ return name.length >= 5 && !COMMON_UTIL_NAMES.has(name.toLowerCase());+}+/*** One real lookup on the code map, as an agent would make it: a question- * about the repo's most central symbol (most incoming edges) outside tests,+ * about the repo's most central symbol (most incoming edges, with a name of+ * 5+ characters that isn't a common util name) outside tests,* fixtures, vendored and generated code, answered with* the code inlined, and what that saved against reading the files it covers* whole. The next most central is tried when a lookup saves nothing (tiny@@ -358,7 +366,9 @@ export function tokensOnOneLookup(repo: string, opts: { contextDir?: string; triif (!graph) return null;// The most central symbols of the product code: tests, fixtures, vendored// and generated code only when there's nothing else.- const all = buildRepoMap(graph, { hotspots: 500 }).hotspots;+ // A name worth asking about: a short or generic one (`cn`, `utils`, `main`)+ // says nothing about the repo, so the example would be meaningless.+ const all = buildRepoMap(graph, { hotspots: 500 }).hotspots.filter((h) => meaningfulSymbol(h.name));const product = all.filter((h) => !notProductCode(h.path));const hubs = (product.length ? product : all).slice(0, Math.max(1, opts.tries ?? 5));for (const hub of hubs) {@@ -443,6 +453,21 @@ function git(repo: string, args: string[], timeout = 15_000): string | null {const BOT = /\[bot\]|^(dependabot|github-actions|renovate)\b/i;+/** Branches that are where work lands, not work in flight: nobody is "on" them. */+const INTEGRATION_BRANCH = /^(main|master|dev|develop|staging|production|release\/.+)$/;++/**+ * Whether a remote branch is open work by someone: not the remote's default+ * branch (`base`), not a shared integration branch, and not fully merged+ * already (its tip is an ancestor of `base`).+ */+export function openBranch(repo: string, base: string, ref: string): boolean {+ const name = ref.replace(/^origin\//, "");+ if (ref === base || name === base.replace(/^origin\//, "") || INTEGRATION_BRANCH.test(name)) return false;+ // `merge-base --is-ancestor` exits 0 when merged, 1 when not; git() returns null on a nonzero exit.+ return git(repo, ["merge-base", "--is-ancestor", ref, base]) === null;+}+/** Files `email` changed in the last `days` days on any branch, plus what's uncommitted here. */export function myRecentFiles(repo: string, email: string, days = 30): string[] {const out = new Set<string>(changedFiles(repo, undefined, 200));@@ -574,6 +599,7 @@ export function teammatesChecked(const out: TeammateSummary[] = [];for (const b of cache.branches) {if (now - b.at > days * 24 * 60 * 60 * 1000) continue;+ if (!openBranch(repo, cache.base, b.ref)) continue;const [name = "", email = ""] = (git(repo, ["log", "-1", "--format=%aN%x09%aE", b.ref]) ?? "").trim().split("\t");if (!name || BOT.test(name)) continue;if ((me && email.toLowerCase() === me) || (myName && name.toLowerCase() === myName)) continue;diff --git a/test/trail-connect.test.ts b/test/trail-connect.test.tsindex 0088044b..f33cedd2 100644--- a/test/trail-connect.test.ts+++ b/test/trail-connect.test.ts@@ -30,6 +30,8 @@ import {sessionsIn,shortBody,teammatesFromGit,+ meaningfulSymbol,+ openBranch,tokensOnOneLookup,} from "../src/cloud/onboarding.js";import { readCloud, writeCloud, type Cloud } from "../src/cloud/workspace.js";@@ -249,6 +251,25 @@ test("the lookup is about product code: a test helper everyone calls is passed oassert.equal(tokensOnOneLookup(onlyTests)?.symbol, "tmpRepo", "nothing else to measure: a test helper it is");});+test("the lookup skips short and generic names: cn has the most callers, the next eligible symbol is measured", async () => {+ const dir = mkdtempSync(join(tmpdir(), "connect-tokens-cn-"));+ const filler = Array.from({ length: 300 }, (_, i) => `export function helper${i}(x: number): number {\n return x * ${i} + ${i};\n}\n`).join("\n");+ writeFileSync(join(dir, "client.ts"), `export function retryDo(attempts: number): number {\n return attempts;\n}\n\n${filler}`);+ writeFileSync(join(dir, "cn.ts"), `export function cn(a: string): string {\n return a;\n}\n\n${filler}`);+ for (const f of ["a", "b"]) writeFileSync(join(dir, `${f}.ts`), `import { retryDo } from "./client";\nexport function use${f}() {\n return retryDo(4);\n}\n`);+ for (const f of ["c", "d", "e", "f", "g", "h"]) writeFileSync(join(dir, `${f}.ts`), `import { cn } from "./cn";\nexport function use${f}() {\n return cn("x");\n}\n`);+ await buildGraph(dir);+ const { buildRepoMap } = await import("../src/graph/map.js");+ const { loadGraphCached } = await import("../src/graph/load.js");+ const { contextDirFor } = await import("../src/context/node-file.js");+ assert.equal(buildRepoMap(loadGraphCached(contextDirFor(dir))!).hotspots[0]!.name, "cn", "cn is the most central symbol");+ const t = tokensOnOneLookup(dir);+ assert.ok(t);+ assert.equal(t.symbol, "retryDo");+ for (const n of ["cn", "utils", "index", "helpers", "main", "init", "config", "setup", "test", "Utils", "Main"]) assert.ok(!meaningfulSymbol(n), n);+ for (const n of ["retryDo", "client", "Handler"]) assert.ok(meaningfulSymbol(n), n);+});+test("the offline line names the Trail it tried once, and the command to connect later carries --server unless it's Trail cloud", () => {assert.equal(connectAgain("trail init", "TRL-7F2A-K9QD", "https://app.trailhq.com"), "trail init --connect TRL-7F2A-K9QD");assert.equal(connectAgain("trail init", "TRL-7F2A-K9QD", "https://dev.trailhq.com"), "trail init --connect TRL-7F2A-K9QD --server https://dev.trailhq.com");@@ -355,6 +376,42 @@ test("teammates: others' branches pushed in the last 14 days that change the filassert.ok(!JSON.stringify(got).includes("defaultRetryMax = 10"));});+test("teammates come only from open branches: not the default branch, integration branches or merged ones", () => {+ const { clone } = team();+ const me = clone("rushabh", "Rushabh Nagda");+ const ritu = clone("ritu", "Ritu N");+ const sumanth = clone("sumanth", "Sumanth S");+ const priya = clone("priya", "Priya R");+ const mina = clone("mina", "Mina M");+ // My own work, so the files that count are client.go and README.md.+ pushBranch(me, "rushabh/mine", { "client.go": "package retry\n// mine\n", "README.md": "# mine\n" }, "Mine");+ git(me, "checkout", "-q", "main");+ // Ritu's commit lands on main: merged, nobody's open work.+ git(ritu, "checkout", "-q", "main");+ writeFileSync(join(ritu, "client.go"), "package retry\n// ritu\n");+ git(ritu, "add", "-A");+ git(ritu, "-c", "user.name=Ritu N", "-c", "[email protected]", "commit", "-qm", "Ritu merged this");+ git(ritu, "push", "-q", "origin", "main");+ // Sumanth works on a long-lived dev branch, ahead of main (so not merged), and on a release branch.+ pushBranch(sumanth, "dev", { "client.go": "package retry\n// dev\n" }, "Dev work");+ pushBranch(sumanth, "release/1.2", { "README.md": "# release\n" }, "Release prep");+ pushBranch(sumanth, "staging", { "client.go": "package retry\n// staging\n" }, "Staging work");+ // Mina's feature branch is fully merged into main (an ancestor of it).+ git(mina, "fetch", "-q", "origin");+ git(mina, "checkout", "-q", "-b", "mina/done", "origin/main~0");+ git(mina, "push", "-q", "origin", "mina/done");+ // Priya has the one open feature branch.+ git(priya, "fetch", "-q", "origin");+ pushBranch(priya, "priya/feature", { "client.go": "package retry\n// priya\n" }, "Priya feature");+ git(me, "fetch", "-q", "origin");+ const got = teammatesFromGit(me);+ assert.deepEqual(got.map((t) => `${t.name} on ${t.branch}`), ["Priya R on priya/feature"], JSON.stringify(got));+ assert.ok(!openBranch(me, "origin/main", "origin/main"));+ assert.ok(!openBranch(me, "origin/main", "origin/dev"), "named like an integration branch");+ assert.ok(!openBranch(me, "origin/main", "origin/mina/done"), "merged");+ assert.ok(openBranch(me, "origin/main", "origin/priya/feature"));+});+test("with no history of your own here, teammates are matched on the repo's busiest files", () => {const { clone } = team();const kumar = clone("kumar", "Kumar S");