cc-safe-setup 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +88 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -86,6 +86,8 @@ const SHARE = process.argv.includes('--share');
|
|
|
86
86
|
const BENCHMARK = process.argv.includes('--benchmark');
|
|
87
87
|
const DASHBOARD = process.argv.includes('--dashboard');
|
|
88
88
|
const ISSUES = process.argv.includes('--issues');
|
|
89
|
+
const COMPARE_IDX = process.argv.findIndex(a => a === '--compare');
|
|
90
|
+
const COMPARE = COMPARE_IDX !== -1 ? { a: process.argv[COMPARE_IDX + 1], b: process.argv[COMPARE_IDX + 2] } : null;
|
|
89
91
|
const CREATE_IDX = process.argv.findIndex(a => a === '--create');
|
|
90
92
|
const CREATE_DESC = CREATE_IDX !== -1 ? process.argv.slice(CREATE_IDX + 1).join(' ') : null;
|
|
91
93
|
|
|
@@ -107,6 +109,7 @@ if (HELP) {
|
|
|
107
109
|
npx cc-safe-setup --audit --json Machine-readable output for CI/CD
|
|
108
110
|
npx cc-safe-setup --scan Detect tech stack, recommend hooks
|
|
109
111
|
npx cc-safe-setup --learn Learn from your block history
|
|
112
|
+
npx cc-safe-setup --compare <a> <b> Compare two hooks side-by-side
|
|
110
113
|
npx cc-safe-setup --issues Show GitHub Issues each hook addresses
|
|
111
114
|
npx cc-safe-setup --dashboard Real-time status dashboard
|
|
112
115
|
npx cc-safe-setup --benchmark Measure hook execution time
|
|
@@ -807,6 +810,90 @@ async function fullSetup() {
|
|
|
807
810
|
console.log();
|
|
808
811
|
}
|
|
809
812
|
|
|
813
|
+
async function compare(hookA, hookB) {
|
|
814
|
+
const { spawnSync } = await import('child_process');
|
|
815
|
+
const { statSync } = await import('fs');
|
|
816
|
+
|
|
817
|
+
console.log();
|
|
818
|
+
console.log(c.bold + ' cc-safe-setup --compare' + c.reset);
|
|
819
|
+
console.log();
|
|
820
|
+
|
|
821
|
+
if (!hookA || !hookB) {
|
|
822
|
+
console.log(c.red + ' Usage: npx cc-safe-setup --compare <hook-a.sh> <hook-b.sh>' + c.reset);
|
|
823
|
+
process.exit(1);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// Resolve paths
|
|
827
|
+
const resolveHook = (h) => {
|
|
828
|
+
if (existsSync(h)) return h;
|
|
829
|
+
const inHooks = join(HOOKS_DIR, h);
|
|
830
|
+
if (existsSync(inHooks)) return inHooks;
|
|
831
|
+
const inExamples = join(__dirname, 'examples', h);
|
|
832
|
+
if (existsSync(inExamples)) return inExamples;
|
|
833
|
+
return null;
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
const pathA = resolveHook(hookA);
|
|
837
|
+
const pathB = resolveHook(hookB);
|
|
838
|
+
|
|
839
|
+
if (!pathA) { console.log(c.red + ' Hook A not found: ' + hookA + c.reset); process.exit(1); }
|
|
840
|
+
if (!pathB) { console.log(c.red + ' Hook B not found: ' + hookB + c.reset); process.exit(1); }
|
|
841
|
+
|
|
842
|
+
const nameA = hookA.split('/').pop();
|
|
843
|
+
const nameB = hookB.split('/').pop();
|
|
844
|
+
|
|
845
|
+
// Test cases
|
|
846
|
+
const tests = [
|
|
847
|
+
{ name: 'empty input', input: '{}' },
|
|
848
|
+
{ name: 'safe command', input: '{"tool_input":{"command":"echo hello"}}' },
|
|
849
|
+
{ name: 'rm -rf /', input: '{"tool_input":{"command":"rm -rf /"}}' },
|
|
850
|
+
{ name: 'rm -rf ~', input: '{"tool_input":{"command":"rm -rf ~"}}' },
|
|
851
|
+
{ name: 'git push main', input: '{"tool_input":{"command":"git push origin main"}}' },
|
|
852
|
+
{ name: 'git push --force', input: '{"tool_input":{"command":"git push --force"}}' },
|
|
853
|
+
{ name: 'git add .env', input: '{"tool_input":{"command":"git add .env"}}' },
|
|
854
|
+
{ name: 'git reset --hard', input: '{"tool_input":{"command":"git reset --hard"}}' },
|
|
855
|
+
{ name: 'npm test', input: '{"tool_input":{"command":"npm test"}}' },
|
|
856
|
+
{ name: 'cd && git log', input: '{"tool_input":{"command":"cd /tmp && git log"}}' },
|
|
857
|
+
];
|
|
858
|
+
|
|
859
|
+
function runHook(path, input) {
|
|
860
|
+
const start = process.hrtime.bigint();
|
|
861
|
+
const result = spawnSync('bash', [path], { input, timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
862
|
+
const ms = Number(process.hrtime.bigint() - start) / 1_000_000;
|
|
863
|
+
return { exit: result.status ?? -1, ms, stderr: (result.stderr || Buffer.alloc(0)).toString().slice(0, 80) };
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// Header
|
|
867
|
+
console.log(' ' + c.bold + 'Test'.padEnd(20) + nameA.padEnd(25) + nameB + c.reset);
|
|
868
|
+
console.log(' ' + '-'.repeat(65));
|
|
869
|
+
|
|
870
|
+
let sameCount = 0;
|
|
871
|
+
let diffCount = 0;
|
|
872
|
+
|
|
873
|
+
for (const test of tests) {
|
|
874
|
+
const a = runHook(pathA, test.input);
|
|
875
|
+
const b = runHook(pathB, test.input);
|
|
876
|
+
const same = a.exit === b.exit;
|
|
877
|
+
if (same) sameCount++; else diffCount++;
|
|
878
|
+
|
|
879
|
+
const exitA = a.exit === 0 ? c.green + 'allow' + c.reset : a.exit === 2 ? c.red + 'BLOCK' + c.reset : c.yellow + 'err' + a.exit + c.reset;
|
|
880
|
+
const exitB = b.exit === 0 ? c.green + 'allow' + c.reset : b.exit === 2 ? c.red + 'BLOCK' + c.reset : c.yellow + 'err' + b.exit + c.reset;
|
|
881
|
+
const marker = same ? ' ' : c.yellow + '≠' + c.reset;
|
|
882
|
+
|
|
883
|
+
console.log(' ' + marker + ' ' + test.name.padEnd(18) + (exitA + ' ' + a.ms.toFixed(0) + 'ms').padEnd(30) + exitB + ' ' + b.ms.toFixed(0) + 'ms');
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// Size comparison
|
|
887
|
+
const sizeA = statSync(pathA).size;
|
|
888
|
+
const sizeB = statSync(pathB).size;
|
|
889
|
+
|
|
890
|
+
console.log(' ' + '-'.repeat(65));
|
|
891
|
+
console.log(' Same decisions: ' + sameCount + '/' + tests.length);
|
|
892
|
+
if (diffCount > 0) console.log(' ' + c.yellow + 'Different: ' + diffCount + c.reset);
|
|
893
|
+
console.log(' Size: ' + nameA + ' ' + sizeA + 'B vs ' + nameB + ' ' + sizeB + 'B');
|
|
894
|
+
console.log();
|
|
895
|
+
}
|
|
896
|
+
|
|
810
897
|
function issues() {
|
|
811
898
|
// Map hooks to the GitHub Issues they address
|
|
812
899
|
const ISSUE_MAP = [
|
|
@@ -2327,6 +2414,7 @@ async function main() {
|
|
|
2327
2414
|
if (FULL) return fullSetup();
|
|
2328
2415
|
if (DOCTOR) return doctor();
|
|
2329
2416
|
if (WATCH) return watch();
|
|
2417
|
+
if (COMPARE) return compare(COMPARE.a, COMPARE.b);
|
|
2330
2418
|
if (ISSUES) return issues();
|
|
2331
2419
|
if (DASHBOARD) return dashboard();
|
|
2332
2420
|
if (BENCHMARK) return benchmark();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safe-setup",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "One command to make Claude Code safe for autonomous operation. 8 built-in + 39 examples. 23 commands including dashboard, issues, create, audit, lint, diff. 260 tests. 2,500+ daily npm downloads.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"bin": {
|