Skip to content

Create a node from a markdown document; import takes front matter as properties - #4247

Merged
mstomar125 merged 3 commits into
mainfrom
issue-4237-md-create
Nov 5, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-4237-md-create

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Part of #4237. Does not close it: the agent-lane pieces (see "Not done") are left, because they live in packages/agent.

What changed

  • Opt-in entry point. The split is node_ops::create_document_node, reached by a new CreateDocument RPC (same request/response types as CreateNode; no existing literal changes) that only the CLI's node create calls. node_ops::create_node, the CreateNode RPC, the editor and every existing agent tool store content exactly as before. (An earlier revision put the split in create_node itself, which would have split editor and agent-tool content; that is gone.) For a type that is not a document type, or content that is a single block with no front matter, create_document_node is create_node.
  • Document types (allow-list, extends chain honoured): text, task, project, spec, plan, decision, issue, software-project and user types extending them. code-block, quote-block, table, the other block types and types named otherwise keep multi-line content; person keeps rejecting content.
  • Split: the first non-empty line becomes the node's content (a #..###### marker stripped, via the importer's own helper) and the rest is parsed with prepare_nodes_from_markdown and written with bulk_create_hierarchy.
  • Title rule (refused with InvalidParams, nothing created): the first line must be a plain line or a heading. A code fence, table row, numbered or bullet item, quote, checklist item or --- as first line is refused with a message naming the shape.
  • Front matter (core/src/markdown/document.rs, new serde_yaml_ng dependency): a block is front matter when line 1 is exactly ---, a later line is exactly --- or ..., and the lines between parse as a non-empty YAML mapping with unique string keys. In the document path, a closed --- block that does not parse that way (YAML error, list, plain text, repeated or non-string key) is refused with a clear error and nothing is created. In the importer such a block keeps being imported as the lines it is (horizontal lines and text), as today.
  • Key rule: a key the type declares (found via undeclared_core_keys) is set as that field and validated by the normal create (decision_status: maybe is refused with the field's message); a key already namespaced (custom:, org:, plugin: with a non-empty name) is stored as given; a key starting with _ is dropped; a key that names a core type or is an empty namespace is stored as custom:<key>; any other key on a core type is custom:<key>. For a type that is not a core type itself (a user subtype), undeclared_core_keys reports nothing and its open bucket takes keys as given, so those keys are stored without the prefix. An explicit properties argument wins over a front matter key. Front matter with no title is refused.
  • Caps: content over 1,000,000 bytes (same cap as the agent's create-from-markdown path) is refused before parsing; more than 1000 nodes is refused.
  • Atomicity (weaker than one transaction, stated). The root goes through create_node (placement, collections, lifecycle, validation) and the body is a second transaction (bulk_create_hierarchy). If the body fails, the root is deleted again and the call fails, so nothing is left; the root is briefly visible and a created then deleted event pair is emitted. Writing both in one transaction would need create_placed_node_in_collections split apart, which I judged too large here. create_document_node uses the validating bulk_create_hierarchy while the importer uses bulk_create_hierarchy_trusted (behaviour validation only), so a body can pass import and be refused by create when the root's type has children rules the text root of an import does not; the error surfaces and nothing remains.
  • Import: front matter is stripped before the title is chosen and becomes custom:<key> properties of the text root (single-file, batch and --replace), creating no node. FileImportResult gets front_matter_keys (proto field 8), printed by import file, in --json and in the daemon summary. Untouched (already imported, no replace) documents report 0. On --replace the new keys are merged into the root's properties; keys from an earlier version of the file that the new front matter no longer has are not removed.
  • root_content_for_title and content_without_title_line moved to core::markdown; import_markdown_content takes a DocumentOptions struct instead of eight arguments.
  • CLI node create --content help, SKILL.md and references/cli.md describe the behaviour (skill:gen regenerated, skill:check clean).

Tests

Core (tests/it/markdown_document_create_test.rs, 18 tests; markdown::document unit tests, 8): decision title + parsed body; marker stripped in each shape; single block unchanged; markup types keep content; person still rejects; the_generic_create_does_not_split_a_multi_block_node (text, task, decision, with and without front matter); every refused first-line shape; every malformed front matter shape; declared field and invalid value; custom: for string, list, nested, number, bool; namespaced and _ keys; empty namespace; explicit property wins; non-object properties refused; subtype gating in both directions (issue, a user type extending decision split; a plain user type does not); node cap and size cap; parent, position and collection kept with a body; a body write that fails leaves no root.
Daemon: CreateNode RPC stores content as given while CreateDocument splits, sets decision_status, and returns InvalidArgument without creating anything for a bad title; importer front matter tests (both import paths); created document body equals the same text imported as a file.
Mutation checks (production change, intended test fails, reverted): CreateNode also splitting (daemon test), title check removed, malformed block ignored, size cap removed, root cleanup removed, front matter winning over explicit properties, non-object properties ignored, document types removed (15 core tests fail), node cap removed, empty-namespace rule removed (unit test), plus the first round (single-block gate, custom: prefix, type gate, marker strip, children insert, import front matter, import key count).
Ran: cargo fmt --check, cargo clippy -p nodespace-core -p nodespace-daemon -p nodespace-cli -p nodespace-proto --all-targets -- -D warnings -D clippy::unused-async, core lib markdown:: (145), core --test it markdown_document_create (18), daemon import_service (47) and the CreateDocument RPC test, cli import (18), bun run skill:check; pre-push lint gate.

Not done

  • The agent's own create_node tool does not take documents: it calls node_ops::create_node, which is deliberately unchanged, and packages/agent is not touched here. Giving it the behaviour means calling create_document_node from the tool (a packages/agent change). The seeded rules, graph skills, prompt snapshots and shape:check reconcile entries are in packages/agent too.
  • The skill's minimum CLI version is stamped from the workspace version at release time; it is not bumped here.
  • No end-to-end run against a scratch NODESPACE_HOME.

🤖 Generated with Claude Code

mstomar125 and others added 3 commits November 5, 2026 12:39
…properties

node_ops::create_node treats the content of a document-type node (text,
task, project, spec, plan, decision and their subtypes) given more than one
block, or front matter, as a markdown document: the first line (heading
marker stripped) is the node's content and the rest is parsed into child
nodes by the importer's parser. Markup types and title-template types keep
their content as given.

A leading front matter block (YAML mapping between --- lines) becomes
properties of the root instead of nodes: a key the type declares is set as
that field, a namespaced key is kept, a leading-underscore key is dropped,
and any other key is stored as custom:<key>. Import applies the same rule
to the text root, and the import result reports the stored key count
(new front_matter_keys field, printed by the CLI).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…matter

The split moves out of node_ops::create_node into node_ops::create_document_node,
reached by a new CreateDocument RPC that only the CLI's node create calls.
CreateNode, the editor and the agent tools store content as given.

In the document path: the first line must be a plain line or a heading;
a closing-delimited --- block that is not a YAML mapping with unique string
keys is refused; content over the markdown size cap is refused before
parsing. An empty namespace (custom:) is not a namespace. The importer
keeps treating such a block as the lines it is. import_markdown_content
takes a DocumentOptions struct instead of eight arguments.

Co-Authored-By: Claude Sonnet 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.

1 participant