arco-workbench 0.2.4 → 0.2.5

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