Skip to content

feat(workspace): create a Space from a node's directory - #757

Open
MtWay wants to merge 1 commit into
DeadWaveWave:mainfrom
MtWay:feat/space-from-node-directory
Open

MtWay wants to merge 1 commit into
DeadWaveWave:mainfrom
MtWay:feat/space-from-node-directory

Conversation

@MtWay

@MtWay MtWay commented Nov 24, 2026 •

Copy link
Copy Markdown

💡 Change Scope

  • Small Change: Fast feedback, localized UI/logic, low-risk.
  • Large Change: New feature, cross-boundary logic, runtime-risk (persistence, IPC, lifecycle, recovery).

📝 What Does This PR Do?

Adds a selection context-menu action on folder nodes — "Create Space from This Directory" — that creates a top-level Space bound to the folder's directory, resolving the containing project mount. The item is hidden for document nodes and for nodes a Space already owns (creating inside a Space makes a child Space, which the position-sensitive Create Space expresses).

Reuses existing logic instead of parallel copies:

  • mount picking → exported resolveBestMount (domain normalisation handles Windows case and macOS /private), reached through the canvas spaceMountLaunchContext facade
  • mount query → listProjectMounts
  • node path → getFilesystemNodeUri, the menu's existing resolver
  • folder / in-Space eligibility → useFilesystemNodePaths, exposed via FilesystemNodesContext

🏗️ Large Change Spec (Required if "Large Change" is checked)

1. Context & Business Logic

A folder node carries a directory URI. This adds a shortcut to create a top-level Space bound to that directory and its containing mount. It applies to folder nodes only and is hidden once a Space owns the node. If the folder has no usable directory, or the directory falls outside every mount, a warning is shown and nothing is written.

2. State Ownership & Invariants

  • Owner: the Space record in the workspace document, written by the existing createSpace. Mount topology truth stays with Main/Worker and is read only through the side-effect-free mount.list query. No new durable state or persistence schema.
  • Invariants:
    1. Applies only to folder nodes that no Space owns yet.
    2. Writes a Space only when the directory resolves inside an existing project mount; otherwise it warns and writes nothing, never falling back to a local location.
    3. A project switch or unmount while mount.list resolves writes nothing (lifetime.active, like blank-canvas create).

3. Verification Plan & Regression Layer

Hook tests on useWorkspaceCanvasCreateSpace (tests/unit/contexts/useSpaces.createSpaceFromNodeDirectory.spec.tsx): mount hit writes mountId + directory; outside every mount → warning + no write; unmount during the query → no write; in-Space node → no write; document node → no write. No new E2E — the invariant does not need a real Desktop boundary (DEVELOPMENT.md). docs/canvas/SPACE_LIFECYCLE_SPEC.md updated in the same change.


🔗 Co-change partners left untouched

  • src/contexts/workspace/presentation/renderer/components/workspaceCanvas/types.ts (with src/contexts/workspace/presentation/renderer/components/workspaceCanvas/WorkspaceCanvasView.types.ts, 9/14): The new createSpaceFromNodeDirectory prop is a callback on the view-props interface only; it reuses existing types (nodeId: string) and introduces no new shared domain/node-data type, so types.ts needs no change (tsc passes without it).

✅ Delivery & Compliance Checklist

  • The local quick gate passes: pnpm verify:quick / pnpm pre-commit is green; any additional focused tests are reported above.
  • Full CI passes on the final revision before merge; local quick checks are not reported as full regression.
  • I have signed the CLA if required (see CLA.md).
  • I have locked down the behavior with the strongest asset that fits, in this order: type or structure, mechanical check, runtime assertion, scenario test (or explicitly stated why none applies).
  • I have strictly adhered to the DEVELOPMENT.md architectural boundaries.
  • I have attached a screenshot or screen recording (if this touches the UI).
  • I have updated the documentation accordingly (if adding a feature or changing a contract).

📸 Screenshots / Visual Evidence

7f39ffc5-0dd3-42f6-a2e6-827629aae941 fa29f0c8-2e74-4b0f-9300-3b9dd263fda2

@CLAassistant

CLAassistant commented Nov 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@MtWay
MtWay force-pushed the feat/space-from-node-directory branch from 119ec59 to 0619fcc Compare November 24, 2026 10:14

@DeadWaveWave DeadWaveWave left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MtWay, and welcome. Binding a Space to a folder you've dropped onto the canvas is a good shortcut, and we want it. I approved the CI run, so you'll see results on this revision soon. Before it can merge, these need to change:

Behaviour

  1. Folder nodes only. Right now the item also appears on document nodes and quietly uses the file's parent folder, which "Create Space from This Directory" doesn't say. Please show it only for folder nodes. That is also what your description and E2E cover.
  2. Follow the existing Space rules when the folder is already inside a Space. createSpace takes the node out of its Space and puts a new top-level Space on top of the old parent. docs/canvas/SPACE_LIFECYCLE_SPEC.md says that creating inside a Space makes a child Space, and createSpaceFromSelectedNodes already decides this through resolveSelectedChildSpaceParent. Either go through that same decision and only override the directory (for a child Space, the directory must be inside the parent's scope; otherwise warn and write nothing), or, simpler, hide the item for nodes that already belong to a Space. Write whichever you pick into the spec.
  3. Nothing written after the canvas has moved on. After mount.list resolves, check the canvas lifetime the way useCreateEmptySpace does (lifetime.active). That way a project switch or unmount during the query writes nothing. The spec already promises this for blank-canvas create, and the new path should keep that promise.

Reuse, no parallel copies (DEVELOPMENT.md, "优先复用")

  1. Mount picking: resolveBestMount in src/contexts/space/application/resolveSpaceMountContext.ts already picks the mount with the longest root that contains the path. It uses the domain normalisation in spaceBoundaryPolicy.ts, which also handles macOS /private aliases and Windows case. Export it (or a small named wrapper) and drop pickMountForDirectory. Then the normalizeComparablePath(…, platform) change in the view helper can be reverted.
  2. Mount query: use listProjectMounts in hooks/spaceMountLaunchContext.ts and drop workspaceMountApi.ts.
  3. Node path: this menu already gets the path from getNodePathUri (useFilesystemNodePaths) to decide hasPath. Use the same resolver instead of re-reading data.folder / data.document.

Tests

  1. These invariants can be shown in a hook test on useWorkspaceCanvasCreateSpace, in the style of the existing createSpace tests: mount found → the Space is written with mountId and the directory; outside every mount → a warning and no write; switch during the query → no write; node inside a Space → whatever you chose in point 2. DEVELOPMENT.md adds a new E2E only when the invariant needs a real Desktop boundary, so I'd drop it. If you keep it, run pnpm e2e:budget:update --reason "Desktop: …": without the budget entry, CI fails. Also, the description mentions "Windows ConPTY E2E coverage", but the spec opens no terminal; please correct that.

PR description

  1. This is a Large Change. Please tick it and fill in the spec: the state owner (the Space record in the workspace document, written by createSpace), the 1–3 invariants (your new invariant 7 is a good start), and the verification. Add the ## 🔗 Co-change partners left untouched section from pnpm impact --base origin/main --pr-section. The pr-template check fails without it.

Happy to look again as soon as you push.

@DeadWaveWave

Copy link
Copy Markdown
Owner

CI finished on this revision. Only the two failures from my review: E2E case budget (point 7) and pr-template (point 8). Everything else passed, including the Ubuntu E2E shards, Windows and macOS. CI runs on your next push need my approval until your first PR is merged; I'll approve them when I see them.

@MtWay
MtWay force-pushed the feat/space-from-node-directory branch from 0619fcc to 3a2b57d Compare November 27, 2026 02:27
@MtWay

MtWay commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

Thanks for the detailed review — all eight points are addressed in the latest push.

Behaviour

  1. Folder nodes only. The item now renders only for folder nodes; document nodes no longer show it and no longer fall back to the file's parent folder. Both the menu and the handler guard on folder kind.
  2. Node already inside a Space. Took the simpler option you suggested: the item is hidden for any node a Space already owns, so the top-level shortcut never competes with the child-Space path. Written into SPACE_LIFECYCLE_SPEC.md (creation entry + invariant 7).
  3. Lifetime. After mount.list resolves, the handler checks lifetime.active exactly like useCreateEmptySpace; a project switch or unmount during the query writes nothing.

Reuse, no parallel copies

  1. Mount picking uses the exported resolveBestMount (domain normalisation in spaceBoundaryPolicy — Windows case + macOS /private). pickMountForDirectory is gone, and the normalizeComparablePath(…, platform) view-helper change is reverted.
  2. Mount query uses listProjectMounts; workspaceMountApi.ts is deleted.
  3. Node path uses getFilesystemNodeUri, the menu's existing resolver. Folder / in-Space eligibility lives in useFilesystemNodePaths and reaches the menu through FilesystemNodesContext, so the menu does not read the store directly.

To keep the architecture ratchet green without suppressions: the folder-kind test is an exit guard, and resolveBestMount reaches the canvas through the spaceMountLaunchContext facade (no new cross-context deep import).

Tests

  1. Dropped the E2E and the pure-function unit spec. Added hook tests on useWorkspaceCanvasCreateSpace (tests/unit/contexts/useSpaces.createSpaceFromNodeDirectory.spec.tsx): mount hit writes mountId + directory; outside every mount → warning + no write; unmount during the query → no write; in-Space node → no write; document node → no write. No new E2E, since the invariant does not need a real Desktop boundary. Corrected the "Windows ConPTY E2E" wording in the description.

PR description

  1. Ticked Large Change and filled the spec: state owner (the Space record in the workspace document, written by createSpace), three invariants, and the verification layer. Added the ## 🔗 Co-change partners left untouched section from pnpm impact --base origin/main --pr-section.

Verification: tsc, oxlint, arch:check (0 errors), line/naming, prettier and the affected unit suites are green locally. The full local suite has pre-existing, environment-dependent failures (CLI / PTY / platform / script tests) that also fail on a clean origin/main checkout — unrelated to this change.

Happy to switch point 2 to routing through resolveSelectedChildSpaceParent (child Space with the directory overridden) instead of hiding, if you'd prefer that behaviour.

Add a context-menu action on filesystem nodes that creates a top-level Space
bound to the right-clicked node's directory, resolving the matching project
mount via the mount.list query.

- spaceDirectoryFromNode: resolve a node's directory and pick its mount
- workspaceMountApi: boundary for the canvas mount topology query
- wire createSpaceFromNodeDirectory through useSpaces, canvas view and menus
- normalizeComparablePath: optional platform param so it runs in node tests
- en/zh i18n, unit spec and Windows ConPTY E2E coverage

Co-Authored-By: Claude Code <noreply@anthropic.com>
@MtWay
MtWay force-pushed the feat/space-from-node-directory branch from 3a2b57d to 55af659 Compare November 27, 2026 03:10
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.

3 participants