khal-os 1.260324.2
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/.env.example +23 -0
- package/.genie/mailbox/cli-sent.jsonl +3 -0
- package/.genie/mailbox/ds1-wave2-engineer-1.json +15 -0
- package/.genie/mailbox/ds1-wave2-engineer-2.json +15 -0
- package/.genie/mailbox/ds1-wave2-engineer-3.json +15 -0
- package/.genie/state/os-observability.json +39 -0
- package/.genie/state/tmux-control-mode-terminal.json +28 -0
- package/.genie/wishes/genieos-one-theme/WISH.md +417 -0
- package/.genie/wishes/workos-prod-rbac/WISH.md +345 -0
- package/.github/workflows/ci.yml +39 -0
- package/.github/workflows/release.yml +78 -0
- package/.github/workflows/version.yml +122 -0
- package/.husky/pre-commit +1 -0
- package/.pnpm-approve-builds.json +1 -0
- package/CLAUDE.md +117 -0
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/biome.json +124 -0
- package/bun.lock +1249 -0
- package/docs/workos-setup.md +116 -0
- package/ecosystem.config.cjs +26 -0
- package/instrumentation.ts +8 -0
- package/knip.json +35 -0
- package/nats.conf +7 -0
- package/next.config.ts +25 -0
- package/package.json +78 -0
- package/packages/dev3000-app/components.ts +12 -0
- package/packages/dev3000-app/manifest.ts +19 -0
- package/packages/dev3000-app/package.json +23 -0
- package/packages/dev3000-app/views/dev3000/Dev3000App.tsx +758 -0
- package/packages/dev3000-app/views/dev3000/ErrorsPanel.tsx +160 -0
- package/packages/dev3000-app/views/dev3000/dev3000-context.tsx +21 -0
- package/packages/dev3000-app/views/dev3000/index.ts +4 -0
- package/packages/dev3000-app/views/dev3000/schema.ts +55 -0
- package/packages/dev3000-app/views/dev3000/service/index.ts +358 -0
- package/packages/dev3000-app/views/dev3000/service/runtime +1 -0
- package/packages/dev3000-app/views/dev3000/subjects.ts +9 -0
- package/packages/dev3000-app/views/dev3000/types.ts +77 -0
- package/packages/files-app/components.ts +12 -0
- package/packages/files-app/manifest.ts +19 -0
- package/packages/files-app/package.json +23 -0
- package/packages/files-app/views/files/ContextMenu.tsx +151 -0
- package/packages/files-app/views/files/DeleteConfirmDialog.tsx +39 -0
- package/packages/files-app/views/files/FileItem.tsx +128 -0
- package/packages/files-app/views/files/FilesApp.tsx +509 -0
- package/packages/files-app/views/files/FilesListView.tsx +201 -0
- package/packages/files-app/views/files/FilesToolbar.tsx +117 -0
- package/packages/files-app/views/files/GridView.tsx +90 -0
- package/packages/files-app/views/files/InlineInput.tsx +131 -0
- package/packages/files-app/views/files/UploadOverlay.tsx +61 -0
- package/packages/files-app/views/files/schema.ts +49 -0
- package/packages/files-app/views/files/service/index.ts +184 -0
- package/packages/files-app/views/files/service/runtime +1 -0
- package/packages/files-app/views/files/use-files.ts +201 -0
- package/packages/files-app/views/files/use-upload.ts +105 -0
- package/packages/genie-app/components.ts +12 -0
- package/packages/genie-app/lib/subjects.ts +87 -0
- package/packages/genie-app/manifest.ts +19 -0
- package/packages/genie-app/package.json +29 -0
- package/packages/genie-app/views/genie/service/agent-lifecycle.ts +136 -0
- package/packages/genie-app/views/genie/service/cli.ts +114 -0
- package/packages/genie-app/views/genie/service/comms.ts +141 -0
- package/packages/genie-app/views/genie/service/directory.ts +167 -0
- package/packages/genie-app/views/genie/service/index.ts +219 -0
- package/packages/genie-app/views/genie/service/system.ts +123 -0
- package/packages/genie-app/views/genie/service/teams.ts +191 -0
- package/packages/genie-app/views/genie/service/terminal-proxy.ts +184 -0
- package/packages/genie-app/views/genie/service/tmux-control.ts +318 -0
- package/packages/genie-app/views/genie/service/wishes.ts +270 -0
- package/packages/genie-app/views/genie/ui/GenieApp.tsx +5 -0
- package/packages/genie-app/views/genie/ui/PaneCard.tsx +307 -0
- package/packages/genie-app/views/genie/ui/Sidebar.tsx +212 -0
- package/packages/genie-app/views/genie/ui/TabBar.tsx +70 -0
- package/packages/genie-app/views/genie/ui/WorkspaceCanvas.tsx +343 -0
- package/packages/genie-app/views/genie/ui/XTermPane.tsx +306 -0
- package/packages/genie-app/views/genie/ui/hooks/useNatsAction.ts +54 -0
- package/packages/genie-app/views/genie/ui/hooks/useNatsRequest.ts +68 -0
- package/packages/genie-app/views/genie/ui/panels/AgentsPanel.tsx +399 -0
- package/packages/genie-app/views/genie/ui/panels/ChatPanel.tsx +351 -0
- package/packages/genie-app/views/genie/ui/panels/SystemPanel.tsx +195 -0
- package/packages/genie-app/views/genie/ui/panels/TeamsPanel.tsx +560 -0
- package/packages/genie-app/views/genie/ui/panels/WishesPanel.tsx +424 -0
- package/packages/nats-viewer-app/components.ts +12 -0
- package/packages/nats-viewer-app/manifest.ts +18 -0
- package/packages/nats-viewer-app/package.json +14 -0
- package/packages/nats-viewer-app/views/nats-viewer/ActiveSubs.tsx +34 -0
- package/packages/nats-viewer-app/views/nats-viewer/MessageLog.tsx +247 -0
- package/packages/nats-viewer-app/views/nats-viewer/NatsViewer.tsx +209 -0
- package/packages/nats-viewer-app/views/nats-viewer/PublishPanel.tsx +111 -0
- package/packages/nats-viewer-app/views/nats-viewer/RequestPanel.tsx +165 -0
- package/packages/nats-viewer-app/views/nats-viewer/Sidebar.tsx +59 -0
- package/packages/nats-viewer-app/views/nats-viewer/SubjectCatalog.tsx +63 -0
- package/packages/nats-viewer-app/views/nats-viewer/SubscribeInput.tsx +59 -0
- package/packages/nats-viewer-app/views/nats-viewer/index.ts +5 -0
- package/packages/nats-viewer-app/views/nats-viewer/nats-viewer-context.tsx +31 -0
- package/packages/nats-viewer-app/views/nats-viewer/types.ts +7 -0
- package/packages/nats-viewer-app/views/nats-viewer/use-message-buffer.ts +55 -0
- package/packages/os-cli/package.json +18 -0
- package/packages/os-cli/src/commands/events.ts +176 -0
- package/packages/os-cli/src/commands/logs.ts +96 -0
- package/packages/os-cli/src/commands/status.ts +53 -0
- package/packages/os-cli/src/commands/traces.ts +115 -0
- package/packages/os-cli/src/index.ts +15 -0
- package/packages/os-cli/src/lib/formatter.ts +123 -0
- package/packages/os-cli/src/lib/nats.ts +16 -0
- package/packages/os-cli/src/lib/trace-tree.ts +144 -0
- package/packages/os-cli/tsconfig.json +12 -0
- package/packages/os-sdk/package.json +27 -0
- package/packages/os-sdk/src/api/handler.ts +67 -0
- package/packages/os-sdk/src/config.ts +68 -0
- package/packages/os-sdk/src/db/factory.test.ts +42 -0
- package/packages/os-sdk/src/db/factory.ts +72 -0
- package/packages/os-sdk/src/db/migrate.ts +140 -0
- package/packages/os-sdk/src/db/provision.ts +44 -0
- package/packages/os-sdk/src/index.ts +36 -0
- package/packages/os-sdk/src/service/console-intercept.ts +60 -0
- package/packages/os-sdk/src/service/logger.ts +88 -0
- package/packages/os-sdk/src/service/o11y-streams.ts +88 -0
- package/packages/os-sdk/src/service/runtime.ts +259 -0
- package/packages/os-sdk/src/service/trace.ts +71 -0
- package/packages/os-sdk/tsconfig.json +16 -0
- package/packages/os-ui/package.json +13 -0
- package/packages/os-ui/src/index.ts +29 -0
- package/packages/os-ui/src/server.ts +4 -0
- package/packages/os-ui/tsconfig.json +19 -0
- package/packages/settings-app/components.ts +12 -0
- package/packages/settings-app/manifest.ts +18 -0
- package/packages/settings-app/package.json +14 -0
- package/packages/settings-app/views/settings/Settings.tsx +492 -0
- package/packages/terminal-app/components.ts +12 -0
- package/packages/terminal-app/manifest.ts +20 -0
- package/packages/terminal-app/package.json +23 -0
- package/packages/terminal-app/views/terminal/schema.ts +82 -0
- package/packages/terminal-app/views/terminal/service/index.ts +133 -0
- package/packages/terminal-app/views/terminal/service/runtime +1 -0
- package/packages/terminal-app/views/terminal/service/session.ts +290 -0
- package/packages/terminal-app/views/terminal/service/shell-hooks/bashrc-hook.sh +21 -0
- package/packages/terminal-app/views/terminal/types.ts +26 -0
- package/packages/terminal-app/views/terminal/ui/MultiTerminalApp.tsx +615 -0
- package/packages/terminal-app/views/terminal/ui/SplitDragHandle.tsx +91 -0
- package/packages/terminal-app/views/terminal/ui/SplitPaneRenderer.tsx +112 -0
- package/packages/terminal-app/views/terminal/ui/TerminalPane.tsx +478 -0
- package/packages/terminal-app/views/terminal/ui/TerminalTabBar.tsx +131 -0
- package/pnpm-workspace.yaml +9 -0
- package/postcss.config.mjs +7 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/icons/code-server.svg +6 -0
- package/public/icons/default.svg +5 -0
- package/public/icons/dusk/1password.svg +1 -0
- package/public/icons/dusk/activity_monitor.svg +1 -0
- package/public/icons/dusk/app_store.svg +1 -0
- package/public/icons/dusk/atom.svg +1 -0
- package/public/icons/dusk/brave.svg +1 -0
- package/public/icons/dusk/calculator.svg +1 -0
- package/public/icons/dusk/calendar.svg +1 -0
- package/public/icons/dusk/chrome.svg +1 -0
- package/public/icons/dusk/chrome2.svg +1 -0
- package/public/icons/dusk/dashboard.svg +13 -0
- package/public/icons/dusk/discord.svg +1 -0
- package/public/icons/dusk/dropbox.svg +1 -0
- package/public/icons/dusk/electron.svg +1 -0
- package/public/icons/dusk/figma.svg +1 -0
- package/public/icons/dusk/finder.svg +1 -0
- package/public/icons/dusk/finder2.svg +1 -0
- package/public/icons/dusk/finder3.svg +1 -0
- package/public/icons/dusk/firefox.svg +1 -0
- package/public/icons/dusk/framer.svg +1 -0
- package/public/icons/dusk/gimp.svg +1 -0
- package/public/icons/dusk/github_desktop.svg +1 -0
- package/public/icons/dusk/hyper.svg +1 -0
- package/public/icons/dusk/hyper3.svg +1 -0
- package/public/icons/dusk/intellij.svg +1 -0
- package/public/icons/dusk/iterm2.svg +1 -0
- package/public/icons/dusk/itunes.svg +1 -0
- package/public/icons/dusk/mail.svg +1 -0
- package/public/icons/dusk/messenger.svg +1 -0
- package/public/icons/dusk/mongodb.svg +1 -0
- package/public/icons/dusk/notes.svg +1 -0
- package/public/icons/dusk/notion.svg +1 -0
- package/public/icons/dusk/obs.svg +1 -0
- package/public/icons/dusk/pages.svg +1 -0
- package/public/icons/dusk/photos.svg +1 -0
- package/public/icons/dusk/postman.svg +1 -0
- package/public/icons/dusk/preview.svg +1 -0
- package/public/icons/dusk/reminders.svg +1 -0
- package/public/icons/dusk/safari.svg +1 -0
- package/public/icons/dusk/sequel_pro.svg +1 -0
- package/public/icons/dusk/sketch.svg +1 -0
- package/public/icons/dusk/skype.svg +1 -0
- package/public/icons/dusk/slack.svg +1 -0
- package/public/icons/dusk/slack2.svg +1 -0
- package/public/icons/dusk/spotify.svg +1 -0
- package/public/icons/dusk/steam.svg +1 -0
- package/public/icons/dusk/system_preferences.svg +1 -0
- package/public/icons/dusk/tableplus.svg +1 -0
- package/public/icons/dusk/teams.svg +1 -0
- package/public/icons/dusk/telegram.svg +1 -0
- package/public/icons/dusk/terminal.svg +1 -0
- package/public/icons/dusk/todoist.svg +1 -0
- package/public/icons/dusk/trash.svg +1 -0
- package/public/icons/dusk/trello.svg +1 -0
- package/public/icons/dusk/vivaldi.svg +1 -0
- package/public/icons/dusk/vlc.svg +1 -0
- package/public/icons/dusk/vscode.svg +1 -0
- package/public/icons/dusk/whatsapp.svg +1 -0
- package/public/icons/dusk/xeyes.svg +1 -0
- package/public/icons/dusk/zoom.svg +1 -0
- package/public/icons/files.svg +5 -0
- package/public/icons/pwa/icon-192.png +0 -0
- package/public/icons/pwa/icon-512.png +0 -0
- package/public/icons/settings.svg +14 -0
- package/public/icons/terminal.svg +5 -0
- package/public/icons/text-editor.svg +7 -0
- package/public/manifest.json +38 -0
- package/public/next.svg +1 -0
- package/public/sw.js +41 -0
- package/public/vercel.svg +1 -0
- package/public/wallpapers/default.svg +10 -0
- package/public/window.svg +1 -0
- package/scripts/generate-pwa-icons.mjs +33 -0
- package/scripts/install-nats.sh +37 -0
- package/sentry.client.config.ts +21 -0
- package/sentry.edge.config.ts +12 -0
- package/sentry.server.config.ts +12 -0
- package/src/app/api/files/download/route.ts +81 -0
- package/src/app/api/files/download-zip/route.ts +102 -0
- package/src/app/api/files/upload/route.ts +58 -0
- package/src/app/api/webhooks/workos/route.ts +98 -0
- package/src/app/auth/callback/route.ts +16 -0
- package/src/app/auth/logout/route.ts +15 -0
- package/src/app/desktop/desktop-shell.tsx +110 -0
- package/src/app/desktop/layout.tsx +8 -0
- package/src/app/desktop/page.tsx +24 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +7 -0
- package/src/app/layout.tsx +64 -0
- package/src/app/offline/page.tsx +83 -0
- package/src/app/page.tsx +5 -0
- package/src/app/standalone/[appId]/page.tsx +28 -0
- package/src/app/standalone/layout.tsx +10 -0
- package/src/components/app-icon.tsx +55 -0
- package/src/components/apps/_echo/schema.ts +14 -0
- package/src/components/apps/_echo/service/index.ts +42 -0
- package/src/components/apps/app-manifest.ts +97 -0
- package/src/components/apps/app-registry.ts +55 -0
- package/src/components/apps/dev3000/Dev3000App.tsx +224 -0
- package/src/components/apps/dev3000/ErrorsPanel.tsx +160 -0
- package/src/components/apps/dev3000/Sidebar.tsx +41 -0
- package/src/components/apps/dev3000/TimelineLog.tsx +173 -0
- package/src/components/apps/dev3000/dev3000-context.tsx +29 -0
- package/src/components/apps/dev3000/index.ts +4 -0
- package/src/components/apps/dev3000/schema.ts +48 -0
- package/src/components/apps/dev3000/service/index.ts +520 -0
- package/src/components/apps/dev3000/service/runtime +1 -0
- package/src/components/apps/dev3000/types.ts +15 -0
- package/src/components/apps/dev3000/use-message-buffer.ts +46 -0
- package/src/components/apps/files/ContextMenu.tsx +151 -0
- package/src/components/apps/files/DeleteConfirmDialog.tsx +78 -0
- package/src/components/apps/files/FileItem.tsx +128 -0
- package/src/components/apps/files/FilesApp.tsx +509 -0
- package/src/components/apps/files/FilesListView.tsx +201 -0
- package/src/components/apps/files/FilesToolbar.tsx +117 -0
- package/src/components/apps/files/GridView.tsx +90 -0
- package/src/components/apps/files/InlineInput.tsx +131 -0
- package/src/components/apps/files/UploadOverlay.tsx +61 -0
- package/src/components/apps/files/schema.ts +49 -0
- package/src/components/apps/files/service/index.ts +227 -0
- package/src/components/apps/files/service/runtime +1 -0
- package/src/components/apps/files/use-files.ts +201 -0
- package/src/components/apps/files/use-upload.ts +105 -0
- package/src/components/apps/nats-viewer/ActiveSubs.tsx +34 -0
- package/src/components/apps/nats-viewer/MessageLog.tsx +247 -0
- package/src/components/apps/nats-viewer/NatsViewer.tsx +209 -0
- package/src/components/apps/nats-viewer/PublishPanel.tsx +113 -0
- package/src/components/apps/nats-viewer/RequestPanel.tsx +167 -0
- package/src/components/apps/nats-viewer/Sidebar.tsx +62 -0
- package/src/components/apps/nats-viewer/SubjectCatalog.tsx +64 -0
- package/src/components/apps/nats-viewer/SubscribeInput.tsx +59 -0
- package/src/components/apps/nats-viewer/index.ts +5 -0
- package/src/components/apps/nats-viewer/nats-viewer-context.tsx +31 -0
- package/src/components/apps/nats-viewer/types.ts +7 -0
- package/src/components/apps/nats-viewer/use-message-buffer.ts +55 -0
- package/src/components/apps/settings/Settings.tsx +492 -0
- package/src/components/apps/terminal/schema.ts +82 -0
- package/src/components/apps/terminal/service/index.ts +189 -0
- package/src/components/apps/terminal/service/runtime +1 -0
- package/src/components/apps/terminal/service/session.ts +296 -0
- package/src/components/apps/terminal/service/shell-hooks/bashrc-hook.sh +21 -0
- package/src/components/apps/terminal/types.ts +26 -0
- package/src/components/apps/terminal/ui/MultiTerminalApp.tsx +617 -0
- package/src/components/apps/terminal/ui/SplitDragHandle.tsx +91 -0
- package/src/components/apps/terminal/ui/SplitPaneRenderer.tsx +112 -0
- package/src/components/apps/terminal/ui/TerminalPane.tsx +476 -0
- package/src/components/apps/terminal/ui/TerminalTabBar.tsx +131 -0
- package/src/components/desktop/AnimatedBackground.tsx +69 -0
- package/src/components/desktop/Desktop.tsx +79 -0
- package/src/components/desktop/DesktopBackground.tsx +16 -0
- package/src/components/desktop/DesktopIcon.tsx +49 -0
- package/src/components/desktop/ShortcutViewer.tsx +136 -0
- package/src/components/desktop/WindowRenderer.tsx +34 -0
- package/src/components/desktop/WindowSwitcher.tsx +42 -0
- package/src/components/notifications/NotificationCenter.tsx +153 -0
- package/src/components/notifications/NotificationToasts.tsx +66 -0
- package/src/components/notifications/OrphanSessionToast.tsx +293 -0
- package/src/components/os-primitives/collapsible-sidebar.tsx +226 -0
- package/src/components/os-primitives/dialog.tsx +76 -0
- package/src/components/os-primitives/empty-state.tsx +43 -0
- package/src/components/os-primitives/index.ts +21 -0
- package/src/components/os-primitives/list-view.tsx +155 -0
- package/src/components/os-primitives/property-panel.tsx +108 -0
- package/src/components/os-primitives/section-header.tsx +19 -0
- package/src/components/os-primitives/sidebar-nav.tsx +110 -0
- package/src/components/os-primitives/split-pane.tsx +146 -0
- package/src/components/os-primitives/status-badge.tsx +10 -0
- package/src/components/os-primitives/status-bar.tsx +100 -0
- package/src/components/os-primitives/toolbar.tsx +152 -0
- package/src/components/taskbar/AppLauncher.tsx +114 -0
- package/src/components/taskbar/RunningApps.tsx +71 -0
- package/src/components/taskbar/SystemTray.tsx +134 -0
- package/src/components/taskbar/Taskbar.tsx +45 -0
- package/src/components/taskbar/UserMenu.tsx +138 -0
- package/src/components/taskbar/WorkspaceSwitcher.tsx +9 -0
- package/src/components/ui/ContextMenu.tsx +130 -0
- package/src/components/ui/badge.tsx +39 -0
- package/src/components/ui/button.tsx +102 -0
- package/src/components/ui/command.tsx +165 -0
- package/src/components/ui/dropdown-menu.tsx +233 -0
- package/src/components/ui/input.tsx +48 -0
- package/src/components/ui/note.tsx +55 -0
- package/src/components/ui/separator.tsx +25 -0
- package/src/components/ui/spinner.tsx +42 -0
- package/src/components/ui/switch.tsx +36 -0
- package/src/components/ui/theme-provider.tsx +24 -0
- package/src/components/ui/theme-switcher.tsx +51 -0
- package/src/components/ui/tooltip.tsx +62 -0
- package/src/components/window/MobileWindowStack.tsx +218 -0
- package/src/components/window/SnapPreview.tsx +37 -0
- package/src/components/window/StandaloneFrame.tsx +170 -0
- package/src/components/window/Window.tsx +423 -0
- package/src/components/window/WindowContent.tsx +14 -0
- package/src/components/window/WindowControlsOverlay.tsx +89 -0
- package/src/components/window/WindowFrame.tsx +124 -0
- package/src/lib/auth/index.ts +27 -0
- package/src/lib/auth/roles.ts +50 -0
- package/src/lib/auth/types.ts +32 -0
- package/src/lib/auth/use-auth.ts +53 -0
- package/src/lib/auth/webhook-handler.ts +87 -0
- package/src/lib/auth/workos.ts +67 -0
- package/src/lib/constants.ts +1 -0
- package/src/lib/desktop/dedup.ts +57 -0
- package/src/lib/desktop/schema.ts +55 -0
- package/src/lib/files/filename-validation.ts +41 -0
- package/src/lib/files/safe-path.ts +49 -0
- package/src/lib/hooks/use-desktop-nats.ts +438 -0
- package/src/lib/hooks/use-is-mobile.ts +23 -0
- package/src/lib/hooks/use-launch-app.ts +79 -0
- package/src/lib/hooks/use-nats-notifications.ts +84 -0
- package/src/lib/hooks/use-nats.ts +60 -0
- package/src/lib/hooks/use-visual-viewport.ts +72 -0
- package/src/lib/icons/resolve-window-icon.ts +10 -0
- package/src/lib/keyboard/defaults.ts +146 -0
- package/src/lib/keyboard/types.ts +52 -0
- package/src/lib/keyboard/use-global-keybinds.ts +231 -0
- package/src/lib/nats-client.ts +255 -0
- package/src/lib/nats.ts +35 -0
- package/src/lib/notifications/schema.ts +12 -0
- package/src/lib/service-loader.ts +171 -0
- package/src/lib/subjects.ts +64 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/ws-bridge.ts +288 -0
- package/src/lib/ws-protocol.ts +53 -0
- package/src/lib/ws-server.ts +167 -0
- package/src/middleware.ts +57 -0
- package/src/stores/desktop-store.ts +112 -0
- package/src/stores/keybind-store.ts +66 -0
- package/src/stores/notification-store.ts +271 -0
- package/src/stores/theme-store.ts +25 -0
- package/src/stores/window-store.ts +294 -0
- package/src/theme/animations.css +68 -0
- package/src/theme/base.css +123 -0
- package/src/theme/controls.css +35 -0
- package/src/theme/design-tokens.css +276 -0
- package/src/theme/index.css +23 -0
- package/src/theme/menus.css +45 -0
- package/src/theme/status.css +41 -0
- package/src/theme/surfaces.css +94 -0
- package/src/theme/tailwind-map.css +138 -0
- package/src/theme/taskbar.css +25 -0
- package/src/theme/terminal.css +55 -0
- package/src/theme/typography.css +26 -0
- package/src/theme/utilities.css +156 -0
- package/src/theme/window.css +103 -0
- package/src/types/desktop-entry.ts +12 -0
- package/src/types/use-descendants.d.ts +13 -0
- package/src/types/window.ts +28 -0
- package/src/types.d.ts +9 -0
- package/tauri/Cargo.lock +5464 -0
- package/tauri/Cargo.toml +19 -0
- package/tauri/build.rs +3 -0
- package/tauri/capabilities/default.json +36 -0
- package/tauri/icons/128x128.png +0 -0
- package/tauri/icons/128x128@2x.png +0 -0
- package/tauri/icons/32x32.png +0 -0
- package/tauri/icons/icon.png +0 -0
- package/tauri/src/main.rs +396 -0
- package/tauri/tauri.conf.json +23 -0
- package/tsconfig.json +43 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { useNats } from '@/lib/hooks/use-nats';
|
|
5
|
+
import { SUBJECTS } from '@/lib/subjects';
|
|
6
|
+
import type { FileEntry, FileListResponse, FileWriteRequest, FileWriteResponse } from './schema';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get the parent directory of a relative path.
|
|
10
|
+
* e.g. '/subdir/file.txt' -> '/subdir', '/file.txt' -> '/'
|
|
11
|
+
*/
|
|
12
|
+
function parentDir(filePath: string): string {
|
|
13
|
+
const lastSlash = filePath.lastIndexOf('/');
|
|
14
|
+
if (lastSlash <= 0) return '/';
|
|
15
|
+
return filePath.slice(0, lastSlash);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sort entries: directories first, then alphabetical by name (case-insensitive).
|
|
20
|
+
*/
|
|
21
|
+
function sortEntries(entries: FileEntry[]): FileEntry[] {
|
|
22
|
+
return [...entries].sort((a, b) => {
|
|
23
|
+
if (a.isDir !== b.isDir) return a.isDir ? -1 : 1;
|
|
24
|
+
return a.name.localeCompare(b.name, undefined, { sensitivity: 'base' });
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface UseFilesReturn {
|
|
29
|
+
currentPath: string;
|
|
30
|
+
filesRoot: string;
|
|
31
|
+
entries: FileEntry[];
|
|
32
|
+
loading: boolean;
|
|
33
|
+
error: string | null;
|
|
34
|
+
navigateTo: (path: string) => void;
|
|
35
|
+
refresh: () => void;
|
|
36
|
+
goBack: () => void;
|
|
37
|
+
goUp: () => void;
|
|
38
|
+
canGoBack: boolean;
|
|
39
|
+
writeOp: (op: FileWriteRequest) => Promise<FileWriteResponse>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useFiles(): UseFilesReturn {
|
|
43
|
+
const { request, subscribe, connected, orgId } = useNats();
|
|
44
|
+
const [currentPath, setCurrentPath] = useState('/');
|
|
45
|
+
const [filesRoot, setFilesRoot] = useState('');
|
|
46
|
+
const [entries, setEntries] = useState<FileEntry[]>([]);
|
|
47
|
+
const [loading, setLoading] = useState(false);
|
|
48
|
+
const [error, setError] = useState<string | null>(null);
|
|
49
|
+
const [pathHistory, setPathHistory] = useState<string[]>([]);
|
|
50
|
+
|
|
51
|
+
// Track whether we've fetched at least once for this path
|
|
52
|
+
const lastFetchedPath = useRef<string | null>(null);
|
|
53
|
+
|
|
54
|
+
const fetchEntries = useCallback(
|
|
55
|
+
async (path: string) => {
|
|
56
|
+
if (!connected) return;
|
|
57
|
+
setLoading(true);
|
|
58
|
+
setError(null);
|
|
59
|
+
try {
|
|
60
|
+
const response = (await request(SUBJECTS.fs.list(orgId), { path })) as FileListResponse & {
|
|
61
|
+
error?: string;
|
|
62
|
+
};
|
|
63
|
+
if (response.error) {
|
|
64
|
+
setError(response.error);
|
|
65
|
+
setEntries([]);
|
|
66
|
+
} else {
|
|
67
|
+
setEntries(sortEntries(response.entries));
|
|
68
|
+
setCurrentPath(response.path);
|
|
69
|
+
if (response.root) setFilesRoot(response.root);
|
|
70
|
+
lastFetchedPath.current = response.path;
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
setError((err as Error).message || 'Failed to list directory');
|
|
74
|
+
setEntries([]);
|
|
75
|
+
} finally {
|
|
76
|
+
setLoading(false);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
[connected, request]
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Fetch entries when path changes or connection becomes available
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (connected && lastFetchedPath.current !== currentPath) {
|
|
85
|
+
fetchEntries(currentPath);
|
|
86
|
+
}
|
|
87
|
+
}, [currentPath, connected, fetchEntries]);
|
|
88
|
+
|
|
89
|
+
// Initial fetch when first connected
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (connected && lastFetchedPath.current === null) {
|
|
92
|
+
fetchEntries(currentPath);
|
|
93
|
+
}
|
|
94
|
+
}, [connected, currentPath, fetchEntries]);
|
|
95
|
+
|
|
96
|
+
// --- Live watch: subscribe to fs.watch events and auto-refresh on changes ---
|
|
97
|
+
// We use a ref for currentPath so the subscription callback always sees the latest value
|
|
98
|
+
// without needing to re-subscribe every time the path changes.
|
|
99
|
+
const currentPathRef = useRef(currentPath);
|
|
100
|
+
currentPathRef.current = currentPath;
|
|
101
|
+
|
|
102
|
+
// Debounce refresh calls from watch events to avoid rapid successive fetches
|
|
103
|
+
const watchRefreshTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!connected) return;
|
|
107
|
+
|
|
108
|
+
const watchSubject = 'os.fs.watch.>';
|
|
109
|
+
const unsub = subscribe(watchSubject, (data: unknown) => {
|
|
110
|
+
if (!data || typeof data !== 'object') return;
|
|
111
|
+
const event = data as Record<string, unknown>;
|
|
112
|
+
if (typeof event.type !== 'string' || typeof event.path !== 'string') return;
|
|
113
|
+
|
|
114
|
+
// Check if this event's parent directory matches the currently viewed path
|
|
115
|
+
const eventParent = parentDir(event.path as string);
|
|
116
|
+
if (eventParent !== currentPathRef.current) return;
|
|
117
|
+
|
|
118
|
+
// Debounce: coalesce rapid events (e.g. bulk operations) into a single refresh
|
|
119
|
+
if (watchRefreshTimer.current) {
|
|
120
|
+
clearTimeout(watchRefreshTimer.current);
|
|
121
|
+
}
|
|
122
|
+
watchRefreshTimer.current = setTimeout(() => {
|
|
123
|
+
watchRefreshTimer.current = null;
|
|
124
|
+
lastFetchedPath.current = null;
|
|
125
|
+
fetchEntries(currentPathRef.current);
|
|
126
|
+
}, 300);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return () => {
|
|
130
|
+
unsub();
|
|
131
|
+
if (watchRefreshTimer.current) {
|
|
132
|
+
clearTimeout(watchRefreshTimer.current);
|
|
133
|
+
watchRefreshTimer.current = null;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}, [connected, subscribe, fetchEntries]);
|
|
137
|
+
|
|
138
|
+
const navigateTo = useCallback(
|
|
139
|
+
(path: string) => {
|
|
140
|
+
setPathHistory((prev) => [...prev, currentPath]);
|
|
141
|
+
setCurrentPath(path);
|
|
142
|
+
lastFetchedPath.current = null; // Force re-fetch
|
|
143
|
+
},
|
|
144
|
+
[currentPath]
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const refresh = useCallback(() => {
|
|
148
|
+
lastFetchedPath.current = null; // Force re-fetch
|
|
149
|
+
fetchEntries(currentPath);
|
|
150
|
+
}, [currentPath, fetchEntries]);
|
|
151
|
+
|
|
152
|
+
const goBack = useCallback(() => {
|
|
153
|
+
if (pathHistory.length === 0) return;
|
|
154
|
+
const previous = pathHistory[pathHistory.length - 1];
|
|
155
|
+
setPathHistory((prev) => prev.slice(0, -1));
|
|
156
|
+
setCurrentPath(previous);
|
|
157
|
+
lastFetchedPath.current = null;
|
|
158
|
+
}, [pathHistory]);
|
|
159
|
+
|
|
160
|
+
const goUp = useCallback(() => {
|
|
161
|
+
if (currentPath === '/') return;
|
|
162
|
+
const segments = currentPath.split('/').filter(Boolean);
|
|
163
|
+
segments.pop();
|
|
164
|
+
const parentPath = segments.length === 0 ? '/' : `/${segments.join('/')}`;
|
|
165
|
+
navigateTo(parentPath);
|
|
166
|
+
}, [currentPath, navigateTo]);
|
|
167
|
+
|
|
168
|
+
const writeOp = useCallback(
|
|
169
|
+
async (op: FileWriteRequest): Promise<FileWriteResponse> => {
|
|
170
|
+
if (!connected) {
|
|
171
|
+
return { ok: false, error: 'Not connected' };
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const response = (await request(SUBJECTS.fs.write(orgId), op)) as FileWriteResponse;
|
|
175
|
+
if (response.ok) {
|
|
176
|
+
// Refresh after successful write
|
|
177
|
+
lastFetchedPath.current = null;
|
|
178
|
+
fetchEntries(currentPath);
|
|
179
|
+
}
|
|
180
|
+
return response;
|
|
181
|
+
} catch (err) {
|
|
182
|
+
return { ok: false, error: (err as Error).message || 'Write operation failed' };
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
[connected, request, currentPath, fetchEntries]
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
currentPath,
|
|
190
|
+
filesRoot,
|
|
191
|
+
entries,
|
|
192
|
+
loading,
|
|
193
|
+
error,
|
|
194
|
+
navigateTo,
|
|
195
|
+
refresh,
|
|
196
|
+
goBack,
|
|
197
|
+
goUp,
|
|
198
|
+
canGoBack: pathHistory.length > 0,
|
|
199
|
+
writeOp,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export interface UploadState {
|
|
6
|
+
uploading: boolean;
|
|
7
|
+
progress: number; // 0-100
|
|
8
|
+
fileName: string | null;
|
|
9
|
+
error: string | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const INITIAL_STATE: UploadState = {
|
|
13
|
+
uploading: false,
|
|
14
|
+
progress: 0,
|
|
15
|
+
fileName: null,
|
|
16
|
+
error: null,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function uploadFile(file: File, targetPath: string): Promise<void> {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const xhr = new XMLHttpRequest();
|
|
22
|
+
const formData = new FormData();
|
|
23
|
+
formData.append('file', file);
|
|
24
|
+
formData.append('path', targetPath);
|
|
25
|
+
|
|
26
|
+
xhr.open('POST', '/api/files/upload');
|
|
27
|
+
|
|
28
|
+
xhr.onload = () => {
|
|
29
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
30
|
+
try {
|
|
31
|
+
const response = JSON.parse(xhr.responseText);
|
|
32
|
+
if (response.ok) {
|
|
33
|
+
resolve();
|
|
34
|
+
} else {
|
|
35
|
+
reject(new Error(response.error || 'Upload failed'));
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
reject(new Error('Invalid server response'));
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
reject(new Error(`Upload failed (${xhr.status})`));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
xhr.onerror = () => {
|
|
46
|
+
reject(new Error('Network error'));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
xhr.send(formData);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useUpload(currentPath: string, onComplete: () => void) {
|
|
54
|
+
const [uploadState, setUploadState] = useState<UploadState>(INITIAL_STATE);
|
|
55
|
+
|
|
56
|
+
const uploadFiles = useCallback(
|
|
57
|
+
async (files: FileList | File[]) => {
|
|
58
|
+
const fileArray = Array.from(files);
|
|
59
|
+
if (fileArray.length === 0) return;
|
|
60
|
+
|
|
61
|
+
setUploadState({
|
|
62
|
+
uploading: true,
|
|
63
|
+
progress: 0,
|
|
64
|
+
fileName: fileArray.length === 1 ? fileArray[0].name : `${fileArray.length} files`,
|
|
65
|
+
error: null,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
let completed = 0;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
for (const file of fileArray) {
|
|
72
|
+
setUploadState((prev) => ({
|
|
73
|
+
...prev,
|
|
74
|
+
fileName: fileArray.length === 1 ? file.name : `${file.name} (${completed + 1}/${fileArray.length})`,
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
await uploadFile(file, currentPath);
|
|
78
|
+
completed++;
|
|
79
|
+
|
|
80
|
+
setUploadState((prev) => ({
|
|
81
|
+
...prev,
|
|
82
|
+
progress: Math.round((completed / fileArray.length) * 100),
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setUploadState(INITIAL_STATE);
|
|
87
|
+
onComplete();
|
|
88
|
+
} catch (err) {
|
|
89
|
+
setUploadState({
|
|
90
|
+
uploading: false,
|
|
91
|
+
progress: 0,
|
|
92
|
+
fileName: null,
|
|
93
|
+
error: err instanceof Error ? err.message : 'Upload failed',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
[currentPath, onComplete]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const clearError = useCallback(() => {
|
|
101
|
+
setUploadState(INITIAL_STATE);
|
|
102
|
+
}, []);
|
|
103
|
+
|
|
104
|
+
return { uploadState, uploadFiles, clearError };
|
|
105
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ComponentType, lazy } from 'react';
|
|
4
|
+
|
|
5
|
+
interface AppComponentProps {
|
|
6
|
+
windowId: string;
|
|
7
|
+
meta?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const components: Record<string, ComponentType<AppComponentProps>> = {
|
|
11
|
+
genie: lazy(() => import('./views/genie/ui/GenieApp').then((m) => ({ default: m.GenieApp }))),
|
|
12
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const PREFIX = 'os.genie';
|
|
2
|
+
|
|
3
|
+
export const SUBJECTS = {
|
|
4
|
+
// --- Existing: Agent listing & pane control ---
|
|
5
|
+
agents: {
|
|
6
|
+
list: () => `${PREFIX}.agents.list`,
|
|
7
|
+
},
|
|
8
|
+
sessions: {
|
|
9
|
+
list: () => `${PREFIX}.sessions.list`,
|
|
10
|
+
},
|
|
11
|
+
pane: {
|
|
12
|
+
capture: (paneId: string) => `${PREFIX}.pane.${paneId}.capture`,
|
|
13
|
+
send: (paneId: string) => `${PREFIX}.pane.${paneId}.send`,
|
|
14
|
+
},
|
|
15
|
+
spawn: () => `${PREFIX}.spawn`,
|
|
16
|
+
events: {
|
|
17
|
+
state: () => `${PREFIX}.events.state`,
|
|
18
|
+
},
|
|
19
|
+
// Terminal proxy — PTY attached to a tmux pane
|
|
20
|
+
term: {
|
|
21
|
+
create: () => `${PREFIX}.term.create`,
|
|
22
|
+
destroy: () => `${PREFIX}.term.destroy`,
|
|
23
|
+
data: (sessionId: string) => `${PREFIX}.term.${sessionId}.data`,
|
|
24
|
+
input: (sessionId: string) => `${PREFIX}.term.${sessionId}.input`,
|
|
25
|
+
resize: (sessionId: string) => `${PREFIX}.term.${sessionId}.resize`,
|
|
26
|
+
exit: (sessionId: string) => `${PREFIX}.term.${sessionId}.exit`,
|
|
27
|
+
replay: (sessionId: string) => `${PREFIX}.term.${sessionId}.replay`,
|
|
28
|
+
buffer: (sessionId: string) => `${PREFIX}.term.${sessionId}.buffer`,
|
|
29
|
+
bufferEnd: (sessionId: string) => `${PREFIX}.term.${sessionId}.buffer-end`,
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// --- Teams domain ---
|
|
33
|
+
teams: {
|
|
34
|
+
list: () => `${PREFIX}.teams.list`,
|
|
35
|
+
get: () => `${PREFIX}.teams.get`,
|
|
36
|
+
create: () => `${PREFIX}.teams.create`,
|
|
37
|
+
disband: () => `${PREFIX}.teams.disband`,
|
|
38
|
+
done: () => `${PREFIX}.teams.done`,
|
|
39
|
+
blocked: () => `${PREFIX}.teams.blocked`,
|
|
40
|
+
hire: () => `${PREFIX}.teams.hire`,
|
|
41
|
+
fire: () => `${PREFIX}.teams.fire`,
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
// --- Communication domain ---
|
|
45
|
+
comms: {
|
|
46
|
+
send: () => `${PREFIX}.comms.send`,
|
|
47
|
+
broadcast: () => `${PREFIX}.comms.broadcast`,
|
|
48
|
+
inbox: () => `${PREFIX}.comms.inbox`,
|
|
49
|
+
chat: {
|
|
50
|
+
post: () => `${PREFIX}.comms.chat.post`,
|
|
51
|
+
read: () => `${PREFIX}.comms.chat.read`,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
// --- Wishes / Work domain ---
|
|
56
|
+
wish: {
|
|
57
|
+
list: () => `${PREFIX}.wish.list`,
|
|
58
|
+
status: () => `${PREFIX}.wish.status`,
|
|
59
|
+
work: () => `${PREFIX}.wish.work`,
|
|
60
|
+
done: () => `${PREFIX}.wish.done`,
|
|
61
|
+
reset: () => `${PREFIX}.wish.reset`,
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// --- Agent lifecycle domain ---
|
|
65
|
+
agent: {
|
|
66
|
+
kill: () => `${PREFIX}.agent.kill`,
|
|
67
|
+
stop: () => `${PREFIX}.agent.stop`,
|
|
68
|
+
history: () => `${PREFIX}.agent.history`,
|
|
69
|
+
answer: () => `${PREFIX}.agent.answer`,
|
|
70
|
+
read: () => `${PREFIX}.agent.read`,
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// --- Agent directory domain ---
|
|
74
|
+
dir: {
|
|
75
|
+
list: () => `${PREFIX}.dir.list`,
|
|
76
|
+
get: () => `${PREFIX}.dir.get`,
|
|
77
|
+
add: () => `${PREFIX}.dir.add`,
|
|
78
|
+
remove: () => `${PREFIX}.dir.remove`,
|
|
79
|
+
edit: () => `${PREFIX}.dir.edit`,
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
// --- System health ---
|
|
83
|
+
system: {
|
|
84
|
+
doctor: () => `${PREFIX}.system.doctor`,
|
|
85
|
+
version: () => `${PREFIX}.system.version`,
|
|
86
|
+
},
|
|
87
|
+
} as const;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
id: 'genie-app',
|
|
3
|
+
views: [
|
|
4
|
+
{
|
|
5
|
+
id: 'genie',
|
|
6
|
+
label: 'Genie',
|
|
7
|
+
permission: 'genie',
|
|
8
|
+
minRole: 'platform-dev' as const,
|
|
9
|
+
natsPrefix: 'genie',
|
|
10
|
+
defaultSize: { width: 960, height: 640 },
|
|
11
|
+
component: './views/genie/ui/GenieApp',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
desktop: {
|
|
15
|
+
icon: '/icons/dusk/electron.svg',
|
|
16
|
+
categories: ['Development'],
|
|
17
|
+
comment: 'Agent mission control',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@genie-os/genie-app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "./manifest.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./manifest.ts",
|
|
8
|
+
"./components": "./components.ts",
|
|
9
|
+
"./views/*": "./views/*"
|
|
10
|
+
},
|
|
11
|
+
"genieOs": {
|
|
12
|
+
"services": [
|
|
13
|
+
{
|
|
14
|
+
"name": "genie-control",
|
|
15
|
+
"entry": "./views/genie/service/index.ts",
|
|
16
|
+
"runtime": "node"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"react-grid-layout": "^1.5.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/react-grid-layout": "^1.3.5"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=19"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Lifecycle domain — kill, stop, history, answer, read.
|
|
3
|
+
*
|
|
4
|
+
* Exposes agent control operations beyond spawn (which lives in index.ts).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ServiceHandler } from '@genie-os/sdk/service';
|
|
8
|
+
import { SUBJECTS } from '../../../lib/subjects';
|
|
9
|
+
import { runGenie } from './cli';
|
|
10
|
+
|
|
11
|
+
export const agentLifecycleHandlers: ServiceHandler[] = [
|
|
12
|
+
// --- Kill agent ---
|
|
13
|
+
{
|
|
14
|
+
subject: SUBJECTS.agent.kill(),
|
|
15
|
+
handler: (msg) => {
|
|
16
|
+
try {
|
|
17
|
+
const { name } = msg.json<{ name: string }>();
|
|
18
|
+
if (!name) {
|
|
19
|
+
msg.respond(JSON.stringify({ error: 'Missing required field: name' }));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const result = runGenie(['kill', name], { json: false });
|
|
23
|
+
if (!result.ok) {
|
|
24
|
+
msg.respond(JSON.stringify({ error: result.error }));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
msg.respond(JSON.stringify({ ok: true }));
|
|
28
|
+
} catch (err) {
|
|
29
|
+
msg.respond(JSON.stringify({ error: String(err) }));
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
// --- Stop agent ---
|
|
35
|
+
{
|
|
36
|
+
subject: SUBJECTS.agent.stop(),
|
|
37
|
+
handler: (msg) => {
|
|
38
|
+
try {
|
|
39
|
+
const { name } = msg.json<{ name: string }>();
|
|
40
|
+
if (!name) {
|
|
41
|
+
msg.respond(JSON.stringify({ error: 'Missing required field: name' }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const result = runGenie(['stop', name], { json: false });
|
|
45
|
+
if (!result.ok) {
|
|
46
|
+
msg.respond(JSON.stringify({ error: result.error }));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
msg.respond(JSON.stringify({ ok: true }));
|
|
50
|
+
} catch (err) {
|
|
51
|
+
msg.respond(JSON.stringify({ error: String(err) }));
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
// --- Agent history ---
|
|
57
|
+
{
|
|
58
|
+
subject: SUBJECTS.agent.history(),
|
|
59
|
+
handler: (msg) => {
|
|
60
|
+
try {
|
|
61
|
+
const { name, full, since } = msg.json<{ name: string; full?: boolean; since?: string }>();
|
|
62
|
+
if (!name) {
|
|
63
|
+
msg.respond(JSON.stringify({ error: 'Missing required field: name' }));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const args = ['history', name, '--json'];
|
|
67
|
+
if (full) args.push('--full');
|
|
68
|
+
if (since) args.push('--since', since);
|
|
69
|
+
|
|
70
|
+
const result = runGenie<unknown[]>(args, { timeout: 15_000 });
|
|
71
|
+
if (!result.ok) {
|
|
72
|
+
msg.respond(JSON.stringify({ error: result.error }));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
msg.respond(JSON.stringify({ history: result.data }));
|
|
76
|
+
} catch (err) {
|
|
77
|
+
msg.respond(JSON.stringify({ error: String(err) }));
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
// --- Answer agent question ---
|
|
83
|
+
{
|
|
84
|
+
subject: SUBJECTS.agent.answer(),
|
|
85
|
+
handler: (msg) => {
|
|
86
|
+
try {
|
|
87
|
+
const { name, choice } = msg.json<{ name: string; choice: string }>();
|
|
88
|
+
if (!name || !choice) {
|
|
89
|
+
msg.respond(JSON.stringify({ error: 'Missing required fields: name, choice' }));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// choice can be a number ("1") or text ("text:my answer")
|
|
93
|
+
const result = runGenie(['answer', name, choice], { json: false });
|
|
94
|
+
if (!result.ok) {
|
|
95
|
+
msg.respond(JSON.stringify({ error: result.error }));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
msg.respond(JSON.stringify({ ok: true, output: result.data }));
|
|
99
|
+
} catch (err) {
|
|
100
|
+
msg.respond(JSON.stringify({ error: String(err) }));
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// --- Read agent output ---
|
|
106
|
+
{
|
|
107
|
+
subject: SUBJECTS.agent.read(),
|
|
108
|
+
handler: (msg) => {
|
|
109
|
+
try {
|
|
110
|
+
const { name, lines, search, grep } = msg.json<{
|
|
111
|
+
name: string;
|
|
112
|
+
lines?: number;
|
|
113
|
+
search?: string;
|
|
114
|
+
grep?: string;
|
|
115
|
+
}>();
|
|
116
|
+
if (!name) {
|
|
117
|
+
msg.respond(JSON.stringify({ error: 'Missing required field: name' }));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const args = ['read', name, '--json'];
|
|
121
|
+
if (lines !== undefined) args.push('--lines', String(lines));
|
|
122
|
+
if (search) args.push('--search', search);
|
|
123
|
+
if (grep) args.push('--grep', grep);
|
|
124
|
+
|
|
125
|
+
const result = runGenie(args, { timeout: 15_000 });
|
|
126
|
+
if (!result.ok) {
|
|
127
|
+
msg.respond(JSON.stringify({ error: result.error }));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
msg.respond(JSON.stringify({ output: result.data }));
|
|
131
|
+
} catch (err) {
|
|
132
|
+
msg.respond(JSON.stringify({ error: String(err) }));
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
];
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared CLI runner for the genie command.
|
|
3
|
+
*
|
|
4
|
+
* - `runGenie()` — synchronous, for fast commands (<1s): list, status, kill, etc.
|
|
5
|
+
* - `runGenieAsync()` — promise-based, for long-running commands: team create, work, etc.
|
|
6
|
+
*
|
|
7
|
+
* Both use `execFileSync` / `execFile` with argument arrays to prevent command injection.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
11
|
+
|
|
12
|
+
export interface RunGenieOptions {
|
|
13
|
+
/** Parse stdout as JSON. Defaults to true. */
|
|
14
|
+
json?: boolean;
|
|
15
|
+
/** Timeout in milliseconds. Defaults to 10_000. */
|
|
16
|
+
timeout?: number;
|
|
17
|
+
/** Working directory for the command. */
|
|
18
|
+
cwd?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface GenieResult<T = unknown> {
|
|
22
|
+
ok: true;
|
|
23
|
+
data: T;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GenieError {
|
|
27
|
+
ok: false;
|
|
28
|
+
error: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type GenieOutput<T = unknown> = GenieResult<T> | GenieError;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Run a genie CLI command synchronously.
|
|
35
|
+
*
|
|
36
|
+
* Uses `execFileSync('genie', [...args])` — never string concatenation.
|
|
37
|
+
*
|
|
38
|
+
* @param args - Argument array passed directly to execFileSync (e.g. ['team', 'ls', '--json'])
|
|
39
|
+
* @param opts - Options for JSON parsing, timeout, and cwd
|
|
40
|
+
* @returns Parsed JSON when opts.json is true (default), raw string otherwise
|
|
41
|
+
*/
|
|
42
|
+
export function runGenie<_T = unknown>(args: string[], opts: RunGenieOptions & { json: false }): GenieOutput<string>;
|
|
43
|
+
export function runGenie<T = unknown>(args: string[], opts?: RunGenieOptions): GenieOutput<T>;
|
|
44
|
+
export function runGenie<T = unknown>(args: string[], opts?: RunGenieOptions): GenieOutput<T | string> {
|
|
45
|
+
const { json = true, timeout = 10_000, cwd } = opts ?? {};
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const stdout = execFileSync('genie', args, {
|
|
49
|
+
encoding: 'utf-8',
|
|
50
|
+
timeout,
|
|
51
|
+
cwd: cwd ?? process.env.HOME,
|
|
52
|
+
env: { ...process.env, FORCE_COLOR: '0', NO_COLOR: '1' },
|
|
53
|
+
}).trim();
|
|
54
|
+
|
|
55
|
+
if (!json) {
|
|
56
|
+
return { ok: true, data: stdout };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
return { ok: true, data: JSON.parse(stdout) as T };
|
|
61
|
+
} catch {
|
|
62
|
+
// JSON parse failed — return raw text
|
|
63
|
+
return { ok: true, data: stdout as unknown as T };
|
|
64
|
+
}
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
67
|
+
return { ok: false, error: message };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Run a genie CLI command asynchronously (promise-based).
|
|
73
|
+
*
|
|
74
|
+
* Uses `execFile('genie', [...args])` — for long-running commands like `team create` or `work`.
|
|
75
|
+
*
|
|
76
|
+
* @param args - Argument array passed directly to execFile
|
|
77
|
+
* @param opts - Options for JSON parsing, timeout, and cwd
|
|
78
|
+
*/
|
|
79
|
+
export function runGenieAsync<T = unknown>(args: string[], opts?: RunGenieOptions): Promise<GenieOutput<T | string>> {
|
|
80
|
+
const { json = true, timeout = 60_000, cwd } = opts ?? {};
|
|
81
|
+
|
|
82
|
+
return new Promise((resolve) => {
|
|
83
|
+
execFile(
|
|
84
|
+
'genie',
|
|
85
|
+
args,
|
|
86
|
+
{
|
|
87
|
+
encoding: 'utf-8',
|
|
88
|
+
timeout,
|
|
89
|
+
cwd: cwd ?? process.env.HOME,
|
|
90
|
+
env: { ...process.env, FORCE_COLOR: '0', NO_COLOR: '1' },
|
|
91
|
+
},
|
|
92
|
+
(err: Error | null, stdout: string, stderr: string) => {
|
|
93
|
+
if (err) {
|
|
94
|
+
const message = stderr?.trim() || err.message;
|
|
95
|
+
resolve({ ok: false, error: message });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const output = stdout.trim();
|
|
100
|
+
|
|
101
|
+
if (!json) {
|
|
102
|
+
resolve({ ok: true, data: output });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
resolve({ ok: true, data: JSON.parse(output) as T });
|
|
108
|
+
} catch {
|
|
109
|
+
resolve({ ok: true, data: output as unknown as T });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
}
|