Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(profile): keep a [profile] opt-out sticky when a client sends no flags

AkitaOnRailsb3c0f5260f59
diff --git a/crates/ai-memory-cli/src/commands/hook_capture.rs b/crates/ai-memory-cli/src/commands/hook_capture.rs
index dd6061a0..275783de 100644
--- a/crates/ai-memory-cli/src/commands/hook_capture.rs
+++ b/crates/ai-memory-cli/src/commands/hook_capture.rs
@@ -451,6 +451,17 @@ fn forwarded_identity_style(raw: Option<&str>) -> Option<&'static str> {
.map(IdentityStyle::as_str)
}
+/// A resolved marker's `[profile]` flag as the explicit value the hook
+/// forwards: `0` for a falsy value, `1` for anything else, an absent key
+/// included.
+fn profile_flag_value(raw: Option<String>) -> &'static str {
+ if raw.as_deref().is_some_and(crate::marker::is_falsy) {
+ "0"
+ } else {
+ "1"
+ }
+}
+
fn marker_query_suffix_impl(
cwd: &str,
default_strategy: Option<&str>,
@@ -475,10 +486,12 @@ fn marker_query_suffix_impl(
// appended to the session-start handoff fetch (#176).
briefing = parse_toml_flag(&marker, "inject_on_session_start");
briefing_budget = parse_toml_flag(&marker, "max_chars");
- // `[profile] contribute` / `consume` (quoted or bare). The server
- // keeps both on unless the value is explicitly falsy.
- profile_contribute = parse_toml_flag(&marker, "contribute");
- profile_consume = parse_toml_flag(&marker, "consume");
+ // `[profile] contribute` / `consume` (quoted or bare), always sent
+ // explicitly once a marker resolved: a falsy value sends `0`, anything
+ // else (an absent key included) `1`. Removing the key re-enables; no
+ // marker sends nothing, so the server keeps what it stored.
+ profile_contribute = Some(profile_flag_value(parse_toml_flag(&marker, "contribute")));
+ profile_consume = Some(profile_flag_value(parse_toml_flag(&marker, "consume")));
}
if let Some(val) = scope.workspace {
qs.push_str(&format!("&workspace={}", url_encode(&val)));
@@ -517,11 +530,11 @@ fn marker_query_suffix_impl(
// Per-project `[profile]` settings: the server records `contribute` on the
// project for harvesting, and `consume = false` suppresses the digest and
// the profile union for this project.
- if let Some(val) = profile_contribute.filter(|v| !v.is_empty()) {
- qs.push_str(&format!("&profile_contribute={}", url_encode(&val)));
+ if let Some(val) = profile_contribute {
+ qs.push_str(&format!("&profile_contribute={val}"));
}
- if let Some(val) = profile_consume.filter(|v| !v.is_empty()) {
- qs.push_str(&format!("&profile_consume={}", url_encode(&val)));
+ if let Some(val) = profile_consume {
+ qs.push_str(&format!("&profile_consume={val}"));
}
// Per-repo session-start brief opt-in: forwarded on every request for
// simplicity (the capture path ignores it); only the `/handoff` GET at
@@ -1302,14 +1315,23 @@ drop_subagent_captures = "true"
)
.unwrap();
let qs = marker_query_suffix(inner.to_str().unwrap(), None);
- assert!(qs.contains("&profile_contribute=false"), "{qs}");
- assert!(qs.contains("&profile_consume=no"), "{qs}");
+ assert!(qs.contains("&profile_contribute=0"), "{qs}");
+ assert!(qs.contains("&profile_consume=0"), "{qs}");
assert!(
!qs.contains("workspace=outer"),
"a [profile] marker is a boundary: {qs}"
);
+ // A resolved marker without the keys states the defaults explicitly,
+ // so removing an opt-out from the marker turns it back on.
let outer = marker_query_suffix(tmp.path().to_str().unwrap(), None);
- assert!(!outer.contains("profile_"), "{outer}");
+ assert!(
+ outer.contains("&profile_contribute=1&profile_consume=1"),
+ "{outer}"
+ );
+ // No marker at all: nothing is sent, so the server keeps what it stored.
+ let bare = tempfile::TempDir::new().unwrap();
+ let none = marker_query_suffix(bare.path().to_str().unwrap(), None);
+ assert!(!none.contains("profile_"), "{none}");
}
/// A marker WITHOUT `drop_subagent_captures` does not forward the flag, so
diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rs
index f734384e..eb54fbf1 100644
--- a/crates/ai-memory-cli/src/commands/install_hooks.rs
+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs
@@ -3933,8 +3933,8 @@ fn ts_apply_marker_params(default_strategy: Option<&str>) -> String {
const defaultGlobal = tomlFlag(body, "default_global");
const briefing = tomlFlag(body, "inject_on_session_start");
const briefingBudget = tomlFlag(body, "max_chars");
- const profileContribute = tomlFlag(body, "contribute");
- const profileConsume = tomlFlag(body, "consume");
+ const profileContribute = profileFlag(tomlFlag(body, "contribute"));
+ const profileConsume = profileFlag(tomlFlag(body, "consume"));
if (workspace) url.searchParams.set("workspace", workspace);
if (project) url.searchParams.set("project", project);
if (projectStrategy) url.searchParams.set("project_strategy", projectStrategy);
@@ -3980,8 +3980,8 @@ fn ts_apply_marker_params(default_strategy: Option<&str>) -> String {
defaultGlobal = tomlFlag(body, "default_global");
briefing = tomlFlag(body, "inject_on_session_start");
briefingBudget = tomlFlag(body, "max_chars");
- profileContribute = tomlFlag(body, "contribute");
- profileConsume = tomlFlag(body, "consume");
+ profileContribute = profileFlag(tomlFlag(body, "contribute"));
+ profileConsume = profileFlag(tomlFlag(body, "consume"));
explicitIdentity = tomlKey(body, "identity");
identityStyle = tomlKey(body, "identity_style");
} catch (_e) {
@@ -4107,6 +4107,12 @@ pub(crate) const TS_TOML_FLAG: &str = r#"function tomlFlag(text: string, key: st
if (match) return match[1] ?? match[2];
}
return undefined;
+}
+// A resolved marker's `[profile]` flag as the explicit value the hook sends:
+// "0" for a falsy value, "1" for anything else, an absent key included.
+// Parity with `profile_flag_value` in hook_capture.rs.
+function profileFlag(value: string | undefined): string {
+ return value !== undefined && ["0", "false", "no", "off"].includes(value.trim().toLowerCase()) ? "0" : "1";
}"#;
/// `repoRootProject`, shared by every generated TypeScript integration: the
diff --git a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs b/crates/ai-memory-cli/src/commands/openclaw_plugin.rs
index 5aa0407b..4e05dced 100644
--- a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs
+++ b/crates/ai-memory-cli/src/commands/openclaw_plugin.rs
@@ -241,8 +241,8 @@ fn apply_marker_params_ts(default_strategy: Option<&str>) -> String {
const defaultGlobal = tomlFlag(body, "default_global");
const briefing = tomlFlag(body, "inject_on_session_start");
const briefingBudget = tomlFlag(body, "max_chars");
- const profileContribute = tomlFlag(body, "contribute");
- const profileConsume = tomlFlag(body, "consume");
+ const profileContribute = profileFlag(tomlFlag(body, "contribute"));
+ const profileConsume = profileFlag(tomlFlag(body, "consume"));
if (workspace) url.searchParams.set("workspace", workspace);
if (project) url.searchParams.set("project", project);
// `project_src` tells the server a marker rescope from a host-derived
@@ -290,8 +290,8 @@ fn apply_marker_params_ts(default_strategy: Option<&str>) -> String {
defaultGlobal = tomlFlag(body, "default_global");
briefing = tomlFlag(body, "inject_on_session_start");
briefingBudget = tomlFlag(body, "max_chars");
- profileContribute = tomlFlag(body, "contribute");
- profileConsume = tomlFlag(body, "consume");
+ profileContribute = profileFlag(tomlFlag(body, "contribute"));
+ profileConsume = profileFlag(tomlFlag(body, "consume"));
} catch (_e) {
}
}
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 8a2cf408..cdf418d1 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -1550,8 +1550,10 @@ async fn fetch_and_accept_handoff_at(
// single-use slot claimed below), it is recomposed on every opted-in
// session start — exactly what a Claude Code `/clear` needs (#176).
let brief_md = render_requested_session_brief(state, &query, ws, proj, actor.as_ref()).await?;
- persist_profile_flags(state, &query, proj).await;
- let profile_md = render_requested_profile_digest(state, &query, ws, proj, viewer).await;
+ let profile_flags = persist_profile_flags(state, &query, ws, proj).await;
+ let profile_md =
+ render_requested_profile_digest(state, &query, ws, proj, viewer, profile_flags.consume)
+ .await;
// Handoff first: it is a short curated pointer and must not be buried
// under a ledger that can run tens of KB. The existing ledger-then-brief
// order is preserved. Claim both single-use inputs only after every
@@ -1931,25 +1933,62 @@ async fn render_requested_session_brief(
Ok(render_session_brief(&core, &recent, budget))
}
-/// The marker's `[profile]` flags, as forwarded on the session-start fetch.
-fn profile_flags_from_query(query: &HandoffQuery) -> ai_memory_store::ProjectProfileFlags {
- ai_memory_store::ProjectProfileFlags {
- contribute: !crate::payload::query_flag_falsy(query.profile_contribute.as_deref()),
- consume: !crate::payload::query_flag_falsy(query.profile_consume.as_deref()),
+/// An explicit `[profile]` flag forwarded by the client: `Some` when the
+/// resolved marker sent `1`/`0` (or another truthy/falsy spelling), `None` when
+/// the parameter is absent. Absent means "no marker said anything" (no marker,
+/// an older client, a front door that wasn't regenerated), so the stored value
+/// stands: an opt-out must not be undone by a session start that omits it.
+fn explicit_profile_flag(value: Option<&str>) -> Option<bool> {
+ if crate::payload::query_flag_truthy(value) {
+ Some(true)
+ } else if crate::payload::query_flag_falsy(value) {
+ Some(false)
+ } else {
+ None
}
}
-/// Persist the marker's `[profile]` flags on the project, so the harvester
-/// and the MCP query union honour them. A conditional no-op in the common
-/// case, and never allowed to fail the session start.
-async fn persist_profile_flags(state: &HookState, query: &HandoffQuery, project_id: ProjectId) {
- if let Err(e) = state
- .writer
- .set_project_profile_flags(project_id, profile_flags_from_query(query))
+/// The project's effective `[profile]` flags for this session start: each
+/// explicit forwarded value overrides the stored one, an absent value keeps it.
+/// Writes only when an explicit value changes what is stored, so the common
+/// session start costs one bounded read and no writer command. Never fails the
+/// session start: an unreadable stored value withholds the digest rather than
+/// guessing it was on.
+async fn persist_profile_flags(
+ state: &HookState,
+ query: &HandoffQuery,
+ workspace_id: WorkspaceId,
+ project_id: ProjectId,
+) -> ai_memory_store::ProjectProfileFlags {
+ let contribute = explicit_profile_flag(query.profile_contribute.as_deref());
+ let consume = explicit_profile_flag(query.profile_consume.as_deref());
+ let stored = match state
+ .reader
+ .project_profile_flags(workspace_id, project_id)
.await
+ {
+ Ok(stored) => stored,
+ Err(e) => {
+ warn!(error = %e, "could not read the project's [profile] flags");
+ return ai_memory_store::ProjectProfileFlags {
+ contribute: contribute.unwrap_or(false),
+ consume: consume.unwrap_or(false),
+ };
+ }
+ };
+ let wanted = ai_memory_store::ProjectProfileFlags {
+ contribute: contribute.unwrap_or(stored.contribute),
+ consume: consume.unwrap_or(stored.consume),
+ };
+ if wanted != stored
+ && let Err(e) = state
+ .writer
+ .set_project_profile_flags(project_id, wanted)
+ .await
{
warn!(error = %e, "could not record the project's [profile] flags");
}
+ wanted
}
/// Render the cross-project profile digest for a session in `(workspace_id,
@@ -1963,9 +2002,10 @@ async fn render_requested_profile_digest(
workspace_id: WorkspaceId,
project_id: ProjectId,
viewer: Option<ai_memory_core::UserId>,
+ consume: bool,
) -> Option<String> {
if !state.profile.inject_on_session_start
- || !profile_flags_from_query(query).consume
+ || !consume
|| crate::payload::query_flag_falsy(query.profile_digest.as_deref())
{
return None;
@@ -17413,17 +17453,21 @@ mod tests {
);
}
- /// The marker's flags are recorded on the project at session start, and
- /// removing them from the marker turns them back on.
+ /// The marker's flags are recorded on the project at session start. An
+ /// opt-out is sticky: a later session start that forwards no flags (no
+ /// marker found, an older hook bundle, a front door not regenerated) keeps
+ /// the project out of the harvest and the digest. Only an explicit value
+ /// (a marker without the key now sends `1`) turns it back on.
#[tokio::test]
async fn session_start_records_the_marker_profile_flags() {
let tmp = TempDir::new().unwrap();
let state = make_state(&tmp).await;
+ seed_global_profile(&state).await;
let cwd = "/home/u/client-work";
let mut query = profile_query(cwd, "claude-code");
query.profile_contribute = Some("false".into());
query.profile_consume = Some("off".into());
- session_start_text(&state, query).await;
+ assert_eq!(session_start_text(&state, query).await, None);
let (ws, proj) = resolve_project_ids(
&state,
Some(cwd),
@@ -17437,7 +17481,18 @@ mod tests {
let flags = state.reader.project_profile_flags(ws, proj).await.unwrap();
assert!(!flags.contribute && !flags.consume, "{flags:?}");
- session_start_text(&state, profile_query(cwd, "claude-code")).await;
+ // No flags forwarded: the opt-out stands and the digest stays off.
+ assert_eq!(
+ session_start_text(&state, profile_query(cwd, "claude-code")).await,
+ None
+ );
+ let flags = state.reader.project_profile_flags(ws, proj).await.unwrap();
+ assert!(!flags.contribute && !flags.consume, "{flags:?}");
+
+ let mut query = profile_query(cwd, "claude-code");
+ query.profile_contribute = Some("1".into());
+ query.profile_consume = Some("1".into());
+ assert!(session_start_text(&state, query).await.is_some());
let flags = state.reader.project_profile_flags(ws, proj).await.unwrap();
assert_eq!(flags, ai_memory_store::ProjectProfileFlags::default());
}
diff --git a/crates/ai-memory-store/src/profile.rs b/crates/ai-memory-store/src/profile.rs
index 06dc06dc..27e61954 100644
--- a/crates/ai-memory-store/src/profile.rs
+++ b/crates/ai-memory-store/src/profile.rs
@@ -59,9 +59,9 @@ pub struct ProfileOptOut {
pub project: String,
}
-/// Persist `flags` on `project_id`, writing only when they differ from the
-/// stored values, so the session-start path that calls this on every fetch
-/// costs one indexed no-op statement in the common case.
+/// Persist `flags` on `project_id`. The session-start path calls this only
+/// when an explicit forwarded flag differs from the stored value; the
+/// conditional `WHERE` keeps a racing duplicate write a no-op.
pub(crate) fn set_project_profile_flags(
conn: &Connection,
project_id: ProjectId,
diff --git a/hooks/_lib.sh b/hooks/_lib.sh
index ca1e10e6..7a35b269 100644
--- a/hooks/_lib.sh
+++ b/hooks/_lib.sh
@@ -80,6 +80,16 @@ ai_memory_parse_toml_flag() {
"$file" | head -n 1 | sed 's/[[:space:]]*$//'
}
+# A resolved marker's `[profile]` flag as the explicit value the hook sends:
+# 0 for a falsy value (0/false/no/off, any case), 1 for anything else, an
+# absent key included. Parity with `profile_flag_value` in hook_capture.rs.
+ai_memory_profile_flag() {
+ case "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" in
+ 0 | false | no | off) printf '0' ;;
+ *) printf '1' ;;
+ esac
+}
+
# Whether "$1" (a marker file) declares anything beyond a `[capture]`
# section: any root-level scope key (workspace/project/project_strategy), or
# any of the other settings ai_memory_marker_qs / ai_memory_briefing_qs
@@ -486,10 +496,12 @@ ai_memory_marker_qs() {
ds=$(ai_memory_parse_toml_key "$marker" drop_subagent_captures)
idn=$(ai_memory_parse_toml_key "$marker" identity)
isty=$(ai_memory_parse_toml_key "$marker" identity_style)
- # `[profile] contribute` / `consume`, quoted or bare; the server
- # decides truthiness and keeps both on unless explicitly falsy.
- pcon=$(ai_memory_parse_toml_flag "$marker" contribute)
- pcons=$(ai_memory_parse_toml_flag "$marker" consume)
+ # `[profile] contribute` / `consume`, quoted or bare, always sent
+ # explicitly once a marker resolved (0 when falsy, else 1): removing
+ # the key re-enables; no marker sends nothing and the server keeps
+ # what it stored.
+ pcon=$(ai_memory_profile_flag "$(ai_memory_parse_toml_flag "$marker" contribute)")
+ pcons=$(ai_memory_profile_flag "$(ai_memory_parse_toml_flag "$marker" consume)")
[ -n "$pr" ] && ps="marker"
fi
# Before repo-root can fill `pr`: a repo-root name is an inference, while
diff --git a/hooks/lib/ai-memory-hook.ps1 b/hooks/lib/ai-memory-hook.ps1
index a05ca16d..c8d58775 100644
--- a/hooks/lib/ai-memory-hook.ps1
+++ b/hooks/lib/ai-memory-hook.ps1
@@ -151,6 +151,15 @@ function Get-AiMemoryTomlFlag {
return $null
}
+# A resolved marker's `[profile]` flag as the explicit value the hook sends:
+# "0" for a falsy value, "1" for anything else, an absent key included.
+# Parity with `profile_flag_value` in hook_capture.rs.
+function ConvertTo-AiMemoryProfileFlag {
+ param([string] $Value)
+ if ($Value -and (@("0", "false", "no", "off") -contains $Value.Trim().ToLowerInvariant())) { return "0" }
+ return "1"
+}
+
function Test-AiMemoryTruthy {
param([string] $Value)
if (-not $Value) { return $false }
@@ -337,8 +346,11 @@ function Get-AiMemoryMarkerQuery {
$identityStyle = Get-AiMemoryTomlKey -File $marker -Key "identity_style"
# `[profile] contribute` / `consume`, quoted or bare; the server
# decides truthiness and keeps both on unless explicitly falsy.
- $profileContribute = Get-AiMemoryTomlFlag -File $marker -Key "contribute"
- $profileConsume = Get-AiMemoryTomlFlag -File $marker -Key "consume"
+ # Always explicit once a marker resolved (0 when falsy, else 1): removing
+ # the key re-enables; no marker sends nothing and the server keeps
+ # what it stored.
+ $profileContribute = ConvertTo-AiMemoryProfileFlag (Get-AiMemoryTomlFlag -File $marker -Key "contribute")
+ $profileConsume = ConvertTo-AiMemoryProfileFlag (Get-AiMemoryTomlFlag -File $marker -Key "consume")
if ($proj) { $projSrc = "marker" }
}
# Before repo-root can fill $proj: a repo-root name is an inference, while
diff --git a/tests/hooks/test_lib.sh b/tests/hooks/test_lib.sh
index 17d856c0..90fc395a 100755
--- a/tests/hooks/test_lib.sh
+++ b/tests/hooks/test_lib.sh
@@ -244,11 +244,11 @@ assert_eq "json_string escapes a control byte as a \u escape" "yes" "$CTRL_ESCAP
# --- marker_qs --------------------------------------------------------
QS=$(ai_memory_marker_qs "$TMP/a/b/c")
-assert_eq "marker_qs single key" "&cwd=$(ai_memory_url_encode "$TMP/a/b/c")&workspace=deep" "$QS"
+assert_eq "marker_qs single key" "&cwd=$(ai_memory_url_encode "$TMP/a/b/c")&workspace=deep&profile_contribute=1&profile_consume=1" "$QS"
printf 'workspace = "ws1"\nproject = "p1"\nproject_strategy = "repo-root"\n' >"$TMP/a/b/.ai-memory.toml"
QS2=$(ai_memory_marker_qs "$TMP/a/b/c")
-assert_eq "closer marker wins" "&cwd=$(ai_memory_url_encode "$TMP/a/b/c")&workspace=ws1&project=p1&project_src=marker&project_strategy=repo-root" "$QS2"
+assert_eq "closer marker wins" "&cwd=$(ai_memory_url_encode "$TMP/a/b/c")&workspace=ws1&project=p1&project_src=marker&project_strategy=repo-root&profile_contribute=1&profile_consume=1" "$QS2"
QS3=$(ai_memory_marker_qs "$TMP/nonexistent")
assert_eq "no marker -> cwd only" "&cwd=$(ai_memory_url_encode "$TMP/nonexistent")" "$QS3"
@@ -269,7 +269,7 @@ assert_eq "capture-only marker: find_settings_marker skips it for the outer" \
"$TMP/scope/.ai-memory.toml" \
"$(ai_memory_find_settings_marker "$TMP/scope/inner")"
assert_eq "capture-only marker: marker_qs forwards the OUTER scope" \
- "&cwd=$(ai_memory_url_encode "$TMP/scope/inner")&workspace=acme&project=infra&project_src=marker" \
+ "&cwd=$(ai_memory_url_encode "$TMP/scope/inner")&workspace=acme&project=infra&project_src=marker&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/scope/inner")"
# --- repository identity (#708) ----------------------------------------
@@ -288,20 +288,20 @@ if command -v git >/dev/null 2>&1; then
"$(ai_memory_marker_qs "$TMP/idrepo")"
printf 'project = "mine"\n' >"$TMP/idrepo/.ai-memory.toml"
assert_eq "identity: a declared project routes by name" \
- "&cwd=$ID_CWD&project=mine&project_src=marker" \
+ "&cwd=$ID_CWD&project=mine&project_src=marker&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/idrepo")"
printf 'project = "mine"\nidentity = "Acme/Platform"\n' >"$TMP/idrepo/.ai-memory.toml"
assert_eq "identity: an explicit identity outranks the project" \
- "&cwd=$ID_CWD&project=mine&project_src=marker&identity=$(ai_memory_url_encode acme/platform)&identity_src=explicit" \
+ "&cwd=$ID_CWD&project=mine&project_src=marker&identity=$(ai_memory_url_encode acme/platform)&identity_src=explicit&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/idrepo")"
# #1033: the path style rides along with a remote identity only.
printf 'identity_style = "path"\n' >"$TMP/idrepo/.ai-memory.toml"
assert_eq "identity: the path style rides along with the remote" \
- "&cwd=$ID_CWD&identity=$(ai_memory_url_encode git.example.test/acme/api)&identity_src=git_remote&identity_style=path" \
+ "&cwd=$ID_CWD&identity=$(ai_memory_url_encode git.example.test/acme/api)&identity_src=git_remote&identity_style=path&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/idrepo")"
printf 'identity_style = "path"\nidentity = "Acme/Platform"\n' >"$TMP/idrepo/.ai-memory.toml"
assert_eq "identity: a declared identity sends no style" \
- "&cwd=$ID_CWD&identity=$(ai_memory_url_encode acme/platform)&identity_src=explicit" \
+ "&cwd=$ID_CWD&identity=$(ai_memory_url_encode acme/platform)&identity_src=explicit&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/idrepo")"
rm -rf "$TMP/idrepo"
fi
@@ -313,21 +313,21 @@ printf '[briefing]\ninject_on_session_start = true\n' >"$TMP/scope/inner/.ai-mem
assert_eq "briefing-only marker is a settings boundary, not transparent" \
"" "$(ai_memory_parse_toml_key "$(ai_memory_find_settings_marker "$TMP/scope/inner")" workspace)"
assert_eq "marker_qs stops at the briefing-only boundary" \
- "&cwd=$(ai_memory_url_encode "$TMP/scope/inner")" \
+ "&cwd=$(ai_memory_url_encode "$TMP/scope/inner")&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/scope/inner")"
# A marker that only sets `[profile]` keys is a settings boundary too, and
-# marker_qs forwards both flags (quoted or bare) for the server to interpret.
+# marker_qs forwards both flags (quoted or bare) as explicit 0/1 values.
mkdir -p "$TMP/profile-only/inner"
printf 'workspace = "outer"\n' >"$TMP/profile-only/.ai-memory.toml"
printf '[profile]\ncontribute = false\nconsume = "no"\n' >"$TMP/profile-only/inner/.ai-memory.toml"
assert_eq "profile-only marker is a settings boundary" \
"$TMP/profile-only/inner/.ai-memory.toml" "$(ai_memory_find_settings_marker "$TMP/profile-only/inner")"
assert_eq "marker_qs forwards [profile] contribute and consume" \
- "&cwd=$(ai_memory_url_encode "$TMP/profile-only/inner")&profile_contribute=false&profile_consume=no" \
+ "&cwd=$(ai_memory_url_encode "$TMP/profile-only/inner")&profile_contribute=0&profile_consume=0" \
"$(ai_memory_marker_qs "$TMP/profile-only/inner")"
-assert_eq "marker_qs omits [profile] keys a marker does not set" \
- "&cwd=$(ai_memory_url_encode "$TMP/profile-only")&workspace=outer" \
+assert_eq "marker_qs sends explicit [profile] defaults when a marker omits the keys" \
+ "&cwd=$(ai_memory_url_encode "$TMP/profile-only")&workspace=outer&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/profile-only")"
PSH=""
if command -v pwsh >/dev/null 2>&1; then
@@ -381,7 +381,7 @@ if command -v git >/dev/null 2>&1; then
printf 'workspace = "oss"\nproject_strategy = "repo-root"\n' >"$REPO/.ai-memory.toml"
QSR=$(ai_memory_marker_qs "$REPO/crates/cli")
assert_eq "repo-root: subdir resolves to repo basename" \
- "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=acme-api&project_src=repo-root&project_strategy=repo-root" \
+ "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=acme-api&project_src=repo-root&project_strategy=repo-root&profile_contribute=1&profile_consume=1" \
"$QSR"
rm -f "$REPO/.ai-memory.toml"
@@ -396,7 +396,7 @@ if command -v git >/dev/null 2>&1; then
>"$REPO/.ai-memory.toml"
QSO=$(ai_memory_marker_qs "$REPO/crates/cli")
assert_eq "marker project strategy overrides env default" \
- "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=pinned&project_src=marker&project_strategy=basename" \
+ "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=pinned&project_src=marker&project_strategy=basename&profile_contribute=1&profile_consume=1" \
"$QSO"
unset AI_MEMORY_PROJECT_STRATEGY
@@ -413,7 +413,7 @@ if command -v git >/dev/null 2>&1; then
if git -C "$REPO" worktree add -q "$WT" >/dev/null 2>&1; then
QSW=$(ai_memory_marker_qs "$WT")
assert_eq "repo-root: out-of-tree worktree collapses to main repo" \
- "&cwd=$(ai_memory_url_encode "$WT")&workspace=oss&project=acme-api&project_src=repo-root&project_strategy=repo-root" \
+ "&cwd=$(ai_memory_url_encode "$WT")&workspace=oss&project=acme-api&project_src=repo-root&project_strategy=repo-root&profile_contribute=1&profile_consume=1" \
"$QSW"
fi
@@ -422,7 +422,7 @@ if command -v git >/dev/null 2>&1; then
>"$REPO/.ai-memory.toml"
QSP=$(ai_memory_marker_qs "$REPO/crates/cli")
assert_eq "explicit project pin beats repo-root" \
- "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=pinned&project_src=marker&project_strategy=repo-root" \
+ "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=pinned&project_src=marker&project_strategy=repo-root&profile_contribute=1&profile_consume=1" \
"$QSP"
PSH=""
@@ -813,7 +813,7 @@ assert_eq "a server-only marker is a settings boundary" \
"$TMP/server-only/inner/.ai-memory.toml" \
"$(ai_memory_find_settings_marker "$TMP/server-only/inner")"
assert_eq "an unrouted repository is unchanged" \
- "&cwd=$(ai_memory_url_encode "$TMP/scope/inner")" \
+ "&cwd=$(ai_memory_url_encode "$TMP/scope/inner")&profile_contribute=1&profile_consume=1" \
"$(ai_memory_marker_qs "$TMP/scope/inner")"
AI_MEMORY_DATA_DIR="$TMP/routed-data"