@hanzo/app 0.2.19 → 0.2.20

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, 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 { createLocalDir, createLocalFile, deleteLocalPath, getActiveWorkspace, getLocalWorkspaces, listLocalEntries, 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,46 @@ 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
+ }
424
+ }, [navSection, activeWs, localPrefix, loadLocalEntries]);
360
425
  const handleRename = useCallback((entry, to) => {
361
426
  const clean = to.trim().replace(/^\/+|\/+$/g, '');
362
427
  if (!clean || !client || !activeBucket || entry.isDir)
@@ -489,20 +554,38 @@ export function Drive() {
489
554
  z: 'var(--z-drawer)',
490
555
  overflowY: 'auto',
491
556
  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: [
557
+ }, 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: () => {
558
+ setNewMenuOpen(false);
559
+ setMenu(false);
560
+ setNaming({ kind: 'file', value: '' });
561
+ }, children: [_jsx(FilePlus, { size: 14 }), "New file"] }), _jsxs(Button, { ...ITEM, onClick: () => {
562
+ setNewMenuOpen(false);
563
+ setMenu(false);
564
+ setNaming({ kind: 'folder', value: '' });
565
+ }, children: [_jsx(FolderPlus, { size: 14 }), "New folder"] }), _jsx(View, { height: 1, bg: "$borderColor", my: 4 }), _jsxs(Button, { ...ITEM, onClick: () => {
566
+ setNewMenuOpen(false);
567
+ setMenu(false);
568
+ void pickLocalFolder().then((ws) => {
569
+ if (ws) {
570
+ setNavSection('local');
571
+ setLocalPrefix('');
572
+ }
573
+ });
574
+ }, children: [_jsx(FolderInput, { size: 14 }), "Open local folder\u2026"] })] })) : (_jsxs(_Fragment, { children: [_jsxs(Button, { ...ITEM, onClick: () => {
575
+ setNewMenuOpen(false);
576
+ setMenu(false);
577
+ setNaming({ kind: 'folder', value: '' });
578
+ }, children: [_jsx(FolderPlus, { size: 14 }), "New folder"] }), _jsx(View, { height: 1, bg: "$borderColor", my: 4 }), _jsxs(Button, { ...ITEM, onClick: () => {
579
+ setNewMenuOpen(false);
580
+ setMenu(false);
581
+ fileInputRef.current?.click();
582
+ }, children: [_jsx(Upload, { size: 14 }), "File upload"] }), _jsxs(Button, { ...ITEM, onClick: () => {
583
+ setNewMenuOpen(false);
584
+ setMenu(false);
585
+ folderInputRef.current?.click();
586
+ }, children: [_jsx(FolderInput, { size: 14 }), "Folder upload"] })] })) })) : null] }), _jsx(YStack, { gap: "$1", children: [
505
587
  { id: 'my-drive', label: 'My Drive', icon: HardDrive },
588
+ { id: 'local', label: 'Local Folders', icon: Laptop },
506
589
  { id: 'recent', label: 'Recent', icon: Clock },
507
590
  ].map((item) => {
508
591
  const isActive = navSection === item.id && !bucket && !prefix;
@@ -513,19 +596,87 @@ export function Drive() {
513
596
  setPrefix('');
514
597
  setMenu(false);
515
598
  }, 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: () => {
599
+ }) }), 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) => {
600
+ const isCur = navSection === 'local' && activeWs?.id === ws.id;
601
+ return (_jsxs(XStack, { items: "center", justify: "space-between", px: "$2", py: "$1", rounded: 6, bg: isCur ? '$hover' : 'transparent', hoverStyle: { bg: '$hover' }, cursor: "pointer", onPress: () => {
602
+ setActiveWorkspace(ws);
603
+ setNavSection('local');
604
+ setLocalPrefix('');
605
+ }, 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) => {
606
+ e.stopPropagation();
607
+ removeLocalWorkspace(ws.id);
608
+ }, title: "Remove", children: _jsx(Trash2, { size: 11, color: "var(--muted-foreground)" }) })] }, ws.id));
609
+ }), _jsxs(Button, { variant: "ghost", size: "sm", justify: "flex-start", gap: 6, px: 8, py: 4, color: "$soft", onClick: () => {
610
+ void pickLocalFolder().then((ws) => {
611
+ if (ws) {
612
+ setNavSection('local');
613
+ setLocalPrefix('');
614
+ }
615
+ });
616
+ }, 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: () => {
617
+ setLocalPrefix('');
618
+ }, children: "Local Folders" }), _jsx(ChevronRight, { size: 13, color: "var(--muted-foreground)" }), _jsx(Button, { ...CRUMB, color: !localPrefix ? '$ink' : '$soft', onClick: () => setLocalPrefix(''), children: activeWs.name }), localPrefix
619
+ ? 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}`)))
620
+ : null] })) : bucket || prefix ? (_jsxs(XStack, { items: "center", gap: "$2", pb: "$2", borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Button, { ...CRUMB, color: "$soft", onClick: () => {
517
621
  openBucket(null);
518
622
  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: [
623
+ }, 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'
624
+ ? activeWs
625
+ ? activeWs.path
626
+ : 'Edit local files, add files & folders, and code locally.'
627
+ : 'Secure. Private. Built for builders.' })] }), _jsx(XStack, { items: "center", bg: "$panel", rounded: 8, borderWidth: 1, borderColor: "$borderColor", p: 2, gap: 2, children: [
520
628
  ['list', 'List View', List],
521
629
  ['grid', 'Grid View', LayoutGrid],
522
630
  ['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) => {
631
+ ].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)" })) : (_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
632
  if (e.key === 'Escape')
525
633
  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) => {
634
+ if (e.key === 'Enter') {
635
+ if (naming.kind === 'file')
636
+ handleCreateFile(naming.value);
637
+ else
638
+ handleCreateFolder(naming.value);
639
+ }
640
+ }, placeholder: naming.kind === 'file' ? 'File name (e.g. index.ts)' : 'Folder name', "aria-label": naming.kind === 'file' ? 'File name' : 'Folder name' }), ...BARE }), _jsx(Button, { variant: "primary", size: "sm", onClick: () => {
641
+ if (naming.kind === 'file')
642
+ handleCreateFile(naming.value);
643
+ else
644
+ handleCreateFolder(naming.value);
645
+ }, children: "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: () => {
646
+ setEditingFile(null);
647
+ loadLocalEntries();
648
+ }, onAskInChat: () => {
649
+ setEditingFile(null);
650
+ router.push('/chat');
651
+ } })) : 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(Button, { onClick: () => {
652
+ void pickLocalFolder().then((ws) => {
653
+ if (ws) {
654
+ setNavSection('local');
655
+ setLocalPrefix('');
656
+ }
657
+ });
658
+ }, children: [_jsx(FolderPlus, { size: 16 }), "Open Local Folder\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(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) => {
659
+ const ext = e.name.split('.').pop() || '';
660
+ 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: () => {
661
+ if (e.isDir) {
662
+ setLocalPrefix(localPrefix ? `${localPrefix}/${e.name}` : e.name);
663
+ }
664
+ else {
665
+ setEditingFile({ path: e.path, name: e.name });
666
+ }
667
+ }, 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) => {
668
+ evt.stopPropagation();
669
+ setItemMenuKey(itemMenuKey === e.path ? null : e.path);
670
+ } }), 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: () => {
671
+ setItemMenuKey(null);
672
+ setEditingFile({ path: e.path, name: e.name });
673
+ } })) : null, _jsx(Pick, { icon: Trash2, label: "Delete", tone: BAD, onPress: () => {
674
+ setItemMenuKey(null);
675
+ deleteLocalPath(e.path)
676
+ .then(() => loadLocalEntries())
677
+ .catch((err) => setFailed(blame(err)));
678
+ } })] })) : null] })] }, e.path));
679
+ }))] })] }))) : 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
680
  const isFolder = e.isDir || e.key.endsWith('/');
530
681
  const cleanName = e.key.replace(/\/+$/, '');
531
682
  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,56 @@
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
+ /** List entries in a local directory */
41
+ export declare function listLocalEntries(dirPath: string): Promise<LocalEntry[]>;
42
+ /** Read text content of a local file */
43
+ export declare function readLocalFile(filePath: string): Promise<string>;
44
+ /** Write text content to a local file */
45
+ export declare function writeLocalFile(filePath: string, content: string): Promise<void>;
46
+ /** Create a new empty file */
47
+ export declare function createLocalFile(dirPath: string, name: string, content?: string): Promise<string>;
48
+ /** Create a new local directory */
49
+ export declare function createLocalDir(dirPath: string, name: string): Promise<string>;
50
+ /** Delete a local file or directory */
51
+ export declare function deleteLocalPath(path: string): Promise<void>;
52
+ /** Run local coding task with `dev` CLI */
53
+ export declare function runLocalDev(workspacePath: string, prompt: string): Promise<{
54
+ sessionId: string;
55
+ output?: string;
56
+ }>;
@@ -0,0 +1,219 @@
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
+ /** List entries in a local directory */
156
+ export async function listLocalEntries(dirPath) {
157
+ if (isTauri()) {
158
+ try {
159
+ return await tauriInvoke('local_workspace_list', { dirPath });
160
+ }
161
+ catch (e) {
162
+ console.warn('local_workspace_list failed:', e);
163
+ }
164
+ }
165
+ return [];
166
+ }
167
+ /** Read text content of a local file */
168
+ export async function readLocalFile(filePath) {
169
+ if (isTauri()) {
170
+ return await tauriInvoke('local_workspace_read_file', { filePath });
171
+ }
172
+ throw new Error('Local file reading requires Hanzo Desktop');
173
+ }
174
+ /** Write text content to a local file */
175
+ export async function writeLocalFile(filePath, content) {
176
+ if (isTauri()) {
177
+ await tauriInvoke('local_workspace_write_file', { filePath, content });
178
+ return;
179
+ }
180
+ throw new Error('Local file writing requires Hanzo Desktop');
181
+ }
182
+ /** Create a new empty file */
183
+ export async function createLocalFile(dirPath, name, content = '') {
184
+ const separator = dirPath.includes('\\') ? '\\' : '/';
185
+ const filePath = `${dirPath.replace(/[/\\]+$/, '')}${separator}${name.trim()}`;
186
+ if (isTauri()) {
187
+ await tauriInvoke('local_workspace_create_file', { filePath, content });
188
+ return filePath;
189
+ }
190
+ throw new Error('Local file creation requires Hanzo Desktop');
191
+ }
192
+ /** Create a new local directory */
193
+ export async function createLocalDir(dirPath, name) {
194
+ const separator = dirPath.includes('\\') ? '\\' : '/';
195
+ const newDirPath = `${dirPath.replace(/[/\\]+$/, '')}${separator}${name.trim()}`;
196
+ if (isTauri()) {
197
+ await tauriInvoke('local_workspace_create_dir', { dirPath: newDirPath });
198
+ return newDirPath;
199
+ }
200
+ throw new Error('Local folder creation requires Hanzo Desktop');
201
+ }
202
+ /** Delete a local file or directory */
203
+ export async function deleteLocalPath(path) {
204
+ if (isTauri()) {
205
+ await tauriInvoke('local_workspace_delete', { path });
206
+ return;
207
+ }
208
+ throw new Error('Local deletion requires Hanzo Desktop');
209
+ }
210
+ /** Run local coding task with `dev` CLI */
211
+ export async function runLocalDev(workspacePath, prompt) {
212
+ if (isTauri()) {
213
+ return await tauriInvoke('local_workspace_run_dev', {
214
+ workspacePath,
215
+ prompt,
216
+ });
217
+ }
218
+ throw new Error('Local Dev agent execution requires Hanzo Desktop');
219
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/app",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
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",