7 nye moduler:
- lib/util/result.mjs — Result-shape m/ ok/fail/combine helpers
- lib/util/frontmatter.mjs — håndruller YAML-frontmatter-parser (subset, zero deps)
- lib/parsers/plan-schema.mjs — v1.7 step-regex + forbidden-heading-deteksjon (Fase/Phase/Stage/Steg)
- lib/parsers/manifest-yaml.mjs — per-step Manifest YAML-ekstraksjon m/ regex-validering
- lib/parsers/project-discovery.mjs — finn brief/research/architecture/plan/progress i prosjektmappe
- lib/parsers/arg-parser.mjs — $ARGUMENTS for alle 4 commands m/ flag-schema
- lib/parsers/bash-normalize.mjs — løftet fra hooks/scripts/pre-bash-executor.mjs
6 test-filer (66 tester totalt) — alle grønn:
- frontmatter (CRLF/BOM, scalars, lister, indent-rejection)
- plan-schema (positive Step-form, negative Fase/Phase/Stage/Steg, numbering, slicing)
- manifest-yaml (extraction, parsing, regex-validering, missing-key detection)
- project-discovery (sortert research, architecture-detection, phase-requirements)
- arg-parser (boolean/valued/multi-value flags, kvotert positional, ukjente flag)
- bash-normalize (\${x}/\\\\evasion, ANSI-stripping, full canonicalize-pipeline)
Forbereder Wave 2 (validators) og Spor 1-wiring inn i commands.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
// lib/parsers/bash-normalize.mjs
|
|
// Bash-evasion normalization, lifted from hooks/scripts/pre-bash-executor.mjs.
|
|
//
|
|
// Source: ../../hooks/scripts/pre-bash-executor.mjs (lines 22-45) — verbatim
|
|
// extraction so the runtime hook and the test suite share one implementation.
|
|
// The hook still inlines a copy because it cannot import from outside the
|
|
// plugin distribution at this time; both copies must stay in sync.
|
|
|
|
/**
|
|
* Strip bash evasion techniques: empty quotes, ${} expansion, backslash splitting.
|
|
* Used to canonicalize a command before running denylist regex over it.
|
|
*/
|
|
export function normalizeBashExpansion(cmd) {
|
|
if (typeof cmd !== 'string' || cmd === '') return '';
|
|
|
|
let result = cmd
|
|
.replace(/''/g, '')
|
|
.replace(/""/g, '')
|
|
.replace(/\$\{(\w)\}/g, '$1')
|
|
.replace(/\$\{[^}]*\}/g, '')
|
|
.replace(/`\s*`/g, '');
|
|
|
|
let prev;
|
|
do {
|
|
prev = result;
|
|
result = result.replace(/(\w)\\(\w)/g, '$1$2');
|
|
} while (result !== prev);
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Strip ANSI escape codes and collapse whitespace.
|
|
*/
|
|
export function normalizeCommand(cmd) {
|
|
if (typeof cmd !== 'string') return '';
|
|
return cmd
|
|
.replace(/\x1B\[[0-9;]*m/g, '')
|
|
.replace(/\s+/g, ' ')
|
|
.trim();
|
|
}
|
|
|
|
/**
|
|
* Full canonicalization pipeline used by hooks before pattern matching.
|
|
*/
|
|
export function canonicalize(cmd) {
|
|
return normalizeCommand(normalizeBashExpansion(cmd));
|
|
}
|