Skip to content

Accept multiple directories in nodespace import dir, combined into one summary - #2470

Merged
mstomar125 merged 5 commits into
mainfrom
issue-2398-import-dir-multi
Sep 8, 2026
Merged

mstomar125 merged 5 commits into
mainfrom
issue-2398-import-dir-multi

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

import dir took exactly one directory, forcing a shell loop to import several unrelated folders — one process, one connection, one result set per directory, with no combined summary. The RPC layer already batches an arbitrary file list into one call; what kept the CLI to one directory at a time was its own base_directory handling, needed for --auto-collection-routing to stay relative to each directory's own root rather than a synthesised common ancestor.

Changes

  • ImportDirArgs.directory: String → directories: Vec<String> (positional, num_args = 1.., required)
  • A single directory (run_one_dir) keeps behaving exactly as before this change — same code path, unmodified, including a scan failure aborting the whole command via ?
  • Two or more directories (run_multi_dir) walk and import each one against its own base_directory, combining results into one summary instead of one per directory. A per-directory scan or import RPC failure is recorded in the combined results and does not stop the rest from running
  • packages/skill/SKILL.md + a new "Import markdown files" worked-example section in references/cli.md cover the multi-directory form, --replace as a repeatable-sync mechanism, and the "routes relative to its own root" guarantee

Acceptance criteria (issue #2398)

  • 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
  • A single directory keeps behaving exactly as today
  • Skill guidance shows the multi-directory form, documents --replace/--auto-collection-routing, reframes import as a repeatable sync

Test plan

  • New integration test suite packages/cli/tests/import_dir_multi.rs (real in-process daemon with both NodeService and ImportService registered): multiple directories import in one call; --auto-collection-routing routes each file relative to its own directory's root (proven via collection-membership + "stays a top-level collection" assertions, not just the printed collection string); a missing directory doesn't abort a sibling's import; a single directory still works
  • All 4 new tests mutation-tested individually — broke the real code, confirmed each test fails, restored, confirmed it passes (including one case where my first assertion design turned out not to catch a real mutation — collection names are globally unique, so a wrong base_directory producing a garbled-but-same-leaf-named path slipped past a membership check alone; strengthened it to also assert the collection stays parent-less, which does catch it)
  • bun run test:all — no new failures
  • bun run quality:fix — clean

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

mstomar125 and others added 5 commits September 8, 2026 12:19
…e summary

import dir took exactly one directory, forcing a shell loop to import several
unrelated folders -- one process, one connection, one result set per
directory, with no combined summary. The RPC layer already batches an
arbitrary file list into one call; the CLI's own base_directory handling
(needed for --auto-collection-routing to stay relative to each directory's
own root) is what kept it to one directory at a time.

A single directory keeps behaving exactly as before (same code path,
unmodified, including a scan failure aborting the whole command). Two or more
route through a new aggregating path: each directory is walked and imported
against its own base_directory, results combine into one summary, and a
per-directory scan or import failure is recorded without stopping the rest.

Co-Authored-By: Claude <[email protected]>
…ires

Trimming for the token budget had reworded "don't follow up with search
calls to verify" away, which broke
skill_rules::tests::skill_md_still_mentions_every_interaction_rule
(bulk-import-no-followup-search's skill_md_key_phrase). Restored the
sentence introduced by #2466 verbatim instead of layering more prose on
top of an already near-full budget; the multi-directory form is taught by
the worked example already in this section plus the dedicated "Import
markdown files" section in references/cli.md.

Co-Authored-By: Claude <[email protected]>
… exit failure

- Two directories in one `import dir A B` call that each contain a
  same-named file (e.g. both have a top-level README.md) compute the
  identical deterministic root id server-side (derived from each file's
  path relative to that call's own base_directory). Silently proceeding
  either skips the second file as "already imported" or, with --replace,
  overwrites the first's content with the second's -- confirmed via a
  mutation test that reproduces exactly this collision when the new
  pre-flight check is disabled. Now scans every directory before issuing
  any RPC and refuses the whole call, loudly, if any two files would
  collide, so nothing is written rather than something being silently
  lost or corrupted.
- run_multi_dir returned Ok(()) even when every directory failed,
  breaking the exit-code contract run_one_dir already had (a scan
  failure there propagates via `?` to a non-zero process exit). Now
  returns Err when any directory failed, after printing the combined
  summary/JSON, so a caller checking the exit code notices.
- Removed two GitHub issue numbers embedded in doc comments (CLAUDE.md
  rule).

Co-Authored-By: Claude <[email protected]>
@mstomar125
mstomar125 merged commit fbb1caf into main Sep 8, 2026
@mstomar125
mstomar125 deleted the issue-2398-import-dir-multi branch September 8, 2026 11:09
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