Skip to content

feat(cli): tole audit prints the delegation tree read-only (#585) - #629

Merged
ajianaz merged 3 commits into
developfrom
feat/delegation-audit
Nov 12, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/delegation-audit

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

The last part of #585 (epic #583). Closes #585.

tole audit [goal] [--json] prints this workspace's delegation tree, read-only. Without a goal it lists the goals. With one it shows each node's:

  • profile, mode, status and depth;
  • budget carve against its measured and charged use;
  • allow list, including the patterns dropped by the parent ∩ profile intersection;
  • lease paths;
  • report summary and reason.

Why

Design docs/profiles-collaboration-secrets.md A8.2: every delegated run is an ordinary durable session, and the ledger records the tree (who spawned whom, budget, allowlist, workspace). tole audit <goal> prints it top-down.

Owner rules that apply:

  • Read-only: no writes and no network.
  • No leaks: nothing may reveal secrets or full prompts beyond a short capped task line.

Changes

  • crates/tole-cli/src/audit.rs (new): audit(log, goal, json, secrets).
    • What it reads: only the delegation log in the data dir (delegate::log_path, outside every workspace, never child-writable), through Delegation::open. That opens without the host lock and never repairs a torn line, so it writes nothing.
    • What it does not read: nothing from the children's agent dirs; the reports shown are the ones the parent recorded in the log. So no child-writable file is opened at all.
    • Bounded and redacted output (each capped field, in this order):
      1. The raw string is redacted through the SecretSet first, so a secret that would straddle the cut, or one that contains whitespace or control characters, is matched whole.
      2. Control characters are dropped and whitespace is collapsed.
      3. The text is cut: the task at 120 characters (never the full prompt), report summaries and reasons at 400. A cut that would split a «NAME» marker drops the whole marker.
    • Second pass: the whole value then goes through redact_value again, which also covers ids, paths and allow patterns.
    • Report: only counts of files, checks and risks are shown.
    • Text form: one line per node, indented by depth. A live node shows its reserved carve; a settled one shows charged/carved tokens and steps. The details follow on indented lines.
  • crates/tole-cli/src/main.rs:
    • Command::Audit { goal, --json } (config gate Skip);
    • resolves the workspace root (--workspace, else cwd) and the log path in tole_data_dir();
    • passes SecretSet::from_env();
    • an unknown goal is an error, and no log yet prints "no delegation goals".
  • crates/tole-core/src/delegation.rs:
    • read helpers goals(), charged(id) and leases_of(id);
    • poll is documented as a pure lookup in the folded state that reads, settles or writes nothing.
  • Docs:

Testing

  • Unit tests (audit_tests.rs, 6):

    • Tree: the output is capped and redacted.
    • JSON: every field is present.
    • Writes nothing: a torn log line is left as is, there is no lock file, and an unknown goal is refused.
    • Review round 1 (red against c011706, green after):
      • a_secret_across_the_task_cut_never_leaks_a_prefix: a secret starting 10 characters before the 120-character cut leaks no prefix, and every line has balanced «/».
      • a_secret_with_whitespace_or_control_characters_is_redacted: a secret with a double space and one with an ESC are both redacted to their «NAME» markers.
    • Proof for the poll finding (a false positive): audit_and_poll_never_settle_or_write_even_with_work_pending. On a tree with a queued spawn and a running child whose process is gone, poll and audit leave both nodes as they were and the log bytes unchanged.
  • End to end (tests/audit_cli.rs): the real binary finds the log in the data dir, redacts a secret from its environment, and leaves the log unchanged.

  • Each rule was broken on purpose; the matching test went red, and green again once restored:

    Behavior broken Test that failed
    redact after cutting (the previous code) the straddle test and the whitespace/ESC test
    the cut may split a marker the straddle test
    no redaction both unit output tests and the end-to-end test
    no length cap the tree test
    control characters kept the tree test
    any node accepted as a goal the read-only/unknown-goal test
    the CLI passing an empty SecretSet the end-to-end test
  • Commands (CARGO_TARGET_DIR set explicitly, CARGO_INCREMENTAL=0, debuginfo off; df -h / checked first):

    • cargo fmt --all: clean
    • cargo clippy --workspace --all-targets -- -D warnings: clean
    • cargo test --workspace --no-fail-fast: 1548 passed, 0 failed
    • cargo test -p tole-core --no-default-features: 536 passed, 0 failed
    • cargo build -p tole-cli --no-default-features: ok
    • cora review --no-llm --staged: no issues found
  • Size: 10 files, +708/-4.

Known limits:

  • Scope: only this workspace's log (the one keyed by the canonical workspace root). There is no cross-workspace listing.
  • Session paths: the agent-dir path of each node (session) is shown; it is a path under the workspace, not a secret.

tole audit [goal] [--json] prints this workspace's delegation tree: the
goals, or one goal's nodes with profile, mode, status, depth, budget
carve against measured and charged use, allow list with dropped
patterns, lease paths, report summary and reason.

It reads only the delegation log in the data dir, without the host lock
and without repairing a torn line; it writes nothing, reads nothing from
the children's agent dirs and makes no network call. The task is one
capped line, summaries and reasons are capped, control characters are
dropped, and every string is redacted through the process SecretSet.

Closes #585
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

let nodes: Vec<Value> = d.tree(goal).into_iter().map(|n| node_json(&d, n)).collect();
json!({ "log": log, "goal": goal, "nodes": nodes })
}
};
"{}\n",
serde_json::to_string_pretty(&value).map_err(|e| e.to_string())?
));
}
node_json capped and normalized the task, report summaries and reasons
before the SecretSet pass, so a secret that straddled the 120 or 400
character cut, or held whitespace or control characters, was no longer
matched and leaked. Each raw string is now redacted first, then control
characters are dropped, whitespace collapsed and the text cut; a cut
that would split a «NAME» marker drops the whole marker. The final
redact_value pass stays as a second pass.

Delegation::poll is documented as a pure lookup, with a test that audit
and poll write nothing on a tree with a queued spawn and a running child
whose process is gone.
@ajianaz
ajianaz merged commit 1c5b320 into develop Nov 12, 2026
15 of 16 checks passed
@ajianaz
ajianaz deleted the feat/delegation-audit branch November 20, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(core): delegation — budget carve, depth 2 (max 3), write lease and mandatory report

3 participants