arco-workbench 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +63 -12
- package/README.md +21 -17
- package/client/dist/assets/{PhosphorBackdrop-DVQdBrTw.js → PhosphorBackdrop-DRu16-Is.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-BfSs2tB4.js → ThemedBackgroundShaderImpl-BLdwwQ4D.js} +1 -1
- package/client/dist/assets/{XtermView-DaMjC8Ny.js → XtermView-Xk7_9JaH.js} +1 -1
- package/client/dist/assets/{galleryEditor-BCQnXj7R.js → galleryEditor-CI8ClzBa.js} +1 -1
- package/client/dist/assets/{index-DD9kFGsF.css → index-BEFgrUJJ.css} +1 -1
- package/client/dist/assets/{index-COfbHCYv.js → index-C7WzZfsr.js} +257 -255
- package/client/dist/index.html +2 -2
- package/client/src/App.tsx +2 -0
- package/client/src/components/ChatMessage.tsx +33 -8
- package/client/src/components/ChatModeView.tsx +2 -0
- package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +65 -15
- package/client/src/components/ClusterRightPanel/SkillsControl.tsx +124 -0
- package/client/src/components/ClusterRightPanel/index.tsx +4 -0
- package/client/src/components/ClusterTaskBoardTab.tsx +9 -22
- package/client/src/components/CodexLateCommand.tsx +34 -0
- package/client/src/components/DialogShell.tsx +2 -0
- package/client/src/components/MemberCard.tsx +4 -1
- package/client/src/components/MemberPane.tsx +3 -1
- package/client/src/components/NeedsYouBadge.tsx +3 -3
- package/client/src/components/PhoneUpload.tsx +288 -0
- package/client/src/components/PrimaryStatus.tsx +14 -6
- package/client/src/components/ProviderReleasesModal.tsx +8 -4
- package/client/src/components/ProvidersPopover.tsx +28 -23
- package/client/src/components/RuntimeStateBanner.tsx +5 -0
- package/client/src/components/SettingsPanel.tsx +2 -2
- package/client/src/components/SkillEditorDialog.tsx +2 -2
- package/client/src/components/SkillsSettings.tsx +21 -4
- package/client/src/components/TabBar.tsx +91 -9
- package/client/src/components/TerminalInput.tsx +15 -11
- package/client/src/components/TranscriptSendDialog.tsx +12 -8
- package/client/src/components/TranscriptWorkerDialog.tsx +119 -0
- package/client/src/components/WorkflowView.tsx +2 -0
- package/client/src/components/clusterNeedsYou.ts +11 -18
- package/client/src/explorer/ArtifactsLens.tsx +37 -28
- package/client/src/explorer/ExplorerApp.tsx +5 -4
- package/client/src/explorer/types.ts +8 -3
- package/client/src/help/content/cluster.tsx +48 -17
- package/client/src/help/content/composer.tsx +40 -1
- package/client/src/help/content/header.tsx +18 -1
- package/client/src/help/content/misc.tsx +9 -1
- package/client/src/help/content/settings.tsx +18 -4
- package/client/src/help/content/tabbar.tsx +5 -0
- package/client/src/help/manualSections/actions.tsx +31 -0
- package/client/src/help/manualSections/clusters.tsx +44 -20
- package/client/src/help/manualSections/configuration.tsx +20 -0
- package/client/src/help/manualSections/gettingStarted.tsx +4 -4
- package/client/src/help/manualSections/maintenance.tsx +25 -6
- package/client/src/help/manualSections/powerFeatures.tsx +3 -2
- package/client/src/help/manualSections/providers.tsx +32 -8
- package/client/src/help/manualSections/troubleshooting.tsx +2 -1
- package/client/src/help/manualSections/workflows.tsx +12 -0
- package/client/src/help/manualSections/workspace.tsx +36 -0
- package/client/src/stores/appStore.ts +7 -0
- package/client/src/stores/appStore.types.ts +4 -0
- package/client/src/styles/global.css +109 -0
- package/client/src/utils/phoneTheme.ts +38 -0
- package/client/src/utils/phoneUploadApi.ts +10 -0
- package/client/src/utils/transcriptWorkerRequest.ts +24 -0
- package/client/src/ws/handleServerMessage.ts +31 -8
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/CLIENT.md +16 -9
- package/docs/FEATURES.md +13 -7
- package/docs/GETTING_STARTED.md +12 -6
- package/docs/GOTCHAS.md +2 -1
- package/docs/INDEX.md +1 -1
- package/docs/OPERATIONS.md +213 -52
- package/docs/PERSISTENCE.md +7 -2
- package/docs/PRIMITIVES.md +42 -0
- package/docs/PROTOCOL_CLUSTER.md +51 -4
- package/docs/PROTOCOL_PRIMITIVES.md +39 -0
- package/docs/PROVIDERS.md +84 -13
- package/docs/SETTINGS.md +29 -3
- package/docs/TASK_LEDGER.md +7 -15
- package/native/linux-x64/manifest.json +1 -1
- package/native/win32-x64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/clusterCoordination.d.ts +2 -0
- package/node_modules/@arco/shared/dist/clusterCoordination.js +5 -1
- package/node_modules/@arco/shared/dist/protocol/chat.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/clientMessages.d.ts +3 -2
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +15 -1
- package/node_modules/@arco/shared/dist/protocol/index.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/index.js +1 -0
- package/node_modules/@arco/shared/dist/protocol/models.d.ts +4 -3
- package/node_modules/@arco/shared/dist/protocol/models.js +26 -2
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +13 -1
- package/node_modules/@arco/shared/dist/protocol/tasks.d.ts +4 -0
- package/node_modules/@arco/shared/dist/protocol/transcriptWorker.d.ts +47 -0
- package/node_modules/@arco/shared/dist/protocol/transcriptWorker.js +2 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
- package/node_modules/@arco/shared/dist/runtimeVersions.d.ts +1 -0
- package/node_modules/@arco/shared/dist/runtimeVersions.js +14 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/scripts/packaging/arco.mjs +1 -1
- package/scripts/packaging/native-repair.mjs +32 -4
- package/server/dist/atomicFile.js +1 -2
- package/server/dist/capabilities.d.ts +5 -2
- package/server/dist/capabilities.js +59 -9
- package/server/dist/cliUpdateDecision.d.ts +1 -1
- package/server/dist/cliUpdateDecision.js +5 -3
- package/server/dist/clusterDirector.js +2 -1
- package/server/dist/clusterPeerOps.js +14 -8
- package/server/dist/clusterProgress.js +1 -1
- package/server/dist/clusterRehydrate.js +2 -0
- package/server/dist/clusterSkills.d.ts +13 -0
- package/server/dist/clusterSkills.js +81 -0
- package/server/dist/clusterSnapshots.js +2 -0
- package/server/dist/clusterStore.d.ts +7 -2
- package/server/dist/clusterStore.js +42 -1
- package/server/dist/diagnostics/codeSkew.js +1 -0
- package/server/dist/eventLog.d.ts +7 -0
- package/server/dist/eventLog.js +70 -13
- package/server/dist/explorerDocs.d.ts +10 -6
- package/server/dist/explorerDocs.js +75 -34
- package/server/dist/historyLimits.d.ts +1 -0
- package/server/dist/historyLimits.js +3 -0
- package/server/dist/http/attachmentUpload.d.ts +13 -0
- package/server/dist/http/attachmentUpload.js +38 -0
- package/server/dist/http/browserWorktrees.d.ts +23 -0
- package/server/dist/http/browserWorktrees.js +120 -0
- package/server/dist/http/phoneUploadDrafts.d.ts +13 -0
- package/server/dist/http/phoneUploadDrafts.js +125 -0
- package/server/dist/http/phoneUploadListener.d.ts +17 -0
- package/server/dist/http/phoneUploadListener.js +81 -0
- package/server/dist/http/phoneUploadNetwork.d.ts +9 -0
- package/server/dist/http/phoneUploadNetwork.js +106 -0
- package/server/dist/http/phoneUploadPage.d.ts +2 -0
- package/server/dist/http/phoneUploadPage.js +136 -0
- package/server/dist/http/phoneUploadRouteHistory.d.ts +4 -0
- package/server/dist/http/phoneUploadRouteHistory.js +72 -0
- package/server/dist/http/phoneUploadRoutes.d.ts +4 -0
- package/server/dist/http/phoneUploadRoutes.js +419 -0
- package/server/dist/http/phoneUploadTheme.d.ts +17 -0
- package/server/dist/http/phoneUploadTheme.js +96 -0
- package/server/dist/http/projectBinding.d.ts +1 -0
- package/server/dist/http/projectBinding.js +3 -2
- package/server/dist/http/readConfinement.js +5 -1
- package/server/dist/http/router.js +14 -25
- package/server/dist/http/writeConfinement.js +19 -2
- package/server/dist/index.js +24 -1
- package/server/dist/jsonlLines.d.ts +4 -0
- package/server/dist/jsonlLines.js +53 -0
- package/server/dist/management/identity.js +1 -0
- package/server/dist/mcp/clusterMcpTools.js +4 -4
- package/server/dist/primitives/seedWorker.d.ts +1 -0
- package/server/dist/primitives/seedWorker.js +2 -1
- package/server/dist/project/taskLedger.d.ts +4 -0
- package/server/dist/project/taskLedger.js +7 -4
- package/server/dist/providerConversation.d.ts +1 -0
- package/server/dist/providerConversation.js +17 -0
- package/server/dist/providers/claude-native/resumeSummary.d.ts +9 -0
- package/server/dist/providers/claude-native/resumeSummary.js +102 -49
- package/server/dist/providers/claude-native/worker.js +8 -4
- package/server/dist/providers/claude.js +2 -1
- package/server/dist/providers/clusterTaskToolDefinitions.js +4 -4
- package/server/dist/providers/codex-appserver/catalog.js +16 -1
- package/server/dist/providers/codex-appserver/heldCommands.d.ts +14 -0
- package/server/dist/providers/codex-appserver/heldCommands.js +54 -0
- package/server/dist/providers/codex-appserver/index.d.ts +52 -2
- package/server/dist/providers/codex-appserver/index.js +239 -21
- package/server/dist/providers/codex-appserver/lateCommands.d.ts +62 -0
- package/server/dist/providers/codex-appserver/lateCommands.js +195 -0
- package/server/dist/providers/codex-appserver/worker.d.ts +23 -1
- package/server/dist/providers/codex-appserver/worker.js +89 -20
- package/server/dist/providers/codex.js +2 -1
- package/server/dist/providers/codexCodeMode.d.ts +2 -1
- package/server/dist/providers/codexCodeMode.js +8 -3
- package/server/dist/providers/cursor/print.js +2 -1
- package/server/dist/providers/cursor/worker.js +2 -1
- package/server/dist/providers/llamacpp.js +17 -8
- package/server/dist/providers/ollamaRecovery.js +6 -6
- package/server/dist/providers/ollamaResilience.js +3 -3
- package/server/dist/providers/ollamaTokens.js +1 -1
- package/server/dist/quota.d.ts +0 -18
- package/server/dist/quota.js +0 -44
- package/server/dist/replacementHistory.d.ts +19 -0
- package/server/dist/replacementHistory.js +49 -0
- package/server/dist/server/broadcast.d.ts +2 -1
- package/server/dist/server/broadcast.js +1 -0
- package/server/dist/server/prompts.d.ts +1 -0
- package/server/dist/server/prompts.js +6 -1
- package/server/dist/sessionJsonl.d.ts +1 -1
- package/server/dist/sessionJsonl.js +115 -40
- package/server/dist/smartPickupAdapters.js +15 -2
- package/server/dist/transcriptWorker.d.ts +34 -0
- package/server/dist/transcriptWorker.js +201 -0
- package/server/dist/workers/WorkerManager.d.ts +1 -0
- package/server/dist/workers/WorkerManager.js +1 -0
- package/server/dist/workers/processKill.d.ts +9 -1
- package/server/dist/workers/processKill.js +26 -10
- package/server/dist/workflowStore.d.ts +1 -0
- package/server/dist/workflowStore.js +31 -0
- package/server/dist/ws/clusterHandlers.d.ts +1 -0
- package/server/dist/ws/clusterHandlers.js +62 -26
- package/server/dist/ws/handoffHandlers.js +7 -2
- package/server/dist/ws/transcriptWorkerHandlers.d.ts +25 -0
- package/server/dist/ws/transcriptWorkerHandlers.js +139 -0
- package/server/dist/ws/turnEngine.js +40 -9
- package/server/dist/ws/updatePrimaryConfig.js +27 -8
- package/server/dist/ws/workflowHandlers.d.ts +4 -1
- package/server/dist/ws/workflowHandlers.js +3 -1
- package/server/package.json +1 -1
- package/server/src/atomicFile.ts +1 -2
- package/server/src/capabilities.ts +58 -17
- package/server/src/cliUpdateDecision.ts +5 -4
- package/server/src/clusterDirector.ts +2 -1
- package/server/src/clusterPeerOps.ts +15 -9
- package/server/src/clusterProgress.ts +1 -1
- package/server/src/clusterRehydrate.ts +2 -0
- package/server/src/clusterSkills.ts +79 -0
- package/server/src/clusterSnapshots.ts +1 -0
- package/server/src/clusterStore.ts +38 -0
- package/server/src/diagnostics/codeSkew.ts +1 -0
- package/server/src/eventLog.ts +73 -13
- package/server/src/explorerDocs.ts +75 -34
- package/server/src/historyLimits.ts +2 -0
- package/server/src/http/attachmentUpload.ts +49 -0
- package/server/src/http/browserWorktrees.ts +124 -0
- package/server/src/http/phoneUploadDrafts.ts +118 -0
- package/server/src/http/phoneUploadListener.ts +96 -0
- package/server/src/http/phoneUploadNetwork.ts +117 -0
- package/server/src/http/phoneUploadPage.ts +137 -0
- package/server/src/http/phoneUploadRouteHistory.ts +73 -0
- package/server/src/http/phoneUploadRoutes.ts +398 -0
- package/server/src/http/phoneUploadTheme.ts +97 -0
- package/server/src/http/projectBinding.ts +3 -2
- package/server/src/http/readConfinement.ts +5 -1
- package/server/src/http/router.ts +12 -26
- package/server/src/http/writeConfinement.ts +13 -2
- package/server/src/index.ts +23 -0
- package/server/src/jsonlLines.ts +52 -0
- package/server/src/management/identity.ts +1 -0
- package/server/src/mcp/clusterMcpTools.ts +4 -4
- package/server/src/primitives/seedWorker.ts +3 -1
- package/server/src/project/taskLedger.ts +7 -5
- package/server/src/providerConversation.ts +15 -0
- package/server/src/providers/claude-native/resumeSummary.ts +98 -50
- package/server/src/providers/claude-native/worker.ts +8 -4
- package/server/src/providers/claude.ts +2 -1
- package/server/src/providers/clusterTaskToolDefinitions.ts +4 -4
- package/server/src/providers/codex-appserver/catalog.ts +14 -1
- package/server/src/providers/codex-appserver/heldCommands.ts +58 -0
- package/server/src/providers/codex-appserver/index.ts +222 -20
- package/server/src/providers/codex-appserver/lateCommands.ts +225 -0
- package/server/src/providers/codex-appserver/worker.ts +85 -21
- package/server/src/providers/codex.ts +2 -1
- package/server/src/providers/codexCodeMode.ts +9 -4
- package/server/src/providers/cursor/print.ts +2 -1
- package/server/src/providers/cursor/worker.ts +2 -1
- package/server/src/providers/llamacpp.ts +18 -7
- package/server/src/providers/llamacppRecovery.ts +2 -0
- package/server/src/providers/ollamaRecovery.ts +6 -6
- package/server/src/providers/ollamaResilience.ts +3 -3
- package/server/src/providers/ollamaTokens.ts +1 -1
- package/server/src/providers/ollamaToolSubset.ts +3 -3
- package/server/src/quota.ts +0 -50
- package/server/src/replacementHistory.ts +44 -0
- package/server/src/server/broadcast.ts +2 -0
- package/server/src/server/prompts.ts +8 -1
- package/server/src/sessionJsonl.ts +92 -32
- package/server/src/smartPickupAdapters.ts +17 -3
- package/server/src/transcriptWorker.ts +182 -0
- package/server/src/workers/WorkerManager.ts +2 -0
- package/server/src/workers/processKill.ts +35 -7
- package/server/src/workflowStore.ts +21 -0
- package/server/src/ws/clusterHandlers.ts +43 -25
- package/server/src/ws/handoffHandlers.ts +7 -1
- package/server/src/ws/transcriptWorkerHandlers.ts +126 -0
- package/server/src/ws/turnEngine.ts +35 -8
- package/server/src/ws/updatePrimaryConfig.ts +25 -6
- package/server/src/ws/workflowHandlers.ts +3 -1
- package/shared/dist/clusterCoordination.d.ts +2 -0
- package/shared/dist/clusterCoordination.js +5 -1
- package/shared/dist/protocol/chat.d.ts +1 -0
- package/shared/dist/protocol/clientMessages.d.ts +3 -2
- package/shared/dist/protocol/clusters.d.ts +15 -1
- package/shared/dist/protocol/index.d.ts +1 -0
- package/shared/dist/protocol/index.js +1 -0
- package/shared/dist/protocol/models.d.ts +4 -3
- package/shared/dist/protocol/models.js +26 -2
- package/shared/dist/protocol/serverMessages.d.ts +13 -1
- package/shared/dist/protocol/tasks.d.ts +4 -0
- package/shared/dist/protocol/transcriptWorker.d.ts +47 -0
- package/shared/dist/protocol/transcriptWorker.js +2 -0
- package/shared/dist/protocol/workflows.d.ts +1 -0
- package/shared/dist/runtimeVersions.d.ts +1 -0
- package/shared/dist/runtimeVersions.js +14 -0
- package/shared/src/clusterCoordination.ts +7 -1
- package/shared/src/protocol/chat.ts +1 -0
- package/shared/src/protocol/clientMessages.ts +5 -0
- package/shared/src/protocol/clusters.ts +20 -6
- package/shared/src/protocol/index.ts +1 -0
- package/shared/src/protocol/models.ts +31 -5
- package/shared/src/protocol/serverMessages.ts +13 -0
- package/shared/src/protocol/settings.ts +2 -3
- package/shared/src/protocol/tasks.ts +4 -7
- package/shared/src/protocol/transcriptWorker.ts +49 -0
- package/shared/src/protocol/workflows.ts +4 -0
- package/shared/src/runtimeVersions.ts +14 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexLateCommands, type HeldCommandResult } from './lateCommands.js';
|
|
1
2
|
import { historyBinding } from '../handoffHistoryBinding.js';
|
|
2
3
|
import { codexWebSearchMode } from '../codexWebSearch.js';
|
|
3
4
|
import { codexImageToolConfig } from '../codexImageTool.js';
|
|
@@ -52,6 +53,7 @@ import type { TurnInterruptParams } from './bindings/v2/TurnInterruptParams.js';
|
|
|
52
53
|
import type { TurnSteerParams } from './bindings/v2/TurnSteerParams.js';
|
|
53
54
|
import type { TurnSteerResponse } from './bindings/v2/TurnSteerResponse.js';
|
|
54
55
|
import type { ThreadStartedNotification } from './bindings/v2/ThreadStartedNotification.js';
|
|
56
|
+
import type { ThreadClosedNotification } from './bindings/v2/ThreadClosedNotification.js';
|
|
55
57
|
import type { TurnStartedNotification } from './bindings/v2/TurnStartedNotification.js';
|
|
56
58
|
import type { TurnCompletedNotification } from './bindings/v2/TurnCompletedNotification.js';
|
|
57
59
|
import type { ItemStartedNotification } from './bindings/v2/ItemStartedNotification.js';
|
|
@@ -355,6 +357,9 @@ interface CurrentTurnState {
|
|
|
355
357
|
// wall of text ("…release process.Kernel.org confirms…"). We insert a
|
|
356
358
|
// paragraph break when the item id changes. Null until the first delta.
|
|
357
359
|
lastAgentMsgItemId: string | null;
|
|
360
|
+
// The agent's final answer has started: a command that ends after this
|
|
361
|
+
// point was never seen by the model.
|
|
362
|
+
finalAnswerStarted: boolean;
|
|
358
363
|
artifacts: Set<Promise<void>>;
|
|
359
364
|
settling: boolean;
|
|
360
365
|
}
|
|
@@ -372,6 +377,7 @@ function emptyTurnState(): CurrentTurnState {
|
|
|
372
377
|
transientNoticeKey: null,
|
|
373
378
|
transientNoticeCount: 0,
|
|
374
379
|
lastAgentMsgItemId: null,
|
|
380
|
+
finalAnswerStarted: false,
|
|
375
381
|
artifacts: new Set(),
|
|
376
382
|
settling: false,
|
|
377
383
|
};
|
|
@@ -676,7 +682,7 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
676
682
|
// element. Empty prompt + image-only payload is a valid request shape now
|
|
677
683
|
// that images are first-class — no more "Please inspect the attached
|
|
678
684
|
// image(s)." synthetic fallback.
|
|
679
|
-
async beginTurn(prompt: string, appendSystemPrompt: string | undefined): Promise<void> {
|
|
685
|
+
async beginTurn(prompt: string, appendSystemPrompt: string | undefined, options: { continuation?: boolean } = {}): Promise<void> {
|
|
680
686
|
if (this.disposed) throw new Error('codex app-server worker disposed');
|
|
681
687
|
if (!this.rpc || !this.threadId) {
|
|
682
688
|
throw new Error('codex app-server worker not bootstrapped');
|
|
@@ -689,7 +695,8 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
689
695
|
}
|
|
690
696
|
|
|
691
697
|
const preparationGeneration = this.preparationGeneration;
|
|
692
|
-
|
|
698
|
+
// A continuation carries command results, never the operator's files again.
|
|
699
|
+
const prepared = await prepareProviderAttachments(options.continuation ? undefined : this.config.attachments, true, undefined, false, this.config.interactionMode === 'chat' && !this.config.voiceOperator);
|
|
693
700
|
if (preparationGeneration !== this.preparationGeneration) throw new Error('Worker killed');
|
|
694
701
|
const modelImages = await persistProviderImages(prepared.images);
|
|
695
702
|
if (preparationGeneration !== this.preparationGeneration) throw new Error('Worker killed');
|
|
@@ -1055,6 +1062,68 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
1055
1062
|
|
|
1056
1063
|
// ── Notification handling ────────────────────────────────────────────
|
|
1057
1064
|
|
|
1065
|
+
private readonly lateCommands = new CodexLateCommands((event, state) => {
|
|
1066
|
+
this.emit('late_command', event, state);
|
|
1067
|
+
}, () => this.emit('held_commands'));
|
|
1068
|
+
|
|
1069
|
+
get runningLateCommands() { return this.lateCommands.snapshot(); }
|
|
1070
|
+
|
|
1071
|
+
// Commands the agent waits on after its Codex turn ended. The per-turn
|
|
1072
|
+
// wrapper holds the Arco turn open for them and delivers each result once.
|
|
1073
|
+
get heldCommands() { return this.lateCommands.running(); }
|
|
1074
|
+
hasHeldResults(): boolean { return this.lateCommands.hasResults(); }
|
|
1075
|
+
hasFailedHeldResult(): boolean { return this.lateCommands.hasFailedResult(); }
|
|
1076
|
+
takeHeldResults(): HeldCommandResult[] { return this.lateCommands.takeResults(); }
|
|
1077
|
+
restoreHeldResults(results: HeldCommandResult[]): void { this.lateCommands.restoreResults(results); }
|
|
1078
|
+
showHeldUntil(until: number): void { this.lateCommands.hold(until); }
|
|
1079
|
+
releaseHeldWait(): void { this.lateCommands.release(); }
|
|
1080
|
+
// Arco's text may join the running turn only before its final answer starts.
|
|
1081
|
+
get acceptsResultSteer(): boolean { return !!this.current.turnId && !this.current.finalAnswerStarted; }
|
|
1082
|
+
abandonHeldCommands(): void { this.lateCommands.abandon(); }
|
|
1083
|
+
|
|
1084
|
+
/** Add Arco's text to the running turn. False when no turn takes it. */
|
|
1085
|
+
async steerText(text: string): Promise<boolean> {
|
|
1086
|
+
const turn = this.current;
|
|
1087
|
+
if (!this.rpc || !this.threadId || !turn.turnId) return false;
|
|
1088
|
+
try {
|
|
1089
|
+
await this.rpc.request<TurnSteerResponse>('turn/steer', {
|
|
1090
|
+
threadId: this.threadId, input: buildSteerInput([{ content: text }]),
|
|
1091
|
+
responsesapiClientMetadata: null, expectedTurnId: turn.turnId,
|
|
1092
|
+
} satisfies TurnSteerParams);
|
|
1093
|
+
return true;
|
|
1094
|
+
} catch (err) {
|
|
1095
|
+
console.warn(`[appserver:${this.workflowId.slice(0, 8)}] command result steer failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1096
|
+
return false;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
private commandToolUse(item: Extract<ThreadItem, { type: 'commandExecution' }>, completed: boolean): ToolUseEvent {
|
|
1101
|
+
return {
|
|
1102
|
+
name: 'Bash',
|
|
1103
|
+
input: JSON.stringify({ command: item.command, cwd: item.cwd }),
|
|
1104
|
+
status: completed ? (item.exitCode === 0 ? 'completed' : 'failed') : 'started',
|
|
1105
|
+
provider: appServerProvider(this.config), itemType: 'command_execution', itemId: item.id,
|
|
1106
|
+
...(completed && item.aggregatedOutput != null ? { output: item.aggregatedOutput } : {}),
|
|
1107
|
+
...(completed && item.exitCode != null ? { exitCode: item.exitCode } : {}),
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
private handleCommandItem(p: ItemStartedNotification | ItemCompletedNotification, completed: boolean): boolean {
|
|
1112
|
+
if (p.item.type !== 'commandExecution') return false;
|
|
1113
|
+
if (p.threadId !== this.threadId || appServerProvider(this.config) !== 'codex') return false;
|
|
1114
|
+
const active = this.current.startedAt && (!this.current.turnId || p.turnId === this.current.turnId);
|
|
1115
|
+
const event = this.commandToolUse(p.item, completed);
|
|
1116
|
+
if (completed) {
|
|
1117
|
+
// One completion per command: one that ended after the agent's final
|
|
1118
|
+
// answer began is kept for after this turn; one from a turn that has
|
|
1119
|
+
// already completed belongs to the long-lived publisher.
|
|
1120
|
+
if (active && this.current.finalAnswerStarted) this.lateCommands.completeUnseen(p.turnId, event);
|
|
1121
|
+
else if (this.lateCommands.complete(p.turnId, event)) return true;
|
|
1122
|
+
} else if (active) this.lateCommands.start(p.turnId, event);
|
|
1123
|
+
if (active) this.emit('tool_use', event);
|
|
1124
|
+
return true;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1058
1127
|
private onNotification(n: JsonRpcNotification): void {
|
|
1059
1128
|
switch (n.method) {
|
|
1060
1129
|
case 'serverRequest/resolved': {
|
|
@@ -1062,6 +1131,12 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
1062
1131
|
if (p.threadId === this.threadId) this.operatorQuestions.resolvedRpc(p.requestId);
|
|
1063
1132
|
return;
|
|
1064
1133
|
}
|
|
1134
|
+
case 'thread/closed': {
|
|
1135
|
+
// Codex unloaded the thread and stopped its terminals: no held
|
|
1136
|
+
// command will report an end any more.
|
|
1137
|
+
if ((n.params as ThreadClosedNotification).threadId === this.threadId) this.lateCommands.disconnect();
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1065
1140
|
case 'thread/started': {
|
|
1066
1141
|
const p = n.params as ThreadStartedNotification;
|
|
1067
1142
|
this.threadId = p.thread.id;
|
|
@@ -1137,12 +1212,14 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
1137
1212
|
}
|
|
1138
1213
|
case 'item/started': {
|
|
1139
1214
|
const p = n.params as ItemStartedNotification;
|
|
1140
|
-
|
|
1215
|
+
if (p.item.type === 'agentMessage' && p.item.phase === 'final_answer' && p.threadId === this.threadId
|
|
1216
|
+
&& this.current.startedAt && (!this.current.turnId || p.turnId === this.current.turnId)) this.current.finalAnswerStarted = true;
|
|
1217
|
+
if (!this.handleCommandItem(p, false)) this.emitToolUseFromItem(p.item, 'started');
|
|
1141
1218
|
return;
|
|
1142
1219
|
}
|
|
1143
1220
|
case 'item/completed': {
|
|
1144
1221
|
const p = n.params as ItemCompletedNotification;
|
|
1145
|
-
this.emitToolUseFromItem(p.item, 'completed');
|
|
1222
|
+
if (!this.handleCommandItem(p, true)) this.emitToolUseFromItem(p.item, 'completed');
|
|
1146
1223
|
const asyncItem = p.item as ThreadItem & { delivery?: string; questions?: unknown };
|
|
1147
1224
|
if (asyncItem.type === 'agentMessage' && asyncItem.delivery === 'async' && p.threadId === this.threadId && this.current.startedAt && (!this.current.turnId || p.turnId === this.current.turnId)) {
|
|
1148
1225
|
try { this.operatorQuestions.acceptAsync(p.threadId, p.turnId, asyncItem); }
|
|
@@ -1254,24 +1331,9 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
1254
1331
|
// unchanged on appserver tabs.
|
|
1255
1332
|
const provider = appServerProvider(this.config);
|
|
1256
1333
|
switch (item.type) {
|
|
1257
|
-
case 'commandExecution':
|
|
1258
|
-
|
|
1259
|
-
const finalStatus: ToolUseEvent['status'] =
|
|
1260
|
-
completed ? (item.exitCode === 0 ? 'completed' : 'failed') : 'started';
|
|
1261
|
-
this.emit('tool_use', {
|
|
1262
|
-
name: 'Bash',
|
|
1263
|
-
input: JSON.stringify({ command: item.command, cwd: item.cwd }),
|
|
1264
|
-
status: finalStatus,
|
|
1265
|
-
provider,
|
|
1266
|
-
itemType: 'command_execution',
|
|
1267
|
-
itemId: item.id,
|
|
1268
|
-
...(completed && item.aggregatedOutput !== null
|
|
1269
|
-
? { output: item.aggregatedOutput }
|
|
1270
|
-
: {}),
|
|
1271
|
-
...(completed && item.exitCode !== null ? { exitCode: item.exitCode } : {}),
|
|
1272
|
-
});
|
|
1334
|
+
case 'commandExecution':
|
|
1335
|
+
this.emit('tool_use', this.commandToolUse(item, status === 'completed'));
|
|
1273
1336
|
return;
|
|
1274
|
-
}
|
|
1275
1337
|
case 'fileChange': {
|
|
1276
1338
|
const completed = status === 'completed';
|
|
1277
1339
|
const finalStatus: ToolUseEvent['status'] =
|
|
@@ -1640,6 +1702,7 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
1640
1702
|
this.emit('turn_settled', data);
|
|
1641
1703
|
return;
|
|
1642
1704
|
}
|
|
1705
|
+
if (this.current.turnId) this.lateCommands.settle(this.current.turnId);
|
|
1643
1706
|
this.current = emptyTurnState();
|
|
1644
1707
|
if (data.error && data.error !== 'Worker killed') {
|
|
1645
1708
|
// Also run the stderr fallback throttle sniffer in case the protocol
|
|
@@ -1663,6 +1726,7 @@ export class CodexAppServerWorker extends EventEmitter {
|
|
|
1663
1726
|
}
|
|
1664
1727
|
|
|
1665
1728
|
private teardownProcess(): void {
|
|
1729
|
+
this.lateCommands.disconnect();
|
|
1666
1730
|
this.operatorQuestions.cancel('The Codex connection closed.');
|
|
1667
1731
|
if (this.rpc) {
|
|
1668
1732
|
try { this.rpc.close('worker teardown'); } catch { /* ignore */ }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { codexTurnWaitInstructions } from './codexCodeMode.js';
|
|
1
2
|
import { prepareProviderHistory, historyBinding } from './handoffHistoryBinding.js';
|
|
2
3
|
import { prepareLocalFileContext, combineChatAttachments } from './localFileMedia.js';
|
|
3
4
|
import { codexChatOverrides, requireCodexChatCapabilities } from './codexChatBoundary.js';
|
|
@@ -111,7 +112,7 @@ class CodexWorkerProcess extends EventEmitter implements ProviderProcess {
|
|
|
111
112
|
// prefix cache like the rest of the framing. Covers operator turns AND
|
|
112
113
|
// primitive seeds (both carry config.goal). Absent / blank ⇒ no change.
|
|
113
114
|
// The output-style addendum closes the prefix, as on app-server.
|
|
114
|
-
const prefixParts = [goalBlock(this.config.goal), this.config.appendSystemPrompt, cliFileReadGuidance(this.config), outputStyleAddendum(this.config.outputStyle)]
|
|
115
|
+
const prefixParts = [codexTurnWaitInstructions(this.config.clusterRole), goalBlock(this.config.goal), this.config.appendSystemPrompt, cliFileReadGuidance(this.config), outputStyleAddendum(this.config.outputStyle)]
|
|
115
116
|
.filter((s): s is string => typeof s === 'string' && s.length > 0);
|
|
116
117
|
const prefixSp = prefixParts.length > 0 ? prefixParts.join('\n\n') : undefined;
|
|
117
118
|
const fullPrompt = prefixSp
|
|
@@ -13,6 +13,7 @@ import * as fs from 'node:fs';
|
|
|
13
13
|
import { resolveCodexHome } from './codexHome.js';
|
|
14
14
|
import * as path from 'node:path';
|
|
15
15
|
import type { WorkerConfig } from '@arco/shared';
|
|
16
|
+
import { AGENT_TURN_WAIT, buildTurnWaitInstructions, isClusterDirector } from '@arco/shared';
|
|
16
17
|
import { buildClusterDirectorDoctrine } from '../clusterDirector.js';
|
|
17
18
|
|
|
18
19
|
interface CodeModeEntry {
|
|
@@ -93,18 +94,22 @@ export function codexCodeModeClusterAddendum(): string {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
// Standing turn discipline for every Codex workflow (cluster and single).
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
const CODEX_COMMAND_WAIT = 'A command reply with a session ID and no exit code means it is still running. Poll that session until it exits before reporting, and do not end the turn saying you are waiting for it. Start a program meant to keep running, such as a server or a watcher, in the background with & or nohup, so Arco does not wait for it.';
|
|
98
|
+
export const CODEX_TURN_DISCIPLINE = AGENT_TURN_WAIT + ' ' + CODEX_COMMAND_WAIT;
|
|
99
|
+
|
|
100
|
+
export function codexTurnWaitInstructions(role: string | undefined): string {
|
|
101
|
+
return isClusterDirector(role) ? buildTurnWaitInstructions(role) : CODEX_TURN_DISCIPLINE;
|
|
102
|
+
}
|
|
98
103
|
|
|
99
104
|
// app-server can place Arco's durable cluster identity at developer level
|
|
100
105
|
// when a thread starts/resumes. Per-turn plan content still rides in user
|
|
101
106
|
// input because it is mutable; the stable role and tool contract do not need
|
|
102
107
|
// to compete with Codex's own `/root` developer framing there.
|
|
103
108
|
// Non-cluster threads still receive CODEX_TURN_DISCIPLINE so single workflows
|
|
104
|
-
//
|
|
109
|
+
// wait for the result their report depends on and check for messages between waits.
|
|
105
110
|
export function codexClusterDeveloperInstructions(config: WorkerConfig): string | null {
|
|
106
111
|
if (config.provider !== 'codex') return null;
|
|
107
|
-
const blocks: string[] = [
|
|
112
|
+
const blocks: string[] = [codexTurnWaitInstructions(config.clusterRole)];
|
|
108
113
|
if (config.clusterId) {
|
|
109
114
|
blocks.push(
|
|
110
115
|
'--- Arco cluster identity ---',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildTurnWaitInstructions } from '@arco/shared';
|
|
1
2
|
import { prepareProviderHistory, historyBinding } from '../handoffHistoryBinding.js';
|
|
2
3
|
import { prepareLocalFileContext, combineChatAttachments } from '../localFileMedia.js';
|
|
3
4
|
import { createChatSandbox, CHAT_FLAGS, CHAT_GUIDANCE } from './chatSandbox.js';
|
|
@@ -111,7 +112,7 @@ class CursorPrintProcess extends EventEmitter implements ProviderProcess {
|
|
|
111
112
|
// ACP worker's beginTurn. goalBlock is null-when-empty so the default primitive
|
|
112
113
|
// path is byte-identical to a bare prompt.
|
|
113
114
|
// The output-style addendum closes the prefix (null for normal).
|
|
114
|
-
const prefixParts = [chat ? CHAT_GUIDANCE : undefined, goalBlock(this.config.goal), this.config.appendSystemPrompt, this.filePlugin ? FILE_READ_GUIDANCE : undefined, outputStyleAddendum(this.config.outputStyle)]
|
|
115
|
+
const prefixParts = [buildTurnWaitInstructions(this.config.clusterRole), chat ? CHAT_GUIDANCE : undefined, goalBlock(this.config.goal), this.config.appendSystemPrompt, this.filePlugin ? FILE_READ_GUIDANCE : undefined, outputStyleAddendum(this.config.outputStyle)]
|
|
115
116
|
.filter((s): s is string => typeof s === 'string' && s.trim().length > 0);
|
|
116
117
|
const prefix = prefixParts.length > 0 ? prefixParts.join('\n\n') : undefined;
|
|
117
118
|
const body = [prompt, prepared?.text, chat ? undefined : withAttachmentRefs('', imagePaths)].filter(Boolean).join('\n\n');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildTurnWaitInstructions } from '@arco/shared';
|
|
1
2
|
import { historyBinding } from '../handoffHistoryBinding.js';
|
|
2
3
|
import { readFileContent } from '../../fileContent.js';
|
|
3
4
|
import { prepareProviderAttachments, FILE_READ_GUIDANCE } from '../providerFileContent.js';
|
|
@@ -383,7 +384,7 @@ export class CursorAcpWorker extends EventEmitter {
|
|
|
383
384
|
// above appendSystemPrompt, both above the `---` prompt separator. goalBlock is
|
|
384
385
|
// null-when-empty so the default path is byte-identical to pre-Phase-4.
|
|
385
386
|
// The output-style addendum closes the prefix (null for normal).
|
|
386
|
-
const prefixParts = [goalBlock(this.config.goal), appendSystemPrompt, this.clusterMcpDescriptor && this.config.cwd ? FILE_READ_GUIDANCE : undefined, outputStyleAddendum(this.config.outputStyle)]
|
|
387
|
+
const prefixParts = [buildTurnWaitInstructions(this.config.clusterRole), goalBlock(this.config.goal), appendSystemPrompt, this.clusterMcpDescriptor && this.config.cwd ? FILE_READ_GUIDANCE : undefined, outputStyleAddendum(this.config.outputStyle)]
|
|
387
388
|
.filter((s): s is string => typeof s === 'string' && s.trim().length > 0);
|
|
388
389
|
const prefix = prefixParts.length > 0 ? prefixParts.join('\n\n') : undefined;
|
|
389
390
|
// Operator attachments: images ride as ACP `image` content blocks when the
|
|
@@ -401,7 +401,7 @@ class LlamacppWorkerProcess extends EventEmitter implements ProviderProcess {
|
|
|
401
401
|
|
|
402
402
|
let res: Response;
|
|
403
403
|
try {
|
|
404
|
-
res = await requestWithDeadline(this.abortController!.signal,
|
|
404
|
+
res = await requestWithDeadline(this.abortController!.signal, Math.min(recovery.stallTimeoutMs, recovery.turnBudgetMs), (signal) => fetch(`${baseUrl}/v1/chat/completions`, {
|
|
405
405
|
method: 'POST',
|
|
406
406
|
headers: { 'Content-Type': 'application/json' },
|
|
407
407
|
body: JSON.stringify(body),
|
|
@@ -451,21 +451,23 @@ class LlamacppWorkerProcess extends EventEmitter implements ProviderProcess {
|
|
|
451
451
|
|
|
452
452
|
// Recovery-bounded stream read. Wraps reader.read() in a stall timeout
|
|
453
453
|
// and a per-iteration runaway check. Aborts the upstream call cleanly
|
|
454
|
-
// when either trips so the run loop can recover.
|
|
454
|
+
// when either trips so the run loop can recover. The time limits also
|
|
455
|
+
// apply with recovery off; that setting controls retries, not the bound.
|
|
455
456
|
const readWithGuards = async (): Promise<{ value?: Uint8Array; done: boolean }> => {
|
|
456
|
-
|
|
457
|
+
const remainingMs = recovery.turnBudgetMs - (Date.now() - turnStart);
|
|
458
|
+
const wallClockFirst = remainingMs <= recovery.stallTimeoutMs;
|
|
457
459
|
let stallTimer: NodeJS.Timeout | null = null;
|
|
458
460
|
try {
|
|
459
461
|
return await Promise.race([
|
|
460
462
|
reader.read(),
|
|
461
463
|
new Promise<{ value?: undefined; done: true }>((resolve) => {
|
|
462
464
|
stallTimer = setTimeout(() => {
|
|
463
|
-
interruption = 'stall';
|
|
465
|
+
interruption = wallClockFirst ? 'wall_clock' : 'stall';
|
|
464
466
|
// Cancel the underlying body reader so the next read() resolves
|
|
465
467
|
// with done:true; resolve our race so the outer loop exits.
|
|
466
468
|
reader.cancel().catch(() => { /* already gone */ });
|
|
467
469
|
resolve({ done: true });
|
|
468
|
-
}, recovery.stallTimeoutMs);
|
|
470
|
+
}, Math.max(0, Math.min(recovery.stallTimeoutMs, remainingMs)));
|
|
469
471
|
}),
|
|
470
472
|
]);
|
|
471
473
|
} finally {
|
|
@@ -489,7 +491,7 @@ class LlamacppWorkerProcess extends EventEmitter implements ProviderProcess {
|
|
|
489
491
|
// Catches the "tool_calls + reasoning + content pumping endlessly"
|
|
490
492
|
// mode that the runaway detector misses (model looks productive by
|
|
491
493
|
// every per-signal metric but isn't converging).
|
|
492
|
-
if (
|
|
494
|
+
if (Date.now() - turnStart >= recovery.turnBudgetMs) {
|
|
493
495
|
interruption = 'wall_clock';
|
|
494
496
|
reader.cancel().catch(() => { /* already gone */ });
|
|
495
497
|
break;
|
|
@@ -511,7 +513,7 @@ class LlamacppWorkerProcess extends EventEmitter implements ProviderProcess {
|
|
|
511
513
|
}
|
|
512
514
|
|
|
513
515
|
const { value, done } = await readWithGuards();
|
|
514
|
-
if (interruption
|
|
516
|
+
if (interruption) break;
|
|
515
517
|
if (done) {
|
|
516
518
|
streamEnded = true;
|
|
517
519
|
if (buf.trim().length === 0) break;
|
|
@@ -846,6 +848,15 @@ class LlamacppWorkerProcess extends EventEmitter implements ProviderProcess {
|
|
|
846
848
|
const turnResult = await this.streamOneTurn(baseUrl, def.alias, messages, tools, recovery);
|
|
847
849
|
if (turnResult === null) return;
|
|
848
850
|
|
|
851
|
+
if (!recovery.enabled && turnResult.interruption) {
|
|
852
|
+
await this.eraseLlamaSlot(baseUrl);
|
|
853
|
+
const reason = turnResult.interruption === 'stall'
|
|
854
|
+
? `no stream data for ${recovery.stallTimeoutMs}ms`
|
|
855
|
+
: `reply exceeded the ${recovery.turnBudgetMs}ms time limit`;
|
|
856
|
+
this.fail(`llama.cpp stopped: ${reason}. Automatic recovery is off; no retry was made.`);
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
|
|
849
860
|
// Don't update lastInputTokens on interrupted streams — the usage
|
|
850
861
|
// event only fires on normal completion, so an interrupted call
|
|
851
862
|
// leaves the field at 0 and would falsely "reset" the CTX bar.
|
|
@@ -44,6 +44,7 @@ export interface RecoveryConfig {
|
|
|
44
44
|
// decode rate on a busy device (a thinking model in mid-reasoning emits
|
|
45
45
|
// tokens slower than answer-mode but never goes silent for 90s when
|
|
46
46
|
// healthy).
|
|
47
|
+
// Enforced even when enabled is false; that switch only disables recovery.
|
|
47
48
|
stallTimeoutMs: number;
|
|
48
49
|
// Per-turn wall-clock budget. Hard ceiling on a single streamOneTurn
|
|
49
50
|
// call regardless of what the model is emitting. Catches productive-
|
|
@@ -51,6 +52,7 @@ export interface RecoveryConfig {
|
|
|
51
52
|
// pumping endlessly) that the runaway detector misses because each
|
|
52
53
|
// signal individually looks legit. 120s lets a long, healthy reasoning
|
|
53
54
|
// pass through; past that the model is almost certainly stuck.
|
|
55
|
+
// Enforced even when enabled is false.
|
|
54
56
|
turnBudgetMs: number;
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Ollama auto-compaction (Master-plan M8 / Hardening §6 Phase 4).
|
|
2
2
|
//
|
|
3
3
|
// This is a PORT of `llamacppRecovery.ts`'s auto-compaction to the Ollama
|
|
4
|
-
// provider,
|
|
5
|
-
//
|
|
4
|
+
// provider, with two tool-message invariants ported from Odysseus
|
|
5
|
+
// (sanitize orphaned tool turns, truncate oversized tool-call args).
|
|
6
6
|
// Read `llamacppRecovery.ts` first — this module mirrors its operator-facing
|
|
7
7
|
// POSTURE exactly: opt-in by choosing the provider (default-on for the provider,
|
|
8
8
|
// env-gated off), bounded by a deterministic context-fill threshold, every
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
// ── WHY THE TRANSFORM DIFFERS FROM llamacppRecovery.performCompaction ─────────
|
|
14
14
|
// The reference asks the PRIMARY model to summarize its whole stack and reseeds
|
|
15
15
|
// `[system, seed]`. M8's spec (Hardening §6) is sharper, matching odysseus:
|
|
16
|
-
// - keep the leading system block intact (
|
|
17
|
-
//
|
|
16
|
+
// - keep the leading system block intact (a naive midpoint split can drop
|
|
17
|
+
// the system prompt - load-bearing);
|
|
18
18
|
// - keep the current turn + last-10 messages VERBATIM (the recent tail the
|
|
19
19
|
// model needs to continue coherently — a summary of the last few turns
|
|
20
20
|
// loses the exact state the model is mid-edit on);
|
|
@@ -389,8 +389,8 @@ export function splitForCompaction(
|
|
|
389
389
|
keepLastMessages: number,
|
|
390
390
|
): { system: CompactMessage[]; older: CompactMessage[]; tail: CompactMessage[] } {
|
|
391
391
|
// Leading system block: all consecutive system messages at the front. Preserve
|
|
392
|
-
// them verbatim
|
|
393
|
-
//
|
|
392
|
+
// them verbatim - a naive midpoint split can drop the system prompt.
|
|
393
|
+
// Offset the split past it.
|
|
394
394
|
let sysEnd = 0;
|
|
395
395
|
while (sysEnd < messages.length && messages[sysEnd].role === 'system') sysEnd++;
|
|
396
396
|
const system = messages.slice(0, sysEnd);
|
|
@@ -50,9 +50,9 @@ export interface ResolvedBackend {
|
|
|
50
50
|
|
|
51
51
|
// ── Cooldown TTLs (Hardening §4: SHORT 5–15s, not minutes) ────────────────
|
|
52
52
|
//
|
|
53
|
-
// A blipped Tailscale host must rejoin selection fast
|
|
54
|
-
//
|
|
55
|
-
//
|
|
53
|
+
// A blipped Tailscale host must rejoin selection fast. A single transient
|
|
54
|
+
// failure must not impose a full 60s lockout after the backend has recovered,
|
|
55
|
+
// leaving requests blocked even though the host is healthy again. We
|
|
56
56
|
// cool reactively on the failure itself (no per-minute %-failure math — at low
|
|
57
57
|
// local request volume a single failure IS the whole signal, per Excellence
|
|
58
58
|
// §"Deliberately rejected") and recover lazily once the TTL lapses.
|
|
@@ -17,7 +17,7 @@ import { imageBase64TokenCost } from '../imageTokens.js';
|
|
|
17
17
|
// so it can compact BEFORE the request overflows the window, not after a
|
|
18
18
|
// 400. This module is that estimate.
|
|
19
19
|
//
|
|
20
|
-
// THE LOAD-BEARING GOTCHA (
|
|
20
|
+
// THE LOAD-BEARING GOTCHA (Hardening §5): a naïve estimate
|
|
21
21
|
// that only counts visible `content` text undershoots by 20-30% on tool-heavy
|
|
22
22
|
// transcripts, because a tool-CALL assistant turn carries `content:""` with
|
|
23
23
|
// the entire payload in `tool_calls[].function.arguments`, and a tool-RESULT
|
|
@@ -5,14 +5,14 @@ import { PLAN_TOOL_NAMES } from '../planTools.js';
|
|
|
5
5
|
// ── Why subset at all ───────────────────────────────────────────────────────
|
|
6
6
|
// Arco advertises its ENTIRE tool registry on every /api/chat turn. On
|
|
7
7
|
// 7B–30B-class local models a large tool-schema payload degrades tool
|
|
8
|
-
// selection (wrong-tool / single-token-stop failures
|
|
8
|
+
// selection (wrong-tool / single-token-stop failures) AND
|
|
9
9
|
// burns input context (the schemas ride every request). We trim the advertised
|
|
10
10
|
// set to a relevant top-K so the schema stays small and selection stays sharp.
|
|
11
11
|
//
|
|
12
12
|
// ── Why a HEURISTIC (no embeddings) ─────────────────────────────────────────
|
|
13
13
|
// Arco's catalog is ~12 tools. Keyword/term-overlap ranking against the
|
|
14
|
-
// task context is more than enough; an embedding model + vector index
|
|
15
|
-
//
|
|
14
|
+
// task context is more than enough; an embedding model + vector index is
|
|
15
|
+
// rejected as overkill for a 12-item set
|
|
16
16
|
// (Hardening §1 "Out"). Deterministic, readable, inspectable — the M10
|
|
17
17
|
// guardrail.
|
|
18
18
|
//
|
package/server/src/quota.ts
CHANGED
|
@@ -137,53 +137,3 @@ export function wireSnapshot(): Record<ProviderName, { throttled: boolean; reset
|
|
|
137
137
|
}
|
|
138
138
|
return out;
|
|
139
139
|
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Legacy PROVIDER STATUS formatter, currently without live callers. Returns empty string when every
|
|
143
|
-
* provider is available — no need to clutter the prompt when routing is
|
|
144
|
-
* unconstrained. See §6.4 for the format.
|
|
145
|
-
*/
|
|
146
|
-
export function buildQuotaInjection(): string {
|
|
147
|
-
const snap = snapshot();
|
|
148
|
-
const anyThrottled = PROVIDERS.some((p) => snap[p].throttled);
|
|
149
|
-
if (!anyThrottled) return '';
|
|
150
|
-
const lines: string[] = ['## PROVIDER STATUS'];
|
|
151
|
-
for (const p of PROVIDERS) {
|
|
152
|
-
const s = snap[p];
|
|
153
|
-
if (s.throttled) {
|
|
154
|
-
const suffix = s.resetsAt
|
|
155
|
-
? ` until ${new Date(s.resetsAt).toISOString()}`
|
|
156
|
-
: ' (no reset time known)';
|
|
157
|
-
lines.push(`- ${p}: THROTTLED${suffix}`);
|
|
158
|
-
} else {
|
|
159
|
-
lines.push(`- ${p}: available`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
lines.push('');
|
|
163
|
-
lines.push('Dispatch AWAY from throttled providers. If a capable worker from an available provider can cover the task, pick that one. Throttled-provider spawns will fail — the cost of retrying is wasted tokens and a stuck workflow.');
|
|
164
|
-
return lines.join('\n');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* §5.4 cross-family reviewer fallback. Maps a primary model to a cross-family
|
|
169
|
-
* reviewer used when the preferred reviewer's provider is throttled. Returns
|
|
170
|
-
* null for models that intentionally skip review (ollama / heretic).
|
|
171
|
-
*
|
|
172
|
-
* Legacy helper, currently without live callers. Kept for a separate cleanup.
|
|
173
|
-
*/
|
|
174
|
-
export interface ReviewerFallback {
|
|
175
|
-
model: string;
|
|
176
|
-
provider: ProviderName;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function crossFamilyFallback(primaryModel: string): ReviewerFallback | null {
|
|
180
|
-
// Codex → Claude
|
|
181
|
-
if (primaryModel === 'gpt-5.4-mini') return { model: 'opus', provider: 'claude' };
|
|
182
|
-
if (primaryModel === 'gpt-5.3-codex') return { model: 'opus', provider: 'claude' };
|
|
183
|
-
if (primaryModel === 'gpt-5.2-codex') return { model: 'opus', provider: 'claude' };
|
|
184
|
-
if (primaryModel === 'gpt-5.5') return { model: 'opus', provider: 'claude' };
|
|
185
|
-
if (primaryModel === 'gpt-5.4') return { model: 'opus', provider: 'claude' };
|
|
186
|
-
if (primaryModel === 'gpt-5.1-codex-max') return { model: 'opus', provider: 'claude' };
|
|
187
|
-
// Heretic (ollama) — review intentionally skipped.
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { buildTranscriptSlice, type TranscriptSliceOptions } from './transcriptWorker.js';
|
|
3
|
+
import { replayEvents } from './workflowStore.js';
|
|
4
|
+
import { renderTranscript, summarizePriorTurns } from './primitives/exportContext.js';
|
|
5
|
+
import { RECENT_HISTORY_MAX_BYTES } from './historyLimits.js';
|
|
6
|
+
|
|
7
|
+
export const REPLACEMENT_FULL_BYTES = 512 * 1024;
|
|
8
|
+
export const REPLACEMENT_RECENT_BYTES = RECENT_HISTORY_MAX_BYTES;
|
|
9
|
+
export type ReplacementHistoryMode = 'recent' | 'full';
|
|
10
|
+
|
|
11
|
+
export async function buildReplacementHistory(cwd: string, workflowId: string, mode: ReplacementHistoryMode, options: TranscriptSliceOptions) {
|
|
12
|
+
if (mode !== 'recent' && mode !== 'full') throw new Error('Choose NO HISTORY, RECENT HISTORY or FULL HISTORY.');
|
|
13
|
+
const slice = await buildTranscriptSlice(cwd, workflowId, { ...options, turns: mode === 'full' ? Number.MAX_SAFE_INTEGER : options.turns }, {
|
|
14
|
+
maxBytes: mode === 'full' ? REPLACEMENT_FULL_BYTES : REPLACEMENT_RECENT_BYTES,
|
|
15
|
+
fitWholeTurns: true, allTurns: mode === 'full',
|
|
16
|
+
});
|
|
17
|
+
let seed = slice.seed, selectedTurns = slice.selectedTurns, historyFallback = false;
|
|
18
|
+
if (mode === 'full') {
|
|
19
|
+
// Preserve the existing full-history transcript and action digest while
|
|
20
|
+
// they fit. Only the oversized fallback uses the shared recent-turn form.
|
|
21
|
+
const events = (await replayEvents(cwd, workflowId, 0)).filter(event => !('seq' in event) || typeof event.seq !== 'number' || event.seq <= slice.cutoffSeq);
|
|
22
|
+
const transcript = renderTranscript(events).trim(), actions = summarizePriorTurns(events).trim();
|
|
23
|
+
const full = [
|
|
24
|
+
'[REPLACEMENT CONTEXT — copied by explicit operator request; this is a new provider session]',
|
|
25
|
+
transcript,
|
|
26
|
+
actions ? `\n[Prior-turn action digest]\n${actions}` : '',
|
|
27
|
+
'\nAcknowledge this imported context briefly, then wait for the operator.',
|
|
28
|
+
].filter(Boolean).join('\n\n');
|
|
29
|
+
if (Buffer.byteLength(full, 'utf8') <= REPLACEMENT_FULL_BYTES) { seed = full; selectedTurns = slice.availableTurns; }
|
|
30
|
+
else historyFallback = true;
|
|
31
|
+
}
|
|
32
|
+
const bytes = Buffer.byteLength(seed, 'utf8');
|
|
33
|
+
const digest = createHash('sha256').update(JSON.stringify({ source: slice.digest, seed, mode, turns: options.turns })).digest('hex');
|
|
34
|
+
return { ...slice, seed, bytes, selectedTurns, digest, historyMode: mode,
|
|
35
|
+
requestedTurns: mode === 'full' ? slice.availableTurns : options.turns,
|
|
36
|
+
truncated: selectedTurns < slice.availableTurns, historyFallback };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function replacementHistoryNotice(preview: Awaited<ReturnType<typeof buildReplacementHistory>>): string | undefined {
|
|
40
|
+
if (!preview.truncated && !preview.historyFallback) return;
|
|
41
|
+
if (!preview.selectedTurns) return 'No whole recent turn fit the replacement history limit. No earlier history was copied; it remains in the previous member conversation.';
|
|
42
|
+
if (preview.truncated) return `Only the most recent ${preview.selectedTurns} of ${preview.availableTurns} turns were copied from the previous member. Earlier turns were not copied; they remain in its conversation.`;
|
|
43
|
+
return `The full history exceeded 512 KiB. All ${preview.selectedTurns} turns were copied as text and tool/file receipts; the full action digest was not copied.`;
|
|
44
|
+
}
|
|
@@ -631,6 +631,7 @@ export function sendWorkflowLive(workflowId: string, message: ServerMessage, sen
|
|
|
631
631
|
}
|
|
632
632
|
|
|
633
633
|
export async function buildClusterStatePayload(clusterId: string): Promise<{
|
|
634
|
+
skillPins?: import('@arco/shared').ClusterSkillPin[];
|
|
634
635
|
clusterId: string;
|
|
635
636
|
cwd: string;
|
|
636
637
|
members: Array<{
|
|
@@ -709,6 +710,7 @@ export async function buildClusterStatePayload(clusterId: string): Promise<{
|
|
|
709
710
|
}
|
|
710
711
|
return {
|
|
711
712
|
clusterId,
|
|
713
|
+
...(state.skillPins?.length ? { skillPins: state.skillPins } : {}),
|
|
712
714
|
cwd: state.cwd,
|
|
713
715
|
members,
|
|
714
716
|
mailboxDepth,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { buildTurnWaitInstructions } from '@arco/shared';
|
|
2
|
+
|
|
1
3
|
// Tells the agent the operator can see a live iframe of any dev server it
|
|
2
4
|
// runs. Static text — appended verbatim to every primary turn so the prefix
|
|
3
5
|
// cache keeps hitting (Claude / Codex caches; Ollama prefix cache). The
|
|
@@ -15,6 +17,12 @@ export function withPreviewNudge(existing: string | undefined): string {
|
|
|
15
17
|
return existing && existing.length > 0 ? `${PREVIEW_NUDGE}\n\n${existing}` : PREVIEW_NUDGE;
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
// Local baselines are role-neutral. Add the wait rule once, after the turn's
|
|
21
|
+
// membership is resolved, before wrapping any cluster coordination around it.
|
|
22
|
+
export function withLocalTurnWaitInstructions(base: string | undefined, role?: string): string {
|
|
23
|
+
return [buildTurnWaitInstructions(role), base].filter(Boolean).join('\n\n');
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
export function buildLocalClusterSystemPrompt(opts: {
|
|
19
27
|
base?: string;
|
|
20
28
|
clusterPlan?: string;
|
|
@@ -70,7 +78,6 @@ export const OLLAMA_PRIMARY_SYSTEM_PROMPT = [
|
|
|
70
78
|
'When the operator asks about the project, start by exploring (Glob the top-level files, Read the README or CLAUDE.md, Grep for relevant terms) before answering. When they ask about something specific, go straight to the file.',
|
|
71
79
|
'Be concise. Default to plain prose. Only use headers, tables, or executive-summary formatting when the operator explicitly asks for that format.',
|
|
72
80
|
'Honor the safety reminders appended to each user message: cap unknown-size shell output, no `find /` without `-maxdepth`, no unbounded scans.',
|
|
73
|
-
'Finishing the request does not mean waiting for it: do not sleep or poll for more than 60 seconds at a time for builds, test suites or CI; report what is running and end the turn.',
|
|
74
81
|
].join(' ');
|
|
75
82
|
|
|
76
83
|
// llama.cpp-specific system prompt. Same baseline as Ollama plus extra
|