arco-workbench 0.2.4 → 0.2.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 (253) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/THIRD_PARTY_NOTICES +2 -2
  3. package/client/dist/assets/{PhosphorBackdrop-CHXVFLGT.js → PhosphorBackdrop-CLILIwOQ.js} +1 -1
  4. package/client/dist/assets/{ThemedBackgroundShaderImpl-Bhs4I9jA.js → ThemedBackgroundShaderImpl-B87chcb5.js} +1 -1
  5. package/client/dist/assets/{XtermView-CdfurwFx.js → XtermView-BP_j7WSN.js} +1 -1
  6. package/client/dist/assets/{galleryEditor-DYjZZ4cf.js → galleryEditor-B90phoBI.js} +1 -1
  7. package/client/dist/assets/{index-BjDmFvqG.js → index-BfPp1Oup.js} +269 -269
  8. package/client/dist/index.html +1 -1
  9. package/client/src/App.tsx +2 -2
  10. package/client/src/components/AuthReloginNotice.tsx +7 -6
  11. package/client/src/components/ChatMessage.tsx +41 -29
  12. package/client/src/components/ChatPanel.tsx +17 -4
  13. package/client/src/components/ClaudeNativeAccountPicker.tsx +32 -0
  14. package/client/src/components/ClaudeNativeAuthRow.tsx +71 -19
  15. package/client/src/components/ClusterRightPanel/AddWorkerSection.tsx +11 -281
  16. package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +1 -1
  17. package/client/src/components/ClusterRightPanel/FreshMemberForm.tsx +315 -0
  18. package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +17 -7
  19. package/client/src/components/ClusterRightPanel/index.tsx +1 -1
  20. package/client/src/components/ClusterRightPanel/useFreshMemberPicker.ts +6 -4
  21. package/client/src/components/ClusterTab.tsx +2 -2
  22. package/client/src/components/Connections/Connections.tsx +5 -9
  23. package/client/src/components/Connections/model.ts +3 -1
  24. package/client/src/components/FileViewerModal.tsx +54 -17
  25. package/client/src/components/GitHubPanel/index.tsx +9 -5
  26. package/client/src/components/HandoffDialog.tsx +5 -3
  27. package/client/src/components/MobileShell.tsx +1 -33
  28. package/client/src/components/OperatorQuestionNotice.tsx +5 -4
  29. package/client/src/components/ProvidersPopover.tsx +6 -2
  30. package/client/src/components/RightPanel/ActivityTab.tsx +2 -1
  31. package/client/src/components/RightPanel/ConfigTab.tsx +23 -5
  32. package/client/src/components/RightPanel/OutputsPanel.tsx +21 -9
  33. package/client/src/components/RightPanel/outputsReconcile.ts +31 -0
  34. package/client/src/components/SettingsPanel.tsx +7 -10
  35. package/client/src/components/SpawnDialog.tsx +14 -3
  36. package/client/src/components/TabBar.tsx +2 -2
  37. package/client/src/components/TabContextMenu.tsx +73 -133
  38. package/client/src/components/TerminalInput.tsx +4 -3
  39. package/client/src/components/TranscriptWorkerDialog.tsx +14 -4
  40. package/client/src/components/UsageBar.tsx +37 -18
  41. package/client/src/components/WorkflowCreator/ClusterMembersSection.tsx +29 -3
  42. package/client/src/components/WorkflowCreator/index.tsx +29 -15
  43. package/client/src/components/WorkflowView.tsx +1 -1
  44. package/client/src/components/providerIndicator.ts +7 -3
  45. package/client/src/components/settings/GitHubAuthRow.tsx +34 -0
  46. package/client/src/explorer/ArtifactsLens.tsx +17 -8
  47. package/client/src/explorer/ExplorerApp.tsx +3 -3
  48. package/client/src/explorer/types.ts +3 -1
  49. package/client/src/help/content/cluster.tsx +10 -4
  50. package/client/src/help/content/composer.tsx +3 -2
  51. package/client/src/help/content/header.tsx +6 -3
  52. package/client/src/help/content/misc.tsx +7 -5
  53. package/client/src/help/content/rightPanel.tsx +8 -4
  54. package/client/src/help/content/settings.tsx +14 -3
  55. package/client/src/help/content/tabbar.tsx +1 -1
  56. package/client/src/help/manualSections/actions.tsx +5 -1
  57. package/client/src/help/manualSections/clusters.tsx +20 -14
  58. package/client/src/help/manualSections/configuration.tsx +6 -4
  59. package/client/src/help/manualSections/gettingStarted.tsx +4 -2
  60. package/client/src/help/manualSections/maintenance.tsx +24 -0
  61. package/client/src/help/manualSections/powerFeatures.tsx +1 -0
  62. package/client/src/help/manualSections/providers.tsx +11 -4
  63. package/client/src/help/manualSections/workspace.tsx +3 -3
  64. package/client/src/hooks/useClaudeNativeCatalog.ts +26 -0
  65. package/client/src/hooks/useClaudeNativeLogin.ts +16 -11
  66. package/client/src/hooks/useWebSocket.ts +4 -2
  67. package/client/src/layout/layoutRange.ts +4 -5
  68. package/client/src/questions/waitingQuestion.ts +2 -0
  69. package/client/src/stores/appStore.ts +5 -1
  70. package/client/src/stores/appStore.types.ts +2 -0
  71. package/client/src/stores/replayContext.ts +20 -0
  72. package/client/src/utils/chatFileLinks.ts +34 -3
  73. package/client/src/utils/claudeAuth.ts +9 -1
  74. package/client/src/ws/handleServerMessage.ts +11 -3
  75. package/docs/ARCHITECTURE.md +3 -3
  76. package/docs/BACKUP.md +1 -1
  77. package/docs/CLIENT.md +10 -5
  78. package/docs/EXTENDING.md +1 -1
  79. package/docs/FEATURES.md +3 -3
  80. package/docs/GETTING_STARTED.md +5 -4
  81. package/docs/GIT_WORKBENCH.md +8 -0
  82. package/docs/GLOSSARY.md +2 -2
  83. package/docs/GOTCHAS.md +4 -4
  84. package/docs/HTTP_API.md +54 -23
  85. package/docs/OPERATIONS.md +11 -0
  86. package/docs/OPERATOR_ACTIONS.md +2 -2
  87. package/docs/OUTPUTS.md +48 -6
  88. package/docs/PERSISTENCE.md +1 -1
  89. package/docs/PRIMITIVES.md +4 -2
  90. package/docs/PROTOCOL_CLUSTER.md +12 -6
  91. package/docs/PROTOCOL_PRIMITIVES.md +1 -1
  92. package/docs/PROVIDERS.md +46 -9
  93. package/docs/RESEARCH.md +1 -1
  94. package/docs/SETTINGS.md +9 -4
  95. package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +15 -3
  96. package/node_modules/@arco/shared/dist/protocol/clusters.js +1 -1
  97. package/node_modules/@arco/shared/dist/protocol/models.d.ts +6 -1
  98. package/node_modules/@arco/shared/dist/protocol/operatorQuestions.d.ts +2 -1
  99. package/node_modules/@arco/shared/dist/protocol/settings.d.ts +3 -0
  100. package/node_modules/@arco/shared/dist/protocol/settings.js +5 -0
  101. package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
  102. package/node_modules/@arco/shared/dist/protocol/workflows.js +0 -2
  103. package/node_modules/@arco/shared/package.json +1 -1
  104. package/package.json +2 -2
  105. package/scripts/packaging/services.mjs +20 -1
  106. package/scripts/packaging/update.mjs +37 -2
  107. package/server/dist/attention.d.ts +6 -0
  108. package/server/dist/attention.js +6 -0
  109. package/server/dist/auth.d.ts +5 -0
  110. package/server/dist/auth.js +31 -20
  111. package/server/dist/clusterAutoTurn.d.ts +5 -1
  112. package/server/dist/clusterAutoTurn.js +31 -9
  113. package/server/dist/clusterPresets.js +3 -3
  114. package/server/dist/effortValidation.d.ts +2 -2
  115. package/server/dist/effortValidation.js +4 -4
  116. package/server/dist/explorerArtifacts.d.ts +1 -0
  117. package/server/dist/explorerArtifacts.js +12 -1
  118. package/server/dist/geminiMembers.d.ts +7 -1
  119. package/server/dist/geminiMembers.js +28 -14
  120. package/server/dist/http/conversationFiles.d.ts +36 -0
  121. package/server/dist/http/conversationFiles.js +222 -0
  122. package/server/dist/http/fileBytes.d.ts +3 -0
  123. package/server/dist/http/fileBytes.js +33 -0
  124. package/server/dist/http/fileContentRoute.d.ts +2 -0
  125. package/server/dist/http/fileContentRoute.js +139 -0
  126. package/server/dist/http/fileRead.d.ts +54 -2
  127. package/server/dist/http/fileRead.js +31 -24
  128. package/server/dist/http/outputRoutes.js +14 -21
  129. package/server/dist/http/readConfinement.d.ts +0 -11
  130. package/server/dist/http/readConfinement.js +4 -30
  131. package/server/dist/http/router.js +40 -66
  132. package/server/dist/index.js +26 -12
  133. package/server/dist/management/initHubLink.js +1 -1
  134. package/server/dist/outputs.js +8 -0
  135. package/server/dist/primitives/exportContext.d.ts +2 -0
  136. package/server/dist/primitives/exportContext.js +13 -2
  137. package/server/dist/primitives/runCompare.d.ts +7 -1
  138. package/server/dist/primitives/runCompare.js +44 -20
  139. package/server/dist/project/taskLedger.js +46 -34
  140. package/server/dist/providerAccounts.d.ts +4 -0
  141. package/server/dist/providerAccounts.js +20 -1
  142. package/server/dist/providers/antigravity/artifacts.d.ts +23 -0
  143. package/server/dist/providers/antigravity/artifacts.js +140 -0
  144. package/server/dist/providers/antigravity/index.js +85 -7
  145. package/server/dist/providers/antigravity/questions.d.ts +2 -0
  146. package/server/dist/providers/antigravity/questions.js +58 -0
  147. package/server/dist/providers/claude-native/auth.d.ts +9 -8
  148. package/server/dist/providers/claude-native/auth.js +50 -58
  149. package/server/dist/providers/claude-native/authStatus.d.ts +2 -2
  150. package/server/dist/providers/claude-native/authStatus.js +9 -7
  151. package/server/dist/providers/claude-native/catalog.d.ts +6 -5
  152. package/server/dist/providers/claude-native/catalog.js +50 -39
  153. package/server/dist/providers/claude-native/oauth.d.ts +10 -9
  154. package/server/dist/providers/claude-native/oauth.js +120 -96
  155. package/server/dist/providers/claude-native/worker.d.ts +1 -0
  156. package/server/dist/providers/claude-native/worker.js +38 -23
  157. package/server/dist/providers/codex-appserver/operatorQuestions.d.ts +5 -3
  158. package/server/dist/providers/codex-appserver/operatorQuestions.js +27 -13
  159. package/server/dist/server/broadcast.js +6 -0
  160. package/server/dist/settings.d.ts +1 -0
  161. package/server/dist/settings.js +39 -7
  162. package/server/dist/skills.js +1 -1
  163. package/server/dist/smartPickupAdapters.d.ts +1 -0
  164. package/server/dist/smartPickupAdapters.js +2 -2
  165. package/server/dist/smartPickupObserver.js +8 -5
  166. package/server/dist/thirdPartySkills.js +11 -5
  167. package/server/dist/usage.d.ts +1 -1
  168. package/server/dist/usage.js +39 -27
  169. package/server/dist/workers/WorkerManager.d.ts +1 -0
  170. package/server/dist/workers/WorkerManager.js +1 -0
  171. package/server/dist/workers/processKill.js +37 -24
  172. package/server/dist/workflowMeta.js +2 -2
  173. package/server/dist/ws/clusterHandlers.d.ts +2 -2
  174. package/server/dist/ws/clusterHandlers.js +127 -113
  175. package/server/dist/ws/clusterMembers.d.ts +1 -1
  176. package/server/dist/ws/clusterMembers.js +34 -4
  177. package/server/dist/ws/compactHandlers.js +30 -14
  178. package/server/dist/ws/compareHandlers.js +53 -21
  179. package/server/dist/ws/gateHandlers.js +2 -0
  180. package/server/dist/ws/genesisHandlers.js +5 -3
  181. package/server/dist/ws/handoffHandlers.d.ts +1 -1
  182. package/server/dist/ws/handoffHandlers.js +115 -39
  183. package/server/dist/ws/transcriptWorkerHandlers.js +7 -2
  184. package/server/dist/ws/turnEngine.js +33 -18
  185. package/server/dist/ws/updatePrimaryConfig.d.ts +3 -2
  186. package/server/dist/ws/updatePrimaryConfig.js +236 -133
  187. package/server/dist/ws/workflowHandlers.js +21 -4
  188. package/server/package.json +1 -1
  189. package/server/src/attention.ts +7 -0
  190. package/server/src/auth.ts +33 -20
  191. package/server/src/clusterAutoTurn.ts +31 -11
  192. package/server/src/clusterPresets.ts +2 -2
  193. package/server/src/effortValidation.ts +4 -4
  194. package/server/src/explorerArtifacts.ts +12 -1
  195. package/server/src/geminiMembers.ts +26 -15
  196. package/server/src/http/conversationFiles.ts +231 -0
  197. package/server/src/http/fileBytes.ts +34 -0
  198. package/server/src/http/fileContentRoute.ts +123 -0
  199. package/server/src/http/fileRead.ts +30 -25
  200. package/server/src/http/outputRoutes.ts +13 -13
  201. package/server/src/http/readConfinement.ts +3 -30
  202. package/server/src/http/router.ts +38 -62
  203. package/server/src/index.ts +27 -18
  204. package/server/src/management/initHubLink.ts +1 -1
  205. package/server/src/outputs.ts +8 -0
  206. package/server/src/primitives/exportContext.ts +14 -2
  207. package/server/src/primitives/runCompare.ts +73 -46
  208. package/server/src/project/taskLedger.ts +47 -30
  209. package/server/src/providerAccounts.ts +20 -1
  210. package/server/src/providers/antigravity/artifacts.ts +121 -0
  211. package/server/src/providers/antigravity/index.ts +64 -6
  212. package/server/src/providers/antigravity/questions.ts +52 -0
  213. package/server/src/providers/claude-native/auth.ts +45 -60
  214. package/server/src/providers/claude-native/authStatus.ts +9 -8
  215. package/server/src/providers/claude-native/catalog.ts +52 -35
  216. package/server/src/providers/claude-native/oauth.ts +101 -77
  217. package/server/src/providers/claude-native/worker.ts +38 -22
  218. package/server/src/providers/codex-appserver/operatorQuestions.ts +26 -12
  219. package/server/src/server/broadcast.ts +4 -0
  220. package/server/src/settings.ts +36 -8
  221. package/server/src/skills.ts +1 -1
  222. package/server/src/smartPickupAdapters.ts +3 -2
  223. package/server/src/smartPickupObserver.ts +8 -5
  224. package/server/src/thirdPartySkills.ts +11 -5
  225. package/server/src/usage.ts +30 -22
  226. package/server/src/workers/WorkerManager.ts +2 -0
  227. package/server/src/workers/processKill.ts +37 -23
  228. package/server/src/workflowMeta.ts +2 -2
  229. package/server/src/ws/clusterHandlers.ts +107 -104
  230. package/server/src/ws/clusterMembers.ts +25 -6
  231. package/server/src/ws/compactHandlers.ts +29 -15
  232. package/server/src/ws/compareHandlers.ts +59 -25
  233. package/server/src/ws/gateHandlers.ts +2 -0
  234. package/server/src/ws/genesisHandlers.ts +5 -4
  235. package/server/src/ws/handoffHandlers.ts +105 -37
  236. package/server/src/ws/transcriptWorkerHandlers.ts +6 -2
  237. package/server/src/ws/turnEngine.ts +32 -17
  238. package/server/src/ws/updatePrimaryConfig.ts +230 -132
  239. package/server/src/ws/workflowHandlers.ts +20 -4
  240. package/shared/dist/protocol/clusters.d.ts +15 -3
  241. package/shared/dist/protocol/clusters.js +1 -1
  242. package/shared/dist/protocol/models.d.ts +6 -1
  243. package/shared/dist/protocol/operatorQuestions.d.ts +2 -1
  244. package/shared/dist/protocol/settings.d.ts +3 -0
  245. package/shared/dist/protocol/settings.js +5 -0
  246. package/shared/dist/protocol/workflows.d.ts +1 -0
  247. package/shared/dist/protocol/workflows.js +0 -2
  248. package/shared/src/protocol/clusters.ts +23 -5
  249. package/shared/src/protocol/compare.ts +2 -2
  250. package/shared/src/protocol/models.ts +8 -4
  251. package/shared/src/protocol/operatorQuestions.ts +2 -1
  252. package/shared/src/protocol/settings.ts +8 -1
  253. package/shared/src/protocol/workflows.ts +1 -1
@@ -1,14 +1,5 @@
1
- // docs/PROTOCOL_CLUSTER.md "Gemini members". A Gemini (Antigravity) cluster
2
- // member takes a turn only from the operator's own action: NUDGE, or a message
3
- // typed in its composer. Mail to it waits in its mailbox, where the operator
4
- // may read, edit or cancel it before pressing NUDGE; the member then reads it
5
- // with peer_read like any other member. Each operator action gets a
6
- // single-use ticket bound to the member and the exact text, and
7
- // handleUserMessage (ws/turnEngine.ts) starts a Gemini member turn only with
8
- // a valid ticket, checked again when a queued message is taken. Automatic
9
- // turns (AUTO-PICKUP, Smart pickup, busy reminders, task dispatch,
10
- // broadcasts, CONTINUE DIRECTOR, timers, retries) carry no ticket and never
11
- // start one.
1
+ // Gemini member turns require a single-use ticket for the exact input.
2
+ // Operator input, previewed replacement history and an admitted AUTO-PICKUP wake can obtain one.
12
3
  import { createHash, randomUUID } from 'node:crypto';
13
4
  import { buildMessageGuardPolicy } from '@arco/shared';
14
5
  import * as clusterStore from './clusterStore.js';
@@ -23,11 +14,20 @@ import { workflows } from './server/state.js';
23
14
  import { listSkills, buildSkillsManifest } from './skills.js';
24
15
  import { gateProjectResources } from './projectTrust.js';
25
16
  export const GEMINI_PROVIDER = 'antigravity-cli';
26
- export const GEMINI_OPERATOR_ONLY_REFUSAL = 'A Gemini member turn starts only from your NUDGE or a message you type in its composer.';
17
+ export const GEMINI_OPERATOR_ONLY_REFUSAL = "Use NUDGE or the member's composer to start a Gemini turn, or enable AUTO-PICKUP for eligible cluster mail.";
27
18
  export function isGeminiMember(workflowId) {
28
19
  return workflows.get(workflowId)?.config.primaryProvider === GEMINI_PROVIDER
29
20
  && clusterStore.getClusterIdForWorkflow(workflowId) !== undefined;
30
21
  }
22
+ // Research has a separate mailbox and wake policy. Ordinary pickup cannot
23
+ // cross into it or into a member with an isolated access mode.
24
+ export function geminiPickupAllowed(workflowId) {
25
+ const clusterId = clusterStore.getClusterIdForWorkflow(workflowId);
26
+ if (!clusterId || !isGeminiMember(workflowId))
27
+ return false;
28
+ const cluster = clusterStore.getClusterCached(clusterId);
29
+ return !!cluster && !cluster.research && clusterStore.getMemberAccessMode(clusterId, workflowId) === 'standard';
30
+ }
31
31
  // A queued message may wait behind a long turn; six hours bounds memory
32
32
  // without expiring an operator message that is still waiting its turn.
33
33
  const TICKET_TTL_MS = 6 * 60 * 60 * 1000;
@@ -40,8 +40,7 @@ function prune(now) {
40
40
  if (t.expiresAt <= now)
41
41
  tickets.delete(id);
42
42
  }
43
- // Called only from the operator's WebSocket user_message (NUDGE or typed
44
- // message) for a Gemini member.
43
+ // Issued by the server for Gemini operator input, previewed replacement history or an eligible AUTO-PICKUP wake.
45
44
  export function issueGeminiSend(workflowId, content, now = Date.now()) {
46
45
  prune(now);
47
46
  const id = randomUUID();
@@ -110,4 +109,19 @@ export async function geminiNudgeText(workflowId, nudge) {
110
109
  }
111
110
  return [instructions, skills, reminder, nudge].filter(part => part.trim()).join('\n\n---\n\n');
112
111
  }
112
+ export async function prepareGeminiPickup(workflowId, prompt, mode) {
113
+ const clusterId = clusterStore.getClusterIdForWorkflow(workflowId);
114
+ if (!clusterId)
115
+ return undefined;
116
+ const isCurrent = () => geminiPickupAllowed(workflowId)
117
+ && clusterStore.getClusterIdForWorkflow(workflowId) === clusterId
118
+ && clusterStore.getAutoPickupMode(clusterId) === mode
119
+ && !clusterStore.isAutoPickupPaused(clusterId);
120
+ if (!isCurrent())
121
+ return undefined;
122
+ const content = await geminiNudgeText(workflowId, prompt);
123
+ if (!isCurrent())
124
+ return undefined;
125
+ return { content, ticket: issueGeminiSend(workflowId, content), isCurrent };
126
+ }
113
127
  //# sourceMappingURL=geminiMembers.js.map
@@ -0,0 +1,36 @@
1
+ interface Member {
2
+ workflowId: string;
3
+ name: string;
4
+ cwd: string;
5
+ canonicalCwd: string;
6
+ live: boolean;
7
+ }
8
+ interface SearchRoot {
9
+ dir: string;
10
+ member: Member;
11
+ artifacts: boolean;
12
+ }
13
+ export interface FileMatch {
14
+ path: string;
15
+ workflowId?: string;
16
+ name?: string;
17
+ artifact?: boolean;
18
+ }
19
+ export declare function conversationScope(viewerId: string, sourceId: string): Promise<{
20
+ source: Member;
21
+ member: (workflowId: string) => Promise<Member>;
22
+ memberIds: string[];
23
+ clustered: boolean;
24
+ }>;
25
+ type ConversationScope = Awaited<ReturnType<typeof conversationScope>>;
26
+ interface SearchResult {
27
+ matches: FileMatch[];
28
+ searched: SearchRoot[];
29
+ truncated: boolean;
30
+ }
31
+ export declare function resolveConversationFile(asked: string, scope: ConversationScope, options: {
32
+ exact: boolean;
33
+ sourceKnown: boolean;
34
+ legacyOwner: string;
35
+ }): Promise<SearchResult>;
36
+ export {};
@@ -0,0 +1,222 @@
1
+ import path from 'node:path';
2
+ import { opendir } from 'node:fs/promises';
3
+ import * as clusters from '../clusterStore.js';
4
+ import { createReadAccessContext, FileAccessError, isPathWithin, safeDirectory } from '../fileAccessPolicy.js';
5
+ import { artifactsDir } from '../workers/limits.js';
6
+ import { resolveBoundCwd } from './writeConfinement.js';
7
+ import { resolveBrowserRead } from './readConfinement.js';
8
+ const WORKFLOW_ID = /^[a-z0-9_-]{1,64}$/i;
9
+ const MAX_ENTRIES = 8192;
10
+ const MAX_DEPTH = 12;
11
+ const MAX_CHOICES = 32;
12
+ const MAX_PEERS = 256;
13
+ const missing = (err) => ['ENOENT', 'ENOTDIR'].includes(err.code ?? '');
14
+ const missingFile = () => Object.assign(new Error('File not found.'), { code: 'ENOENT' });
15
+ const artifactOwner = (file) => /(?:^|[\\/])\.arco[\\/]workflows[\\/]([^\\/]+)[\\/]artifacts(?:[\\/]|$)/i.exec(file)?.[1];
16
+ export async function conversationScope(viewerId, sourceId) {
17
+ if (!WORKFLOW_ID.test(viewerId) || (sourceId && !WORKFLOW_ID.test(sourceId)))
18
+ throw new FileAccessError();
19
+ const id = clusters.getClusterIdForWorkflow(viewerId);
20
+ const stored = id ? await clusters.readCluster(id) : null;
21
+ const cluster = stored?.members.includes(viewerId) ? stored : null;
22
+ const members = new Map();
23
+ const member = (workflowId) => {
24
+ if (workflowId !== viewerId && !cluster?.members.includes(workflowId))
25
+ throw new FileAccessError();
26
+ let value = members.get(workflowId);
27
+ if (!value) {
28
+ value = (async () => {
29
+ const bound = await resolveBoundCwd(undefined, workflowId);
30
+ // Saved members may have a recorded working directory before the tab
31
+ // rehydrates. Only the current cluster record provides that binding.
32
+ const cwd = bound.ok ? bound.cwd : cluster ? clusters.memberCwdFor(cluster, workflowId) : null;
33
+ if (!cwd)
34
+ throw new FileAccessError();
35
+ return { workflowId, cwd, canonicalCwd: safeDirectory(cwd), name: clusters.displayNameFor(workflowId), live: bound.ok };
36
+ })();
37
+ members.set(workflowId, value);
38
+ }
39
+ return value;
40
+ };
41
+ const viewer = await member(viewerId);
42
+ const source = sourceId ? await member(sourceId) : viewer;
43
+ return { source, member, memberIds: cluster?.members ?? [viewerId], clustered: !!cluster };
44
+ }
45
+ function projectRoot(member) { return { dir: member.canonicalCwd, member, artifacts: false }; }
46
+ function artifactRoot(member) {
47
+ return { dir: artifactsDir(member.canonicalCwd, member.workflowId), member, artifacts: true };
48
+ }
49
+ function matchIn(root, file) {
50
+ return { path: file, workflowId: root.member.workflowId, name: root.artifacts ? root.member.name : 'Project', artifact: root.artifacts };
51
+ }
52
+ // Artifact paths must stay in their owner's artifact tree, including when an
53
+ // alias in the project resolved to that tree or the owner lives in a worktree.
54
+ async function checkArtifact(file, owner, scope, access) {
55
+ const root = artifactRoot(await scope.member(owner));
56
+ const writtenRoot = artifactsDir(root.member.cwd, owner);
57
+ if (!isPathWithin(root.dir, file) && !isPathWithin(writtenRoot, file))
58
+ throw new FileAccessError();
59
+ // A linked artifact root would make another directory the owner's tree.
60
+ if (await access.safeDirectory(root.dir) !== root.dir)
61
+ throw new FileAccessError();
62
+ return matchIn(root, await access.confinedPath(file, [root.dir, writtenRoot]));
63
+ }
64
+ async function exactFile(file, member, scope, access) {
65
+ const owner = artifactOwner(file);
66
+ if (owner) {
67
+ try {
68
+ return await checkArtifact(file, owner, scope, access);
69
+ }
70
+ catch (err) {
71
+ if (!missing(err))
72
+ throw err;
73
+ // Keep the link to an output moved through Arco's output index.
74
+ const producer = await scope.member(owner);
75
+ const tracked = await import('../outputs.js').then(m => m.resolveTrackedOutput(producer.cwd, owner, file)).catch(() => null);
76
+ if (!tracked)
77
+ throw err;
78
+ const trackedOwner = artifactOwner(tracked);
79
+ return trackedOwner ? checkArtifact(tracked, trackedOwner, scope, access)
80
+ : { path: tracked, workflowId: owner, name: producer.name, artifact: true };
81
+ }
82
+ }
83
+ const real = member.live
84
+ ? await resolveBrowserRead(file, member.cwd, member.workflowId)
85
+ : await access.confinedPath(file, [member.cwd]);
86
+ const realOwner = artifactOwner(real);
87
+ return realOwner ? checkArtifact(real, realOwner, scope, access) : { path: real, workflowId: member.workflowId };
88
+ }
89
+ // Directory enumeration is bounded across the whole request. Listings don't
90
+ // follow links or descend into hidden/runtime trees. A matching regular file
91
+ // and every directory are checked under the same root before use.
92
+ async function searchName(root, name, access, matches, budget) {
93
+ async function walk(dir, depth) {
94
+ if (budget.entries >= MAX_ENTRIES || matches.size >= MAX_CHOICES || depth > MAX_DEPTH) {
95
+ budget.truncated = true;
96
+ return;
97
+ }
98
+ try {
99
+ if (await access.confinedPath(dir, [root.dir], 'directory') !== dir)
100
+ return;
101
+ for await (const entry of await opendir(dir)) {
102
+ if (budget.entries++ >= MAX_ENTRIES || matches.size >= MAX_CHOICES) {
103
+ budget.truncated = true;
104
+ break;
105
+ }
106
+ if (entry.name.startsWith('.') || ['node_modules', 'raw-tools'].includes(entry.name.toLowerCase()))
107
+ continue;
108
+ const file = path.join(dir, entry.name);
109
+ if (entry.isDirectory())
110
+ await walk(file, depth + 1);
111
+ else if (entry.isFile() && (process.platform === 'win32' ? entry.name.toLowerCase() === name.toLowerCase() : entry.name === name)) {
112
+ const resolved = await access.confinedPath(file, [root.dir]).catch(err => {
113
+ if (missing(err) || err instanceof FileAccessError)
114
+ return undefined;
115
+ throw err;
116
+ });
117
+ if (resolved === file)
118
+ matches.set(file, matchIn(root, file));
119
+ }
120
+ }
121
+ }
122
+ catch (err) {
123
+ if (!missing(err) && err.code !== 'EACCES' && err.code !== 'EPERM')
124
+ throw err;
125
+ }
126
+ }
127
+ await walk(root.dir, 0);
128
+ }
129
+ export async function resolveConversationFile(asked, scope, options) {
130
+ const { source } = scope;
131
+ const access = await createReadAccessContext();
132
+ if (!asked || asked.includes('\0'))
133
+ throw new FileAccessError();
134
+ if (options.exact && !path.isAbsolute(asked))
135
+ throw new FileAccessError();
136
+ const absolute = path.resolve(source.cwd, asked);
137
+ access.assertSafePath(absolute);
138
+ const bare = !/[\\/]/.test(asked) && !asked.startsWith('.');
139
+ if (options.legacyOwner && (!bare || !scope.clustered || !scope.memberIds.includes(options.legacyOwner)))
140
+ throw new FileAccessError();
141
+ const result = { matches: [], searched: [], truncated: false };
142
+ const matches = new Map();
143
+ const budget = { entries: 0, truncated: false };
144
+ const project = projectRoot(source);
145
+ const artifacts = artifactRoot(source);
146
+ const probe = async (read, bestEffort = false) => {
147
+ try {
148
+ const match = await read();
149
+ matches.set(match.path, match);
150
+ }
151
+ catch (err) {
152
+ if (!missing(err) && !(bestEffort && err instanceof FileAccessError))
153
+ throw err;
154
+ }
155
+ };
156
+ const finish = () => ({ ...result, matches: [...matches.values()], truncated: budget.truncated });
157
+ const qualified = path.isAbsolute(asked) || /^(?:\.\.?)[\\/]/.test(asked);
158
+ if (!path.isAbsolute(asked) && path.win32.isAbsolute(asked))
159
+ return finish();
160
+ if (!options.legacyOwner) {
161
+ result.searched.push(project);
162
+ await probe(() => exactFile(absolute, source, scope, access));
163
+ if (options.exact || qualified || (!bare && matches.size)) {
164
+ if (options.exact && matches.size && !matches.has(asked))
165
+ throw missingFile();
166
+ return finish();
167
+ }
168
+ }
169
+ const peerRoots = async () => {
170
+ const ids = options.legacyOwner ? [options.legacyOwner] : scope.memberIds.filter(id => id !== source.workflowId);
171
+ if (ids.length > MAX_PEERS)
172
+ budget.truncated = true;
173
+ const roots = [];
174
+ for (const id of ids.slice(0, MAX_PEERS)) {
175
+ const member = await scope.member(id).catch(err => {
176
+ if (err instanceof FileAccessError || missing(err))
177
+ return null;
178
+ throw err;
179
+ });
180
+ if (member)
181
+ roots.push(artifactRoot(member));
182
+ }
183
+ return roots;
184
+ };
185
+ const search = async (roots, projectFallback) => {
186
+ for (const root of roots) {
187
+ const target = path.resolve(root.dir, asked);
188
+ if (!isPathWithin(root.dir, target))
189
+ continue;
190
+ result.searched.push(root);
191
+ await probe(() => checkArtifact(target, root.member.workflowId, scope, access), true);
192
+ if (matches.size >= MAX_CHOICES) {
193
+ budget.truncated = true;
194
+ return;
195
+ }
196
+ }
197
+ if (!bare)
198
+ return;
199
+ for (const root of projectFallback ? [...roots, projectFallback] : roots) {
200
+ await searchName(root, asked, access, matches, budget);
201
+ if (budget.entries >= MAX_ENTRIES || matches.size >= MAX_CHOICES) {
202
+ budget.truncated = true;
203
+ break;
204
+ }
205
+ }
206
+ };
207
+ if (options.legacyOwner) {
208
+ await search(await peerRoots());
209
+ if (!matches.size)
210
+ throw new FileAccessError();
211
+ }
212
+ else if (options.sourceKnown) {
213
+ await search([artifacts], project);
214
+ if (!matches.size)
215
+ await search(await peerRoots());
216
+ }
217
+ else {
218
+ await search([artifacts, ...await peerRoots()], project);
219
+ }
220
+ return finish();
221
+ }
222
+ //# sourceMappingURL=conversationFiles.js.map
@@ -0,0 +1,3 @@
1
+ import type { FileHandle } from 'node:fs/promises';
2
+ import type { IncomingMessage, ServerResponse } from 'node:http';
3
+ export declare function sendFileBytes(req: IncomingMessage, res: ServerResponse, handle: FileHandle, size: number, name: string, mime?: string): Promise<void>;
@@ -0,0 +1,33 @@
1
+ import { pipeline } from 'node:stream/promises';
2
+ export async function sendFileBytes(req, res, handle, size, name, mime) {
3
+ const range = /^bytes=(\d*)-(\d*)$/.exec(req.headers.range || '');
4
+ // A multipart or malformed range is ignored. Browsers seek with one byte
5
+ // range, including open-ended ranges and suffixes (the tail of a PDF).
6
+ const partial = !!(range && (range[1] || range[2]));
7
+ const start = !partial ? 0 : range[1] ? Number(range[1]) : Math.max(0, size - Number(range[2]));
8
+ const end = partial && range[1] && range[2] ? Math.min(Number(range[2]), size - 1) : size - 1;
9
+ if (partial && (start > end || start >= size)) {
10
+ res.writeHead(416, { 'Content-Range': `bytes */${size}`, 'Accept-Ranges': 'bytes', 'Cache-Control': 'no-store' });
11
+ res.end();
12
+ return;
13
+ }
14
+ const encodedName = encodeURIComponent(Buffer.from(name).toString())
15
+ .replace(/['()*]/g, char => '%' + char.charCodeAt(0).toString(16).toUpperCase());
16
+ res.writeHead(partial ? 206 : 200, {
17
+ 'Content-Type': mime ?? 'application/octet-stream',
18
+ 'Cache-Control': 'no-store',
19
+ 'X-Content-Type-Options': 'nosniff',
20
+ // Native PDF viewers need an unsandboxed same-origin frame. The body
21
+ // still has a fixed PDF content type and cannot be sniffed as HTML.
22
+ 'Content-Security-Policy': mime === 'application/pdf' ? "default-src 'none'; frame-ancestors 'self'" : "sandbox; default-src 'none'",
23
+ 'Content-Disposition': `${mime ? 'inline' : 'attachment'}; filename*=UTF-8''${encodedName}`,
24
+ 'Accept-Ranges': 'bytes',
25
+ 'Content-Length': partial ? end - start + 1 : size,
26
+ ...(partial ? { 'Content-Range': `bytes ${start}-${end}/${size}` } : {}),
27
+ });
28
+ if (req.method === 'HEAD' || !size)
29
+ res.end();
30
+ else
31
+ await pipeline(handle.createReadStream({ autoClose: false, emitClose: false, start, end }), res);
32
+ }
33
+ //# sourceMappingURL=fileBytes.js.map
@@ -0,0 +1,2 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ export declare function tryHandleFileContent(req: IncomingMessage, res: ServerResponse): Promise<boolean>;
@@ -0,0 +1,139 @@
1
+ import path from 'node:path';
2
+ import { openCheckedFile } from '../checkedFile.js';
3
+ import { FileAccessError } from '../fileAccessPolicy.js';
4
+ import { geminiSessionKey, openGeminiArtifact } from '../providers/antigravity/artifacts.js';
5
+ import { outputContext } from '../outputs.js';
6
+ import { conversationScope, resolveConversationFile } from './conversationFiles.js';
7
+ import { sendFileBytes } from './fileBytes.js';
8
+ import { readExplorerHandle } from './fileRead.js';
9
+ import { resolveBrowserRead } from './readConfinement.js';
10
+ const PREVIEW_MIME = new Map([
11
+ ['.mp3', 'audio/mpeg'], ['.wav', 'audio/wav'], ['.ogg', 'audio/ogg'], ['.opus', 'audio/ogg'],
12
+ ['.m4a', 'audio/mp4'], ['.aac', 'audio/aac'], ['.oga', 'audio/ogg'], ['.flac', 'audio/flac'],
13
+ ['.mp4', 'video/mp4'], ['.m4v', 'video/mp4'], ['.webm', 'video/webm'], ['.ogv', 'video/ogg'],
14
+ ['.mov', 'video/quicktime'], ['.pdf', 'application/pdf'],
15
+ ]);
16
+ const ROUTE = '/api/file-content';
17
+ function json(res, status, body) {
18
+ res.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
19
+ res.end(JSON.stringify(body));
20
+ return true;
21
+ }
22
+ export async function tryHandleFileContent(req, res) {
23
+ if (req.url?.split('?')[0] !== ROUTE || (req.method !== 'GET' && req.method !== 'HEAD'))
24
+ return false;
25
+ const params = new URL(req.url, 'http://localhost').searchParams;
26
+ const asked = params.get('path') || '';
27
+ const cwd = params.get('cwd') || '';
28
+ const viewer = params.get('workflowId') || '';
29
+ const source = params.get('sourceWorkflowId') || '';
30
+ const legacyOwner = params.get('artifactOwner') || '';
31
+ const download = params.get('download') === '1';
32
+ const bytes = download || params.get('bytes') === '1';
33
+ const exact = bytes || params.get('exact') === '1';
34
+ if (req.method === 'HEAD' && !bytes)
35
+ return false;
36
+ const selectedUrl = (match, mode) => {
37
+ const query = new URLSearchParams({ path: match.path, exact: '1' });
38
+ if (cwd)
39
+ query.set('cwd', cwd);
40
+ if (viewer)
41
+ query.set('workflowId', viewer);
42
+ if (match.workflowId)
43
+ query.set('sourceWorkflowId', match.workflowId);
44
+ if (mode)
45
+ query.set(mode, '1');
46
+ return ROUTE + '?' + query;
47
+ };
48
+ const respond = async (match, handle, size) => {
49
+ const mime = PREVIEW_MIME.get(path.extname(match.path).toLowerCase());
50
+ if (bytes) {
51
+ if (!download && !mime)
52
+ throw new FileAccessError();
53
+ await sendFileBytes(req, res, handle, size, path.basename(match.path), download ? undefined : mime);
54
+ return true;
55
+ }
56
+ const payload = mime
57
+ ? { type: mime === 'application/pdf' ? 'pdf' : mime.split('/')[0], size, url: selectedUrl(match, 'bytes') }
58
+ : await readExplorerHandle(match.path, handle, size);
59
+ return json(res, 200, { ...payload, resolvedPath: match.path,
60
+ ...(match.artifact ? { artifactOwner: match.name } : {}),
61
+ ...(mime || payload.type === 'binary' || payload.type === 'too-large' ? { downloadUrl: selectedUrl(match, 'download') } : {}),
62
+ });
63
+ };
64
+ try {
65
+ if ((source && !viewer) || (legacyOwner && exact) || (exact && !path.isAbsolute(asked)))
66
+ throw new FileAccessError();
67
+ const key = geminiSessionKey(asked);
68
+ if (key !== undefined) {
69
+ if (!key || !viewer || legacyOwner)
70
+ throw new FileAccessError();
71
+ // Continue serving saved Gemini outputs through the manifest. When a
72
+ // message has a peer sender, authorize it before using that manifest.
73
+ const member = source && source !== viewer ? (await conversationScope(viewer, source)).source : undefined;
74
+ const ctx = await outputContext(member?.cwd ?? cwd, member?.workflowId ?? viewer).catch(() => { throw new FileAccessError(); });
75
+ const { file, handle, info } = await openGeminiArtifact(ctx.cwd, ctx.workflowId, { key });
76
+ try {
77
+ if (exact && file !== asked)
78
+ return json(res, 404, { type: 'error', error: `File not found: ${asked}.` });
79
+ return await respond({ path: file, workflowId: ctx.workflowId }, handle, info.size);
80
+ }
81
+ finally {
82
+ await handle.close();
83
+ }
84
+ }
85
+ let match;
86
+ const scope = viewer ? await conversationScope(viewer, source).catch(err => {
87
+ // Older call sites can read a tracked output of a saved workflow even
88
+ // when it has no live tab. Keep the narrow tracked-output lookup below.
89
+ if (err instanceof FileAccessError && !source && !legacyOwner)
90
+ return undefined;
91
+ throw err;
92
+ }) : undefined;
93
+ if (scope) {
94
+ const found = await resolveConversationFile(asked, scope, { exact, sourceKnown: Boolean(source), legacyOwner });
95
+ if (!exact && (found.matches.length > 1 || (found.truncated && found.matches.length > 0))) {
96
+ return json(res, 200, {
97
+ type: 'choices',
98
+ choices: found.matches.map(item => ({
99
+ workflowId: item.workflowId, name: item.name ?? 'Project', resolvedPath: item.path, readUrl: selectedUrl(item),
100
+ })),
101
+ ...(found.truncated ? { truncated: true } : {}),
102
+ });
103
+ }
104
+ const chosen = found.matches[0];
105
+ if (!chosen) {
106
+ const locations = found.searched.map(root => root.artifacts ? `${root.member.name} artifacts (${root.dir})` : root.dir);
107
+ const search = locations.length ? ` Searched: ${[...new Set(locations)].join(', ')}.` : '';
108
+ const limit = found.truncated ? ' Search reached its limit. Use a more specific path.' : '';
109
+ return json(res, 404, { type: 'error', error: `File not found: ${asked}.${search}${limit}` });
110
+ }
111
+ match = chosen;
112
+ }
113
+ else {
114
+ if (legacyOwner)
115
+ throw new FileAccessError();
116
+ const resolved = await resolveBrowserRead(asked, cwd, viewer);
117
+ if (exact && resolved !== asked)
118
+ return json(res, 404, { type: 'error', error: `File not found: ${asked}.` });
119
+ match = { path: resolved };
120
+ }
121
+ const handle = await openCheckedFile(match.path);
122
+ try {
123
+ return await respond(match, handle, (await handle.stat()).size);
124
+ }
125
+ finally {
126
+ await handle.close();
127
+ }
128
+ }
129
+ catch (err) {
130
+ if (res.headersSent) {
131
+ res.destroy();
132
+ return true;
133
+ }
134
+ const code = err.code;
135
+ const message = code === 'ENOENT' || code === 'ENOTDIR' ? `File not found: ${asked}` : (err instanceof Error ? err.message : String(err));
136
+ return json(res, code === 'EACCES' ? 403 : 404, { type: 'error', error: message });
137
+ }
138
+ }
139
+ //# sourceMappingURL=fileContentRoute.js.map
@@ -1,7 +1,8 @@
1
+ import type { FileHandle } from 'fs/promises';
1
2
  export declare function readFileForExplorer(path: string): Promise<{
2
3
  type: "too-large";
3
4
  size: number;
4
- kind: "image";
5
+ kind: string;
5
6
  dataUrl?: undefined;
6
7
  content?: undefined;
7
8
  } | {
@@ -11,11 +12,30 @@ export declare function readFileForExplorer(path: string): Promise<{
11
12
  kind?: undefined;
12
13
  content?: undefined;
13
14
  } | {
15
+ type: "binary";
16
+ size: number;
17
+ kind?: undefined;
18
+ dataUrl?: undefined;
19
+ content?: undefined;
20
+ } | {
21
+ type: "text";
22
+ content: string;
23
+ size: number;
24
+ kind?: undefined;
25
+ dataUrl?: undefined;
26
+ }>;
27
+ export declare function readExplorerHandle(path: string, handle: FileHandle, size: number): Promise<{
14
28
  type: "too-large";
15
29
  size: number;
16
- kind: "text";
30
+ kind: string;
17
31
  dataUrl?: undefined;
18
32
  content?: undefined;
33
+ } | {
34
+ type: "image";
35
+ dataUrl: string;
36
+ size: number;
37
+ kind?: undefined;
38
+ content?: undefined;
19
39
  } | {
20
40
  type: "binary";
21
41
  size: number;
@@ -29,4 +49,36 @@ export declare function readFileForExplorer(path: string): Promise<{
29
49
  kind?: undefined;
30
50
  dataUrl?: undefined;
31
51
  }>;
52
+ export declare function readGeminiPreview(file: string, handle: FileHandle, size: number, ctx: {
53
+ cwd: string;
54
+ workflowId: string;
55
+ }, id: string): Promise<{
56
+ type: "too-large";
57
+ size: number;
58
+ kind: string;
59
+ dataUrl?: undefined;
60
+ content?: undefined;
61
+ } | {
62
+ type: "image";
63
+ dataUrl: string;
64
+ size: number;
65
+ kind?: undefined;
66
+ content?: undefined;
67
+ } | {
68
+ type: "binary";
69
+ size: number;
70
+ kind?: undefined;
71
+ dataUrl?: undefined;
72
+ content?: undefined;
73
+ } | {
74
+ type: "text";
75
+ content: string;
76
+ size: number;
77
+ kind?: undefined;
78
+ dataUrl?: undefined;
79
+ }> | {
80
+ type: string;
81
+ size: number;
82
+ url: string;
83
+ };
32
84
  export declare function encodeProjectDir(cwd: string): string;
@@ -1,5 +1,4 @@
1
1
  import { openCheckedFile } from '../checkedFile.js';
2
- import { FileAccessError } from '../fileAccessPolicy.js';
3
2
  import { extname, resolve } from 'path';
4
3
  import { MAX_TEXT_SIZE, MAX_IMAGE_SIZE } from '../server/constants.js';
5
4
  const IMAGE_MIME = {
@@ -13,36 +12,44 @@ const IMAGE_MIME = {
13
12
  '.ico': 'image/x-icon',
14
13
  };
15
14
  export async function readFileForExplorer(path) {
16
- const ext = extname(path).toLowerCase();
17
15
  const handle = await openCheckedFile(path);
18
16
  try {
19
- const stats = await handle.stat();
20
- if (!stats.isFile())
21
- throw new FileAccessError();
22
- const size = stats.size;
23
- if (IMAGE_MIME[ext]) {
24
- if (size > MAX_IMAGE_SIZE)
25
- return { type: 'too-large', size, kind: 'image' };
26
- const buf = await handle.readFile();
27
- return {
28
- type: 'image',
29
- dataUrl: `data:${IMAGE_MIME[ext]};base64,${buf.toString('base64')}`,
30
- size,
31
- };
32
- }
33
- if (size > MAX_TEXT_SIZE)
34
- return { type: 'too-large', size, kind: 'text' };
35
- const buf = await handle.readFile();
36
- const sample = buf.subarray(0, Math.min(8192, buf.length));
37
- if (sample.includes(0)) {
38
- return { type: 'binary', size };
39
- }
40
- return { type: 'text', content: buf.toString('utf-8'), size };
17
+ return await readExplorerHandle(path, handle, (await handle.stat()).size);
41
18
  }
42
19
  finally {
43
20
  await handle.close();
44
21
  }
45
22
  }
23
+ // Use the handle that passed authorization and stop at the inspected length,
24
+ // even if the producer appends bytes while the preview is loading.
25
+ export async function readExplorerHandle(path, handle, size) {
26
+ const mime = IMAGE_MIME[extname(path).toLowerCase()];
27
+ if (size > (mime ? MAX_IMAGE_SIZE : MAX_TEXT_SIZE))
28
+ return { type: 'too-large', size, kind: mime ? 'image' : 'text' };
29
+ const buffer = Buffer.alloc(size);
30
+ let offset = 0;
31
+ while (offset < size) {
32
+ const { bytesRead } = await handle.read(buffer, offset, size - offset, offset);
33
+ if (!bytesRead)
34
+ break;
35
+ offset += bytesRead;
36
+ }
37
+ const bytes = buffer.subarray(0, offset);
38
+ if (mime)
39
+ return { type: 'image', dataUrl: `data:${mime};base64,${bytes.toString('base64')}`, size: offset };
40
+ if (bytes.subarray(0, 8192).includes(0))
41
+ return { type: 'binary', size: offset };
42
+ return { type: 'text', content: bytes.toString('utf8'), size: offset };
43
+ }
44
+ // Media playback uses the same exact output id and bounded download handle.
45
+ export function readGeminiPreview(file, handle, size, ctx, id) {
46
+ const ext = extname(file).toLowerCase();
47
+ const type = ['.mp3', '.wav', '.ogg', '.m4a', '.flac', '.opus'].includes(ext) ? 'audio'
48
+ : ['.mp4', '.webm', '.mov'].includes(ext) ? 'video' : null;
49
+ if (type)
50
+ return { type, size, url: '/api/outputs/file?' + new URLSearchParams({ cwd: ctx.cwd, workflowId: ctx.workflowId, id }) };
51
+ return readExplorerHandle(file, handle, size);
52
+ }
46
53
  // Claude CLI stores historical transcripts at
47
54
  // ~/.claude/projects/<encoded-cwd>/<sessionId>.jsonl
48
55
  // Encoding replaces every non-[A-Za-z0-9-] char with `-`, not just `/` — see