@myrialabs/clopen 0.4.46 → 0.4.48

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 (328) hide show
  1. package/README.md +11 -11
  2. package/backend/artifacts/project/sources.ts +1 -1
  3. package/backend/auth/auth-service.ts +52 -358
  4. package/backend/auth/onboarding.test.ts +2 -3
  5. package/backend/auth/permissions.test.ts +10 -20
  6. package/backend/auth/permissions.ts +4 -290
  7. package/backend/auth/rate-limiter.test.ts +8 -9
  8. package/backend/auth/rate-limiter.ts +0 -2
  9. package/backend/auth/tokens.ts +1 -8
  10. package/backend/bootstrap.ts +7 -0
  11. package/backend/chat/attachments.test.ts +88 -0
  12. package/backend/chat/attachments.ts +159 -0
  13. package/backend/chat/engine-handoff.test.ts +0 -2
  14. package/backend/chat/stream-manager.ts +62 -62
  15. package/backend/chat/turn-answer.test.ts +64 -0
  16. package/backend/chat/turn-answer.ts +125 -0
  17. package/backend/chat-apps/awaiting.test.ts +39 -0
  18. package/backend/chat-apps/awaiting.ts +49 -0
  19. package/backend/chat-apps/conversation.ts +746 -0
  20. package/backend/chat-apps/inbound.ts +324 -0
  21. package/backend/chat-apps/index.ts +309 -0
  22. package/backend/chat-apps/link-events.ts +20 -0
  23. package/backend/chat-apps/media.test.ts +62 -0
  24. package/backend/chat-apps/media.ts +208 -0
  25. package/backend/chat-apps/messages.test.ts +229 -0
  26. package/backend/chat-apps/messages.ts +365 -0
  27. package/backend/chat-apps/outbound.ts +243 -0
  28. package/backend/chat-apps/pairing.test.ts +45 -0
  29. package/backend/chat-apps/pairing.ts +74 -0
  30. package/backend/chat-apps/platforms/index.ts +20 -0
  31. package/backend/chat-apps/platforms/telegram.test.ts +35 -0
  32. package/backend/chat-apps/platforms/telegram.ts +191 -0
  33. package/backend/chat-apps/platforms/types.ts +114 -0
  34. package/backend/chat-apps/questions.ts +133 -0
  35. package/backend/chat-apps/runtime.ts +572 -0
  36. package/backend/chat-apps/storage.test.ts +201 -0
  37. package/backend/chat-apps/turns.test.ts +45 -0
  38. package/backend/chat-apps/turns.ts +208 -0
  39. package/backend/containers/pty.ts +3 -11
  40. package/backend/control/actions/accounts.ts +89 -0
  41. package/backend/control/actions/files.ts +116 -0
  42. package/backend/control/actions/models.ts +188 -0
  43. package/backend/control/actions/projects.ts +272 -0
  44. package/backend/control/actions/sessions.ts +280 -0
  45. package/backend/control/actions/skills.ts +111 -0
  46. package/backend/control/control.test.ts +169 -0
  47. package/backend/control/define.ts +20 -0
  48. package/backend/control/folders.test.ts +67 -0
  49. package/backend/control/index.ts +213 -0
  50. package/backend/control/invoke.ts +44 -0
  51. package/backend/control/links.ts +35 -0
  52. package/backend/control/paging.ts +26 -0
  53. package/backend/control/types.ts +117 -0
  54. package/backend/control/workspace.ts +127 -0
  55. package/backend/database/migrations/084_create_channel_links.ts +71 -0
  56. package/backend/database/migrations/085_add_home_projects.ts +36 -0
  57. package/backend/database/migrations/086_single_owner.test.ts +170 -0
  58. package/backend/database/migrations/086_single_owner.ts +418 -0
  59. package/backend/database/migrations/index.ts +21 -0
  60. package/backend/database/queries/auth-queries.ts +7 -85
  61. package/backend/database/queries/channel-queries.ts +270 -0
  62. package/backend/database/queries/db-client-connection-queries.ts +18 -56
  63. package/backend/database/queries/file-share-queries.ts +5 -23
  64. package/backend/database/queries/git-identity-queries.ts +31 -42
  65. package/backend/database/queries/graph-queries.ts +1 -1
  66. package/backend/database/queries/index.ts +13 -1
  67. package/backend/database/queries/message-queries.test.ts +146 -0
  68. package/backend/database/queries/message-queries.ts +42 -1
  69. package/backend/database/queries/permission-set-queries.ts +1 -1
  70. package/backend/database/queries/profile-queries.ts +1 -1
  71. package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
  72. package/backend/database/queries/project-queries.ts +50 -63
  73. package/backend/database/queries/session-queries.ts +28 -56
  74. package/backend/database/queries/ssh-connection-queries.ts +18 -41
  75. package/backend/db-client/integrations/projector.ts +0 -5
  76. package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
  77. package/backend/engine/adapters/claude/message-converter.ts +25 -2
  78. package/backend/engine/adapters/cline/message-converter.ts +0 -1
  79. package/backend/engine/adapters/cline/stream.ts +11 -15
  80. package/backend/engine/adapters/codex/message-converter.ts +0 -2
  81. package/backend/engine/adapters/copilot/message-converter.ts +1 -2
  82. package/backend/engine/adapters/cursor/message-converter.ts +0 -1
  83. package/backend/engine/adapters/opencode/message-converter.ts +2 -4
  84. package/backend/engine/adapters/opencode/presets.ts +27 -2
  85. package/backend/engine/adapters/opencode/server.ts +6 -4
  86. package/backend/engine/adapters/opencode/stream.ts +11 -0
  87. package/backend/engine/adapters/parent-scope.test.ts +38 -0
  88. package/backend/engine/adapters/parent-scope.ts +44 -0
  89. package/backend/engine/adapters/pi/message-converter.ts +0 -1
  90. package/backend/engine/adapters/pi/stream.ts +4 -5
  91. package/backend/engine/adapters/qwen/message-converter.ts +0 -2
  92. package/backend/engine/bootstrap-default-engine.ts +2 -2
  93. package/backend/engine/docs/adapter-contract.md +8 -1
  94. package/backend/engine/install-runner.ts +8 -17
  95. package/backend/files/file-shares.ts +20 -44
  96. package/backend/files/file-size-limit.ts +3 -3
  97. package/backend/files/image-processing.ts +1 -1
  98. package/backend/files/os-clipboard.ts +2 -2
  99. package/backend/git/git-executor.ts +25 -5
  100. package/backend/git/git-service.ts +420 -19
  101. package/backend/git/identity/credential-helper.test.ts +2 -7
  102. package/backend/git/identity/import-local.test.ts +11 -16
  103. package/backend/git/identity/import-local.ts +12 -12
  104. package/backend/git/identity/index.ts +10 -24
  105. package/backend/git/identity/resolve.ts +13 -14
  106. package/backend/git/identity/scope-config.ts +33 -28
  107. package/backend/git/identity/service.ts +44 -47
  108. package/backend/git/op-lock.test.ts +111 -0
  109. package/backend/git/op-lock.ts +180 -0
  110. package/backend/git/remote-sync.test.ts +249 -0
  111. package/backend/host/metrics.ts +1 -1
  112. package/backend/http/bearer-auth.ts +1 -2
  113. package/backend/http/files-download.test.ts +8 -9
  114. package/backend/http/files-download.ts +2 -2
  115. package/backend/http/files-shared.test.ts +62 -89
  116. package/backend/http/files-shared.ts +2 -2
  117. package/backend/http/files-upload.test.ts +3 -7
  118. package/backend/http/files-upload.ts +3 -3
  119. package/backend/http/notes-images.test.ts +15 -38
  120. package/backend/http/notes-images.ts +6 -8
  121. package/backend/http/ssh-sftp.ts +5 -10
  122. package/backend/index.ts +21 -7
  123. package/backend/integrations/accounts.ts +61 -3
  124. package/backend/integrations/index.ts +2 -2
  125. package/backend/integrations/registry/define.ts +15 -0
  126. package/backend/integrations/registry/index.ts +2 -0
  127. package/backend/integrations/registry/providers/telegram.ts +54 -0
  128. package/backend/integrations/registry/types.ts +21 -1
  129. package/backend/integrations/webhooks/gateway.ts +7 -6
  130. package/backend/integrations/webhooks/verify.test.ts +30 -0
  131. package/backend/integrations/webhooks/verify.ts +4 -0
  132. package/backend/mcp/external/project.ts +1 -1
  133. package/backend/mcp/internal/remote-server.test.ts +1 -3
  134. package/backend/mcp/internal/remote-server.ts +4 -4
  135. package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
  136. package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
  137. package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
  138. package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
  139. package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
  140. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
  141. package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
  142. package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
  143. package/backend/memory/redact.ts +1 -1
  144. package/backend/notes/access.test.ts +28 -29
  145. package/backend/notes/access.ts +6 -11
  146. package/backend/permissions/service.ts +1 -1
  147. package/backend/preview/browser/browser-clipboard.test.ts +46 -0
  148. package/backend/preview/browser/browser-clipboard.ts +67 -0
  149. package/backend/preview/browser/browser-dialog-handler.ts +95 -6
  150. package/backend/preview/browser/browser-host-bridge.ts +9 -0
  151. package/backend/preview/browser/browser-interaction-handler.ts +316 -86
  152. package/backend/preview/browser/browser-mcp-control.ts +34 -0
  153. package/backend/preview/browser/browser-pool.ts +67 -6
  154. package/backend/preview/browser/browser-preview-service.ts +361 -25
  155. package/backend/preview/browser/browser-tab-manager.ts +66 -23
  156. package/backend/preview/browser/browser-video-capture.ts +92 -5
  157. package/backend/preview/browser/element-locator.ts +190 -17
  158. package/backend/preview/browser/keyboard-chords.test.ts +68 -0
  159. package/backend/preview/browser/keyboard-chords.ts +132 -0
  160. package/backend/preview/browser/paste.ts +81 -0
  161. package/backend/preview/browser/process-usage.ts +142 -0
  162. package/backend/preview/browser/profile-lock.ts +209 -0
  163. package/backend/preview/browser/scripts/host-bridge.ts +59 -0
  164. package/backend/preview/browser/scripts/video-stream.ts +58 -0
  165. package/backend/preview/browser/types.ts +40 -2
  166. package/backend/preview/browser/viewport.test.ts +45 -0
  167. package/backend/preview/browser/viewport.ts +96 -0
  168. package/backend/profiles/service.ts +2 -2
  169. package/backend/project/status-manager.ts +43 -172
  170. package/backend/projects/home.ts +61 -0
  171. package/backend/projects/project-cleanup.integration.test.ts +2 -2
  172. package/backend/projects/project-cleanup.ts +0 -8
  173. package/backend/skills/service.ts +2 -3
  174. package/backend/snapshot/helpers.ts +0 -1
  175. package/backend/snapshot/restore.ts +252 -0
  176. package/backend/ssh/ptykit.ts +1 -2
  177. package/backend/terminal/ptykit.ts +5 -8
  178. package/backend/tunnel/public-origin.ts +31 -20
  179. package/backend/utils/user-helpers.ts +0 -55
  180. package/backend/utils/ws.ts +61 -154
  181. package/backend/worktrees/branching/engine.ts +3 -16
  182. package/backend/worktrees/branching/index.ts +1 -1
  183. package/backend/worktrees/branching/projector.ts +1 -1
  184. package/backend/worktrees/branching/service.ts +13 -25
  185. package/backend/ws/access.ts +12 -21
  186. package/backend/ws/artifacts/generate.ts +2 -2
  187. package/backend/ws/auth/device.ts +16 -71
  188. package/backend/ws/auth/index.ts +4 -22
  189. package/backend/ws/auth/login.test.ts +14 -60
  190. package/backend/ws/auth/login.ts +24 -124
  191. package/backend/ws/auth/status.ts +0 -1
  192. package/backend/ws/chat/composer.ts +118 -118
  193. package/backend/ws/chat/stream.ts +64 -47
  194. package/backend/ws/chat-apps/index.ts +117 -0
  195. package/backend/ws/containers/actions.ts +11 -25
  196. package/backend/ws/containers/index.ts +3 -4
  197. package/backend/ws/containers/list.ts +10 -36
  198. package/backend/ws/containers/logs.ts +2 -2
  199. package/backend/ws/containers/tunnel.ts +1 -2
  200. package/backend/ws/db-client/access.ts +2 -16
  201. package/backend/ws/db-client/accounts.ts +5 -15
  202. package/backend/ws/db-client/connections.ts +17 -25
  203. package/backend/ws/db-client/context.ts +1 -1
  204. package/backend/ws/db-client/env.ts +7 -10
  205. package/backend/ws/db-client/index.ts +2 -2
  206. package/backend/ws/db-client/io.ts +5 -5
  207. package/backend/ws/db-client/query-history-retention.test.ts +8 -8
  208. package/backend/ws/db-client/query.ts +18 -17
  209. package/backend/ws/db-client/schema.ts +13 -13
  210. package/backend/ws/db-client/structure.ts +35 -35
  211. package/backend/ws/db-client/supabase.ts +4 -21
  212. package/backend/ws/deployments/context.ts +1 -1
  213. package/backend/ws/deployments/crud.ts +0 -5
  214. package/backend/ws/engine/access.ts +7 -20
  215. package/backend/ws/engine/claude/accounts.ts +4 -4
  216. package/backend/ws/engine/cline/accounts.ts +5 -5
  217. package/backend/ws/engine/codex/accounts.ts +3 -3
  218. package/backend/ws/engine/opencode/providers.ts +2 -1
  219. package/backend/ws/engine/pi/accounts.ts +5 -5
  220. package/backend/ws/files/clipboard.ts +8 -27
  221. package/backend/ws/files/image-edit.ts +6 -6
  222. package/backend/ws/files/index.ts +1 -1
  223. package/backend/ws/files/path-access.test.ts +32 -131
  224. package/backend/ws/files/path-access.ts +8 -87
  225. package/backend/ws/files/read.ts +15 -19
  226. package/backend/ws/files/reveal.ts +3 -3
  227. package/backend/ws/files/search.ts +7 -7
  228. package/backend/ws/files/share.ts +9 -13
  229. package/backend/ws/files/state.ts +9 -12
  230. package/backend/ws/files/watch.ts +3 -3
  231. package/backend/ws/files/write.ts +30 -31
  232. package/backend/ws/git/branch.ts +80 -59
  233. package/backend/ws/git/commit.ts +63 -44
  234. package/backend/ws/git/conflict.ts +16 -18
  235. package/backend/ws/git/identity-context.ts +8 -17
  236. package/backend/ws/git/identity.ts +17 -27
  237. package/backend/ws/git/index.ts +3 -1
  238. package/backend/ws/git/op-state.ts +139 -0
  239. package/backend/ws/git/remote.ts +241 -141
  240. package/backend/ws/git/repo-context.ts +67 -0
  241. package/backend/ws/git/staging.ts +18 -28
  242. package/backend/ws/git/status.ts +5 -2
  243. package/backend/ws/index.ts +5 -1
  244. package/backend/ws/instructions/crud.ts +1 -1
  245. package/backend/ws/integrations/crud.ts +1 -3
  246. package/backend/ws/mcp/crud.ts +3 -5
  247. package/backend/ws/mcp/tools.ts +1 -1
  248. package/backend/ws/memory/crud.ts +14 -46
  249. package/backend/ws/memory/index.ts +2 -2
  250. package/backend/ws/messages/crud.ts +29 -8
  251. package/backend/ws/notes/index.ts +33 -39
  252. package/backend/ws/permissions/crud.ts +3 -4
  253. package/backend/ws/ports/index.ts +1 -2
  254. package/backend/ws/ports/kill.ts +5 -10
  255. package/backend/ws/ports/list.ts +4 -10
  256. package/backend/ws/preview/access.ts +1 -1
  257. package/backend/ws/preview/browser/interact.ts +52 -79
  258. package/backend/ws/preview/browser/native-ui.ts +24 -0
  259. package/backend/ws/preview/browser/stats.ts +98 -1
  260. package/backend/ws/preview/browser/tab-info.ts +15 -0
  261. package/backend/ws/preview/browser/tab.ts +19 -4
  262. package/backend/ws/preview/index.ts +27 -0
  263. package/backend/ws/profiles/crud.ts +6 -8
  264. package/backend/ws/project-artifacts/index.ts +30 -31
  265. package/backend/ws/projects/crud.ts +33 -35
  266. package/backend/ws/projects/index.ts +3 -8
  267. package/backend/ws/projects/info.ts +3 -3
  268. package/backend/ws/projects/overview.ts +19 -30
  269. package/backend/ws/projects/status.ts +17 -57
  270. package/backend/ws/sessions/crud.ts +34 -45
  271. package/backend/ws/sessions/index.ts +1 -1
  272. package/backend/ws/settings/crud.ts +1 -1
  273. package/backend/ws/skills/crud.ts +3 -4
  274. package/backend/ws/skills/index.ts +1 -1
  275. package/backend/ws/snapshot/changes.ts +7 -7
  276. package/backend/ws/snapshot/restore.ts +11 -295
  277. package/backend/ws/snapshot/timeline.ts +2 -4
  278. package/backend/ws/ssh/access.ts +6 -21
  279. package/backend/ws/ssh/connections.ts +21 -31
  280. package/backend/ws/ssh/forwards.ts +12 -12
  281. package/backend/ws/ssh/sftp.ts +34 -34
  282. package/backend/ws/ssh/tunnel.ts +1 -2
  283. package/backend/ws/stack/install.ts +7 -17
  284. package/backend/ws/subagents/crud.ts +1 -1
  285. package/backend/ws/tunnel/share.ts +0 -2
  286. package/backend/ws/user/crud.ts +1 -59
  287. package/backend/ws/user/index.ts +1 -1
  288. package/backend/ws/work/context.ts +1 -1
  289. package/backend/ws/work/crud.ts +0 -5
  290. package/backend/ws/workspace/state.ts +10 -13
  291. package/backend/ws/worktrees/branching.ts +7 -36
  292. package/backend/ws/worktrees/crud.ts +2 -2
  293. package/bin/clopen.ts +10 -11
  294. package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
  295. package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
  296. package/dist/assets/main-BUiUL3eZ.css +1 -0
  297. package/dist/assets/main-nBOb9YOA.js +1240 -0
  298. package/dist/index.html +2 -2
  299. package/package.json +2 -1
  300. package/shared/constants/attachments.ts +14 -0
  301. package/shared/constants/engine-tools.ts +1 -1
  302. package/shared/constants/preview.test.ts +259 -0
  303. package/shared/constants/preview.ts +1018 -57
  304. package/shared/constants/tool-icons.ts +5 -0
  305. package/shared/types/containers/container.ts +1 -1
  306. package/shared/types/database/schema.ts +9 -6
  307. package/shared/types/git-identity.ts +1 -1
  308. package/shared/types/git.ts +116 -0
  309. package/shared/types/integrations.ts +7 -0
  310. package/shared/types/stores/settings.ts +1 -1
  311. package/shared/types/unified/index.ts +1 -1
  312. package/shared/types/unified/message.ts +0 -7
  313. package/shared/types/unified/stream.ts +2 -4
  314. package/shared/types/unified/tool.ts +15 -1
  315. package/shared/utils/ask-user-question.test.ts +319 -0
  316. package/shared/utils/ask-user-question.ts +154 -0
  317. package/shared/utils/home-project.ts +25 -0
  318. package/shared/utils/logger.ts +2 -0
  319. package/shared/utils/ws-server.ts +32 -7
  320. package/backend/auth/session-invalidation.test.ts +0 -112
  321. package/backend/auth/session-invalidation.ts +0 -77
  322. package/backend/project/status-manager.test.ts +0 -32
  323. package/backend/ws/auth/invites.ts +0 -94
  324. package/backend/ws/auth/users.ts +0 -112
  325. package/backend/ws/projects/presence.ts +0 -46
  326. package/backend/ws/stack/access.ts +0 -31
  327. package/dist/assets/main-BiDNMWb3.css +0 -1
  328. package/dist/assets/main-BlhKWz2B.js +0 -1241
@@ -0,0 +1,38 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import type { EngineOutput } from '$shared/types/unified';
3
+ import { scopeToParentTool } from './parent-scope';
4
+
5
+ const engine = { type: 'claude-code', provider: 'anthropic', model: { id: '', name: '' }, account: { id: 0, name: '' } } as const;
6
+ const base = { createdAt: '', messageId: 'm', sessionId: 's', engine, parent: { messageId: null, sessionId: null, toolUseId: null } };
7
+
8
+ describe('scopeToParentTool', () => {
9
+ test('tags every persisted message kind with the parent tool', () => {
10
+ const messages: EngineOutput[] = [
11
+ { ...base, type: 'reasoning', text: 'thinking' },
12
+ { ...base, type: 'assistant', content: [{ type: 'text', text: 'hi' }], stopReason: null, usage: null },
13
+ { ...base, type: 'user', content: [{ type: 'text', text: 'hi' }], synthetic: true },
14
+ { ...base, type: 'compact_boundary', trigger: 'auto', preTokens: 0 },
15
+ ];
16
+ for (const message of messages) {
17
+ expect(scopeToParentTool(message, 'agent-1')).toMatchObject({ type: message.type, parent: { toolUseId: 'agent-1' } });
18
+ }
19
+ });
20
+
21
+ test('keeps the closer parent of a nested sub-agent and does not mutate', () => {
22
+ const nested: EngineOutput = { ...base, type: 'reasoning', text: 't', parent: { ...base.parent, toolUseId: 'inner' } };
23
+ expect(scopeToParentTool(nested, 'outer')).toBe(nested);
24
+
25
+ const root: EngineOutput = { ...base, type: 'reasoning', text: 't' };
26
+ scopeToParentTool(root, 'agent-1');
27
+ expect(root.parent.toolUseId).toBeNull();
28
+ });
29
+
30
+ test('drops turn-level output a child must never drive', () => {
31
+ const transient: EngineOutput[] = [
32
+ { type: 'stream_event', event: 'delta', sessionId: 's', text: 'x', reasoning: true },
33
+ { type: 'stream_event', event: 'start', sessionId: 's', reasoning: false },
34
+ { type: 'result', subtype: 'success', sessionId: 's', numTurns: 1, totalCostUsd: 0, usage: { inputTokens: 0, outputTokens: 0, cacheCreationInputTokens: 0, cacheReadInputTokens: 0 }, stopReason: null },
35
+ ];
36
+ for (const output of transient) expect(scopeToParentTool(output, 'agent-1')).toBeNull();
37
+ });
38
+ });
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Scoping a sub-agent's output to the parent tool call that spawned it.
3
+ *
4
+ * Every engine that runs sub-agents (`Agent` / `Workflow`) has to make the same
5
+ * decision for each output the child produces: does it belong to the parent
6
+ * tool block, or to the main turn? Answering that per message constructor is
7
+ * how sub-agent thinking leaked into the main chat — the Claude converter set
8
+ * `parent.toolUseId` on assistant and user messages but hard-coded `null` on
9
+ * reasoning, and forwarded the child's live `stream_event` deltas into the
10
+ * root typing placeholder. A new output kind would leak the same way.
11
+ *
12
+ * So the decision lives here, once, keyed on the output's TYPE rather than on
13
+ * which constructor made it: whatever the child emits either joins the parent
14
+ * tool or is dropped. Nothing a child produces can reach the root.
15
+ */
16
+
17
+ import type { EngineOutput } from '$shared/types/unified';
18
+
19
+ /**
20
+ * Scope one sub-agent output to `parentToolUseId`.
21
+ *
22
+ * - Persisted messages (`user`, `assistant`, `reasoning`, `compact_boundary`)
23
+ * are returned tagged with the parent tool id, so the frontend folds them
24
+ * into that tool's `subActivities`. A message already tagged by a deeper
25
+ * sub-agent keeps its own (closer) parent.
26
+ * - Everything else is turn-level — live typing deltas, results, init, rate
27
+ * limits, notifications. A child's copy of any of these would drive the MAIN
28
+ * turn's placeholder or lifecycle, and the stream protocol cannot carry a
29
+ * parent for them (adapter-contract §2.3, parent-tool rule 4), so they are dropped.
30
+ *
31
+ * Returns `null` for dropped outputs. Never mutates the input.
32
+ */
33
+ export function scopeToParentTool(output: EngineOutput, parentToolUseId: string): EngineOutput | null {
34
+ switch (output.type) {
35
+ case 'user':
36
+ case 'assistant':
37
+ case 'reasoning':
38
+ case 'compact_boundary':
39
+ if (output.parent.toolUseId) return output;
40
+ return { ...output, parent: { ...output.parent, toolUseId: parentToolUseId } };
41
+ default:
42
+ return null;
43
+ }
44
+ }
@@ -327,7 +327,6 @@ export function createPiMessageConverter(options: PiConverterOptions): PiMessage
327
327
  sessionId,
328
328
  parent: { messageId: null, sessionId: null, toolUseId: null },
329
329
  engine,
330
- sender: { id: '', name: '' },
331
330
  content: [{ type: 'tool_result', toolUseId: toolCallId, content: text, isError }],
332
331
  synthetic: true,
333
332
  };
@@ -44,6 +44,7 @@ import { artifactFilter } from '$backend/profiles';
44
44
  import { resolvePermissionsFromDb, isToolAllowed } from '$backend/permissions';
45
45
  import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
46
46
  import { EngineRuns } from '../run-registry';
47
+ import { scopeToParentTool } from '../parent-scope';
47
48
  import { DbCredentialStore, canonicalPiProviderId, getPiAccountForProvider, parsePiCredential } from './credential';
48
49
  import { createPiRuntime } from './presets';
49
50
  import { getPiAgentDir } from './environment';
@@ -264,11 +265,9 @@ export class PiEngine implements AIEngine {
264
265
  });
265
266
  let text = '';
266
267
  const unsub = sub.subscribe((ev) => {
267
- for (const out of subConverter.convert(ev)) {
268
- if (out.type === 'stream_event' || out.type === 'result' || out.type === 'system_init' || out.type === 'notification') continue;
269
- if (out.type === 'assistant' || out.type === 'user' || out.type === 'reasoning') {
270
- out.parent = { messageId: null, sessionId: null, toolUseId: toolCallId };
271
- }
268
+ for (const raw of subConverter.convert(ev)) {
269
+ const out = scopeToParentTool(raw, toolCallId);
270
+ if (!out) continue;
272
271
  if (out.type === 'assistant') {
273
272
  const t = out.content.filter((b) => b.type === 'text').map((b) => (b.type === 'text' ? b.text : '')).join('');
274
273
  if (t.trim()) text = t;
@@ -724,7 +724,6 @@ export function convertUserMessage(msg: SDKUserMessage, state: QwenConverterStat
724
724
  // (README §10.5). Sub-agent messages are an explicit exception.
725
725
  parent: { messageId: null, sessionId: null, toolUseId: msg.parent_tool_use_id || null },
726
726
  engine: buildEngine(state.modelId),
727
- sender: { id: '', name: '' },
728
727
  content: outBlocks,
729
728
  synthetic: true,
730
729
  };
@@ -748,7 +747,6 @@ function buildSyntheticToolResult(
748
747
  sessionId: sessionId ?? '',
749
748
  parent: { messageId: null, sessionId: null, toolUseId: null },
750
749
  engine: buildEngine(state.modelId),
751
- sender: { id: '', name: '' },
752
750
  content: [result],
753
751
  synthetic: true,
754
752
  };
@@ -28,7 +28,7 @@ import { debug } from '$shared/utils/logger';
28
28
  import { isEngineSdkInstalled } from './sdk-loader';
29
29
  import { ENGINE_PACKAGES } from './install-recipes';
30
30
  import { getRequiredEngineCliSpec, resolveEngineCli } from './engine-cli';
31
- import { awaitInstall, InstallAlreadyRunningError, startInstall, SYSTEM_INSTALL_USER } from './install-runner';
31
+ import { awaitInstall, InstallAlreadyRunningError, startInstall } from './install-runner';
32
32
 
33
33
  const DEFAULT_ENGINE = 'opencode' as const;
34
34
 
@@ -95,7 +95,7 @@ async function runDefaultEngineInstall(): Promise<void> {
95
95
  );
96
96
 
97
97
  try {
98
- const session = await startInstall(DEFAULT_ENGINE, SYSTEM_INSTALL_USER);
98
+ const session = await startInstall(DEFAULT_ENGINE);
99
99
  // Callers chain work that needs a usable engine (memory picks its
100
100
  // extraction model from the engine's catalog), so wait for the run to
101
101
  // settle rather than returning as soon as it is spawned.
@@ -148,11 +148,18 @@ The following invariants are mandatory:
148
148
  1. Emit the parent tool message before any child activity.
149
149
  2. Set every child message's `parent.toolUseId` to the parent tool call id
150
150
  before yielding it. Never emit a root-shaped child and patch it later.
151
+ This covers **every** message kind — `reasoning` included. Route child
152
+ output through `scopeToParentTool()` (`adapters/parent-scope.ts`) instead of
153
+ tagging per constructor: it scopes by output type, so a kind you forgot
154
+ cannot reach the root. A sub-agent's thinking once leaked into the main chat
155
+ because one converter tagged `assistant`/`user` but hard-coded `null` on
156
+ `reasoning`.
151
157
  3. Keep top-level tool results at `parent.toolUseId = null`; the id of the tool
152
158
  they answer belongs on the inner `tool_result.toolUseId`.
153
159
  4. Do not forward nested text/reasoning `stream_event` deltas unless the
154
160
  protocol can carry their parent id. Suppress them and emit the finalized
155
- parent-tagged message instead.
161
+ parent-tagged message instead. `scopeToParentTool()` drops them (and every
162
+ other turn-level output: result, init, rate limit, notification).
156
163
  5. When activity comes from a side channel, merge it with the SDK stream using
157
164
  a push queue. Use the source's native notification mechanism (for example
158
165
  filesystem change events for JSONL transcripts), not interval polling.
@@ -60,7 +60,6 @@ interface Session {
60
60
  endedAt: number | null;
61
61
  buffer: RingBuffer;
62
62
  retentionTimer: ReturnType<typeof setTimeout> | null;
63
- startedBy: string;
64
63
  /** Current partial line per stream (for line-based chunking). */
65
64
  pending: { stdout: string; stderr: string };
66
65
  }
@@ -114,7 +113,7 @@ function emitStream(session: Session, stream: 'stdout' | 'stderr', chunk: string
114
113
  session.pending[stream] = parts.pop() ?? '';
115
114
  for (const line of parts) {
116
115
  pushLine(session.buffer, line);
117
- ws.emit.user(session.startedBy, 'stack:install-stream', {
116
+ ws.emit.signedIn('stack:install-stream', {
118
117
  sessionId: session.id,
119
118
  tool: session.tool,
120
119
  type: stream,
@@ -128,7 +127,7 @@ function flushPending(session: Session): void {
128
127
  const remaining = session.pending[stream];
129
128
  if (remaining) {
130
129
  pushLine(session.buffer, remaining);
131
- ws.emit.user(session.startedBy, 'stack:install-stream', {
130
+ ws.emit.signedIn('stack:install-stream', {
132
131
  sessionId: session.id,
133
132
  tool: session.tool,
134
133
  type: stream,
@@ -192,7 +191,7 @@ function finalizeSession(session: Session, preferredStatus: SessionStatus, exitC
192
191
 
193
192
  debug.log('path', `[install:${session.id}] Finished status=${session.status} exit=${exitCode}`);
194
193
 
195
- ws.emit.user(session.startedBy, 'stack:install-finished', {
194
+ ws.emit.signedIn('stack:install-finished', {
196
195
  sessionId: session.id,
197
196
  tool: session.tool,
198
197
  status: session.status,
@@ -363,14 +362,11 @@ async function removeStackDependencies(session: Session, cwd: string, env: Recor
363
362
  }
364
363
 
365
364
  /**
366
- * Owner id for installs clopen starts itself (startup repair), rather than a
367
- * user clicking Install. Sessions carry an owner so one admin cannot drive
368
- * another's install; system-owned sessions are readable by any admin instead
369
- * (see `requireInstallSessionAccess`) so the repair is visible and cancellable.
365
+ * Start installing `tool`. Progress streams to every signed-in device, so an
366
+ * install clopen starts itself (startup repair) is as visible and cancellable
367
+ * as one started from Settings → Stack.
370
368
  */
371
- export const SYSTEM_INSTALL_USER = 'system';
372
-
373
- export async function startInstall(tool: ToolId, userId: string): Promise<Session> {
369
+ export async function startInstall(tool: ToolId): Promise<Session> {
374
370
  await refreshProcessPath();
375
371
 
376
372
  const existing = activeByTool.get(tool);
@@ -400,7 +396,6 @@ export async function startInstall(tool: ToolId, userId: string): Promise<Sessio
400
396
  endedAt: null,
401
397
  buffer: newRingBuffer(),
402
398
  retentionTimer: null,
403
- startedBy: userId,
404
399
  pending: { stdout: '', stderr: '' }
405
400
  };
406
401
 
@@ -412,7 +407,7 @@ export async function startInstall(tool: ToolId, userId: string): Promise<Sessio
412
407
  emitStream(session, 'stdout', banner + '\n');
413
408
 
414
409
  // Broadcast the session-started event so clients that subscribe mid-run can attach.
415
- ws.emit.user(userId, 'stack:install-started', {
410
+ ws.emit.signedIn('stack:install-started', {
416
411
  sessionId: id,
417
412
  tool,
418
413
  displayCommand: recipe.displayCommand ?? '',
@@ -458,10 +453,6 @@ export function getSession(sessionId: string) {
458
453
  return session ? sessionSnapshot(session) : null;
459
454
  }
460
455
 
461
- export function getSessionOwner(sessionId: string): string | null {
462
- return sessions.get(sessionId)?.startedBy ?? null;
463
- }
464
-
465
456
  export function getActiveSessionForTool(tool: ToolId) {
466
457
  const id = activeByTool.get(tool);
467
458
  if (!id) return null;
@@ -12,17 +12,15 @@
12
12
  * - a short deadline (default {@link DEFAULT_FILE_SHARE_TTL_MINUTES} minutes),
13
13
  * a longer one, or none at all — a link only a revoke can end.
14
14
  *
15
- * Security model (mirrors the invite/device-code flows):
15
+ * Security model (mirrors the device-code flow):
16
16
  * - Only the raw token's SHA-256 hash is kept; the raw token is returned once,
17
17
  * at creation time, and is embedded in the shared URL.
18
18
  * - Tokens live in SQLite (`file_shares`, migration 080) like device codes, so
19
19
  * a restart does not silently kill links a user already handed out.
20
- * - Creation reuses the exact project-scoped path check the download route
21
- * uses (`requireFilePathAccessFor`), so a user can only share files they
22
- * could download themselves. Directories are rejected.
23
- * - That same check is re-run on every open: if the creator loses access to
24
- * the path (removed from the project, project deleted, account deleted),
25
- * every link they minted for it stops serving immediately.
20
+ * - Creation resolves the path the same way the download route does
21
+ * (`resolveFilePath`). Directories are rejected.
22
+ * - Every open re-checks that the account which minted the link still exists
23
+ * and the path still resolves; a reset install leaves no working link.
26
24
  * - Links are single-file bound: the HTTP route resolves the path from the
27
25
  * token and ignores any caller-supplied path, so a link can never be
28
26
  * retargeted at another file.
@@ -41,7 +39,7 @@ import { authQueries, fileShareQueries } from '../database/queries';
41
39
  import { projectQueries } from '../database/queries/project-queries';
42
40
  import { worktreeQueries } from '../database/queries/worktree-queries';
43
41
  import { generateFileShareToken, hashToken } from '../auth/tokens';
44
- import { requireFilePathAccessFor } from '../ws/files/path-access';
42
+ import { resolveFilePath } from '../ws/files/path-access';
45
43
 
46
44
  /**
47
45
  * Default lifetime of a new link, in minutes.
@@ -111,16 +109,16 @@ export function consumerFingerprint(ip?: string | null, userAgent?: string | nul
111
109
  }
112
110
 
113
111
  /**
114
- * Re-run the creator's project-scoped access check against the shared path.
115
- * A link is only ever as alive as the access that minted it.
112
+ * A link is only ever as alive as the account that minted it: a reset install
113
+ * (or a removed account) must not leave a working download behind.
116
114
  */
117
- async function assertCreatorStillHasAccess(filePath: string, createdBy: string): Promise<void> {
115
+ async function assertCreatorStillExists(filePath: string, createdBy: string): Promise<void> {
118
116
  const user = authQueries.getUserById(createdBy);
119
117
  if (!user) {
120
118
  throw new FileShareGoneError();
121
119
  }
122
120
  try {
123
- await requireFilePathAccessFor(filePath, user.role, user.id);
121
+ await resolveFilePath(filePath);
124
122
  } catch {
125
123
  throw new FileShareGoneError();
126
124
  }
@@ -175,19 +173,17 @@ export function describeShareLocation(filePath: string): FileShareLocation {
175
173
 
176
174
  /**
177
175
  * Mint a share token for a single file. The caller must already be
178
- * authenticated over the WebSocket; access is enforced with the same
179
- * project-scoped policy as the download route.
176
+ * authenticated over the WebSocket.
180
177
  */
181
178
  export async function createFileShareLink(
182
179
  requestedPath: string,
183
- role: string | null,
184
180
  userId: string | null,
185
181
  options: FileShareOptions = {}
186
182
  ): Promise<{ shareId: string; shareToken: string; oneTime: boolean; expiresAt: string | null }> {
187
183
  if (!userId) {
188
184
  throw new Error('Access denied');
189
185
  }
190
- const resolvedPath = await requireFilePathAccessFor(requestedPath, role, userId);
186
+ const resolvedPath = await resolveFilePath(requestedPath);
191
187
 
192
188
  const stats = await stat(resolvedPath).catch(() => null);
193
189
  if (!stats) {
@@ -255,7 +251,7 @@ export async function peekFileShare(shareToken: string, fingerprint: string): Pr
255
251
  }
256
252
  }
257
253
 
258
- await assertCreatorStillHasAccess(row.file_path, row.created_by);
254
+ await assertCreatorStillExists(row.file_path, row.created_by);
259
255
 
260
256
  return {
261
257
  filePath: row.file_path,
@@ -285,22 +281,13 @@ export function recordFileShareOpen(shareToken: string): void {
285
281
  }
286
282
 
287
283
  /**
288
- * Revoke a share by its row id. The creator or an admin may revoke; returns
289
- * false when the id is unknown (already used up, lapsed, or revoked).
284
+ * Revoke a share by its row id. Returns false when the id is unknown (already
285
+ * used up, lapsed, or revoked).
290
286
  *
291
287
  * Revoking a link that is inside its continuation window also ends that
292
288
  * window, so a stream in progress stops on the next range request.
293
289
  */
294
- export function revokeFileShareLink(
295
- shareId: string,
296
- role: string | null,
297
- userId: string | null
298
- ): boolean {
299
- const row = fileShareQueries.getById(shareId);
300
- if (!row) return false;
301
- if (role !== 'admin' && row.created_by !== userId) {
302
- throw new Error('Access denied');
303
- }
290
+ export function revokeFileShareLink(shareId: string): boolean {
304
291
  return fileShareQueries.deleteById(shareId) > 0;
305
292
  }
306
293
 
@@ -314,8 +301,6 @@ export interface FileShareSummary {
314
301
  worktreeName: string | null;
315
302
  /** Path within the project/worktree, `/`-separated on every platform. */
316
303
  relativePath: string;
317
- createdBy: string;
318
- createdByName: string | null;
319
304
  createdAt: string;
320
305
  oneTime: boolean;
321
306
  /** ISO deadline, or null for "until revoked". */
@@ -328,18 +313,11 @@ export interface FileShareSummary {
328
313
  }
329
314
 
330
315
  /**
331
- * List live share links: an admin sees every user's, everyone else sees their
332
- * own. Lapsed rows are filtered by the query, so the list answers "what is
333
- * reachable right now" rather than "what was ever created".
316
+ * List live share links. Lapsed rows are filtered by the query, so the list
317
+ * answers "what is reachable right now" rather than "what was ever created".
334
318
  */
335
- export function listFileShares(role: string | null, userId: string | null): FileShareSummary[] {
336
- if (!userId) {
337
- throw new Error('Access denied');
338
- }
339
- const now = new Date().toISOString();
340
- const rows = role === 'admin'
341
- ? fileShareQueries.listAll(now)
342
- : fileShareQueries.listForUser(userId, now);
319
+ export function listFileShares(): FileShareSummary[] {
320
+ const rows = fileShareQueries.listLive(new Date().toISOString());
343
321
 
344
322
  return rows.map((row) => {
345
323
  const location = describeShareLocation(row.file_path);
@@ -350,8 +328,6 @@ export function listFileShares(role: string | null, userId: string | null): File
350
328
  projectName: location.projectName,
351
329
  worktreeName: location.worktreeName,
352
330
  relativePath: location.relativePath,
353
- createdBy: row.created_by,
354
- createdByName: row.created_by_name,
355
331
  createdAt: row.created_at,
356
332
  oneTime: row.one_time === 1,
357
333
  expiresAt: row.expires_at,
@@ -3,20 +3,20 @@
3
3
  *
4
4
  * Enforces a configurable maximum file size on write, upload, zip, and
5
5
  * extract operations to prevent disk exhaustion attacks (DoS). The limit
6
- * is sourced from the `system:settings.maxFileSizeMB` admin setting and
6
+ * is sourced from the `system:settings.maxFileSizeMB` system setting and
7
7
  * defaults to 500MB when the setting is missing or invalid.
8
8
  */
9
9
 
10
10
  import { readSystemSetting } from '../settings/system-settings';
11
11
 
12
- /** Default maximum file size in megabytes when no admin setting is present. */
12
+ /** Default maximum file size in megabytes when no setting is present. */
13
13
  export const DEFAULT_MAX_FILE_SIZE_MB = 500;
14
14
 
15
15
  /**
16
16
  * Read the current maximum file size (bytes) from system settings.
17
17
  * Falls back to the default if the row is missing, malformed, or holds a
18
18
  * non-positive value — keeps callers resilient even if the DB is empty
19
- * (e.g. on first boot before the admin writes any system setting).
19
+ * (e.g. on first boot before any system setting is written).
20
20
  */
21
21
  export function getMaxFileSize(): number {
22
22
  const limitMB = readSystemSetting((settings) => {
@@ -348,7 +348,7 @@ export async function processImageEdit(
348
348
 
349
349
  const { data, info } = await encodeToBuffer(pipeline, recipe.output, fast);
350
350
 
351
- // Guard against producing an output larger than the admin file-size limit.
351
+ // Guard against producing an output larger than the configured file-size limit.
352
352
  validateFileSize(data.length);
353
353
 
354
354
  return {
@@ -24,8 +24,8 @@ import { debug } from '$shared/utils/logger';
24
24
  * Ctrl+V/⌘V keeps using the `paste` event fast path in the frontend.
25
25
  *
26
26
  * Both directions are HOST-MACHINE operations: they read and write the
27
- * clipboard of the machine the server runs on, not the viewer's. The WS
28
- * routes therefore restrict them to admins (see `backend/ws/files/clipboard.ts`).
27
+ * clipboard of the machine the server runs on, not the viewer's (see
28
+ * `backend/ws/files/clipboard.ts`).
29
29
  */
30
30
 
31
31
  export const OS_CLIPBOARD_ENV_VAR = 'CLOPEN_OS_CLIP_PATHS_B64';
@@ -16,6 +16,9 @@ import { resolveBinary } from '../utils/cli';
16
16
  */
17
17
  export type GitIdentityEnv = Record<string, string>;
18
18
 
19
+ /** How long a timed-out git gets to exit on SIGTERM before it is killed outright. */
20
+ const KILL_GRACE_MS = 5000;
21
+
19
22
  export interface GitExecResult {
20
23
  stdout: string;
21
24
  stderr: string;
@@ -108,9 +111,15 @@ export async function execGit(
108
111
  }
109
112
  });
110
113
 
111
- // Timeout handling
114
+ // Timeout handling. SIGTERM first: git traps it and deletes the lockfile it
115
+ // holds, where SIGKILL would strand `.git/index.lock` and break every later
116
+ // command until someone removes it by hand. SIGKILL only if git ignores it.
117
+ let timedOut = false;
118
+ let killTimer: ReturnType<typeof setTimeout> | null = null;
112
119
  const timeoutId = setTimeout(() => {
113
- proc.kill();
120
+ timedOut = true;
121
+ proc.kill('SIGTERM');
122
+ killTimer = setTimeout(() => proc.kill('SIGKILL'), KILL_GRACE_MS);
114
123
  }, timeout);
115
124
 
116
125
  try {
@@ -123,14 +132,25 @@ export async function execGit(
123
132
 
124
133
  const exitCode = await proc.exited;
125
134
  clearTimeout(timeoutId);
135
+ if (killTimer) clearTimeout(killTimer);
136
+
137
+ // A killed git usually prints nothing, which surfaced as an error dialog
138
+ // with an empty message.
139
+ const finalStderr = timedOut
140
+ ? `${stderr.trim() ? `${stderr.trim()}\n` : ''}git ${args[0]} timed out after ${Math.round(timeout / 1000)}s and was stopped.`
141
+ : stderr;
142
+ const finalExitCode = timedOut && exitCode === 0 ? 1 : exitCode;
126
143
 
127
- if (exitCode !== 0 && !okExitCodes.includes(exitCode)) {
128
- debug.warn('git', `Command failed (exit ${exitCode}): git ${args.join(' ')}\n${stderr}`);
144
+ if (finalExitCode !== 0 && !okExitCodes.includes(finalExitCode)) {
145
+ debug.warn('git', `Command failed (exit ${finalExitCode}): git ${args.join(' ')}\n${finalStderr}`);
129
146
  }
130
147
 
131
- return raw ? { stdout, stderr, exitCode, stdoutBytes } : { stdout, stderr, exitCode };
148
+ return raw
149
+ ? { stdout, stderr: finalStderr, exitCode: finalExitCode, stdoutBytes }
150
+ : { stdout, stderr: finalStderr, exitCode: finalExitCode };
132
151
  } catch (err) {
133
152
  clearTimeout(timeoutId);
153
+ if (killTimer) clearTimeout(killTimer);
134
154
  throw err;
135
155
  }
136
156
  }