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(hosts): host registry with home/repo detection probes
Shrish Dwivedifb1663d76477
diff --git a/src/hosts/registry.ts b/src/hosts/registry.tsnew file mode 100644index 00000000..9406c62c--- /dev/null+++ b/src/hosts/registry.ts@@ -0,0 +1,88 @@+/**+ * Registry of AI coding hosts Graft can write instructions for.+ * Adding a host = adding one entry here (plus a renderer if it needs+ * a new file format).+ *+ * kind: 'section' → upsert the fenced block into a shared file the user owns.+ * kind: 'owned' → graft owns the whole file; overwrite it each run.+ */+import { join } from 'node:path';+import { instructionBody, cursorRule, kiroSteering, windsurfRule } from './instructions.js';++export interface DetectProbe {+ home: string;+ repo: string;+ dirExists(path: string): boolean;+}++export interface HostTarget {+ id: string;+ name: string;+ kind: 'section' | 'owned';+ /** Target file, relative to the repo root. */+ relPath: string;+ content(): string;+ detect(probe: DetectProbe): boolean;+}++export const HOSTS: HostTarget[] = [+ {+ id: 'agents',+ name: 'AGENTS.md hosts (Codex-style CLIs, editors that read AGENTS.md)',+ kind: 'section',+ relPath: 'AGENTS.md',+ content: instructionBody,+ detect: (p) =>+ p.dirExists(join(p.home, '.codex')) ||+ p.dirExists(join(p.home, '.config', 'opencode')) ||+ p.dirExists(join(p.home, '.config', 'agents')),+ },+ {+ id: 'cursor',+ name: 'Cursor',+ kind: 'owned',+ relPath: join('.cursor', 'rules', 'graft.mdc'),+ content: cursorRule,+ detect: (p) => p.dirExists(join(p.home, '.cursor')) || p.dirExists(join(p.repo, '.cursor')),+ },+ {+ id: 'gemini',+ name: 'Gemini CLI',+ kind: 'section',+ relPath: 'GEMINI.md',+ content: instructionBody,+ detect: (p) => p.dirExists(join(p.home, '.gemini')),+ },+ {+ id: 'copilot',+ name: 'GitHub Copilot',+ kind: 'section',+ relPath: join('.github', 'copilot-instructions.md'),+ content: instructionBody,+ detect: (p) => p.dirExists(join(p.repo, '.github')),+ },+ {+ id: 'kiro',+ name: 'Kiro',+ kind: 'owned',+ relPath: join('.kiro', 'steering', 'graft.md'),+ content: kiroSteering,+ detect: (p) => p.dirExists(join(p.home, '.kiro')) || p.dirExists(join(p.repo, '.kiro')),+ },+ {+ id: 'windsurf',+ name: 'Windsurf',+ kind: 'owned',+ relPath: join('.windsurf', 'rules', 'graft.md'),+ content: windsurfRule,+ detect: (p) => p.dirExists(join(p.home, '.codeium', 'windsurf')) || p.dirExists(join(p.repo, '.windsurf')),+ },+];++export function hostIds(): string[] {+ return HOSTS.map((h) => h.id);+}++export function detectHosts(probe: DetectProbe): HostTarget[] {+ return HOSTS.filter((h) => h.detect(probe));+}diff --git a/test/hosts-registry.test.ts b/test/hosts-registry.test.tsnew file mode 100644index 00000000..64cde170--- /dev/null+++ b/test/hosts-registry.test.ts@@ -0,0 +1,44 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { mkdtempSync, mkdirSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { HOSTS, detectHosts, hostIds, type DetectProbe } from '../src/hosts/registry.js';+import { existsSync, statSync } from 'node:fs';++function probeFor(home: string, repo: string): DetectProbe {+ return {+ home, repo,+ dirExists: (p) => { try { return statSync(p).isDirectory(); } catch { return false; } },+ };+}+function fresh(): string { return mkdtempSync(join(tmpdir(), 'graft-registry-')); }++test('registry exposes the six phase-1 hosts', () => {+ assert.deepEqual(hostIds().sort(), ['agents', 'copilot', 'cursor', 'gemini', 'kiro', 'windsurf']);+ for (const h of HOSTS) {+ assert.ok(h.relPath.length > 0);+ assert.ok(h.content().length > 0);+ }+});++test('nothing detected on a bare machine and bare repo', () => {+ assert.deepEqual(detectHosts(probeFor(fresh(), fresh())), []);+});++test('home config dirs light up their hosts', () => {+ const home = fresh(); const repo = fresh();+ mkdirSync(join(home, '.cursor'));+ mkdirSync(join(home, '.gemini'));+ mkdirSync(join(home, '.codex'));+ const ids = detectHosts(probeFor(home, repo)).map((h) => h.id).sort();+ assert.deepEqual(ids, ['agents', 'cursor', 'gemini']);+});++test('repo-local markers also light up hosts', () => {+ const home = fresh(); const repo = fresh();+ mkdirSync(join(repo, '.github'));+ mkdirSync(join(repo, '.kiro'));+ const ids = detectHosts(probeFor(home, repo)).map((h) => h.id).sort();+ assert.deepEqual(ids, ['copilot', 'kiro']);+});