@jlongo78/agent-spaces 0.7.3 → 0.7.5

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 (597) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/app-path-routes-manifest.json +7 -0
  3. package/.next/standalone/.next/build-manifest.json +2 -2
  4. package/.next/standalone/.next/prerender-manifest.json +3 -3
  5. package/.next/standalone/.next/required-server-files.json +19 -19
  6. package/.next/standalone/.next/routes-manifest.json +42 -0
  7. package/.next/standalone/.next/server/app/(desktop)/admin/analytics/page.js +1 -1
  8. package/.next/standalone/.next/server/app/(desktop)/admin/analytics/page.js.nft.json +1 -1
  9. package/.next/standalone/.next/server/app/(desktop)/admin/analytics/page_client-reference-manifest.js +1 -1
  10. package/.next/standalone/.next/server/app/(desktop)/admin/users/page.js +1 -1
  11. package/.next/standalone/.next/server/app/(desktop)/admin/users/page.js.nft.json +1 -1
  12. package/.next/standalone/.next/server/app/(desktop)/admin/users/page_client-reference-manifest.js +1 -1
  13. package/.next/standalone/.next/server/app/(desktop)/analytics/page.js +1 -1
  14. package/.next/standalone/.next/server/app/(desktop)/analytics/page.js.nft.json +1 -1
  15. package/.next/standalone/.next/server/app/(desktop)/analytics/page_client-reference-manifest.js +1 -1
  16. package/.next/standalone/.next/server/app/(desktop)/cortex/page.js +1 -1
  17. package/.next/standalone/.next/server/app/(desktop)/cortex/page.js.nft.json +1 -1
  18. package/.next/standalone/.next/server/app/(desktop)/cortex/page_client-reference-manifest.js +1 -1
  19. package/.next/standalone/.next/server/app/(desktop)/network/page.js +1 -1
  20. package/.next/standalone/.next/server/app/(desktop)/network/page.js.nft.json +1 -1
  21. package/.next/standalone/.next/server/app/(desktop)/network/page_client-reference-manifest.js +1 -1
  22. package/.next/standalone/.next/server/app/(desktop)/page.js +1 -1
  23. package/.next/standalone/.next/server/app/(desktop)/page.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/(desktop)/page_client-reference-manifest.js +1 -1
  25. package/.next/standalone/.next/server/app/(desktop)/projects/page.js +1 -1
  26. package/.next/standalone/.next/server/app/(desktop)/projects/page.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/(desktop)/projects/page_client-reference-manifest.js +1 -1
  28. package/.next/standalone/.next/server/app/(desktop)/sessions/[id]/page.js +1 -1
  29. package/.next/standalone/.next/server/app/(desktop)/sessions/[id]/page.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/(desktop)/sessions/[id]/page_client-reference-manifest.js +1 -1
  31. package/.next/standalone/.next/server/app/(desktop)/sessions/page.js +1 -1
  32. package/.next/standalone/.next/server/app/(desktop)/sessions/page.js.nft.json +1 -1
  33. package/.next/standalone/.next/server/app/(desktop)/sessions/page_client-reference-manifest.js +1 -1
  34. package/.next/standalone/.next/server/app/(desktop)/settings/page.js +1 -1
  35. package/.next/standalone/.next/server/app/(desktop)/settings/page.js.nft.json +1 -1
  36. package/.next/standalone/.next/server/app/(desktop)/settings/page_client-reference-manifest.js +1 -1
  37. package/.next/standalone/.next/server/app/(desktop)/terminal/page.js +1 -1
  38. package/.next/standalone/.next/server/app/(desktop)/terminal/page.js.nft.json +1 -1
  39. package/.next/standalone/.next/server/app/(desktop)/terminal/page_client-reference-manifest.js +1 -1
  40. package/.next/standalone/.next/server/app/(desktop)/terminal/pane/[id]/page.js +1 -1
  41. package/.next/standalone/.next/server/app/(desktop)/terminal/pane/[id]/page.js.nft.json +1 -1
  42. package/.next/standalone/.next/server/app/(desktop)/terminal/pane/[id]/page_client-reference-manifest.js +1 -1
  43. package/.next/standalone/.next/server/app/(desktop)/terminal/remote/[nodeId]/[workspaceId]/page.js +1 -1
  44. package/.next/standalone/.next/server/app/(desktop)/terminal/remote/[nodeId]/[workspaceId]/page.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/(desktop)/terminal/remote/[nodeId]/[workspaceId]/page_client-reference-manifest.js +1 -1
  46. package/.next/standalone/.next/server/app/(desktop)/workspaces/page.js +1 -1
  47. package/.next/standalone/.next/server/app/(desktop)/workspaces/page.js.nft.json +1 -1
  48. package/.next/standalone/.next/server/app/(desktop)/workspaces/page_client-reference-manifest.js +1 -1
  49. package/.next/standalone/.next/server/app/_global-error.html +2 -2
  50. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  51. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  52. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  53. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  54. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  55. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  56. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  57. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  58. package/.next/standalone/.next/server/app/_not-found.rsc +2 -2
  59. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  60. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  61. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  62. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  63. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  64. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  65. package/.next/standalone/.next/server/app/admin/analytics.html +1 -1
  66. package/.next/standalone/.next/server/app/admin/analytics.rsc +17 -16
  67. package/.next/standalone/.next/server/app/admin/analytics.segments/!KGRlc2t0b3Ap/admin/analytics/__PAGE__.segment.rsc +2 -2
  68. package/.next/standalone/.next/server/app/admin/analytics.segments/!KGRlc2t0b3Ap/admin/analytics.segment.rsc +1 -1
  69. package/.next/standalone/.next/server/app/admin/analytics.segments/!KGRlc2t0b3Ap/admin.segment.rsc +1 -1
  70. package/.next/standalone/.next/server/app/admin/analytics.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  71. package/.next/standalone/.next/server/app/admin/analytics.segments/_full.segment.rsc +17 -16
  72. package/.next/standalone/.next/server/app/admin/analytics.segments/_head.segment.rsc +1 -1
  73. package/.next/standalone/.next/server/app/admin/analytics.segments/_index.segment.rsc +2 -2
  74. package/.next/standalone/.next/server/app/admin/analytics.segments/_tree.segment.rsc +2 -2
  75. package/.next/standalone/.next/server/app/admin/users.html +1 -1
  76. package/.next/standalone/.next/server/app/admin/users.rsc +17 -16
  77. package/.next/standalone/.next/server/app/admin/users.segments/!KGRlc2t0b3Ap/admin/users/__PAGE__.segment.rsc +2 -2
  78. package/.next/standalone/.next/server/app/admin/users.segments/!KGRlc2t0b3Ap/admin/users.segment.rsc +1 -1
  79. package/.next/standalone/.next/server/app/admin/users.segments/!KGRlc2t0b3Ap/admin.segment.rsc +1 -1
  80. package/.next/standalone/.next/server/app/admin/users.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  81. package/.next/standalone/.next/server/app/admin/users.segments/_full.segment.rsc +17 -16
  82. package/.next/standalone/.next/server/app/admin/users.segments/_head.segment.rsc +1 -1
  83. package/.next/standalone/.next/server/app/admin/users.segments/_index.segment.rsc +2 -2
  84. package/.next/standalone/.next/server/app/admin/users.segments/_tree.segment.rsc +2 -2
  85. package/.next/standalone/.next/server/app/analytics.html +1 -1
  86. package/.next/standalone/.next/server/app/analytics.rsc +17 -16
  87. package/.next/standalone/.next/server/app/analytics.segments/!KGRlc2t0b3Ap/analytics/__PAGE__.segment.rsc +2 -2
  88. package/.next/standalone/.next/server/app/analytics.segments/!KGRlc2t0b3Ap/analytics.segment.rsc +1 -1
  89. package/.next/standalone/.next/server/app/analytics.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  90. package/.next/standalone/.next/server/app/analytics.segments/_full.segment.rsc +17 -16
  91. package/.next/standalone/.next/server/app/analytics.segments/_head.segment.rsc +1 -1
  92. package/.next/standalone/.next/server/app/analytics.segments/_index.segment.rsc +2 -2
  93. package/.next/standalone/.next/server/app/analytics.segments/_tree.segment.rsc +2 -2
  94. package/.next/standalone/.next/server/app/api/analytics/overview/route.js.nft.json +1 -1
  95. package/.next/standalone/.next/server/app/api/bulk/route.js.nft.json +1 -1
  96. package/.next/standalone/.next/server/app/api/chat/route.js +1 -1
  97. package/.next/standalone/.next/server/app/api/chat/route.js.nft.json +1 -1
  98. package/.next/standalone/.next/server/app/api/config/route.js.nft.json +1 -1
  99. package/.next/standalone/.next/server/app/api/cortex/context/route.js.nft.json +1 -1
  100. package/.next/standalone/.next/server/app/api/cortex/curation/assess/route/app-paths-manifest.json +3 -0
  101. package/.next/standalone/.next/server/app/api/cortex/curation/assess/route/build-manifest.json +11 -0
  102. package/.next/standalone/.next/server/app/api/cortex/curation/assess/route/server-reference-manifest.json +4 -0
  103. package/.next/standalone/.next/server/app/api/cortex/curation/assess/route.js +7 -0
  104. package/.next/standalone/.next/server/app/api/cortex/curation/assess/route.js.map +5 -0
  105. package/.next/standalone/.next/server/app/api/cortex/curation/assess/route.js.nft.json +1 -0
  106. package/.next/standalone/.next/server/app/api/cortex/curation/assess/route_client-reference-manifest.js +2 -0
  107. package/.next/standalone/.next/server/app/api/cortex/curation/publish/route/app-paths-manifest.json +3 -0
  108. package/.next/standalone/.next/server/app/api/cortex/curation/publish/route/build-manifest.json +11 -0
  109. package/.next/standalone/.next/server/app/api/cortex/curation/publish/route/server-reference-manifest.json +4 -0
  110. package/.next/standalone/.next/server/app/api/cortex/curation/publish/route.js +7 -0
  111. package/.next/standalone/.next/server/app/api/cortex/curation/publish/route.js.map +5 -0
  112. package/.next/standalone/.next/server/app/api/cortex/curation/publish/route.js.nft.json +1 -0
  113. package/.next/standalone/.next/server/app/api/cortex/curation/publish/route_client-reference-manifest.js +2 -0
  114. package/.next/standalone/.next/server/app/api/cortex/curation/refine/route/app-paths-manifest.json +3 -0
  115. package/.next/standalone/.next/server/app/api/cortex/curation/refine/route/build-manifest.json +11 -0
  116. package/.next/standalone/.next/server/app/api/cortex/curation/refine/route/server-reference-manifest.json +4 -0
  117. package/.next/standalone/.next/server/app/api/cortex/curation/refine/route.js +7 -0
  118. package/.next/standalone/.next/server/app/api/cortex/curation/refine/route.js.map +5 -0
  119. package/.next/standalone/.next/server/app/api/cortex/curation/refine/route.js.nft.json +1 -0
  120. package/.next/standalone/.next/server/app/api/cortex/curation/refine/route_client-reference-manifest.js +2 -0
  121. package/.next/standalone/.next/server/app/api/cortex/curation/review/route/app-paths-manifest.json +3 -0
  122. package/.next/standalone/.next/server/app/api/cortex/curation/review/route/build-manifest.json +11 -0
  123. package/.next/standalone/.next/server/app/api/cortex/curation/review/route/server-reference-manifest.json +4 -0
  124. package/.next/standalone/.next/server/app/api/cortex/curation/review/route.js +7 -0
  125. package/.next/standalone/.next/server/app/api/cortex/curation/review/route.js.map +5 -0
  126. package/.next/standalone/.next/server/app/api/cortex/curation/review/route.js.nft.json +1 -0
  127. package/.next/standalone/.next/server/app/api/cortex/curation/review/route_client-reference-manifest.js +2 -0
  128. package/.next/standalone/.next/server/app/api/cortex/curation/seed/route/app-paths-manifest.json +3 -0
  129. package/.next/standalone/.next/server/app/api/cortex/curation/seed/route/build-manifest.json +11 -0
  130. package/.next/standalone/.next/server/app/api/cortex/curation/seed/route/server-reference-manifest.json +4 -0
  131. package/.next/standalone/.next/server/app/api/cortex/curation/seed/route.js +7 -0
  132. package/.next/standalone/.next/server/app/api/cortex/curation/seed/route.js.map +5 -0
  133. package/.next/standalone/.next/server/app/api/cortex/curation/seed/route.js.nft.json +1 -0
  134. package/.next/standalone/.next/server/app/api/cortex/curation/seed/route_client-reference-manifest.js +2 -0
  135. package/.next/standalone/.next/server/app/api/cortex/export/route.js.nft.json +1 -1
  136. package/.next/standalone/.next/server/app/api/cortex/federation/pending/route.js.nft.json +1 -1
  137. package/.next/standalone/.next/server/app/api/cortex/federation/resolve/route.js.nft.json +1 -1
  138. package/.next/standalone/.next/server/app/api/cortex/federation/search/route.js.nft.json +1 -1
  139. package/.next/standalone/.next/server/app/api/cortex/federation/teach/route.js.nft.json +1 -1
  140. package/.next/standalone/.next/server/app/api/cortex/graph/edges/route.js.nft.json +1 -1
  141. package/.next/standalone/.next/server/app/api/cortex/graph/entities/[id]/route.js.nft.json +1 -1
  142. package/.next/standalone/.next/server/app/api/cortex/graph/entities/route.js.nft.json +1 -1
  143. package/.next/standalone/.next/server/app/api/cortex/graph/populate/route.js.nft.json +1 -1
  144. package/.next/standalone/.next/server/app/api/cortex/import/route.js.nft.json +1 -1
  145. package/.next/standalone/.next/server/app/api/cortex/import/status/route.js.nft.json +1 -1
  146. package/.next/standalone/.next/server/app/api/cortex/ingest/bootstrap/route.js.nft.json +1 -1
  147. package/.next/standalone/.next/server/app/api/cortex/ingest/status/route.js.nft.json +1 -1
  148. package/.next/standalone/.next/server/app/api/cortex/knowledge/[id]/route.js.nft.json +1 -1
  149. package/.next/standalone/.next/server/app/api/cortex/knowledge/route.js.nft.json +1 -1
  150. package/.next/standalone/.next/server/app/api/cortex/lobes/[id]/route.js.nft.json +1 -1
  151. package/.next/standalone/.next/server/app/api/cortex/lobes/route.js.nft.json +1 -1
  152. package/.next/standalone/.next/server/app/api/cortex/lobes/share/route.js.nft.json +1 -1
  153. package/.next/standalone/.next/server/app/api/cortex/marketplace/browse/route/app-paths-manifest.json +3 -0
  154. package/.next/standalone/.next/server/app/api/cortex/marketplace/browse/route/build-manifest.json +11 -0
  155. package/.next/standalone/.next/server/app/api/cortex/marketplace/browse/route/server-reference-manifest.json +4 -0
  156. package/.next/standalone/.next/server/app/api/cortex/marketplace/browse/route.js +7 -0
  157. package/.next/standalone/.next/server/app/api/cortex/marketplace/browse/route.js.map +5 -0
  158. package/.next/standalone/.next/server/app/api/cortex/marketplace/browse/route.js.nft.json +1 -0
  159. package/.next/standalone/.next/server/app/api/cortex/marketplace/browse/route_client-reference-manifest.js +2 -0
  160. package/.next/standalone/.next/server/app/api/cortex/marketplace/preview/route/app-paths-manifest.json +3 -0
  161. package/.next/standalone/.next/server/app/api/cortex/marketplace/preview/route/build-manifest.json +11 -0
  162. package/.next/standalone/.next/server/app/api/cortex/marketplace/preview/route/server-reference-manifest.json +4 -0
  163. package/.next/standalone/.next/server/app/api/cortex/marketplace/preview/route.js +7 -0
  164. package/.next/standalone/.next/server/app/api/cortex/marketplace/preview/route.js.map +5 -0
  165. package/.next/standalone/.next/server/app/api/cortex/marketplace/preview/route.js.nft.json +1 -0
  166. package/.next/standalone/.next/server/app/api/cortex/marketplace/preview/route_client-reference-manifest.js +2 -0
  167. package/.next/standalone/.next/server/app/api/cortex/mcp/call/route.js.nft.json +1 -1
  168. package/.next/standalone/.next/server/app/api/cortex/mcp/tools/route.js.nft.json +1 -1
  169. package/.next/standalone/.next/server/app/api/cortex/search/route.js.nft.json +1 -1
  170. package/.next/standalone/.next/server/app/api/cortex/settings/route.js.nft.json +1 -1
  171. package/.next/standalone/.next/server/app/api/cortex/status/route.js.nft.json +1 -1
  172. package/.next/standalone/.next/server/app/api/cortex/timeline/route.js.nft.json +1 -1
  173. package/.next/standalone/.next/server/app/api/cortex/usage/route.js.nft.json +1 -1
  174. package/.next/standalone/.next/server/app/api/cortex/workspace/[id]/context/route.js.nft.json +1 -1
  175. package/.next/standalone/.next/server/app/api/events/route.js.nft.json +1 -1
  176. package/.next/standalone/.next/server/app/api/folders/route.js.nft.json +1 -1
  177. package/.next/standalone/.next/server/app/api/network/handshake/route.js.nft.json +1 -1
  178. package/.next/standalone/.next/server/app/api/network/projects/route.js.nft.json +1 -1
  179. package/.next/standalone/.next/server/app/api/network/search/route.js.nft.json +1 -1
  180. package/.next/standalone/.next/server/app/api/network/sessions/[id]/messages/route.js.nft.json +1 -1
  181. package/.next/standalone/.next/server/app/api/network/sessions/[id]/route.js.nft.json +1 -1
  182. package/.next/standalone/.next/server/app/api/network/sessions/route.js.nft.json +1 -1
  183. package/.next/standalone/.next/server/app/api/network/workspaces/[id]/route.js.nft.json +1 -1
  184. package/.next/standalone/.next/server/app/api/network/workspaces/route.js +1 -1
  185. package/.next/standalone/.next/server/app/api/network/workspaces/route.js.nft.json +1 -1
  186. package/.next/standalone/.next/server/app/api/panes/[id]/route.js.nft.json +1 -1
  187. package/.next/standalone/.next/server/app/api/panes/route.js.nft.json +1 -1
  188. package/.next/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  189. package/.next/standalone/.next/server/app/api/search/route.js.nft.json +1 -1
  190. package/.next/standalone/.next/server/app/api/sessions/[id]/chat/route.js.nft.json +1 -1
  191. package/.next/standalone/.next/server/app/api/sessions/[id]/messages/route.js.nft.json +1 -1
  192. package/.next/standalone/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -1
  193. package/.next/standalone/.next/server/app/api/sessions/route.js.nft.json +1 -1
  194. package/.next/standalone/.next/server/app/api/sync/route.js.nft.json +1 -1
  195. package/.next/standalone/.next/server/app/api/tags/route.js.nft.json +1 -1
  196. package/.next/standalone/.next/server/app/api/tier/route.js.nft.json +1 -1
  197. package/.next/standalone/.next/server/app/api/workspaces/[id]/context/[key]/route.js.nft.json +1 -1
  198. package/.next/standalone/.next/server/app/api/workspaces/[id]/context/route.js.nft.json +1 -1
  199. package/.next/standalone/.next/server/app/api/workspaces/[id]/messages/[msgId]/route.js.nft.json +1 -1
  200. package/.next/standalone/.next/server/app/api/workspaces/[id]/messages/route.js.nft.json +1 -1
  201. package/.next/standalone/.next/server/app/api/workspaces/[id]/route.js.nft.json +1 -1
  202. package/.next/standalone/.next/server/app/api/workspaces/[id]/sessions/route.js.nft.json +1 -1
  203. package/.next/standalone/.next/server/app/api/workspaces/route.js.nft.json +1 -1
  204. package/.next/standalone/.next/server/app/cortex.html +1 -1
  205. package/.next/standalone/.next/server/app/cortex.rsc +17 -16
  206. package/.next/standalone/.next/server/app/cortex.segments/!KGRlc2t0b3Ap/cortex/__PAGE__.segment.rsc +2 -2
  207. package/.next/standalone/.next/server/app/cortex.segments/!KGRlc2t0b3Ap/cortex.segment.rsc +1 -1
  208. package/.next/standalone/.next/server/app/cortex.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  209. package/.next/standalone/.next/server/app/cortex.segments/_full.segment.rsc +17 -16
  210. package/.next/standalone/.next/server/app/cortex.segments/_head.segment.rsc +1 -1
  211. package/.next/standalone/.next/server/app/cortex.segments/_index.segment.rsc +2 -2
  212. package/.next/standalone/.next/server/app/cortex.segments/_tree.segment.rsc +2 -2
  213. package/.next/standalone/.next/server/app/login/page_client-reference-manifest.js +1 -1
  214. package/.next/standalone/.next/server/app/login.html +1 -1
  215. package/.next/standalone/.next/server/app/login.rsc +2 -2
  216. package/.next/standalone/.next/server/app/login.segments/_full.segment.rsc +2 -2
  217. package/.next/standalone/.next/server/app/login.segments/_head.segment.rsc +1 -1
  218. package/.next/standalone/.next/server/app/login.segments/_index.segment.rsc +2 -2
  219. package/.next/standalone/.next/server/app/login.segments/_tree.segment.rsc +2 -2
  220. package/.next/standalone/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
  221. package/.next/standalone/.next/server/app/login.segments/login.segment.rsc +1 -1
  222. package/.next/standalone/.next/server/app/m/page.js.nft.json +1 -1
  223. package/.next/standalone/.next/server/app/m/page_client-reference-manifest.js +1 -1
  224. package/.next/standalone/.next/server/app/m/projects/page.js.nft.json +1 -1
  225. package/.next/standalone/.next/server/app/m/projects/page_client-reference-manifest.js +1 -1
  226. package/.next/standalone/.next/server/app/m/projects.html +1 -1
  227. package/.next/standalone/.next/server/app/m/projects.rsc +4 -4
  228. package/.next/standalone/.next/server/app/m/projects.segments/_full.segment.rsc +4 -4
  229. package/.next/standalone/.next/server/app/m/projects.segments/_head.segment.rsc +1 -1
  230. package/.next/standalone/.next/server/app/m/projects.segments/_index.segment.rsc +2 -2
  231. package/.next/standalone/.next/server/app/m/projects.segments/_tree.segment.rsc +2 -2
  232. package/.next/standalone/.next/server/app/m/projects.segments/m/projects/__PAGE__.segment.rsc +2 -2
  233. package/.next/standalone/.next/server/app/m/projects.segments/m/projects.segment.rsc +1 -1
  234. package/.next/standalone/.next/server/app/m/projects.segments/m.segment.rsc +2 -2
  235. package/.next/standalone/.next/server/app/m/sessions/[id]/page.js.nft.json +1 -1
  236. package/.next/standalone/.next/server/app/m/sessions/[id]/page_client-reference-manifest.js +1 -1
  237. package/.next/standalone/.next/server/app/m/sessions/page.js.nft.json +1 -1
  238. package/.next/standalone/.next/server/app/m/sessions/page_client-reference-manifest.js +1 -1
  239. package/.next/standalone/.next/server/app/m/sessions.html +1 -1
  240. package/.next/standalone/.next/server/app/m/sessions.rsc +4 -4
  241. package/.next/standalone/.next/server/app/m/sessions.segments/_full.segment.rsc +4 -4
  242. package/.next/standalone/.next/server/app/m/sessions.segments/_head.segment.rsc +1 -1
  243. package/.next/standalone/.next/server/app/m/sessions.segments/_index.segment.rsc +2 -2
  244. package/.next/standalone/.next/server/app/m/sessions.segments/_tree.segment.rsc +2 -2
  245. package/.next/standalone/.next/server/app/m/sessions.segments/m/sessions/__PAGE__.segment.rsc +2 -2
  246. package/.next/standalone/.next/server/app/m/sessions.segments/m/sessions.segment.rsc +1 -1
  247. package/.next/standalone/.next/server/app/m/sessions.segments/m.segment.rsc +2 -2
  248. package/.next/standalone/.next/server/app/m/settings/page.js.nft.json +1 -1
  249. package/.next/standalone/.next/server/app/m/settings/page_client-reference-manifest.js +1 -1
  250. package/.next/standalone/.next/server/app/m/settings.html +1 -1
  251. package/.next/standalone/.next/server/app/m/settings.rsc +4 -4
  252. package/.next/standalone/.next/server/app/m/settings.segments/_full.segment.rsc +4 -4
  253. package/.next/standalone/.next/server/app/m/settings.segments/_head.segment.rsc +1 -1
  254. package/.next/standalone/.next/server/app/m/settings.segments/_index.segment.rsc +2 -2
  255. package/.next/standalone/.next/server/app/m/settings.segments/_tree.segment.rsc +2 -2
  256. package/.next/standalone/.next/server/app/m/settings.segments/m/settings/__PAGE__.segment.rsc +2 -2
  257. package/.next/standalone/.next/server/app/m/settings.segments/m/settings.segment.rsc +1 -1
  258. package/.next/standalone/.next/server/app/m/settings.segments/m.segment.rsc +2 -2
  259. package/.next/standalone/.next/server/app/m/terminal/page.js.nft.json +1 -1
  260. package/.next/standalone/.next/server/app/m/terminal/page_client-reference-manifest.js +1 -1
  261. package/.next/standalone/.next/server/app/m/terminal.html +1 -1
  262. package/.next/standalone/.next/server/app/m/terminal.rsc +4 -4
  263. package/.next/standalone/.next/server/app/m/terminal.segments/_full.segment.rsc +4 -4
  264. package/.next/standalone/.next/server/app/m/terminal.segments/_head.segment.rsc +1 -1
  265. package/.next/standalone/.next/server/app/m/terminal.segments/_index.segment.rsc +2 -2
  266. package/.next/standalone/.next/server/app/m/terminal.segments/_tree.segment.rsc +2 -2
  267. package/.next/standalone/.next/server/app/m/terminal.segments/m/terminal/__PAGE__.segment.rsc +2 -2
  268. package/.next/standalone/.next/server/app/m/terminal.segments/m/terminal.segment.rsc +1 -1
  269. package/.next/standalone/.next/server/app/m/terminal.segments/m.segment.rsc +2 -2
  270. package/.next/standalone/.next/server/app/m.html +1 -1
  271. package/.next/standalone/.next/server/app/m.rsc +4 -4
  272. package/.next/standalone/.next/server/app/m.segments/_full.segment.rsc +4 -4
  273. package/.next/standalone/.next/server/app/m.segments/_head.segment.rsc +1 -1
  274. package/.next/standalone/.next/server/app/m.segments/_index.segment.rsc +2 -2
  275. package/.next/standalone/.next/server/app/m.segments/_tree.segment.rsc +2 -2
  276. package/.next/standalone/.next/server/app/m.segments/m/__PAGE__.segment.rsc +2 -2
  277. package/.next/standalone/.next/server/app/m.segments/m.segment.rsc +2 -2
  278. package/.next/standalone/.next/server/app/network.html +1 -1
  279. package/.next/standalone/.next/server/app/network.rsc +17 -16
  280. package/.next/standalone/.next/server/app/network.segments/!KGRlc2t0b3Ap/network/__PAGE__.segment.rsc +2 -2
  281. package/.next/standalone/.next/server/app/network.segments/!KGRlc2t0b3Ap/network.segment.rsc +1 -1
  282. package/.next/standalone/.next/server/app/network.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  283. package/.next/standalone/.next/server/app/network.segments/_full.segment.rsc +17 -16
  284. package/.next/standalone/.next/server/app/network.segments/_head.segment.rsc +1 -1
  285. package/.next/standalone/.next/server/app/network.segments/_index.segment.rsc +2 -2
  286. package/.next/standalone/.next/server/app/network.segments/_tree.segment.rsc +2 -2
  287. package/.next/standalone/.next/server/app/projects.html +1 -1
  288. package/.next/standalone/.next/server/app/projects.rsc +17 -16
  289. package/.next/standalone/.next/server/app/projects.segments/!KGRlc2t0b3Ap/projects/__PAGE__.segment.rsc +2 -2
  290. package/.next/standalone/.next/server/app/projects.segments/!KGRlc2t0b3Ap/projects.segment.rsc +1 -1
  291. package/.next/standalone/.next/server/app/projects.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  292. package/.next/standalone/.next/server/app/projects.segments/_full.segment.rsc +17 -16
  293. package/.next/standalone/.next/server/app/projects.segments/_head.segment.rsc +1 -1
  294. package/.next/standalone/.next/server/app/projects.segments/_index.segment.rsc +2 -2
  295. package/.next/standalone/.next/server/app/projects.segments/_tree.segment.rsc +2 -2
  296. package/.next/standalone/.next/server/app/sessions.html +1 -1
  297. package/.next/standalone/.next/server/app/sessions.rsc +17 -16
  298. package/.next/standalone/.next/server/app/sessions.segments/!KGRlc2t0b3Ap/sessions/__PAGE__.segment.rsc +2 -2
  299. package/.next/standalone/.next/server/app/sessions.segments/!KGRlc2t0b3Ap/sessions.segment.rsc +1 -1
  300. package/.next/standalone/.next/server/app/sessions.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  301. package/.next/standalone/.next/server/app/sessions.segments/_full.segment.rsc +17 -16
  302. package/.next/standalone/.next/server/app/sessions.segments/_head.segment.rsc +1 -1
  303. package/.next/standalone/.next/server/app/sessions.segments/_index.segment.rsc +2 -2
  304. package/.next/standalone/.next/server/app/sessions.segments/_tree.segment.rsc +2 -2
  305. package/.next/standalone/.next/server/app/settings.html +1 -1
  306. package/.next/standalone/.next/server/app/settings.rsc +17 -16
  307. package/.next/standalone/.next/server/app/settings.segments/!KGRlc2t0b3Ap/settings/__PAGE__.segment.rsc +2 -2
  308. package/.next/standalone/.next/server/app/settings.segments/!KGRlc2t0b3Ap/settings.segment.rsc +1 -1
  309. package/.next/standalone/.next/server/app/settings.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  310. package/.next/standalone/.next/server/app/settings.segments/_full.segment.rsc +17 -16
  311. package/.next/standalone/.next/server/app/settings.segments/_head.segment.rsc +1 -1
  312. package/.next/standalone/.next/server/app/settings.segments/_index.segment.rsc +2 -2
  313. package/.next/standalone/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
  314. package/.next/standalone/.next/server/app/terminal.html +1 -1
  315. package/.next/standalone/.next/server/app/terminal.rsc +17 -16
  316. package/.next/standalone/.next/server/app/terminal.segments/!KGRlc2t0b3Ap/terminal/__PAGE__.segment.rsc +2 -2
  317. package/.next/standalone/.next/server/app/terminal.segments/!KGRlc2t0b3Ap/terminal.segment.rsc +1 -1
  318. package/.next/standalone/.next/server/app/terminal.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  319. package/.next/standalone/.next/server/app/terminal.segments/_full.segment.rsc +17 -16
  320. package/.next/standalone/.next/server/app/terminal.segments/_head.segment.rsc +1 -1
  321. package/.next/standalone/.next/server/app/terminal.segments/_index.segment.rsc +2 -2
  322. package/.next/standalone/.next/server/app/terminal.segments/_tree.segment.rsc +2 -2
  323. package/.next/standalone/.next/server/app/workspaces.html +1 -1
  324. package/.next/standalone/.next/server/app/workspaces.rsc +17 -16
  325. package/.next/standalone/.next/server/app/workspaces.segments/!KGRlc2t0b3Ap/workspaces/__PAGE__.segment.rsc +2 -2
  326. package/.next/standalone/.next/server/app/workspaces.segments/!KGRlc2t0b3Ap/workspaces.segment.rsc +1 -1
  327. package/.next/standalone/.next/server/app/workspaces.segments/!KGRlc2t0b3Ap.segment.rsc +5 -4
  328. package/.next/standalone/.next/server/app/workspaces.segments/_full.segment.rsc +17 -16
  329. package/.next/standalone/.next/server/app/workspaces.segments/_head.segment.rsc +1 -1
  330. package/.next/standalone/.next/server/app/workspaces.segments/_index.segment.rsc +2 -2
  331. package/.next/standalone/.next/server/app/workspaces.segments/_tree.segment.rsc +2 -2
  332. package/.next/standalone/.next/server/app-paths-manifest.json +7 -0
  333. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0041efe4._.js +98 -0
  334. package/.next/standalone/.next/server/chunks/[root-of-the-server]__00bf0ace._.js +2 -2
  335. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0e71d908._.js +2 -2
  336. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0e9142f3._.js +2 -2
  337. package/.next/standalone/.next/server/chunks/[root-of-the-server]__10e47926._.js +1 -1
  338. package/.next/standalone/.next/server/chunks/[root-of-the-server]__1665dc78._.js +2 -2
  339. package/.next/standalone/.next/server/chunks/[root-of-the-server]__175cbabf._.js +2 -2
  340. package/.next/standalone/.next/server/chunks/[root-of-the-server]__1adae357._.js +2 -2
  341. package/.next/standalone/.next/server/chunks/[root-of-the-server]__1d359752._.js +2 -2
  342. package/.next/standalone/.next/server/chunks/[root-of-the-server]__1e8fabeb._.js +3 -3
  343. package/.next/standalone/.next/server/chunks/[root-of-the-server]__1f8deca0._.js +8 -8
  344. package/.next/standalone/.next/server/chunks/[root-of-the-server]__253fdda1._.js +2 -2
  345. package/.next/standalone/.next/server/chunks/[root-of-the-server]__28e6434f._.js +2 -2
  346. package/.next/standalone/.next/server/chunks/[root-of-the-server]__2a386564._.js +1 -1
  347. package/.next/standalone/.next/server/chunks/[root-of-the-server]__2c20fb38._.js +2 -2
  348. package/.next/standalone/.next/server/chunks/[root-of-the-server]__309132cd._.js +1 -1
  349. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__cf3c60c2._.js → [root-of-the-server]__33fec964._.js} +4 -4
  350. package/.next/standalone/.next/server/chunks/[root-of-the-server]__3786d8ae._.js +1 -1
  351. package/.next/standalone/.next/server/chunks/[root-of-the-server]__3ae92407._.js +2 -2
  352. package/.next/standalone/.next/server/chunks/[root-of-the-server]__3beda9fe._.js +2 -2
  353. package/.next/standalone/.next/server/chunks/[root-of-the-server]__4619e9bd._.js +1 -1
  354. package/.next/standalone/.next/server/chunks/[root-of-the-server]__4a051043._.js +1 -1
  355. package/.next/standalone/.next/server/chunks/[root-of-the-server]__508002e4._.js +2 -2
  356. package/.next/standalone/.next/server/chunks/[root-of-the-server]__5086c373._.js +2 -2
  357. package/.next/standalone/.next/server/chunks/[root-of-the-server]__5913e097._.js +2 -2
  358. package/.next/standalone/.next/server/chunks/[root-of-the-server]__5b5f68d2._.js +2 -2
  359. package/.next/standalone/.next/server/chunks/[root-of-the-server]__5c1f2459._.js +2 -2
  360. package/.next/standalone/.next/server/chunks/[root-of-the-server]__5ec8c977._.js +2 -2
  361. package/.next/standalone/.next/server/chunks/[root-of-the-server]__63cebc6c._.js +98 -0
  362. package/.next/standalone/.next/server/chunks/[root-of-the-server]__64d30d4d._.js +2 -2
  363. package/.next/standalone/.next/server/chunks/[root-of-the-server]__6c54fc2e._.js +2 -2
  364. package/.next/standalone/.next/server/chunks/[root-of-the-server]__6dc1fb7e._.js +1 -1
  365. package/.next/standalone/.next/server/chunks/[root-of-the-server]__6e568102._.js +1 -1
  366. package/.next/standalone/.next/server/chunks/[root-of-the-server]__6faa04c0._.js +2 -2
  367. package/.next/standalone/.next/server/chunks/[root-of-the-server]__74a34dc3._.js +98 -0
  368. package/.next/standalone/.next/server/chunks/[root-of-the-server]__7e7250a4._.js +3 -3
  369. package/.next/standalone/.next/server/chunks/[root-of-the-server]__8309e0a4._.js +2 -2
  370. package/.next/standalone/.next/server/chunks/[root-of-the-server]__86cc0e2b._.js +6 -6
  371. package/.next/standalone/.next/server/chunks/[root-of-the-server]__89c2565a._.js +2 -2
  372. package/.next/standalone/.next/server/chunks/[root-of-the-server]__8d178ad9._.js +2 -2
  373. package/.next/standalone/.next/server/chunks/[root-of-the-server]__93ee06f3._.js +3 -3
  374. package/.next/standalone/.next/server/chunks/[root-of-the-server]__9e4c154a._.js +2 -2
  375. package/.next/standalone/.next/server/chunks/[root-of-the-server]__a9d2e1d3._.js +2 -2
  376. package/.next/standalone/.next/server/chunks/[root-of-the-server]__ae53d343._.js +2 -2
  377. package/.next/standalone/.next/server/chunks/[root-of-the-server]__b3a04cef._.js +2 -2
  378. package/.next/standalone/.next/server/chunks/[root-of-the-server]__b4270b77._.js +3 -0
  379. package/.next/standalone/.next/server/chunks/[root-of-the-server]__b6b6ce60._.js +1 -1
  380. package/.next/standalone/.next/server/chunks/[root-of-the-server]__b9545dd9._.js +1 -1
  381. package/.next/standalone/.next/server/chunks/[root-of-the-server]__c88b63f7._.js +98 -0
  382. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__eee4c5e8._.js → [root-of-the-server]__cba5f007._.js} +2 -2
  383. package/.next/standalone/.next/server/chunks/[root-of-the-server]__cbf4ceb0._.js +2 -2
  384. package/.next/standalone/.next/server/chunks/[root-of-the-server]__cefdba2f._.js +2 -2
  385. package/.next/standalone/.next/server/chunks/[root-of-the-server]__cf9e82bb._.js +2 -2
  386. package/.next/standalone/.next/server/chunks/[root-of-the-server]__d2897392._.js +2 -2
  387. package/.next/standalone/.next/server/chunks/[root-of-the-server]__d3b2d856._.js +2 -2
  388. package/.next/standalone/.next/server/chunks/[root-of-the-server]__d73273ca._.js +1 -1
  389. package/.next/standalone/.next/server/chunks/[root-of-the-server]__d8417eb6._.js +2 -2
  390. package/.next/standalone/.next/server/chunks/[root-of-the-server]__dc2a55de._.js +2 -2
  391. package/.next/standalone/.next/server/chunks/[root-of-the-server]__e0d4690b._.js +3 -3
  392. package/.next/standalone/.next/server/chunks/[root-of-the-server]__e678dd53._.js +3 -0
  393. package/.next/standalone/.next/server/chunks/[root-of-the-server]__e9223f55._.js +2 -2
  394. package/.next/standalone/.next/server/chunks/[root-of-the-server]__ea630076._.js +3 -3
  395. package/.next/standalone/.next/server/chunks/[root-of-the-server]__eb8acb65._.js +1 -1
  396. package/.next/standalone/.next/server/chunks/[root-of-the-server]__f26ca49d._.js +1 -1
  397. package/.next/standalone/.next/server/chunks/[root-of-the-server]__f33e1101._.js +1 -1
  398. package/.next/standalone/.next/server/chunks/[root-of-the-server]__f515f865._.js +2 -2
  399. package/.next/standalone/.next/server/chunks/[root-of-the-server]__fceb5d60._.js +98 -0
  400. package/.next/standalone/.next/server/chunks/[root-of-the-server]__fed41403._.js +2 -2
  401. package/.next/standalone/.next/server/chunks/[root-of-the-server]__ff2e98c2._.js +2 -2
  402. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_cortex_curation_assess_route_actions_3e8ef2a6.js +3 -0
  403. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_cortex_curation_publish_route_actions_49238be3.js +3 -0
  404. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_cortex_curation_refine_route_actions_05675688.js +3 -0
  405. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_cortex_curation_review_route_actions_5cbb5f6b.js +3 -0
  406. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_cortex_curation_seed_route_actions_21084bdb.js +3 -0
  407. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_cortex_marketplace_browse_route_actions_7ed0768c.js +3 -0
  408. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_cortex_marketplace_preview_route_actions_38d4cc17.js +3 -0
  409. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__19afc53d._.js +3 -0
  410. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__66aca5d4._.js +1 -1
  411. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__efef0a06._.js → [root-of-the-server]__ca5beb09._.js} +2 -2
  412. package/.next/standalone/.next/server/chunks/ssr/{_7dd2ac82._.js → _078dd64d._.js} +1 -1
  413. package/.next/standalone/.next/server/chunks/ssr/_163d0838._.js +3 -0
  414. package/.next/standalone/.next/server/chunks/ssr/{_a4eeff0d._.js → _2230ad2d._.js} +2 -2
  415. package/.next/standalone/.next/server/chunks/ssr/{_9303a965._.js → _701606d5._.js} +1 -1
  416. package/.next/standalone/.next/server/chunks/ssr/_72b1de37._.js +3 -0
  417. package/.next/standalone/.next/server/chunks/ssr/{_d39bcfda._.js → _93ef0f79._.js} +2 -2
  418. package/.next/standalone/.next/server/chunks/ssr/_950142a4._.js +1 -1
  419. package/.next/standalone/.next/server/chunks/ssr/_a22b5eb0._.js +3 -0
  420. package/.next/standalone/.next/server/chunks/ssr/_aeeff784._.js +3 -0
  421. package/.next/standalone/.next/server/chunks/ssr/_c1cfdd09._.js +3 -0
  422. package/.next/standalone/.next/server/chunks/ssr/_c2d3f6de._.js +3 -0
  423. package/.next/standalone/.next/server/chunks/ssr/{_8167090e._.js → _db2fec84._.js} +2 -2
  424. package/.next/standalone/.next/server/chunks/ssr/src_02bae6e5._.js +3 -0
  425. package/.next/standalone/.next/server/chunks/ssr/src_app_(desktop)_terminal_page_tsx_de5e8d85._.js +2 -2
  426. package/.next/standalone/.next/server/chunks/ssr/src_components_terminal_terminal-pane_tsx_803c5e2c._.js +2 -2
  427. package/.next/standalone/.next/server/edge/chunks/_d73df637._.js +1 -1
  428. package/.next/standalone/.next/server/middleware-manifest.json +5 -5
  429. package/.next/standalone/.next/server/pages/404.html +1 -1
  430. package/.next/standalone/.next/server/pages/500.html +2 -2
  431. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  432. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  433. package/.next/standalone/.next/static/chunks/25b7a243a404a1a7.js +1 -0
  434. package/.next/standalone/.next/static/chunks/2b997e211a5d547b.js +1 -0
  435. package/.next/standalone/.next/static/chunks/5e08abb00653754a.js +1 -0
  436. package/.next/standalone/.next/static/chunks/61f2ed39b75b1efc.js +1 -0
  437. package/.next/standalone/.next/static/chunks/6c78a1dfa7ec2959.css +3 -0
  438. package/.next/standalone/.next/static/chunks/7246f1ee445f7024.js +1 -0
  439. package/.next/standalone/.next/static/chunks/7424664c6ffa94bd.js +1 -0
  440. package/.next/standalone/.next/static/chunks/7e0091ab6c5ee8bd.js +1 -0
  441. package/.next/standalone/.next/static/chunks/8b3f4572fec83caa.js +5 -0
  442. package/.next/standalone/.next/static/chunks/{a7b2795949a6c63e.js → 9899cf4c2bdbe61d.js} +2 -2
  443. package/.next/standalone/.next/static/chunks/ac339e970df82fa5.js +5 -0
  444. package/.next/standalone/.next/static/chunks/{0e61e67b7b8fc3f3.js → c418112e102673ce.js} +1 -1
  445. package/.next/standalone/.next/static/chunks/e2f0a2330dedff4b.js +85 -0
  446. package/.next/standalone/.next/static/chunks/f0c8b3f8cc1939ec.js +1 -0
  447. package/.next/standalone/.next/static/chunks/f9f2628207848ac2.js +1 -0
  448. package/.next/standalone/bin/cortex-hook.sh +62 -62
  449. package/.next/standalone/bin/cortex-mcp.js +60 -60
  450. package/.next/standalone/docs/superpowers/plans/2026-03-13-cortex-wiring.md +1387 -1387
  451. package/.next/standalone/docs/superpowers/plans/2026-03-14-cortex-v2-entity-graph.md +1923 -1923
  452. package/.next/standalone/docs/superpowers/plans/2026-03-14-cortex-v2-knowledge-evolution.md +1113 -1113
  453. package/.next/standalone/docs/superpowers/plans/2026-03-15-cortex-v2-boundary-engine.md +853 -853
  454. package/.next/standalone/docs/superpowers/plans/2026-03-15-cortex-v2-context-engine.md +1274 -1274
  455. package/.next/standalone/docs/superpowers/plans/2026-03-15-cortex-v2-signal-ingestion.md +933 -933
  456. package/.next/standalone/docs/superpowers/plans/2026-03-16-cortex-lobes.md +1080 -1080
  457. package/.next/standalone/docs/superpowers/plans/2026-03-16-cortex-v2-gravity-system.md +768 -768
  458. package/.next/standalone/docs/superpowers/plans/2026-03-16-cortex-v2-ui.md +1108 -1108
  459. package/.next/standalone/docs/superpowers/plans/2026-03-18-cortex-ui-integration.md +1846 -0
  460. package/.next/standalone/docs/superpowers/specs/2026-03-13-cortex-wiring-design.md +268 -268
  461. package/.next/standalone/docs/superpowers/specs/2026-03-14-cortex-v2-design.md +623 -623
  462. package/.next/standalone/docs/superpowers/specs/2026-03-16-cortex-lobes-design.md +263 -263
  463. package/.next/standalone/docs/superpowers/specs/2026-03-16-cortex-v2-ui-design.md +240 -240
  464. package/.next/standalone/docs/superpowers/specs/2026-03-18-cortex-ui-integration-design.md +341 -0
  465. package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/README.md +46 -0
  466. package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/lib/glib-2.0/include/glibconfig.h +221 -0
  467. package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/lib/index.js +1 -0
  468. package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.8.17.3 +0 -0
  469. package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/package.json +42 -0
  470. package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/README.md +46 -0
  471. package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/glib-2.0/include/glibconfig.h +221 -0
  472. package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/index.js +1 -0
  473. package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/libvips-cpp.so.8.17.3 +0 -0
  474. package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/package.json +42 -0
  475. package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/versions.json +30 -0
  476. package/.next/standalone/node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node +0 -0
  477. package/.next/standalone/node_modules/@img/{sharp-win32-x64 → sharp-linux-x64}/package.json +46 -39
  478. package/.next/standalone/node_modules/@img/sharp-linuxmusl-x64/lib/sharp-linuxmusl-x64.node +0 -0
  479. package/.next/standalone/node_modules/@img/sharp-linuxmusl-x64/package.json +46 -0
  480. package/.next/standalone/package.json +102 -102
  481. package/.next/standalone/server.js +1 -1
  482. package/.next/standalone/src/app/(desktop)/cortex/page.tsx +78 -75
  483. package/.next/standalone/src/app/api/cortex/context/route.ts +78 -78
  484. package/.next/standalone/src/app/api/cortex/curation/assess/route.ts +27 -0
  485. package/.next/standalone/src/app/api/cortex/curation/publish/route.ts +23 -0
  486. package/.next/standalone/src/app/api/cortex/curation/refine/route.ts +23 -0
  487. package/.next/standalone/src/app/api/cortex/curation/review/route.ts +29 -0
  488. package/.next/standalone/src/app/api/cortex/curation/seed/route.ts +23 -0
  489. package/.next/standalone/src/app/api/cortex/export/route.ts +40 -40
  490. package/.next/standalone/src/app/api/cortex/federation/pending/route.ts +20 -20
  491. package/.next/standalone/src/app/api/cortex/federation/resolve/route.ts +43 -43
  492. package/.next/standalone/src/app/api/cortex/federation/search/route.ts +35 -35
  493. package/.next/standalone/src/app/api/cortex/federation/teach/route.ts +76 -76
  494. package/.next/standalone/src/app/api/cortex/graph/edges/route.ts +112 -112
  495. package/.next/standalone/src/app/api/cortex/graph/entities/[id]/route.ts +73 -73
  496. package/.next/standalone/src/app/api/cortex/graph/entities/route.ts +75 -75
  497. package/.next/standalone/src/app/api/cortex/graph/populate/route.ts +203 -203
  498. package/.next/standalone/src/app/api/cortex/import/route.ts +75 -43
  499. package/.next/standalone/src/app/api/cortex/import/status/route.ts +15 -15
  500. package/.next/standalone/src/app/api/cortex/ingest/bootstrap/route.ts +29 -29
  501. package/.next/standalone/src/app/api/cortex/ingest/status/route.ts +15 -15
  502. package/.next/standalone/src/app/api/cortex/knowledge/[id]/route.ts +91 -91
  503. package/.next/standalone/src/app/api/cortex/knowledge/route.ts +93 -93
  504. package/.next/standalone/src/app/api/cortex/lobes/[id]/route.ts +67 -67
  505. package/.next/standalone/src/app/api/cortex/lobes/route.ts +22 -22
  506. package/.next/standalone/src/app/api/cortex/lobes/share/route.ts +80 -80
  507. package/.next/standalone/src/app/api/cortex/marketplace/browse/route.ts +43 -0
  508. package/.next/standalone/src/app/api/cortex/marketplace/preview/route.ts +46 -0
  509. package/.next/standalone/src/app/api/cortex/mcp/call/route.ts +11 -11
  510. package/.next/standalone/src/app/api/cortex/mcp/tools/route.ts +6 -6
  511. package/.next/standalone/src/app/api/cortex/search/route.ts +43 -43
  512. package/.next/standalone/src/app/api/cortex/settings/route.ts +33 -33
  513. package/.next/standalone/src/app/api/cortex/status/route.ts +169 -129
  514. package/.next/standalone/src/app/api/cortex/timeline/route.ts +42 -42
  515. package/.next/standalone/src/app/api/cortex/usage/route.ts +31 -31
  516. package/.next/standalone/src/app/api/cortex/workspace/[id]/context/route.ts +41 -41
  517. package/.next/standalone/src/components/cortex/constants.ts +29 -0
  518. package/.next/standalone/src/components/cortex/cortex-dashboard.tsx +304 -228
  519. package/.next/standalone/src/components/cortex/cortex-indicator.tsx +44 -44
  520. package/.next/standalone/src/components/cortex/cortex-panel.tsx +140 -140
  521. package/.next/standalone/src/components/cortex/cortex-settings.tsx +221 -221
  522. package/.next/standalone/src/components/cortex/curation-tab.tsx +810 -0
  523. package/.next/standalone/src/components/cortex/entity-detail.tsx +101 -101
  524. package/.next/standalone/src/components/cortex/entity-graph.tsx +382 -382
  525. package/.next/standalone/src/components/cortex/import-dialog.tsx +212 -0
  526. package/.next/standalone/src/components/cortex/injection-badge.tsx +72 -72
  527. package/.next/standalone/src/components/cortex/knowledge-card.tsx +109 -127
  528. package/.next/standalone/src/components/cortex/knowledge-tab.tsx +158 -56
  529. package/.next/standalone/src/components/cortex/lobe-settings.tsx +215 -199
  530. package/.next/standalone/src/components/cortex/marketplace-card.tsx +126 -0
  531. package/.next/standalone/src/components/cortex/marketplace-tab.tsx +113 -0
  532. package/.next/standalone/src/lib/cortex/config.ts +40 -40
  533. package/.next/standalone/src/lib/cortex/debug.ts +10 -10
  534. package/.next/standalone/src/lib/cortex/distillation/usage-store.ts +18 -18
  535. package/.next/standalone/src/lib/cortex/graph/resolver.ts +10 -10
  536. package/.next/standalone/src/lib/cortex/graph/types.ts +22 -22
  537. package/.next/standalone/src/lib/cortex/index.ts +56 -56
  538. package/.next/standalone/src/lib/cortex/ingestion/bootstrap.ts +14 -14
  539. package/.next/standalone/src/lib/cortex/knowledge/compat.ts +14 -14
  540. package/.next/standalone/src/lib/cortex/knowledge/contradiction.ts +10 -10
  541. package/.next/standalone/src/lib/cortex/knowledge/types.ts +67 -67
  542. package/.next/standalone/src/lib/cortex/lobes/config.ts +16 -16
  543. package/.next/standalone/src/lib/cortex/lobes/resolver.ts +8 -8
  544. package/.next/standalone/src/lib/cortex/lobes/shares.ts +14 -14
  545. package/.next/standalone/src/lib/cortex/mcp/server.ts +8 -8
  546. package/.next/standalone/src/lib/cortex/portability/exporter.ts +6 -6
  547. package/.next/standalone/src/lib/cortex/portability/importer.ts +10 -10
  548. package/.next/standalone/src/lib/cortex/retrieval/context-engine.ts +10 -10
  549. package/.next/standalone/src/lib/cortex/types.ts +39 -38
  550. package/.next/standalone/tsconfig.json +34 -34
  551. package/LICENSE +661 -661
  552. package/README.md +131 -131
  553. package/bin/cortex-hook.sh +62 -62
  554. package/bin/cortex-mcp.js +60 -60
  555. package/bin/fix-standalone-externals.js +79 -79
  556. package/bin/lib/auto-setup.js +110 -110
  557. package/bin/mdns-service.js +171 -171
  558. package/bin/postinstall.js +35 -35
  559. package/bin/setup-admin.js +195 -195
  560. package/bin/spaces-dev.js +208 -208
  561. package/bin/spaces-install.js +599 -599
  562. package/bin/spaces-reset-totp.js +50 -50
  563. package/bin/spaces-service.js +1020 -1020
  564. package/bin/spaces-setup.js +253 -253
  565. package/bin/spaces.js +776 -728
  566. package/bin/ssh-auth-keys.sh +68 -68
  567. package/bin/terminal-server.js +1649 -1646
  568. package/package.json +102 -102
  569. package/.next/standalone/.claude/settings.local.json +0 -55
  570. package/.next/standalone/.claude/spaces-env.json +0 -1
  571. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ecce08b._.js +0 -3
  572. package/.next/standalone/.next/server/chunks/ssr/_7e63066a._.js +0 -3
  573. package/.next/standalone/.next/server/chunks/ssr/_a012c43b._.js +0 -3
  574. package/.next/standalone/.next/server/chunks/ssr/_b4db3983._.js +0 -3
  575. package/.next/standalone/.next/server/chunks/ssr/_cd50a174._.js +0 -3
  576. package/.next/standalone/.next/server/chunks/ssr/_e7a9e2b0._.js +0 -3
  577. package/.next/standalone/.next/server/chunks/ssr/_ed6c285b._.js +0 -3
  578. package/.next/standalone/.next/server/chunks/ssr/src_133a7c8a._.js +0 -3
  579. package/.next/standalone/.next/static/chunks/17d164c01fa1aaa9.js +0 -5
  580. package/.next/standalone/.next/static/chunks/19da759dde107f02.js +0 -1
  581. package/.next/standalone/.next/static/chunks/58d78765e5140dcb.js +0 -1
  582. package/.next/standalone/.next/static/chunks/596bd56e0ad09173.js +0 -5
  583. package/.next/standalone/.next/static/chunks/78dd908e70bf8c4b.js +0 -85
  584. package/.next/standalone/.next/static/chunks/79aacab676df80c4.js +0 -1
  585. package/.next/standalone/.next/static/chunks/846d6ef408f69390.js +0 -1
  586. package/.next/standalone/.next/static/chunks/8de5e432a2fc563a.js +0 -1
  587. package/.next/standalone/.next/static/chunks/9196173f0d081f2c.js +0 -1
  588. package/.next/standalone/.next/static/chunks/9bd8a119aaeafc9e.js +0 -1
  589. package/.next/standalone/.next/static/chunks/e35e863c09511a51.js +0 -1
  590. package/.next/standalone/.next/static/chunks/f644c11ace7a0d9d.css +0 -3
  591. package/.next/standalone/.spaces/cortex-context.md +0 -70
  592. package/.next/standalone/node_modules/@img/sharp-win32-x64/lib/sharp-win32-x64.node +0 -0
  593. package/.next/standalone/src/components/cortex/context-tab.tsx +0 -171
  594. /package/.next/standalone/.next/static/{B207XFa7QvXAYS7Sqq2_4 → 77VYbwIoyxFNr5xevTrCu}/_buildManifest.js +0 -0
  595. /package/.next/standalone/.next/static/{B207XFa7QvXAYS7Sqq2_4 → 77VYbwIoyxFNr5xevTrCu}/_clientMiddlewareManifest.json +0 -0
  596. /package/.next/standalone/.next/static/{B207XFa7QvXAYS7Sqq2_4 → 77VYbwIoyxFNr5xevTrCu}/_ssgManifest.js +0 -0
  597. /package/.next/standalone/node_modules/@img/{sharp-win32-x64 → sharp-libvips-linux-x64}/versions.json +0 -0
package/bin/spaces.js CHANGED
@@ -1,728 +1,776 @@
1
- #!/usr/bin/env node
2
-
3
- // Re-exec with higher heap if needed (embedding models + LanceDB leak memory over time)
4
- if (!process.execArgv.some(a => a.includes('max-old-space-size')) && !process.env.__SPACES_HEAP) {
5
- process.env.__SPACES_HEAP = '1';
6
- require('child_process').spawn(
7
- process.execPath,
8
- ['--max-old-space-size=8192', ...process.argv.slice(1)],
9
- { stdio: 'inherit', env: process.env }
10
- ).on('exit', (code) => process.exit(code ?? 1));
11
- // Stop the outer process from continuing
12
- return;
13
- }
14
-
15
- const net = require('net');
16
- const http = require('http');
17
- const https = require('https');
18
- const { execFileSync, spawn } = require('child_process');
19
- const path = require('path');
20
- const os = require('os');
21
- const fs = require('fs');
22
- // terminal-server is loaded lazily (after SPACES_TIER is set in process.env)
23
-
24
- // ─── Memory monitoring (only when SPACES_DEBUG or cortex.debug) ──
25
- let _lastHeapMB = 0;
26
- function logMemory(label) {
27
- if (!process.env.SPACES_DEBUG && !_spacesDebug) return;
28
- const mem = process.memoryUsage();
29
- const heapMB = Math.round(mem.heapUsed / 1048576);
30
- const rssMB = Math.round(mem.rss / 1048576);
31
- const extMB = Math.round((mem.external || 0) / 1048576);
32
- const abMB = Math.round((mem.arrayBuffers || 0) / 1048576);
33
- const delta = heapMB - _lastHeapMB;
34
- if (label || Math.abs(delta) > 20) {
35
- console.log(`[Memory] ${label || 'periodic'}: heap=${heapMB}MB rss=${rssMB}MB external=${extMB}MB arrayBuffers=${abMB}MB ${delta > 0 ? '+' : ''}${delta}MB`);
36
- }
37
- _lastHeapMB = heapMB;
38
- }
39
- let _spacesDebug = false;
40
- try {
41
- const cfgPath = path.join(os.homedir(), '.spaces', 'config.json');
42
- if (fs.existsSync(cfgPath)) _spacesDebug = !!JSON.parse(fs.readFileSync(cfgPath, 'utf-8')).cortex?.debug;
43
- } catch { /* ignore */ }
44
- setInterval(() => logMemory(), 60000);
45
-
46
- const SPACES_DIR = path.join(os.homedir(), '.spaces');
47
- const CONFIG_PATH = path.join(SPACES_DIR, 'server.json');
48
- const SESSION_SECRET_PATH = path.join(SPACES_DIR, 'session_secret');
49
- const NEXT_INTERNAL_PORT = 3400;
50
- const projectDir = path.join(__dirname, '..');
51
- const MANAGED_PACKAGES = path.join(SPACES_DIR, 'packages');
52
- const MANAGED_NODE_MODULES = path.join(MANAGED_PACKAGES, 'node_modules');
53
-
54
- // ─── CLI arg parsing ──────────────────────────────────────
55
- const args = process.argv.slice(2);
56
- const cliFlags = {};
57
- for (let i = 0; i < args.length; i++) {
58
- if (args[i] === '--setup') { cliFlags.setup = true; }
59
- else if (args[i] === '--port' && args[i + 1]) { cliFlags.port = parseInt(args[++i], 10); }
60
- else if (args[i] === '--tier' && args[i + 1]) { cliFlags.tier = args[++i]; }
61
- else if (args[i] === '--base-path' && args[i + 1]) { cliFlags.basePath = args[++i]; }
62
- else if (args[i] === '--help' || args[i] === '-h') { cliFlags.help = true; }
63
- }
64
-
65
- if (cliFlags.help) {
66
- console.log(`
67
- Spaces - Agent Workspace Manager
68
-
69
- Usage:
70
- spaces Start the server (auto-detects tier)
71
- spaces stop Stop running server
72
- spaces install <teams|pro> Install a tier package
73
- spaces uninstall [teams|pro] Uninstall packages (all if none specified)
74
- spaces verify Verify installed packages
75
- spaces upgrade [teams|pro] Upgrade installed packages
76
- spaces --setup Interactive first-time setup wizard
77
- spaces --port 3457 Override port
78
- spaces --tier team Override tier (community|team|federation)
79
- spaces --base-path /spaces Set base path for reverse proxy
80
- spaces service install Install as OS service (systemd/launchd/Task Scheduler)
81
- spaces service uninstall Remove OS service
82
- spaces service start Start the service
83
- spaces service stop Stop the service
84
- spaces service status Show service status
85
- spaces service logs Tail service logs
86
- spaces reset-totp <user> Reset TOTP/2FA for a user
87
- spaces --help Show this help
88
- `);
89
- process.exit(0);
90
- }
91
-
92
- // ─── Stop command ─────────────────────────────────────────
93
- const subcommand = args[0];
94
- if (subcommand === 'stop') {
95
- stopServer();
96
- process.exit(0);
97
- }
98
-
99
- // ─── Route install/verify/upgrade to spaces-install.js ────
100
- if (subcommand === 'install' || subcommand === 'uninstall' || subcommand === 'verify' || subcommand === 'upgrade') {
101
- // Re-exec with spaces-install.js, passing through all args
102
- const installScript = path.join(__dirname, 'spaces-install.js');
103
- const { status } = require('child_process').spawnSync(
104
- process.execPath, [installScript, ...args],
105
- { stdio: 'inherit', env: process.env }
106
- );
107
- process.exit(status || 0);
108
- }
109
-
110
- // ─── Route reset-totp to spaces-reset-totp.js ───────
111
- if (subcommand === 'reset-totp') {
112
- const resetScript = path.join(__dirname, 'spaces-reset-totp.js');
113
- const { status } = require('child_process').spawnSync(
114
- process.execPath, [resetScript, ...args.slice(1)],
115
- { stdio: 'inherit', env: process.env }
116
- );
117
- process.exit(status || 0);
118
- }
119
-
120
- // ─── Route service commands to spaces-service.js ─────
121
- if (subcommand === 'service') {
122
- const serviceScript = path.join(__dirname, 'spaces-service.js');
123
- const { status } = require('child_process').spawnSync(
124
- process.execPath, [serviceScript, ...args.slice(1)],
125
- { stdio: 'inherit', env: process.env }
126
- );
127
- process.exit(status || 0);
128
- }
129
-
130
- // ─── Setup wizard ─────────────────────────────────────────
131
- if (cliFlags.setup) {
132
- require('./spaces-setup');
133
- // spaces-setup handles its own process.exit
134
- } else if (subcommand && !subcommand.startsWith('-')) {
135
- console.error(` Unknown command: ${subcommand}`);
136
- console.error(` Run "spaces --help" for usage`);
137
- process.exit(1);
138
- } else {
139
- startServer();
140
- }
141
-
142
- // ─── TLS certificate ────────────────────────────────────────
143
- // Uses a real cert if configured in server.json (tlsCert, tlsKey, optional
144
- // tlsCa for the full chain), otherwise generates a self-signed cert so
145
- // mobile browsers that force HTTPS-first can still connect.
146
- function ensureTlsCert() {
147
- // Check for configured real cert in server.json
148
- try {
149
- const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
150
- if (config.tlsCert && config.tlsKey) {
151
- if (fs.existsSync(config.tlsCert) && fs.existsSync(config.tlsKey)) {
152
- // Read cert + key, and optionally the CA bundle for full chain
153
- const certPem = fs.readFileSync(config.tlsCert, 'utf-8').trim();
154
- const caPem = (config.tlsCa && fs.existsSync(config.tlsCa))
155
- ? fs.readFileSync(config.tlsCa, 'utf-8').trim()
156
- : null;
157
- const creds = {
158
- cert: caPem ? certPem + '\n' + caPem : certPem,
159
- key: fs.readFileSync(config.tlsKey, 'utf-8'),
160
- };
161
- console.log(' Using TLS certificate: ' + config.tlsCert);
162
- return creds;
163
- }
164
- console.log(' Warning: tlsCert/tlsKey configured but files not found, falling back to self-signed');
165
- }
166
- } catch {}
167
-
168
- // Fall back to self-signed
169
- const certPath = path.join(SPACES_DIR, 'tls-cert.pem');
170
- const keyPath = path.join(SPACES_DIR, 'tls-key.pem');
171
-
172
- if (fs.existsSync(certPath) && fs.existsSync(keyPath)) {
173
- try {
174
- return { cert: fs.readFileSync(certPath), key: fs.readFileSync(keyPath) };
175
- } catch {}
176
- }
177
-
178
- try {
179
- fs.mkdirSync(SPACES_DIR, { recursive: true });
180
- execFileSync('openssl', [
181
- 'req', '-x509', '-newkey', 'rsa:2048',
182
- '-keyout', keyPath, '-out', certPath,
183
- '-sha256', '-days', '365', '-nodes',
184
- '-subj', '/CN=spaces-local',
185
- '-addext', 'subjectAltName=DNS:localhost,DNS:*.local,DNS:*.robindale.com,IP:127.0.0.1',
186
- ], { stdio: 'pipe', timeout: 15000 });
187
- console.log(' Generated self-signed TLS certificate');
188
- return { cert: fs.readFileSync(certPath), key: fs.readFileSync(keyPath) };
189
- } catch (e) {
190
- console.log(` Warning: Could not generate TLS cert (${e.message})`);
191
- console.log(' HTTPS will not be available. Install OpenSSL to enable it.');
192
- return null;
193
- }
194
- }
195
-
196
- function startServer() {
197
- // ─── Load saved config ────────────────────────────────────
198
- let savedConfig = {};
199
- if (fs.existsSync(CONFIG_PATH)) {
200
- try { savedConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8')); } catch {}
201
- }
202
-
203
- // ─── Resolve settings (CLI > env > config > defaults) ─────
204
- const PORT = cliFlags.port
205
- || parseInt(process.env.SPACES_PORT || '', 10)
206
- || savedConfig.port
207
- || 3457;
208
-
209
- const basePath = cliFlags.basePath
210
- || process.env.SPACES_BASE_PATH
211
- || savedConfig.basePath
212
- || '';
213
-
214
- const allowedOrigins = process.env.SPACES_ALLOWED_ORIGINS
215
- || savedConfig.allowedOrigins
216
- || '';
217
-
218
- // ─── Kill any existing server on this port ───────────────────
219
- stopServer();
220
-
221
- // ─── Resolve optional packages once ─────────────────────────
222
- const proPath = resolveSpacesPro();
223
- const teamsPath = resolveSpacesTeams();
224
- const cortexPath = resolveSpacesCortex();
225
-
226
- // Tier resolution: CLI > env > config > auto-detect
227
- let tier = cliFlags.tier
228
- || process.env.SPACES_TIER
229
- || savedConfig.tier
230
- || '';
231
-
232
- // Auto-detect tier from package presence
233
- if (!tier) {
234
- if (proPath) tier = 'federation';
235
- else if (teamsPath) tier = 'team';
236
- else tier = 'community';
237
- }
238
-
239
- console.log('');
240
- console.log(' Spaces - Agent Workspace Manager');
241
- console.log(' =================================');
242
- console.log('');
243
- console.log(` Tier: ${tier}`);
244
-
245
- // ─── Server tier prerequisites ────────────────────────────
246
- const childEnv = { ...process.env };
247
-
248
- if (tier !== 'community') {
249
- // team/federation tiers require @spaces/teams (auth + collaboration)
250
- if ((tier === 'team' || tier === 'federation') && !teamsPath) {
251
- console.error(' Error: @spaces/teams is required for team/federation tiers.');
252
- console.error(' Install it: spaces install teams');
253
- process.exit(1);
254
- }
255
- // federation tier requires @spaces/pro (network)
256
- if (tier === 'federation' && !proPath) {
257
- console.error(' Error: @spaces/pro is required for the federation tier.');
258
- console.error(' Install it: spaces install pro');
259
- process.exit(1);
260
- }
261
-
262
- // Check for session secret
263
- let sessionSecret = process.env.SPACES_SESSION_SECRET || '';
264
- if (!sessionSecret && fs.existsSync(SESSION_SECRET_PATH)) {
265
- sessionSecret = fs.readFileSync(SESSION_SECRET_PATH, 'utf-8').trim();
266
- }
267
-
268
- // Check for admin DB — auto-setup if missing
269
- const adminDbPath = path.join(SPACES_DIR, 'admin.db');
270
- if (!fs.existsSync(adminDbPath) || !sessionSecret) {
271
- const { autoSetup } = require('./lib/auto-setup');
272
- const result = autoSetup({ SPACES_DIR, SESSION_SECRET_PATH, ADMIN_DB_PATH: adminDbPath, CONFIG_PATH, tier, port: PORT, basePath });
273
- sessionSecret = result.sessionSecret;
274
- }
275
-
276
- childEnv.SPACES_SESSION_SECRET = sessionSecret;
277
- process.env.SPACES_SESSION_SECRET = sessionSecret;
278
- console.log(` Admin DB: ${adminDbPath}`);
279
- }
280
-
281
- // Set tier in both child env and own process env (terminal-server reads it)
282
- childEnv.SPACES_TIER = tier;
283
- process.env.SPACES_TIER = tier;
284
- if (basePath) {
285
- childEnv.SPACES_BASE_PATH = basePath;
286
- console.log(` Base path: ${basePath}`);
287
- }
288
- if (allowedOrigins) {
289
- childEnv.SPACES_ALLOWED_ORIGINS = allowedOrigins;
290
- process.env.SPACES_ALLOWED_ORIGINS = allowedOrigins;
291
- console.log(` Allowed origins: ${allowedOrigins}`);
292
- }
293
-
294
- // ─── Resolve NODE_PATH for @spaces/pro and @spaces/teams ──
295
- // Update both childEnv (for the Next.js child process) and process.env
296
- // (for terminal-server.js which runs in this same parent process).
297
- // Include:
298
- // - Managed packages node_modules (~/.spaces/packages/node_modules)
299
- // - Each managed package's own node_modules (for its bundled deps)
300
- // - The host app's own node_modules (fallback for peer deps)
301
- const appNodeModules = path.join(projectDir, 'node_modules');
302
- const nodePaths = [MANAGED_NODE_MODULES, appNodeModules];
303
- // Add each resolved package's own node_modules so its bundled deps are found
304
- for (const pkgPath of [proPath, teamsPath, cortexPath]) {
305
- if (pkgPath) {
306
- // pkgPath is the package root (symlink target or direct path)
307
- const realPath = fs.realpathSync(pkgPath);
308
- const pkgNodeModules = path.join(realPath, 'node_modules');
309
- if (fs.existsSync(pkgNodeModules) && !nodePaths.includes(pkgNodeModules)) {
310
- nodePaths.push(pkgNodeModules);
311
- }
312
- // Also add the parent scope for @spaces/* resolution
313
- const parentModules = path.dirname(path.dirname(pkgPath));
314
- if (!nodePaths.includes(parentModules)) {
315
- nodePaths.push(parentModules);
316
- }
317
- }
318
- }
319
- for (const dir of nodePaths) {
320
- for (const target of [childEnv, process.env]) {
321
- const existing = target.NODE_PATH || '';
322
- if (!existing.includes(dir)) {
323
- target.NODE_PATH = existing
324
- ? `${dir}${path.delimiter}${existing}`
325
- : dir;
326
- }
327
- }
328
- }
329
- // Re-init module paths so require() in this process picks up the new NODE_PATH
330
- require('module').Module._initPaths();
331
-
332
- // Verify collaboration pipeline works end-to-end at startup
333
- if (tier === 'team' || tier === 'federation') {
334
- try {
335
- const teams = require('@spaces/teams');
336
- console.log(' Collaboration: @spaces/teams loaded OK');
337
- // Smoke-test that peer deps resolve from this process
338
- require('better-sqlite3');
339
- } catch (e) {
340
- console.error(` Warning: Collaboration may not work — ${e.message}`);
341
- console.error(' Check that NODE_PATH includes the host app node_modules.');
342
- }
343
- }
344
-
345
- // ─── Detect @spaces/cortex ──────────────────────────────────
346
- if (cortexPath) {
347
- childEnv.SPACES_HAS_CORTEX = '1';
348
- process.env.SPACES_HAS_CORTEX = '1';
349
- console.log(' Cortex: @spaces/cortex detected');
350
- }
351
-
352
- console.log('');
353
-
354
- // ─── Background update check (non-blocking) ───────────────
355
- // Compare installed version against npm registry. Writes result to
356
- // ~/.spaces/update-check.json so the UI can show a banner.
357
- const updateCheckPath = path.join(SPACES_DIR, 'update-check.json');
358
- (async () => {
359
- try {
360
- const pkg = require(path.join(projectDir, 'package.json'));
361
- const currentVersion = pkg.version;
362
- const npmName = pkg.name || '@jlongo78/agent-spaces';
363
-
364
- // Skip if checked within the last hour
365
- try {
366
- if (fs.existsSync(updateCheckPath)) {
367
- const cached = JSON.parse(fs.readFileSync(updateCheckPath, 'utf-8'));
368
- if (Date.now() - (cached.checkedAt || 0) < 3600_000) {
369
- if (cached.available) {
370
- console.log(` Update available: ${currentVersion} → ${cached.latest} (run: npm i -g ${npmName})`);
371
- }
372
- return;
373
- }
374
- }
375
- } catch { /* check fresh */ }
376
-
377
- const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(npmName)}/latest`, {
378
- signal: AbortSignal.timeout(5000),
379
- });
380
- if (!res.ok) return;
381
- const data = await res.json();
382
- const latest = data.version;
383
-
384
- const result = {
385
- current: currentVersion,
386
- latest,
387
- available: latest !== currentVersion && latest > currentVersion,
388
- checkedAt: Date.now(),
389
- name: npmName,
390
- };
391
-
392
- fs.writeFileSync(updateCheckPath, JSON.stringify(result, null, 2));
393
-
394
- if (result.available) {
395
- console.log(` Update available: ${currentVersion} → ${latest} (run: npm i -g ${npmName})`);
396
- }
397
- } catch { /* network error — skip silently */ }
398
- })();
399
-
400
- // Also check addon updates (git-based packages)
401
- const gitSafe = ['-c', 'safe.directory=*'];
402
- const addonPaths = { teams: teamsPath, pro: proPath, cortex: cortexPath };
403
- (async () => {
404
- for (const [key, addonDir] of Object.entries(addonPaths)) {
405
- if (!addonDir || !fs.existsSync(path.join(addonDir, '.git'))) continue;
406
- const realDir = fs.realpathSync(addonDir);
407
- try {
408
- execFileSync('git', [...gitSafe, 'fetch', '--quiet'], { cwd: realDir, stdio: 'ignore', timeout: 5000 });
409
- const local = execFileSync('git', [...gitSafe, 'rev-parse', 'HEAD'], { cwd: realDir, encoding: 'utf-8' }).trim();
410
- const remote = execFileSync('git', [...gitSafe, 'rev-parse', '@{u}'], { cwd: realDir, encoding: 'utf-8' }).trim();
411
- if (local !== remote) {
412
- console.log(` Update available for @spaces/${key} (run: spaces upgrade ${key})`);
413
- }
414
- } catch { /* not on a branch with upstream, skip */ }
415
- }
416
- })();
417
-
418
- // Check for ~/.claude/ directory
419
- const claudeDir = path.join(os.homedir(), '.claude');
420
- if (!fs.existsSync(claudeDir)) {
421
- console.log(' Warning: ~/.claude/ not found. Have you used Claude Code yet?');
422
- console.log('');
423
- }
424
-
425
- // ─── Detect build type ────────────────────────────────────
426
- const standaloneServer = path.join(projectDir, '.next', 'standalone', 'server.js');
427
- const fullBuildDir = path.join(projectDir, '.next', 'BUILD_ID');
428
- const isStandalone = fs.existsSync(standaloneServer);
429
- const isFullBuild = fs.existsSync(fullBuildDir);
430
-
431
- if (!isStandalone && !isFullBuild) {
432
- console.error(' Error: No build found.');
433
- console.error(' Run "npm run build" first, or install via "npm install -g @jlongo78/agent-spaces".');
434
- process.exit(1);
435
- }
436
-
437
- // ─── Spawn Next.js ────────────────────────────────────────
438
- let next;
439
- if (isStandalone) {
440
- const parentNodeModules = path.join(projectDir, 'node_modules');
441
- const existingNodePath = childEnv.NODE_PATH || '';
442
- childEnv.NODE_PATH = existingNodePath
443
- ? `${parentNodeModules}${path.delimiter}${existingNodePath}`
444
- : parentNodeModules;
445
-
446
- next = spawn(process.execPath, [standaloneServer], {
447
- cwd: path.dirname(standaloneServer),
448
- stdio: ['ignore', 'pipe', 'pipe'],
449
- env: {
450
- ...childEnv,
451
- PORT: String(NEXT_INTERNAL_PORT),
452
- HOSTNAME: '0.0.0.0',
453
- NODE_ENV: 'production',
454
- },
455
- });
456
- } else {
457
- next = spawn('npx', ['next', 'start', '--port', String(NEXT_INTERNAL_PORT)], {
458
- cwd: projectDir,
459
- stdio: ['ignore', 'pipe', 'pipe'],
460
- env: {
461
- ...childEnv,
462
- PORT: String(NEXT_INTERNAL_PORT),
463
- HOSTNAME: '0.0.0.0',
464
- NODE_ENV: 'production',
465
- },
466
- shell: true,
467
- });
468
- }
469
-
470
- let nextReady = false;
471
-
472
- next.stdout.on('data', (data) => {
473
- const msg = data.toString();
474
- process.stdout.write(msg);
475
- if (!nextReady && (msg.includes('Ready') || msg.includes('started server') || msg.includes('Listening') || msg.includes('localhost'))) {
476
- nextReady = true;
477
- console.log(`\n Ready at http://localhost:${PORT}`);
478
- if (tlsCreds) console.log(` Also at https://localhost:${PORT} (self-signed)`);
479
- console.log('');
480
-
481
- const url = `http://localhost:${PORT}`;
482
- const isService = process.env.SPACES_SERVICE === '1';
483
- if (!isService) {
484
- try {
485
- if (process.platform === 'win32') {
486
- execFileSync('cmd', ['/c', 'start', url], { stdio: 'ignore' });
487
- } else if (process.platform === 'darwin') {
488
- execFileSync('open', [url], { stdio: 'ignore' });
489
- } else {
490
- execFileSync('xdg-open', [url], { stdio: 'ignore' });
491
- }
492
- } catch {
493
- console.log(` Open ${url} in your browser`);
494
- }
495
- }
496
- }
497
- });
498
-
499
- next.stderr.on('data', (data) => {
500
- const msg = data.toString();
501
- if (!msg.includes('Warning')) {
502
- process.stderr.write(data);
503
- }
504
- });
505
-
506
- next.on('exit', (code) => {
507
- if (code !== 0 && code !== null) {
508
- console.error(` [spaces] Next.js exited with code ${code}`);
509
- }
510
- cleanup();
511
- });
512
-
513
- // ─── Proxy request handler (shared by HTTP and HTTPS) ────
514
- function proxyHandler(req, res) {
515
- // WebSocket paths are handled by the 'upgrade' event, but a plain
516
- // HTTP request to /ws (e.g. health check) should not be proxied to
517
- // Next.js which would 308-redirect it due to trailingSlash.
518
- const urlPath = (req.url || '').split('?')[0];
519
- if (urlPath === '/ws' || urlPath.endsWith('/ws') || urlPath.endsWith('/ws/')) {
520
- res.writeHead(200, { 'Content-Type': 'text/plain' });
521
- res.end('WebSocket endpoint');
522
- return;
523
- }
524
-
525
- const proxyReq = http.request(
526
- {
527
- hostname: '127.0.0.1',
528
- port: NEXT_INTERNAL_PORT,
529
- path: req.url,
530
- method: req.method,
531
- headers: req.headers,
532
- },
533
- (proxyRes) => {
534
- res.writeHead(proxyRes.statusCode, proxyRes.headers);
535
- proxyRes.pipe(res);
536
- }
537
- );
538
- proxyReq.on('error', () => {
539
- if (!res.headersSent) {
540
- res.writeHead(502);
541
- res.end('Server not ready yet. Refresh in a moment.');
542
- }
543
- });
544
- req.pipe(proxyReq);
545
- }
546
-
547
- // ─── HTTP + HTTPS on a single port ─────────────────────────
548
- // Peek at the first byte of each connection: 0x16 = TLS ClientHello,
549
- // anything else = plain HTTP. This lets mobile browsers that force
550
- // HTTPS-first connect to the same port without a separate listener.
551
- const httpServer = http.createServer(proxyHandler);
552
- const tlsCreds = ensureTlsCert();
553
- const httpsServer = tlsCreds ? https.createServer(tlsCreds, proxyHandler) : null;
554
-
555
- const { createTerminalServer } = require('./terminal-server');
556
- createTerminalServer(httpServer);
557
- if (httpsServer) createTerminalServer(httpsServer);
558
-
559
- // Wire up 'address()' on the inner servers so terminal-server can
560
- // discover the port, then emit 'listening' so its event handler fires.
561
- const patchAddress = (srv) => { srv.address = () => ({ port: PORT }); };
562
- patchAddress(httpServer);
563
- if (httpsServer) patchAddress(httpsServer);
564
-
565
- const dualServer = net.createServer((socket) => {
566
- // If client connects but sends nothing for 5s, destroy.
567
- // Once routed, clear the timeout so long-lived connections (WebSocket) aren't killed.
568
- socket.setTimeout(5000, () => socket.destroy());
569
- socket.once('data', (buf) => {
570
- socket.setTimeout(0);
571
- socket.pause();
572
- const target = (buf[0] === 0x16 && httpsServer) ? httpsServer : httpServer;
573
- target.emit('connection', socket);
574
- socket.unshift(buf);
575
- socket.resume();
576
- });
577
- });
578
-
579
- dualServer.listen(PORT, () => {
580
- // Now that the port is bound, tell the inner servers they're "listening"
581
- // so terminal-server's mDNS and message watcher start up.
582
- httpServer.emit('listening');
583
- if (httpsServer) httpsServer.emit('listening');
584
-
585
- if (httpsServer) {
586
- console.log(` Starting server on port ${PORT} (HTTP + HTTPS)`);
587
- } else {
588
- console.log(` Starting server on http://localhost:${PORT}`);
589
- }
590
- console.log('');
591
- });
592
-
593
- function cleanup() {
594
- next.kill();
595
- dualServer.close();
596
- process.exit(0);
597
- }
598
-
599
- process.on('SIGINT', cleanup);
600
- process.on('SIGTERM', cleanup);
601
- }
602
-
603
- // ─── Stop running server ─────────────────────────────────────
604
- function findPidsOnPort(port) {
605
- const pids = new Set();
606
- if (process.platform === 'win32') {
607
- try {
608
- const output = execFileSync('netstat', ['-ano'], { encoding: 'utf-8' });
609
- for (const line of output.split(String.fromCharCode(10))) {
610
- if (line.includes(':' + port + ' ') && line.includes('LISTENING')) {
611
- const parts = line.trim().split(/\s+/);
612
- const pid = parseInt(parts[parts.length - 1], 10);
613
- if (pid > 0) pids.add(pid);
614
- }
615
- }
616
- } catch {}
617
- } else {
618
- try {
619
- const output = execFileSync('lsof', ['-ti', `tcp:${port}`], { encoding: 'utf-8' }).trim();
620
- for (const p of output.split('\n')) { if (p.trim()) pids.add(parseInt(p.trim(), 10)); }
621
- } catch {}
622
- try {
623
- const output = execFileSync('fuser', [`${port}/tcp`], { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
624
- for (const p of output.split(/\s+/)) { if (p.trim()) pids.add(parseInt(p.trim(), 10)); }
625
- } catch {}
626
- }
627
- return [...pids].filter(p => !isNaN(p) && p > 0);
628
- }
629
-
630
- function stopServer() {
631
- let savedConfig = {};
632
- if (fs.existsSync(CONFIG_PATH)) {
633
- try { savedConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8')); } catch {}
634
- }
635
- const port = parseInt(process.env.SPACES_PORT || '', 10) || savedConfig.port || 3457;
636
- const ports = [port, NEXT_INTERNAL_PORT];
637
- let killed = 0;
638
-
639
- for (const p of ports) {
640
- for (const pid of findPidsOnPort(p)) {
641
- try {
642
- process.kill(pid, 'SIGTERM');
643
- killed++;
644
- } catch {}
645
- }
646
- }
647
-
648
- if (killed > 0) {
649
- console.log(` Stopped ${killed} process(es) on port ${port}`);
650
- // Wait for ports to be released, escalate to SIGKILL if needed
651
- const deadline = Date.now() + 2000;
652
- let escalated = false;
653
- while (Date.now() < deadline) {
654
- const remaining = ports.flatMap(p => findPidsOnPort(p));
655
- if (remaining.length === 0) break;
656
- if (!escalated && Date.now() > deadline - 1000) {
657
- for (const pid of remaining) {
658
- try { process.kill(pid, 'SIGKILL'); } catch {}
659
- }
660
- escalated = true;
661
- }
662
- if (process.platform === 'win32') { require('child_process').spawnSync('powershell', ['-Command', 'Start-Sleep -Milliseconds 200']); } else { require('child_process').spawnSync('sleep', ['0.2']); }
663
- }
664
- } else {
665
- console.log(` No running server found on port ${port}`);
666
- }
667
- }
668
-
669
- // ─── @spaces/pro resolution ──────────────────────────────────
670
- function resolveSpacesPro() {
671
- // 1. Managed install (~/.spaces/packages/)
672
- const managed = path.join(MANAGED_NODE_MODULES, '@spaces', 'pro');
673
- if (fs.existsSync(path.join(managed, 'dist', 'index.js'))) return managed;
674
-
675
- // 2. Local node_modules (npm link / optionalDep)
676
- try {
677
- return require.resolve('@spaces/pro');
678
- } catch {}
679
-
680
- // 3. Global npm prefix (legacy)
681
- try {
682
- const globalPrefix = execFileSync('npm', ['prefix', '-g'], { encoding: 'utf-8' }).trim();
683
- const globalProPath = path.join(globalPrefix, 'lib', 'node_modules', '@spaces', 'pro');
684
- if (fs.existsSync(globalProPath)) return globalProPath;
685
- const altPath = path.join(globalPrefix, 'node_modules', '@spaces', 'pro');
686
- if (fs.existsSync(altPath)) return altPath;
687
- } catch {}
688
-
689
- return null;
690
- }
691
-
692
- // ─── @spaces/teams resolution ────────────────────────────────
693
- function resolveSpacesTeams() {
694
- // 1. Managed install (~/.spaces/packages/)
695
- const managed = path.join(MANAGED_NODE_MODULES, '@spaces', 'teams');
696
- if (fs.existsSync(path.join(managed, 'dist', 'index.js'))) return managed;
697
-
698
- // 2. Local node_modules (npm link / optionalDep)
699
- try {
700
- return require.resolve('@spaces/teams');
701
- } catch {}
702
-
703
- // 3. Global npm prefix (legacy)
704
- try {
705
- const globalPrefix = execFileSync('npm', ['prefix', '-g'], { encoding: 'utf-8' }).trim();
706
- const globalTeamsPath = path.join(globalPrefix, 'lib', 'node_modules', '@spaces', 'teams');
707
- if (fs.existsSync(globalTeamsPath)) return globalTeamsPath;
708
- const altPath = path.join(globalPrefix, 'node_modules', '@spaces', 'teams');
709
- if (fs.existsSync(altPath)) return altPath;
710
- } catch {}
711
-
712
- return null;
713
- }
714
-
715
- // ─── @spaces/cortex resolution ───────────────────────────────
716
- function resolveSpacesCortex() {
717
- const managed = path.join(MANAGED_NODE_MODULES, '@spaces', 'cortex');
718
- if (fs.existsSync(path.join(managed, 'dist', 'index.js'))) return managed;
719
- try { return require.resolve('@spaces/cortex'); } catch {}
720
- try {
721
- const globalPrefix = execFileSync('npm', ['prefix', '-g'], { encoding: 'utf-8' }).trim();
722
- const globalPath = path.join(globalPrefix, 'lib', 'node_modules', '@spaces', 'cortex');
723
- if (fs.existsSync(globalPath)) return globalPath;
724
- const altPath = path.join(globalPrefix, 'node_modules', '@spaces', 'cortex');
725
- if (fs.existsSync(altPath)) return altPath;
726
- } catch {}
727
- return null;
728
- }
1
+ #!/usr/bin/env node
2
+
3
+ // Re-exec with higher heap if needed (embedding models + LanceDB leak memory over time)
4
+ if (!process.execArgv.some(a => a.includes('max-old-space-size')) && !process.env.__SPACES_HEAP) {
5
+ process.env.__SPACES_HEAP = '1';
6
+ require('child_process').spawn(
7
+ process.execPath,
8
+ ['--max-old-space-size=8192', ...process.argv.slice(1)],
9
+ { stdio: 'inherit', env: process.env }
10
+ ).on('exit', (code) => process.exit(code ?? 1));
11
+ // Stop the outer process from continuing
12
+ return;
13
+ }
14
+
15
+ const net = require('net');
16
+ const http = require('http');
17
+ const https = require('https');
18
+ const { execFileSync, spawn } = require('child_process');
19
+ const path = require('path');
20
+ const os = require('os');
21
+ const fs = require('fs');
22
+ // terminal-server is loaded lazily (after SPACES_TIER is set in process.env)
23
+
24
+ // ─── Memory monitoring (only when SPACES_DEBUG or cortex.debug) ──
25
+ let _lastHeapMB = 0;
26
+ function logMemory(label) {
27
+ if (!process.env.SPACES_DEBUG && !_spacesDebug) return;
28
+ const mem = process.memoryUsage();
29
+ const heapMB = Math.round(mem.heapUsed / 1048576);
30
+ const rssMB = Math.round(mem.rss / 1048576);
31
+ const extMB = Math.round((mem.external || 0) / 1048576);
32
+ const abMB = Math.round((mem.arrayBuffers || 0) / 1048576);
33
+ const delta = heapMB - _lastHeapMB;
34
+ if (label || Math.abs(delta) > 20) {
35
+ console.log(`[Memory] ${label || 'periodic'}: heap=${heapMB}MB rss=${rssMB}MB external=${extMB}MB arrayBuffers=${abMB}MB ${delta > 0 ? '+' : ''}${delta}MB`);
36
+ }
37
+ _lastHeapMB = heapMB;
38
+ }
39
+ let _spacesDebug = false;
40
+ try {
41
+ const cfgPath = path.join(os.homedir(), '.spaces', 'config.json');
42
+ if (fs.existsSync(cfgPath)) _spacesDebug = !!JSON.parse(fs.readFileSync(cfgPath, 'utf-8')).cortex?.debug;
43
+ } catch { /* ignore */ }
44
+ setInterval(() => logMemory(), 60000);
45
+
46
+ const SPACES_DIR = path.join(os.homedir(), '.spaces');
47
+ const CONFIG_PATH = path.join(SPACES_DIR, 'server.json');
48
+ const SESSION_SECRET_PATH = path.join(SPACES_DIR, 'session_secret');
49
+ const NEXT_INTERNAL_PORT = 3400;
50
+ const projectDir = path.join(__dirname, '..');
51
+ const MANAGED_PACKAGES = path.join(SPACES_DIR, 'packages');
52
+ const MANAGED_NODE_MODULES = path.join(MANAGED_PACKAGES, 'node_modules');
53
+
54
+ // ─── CLI arg parsing ──────────────────────────────────────
55
+ const args = process.argv.slice(2);
56
+ const cliFlags = {};
57
+ for (let i = 0; i < args.length; i++) {
58
+ if (args[i] === '--setup') { cliFlags.setup = true; }
59
+ else if (args[i] === '--port' && args[i + 1]) { cliFlags.port = parseInt(args[++i], 10); }
60
+ else if (args[i] === '--tier' && args[i + 1]) { cliFlags.tier = args[++i]; }
61
+ else if (args[i] === '--base-path' && args[i + 1]) { cliFlags.basePath = args[++i]; }
62
+ else if (args[i] === '--help' || args[i] === '-h') { cliFlags.help = true; }
63
+ }
64
+
65
+ if (cliFlags.help) {
66
+ console.log(`
67
+ Spaces - Agent Workspace Manager
68
+
69
+ Usage:
70
+ spaces Start the server (auto-detects tier)
71
+ spaces stop Stop running server
72
+ spaces install <teams|pro> Install a tier package
73
+ spaces uninstall [teams|pro] Uninstall packages (all if none specified)
74
+ spaces verify Verify installed packages
75
+ spaces upgrade [teams|pro] Upgrade installed packages
76
+ spaces --setup Interactive first-time setup wizard
77
+ spaces --port 3457 Override port
78
+ spaces --tier team Override tier (community|team|federation)
79
+ spaces --base-path /spaces Set base path for reverse proxy
80
+ spaces service install Install as OS service (systemd/launchd/Task Scheduler)
81
+ spaces service uninstall Remove OS service
82
+ spaces service start Start the service
83
+ spaces service stop Stop the service
84
+ spaces service status Show service status
85
+ spaces service logs Tail service logs
86
+ spaces reset-totp <user> Reset TOTP/2FA for a user
87
+ spaces --help Show this help
88
+ `);
89
+ process.exit(0);
90
+ }
91
+
92
+ // ─── Stop command ─────────────────────────────────────────
93
+ const subcommand = args[0];
94
+ if (subcommand === 'stop') {
95
+ stopServer();
96
+ process.exit(0);
97
+ }
98
+
99
+ // ─── Route install/verify/upgrade to spaces-install.js ────
100
+ if (subcommand === 'install' || subcommand === 'uninstall' || subcommand === 'verify' || subcommand === 'upgrade') {
101
+ // Re-exec with spaces-install.js, passing through all args
102
+ const installScript = path.join(__dirname, 'spaces-install.js');
103
+ const { status } = require('child_process').spawnSync(
104
+ process.execPath, [installScript, ...args],
105
+ { stdio: 'inherit', env: process.env }
106
+ );
107
+ process.exit(status || 0);
108
+ }
109
+
110
+ // ─── Route reset-totp to spaces-reset-totp.js ───────
111
+ if (subcommand === 'reset-totp') {
112
+ const resetScript = path.join(__dirname, 'spaces-reset-totp.js');
113
+ const { status } = require('child_process').spawnSync(
114
+ process.execPath, [resetScript, ...args.slice(1)],
115
+ { stdio: 'inherit', env: process.env }
116
+ );
117
+ process.exit(status || 0);
118
+ }
119
+
120
+ // ─── Route service commands to spaces-service.js ─────
121
+ if (subcommand === 'service') {
122
+ const serviceScript = path.join(__dirname, 'spaces-service.js');
123
+ const { status } = require('child_process').spawnSync(
124
+ process.execPath, [serviceScript, ...args.slice(1)],
125
+ { stdio: 'inherit', env: process.env }
126
+ );
127
+ process.exit(status || 0);
128
+ }
129
+
130
+ // ─── Setup wizard ─────────────────────────────────────────
131
+ if (cliFlags.setup) {
132
+ require('./spaces-setup');
133
+ // spaces-setup handles its own process.exit
134
+ } else if (subcommand && !subcommand.startsWith('-')) {
135
+ console.error(` Unknown command: ${subcommand}`);
136
+ console.error(` Run "spaces --help" for usage`);
137
+ process.exit(1);
138
+ } else {
139
+ startServer();
140
+ }
141
+
142
+ // ─── TLS certificate ────────────────────────────────────────
143
+ // Uses a real cert if configured in server.json (tlsCert, tlsKey, optional
144
+ // tlsCa for the full chain), otherwise generates a self-signed cert so
145
+ // mobile browsers that force HTTPS-first can still connect.
146
+ function ensureTlsCert() {
147
+ // Check for configured real cert in server.json
148
+ try {
149
+ const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
150
+ if (config.tlsCert && config.tlsKey) {
151
+ if (fs.existsSync(config.tlsCert) && fs.existsSync(config.tlsKey)) {
152
+ // Read cert + key, and optionally the CA bundle for full chain
153
+ const certPem = fs.readFileSync(config.tlsCert, 'utf-8').trim();
154
+ const caPem = (config.tlsCa && fs.existsSync(config.tlsCa))
155
+ ? fs.readFileSync(config.tlsCa, 'utf-8').trim()
156
+ : null;
157
+ const creds = {
158
+ cert: caPem ? certPem + '\n' + caPem : certPem,
159
+ key: fs.readFileSync(config.tlsKey, 'utf-8'),
160
+ };
161
+ console.log(' Using TLS certificate: ' + config.tlsCert);
162
+ return creds;
163
+ }
164
+ console.log(' Warning: tlsCert/tlsKey configured but files not found, falling back to self-signed');
165
+ }
166
+ } catch {}
167
+
168
+ // Fall back to self-signed
169
+ const certPath = path.join(SPACES_DIR, 'tls-cert.pem');
170
+ const keyPath = path.join(SPACES_DIR, 'tls-key.pem');
171
+
172
+ if (fs.existsSync(certPath) && fs.existsSync(keyPath)) {
173
+ try {
174
+ return { cert: fs.readFileSync(certPath), key: fs.readFileSync(keyPath) };
175
+ } catch {}
176
+ }
177
+
178
+ try {
179
+ fs.mkdirSync(SPACES_DIR, { recursive: true });
180
+ execFileSync('openssl', [
181
+ 'req', '-x509', '-newkey', 'rsa:2048',
182
+ '-keyout', keyPath, '-out', certPath,
183
+ '-sha256', '-days', '365', '-nodes',
184
+ '-subj', '/CN=spaces-local',
185
+ '-addext', 'subjectAltName=DNS:localhost,DNS:*.local,DNS:*.robindale.com,IP:127.0.0.1',
186
+ ], { stdio: 'pipe', timeout: 15000 });
187
+ console.log(' Generated self-signed TLS certificate');
188
+ return { cert: fs.readFileSync(certPath), key: fs.readFileSync(keyPath) };
189
+ } catch (e) {
190
+ console.log(` Warning: Could not generate TLS cert (${e.message})`);
191
+ console.log(' HTTPS will not be available. Install OpenSSL to enable it.');
192
+ return null;
193
+ }
194
+ }
195
+
196
+ function startServer() {
197
+ // ─── Load saved config ────────────────────────────────────
198
+ let savedConfig = {};
199
+ if (fs.existsSync(CONFIG_PATH)) {
200
+ try { savedConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8')); } catch {}
201
+ }
202
+
203
+ // ─── Resolve settings (CLI > env > config > defaults) ─────
204
+ const PORT = cliFlags.port
205
+ || parseInt(process.env.SPACES_PORT || '', 10)
206
+ || savedConfig.port
207
+ || 3457;
208
+
209
+ const basePath = cliFlags.basePath
210
+ || process.env.SPACES_BASE_PATH
211
+ || savedConfig.basePath
212
+ || '';
213
+
214
+ const allowedOrigins = process.env.SPACES_ALLOWED_ORIGINS
215
+ || savedConfig.allowedOrigins
216
+ || '';
217
+
218
+ // ─── Kill any existing server on this port ───────────────────
219
+ stopServer();
220
+
221
+ // ─── Resolve optional packages once ─────────────────────────
222
+ const proPath = resolveSpacesPro();
223
+ const teamsPath = resolveSpacesTeams();
224
+ const cortexPath = resolveSpacesCortex();
225
+
226
+ // Tier resolution: CLI > env > config > auto-detect
227
+ let tier = cliFlags.tier
228
+ || process.env.SPACES_TIER
229
+ || savedConfig.tier
230
+ || '';
231
+
232
+ // Auto-detect tier from package presence
233
+ if (!tier) {
234
+ if (proPath) tier = 'federation';
235
+ else if (teamsPath) tier = 'team';
236
+ else tier = 'community';
237
+ }
238
+
239
+ console.log('');
240
+ console.log(' Spaces - Agent Workspace Manager');
241
+ console.log(' =================================');
242
+ console.log('');
243
+ console.log(` Tier: ${tier}`);
244
+
245
+ // ─── Server tier prerequisites ────────────────────────────
246
+ const childEnv = { ...process.env };
247
+
248
+ if (tier !== 'community') {
249
+ // team/federation tiers require @spaces/teams (auth + collaboration)
250
+ if ((tier === 'team' || tier === 'federation') && !teamsPath) {
251
+ console.error(' Error: @spaces/teams is required for team/federation tiers.');
252
+ console.error(' Install it: spaces install teams');
253
+ process.exit(1);
254
+ }
255
+ // federation tier requires @spaces/pro (network)
256
+ if (tier === 'federation' && !proPath) {
257
+ console.error(' Error: @spaces/pro is required for the federation tier.');
258
+ console.error(' Install it: spaces install pro');
259
+ process.exit(1);
260
+ }
261
+
262
+ // Check for session secret
263
+ let sessionSecret = process.env.SPACES_SESSION_SECRET || '';
264
+ if (!sessionSecret && fs.existsSync(SESSION_SECRET_PATH)) {
265
+ sessionSecret = fs.readFileSync(SESSION_SECRET_PATH, 'utf-8').trim();
266
+ }
267
+
268
+ // Check for admin DB — auto-setup if missing
269
+ const adminDbPath = path.join(SPACES_DIR, 'admin.db');
270
+ if (!fs.existsSync(adminDbPath) || !sessionSecret) {
271
+ const { autoSetup } = require('./lib/auto-setup');
272
+ const result = autoSetup({ SPACES_DIR, SESSION_SECRET_PATH, ADMIN_DB_PATH: adminDbPath, CONFIG_PATH, tier, port: PORT, basePath });
273
+ sessionSecret = result.sessionSecret;
274
+ }
275
+
276
+ childEnv.SPACES_SESSION_SECRET = sessionSecret;
277
+ process.env.SPACES_SESSION_SECRET = sessionSecret;
278
+ console.log(` Admin DB: ${adminDbPath}`);
279
+ }
280
+
281
+ // Set tier in both child env and own process env (terminal-server reads it)
282
+ childEnv.SPACES_TIER = tier;
283
+ process.env.SPACES_TIER = tier;
284
+ if (basePath) {
285
+ childEnv.SPACES_BASE_PATH = basePath;
286
+ console.log(` Base path: ${basePath}`);
287
+ }
288
+ if (allowedOrigins) {
289
+ childEnv.SPACES_ALLOWED_ORIGINS = allowedOrigins;
290
+ process.env.SPACES_ALLOWED_ORIGINS = allowedOrigins;
291
+ console.log(` Allowed origins: ${allowedOrigins}`);
292
+ }
293
+
294
+ // ─── Resolve NODE_PATH for @spaces/pro and @spaces/teams ──
295
+ // Update both childEnv (for the Next.js child process) and process.env
296
+ // (for terminal-server.js which runs in this same parent process).
297
+ // Include:
298
+ // - Managed packages node_modules (~/.spaces/packages/node_modules)
299
+ // - Each managed package's own node_modules (for its bundled deps)
300
+ // - The host app's own node_modules (fallback for peer deps)
301
+ const appNodeModules = path.join(projectDir, 'node_modules');
302
+ const nodePaths = [MANAGED_NODE_MODULES, appNodeModules];
303
+ // Add each resolved package's own node_modules so its bundled deps are found
304
+ for (const pkgPath of [proPath, teamsPath, cortexPath]) {
305
+ if (pkgPath) {
306
+ // pkgPath is the package root (symlink target or direct path)
307
+ const realPath = fs.realpathSync(pkgPath);
308
+ const pkgNodeModules = path.join(realPath, 'node_modules');
309
+ if (fs.existsSync(pkgNodeModules) && !nodePaths.includes(pkgNodeModules)) {
310
+ nodePaths.push(pkgNodeModules);
311
+ }
312
+ // Also add the parent scope for @spaces/* resolution
313
+ const parentModules = path.dirname(path.dirname(pkgPath));
314
+ if (!nodePaths.includes(parentModules)) {
315
+ nodePaths.push(parentModules);
316
+ }
317
+ }
318
+ }
319
+ for (const dir of nodePaths) {
320
+ for (const target of [childEnv, process.env]) {
321
+ const existing = target.NODE_PATH || '';
322
+ if (!existing.includes(dir)) {
323
+ target.NODE_PATH = existing
324
+ ? `${dir}${path.delimiter}${existing}`
325
+ : dir;
326
+ }
327
+ }
328
+ }
329
+ // Re-init module paths so require() in this process picks up the new NODE_PATH
330
+ require('module').Module._initPaths();
331
+
332
+ // Verify collaboration pipeline works end-to-end at startup
333
+ if (tier === 'team' || tier === 'federation') {
334
+ try {
335
+ const teams = require('@spaces/teams');
336
+ console.log(' Collaboration: @spaces/teams loaded OK');
337
+ // Smoke-test that peer deps resolve from this process
338
+ require('better-sqlite3');
339
+ } catch (e) {
340
+ console.error(` Warning: Collaboration may not work — ${e.message}`);
341
+ console.error(' Check that NODE_PATH includes the host app node_modules.');
342
+ }
343
+ }
344
+
345
+ // ─── Detect @spaces/cortex ──────────────────────────────────
346
+ if (cortexPath) {
347
+ childEnv.SPACES_HAS_CORTEX = '1';
348
+ process.env.SPACES_HAS_CORTEX = '1';
349
+ console.log(' Cortex: @spaces/cortex detected');
350
+ }
351
+
352
+ console.log('');
353
+
354
+ // ─── Background update check (non-blocking, repeats every 4h) ──
355
+ // Checks npm registry, GitHub releases, and addon git repos.
356
+ // Writes results to ~/.spaces/update-check.json for the UI banner.
357
+ const updateCheckPath = path.join(SPACES_DIR, 'update-check.json');
358
+ const checkForUpdates = async (logIfAvailable = true) => {
359
+ try {
360
+ const pkg = require(path.join(projectDir, 'package.json'));
361
+ const currentVersion = pkg.version;
362
+ const npmName = pkg.name || '@jlongo78/agent-spaces';
363
+ const githubRepo = 'jlongo78/spaces';
364
+
365
+ // Check npm registry
366
+ let npmLatest = null;
367
+ try {
368
+ const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(npmName)}/latest`, {
369
+ signal: AbortSignal.timeout(5000),
370
+ });
371
+ if (res.ok) {
372
+ const data = await res.json();
373
+ npmLatest = data.version;
374
+ }
375
+ } catch { /* */ }
376
+
377
+ // Check GitHub for latest release or tag (may be ahead of npm)
378
+ let githubLatest = null;
379
+ let githubPrerelease = false;
380
+ let githubUrl = null;
381
+ try {
382
+ // Check releases first (includes pre-releases)
383
+ const res = await fetch(`https://api.github.com/repos/${githubRepo}/releases?per_page=5`, {
384
+ signal: AbortSignal.timeout(5000),
385
+ headers: { 'Accept': 'application/vnd.github.v3+json', 'User-Agent': 'agent-spaces' },
386
+ });
387
+ if (res.ok) {
388
+ const releases = await res.json();
389
+ if (releases.length > 0) {
390
+ // Find latest stable and latest pre-release
391
+ const stable = releases.find(r => !r.prerelease && !r.draft);
392
+ const pre = releases.find(r => r.prerelease && !r.draft);
393
+ if (stable) {
394
+ githubLatest = stable.tag_name.replace(/^v/, '');
395
+ githubUrl = stable.html_url;
396
+ }
397
+ if (pre) {
398
+ const preVersion = pre.tag_name.replace(/^v/, '');
399
+ // If pre-release is newer than stable, surface it
400
+ if (!githubLatest || preVersion > githubLatest) {
401
+ githubLatest = preVersion;
402
+ githubPrerelease = true;
403
+ githubUrl = pre.html_url;
404
+ }
405
+ }
406
+ }
407
+ }
408
+ } catch { /* */ }
409
+
410
+ // Check addon git repos
411
+ const gitSafe = ['-c', 'safe.directory=*'];
412
+ const addonPaths = { teams: teamsPath, pro: proPath, cortex: cortexPath };
413
+ const addons = {};
414
+ for (const [key, addonDir] of Object.entries(addonPaths)) {
415
+ if (!addonDir || !fs.existsSync(path.join(addonDir, '.git'))) continue;
416
+ const realDir = fs.realpathSync(addonDir);
417
+ try {
418
+ execFileSync('git', [...gitSafe, 'fetch', '--quiet'], { cwd: realDir, stdio: 'ignore', timeout: 5000 });
419
+ const local = execFileSync('git', [...gitSafe, 'rev-parse', 'HEAD'], { cwd: realDir, encoding: 'utf-8' }).trim();
420
+ const remote = execFileSync('git', [...gitSafe, 'rev-parse', '@{u}'], { cwd: realDir, encoding: 'utf-8' }).trim();
421
+ const behind = local !== remote;
422
+ let commitsBehind = 0;
423
+ if (behind) {
424
+ try {
425
+ const count = execFileSync('git', [...gitSafe, 'rev-list', '--count', `HEAD..@{u}`], { cwd: realDir, encoding: 'utf-8' }).trim();
426
+ commitsBehind = parseInt(count, 10) || 0;
427
+ } catch { /* */ }
428
+ }
429
+ addons[key] = { installed: true, behind, commitsBehind, localHead: local.slice(0, 7) };
430
+ if (behind && logIfAvailable) {
431
+ console.log(` Update available for @spaces/${key}: ${commitsBehind} commit(s) behind (run: spaces upgrade ${key})`);
432
+ }
433
+ } catch {
434
+ addons[key] = { installed: true, behind: false, commitsBehind: 0 };
435
+ }
436
+ }
437
+
438
+ const npmAvailable = npmLatest && npmLatest !== currentVersion && npmLatest > currentVersion;
439
+ const githubAvailable = githubLatest && githubLatest !== currentVersion && githubLatest > currentVersion;
440
+
441
+ const result = {
442
+ current: currentVersion,
443
+ npm: npmLatest ? { latest: npmLatest, available: !!npmAvailable } : null,
444
+ github: githubLatest ? { latest: githubLatest, prerelease: githubPrerelease, url: githubUrl, available: !!githubAvailable } : null,
445
+ // Backward compat: 'available' and 'latest' still work for the existing banner
446
+ latest: npmLatest || githubLatest || currentVersion,
447
+ available: !!(npmAvailable || githubAvailable),
448
+ addons,
449
+ checkedAt: Date.now(),
450
+ name: npmName,
451
+ };
452
+
453
+ fs.writeFileSync(updateCheckPath, JSON.stringify(result, null, 2));
454
+
455
+ if (npmAvailable && logIfAvailable) {
456
+ console.log(` Update available: ${currentVersion} ${npmLatest} (run: npm i -g ${npmName})`);
457
+ }
458
+ if (githubAvailable && (!npmAvailable || githubLatest > npmLatest) && logIfAvailable) {
459
+ console.log(` GitHub ${githubPrerelease ? 'pre-release' : 'release'}: ${githubLatest} (${githubUrl || `https://github.com/${githubRepo}/releases`})`);
460
+ }
461
+ } catch { /* network error — skip silently */ }
462
+ };
463
+ checkForUpdates(true);
464
+ setInterval(() => checkForUpdates(false), 4 * 3600_000);
465
+
466
+ // Check for ~/.claude/ directory
467
+ const claudeDir = path.join(os.homedir(), '.claude');
468
+ if (!fs.existsSync(claudeDir)) {
469
+ console.log(' Warning: ~/.claude/ not found. Have you used Claude Code yet?');
470
+ console.log('');
471
+ }
472
+
473
+ // ─── Detect build type ────────────────────────────────────
474
+ const standaloneServer = path.join(projectDir, '.next', 'standalone', 'server.js');
475
+ const fullBuildDir = path.join(projectDir, '.next', 'BUILD_ID');
476
+ const isStandalone = fs.existsSync(standaloneServer);
477
+ const isFullBuild = fs.existsSync(fullBuildDir);
478
+
479
+ if (!isStandalone && !isFullBuild) {
480
+ console.error(' Error: No build found.');
481
+ console.error(' Run "npm run build" first, or install via "npm install -g @jlongo78/agent-spaces".');
482
+ process.exit(1);
483
+ }
484
+
485
+ // ─── Spawn Next.js ────────────────────────────────────────
486
+ let next;
487
+ if (isStandalone) {
488
+ const parentNodeModules = path.join(projectDir, 'node_modules');
489
+ const existingNodePath = childEnv.NODE_PATH || '';
490
+ childEnv.NODE_PATH = existingNodePath
491
+ ? `${parentNodeModules}${path.delimiter}${existingNodePath}`
492
+ : parentNodeModules;
493
+
494
+ next = spawn(process.execPath, [standaloneServer], {
495
+ cwd: path.dirname(standaloneServer),
496
+ stdio: ['ignore', 'pipe', 'pipe'],
497
+ env: {
498
+ ...childEnv,
499
+ PORT: String(NEXT_INTERNAL_PORT),
500
+ HOSTNAME: '0.0.0.0',
501
+ NODE_ENV: 'production',
502
+ },
503
+ });
504
+ } else {
505
+ next = spawn('npx', ['next', 'start', '--port', String(NEXT_INTERNAL_PORT)], {
506
+ cwd: projectDir,
507
+ stdio: ['ignore', 'pipe', 'pipe'],
508
+ env: {
509
+ ...childEnv,
510
+ PORT: String(NEXT_INTERNAL_PORT),
511
+ HOSTNAME: '0.0.0.0',
512
+ NODE_ENV: 'production',
513
+ },
514
+ shell: true,
515
+ });
516
+ }
517
+
518
+ let nextReady = false;
519
+
520
+ next.stdout.on('data', (data) => {
521
+ const msg = data.toString();
522
+ process.stdout.write(msg);
523
+ if (!nextReady && (msg.includes('Ready') || msg.includes('started server') || msg.includes('Listening') || msg.includes('localhost'))) {
524
+ nextReady = true;
525
+ console.log(`\n Ready at http://localhost:${PORT}`);
526
+ if (tlsCreds) console.log(` Also at https://localhost:${PORT} (self-signed)`);
527
+ console.log('');
528
+
529
+ const url = `http://localhost:${PORT}`;
530
+ const isService = process.env.SPACES_SERVICE === '1';
531
+ if (!isService) {
532
+ try {
533
+ if (process.platform === 'win32') {
534
+ execFileSync('cmd', ['/c', 'start', url], { stdio: 'ignore' });
535
+ } else if (process.platform === 'darwin') {
536
+ execFileSync('open', [url], { stdio: 'ignore' });
537
+ } else {
538
+ execFileSync('xdg-open', [url], { stdio: 'ignore' });
539
+ }
540
+ } catch {
541
+ console.log(` Open ${url} in your browser`);
542
+ }
543
+ }
544
+ }
545
+ });
546
+
547
+ next.stderr.on('data', (data) => {
548
+ const msg = data.toString();
549
+ if (!msg.includes('Warning')) {
550
+ process.stderr.write(data);
551
+ }
552
+ });
553
+
554
+ next.on('exit', (code) => {
555
+ if (code !== 0 && code !== null) {
556
+ console.error(` [spaces] Next.js exited with code ${code}`);
557
+ }
558
+ cleanup();
559
+ });
560
+
561
+ // ─── Proxy request handler (shared by HTTP and HTTPS) ────
562
+ function proxyHandler(req, res) {
563
+ // WebSocket paths are handled by the 'upgrade' event, but a plain
564
+ // HTTP request to /ws (e.g. health check) should not be proxied to
565
+ // Next.js which would 308-redirect it due to trailingSlash.
566
+ const urlPath = (req.url || '').split('?')[0];
567
+ if (urlPath === '/ws' || urlPath.endsWith('/ws') || urlPath.endsWith('/ws/')) {
568
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
569
+ res.end('WebSocket endpoint');
570
+ return;
571
+ }
572
+
573
+ const proxyReq = http.request(
574
+ {
575
+ hostname: '127.0.0.1',
576
+ port: NEXT_INTERNAL_PORT,
577
+ path: req.url,
578
+ method: req.method,
579
+ headers: req.headers,
580
+ },
581
+ (proxyRes) => {
582
+ res.writeHead(proxyRes.statusCode, proxyRes.headers);
583
+ proxyRes.pipe(res);
584
+ }
585
+ );
586
+ proxyReq.on('error', () => {
587
+ if (!res.headersSent) {
588
+ res.writeHead(502);
589
+ res.end('Server not ready yet. Refresh in a moment.');
590
+ }
591
+ });
592
+ req.pipe(proxyReq);
593
+ }
594
+
595
+ // ─── HTTP + HTTPS on a single port ─────────────────────────
596
+ // Peek at the first byte of each connection: 0x16 = TLS ClientHello,
597
+ // anything else = plain HTTP. This lets mobile browsers that force
598
+ // HTTPS-first connect to the same port without a separate listener.
599
+ const httpServer = http.createServer(proxyHandler);
600
+ const tlsCreds = ensureTlsCert();
601
+ const httpsServer = tlsCreds ? https.createServer(tlsCreds, proxyHandler) : null;
602
+
603
+ const { createTerminalServer } = require('./terminal-server');
604
+ createTerminalServer(httpServer);
605
+ if (httpsServer) createTerminalServer(httpsServer);
606
+
607
+ // Wire up 'address()' on the inner servers so terminal-server can
608
+ // discover the port, then emit 'listening' so its event handler fires.
609
+ const patchAddress = (srv) => { srv.address = () => ({ port: PORT }); };
610
+ patchAddress(httpServer);
611
+ if (httpsServer) patchAddress(httpsServer);
612
+
613
+ const dualServer = net.createServer((socket) => {
614
+ // If client connects but sends nothing for 5s, destroy.
615
+ // Once routed, clear the timeout so long-lived connections (WebSocket) aren't killed.
616
+ socket.setTimeout(5000, () => socket.destroy());
617
+ socket.once('data', (buf) => {
618
+ socket.setTimeout(0);
619
+ socket.pause();
620
+ const target = (buf[0] === 0x16 && httpsServer) ? httpsServer : httpServer;
621
+ target.emit('connection', socket);
622
+ socket.unshift(buf);
623
+ socket.resume();
624
+ });
625
+ });
626
+
627
+ dualServer.listen(PORT, () => {
628
+ // Now that the port is bound, tell the inner servers they're "listening"
629
+ // so terminal-server's mDNS and message watcher start up.
630
+ httpServer.emit('listening');
631
+ if (httpsServer) httpsServer.emit('listening');
632
+
633
+ if (httpsServer) {
634
+ console.log(` Starting server on port ${PORT} (HTTP + HTTPS)`);
635
+ } else {
636
+ console.log(` Starting server on http://localhost:${PORT}`);
637
+ }
638
+ console.log('');
639
+ });
640
+
641
+ function cleanup() {
642
+ next.kill();
643
+ dualServer.close();
644
+ process.exit(0);
645
+ }
646
+
647
+ process.on('SIGINT', cleanup);
648
+ process.on('SIGTERM', cleanup);
649
+ }
650
+
651
+ // ─── Stop running server ─────────────────────────────────────
652
+ function findPidsOnPort(port) {
653
+ const pids = new Set();
654
+ if (process.platform === 'win32') {
655
+ try {
656
+ const output = execFileSync('netstat', ['-ano'], { encoding: 'utf-8' });
657
+ for (const line of output.split(String.fromCharCode(10))) {
658
+ if (line.includes(':' + port + ' ') && line.includes('LISTENING')) {
659
+ const parts = line.trim().split(/\s+/);
660
+ const pid = parseInt(parts[parts.length - 1], 10);
661
+ if (pid > 0) pids.add(pid);
662
+ }
663
+ }
664
+ } catch {}
665
+ } else {
666
+ try {
667
+ const output = execFileSync('lsof', ['-ti', `tcp:${port}`], { encoding: 'utf-8' }).trim();
668
+ for (const p of output.split('\n')) { if (p.trim()) pids.add(parseInt(p.trim(), 10)); }
669
+ } catch {}
670
+ try {
671
+ const output = execFileSync('fuser', [`${port}/tcp`], { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
672
+ for (const p of output.split(/\s+/)) { if (p.trim()) pids.add(parseInt(p.trim(), 10)); }
673
+ } catch {}
674
+ }
675
+ return [...pids].filter(p => !isNaN(p) && p > 0);
676
+ }
677
+
678
+ function stopServer() {
679
+ let savedConfig = {};
680
+ if (fs.existsSync(CONFIG_PATH)) {
681
+ try { savedConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8')); } catch {}
682
+ }
683
+ const port = parseInt(process.env.SPACES_PORT || '', 10) || savedConfig.port || 3457;
684
+ const ports = [port, NEXT_INTERNAL_PORT];
685
+ let killed = 0;
686
+
687
+ for (const p of ports) {
688
+ for (const pid of findPidsOnPort(p)) {
689
+ try {
690
+ process.kill(pid, 'SIGTERM');
691
+ killed++;
692
+ } catch {}
693
+ }
694
+ }
695
+
696
+ if (killed > 0) {
697
+ console.log(` Stopped ${killed} process(es) on port ${port}`);
698
+ // Wait for ports to be released, escalate to SIGKILL if needed
699
+ const deadline = Date.now() + 2000;
700
+ let escalated = false;
701
+ while (Date.now() < deadline) {
702
+ const remaining = ports.flatMap(p => findPidsOnPort(p));
703
+ if (remaining.length === 0) break;
704
+ if (!escalated && Date.now() > deadline - 1000) {
705
+ for (const pid of remaining) {
706
+ try { process.kill(pid, 'SIGKILL'); } catch {}
707
+ }
708
+ escalated = true;
709
+ }
710
+ if (process.platform === 'win32') { require('child_process').spawnSync('powershell', ['-Command', 'Start-Sleep -Milliseconds 200']); } else { require('child_process').spawnSync('sleep', ['0.2']); }
711
+ }
712
+ } else {
713
+ console.log(` No running server found on port ${port}`);
714
+ }
715
+ }
716
+
717
+ // ─── @spaces/pro resolution ──────────────────────────────────
718
+ function resolveSpacesPro() {
719
+ // 1. Managed install (~/.spaces/packages/)
720
+ const managed = path.join(MANAGED_NODE_MODULES, '@spaces', 'pro');
721
+ if (fs.existsSync(path.join(managed, 'dist', 'index.js'))) return managed;
722
+
723
+ // 2. Local node_modules (npm link / optionalDep)
724
+ try {
725
+ return require.resolve('@spaces/pro');
726
+ } catch {}
727
+
728
+ // 3. Global npm prefix (legacy)
729
+ try {
730
+ const globalPrefix = execFileSync('npm', ['prefix', '-g'], { encoding: 'utf-8' }).trim();
731
+ const globalProPath = path.join(globalPrefix, 'lib', 'node_modules', '@spaces', 'pro');
732
+ if (fs.existsSync(globalProPath)) return globalProPath;
733
+ const altPath = path.join(globalPrefix, 'node_modules', '@spaces', 'pro');
734
+ if (fs.existsSync(altPath)) return altPath;
735
+ } catch {}
736
+
737
+ return null;
738
+ }
739
+
740
+ // ─── @spaces/teams resolution ────────────────────────────────
741
+ function resolveSpacesTeams() {
742
+ // 1. Managed install (~/.spaces/packages/)
743
+ const managed = path.join(MANAGED_NODE_MODULES, '@spaces', 'teams');
744
+ if (fs.existsSync(path.join(managed, 'dist', 'index.js'))) return managed;
745
+
746
+ // 2. Local node_modules (npm link / optionalDep)
747
+ try {
748
+ return require.resolve('@spaces/teams');
749
+ } catch {}
750
+
751
+ // 3. Global npm prefix (legacy)
752
+ try {
753
+ const globalPrefix = execFileSync('npm', ['prefix', '-g'], { encoding: 'utf-8' }).trim();
754
+ const globalTeamsPath = path.join(globalPrefix, 'lib', 'node_modules', '@spaces', 'teams');
755
+ if (fs.existsSync(globalTeamsPath)) return globalTeamsPath;
756
+ const altPath = path.join(globalPrefix, 'node_modules', '@spaces', 'teams');
757
+ if (fs.existsSync(altPath)) return altPath;
758
+ } catch {}
759
+
760
+ return null;
761
+ }
762
+
763
+ // ─── @spaces/cortex resolution ───────────────────────────────
764
+ function resolveSpacesCortex() {
765
+ const managed = path.join(MANAGED_NODE_MODULES, '@spaces', 'cortex');
766
+ if (fs.existsSync(path.join(managed, 'dist', 'index.js'))) return managed;
767
+ try { return require.resolve('@spaces/cortex'); } catch {}
768
+ try {
769
+ const globalPrefix = execFileSync('npm', ['prefix', '-g'], { encoding: 'utf-8' }).trim();
770
+ const globalPath = path.join(globalPrefix, 'lib', 'node_modules', '@spaces', 'cortex');
771
+ if (fs.existsSync(globalPath)) return globalPath;
772
+ const altPath = path.join(globalPrefix, 'node_modules', '@spaces', 'cortex');
773
+ if (fs.existsSync(altPath)) return altPath;
774
+ } catch {}
775
+ return null;
776
+ }