AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(init): accept --disable-feedback on every subcommand (#1773)
xerj-org83c6778fd301
diff --git a/engine/crates/xerj-autoindex/src/def.rs b/engine/crates/xerj-autoindex/src/def.rsindex 6b48b7446..4ec7ad6ed 100644--- a/engine/crates/xerj-autoindex/src/def.rs+++ b/engine/crates/xerj-autoindex/src/def.rs@@ -405,6 +405,7 @@ pub fn run_def_cli() -> i32 {"--kind" => kind = it.next(),"--lang" => lang = it.next(),"--json" => as_json = true,+ "--disable-feedback" => {}other if !other.starts_with('-') && query.is_none() => query = Some(other.to_string()),other => {eprintln!("xerj def: unexpected argument '{other}'\n\n{USAGE}");diff --git a/engine/crates/xerj-autoindex/src/gain.rs b/engine/crates/xerj-autoindex/src/gain.rsindex d821afd69..330482db3 100644--- a/engine/crates/xerj-autoindex/src/gain.rs+++ b/engine/crates/xerj-autoindex/src/gain.rs@@ -208,6 +208,7 @@ pub fn run_gain_cli() -> i32 {"--url" => url = it.next().unwrap_or(url),"--api-key" => api_key = it.next(),"--json" => as_json = true,+ "--disable-feedback" => {}other => {eprintln!("xerj gain: unexpected argument '{other}'\n\n{USAGE}");return 2;diff --git a/engine/crates/xerj-autoindex/src/init.rs b/engine/crates/xerj-autoindex/src/init.rsindex 3dfc47e56..e75190d4d 100644--- a/engine/crates/xerj-autoindex/src/init.rs+++ b/engine/crates/xerj-autoindex/src/init.rs@@ -63,6 +63,9 @@ OPTIONS:--url <U> node endpoint baked into the MCP config(default $XERJ_URL or http://localhost:9200)--dry-run print what would be written, write nothing+ --disable-feedback+ accepted; turns off the feedback invitation on help+ screens. Honoured in any position (env XERJ_DISABLE_FEEDBACK)-h, --help this helpAfter init: restart the agent session so it picks up the new tools, then@@ -553,31 +556,59 @@ fn register_mcp(path: &Path, url: &str, dry: bool) -> Result<String, String> {Ok(report(if had { "merged" } else { "wrote" }, path, dry))}-/// Entry point for the `init` subcommand. Returns a process exit code.-pub fn run_init_cli() -> i32 {+struct InitFlags {+ url: String,+ dry: bool,+ help: bool,+}++/// `Err` is the unexpected-argument line, without the help page.+fn read_init_flags(args: impl IntoIterator<Item = String>) -> Result<InitFlags, String> {let mut url = std::env::var("XERJ_URL").ok().filter(|s| !s.is_empty()).unwrap_or_else(|| DEFAULT_URL.to_string());let mut dry = false;- let mut it = xerj_common::argv::args_after_subcommand().into_iter();+ let mut it = args.into_iter();while let Some(a) = it.next() {match a.as_str() {"-h" | "--help" => {- print!("{}", usage(xerj_common::hub::hub_key_configured()));- return 0;+ return Ok(InitFlags {+ url,+ dry,+ help: true,+ });}"--url" => url = it.next().unwrap_or(url),"--dry-run" => dry = true,- other => {- eprintln!(- "xerj init: unexpected argument '{other}'\n\n{}",- usage(xerj_common::hub::hub_key_configured())- );- return 2;- }+ // Also stripped by args_after_subcommand. Accepted here so a+ // caller that passes the raw list still does not exit 2.+ "--disable-feedback" => {}+ other => return Err(format!("xerj init: unexpected argument '{other}'")),}}+ Ok(InitFlags {+ url,+ dry,+ help: false,+ })+}++/// Entry point for the `init` subcommand. Returns a process exit code.+pub fn run_init_cli() -> i32 {+ let flags = match read_init_flags(xerj_common::argv::args_after_subcommand()) {+ Ok(flags) => flags,+ Err(e) => {+ eprintln!("{e}\n\n{}", usage(xerj_common::hub::hub_key_configured()));+ return 2;+ }+ };+ if flags.help {+ print!("{}", usage(xerj_common::hub::hub_key_configured()));+ return 0;+ }+ let url = flags.url;+ let dry = flags.dry;let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));let hub = xerj_common::hub::hub_key_configured();match run_init_with(&cwd, &url, dry, hub) {@@ -1238,6 +1269,29 @@ mod tests {assert!(printed.contains("xerj_search"));}+ #[test]+ fn disable_feedback_is_accepted_in_any_position() {+ let help = usage(false);+ assert!(+ help.contains("--disable-feedback"),+ "xerj init --help must document the off-switch:\n{help}"+ );+ for args in [+ vec!["--disable-feedback"],+ vec!["--dry-run", "--disable-feedback"],+ vec!["--disable-feedback", "--url", "http://127.0.0.1:9"],+ vec!["--url", "http://127.0.0.1:9", "--disable-feedback"],+ ] {+ let flags = read_init_flags(args.iter().map(|s| (*s).to_string()))+ .unwrap_or_else(|e| panic!("{args:?}: {e}"));+ assert!(!flags.help, "{args:?}");+ }+ match read_init_flags(["--nope".to_string()]) {+ Err(err) => assert!(err.contains("unexpected argument"), "{err}"),+ Ok(_) => panic!("--nope must be rejected"),+ }+ }+/// `--help` lists every file init can write. The hub pair is listed only/// when this build can verify hub packs; otherwise the help must not/// teach `xerj "<question>"`, which exits 5.diff --git a/engine/crates/xerj-autoindex/src/search.rs b/engine/crates/xerj-autoindex/src/search.rsindex ae431fd42..93617ccdc 100644--- a/engine/crates/xerj-autoindex/src/search.rs+++ b/engine/crates/xerj-autoindex/src/search.rs@@ -760,6 +760,9 @@ fn parse_search_cli("-k" => k = parse_count_arg("-k", it.next())?,"--full" => full = parse_count_arg("--full", it.next())?,"--json" => as_json = true,+ // Read by feedback::enabled from the raw argv. Accepted so+ // `xerj search --disable-feedback` is not an unexpected argument.+ "--disable-feedback" => {}"--mode" => {let asked = it.next().unwrap_or_default();eprintln!("{}", search_mode_refusal(&asked));@@ -1044,6 +1047,23 @@ mod tests {args.iter().map(|s| (*s).to_string()).collect()}+ #[test]+ fn disable_feedback_is_not_an_unexpected_argument() {+ for args in [+ vec!["--disable-feedback", "needle"],+ vec!["needle", "--disable-feedback"],+ vec!["--disable-feedback", "--json", "needle"],+ ] {+ let parsed = parse_search_cli(words(&args).into_iter(), String::new(), None)+ .unwrap_or_else(|e| panic!("{args:?}: {e}"));+ match parsed {+ SearchCli::Query(q) => assert_eq!(q.query.as_deref(), Some("needle")),+ SearchCli::Help => panic!("help from {args:?}"),+ SearchCli::Refuse => panic!("refusal from {args:?}"),+ }+ }+ }+#[test]fn a_non_numeric_k_is_a_usage_error() {let err = parse_search_cli(diff --git a/engine/crates/xerj-common/src/argv.rs b/engine/crates/xerj-common/src/argv.rsindex 242c0933e..8d0f96add 100644--- a/engine/crates/xerj-common/src/argv.rs+++ b/engine/crates/xerj-common/src/argv.rs@@ -32,11 +32,20 @@ pub fn subcommand() -> Option<String> {/// Arguments after the subcommand word. A hoist appends the flags that/// preceded it, so `xerj --url U corpus index name` is seen as/// `index name --url U`.+///+/// `--disable-feedback` is removed here. `feedback::enabled` still sees it+/// on the raw process arguments (it turns the help invitation off), and a+/// subcommand parser must not reject it as unknown. Parsers that also match+/// the flag themselves keep working: it is simply absent from this list.pub fn args_after_subcommand() -> Vec<String> {- if let Some(v) = hoisted() {- return v.into_iter().skip(1).collect();- }- std::env::args().skip(2).collect()+ let raw = if let Some(v) = hoisted() {+ v.into_iter().skip(1).collect::<Vec<_>>()+ } else {+ std::env::args().skip(2).collect::<Vec<_>>()+ };+ raw.into_iter()+ .filter(|a| a != crate::feedback::DISABLE_FLAG)+ .collect()}/// Move flags that precede a command word to the end of the list.@@ -114,6 +123,32 @@ mod tests {);}+ #[test]+ fn disable_feedback_is_stripped_before_a_subcommand_parser_sees_argv() {+ let _guard = HoistGuard;+ install_hoist(Some(v(&[+ "init",+ "--disable-feedback",+ "--dry-run",+ "--url",+ "http://127.0.0.1:9",+ ])));+ assert_eq!(+ args_after_subcommand(),+ v(&["--dry-run", "--url", "http://127.0.0.1:9"])+ );+ install_hoist(Some(v(&["search", "--disable-feedback", "needle"])));+ assert_eq!(args_after_subcommand(), v(&["needle"]));+ }++ /// Clears the process-global hoist even when the test fails.+ struct HoistGuard;+ impl Drop for HoistGuard {+ fn drop(&mut self) {+ install_hoist(None);+ }+ }+#[test]fn a_subcommand_already_in_front_is_left_alone() {assert!(reorder_flags_before_command(