MCPcopy Create free account
hub / github.com/freecodexyz/free-code / commandHasArgAbbreviation

Function commandHasArgAbbreviation

src/utils/powershell/parser.ts:1663–1684  ·  view source on GitHub ↗
(
  command: ParsedCommandElement,
  fullParam: string,
  minPrefix: string,
)

Source from the content-addressed store, hash-verified

1661 * For example, minPrefix '-en' for fullParam '-encodedcommand' matches '-en', '-enc', '-enco', etc.
1662 */
1663export function commandHasArgAbbreviation(
1664 command: ParsedCommandElement,
1665 fullParam: string,
1666 minPrefix: string,
1667): boolean {
1668 const lowerFull = fullParam.toLowerCase()
1669 const lowerMin = minPrefix.toLowerCase()
1670 return command.args.some(a => {
1671 // Strip colon-bound value (e.g., -en:base64value -> -en)
1672 const colonIndex = a.indexOf(':', 1)
1673 const paramPart = colonIndex > 0 ? a.slice(0, colonIndex) : a
1674 // Strip backtick escapes — PowerShell resolves `-Member`Name` to
1675 // `-MemberName` but Extent.Text preserves the backtick, causing
1676 // prefix-comparison misses on the raw text.
1677 const lower = paramPart.replace(/`/g, '').toLowerCase()
1678 return (
1679 lower.startsWith(lowerMin) &&
1680 lowerFull.startsWith(lower) &&
1681 lower.length <= lowerFull.length
1682 )
1683 })
1684}
1685
1686/**
1687 * Split a parsed command into its pipeline segments for per-segment permission checking.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected