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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { watch } from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
import { join, resolve } from 'path';
|
|
1
|
+
import { watch, statSync } from 'fs';
|
|
2
|
+
import { open } from 'fs/promises';
|
|
3
|
+
import { basename, dirname, join, resolve } from 'path';
|
|
4
4
|
import { homedir } from 'os';
|
|
5
|
+
import { jsonlLines } from './jsonlLines.js';
|
|
5
6
|
export function resolveSessionJsonlPath(cwd, sessionId) {
|
|
6
7
|
// Claude's CLI encodes cwd by replacing any non-[A-Za-z0-9-] char with '-',
|
|
7
8
|
// not just '/'. So `/home/operator/Projects/Sample_Project` becomes
|
|
@@ -21,30 +22,64 @@ export function resolveSubagentsWorkflowsDir(cwd, sessionId) {
|
|
|
21
22
|
return join(homedir(), '.claude', 'projects', encoded, sessionId, 'subagents', 'workflows');
|
|
22
23
|
}
|
|
23
24
|
export async function loadSessionJsonl(path) {
|
|
24
|
-
let
|
|
25
|
+
let fh;
|
|
25
26
|
try {
|
|
26
|
-
|
|
27
|
+
fh = await open(path, 'r');
|
|
27
28
|
}
|
|
28
|
-
catch {
|
|
29
|
-
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err.code === 'ENOENT')
|
|
31
|
+
return { entries: [], byteLength: 0 };
|
|
32
|
+
throw err;
|
|
30
33
|
}
|
|
31
34
|
const entries = [];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
let complete = 0;
|
|
36
|
+
try {
|
|
37
|
+
const size = (await fh.stat()).size;
|
|
38
|
+
async function* chunks() {
|
|
39
|
+
for (let position = 0; position < size;) {
|
|
40
|
+
const buffer = Buffer.alloc(Math.min(64 * 1024, size - position));
|
|
41
|
+
const { bytesRead } = await fh.read(buffer, 0, buffer.length, position);
|
|
42
|
+
if (!bytesRead)
|
|
43
|
+
break;
|
|
44
|
+
const chunk = buffer.subarray(0, bytesRead);
|
|
45
|
+
const newline = chunk.lastIndexOf(0x0a);
|
|
46
|
+
if (newline >= 0)
|
|
47
|
+
complete = position + newline + 1;
|
|
48
|
+
position += bytesRead;
|
|
49
|
+
yield chunk;
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
|
-
|
|
52
|
+
for await (const line of jsonlLines(chunks(), path, { finalLine: false, carriageReturns: false })) {
|
|
53
|
+
if (!line.trim())
|
|
54
|
+
continue;
|
|
55
|
+
try {
|
|
56
|
+
const e = JSON.parse(line);
|
|
57
|
+
if (e && typeof e.type === 'string')
|
|
58
|
+
entries.push(e);
|
|
59
|
+
}
|
|
60
|
+
catch { /* skip malformed lines */ }
|
|
61
|
+
}
|
|
62
|
+
return { entries, byteLength: complete };
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await fh.close();
|
|
42
66
|
}
|
|
43
|
-
|
|
67
|
+
}
|
|
68
|
+
async function lastCompleteOffset(fh, size) {
|
|
69
|
+
for (let end = size; end > 0;) {
|
|
70
|
+
const start = Math.max(0, end - 64 * 1024), buffer = Buffer.alloc(end - start);
|
|
71
|
+
const { bytesRead } = await fh.read(buffer, 0, buffer.length, start);
|
|
72
|
+
const newline = buffer.subarray(0, bytesRead).lastIndexOf(0x0a);
|
|
73
|
+
if (newline >= 0)
|
|
74
|
+
return start + newline + 1;
|
|
75
|
+
end = start;
|
|
76
|
+
}
|
|
77
|
+
return 0;
|
|
44
78
|
}
|
|
45
79
|
// Tail the session JSONL for new entries, emitting each one via `onEntry`.
|
|
46
80
|
// `initialOffset` should be the byteLength from loadSessionJsonl so we
|
|
47
|
-
// don't re-emit history.
|
|
81
|
+
// don't re-emit history. Null anchors at the first readable complete boundary
|
|
82
|
+
// after initial loading failed. Returns a dispose function.
|
|
48
83
|
export function watchSessionJsonl(path, initialOffset, onEntry) {
|
|
49
84
|
let lastOffset = initialOffset;
|
|
50
85
|
let active = true;
|
|
@@ -52,6 +87,12 @@ export function watchSessionJsonl(path, initialOffset, onEntry) {
|
|
|
52
87
|
let restartTimer = null;
|
|
53
88
|
let reading = false;
|
|
54
89
|
let requested = false;
|
|
90
|
+
let identity;
|
|
91
|
+
try {
|
|
92
|
+
const st = statSync(path);
|
|
93
|
+
identity = `${st.dev}:${st.ino}`;
|
|
94
|
+
}
|
|
95
|
+
catch { /* not created yet */ }
|
|
55
96
|
const readNew = async () => {
|
|
56
97
|
if (!active)
|
|
57
98
|
return;
|
|
@@ -63,30 +104,59 @@ export function watchSessionJsonl(path, initialOffset, onEntry) {
|
|
|
63
104
|
while (active && requested) {
|
|
64
105
|
requested = false;
|
|
65
106
|
try {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
return;
|
|
69
|
-
if (buf.length < lastOffset)
|
|
70
|
-
lastOffset = 0;
|
|
71
|
-
const end = buf.lastIndexOf(10) + 1;
|
|
72
|
-
if (end <= lastOffset)
|
|
73
|
-
continue;
|
|
74
|
-
const slice = buf.subarray(lastOffset, end).toString('utf-8');
|
|
75
|
-
lastOffset = end;
|
|
76
|
-
for (const line of slice.split('\n')) {
|
|
107
|
+
const fh = await open(path, 'r');
|
|
108
|
+
try {
|
|
77
109
|
if (!active)
|
|
78
110
|
return;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
111
|
+
const st = await fh.stat();
|
|
112
|
+
const nextIdentity = `${st.dev}:${st.ino}`;
|
|
113
|
+
// After an initial-load failure, anchor to the first readable
|
|
114
|
+
// complete boundary. Old terminal rows must not look like new
|
|
115
|
+
// concurrent-session writes; an unfinished last row stays pending.
|
|
116
|
+
if (lastOffset === null) {
|
|
117
|
+
lastOffset = await lastCompleteOffset(fh, st.size);
|
|
118
|
+
identity = nextIdentity;
|
|
84
119
|
}
|
|
85
|
-
|
|
86
|
-
|
|
120
|
+
if ((identity !== undefined && identity !== nextIdentity) || st.size < lastOffset)
|
|
121
|
+
lastOffset = 0;
|
|
122
|
+
identity = nextIdentity;
|
|
123
|
+
const startOffset = lastOffset;
|
|
124
|
+
let completeOffset = startOffset;
|
|
125
|
+
// Read only the appended range. An unfinished record is left at
|
|
126
|
+
// lastOffset and completed by the next notification, as before.
|
|
127
|
+
async function* chunks() {
|
|
128
|
+
for (let position = startOffset; active && position < st.size;) {
|
|
129
|
+
const buffer = Buffer.alloc(Math.min(64 * 1024, st.size - position));
|
|
130
|
+
const { bytesRead } = await fh.read(buffer, 0, buffer.length, position);
|
|
131
|
+
if (!bytesRead)
|
|
132
|
+
break;
|
|
133
|
+
const chunk = buffer.subarray(0, bytesRead);
|
|
134
|
+
const newline = chunk.lastIndexOf(0x0a);
|
|
135
|
+
if (newline >= 0)
|
|
136
|
+
completeOffset = position + newline + 1;
|
|
137
|
+
position += bytesRead;
|
|
138
|
+
yield chunk;
|
|
139
|
+
}
|
|
87
140
|
}
|
|
88
|
-
|
|
89
|
-
|
|
141
|
+
for await (const line of jsonlLines(chunks(), path, { finalLine: false, carriageReturns: false })) {
|
|
142
|
+
if (!active)
|
|
143
|
+
return;
|
|
144
|
+
if (!line.trim())
|
|
145
|
+
continue;
|
|
146
|
+
let e;
|
|
147
|
+
try {
|
|
148
|
+
e = JSON.parse(line);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (e && typeof e.type === 'string')
|
|
154
|
+
onEntry(e);
|
|
155
|
+
}
|
|
156
|
+
lastOffset = completeOffset;
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
await fh.close();
|
|
90
160
|
}
|
|
91
161
|
}
|
|
92
162
|
catch { /* file unavailable; retry at the next notification */ }
|
|
@@ -112,7 +182,12 @@ export function watchSessionJsonl(path, initialOffset, onEntry) {
|
|
|
112
182
|
if (!active || watcher)
|
|
113
183
|
return;
|
|
114
184
|
try {
|
|
115
|
-
|
|
185
|
+
// Watching the directory survives replacement of the session file;
|
|
186
|
+
// an inode-bound watcher would keep watching the removed file.
|
|
187
|
+
watcher = watch(dirname(path), { persistent: false }, (_event, name) => {
|
|
188
|
+
if (name === null || name === basename(path))
|
|
189
|
+
void readNew();
|
|
190
|
+
});
|
|
116
191
|
void readNew();
|
|
117
192
|
watcher.on('error', () => {
|
|
118
193
|
watcher = null;
|
|
@@ -120,7 +195,7 @@ export function watchSessionJsonl(path, initialOffset, onEntry) {
|
|
|
120
195
|
});
|
|
121
196
|
}
|
|
122
197
|
catch {
|
|
123
|
-
//
|
|
198
|
+
// Session directory not yet created — retry after 2s (happens for brand-new sessions)
|
|
124
199
|
scheduleRestart();
|
|
125
200
|
}
|
|
126
201
|
};
|
|
@@ -2,9 +2,10 @@ import { type AutoPickupMode, type ClusterAutoPickupState, type SmartPickupEvalu
|
|
|
2
2
|
import * as clusterStore from './clusterStore.js';
|
|
3
3
|
type Changed = (clusterId: string) => void;
|
|
4
4
|
export declare const SMART_PICKUP_SWEEP_MS: number;
|
|
5
|
-
export type ArmProblem = 'unknown_cluster' | 'invalid_mode' | 'evaluator_required' | 'evaluator_provider_disabled' | 'evaluator_unavailable' | 'ledger_unreadable';
|
|
5
|
+
export type ArmProblem = 'unknown_cluster' | 'invalid_mode' | 'invalid_pause' | 'evaluator_required' | 'evaluator_provider_disabled' | 'evaluator_unavailable' | 'ledger_unreadable';
|
|
6
6
|
export declare function applyAutoPickup(clusterId: string, request: {
|
|
7
7
|
mode: unknown;
|
|
8
|
+
paused?: unknown;
|
|
8
9
|
evaluator?: unknown;
|
|
9
10
|
limits?: unknown;
|
|
10
11
|
ruleLimits?: unknown;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { isSmartPickupMode, sanitizeSmartPickupEvaluator, sanitizeSmartPickupLimits, sanitizeRulePickupLimits, RULE_PICKUP_LIMIT_KEYS, } from '@arco/shared';
|
|
5
5
|
import * as ruleAutoTurn from './clusterAutoTurn.js';
|
|
6
6
|
import * as clusterStore from './clusterStore.js';
|
|
7
|
+
import { pickupSmartWaitingMail } from './smartPickupObserver.js';
|
|
7
8
|
import { evaluatorAdapter } from './smartPickupAdapters.js';
|
|
8
9
|
import { recordSmartPickupDecision, recoverSmartPickupLedger, smartPickupSnapshot, SmartPickupLedgerUnreadable, } from './smartPickupLedger.js';
|
|
9
10
|
let onChanged = () => { };
|
|
@@ -22,6 +23,30 @@ export async function applyAutoPickup(clusterId, request, isProviderEnabled, now
|
|
|
22
23
|
const state = clusterStore.getClusterCached(clusterId) ?? await clusterStore.readCluster(clusterId).catch(() => null);
|
|
23
24
|
if (!state)
|
|
24
25
|
return { ok: false, problem: 'unknown_cluster' };
|
|
26
|
+
if (request.paused !== undefined) {
|
|
27
|
+
if (typeof request.paused !== 'boolean' || mode === 'off' || mode !== clusterStore.autoPickupModeOf(state)
|
|
28
|
+
|| request.resumeRule || request.evaluator !== undefined || request.limits !== undefined || request.ruleLimits !== undefined || request.remindBusy !== undefined)
|
|
29
|
+
return { ok: false, problem: 'invalid_pause' };
|
|
30
|
+
const session = state.smartPickup?.session;
|
|
31
|
+
if (isSmartPickupMode(mode) && (!session || (state.autoPickupPausedAt ?? now) >= session.expiresAt)) {
|
|
32
|
+
await disarm(clusterId, session ? 'session_expired' : 'session_missing', now);
|
|
33
|
+
return { ok: true, mode: 'off' };
|
|
34
|
+
}
|
|
35
|
+
const updated = await clusterStore.setAutoPickup(clusterId, { mode, paused: request.paused, now });
|
|
36
|
+
if (!updated)
|
|
37
|
+
return { ok: false, problem: 'invalid_pause' };
|
|
38
|
+
await recordSmartPickupDecision(clusterId, { at: now, action: null, reason: request.paused ? 'operator_paused' : 'operator_resumed', outcome: 'none' }).catch(() => undefined);
|
|
39
|
+
if (state.autoPickupPausedAt !== undefined && !request.paused) {
|
|
40
|
+
// Reply with the new control state promptly; evaluator requests may take
|
|
41
|
+
// time. Both scans use the same admission path as ordinary waiting mail.
|
|
42
|
+
setImmediate(() => {
|
|
43
|
+
void (mode === 'rule' ? ruleAutoTurn.pickupWaitingMail(clusterId) : pickupSmartWaitingMail(clusterId)).catch((error) => console.error('[arco] auto-pickup resume failed:', error));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return { ok: true, mode };
|
|
47
|
+
}
|
|
48
|
+
if (request.resumeRule && state.autoPickupPausedAt !== undefined)
|
|
49
|
+
return { ok: false, problem: 'invalid_pause' };
|
|
25
50
|
let evaluator;
|
|
26
51
|
if (isSmartPickupMode(mode)) {
|
|
27
52
|
evaluator = sanitizeSmartPickupEvaluator(request.evaluator) ?? undefined;
|
|
@@ -89,6 +114,8 @@ export async function autoPickupStateFor(state, now = Date.now()) {
|
|
|
89
114
|
const smart = state.smartPickup ?? {};
|
|
90
115
|
const out = {
|
|
91
116
|
mode,
|
|
117
|
+
paused: state.autoPickupPausedAt !== undefined,
|
|
118
|
+
...(state.autoPickupPausedAt !== undefined ? { pausedAt: state.autoPickupPausedAt } : {}),
|
|
92
119
|
remindBusy: state.remindBusy === true,
|
|
93
120
|
limits: sanitizeSmartPickupLimits(smart.limits),
|
|
94
121
|
ruleLimits: sanitizeRulePickupLimits(state.rulePickupLimits),
|
|
@@ -130,7 +157,7 @@ export async function sweepSmartPickup(now = Date.now()) {
|
|
|
130
157
|
await disarm(clusterId, 'session_missing', now);
|
|
131
158
|
continue;
|
|
132
159
|
}
|
|
133
|
-
if (now >= session.expiresAt) {
|
|
160
|
+
if (state.autoPickupPausedAt === undefined && now >= session.expiresAt) {
|
|
134
161
|
await disarm(clusterId, 'session_expired', now);
|
|
135
162
|
continue;
|
|
136
163
|
}
|
|
@@ -215,6 +215,19 @@ export function claudeAdapter(opts = {}) {
|
|
|
215
215
|
},
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
|
+
// A terminating child can still hold its cwd open on Windows. Allow up to
|
|
219
|
+
// 250 ms for exit, then at most 600 ms of removal retries. Cleanup must never
|
|
220
|
+
// change the evaluator's answer or refusal.
|
|
221
|
+
async function removeEvaluatorFolder(proc, cwd) {
|
|
222
|
+
if (proc.pid && proc.exitCode === null && proc.signalCode === null) {
|
|
223
|
+
await new Promise((resolve) => {
|
|
224
|
+
const done = () => { clearTimeout(timer); proc.off('close', done); resolve(); };
|
|
225
|
+
const timer = setTimeout(done, 250);
|
|
226
|
+
proc.once('close', done);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
await rm(cwd, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }).catch(() => undefined);
|
|
230
|
+
}
|
|
218
231
|
export function cursorAdapter(opts = {}) {
|
|
219
232
|
// `cursor-agent acp` ignores `--model`; the model is selected over ACP after
|
|
220
233
|
// session/new and confirmed, and the evaluator refuses rather than answer
|
|
@@ -357,7 +370,7 @@ export function cursorAdapter(opts = {}) {
|
|
|
357
370
|
clearTimeout(timer);
|
|
358
371
|
req.signal?.removeEventListener('abort', onAbort);
|
|
359
372
|
stop();
|
|
360
|
-
await
|
|
373
|
+
await removeEvaluatorFolder(proc, cwd);
|
|
361
374
|
}
|
|
362
375
|
},
|
|
363
376
|
};
|
|
@@ -504,7 +517,7 @@ export function codexAdapter(opts = {}) {
|
|
|
504
517
|
clearTimeout(timer);
|
|
505
518
|
req.signal?.removeEventListener('abort', onAbort);
|
|
506
519
|
stop();
|
|
507
|
-
await
|
|
520
|
+
await removeEvaluatorFolder(proc, cwd);
|
|
508
521
|
}
|
|
509
522
|
},
|
|
510
523
|
};
|
|
@@ -10,10 +10,11 @@ import { promises as fs } from 'node:fs';
|
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { randomUUID } from 'node:crypto';
|
|
12
12
|
import { atomicWriteFile } from './atomicFile.js';
|
|
13
|
-
import { clusterDir } from './clusterStore.js';
|
|
13
|
+
import { clusterDir, getClusterCached } from './clusterStore.js';
|
|
14
14
|
const HOUR_MS = 60 * 60 * 1000;
|
|
15
|
-
//
|
|
16
|
-
// of at most 8 hours), so they are dropped on the next write.
|
|
15
|
+
// Older entries normally cannot affect a limit (hour windows and sessions
|
|
16
|
+
// of at most 8 hours), so they are dropped on the next write. Pauses can
|
|
17
|
+
// extend a session's wall-clock life: retain its entries until it ends.
|
|
17
18
|
const RETAIN_MS = 9 * HOUR_MS;
|
|
18
19
|
const DECISIONS_KEPT = 50;
|
|
19
20
|
export class SmartPickupLedgerUnreadable extends Error {
|
|
@@ -50,7 +51,8 @@ async function read(clusterId) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
async function write(clusterId, ledger, now) {
|
|
53
|
-
|
|
54
|
+
const activeSession = getClusterCached(clusterId)?.smartPickup?.session?.id;
|
|
55
|
+
ledger.entries = ledger.entries.filter((e) => e.status === 'reserved' || e.sessionId === activeSession || now - e.at < RETAIN_MS);
|
|
54
56
|
ledger.decisions = ledger.decisions.slice(-DECISIONS_KEPT);
|
|
55
57
|
await fs.mkdir(clusterDir(clusterId), { recursive: true });
|
|
56
58
|
await atomicWriteFile(ledgerPath(clusterId), JSON.stringify(ledger, null, 2));
|
|
@@ -26,5 +26,6 @@ export declare function onSmartPickupMail(clusterId: string, workflowId: string,
|
|
|
26
26
|
export declare function evaluateOnce(clusterId: string, workflowId: string): Promise<ObservedDecision | null>;
|
|
27
27
|
export declare function noteSmartPickupStop(workflowId: string): Promise<void>;
|
|
28
28
|
export declare function sweepSmartPickupMail(): Promise<void>;
|
|
29
|
+
export declare function pickupSmartWaitingMail(clusterId: string): Promise<void>;
|
|
29
30
|
export declare function startSmartPickupObserver(next: Partial<Deps>): void;
|
|
30
31
|
export {};
|
|
@@ -91,7 +91,7 @@ function armed(clusterId) {
|
|
|
91
91
|
return null;
|
|
92
92
|
const mode = clusterStore.autoPickupModeOf(state);
|
|
93
93
|
const session = state.smartPickup?.session;
|
|
94
|
-
if (!isSmartPickupMode(mode) || !session || !state.smartPickup?.evaluator)
|
|
94
|
+
if (state.autoPickupPausedAt !== undefined || !isSmartPickupMode(mode) || !session || !state.smartPickup?.evaluator)
|
|
95
95
|
return null;
|
|
96
96
|
if (deps.now() >= session.expiresAt)
|
|
97
97
|
return null;
|
|
@@ -101,11 +101,11 @@ function armed(clusterId) {
|
|
|
101
101
|
// evaluation per recipient at a time; a trigger during a run schedules one
|
|
102
102
|
// more pass afterwards.
|
|
103
103
|
export function onSmartPickupMail(clusterId, workflowId, chainDepth = 0) {
|
|
104
|
-
if (!armed(clusterId))
|
|
105
|
-
return Promise.resolve();
|
|
106
104
|
const k = key(clusterId, workflowId);
|
|
107
105
|
if (chainDepth > (depthSeen.get(k) ?? 0))
|
|
108
106
|
depthSeen.set(k, chainDepth);
|
|
107
|
+
if (!armed(clusterId))
|
|
108
|
+
return Promise.resolve();
|
|
109
109
|
const current = running.get(k);
|
|
110
110
|
if (current) {
|
|
111
111
|
rerun.add(k);
|
|
@@ -177,6 +177,8 @@ export async function evaluateOnce(clusterId, workflowId) {
|
|
|
177
177
|
return d;
|
|
178
178
|
}
|
|
179
179
|
const evaluator = state.smartPickup.evaluator;
|
|
180
|
+
if (armed(clusterId)?.sessionId !== arm.sessionId)
|
|
181
|
+
return null;
|
|
180
182
|
const slot = await reserveSmartPickup(clusterId, { kind: 'evaluator', memberId: workflowId, sessionId: arm.sessionId, limits, now: deps.now() }).catch(() => ({ ok: false, reason: 'ledger_unreadable' }));
|
|
181
183
|
if (!slot.ok) {
|
|
182
184
|
const d = { ...base, action: null, reason: slot.reason, outcome: 'skipped' };
|
|
@@ -191,6 +193,10 @@ export async function evaluateOnce(clusterId, workflowId) {
|
|
|
191
193
|
}
|
|
192
194
|
let raw = null;
|
|
193
195
|
let failure = null;
|
|
196
|
+
if (armed(clusterId)?.sessionId !== arm.sessionId) {
|
|
197
|
+
await settleSmartPickup(clusterId, slot.id, 'session_changed', deps.now()).catch(() => undefined);
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
194
200
|
try {
|
|
195
201
|
raw = await evaluatorAdapter(evaluator.provider).evaluate({
|
|
196
202
|
model: evaluator.model,
|
|
@@ -379,24 +385,27 @@ export async function sweepSmartPickupMail() {
|
|
|
379
385
|
sweeping = true;
|
|
380
386
|
try {
|
|
381
387
|
for (const clusterId of clusterStore.listKnownClusterIds().sort()) {
|
|
382
|
-
|
|
383
|
-
continue;
|
|
384
|
-
const members = [...(clusterStore.getClusterCached(clusterId)?.members ?? [])].sort();
|
|
385
|
-
// One member at a time per cluster, in a stable order, so the
|
|
386
|
-
// in-flight limit is respected and no mailbox starves another.
|
|
387
|
-
for (const wfid of members) {
|
|
388
|
-
if (deps.isBusy(wfid))
|
|
389
|
-
continue;
|
|
390
|
-
const depth = await clusterMailbox.depthFor(wfid).catch(() => 0);
|
|
391
|
-
if (depth > 0)
|
|
392
|
-
await onSmartPickupMail(clusterId, wfid).catch(() => undefined);
|
|
393
|
-
}
|
|
388
|
+
await pickupSmartWaitingMail(clusterId);
|
|
394
389
|
}
|
|
395
390
|
}
|
|
396
391
|
finally {
|
|
397
392
|
sweeping = false;
|
|
398
393
|
}
|
|
399
394
|
}
|
|
395
|
+
export async function pickupSmartWaitingMail(clusterId) {
|
|
396
|
+
if (!armed(clusterId))
|
|
397
|
+
return;
|
|
398
|
+
const members = [...(clusterStore.getClusterCached(clusterId)?.members ?? [])].sort();
|
|
399
|
+
// One member at a time per cluster, in a stable order, so the
|
|
400
|
+
// in-flight limit is respected and no mailbox starves another.
|
|
401
|
+
for (const wfid of members) {
|
|
402
|
+
if (deps.isBusy(wfid))
|
|
403
|
+
continue;
|
|
404
|
+
const depth = await clusterMailbox.depthFor(wfid).catch(() => 0);
|
|
405
|
+
if (depth > 0)
|
|
406
|
+
await onSmartPickupMail(clusterId, wfid).catch(() => undefined);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
400
409
|
let mailTimer = null;
|
|
401
410
|
const MAIL_SWEEP_MS = (() => {
|
|
402
411
|
const raw = Number(process.env.ARCO_SMART_PICKUP_MAIL_SWEEP_MS);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const TRANSCRIPT_WORKER_MAX_BYTES: number;
|
|
2
|
+
export declare const TRANSCRIPT_WORKER_PREFACE_BYTES: number;
|
|
3
|
+
export interface TranscriptSliceOptions {
|
|
4
|
+
turns: number;
|
|
5
|
+
includePartial: boolean;
|
|
6
|
+
preface: string;
|
|
7
|
+
cutoffSeq?: number;
|
|
8
|
+
wasBusy: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildTranscriptWorkerSlice(cwd: string, workflowId: string, options: TranscriptSliceOptions): Promise<{
|
|
11
|
+
seed: string;
|
|
12
|
+
bytes: number;
|
|
13
|
+
availableTurns: number;
|
|
14
|
+
selectedTurns: number;
|
|
15
|
+
partialIncluded: boolean;
|
|
16
|
+
cutoffSeq: number;
|
|
17
|
+
digest: string;
|
|
18
|
+
branchKey: string;
|
|
19
|
+
}>;
|
|
20
|
+
export interface TranscriptSelectionPolicy {
|
|
21
|
+
maxBytes: number;
|
|
22
|
+
fitWholeTurns: boolean;
|
|
23
|
+
allTurns?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function buildTranscriptSlice(cwd: string, workflowId: string, options: TranscriptSliceOptions, policy?: TranscriptSelectionPolicy): Promise<{
|
|
26
|
+
seed: string;
|
|
27
|
+
bytes: number;
|
|
28
|
+
availableTurns: number;
|
|
29
|
+
selectedTurns: number;
|
|
30
|
+
partialIncluded: boolean;
|
|
31
|
+
cutoffSeq: number;
|
|
32
|
+
digest: string;
|
|
33
|
+
branchKey: string;
|
|
34
|
+
}>;
|