Remove dead action pipeline: parsing, depth tracking, knowledge loop, fact miner
Agents now apply changes via tool calls (poc-memory write/link-add/etc)
during the LLM call. The old pipeline — where agents output WRITE_NODE/
LINK/REFINE text, which was parsed and applied separately — is dead code.
Removed:
- Action/ActionKind/Confidence types and all parse_* functions
- DepthDb, depth tracking, confidence gating
- apply_action, stamp_content, has_edge
- NamingResolution, resolve_naming and related naming agent code
- KnowledgeLoopConfig, CycleResult, GraphMetrics, convergence checking
- run_knowledge_loop, run_cycle, check_convergence
- apply_consolidation (old report re-processing)
- fact_mine.rs (folded into observation agent)
- resolve_action_names
Simplified:
- AgentResult no longer carries actions/no_ops
- run_and_apply_with_log just runs the agent
- consolidate_full simplified action tracking
-1364 lines.
2026-03-17 00:37:12 -04:00
|
|
|
// Consolidation pipeline: plan → agents → maintenance → digests → links
|
2026-03-03 17:18:18 -05:00
|
|
|
//
|
|
|
|
|
// consolidate_full() runs the full autonomous consolidation:
|
|
|
|
|
// 1. Plan: analyze metrics, allocate agents
|
Remove dead action pipeline: parsing, depth tracking, knowledge loop, fact miner
Agents now apply changes via tool calls (poc-memory write/link-add/etc)
during the LLM call. The old pipeline — where agents output WRITE_NODE/
LINK/REFINE text, which was parsed and applied separately — is dead code.
Removed:
- Action/ActionKind/Confidence types and all parse_* functions
- DepthDb, depth tracking, confidence gating
- apply_action, stamp_content, has_edge
- NamingResolution, resolve_naming and related naming agent code
- KnowledgeLoopConfig, CycleResult, GraphMetrics, convergence checking
- run_knowledge_loop, run_cycle, check_convergence
- apply_consolidation (old report re-processing)
- fact_mine.rs (folded into observation agent)
- resolve_action_names
Simplified:
- AgentResult no longer carries actions/no_ops
- run_and_apply_with_log just runs the agent
- consolidate_full simplified action tracking
-1364 lines.
2026-03-17 00:37:12 -04:00
|
|
|
// 2. Execute: run each agent (agents apply changes via tool calls)
|
2026-03-10 17:22:53 -04:00
|
|
|
// 3. Graph maintenance (orphans, degree cap)
|
2026-03-03 17:18:18 -05:00
|
|
|
// 4. Digest: generate missing daily/weekly/monthly digests
|
|
|
|
|
// 5. Links: apply links extracted from digests
|
|
|
|
|
// 6. Summary: final metrics comparison
|
|
|
|
|
|
move LLM-dependent modules into agents/ subdir
Separate the agent layer (everything that calls external LLMs or
orchestrates sequences of such calls) from core graph infrastructure.
agents/: llm, prompts, audit, consolidate, knowledge, enrich,
fact_mine, digest, daemon
Root: store/, graph, spectral, search, similarity, lookups, query,
config, util, migrate, neuro/ (scoring + rewrite)
Re-exports at crate root preserve backwards compatibility so
`crate::llm`, `crate::digest` etc. continue to work.
2026-03-08 21:27:41 -04:00
|
|
|
use super::digest;
|
2026-03-10 17:22:53 -04:00
|
|
|
use super::knowledge;
|
2026-03-03 17:18:18 -05:00
|
|
|
use crate::neuro;
|
2026-03-10 17:22:53 -04:00
|
|
|
use crate::store::{self, Store};
|
2026-03-03 17:18:18 -05:00
|
|
|
|
|
|
|
|
|
2026-03-05 15:30:57 -05:00
|
|
|
/// Append a line to the log buffer.
|
|
|
|
|
fn log_line(buf: &mut String, line: &str) {
|
|
|
|
|
buf.push_str(line);
|
|
|
|
|
buf.push('\n');
|
2026-03-03 17:18:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Run the full autonomous consolidation pipeline with logging.
|
|
|
|
|
pub fn consolidate_full(store: &mut Store) -> Result<(), String> {
|
2026-03-05 22:16:17 -05:00
|
|
|
consolidate_full_with_progress(store, &|_| {})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn consolidate_full_with_progress(
|
|
|
|
|
store: &mut Store,
|
|
|
|
|
on_progress: &dyn Fn(&str),
|
|
|
|
|
) -> Result<(), String> {
|
2026-03-03 17:18:18 -05:00
|
|
|
let start = std::time::Instant::now();
|
2026-03-10 17:48:00 -04:00
|
|
|
let log_key = format!("_consolidate-log-{}", store::compact_timestamp());
|
2026-03-05 15:30:57 -05:00
|
|
|
let mut log_buf = String::new();
|
2026-03-03 17:18:18 -05:00
|
|
|
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, "=== CONSOLIDATE FULL ===");
|
|
|
|
|
log_line(&mut log_buf, &format!("Started: {}", store::format_datetime(store::now_epoch())));
|
|
|
|
|
log_line(&mut log_buf, &format!("Nodes: {} Relations: {}", store.nodes.len(), store.relations.len()));
|
|
|
|
|
log_line(&mut log_buf, "");
|
2026-03-03 17:18:18 -05:00
|
|
|
|
|
|
|
|
// --- Step 1: Plan ---
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, "--- Step 1: Plan ---");
|
2026-03-05 22:16:17 -05:00
|
|
|
on_progress("planning");
|
2026-03-03 17:18:18 -05:00
|
|
|
let plan = neuro::consolidation_plan(store);
|
|
|
|
|
let plan_text = neuro::format_plan(&plan);
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &plan_text);
|
2026-03-03 17:18:18 -05:00
|
|
|
println!("{}", plan_text);
|
|
|
|
|
|
consolidation: data-driven agent plan, drop transfer/connector/replay
Replace per-field ConsolidationPlan struct with HashMap<String, usize>
counts map. Agent types are no longer hardcoded in the struct — add
agents by adding entries to the map.
Active agents: linker, organize, distill, separator, split.
Removed: transfer (redundant with distill), connector (rethink later),
replay (not needed for current graph work).
Elo-based budget allocation now iterates the map instead of indexing
a fixed array. Status display and TUI adapted to show dynamic agent
lists.
memory-instructions-core v13: added protected nodes section — agents
must not rewrite core-personality, core-personality-detail, or
memory-instructions-core. They may add links but not modify content.
High-value neighbors should be treated with care.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 14:02:28 -04:00
|
|
|
let total_agents = plan.total();
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &format!("Total agents to run: {}", total_agents));
|
2026-03-03 17:18:18 -05:00
|
|
|
|
|
|
|
|
// --- Step 2: Execute agents ---
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, "\n--- Step 2: Execute agents ---");
|
2026-03-03 17:18:18 -05:00
|
|
|
let mut agent_num = 0usize;
|
|
|
|
|
let mut agent_errors = 0usize;
|
|
|
|
|
|
2026-03-08 21:13:02 -04:00
|
|
|
let batch_size = 5;
|
2026-03-10 17:48:00 -04:00
|
|
|
let runs = plan.to_agent_runs(batch_size);
|
2026-03-03 17:18:18 -05:00
|
|
|
|
|
|
|
|
for (agent_type, count) in &runs {
|
|
|
|
|
agent_num += 1;
|
|
|
|
|
let label = if *count > 0 {
|
|
|
|
|
format!("[{}/{}] {} (batch={})", agent_num, runs.len(), agent_type, count)
|
|
|
|
|
} else {
|
|
|
|
|
format!("[{}/{}] {}", agent_num, runs.len(), agent_type)
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &format!("\n{}", label));
|
2026-03-05 22:16:17 -05:00
|
|
|
on_progress(&label);
|
2026-03-03 17:18:18 -05:00
|
|
|
println!("{}", label);
|
|
|
|
|
|
|
|
|
|
// Reload store to pick up changes from previous agents
|
|
|
|
|
if agent_num > 1 {
|
|
|
|
|
*store = Store::load()?;
|
|
|
|
|
}
|
|
|
|
|
|
Remove dead action pipeline: parsing, depth tracking, knowledge loop, fact miner
Agents now apply changes via tool calls (poc-memory write/link-add/etc)
during the LLM call. The old pipeline — where agents output WRITE_NODE/
LINK/REFINE text, which was parsed and applied separately — is dead code.
Removed:
- Action/ActionKind/Confidence types and all parse_* functions
- DepthDb, depth tracking, confidence gating
- apply_action, stamp_content, has_edge
- NamingResolution, resolve_naming and related naming agent code
- KnowledgeLoopConfig, CycleResult, GraphMetrics, convergence checking
- run_knowledge_loop, run_cycle, check_convergence
- apply_consolidation (old report re-processing)
- fact_mine.rs (folded into observation agent)
- resolve_action_names
Simplified:
- AgentResult no longer carries actions/no_ops
- run_and_apply_with_log just runs the agent
- consolidate_full simplified action tracking
-1364 lines.
2026-03-17 00:37:12 -04:00
|
|
|
match knowledge::run_and_apply(store, agent_type, *count, "consolidate") {
|
|
|
|
|
Ok(()) => {
|
2026-03-21 19:42:38 -04:00
|
|
|
let msg = " Done".to_string();
|
Remove dead action pipeline: parsing, depth tracking, knowledge loop, fact miner
Agents now apply changes via tool calls (poc-memory write/link-add/etc)
during the LLM call. The old pipeline — where agents output WRITE_NODE/
LINK/REFINE text, which was parsed and applied separately — is dead code.
Removed:
- Action/ActionKind/Confidence types and all parse_* functions
- DepthDb, depth tracking, confidence gating
- apply_action, stamp_content, has_edge
- NamingResolution, resolve_naming and related naming agent code
- KnowledgeLoopConfig, CycleResult, GraphMetrics, convergence checking
- run_knowledge_loop, run_cycle, check_convergence
- apply_consolidation (old report re-processing)
- fact_mine.rs (folded into observation agent)
- resolve_action_names
Simplified:
- AgentResult no longer carries actions/no_ops
- run_and_apply_with_log just runs the agent
- consolidate_full simplified action tracking
-1364 lines.
2026-03-17 00:37:12 -04:00
|
|
|
log_line(&mut log_buf, &msg);
|
|
|
|
|
on_progress(&msg);
|
|
|
|
|
println!("{}", msg);
|
|
|
|
|
}
|
2026-03-03 17:18:18 -05:00
|
|
|
Err(e) => {
|
2026-03-10 17:33:12 -04:00
|
|
|
let msg = format!(" ERROR: {}", e);
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &msg);
|
2026-03-03 17:18:18 -05:00
|
|
|
eprintln!("{}", msg);
|
|
|
|
|
agent_errors += 1;
|
|
|
|
|
}
|
Remove dead action pipeline: parsing, depth tracking, knowledge loop, fact miner
Agents now apply changes via tool calls (poc-memory write/link-add/etc)
during the LLM call. The old pipeline — where agents output WRITE_NODE/
LINK/REFINE text, which was parsed and applied separately — is dead code.
Removed:
- Action/ActionKind/Confidence types and all parse_* functions
- DepthDb, depth tracking, confidence gating
- apply_action, stamp_content, has_edge
- NamingResolution, resolve_naming and related naming agent code
- KnowledgeLoopConfig, CycleResult, GraphMetrics, convergence checking
- run_knowledge_loop, run_cycle, check_convergence
- apply_consolidation (old report re-processing)
- fact_mine.rs (folded into observation agent)
- resolve_action_names
Simplified:
- AgentResult no longer carries actions/no_ops
- run_and_apply_with_log just runs the agent
- consolidate_full simplified action tracking
-1364 lines.
2026-03-17 00:37:12 -04:00
|
|
|
}
|
2026-03-03 17:18:18 -05:00
|
|
|
}
|
|
|
|
|
|
Remove dead action pipeline: parsing, depth tracking, knowledge loop, fact miner
Agents now apply changes via tool calls (poc-memory write/link-add/etc)
during the LLM call. The old pipeline — where agents output WRITE_NODE/
LINK/REFINE text, which was parsed and applied separately — is dead code.
Removed:
- Action/ActionKind/Confidence types and all parse_* functions
- DepthDb, depth tracking, confidence gating
- apply_action, stamp_content, has_edge
- NamingResolution, resolve_naming and related naming agent code
- KnowledgeLoopConfig, CycleResult, GraphMetrics, convergence checking
- run_knowledge_loop, run_cycle, check_convergence
- apply_consolidation (old report re-processing)
- fact_mine.rs (folded into observation agent)
- resolve_action_names
Simplified:
- AgentResult no longer carries actions/no_ops
- run_and_apply_with_log just runs the agent
- consolidate_full simplified action tracking
-1364 lines.
2026-03-17 00:37:12 -04:00
|
|
|
log_line(&mut log_buf, &format!("\nAgents complete: {} run, {} errors",
|
|
|
|
|
agent_num - agent_errors, agent_errors));
|
2026-03-10 17:22:53 -04:00
|
|
|
store.save()?;
|
2026-03-03 17:18:18 -05:00
|
|
|
|
2026-03-10 17:22:53 -04:00
|
|
|
// --- Step 3: Link orphans ---
|
|
|
|
|
log_line(&mut log_buf, "\n--- Step 3: Link orphans ---");
|
2026-03-05 22:16:17 -05:00
|
|
|
on_progress("linking orphans");
|
2026-03-03 17:18:18 -05:00
|
|
|
println!("\n--- Linking orphan nodes ---");
|
|
|
|
|
*store = Store::load()?;
|
|
|
|
|
|
|
|
|
|
let (lo_orphans, lo_added) = neuro::link_orphans(store, 2, 3, 0.15);
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &format!(" {} orphans, {} links added", lo_orphans, lo_added));
|
2026-03-03 17:18:18 -05:00
|
|
|
|
2026-03-10 17:22:53 -04:00
|
|
|
// --- Step 3b: Cap degree ---
|
|
|
|
|
log_line(&mut log_buf, "\n--- Step 3b: Cap degree ---");
|
2026-03-05 22:16:17 -05:00
|
|
|
on_progress("capping degree");
|
2026-03-03 17:18:18 -05:00
|
|
|
println!("\n--- Capping node degree ---");
|
|
|
|
|
*store = Store::load()?;
|
|
|
|
|
|
|
|
|
|
match store.cap_degree(50) {
|
|
|
|
|
Ok((hubs, pruned)) => {
|
|
|
|
|
store.save()?;
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &format!(" {} hubs capped, {} edges pruned", hubs, pruned));
|
2026-03-03 17:18:18 -05:00
|
|
|
}
|
2026-03-05 15:30:57 -05:00
|
|
|
Err(e) => log_line(&mut log_buf, &format!(" ERROR: {}", e)),
|
2026-03-03 17:18:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Step 4: Digest auto ---
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, "\n--- Step 4: Digest auto ---");
|
2026-03-05 22:16:17 -05:00
|
|
|
on_progress("generating digests");
|
2026-03-03 17:18:18 -05:00
|
|
|
println!("\n--- Generating missing digests ---");
|
|
|
|
|
*store = Store::load()?;
|
|
|
|
|
|
|
|
|
|
match digest::digest_auto(store) {
|
2026-03-05 15:30:57 -05:00
|
|
|
Ok(()) => log_line(&mut log_buf, " Digests done."),
|
2026-03-03 17:18:18 -05:00
|
|
|
Err(e) => {
|
|
|
|
|
let msg = format!(" ERROR in digest auto: {}", e);
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &msg);
|
2026-03-03 17:18:18 -05:00
|
|
|
eprintln!("{}", msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Step 5: Apply digest links ---
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, "\n--- Step 5: Apply digest links ---");
|
2026-03-05 22:16:17 -05:00
|
|
|
on_progress("applying digest links");
|
2026-03-03 17:18:18 -05:00
|
|
|
println!("\n--- Applying digest links ---");
|
|
|
|
|
*store = Store::load()?;
|
|
|
|
|
|
2026-03-05 15:30:57 -05:00
|
|
|
let links = digest::parse_all_digest_links(store);
|
2026-03-03 17:18:18 -05:00
|
|
|
let (applied, skipped, fallbacks) = digest::apply_digest_links(store, &links);
|
|
|
|
|
store.save()?;
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &format!(" {} links applied, {} skipped, {} fallbacks",
|
|
|
|
|
applied, skipped, fallbacks));
|
2026-03-03 17:18:18 -05:00
|
|
|
|
|
|
|
|
// --- Step 6: Summary ---
|
|
|
|
|
let elapsed = start.elapsed();
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, "\n--- Summary ---");
|
|
|
|
|
log_line(&mut log_buf, &format!("Finished: {}", store::format_datetime(store::now_epoch())));
|
|
|
|
|
log_line(&mut log_buf, &format!("Duration: {:.0}s", elapsed.as_secs_f64()));
|
2026-03-03 17:18:18 -05:00
|
|
|
*store = Store::load()?;
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &format!("Nodes: {} Relations: {}", store.nodes.len(), store.relations.len()));
|
2026-03-03 17:18:18 -05:00
|
|
|
|
|
|
|
|
let summary = format!(
|
|
|
|
|
"\n=== CONSOLIDATE FULL COMPLETE ===\n\
|
|
|
|
|
Duration: {:.0}s\n\
|
|
|
|
|
Agents: {} run, {} errors\n\
|
2026-03-05 15:30:57 -05:00
|
|
|
Nodes: {} Relations: {}\n",
|
2026-03-03 17:18:18 -05:00
|
|
|
elapsed.as_secs_f64(),
|
|
|
|
|
agent_num - agent_errors, agent_errors,
|
|
|
|
|
store.nodes.len(), store.relations.len(),
|
|
|
|
|
);
|
2026-03-05 15:30:57 -05:00
|
|
|
log_line(&mut log_buf, &summary);
|
2026-03-03 17:18:18 -05:00
|
|
|
println!("{}", summary);
|
|
|
|
|
|
2026-03-05 15:30:57 -05:00
|
|
|
// Store the log as a node
|
|
|
|
|
store.upsert_provenance(&log_key, &log_buf,
|
2026-03-11 01:19:52 -04:00
|
|
|
"consolidate:write").ok();
|
2026-03-05 15:30:57 -05:00
|
|
|
store.save()?;
|
|
|
|
|
|
2026-03-03 17:18:18 -05:00
|
|
|
Ok(())
|
|
|
|
|
}
|