✨ feat(sarathi): sarathi where answers module-graph questions from the project's depcruise, 0.8.9

Merged
AT
3d ago
+966-7

Slice: #566

sarathi where is a port of athya_mono's scripts/where.ts (W-69, athya-hq/athya_mono#3631). Once it ships, athya_mono deletes its own copy and calls sarathi where.

What it keeps

  • The modes: <regex> (focus, --depth N, default 1), --reaches/-r, and --affected [rev] (default main).
  • The flags: --scope DIR (repeatable, default apps packages), --max N (default 60) and --help.
  • The output: one a → b edge per line, deduplicated and sorted, then … N more of M (raise with --max) when it truncates.
  • EXCLUDED, unchanged.
  • The exit codes: 0 is an answer, 2 a usage error, and every other failure is non-zero. athya_mono's android e2e gate reads non-zero as "the graph failed, run everything".

What changes for a package

  • depcruise: where runs the project's own node_modules/.bin/depcruise, found from git rev-parse --show-toplevel, so sarathi gains no dependency. Without it, where refuses and names the binary.
  • Config: the dependency-cruiser config comes from --config, or from where.config in .claude/sarathi.json. With neither, where refuses rather than fall back to the project's default config. athya_mono's gate config deliberately resolves @athya/shared to dist, and a fallback to it would look right while losing edges.
  • Failures: no checkout, no binary, no config, a killed child, or a failed cruise that printed nothing all exit 1, with the reason on stderr. stdout carries only the answer.
  • sarathi check: it validates the new where key, and config.ts accepts it at the top level.

Upgrade order: releases before this one refuse a top-level where key, and on PreToolUse that refuses every tool call. A project adds the key only once every checkout runs the new release, and uses --config until then. The README section says so.

Tests: where.test.ts covers argument parsing, the depcruise arguments, EXCLUDED, the edge formatting and truncation, the spawn-failure handling, and whereMain in real git checkouts against a stub depcruise. athya_mono keeps one wiring test that runs against its real repository.

Version: sarathi goes to 0.8.9 and shares v0.8.9 with W-50's pariksha PR, as the 0114 coordinator decided. Whichever PR merges second pushes the tag.

🤖 Generated with Claude Code


Summary by cubic

Adds sarathi where, a port of athya_mono's scripts/where.ts, that answers module-graph questions from the project's own dependency-cruiser, so a session need not open files to find what a module sits next to or what depends on it.

  • Supports <regex> focus with --depth N, --reaches/-r, and --affected [rev] (default main), plus --scope DIR (repeatable, default apps packages; a folder starting with - is refused, since depcruise would read it as an option), --max N (default 60), and --help.
  • Prints one a → b edge per line, deduplicated and sorted, then … N more of M (raise with --max) when truncated.
  • Runs the project's node_modules/.bin/depcruise from git rev-parse --show-toplevel, so sarathi gains no dependency; it refuses when the binary is missing.
  • Config comes from --config or where.config in .claude/sarathi.json; without either it refuses rather than fall back to the project's default config, which would look right while dropping every edge into a package's source.
  • Exit 0 is an answer, exit 2 a usage error, exit 1 a failure with the reason on stderr, so callers reading non-zero as "the graph failed" keep working; sarathi check validates the new where key.
  • Version bumps to 0.8.9; projects add the where key only once every checkout runs 0.8.9 or later, since older releases refuse unknown top-level keys.