Skip to content

npm run cli reads the checkout's .loopway, not the directory you ran it from #508

Closed

Description

@mcwhittemore

Found while testing #502. Matthew saw no updates: under npm workspaces, npm run cli sets INIT_CWD to the checkout root, so projectDir in packages/cli/src/index.ts resolved the checkout's own .loopway, not the scratch project. #502 changed the docs to say "run node <checkout>/packages/cli/dist/index.js from your project". That works, but it's easy to get wrong.

What

  • loopway finds its project the way git finds a repo: it walks up from process.cwd() to the nearest directory holding a .loopway/ folder. No INIT_CWD fallback. --project <dir> overrides the search. If no .loopway/ is found, it exits with a message naming where it looked.
  • On startup, the log and the TUI header print the resolved project path, so a wrong project is obvious.
  • Give the checkout a dev entry point that works from anywhere, e.g. npm link -w @loopway/cli documented in docs/developing.md, so loopway on your PATH is your checkout's build. Remove or fix the root cli script so it can't silently read the wrong project.

How to test it (you, locally)

  1. npm run build && npm link -w @loopway/cli.
  2. cd into a scratch project that has .loopway/dev.md, or into a subdirectory of one, and run loopway --no-tui. The first line names that project's .loopway.
  3. cd /tmp && loopway: it exits saying no .loopway/ was found above /tmp.
  4. loopway --project <scratch> from anywhere uses that project.

Done when

  • Tests for the walk-up, --project and the not-found message.
  • npm test, npm run typecheck, npm run lint and npm run format:check pass.
  • verifications/<pr>.md records steps 1–4.

Activity

  1. mcwhittemore commented on Nov 11, 2026

    @mcwhittemore
    CollaboratorAuthor

    I don't get what No INIT_CWD fallback really means. Where is INIT_CWD coming from?

  2. mcwhittemore commented on Nov 11, 2026

    @mcwhittemore
    CollaboratorAuthor
    `INIT_CWD` is an environment variable that npm sets when you run `npm run <script>`: it holds the directory you ran npm from. Under npm workspaces, `npm run cli` from the checkout root ran the script with that root as `INIT_CWD`, and the old code used `process.env.INIT_CWD || process.cwd()` as the project, so it read the checkout's own `.loopway` instead of your scratch project. "No fallback" means loopway no longer reads that variable at all: the project comes only from `process.cwd()` walking up, or `--project`. PR #509 does that, and removes the root `cli` script.
  3. mcwhittemore commented on Nov 11, 2026

    @mcwhittemore
    CollaboratorAuthor

    I don't get how a walk up solves a problem here. I'm always running beside a .loopway directory. If we can't know that CWD why would a walk up find it?

  4. mcwhittemore commented on Nov 11, 2026

    @mcwhittemore
    CollaboratorAuthor
    You're right: the walk-up does not fix the #502 bug. That bug came from `npm run`: npm runs the script with its cwd at the checkout, not where you typed it, so `process.cwd()` was the wrong place too. That is why the old code reached for `INIT_CWD`, and why it read the checkout's `.loopway`. What fixes it in #509 is dropping that path: `loopway` on your PATH (`npm link -w @loopway/cli`) runs in your own cwd, and the root `cli` script is gone so nothing can silently run from the checkout.

    The walk-up is the other bullet in the issue. It only matters when you run from a subdirectory of a project. If you always run beside .loopway, it changes nothing for you, and --project covers running from elsewhere. If you would rather keep this to "cwd must hold .loopway", I can drop the walk-up and keep the rest. Say so and I will.

  5. mcwhittemore commented on Nov 11, 2026

    @mcwhittemore
    CollaboratorAuthor

    I think we can close this ticket for now. This is past where we are from a robustness POV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions