arco-workbench 0.2.2 → 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 (276) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/THIRD_PARTY_NOTICES +2 -2
  3. package/client/dist/assets/{PhosphorBackdrop-BbR3xmfD.js → PhosphorBackdrop-CLILIwOQ.js} +1 -1
  4. package/client/dist/assets/{ThemedBackgroundShaderImpl-UMjbs9ZN.js → ThemedBackgroundShaderImpl-B87chcb5.js} +1 -1
  5. package/client/dist/assets/{XtermView-n135qz-f.js → XtermView-BP_j7WSN.js} +1 -1
  6. package/client/dist/assets/{galleryEditor-CFSke4by.js → galleryEditor-B90phoBI.js} +1 -1
  7. package/client/dist/assets/{index-DeoJbjI3.js → index-BfPp1Oup.js} +270 -270
  8. package/client/dist/index.html +1 -1
  9. package/client/dist/manifest-mobile.webmanifest +1 -0
  10. package/client/src/App.tsx +2 -2
  11. package/client/src/components/AuthReloginNotice.tsx +7 -6
  12. package/client/src/components/ChatMessage.tsx +41 -29
  13. package/client/src/components/ChatPanel.tsx +17 -4
  14. package/client/src/components/ClaudeNativeAccountPicker.tsx +32 -0
  15. package/client/src/components/ClaudeNativeAuthRow.tsx +71 -19
  16. package/client/src/components/ClusterRightPanel/AddWorkerSection.tsx +11 -281
  17. package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +1 -1
  18. package/client/src/components/ClusterRightPanel/FreshMemberForm.tsx +315 -0
  19. package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +17 -7
  20. package/client/src/components/ClusterRightPanel/index.tsx +1 -1
  21. package/client/src/components/ClusterRightPanel/useFreshMemberPicker.ts +6 -4
  22. package/client/src/components/ClusterTab.tsx +2 -2
  23. package/client/src/components/Connections/Connections.tsx +7 -11
  24. package/client/src/components/Connections/model.ts +3 -1
  25. package/client/src/components/FileViewerModal.tsx +54 -17
  26. package/client/src/components/GitHubPanel/index.tsx +9 -5
  27. package/client/src/components/HandoffDialog.tsx +5 -3
  28. package/client/src/components/MobileShell.tsx +1 -33
  29. package/client/src/components/OperatorQuestionNotice.tsx +5 -4
  30. package/client/src/components/ProvidersPopover.tsx +6 -2
  31. package/client/src/components/RightPanel/ActivityTab.tsx +2 -1
  32. package/client/src/components/RightPanel/ConfigTab.tsx +23 -5
  33. package/client/src/components/RightPanel/OutputsPanel.tsx +21 -9
  34. package/client/src/components/RightPanel/outputsReconcile.ts +31 -0
  35. package/client/src/components/SettingsPanel.tsx +7 -10
  36. package/client/src/components/SpawnDialog.tsx +14 -3
  37. package/client/src/components/TabBar.tsx +2 -2
  38. package/client/src/components/TabContextMenu.tsx +73 -133
  39. package/client/src/components/TerminalInput.tsx +4 -3
  40. package/client/src/components/TranscriptWorkerDialog.tsx +14 -4
  41. package/client/src/components/UsageBar.tsx +37 -18
  42. package/client/src/components/WorkflowCreator/ClusterMembersSection.tsx +29 -3
  43. package/client/src/components/WorkflowCreator/index.tsx +29 -15
  44. package/client/src/components/WorkflowView.tsx +1 -1
  45. package/client/src/components/providerIndicator.ts +7 -3
  46. package/client/src/components/research/QuickResearchOverview.tsx +7 -3
  47. package/client/src/components/research/SavedQuickKeep.tsx +7 -3
  48. package/client/src/components/settings/GitHubAuthRow.tsx +34 -0
  49. package/client/src/explorer/ArtifactsLens.tsx +17 -8
  50. package/client/src/explorer/ExplorerApp.tsx +3 -3
  51. package/client/src/explorer/types.ts +3 -1
  52. package/client/src/help/content/cluster.tsx +10 -4
  53. package/client/src/help/content/composer.tsx +3 -2
  54. package/client/src/help/content/header.tsx +6 -3
  55. package/client/src/help/content/misc.tsx +9 -7
  56. package/client/src/help/content/rightPanel.tsx +11 -6
  57. package/client/src/help/content/settings.tsx +14 -3
  58. package/client/src/help/content/tabbar.tsx +1 -1
  59. package/client/src/help/manualSections/actions.tsx +5 -1
  60. package/client/src/help/manualSections/clusters.tsx +21 -15
  61. package/client/src/help/manualSections/configuration.tsx +6 -4
  62. package/client/src/help/manualSections/gettingStarted.tsx +4 -2
  63. package/client/src/help/manualSections/maintenance.tsx +24 -0
  64. package/client/src/help/manualSections/powerFeatures.tsx +4 -2
  65. package/client/src/help/manualSections/providers.tsx +11 -4
  66. package/client/src/help/manualSections/workspace.tsx +3 -3
  67. package/client/src/hooks/useClaudeNativeCatalog.ts +26 -0
  68. package/client/src/hooks/useClaudeNativeLogin.ts +16 -11
  69. package/client/src/hooks/useWebSocket.ts +4 -2
  70. package/client/src/layout/layoutRange.ts +14 -5
  71. package/client/src/main.tsx +2 -0
  72. package/client/src/questions/waitingQuestion.ts +2 -0
  73. package/client/src/stores/appStore.ts +5 -1
  74. package/client/src/stores/appStore.types.ts +2 -0
  75. package/client/src/stores/replayContext.ts +20 -0
  76. package/client/src/utils/chatFileLinks.ts +34 -3
  77. package/client/src/utils/claudeAuth.ts +9 -1
  78. package/client/src/ws/handleServerMessage.ts +11 -3
  79. package/docs/ARCHITECTURE.md +3 -3
  80. package/docs/BACKUP.md +1 -1
  81. package/docs/CHECKPOINTS.md +67 -3
  82. package/docs/CLIENT.md +11 -6
  83. package/docs/EXTENDING.md +1 -1
  84. package/docs/FEATURES.md +3 -3
  85. package/docs/GETTING_STARTED.md +5 -4
  86. package/docs/GIT_WORKBENCH.md +8 -0
  87. package/docs/GLOSSARY.md +2 -2
  88. package/docs/GOTCHAS.md +4 -4
  89. package/docs/HTTP_API.md +63 -30
  90. package/docs/OPERATIONS.md +11 -0
  91. package/docs/OPERATOR_ACTIONS.md +2 -2
  92. package/docs/OUTPUTS.md +48 -6
  93. package/docs/PERSISTENCE.md +1 -1
  94. package/docs/PRIMITIVES.md +4 -2
  95. package/docs/PROTOCOL_CLUSTER.md +12 -6
  96. package/docs/PROTOCOL_PRIMITIVES.md +1 -1
  97. package/docs/PROVIDERS.md +47 -10
  98. package/docs/RESEARCH.md +3 -3
  99. package/docs/SETTINGS.md +9 -4
  100. package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +15 -3
  101. package/node_modules/@arco/shared/dist/protocol/clusters.js +1 -1
  102. package/node_modules/@arco/shared/dist/protocol/models.d.ts +6 -1
  103. package/node_modules/@arco/shared/dist/protocol/operatorQuestions.d.ts +2 -1
  104. package/node_modules/@arco/shared/dist/protocol/settings.d.ts +3 -0
  105. package/node_modules/@arco/shared/dist/protocol/settings.js +5 -0
  106. package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
  107. package/node_modules/@arco/shared/dist/protocol/workflows.js +0 -2
  108. package/node_modules/@arco/shared/package.json +1 -1
  109. package/package.json +2 -2
  110. package/scripts/packaging/services.mjs +20 -1
  111. package/scripts/packaging/update.mjs +37 -2
  112. package/server/dist/attention.d.ts +6 -0
  113. package/server/dist/attention.js +6 -0
  114. package/server/dist/auth.d.ts +5 -0
  115. package/server/dist/auth.js +31 -20
  116. package/server/dist/clusterAutoTurn.d.ts +5 -1
  117. package/server/dist/clusterAutoTurn.js +31 -9
  118. package/server/dist/clusterPresets.js +3 -3
  119. package/server/dist/effortValidation.d.ts +2 -2
  120. package/server/dist/effortValidation.js +4 -4
  121. package/server/dist/explorerArtifacts.d.ts +1 -0
  122. package/server/dist/explorerArtifacts.js +12 -1
  123. package/server/dist/explorerDocs.d.ts +1 -0
  124. package/server/dist/explorerDocs.js +4 -4
  125. package/server/dist/geminiMembers.d.ts +7 -1
  126. package/server/dist/geminiMembers.js +28 -14
  127. package/server/dist/gitSnapshots.d.ts +1 -0
  128. package/server/dist/gitSnapshots.js +547 -83
  129. package/server/dist/http/clusterRoutes.js +9 -3
  130. package/server/dist/http/conversationFiles.d.ts +36 -0
  131. package/server/dist/http/conversationFiles.js +222 -0
  132. package/server/dist/http/fileBytes.d.ts +3 -0
  133. package/server/dist/http/fileBytes.js +33 -0
  134. package/server/dist/http/fileContentRoute.d.ts +2 -0
  135. package/server/dist/http/fileContentRoute.js +139 -0
  136. package/server/dist/http/fileRead.d.ts +54 -2
  137. package/server/dist/http/fileRead.js +31 -24
  138. package/server/dist/http/outputRoutes.js +14 -21
  139. package/server/dist/http/readConfinement.d.ts +0 -11
  140. package/server/dist/http/readConfinement.js +4 -30
  141. package/server/dist/http/router.js +41 -66
  142. package/server/dist/index.js +26 -12
  143. package/server/dist/management/initHubLink.js +1 -1
  144. package/server/dist/outputs.js +8 -0
  145. package/server/dist/primitives/exportContext.d.ts +2 -0
  146. package/server/dist/primitives/exportContext.js +13 -2
  147. package/server/dist/primitives/runCompare.d.ts +7 -1
  148. package/server/dist/primitives/runCompare.js +44 -20
  149. package/server/dist/project/taskLedger.js +46 -34
  150. package/server/dist/providerAccounts.d.ts +4 -0
  151. package/server/dist/providerAccounts.js +20 -1
  152. package/server/dist/providers/antigravity/artifacts.d.ts +23 -0
  153. package/server/dist/providers/antigravity/artifacts.js +140 -0
  154. package/server/dist/providers/antigravity/index.js +85 -7
  155. package/server/dist/providers/antigravity/questions.d.ts +2 -0
  156. package/server/dist/providers/antigravity/questions.js +58 -0
  157. package/server/dist/providers/claude-native/auth.d.ts +9 -8
  158. package/server/dist/providers/claude-native/auth.js +50 -58
  159. package/server/dist/providers/claude-native/authStatus.d.ts +2 -2
  160. package/server/dist/providers/claude-native/authStatus.js +9 -7
  161. package/server/dist/providers/claude-native/catalog.d.ts +6 -5
  162. package/server/dist/providers/claude-native/catalog.js +50 -39
  163. package/server/dist/providers/claude-native/oauth.d.ts +10 -9
  164. package/server/dist/providers/claude-native/oauth.js +120 -96
  165. package/server/dist/providers/claude-native/worker.d.ts +1 -0
  166. package/server/dist/providers/claude-native/worker.js +38 -23
  167. package/server/dist/providers/codex-appserver/operatorQuestions.d.ts +5 -3
  168. package/server/dist/providers/codex-appserver/operatorQuestions.js +27 -13
  169. package/server/dist/providers/codexChatBoundary.js +6 -1
  170. package/server/dist/research/quickPromotion.d.ts +3 -0
  171. package/server/dist/research/quickPromotion.js +26 -9
  172. package/server/dist/research/savedQuickPromotion.js +2 -11
  173. package/server/dist/server/broadcast.js +6 -0
  174. package/server/dist/settings.d.ts +1 -0
  175. package/server/dist/settings.js +39 -7
  176. package/server/dist/skills.js +1 -1
  177. package/server/dist/smartPickupAdapters.d.ts +1 -0
  178. package/server/dist/smartPickupAdapters.js +2 -2
  179. package/server/dist/smartPickupObserver.js +8 -5
  180. package/server/dist/thirdPartySkills.js +11 -5
  181. package/server/dist/turnChanges.d.ts +1 -1
  182. package/server/dist/turnChanges.js +5 -4
  183. package/server/dist/usage.d.ts +1 -1
  184. package/server/dist/usage.js +39 -27
  185. package/server/dist/workers/WorkerManager.d.ts +1 -0
  186. package/server/dist/workers/WorkerManager.js +1 -0
  187. package/server/dist/workers/processKill.js +37 -24
  188. package/server/dist/workflowMeta.js +2 -2
  189. package/server/dist/ws/clusterHandlers.d.ts +2 -2
  190. package/server/dist/ws/clusterHandlers.js +127 -113
  191. package/server/dist/ws/clusterMembers.d.ts +1 -1
  192. package/server/dist/ws/clusterMembers.js +34 -4
  193. package/server/dist/ws/compactHandlers.js +30 -14
  194. package/server/dist/ws/compareHandlers.js +53 -21
  195. package/server/dist/ws/gateHandlers.js +2 -0
  196. package/server/dist/ws/genesisHandlers.js +5 -3
  197. package/server/dist/ws/handoffHandlers.d.ts +1 -1
  198. package/server/dist/ws/handoffHandlers.js +115 -39
  199. package/server/dist/ws/transcriptWorkerHandlers.js +7 -2
  200. package/server/dist/ws/turnEngine.js +37 -19
  201. package/server/dist/ws/updatePrimaryConfig.d.ts +3 -2
  202. package/server/dist/ws/updatePrimaryConfig.js +236 -133
  203. package/server/dist/ws/workflowHandlers.js +21 -4
  204. package/server/package.json +1 -1
  205. package/server/src/attention.ts +7 -0
  206. package/server/src/auth.ts +33 -20
  207. package/server/src/clusterAutoTurn.ts +31 -11
  208. package/server/src/clusterPresets.ts +2 -2
  209. package/server/src/effortValidation.ts +4 -4
  210. package/server/src/explorerArtifacts.ts +12 -1
  211. package/server/src/explorerDocs.ts +5 -5
  212. package/server/src/geminiMembers.ts +26 -15
  213. package/server/src/gitSnapshots.ts +538 -82
  214. package/server/src/http/clusterRoutes.ts +10 -3
  215. package/server/src/http/conversationFiles.ts +231 -0
  216. package/server/src/http/fileBytes.ts +34 -0
  217. package/server/src/http/fileContentRoute.ts +123 -0
  218. package/server/src/http/fileRead.ts +30 -25
  219. package/server/src/http/outputRoutes.ts +13 -13
  220. package/server/src/http/readConfinement.ts +3 -30
  221. package/server/src/http/router.ts +39 -62
  222. package/server/src/index.ts +27 -18
  223. package/server/src/management/initHubLink.ts +1 -1
  224. package/server/src/outputs.ts +8 -0
  225. package/server/src/primitives/exportContext.ts +14 -2
  226. package/server/src/primitives/runCompare.ts +73 -46
  227. package/server/src/project/taskLedger.ts +47 -30
  228. package/server/src/providerAccounts.ts +20 -1
  229. package/server/src/providers/antigravity/artifacts.ts +121 -0
  230. package/server/src/providers/antigravity/index.ts +64 -6
  231. package/server/src/providers/antigravity/questions.ts +52 -0
  232. package/server/src/providers/claude-native/auth.ts +45 -60
  233. package/server/src/providers/claude-native/authStatus.ts +9 -8
  234. package/server/src/providers/claude-native/catalog.ts +52 -35
  235. package/server/src/providers/claude-native/oauth.ts +101 -77
  236. package/server/src/providers/claude-native/worker.ts +38 -22
  237. package/server/src/providers/codex-appserver/operatorQuestions.ts +26 -12
  238. package/server/src/providers/codexChatBoundary.ts +6 -1
  239. package/server/src/research/quickPromotion.ts +24 -6
  240. package/server/src/research/savedQuickPromotion.ts +2 -8
  241. package/server/src/server/broadcast.ts +4 -0
  242. package/server/src/settings.ts +36 -8
  243. package/server/src/skills.ts +1 -1
  244. package/server/src/smartPickupAdapters.ts +3 -2
  245. package/server/src/smartPickupObserver.ts +8 -5
  246. package/server/src/thirdPartySkills.ts +11 -5
  247. package/server/src/turnChanges.ts +5 -4
  248. package/server/src/usage.ts +30 -22
  249. package/server/src/workers/WorkerManager.ts +2 -0
  250. package/server/src/workers/processKill.ts +37 -23
  251. package/server/src/workflowMeta.ts +2 -2
  252. package/server/src/ws/clusterHandlers.ts +107 -104
  253. package/server/src/ws/clusterMembers.ts +25 -6
  254. package/server/src/ws/compactHandlers.ts +29 -15
  255. package/server/src/ws/compareHandlers.ts +59 -25
  256. package/server/src/ws/gateHandlers.ts +2 -0
  257. package/server/src/ws/genesisHandlers.ts +5 -4
  258. package/server/src/ws/handoffHandlers.ts +105 -37
  259. package/server/src/ws/transcriptWorkerHandlers.ts +6 -2
  260. package/server/src/ws/turnEngine.ts +36 -18
  261. package/server/src/ws/updatePrimaryConfig.ts +230 -132
  262. package/server/src/ws/workflowHandlers.ts +20 -4
  263. package/shared/dist/protocol/clusters.d.ts +15 -3
  264. package/shared/dist/protocol/clusters.js +1 -1
  265. package/shared/dist/protocol/models.d.ts +6 -1
  266. package/shared/dist/protocol/operatorQuestions.d.ts +2 -1
  267. package/shared/dist/protocol/settings.d.ts +3 -0
  268. package/shared/dist/protocol/settings.js +5 -0
  269. package/shared/dist/protocol/workflows.d.ts +1 -0
  270. package/shared/dist/protocol/workflows.js +0 -2
  271. package/shared/src/protocol/clusters.ts +23 -5
  272. package/shared/src/protocol/compare.ts +2 -2
  273. package/shared/src/protocol/models.ts +8 -4
  274. package/shared/src/protocol/operatorQuestions.ts +2 -1
  275. package/shared/src/protocol/settings.ts +8 -1
  276. package/shared/src/protocol/workflows.ts +1 -1
@@ -5,7 +5,10 @@ import { send, broadcastWorkflow, broadcastTransient } from '../server/broadcast
5
5
  import { workflows } from '../server/state.js';
6
6
  import { capGoal } from '../providers/goalBlock.js';
7
7
  import { normalizeGoalRunArm } from '../goalRun.js';
8
- import { deriveAutoFold, deriveAutoHandoff, startSessionWatcher } from './turnEngine.js';
8
+ import { claimBusy, deriveAutoFold, deriveAutoHandoff, drainQueueIfIdle, releaseBusy, startSessionWatcher } from './turnEngine.js';
9
+ import { requireClaudeNativeAccount } from '../providerAccounts.js';
10
+ import { effectiveClaudeTransport } from '../claudeTransport.js';
11
+ import { readSettings } from '../settings.js';
9
12
  import { updateMeta } from '../workflowMeta.js';
10
13
  import { withFileLock } from '../atomicFile.js';
11
14
  import { disposeProviderResources } from '../providers/index.js';
@@ -13,99 +16,198 @@ import { refreshHubReporting } from '../management/initHubLink.js';
13
16
  import { buildPinnedSkillsBlock, resolvePinnedSkills, isValidSlug } from '../skills.js';
14
17
  import { withClusterSkillLock } from '../clusterStore.js';
15
18
  import { assertWorkflowSkillPins, uniqueSkillRefs } from '../clusterSkills.js';
16
- export async function handleUpdatePrimaryConfig(ws, session, msg) {
17
- const wf = workflows.get(msg.workflowId);
18
- if (!wf) {
19
- send(ws, { type: 'error', message: `Unknown workflow ${msg.workflowId.slice(0, 8)}` });
20
- return;
21
- }
22
- const proposedModel = msg.model ?? wf.primary.model;
23
- const allowedEfforts = allowedWorkflowEfforts(wf.primary.provider, proposedModel);
19
+ // STOP must not release an in-flight account save and let a new turn race it.
20
+ const updatingNativeAccount = new WeakSet();
21
+ export function isUpdatingNativeAccount(wf) {
22
+ return updatingNativeAccount.has(wf);
23
+ }
24
+ export async function handleUpdatePrimaryConfig(ws, _session, msg) {
25
+ await withFileLock(`primary-config:${msg.workflowId}`, async () => {
26
+ const wf = workflows.get(msg.workflowId);
27
+ if (!wf) {
28
+ send(ws, { type: 'error', message: `Unknown workflow ${msg.workflowId.slice(0, 8)}` });
29
+ return;
30
+ }
31
+ const update = (account) => {
32
+ const apply = () => applyPrimaryConfig(ws, wf, msg, account);
33
+ // Keep pin validation and publication under the cluster's pin lock.
34
+ return msg.pinnedSkills !== undefined ? withClusterSkillLock(msg.workflowId, apply) : apply();
35
+ };
36
+ if (msg.providerAccountRef === undefined || wf.primary.provider !== 'claude') {
37
+ await update();
38
+ return;
39
+ }
40
+ let token;
41
+ try {
42
+ if (typeof msg.providerAccountRef !== 'string' || !msg.providerAccountRef)
43
+ throw new Error('Choose a Claude Native account.');
44
+ if (wf.busy)
45
+ throw new Error('Wait for the current turn to finish before changing its account.');
46
+ token = claimBusy(wf, false);
47
+ updatingNativeAccount.add(wf);
48
+ const account = await requireClaudeNativeAccount(msg.providerAccountRef);
49
+ const settings = await readSettings(wf.config.workingDirectory);
50
+ if (effectiveClaudeTransport({ ...wf.config, claudeTransport: msg.claudeTransport ?? wf.config.claudeTransport, ultracode: msg.ultracode ?? wf.config.ultracode }, settings) !== 'native') {
51
+ throw new Error('Choose Claude Native before changing its account.');
52
+ }
53
+ if (workflows.get(msg.workflowId) !== wf)
54
+ return;
55
+ await update(account);
56
+ }
57
+ catch (err) {
58
+ send(ws, { type: 'error', workflowId: msg.workflowId, message: err instanceof Error ? err.message : 'Could not select the Claude Native account.' });
59
+ if (!wf.bootMaterialized)
60
+ broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config: wf.config });
61
+ }
62
+ finally {
63
+ if (token !== undefined) {
64
+ updatingNativeAccount.delete(wf);
65
+ if (releaseBusy(wf, token, 'finished', false) && workflows.get(msg.workflowId) === wf) {
66
+ void drainQueueIfIdle(msg.workflowId);
67
+ }
68
+ }
69
+ }
70
+ });
71
+ }
72
+ async function applyPrimaryConfig(ws, wf, msg, nativeAccount) {
73
+ // A Native account switch publishes the account and all accompanying edits
74
+ // only after validation and the single metadata write have succeeded.
75
+ const config = nativeAccount === undefined
76
+ ? wf.config
77
+ : { ...wf.config, providerAccountRef: nativeAccount, claudeTransport: 'native' };
78
+ const primary = nativeAccount === undefined ? wf.primary : { ...wf.primary };
79
+ const proposedModel = msg.model ?? primary.model;
80
+ const allowedEfforts = allowedWorkflowEfforts(primary.provider, proposedModel, config.providerAccountRef);
24
81
  if (msg.effort !== undefined && !allowedEfforts.includes(msg.effort)) {
25
- const label = wf.primary.provider === 'claude' ? 'Claude' : 'Provider';
26
- send(ws, { type: 'error', workflowId: msg.workflowId,
27
- message: `${label} effort must be ${allowedEfforts.join(', ')}; no settings were changed.` });
82
+ const label = primary.provider === 'claude' ? 'Claude' : 'Provider';
83
+ const message = `${label} effort must be ${allowedEfforts.join(', ')}; no settings were changed.`;
84
+ if (nativeAccount !== undefined)
85
+ throw new Error(message);
86
+ send(ws, { type: 'error', workflowId: msg.workflowId, message });
28
87
  return;
29
88
  }
30
- if (msg.model !== undefined && msg.effort === undefined) {
31
- const next = normalizedWorkflowEffort(wf.primary.provider, proposedModel, wf.primary.effort);
32
- if (next !== wf.primary.effort)
89
+ if ((msg.model !== undefined || nativeAccount !== undefined) && msg.effort === undefined) {
90
+ const next = normalizedWorkflowEffort(primary.provider, proposedModel, primary.effort, config.providerAccountRef);
91
+ if (next !== primary.effort)
33
92
  msg = { ...msg, effort: next };
34
93
  }
35
- const proposedGoal = msg.goal === undefined ? wf.config.goal : capGoal(msg.goal);
94
+ const proposedGoal = msg.goal === undefined ? config.goal : capGoal(msg.goal);
36
95
  const proposedGoalRun = msg.goalRun === undefined ? undefined : normalizeGoalRunArm(msg.goalRun, !!proposedGoal?.trim());
37
96
  if (typeof proposedGoalRun === 'string') {
97
+ if (nativeAccount !== undefined)
98
+ throw new Error(proposedGoalRun);
38
99
  send(ws, { type: 'error', workflowId: msg.workflowId, message: proposedGoalRun });
39
100
  return;
40
101
  }
41
102
  if (msg.autoCompaction !== undefined && msg.autoCompaction !== null && !isAutoCompactionPolicy(msg.autoCompaction)) {
42
- send(ws, { type: 'error', message: 'Auto-compaction requires a boolean and an integer threshold from 30 to 95.' });
103
+ const message = 'Auto-compaction requires a boolean and an integer threshold from 30 to 95.';
104
+ if (nativeAccount !== undefined)
105
+ throw new Error(message);
106
+ send(ws, { type: 'error', message });
43
107
  if (!wf.bootMaterialized)
44
- broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config: wf.config });
108
+ broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config });
45
109
  return;
46
110
  }
47
- if (msg.autoCompaction !== undefined) {
111
+ const previousCompaction = config.autoCompaction;
112
+ if (msg.autoCompaction !== undefined && nativeAccount !== undefined) {
113
+ config.autoCompaction = msg.autoCompaction === null ? undefined : { ...msg.autoCompaction };
114
+ }
115
+ else if (msg.autoCompaction !== undefined) {
48
116
  const saved = await withFileLock(`auto-compaction:${msg.workflowId}`, async () => {
49
117
  const next = msg.autoCompaction === null ? undefined : { ...msg.autoCompaction };
50
- const previous = wf.config.autoCompaction;
118
+ const previous = config.autoCompaction;
51
119
  const changed = next?.enabled !== previous?.enabled || next?.thresholdPercent !== previous?.thresholdPercent;
52
120
  if (!changed)
53
121
  return true;
54
- if (wf.config.workingDirectory && !wf.config.incognito) {
122
+ if (config.workingDirectory && !config.incognito) {
55
123
  try {
56
- const updated = await updateMeta(wf.config.workingDirectory, msg.workflowId, (meta) => { meta.autoCompaction = next; });
124
+ const updated = await updateMeta(config.workingDirectory, msg.workflowId, (meta) => { meta.autoCompaction = next; });
57
125
  if (!updated)
58
126
  throw new Error('workflow metadata unavailable');
59
127
  }
60
128
  catch {
61
129
  send(ws, { type: 'error', workflowId: msg.workflowId, message: 'Could not save auto-compaction policy; the previous policy remains active.' });
62
130
  if (!wf.bootMaterialized)
63
- broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config: wf.config });
131
+ broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config });
64
132
  return false;
65
133
  }
66
134
  }
67
- wf.config.autoCompaction = next;
68
- broadcastWorkflow(msg.workflowId, { type: 'system_notice', workflowId: msg.workflowId,
69
- content: next ? `[AUTO-COMPACT] Worker policy ${next.enabled ? `enabled at ${next.thresholdPercent}%` : 'disabled'}.` : '[AUTO-COMPACT] Worker policy cleared; cluster or legacy behavior applies.' });
135
+ config.autoCompaction = next;
136
+ announceAutoCompaction(msg.workflowId, next);
70
137
  return true;
71
138
  });
72
139
  if (!saved)
73
140
  return;
74
141
  }
142
+ // Standing skill pins are a whole-set replacement. Resolve before persisting
143
+ // so malformed / missing references never become durable config, and report
144
+ // current prompt bytes for cost visibility. Bodies remain on disk and are
145
+ // re-read at every turn; this snapshot is only the pin acknowledgement.
146
+ let pinnedSkillsBroadcast;
147
+ if (msg.pinnedSkills !== undefined) {
148
+ const requested = uniqueSkillRefs((Array.isArray(msg.pinnedSkills) ? msg.pinnedSkills : []).filter(ref => ref && (ref.scope === 'project' || ref.scope === 'global') && isValidSlug(ref.slug)));
149
+ let resolved;
150
+ try {
151
+ await assertWorkflowSkillPins(msg.workflowId, config.workingDirectory, requested);
152
+ resolved = await resolvePinnedSkills(requested, config.workingDirectory);
153
+ const refs = resolved.skills.map(s => ({ scope: s.scope, slug: s.slug }));
154
+ if (refs.length)
155
+ config.pinnedSkills = refs;
156
+ else
157
+ delete config.pinnedSkills;
158
+ }
159
+ catch (err) {
160
+ if (nativeAccount !== undefined)
161
+ throw err;
162
+ send(ws, { type: 'error', workflowId: msg.workflowId, message: err instanceof Error ? err.message : String(err) });
163
+ return;
164
+ }
165
+ const block = buildPinnedSkillsBlock(resolved.skills);
166
+ pinnedSkillsBroadcast = {
167
+ skills: resolved.skills.map((s) => ({ scope: s.scope, slug: s.slug, name: s.name })),
168
+ bytes: block.bytes,
169
+ missing: [...resolved.missing, ...resolved.truncated],
170
+ };
171
+ }
75
172
  if (msg.model !== undefined)
76
- wf.primary.model = msg.model;
173
+ primary.model = msg.model;
77
174
  if (msg.effort !== undefined)
78
- wf.primary.effort = msg.effort;
79
- if (msg.providerAccountRef !== undefined) {
175
+ primary.effort = msg.effort;
176
+ if (msg.providerAccountRef !== undefined && nativeAccount === undefined) {
80
177
  if (wf.busy) {
81
178
  send(ws, { type: 'error', message: 'Cannot change account profile while a turn is running.' });
82
179
  return;
83
180
  }
84
- wf.config.providerAccountRef = msg.providerAccountRef || undefined;
181
+ config.providerAccountRef = msg.providerAccountRef || undefined;
85
182
  disposeProviderResources(msg.workflowId);
86
183
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] provider.account updated → ${msg.providerAccountRef || 'default'}`);
87
184
  }
88
- // Update the auto-handoff config. Mirrors into wf.config so the client
185
+ // Update the auto-handoff config. Mirrors into config so the client
89
186
  // receives the updated config on next rehydrate. The compaction count of
90
187
  // the current conversation is kept: lowering N to or below it hands off at
91
188
  // the next turn boundary. A malformed value is ignored. The 0.1.4
92
189
  // percentages the tab already has are kept when the update leaves them out.
93
- const previous = wf.config.autoHandoff;
190
+ const previous = config.autoHandoff;
94
191
  const raw = msg.autoHandoff;
95
192
  const autoHandoff = raw === undefined ? undefined
96
193
  : normalizeAutoHandoff(raw && typeof raw === 'object' ? { warnAt: previous?.warnAt, autoAt: previous?.autoAt, ...raw } : raw);
97
- if (autoHandoff) {
98
- wf.config.autoHandoff = autoHandoff;
99
- const live = deriveAutoHandoff(wf.config);
194
+ const applyAutoHandoff = () => {
195
+ const live = deriveAutoHandoff(config);
100
196
  wf.autoHandoff = { ...live, compactions: wf.autoHandoff?.compactions ?? 0, session: wf.autoHandoff?.session, fired: wf.autoHandoff?.fired ?? false };
101
- console.log(`[arco] [${msg.workflowId.slice(0, 8)}] auto-handoff updated → enabled=${autoHandoff.enabled} after=${live.afterCompactions} compactions`);
197
+ };
198
+ if (autoHandoff) {
199
+ config.autoHandoff = autoHandoff;
200
+ if (nativeAccount === undefined)
201
+ applyAutoHandoff();
202
+ console.log(`[arco] [${msg.workflowId.slice(0, 8)}] auto-handoff updated → enabled=${autoHandoff.enabled} after=${autoHandoff.afterCompactions} compactions`);
102
203
  }
103
204
  // §2.1 — auto-fold config. Mirror into the live state (deriveAutoFold carries
104
205
  // the runtime fired/anti-thrash counters) so the next post-turn check honors
105
206
  // it without a reload.
106
207
  if (msg.autoFold !== undefined) {
107
- wf.config.autoFold = { ...msg.autoFold };
108
- wf.autoFold = deriveAutoFold(wf.config);
208
+ config.autoFold = { ...msg.autoFold };
209
+ if (nativeAccount === undefined)
210
+ wf.autoFold = deriveAutoFold(config);
109
211
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] auto-fold updated → enabled=${msg.autoFold.enabled} foldAt=${msg.autoFold.foldAt}%`);
110
212
  }
111
213
  // docs/GOTCHAS.md - arm / re-arm / disarm the north-star auto-continue.
@@ -116,10 +218,10 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
116
218
  if (msg.goalRun !== undefined) {
117
219
  const next = proposedGoalRun;
118
220
  if (next.enabled) {
119
- wf.config.goalRun = next;
221
+ config.goalRun = next;
120
222
  }
121
223
  else {
122
- delete wf.config.goalRun;
224
+ delete config.goalRun;
123
225
  }
124
226
  goalRunBroadcast = next;
125
227
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] goal run ${next.enabled ? `armed → ${next.total} iteration(s)` : 'disarmed'}`);
@@ -128,7 +230,7 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
128
230
  // read it) so the toggle survives a provider swap on the same tab. Takes
129
231
  // effect on the next message — each turn recomputes chatWebArmed().
130
232
  if (msg.chatWebAccess !== undefined) {
131
- wf.config.chatWebAccess = msg.chatWebAccess;
233
+ config.chatWebAccess = msg.chatWebAccess;
132
234
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] chat.web updated → ${msg.chatWebAccess ? 'armed' : 'off'}`);
133
235
  }
134
236
  // Phase 6e — per-tab Codex transport. handleUserMessage prefers this over
@@ -137,45 +239,27 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
137
239
  // provider so a Handoff that swaps from claude→codex on the same tab still
138
240
  // sees the operator's pinned choice.
139
241
  if (msg.codexTransport !== undefined) {
140
- wf.config.codexTransport = msg.codexTransport;
242
+ config.codexTransport = msg.codexTransport;
141
243
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] codex.transport updated → ${msg.codexTransport}`);
142
244
  }
143
245
  if (msg.codexContextPolicy !== undefined) {
144
- wf.config.codexContextPolicy = msg.codexContextPolicy;
246
+ config.codexContextPolicy = msg.codexContextPolicy;
145
247
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] codex.context updated → ${msg.codexContextPolicy}`);
146
248
  }
147
249
  // Phase 7a — same shape for Claude. Honored only on Claude tabs but written
148
250
  // unconditionally so a Handoff that swaps from codex→claude on the same
149
251
  // tab still sees the operator's pinned choice.
150
- if (msg.claudeTransport !== undefined) {
151
- wf.config.claudeTransport = msg.claudeTransport;
152
- // The CLI-session JSONL watcher is CLI-transport-only (a Native tab's
153
- // transcript truth is events.jsonl; watching a stale CLI file painted
154
- // calibration-probe entries over real answers). A live
155
- // swap must move the watcher NOW, not at the next restart: stop it on the
156
- // native direction, (re)start it on the cli direction — nothing on the
157
- // normal turn path starts it (only create/rehydrate and handoff rotation
158
- // do), so without this a cli→native→cli round trip leaves it dead.
159
- if (msg.claudeTransport === 'native') {
160
- if (wf.sessionWatcher) {
161
- try {
162
- wf.sessionWatcher();
163
- }
164
- catch { /* already disposed */ }
165
- wf.sessionWatcher = null;
166
- }
167
- }
168
- else if (wf.config.workingDirectory) {
169
- startSessionWatcher(msg.workflowId, wf, wf.config.workingDirectory, ws);
170
- }
252
+ if (msg.claudeTransport !== undefined && nativeAccount === undefined) {
253
+ config.claudeTransport = msg.claudeTransport;
254
+ applyClaudeTransportWatcher(ws, msg.workflowId, wf);
171
255
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] claude.transport updated → ${msg.claudeTransport}`);
172
256
  }
173
257
  // docs/PROVIDERS.md - sticky ultracode toggle. We deliberately do NOT mutate
174
- // wf.config.claudeTransport here: turnEngine forces 'cli' at turn time while
258
+ // config.claudeTransport here: turnEngine forces 'cli' at turn time while
175
259
  // this is on, so the stored base transport stays intact and restores itself
176
260
  // when ultracode flips off. Takes effect on the next turn; reversible.
177
261
  if (msg.ultracode !== undefined) {
178
- wf.config.ultracode = msg.ultracode;
262
+ config.ultracode = msg.ultracode;
179
263
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] ultracode → ${msg.ultracode ? 'ON (CLI + Workflow + xhigh forced next turn)' : 'OFF'}`);
180
264
  }
181
265
  // Per-tab Claude Native web budget (server-tool max_uses). Clamp to a sane
@@ -183,74 +267,74 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
183
267
  // posture picker is for — keep at least 1. Takes effect next turn.
184
268
  if (msg.webSearchMaxUses !== undefined) {
185
269
  const clamped = Math.max(1, Math.min(50, Math.round(msg.webSearchMaxUses)));
186
- wf.config.webSearchMaxUses = clamped;
270
+ config.webSearchMaxUses = clamped;
187
271
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] web search budget → ${clamped}/turn`);
188
272
  }
189
273
  // Phase 7c-followup — Claude Native server-side compaction. Honored on
190
274
  // Native tabs only, but stored unconditionally so a transport flip
191
275
  // back to Native picks up the operator's last pinned value.
192
276
  if (msg.claudeNativeCompact !== undefined) {
193
- wf.config.claudeNativeCompact = msg.claudeNativeCompact;
277
+ config.claudeNativeCompact = msg.claudeNativeCompact;
194
278
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] claude.native.compact updated → ${msg.claudeNativeCompact}`);
195
279
  }
196
280
  if (msg.claudeNativeForceInterleavedThinkingBeta !== undefined) {
197
- wf.config.claudeNativeForceInterleavedThinkingBeta = msg.claudeNativeForceInterleavedThinkingBeta;
281
+ config.claudeNativeForceInterleavedThinkingBeta = msg.claudeNativeForceInterleavedThinkingBeta;
198
282
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] claude.native.force-interleaved-beta updated → ${msg.claudeNativeForceInterleavedThinkingBeta}`);
199
283
  }
200
284
  // Native Task defaults are captured at the next parent turn.
201
285
  if (msg.nativeSubagents !== undefined) {
202
286
  if (msg.nativeSubagents === null)
203
- delete wf.config.nativeSubagents;
287
+ delete config.nativeSubagents;
204
288
  else
205
- wf.config.nativeSubagents = sanitizeNativeSubagents(msg.nativeSubagents);
289
+ config.nativeSubagents = sanitizeNativeSubagents(msg.nativeSubagents);
206
290
  }
207
291
  // Adaptive-thinking display. Stored unconditionally so a CLI→Native
208
292
  // transport flip picks up the operator's last pinned value; only the
209
293
  // Native worker's buildThinkingParams reads it. Takes effect next turn.
210
294
  if (msg.claudeNativeThinkingDisplay !== undefined) {
211
- wf.config.claudeNativeThinkingDisplay = msg.claudeNativeThinkingDisplay;
295
+ config.claudeNativeThinkingDisplay = msg.claudeNativeThinkingDisplay;
212
296
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] claude.native.thinking-display updated → ${msg.claudeNativeThinkingDisplay}`);
213
297
  }
214
298
  // NATIVE_COMPACTION_PLAN Phase 3 — opt-in auto-continue after compaction.
215
299
  // Stored unconditionally so a transport flip back to Native picks up the
216
300
  // operator's last pinned value; only the Native compaction paths read it.
217
301
  if (msg.nativeCompactAutoContinue !== undefined) {
218
- wf.config.nativeCompactAutoContinue = msg.nativeCompactAutoContinue;
302
+ config.nativeCompactAutoContinue = msg.nativeCompactAutoContinue;
219
303
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] native.compact.auto-continue updated → ${msg.nativeCompactAutoContinue}`);
220
304
  }
221
305
  // docs/PROVIDERS.md - Native tool-result filter mode. Stored
222
306
  // unconditionally so a CLI→Native transport flip picks up the operator's
223
307
  // last pinned value; only honored on Native turns at handleUserMessage.
224
308
  if (msg.efficiencyToolFilter !== undefined) {
225
- wf.config.efficiencyToolFilter = msg.efficiencyToolFilter;
309
+ config.efficiencyToolFilter = msg.efficiencyToolFilter;
226
310
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] efficiency.tool-filter updated → ${msg.efficiencyToolFilter}`);
227
311
  }
228
312
  // docs/PROVIDERS.md - fact-force first-edit gate. Stored
229
313
  // unconditionally so a CLI→Native transport flip picks up the operator's
230
314
  // last pinned value; only honored on Native turns at handleUserMessage.
231
315
  if (msg.efficiencyFactForce !== undefined) {
232
- wf.config.efficiencyFactForce = msg.efficiencyFactForce;
316
+ config.efficiencyFactForce = msg.efficiencyFactForce;
233
317
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] efficiency.fact-force updated → ${msg.efficiencyFactForce}`);
234
318
  }
235
319
  // Config-protection write-gate. Stored unconditionally so a CLI→Native
236
320
  // transport flip picks up the operator's last pinned value; only honored
237
321
  // on Native turns (the gate lives in the Native worker's dispatchTool).
238
322
  if (msg.efficiencyConfigProtection !== undefined) {
239
- wf.config.efficiencyConfigProtection = msg.efficiencyConfigProtection;
323
+ config.efficiencyConfigProtection = msg.efficiencyConfigProtection;
240
324
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] efficiency.config-protection updated → ${msg.efficiencyConfigProtection}`);
241
325
  }
242
326
  // docs/PROVIDERS.md - opt-in sandbox tools. Stored
243
327
  // unconditionally so a CLI→Native flip picks up the last pinned
244
328
  // value; honored only on Native turns at handleUserMessage.
245
329
  if (msg.efficiencySandbox !== undefined) {
246
- wf.config.efficiencySandbox = msg.efficiencySandbox;
330
+ config.efficiencySandbox = msg.efficiencySandbox;
247
331
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] efficiency.sandbox updated → ${msg.efficiencySandbox}`);
248
332
  }
249
333
  // docs/PROVIDERS.md - operator-armed durable review gate. Stored unconditionally
250
334
  // so a transport flip picks up the last pinned value; honored only on Native
251
335
  // turns (the gate lives in the Native worker's dispatchTool).
252
336
  if (msg.reviewSafeMode !== undefined) {
253
- wf.config.reviewSafeMode = msg.reviewSafeMode;
337
+ config.reviewSafeMode = msg.reviewSafeMode;
254
338
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] review-safe-mode updated → ${msg.reviewSafeMode}`);
255
339
  }
256
340
  // docs/PROVIDERS.md - operator-armed terseness picker. Stored
@@ -260,12 +344,12 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
260
344
  // so 0.1.4 never reads a value it does not know.
261
345
  const outputStyle = msg.outputStyle !== undefined ? normalizeOutputStyle(msg.outputStyle) : undefined;
262
346
  if (outputStyle) {
263
- wf.config.outputStyle = outputStyle;
347
+ config.outputStyle = outputStyle;
264
348
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] output-style updated → ${outputStyle}`);
265
349
  }
266
350
  // docs/GOTCHAS.md - operator-set persistent north-star. Trim + byte-cap;
267
351
  // empty / whitespace-only ⇒ clear (delete the field so pre-feature meta.json
268
- // stays byte-clean). We mutate wf.config now (the next turn reads it) but DEFER
352
+ // stays byte-clean). We mutate config now (the next turn reads it) but DEFER
269
353
  // the goal_set broadcast until AFTER the meta.json write below — persist-then-
270
354
  // announce, so "goal_set observed ⇒ value already durable" holds and a client
271
355
  // (or the smoke) that reads meta.json on the event never races the disk write.
@@ -275,56 +359,25 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
275
359
  if (msg.goal !== undefined) {
276
360
  const capped = capGoal(msg.goal);
277
361
  if (capped)
278
- wf.config.goal = capped;
362
+ config.goal = capped;
279
363
  else
280
- delete wf.config.goal;
364
+ delete config.goal;
281
365
  goalBroadcast = { goal: capped || null, byteLen: capped ? Buffer.byteLength(capped, 'utf8') : 0 };
282
366
  }
283
- // Standing skill pins are a whole-set replacement. Resolve before persisting
284
- // so malformed / missing references never become durable config, and report
285
- // current prompt bytes for cost visibility. Bodies remain on disk and are
286
- // re-read at every turn; this snapshot is only the pin acknowledgement.
287
- let pinnedSkillsBroadcast;
288
- if (msg.pinnedSkills !== undefined) {
289
- const requested = uniqueSkillRefs((Array.isArray(msg.pinnedSkills) ? msg.pinnedSkills : []).filter(ref => ref && (ref.scope === 'project' || ref.scope === 'global') && isValidSlug(ref.slug)));
290
- let resolved;
291
- try {
292
- resolved = await withClusterSkillLock(msg.workflowId, async () => {
293
- await assertWorkflowSkillPins(msg.workflowId, wf.config.workingDirectory, requested);
294
- const result = await resolvePinnedSkills(requested, wf.config.workingDirectory);
295
- const refs = result.skills.map(s => ({ scope: s.scope, slug: s.slug }));
296
- if (refs.length)
297
- wf.config.pinnedSkills = refs;
298
- else
299
- delete wf.config.pinnedSkills;
300
- return result;
301
- });
302
- }
303
- catch (err) {
304
- send(ws, { type: 'error', workflowId: msg.workflowId, message: err instanceof Error ? err.message : String(err) });
305
- return;
306
- }
307
- const block = buildPinnedSkillsBlock(resolved.skills);
308
- pinnedSkillsBroadcast = {
309
- skills: resolved.skills.map((s) => ({ scope: s.scope, slug: s.slug, name: s.name })),
310
- bytes: block.bytes,
311
- missing: [...resolved.missing, ...resolved.truncated],
312
- };
313
- }
314
367
  // REMOTE_MANAGEMENT.md §1.4 — per-workflow hub opt-in (`REMOTE CONTINUATION`).
315
368
  // Default OFF. Flipping it re-pushes the hub snapshot + re-broadcasts
316
369
  // hub_link_status below so the VPS console and the header monitored-count
317
370
  // update immediately.
318
371
  let remoteEnabledChanged = false;
319
- if (msg.remoteEnabled !== undefined && msg.remoteEnabled !== wf.config.remoteEnabled) {
320
- wf.config.remoteEnabled = msg.remoteEnabled;
372
+ if (msg.remoteEnabled !== undefined && msg.remoteEnabled !== config.remoteEnabled) {
373
+ config.remoteEnabled = msg.remoteEnabled;
321
374
  remoteEnabledChanged = true;
322
375
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] remote-enabled updated → ${msg.remoteEnabled}`);
323
376
  }
324
377
  // R1 §9.2 — remote-gates arming shares remoteEnabled's re-push semantics so
325
378
  // the console's gate buttons track the flip without waiting for the 4s tick.
326
- if (msg.remoteGatesEnabled !== undefined && msg.remoteGatesEnabled !== wf.config.remoteGatesEnabled) {
327
- wf.config.remoteGatesEnabled = msg.remoteGatesEnabled;
379
+ if (msg.remoteGatesEnabled !== undefined && msg.remoteGatesEnabled !== config.remoteGatesEnabled) {
380
+ config.remoteGatesEnabled = msg.remoteGatesEnabled;
328
381
  remoteEnabledChanged = true;
329
382
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] remote-gates updated → ${msg.remoteGatesEnabled}`);
330
383
  }
@@ -340,7 +393,7 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
340
393
  // way the effort switch is logged. The next Ollama turn re-prefills its
341
394
  // prompt (one-time cost the operator opted into).
342
395
  if (msg.ollamaParams !== undefined) {
343
- wf.config.ollamaParams = msg.ollamaParams;
396
+ config.ollamaParams = msg.ollamaParams;
344
397
  const keys = Object.keys(msg.ollamaParams).join(', ') || '(cleared)';
345
398
  console.log(`[arco] [${msg.workflowId.slice(0, 8)}] ollama.params updated → ${keys} (prefix cache invalidates next turn)`);
346
399
  }
@@ -348,12 +401,14 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
348
401
  // change; fields on WorkflowConfig and PrimaryConfig are the source of
349
402
  // truth together (derivePrimaryConfig reads from config).
350
403
  if (msg.model !== undefined)
351
- wf.config.primaryModel = msg.model;
404
+ config.primaryModel = msg.model;
352
405
  if (msg.effort !== undefined)
353
- wf.config.primaryEffort = msg.effort;
354
- const cwd = wf.config.workingDirectory;
406
+ config.primaryEffort = msg.effort;
407
+ const cwd = config.workingDirectory;
355
408
  const hasOtherConfig = Object.keys(msg).some((key) => key !== 'type' && key !== 'workflowId' && key !== 'autoCompaction');
356
- if (cwd && hasOtherConfig && !wf.config.incognito) {
409
+ if (nativeAccount !== undefined && workflows.get(msg.workflowId) !== wf)
410
+ return;
411
+ if (cwd && hasOtherConfig && !config.incognito) {
357
412
  try {
358
413
  const saved = await updateMeta(cwd, msg.workflowId, (meta) => {
359
414
  if (msg.model !== undefined)
@@ -361,7 +416,7 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
361
416
  if (msg.effort !== undefined)
362
417
  meta.primaryEffort = msg.effort;
363
418
  if (msg.providerAccountRef !== undefined)
364
- meta.providerAccountRef = msg.providerAccountRef || undefined;
419
+ meta.providerAccountRef = config.providerAccountRef;
365
420
  if (autoHandoff)
366
421
  meta.autoHandoff = { ...autoHandoff };
367
422
  if (msg.autoFold !== undefined)
@@ -370,12 +425,14 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
370
425
  meta.codexTransport = msg.codexTransport;
371
426
  if (msg.codexContextPolicy !== undefined)
372
427
  meta.codexContextPolicy = msg.codexContextPolicy;
373
- if (msg.claudeTransport !== undefined)
374
- meta.claudeTransport = msg.claudeTransport;
428
+ if (nativeAccount !== undefined || msg.claudeTransport !== undefined)
429
+ meta.claudeTransport = config.claudeTransport;
430
+ if (nativeAccount !== undefined && msg.autoCompaction !== undefined)
431
+ meta.autoCompaction = config.autoCompaction;
375
432
  if (msg.ultracode !== undefined)
376
433
  meta.ultracode = msg.ultracode;
377
434
  if (msg.webSearchMaxUses !== undefined)
378
- meta.webSearchMaxUses = wf.config.webSearchMaxUses;
435
+ meta.webSearchMaxUses = config.webSearchMaxUses;
379
436
  if (msg.chatWebAccess !== undefined)
380
437
  meta.chatWebAccess = msg.chatWebAccess;
381
438
  if (msg.claudeNativeCompact !== undefined) {
@@ -393,7 +450,7 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
393
450
  if (msg.nativeSubagents === null)
394
451
  delete meta.nativeSubagents;
395
452
  else
396
- meta.nativeSubagents = wf.config.nativeSubagents;
453
+ meta.nativeSubagents = config.nativeSubagents;
397
454
  }
398
455
  if (msg.claudeNativeThinkingDisplay !== undefined)
399
456
  meta.claudeNativeThinkingDisplay = msg.claudeNativeThinkingDisplay;
@@ -412,7 +469,7 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
412
469
  if (outputStyle)
413
470
  meta.outputStyle = storedOutputStyle(outputStyle);
414
471
  if (msg.goal !== undefined) {
415
- // Mirror the wf.config decision above: capped text persists, blank clears.
472
+ // Mirror the config decision above: capped text persists, blank clears.
416
473
  const capped = capGoal(msg.goal);
417
474
  if (capped)
418
475
  meta.goal = capped;
@@ -420,8 +477,8 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
420
477
  delete meta.goal;
421
478
  }
422
479
  if (msg.pinnedSkills !== undefined) {
423
- if (wf.config.pinnedSkills?.length) {
424
- meta.pinnedSkills = wf.config.pinnedSkills.map((s) => ({ ...s }));
480
+ if (config.pinnedSkills?.length) {
481
+ meta.pinnedSkills = config.pinnedSkills.map((s) => ({ ...s }));
425
482
  }
426
483
  else {
427
484
  delete meta.pinnedSkills;
@@ -440,16 +497,37 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
440
497
  }
441
498
  catch (err) {
442
499
  console.error(`[arco] [${msg.workflowId.slice(0, 8)}] update_primary_config meta write failed:`, err);
500
+ if (nativeAccount !== undefined) {
501
+ throw new Error('Workflow settings could not be saved. The previous account and settings are still active.');
502
+ }
443
503
  const message = 'Workflow settings could not be saved. Changes are temporary for this running tab and may be lost after restart. Retry the save when storage is available.';
444
504
  send(ws, { type: 'error', workflowId: msg.workflowId, message });
445
505
  broadcastWorkflow(msg.workflowId, { type: 'system_notice', workflowId: msg.workflowId, content: message });
446
506
  if (!wf.bootMaterialized)
447
- broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config: wf.config });
507
+ broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config });
448
508
  if (remoteEnabledChanged)
449
509
  refreshHubReporting();
450
510
  return;
451
511
  }
452
512
  }
513
+ if (nativeAccount !== undefined) {
514
+ if (workflows.get(msg.workflowId) !== wf)
515
+ return;
516
+ wf.config = config;
517
+ wf.primary = primary;
518
+ if (autoHandoff)
519
+ applyAutoHandoff();
520
+ if (msg.autoFold !== undefined)
521
+ wf.autoFold = deriveAutoFold(config);
522
+ applyClaudeTransportWatcher(ws, msg.workflowId, wf);
523
+ await disposeProviderResources(msg.workflowId).catch((err) => {
524
+ console.error('Could not dispose previous provider resources:', err);
525
+ });
526
+ if (msg.autoCompaction !== undefined && (config.autoCompaction?.enabled !== previousCompaction?.enabled
527
+ || config.autoCompaction?.thresholdPercent !== previousCompaction?.thresholdPercent)) {
528
+ announceAutoCompaction(msg.workflowId, config.autoCompaction);
529
+ }
530
+ }
453
531
  // Persist-then-announce (see the north-star note above): the meta.json write
454
532
  // is durable now, so emit the goal_set event. Storage failures return above with an explicit temporary-setting notice.
455
533
  if (goalBroadcast) {
@@ -498,8 +576,33 @@ export async function handleUpdatePrimaryConfig(ws, session, msg) {
498
576
  // config replayed after later non-config edits would regress the job; a
499
577
  // reconnecting browser takes the live config from workspace_snapshot instead.
500
578
  if (!wf.bootMaterialized) {
501
- broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config: wf.config });
579
+ broadcastTransient(msg.workflowId, { type: 'workflow_config_synced', workflowId: msg.workflowId, config });
580
+ }
581
+ console.log(`[arco] [${msg.workflowId.slice(0, 8)}] primary updated → ${primary.provider}:${primary.model}@${primary.effort}`);
582
+ }
583
+ function announceAutoCompaction(workflowId, next) {
584
+ broadcastWorkflow(workflowId, { type: 'system_notice', workflowId,
585
+ content: next ? `[AUTO-COMPACT] Worker policy ${next.enabled ? `enabled at ${next.thresholdPercent}%` : 'disabled'}.` : '[AUTO-COMPACT] Worker policy cleared; cluster or legacy behavior applies.' });
586
+ }
587
+ function applyClaudeTransportWatcher(ws, workflowId, wf) {
588
+ // The CLI-session JSONL watcher is CLI-transport-only (a Native tab's
589
+ // transcript truth is events.jsonl; watching a stale CLI file painted
590
+ // calibration-probe entries over real answers). A live
591
+ // swap must move the watcher NOW, not at the next restart: stop it on the
592
+ // native direction, (re)start it on the cli direction — nothing on the
593
+ // normal turn path starts it (only create/rehydrate and handoff rotation
594
+ // do), so without this a cli→native→cli round trip leaves it dead.
595
+ if (wf.config.claudeTransport === 'native') {
596
+ if (wf.sessionWatcher) {
597
+ try {
598
+ wf.sessionWatcher();
599
+ }
600
+ catch { /* already disposed */ }
601
+ wf.sessionWatcher = null;
602
+ }
603
+ }
604
+ else if (wf.config.workingDirectory) {
605
+ startSessionWatcher(workflowId, wf, wf.config.workingDirectory, ws);
502
606
  }
503
- console.log(`[arco] [${msg.workflowId.slice(0, 8)}] primary updated → ${wf.primary.provider}:${wf.primary.model}@${wf.primary.effort}`);
504
607
  }
505
608
  //# sourceMappingURL=updatePrimaryConfig.js.map