Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ jobs:
run: node scripts/ci/validate-hooks.js
continue-on-error: false

- name: Check adapter drift
run: node scripts/ci/check-adapter-drift.js
continue-on-error: false

- name: Validate commands
run: node scripts/ci/validate-commands.js
continue-on-error: false
Expand Down
4 changes: 2 additions & 2 deletions hooks/hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/session-start.js\""
"command": "node -e \"const fs=require('fs'),path=require('path'),os=require('os'),cp=require('child_process');const candidates=[process.env.CLAUDE_PLUGIN_ROOT,process.env.CLAUDE_PROJECT_DIR,process.cwd(),path.join(os.homedir(),'.claude','plugins','everything-claude-code'),path.join(os.homedir(),'.claude','plugins','ecc-universal')].filter(Boolean);let script='';for(const base of candidates){const p=path.join(base,'scripts','hooks','session-start.js');if(fs.existsSync(p)){script=p;break}}if(!script){console.error('[Hook] SessionStart resolver: session-start.js not found');process.exit(0)}const r=cp.spawnSync(process.execPath,[script],{stdio:'inherit'});process.exit(r.status??0)\""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict SessionStart resolver to plugin install paths

The new resolver now searches CLAUDE_PROJECT_DIR and process.cwd() before the known plugin directories, so when CLAUDE_PLUGIN_ROOT is unset it will execute any project-local scripts/hooks/session-start.js it finds first. In normal usage cwd is the user’s repo, so this can run unrelated or untrusted repository code at session start instead of the bundled hook, changing behavior and creating a code-execution risk tied to repository contents.

Useful? React with 👍 / 👎.

}
],
"description": "Load previous context and detect package manager on new session"
Expand Down Expand Up @@ -108,7 +108,7 @@
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/post-edit-format.js\""
}
],
"description": "Auto-format JS/TS files with Prettier after edits"
"description": "Auto-format JS/TS files after edits (auto-detects Biome or Prettier)"
},
{
"matcher": "Edit",
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"scripts/ci/",
"scripts/hooks/",
"scripts/lib/",
"scripts/sync/",
"scripts/setup-package-manager.js",
"scripts/skill-create-output.js",
"skills/",
Expand All @@ -75,7 +76,11 @@
"scripts": {
"postinstall": "echo '\\n ecc-universal installed!\\n Run: npx ecc-install typescript\\n Docs: https://github.com/affaan-m/everything-claude-code\\n'",
"lint": "eslint . && markdownlint '**/*.md' --ignore node_modules",
"test": "node scripts/ci/validate-agents.js && node scripts/ci/validate-commands.js && node scripts/ci/validate-rules.js && node scripts/ci/validate-skills.js && node scripts/ci/validate-hooks.js && node tests/run-all.js"
"test": "node scripts/ci/check-adapter-drift.js && node scripts/ci/validate-agents.js && node scripts/ci/validate-commands.js && node scripts/ci/validate-rules.js && node scripts/ci/validate-skills.js && node scripts/ci/validate-hooks.js && node tests/run-all.js",
"sync:commands": "node scripts/sync/sync-commands.js",
"sync:rules-skills": "node scripts/sync/sync-rules-skills.js",
"sync:adapters": "npm run sync:commands && npm run sync:rules-skills",
"sync:check": "node scripts/ci/check-adapter-drift.js"
},
"devDependencies": {
"@eslint/js": "^9.39.2",
Expand Down
22 changes: 22 additions & 0 deletions scripts/ci/check-adapter-drift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
/**
* CI guard: fail when adapter files drift from canonical sources.
*/

const { syncCommandAdapters } = require('../sync/sync-commands');
const { syncRulesAndSkills } = require('../sync/sync-rules-skills');

try {
const commandResult = syncCommandAdapters({ checkOnly: true });
const rulesSkillsResult = syncRulesAndSkills({ checkOnly: true });
const issueCount = commandResult.issues.length + rulesSkillsResult.issues.length;

if (issueCount > 0) {
process.exit(1);
}
console.log('Adapter drift check passed');
process.exit(0);
} catch (err) {
console.error(`ERROR: adapter drift check failed - ${err.message}`);
process.exit(1);
}
106 changes: 94 additions & 12 deletions scripts/hooks/post-edit-format.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,124 @@
#!/usr/bin/env node
/**
* PostToolUse Hook: Auto-format JS/TS files with Prettier after edits
* PostToolUse Hook: Auto-format JS/TS files after edits
*
* Cross-platform (Windows, macOS, Linux)
*
* Runs after Edit tool use. If the edited file is a JS/TS file,
* formats it with Prettier. Fails silently if Prettier isn't installed.
* auto-detects the project formatter (Biome or Prettier) by looking
* for config files, then formats accordingly.
* Fails silently if no formatter is found or installed.
*/

const { execFileSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const MAX_STDIN = 1024 * 1024; // 1MB limit
const JS_TS_FILE_REGEX = /\.(ts|tsx|js|jsx)$/;
let data = '';
process.stdin.setEncoding('utf8');

process.stdin.on('data', chunk => {
if (data.length < MAX_STDIN) {
data += chunk;
const remaining = MAX_STDIN - data.length;
data += chunk.substring(0, remaining);
}
});

function findProjectRoot(startDir) {
let dir = startDir;

while (dir !== path.dirname(dir)) {
if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
dir = path.dirname(dir);
}

return startDir;
}

function hasPrettierInPackageJson(dir) {
const pkgPath = path.join(dir, 'package.json');
if (!fs.existsSync(pkgPath)) return false;

try {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
return Object.prototype.hasOwnProperty.call(pkg, 'prettier');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Detect Prettier installation from dependencies

hasPrettierInPackageJson only checks for a top-level prettier config key, so projects that install Prettier in dependencies/devDependencies and rely on default formatting are treated as having no formatter. In that case detectFormatter returns null and the hook skips formatting entirely, which is a regression from the prior behavior that always attempted npx prettier --write for JS/TS edits.

Useful? React with 👍 / 👎.

} catch {
return false;
}
}

function detectFormatter(startDir) {
const biomeConfigs = ['biome.json', 'biome.jsonc'];
const prettierConfigs = [
'.prettierrc',
'.prettierrc.json',
'.prettierrc.js',
'.prettierrc.cjs',
'.prettierrc.mjs',
'.prettierrc.yml',
'.prettierrc.yaml',
'.prettierrc.toml',
'prettier.config.js',
'prettier.config.cjs',
'prettier.config.mjs'
];

let dir = startDir;
while (true) {
for (const cfg of biomeConfigs) {
if (fs.existsSync(path.join(dir, cfg))) return 'biome';
}

for (const cfg of prettierConfigs) {
if (fs.existsSync(path.join(dir, cfg))) return 'prettier';
}

if (hasPrettierInPackageJson(dir)) return 'prettier';

const parent = path.dirname(dir);
if (parent === dir) break;
dir = parent;
}

return null;
}

function getFormatterCommand(formatter, filePath) {
const npxBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';

if (formatter === 'biome') {
return { bin: npxBin, args: ['@biomejs/biome', 'format', '--write', filePath] };
}
if (formatter === 'prettier') {
return { bin: npxBin, args: ['prettier', '--write', filePath] };
}

return null;
}

process.stdin.on('end', () => {
try {
const input = JSON.parse(data);
const filePath = input.tool_input?.file_path;

if (filePath && /\.(ts|tsx|js|jsx)$/.test(filePath)) {
if (filePath && JS_TS_FILE_REGEX.test(filePath)) {
try {
// Use npx.cmd on Windows to avoid shell: true which enables command injection
const npxBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
execFileSync(npxBin, ['prettier', '--write', filePath], {
cwd: path.dirname(path.resolve(filePath)),
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 15000
});
const absFilePath = path.resolve(filePath);
const projectRoot = findProjectRoot(path.dirname(absFilePath));
const formatter = detectFormatter(projectRoot);
const cmd = getFormatterCommand(formatter, absFilePath);

if (cmd) {
execFileSync(cmd.bin, cmd.args, {
cwd: projectRoot,
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 15000
});
}
} catch {
// Prettier not installed, file missing, or failed — non-blocking
// Formatter not installed, file missing, or failed — non-blocking
}
}
} catch {
Expand Down
183 changes: 183 additions & 0 deletions scripts/sync/sync-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#!/usr/bin/env node
/**
* Sync command adapters from canonical root commands/.
*
* By default, writes updates into adapter targets.
* Use --check to report drift without writing.
*/

const fs = require('fs');
const path = require('path');

const ROOT_DIR = path.join(__dirname, '../..');
const SOURCE_DIR = path.join(ROOT_DIR, 'commands');

const TARGETS = [
{
name: 'cursor',
dir: path.join(ROOT_DIR, '.cursor/commands'),
excluded: new Set(),
overrides: new Set([
'build-fix.md',
'evolve.md',
'refactor-clean.md',
'test-coverage.md',
'update-codemaps.md',
'update-docs.md'
]),
extraAllowed: new Set()
},
{
name: 'opencode',
dir: path.join(ROOT_DIR, '.opencode/commands'),
excluded: new Set([
'multi-backend.md',
'multi-execute.md',
'multi-frontend.md',
'multi-plan.md',
'multi-workflow.md',
'pm2.md',
'python-review.md',
'sessions.md'
]),
overrides: new Set([
'build-fix.md',
'checkpoint.md',
'code-review.md',
'e2e.md',
'eval.md',
'evolve.md',
'go-build.md',
'go-review.md',
'go-test.md',
'instinct-export.md',
'instinct-import.md',
'instinct-status.md',
'learn.md',
'orchestrate.md',
'plan.md',
'refactor-clean.md',
'setup-pm.md',
'skill-create.md',
'tdd.md',
'test-coverage.md',
'update-codemaps.md',
'update-docs.md',
'verify.md'
]),
extraAllowed: new Set(['security.md'])
}
];

function readNormalized(filePath) {
return fs.readFileSync(filePath, 'utf8').replace(/\r\n/g, '\n');
}

function listMarkdownFiles(dir) {
if (!fs.existsSync(dir)) return [];
return fs.readdirSync(dir).filter(name => name.endsWith('.md')).sort();
}

function ensureDir(dir) {
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
}

function copyFile(sourcePath, targetPath) {
ensureDir(path.dirname(targetPath));
fs.copyFileSync(sourcePath, targetPath);
}

function syncTarget(target, sourceFiles, checkOnly) {
const issues = [];
const updates = [];
const expectedFiles = sourceFiles.filter(file => !target.excluded.has(file));
const expectedSet = new Set(expectedFiles);

for (const file of expectedFiles) {
const sourcePath = path.join(SOURCE_DIR, file);
const targetPath = path.join(target.dir, file);
const isOverride = target.overrides.has(file);

if (!fs.existsSync(targetPath)) {
if (isOverride || checkOnly) {
issues.push(`[${target.name}] missing command: ${file}`);
} else {
copyFile(sourcePath, targetPath);
updates.push(`[${target.name}] created ${file}`);
}
continue;
}

if (isOverride) continue;

const sourceContent = readNormalized(sourcePath);
const targetContent = readNormalized(targetPath);
if (sourceContent !== targetContent) {
if (checkOnly) {
issues.push(`[${target.name}] drift detected: ${file}`);
} else {
copyFile(sourcePath, targetPath);
updates.push(`[${target.name}] updated ${file}`);
}
}
}

const targetFiles = listMarkdownFiles(target.dir);
for (const file of targetFiles) {
const isExpected = expectedSet.has(file);
const isAllowedExtra = target.extraAllowed.has(file);
if (!isExpected && !isAllowedExtra) {
issues.push(`[${target.name}] unexpected adapter command: ${file}`);
}
}

return { issues, updates };
}

function syncCommandAdapters(options = {}) {
const { checkOnly = false } = options;

if (!fs.existsSync(SOURCE_DIR)) {
throw new Error(`commands directory not found: ${SOURCE_DIR}`);
}

const sourceFiles = listMarkdownFiles(SOURCE_DIR);
let allIssues = [];
let allUpdates = [];

for (const target of TARGETS) {
ensureDir(target.dir);
const result = syncTarget(target, sourceFiles, checkOnly);
allIssues = allIssues.concat(result.issues);
allUpdates = allUpdates.concat(result.updates);
}

if (allIssues.length > 0) {
for (const issue of allIssues) console.error(issue);
}

if (!checkOnly && allUpdates.length > 0) {
for (const update of allUpdates) console.log(update);
}

if (!checkOnly && allUpdates.length === 0 && allIssues.length === 0) {
console.log('Command adapters are already in sync.');
}

return { issues: allIssues, updates: allUpdates };
}

if (require.main === module) {
const checkOnly = process.argv.includes('--check');
const { issues } = syncCommandAdapters({ checkOnly });

if (issues.length > 0) {
process.exit(1);
}
process.exit(0);
}

module.exports = {
syncCommandAdapters
};

Loading
Loading