Skip to content

Make tool an abstract base with a tool-native subtype and drop source (closes #3450) - #3496

Merged
malibio merged 3 commits into
mainfrom
issue-3450-tool-native-subtype
Oct 2, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-3450-tool-native-subtype

Conversation

@malibio

@malibio malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Closes #3450. Implements ADR-086 §12.

What changes

Kind and category. tool becomes an abstract base (structured: parameter_schema is an object). tool-native is a new core subtype of it (structured through the inherited field). Both keep the generic wire shape tool already had.

Type Fields Rule
tool (abstract) description, parameter_schema, enabled (bucket tool) Name required; parameter_schema depth ≤ 9 and no open additionalProperties; no children; embedded as name + description
tool-native handler (bucket tool-native) handler required; always trusted
  • source is deleted. The subtype says where a tool comes from. The tool bucket is closed, so a write that names source is refused.
  • The trust gate is behaviors::tool_is_offered(chain, enabled): a type that is tool-native or extends it is always offered; any other type extending tool is offered only when enabled. A subtype nobody has given a rule is therefore untrusted.
  • available_tools() queries tool (every subtype), resolves each subtype's chain once, applies the gate, and reads the collapsed wire fields. A native tool is called by its handler key; any other subtype by its name. A non-native tool that takes a built-in tool's name is skipped, so it can't put its own description and schema in that tool's place.
  • Seeds are tool-native nodes. No relationships, structural rules or participation rules change: the leaf rule and embedding stay declared on tool and reach the subtype through the chain.
  • Frontend: generated TypeScript regenerated. The "+New" name-as-content rule now follows the chain (isA) instead of an exact id match, so it reaches tool-native.

No remote subtype (tool-mcp, tool-rest, tool-cli) is added.

Tests

  • New packages/core/tests/it/tool_subtypes_test.rs: a bare tool is refused on every create path and on retype; bucket placement; closed buckets (source refused); the base's schema guard and leaf rule reach a fixture subtype that extends tool; a tool query returns every subtype.
  • available_tools tests run against the real seeding path, with a fixture remote-style subtype: offered only when enabled, never under a built-in name; seeded native tools produce the registry's definitions in order.
  • Mutation-checked: making the gate return true for non-native tools, and removing the built-in-name guard, each fail the gate tests.
  • bun run test:changed passes (frontend, scripts, browser, types drift, Rust workspace).

Docs

components/node-types.md and components/tool-registry.md in nodespace-docs already describe this shape; the tool registry page gains where the gate lives and what a tool is called by (nodespace-docs 8ee39e3). architecture/prompt-skill-system.md needed no change: it defers to the tool registry page for tool nodes and the trust gate.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3496

Review Type: Initial Review (no prior reviews or comments on the PR; head 7f0def77)

Summary

The change does what the issue asks and is a clear net improvement: tool is abstract, tool-native is a core subtype with its own closed bucket, source is gone from schema, behaviour, seeds and reader, and the trust gate is decided from the extends chain and fails closed on an unresolved chain. No rejection-list item from the node type sequence applies. Two gaps remain in the trust gate itself; neither is a regression from main, but both are small and belong in this PR because the gate is its subject.

What I ran: tool_subtypes_test:: (12/12 pass), check-node-type-literals, check-lifecycle-reads, check-pro-boundary (all clean). I did not run test:changed, types:check or quality:fix. The two Important findings are from reading the code, not from a failing test.

Requirements Check

  • ✅ tool abstract, tool-native a core subtype, each with a declared schema; bare tool refused. Registry entries in core_type.rs, schemas in core_schemas.rs. a_bare_tool_is_refused_on_every_create_path covers create_node, create_node_with_parent, bulk_create, bulk_create_hierarchy; a_tool_cannot_be_retyped_into_the_abstract_base covers retype.
  • ✅ No source; the gate is the subtype's rule, tested with a non-enabled fixture subtype. tool_is_offered plus a_tool_that_is_not_native_is_offered_only_when_enabled against a real extends: tool schema; a_tool_takes_only_its_declared_fields shows source is refused. Caveat: the fixture always states enabled; see finding 1 for the node that doesn't.
  • ✅ Seeds are tool-native, and available_tools() builds the surface from them. the_seeded_native_tools_are_the_tool_surface compares name, description and schema with model_facing_tool_definitions() in order.
  • ✅ Node type sequence followed; sheet updated. Registry, closed schema, behaviour, wire shape (generic, no second definition), promoted fields, regenerated TypeScript, flat write path and tests are all present. The tool sheet in components/node-types.md and components/tool-registry.md on nodespace-docs origin/main (8ee39e3) match the code. The issue also names architecture/prompt-skill-system.md; it only links to the tool registry page, so no change was needed.
  • ⚠️ test:changed passes; quality:fix clean. Not re-run by me; taken from the PR description.

Reviewer rejection list: no undeclared key, no literal node_type comparison, no lifecycle_status read, no second wire type or hand-copied TypeScript, no ids-as-relationship, no non-UUID id, no compatibility code, no lint suppression.

Code Review Findings

1. 🟡 Important — enabled defaults to true, so a non-native tool is offered unless it opts out
📁 packages/core/src/models/core_schemas.rs:1759-1777 (default at 1770), packages/agent/src/local_agent/tools.rs:4365-4376

The reader treats a missing enabled as false, but the write path never leaves it missing: apply_schema_defaults_with_fields fills the inherited default into the tool bucket on create. a_native_tool_stores_each_field_in_its_declaring_bucket shows exactly that ("enabled": true stored though not supplied), and the same path runs for any type that extends tool. So a remote-style node created without enabled is stored enabled and offered. The issue and ADR-086 §12 say such tools are offered "only when enabled", and tool-registry.md says a node that doesn't say is read as not enabled; with this default that sentence can never apply. The agent's own create_schema + create_node can produce such a node, putting arbitrary description text on the model's tool surface.

Recommendation: make the default false (or drop it). Native tools ignore the field and the seeds set it explicitly, so nothing else changes. Add a test that creates a fixture-subtype node without enabled and asserts it is not in available_tools(); the current tests always pass the flag, so they cannot catch this.
Principle: secure defaults / fail closed — a trust gate should need an explicit grant.

2. 🟡 Important — the built-in-name guard covers only non-native tools; a second native node can still replace a built-in tool's definition
📁 packages/agent/src/local_agent/tools.rs:4380-4431

A non-native node named delete_node is skipped, but any node whose chain reaches tool-native is keyed by its handler and inserted with node_defs.insert (last one wins, in query order). A second tool-native node, or a node of a user schema that extends: tool-native (which tool_is_offered trusts by design, see the tool-native-plus assertion), with handler: "delete_node" and its own description and schema therefore competes with the seeded node for that tool's definition. Nothing restricts creating such a node: exec_create_node only requires that the type has a schema, and handler is not unique. main had the same hole through source: "internal", so this is not a regression, but the PR description's claim that a tool "can't put its own description and schema in that tool's place" holds only for non-native types.

Recommendation: for a handler that is in Tool::ALL, accept only the node whose id is Tool::seed_id() (fixed ids exist since the seed tables), and warn and skip any other; at minimum make a duplicate handler deterministic and logged. Add the native-impostor case to a_tool_that_is_not_native_is_offered_only_when_enabled. Separately decide whether a user-defined subtype of tool-native should be trusted at all; tool-registry.md says "a subtype nobody has given a rule is therefore untrusted", which this contradicts.
Principle: complete mediation — a guard that one path enforces and a sibling path skips protects nothing.

3. 🟢 Suggestion — the native test lives in two places
📁 packages/agent/src/local_agent/tools.rs:4380-4381, packages/core/src/behaviors/mod.rs:2023-2029

available_tools recomputes nearest(chain).is_a(ToolNative) right after tool_is_offered decided the same thing. Have core return the decision once (for example an enum Native / EnabledOnly / NotATool) so the gate and the call-name rule cannot drift when tool-mcp adds a third arm. DRY.

4. 🟢 Suggestion — an offered non-native tool cannot be called
📁 packages/agent/src/local_agent/tools.rs:4483

execute dispatches only through Tool::from_name, so an enabled fixture-style tool is shown to the model and returns UnknownTool when called. Remote bindings are a non-goal here and main behaved the same for external, so no change is required; a one-line comment at the gate saying so would save the next reader the trace.

5. Nit — stale comments that still describe the old shape

  • 📁 packages/agent/src/skill_pipeline.rs:19 — module doc says "Tool nodes (node_type='tool')"; they are tool-native.
  • 📁 packages/proto/proto/node_service.proto:473 — lists "tool" as a seeded node type; a reset keyed on tool now matches no template (root_node_type is tool-native). Only the skill reset calls it today.
  • 📁 packages/cli/src/commands/mcp.rs:110-125 — says tool nodes carry a source marker; they no longer do.
  • 📁 packages/core/src/behaviors/mod.rs:5119-5120 — comment says the bare base is "never trusted", but the assertion is that it is offered when enabled.

6. Nit — docs disagree on mentionability
components/tool-registry.md says a tool is "not mentionable"; the registry (EMBEDDED, mentionable: true), the generated TypeScript and components/participation.md say it is. Pre-existing and not changed by this PR; fix the sentence in the docs repo.

7. Nit — 📁 packages/desktop-app/src/lib/services/schema-authoring.ts:52-54: the seed content for the subtype is "Untitled Tool Native" while its schema is named "Tool (Native)". No "+New" path creates one, so cosmetic only. The move to isA also widens the rule to user subtypes of project, skill and collection, which is correct (the name rule is the base's) but only tool-native is tested.

What is solid

  • An unresolved chain yields an empty chain and the gate refuses it; a missing nodeType does the same.
  • The schema guard and leaf rule stay on the base and are tested through a real fixture subtype, not only tool-native.
  • ToolNativeNodeBehavior adds to the base and delegates embedding rules; a_native_tool_takes_the_bases_embedding_rules pins it.
  • No leftover reader of source or of handler in the tool bucket in the Rust crates, CLI, daemon, packages/skill, scripts/ or the frontend.

Recommendation: APPROVE

No blocker. Findings 1 and 2 are each a few lines plus a test and should be folded into this PR before merge rather than filed separately.

@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.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (commit 4fea0db)

Addressed

  • 1 (🟡 enabled default): tool.enabled now defaults to false. A tool that is not native and never states enabled is stored as off and not offered. New tests: a_tool_that_does_not_say_it_is_enabled_is_not_offered (agent) and an assertion in the_trust_gate_follows_the_stored_chain (core).
  • 2 (🟡 native impostor): available_tools() admits a built-in tool only from its own seeded node (Tool::seed_id()). A native node naming a built-in handler without being that seed, a native node whose handler is no built-in tool, and any other subtype taking a built-in name are skipped. New test: only_a_built_in_tools_seed_defines_it, with impostors on both sides of the seed in query order.
  • 3 (🟢 one decision): behaviors::ToolOrigin (Native / External) decides both the gate and what a tool is called by; tool_is_offered is a thin wrapper over it.
  • 4 (🟢 dispatch): comment at the name rule says nothing dispatches a non-native tool yet.
  • 5 (nits): stale comments fixed in skill_pipeline.rs, node_service.proto, mcp.rs, and the behaviour test's "never trusted" wording.

Both new guards are mutation-checked: reverting either fails the new tests. bun run test:changed passes on this commit. components/tool-registry.md updated in nodespace-docs to match.

Skipped

  • 6 (docs: is a tool mentionable?): tool-registry.md says not mentionable; the registry and participation.md say it is. Pre-existing and a design question, not a wording fix; left for the owner to decide.
  • 7 ("Untitled Tool Native"): no "+New" path can create a tool, so the placeholder wording is never shown.

Re-review: needed — findings 1 and 2 changed the trust gate's behaviour.

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3496 (re-review)

Review Type: Re-Review (first review on 7f0def77; this covers 4fea0db6 only)

Previous Review Summary: 7 earlier findings. 5 addressed correctly (1, 2, 3, 4, 5), 2 skipped with reasons that hold (6, 7), 0 addressed incorrectly. No new Critical or Important issue; 6 new Suggestions/Nits, none blocking.

What I ran on 4fea0db6: the agent's available_tools_from_nodes and seed_tool_nodes tests (10/10 pass), tool_subtypes_test:: (12/12), the two behaviour unit tests for the gate (2/2), and check-node-type-literals, check-lifecycle-reads, check-pro-boundary (all clean). I did not run test:changed, types:check, the doctests or a mutation check; the author's statement that reverting either guard fails the new tests is taken from the PR comment, and is consistent with what I read (below).

Status of each earlier finding

  1. 🟡 enabled default — addressed correctly. tool.enabled defaults to false (packages/core/src/models/core_schemas.rs:1770-1776). Nothing depended on the old default: the tool seeds state enabled: true themselves, so their _seed.config_version hash and seed reconciliation are unchanged; no generated TypeScript carries a tool default (typed-core-fields.ts has none for tool); the two core tests that asserted the stored default were updated. The new agent test does pin the fix: executor_seeded_with seeds through create_node_with_parent, which applies schema defaults, so with a true default the unstated node would be stored enabled and offered.

  2. 🟡 native impostor — addressed correctly. A built-in name is admitted only from the node whose id is Tool::seed_id() (packages/agent/src/local_agent/tools.rs:4404-4423). I walked every combination:

    Node Result
    Native, handler is a built-in, id is that tool's seed admitted
    Native (or a user subtype of tool-native), built-in handler, any other id skipped
    Native, handler is no built-in tool skipped
    Native, no handler skipped (empty name)
    Not native, not enabled or enabled missing skipped
    Not native, enabled, name is a built-in or system-only tool skipped
    Not native, enabled, any other name admitted, after the built-ins
    Unresolved chain, missing nodeType, or a type that is no tool skipped

    No legitimate node is dropped: the real seeds still produce the registry's surface in order (the_seeded_native_tools_are_the_tool_surface passes). A second node can no longer replace a built-in definition. Editing the seed node itself still changes the definition, which tool-registry.md states as intended. The earlier open question (is a user subtype of tool-native trusted?) is settled in effect: such a node can never be a seed, so it never reaches the surface.

  3. 🟢 one decision — addressed correctly. ToolOrigin::of + is_offered (packages/core/src/behaviors/mod.rs:2005-2048) decide the gate, the call name and the admission rule; the agent no longer recomputes the chain test.

  4. 🟢 dispatch comment — addressed. tools.rs:4382-4385.

  5. Nit, stale comments — addressed. All four sites now describe the current shape.

  6. Nit, mentionable — skipped; reason holds. It is a pre-existing contradiction between tool-registry.md ("not mentionable") and the registry plus participation.md, and which is right is a design call. It still needs an answer from the owner; it does not belong in this PR.

  7. Nit, "Untitled Tool Native" — skipped; reason holds. The comment above NAME_AS_CONTENT_TYPES in schema-authoring.ts says the same: no "+New" path creates a tool.

New findings

1. 🟢 Suggestion — tool_is_offered has no production caller left
📁 packages/core/src/behaviors/mod.rs:2050-2065
After this commit only its own doctest, the unit test and tool_subtypes_test.rs call it; the agent uses ToolOrigin. Delete it and point the tests at ToolOrigin::of(..).is_some_and(|o| o.is_offered(..)), or it becomes a second spelling of the gate that can drift. Principle: one definition; the project rule is to delete unused code.

2. 🟢 Suggestion — the new core assertion does not use the value it just read
📁 packages/core/tests/it/tool_subtypes_test.rs:361-366
The last line is assert!(!tool_is_offered(&remote, false)) with a literal false, identical to line 356. Line 365 (stored.properties["tool"]["enabled"] == false) is what pins the default, so the fix is covered; pass the stored value to the gate so the test states the end-to-end claim in its comment.

3. 🟢 Suggestion — two tools that are not native can share a name, and the later one wins
📁 packages/agent/src/local_agent/tools.rs:4436-4443
node_defs.insert is still last-one-wins for enabled tools that are not native, in query order. Nothing dispatches such a tool yet, so this has no effect today; settle it (first wins plus a warning, or a uniqueness rule) when remote bindings are designed.

4. 🟢 Suggestion (suspicion, not introduced here) — the 256-node page is shared with nodes that are now always skipped
📁 packages/agent/src/local_agent/tools.rs:4317-4320
The query takes at most 256 tool nodes of any subtype. I confirmed the limit is applied; I did not check the order. If more than 256 tool nodes exist, a seed could fall outside the page and its built-in tool would leave the surface. Far from reachable in practice with 21 seeds; noting it because built-ins now come only from seeds, so reading the seeds by id would remove the dependency.

5. Nit — log wording and level
📁 packages/agent/src/local_agent/tools.rs:4373-4379, 4414-4421
"skipping unenabled tool" is also logged for a type that is no tool and for an unresolved chain; "not the built-in tool it names" is also logged for a native node whose handler is no built-in tool. The second is a warn that repeats on every available_tools call for as long as the node exists.

6. Nit — docs (nodespace-docs origin/main at 181f9b4)
components/tool-registry.md matches the code: default false, ToolOrigin, and step 4 on seed-only admission. Two small gaps: the tool sheet in components/node-types.md lists enabled as boolean with no default, where other sheets give one; and the trust-gate table still says tool-native is offered "Always", which step 4 narrows to the built-in seeds. ADR-086 §12 is not contradicted.

Recommendation: APPROVE

Both Important findings are fixed, tested through the real write path, and documented. The new items are optional polish; 1 and 2 are a few lines each if you want them in this PR.

@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.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed (commit fe581ef)

Addressed

  • 1: tool_is_offered deleted — no production caller remained after the agent moved to ToolOrigin. Its unit and integration tests now go through ToolOrigin::of(..) / is_offered(..); the doctest moved to ToolOrigin::is_offered.
  • 2: the_trust_gate_follows_the_stored_chain passes the stored enabled value to the gate instead of a literal.
  • 5: log lines reworded to say what was skipped.
  • 6: docs (nodespace-docs main): the tool sheet notes enabled is off by default, and the trust-gate table says only a built-in tool's seeded node counts as that tool.

Skipped

  • 3 (two non-native tools sharing a name): nothing dispatches a non-native tool yet; the collision rule belongs with the remote-binding design.
  • 4 (256-node page): a suspicion, not reachable with the built-in set; reading seeds by id can come with remote tools, when the registry can grow.

bun run test:changed passes on this commit.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: this commit removes an unused function, tightens one test assertion and rewords two log lines. No logic the gate depends on changed.

malibio and others added 3 commits October 2, 2026 18:07
…closes #3450)

tool is now abstract (ADR-086 §12): it declares description,
parameter_schema and enabled, and is never instantiated. tool-native is a
new core subtype that declares handler; the seeded built-in tools are
tool-native nodes. The source field is gone: the subtype says where a
tool comes from.

The trust gate is behaviors::tool_is_offered, decided from the node's
extends chain: a native tool is always offered, any other tool subtype
only when enabled. available_tools() queries every tool subtype, applies
the gate, and refuses a non-native tool that takes a built-in tool's name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ool only from its seed

- enabled defaults to false, so a tool that is not native and never says
  whether it is enabled is stored as off and not offered (fail closed).
- available_tools() admits a built-in tool only from its own seeded node:
  a native node naming a built-in handler without being that tool's seed,
  a native node whose handler is no built-in tool, and any other subtype
  taking a built-in tool's name are skipped, so none can replace a
  built-in tool's description and schema.
- ToolOrigin in core decides both the gate and what a tool is called by,
  replacing two separate chain tests in the agent.
- Stale comments describing node_type='tool' and the source field fixed.

Skipped: the seed content wording for a tool-native placeholder (no +New
path creates a tool).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…te test

- tool_is_offered had no production caller once the agent moved to
  ToolOrigin; deleted, with its tests pointed at ToolOrigin.
- The stored-default assertion now passes the value it read to the gate.
- Log lines say what was actually skipped.

Skipped: two tools that are not native sharing a name (nothing dispatches
one yet; settled with remote bindings), and reading seeds by id instead of
through the 256-node page (not reachable with the built-in set).

Co-Authored-By: Claude Opus 5.5 <[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.

Make tool an abstract base with a tool-native subtype and drop source

1 participant