@myrialabs/clopen 0.4.37 → 0.4.39

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 (193) hide show
  1. package/README.md +2 -2
  2. package/backend/auth/permissions.ts +39 -0
  3. package/backend/bootstrap.ts +16 -0
  4. package/backend/chat/stream-manager.ts +1 -1
  5. package/backend/database/crypto/envelope.test.ts +93 -0
  6. package/backend/database/crypto/envelope.ts +127 -0
  7. package/backend/database/crypto/index.ts +22 -0
  8. package/backend/database/crypto/master-key.ts +129 -0
  9. package/backend/database/crypto/secret-columns.ts +151 -0
  10. package/backend/database/migrations/071_create_notes_tables.ts +90 -0
  11. package/backend/database/migrations/072_encrypt_stored_secrets.ts +107 -0
  12. package/backend/database/migrations/073_create_integration_tables.ts +119 -0
  13. package/backend/database/migrations/074_create_work_tables.ts +94 -0
  14. package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
  15. package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
  16. package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
  17. package/backend/database/migrations/index.ts +49 -0
  18. package/backend/database/queries/db-client-connection-queries.ts +42 -12
  19. package/backend/database/queries/deploy-queries.ts +124 -0
  20. package/backend/database/queries/engine-queries.ts +23 -10
  21. package/backend/database/queries/graph-queries.ts +291 -247
  22. package/backend/database/queries/index.ts +10 -1
  23. package/backend/database/queries/integration-db-link-queries.ts +168 -0
  24. package/backend/database/queries/integration-queries.ts +325 -0
  25. package/backend/database/queries/mcp-server-queries.ts +38 -11
  26. package/backend/database/queries/note-queries.test.ts +190 -0
  27. package/backend/database/queries/note-queries.ts +269 -0
  28. package/backend/database/queries/profile-queries.ts +1 -1
  29. package/backend/database/queries/ssh-connection-queries.ts +19 -8
  30. package/backend/database/queries/work-queries.ts +210 -0
  31. package/backend/db-client/integrations/index.ts +37 -0
  32. package/backend/db-client/integrations/links.ts +533 -0
  33. package/backend/db-client/integrations/projector.test.ts +280 -0
  34. package/backend/db-client/integrations/projector.ts +256 -0
  35. package/backend/db-client/integrations/supabase-service.ts +266 -0
  36. package/backend/db-client/providers/registry.ts +27 -0
  37. package/backend/db-client/providers/supabase/adapter.ts +500 -0
  38. package/backend/db-client/providers/supabase/api-types.ts +92 -0
  39. package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
  40. package/backend/db-client/providers/supabase/client.ts +259 -0
  41. package/backend/db-client/providers/supabase/features.ts +502 -0
  42. package/backend/db-client/providers/supabase/local.test.ts +78 -0
  43. package/backend/db-client/providers/supabase/local.ts +137 -0
  44. package/backend/db-client/providers/types.ts +137 -0
  45. package/backend/deployments/bindings.test.ts +43 -0
  46. package/backend/deployments/bindings.ts +216 -0
  47. package/backend/deployments/index.ts +53 -0
  48. package/backend/deployments/log-streams.ts +214 -0
  49. package/backend/deployments/prompts.ts +70 -0
  50. package/backend/deployments/providers/vercel/adapter.ts +757 -0
  51. package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
  52. package/backend/deployments/providers/vercel/build-logs.ts +211 -0
  53. package/backend/deployments/providers/vercel/client.ts +203 -0
  54. package/backend/deployments/providers/vercel/list.test.ts +624 -0
  55. package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
  56. package/backend/deployments/providers/vercel/normalise.ts +113 -0
  57. package/backend/deployments/providers/vercel/types.ts +104 -0
  58. package/backend/deployments/registry.ts +27 -0
  59. package/backend/deployments/service.ts +458 -0
  60. package/backend/deployments/types.ts +278 -0
  61. package/backend/engine/docs/artifacts.md +22 -9
  62. package/backend/files/os-clipboard.test.ts +209 -0
  63. package/backend/files/os-clipboard.ts +567 -0
  64. package/backend/http/integration-hooks.ts +42 -0
  65. package/backend/http/notes-images.test.ts +228 -0
  66. package/backend/http/notes-images.ts +196 -0
  67. package/backend/index.ts +13 -0
  68. package/backend/integrations/accounts.ts +229 -0
  69. package/backend/integrations/health.ts +146 -0
  70. package/backend/integrations/index.ts +36 -0
  71. package/backend/integrations/projections/index.ts +0 -0
  72. package/backend/integrations/projections/mcp-projector.test.ts +204 -0
  73. package/backend/integrations/projections/mcp-projector.ts +163 -0
  74. package/backend/integrations/projections/types.ts +63 -0
  75. package/backend/integrations/registry/define.ts +38 -0
  76. package/backend/integrations/registry/index.ts +60 -0
  77. package/backend/integrations/registry/providers/context7.ts +44 -0
  78. package/backend/integrations/registry/providers/firecrawl.ts +41 -0
  79. package/backend/integrations/registry/providers/github.ts +78 -0
  80. package/backend/integrations/registry/providers/supabase.ts +61 -0
  81. package/backend/integrations/registry/providers/vercel.ts +46 -0
  82. package/backend/integrations/registry/types.ts +96 -0
  83. package/backend/integrations/webhooks/gateway.ts +160 -0
  84. package/backend/integrations/webhooks/verify.ts +65 -0
  85. package/backend/mcp/README.md +25 -3
  86. package/backend/mcp/external/config.ts +35 -1
  87. package/backend/mcp/index.ts +1 -1
  88. package/backend/mcp/internal/config.ts +1 -1
  89. package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
  90. package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
  91. package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
  92. package/backend/memory/README.md +57 -34
  93. package/backend/memory/compose.test.ts +3 -3
  94. package/backend/memory/compose.ts +6 -9
  95. package/backend/memory/config.ts +0 -5
  96. package/backend/memory/consolidate.ts +1 -2
  97. package/backend/memory/context.test.ts +8 -54
  98. package/backend/memory/context.ts +19 -25
  99. package/backend/memory/extract/episodic.ts +10 -12
  100. package/backend/memory/extract/index.ts +23 -52
  101. package/backend/memory/extract/scheduler.ts +3 -6
  102. package/backend/memory/index.ts +6 -5
  103. package/backend/memory/invalidate.ts +36 -48
  104. package/backend/memory/layout.ts +319 -130
  105. package/backend/memory/retention.ts +12 -42
  106. package/backend/memory/retrieval.eval.test.ts +2 -2
  107. package/backend/memory/retrieval.test.ts +228 -183
  108. package/backend/memory/retrieval.ts +22 -21
  109. package/backend/memory/revise.test.ts +62 -116
  110. package/backend/memory/revise.ts +0 -1
  111. package/backend/memory/view.ts +8 -5
  112. package/backend/notes/access.test.ts +82 -0
  113. package/backend/notes/access.ts +27 -0
  114. package/backend/notes/storage.test.ts +77 -0
  115. package/backend/notes/storage.ts +114 -0
  116. package/backend/permissions/service.ts +2 -2
  117. package/backend/profiles/service.ts +1 -1
  118. package/backend/projects/project-cleanup.ts +6 -0
  119. package/backend/snapshot/helpers.ts +35 -41
  120. package/backend/snapshot/snapshot-service.ts +90 -0
  121. package/backend/snapshot/turn-changes.test.ts +163 -0
  122. package/backend/snapshot/turn-changes.ts +131 -0
  123. package/backend/work/bindings.ts +124 -0
  124. package/backend/work/index.ts +42 -0
  125. package/backend/work/prompts.ts +150 -0
  126. package/backend/work/providers/github/actions-logs.ts +180 -0
  127. package/backend/work/providers/github/adapter.test.ts +88 -0
  128. package/backend/work/providers/github/adapter.ts +1255 -0
  129. package/backend/work/providers/github/client.ts +280 -0
  130. package/backend/work/providers/github/list-range.test.ts +158 -0
  131. package/backend/work/providers/github/token-kind.test.ts +42 -0
  132. package/backend/work/pull-requests.ts +242 -0
  133. package/backend/work/registry.ts +27 -0
  134. package/backend/work/service.ts +436 -0
  135. package/backend/work/start-work.test.ts +71 -0
  136. package/backend/work/start-work.ts +232 -0
  137. package/backend/work/types.ts +180 -0
  138. package/backend/ws/db-client/accounts.ts +225 -0
  139. package/backend/ws/db-client/connections.ts +34 -3
  140. package/backend/ws/db-client/context.ts +37 -0
  141. package/backend/ws/db-client/index.ts +20 -1
  142. package/backend/ws/db-client/supabase.ts +188 -0
  143. package/backend/ws/deployments/actions.ts +360 -0
  144. package/backend/ws/deployments/context.ts +43 -0
  145. package/backend/ws/deployments/crud.ts +152 -0
  146. package/backend/ws/deployments/index.ts +15 -0
  147. package/backend/ws/deployments/schemas.ts +183 -0
  148. package/backend/ws/files/clipboard.ts +78 -0
  149. package/backend/ws/files/index.ts +5 -0
  150. package/backend/ws/git/diff-budget.ts +70 -11
  151. package/backend/ws/index.ts +16 -2
  152. package/backend/ws/integrations/crud.ts +219 -0
  153. package/backend/ws/integrations/index.ts +22 -0
  154. package/backend/ws/mcp/crud.ts +25 -1
  155. package/backend/ws/memory/crud.ts +4 -16
  156. package/backend/ws/notes/index.ts +278 -0
  157. package/backend/ws/profiles/crud.ts +1 -1
  158. package/backend/ws/snapshot/changes.ts +279 -0
  159. package/backend/ws/snapshot/index.ts +4 -3
  160. package/backend/ws/work/actions.ts +206 -0
  161. package/backend/ws/work/context.ts +51 -0
  162. package/backend/ws/work/crud.ts +347 -0
  163. package/backend/ws/work/index.ts +17 -0
  164. package/backend/ws/work/pull-requests.ts +177 -0
  165. package/backend/ws/work/schemas.ts +226 -0
  166. package/dist/assets/{index-sJmS_CCm.js → index-BrF6nqld.js} +1 -1
  167. package/dist/assets/{index-Bik9TCBi.js → index-C8Gi-b6U.js} +1 -1
  168. package/dist/assets/main-Bd3gb79F.css +1 -0
  169. package/dist/assets/main-Bo1hD7mt.js +1191 -0
  170. package/dist/index.html +2 -2
  171. package/package.json +1 -1
  172. package/shared/constants/engine-tools.ts +1 -1
  173. package/shared/constants/tool-icons.ts +42 -0
  174. package/shared/types/database/schema.ts +41 -0
  175. package/shared/types/db-client/connection.ts +6 -0
  176. package/shared/types/db-client/index.ts +2 -0
  177. package/shared/types/db-client/integrations.ts +174 -0
  178. package/shared/types/db-client/supabase.ts +131 -0
  179. package/shared/types/deployments.ts +382 -0
  180. package/shared/types/integrations.ts +140 -0
  181. package/shared/types/memory.ts +34 -51
  182. package/shared/types/stores/settings.ts +8 -0
  183. package/shared/types/ui/components.ts +1 -1
  184. package/shared/types/work.ts +426 -0
  185. package/shared/utils/diff-calculator.test.ts +89 -0
  186. package/shared/utils/diff-calculator.ts +30 -65
  187. package/shared/utils/logger.ts +4 -0
  188. package/backend/memory/extract/languages.ts +0 -176
  189. package/backend/memory/extract/structural.test.ts +0 -215
  190. package/backend/memory/extract/structural.ts +0 -364
  191. package/backend/ws/snapshot/content.ts +0 -85
  192. package/dist/assets/main-DLqolBI2.css +0 -1
  193. package/dist/assets/main-Df1I3hnw.js +0 -1096
@@ -0,0 +1,183 @@
1
+ /**
2
+ * TypeBox shapes for the Deployments surface.
3
+ *
4
+ * Kept in one file because three handler modules serialise the same deployment,
5
+ * and a schema copied per handler is a schema that drifts per handler — the
6
+ * client's generated types then disagree with each other rather than with the
7
+ * server, which is much harder to notice.
8
+ */
9
+
10
+ import { t } from 'elysia';
11
+
12
+ export const DEPLOYMENT_STATE_SCHEMA = t.Union([
13
+ t.Literal('queued'),
14
+ t.Literal('building'),
15
+ t.Literal('ready'),
16
+ t.Literal('error'),
17
+ t.Literal('canceled')
18
+ ]);
19
+
20
+ export const ENVIRONMENT_SCHEMA = t.Union([
21
+ t.Literal('production'),
22
+ t.Literal('preview'),
23
+ t.Literal('custom')
24
+ ]);
25
+
26
+ export const ENVIRONMENT_FILTER_SCHEMA = t.Union([ENVIRONMENT_SCHEMA, t.Literal('all')]);
27
+
28
+ export const STATUS_SCHEMA = t.Union([
29
+ t.Literal('ok'),
30
+ t.Literal('needs_auth'),
31
+ t.Literal('needs_config'),
32
+ t.Literal('error'),
33
+ t.Literal('unknown')
34
+ ]);
35
+
36
+ export const DEPLOY_ACTION_SCHEMA = t.Union([
37
+ t.Literal('redeploy'),
38
+ t.Literal('cancel'),
39
+ t.Literal('rollback'),
40
+ t.Literal('promote'),
41
+ t.Literal('delete')
42
+ ]);
43
+
44
+ export const RATE_LIMIT_SCHEMA = t.Object({
45
+ remaining: t.Number(),
46
+ limit: t.Number(),
47
+ resetAt: t.Union([t.String(), t.Null()])
48
+ });
49
+
50
+ export const DEPLOYMENT_SCHEMA = t.Object({
51
+ id: t.String(),
52
+ name: t.String(),
53
+ url: t.Union([t.String(), t.Null()]),
54
+ inspectorUrl: t.Union([t.String(), t.Null()]),
55
+ state: DEPLOYMENT_STATE_SCHEMA,
56
+ stateDetail: t.String(),
57
+ environment: ENVIRONMENT_SCHEMA,
58
+ isCurrent: t.Boolean(),
59
+ isRollbackCandidate: t.Union([t.Boolean(), t.Null()]),
60
+ branch: t.Union([t.String(), t.Null()]),
61
+ commitSha: t.Union([t.String(), t.Null()]),
62
+ commitMessage: t.Union([t.String(), t.Null()]),
63
+ creator: t.Union([t.String(), t.Null()]),
64
+ createdAt: t.String(),
65
+ buildingAt: t.Union([t.String(), t.Null()]),
66
+ readyAt: t.Union([t.String(), t.Null()]),
67
+ errorCode: t.Union([t.String(), t.Null()]),
68
+ errorMessage: t.Union([t.String(), t.Null()]),
69
+ source: t.Union([t.String(), t.Null()])
70
+ });
71
+
72
+ export const DEPLOYMENT_DETAIL_SCHEMA = t.Composite([
73
+ DEPLOYMENT_SCHEMA,
74
+ t.Object({
75
+ aliases: t.Array(t.String()),
76
+ framework: t.Union([t.String(), t.Null()]),
77
+ durationMs: t.Union([t.Number(), t.Null()])
78
+ })
79
+ ]);
80
+
81
+ export const DEPLOY_TARGET_SCHEMA = t.Object({
82
+ id: t.String(),
83
+ name: t.String(),
84
+ teamId: t.Union([t.String(), t.Null()]),
85
+ teamName: t.Union([t.String(), t.Null()]),
86
+ framework: t.Union([t.String(), t.Null()]),
87
+ gitRepo: t.Union([t.String(), t.Null()])
88
+ });
89
+
90
+ export const DEPLOY_CONFIG_SCHEMA = t.Object({
91
+ environment: ENVIRONMENT_FILTER_SCHEMA,
92
+ autoRefresh: t.Boolean()
93
+ });
94
+
95
+ export const DEPLOY_BINDING_SCHEMA = t.Object({
96
+ locator: t.String(),
97
+ displayName: t.String(),
98
+ detected: t.Boolean(),
99
+ teamId: t.Union([t.String(), t.Null()]),
100
+ config: DEPLOY_CONFIG_SCHEMA
101
+ });
102
+
103
+ export const DEPLOY_CAPABILITIES_SCHEMA = t.Object({
104
+ logs: t.Boolean(),
105
+ createDeployment: t.Boolean(),
106
+ createProject: t.Boolean(),
107
+ connectRepository: t.Boolean(),
108
+ deleteDeployment: t.Boolean(),
109
+ streamLogs: t.Boolean(),
110
+ redeploy: t.Boolean(),
111
+ cancel: t.Boolean(),
112
+ rollback: t.Boolean(),
113
+ promote: t.Boolean(),
114
+ environments: t.Boolean(),
115
+ branchFilter: t.Boolean()
116
+ });
117
+
118
+ export const DEPLOY_SOURCE_SCHEMA = t.Object({
119
+ accountId: t.String(),
120
+ provider: t.String(),
121
+ providerName: t.String(),
122
+ label: t.String(),
123
+ viewer: t.Union([t.String(), t.Null()]),
124
+ capabilities: DEPLOY_CAPABILITIES_SCHEMA,
125
+ binding: t.Union([DEPLOY_BINDING_SCHEMA, t.Null()]),
126
+ suggestedTargets: t.Array(DEPLOY_TARGET_SCHEMA),
127
+ status: STATUS_SCHEMA,
128
+ statusDetail: t.Union([t.String(), t.Null()])
129
+ });
130
+
131
+ export const LOG_BUNDLE_SCHEMA = t.Object({
132
+ deploymentId: t.String(),
133
+ text: t.String(),
134
+ truncated: t.Boolean()
135
+ });
136
+
137
+ export const ACTION_RESULT_SCHEMA = t.Object({
138
+ action: DEPLOY_ACTION_SCHEMA,
139
+ status: t.Union([t.Literal('done'), t.Literal('pending')]),
140
+ deploymentId: t.Union([t.String(), t.Null()]),
141
+ message: t.String()
142
+ });
143
+
144
+ export const DEPLOY_INFO_SCHEMA = t.Object({
145
+ gitRepo: t.Union([t.String(), t.Null()]),
146
+ productionBranch: t.Union([t.String(), t.Null()]),
147
+ canDeploy: t.Boolean(),
148
+ reason: t.Union([t.String(), t.Null()]),
149
+ suggestedRepo: t.Union([t.String(), t.Null()]),
150
+ connectState: t.Union([
151
+ t.Literal('ready'),
152
+ t.Literal('blocked'),
153
+ t.Literal('unknown'),
154
+ t.Literal('unavailable')
155
+ ]),
156
+ connectHint: t.Union([t.String(), t.Null()]),
157
+ connectUrl: t.Union([t.String(), t.Null()]),
158
+ currentBranch: t.Union([t.String(), t.Null()])
159
+ });
160
+
161
+ export const NEW_PROJECT_DEFAULTS_SCHEMA = t.Object({
162
+ suggestedName: t.String(),
163
+ gitRepo: t.Union([t.String(), t.Null()]),
164
+ gitProvider: t.Union([t.String(), t.Null()])
165
+ });
166
+
167
+ export const PROJECT_STATUS_SCHEMA = t.Object({
168
+ paused: t.Boolean(),
169
+ aliasRequest: t.Union([
170
+ t.Object({
171
+ type: t.Union([t.Literal('rollback'), t.Literal('promote')]),
172
+ status: t.Union([
173
+ t.Literal('pending'),
174
+ t.Literal('in-progress'),
175
+ t.Literal('succeeded'),
176
+ t.Literal('failed'),
177
+ t.Literal('skipped')
178
+ ]),
179
+ toDeploymentId: t.Union([t.String(), t.Null()])
180
+ }),
181
+ t.Null()
182
+ ])
183
+ });
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Files OS Clipboard Operations
3
+ *
4
+ * `files:copy-to-os-clipboard` — places Clopen files/folders onto the native
5
+ * clipboard of the machine the SERVER runs on, so the user can paste them in
6
+ * File Explorer / Finder / their Linux file manager. `effect: 'copy'`
7
+ * (default) pastes duplicates and keeps the Clopen sources; `effect: 'move'`
8
+ * (used for CUT) lets the file manager relocate them. The response echoes the
9
+ * effect that was actually published — macOS cannot express "move" on the
10
+ * pasteboard, so a CUT lands there as a copy and the UI says so. The
11
+ * frontend's internal clipboard is untouched; this only adds the OS-native
12
+ * side.
13
+ *
14
+ * `files:read-os-clipboard` — the reverse direction: reads file/folder
15
+ * entries copied in a native file manager so the Clopen context-menu Paste
16
+ * works even when the copy source was outside Clopen. Browsers cannot read a
17
+ * native file-drop list on a menu click (no DataTransfer), hence this backend
18
+ * round-trip.
19
+ *
20
+ * Security: both routes act on the HOST machine's clipboard, which belongs to
21
+ * whoever runs the server — not to a remote collaborator. A member's project
22
+ * grants say nothing about that clipboard, and its contents are absolute
23
+ * paths that can sit anywhere on disk (another user's project, a home
24
+ * directory), so both routes are admin-only.
25
+ *
26
+ * The read route answers a non-admin with an empty list rather than an error:
27
+ * the frontend polls it to decide whether to offer "Paste", and an empty list
28
+ * simply means "nothing pasteable from the OS" — no error toast on every
29
+ * context-menu open. The write route throws, because it is only ever reached
30
+ * from an explicit Copy/Cut the caller asked for.
31
+ *
32
+ * Published paths still go through the standard per-user file access guard on
33
+ * top of the admin check, so the guard stays correct if the policy is ever
34
+ * widened. The backend only *publishes references* — the file manager
35
+ * performs the actual copy, and sources are never moved or deleted by Clopen.
36
+ */
37
+
38
+ import { t } from 'elysia';
39
+ import { createRouter } from '$shared/utils/ws-server';
40
+ import { ws } from '$backend/utils/ws';
41
+ import { copyPathsToOsClipboard, readOsClipboardFilePaths } from '../../files/os-clipboard';
42
+ import { requireFilePathAccess } from './path-access';
43
+
44
+ export const clipboardHandler = createRouter()
45
+ .http('files:copy-to-os-clipboard', {
46
+ data: t.Object({
47
+ paths: t.Array(t.String(), { minItems: 1 }),
48
+ effect: t.Optional(t.Union([t.Literal('copy'), t.Literal('move')]))
49
+ }),
50
+ response: t.Object({
51
+ count: t.Number(),
52
+ /** The effect actually published — `copy` on macOS even for a CUT. */
53
+ effect: t.Union([t.Literal('copy'), t.Literal('move')])
54
+ })
55
+ }, async ({ data, conn }) => {
56
+ if (ws.getRole(conn) !== 'admin') {
57
+ throw new Error('Access denied');
58
+ }
59
+ const resolved: string[] = [];
60
+ for (const p of data.paths) {
61
+ resolved.push(await requireFilePathAccess(conn, p));
62
+ }
63
+ return await copyPathsToOsClipboard(resolved, data.effect ?? 'copy');
64
+ })
65
+ .http('files:read-os-clipboard', {
66
+ data: t.Object({}),
67
+ response: t.Object({
68
+ items: t.Array(t.Object({
69
+ path: t.String(),
70
+ isDirectory: t.Boolean()
71
+ }))
72
+ })
73
+ }, async ({ conn }) => {
74
+ if (ws.getRole(conn) !== 'admin') {
75
+ return { items: [] };
76
+ }
77
+ return { items: await readOsClipboardFilePaths() };
78
+ });
@@ -7,6 +7,7 @@
7
7
  * - read.ts: HTTP endpoints for reading (list-tree, browse, read-file, read-content)
8
8
  * - write.ts: HTTP endpoints for writing (write, create, rename, duplicate, upload, delete)
9
9
  * - reveal.ts: HTTP endpoint for revealing files in the OS file manager
10
+ * - clipboard.ts: HTTP endpoints for the native OS clipboard bridge (admin-only)
10
11
  * - search.ts: HTTP endpoints for searching (search-files, search-code)
11
12
  * - watch.ts: Event handlers for real-time file watching
12
13
  */
@@ -15,6 +16,7 @@ import { createRouter } from '$shared/utils/ws-server';
15
16
  import { readHandler } from './read';
16
17
  import { writeHandler } from './write';
17
18
  import { revealHandler } from './reveal';
19
+ import { clipboardHandler } from './clipboard';
18
20
  import { imageEditHandler } from './image-edit';
19
21
  import { fileSearchHandler } from './search';
20
22
  import { watchHandler } from './watch';
@@ -30,6 +32,9 @@ export const filesRouter = createRouter()
30
32
  // Reveal in File Manager (HTTP)
31
33
  .merge(revealHandler)
32
34
 
35
+ // OS Clipboard bridge — read/write native file-drop lists (HTTP)
36
+ .merge(clipboardHandler)
37
+
33
38
  // Image Edit Operation (HTTP)
34
39
  .merge(imageEditHandler)
35
40
 
@@ -51,6 +51,56 @@ export const BRANCH_NAME_BUDGET: DiffBudget = {
51
51
  contextLines: 0
52
52
  };
53
53
 
54
+ /**
55
+ * Budget for pull-request descriptions. The most generous of the three: a PR
56
+ * description covers a whole branch rather than one commit, and a description
57
+ * written from a heavily sampled diff is the one that invents changes.
58
+ */
59
+ export const PR_DESCRIPTION_BUDGET: DiffBudget = {
60
+ perFileBytes: 8 * 1024,
61
+ totalBytes: 40 * 1024,
62
+ maxFiles: 60,
63
+ contextLines: 3
64
+ };
65
+
66
+ /**
67
+ * WHICH diff to budget.
68
+ *
69
+ * Extracted when the pull-request composer needed `base...head` instead of
70
+ * `--cached`. Everything below is identical for both — the file walk, the
71
+ * skip list, the per-file clipping — so the scope is a parameter rather than a
72
+ * second copy of the builder that would drift from this one.
73
+ */
74
+ export interface DiffScope {
75
+ /** Operands inserted into every `git diff` invocation. */
76
+ args: string[];
77
+ /** How the patch section is introduced. */
78
+ label: string;
79
+ /** Wording when nothing changed, used by the caller's empty check. */
80
+ emptyLabel: string;
81
+ }
82
+
83
+ export const STAGED_SCOPE: DiffScope = {
84
+ args: ['--cached'],
85
+ label: 'Staged diff',
86
+ emptyLabel: 'staged changes'
87
+ };
88
+
89
+ /**
90
+ * Everything on `head` that is not on `base`.
91
+ *
92
+ * Three dots, not two: `base..head` would also show changes made to base since
93
+ * the branch left it, which are not this pull request's changes and are exactly
94
+ * what makes an AI-written description claim work someone else did.
95
+ */
96
+ export function rangeScope(base: string, head: string): DiffScope {
97
+ return {
98
+ args: [`${base}...${head}`],
99
+ label: `Diff (${base}...${head})`,
100
+ emptyLabel: `changes between ${base} and ${head}`
101
+ };
102
+ }
103
+
54
104
  /**
55
105
  * Paths whose diff is machine-generated: enormous, uninformative, and the single
56
106
  * biggest source of wasted context. They still appear in the `--stat` header, so
@@ -123,29 +173,30 @@ export interface BudgetedDiff {
123
173
  text: string;
124
174
  /** True when any file's patch was clipped or dropped. */
125
175
  truncated: boolean;
126
- /** True when there is nothing staged at all. */
176
+ /** True when the scope contains no change at all. */
127
177
  isEmpty: boolean;
128
178
  }
129
179
 
130
180
  /**
131
- * Build the staged-diff section of an AI prompt under `budget`.
181
+ * Build the diff section of an AI prompt under `budget`, for `scope`.
132
182
  *
133
183
  * We deliberately spawn one `git diff` per file rather than one for everything:
134
- * it lets us stop as soon as the budget is spent, so a 200 MB staged blob is
135
- * never read into memory in the first place.
184
+ * it lets us stop as soon as the budget is spent, so a 200 MB blob is never read
185
+ * into memory in the first place.
136
186
  */
137
- export async function buildBudgetedStagedDiff(
187
+ export async function buildBudgetedDiff(
138
188
  cwd: string,
139
- budget: DiffBudget
189
+ budget: DiffBudget,
190
+ scope: DiffScope = STAGED_SCOPE
140
191
  ): Promise<BudgetedDiff> {
141
- const numstat = await execGit(['diff', '--cached', '--numstat', '-z', '-M'], cwd);
192
+ const numstat = await execGit(['diff', ...scope.args, '--numstat', '-z', '-M'], cwd);
142
193
  const entries = parseNumstat(numstat.stdout);
143
194
 
144
195
  if (entries.length === 0) {
145
196
  return { text: '', truncated: false, isEmpty: true };
146
197
  }
147
198
 
148
- const statResult = await execGit(['diff', '--cached', '--stat=200', '-M'], cwd);
199
+ const statResult = await execGit(['diff', ...scope.args, '--stat=200', '-M'], cwd);
149
200
  const stat = statResult.stdout.trim();
150
201
 
151
202
  const skipped: string[] = [];
@@ -180,7 +231,7 @@ export async function buildBudgetedStagedDiff(
180
231
  const result = await execGit(
181
232
  [
182
233
  'diff',
183
- '--cached',
234
+ ...scope.args,
184
235
  '--no-color',
185
236
  `--unified=${budget.contextLines}`,
186
237
  '-M',
@@ -208,8 +259,8 @@ export async function buildBudgetedStagedDiff(
208
259
  }
209
260
  if (patches.length > 0) {
210
261
  const header = truncated
211
- ? 'Staged diff (sampled — some files or lines were omitted to fit context):'
212
- : 'Staged diff:';
262
+ ? `${scope.label} (sampled — some files or lines were omitted to fit context):`
263
+ : `${scope.label}:`;
213
264
  sections.push(`${header}\n${patches.join('\n')}`);
214
265
  }
215
266
  if (filesOmitted > 0) {
@@ -218,3 +269,11 @@ export async function buildBudgetedStagedDiff(
218
269
 
219
270
  return { text: sections.join('\n\n'), truncated, isEmpty: false };
220
271
  }
272
+
273
+ /** The staged diff. Kept as its own name because two callers read better for it. */
274
+ export async function buildBudgetedStagedDiff(
275
+ cwd: string,
276
+ budget: DiffBudget
277
+ ): Promise<BudgetedDiff> {
278
+ return buildBudgetedDiff(cwd, budget, STAGED_SCOPE);
279
+ }
@@ -35,6 +35,7 @@ import { sshRouter } from './ssh';
35
35
  import { portsRouter } from './ports';
36
36
  import { containersRouter } from './containers';
37
37
  import { mcpRouter } from './mcp';
38
+ import { integrationsRouter } from './integrations';
38
39
  import { skillsRouter } from './skills';
39
40
  import { commandsRouter } from './commands';
40
41
  import { subagentsRouter } from './subagents';
@@ -44,6 +45,9 @@ import { profilesRouter } from './profiles';
44
45
  import { artifactsRouter } from './artifacts';
45
46
  import { memoryRouter } from './memory';
46
47
  import { worktreesRouter } from './worktrees';
48
+ import { notesRouter } from './notes';
49
+ import { workRouter } from './work';
50
+ import { deploymentsRouter } from './deployments';
47
51
 
48
52
  // ============================================
49
53
  // Main App Router - Merge All Module Routers
@@ -98,6 +102,7 @@ export const wsRouter = createRouter()
98
102
 
99
103
  // External MCP server management (install from the official registry)
100
104
  .merge(mcpRouter)
105
+ .merge(integrationsRouter)
101
106
 
102
107
  // Agent Skills management (create, import, install from a marketplace)
103
108
  .merge(skillsRouter)
@@ -112,8 +117,17 @@ export const wsRouter = createRouter()
112
117
  .merge(profilesRouter)
113
118
  .merge(artifactsRouter)
114
119
 
115
- // Memory Graph (unified episodic + structural memory, shared by every engine)
116
- .merge(memoryRouter);
120
+ // Memory Graph (one store of memories, shared by every engine)
121
+ .merge(memoryRouter)
122
+
123
+ // Notes (project-scoped markdown)
124
+ .merge(notesRouter)
125
+
126
+ // Issues & PRs surface — work items, pull requests and CI for the current project
127
+ .merge(workRouter)
128
+
129
+ // Deployments surface — builds, logs and what is live, for the current project
130
+ .merge(deploymentsRouter);
117
131
 
118
132
  // Export API type for frontend type-safe access
119
133
  export type WSAPI = typeof wsRouter['$api'];
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Integration account handlers.
3
+ *
4
+ * integrations:providers — the registry, as the catalogue renders it
5
+ * integrations:list — connected accounts (never credential values)
6
+ * integrations:connect — create an account and project its capabilities
7
+ * integrations:update — credentials / capabilities / project / enabled
8
+ * integrations:disconnect — release every projection, then drop the account
9
+ * integrations:health — probe one account
10
+ * integrations:secrets-health — state of secrets at rest, for the hub banner
11
+ *
12
+ * Admin-gated in `backend/auth/permissions.ts`, matching the MCP surface it
13
+ * absorbs: connecting an account changes what every engine and every project
14
+ * can reach.
15
+ */
16
+
17
+ import { t } from 'elysia';
18
+ import { createRouter } from '$shared/utils/ws-server';
19
+ import { debug } from '$shared/utils/logger';
20
+ import {
21
+ checkAccountHealth,
22
+ getSecretsHealth,
23
+ integrationAccounts,
24
+ listProviderInfo
25
+ } from '$backend/integrations';
26
+ import { INTEGRATION_CAPABILITIES, INTEGRATION_CATEGORIES } from '$shared/types/integrations';
27
+ import type { IntegrationCapability } from '$shared/types/integrations';
28
+ import { ws as wsServer } from '$backend/utils/ws';
29
+
30
+ /**
31
+ * Tell every connected client an account changed.
32
+ *
33
+ * Global rather than per-project: an account can be bound to a project, but the
34
+ * connector row it projects is instance-wide, and the hub is an instance-wide
35
+ * screen.
36
+ */
37
+ function announce(accountId?: string): void {
38
+ wsServer.emit.global('integrations:changed', accountId ? { accountId } : {});
39
+ }
40
+
41
+ const CAPABILITY_SCHEMA = t.Union(INTEGRATION_CAPABILITIES.map((capability) => t.Literal(capability)));
42
+ const CATEGORY_SCHEMA = t.Union(INTEGRATION_CATEGORIES.map((category) => t.Literal(category)));
43
+
44
+ const STATUS_SCHEMA = t.Union([
45
+ t.Literal('unknown'),
46
+ t.Literal('ok'),
47
+ t.Literal('needs_auth'),
48
+ t.Literal('needs_config'),
49
+ t.Literal('error')
50
+ ]);
51
+
52
+ const AUTH_METHOD_SCHEMA = t.Union([
53
+ t.Literal('api-key'),
54
+ t.Literal('oauth-device'),
55
+ t.Literal('oauth-code'),
56
+ t.Literal('mcp-oauth'),
57
+ t.Literal('connection-string'),
58
+ t.Literal('none')
59
+ ]);
60
+
61
+ const CREDENTIAL_FIELD_SCHEMA = t.Object({
62
+ name: t.String(),
63
+ label: t.String(),
64
+ placeholder: t.Optional(t.String()),
65
+ help: t.Optional(t.String()),
66
+ isSecret: t.Boolean(),
67
+ isRequired: t.Boolean()
68
+ });
69
+
70
+ const PROVIDER_SCHEMA = t.Object({
71
+ id: t.String(),
72
+ name: t.String(),
73
+ category: CATEGORY_SCHEMA,
74
+ description: t.String(),
75
+ docsUrl: t.Optional(t.String()),
76
+ authMethod: AUTH_METHOD_SCHEMA,
77
+ credentialFields: t.Array(CREDENTIAL_FIELD_SCHEMA),
78
+ capabilities: t.Array(CAPABILITY_SCHEMA),
79
+ defaultCapabilities: t.Array(CAPABILITY_SCHEMA),
80
+ providesAgentTools: t.Boolean(),
81
+ acceptsWebhooks: t.Boolean()
82
+ });
83
+
84
+ const ACCOUNT_SCHEMA = t.Object({
85
+ id: t.String(),
86
+ provider: t.String(),
87
+ label: t.String(),
88
+ projectId: t.Union([t.String(), t.Null()]),
89
+ authMethod: AUTH_METHOD_SCHEMA,
90
+ // Which fields hold a value — NOT the values. A credential that reached the
91
+ // client would be a credential in a log, a screenshot and a bug report.
92
+ configuredFields: t.Array(t.String()),
93
+ capabilities: t.Array(CAPABILITY_SCHEMA),
94
+ status: STATUS_SCHEMA,
95
+ statusDetail: t.Union([t.String(), t.Null()]),
96
+ checkedAt: t.Union([t.String(), t.Null()]),
97
+ isEnabled: t.Boolean(),
98
+ createdAt: t.String(),
99
+ updatedAt: t.String(),
100
+ projections: t.Array(t.Object({
101
+ capability: CAPABILITY_SCHEMA,
102
+ targetKind: t.Union([t.Literal('mcp_server'), t.Literal('db_client_connection')]),
103
+ targetId: t.String(),
104
+ adopted: t.Boolean()
105
+ }))
106
+ });
107
+
108
+ const SECRETS_HEALTH_SCHEMA = t.Object({
109
+ keySource: t.Union([t.Literal('env'), t.Literal('file')]),
110
+ keyFingerprint: t.String(),
111
+ failureCount: t.Number(),
112
+ lastFailureAt: t.Union([t.String(), t.Null()]),
113
+ unknownKeyFingerprints: t.Array(t.String()),
114
+ unsealedColumns: t.Array(t.Object({
115
+ table: t.String(),
116
+ column: t.String(),
117
+ count: t.Number()
118
+ }))
119
+ });
120
+
121
+ export const integrationsCrudHandler = createRouter()
122
+ .http('integrations:providers', {
123
+ data: t.Object({}),
124
+ response: t.Object({ providers: t.Array(PROVIDER_SCHEMA) })
125
+ }, async () => {
126
+ debug.log('path', 'integrations:providers');
127
+ return { providers: listProviderInfo() };
128
+ })
129
+
130
+ .http('integrations:list', {
131
+ data: t.Object({}),
132
+ response: t.Object({ accounts: t.Array(ACCOUNT_SCHEMA) })
133
+ }, async () => {
134
+ debug.log('path', 'integrations:list');
135
+ return { accounts: integrationAccounts.list() };
136
+ })
137
+
138
+ .http('integrations:connect', {
139
+ data: t.Object({
140
+ provider: t.String(),
141
+ label: t.Optional(t.String()),
142
+ projectId: t.Optional(t.Union([t.String(), t.Null()])),
143
+ credentials: t.Record(t.String(), t.String()),
144
+ capabilities: t.Optional(t.Array(CAPABILITY_SCHEMA))
145
+ }),
146
+ response: t.Object({ account: ACCOUNT_SCHEMA })
147
+ }, async ({ data }) => {
148
+ debug.log('path', `integrations:connect ${data.provider}`);
149
+ const account = integrationAccounts.connect({
150
+ provider: data.provider,
151
+ label: data.label,
152
+ projectId: data.projectId ?? null,
153
+ credentials: data.credentials,
154
+ capabilities: data.capabilities as IntegrationCapability[] | undefined
155
+ });
156
+ announce(account.id);
157
+ return { account };
158
+ })
159
+
160
+ /**
161
+ * One update handler rather than four.
162
+ *
163
+ * Every field here re-projects, and splitting them into separate events
164
+ * would just be four ways to reach the same pass. Absent fields are left
165
+ * alone; an empty credential value means "not re-typed", not "clear".
166
+ */
167
+ .http('integrations:update', {
168
+ data: t.Object({
169
+ id: t.String(),
170
+ label: t.Optional(t.String({ minLength: 1, maxLength: 120 })),
171
+ credentials: t.Optional(t.Record(t.String(), t.String())),
172
+ capabilities: t.Optional(t.Array(CAPABILITY_SCHEMA)),
173
+ projectId: t.Optional(t.Union([t.String(), t.Null()])),
174
+ enabled: t.Optional(t.Boolean())
175
+ }),
176
+ response: t.Object({ account: ACCOUNT_SCHEMA })
177
+ }, async ({ data }) => {
178
+ debug.log('path', `integrations:update ${data.id}`);
179
+
180
+ if (data.label !== undefined) integrationAccounts.setLabel(data.id, data.label);
181
+ if (data.credentials) integrationAccounts.updateCredentials(data.id, data.credentials);
182
+ if (data.capabilities) integrationAccounts.setCapabilities(data.id, data.capabilities as IntegrationCapability[]);
183
+ if (data.projectId !== undefined) integrationAccounts.setProject(data.id, data.projectId);
184
+ if (data.enabled !== undefined) integrationAccounts.setEnabled(data.id, data.enabled);
185
+
186
+ const account = integrationAccounts.get(data.id);
187
+ if (!account) throw new Error('Integration account not found');
188
+ announce(account.id);
189
+ return { account };
190
+ })
191
+
192
+ .http('integrations:disconnect', {
193
+ data: t.Object({ id: t.String() }),
194
+ response: t.Object({ success: t.Boolean() })
195
+ }, async ({ data }) => {
196
+ debug.log('path', `integrations:disconnect ${data.id}`);
197
+ integrationAccounts.disconnect(data.id);
198
+ announce(data.id);
199
+ return { success: true };
200
+ })
201
+
202
+ .http('integrations:health', {
203
+ data: t.Object({ id: t.String() }),
204
+ response: t.Object({
205
+ status: STATUS_SCHEMA,
206
+ detail: t.Union([t.String(), t.Null()])
207
+ })
208
+ }, async ({ data }) => {
209
+ debug.log('path', `integrations:health ${data.id}`);
210
+ return checkAccountHealth(data.id);
211
+ })
212
+
213
+ .http('integrations:secrets-health', {
214
+ data: t.Object({}),
215
+ response: t.Object({ health: SECRETS_HEALTH_SCHEMA })
216
+ }, async () => {
217
+ debug.log('path', 'integrations:secrets-health');
218
+ return { health: getSecretsHealth() };
219
+ });