Skip to content

Single tool registry as the source of truth for agent tool name lists - #1336

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1326-tool-registry
Jun 5, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1326-tool-registry

Conversation

@malibio

@malibio malibio commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Closes #1326

…oses #1326)

Agent tool names were hand-maintained in four places kept in sync only by
drift-detector tests: all_tool_definitions() + BASELINE_TOOLS (tools.rs),
humanize_tool_name() (agent_loop.rs), and per-skill tool_whitelist arrays
(skill_pipeline.rs).

Introduce a `Tool` enum in tools.rs as the canonical set. Derived from it:
- all_tool_definitions() maps over Tool::ALL
- humanize_tool_name() delegates to Tool::humanized()
- baseline membership comes from Tool::is_baseline()
- execute() dispatches via Tool::from_name() then an exhaustive match, so the
  compiler forces an exec arm for every registered tool

Adding a tool is now one variant plus filling exhaustive match arms.

Remove drift-detector tests that only existed to keep the lists aligned
(humanize_tool_name_covers_all_registered_tools and the 8 per-skill whitelist
assertions); their guarantee now holds by construction. Replace them with
all_skill_whitelist_tools_are_registered, which validates every skill
tool_whitelist entry resolves against the registry, plus registry invariant
tests (unique names, name round-trip, definition/name agreement, baseline set).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@malibio

malibio commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Recommendation: Approve.

This is a clean, well-executed refactor that does exactly what issue #1326 asks: it collapses four hand-synced tool-name lists into a single Tool enum and derives the definitions, display names, baseline membership, and dispatch from it. The design replaces runtime drift detection (tests that hoped to catch a forgotten edit) with compile-time exhaustiveness (matches the compiler enforces) — a textbook "make illegal states unrepresentable" improvement. Clippy (-D warnings) is clean and all 233 agent-crate tests pass. This is a clear net positive to code health.

Verification performed:

  • cargo clippy -p nodespace-agent --all-targets -- -D warnings — clean (no dead-code/unused-method warnings; every Tool method has a non-test caller).
  • cargo test -p nodespace-agent — 230 + 3 passed, 0 failed.
  • Confirmed Tool::ALL ordering is byte-for-byte identical to the prior all_tool_definitions() order, so the model-facing tool presentation order is unchanged (the doc comment correctly flags that order is load-bearing).

Acceptance Criteria

  • Single registry defines the canonical tool set — Tool enum + Tool::ALL.
  • Definition, humanized name, baseline derived from registry — definition(), humanized(), is_baseline(); all_tool_definitions() and humanize_tool_name() now delegate.
  • [~] Adding a tool requires editing exactly one place — see Improvement below. Adding a variant forces edits across name()/definition()/humanized()/exec match arms (compiler-guided), plus a hand-written def_* schema fn and exec_* method. It is now one cohesive, compiler-checked change rather than four silently-driftable lists — the intent of the AC is met — but it is not literally "one place." Honest to call this substantially-but-not-literally satisfied.
  • Drift-detector tests removed — humanize_tool_name_covers_all_registered_tools and the 8 per-skill whitelist assertions are gone, replaced by construction-guaranteed exhaustiveness.
  • Skill tool_whitelist validated against registry — all_skill_whitelist_tools_are_registered rejects any whitelist entry that does not resolve via Tool::from_name.
  • quality:fix / clippy clean.
  • Tests pass.

Findings

Critical Issues

None.

Suggested Improvements

  • [Improvement] tools.rs — the def_* schema fns and exec_* methods are still hand-synced to the registry, partially undercutting AC Desktop shell with resizable panels #3. The enum unifies naming/membership, but a new tool still requires authoring a separate def_<tool>() and exec_<tool>() and wiring both match arms. The compiler enforces the wiring (good), and registry_definition_name_matches_variant_name guards name agreement, but there is no guard that the def_*'s schema body (parameters/description) corresponds to what the matching exec_* actually deserializes — that contract remains by-convention. This is acceptable for now (the param structs are the natural home for that schema and consolidating them is a larger change), but worth a tracking note so the "single place" claim isn't overstated. No action required for merge.

  • [Improvement] Lost coverage from the 8 per-skill assertions is real but low-value; the trade is sound. The old tests asserted specific skills contain specific tools (e.g. "Node Deletion whitelists delete_node"). The new all_skill_whitelist_tools_are_registered only asserts every whitelisted name is a registry member — it would NOT catch a semantic regression like "Node Deletion" silently losing delete_node or being given create_node instead. So a genuine guarantee was dropped, not merely relocated. That said, those assertions were tautological smoke tests (a seed asserting it contains what the same file literally writes two lines up) with near-zero defect-catching power, and the new test catches the higher-value failure mode (typos / references to removed tools) that the registry now makes possible to check. Net positive. If you want to retain intent-level coverage cheaply, consider one table-driven test mapping skill title → required tool, but I would not block on it (arguably YAGNI).

Nitpicks

  • Nit: tools.rs humanized() — variant arm order diverges from ALL/name()/definition(). DeleteNode is listed mid-block (after UpdateNode) here, whereas every other match orders it second-to-last per Tool::ALL. Purely cosmetic, but matching the canonical order across all four matches makes future audits a single visual scan.

  • Nit: tools.rs select_tools — baseline_count recomputes the baseline cardinality by filtering Tool::ALL. Minor; a Tool::ALL.iter().filter(..).count() is fine, but since the same filter is materialized two lines later into selected_names, you could derive the count from that initial set's .len() before insertions and drop one pass. Negligible (13-element slice). Optional.

  • Nit: from_name is a linear scan over 13 entries per lookup. Completely fine at this scale and called on cold paths (dispatch, validation). Flagging only so it's a conscious choice, not an oversight — no change wanted.

Notes

  • Commit message is exemplary: states the problem, the construction-based fix, and exactly what was removed and why.
  • No security/perf concerns: the change is pure internal plumbing over a fixed, small, compile-time set; no new inputs, dependencies, or external surface.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review verdict: APPROVE (posting as comment — GitHub blocks self-approval on own PR). Clean compile-time-enforced refactor that meets the issue's intent; clippy clean and all agent-crate tests pass. Two non-blocking notes in the detailed review comment above. Cleared to merge.

Reviewer noted DeleteNode was listed mid-block in humanized() while every
other match (name, definition, execute) follows Tool::ALL order. Reordered
to match Tool::ALL so all four exhaustive arms are visually consistent and
future audits can do a single left-to-right scan.

Skipped: baseline_count two-pass (negligible on 13-element slice), structural
improvements re def_*/exec_* coupling (flagged as "no action required for
merge" / YAGNI by reviewer).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@malibio

malibio commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary

Addressed 1 of 3 review items:

✅ Nit addressed: Reordered humanized() arm order to match Tool::ALL canonical ordering (DeleteNode moved from mid-block to second-to-last, consistent with name(), definition(), and execute()).

⏭️ Nit skipped: baseline_count two-pass over Tool::ALL — reviewer noted it's negligible on a 13-element slice, no change warranted.

⏭️ Improvements skipped: Both structural observations (def_*/exec_* still hand-synced; dropped per-skill intent assertions) were explicitly flagged as "no action required for merge" / YAGNI by the reviewer. Tracked in the issue for future consideration.

Re-review decision: NO RE-REVIEW NEEDED — only a cosmetic arm-reorder with no logic change. Reviewer's recommendation was Approve on the original diff.

@malibio
malibio merged commit 72f8a55 into main Jun 5, 2026
@malibio
malibio deleted the worktree-issue-1326-tool-registry branch June 5, 2026 15:28
malibio added a commit that referenced this pull request Jun 22, 2026
…#1336)

* Introduce single Tool registry as source of truth for agent tools (closes #1326)

Agent tool names were hand-maintained in four places kept in sync only by
drift-detector tests: all_tool_definitions() + BASELINE_TOOLS (tools.rs),
humanize_tool_name() (agent_loop.rs), and per-skill tool_whitelist arrays
(skill_pipeline.rs).

Introduce a `Tool` enum in tools.rs as the canonical set. Derived from it:
- all_tool_definitions() maps over Tool::ALL
- humanize_tool_name() delegates to Tool::humanized()
- baseline membership comes from Tool::is_baseline()
- execute() dispatches via Tool::from_name() then an exhaustive match, so the
  compiler forces an exec arm for every registered tool

Adding a tool is now one variant plus filling exhaustive match arms.

Remove drift-detector tests that only existed to keep the lists aligned
(humanize_tool_name_covers_all_registered_tools and the 8 per-skill whitelist
assertions); their guarantee now holds by construction. Replace them with
all_skill_whitelist_tools_are_registered, which validates every skill
tool_whitelist entry resolves against the registry, plus registry invariant
tests (unique names, name round-trip, definition/name agreement, baseline set).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Address review nit: align humanized() arm order with Tool::ALL

Reviewer noted DeleteNode was listed mid-block in humanized() while every
other match (name, definition, execute) follows Tool::ALL order. Reordered
to match Tool::ALL so all four exhaustive arms are visually consistent and
future audits can do a single left-to-right scan.

Skipped: baseline_count two-pass (negligible on 13-element slice), structural
improvements re def_*/exec_* coupling (flagged as "no action required for
merge" / YAGNI by reviewer).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

Single tool registry as the source of truth for agent tool name lists

1 participant