@hanzo/app 0.2.19 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Drive.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
- import { ArrowRight, ChevronDown, ChevronRight, Clock, Cloud, Download, File as FileIcon, FileArchive, FileAudio, FileCode, FileImage, FileText, FileVideo, Folder, FolderInput, FolderPlus, HardDrive, ListTree, MessageSquare, LayoutGrid, List, MoreHorizontal, PanelLeft, Plus, Search, Trash2, Upload, } from 'lucide-react';
4
+ import { ArrowRight, ChevronDown, ChevronRight, Clock, Cloud, Download, File as FileIcon, FileArchive, FileAudio, FileCode, FileImage, FilePlus, FileText, FileVideo, Folder, FolderGit2, FolderInput, FolderPlus, HardDrive, Laptop, ListTree, MessageSquare, LayoutGrid, List, MoreHorizontal, PanelLeft, Plus, Search, Trash2, Upload, } from 'lucide-react';
5
5
  import { Box, Button, Text, View, XStack, YStack } from '@hanzo/ui';
6
6
  import { useIam, useOrganizations } from '@hanzo/iam/react';
7
7
  import { useAi } from './lib/ai.js';
@@ -10,6 +10,8 @@ import { attach, channel } from './pane.js';
10
10
  import { useRooms } from './host.js';
11
11
  import { org } from './lib/session.js';
12
12
  import { Badge, Contents, Hits } from './Contents.js';
13
+ import { Editor } from './Editor.js';
14
+ import { cloneRemoteRepo, createLocalDir, createLocalFile, deleteLocalPath, getActiveWorkspace, getLocalWorkspaces, importLocalFile, listLocalEntries, pickLocalFile, pickLocalFolder, removeLocalWorkspace, setActiveWorkspace, subscribeLocalFs, } from './lib/local-fs.js';
13
15
  import { weigh as size } from './lib/attach.js';
14
16
  import { dropped, filesIn, forget, pool, register, search, settled, slug, upload, } from './lib/files.js';
15
17
  import { checkoutUrl } from './lib/pay.js';
@@ -141,6 +143,34 @@ export function Drive() {
141
143
  const [itemMenuKey, setItemMenuKey] = useState(null);
142
144
  const [naming, setNaming] = useState(null);
143
145
  const [projects, setProjects] = useState(null);
146
+ const [localWorkspaces, setLocalWorkspaces] = useState(getLocalWorkspaces);
147
+ const [activeWs, setActiveWs] = useState(getActiveWorkspace);
148
+ const [localEntries, setLocalEntries] = useState(null);
149
+ const [localPrefix, setLocalPrefix] = useState('');
150
+ const [editingFile, setEditingFile] = useState(null);
151
+ useEffect(() => {
152
+ return subscribeLocalFs(() => {
153
+ setLocalWorkspaces(getLocalWorkspaces());
154
+ setActiveWs(getActiveWorkspace());
155
+ });
156
+ }, []);
157
+ const loadLocalEntries = useCallback(() => {
158
+ if (!activeWs) {
159
+ setLocalEntries(null);
160
+ return;
161
+ }
162
+ const targetDir = localPrefix
163
+ ? `${activeWs.path}/${localPrefix}`.replace(/\/+/g, '/')
164
+ : activeWs.path;
165
+ listLocalEntries(targetDir)
166
+ .then((items) => setLocalEntries(items))
167
+ .catch((e) => setFailed(blame(e)));
168
+ }, [activeWs, localPrefix]);
169
+ useEffect(() => {
170
+ if (navSection === 'local') {
171
+ loadLocalEntries();
172
+ }
173
+ }, [navSection, loadLocalEntries, reload]);
144
174
  // What the drive actually holds, measured. There is no quota route, so there
145
175
  // is no quota drawn: a number nobody publishes would be a number invented.
146
176
  const [usage, setUsage] = useState(null);
@@ -352,11 +382,93 @@ export function Drive() {
352
382
  }, [client, activeBucket, prefix, run]);
353
383
  const handleCreateFolder = useCallback((folderName) => {
354
384
  const clean = folderName.trim().replace(/^\/+|\/+$/g, '');
355
- if (!clean || !client || !activeBucket)
385
+ if (!clean)
386
+ return;
387
+ if (navSection === 'local') {
388
+ if (!activeWs)
389
+ return;
390
+ const targetDir = localPrefix
391
+ ? `${activeWs.path}/${localPrefix}`.replace(/\/+/g, '/')
392
+ : activeWs.path;
393
+ createLocalDir(targetDir, clean)
394
+ .then(() => {
395
+ setNaming(null);
396
+ loadLocalEntries();
397
+ })
398
+ .catch((e) => setFailed(blame(e)));
399
+ return;
400
+ }
401
+ if (!client || !activeBucket)
356
402
  return;
357
403
  void run(`Creating ${clean}`, () => putBytes(client, activeBucket, `${prefix}${clean}/`, new Blob([])));
358
404
  setNaming(null);
359
- }, [client, activeBucket, prefix, run]);
405
+ }, [client, activeBucket, prefix, run, navSection, activeWs, localPrefix, loadLocalEntries]);
406
+ const handleCreateFile = useCallback((fileName) => {
407
+ const clean = fileName.trim().replace(/^\/+|\/+$/g, '');
408
+ if (!clean)
409
+ return;
410
+ if (navSection === 'local') {
411
+ if (!activeWs)
412
+ return;
413
+ const targetDir = localPrefix
414
+ ? `${activeWs.path}/${localPrefix}`.replace(/\/+/g, '/')
415
+ : activeWs.path;
416
+ createLocalFile(targetDir, clean)
417
+ .then((filePath) => {
418
+ setNaming(null);
419
+ loadLocalEntries();
420
+ setEditingFile({ path: filePath, name: clean });
421
+ })
422
+ .catch((e) => setFailed(blame(e)));
423
+ return;
424
+ }
425
+ if (!client || !activeBucket)
426
+ return;
427
+ void run(`Creating ${clean}`, () => putBytes(client, activeBucket, `${prefix}${clean}`, new Blob([''])));
428
+ setNaming(null);
429
+ }, [client, activeBucket, prefix, run, navSection, activeWs, localPrefix, loadLocalEntries]);
430
+ const handleCloneRepo = useCallback((repoUrl) => {
431
+ const clean = repoUrl.trim();
432
+ if (!clean)
433
+ return;
434
+ setNaming(null);
435
+ void run(`Cloning ${clean}`, async () => {
436
+ const ws = await cloneRemoteRepo(clean);
437
+ setNavSection('local');
438
+ setActiveWorkspace(ws);
439
+ setLocalPrefix('');
440
+ loadLocalEntries();
441
+ });
442
+ }, [run, loadLocalEntries]);
443
+ const handleOpenLocalFile = useCallback(async () => {
444
+ try {
445
+ const selected = await pickLocalFile();
446
+ if (selected) {
447
+ const fileName = selected.split(/[/\\]/).pop() || 'file';
448
+ setEditingFile({ path: selected, name: fileName });
449
+ }
450
+ }
451
+ catch (e) {
452
+ setFailed(blame(e));
453
+ }
454
+ }, []);
455
+ const handleImportLocalFile = useCallback(async () => {
456
+ if (!activeWs)
457
+ return;
458
+ try {
459
+ const selected = await pickLocalFile();
460
+ if (selected) {
461
+ const targetDir = localPrefix
462
+ ? `${activeWs.path}/${localPrefix}`.replace(/\/+/g, '/')
463
+ : activeWs.path;
464
+ await importLocalFile(selected, targetDir);
465
+ loadLocalEntries();
466
+ }
467
+ }
468
+ catch (e) {
469
+ setFailed(blame(e));
470
+ }
471
+ }, [activeWs, localPrefix, loadLocalEntries]);
360
472
  const handleRename = useCallback((entry, to) => {
361
473
  const clean = to.trim().replace(/^\/+|\/+$/g, '');
362
474
  if (!clean || !client || !activeBucket || entry.isDir)
@@ -489,20 +601,58 @@ export function Drive() {
489
601
  z: 'var(--z-drawer)',
490
602
  overflowY: 'auto',
491
603
  boxShadow: 'var(--shadow-lg)',
492
- }, children: [_jsxs(YStack, { gap: "$4", children: [_jsxs(View, { position: "relative", children: [_jsxs(Button, { size: "lg", width: "100%", justify: "space-between", onClick: () => setNewMenuOpen((v) => !v), "aria-expanded": newMenuOpen, children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Plus, { size: 16 }), _jsx(Text, { fontSize: "$3", fontWeight: "500", color: "$ink", children: "New" })] }), _jsx(ChevronDown, { size: 14, opacity: 0.65 })] }), newMenuOpen ? (_jsxs(YStack, { position: "absolute", t: "100%", mt: 6, l: 0, width: "100%", bg: "var(--popover)", borderWidth: 1, borderColor: "$borderColor", rounded: 10, boxShadow: "var(--shadow-lg)", z: "var(--z-dropdown)", p: 6, gap: 2, children: [_jsxs(Button, { ...ITEM, onClick: () => {
493
- setNewMenuOpen(false);
494
- setMenu(false);
495
- setNaming({ kind: 'folder', value: '' });
496
- }, children: [_jsx(FolderPlus, { size: 14 }), "New folder"] }), _jsx(View, { height: 1, bg: "$borderColor", my: 4 }), _jsxs(Button, { ...ITEM, onClick: () => {
497
- setNewMenuOpen(false);
498
- setMenu(false);
499
- fileInputRef.current?.click();
500
- }, children: [_jsx(Upload, { size: 14 }), "File upload"] }), _jsxs(Button, { ...ITEM, onClick: () => {
501
- setNewMenuOpen(false);
502
- setMenu(false);
503
- folderInputRef.current?.click();
504
- }, children: [_jsx(FolderInput, { size: 14 }), "Folder upload"] })] })) : null] }), _jsx(YStack, { gap: "$1", children: [
604
+ }, children: [_jsxs(YStack, { gap: "$4", children: [_jsxs(View, { position: "relative", children: [_jsxs(Button, { size: "lg", width: "100%", justify: "space-between", onClick: () => setNewMenuOpen((v) => !v), "aria-expanded": newMenuOpen, children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Plus, { size: 16 }), _jsx(Text, { fontSize: "$3", fontWeight: "500", color: "$ink", children: "New" })] }), _jsx(ChevronDown, { size: 14, opacity: 0.65 })] }), newMenuOpen ? (_jsx(YStack, { position: "absolute", t: "100%", mt: 6, l: 0, width: "100%", bg: "var(--popover)", borderWidth: 1, borderColor: "$borderColor", rounded: 10, boxShadow: "var(--shadow-lg)", z: "var(--z-dropdown)", p: 6, gap: 2, children: navSection === 'local' ? (_jsxs(_Fragment, { children: [_jsxs(Button, { ...ITEM, onClick: () => {
605
+ setNewMenuOpen(false);
606
+ setMenu(false);
607
+ setNaming({ kind: 'file', value: '' });
608
+ }, children: [_jsx(FilePlus, { size: 14 }), "New file"] }), _jsxs(Button, { ...ITEM, onClick: () => {
609
+ setNewMenuOpen(false);
610
+ setMenu(false);
611
+ setNaming({ kind: 'folder', value: '' });
612
+ }, children: [_jsx(FolderPlus, { size: 14 }), "New folder"] }), _jsx(View, { height: 1, bg: "$borderColor", my: 4 }), _jsxs(Button, { ...ITEM, onClick: () => {
613
+ setNewMenuOpen(false);
614
+ setMenu(false);
615
+ void pickLocalFolder().then((ws) => {
616
+ if (ws) {
617
+ setNavSection('local');
618
+ setLocalPrefix('');
619
+ }
620
+ });
621
+ }, children: [_jsx(FolderInput, { size: 14 }), "Open local folder\u2026"] }), _jsxs(Button, { ...ITEM, onClick: () => {
622
+ setNewMenuOpen(false);
623
+ setMenu(false);
624
+ void handleOpenLocalFile();
625
+ }, children: [_jsx(FileText, { size: 14 }), "Open local file\u2026"] }), _jsxs(Button, { ...ITEM, onClick: () => {
626
+ setNewMenuOpen(false);
627
+ setMenu(false);
628
+ void handleImportLocalFile();
629
+ }, children: [_jsx(Upload, { size: 14 }), "Import local file\u2026"] }), _jsxs(Button, { ...ITEM, onClick: () => {
630
+ setNewMenuOpen(false);
631
+ setMenu(false);
632
+ setNaming({ kind: 'clone', value: '' });
633
+ }, children: [_jsx(FolderGit2, { size: 14 }), "Clone remote repo\u2026"] })] })) : (_jsxs(_Fragment, { children: [_jsxs(Button, { ...ITEM, onClick: () => {
634
+ setNewMenuOpen(false);
635
+ setMenu(false);
636
+ setNaming({ kind: 'file', value: '' });
637
+ }, children: [_jsx(FilePlus, { size: 14 }), "New file"] }), _jsxs(Button, { ...ITEM, onClick: () => {
638
+ setNewMenuOpen(false);
639
+ setMenu(false);
640
+ setNaming({ kind: 'folder', value: '' });
641
+ }, children: [_jsx(FolderPlus, { size: 14 }), "New folder"] }), _jsx(View, { height: 1, bg: "$borderColor", my: 4 }), _jsxs(Button, { ...ITEM, onClick: () => {
642
+ setNewMenuOpen(false);
643
+ setMenu(false);
644
+ fileInputRef.current?.click();
645
+ }, children: [_jsx(Upload, { size: 14 }), "File upload"] }), _jsxs(Button, { ...ITEM, onClick: () => {
646
+ setNewMenuOpen(false);
647
+ setMenu(false);
648
+ folderInputRef.current?.click();
649
+ }, children: [_jsx(FolderInput, { size: 14 }), "Folder upload"] }), _jsx(View, { height: 1, bg: "$borderColor", my: 4 }), _jsxs(Button, { ...ITEM, onClick: () => {
650
+ setNewMenuOpen(false);
651
+ setMenu(false);
652
+ setNaming({ kind: 'clone', value: '' });
653
+ }, children: [_jsx(FolderGit2, { size: 14 }), "Clone remote repo\u2026"] })] })) })) : null] }), _jsx(YStack, { gap: "$1", children: [
505
654
  { id: 'my-drive', label: 'My Drive', icon: HardDrive },
655
+ { id: 'local', label: 'Local Folders', icon: Laptop },
506
656
  { id: 'recent', label: 'Recent', icon: Clock },
507
657
  ].map((item) => {
508
658
  const isActive = navSection === item.id && !bucket && !prefix;
@@ -513,19 +663,99 @@ export function Drive() {
513
663
  setPrefix('');
514
664
  setMenu(false);
515
665
  }, children: [_jsx(Icon, { size: 16 }), item.label] }, item.id));
516
- }) }), _jsxs(YStack, { gap: "$2", mt: "$2", px: "$2", children: [_jsx(Text, { fontSize: 11, fontWeight: "600", color: "$faint", letterSpacing: 0.6, children: "Storage" }), _jsx(Text, { fontSize: 12, color: "$quiet", children: usage ? `${usage.capped ? 'over ' : ''}${weigh(usage.bytes)} in ${usage.files.toLocaleString()} file${usage.files === 1 ? '' : 's'}` : 'Measuring…' }), _jsx(Button, { asChild: true, size: "sm", mt: 8, children: _jsx("a", { href: checkoutUrl(), target: "_blank", rel: "noreferrer", children: "Manage storage" }) })] })] }), _jsxs(YStack, { px: 14, py: 12, rounded: 10, borderWidth: 1, borderColor: "$borderColor", bg: "$panel", gap: 6, children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Cloud, { size: 16, color: "var(--foreground)" }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", children: "Hanzo Drive" })] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: [userEmail, activeBucket].filter(Boolean).join(' · ') }), _jsx(Button, { asChild: true, variant: "link", size: "sm", px: 0, mt: 4, justify: "flex-start", children: _jsxs("a", { href: "https://docs.hanzo.ai/docs/openapi/s3/", target: "_blank", rel: "noreferrer", children: ["Documentation", _jsx(ArrowRight, { size: 12 })] }) })] })] }), _jsxs(YStack, { flex: 1, minH: 0, px: "$6", py: "$5", overflowY: "auto", overflowX: "hidden", gap: "$5", children: [bucket || prefix ? (_jsxs(XStack, { items: "center", gap: "$2", pb: "$2", borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Button, { ...CRUMB, color: "$soft", onClick: () => {
666
+ }) }), navSection === 'local' || localWorkspaces.length > 0 ? (_jsxs(YStack, { gap: "$1", pl: "$2", borderLeftWidth: 1, borderColor: "$borderColor", ml: "$3", children: [_jsx(Text, { fontSize: 11, fontWeight: "600", color: "$faint", letterSpacing: 0.5, mb: 2, children: "Workspaces" }), localWorkspaces.map((ws) => {
667
+ const isCur = navSection === 'local' && activeWs?.id === ws.id;
668
+ return (_jsxs(XStack, { items: "center", justify: "space-between", px: "$2", py: "$1", rounded: 6, bg: isCur ? '$hover' : 'transparent', hoverStyle: { bg: '$hover' }, cursor: "pointer", onPress: () => {
669
+ setActiveWorkspace(ws);
670
+ setNavSection('local');
671
+ setLocalPrefix('');
672
+ }, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(Folder, { size: 13, color: isCur ? 'var(--primary)' : 'var(--muted-foreground)' }), _jsx(Text, { fontSize: "$2", fontWeight: isCur ? '600' : '400', color: isCur ? '$ink' : '$soft', numberOfLines: 1, children: ws.name })] }), _jsx(Button, { variant: "ghost", size: "icon-sm", onClick: (e) => {
673
+ e.stopPropagation();
674
+ removeLocalWorkspace(ws.id);
675
+ }, title: "Remove", children: _jsx(Trash2, { size: 11, color: "var(--muted-foreground)" }) })] }, ws.id));
676
+ }), _jsxs(Button, { variant: "ghost", size: "sm", justify: "flex-start", gap: 6, px: 8, py: 4, color: "$soft", onClick: () => {
677
+ void pickLocalFolder().then((ws) => {
678
+ if (ws) {
679
+ setNavSection('local');
680
+ setLocalPrefix('');
681
+ }
682
+ });
683
+ }, children: [_jsx(Plus, { size: 13 }), _jsx(Text, { fontSize: "$1", color: "$soft", children: "Open folder\u2026" })] })] })) : null, _jsxs(YStack, { gap: "$2", mt: "$2", px: "$2", children: [_jsx(Text, { fontSize: 11, fontWeight: "600", color: "$faint", letterSpacing: 0.6, children: "Storage" }), _jsx(Text, { fontSize: 12, color: "$quiet", children: usage ? `${usage.capped ? 'over ' : ''}${weigh(usage.bytes)} in ${usage.files.toLocaleString()} file${usage.files === 1 ? '' : 's'}` : 'Measuring…' }), _jsx(Button, { asChild: true, size: "sm", mt: 8, children: _jsx("a", { href: checkoutUrl(), target: "_blank", rel: "noreferrer", children: "Manage storage" }) })] })] }), _jsxs(YStack, { px: 14, py: 12, rounded: 10, borderWidth: 1, borderColor: "$borderColor", bg: "$panel", gap: 6, children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Cloud, { size: 16, color: "var(--foreground)" }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", children: "Hanzo Drive" })] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: [userEmail, activeBucket].filter(Boolean).join(' · ') }), _jsx(Button, { asChild: true, variant: "link", size: "sm", px: 0, mt: 4, justify: "flex-start", children: _jsxs("a", { href: "https://docs.hanzo.ai/docs/openapi/s3/", target: "_blank", rel: "noreferrer", children: ["Documentation", _jsx(ArrowRight, { size: 12 })] }) })] })] }), _jsxs(YStack, { flex: 1, minH: 0, px: "$6", py: "$5", overflowY: "auto", overflowX: "hidden", gap: "$5", children: [navSection === 'local' && activeWs ? (_jsxs(XStack, { items: "center", gap: "$2", pb: "$2", borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Button, { ...CRUMB, color: "$soft", onClick: () => {
684
+ setLocalPrefix('');
685
+ }, children: "Local Folders" }), _jsx(ChevronRight, { size: 13, color: "var(--muted-foreground)" }), _jsx(Button, { ...CRUMB, color: !localPrefix ? '$ink' : '$soft', onClick: () => setLocalPrefix(''), children: activeWs.name }), localPrefix
686
+ ? localPrefix.split('/').map((c, i, arr) => (_jsxs(React.Fragment, { children: [_jsx(ChevronRight, { size: 13, color: "var(--muted-foreground)" }), _jsx(Button, { ...CRUMB, color: i === arr.length - 1 ? '$ink' : '$soft', onClick: () => setLocalPrefix(arr.slice(0, i + 1).join('/')), children: c })] }, `${i}-${c}`)))
687
+ : null] })) : bucket || prefix ? (_jsxs(XStack, { items: "center", gap: "$2", pb: "$2", borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Button, { ...CRUMB, color: "$soft", onClick: () => {
517
688
  openBucket(null);
518
689
  setPrefix('');
519
- }, children: "Drive" }), _jsx(ChevronRight, { size: 13, color: "var(--muted-foreground)" }), _jsx(Button, { ...CRUMB, color: crumbs.length === 0 ? '$ink' : '$soft', onClick: () => setPrefix(''), children: bucket || 'hanzo' }), crumbs.map((c, i) => (_jsxs(React.Fragment, { children: [_jsx(ChevronRight, { size: 13, color: "var(--muted-foreground)" }), _jsx(Button, { ...CRUMB, color: i === crumbs.length - 1 ? '$ink' : '$soft', onClick: () => setPrefix(crumbs.slice(0, i + 1).map((x) => `${x}/`).join('')), children: c })] }, `${i}-${c}`)))] })) : null, _jsxs(XStack, { items: "center", justify: "space-between", children: [_jsxs(YStack, { gap: "$1", children: [_jsx(Text, { render: "h1", fontSize: 26, fontWeight: "700", color: "$ink", children: "Drive" }), _jsx(Text, { fontSize: 13, color: "$soft", children: "Secure. Private. Built for builders." })] }), _jsx(XStack, { items: "center", bg: "$panel", rounded: 8, borderWidth: 1, borderColor: "$borderColor", p: 2, gap: 2, children: [
690
+ }, children: "Drive" }), _jsx(ChevronRight, { size: 13, color: "var(--muted-foreground)" }), _jsx(Button, { ...CRUMB, color: crumbs.length === 0 ? '$ink' : '$soft', onClick: () => setPrefix(''), children: bucket || 'hanzo' }), crumbs.map((c, i) => (_jsxs(React.Fragment, { children: [_jsx(ChevronRight, { size: 13, color: "var(--muted-foreground)" }), _jsx(Button, { ...CRUMB, color: i === crumbs.length - 1 ? '$ink' : '$soft', onClick: () => setPrefix(crumbs.slice(0, i + 1).map((x) => `${x}/`).join('')), children: c })] }, `${i}-${c}`)))] })) : null, _jsxs(XStack, { items: "center", justify: "space-between", children: [_jsxs(YStack, { gap: "$1", children: [_jsx(Text, { render: "h1", fontSize: 26, fontWeight: "700", color: "$ink", children: navSection === 'local' ? (activeWs ? activeWs.name : 'Local Folders') : 'Drive' }), _jsx(Text, { fontSize: 13, color: "$soft", children: navSection === 'local'
691
+ ? activeWs
692
+ ? activeWs.path
693
+ : 'Edit local files, add files & folders, and code locally.'
694
+ : 'Secure. Private. Built for builders.' })] }), _jsx(XStack, { items: "center", bg: "$panel", rounded: 8, borderWidth: 1, borderColor: "$borderColor", p: 2, gap: 2, children: [
520
695
  ['list', 'List View', List],
521
696
  ['grid', 'Grid View', LayoutGrid],
522
697
  ['details', 'Details View', MoreHorizontal],
523
- ].map(([mode, label, Icon]) => (_jsx(Button, { variant: viewMode === mode ? 'secondary' : 'ghost', size: "icon-sm", color: viewMode === mode ? '$ink' : '$soft', onClick: () => setViewMode(mode), "aria-label": label, "aria-pressed": viewMode === mode, title: label, children: _jsx(Icon, { size: 14 }) }, mode))) })] }), naming ? (_jsxs(XStack, { items: "center", gap: "$3", py: 10, px: 14, rounded: 8, borderWidth: 1, borderColor: "var(--border-control)", bg: "$panel", children: [_jsx(Folder, { size: 16, color: "var(--foreground)" }), _jsx(Text, { render: _jsx("input", { autoFocus: true, value: naming.value, onChange: (e) => setNaming({ ...naming, value: e.target.value }), onKeyDown: (e) => {
698
+ ].map(([mode, label, Icon]) => (_jsx(Button, { variant: viewMode === mode ? 'secondary' : 'ghost', size: "icon-sm", color: viewMode === mode ? '$ink' : '$soft', onClick: () => setViewMode(mode), "aria-label": label, "aria-pressed": viewMode === mode, title: label, children: _jsx(Icon, { size: 14 }) }, mode))) })] }), naming ? (_jsxs(XStack, { items: "center", gap: "$3", py: 10, px: 14, rounded: 8, borderWidth: 1, borderColor: "var(--border-control)", bg: "$panel", children: [naming.kind === 'file' ? (_jsx(FileCode, { size: 16, color: "var(--primary)" })) : naming.kind === 'clone' ? (_jsx(FolderGit2, { size: 16, color: "var(--primary)" })) : (_jsx(Folder, { size: 16, color: "var(--foreground)" })), _jsx(Text, { render: _jsx("input", { autoFocus: true, value: naming.value, onChange: (e) => setNaming({ ...naming, value: e.target.value }), onKeyDown: (e) => {
524
699
  if (e.key === 'Escape')
525
700
  setNaming(null);
526
- if (e.key === 'Enter')
527
- handleCreateFolder(naming.value);
528
- }, placeholder: "Folder name", "aria-label": "Folder name" }), ...BARE }), _jsx(Button, { variant: "primary", size: "sm", onClick: () => handleCreateFolder(naming.value), children: "Create" }), _jsx(Button, { variant: "ghost", size: "sm", color: "$soft", onClick: () => setNaming(null), children: "Cancel" })] })) : null, busy ? (_jsxs(Text, { fontSize: "$2", color: "$soft", "data-slot": "drive-busy", children: [busy, "\u2026"] })) : null, hits && hits.length ? _jsx(Hits, { hits: hits, onOpen: (p) => showContents(p.file.id, p.section.id) }) : null, bucket || prefix ? (_jsx(YStack, { gap: "$2", children: _jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: 8, overflowX: "auto", overflowY: "hidden", children: [_jsxs(View, { display: "grid", gridTemplateColumns: FILES, minW: "min-content", px: 16, py: 10, borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Text, { ...HEAD, children: "NAME" }), _jsx(Text, { ...HEAD, children: "TYPE" }), _jsx(Text, { ...HEAD, children: "UPDATED \u2193" }), _jsx(Text, { ...HEAD, children: "SIZE" }), _jsx(View, {})] }), !filteredEntries || filteredEntries.length === 0 ? (_jsx(Text, { py: 36, px: 16, text: "center", fontSize: "$2", color: "$faint", children: "None" })) : (filteredEntries.map((e) => {
701
+ if (e.key === 'Enter') {
702
+ if (naming.kind === 'file')
703
+ handleCreateFile(naming.value);
704
+ else if (naming.kind === 'clone')
705
+ handleCloneRepo(naming.value);
706
+ else
707
+ handleCreateFolder(naming.value);
708
+ }
709
+ }, placeholder: naming.kind === 'file'
710
+ ? 'File name (e.g. index.ts)'
711
+ : naming.kind === 'clone'
712
+ ? 'owner/repo or Git URL (e.g. hanzoai/desktop)'
713
+ : 'Folder name', "aria-label": naming.kind === 'file'
714
+ ? 'File name'
715
+ : naming.kind === 'clone'
716
+ ? 'Clone remote repository'
717
+ : 'Folder name' }), ...BARE }), _jsx(Button, { variant: "primary", size: "sm", onClick: () => {
718
+ if (naming.kind === 'file')
719
+ handleCreateFile(naming.value);
720
+ else if (naming.kind === 'clone')
721
+ handleCloneRepo(naming.value);
722
+ else
723
+ handleCreateFolder(naming.value);
724
+ }, children: naming.kind === 'clone' ? 'Clone' : 'Create' }), _jsx(Button, { variant: "ghost", size: "sm", color: "$soft", onClick: () => setNaming(null), children: "Cancel" })] })) : null, editingFile ? (_jsx(Editor, { filePath: editingFile.path, fileName: editingFile.name, onClose: () => {
725
+ setEditingFile(null);
726
+ loadLocalEntries();
727
+ }, onAskInChat: () => {
728
+ setEditingFile(null);
729
+ router.push('/chat');
730
+ } })) : null, busy ? (_jsxs(Text, { fontSize: "$2", color: "$soft", "data-slot": "drive-busy", children: [busy, "\u2026"] })) : null, hits && hits.length ? _jsx(Hits, { hits: hits, onOpen: (p) => showContents(p.file.id, p.section.id) }) : null, navSection === 'local' ? (!activeWs ? (_jsxs(YStack, { py: 60, px: 24, items: "center", justify: "center", gap: "$4", borderWidth: 1, borderStyle: "dashed", borderColor: "$borderColor", rounded: 12, bg: "$panel", children: [_jsx(Laptop, { size: 40, color: "var(--primary)" }), _jsxs(YStack, { items: "center", gap: "$1", maxW: 460, children: [_jsx(Text, { fontSize: 18, fontWeight: "600", color: "$ink", text: "center", children: "No local folder opened" }), _jsx(Text, { fontSize: 13, color: "$soft", text: "center", children: "Open a local folder on your computer to browse, create, edit, and save files directly in Hanzo Desktop." })] }), _jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(Button, { onClick: () => {
731
+ void pickLocalFolder().then((ws) => {
732
+ if (ws) {
733
+ setNavSection('local');
734
+ setLocalPrefix('');
735
+ }
736
+ });
737
+ }, children: [_jsx(FolderPlus, { size: 16 }), "Open Local Folder\u2026"] }), _jsxs(Button, { variant: "outline", onClick: () => setNaming({ kind: 'clone', value: '' }), children: [_jsx(FolderGit2, { size: 16 }), "Clone Remote Repo\u2026"] })] })] })) : (_jsxs(YStack, { gap: "$2", children: [_jsxs(XStack, { items: "center", justify: "space-between", pb: "$1", children: [_jsx(Text, { fontSize: 12, fontWeight: "600", color: "$soft", children: localPrefix ? `Folder: ${localPrefix}` : 'Root Files & Directories' }), _jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(Button, { variant: "outline", size: "sm", onClick: () => setNaming({ kind: 'file', value: '' }), children: [_jsx(FilePlus, { size: 13 }), "New file"] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setNaming({ kind: 'folder', value: '' }), children: [_jsx(FolderPlus, { size: 13 }), "New folder"] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => void handleImportLocalFile(), children: [_jsx(Upload, { size: 13 }), "Import file"] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setNaming({ kind: 'clone', value: '' }), children: [_jsx(FolderGit2, { size: 13 }), "Clone repo"] })] })] }), _jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: 8, overflowX: "auto", overflowY: "hidden", children: [_jsxs(View, { display: "grid", gridTemplateColumns: FILES, minW: "min-content", px: 16, py: 10, borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Text, { ...HEAD, children: "Name" }), _jsx(Text, { ...HEAD, children: "Type" }), _jsx(Text, { ...HEAD, children: "Updated" }), _jsx(Text, { ...HEAD, children: "Size" }), _jsx(View, {})] }), !localEntries || localEntries.length === 0 ? (_jsx(Text, { py: 36, px: 16, text: "center", fontSize: "$2", color: "$faint", children: "Empty folder" })) : (localEntries.map((e) => {
738
+ const ext = e.name.split('.').pop() || '';
739
+ return (_jsxs(View, { display: "grid", gridTemplateColumns: FILES, minW: "min-content", px: 16, py: 11, items: "center", cursor: "pointer", borderBottomWidth: 1, borderColor: "$borderColor", transition: "100ms", hoverStyle: { bg: '$hover' }, onClick: () => {
740
+ if (e.isDir) {
741
+ setLocalPrefix(localPrefix ? `${localPrefix}/${e.name}` : e.name);
742
+ }
743
+ else {
744
+ setEditingFile({ path: e.path, name: e.name });
745
+ }
746
+ }, children: [_jsxs(XStack, { items: "center", gap: "$3", minW: 0, pr: "$2", children: [e.isDir ? (_jsx(Folder, { size: 16, color: "var(--foreground)" })) : (_jsx(FileCode, { size: 16, color: "var(--muted-foreground)" })), _jsx(Text, { ...NAME, children: e.name })] }), _jsx(Text, { fontSize: "$2", color: "$soft", numberOfLines: 1, children: e.isDir ? 'Folder' : ext.toUpperCase() || 'File' }), _jsx(Text, { ...CELL, children: e.lastModified ? when(e.lastModified) : '—' }), _jsx(Text, { ...CELL, children: e.isDir ? '—' : weigh(e.size) }), _jsxs(View, { position: "relative", onClick: (evt) => evt.stopPropagation(), children: [_jsx(More, { onPress: (evt) => {
747
+ evt.stopPropagation();
748
+ setItemMenuKey(itemMenuKey === e.path ? null : e.path);
749
+ } }), itemMenuKey === e.path ? (_jsxs(YStack, { position: "absolute", r: 0, t: "100%", z: "var(--z-dropdown)", width: 160, bg: "var(--popover)", borderWidth: 1, borderColor: "$borderColor", rounded: 8, boxShadow: "var(--shadow-lg)", p: 4, gap: 2, children: [!e.isDir ? (_jsx(Pick, { icon: FileCode, label: "Edit file", onPress: () => {
750
+ setItemMenuKey(null);
751
+ setEditingFile({ path: e.path, name: e.name });
752
+ } })) : null, _jsx(Pick, { icon: Trash2, label: "Delete", tone: BAD, onPress: () => {
753
+ setItemMenuKey(null);
754
+ deleteLocalPath(e.path)
755
+ .then(() => loadLocalEntries())
756
+ .catch((err) => setFailed(blame(err)));
757
+ } })] })) : null] })] }, e.path));
758
+ }))] })] }))) : bucket || prefix ? (_jsx(YStack, { gap: "$2", children: _jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: 8, overflowX: "auto", overflowY: "hidden", children: [_jsxs(View, { display: "grid", gridTemplateColumns: FILES, minW: "min-content", px: 16, py: 10, borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Text, { ...HEAD, children: "NAME" }), _jsx(Text, { ...HEAD, children: "TYPE" }), _jsx(Text, { ...HEAD, children: "UPDATED \u2193" }), _jsx(Text, { ...HEAD, children: "SIZE" }), _jsx(View, {})] }), !filteredEntries || filteredEntries.length === 0 ? (_jsx(Text, { py: 36, px: 16, text: "center", fontSize: "$2", color: "$faint", children: "None" })) : (filteredEntries.map((e) => {
529
759
  const isFolder = e.isDir || e.key.endsWith('/');
530
760
  const cleanName = e.key.replace(/\/+$/, '');
531
761
  return (_jsxs(View, { display: "grid", gridTemplateColumns: FILES, minW: "min-content", px: 16, py: 11, items: "center", cursor: "pointer", borderBottomWidth: 1, borderColor: "$borderColor", transition: "100ms", hoverStyle: { bg: '$hover' }, onClick: () => {
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export interface EditorProps {
3
+ filePath: string;
4
+ fileName?: string;
5
+ onClose: () => void;
6
+ onAskInChat?: (filePath: string, fileName: string) => void;
7
+ }
8
+ export declare function Editor({ filePath, fileName, onClose, onAskInChat }: EditorProps): React.JSX.Element;
package/dist/Editor.js ADDED
@@ -0,0 +1,94 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useState } from 'react';
4
+ import { ArrowLeft, Check, FileCode, MessageSquare, Save, X } from 'lucide-react';
5
+ import { Button, Text, XStack, YStack } from '@hanzo/ui';
6
+ import { useI18n } from '@hanzo/i18n/react';
7
+ import { readLocalFile, writeLocalFile } from './lib/local-fs.js';
8
+ export function Editor({ filePath, fileName, onClose, onAskInChat }) {
9
+ const { t } = useI18n();
10
+ const name = fileName || filePath.split(/[/\\]/).pop() || 'Untitled';
11
+ const [content, setContent] = useState('');
12
+ const [initialContent, setInitialContent] = useState('');
13
+ const [loading, setLoading] = useState(true);
14
+ const [saving, setSaving] = useState(false);
15
+ const [saved, setSaved] = useState(false);
16
+ const [error, setError] = useState(null);
17
+ const isDirty = content !== initialContent;
18
+ useEffect(() => {
19
+ let live = true;
20
+ setLoading(true);
21
+ setError(null);
22
+ readLocalFile(filePath)
23
+ .then((text) => {
24
+ if (!live)
25
+ return;
26
+ setContent(text);
27
+ setInitialContent(text);
28
+ setLoading(false);
29
+ })
30
+ .catch((err) => {
31
+ if (!live)
32
+ return;
33
+ setError(err instanceof Error ? err.message : String(err));
34
+ setLoading(false);
35
+ });
36
+ return () => {
37
+ live = false;
38
+ };
39
+ }, [filePath]);
40
+ const handleSave = useCallback(async () => {
41
+ if (saving || !isDirty)
42
+ return;
43
+ setSaving(true);
44
+ setError(null);
45
+ try {
46
+ await writeLocalFile(filePath, content);
47
+ setInitialContent(content);
48
+ setSaved(true);
49
+ setTimeout(() => setSaved(false), 2000);
50
+ }
51
+ catch (err) {
52
+ setError(err instanceof Error ? err.message : String(err));
53
+ }
54
+ finally {
55
+ setSaving(false);
56
+ }
57
+ }, [filePath, content, saving, isDirty]);
58
+ // Handle Ctrl+S / Cmd+S
59
+ useEffect(() => {
60
+ const handleKeyDown = (e) => {
61
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
62
+ e.preventDefault();
63
+ void handleSave();
64
+ }
65
+ if (e.key === 'Escape') {
66
+ onClose();
67
+ }
68
+ };
69
+ window.addEventListener('keydown', handleKeyDown);
70
+ return () => window.removeEventListener('keydown', handleKeyDown);
71
+ }, [handleSave, onClose]);
72
+ const lineCount = content.split('\n').length;
73
+ return (_jsxs(YStack, { position: "absolute", t: 0, r: 0, b: 0, l: 0, z: 30, bg: "$background", overflow: "hidden", "data-slot": "local-file-editor", children: [_jsxs(XStack, { height: 52, items: "center", justify: "space-between", px: "$4", borderBottomWidth: 1, borderColor: "$borderColor", bg: "$panel", shrink: 0, children: [_jsxs(XStack, { items: "center", gap: "$3", minW: 0, flex: 1, children: [_jsx(Button, { variant: "ghost", size: "icon-sm", onClick: onClose, "aria-label": t('Back'), children: _jsx(ArrowLeft, { size: 16 }) }), _jsx(FileCode, { size: 18, color: "var(--primary)", "aria-hidden": true }), _jsxs(YStack, { minW: 0, flex: 1, children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", numberOfLines: 1, children: name }), isDirty ? (_jsxs(Text, { fontSize: "$1", color: "var(--primary)", fontWeight: "600", children: ["\u25CF ", t('Modified')] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", numberOfLines: 1, children: filePath })] })] }), _jsxs(XStack, { items: "center", gap: "$2", children: [error ? (_jsx(Text, { fontSize: "$1", color: "var(--destructive)", numberOfLines: 1, maxW: 240, children: error })) : null, onAskInChat ? (_jsxs(Button, { variant: "outline", size: "sm", onClick: () => onAskInChat(filePath, name), "aria-label": t('Ask in Chat'), children: [_jsx(MessageSquare, { size: 14 }), t('Ask in Chat')] })) : null, _jsxs(Button, { variant: isDirty ? 'default' : 'secondary', size: "sm", onClick: () => void handleSave(), disabled: saving || !isDirty, "aria-label": t('Save'), children: [saved ? _jsx(Check, { size: 14 }) : _jsx(Save, { size: 14 }), saved ? t('Saved') : saving ? t('Saving…') : t('Save (⌘S)')] }), _jsx(Button, { variant: "ghost", size: "icon-sm", onClick: onClose, "aria-label": t('Close'), children: _jsx(X, { size: 16 }) })] })] }), loading ? (_jsx(YStack, { flex: 1, items: "center", justify: "center", gap: "$3", children: _jsx(Text, { fontSize: "$3", color: "$soft", children: t('Loading file…') }) })) : error && !content ? (_jsxs(YStack, { flex: 1, items: "center", justify: "center", p: "$6", gap: "$3", children: [_jsx(Text, { fontSize: "$4", color: "var(--destructive)", fontWeight: "600", children: t('Failed to open file') }), _jsx(Text, { fontSize: "$2", color: "$soft", text: "center", maxW: 480, children: error }), _jsx(Button, { variant: "outline", size: "sm", onClick: onClose, mt: "$3", children: t('Go back') })] })) : (_jsxs(XStack, { flex: 1, minH: 0, overflow: "hidden", children: [_jsx(YStack, { width: 48, py: "$3", px: "$2", bg: "$panel", borderRightWidth: 1, borderColor: "$borderColor",
74
+ // inline-style: user-select is needed to prevent selection of line numbers
75
+ style: { userSelect: 'none' }, overflow: "hidden", items: "flex-end", children: Array.from({ length: Math.min(lineCount, 5000) }).map((_, i) => (_jsx(Text, { fontSize: 12, lineHeight: 20, fontFamily: "$mono", color: "$faint", children: i + 1 }, i))) }), _jsx("textarea", { value: content, onChange: (e) => setContent(e.target.value), spellCheck: false, autoCapitalize: "off", autoComplete: "off", autoCorrect: "off",
76
+ // inline-style: raw textarea styling for code editing
77
+ style: {
78
+ flex: 1,
79
+ height: '100%',
80
+ backgroundColor: 'transparent',
81
+ color: 'var(--foreground)',
82
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
83
+ fontSize: 'var(--text-sm)',
84
+ lineHeight: '20px',
85
+ padding: '12px 16px',
86
+ border: 'none',
87
+ outline: 'none',
88
+ resize: 'none',
89
+ whiteSpace: 'pre',
90
+ overflowWrap: 'normal',
91
+ overflowX: 'auto',
92
+ overflowY: 'auto',
93
+ } })] }))] }));
94
+ }
package/dist/Start.js CHANGED
@@ -29,6 +29,7 @@ import { Composer } from '@hanzo/ui/chat';
29
29
  import { useOpen } from './open.js';
30
30
  import { CodingRefusal, dispatchable, listTargets, startCoding, } from './lib/coding.js';
31
31
  import { BAD } from './lib/mix.js';
32
+ import { getLocalWorkspaces, pickLocalFolder, runLocalDev, } from './lib/local-fs.js';
32
33
  /** A field of the start row: 32px, outlined, in the row's own ink. */
33
34
  const FIELD = {
34
35
  height: 32,
@@ -49,13 +50,11 @@ export function Start() {
49
50
  const [repo, setRepo] = useState('');
50
51
  const [where, setWhere] = useState(SANDBOX);
51
52
  const [targets, setTargets] = useState([]);
53
+ const [localWorkspaces, setLocalWorkspaces] = useState([]);
52
54
  const [busy, setBusy] = useState(false);
53
55
  const [tool, setTool] = useState('dev');
54
56
  const [err, setErr] = useState(null);
55
- // The machines this org has claimed. An empty list is an ANSWER — every run
56
- // goes to a sandbox — so it is not an error and draws no warning. Only a
57
- // refusal is reported, and even then the composer stays usable: a sandbox run
58
- // needs no target, so being unable to list machines must not stop a send.
57
+ const [localMsg, setLocalMsg] = useState(null);
59
58
  useEffect(() => {
60
59
  let live = true;
61
60
  listTargets()
@@ -63,16 +62,50 @@ export function Start() {
63
62
  .catch(() => {
64
63
  /* Listing is an enhancement here; the sandbox needs nothing from it. */
65
64
  });
65
+ setLocalWorkspaces(getLocalWorkspaces());
66
66
  return () => {
67
67
  live = false;
68
68
  };
69
69
  }, []);
70
+ const handleWhereChange = useCallback(async (val) => {
71
+ if (val === 'action:pick-local') {
72
+ try {
73
+ const ws = await pickLocalFolder();
74
+ if (ws) {
75
+ setLocalWorkspaces((prev) => [ws, ...prev.filter((p) => p.path !== ws.path)]);
76
+ setWhere(`local:${ws.path}`);
77
+ }
78
+ }
79
+ catch (e) {
80
+ setErr(e?.message || 'Could not pick folder');
81
+ }
82
+ return;
83
+ }
84
+ setWhere(val);
85
+ }, []);
70
86
  const send = useCallback(async () => {
71
87
  const task = prompt.trim();
72
88
  if (!task || busy)
73
89
  return;
74
90
  setBusy(true);
75
91
  setErr(null);
92
+ setLocalMsg(null);
93
+ if (where.startsWith('local:')) {
94
+ const localPath = where.slice(6);
95
+ try {
96
+ setLocalMsg(t('Running local dev agent in {path}…', { path: localPath }));
97
+ const res = await runLocalDev(localPath, task);
98
+ setPrompt('');
99
+ setLocalMsg(res.output?.slice(0, 300) || res.sessionId || t('Completed successfully.'));
100
+ }
101
+ catch (e) {
102
+ setErr(e?.message || t('Local dev execution failed'));
103
+ }
104
+ finally {
105
+ setBusy(false);
106
+ }
107
+ return;
108
+ }
76
109
  try {
77
110
  const run = await startCoding({
78
111
  prompt: task,
@@ -92,5 +125,12 @@ export function Start() {
92
125
  setBusy(false);
93
126
  }
94
127
  }, [prompt, repo, tool, where, busy, openSession, t]);
95
- return (_jsxs(YStack, { width: "100%", gap: "$2", children: [_jsx(Composer, { value: prompt, onChange: setPrompt, onSend: () => void send(), busy: busy, placeholder: t('Describe what to build…'), label: t('Describe what to build') }), _jsxs(XStack, { gap: "$2", items: "center", flexWrap: "wrap", children: [_jsxs(Text, { render: _jsx("select", { value: tool, onChange: (e) => setTool(e.currentTarget.value), "aria-label": t('Agent Harness') }), ...FIELD, px: 8, children: [_jsx("option", { value: "dev", children: "Dev" }), _jsx("option", { value: "claude", children: "Claude" }), _jsx("option", { value: "codex", children: "Codex" }), _jsx("option", { value: "python", children: "Python" })] }), _jsx(Text, { render: _jsx("input", { "data-i18n-ltr": "", value: repo, onChange: (e) => setRepo(e.currentTarget.value), placeholder: t('owner/repo (optional)'), "aria-label": t('Repository') }), ...FIELD, flex: 1, minW: 160, px: 10, outlineStyle: "none" }), targets.length > 0 ? (_jsxs(Text, { render: _jsx("select", { value: where, onChange: (e) => setWhere(e.currentTarget.value), "aria-label": t('Where to run') }), ...FIELD, px: 8, children: [_jsx("option", { value: SANDBOX, children: t('Sandbox') }), targets.map((t) => (_jsxs("option", { value: t.id, children: [t.label || t.host || t.id, t.capacity ? ` — ${t.capacity}` : ''] }, t.id)))] })) : null] }), err ? (_jsx(Text, { role: "alert", fontSize: "$2", color: BAD, children: err })) : (_jsx(Text, { fontSize: "$2", color: SOFT, children: t(targets.length > 0 && where !== SANDBOX ? 'Runs on your machine.' : 'Runs in an isolated sandbox with Free AI / Enso.') }))] }));
128
+ const isLocal = where.startsWith('local:');
129
+ return (_jsxs(YStack, { width: "100%", gap: "$2", children: [_jsx(Composer, { value: prompt, onChange: setPrompt, onSend: () => void send(), busy: busy, placeholder: t('Describe what to build…'), label: t('Describe what to build') }), _jsxs(XStack, { gap: "$2", items: "center", flexWrap: "wrap", children: [_jsxs(Text, { render: _jsx("select", { value: tool, onChange: (e) => setTool(e.currentTarget.value), "aria-label": t('Agent Harness') }), ...FIELD, px: 8, children: [_jsx("option", { value: "dev", children: "Dev" }), _jsx("option", { value: "claude", children: "Claude" }), _jsx("option", { value: "codex", children: "Codex" }), _jsx("option", { value: "python", children: "Python" })] }), !isLocal ? (_jsx(Text, { render: _jsx("input", { "data-i18n-ltr": "", value: repo, onChange: (e) => setRepo(e.currentTarget.value), placeholder: t('owner/repo (optional)'), "aria-label": t('Repository') }), ...FIELD, flex: 1, minW: 160, px: 10, outlineStyle: "none" })) : (_jsx(Text, { ...FIELD, flex: 1, minW: 160, px: 10,
130
+ // inline-style: flex alignment for where path text
131
+ style: { display: 'flex', alignItems: 'center', opacity: 0.8 }, children: where.slice(6) })), _jsxs(Text, { render: _jsx("select", { value: where, onChange: (e) => void handleWhereChange(e.currentTarget.value), "aria-label": t('Where to run') }), ...FIELD, px: 8, children: [_jsx("option", { value: SANDBOX, children: t('Cloud Sandbox') }), localWorkspaces.map((ws) => (_jsx("option", { value: `local:${ws.path}`, children: t('Local: {name}', { name: ws.name }) }, ws.path))), _jsx("option", { value: "action:pick-local", children: t('+ Open local folder…') }), targets.map((tg) => (_jsxs("option", { value: tg.id, children: [tg.label || tg.host || tg.id, tg.capacity ? ` — ${tg.capacity}` : ''] }, tg.id)))] })] }), err ? (_jsx(Text, { role: "alert", fontSize: "$2", color: BAD, children: err })) : localMsg ? (_jsx(Text, { fontSize: "$2", color: "$color", children: localMsg })) : (_jsx(Text, { fontSize: "$2", color: SOFT, children: t(isLocal
132
+ ? 'Runs locally on your machine with dev agent.'
133
+ : targets.length > 0 && where !== SANDBOX
134
+ ? 'Runs on your linked machine.'
135
+ : 'Runs in an isolated sandbox with Free AI / Enso.') }))] }));
96
136
  }
package/dist/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export { configure, where, site, brand } from './where.js';
12
12
  export type { Addresses } from './where.js';
13
13
  export { Rooms, Look, useRooms, useLook, useOrg } from './host.js';
14
14
  export type { Router, Link, RoomsProps } from './host.js';
15
+ export * from './lib/local-fs.js';
package/dist/index.js CHANGED
@@ -10,5 +10,6 @@
10
10
  */
11
11
  export { configure, where, site, brand } from './where.js';
12
12
  export { Rooms, Look, useRooms, useLook, useOrg } from './host.js';
13
- // Desktop UI loads through @hanzo/app/WindowControls; keep the root usable
13
+ export * from './lib/local-fs.js';
14
+ // Desktop UI loads through @hanzo/app/WindowControls and @hanzo/app/Editor; keep the root usable
14
15
  // by Node tools without loading @hanzo/ui and React Native.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Local file system support for Hanzo Desktop & modern browsers.
3
+ *
4
+ * Allows users to:
5
+ * 1. Open and track local folders/workspaces on their machine.
6
+ * 2. Browse files and subdirectories.
7
+ * 3. Create new files and folders.
8
+ * 4. Read, view, and edit local files with real-time saving.
9
+ * 5. Run local coding tasks against the workspace with `hanzoai/dev`.
10
+ */
11
+ export interface LocalWorkspace {
12
+ id: string;
13
+ name: string;
14
+ path: string;
15
+ addedAt: number;
16
+ lastOpenedAt: number;
17
+ }
18
+ export interface LocalEntry {
19
+ name: string;
20
+ path: string;
21
+ isDir: boolean;
22
+ size: number;
23
+ lastModified?: number;
24
+ }
25
+ export declare function subscribeLocalFs(l: () => void): () => void;
26
+ /** Check if running inside the Tauri native desktop app */
27
+ export declare function isTauri(): boolean;
28
+ /** Get all registered local workspaces */
29
+ export declare function getLocalWorkspaces(): LocalWorkspace[];
30
+ /** Get active local workspace */
31
+ export declare function getActiveWorkspace(): LocalWorkspace | null;
32
+ /** Set active local workspace */
33
+ export declare function setActiveWorkspace(ws: LocalWorkspace | null): void;
34
+ /** Add a local workspace */
35
+ export declare function addLocalWorkspace(path: string, name?: string): LocalWorkspace;
36
+ /** Remove a local workspace */
37
+ export declare function removeLocalWorkspace(idOrPath: string): void;
38
+ /** Open native dialog to pick a local folder */
39
+ export declare function pickLocalFolder(): Promise<LocalWorkspace | null>;
40
+ /** Open native dialog to pick a local file to view or edit */
41
+ export declare function pickLocalFile(): Promise<string | null>;
42
+ /** Clone a remote repository to local machine and register as a workspace */
43
+ export declare function cloneRemoteRepo(repo: string, targetDir?: string): Promise<LocalWorkspace>;
44
+ /** Import an existing local file into the active workspace directory */
45
+ export declare function importLocalFile(sourcePath: string, targetDir: string): Promise<LocalEntry>;
46
+ /** List entries in a local directory */
47
+ export declare function listLocalEntries(dirPath: string): Promise<LocalEntry[]>;
48
+ /** Read text content of a local file */
49
+ export declare function readLocalFile(filePath: string): Promise<string>;
50
+ /** Write text content to a local file */
51
+ export declare function writeLocalFile(filePath: string, content: string): Promise<void>;
52
+ /** Create a new empty file */
53
+ export declare function createLocalFile(dirPath: string, name: string, content?: string): Promise<string>;
54
+ /** Create a new local directory */
55
+ export declare function createLocalDir(dirPath: string, name: string): Promise<string>;
56
+ /** Delete a local file or directory */
57
+ export declare function deleteLocalPath(path: string): Promise<void>;
58
+ /** Run local coding task with `dev` CLI */
59
+ export declare function runLocalDev(workspacePath: string, prompt: string): Promise<{
60
+ sessionId: string;
61
+ output?: string;
62
+ }>;
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Local file system support for Hanzo Desktop & modern browsers.
3
+ *
4
+ * Allows users to:
5
+ * 1. Open and track local folders/workspaces on their machine.
6
+ * 2. Browse files and subdirectories.
7
+ * 3. Create new files and folders.
8
+ * 4. Read, view, and edit local files with real-time saving.
9
+ * 5. Run local coding tasks against the workspace with `hanzoai/dev`.
10
+ */
11
+ const WORKSPACES_KEY = 'hanzo.local_workspaces';
12
+ const ACTIVE_WORKSPACE_KEY = 'hanzo.active_workspace';
13
+ const listeners = new Set();
14
+ function notify() {
15
+ for (const l of listeners)
16
+ l();
17
+ }
18
+ export function subscribeLocalFs(l) {
19
+ listeners.add(l);
20
+ return () => {
21
+ listeners.delete(l);
22
+ };
23
+ }
24
+ /** Check if running inside the Tauri native desktop app */
25
+ export function isTauri() {
26
+ return typeof window !== 'undefined' && Boolean(window.__TAURI_INTERNALS__ ||
27
+ window.__TAURI__);
28
+ }
29
+ /** Invoke a Tauri IPC command safely */
30
+ async function tauriInvoke(cmd, args) {
31
+ const win = window;
32
+ const invoke = win.__TAURI_INTERNALS__?.invoke || win.__TAURI__?.core?.invoke;
33
+ if (!invoke)
34
+ throw new Error('Tauri IPC is not available');
35
+ return invoke(cmd, args);
36
+ }
37
+ /** Get all registered local workspaces */
38
+ export function getLocalWorkspaces() {
39
+ try {
40
+ const raw = window.localStorage.getItem(WORKSPACES_KEY);
41
+ if (!raw)
42
+ return [];
43
+ const parsed = JSON.parse(raw);
44
+ return Array.isArray(parsed) ? parsed : [];
45
+ }
46
+ catch {
47
+ return [];
48
+ }
49
+ }
50
+ /** Get active local workspace */
51
+ export function getActiveWorkspace() {
52
+ try {
53
+ const id = window.localStorage.getItem(ACTIVE_WORKSPACE_KEY);
54
+ const list = getLocalWorkspaces();
55
+ if (!id)
56
+ return list[0] ?? null;
57
+ return list.find((w) => w.id === id || w.path === id) ?? list[0] ?? null;
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ /** Set active local workspace */
64
+ export function setActiveWorkspace(ws) {
65
+ try {
66
+ if (ws) {
67
+ window.localStorage.setItem(ACTIVE_WORKSPACE_KEY, ws.id);
68
+ const list = getLocalWorkspaces().map((w) => (w.id === ws.id ? { ...w, lastOpenedAt: Date.now() } : w));
69
+ window.localStorage.setItem(WORKSPACES_KEY, JSON.stringify(list));
70
+ }
71
+ else {
72
+ window.localStorage.removeItem(ACTIVE_WORKSPACE_KEY);
73
+ }
74
+ }
75
+ catch {
76
+ /* ignore storage errors */
77
+ }
78
+ notify();
79
+ }
80
+ /** Add a local workspace */
81
+ export function addLocalWorkspace(path, name) {
82
+ const cleanPath = path.trim().replace(/\/+$/, '');
83
+ const folderName = name?.trim() || cleanPath.split(/[/\\]/).pop() || 'workspace';
84
+ const list = getLocalWorkspaces();
85
+ const existing = list.find((w) => w.path === cleanPath);
86
+ if (existing) {
87
+ setActiveWorkspace(existing);
88
+ return existing;
89
+ }
90
+ const ws = {
91
+ id: `ws_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`,
92
+ name: folderName,
93
+ path: cleanPath,
94
+ addedAt: Date.now(),
95
+ lastOpenedAt: Date.now(),
96
+ };
97
+ try {
98
+ window.localStorage.setItem(WORKSPACES_KEY, JSON.stringify([ws, ...list]));
99
+ window.localStorage.setItem(ACTIVE_WORKSPACE_KEY, ws.id);
100
+ }
101
+ catch {
102
+ /* ignore storage errors */
103
+ }
104
+ notify();
105
+ return ws;
106
+ }
107
+ /** Remove a local workspace */
108
+ export function removeLocalWorkspace(idOrPath) {
109
+ const list = getLocalWorkspaces().filter((w) => w.id !== idOrPath && w.path !== idOrPath);
110
+ try {
111
+ window.localStorage.setItem(WORKSPACES_KEY, JSON.stringify(list));
112
+ const current = window.localStorage.getItem(ACTIVE_WORKSPACE_KEY);
113
+ if (current === idOrPath) {
114
+ if (list[0])
115
+ window.localStorage.setItem(ACTIVE_WORKSPACE_KEY, list[0].id);
116
+ else
117
+ window.localStorage.removeItem(ACTIVE_WORKSPACE_KEY);
118
+ }
119
+ }
120
+ catch {
121
+ /* ignore storage errors */
122
+ }
123
+ notify();
124
+ }
125
+ /** Open native dialog to pick a local folder */
126
+ export async function pickLocalFolder() {
127
+ if (isTauri()) {
128
+ try {
129
+ const selected = await tauriInvoke('local_workspace_open_dialog');
130
+ if (selected && typeof selected === 'string') {
131
+ return addLocalWorkspace(selected);
132
+ }
133
+ }
134
+ catch (e) {
135
+ console.warn('local_workspace_open_dialog failed, falling back:', e);
136
+ }
137
+ }
138
+ // Browser File System Access API
139
+ if (typeof window !== 'undefined' && 'showDirectoryPicker' in window) {
140
+ try {
141
+ const picker = window.showDirectoryPicker;
142
+ const handle = await picker();
143
+ if (handle?.name) {
144
+ return addLocalWorkspace(`/${handle.name}`, handle.name);
145
+ }
146
+ }
147
+ catch (e) {
148
+ if (e?.name === 'AbortError')
149
+ return null;
150
+ console.warn('showDirectoryPicker failed:', e);
151
+ }
152
+ }
153
+ return null;
154
+ }
155
+ /** Open native dialog to pick a local file to view or edit */
156
+ export async function pickLocalFile() {
157
+ if (isTauri()) {
158
+ try {
159
+ const selected = await tauriInvoke('local_workspace_open_file_dialog');
160
+ if (selected && typeof selected === 'string') {
161
+ return selected;
162
+ }
163
+ }
164
+ catch (e) {
165
+ console.warn('local_workspace_open_file_dialog failed:', e);
166
+ }
167
+ }
168
+ return null;
169
+ }
170
+ /** Clone a remote repository to local machine and register as a workspace */
171
+ export async function cloneRemoteRepo(repo, targetDir) {
172
+ if (isTauri()) {
173
+ const res = await tauriInvoke('local_workspace_clone_repo', {
174
+ repo,
175
+ targetDir,
176
+ });
177
+ return addLocalWorkspace(res.path, res.name);
178
+ }
179
+ throw new Error('Cloning remote repositories locally requires Hanzo Desktop');
180
+ }
181
+ /** Import an existing local file into the active workspace directory */
182
+ export async function importLocalFile(sourcePath, targetDir) {
183
+ if (isTauri()) {
184
+ return await tauriInvoke('local_workspace_import_file', {
185
+ sourcePath,
186
+ targetDir,
187
+ });
188
+ }
189
+ throw new Error('Importing files requires Hanzo Desktop');
190
+ }
191
+ /** List entries in a local directory */
192
+ export async function listLocalEntries(dirPath) {
193
+ if (isTauri()) {
194
+ try {
195
+ return await tauriInvoke('local_workspace_list', { dirPath });
196
+ }
197
+ catch (e) {
198
+ console.warn('local_workspace_list failed:', e);
199
+ }
200
+ }
201
+ return [];
202
+ }
203
+ /** Read text content of a local file */
204
+ export async function readLocalFile(filePath) {
205
+ if (isTauri()) {
206
+ return await tauriInvoke('local_workspace_read_file', { filePath });
207
+ }
208
+ throw new Error('Local file reading requires Hanzo Desktop');
209
+ }
210
+ /** Write text content to a local file */
211
+ export async function writeLocalFile(filePath, content) {
212
+ if (isTauri()) {
213
+ await tauriInvoke('local_workspace_write_file', { filePath, content });
214
+ return;
215
+ }
216
+ throw new Error('Local file writing requires Hanzo Desktop');
217
+ }
218
+ /** Create a new empty file */
219
+ export async function createLocalFile(dirPath, name, content = '') {
220
+ const separator = dirPath.includes('\\') ? '\\' : '/';
221
+ const filePath = `${dirPath.replace(/[/\\]+$/, '')}${separator}${name.trim()}`;
222
+ if (isTauri()) {
223
+ await tauriInvoke('local_workspace_create_file', { filePath, content });
224
+ return filePath;
225
+ }
226
+ throw new Error('Local file creation requires Hanzo Desktop');
227
+ }
228
+ /** Create a new local directory */
229
+ export async function createLocalDir(dirPath, name) {
230
+ const separator = dirPath.includes('\\') ? '\\' : '/';
231
+ const newDirPath = `${dirPath.replace(/[/\\]+$/, '')}${separator}${name.trim()}`;
232
+ if (isTauri()) {
233
+ await tauriInvoke('local_workspace_create_dir', { dirPath: newDirPath });
234
+ return newDirPath;
235
+ }
236
+ throw new Error('Local folder creation requires Hanzo Desktop');
237
+ }
238
+ /** Delete a local file or directory */
239
+ export async function deleteLocalPath(path) {
240
+ if (isTauri()) {
241
+ await tauriInvoke('local_workspace_delete', { path });
242
+ return;
243
+ }
244
+ throw new Error('Local deletion requires Hanzo Desktop');
245
+ }
246
+ /** Run local coding task with `dev` CLI */
247
+ export async function runLocalDev(workspacePath, prompt) {
248
+ if (isTauri()) {
249
+ return await tauriInvoke('local_workspace_run_dev', {
250
+ workspacePath,
251
+ prompt,
252
+ });
253
+ }
254
+ throw new Error('Local Dev agent execution requires Hanzo Desktop');
255
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/app",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",