Sed-pipeline (16 patterns, longest-match-first) sweeper residuelle ultra*-treff i prose, command-narrativ, agent-prompts, hook-kommentarer, doc-prosa. Pipeline-utvidelser fra V4-prompten: - BSD-syntax [[:<:]]ultra[[:>:]] istedenfor \bultra\b (BSD sed mangler \b) - 6 compound-patterns for ultraplan/ultraexecute/ultraresearch/ultrabrief/ ultrareview/ultracontinue uten -local-suffiks - ultra*-stats glob -> trek*-stats glob - Linje-eksklusjon redusert til ultra-cc-architect (Q8); session-state- eksklusjonen var over-protektiv - File-eksklusjon utvidet til settings.json, package.json, plugin.json, hele .claude/-treet (gitignored + V5-territorium) Q8-undantak holdt: architecture-discovery.mjs + project-discovery.mjs urort. Filnavn-konvensjon holdt: .session-state.local.json + *.local.* preservert. Manuell narrative-fix: tests/lib/agent-frontmatter.test.mjs linje 10 mangled "/ultra*-local" til "/voyage*-local" (ingen slik kommando finnes); korrigert til "/trek*". Residualer utenfor scope (V5 handterer): package.json + .claude-plugin/ plugin.json (Step 12-14 versjons-bump). .claude/* er gitignored spec-historikk med tilsiktet BEFORE/AFTER-narrativ. Part of voyage-rebrand session 3 (Wave 4 / Step 10). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
127 lines
3.2 KiB
JavaScript
127 lines
3.2 KiB
JavaScript
// lib/parsers/arg-parser.mjs
|
|
// Parse $ARGUMENTS strings for the four voyage commands.
|
|
//
|
|
// Each command has its own valid-flag set; passing flags from another command
|
|
// produces an `unknown_flags` array but does not error — the caller decides.
|
|
|
|
const FLAG_SCHEMA = {
|
|
trekbrief: {
|
|
boolean: ['--quick', '--fg'],
|
|
valued: [],
|
|
aliases: {},
|
|
},
|
|
trekresearch: {
|
|
boolean: ['--quick', '--local', '--external', '--fg'],
|
|
valued: ['--project'],
|
|
aliases: {},
|
|
},
|
|
trekplan: {
|
|
boolean: ['--quick', '--fg'],
|
|
valued: ['--project', '--brief', '--export', '--decompose'],
|
|
multi: ['--research'],
|
|
aliases: {},
|
|
},
|
|
trekexecute: {
|
|
boolean: ['--resume', '--dry-run', '--validate', '--fg'],
|
|
valued: ['--project', '--step', '--session'],
|
|
aliases: {},
|
|
},
|
|
trekreview: {
|
|
boolean: ['--quick', '--fg', '--dry-run', '--validate'],
|
|
valued: ['--project', '--since'],
|
|
aliases: {},
|
|
},
|
|
trekcontinue: {
|
|
boolean: ['--help', '--cleanup', '--confirm', '--dry-run'],
|
|
valued: [],
|
|
aliases: {},
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @param {string} argString Raw $ARGUMENTS as the command sees it.
|
|
* @param {keyof FLAG_SCHEMA} command
|
|
* @returns {{
|
|
* command: string,
|
|
* flags: Record<string, true | string | string[]>,
|
|
* positional: string[],
|
|
* unknown: string[],
|
|
* errors: Array<{code: string, message: string}>,
|
|
* }}
|
|
*/
|
|
export function parseArgs(argString, command) {
|
|
const schema = FLAG_SCHEMA[command];
|
|
if (!schema) {
|
|
return {
|
|
command,
|
|
flags: {},
|
|
positional: [],
|
|
unknown: [],
|
|
errors: [{ code: 'ARG_UNKNOWN_COMMAND', message: `Unknown command: ${command}` }],
|
|
};
|
|
}
|
|
|
|
const tokens = tokenize(argString);
|
|
const flags = {};
|
|
const positional = [];
|
|
const unknown = [];
|
|
const errors = [];
|
|
|
|
for (let i = 0; i < tokens.length; i++) {
|
|
const tok = tokens[i];
|
|
|
|
if (!tok.startsWith('--')) {
|
|
positional.push(tok);
|
|
continue;
|
|
}
|
|
|
|
if (schema.boolean.includes(tok)) {
|
|
flags[tok] = true;
|
|
continue;
|
|
}
|
|
|
|
if (schema.valued.includes(tok)) {
|
|
const next = tokens[i + 1];
|
|
if (next === undefined || next.startsWith('--')) {
|
|
errors.push({ code: 'ARG_MISSING_VALUE', message: `Flag ${tok} requires a value` });
|
|
} else {
|
|
flags[tok] = next;
|
|
i++;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (schema.multi && schema.multi.includes(tok)) {
|
|
const collected = [];
|
|
while (i + 1 < tokens.length && !tokens[i + 1].startsWith('--')) {
|
|
collected.push(tokens[i + 1]);
|
|
i++;
|
|
}
|
|
if (collected.length === 0) {
|
|
errors.push({ code: 'ARG_MISSING_VALUE', message: `Flag ${tok} requires at least one value` });
|
|
} else {
|
|
flags[tok] = collected;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
unknown.push(tok);
|
|
}
|
|
|
|
return { command, flags, positional, unknown, errors };
|
|
}
|
|
|
|
function tokenize(s) {
|
|
if (typeof s !== 'string') return [];
|
|
const trimmed = s.trim();
|
|
if (trimmed === '') return [];
|
|
const out = [];
|
|
const re = /"([^"]*)"|'([^']*)'|(\S+)/g;
|
|
let m;
|
|
while ((m = re.exec(trimmed)) !== null) {
|
|
out.push(m[1] !== undefined ? m[1] : m[2] !== undefined ? m[2] : m[3]);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export { FLAG_SCHEMA };
|