Skip to content

fix(cli): inherit nearest bound Space from ancestor directories - #548

Open
atou42 wants to merge 1 commit into
netaart:mainfrom
atou42:feat/cli-subdir-space-binding
Open

atou42 wants to merge 1 commit into
netaart:mainfrom
atou42:feat/cli-subdir-space-binding

Conversation

@atou42

@atou42 atou42 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

When a local directory is bound to a Space via cohub runtime up, running Space-scoped CLI commands or cohub runtime status/down/logs/detach/import from a subdirectory of that repository currently misses the binding because getRuntimeSpaceBinding() only checks exact binding.root === cwd.

In particular, cohub prompt silently fell back to the user's personal Home Space when invoked from a subdirectory, while other commands exited with No target space.

Changes

  • packages/cli/src/runtime/space-binding.ts:
    • Keeps findRuntimeSpaceBinding() / getRuntimeSpaceBinding() exact-match so cohub runtime up continues binding the exact requested directory without hijacking a parent binding.
    • Adds findContainingRuntimeSpaceBinding() and findNearestRuntimeSpaceBinding(), walking ancestor directories via dirname (like Git):
      • Deepest (nested) binding wins over a parent binding.
      • Sibling prefix paths (e.g. /work/app-2) never falsely match /work/app.
      • Resolves symlinks to canonical roots first, preserving identity/environment scoping.
  • packages/cli/src/space.ts, packages/cli/src/runtime/launch.ts, packages/cli/src/commands/runtime.ts:
    • Switches resolveBoundSpace(), resolveRuntimeTarget(), and boundRuntime() to findNearestRuntimeSpaceBinding(), returning binding.root as the workspace root for runtime detach and runtime import.
  • packages/cli/tests/runtime-space-binding.test.ts:
    • Adds tests covering ancestor traversal, nested child overrides, sibling-prefix isolation, identity isolation, and symlinked subdirectories.

Verification

  • pnpm --filter @neta-art/cohub-cli typecheck & build — passed
  • pnpm exec biome check on all 5 touched files — 0 errors
  • node --import tsx --test packages/cli/tests/runtime-space-binding.test.ts packages/cli/tests/space.test.ts packages/cli/tests/desktop.test.ts — 24/24 passed

This branch has not been deployed

No deployments
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