Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(workstream): skip Codex's instructions when no project AGENTS.md contributes
Felipe Neves Ricardo3f84630b6684
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b43a8edc..70d75cad 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Fixed+- Fixed a global `~/.codex/AGENTS.md` reaching the cross-project profile as+ the user's own words. Codex injects its instruction files as a user message+ headed `# AGENTS.md instructions for <cwd>` when a project `AGENTS.md`+ contributes, and `# AGENTS.md instructions` with no directory when only the+ global file does. The transcript import recognized only the first heading,+ so `backfill` stored the global file as a user prompt in every project, and+ the profile harvest admitted its "always"/"never" lines, which repeat across+ projects by construction. The import now recognizes both headings. (#1173)- Fixed Cursor tool calls being stored with no title or content: Cursor's ownhooks, and the Claude Code hooks Cursor also runs, send Claude's`tool_name`/`tool_input` fields, but Cursor was missing from the tool-capturediff --git a/crates/ai-memory-core/src/lib.rs b/crates/ai-memory-core/src/lib.rsindex 11229a6a..f0efb63b 100644--- a/crates/ai-memory-core/src/lib.rs+++ b/crates/ai-memory-core/src/lib.rs@@ -23,7 +23,9 @@ pub mod repository_identity;pub use repository_identity::{MARKER_FILENAME, MARKER_FILENAMES};pub mod routing_skills;pub mod scaffolding;-pub use scaffolding::{looks_like_markup_block, looks_like_scaffolding};+pub use scaffolding::{+ looks_like_codex_instructions, looks_like_markup_block, looks_like_scaffolding,+};pub mod routing_snippet;pub mod sanitize;pub mod slots;diff --git a/crates/ai-memory-core/src/scaffolding.rs b/crates/ai-memory-core/src/scaffolding.rsindex d720a61e..ab8811aa 100644--- a/crates/ai-memory-core/src/scaffolding.rs+++ b/crates/ai-memory-core/src/scaffolding.rs@@ -86,6 +86,21 @@ pub fn looks_like_markup_block(candidate: &str) -> bool {false}+/// `true` when `candidate` opens with the instruction files Codex injects as a+/// user message: `# AGENTS.md instructions for <cwd>` when a project+/// `AGENTS.md` contributes, a bare `# AGENTS.md instructions` when only the+/// global `~/.codex/AGENTS.md` does. The text is the user's or the+/// repository's standing rules, not something the user typed in the session.+#[must_use]+pub fn looks_like_codex_instructions(candidate: &str) -> bool {+ candidate+ .trim_start()+ .strip_prefix("# AGENTS.md instructions")+ .is_some_and(|rest| {+ rest.is_empty() || rest.starts_with(" for ") || rest.starts_with(['\n', '\r'])+ })+}+#[cfg(test)]mod tests {use super::*;@@ -159,6 +174,22 @@ mod tests {assert!(!looks_like_scaffolding("well-done"));}+ #[test]+ fn both_codex_instruction_headers_are_recognized() {+ assert!(looks_like_codex_instructions(+ "# AGENTS.md instructions for /repo\n\n<INSTRUCTIONS>rules</INSTRUCTIONS>"+ ));+ assert!(looks_like_codex_instructions(+ "# AGENTS.md instructions\n\n<INSTRUCTIONS>rules</INSTRUCTIONS>"+ ));+ assert!(!looks_like_codex_instructions(+ "# AGENTS.md instructionsets are confusing"+ ));+ assert!(!looks_like_codex_instructions(+ "update the AGENTS.md instructions for the release flow"+ ));+ }+#[test]fn empty_or_blank_is_scaffolding() {assert!(looks_like_scaffolding(""));diff --git a/crates/ai-memory-workstream/src/transcript.rs b/crates/ai-memory-workstream/src/transcript.rsindex 6ad1aaca..df8eac6a 100644--- a/crates/ai-memory-workstream/src/transcript.rs+++ b/crates/ai-memory-workstream/src/transcript.rs@@ -2151,7 +2151,7 @@ fn codex_synthetic_context(agent: AgentKind, role: &str, text: &str) -> bool {let trimmed = text.trim_start();match agent {AgentKind::Codex => {- trimmed.starts_with("# AGENTS.md instructions for ")+ ai_memory_core::looks_like_codex_instructions(trimmed)|| trimmed.starts_with("<environment_context>")|| trimmed.starts_with("<permissions instructions>")|| trimmed.starts_with("<INSTRUCTIONS>")@@ -5468,6 +5468,20 @@ mod tests {assert_eq!(events[0].content, "actual request");}+ #[test]+ fn codex_adapter_excludes_the_bare_instructions_heading() {+ // Codex omits ` for <cwd>` when only the global AGENTS.md contributes.+ // Backfill then replayed that file as a prompt in every project.+ let value = json!({"type":"response_item","payload":{"type":"message","role":"user","content":[+ {"type":"input_text","text":"# AGENTS.md instructions\n\n<INSTRUCTIONS>\nNever commit secrets.\n</INSTRUCTIONS>"},+ {"type":"input_text","text":"<environment_context>\n <cwd>/repo</cwd>\n</environment_context>"}+ ]}});+ let mut events = Vec::new();+ let mut losses = Vec::new();+ parse_codex(&value, "session", "record", &mut events, &mut losses);+ assert!(events.is_empty(), "{events:?}");+ }+#[test]fn codex_adapter_keeps_current_top_level_compaction_shape() {let value = json!({