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
|
@@ -15,6 +15,7 @@ import { CodexAppServerWorker, computeMcpSignature, bootstrapSurfaceKey } from '
|
|
|
15
15
|
import { codexContextWindowOverride } from '../codexContextWindow.js';
|
|
16
16
|
import { allowVoiceTools, blockVoiceTools, observeVoiceTools } from '../../voice/operatorTools.js';
|
|
17
17
|
import { ComputerTurnWatchdog } from '../../voice/turnWatchdog.js';
|
|
18
|
+
import { HELD_BATCH_MS, HELD_CONTINUATION_LIMIT, HELD_WAIT_LIMIT_MS, formatDuration, heldResultNotice, heldResultsMessage, shortCommand, } from './heldCommands.js';
|
|
18
19
|
const workersByWorkflow = new Map();
|
|
19
20
|
const compactReservations = new Map();
|
|
20
21
|
// Children being torn down for a recycle (bootstrap-signature change,
|
|
@@ -60,7 +61,7 @@ function resetFailureCount(workflowId) {
|
|
|
60
61
|
}
|
|
61
62
|
// One operator turn against the long-lived worker. ProviderProcess shape
|
|
62
63
|
// preserved so WorkerManager / seedWorker can stay unchanged.
|
|
63
|
-
class CodexAppServerTurn extends EventEmitter {
|
|
64
|
+
export class CodexAppServerTurn extends EventEmitter {
|
|
64
65
|
worker;
|
|
65
66
|
config;
|
|
66
67
|
appendSystemPrompt;
|
|
@@ -80,6 +81,24 @@ class CodexAppServerTurn extends EventEmitter {
|
|
|
80
81
|
watchdog;
|
|
81
82
|
stopToolObserver;
|
|
82
83
|
timeoutReason;
|
|
84
|
+
// docs/PROVIDERS.md - the Arco turn stays open while a command the agent
|
|
85
|
+
// started is still running after its Codex turn completed. Each Codex turn
|
|
86
|
+
// inside it adds its cost; the result is reported once, at the end.
|
|
87
|
+
startedAt = Date.now();
|
|
88
|
+
costUsd = 0;
|
|
89
|
+
lastResult;
|
|
90
|
+
continuations = 0;
|
|
91
|
+
waitedMs = 0;
|
|
92
|
+
waitStartedAt = 0;
|
|
93
|
+
waitTimer;
|
|
94
|
+
inputTimer;
|
|
95
|
+
batchTimer;
|
|
96
|
+
resultSteer;
|
|
97
|
+
// STOP: nothing continues, and no later result restarts the turn.
|
|
98
|
+
stopped = false;
|
|
99
|
+
// Interrupt & send: the wait ends, but the commands stay held so the
|
|
100
|
+
// operator's next turn receives their results.
|
|
101
|
+
interrupting = false;
|
|
83
102
|
constructor(id, worker, config, appendSystemPrompt, workflowId) {
|
|
84
103
|
super();
|
|
85
104
|
this.worker = worker;
|
|
@@ -160,12 +179,18 @@ class CodexAppServerTurn extends EventEmitter {
|
|
|
160
179
|
});
|
|
161
180
|
}
|
|
162
181
|
async interrupt() {
|
|
163
|
-
if (
|
|
164
|
-
|
|
182
|
+
if (this.settled)
|
|
183
|
+
return;
|
|
184
|
+
this.interrupting = true;
|
|
185
|
+
this.stopWaitClock();
|
|
186
|
+
await this.worker.cancelCurrentTurn();
|
|
165
187
|
}
|
|
166
188
|
kill() {
|
|
167
189
|
if (this.settled)
|
|
168
190
|
return;
|
|
191
|
+
this.stopped = true;
|
|
192
|
+
this.stopWaitClock();
|
|
193
|
+
this.worker.abandonHeldCommands();
|
|
169
194
|
// Async; the wrapper's `error` event fires when `turn_settled` lands.
|
|
170
195
|
void this.worker.cancelCurrentTurn().catch((err) => {
|
|
171
196
|
if (this.settled)
|
|
@@ -223,26 +248,28 @@ class CodexAppServerTurn extends EventEmitter {
|
|
|
223
248
|
this.fail('turn settled with no result');
|
|
224
249
|
return;
|
|
225
250
|
}
|
|
226
|
-
this.settled = true;
|
|
227
|
-
this._status = 'completed';
|
|
228
|
-
this.unwire();
|
|
229
251
|
// Successful turn — the spawn-failure circuit breaker resets so any
|
|
230
252
|
// earlier intermittent crashes stop counting toward the 3-strike cap.
|
|
231
253
|
resetFailureCount(this.workflowId);
|
|
232
|
-
this.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
254
|
+
this.costUsd += r.costUsd ?? 0;
|
|
255
|
+
this.lastResult = r;
|
|
256
|
+
void this.afterCodexTurn();
|
|
257
|
+
};
|
|
258
|
+
const onHeldCommands = () => {
|
|
259
|
+
if (this.settled || this.stopped)
|
|
260
|
+
return;
|
|
261
|
+
if (this.waitStartedAt) {
|
|
262
|
+
// Ends that arrive close together go to the agent in one turn.
|
|
263
|
+
if (!this.batchTimer)
|
|
264
|
+
this.batchTimer = setTimeout(() => { this.batchTimer = undefined; this.reviewWait(); }, HELD_BATCH_MS);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
// A result that arrives while the final answer is being written waits
|
|
268
|
+
// for the turn to complete and continues it, so it is never lost.
|
|
269
|
+
if (this.worker.hasHeldResults() && !this.resultSteer && !this.lastResult && this.worker.acceptsResultSteer) {
|
|
270
|
+
// A Codex turn is running: the result goes into it, never a second turn.
|
|
271
|
+
this.resultSteer = this.steerResults().finally(() => { this.resultSteer = undefined; });
|
|
272
|
+
}
|
|
246
273
|
};
|
|
247
274
|
const onFatal = (reason) => {
|
|
248
275
|
if (this.settled)
|
|
@@ -260,13 +287,15 @@ class CodexAppServerTurn extends EventEmitter {
|
|
|
260
287
|
this.worker.on('system_notice', onSystemNotice);
|
|
261
288
|
this.worker.on('turn_settled', onSettled);
|
|
262
289
|
this.worker.on('fatal', onFatal);
|
|
263
|
-
this.
|
|
290
|
+
this.worker.on('held_commands', onHeldCommands);
|
|
291
|
+
this.wired.push({ event: 'init', fn: onInit }, { event: 'text', fn: onText }, { event: 'thinking', fn: onThinking }, { event: 'tool_use', fn: onToolUse }, { event: 'primary_artifact', fn: onPrimaryArtifact }, { event: 'system_notice', fn: onSystemNotice }, { event: 'turn_settled', fn: onSettled }, { event: 'fatal', fn: onFatal }, { event: 'held_commands', fn: onHeldCommands });
|
|
264
292
|
// Phase 6a unused but harmless — silences "WorkerConfig.appendSystemPrompt
|
|
265
293
|
// is read-only / accessed once" linter complaint. The field flows
|
|
266
294
|
// through to beginTurn() at spawn time.
|
|
267
295
|
void this.config;
|
|
268
296
|
}
|
|
269
297
|
unwire() {
|
|
298
|
+
this.stopWaitClock();
|
|
270
299
|
this.watchdog?.stop();
|
|
271
300
|
this.watchdog = undefined;
|
|
272
301
|
this.stopToolObserver?.();
|
|
@@ -282,8 +311,174 @@ class CodexAppServerTurn extends EventEmitter {
|
|
|
282
311
|
this.settled = true;
|
|
283
312
|
this._status = 'failed';
|
|
284
313
|
this.unwire();
|
|
314
|
+
// After Interrupt & send the operator's message runs next and takes the
|
|
315
|
+
// results; any other failure leaves nobody to deliver them to.
|
|
316
|
+
if (!this.interrupting)
|
|
317
|
+
this.worker.abandonHeldCommands();
|
|
285
318
|
this.emit('error', reason);
|
|
286
319
|
}
|
|
320
|
+
// ── Waiting on commands the agent started ───────────────────────────
|
|
321
|
+
async afterCodexTurn() {
|
|
322
|
+
// A result steer still in flight either landed in the turn that just
|
|
323
|
+
// ended or comes back to the queue of results; wait to know which.
|
|
324
|
+
if (this.resultSteer)
|
|
325
|
+
await this.resultSteer;
|
|
326
|
+
if (this.settled)
|
|
327
|
+
return;
|
|
328
|
+
const running = this.worker.heldCommands;
|
|
329
|
+
const ready = this.worker.hasHeldResults();
|
|
330
|
+
if (this.stopped || (!ready && running.length === 0))
|
|
331
|
+
return this.finish();
|
|
332
|
+
if (this.continuations >= HELD_CONTINUATION_LIMIT) {
|
|
333
|
+
return this.giveUp(`Arco stopped continuing Codex after ${HELD_CONTINUATION_LIMIT} command results in this turn.`);
|
|
334
|
+
}
|
|
335
|
+
if (ready && (running.length === 0 || this.worker.hasFailedHeldResult()))
|
|
336
|
+
return this.continueWith([]);
|
|
337
|
+
this.startWait();
|
|
338
|
+
}
|
|
339
|
+
startWait() {
|
|
340
|
+
const remaining = HELD_WAIT_LIMIT_MS - this.waitedMs;
|
|
341
|
+
if (remaining <= 0)
|
|
342
|
+
return this.giveUp(`Arco stopped waiting after ${formatDuration(HELD_WAIT_LIMIT_MS)} in this turn.`);
|
|
343
|
+
this.waitStartedAt = Date.now();
|
|
344
|
+
this.worker.showHeldUntil(this.waitStartedAt + remaining);
|
|
345
|
+
this.waitTimer = setTimeout(() => {
|
|
346
|
+
this.stopWaitClock();
|
|
347
|
+
this.giveUp(`Arco stopped waiting after ${formatDuration(HELD_WAIT_LIMIT_MS)} in this turn.`);
|
|
348
|
+
}, remaining);
|
|
349
|
+
this.waitTimer.unref?.();
|
|
350
|
+
this.inputTimer = setInterval(() => this.checkInput(), 500);
|
|
351
|
+
this.inputTimer.unref?.();
|
|
352
|
+
}
|
|
353
|
+
stopWaitClock() {
|
|
354
|
+
if (this.waitStartedAt) {
|
|
355
|
+
this.waitedMs += Date.now() - this.waitStartedAt;
|
|
356
|
+
this.worker.releaseHeldWait();
|
|
357
|
+
}
|
|
358
|
+
this.waitStartedAt = 0;
|
|
359
|
+
clearTimeout(this.waitTimer);
|
|
360
|
+
this.waitTimer = undefined;
|
|
361
|
+
clearInterval(this.inputTimer);
|
|
362
|
+
this.inputTimer = undefined;
|
|
363
|
+
clearTimeout(this.batchTimer);
|
|
364
|
+
this.batchTimer = undefined;
|
|
365
|
+
}
|
|
366
|
+
reviewWait() {
|
|
367
|
+
if (this.settled || !this.waitStartedAt)
|
|
368
|
+
return;
|
|
369
|
+
const running = this.worker.heldCommands;
|
|
370
|
+
const ready = this.worker.hasHeldResults();
|
|
371
|
+
if (ready && (running.length === 0 || this.worker.hasFailedHeldResult())) {
|
|
372
|
+
this.stopWaitClock();
|
|
373
|
+
this.continueWith([]);
|
|
374
|
+
}
|
|
375
|
+
else if (!ready && running.length === 0) {
|
|
376
|
+
// Codex lost the commands (connection or thread closed); the lost
|
|
377
|
+
// line has already been shown.
|
|
378
|
+
this.stopWaitClock();
|
|
379
|
+
this.finish();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
// Direct operator input or an explicit nudge ends the wait. A steer goes
|
|
383
|
+
// to the agent at once; a follow-up waits for the turn to end, so the
|
|
384
|
+
// turn ends here and the follow-up turn takes over the held commands.
|
|
385
|
+
checkInput() {
|
|
386
|
+
if (this.settled || !this.waitStartedAt)
|
|
387
|
+
return;
|
|
388
|
+
const pending = this.config.pendingInput?.();
|
|
389
|
+
if (!pending)
|
|
390
|
+
return;
|
|
391
|
+
const peeked = this.config.peekSteer?.() ?? [];
|
|
392
|
+
if (pending === 'follow-up' || peeked.some(item => item.attachments?.length)) {
|
|
393
|
+
this.stopWaitClock();
|
|
394
|
+
this.emit('system_notice', `Stopped waiting for ${this.runningLabel()}: your message is next. Arco still passes the result on when it ends.`);
|
|
395
|
+
return this.finish();
|
|
396
|
+
}
|
|
397
|
+
const items = this.config.drainSteer?.() ?? [];
|
|
398
|
+
if (!items.length)
|
|
399
|
+
return;
|
|
400
|
+
this.stopWaitClock();
|
|
401
|
+
this.continueWith(items);
|
|
402
|
+
}
|
|
403
|
+
continueWith(items) {
|
|
404
|
+
this.continuations += 1;
|
|
405
|
+
const results = this.worker.takeHeldResults();
|
|
406
|
+
const running = this.worker.heldCommands;
|
|
407
|
+
for (const result of results)
|
|
408
|
+
this.emit('system_notice', heldResultNotice(result, true));
|
|
409
|
+
const message = [
|
|
410
|
+
...(results.length ? [heldResultsMessage(results, running)] : []),
|
|
411
|
+
...items.map(item => item.content),
|
|
412
|
+
...(!results.length && running.length ? [`[Arco] Still running: ${running.map(item => shortCommand(item.command)).join('; ')}. Arco tells you when it ends.`] : []),
|
|
413
|
+
].join('\n\n');
|
|
414
|
+
this._output += this._output ? '\n\n' : '';
|
|
415
|
+
this.lastResult = undefined;
|
|
416
|
+
this.worker.beginTurn(message, undefined, { continuation: true })
|
|
417
|
+
.then(() => {
|
|
418
|
+
if (items.length)
|
|
419
|
+
this.config.onSteerDelivered?.(items);
|
|
420
|
+
if (this.settled)
|
|
421
|
+
void this.worker.cancelCurrentTurn().catch(() => { });
|
|
422
|
+
})
|
|
423
|
+
.catch((err) => {
|
|
424
|
+
if (this.settled)
|
|
425
|
+
return;
|
|
426
|
+
this.worker.restoreHeldResults(results);
|
|
427
|
+
if (items.length)
|
|
428
|
+
this.config.requeueSteer?.(items, 'follow-up');
|
|
429
|
+
this.fail(err instanceof Error ? err.message : String(err));
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
async steerResults() {
|
|
433
|
+
const results = this.worker.takeHeldResults();
|
|
434
|
+
if (!results.length)
|
|
435
|
+
return;
|
|
436
|
+
const delivered = await this.worker.steerText(heldResultsMessage(results, this.worker.heldCommands));
|
|
437
|
+
if (!delivered) {
|
|
438
|
+
this.worker.restoreHeldResults(results);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
for (const result of results)
|
|
442
|
+
this.emit('system_notice', heldResultNotice(result, false));
|
|
443
|
+
}
|
|
444
|
+
runningLabel() {
|
|
445
|
+
const running = this.worker.heldCommands;
|
|
446
|
+
return running.length ? running.map(item => `\`${shortCommand(item.command)}\``).join(', ') : 'the command';
|
|
447
|
+
}
|
|
448
|
+
giveUp(line) {
|
|
449
|
+
const running = this.worker.heldCommands;
|
|
450
|
+
this.worker.abandonHeldCommands();
|
|
451
|
+
this.emit('system_notice', running.length
|
|
452
|
+
? `${line} Still running: ${running.map(item => `\`${shortCommand(item.command)}\``).join(', ')}. Its row records how it ends.`
|
|
453
|
+
: line);
|
|
454
|
+
this.finish();
|
|
455
|
+
}
|
|
456
|
+
finish() {
|
|
457
|
+
if (this.settled)
|
|
458
|
+
return;
|
|
459
|
+
const r = this.lastResult;
|
|
460
|
+
if (!r) {
|
|
461
|
+
this.fail('turn settled with no result');
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
this.settled = true;
|
|
465
|
+
this._status = 'completed';
|
|
466
|
+
this.unwire();
|
|
467
|
+
this.emit('result', {
|
|
468
|
+
text: this._output.length >= r.text.length ? this._output : r.text,
|
|
469
|
+
costUsd: this.costUsd,
|
|
470
|
+
durationMs: Math.max(r.durationMs ?? 0, Date.now() - this.startedAt),
|
|
471
|
+
...(r.usage ? { usage: r.usage } : {}),
|
|
472
|
+
...(typeof r.modelContextWindow === 'number' ? { modelContextWindow: r.modelContextWindow } : {}),
|
|
473
|
+
...(typeof r.freshContextWindow === 'number' ? { freshContextWindow: r.freshContextWindow } : {}),
|
|
474
|
+
...(typeof r.lastPromptTokens === 'number' ? { lastPromptTokens: r.lastPromptTokens } : {}),
|
|
475
|
+
// docs/PROVIDERS.md - Codex doesn't expose tool_result bytes
|
|
476
|
+
// through the app-server JSON-RPC surface. Sentinel: -1 = unknown.
|
|
477
|
+
thinkingBytes: 0,
|
|
478
|
+
toolResultBytes: -1,
|
|
479
|
+
toolResultBytesRaw: -1,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
287
482
|
}
|
|
288
483
|
// Long-lived worker accessor. Creates lazily on first turn for a given
|
|
289
484
|
// workflow; subsequent turns reuse the cached worker (same `app-server`
|
|
@@ -311,6 +506,26 @@ function acquireWorker(workflowId, config, resumeSessionId) {
|
|
|
311
506
|
}
|
|
312
507
|
const fresh = new CodexAppServerWorker(workflowId, config, resumeSessionId);
|
|
313
508
|
workersByWorkflow.set(workflowId, fresh);
|
|
509
|
+
fresh.on('late_command', (event, lateCommand) => {
|
|
510
|
+
void import('../../server/broadcast.js').then(({ broadcastWorkflow }) => {
|
|
511
|
+
const { name: tool, ...entry } = event;
|
|
512
|
+
broadcastWorkflow(workflowId, {
|
|
513
|
+
...entry, type: 'primary_tool_use', workflowId, tool, lateCommand,
|
|
514
|
+
...(lateCommand?.state === 'finished' ? {} : { status: 'in_progress' }),
|
|
515
|
+
});
|
|
516
|
+
if (lateCommand?.state === 'lost') {
|
|
517
|
+
let command = 'A command';
|
|
518
|
+
try {
|
|
519
|
+
command = JSON.parse(event.input).command || command;
|
|
520
|
+
}
|
|
521
|
+
catch { /* use the fallback */ }
|
|
522
|
+
broadcastWorkflow(workflowId, {
|
|
523
|
+
type: 'system_notice', workflowId,
|
|
524
|
+
content: `Codex lost the result for ${command.slice(0, 240)} when its connection closed.`,
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}).catch(error => console.warn('[arco] could not record a late Codex command result', error));
|
|
528
|
+
});
|
|
314
529
|
fresh.on('fatal', (reason) => {
|
|
315
530
|
// Drop the cache entry so the next operator turn re-spawns. Don't
|
|
316
531
|
// dispose() — the entry is already torn down by `onChildDeath`.
|
|
@@ -325,6 +540,9 @@ function acquireWorker(workflowId, config, resumeSessionId) {
|
|
|
325
540
|
});
|
|
326
541
|
return fresh;
|
|
327
542
|
}
|
|
543
|
+
export function runningCodexLateCommands(workflowId) {
|
|
544
|
+
return workersByWorkflow.get(workflowId)?.runningLateCommands ?? [];
|
|
545
|
+
}
|
|
328
546
|
// Operator-triggered native compaction against the long-lived per-workflow
|
|
329
547
|
// thread (the app-server equivalent of `/compact` in Codex CLI). Out-of-band
|
|
330
548
|
// vs. the per-turn CodexAppServerTurn wrapper — it talks straight to the
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { CodexLateCommand, PrimaryToolUseMessage } from '@arco/shared';
|
|
2
|
+
import type { ToolUseEvent } from './worker.js';
|
|
3
|
+
export declare function isLongRunningProgram(command: string): boolean;
|
|
4
|
+
export interface HeldCommandResult {
|
|
5
|
+
itemId: string;
|
|
6
|
+
command: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
startedAt: number;
|
|
9
|
+
endedAt: number;
|
|
10
|
+
exitCode?: number;
|
|
11
|
+
output?: string;
|
|
12
|
+
failed: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function commandText(event: Pick<ToolUseEvent, 'input'>): {
|
|
15
|
+
command: string;
|
|
16
|
+
cwd?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class CodexLateCommands {
|
|
19
|
+
private readonly publish;
|
|
20
|
+
private readonly onHeldChange;
|
|
21
|
+
private readonly commands;
|
|
22
|
+
private readonly results;
|
|
23
|
+
constructor(publish: (event: ToolUseEvent, state: NonNullable<PrimaryToolUseMessage['lateCommand']>) => void, onHeldChange?: () => void);
|
|
24
|
+
start(turnId: string, event: ToolUseEvent): void;
|
|
25
|
+
/** True once the long-lived publisher owns this completion. */
|
|
26
|
+
complete(turnId: string, event: ToolUseEvent): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* A command that ended inside its own turn after the agent's final answer
|
|
29
|
+
* had started: the model never saw the result, so it is kept for delivery
|
|
30
|
+
* once that turn has completed. The completion is still shown in the turn.
|
|
31
|
+
* False when the command is unknown, belongs to another turn or has
|
|
32
|
+
* already outlived its turn.
|
|
33
|
+
*/
|
|
34
|
+
completeUnseen(turnId: string, event: ToolUseEvent): boolean;
|
|
35
|
+
settle(turnId: string): void;
|
|
36
|
+
/** Commands the agent still waits on, oldest first. */
|
|
37
|
+
running(): Array<{
|
|
38
|
+
itemId: string;
|
|
39
|
+
command: string;
|
|
40
|
+
startedAt: number;
|
|
41
|
+
}>;
|
|
42
|
+
hasResults(): boolean;
|
|
43
|
+
hasFailedResult(): boolean;
|
|
44
|
+
/** Ended results; each is handed out exactly once. */
|
|
45
|
+
takeResults(): HeldCommandResult[];
|
|
46
|
+
/** Put back results whose delivery failed, ahead of any newer ones. */
|
|
47
|
+
restoreResults(results: HeldCommandResult[]): void;
|
|
48
|
+
/** The Arco turn now waits on the held commands, at most until `until`. */
|
|
49
|
+
hold(until: number): void;
|
|
50
|
+
/** The turn no longer waits (it continued, ended or was stopped). */
|
|
51
|
+
release(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Nobody waits on these commands any more (STOP, the wait limit, a failed
|
|
54
|
+
* turn). They keep running and their rows still record how they end, but
|
|
55
|
+
* no result reaches the agent.
|
|
56
|
+
*/
|
|
57
|
+
abandon(): void;
|
|
58
|
+
snapshot(): CodexLateCommand[];
|
|
59
|
+
disconnect(): void;
|
|
60
|
+
private result;
|
|
61
|
+
private notify;
|
|
62
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
const DISPLAY_MS = 5 * 60_000;
|
|
2
|
+
const MAX_COMMANDS = 64;
|
|
3
|
+
// A program meant to keep running (a server or a watcher) must never hold a
|
|
4
|
+
// turn open. Programs the shell put in the background (`&`, `nohup`) end the
|
|
5
|
+
// shell at once, so Codex completes their item inside the turn; only a known
|
|
6
|
+
// long-running program started in the foreground needs this pattern. Kept
|
|
7
|
+
// narrower than the preview detector's pattern: `vite build` or `deno run
|
|
8
|
+
// script.ts` end on their own and must still be waited on.
|
|
9
|
+
const LONG_RUNNING_RE = new RegExp([
|
|
10
|
+
String.raw `\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve|watch)\b`,
|
|
11
|
+
String.raw `\b(?:vite|next|astro|nuxt|remix|gatsby|docusaurus)\s+(?:dev|develop|start|serve|preview)\b`,
|
|
12
|
+
String.raw `\bvite\s*(?:$|['"]|--(?:host|port)\b)`,
|
|
13
|
+
String.raw `\bpython3?\s+-m\s+http\.server\b`,
|
|
14
|
+
String.raw `\buvicorn\b`, String.raw `\bflask\s+run\b`, String.raw `\brails\s+s(?:erver)?\b`, String.raw `\bphp\s+-S\b`,
|
|
15
|
+
String.raw `(?:^|\s)--watch\b`, String.raw `\bwatch\s+-n\b`, String.raw `\btail\s+(?:-\w+\s+)*-\w*[fF]\b`,
|
|
16
|
+
String.raw `\bsleep\s+infinity\b`,
|
|
17
|
+
String.raw `\bdocker[\s-]compose\s+(?:\S+\s+)*up\b(?![^|;&]*\s(?:-d|--detach)\b)`,
|
|
18
|
+
].join('|'));
|
|
19
|
+
export function isLongRunningProgram(command) {
|
|
20
|
+
return LONG_RUNNING_RE.test(command);
|
|
21
|
+
}
|
|
22
|
+
export function commandText(event) {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(event.input);
|
|
25
|
+
return {
|
|
26
|
+
command: typeof parsed.command === 'string' ? parsed.command : 'a shell command',
|
|
27
|
+
...(typeof parsed.cwd === 'string' ? { cwd: parsed.cwd } : {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return { command: 'a shell command' };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class CodexLateCommands {
|
|
35
|
+
publish;
|
|
36
|
+
onHeldChange;
|
|
37
|
+
commands = new Map();
|
|
38
|
+
// Ended held commands whose result has not yet been delivered to the agent.
|
|
39
|
+
results = [];
|
|
40
|
+
constructor(publish, onHeldChange = () => { }) {
|
|
41
|
+
this.publish = publish;
|
|
42
|
+
this.onHeldChange = onHeldChange;
|
|
43
|
+
}
|
|
44
|
+
start(turnId, event) {
|
|
45
|
+
if (!event.itemId || this.commands.has(event.itemId))
|
|
46
|
+
return;
|
|
47
|
+
if (this.commands.size >= MAX_COMMANDS) {
|
|
48
|
+
const oldest = this.commands.keys().next().value;
|
|
49
|
+
if (oldest) {
|
|
50
|
+
const previous = this.commands.get(oldest);
|
|
51
|
+
if (previous.waitingUntil)
|
|
52
|
+
this.notify(previous, 'untracked');
|
|
53
|
+
clearTimeout(previous.timer);
|
|
54
|
+
this.commands.delete(oldest);
|
|
55
|
+
if (previous.held)
|
|
56
|
+
this.onHeldChange();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.commands.set(event.itemId, { turnId, event, startedAt: Date.now() });
|
|
60
|
+
}
|
|
61
|
+
/** True once the long-lived publisher owns this completion. */
|
|
62
|
+
complete(turnId, event) {
|
|
63
|
+
const id = event.itemId;
|
|
64
|
+
const command = id ? this.commands.get(id) : undefined;
|
|
65
|
+
if (!id || !command || command.turnId !== turnId)
|
|
66
|
+
return false;
|
|
67
|
+
this.commands.delete(id);
|
|
68
|
+
clearTimeout(command.timer);
|
|
69
|
+
if (!command.waitingUntil)
|
|
70
|
+
return false;
|
|
71
|
+
this.notify(command, 'finished', event);
|
|
72
|
+
if (command.held) {
|
|
73
|
+
this.results.push(this.result(command, event));
|
|
74
|
+
this.onHeldChange();
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A command that ended inside its own turn after the agent's final answer
|
|
80
|
+
* had started: the model never saw the result, so it is kept for delivery
|
|
81
|
+
* once that turn has completed. The completion is still shown in the turn.
|
|
82
|
+
* False when the command is unknown, belongs to another turn or has
|
|
83
|
+
* already outlived its turn.
|
|
84
|
+
*/
|
|
85
|
+
completeUnseen(turnId, event) {
|
|
86
|
+
const id = event.itemId;
|
|
87
|
+
const command = id ? this.commands.get(id) : undefined;
|
|
88
|
+
if (!id || !command || command.turnId !== turnId || command.waitingUntil)
|
|
89
|
+
return false;
|
|
90
|
+
this.commands.delete(id);
|
|
91
|
+
clearTimeout(command.timer);
|
|
92
|
+
if (!isLongRunningProgram(commandText(command.event).command)) {
|
|
93
|
+
this.results.push(this.result(command, event));
|
|
94
|
+
this.onHeldChange();
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
settle(turnId) {
|
|
99
|
+
let held = false;
|
|
100
|
+
for (const command of this.commands.values()) {
|
|
101
|
+
if (command.turnId !== turnId || command.waitingUntil)
|
|
102
|
+
continue;
|
|
103
|
+
command.waitingUntil = Date.now() + DISPLAY_MS;
|
|
104
|
+
command.held = !isLongRunningProgram(commandText(command.event).command);
|
|
105
|
+
held ||= command.held;
|
|
106
|
+
this.notify(command, 'running');
|
|
107
|
+
command.timer = setTimeout(() => this.notify(command, 'untracked'), DISPLAY_MS);
|
|
108
|
+
command.timer.unref();
|
|
109
|
+
}
|
|
110
|
+
if (held)
|
|
111
|
+
this.onHeldChange();
|
|
112
|
+
}
|
|
113
|
+
/** Commands the agent still waits on, oldest first. */
|
|
114
|
+
running() {
|
|
115
|
+
return [...this.commands.values()].flatMap(command => command.held && command.event.itemId
|
|
116
|
+
? [{ itemId: command.event.itemId, command: commandText(command.event).command, startedAt: command.startedAt }] : []);
|
|
117
|
+
}
|
|
118
|
+
hasResults() { return this.results.length > 0; }
|
|
119
|
+
hasFailedResult() { return this.results.some(result => result.failed); }
|
|
120
|
+
/** Ended results; each is handed out exactly once. */
|
|
121
|
+
takeResults() { return this.results.splice(0); }
|
|
122
|
+
/** Put back results whose delivery failed, ahead of any newer ones. */
|
|
123
|
+
restoreResults(results) {
|
|
124
|
+
if (results.length)
|
|
125
|
+
this.results.unshift(...results);
|
|
126
|
+
}
|
|
127
|
+
/** The Arco turn now waits on the held commands, at most until `until`. */
|
|
128
|
+
hold(until) {
|
|
129
|
+
for (const command of this.commands.values()) {
|
|
130
|
+
if (!command.held || !command.waitingUntil)
|
|
131
|
+
continue;
|
|
132
|
+
command.waiting = true;
|
|
133
|
+
if (command.waitingUntil < until) {
|
|
134
|
+
command.waitingUntil = until;
|
|
135
|
+
clearTimeout(command.timer);
|
|
136
|
+
command.timer = setTimeout(() => this.notify(command, 'untracked'), Math.max(0, until - Date.now()));
|
|
137
|
+
command.timer.unref();
|
|
138
|
+
}
|
|
139
|
+
this.notify(command, 'running');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** The turn no longer waits (it continued, ended or was stopped). */
|
|
143
|
+
release() {
|
|
144
|
+
for (const command of this.commands.values()) {
|
|
145
|
+
if (!command.waiting)
|
|
146
|
+
continue;
|
|
147
|
+
command.waiting = false;
|
|
148
|
+
this.notify(command, 'running');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Nobody waits on these commands any more (STOP, the wait limit, a failed
|
|
153
|
+
* turn). They keep running and their rows still record how they end, but
|
|
154
|
+
* no result reaches the agent.
|
|
155
|
+
*/
|
|
156
|
+
abandon() {
|
|
157
|
+
this.release();
|
|
158
|
+
this.results.length = 0;
|
|
159
|
+
for (const command of this.commands.values())
|
|
160
|
+
command.held = false;
|
|
161
|
+
}
|
|
162
|
+
snapshot() {
|
|
163
|
+
const now = Date.now();
|
|
164
|
+
return [...this.commands.values()].flatMap(({ event, startedAt, waitingUntil, waiting }) => event.itemId && waitingUntil && waitingUntil > now
|
|
165
|
+
? [{ itemId: event.itemId, input: event.input, startedAt, waitingUntil, ...(waiting ? { waiting } : {}) }] : []);
|
|
166
|
+
}
|
|
167
|
+
disconnect() {
|
|
168
|
+
const held = this.results.length > 0 || [...this.commands.values()].some(command => command.held);
|
|
169
|
+
for (const command of this.commands.values()) {
|
|
170
|
+
clearTimeout(command.timer);
|
|
171
|
+
this.notify(command, 'lost');
|
|
172
|
+
}
|
|
173
|
+
this.commands.clear();
|
|
174
|
+
this.results.length = 0;
|
|
175
|
+
if (held)
|
|
176
|
+
this.onHeldChange();
|
|
177
|
+
}
|
|
178
|
+
result(command, event) {
|
|
179
|
+
const { command: text, cwd } = commandText(command.event);
|
|
180
|
+
return {
|
|
181
|
+
itemId: command.event.itemId, command: text, ...(cwd ? { cwd } : {}),
|
|
182
|
+
startedAt: command.startedAt, endedAt: Date.now(),
|
|
183
|
+
...(typeof event.exitCode === 'number' ? { exitCode: event.exitCode } : {}),
|
|
184
|
+
...(typeof event.output === 'string' ? { output: event.output } : {}),
|
|
185
|
+
failed: event.status === 'failed' || (typeof event.exitCode === 'number' && event.exitCode !== 0),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
notify(command, state, result) {
|
|
189
|
+
this.publish(result ?? command.event, {
|
|
190
|
+
state, startedAt: command.startedAt, waitingUntil: command.waitingUntil ?? Date.now(),
|
|
191
|
+
...(command.waiting && state === 'running' ? { waiting: true } : {}),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=lateCommands.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type HeldCommandResult } from './lateCommands.js';
|
|
1
2
|
import { EventEmitter } from 'events';
|
|
2
3
|
import { type ProviderName, type WorkerConfig } from '@arco/shared';
|
|
3
4
|
import type { ThreadStartParams } from './bindings/v2/ThreadStartParams.js';
|
|
@@ -81,7 +82,9 @@ export declare class CodexAppServerWorker extends EventEmitter {
|
|
|
81
82
|
updateConfig(next: WorkerConfig): void;
|
|
82
83
|
ensureStarted(): Promise<void>;
|
|
83
84
|
private clearThreadGoal;
|
|
84
|
-
beginTurn(prompt: string, appendSystemPrompt: string | undefined
|
|
85
|
+
beginTurn(prompt: string, appendSystemPrompt: string | undefined, options?: {
|
|
86
|
+
continuation?: boolean;
|
|
87
|
+
}): Promise<void>;
|
|
85
88
|
private cancellation;
|
|
86
89
|
cancelCurrentTurn(): Promise<void>;
|
|
87
90
|
private interruptCurrentTurn;
|
|
@@ -96,6 +99,25 @@ export declare class CodexAppServerWorker extends EventEmitter {
|
|
|
96
99
|
private requeueSteer;
|
|
97
100
|
dispose(): Promise<void>;
|
|
98
101
|
private buildSandboxPolicy;
|
|
102
|
+
private readonly lateCommands;
|
|
103
|
+
get runningLateCommands(): import("@arco/shared").CodexLateCommand[];
|
|
104
|
+
get heldCommands(): {
|
|
105
|
+
itemId: string;
|
|
106
|
+
command: string;
|
|
107
|
+
startedAt: number;
|
|
108
|
+
}[];
|
|
109
|
+
hasHeldResults(): boolean;
|
|
110
|
+
hasFailedHeldResult(): boolean;
|
|
111
|
+
takeHeldResults(): HeldCommandResult[];
|
|
112
|
+
restoreHeldResults(results: HeldCommandResult[]): void;
|
|
113
|
+
showHeldUntil(until: number): void;
|
|
114
|
+
releaseHeldWait(): void;
|
|
115
|
+
get acceptsResultSteer(): boolean;
|
|
116
|
+
abandonHeldCommands(): void;
|
|
117
|
+
/** Add Arco's text to the running turn. False when no turn takes it. */
|
|
118
|
+
steerText(text: string): Promise<boolean>;
|
|
119
|
+
private commandToolUse;
|
|
120
|
+
private handleCommandItem;
|
|
99
121
|
private onNotification;
|
|
100
122
|
private countedCompactionTurns;
|
|
101
123
|
private countCompaction;
|