Skip to content

feat(skills): load only owner-approved skill content hashes - #617

Merged
ajianaz merged 3 commits into
developfrom
feat/skill-approved-hashes
Nov 11, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/skill-approved-hashes

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

A session can now be set to load only skill content the owner approved. With TOLE_SKILL_APPROVAL=required, a discovered skill loads only when its whole directory hashes to the owner's approval. Every other skill is listed by name only, as unavailable, and its text never reaches the model. New tole skills approve|revoke|list commands manage the approvals. The default (off) keeps today's behavior.

Why

Closes #591 (epic #589). A skill is meant to be followed, so trusting "the file is there" or "the index returned it" lets anything that can write a skill steer the agent (SkillJack). Design §4.2 in docs/skills-registry-design.md makes the owner's approval of exact bytes the trust anchor.

Changes

  • tole-core/src/skill_approval.rs (new):
    • read_package / package_hash: a skill package is every file of its directory (SKILL.md plus references/, scripts/, assets/, ...). The hash is sha256: over each file's relative path, length and bytes, in path order, so editing, adding or renaming any file changes it.
      • A symlink in a package makes it unreadable, because its target could change without the hash changing.
      • A package is capped at 256 files and 4 MiB.
    • Approvals: one record per skill name (hash, approval time, file count) in $CODECORA_HOME/tole/skill-approvals.json, outside every workspace.
      • Approving new bytes replaces the old approval, so a reverted older version does not silently load again.
      • It is written atomically (temp file and rename).
      • A missing file means no approvals; a malformed file is an error, never "nothing approved" or "everything approved".
    • Gate: Open is today's behavior. Approved loads a skill only when its package hash matches, and parses the body from the exact bytes it hashed, so a file swapped after the check is never what loads. A refusal is LoadError::NotApproved { name, hash }.
  • skills.rs:
    • LoadSkillTool::with_gate and index_block_gated. Under the gate, an unapproved skill is listed as - name (unavailable: not approved by the owner); its description is left out as well, since it is text from the same untrusted file.
    • New helpers skill_names and parse_loaded.
    • index_block is unchanged.
  • skill_index.rs: select and SkillSearchTool::new take a Gate.
    • A pinned or recalled skill the gate refuses goes into Selection::unavailable. It is named in the prompt block and does not use up the K.
    • A refused skill_search hit comes back as {"name", "available": false} with no description.
  • tole-cli/src/skill_approve.rs (new):
    • The setting: TOLE_SKILL_APPROVAL is off (the default) or required. Any other value, or a malformed approvals file, fails startup.
    • tole skills approve <name> [--hash sha256:…]: prints the hash and every file it covers. --hash pins the hash the owner reviewed, so a skill changed between review and approval is refused. A broken SKILL.md is never approved.
    • tole skills revoke <name>: removes the approval; the skill stays on disk.
    • tole skills list: shows each skill as approved, changed since approval or not approved, with its hash and approval time.
    • The uteke index actions from feat(skills): recall skills per session through the uteke index #616 (index, retire, search) are flattened into the same tole skills command, renamed to skill_recall::IndexAction, and still need shell-tools.
  • skill_recall.rs / main.rs: SkillRecall.gate is set from the setting. In local mode it gates the full listing and load_skill. With TOLE_SKILL_INDEX=uteke it also gates the pinned core, the recalled skills and skill_search.
  • Not gated: skills the owner names directly (--skill <file>, a profile's skills), because naming the file is the approval.
  • Docs: README variable row, a threat-model paragraph (including the limit: the approvals file is only as strong as the user's home directory), the design doc §4.2 "as built" note and status, and CHANGELOG.

Testing

All run locally on head 4bdb804 (the feature commit, a merge of develop be9b2fc, and the size fix below):

  • cargo test --workspace passes: 1457 passed, 0 failed (82 suites).
  • cargo test -p tole-core --no-default-features passes: 488 passed, 0 failed.
  • cargo test -p tole-cli --no-default-features passes: 426 passed, 0 failed (run on 8b4473e; the fix does not touch tole-cli).
  • cargo fmt --all -- --check passes.
  • cargo clippy --workspace --all-targets -- -D warnings passes, and so does cargo clippy -p tole-core --no-default-features --all-targets. The --no-default-features and shell-tools-only clippy builds of tole-cli were checked on 8b4473e.
  • cora review --no-llm --base origin/develop (cora v0.20.0): "No issues found". The LLM review is CI Cora Review.
  • Smoke test: tests/skill_approval_e2e.rs runs the real tole binary with CODECORA_HOME in a temp dir and a mock provider that records the system message. It covers list, approve, run with the setting required (approved skill listed, unapproved one by name only, its text absent), an edit after approval making the skill unavailable, the default off listing everything, revoke, and the startup errors.

Fix (4bdb804, from the CI Cora Review finding): read_package used to read each file in full before checking the package's byte cap, so one huge (sparse) file in a cloned repo's skill would be loaded into memory at every session start under required. The walk now refuses a file before opening it when the file count is at the limit or its reported (lstat) length is over the remaining budget. It opens files without following a symlink, and reads at most one byte past the remaining budget (take(remaining + 1)), so a file that grows after the check cannot allocate more either. The over-limit error text is unchanged. New test an_over_budget_file_is_refused_without_a_full_read: it was red against the old read-everything form (a reader that panics past the cap was read past it) and is green now.

An earlier workspace run on 8b4473e hit 9 compaction::tests failures with AlreadyExists: a leftover tole-compaction-<pid>-N temp directory from a reused pid on the shared machine. They are unrelated to this change and passed on the rerun above.

New tests:

  • skill_approval::tests:
    • an_over_budget_file_is_refused_without_a_full_read
    • package_hash_covers_every_file_path_and_byte
    • a_symlink_in_a_package_makes_it_unreadable
    • the_approved_gate_loads_only_the_approved_bytes
    • approvals_round_trip_replace_revoke_and_fail_closed
  • skills::tests::gated_index_and_load_skill_show_unapproved_skills_as_unavailable
  • skill_index::tests::the_gate_names_unapproved_skills_as_unavailable
  • skill_approve::tests:
    • the_setting_is_off_by_default_and_required_reads_the_approvals
    • approve_pins_the_reviewed_hash_and_list_shows_each_status
  • skill_recall::tests::the_approval_gate_covers_local_and_uteke_sessions
  • tests/skill_approval_e2e.rs:
    • required_approval_lists_unapproved_skills_by_name_only
    • a_bad_setting_or_a_malformed_approvals_file_fails_startup

Red/green: each behavior was broken on purpose, the named test was seen failing, the file was restored, and the test passed again. All 19 mutants were killed:

Broken variant Test that failed
hash ignores file paths package_hash_covers…
subdirectories not hashed package_hash_covers…
symlink followed a_symlink_in_a_package…
approval not checked the_approved_gate_loads…
approve keeps the old approval approvals_round_trip…
malformed approvals file read as empty approvals_round_trip…
gated index shows an unapproved description gated_index_and_load_skill…
load_skill ignores the gate gated_index_and_load_skill…
refused skill uses up the K the_gate_names_unapproved…
skill_search shows an unapproved description the_gate_names_unapproved…
pinned skill ignores the gate the_gate_names_unapproved…
unknown setting treated as off the_setting_is_off…
approve ignores the reviewed hash approve_pins…
approve accepts a broken SKILL.md approve_pins…
session never gets the gate required_approval_lists… (e2e)
local listing not gated the_approval_gate_covers…
session load_skill not gated the_approval_gate_covers…
recall select not gated the_approval_gate_covers…
session skill_search not gated the_approval_gate_covers…

Related Issues

Closes #591. Epic #589. Builds on #613 and #616 (#590).

Checklist

  • Branch name follows convention (feat/skill-approved-hashes)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR

With TOLE_SKILL_APPROVAL=required a discovered skill loads only when its
package (SKILL.md plus every other file of its directory, paths and
bytes) hashes to the owner's approval in
$CODECORA_HOME/tole/skill-approvals.json. Any other skill is listed by
name only as unavailable; load_skill refuses it and skill_search returns
no description for it. With TOLE_SKILL_INDEX=uteke the same gate covers
the pinned core and the recalled skills. The body that loads is parsed
from the exact bytes that were hashed; a symlink in a package makes it
unloadable; a malformed approvals file or an unknown setting fails
startup.

New tole skills approve <name> [--hash], revoke and list, beside the
index actions. New tole-core module skill_approval (Gate, Approvals,
read_package); skill_index select and SkillSearchTool take a Gate. The
default off keeps today's behavior; --skill files and profile skills
are not gated.

Closes #591.
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

Comment thread crates/tole-core/src/skill_approval.rs Outdated
} else if kind.is_dir() {
walk(&path, &rel, files, total)?;
} else if kind.is_file() {
let bytes = std::fs::read(&path).map_err(|e| format!("{}: {e}", path.display()))?;
read_package read each file in full and only then compared the total
with MAX_PACKAGE_BYTES, so a skill directory with one huge file (cheap to
ship sparse in a cloned repo) was loaded into memory at every session
start under TOLE_SKILL_APPROVAL=required. The walk now refuses on the
file count and the length the directory entry reports before opening a
file, opens it without following a symlink, and reads at most one byte
past the remaining budget, so a file that grew after the check cannot
allocate more either. The over-limit error text is unchanged.
@ajianaz
ajianaz merged commit 4f73cff into develop Nov 11, 2026
19 of 20 checks passed
@ajianaz
ajianaz deleted the feat/skill-approved-hashes branch November 20, 2026 08:37
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(skills): load only owner-approved skill content hashes

3 participants