arco-workbench 0.1.8 → 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 +11 -0
- package/README.md +7 -5
- package/client/dist/assets/{PhosphorBackdrop-D7jdAV_G.js → PhosphorBackdrop-DRu16-Is.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-DrDm60h8.js → ThemedBackgroundShaderImpl-BLdwwQ4D.js} +1 -1
- package/client/dist/assets/{XtermView-BGFujb1e.js → XtermView-Xk7_9JaH.js} +1 -1
- package/client/dist/assets/{galleryEditor-D951A2sE.js → galleryEditor-CI8ClzBa.js} +1 -1
- package/client/dist/assets/{index-DD9kFGsF.css → index-BEFgrUJJ.css} +1 -1
- package/client/dist/assets/{index-CsVy3eZm.js → index-C7WzZfsr.js} +246 -244
- 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/SkillsControl.tsx +25 -8
- 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/PhoneUpload.tsx +288 -0
- package/client/src/components/PrimaryStatus.tsx +14 -6
- package/client/src/components/RuntimeStateBanner.tsx +5 -0
- package/client/src/components/SkillEditorDialog.tsx +2 -2
- package/client/src/components/SkillsSettings.tsx +17 -5
- package/client/src/components/TerminalInput.tsx +3 -1
- package/client/src/components/WorkflowView.tsx +2 -0
- 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 +11 -1
- package/client/src/help/content/composer.tsx +18 -1
- package/client/src/help/content/header.tsx +2 -1
- package/client/src/help/content/misc.tsx +1 -1
- package/client/src/help/content/settings.tsx +1 -1
- package/client/src/help/manualSections/clusters.tsx +3 -0
- package/client/src/help/manualSections/configuration.tsx +3 -1
- package/client/src/help/manualSections/gettingStarted.tsx +4 -4
- package/client/src/help/manualSections/maintenance.tsx +7 -6
- package/client/src/help/manualSections/powerFeatures.tsx +3 -2
- package/client/src/help/manualSections/workspace.tsx +30 -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/ws/handleServerMessage.ts +23 -6
- package/docs/CLIENT.md +7 -1
- package/docs/FEATURES.md +6 -3
- package/docs/GETTING_STARTED.md +8 -3
- package/docs/INDEX.md +1 -1
- package/docs/OPERATIONS.md +199 -48
- package/docs/PROTOCOL_CLUSTER.md +9 -1
- package/docs/PROVIDERS.md +34 -0
- package/docs/SETTINGS.md +5 -3
- package/native/darwin-arm64/manifest.json +1 -1
- package/native/linux-x64/manifest.json +1 -1
- package/native/win32-x64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/protocol/chat.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +2 -0
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +11 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/server/dist/clusterDirector.js +1 -0
- package/server/dist/clusterPeerOps.js +4 -1
- package/server/dist/clusterRehydrate.js +2 -0
- package/server/dist/explorerDocs.d.ts +10 -6
- package/server/dist/explorerDocs.js +75 -34
- 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 +13 -24
- package/server/dist/http/writeConfinement.js +19 -2
- package/server/dist/primitives/seedWorker.d.ts +1 -0
- package/server/dist/primitives/seedWorker.js +2 -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 -2
- package/server/dist/providers/codexCodeMode.d.ts +2 -1
- package/server/dist/providers/codexCodeMode.js +7 -3
- 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/ws/handoffHandlers.js +2 -0
- package/server/dist/ws/turnEngine.js +17 -0
- package/server/package.json +1 -1
- package/server/src/clusterDirector.ts +1 -0
- package/server/src/clusterPeerOps.ts +4 -1
- package/server/src/clusterRehydrate.ts +2 -0
- package/server/src/explorerDocs.ts +75 -34
- 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 +11 -25
- package/server/src/http/writeConfinement.ts +13 -2
- package/server/src/primitives/seedWorker.ts +3 -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 -2
- package/server/src/providers/codexCodeMode.ts +8 -3
- package/server/src/workers/WorkerManager.ts +2 -0
- package/server/src/workers/processKill.ts +35 -7
- package/server/src/ws/handoffHandlers.ts +2 -0
- package/server/src/ws/turnEngine.ts +15 -0
- package/shared/dist/protocol/chat.d.ts +1 -0
- package/shared/dist/protocol/clusters.d.ts +2 -0
- package/shared/dist/protocol/serverMessages.d.ts +11 -0
- package/shared/dist/protocol/workflows.d.ts +1 -0
- package/shared/src/protocol/chat.ts +1 -0
- package/shared/src/protocol/clusters.ts +4 -5
- package/shared/src/protocol/serverMessages.ts +11 -0
- package/shared/src/protocol/workflows.ts +4 -0
|
@@ -112,7 +112,7 @@ export async function resolveBoundCwd(callerCwd, workflowId) {
|
|
|
112
112
|
...clusterStore.listKnownClusterIds().map(id => clusterStore.getClusterCached(id)?.cwd)];
|
|
113
113
|
for (const root of live) {
|
|
114
114
|
try {
|
|
115
|
-
if (root &&
|
|
115
|
+
if (root && sameDirectory(canonical, root))
|
|
116
116
|
return { ok: true, cwd: callerCwd };
|
|
117
117
|
}
|
|
118
118
|
catch { /* protected or stale root */ }
|
|
@@ -120,13 +120,30 @@ export async function resolveBoundCwd(callerCwd, workflowId) {
|
|
|
120
120
|
const roots = await knownRoots();
|
|
121
121
|
for (const root of roots) {
|
|
122
122
|
try {
|
|
123
|
-
if (
|
|
123
|
+
if (sameDirectory(canonical, root))
|
|
124
124
|
return { ok: true, cwd: callerCwd };
|
|
125
125
|
}
|
|
126
126
|
catch { /* protected or stale root */ }
|
|
127
127
|
}
|
|
128
128
|
return { ok: false, reason: 'unknown-cwd' };
|
|
129
129
|
}
|
|
130
|
+
// Node's JavaScript realpath keeps a Windows 8.3 short name and the letter
|
|
131
|
+
// case as written, while the native resolver (used by the document list)
|
|
132
|
+
// expands both. A known root and a caller cwd that name the same directory in
|
|
133
|
+
// different spellings still match; both sides pass safeDirectory first.
|
|
134
|
+
function sameDirectory(canonical, root) {
|
|
135
|
+
const other = safeDirectory(root);
|
|
136
|
+
if (other === canonical)
|
|
137
|
+
return true;
|
|
138
|
+
if (process.platform !== 'win32')
|
|
139
|
+
return false;
|
|
140
|
+
try {
|
|
141
|
+
return realpathSync.native(other) === realpathSync.native(canonical);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
130
147
|
export function boundCwdError(reason) {
|
|
131
148
|
switch (reason) {
|
|
132
149
|
case 'none': return 'cwd or a workflow id with a bound cwd is required';
|
|
@@ -50,6 +50,7 @@ export declare function runPrimaryTurn(ctx: TurnContext, args: {
|
|
|
50
50
|
incognito?: boolean;
|
|
51
51
|
drainSteer?: () => SteerItem[];
|
|
52
52
|
peekSteer?: () => readonly SteerItem[];
|
|
53
|
+
pendingInput?: WorkerConfig['pendingInput'];
|
|
53
54
|
requeueSteer?: (items: SteerItem[], bucket: 'steer' | 'follow-up') => void;
|
|
54
55
|
onSteerDelivered?: (items: SteerItem[]) => void;
|
|
55
56
|
codexTransport?: 'exec' | 'appserver';
|
|
@@ -129,7 +129,7 @@ function emitWorkerStuck(ctx, toolName, verdict) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
export function runPrimaryTurn(ctx, args) {
|
|
132
|
-
const { primary, prompt, resumeSessionId, attachments, disableRssGuard, appendSystemPrompt, systemPrompt, interactionMode, disableProviderHooks, chatWebAccess, voiceOperator, incognito, drainSteer, peekSteer, requeueSteer, onSteerDelivered, codexTransport, codexContextPolicy, providerAccountRef, codexHome, claudeTransport, ultracode, claudeNativeTaskDisabled, claudeNativeSubagent, claudeNativeCompact, claudeNativeInTurnCompactPercent, claudeNativeForceInterleavedThinkingBeta, claudeNativeThinkingDisplay, nativeSubagents, claudeNativePlanModeArmed, turnNotice, efficiencyToolFilter, efficiencyFactForce, efficiencyConfigProtection, efficiencySandbox, reviewSafeMode, outputStyle, goal, toolPosture, clusterId, clusterAccessMode, executionCwd, persistenceCwd, clusterTaskBoardAttached, clusterPlan, clusterRole, clusterEfficiencyDoctrine, clusterProgressDoctrine, clusterMcpConfigPath, codebaseMemoryAttached, codebaseMemoryIndexPath, mcpRegistryServers, mcpDisallowedTools, ollamaParams, webSearchMaxUses } = args;
|
|
132
|
+
const { primary, prompt, resumeSessionId, attachments, disableRssGuard, appendSystemPrompt, systemPrompt, interactionMode, disableProviderHooks, chatWebAccess, voiceOperator, incognito, drainSteer, peekSteer, pendingInput, requeueSteer, onSteerDelivered, codexTransport, codexContextPolicy, providerAccountRef, codexHome, claudeTransport, ultracode, claudeNativeTaskDisabled, claudeNativeSubagent, claudeNativeCompact, claudeNativeInTurnCompactPercent, claudeNativeForceInterleavedThinkingBeta, claudeNativeThinkingDisplay, nativeSubagents, claudeNativePlanModeArmed, turnNotice, efficiencyToolFilter, efficiencyFactForce, efficiencyConfigProtection, efficiencySandbox, reviewSafeMode, outputStyle, goal, toolPosture, clusterId, clusterAccessMode, executionCwd, persistenceCwd, clusterTaskBoardAttached, clusterPlan, clusterRole, clusterEfficiencyDoctrine, clusterProgressDoctrine, clusterMcpConfigPath, codebaseMemoryAttached, codebaseMemoryIndexPath, mcpRegistryServers, mcpDisallowedTools, ollamaParams, webSearchMaxUses } = args;
|
|
133
133
|
const workerId = `primary-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
|
134
134
|
// Claude: pre-mint on first turn so meta.json can pin it before the CLI
|
|
135
135
|
// even starts. Codex mints its own; we'll learn it via the init event.
|
|
@@ -169,6 +169,7 @@ export function runPrimaryTurn(ctx, args) {
|
|
|
169
169
|
disableRssGuard,
|
|
170
170
|
drainSteer,
|
|
171
171
|
peekSteer,
|
|
172
|
+
pendingInput,
|
|
172
173
|
requeueSteer,
|
|
173
174
|
onSteerDelivered,
|
|
174
175
|
codexTransport,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HeldCommandResult } from './lateCommands.js';
|
|
2
|
+
export declare const HELD_WAIT_LIMIT_MS: number;
|
|
3
|
+
export declare const HELD_CONTINUATION_LIMIT = 20;
|
|
4
|
+
export declare const HELD_OUTPUT_CHARS = 4000;
|
|
5
|
+
export declare const HELD_RESULTS_WITH_OUTPUT = 8;
|
|
6
|
+
export declare const HELD_BATCH_MS = 2000;
|
|
7
|
+
export declare function formatDuration(ms: number): string;
|
|
8
|
+
export declare function shortCommand(command: string, max?: number): string;
|
|
9
|
+
/** The operator-visible line for one delivered result. */
|
|
10
|
+
export declare function heldResultNotice(result: HeldCommandResult, continues: boolean): string;
|
|
11
|
+
/** The text Codex receives: each result once, output tail capped. */
|
|
12
|
+
export declare function heldResultsMessage(results: HeldCommandResult[], stillRunning: Array<{
|
|
13
|
+
command: string;
|
|
14
|
+
}>): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export const HELD_WAIT_LIMIT_MS = 30 * 60_000;
|
|
2
|
+
export const HELD_CONTINUATION_LIMIT = 20;
|
|
3
|
+
export const HELD_OUTPUT_CHARS = 4_000;
|
|
4
|
+
// Results in one message; any further results in the same batch keep their
|
|
5
|
+
// exit code but not their output.
|
|
6
|
+
export const HELD_RESULTS_WITH_OUTPUT = 8;
|
|
7
|
+
// Ends this close together go to the agent in one continuation.
|
|
8
|
+
export const HELD_BATCH_MS = 2_000;
|
|
9
|
+
export function formatDuration(ms) {
|
|
10
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
11
|
+
if (seconds < 60)
|
|
12
|
+
return `${seconds}s`;
|
|
13
|
+
const minutes = Math.floor(seconds / 60);
|
|
14
|
+
if (minutes < 60)
|
|
15
|
+
return `${minutes}m ${seconds % 60}s`;
|
|
16
|
+
return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
|
|
17
|
+
}
|
|
18
|
+
export function shortCommand(command, max = 160) {
|
|
19
|
+
const flat = command.replace(/\s+/g, ' ').trim();
|
|
20
|
+
return flat.length > max ? `${flat.slice(0, max - 3)}...` : flat;
|
|
21
|
+
}
|
|
22
|
+
function outcome(result) {
|
|
23
|
+
return typeof result.exitCode === 'number' ? `exit ${result.exitCode}` : result.failed ? 'failed' : 'ended';
|
|
24
|
+
}
|
|
25
|
+
/** The operator-visible line for one delivered result. */
|
|
26
|
+
export function heldResultNotice(result, continues) {
|
|
27
|
+
return `Command ended: \`${shortCommand(result.command)}\` - ${outcome(result)} after ${formatDuration(result.endedAt - result.startedAt)}.${continues ? ' Codex continues.' : ''}`;
|
|
28
|
+
}
|
|
29
|
+
/** The text Codex receives: each result once, output tail capped. */
|
|
30
|
+
export function heldResultsMessage(results, stillRunning) {
|
|
31
|
+
const parts = ['[Arco] A command you started has ended since your last reply. This is its result, observed by Arco; it is not from the operator.'];
|
|
32
|
+
results.forEach((result, index) => {
|
|
33
|
+
const lines = [
|
|
34
|
+
`Command: ${result.command}`,
|
|
35
|
+
...(result.cwd ? [`Working directory: ${result.cwd}`] : []),
|
|
36
|
+
`Result: ${outcome(result)} after ${formatDuration(result.endedAt - result.startedAt)}`,
|
|
37
|
+
];
|
|
38
|
+
if (index < HELD_RESULTS_WITH_OUTPUT) {
|
|
39
|
+
const output = result.output ?? '';
|
|
40
|
+
const tail = output.length > HELD_OUTPUT_CHARS ? output.slice(-HELD_OUTPUT_CHARS) : output;
|
|
41
|
+
lines.push(output.length > HELD_OUTPUT_CHARS
|
|
42
|
+
? `Output (last ${HELD_OUTPUT_CHARS} of ${output.length} characters):\n${tail}`
|
|
43
|
+
: `Output:\n${tail || '(none)'}`);
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
lines.push('Output: not included; too many results in one message.');
|
|
47
|
+
parts.push(lines.join('\n'));
|
|
48
|
+
});
|
|
49
|
+
if (stillRunning.length)
|
|
50
|
+
parts.push(`Still running: ${stillRunning.map(item => shortCommand(item.command)).join('; ')}. Arco tells you when ${stillRunning.length === 1 ? 'it ends' : 'they end'}.`);
|
|
51
|
+
parts.push('Continue the work.');
|
|
52
|
+
return parts.join('\n\n');
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=heldCommands.js.map
|
|
@@ -1,5 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import type { WorkerConfig, WorkerStatus } from '@arco/shared';
|
|
3
|
+
import type { Provider, ProviderProcess } from '../types.js';
|
|
4
|
+
import { CodexAppServerWorker } from './worker.js';
|
|
5
|
+
export declare class CodexAppServerTurn extends EventEmitter implements ProviderProcess {
|
|
6
|
+
private readonly worker;
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly appendSystemPrompt;
|
|
9
|
+
private readonly workflowId;
|
|
10
|
+
readonly id: string;
|
|
11
|
+
private _status;
|
|
12
|
+
private _output;
|
|
13
|
+
private settled;
|
|
14
|
+
private wired;
|
|
15
|
+
private fatalSeen;
|
|
16
|
+
private watchdog?;
|
|
17
|
+
private stopToolObserver?;
|
|
18
|
+
private timeoutReason?;
|
|
19
|
+
private readonly startedAt;
|
|
20
|
+
private costUsd;
|
|
21
|
+
private lastResult?;
|
|
22
|
+
private continuations;
|
|
23
|
+
private waitedMs;
|
|
24
|
+
private waitStartedAt;
|
|
25
|
+
private waitTimer?;
|
|
26
|
+
private inputTimer?;
|
|
27
|
+
private batchTimer?;
|
|
28
|
+
private resultSteer?;
|
|
29
|
+
private stopped;
|
|
30
|
+
private interrupting;
|
|
31
|
+
constructor(id: string, worker: CodexAppServerWorker, config: WorkerConfig, appendSystemPrompt: string | undefined, workflowId: string);
|
|
32
|
+
get status(): WorkerStatus;
|
|
33
|
+
get output(): string;
|
|
34
|
+
get pid(): number | undefined;
|
|
35
|
+
spawn(prompt: string): void;
|
|
36
|
+
interrupt(): Promise<void>;
|
|
37
|
+
kill(): void;
|
|
38
|
+
private wireListeners;
|
|
39
|
+
private unwire;
|
|
40
|
+
private fail;
|
|
41
|
+
private afterCodexTurn;
|
|
42
|
+
private startWait;
|
|
43
|
+
private stopWaitClock;
|
|
44
|
+
private reviewWait;
|
|
45
|
+
private checkInput;
|
|
46
|
+
private continueWith;
|
|
47
|
+
private steerResults;
|
|
48
|
+
private runningLabel;
|
|
49
|
+
private giveUp;
|
|
50
|
+
private finish;
|
|
51
|
+
}
|
|
52
|
+
export declare function runningCodexLateCommands(workflowId: string): import("@arco/shared").CodexLateCommand[];
|
|
3
53
|
export declare function compactCodexAppServerThread(workflowId: string, config?: WorkerConfig, resumeSessionId?: string, stillOwner?: () => boolean): Promise<{
|
|
4
54
|
ok: boolean;
|
|
5
55
|
error?: string;
|
|
@@ -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
|
+
}
|