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: postinstall nudge to run graft init (silent in CI / when initialized)
Shrish Dwivedib53d4745da23
diff --git a/package.json b/package.jsonindex bba3d88a..534cf453 100644--- a/package.json+++ b/package.json@@ -38,6 +38,7 @@},"files": ["dist",+ "scripts","README.md","LICENSE"],@@ -48,7 +49,8 @@"bench": "tsx bench/run.ts","test": "node --import tsx --test test/*.test.ts","prepare": "npm run build",- "prepublishOnly": "npm run build"+ "prepublishOnly": "npm run build",+ "postinstall": "node scripts/postinstall.mjs"},"engines": {"node": ">=20"diff --git a/scripts/postinstall.mjs b/scripts/postinstall.mjsnew file mode 100644index 00000000..221237d8--- /dev/null+++ b/scripts/postinstall.mjs@@ -0,0 +1,11 @@+// Prints a one-line nudge after install. Never fails the install.+try {+ if (process.env.CI) process.exit(0);+ const { existsSync } = await import('node:fs');+ const { join } = await import('node:path');+ const dir = process.env.INIT_CWD || process.cwd();+ if (existsSync(join(dir, '.claude', 'helpers', 'graft-statusline.cjs'))) process.exit(0);+ console.log('\n Graft installed. Run `npx graft init` to enable the Claude Code integration (statusline + hooks + auto-sync).\n');+} catch {+ /* never fail an install */+}diff --git a/test/claude-init.test.ts b/test/claude-init.test.tsindex a63eafb2..76ca9e7f 100644--- a/test/claude-init.test.ts+++ b/test/claude-init.test.ts@@ -3,10 +3,18 @@ import assert from 'node:assert/strict';import { mkdtempSync, readFileSync, existsSync, writeFileSync, mkdirSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';+import { execFileSync } from 'node:child_process';import { runInit } from '../src/claude/init.js';function fresh(): string { return mkdtempSync(join(tmpdir(), 'graft-init-')); }+function runPostinstall(env: Record<string, string>): string {+ try {+ return execFileSync(process.execPath, ['scripts/postinstall.mjs'],+ { encoding: 'utf8', env: { ...process.env, ...env } });+ } catch { return ''; }+}+test('runInit scaffolds settings + both shims (build skipped)', () => {const d = fresh();const r = runInit(d, { build: false });@@ -37,3 +45,21 @@ test('runInit is idempotent', () => {const s = JSON.parse(readFileSync(join(d, '.claude', 'settings.json'), 'utf8'));assert.equal(s.hooks.PostToolUse.length, 1);});++test('postinstall prints the nudge in a fresh dir', () => {+ const d = fresh();+ const out = runPostinstall({ INIT_CWD: d, CI: '' });+ assert.match(out, /npx graft init/);+});++test('postinstall is silent when already initialized', () => {+ const d = fresh();+ runInit(d, { build: false });+ const out = runPostinstall({ INIT_CWD: d, CI: '' });+ assert.equal(out.trim(), '');+});++test('postinstall is silent under CI', () => {+ const out = runPostinstall({ INIT_CWD: fresh(), CI: '1' });+ assert.equal(out.trim(), '');+});