Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(hooks): enforce --capture-mode allowlist in the generated TS integrations (#661)
AkitaOnRailsa688fbe6d14f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2cc5dccb..d88c7516 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,6 +19,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0migrating. The check now reads past the frontmatter fence and classifies onthe first body line, so a real page that happens to be named `log.md` isstill indexed. (#660)+- `install-hooks --apply --capture-mode allowlist` no longer captures+ repositories with no `.ai-memory.toml` marker on the five generated+ TypeScript integrations (`pi`, `omp`, `opencode`, `opencode2`,+ `openclaw`). The native `ai-memory hook` path already gated every+ lifecycle event on marker presence before spooling or sending anything+ (`repository_admits_capture` in `ai-memory-hooks::capture_policy`), but+ the generated adapters POST to `<server>/hook` directly and had only+ ported the `ignore_paths` denylist logic into their shared+ `capturePolicy` — never the allowlist admit gate — so an unmarked+ repository was still fully captured while the CLI printed that the+ protection was active. The shared template now bakes the selected+ `--capture-mode` into a `CAPTURE_MODE` constant and gates on+ marker *presence* (not on marker configuration state, so a marker with+ an empty `[capture]` section still opts a repository in) before any+ per-event disposition runs. The install-time "enforced"/"NOT in force"+ messaging is corrected to match: a script-fallback install is now the+ only path flagged as unenforced. (#661)## [2.1.0] - 2026-09-06diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rsindex 23bc8b5c..419fe86c 100644--- a/crates/ai-memory-cli/src/commands/install_hooks.rs+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs@@ -423,12 +423,15 @@ pub fn run(config: &Config, mut args: InstallHooksArgs) -> Result<()> {println!("capture mode: {capture_mode}");if capture_mode == "allowlist" {println!(" repositories without a .ai-memory.toml marker emit no lifecycle events");- // The gate lives inside the native hook binary, immediately before- // the spool write. A script install POSTs to the server directly- // and never runs it, so the mode is stored but unenforced. Saying- // nothing would leave an operator trusting a protection this- // install does not have — the exact failure #446 is about.- if !local_hook_policy_v1_supported() {+ // The gate runs inside the native hook binary (immediately before+ // the spool write) and, since #661, inside the generated+ // TypeScript integrations' shared `capturePolicy` (before any+ // POST). The only install left that reaches the server with no+ // gate at all is the raw script fallback: it POSTs directly and+ // never runs either enforcement point. Saying nothing would leave+ // an operator trusting a protection this install does not have —+ // the exact failure #446 is about.+ if !generated && !local_hook_policy_v1_supported() {println!(" WARNING: this install uses script hooks, which POST directly and \cannot enforce the mode. Allowlist is stored but NOT in force here."@@ -445,10 +448,14 @@ pub fn run(config: &Config, mut args: InstallHooksArgs) -> Result<()> {// per-agent plumbing.args.project_strategy = install_project_strategy(&args);return match args.agent {- AgentChoice::OpenCode => apply_to_opencode_plugin(&server_url, auth, &args),- AgentChoice::OpenCode2 => apply_to_opencode2_plugin(&server_url, auth, &args),- AgentChoice::Pi => apply_to_pi_extension(&server_url, auth, &args),- AgentChoice::Omp => apply_to_omp_extension(&server_url, auth, &args),+ AgentChoice::OpenCode => {+ apply_to_opencode_plugin(&server_url, auth, &args, &capture_mode)+ }+ AgentChoice::OpenCode2 => {+ apply_to_opencode2_plugin(&server_url, auth, &args, &capture_mode)+ }+ AgentChoice::Pi => apply_to_pi_extension(&server_url, auth, &args, &capture_mode),+ AgentChoice::Omp => apply_to_omp_extension(&server_url, auth, &args, &capture_mode),AgentChoice::ClaudeCode => {let hooks_dir =resolve_hooks_dir(args.hooks_dir.as_deref(), args.agent, &config.data_dir)?;@@ -509,7 +516,9 @@ pub fn run(config: &Config, mut args: InstallHooksArgs) -> Result<()> {resolve_hooks_dir(args.hooks_dir.as_deref(), args.agent, &config.data_dir)?;apply_to_devin_settings(&hooks_dir, &server_url, auth, &config.data_dir, &args)}- AgentChoice::Openclaw => openclaw_plugin::apply(&server_url, auth, &args),+ AgentChoice::Openclaw => {+ openclaw_plugin::apply(&server_url, auth, &args, &capture_mode)+ }AgentChoice::KimiCode => {let hooks_dir =resolve_hooks_dir(args.hooks_dir.as_deref(), args.agent, &config.data_dir)?;@@ -539,13 +548,24 @@ pub fn run(config: &Config, mut args: InstallHooksArgs) -> Result<()> {};}let strategy = args.project_strategy.and_then(ProjectStrategyArg::baked);+ // Preview must bake the same `CAPTURE_MODE` the next `--apply` would+ // persist (#661) — resolved read-only so a bare preview never writes.+ let preview_capture_mode = resolve_capture_mode(&config.data_dir, args.capture_mode);match args.agent {- AgentChoice::OpenCode => render_opencode_plugin(&server_url, auth, strategy),- AgentChoice::OpenCode2 => render_opencode2_plugin(&server_url, auth, strategy),- AgentChoice::Pi => render_pi_extension(&server_url, auth, strategy),- AgentChoice::Omp => {- render_omp_extension(&server_url, auth, strategy, args.profile.as_deref())+ AgentChoice::OpenCode => {+ render_opencode_plugin(&server_url, auth, strategy, &preview_capture_mode)}+ AgentChoice::OpenCode2 => {+ render_opencode2_plugin(&server_url, auth, strategy, &preview_capture_mode)+ }+ AgentChoice::Pi => render_pi_extension(&server_url, auth, strategy, &preview_capture_mode),+ AgentChoice::Omp => render_omp_extension(+ &server_url,+ auth,+ strategy,+ args.profile.as_deref(),+ &preview_capture_mode,+ ),AgentChoice::ClaudeCode => {let hooks_dir =resolve_hooks_dir(args.hooks_dir.as_deref(), args.agent, &config.data_dir)?;@@ -639,7 +659,7 @@ pub fn run(config: &Config, mut args: InstallHooksArgs) -> Result<()> {render_devin(&hooks_dir, &server_url, auth, &config.data_dir, strategy)}AgentChoice::Openclaw => {- openclaw_plugin::render(&server_url, auth, strategy);+ openclaw_plugin::render(&server_url, auth, strategy, &preview_capture_mode);Ok(())}AgentChoice::KimiCode => {@@ -690,6 +710,26 @@ fn install_project_strategy(args: &InstallHooksArgs) -> Option<ProjectStrategyAr.and_then(|existing| baked_project_strategy(args.agent, existing))}+/// The capture failure mode (#446) currently in force: an explicit+/// `--capture-mode` flag wins, otherwise the value stored under `data_dir`+/// from an earlier `--apply`, otherwise the historical `denylist` default.+/// Read-only — used by both [`persist_capture_mode`] and the print-only+/// preview path so a preview's baked `CAPTURE_MODE` matches what the next+/// `--apply` would actually persist (#661).+fn resolve_capture_mode(data_dir: &Path, requested: Option<CaptureModeArg>) -> String {+ let Some(requested) = requested else {+ let path = data_dir.join(crate::commands::hook::CAPTURE_MODE_FILE);+ return match fs::read_to_string(&path) {+ Ok(text) if text.trim().eq_ignore_ascii_case("allowlist") => "allowlist".to_string(),+ _ => "denylist".to_string(),+ };+ };+ match requested {+ CaptureModeArg::Allowlist => "allowlist".to_string(),+ CaptureModeArg::Denylist => "denylist".to_string(),+ }+}+/// Settle and persist the capture failure mode (#446), returning the mode now/// in force.///@@ -698,26 +738,19 @@ fn install_project_strategy(args: &InstallHooksArgs) -> Option<ProjectStrategyAr/// auto-refresh inside `ai-memory upgrade` — can never quietly downgrade an/// existing opt-in back to capture-by-default.fn persist_capture_mode(data_dir: &Path, requested: Option<CaptureModeArg>) -> Result<String> {- let path = data_dir.join(crate::commands::hook::CAPTURE_MODE_FILE);- let Some(requested) = requested else {- return Ok(match fs::read_to_string(&path) {- Ok(text) if text.trim().eq_ignore_ascii_case("allowlist") => "allowlist".to_string(),- _ => "denylist".to_string(),- });- };- let value = match requested {- CaptureModeArg::Allowlist => "allowlist",- CaptureModeArg::Denylist => "denylist",- };- fs::create_dir_all(data_dir)- .with_context(|| format!("creating data dir {}", data_dir.display()))?;- // Atomically, because every reader maps an unrecognised value onto- // `denylist`: a torn write would not corrupt the opt-in, it would silently- // revert it to capture-by-default (`CONTRIBUTING.md`, "Atomic file writes- // only").- ai_memory_wiki::write_atomic(&path, format!("{value}\n").as_bytes())- .with_context(|| format!("writing {}", path.display()))?;- Ok(value.to_string())+ let value = resolve_capture_mode(data_dir, requested);+ if requested.is_some() {+ let path = data_dir.join(crate::commands::hook::CAPTURE_MODE_FILE);+ fs::create_dir_all(data_dir)+ .with_context(|| format!("creating data dir {}", data_dir.display()))?;+ // Atomically, because every reader maps an unrecognised value onto+ // `denylist`: a torn write would not corrupt the opt-in, it would+ // silently revert it to capture-by-default (`CONTRIBUTING.md`,+ // "Atomic file writes only").+ ai_memory_wiki::write_atomic(&path, format!("{value}\n").as_bytes())+ .with_context(|| format!("writing {}", path.display()))?;+ }+ Ok(value)}/// Whether the Claude Code install should include its prompt-capture hook.@@ -2739,13 +2772,14 @@ fn apply_to_opencode_plugin(server_url: &str,auth_token: Option<&str>,args: &InstallHooksArgs,+ capture_mode: &str,) -> Result<()> {let path = match &args.config_file {Some(p) => p.clone(),None => opencode_plugin_path()?,};let strategy = args.project_strategy.and_then(ProjectStrategyArg::baked);- let body = build_opencode_plugin(server_url, auth_token, strategy);+ let body = build_opencode_plugin(server_url, auth_token, strategy, capture_mode);let outcome = apply_atomic(&path, move |_existing| Ok(body.clone()))?;println!(@@ -2771,6 +2805,7 @@ fn render_opencode_plugin(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> Result<()> {println!("// OpenCode plugin — write to ~/.config/opencode/plugins/ai-memory.ts");println!("// Or re-run with `--apply` to install it automatically.");@@ -2778,7 +2813,7 @@ fn render_opencode_plugin(println!();println!("{}",- build_opencode_plugin(server_url, auth_token, project_strategy)+ build_opencode_plugin(server_url, auth_token, project_strategy, capture_mode));Ok(())}@@ -2810,13 +2845,14 @@ fn apply_to_opencode2_plugin(server_url: &str,auth_token: Option<&str>,args: &InstallHooksArgs,+ capture_mode: &str,) -> Result<()> {let path = match &args.config_file {Some(p) => p.clone(),None => opencode2_plugin_path()?,};let strategy = args.project_strategy.and_then(ProjectStrategyArg::baked);- let body = build_opencode2_plugin(server_url, auth_token, strategy)?;+ let body = build_opencode2_plugin(server_url, auth_token, strategy, capture_mode)?;let outcome = apply_atomic(&path, move |_existing| Ok(body.clone()))?;println!(@@ -2842,6 +2878,7 @@ fn render_opencode2_plugin(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> Result<()> {println!("// OpenCode 2.0 beta plugin — write to ~/.config/opencode/plugins/ai-memory-opencode2.ts"@@ -2851,7 +2888,7 @@ fn render_opencode2_plugin(println!();println!("{}",- build_opencode2_plugin(server_url, auth_token, project_strategy)?+ build_opencode2_plugin(server_url, auth_token, project_strategy, capture_mode)?);Ok(())}@@ -2866,8 +2903,9 @@ fn build_opencode2_plugin(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> Result<String> {- let v1 = build_opencode_plugin(server_url, auth_token, project_strategy);+ let v1 = build_opencode_plugin(server_url, auth_token, project_strategy, capture_mode);const BANNER_V1: &str ="// Auto-generated by `ai-memory install-hooks --agent opencode --apply`.";const BANNER_V2: &str =@@ -3240,12 +3278,13 @@ fn build_opencode_plugin(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> String {let token_line = auth_token.map(|t| format!("const TOKEN: string | null = {};\n", ts_string_literal(t))).unwrap_or_else(|| "const TOKEN: string | null = null;\n".to_string());let apply_marker_params = ts_apply_marker_params(project_strategy);- let capture_policy = ts_capture_policy_v1();+ let capture_policy = ts_capture_policy_v1(capture_mode);let body = format!(r#"// Auto-generated by `ai-memory install-hooks --agent opencode --apply`.// Edit by re-running the command, not by hand — install-hooks@@ -3709,10 +3748,11 @@ fn apply_to_omp_extension(server_url: &str,auth_token: Option<&str>,args: &InstallHooksArgs,+ capture_mode: &str,) -> Result<()> {let path = resolve_omp_extension_path(args)?;let strategy = args.project_strategy.and_then(ProjectStrategyArg::baked);- let body = build_omp_extension(server_url, auth_token, strategy);+ let body = build_omp_extension(server_url, auth_token, strategy, capture_mode);let outcome = apply_atomic(&path, move |_existing| Ok(body.clone()))?;println!(@@ -3769,6 +3809,7 @@ fn render_omp_extension(auth_token: Option<&str>,project_strategy: Option<&str>,profile: Option<&str>,+ capture_mode: &str,) -> Result<()> {println!("// Oh My Pi / OMP extension — write to {}",@@ -3779,7 +3820,7 @@ fn render_omp_extension(println!();println!("{}",- build_omp_extension(server_url, auth_token, project_strategy)+ build_omp_extension(server_url, auth_token, project_strategy, capture_mode));Ok(())}@@ -3801,10 +3842,11 @@ fn apply_to_pi_extension(server_url: &str,auth_token: Option<&str>,args: &InstallHooksArgs,+ capture_mode: &str,) -> Result<()> {let path = resolve_pi_extension_path(args)?;let strategy = args.project_strategy.and_then(ProjectStrategyArg::baked);- let body = build_pi_extension(server_url, auth_token, strategy);+ let body = build_pi_extension(server_url, auth_token, strategy, capture_mode);let outcome = apply_atomic(&path, move |_existing| Ok(body.clone()))?;println!(@@ -3833,6 +3875,7 @@ fn render_pi_extension(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> Result<()> {println!("// Pi extension — write to {}",@@ -3843,7 +3886,7 @@ fn render_pi_extension(println!();println!("{}",- build_pi_extension(server_url, auth_token, project_strategy)+ build_pi_extension(server_url, auth_token, project_strategy, capture_mode));Ok(())}@@ -3859,8 +3902,9 @@ fn build_pi_extension(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> String {- let lifecycle = build_omp_extension(server_url, auth_token, project_strategy)+ let lifecycle = build_omp_extension(server_url, auth_token, project_strategy, capture_mode).replace("install-hooks --agent omp --apply", "install-hooks --agent pi --apply").replace("const AGENT = \"omp\";", "const AGENT = \"pi\";").replace(@@ -3973,12 +4017,13 @@ fn build_omp_extension(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> String {let token_line = auth_token.map(|t| format!("const TOKEN: string | null = {};\n", ts_string_literal(t))).unwrap_or_else(|| "const TOKEN: string | null = null;\n".to_string());let apply_marker_params = ts_apply_marker_params(project_strategy);- let capture_policy = ts_capture_policy_v1();+ let capture_policy = ts_capture_policy_v1(capture_mode);let body = format!(r#"// Auto-generated by `ai-memory install-hooks --agent omp --apply`.// Edit by re-running the command, not by hand — install-hooks@@ -5522,6 +5567,17 @@ fn apply_to_pool(mod tests {use super::*;+ /// The marker-presence admit gate the shared `ts_capture_policy_v1`+ /// template bakes into `capturePolicy` (#661). Under allowlist a+ /// repository with no `.ai-memory.toml` marker must emit nothing —+ /// mirroring `repository_admits_capture` in+ /// `ai-memory-hooks::capture_policy`, the gate hook.rs's native path+ /// runs before any per-event disposition. Keyed on `findMarker(cwd)`+ /// presence rather than `config.state`, so a marker with an empty+ /// `[capture]` section — `state` is "inactive" either way — still admits+ /// capture.+ const CAPTURE_ADMIT_GATE_TS: &str = "const markerPresent = !!findMarker(cwd); if (CAPTURE_MODE === \"allowlist\" && !markerPresent) return { disposition: \"drop\", payload };";+/// #446's binding requirement: "a protection that disappears on upgrade/// without saying so is worse than no protection". A bare `--apply` — what/// `ai-memory upgrade` runs — must leave an existing opt-in alone.@@ -7751,15 +7807,15 @@ model = "gpt-5"for (name, source) in [("opencode",- build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None),+ build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist"),),("omp",- build_omp_extension("http://127.0.0.1:49374", Some("tok"), None),+ build_omp_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist"),),("pi",- build_pi_extension("http://127.0.0.1:49374", Some("tok"), None),+ build_pi_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist"),),] {// The fire-and-forget delivery must be gone...@@ -7848,7 +7904,7 @@ model = "gpt-5"#[test]fn opencode_plugin_uses_real_plugin_hooks() {- let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None);+ let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(plugin.contains("event: async (input)"));assert!(plugin.contains(r#""chat.message": async"#));@@ -7925,7 +7981,9 @@ model = "gpt-5"#[test]fn opencode2_plugin_binds_the_v2_api() {- let plugin = build_opencode2_plugin("http://127.0.0.1:49374", Some("tok"), None).unwrap();+ let plugin =+ build_opencode2_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist")+ .unwrap();// Ownership markers the uninstall gate keys on.assert!(plugin.contains("install-hooks --agent opencode2 --apply"));@@ -7993,7 +8051,13 @@ model = "gpt-5"// The builder rewrites the v1 template, so a v1 edit that moves the// binding anchor must fail loudly instead of shipping a hybrid.let plugin =- build_opencode2_plugin("http://127.0.0.1:49374/", None, Some("repo-root")).unwrap();+ build_opencode2_plugin(+ "http://127.0.0.1:49374/",+ None,+ Some("repo-root"),+ "denylist",+ )+ .unwrap();assert!(plugin.contains("const TOKEN: string | null = null;"));assert!(plugin.contains("const DEFAULT_PROJECT_STRATEGY = \"repo-root\";"),@@ -8011,9 +8075,34 @@ model = "gpt-5");}+ #[test]+ fn opencode2_plugin_bakes_allowlist_admit_gate() {+ // opencode2 reuses v1's capture prelude verbatim (see+ // `build_opencode2_plugin`'s doc comment), so the gate must survive+ // the anchor rewrite into the beta's `{ id, setup }` host binding.+ let plugin = build_opencode2_plugin("http://127.0.0.1:49374", Some("tok"), None, "allowlist")+ .unwrap();+ assert!(+ plugin.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"allowlist\";"),+ "{plugin}"+ );+ assert!(plugin.contains(CAPTURE_ADMIT_GATE_TS), "{plugin}");+ }++ #[test]+ fn opencode2_plugin_denylist_bakes_inert_gate() {+ let plugin = build_opencode2_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist")+ .unwrap();+ assert!(+ plugin.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"denylist\";"),+ "{plugin}"+ );+ assert!(plugin.contains(CAPTURE_ADMIT_GATE_TS), "{plugin}");+ }+#[test]fn opencode_plugin_normalizes_payloads_without_legacy_wrapper() {- let plugin = build_opencode_plugin("http://127.0.0.1:49374/", None, None);+ let plugin = build_opencode_plugin("http://127.0.0.1:49374/", None, None, "denylist");assert!(plugin.contains("const SERVER = \"http://127.0.0.1:49374/\".replace"));assert!(plugin.contains("const TOKEN: string | null = null;"));@@ -8031,7 +8120,12 @@ model = "gpt-5"#[test]fn opencode_plugin_bakes_repo_root_default() {let plugin =- build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), Some("repo-root"));+ build_opencode_plugin(+ "http://127.0.0.1:49374",+ Some("tok"),+ Some("repo-root"),+ "denylist",+ );assert!(plugin.contains("const DEFAULT_PROJECT_STRATEGY = \"repo-root\";"),"repo-root install default must bake the const: {plugin}"@@ -8048,23 +8142,43 @@ model = "gpt-5"#[test]fn opencode_plugin_default_omits_baked_strategy() {- let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None);+ let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(!plugin.contains("DEFAULT_PROJECT_STRATEGY"),"basename default must bake no strategy: {plugin}");}+ #[test]+ fn opencode_plugin_bakes_allowlist_admit_gate() {+ let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None, "allowlist");+ assert!(+ plugin.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"allowlist\";"),+ "{plugin}"+ );+ assert!(plugin.contains(CAPTURE_ADMIT_GATE_TS), "{plugin}");+ }++ #[test]+ fn opencode_plugin_denylist_bakes_inert_gate() {+ let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");+ assert!(+ plugin.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"denylist\";"),+ "{plugin}"+ );+ assert!(plugin.contains(CAPTURE_ADMIT_GATE_TS), "{plugin}");+ }+#[test]fn opencode_plugin_uses_bounded_hook_queue() {- let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None);+ let plugin = build_opencode_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert_generated_ts_uses_bounded_hook_queue(&plugin);}#[test]fn opencode_plugin_resolves_token_at_runtime_when_not_embedded() {- let plugin = build_opencode_plugin("http://127.0.0.1:49374", None, None);+ let plugin = build_opencode_plugin("http://127.0.0.1:49374", None, None, "denylist");assert!(plugin.contains("function resolveToken("));assert!(plugin.contains("const token = resolveToken();"));assert!(plugin.contains("if (!response.ok) return undefined;"));@@ -8072,7 +8186,7 @@ model = "gpt-5"#[test]fn omp_extension_resolves_token_at_runtime_when_not_embedded() {- let extension = build_omp_extension("http://127.0.0.1:49374", None, None);+ let extension = build_omp_extension("http://127.0.0.1:49374", None, None, "denylist");assert!(extension.contains("function resolveToken("));assert!(extension.contains("process.env.AI_MEMORY_AUTH_TOKEN"));assert!(extension.contains("auth-token"));@@ -8081,7 +8195,7 @@ model = "gpt-5"#[test]fn omp_extension_prefers_statically_embedded_token() {- let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None);+ let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(extension.contains("function resolveToken("));assert!(extension.contains("if (TOKEN) return TOKEN;"));}@@ -8090,9 +8204,31 @@ model = "gpt-5"// OMP tests// ----------------------------------------------------------------+ #[test]+ fn omp_extension_bakes_allowlist_admit_gate() {+ let extension =+ build_omp_extension("http://127.0.0.1:49374", Some("tok"), None, "allowlist");+ assert!(+ extension.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"allowlist\";"),+ "{extension}"+ );+ assert!(extension.contains(CAPTURE_ADMIT_GATE_TS), "{extension}");+ }++ #[test]+ fn omp_extension_denylist_bakes_inert_gate() {+ let extension =+ build_omp_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist");+ assert!(+ extension.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"denylist\";"),+ "{extension}"+ );+ assert!(extension.contains(CAPTURE_ADMIT_GATE_TS), "{extension}");+ }+#[test]fn omp_extension_uses_native_lifecycle_events() {- let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None);+ let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(extension.contains("export default function AiMemoryExtension"));assert!(extension.contains("const AGENT = \"omp\";"));@@ -8141,7 +8277,12 @@ model = "gpt-5"#[test]fn omp_extension_bakes_repo_root_default() {let extension =- build_omp_extension("http://127.0.0.1:49374", Some("tok"), Some("repo-root"));+ build_omp_extension(+ "http://127.0.0.1:49374",+ Some("tok"),+ Some("repo-root"),+ "denylist",+ );assert!(extension.contains("const DEFAULT_PROJECT_STRATEGY = \"repo-root\";"),"repo-root install default must bake the const: {extension}"@@ -8154,7 +8295,7 @@ model = "gpt-5"#[test]fn omp_extension_default_omits_baked_strategy() {- let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None);+ let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(!extension.contains("DEFAULT_PROJECT_STRATEGY"),"{extension}"@@ -8163,7 +8304,7 @@ model = "gpt-5"#[test]fn omp_extension_uses_bounded_hook_queue() {- let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None);+ let extension = build_omp_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert_generated_ts_uses_bounded_hook_queue(&extension);}@@ -8480,9 +8621,34 @@ model = "gpt-5");}+ #[test]+ fn pi_extension_bakes_allowlist_admit_gate() {+ // Pi is `build_omp_extension` with the AGENT constant swapped, so the+ // gate must survive that string-replace rewrite too.+ let extension =+ build_pi_extension("http://127.0.0.1:49374", Some("tok"), None, "allowlist");+ assert!(+ extension.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"allowlist\";"),+ "{extension}"+ );+ assert!(extension.contains(CAPTURE_ADMIT_GATE_TS), "{extension}");+ }++ #[test]+ fn pi_extension_denylist_bakes_inert_gate() {+ let extension =+ build_pi_extension("http://127.0.0.1:49374", Some("tok"), None, "denylist");+ assert!(+ extension.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"denylist\";"),+ "{extension}"+ );+ assert!(extension.contains(CAPTURE_ADMIT_GATE_TS), "{extension}");+ }+#[test]fn pi_extension_contains_lifecycle_capture_and_mcp_bridge() {- let extension = build_pi_extension("http://127.0.0.1:49374/base", Some("tok"), None);+ let extension =+ build_pi_extension("http://127.0.0.1:49374/base", Some("tok"), None, "denylist");assert!(extension.contains("export default function AiMemoryExtension(pi: any): void"));assert!(extension.contains("const AGENT = \"pi\";"));diff --git a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs b/crates/ai-memory-cli/src/commands/openclaw_plugin.rsindex 947e65e9..b6ed989c 100644--- a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs+++ b/crates/ai-memory-cli/src/commands/openclaw_plugin.rs@@ -24,12 +24,13 @@ pub(crate) fn apply(server_url: &str,auth_token: Option<&str>,args: &InstallHooksArgs,+ capture_mode: &str,) -> Result<()> {let plugin_dir = resolve_plugin_dir(args)?;let strategy = args.project_strategy.and_then(crate::cli::ProjectStrategyArg::baked);- let outcomes = write_package(&plugin_dir, server_url, auth_token, strategy)?;+ let outcomes = write_package(&plugin_dir, server_url, auth_token, strategy, capture_mode)?;for (path, outcome) in &outcomes {println!("✓ {} {} ({})",@@ -64,7 +65,12 @@ pub(crate) fn apply(}/// Print the generated package for manual installation.-pub(crate) fn render(server_url: &str, auth_token: Option<&str>, project_strategy: Option<&str>) {+pub(crate) fn render(+ server_url: &str,+ auth_token: Option<&str>,+ project_strategy: Option<&str>,+ capture_mode: &str,+) {println!("# OpenClaw native plugin package");println!("# Re-run with `--apply` to write the package and call:");println!("# openclaw plugins install --link <package-dir> --force");@@ -76,7 +82,10 @@ pub(crate) fn render(server_url: &str, auth_token: Option<&str>, project_strategprintln!("## {MANIFEST_JSON}");println!("{}", manifest_json());println!("## {ENTRYPOINT_TS}");- println!("{}", build_plugin(server_url, auth_token, project_strategy));+ println!(+ "{}",+ build_plugin(server_url, auth_token, project_strategy, capture_mode)+ );}fn outcome_detail(outcome: ApplyOutcome) -> &'static str {@@ -106,13 +115,14 @@ fn write_package(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> Result<Vec<(PathBuf, ApplyOutcome)>> {let files = [(PACKAGE_JSON, package_json()),(MANIFEST_JSON, manifest_json()),(ENTRYPOINT_TS,- build_plugin(server_url, auth_token, project_strategy),+ build_plugin(server_url, auth_token, project_strategy, capture_mode),),];let mut outcomes = Vec::with_capacity(files.len());@@ -300,13 +310,14 @@ fn build_plugin(server_url: &str,auth_token: Option<&str>,project_strategy: Option<&str>,+ capture_mode: &str,) -> String {let token_line = auth_token.map(|t| format!("const TOKEN: string | null = {};\n", ts_string_literal(t))).unwrap_or_else(|| "const TOKEN: string | null = null;\n".to_string());let resolve_fn = ts_resolve_token_fn();let apply_marker_params = apply_marker_params_ts(project_strategy);- let capture_policy = ts_capture_policy_v1();+ let capture_policy = ts_capture_policy_v1(capture_mode);format!(r#"// Auto-generated by `ai-memory install-hooks --agent openclaw --apply`.// Edit by re-running the command, not by hand. install-hooks owns@@ -573,7 +584,7 @@ mod tests {fn openclaw_plugin_spools_failed_deliveries() {// #580: OpenClaw's fire-and-forget postHook must persist failures// in the CLI hook-spool format and drain the backlog on success.- let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None);+ let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(plugin.contains("function spoolFailedHook("));assert!(plugin.contains("async function drainHookSpool()"));assert!(@@ -600,7 +611,7 @@ mod tests {fn package_has_manifest_and_hook_entrypoint() {let package = package_json();let manifest = manifest_json();- let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None);+ let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(package.contains(r#""extensions""#));assert!(package.contains(r#""./index.ts""#));@@ -653,7 +664,7 @@ mod tests {#[test]fn openclaw_plugin_resolves_token_at_runtime_when_not_embedded() {- let plugin = build_plugin("http://127.0.0.1:49374", None, None);+ let plugin = build_plugin("http://127.0.0.1:49374", None, None, "denylist");assert!(plugin.contains("function resolveToken("));assert!(plugin.contains("const token = resolveToken();"));assert!(plugin.contains("if (!response.ok) return undefined;"));@@ -661,7 +672,12 @@ mod tests {#[test]fn openclaw_plugin_bakes_repo_root_default() {- let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), Some("repo-root"));+ let plugin = build_plugin(+ "http://127.0.0.1:49374",+ Some("tok"),+ Some("repo-root"),+ "denylist",+ );assert!(plugin.contains("const DEFAULT_PROJECT_STRATEGY = \"repo-root\";"),"repo-root install default must bake the const: {plugin}"@@ -674,17 +690,55 @@ mod tests {#[test]fn openclaw_plugin_default_omits_baked_strategy() {- let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None);+ let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");assert!(!plugin.contains("DEFAULT_PROJECT_STRATEGY"),"basename default must bake no strategy: {plugin}");}+ #[test]+ fn openclaw_plugin_bakes_allowlist_admit_gate() {+ // #661: the generated OpenClaw plugin POSTs to `<server>/hook` directly+ // and never runs through the native `ai-memory hook` admit gate+ // (`repository_admits_capture` in `ai-memory-hooks::capture_policy`), so+ // the shared TS template must carry an equivalent gate keyed on marker+ // *presence*, baked from `--capture-mode`.+ let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None, "allowlist");+ assert!(+ plugin.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"allowlist\";"),+ "allowlist mode must be baked into the emitted constant: {plugin}"+ );+ assert!(+ plugin.contains(+ "const markerPresent = !!findMarker(cwd); if (CAPTURE_MODE === \"allowlist\" && !markerPresent) return { disposition: \"drop\", payload };"+ ),+ "allowlist build must carry the marker-presence admit gate: {plugin}"+ );+ }++ #[test]+ fn openclaw_plugin_denylist_bakes_inert_gate() {+ let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");+ assert!(+ plugin.contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"denylist\";"),+ "denylist mode must be baked into the emitted constant: {plugin}"+ );+ // The gate expression is present in every build (it's part of the one+ // shared template) but is inert under denylist, since `CAPTURE_MODE`+ // never equals `"allowlist"`.+ assert!(+ plugin.contains(+ "const markerPresent = !!findMarker(cwd); if (CAPTURE_MODE === \"allowlist\" && !markerPresent) return { disposition: \"drop\", payload };"+ )+ );+ }+#[test]fn package_writes_all_required_files() {let tmp = TempDir::new().unwrap();- let outcomes = write_package(tmp.path(), "http://127.0.0.1:49374", None, None).unwrap();+ let outcomes =+ write_package(tmp.path(), "http://127.0.0.1:49374", None, None, "denylist").unwrap();assert_eq!(outcomes.len(), 3);assert!(tmp.path().join(PACKAGE_JSON).is_file());diff --git a/crates/ai-memory-cli/src/commands/render_shared.rs b/crates/ai-memory-cli/src/commands/render_shared.rsindex 4bf59fd2..24c63dbd 100644--- a/crates/ai-memory-cli/src/commands/render_shared.rs+++ b/crates/ai-memory-cli/src/commands/render_shared.rs@@ -180,10 +180,19 @@ pub(crate) fn ts_string_literal(s: &str) -> String {/// The single capture-policy-v1 implementation embedded in every generated/// JavaScript integration. It deliberately has no package dependency: these/// extensions run in several hosts with different module loaders.+///+/// `capture_mode` is the baked `--capture-mode` value ("allowlist" or+/// "denylist", the same string [`crate::commands::install_hooks`]'s+/// `persist_capture_mode` returns) and is spliced into the emitted+/// `CAPTURE_MODE` constant that `capturePolicy` gates on. Under allowlist a+/// repository with no `.ai-memory.toml` marker must emit nothing — mirroring+/// the native admit gate in `commands/hook.rs` (`repository_admits_capture`)+/// — so the check runs before any disposition logic, for every event kind.#[must_use]-pub(crate) fn ts_capture_policy_v1() -> &'static str {- r##"// capture-policy-v1 (generated; do not fork between adapters)+pub(crate) fn ts_capture_policy_v1(capture_mode: &str) -> String {+ const TEMPLATE: &str = r##"// capture-policy-v1 (generated; do not fork between adapters)const CAPTURE_POLICY_V1 = 1;+const CAPTURE_MODE: "allowlist" | "denylist" = "__AI_MEMORY_CAPTURE_MODE__";const CAPTURE_MARKER_MAX_BYTES = 64 * 1024;const CAPTURE_MAX_PATTERNS = 128;const CAPTURE_MAX_PATTERN_CHARS = 1024;@@ -261,8 +270,9 @@ function captureConfig(cwd: string | undefined): CaptureConfig {}function captureGlob(pattern: string, candidate: string, insensitive: boolean, budget: { work: number }): boolean | undefined { const p = [...pattern]; const c = [...candidate]; const eq = (a: string, b: string) => insensitive && a.charCodeAt(0) < 128 && b.charCodeAt(0) < 128 ? a.toLowerCase() === b.toLowerCase() : a === b; const previous = new Array<boolean>(p.length + 1).fill(false); previous[0] = true; for (let j = 1; j <= p.length; j++) previous[j] = p[j - 1] === "*" && p[j] !== "*" && previous[j - 1]; for (const ch of c) { const current = new Array<boolean>(p.length + 1).fill(false); for (let j = 1; j <= p.length; j++) { if (++budget.work > CAPTURE_MAX_WORK) return undefined; const x = p[j - 1]; current[j] = x === "*" && p[j] === "*" ? false : x === "*" && j >= 2 && p[j - 2] === "*" ? current[j - 2] || previous[j] : x === "*" ? current[j - 1] || (ch !== "/" && previous[j]) : x === "?" ? ch !== "/" && previous[j - 1] : eq(x, ch) && previous[j - 1]; } for (let j = 0; j <= p.length; j++) previous[j] = current[j]; } return previous[p.length]; }function captureTool(payload: Record<string, unknown>): { family: CaptureProtocol["tool_family"]; paths?: string[]; extraction: CaptureProtocol["extraction_state"]; callID?: string } { const name = typeof payload.tool === "string" ? payload.tool.toLowerCase() : ""; const args = payload.args as Record<string, unknown> | undefined; const call = ["tool_use_id","toolUseId","tool_call_id","toolCallId","call_id","callId","callID"].map((k) => payload[k]).find((v): v is string => typeof v === "string" && /^[A-Za-z0-9_.-]{1,128}$/.test(v)); if (["search","grep","glob","find","list","ls","list_files","read_dir"].includes(name)) return { family: "search-list", extraction: "not-applicable", callID: call }; if (["bash","shell","execute","run_command","web_search"].includes(name)) return { family: "non-file", extraction: "extracted", callID: call }; if (!["read","write","edit","apply_patch","notebookedit","notebook_edit","create_file","delete_file","rename_file","move_file","multi_edit","multiedit","replace","replace_all"].includes(name)) return { family: "unknown", extraction: "extracted", callID: call }; const direct = (o: any): string[] | undefined => { if (!o || typeof o !== "object") return undefined; const r: string[] = []; for (const k of ["file_path","filePath","path","absolute_path","AbsolutePath","notebook_path"]) if (k in o) { if (typeof o[k] !== "string") return undefined; r.push(o[k]); } if ("paths" in o) { if (!Array.isArray(o.paths) || o.paths.some((x: unknown) => typeof x !== "string")) return undefined; r.push(...o.paths); } return r.length && r.length <= CAPTURE_MAX_CANDIDATES ? r : undefined; }; let paths = direct(args); if (["multi_edit","multiedit","replace_all"].includes(name)) { const entries = args?.edits ?? args?.replacements; if (!Array.isArray(entries) || !entries.length || entries.length > CAPTURE_MAX_CANDIDATES) paths = undefined; else { paths = paths ?? []; for (const entry of entries) { const more = direct(entry); if (!more || paths.length + more.length > CAPTURE_MAX_CANDIDATES) { paths = undefined; break; } paths.push(...more); } } } if (!paths || paths.some((p) => !p.trim() || [...p].length > CAPTURE_MAX_PATH_CHARS)) return { family: "file", extraction: "missing-or-malformed", callID: call }; return { family: "file", paths, extraction: "extracted", callID: call }; }-function capturePolicy(payload: Record<string, unknown>, cwd: string | undefined): { disposition: CaptureDisposition; protocol?: CaptureProtocol; payload: Record<string, unknown> } { const config = captureConfig(cwd); const tool = captureTool(payload); let disposition: CaptureDisposition = "keep"; if (config.state === "invalid" && tool.family === "file") disposition = "metadata-only"; else if (config.state === "active" && tool.family === "search-list") disposition = "drop"; else if (config.state === "active" && tool.family === "file") { if (!tool.paths) disposition = "metadata-only"; else { const candidates = tool.paths.map((p) => captureNormalize(/^(?:\/|\\\\|[A-Za-z]:[\\/])/.test(p) ? p : captureJoin(config.base, p))); if (candidates.some((p) => !p)) disposition = "metadata-only"; else { const budget = { work: 0 }; captureMatch: for (const candidate of candidates as { path: string; windows: boolean }[]) for (const pattern of config.patterns) { if (candidate.windows !== pattern.windows) continue; if (pattern.directory && captureGlob(pattern.directory, candidate.path, pattern.windows, budget)) { disposition = "drop"; break captureMatch; } const match = captureGlob(pattern.path, candidate.path, pattern.windows, budget); if (match === undefined) { disposition = "metadata-only"; break; } if (match) { disposition = "drop"; break captureMatch; } } } } } if (config.state === "inactive") return { disposition, payload }; const protocol: CaptureProtocol = { version: CAPTURE_POLICY_V1, disposition, policy_state: config.state, tool_family: tool.family, path_count: tool.paths?.length ?? 0, extraction_state: tool.extraction }; if (disposition === "metadata-only") { const session = payload.sessionID ?? payload.sessionId ?? payload.session_id; const routing = typeof payload.cwd === "string" ? payload.cwd : cwd; return { disposition, protocol, payload: { ...(typeof session === "string" ? { session_id: session } : {}), ...(typeof routing === "string" ? { cwd: routing } : {}), tool_family: tool.family, tool_name: tool.family, ...(tool.callID ? { tool_call_id: tool.callID } : {}), _ai_memory_capture: protocol } }; } if (disposition === "keep") return { disposition, protocol, payload: { ...payload, _ai_memory_capture: protocol } }; return { disposition, protocol, payload }; }-"##+function capturePolicy(payload: Record<string, unknown>, cwd: string | undefined): { disposition: CaptureDisposition; protocol?: CaptureProtocol; payload: Record<string, unknown> } { const markerPresent = !!findMarker(cwd); if (CAPTURE_MODE === "allowlist" && !markerPresent) return { disposition: "drop", payload }; const config = captureConfig(cwd); const tool = captureTool(payload); let disposition: CaptureDisposition = "keep"; if (config.state === "invalid" && tool.family === "file") disposition = "metadata-only"; else if (config.state === "active" && tool.family === "search-list") disposition = "drop"; else if (config.state === "active" && tool.family === "file") { if (!tool.paths) disposition = "metadata-only"; else { const candidates = tool.paths.map((p) => captureNormalize(/^(?:\/|\\\\|[A-Za-z]:[\\/])/.test(p) ? p : captureJoin(config.base, p))); if (candidates.some((p) => !p)) disposition = "metadata-only"; else { const budget = { work: 0 }; captureMatch: for (const candidate of candidates as { path: string; windows: boolean }[]) for (const pattern of config.patterns) { if (candidate.windows !== pattern.windows) continue; if (pattern.directory && captureGlob(pattern.directory, candidate.path, pattern.windows, budget)) { disposition = "drop"; break captureMatch; } const match = captureGlob(pattern.path, candidate.path, pattern.windows, budget); if (match === undefined) { disposition = "metadata-only"; break; } if (match) { disposition = "drop"; break captureMatch; } } } } } if (config.state === "inactive") return { disposition, payload }; const protocol: CaptureProtocol = { version: CAPTURE_POLICY_V1, disposition, policy_state: config.state, tool_family: tool.family, path_count: tool.paths?.length ?? 0, extraction_state: tool.extraction }; if (disposition === "metadata-only") { const session = payload.sessionID ?? payload.sessionId ?? payload.session_id; const routing = typeof payload.cwd === "string" ? payload.cwd : cwd; return { disposition, protocol, payload: { ...(typeof session === "string" ? { session_id: session } : {}), ...(typeof routing === "string" ? { cwd: routing } : {}), tool_family: tool.family, tool_name: tool.family, ...(tool.callID ? { tool_call_id: tool.callID } : {}), _ai_memory_capture: protocol } }; } if (disposition === "keep") return { disposition, protocol, payload: { ...payload, _ai_memory_capture: protocol } }; return { disposition, protocol, payload }; }+"##;+ TEMPLATE.replace("__AI_MEMORY_CAPTURE_MODE__", capture_mode)}/// Build the Claude Code `settings.json` fragment that wires the@@ -2136,7 +2146,7 @@ const activeKeep = capturePolicy({{ tool: "bash", args: {{ command: privateBodycheck(activeKeep.disposition === "keep" && activeKeep.protocol?.version === 1 && activeKeep.protocol.policy_state === "active", "active-keep-adds-protocol");"#,fixture = fixture,- policy = ts_capture_policy_v1(),+ policy = ts_capture_policy_v1("denylist"),);fs::write(&module, source).unwrap();let output = Command::new("node")@@ -2168,6 +2178,60 @@ check(activeKeep.disposition === "keep" && activeKeep.protocol?.version === 1 &&"Node diagnostics leaked a private sentinel");}++ // #661: under `--capture-mode allowlist`, a repository with no marker+ // must emit nothing at all — for a prompt/session event as much as a+ // file event, since `inspect` (and its `search-list`/`file` families)+ // is never reached for those event kinds. A repository WITH a marker+ // but an empty `[capture]` section must still be admitted: `state`+ // is "inactive" in both the no-marker and marker-with-no-section+ // cases, so the gate must key on marker *presence*, never on+ // `config.state`, or this second case would be wrongly dropped.+ let allowlist_module = temp.path().join("capture-policy-allowlist-evidence.ts");+ let allowlist_source = format!(+ r#"import {{ closeSync, mkdirSync, openSync, readFileSync as readMarkerText, readSync, writeFileSync }} from "node:fs";+import {{ dirname, join, resolve }} from "node:path";+import {{ homedir }} from "node:os";++const markerRoot = process.argv[2]!;+const markerFixtures = new Map<string, string>();+function findMarker(cwd: string | undefined): string | undefined {{ return cwd ? markerFixtures.get(cwd) : undefined; }}+{policy}++function fail(label: string): never {{ throw new Error(`allowlist runtime evidence failed: ${{label}}`); }}+function check(ok: unknown, label: string): asserts ok {{ if (!ok) fail(label); }}++const promptDrop = capturePolicy({{ prompt: "hello" }}, "/no-marker-allowlist");+check(promptDrop.disposition === "drop", "allowlist-no-marker-prompt-event-drop");++const fileDrop = capturePolicy({{ tool: "edit", args: {{ path: "x" }} }}, "/no-marker-allowlist");+check(fileDrop.disposition === "drop", "allowlist-no-marker-file-event-drop");++const markedDir = join(markerRoot, "marked-empty");+mkdirSync(markedDir, {{ recursive: true }});+const markerFile = join(markedDir, ".ai-memory.toml");+writeFileSync(markerFile, "[capture]\n");+markerFixtures.set("/marked-empty-cwd", markerFile);+const markedButEmpty = capturePolicy({{ tool: "edit", args: {{ path: "x" }} }}, "/marked-empty-cwd");+check(markedButEmpty.disposition === "keep", "allowlist-marker-present-empty-capture-not-dropped");+"#,+ policy = ts_capture_policy_v1("allowlist"),+ );+ fs::write(&allowlist_module, allowlist_source).unwrap();+ let allowlist_output = Command::new("node")+ .args([+ "--experimental-strip-types",+ allowlist_module.to_str().unwrap(),+ temp.path().to_str().unwrap(),+ ])+ .output()+ .unwrap();+ assert!(+ allowlist_output.status.success(),+ "allowlist Node runtime evidence failed\nstdout:\n{}\nstderr:\n{}",+ String::from_utf8_lossy(&allowlist_output.stdout),+ String::from_utf8_lossy(&allowlist_output.stderr),+ );}#[test]diff --git a/docs/marker-file.md b/docs/marker-file.mdindex 7a3498ef..2a72f5f3 100644--- a/docs/marker-file.md+++ b/docs/marker-file.md@@ -172,11 +172,13 @@ direction whose failure you would rather explain.The mode is stored per install rather than per agent, and a later bare`install-hooks --apply` (including an upgrade refresh) leaves it in place.-Like `ignore_paths` below, it is enforced by native `ai-memory hook` commands-only — which is what `install-hooks --apply` writes by default. Script-based-installs (the `AI_MEMORY_HOOK_PLATFORM` override, the Docker host wrapper, and-`setup-agent` snippets) POST to the server directly without running that-binary, so allowlist mode does not gate them.+It is enforced both by native `ai-memory hook` commands and by the generated+TypeScript integrations (`pi`, `omp`, `opencode`, `opencode2`, `openclaw`) —+each bakes the selected mode in and carries the same marker-presence gate+before it ever POSTs. Only the raw script-fallback paths (the+`AI_MEMORY_HOOK_PLATFORM` override, the Docker host wrapper, and+`setup-agent` snippets) POST to the server directly without running either+enforcement point, so allowlist mode does not gate them.## Capture exclusions