Skip to content

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.

feat(clone): CloneRepoDialog with shorthand preview, progress bar and abort

enes1081a39057da
diff --git a/src/renderer/components/CloneRepoDialog.tsx b/src/renderer/components/CloneRepoDialog.tsx
new file mode 100644
index 000000000..829db9bb8
--- /dev/null
+++ b/src/renderer/components/CloneRepoDialog.tsx
@@ -0,0 +1,166 @@
+import { useEffect, useRef, useState } from 'react'
+import { createPortal } from 'react-dom'
+import {
+ expandCloneUrl,
+ isValidCloneUrl,
+ deriveRepoDirName,
+ type CloneProgress
+} from '@shared/clone-url'
+
+const PARENT_KEY = 'nodeterm.cloneParent'
+
+interface CloneRepoDialogProps {
+ open: boolean
+ onClose: () => void
+ /** Called with the cloned absolute path + repo name; the caller opens the project. */
+ onCloned: (path: string, name: string) => void
+}
+
+/**
+ * REF-style clone dialog: URL (with owner/repo GitHub shorthand preview) + parent
+ * folder (native picker, last-used remembered) + live progress + inline error.
+ * Cancel — or closing the dialog — aborts the in-flight clone; main cleans up the
+ * half-cloned directory it claimed.
+ */
+export function CloneRepoDialog({ open, onClose, onCloned }: CloneRepoDialogProps) {
+ const [url, setUrl] = useState('')
+ const [parent, setParent] = useState('')
+ const [cloning, setCloning] = useState(false)
+ const [progress, setProgress] = useState<CloneProgress | null>(null)
+ const [error, setError] = useState('')
+ const urlRef = useRef<HTMLInputElement>(null)
+ const cloningRef = useRef(false)
+
+ const expanded = expandCloneUrl(url)
+ const showPreview = url.trim() !== '' && expanded !== url.trim()
+ const canClone = !cloning && parent.trim() !== '' && isValidCloneUrl(expanded)
+
+ // Seed the parent dir once per open: last-used, else the main-suggested default.
+ useEffect(() => {
+ if (!open) return
+ setError('')
+ setProgress(null)
+ urlRef.current?.focus()
+ const remembered = localStorage.getItem(PARENT_KEY)
+ if (remembered) setParent(remembered)
+ else void window.nodeTerminal.git.cloneDefaultParent().then((p) => setParent((cur) => cur || p))
+ }, [open])
+
+ // Progress stream — subscribed only while the dialog is open.
+ useEffect(() => {
+ if (!open) return
+ return window.nodeTerminal.git.onCloneProgress(setProgress)
+ }, [open])
+
+ // Unmount/close while cloning = abort (main deletes the claimed dir).
+ useEffect(() => {
+ cloningRef.current = cloning
+ }, [cloning])
+ useEffect(() => {
+ if (open) return
+ if (cloningRef.current) void window.nodeTerminal.git.cloneAbort()
+ }, [open])
+
+ if (!open) return null
+
+ const startClone = async (): Promise<void> => {
+ if (!canClone) return
+ setCloning(true)
+ setError('')
+ setProgress(null)
+ const r = await window.nodeTerminal.git.clone(parent.trim(), expanded)
+ setCloning(false)
+ if (!r.ok) {
+ // Abort resolves message:'aborted' — the dialog is already closing; stay silent.
+ if (r.message !== 'aborted') setError(r.message)
+ return
+ }
+ localStorage.setItem(PARENT_KEY, parent.trim())
+ const name = deriveRepoDirName(expanded) ?? 'repo'
+ setUrl('')
+ onCloned(r.message, name)
+ onClose()
+ }
+
+ const cancel = (): void => {
+ if (cloning) void window.nodeTerminal.git.cloneAbort()
+ onClose()
+ }
+
+ const onKeyDown = (e: React.KeyboardEvent): void => {
+ if (e.key === 'Enter') {
+ e.preventDefault()
+ void startClone()
+ } else if (e.key === 'Escape') {
+ e.preventDefault()
+ cancel()
+ }
+ }
+
+ return createPortal(
+ <div className="confirm-overlay" onClick={cancel}>
+ <div className="confirm clone-dialog" onClick={(e) => e.stopPropagation()}>
+ <p className="confirm__msg">Clone repository</p>
+ <label className="clone-dialog__label">Repository URL</label>
+ <input
+ ref={urlRef}
+ className="confirm__input"
+ value={url}
+ placeholder="https://github.com/user/repo.git — or user/repo"
+ spellCheck={false}
+ disabled={cloning}
+ onChange={(e) => setUrl(e.target.value)}
+ onKeyDown={onKeyDown}
+ />
+ {showPreview && <div className="clone-dialog__preview">→ {expanded}</div>}
+ <label className="clone-dialog__label">Parent folder</label>
+ <div className="clone-dialog__row">
+ <input
+ className="confirm__input"
+ value={parent}
+ placeholder="/path/to/projects"
+ spellCheck={false}
+ disabled={cloning}
+ onChange={(e) => setParent(e.target.value)}
+ onKeyDown={onKeyDown}
+ />
+ <button
+ className="confirm__btn"
+ title="Choose folder"
+ disabled={cloning}
+ onClick={() => {
+ void window.nodeTerminal.dialog.selectFolder().then((f) => {
+ if (f) setParent(f)
+ })
+ }}
+ >
+ 📁
+ </button>
+ </div>
+ {error && <div className="clone-dialog__error">{error}</div>}
+ {cloning && (
+ <div className="clone-dialog__progress">
+ <div className="clone-dialog__progress-label">
+ {progress ? `${progress.phase}… ${progress.percent}%` : 'Starting clone…'}
+ </div>
+ <div className="clone-dialog__progress-track">
+ <div
+ className="clone-dialog__progress-bar"
+ style={{ width: `${progress?.percent ?? 3}%` }}
+ />
+ </div>
+ </div>
+ )}
+ <div className="confirm__actions">
+ <button className="confirm__btn" onClick={cancel}>
+ Cancel
+ </button>
+ <button className="confirm__btn primary" disabled={!canClone} onClick={() => void startClone()}>
+ {cloning ? 'Cloning…' : 'Clone'}
+ </button>
+ </div>
+ </div>
+ </div>,
+ document.body
+ )
+}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index b18aa732c..f23a4e794 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -2860,6 +2860,59 @@ body,
cursor: not-allowed;
}
+/* ---- Clone repo dialog (reuses the .confirm shell) ---- */
+.clone-dialog {
+ width: 420px;
+}
+.clone-dialog__label {
+ display: block;
+ margin: 10px 2px 4px;
+ font-size: 11px;
+ color: rgba(255, 255, 255, 0.55);
+}
+.clone-dialog__row {
+ display: flex;
+ gap: 6px;
+ align-items: center;
+}
+.clone-dialog__row .confirm__input {
+ flex: 1;
+}
+.clone-dialog__preview {
+ margin: 4px 2px 0;
+ font-size: 11px;
+ color: rgba(255, 255, 255, 0.45);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.clone-dialog__error {
+ margin-top: 8px;
+ font-size: 11px;
+ color: #ff6b6b;
+ word-break: break-word;
+}
+.clone-dialog__progress {
+ margin-top: 10px;
+}
+.clone-dialog__progress-label {
+ font-size: 11px;
+ color: rgba(255, 255, 255, 0.55);
+ margin-bottom: 4px;
+}
+.clone-dialog__progress-track {
+ height: 4px;
+ border-radius: 2px;
+ background: rgba(255, 255, 255, 0.12);
+ overflow: hidden;
+}
+.clone-dialog__progress-bar {
+ height: 100%;
+ border-radius: 2px;
+ background: var(--accent);
+ transition: width 200ms ease;
+}
+
/* ---- Notification consent dialog (polished, icon + title + actions) ---- */
.consent-overlay {
position: fixed;