From 43466150e8090b527fca14bb3b658bbcbb23ef12 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 13:39:40 +0000 Subject: [PATCH 1/7] IDE: explorer file operations: cut, copy, paste, duplicate, reveal, open in terminal (#285) Workspace.copyEntry and moveEntry check both ends inside the folder by real path, refuse a folder pasted into itself, never overwrite (a copy over a taken name gets " copy" / " copy 2" before the extension) and cap a copy at 10,000 entries / 512 MB before writing anything. Reveal uses shell.showItemInFolder on the checked real path; a terminal opened on an entry gets its cwd resolved and checked in main. The explorer's context menu now covers files, folders and the top folder, with Rename and Delete, a renderer-side clipboard (cut rows dimmed, Ctrl/Cmd+C/X/V), and Refresh / Collapse All in the toolbar. A cut-and-paste move goes through entryMoved so open tabs follow. --- .claude/docs/V1.2.1_STATUS.md | 6 + apps/ide/README.md | 2 + apps/ide/src/main/ipc.ts | 11 +- apps/ide/src/main/terminal/terminalHost.ts | 7 +- apps/ide/src/main/workspace/workspace.ts | 206 ++++++++++++++++- apps/ide/src/preload/index.ts | 6 +- apps/ide/src/renderer/explorer.ts | 189 ++++++++++++++-- apps/ide/src/renderer/main.ts | 47 +++- apps/ide/src/renderer/styles.css | 2 + .../src/renderer/terminal/terminalPanel.ts | 8 +- apps/ide/src/shared/api.ts | 20 +- apps/ide/test/workspace.test.ts | 2 +- apps/ide/test/workspaceCopyMove.test.ts | 209 ++++++++++++++++++ 13 files changed, 680 insertions(+), 35 deletions(-) create mode 100644 apps/ide/test/workspaceCopyMove.test.ts diff --git a/.claude/docs/V1.2.1_STATUS.md b/.claude/docs/V1.2.1_STATUS.md index 45c8afeda..5ad741cce 100644 --- a/.claude/docs/V1.2.1_STATUS.md +++ b/.claude/docs/V1.2.1_STATUS.md @@ -654,6 +654,12 @@ Then pushed `v1.2.1` to `origin` at the maintainer's request. **No merge and no - The agent-first layout thread builds its chat tabs on the same seam. - Not done: password-protected PDFs, the outline/thumbnails sidebar, printing, CJK PDFs without embedded fonts (no CMaps bundled). +**#285 (IDE), epic #253 (classic gaps after #163): explorer file operations** [confirmed: unit tests (`workspaceCopyMove.test.ts`, 15 cases: copy and move of a file and of a folder, " copy" / " copy 2" / " copy 3" with the extension kept and a dotfile without one, a folder refused into itself and below itself, `..`, absolute paths and the root refused, a symlink leading out refused at either end, a link inside a copied folder kept when it stays in and left out when it leads out, the entry and size caps refusing before anything is written, a taken name refused on move, `revealablePath`/`terminalFolder` inside the folder only), `workspace.test.ts` still green after the root-refusal message changed, the IDE gate (`npm test`: typecheck, lint at `--max-warnings 0`, 683 tests, 0 failures), the smoke run under xvfb on Linux. Not driven by hand: the context menu, the keyboard shortcuts and the toolbar in the real window, Reveal and the terminal on Windows and macOS.] +- Main: `Workspace.copyEntry` / `moveEntry` (both ends by real path, never into itself, never overwriting; a copy is planned whole first and capped at 10,000 entries / 512 MB via `COPY_LIMITS`; a move across disks falls back to copy then remove), `revealablePath`, `terminalFolder`, and `freeCopyName`. IPC `codexr:workspace:copy-entry`, `move-entry`, `reveal-in-os` (`shell.showItemInFolder` on the checked real path); `terminal.create` takes an optional workspace path as its cwd, resolved by `terminalFolder` in main. The refusal of the root now says "renamed, moved, copied or deleted". +- Trust (#177): like create, rename and trash, copy and move work in Restricted Mode (they run nothing); Reveal and Open in Integrated Terminal follow "the terminal you open yourself", which also works either way. +- Renderer: the explorer's menu on files, folders and the tree's free space (Open, Reveal in File Explorer / Finder / File Manager by platform, Open in Integrated Terminal, Cut, Copy, Paste, Duplicate, Copy Path, Copy Relative Path, Rename, Delete, then the existing XR items for files); the clipboard lives in `explorer.ts` (a cut row gets `is-cut`, dimmed; it follows a rename and is dropped on trash); Ctrl/Cmd+C, X, V in the tree; toolbar Refresh Explorer and Collapse Folders in Explorer. A cut-and-paste move calls `onRenamed`, i.e. `editors.entryMoved`, so open tabs follow as they do a rename. +- Not done: drag and drop in the tree, multi-selection, the OS clipboard (copying files between the IDE and the file manager), undo of a paste, and a "replace?" prompt on a move over a taken name (refused instead). + **#176 (IDE), sixteenth PR of epic #163: tasks and Run Current File** [confirmed: unit tests (`tasks.test.ts`: package.json scripts and hooks, package manager by lock file, Makefile targets, `.codexr/tasks.json` with comments, matchers by command, interpreters by extension, PATH and PATHEXT lookup, quoting for bash/PowerShell/cmd, tsc and ESLint matchers, a command terminal's output and exit code), the smoke run (an untrusted folder lists its tasks as not trusted and refuses a run), Playwright on Linux: Run Task in Restricted Mode shows the explanation with Manage Workspace Trust; once trusted the picker lists the user task, `npm: hello` and `make: build`; each ran in its own tab with its exit code; the user task's tsc-shaped line reached the Problems panel; Run Current File ran `run me.py` (a space in the name) with python3]. `shared/tasks.ts` (pure), `main/tasks/taskHost.ts` + `problemMatchers.ts`, `TerminalService.createCommand` (the default profile's shell with `-c` or its equivalent, `shellInvocation` from the agents' command tool), `Workspace.runnableFile`, settings `run.pythonInterpreter` / `run.nodeInterpreter`, commands `workbench.action.tasks.runTask`, `workbench.action.tasks.configureTaskRunner`, `workbench.action.runCurrentFile` (`Ctrl/Cmd+F5`). Core: `ProblemOrigin` gains `task` (type only; the plugin never produces it). The user tasks file is `.codexr/tasks.json`, next to `.codexr/settings.json`, not the `.code-xr/` the issue wrote. Windows and macOS not run by hand: the quoting and PATHEXT paths are unit-tested and CI runs the gate on all three. Plugin: nothing to do, VS Code has tasks natively. **#177 (IDE), fifteenth PR of epic #163: workspace trust** [confirmed: unit tests (`trust.test.ts`: parent trusts children, a sibling with the same prefix is not, Restricted Mode inside a trusted parent, case rules per platform, bounded storage; the choices offered), the smoke run (new folder unknown, shield shown, Git `restricted`, then trusted and Git on), Playwright on Linux: the question on a new folder, the XR deep analysis ran to a scene while restricted, Trust Folder turned Git on and hid the shield, the answer survived a restart, Manage Workspace Trust from the palette restricted it again, "Trust every folder in ol" trusted it through the parent]. Main: `main/trust/trustModel.ts` (pure), `main/trust/workspaceTrust.ts` (decisions in `userData/workspace-trust.json`, in memory for the smoke run; `isWorkspaceTrusted(contents)` for #176), IPC `codexr:workspace:trust` / `set-trust` and event `trust-changed`. Gated: Git (`GitRepoState` `restricted`, status and every operation), the Python language server (pyright runs a project-configured interpreter); a trust change stops the window's language servers and the renderer re-sends its documents (`reopenLanguageDocuments`). Not gated: the IDE's own TypeScript server (no local tsserver plugins), the terminal, the analysis. Renderer: `trustView.ts` + `trustChoices.ts`, status-bar shield, command `workbench.trust.manage`. Acceptance "Run Task is disabled with an explanation" lands with #176, which does not exist yet; this PR provides the gate. Plugin: nothing to do, VS Code has Workspace Trust natively. diff --git a/apps/ide/README.md b/apps/ide/README.md index 7bfcac728..700108154 100644 --- a/apps/ide/README.md +++ b/apps/ide/README.md @@ -98,6 +98,8 @@ The renderer only reports the slot's bounds (`analysis.setSceneBounds`, sanitise **Editor tabs (#167).** A single click in the explorer opens a file in the *preview* tab (italic), which the next single click replaces; double-clicking the file or the tab, editing it, dragging it or **Keep Editor** (`Ctrl/Cmd+K Enter`) keeps it, and Enter in the explorer opens for keeps. Tabs drag to reorder, close with a middle click, cycle with `Ctrl+PageDown`/`Ctrl+PageUp` (or `Ctrl+Tab`/`Ctrl+Shift+Tab`), move with the arrow keys, Home and End when the strip has the focus, and scroll sideways with the wheel when they overflow. Right-click (or the context-menu key, `Shift+F10`) opens the tab menu: Close, Close Others, Close to the Right, Close Saved (`Ctrl/Cmd+K U`), Close All (`Ctrl/Cmd+K W`), Copy Path, Copy Relative Path (the main process checks the path and writes the clipboard; the renderer has no clipboard permission), Keep Open and Reveal in Explorer. A group close asks once, listing the unsaved tabs it would discard. The open tabs, their order, the preview, the active tab and each tab's view state (cursor, scroll, folding) are a session of the folder, saved in renderer storage under the folder's path and restored when it opens again; a file gone since is skipped (`editor/tabsModel.ts`, `contextMenu.ts`). +**Explorer operations (#285).** Right-click a file, a folder or the explorer's free space (the top folder) for: Open, **Reveal in File Explorer** / **Reveal in Finder** / **Reveal in File Manager** (by platform; `shell.showItemInFolder`), **Open in Integrated Terminal** (a new terminal in that folder, or in a file's folder), Cut, Copy, Paste, Duplicate, Copy Path, Copy Relative Path, Rename (F2) and Delete (to the OS trash). `Ctrl/Cmd+X`, `C` and `V` work while the tree has the focus. The clipboard is the explorer's own and names an entry, not its contents; a cut entry is dimmed until it is pasted. A paste over a taken name is named like VS Code's, `" copy"`, then `" copy 2"`..., before the extension (`a copy.ts`, `.env copy`); a cut-and-paste move over a taken name is refused, never overwritten, and its open tabs follow it as they follow a rename (`editors.entryMoved`). The toolbar adds **Refresh Explorer** and **Collapse Folders in Explorer**. The main process does the work (`Workspace.copyEntry`, `moveEntry`, `revealablePath`, `terminalFolder`): both ends are checked by real path inside the folder, a folder is never pasted into itself or below itself, and a copy is walked whole before anything is written and refused above 10,000 entries or 512 MB (`COPY_LIMITS`); a symlink inside a copied folder is copied as its target when that stays inside, and left out otherwise. The terminal's cwd is resolved in main from the workspace path, so the renderer never names a directory. Like create, rename and trash, these work in Restricted Mode (#177): they edit files and run nothing, and the terminal is one you open yourself. + **Split editor (#168).** **Split Editor Right** (`Ctrl/Cmd+\`, or Split Right in the tab menu) opens the file in a second editor group beside the first; `Ctrl/Cmd+1` and `Ctrl/Cmd+2` focus a group (the second is created on first use). Both groups share one Monaco model per file, so an edit in either shows in both and the file has a single dirty state; closing a file asks about unsaved changes only when its last tab goes. A tab dragged onto the other group's strip moves there with its view state. The sash between the groups drags (pointer or arrow keys) and resets on double-click; each group keeps at least 120 px, half the editor column's minimum, so the XR scene column keeps its width. The group that has the focus owns the breadcrumbs, the status bar and the commands. A group left without tabs closes. The second group, the split ratio and the focused group are part of the folder's tab session, so a restart restores them; a session saved before the split existed reads as one group (`editor/editorGroup.ts`, `editor/tabsModel.ts`). Not implemented: vertical splits and more than two groups. **Markdown preview (#179).** **Open Preview to the Side** (`Ctrl/Cmd+K V`, or the tab menu of a Markdown file) opens a pane to the right of the editor groups that renders the active Markdown file with GitHub-flavoured Markdown (headings, lists, task lists, tables, code blocks coloured by Monaco's own tokenizer, images). It re-renders as you type, follows the editor's scroll, takes over whichever Markdown file becomes active, and uses the workbench's colours, so it follows the theme. Its sash drags and resets on double-click like the split one. The preview is the only place in the renderer that inserts parsed markup, so it is fenced: DOMPurify sanitises everything (no script, no `