Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(explorer,canvas): New File / New Folder via right-click (local + SSH)
enes398a716415e3
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex b5c262deb..216e30337 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -87,8 +87,10 @@ import { RemoteSessionView } from './RemoteSessionView'import { RemoteAccessDialog } from '../components/RemoteAccessDialog'import { SshProjectDialog } from '../components/SshProjectDialog'import { transport } from '../terminal/local-transport'+import { sshFs } from '../terminal/ssh-fs'import { prepareQuickOpenFiles, type QuickOpenIndexedFile } from '../lib/quickOpenSearch'import { opensInEditor } from '../lib/openTarget'+import { newEntryPath, parentDir } from '../lib/explorerCreate'import { useProjects } from '../state/projects'import { useAgentStatus } from '../state/agentStatus'import { useChatSessions } from '../state/chatSessions'@@ -1658,6 +1660,41 @@ export function Canvas() {[openFile])+ /** Create a new file under the project folder (relative name, subdirs auto-created) and+ * open it as an editor node. SSH projects create on the remote host. */+ const newProjectFile = useCallback(+ async (center?: { x: number; y: number }) => {+ const project = useProjects.getState().getProject(activeProjectId ?? '')+ const cwd = project?.ssh?.remoteCwd ?? project?.cwd+ if (!project || !cwd) return+ const name = await promptDialog({+ message: 'New file — name (relative to the project folder):',+ placeholder: 'src/notes.md',+ confirmLabel: 'Create'+ })+ if (name === null) return+ const dest = newEntryPath(cwd, name)+ if (!dest) {+ setCopyError(`Invalid name: “${name.trim()}”`)+ return+ }+ const fsApi = project.ssh ? sshFs(project.id) : window.nodeTerminal.fs+ if (await fsApi.exists(dest)) {+ setCopyError(`Already exists: ${dest}`)+ return+ }+ const ok =+ (name.includes('/') ? await fsApi.mkdir(parentDir(dest)) : true) &&+ (await fsApi.write(dest, ''))+ if (!ok) {+ setCopyError(`Could not create ${dest}`)+ return+ }+ openFile(dest, center, !!project.ssh)+ },+ [activeProjectId, openFile]+ )+/** Open the clone dialog; project creation happens in onRepoCloned below. */const cloneRepo = useCallback(() => setCloneDialogOpen(true), [])@@ -2705,6 +2742,7 @@ export function Canvas() {{ label: 'New sticky note', icon: <IconNote />, onClick: () => addSticky(at) },{ label: 'New dino game', icon: <IconDino />, onClick: () => addDino(at) },{ label: 'Open file…', icon: <IconEditor />, onClick: () => void openFileDialog(at) },+ { label: 'New file…', icon: <IconEditor />, onClick: () => void newProjectFile(at) },{ type: 'separator' },// Canvas actions.{ label: 'Select all', icon: <IconSelectAll />, onClick: selectAll },@@ -2720,6 +2758,7 @@ export function Canvas() {addDino,addBrowser,openFileDialog,+ newProjectFile,openRemotePicker,selectAll,fitView@@ -3969,6 +4008,7 @@ export function Canvas() {{ id: 'new-sticky', label: 'New sticky note', icon: <IconNote />, run: () => addSticky() },{ id: 'new-dino', label: 'New dino game', icon: <IconDino />, run: () => addDino() },{ id: 'open-file', label: 'Open file…', icon: <IconEditor />, run: () => void openFileDialog() },+ { id: 'new-file', label: 'New file…', icon: <IconEditor />, run: () => void newProjectFile() },{ id: 'open-web', label: 'Open web view…', icon: <IconRemote />, run: () => addWebView() },{ id: 'open-browser', label: 'New browser', icon: <IconRemote />, run: () => addBrowser() },...useSshServers.getState().servers.map(@@ -4050,6 +4090,7 @@ export function Canvas() {addWebView,addBrowser,openFileDialog,+ newProjectFile,addProject,fitView,persist,diff --git a/src/renderer/components/ExplorerPanel.tsx b/src/renderer/components/ExplorerPanel.tsxindex 4658f8276..19947d7a7 100644--- a/src/renderer/components/ExplorerPanel.tsx+++ b/src/renderer/components/ExplorerPanel.tsx@@ -4,6 +4,8 @@ import type { DirEntry, FsApi } from '@shared/types'import { useProjects } from '../state/projects'import { useExplorer } from '../state/explorer'import { sshFs } from '../terminal/ssh-fs'+import { promptDialog } from './promptDialog'+import { ancestorDirs, createTargetDir, newEntryPath, parentDir } from '../lib/explorerCreate'interface ExplorerPanelProps {onClose: () => void@@ -19,6 +21,11 @@ type ContextFn = (x: number, y: number, path: string, isDir: boolean) => voidtype OpenFn = (path: string) => voidtype SelectFn = (path: string) => void+// Surface a transient error message (matches the Canvas listener at Canvas.tsx:380).+const toast = (message: string): void => {+ window.dispatchEvent(new CustomEvent('nodeterm:toast', { detail: { kind: 'error', message } }))+}+function EntryIcon({ dir }: { dir: boolean }) {return dir ? (<svg className="ex-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6">@@ -156,7 +163,7 @@ export function ExplorerPanel({ onClose, onOpenFile, reveal }: ExplorerPanelPropconst [roots, setRoots] = useState<DirEntry[] | null>(null)const [version, setVersion] = useState(0)const [selected, setSelected] = useState<string | null>(null)- const [menu, setMenu] = useState<{ x: number; y: number; path: string } | null>(null)+ const [menu, setMenu] = useState<{ x: number; y: number; path: string; dir: boolean } | null>(null)useEffect(() => {if (cwd) fs.list(cwd).then(setRoots)@@ -186,7 +193,47 @@ export function ExplorerPanel({ onClose, onOpenFile, reveal }: ExplorerPanelProp// eslint-disable-next-line react-hooks/exhaustive-deps}, [reveal?.nonce, cwd])- const onContext: ContextFn = (x, y, path) => setMenu({ x, y, path })+ const onContext: ContextFn = (x, y, path, isDir) => setMenu({ x, y, path, dir: isDir })++ // Create a file or folder under the clicked entry (a dir targets itself, a file its+ // parent). Multi-segment names create intermediate dirs. Never overwrites: an existing+ // path is surfaced as a toast and the prompt is abandoned.+ const createEntry = useCallback(+ async (targetPath: string, targetIsDir: boolean, kind: 'file' | 'folder') => {+ const baseDir = createTargetDir(targetPath, targetIsDir)+ const name = await promptDialog({+ message: kind === 'file' ? 'New file name:' : 'New folder name:',+ placeholder: kind === 'file' ? 'notes.md (subdirs ok: docs/notes.md)' : 'folder name',+ confirmLabel: 'Create'+ })+ if (name === null) return+ const dest = newEntryPath(baseDir, name)+ if (!dest) {+ toast(`Invalid name: “${name.trim()}”`)+ return+ }+ if (await fs.exists(dest)) {+ toast(`Already exists: ${dest}`)+ return+ }+ const ok =+ kind === 'folder'+ ? await fs.mkdir(dest)+ : (name.includes('/') ? await fs.mkdir(parentDir(dest)) : true) && (await fs.write(dest, ''))+ if (!ok) {+ toast(`Could not create ${dest}`)+ return+ }+ // Keep the target (and any new intermediate dirs) expanded, then re-list the tree.+ if (project) {+ const dirs = [baseDir, ...ancestorDirs(baseDir, name)].filter((d) => d !== cwd)+ useExplorer.getState().expandMany(project.id, dirs)+ }+ setVersion((v) => v + 1)+ if (kind === 'file') handleOpenFile(dest)+ },+ [fs, cwd, project, handleOpenFile]+ )return createPortal(<div className="drawer-overlay" onClick={onClose}>@@ -210,7 +257,14 @@ export function ExplorerPanel({ onClose, onOpenFile, reveal }: ExplorerPanelProp)}{cwd && (- <div className="drawer__body ex-body">+ <div+ className="drawer__body ex-body"+ onContextMenu={(e) => {+ if (e.target !== e.currentTarget || !cwd) return+ e.preventDefault()+ setMenu({ x: e.clientX, y: e.clientY, path: cwd, dir: true })+ }}+ >{roots?.length === 0 && <p className="set-note">Empty folder.</p>}{roots?.map((e) => (<TreeEntry@@ -235,6 +289,27 @@ export function ExplorerPanel({ onClose, onOpenFile, reveal }: ExplorerPanelProp<><div className="tab-backdrop" style={{ zIndex: 78 }} onClick={() => setMenu(null)} /><div className="ctx-menu" style={{ top: menu.y, left: menu.x, zIndex: 80 }}>+ <button+ className="ctx-item"+ onClick={() => {+ const m = menu+ setMenu(null)+ void createEntry(m.path, m.dir, 'file')+ }}+ >+ New File…+ </button>+ <button+ className="ctx-item"+ onClick={() => {+ const m = menu+ setMenu(null)+ void createEntry(m.path, m.dir, 'folder')+ }}+ >+ New Folder…+ </button>+ <div className="ctx-sep" /><buttonclassName="ctx-item"onClick={() => {diff --git a/src/renderer/lib/explorerCreate.test.ts b/src/renderer/lib/explorerCreate.test.tsnew file mode 100644index 000000000..44d0d085c--- /dev/null+++ b/src/renderer/lib/explorerCreate.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from 'vitest'+import { ancestorDirs, createTargetDir, newEntryPath, parentDir } from './explorerCreate'++describe('createTargetDir', () => {+ it('a dir targets itself, a file targets its parent', () => {+ expect(createTargetDir('/repo/src', true)).toBe('/repo/src')+ expect(createTargetDir('/repo/src/a.ts', false)).toBe('/repo/src')+ })+})++describe('parentDir', () => {+ it('strips the last segment', () => {+ expect(parentDir('/repo/src/a.ts')).toBe('/repo/src')+ expect(parentDir('/repo')).toBe('/')+ })+})++describe('newEntryPath', () => {+ it('joins simple and nested names', () => {+ expect(newEntryPath('/repo/src', 'notes.md')).toBe('/repo/src/notes.md')+ expect(newEntryPath('/repo/src/', 'a/b.ts')).toBe('/repo/src/a/b.ts')+ })+ it('rejects empty, absolute, traversal and trailing-slash names', () => {+ expect(newEntryPath('/repo', '')).toBeNull()+ expect(newEntryPath('/repo', ' ')).toBeNull()+ expect(newEntryPath('/repo', '/etc/passwd')).toBeNull()+ expect(newEntryPath('/repo', '../evil')).toBeNull()+ expect(newEntryPath('/repo', 'a/../../evil')).toBeNull()+ expect(newEntryPath('/repo', 'a/')).toBeNull()+ })+})++describe('ancestorDirs', () => {+ it('lists the intermediate dirs a nested name creates', () => {+ expect(ancestorDirs('/repo', 'a/b/c.ts')).toEqual(['/repo/a', '/repo/a/b'])+ expect(ancestorDirs('/repo', 'c.ts')).toEqual([])+ })+})diff --git a/src/renderer/lib/explorerCreate.ts b/src/renderer/lib/explorerCreate.tsnew file mode 100644index 000000000..57671cdd2--- /dev/null+++ b/src/renderer/lib/explorerCreate.ts@@ -0,0 +1,37 @@+// Pure path logic for Explorer/canvas "New File…" / "New Folder…" — kept out of the+// components so name validation and expansion targets are unit-testable. Paths are+// `/`-separated absolutes (remote SSH paths included); names come from a user prompt.++/** The directory a create targets: the clicked dir itself, or the clicked file's parent. */+export function createTargetDir(path: string, isDir: boolean): string {+ return isDir ? path : parentDir(path)+}++export function parentDir(p: string): string {+ const i = p.replace(/\/+$/, '').lastIndexOf('/')+ return i <= 0 ? '/' : p.slice(0, i)+}++/**+ * Join a user-entered name onto a base dir. Multi-segment relative names (`a/b.ts`) are+ * allowed — intermediate dirs are the caller's job (see `ancestorDirs`). Returns null for+ * anything unsafe or senseless: empty, absolute, `..` traversal, trailing slash.+ */+export function newEntryPath(baseDir: string, name: string): string | null {+ const n = name.trim()+ if (!n || n.startsWith('/') || n.endsWith('/')) return null+ if (n.split('/').some((seg) => !seg || seg === '..')) return null+ return `${baseDir.replace(/\/+$/, '')}/${n}`+}++/** Absolute paths of the intermediate dirs a nested name passes through (shallowest first). */+export function ancestorDirs(baseDir: string, name: string): string[] {+ const segs = name.trim().split('/').slice(0, -1)+ const out: string[] = []+ let acc = baseDir.replace(/\/+$/, '')+ for (const s of segs) {+ acc = `${acc}/${s}`+ out.push(acc)+ }+ return out+}