arco-workbench 0.1.4 → 0.1.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.
- package/CONTRIBUTING.md +40 -8
- package/README.md +35 -21
- package/THIRD_PARTY_NOTICES +789 -0
- package/client/dist/assets/{PhosphorBackdrop-CNumba2X.js → PhosphorBackdrop-D6cbmLNY.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-DX5KyCt3.js → ThemedBackgroundShaderImpl-2dyerOi4.js} +1 -1
- package/client/dist/assets/{XtermView-DhS5g8Rt.js → XtermView-AIwo7O3D.js} +2 -2
- package/client/dist/assets/galleryEditor-DXAuxS8D.js +702 -0
- package/client/dist/assets/index-8j6p-pmQ.js +610 -0
- package/client/dist/assets/index-DD9kFGsF.css +1 -0
- package/client/dist/index.html +2 -2
- package/client/src/App.tsx +44 -55
- package/client/src/alerts/desktopAlerts.ts +20 -12
- package/client/src/alerts/desktopTest.ts +68 -0
- package/client/src/alerts/focusNotice.ts +16 -0
- package/client/src/buildCheck.ts +42 -2
- package/client/src/components/ArchitectureReviewDialog.tsx +98 -0
- package/client/src/components/ArtifactModal.tsx +4 -6
- package/client/src/components/ArtifactMoveDialog.tsx +11 -7
- package/client/src/components/AskUserQuestionNotice.tsx +2 -1
- package/client/src/components/AutomaticMessage.tsx +19 -0
- package/client/src/components/BriefControl.tsx +4 -2
- package/client/src/components/BrowserNotice.tsx +35 -0
- package/client/src/components/CatchMeUp.tsx +12 -6
- package/client/src/components/ChatMessage.tsx +15 -4
- package/client/src/components/ChatModeView.tsx +23 -16
- package/client/src/components/ChatPanel.tsx +33 -5
- package/client/src/components/CheckpointActions.tsx +91 -26
- package/client/src/components/ClusterActivityTab.tsx +4 -2
- package/client/src/components/ClusterMemberPicker.tsx +6 -3
- package/client/src/components/ClusterPlanTab.tsx +93 -62
- package/client/src/components/ClusterRightPanel/AddWorkerSection.tsx +16 -5
- package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +25 -14
- package/client/src/components/ClusterRightPanel/MailboxModal.tsx +7 -3
- package/client/src/components/ClusterRightPanel/MemberRow.tsx +5 -2
- package/client/src/components/ClusterRightPanel/MemberSettingsFields.tsx +104 -0
- package/client/src/components/ClusterRightPanel/MessageGuardControl.tsx +1 -1
- package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +85 -7
- package/client/src/components/ClusterRightPanel/index.tsx +90 -36
- package/client/src/components/ClusterRightPanel/memberSettings.ts +52 -0
- package/client/src/components/ClusterRightPanel/panels.ts +18 -0
- package/client/src/components/ClusterRightPanel/types.ts +9 -10
- package/client/src/components/ClusterTab.tsx +252 -62
- package/client/src/components/ClusterTaskBoardTab.tsx +22 -598
- package/client/src/components/CommandPalette.tsx +17 -6
- package/client/src/components/ComputerAgentPicker.tsx +1 -1
- package/client/src/components/ComputerPanel.tsx +4 -2
- package/client/src/components/Connections/Connections.tsx +5 -2
- package/client/src/components/Connections/EndpointEditor.tsx +2 -2
- package/client/src/components/Connections/connections.css +1 -1
- package/client/src/components/Connections/model.ts +5 -1
- package/client/src/components/ContextMeter.tsx +15 -4
- package/client/src/components/DeepSeekControls.tsx +7 -6
- package/client/src/components/DiagnosticsTab.tsx +3 -2
- package/client/src/components/DialogShell.tsx +19 -11
- package/client/src/components/FileExplorer.tsx +8 -9
- package/client/src/components/FileViewerModal.tsx +37 -12
- package/client/src/components/FirstRun.tsx +8 -7
- package/client/src/components/GateApprovalNotice.tsx +4 -2
- package/client/src/components/GitDialog.tsx +1 -0
- package/client/src/components/GitHubPanel/CodeView.tsx +35 -23
- package/client/src/components/GitHubPanel/IssueView.tsx +6 -4
- package/client/src/components/GitHubPanel/PullView.tsx +7 -6
- package/client/src/components/GitHubPanel/RunView.tsx +7 -5
- package/client/src/components/GitHubPanel/shared.tsx +23 -8
- package/client/src/components/HandoffSeedPill.tsx +5 -5
- package/client/src/components/HandoffSource.tsx +54 -0
- package/client/src/components/HeaderAuthChip.tsx +22 -1
- package/client/src/components/HeaderDropdown.tsx +5 -0
- package/client/src/components/HeaderVersionBox.tsx +3 -0
- package/client/src/components/HistoryTab.tsx +59 -32
- package/client/src/components/Home/AddProject.tsx +1 -1
- package/client/src/components/Home/HomeView.tsx +28 -19
- package/client/src/components/Home/LocationDialog.tsx +1 -1
- package/client/src/components/Home/ProjectCard.tsx +5 -3
- package/client/src/components/Home/home.css +4 -4
- package/client/src/components/KeepButton.tsx +22 -0
- package/client/src/components/LlamacppCatalogEditor.tsx +12 -3
- package/client/src/components/LocalRuntimeStatus.tsx +54 -0
- package/client/src/components/MdTuneupDialog.tsx +3 -1
- package/client/src/components/MemberCard.tsx +44 -42
- package/client/src/components/MemberPane.tsx +11 -10
- package/client/src/components/ModelHealthPanel.tsx +5 -4
- package/client/src/components/NativeSubagentControls.tsx +64 -0
- package/client/src/components/NeedsYouBadge.tsx +13 -6
- package/client/src/components/NorthStarBar.tsx +5 -3
- package/client/src/components/NotificationCenter.tsx +14 -2
- package/client/src/components/NotificationChannelsSettings.tsx +38 -30
- package/client/src/components/NotificationToasts.tsx +6 -8
- package/client/src/components/PendingQuestionsButton.tsx +4 -1
- package/client/src/components/PlanBodyRenderer.tsx +1 -0
- package/client/src/components/PlanCandidateBanner.tsx +20 -3
- package/client/src/components/PlanReviewPicker.tsx +6 -3
- package/client/src/components/PreviewTab.tsx +62 -25
- package/client/src/components/PrimaryStatus.tsx +20 -74
- package/client/src/components/ProjectsSettings.tsx +28 -2
- package/client/src/components/ProviderReleasesModal.tsx +13 -3
- package/client/src/components/ProvidersPopover.tsx +81 -23
- package/client/src/components/PublicProjectBox.tsx +10 -6
- package/client/src/components/PurgeConversationModal.tsx +7 -2
- package/client/src/components/QueuedMessagesIndicator.tsx +42 -150
- package/client/src/components/Recall/RecallResultRow.tsx +4 -2
- package/client/src/components/Recall/RecallView.tsx +12 -9
- package/client/src/components/ResearchDialog.tsx +1 -1
- package/client/src/components/ReviewDialog.tsx +12 -5
- package/client/src/components/RightPanel/ActivityTab.tsx +32 -16
- package/client/src/components/RightPanel/CodebaseMemorySection.tsx +3 -1
- package/client/src/components/RightPanel/ConfigTab.tsx +129 -140
- package/client/src/components/RightPanel/GenesisTab.tsx +67 -24
- package/client/src/components/RightPanel/HandoffsTab.tsx +4 -0
- package/client/src/components/RightPanel/KnowledgeTab.tsx +1 -1
- package/client/src/components/RightPanel/LedgerTab.tsx +1 -1
- package/client/src/components/RightPanel/McpRegistrySection.tsx +7 -6
- package/client/src/components/RightPanel/MoveTargetModal.tsx +6 -3
- package/client/src/components/RightPanel/OutputsPanel.tsx +40 -17
- package/client/src/components/RightPanel/PlanTab.tsx +109 -111
- package/client/src/components/RightPanel/ReviewTab.tsx +7 -4
- package/client/src/components/RightPanel/UsageTab.tsx +18 -5
- package/client/src/components/RightPanel/format.ts +3 -1
- package/client/src/components/RightPanel/index.tsx +10 -2
- package/client/src/components/RightPanel/types.ts +4 -2
- package/client/src/components/RunAsPicker.tsx +5 -3
- package/client/src/components/RuntimeStateBanner.tsx +13 -3
- package/client/src/components/SavedClustersList.tsx +30 -3
- package/client/src/components/ServicesTab.tsx +17 -34
- package/client/src/components/SettingsPanel.tsx +101 -337
- package/client/src/components/ShortcutCheatSheet.tsx +6 -4
- package/client/src/components/SkillEditorDialog.tsx +2 -1
- package/client/src/components/SkillsSettings.tsx +307 -0
- package/client/src/components/SpawnDialog.tsx +3 -3
- package/client/src/components/SpawnSeedPill.tsx +5 -4
- package/client/src/components/StaleBuildBanner.tsx +3 -1
- package/client/src/components/StorageWarnings.tsx +3 -1
- package/client/src/components/SystemHeader.tsx +17 -10
- package/client/src/components/SystemModal.tsx +6 -5
- package/client/src/components/TabBar.tsx +20 -10
- package/client/src/components/TabContextMenu.tsx +36 -10
- package/client/src/components/TaskCard.tsx +16 -11
- package/client/src/components/TasksPanel.tsx +13 -11
- package/client/src/components/Terminal/XtermView.tsx +2 -0
- package/client/src/components/TerminalInput.tsx +248 -447
- package/client/src/components/TerminalSessions.tsx +1 -1
- package/client/src/components/TokenBadge.tsx +20 -17
- package/client/src/components/ToolCallPill.tsx +5 -3
- package/client/src/components/ToolboxMenu.tsx +5 -5
- package/client/src/components/TranscriptSendDialog.tsx +1 -1
- package/client/src/components/TurnTimer.tsx +21 -0
- package/client/src/components/UpdateAction.tsx +4 -1
- package/client/src/components/UsageBar.tsx +32 -126
- package/client/src/components/UserManual/index.tsx +6 -4
- package/client/src/components/VoiceMenu.tsx +5 -1
- package/client/src/components/VoiceSetupSettings.tsx +21 -11
- package/client/src/components/WorkerCard.tsx +7 -1
- package/client/src/components/WorkerDetailModal.tsx +7 -3
- package/client/src/components/WorkflowCreator/ClusterMembersSection.tsx +6 -6
- package/client/src/components/WorkflowCreator/ProjectPicker.tsx +13 -12
- package/client/src/components/WorkflowCreator/index.tsx +237 -78
- package/client/src/components/WorkflowCreator/types.ts +5 -3
- package/client/src/components/WorkflowStatusChip.tsx +93 -13
- package/client/src/components/WorkflowView.tsx +55 -24
- package/client/src/components/WorkspaceRename.tsx +11 -1
- package/client/src/components/activityTime.ts +4 -0
- package/client/src/components/compare/CompareDialog.tsx +6 -3
- package/client/src/components/compare/CompareOverlay.tsx +10 -3
- package/client/src/components/composer/submitComposer.ts +191 -0
- package/client/src/components/diff/ChangesPanel.tsx +4 -2
- package/client/src/components/diff/LiveChangesPanel.tsx +18 -2
- package/client/src/components/editor/CodeEditor.tsx +17 -2
- package/client/src/components/headerPopoverState.ts +15 -0
- package/client/src/components/help/DocViewer.tsx +6 -4
- package/client/src/components/help/HelpCard.tsx +3 -2
- package/client/src/components/help/HelpPopover.tsx +3 -1
- package/client/src/components/media/AudioEditor/AudioOpsPanel.tsx +16 -2
- package/client/src/components/media/DirectoryPicker.tsx +18 -11
- package/client/src/components/media/ImageEditor/ImageEditor.tsx +2 -2
- package/client/src/components/media/MediaModalHost.tsx +7 -15
- package/client/src/components/media/MediaStemsControls.tsx +16 -2
- package/client/src/components/media/VideoEditor/VideoOpsPanel.tsx +16 -2
- package/client/src/components/media/launchers.ts +4 -0
- package/client/src/components/plans/PlanChooser.tsx +135 -0
- package/client/src/components/plans/PlanRefsSection.tsx +47 -28
- package/client/src/components/plans/planBodySave.ts +17 -0
- package/client/src/components/plans/planRefs.ts +21 -11
- package/client/src/components/plans/startPlanGenesis.ts +37 -0
- package/client/src/components/primitives/Panel.tsx +1 -0
- package/client/src/components/providerPanelState.ts +17 -0
- package/client/src/components/settings/AppVersionSection.tsx +5 -5
- package/client/src/components/settings/AppWindowBrowserSection.tsx +88 -0
- package/client/src/components/settings/PreviewPortsSection.tsx +31 -0
- package/client/src/components/settings/SettingsLayout.tsx +1 -1
- package/client/src/components/settings/appWindowBrowserReport.ts +23 -0
- package/client/src/components/settings/navigation.ts +5 -1
- package/client/src/components/settings/settings.css +6 -0
- package/client/src/components/terminalInput/planDraft.ts +5 -5
- package/client/src/components/usageVisibility.ts +3 -2
- package/client/src/components/workSurface/WorkSurfaceControls.tsx +125 -10
- package/client/src/components/workSurface/workSurface.css +10 -2
- package/client/src/explorer/ArtifactsLens.tsx +53 -17
- package/client/src/explorer/ExplorerApp.tsx +8 -6
- package/client/src/explorer/PlansLens.tsx +80 -20
- package/client/src/explorer/RecentsLens.tsx +22 -61
- package/client/src/explorer/StorageLens.tsx +10 -4
- package/client/src/explorer/changedAttribution.ts +23 -0
- package/client/src/explorer/launch.ts +6 -3
- package/client/src/explorer/treeReveal.ts +21 -0
- package/client/src/explorer/types.ts +3 -3
- package/client/src/help/content/chat.tsx +17 -10
- package/client/src/help/content/cluster.tsx +135 -104
- package/client/src/help/content/composer.tsx +124 -43
- package/client/src/help/content/gitOps.tsx +19 -19
- package/client/src/help/content/github.tsx +9 -4
- package/client/src/help/content/header.tsx +70 -51
- package/client/src/help/content/media.tsx +20 -20
- package/client/src/help/content/misc.tsx +347 -163
- package/client/src/help/content/recall.tsx +12 -12
- package/client/src/help/content/rightPanel.tsx +199 -102
- package/client/src/help/content/settings.tsx +117 -44
- package/client/src/help/content/shared.tsx +1 -1
- package/client/src/help/content/tabbar.tsx +1 -1
- package/client/src/help/manualSections/actions.tsx +24 -17
- package/client/src/help/manualSections/chat.tsx +28 -5
- package/client/src/help/manualSections/clusters.tsx +193 -131
- package/client/src/help/manualSections/configuration.tsx +232 -48
- package/client/src/help/manualSections/deepseek.tsx +7 -5
- package/client/src/help/manualSections/gettingStarted.tsx +74 -12
- package/client/src/help/manualSections/maintenance.tsx +60 -13
- package/client/src/help/manualSections/media.tsx +14 -12
- package/client/src/help/manualSections/plans.tsx +108 -25
- package/client/src/help/manualSections/powerFeatures.tsx +145 -50
- package/client/src/help/manualSections/providers.tsx +237 -42
- package/client/src/help/manualSections/reference.tsx +19 -11
- package/client/src/help/manualSections/strata.tsx +6 -6
- package/client/src/help/manualSections/troubleshooting.tsx +14 -8
- package/client/src/help/manualSections/voice.tsx +12 -7
- package/client/src/help/manualSections/workflows.tsx +76 -19
- package/client/src/help/manualSections/workspace.tsx +173 -46
- package/client/src/help/shortcuts.ts +1 -0
- package/client/src/hooks/useWebSocket.ts +49 -25
- package/client/src/layout/SlideOut.tsx +77 -0
- package/client/src/layout/ToolbarOverflow.tsx +97 -0
- package/client/src/layout/keepInWindow.ts +216 -0
- package/client/src/layout/layoutRange.ts +129 -0
- package/client/src/main.tsx +2 -0
- package/client/src/phosphor-demo/Demo.tsx +5 -13
- package/client/src/phosphor-demo/demo.css +1 -1
- package/client/src/stores/appStore.ts +65 -14
- package/client/src/stores/appStore.types.ts +35 -16
- package/client/src/stores/docEditStore.ts +13 -21
- package/client/src/stores/draftStore.ts +28 -4
- package/client/src/stores/knowledgeDistillStore.ts +4 -2
- package/client/src/stores/mdTuneupStore.ts +10 -5
- package/client/src/stores/notificationChannelsStore.ts +21 -11
- package/client/src/stores/planGenesisStore.ts +67 -0
- package/client/src/stores/recallStore.ts +6 -0
- package/client/src/stores/terminalStore.ts +1 -1
- package/client/src/styles/global.css +72 -0
- package/client/src/styles/matrix.css +7 -0
- package/client/src/themes/apply.ts +3 -3
- package/client/src/themes/bootstrap.ts +3 -0
- package/client/src/utils/activeProject.ts +6 -0
- package/client/src/utils/activityPresentation.ts +51 -0
- package/client/src/utils/browserFamily.ts +22 -0
- package/client/src/utils/chatFileLinks.ts +3 -2
- package/client/src/utils/chatText.ts +14 -6
- package/client/src/utils/checkedJson.ts +11 -0
- package/client/src/utils/checkpointChanges.ts +18 -0
- package/client/src/utils/clusterCreation.ts +39 -0
- package/client/src/utils/clusterNudge.ts +31 -0
- package/client/src/utils/displayMessages.ts +45 -7
- package/client/src/utils/effortDefaults.ts +4 -3
- package/client/src/utils/format.ts +11 -4
- package/client/src/utils/gateArgs.ts +3 -2
- package/client/src/utils/handoffSeeds.ts +13 -0
- package/client/src/utils/historyEvents.ts +21 -12
- package/client/src/utils/homeModel.ts +19 -3
- package/client/src/utils/memberReviewScope.ts +6 -0
- package/client/src/utils/outputNavigation.ts +16 -0
- package/client/src/utils/outputStyleText.ts +8 -0
- package/client/src/utils/publicProject.ts +102 -28
- package/client/src/utils/queuedMessageEdit.ts +40 -0
- package/client/src/utils/requestGeneration.ts +8 -0
- package/client/src/utils/rewindSupport.ts +17 -0
- package/client/src/utils/settingsRequests.ts +36 -0
- package/client/src/utils/settingsResponse.ts +8 -0
- package/client/src/utils/wsSession.ts +12 -5
- package/client/src/vendor/odysseus-editor/editor/clipboard-and-drop.js +9 -9
- package/client/src/vendor/odysseus-editor/editor/keyboard-shortcuts.js +2 -2
- package/client/src/vendor/odysseus-editor/editor/state.js +8 -0
- package/client/src/vendor/odysseus-editor/editor.css +13 -5
- package/client/src/vendor/odysseus-editor/galleryEditor.d.ts +1 -1
- package/client/src/vendor/odysseus-editor/galleryEditor.js +16 -5
- package/client/src/voice/executor.ts +4 -3
- package/client/src/voice/panels.ts +14 -3
- package/client/src/voice/screen.ts +48 -6
- package/client/src/voice/setupAudio.ts +5 -3
- package/client/src/ws/handleServerMessage.ts +154 -36
- package/client/src/ws/operatorQuestions.ts +2 -2
- package/docs/ARCHITECTURE.md +95 -55
- package/docs/ARCHITECTURE_REVIEW.md +47 -0
- package/docs/BACKUP.md +5 -2
- package/docs/CHAT.md +48 -37
- package/docs/CHECKPOINTS.md +43 -16
- package/docs/CLIENT.md +218 -82
- package/docs/CODEX_GPT56_CLUSTER_INCOMPAT.md +1 -1
- package/docs/DEEPSEEK.md +6 -6
- package/docs/DIAGNOSTICS.md +12 -7
- package/docs/EXTENDING.md +52 -48
- package/docs/FEATURES.md +33 -20
- package/docs/GENESIS.md +42 -6
- package/docs/GETTING_STARTED.md +59 -25
- package/docs/GIT_WORKBENCH.md +15 -9
- package/docs/GLOSSARY.md +42 -40
- package/docs/GOTCHAS.md +70 -57
- package/docs/HTTP_API.md +145 -47
- package/docs/INDEX.md +3 -4
- package/docs/KNOWLEDGE.md +6 -4
- package/docs/LOCAL_SERVICES.md +6 -6
- package/docs/LSP.md +4 -3
- package/docs/MCP_REGISTRY.md +16 -12
- package/docs/MEDIA_STUDIO.md +23 -16
- package/docs/NOTIFICATIONS.md +50 -17
- package/docs/OPERATIONS.md +211 -120
- package/docs/OPERATOR_ACTIONS.md +43 -24
- package/docs/OUTPUTS.md +27 -10
- package/docs/PERSISTENCE.md +88 -34
- package/docs/PHOSPHOR_DEMO.md +4 -4
- package/docs/PLAN_OR_BOARD.md +9 -4
- package/docs/PREVIEW_VERIFY.md +10 -8
- package/docs/PRIMITIVES.md +90 -87
- package/docs/PROTOCOL.md +100 -29
- package/docs/PROTOCOL_CLUSTER.md +77 -14
- package/docs/PROTOCOL_PRIMITIVES.md +9 -9
- package/docs/PROVIDERS.md +471 -82
- package/docs/RECALL.md +17 -12
- package/docs/REMOTE_MANAGEMENT.md +69 -8
- package/docs/REPO_LAYOUT.md +1 -1
- package/docs/RESUME_INDEX.md +16 -17
- package/docs/SERVICE_MODE.md +45 -10
- package/docs/SETTINGS.md +58 -7
- package/docs/STORAGE_PLAN.md +54 -49
- package/docs/STRATA.md +4 -4
- package/docs/TASK_LEDGER.md +33 -12
- package/docs/TERMINAL.md +14 -12
- package/docs/THIRD_PARTY.md +1 -3
- package/docs/VOICE.md +15 -7
- package/native/darwin-arm64/manifest.json +1 -1
- package/native/win32-arm64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/clusterCoordination.js +15 -7
- package/node_modules/@arco/shared/dist/clusterRolePresets.js +8 -6
- package/node_modules/@arco/shared/dist/codexChat.d.ts +2 -0
- package/node_modules/@arco/shared/dist/codexChat.js +5 -0
- package/node_modules/@arco/shared/dist/folderName.d.ts +1 -0
- package/node_modules/@arco/shared/dist/folderName.js +18 -0
- package/node_modules/@arco/shared/dist/index.d.ts +6 -0
- package/node_modules/@arco/shared/dist/index.js +6 -0
- package/node_modules/@arco/shared/dist/localRuntimeStatus.d.ts +23 -0
- package/node_modules/@arco/shared/dist/localRuntimeStatus.js +47 -0
- package/node_modules/@arco/shared/dist/notificationTitle.d.ts +9 -0
- package/node_modules/@arco/shared/dist/notificationTitle.js +23 -0
- package/node_modules/@arco/shared/dist/outputStyle.d.ts +10 -0
- package/node_modules/@arco/shared/dist/outputStyle.js +28 -0
- package/node_modules/@arco/shared/dist/outputs.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/autoPickup.d.ts +2 -0
- package/node_modules/@arco/shared/dist/protocol/chat.d.ts +4 -0
- package/node_modules/@arco/shared/dist/protocol/checkpoints.d.ts +24 -2
- package/node_modules/@arco/shared/dist/protocol/checkpoints.js +1 -0
- package/node_modules/@arco/shared/dist/protocol/clientMessages.d.ts +9 -14
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +21 -4
- package/node_modules/@arco/shared/dist/protocol/clusters.js +3 -3
- package/node_modules/@arco/shared/dist/protocol/connections.d.ts +2 -0
- package/node_modules/@arco/shared/dist/protocol/diagnostics.js +1 -1
- package/node_modules/@arco/shared/dist/protocol/genesis.d.ts +9 -0
- package/node_modules/@arco/shared/dist/protocol/mcp.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/mcp.js +8 -5
- package/node_modules/@arco/shared/dist/protocol/mdTuneup.d.ts +2 -0
- package/node_modules/@arco/shared/dist/protocol/models.d.ts +3 -1
- package/node_modules/@arco/shared/dist/protocol/models.js +19 -8
- package/node_modules/@arco/shared/dist/protocol/notifications.d.ts +2 -1
- package/node_modules/@arco/shared/dist/protocol/notifications.js +15 -3
- package/node_modules/@arco/shared/dist/protocol/plans.d.ts +2 -1
- package/node_modules/@arco/shared/dist/protocol/remoteManagement.d.ts +6 -0
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +69 -10
- package/node_modules/@arco/shared/dist/protocol/settings.d.ts +16 -4
- package/node_modules/@arco/shared/dist/protocol/settings.js +17 -1
- package/node_modules/@arco/shared/dist/protocol/tasks.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/usage.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/workers.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +73 -14
- package/node_modules/@arco/shared/dist/protocol/workflows.js +66 -0
- package/node_modules/@arco/shared/dist/publicGuardrails.d.ts +1 -1
- package/node_modules/@arco/shared/dist/publicGuardrails.js +1 -1
- package/node_modules/@arco/shared/dist/runtimeVersions.d.ts +2 -0
- package/node_modules/@arco/shared/dist/runtimeVersions.js +13 -0
- package/node_modules/@arco/shared/dist/shellTool.d.ts +2 -0
- package/node_modules/@arco/shared/dist/shellTool.js +9 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/node_modules/xlsx/LICENSE +201 -0
- package/node_modules/xlsx/dist/cpexcel.js +1506 -0
- package/node_modules/xlsx/package.json +69 -0
- package/node_modules/xlsx/xlsx.js +28103 -0
- package/node_modules/xlsx/xlsx.mjs +28228 -0
- package/package.json +22 -3
- package/scripts/packaging/arco.mjs +3 -3
- package/scripts/packaging/browsers.mjs +366 -0
- package/scripts/packaging/launch.mjs +34 -20
- package/scripts/packaging/services.mjs +1 -1
- package/scripts/packaging/storage.mjs +39 -3
- package/server/dist/appBrowsers.d.ts +45 -0
- package/server/dist/appBrowsers.js +73 -0
- package/server/dist/architectureReview.d.ts +60 -0
- package/server/dist/architectureReview.js +347 -0
- package/server/dist/architectureSkill.d.ts +8 -0
- package/server/dist/architectureSkill.js +70 -0
- package/server/dist/arcoHome.d.ts +1 -0
- package/server/dist/arcoHome.js +43 -3
- package/server/dist/artifactCopy.d.ts +3 -0
- package/server/dist/artifactCopy.js +113 -36
- package/server/dist/atomicFile.d.ts +1 -1
- package/server/dist/atomicFile.js +6 -1
- package/server/dist/attention.d.ts +5 -1
- package/server/dist/attention.js +27 -16
- package/server/dist/auth.d.ts +1 -0
- package/server/dist/auth.js +19 -6
- package/server/dist/authLoginSession.d.ts +2 -0
- package/server/dist/authLoginSession.js +6 -1
- package/server/dist/boundedRead.d.ts +26 -0
- package/server/dist/boundedRead.js +246 -0
- package/server/dist/capabilities.d.ts +4 -1
- package/server/dist/capabilities.js +25 -8
- package/server/dist/catchUp.d.ts +7 -0
- package/server/dist/catchUp.js +20 -1
- package/server/dist/checkedFile.d.ts +5 -0
- package/server/dist/checkedFile.js +138 -0
- package/server/dist/claudeTransport.d.ts +7 -0
- package/server/dist/claudeTransport.js +14 -0
- package/server/dist/clusterAutoTurn.d.ts +7 -0
- package/server/dist/clusterAutoTurn.js +54 -7
- package/server/dist/clusterBusyReminder.d.ts +7 -0
- package/server/dist/clusterBusyReminder.js +45 -0
- package/server/dist/clusterDirector.js +6 -3
- package/server/dist/clusterIdleNudger.d.ts +6 -0
- package/server/dist/clusterIdleNudger.js +5 -0
- package/server/dist/clusterMailbox.d.ts +4 -2
- package/server/dist/clusterMailbox.js +104 -24
- package/server/dist/clusterPeerOps.js +9 -21
- package/server/dist/clusterPlanBridge.d.ts +6 -3
- package/server/dist/clusterPlanBridge.js +48 -45
- package/server/dist/clusterPresets.js +46 -32
- package/server/dist/clusterProgress.js +3 -0
- package/server/dist/clusterSnapshots.d.ts +1 -1
- package/server/dist/clusterSnapshots.js +17 -2
- package/server/dist/clusterStore.d.ts +3 -0
- package/server/dist/clusterStore.js +23 -13
- package/server/dist/clusterTurnTools.d.ts +4 -0
- package/server/dist/clusterTurnTools.js +9 -0
- package/server/dist/commandShell.d.ts +56 -0
- package/server/dist/commandShell.js +278 -0
- package/server/dist/compactionCounter.d.ts +6 -0
- package/server/dist/compactionCounter.js +73 -0
- package/server/dist/compactionReport.d.ts +8 -0
- package/server/dist/compactionReport.js +15 -0
- package/server/dist/contentSearch.js +16 -6
- package/server/dist/contextCalibrator.js +7 -2
- package/server/dist/contextEstimator.d.ts +4 -0
- package/server/dist/contextEstimator.js +76 -17
- package/server/dist/contextRefs.d.ts +1 -0
- package/server/dist/contextRefs.js +44 -9
- package/server/dist/conversationActivity.d.ts +3 -0
- package/server/dist/conversationActivity.js +27 -0
- package/server/dist/cursorUsage.js +15 -4
- package/server/dist/diagnostics/checks.js +4 -12
- package/server/dist/diagnostics/executableLookup.d.ts +2 -0
- package/server/dist/diagnostics/executableLookup.js +28 -0
- package/server/dist/diagnostics/modelHealth.js +3 -12
- package/server/dist/diagnostics/supportBundle.js +5 -13
- package/server/dist/eventLog.d.ts +19 -0
- package/server/dist/eventLog.js +299 -99
- package/server/dist/existingClusterMembers.d.ts +1 -0
- package/server/dist/existingClusterMembers.js +9 -0
- package/server/dist/explorerArtifacts.js +46 -12
- package/server/dist/explorerChanged.d.ts +7 -0
- package/server/dist/explorerChanged.js +116 -80
- package/server/dist/explorerDocs.d.ts +11 -0
- package/server/dist/explorerDocs.js +46 -48
- package/server/dist/explorerLaunch.d.ts +4 -0
- package/server/dist/explorerLaunch.js +9 -1
- package/server/dist/fileAccessPolicy.d.ts +21 -0
- package/server/dist/fileAccessPolicy.js +89 -1
- package/server/dist/fileContent/decodeSlots.d.ts +1 -0
- package/server/dist/fileContent/decodeSlots.js +50 -0
- package/server/dist/fileContent/detect.d.ts +2 -0
- package/server/dist/fileContent/detect.js +55 -0
- package/server/dist/fileContent/externalImage.d.ts +3 -0
- package/server/dist/fileContent/externalImage.js +68 -0
- package/server/dist/fileContent/icons.d.ts +4 -0
- package/server/dist/fileContent/icons.js +58 -0
- package/server/dist/fileContent/images.d.ts +15 -0
- package/server/dist/fileContent/images.js +182 -0
- package/server/dist/fileContent/legacyText.d.ts +3 -0
- package/server/dist/fileContent/legacyText.js +19 -0
- package/server/dist/fileContent/notebook.d.ts +2 -0
- package/server/dist/fileContent/notebook.js +54 -0
- package/server/dist/fileContent/office.d.ts +3 -0
- package/server/dist/fileContent/office.js +349 -0
- package/server/dist/fileContent/pdf.d.ts +2 -0
- package/server/dist/fileContent/pdf.js +76 -0
- package/server/dist/fileContent/pngRows.d.ts +4 -0
- package/server/dist/fileContent/pngRows.js +118 -0
- package/server/dist/fileContent/svg.d.ts +3 -0
- package/server/dist/fileContent/svg.js +60 -0
- package/server/dist/fileContent/types.d.ts +8 -0
- package/server/dist/fileContent/types.js +43 -0
- package/server/dist/fileContent/worker.d.ts +1 -0
- package/server/dist/fileContent/worker.js +68 -0
- package/server/dist/fileContent.d.ts +55 -0
- package/server/dist/fileContent.js +81 -0
- package/server/dist/fileContextReceipts.d.ts +12 -0
- package/server/dist/fileContextReceipts.js +53 -0
- package/server/dist/fileFetch.d.ts +17 -0
- package/server/dist/fileFetch.js +191 -0
- package/server/dist/fileVersion.d.ts +10 -0
- package/server/dist/fileVersion.js +43 -0
- package/server/dist/genesis/creative.js +28 -36
- package/server/dist/genesis/prompts.js +4 -0
- package/server/dist/genesis/savePlan.d.ts +5 -0
- package/server/dist/genesis/savePlan.js +49 -0
- package/server/dist/genesis/stages.js +4 -4
- package/server/dist/gitDiff.js +25 -5
- package/server/dist/gitSnapshots.d.ts +18 -0
- package/server/dist/gitSnapshots.js +280 -149
- package/server/dist/gitWorking.js +15 -13
- package/server/dist/github.js +5 -1
- package/server/dist/goalRun.d.ts +1 -1
- package/server/dist/goalRun.js +7 -5
- package/server/dist/handoffHistory.d.ts +26 -0
- package/server/dist/handoffHistory.js +80 -0
- package/server/dist/handoffHistoryProtocol.d.ts +59 -0
- package/server/dist/handoffHistoryProtocol.js +20 -0
- package/server/dist/handoffHistorySupport.d.ts +2 -0
- package/server/dist/handoffHistorySupport.js +11 -0
- package/server/dist/handoffHistoryTool.d.ts +29 -0
- package/server/dist/handoffHistoryTool.js +235 -0
- package/server/dist/handoffPrompts.js +6 -4
- package/server/dist/handoffReplay.d.ts +9 -0
- package/server/dist/handoffReplay.js +14 -0
- package/server/dist/handoffSeedCache.d.ts +3 -0
- package/server/dist/handoffSeedCache.js +26 -0
- package/server/dist/http/appBrowserRoutes.d.ts +3 -0
- package/server/dist/http/appBrowserRoutes.js +16 -0
- package/server/dist/http/architectureReviewRoutes.d.ts +3 -0
- package/server/dist/http/architectureReviewRoutes.js +117 -0
- package/server/dist/http/clusterRoutes.js +13 -1
- package/server/dist/http/clusterSnapshotRoutes.js +8 -3
- package/server/dist/http/connectionsRoutes.js +3 -1
- package/server/dist/http/diffRoutes.js +37 -3
- package/server/dist/http/explorerRoot.d.ts +3 -0
- package/server/dist/http/explorerRoot.js +22 -0
- package/server/dist/http/explorerRoutes.js +65 -12
- package/server/dist/http/fileRead.js +2 -3
- package/server/dist/http/fileWriteRoutes.js +4 -3
- package/server/dist/http/gitCompareRoutes.js +4 -6
- package/server/dist/http/gitDiffRoutes.js +3 -3
- package/server/dist/http/gitOpRoutes.js +3 -5
- package/server/dist/http/gitWorktreeRoutes.js +3 -3
- package/server/dist/http/handoffHistoryRoutes.d.ts +4 -0
- package/server/dist/http/handoffHistoryRoutes.js +59 -0
- package/server/dist/http/imageWriteRoutes.js +6 -2
- package/server/dist/http/knowledgeRoutes.js +2 -0
- package/server/dist/http/mediaOpsRoutes.js +2 -3
- package/server/dist/http/originGuard.d.ts +1 -1
- package/server/dist/http/originGuard.js +95 -12
- package/server/dist/http/outputRoutes.js +31 -6
- package/server/dist/http/projectBinding.d.ts +3 -0
- package/server/dist/http/projectBinding.js +133 -0
- package/server/dist/http/providerThrottleRoutes.d.ts +8 -0
- package/server/dist/http/providerThrottleRoutes.js +96 -0
- package/server/dist/http/publicProjectRoutes.js +50 -9
- package/server/dist/http/readConfinement.d.ts +2 -1
- package/server/dist/http/readConfinement.js +17 -15
- package/server/dist/http/router.js +224 -62
- package/server/dist/http/searchRoutes.js +4 -4
- package/server/dist/http/sessionTransport.d.ts +2 -0
- package/server/dist/http/sessionTransport.js +32 -0
- package/server/dist/http/skillManagementRoutes.d.ts +5 -0
- package/server/dist/http/skillManagementRoutes.js +166 -0
- package/server/dist/http/storageRoutes.js +20 -6
- package/server/dist/http/utilityAgentRoutes.js +27 -5
- package/server/dist/http/workflowDataRoutes.js +75 -14
- package/server/dist/http/writeConfinement.d.ts +5 -3
- package/server/dist/http/writeConfinement.js +37 -11
- package/server/dist/http/wsAuth.d.ts +3 -2
- package/server/dist/http/wsAuth.js +26 -8
- package/server/dist/imageTokens.d.ts +7 -0
- package/server/dist/imageTokens.js +85 -0
- package/server/dist/index.js +283 -178
- package/server/dist/inputDeliveryHistory.d.ts +21 -0
- package/server/dist/inputDeliveryHistory.js +146 -0
- package/server/dist/keepStore.d.ts +4 -0
- package/server/dist/keepStore.js +48 -0
- package/server/dist/knowledge/store.js +28 -20
- package/server/dist/legacyTarRestore.d.ts +1 -0
- package/server/dist/legacyTarRestore.js +240 -0
- package/server/dist/llamacppCatalog.d.ts +8 -1
- package/server/dist/llamacppCatalog.js +65 -13
- package/server/dist/localRuntimeStatus.d.ts +35 -0
- package/server/dist/localRuntimeStatus.js +136 -0
- package/server/dist/lsp/client.js +28 -9
- package/server/dist/lsp/servers.js +2 -2
- package/server/dist/managedPath.d.ts +2 -0
- package/server/dist/managedPath.js +47 -0
- package/server/dist/management/hubGuard.d.ts +23 -0
- package/server/dist/management/hubGuard.js +118 -0
- package/server/dist/management/hubLink.d.ts +4 -1
- package/server/dist/management/hubLink.js +8 -1
- package/server/dist/management/initHubLink.d.ts +12 -0
- package/server/dist/management/initHubLink.js +44 -22
- package/server/dist/manualCompactCapability.d.ts +2 -0
- package/server/dist/manualCompactCapability.js +7 -0
- package/server/dist/mcp/arcoMcpServer.js +4 -0
- package/server/dist/mcp/client.d.ts +4 -4
- package/server/dist/mcp/client.js +31 -10
- package/server/dist/mcp/clusterMcpLoopback.d.ts +4 -0
- package/server/dist/mcp/clusterMcpLoopback.js +21 -1
- package/server/dist/mcp/clusterMcpTools.js +25 -26
- package/server/dist/mcp/fileContent.d.ts +8 -0
- package/server/dist/mcp/fileContent.js +55 -0
- package/server/dist/mcp/fileMcpServer.d.ts +1 -0
- package/server/dist/mcp/fileMcpServer.js +13 -0
- package/server/dist/mcp/fileMcpTools.d.ts +2 -0
- package/server/dist/mcp/fileMcpTools.js +54 -0
- package/server/dist/mcp/handoffHistoryMcpTools.d.ts +3 -0
- package/server/dist/mcp/handoffHistoryMcpTools.js +27 -0
- package/server/dist/mcp/mcpConfigWriter.d.ts +5 -0
- package/server/dist/mcp/mcpConfigWriter.js +44 -12
- package/server/dist/mcp/planMcpTools.d.ts +6 -14
- package/server/dist/mcp/planMcpTools.js +6 -250
- package/server/dist/mcp/planReadMcpServer.d.ts +1 -0
- package/server/dist/mcp/planReadMcpServer.js +19 -0
- package/server/dist/mcp/registry.js +44 -38
- package/server/dist/mcp/registryWiring.js +4 -5
- package/server/dist/media/demucs.d.ts +5 -0
- package/server/dist/media/demucs.js +16 -4
- package/server/dist/media/ffmpeg.js +24 -16
- package/server/dist/media/scratch.js +24 -9
- package/server/dist/noticeSource.d.ts +2 -0
- package/server/dist/noticeSource.js +11 -0
- package/server/dist/notifications.d.ts +1 -0
- package/server/dist/notifications.js +7 -3
- package/server/dist/npmPlatformResolve.d.ts +9 -3
- package/server/dist/npmPlatformResolve.js +24 -5
- package/server/dist/ntfyTransport.d.ts +2 -1
- package/server/dist/ntfyTransport.js +15 -4
- package/server/dist/outputGrants.d.ts +9 -0
- package/server/dist/outputGrants.js +63 -0
- package/server/dist/outputs.js +78 -13
- package/server/dist/peerRecipientContext.js +22 -5
- package/server/dist/planStore.d.ts +11 -2
- package/server/dist/planStore.js +236 -64
- package/server/dist/planTools.d.ts +41 -0
- package/server/dist/planTools.js +259 -0
- package/server/dist/previewAutoDetect.js +31 -23
- package/server/dist/previewPortConfiguration.d.ts +2 -0
- package/server/dist/previewPortConfiguration.js +32 -0
- package/server/dist/previewPorts.d.ts +1 -0
- package/server/dist/previewPorts.js +3 -0
- package/server/dist/previewProxy.d.ts +30 -9
- package/server/dist/previewProxy.js +226 -183
- package/server/dist/primaryBackgroundTracker.d.ts +15 -2
- package/server/dist/primaryBackgroundTracker.js +172 -63
- package/server/dist/primitives/exportContext.d.ts +3 -0
- package/server/dist/primitives/exportContext.js +77 -15
- package/server/dist/primitives/localFileContext.d.ts +3 -0
- package/server/dist/primitives/localFileContext.js +38 -0
- package/server/dist/primitives/reviewContent.d.ts +2 -0
- package/server/dist/primitives/reviewContent.js +53 -6
- package/server/dist/primitives/runCompare.js +1 -1
- package/server/dist/primitives/runDocEdit.js +1 -1
- package/server/dist/primitives/runMdTuneup.d.ts +2 -1
- package/server/dist/primitives/runMdTuneup.js +20 -34
- package/server/dist/primitives/runResearch.js +1 -1
- package/server/dist/primitives/runReviewer.d.ts +2 -0
- package/server/dist/primitives/runReviewer.js +5 -2
- package/server/dist/primitives/seedWorker.d.ts +11 -2
- package/server/dist/primitives/seedWorker.js +26 -12
- package/server/dist/project/orchestrationProposals.d.ts +1 -0
- package/server/dist/project/orchestrationProposals.js +5 -1
- package/server/dist/project/taskLedger.d.ts +1 -0
- package/server/dist/project/taskLedger.js +17 -11
- package/server/dist/projectGlob.d.ts +1 -0
- package/server/dist/projectGlob.js +9 -0
- package/server/dist/projectIgnore.d.ts +1 -0
- package/server/dist/projectIgnore.js +24 -0
- package/server/dist/projectScan.d.ts +24 -0
- package/server/dist/projectScan.js +101 -0
- package/server/dist/projectStateIgnore.d.ts +13 -0
- package/server/dist/projectStateIgnore.js +36 -1
- package/server/dist/projects.d.ts +11 -3
- package/server/dist/projects.js +141 -40
- package/server/dist/prompts.js +7 -8
- package/server/dist/proportionateTestingSkill.d.ts +7 -0
- package/server/dist/proportionateTestingSkill.js +32 -0
- package/server/dist/providers/attachmentLabels.d.ts +4 -0
- package/server/dist/providers/attachmentLabels.js +9 -0
- package/server/dist/providers/attachments.d.ts +1 -3
- package/server/dist/providers/attachments.js +58 -173
- package/server/dist/providers/claude-native/apiEndpoint.d.ts +2 -0
- package/server/dist/providers/claude-native/apiEndpoint.js +8 -0
- package/server/dist/providers/claude-native/appendOnlyPrefix.js +21 -1
- package/server/dist/providers/claude-native/catalog.js +17 -15
- package/server/dist/providers/claude-native/contentBlocks.d.ts +22 -2
- package/server/dist/providers/claude-native/contentBlocks.js +31 -8
- package/server/dist/providers/claude-native/contextBudget.d.ts +0 -4
- package/server/dist/providers/claude-native/contextBudget.js +0 -2
- package/server/dist/providers/claude-native/editApply.js +6 -1
- package/server/dist/providers/claude-native/fileContent.d.ts +15 -0
- package/server/dist/providers/claude-native/fileContent.js +120 -0
- package/server/dist/providers/claude-native/filterConfigs/bash-cargo-test.js +2 -0
- package/server/dist/providers/claude-native/filterConfigs/bash-jest-vitest.js +2 -0
- package/server/dist/providers/claude-native/filterConfigs/bash-pytest.js +2 -0
- package/server/dist/providers/claude-native/filterConfigs/index.js +2 -1
- package/server/dist/providers/claude-native/foldDigest.js +10 -2
- package/server/dist/providers/claude-native/gateReview.d.ts +1 -1
- package/server/dist/providers/claude-native/gateReview.js +0 -0
- package/server/dist/providers/claude-native/hookIf.d.ts +28 -0
- package/server/dist/providers/claude-native/hookIf.js +590 -0
- package/server/dist/providers/claude-native/hooks.d.ts +77 -7
- package/server/dist/providers/claude-native/hooks.js +344 -52
- package/server/dist/providers/claude-native/imageRead.d.ts +15 -0
- package/server/dist/providers/claude-native/imageRead.js +108 -0
- package/server/dist/providers/claude-native/index.d.ts +4 -1
- package/server/dist/providers/claude-native/index.js +32 -2
- package/server/dist/providers/claude-native/mediaLimits.d.ts +6 -0
- package/server/dist/providers/claude-native/mediaLimits.js +15 -0
- package/server/dist/providers/claude-native/mediaRetention.d.ts +11 -0
- package/server/dist/providers/claude-native/mediaRetention.js +66 -0
- package/server/dist/providers/claude-native/mediaRetirementNotice.d.ts +1 -0
- package/server/dist/providers/claude-native/mediaRetirementNotice.js +12 -0
- package/server/dist/providers/claude-native/modelParams.d.ts +6 -0
- package/server/dist/providers/claude-native/modelParams.js +21 -3
- package/server/dist/providers/claude-native/oauth.js +9 -8
- package/server/dist/providers/claude-native/outputAccumulator.d.ts +2 -0
- package/server/dist/providers/claude-native/outputAccumulator.js +29 -18
- package/server/dist/providers/claude-native/peerTools.js +3 -158
- package/server/dist/providers/claude-native/pretoolGuards.js +92 -9
- package/server/dist/providers/claude-native/registryTools.js +4 -2
- package/server/dist/providers/claude-native/resumeSummary.d.ts +23 -2
- package/server/dist/providers/claude-native/resumeSummary.js +135 -28
- package/server/dist/providers/claude-native/sandboxExecutor.js +26 -19
- package/server/dist/providers/claude-native/taskAdmission.d.ts +21 -0
- package/server/dist/providers/claude-native/taskAdmission.js +75 -0
- package/server/dist/providers/claude-native/toolChecks.d.ts +38 -0
- package/server/dist/providers/claude-native/toolChecks.js +96 -0
- package/server/dist/providers/claude-native/toolPosture.js +5 -3
- package/server/dist/providers/claude-native/toolResultEviction.d.ts +4 -3
- package/server/dist/providers/claude-native/toolResultEviction.js +18 -29
- package/server/dist/providers/claude-native/tools.d.ts +17 -4
- package/server/dist/providers/claude-native/tools.js +248 -135
- package/server/dist/providers/claude-native/usageContext.d.ts +30 -0
- package/server/dist/providers/claude-native/usageContext.js +70 -0
- package/server/dist/providers/claude-native/wireFingerprint.d.ts +2 -2
- package/server/dist/providers/claude-native/wireFingerprint.js +2 -2
- package/server/dist/providers/claude-native/worker.d.ts +63 -1
- package/server/dist/providers/claude-native/worker.js +1103 -324
- package/server/dist/providers/claude-native/workerHelpers.d.ts +13 -0
- package/server/dist/providers/claude-native/workerHelpers.js +117 -6
- package/server/dist/providers/claude-native/workspaceFacts.js +2 -2
- package/server/dist/providers/claude.d.ts +1 -0
- package/server/dist/providers/claude.js +69 -85
- package/server/dist/providers/clusterTaskToolDefinitions.d.ts +11 -0
- package/server/dist/providers/clusterTaskToolDefinitions.js +161 -0
- package/server/dist/providers/codex-appserver/catalog.js +26 -20
- package/server/dist/providers/codex-appserver/index.js +10 -3
- package/server/dist/providers/codex-appserver/jsonRpc.d.ts +2 -1
- package/server/dist/providers/codex-appserver/jsonRpc.js +11 -3
- package/server/dist/providers/codex-appserver/worker.d.ts +5 -0
- package/server/dist/providers/codex-appserver/worker.js +119 -81
- package/server/dist/providers/codex.js +55 -58
- package/server/dist/providers/codexChatBoundary.d.ts +11 -0
- package/server/dist/providers/codexChatBoundary.js +60 -0
- package/server/dist/providers/codexCodeMode.js +2 -2
- package/server/dist/providers/codexContextWindow.js +2 -2
- package/server/dist/providers/codexHome.d.ts +1 -0
- package/server/dist/providers/codexHome.js +6 -0
- package/server/dist/providers/codexImageTool.d.ts +6 -0
- package/server/dist/providers/codexImageTool.js +21 -0
- package/server/dist/providers/codexVersion.d.ts +1 -0
- package/server/dist/providers/codexVersion.js +14 -0
- package/server/dist/providers/codexWebSearch.d.ts +2 -0
- package/server/dist/providers/codexWebSearch.js +4 -0
- package/server/dist/providers/cursor/acpJsonRpc.d.ts +1 -0
- package/server/dist/providers/cursor/acpJsonRpc.js +3 -1
- package/server/dist/providers/cursor/authState.d.ts +10 -0
- package/server/dist/providers/cursor/authState.js +78 -0
- package/server/dist/providers/cursor/catalog.js +22 -14
- package/server/dist/providers/cursor/chatSandbox.d.ts +11 -0
- package/server/dist/providers/cursor/chatSandbox.js +81 -0
- package/server/dist/providers/cursor/filePlugin.d.ts +4 -0
- package/server/dist/providers/cursor/filePlugin.js +31 -0
- package/server/dist/providers/cursor/index.d.ts +1 -0
- package/server/dist/providers/cursor/index.js +30 -4
- package/server/dist/providers/cursor/modelMap.d.ts +35 -0
- package/server/dist/providers/cursor/modelMap.js +180 -0
- package/server/dist/providers/cursor/print.js +95 -30
- package/server/dist/providers/cursor/worker.d.ts +4 -1
- package/server/dist/providers/cursor/worker.js +169 -89
- package/server/dist/providers/errorClassifier.js +6 -2
- package/server/dist/providers/handoffHistoryBinding.d.ts +11 -0
- package/server/dist/providers/handoffHistoryBinding.js +43 -0
- package/server/dist/providers/index.d.ts +1 -1
- package/server/dist/providers/index.js +10 -5
- package/server/dist/providers/llamacpp.d.ts +1 -0
- package/server/dist/providers/llamacpp.js +102 -192
- package/server/dist/providers/llamacppManager.d.ts +5 -0
- package/server/dist/providers/llamacppManager.js +68 -32
- package/server/dist/providers/llamacppVersion.d.ts +1 -0
- package/server/dist/providers/llamacppVersion.js +5 -0
- package/server/dist/providers/lmstudio.d.ts +3 -3
- package/server/dist/providers/lmstudio.js +133 -207
- package/server/dist/providers/localFileMedia.d.ts +25 -0
- package/server/dist/providers/localFileMedia.js +302 -0
- package/server/dist/providers/localMcp.d.ts +17 -0
- package/server/dist/providers/localMcp.js +85 -0
- package/server/dist/providers/localShellLifecycle.d.ts +7 -0
- package/server/dist/providers/localShellLifecycle.js +33 -0
- package/server/dist/providers/localToolDispatch.d.ts +28 -0
- package/server/dist/providers/localToolDispatch.js +90 -0
- package/server/dist/providers/ollama.d.ts +2 -1
- package/server/dist/providers/ollama.js +180 -181
- package/server/dist/providers/ollamaDurableCompaction.js +5 -4
- package/server/dist/providers/ollamaExecutionHistory.d.ts +1 -1
- package/server/dist/providers/ollamaExecutionHistory.js +55 -14
- package/server/dist/providers/ollamaFencedTools.js +10 -11
- package/server/dist/providers/ollamaResilience.js +9 -13
- package/server/dist/providers/ollamaTokens.js +3 -4
- package/server/dist/providers/ollamaToolSubset.d.ts +2 -0
- package/server/dist/providers/ollamaToolSubset.js +11 -40
- package/server/dist/providers/ollamaTools.d.ts +13 -0
- package/server/dist/providers/ollamaTools.js +225 -219
- package/server/dist/providers/outputStyle.d.ts +2 -1
- package/server/dist/providers/outputStyle.js +70 -76
- package/server/dist/providers/providerFileContent.d.ts +40 -0
- package/server/dist/providers/providerFileContent.js +151 -0
- package/server/dist/providers/renderedTranscript.d.ts +1 -0
- package/server/dist/providers/renderedTranscript.js +3 -0
- package/server/dist/providers/requestDeadline.d.ts +1 -0
- package/server/dist/providers/requestDeadline.js +26 -0
- package/server/dist/providers/sessionScope.d.ts +2 -0
- package/server/dist/providers/sessionScope.js +8 -0
- package/server/dist/providers/types.d.ts +1 -0
- package/server/dist/publicProject.d.ts +10 -2
- package/server/dist/publicProject.js +59 -13
- package/server/dist/publicProjectChoice.d.ts +4 -0
- package/server/dist/publicProjectChoice.js +46 -0
- package/server/dist/quota.d.ts +10 -7
- package/server/dist/quota.js +49 -19
- package/server/dist/recall/search.js +9 -32
- package/server/dist/recall/transcriptSearch.d.ts +4 -0
- package/server/dist/recall/transcriptSearch.js +29 -0
- package/server/dist/recentFilesLedger.js +9 -7
- package/server/dist/recentProjectActivity.d.ts +11 -0
- package/server/dist/recentProjectActivity.js +69 -0
- package/server/dist/scanDeadline.d.ts +4 -0
- package/server/dist/scanDeadline.js +48 -0
- package/server/dist/searchText.d.ts +1 -0
- package/server/dist/searchText.js +22 -0
- package/server/dist/server/broadcast.d.ts +2 -2
- package/server/dist/server/broadcast.js +130 -58
- package/server/dist/sessionJsonl.js +45 -19
- package/server/dist/settings.d.ts +6 -1
- package/server/dist/settings.js +183 -56
- package/server/dist/skillManagement.d.ts +125 -0
- package/server/dist/skillManagement.js +709 -0
- package/server/dist/skillMutation.d.ts +1 -0
- package/server/dist/skillMutation.js +6 -0
- package/server/dist/skills.d.ts +75 -1
- package/server/dist/skills.js +254 -75
- package/server/dist/smartPickup.d.ts +1 -0
- package/server/dist/smartPickup.js +2 -1
- package/server/dist/smartPickupAdapters.d.ts +1 -0
- package/server/dist/smartPickupAdapters.js +31 -8
- package/server/dist/storageActions.d.ts +2 -2
- package/server/dist/storageArchive.js +55 -24
- package/server/dist/storageRoot.d.ts +5 -0
- package/server/dist/storageRoot.js +38 -0
- package/server/dist/storageTurnWatch.d.ts +6 -0
- package/server/dist/storageTurnWatch.js +36 -0
- package/server/dist/taskDispatcher.js +69 -41
- package/server/dist/templates/store.js +75 -59
- package/server/dist/terminal/ptyManager.d.ts +3 -1
- package/server/dist/terminal/ptyManager.js +44 -37
- package/server/dist/terminal/ptyPidRegistry.d.ts +4 -2
- package/server/dist/terminal/ptyPidRegistry.js +9 -63
- package/server/dist/thirdPartySkills.d.ts +4 -0
- package/server/dist/thirdPartySkills.js +80 -0
- package/server/dist/toolPath.d.ts +1 -0
- package/server/dist/toolPath.js +38 -0
- package/server/dist/toolboxWorkflow.js +2 -1
- package/server/dist/uploadImages.d.ts +6 -0
- package/server/dist/uploadImages.js +155 -0
- package/server/dist/voice/computerContext.js +2 -0
- package/server/dist/voice/conditionSchema.d.ts +1 -0
- package/server/dist/voice/conditionSchema.js +3 -1
- package/server/dist/voice/conditions.js +1 -1
- package/server/dist/workers/StreamParser.d.ts +3 -0
- package/server/dist/workers/StreamParser.js +45 -11
- package/server/dist/workers/WorkerManager.d.ts +9 -2
- package/server/dist/workers/WorkerManager.js +18 -18
- package/server/dist/workers/durablePidRegistry.d.ts +53 -0
- package/server/dist/workers/durablePidRegistry.js +289 -0
- package/server/dist/workers/limits.js +1 -1
- package/server/dist/workers/pidRegistry.d.ts +6 -9
- package/server/dist/workers/pidRegistry.js +13 -101
- package/server/dist/workers/processActivity.d.ts +6 -0
- package/server/dist/workers/processActivity.js +13 -0
- package/server/dist/workers/processKill.d.ts +30 -0
- package/server/dist/workers/processKill.js +174 -0
- package/server/dist/workers/processStartTime.d.ts +21 -5
- package/server/dist/workers/processStartTime.js +127 -50
- package/server/dist/workflowMeta.d.ts +15 -12
- package/server/dist/workflowMeta.js +42 -10
- package/server/dist/workflowStore.d.ts +1 -0
- package/server/dist/workflowStore.js +194 -23
- package/server/dist/workflows/modelTitles.js +4 -3
- package/server/dist/workflows/sessionIndex.d.ts +2 -0
- package/server/dist/workflows/sessionIndex.js +24 -2
- package/server/dist/workflows/types.d.ts +15 -5
- package/server/dist/workspace.d.ts +1 -0
- package/server/dist/workspace.js +5 -0
- package/server/dist/ws/afterTurn.d.ts +9 -0
- package/server/dist/ws/afterTurn.js +25 -0
- package/server/dist/ws/clusterHandlers.d.ts +7 -2
- package/server/dist/ws/clusterHandlers.js +361 -407
- package/server/dist/ws/clusterMembers.d.ts +42 -0
- package/server/dist/ws/clusterMembers.js +165 -0
- package/server/dist/ws/compactHandlers.js +38 -28
- package/server/dist/ws/gateHandlers.js +2 -1
- package/server/dist/ws/genesisHandlers.js +171 -116
- package/server/dist/ws/handoffHandlers.d.ts +3 -1
- package/server/dist/ws/handoffHandlers.js +367 -196
- package/server/dist/ws/previewCaptureHandlers.js +1 -4
- package/server/dist/ws/taskLedgerHandlers.d.ts +6 -1
- package/server/dist/ws/taskLedgerHandlers.js +28 -12
- package/server/dist/ws/taskLifecycle.d.ts +15 -0
- package/server/dist/ws/taskLifecycle.js +39 -0
- package/server/dist/ws/turnEngine.d.ts +27 -8
- package/server/dist/ws/turnEngine.js +1790 -1637
- package/server/dist/ws/turnPrompt.d.ts +17 -0
- package/server/dist/ws/turnPrompt.js +47 -0
- package/server/dist/ws/turnSettings.d.ts +41 -0
- package/server/dist/ws/turnSettings.js +61 -0
- package/server/dist/ws/updatePrimaryConfig.js +63 -40
- package/server/dist/ws/workflowHandlers.d.ts +2 -1
- package/server/dist/ws/workflowHandlers.js +220 -180
- package/server/package.json +1 -1
- package/server/src/appBrowsers.ts +95 -0
- package/server/src/architectureReview.ts +327 -0
- package/server/src/architectureSkill.ts +71 -0
- package/server/src/arcoHome.ts +42 -3
- package/server/src/artifactCopy.ts +90 -24
- package/server/src/atomicFile.ts +6 -1
- package/server/src/attention.ts +24 -17
- package/server/src/auth.ts +20 -6
- package/server/src/authLoginSession.ts +7 -2
- package/server/src/boundedRead.ts +172 -0
- package/server/src/capabilities.ts +26 -9
- package/server/src/catchUp.ts +19 -2
- package/server/src/checkedFile.ts +90 -0
- package/server/src/claudeTransport.ts +14 -0
- package/server/src/clusterAutoTurn.ts +55 -7
- package/server/src/clusterBusyReminder.ts +45 -0
- package/server/src/clusterDirector.ts +6 -3
- package/server/src/clusterIdleNudger.ts +6 -0
- package/server/src/clusterMailbox.ts +96 -26
- package/server/src/clusterPeerOps.ts +6 -19
- package/server/src/clusterPlanBridge.ts +37 -45
- package/server/src/clusterPresets.ts +44 -31
- package/server/src/clusterProgress.ts +3 -0
- package/server/src/clusterSnapshots.ts +16 -2
- package/server/src/clusterStore.ts +25 -14
- package/server/src/clusterTurnTools.ts +11 -0
- package/server/src/commandShell.ts +287 -0
- package/server/src/compactionCounter.ts +69 -0
- package/server/src/compactionReport.ts +20 -0
- package/server/src/contentSearch.ts +8 -3
- package/server/src/contextCalibrator.ts +6 -1
- package/server/src/contextEstimator.ts +71 -16
- package/server/src/contextRefs.ts +41 -11
- package/server/src/conversationActivity.ts +26 -0
- package/server/src/cursorUsage.ts +13 -3
- package/server/src/diagnostics/checks.ts +4 -11
- package/server/src/diagnostics/executableLookup.ts +20 -0
- package/server/src/diagnostics/modelHealth.ts +3 -11
- package/server/src/diagnostics/supportBundle.ts +5 -13
- package/server/src/eventLog.ts +228 -81
- package/server/src/existingClusterMembers.ts +9 -0
- package/server/src/explorerArtifacts.ts +27 -10
- package/server/src/explorerChanged.ts +99 -67
- package/server/src/explorerDocs.ts +37 -31
- package/server/src/explorerLaunch.ts +10 -2
- package/server/src/fileAccessPolicy.ts +82 -1
- package/server/src/fileContent/decodeSlots.ts +31 -0
- package/server/src/fileContent/detect.ts +28 -0
- package/server/src/fileContent/externalImage.ts +49 -0
- package/server/src/fileContent/icons.ts +37 -0
- package/server/src/fileContent/images.ts +140 -0
- package/server/src/fileContent/legacyText.ts +16 -0
- package/server/src/fileContent/notebook.ts +37 -0
- package/server/src/fileContent/office.ts +234 -0
- package/server/src/fileContent/pdf.ts +59 -0
- package/server/src/fileContent/pngRows.ts +54 -0
- package/server/src/fileContent/svg.ts +42 -0
- package/server/src/fileContent/types.ts +39 -0
- package/server/src/fileContent/worker.ts +43 -0
- package/server/src/fileContent.ts +108 -0
- package/server/src/fileContextReceipts.ts +44 -0
- package/server/src/fileFetch.ts +167 -0
- package/server/src/fileVersion.ts +36 -0
- package/server/src/genesis/creative.ts +27 -33
- package/server/src/genesis/prompts.ts +3 -0
- package/server/src/genesis/savePlan.ts +45 -0
- package/server/src/genesis/stages.ts +4 -4
- package/server/src/gitDiff.ts +20 -5
- package/server/src/gitSnapshots.ts +288 -191
- package/server/src/gitWorking.ts +11 -11
- package/server/src/github.ts +3 -1
- package/server/src/goalRun.ts +7 -4
- package/server/src/handoffHistory.ts +89 -0
- package/server/src/handoffHistoryProtocol.ts +20 -0
- package/server/src/handoffHistorySupport.ts +10 -0
- package/server/src/handoffHistoryTool.ts +192 -0
- package/server/src/handoffPrompts.ts +6 -4
- package/server/src/handoffReplay.ts +20 -0
- package/server/src/handoffSeedCache.ts +22 -0
- package/server/src/http/appBrowserRoutes.ts +17 -0
- package/server/src/http/architectureReviewRoutes.ts +86 -0
- package/server/src/http/clusterRoutes.ts +13 -1
- package/server/src/http/clusterSnapshotRoutes.ts +8 -3
- package/server/src/http/connectionsRoutes.ts +5 -1
- package/server/src/http/diffRoutes.ts +36 -3
- package/server/src/http/explorerRoot.ts +20 -0
- package/server/src/http/explorerRoutes.ts +59 -12
- package/server/src/http/fileRead.ts +2 -1
- package/server/src/http/fileWriteRoutes.ts +3 -2
- package/server/src/http/gitCompareRoutes.ts +4 -5
- package/server/src/http/gitDiffRoutes.ts +3 -2
- package/server/src/http/gitOpRoutes.ts +3 -4
- package/server/src/http/gitWorktreeRoutes.ts +3 -2
- package/server/src/http/handoffHistoryRoutes.ts +42 -0
- package/server/src/http/imageWriteRoutes.ts +5 -1
- package/server/src/http/knowledgeRoutes.ts +2 -0
- package/server/src/http/mediaOpsRoutes.ts +2 -1
- package/server/src/http/originGuard.ts +71 -14
- package/server/src/http/outputRoutes.ts +26 -5
- package/server/src/http/projectBinding.ts +108 -0
- package/server/src/http/providerThrottleRoutes.ts +76 -0
- package/server/src/http/publicProjectRoutes.ts +40 -8
- package/server/src/http/readConfinement.ts +16 -9
- package/server/src/http/router.ts +173 -60
- package/server/src/http/searchRoutes.ts +4 -4
- package/server/src/http/sessionTransport.ts +27 -0
- package/server/src/http/skillManagementRoutes.ts +120 -0
- package/server/src/http/storageRoutes.ts +19 -6
- package/server/src/http/utilityAgentRoutes.ts +19 -5
- package/server/src/http/workflowDataRoutes.ts +68 -16
- package/server/src/http/writeConfinement.ts +31 -12
- package/server/src/http/wsAuth.ts +27 -9
- package/server/src/imageTokens.ts +60 -0
- package/server/src/index.ts +265 -178
- package/server/src/inputDeliveryHistory.ts +122 -0
- package/server/src/keepStore.ts +37 -0
- package/server/src/knowledge/store.ts +27 -19
- package/server/src/legacyTarRestore.ts +177 -0
- package/server/src/llamacppCatalog.ts +47 -12
- package/server/src/localRuntimeStatus.ts +121 -0
- package/server/src/lsp/client.ts +19 -11
- package/server/src/lsp/servers.ts +2 -2
- package/server/src/managedPath.ts +38 -0
- package/server/src/management/hubGuard.ts +135 -0
- package/server/src/management/hubLink.ts +8 -2
- package/server/src/management/initHubLink.ts +45 -37
- package/server/src/manualCompactCapability.ts +8 -0
- package/server/src/mcp/arcoMcpServer.ts +4 -0
- package/server/src/mcp/client.ts +28 -11
- package/server/src/mcp/clusterMcpLoopback.ts +27 -1
- package/server/src/mcp/clusterMcpTools.ts +24 -25
- package/server/src/mcp/fileContent.ts +34 -0
- package/server/src/mcp/fileMcpServer.ts +12 -0
- package/server/src/mcp/fileMcpTools.ts +51 -0
- package/server/src/mcp/handoffHistoryMcpTools.ts +21 -0
- package/server/src/mcp/mcpConfigWriter.ts +43 -12
- package/server/src/mcp/planMcpTools.ts +9 -285
- package/server/src/mcp/planReadMcpServer.ts +19 -0
- package/server/src/mcp/registry.ts +41 -35
- package/server/src/mcp/registryWiring.ts +4 -5
- package/server/src/media/demucs.ts +11 -4
- package/server/src/media/ffmpeg.ts +21 -16
- package/server/src/media/scratch.ts +17 -10
- package/server/src/noticeSource.ts +11 -0
- package/server/src/notifications.ts +8 -4
- package/server/src/npmPlatformResolve.ts +25 -8
- package/server/src/ntfyTransport.ts +12 -4
- package/server/src/outputGrants.ts +53 -0
- package/server/src/outputs.ts +54 -11
- package/server/src/peerRecipientContext.ts +16 -5
- package/server/src/planStore.ts +201 -55
- package/server/src/planTools.ts +303 -0
- package/server/src/previewAutoDetect.ts +26 -19
- package/server/src/previewPortConfiguration.ts +28 -0
- package/server/src/previewPorts.ts +2 -0
- package/server/src/previewProxy.ts +156 -189
- package/server/src/primaryBackgroundTracker.ts +151 -61
- package/server/src/primitives/exportContext.ts +67 -16
- package/server/src/primitives/localFileContext.ts +31 -0
- package/server/src/primitives/reviewContent.ts +42 -7
- package/server/src/primitives/runCompare.ts +1 -1
- package/server/src/primitives/runDocEdit.ts +1 -1
- package/server/src/primitives/runMdTuneup.ts +17 -27
- package/server/src/primitives/runResearch.ts +1 -1
- package/server/src/primitives/runReviewer.ts +6 -2
- package/server/src/primitives/seedWorker.ts +36 -17
- package/server/src/project/orchestrationProposals.ts +6 -1
- package/server/src/project/taskLedger.ts +17 -11
- package/server/src/projectGlob.ts +9 -0
- package/server/src/projectIgnore.ts +19 -0
- package/server/src/projectScan.ts +76 -0
- package/server/src/projectStateIgnore.ts +40 -1
- package/server/src/projects.ts +114 -36
- package/server/src/prompts.ts +5 -8
- package/server/src/proportionateTestingSkill.ts +31 -0
- package/server/src/providers/attachmentLabels.ts +8 -0
- package/server/src/providers/attachments.ts +52 -174
- package/server/src/providers/claude-native/apiEndpoint.ts +9 -0
- package/server/src/providers/claude-native/appendOnlyPrefix.ts +17 -1
- package/server/src/providers/claude-native/catalog.ts +16 -14
- package/server/src/providers/claude-native/contentBlocks.ts +39 -8
- package/server/src/providers/claude-native/contextBudget.ts +0 -6
- package/server/src/providers/claude-native/editApply.ts +6 -1
- package/server/src/providers/claude-native/fileContent.ts +98 -0
- package/server/src/providers/claude-native/filterConfigs/bash-cargo-test.ts +1 -0
- package/server/src/providers/claude-native/filterConfigs/bash-jest-vitest.ts +1 -0
- package/server/src/providers/claude-native/filterConfigs/bash-pytest.ts +1 -0
- package/server/src/providers/claude-native/filterConfigs/index.ts +2 -1
- package/server/src/providers/claude-native/foldDigest.ts +9 -2
- package/server/src/providers/claude-native/gateReview.ts +0 -0
- package/server/src/providers/claude-native/hookIf.ts +414 -0
- package/server/src/providers/claude-native/hooks.ts +398 -54
- package/server/src/providers/claude-native/imageRead.ts +92 -0
- package/server/src/providers/claude-native/index.ts +32 -1
- package/server/src/providers/claude-native/mediaLimits.ts +14 -0
- package/server/src/providers/claude-native/mediaRetention.ts +49 -0
- package/server/src/providers/claude-native/mediaRetirementNotice.ts +8 -0
- package/server/src/providers/claude-native/modelParams.ts +23 -2
- package/server/src/providers/claude-native/oauth.ts +9 -8
- package/server/src/providers/claude-native/outputAccumulator.ts +29 -17
- package/server/src/providers/claude-native/peerTools.ts +3 -169
- package/server/src/providers/claude-native/pretoolGuards.ts +76 -9
- package/server/src/providers/claude-native/registryTools.ts +4 -2
- package/server/src/providers/claude-native/resumeSummary.ts +138 -28
- package/server/src/providers/claude-native/sandboxExecutor.ts +24 -16
- package/server/src/providers/claude-native/taskAdmission.ts +62 -0
- package/server/src/providers/claude-native/toolChecks.ts +127 -0
- package/server/src/providers/claude-native/toolPosture.ts +5 -3
- package/server/src/providers/claude-native/toolResultEviction.ts +17 -7
- package/server/src/providers/claude-native/tools.ts +228 -130
- package/server/src/providers/claude-native/usageContext.ts +93 -0
- package/server/src/providers/claude-native/wireFingerprint.ts +2 -2
- package/server/src/providers/claude-native/worker.ts +1056 -334
- package/server/src/providers/claude-native/workerHelpers.ts +133 -6
- package/server/src/providers/claude-native/workspaceFacts.ts +2 -2
- package/server/src/providers/claude.ts +65 -93
- package/server/src/providers/clusterTaskToolDefinitions.ts +180 -0
- package/server/src/providers/codex-appserver/catalog.ts +26 -19
- package/server/src/providers/codex-appserver/index.ts +8 -3
- package/server/src/providers/codex-appserver/jsonRpc.ts +9 -2
- package/server/src/providers/codex-appserver/worker.ts +108 -77
- package/server/src/providers/codex.ts +49 -57
- package/server/src/providers/codexChatBoundary.ts +55 -0
- package/server/src/providers/codexCodeMode.ts +2 -2
- package/server/src/providers/codexContextWindow.ts +2 -2
- package/server/src/providers/codexHome.ts +6 -0
- package/server/src/providers/codexImageTool.ts +22 -0
- package/server/src/providers/codexVersion.ts +13 -0
- package/server/src/providers/codexWebSearch.ts +5 -0
- package/server/src/providers/cursor/acpJsonRpc.ts +3 -1
- package/server/src/providers/cursor/authState.ts +72 -0
- package/server/src/providers/cursor/catalog.ts +20 -13
- package/server/src/providers/cursor/chatSandbox.ts +71 -0
- package/server/src/providers/cursor/filePlugin.ts +27 -0
- package/server/src/providers/cursor/index.ts +29 -4
- package/server/src/providers/cursor/modelMap.ts +182 -0
- package/server/src/providers/cursor/print.ts +80 -27
- package/server/src/providers/cursor/worker.ts +156 -84
- package/server/src/providers/errorClassifier.ts +7 -2
- package/server/src/providers/handoffHistoryBinding.ts +40 -0
- package/server/src/providers/index.ts +12 -6
- package/server/src/providers/llamacpp.ts +93 -176
- package/server/src/providers/llamacppManager.ts +62 -33
- package/server/src/providers/llamacppVersion.ts +4 -0
- package/server/src/providers/lmstudio.ts +124 -190
- package/server/src/providers/localFileMedia.ts +229 -0
- package/server/src/providers/localMcp.ts +76 -0
- package/server/src/providers/localShellLifecycle.ts +30 -0
- package/server/src/providers/localToolDispatch.ts +111 -0
- package/server/src/providers/ollama.ts +161 -171
- package/server/src/providers/ollamaCtxFallback.ts +1 -2
- package/server/src/providers/ollamaDurableCompaction.ts +5 -4
- package/server/src/providers/ollamaExecutionHistory.ts +40 -13
- package/server/src/providers/ollamaFencedTools.ts +10 -11
- package/server/src/providers/ollamaResilience.ts +10 -13
- package/server/src/providers/ollamaTokens.ts +4 -7
- package/server/src/providers/ollamaToolSubset.ts +14 -2
- package/server/src/providers/ollamaTools.ts +212 -200
- package/server/src/providers/outputStyle.ts +72 -72
- package/server/src/providers/providerFileContent.ts +133 -0
- package/server/src/providers/renderedTranscript.ts +2 -0
- package/server/src/providers/requestDeadline.ts +27 -0
- package/server/src/providers/sessionScope.ts +9 -0
- package/server/src/providers/types.ts +3 -0
- package/server/src/publicProject.ts +54 -13
- package/server/src/publicProjectChoice.ts +39 -0
- package/server/src/quota.ts +48 -23
- package/server/src/recall/search.ts +9 -32
- package/server/src/recall/transcriptSearch.ts +27 -0
- package/server/src/recentFilesLedger.ts +10 -8
- package/server/src/recentProjectActivity.ts +56 -0
- package/server/src/scanDeadline.ts +26 -0
- package/server/src/searchText.ts +16 -0
- package/server/src/server/broadcast.ts +120 -54
- package/server/src/sessionJsonl.ts +31 -17
- package/server/src/settings.ts +137 -41
- package/server/src/skillManagement.ts +585 -0
- package/server/src/skillMutation.ts +6 -0
- package/server/src/skills.ts +195 -25
- package/server/src/smartPickup.ts +3 -2
- package/server/src/smartPickupAdapters.ts +31 -10
- package/server/src/storageActions.ts +1 -1
- package/server/src/storageArchive.ts +42 -22
- package/server/src/storageRoot.ts +30 -0
- package/server/src/storageTurnWatch.ts +39 -0
- package/server/src/taskDispatcher.ts +22 -2
- package/server/src/templates/store.ts +72 -57
- package/server/src/terminal/ptyManager.ts +37 -27
- package/server/src/terminal/ptyPidRegistry.ts +10 -58
- package/server/src/thirdPartySkills.ts +79 -0
- package/server/src/toolPath.ts +31 -0
- package/server/src/toolboxWorkflow.ts +2 -1
- package/server/src/uploadImages.ts +124 -0
- package/server/src/voice/computerContext.ts +2 -1
- package/server/src/voice/conditionSchema.ts +3 -1
- package/server/src/voice/conditions.ts +1 -1
- package/server/src/workers/StreamParser.ts +42 -11
- package/server/src/workers/WorkerManager.ts +32 -35
- package/server/src/workers/durablePidRegistry.ts +266 -0
- package/server/src/workers/limits.ts +1 -1
- package/server/src/workers/pidRegistry.ts +15 -89
- package/server/src/workers/processActivity.ts +14 -0
- package/server/src/workers/processKill.ts +175 -1
- package/server/src/workers/processStartTime.ts +137 -49
- package/server/src/workflowMeta.ts +59 -19
- package/server/src/workflowStore.ts +177 -22
- package/server/src/workflows/modelTitles.ts +4 -3
- package/server/src/workflows/sessionIndex.ts +24 -3
- package/server/src/workflows/types.ts +20 -10
- package/server/src/workspace.ts +6 -0
- package/server/src/ws/afterTurn.ts +34 -0
- package/server/src/ws/clusterHandlers.ts +198 -276
- package/server/src/ws/clusterMembers.ts +204 -0
- package/server/src/ws/compactHandlers.ts +38 -11
- package/server/src/ws/gateHandlers.ts +2 -1
- package/server/src/ws/genesisHandlers.ts +49 -6
- package/server/src/ws/handoffHandlers.ts +168 -53
- package/server/src/ws/previewCaptureHandlers.ts +1 -4
- package/server/src/ws/taskLedgerHandlers.ts +22 -13
- package/server/src/ws/taskLifecycle.ts +41 -0
- package/server/src/ws/turnEngine.ts +488 -366
- package/server/src/ws/turnPrompt.ts +60 -0
- package/server/src/ws/turnSettings.ts +95 -0
- package/server/src/ws/updatePrimaryConfig.ts +55 -31
- package/server/src/ws/workflowHandlers.ts +187 -158
- package/shared/dist/clusterCoordination.js +15 -7
- package/shared/dist/clusterRolePresets.js +8 -6
- package/shared/dist/codexChat.d.ts +2 -0
- package/shared/dist/codexChat.js +5 -0
- package/shared/dist/folderName.d.ts +1 -0
- package/shared/dist/folderName.js +18 -0
- package/shared/dist/index.d.ts +6 -0
- package/shared/dist/index.js +6 -0
- package/shared/dist/localRuntimeStatus.d.ts +23 -0
- package/shared/dist/localRuntimeStatus.js +47 -0
- package/shared/dist/notificationTitle.d.ts +9 -0
- package/shared/dist/notificationTitle.js +23 -0
- package/shared/dist/outputStyle.d.ts +10 -0
- package/shared/dist/outputStyle.js +28 -0
- package/shared/dist/outputs.d.ts +1 -0
- package/shared/dist/protocol/autoPickup.d.ts +2 -0
- package/shared/dist/protocol/chat.d.ts +4 -0
- package/shared/dist/protocol/checkpoints.d.ts +24 -2
- package/shared/dist/protocol/checkpoints.js +1 -0
- package/shared/dist/protocol/clientMessages.d.ts +9 -14
- package/shared/dist/protocol/clusters.d.ts +21 -4
- package/shared/dist/protocol/clusters.js +3 -3
- package/shared/dist/protocol/connections.d.ts +2 -0
- package/shared/dist/protocol/diagnostics.js +1 -1
- package/shared/dist/protocol/genesis.d.ts +9 -0
- package/shared/dist/protocol/mcp.d.ts +1 -0
- package/shared/dist/protocol/mcp.js +8 -5
- package/shared/dist/protocol/mdTuneup.d.ts +2 -0
- package/shared/dist/protocol/models.d.ts +3 -1
- package/shared/dist/protocol/models.js +19 -8
- package/shared/dist/protocol/notifications.d.ts +2 -1
- package/shared/dist/protocol/notifications.js +15 -3
- package/shared/dist/protocol/plans.d.ts +2 -1
- package/shared/dist/protocol/remoteManagement.d.ts +6 -0
- package/shared/dist/protocol/serverMessages.d.ts +69 -10
- package/shared/dist/protocol/settings.d.ts +16 -4
- package/shared/dist/protocol/settings.js +17 -1
- package/shared/dist/protocol/tasks.d.ts +1 -0
- package/shared/dist/protocol/usage.d.ts +1 -0
- package/shared/dist/protocol/workers.d.ts +1 -0
- package/shared/dist/protocol/workflows.d.ts +73 -14
- package/shared/dist/protocol/workflows.js +66 -0
- package/shared/dist/publicGuardrails.d.ts +1 -1
- package/shared/dist/publicGuardrails.js +1 -1
- package/shared/dist/runtimeVersions.d.ts +2 -0
- package/shared/dist/runtimeVersions.js +13 -0
- package/shared/dist/shellTool.d.ts +2 -0
- package/shared/dist/shellTool.js +9 -0
- package/shared/src/clusterCoordination.ts +12 -7
- package/shared/src/clusterRolePresets.ts +8 -6
- package/shared/src/codexChat.ts +8 -0
- package/shared/src/folderName.ts +11 -0
- package/shared/src/index.ts +8 -0
- package/shared/src/localRuntimeStatus.ts +53 -0
- package/shared/src/notificationTitle.ts +23 -0
- package/shared/src/outputStyle.ts +35 -0
- package/shared/src/outputs.ts +3 -0
- package/shared/src/protocol/autoPickup.ts +2 -0
- package/shared/src/protocol/chat.ts +5 -0
- package/shared/src/protocol/checkpoints.ts +40 -8
- package/shared/src/protocol/clientMessages.ts +11 -11
- package/shared/src/protocol/clusters.ts +40 -10
- package/shared/src/protocol/connections.ts +6 -0
- package/shared/src/protocol/diagnostics.ts +1 -1
- package/shared/src/protocol/genesis.ts +11 -0
- package/shared/src/protocol/mcp.ts +12 -7
- package/shared/src/protocol/mdTuneup.ts +4 -2
- package/shared/src/protocol/models.ts +22 -8
- package/shared/src/protocol/notifications.ts +16 -3
- package/shared/src/protocol/plans.ts +5 -7
- package/shared/src/protocol/remoteManagement.ts +10 -3
- package/shared/src/protocol/serverMessages.ts +88 -7
- package/shared/src/protocol/settings.ts +35 -5
- package/shared/src/protocol/tasks.ts +1 -0
- package/shared/src/protocol/usage.ts +3 -3
- package/shared/src/protocol/workers.ts +5 -0
- package/shared/src/protocol/workflows.ts +133 -21
- package/shared/src/publicGuardrails.ts +1 -1
- package/shared/src/runtimeVersions.ts +15 -0
- package/shared/src/shellTool.ts +9 -0
- package/client/dist/assets/galleryEditor-fPb76Cjv.js +0 -702
- package/client/dist/assets/index-CjkHb-_n.js +0 -592
- package/client/dist/assets/index-DIbh3ae5.css +0 -1
- package/client/src/components/ConversationMenu.tsx +0 -467
- package/client/src/stores/sessionIndexStore.ts +0 -92
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mintHandoffHistoryCapability } from '../http/handoffHistoryRoutes.js';
|
|
2
|
+
import { deliverAfterTurnRevoked } from './taskLifecycle.js';
|
|
3
|
+
import { resolveClaudeTransport } from '../claudeTransport.js';
|
|
4
|
+
import { projectLocalFileReferences } from '../primitives/localFileContext.js';
|
|
5
|
+
import { getEffectivePublicProjectChoice } from '../publicProjectChoice.js';
|
|
6
|
+
import { buildMessageGuardPolicy, storedOutputStyle } from '@arco/shared';
|
|
2
7
|
import * as attention from '../attention.js';
|
|
3
8
|
import { acquireCheckoutWriter, assertCheckoutAvailable, workflowWritePaths, observeCheckoutWriters } from '../checkoutOwnership.js';
|
|
4
9
|
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import path from 'node:path';
|
|
5
11
|
import { projectOllamaHistory, stampOllamaExecution } from '../providers/ollamaExecutionHistory.js';
|
|
6
12
|
import { publishActivity, computerProjectionChanged } from '../voice/activityBus.js';
|
|
7
13
|
import { setComputerBackgroundClaim, clearComputerBackgroundClaim, isComputerBackgroundClaim } from '../voice/operatorTools.js';
|
|
8
14
|
import { watchClaimed, watchSettled } from '../voice/watches.js';
|
|
9
15
|
import { renderComputerHistory } from '../voice/history.js';
|
|
10
16
|
import { computerReplayEvents, announceComputerSettled } from '../voice/computerContext.js';
|
|
11
|
-
import { VOICE_OPERATOR_PROMPT } from '../voice/operatorPrompt.js';
|
|
12
17
|
import { COMPUTER_TIMEOUT } from '../voice/turnWatchdog.js';
|
|
13
|
-
import { isAutoCompactionPolicy, resolveProviderAutoCompaction } from '@arco/shared';
|
|
18
|
+
import { AUTO_HANDOFF_DEFAULT_COMPACTIONS, autoHandoffAvailability, clampAutoHandoffCompactions, isAutoCompactionPolicy, normalizeAutoHandoff, resolveProviderAutoCompaction } from '@arco/shared';
|
|
19
|
+
import { compactionsThisConversation } from '../compactionCounter.js';
|
|
14
20
|
import { WebSocket } from 'ws';
|
|
15
21
|
import { discoverClaudeMdFiles } from '../claudeMdDiscovery.js';
|
|
16
22
|
import { buildKnowledgeBlock } from '../knowledge/store.js';
|
|
@@ -21,6 +27,7 @@ import { summarizeTurnChanges, timelyCheckpoint, shouldCaptureTurn } from '../tu
|
|
|
21
27
|
import { isManagedBakeoffWorktree } from '../gitBakeoff.js';
|
|
22
28
|
import * as clusterMailbox from '../clusterMailbox.js';
|
|
23
29
|
import * as clusterPlanBridge from '../clusterPlanBridge.js';
|
|
30
|
+
import { clusterToolsPending, CLUSTER_TOOLS_PENDING_NOTICE, CLUSTER_TOOLS_PENDING_AGENT } from '../clusterTurnTools.js';
|
|
24
31
|
import * as clusterStore from '../clusterStore.js';
|
|
25
32
|
import * as clusterEfficiency from '../clusterEfficiency.js';
|
|
26
33
|
import { BLIND_CLUSTER_DOCTRINE } from '../clusterAccessDoctrine.js';
|
|
@@ -47,15 +54,20 @@ import { isAvailable } from '../quota.js';
|
|
|
47
54
|
import { resolveProviderAccount } from '../providerAccounts.js';
|
|
48
55
|
import { broadcastTransient, broadcastWorkflow, notifyClusterStateForWorkflow, send } from '../server/broadcast.js';
|
|
49
56
|
import { FOREIGN_WARN_DEBOUNCE_MS, FOREIGN_WRITE_BLOCK_MS, PORT, SESSION_HISTORY_PAGE_SIZE } from '../server/constants.js';
|
|
50
|
-
import { buildLocalClusterSystemPrompt, LLAMACPP_PRIMARY_SYSTEM_PROMPT, OLLAMA_PRIMARY_SYSTEM_PROMPT
|
|
57
|
+
import { buildLocalClusterSystemPrompt, LLAMACPP_PRIMARY_SYSTEM_PROMPT, OLLAMA_PRIMARY_SYSTEM_PROMPT } from '../server/prompts.js';
|
|
51
58
|
import { buildGenesisSystemBlock } from '../genesis/prompts.js';
|
|
52
59
|
import { CHAT_PROVIDERS, chatSystemPrompt, chatWebArmed, isChatWorkflow } from '../chatMode.js';
|
|
60
|
+
import { resolveNativeInTurnCompactPercent, resolveTurnSettings } from './turnSettings.js';
|
|
61
|
+
import { composeBasePrompts } from './turnPrompt.js';
|
|
62
|
+
import { runAfterTurn } from './afterTurn.js';
|
|
53
63
|
import { sessions, workflows } from '../server/state.js';
|
|
54
64
|
import { loadSessionJsonl, resolveSessionJsonlPath, watchSessionJsonl } from '../sessionJsonl.js';
|
|
55
65
|
import { startUltracodeFleetWatcher } from '../ultracodeFleetWatcher.js';
|
|
56
66
|
import { readSettings } from '../settings.js';
|
|
57
|
-
import { buildPickedSkillsBlock, buildPinnedSkillsBlock, resolvePinnedSkills, buildSkillsManifest, listSkills, readSkillBody } from '../skills.js';
|
|
58
|
-
import {
|
|
67
|
+
import { buildPickedSkillsBlock, buildPinnedSkillsBlock, resolvePinnedSkills, buildSkillsManifest, listSkills, readSkillBody, readBuiltinSkill, } from '../skills.js';
|
|
68
|
+
import { ARCHITECTURE_REVIEW_SLUG, architectureReviewFacts } from '../architectureReview.js';
|
|
69
|
+
import { artifactsDir } from '../workers/limits.js';
|
|
70
|
+
import { ensureMeta, readMeta, reconcileLatestCliSession, updateMeta, workflowDir } from '../workflowMeta.js';
|
|
59
71
|
import { currentSeq as currentWorkflowSeq, replayEvents as replayWorkflowEvents } from '../workflowStore.js';
|
|
60
72
|
import { latestCodexTokenSnapshot } from '../workflows/transcripts.js';
|
|
61
73
|
import { foldClaudeNativeWorker } from '../providers/claude-native/index.js';
|
|
@@ -69,7 +81,14 @@ const PUBLIC_REPO_SAFETY_SYSTEM_BLOCK = [
|
|
|
69
81
|
'Never publish sensitive material. If a file or value is ambiguous, stop and ask the operator before committing or pushing.',
|
|
70
82
|
].join('\n');
|
|
71
83
|
let deps;
|
|
72
|
-
export function initTurnEngine(d) {
|
|
84
|
+
export function initTurnEngine(d) {
|
|
85
|
+
deps = d;
|
|
86
|
+
clusterStore.setMemberJoinedListener((clusterId, workflowId) => {
|
|
87
|
+
if (clusterToolsPending(workflows.get(workflowId), clusterId)) {
|
|
88
|
+
broadcastWorkflow(workflowId, { type: 'system_notice', workflowId, content: CLUSTER_TOOLS_PENDING_NOTICE });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
73
92
|
// Extract renderable entries from a raw Claude session JSONL line. A single
|
|
74
93
|
// line can produce 0..N entries: assistant messages often contain a text
|
|
75
94
|
// block plus one or more tool_use blocks, and we want each to show up
|
|
@@ -195,19 +214,7 @@ export function toSessionEntries(raw) {
|
|
|
195
214
|
}
|
|
196
215
|
return out;
|
|
197
216
|
}
|
|
198
|
-
|
|
199
|
-
// (the harness WorkflowTool lives only in the `claude` binary), else explicit
|
|
200
|
-
// per-tab config wins, else the cwd's TRANSPORT DEFAULTS cascade, else 'cli'.
|
|
201
|
-
// Same precedence as the turn dispatcher — keep the two in sync.
|
|
202
|
-
export async function resolveClaudeTransport(wf, cwd) {
|
|
203
|
-
if (wf.primary.provider === 'claude' && wf.config.ultracode === true)
|
|
204
|
-
return 'cli';
|
|
205
|
-
if (wf.config.claudeTransport === 'native' || wf.config.claudeTransport === 'cli') {
|
|
206
|
-
return wf.config.claudeTransport;
|
|
207
|
-
}
|
|
208
|
-
const cascade = await readSettings(cwd).catch(() => null);
|
|
209
|
-
return cascade?.claude?.transport === 'native' ? 'native' : 'cli';
|
|
210
|
-
}
|
|
217
|
+
export { resolveClaudeTransport } from '../claudeTransport.js';
|
|
211
218
|
// Start watching Claude's session JSONL for a workflow.
|
|
212
219
|
// `initialWs` receives the historical entries; new entries go to all observers.
|
|
213
220
|
// No-op for non-Claude providers, when primarySessionId is absent, or on the
|
|
@@ -217,23 +224,26 @@ export async function resolveClaudeTransport(wf, cwd) {
|
|
|
217
224
|
// synthetic "No response requested." rows — render as agent replies while
|
|
218
225
|
// ChatPanel's sessionChat-canonical mode hid every real finalized answer
|
|
219
226
|
// otherwise stale session entries could hide finalized answers.
|
|
227
|
+
const sessionWatcherEpochs = new WeakMap();
|
|
220
228
|
export function startSessionWatcher(workflowId, wf, cwd, initialWs) {
|
|
221
|
-
|
|
222
|
-
|
|
229
|
+
const epoch = (sessionWatcherEpochs.get(wf) ?? 0) + 1;
|
|
230
|
+
sessionWatcherEpochs.set(wf, epoch);
|
|
223
231
|
const sessionId = wf.primarySessionId;
|
|
224
|
-
if (!sessionId)
|
|
225
|
-
return;
|
|
226
232
|
if (wf.sessionWatcher) {
|
|
227
233
|
wf.sessionWatcher();
|
|
228
234
|
wf.sessionWatcher = null;
|
|
229
235
|
}
|
|
236
|
+
if (wf.primary.provider !== 'claude' || !sessionId)
|
|
237
|
+
return;
|
|
238
|
+
const current = () => workflows.get(workflowId) === wf && wf.primarySessionId === sessionId
|
|
239
|
+
&& sessionWatcherEpochs.get(wf) === epoch && wf.primary.provider === 'claude';
|
|
230
240
|
const path = resolveSessionJsonlPath(cwd, sessionId);
|
|
231
241
|
resolveClaudeTransport(wf, cwd).then((transport) => {
|
|
232
|
-
if (transport === 'native')
|
|
242
|
+
if (!current() || transport === 'native')
|
|
233
243
|
return null;
|
|
234
244
|
return loadSessionJsonl(path);
|
|
235
245
|
}).then((loaded) => {
|
|
236
|
-
if (!loaded)
|
|
246
|
+
if (!loaded || !current())
|
|
237
247
|
return;
|
|
238
248
|
const { entries, byteLength } = loaded;
|
|
239
249
|
// Tail-first: only the last N raw entries go out immediately. Anything
|
|
@@ -267,6 +277,8 @@ export function startSessionWatcher(workflowId, wf, cwd, initialWs) {
|
|
|
267
277
|
if (!workflows.has(workflowId))
|
|
268
278
|
return; // workflow removed while loading
|
|
269
279
|
const dispose = watchSessionJsonl(path, byteLength, (raw) => {
|
|
280
|
+
if (!current())
|
|
281
|
+
return;
|
|
270
282
|
// Concurrent-session detection. Live writes with an entrypoint other
|
|
271
283
|
// than 'sdk-cli' mean a native `claude --resume` terminal is writing
|
|
272
284
|
// to this same JSONL. Flag the workflow, and emit a debounced chat
|
|
@@ -295,7 +307,7 @@ export function startSessionWatcher(workflowId, wf, cwd, initialWs) {
|
|
|
295
307
|
}
|
|
296
308
|
});
|
|
297
309
|
const wfNow = workflows.get(workflowId);
|
|
298
|
-
if (wfNow) {
|
|
310
|
+
if (wfNow && current()) {
|
|
299
311
|
wfNow.sessionWatcher = dispose;
|
|
300
312
|
}
|
|
301
313
|
else {
|
|
@@ -317,17 +329,17 @@ export function derivePrimaryConfig(config) {
|
|
|
317
329
|
};
|
|
318
330
|
}
|
|
319
331
|
export function deriveAutoHandoff(config) {
|
|
332
|
+
const saved = normalizeAutoHandoff(config.autoHandoff);
|
|
320
333
|
return {
|
|
321
|
-
enabled:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
autoFired: false,
|
|
334
|
+
enabled: saved?.enabled ?? false,
|
|
335
|
+
afterCompactions: saved?.afterCompactions ?? AUTO_HANDOFF_DEFAULT_COMPACTIONS,
|
|
336
|
+
compactions: 0,
|
|
337
|
+
fired: false,
|
|
326
338
|
// WP5 — carry through verbatim (no defaulting); resolution happens at
|
|
327
339
|
// fire time so a later change to the global default still affects tabs
|
|
328
340
|
// that never set a per-tab override.
|
|
329
|
-
mode:
|
|
330
|
-
summarizer:
|
|
341
|
+
mode: saved?.mode,
|
|
342
|
+
summarizer: saved?.summarizer,
|
|
331
343
|
};
|
|
332
344
|
}
|
|
333
345
|
// §2.1 — mirror WorkflowConfig.autoFold into the live state shape (carrying the
|
|
@@ -345,23 +357,30 @@ export function deriveAutoFold(config) {
|
|
|
345
357
|
};
|
|
346
358
|
}
|
|
347
359
|
export function applyAutoHandoffDefault(config, defaults) {
|
|
360
|
+
// A config from an older client or saved file may carry percent fields.
|
|
361
|
+
if (config.autoHandoff !== undefined) {
|
|
362
|
+
const saved = normalizeAutoHandoff(config.autoHandoff);
|
|
363
|
+
if (saved)
|
|
364
|
+
config.autoHandoff = saved;
|
|
365
|
+
else
|
|
366
|
+
delete config.autoHandoff;
|
|
367
|
+
}
|
|
348
368
|
if (config.autoHandoff)
|
|
349
369
|
return false;
|
|
350
370
|
if (!defaults)
|
|
351
371
|
return false;
|
|
352
372
|
if (defaults.enabled === undefined
|
|
353
|
-
&& defaults.
|
|
354
|
-
&& defaults.autoAt === undefined
|
|
373
|
+
&& defaults.afterCompactions === undefined
|
|
355
374
|
&& defaults.mode === undefined
|
|
356
375
|
&& defaults.summarizer === undefined)
|
|
357
376
|
return false;
|
|
358
|
-
|
|
377
|
+
// Through normalizeAutoHandoff so the saved form carries the 0.1.4 fields too.
|
|
378
|
+
config.autoHandoff = normalizeAutoHandoff({
|
|
359
379
|
enabled: defaults.enabled ?? false,
|
|
360
|
-
|
|
361
|
-
autoAt: defaults.autoAt ?? 90,
|
|
380
|
+
afterCompactions: clampAutoHandoffCompactions(defaults.afterCompactions),
|
|
362
381
|
...(defaults.mode !== undefined ? { mode: defaults.mode } : {}),
|
|
363
382
|
...(defaults.summarizer !== undefined ? { summarizer: defaults.summarizer } : {}),
|
|
364
|
-
};
|
|
383
|
+
});
|
|
365
384
|
return true;
|
|
366
385
|
}
|
|
367
386
|
export async function refreshCodexTokenSnapshot(workflowId, wf, codexHome, opts) {
|
|
@@ -390,8 +409,6 @@ export async function refreshCodexTokenSnapshot(workflowId, wf, codexHome, opts)
|
|
|
390
409
|
}
|
|
391
410
|
export function resetCodexContextAfterCompact(workflowId, wf, modelContextWindow) {
|
|
392
411
|
wf.lastContextPercent = 0;
|
|
393
|
-
wf.autoHandoff.warnFired = false;
|
|
394
|
-
wf.autoHandoff.autoFired = false;
|
|
395
412
|
broadcastTransient(workflowId, {
|
|
396
413
|
type: 'codex_token_snapshot',
|
|
397
414
|
workflowId,
|
|
@@ -429,6 +446,8 @@ export function anyObserver(workflowId) {
|
|
|
429
446
|
let busyClaimSeq = 0;
|
|
430
447
|
const busyCheckoutLeases = new WeakMap();
|
|
431
448
|
const busyOwners = new WeakMap();
|
|
449
|
+
const storageMigrations = new WeakSet();
|
|
450
|
+
const incomingMessages = new WeakMap();
|
|
432
451
|
const lastBusyClaim = new WeakMap();
|
|
433
452
|
const busyRevocations = new WeakMap();
|
|
434
453
|
export function publishWorkerActivity(wf, kind) {
|
|
@@ -440,7 +459,9 @@ export function publishWorkerActivity(wf, kind) {
|
|
|
440
459
|
break;
|
|
441
460
|
}
|
|
442
461
|
}
|
|
443
|
-
export function claimBusy(wf) {
|
|
462
|
+
export function claimBusy(wf, workerActivity = true) {
|
|
463
|
+
if (storageMigrations.has(wf))
|
|
464
|
+
throw new Error('Workflow storage is moving. Wait for the scaffold to finish.');
|
|
444
465
|
// Keep the existing conservative restore reservation, but observe isolated
|
|
445
466
|
// members at their actual scratch cwd for turn-overlap reporting.
|
|
446
467
|
const wfid = [...workflows].find(([, current]) => current === wf)?.[0];
|
|
@@ -455,14 +476,32 @@ export function claimBusy(wf) {
|
|
|
455
476
|
lastBusyClaim.set(wf, token);
|
|
456
477
|
watchClaimed(wf, token);
|
|
457
478
|
wf.busy = true;
|
|
479
|
+
wf.turnStartedAt = undefined;
|
|
480
|
+
if (wfid && workerActivity)
|
|
481
|
+
void notifyClusterStateForWorkflow(wfid);
|
|
458
482
|
if (wf.config?.voiceOperator)
|
|
459
483
|
wf.computerSettled = false;
|
|
460
|
-
|
|
484
|
+
if (workerActivity)
|
|
485
|
+
publishWorkerActivity(wf, 'worker_started');
|
|
461
486
|
return token;
|
|
462
487
|
}
|
|
488
|
+
export function isWorkflowStorageMoving(wf) { return storageMigrations.has(wf); }
|
|
489
|
+
export function reserveWorkflowMigration(wf) {
|
|
490
|
+
if (wf.busy || storageMigrations.has(wf) || incomingMessages.get(wf))
|
|
491
|
+
throw new Error('Workflow is busy.');
|
|
492
|
+
const token = claimBusy(wf, false);
|
|
493
|
+
storageMigrations.add(wf);
|
|
494
|
+
return () => { storageMigrations.delete(wf); if (!releaseBusy(wf, token, 'finished', false))
|
|
495
|
+
wf.busy = false; };
|
|
496
|
+
}
|
|
463
497
|
export function ownsBusy(wf, token) {
|
|
464
498
|
return busyOwners.get(wf) === token;
|
|
465
499
|
}
|
|
500
|
+
// A released claim remains current until another claim or STOP supersedes it.
|
|
501
|
+
// Background completion metadata can use this without retaining busy.
|
|
502
|
+
export function isCurrentBusyClaim(wf, token) {
|
|
503
|
+
return lastBusyClaim.get(wf) === token;
|
|
504
|
+
}
|
|
466
505
|
// Returns false (and leaves wf.busy alone) when the claim was revoked or
|
|
467
506
|
// superseded — the caller is a stale holder and must not touch busy/queue.
|
|
468
507
|
export function releaseBusy(wf, token, outcome = 'interrupted', workerActivity = true) {
|
|
@@ -473,6 +512,7 @@ export function releaseBusy(wf, token, outcome = 'interrupted', workerActivity =
|
|
|
473
512
|
busyCheckoutLeases.get(wf)?.();
|
|
474
513
|
busyCheckoutLeases.delete(wf);
|
|
475
514
|
wf.busy = false;
|
|
515
|
+
wf.turnStartedAt = undefined;
|
|
476
516
|
clearComputerBackgroundClaim([...workflows].find(([, current]) => current === wf)?.[0] ?? '', token);
|
|
477
517
|
if (wf.config?.voiceOperator)
|
|
478
518
|
computerProjectionChanged();
|
|
@@ -498,7 +538,8 @@ export function revokeBusy(wf) {
|
|
|
498
538
|
busyOwners.delete(wf);
|
|
499
539
|
busyCheckoutLeases.get(wf)?.();
|
|
500
540
|
busyCheckoutLeases.delete(wf);
|
|
501
|
-
wf.busy =
|
|
541
|
+
wf.busy = storageMigrations.has(wf);
|
|
542
|
+
wf.turnStartedAt = undefined;
|
|
502
543
|
if (token !== undefined)
|
|
503
544
|
clearComputerBackgroundClaim([...workflows].find(([, current]) => current === wf)?.[0] ?? '', token);
|
|
504
545
|
if (wf.config?.voiceOperator)
|
|
@@ -597,8 +638,7 @@ export async function maybeAutoFold(workflowId, wf, cwd, onAttempt, canAttempt)
|
|
|
597
638
|
if ((st.foldIneffectiveCount ?? 0) >= MAX_INEFFECTIVE_FOLDS)
|
|
598
639
|
return false;
|
|
599
640
|
// Native transport required (CLI Claude has no in-process history to fold).
|
|
600
|
-
const
|
|
601
|
-
const transport = wf.config.claudeTransport ?? (cascade?.claude?.transport === 'native' ? 'native' : 'cli');
|
|
641
|
+
const transport = await resolveClaudeTransport(wf, cwd);
|
|
602
642
|
if (transport !== 'native')
|
|
603
643
|
return false;
|
|
604
644
|
// Re-check after the settings await: an operator message can have claimed
|
|
@@ -645,97 +685,108 @@ export async function maybeAutoFold(workflowId, wf, cwd, onAttempt, canAttempt)
|
|
|
645
685
|
console.log(`[arco] [${workflowId.slice(0, 8)}] auto-fold fired at ${pct}% budget, byteDelta=${res.byteDelta ?? 0}`);
|
|
646
686
|
return true;
|
|
647
687
|
}
|
|
648
|
-
//
|
|
649
|
-
// loop exits (wf.busy
|
|
688
|
+
// Auto-handoff after N compactions (operator decision for 0.1.5). Runs at a
|
|
689
|
+
// turn boundary only: called after the turn loop exits (wf.busy reset), before
|
|
690
|
+
// any automatic fold or compaction of that boundary. Nothing is said before
|
|
691
|
+
// the handoff; once it has run, one chat line names the count and links the
|
|
692
|
+
// handoff document. Returns true when a handoff was started.
|
|
650
693
|
export async function maybeAutoHandoff(workflowId, wf, cwd) {
|
|
651
694
|
// Chat tabs are projectless: a handoff re-seeds as an Agent worker (tools,
|
|
652
695
|
// project context) and, for incognito, installed a cwdHandoffChain slot for
|
|
653
|
-
// the temp root + broadcast lock snapshots.
|
|
654
|
-
// so an Ollama chat at 90% window used to rotate into an Agent tab silently.
|
|
696
|
+
// the temp root + broadcast lock snapshots. Never automatically.
|
|
655
697
|
if (isChatWorkflow(wf.config))
|
|
656
|
-
return;
|
|
657
|
-
const percentOfWindow = wf.lastContextPercent;
|
|
658
|
-
if (typeof percentOfWindow !== 'number' || percentOfWindow <= 0)
|
|
659
|
-
return;
|
|
698
|
+
return false;
|
|
660
699
|
const ah = wf.autoHandoff;
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
700
|
+
if (!ah?.enabled || ah.fired || wf.busy)
|
|
701
|
+
return false;
|
|
702
|
+
const count = compactionsThisConversation(wf);
|
|
703
|
+
if (count < ah.afterCompactions)
|
|
704
|
+
return false;
|
|
705
|
+
const cascade = await readSettings(cwd).catch(() => null);
|
|
706
|
+
if (!(await autoHandoffAvailableFor(workflowId, wf, cwd, cascade)).available)
|
|
707
|
+
return false;
|
|
708
|
+
if (wf.busy || ah.fired)
|
|
709
|
+
return false;
|
|
710
|
+
const obs = anyObserver(workflowId);
|
|
711
|
+
if (!obs) {
|
|
712
|
+
console.warn(`[arco] [${workflowId.slice(0, 8)}] auto-handoff: no observer to broadcast on`);
|
|
713
|
+
return false;
|
|
714
|
+
}
|
|
715
|
+
ah.fired = true;
|
|
716
|
+
console.log(`[arco] [${workflowId.slice(0, 8)}] auto-handoff: ${count} compactions this conversation, firing`);
|
|
717
|
+
// Re-use the same handoff logic as the manual button by constructing
|
|
718
|
+
// a synthetic message and calling the handler.
|
|
719
|
+
//
|
|
720
|
+
// Per-tab override wins over the global default; quick is the fallback.
|
|
721
|
+
const mode = wf.autoHandoff.mode
|
|
722
|
+
?? cascade?.autoHandoffDefaults?.mode
|
|
723
|
+
?? 'quick';
|
|
724
|
+
// Keep mode resolution in sync with manual handoff: provider-specific
|
|
725
|
+
// resume capability is handled by handoffHandlers, which translates the
|
|
726
|
+
// original-worker choice where a live session cannot be reopened.
|
|
727
|
+
const synthMsg = {
|
|
728
|
+
type: 'handoff_request',
|
|
729
|
+
workflowId,
|
|
730
|
+
mode,
|
|
731
|
+
};
|
|
732
|
+
// SUMMARIZER resolution: only matters for fresh-summarizer. Put the
|
|
733
|
+
// per-tab summarizer (if set) onto the synthesized message; the handler's
|
|
734
|
+
// chain is `msg.summarizer ?? settings.handoffSummarizer ?? primary`, so
|
|
735
|
+
// per-tab wins, global is the middle, primary is last. For original-worker
|
|
736
|
+
// we leave summarizer unset.
|
|
737
|
+
if (mode === 'fresh-summarizer' && wf.autoHandoff.summarizer) {
|
|
738
|
+
const s = wf.autoHandoff.summarizer;
|
|
739
|
+
synthMsg.summarizer = {
|
|
740
|
+
provider: s.provider,
|
|
741
|
+
model: s.model ?? wf.primary.model,
|
|
742
|
+
effort: s.effort ?? 'medium',
|
|
743
|
+
};
|
|
666
744
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
745
|
+
try {
|
|
746
|
+
const dummySession = sessions.get(obs) ?? { id: 'auto', workflowIds: new Set([workflowId]), clusterIds: new Set(), clusterObserved: new Map() };
|
|
747
|
+
const done = await deps.handleHandoffRequest(obs, dummySession, synthMsg);
|
|
748
|
+
if (done && typeof done === 'object' && done.artifactName) {
|
|
749
|
+
const doc = path.join(workflowDir(cwd, workflowId), 'handoffs', done.artifactName);
|
|
750
|
+
broadcastWorkflow(workflowId, {
|
|
673
751
|
type: 'system_notice',
|
|
674
752
|
workflowId,
|
|
675
|
-
content: `
|
|
753
|
+
content: `Handed off after ${count} compaction${count === 1 ? '' : 's'}: [handoff document](${doc.split(path.sep).join('/')})`,
|
|
676
754
|
});
|
|
677
755
|
}
|
|
678
|
-
|
|
756
|
+
// Not completed (cancelled, refused, or failed with its own notice): no
|
|
757
|
+
// retry in this conversation; HANDOFF stays available.
|
|
679
758
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
send(obs, {
|
|
690
|
-
type: 'system_notice',
|
|
691
|
-
workflowId,
|
|
692
|
-
content: `[AUTO-HANDOFF] Context at ${percentOfWindow}%. Rotating the session.`,
|
|
693
|
-
});
|
|
694
|
-
// Re-use the same handoff logic as the manual button by constructing
|
|
695
|
-
// a synthetic message and calling the handler.
|
|
696
|
-
//
|
|
697
|
-
// Per-tab override wins over the global default; quick is the fallback.
|
|
698
|
-
const cascade = await readSettings(cwd).catch(() => null);
|
|
699
|
-
const mode = wf.autoHandoff.mode
|
|
700
|
-
?? cascade?.autoHandoffDefaults?.mode
|
|
701
|
-
?? 'quick';
|
|
702
|
-
// Keep mode resolution in sync with manual handoff: provider-specific
|
|
703
|
-
// resume capability is handled by handoffHandlers, which translates the
|
|
704
|
-
// original-worker choice where a live session cannot be reopened.
|
|
705
|
-
const synthMsg = {
|
|
706
|
-
type: 'handoff_request',
|
|
707
|
-
workflowId,
|
|
708
|
-
mode,
|
|
709
|
-
};
|
|
710
|
-
// SUMMARIZER resolution: only matters for fresh-summarizer. Put the
|
|
711
|
-
// per-tab summarizer (if set) onto the synthesized message; the handler's
|
|
712
|
-
// chain is `msg.summarizer ?? settings.handoffSummarizer ?? primary`, so
|
|
713
|
-
// per-tab wins, global is the middle, primary is last. For original-worker
|
|
714
|
-
// we leave summarizer unset.
|
|
715
|
-
if (mode === 'fresh-summarizer' && wf.autoHandoff.summarizer) {
|
|
716
|
-
const s = wf.autoHandoff.summarizer;
|
|
717
|
-
synthMsg.summarizer = {
|
|
718
|
-
provider: s.provider,
|
|
719
|
-
model: s.model ?? wf.primary.model,
|
|
720
|
-
effort: s.effort ?? 'medium',
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
try {
|
|
724
|
-
const dummySession = sessions.get(obs) ?? { id: 'auto', workflowIds: new Set([workflowId]), clusterIds: new Set(), clusterObserved: new Map() };
|
|
725
|
-
await deps.handleHandoffRequest(obs, dummySession, synthMsg);
|
|
726
|
-
}
|
|
727
|
-
catch (err) {
|
|
728
|
-
console.error(`[arco] [${workflowId.slice(0, 8)}] auto-handoff failed:`, err);
|
|
729
|
-
const obs2 = anyObserver(workflowId);
|
|
730
|
-
if (obs2) {
|
|
731
|
-
send(obs2, {
|
|
732
|
-
type: 'system_notice',
|
|
733
|
-
workflowId,
|
|
734
|
-
content: `[AUTO-HANDOFF FAILED] ${err instanceof Error ? err.message : String(err)}. Click HANDOFF manually.`,
|
|
735
|
-
});
|
|
736
|
-
}
|
|
759
|
+
catch (err) {
|
|
760
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] auto-handoff failed:`, err);
|
|
761
|
+
const obs2 = anyObserver(workflowId);
|
|
762
|
+
if (obs2) {
|
|
763
|
+
send(obs2, {
|
|
764
|
+
type: 'system_notice',
|
|
765
|
+
workflowId,
|
|
766
|
+
content: `[AUTO-HANDOFF FAILED] ${err instanceof Error ? err.message : String(err)}. Click HANDOFF manually.`,
|
|
767
|
+
});
|
|
737
768
|
}
|
|
738
769
|
}
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
// Whether auto-handoff can count compactions for this tab now (provider,
|
|
773
|
+
// transport and the resolved auto-compaction policy, worker over cluster).
|
|
774
|
+
export async function autoHandoffAvailableFor(workflowId, wf, cwd, cascade) {
|
|
775
|
+
const settings = cascade === undefined ? await readSettings(cwd).catch(() => null) : cascade;
|
|
776
|
+
const provider = wf.primary.provider;
|
|
777
|
+
const claudeTransport = provider === 'claude' ? await resolveClaudeTransport(wf, cwd) : undefined;
|
|
778
|
+
const codexTransport = wf.config.codexTransport ?? (settings?.codex?.transport === 'appserver' ? 'appserver' : 'exec');
|
|
779
|
+
const clusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
780
|
+
const ollamaSaved = settings?.ollama?.compaction?.enabled !== undefined || settings?.ollama?.compaction?.threshold !== undefined;
|
|
781
|
+
const compaction = resolveProviderAutoCompaction(wf.config.autoCompaction, clusterId ? clusterStore.getAutoCompaction(clusterId) : undefined, provider, claudeTransport ?? '', wf.config.claudeNativeCompact === true, ollamaSaved);
|
|
782
|
+
return autoHandoffAvailability({
|
|
783
|
+
provider,
|
|
784
|
+
claudeTransport,
|
|
785
|
+
codexTransport,
|
|
786
|
+
chat: isChatWorkflow(wf.config),
|
|
787
|
+
compaction,
|
|
788
|
+
ollamaSavedEnabled: ollamaSaved ? settings?.ollama?.compaction?.enabled !== false : undefined,
|
|
789
|
+
});
|
|
739
790
|
}
|
|
740
791
|
export function freshAutoCompactionPercent(provider, transport, outcome) {
|
|
741
792
|
if (outcome.error || !((provider === 'claude' && transport === 'native') || (provider === 'codex' && transport === 'appserver')))
|
|
@@ -791,8 +842,13 @@ export async function maybeAutoCompactPolicy(workflowId, wf, cwd, policy, readin
|
|
|
791
842
|
export async function runExplicitContextActions(workflowId, wf, cwd, policy, reading, busyToken, ws, session) {
|
|
792
843
|
if (lastBusyClaim.get(wf) !== busyToken)
|
|
793
844
|
return 'stale';
|
|
794
|
-
//
|
|
795
|
-
//
|
|
845
|
+
// A due auto-handoff starts a fresh session, so this boundary needs no
|
|
846
|
+
// fold or compaction.
|
|
847
|
+
if (await maybeAutoHandoff(workflowId, wf, cwd))
|
|
848
|
+
return 'done';
|
|
849
|
+
if (lastBusyClaim.get(wf) !== busyToken)
|
|
850
|
+
return 'stale';
|
|
851
|
+
// Ollama compacts at the next pre-dispatch boundary.
|
|
796
852
|
if (wf.primary.provider === 'ollama' && policy.enabled)
|
|
797
853
|
return 'done';
|
|
798
854
|
let foldClaim;
|
|
@@ -808,7 +864,6 @@ export async function runExplicitContextActions(workflowId, wf, cwd, policy, rea
|
|
|
808
864
|
return 'done';
|
|
809
865
|
if (await maybeAutoCompactPolicy(workflowId, wf, cwd, policy, reading, busyToken, ws, session))
|
|
810
866
|
return 'compact-attempted';
|
|
811
|
-
await maybeAutoHandoff(workflowId, wf, cwd);
|
|
812
867
|
return 'done';
|
|
813
868
|
}
|
|
814
869
|
// NATIVE_COMPACTION_PLAN Phase 3 — the continuance prompt the opt-in auto-continue
|
|
@@ -842,7 +897,15 @@ export async function maybeAutoContinueAfterCompact(workflowId, ws, session) {
|
|
|
842
897
|
// turn starts while calibration is running, the pty is cancelled via
|
|
843
898
|
// wf.cancelCalibration (set by the primary turn handler in handleUserMessage).
|
|
844
899
|
export async function maybeCalibrate(workflowId, wf, cwd) {
|
|
845
|
-
|
|
900
|
+
const sessionId = wf.primarySessionId;
|
|
901
|
+
const model = wf.primary.model;
|
|
902
|
+
const claim = lastBusyClaim.get(wf);
|
|
903
|
+
const revocation = busyRevocations.get(wf);
|
|
904
|
+
const stillIdle = () => workflows.get(workflowId) === wf && !wf.busy
|
|
905
|
+
&& wf.primary.provider === 'claude' && wf.primarySessionId === sessionId
|
|
906
|
+
&& wf.primary.model === model && lastBusyClaim.get(wf) === claim
|
|
907
|
+
&& busyRevocations.get(wf) === revocation;
|
|
908
|
+
if (!sessionId || !stillIdle() || wf.cancelCalibration)
|
|
846
909
|
return;
|
|
847
910
|
// CLI transport only. Native gets exact token counts from the API
|
|
848
911
|
// (lastPromptTokens) — the byte-ratio estimator this tunes never runs for
|
|
@@ -853,8 +916,7 @@ export async function maybeCalibrate(workflowId, wf, cwd) {
|
|
|
853
916
|
// transcript truth.
|
|
854
917
|
if (await resolveClaudeTransport(wf, cwd) === 'native')
|
|
855
918
|
return;
|
|
856
|
-
|
|
857
|
-
if (!sessionId)
|
|
919
|
+
if (!stillIdle())
|
|
858
920
|
return;
|
|
859
921
|
const cal = wf.calibration ?? {
|
|
860
922
|
ratio: BYTES_PER_TOKEN_DEFAULT,
|
|
@@ -863,14 +925,14 @@ export async function maybeCalibrate(workflowId, wf, cwd) {
|
|
|
863
925
|
};
|
|
864
926
|
// Get current estimate to detect zone crossing
|
|
865
927
|
const est = await estimateContextFill(cwd, sessionId, wf.primary.model, cal).catch(() => null);
|
|
866
|
-
if (!est)
|
|
928
|
+
if (!est || !stillIdle())
|
|
867
929
|
return;
|
|
868
930
|
const currentPercent = est.percentOfWindow;
|
|
869
931
|
const prevPercent = wf.lastContextPercent;
|
|
870
932
|
wf.lastContextPercent = currentPercent;
|
|
871
|
-
// Don't calibrate
|
|
872
|
-
//
|
|
873
|
-
if (currentPercent >=
|
|
933
|
+
// Don't calibrate near a full window: not worth the latency when the CLI's
|
|
934
|
+
// own compaction is imminent.
|
|
935
|
+
if (currentPercent >= 90)
|
|
874
936
|
return;
|
|
875
937
|
// Skip when the estimator already has ground truth from the JSONL usage
|
|
876
938
|
// blocks — calibration only exists to tune the byte-count ratio, and the
|
|
@@ -892,16 +954,27 @@ export async function maybeCalibrate(workflowId, wf, cwd) {
|
|
|
892
954
|
if (!zone)
|
|
893
955
|
return;
|
|
894
956
|
console.log(`[arco] [${workflowId.slice(0, 8)}] calibrating zone ${zone} at ${currentPercent}%`);
|
|
957
|
+
if (!stillIdle() || wf.cancelCalibration)
|
|
958
|
+
return;
|
|
959
|
+
let cancelProbe;
|
|
960
|
+
let cancelled = false;
|
|
961
|
+
const cancel = () => { cancelled = true; cancelProbe?.(); };
|
|
962
|
+
wf.cancelCalibration = cancel;
|
|
895
963
|
let result = null;
|
|
896
964
|
try {
|
|
897
965
|
result = await runCalibration(sessionId, wf.primary.model, cwd, est.jsonlBytes, (cancelFn) => {
|
|
898
|
-
|
|
966
|
+
cancelProbe = cancelFn;
|
|
967
|
+
if (cancelled || !stillIdle())
|
|
968
|
+
cancelFn();
|
|
899
969
|
});
|
|
900
970
|
}
|
|
901
971
|
catch (err) {
|
|
902
972
|
console.error(`[arco] [${workflowId.slice(0, 8)}] calibration error:`, err);
|
|
903
973
|
}
|
|
904
|
-
wf.cancelCalibration
|
|
974
|
+
if (wf.cancelCalibration === cancel)
|
|
975
|
+
wf.cancelCalibration = undefined;
|
|
976
|
+
if (cancelled || !stillIdle())
|
|
977
|
+
return;
|
|
905
978
|
if (!result) {
|
|
906
979
|
console.warn(`[arco] [${workflowId.slice(0, 8)}] calibration zone ${zone} failed or was cancelled`);
|
|
907
980
|
return;
|
|
@@ -934,7 +1007,7 @@ export async function maybeCalibrate(workflowId, wf, cwd) {
|
|
|
934
1007
|
// Plan-less workflows receive a single-line note describing plan creation and
|
|
935
1008
|
// attachment. It preserves the parseable phase and checkbox structure and can
|
|
936
1009
|
// be stripped from session replay without duplicating the user message.
|
|
937
|
-
function planAuthoringNote(cwd, workflowId) {
|
|
1010
|
+
function planAuthoringNote(cwd, workflowId, publicProject = false) {
|
|
938
1011
|
return (`[No project plan is attached to this Arco workflow. If asked to create/attach one, do NOT just write a ` +
|
|
939
1012
|
`markdown file — a loose file is invisible to Arco. Prefer the \`plan_create\` tool (MCP server \`arco\`) ` +
|
|
940
1013
|
`if you have it — one call, title + body, creates and attaches. Otherwise write the body to a scratch file, then POST it (this ` +
|
|
@@ -950,13 +1023,17 @@ function planAuthoringNote(cwd, workflowId) {
|
|
|
950
1023
|
`docs, which hold the specs/research/design detail. After creating the plan, write each doc with \`plan_ref_write\` ` +
|
|
951
1024
|
`(or as files at .arco/plans/<planId>.refs/<slug>.md — not loose design files elsewhere in the repo) and link it ` +
|
|
952
1025
|
`from every task that depends on it as \`[label](ref:slug)\`; whoever works that task reads the linked ref first. ` +
|
|
1026
|
+
(publicProject ? `This project is public. Include a Privacy and public safety section in any new plan, fitted to this project and its risks. ` : '') +
|
|
953
1027
|
`Don't create a plan unless asked.]\n\n`);
|
|
954
1028
|
}
|
|
955
1029
|
export async function buildPlanPrefix(cwd, wf, workflowId) {
|
|
956
1030
|
if (!cwd)
|
|
957
1031
|
return '';
|
|
958
|
-
if (!wf.planId)
|
|
959
|
-
|
|
1032
|
+
if (!wf.planId) {
|
|
1033
|
+
const isPublic = await getEffectivePublicProjectChoice(cwd).catch((error) => { if (error.code === 'ENOENT')
|
|
1034
|
+
return null; throw error; });
|
|
1035
|
+
return planAuthoringNote(cwd, workflowId, isPublic === true);
|
|
1036
|
+
}
|
|
960
1037
|
const plan = await readPlan(cwd, wf.planId).catch(() => null);
|
|
961
1038
|
if (!plan) {
|
|
962
1039
|
// Plan was deleted out from under us. Detach quietly so future turns
|
|
@@ -1020,6 +1097,7 @@ export async function buildPlanPrefix(cwd, wf, workflowId) {
|
|
|
1020
1097
|
export function projectQueue(items) {
|
|
1021
1098
|
return items.map((q) => ({
|
|
1022
1099
|
content: q.content,
|
|
1100
|
+
...(q.automaticKind ? { automaticKind: q.automaticKind } : {}),
|
|
1023
1101
|
...(q.interrupt ? { interrupt: true } : {}),
|
|
1024
1102
|
...(q.clientMessageId ? { clientMessageId: q.clientMessageId } : {}),
|
|
1025
1103
|
}));
|
|
@@ -1052,8 +1130,8 @@ export function broadcastQueueUpdate(workflowId) {
|
|
|
1052
1130
|
// shape the post-turn drain uses. The `user_message_echo` was already
|
|
1053
1131
|
// emitted at enqueue time (handleUserMessage) so we don't re-echo here;
|
|
1054
1132
|
// the persisted echo at the original timestamp is the authoritative
|
|
1055
|
-
//
|
|
1056
|
-
//
|
|
1133
|
+
// audit record. Delivery attempt metadata places the input at its confirmed
|
|
1134
|
+
// boundary for provider replay and review, while the live chat keeps the echo.
|
|
1057
1135
|
//
|
|
1058
1136
|
// Retry safety: the drain is destructive (splice) so a same-iteration
|
|
1059
1137
|
// re-call would return []. Provider-side retry loops that call drainSteer
|
|
@@ -1061,38 +1139,48 @@ export function broadcastQueueUpdate(workflowId) {
|
|
|
1061
1139
|
// results and the next streamOneTurn) cannot double-deliver. Recovery
|
|
1062
1140
|
// paths in llamacpp.ts inject their own synthetic user messages and skip
|
|
1063
1141
|
// past the hook — by design.
|
|
1064
|
-
|
|
1142
|
+
const originalSteerItems = new WeakMap();
|
|
1143
|
+
export function drainSteerForWorker(workflowId, ws, deliveryProvider) {
|
|
1065
1144
|
const wf = workflows.get(workflowId);
|
|
1066
1145
|
if (!wf || wf.queue.steering.length === 0 || wf.primaryTurn?.holdSteer || wf.queue.steering.some((q) => q.interrupt))
|
|
1067
1146
|
return [];
|
|
1068
1147
|
const drained = wf.queue.steering.splice(0);
|
|
1148
|
+
const deliveryId = randomUUID();
|
|
1069
1149
|
broadcastQueueUpdate(workflowId);
|
|
1070
1150
|
const drainedClientIds = drained
|
|
1071
1151
|
.map((d) => d.clientMessageId)
|
|
1072
1152
|
.filter((id) => typeof id === 'string' && id.length > 0);
|
|
1073
|
-
if (drainedClientIds.length > 0 && wf.primary.provider !== 'codex') {
|
|
1074
|
-
|
|
1153
|
+
if (drainedClientIds.length > 0 && (deliveryProvider ?? wf.primary.provider) !== 'codex') {
|
|
1154
|
+
broadcastWorkflow(workflowId, { type: 'turn_messages_delivered', workflowId, clientMessageIds: drainedClientIds, deliveryId });
|
|
1075
1155
|
}
|
|
1076
1156
|
if (drainedClientIds.length > 0) {
|
|
1077
1157
|
send(ws, {
|
|
1078
1158
|
type: 'queued_messages_drained',
|
|
1079
1159
|
workflowId,
|
|
1160
|
+
deliveryId,
|
|
1080
1161
|
clientMessageIds: drainedClientIds,
|
|
1081
1162
|
drainedAt: Date.now(),
|
|
1082
1163
|
});
|
|
1083
1164
|
}
|
|
1084
1165
|
console.log(`[arco] [${workflowId.slice(0, 8)}] mid-turn steer drained (${drained.length} item${drained.length === 1 ? '' : 's'}; follow-up bucket untouched)`);
|
|
1085
|
-
return drained.map((d) =>
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1166
|
+
return drained.map((d) => {
|
|
1167
|
+
const pending = clusterToolsPending(wf, clusterStore.getClusterIdForWorkflow(workflowId));
|
|
1168
|
+
const raw = d.expandedContext ? d.content + d.expandedContext : d.content;
|
|
1169
|
+
const item = {
|
|
1170
|
+
deliveryId,
|
|
1171
|
+
// §D1 — mid-turn steer is delivered as a single `content` string through
|
|
1172
|
+
// the provider steer APIs (SteerItem has no separate context block), so a
|
|
1173
|
+
// steer message's expanded `@`-refs ride appended to its content. The echo
|
|
1174
|
+
// already went out compact at enqueue; this only affects what the model
|
|
1175
|
+
// sees mid-turn. Post-turn drain (the loop in handleUserMessage) uses the
|
|
1176
|
+
// separate-block path instead.
|
|
1177
|
+
content: pending ? (d.clusterBusyReminder ? CLUSTER_TOOLS_PENDING_AGENT : `${CLUSTER_TOOLS_PENDING_AGENT}\n\n${raw}`) : raw,
|
|
1178
|
+
...(d.clientMessageId ? { clientMessageId: d.clientMessageId } : {}),
|
|
1179
|
+
...(d.attachments && d.attachments.length > 0 ? { attachments: d.attachments } : {}),
|
|
1180
|
+
};
|
|
1181
|
+
originalSteerItems.set(item, d);
|
|
1182
|
+
return item;
|
|
1183
|
+
});
|
|
1096
1184
|
}
|
|
1097
1185
|
// Phase 6b — re-enqueue support for the Codex app-server worker. The worker
|
|
1098
1186
|
// drains via `drainSteerForWorker` (destructive splice) and dispatches
|
|
@@ -1113,7 +1201,7 @@ export function requeueSteerForWorker(workflowId, ws, items, bucket) {
|
|
|
1113
1201
|
return;
|
|
1114
1202
|
const arr = bucket === 'steer' ? wf.queue.steering : wf.queue.followUp;
|
|
1115
1203
|
for (const item of items) {
|
|
1116
|
-
arr.push({
|
|
1204
|
+
arr.push(originalSteerItems.get(item) ?? {
|
|
1117
1205
|
content: item.content,
|
|
1118
1206
|
...(item.clientMessageId ? { clientMessageId: item.clientMessageId } : {}),
|
|
1119
1207
|
...(item.attachments && item.attachments.length > 0 ? { attachments: item.attachments } : {}),
|
|
@@ -1188,6 +1276,8 @@ export async function persistInitialMeta(cwd, workflowId, config, primary, opts)
|
|
|
1188
1276
|
...(typeof config.claudeNativeForceInterleavedThinkingBeta === 'boolean'
|
|
1189
1277
|
? { claudeNativeForceInterleavedThinkingBeta: config.claudeNativeForceInterleavedThinkingBeta }
|
|
1190
1278
|
: {}),
|
|
1279
|
+
nativeSubagents: config.nativeSubagents,
|
|
1280
|
+
claudeNativeTaskDisabled: config.claudeNativeTaskDisabled,
|
|
1191
1281
|
...(config.claudeNativeThinkingDisplay === 'omitted' || config.claudeNativeThinkingDisplay === 'summarized' || config.claudeNativeThinkingDisplay === 'updates'
|
|
1192
1282
|
? { claudeNativeThinkingDisplay: config.claudeNativeThinkingDisplay }
|
|
1193
1283
|
: {}),
|
|
@@ -1220,12 +1310,10 @@ export async function persistInitialMeta(cwd, workflowId, config, primary, opts)
|
|
|
1220
1310
|
...(config.reviewSafeMode === 'on' || config.reviewSafeMode === 'off'
|
|
1221
1311
|
? { reviewSafeMode: config.reviewSafeMode }
|
|
1222
1312
|
: {}),
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
? { outputStyle: 'terse' }
|
|
1228
|
-
: {}),
|
|
1313
|
+
// Only a style other than the default is written; unset means
|
|
1314
|
+
// DEFAULT_OUTPUT_STYLE. Legacy `lite` / `caveman` from a stale client are
|
|
1315
|
+
// written as `plain` / `terse` (plain being the default, it stays unset).
|
|
1316
|
+
...(storedOutputStyle(config.outputStyle) ? { outputStyle: storedOutputStyle(config.outputStyle) } : {}),
|
|
1229
1317
|
// docs/GOTCHAS.md - persist a north-star seeded before the first turn
|
|
1230
1318
|
// (e.g. a Spawn-from-here that inherited the parent's) so it survives a
|
|
1231
1319
|
// restart even if the operator never re-sets it. Blank ⇒ omitted.
|
|
@@ -1249,6 +1337,16 @@ export async function writeCalibrationToMeta(cwd, workflowId, ratio, overhead, l
|
|
|
1249
1337
|
meta.calibration = { ratio, overhead, lastGroundTruth };
|
|
1250
1338
|
});
|
|
1251
1339
|
}
|
|
1340
|
+
// Automatic busy reminders use the same steering queue as a manual nudge.
|
|
1341
|
+
// Losing the busy turn during async preparation drops the reminder instead
|
|
1342
|
+
// of creating a new turn or steering a newer generation.
|
|
1343
|
+
export async function enqueueBusyReminder(workflowId, content, allow) {
|
|
1344
|
+
let accepted = false;
|
|
1345
|
+
const ws = { readyState: WebSocket.CLOSED, send: () => undefined };
|
|
1346
|
+
const session = { id: 'busy-reminder', workflowIds: new Set([workflowId]), clusterIds: new Set(), clusterObserved: new Map() };
|
|
1347
|
+
await handleUserMessage(ws, session, workflowId, content, undefined, undefined, true, 'steer', undefined, undefined, { automaticKind: 'auto-pickup', clusterBusyReminder: true, busyOnly: true, busyOnlyGuard: allow, onBusyQueued: () => { accepted = true; } });
|
|
1348
|
+
return accepted;
|
|
1349
|
+
}
|
|
1252
1350
|
export async function handleUserMessage(ws, session, workflowId, content, clientMessageId, attachments, interjection, kind, primitive, pickedSkills,
|
|
1253
1351
|
// drainQueueIfIdle only: take the prompt from wf.queue at claim time
|
|
1254
1352
|
// instead of `content` (items were echoed + expanded at enqueue).
|
|
@@ -1259,1562 +1357,1617 @@ opts) {
|
|
|
1259
1357
|
send(ws, { type: 'error', message: `Unknown workflow ${workflowId.slice(0, 8)}` });
|
|
1260
1358
|
return;
|
|
1261
1359
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
if (!cwd) {
|
|
1265
|
-
send(ws, { type: 'error', message: 'Workflow has no working directory configured.' });
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
|
-
const memberClusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
1269
|
-
const chatMode = isChatWorkflow(wf.config);
|
|
1270
|
-
const incognito = chatMode && wf.config.incognito === true;
|
|
1271
|
-
const trackOllama = wf.primary.provider === 'ollama' && !chatMode;
|
|
1272
|
-
if (trackOllama && !clientMessageId)
|
|
1273
|
-
clientMessageId = randomUUID();
|
|
1274
|
-
// Chat tabs expose no project tools; web_search/web_fetch is the one
|
|
1275
|
-
// exception the operator can arm (default on for a saved Chat). Computed per
|
|
1276
|
-
// turn so the header toggle takes effect on the next message, and passed
|
|
1277
|
-
// down so each provider arms its own web surface.
|
|
1278
|
-
const chatWeb = chatMode && chatWebArmed(wf.config, wf.primary.provider);
|
|
1279
|
-
const clusterAccessMode = memberClusterId
|
|
1280
|
-
? clusterStore.getMemberAccessMode(memberClusterId, workflowId)
|
|
1281
|
-
: 'standard';
|
|
1282
|
-
const isolatedMember = clusterAccessMode === 'isolated';
|
|
1283
|
-
const projectContextEnabled = !chatMode && !isolatedMember;
|
|
1284
|
-
if (chatMode && !CHAT_PROVIDERS.has(wf.primary.provider)) {
|
|
1285
|
-
send(ws, { type: 'error', workflowId, message: `${wf.primary.provider} is not available in Chat mode.` });
|
|
1286
|
-
return;
|
|
1287
|
-
}
|
|
1288
|
-
const configuredTrustSource = wf.config.managedWorktreeSourceCwd;
|
|
1289
|
-
const managedTrustSource = configuredTrustSource
|
|
1290
|
-
&& await isManagedBakeoffWorktree(configuredTrustSource, cwd).catch(() => false)
|
|
1291
|
-
? configuredTrustSource
|
|
1292
|
-
: undefined;
|
|
1293
|
-
if (isolatedMember && (wf.primary.provider !== 'claude' || wf.config.claudeTransport !== 'native')) {
|
|
1294
|
-
send(ws, {
|
|
1295
|
-
type: 'error',
|
|
1296
|
-
message: 'isolated cluster members require the Claude Native transport',
|
|
1297
|
-
});
|
|
1360
|
+
if (storageMigrations.has(wf)) {
|
|
1361
|
+
send(ws, { type: 'error', message: 'Message not sent: workflow storage is moving. Wait for the scaffold to finish, then resend.' });
|
|
1298
1362
|
return;
|
|
1299
1363
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1364
|
+
incomingMessages.set(wf, (incomingMessages.get(wf) ?? 0) + 1);
|
|
1365
|
+
try {
|
|
1366
|
+
const busyOnlyClaim = lastBusyClaim.get(wf);
|
|
1367
|
+
if (opts?.busyOnly && !wf.busy)
|
|
1368
|
+
return;
|
|
1369
|
+
const interruptEpoch = busyRevocations.get(wf) ?? 0;
|
|
1370
|
+
const cwd = wf.config.workingDirectory;
|
|
1371
|
+
if (!cwd) {
|
|
1372
|
+
send(ws, { type: 'error', message: 'Workflow has no working directory configured.' });
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
const memberClusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
1376
|
+
const chatMode = isChatWorkflow(wf.config);
|
|
1377
|
+
const incognito = chatMode && wf.config.incognito === true;
|
|
1378
|
+
const trackOllama = wf.primary.provider === 'ollama' && !chatMode;
|
|
1379
|
+
if (!clientMessageId)
|
|
1380
|
+
clientMessageId = randomUUID();
|
|
1381
|
+
// Chat tabs expose no project tools; web_search/web_fetch is the one
|
|
1382
|
+
// exception the operator can arm (default on for a saved Chat). Computed per
|
|
1383
|
+
// turn so the header toggle takes effect on the next message, and passed
|
|
1384
|
+
// down so each provider arms its own web surface.
|
|
1385
|
+
const chatWeb = chatMode && chatWebArmed(wf.config, wf.primary.provider);
|
|
1386
|
+
const clusterAccessMode = memberClusterId
|
|
1387
|
+
? clusterStore.getMemberAccessMode(memberClusterId, workflowId)
|
|
1388
|
+
: 'standard';
|
|
1389
|
+
const isolatedMember = clusterAccessMode === 'isolated';
|
|
1390
|
+
const projectContextEnabled = !chatMode && !isolatedMember;
|
|
1391
|
+
if (chatMode && !CHAT_PROVIDERS.has(wf.primary.provider)) {
|
|
1392
|
+
send(ws, { type: 'error', workflowId, message: `${wf.primary.provider} is not available in Chat mode.` });
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
const configuredTrustSource = wf.config.managedWorktreeSourceCwd;
|
|
1396
|
+
const managedTrustSource = configuredTrustSource
|
|
1397
|
+
&& await isManagedBakeoffWorktree(configuredTrustSource, cwd).catch(() => false)
|
|
1398
|
+
? configuredTrustSource
|
|
1399
|
+
: undefined;
|
|
1400
|
+
if (isolatedMember && (wf.primary.provider !== 'claude' || wf.config.claudeTransport !== 'native')) {
|
|
1401
|
+
send(ws, {
|
|
1402
|
+
type: 'error',
|
|
1403
|
+
message: 'isolated cluster members require the Claude Native transport',
|
|
1314
1404
|
});
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
// Explicit built-in slash commands are resolved before queueing, so queued
|
|
1408
|
+
// turns retain the same pick. A trusted project or global copy takes priority.
|
|
1409
|
+
if (projectContextEnabled && !fromQueue) {
|
|
1410
|
+
const invocation = /^\/(grill-me|grill-with-docs|wait-what|retro|improve-codebase-architecture)(?:\s|$)/i.exec(content);
|
|
1411
|
+
if (invocation) {
|
|
1412
|
+
const requested = invocation[1].toLowerCase();
|
|
1413
|
+
const slug = requested === 'improve-codebase-architecture' ? 'architecture-review' : requested;
|
|
1414
|
+
const include = await projectTrust.resolveTrustStatus(managedTrustSource ?? cwd).catch(() => 'ask') === 'always';
|
|
1415
|
+
const catalog = await listSkills(cwd, { includeProject: include });
|
|
1416
|
+
const own = [...catalog.project, ...catalog.global].find((s) => s.slug.toLowerCase() === requested || s.name.toLowerCase() === requested);
|
|
1417
|
+
const builtin = catalog.builtin.find((s) => s.slug === slug);
|
|
1418
|
+
if (own?.off || (!own && builtin?.off)) {
|
|
1419
|
+
send(ws, { type: 'error', workflowId, message: `/${requested} is turned off.` });
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
if (own)
|
|
1423
|
+
pickedSkills = [...(pickedSkills ?? []), { scope: own.scope, slug: own.slug }];
|
|
1424
|
+
else if (builtin && !builtin.replaced)
|
|
1425
|
+
pickedSkills = [...(pickedSkills ?? []), { scope: 'builtin', slug }];
|
|
1322
1426
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1427
|
+
}
|
|
1428
|
+
// DD10 — parameterized `/prompt` command expansion. Runs FIRST (before
|
|
1429
|
+
// context-refs + before any echo/record) so events.jsonl carries the expanded
|
|
1430
|
+
// turn, and so `@`-refs inside an expanded template still expand below. A
|
|
1431
|
+
// project-scope template is gated behind DD7 trust (key on the raw decision —
|
|
1432
|
+
// a cloned repo's `.arco/prompts/*.md` is an injection vector). No matching
|
|
1433
|
+
// template ⇒ the text passes through untouched as a normal turn.
|
|
1434
|
+
if (projectContextEnabled && !fromQueue) {
|
|
1435
|
+
const invocation = parsePromptInvocation(content);
|
|
1436
|
+
if (invocation) {
|
|
1437
|
+
const trustStatus = await projectTrust.resolveTrustStatus(managedTrustSource ?? cwd).catch(() => 'ask');
|
|
1438
|
+
const includeProject = trustStatus === 'always';
|
|
1439
|
+
const expanded = await expandPromptCommand(invocation.name, invocation.argsRaw, cwd, { includeProject }).catch((err) => {
|
|
1440
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] prompt-command expansion failed:`, err);
|
|
1441
|
+
return null;
|
|
1330
1442
|
});
|
|
1443
|
+
if (expanded) {
|
|
1444
|
+
content = expanded.expanded;
|
|
1445
|
+
broadcastWorkflow(workflowId, {
|
|
1446
|
+
type: 'system_notice',
|
|
1447
|
+
workflowId,
|
|
1448
|
+
content: `[PROMPT] Expanded /${invocation.name} (${expanded.scope}) into this turn.`,
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
else if (!includeProject && await projectPromptExists(invocation.name, cwd).catch(() => false)) {
|
|
1452
|
+
// A project template EXISTS but the repo isn't trusted — explain the
|
|
1453
|
+
// suppression rather than silently sending the literal `/name`.
|
|
1454
|
+
broadcastWorkflow(workflowId, {
|
|
1455
|
+
type: 'system_notice',
|
|
1456
|
+
workflowId,
|
|
1457
|
+
content: `[PROMPT] /${invocation.name} is a project template but this repo isn't trusted (${trustStatus}) — it was NOT expanded. Trust the repo to enable it.`,
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1331
1460
|
}
|
|
1332
1461
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
// with no kind, which matched today's silent post-turn flush; follow-up is
|
|
1371
|
-
// the closest fit). Phase 4 ships visible/rebindable; both kinds still
|
|
1372
|
-
// drain post-turn — Phases 5–7 turn on real mid-turn delivery for steer
|
|
1373
|
-
// per provider.
|
|
1374
|
-
if (opts?.claimGuard && (wf.busy || wf.computerResetting))
|
|
1375
|
-
return;
|
|
1376
|
-
if (wf.busy || wf.computerResetting) {
|
|
1377
|
-
if (primitive === 'plan-review') {
|
|
1378
|
-
send(ws, { type: 'system_notice', workflowId, content: '[PLAN DRAFT NOT STARTED] Wait for the current turn to finish, then try again.' });
|
|
1379
|
-
return;
|
|
1462
|
+
// docs/ARCHITECTURE.md - context-refs expansion. Expand `@`-refs
|
|
1463
|
+
// (`@file:`, `@diff`, `@staged`, `@git:N`; `@url:` deferred) ONCE here, before
|
|
1464
|
+
// the busy/queue split, so queued AND immediate sends both carry the result.
|
|
1465
|
+
// The operator's chat echo stays compact (raw `content`); the expanded block
|
|
1466
|
+
// is appended to the MODEL prompt only (below for immediate; on the QueueItem
|
|
1467
|
+
// for queued). A system_notice summarizes the expansion so it's visible +
|
|
1468
|
+
// reviewable in events.jsonl (the four-question test). Never throws — the
|
|
1469
|
+
// expander converts every failure to a notice.
|
|
1470
|
+
const contextExpansion = !projectContextEnabled || fromQueue
|
|
1471
|
+
? { block: '', notices: [], expandedCount: 0 }
|
|
1472
|
+
: await expandContextRefs(cwd, content, { windowSize: lookupCtx(wf.primary.model) }).catch((err) => {
|
|
1473
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] context-ref expansion failed:`, err);
|
|
1474
|
+
return { block: '', notices: [], expandedCount: 0 };
|
|
1475
|
+
});
|
|
1476
|
+
if (contextExpansion.notices.length > 0) {
|
|
1477
|
+
send(ws, {
|
|
1478
|
+
type: 'system_notice',
|
|
1479
|
+
workflowId,
|
|
1480
|
+
content: `[CONTEXT REFS] expanded ${contextExpansion.expandedCount} ref` +
|
|
1481
|
+
`${contextExpansion.expandedCount === 1 ? '' : 's'} into this turn's context:\n` +
|
|
1482
|
+
contextExpansion.notices.map((n) => ` • ${n}`).join('\n'),
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
let expandedContext = contextExpansion.block || undefined;
|
|
1486
|
+
const contextAttachments = contextExpansion.attachments ?? [];
|
|
1487
|
+
const editPickedSkills = Array.isArray(pickedSkills)
|
|
1488
|
+
? pickedSkills.filter(p => p && ['project', 'global', 'builtin'].includes(p.scope) && typeof p.slug === 'string' && p.slug.length > 0)
|
|
1489
|
+
.filter((p, index, all) => all.findIndex(other => other.scope === p.scope && other.slug === p.slug) === index)
|
|
1490
|
+
.map(({ scope, slug }) => ({ scope, slug })) : undefined;
|
|
1491
|
+
pickedSkills = editPickedSkills;
|
|
1492
|
+
// A synchronous provider drain cannot load one-shot skills. Resolve them
|
|
1493
|
+
// before admitting a busy send; both drain paths then carry the same block.
|
|
1494
|
+
if (wf.busy && pickedSkills?.length) {
|
|
1495
|
+
const selectedBlock = await resolvePickedSkillsBlock(pickedSkills);
|
|
1496
|
+
if (selectedBlock)
|
|
1497
|
+
expandedContext = `${expandedContext ?? ''}\n\n${selectedBlock}`;
|
|
1498
|
+
pickedSkills = undefined;
|
|
1380
1499
|
}
|
|
1381
|
-
//
|
|
1382
|
-
//
|
|
1383
|
-
if (
|
|
1500
|
+
// STOP/removal during async ref/trust preparation revokes every pending
|
|
1501
|
+
// send, before it can claim a fresh busy token or enter either queue.
|
|
1502
|
+
if (workflows.get(workflowId) !== wf || (busyRevocations.get(wf) ?? 0) !== interruptEpoch) {
|
|
1503
|
+
if (clientMessageId)
|
|
1504
|
+
send(ws, { type: 'queued_message_cancelled', workflowId, clientMessageId });
|
|
1384
1505
|
return;
|
|
1385
|
-
if (!interjection) {
|
|
1386
|
-
// Non-interjection arriving while busy is a client bug (didn't tag it),
|
|
1387
|
-
// but we still queue rather than error — drops fewer operator messages.
|
|
1388
|
-
console.warn(`[arco] [${workflowId.slice(0, 8)}] user_message while busy without interjection flag — queuing anyway`);
|
|
1389
1506
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1507
|
+
// Busy sends are echoed once and queued. Interrupt is a priority turn after
|
|
1508
|
+
// provider teardown; it must keep this loop's busy claim and older queue.
|
|
1509
|
+
//
|
|
1510
|
+
// Phase 4 — `kind` selects steering vs follow-up bucket. Default 'follow-up'
|
|
1511
|
+
// for back-compat with pre-Phase-4 clients (they sent `interjection: true`
|
|
1512
|
+
// with no kind, which matched today's silent post-turn flush; follow-up is
|
|
1513
|
+
// the closest fit). Phase 4 ships visible/rebindable; both kinds still
|
|
1514
|
+
// drain post-turn — Phases 5–7 turn on real mid-turn delivery for steer
|
|
1515
|
+
// per provider.
|
|
1516
|
+
if (opts?.busyOnly && (!wf.busy || wf.computerResetting || lastBusyClaim.get(wf) !== busyOnlyClaim || (opts.busyOnlyGuard && !opts.busyOnlyGuard())))
|
|
1517
|
+
return;
|
|
1518
|
+
if (opts?.claimGuard && (wf.busy || wf.computerResetting))
|
|
1519
|
+
return;
|
|
1520
|
+
if (wf.busy || wf.computerResetting) {
|
|
1521
|
+
if (primitive === 'plan-review') {
|
|
1522
|
+
send(ws, { type: 'system_notice', workflowId, content: '[PLAN DRAFT NOT STARTED] Wait for the current turn to finish, then try again.' });
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
// A drain lost the race to another holder; that holder's loop (or its own
|
|
1526
|
+
// drainQueueIfIdle) flushes the queue — nothing to enqueue here.
|
|
1527
|
+
if (fromQueue)
|
|
1528
|
+
return;
|
|
1529
|
+
if (!interjection) {
|
|
1530
|
+
// Non-interjection arriving while busy is a client bug (didn't tag it),
|
|
1531
|
+
// but we still queue rather than error — drops fewer operator messages.
|
|
1532
|
+
console.warn(`[arco] [${workflowId.slice(0, 8)}] user_message while busy without interjection flag — queuing anyway`);
|
|
1533
|
+
}
|
|
1534
|
+
const toolsPending = clusterToolsPending(wf, clusterStore.getClusterIdForWorkflow(workflowId));
|
|
1535
|
+
if (opts?.clusterBusyReminder && toolsPending)
|
|
1536
|
+
return;
|
|
1537
|
+
if (toolsPending && !opts?.clusterBusyReminder && opts?.automaticKind !== 'auto-pickup' && !opts?.backgroundEvent)
|
|
1538
|
+
broadcastWorkflow(workflowId, {
|
|
1539
|
+
type: 'system_notice', workflowId, content: CLUSTER_TOOLS_PENDING_NOTICE,
|
|
1540
|
+
});
|
|
1541
|
+
const interrupt = kind === 'interrupt' && !wf.config.voiceOperator
|
|
1542
|
+
&& (wf.primary.provider === 'claude' || wf.primary.provider === 'codex')
|
|
1543
|
+
&& wf.primaryTurn !== undefined && ownsBusy(wf, wf.primaryTurn.token);
|
|
1544
|
+
const bucket = interrupt ? 'steer'
|
|
1545
|
+
: isComputerBackgroundClaim(workflowId) || kind === 'interrupt' ? 'follow-up' : kind ?? 'follow-up';
|
|
1546
|
+
if (kind === 'interrupt' && !interrupt)
|
|
1547
|
+
broadcastWorkflow(workflowId, {
|
|
1548
|
+
type: 'system_notice', workflowId,
|
|
1549
|
+
content: '[INTERRUPT & SEND] No interruptible Claude or Codex primary turn is running. Your message is queued as a follow-up.',
|
|
1550
|
+
});
|
|
1551
|
+
const arr = bucket === 'steer' ? wf.queue.steering : wf.queue.followUp;
|
|
1552
|
+
const queuedAttachments = [...new Set([...(attachments ?? []), ...contextAttachments])];
|
|
1553
|
+
const queuedItem = { clusterBusyReminder: opts?.clusterBusyReminder, automaticKind: opts?.automaticKind, content, attachments: isolatedMember || !queuedAttachments.length ? undefined : queuedAttachments, clientMessageId, expandedContext, pickedSkills, editPickedSkills, ollamaInputSeq: undefined, ...(interrupt ? { interrupt: true } : {}) };
|
|
1554
|
+
arr.push(queuedItem);
|
|
1555
|
+
opts?.onBusyQueued?.();
|
|
1556
|
+
send(ws, {
|
|
1557
|
+
type: 'user_message_echo',
|
|
1558
|
+
workflowId,
|
|
1559
|
+
...(opts?.automaticKind ? { automaticKind: opts.automaticKind } : {}),
|
|
1560
|
+
content,
|
|
1561
|
+
attachments,
|
|
1562
|
+
clientMessageId,
|
|
1563
|
+
timestamp: Date.now(),
|
|
1564
|
+
kind: interrupt ? 'interrupt' : bucket,
|
|
1565
|
+
deliveryTracked: true,
|
|
1566
|
+
...(trackOllama ? { ollamaReplayInput: true } : {}),
|
|
1399
1567
|
});
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
if (trackOllama)
|
|
1414
|
-
queuedItem.ollamaInputSeq = currentWorkflowSeq(cwd, workflowId);
|
|
1415
|
-
broadcastQueueUpdate(workflowId);
|
|
1416
|
-
if (interrupt) {
|
|
1417
|
-
disarmGoalRun(workflowId, wf, 'the operator interrupted with a new instruction');
|
|
1418
|
-
broadcastWorkflow(workflowId, { type: 'system_notice', workflowId,
|
|
1419
|
-
content: '[INTERRUPT & SEND] Interrupting the current turn. This message runs next; existing queued messages are preserved. Completed changes remain in place.' });
|
|
1420
|
-
const active = wf.primaryTurn;
|
|
1421
|
-
if (active?.workerId && !active.interruption) {
|
|
1422
|
-
active.interruption = wf.manager.interrupt(active.workerId);
|
|
1423
|
-
// Observe immediately: settlement below awaits the same promise.
|
|
1424
|
-
void active.interruption.catch(() => { });
|
|
1568
|
+
if (trackOllama)
|
|
1569
|
+
queuedItem.ollamaInputSeq = currentWorkflowSeq(cwd, workflowId);
|
|
1570
|
+
broadcastQueueUpdate(workflowId);
|
|
1571
|
+
if (interrupt) {
|
|
1572
|
+
disarmGoalRun(workflowId, wf, 'the operator interrupted with a new instruction');
|
|
1573
|
+
broadcastWorkflow(workflowId, { type: 'system_notice', workflowId,
|
|
1574
|
+
content: '[INTERRUPT & SEND] Interrupting the current turn. This message runs next; existing queued messages are preserved. Completed changes remain in place.' });
|
|
1575
|
+
const active = wf.primaryTurn;
|
|
1576
|
+
if (active?.workerId && !active.interruption) {
|
|
1577
|
+
active.interruption = wf.manager.interrupt(active.workerId);
|
|
1578
|
+
// Observe immediately: settlement below awaits the same promise.
|
|
1579
|
+
void active.interruption.catch(() => { });
|
|
1580
|
+
}
|
|
1425
1581
|
}
|
|
1426
|
-
|
|
1427
|
-
console.log(`[arco] [${workflowId.slice(0, 8)}] queued as ${bucket} (depth: steer=${wf.queue.steering.length}, follow-up=${wf.queue.followUp.length})`);
|
|
1428
|
-
return;
|
|
1429
|
-
}
|
|
1430
|
-
// Refuse the turn if a native `claude --resume` terminal has written to
|
|
1431
|
-
// this session JSONL recently. Two concurrent writers corrupt session
|
|
1432
|
-
// state — the JSONL interleaves sdk-cli and cli entries, the model sees
|
|
1433
|
-
// synthetic "Continue from where you left off" turns, and Arco's chat
|
|
1434
|
-
// drifts from the CLI's internal state. The block clears itself
|
|
1435
|
-
// FOREIGN_WRITE_BLOCK_MS after the last foreign write (i.e. ~60s after
|
|
1436
|
-
// the operator closes the native terminal), without needing explicit
|
|
1437
|
-
// state reset. A handoff remains the clean escape.
|
|
1438
|
-
if (wf.lastForeignWriteAt && (Date.now() - wf.lastForeignWriteAt) < FOREIGN_WRITE_BLOCK_MS) {
|
|
1439
|
-
// Queued items stay queued (already echoed); the operator resends later.
|
|
1440
|
-
if (fromQueue)
|
|
1441
|
-
return;
|
|
1442
|
-
const secs = Math.ceil((FOREIGN_WRITE_BLOCK_MS - (Date.now() - wf.lastForeignWriteAt)) / 1000);
|
|
1443
|
-
send(ws, {
|
|
1444
|
-
type: 'system_notice',
|
|
1445
|
-
workflowId,
|
|
1446
|
-
content: `[TURN BLOCKED] A native \`claude --resume\` terminal is writing to this session. Close it (Arco will auto-clear the block ~${secs}s after its last write), or rotate via Handoff to continue in a clean session.`,
|
|
1447
|
-
});
|
|
1448
|
-
// Echo the operator's message so it isn't silently dropped; they can
|
|
1449
|
-
// resend once the block clears.
|
|
1450
|
-
send(ws, {
|
|
1451
|
-
type: 'user_message_echo',
|
|
1452
|
-
workflowId,
|
|
1453
|
-
content,
|
|
1454
|
-
attachments,
|
|
1455
|
-
clientMessageId,
|
|
1456
|
-
timestamp: Date.now(),
|
|
1457
|
-
});
|
|
1458
|
-
return;
|
|
1459
|
-
}
|
|
1460
|
-
// Cancel any in-flight calibration pty before starting the primary turn.
|
|
1461
|
-
// Calibration is idle-only; the primary turn takes priority.
|
|
1462
|
-
if (wf.cancelCalibration) {
|
|
1463
|
-
wf.cancelCalibration();
|
|
1464
|
-
wf.cancelCalibration = undefined;
|
|
1465
|
-
}
|
|
1466
|
-
// Drain path: splice the queue in the same synchronous span as the busy
|
|
1467
|
-
// claim below, so nothing can slip in between the idle check and the take.
|
|
1468
|
-
let initialInterrupt = false;
|
|
1469
|
-
// Refuse before taking queued input: a restore admitted during preflight
|
|
1470
|
-
// must leave the queue available for an explicit later attempt.
|
|
1471
|
-
assertCheckoutAvailable(workflowWritePaths(wf));
|
|
1472
|
-
let activeOllamaInputSeqs = [];
|
|
1473
|
-
if (fromQueue) {
|
|
1474
|
-
const drained = takeQueuedTurn(wf.queue);
|
|
1475
|
-
if (drained.length === 0)
|
|
1582
|
+
console.log(`[arco] [${workflowId.slice(0, 8)}] queued as ${bucket} (depth: steer=${wf.queue.steering.length}, follow-up=${wf.queue.followUp.length})`);
|
|
1476
1583
|
return;
|
|
1477
|
-
if (!incognito)
|
|
1478
|
-
console.log(`[arco] [${workflowId.slice(0, 8)}] idle drain: flushing ${drained.length} queued message(s) as a fresh turn`);
|
|
1479
|
-
broadcastQueueUpdate(workflowId);
|
|
1480
|
-
const drainedClientIds = drained
|
|
1481
|
-
.map((d) => d.clientMessageId)
|
|
1482
|
-
.filter((id) => typeof id === 'string' && id.length > 0);
|
|
1483
|
-
if (drainedClientIds.length > 0) {
|
|
1484
|
-
send(ws, { type: 'queued_messages_drained', workflowId, clientMessageIds: drainedClientIds, drainedAt: Date.now() });
|
|
1485
1584
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1585
|
+
// Refuse the turn if a native `claude --resume` terminal has written to
|
|
1586
|
+
// this session JSONL recently. Two concurrent writers corrupt session
|
|
1587
|
+
// state — the JSONL interleaves sdk-cli and cli entries, the model sees
|
|
1588
|
+
// synthetic "Continue from where you left off" turns, and Arco's chat
|
|
1589
|
+
// drifts from the CLI's internal state. The block clears itself
|
|
1590
|
+
// FOREIGN_WRITE_BLOCK_MS after the last foreign write (i.e. ~60s after
|
|
1591
|
+
// the operator closes the native terminal), without needing explicit
|
|
1592
|
+
// state reset. A handoff remains the clean escape.
|
|
1593
|
+
if (wf.lastForeignWriteAt && (Date.now() - wf.lastForeignWriteAt) < FOREIGN_WRITE_BLOCK_MS) {
|
|
1594
|
+
// Queued items stay queued (already echoed); the operator resends later.
|
|
1595
|
+
if (fromQueue)
|
|
1596
|
+
return;
|
|
1597
|
+
const secs = Math.ceil((FOREIGN_WRITE_BLOCK_MS - (Date.now() - wf.lastForeignWriteAt)) / 1000);
|
|
1598
|
+
send(ws, {
|
|
1599
|
+
type: 'system_notice',
|
|
1600
|
+
workflowId,
|
|
1601
|
+
content: `[TURN BLOCKED] A native \`claude --resume\` terminal is writing to this session. Close it (Arco will auto-clear the block ~${secs}s after its last write), or rotate via Handoff to continue in a clean session.`,
|
|
1602
|
+
});
|
|
1603
|
+
// Echo the operator's message so it isn't silently dropped; they can
|
|
1604
|
+
// resend once the block clears.
|
|
1605
|
+
send(ws, {
|
|
1606
|
+
type: 'user_message_echo',
|
|
1607
|
+
workflowId,
|
|
1608
|
+
...(opts?.automaticKind ? { automaticKind: opts.automaticKind } : {}),
|
|
1609
|
+
content,
|
|
1610
|
+
attachments,
|
|
1611
|
+
clientMessageId,
|
|
1612
|
+
timestamp: Date.now(),
|
|
1613
|
+
});
|
|
1511
1614
|
return;
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
// An armed goal run stops on an errored turn rather than looping on the same
|
|
1540
|
-
// failure; the flag has to outlive the loop body to reach `maybeGoalRun`.
|
|
1541
|
-
let lastTurnErrored = false;
|
|
1542
|
-
let policyReading;
|
|
1543
|
-
let staleLoop = false;
|
|
1544
|
-
let watchLoopFinished = false;
|
|
1545
|
-
let watchHadError = false;
|
|
1546
|
-
let preserveQueue = false;
|
|
1547
|
-
const loadQueuedPrompt = (append = false) => {
|
|
1548
|
-
const drained = takeQueuedTurn(wf.queue);
|
|
1549
|
-
broadcastQueueUpdate(workflowId);
|
|
1550
|
-
const ids = drained.flatMap((d) => d.clientMessageId ? [d.clientMessageId] : []);
|
|
1551
|
-
if (ids.length)
|
|
1552
|
-
send(ws, { type: 'queued_messages_drained', workflowId,
|
|
1553
|
-
clientMessageIds: ids, drainedAt: Date.now() });
|
|
1554
|
-
activeOllamaInputSeqs = drained.every(d => d.ollamaInputSeq) ? [...(append ? activeOllamaInputSeqs : []), ...drained.map(d => d.ollamaInputSeq)] : [];
|
|
1555
|
-
prompt = [...(append ? [prompt] : []), ...drained.map((d) => d.content)].join('\n\n');
|
|
1556
|
-
const files = [...(append ? promptAttachments ?? [] : []), ...drained.flatMap((d) => d.attachments ?? [])];
|
|
1557
|
-
promptAttachments = files.length ? files : undefined;
|
|
1558
|
-
const refs = (append ? promptExpandedContext ?? '' : '') + drained.map((d) => d.expandedContext ?? '').join('');
|
|
1559
|
-
promptExpandedContext = refs || undefined;
|
|
1560
|
-
promptClientMessageId = undefined;
|
|
1561
|
-
promptPickedSkills = [...(append ? promptPickedSkills ?? [] : []), ...drained.flatMap((d) => d.pickedSkills ?? [])];
|
|
1562
|
-
primaryTurn.holdSteer = drained.some((d) => d.interrupt);
|
|
1563
|
-
};
|
|
1564
|
-
// DD7 — project-trust gate. Resolve ONCE per turn (stable across drain
|
|
1565
|
-
// iterations) from USER/GLOBAL scope only — trust.json + the global
|
|
1566
|
-
// settings.json's defaultProjectTrust — BEFORE any project-local surface is
|
|
1567
|
-
// read below. When the repo is untrusted, `includeProject` suppresses its
|
|
1568
|
-
// CLAUDE.md, project skills, and project settings.json from the model turn
|
|
1569
|
-
// (the cloned-repo prompt-injection vector). The turn STILL PROCEEDS; an
|
|
1570
|
-
// 'ask' repo additionally raises a one-time operator prompt (deduped per cwd,
|
|
1571
|
-
// so cluster peers sharing the cwd prompt once). Decision + suppressed list
|
|
1572
|
-
// land in events.jsonl for the four-question test's visibility leg.
|
|
1573
|
-
const trustGate = !projectContextEnabled
|
|
1574
|
-
? { includeProject: false, needsPrompt: false, status: 'never', resources: [] }
|
|
1575
|
-
: await (managedTrustSource
|
|
1576
|
-
? projectTrust.gateManagedWorktreeResources(cwd, managedTrustSource)
|
|
1577
|
-
: projectTrust.gateProjectResources(cwd)).catch((err) => {
|
|
1578
|
-
// Fail SAFE: on any gate error, suppress project resources rather than
|
|
1579
|
-
// leaking an unvetted repo's instructions into the turn.
|
|
1580
|
-
console.error(`[arco] [${workflowId.slice(0, 8)}] project-trust gate failed; suppressing project resources:`, err);
|
|
1581
|
-
return { includeProject: false, needsPrompt: false, status: 'ask', resources: [] };
|
|
1582
|
-
});
|
|
1583
|
-
const includeProject = trustGate.includeProject;
|
|
1584
|
-
const trustDecisionCwd = managedTrustSource ?? cwd;
|
|
1585
|
-
// Log the suppression for the four-question test's visibility leg — but stay
|
|
1586
|
-
// quiet for an explicit 'never' (the operator deliberately chose to suppress;
|
|
1587
|
-
// a per-turn notice would just nag). 'ask' / fail-safe always log.
|
|
1588
|
-
if (!includeProject && trustGate.resources.length > 0 && trustGate.status !== 'never') {
|
|
1589
|
-
broadcastWorkflow(workflowId, {
|
|
1590
|
-
type: 'system_notice',
|
|
1591
|
-
workflowId,
|
|
1592
|
-
content: `[PROJECT TRUST] This repo is not trusted (${trustGate.status}); suppressed from this turn: ` +
|
|
1593
|
-
`${trustGate.resources.join(', ')}. Trust it to fold these in (next turn).`,
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
if (trustGate.needsPrompt && projectTrust.markPromptPending(trustDecisionCwd)) {
|
|
1597
|
-
broadcastWorkflow(workflowId, {
|
|
1598
|
-
type: 'project_trust_prompt',
|
|
1599
|
-
workflowId,
|
|
1600
|
-
cwd: trustDecisionCwd,
|
|
1601
|
-
resources: trustGate.resources,
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
// DD8 — resolve picks for the prompt that owns them, including queued
|
|
1605
|
-
// interrupt instructions. Picking is an explicit operator action, so it
|
|
1606
|
-
// applies regardless
|
|
1607
|
-
// of the DD7 trust gate above — picking IS the operator's vouch. A missing /
|
|
1608
|
-
// unreadable skill is skipped with a notice rather than failing the turn.
|
|
1609
|
-
async function resolvePickedSkillsBlock(picks) {
|
|
1610
|
-
if (!projectContextEnabled || !picks?.length)
|
|
1611
|
-
return '';
|
|
1612
|
-
const resolved = [];
|
|
1613
|
-
const missing = [];
|
|
1614
|
-
for (const pick of picks) {
|
|
1615
|
-
try {
|
|
1616
|
-
const full = await readSkillBody(pick.scope, pick.slug, cwd);
|
|
1617
|
-
if (full)
|
|
1618
|
-
resolved.push({ name: full.name, scope: full.scope, body: full.body });
|
|
1619
|
-
else
|
|
1620
|
-
missing.push(`${pick.scope}:${pick.slug}`);
|
|
1621
|
-
}
|
|
1622
|
-
catch {
|
|
1623
|
-
missing.push(`${pick.scope}:${pick.slug}`);
|
|
1615
|
+
}
|
|
1616
|
+
// Cancel any in-flight calibration pty before starting the primary turn.
|
|
1617
|
+
// Calibration is idle-only; the primary turn takes priority.
|
|
1618
|
+
if (wf.cancelCalibration) {
|
|
1619
|
+
wf.cancelCalibration();
|
|
1620
|
+
wf.cancelCalibration = undefined;
|
|
1621
|
+
}
|
|
1622
|
+
// Drain path: splice the queue in the same synchronous span as the busy
|
|
1623
|
+
// claim below, so nothing can slip in between the idle check and the take.
|
|
1624
|
+
let initialInterrupt = false;
|
|
1625
|
+
// Refuse before taking queued input: a restore admitted during preflight
|
|
1626
|
+
// must leave the queue available for an explicit later attempt.
|
|
1627
|
+
assertCheckoutAvailable(workflowWritePaths(wf));
|
|
1628
|
+
let activeOllamaInputSeqs = [];
|
|
1629
|
+
let activeInputClientIds = [];
|
|
1630
|
+
if (fromQueue) {
|
|
1631
|
+
const drained = takeQueuedTurn(wf.queue);
|
|
1632
|
+
if (drained.length === 0)
|
|
1633
|
+
return;
|
|
1634
|
+
if (!incognito)
|
|
1635
|
+
console.log(`[arco] [${workflowId.slice(0, 8)}] idle drain: flushing ${drained.length} queued message(s) as a fresh turn`);
|
|
1636
|
+
broadcastQueueUpdate(workflowId);
|
|
1637
|
+
const drainedClientIds = drained
|
|
1638
|
+
.map((d) => d.clientMessageId)
|
|
1639
|
+
.filter((id) => typeof id === 'string' && id.length > 0);
|
|
1640
|
+
if (drainedClientIds.length > 0) {
|
|
1641
|
+
send(ws, { type: 'queued_messages_drained', workflowId, clientMessageIds: drainedClientIds, drainedAt: Date.now() });
|
|
1624
1642
|
}
|
|
1643
|
+
activeInputClientIds = drained.flatMap(item => item.clientMessageId ? [item.clientMessageId] : []);
|
|
1644
|
+
activeOllamaInputSeqs = drained.every(d => d.ollamaInputSeq) ? drained.map(d => d.ollamaInputSeq) : [];
|
|
1645
|
+
content = drained.map((d) => d.content).join('\n\n');
|
|
1646
|
+
const mergedAttachments = drained.flatMap((d) => d.attachments ?? []);
|
|
1647
|
+
attachments = mergedAttachments.length > 0 ? mergedAttachments : undefined;
|
|
1648
|
+
const mergedRefs = drained.map((d) => d.expandedContext ?? '').filter(Boolean).join('');
|
|
1649
|
+
expandedContext = mergedRefs.length > 0 ? mergedRefs : undefined;
|
|
1650
|
+
clientMessageId = undefined;
|
|
1651
|
+
pickedSkills = drained.flatMap((d) => d.pickedSkills ?? []);
|
|
1652
|
+
initialInterrupt = drained.some((d) => d.interrupt);
|
|
1625
1653
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1654
|
+
let busyToken;
|
|
1655
|
+
if (primitive === 'plan-review')
|
|
1656
|
+
disarmGoalRun(workflowId, wf, 'a plan review was requested');
|
|
1657
|
+
if (opts?.claimGuard) {
|
|
1658
|
+
let guardedToken;
|
|
1659
|
+
await opts.claimGuard(() => {
|
|
1660
|
+
// Async preflight may have lost to STOP, a real operator turn or removal.
|
|
1661
|
+
// Conditional nudges must never fall into the ordinary follow-up queue.
|
|
1662
|
+
if (workflows.get(workflowId) !== wf || (busyRevocations.get(wf) ?? 0) !== interruptEpoch || wf.busy || wf.computerResetting || wf.queue.steering.length || wf.queue.followUp.length
|
|
1663
|
+
|| (wf.lastForeignWriteAt && Date.now() - wf.lastForeignWriteAt < FOREIGN_WRITE_BLOCK_MS))
|
|
1664
|
+
return false;
|
|
1665
|
+
guardedToken = claimBusy(wf);
|
|
1666
|
+
return true;
|
|
1667
|
+
});
|
|
1668
|
+
if (guardedToken === undefined)
|
|
1669
|
+
return;
|
|
1670
|
+
busyToken = guardedToken;
|
|
1671
|
+
}
|
|
1672
|
+
else
|
|
1673
|
+
busyToken = claimBusy(wf);
|
|
1674
|
+
const primaryTurn = { token: busyToken, holdSteer: initialInterrupt };
|
|
1675
|
+
wf.primaryTurn = primaryTurn;
|
|
1676
|
+
// Drive the turn loop. On first iteration `prompt` is the incoming content;
|
|
1677
|
+
// on subsequent iterations it's the drained interjection queue (joined so
|
|
1678
|
+
// multiple queued messages land in a single follow-up turn). This keeps
|
|
1679
|
+
// the CLI session alive and matches Claude Code terminal's flush-on-idle.
|
|
1680
|
+
if (opts?.backgroundEvent)
|
|
1681
|
+
setComputerBackgroundClaim(workflowId, busyToken);
|
|
1682
|
+
let prompt = content;
|
|
1683
|
+
let promptPickedSkills = pickedSkills;
|
|
1684
|
+
const initialAttachments = [...new Set([...(attachments ?? []), ...contextAttachments])];
|
|
1685
|
+
let promptAttachments = isolatedMember || !initialAttachments.length ? undefined : initialAttachments;
|
|
1686
|
+
let promptClientMessageId = clientMessageId;
|
|
1687
|
+
// §D1 — expanded `@`-context-refs for the current iteration's prompt. First
|
|
1688
|
+
// iteration uses the immediate-send expansion; drain iterations rebuild it
|
|
1689
|
+
// from the drained QueueItems' stored blocks. Appended to the model prompt
|
|
1690
|
+
// (after the plan prefix) but never to the echo.
|
|
1691
|
+
let promptExpandedContext = expandedContext;
|
|
1692
|
+
// First iteration echoes the original message via the standard path; later
|
|
1693
|
+
// iterations generate their own clientMessageId so the dedup on the
|
|
1694
|
+
// originating tab doesn't accidentally swallow an auto-flushed prompt
|
|
1695
|
+
// whose UUID was already rendered client-side.
|
|
1696
|
+
let firstIteration = true;
|
|
1697
|
+
// docs/GOTCHAS.md - outcome of the LAST settled turn in this drain loop.
|
|
1698
|
+
// An armed goal run stops on an errored turn rather than looping on the same
|
|
1699
|
+
// failure; the flag has to outlive the loop body to reach `maybeGoalRun`.
|
|
1700
|
+
let lastTurnErrored = false;
|
|
1701
|
+
let policyReading;
|
|
1702
|
+
let staleLoop = false;
|
|
1703
|
+
let watchLoopFinished = false;
|
|
1704
|
+
let watchHadError = false;
|
|
1705
|
+
let preserveQueue = false;
|
|
1706
|
+
const loadQueuedPrompt = (append = false) => {
|
|
1707
|
+
const drained = takeQueuedTurn(wf.queue);
|
|
1708
|
+
broadcastQueueUpdate(workflowId);
|
|
1709
|
+
const ids = drained.flatMap((d) => d.clientMessageId ? [d.clientMessageId] : []);
|
|
1710
|
+
if (ids.length)
|
|
1711
|
+
send(ws, { type: 'queued_messages_drained', workflowId,
|
|
1712
|
+
clientMessageIds: ids, drainedAt: Date.now() });
|
|
1713
|
+
activeInputClientIds = [...(append ? activeInputClientIds : []), ...drained.flatMap(item => item.clientMessageId ? [item.clientMessageId] : [])];
|
|
1714
|
+
activeOllamaInputSeqs = drained.every(d => d.ollamaInputSeq) ? [...(append ? activeOllamaInputSeqs : []), ...drained.map(d => d.ollamaInputSeq)] : [];
|
|
1715
|
+
prompt = [...(append ? [prompt] : []), ...drained.map((d) => d.content)].join('\n\n');
|
|
1716
|
+
const files = [...(append ? promptAttachments ?? [] : []), ...drained.flatMap((d) => d.attachments ?? [])];
|
|
1717
|
+
promptAttachments = files.length ? files : undefined;
|
|
1718
|
+
const refs = (append ? promptExpandedContext ?? '' : '') + drained.map((d) => d.expandedContext ?? '').join('');
|
|
1719
|
+
promptExpandedContext = refs || undefined;
|
|
1720
|
+
promptClientMessageId = undefined;
|
|
1721
|
+
promptPickedSkills = [...(append ? promptPickedSkills ?? [] : []), ...drained.flatMap((d) => d.pickedSkills ?? [])];
|
|
1722
|
+
primaryTurn.holdSteer = drained.some((d) => d.interrupt);
|
|
1723
|
+
};
|
|
1724
|
+
// DD7 — project-trust gate. Resolve ONCE per turn (stable across drain
|
|
1725
|
+
// iterations) from USER/GLOBAL scope only — trust.json + the global
|
|
1726
|
+
// settings.json's defaultProjectTrust — BEFORE any project-local surface is
|
|
1727
|
+
// read below. When the repo is untrusted, `includeProject` suppresses its
|
|
1728
|
+
// CLAUDE.md, project skills, and project settings.json from the model turn
|
|
1729
|
+
// (the cloned-repo prompt-injection vector). The turn STILL PROCEEDS; an
|
|
1730
|
+
// 'ask' repo additionally raises a one-time operator prompt (deduped per cwd,
|
|
1731
|
+
// so cluster peers sharing the cwd prompt once). Decision + suppressed list
|
|
1732
|
+
// land in events.jsonl for the four-question test's visibility leg.
|
|
1733
|
+
const trustGate = !projectContextEnabled
|
|
1734
|
+
? { includeProject: false, needsPrompt: false, status: 'never', resources: [] }
|
|
1735
|
+
: await (managedTrustSource
|
|
1736
|
+
? projectTrust.gateManagedWorktreeResources(cwd, managedTrustSource)
|
|
1737
|
+
: projectTrust.gateProjectResources(cwd)).catch((err) => {
|
|
1738
|
+
// Fail SAFE: on any gate error, suppress project resources rather than
|
|
1739
|
+
// leaking an unvetted repo's instructions into the turn.
|
|
1740
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] project-trust gate failed; suppressing project resources:`, err);
|
|
1741
|
+
return { includeProject: false, needsPrompt: false, status: 'ask', resources: [] };
|
|
1742
|
+
});
|
|
1743
|
+
const includeProject = trustGate.includeProject;
|
|
1744
|
+
const trustDecisionCwd = managedTrustSource ?? cwd;
|
|
1745
|
+
// Log the suppression for the four-question test's visibility leg — but stay
|
|
1746
|
+
// quiet for an explicit 'never' (the operator deliberately chose to suppress;
|
|
1747
|
+
// a per-turn notice would just nag). 'ask' / fail-safe always log.
|
|
1748
|
+
if (!includeProject && trustGate.resources.length > 0 && trustGate.status !== 'never') {
|
|
1649
1749
|
broadcastWorkflow(workflowId, {
|
|
1650
1750
|
type: 'system_notice',
|
|
1651
1751
|
workflowId,
|
|
1652
|
-
content: `[
|
|
1752
|
+
content: `[PROJECT TRUST] This repo is not trusted (${trustGate.status}); suppressed from this turn: ` +
|
|
1753
|
+
`${trustGate.resources.join(', ')}. Trust it to fold these in (next turn).`,
|
|
1653
1754
|
});
|
|
1654
1755
|
}
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
// Adaptive-thinking display for the Native worker. Absent ⇒ 'omitted'
|
|
1702
|
-
// (Claude-Code parity — no thinking streamed back); 'summarized' streams
|
|
1703
|
-
// summarized thinking into the Activity tab.
|
|
1704
|
-
const claudeNativeThinkingDisplay = claudeTransport === 'native'
|
|
1705
|
-
? wf.config.claudeNativeThinkingDisplay
|
|
1706
|
-
: undefined;
|
|
1707
|
-
// docs/PROVIDERS.md - Native tool-result filter mode. Only honored
|
|
1708
|
-
// on Native (the filter pipeline runs inside `claude-native/dispatchTool`;
|
|
1709
|
-
// CLI/Codex don't surface raw tool stdout to us). Default off until measured
|
|
1710
|
-
// per the §13.3 / §2.4 doc-discipline rule (no aggressive defaults).
|
|
1711
|
-
const efficiencyToolFilter = claudeTransport === 'native'
|
|
1712
|
-
? (wf.config.efficiencyToolFilter ?? 'off')
|
|
1713
|
-
: 'off';
|
|
1714
|
-
// docs/PROVIDERS.md - fact-force first-edit gate mode. It is
|
|
1715
|
-
// opt-in: new tabs and rehydrated tabs without the field stay 'off'. CLI
|
|
1716
|
-
// parity is deferred (master §3.3 F4), so hard-zero non-Native transports.
|
|
1717
|
-
const efficiencyFactForce = claudeTransport === 'native'
|
|
1718
|
-
? (wf.config.efficiencyFactForce ?? 'off')
|
|
1719
|
-
: 'off';
|
|
1720
|
-
// Config-protection write-gate. Default 'on' (safety gate); the operator
|
|
1721
|
-
// opts out per-tab. Native-only (the gate lives in the Native worker), so
|
|
1722
|
-
// we hard-zero non-Native transports to 'off' to avoid a meaningless flag.
|
|
1723
|
-
const efficiencyConfigProtection = claudeTransport === 'native'
|
|
1724
|
-
? (wf.config.efficiencyConfigProtection ?? 'on')
|
|
1725
|
-
: 'off';
|
|
1726
|
-
const efficiencySandbox = claudeTransport === 'native' && !isolatedMember
|
|
1727
|
-
? (wf.config.efficiencySandbox ?? 'off')
|
|
1728
|
-
: 'off';
|
|
1729
|
-
// docs/PROVIDERS.md - operator-armed durable review gate. Native-only (the gate
|
|
1730
|
-
// lives in the in-process worker's dispatchTool). Default 'off' so it stays
|
|
1731
|
-
// operator-opted-in and inert until armed.
|
|
1732
|
-
const reviewSafeMode = claudeTransport === 'native'
|
|
1733
|
-
? (wf.config.reviewSafeMode ?? 'off')
|
|
1734
|
-
: 'off';
|
|
1735
|
-
// docs/PROVIDERS.md - operator-armed terseness picker. Honored by
|
|
1736
|
-
const outputStyleSupported = (wf.primary.provider === 'claude' && claudeTransport === 'native') ||
|
|
1737
|
-
(wf.primary.provider === 'codex' && codexTransport === 'appserver');
|
|
1738
|
-
const outputStyle = primitive === 'docs' || primitive === 'git'
|
|
1739
|
-
? 'normal'
|
|
1740
|
-
: outputStyleSupported
|
|
1741
|
-
? (wf.config.outputStyle ?? 'normal')
|
|
1742
|
-
: 'normal';
|
|
1743
|
-
// docs/GOTCHAS.md - operator-set persistent north-star. Read straight
|
|
1744
|
-
// from wf.config, inherited on EVERY path including in-tab DOCS / GIT (the one
|
|
1745
|
-
// deliberate divergence from outputStyle's forced 'normal' for those two — a
|
|
1746
|
-
// DOCS/GIT prompt benefits from the goal context). Absent / blank ⇒ no block
|
|
1747
|
-
// on any transport; honored wherever clusterPlan is folded.
|
|
1748
|
-
const goal = isolatedMember ? undefined : wf.config.goal;
|
|
1749
|
-
// docs/PROVIDERS.md - per-tab Ollama param preset blob. Resolved
|
|
1750
|
-
// ONLY for Ollama tabs (the provider's request builder is the sole consumer;
|
|
1751
|
-
// every other provider ignores the field). Read straight from wf.config so
|
|
1752
|
-
// it is byte-stable across this workflow's turns — the prefix-cache
|
|
1753
|
-
// invariant. The operator-edit path (updatePrimaryConfig) is the only place
|
|
1754
|
-
// it changes between turns, and that's logged as a cache-invalidation event.
|
|
1755
|
-
const ollamaParams = wf.primary.provider === 'ollama'
|
|
1756
|
-
? wf.config.ollamaParams
|
|
1757
|
-
: undefined;
|
|
1758
|
-
let activeTurnObservation;
|
|
1759
|
-
try {
|
|
1760
|
-
while (true) {
|
|
1761
|
-
const pickedSkillsBlock = await resolvePickedSkillsBlock(promptPickedSkills);
|
|
1762
|
-
console.log(`[arco] [${workflowId.slice(0, 8)}] user_message received; starting primary turn (${wf.primary.provider}:${wf.primary.model}, resume=${wf.primarySessionId?.slice(0, 8) || 'none'})`);
|
|
1763
|
-
// Peer mailbox: don't auto-drain pre-turn. Just count what's pending and
|
|
1764
|
-
// surface a short notice so the worker knows it has peer mail and reads
|
|
1765
|
-
// it via peer_read. Keeps peer messages as a normal tool-flow primitive
|
|
1766
|
-
// instead of getting silently shoved into the system prompt where the
|
|
1767
|
-
// model conflates "system context" with "current peer mail."
|
|
1768
|
-
// peer_message_received events now fire on peer_read call (where they
|
|
1769
|
-
// belong) rather than pre-turn.
|
|
1770
|
-
//
|
|
1771
|
-
// Phrase the notice as an instruction to read peer mail so the model
|
|
1772
|
-
// invokes the tool rather than echoing a tool-call example.
|
|
1773
|
-
// the notice text now varies by the cluster's efficiency
|
|
1774
|
-
// level (clusterEfficiency.buildPeerMailboxNotice). At balanced/lean the
|
|
1775
|
-
// doctrine tells members not to re-review unless signalled, so the notice
|
|
1776
|
-
// must NOT also shout "re-engage on every inbound" — that contradiction
|
|
1777
|
-
// is exactly the over-review loop this feature targets. The level lookup
|
|
1778
|
-
// is a synchronous in-memory read, so resolving the clusterId here
|
|
1779
|
-
// (ahead of the turn-start resolution below) is cheap. 'thorough' yields
|
|
1780
|
-
// the byte-identical historical notice.
|
|
1781
|
-
let peerMessagesPrologue;
|
|
1782
|
-
if (firstIteration) {
|
|
1783
|
-
const pendingDepth = await clusterMailbox.depthFor(workflowId).catch(() => 0);
|
|
1784
|
-
if (pendingDepth > 0) {
|
|
1785
|
-
const noticeClusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
1786
|
-
const noticeLevel = noticeClusterId
|
|
1787
|
-
? clusterStore.getEfficiencyLevel(noticeClusterId)
|
|
1788
|
-
: 'thorough';
|
|
1789
|
-
const noticeAccess = noticeClusterId
|
|
1790
|
-
? clusterStore.getMemberAccessMode(noticeClusterId, workflowId)
|
|
1791
|
-
: 'standard';
|
|
1792
|
-
peerMessagesPrologue = noticeAccess === 'standard'
|
|
1793
|
-
? clusterEfficiency.buildPeerMailboxNotice(noticeLevel, pendingDepth, noticeClusterId ? clusterStore.getMemberRole(noticeClusterId, workflowId) : undefined)
|
|
1794
|
-
: `You have ${pendingDepth} pending peer message${pendingDepth === 1 ? '' : 's'}. Read them with peer_read; no other cluster context is available.`;
|
|
1756
|
+
if (trustGate.needsPrompt && projectTrust.markPromptPending(trustDecisionCwd)) {
|
|
1757
|
+
broadcastWorkflow(workflowId, {
|
|
1758
|
+
type: 'project_trust_prompt',
|
|
1759
|
+
workflowId,
|
|
1760
|
+
cwd: trustDecisionCwd,
|
|
1761
|
+
resources: trustGate.resources,
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
// DD8 — resolve picks for the prompt that owns them, including queued
|
|
1765
|
+
// interrupt instructions. Picking is an explicit operator action, so it
|
|
1766
|
+
// applies regardless
|
|
1767
|
+
// of the DD7 trust gate above — picking IS the operator's vouch. A missing /
|
|
1768
|
+
// unreadable skill is skipped with a notice rather than failing the turn.
|
|
1769
|
+
async function resolvePickedSkillsBlock(picks) {
|
|
1770
|
+
if (!projectContextEnabled || !picks?.length)
|
|
1771
|
+
return '';
|
|
1772
|
+
const resolved = [];
|
|
1773
|
+
const missing = [];
|
|
1774
|
+
for (const pick of picks) {
|
|
1775
|
+
try {
|
|
1776
|
+
if (pick.scope === 'builtin') {
|
|
1777
|
+
// Built-in skills ship with Arco. The Architecture review also gets
|
|
1778
|
+
// the facts Arco gathers now and the project's recorded decisions.
|
|
1779
|
+
const builtin = readBuiltinSkill(pick.slug);
|
|
1780
|
+
if (!builtin) {
|
|
1781
|
+
missing.push(`builtin:${pick.slug}`);
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
const trust = await projectTrust.resolveTrustStatus(managedTrustSource ?? cwd).catch(() => 'ask');
|
|
1785
|
+
const catalog = await listSkills(cwd, { includeProject: trust === 'always' });
|
|
1786
|
+
const summary = catalog.builtin.find((s) => s.slug === builtin.slug);
|
|
1787
|
+
if (!summary || summary.off || summary.replaced) {
|
|
1788
|
+
missing.push(`builtin:${pick.slug}`);
|
|
1789
|
+
continue;
|
|
1790
|
+
}
|
|
1791
|
+
const extra = builtin.slug === ARCHITECTURE_REVIEW_SLUG
|
|
1792
|
+
? `\n\nArtifacts folder for this conversation: ${artifactsDir(cwd, workflowId)}\n\n${await architectureReviewFacts(cwd, wf?.planId ?? clusterStore.getPlanId(clusterStore.getClusterIdForWorkflow(workflowId) ?? ''))}`
|
|
1793
|
+
: `\n\nThe available skill files are listed in the skill manifest.`;
|
|
1794
|
+
resolved.push({ name: builtin.name, scope: 'builtin', body: builtin.body + extra });
|
|
1795
|
+
continue;
|
|
1796
|
+
}
|
|
1797
|
+
const full = await readSkillBody(pick.scope, pick.slug, cwd);
|
|
1798
|
+
if (full)
|
|
1799
|
+
resolved.push({ name: full.name, scope: full.scope, body: full.body });
|
|
1800
|
+
else
|
|
1801
|
+
missing.push(`${pick.scope}:${pick.slug}`);
|
|
1795
1802
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
// Drain turns don't re-echo — each queued interjection was already
|
|
1799
|
-
// echoed at enqueue-time, so the transcript renders the individual
|
|
1800
|
-
// interjections rather than the joined follow-up prompt.
|
|
1801
|
-
if (firstIteration) {
|
|
1802
|
-
// An idle drain's items were echoed individually at enqueue time.
|
|
1803
|
-
if (!fromQueue)
|
|
1804
|
-
send(ws, {
|
|
1805
|
-
type: 'user_message_echo',
|
|
1806
|
-
workflowId,
|
|
1807
|
-
content: prompt,
|
|
1808
|
-
attachments: promptAttachments,
|
|
1809
|
-
clientMessageId: promptClientMessageId,
|
|
1810
|
-
timestamp: Date.now(),
|
|
1811
|
-
...(trackOllama ? { ollamaReplayInput: true } : {}),
|
|
1812
|
-
});
|
|
1813
|
-
if (!fromQueue && trackOllama)
|
|
1814
|
-
activeOllamaInputSeqs = [currentWorkflowSeq(cwd, workflowId)];
|
|
1815
|
-
if (chatMode && !incognito) {
|
|
1816
|
-
// Keep the global Past Chats list useful without rescanning a growing
|
|
1817
|
-
// events.jsonl for every creator render.
|
|
1818
|
-
const preview = prompt.replace(/\s+/g, ' ').trim().slice(0, 80);
|
|
1819
|
-
await updateMeta(cwd, workflowId, (meta) => {
|
|
1820
|
-
meta.lastActiveAt = Date.now();
|
|
1821
|
-
meta.lastUserPreview = preview;
|
|
1822
|
-
}).catch((err) => {
|
|
1823
|
-
console.warn(`[arco] [${workflowId.slice(0, 8)}] Chat activity meta write failed:`, err);
|
|
1824
|
-
});
|
|
1803
|
+
catch {
|
|
1804
|
+
missing.push(`${pick.scope}:${pick.slug}`);
|
|
1825
1805
|
}
|
|
1826
1806
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1807
|
+
const built = buildPickedSkillsBlock(resolved);
|
|
1808
|
+
const names = resolved.map((s) => s.name).join(', ');
|
|
1809
|
+
broadcastWorkflow(workflowId, {
|
|
1810
|
+
type: 'system_notice',
|
|
1811
|
+
workflowId,
|
|
1812
|
+
content: `[SKILLS] Inlined ${resolved.length} operator-picked skill${resolved.length === 1 ? '' : 's'} ` +
|
|
1813
|
+
`(${built.bytes} bytes) into this turn${names ? `: ${names}` : ''}.` +
|
|
1814
|
+
(missing.length > 0 ? ` Skipped (not found): ${missing.join(', ')}.` : ''),
|
|
1815
|
+
});
|
|
1816
|
+
return built.text;
|
|
1817
|
+
}
|
|
1818
|
+
// Standing SKILLS pins are re-resolved once per primary-turn invocation.
|
|
1819
|
+
// This keeps edits live, survives Native compaction / Handoff / restart, and
|
|
1820
|
+
// avoids silently snapshotting stale bodies into meta.json. Like a one-shot
|
|
1821
|
+
// pick, a project pin is an explicit operator vouch and bypasses discovery's
|
|
1822
|
+
// project-trust suppression. Missing files fail safe and stay visible.
|
|
1823
|
+
let pinnedSkillsBlock = '';
|
|
1824
|
+
if (projectContextEnabled && wf.config.pinnedSkills?.length) {
|
|
1825
|
+
const resolved = await resolvePinnedSkills(wf.config.pinnedSkills, cwd);
|
|
1826
|
+
const built = buildPinnedSkillsBlock(resolved.skills);
|
|
1827
|
+
pinnedSkillsBlock = built.text;
|
|
1828
|
+
const skipped = [...resolved.missing, ...resolved.truncated];
|
|
1829
|
+
if (skipped.length > 0) {
|
|
1830
|
+
broadcastWorkflow(workflowId, {
|
|
1831
|
+
type: 'system_notice',
|
|
1834
1832
|
workflowId,
|
|
1835
|
-
|
|
1833
|
+
content: `[PINNED SKILLS] ${resolved.skills.length} active (${built.bytes} bytes); skipped: ${skipped.join(', ')}.`,
|
|
1836
1834
|
});
|
|
1837
1835
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1836
|
+
}
|
|
1837
|
+
// Phase 6 — resolve the Codex transport once per primary-turn invocation.
|
|
1838
|
+
// Reading the cascade up here means the value is stable across the
|
|
1839
|
+
// drain-loop iterations below; an HMR-driven settings.json change between
|
|
1840
|
+
// turns won't re-toggle the transport mid-loop, which would otherwise
|
|
1841
|
+
// leak a long-lived `codex app-server` worker after switching back to
|
|
1842
|
+
// exec mode. The dispatcher's exec-default fall-through covers other
|
|
1843
|
+
// providers; reviewers/handoffs leave codexTransport unset.
|
|
1844
|
+
// Phase 6e — per-tab override (`wf.config.codexTransport`) takes precedence
|
|
1845
|
+
// over the cascade. The CONFIG-tab toggle writes to that field via
|
|
1846
|
+
// update_primary_config so the operator's choice doesn't depend on a
|
|
1847
|
+
// hand-edited settings.json.
|
|
1848
|
+
const cascade = await readSettings(cwd, { includeProject }).catch(() => null);
|
|
1849
|
+
// turnSettings.ts — which value wins for each per-turn setting (tab
|
|
1850
|
+
// choice, settings files, default; Native-only switches off elsewhere).
|
|
1851
|
+
const { codexTransport, ultracode, claudeTransport, claudeNativeCompact, claudeNativeForceInterleavedThinkingBeta, claudeNativeThinkingDisplay, nativeSubagents, efficiencyToolFilter, efficiencyFactForce, efficiencyConfigProtection, efficiencySandbox, reviewSafeMode, outputStyle, goal, ollamaParams, } = resolveTurnSettings({ provider: wf.primary.provider, config: wf.config, cascade, isolatedMember, primitive });
|
|
1852
|
+
// In-turn compaction follows the tab's or cluster's auto-compaction policy
|
|
1853
|
+
// (the plan-review step, a Chat-style request, leaves it off below).
|
|
1854
|
+
const inTurnClusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
1855
|
+
const claudeNativeInTurnCompactPercent = wf.primary.provider === 'claude'
|
|
1856
|
+
? resolveNativeInTurnCompactPercent({
|
|
1857
|
+
native: claudeTransport === 'native',
|
|
1858
|
+
chat: isChatWorkflow(wf.config),
|
|
1859
|
+
claudeNativeCompact,
|
|
1860
|
+
worker: wf.config.autoCompaction ?? undefined,
|
|
1861
|
+
cluster: inTurnClusterId ? clusterStore.getAutoCompaction(inTurnClusterId) : undefined,
|
|
1862
|
+
})
|
|
1863
|
+
: undefined;
|
|
1864
|
+
const providerAccount = wf.primary.provider === 'codex'
|
|
1865
|
+
? await resolveProviderAccount('codex', wf.config.providerAccountRef, cwd).catch(() => null)
|
|
1866
|
+
: null;
|
|
1867
|
+
if (providerAccount?.profile.id && wf.config.providerAccountRef !== providerAccount.profile.id) {
|
|
1868
|
+
wf.config.providerAccountRef = providerAccount.profile.id;
|
|
1869
|
+
}
|
|
1870
|
+
let activeTurnObservation;
|
|
1871
|
+
try {
|
|
1872
|
+
while (true) {
|
|
1873
|
+
primaryTurn.clusterDispatch = undefined;
|
|
1874
|
+
const pickedSkillsBlock = await resolvePickedSkillsBlock(promptPickedSkills);
|
|
1875
|
+
console.log(`[arco] [${workflowId.slice(0, 8)}] user_message received; starting primary turn (${wf.primary.provider}:${wf.primary.model}, resume=${wf.primarySessionId?.slice(0, 8) || 'none'})`);
|
|
1876
|
+
// Peer mailbox: don't auto-drain pre-turn. Just count what's pending and
|
|
1877
|
+
// surface a short notice so the worker knows it has peer mail and reads
|
|
1878
|
+
// it via peer_read. Keeps peer messages as a normal tool-flow primitive
|
|
1879
|
+
// instead of getting silently shoved into the system prompt where the
|
|
1880
|
+
// model conflates "system context" with "current peer mail."
|
|
1881
|
+
// peer_message_received events now fire on peer_read call (where they
|
|
1882
|
+
// belong) rather than pre-turn.
|
|
1883
|
+
//
|
|
1884
|
+
// Phrase the notice as an instruction to read peer mail so the model
|
|
1885
|
+
// invokes the tool rather than echoing a tool-call example.
|
|
1886
|
+
// the notice text now varies by the cluster's efficiency
|
|
1887
|
+
// level (clusterEfficiency.buildPeerMailboxNotice). At balanced/lean the
|
|
1888
|
+
// doctrine tells members not to re-review unless signalled, so the notice
|
|
1889
|
+
// must NOT also shout "re-engage on every inbound" — that contradiction
|
|
1890
|
+
// is exactly the over-review loop this feature targets. The level lookup
|
|
1891
|
+
// is a synchronous in-memory read, so resolving the clusterId here
|
|
1892
|
+
// (ahead of the turn-start resolution below) is cheap. 'thorough' yields
|
|
1893
|
+
// the byte-identical historical notice.
|
|
1894
|
+
let peerMessagesPrologue;
|
|
1895
|
+
if (firstIteration) {
|
|
1896
|
+
const pendingDepth = await clusterMailbox.depthFor(workflowId).catch(() => 0);
|
|
1897
|
+
if (pendingDepth > 0) {
|
|
1898
|
+
const noticeClusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
1899
|
+
const noticeLevel = noticeClusterId
|
|
1900
|
+
? clusterStore.getEfficiencyLevel(noticeClusterId)
|
|
1901
|
+
: 'thorough';
|
|
1902
|
+
const noticeAccess = noticeClusterId
|
|
1903
|
+
? clusterStore.getMemberAccessMode(noticeClusterId, workflowId)
|
|
1904
|
+
: 'standard';
|
|
1905
|
+
peerMessagesPrologue = noticeAccess === 'standard'
|
|
1906
|
+
? clusterEfficiency.buildPeerMailboxNotice(noticeLevel, pendingDepth, noticeClusterId ? clusterStore.getMemberRole(noticeClusterId, workflowId) : undefined)
|
|
1907
|
+
: `You have ${pendingDepth} pending peer message${pendingDepth === 1 ? '' : 's'}. Read them with peer_read; no other cluster context is available.`;
|
|
1908
|
+
}
|
|
1905
1909
|
}
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1910
|
+
// First turn echoes the operator's fresh prompt into events.jsonl.
|
|
1911
|
+
// Drain turns don't re-echo — each queued interjection was already
|
|
1912
|
+
// echoed at enqueue-time, so the transcript renders the individual
|
|
1913
|
+
// interjections rather than the joined follow-up prompt.
|
|
1914
|
+
if (firstIteration) {
|
|
1915
|
+
// An idle drain's items were echoed individually at enqueue time.
|
|
1916
|
+
if (!fromQueue)
|
|
1917
|
+
send(ws, {
|
|
1918
|
+
type: 'user_message_echo',
|
|
1919
|
+
workflowId,
|
|
1920
|
+
...(opts?.automaticKind ? { automaticKind: opts.automaticKind } : {}),
|
|
1921
|
+
content: prompt,
|
|
1922
|
+
attachments: promptAttachments,
|
|
1923
|
+
clientMessageId: promptClientMessageId,
|
|
1924
|
+
deliveryTracked: true,
|
|
1925
|
+
timestamp: Date.now(),
|
|
1926
|
+
...(trackOllama ? { ollamaReplayInput: true } : {}),
|
|
1927
|
+
});
|
|
1928
|
+
if (!fromQueue)
|
|
1929
|
+
activeInputClientIds = promptClientMessageId ? [promptClientMessageId] : [];
|
|
1930
|
+
if (!fromQueue && trackOllama)
|
|
1931
|
+
activeOllamaInputSeqs = [currentWorkflowSeq(cwd, workflowId)];
|
|
1932
|
+
if (chatMode && !incognito) {
|
|
1933
|
+
// Keep the global Past Chats list useful without rescanning a growing
|
|
1934
|
+
// events.jsonl for every creator render.
|
|
1935
|
+
const preview = prompt.replace(/\s+/g, ' ').trim().slice(0, 80);
|
|
1936
|
+
await updateMeta(cwd, workflowId, (meta) => {
|
|
1937
|
+
meta.lastActiveAt = Date.now();
|
|
1938
|
+
meta.lastUserPreview = preview;
|
|
1939
|
+
}).catch((err) => {
|
|
1940
|
+
console.warn(`[arco] [${workflowId.slice(0, 8)}] Chat activity meta write failed:`, err);
|
|
1941
|
+
});
|
|
1935
1942
|
}
|
|
1936
|
-
const rendered = (wf.config.voiceOperator ? renderComputerHistory(replayEvents) : renderTranscript(replayEvents, { preserveThinking: !chatMode })).trim();
|
|
1937
|
-
if (rendered)
|
|
1938
|
-
primaryAppendSystemPrompt = rendered;
|
|
1939
1943
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1944
|
+
// Lazy-create the bg-jobs tracker on first turn — most tabs never
|
|
1945
|
+
// spawn long-running children, so the /proc poller only starts when
|
|
1946
|
+
// a Bash(run_in_background) hint or a fresh descendant actually
|
|
1947
|
+
// appears. Tracker is persistent across turns (and across handoffs)
|
|
1948
|
+
// so a download started in turn N stays visible in turn N+3.
|
|
1949
|
+
if (!chatMode && !wf.bgTracker) {
|
|
1950
|
+
wf.bgTracker = new PrimaryBackgroundTracker({
|
|
1951
|
+
workflowId,
|
|
1952
|
+
broadcast: (msg) => broadcastTransient(workflowId, msg),
|
|
1953
|
+
});
|
|
1942
1954
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
//
|
|
1946
|
-
//
|
|
1947
|
-
//
|
|
1948
|
-
// transcript
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
//
|
|
1952
|
-
//
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1955
|
+
// Plan header injection. When a plan is attached, prepend a brief
|
|
1956
|
+
// "active plan" reminder to the prompt before forwarding to the
|
|
1957
|
+
// provider — the operator's echo'd transcript stays clean. If the
|
|
1958
|
+
// plan body was edited since the last turn that injected it, also
|
|
1959
|
+
// include the full body once so the agent picks up the change. The
|
|
1960
|
+
// operator's transcript is unaffected (echo already sent above).
|
|
1961
|
+
const planPrefix = projectContextEnabled ? await buildPlanPrefix(cwd, wf, workflowId) : '';
|
|
1962
|
+
const promptWithRefs = promptExpandedContext ? prompt + promptExpandedContext : prompt;
|
|
1963
|
+
// DD8 — inline the picks owned by this prompt, after explicit refs.
|
|
1964
|
+
// Model-facing only; each queued prompt carries its own picks.
|
|
1965
|
+
const promptWithSkills = pickedSkillsBlock
|
|
1966
|
+
? `${promptWithRefs}\n\n${pickedSkillsBlock}`
|
|
1967
|
+
: promptWithRefs;
|
|
1968
|
+
let promptWithPlan = planPrefix ? planPrefix + promptWithSkills : promptWithSkills;
|
|
1969
|
+
if (firstIteration && primitive === 'plan-review' && wf.primary.provider === 'cursor') {
|
|
1970
|
+
const prior = renderTranscript(await replayWorkflowEvents(cwd, workflowId, 0)).slice(-48_000);
|
|
1971
|
+
if (prior.trim())
|
|
1972
|
+
promptWithPlan = `Recent conversation (may be truncated):\n${prior}\n\n${promptWithPlan}`;
|
|
1973
|
+
}
|
|
1974
|
+
// Ollama has no native session resume — every spawn is a fresh HTTP
|
|
1975
|
+
// request. To give the model memory across turns we replay the
|
|
1976
|
+
// workflow's events.jsonl into the same USER:/AGENT: transcript shape
|
|
1977
|
+
// the fresh-summarizer Handoff produces, then hand it to the provider
|
|
1978
|
+
// as appendSystemPrompt. The provider parses it back into structured
|
|
1979
|
+
// /api/chat messages so the prefix bytes stay stable across turns
|
|
1980
|
+
// and Ollama's prefix cache hits.
|
|
1960
1981
|
//
|
|
1961
|
-
//
|
|
1962
|
-
//
|
|
1963
|
-
//
|
|
1964
|
-
//
|
|
1965
|
-
//
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1982
|
+
// The system prompt counters two observed Qwen-MoE behaviors against
|
|
1983
|
+
// a code chat: (1) verbose tabular formatting on every reply, (2)
|
|
1984
|
+
// hallucinating about files when no tools are wired (§5.4 still
|
|
1985
|
+
// pending). Static text — no timestamps or random ids — so the prefix
|
|
1986
|
+
// cache hits cleanly across turns.
|
|
1987
|
+
let ollamaReplay;
|
|
1988
|
+
const retainLocalFiles = ['ollama', 'llamacpp', 'lmstudio', 'strata', 'deepseek'].includes(wf.primary.provider);
|
|
1989
|
+
let priorFiles = retainLocalFiles || chatMode ? [] : undefined;
|
|
1990
|
+
let primaryAppendSystemPrompt;
|
|
1991
|
+
let primarySystemPrompt;
|
|
1992
|
+
// The current user echo was just recorded above. Stateless providers
|
|
1993
|
+
// receive only the completed turns before it; the current prompt rides
|
|
1994
|
+
// the normal provider input exactly once.
|
|
1995
|
+
const priorIncognitoEvents = incognito
|
|
1996
|
+
? (() => {
|
|
1997
|
+
const events = wf.incognitoEvents ?? [];
|
|
1998
|
+
return events[events.length - 1]?.type === 'user_message_echo'
|
|
1999
|
+
? events.slice(0, -1)
|
|
2000
|
+
: [...events];
|
|
2001
|
+
})()
|
|
2002
|
+
: null;
|
|
2003
|
+
// Phase 1 — Arco-managed skills. Scan project + global skill
|
|
2004
|
+
// directories on every turn (cheap — small dir count, single SKILL.md
|
|
2005
|
+
// read each), build the XML manifest, and route it to wherever the
|
|
2006
|
+
// provider's system prompt actually lives. Manifest holds only name +
|
|
2007
|
+
// description; the agent reads the full SKILL.md via its Read tool.
|
|
2008
|
+
// Re-scanning per turn means edits / deletes via the UI take effect on
|
|
2009
|
+
// the next turn without restarting anything.
|
|
2010
|
+
let primarySkillsManifest = '';
|
|
2011
|
+
if (projectContextEnabled)
|
|
2012
|
+
try {
|
|
2013
|
+
const catalog = await listSkills(cwd, { includeProject });
|
|
2014
|
+
// A pinned body is already present in full; omit its progressive-
|
|
2015
|
+
// disclosure metadata to avoid duplicate/conflicting instructions.
|
|
2016
|
+
const pinnedKeys = new Set((wf.config.pinnedSkills ?? []).map((s) => `${s.scope}:${s.slug}`));
|
|
2017
|
+
primarySkillsManifest = buildSkillsManifest({
|
|
2018
|
+
project: catalog.project.filter((s) => !pinnedKeys.has(`project:${s.slug}`)),
|
|
2019
|
+
global: catalog.global.filter((s) => !pinnedKeys.has(`global:${s.slug}`)),
|
|
2020
|
+
builtin: catalog.builtin,
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
catch (err) {
|
|
2024
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] skills scan failed:`, err);
|
|
2025
|
+
}
|
|
2026
|
+
if (wf.primary.provider === 'ollama') {
|
|
2027
|
+
primarySystemPrompt = chatMode ? chatSystemPrompt(chatWeb) : OLLAMA_PRIMARY_SYSTEM_PROMPT;
|
|
2028
|
+
try {
|
|
2029
|
+
const events = priorIncognitoEvents ?? (wf.config.voiceOperator
|
|
2030
|
+
? await computerReplayEvents(cwd, workflowId, wf.config.computerContext?.lastResetAt, wf.config.computerContext?.lastResetSeq)
|
|
2031
|
+
: await replayWorkflowEvents(cwd, workflowId, 0));
|
|
2032
|
+
// preserveThinking: Qwen-family models (3.6, 3-VL) implement
|
|
2033
|
+
// Thinking Preservation — prior turn reasoning fed back as
|
|
2034
|
+
// context improves multi-turn coherence. Cheap (just routes
|
|
2035
|
+
// primary_thinking events into a <think> block on each AGENT
|
|
2036
|
+
// entry); UI/handoff paths still call renderTranscript without
|
|
2037
|
+
// the flag and stay reasoning-clean.
|
|
2038
|
+
// Hidden reasoning is useful continuity for project Agent work, but
|
|
2039
|
+
// Chat capabilities can change between turns via the WEB toggle. A
|
|
2040
|
+
// saved offline turn can contain the old system restriction verbatim;
|
|
2041
|
+
// replaying that reasoning after web is armed makes local models obey
|
|
2042
|
+
// the stale state instead of the current system block + tools[].
|
|
2043
|
+
const clusterForReplay = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
2044
|
+
const savedOllamaPolicy = cascade?.ollama?.compaction?.enabled !== undefined || cascade?.ollama?.compaction?.threshold !== undefined;
|
|
2045
|
+
const policy = trackOllama ? resolveProviderAutoCompaction(wf.config.autoCompaction, clusterForReplay ? clusterStore.getAutoCompaction(clusterForReplay) : undefined, 'ollama', '', false, savedOllamaPolicy) : undefined;
|
|
2046
|
+
let replayEvents = events;
|
|
2047
|
+
if (policy) {
|
|
2048
|
+
const policyKey = JSON.stringify(policy);
|
|
2049
|
+
ollamaReplay = { events, activeInputSeqs: [...activeOllamaInputSeqs], policy, stillOwner: () => {
|
|
2050
|
+
const cluster = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
2051
|
+
const current = resolveProviderAutoCompaction(wf.config.autoCompaction, cluster ? clusterStore.getAutoCompaction(cluster) : undefined, 'ollama', '', false, savedOllamaPolicy);
|
|
2052
|
+
return workflows.get(workflowId) === wf && ownsBusy(wf, busyToken) && wf.primary.provider === 'ollama' && JSON.stringify(current) === policyKey;
|
|
2053
|
+
} };
|
|
2054
|
+
replayEvents = projectOllamaHistory(events, workflowId, activeOllamaInputSeqs, true).events;
|
|
2055
|
+
}
|
|
2056
|
+
priorFiles = projectLocalFileReferences(events, cwd, chatMode);
|
|
2057
|
+
const rendered = (wf.config.voiceOperator ? renderComputerHistory(replayEvents) : renderTranscript(replayEvents, { preserveThinking: !chatMode, separateFileContext: !chatMode, attachmentOnly: chatMode })).trim();
|
|
2058
|
+
if (rendered)
|
|
2059
|
+
primaryAppendSystemPrompt = rendered;
|
|
2060
|
+
}
|
|
2061
|
+
catch (err) {
|
|
2062
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] ollama transcript build failed:`, err);
|
|
1976
2063
|
}
|
|
1977
|
-
if (rendered)
|
|
1978
|
-
parts.push(rendered);
|
|
1979
|
-
const combined = parts.join('\n\n').trim();
|
|
1980
|
-
if (combined)
|
|
1981
|
-
primaryAppendSystemPrompt = combined;
|
|
1982
|
-
}
|
|
1983
|
-
catch (err) {
|
|
1984
|
-
console.error(`[arco] [${workflowId.slice(0, 8)}] ${wf.primary.provider} transcript build failed:`, err);
|
|
1985
2064
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2065
|
+
else if (wf.primary.provider === 'llamacpp' || wf.primary.provider === 'lmstudio' || (wf.primary.provider === 'strata' || wf.primary.provider === 'deepseek') || (chatMode && wf.primary.provider === 'cursor')) {
|
|
2066
|
+
// M13 — LM Studio reuses llama.cpp's transcript-rebuild path verbatim:
|
|
2067
|
+
// both are OpenAI-compat local runtimes with no native session, so the
|
|
2068
|
+
// deterministic prior-turn summary + reasoning-clean rendered
|
|
2069
|
+
// transcript apply identically. (LM Studio is remote, but the
|
|
2070
|
+
// context-loss-across-turns problem is the same.)
|
|
2071
|
+
primarySystemPrompt = chatMode ? chatSystemPrompt(chatWeb) : LLAMACPP_PRIMARY_SYSTEM_PROMPT;
|
|
2072
|
+
// llama.cpp: same prefix-cache benefits as ollama but with an
|
|
2073
|
+
// additional structured prior-turn summary prepended. Local thinking
|
|
2074
|
+
// models lose track across turns because renderTranscript drops all
|
|
2075
|
+
// tool history (only USER:/AGENT: text survives) — the model on
|
|
2076
|
+
// turn N has no idea which files it read or wrote on turn N-1.
|
|
2077
|
+
// summarizePriorTurns walks events.jsonl and produces a deterministic
|
|
2078
|
+
// per-turn breakdown (tools used, files touched, bash run, final
|
|
2079
|
+
// reply text). It's stuffed into a faux AGENT block at the head of
|
|
2080
|
+
// the transcript so the parser routes it into one assistant message.
|
|
2081
|
+
//
|
|
2082
|
+
// We deliberately do NOT preserveThinking here: re-feeding Qwen3.6
|
|
2083
|
+
// its own reasoning across turns has the opposite of the ollama
|
|
2084
|
+
// benefit because llama-server already exposes reasoning_content
|
|
2085
|
+
// separately and the extra <think> blocks just inflate the prompt
|
|
2086
|
+
// and trigger more verbose monologue on the next turn.
|
|
2087
|
+
try {
|
|
2088
|
+
const events = priorIncognitoEvents ?? (wf.config.voiceOperator
|
|
2089
|
+
? await computerReplayEvents(cwd, workflowId, wf.config.computerContext?.lastResetAt, wf.config.computerContext?.lastResetSeq)
|
|
2090
|
+
: await replayWorkflowEvents(cwd, workflowId, 0));
|
|
2091
|
+
if (retainLocalFiles || chatMode)
|
|
2092
|
+
priorFiles = projectLocalFileReferences(events, cwd, chatMode);
|
|
2093
|
+
const summary = chatMode ? '' : summarizePriorTurns(events);
|
|
2094
|
+
const rendered = (wf.config.voiceOperator ? renderComputerHistory(events) : renderTranscript(events, { preserveThinking: false, separateFileContext: !chatMode && (wf.primary.provider === 'llamacpp' || wf.primary.provider === 'lmstudio'), attachmentOnly: chatMode })).trim();
|
|
2095
|
+
const parts = [];
|
|
2096
|
+
if (summary) {
|
|
2097
|
+
parts.push(`USER: [Workflow context]`);
|
|
2098
|
+
parts.push(`AGENT: ${summary}`);
|
|
2099
|
+
}
|
|
2100
|
+
if (rendered)
|
|
2101
|
+
parts.push(rendered);
|
|
2102
|
+
const combined = parts.join('\n\n').trim();
|
|
2103
|
+
if (combined)
|
|
2104
|
+
primaryAppendSystemPrompt = combined;
|
|
2105
|
+
}
|
|
2106
|
+
catch (err) {
|
|
2107
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] ${wf.primary.provider} transcript build failed:`, err);
|
|
2108
|
+
}
|
|
2026
2109
|
}
|
|
2027
|
-
else
|
|
2028
|
-
|
|
2110
|
+
else if (incognito
|
|
2111
|
+
&& ((wf.primary.provider === 'claude' && claudeTransport !== 'native')
|
|
2112
|
+
|| (wf.primary.provider === 'codex' && codexTransport !== 'appserver'))) {
|
|
2113
|
+
// Incognito CLI turns deliberately have no resumable provider session.
|
|
2114
|
+
// Replay the memory-only completed transcript into each one-shot call.
|
|
2115
|
+
const rendered = renderTranscript(priorIncognitoEvents ?? []).trim();
|
|
2116
|
+
if (rendered)
|
|
2117
|
+
primaryAppendSystemPrompt = `Conversation so far:\n\n${rendered}`;
|
|
2029
2118
|
}
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
: claudeMd;
|
|
2119
|
+
if (chatMode && (incognito || !wf.primarySessionId) && (wf.primary.provider === 'codex' || (wf.primary.provider === 'claude' && claudeTransport !== 'native'))) {
|
|
2120
|
+
try {
|
|
2121
|
+
const events = priorIncognitoEvents ?? await replayWorkflowEvents(cwd, workflowId, 0);
|
|
2122
|
+
priorFiles = projectLocalFileReferences(events, cwd, true);
|
|
2123
|
+
}
|
|
2124
|
+
catch (err) {
|
|
2125
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] chat attachment replay failed:`, err);
|
|
2038
2126
|
}
|
|
2039
2127
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2128
|
+
// Local HTTP transports receive stable tool instructions through the
|
|
2129
|
+
// provider system-prompt field; Claude and Codex transports fold them
|
|
2130
|
+
// into their string-form prompt or native request blocks.
|
|
2131
|
+
let claudeMd = null;
|
|
2132
|
+
if (projectContextEnabled && (wf.primary.provider === 'claude') && cwd) {
|
|
2133
|
+
try {
|
|
2134
|
+
claudeMd = (await discoverClaudeMdFiles(cwd, { includeProject })) || null;
|
|
2135
|
+
}
|
|
2136
|
+
catch (err) {
|
|
2137
|
+
console.warn(`[arco] [${workflowId.slice(0, 8)}] CLAUDE.md discovery failed:`, err);
|
|
2138
|
+
}
|
|
2042
2139
|
}
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
}
|
|
2140
|
+
// docs/ARCHITECTURE.md - the operator-curated knowledge base, as a
|
|
2141
|
+
// BOUNDED block. Provider-agnostic, only the always-include articles.
|
|
2142
|
+
// buildKnowledgeBlock hard-caps the combined body at
|
|
2143
|
+
// KNOWLEDGE_INJECT_BUDGET and appends a truncation notice when the set
|
|
2144
|
+
// overflows — the KB can NEVER silently bloat the turn. Emitted byte
|
|
2145
|
+
// counts land in events.jsonl (system_notice) for the four-question
|
|
2146
|
+
// test's context visibility. FENCE: this READS operator-curated
|
|
2147
|
+
// articles; nothing here writes the KB.
|
|
2148
|
+
let knowledge = null;
|
|
2149
|
+
if (projectContextEnabled && cwd) {
|
|
2150
|
+
try {
|
|
2151
|
+
const kb = await buildKnowledgeBlock(cwd);
|
|
2152
|
+
if (kb.text) {
|
|
2153
|
+
knowledge = kb.text;
|
|
2154
|
+
if (firstIteration) {
|
|
2155
|
+
const truncNote = kb.truncated ? ` (truncated — exceeds injection budget)` : '';
|
|
2156
|
+
send(ws, {
|
|
2157
|
+
type: 'system_notice',
|
|
2158
|
+
workflowId,
|
|
2159
|
+
content: `Knowledge base: ${kb.included}/${kb.total} always-include article${kb.total === 1 ? '' : 's'} folded into context (${kb.bytes} bytes)${truncNote}.`,
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2065
2162
|
}
|
|
2066
2163
|
}
|
|
2164
|
+
catch (err) {
|
|
2165
|
+
console.warn(`[arco] [${workflowId.slice(0, 8)}] knowledge-base injection failed:`, err);
|
|
2166
|
+
}
|
|
2067
2167
|
}
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
if (nativeClaudeTurn)
|
|
2099
|
-
turnNoticeParts.push(peerMessagesPrologue);
|
|
2100
|
-
else
|
|
2101
|
-
finalAppend = finalAppend ? `${peerMessagesPrologue}\n\n${finalAppend}` : peerMessagesPrologue;
|
|
2102
|
-
}
|
|
2103
|
-
// docs/PROTOCOL_CLUSTER.md - resolve the workflow's clusterId
|
|
2104
|
-
// (if any) at turn start. Threaded into the worker's WorkerConfig so
|
|
2105
|
-
// peer tools register and dispatch only when the membership is live.
|
|
2106
|
-
// Per plan §6.2 reversibility: once the cluster is deleted via REST,
|
|
2107
|
-
// the next turn's lookup returns undefined and the tools disappear
|
|
2108
|
-
// from the worker's tool list.
|
|
2109
|
-
const turnClusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
2110
|
-
// Phase 2.6 — resolve the cluster's shared plan body + this member's
|
|
2111
|
-
// role hint at turn start. Both ride into WorkerConfig so the Native
|
|
2112
|
-
// worker's buildSystemBlocks() can inject them as forced system blocks
|
|
2113
|
-
// (after FORCED_FIRST_BLOCK, before operator prompts). Editing the
|
|
2114
|
-
// plan mid-turn never tears the running turn down — only the NEXT
|
|
2115
|
-
// turn's resolution picks up the new body.
|
|
2116
|
-
let turnClusterPlan;
|
|
2117
|
-
let turnClusterRole;
|
|
2118
|
-
// per-cluster efficiency doctrine + level. The doctrine
|
|
2119
|
-
// (canned restraint text for the level + optional operator addendum)
|
|
2120
|
-
// injects alongside plan/role; the level itself also drives the
|
|
2121
|
-
// peer-mailbox notice variant below. Resolved at turn start so an
|
|
2122
|
-
// operator level-change lands on the NEXT turn (in-flight turns are
|
|
2123
|
-
// untouched). Legacy omitted styles remain Thorough; guards resolve
|
|
2124
|
-
// independently and are included even for mailbox-only members.
|
|
2125
|
-
let turnClusterEfficiencyDoctrine = turnClusterId ? buildMessageGuardPolicy(clusterStore.getMessageGuard(turnClusterId)) : undefined;
|
|
2126
|
-
let turnClusterEfficiencyLevel = 'thorough';
|
|
2127
|
-
let turnClusterTaskBoardAttached = false;
|
|
2128
|
-
// per-cluster progress-tracking doctrine. Built from the
|
|
2129
|
-
// cluster's mode (plan/board/both, default both) gated on whether a plan
|
|
2130
|
-
// body and/or a task board actually exist for this turn. Injected
|
|
2131
|
-
// alongside the efficiency doctrine. Resolved at turn start so an operator
|
|
2132
|
-
// mode-change lands on the NEXT turn (in-flight turns untouched). Undefined
|
|
2133
|
-
// when there is nothing to keep current (e.g. mode 'plan' but no plan).
|
|
2134
|
-
let turnClusterProgressDoctrine;
|
|
2135
|
-
if (turnClusterId && clusterAccessMode === 'standard') {
|
|
2136
|
-
const planRec = await clusterPlanBridge.readClusterPlan(turnClusterId).catch(() => null);
|
|
2137
|
-
turnClusterPlan = planRec?.body;
|
|
2138
|
-
// Plan reference docs ride as one trailing heading line — a heading so
|
|
2139
|
-
// the outline fallback (clusterPlanOutline keeps every heading) can't
|
|
2140
|
-
// drop it, and slugs only so it stays small. Members read a ref with
|
|
2141
|
-
// plan_ref_read or plain file tools.
|
|
2142
|
-
const refsCwd = wf.config.workingDirectory;
|
|
2143
|
-
if (planRec && turnClusterPlan && refsCwd) {
|
|
2144
|
-
const refs = await listPlanRefs(refsCwd, planRec.planId).catch(() => []);
|
|
2145
|
-
if (refs.length > 0) {
|
|
2146
|
-
turnClusterPlan = `${turnClusterPlan.trimEnd()}\n\n#### Plan reference docs (planId ${planRec.planId}) — ${refsDoctrine(planRec.planId, refs.map((r) => r.slug), 24)}\n`;
|
|
2168
|
+
// turnPrompt.ts — skills, the Chat or Computer preamble, CLAUDE.md and
|
|
2169
|
+
// the knowledge base, in the order the model sees them.
|
|
2170
|
+
let { systemPrompt: finalSystemPrompt, appendSystemPrompt: finalAppend } = composeBasePrompts({
|
|
2171
|
+
provider: wf.primary.provider,
|
|
2172
|
+
chatMode,
|
|
2173
|
+
computerChat: wf.config.voiceOperator === true,
|
|
2174
|
+
chatWeb,
|
|
2175
|
+
systemPrompt: primarySystemPrompt,
|
|
2176
|
+
appendSystemPrompt: primaryAppendSystemPrompt,
|
|
2177
|
+
pinnedSkills: pinnedSkillsBlock,
|
|
2178
|
+
skillsManifest: primarySkillsManifest,
|
|
2179
|
+
claudeMd,
|
|
2180
|
+
knowledge,
|
|
2181
|
+
});
|
|
2182
|
+
// Operator-initiated plan-mode entry. Resolved per turn from the
|
|
2183
|
+
// pending flag the `enter_plan_mode_request` handler set. Only Claude
|
|
2184
|
+
// Native honours arming; on any other resolved transport the flag is
|
|
2185
|
+
// silently cleared so a stale arm doesn't survive a provider switch.
|
|
2186
|
+
// docs/PROVIDERS.md - per-turn text for Claude Native
|
|
2187
|
+
// rides WorkerConfig.turnNotice (appended to the user message, kept
|
|
2188
|
+
// forever) instead of appendSystemPrompt, which the Native worker now
|
|
2189
|
+
// freezes; a firstIteration-gated fold there flipped the system prompt
|
|
2190
|
+
// between consecutive requests of an auto-continued turn.
|
|
2191
|
+
const nativeClaudeTurn = wf.primary.provider === 'claude' && claudeTransport === 'native';
|
|
2192
|
+
const turnNoticeParts = [];
|
|
2193
|
+
let armPlanMode = false;
|
|
2194
|
+
if (wf.pendingPlanModeEntry) {
|
|
2195
|
+
if (nativeClaudeTurn && firstIteration) {
|
|
2196
|
+
armPlanMode = true;
|
|
2197
|
+
turnNoticeParts.push('Operator has armed plan mode for this turn. Write/Edit tools are disabled until you call ExitPlanMode. Begin by calling EnterPlanMode with a plan body for what the operator just asked.');
|
|
2147
2198
|
}
|
|
2199
|
+
wf.pendingPlanModeEntry = false;
|
|
2148
2200
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
clusterRole: turnClusterRole,
|
|
2161
|
-
clusterEfficiencyDoctrine: turnClusterEfficiencyDoctrine,
|
|
2162
|
-
clusterProgressDoctrine: turnClusterProgressDoctrine,
|
|
2163
|
-
});
|
|
2201
|
+
// docs/PROTOCOL_CLUSTER.md - fold the drained mailbox prologue
|
|
2202
|
+
// into the front of appendSystemPrompt so a CLI / Codex worker renders
|
|
2203
|
+
// it as system-level context before any operator-supplied
|
|
2204
|
+
// appendSystemPrompt content. Only first-iteration (drain ran above only
|
|
2205
|
+
// on firstIteration); follow-up drains skip. Native takes it as a
|
|
2206
|
+
// turnNotice instead (see above).
|
|
2207
|
+
if (peerMessagesPrologue) {
|
|
2208
|
+
if (nativeClaudeTurn)
|
|
2209
|
+
turnNoticeParts.push(peerMessagesPrologue);
|
|
2210
|
+
else
|
|
2211
|
+
finalAppend = finalAppend ? `${peerMessagesPrologue}\n\n${finalAppend}` : peerMessagesPrologue;
|
|
2164
2212
|
}
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2213
|
+
// docs/PROTOCOL_CLUSTER.md - resolve the workflow's clusterId
|
|
2214
|
+
// (if any) at turn start. Threaded into the worker's WorkerConfig so
|
|
2215
|
+
// peer tools register and dispatch only when the membership is live.
|
|
2216
|
+
// Per plan §6.2 reversibility: once the cluster is deleted via REST,
|
|
2217
|
+
// the next turn's lookup returns undefined and the tools disappear
|
|
2218
|
+
// from the worker's tool list.
|
|
2219
|
+
const turnClusterId = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
2220
|
+
primaryTurn.clusterDispatch = { clusterId: turnClusterId };
|
|
2221
|
+
// Phase 2.6 — resolve the cluster's shared plan body + this member's
|
|
2222
|
+
// role hint at turn start. Both ride into WorkerConfig so the Native
|
|
2223
|
+
// worker's buildSystemBlocks() can inject them as forced system blocks
|
|
2224
|
+
// (after FORCED_FIRST_BLOCK, before operator prompts). Editing the
|
|
2225
|
+
// plan mid-turn never tears the running turn down — only the NEXT
|
|
2226
|
+
// turn's resolution picks up the new body.
|
|
2227
|
+
let turnClusterPlan;
|
|
2228
|
+
let turnClusterRole;
|
|
2229
|
+
// per-cluster efficiency doctrine + level. The doctrine
|
|
2230
|
+
// (canned restraint text for the level + optional operator addendum)
|
|
2231
|
+
// injects alongside plan/role; the level itself also drives the
|
|
2232
|
+
// peer-mailbox notice variant below. Resolved at turn start so an
|
|
2233
|
+
// operator level-change lands on the NEXT turn (in-flight turns are
|
|
2234
|
+
// untouched). Legacy omitted styles remain Thorough; guards resolve
|
|
2235
|
+
// independently and are included even for mailbox-only members.
|
|
2236
|
+
let turnClusterEfficiencyDoctrine = turnClusterId ? buildMessageGuardPolicy(clusterStore.getMessageGuard(turnClusterId)) : undefined;
|
|
2237
|
+
let turnClusterEfficiencyLevel = 'thorough';
|
|
2238
|
+
let turnClusterTaskBoardAttached = false;
|
|
2239
|
+
// per-cluster progress-tracking doctrine. Built from the
|
|
2240
|
+
// cluster's mode (plan/board/both, default both) gated on whether a plan
|
|
2241
|
+
// body and/or a task board actually exist for this turn. Injected
|
|
2242
|
+
// alongside the efficiency doctrine. Resolved at turn start so an operator
|
|
2243
|
+
// mode-change lands on the NEXT turn (in-flight turns untouched). Undefined
|
|
2244
|
+
// when there is nothing to keep current (e.g. mode 'plan' but no plan).
|
|
2245
|
+
let turnClusterProgressDoctrine;
|
|
2246
|
+
if (turnClusterId && clusterAccessMode === 'standard') {
|
|
2247
|
+
const planRec = await clusterPlanBridge.readClusterPlan(turnClusterId).catch(() => null);
|
|
2248
|
+
turnClusterPlan = planRec?.body;
|
|
2249
|
+
// Plan reference docs ride as one trailing heading line — a heading so
|
|
2250
|
+
// the outline fallback (clusterPlanOutline keeps every heading) can't
|
|
2251
|
+
// drop it, and slugs only so it stays small. Members read a ref with
|
|
2252
|
+
// plan_ref_read or plain file tools.
|
|
2253
|
+
const refsCwd = wf.config.workingDirectory;
|
|
2254
|
+
if (planRec && turnClusterPlan && refsCwd) {
|
|
2255
|
+
const refs = await listPlanRefs(refsCwd, planRec.planId).catch(() => []);
|
|
2256
|
+
if (refs.length > 0) {
|
|
2257
|
+
turnClusterPlan = `${turnClusterPlan.trimEnd()}\n\n#### Plan reference docs (planId ${planRec.planId}) — ${refsDoctrine(planRec.planId, refs.map((r) => r.slug), 24)}\n`;
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
turnClusterRole = clusterStore.getMemberRole(turnClusterId, workflowId);
|
|
2261
|
+
turnClusterTaskBoardAttached = clusterStore.isTaskBoardAttached(turnClusterId);
|
|
2262
|
+
turnClusterEfficiencyLevel = clusterStore.getEfficiencyLevel(turnClusterId);
|
|
2263
|
+
turnClusterEfficiencyDoctrine = clusterEfficiency.buildDoctrine(turnClusterEfficiencyLevel, clusterStore.getEfficiencyAddendum(turnClusterId), turnClusterRole, clusterStore.getMessageGuard(turnClusterId));
|
|
2264
|
+
turnClusterProgressDoctrine = joinClusterDoctrines(buildClusterDirectorDoctrine(turnClusterRole), buildProgressDoctrine(clusterStore.getProgressTracking(turnClusterId), !!turnClusterPlan && turnClusterPlan.trim().length > 0, turnClusterTaskBoardAttached));
|
|
2169
2265
|
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
// from `WorkerConfig.clusterId` (Phase 4 §13 decision: Codex CLI has
|
|
2186
|
-
// no `--mcp-config <path>` flag, but `-c` overrides leave the
|
|
2187
|
-
// operator's `~/.codex/config.toml` untouched and avoid TOML merge).
|
|
2188
|
-
//
|
|
2189
|
-
// CLI transports retain the 16 KB cap: argv paths E2BIG above roughly
|
|
2190
|
-
// 128 KB and the tmpfile fallback handles arbitrary sizes, while the
|
|
2191
|
-
// explicit bound surfaces unreasonable growth early. Codex app-server
|
|
2192
|
-
// uses 48 KB because it rides JSON-RPC stdin and needs room for the
|
|
2193
|
-
// maximum 32 KB plan plus small blocks. The PLAN is the only block that
|
|
2194
|
-
// shrinks to fit
|
|
2195
|
-
// (composeClusterAppend) — the small blocks are load-bearing and
|
|
2196
|
-
// survive verbatim.
|
|
2197
|
-
let turnClusterMcpConfigPath;
|
|
2198
|
-
const needsStringFormCluster = turnClusterId !== undefined &&
|
|
2199
|
-
((wf.primary.provider === 'claude' && claudeTransport === 'cli') ||
|
|
2200
|
-
wf.primary.provider === 'codex' || wf.primary.provider === 'cursor');
|
|
2201
|
-
if (needsStringFormCluster) {
|
|
2202
|
-
// Small load-bearing blocks first — composeClusterAppend reserves
|
|
2203
|
-
// their bytes (plus whatever already folded into finalAppend, i.e.
|
|
2204
|
-
// the peer-mailbox notice) and truncates the PLAN to the remaining
|
|
2205
|
-
// budget. This prevents a large plan from evicting the notice, role
|
|
2206
|
-
// and code-mode guidance. See clusterStringFold.ts.
|
|
2207
|
-
const tailBlocks = [];
|
|
2208
|
-
if (clusterAccessMode !== 'standard') {
|
|
2209
|
-
tailBlocks.push(clusterAccessMode === 'isolated'
|
|
2210
|
-
? 'ISOLATED cluster member: the project and cluster coordination state are intentionally hidden. Use only peer_send and peer_read for cluster communication.'
|
|
2211
|
-
: BLIND_CLUSTER_DOCTRINE);
|
|
2266
|
+
if (turnClusterId && (wf.primary.provider === 'ollama' || wf.primary.provider === 'llamacpp' || wf.primary.provider === 'lmstudio' || wf.primary.provider === 'strata' || wf.primary.provider === 'deepseek')) {
|
|
2267
|
+
if (clusterAccessMode === 'standard') {
|
|
2268
|
+
finalSystemPrompt = buildLocalClusterSystemPrompt({
|
|
2269
|
+
base: finalSystemPrompt,
|
|
2270
|
+
clusterPlan: turnClusterPlan,
|
|
2271
|
+
clusterRole: turnClusterRole,
|
|
2272
|
+
clusterEfficiencyDoctrine: turnClusterEfficiencyDoctrine,
|
|
2273
|
+
clusterProgressDoctrine: turnClusterProgressDoctrine,
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
finalSystemPrompt = finalSystemPrompt
|
|
2278
|
+
? `${BLIND_CLUSTER_DOCTRINE}\n\n${turnClusterEfficiencyDoctrine}\n\n${finalSystemPrompt}`
|
|
2279
|
+
: `${BLIND_CLUSTER_DOCTRINE}\n\n${turnClusterEfficiencyDoctrine}`;
|
|
2280
|
+
}
|
|
2212
2281
|
}
|
|
2213
|
-
|
|
2214
|
-
|
|
2282
|
+
// docs/PROTOCOL_CLUSTER.md - non-Native cluster member
|
|
2283
|
+
// wiring. Native dispatches peer_* in-process via peerTools (clusterId
|
|
2284
|
+
// on WorkerConfig is sufficient, and buildSystemBlocks injects plan +
|
|
2285
|
+
// role as forced system blocks). CLI Claude / Codex `exec` / Codex
|
|
2286
|
+
// `appserver` all reach the model via a string-form prompt, so the
|
|
2287
|
+
// plan + role have to fold into `finalAppend` (which becomes
|
|
2288
|
+
// `--append-system-prompt` for Claude CLI and the byte-stable prefix
|
|
2289
|
+
// for both Codex transports). Order (peer prologue → plan → role)
|
|
2290
|
+
// matches Native's buildSystemBlocks ordering.
|
|
2291
|
+
//
|
|
2292
|
+
// For Claude CLI: also write the per-workflow mcp-config.json so the
|
|
2293
|
+
// claude CLI's `--mcp-config <path>` spawns the per-turn MCP stdio
|
|
2294
|
+
// child. For Codex: nothing to write — the codex provider builds
|
|
2295
|
+
// `-c mcp_servers.arco-cluster.*` TOML overrides at spawn time
|
|
2296
|
+
// from `WorkerConfig.clusterId` (Phase 4 §13 decision: Codex CLI has
|
|
2297
|
+
// no `--mcp-config <path>` flag, but `-c` overrides leave the
|
|
2298
|
+
// operator's `~/.codex/config.toml` untouched and avoid TOML merge).
|
|
2299
|
+
//
|
|
2300
|
+
// CLI transports retain the 16 KB cap: argv paths E2BIG above roughly
|
|
2301
|
+
// 128 KB and the tmpfile fallback handles arbitrary sizes, while the
|
|
2302
|
+
// explicit bound surfaces unreasonable growth early. Codex app-server
|
|
2303
|
+
// uses 48 KB because it rides JSON-RPC stdin and needs room for the
|
|
2304
|
+
// maximum 32 KB plan plus small blocks. The PLAN is the only block that
|
|
2305
|
+
// shrinks to fit
|
|
2306
|
+
// (composeClusterAppend) — the small blocks are load-bearing and
|
|
2307
|
+
// survive verbatim.
|
|
2308
|
+
let turnClusterMcpConfigPath;
|
|
2309
|
+
const needsStringFormCluster = turnClusterId !== undefined &&
|
|
2310
|
+
((wf.primary.provider === 'claude' && claudeTransport === 'cli') ||
|
|
2311
|
+
wf.primary.provider === 'codex' || wf.primary.provider === 'cursor');
|
|
2312
|
+
if (needsStringFormCluster) {
|
|
2313
|
+
// Small load-bearing blocks first — composeClusterAppend reserves
|
|
2314
|
+
// their bytes (plus whatever already folded into finalAppend, i.e.
|
|
2315
|
+
// the peer-mailbox notice) and truncates the PLAN to the remaining
|
|
2316
|
+
// budget. This prevents a large plan from evicting the notice, role
|
|
2317
|
+
// and code-mode guidance. See clusterStringFold.ts.
|
|
2318
|
+
const tailBlocks = [];
|
|
2319
|
+
if (clusterAccessMode !== 'standard') {
|
|
2320
|
+
tailBlocks.push(clusterAccessMode === 'isolated'
|
|
2321
|
+
? 'ISOLATED cluster member: the project and cluster coordination state are intentionally hidden. Use only peer_send and peer_read for cluster communication.'
|
|
2322
|
+
: BLIND_CLUSTER_DOCTRINE);
|
|
2323
|
+
}
|
|
2324
|
+
if (turnClusterRole && turnClusterRole.length > 0) {
|
|
2325
|
+
tailBlocks.push(`Your role in this cluster: ${turnClusterRole}`);
|
|
2326
|
+
}
|
|
2327
|
+
// docs/CODEX_GPT56_CLUSTER_INCOMPAT.md — code-mode models run
|
|
2328
|
+
// OpenAI's own multi-agent "code mode" harness, which renames the
|
|
2329
|
+
// arco-cluster MCP tools into the exec code cell's `tools`
|
|
2330
|
+
// namespace (`tools.mcp__arco_cluster__peer_send`) and gives the
|
|
2331
|
+
// harness's native send_message top billing. Without this addendum
|
|
2332
|
+
// a code-mode member cannot find the peer substrate. Detection is
|
|
2333
|
+
// catalog-driven (codex's own models_cache.json `tool_mode` /
|
|
2334
|
+
// `multi_agent_version` — the exact fields that gate the harness);
|
|
2335
|
+
// fail-open on unknown because the addendum is phrased
|
|
2336
|
+
// conditionally and reads as inapplicable to plain
|
|
2337
|
+
if (wf.primary.provider === 'codex'
|
|
2338
|
+
&& codexModelUsesCodeMode(wf.primary.model, providerAccount?.codexHome) !== false) {
|
|
2339
|
+
tailBlocks.push(codexCodeModeClusterAddendum());
|
|
2340
|
+
}
|
|
2341
|
+
if (turnClusterEfficiencyDoctrine && turnClusterEfficiencyDoctrine.length > 0) {
|
|
2342
|
+
tailBlocks.push(turnClusterEfficiencyDoctrine);
|
|
2343
|
+
}
|
|
2344
|
+
if (turnClusterProgressDoctrine && turnClusterProgressDoctrine.length > 0) {
|
|
2345
|
+
tailBlocks.push(turnClusterProgressDoctrine);
|
|
2346
|
+
}
|
|
2347
|
+
const planBlock = turnClusterPlan && turnClusterPlan.length > 0
|
|
2348
|
+
? `--- Shared cluster plan ---\n${turnClusterPlan}`
|
|
2349
|
+
: undefined;
|
|
2350
|
+
// Outline fallback: when the full plan overflows the budget, fold a
|
|
2351
|
+
// deterministic outline (headings + every checkbox line verbatim +
|
|
2352
|
+
// labelled standing-directive sections) instead of a head-slice — the
|
|
2353
|
+
// actionable skeleton survives whole and omitted prose is one
|
|
2354
|
+
// cluster_plan_read call away.
|
|
2355
|
+
const planFallback = turnClusterPlan && turnClusterPlan.length > 0
|
|
2356
|
+
? `--- Shared cluster plan (OUTLINE — prose omitted; call cluster_plan_read for the full plan) ---\n${planOutline(turnClusterPlan)}`
|
|
2357
|
+
: undefined;
|
|
2358
|
+
const clusterAppendCap = wf.primary.provider === 'codex' && codexTransport === 'appserver'
|
|
2359
|
+
? CODEX_APP_SERVER_CLUSTER_MAX
|
|
2360
|
+
: APPEND_CLUSTER_MAX;
|
|
2361
|
+
const { combined, planTruncatedFrom, usedFallback } = composeClusterAppend(planBlock, tailBlocks, finalAppend?.length ?? 0, clusterAppendCap, planFallback);
|
|
2362
|
+
if (planTruncatedFrom !== undefined) {
|
|
2363
|
+
console.log(`[arco] [${workflowId.slice(0, 8)}] cluster plan over string-form fold budget ` +
|
|
2364
|
+
`(${planTruncatedFrom} bytes → ${usedFallback ? 'outline fallback' : 'head-truncated'}; ` +
|
|
2365
|
+
`${clusterAppendCap} total cap; notice/role/addendum/doctrines preserved)`);
|
|
2366
|
+
}
|
|
2367
|
+
if (combined) {
|
|
2368
|
+
finalAppend = finalAppend ? `${combined}\n\n${finalAppend}` : combined;
|
|
2369
|
+
}
|
|
2215
2370
|
}
|
|
2216
|
-
|
|
2217
|
-
//
|
|
2218
|
-
|
|
2219
|
-
//
|
|
2220
|
-
//
|
|
2221
|
-
//
|
|
2222
|
-
//
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2371
|
+
const genesisSeed = wf.config.genesisSeed;
|
|
2372
|
+
// Separator-agnostic scratch-dir check (POSIX primary; tolerate Windows).
|
|
2373
|
+
const inGenesisScratch = !!genesisSeed && /[\\/]\.arco[\\/]genesis[\\/]/.test(cwd);
|
|
2374
|
+
// M3 Creative mode runs the same staged framing inside an EXISTING workflow
|
|
2375
|
+
// (real cwd) — gated on the operator-armed seed.creative flag instead of the
|
|
2376
|
+
// scratch-dir path. buildGenesisSystemBlock folds in seed.projectContext for
|
|
2377
|
+
// this case so the model stays anchored to what is really on disk.
|
|
2378
|
+
const inGenesisCreative = !!genesisSeed && genesisSeed.creative === true;
|
|
2379
|
+
if ((inGenesisScratch || inGenesisCreative || genesisSeed?.planOnly) && genesisSeed) {
|
|
2380
|
+
if (wf.primary.provider === 'ollama' || wf.primary.provider === 'llamacpp' || wf.primary.provider === 'lmstudio' || (wf.primary.provider === 'strata' || wf.primary.provider === 'deepseek')) {
|
|
2381
|
+
finalSystemPrompt = buildGenesisSystemBlock(genesisSeed, { base: finalSystemPrompt });
|
|
2382
|
+
}
|
|
2383
|
+
else {
|
|
2384
|
+
const genesisBlock = buildGenesisSystemBlock(genesisSeed);
|
|
2385
|
+
finalAppend = finalAppend ? `${genesisBlock}\n\n${finalAppend}` : genesisBlock;
|
|
2386
|
+
}
|
|
2229
2387
|
}
|
|
2230
|
-
if (
|
|
2231
|
-
|
|
2388
|
+
if (genesisSeed?.github?.create && genesisSeed.github.visibility === 'public') {
|
|
2389
|
+
if (wf.primary.provider === 'ollama' || wf.primary.provider === 'llamacpp' || wf.primary.provider === 'lmstudio' || (wf.primary.provider === 'strata' || wf.primary.provider === 'deepseek')) {
|
|
2390
|
+
finalSystemPrompt = finalSystemPrompt
|
|
2391
|
+
? `${PUBLIC_REPO_SAFETY_SYSTEM_BLOCK}\n\n${finalSystemPrompt}`
|
|
2392
|
+
: PUBLIC_REPO_SAFETY_SYSTEM_BLOCK;
|
|
2393
|
+
}
|
|
2394
|
+
else {
|
|
2395
|
+
finalAppend = finalAppend
|
|
2396
|
+
? `${PUBLIC_REPO_SAFETY_SYSTEM_BLOCK}\n\n${finalAppend}`
|
|
2397
|
+
: PUBLIC_REPO_SAFETY_SYSTEM_BLOCK;
|
|
2398
|
+
}
|
|
2232
2399
|
}
|
|
2233
|
-
|
|
2234
|
-
|
|
2400
|
+
// docs/GOTCHAS.md - the north-star is NOT folded here. Native
|
|
2401
|
+
// injects it as its own cached system block (buildSystemBlocks reads
|
|
2402
|
+
// config.goal); every other transport folds goalBlock(config.goal) inside
|
|
2403
|
+
// its own provider (mirroring outputStyleAddendum). Doing it per-provider
|
|
2404
|
+
// rather than into finalAppend here is load-bearing: reviewers spawn via
|
|
2405
|
+
// manager.spawn and handoff seeds via runPrimaryTurn — both bypass this
|
|
2406
|
+
// operator-turn assembly but still carry config.goal, so the provider fold
|
|
2407
|
+
// is the one place that covers operator turns AND primitive seeds without
|
|
2408
|
+
// double-injecting.
|
|
2409
|
+
// docs/ARCHITECTURE.md - resolve the operator-enabled-and-allowed
|
|
2410
|
+
// registry MCP servers for this workflow from the global registry + the
|
|
2411
|
+
// workflow's per-tab allowlist (meta.mcpAllow). Produces BOTH the merged
|
|
2412
|
+
// server entries (for the mcp-config write / Codex `-c` overrides) AND
|
|
2413
|
+
// the dangerous-and-unticked `--disallowedTools` set for CLI Claude.
|
|
2414
|
+
// This is the ONLY model-exposed expansion besides cluster /
|
|
2415
|
+
// codebase-memory — no hidden, model-selected servers.
|
|
2416
|
+
let turnRegistryServers = [];
|
|
2417
|
+
let turnMcpDisallowedTools = [];
|
|
2418
|
+
if (projectContextEnabled)
|
|
2419
|
+
try {
|
|
2420
|
+
const metaForMcp = await readMeta(cwd, workflowId);
|
|
2421
|
+
const wiring = await resolveRegistryWiring(metaForMcp?.mcpAllow ?? []);
|
|
2422
|
+
turnRegistryServers = wiring.registryServers;
|
|
2423
|
+
turnMcpDisallowedTools = wiring.disallowedTools;
|
|
2424
|
+
}
|
|
2425
|
+
catch (err) {
|
|
2426
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] mcp registry resolve failed:`, err);
|
|
2427
|
+
}
|
|
2428
|
+
// docs/PROVIDERS.md - write `.arco/<wfid>/mcp-config.json`
|
|
2429
|
+
// for CLI Claude turns when cluster membership, the operator-attached
|
|
2430
|
+
// codebase-memory entry, OR §E1 registry servers apply. All coexist; the
|
|
2431
|
+
// writer merges deterministically and unlinks when none apply. Codex
|
|
2432
|
+
// transports don't use --mcp-config — they layer the same registrations
|
|
2433
|
+
// on via `-c mcp_servers.*` TOML overrides built in the codex provider.
|
|
2434
|
+
if (projectContextEnabled && wf.primary.provider === 'claude' && claudeTransport === 'cli') {
|
|
2435
|
+
const cbm = wf.config.codebaseMemory;
|
|
2436
|
+
const wantsCodebaseMemory = projectContextEnabled && cbm?.attached === true;
|
|
2437
|
+
// The workflow-scoped `arco` plan entry applies to EVERY workflow, so
|
|
2438
|
+
// the config is now written unconditionally (cwd is the only
|
|
2439
|
+
// precondition) rather than only when a cluster / codebase-memory /
|
|
2440
|
+
// registry entry applies.
|
|
2441
|
+
{
|
|
2442
|
+
try {
|
|
2443
|
+
turnClusterMcpConfigPath = await mcpConfigWriter.writeFor(cwd, workflowId, {
|
|
2444
|
+
planToolsCwd: cwd,
|
|
2445
|
+
handoffHistoryToken: !wf.primary.tools || wf.primary.tools.includes('handoff_history')
|
|
2446
|
+
? await mintHandoffHistoryCapability(workflowId) : undefined,
|
|
2447
|
+
clusterId: turnClusterId,
|
|
2448
|
+
taskBoardAttached: turnClusterTaskBoardAttached,
|
|
2449
|
+
accessMode: clusterAccessMode,
|
|
2450
|
+
port: PORT,
|
|
2451
|
+
codebaseMemoryIndexPath: wantsCodebaseMemory
|
|
2452
|
+
? (cbm?.indexPath || cwd)
|
|
2453
|
+
: undefined,
|
|
2454
|
+
registryServers: turnRegistryServers,
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
catch (err) {
|
|
2458
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] mcp-config write failed:`, err);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2235
2461
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
//
|
|
2240
|
-
//
|
|
2241
|
-
//
|
|
2242
|
-
//
|
|
2243
|
-
//
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2462
|
+
// Workbench Expansion A2 — shadow-git checkpoint. Snapshot the working
|
|
2463
|
+
// tree BEFORE the turn that may mutate files so the operator can
|
|
2464
|
+
// undo-the-agent independent of their real git history. Skipped when
|
|
2465
|
+
// plan mode is armed (the turn is read-only until ExitPlanMode, so
|
|
2466
|
+
// there's nothing to checkpoint). Wait at most two seconds; a slow or
|
|
2467
|
+
// failed capture is omitted and the turn proceeds without a summary.
|
|
2468
|
+
//
|
|
2469
|
+
// Hooked HERE rather than in seedWorker.ts (the plan's guess): runtime
|
|
2470
|
+
// verification showed runPrimaryTurn is shared by reviewers, handoff
|
|
2471
|
+
// seeds, exportContext, and Task children — none of which should snapshot
|
|
2472
|
+
// the operator's tree. The operator-turn loop in turnEngine.handleUserMessage
|
|
2473
|
+
// is the only dispatch path that runs an operator-driven, file-mutating
|
|
2474
|
+
// turn, so the checkpoint belongs at this call site. The ref suffix uses
|
|
2475
|
+
// the workflow's current event seq (the turn it guards), carried as
|
|
2476
|
+
// `checkpointSeq`; the checkpoint_created event gets its own next seq.
|
|
2477
|
+
// Upload-time image downscaling runs in the background; a send right
|
|
2478
|
+
// after a paste can beat it. Wait (bounded) here so the sync providers
|
|
2479
|
+
// (Claude CLI / Native, Codex exec) read the model copy too — they call
|
|
2480
|
+
// the sync modelImagePath() and can't wait themselves.
|
|
2481
|
+
if (promptAttachments && promptAttachments.length > 0)
|
|
2482
|
+
await awaitModelImages(promptAttachments);
|
|
2483
|
+
// STOP landed during the pre-spawn awaits above (killAll had nothing to
|
|
2484
|
+
// kill yet). Spawning now would run a turn nobody owns.
|
|
2485
|
+
if (!ownsBusy(wf, busyToken))
|
|
2486
|
+
break;
|
|
2487
|
+
if (wf.queue.steering.some((q) => q.interrupt)) {
|
|
2488
|
+
firstIteration = false;
|
|
2489
|
+
loadQueuedPrompt(primaryTurn.holdSteer);
|
|
2490
|
+
continue;
|
|
2255
2491
|
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2492
|
+
let checkpointSkipNoticeSent = false;
|
|
2493
|
+
const onCheckpointSkipped = (content) => {
|
|
2494
|
+
if (checkpointSkipNoticeSent || workflows.get(workflowId) !== wf)
|
|
2495
|
+
return;
|
|
2496
|
+
checkpointSkipNoticeSent = true;
|
|
2497
|
+
broadcastWorkflow(workflowId, { type: 'system_notice', workflowId, content });
|
|
2498
|
+
};
|
|
2499
|
+
let checkpoint = null;
|
|
2500
|
+
let checkpointGuardSeq;
|
|
2501
|
+
if (!(firstIteration && primitive === 'plan-review') && shouldCaptureTurn({ chatMode, planMode: armPlanMode, isolated: isolatedMember, provider: wf.primary.provider, tools: wf.primary.tools })) {
|
|
2502
|
+
checkpointGuardSeq = currentWorkflowSeq(cwd, workflowId);
|
|
2503
|
+
activeTurnObservation = observeCheckoutWriters(workflowWritePaths(wf), wf.manager);
|
|
2504
|
+
checkpoint = await timelyCheckpoint((deps.captureCheckpoint ?? createCheckpoint)({ cwd, workflowId, seq: checkpointGuardSeq, onSkipped: onCheckpointSkipped }));
|
|
2505
|
+
if (!checkpoint || !ownsBusy(wf, busyToken)) {
|
|
2506
|
+
activeTurnObservation.stop();
|
|
2507
|
+
activeTurnObservation = undefined;
|
|
2508
|
+
checkpoint = null;
|
|
2509
|
+
}
|
|
2258
2510
|
}
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
if ((inGenesisScratch || inGenesisCreative) && genesisSeed) {
|
|
2269
|
-
if (wf.primary.provider === 'ollama' || wf.primary.provider === 'llamacpp' || wf.primary.provider === 'lmstudio' || (wf.primary.provider === 'strata' || wf.primary.provider === 'deepseek')) {
|
|
2270
|
-
finalSystemPrompt = buildGenesisSystemBlock(genesisSeed, { base: finalSystemPrompt });
|
|
2511
|
+
// STOP or an interrupt during capture must never launch the stale prompt.
|
|
2512
|
+
if (!ownsBusy(wf, busyToken))
|
|
2513
|
+
break;
|
|
2514
|
+
if (wf.queue.steering.some((q) => q.interrupt)) {
|
|
2515
|
+
activeTurnObservation?.stop();
|
|
2516
|
+
activeTurnObservation = undefined;
|
|
2517
|
+
firstIteration = false;
|
|
2518
|
+
loadQueuedPrompt(primaryTurn.holdSteer);
|
|
2519
|
+
continue;
|
|
2271
2520
|
}
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2521
|
+
if (checkpoint && checkpointGuardSeq !== undefined) {
|
|
2522
|
+
broadcastWorkflow(workflowId, {
|
|
2523
|
+
type: 'checkpoint_created', workflowId, checkpointSeq: checkpointGuardSeq,
|
|
2524
|
+
ref: checkpoint.ref, label: checkpoint.label, ts: checkpoint.ts, fileCount: checkpoint.fileCount,
|
|
2525
|
+
...(checkpoint.skippedLargeFiles ? { skippedLargeFiles: checkpoint.skippedLargeFiles } : {}),
|
|
2526
|
+
...(checkpoint.limitation ? { limitation: checkpoint.limitation } : {}),
|
|
2527
|
+
});
|
|
2275
2528
|
}
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2529
|
+
const policyTurnProvider = wf.primary.provider;
|
|
2530
|
+
const ollamaExecutionId = trackOllama ? randomUUID() : undefined;
|
|
2531
|
+
const executionInputSeqs = [...activeOllamaInputSeqs];
|
|
2532
|
+
const executionInputClientIds = [...activeInputClientIds];
|
|
2533
|
+
let dispatchedWorkerId;
|
|
2534
|
+
const dispatchCurrent = () => workflows.get(workflowId) === wf && ownsBusy(wf, busyToken) && (dispatchedWorkerId === undefined || primaryTurn.workerId === dispatchedWorkerId);
|
|
2535
|
+
const turn = runPrimaryTurn({
|
|
2536
|
+
workflowId,
|
|
2537
|
+
cwd,
|
|
2538
|
+
manager: wf.manager,
|
|
2539
|
+
broadcast: (msg) => {
|
|
2540
|
+
// A Task child's final status still belongs to the card after STOP.
|
|
2541
|
+
if (!dispatchCurrent() && !deliverAfterTurnRevoked(msg))
|
|
2542
|
+
return;
|
|
2543
|
+
const delivery = msg.type === 'primary_turn_started' && executionInputClientIds.length
|
|
2544
|
+
? { ...msg, inputClientMessageIds: executionInputClientIds } : msg;
|
|
2545
|
+
send(ws, ollamaExecutionId ? stampOllamaExecution(delivery, ollamaExecutionId, executionInputSeqs) : delivery);
|
|
2546
|
+
},
|
|
2547
|
+
bgTracker: chatMode ? undefined : wf.bgTracker,
|
|
2548
|
+
notePotentialDevServerStart: chatMode ? undefined : (cmd, toolUseId) => { if (dispatchCurrent())
|
|
2549
|
+
deps.previewAutoDetect.notePotentialDevServerStart(workflowId, cmd, toolUseId); },
|
|
2550
|
+
noteAgentText: chatMode ? undefined : (text) => { if (dispatchCurrent())
|
|
2551
|
+
deps.previewAutoDetect.noteAgentText(workflowId, text); },
|
|
2552
|
+
}, {
|
|
2553
|
+
primary: wf.primary,
|
|
2554
|
+
prompt: promptWithPlan,
|
|
2555
|
+
resumeSessionId: incognito ? undefined : wf.primarySessionId,
|
|
2556
|
+
attachments: promptAttachments,
|
|
2557
|
+
disableRssGuard: wf.disableRssGuard,
|
|
2558
|
+
appendSystemPrompt: finalAppend,
|
|
2559
|
+
systemPrompt: finalSystemPrompt,
|
|
2560
|
+
interactionMode: chatMode || (firstIteration && primitive === 'plan-review') ? 'chat' : 'agent',
|
|
2561
|
+
disableProviderHooks: firstIteration && primitive === 'plan-review',
|
|
2562
|
+
chatWebAccess: firstIteration && primitive === 'plan-review' ? false : chatWeb,
|
|
2563
|
+
voiceOperator: chatMode && wf.config.voiceOperator === true,
|
|
2564
|
+
incognito,
|
|
2565
|
+
drainSteer: () => {
|
|
2566
|
+
if (!dispatchCurrent())
|
|
2567
|
+
return [];
|
|
2568
|
+
return drainSteerForWorker(workflowId, ws, policyTurnProvider);
|
|
2569
|
+
},
|
|
2570
|
+
requeueSteer: (items, bucket) => {
|
|
2571
|
+
if (workflows.get(workflowId) === wf && (busyRevocations.get(wf) ?? 0) === interruptEpoch)
|
|
2572
|
+
requeueSteerForWorker(workflowId, ws, items, bucket);
|
|
2573
|
+
},
|
|
2574
|
+
onSteerDelivered: (items) => {
|
|
2575
|
+
const clientMessageIds = items.flatMap((item) => item.clientMessageId ? [item.clientMessageId] : []);
|
|
2576
|
+
if (clientMessageIds.length && policyTurnProvider === 'codex')
|
|
2577
|
+
broadcastWorkflow(workflowId, { type: 'turn_messages_delivered', workflowId, clientMessageIds, ...(items[0]?.deliveryId ? { deliveryId: items[0].deliveryId } : {}) });
|
|
2578
|
+
},
|
|
2579
|
+
codexTransport,
|
|
2580
|
+
codexContextPolicy: wf.config.codexContextPolicy,
|
|
2581
|
+
providerAccountRef: providerAccount?.profile.id,
|
|
2582
|
+
codexHome: providerAccount?.codexHome,
|
|
2583
|
+
claudeTransport,
|
|
2584
|
+
ultracode,
|
|
2585
|
+
claudeNativeCompact,
|
|
2586
|
+
claudeNativeTaskDisabled: wf.config.claudeNativeTaskDisabled,
|
|
2587
|
+
...(claudeNativeInTurnCompactPercent !== undefined && !(firstIteration && primitive === 'plan-review') ? { claudeNativeInTurnCompactPercent } : {}),
|
|
2588
|
+
claudeNativeForceInterleavedThinkingBeta,
|
|
2589
|
+
claudeNativeThinkingDisplay, nativeSubagents,
|
|
2590
|
+
claudeNativePlanModeArmed: armPlanMode,
|
|
2591
|
+
turnNotice: turnNoticeParts.length > 0 ? turnNoticeParts.join('\n\n') : undefined,
|
|
2592
|
+
efficiencyToolFilter,
|
|
2593
|
+
efficiencyFactForce,
|
|
2594
|
+
efficiencyConfigProtection,
|
|
2595
|
+
efficiencySandbox,
|
|
2596
|
+
reviewSafeMode,
|
|
2597
|
+
outputStyle: firstIteration && primitive === 'plan-review' ? 'normal' : outputStyle,
|
|
2598
|
+
goal,
|
|
2599
|
+
// §4.1 — session-local posture filter (runtime-only WorkflowState
|
|
2600
|
+
// field). Operator-turn only; primitives (reviewers / handoff seeds /
|
|
2601
|
+
// Task children) leave it unset ⇒ full, like outputStyle's 'normal'.
|
|
2602
|
+
toolPosture: wf.toolPosture,
|
|
2603
|
+
clusterId: turnClusterId,
|
|
2604
|
+
clusterAccessMode,
|
|
2605
|
+
executionCwd: isolatedMember && turnClusterId
|
|
2606
|
+
? clusterStore.isolatedWorkspaceFor(turnClusterId, workflowId)
|
|
2607
|
+
: undefined,
|
|
2608
|
+
persistenceCwd: isolatedMember ? cwd : undefined,
|
|
2609
|
+
clusterTaskBoardAttached: turnClusterTaskBoardAttached,
|
|
2610
|
+
clusterPlan: turnClusterPlan,
|
|
2611
|
+
clusterRole: turnClusterRole,
|
|
2612
|
+
clusterEfficiencyDoctrine: turnClusterEfficiencyDoctrine,
|
|
2613
|
+
clusterProgressDoctrine: turnClusterProgressDoctrine,
|
|
2614
|
+
clusterMcpConfigPath: turnClusterMcpConfigPath,
|
|
2615
|
+
codebaseMemoryAttached: projectContextEnabled && wf.config.codebaseMemory?.attached === true,
|
|
2616
|
+
codebaseMemoryIndexPath: projectContextEnabled && wf.config.codebaseMemory?.attached === true
|
|
2617
|
+
? (wf.config.codebaseMemory.indexPath || cwd)
|
|
2618
|
+
: undefined,
|
|
2619
|
+
// §E1 — registry servers feed Codex `-c` overrides; CLI Claude got
|
|
2620
|
+
// them via the mcp-config write above. mcpDisallowedTools feed CLI
|
|
2621
|
+
// Claude's --disallowedTools (dangerous-tool denylist enforcement).
|
|
2622
|
+
mcpRegistryServers: turnRegistryServers,
|
|
2623
|
+
mcpDisallowedTools: turnMcpDisallowedTools,
|
|
2624
|
+
ollamaParams,
|
|
2625
|
+
ollamaReplay,
|
|
2626
|
+
priorFiles,
|
|
2627
|
+
fileContextCwd: retainLocalFiles ? cwd : undefined,
|
|
2628
|
+
fileContextInputIds: retainLocalFiles ? [...activeInputClientIds] : undefined,
|
|
2629
|
+
// Per-tab Claude Native web budget (Anthropic server-tool max_uses).
|
|
2630
|
+
// Native-only; the worker falls back to the server default when unset.
|
|
2631
|
+
webSearchMaxUses: wf.config.webSearchMaxUses,
|
|
2632
|
+
});
|
|
2633
|
+
dispatchedWorkerId = turn.workerId;
|
|
2634
|
+
activeTurnObservation?.setPrimaryWorker(turn.workerId);
|
|
2635
|
+
primaryTurn.workerId = turn.workerId;
|
|
2636
|
+
// Claude pre-mints its session id; pin it into meta.json immediately so a
|
|
2637
|
+
// crash between now and turn-completion still leaves meta pointing at the
|
|
2638
|
+
// right CLI session. Only relevant on the first iteration — later
|
|
2639
|
+
// flushes resume the already-pinned session. Native transport runs
|
|
2640
|
+
// in-process and never writes a CLI rollout, so seedWorker's pre-minted
|
|
2641
|
+
// UUID is meaningless here — recording it would phantom-pollute meta and
|
|
2642
|
+
// break original-worker handoff (which would try `claude --resume <id>`
|
|
2643
|
+
// against a non-existent rollout).
|
|
2644
|
+
if (!incognito && firstIteration && !wf.primarySessionId && turn.initialSessionId
|
|
2645
|
+
&& wf.primary.provider === 'claude' && claudeTransport !== 'native') {
|
|
2646
|
+
wf.primarySessionId = turn.initialSessionId;
|
|
2647
|
+
reconcileLatestCliSession(cwd, workflowId, 'claude', turn.initialSessionId).catch((err) => {
|
|
2648
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] meta reconcile (claude mint) failed:`, err);
|
|
2649
|
+
});
|
|
2282
2650
|
}
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2651
|
+
// Codex emits thread_id at init. Capture on first fire, persist to meta.
|
|
2652
|
+
turn.onSessionDiscovered((sid) => {
|
|
2653
|
+
if (incognito || !dispatchCurrent() || wf.primary.provider !== policyTurnProvider)
|
|
2654
|
+
return;
|
|
2655
|
+
if (!wf.primarySessionId)
|
|
2656
|
+
wf.primarySessionId = sid;
|
|
2657
|
+
reconcileLatestCliSession(cwd, workflowId, policyTurnProvider, sid, providerAccount?.profile.id).catch((err) => {
|
|
2658
|
+
console.error(`[arco] [${workflowId.slice(0, 8)}] meta reconcile (${wf.primary.provider}) failed:`, err);
|
|
2659
|
+
});
|
|
2660
|
+
});
|
|
2661
|
+
// docs/PROVIDERS.md - surface the background fleet. Under ultracode the
|
|
2662
|
+
// CLI's WorkflowTool runs subagents whose transcripts never touch the
|
|
2663
|
+
// parent stream, so the Activity tab would look dead. Poll those files and
|
|
2664
|
+
// emit live `ultracode_fleet_progress` snapshots, scoped strictly to this
|
|
2665
|
+
// turn (started here, stopped in finally). Gated on a known session id —
|
|
2666
|
+
// the watcher needs it to locate `<sessionId>/subagents/workflows/`.
|
|
2667
|
+
let fleetWatcher = null;
|
|
2668
|
+
if (ultracode && wf.primarySessionId) {
|
|
2669
|
+
fleetWatcher = startUltracodeFleetWatcher({
|
|
2670
|
+
workflowId,
|
|
2671
|
+
cwd,
|
|
2672
|
+
sessionId: wf.primarySessionId,
|
|
2673
|
+
emit: (msg) => broadcastTransient(workflowId, msg),
|
|
2674
|
+
});
|
|
2287
2675
|
}
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
// config.goal); every other transport folds goalBlock(config.goal) inside
|
|
2292
|
-
// its own provider (mirroring outputStyleAddendum). Doing it per-provider
|
|
2293
|
-
// rather than into finalAppend here is load-bearing: reviewers spawn via
|
|
2294
|
-
// manager.spawn and handoff seeds via runPrimaryTurn — both bypass this
|
|
2295
|
-
// operator-turn assembly but still carry config.goal, so the provider fold
|
|
2296
|
-
// is the one place that covers operator turns AND primitive seeds without
|
|
2297
|
-
// double-injecting.
|
|
2298
|
-
// docs/ARCHITECTURE.md - resolve the operator-enabled-and-allowed
|
|
2299
|
-
// registry MCP servers for this workflow from the global registry + the
|
|
2300
|
-
// workflow's per-tab allowlist (meta.mcpAllow). Produces BOTH the merged
|
|
2301
|
-
// server entries (for the mcp-config write / Codex `-c` overrides) AND
|
|
2302
|
-
// the dangerous-and-unticked `--disallowedTools` set for CLI Claude.
|
|
2303
|
-
// This is the ONLY model-exposed expansion besides cluster /
|
|
2304
|
-
// codebase-memory — no hidden, model-selected servers.
|
|
2305
|
-
let turnRegistryServers = [];
|
|
2306
|
-
let turnMcpDisallowedTools = [];
|
|
2307
|
-
if (projectContextEnabled)
|
|
2676
|
+
policyReading = undefined;
|
|
2677
|
+
let outcome;
|
|
2678
|
+
let carryInterruptedPrompt = false;
|
|
2308
2679
|
try {
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2680
|
+
outcome = await turn.settled;
|
|
2681
|
+
// A second correction may cancel Native during auth/hooks, before
|
|
2682
|
+
// its first correction entered history. Carry that unsent input.
|
|
2683
|
+
carryInterruptedPrompt = await primaryTurn.interruption === false && primaryTurn.holdSteer;
|
|
2313
2684
|
}
|
|
2314
2685
|
catch (err) {
|
|
2315
|
-
|
|
2686
|
+
if (!primaryTurn.interruption)
|
|
2687
|
+
throw err;
|
|
2688
|
+
preserveQueue = true;
|
|
2689
|
+
lastTurnErrored = true;
|
|
2690
|
+
broadcastWorkflow(workflowId, { type: 'system_notice', workflowId,
|
|
2691
|
+
content: `[INTERRUPT & SEND] Cancellation failed; queued messages were preserved without starting another turn. ${err instanceof Error ? err.message : String(err)}` });
|
|
2692
|
+
break;
|
|
2316
2693
|
}
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
// transports don't use --mcp-config — they layer the same registrations
|
|
2322
|
-
// on via `-c mcp_servers.*` TOML overrides built in the codex provider.
|
|
2323
|
-
if (projectContextEnabled && wf.primary.provider === 'claude' && claudeTransport === 'cli') {
|
|
2324
|
-
const cbm = wf.config.codebaseMemory;
|
|
2325
|
-
const wantsCodebaseMemory = projectContextEnabled && cbm?.attached === true;
|
|
2326
|
-
// The workflow-scoped `arco` plan entry applies to EVERY workflow, so
|
|
2327
|
-
// the config is now written unconditionally (cwd is the only
|
|
2328
|
-
// precondition) rather than only when a cluster / codebase-memory /
|
|
2329
|
-
// registry entry applies.
|
|
2330
|
-
{
|
|
2331
|
-
try {
|
|
2332
|
-
turnClusterMcpConfigPath = await mcpConfigWriter.writeFor(cwd, workflowId, {
|
|
2333
|
-
planToolsCwd: cwd,
|
|
2334
|
-
clusterId: turnClusterId,
|
|
2335
|
-
taskBoardAttached: turnClusterTaskBoardAttached,
|
|
2336
|
-
accessMode: clusterAccessMode,
|
|
2337
|
-
port: PORT,
|
|
2338
|
-
codebaseMemoryIndexPath: wantsCodebaseMemory
|
|
2339
|
-
? (cbm?.indexPath || cwd)
|
|
2340
|
-
: undefined,
|
|
2341
|
-
registryServers: turnRegistryServers,
|
|
2342
|
-
});
|
|
2343
|
-
}
|
|
2344
|
-
catch (err) {
|
|
2345
|
-
console.error(`[arco] [${workflowId.slice(0, 8)}] mcp-config write failed:`, err);
|
|
2346
|
-
}
|
|
2694
|
+
finally {
|
|
2695
|
+
fleetWatcher?.stop();
|
|
2696
|
+
primaryTurn.workerId = undefined;
|
|
2697
|
+
primaryTurn.interruption = undefined;
|
|
2347
2698
|
}
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
// STOP landed during the pre-spawn awaits above (killAll had nothing to
|
|
2371
|
-
// kill yet). Spawning now would run a turn nobody owns.
|
|
2372
|
-
if (!ownsBusy(wf, busyToken))
|
|
2373
|
-
break;
|
|
2374
|
-
if (wf.queue.steering.some((q) => q.interrupt)) {
|
|
2375
|
-
firstIteration = false;
|
|
2376
|
-
loadQueuedPrompt(primaryTurn.holdSteer);
|
|
2377
|
-
continue;
|
|
2378
|
-
}
|
|
2379
|
-
let checkpoint = null;
|
|
2380
|
-
let checkpointGuardSeq;
|
|
2381
|
-
if (!(firstIteration && primitive === 'plan-review') && shouldCaptureTurn({ chatMode, planMode: armPlanMode, isolated: isolatedMember, provider: wf.primary.provider, tools: wf.primary.tools })) {
|
|
2382
|
-
checkpointGuardSeq = currentWorkflowSeq(cwd, workflowId);
|
|
2383
|
-
activeTurnObservation = observeCheckoutWriters(workflowWritePaths(wf), wf.manager);
|
|
2384
|
-
checkpoint = await timelyCheckpoint((deps.captureCheckpoint ?? createCheckpoint)({ cwd, workflowId, seq: checkpointGuardSeq }));
|
|
2385
|
-
if (!checkpoint || !ownsBusy(wf, busyToken)) {
|
|
2386
|
-
activeTurnObservation.stop();
|
|
2387
|
-
activeTurnObservation = undefined;
|
|
2388
|
-
checkpoint = null;
|
|
2699
|
+
if (checkpoint && checkpointGuardSeq !== undefined && activeTurnObservation && ownsBusy(wf, busyToken)) {
|
|
2700
|
+
// Hold this workflow's busy claim until the end snapshot is captured;
|
|
2701
|
+
// otherwise a queued follow-up could alter the tree before the range ends.
|
|
2702
|
+
const endSeq = currentWorkflowSeq(cwd, workflowId);
|
|
2703
|
+
if (endSeq > checkpointGuardSeq) {
|
|
2704
|
+
const end = await (deps.captureCheckpoint ?? createCheckpoint)({ cwd, workflowId, seq: endSeq, onSkipped: onCheckpointSkipped });
|
|
2705
|
+
if (end && ownsBusy(wf, busyToken)) {
|
|
2706
|
+
const otherWriters = activeTurnObservation.hasOverlap();
|
|
2707
|
+
activeTurnObservation.stop();
|
|
2708
|
+
activeTurnObservation = undefined;
|
|
2709
|
+
const summary = await summarizeTurnChanges(cwd, checkpoint.ref, end.ref);
|
|
2710
|
+
if (summary && summary.fileCount > 0 && ownsBusy(wf, busyToken)) {
|
|
2711
|
+
broadcastWorkflow(workflowId, {
|
|
2712
|
+
type: 'turn_changes', workflowId, checkpointSeq: checkpointGuardSeq,
|
|
2713
|
+
fromRef: checkpoint.ref, toRef: end.ref, ...summary,
|
|
2714
|
+
otherWriters,
|
|
2715
|
+
...((checkpoint.skippedLargeFiles || end.skippedLargeFiles) ? { skippedLargeFiles: Math.max(checkpoint.skippedLargeFiles ?? 0, end.skippedLargeFiles ?? 0) } : {}),
|
|
2716
|
+
timestamp: Date.now(),
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2389
2721
|
}
|
|
2390
|
-
}
|
|
2391
|
-
// STOP or an interrupt during capture must never launch the stale prompt.
|
|
2392
|
-
if (!ownsBusy(wf, busyToken))
|
|
2393
|
-
break;
|
|
2394
|
-
if (wf.queue.steering.some((q) => q.interrupt)) {
|
|
2395
2722
|
activeTurnObservation?.stop();
|
|
2396
2723
|
activeTurnObservation = undefined;
|
|
2724
|
+
console.log(`[arco] [${workflowId.slice(0, 8)}] turn settled${outcome.error ? ' with error: ' + outcome.error : ''}`);
|
|
2725
|
+
lastTurnErrored = !!outcome.error;
|
|
2726
|
+
watchHadError ||= lastTurnErrored;
|
|
2727
|
+
if (firstIteration && opts?.backgroundEvent)
|
|
2728
|
+
opts.onBackgroundSettled?.(outcome.error ?? undefined);
|
|
2729
|
+
clearComputerBackgroundClaim(workflowId, busyToken);
|
|
2397
2730
|
firstIteration = false;
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
clusterEfficiencyDoctrine: turnClusterEfficiencyDoctrine,
|
|
2471
|
-
clusterProgressDoctrine: turnClusterProgressDoctrine,
|
|
2472
|
-
clusterMcpConfigPath: turnClusterMcpConfigPath,
|
|
2473
|
-
codebaseMemoryAttached: projectContextEnabled && wf.config.codebaseMemory?.attached === true,
|
|
2474
|
-
codebaseMemoryIndexPath: projectContextEnabled && wf.config.codebaseMemory?.attached === true
|
|
2475
|
-
? (wf.config.codebaseMemory.indexPath || cwd)
|
|
2476
|
-
: undefined,
|
|
2477
|
-
// §E1 — registry servers feed Codex `-c` overrides; CLI Claude got
|
|
2478
|
-
// them via the mcp-config write above. mcpDisallowedTools feed CLI
|
|
2479
|
-
// Claude's --disallowedTools (dangerous-tool denylist enforcement).
|
|
2480
|
-
mcpRegistryServers: turnRegistryServers,
|
|
2481
|
-
mcpDisallowedTools: turnMcpDisallowedTools,
|
|
2482
|
-
ollamaParams,
|
|
2483
|
-
ollamaReplay,
|
|
2484
|
-
// Per-tab Claude Native web budget (Anthropic server-tool max_uses).
|
|
2485
|
-
// Native-only; the worker falls back to the server default when unset.
|
|
2486
|
-
webSearchMaxUses: wf.config.webSearchMaxUses,
|
|
2487
|
-
});
|
|
2488
|
-
activeTurnObservation?.setPrimaryWorker(turn.workerId);
|
|
2489
|
-
primaryTurn.workerId = turn.workerId;
|
|
2490
|
-
// Claude pre-mints its session id; pin it into meta.json immediately so a
|
|
2491
|
-
// crash between now and turn-completion still leaves meta pointing at the
|
|
2492
|
-
// right CLI session. Only relevant on the first iteration — later
|
|
2493
|
-
// flushes resume the already-pinned session. Native transport runs
|
|
2494
|
-
// in-process and never writes a CLI rollout, so seedWorker's pre-minted
|
|
2495
|
-
// UUID is meaningless here — recording it would phantom-pollute meta and
|
|
2496
|
-
// break original-worker handoff (which would try `claude --resume <id>`
|
|
2497
|
-
// against a non-existent rollout).
|
|
2498
|
-
if (!incognito && firstIteration && !wf.primarySessionId && turn.initialSessionId
|
|
2499
|
-
&& wf.primary.provider === 'claude' && claudeTransport !== 'native') {
|
|
2500
|
-
wf.primarySessionId = turn.initialSessionId;
|
|
2501
|
-
reconcileLatestCliSession(cwd, workflowId, 'claude', turn.initialSessionId).catch((err) => {
|
|
2502
|
-
console.error(`[arco] [${workflowId.slice(0, 8)}] meta reconcile (claude mint) failed:`, err);
|
|
2503
|
-
});
|
|
2504
|
-
}
|
|
2505
|
-
// Codex emits thread_id at init. Capture on first fire, persist to meta.
|
|
2506
|
-
turn.onSessionDiscovered((sid) => {
|
|
2507
|
-
if (incognito)
|
|
2508
|
-
return;
|
|
2509
|
-
if (!wf.primarySessionId)
|
|
2510
|
-
wf.primarySessionId = sid;
|
|
2511
|
-
reconcileLatestCliSession(cwd, workflowId, wf.primary.provider, sid, providerAccount?.profile.id).catch((err) => {
|
|
2512
|
-
console.error(`[arco] [${workflowId.slice(0, 8)}] meta reconcile (${wf.primary.provider}) failed:`, err);
|
|
2513
|
-
});
|
|
2514
|
-
});
|
|
2515
|
-
// docs/PROVIDERS.md - surface the background fleet. Under ultracode the
|
|
2516
|
-
// CLI's WorkflowTool runs subagents whose transcripts never touch the
|
|
2517
|
-
// parent stream, so the Activity tab would look dead. Poll those files and
|
|
2518
|
-
// emit live `ultracode_fleet_progress` snapshots, scoped strictly to this
|
|
2519
|
-
// turn (started here, stopped in finally). Gated on a known session id —
|
|
2520
|
-
// the watcher needs it to locate `<sessionId>/subagents/workflows/`.
|
|
2521
|
-
let fleetWatcher = null;
|
|
2522
|
-
if (ultracode && wf.primarySessionId) {
|
|
2523
|
-
fleetWatcher = startUltracodeFleetWatcher({
|
|
2524
|
-
workflowId,
|
|
2525
|
-
cwd,
|
|
2526
|
-
sessionId: wf.primarySessionId,
|
|
2527
|
-
emit: (msg) => broadcastTransient(workflowId, msg),
|
|
2528
|
-
});
|
|
2529
|
-
}
|
|
2530
|
-
policyReading = undefined;
|
|
2531
|
-
let outcome;
|
|
2532
|
-
let carryInterruptedPrompt = false;
|
|
2533
|
-
try {
|
|
2534
|
-
outcome = await turn.settled;
|
|
2535
|
-
// A second correction may cancel Native during auth/hooks, before
|
|
2536
|
-
// its first correction entered history. Carry that unsent input.
|
|
2537
|
-
carryInterruptedPrompt = await primaryTurn.interruption === false && primaryTurn.holdSteer;
|
|
2538
|
-
}
|
|
2539
|
-
catch (err) {
|
|
2540
|
-
if (!primaryTurn.interruption)
|
|
2541
|
-
throw err;
|
|
2542
|
-
preserveQueue = true;
|
|
2543
|
-
lastTurnErrored = true;
|
|
2544
|
-
broadcastWorkflow(workflowId, { type: 'system_notice', workflowId,
|
|
2545
|
-
content: `[INTERRUPT & SEND] Cancellation failed; queued messages were preserved without starting another turn. ${err instanceof Error ? err.message : String(err)}` });
|
|
2546
|
-
break;
|
|
2547
|
-
}
|
|
2548
|
-
finally {
|
|
2549
|
-
fleetWatcher?.stop();
|
|
2550
|
-
primaryTurn.workerId = undefined;
|
|
2551
|
-
primaryTurn.interruption = undefined;
|
|
2552
|
-
}
|
|
2553
|
-
if (checkpoint && checkpointGuardSeq !== undefined && activeTurnObservation && ownsBusy(wf, busyToken)) {
|
|
2554
|
-
// Hold this workflow's busy claim until the end snapshot is captured;
|
|
2555
|
-
// otherwise a queued follow-up could alter the tree before the range ends.
|
|
2556
|
-
const endSeq = currentWorkflowSeq(cwd, workflowId);
|
|
2557
|
-
if (endSeq > checkpointGuardSeq) {
|
|
2558
|
-
const end = await (deps.captureCheckpoint ?? createCheckpoint)({ cwd, workflowId, seq: endSeq });
|
|
2559
|
-
if (end && ownsBusy(wf, busyToken)) {
|
|
2560
|
-
const otherWriters = activeTurnObservation.hasOverlap();
|
|
2561
|
-
activeTurnObservation.stop();
|
|
2562
|
-
activeTurnObservation = undefined;
|
|
2563
|
-
const summary = await summarizeTurnChanges(cwd, checkpoint.ref, end.ref);
|
|
2564
|
-
if (summary && summary.fileCount > 0 && ownsBusy(wf, busyToken)) {
|
|
2565
|
-
broadcastWorkflow(workflowId, {
|
|
2566
|
-
type: 'turn_changes', workflowId, checkpointSeq: checkpointGuardSeq,
|
|
2567
|
-
fromRef: checkpoint.ref, toRef: end.ref, ...summary,
|
|
2568
|
-
otherWriters,
|
|
2569
|
-
...((checkpoint.skippedLargeFiles || end.skippedLargeFiles) ? { skippedLargeFiles: Math.max(checkpoint.skippedLargeFiles ?? 0, end.skippedLargeFiles ?? 0) } : {}),
|
|
2570
|
-
timestamp: Date.now(),
|
|
2571
|
-
});
|
|
2572
|
-
}
|
|
2731
|
+
if (wf.config.voiceOperator && outcome.error?.startsWith(COMPUTER_TIMEOUT)) {
|
|
2732
|
+
// The transport may have executed earlier actions. Never replay this
|
|
2733
|
+
// request or drain dependent queued instructions after a timeout.
|
|
2734
|
+
const queued = wf.queue.steering.length + wf.queue.followUp.length;
|
|
2735
|
+
for (const item of [...wf.queue.steering, ...wf.queue.followUp])
|
|
2736
|
+
if (item.clientMessageId)
|
|
2737
|
+
broadcastWorkflow(workflowId, { type: 'queued_message_cancelled', workflowId, clientMessageId: item.clientMessageId });
|
|
2738
|
+
if (queued)
|
|
2739
|
+
broadcastWorkflow(workflowId, { type: 'system_notice', workflowId,
|
|
2740
|
+
content: `[COMPUTER] Cancelled ${queued} queued request(s) after the timeout; resubmit them when ready. Earlier actions may already have happened.` });
|
|
2741
|
+
if (incognito)
|
|
2742
|
+
wf.config.computerContext = { ...(wf.config.computerContext ?? { keepContext: false, resets: 0 }), pendingFresh: true, pendingFreshReason: 'recovery' };
|
|
2743
|
+
break;
|
|
2744
|
+
}
|
|
2745
|
+
if (wf.primary.provider === 'claude' && wf.primarySessionId && claudeTransport !== 'native') {
|
|
2746
|
+
const sid = wf.primarySessionId;
|
|
2747
|
+
estimateContextFill(cwd, sid, wf.primary.model, wf.calibration).then((est) => {
|
|
2748
|
+
if (!est)
|
|
2749
|
+
return;
|
|
2750
|
+
broadcastTransient(workflowId, {
|
|
2751
|
+
type: 'context_usage',
|
|
2752
|
+
workflowId,
|
|
2753
|
+
...est,
|
|
2754
|
+
claudeSessionId: sid,
|
|
2755
|
+
});
|
|
2756
|
+
// Keep the shared context signal fresh (fire-and-forget, so it may
|
|
2757
|
+
// settle one turn late; nothing here acts on a single reading).
|
|
2758
|
+
wf.lastContextPercent = est.percentOfWindow;
|
|
2759
|
+
}).catch(() => { });
|
|
2760
|
+
}
|
|
2761
|
+
else if (wf.primary.provider === 'claude' && claudeTransport === 'native' && typeof outcome.lastPromptTokens === 'number') {
|
|
2762
|
+
// Native Claude has no session JSONL to read. The worker's settled
|
|
2763
|
+
// outcome carries the last round's prompt size — convert to a fresh
|
|
2764
|
+
// ground-truth context_usage and fan out via broadcastTransient
|
|
2765
|
+
// (consistent with the CLI path: primary_complete already persists
|
|
2766
|
+
// lastPromptTokens, so context_usage stays derived/transient).
|
|
2767
|
+
const est = wf.config.voiceOperator && outcome.modelContextWindow
|
|
2768
|
+
? promptContextEstimate(outcome.lastPromptTokens, outcome.modelContextWindow, Date.now())
|
|
2769
|
+
: nativeContextEstimate(wf.primary.model, outcome.lastPromptTokens, Date.now());
|
|
2770
|
+
if (est) {
|
|
2771
|
+
wf.lastContextPercent = est.percentOfWindow;
|
|
2772
|
+
broadcastTransient(workflowId, {
|
|
2773
|
+
type: 'context_usage',
|
|
2774
|
+
workflowId,
|
|
2775
|
+
...est,
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
// §2.3 — emit the deterministic budget meter alongside the CTX bar's
|
|
2779
|
+
// context_usage. Uses the same ground-truth lastPromptTokens but against
|
|
2780
|
+
// the EFFECTIVE window (real window − reserved output budget) — the
|
|
2781
|
+
// usable-input-pressure signal the §2.1 auto-fold trigger reads. Window +
|
|
2782
|
+
// reserved come straight from the model's own params (KNOWN_CTX +
|
|
2783
|
+
// chooseMaxTokens), so this stays deterministic and LLM-free.
|
|
2784
|
+
const win = lookupCtx(wf.primary.model);
|
|
2785
|
+
if (typeof win === 'number' && win > 0) {
|
|
2786
|
+
const reserved = chooseMaxTokens(wf.primary.model, wf.primary.effort ?? 'high');
|
|
2787
|
+
const budget = computeContextBudget(outcome.lastPromptTokens, win, reserved);
|
|
2788
|
+
wf.lastContextBudgetPct = budget.pct;
|
|
2789
|
+
const thresholds = {
|
|
2790
|
+
...(typeof wf.autoFold?.foldAt === 'number' ? { foldAt: wf.autoFold.foldAt } : {}),
|
|
2791
|
+
};
|
|
2792
|
+
broadcastTransient(workflowId, {
|
|
2793
|
+
type: 'context_budget',
|
|
2794
|
+
workflowId,
|
|
2795
|
+
usedTokens: budget.usedTokens,
|
|
2796
|
+
windowSize: budget.windowSize,
|
|
2797
|
+
reservedOutput: budget.reservedOutput,
|
|
2798
|
+
effectiveWindow: budget.effectiveWindow,
|
|
2799
|
+
pct: budget.pct,
|
|
2800
|
+
thresholds,
|
|
2801
|
+
crossed: crossedThresholds(budget.pct, thresholds),
|
|
2802
|
+
});
|
|
2573
2803
|
}
|
|
2574
2804
|
}
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
if (incognito)
|
|
2596
|
-
wf.config.computerContext = { ...(wf.config.computerContext ?? { keepContext: false, resets: 0 }), pendingFresh: true, pendingFreshReason: 'recovery' };
|
|
2597
|
-
break;
|
|
2598
|
-
}
|
|
2599
|
-
if (wf.primary.provider === 'claude' && wf.primarySessionId && claudeTransport !== 'native') {
|
|
2600
|
-
const sid = wf.primarySessionId;
|
|
2601
|
-
estimateContextFill(cwd, sid, wf.primary.model, wf.calibration).then((est) => {
|
|
2602
|
-
if (!est)
|
|
2603
|
-
return;
|
|
2604
|
-
broadcastTransient(workflowId, {
|
|
2605
|
-
type: 'context_usage',
|
|
2606
|
-
workflowId,
|
|
2607
|
-
...est,
|
|
2608
|
-
claudeSessionId: sid,
|
|
2609
|
-
});
|
|
2610
|
-
// Keep the shared auto-handoff signal fresh (fire-and-forget, so it
|
|
2611
|
-
// may settle just after maybeAutoHandoff runs — warnAt/autoAt margin
|
|
2612
|
-
// absorbs the one-turn lag).
|
|
2613
|
-
wf.lastContextPercent = est.percentOfWindow;
|
|
2614
|
-
}).catch(() => { });
|
|
2615
|
-
}
|
|
2616
|
-
else if (wf.primary.provider === 'claude' && claudeTransport === 'native' && typeof outcome.lastPromptTokens === 'number') {
|
|
2617
|
-
// Native Claude has no session JSONL to read. The worker's settled
|
|
2618
|
-
// outcome carries the last round's prompt size — convert to a fresh
|
|
2619
|
-
// ground-truth context_usage and fan out via broadcastTransient
|
|
2620
|
-
// (consistent with the CLI path: primary_complete already persists
|
|
2621
|
-
// lastPromptTokens, so context_usage stays derived/transient).
|
|
2622
|
-
const est = wf.config.voiceOperator && outcome.modelContextWindow
|
|
2623
|
-
? promptContextEstimate(outcome.lastPromptTokens, outcome.modelContextWindow, Date.now())
|
|
2624
|
-
: nativeContextEstimate(wf.primary.model, outcome.lastPromptTokens, Date.now());
|
|
2625
|
-
if (est) {
|
|
2626
|
-
wf.lastContextPercent = est.percentOfWindow;
|
|
2627
|
-
broadcastTransient(workflowId, {
|
|
2628
|
-
type: 'context_usage',
|
|
2629
|
-
workflowId,
|
|
2630
|
-
...est,
|
|
2631
|
-
});
|
|
2805
|
+
else if (wf.primary.provider === 'ollama' && typeof outcome.lastPromptTokens === 'number') {
|
|
2806
|
+
// M6 — Ollama has no session JSONL. The worker's settled outcome carries
|
|
2807
|
+
// the LAST turn's prompt_eval_count (ground truth: the exact prompt the
|
|
2808
|
+
// daemon saw on its final call) plus the per-backend probed num_ctx the
|
|
2809
|
+
// request actually used (M3/M4: the window is per-host, so the
|
|
2810
|
+
// denominator must be the host that produced this answer, not a static
|
|
2811
|
+
// map). Build the same-shaped context_usage the CTX bar already renders
|
|
2812
|
+
// for every other provider; fall back to Ollama's 2048 default only when
|
|
2813
|
+
// nothing was probed. Transient (broadcastTransient): primary_complete
|
|
2814
|
+
// already persisted lastPromptTokens + modelContextWindow, so this stays
|
|
2815
|
+
// derived. M8 reads context_usage.percentOfWindow as its compaction gate.
|
|
2816
|
+
const est = ollamaContextUsage(outcome.lastPromptTokens, outcome.modelContextWindow, Date.now());
|
|
2817
|
+
if (est) {
|
|
2818
|
+
wf.lastContextPercent = est.percentOfWindow;
|
|
2819
|
+
broadcastTransient(workflowId, {
|
|
2820
|
+
type: 'context_usage',
|
|
2821
|
+
workflowId,
|
|
2822
|
+
...est,
|
|
2823
|
+
});
|
|
2824
|
+
}
|
|
2632
2825
|
}
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
const reserved = chooseMaxTokens(wf.primary.model, wf.primary.effort ?? 'high');
|
|
2642
|
-
const budget = computeContextBudget(outcome.lastPromptTokens, win, reserved);
|
|
2643
|
-
wf.lastContextBudgetPct = budget.pct;
|
|
2644
|
-
const thresholds = {
|
|
2645
|
-
warnAt: wf.autoHandoff.warnAt,
|
|
2646
|
-
autoAt: wf.autoHandoff.autoAt,
|
|
2647
|
-
...(typeof wf.autoFold?.foldAt === 'number' ? { foldAt: wf.autoFold.foldAt } : {}),
|
|
2648
|
-
};
|
|
2649
|
-
broadcastTransient(workflowId, {
|
|
2650
|
-
type: 'context_budget',
|
|
2651
|
-
workflowId,
|
|
2652
|
-
usedTokens: budget.usedTokens,
|
|
2653
|
-
windowSize: budget.windowSize,
|
|
2654
|
-
reservedOutput: budget.reservedOutput,
|
|
2655
|
-
effectiveWindow: budget.effectiveWindow,
|
|
2656
|
-
pct: budget.pct,
|
|
2657
|
-
thresholds,
|
|
2658
|
-
crossed: crossedThresholds(budget.pct, thresholds),
|
|
2659
|
-
});
|
|
2826
|
+
else if ((wf.primary.provider === 'strata' || wf.primary.provider === 'deepseek') && typeof outcome.lastPromptTokens === 'number' && outcome.modelContextWindow) {
|
|
2827
|
+
// Use Strata's discovered window and the final call's actual prompt;
|
|
2828
|
+
// never count summed tool-loop input as context occupancy.
|
|
2829
|
+
const est = promptContextEstimate(outcome.lastPromptTokens, outcome.modelContextWindow, Date.now());
|
|
2830
|
+
if (est) {
|
|
2831
|
+
wf.lastContextPercent = est.percentOfWindow;
|
|
2832
|
+
broadcastTransient(workflowId, { type: 'context_usage', workflowId, ...est });
|
|
2833
|
+
}
|
|
2660
2834
|
}
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
// map). Build the same-shaped context_usage the CTX bar already renders
|
|
2669
|
-
// for every other provider; fall back to Ollama's 2048 default only when
|
|
2670
|
-
// nothing was probed. Transient (broadcastTransient): primary_complete
|
|
2671
|
-
// already persisted lastPromptTokens + modelContextWindow, so this stays
|
|
2672
|
-
// derived. M8 reads context_usage.percentOfWindow as its compaction gate.
|
|
2673
|
-
const est = ollamaContextUsage(outcome.lastPromptTokens, outcome.modelContextWindow, Date.now());
|
|
2674
|
-
if (est) {
|
|
2675
|
-
wf.lastContextPercent = est.percentOfWindow;
|
|
2676
|
-
broadcastTransient(workflowId, {
|
|
2677
|
-
type: 'context_usage',
|
|
2678
|
-
workflowId,
|
|
2679
|
-
...est,
|
|
2680
|
-
});
|
|
2835
|
+
else if (incognito && wf.config.voiceOperator && wf.primary.provider === 'codex'
|
|
2836
|
+
&& typeof outcome.lastPromptTokens === 'number' && outcome.modelContextWindow) {
|
|
2837
|
+
const est = promptContextEstimate(outcome.lastPromptTokens, outcome.modelContextWindow, Date.now());
|
|
2838
|
+
if (est) {
|
|
2839
|
+
wf.lastContextPercent = est.percentOfWindow;
|
|
2840
|
+
broadcastTransient(workflowId, { type: 'context_usage', workflowId, ...est });
|
|
2841
|
+
}
|
|
2681
2842
|
}
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
wf.lastContextPercent = est.percentOfWindow;
|
|
2689
|
-
broadcastTransient(workflowId, { type: 'context_usage', workflowId, ...est });
|
|
2843
|
+
// This policy uses only this settled turn's own measurement, never the
|
|
2844
|
+
// rollout fallback or a previous turn's display snapshot.
|
|
2845
|
+
if (wf.primary.provider === policyTurnProvider) {
|
|
2846
|
+
const percent = freshAutoCompactionPercent(policyTurnProvider, policyTurnProvider === 'claude' ? claudeTransport : codexTransport, outcome);
|
|
2847
|
+
if (percent !== undefined)
|
|
2848
|
+
policyReading = { percent, sessionId: wf.primarySessionId, provider: policyTurnProvider, transport: policyTurnProvider === 'claude' ? claudeTransport : codexTransport };
|
|
2690
2849
|
}
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2850
|
+
// Codex app-server equivalent — provider turn usage can be the SUM across all
|
|
2851
|
+
// internal LLM calls within this operator turn. That's right for billing
|
|
2852
|
+
// but wrong for context-window-fill display; the live context is the LAST
|
|
2853
|
+
// call's prompt. Await this best-effort rollout read before threshold
|
|
2854
|
+
// checks so auto-handoff never fires from the previous turn's percentage.
|
|
2855
|
+
if ((wf.primary.provider === 'codex') && wf.primarySessionId) {
|
|
2856
|
+
await refreshCodexTokenSnapshot(workflowId, wf, providerAccount?.codexHome);
|
|
2698
2857
|
}
|
|
2858
|
+
// Drain the whole queue at once as a single merged follow-up turn.
|
|
2859
|
+
// Operators typically stack queued messages as a cumulative thought
|
|
2860
|
+
// ("oh and also…", "I forgot to mention…") and want one integrated
|
|
2861
|
+
// reply, not N sequential turns each answering a partial thought.
|
|
2862
|
+
// Messages join with `\n\n` (blank line between, reads as paragraphs
|
|
2863
|
+
// of one prompt), attachments concat across all drained items.
|
|
2864
|
+
// `cancel` clears the queue, so STOP during the merge drops the
|
|
2865
|
+
// whole batch before it fires.
|
|
2866
|
+
//
|
|
2867
|
+
// Phase 4 — order is steering first, then follow-up. Steer is "do this
|
|
2868
|
+
// now / change direction"; follow-up is "after the current task lands."
|
|
2869
|
+
// Interrupt entries get their own next turn; remaining steers and
|
|
2870
|
+
// follow-ups stay queued until that correction has completed.
|
|
2871
|
+
// Cancelled (and possibly superseded by a resend) while settling: the
|
|
2872
|
+
// queue belongs to whoever holds busy now — don't drain it.
|
|
2873
|
+
if (!ownsBusy(wf, busyToken))
|
|
2874
|
+
break;
|
|
2875
|
+
if (wf.queue.steering.length === 0 && wf.queue.followUp.length === 0)
|
|
2876
|
+
break;
|
|
2877
|
+
loadQueuedPrompt(carryInterruptedPrompt);
|
|
2699
2878
|
}
|
|
2700
|
-
|
|
2701
|
-
// rollout fallback or a previous turn's display snapshot.
|
|
2702
|
-
if (wf.primary.provider === policyTurnProvider) {
|
|
2703
|
-
const percent = freshAutoCompactionPercent(policyTurnProvider, policyTurnProvider === 'claude' ? claudeTransport : codexTransport, outcome);
|
|
2704
|
-
if (percent !== undefined)
|
|
2705
|
-
policyReading = { percent, sessionId: wf.primarySessionId, provider: policyTurnProvider, transport: policyTurnProvider === 'claude' ? claudeTransport : codexTransport };
|
|
2706
|
-
}
|
|
2707
|
-
// Codex app-server equivalent — provider turn usage can be the SUM across all
|
|
2708
|
-
// internal LLM calls within this operator turn. That's right for billing
|
|
2709
|
-
// but wrong for context-window-fill display; the live context is the LAST
|
|
2710
|
-
// call's prompt. Await this best-effort rollout read before threshold
|
|
2711
|
-
// checks so auto-handoff never fires from the previous turn's percentage.
|
|
2712
|
-
if ((wf.primary.provider === 'codex') && wf.primarySessionId) {
|
|
2713
|
-
await refreshCodexTokenSnapshot(workflowId, wf, providerAccount?.codexHome);
|
|
2714
|
-
}
|
|
2715
|
-
// Drain the whole queue at once as a single merged follow-up turn.
|
|
2716
|
-
// Operators typically stack queued messages as a cumulative thought
|
|
2717
|
-
// ("oh and also…", "I forgot to mention…") and want one integrated
|
|
2718
|
-
// reply, not N sequential turns each answering a partial thought.
|
|
2719
|
-
// Messages join with `\n\n` (blank line between, reads as paragraphs
|
|
2720
|
-
// of one prompt), attachments concat across all drained items.
|
|
2721
|
-
// `cancel` clears the queue, so STOP during the merge drops the
|
|
2722
|
-
// whole batch before it fires.
|
|
2723
|
-
//
|
|
2724
|
-
// Phase 4 — order is steering first, then follow-up. Steer is "do this
|
|
2725
|
-
// now / change direction"; follow-up is "after the current task lands."
|
|
2726
|
-
// Interrupt entries get their own next turn; remaining steers and
|
|
2727
|
-
// follow-ups stay queued until that correction has completed.
|
|
2728
|
-
// Cancelled (and possibly superseded by a resend) while settling: the
|
|
2729
|
-
// queue belongs to whoever holds busy now — don't drain it.
|
|
2730
|
-
if (!ownsBusy(wf, busyToken))
|
|
2731
|
-
break;
|
|
2732
|
-
if (wf.queue.steering.length === 0 && wf.queue.followUp.length === 0)
|
|
2733
|
-
break;
|
|
2734
|
-
loadQueuedPrompt(carryInterruptedPrompt);
|
|
2879
|
+
watchLoopFinished = true;
|
|
2735
2880
|
}
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
broadcastQueueUpdate(workflowId);
|
|
2881
|
+
finally {
|
|
2882
|
+
activeTurnObservation?.stop();
|
|
2883
|
+
if (wf.primaryTurn === primaryTurn)
|
|
2884
|
+
wf.primaryTurn = undefined;
|
|
2885
|
+
// Only the owning claim may release busy / touch the queue. A loop whose
|
|
2886
|
+
// claim STOP revoked exits quietly — STOP + quick resend used to let turn
|
|
2887
|
+
// 1's finally clear turn 2's busy flag (and drain/clear turn 2's queue).
|
|
2888
|
+
staleLoop = !releaseBusy(wf, busyToken, watchLoopFinished && !watchHadError ? 'finished' : 'failed');
|
|
2889
|
+
if (!staleLoop) {
|
|
2890
|
+
// The provider's `primary_turn_ended` broadcast already fired before
|
|
2891
|
+
// this finally runs (it's queued from the settled.then() microtask in
|
|
2892
|
+
// seedWorker which awaits the same promise the turn loop does — the
|
|
2893
|
+
// provider's .then attaches first, so it runs first). At that moment
|
|
2894
|
+
// wf.busy was still `true`, so the cluster_state push triggered by
|
|
2895
|
+
// CLUSTER_STATE_TRIGGERS read `busy` and reported the member as still
|
|
2896
|
+
// busy. Re-notify here so the cluster tab dot + per-card status
|
|
2897
|
+
// actually drop when the worker becomes idle. Without this the
|
|
2898
|
+
// cluster-level indicators stay lit until the next unrelated event.
|
|
2899
|
+
void notifyClusterStateForWorkflow(workflowId);
|
|
2900
|
+
// Defensive: the drain loop above already empties both arrays on each
|
|
2901
|
+
// iteration. This catches the case where the loop exited via throw —
|
|
2902
|
+
// we don't want the next turn to inherit half-drained state.
|
|
2903
|
+
if (!preserveQueue && (wf.queue.steering.length > 0 || wf.queue.followUp.length > 0)) {
|
|
2904
|
+
wf.queue.steering.length = 0;
|
|
2905
|
+
wf.queue.followUp.length = 0;
|
|
2906
|
+
broadcastQueueUpdate(workflowId);
|
|
2907
|
+
}
|
|
2764
2908
|
}
|
|
2765
2909
|
}
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
}
|
|
2777
|
-
return;
|
|
2778
|
-
}
|
|
2779
|
-
if (preserveQueue)
|
|
2780
|
-
return;
|
|
2781
|
-
// Computer rotates only after the complete tool/queue turn has settled.
|
|
2782
|
-
await maybeFreshComputerContext(workflowId, !lastTurnErrored);
|
|
2783
|
-
await announceComputerSettled(workflowId);
|
|
2784
|
-
// Phase 2 calibration — run after the full drain queue empties (idle moment).
|
|
2785
|
-
// Updates per-session ratio/overhead from ground-truth /context output.
|
|
2786
|
-
await maybeCalibrate(workflowId, wf, cwd);
|
|
2787
|
-
// §2.1 — auto-fold runs FIRST (foldAt sits below the handoff thresholds): the
|
|
2788
|
-
// cheap deterministic in-place Fold is tried before recommending a handoff. A
|
|
2789
|
-
// successful fold reseeds the session, so skip the (now-stale) handoff check
|
|
2790
|
-
// this round — the next turn's meter re-evaluates against the reduced context.
|
|
2791
|
-
const clusterIdForPolicy = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
2792
|
-
const explicitPolicy = resolveProviderAutoCompaction(wf.config.autoCompaction, clusterIdForPolicy ? clusterStore.getAutoCompaction(clusterIdForPolicy) : undefined, wf.primary.provider, claudeTransport, wf.config.claudeNativeCompact === true, cascade?.ollama?.compaction?.enabled !== undefined || cascade?.ollama?.compaction?.threshold !== undefined);
|
|
2793
|
-
if (explicitPolicy) {
|
|
2794
|
-
const action = await runExplicitContextActions(workflowId, wf, cwd, explicitPolicy, policyReading, busyToken, ws, session);
|
|
2795
|
-
if (action === 'stale')
|
|
2796
|
-
return;
|
|
2797
|
-
if (action === 'compact-attempted') {
|
|
2798
|
-
await drainQueueIfIdle(workflowId);
|
|
2910
|
+
// Stale loop: STOP already disarmed the goal run and owns the teardown; the
|
|
2911
|
+
// post-settle armed actions belong to whoever holds the tab now.
|
|
2912
|
+
if (staleLoop) {
|
|
2913
|
+
// A requested Computer reset still needs a boundary after STOP's
|
|
2914
|
+
// interrupt actually settles. A newer busy owner keeps it deferred.
|
|
2915
|
+
if (wf.config.voiceOperator) {
|
|
2916
|
+
await maybeFreshComputerContext(workflowId, false);
|
|
2917
|
+
await drainQueueIfIdle(workflowId);
|
|
2918
|
+
await announceComputerSettled(workflowId);
|
|
2919
|
+
}
|
|
2799
2920
|
return;
|
|
2800
2921
|
}
|
|
2922
|
+
if (preserveQueue)
|
|
2923
|
+
return;
|
|
2924
|
+
// afterTurn.ts — the post-settle steps in their fixed order.
|
|
2925
|
+
await runAfterTurn({
|
|
2926
|
+
// Computer rotates only after the complete tool/queue turn has settled.
|
|
2927
|
+
computer: async () => {
|
|
2928
|
+
await maybeFreshComputerContext(workflowId, !lastTurnErrored);
|
|
2929
|
+
await announceComputerSettled(workflowId);
|
|
2930
|
+
},
|
|
2931
|
+
// Phase 2 calibration: per-session ratio/overhead from ground-truth /context output.
|
|
2932
|
+
calibrate: () => maybeCalibrate(workflowId, wf, cwd),
|
|
2933
|
+
// A due auto-handoff (N compactions this conversation) runs first and
|
|
2934
|
+
// replaces any fold or compaction of this boundary; otherwise the cheap
|
|
2935
|
+
// deterministic Fold, then the auto-compaction policy.
|
|
2936
|
+
context: async () => {
|
|
2937
|
+
const clusterIdForPolicy = clusterStore.getClusterIdForWorkflow(workflowId);
|
|
2938
|
+
const explicitPolicy = resolveProviderAutoCompaction(wf.config.autoCompaction, clusterIdForPolicy ? clusterStore.getAutoCompaction(clusterIdForPolicy) : undefined, wf.primary.provider, claudeTransport, wf.config.claudeNativeCompact === true, cascade?.ollama?.compaction?.enabled !== undefined || cascade?.ollama?.compaction?.threshold !== undefined);
|
|
2939
|
+
if (explicitPolicy) {
|
|
2940
|
+
const action = await runExplicitContextActions(workflowId, wf, cwd, explicitPolicy, policyReading, busyToken, ws, session);
|
|
2941
|
+
if (action === 'stale')
|
|
2942
|
+
return 'stop';
|
|
2943
|
+
if (action === 'compact-attempted') {
|
|
2944
|
+
await drainQueueIfIdle(workflowId);
|
|
2945
|
+
return 'stop';
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
else {
|
|
2949
|
+
// Work without an explicit policy: a due auto-handoff first, else
|
|
2950
|
+
// the cheap fold. Provider-owned compaction remains with the provider.
|
|
2951
|
+
if (!(await maybeAutoHandoff(workflowId, wf, cwd)))
|
|
2952
|
+
await maybeAutoFold(workflowId, wf, cwd);
|
|
2953
|
+
}
|
|
2954
|
+
return 'continue';
|
|
2955
|
+
},
|
|
2956
|
+
// Messages typed while auto-fold / auto-handoff held the tab are still
|
|
2957
|
+
// queued; that turn runs its own post-settle chain (goal run included).
|
|
2958
|
+
drainQueue: () => drainQueueIfIdle(workflowId),
|
|
2959
|
+
// docs/GOTCHAS.md - north-star auto-continue, last on purpose: fold,
|
|
2960
|
+
// handoff and compaction all reshape the context this tick would run against.
|
|
2961
|
+
goalRun: () => maybeGoalRun(workflowId, wf, ws, session, lastTurnErrored),
|
|
2962
|
+
});
|
|
2801
2963
|
}
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2964
|
+
finally {
|
|
2965
|
+
const remaining = (incomingMessages.get(wf) ?? 1) - 1;
|
|
2966
|
+
if (remaining)
|
|
2967
|
+
incomingMessages.set(wf, remaining);
|
|
2968
|
+
else
|
|
2969
|
+
incomingMessages.delete(wf);
|
|
2808
2970
|
}
|
|
2809
|
-
// Messages typed while auto-fold / auto-handoff held the tab are still
|
|
2810
|
-
// queued. Flush them first; that turn runs its own post-settle chain (goal
|
|
2811
|
-
// run included), so this settle is done.
|
|
2812
|
-
if (await drainQueueIfIdle(workflowId))
|
|
2813
|
-
return;
|
|
2814
|
-
// docs/GOTCHAS.md - north-star auto-continue. Last of the post-settle armed
|
|
2815
|
-
// actions on purpose: fold / handoff / compaction all reshape the context
|
|
2816
|
-
// this tick would run against, so they get to act first.
|
|
2817
|
-
await maybeGoalRun(workflowId, wf, ws, session, lastTurnErrored);
|
|
2818
2971
|
}
|
|
2819
2972
|
// docs/GOTCHAS.md - one tick of an armed goal run. Every branch either
|
|
2820
2973
|
// dispatches exactly one visible turn or stops the run with an operator-
|