diff --git a/src/cli/cli.h b/src/cli/cli.h index 139221f0a..556b0a13a 100644 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -25,6 +25,18 @@ const char *cbm_cli_get_version(void); /* ── CLI tool arguments (flags / --args-file / --help) ────────── */ +/* Top-level `cli --help` text printed by run_cli() in src/main.c. + * Documents tool-level --format without adding a session-wide flag (#2102). */ +#define CBM_CLI_USAGE \ + "Usage: codebase-memory-mcp cli [--quiet] [--progress] [--verbose] [--json] " \ + "[json_args]\n" \ + " --quiet Show errors only; cannot combine with --progress or outer --verbose\n" \ + " --progress Show lifecycle progress even when stderr is redirected\n" \ + " --verbose Include informational logs (preserves CBM_LOG_LEVEL=debug)\n" \ + " --json Print the raw MCP result envelope\n" \ + " Tools that accept format support --format tree|json (default: tree).\n" \ + " --format json prints payload JSON; outer --json prints the full MCP envelope.\n" + /* Convert `--flag value` / `--flag=value` / bare-boolean `--flag` arguments for * a tool into a JSON arguments object string, using the tool's input_schema to * type values (string/integer/boolean) and to collect repeated flags into diff --git a/src/main.c b/src/main.c index 53d259b1c..25aac25c6 100644 --- a/src/main.c +++ b/src/main.c @@ -654,13 +654,7 @@ static bool client_start_parent_watchdog(DWORD initial_ppid) { /* ── CLI mode ───────────────────────────────────────────────────── */ -#define CLI_USAGE \ - "Usage: codebase-memory-mcp cli [--quiet] [--progress] [--verbose] [--json] " \ - "[json_args]\n" \ - " --quiet Show errors only; cannot combine with --progress or outer --verbose\n" \ - " --progress Show lifecycle progress even when stderr is redirected\n" \ - " --verbose Include informational logs (preserves CBM_LOG_LEVEL=debug)\n" \ - " --json Print the raw MCP result envelope\n" +#define CLI_USAGE CBM_CLI_USAGE /* `cli --help`; wording lives in cli.h (#2102) */ /* Extract text content from MCP tool result envelope and print it. * MCP results: {"content":[{"type":"text","text":"..."}],"isError":...} diff --git a/tests/test_cli.c b/tests/test_cli.c index 44259a63c..279f10944 100644 --- a/tests/test_cli.c +++ b/tests/test_cli.c @@ -14272,6 +14272,21 @@ TEST(cli_print_tool_help_issue680) { PASS(); } +/* #2102: top-level `cli --help` (CLI_USAGE) must point at tool-level + * `--format json` and distinguish it from outer `--json`. This is help-only: + * the usage synopsis still has no session-wide --format / CBM_CLI_FORMAT. */ +TEST(cli_usage_points_to_tool_format_json_issue2102) { + ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "--format tree|json")); + ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "payload JSON")); + ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "full MCP envelope")); + ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "--json Print the raw MCP result envelope")); + ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "cli [--quiet] [--progress] [--verbose] [--json] " + "")); + ASSERT_NULL(strstr(CBM_CLI_USAGE, "[--format")); + ASSERT_NULL(strstr(CBM_CLI_USAGE, "CBM_CLI_FORMAT")); + PASS(); +} + /* #1359: `cli ` with no argument-bearing token used to slurp stdin to EOF * for ANY non-terminal stdin. The ordinary automation caller never sends that * EOF — Node's child_process.spawn defaults to stdio:['pipe','pipe','pipe'] and @@ -15300,6 +15315,7 @@ SUITE(cli) { RUN_TEST(cli_build_args_json_key_equals_value_issue680); RUN_TEST(cli_build_args_json_bad_positional_errors_issue680); RUN_TEST(cli_print_tool_help_issue680); + RUN_TEST(cli_usage_points_to_tool_format_json_issue2102); /* Stdin argument gate (#1359) */ RUN_TEST(cli_zero_argument_tool_never_reads_stdin_issue1359);