Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions COMMIT_MSG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Commit Message — SlopLedger (#2127)

## Summary

Add a durable `SlopLedger` that makes invisible architectural residue
visible and queryable across agent sessions.

Closes: https://github.com/Hmbown/CodeWhale/issues/2127

## Problem

AI agents often leave behind invisible "slop" after a task:
compatibility shims, unmigrated callers, duplicated concepts,
naming drift, stale docs/tests, suspected dead code, and tool gaps.

Currently these residues are untracked. The next agent rediscovers
them, amplifies them, or mistakes them for intended architecture.

## Solution

A persistent JSON-backed ledger (`~/.codewhale/slop_ledger/slop_ledger.json`)
with four model-callable tools and a `/slop` slash command.

### Data Model

- **10 classification buckets**: retained_compatibility, unmigrated_callers,
duplicate_concepts, naming_drift, stale_docs, stale_tests,
suspected_dead_code, unverified_public_behavior, tool_gaps, accepted_debt
- **Severity**: critical | high | medium | low | info
- **Confidence**: certain | high | medium | low
- **Status lifecycle**: open → in_progress → resolved | accepted | wontfix
- Each entry carries: owner, source links, title, description,
cleanup recommendation, timestamps, and optional task_id / thread_id

### Tools (model-callable)

| Tool | Description |
|---|---|
| `slop_ledger_append` | Append entries with bucket, severity, confidence, title, description |
| `slop_ledger_query` | Query with bucket/severity/status/text filters |
| `slop_ledger_update` | Update entry status |
| `slop_ledger_export` | Export as Markdown for handoffs / GitHub issues |

### Slash Command

- `/slop` — print summary
- `/slop query` — list entries
- `/slop export` — Markdown export
- Alias: `/canzha`

### Files Changed

| File | Change |
|---|---|
| `crates/tui/src/slop_ledger.rs` | **New** — 1089 lines |
| `crates/tui/src/main.rs` | +1: mod declaration |
| `crates/tui/src/tools/registry.rs` | +16: builder method |
| `crates/tui/src/core/engine/tool_setup.rs` | +1: registration |
| `crates/tui/src/commands/mod.rs` | +10: command + dispatch |
| `crates/tui/src/commands/config.rs` | +41: handler |

### Tests

8 unit tests: bucket roundtrip, save/load, query by bucket/search,
update status, markdown export, empty ledger, summary counts.

## How to Test

```bash
cargo test -p codewhale-tui -- slop_ledger
```

In TUI: `/slop`, `/slop query`, `/slop export`
41 changes: 41 additions & 0 deletions crates/tui/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,47 @@ pub fn theme(app: &mut App, arg: Option<&str>) -> CommandResult {
}
}

/// `/slop [query|export]` — inspect or export the slop ledger (#2127).
/// With no arguments, prints a summary. `query` shows filtered results;
/// `export` outputs the full ledger as Markdown.
pub fn slop(_app: &mut App, arg: Option<&str>) -> CommandResult {
let arg = arg.map(str::trim).unwrap_or("");
let ledger = match crate::slop_ledger::SlopLedger::load() {
Ok(l) => l,
Err(e) => return CommandResult::error(format!("Failed to load slop ledger: {e}")),
};

match arg {
"" => CommandResult::message(ledger.summary()),
"query" | "q" => {
if ledger.is_empty() {
return CommandResult::message("Slop ledger is empty.");
}
let mut out = String::new();
for entry in &ledger.query(&Default::default()) {
use std::fmt::Write;
let _ = writeln!(
out,
"[{}] {} ({:?} | {:?}) — {}",
&entry.id[..8],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Slicing &entry.id[..8] directly can panic if the ID is shorter than 8 bytes or sliced on an invalid UTF-8 boundary. Use .get(..8) to safely slice the ID.

                    entry.id.get(..8).unwrap_or(&entry.id),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show id

Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
entry.bucket.as_str(),
entry.severity,
entry.status,
entry.title
);
}
CommandResult::message(out)
}
"export" | "e" => {
let md = ledger.export_markdown(None, None);
CommandResult::message(md)
}
_ => CommandResult::error(format!(
"Unknown /slop action '{arg}'. Use /slop, /slop query, or /slop export."
)),
}
}

/// Manage workspace-level trust and the per-path allowlist.
///
/// Subcommands:
Expand Down
10 changes: 10 additions & 0 deletions crates/tui/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ pub const COMMANDS: &[CommandInfo] = &[
usage: "/cache [count|inspect|warmup]",
description_id: MessageId::CmdCacheDescription,
},
// Slop Ledger (#2127)
CommandInfo {
name: "slop",
aliases: &["canzha"],
usage: "/slop [query|export]",
description_id: MessageId::CmdHelpDescription,
},
];

/// Execute a slash command
Expand Down Expand Up @@ -614,6 +621,9 @@ pub fn execute(cmd: &str, app: &mut App) -> CommandResult {
"balance" => balance::balance(app),
"cache" => debug::cache(app, arg),

// Slop ledger (#2127)
"slop" | "canzha" => config::slop(app, arg),

// ChangeLog command
"change" => change::change(app, arg),
"system" | "xitong" => debug::system_prompt(app),
Expand Down
8 changes: 8 additions & 0 deletions crates/tui/src/core/engine/tool_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ impl Engine {
.with_parallel_tool()
.with_recall_archive_tool();

// SlopLedger: plan mode only gets read-only query + export,
// agent/yolo get the full set including append + update.
builder = if mode == AppMode::Plan {
builder.with_slop_ledger_read_only_tools()
} else {
builder.with_slop_ledger_tools()
};

if mode != AppMode::Plan {
builder = builder
.with_rlm_tool(self.deepseek_client.clone(), self.session.model.clone())
Expand Down
1 change: 1 addition & 0 deletions crates/tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod session_manager;
mod settings;
mod skill_state;
mod skills;
mod slop_ledger;
mod snapshot;
mod task_manager;
#[cfg(test)]
Expand Down
Loading
Loading