Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

chore: move memory prompt builder into extension (#24558)

jif-oaide513a83f3fa
diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock
index 4b437b7eb4..4268666fc6 100644
--- a/codex-rs/Cargo.lock
+++ b/codex-rs/Cargo.lock
@@ -3182,10 +3182,10 @@ dependencies = [
"codex-core",
"codex-extension-api",
"codex-features",
- "codex-memories-read",
"codex-tools",
"codex-utils-absolute-path",
"codex-utils-output-truncation",
+ "codex-utils-template",
"pretty_assertions",
"schemars 0.8.22",
"serde",
@@ -3202,11 +3202,7 @@ dependencies = [
"codex-protocol",
"codex-shell-command",
"codex-utils-absolute-path",
- "codex-utils-output-truncation",
- "codex-utils-template",
"pretty_assertions",
- "tempfile",
- "tokio",
]
[[package]]
diff --git a/codex-rs/ext/memories/BUILD.bazel b/codex-rs/ext/memories/BUILD.bazel
index 5da7a952ab..0d9e20695f 100644
--- a/codex-rs/ext/memories/BUILD.bazel
+++ b/codex-rs/ext/memories/BUILD.bazel
@@ -3,4 +3,7 @@ load("//:defs.bzl", "codex_rust_crate")
codex_rust_crate(
name = "memories",
crate_name = "codex_memories_extension",
+ compile_data = glob([
+ "templates/**",
+ ]),
)
diff --git a/codex-rs/ext/memories/Cargo.toml b/codex-rs/ext/memories/Cargo.toml
index 5485eedc9f..ca55eba84a 100644
--- a/codex-rs/ext/memories/Cargo.toml
+++ b/codex-rs/ext/memories/Cargo.toml
@@ -17,10 +17,10 @@ async-trait = { workspace = true }
codex-core = { workspace = true }
codex-extension-api = { workspace = true }
codex-features = { workspace = true }
-codex-memories-read = { workspace = true }
codex-tools = { workspace = true }
codex-utils-absolute-path = { workspace = true }
codex-utils-output-truncation = { workspace = true }
+codex-utils-template = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
diff --git a/codex-rs/ext/memories/src/extension.rs b/codex-rs/ext/memories/src/extension.rs
index a50949e919..70f9f5ddcd 100644
--- a/codex-rs/ext/memories/src/extension.rs
+++ b/codex-rs/ext/memories/src/extension.rs
@@ -10,10 +10,10 @@ use codex_extension_api::ThreadLifecycleContributor;
use codex_extension_api::ThreadStartInput;
use codex_extension_api::ToolContributor;
use codex_features::Feature;
-use codex_memories_read::build_memory_tool_developer_instructions;
use codex_utils_absolute_path::AbsolutePathBuf;
use crate::local::LocalMemoriesBackend;
+use crate::prompts::build_memory_tool_developer_instructions;
use crate::tools;
/// Contributes Codex memory read-path prompt context and memory read tools.
diff --git a/codex-rs/ext/memories/src/lib.rs b/codex-rs/ext/memories/src/lib.rs
index bb7b07bc69..6f06f95d4f 100644
--- a/codex-rs/ext/memories/src/lib.rs
+++ b/codex-rs/ext/memories/src/lib.rs
@@ -1,6 +1,7 @@
mod backend;
mod extension;
mod local;
+mod prompts;
mod schema;
mod tools;
@@ -11,6 +12,7 @@ pub(crate) const MAX_LIST_RESULTS: usize = 2_000;
pub(crate) const DEFAULT_SEARCH_MAX_RESULTS: usize = 200;
pub(crate) const MAX_SEARCH_RESULTS: usize = 200;
pub(crate) const DEFAULT_READ_MAX_TOKENS: usize = 20_000;
+pub(crate) const MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT: usize = 2_500;
pub(crate) const MEMORY_TOOLS_NAMESPACE: &str = "memories/";
pub(crate) const LIST_TOOL_NAME: &str = "list";
diff --git a/codex-rs/memories/read/src/prompts.rs b/codex-rs/ext/memories/src/prompts.rs
similarity index 89%
rename from codex-rs/memories/read/src/prompts.rs
rename to codex-rs/ext/memories/src/prompts.rs
index 5bba68aa69..6546206b1c 100644
--- a/codex-rs/memories/read/src/prompts.rs
+++ b/codex-rs/ext/memories/src/prompts.rs
@@ -1,5 +1,4 @@
use crate::MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT;
-use crate::memory_root;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_output_truncation::TruncationPolicy;
use codex_utils_output_truncation::truncate_text;
@@ -21,14 +20,14 @@ fn parse_embedded_template(source: &'static str, template_name: &str) -> Templat
}
}
-/// Build the read-path prompt that is added to developer instructions.
+/// Build the memory read-path prompt that is added to developer instructions.
///
/// Large `memory_summary.md` files are truncated at
/// [MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT].
-pub async fn build_memory_tool_developer_instructions(
+pub(crate) async fn build_memory_tool_developer_instructions(
codex_home: &AbsolutePathBuf,
) -> Option<String> {
- let base_path = memory_root(codex_home);
+ let base_path = codex_home.join("memories");
let memory_summary_path = base_path.join("memory_summary.md");
let memory_summary = fs::read_to_string(&memory_summary_path)
.await
diff --git a/codex-rs/memories/read/src/prompts_tests.rs b/codex-rs/ext/memories/src/prompts_tests.rs
similarity index 100%
rename from codex-rs/memories/read/src/prompts_tests.rs
rename to codex-rs/ext/memories/src/prompts_tests.rs
diff --git a/codex-rs/memories/read/templates/memories/read_path.md b/codex-rs/ext/memories/templates/memories/read_path.md
similarity index 100%
rename from codex-rs/memories/read/templates/memories/read_path.md
rename to codex-rs/ext/memories/templates/memories/read_path.md
diff --git a/codex-rs/memories/read/BUILD.bazel b/codex-rs/memories/read/BUILD.bazel
index 54cf2e3b00..5cf6ec799b 100644
--- a/codex-rs/memories/read/BUILD.bazel
+++ b/codex-rs/memories/read/BUILD.bazel
@@ -3,7 +3,4 @@ load("//:defs.bzl", "codex_rust_crate")
codex_rust_crate(
name = "read",
crate_name = "codex_memories_read",
- compile_data = glob([
- "templates/**",
- ]),
)
diff --git a/codex-rs/memories/read/Cargo.toml b/codex-rs/memories/read/Cargo.toml
index af11826ff2..2c0c5f2c95 100644
--- a/codex-rs/memories/read/Cargo.toml
+++ b/codex-rs/memories/read/Cargo.toml
@@ -16,11 +16,6 @@ workspace = true
codex-protocol = { workspace = true }
codex-shell-command = { workspace = true }
codex-utils-absolute-path = { workspace = true }
-codex-utils-output-truncation = { workspace = true }
-codex-utils-template = { workspace = true }
-tokio = { workspace = true, features = ["fs"] }
[dev-dependencies]
pretty_assertions = { workspace = true }
-tempfile = { workspace = true }
-tokio = { workspace = true, features = ["fs", "macros"] }
diff --git a/codex-rs/memories/read/src/lib.rs b/codex-rs/memories/read/src/lib.rs
index ac6aa4d7f1..4965dfd2b6 100644
--- a/codex-rs/memories/read/src/lib.rs
+++ b/codex-rs/memories/read/src/lib.rs
@@ -6,15 +6,10 @@
pub mod citations;
mod metrics;
-mod prompts;
pub mod usage;
use codex_utils_absolute_path::AbsolutePathBuf;
-pub use prompts::build_memory_tool_developer_instructions;
-
-const MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT: usize = 2_500;
-
pub fn memory_root(codex_home: &AbsolutePathBuf) -> AbsolutePathBuf {
codex_home.join("memories")
}