Skip to content

Refactor: Extract agent detection and add workspace support - #1

Merged
hunghg255 merged 3 commits into
mainfrom
claude/gallant-ritchie-rcq6tx
Sep 28, 2026
Merged

hunghg255 merged 3 commits into
mainfrom
claude/gallant-ritchie-rcq6tx

Conversation

@hunghg255

Copy link
Copy Markdown
Owner

Summary

This PR significantly refactors the codebase to improve maintainability and add new features. The main changes include extracting package manager detection logic into a dedicated agents module, adding monorepo/workspace support, and introducing new CLI commands (nlx for package execution and nci for clean installs).

Key Changes

  • New agents.ts module: Centralized package manager detection and command building

    • Supports npm, yarn, pnpm, bun, and upm
    • Detects from packageManager field in package.json (takes priority), then lockfiles
    • Walks up directory tree to find workspace root
    • Provides getCommand() to build commands for different operations (run, install, add, remove, execute, frozen)
    • Handles npm-specific -- separator for passing flags to scripts
  • New workspaces.ts module: Monorepo/workspace support

    • Reads pnpm-workspace.yaml and package.json workspaces configurations
    • Supports glob patterns (dir, dir/*, dir/**)
    • Finds workspace root by walking up from current directory
    • Lists all workspace packages with metadata
  • Enhanced nr command:

    • Added -w/--workspace flag to select and run scripts in workspace packages
    • Added - flag to rerun the last script of the current project
    • Improved script filtering with autocomplete (search by name or description)
    • Per-project script history (stored by directory)
  • New nlx command: Execute packages without installing (npx/pnpm dlx/bunx/upx)

  • New nci command: Clean install for CI environments (npm ci/pnpm install --frozen-lockfile/etc)

  • Simplified ni and nu commands: Now use centralized agent detection and command building

  • Updated dependencies: Switched from unprompts to @clack/prompts for better UX

  • Improved storage: Changed from single lastRunCommand to lastRunCommands keyed by project directory

  • Added comprehensive tests: Test coverage for agent detection, command building, and workspace resolution

Notable Implementation Details

  • Agent detection prioritizes packageManager field over lockfiles for explicit configuration
  • Workspace package selection uses autocomplete with filtering by package name or path
  • Storage is now per-project to support monorepos with different last-run scripts
  • Atomic file writes prevent corruption during concurrent access
  • Proper error handling for missing binaries and exit codes

https://claude.ai/code/session_01VYGczmXF4CDqqMFj25NM5e

@hunghg255
hunghg255 merged commit 627616f into main Sep 28, 2026
1 check passed
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.

2 participants