44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Shared shell content rules для router-gate v4 (§5.1 + §5.1.2).
|
|
* Используется Bash-гейтом (enforce-router-gate.mjs) и PowerShell-гейтом
|
|
* (enforce-powershell-gate.mjs). Без хук-I/O — чистые функции + чтение
|
|
* approve-решений из ~/.claude/runtime.
|
|
*/
|
|
import { readFileSync, existsSync } from 'fs';
|
|
import { join } from 'path';
|
|
import { homedir } from 'os';
|
|
|
|
// ── Path normalization (Stream A заглушка; реальная — path-normalization.mjs) ──
|
|
export function defaultPathNormalize(target) {
|
|
if (typeof target !== 'string') return '';
|
|
let t = target.trim().replace(/^['"]|['"]$/g, '');
|
|
t = t.replace(/\\/g, '/');
|
|
const home = homedir().replace(/\\/g, '/');
|
|
t = t.replace(/^~(?=\/|$)/, home);
|
|
return t;
|
|
}
|
|
|
|
// Минимальный protected-list (полный — gate-config.json, Stream C/G).
|
|
export const DEFAULT_PROTECTED_PATTERNS = [
|
|
/(^|\/)\.claude\/runtime\//i,
|
|
/(^|\/)\.claude\/settings(\.local)?\.json$/i,
|
|
/(^|\/)\.env(\.|$)/i,
|
|
/(^|\/)node_modules\//i,
|
|
/(^|\/)CLAUDE\.md$/i,
|
|
/Pravila_raboty_Claude/i,
|
|
/Plugin_stack_rules/i,
|
|
/Tooling_v8_3/i,
|
|
/(^|\/)memory\//i,
|
|
/(^|\/)tools\/dep-checksums\.json$/i,
|
|
/(^|\/)\.git\/hooks\//i,
|
|
/(^|\/)lefthook\.ya?ml$/i,
|
|
/(^|\/)\.gitleaks/i,
|
|
/(^|\/)\.npmrc$/i,
|
|
];
|
|
|
|
export function isProtectedPath(p, pathNormalize = defaultPathNormalize, patterns = DEFAULT_PROTECTED_PATTERNS) {
|
|
const n = pathNormalize(p);
|
|
if (!n) return false;
|
|
return patterns.some((re) => re.test(n));
|
|
} |