arco-workbench 0.1.6 → 0.1.8
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 +52 -12
- package/README.md +20 -13
- package/client/dist/assets/{PhosphorBackdrop-BR-TgB5x.js → PhosphorBackdrop-D7jdAV_G.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-DgcFj6JN.js → ThemedBackgroundShaderImpl-DrDm60h8.js} +1 -1
- package/client/dist/assets/{XtermView-CflVBQgC.js → XtermView-BGFujb1e.js} +1 -1
- package/client/dist/assets/{galleryEditor-BB-emfmi.js → galleryEditor-D951A2sE.js} +1 -1
- package/client/dist/assets/{index-B_EqHDz3.js → index-CsVy3eZm.js} +248 -248
- package/client/dist/index.html +1 -1
- package/client/src/buildCheck.ts +3 -1
- package/client/src/components/AppUpdateNotice.tsx +2 -1
- package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +24 -12
- package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +65 -15
- package/client/src/components/ClusterRightPanel/SkillsControl.tsx +107 -0
- package/client/src/components/ClusterRightPanel/index.tsx +6 -1
- package/client/src/components/ClusterTaskBoardTab.tsx +9 -22
- package/client/src/components/HeaderVersionBox.tsx +7 -4
- package/client/src/components/NeedsYouBadge.tsx +3 -3
- package/client/src/components/ProviderReleasesModal.tsx +8 -4
- package/client/src/components/ProvidersPopover.tsx +28 -23
- package/client/src/components/SettingsPanel.tsx +2 -2
- package/client/src/components/SkillsSettings.tsx +5 -0
- package/client/src/components/TabBar.tsx +91 -9
- package/client/src/components/TerminalInput.tsx +12 -10
- package/client/src/components/TranscriptSendDialog.tsx +12 -8
- package/client/src/components/TranscriptWorkerDialog.tsx +119 -0
- package/client/src/components/UpdateAction.tsx +18 -4
- package/client/src/components/UpdateResultNotice.tsx +3 -1
- package/client/src/components/clusterNeedsYou.ts +11 -18
- package/client/src/help/content/cluster.tsx +54 -22
- package/client/src/help/content/composer.tsx +22 -0
- package/client/src/help/content/header.tsx +19 -1
- package/client/src/help/content/misc.tsx +8 -0
- package/client/src/help/content/rightPanel.tsx +1 -1
- package/client/src/help/content/settings.tsx +19 -5
- 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 +58 -21
- package/client/src/help/manualSections/configuration.tsx +38 -4
- package/client/src/help/manualSections/maintenance.tsx +30 -0
- package/client/src/help/manualSections/plans.tsx +5 -1
- 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 +19 -0
- package/client/src/help/manualSections/workspace.tsx +6 -0
- package/client/src/stores/appUpdateStore.ts +29 -8
- package/client/src/utils/transcriptWorkerRequest.ts +24 -0
- package/client/src/utils/wsSession.ts +2 -1
- package/client/src/ws/handleServerMessage.ts +8 -2
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/CLIENT.md +9 -8
- package/docs/FEATURES.md +8 -5
- package/docs/GETTING_STARTED.md +9 -4
- package/docs/GOTCHAS.md +2 -1
- package/docs/OPERATIONS.md +37 -4
- package/docs/PERSISTENCE.md +25 -3
- package/docs/PRIMITIVES.md +42 -0
- package/docs/PROTOCOL_CLUSTER.md +51 -5
- package/docs/PROTOCOL_PRIMITIVES.md +39 -0
- package/docs/PROVIDERS.md +50 -13
- package/docs/SETTINGS.md +27 -3
- package/docs/TASK_LEDGER.md +7 -15
- 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/autoPickup.d.ts +3 -0
- package/node_modules/@arco/shared/dist/protocol/clientMessages.d.ts +3 -2
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +13 -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 +2 -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/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 +78 -12
- package/scripts/packaging/update.mjs +5 -1
- 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/clusterAutoTurn.d.ts +4 -0
- package/server/dist/clusterAutoTurn.js +29 -25
- package/server/dist/clusterBusyReminder.js +1 -1
- package/server/dist/clusterDirector.js +1 -1
- package/server/dist/clusterPeerOps.js +10 -7
- package/server/dist/clusterProgress.js +1 -1
- 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 +10 -2
- package/server/dist/clusterStore.js +64 -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/historyLimits.d.ts +1 -0
- package/server/dist/historyLimits.js +3 -0
- package/server/dist/http/router.js +1 -1
- 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/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.js +2 -1
- package/server/dist/providers/codexCodeMode.d.ts +1 -1
- package/server/dist/providers/codexCodeMode.js +4 -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/smartPickup.d.ts +2 -1
- package/server/dist/smartPickup.js +28 -1
- package/server/dist/smartPickupAdapters.js +15 -2
- package/server/dist/smartPickupLedger.js +6 -4
- package/server/dist/smartPickupObserver.d.ts +1 -0
- package/server/dist/smartPickupObserver.js +24 -15
- package/server/dist/transcriptWorker.d.ts +34 -0
- package/server/dist/transcriptWorker.js +201 -0
- package/server/dist/workflowStore.d.ts +1 -0
- package/server/dist/workflowStore.js +31 -0
- package/server/dist/ws/clusterHandlers.d.ts +2 -0
- package/server/dist/ws/clusterHandlers.js +64 -27
- package/server/dist/ws/handoffHandlers.js +5 -2
- package/server/dist/ws/transcriptWorkerHandlers.d.ts +25 -0
- package/server/dist/ws/transcriptWorkerHandlers.js +139 -0
- package/server/dist/ws/turnEngine.js +23 -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/clusterAutoTurn.ts +26 -21
- package/server/src/clusterBusyReminder.ts +1 -1
- package/server/src/clusterDirector.ts +1 -1
- package/server/src/clusterPeerOps.ts +11 -8
- package/server/src/clusterProgress.ts +1 -1
- package/server/src/clusterSkills.ts +79 -0
- package/server/src/clusterSnapshots.ts +1 -0
- package/server/src/clusterStore.ts +64 -1
- package/server/src/diagnostics/codeSkew.ts +1 -0
- package/server/src/eventLog.ts +73 -13
- package/server/src/historyLimits.ts +2 -0
- package/server/src/http/router.ts +1 -1
- 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/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.ts +2 -1
- package/server/src/providers/codexCodeMode.ts +4 -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/smartPickup.ts +27 -3
- package/server/src/smartPickupAdapters.ts +17 -3
- package/server/src/smartPickupLedger.ts +6 -4
- package/server/src/smartPickupObserver.ts +20 -11
- package/server/src/transcriptWorker.ts +182 -0
- package/server/src/workflowStore.ts +21 -0
- package/server/src/ws/clusterHandlers.ts +46 -27
- package/server/src/ws/handoffHandlers.ts +5 -1
- package/server/src/ws/transcriptWorkerHandlers.ts +126 -0
- package/server/src/ws/turnEngine.ts +20 -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/autoPickup.d.ts +3 -0
- package/shared/dist/protocol/clientMessages.d.ts +3 -2
- package/shared/dist/protocol/clusters.d.ts +13 -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 +2 -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/runtimeVersions.d.ts +1 -0
- package/shared/dist/runtimeVersions.js +14 -0
- package/shared/src/clusterCoordination.ts +7 -1
- package/shared/src/protocol/autoPickup.ts +5 -0
- package/shared/src/protocol/clientMessages.ts +5 -0
- package/shared/src/protocol/clusters.ts +16 -1
- package/shared/src/protocol/index.ts +1 -0
- package/shared/src/protocol/models.ts +31 -5
- package/shared/src/protocol/serverMessages.ts +2 -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/runtimeVersions.ts +14 -0
|
@@ -6,9 +6,11 @@ import { promises as fs } from 'node:fs';
|
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { randomUUID } from 'node:crypto';
|
|
8
8
|
import { atomicWriteFile } from '../../atomicFile.js';
|
|
9
|
-
import {
|
|
9
|
+
import { openLogByteSource, readLogLines, type LogByteSource } from '../../eventLog.js';
|
|
10
|
+
import { jsonlLines } from '../../jsonlLines.js';
|
|
10
11
|
import { serverFoldSeed, type ServerCompactionBlock } from './serverFold.js';
|
|
11
12
|
import { isShellToolName } from '@arco/shared';
|
|
13
|
+
import { RECENT_HISTORY_MAX_BYTES } from '../../historyLimits.js';
|
|
12
14
|
|
|
13
15
|
const isFileRead = (name: string | undefined): boolean => !!name && /^(?:Read|(?:.*__)?(?:read_file|fetch_file))$/i.test(name);
|
|
14
16
|
|
|
@@ -17,6 +19,19 @@ const SUMMARY_CACHE_KIND = 'claude-native-resume-summary';
|
|
|
17
19
|
const DEFAULT_REPLAY_BYTES = 1 * 1024 * 1024;
|
|
18
20
|
const TAIL_LINE_BACKTRACK_BYTES = 1 * 1024 * 1024;
|
|
19
21
|
|
|
22
|
+
// The retained event arrays still amplify source bytes during reconstruction.
|
|
23
|
+
// Refuse an uncached parse beyond the measured default-heap margin; a valid
|
|
24
|
+
// summary cache needs only its small tail and does not parse the old prefix.
|
|
25
|
+
export const NATIVE_RECONSTRUCTION_MAX_BYTES = 1024 * 1024 * 1024;
|
|
26
|
+
export class NativeReconstructionLimitError extends Error {
|
|
27
|
+
readonly code = 'NATIVE_RECONSTRUCTION_LIMIT';
|
|
28
|
+
readonly limitBytes = NATIVE_RECONSTRUCTION_MAX_BYTES;
|
|
29
|
+
constructor(readonly rangeBytes: number) {
|
|
30
|
+
super(`Claude Native reconstruction requires ${rangeBytes} bytes, above the ${NATIVE_RECONSTRUCTION_MAX_BYTES}-byte limit.`);
|
|
31
|
+
this.name = 'NativeReconstructionLimitError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
function readPositiveIntEnv(name: string, fallback: number): number {
|
|
21
36
|
const raw = process.env[name];
|
|
22
37
|
if (!raw) return fallback;
|
|
@@ -118,6 +133,7 @@ export type ResumeReplayResult = {
|
|
|
118
133
|
summaryThroughSeq?: number;
|
|
119
134
|
summaryBytes?: number;
|
|
120
135
|
tailEvents?: number;
|
|
136
|
+
summaryNotice?: string;
|
|
121
137
|
// docs/PERSISTENCE.md - true when a branch-aware (leafSeq)
|
|
122
138
|
// replay walked into ancestry that had rotated off the size-capped log, so
|
|
123
139
|
// the branch was reconstructed from what survived rather than replayed in
|
|
@@ -134,12 +150,14 @@ type SummaryCache = {
|
|
|
134
150
|
throughSeq: number | null;
|
|
135
151
|
lastHandoffSeq: number | null;
|
|
136
152
|
summary: string;
|
|
153
|
+
summaryNotice?: string;
|
|
137
154
|
inputHistory: ReplayEvent[];
|
|
138
155
|
updatedAt: string;
|
|
139
156
|
};
|
|
140
157
|
|
|
141
158
|
type SummaryBuild = {
|
|
142
159
|
summary: string;
|
|
160
|
+
summaryNotice?: string;
|
|
143
161
|
throughSeq: number | null;
|
|
144
162
|
lastHandoffSeq: number | null;
|
|
145
163
|
};
|
|
@@ -148,43 +166,28 @@ function workflowDir(cwd: string, workflowId: string): string {
|
|
|
148
166
|
return join(cwd, '.arco', 'workflows', workflowId);
|
|
149
167
|
}
|
|
150
168
|
|
|
151
|
-
function eventsPath(cwd: string, workflowId: string): string {
|
|
152
|
-
return join(workflowDir(cwd, workflowId), 'events.jsonl');
|
|
153
|
-
}
|
|
154
|
-
|
|
155
169
|
function summaryCachePath(cwd: string, workflowId: string): string {
|
|
156
170
|
return join(workflowDir(cwd, workflowId), 'resume-summary.json');
|
|
157
171
|
}
|
|
158
172
|
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
interface LogSource { size: number; read(start: number, length: number): Promise<string> }
|
|
173
|
+
// Only the byte source changes here. Replay projection, summary boundaries,
|
|
174
|
+
// branch ancestry and cache keys continue to use their existing rules.
|
|
175
|
+
type LogSource = LogByteSource;
|
|
163
176
|
async function openLogSource(cwd: string, workflowId: string): Promise<LogSource | null> {
|
|
164
|
-
|
|
165
|
-
if ((await listSegments(dir)).length > 0) {
|
|
166
|
-
const text = Buffer.from(await readLogText(dir), 'utf8');
|
|
167
|
-
return { size: text.length, read: async (start, length) => text.subarray(start, start + length).toString('utf8') };
|
|
168
|
-
}
|
|
169
|
-
const path = eventsPath(cwd, workflowId);
|
|
170
|
-
try {
|
|
171
|
-
const size = (await fs.stat(path)).size;
|
|
172
|
-
return { size, read: (start, length) => readByteRange(path, start, length) };
|
|
173
|
-
} catch (err) {
|
|
174
|
-
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return null;
|
|
175
|
-
throw err;
|
|
176
|
-
}
|
|
177
|
+
return openLogByteSource(workflowDir(cwd, workflowId));
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
async function
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
async function readSourceEvents(source: LogSource, length: number, dropLastPartial = false): Promise<ReplayEvent[]> {
|
|
181
|
+
if (length > NATIVE_RECONSTRUCTION_MAX_BYTES) throw new NativeReconstructionLimitError(length);
|
|
182
|
+
const events: ReplayEvent[] = [];
|
|
183
|
+
for await (const line of jsonlLines(source.chunks(0, length), 'conversation replay', {
|
|
184
|
+
finalLine: !dropLastPartial, carriageReturns: false,
|
|
185
|
+
})) {
|
|
186
|
+
if (!line) continue;
|
|
187
|
+
try { events.push(JSON.parse(line) as ReplayEvent); }
|
|
188
|
+
catch { /* Match parseJsonl: corrupt or partial records remain untouched. */ }
|
|
187
189
|
}
|
|
190
|
+
return events;
|
|
188
191
|
}
|
|
189
192
|
|
|
190
193
|
async function findTailReplayStart(source: LogSource, desiredStart: number): Promise<{ start: number; completeLine: boolean }> {
|
|
@@ -560,20 +563,25 @@ export function summarizeClaudeNativePriorTurns(events: ReplayEvent[], laterEven
|
|
|
560
563
|
|
|
561
564
|
if (turns.length === 0 && !compactSummary) return { summary: '', throughSeq, lastHandoffSeq };
|
|
562
565
|
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
lines.push(compactSummary.trim());
|
|
568
|
-
if (compactTail) {
|
|
566
|
+
const renderPrefix = (summary = compactSummary, tail = compactTail): string => {
|
|
567
|
+
const lines: string[] = [];
|
|
568
|
+
if (compactSummary) {
|
|
569
|
+
lines.push('## Earlier context (operator-compacted)');
|
|
569
570
|
lines.push('');
|
|
570
|
-
lines.push(
|
|
571
|
-
|
|
571
|
+
lines.push(summary?.trim() ?? '');
|
|
572
|
+
if (tail) {
|
|
573
|
+
lines.push('');
|
|
574
|
+
lines.push('### Recent verbatim turns kept at that compaction');
|
|
575
|
+
lines.push(tail);
|
|
576
|
+
}
|
|
577
|
+
if (turns.length > 0) lines.push('');
|
|
572
578
|
}
|
|
573
|
-
if (turns.length > 0) lines.push('');
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
579
|
+
if (turns.length > 0) lines.push('## Prior turns in this workflow (auto-summary)');
|
|
580
|
+
return lines.join('\n');
|
|
581
|
+
};
|
|
582
|
+
let prefix = renderPrefix();
|
|
583
|
+
const notes = turns.map((t, i) => {
|
|
584
|
+
const lines: string[] = [];
|
|
577
585
|
const head = t.userText.length > 120 ? t.userText.slice(0, 120) + '...' : t.userText;
|
|
578
586
|
lines.push('');
|
|
579
587
|
lines.push(`### Turn ${i + 1}: ${head}`);
|
|
@@ -600,8 +608,43 @@ export function summarizeClaudeNativePriorTurns(events: ReplayEvent[], laterEven
|
|
|
600
608
|
const reply = t.finalReply.trim().replace(/\s+/g, ' ').slice(0, 240);
|
|
601
609
|
lines.push(`- Assistant reply: "${reply}${t.finalReply.length > 240 ? '...' : ''}"`);
|
|
602
610
|
}
|
|
611
|
+
return lines.join('\n');
|
|
603
612
|
});
|
|
604
|
-
|
|
613
|
+
const noteBytes = notes.map(note => Buffer.byteLength(note, 'utf8') + 1);
|
|
614
|
+
let retainedBytes = noteBytes.reduce((sum, bytes) => sum + bytes, 0);
|
|
615
|
+
if (Buffer.byteLength(prefix, 'utf8') + retainedBytes <= RECENT_HISTORY_MAX_BYTES) {
|
|
616
|
+
return { summary: [prefix, ...notes].join('\n'), throughSeq, lastHandoffSeq };
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
let omitted = 0;
|
|
620
|
+
let shortened = false;
|
|
621
|
+
const notice = () => `Earlier context: ${omitted} oldest turn note${omitted === 1 ? '' : 's'} ${omitted === 1 ? 'was' : 'were'} left out${shortened ? ' and compacted context was shortened' : ''} to stay within 128 KiB.`;
|
|
622
|
+
const prefixBytes = Buffer.byteLength(prefix, 'utf8');
|
|
623
|
+
while (omitted < notes.length && prefixBytes + 1 + Buffer.byteLength(notice(), 'utf8') + retainedBytes > RECENT_HISTORY_MAX_BYTES) {
|
|
624
|
+
retainedBytes -= noteBytes[omitted++];
|
|
625
|
+
}
|
|
626
|
+
if (prefixBytes + 1 + Buffer.byteLength(notice(), 'utf8') > RECENT_HISTORY_MAX_BYTES) {
|
|
627
|
+
// The compacted context itself can be larger than the budget. Preserve its
|
|
628
|
+
// kept-tail digest first, then as much summary text as fits, without cutting
|
|
629
|
+
// a UTF-8 character. The same notice discloses this exceptional shortening.
|
|
630
|
+
shortened = true;
|
|
631
|
+
const budget = RECENT_HISTORY_MAX_BYTES - Buffer.byteLength(notice(), 'utf8') - 1;
|
|
632
|
+
const clip = (text: string, bytes: number): string => {
|
|
633
|
+
const encoded = Buffer.from(text, 'utf8');
|
|
634
|
+
let end = Math.min(encoded.length, Math.max(0, bytes));
|
|
635
|
+
while (end > 0 && (encoded[end] & 0xc0) === 0x80) end--;
|
|
636
|
+
return encoded.subarray(0, end).toString('utf8');
|
|
637
|
+
};
|
|
638
|
+
const tailPrefix = renderPrefix('', compactTail);
|
|
639
|
+
if (Buffer.byteLength(tailPrefix, 'utf8') <= budget) {
|
|
640
|
+
prefix = renderPrefix(clip(compactSummary?.trim() ?? '', budget - Buffer.byteLength(tailPrefix, 'utf8')), compactTail);
|
|
641
|
+
} else {
|
|
642
|
+
const overhead = Buffer.byteLength(renderPrefix('', 'x'), 'utf8') - 1;
|
|
643
|
+
prefix = renderPrefix('', clip(compactTail ?? '', budget - overhead));
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
const summaryNotice = notice();
|
|
647
|
+
return { summary: [prefix, summaryNotice, ...notes.slice(omitted)].join('\n'), summaryNotice, throughSeq, lastHandoffSeq };
|
|
605
648
|
}
|
|
606
649
|
|
|
607
650
|
async function readSummaryCache(path: string, workflowId: string, sourceSize: number, tailStartByte: number): Promise<SummaryCache | null> {
|
|
@@ -614,7 +657,8 @@ async function readSummaryCache(path: string, workflowId: string, sourceSize: nu
|
|
|
614
657
|
parsed.workflowId === workflowId &&
|
|
615
658
|
parsed.sourceSize === sourceSize &&
|
|
616
659
|
parsed.tailStartByte === tailStartByte &&
|
|
617
|
-
typeof parsed.summary === 'string' && Array.isArray(parsed.inputHistory)
|
|
660
|
+
typeof parsed.summary === 'string' && Buffer.byteLength(parsed.summary, 'utf8') <= RECENT_HISTORY_MAX_BYTES && Array.isArray(parsed.inputHistory)
|
|
661
|
+
&& (parsed.summaryNotice === undefined || typeof parsed.summaryNotice === 'string')
|
|
618
662
|
&& parsed.inputHistory.every(event => (event?.type === 'user_message_echo' && typeof event.content === 'string') || (event?.type === 'queued_messages_drained' && typeof event.deliveryId === 'string'))
|
|
619
663
|
) {
|
|
620
664
|
return parsed as SummaryCache;
|
|
@@ -645,6 +689,11 @@ export async function replayMessagesWithResumePolicy(
|
|
|
645
689
|
): Promise<ResumeReplayResult> {
|
|
646
690
|
const source = await openLogSource(cwd, workflowId);
|
|
647
691
|
if (!source) return { messages: [], mode: 'empty', eventBytes: 0 };
|
|
692
|
+
try { return await replayFromSource(cwd, workflowId, source, maxSeq, opts); }
|
|
693
|
+
finally { await source.close(); }
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
async function replayFromSource(cwd: string, workflowId: string, source: LogSource, maxSeq: number | undefined, opts: ReplayOptions): Promise<ResumeReplayResult> {
|
|
648
697
|
const stat = { size: source.size };
|
|
649
698
|
|
|
650
699
|
const exactReplayBytes = opts.exactReplayBytes ?? RESUME_EXACT_REPLAY_BYTES;
|
|
@@ -664,8 +713,7 @@ export async function replayMessagesWithResumePolicy(
|
|
|
664
713
|
// This is what lets post-rewind turns be included WITHOUT advancing leafSeq
|
|
665
714
|
// on every turn.
|
|
666
715
|
if (typeof opts.leafSeq === 'number') {
|
|
667
|
-
const
|
|
668
|
-
const events = parseJsonl(raw);
|
|
716
|
+
const events = await readSourceEvents(source, stat.size);
|
|
669
717
|
let tailSeq: number | undefined;
|
|
670
718
|
for (const e of events) {
|
|
671
719
|
if (typeof e.seq === 'number' && (tailSeq === undefined || e.seq > tailSeq)) tailSeq = e.seq;
|
|
@@ -681,8 +729,7 @@ export async function replayMessagesWithResumePolicy(
|
|
|
681
729
|
}
|
|
682
730
|
|
|
683
731
|
if (stat.size <= exactReplayBytes) {
|
|
684
|
-
const
|
|
685
|
-
const events = parseJsonl(raw);
|
|
732
|
+
const events = await readSourceEvents(source, stat.size);
|
|
686
733
|
return {
|
|
687
734
|
messages: buildMessagesFromReplayEvents(events, [], maxSeq, undefined, [], opts.attachmentMarkers),
|
|
688
735
|
mode: 'exact',
|
|
@@ -717,8 +764,7 @@ export async function replayMessagesWithResumePolicy(
|
|
|
717
764
|
const cachePath = summaryCachePath(cwd, workflowId);
|
|
718
765
|
let cache = opts.attachmentMarkers ? null : await readSummaryCache(cachePath, workflowId, stat.size, tailStartByte);
|
|
719
766
|
if (!cache) {
|
|
720
|
-
const
|
|
721
|
-
const olderEvents = parseJsonl(olderRaw, { dropLastPartial: !tailStart.completeLine });
|
|
767
|
+
const olderEvents = await readSourceEvents(source, tailStartByte, !tailStart.completeLine);
|
|
722
768
|
const built = summarizeClaudeNativePriorTurns(olderEvents, tailEvents, !!opts.attachmentMarkers);
|
|
723
769
|
if (opts.attachmentMarkers) {
|
|
724
770
|
const lastOlderSeq = olderEvents.reduce((max, event) => Math.max(max, event.seq ?? 0), 0);
|
|
@@ -739,6 +785,7 @@ export async function replayMessagesWithResumePolicy(
|
|
|
739
785
|
throughSeq: built.throughSeq,
|
|
740
786
|
lastHandoffSeq: built.lastHandoffSeq,
|
|
741
787
|
summary: built.summary,
|
|
788
|
+
summaryNotice: built.summaryNotice,
|
|
742
789
|
inputHistory: referencedInputRecords(tailEvents, olderEvents),
|
|
743
790
|
updatedAt: new Date().toISOString(),
|
|
744
791
|
};
|
|
@@ -753,5 +800,6 @@ export async function replayMessagesWithResumePolicy(
|
|
|
753
800
|
summaryThroughSeq: cache.throughSeq ?? undefined,
|
|
754
801
|
summaryBytes: cache.summary.length,
|
|
755
802
|
tailEvents: tailEvents.length,
|
|
803
|
+
...(cache.summaryNotice ? { summaryNotice: cache.summaryNotice } : {}),
|
|
756
804
|
};
|
|
757
805
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setMaxListeners } from 'node:events';
|
|
2
2
|
import { assertNativeTaskAllowed } from './taskAdmission.js';
|
|
3
3
|
import { readSettings } from '../../settings.js';
|
|
4
|
-
import { resolveNativeSubagents, type NativeSubagentPolicy } from '@arco/shared';
|
|
4
|
+
import { buildTurnWaitInstructions, resolveNativeSubagents, type NativeSubagentPolicy } from '@arco/shared';
|
|
5
5
|
import { availableHandoffSources, executeHandoffHistory, HANDOFF_HISTORY_TOOL, HANDOFF_HISTORY_CONTEXT } from '../../handoffHistoryTool.js';
|
|
6
6
|
import { mediaRetirementNotice } from './mediaRetirementNotice.js';
|
|
7
7
|
import { nativeMediaLimits } from './mediaLimits.js';
|
|
@@ -15,6 +15,7 @@ import { nativeOAuthBaseUrl } from './apiEndpoint.js';
|
|
|
15
15
|
import { createHash } from 'node:crypto';
|
|
16
16
|
import { ensureProjectStateIgnore } from '../../projectStateIgnore.js';
|
|
17
17
|
import { replayEventsWithTs } from '../../workflowStore.js';
|
|
18
|
+
import { reportHistoryLoadFailure } from '../../providerConversation.js';
|
|
18
19
|
import { computerToolDefinitions, executeComputerTool } from '../../voice/toolDefinitions.js';
|
|
19
20
|
// Phase 7a — long-lived per-workflow Claude Native worker.
|
|
20
21
|
//
|
|
@@ -58,7 +59,7 @@ import { getPeerToolDefinitions, isPeerTool, executePeerTool } from './peerTools
|
|
|
58
59
|
import { registryToolDefs, parseRegistryToolName, isRegistryToolAllowed, isRegistryToolReadOnly } from './registryTools.js';
|
|
59
60
|
import { connectServer, type McpSession } from '../../mcp/client.js';
|
|
60
61
|
import { getSandboxToolDefinitions, isSandboxTool, executeSandboxTool } from './sandboxTools.js';
|
|
61
|
-
import { buildMessagesFromReplayEvents, replayMessagesWithResumePolicy, compactSummarySeed, type ClaudeResumeMessage } from './resumeSummary.js';
|
|
62
|
+
import { buildMessagesFromReplayEvents, replayMessagesWithResumePolicy, compactSummarySeed, NativeReconstructionLimitError, type ClaudeResumeMessage } from './resumeSummary.js';
|
|
62
63
|
import { readMeta, setResolvedModelId } from '../../workflowMeta.js';
|
|
63
64
|
import { lspManager } from '../../lsp/client.js';
|
|
64
65
|
import { isClaudeServerToolDef, isServerToolResultType, pendingServerTools, pruneServerToolEvidenceAfterTurn, stripDanglingServerToolResults } from './retainedContext.js';
|
|
@@ -1468,10 +1469,11 @@ export class ClaudeNativeWorker extends EventEmitter {
|
|
|
1468
1469
|
.filter((e) => meta?.computerContext?.lastResetSeq !== undefined
|
|
1469
1470
|
? (('seq' in e.message && typeof e.message.seq === 'number') ? e.message.seq : 0) > meta.computerContext.lastResetSeq
|
|
1470
1471
|
: e.ts > (meta?.computerContext?.lastResetAt ?? 0)).map((e) => e.message) as unknown as Parameters<typeof buildMessagesFromReplayEvents>[0]),
|
|
1471
|
-
mode: 'exact', reconstructed: false, summaryThroughSeq: undefined, tailEvents: undefined }
|
|
1472
|
+
mode: 'exact', reconstructed: false, summaryThroughSeq: undefined, tailEvents: undefined, summaryNotice: undefined }
|
|
1472
1473
|
: await replayMessagesWithResumePolicy(cwd, this.workflowId, undefined, { leafSeq: meta?.leafSeq, attachmentMarkers });
|
|
1473
1474
|
this.messages = attachmentMarkers ? await restoreChatAttachments(replay.messages as MessageParam[], attachmentMarkers) : replay.messages as MessageParam[];
|
|
1474
1475
|
this.resetPrefixFreeze('replay');
|
|
1476
|
+
if (replay.summaryNotice) this.emit('system_notice', replay.summaryNotice);
|
|
1475
1477
|
if (replay.reconstructed) {
|
|
1476
1478
|
// docs/PERSISTENCE.md - the rewound branch's ancestry
|
|
1477
1479
|
// had rotated off the size-capped log, so this is a RECONSTRUCTED
|
|
@@ -1488,6 +1490,8 @@ export class ClaudeNativeWorker extends EventEmitter {
|
|
|
1488
1490
|
}
|
|
1489
1491
|
} catch (err) {
|
|
1490
1492
|
console.warn(`[claude-native:${this.workflowId.slice(0, 8)}] replay failed:`, err);
|
|
1493
|
+
reportHistoryLoadFailure(this.workflowId, this, 'native', content => this.emit('system_notice', content),
|
|
1494
|
+
err instanceof NativeReconstructionLimitError ? err.limitBytes : undefined);
|
|
1491
1495
|
}
|
|
1492
1496
|
}
|
|
1493
1497
|
this.replayed = true;
|
|
@@ -2068,7 +2072,7 @@ export class ClaudeNativeWorker extends EventEmitter {
|
|
|
2068
2072
|
'Continue working until the request is complete or you are genuinely blocked on operator input. ' +
|
|
2069
2073
|
"Never end your turn with a status update, a plan, or a promise of future work ('Continuing now', 'I'll do X next') — " +
|
|
2070
2074
|
'if your final paragraph describes work you have not done, do that work now instead of ending the turn. ' +
|
|
2071
|
-
|
|
2075
|
+
buildTurnWaitInstructions(this.config.clusterRole) + ' ' +
|
|
2072
2076
|
'If a delegated Task child fails or returns an error or nonsense (e.g. a login error), say so explicitly in your reply and adapt openly — never silently work around a failed delegation. ' +
|
|
2073
2077
|
// Fable 5.1 / 5.2 can rewrite whole files where a targeted edit would do
|
|
2074
2078
|
// (docs/PROVIDERS.md); Anthropic's documented one-liner.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildTurnWaitInstructions } from '@arco/shared';
|
|
1
2
|
import { prepareProviderHistory } from './handoffHistoryBinding.js';
|
|
2
3
|
import { prepareLocalFileContext, combineChatAttachments } from './localFileMedia.js';
|
|
3
4
|
import { cliFileReadGuidance, prepareProviderAttachments, type PreparedAttachments } from './providerFileContent.js';
|
|
@@ -46,7 +47,7 @@ const APPEND_SP_TMPDIR = joinPath(tmpdir(), 'arco-prompts');
|
|
|
46
47
|
// last (the order Claude Native uses). Each part is stable for the tab, so the
|
|
47
48
|
// appended system prompt stays byte-identical from turn to turn.
|
|
48
49
|
function effectiveAppendSystemPrompt(config: WorkerConfig): string | undefined {
|
|
49
|
-
const parts = [goalBlock(config.goal), config.appendSystemPrompt, cliFileReadGuidance(config), outputStyleAddendum(config.outputStyle)]
|
|
50
|
+
const parts = [buildTurnWaitInstructions(config.clusterRole), goalBlock(config.goal), config.appendSystemPrompt, cliFileReadGuidance(config), outputStyleAddendum(config.outputStyle)]
|
|
50
51
|
.filter((s): s is string => typeof s === 'string' && s.length > 0);
|
|
51
52
|
return parts.length > 0 ? parts.join('\n\n') : undefined;
|
|
52
53
|
}
|
|
@@ -31,7 +31,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS: ClusterTaskToolDefinition[] = [
|
|
|
31
31
|
{
|
|
32
32
|
name: 'cluster_task_create',
|
|
33
33
|
description:
|
|
34
|
-
'Create a non-terminal task on the shared cluster board. New tasks start as todo;
|
|
34
|
+
'Create a non-terminal task on the shared cluster board. New tasks start as todo; terminal statuses cannot be set when creating a task. Use title plus optional body/notes, assignee, priority, parentIds, links, reviewRequired, goalMode, and goalMaxTurns. parentIds must refer to existing tasks. When the task implements a plan item, start the title with that item\'s id or text (e.g. \'P6.9 Live tab drag follow on X11\'): cluster_task_show then resolves the item\'s reference docs (its own ref links, its sub-bullets, its phase intro) for whoever works it. Add any extra ref:slug links the task needs to notes.',
|
|
35
35
|
input_schema: {
|
|
36
36
|
type: 'object',
|
|
37
37
|
properties: {
|
|
@@ -76,7 +76,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS: ClusterTaskToolDefinition[] = [
|
|
|
76
76
|
{
|
|
77
77
|
name: 'cluster_task_update',
|
|
78
78
|
description:
|
|
79
|
-
"Update a task on the shared cluster board.
|
|
79
|
+
"Update a task on the shared cluster board. Workers move completed work to review. Only the director signs off: set signoff to met, partial, or not_met with a plain one-line summary for the operator, without commit hashes. A director's met sign-off closes the task unless Board auto-done is off in Settings; partial and not_met leave the task status unchanged unless you set a status. Tell the operator in chat what to try. Direct status changes to done or archived remain operator-only.",
|
|
80
80
|
input_schema: {
|
|
81
81
|
type: 'object',
|
|
82
82
|
properties: {
|
|
@@ -86,7 +86,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS: ClusterTaskToolDefinition[] = [
|
|
|
86
86
|
release: { type: 'string', description: 'Release label such as 0.1.4; an empty string clears it.' },
|
|
87
87
|
signoff: {
|
|
88
88
|
type: 'object',
|
|
89
|
-
description: '
|
|
89
|
+
description: 'Director verdict: met closes the task unless Board auto-done is off.',
|
|
90
90
|
properties: {
|
|
91
91
|
state: { type: 'string', enum: ['met', 'not_met', 'partial'], description: 'Your verdict: met / not_met / partial.' },
|
|
92
92
|
summary: { type: 'string', description: 'One-line reason shown on the board card.' },
|
|
@@ -165,7 +165,7 @@ export const CLUSTER_TASK_TOOL_DEFINITIONS: ClusterTaskToolDefinition[] = [
|
|
|
165
165
|
{
|
|
166
166
|
name: 'cluster_task_complete',
|
|
167
167
|
description:
|
|
168
|
-
"Submit a completion report for a task YOU OWN. Moves the task to review and appends a durable COMPLETION REPORT comment. You can only complete a task currently assigned to you - completing an unknown id is rejected (not_found) and completing another member's or an unassigned task is rejected (not_owner); claim it first (cluster_task_claim) or coordinate via peer_send. It does
|
|
168
|
+
"Submit a completion report for a task YOU OWN. Moves the task to review and appends a durable COMPLETION REPORT comment. You can only complete a task currently assigned to you - completing an unknown id is rejected (not_found) and completing another member's or an unassigned task is rejected (not_owner); claim it first (cluster_task_claim) or coordinate via peer_send. It does not mark done; the director reviews the report.",
|
|
169
169
|
input_schema: {
|
|
170
170
|
type: 'object',
|
|
171
171
|
properties: {
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
// (c) `additionalSpeedTiers` (e.g. 'priority'), (d) personality support.
|
|
29
29
|
|
|
30
30
|
import { spawn } from 'node:child_process';
|
|
31
|
+
import { statSync } from 'node:fs';
|
|
32
|
+
import { join } from 'node:path';
|
|
31
33
|
import { JsonRpcClient } from './jsonRpc.js';
|
|
32
34
|
import type { InitializeResponse } from './bindings/InitializeResponse.js';
|
|
33
35
|
import type { ModelListResponse } from './bindings/v2/ModelListResponse.js';
|
|
@@ -49,6 +51,16 @@ const ARCO_CLIENT_VERSION = '0.1.0';
|
|
|
49
51
|
// reads of the same home share one entry.
|
|
50
52
|
const caches = new Map<string, CodexCatalogSnapshot>();
|
|
51
53
|
const inFlightByKey = new Map<string, Promise<CodexCatalogSnapshot>>();
|
|
54
|
+
const modelCacheStamps = new Map<string, string | null>();
|
|
55
|
+
|
|
56
|
+
// Codex refreshes this file independently, including from its own model picker.
|
|
57
|
+
// A new local catalog must not wait for Arco's one-hour snapshot to expire.
|
|
58
|
+
function modelCacheStamp(home: string): string | null {
|
|
59
|
+
try {
|
|
60
|
+
const file = statSync(join(home, 'models_cache.json'));
|
|
61
|
+
return `${file.mtimeMs}:${file.ctimeMs}:${file.size}:${file.ino}`;
|
|
62
|
+
} catch { return null; }
|
|
63
|
+
}
|
|
52
64
|
|
|
53
65
|
function cacheKey(codexHome?: string): string {
|
|
54
66
|
return resolveCodexHome(codexHome);
|
|
@@ -97,13 +109,14 @@ export async function getCodexCatalog(force = false, codexHome?: string): Promis
|
|
|
97
109
|
const key = cacheKey(codexHome);
|
|
98
110
|
const now = Date.now();
|
|
99
111
|
const cache = caches.get(key) ?? null;
|
|
100
|
-
if (!force && cache && now - cache.fetchedAt < REFRESH_INTERVAL_MS) return cache;
|
|
112
|
+
if (!force && cache && now - cache.fetchedAt < REFRESH_INTERVAL_MS && modelCacheStamps.get(key) === modelCacheStamp(key)) return cache;
|
|
101
113
|
const existing = inFlightByKey.get(key);
|
|
102
114
|
if (existing) return existing;
|
|
103
115
|
const p = (async () => {
|
|
104
116
|
try {
|
|
105
117
|
const fresh = await fetchCodexCatalog(codexHome);
|
|
106
118
|
caches.set(key, fresh);
|
|
119
|
+
modelCacheStamps.set(key, modelCacheStamp(key));
|
|
107
120
|
return fresh;
|
|
108
121
|
} catch (err) {
|
|
109
122
|
if (cache) {
|
|
@@ -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 { 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 = [buildTurnWaitInstructions(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 } from '@arco/shared';
|
|
16
17
|
import { buildClusterDirectorDoctrine } from '../clusterDirector.js';
|
|
17
18
|
|
|
18
19
|
interface CodeModeEntry {
|
|
@@ -93,18 +94,17 @@ export function codexCodeModeClusterAddendum(): string {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
// Standing turn discipline for every Codex workflow (cluster and single).
|
|
96
|
-
export const CODEX_TURN_DISCIPLINE =
|
|
97
|
-
'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.';
|
|
97
|
+
export const CODEX_TURN_DISCIPLINE = AGENT_TURN_WAIT;
|
|
98
98
|
|
|
99
99
|
// app-server can place Arco's durable cluster identity at developer level
|
|
100
100
|
// when a thread starts/resumes. Per-turn plan content still rides in user
|
|
101
101
|
// input because it is mutable; the stable role and tool contract do not need
|
|
102
102
|
// to compete with Codex's own `/root` developer framing there.
|
|
103
103
|
// Non-cluster threads still receive CODEX_TURN_DISCIPLINE so single workflows
|
|
104
|
-
//
|
|
104
|
+
// wait for the result their report depends on and check for messages between waits.
|
|
105
105
|
export function codexClusterDeveloperInstructions(config: WorkerConfig): string | null {
|
|
106
106
|
if (config.provider !== 'codex') return null;
|
|
107
|
-
const blocks: string[] = [
|
|
107
|
+
const blocks: string[] = [buildTurnWaitInstructions(config.clusterRole)];
|
|
108
108
|
if (config.clusterId) {
|
|
109
109
|
blocks.push(
|
|
110
110
|
'--- 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.
|