Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(bootstrap): cap a lone chunk's output like any chunk (#928)
Felipe Neves Ricardode2719d8c9ce
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex adae0176..7cdb9f58 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- `ai-memory bootstrap` on a repository small enough for one chunk no longer+ asks the provider for 64K output tokens. The output cap was keyed on the+ number of chunks, so the only chunk of a small repo got the one-shot cap+ meant for `--chunk-input-tokens 0`, and every such run failed on a+ 64K-context model. Under chunking (the default) every call now asks for up+ to 16K; only `--chunk-input-tokens 0` keeps 64K. The `--max-input-tokens`+ help no longer claims its 150K default leaves room for 64K of output in a+ 200K window. (#928)+## [2.4.1] - 2026-09-25### Changeddiff --git a/crates/ai-memory-cli/src/cli.rs b/crates/ai-memory-cli/src/cli.rsindex 22f3ac38..9499ba09 100644--- a/crates/ai-memory-cli/src/cli.rs+++ b/crates/ai-memory-cli/src/cli.rs@@ -1269,11 +1269,14 @@ pub struct BootstrapArgs {/// Maximum total tokens of source text sent to the LLM in one/// run. When the collected sources exceed this, lower-priority/// inputs (older git commits, then code module headers, then- /// docs) are dropped first. Default is 150K — comfortably under- /// Haiku/Sonnet 4.5's 200K context (leaves room for the ~64K- /// output budget) — so the model sees as much of your project- /// as possible. Lower it explicitly only if you're cost-- /// sensitive or running against a smaller-context provider.+ /// docs) are dropped first. Default is 150K, so the model sees as+ /// much of your project as possible; with chunking on (the+ /// default), each call carries at most `--chunk-input-tokens` of+ /// it plus up to 16K output tokens. Lower it if you're+ /// cost-sensitive. With `--chunk-input-tokens 0`, this whole+ /// budget goes into one call that also asks for up to 64K output+ /// tokens, so budget + 64K must fit the model's context window+ /// (the 150K default does not fit a 200K window).#[arg(long, default_value_t = 150_000)]pub max_input_tokens: usize,/// Max estimated input tokens per LLM call. When pruned sources exceeddiff --git a/crates/ai-memory-consolidate/src/bootstrap.rs b/crates/ai-memory-consolidate/src/bootstrap.rsindex 4ea11c0d..7f5734f4 100644--- a/crates/ai-memory-consolidate/src/bootstrap.rs+++ b/crates/ai-memory-consolidate/src/bootstrap.rs@@ -516,7 +516,8 @@ impl Bootstrap {let mut prior: Vec<String> = pages_by_path.keys().cloned().collect();prior.sort_unstable();let prior_refs: Vec<&str> = prior.iter().map(String::as_str).collect();- let request = build_chunk_request(chunk, idx + 1, llm_chunks, &prior_refs);+ let request =+ build_chunk_request(chunk, idx + 1, llm_chunks, chunk_budget, &prior_refs);info!(chunk = idx + 1,total = llm_chunks,@@ -1351,6 +1352,7 @@ fn build_chunk_request(sources: &[BootstrapSource],chunk_index: usize,chunk_total: usize,+ chunk_budget: usize,prior_paths: &[&str],) -> ChatRequest {let mut buf = String::with_capacity(8_192);@@ -1384,12 +1386,7 @@ fn build_chunk_request(buf.push_str(&src.text);buf.push_str("\n\n");}- let max_tokens = if chunk_total > 1 {- // Each chunk targets a smaller page batch; keeps Cursor bridge responses bounded.- 16_000- } else {- 64_000- };+ let max_tokens = bootstrap_chunk_max_tokens(chunk_budget);ChatRequest {system: Some(SYSTEM_PROMPT.into()),messages: vec![ChatMessage {@@ -1401,6 +1398,20 @@ fn build_chunk_request(}}+/// Output cap for one bootstrap LLM call.+///+/// With chunking on (the default), every call is a chunk that fits+/// `chunk_budget`, including the only chunk of a small repo, so every call+/// gets the chunk cap: it keeps Cursor bridge responses bounded and, with the+/// default 24K chunk budget, fits a 64K-context model. Keying the cap on the+/// chunk count instead sent a small repo's single chunk 64K output tokens,+/// which no 64K-context model can accept. Only an operator who disables+/// chunking (`chunk_budget == 0`, one call with the whole pruned bundle) gets+/// the large cap.+const fn bootstrap_chunk_max_tokens(chunk_budget: usize) -> u32 {+ if chunk_budget == 0 { 64_000 } else { 16_000 }+}+/// Highest `decisions/NNNN-…` serial seen in `prior_paths`, or 0.fn next_decision_serial(prior_paths: &[&str]) -> u32 {prior_paths@@ -1779,6 +1790,24 @@ mod tests {assert_eq!(chunks.len(), 1);}+ /// A repo small enough for one chunk, under default chunking, must get the+ /// chunk output cap: asking for 64K output tokens made every call fail on+ /// a 64K-context model. Control: disabling chunking keeps the one-shot cap.+ #[test]+ fn a_small_repos_only_chunk_gets_the_chunk_output_cap() {+ let s = BootstrapSource {+ kind: SourceKind::Readme,+ label: "README".into(),+ text: "hello".into(),+ };+ let chunks = plan_bootstrap_chunks(vec![s], DEFAULT_CHUNK_INPUT_TOKENS);+ assert_eq!(chunks.len(), 1);+ let chunked = build_chunk_request(&chunks[0], 1, 1, DEFAULT_CHUNK_INPUT_TOKENS, &[]);+ assert_eq!(chunked.max_tokens, 16_000);+ let one_shot = build_chunk_request(&chunks[0], 1, 1, 0, &[]);+ assert_eq!(one_shot.max_tokens, 64_000);+ }+#[test]fn plan_chunks_splits_when_over_budget() {let mut sources = Vec::new();diff --git a/docs/install.md b/docs/install.mdindex ff774284..ea445be8 100644--- a/docs/install.md+++ b/docs/install.md@@ -2167,7 +2167,9 @@ remote or uses a custom host/port."scratch" only as a defensive fallback forhook events with no usable cwd.)--max-input-tokens N (default: 150000; total source budget after prune)---chunk-input-tokens N (default: 24000; per LLM call; 0 = single call)+--chunk-input-tokens N (default: 24000; per LLM call, each asking for up+ to 16K output tokens; 0 = single call asking for+ up to 64K, so input + 64K must fit the context)--since "30 days ago" (git log filter; supports "N days/months/years ago" + YYYY-MM-DD)--exclude-git (skip commit history)--exclude-readme (skip README)