Non-invasive MCP accelerator plugin for Google Antigravity (CLI/Desktop/IDE): cuts LLM turns (-34%), token quota (-31%), and upload traffic (-40%) without affecting native UI or diffs.
TypeScript ai-agentai-codingantigravityantigravity-cliantigravity-ideantigravity-pluginscoding-agentcontext-optimizationdeveloper-productivitydeveloper-toolsgeminigoogle-antigravitylatency-optimizationmcpmcp-pluginmcp-servermodel-context-protocolperformanceplugintoken-optimization
feat(cli): add actionable misuse hints for MCP-vs-CLI flag mix-ups
Fang5ac9d4f73ad4
diff --git a/dist/mcp-server.mjs b/dist/mcp-server.mjsindex 5efa9a3..c7a5b18 100755--- a/dist/mcp-server.mjs+++ b/dist/mcp-server.mjs@@ -11214,15 +11214,15 @@ function formatCliUsage() {"","Commands (aliases):"," outline | quick_outline <file...> [--cwd <dir>] [--max-chars <N>]",- " slice | read_slices <path:start-end,...> [--outline <file>] [--cwd <dir>]",+ " slice | read_slices <path:start-end,...> [--outline <file>] [--cwd <dir>] (positional path:s-e, not --lineRanges)"," search | batch_search [--text <p>] [--regex <p>] [--glob <p>] [--fuzzy <p>] [--git <cmd>]"," [--pattern|--query <p>] [--type text|regex|glob|fuzzy|git]"," [--path <dir>] [--file-type <t>] [--glob-filter <g>]"," [--output-mode content|files_with_matches|count] [--sort-by path|mtime]"," [--context <0..10>] [--max-results <N>] [-i|--ignore-case] [--multiline]"," (modifiers before a query scope only to that query; trailing modifiers apply to all)",- " check | run_checks <cmd...> [--compact|--full] [--concurrency <N>] [--timeout <sec>]",- " edit | apply_edits [--best-effort] [--dry-run] [--diff] [--verify <cmd>] (JSON via --json, --file/--from-file, or stdin)",+ " check | run_checks <cmd...> [--compact|--full] [--concurrency <N>] [--timeout <sec>] (defaults to --compact)",+ " edit | apply_edits [--best-effort] [--dry-run] [--diff] [--verify <cmd>] --from-file <edits.json> | --json '<json>' | --stdin","","JSON input (works for every command using the exact MCP tool schema):"," --json '<json>' Pass tool arguments JSON object (or shorthand array) inline",@@ -11398,6 +11398,42 @@ var VALUE_LONG_FLAGS = /* @__PURE__ */ new Set(["--verify-timeout","--max-verify-chars"]);+var MISUSED_FLAG_HINTS = {+ batch_search: {+ "--queries": "Pass queries via --text/--regex/--glob/--fuzzy/--git flags or UTF-8 JSON (--from-file / --json / --stdin)."+ },+ read_slices: {+ "--lineranges": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--line-ranges": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--slices": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--range": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--ranges": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--outlines": "Use --outline <file> (repeatable) instead of --outlines."+ },+ quick_outline: {+ "--paths": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts).",+ "--path": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts).",+ "-p": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts).",+ "--files": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts)."+ },+ apply_edits: {+ "--edits": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin.",+ "--hunks": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin.",+ "--path": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin.",+ "--target": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin."+ },+ run_checks: {+ "--commands": 'Pass commands as positional args instead (e.g. --cli check --compact "cmd1" "cmd2").',+ "--cmd": 'Pass commands as positional args instead (e.g. --cli check --compact "cmd1" "cmd2").',+ "--cmds": 'Pass commands as positional args instead (e.g. --cli check --compact "cmd1" "cmd2").'+ }+};+function getMisusedFlagHint(tool, flag) {+ const eqIdx = flag.startsWith("--") ? flag.indexOf("=") : -1;+ const normalized = (eqIdx > 2 ? flag.slice(0, eqIdx) : flag).toLowerCase();+ const hint = MISUSED_FLAG_HINTS[tool]?.[normalized];+ return hint ? ` ${hint}` : "";+}var VALID_FLAGS_HINT = {batch_search: "--cwd --text -t --regex -r --glob -g --fuzzy -f --git --pattern --query -q --type --path --paths -p --file-type --glob-filter --output-mode --sort-by --context -C --max-results -i --ignore-case --multiline --max-chars --json --file --from-file --stdin",quick_outline: "--cwd --max-chars --json --file --from-file --stdin",@@ -11637,7 +11673,7 @@ function parseToolFlags(tool, rawArgs) {}if (arg.startsWith("-")) {throw new Error(- `Unknown option '${rawArg}' for '${tool}'. Valid flags: ${VALID_FLAGS_HINT[tool]}. Run with '--cli --help' for usage.`+ `Unknown option '${rawArg}' for '${tool}'.${getMisusedFlagHint(tool, arg)} Valid flags: ${VALID_FLAGS_HINT[tool]}. Run with '--cli --help' for usage.`);}if (tool === "batch_search") {@@ -11866,7 +11902,7 @@ async function runAgyFastCli(argv, io = {}) {} else if (tool === "apply_edits") {if (!jsonInput) {stderr.write(- `Error: 'edit' requires JSON input via --json, --file, or stdin (e.g. {"edits":[...],"bestEffort":true}).+ `Error: 'edit' requires JSON input via --from-file <edits.json>, --json '<json>', or --stdin (e.g. {"edits":[...],"bestEffort":true}).`);return 1;diff --git a/src/cli-runner.ts b/src/cli-runner.tsindex efd76df..37e6c1c 100644--- a/src/cli-runner.ts+++ b/src/cli-runner.ts@@ -60,15 +60,15 @@ export function formatCliUsage(): string {"","Commands (aliases):"," outline | quick_outline <file...> [--cwd <dir>] [--max-chars <N>]",- " slice | read_slices <path:start-end,...> [--outline <file>] [--cwd <dir>]",+ " slice | read_slices <path:start-end,...> [--outline <file>] [--cwd <dir>] (positional path:s-e, not --lineRanges)"," search | batch_search [--text <p>] [--regex <p>] [--glob <p>] [--fuzzy <p>] [--git <cmd>]"," [--pattern|--query <p>] [--type text|regex|glob|fuzzy|git]"," [--path <dir>] [--file-type <t>] [--glob-filter <g>]"," [--output-mode content|files_with_matches|count] [--sort-by path|mtime]"," [--context <0..10>] [--max-results <N>] [-i|--ignore-case] [--multiline]"," (modifiers before a query scope only to that query; trailing modifiers apply to all)",- " check | run_checks <cmd...> [--compact|--full] [--concurrency <N>] [--timeout <sec>]",- " edit | apply_edits [--best-effort] [--dry-run] [--diff] [--verify <cmd>] (JSON via --json, --file/--from-file, or stdin)",+ " check | run_checks <cmd...> [--compact|--full] [--concurrency <N>] [--timeout <sec>] (defaults to --compact)",+ " edit | apply_edits [--best-effort] [--dry-run] [--diff] [--verify <cmd>] --from-file <edits.json> | --json '<json>' | --stdin","","JSON input (works for every command using the exact MCP tool schema):"," --json '<json>' Pass tool arguments JSON object (or shorthand array) inline",@@ -292,6 +292,45 @@ const VALUE_LONG_FLAGS = new Set(["--max-verify-chars",]);+const MISUSED_FLAG_HINTS: Partial<Record<CliCanonicalTool, Record<string, string>>> = {+ batch_search: {+ "--queries":+ "Pass queries via --text/--regex/--glob/--fuzzy/--git flags or UTF-8 JSON (--from-file / --json / --stdin).",+ },+ read_slices: {+ "--lineranges": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--line-ranges": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--slices": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--range": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--ranges": "Pass ranges as positional args instead (e.g. --cli slice src/a.ts:1-60,90-120).",+ "--outlines": "Use --outline <file> (repeatable) instead of --outlines.",+ },+ quick_outline: {+ "--paths": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts).",+ "--path": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts).",+ "-p": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts).",+ "--files": "Pass file paths as positional args instead (e.g. --cli outline src/a.ts src/b.ts).",+ },+ apply_edits: {+ "--edits": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin.",+ "--hunks": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin.",+ "--path": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin.",+ "--target": "Pass edits via UTF-8 JSON using --from-file <edits.json>, --json '<json>', or --stdin.",+ },+ run_checks: {+ "--commands": "Pass commands as positional args instead (e.g. --cli check --compact \"cmd1\" \"cmd2\").",+ "--cmd": "Pass commands as positional args instead (e.g. --cli check --compact \"cmd1\" \"cmd2\").",+ "--cmds": "Pass commands as positional args instead (e.g. --cli check --compact \"cmd1\" \"cmd2\").",+ },+};++function getMisusedFlagHint(tool: CliCanonicalTool, flag: string): string {+ const eqIdx = flag.startsWith("--") ? flag.indexOf("=") : -1;+ const normalized = (eqIdx > 2 ? flag.slice(0, eqIdx) : flag).toLowerCase();+ const hint = MISUSED_FLAG_HINTS[tool]?.[normalized];+ return hint ? ` ${hint}` : "";+}+const VALID_FLAGS_HINT: Record<CliCanonicalTool, string> = {batch_search:"--cwd --text -t --regex -r --glob -g --fuzzy -f --git --pattern --query -q --type --path --paths -p --file-type --glob-filter --output-mode --sort-by --context -C --max-results -i --ignore-case --multiline --max-chars --json --file --from-file --stdin",@@ -569,7 +608,7 @@ function parseToolFlags(tool: CliCanonicalTool, rawArgs: string[]): ParsedCliOptif (arg.startsWith("-")) {throw new Error(- `Unknown option '${rawArg}' for '${tool}'. Valid flags: ${VALID_FLAGS_HINT[tool]}. Run with '--cli --help' for usage.`,+ `Unknown option '${rawArg}' for '${tool}'.${getMisusedFlagHint(tool, arg)} Valid flags: ${VALID_FLAGS_HINT[tool]}. Run with '--cli --help' for usage.`,);}if (tool === "batch_search") {@@ -821,7 +860,7 @@ export async function runAgyFastCli(} else if (tool === "apply_edits") {if (!jsonInput) {stderr.write(- "Error: 'edit' requires JSON input via --json, --file, or stdin (e.g. {\"edits\":[...],\"bestEffort\":true}).\n",+ "Error: 'edit' requires JSON input via --from-file <edits.json>, --json '<json>', or --stdin (e.g. {\"edits\":[...],\"bestEffort\":true}).\n",);return 1;}diff --git a/test/cli-runner.test.ts b/test/cli-runner.test.tsindex 686eccf..4a28e9e 100644--- a/test/cli-runner.test.ts+++ b/test/cli-runner.test.ts@@ -567,4 +567,40 @@ describe("agy-fast --cli direct runner", () => {assert.match(above.stderr, /exceeds 2097152 bytes/);assert.equal(await fs.readFile(target, "utf8"), original);});++ it("emits actionable misuse hints for MCP-vs-CLI flag mix-ups (including --flag=value)", async () => {+ const spaceCases: Array<[string[], RegExp]> = [+ [["slice", "--lineRanges", "src/math.ts:1-2"], /Pass ranges as positional args instead/],+ [["slice", "--outlines", "src/math.ts"], /Use --outline <file> \(repeatable\) instead of --outlines/],+ [["outline", "--paths", "src/math.ts"], /Pass file paths as positional args instead/],+ [["edit", "--edits", "[]"], /Pass edits via UTF-8 JSON using --from-file/],+ [["check", "--commands", "echo ok"], /Pass commands as positional args instead/],+ [["search", "--queries", "[]"], /Pass queries via --text\/--regex\/--glob\/--fuzzy\/--git flags/],+ ];+ for (const [args, pattern] of spaceCases) {+ const res = await runCliSubprocess(args, { cwd: tmpDir });+ assert.equal(res.code, 1, `expected exit 1 for ${args.join(" ")}`);+ assert.match(res.stderr, pattern);+ }++ const equalsCases: Array<[string[], RegExp]> = [+ [["slice", "--lineRanges=src/math.ts:1-2"], /Pass ranges as positional args instead/],+ [["slice", "--outlines=src/math.ts"], /Use --outline <file> \(repeatable\) instead of --outlines/],+ [["outline", "--files=src/math.ts"], /Pass file paths as positional args instead/],+ [["outline", "--PATH=src/math.ts"], /Pass file paths as positional args instead/],+ [["edit", "--edits=[]"], /Pass edits via UTF-8 JSON using --from-file/],+ [["check", "--commands=echo ok"], /Pass commands as positional args instead/],+ [["search", "--queries=[]"], /Pass queries via --text\/--regex\/--glob\/--fuzzy\/--git flags/],+ ];+ for (const [args, pattern] of equalsCases) {+ const res = await runCliSubprocess(args, { cwd: tmpDir });+ assert.equal(res.code, 1, `expected exit 1 for ${args.join(" ")}`);+ assert.match(res.stderr, pattern);+ }++ const unknownSlice = await runCliSubprocess(["slice", "--definitely-unknown"], { cwd: tmpDir });+ assert.equal(unknownSlice.code, 1);+ assert.match(unknownSlice.stderr, /Unknown option '--definitely-unknown' for 'read_slices'\. Valid flags:/);+ assert.doesNotMatch(unknownSlice.stderr, /Pass .* instead|Use --outline/);+ });});