Skip to content

CLI --json leaks the nested storage shape instead of the flat API shape the flattener already defines #2381

Closed

Description

@malibio

What happened

An external Claude Code session, with no prior NodeSpace knowledge, loaded the skill and used it correctly — preflight, schema list, query. It then piped nodespace query --json into a Python script containing:

c = Counter(n['properties'].get('status', '(none)') for n in nodes)

That returned {'(none)': 1}. The agent nearly reported "1 task, status unknown" as a fact about the user's data.

It caught itself only because the result contradicted a constraint it had read a minute earlier — status is required: true with default: "open", so a task cannot legitimately lack one. It re-ran with a raw dump and found the real shape:

"properties": { "task": { "_schema_version": 1, "status": "open" } }

Properties are namespaced under the schema id. The flat accessor was wrong.

The agent's own conclusion, quoted:

I'd assumed a flat property bag, which is what the skill doc's example output shows

The docs caused this

1. The only properties example in SKILL.md is empty. Line 304 shows "properties": {} — structurally uninformative, and an empty object reads as "flat bag, currently unpopulated".

2. --json output shape is never documented. references/cli.md:12 says only:

All commands accept --json for machine-readable output.

Nothing describes the envelope or the property nesting. Any agent parsing it must guess, and flat is the natural guess.

3. The one place "namespace" appears actively misleads. cli.md:36:

do not add namespace prefixes when setting properties on instances (namespace prefixing, where it applies, is a schema-authoring concern)

That is about custom:-style field-name prefixes at schema-authoring time — a different concept from runtime property nesting under the schema id. An agent reading "don't use namespace prefixes on instance properties" can reasonably infer properties are flat. The doc is correct on its own terms and misleading in combination with the missing shape.

4. _schema_version is undocumented. It sits inside the namespace alongside real fields. Anything iterating property keys will trip over it.

Why this matters more than one bad script

The skill exists so external agents can drive NodeSpace with no prior knowledge. This agent did everything right — read the schema first, cross-checked before answering — and still produced a wrong intermediate result, because the documented shape does not match the wire shape. A less careful agent reports the wrong answer with confidence.

Note the asymmetry the agent identified: nodespace query --filters '{"property":"status"}' does resolve correctly against the schema, so the CLI's own filtering hides the nesting. It only bites when parsing --json directly — which is exactly what an agent does when output is too large for context (~30KB here).

The principle

A CLI consumer must never be able to tell that properties are stored nested. Namespacing is a storage-layer concern; it should be invisible across the entire CLI surface — output, input, filters, docs and examples alike. Not "documented so callers can cope with it", but absent from what a caller sees or types.

Today the CLI is inconsistent about this, and its own source says it intends the flat contract:

  • Writes are already bare. node update --property status=in_progress takes the plain field name; no namespace is typed by anyone.
  • Filters are already bare. --filters '{"property":"status"}' resolves against the schema.
  • output.rs documents the flat shape in two places — output.rs:84: // JSON so scripts can jq '.properties.foo' without a second parse. and output.rs:124: // Scripts pipe nodespace node get --json ID | jq '.properties.foo';. Both say .properties.foo — bare.
  • Only read output leaks, emitting .properties.<schema-id>.<field> instead.

So this is not a design change. It is the CLI failing to honour a contract it already states in its own comments, in the one direction nobody checked.

The real defect: the CLI leaks the storage shape

Filed initially as a docs gap. On investigation it is not — the flattening this needs already exists and is already the intended contract; the CLI simply does not apply it.

flatten_properties_for_api (packages/nodespace-types/src/convert.rs:63):

/// Storage format: `{ "task": { "status": "open" } }`
/// API format:     `{ "status": "open" }`
///
/// Dormant namespaces (from previous type changes) are not exposed.

It also filters _-prefixed keys, so _schema_version and _seed never reach a consumer. The frontend gets flat output through node_to_typed_value; convert.rs:216 calls this a contract, and convert.rs:408 has property tests guarding it against silent field-drop.

The CLI does not use any of it — no reference to flatten_properties_for_api, node_to_typed_value, or convert:: anywhere in packages/cli/src/. So --json emits the raw storage representation that the rest of the codebase has already decided should not cross the API boundary.

Documenting the nesting would enshrine that leak. The fix is to make the CLI emit the same flat shape every other consumer gets.

Storage should stay nested

Flattening at rest is not the answer, for reasons visible in real data:

skill →  {"_seed": {...}, "skill": {"description": ...}}

Two sibling namespaces coexist. Flattened at rest, _seed.version would collide with any schema field named version. Namespacing also lets dormant namespaces survive a type change, which a flat bag cannot represent. Storage nesting earns its keep; it just should not be what a CLI consumer sees.

The asymmetry this explains

--filters '{"property":"status"}' takes the bare field name (it resolves against the schema), while --json emits nested. The CLI is already half-flat — bare on input, nested on output. Applying the flattener makes it consistent in both directions, which removes the trap rather than documenting it.

Fix

  • Nesting is not observable anywhere on the CLI surface — no command's output, input, filter syntax, help text, doc or example exposes properties.<schema-id>
  • All read paths apply the existing flatten_properties_for_api contract — node get, query, search, schema-adjacent output, and any other command emitting a node
  • Both human-readable and --json output are covered (output.rs renders both)
  • The flat shape matches what output.rs:84 and output.rs:124 already promise: jq '.properties.foo' works with no second parse
  • _-prefixed internals (_schema_version, _seed) do not appear in CLI output, matching the frontend contract
  • Storage stays namespaced — no change at rest (skill's coexisting _seed + skill namespaces show why flattening at rest is unsafe)
  • Input and output agree: --filters '{"property":"status"}' and parsed --json use the same bare field name
  • SKILL.md's node example shows a populated properties object reflecting the flat wire shape, not {}
  • references/cli.md documents the --json shape rather than only stating that the flag exists
  • Verified against a core type and a user-defined type
  • Any skill docs or example scripts that assume the nested shape are updated in the same change (breaking output change — fine per CLAUDE.md's zero-users rule, but must not be left half-done)

Verified

On a clean v0.2.7 install, nodespace query --type task --json returns exactly:

"properties": { "task": { "_schema_version": 1, "status": "open" } }

Source of truth is packages/skill/ in this repo; nodespace-skill is a generated publish target and must not be edited directly.

Activity

  1. added
    bug
    documentation
    on Sep 7, 2026
  2. changed the title [-]Skill docs imply flat node properties, but --json nests them under the schema id[/-] [+]CLI --json leaks the nested storage shape instead of the flat API shape the flattener already defines[/+] on Sep 7, 2026
  3. malibio commented on Sep 7, 2026

    @malibio
    CollaboratorAuthor

    Baseline (worktree issue-2381-cli-flat-properties): Frontend: 4863 passed across 232 test files, 0 failed.

  4. self-assigned this
    on Sep 7, 2026
  5. added a commit that references this issue on Sep 7, 2026
    f6828b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugdocumentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions