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
feat(trail): send the picked agents with the push (#494)
anirudhkumar-nanonets526639e5e248
diff --git a/src/app/history.ts b/src/app/history.tsindex 71e13e83..4cbbe530 100644--- a/src/app/history.ts+++ b/src/app/history.ts@@ -64,6 +64,10 @@ export interface RepoDigest {* rather than a field per kind, so adding a source is adding an entry. */sources: HistorySource[];auto_approve: boolean;+ /** The agents `graft init` wired this repo for (claude, cursor, agents, …).+ * Trail shows only the context files those agents read. Absent or empty+ * means "not known", and Trail then shows every kind. */+ agents?: string[];}/** Field separators inside one `git log` record. Chosen for being bytes no@@ -363,6 +367,7 @@ export function buildDigest(input: {symbols: HistorySymbol[];sources: HistorySource[];autoApprove: boolean;+ agents?: string[];}): RepoDigest {const byPath = new Map<string, string[]>();for (const s of input.symbols) {@@ -397,6 +402,7 @@ export function buildDigest(input: {symbols: input.symbols,sources: input.sources,auto_approve: input.autoApprove,+ ...(input.agents?.length ? { agents: input.agents } : {}),};}diff --git a/src/brain/push.ts b/src/brain/push.tsindex fefa2343..782b76c5 100644--- a/src/brain/push.ts+++ b/src/brain/push.ts@@ -37,6 +37,7 @@ import {readTestNames,} from "../app/sources.js";import type { GraphV1 } from "../graph/types.js";+import { readStamp, wiredHostIds } from "../upkeep.js";import { baseUrlFor, type BrainLink } from "./link.js";import { postDigestOnce, uploadDigest, type UploadCaps, type UploadOptions } from "./upload.js";@@ -272,10 +273,25 @@ export async function buildEarlyDigest(symbols: [],sources: budgetSources(readAgentInstructions(root)),autoApprove: true,+ agents: pickedAgents(root),});return { digest, threads };}+/**+ * The agents this repo is wired for — what `graft init` recorded plus what is on+ * disk, the same set `graft trail pull` filters by — so Trail can show only the+ * context files those agents read. Empty before the first init; Trail then+ * shows every kind.+ */+export function pickedAgents(root: string): string[] {+ try {+ return [...new Set([...(readStamp(root)?.hosts ?? []), ...wiredHostIds(root)])];+ } catch {+ return [];+ }+}+/** Send the early upload. Best-effort: false on any failure, and the full* upload still does everything. Gzipped when the server takes it. */export async function pushEarlyDigest(@@ -356,6 +372,7 @@ export async function buildLocalDigest(symbols,sources,autoApprove: opts.autoApprove ?? true,+ agents: pickedAgents(root),});return { digest, warning };}diff --git a/src/brain/signup.ts b/src/brain/signup.tsindex fe3f87e8..9f161d1e 100644--- a/src/brain/signup.ts+++ b/src/brain/signup.ts@@ -202,9 +202,12 @@ export function brainUrl(brainId: string, baseUrl?: string): string {return `${webBaseUrl(baseUrl)}/get-started?step=build&brain=${encodeURIComponent(brainId)}`;}-/** Where a trail's suggested context-file changes are reviewed and accepted. */+/** Where a trail's suggested context-file changes are reviewed and accepted:+ * the Context files overview, which lists every file the repo's agents read+ * (CLAUDE.md, AGENTS.md, Cursor rules, folder files, skills) with what waits+ * on each. Needs a Trail that has the page (NanoNets/assign#2957). */export function reviewUrl(brainId: string, baseUrl?: string): string {- return `${webBaseUrl(baseUrl)}/brain/${encodeURIComponent(brainId)}/claude-md`;+ return `${webBaseUrl(baseUrl)}/brain/${encodeURIComponent(brainId)}/context-files`;}/** Where to send the browser for a repo's brain. */diff --git a/test/brain-push-agents.test.ts b/test/brain-push-agents.test.tsnew file mode 100644index 00000000..1e5593fc--- /dev/null+++ b/test/brain-push-agents.test.ts@@ -0,0 +1,36 @@+/**+ * The push tells Trail which agents this repo is wired for, so its sidebar+ * shows only the context files those agents read — the same set `graft trail+ * pull` filters by. A repo that has never been wired sends none, and Trail then+ * shows every kind.+ */+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { mkdtempSync, mkdirSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { pickedAgents } from '../src/brain/push.js';+import { buildDigest } from '../src/app/history.js';++const empty = {+ owner: 'o', name: 'n', headSha: 'h', defaultBranch: 'main', isPrivate: false,+ commits: [], threads: [], symbols: [], sources: [], autoApprove: true,+};++test('an unwired repo sends no agents', () => {+ const repo = mkdtempSync(join(tmpdir(), 'graft-agents-'));+ assert.deepEqual(pickedAgents(repo), []);+ assert.equal('agents' in buildDigest({ ...empty, agents: pickedAgents(repo) }), false);+});++test('a repo wired for Claude Code and Cursor sends both', () => {+ const repo = mkdtempSync(join(tmpdir(), 'graft-agents-'));+ mkdirSync(join(repo, '.claude', 'helpers'), { recursive: true });+ writeFileSync(join(repo, '.claude', 'helpers', 'graft-hooks.cjs'), '');+ mkdirSync(join(repo, '.cursor', 'rules'), { recursive: true });+ writeFileSync(join(repo, '.cursor', 'rules', 'graft.mdc'), '---\n---\n');+ const agents = pickedAgents(repo);+ assert.ok(agents.includes('claude'));+ assert.ok(agents.includes('cursor'));+ assert.deepEqual(buildDigest({ ...empty, agents }).agents, agents);+});