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.
Files changed (408) hide show
  1. package/.env.example +23 -0
  2. package/.genie/mailbox/cli-sent.jsonl +3 -0
  3. package/.genie/mailbox/ds1-wave2-engineer-1.json +15 -0
  4. package/.genie/mailbox/ds1-wave2-engineer-2.json +15 -0
  5. package/.genie/mailbox/ds1-wave2-engineer-3.json +15 -0
  6. package/.genie/state/os-observability.json +39 -0
  7. package/.genie/state/tmux-control-mode-terminal.json +28 -0
  8. package/.genie/wishes/genieos-one-theme/WISH.md +417 -0
  9. package/.genie/wishes/workos-prod-rbac/WISH.md +345 -0
  10. package/.github/workflows/ci.yml +39 -0
  11. package/.github/workflows/release.yml +78 -0
  12. package/.github/workflows/version.yml +122 -0
  13. package/.husky/pre-commit +1 -0
  14. package/.pnpm-approve-builds.json +1 -0
  15. package/CLAUDE.md +117 -0
  16. package/LICENSE +21 -0
  17. package/README.md +38 -0
  18. package/biome.json +124 -0
  19. package/bun.lock +1249 -0
  20. package/docs/workos-setup.md +116 -0
  21. package/ecosystem.config.cjs +26 -0
  22. package/instrumentation.ts +8 -0
  23. package/knip.json +35 -0
  24. package/nats.conf +7 -0
  25. package/next.config.ts +25 -0
  26. package/package.json +78 -0
  27. package/packages/dev3000-app/components.ts +12 -0
  28. package/packages/dev3000-app/manifest.ts +19 -0
  29. package/packages/dev3000-app/package.json +23 -0
  30. package/packages/dev3000-app/views/dev3000/Dev3000App.tsx +758 -0
  31. package/packages/dev3000-app/views/dev3000/ErrorsPanel.tsx +160 -0
  32. package/packages/dev3000-app/views/dev3000/dev3000-context.tsx +21 -0
  33. package/packages/dev3000-app/views/dev3000/index.ts +4 -0
  34. package/packages/dev3000-app/views/dev3000/schema.ts +55 -0
  35. package/packages/dev3000-app/views/dev3000/service/index.ts +358 -0
  36. package/packages/dev3000-app/views/dev3000/service/runtime +1 -0
  37. package/packages/dev3000-app/views/dev3000/subjects.ts +9 -0
  38. package/packages/dev3000-app/views/dev3000/types.ts +77 -0
  39. package/packages/files-app/components.ts +12 -0
  40. package/packages/files-app/manifest.ts +19 -0
  41. package/packages/files-app/package.json +23 -0
  42. package/packages/files-app/views/files/ContextMenu.tsx +151 -0
  43. package/packages/files-app/views/files/DeleteConfirmDialog.tsx +39 -0
  44. package/packages/files-app/views/files/FileItem.tsx +128 -0
  45. package/packages/files-app/views/files/FilesApp.tsx +509 -0
  46. package/packages/files-app/views/files/FilesListView.tsx +201 -0
  47. package/packages/files-app/views/files/FilesToolbar.tsx +117 -0
  48. package/packages/files-app/views/files/GridView.tsx +90 -0
  49. package/packages/files-app/views/files/InlineInput.tsx +131 -0
  50. package/packages/files-app/views/files/UploadOverlay.tsx +61 -0
  51. package/packages/files-app/views/files/schema.ts +49 -0
  52. package/packages/files-app/views/files/service/index.ts +184 -0
  53. package/packages/files-app/views/files/service/runtime +1 -0
  54. package/packages/files-app/views/files/use-files.ts +201 -0
  55. package/packages/files-app/views/files/use-upload.ts +105 -0
  56. package/packages/genie-app/components.ts +12 -0
  57. package/packages/genie-app/lib/subjects.ts +87 -0
  58. package/packages/genie-app/manifest.ts +19 -0
  59. package/packages/genie-app/package.json +29 -0
  60. package/packages/genie-app/views/genie/service/agent-lifecycle.ts +136 -0
  61. package/packages/genie-app/views/genie/service/cli.ts +114 -0
  62. package/packages/genie-app/views/genie/service/comms.ts +141 -0
  63. package/packages/genie-app/views/genie/service/directory.ts +167 -0
  64. package/packages/genie-app/views/genie/service/index.ts +219 -0
  65. package/packages/genie-app/views/genie/service/system.ts +123 -0
  66. package/packages/genie-app/views/genie/service/teams.ts +191 -0
  67. package/packages/genie-app/views/genie/service/terminal-proxy.ts +184 -0
  68. package/packages/genie-app/views/genie/service/tmux-control.ts +318 -0
  69. package/packages/genie-app/views/genie/service/wishes.ts +270 -0
  70. package/packages/genie-app/views/genie/ui/GenieApp.tsx +5 -0
  71. package/packages/genie-app/views/genie/ui/PaneCard.tsx +307 -0
  72. package/packages/genie-app/views/genie/ui/Sidebar.tsx +212 -0
  73. package/packages/genie-app/views/genie/ui/TabBar.tsx +70 -0
  74. package/packages/genie-app/views/genie/ui/WorkspaceCanvas.tsx +343 -0
  75. package/packages/genie-app/views/genie/ui/XTermPane.tsx +306 -0
  76. package/packages/genie-app/views/genie/ui/hooks/useNatsAction.ts +54 -0
  77. package/packages/genie-app/views/genie/ui/hooks/useNatsRequest.ts +68 -0
  78. package/packages/genie-app/views/genie/ui/panels/AgentsPanel.tsx +399 -0
  79. package/packages/genie-app/views/genie/ui/panels/ChatPanel.tsx +351 -0
  80. package/packages/genie-app/views/genie/ui/panels/SystemPanel.tsx +195 -0
  81. package/packages/genie-app/views/genie/ui/panels/TeamsPanel.tsx +560 -0
  82. package/packages/genie-app/views/genie/ui/panels/WishesPanel.tsx +424 -0
  83. package/packages/nats-viewer-app/components.ts +12 -0
  84. package/packages/nats-viewer-app/manifest.ts +18 -0
  85. package/packages/nats-viewer-app/package.json +14 -0
  86. package/packages/nats-viewer-app/views/nats-viewer/ActiveSubs.tsx +34 -0
  87. package/packages/nats-viewer-app/views/nats-viewer/MessageLog.tsx +247 -0
  88. package/packages/nats-viewer-app/views/nats-viewer/NatsViewer.tsx +209 -0
  89. package/packages/nats-viewer-app/views/nats-viewer/PublishPanel.tsx +111 -0
  90. package/packages/nats-viewer-app/views/nats-viewer/RequestPanel.tsx +165 -0
  91. package/packages/nats-viewer-app/views/nats-viewer/Sidebar.tsx +59 -0
  92. package/packages/nats-viewer-app/views/nats-viewer/SubjectCatalog.tsx +63 -0
  93. package/packages/nats-viewer-app/views/nats-viewer/SubscribeInput.tsx +59 -0
  94. package/packages/nats-viewer-app/views/nats-viewer/index.ts +5 -0
  95. package/packages/nats-viewer-app/views/nats-viewer/nats-viewer-context.tsx +31 -0
  96. package/packages/nats-viewer-app/views/nats-viewer/types.ts +7 -0
  97. package/packages/nats-viewer-app/views/nats-viewer/use-message-buffer.ts +55 -0
  98. package/packages/os-cli/package.json +18 -0
  99. package/packages/os-cli/src/commands/events.ts +176 -0
  100. package/packages/os-cli/src/commands/logs.ts +96 -0
  101. package/packages/os-cli/src/commands/status.ts +53 -0
  102. package/packages/os-cli/src/commands/traces.ts +115 -0
  103. package/packages/os-cli/src/index.ts +15 -0
  104. package/packages/os-cli/src/lib/formatter.ts +123 -0
  105. package/packages/os-cli/src/lib/nats.ts +16 -0
  106. package/packages/os-cli/src/lib/trace-tree.ts +144 -0
  107. package/packages/os-cli/tsconfig.json +12 -0
  108. package/packages/os-sdk/package.json +27 -0
  109. package/packages/os-sdk/src/api/handler.ts +67 -0
  110. package/packages/os-sdk/src/config.ts +68 -0
  111. package/packages/os-sdk/src/db/factory.test.ts +42 -0
  112. package/packages/os-sdk/src/db/factory.ts +72 -0
  113. package/packages/os-sdk/src/db/migrate.ts +140 -0
  114. package/packages/os-sdk/src/db/provision.ts +44 -0
  115. package/packages/os-sdk/src/index.ts +36 -0
  116. package/packages/os-sdk/src/service/console-intercept.ts +60 -0
  117. package/packages/os-sdk/src/service/logger.ts +88 -0
  118. package/packages/os-sdk/src/service/o11y-streams.ts +88 -0
  119. package/packages/os-sdk/src/service/runtime.ts +259 -0
  120. package/packages/os-sdk/src/service/trace.ts +71 -0
  121. package/packages/os-sdk/tsconfig.json +16 -0
  122. package/packages/os-ui/package.json +13 -0
  123. package/packages/os-ui/src/index.ts +29 -0
  124. package/packages/os-ui/src/server.ts +4 -0
  125. package/packages/os-ui/tsconfig.json +19 -0
  126. package/packages/settings-app/components.ts +12 -0
  127. package/packages/settings-app/manifest.ts +18 -0
  128. package/packages/settings-app/package.json +14 -0
  129. package/packages/settings-app/views/settings/Settings.tsx +492 -0
  130. package/packages/terminal-app/components.ts +12 -0
  131. package/packages/terminal-app/manifest.ts +20 -0
  132. package/packages/terminal-app/package.json +23 -0
  133. package/packages/terminal-app/views/terminal/schema.ts +82 -0
  134. package/packages/terminal-app/views/terminal/service/index.ts +133 -0
  135. package/packages/terminal-app/views/terminal/service/runtime +1 -0
  136. package/packages/terminal-app/views/terminal/service/session.ts +290 -0
  137. package/packages/terminal-app/views/terminal/service/shell-hooks/bashrc-hook.sh +21 -0
  138. package/packages/terminal-app/views/terminal/types.ts +26 -0
  139. package/packages/terminal-app/views/terminal/ui/MultiTerminalApp.tsx +615 -0
  140. package/packages/terminal-app/views/terminal/ui/SplitDragHandle.tsx +91 -0
  141. package/packages/terminal-app/views/terminal/ui/SplitPaneRenderer.tsx +112 -0
  142. package/packages/terminal-app/views/terminal/ui/TerminalPane.tsx +478 -0
  143. package/packages/terminal-app/views/terminal/ui/TerminalTabBar.tsx +131 -0
  144. package/pnpm-workspace.yaml +9 -0
  145. package/postcss.config.mjs +7 -0
  146. package/public/file.svg +1 -0
  147. package/public/globe.svg +1 -0
  148. package/public/icons/code-server.svg +6 -0
  149. package/public/icons/default.svg +5 -0
  150. package/public/icons/dusk/1password.svg +1 -0
  151. package/public/icons/dusk/activity_monitor.svg +1 -0
  152. package/public/icons/dusk/app_store.svg +1 -0
  153. package/public/icons/dusk/atom.svg +1 -0
  154. package/public/icons/dusk/brave.svg +1 -0
  155. package/public/icons/dusk/calculator.svg +1 -0
  156. package/public/icons/dusk/calendar.svg +1 -0
  157. package/public/icons/dusk/chrome.svg +1 -0
  158. package/public/icons/dusk/chrome2.svg +1 -0
  159. package/public/icons/dusk/dashboard.svg +13 -0
  160. package/public/icons/dusk/discord.svg +1 -0
  161. package/public/icons/dusk/dropbox.svg +1 -0
  162. package/public/icons/dusk/electron.svg +1 -0
  163. package/public/icons/dusk/figma.svg +1 -0
  164. package/public/icons/dusk/finder.svg +1 -0
  165. package/public/icons/dusk/finder2.svg +1 -0
  166. package/public/icons/dusk/finder3.svg +1 -0
  167. package/public/icons/dusk/firefox.svg +1 -0
  168. package/public/icons/dusk/framer.svg +1 -0
  169. package/public/icons/dusk/gimp.svg +1 -0
  170. package/public/icons/dusk/github_desktop.svg +1 -0
  171. package/public/icons/dusk/hyper.svg +1 -0
  172. package/public/icons/dusk/hyper3.svg +1 -0
  173. package/public/icons/dusk/intellij.svg +1 -0
  174. package/public/icons/dusk/iterm2.svg +1 -0
  175. package/public/icons/dusk/itunes.svg +1 -0
  176. package/public/icons/dusk/mail.svg +1 -0
  177. package/public/icons/dusk/messenger.svg +1 -0
  178. package/public/icons/dusk/mongodb.svg +1 -0
  179. package/public/icons/dusk/notes.svg +1 -0
  180. package/public/icons/dusk/notion.svg +1 -0
  181. package/public/icons/dusk/obs.svg +1 -0
  182. package/public/icons/dusk/pages.svg +1 -0
  183. package/public/icons/dusk/photos.svg +1 -0
  184. package/public/icons/dusk/postman.svg +1 -0
  185. package/public/icons/dusk/preview.svg +1 -0
  186. package/public/icons/dusk/reminders.svg +1 -0
  187. package/public/icons/dusk/safari.svg +1 -0
  188. package/public/icons/dusk/sequel_pro.svg +1 -0
  189. package/public/icons/dusk/sketch.svg +1 -0
  190. package/public/icons/dusk/skype.svg +1 -0
  191. package/public/icons/dusk/slack.svg +1 -0
  192. package/public/icons/dusk/slack2.svg +1 -0
  193. package/public/icons/dusk/spotify.svg +1 -0
  194. package/public/icons/dusk/steam.svg +1 -0
  195. package/public/icons/dusk/system_preferences.svg +1 -0
  196. package/public/icons/dusk/tableplus.svg +1 -0
  197. package/public/icons/dusk/teams.svg +1 -0
  198. package/public/icons/dusk/telegram.svg +1 -0
  199. package/public/icons/dusk/terminal.svg +1 -0
  200. package/public/icons/dusk/todoist.svg +1 -0
  201. package/public/icons/dusk/trash.svg +1 -0
  202. package/public/icons/dusk/trello.svg +1 -0
  203. package/public/icons/dusk/vivaldi.svg +1 -0
  204. package/public/icons/dusk/vlc.svg +1 -0
  205. package/public/icons/dusk/vscode.svg +1 -0
  206. package/public/icons/dusk/whatsapp.svg +1 -0
  207. package/public/icons/dusk/xeyes.svg +1 -0
  208. package/public/icons/dusk/zoom.svg +1 -0
  209. package/public/icons/files.svg +5 -0
  210. package/public/icons/pwa/icon-192.png +0 -0
  211. package/public/icons/pwa/icon-512.png +0 -0
  212. package/public/icons/settings.svg +14 -0
  213. package/public/icons/terminal.svg +5 -0
  214. package/public/icons/text-editor.svg +7 -0
  215. package/public/manifest.json +38 -0
  216. package/public/next.svg +1 -0
  217. package/public/sw.js +41 -0
  218. package/public/vercel.svg +1 -0
  219. package/public/wallpapers/default.svg +10 -0
  220. package/public/window.svg +1 -0
  221. package/scripts/generate-pwa-icons.mjs +33 -0
  222. package/scripts/install-nats.sh +37 -0
  223. package/sentry.client.config.ts +21 -0
  224. package/sentry.edge.config.ts +12 -0
  225. package/sentry.server.config.ts +12 -0
  226. package/src/app/api/files/download/route.ts +81 -0
  227. package/src/app/api/files/download-zip/route.ts +102 -0
  228. package/src/app/api/files/upload/route.ts +58 -0
  229. package/src/app/api/webhooks/workos/route.ts +98 -0
  230. package/src/app/auth/callback/route.ts +16 -0
  231. package/src/app/auth/logout/route.ts +15 -0
  232. package/src/app/desktop/desktop-shell.tsx +110 -0
  233. package/src/app/desktop/layout.tsx +8 -0
  234. package/src/app/desktop/page.tsx +24 -0
  235. package/src/app/favicon.ico +0 -0
  236. package/src/app/globals.css +7 -0
  237. package/src/app/layout.tsx +64 -0
  238. package/src/app/offline/page.tsx +83 -0
  239. package/src/app/page.tsx +5 -0
  240. package/src/app/standalone/[appId]/page.tsx +28 -0
  241. package/src/app/standalone/layout.tsx +10 -0
  242. package/src/components/app-icon.tsx +55 -0
  243. package/src/components/apps/_echo/schema.ts +14 -0
  244. package/src/components/apps/_echo/service/index.ts +42 -0
  245. package/src/components/apps/app-manifest.ts +97 -0
  246. package/src/components/apps/app-registry.ts +55 -0
  247. package/src/components/apps/dev3000/Dev3000App.tsx +224 -0
  248. package/src/components/apps/dev3000/ErrorsPanel.tsx +160 -0
  249. package/src/components/apps/dev3000/Sidebar.tsx +41 -0
  250. package/src/components/apps/dev3000/TimelineLog.tsx +173 -0
  251. package/src/components/apps/dev3000/dev3000-context.tsx +29 -0
  252. package/src/components/apps/dev3000/index.ts +4 -0
  253. package/src/components/apps/dev3000/schema.ts +48 -0
  254. package/src/components/apps/dev3000/service/index.ts +520 -0
  255. package/src/components/apps/dev3000/service/runtime +1 -0
  256. package/src/components/apps/dev3000/types.ts +15 -0
  257. package/src/components/apps/dev3000/use-message-buffer.ts +46 -0
  258. package/src/components/apps/files/ContextMenu.tsx +151 -0
  259. package/src/components/apps/files/DeleteConfirmDialog.tsx +78 -0
  260. package/src/components/apps/files/FileItem.tsx +128 -0
  261. package/src/components/apps/files/FilesApp.tsx +509 -0
  262. package/src/components/apps/files/FilesListView.tsx +201 -0
  263. package/src/components/apps/files/FilesToolbar.tsx +117 -0
  264. package/src/components/apps/files/GridView.tsx +90 -0
  265. package/src/components/apps/files/InlineInput.tsx +131 -0
  266. package/src/components/apps/files/UploadOverlay.tsx +61 -0
  267. package/src/components/apps/files/schema.ts +49 -0
  268. package/src/components/apps/files/service/index.ts +227 -0
  269. package/src/components/apps/files/service/runtime +1 -0
  270. package/src/components/apps/files/use-files.ts +201 -0
  271. package/src/components/apps/files/use-upload.ts +105 -0
  272. package/src/components/apps/nats-viewer/ActiveSubs.tsx +34 -0
  273. package/src/components/apps/nats-viewer/MessageLog.tsx +247 -0
  274. package/src/components/apps/nats-viewer/NatsViewer.tsx +209 -0
  275. package/src/components/apps/nats-viewer/PublishPanel.tsx +113 -0
  276. package/src/components/apps/nats-viewer/RequestPanel.tsx +167 -0
  277. package/src/components/apps/nats-viewer/Sidebar.tsx +62 -0
  278. package/src/components/apps/nats-viewer/SubjectCatalog.tsx +64 -0
  279. package/src/components/apps/nats-viewer/SubscribeInput.tsx +59 -0
  280. package/src/components/apps/nats-viewer/index.ts +5 -0
  281. package/src/components/apps/nats-viewer/nats-viewer-context.tsx +31 -0
  282. package/src/components/apps/nats-viewer/types.ts +7 -0
  283. package/src/components/apps/nats-viewer/use-message-buffer.ts +55 -0
  284. package/src/components/apps/settings/Settings.tsx +492 -0
  285. package/src/components/apps/terminal/schema.ts +82 -0
  286. package/src/components/apps/terminal/service/index.ts +189 -0
  287. package/src/components/apps/terminal/service/runtime +1 -0
  288. package/src/components/apps/terminal/service/session.ts +296 -0
  289. package/src/components/apps/terminal/service/shell-hooks/bashrc-hook.sh +21 -0
  290. package/src/components/apps/terminal/types.ts +26 -0
  291. package/src/components/apps/terminal/ui/MultiTerminalApp.tsx +617 -0
  292. package/src/components/apps/terminal/ui/SplitDragHandle.tsx +91 -0
  293. package/src/components/apps/terminal/ui/SplitPaneRenderer.tsx +112 -0
  294. package/src/components/apps/terminal/ui/TerminalPane.tsx +476 -0
  295. package/src/components/apps/terminal/ui/TerminalTabBar.tsx +131 -0
  296. package/src/components/desktop/AnimatedBackground.tsx +69 -0
  297. package/src/components/desktop/Desktop.tsx +79 -0
  298. package/src/components/desktop/DesktopBackground.tsx +16 -0
  299. package/src/components/desktop/DesktopIcon.tsx +49 -0
  300. package/src/components/desktop/ShortcutViewer.tsx +136 -0
  301. package/src/components/desktop/WindowRenderer.tsx +34 -0
  302. package/src/components/desktop/WindowSwitcher.tsx +42 -0
  303. package/src/components/notifications/NotificationCenter.tsx +153 -0
  304. package/src/components/notifications/NotificationToasts.tsx +66 -0
  305. package/src/components/notifications/OrphanSessionToast.tsx +293 -0
  306. package/src/components/os-primitives/collapsible-sidebar.tsx +226 -0
  307. package/src/components/os-primitives/dialog.tsx +76 -0
  308. package/src/components/os-primitives/empty-state.tsx +43 -0
  309. package/src/components/os-primitives/index.ts +21 -0
  310. package/src/components/os-primitives/list-view.tsx +155 -0
  311. package/src/components/os-primitives/property-panel.tsx +108 -0
  312. package/src/components/os-primitives/section-header.tsx +19 -0
  313. package/src/components/os-primitives/sidebar-nav.tsx +110 -0
  314. package/src/components/os-primitives/split-pane.tsx +146 -0
  315. package/src/components/os-primitives/status-badge.tsx +10 -0
  316. package/src/components/os-primitives/status-bar.tsx +100 -0
  317. package/src/components/os-primitives/toolbar.tsx +152 -0
  318. package/src/components/taskbar/AppLauncher.tsx +114 -0
  319. package/src/components/taskbar/RunningApps.tsx +71 -0
  320. package/src/components/taskbar/SystemTray.tsx +134 -0
  321. package/src/components/taskbar/Taskbar.tsx +45 -0
  322. package/src/components/taskbar/UserMenu.tsx +138 -0
  323. package/src/components/taskbar/WorkspaceSwitcher.tsx +9 -0
  324. package/src/components/ui/ContextMenu.tsx +130 -0
  325. package/src/components/ui/badge.tsx +39 -0
  326. package/src/components/ui/button.tsx +102 -0
  327. package/src/components/ui/command.tsx +165 -0
  328. package/src/components/ui/dropdown-menu.tsx +233 -0
  329. package/src/components/ui/input.tsx +48 -0
  330. package/src/components/ui/note.tsx +55 -0
  331. package/src/components/ui/separator.tsx +25 -0
  332. package/src/components/ui/spinner.tsx +42 -0
  333. package/src/components/ui/switch.tsx +36 -0
  334. package/src/components/ui/theme-provider.tsx +24 -0
  335. package/src/components/ui/theme-switcher.tsx +51 -0
  336. package/src/components/ui/tooltip.tsx +62 -0
  337. package/src/components/window/MobileWindowStack.tsx +218 -0
  338. package/src/components/window/SnapPreview.tsx +37 -0
  339. package/src/components/window/StandaloneFrame.tsx +170 -0
  340. package/src/components/window/Window.tsx +423 -0
  341. package/src/components/window/WindowContent.tsx +14 -0
  342. package/src/components/window/WindowControlsOverlay.tsx +89 -0
  343. package/src/components/window/WindowFrame.tsx +124 -0
  344. package/src/lib/auth/index.ts +27 -0
  345. package/src/lib/auth/roles.ts +50 -0
  346. package/src/lib/auth/types.ts +32 -0
  347. package/src/lib/auth/use-auth.ts +53 -0
  348. package/src/lib/auth/webhook-handler.ts +87 -0
  349. package/src/lib/auth/workos.ts +67 -0
  350. package/src/lib/constants.ts +1 -0
  351. package/src/lib/desktop/dedup.ts +57 -0
  352. package/src/lib/desktop/schema.ts +55 -0
  353. package/src/lib/files/filename-validation.ts +41 -0
  354. package/src/lib/files/safe-path.ts +49 -0
  355. package/src/lib/hooks/use-desktop-nats.ts +438 -0
  356. package/src/lib/hooks/use-is-mobile.ts +23 -0
  357. package/src/lib/hooks/use-launch-app.ts +79 -0
  358. package/src/lib/hooks/use-nats-notifications.ts +84 -0
  359. package/src/lib/hooks/use-nats.ts +60 -0
  360. package/src/lib/hooks/use-visual-viewport.ts +72 -0
  361. package/src/lib/icons/resolve-window-icon.ts +10 -0
  362. package/src/lib/keyboard/defaults.ts +146 -0
  363. package/src/lib/keyboard/types.ts +52 -0
  364. package/src/lib/keyboard/use-global-keybinds.ts +231 -0
  365. package/src/lib/nats-client.ts +255 -0
  366. package/src/lib/nats.ts +35 -0
  367. package/src/lib/notifications/schema.ts +12 -0
  368. package/src/lib/service-loader.ts +171 -0
  369. package/src/lib/subjects.ts +64 -0
  370. package/src/lib/utils.ts +6 -0
  371. package/src/lib/ws-bridge.ts +288 -0
  372. package/src/lib/ws-protocol.ts +53 -0
  373. package/src/lib/ws-server.ts +167 -0
  374. package/src/middleware.ts +57 -0
  375. package/src/stores/desktop-store.ts +112 -0
  376. package/src/stores/keybind-store.ts +66 -0
  377. package/src/stores/notification-store.ts +271 -0
  378. package/src/stores/theme-store.ts +25 -0
  379. package/src/stores/window-store.ts +294 -0
  380. package/src/theme/animations.css +68 -0
  381. package/src/theme/base.css +123 -0
  382. package/src/theme/controls.css +35 -0
  383. package/src/theme/design-tokens.css +276 -0
  384. package/src/theme/index.css +23 -0
  385. package/src/theme/menus.css +45 -0
  386. package/src/theme/status.css +41 -0
  387. package/src/theme/surfaces.css +94 -0
  388. package/src/theme/tailwind-map.css +138 -0
  389. package/src/theme/taskbar.css +25 -0
  390. package/src/theme/terminal.css +55 -0
  391. package/src/theme/typography.css +26 -0
  392. package/src/theme/utilities.css +156 -0
  393. package/src/theme/window.css +103 -0
  394. package/src/types/desktop-entry.ts +12 -0
  395. package/src/types/use-descendants.d.ts +13 -0
  396. package/src/types/window.ts +28 -0
  397. package/src/types.d.ts +9 -0
  398. package/tauri/Cargo.lock +5464 -0
  399. package/tauri/Cargo.toml +19 -0
  400. package/tauri/build.rs +3 -0
  401. package/tauri/capabilities/default.json +36 -0
  402. package/tauri/icons/128x128.png +0 -0
  403. package/tauri/icons/128x128@2x.png +0 -0
  404. package/tauri/icons/32x32.png +0 -0
  405. package/tauri/icons/icon.png +0 -0
  406. package/tauri/src/main.rs +396 -0
  407. package/tauri/tauri.conf.json +23 -0
  408. package/tsconfig.json +43 -0
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Teams domain — NATS handlers for team lifecycle management.
3
+ *
4
+ * Exports a ServiceHandler[] array to be spread into the main service subscriptions.
5
+ */
6
+
7
+ import type { ServiceHandler } from '@genie-os/sdk/service';
8
+ import { SUBJECTS } from '../../../lib/subjects';
9
+ import { runGenie, runGenieAsync } from './cli';
10
+
11
+ // Use require() to avoid @types/node dependency (matches index.ts pattern)
12
+ const fs = require('node:fs') as typeof import('node:fs');
13
+ const path = require('node:path') as typeof import('node:path');
14
+
15
+ const TEAMS_DIR = path.join(process.env.HOME ?? '', '.genie', 'teams');
16
+
17
+ export const teamsHandlers: ServiceHandler[] = [
18
+ // --- List all teams ---
19
+ {
20
+ subject: SUBJECTS.teams.list(),
21
+ handler: (msg) => {
22
+ try {
23
+ const result = runGenie<unknown[]>(['team', 'ls', '--json']);
24
+ if (!result.ok) {
25
+ msg.respond(JSON.stringify({ error: result.error, teams: [] }));
26
+ return;
27
+ }
28
+ msg.respond(JSON.stringify({ teams: result.data }));
29
+ } catch (err) {
30
+ msg.respond(JSON.stringify({ error: String(err), teams: [] }));
31
+ }
32
+ },
33
+ },
34
+
35
+ // --- Get full team config ---
36
+ {
37
+ subject: SUBJECTS.teams.get(),
38
+ handler: (msg) => {
39
+ try {
40
+ const req = msg.json<{ name: string }>();
41
+ if (!req.name) {
42
+ msg.respond(JSON.stringify({ error: 'Missing required field: name' }));
43
+ return;
44
+ }
45
+ const teamFile = path.join(TEAMS_DIR, `${req.name}.json`);
46
+ const raw = fs.readFileSync(teamFile, 'utf-8');
47
+ const team = JSON.parse(raw);
48
+ msg.respond(JSON.stringify({ team }));
49
+ } catch (err) {
50
+ msg.respond(JSON.stringify({ error: String(err) }));
51
+ }
52
+ },
53
+ },
54
+
55
+ // --- Create team (async — spawns worktree + team-lead) ---
56
+ {
57
+ subject: SUBJECTS.teams.create(),
58
+ handler: async (msg) => {
59
+ try {
60
+ const req = msg.json<{ name: string; repo: string; branch?: string; wish?: string }>();
61
+ if (!req.name || !req.repo) {
62
+ msg.respond(JSON.stringify({ ok: false, error: 'Missing required fields: name, repo' }));
63
+ return;
64
+ }
65
+
66
+ const args = ['team', 'create', req.name, '--repo', req.repo];
67
+ if (req.branch) args.push('--branch', req.branch);
68
+ if (req.wish) args.push('--wish', req.wish);
69
+
70
+ const result = await runGenieAsync(args, { json: false, timeout: 120_000 });
71
+ if (!result.ok) {
72
+ msg.respond(JSON.stringify({ ok: false, error: result.error }));
73
+ return;
74
+ }
75
+ msg.respond(JSON.stringify({ ok: true, output: result.data }));
76
+ } catch (err) {
77
+ msg.respond(JSON.stringify({ ok: false, error: String(err) }));
78
+ }
79
+ },
80
+ },
81
+
82
+ // --- Disband team ---
83
+ {
84
+ subject: SUBJECTS.teams.disband(),
85
+ handler: (msg) => {
86
+ try {
87
+ const req = msg.json<{ name: string }>();
88
+ if (!req.name) {
89
+ msg.respond(JSON.stringify({ ok: false, error: 'Missing required field: name' }));
90
+ return;
91
+ }
92
+ const result = runGenie(['team', 'disband', req.name], { json: false });
93
+ if (!result.ok) {
94
+ msg.respond(JSON.stringify({ ok: false, error: result.error }));
95
+ return;
96
+ }
97
+ msg.respond(JSON.stringify({ ok: true }));
98
+ } catch (err) {
99
+ msg.respond(JSON.stringify({ ok: false, error: String(err) }));
100
+ }
101
+ },
102
+ },
103
+
104
+ // --- Mark team done ---
105
+ {
106
+ subject: SUBJECTS.teams.done(),
107
+ handler: (msg) => {
108
+ try {
109
+ const req = msg.json<{ name: string }>();
110
+ if (!req.name) {
111
+ msg.respond(JSON.stringify({ ok: false, error: 'Missing required field: name' }));
112
+ return;
113
+ }
114
+ const result = runGenie(['team', 'done', req.name], { json: false });
115
+ if (!result.ok) {
116
+ msg.respond(JSON.stringify({ ok: false, error: result.error }));
117
+ return;
118
+ }
119
+ msg.respond(JSON.stringify({ ok: true }));
120
+ } catch (err) {
121
+ msg.respond(JSON.stringify({ ok: false, error: String(err) }));
122
+ }
123
+ },
124
+ },
125
+
126
+ // --- Mark team blocked ---
127
+ {
128
+ subject: SUBJECTS.teams.blocked(),
129
+ handler: (msg) => {
130
+ try {
131
+ const req = msg.json<{ name: string }>();
132
+ if (!req.name) {
133
+ msg.respond(JSON.stringify({ ok: false, error: 'Missing required field: name' }));
134
+ return;
135
+ }
136
+ const result = runGenie(['team', 'blocked', req.name], { json: false });
137
+ if (!result.ok) {
138
+ msg.respond(JSON.stringify({ ok: false, error: result.error }));
139
+ return;
140
+ }
141
+ msg.respond(JSON.stringify({ ok: true }));
142
+ } catch (err) {
143
+ msg.respond(JSON.stringify({ ok: false, error: String(err) }));
144
+ }
145
+ },
146
+ },
147
+
148
+ // --- Hire agent into team ---
149
+ {
150
+ subject: SUBJECTS.teams.hire(),
151
+ handler: (msg) => {
152
+ try {
153
+ const req = msg.json<{ agent: string; team: string }>();
154
+ if (!req.agent || !req.team) {
155
+ msg.respond(JSON.stringify({ ok: false, error: 'Missing required fields: agent, team' }));
156
+ return;
157
+ }
158
+ const result = runGenie(['team', 'hire', req.agent, '--team', req.team], { json: false });
159
+ if (!result.ok) {
160
+ msg.respond(JSON.stringify({ ok: false, error: result.error }));
161
+ return;
162
+ }
163
+ msg.respond(JSON.stringify({ ok: true, output: result.data }));
164
+ } catch (err) {
165
+ msg.respond(JSON.stringify({ ok: false, error: String(err) }));
166
+ }
167
+ },
168
+ },
169
+
170
+ // --- Fire agent from team ---
171
+ {
172
+ subject: SUBJECTS.teams.fire(),
173
+ handler: (msg) => {
174
+ try {
175
+ const req = msg.json<{ agent: string; team: string }>();
176
+ if (!req.agent || !req.team) {
177
+ msg.respond(JSON.stringify({ ok: false, error: 'Missing required fields: agent, team' }));
178
+ return;
179
+ }
180
+ const result = runGenie(['team', 'fire', req.agent, '--team', req.team], { json: false });
181
+ if (!result.ok) {
182
+ msg.respond(JSON.stringify({ ok: false, error: result.error }));
183
+ return;
184
+ }
185
+ msg.respond(JSON.stringify({ ok: true, output: result.data }));
186
+ } catch (err) {
187
+ msg.respond(JSON.stringify({ ok: false, error: String(err) }));
188
+ }
189
+ },
190
+ },
191
+ ];
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Terminal proxy — uses tmux control mode to stream pane I/O.
3
+ * One control mode connection per tmux session, multiplexing all pane output.
4
+ * Zero linked sessions, zero PTY processes.
5
+ *
6
+ * Subjects:
7
+ * os.genie.term.create → { tmuxPaneId, cols?, rows? } → { sessionId }
8
+ * os.genie.term.destroy → { sessionId }
9
+ * os.genie.term.<id>.data (service → browser, base64)
10
+ * os.genie.term.<id>.input (browser → service, raw text)
11
+ * os.genie.term.<id>.resize (browser → service, cols/rows)
12
+ * os.genie.term.<id>.exit (service → browser)
13
+ */
14
+ // ARCHITECTURE DECISION: Terminal I/O uses tmux control mode (-CC). NEVER use node-pty, linked sessions, or _genie_proxy_* patterns. See wish tmux-control-mode-terminal.
15
+
16
+ import { execSync } from 'node:child_process';
17
+ import { randomUUID } from 'node:crypto';
18
+ import type { NatsConnection } from '@nats-io/transport-node';
19
+ import type { ControlSession, TmuxControl } from './tmux-control';
20
+
21
+ const PREFIX = 'os.genie.term';
22
+
23
+ interface ProxySession {
24
+ sessionId: string;
25
+ tmuxPaneId: string;
26
+ tmuxSessionName: string;
27
+ controlSession: ControlSession;
28
+ outputHandler: (paneId: string, data: Buffer) => void;
29
+ }
30
+
31
+ interface ControlEntry {
32
+ controlSession: ControlSession;
33
+ refCount: number;
34
+ }
35
+
36
+ export function createTerminalProxy(nc: NatsConnection, tmux: TmuxControl) {
37
+ const sessions = new Map<string, ProxySession>();
38
+ const controlSessions = new Map<string, ControlEntry>();
39
+
40
+ function getOrCreateControl(sessionName: string): ControlSession {
41
+ let entry = controlSessions.get(sessionName);
42
+ if (entry) {
43
+ entry.refCount++;
44
+ return entry.controlSession;
45
+ }
46
+
47
+ const cs = tmux.attachSession(sessionName);
48
+ entry = { controlSession: cs, refCount: 1 };
49
+ controlSessions.set(sessionName, entry);
50
+
51
+ // If the control session exits, notify all proxy sessions using it
52
+ cs.on('exit', () => {
53
+ for (const [sid, session] of sessions) {
54
+ if (session.tmuxSessionName === sessionName) {
55
+ nc.publish(`${PREFIX}.${sid}.exit`, JSON.stringify({ sessionId: sid, code: 0 }));
56
+ }
57
+ }
58
+ });
59
+
60
+ return cs;
61
+ }
62
+
63
+ function releaseControl(sessionName: string): void {
64
+ const entry = controlSessions.get(sessionName);
65
+ if (!entry) return;
66
+ entry.refCount--;
67
+ if (entry.refCount <= 0) {
68
+ entry.controlSession.detach();
69
+ controlSessions.delete(sessionName);
70
+ }
71
+ }
72
+
73
+ function create(tmuxPaneId: string, cols = 80, rows = 24): string {
74
+ const sessionId = randomUUID();
75
+
76
+ // Find the tmux session that owns this pane
77
+ let sessionName: string;
78
+ try {
79
+ sessionName = execSync(`tmux display -t '${tmuxPaneId}' -p '#{session_name}'`, {
80
+ encoding: 'utf-8',
81
+ timeout: 3000,
82
+ }).trim();
83
+ } catch {
84
+ throw new Error(`Cannot find tmux pane ${tmuxPaneId}`);
85
+ }
86
+
87
+ const controlSession = getOrCreateControl(sessionName);
88
+
89
+ // Register output listener filtered to this pane
90
+ const outputHandler = (paneId: string, data: Buffer) => {
91
+ if (paneId !== tmuxPaneId) return;
92
+ nc.publish(`${PREFIX}.${sessionId}.data`, JSON.stringify({ sessionId, data: data.toString('base64') }));
93
+ };
94
+ controlSession.on('output', outputHandler);
95
+
96
+ const session: ProxySession = {
97
+ sessionId,
98
+ tmuxPaneId,
99
+ tmuxSessionName: sessionName,
100
+ controlSession,
101
+ outputHandler,
102
+ };
103
+ sessions.set(sessionId, session);
104
+
105
+ // Set initial size
106
+ controlSession.resizeClient(cols, rows);
107
+
108
+ // Initial buffer fill via capture-pane
109
+ try {
110
+ const content = tmux.capturePane(tmuxPaneId);
111
+ if (content) {
112
+ nc.publish(
113
+ `${PREFIX}.${sessionId}.buffer`,
114
+ JSON.stringify({ sessionId, data: Buffer.from(content, 'utf-8').toString('base64') })
115
+ );
116
+ nc.publish(`${PREFIX}.${sessionId}.buffer-end`, JSON.stringify({ sessionId }));
117
+ }
118
+ } catch {
119
+ // capture errors are non-fatal
120
+ }
121
+
122
+ return sessionId;
123
+ }
124
+
125
+ function destroy(sessionId: string): boolean {
126
+ const session = sessions.get(sessionId);
127
+ if (!session) return false;
128
+
129
+ // Unregister the output listener
130
+ session.controlSession.removeListener('output', session.outputHandler);
131
+ sessions.delete(sessionId);
132
+
133
+ // Release control session (detaches when refcount hits zero)
134
+ releaseControl(session.tmuxSessionName);
135
+
136
+ return true;
137
+ }
138
+
139
+ function write(sessionId: string, data: string): void {
140
+ const session = sessions.get(sessionId);
141
+ if (session) {
142
+ session.controlSession.sendKeys(session.tmuxPaneId, data);
143
+ }
144
+ }
145
+
146
+ function resize(sessionId: string, cols: number, rows: number): void {
147
+ const session = sessions.get(sessionId);
148
+ if (session) {
149
+ session.controlSession.resizeClient(Math.max(1, cols), Math.max(1, rows));
150
+ }
151
+ }
152
+
153
+ function replay(sessionId: string): void {
154
+ const session = sessions.get(sessionId);
155
+ if (!session) return;
156
+
157
+ try {
158
+ const content = tmux.capturePane(session.tmuxPaneId);
159
+ if (content) {
160
+ nc.publish(
161
+ `${PREFIX}.${sessionId}.buffer`,
162
+ JSON.stringify({ sessionId, data: Buffer.from(content, 'utf-8').toString('base64') })
163
+ );
164
+ }
165
+ } catch {
166
+ // capture errors are non-fatal
167
+ }
168
+ nc.publish(`${PREFIX}.${sessionId}.buffer-end`, JSON.stringify({ sessionId }));
169
+ }
170
+
171
+ function shutdown(): void {
172
+ // Destroy all proxy sessions
173
+ for (const sessionId of [...sessions.keys()]) {
174
+ destroy(sessionId);
175
+ }
176
+ // Detach any remaining control sessions
177
+ for (const [, entry] of controlSessions) {
178
+ entry.controlSession.detach();
179
+ }
180
+ controlSessions.clear();
181
+ }
182
+
183
+ return { create, destroy, write, resize, replay, shutdown };
184
+ }
@@ -0,0 +1,318 @@
1
+ /**
2
+ * tmux client — uses direct exec for queries (reliable) and
3
+ * control mode for pane I/O streaming + event notifications.
4
+ */
5
+
6
+ import { type ChildProcess, execSync, spawn } from 'node:child_process';
7
+ import { EventEmitter } from 'node:events';
8
+ import * as readline from 'node:readline';
9
+
10
+ function isOctalDigit(ch: string): boolean {
11
+ return ch >= '0' && ch <= '7';
12
+ }
13
+
14
+ function pushUtf8Bytes(bytes: number[], code: number): void {
15
+ if (code <= 0x7f) {
16
+ bytes.push(code);
17
+ } else if (code <= 0x7ff) {
18
+ bytes.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f));
19
+ } else if (code <= 0xffff) {
20
+ bytes.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f));
21
+ } else {
22
+ bytes.push(0xf0 | (code >> 18), 0x80 | ((code >> 12) & 0x3f), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f));
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Decode tmux control mode octal escape format.
28
+ * - \ooo → byte value (3-digit octal)
29
+ * - \\ → literal backslash
30
+ * - All other characters pass through as UTF-8
31
+ */
32
+ export function decodeOctalEscapes(input: string): Buffer {
33
+ const bytes: number[] = [];
34
+ let i = 0;
35
+ while (i < input.length) {
36
+ if (input[i] === '\\' && i + 1 < input.length) {
37
+ if (input[i + 1] === '\\') {
38
+ bytes.push(0x5c);
39
+ i += 2;
40
+ } else if (
41
+ i + 3 < input.length &&
42
+ isOctalDigit(input[i + 1]) &&
43
+ isOctalDigit(input[i + 2]) &&
44
+ isOctalDigit(input[i + 3])
45
+ ) {
46
+ bytes.push(Number.parseInt(input.substring(i + 1, i + 4), 8));
47
+ i += 4;
48
+ } else {
49
+ bytes.push(input.charCodeAt(i));
50
+ i++;
51
+ }
52
+ } else {
53
+ const code = input.codePointAt(i)!;
54
+ pushUtf8Bytes(bytes, code);
55
+ i += code > 0xffff ? 2 : 1;
56
+ }
57
+ }
58
+ return Buffer.from(bytes);
59
+ }
60
+
61
+ /**
62
+ * A control mode connection to a single tmux session.
63
+ * Emits 'output' events with (paneId, data) for all panes in the session.
64
+ * Emits 'exit' when the control connection ends.
65
+ */
66
+ export class ControlSession extends EventEmitter {
67
+ private proc: ChildProcess | null = null;
68
+ private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
69
+ private _connected = false;
70
+ private _detached = false;
71
+
72
+ constructor(readonly sessionName: string) {
73
+ super();
74
+ this.connect();
75
+ }
76
+
77
+ get connected(): boolean {
78
+ return this._connected;
79
+ }
80
+
81
+ private connect(): void {
82
+ if (this._detached) return;
83
+
84
+ // Double -C disables echo of input commands
85
+ this.proc = spawn('tmux', ['-CC', 'attach-session', '-t', this.sessionName], {
86
+ stdio: ['pipe', 'pipe', 'pipe'],
87
+ env: { ...process.env, LC_ALL: 'C.UTF-8', LANG: 'C.UTF-8' },
88
+ });
89
+
90
+ const rl = readline.createInterface({ input: this.proc.stdout! });
91
+
92
+ rl.on('line', (line) => {
93
+ if (!line.startsWith('%')) return;
94
+
95
+ if (line.startsWith('%output ')) {
96
+ this.handleOutput(line);
97
+ } else if (line.startsWith('%exit')) {
98
+ this._connected = false;
99
+ this.emit('exit', line.slice(6).trim());
100
+ }
101
+ // Ignore %begin, %end, %error — those are command responses
102
+ });
103
+
104
+ this.proc.on('close', (code) => {
105
+ this._connected = false;
106
+ this.proc = null;
107
+ if (!this._detached) {
108
+ // Auto-reconnect after 1 second
109
+ this.reconnectTimer = setTimeout(() => this.connect(), 1000);
110
+ }
111
+ this.emit('close', code);
112
+ });
113
+
114
+ this._connected = true;
115
+ }
116
+
117
+ private handleOutput(line: string): void {
118
+ // Format: %output %<pane_id> <data>
119
+ // Find pane ID: starts after "%output " and is like "%0", "%42"
120
+ const afterOutput = line.substring(8); // skip "%output "
121
+ const spaceIdx = afterOutput.indexOf(' ');
122
+ if (spaceIdx === -1) return;
123
+
124
+ const paneId = afterOutput.substring(0, spaceIdx);
125
+ const rawData = afterOutput.substring(spaceIdx + 1);
126
+ const data = decodeOctalEscapes(rawData);
127
+ this.emit('output', paneId, data);
128
+ }
129
+
130
+ /**
131
+ * Send raw input bytes to a pane using hex mode.
132
+ * Converts each byte to two-digit hex for send-keys -H.
133
+ */
134
+ sendKeys(paneId: string, data: string): void {
135
+ if (!this.proc?.stdin?.writable) return;
136
+ const buf = Buffer.from(data, 'utf-8');
137
+ const hex = Array.from(buf)
138
+ .map((b) => b.toString(16).padStart(2, '0'))
139
+ .join(' ');
140
+ this.proc.stdin.write(`send-keys -H -t '${paneId}' ${hex}\n`);
141
+ }
142
+
143
+ /**
144
+ * Resize the control client's view.
145
+ */
146
+ resizeClient(cols: number, rows: number): void {
147
+ if (!this.proc?.stdin?.writable) return;
148
+ this.proc.stdin.write(`refresh-client -C ${cols},${rows}\n`);
149
+ }
150
+
151
+ /**
152
+ * Detach and clean up the control connection.
153
+ */
154
+ detach(): void {
155
+ this._detached = true;
156
+ if (this.reconnectTimer) {
157
+ clearTimeout(this.reconnectTimer);
158
+ this.reconnectTimer = null;
159
+ }
160
+ if (this.proc) {
161
+ this.proc.stdin?.end();
162
+ this.proc.kill();
163
+ this.proc = null;
164
+ }
165
+ this._connected = false;
166
+ this.removeAllListeners();
167
+ }
168
+ }
169
+
170
+ export interface TmuxSession {
171
+ id: string;
172
+ name: string;
173
+ windows: number;
174
+ attached: number;
175
+ created: number;
176
+ }
177
+
178
+ export interface TmuxWindow {
179
+ id: string;
180
+ name: string;
181
+ panes: number;
182
+ active: boolean;
183
+ sessionId: string;
184
+ width: number;
185
+ height: number;
186
+ }
187
+
188
+ export interface TmuxPane {
189
+ id: string;
190
+ windowId: string;
191
+ active: boolean;
192
+ pid: number;
193
+ command: string;
194
+ title: string;
195
+ left: number;
196
+ top: number;
197
+ width: number;
198
+ height: number;
199
+ dead: boolean;
200
+ }
201
+
202
+ /**
203
+ * Run a tmux command and return stdout.
204
+ */
205
+ function tmuxExec(args: string): string {
206
+ return execSync(`tmux ${args}`, { encoding: 'utf-8', timeout: 5000 }).trim();
207
+ }
208
+
209
+ export class TmuxControl extends EventEmitter {
210
+ /**
211
+ * List all tmux sessions.
212
+ */
213
+ listSessions(): TmuxSession[] {
214
+ try {
215
+ const output = tmuxExec(
216
+ "list-sessions -F '#{session_id}|#{session_name}|#{session_windows}|#{session_attached}|#{session_created}'"
217
+ );
218
+ if (!output) return [];
219
+ return output.split('\n').map((line) => {
220
+ const [id, name, windows, attached, created] = line.split('|');
221
+ return {
222
+ id,
223
+ name,
224
+ windows: Number.parseInt(windows, 10),
225
+ attached: Number.parseInt(attached, 10),
226
+ created: Number.parseInt(created, 10),
227
+ };
228
+ });
229
+ } catch {
230
+ return [];
231
+ }
232
+ }
233
+
234
+ /**
235
+ * List all windows across all sessions.
236
+ */
237
+ listWindows(): TmuxWindow[] {
238
+ try {
239
+ const output = tmuxExec(
240
+ "list-windows -a -F '#{window_id}|#{window_name}|#{window_panes}|#{window_active}|#{session_id}|#{window_width}|#{window_height}'"
241
+ );
242
+ if (!output) return [];
243
+ return output.split('\n').map((line) => {
244
+ const [id, name, panes, active, sessionId, width, height] = line.split('|');
245
+ return {
246
+ id,
247
+ name,
248
+ panes: Number.parseInt(panes, 10),
249
+ active: active === '1',
250
+ sessionId,
251
+ width: Number.parseInt(width, 10),
252
+ height: Number.parseInt(height, 10),
253
+ };
254
+ });
255
+ } catch {
256
+ return [];
257
+ }
258
+ }
259
+
260
+ /**
261
+ * List all panes across all sessions.
262
+ */
263
+ listPanes(): TmuxPane[] {
264
+ try {
265
+ const output = tmuxExec(
266
+ "list-panes -a -F '#{pane_id}|#{window_id}|#{pane_active}|#{pane_pid}|#{pane_current_command}|#{pane_title}|#{pane_left}|#{pane_top}|#{pane_width}|#{pane_height}|#{pane_dead}'"
267
+ );
268
+ if (!output) return [];
269
+ return output.split('\n').map((line) => {
270
+ const [id, windowId, active, pid, command, title, left, top, width, height, dead] = line.split('|');
271
+ return {
272
+ id,
273
+ windowId,
274
+ active: active === '1',
275
+ pid: Number.parseInt(pid, 10),
276
+ command,
277
+ title,
278
+ left: Number.parseInt(left, 10),
279
+ top: Number.parseInt(top, 10),
280
+ width: Number.parseInt(width, 10),
281
+ height: Number.parseInt(height, 10),
282
+ dead: dead === '1',
283
+ };
284
+ });
285
+ } catch {
286
+ return [];
287
+ }
288
+ }
289
+
290
+ /**
291
+ * Capture pane content (snapshot).
292
+ */
293
+ capturePane(paneId: string, lines = 50): string {
294
+ try {
295
+ return tmuxExec(`capture-pane -t '${paneId}' -p -S ${-lines} -J`);
296
+ } catch {
297
+ return '';
298
+ }
299
+ }
300
+
301
+ /**
302
+ * Send keys to a pane.
303
+ */
304
+ sendKeys(paneId: string, keys: string): void {
305
+ const escaped = keys.replace(/'/g, "'\\''");
306
+ tmuxExec(`send-keys -t '${paneId}' -l '${escaped}'`);
307
+ tmuxExec(`send-keys -t '${paneId}' Enter`);
308
+ }
309
+
310
+ /**
311
+ * Attach to an existing tmux session in control mode.
312
+ * Returns a ControlSession that streams pane output and accepts input.
313
+ * Creates zero additional tmux sessions.
314
+ */
315
+ attachSession(sessionName: string): ControlSession {
316
+ return new ControlSession(sessionName);
317
+ }
318
+ }