Repository navigation
feat(workspace): create a Space from a node's directory - #757
Conversation
119ec59 to
0619fcc
Compare
DeadWaveWave
left a comment
There was a problem hiding this comment.
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
- 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.
- Follow the existing Space rules when the folder is already inside a Space.
createSpacetakes the node out of its Space and puts a new top-level Space on top of the old parent.docs/canvas/SPACE_LIFECYCLE_SPEC.mdsays that creating inside a Space makes a child Space, andcreateSpaceFromSelectedNodesalready decides this throughresolveSelectedChildSpaceParent. 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. - Nothing written after the canvas has moved on. After
mount.listresolves, check the canvas lifetime the wayuseCreateEmptySpacedoes (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, "优先复用")
- Mount picking:
resolveBestMountinsrc/contexts/space/application/resolveSpaceMountContext.tsalready picks the mount with the longest root that contains the path. It uses the domain normalisation inspaceBoundaryPolicy.ts, which also handles macOS/privatealiases and Windows case. Export it (or a small named wrapper) and droppickMountForDirectory. Then thenormalizeComparablePath(…, platform)change in the view helper can be reverted. - Mount query: use
listProjectMountsinhooks/spaceMountLaunchContext.tsand dropworkspaceMountApi.ts. - Node path: this menu already gets the path from
getNodePathUri(useFilesystemNodePaths) to decidehasPath. Use the same resolver instead of re-readingdata.folder/data.document.
Tests
- 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 withmountIdand 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, runpnpm 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
- 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 untouchedsection frompnpm impact --base origin/main --pr-section. Thepr-templatecheck fails without it.
Happy to look again as soon as you push.
|
CI finished on this revision. Only the two failures from my review: |
0619fcc to
3a2b57d
Compare
|
Thanks for the detailed review — all eight points are addressed in the latest push. Behaviour
Reuse, no parallel copies
To keep the architecture ratchet green without suppressions: the folder-kind test is an exit guard, and Tests
PR description
Verification: Happy to switch point 2 to routing through |
3a2b57d to
55af659
Compare
DeadWaveWave
left a comment
There was a problem hiding this comment.
Thanks @MtWay, this is a thorough revision. I checked all eight points against the diff and they hold:
- The item is limited to folder nodes and hidden once a Space owns the node, in both the menu and the handler.
- The handler checks
lifetime.activeaftermount.list. - It uses
resolveBestMount,listProjectMountsandgetFilesystemNodeUri, and the parallel copies are gone. - The E2E is replaced by hook tests.
- The description has the spec and the co-change section.
pr-template is green now. I approved the CI run on 55af659 and it is still running.
The drive-root fix in normalizeComparablePath is a good catch. Before it, isPathInsideOrEqual('D:\\', 'D:\\work') was false for every caller, not only this one.
One thing is left: the gap while mount.list is pending.
1. Re-check the node after the await. createSpaceFromNodeDirectory does three things before await listProjectMounts(...): it reads the node, decides whether the node is eligible, and resolves directoryPath. It hands those results to createSpace afterwards. createSpace reads the document again, but it does not enforce invariant 1: it takes the node out of any Space that owns it and makes a new top-level Space. So a change that happens during the wait gets overwritten. I added two hook tests to your spec locally and both fail on 55af659:
- Clicking the item twice before
mount.listanswers. The menu stays open untilcreateSpacecloses it, so a second click is possible. Both calls pass the check before the await. The secondcreateSpacethen takes the folder out of the Space the first call just made. Store result:[[], ['folder-1']], which is an empty Space plus a second Space holding the folder. - The folder is moved into an existing Space while
mount.listis pending. The test does this withnodeStore.updateCanvasDocument. Result: that Space is emptied and a new top-level Space takes the folder.
A folder that navigates during the wait has the same problem: updateFolder changes folder.uri, so the Space would bind the old directory.
Fix: after the lifetime.active check, read the document again and run the same decision on the current node: it is a folder, no Space owns it, and its directory comes from getFilesystemNodeUri. If any of that no longer holds, write nothing.
To keep that decision in one place, extract it as a pure function over { nodes, spaces } and nodeId that returns the directory path or null. Call it from three places: isTopLevelSpaceDirectoryCandidate for the menu, before the await for the early "no directory" warning, and after the await. Right now the kind and owner checks are written twice, in useFilesystemNodePaths.ts and in the handler.
2. Close the context menu on click, before the query. copyPath and blank-canvas create (createSpaceFromContextMenu) already do this. It removes the second click from the UI, but the re-check in point 1 is still what keeps the invariant.
3. Tests. Add both cases above to useSpaces.createSpaceFromNodeDirectory.spec.tsx:
- (a) Two calls before
mount.listresolves leave exactly one Space, and it owns the folder. - (b) When the folder is moved into a Space while the query is pending, that Space still owns it and no new Space is written.
One trap: the spec mocks t as key => key, which ignores count. As soon as a test creates a second Space, resolveDefaultSpaceName loops forever, because every candidate name is the same string. Case (a) hangs until the mock interpolates the count, e.g. (key, options) => options?.count === undefined ? key : \${key}-${options.count}`. For (b), have useSpacesUnderTestalso returnnodeStore` so the test can write the move.
Nothing else is needed. Once these land and CI is green I'll merge. If you'd rather I make this change myself, say so and I'll push it to your branch.
|
CI finished green on 55af659: every job passed, including the Ubuntu E2E shards, Windows and macOS. The three points in my review are all that's left. I'll approve the CI run on your next push once I've read the diff. |
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>
55af659 to
d746d95
Compare
|
Thanks — the pending- 1. Re-check after the await, one decision function. Extracted
The duplicated kind/owner checks in the handler are gone. 2. Menu closes on click. 3. Tests. Added both cases to
Fixed the
|
DeadWaveWave
left a comment
There was a problem hiding this comment.
The three points are addressed in d746d95. Checked: the kind/owner/directory decision is one pure function (resolveTopLevelSpaceDirectoryFromNode) used by the menu, before the query and again on the current document after it; the menu closes on click; with the post-query re-check removed locally, both new hook tests fail. CI is green on this revision.
|
Merged as 67412e7, thanks @MtWay, and welcome. Checked: the item shows only for folder nodes that no Space owns; the Space binds the mount from |
💡 Change Scope
📝 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 Spaceexpresses).Reuses existing logic instead of parallel copies:
resolveBestMount(domain normalisation handles Windows case and macOS/private), reached through the canvasspaceMountLaunchContextfacadelistProjectMountsgetFilesystemNodeUri, the menu's existing resolveruseFilesystemNodePaths, exposed viaFilesystemNodesContext🏗️ 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
createSpace. Mount topology truth stays with Main/Worker and is read only through the side-effect-freemount.listquery. No new durable state or persistence schema.mount.listresolves 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 writesmountId+ 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.mdupdated in the same change.🔗 Co-change partners left untouched
src/contexts/workspace/presentation/renderer/components/workspaceCanvas/types.ts(withsrc/contexts/workspace/presentation/renderer/components/workspaceCanvas/WorkspaceCanvasView.types.ts, 9/14): The newcreateSpaceFromNodeDirectoryprop is a callback on the view-props interface only; it reuses existing types (nodeId: string) and introduces no new shared domain/node-data type, sotypes.tsneeds no change (tsc passes without it).✅ Delivery & Compliance Checklist
pnpm verify:quick/pnpm pre-commitis green; any additional focused tests are reported above.CLA.md).DEVELOPMENT.mdarchitectural boundaries.📸 Screenshots / Visual Evidence