Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
read project names from system reminders
Raine Virtabfdef04fd4ff
diff --git a/src/project.rs b/src/project.rsindex 187662e..3ec8fac 100644--- a/src/project.rs+++ b/src/project.rs@@ -9,24 +9,35 @@ const WORKING_DIRECTORY_PREFIXES: [&str; 3] = [];pub fn name_from_system(system: Option<&Value>) -> Option<String> {- system_text(system)- .lines()- .find_map(working_directory_from_line)- .and_then(name_from_working_directory)+ system.and_then(name_from_value)+}++pub fn name_from_request<'a>(+ system: Option<&Value>,+ message_contents: impl IntoIterator<Item = &'a Value>,+) -> Option<String> {+ name_from_system(system).or_else(|| message_contents.into_iter().find_map(name_from_value))}-fn system_text(system: Option<&Value>) -> String {- match system {- Some(Value::String(text)) => text.clone(),- Some(Value::Array(blocks)) => blocks- .iter()- .filter_map(|block| block.get("text").and_then(Value::as_str))- .collect::<Vec<_>>()- .join("\n"),- _ => String::new(),+fn name_from_value(value: &Value) -> Option<String> {+ match value {+ Value::String(text) => name_from_text(text),+ Value::Array(values) => values.iter().find_map(name_from_value),+ Value::Object(object) => object+ .get("text")+ .and_then(Value::as_str)+ .and_then(name_from_text)+ .or_else(|| object.get("content").and_then(name_from_value)),+ _ => None,}}+fn name_from_text(text: &str) -> Option<String> {+ text.lines()+ .find_map(working_directory_from_line)+ .and_then(name_from_working_directory)+}+fn working_directory_from_line(line: &str) -> Option<&str> {let line = line.trim().strip_prefix("- ").unwrap_or(line.trim());WORKING_DIRECTORY_PREFIXES.iter().find_map(|prefix| {@@ -109,6 +120,19 @@ mod tests {assert_eq!(name_from_system(Some(&system)).as_deref(), Some("example"));}+ #[test]+ fn reads_working_directory_from_message_system_reminder() {+ let content = json!([+ {"type": "text", "text": "hello"},+ {"type": "text", "text": "<system-reminder>\n# Environment\n - Primary working directory: /home/user/example\n</system-reminder>"}+ ]);++ assert_eq!(+ name_from_request(None, [&content]).as_deref(),+ Some("example")+ );+ }+#[test]fn resolves_linked_worktree_to_main_repository_name() {let temp = tempdir().unwrap();diff --git a/src/server.rs b/src/server.rsindex e90e908..3bb13fc 100644--- a/src/server.rs+++ b/src/server.rs@@ -248,8 +248,10 @@ async fn dispatch_request(}};- if let Some(project) = project::name_from_system(body.extra.get("system"))- && let Some(monitor) = state.monitor.as_ref()+ if let Some(project) = project::name_from_request(+ body.extra.get("system"),+ body.messages.iter().rev().map(|message| &message.content),+ ) && let Some(monitor) = state.monitor.as_ref(){monitor.project_resolved(&req_id, project);}diff --git a/tests/server.rs b/tests/server.rsindex ba7f334..9832a1d 100644--- a/tests/server.rs+++ b/tests/server.rs@@ -267,7 +267,7 @@ async fn monitor_records_successful_request_events() {.uri("/v1/messages/count_tokens").header("content-type", "application/json").body(body_string(- r##"{"model":"gpt-5.4","messages":[{"role":"user","content":"hello"}],"system":"# Environment\n - Primary working directory: /projects/example","output_config":{"effort":"high"}}"##,+ r##"{"model":"gpt-5.4","messages":[{"role":"user","content":[{"type":"text","text":"hello"},{"type":"text","text":"<system-reminder>\n# Environment\n - Primary working directory: /projects/example\n</system-reminder>"}]}],"output_config":{"effort":"high"}}"##,)).unwrap(),)