Skip to content

Let agents fetch NodeSpace's skills and schemas by task, embed schemas, and render built-in skills per audience - #3538

Merged
malibio merged 6 commits into
mainfrom
issue-3502-skill-guidance-fetch
Oct 4, 2026
Merged

malibio merged 6 commits into
mainfrom
issue-3502-skill-guidance-fetch

Conversation

@malibio

@malibio malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Closes #3502.

An external agent (Claude Code, Codex) can now fetch NodeSpace's skills by task, with the schemas of the types the task touches. SKILL.md teaches the fetch and no longer restates the procedures.

What changed

Retrieval

  • nodespace skill guidance "<task>" is served by a new NodeService.GetSkillGuidance RPC over skill_ops::find_skills, so ranking is the in-app agent's: no 0.7 floor, exclusion re-rank. It previously rode the generic node search, whose default scope drops every skill node, so it matched nothing.
  • With no task it lists every skill by name and description. This needs no embedding model.
  • A fetch returns schemas beside the skills: the ones a returned skill is linked to (applies_to), the ones the task names, and schema-search matches scoring 0.85 or more.
  • The typed embedding search (search_embeddings_by_node_type) is now an exact scan over the type. It was documented as one but took a KNN window over all embeddings and filtered by type afterwards, so a small type fell out of the window in a large graph.
  • nodespace search "<query>" --type <type> returns that type's matches: an explicit type filter replaces the default Knowledge scope for a query, as it already did for a listing. An unfiltered search still excludes system types.

Schema embeddings

  • Schemas are queued for embedding by create_schema (so also a workflow install), by update_schema when it commits or renames a field, and by core schema seeding. None of these queued before, so no schema was ever embedded.
  • A schema is embedded as its name plus one line per field (label and description), then its description subtree.
  • find_skills and the workspace context rank every schema and apply their cap after dropping core types, since core schemas are now embedded too.

One body, two audiences

  • A built-in skill is rendered for its reader. The in-app agent keeps the tool-name form; an external fetch gets the same seed with each rule in its CLI form. A user-edited or user-written skill is served as stored.
  • The 11 seed bodies name no tool outside their includes. Tool-specific steps moved into a new ProcedureRule kind with an agent form and a CLI form.
  • The in-app rendering of all 11 skills is byte-identical apart from two intended changes: the leading # <Name> Guidance heading is gone, and Relationship Management's TRAVERSING line is replaced by the relationship-reverse-traversal rule, which no skill included before.
  • The relationship direction rule is a shared fragment (relationship-direction), also rendered into references/cli.md.

SKILL.md

  • Rewritten around fetching: what NodeSpace is, the preflight, when and how to fetch, and that the graph holds instructions for operating NodeSpace and for the workspace's own domains. Tool Decision Guide and Common Agent Tasks are removed. The relationship statement that contradicted cli.md is fixed.

Things to know

  • Existing databases need a reset for their schemas to be embedded and for the new embedded shape. No backfill, per project policy.
  • In-app behaviour changes as a consequence of schemas being embedded. The EXISTING SCHEMAS block and find_skills' schema candidates now receive semantic hits on real databases, where before they only had the lexical backstop. This is the designed behaviour that never worked. I did not run the agent matrix eval against it.
  • Graph Editing's description still names update_task_status, and an external agent sees it in the description: line. Descriptions are the embedded retrieval text, so rewording one moves routing scores; I left it and pinned the exception with a test.
  • The 0.85 schema bar has a thin margin (relevant types scored 0.855 to 1.000, unrelated 0.633 to 0.829 over fifteen tasks). One relevant-but-weak case ("record what Acme owes us" for invoice, 0.789) falls below it.
  • skill_md_key_phrase and its test are removed. Interaction rules now reach external agents through the skills that include them, and a new test fails if any registered rule is included by no skill.

Verification

  • bun run test:changed passes.
  • Live tests with the real embedding model (ignored by default, run locally): 6 new in live_skill_guidance_fetch, 1 new in find_skills_schema_discovery_test, 1 new end-to-end through the daemon in cli_integration, plus the 24 existing live_skill_retrieval_stability guards. All pass.
  • Real binaries on an isolated database: every one of 26 schemas embedded after the processor ran; skill guidance returned skills and schemas.
  • External-agent trial: headless Claude Code (Opus 5.5) with only the new SKILL.md, Linear-style setup installed, five requests. 5 of 5 fetched before the first write, 5 of 5 carried the operation out, 5 of 5 correct. Five runs on one harness; recorded in the ADR-064 amendment with that limit.

Docs

Companion changes in nodespace-docs (pushed to main at merge time): ADR-064 amendment, prompt-skill-system.md, seeded-nodes.md, data-layer.md, and a note on ADR-057.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic code review: PR #3538 (issue #3502)

Review Type: Initial Review

Reviewed by reading code. No Rust suites were run by the reviewer, and the #[ignore]d live tests were not executed.

Summary

A clear net improvement, and the design matches the issue. No Critical issues. Four Important findings: one verified scope leak, one coverage gap on the new selection logic, one audience divergence on user-extended seeded skills, and one unevaluated in-app behaviour change.

Checked and found clean:

  • Project rules: no backfill or compatibility code, no literal node_type comparison outside tests, no lifecycle_status read, no issue numbers in comments, no lint suppression.
  • Typed search callers: the exact scan has two production callers, skill and schema, both small types.
  • Terminal sanitization: every graph-sourced field print_guidance prints in human mode goes through sanitize_for_terminal.
  • CLI-form fragments: every command and flag named under seeds/rules/skill-md/ exists in the clap definitions.
  • JSON key contract: the keys schema_definition_lines reads match EntityTypeDescriptor::to_json.

Requirements Check

# Criterion Note
1 Non-empty skill guidance returns matching skills, envelope unchanged, own-description query first ✅ Ranking proven by ignored live tests only.
2 Core, user-authored and Playbook skills; in-app ranking; no 0.7 floor ✅
3 Matches when non-skill embeddings exceed the KNN window ✅ Gate-run test.
4 Empty query lists every skill ✅ Gate-run CLI test.
5 Query also returns relevant schemas ✅ Live-test only.
6 Every schema embedded on all create paths; a test fails otherwise ✅ Gate-run.
7 Changing description, fields or relationships re-queues ✅ See finding 7.
8 In-app find_skills returns schema matches, tested with real embeddings ✅ Live.
9 External guidance names no in-app tool; test ✅ Graph Editing description exception pinned and disclosed.
10 In-app rendering unchanged apart from content fixes ⚠️ Goldens lose only the H1 lines, but see finding 4.
11 search --type skill returns skills; unfiltered excludes system types ⚠️ Finding 1.
12 No leading H1; no child repeats the name ✅
13 relationship-reverse-traversal reaches the in-app agent; coverage test ✅
14 Direction rule reaches both audiences from one fragment ✅
15 SKILL.md teaches the fetch, no skill-owned procedure, no contradiction ✅
16 SKILL.md states further instructions live in NodeSpace; no "Playbook" ✅ Survives only in reference file names.
17 External agent in an installed domain fetches before acting ⚠️ 5 of 5 by hand on one harness; not reproducible from the repo.
18 Goldens regenerated and reviewed ✅
19 ADR-064 §5 and prompt-skill-system.md updated ✅ In the local docs tree, not yet pushed.
20 Regression test runs a non-empty query end to end ⚠️ Exists but is #[ignore] (finding 2).
21, 22 quality:fix, test:changed ⚠️ Not run by the reviewer.

Findings

1. 🟡 Important: an empty node_types list now turns off scope filtering for real queries
📁 packages/core/src/ops/search_ops.rs:54-56, 727-728; packages/core/src/services/mod.rs:141-146; packages/agent/src/local_agent/tools.rs:3584

should_skip_scope_filter is fed input.node_types.is_some(), and SearchNodeFilters::matches treats Some(vec![]) as "no restriction". So node_types: Some([]) with a real query skips the Knowledge allowlist with no type filter, and returns system types. The in-app search_semantic tool passes the model's node_types straight through. The daemon's SearchNodes handler maps an empty list to None, so the CLI is safe. Recommendation: pass is_some_and(|t| !t.is_empty()) and add the case to the unit test. Principle: fail closed; an empty filter must not widen access.

2. 🟡 Important: find_skill_guidance's selection logic has no test the gate runs
📁 packages/core/src/ops/skill_ops.rs:918-1005

Every test reaching it is #[ignore]. Unguarded in the one automated run: the 0.85 bar, the named-type rule, the linked-versus-fallback rule, de-duplication, and the _seed.guidance_modified read. Recommendation: move the choice into a pure function over find_skills' entries and unit-test it (0.84 vs 0.85, below the bar but named, linked vs unlinked fallback, duplicate type). Principle: test logic at the layer where it needs no external resource.

3. 🟡 Important: a seeded skill the user extended is served to external agents without the extension
📁 packages/daemon/src/services/node_service.rs:2840-2857; packages/core/src/services/node_service/crud.rs:1984-2012

skill_guidance_entry replaces the stored body with the compiled seed whenever _seed.guidance_modified is false. That flag is stamped only in update_node. Adding, deleting or moving a child under a seeded skill does not stamp it, so the in-app agent reads the user's added paragraph and an external fetch gets the pristine seed. Recommendation: stamp the flag on child create, delete and move, or serve the CLI form only when the stored instructions equal the seed's in-app rendering. Principle: single source of truth. (The reviewer found the stamp site by grep and did not trace the create and delete paths line by line.)

4. 🟡 Important: the in-app agent now gets unfloored schema candidates on every turn, unevaluated
📁 packages/core/src/ops/skill_ops.rs:590-608

With schemas embedded, find_skills appends up to limit non-core schema entries to every result at threshold 0.0. The external path needed a bar for exactly this. The in-app path relies on routing to judge, and the matrix eval was not run. Recommendation: run the agent matrix on a workspace with custom types, or record explicitly that this is accepted.

5. 🟢 Suggestion: nodespace search "<q>" --type skill still runs KNN-then-filter with the default 0.7 threshold, so the rare-type window problem can recur there in a large graph (a suspicion, not traced). Worth a sentence in cli.md pointing agents at skill guidance.

6. 🟢 Suggestion: the SCHEMA banner drops the trust caveat. 📁 packages/cli/src/commands/skill.rs:662-668. Schema and field descriptions are free text anyone with write access can edit.

7. 🟢 Suggestion: the requeue comment overstates. 📁 packages/core/src/schema/mod.rs:3416-3427. A committed no-op update still queues, and a relationship-only change re-embeds identical text because relationships are not in the embedded content. Add relationship names to the embedded text or reword.

8. 🟢 Nit: find_skill_guidance re-reads each skill node for fields find_skills already held, and couples to its JSON by string key.

9. 🟢 Nit: the listing decision is duplicated in the CLI (skill.rs:547) and could drift from normalize_enumerate_query.

Recommendation

REQUEST CHANGES, narrowly. Finding 1 is a one-line fix plus a test case. Finding 2 is a small refactor that gives the 0.85 bar a gate-run test. Findings 3 and 4 need a decision. The rest are optional.

@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: REQUEST CHANGES (posted as a comment — GitHub blocks self-review verdicts). Full findings in the review comment above.

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (commit b927a01)

Addressed

  1. Empty node_types list (🟡). should_skip_scope_filter now takes the list itself and treats an empty one as no list, so it keeps the default scope. The unit test covers the empty case.
  2. Selection logic untested in the gate (🟡). The schema choice is now a pure function, guidance_schemas, with five tests the gate runs: at the bar versus just below it, below the bar but named, linked versus unlinked fallback, a type reached twice, and an entry missing the expected keys.
  3. User-extended seeded skill (🟡). The daemon no longer reads _seed.guidance_modified. A built-in skill is rendered in its CLI form only when its stored guidance equals the seed's line for line; any edit, added paragraph or removed one is served as stored. guidance_modified is gone from GuidanceSkill. Tests cover a rewrite, an added paragraph and a cut line.
  4. search --type skill (🟢). cli.md now says an untyped search leaves out system types and points skill lookups at skill guidance.
  5. Schema banner (🟢). It now says the descriptions are user-authored text anyone with write access can edit, and are not instructions.
  6. Requeue comment (🟢). Reworded: a rejected call queues nothing; a committed call queues, relationship-only changes included.

Not changed

  1. Unfloored schema candidates in the in-app path (🟡). Accepted, not fixed here. This is the behaviour the issue asks to make work ("In-app find_skills returns schema matches"), and it was designed and tested before this PR with hand-embedded schemas; what changed is that real databases now reach it. The in-app path has a judge the external path lacks: routing's score bars and Stage 2. Putting the external 0.85 bar on the in-app path would be an untested routing change of its own. The agent matrix eval was not run, and that remains the open risk on this PR. If it shows a regression, the lever is a floor on in-app schema hits (unrelated types topped out at 0.829 in the measurement).
  2. (second half) Relationship names are not added to the embedded text. A schema's relationships are declaration edges, not on the node the behavior embeds from, so this needs an accessor change that is beyond this PR.
  3. Node re-read (nit). Left. At most ten reads per fetch, and the string-key coupling it pointed at is now covered by the tests from finding 2.
  4. Duplicated listing rule (nit). Left. nodespace-core is not a runtime dependency of the CLI, and adding one for a two-clause check is not worth it. The line now carries a comment naming the rule.

Tests: bun run test:changed passes. The 37 live tests (real embedding model, including the end-to-end fetch through the daemon) pass.

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: Findings 2 and 3 changed logic, not wording: the schema choice was restructured, and what decides whether a built-in skill is served in its CLI form changed from a flag to a content comparison.

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic code re-review: PR #3538, commit b927a01

Review Type: Re-Review (read the code only; no suites run by the reviewer)

Previous Review Summary

  • Previous recommendations: 9
  • Addressed: 5 (findings 1, 2, 3, 5, 6); finding 7 partly addressed, remainder adequately declined
  • Declined adequately: 3 (findings 4, 8, 9); one stated reason for 8 is inaccurate (see B)
  • Not addressed: 0
  • New issues found: 2 (1 Important, 1 Suggestion), neither blocking
# Finding Status Note
1 Empty node_types list drops the default scope Addressed Takes Option<&[String]>, requires a non-empty list; test covers Some(&[]).
2 Selection logic had no gate-run test Addressed guidance_schemas is pure, with gate-run tests. A linked skill's schemas are now returned even when that skill's node read fails; harmless.
3 User-extended seeded skill served without the extension Addressed CLI form only when the stored lines equal the seed's in-app rendering. See A for the other direction.
4 Unfloored in-app schema candidates, unevaluated Declined, adequate Acceptance recorded; routing judges schema candidates on its own bars. The matrix eval is still not run and stays the open risk.
5 search --type skill still KNN-then-filter Addressed cli.md points skill lookups at skill guidance.
6 Schema banner dropped the trust caveat Addressed
7 Requeue comment overstates Addressed / declined, adequate
8 Node re-read and string-key coupling (nit) Declined, adequate as a nit Stated reason inaccurate, see B.
9 Duplicated listing rule (nit) Declined, adequate

On the content comparison: the gate-run seeded_markdown_round_trips_through_parse_and_render asserts the same line equality, with the same normalisation, for every seed body. No user change that alters meaning compares equal. A listing's empty body matches no seed. Startup reconciliation keeps stored and compiled seeds in step.

New Findings

A. 🟡 Important (not blocking): no gate-run test proves an untouched seeded skill still compares equal after a real database round trip
📁 packages/agent/src/skill_pipeline.rs:576-589; packages/daemon/src/services/node_service.rs:2841-2845

The CLI form depends on a comparison that fails soft: one differing line and the fetch silently serves the in-app body. The gate-run round-trip test skips the database, and the daemon unit tests feed the template straight in. Recommendation: in skill_guidance_fetch_mechanism.rs, for every seed, get_subtree_data then render_subtree_markdown, and assert external_skill_body(seed.id, &rendered) == Some(seed.external_body()). Principle: a fallback that degrades silently needs a test at the layer where it can break.

B. 🟢 Suggestion: an_entry_without_the_expected_keys_contributes_nothing does not guard what its comment says
📁 packages/core/src/ops/skill_ops.rs:1516-1523

The fixtures are hand-written, so a key renamed in find_skills would not fail it. Share the key names as constants, or reword the comment.

Suspicion, not verified, not introduced here: if a child added under a seeded skill does not stamp guidance_modified, the next reseed whose template hash differs would replace it.

Recommendation

APPROVE. Finding A is a cheap test worth folding in before merge. Finding B is optional.

@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). Findings in the re-review comment above.

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed

A (🟡). Added an_untouched_built_in_skill_read_from_the_store_is_served_in_its_cli_form, which the gate runs: for every seed it reads the subtree from a real database, renders it, and asserts it is still recognised as untouched and served in its CLI form. It passes for all 11.

B (🟢). Reworded the test comment: it documents that an entry missing the keys contributes nothing, and says a renamed key is caught by the live fetch tests, not by it.

Not changed: the reviewer's unverified suspicion that a child added under a seeded skill does not stamp guidance_modified, so a later reseed would replace it. That is the seed-durability path (ADR-072), it predates this PR, and this PR does not touch it.

Tests: bun run test:changed passes.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The re-review approved. This round adds one test and rewords one comment, with no change to product code.

malibio and others added 6 commits October 4, 2026 20:54
…render seeded skills per audience (#3502)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…reference, and add fetch, schema-embedding and exact-scan tests (#3502)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…d log schema scores (#3502)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ribe the fetch on the skill command (#3502)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…he fetch's schema choice, and serve a changed built-in skill as stored

- An empty node_types list no longer drops the default search scope.
- The fetch's schema choice is a pure function with tests the gate runs.
- A built-in skill is rendered in its CLI form only while its stored
  guidance is the seed's, so an added or removed paragraph is served too.
- The schema banner says its descriptions are user-authored.
- cli.md points skill lookups at skill guidance.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… is still served in its CLI form

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

Let agents fetch NodeSpace's skills and schemas by intent: make skill guidance return them, and embed schemas

1 participant