Skip to content

import dir takes one directory at a time; accept several in one call #2398

Closed

Description

@malibio

Problem

nodespace import dir accepts exactly one directory:

Usage: nodespace import dir [OPTIONS] <DIRECTORY>
  <DIRECTORY>  Path to the directory containing markdown files

Importing several unrelated folders means a shell loop:

for d in docs/adr docs/specs; do nodespace import dir "$d"; done

Which works, but is one process per directory, one connection per directory, and no single summary of what was imported. For an agent driving this it is also several tool calls where one would do.

Recursion covers the common case — pointing at a shared parent walks the tree, with --exclude to prune — so this only bites when the folders are genuinely disjoint or live under different roots. That makes it an ergonomics gap rather than a missing capability.

Suggested

  • import dir accepts multiple directories: nodespace import dir docs/adr docs/specs
  • One summary across all of them, not one per directory
  • Per-directory failures do not abort the rest; the summary reports which succeeded and which did not
  • Existing flags apply across the whole invocation (--collection, --exclude, --replace, --auto-collection-routing, --use-filename-as-title)
  • --auto-collection-routing routes relative to each directory's own root, not a synthesised common ancestor — otherwise two disjoint trees produce surprising collection paths
  • A single directory keeps behaving exactly as today

Skill and guidance updates (ship with the change, not after)

A CLI capability agents do not know about is one that does not exist. This session produced several findings of exactly that shape — a documented rule that never fired, or a real capability filed where nobody looked — so the guidance half ships with the change.

  • Skill guidance shows the multi-directory form where import is documented, so it is what an agent copies
  • The --replace and --auto-collection-routing flags are documented alongside it — both are directly relevant to a repeated import and neither is currently surfaced in the skill
  • Import is reframed from a one-off bulk operation to a repeatable sync: --replace refreshes a document's subtree while keeping its root, so inbound links survive re-import
  • Updates land in packages/agent/src/skill_rules.rs and packages/skill/SKILL.md — the sources of truth; references/cli.md and the published nodespace-skill repo are generated, and a hand edit there is overwritten on the next release
  • The generated references/cli.md argument list reflects the new arity
  • Verified against a cold agent: asked to import two unrelated folders, it uses one call rather than a shell loop

Note on the surrounding flags

The flags themselves are good and mostly undocumented in the skill. Two that matter for the docs-import plan:

  • --auto-collection-routing — directory structure becomes collections. This is the answer to the tagging/grouping question: the folder layout is the collection hierarchy, for free.
  • --replace — refreshes an existing document's child subtree while keeping the root node, so inbound links survive a re-import. Without it, already-imported documents are skipped, so a plain re-import never duplicates.

--replace is the piece that makes markdown-on-disk a viable source of truth: import builds the tree, re-import updates it in place rather than orphaning links. Worth surfacing in the skill's import guidance, which currently frames import as a one-off bulk operation.

Context

Raised by an external agent asked whether multiple folders could be imported in one call. Its answer was correct — one at a time, loop for more — and the follow-up observation about --replace is what makes the round-trip workable.

Activity

  1. added
    enhancement
    on Sep 7, 2026
  2. self-assigned this
    on Sep 8, 2026
  3. mstomar125 commented on Sep 8, 2026

    @mstomar125
    Contributor

    Fixed in #2470 (merged).

    nodespace import dir now accepts several directories in one call: nodespace import dir docs/adr docs/specs. A single directory keeps behaving exactly as before (same code path, unchanged, including a scan failure aborting the whole command). Two or more directories walk and import each one against its own base_directory (so --auto-collection-routing stays relative to each directory's own root, not a synthesised common ancestor), combine into one summary instead of one per directory, and a per-directory scan/import failure is recorded without stopping the rest.

    An adversarial review of the first version of this PR caught a real, silent-data-loss bug before merge: two directories in one call that each contain a same-named file (e.g. both have a top-level README.md) would compute the same deterministic document id server-side, so the second file would either be silently skipped as "already imported" or, with --replace, silently overwrite the first's content. Fixed by scanning every directory up front and refusing the whole call — before any RPC is issued — if two files would collide on identity. Also fixed: the command previously reported success (exit 0) even when every directory failed; it now propagates failure like the single-directory form always has.

    • packages/skill/SKILL.md + a new "Import markdown files" section in references/cli.md document the multi-directory form, --replace as a repeatable-sync mechanism, and the per-directory routing guarantee
    • Regression tests: multi-directory import, --auto-collection-routing routes relative to each directory's own root (verified via collection membership, not just the printed string), a missing directory doesn't stop a sibling's import but the call still reports failure, the identity-collision refusal (plus a negative case proving it doesn't over-fire), single directory unchanged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions