Skip to content

Add a discoverable schema delete subcommand (closes #2397) - #2435

Merged
malibio merged 2 commits into
mainfrom
issue-2397-schema-delete-discoverable
Sep 7, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2397-schema-delete-discoverable

Conversation

@malibio

@malibio malibio commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #2397.

The defect

Deleting a schema already worked — schemas are nodes, so node delete <id> removed one — but nothing in the CLI's own surface revealed it. nodespace schema --help listed list/get/create/update, and a subcommand group listing four verbs reads as the complete set of operations on that noun. An agent enumerating the group saw a deliberate omission rather than a redirect, told the user the capability did not exist, and proposed stripping the schema to an empty shell instead.

Because schema create is available to agents, that asymmetry meant an agent could add schemas to a user's workspace and then report the mess as unfixable.

Decision: a real subcommand, not prose

The issue left this open. I added nodespace schema delete <id>.

The deciding factor is what an agent actually enumerates. packages/skill/references/cli.md generates its "Complete command surface" section by walking Cli::command() (packages/cli/examples/gen_skill_md.rs), so a new clap variant propagates into the shipped agent-facing guidance automatically and, per that generator's own contract, cannot fall behind the binary. A redirect line in schema --help would have been cheaper, but it lives only where an agent has to already be reading — and the failure mode here was precisely an agent trusting the verb list.

The subcommand dispatches to the same DeleteNode RPC, so it is a discoverability fix rather than a new code path. The daemon's existing guard still applies unchanged: a schema still carrying relationship declarations is rejected with schema_has_declarations, naming the remaining count and the fix. That satisfies the issue's "handle the prerequisite itself, or fail with the same actionable message" criterion via the second branch.

Guidance (same PR, per the standing rule)

A CLI capability agents don't know about is one that doesn't exist. Edited the sources of truth, not the generated output:

  • packages/agent/src/skill_rules.rs — new DELETE_A_SCHEMA rule, added to SCHEMA_RULES. It states the recognition trigger rather than only the conclusion: asked to remove, drop, undo or clean up a node type — including a throwaway type you created yourself this session. It names the superseded workaround explicitly ("never propose stripping a schema to an empty shell"), so the pattern is removed rather than left standing alongside. The prerequisite is stated in advance, including the non-obvious half — a declaration on another type that targets this one blocks it too — and framed as the mirror of the existing targetType rule: a relationship's target must exist to declare it, and must be absent to delete the type it points at.
  • packages/cli/examples/gen_skill_md.rs — renders the new rule into the generated schema-rules region.
  • packages/skill/SKILL.md — the "Delete a node" task now covers the type case alongside the node case, so the two deletion paths sit together rather than the type case being a footnote elsewhere.

packages/skill/references/cli.md is partly generated and was updated by running bun run skill:gen, never by hand: three marker-delimited regions (schema-rules, cli-surface, builtin-relationships) come from skill_rules.rs, the clap derive, and BUILTIN_RELATIONSHIP_NAMES respectively. The surrounding worked-example prose is hand-maintained and outside the markers, so the delete sequence was added there directly. The nodespace-skill repo is published from these files by scripts/publish-skill-repo.ts and was not touched.

Two incidental trims, flagged for review

skill_md_body_is_within_spec_size_recommendations caps the SKILL.md body at ~5000 tokens, and the body was already within ~20 characters of that ceiling — so any addition overflowed it. The test's own instruction is to move detail into references/. Rather than erode unrelated guidance, I cut duplication:

  • The ticket example's inline enum blob is reduced to its shape; the full field/enum form is already in references/cli.md verbatim, which the comment now points at.
  • The "Build a knowledge graph session" snippet is dropped — it only restated the Preflight Check commands and the save-as-you-go guidance from "When to Use NodeSpace" above it.

Both are judgment calls beyond the strict scope of the issue, so they're worth a look.

Testing

  • New schema_delete_requires_relationship_declarations_removed_first in packages/cli/tests/cli_integration.rs covers the full loop: a self-referential declaration blocks the delete, the rejection names both the guard and the fix, clearing the declaration unblocks it, and the deleted schema no longer resolves.
  • bun run test:all — frontend 233 files / 4900 tests passed, identical to baseline; no new failures anywhere.
  • Pre-push gate (test:all + cargo build --bin nodespaced + full e2e) passed.
  • Verified separately that deleting a schema node does not cascade to its instances (instances are independent node rows), which is what the new guidance claims.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY

malibio and others added 2 commits September 7, 2026 23:19
Deleting a schema already worked — schemas are nodes, so `node delete <id>`
removed one — but nothing in the CLI's own surface said so. `schema --help`
listed four verbs, which reads as the complete set of operations on that noun,
so an agent enumerating the group saw a deliberate omission rather than a
redirect and reported the capability as missing. Since `schema create` is
available to agents, that asymmetry let an agent add schemas to a workspace
and then report the mess as unfixable.

Adds a real `schema delete <id>` rather than documenting the `node delete`
path, because the help output is what an agent enumerates: `references/cli.md`
generates its "Complete command surface" by walking `Cli::command()`, so the
new clap variant propagates into the shipped agent guidance automatically and
cannot fall behind the binary. A prose redirect would have been cheaper but
would live only where an agent has to already be reading.

The subcommand dispatches to the same `DeleteNode` RPC, so the daemon's
existing guard still applies: a schema carrying relationship declarations is
rejected with `schema_has_declarations`, naming the count and the fix. That
prerequisite is now stated in advance rather than discovered by hitting it.

Guidance (a CLI capability agents don't know about is one that doesn't exist):
- `skill_rules.rs` gains a DELETE_A_SCHEMA rule stating the recognition
  trigger — asked to remove/drop/undo/clean up a type, including a throwaway
  one the agent created itself — not just the conclusion, and naming the
  stripping-to-an-empty-shell workaround as the thing not to do.
- The rule frames the prerequisite as the mirror of the existing targetType
  rule: a relationship's target must exist to declare it, and must be absent
  to delete the type it points at.
- `SKILL.md`'s "Delete a node" section covers the type case alongside it.

Two incidental trims keep the SKILL.md body within its 5000-token budget,
which it was already within ~20 characters of: the ticket example's inline
enum blob (duplicated in full in `references/cli.md`) is reduced to its shape,
and the "Build a knowledge graph session" snippet is dropped as it only
restated the Preflight Check and save-as-you-go guidance above it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY
The delete rule was wired into the shipped SKILL.md but not into the local
agent's seed prompt, so only the external shell agent got the fix. The in-app
agent is the surface holding BOTH create_schema and delete_node, which means it
reproduced the exact create/delete asymmetry this work exists to close: asked
to drop a type it had just created, its prompt carried EDIT_DONT_RECREATE and
RENAME_VS_RELABEL but nothing about deletion.

`schema_creation_guidance()` is the sole renderer of `imperative` for this rule
family, per the contract in skill_rules.rs, so DELETE_A_SCHEMA now interpolates
there alongside the other procedure rules. The prompt-assembly golden is updated
accordingly — the diff is exactly the new paragraph, which is the confirmation
that the rule now reaches the model.

Scoping corrections to the rule text, in both forms:
- Only declarations BETWEEN SCHEMAS block the delete. The guard counts edges
  whose endpoints are both schema nodes, so instance edges are irrelevant; the
  previous "relationship declarations" phrasing was broad enough to send an
  agent unpicking instance data it never needed to touch.
- Deleting a type does not delete its instances. Since the rule actively pushes
  agents toward deletion, saying so prevents both over-promising to the user and
  a needless refusal to delete.

Also: name type deletion in the consent rule (it is strictly more destructive
than node deletion, which was already named), assert the declaration count in
the CLI test since the guidance tells agents to act on that count, and trim the
delete fn doc to the part the clap variant doc does not already state.

Skipped: a companion test asserting that every SchemaRule's `imperative` reaches
the seed prompt. Five of the fifteen rules are prose-only by design — the
argument-shape rules moved onto create_schema's own tool schema under ADR-064 —
so such a test needs a hand-maintained exclusion list encoding that decision,
which is a drift source of its own. The golden snapshot already fails loudly on
any change to what the prompt sends, which covers the regression that matters.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY
@malibio

malibio commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed — c49c21b

Thanks for the verification pass; the Important finding was correct and is the substantive fix here.

✅ Addressed

🟡 1 — DELETE_A_SCHEMA.imperative was dead text. Confirmed exactly as described: schema_creation_guidance() interpolates nine rules by .imperative and mine wasn't among them, so only the external shell agent got the fix. That matters because the in-app agent is the surface holding both create_schema and delete_node — it reproduced the same create/delete asymmetry this PR exists to close, just on the other surface.

Added {delete_a_schema} with .imperative to the format string. prompt_assembly_snapshot's stage2_candidate_block golden then failed, which is the useful confirmation that the rule now reaches the model — the diff is exactly the new paragraph and nothing else. Golden updated and reviewed.

🟢 2 — Prerequisite framing narrower than the guard. Fixed in both imperative and prose, so both surfaces get it:

  • Only declarations between schemas block the delete — instance edges don't count, so an agent shouldn't go unpicking them.
  • Deleting the type does not delete its instances. Since the rule actively pushes agents toward deletion, this prevents both over-promising and a needless refusal.

This costs nothing against the SKILL.md cap: the schema-rules region renders into references/cli.md, which has no size assertion.

🟢 3 — Consent discipline. SKILL.md:68 now reads "delete a node or type". Type deletion is strictly more destructive and wasn't named. Fits in the headroom; the cap test passes.

🟢 4 — Test assertion. Added a count assertion. Worth noting it caught a real error: I first asserted 2 relationship declaration(s) reasoning that a self-reference touches the schema at both ends, and the test proved it's 1 — one stored edge. Comment records why.

🟢 5 — Redundant doc comment. Trimmed the delete fn doc to what the clap variant doc doesn't already state (why it routes through DeleteNode); the prerequisite is stated once, in the variant doc that ships into --help.

⏭️ Skipped (1)

Companion test asserting every SchemaRule.imperative reaches the seed prompt. Flagged as a judgment call, and I don't think it earns its keep. Five of the fifteen rules are prose-only by design — the argument-shape rules moved onto create_schema's own tool schema under ADR-064 — so a blanket test needs a hand-maintained exclusion list encoding that architectural decision, which is a drift source of exactly the kind it's meant to prevent. The prompt_assembly_snapshot golden already fails loudly on any change to what the prompt sends, which covers the regression that actually matters. Happy to add it if you'd rather have the explicit guard.

Also per your note, the update_schema vs schema update vocabulary split is left alone — the imperative/prose split gives each surface its correct vocabulary.

Testing

bun run test:all — 233 files / 4900 tests, identical to baseline, no failures. quality:fix clean (0 errors, 0 warnings). Pre-push gate green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY

@malibio
malibio merged commit 3e432e5 into main Sep 7, 2026
@malibio
malibio deleted the issue-2397-schema-delete-discoverable branch September 7, 2026 21:50
malibio added a commit that referenced this pull request Sep 8, 2026
`main` is currently red: `object_property_round_trips_through_relationship_get`
declares `held_at -> venue` with no `reverseName`/`reverseCardinality`, which
the validation added in #2437 rejects, so the test fails at schema creation
before reaching what it exists to verify.

Neither PR's gate could have caught this. #2436 added the fixture and #2437
added the rule; each was validated against a base that predated the other, and
the squash merges landed 33 minutes apart. This is the same collision #2437's
review caught between #2435 and #2437 — the third instance of a green gate on a
stale base proving nothing about the merge result.

A concert is held at one venue and a venue hosts many concerts, so the inverse
is `concerts`/`many`.


Claude-Session: https://claude.ai/code/session_01KHdtH4eZHiU7RzhCuHArQX

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
malibio added a commit that referenced this pull request Sep 8, 2026
…prompt (#2479)

* Guard against a SCHEMA_RULES entry silently missing the in-app agent prompt (closes #2438)

Adds schema_rules_are_wired_or_explicitly_excluded, a test that checks every
SCHEMA_RULES entry is either interpolated into schema_creation_guidance() (the
in-app agent's prompt) or named in the new SCHEMA_RULES_NOT_IN_PROMPT
exclusion list, with the ADR-064 rationale recorded inline for the five
field/enum shape rules that are deliberately prose-only.

This closes the gap that let DELETE_A_SCHEMA (PR #2435) reach the shipped
SKILL.md without ever being wired into the in-app prompt: the existing
every_schema_rule_reaches_the_skill test only checks the SKILL.md renderer,
and the prompt_assembly_snapshot golden cannot catch an unwired rule since it
never changes the rendered output. Verified the new test actually fails on an
unwired rule and on a wrongly-excluded one before finalizing the failure
messages, which name the two concrete fixes (wire it, or exclude it with a
reason) rather than just reporting a mismatch.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY

* Fix enum-edge-fields exclusion comment to state the truth

Review of PR #2479 caught that the enum-edge-fields entry in
SCHEMA_RULES_NOT_IN_PROMPT claimed enforcement via create_schema's
edgeFields tool-schema description. Neither create_schema nor
update_schema takes an edgeFields parameter (local_agent/tools.rs) --
the only enforcement is the post-hoc validator in
packages/core/src/schema/mod.rs, which runs after the model has
already committed to a shape. That's exactly the failure mode
ADR-064 exists to prevent for this rule category.

Rewrote the comment to say so plainly: the rule sits in the
exclusion list per ADR-064's intent, but the tool-schema side that
intent describes hasn't been built for this specific rule yet.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY

---------

Co-authored-by: Claude Sonnet 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.

Schema deletion is undiscoverable: 'schema --help' shows no delete, so agents report the capability as missing

1 participant