Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230//region Worktree-enforcement escape hatch constants
/** Wrapper-only flag that suppresses linked-worktree enforcement for one guarded invocation. Stripped before forwarding to real git, which would otherwise reject it. */export const WORKTREE_ENFORCEMENT_ESCAPE_HATCH = '--no-enforce-worktree';
/** Wrapper-only flag that skips ignored-state synchronization into worktrees created by one invocation. Stripped before forwarding to real git, which would otherwise reject it. */export const WORKTREE_COPY_ESCAPE_HATCH = '--no-worktree-copy';
/** Pathspec separator after which git treats every remaining token as a path. Wrapper-only options are not recognised past this token. */export const PATHSPEC_SEPARATOR = '--';
//endregion Worktree-enforcement escape hatch constants
//region Escape hatch token stripping
/** Options for stripping the escape hatch from post-subcommand argv. */type StripEscapeHatchOptions = { /** Complete git argv. */ readonly args: readonly string[]; /** Index where guarded subcommand appears. */ readonly subcommandIndex: number; /** Options that consume next argv token as value. */ readonly separateValueOptions: ReadonlySet<string>; /** Wrapper-only token removed from flag positions. */ readonly escapeHatchToken: string;};
/** Removes flag-position escape-hatch tokens from the post-subcommand region. Tokens that sit in the value position of a separated-value option are preserved so the resulting argv is forwarded with values intact. Pathspec tokens past {@link PATHSPEC_SEPARATOR} are preserved verbatim. Optique handles the detection upstream by parsing each guarded subcommand's post-region with arity-aware option declarations; this helper only does the destructive token removal, via {@link filterFlagEscapeHatch}, that the parsed result cannot express directly. @param args - Complete git argv. @param subcommandIndex - Index where guarded subcommand appears. @param separateValueOptions - Options whose next argv token is value. @param escapeHatchToken - Wrapper-only token removed from flag positions. @returns Git argv with flag-position escape-hatch tokens removed. @example ```ts stripEscapeHatch({ args: ['stash', '--no-enforce-worktree', 'list'], subcommandIndex: 0, separateValueOptions: new Set(), escapeHatchToken: '--no-enforce-worktree', }); // => ['stash', 'list'] ``` */export function stripEscapeHatch({ args, subcommandIndex, separateValueOptions, escapeHatchToken,}: StripEscapeHatchOptions,): readonly string[] { /** Pre-subcommand region and subcommand kept verbatim so global options survive the strip. */ const preAndSubcommand = args.slice( 0, subcommandIndex + 1, ); /** Slice of args strictly after guarded subcommand. */ const postSubcommandArgs = args.slice(subcommandIndex + 1,); /** Position of pathspec separator inside post-subcommand region. */ const separatorIndex = postSubcommandArgs.indexOf(PATHSPEC_SEPARATOR,);
if (separatorIndex === (-1)) { return [ ...preAndSubcommand, ...filterFlagEscapeHatch({ args: postSubcommandArgs, separateValueOptions, escapeHatchToken, },), ]; }
/** Region before pathspec separator where wrapper-only options are recognized. */ const wrapperArgs = postSubcommandArgs.slice( 0, separatorIndex, ); /** Pathspec separator and user path text preserved verbatim. */ const pathspecArgs = postSubcommandArgs.slice(separatorIndex,);
return [ ...preAndSubcommand, ...filterFlagEscapeHatch({ args: wrapperArgs, separateValueOptions, escapeHatchToken, },), ...pathspecArgs, ];}
/** Options for the arity-aware escape-hatch filter. */type FilterFlagEscapeHatchOptions = { /** Argv slice to filter. */ readonly args: readonly string[]; /** Options whose next argv token is value. */ readonly separateValueOptions: ReadonlySet<string>; /** Wrapper-only token removed from flag positions. */ readonly escapeHatchToken: string;};
/** Filters flag-position escape-hatch tokens out of an argv slice while leaving value-position tokens intact. Recursive walk that mirrors the optique arity model used by the per-subcommand parsers. @param args - Argv slice to filter. @param separateValueOptions - Options whose next argv token is value. @param escapeHatchToken - Wrapper-only token removed from flag positions. @returns Argv slice with flag-position escape-hatch tokens removed. @example ```ts filterFlagEscapeHatch({ args: ['-m', '--no-enforce-worktree', '--no-enforce-worktree'], separateValueOptions: new Set(['-m']), escapeHatchToken: '--no-enforce-worktree', }); // => ['-m', '--no-enforce-worktree'] ``` */function filterFlagEscapeHatch({ args, separateValueOptions, escapeHatchToken,}: FilterFlagEscapeHatchOptions,): readonly string[] { /** Current token at the head of args. */ const [arg, ...remaining] = args;
if (arg === undefined) return [];
if (separateValueOptions.has(arg,)) { /** Value token that follows a separated-value option; kept verbatim. */ const [value, ...afterValue] = remaining;
if (value === undefined) return [arg,];
return [ arg, value, ...filterFlagEscapeHatch({ args: afterValue, separateValueOptions, escapeHatchToken, },), ]; }
if (arg === escapeHatchToken) { return filterFlagEscapeHatch({ args: remaining, separateValueOptions, escapeHatchToken, },); }
return [ arg, ...filterFlagEscapeHatch({ args: remaining, separateValueOptions, escapeHatchToken, },), ];}
//endregion Escape hatch token stripping