arco-workbench 0.1.7 → 0.1.9

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 (301) hide show
  1. package/CONTRIBUTING.md +63 -12
  2. package/README.md +21 -17
  3. package/client/dist/assets/{PhosphorBackdrop-DVQdBrTw.js → PhosphorBackdrop-DRu16-Is.js} +1 -1
  4. package/client/dist/assets/{ThemedBackgroundShaderImpl-BfSs2tB4.js → ThemedBackgroundShaderImpl-BLdwwQ4D.js} +1 -1
  5. package/client/dist/assets/{XtermView-DaMjC8Ny.js → XtermView-Xk7_9JaH.js} +1 -1
  6. package/client/dist/assets/{galleryEditor-BCQnXj7R.js → galleryEditor-CI8ClzBa.js} +1 -1
  7. package/client/dist/assets/{index-DD9kFGsF.css → index-BEFgrUJJ.css} +1 -1
  8. package/client/dist/assets/{index-COfbHCYv.js → index-C7WzZfsr.js} +257 -255
  9. package/client/dist/index.html +2 -2
  10. package/client/src/App.tsx +2 -0
  11. package/client/src/components/ChatMessage.tsx +33 -8
  12. package/client/src/components/ChatModeView.tsx +2 -0
  13. package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +65 -15
  14. package/client/src/components/ClusterRightPanel/SkillsControl.tsx +124 -0
  15. package/client/src/components/ClusterRightPanel/index.tsx +4 -0
  16. package/client/src/components/ClusterTaskBoardTab.tsx +9 -22
  17. package/client/src/components/CodexLateCommand.tsx +34 -0
  18. package/client/src/components/DialogShell.tsx +2 -0
  19. package/client/src/components/MemberCard.tsx +4 -1
  20. package/client/src/components/MemberPane.tsx +3 -1
  21. package/client/src/components/NeedsYouBadge.tsx +3 -3
  22. package/client/src/components/PhoneUpload.tsx +288 -0
  23. package/client/src/components/PrimaryStatus.tsx +14 -6
  24. package/client/src/components/ProviderReleasesModal.tsx +8 -4
  25. package/client/src/components/ProvidersPopover.tsx +28 -23
  26. package/client/src/components/RuntimeStateBanner.tsx +5 -0
  27. package/client/src/components/SettingsPanel.tsx +2 -2
  28. package/client/src/components/SkillEditorDialog.tsx +2 -2
  29. package/client/src/components/SkillsSettings.tsx +21 -4
  30. package/client/src/components/TabBar.tsx +91 -9
  31. package/client/src/components/TerminalInput.tsx +15 -11
  32. package/client/src/components/TranscriptSendDialog.tsx +12 -8
  33. package/client/src/components/TranscriptWorkerDialog.tsx +119 -0
  34. package/client/src/components/WorkflowView.tsx +2 -0
  35. package/client/src/components/clusterNeedsYou.ts +11 -18
  36. package/client/src/explorer/ArtifactsLens.tsx +37 -28
  37. package/client/src/explorer/ExplorerApp.tsx +5 -4
  38. package/client/src/explorer/types.ts +8 -3
  39. package/client/src/help/content/cluster.tsx +48 -17
  40. package/client/src/help/content/composer.tsx +40 -1
  41. package/client/src/help/content/header.tsx +18 -1
  42. package/client/src/help/content/misc.tsx +9 -1
  43. package/client/src/help/content/settings.tsx +18 -4
  44. package/client/src/help/content/tabbar.tsx +5 -0
  45. package/client/src/help/manualSections/actions.tsx +31 -0
  46. package/client/src/help/manualSections/clusters.tsx +44 -20
  47. package/client/src/help/manualSections/configuration.tsx +20 -0
  48. package/client/src/help/manualSections/gettingStarted.tsx +4 -4
  49. package/client/src/help/manualSections/maintenance.tsx +25 -6
  50. package/client/src/help/manualSections/powerFeatures.tsx +3 -2
  51. package/client/src/help/manualSections/providers.tsx +32 -8
  52. package/client/src/help/manualSections/troubleshooting.tsx +2 -1
  53. package/client/src/help/manualSections/workflows.tsx +12 -0
  54. package/client/src/help/manualSections/workspace.tsx +36 -0
  55. package/client/src/stores/appStore.ts +7 -0
  56. package/client/src/stores/appStore.types.ts +4 -0
  57. package/client/src/styles/global.css +109 -0
  58. package/client/src/utils/phoneTheme.ts +38 -0
  59. package/client/src/utils/phoneUploadApi.ts +10 -0
  60. package/client/src/utils/transcriptWorkerRequest.ts +24 -0
  61. package/client/src/ws/handleServerMessage.ts +31 -8
  62. package/docs/ARCHITECTURE.md +1 -1
  63. package/docs/CLIENT.md +16 -9
  64. package/docs/FEATURES.md +13 -7
  65. package/docs/GETTING_STARTED.md +12 -6
  66. package/docs/GOTCHAS.md +2 -1
  67. package/docs/INDEX.md +1 -1
  68. package/docs/OPERATIONS.md +213 -52
  69. package/docs/PERSISTENCE.md +7 -2
  70. package/docs/PRIMITIVES.md +42 -0
  71. package/docs/PROTOCOL_CLUSTER.md +51 -4
  72. package/docs/PROTOCOL_PRIMITIVES.md +39 -0
  73. package/docs/PROVIDERS.md +84 -13
  74. package/docs/SETTINGS.md +29 -3
  75. package/docs/TASK_LEDGER.md +7 -15
  76. package/native/linux-x64/manifest.json +1 -1
  77. package/native/win32-x64/manifest.json +1 -1
  78. package/node_modules/@arco/shared/dist/clusterCoordination.d.ts +2 -0
  79. package/node_modules/@arco/shared/dist/clusterCoordination.js +5 -1
  80. package/node_modules/@arco/shared/dist/protocol/chat.d.ts +1 -0
  81. package/node_modules/@arco/shared/dist/protocol/clientMessages.d.ts +3 -2
  82. package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +15 -1
  83. package/node_modules/@arco/shared/dist/protocol/index.d.ts +1 -0
  84. package/node_modules/@arco/shared/dist/protocol/index.js +1 -0
  85. package/node_modules/@arco/shared/dist/protocol/models.d.ts +4 -3
  86. package/node_modules/@arco/shared/dist/protocol/models.js +26 -2
  87. package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +13 -1
  88. package/node_modules/@arco/shared/dist/protocol/tasks.d.ts +4 -0
  89. package/node_modules/@arco/shared/dist/protocol/transcriptWorker.d.ts +47 -0
  90. package/node_modules/@arco/shared/dist/protocol/transcriptWorker.js +2 -0
  91. package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
  92. package/node_modules/@arco/shared/dist/runtimeVersions.d.ts +1 -0
  93. package/node_modules/@arco/shared/dist/runtimeVersions.js +14 -0
  94. package/node_modules/@arco/shared/package.json +1 -1
  95. package/package.json +2 -2
  96. package/scripts/packaging/arco.mjs +1 -1
  97. package/scripts/packaging/native-repair.mjs +32 -4
  98. package/server/dist/atomicFile.js +1 -2
  99. package/server/dist/capabilities.d.ts +5 -2
  100. package/server/dist/capabilities.js +59 -9
  101. package/server/dist/cliUpdateDecision.d.ts +1 -1
  102. package/server/dist/cliUpdateDecision.js +5 -3
  103. package/server/dist/clusterDirector.js +2 -1
  104. package/server/dist/clusterPeerOps.js +14 -8
  105. package/server/dist/clusterProgress.js +1 -1
  106. package/server/dist/clusterRehydrate.js +2 -0
  107. package/server/dist/clusterSkills.d.ts +13 -0
  108. package/server/dist/clusterSkills.js +81 -0
  109. package/server/dist/clusterSnapshots.js +2 -0
  110. package/server/dist/clusterStore.d.ts +7 -2
  111. package/server/dist/clusterStore.js +42 -1
  112. package/server/dist/diagnostics/codeSkew.js +1 -0
  113. package/server/dist/eventLog.d.ts +7 -0
  114. package/server/dist/eventLog.js +70 -13
  115. package/server/dist/explorerDocs.d.ts +10 -6
  116. package/server/dist/explorerDocs.js +75 -34
  117. package/server/dist/historyLimits.d.ts +1 -0
  118. package/server/dist/historyLimits.js +3 -0
  119. package/server/dist/http/attachmentUpload.d.ts +13 -0
  120. package/server/dist/http/attachmentUpload.js +38 -0
  121. package/server/dist/http/browserWorktrees.d.ts +23 -0
  122. package/server/dist/http/browserWorktrees.js +120 -0
  123. package/server/dist/http/phoneUploadDrafts.d.ts +13 -0
  124. package/server/dist/http/phoneUploadDrafts.js +125 -0
  125. package/server/dist/http/phoneUploadListener.d.ts +17 -0
  126. package/server/dist/http/phoneUploadListener.js +81 -0
  127. package/server/dist/http/phoneUploadNetwork.d.ts +9 -0
  128. package/server/dist/http/phoneUploadNetwork.js +106 -0
  129. package/server/dist/http/phoneUploadPage.d.ts +2 -0
  130. package/server/dist/http/phoneUploadPage.js +136 -0
  131. package/server/dist/http/phoneUploadRouteHistory.d.ts +4 -0
  132. package/server/dist/http/phoneUploadRouteHistory.js +72 -0
  133. package/server/dist/http/phoneUploadRoutes.d.ts +4 -0
  134. package/server/dist/http/phoneUploadRoutes.js +419 -0
  135. package/server/dist/http/phoneUploadTheme.d.ts +17 -0
  136. package/server/dist/http/phoneUploadTheme.js +96 -0
  137. package/server/dist/http/projectBinding.d.ts +1 -0
  138. package/server/dist/http/projectBinding.js +3 -2
  139. package/server/dist/http/readConfinement.js +5 -1
  140. package/server/dist/http/router.js +14 -25
  141. package/server/dist/http/writeConfinement.js +19 -2
  142. package/server/dist/index.js +24 -1
  143. package/server/dist/jsonlLines.d.ts +4 -0
  144. package/server/dist/jsonlLines.js +53 -0
  145. package/server/dist/management/identity.js +1 -0
  146. package/server/dist/mcp/clusterMcpTools.js +4 -4
  147. package/server/dist/primitives/seedWorker.d.ts +1 -0
  148. package/server/dist/primitives/seedWorker.js +2 -1
  149. package/server/dist/project/taskLedger.d.ts +4 -0
  150. package/server/dist/project/taskLedger.js +7 -4
  151. package/server/dist/providerConversation.d.ts +1 -0
  152. package/server/dist/providerConversation.js +17 -0
  153. package/server/dist/providers/claude-native/resumeSummary.d.ts +9 -0
  154. package/server/dist/providers/claude-native/resumeSummary.js +102 -49
  155. package/server/dist/providers/claude-native/worker.js +8 -4
  156. package/server/dist/providers/claude.js +2 -1
  157. package/server/dist/providers/clusterTaskToolDefinitions.js +4 -4
  158. package/server/dist/providers/codex-appserver/catalog.js +16 -1
  159. package/server/dist/providers/codex-appserver/heldCommands.d.ts +14 -0
  160. package/server/dist/providers/codex-appserver/heldCommands.js +54 -0
  161. package/server/dist/providers/codex-appserver/index.d.ts +52 -2
  162. package/server/dist/providers/codex-appserver/index.js +239 -21
  163. package/server/dist/providers/codex-appserver/lateCommands.d.ts +62 -0
  164. package/server/dist/providers/codex-appserver/lateCommands.js +195 -0
  165. package/server/dist/providers/codex-appserver/worker.d.ts +23 -1
  166. package/server/dist/providers/codex-appserver/worker.js +89 -20
  167. package/server/dist/providers/codex.js +2 -1
  168. package/server/dist/providers/codexCodeMode.d.ts +2 -1
  169. package/server/dist/providers/codexCodeMode.js +8 -3
  170. package/server/dist/providers/cursor/print.js +2 -1
  171. package/server/dist/providers/cursor/worker.js +2 -1
  172. package/server/dist/providers/llamacpp.js +17 -8
  173. package/server/dist/providers/ollamaRecovery.js +6 -6
  174. package/server/dist/providers/ollamaResilience.js +3 -3
  175. package/server/dist/providers/ollamaTokens.js +1 -1
  176. package/server/dist/quota.d.ts +0 -18
  177. package/server/dist/quota.js +0 -44
  178. package/server/dist/replacementHistory.d.ts +19 -0
  179. package/server/dist/replacementHistory.js +49 -0
  180. package/server/dist/server/broadcast.d.ts +2 -1
  181. package/server/dist/server/broadcast.js +1 -0
  182. package/server/dist/server/prompts.d.ts +1 -0
  183. package/server/dist/server/prompts.js +6 -1
  184. package/server/dist/sessionJsonl.d.ts +1 -1
  185. package/server/dist/sessionJsonl.js +115 -40
  186. package/server/dist/smartPickupAdapters.js +15 -2
  187. package/server/dist/transcriptWorker.d.ts +34 -0
  188. package/server/dist/transcriptWorker.js +201 -0
  189. package/server/dist/workers/WorkerManager.d.ts +1 -0
  190. package/server/dist/workers/WorkerManager.js +1 -0
  191. package/server/dist/workers/processKill.d.ts +9 -1
  192. package/server/dist/workers/processKill.js +26 -10
  193. package/server/dist/workflowStore.d.ts +1 -0
  194. package/server/dist/workflowStore.js +31 -0
  195. package/server/dist/ws/clusterHandlers.d.ts +1 -0
  196. package/server/dist/ws/clusterHandlers.js +62 -26
  197. package/server/dist/ws/handoffHandlers.js +7 -2
  198. package/server/dist/ws/transcriptWorkerHandlers.d.ts +25 -0
  199. package/server/dist/ws/transcriptWorkerHandlers.js +139 -0
  200. package/server/dist/ws/turnEngine.js +40 -9
  201. package/server/dist/ws/updatePrimaryConfig.js +27 -8
  202. package/server/dist/ws/workflowHandlers.d.ts +4 -1
  203. package/server/dist/ws/workflowHandlers.js +3 -1
  204. package/server/package.json +1 -1
  205. package/server/src/atomicFile.ts +1 -2
  206. package/server/src/capabilities.ts +58 -17
  207. package/server/src/cliUpdateDecision.ts +5 -4
  208. package/server/src/clusterDirector.ts +2 -1
  209. package/server/src/clusterPeerOps.ts +15 -9
  210. package/server/src/clusterProgress.ts +1 -1
  211. package/server/src/clusterRehydrate.ts +2 -0
  212. package/server/src/clusterSkills.ts +79 -0
  213. package/server/src/clusterSnapshots.ts +1 -0
  214. package/server/src/clusterStore.ts +38 -0
  215. package/server/src/diagnostics/codeSkew.ts +1 -0
  216. package/server/src/eventLog.ts +73 -13
  217. package/server/src/explorerDocs.ts +75 -34
  218. package/server/src/historyLimits.ts +2 -0
  219. package/server/src/http/attachmentUpload.ts +49 -0
  220. package/server/src/http/browserWorktrees.ts +124 -0
  221. package/server/src/http/phoneUploadDrafts.ts +118 -0
  222. package/server/src/http/phoneUploadListener.ts +96 -0
  223. package/server/src/http/phoneUploadNetwork.ts +117 -0
  224. package/server/src/http/phoneUploadPage.ts +137 -0
  225. package/server/src/http/phoneUploadRouteHistory.ts +73 -0
  226. package/server/src/http/phoneUploadRoutes.ts +398 -0
  227. package/server/src/http/phoneUploadTheme.ts +97 -0
  228. package/server/src/http/projectBinding.ts +3 -2
  229. package/server/src/http/readConfinement.ts +5 -1
  230. package/server/src/http/router.ts +12 -26
  231. package/server/src/http/writeConfinement.ts +13 -2
  232. package/server/src/index.ts +23 -0
  233. package/server/src/jsonlLines.ts +52 -0
  234. package/server/src/management/identity.ts +1 -0
  235. package/server/src/mcp/clusterMcpTools.ts +4 -4
  236. package/server/src/primitives/seedWorker.ts +3 -1
  237. package/server/src/project/taskLedger.ts +7 -5
  238. package/server/src/providerConversation.ts +15 -0
  239. package/server/src/providers/claude-native/resumeSummary.ts +98 -50
  240. package/server/src/providers/claude-native/worker.ts +8 -4
  241. package/server/src/providers/claude.ts +2 -1
  242. package/server/src/providers/clusterTaskToolDefinitions.ts +4 -4
  243. package/server/src/providers/codex-appserver/catalog.ts +14 -1
  244. package/server/src/providers/codex-appserver/heldCommands.ts +58 -0
  245. package/server/src/providers/codex-appserver/index.ts +222 -20
  246. package/server/src/providers/codex-appserver/lateCommands.ts +225 -0
  247. package/server/src/providers/codex-appserver/worker.ts +85 -21
  248. package/server/src/providers/codex.ts +2 -1
  249. package/server/src/providers/codexCodeMode.ts +9 -4
  250. package/server/src/providers/cursor/print.ts +2 -1
  251. package/server/src/providers/cursor/worker.ts +2 -1
  252. package/server/src/providers/llamacpp.ts +18 -7
  253. package/server/src/providers/llamacppRecovery.ts +2 -0
  254. package/server/src/providers/ollamaRecovery.ts +6 -6
  255. package/server/src/providers/ollamaResilience.ts +3 -3
  256. package/server/src/providers/ollamaTokens.ts +1 -1
  257. package/server/src/providers/ollamaToolSubset.ts +3 -3
  258. package/server/src/quota.ts +0 -50
  259. package/server/src/replacementHistory.ts +44 -0
  260. package/server/src/server/broadcast.ts +2 -0
  261. package/server/src/server/prompts.ts +8 -1
  262. package/server/src/sessionJsonl.ts +92 -32
  263. package/server/src/smartPickupAdapters.ts +17 -3
  264. package/server/src/transcriptWorker.ts +182 -0
  265. package/server/src/workers/WorkerManager.ts +2 -0
  266. package/server/src/workers/processKill.ts +35 -7
  267. package/server/src/workflowStore.ts +21 -0
  268. package/server/src/ws/clusterHandlers.ts +43 -25
  269. package/server/src/ws/handoffHandlers.ts +7 -1
  270. package/server/src/ws/transcriptWorkerHandlers.ts +126 -0
  271. package/server/src/ws/turnEngine.ts +35 -8
  272. package/server/src/ws/updatePrimaryConfig.ts +25 -6
  273. package/server/src/ws/workflowHandlers.ts +3 -1
  274. package/shared/dist/clusterCoordination.d.ts +2 -0
  275. package/shared/dist/clusterCoordination.js +5 -1
  276. package/shared/dist/protocol/chat.d.ts +1 -0
  277. package/shared/dist/protocol/clientMessages.d.ts +3 -2
  278. package/shared/dist/protocol/clusters.d.ts +15 -1
  279. package/shared/dist/protocol/index.d.ts +1 -0
  280. package/shared/dist/protocol/index.js +1 -0
  281. package/shared/dist/protocol/models.d.ts +4 -3
  282. package/shared/dist/protocol/models.js +26 -2
  283. package/shared/dist/protocol/serverMessages.d.ts +13 -1
  284. package/shared/dist/protocol/tasks.d.ts +4 -0
  285. package/shared/dist/protocol/transcriptWorker.d.ts +47 -0
  286. package/shared/dist/protocol/transcriptWorker.js +2 -0
  287. package/shared/dist/protocol/workflows.d.ts +1 -0
  288. package/shared/dist/runtimeVersions.d.ts +1 -0
  289. package/shared/dist/runtimeVersions.js +14 -0
  290. package/shared/src/clusterCoordination.ts +7 -1
  291. package/shared/src/protocol/chat.ts +1 -0
  292. package/shared/src/protocol/clientMessages.ts +5 -0
  293. package/shared/src/protocol/clusters.ts +20 -6
  294. package/shared/src/protocol/index.ts +1 -0
  295. package/shared/src/protocol/models.ts +31 -5
  296. package/shared/src/protocol/serverMessages.ts +13 -0
  297. package/shared/src/protocol/settings.ts +2 -3
  298. package/shared/src/protocol/tasks.ts +4 -7
  299. package/shared/src/protocol/transcriptWorker.ts +49 -0
  300. package/shared/src/protocol/workflows.ts +4 -0
  301. package/shared/src/runtimeVersions.ts +14 -0
@@ -6,14 +6,30 @@ import { promises as fs } from 'node:fs';
6
6
  import { join } from 'node:path';
7
7
  import { randomUUID } from 'node:crypto';
8
8
  import { atomicWriteFile } from '../../atomicFile.js';
9
- import { listSegments, readLogText, readLogLines } from '../../eventLog.js';
9
+ import { openLogByteSource, readLogLines } from '../../eventLog.js';
10
+ import { jsonlLines } from '../../jsonlLines.js';
10
11
  import { serverFoldSeed } from './serverFold.js';
11
12
  import { isShellToolName } from '@arco/shared';
13
+ import { RECENT_HISTORY_MAX_BYTES } from '../../historyLimits.js';
12
14
  const isFileRead = (name) => !!name && /^(?:Read|(?:.*__)?(?:read_file|fetch_file))$/i.test(name);
13
15
  const SUMMARY_CACHE_VERSION = 4;
14
16
  const SUMMARY_CACHE_KIND = 'claude-native-resume-summary';
15
17
  const DEFAULT_REPLAY_BYTES = 1 * 1024 * 1024;
16
18
  const TAIL_LINE_BACKTRACK_BYTES = 1 * 1024 * 1024;
19
+ // The retained event arrays still amplify source bytes during reconstruction.
20
+ // Refuse an uncached parse beyond the measured default-heap margin; a valid
21
+ // summary cache needs only its small tail and does not parse the old prefix.
22
+ export const NATIVE_RECONSTRUCTION_MAX_BYTES = 1024 * 1024 * 1024;
23
+ export class NativeReconstructionLimitError extends Error {
24
+ rangeBytes;
25
+ code = 'NATIVE_RECONSTRUCTION_LIMIT';
26
+ limitBytes = NATIVE_RECONSTRUCTION_MAX_BYTES;
27
+ constructor(rangeBytes) {
28
+ super(`Claude Native reconstruction requires ${rangeBytes} bytes, above the ${NATIVE_RECONSTRUCTION_MAX_BYTES}-byte limit.`);
29
+ this.rangeBytes = rangeBytes;
30
+ this.name = 'NativeReconstructionLimitError';
31
+ }
32
+ }
17
33
  function readPositiveIntEnv(name, fallback) {
18
34
  const raw = process.env[name];
19
35
  if (!raw)
@@ -26,39 +42,27 @@ export const RESUME_RECENT_TAIL_BYTES = readPositiveIntEnv('ARCO_CLAUDE_NATIVE_R
26
42
  function workflowDir(cwd, workflowId) {
27
43
  return join(cwd, '.arco', 'workflows', workflowId);
28
44
  }
29
- function eventsPath(cwd, workflowId) {
30
- return join(workflowDir(cwd, workflowId), 'events.jsonl');
31
- }
32
45
  function summaryCachePath(cwd, workflowId) {
33
46
  return join(workflowDir(cwd, workflowId), 'resume-summary.json');
34
47
  }
35
48
  async function openLogSource(cwd, workflowId) {
36
- const dir = workflowDir(cwd, workflowId);
37
- if ((await listSegments(dir)).length > 0) {
38
- const text = Buffer.from(await readLogText(dir), 'utf8');
39
- return { size: text.length, read: async (start, length) => text.subarray(start, start + length).toString('utf8') };
40
- }
41
- const path = eventsPath(cwd, workflowId);
42
- try {
43
- const size = (await fs.stat(path)).size;
44
- return { size, read: (start, length) => readByteRange(path, start, length) };
45
- }
46
- catch (err) {
47
- if (err.code === 'ENOENT')
48
- return null;
49
- throw err;
50
- }
49
+ return openLogByteSource(workflowDir(cwd, workflowId));
51
50
  }
52
- async function readByteRange(path, start, length) {
53
- const fh = await fs.open(path, 'r');
54
- try {
55
- const buf = Buffer.alloc(length);
56
- await fh.read(buf, 0, buf.length, start);
57
- return buf.toString('utf8');
58
- }
59
- finally {
60
- await fh.close();
51
+ async function readSourceEvents(source, length, dropLastPartial = false) {
52
+ if (length > NATIVE_RECONSTRUCTION_MAX_BYTES)
53
+ throw new NativeReconstructionLimitError(length);
54
+ const events = [];
55
+ for await (const line of jsonlLines(source.chunks(0, length), 'conversation replay', {
56
+ finalLine: !dropLastPartial, carriageReturns: false,
57
+ })) {
58
+ if (!line)
59
+ continue;
60
+ try {
61
+ events.push(JSON.parse(line));
62
+ }
63
+ catch { /* Match parseJsonl: corrupt or partial records remain untouched. */ }
61
64
  }
65
+ return events;
62
66
  }
63
67
  async function findTailReplayStart(source, desiredStart) {
64
68
  if (desiredStart <= 0)
@@ -445,22 +449,27 @@ export function summarizeClaudeNativePriorTurns(events, laterEvents = [], attach
445
449
  }
446
450
  if (turns.length === 0 && !compactSummary)
447
451
  return { summary: '', throughSeq, lastHandoffSeq };
448
- const lines = [];
449
- if (compactSummary) {
450
- lines.push('## Earlier context (operator-compacted)');
451
- lines.push('');
452
- lines.push(compactSummary.trim());
453
- if (compactTail) {
452
+ const renderPrefix = (summary = compactSummary, tail = compactTail) => {
453
+ const lines = [];
454
+ if (compactSummary) {
455
+ lines.push('## Earlier context (operator-compacted)');
454
456
  lines.push('');
455
- lines.push('### Recent verbatim turns kept at that compaction');
456
- lines.push(compactTail);
457
+ lines.push(summary?.trim() ?? '');
458
+ if (tail) {
459
+ lines.push('');
460
+ lines.push('### Recent verbatim turns kept at that compaction');
461
+ lines.push(tail);
462
+ }
463
+ if (turns.length > 0)
464
+ lines.push('');
457
465
  }
458
466
  if (turns.length > 0)
459
- lines.push('');
460
- }
461
- if (turns.length > 0)
462
- lines.push('## Prior turns in this workflow (auto-summary)');
463
- turns.forEach((t, i) => {
467
+ lines.push('## Prior turns in this workflow (auto-summary)');
468
+ return lines.join('\n');
469
+ };
470
+ let prefix = renderPrefix();
471
+ const notes = turns.map((t, i) => {
472
+ const lines = [];
464
473
  const head = t.userText.length > 120 ? t.userText.slice(0, 120) + '...' : t.userText;
465
474
  lines.push('');
466
475
  lines.push(`### Turn ${i + 1}: ${head}`);
@@ -489,8 +498,44 @@ export function summarizeClaudeNativePriorTurns(events, laterEvents = [], attach
489
498
  const reply = t.finalReply.trim().replace(/\s+/g, ' ').slice(0, 240);
490
499
  lines.push(`- Assistant reply: "${reply}${t.finalReply.length > 240 ? '...' : ''}"`);
491
500
  }
501
+ return lines.join('\n');
492
502
  });
493
- return { summary: lines.join('\n'), throughSeq, lastHandoffSeq };
503
+ const noteBytes = notes.map(note => Buffer.byteLength(note, 'utf8') + 1);
504
+ let retainedBytes = noteBytes.reduce((sum, bytes) => sum + bytes, 0);
505
+ if (Buffer.byteLength(prefix, 'utf8') + retainedBytes <= RECENT_HISTORY_MAX_BYTES) {
506
+ return { summary: [prefix, ...notes].join('\n'), throughSeq, lastHandoffSeq };
507
+ }
508
+ let omitted = 0;
509
+ let shortened = false;
510
+ const notice = () => `Earlier context: ${omitted} oldest turn note${omitted === 1 ? '' : 's'} ${omitted === 1 ? 'was' : 'were'} left out${shortened ? ' and compacted context was shortened' : ''} to stay within 128 KiB.`;
511
+ const prefixBytes = Buffer.byteLength(prefix, 'utf8');
512
+ while (omitted < notes.length && prefixBytes + 1 + Buffer.byteLength(notice(), 'utf8') + retainedBytes > RECENT_HISTORY_MAX_BYTES) {
513
+ retainedBytes -= noteBytes[omitted++];
514
+ }
515
+ if (prefixBytes + 1 + Buffer.byteLength(notice(), 'utf8') > RECENT_HISTORY_MAX_BYTES) {
516
+ // The compacted context itself can be larger than the budget. Preserve its
517
+ // kept-tail digest first, then as much summary text as fits, without cutting
518
+ // a UTF-8 character. The same notice discloses this exceptional shortening.
519
+ shortened = true;
520
+ const budget = RECENT_HISTORY_MAX_BYTES - Buffer.byteLength(notice(), 'utf8') - 1;
521
+ const clip = (text, bytes) => {
522
+ const encoded = Buffer.from(text, 'utf8');
523
+ let end = Math.min(encoded.length, Math.max(0, bytes));
524
+ while (end > 0 && (encoded[end] & 0xc0) === 0x80)
525
+ end--;
526
+ return encoded.subarray(0, end).toString('utf8');
527
+ };
528
+ const tailPrefix = renderPrefix('', compactTail);
529
+ if (Buffer.byteLength(tailPrefix, 'utf8') <= budget) {
530
+ prefix = renderPrefix(clip(compactSummary?.trim() ?? '', budget - Buffer.byteLength(tailPrefix, 'utf8')), compactTail);
531
+ }
532
+ else {
533
+ const overhead = Buffer.byteLength(renderPrefix('', 'x'), 'utf8') - 1;
534
+ prefix = renderPrefix('', clip(compactTail ?? '', budget - overhead));
535
+ }
536
+ }
537
+ const summaryNotice = notice();
538
+ return { summary: [prefix, summaryNotice, ...notes.slice(omitted)].join('\n'), summaryNotice, throughSeq, lastHandoffSeq };
494
539
  }
495
540
  async function readSummaryCache(path, workflowId, sourceSize, tailStartByte) {
496
541
  try {
@@ -501,7 +546,8 @@ async function readSummaryCache(path, workflowId, sourceSize, tailStartByte) {
501
546
  parsed.workflowId === workflowId &&
502
547
  parsed.sourceSize === sourceSize &&
503
548
  parsed.tailStartByte === tailStartByte &&
504
- typeof parsed.summary === 'string' && Array.isArray(parsed.inputHistory)
549
+ typeof parsed.summary === 'string' && Buffer.byteLength(parsed.summary, 'utf8') <= RECENT_HISTORY_MAX_BYTES && Array.isArray(parsed.inputHistory)
550
+ && (parsed.summaryNotice === undefined || typeof parsed.summaryNotice === 'string')
505
551
  && parsed.inputHistory.every(event => (event?.type === 'user_message_echo' && typeof event.content === 'string') || (event?.type === 'queued_messages_drained' && typeof event.deliveryId === 'string'))) {
506
552
  return parsed;
507
553
  }
@@ -527,6 +573,14 @@ export async function replayMessagesWithResumePolicy(cwd, workflowId, maxSeq, op
527
573
  const source = await openLogSource(cwd, workflowId);
528
574
  if (!source)
529
575
  return { messages: [], mode: 'empty', eventBytes: 0 };
576
+ try {
577
+ return await replayFromSource(cwd, workflowId, source, maxSeq, opts);
578
+ }
579
+ finally {
580
+ await source.close();
581
+ }
582
+ }
583
+ async function replayFromSource(cwd, workflowId, source, maxSeq, opts) {
530
584
  const stat = { size: source.size };
531
585
  const exactReplayBytes = opts.exactReplayBytes ?? RESUME_EXACT_REPLAY_BYTES;
532
586
  const recentTailBytes = opts.recentTailBytes ?? RESUME_RECENT_TAIL_BYTES;
@@ -544,8 +598,7 @@ export async function replayMessagesWithResumePolicy(cwd, workflowId, maxSeq, op
544
598
  // This is what lets post-rewind turns be included WITHOUT advancing leafSeq
545
599
  // on every turn.
546
600
  if (typeof opts.leafSeq === 'number') {
547
- const raw = await source.read(0, stat.size);
548
- const events = parseJsonl(raw);
601
+ const events = await readSourceEvents(source, stat.size);
549
602
  let tailSeq;
550
603
  for (const e of events) {
551
604
  if (typeof e.seq === 'number' && (tailSeq === undefined || e.seq > tailSeq))
@@ -561,8 +614,7 @@ export async function replayMessagesWithResumePolicy(cwd, workflowId, maxSeq, op
561
614
  };
562
615
  }
563
616
  if (stat.size <= exactReplayBytes) {
564
- const raw = await source.read(0, stat.size);
565
- const events = parseJsonl(raw);
617
+ const events = await readSourceEvents(source, stat.size);
566
618
  return {
567
619
  messages: buildMessagesFromReplayEvents(events, [], maxSeq, undefined, [], opts.attachmentMarkers),
568
620
  mode: 'exact',
@@ -596,8 +648,7 @@ export async function replayMessagesWithResumePolicy(cwd, workflowId, maxSeq, op
596
648
  const cachePath = summaryCachePath(cwd, workflowId);
597
649
  let cache = opts.attachmentMarkers ? null : await readSummaryCache(cachePath, workflowId, stat.size, tailStartByte);
598
650
  if (!cache) {
599
- const olderRaw = tailStartByte > 0 ? await source.read(0, tailStartByte) : '';
600
- const olderEvents = parseJsonl(olderRaw, { dropLastPartial: !tailStart.completeLine });
651
+ const olderEvents = await readSourceEvents(source, tailStartByte, !tailStart.completeLine);
601
652
  const built = summarizeClaudeNativePriorTurns(olderEvents, tailEvents, !!opts.attachmentMarkers);
602
653
  if (opts.attachmentMarkers) {
603
654
  const lastOlderSeq = olderEvents.reduce((max, event) => Math.max(max, event.seq ?? 0), 0);
@@ -621,6 +672,7 @@ export async function replayMessagesWithResumePolicy(cwd, workflowId, maxSeq, op
621
672
  throughSeq: built.throughSeq,
622
673
  lastHandoffSeq: built.lastHandoffSeq,
623
674
  summary: built.summary,
675
+ summaryNotice: built.summaryNotice,
624
676
  inputHistory: referencedInputRecords(tailEvents, olderEvents),
625
677
  updatedAt: new Date().toISOString(),
626
678
  };
@@ -635,6 +687,7 @@ export async function replayMessagesWithResumePolicy(cwd, workflowId, maxSeq, op
635
687
  summaryThroughSeq: cache.throughSeq ?? undefined,
636
688
  summaryBytes: cache.summary.length,
637
689
  tailEvents: tailEvents.length,
690
+ ...(cache.summaryNotice ? { summaryNotice: cache.summaryNotice } : {}),
638
691
  };
639
692
  }
640
693
  //# sourceMappingURL=resumeSummary.js.map
@@ -1,7 +1,7 @@
1
1
  import { setMaxListeners } from 'node:events';
2
2
  import { assertNativeTaskAllowed } from './taskAdmission.js';
3
3
  import { readSettings } from '../../settings.js';
4
- import { resolveNativeSubagents } from '@arco/shared';
4
+ import { buildTurnWaitInstructions, resolveNativeSubagents } from '@arco/shared';
5
5
  import { availableHandoffSources, executeHandoffHistory, HANDOFF_HISTORY_TOOL, HANDOFF_HISTORY_CONTEXT } from '../../handoffHistoryTool.js';
6
6
  import { mediaRetirementNotice } from './mediaRetirementNotice.js';
7
7
  import { nativeMediaLimits } from './mediaLimits.js';
@@ -15,6 +15,7 @@ import { nativeOAuthBaseUrl } from './apiEndpoint.js';
15
15
  import { createHash } from 'node:crypto';
16
16
  import { ensureProjectStateIgnore } from '../../projectStateIgnore.js';
17
17
  import { replayEventsWithTs } from '../../workflowStore.js';
18
+ import { reportHistoryLoadFailure } from '../../providerConversation.js';
18
19
  import { computerToolDefinitions, executeComputerTool } from '../../voice/toolDefinitions.js';
19
20
  // Phase 7a — long-lived per-workflow Claude Native worker.
20
21
  //
@@ -55,7 +56,7 @@ import { getPeerToolDefinitions, isPeerTool, executePeerTool } from './peerTools
55
56
  import { registryToolDefs, parseRegistryToolName, isRegistryToolAllowed, isRegistryToolReadOnly } from './registryTools.js';
56
57
  import { connectServer } from '../../mcp/client.js';
57
58
  import { getSandboxToolDefinitions, isSandboxTool, executeSandboxTool } from './sandboxTools.js';
58
- import { buildMessagesFromReplayEvents, replayMessagesWithResumePolicy, compactSummarySeed } from './resumeSummary.js';
59
+ import { buildMessagesFromReplayEvents, replayMessagesWithResumePolicy, compactSummarySeed, NativeReconstructionLimitError } from './resumeSummary.js';
59
60
  import { readMeta, setResolvedModelId } from '../../workflowMeta.js';
60
61
  import { lspManager } from '../../lsp/client.js';
61
62
  import { isClaudeServerToolDef, isServerToolResultType, pendingServerTools, pruneServerToolEvidenceAfterTurn, stripDanglingServerToolResults } from './retainedContext.js';
@@ -1266,10 +1267,12 @@ export class ClaudeNativeWorker extends EventEmitter {
1266
1267
  .filter((e) => meta?.computerContext?.lastResetSeq !== undefined
1267
1268
  ? (('seq' in e.message && typeof e.message.seq === 'number') ? e.message.seq : 0) > meta.computerContext.lastResetSeq
1268
1269
  : e.ts > (meta?.computerContext?.lastResetAt ?? 0)).map((e) => e.message)),
1269
- mode: 'exact', reconstructed: false, summaryThroughSeq: undefined, tailEvents: undefined }
1270
+ mode: 'exact', reconstructed: false, summaryThroughSeq: undefined, tailEvents: undefined, summaryNotice: undefined }
1270
1271
  : await replayMessagesWithResumePolicy(cwd, this.workflowId, undefined, { leafSeq: meta?.leafSeq, attachmentMarkers });
1271
1272
  this.messages = attachmentMarkers ? await restoreChatAttachments(replay.messages, attachmentMarkers) : replay.messages;
1272
1273
  this.resetPrefixFreeze('replay');
1274
+ if (replay.summaryNotice)
1275
+ this.emit('system_notice', replay.summaryNotice);
1273
1276
  if (replay.reconstructed) {
1274
1277
  // docs/PERSISTENCE.md - the rewound branch's ancestry
1275
1278
  // had rotated off the size-capped log, so this is a RECONSTRUCTED
@@ -1287,6 +1290,7 @@ export class ClaudeNativeWorker extends EventEmitter {
1287
1290
  }
1288
1291
  catch (err) {
1289
1292
  console.warn(`[claude-native:${this.workflowId.slice(0, 8)}] replay failed:`, err);
1293
+ reportHistoryLoadFailure(this.workflowId, this, 'native', content => this.emit('system_notice', content), err instanceof NativeReconstructionLimitError ? err.limitBytes : undefined);
1290
1294
  }
1291
1295
  }
1292
1296
  this.replayed = true;
@@ -1861,7 +1865,7 @@ export class ClaudeNativeWorker extends EventEmitter {
1861
1865
  'Continue working until the request is complete or you are genuinely blocked on operator input. ' +
1862
1866
  "Never end your turn with a status update, a plan, or a promise of future work ('Continuing now', 'I'll do X next') — " +
1863
1867
  'if your final paragraph describes work you have not done, do that work now instead of ending the turn. ' +
1864
- 'Finishing the request does not mean waiting for it: do not sleep or poll for more than 60 seconds at a time for builds, test suites or CI; report what is running and end the turn. ' +
1868
+ buildTurnWaitInstructions(this.config.clusterRole) + ' ' +
1865
1869
  'If a delegated Task child fails or returns an error or nonsense (e.g. a login error), say so explicitly in your reply and adapt openly — never silently work around a failed delegation. ' +
1866
1870
  // Fable 5.1 / 5.2 can rewrite whole files where a targeted edit would do
1867
1871
  // (docs/PROVIDERS.md); Anthropic's documented one-liner.
@@ -1,3 +1,4 @@
1
+ import { buildTurnWaitInstructions } from '@arco/shared';
1
2
  import { prepareProviderHistory } from './handoffHistoryBinding.js';
2
3
  import { prepareLocalFileContext, combineChatAttachments } from './localFileMedia.js';
3
4
  import { cliFileReadGuidance, prepareProviderAttachments } from './providerFileContent.js';
@@ -37,7 +38,7 @@ const APPEND_SP_TMPDIR = joinPath(tmpdir(), 'arco-prompts');
37
38
  // last (the order Claude Native uses). Each part is stable for the tab, so the
38
39
  // appended system prompt stays byte-identical from turn to turn.
39
40
  function effectiveAppendSystemPrompt(config) {
40
- const parts = [goalBlock(config.goal), config.appendSystemPrompt, cliFileReadGuidance(config), outputStyleAddendum(config.outputStyle)]
41
+ const parts = [buildTurnWaitInstructions(config.clusterRole), goalBlock(config.goal), config.appendSystemPrompt, cliFileReadGuidance(config), outputStyleAddendum(config.outputStyle)]
41
42
  .filter((s) => typeof s === 'string' && s.length > 0);
42
43
  return parts.length > 0 ? parts.join('\n\n') : undefined;
43
44
  }
@@ -20,7 +20,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS = [
20
20
  },
21
21
  {
22
22
  name: 'cluster_task_create',
23
- description: 'Create a non-terminal task on the shared cluster board. New tasks start as todo; done/archived remain operator-only. Use title plus optional body/notes, assignee, priority, parentIds, links, reviewRequired, goalMode, and goalMaxTurns. parentIds must refer to existing tasks. When the task implements a plan item, start the title with that item\'s id or text (e.g. \'P6.9 Live tab drag follow on X11\'): cluster_task_show then resolves the item\'s reference docs (its own ref links, its sub-bullets, its phase intro) for whoever works it. Add any extra ref:slug links the task needs to notes.',
23
+ description: 'Create a non-terminal task on the shared cluster board. New tasks start as todo; terminal statuses cannot be set when creating a task. Use title plus optional body/notes, assignee, priority, parentIds, links, reviewRequired, goalMode, and goalMaxTurns. parentIds must refer to existing tasks. When the task implements a plan item, start the title with that item\'s id or text (e.g. \'P6.9 Live tab drag follow on X11\'): cluster_task_show then resolves the item\'s reference docs (its own ref links, its sub-bullets, its phase intro) for whoever works it. Add any extra ref:slug links the task needs to notes.',
24
24
  input_schema: {
25
25
  type: 'object',
26
26
  properties: {
@@ -63,7 +63,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS = [
63
63
  },
64
64
  {
65
65
  name: 'cluster_task_update',
66
- description: "Update a task on the shared cluster board. Change its `status` (triage / todo / ready / in_progress / blocked / review), append/replace `notes`, and/or record a `signoff` verdict. IMPORTANT: `done` and `archived` are OPERATOR-ONLY - those statuses are REJECTED here (operator_gated). When you finish work, move the task to review or report completion to the director via peer_send; the operator marks done from the LEDGER tab.\n\nSIGN-OFF (director): when you review a peer's completed task (e.g. one in `review`), set `signoff` to your verdict on whether it met its target - `met`, `not_met`, or `partial` - with a one-line `summary`. This is ADVISORY: it does NOT mark the task done (that stays operator-only); it surfaces a recommendation on the board so the operator can accept at a glance. Sign off as part of the same update where you move the task to `review`. Only the reviewing member (the director) should set this.",
66
+ description: "Update a task on the shared cluster board. Workers move completed work to review. Only the director signs off: set signoff to met, partial, or not_met with a plain one-line summary for the operator, without commit hashes. A director's met sign-off closes the task unless Board auto-done is off in Settings; partial and not_met leave the task status unchanged unless you set a status. Tell the operator in chat what to try. Direct status changes to done or archived remain operator-only.",
67
67
  input_schema: {
68
68
  type: 'object',
69
69
  properties: {
@@ -73,7 +73,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS = [
73
73
  release: { type: 'string', description: 'Release label such as 0.1.4; an empty string clears it.' },
74
74
  signoff: {
75
75
  type: 'object',
76
- description: 'Advisory director verdict on whether the task met its target. Does NOT mark it done.',
76
+ description: 'Director verdict: met closes the task unless Board auto-done is off.',
77
77
  properties: {
78
78
  state: { type: 'string', enum: ['met', 'not_met', 'partial'], description: 'Your verdict: met / not_met / partial.' },
79
79
  summary: { type: 'string', description: 'One-line reason shown on the board card.' },
@@ -146,7 +146,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS = [
146
146
  },
147
147
  {
148
148
  name: 'cluster_task_complete',
149
- description: "Submit a completion report for a task YOU OWN. Moves the task to review and appends a durable COMPLETION REPORT comment. You can only complete a task currently assigned to you - completing an unknown id is rejected (not_found) and completing another member's or an unassigned task is rejected (not_owner); claim it first (cluster_task_claim) or coordinate via peer_send. It does NOT mark done; done remains operator-only.",
149
+ description: "Submit a completion report for a task YOU OWN. Moves the task to review and appends a durable COMPLETION REPORT comment. You can only complete a task currently assigned to you - completing an unknown id is rejected (not_found) and completing another member's or an unassigned task is rejected (not_owner); claim it first (cluster_task_claim) or coordinate via peer_send. It does not mark done; the director reviews the report.",
150
150
  input_schema: {
151
151
  type: 'object',
152
152
  properties: {
@@ -27,6 +27,8 @@
27
27
  // `xhigh` on a model that supports it, (b) per-model image-input support,
28
28
  // (c) `additionalSpeedTiers` (e.g. 'priority'), (d) personality support.
29
29
  import { spawn } from 'node:child_process';
30
+ import { statSync } from 'node:fs';
31
+ import { join } from 'node:path';
30
32
  import { JsonRpcClient } from './jsonRpc.js';
31
33
  import { resolveCodexHome } from '../codexHome.js';
32
34
  import { readCodexContextMetadata } from '../codexContextWindow.js';
@@ -39,6 +41,18 @@ const ARCO_CLIENT_VERSION = '0.1.0';
39
41
  // reads of the same home share one entry.
40
42
  const caches = new Map();
41
43
  const inFlightByKey = new Map();
44
+ const modelCacheStamps = new Map();
45
+ // Codex refreshes this file independently, including from its own model picker.
46
+ // A new local catalog must not wait for Arco's one-hour snapshot to expire.
47
+ function modelCacheStamp(home) {
48
+ try {
49
+ const file = statSync(join(home, 'models_cache.json'));
50
+ return `${file.mtimeMs}:${file.ctimeMs}:${file.size}:${file.ino}`;
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ }
42
56
  function cacheKey(codexHome) {
43
57
  return resolveCodexHome(codexHome);
44
58
  }
@@ -83,7 +97,7 @@ export async function getCodexCatalog(force = false, codexHome) {
83
97
  const key = cacheKey(codexHome);
84
98
  const now = Date.now();
85
99
  const cache = caches.get(key) ?? null;
86
- if (!force && cache && now - cache.fetchedAt < REFRESH_INTERVAL_MS)
100
+ if (!force && cache && now - cache.fetchedAt < REFRESH_INTERVAL_MS && modelCacheStamps.get(key) === modelCacheStamp(key))
87
101
  return cache;
88
102
  const existing = inFlightByKey.get(key);
89
103
  if (existing)
@@ -92,6 +106,7 @@ export async function getCodexCatalog(force = false, codexHome) {
92
106
  try {
93
107
  const fresh = await fetchCodexCatalog(codexHome);
94
108
  caches.set(key, fresh);
109
+ modelCacheStamps.set(key, modelCacheStamp(key));
95
110
  return fresh;
96
111
  }
97
112
  catch (err) {
@@ -0,0 +1,14 @@
1
+ import type { HeldCommandResult } from './lateCommands.js';
2
+ export declare const HELD_WAIT_LIMIT_MS: number;
3
+ export declare const HELD_CONTINUATION_LIMIT = 20;
4
+ export declare const HELD_OUTPUT_CHARS = 4000;
5
+ export declare const HELD_RESULTS_WITH_OUTPUT = 8;
6
+ export declare const HELD_BATCH_MS = 2000;
7
+ export declare function formatDuration(ms: number): string;
8
+ export declare function shortCommand(command: string, max?: number): string;
9
+ /** The operator-visible line for one delivered result. */
10
+ export declare function heldResultNotice(result: HeldCommandResult, continues: boolean): string;
11
+ /** The text Codex receives: each result once, output tail capped. */
12
+ export declare function heldResultsMessage(results: HeldCommandResult[], stillRunning: Array<{
13
+ command: string;
14
+ }>): string;
@@ -0,0 +1,54 @@
1
+ export const HELD_WAIT_LIMIT_MS = 30 * 60_000;
2
+ export const HELD_CONTINUATION_LIMIT = 20;
3
+ export const HELD_OUTPUT_CHARS = 4_000;
4
+ // Results in one message; any further results in the same batch keep their
5
+ // exit code but not their output.
6
+ export const HELD_RESULTS_WITH_OUTPUT = 8;
7
+ // Ends this close together go to the agent in one continuation.
8
+ export const HELD_BATCH_MS = 2_000;
9
+ export function formatDuration(ms) {
10
+ const seconds = Math.max(0, Math.round(ms / 1000));
11
+ if (seconds < 60)
12
+ return `${seconds}s`;
13
+ const minutes = Math.floor(seconds / 60);
14
+ if (minutes < 60)
15
+ return `${minutes}m ${seconds % 60}s`;
16
+ return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
17
+ }
18
+ export function shortCommand(command, max = 160) {
19
+ const flat = command.replace(/\s+/g, ' ').trim();
20
+ return flat.length > max ? `${flat.slice(0, max - 3)}...` : flat;
21
+ }
22
+ function outcome(result) {
23
+ return typeof result.exitCode === 'number' ? `exit ${result.exitCode}` : result.failed ? 'failed' : 'ended';
24
+ }
25
+ /** The operator-visible line for one delivered result. */
26
+ export function heldResultNotice(result, continues) {
27
+ return `Command ended: \`${shortCommand(result.command)}\` - ${outcome(result)} after ${formatDuration(result.endedAt - result.startedAt)}.${continues ? ' Codex continues.' : ''}`;
28
+ }
29
+ /** The text Codex receives: each result once, output tail capped. */
30
+ export function heldResultsMessage(results, stillRunning) {
31
+ const parts = ['[Arco] A command you started has ended since your last reply. This is its result, observed by Arco; it is not from the operator.'];
32
+ results.forEach((result, index) => {
33
+ const lines = [
34
+ `Command: ${result.command}`,
35
+ ...(result.cwd ? [`Working directory: ${result.cwd}`] : []),
36
+ `Result: ${outcome(result)} after ${formatDuration(result.endedAt - result.startedAt)}`,
37
+ ];
38
+ if (index < HELD_RESULTS_WITH_OUTPUT) {
39
+ const output = result.output ?? '';
40
+ const tail = output.length > HELD_OUTPUT_CHARS ? output.slice(-HELD_OUTPUT_CHARS) : output;
41
+ lines.push(output.length > HELD_OUTPUT_CHARS
42
+ ? `Output (last ${HELD_OUTPUT_CHARS} of ${output.length} characters):\n${tail}`
43
+ : `Output:\n${tail || '(none)'}`);
44
+ }
45
+ else
46
+ lines.push('Output: not included; too many results in one message.');
47
+ parts.push(lines.join('\n'));
48
+ });
49
+ if (stillRunning.length)
50
+ parts.push(`Still running: ${stillRunning.map(item => shortCommand(item.command)).join('; ')}. Arco tells you when ${stillRunning.length === 1 ? 'it ends' : 'they end'}.`);
51
+ parts.push('Continue the work.');
52
+ return parts.join('\n\n');
53
+ }
54
+ //# sourceMappingURL=heldCommands.js.map
@@ -1,5 +1,55 @@
1
- import type { WorkerConfig } from '@arco/shared';
2
- import type { Provider } from '../types.js';
1
+ import { EventEmitter } from 'events';
2
+ import type { WorkerConfig, WorkerStatus } from '@arco/shared';
3
+ import type { Provider, ProviderProcess } from '../types.js';
4
+ import { CodexAppServerWorker } from './worker.js';
5
+ export declare class CodexAppServerTurn extends EventEmitter implements ProviderProcess {
6
+ private readonly worker;
7
+ private readonly config;
8
+ private readonly appendSystemPrompt;
9
+ private readonly workflowId;
10
+ readonly id: string;
11
+ private _status;
12
+ private _output;
13
+ private settled;
14
+ private wired;
15
+ private fatalSeen;
16
+ private watchdog?;
17
+ private stopToolObserver?;
18
+ private timeoutReason?;
19
+ private readonly startedAt;
20
+ private costUsd;
21
+ private lastResult?;
22
+ private continuations;
23
+ private waitedMs;
24
+ private waitStartedAt;
25
+ private waitTimer?;
26
+ private inputTimer?;
27
+ private batchTimer?;
28
+ private resultSteer?;
29
+ private stopped;
30
+ private interrupting;
31
+ constructor(id: string, worker: CodexAppServerWorker, config: WorkerConfig, appendSystemPrompt: string | undefined, workflowId: string);
32
+ get status(): WorkerStatus;
33
+ get output(): string;
34
+ get pid(): number | undefined;
35
+ spawn(prompt: string): void;
36
+ interrupt(): Promise<void>;
37
+ kill(): void;
38
+ private wireListeners;
39
+ private unwire;
40
+ private fail;
41
+ private afterCodexTurn;
42
+ private startWait;
43
+ private stopWaitClock;
44
+ private reviewWait;
45
+ private checkInput;
46
+ private continueWith;
47
+ private steerResults;
48
+ private runningLabel;
49
+ private giveUp;
50
+ private finish;
51
+ }
52
+ export declare function runningCodexLateCommands(workflowId: string): import("@arco/shared").CodexLateCommand[];
3
53
  export declare function compactCodexAppServerThread(workflowId: string, config?: WorkerConfig, resumeSessionId?: string, stillOwner?: () => boolean): Promise<{
4
54
  ok: boolean;
5
55
  error?: string;