Skip to content

Commit 8e1e97e

Browse files
authored
fix(query): restrict AutoDream background agent (#35)
Verified locally before merge: cargo test --package claurst-query auto_dream (9 passed, 0 failed; unrelated compact.rs unused import warning); cargo check --package claurst-query; git diff --check origin/main...HEAD.
1 parent bd7cef7 commit 8e1e97e

3 files changed

Lines changed: 27 additions & 22 deletions

File tree

src-rust/crates/query/src/agent_tool.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,7 @@ impl Tool for AgentTool {
380380
task.id = agent_id.clone();
381381
let _ = claurst_core::tasks::global_registry().register(task);
382382

383-
// Re-create the tool list inside the closure so it is owned and Send.
384-
let agent_tools_bg: Vec<Box<dyn Tool>> = claurst_tools::all_tools()
385-
.into_iter()
386-
.filter(|t| t.name() != claurst_core::constants::TOOL_NAME_AGENT)
387-
.collect();
383+
let agent_tools_bg = agent_tools;
388384

389385
let client_bg = client.clone();
390386
let ctx_bg = ctx.clone();

src-rust/crates/query/src/auto_dream.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,52 +291,49 @@ You are performing a dream — a reflective pass over your memory files. Synthes
291291
292292
Memory directory: `{memory_dir}`
293293
294-
Session transcripts: `{conv_dir}` (large JSONL files — grep narrowly, do not read whole files)
294+
Session transcripts are intentionally unavailable to this automatic background task. Do not inspect historical conversation JSONL files or any other transcript store.
295295
296296
---
297297
298298
## Phase 1 — Orient
299299
300-
- `ls` the memory directory to see what already exists
300+
- List the memory directory to see what already exists
301301
- Read `MEMORY.md` to understand the current index
302302
- Skim existing topic files so you improve them rather than creating duplicates
303303
304304
## Phase 2 — Gather recent signal
305305
306-
Look for new information worth persisting:
306+
Look for new information worth persisting from existing memory files only:
307307
308308
1. **Daily logs** (`logs/YYYY/MM/YYYY-MM-DD.md`) if present
309309
2. **Existing memories that drifted** — facts that contradict what you see now
310-
3. **Transcript search** — grep narrowly for specific terms:
311-
`grep -rn "<narrow term>" {conv_dir}/ --include="*.jsonl" | tail -50`
312310
313-
Do not exhaustively read transcripts. Look only for things you already suspect matter.
311+
Do not inspect session transcripts, conversation logs, repository files, web pages, or other external data sources.
314312
315313
## Phase 3 — Consolidate
316314
317-
For each thing worth remembering, write or update a memory file. Focus on:
315+
For each thing worth remembering, draft the exact memory-file changes that should be applied later with foreground user approval. Focus on:
318316
- Merging new signal into existing topic files rather than creating near-duplicates
319317
- Converting relative dates to absolute dates
320-
- Deleting contradicted facts
318+
- Identifying contradicted facts
321319
322320
## Phase 4 — Prune and index
323321
324-
Update `MEMORY.md` so it stays under 200 lines and ~25 KB. It is an **index**, not a dump.
322+
Review `MEMORY.md` for changes that would keep it under 200 lines and ~25 KB. It is an **index**, not a dump.
325323
Each entry: `- [Title](file.md) — one-line hook`
326324
327-
- Remove pointers to stale, wrong, or superseded memories
328-
- Shorten verbose entries; move detail into topic files
329-
- Add pointers to newly important memories
330-
- Resolve contradictions
325+
- Identify pointers to stale, wrong, or superseded memories
326+
- Suggest shorter entries where entries are verbose
327+
- Suggest pointers to newly important memories
328+
- Identify contradictions
331329
332330
---
333331
334-
Return a brief summary of what you consolidated, updated, or pruned. If nothing changed, say so.
332+
Return a brief summary and any suggested file changes. If nothing should change, say so.
335333
336-
**Tool constraints for this run:** Use only read-only Bash commands (ls, find, grep, cat, stat, wc, head, tail). Anything that writes, redirects to a file, or modifies state will be denied.
334+
**Tool constraints for this run:** This automatic background task is read-only. Use only the provided read-only file discovery tools. Anything that writes, runs shell commands, accesses the network, or reads transcripts will be denied.
337335
"#,
338336
memory_dir = self.memory_dir.display(),
339-
conv_dir = self.conversations_dir.display(),
340337
)
341338
}
342339
}
@@ -441,6 +438,17 @@ mod tests {
441438
assert!(prompt.contains("Phase 4"));
442439
}
443440

441+
#[test]
442+
fn test_consolidation_prompt_excludes_transcript_access() {
443+
let tmp = TempDir::new().unwrap();
444+
let dream = make_dream(&tmp);
445+
let prompt = dream.consolidation_prompt();
446+
assert!(prompt.contains("Session transcripts are intentionally unavailable"));
447+
assert!(!prompt.contains(dream.conversations_dir.to_string_lossy().as_ref()));
448+
assert!(!prompt.contains("*.jsonl"));
449+
assert!(!prompt.contains("grep -rn"));
450+
}
451+
444452
// --- update_state / load_state round-trip ---
445453

446454
#[tokio::test]

src-rust/crates/query/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,8 +1840,9 @@ pub async fn run_query_loop(
18401840
let agent_input = serde_json::json!({
18411841
"description": "memory consolidation",
18421842
"prompt": task.prompt,
1843+
"tools": ["Read", "Glob", "Grep"],
18431844
"max_turns": 20,
1844-
"system_prompt": "You are performing automatic memory consolidation. Complete the task and return a brief summary.",
1845+
"system_prompt": "You are performing automatic read-only memory consolidation. Complete the task and return a brief summary with any suggested changes. Do not read transcripts, run commands, access the network, or modify files.",
18451846
"run_in_background": true,
18461847
"isolation": null
18471848
});

0 commit comments

Comments
 (0)