arco-workbench 0.1.6 → 0.1.7

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.
Files changed (57) hide show
  1. package/README.md +6 -1
  2. package/client/dist/assets/{PhosphorBackdrop-BR-TgB5x.js → PhosphorBackdrop-DVQdBrTw.js} +1 -1
  3. package/client/dist/assets/{ThemedBackgroundShaderImpl-DgcFj6JN.js → ThemedBackgroundShaderImpl-BfSs2tB4.js} +1 -1
  4. package/client/dist/assets/{XtermView-CflVBQgC.js → XtermView-DaMjC8Ny.js} +1 -1
  5. package/client/dist/assets/{galleryEditor-BB-emfmi.js → galleryEditor-BCQnXj7R.js} +1 -1
  6. package/client/dist/assets/{index-B_EqHDz3.js → index-COfbHCYv.js} +218 -218
  7. package/client/dist/index.html +1 -1
  8. package/client/src/buildCheck.ts +3 -1
  9. package/client/src/components/AppUpdateNotice.tsx +2 -1
  10. package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +24 -12
  11. package/client/src/components/ClusterRightPanel/index.tsx +2 -1
  12. package/client/src/components/HeaderVersionBox.tsx +7 -4
  13. package/client/src/components/UpdateAction.tsx +18 -4
  14. package/client/src/components/UpdateResultNotice.tsx +3 -1
  15. package/client/src/help/content/cluster.tsx +16 -5
  16. package/client/src/help/content/header.tsx +3 -1
  17. package/client/src/help/content/rightPanel.tsx +1 -1
  18. package/client/src/help/content/settings.tsx +1 -1
  19. package/client/src/help/manualSections/clusters.tsx +17 -1
  20. package/client/src/help/manualSections/configuration.tsx +20 -4
  21. package/client/src/help/manualSections/maintenance.tsx +12 -0
  22. package/client/src/help/manualSections/plans.tsx +5 -1
  23. package/client/src/help/manualSections/workflows.tsx +7 -0
  24. package/client/src/stores/appUpdateStore.ts +29 -8
  25. package/client/src/utils/wsSession.ts +2 -1
  26. package/docs/GETTING_STARTED.md +5 -1
  27. package/docs/OPERATIONS.md +23 -0
  28. package/docs/PERSISTENCE.md +18 -1
  29. package/docs/PROTOCOL_CLUSTER.md +9 -2
  30. package/native/darwin-arm64/manifest.json +1 -1
  31. package/node_modules/@arco/shared/dist/protocol/autoPickup.d.ts +3 -0
  32. package/node_modules/@arco/shared/package.json +1 -1
  33. package/package.json +2 -2
  34. package/scripts/packaging/native-repair.mjs +46 -8
  35. package/scripts/packaging/update.mjs +5 -1
  36. package/server/dist/clusterAutoTurn.d.ts +4 -0
  37. package/server/dist/clusterAutoTurn.js +29 -25
  38. package/server/dist/clusterBusyReminder.js +1 -1
  39. package/server/dist/clusterStore.d.ts +3 -0
  40. package/server/dist/clusterStore.js +22 -0
  41. package/server/dist/smartPickup.d.ts +2 -1
  42. package/server/dist/smartPickup.js +28 -1
  43. package/server/dist/smartPickupLedger.js +6 -4
  44. package/server/dist/smartPickupObserver.d.ts +1 -0
  45. package/server/dist/smartPickupObserver.js +24 -15
  46. package/server/dist/ws/clusterHandlers.d.ts +1 -0
  47. package/server/dist/ws/clusterHandlers.js +2 -1
  48. package/server/package.json +1 -1
  49. package/server/src/clusterAutoTurn.ts +26 -21
  50. package/server/src/clusterBusyReminder.ts +1 -1
  51. package/server/src/clusterStore.ts +26 -1
  52. package/server/src/smartPickup.ts +27 -3
  53. package/server/src/smartPickupLedger.ts +6 -4
  54. package/server/src/smartPickupObserver.ts +20 -11
  55. package/server/src/ws/clusterHandlers.ts +3 -2
  56. package/shared/dist/protocol/autoPickup.d.ts +3 -0
  57. package/shared/src/protocol/autoPickup.ts +5 -0
@@ -372,7 +372,11 @@ notice and [VOICE.md](VOICE.md) before enabling hands-free mode.
372
372
  - Per-project workflows, chats, plans, and project settings: `<project>/.arco`.
373
373
  Opening a project creates that folder. It ships its own `.gitignore` so its
374
374
  contents stay out of Git by default; adding `.arco/` to the project's root
375
- `.gitignore` is a sensible extra safeguard.
375
+ `.gitignore` is a sensible extra safeguard. Treat `.arco/` as local state that
376
+ is not committed, except a skill shared through SHARE WITH REPOSITORY.
377
+ - Files you want kept in the project (documentation, a README, notes to commit)
378
+ belong in the project tree, for example `docs/`, not only under a conversation's
379
+ `artifacts/` folder inside `.arco`.
376
380
  - `ARCO_HOME` relocates the global Arco home. Project state remains in each
377
381
  project's `.arco` directory.
378
382
 
@@ -220,6 +220,8 @@ The version box in the top bar, left of the power button, always shows the
220
220
  running version. When a newer release is known it turns into an accent box with
221
221
  an up arrow and the new version, stays that way after the toast is dismissed,
222
222
  opens the update dialog on click, and shows UPDATING while an update runs.
223
+ A release found by CHECK NOW appears in the version box; select UPDATE AND
224
+ RESTART to open its confirmation.
223
225
 
224
226
  ### Packaged install
225
227
 
@@ -242,6 +244,27 @@ modules cannot be replaced safely. A packaged service can instead use
242
244
  Linux, macOS, and Windows. The action interrupts running turns and reports
243
245
  completion or rollback after reconnect.
244
246
 
247
+ The result appears beside the open update control. When that control is closed,
248
+ a separate result notice remains available with **DISMISS**. The same result is
249
+ not shown in both places at once.
250
+
251
+ Package updates and `arco setup --repair-native` find npm beside Node.js,
252
+ through the global package directory, or through the npm command on `PATH`.
253
+ Homebrew's versioned Node executable is supported even when the service has a
254
+ short `PATH`. If npm still cannot be found, the update stops before stopping the
255
+ service and describes the locations checked. In a terminal where `npm --version`
256
+ works, update a packaged service manually:
257
+
258
+ ```sh
259
+ arco service stop
260
+ npm install -g arco-workbench
261
+ arco service start
262
+ ```
263
+
264
+ For a foreground run, stop that process before installing and run `arco start`
265
+ afterward. If `npm --version` fails too, repair the Node.js/npm installation
266
+ first. A native repair can then be retried with `arco setup --repair-native`.
267
+
245
268
  After a restart, a page reloads automatically if its build changed or its
246
269
  session cannot recover and no unsaved work is detected. Otherwise it shows a
247
270
  RELOAD banner. Save drafts and edits before selecting RELOAD.
@@ -482,6 +482,16 @@ CREATE VIRTUAL TABLE chunks_fts USING fts5(content, content='chunks', content_ro
482
482
 
483
483
  ## Artifacts
484
484
 
485
+ The per-workflow `artifacts/` folder holds conversation deliverables Arco
486
+ surfaces in chat and in ARTIFACTS or Outputs: reviews, handoff-related
487
+ outputs, report files and other finished work for that tab. Put files the
488
+ operator wants kept in the project (documentation, a README, notes to commit)
489
+ in the project tree, for example `docs/`, not only under
490
+ `.arco/workflows/<wfid>/artifacts/`. Large intermediate files belong in the
491
+ sibling `scratch/` folder. `.arco/` itself is local state and is not committed,
492
+ except a skill shared through SHARE WITH REPOSITORY (see
493
+ [Project `.arco/.gitignore`](#project-arcogitignore)).
494
+
485
495
  `<cwd>/.arco/workflows/<wfid>/artifacts/review-<ts>.md` - Review primitive outputs. YAML frontmatter + body:
486
496
 
487
497
  ```markdown
@@ -899,7 +909,14 @@ Updated on each worker spawn / settle; on macOS and Windows the start time is fi
899
909
 
900
910
  Arco creates `<cwd>/.arco/.gitignore` before writing project state. Its default
901
911
  is `*`, so Git ignores all contents of `.arco/`, including the ignore file
902
- itself. To share an individual file, add a negation such as `!settings.json`
912
+ itself. Treat `.arco/` as local state that stays out of Git by default. Agents
913
+ do not commit, force-add or add ignore exceptions for it. The one route Arco
914
+ itself offers is **SHARE WITH REPOSITORY** in Settings > SKILLS for a project
915
+ skill: that adds ignore exceptions for that skill only and does not stage or
916
+ commit for you. An operator who decides to share an individual file by hand can
917
+ still add a negation, as described next.
918
+
919
+ To share an individual file by hand, add a negation such as `!settings.json`
903
920
  to that file. Sharing a nested file also requires unignoring its parent
904
921
  directories. A repository-level ignore rule can still exclude `.arco/`.
905
922
  Already tracked files stay tracked; remove them from the Git index explicitly
@@ -795,7 +795,7 @@ Existing cooldown and rate guards and the chain-depth default support environmen
795
795
  | Per-cluster rate cap (rolling 60s) | 10 | `ARCO_CLUSTER_AUTO_TURN_RATE_CAP_PER_MINUTE` |
796
796
  | Chain-depth cap | 8 | `ARCO_CLUSTER_AUTO_TURN_MAX_CHAIN_DEPTH` |
797
797
 
798
- Rule-based pickup ignores batches containing only short, unambiguous acknowledgements; the mail remains pending. A later actionable message wakes the recipient with the full batch. Rule limits default to four alternating wakes for a pair, six wakes per member per rolling hour, 40 wakes per arming, and depth eight. A pair pause clears on an operator message to either member, NUDGE, re-arming, or mail from a third member. A board or plan change breaks an unpaused alternating sequence. Reaching the arming total pauses pickup and RESUME starts a fresh total; the hourly member cap remains. Limits are adjustable in the AUTO-PICKUP dialog. Rule guard counters and pair pauses are stored in the cluster ledger and survive a server restart.
798
+ Rule-based pickup ignores batches containing only short, unambiguous acknowledgements; the mail remains pending. A later actionable message wakes the recipient with the full batch. Rule limits default to four alternating wakes for a pair, six wakes per member per rolling hour, 40 wakes per arming, and depth eight. A pair pause clears on an operator message to either member, NUDGE, re-arming, or mail from a third member. A board or plan change breaks an unpaused alternating sequence. Reaching the arming total stops pickup and RESET BUDGET starts a fresh total; the hourly member cap remains. Limits are adjustable in the AUTO-PICKUP dialog. Rule guard counters and pair pauses are stored in the cluster ledger and survive a server restart.
799
799
 
800
800
  Chain depth is carried on `peer_message_sent.chainDepth` (see below); operator-initiated peer-sends ride at depth 0, so the first auto-turn lands at depth 1.
801
801
 
@@ -816,11 +816,18 @@ Operator chose an AUTO-PICKUP mode in the cluster dialog. Modes: `off` (default)
816
816
  limits?: Partial<SmartPickupLimits>, // only changed limits; each bounded
817
817
  ruleLimits?: Partial<RulePickupLimits>,
818
818
  resumeRule?: boolean,
819
+ paused?: boolean, // change only the operator pause; keep the current mode and omit arming/settings fields
819
820
  remindBusy?: boolean, // Also remind busy members; default false, saved per cluster
820
821
  }
821
822
  ```
822
823
 
823
- Smart modes require an evaluator whose provider is enabled and whose adapter reports itself available (`GET /api/smart-pickup/evaluators`; Codex only while it is enabled and signed in), and a readable budget ledger, and every arming starts a new session (`id`, `armedAt`, `expiresAt` from `sessionMinutes`). Off and Rule-based end the session; the evaluator choice is kept as `lastEvaluator` and adjusted limits persist. Refusals return `error` with `cluster_auto_pickup_set rejected: <problem>` (`invalid_mode`, `unknown_cluster`, `evaluator_required`, `evaluator_provider_disabled`, `evaluator_unavailable`, `ledger_unreadable`).
824
+ Smart modes require an evaluator whose provider is enabled and whose adapter reports itself available (`GET /api/smart-pickup/evaluators`; Codex only while it is enabled and signed in), and a readable budget ledger, and every arming starts a new session (`id`, `armedAt`, `expiresAt` from `sessionMinutes`). Off and Rule-based end the session; the evaluator choice is kept as `lastEvaluator` and adjusted limits persist. Refusals return `error` with `cluster_auto_pickup_set rejected: <problem>` (`invalid_mode`, `invalid_pause`, `unknown_cluster`, `evaluator_required`, `evaluator_provider_disabled`, `evaluator_unavailable`, `ledger_unreadable`).
825
+
826
+ PAUSE and RESUME are operator-only controls beside TURN OFF and in the dialog. A request with `paused` must name the current non-Off mode and omit evaluator, limits, Rule-based budget reset and reminder settings. It stores `autoPickupPausedAt` in cluster metadata, echoed as `autoPickup.paused` and `autoPickup.pausedAt`; an absent timestamp means running. Pausing preserves the mode, Smart session id and timestamps, all counters and the Rule-based wake ledger. It stops automatic wakes, evaluator requests and busy reminders; already running turns continue and manual NUDGE remains available. Pending mail stays visible as waiting.
827
+
828
+ RESUME does not require confirmation or evaluator revalidation. Each idle member with pending mail re-enters the ordinary pickup path once, including Smart evaluation and every existing limit; Observe-only still never wakes a member. Repeated resume requests while already running do not scan again. The Rule-based budget reset remains a separate `resumeRule: true` action, labelled RESET BUDGET and refused during an operator pause. Resume never silently resets a spent budget. The pause persists across restart. Changing settings in the same mode keeps the pause; changing mode clears it.
829
+
830
+ The Smart session clock freezes at PAUSE. While paused, remaining time is `expiresAt - autoPickupPausedAt`; the supervisor does not expire the session and the dialog shows remaining time with PAUSED, without an end time. RESUME moves `expiresAt` forward by the pause duration, preserving the session id, `armedAt` and remaining running time. Repeated PAUSE does not move the pause timestamp, and repeated RESUME does not extend the session again. Hourly evaluator and wake limits continue to use real time; session counters are not reset. The ledger retains the current armed session's entries across long pauses, even past its normal nine-hour retention window. TURN OFF while paused clears the timestamp and ends the session.
824
831
 
825
832
  **Also remind busy members** is available under Rule-based and Smart: Automatic. It is off by default and saved per cluster as `remindBusy`; state echoes include `autoPickup.remindBusy`. When enabled, actionable unread mail sends the existing busy NUDGE through the member's steering path once per unread batch, with at least five minutes between reminders for that member. Acknowledgement-only batches stay pending without a reminder. New mail held by the gap is checked again by the resume sweep. Off, Observe-only and expired Smart sessions send none. A reminder whose busy turn ends or changes during preparation is dropped. Idle pickup keeps its usual rules.
826
833
 
@@ -2,7 +2,7 @@
2
2
  "platform": "darwin",
3
3
  "arch": "arm64",
4
4
  "binding": "napi",
5
- "node": "24.22.2",
5
+ "node": "24.22.3",
6
6
  "dependencies": {
7
7
  "better-sqlite3": "13.0.3",
8
8
  "node-pty": "1.1.0"
@@ -67,6 +67,8 @@ export interface SmartPickupCounters {
67
67
  }
68
68
  export interface ClusterAutoPickupState {
69
69
  remindBusy?: boolean;
70
+ paused?: boolean;
71
+ pausedAt?: number;
70
72
  mode: AutoPickupMode;
71
73
  limits: SmartPickupLimits;
72
74
  evaluator?: SmartPickupEvaluator;
@@ -90,6 +92,7 @@ export interface ClusterAutoPickupSetMessage {
90
92
  limits?: Partial<SmartPickupLimits>;
91
93
  ruleLimits?: Partial<RulePickupLimits>;
92
94
  resumeRule?: boolean;
95
+ paused?: boolean;
93
96
  remindBusy?: boolean;
94
97
  }
95
98
  export interface RulePickupLimits {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arco/shared",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "node-pty": "1.1.0"
5
5
  },
6
6
  "name": "arco-workbench",
7
- "version": "0.1.6",
7
+ "version": "0.1.7",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/ghreprimand/arco.git"
@@ -66,7 +66,7 @@
66
66
  "word-extractor": "1.0.4",
67
67
  "ws": "8.22.0",
68
68
  "xlsx": "0.20.3",
69
- "@arco/shared": "0.1.6"
69
+ "@arco/shared": "0.1.7"
70
70
  },
71
71
  "bundleDependencies": [
72
72
  "@arco/shared",
@@ -1,7 +1,7 @@
1
1
  import { spawnSync } from 'node:child_process';
2
- import { chmodSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { chmodSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
- import { dirname, join, resolve } from 'node:path';
4
+ import { basename, delimiter, dirname, isAbsolute, join, resolve } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { createRequire } from 'node:module';
7
7
 
@@ -10,12 +10,50 @@ export function supportedNodeVersion(version = process.versions.node) {
10
10
  return !!match && [24, 26].includes(Number(match[1]));
11
11
  }
12
12
 
13
- export function npmCliPath(env = process.env, executable = process.execPath) {
14
- const bin = dirname(executable);
15
- const candidates = [env.npm_execpath, join(bin, 'node_modules', 'npm', 'bin', 'npm-cli.js'), join(bin, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js')];
16
- const cli = candidates.find((p) => p && p.endsWith('.js') && existsSync(p));
17
- if (!cli) throw new Error('Cannot locate npm. Reinstall Node.js with npm and retry.');
18
- return resolve(cli);
13
+ export function npmCliPath(env = process.env, executable = process.execPath, options = {}) {
14
+ const { argv0 = process.argv0, argv = process.argv, packageRoot = fileURLToPath(new URL('../..', import.meta.url)) } = options;
15
+ const path = (env.PATH || env.Path || '').split(delimiter).filter(Boolean);
16
+ const candidates = [env.npm_execpath];
17
+ const beside = (bin) => {
18
+ candidates.push(join(bin, 'node_modules', 'npm', 'bin', 'npm-cli.js'), join(bin, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'));
19
+ // Homebrew also keeps npm under the versioned keg's libexec directory.
20
+ candidates.push(join(bin, '..', 'libexec', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'));
21
+ };
22
+ for (const command of [executable, env.npm_node_execpath, argv0, ...argv.slice(0, 2)]) {
23
+ if (!command) continue;
24
+ const locations = isAbsolute(command) || /[/\\]/.test(command) ? [resolve(command)] : path.map((bin) => join(bin, command));
25
+ for (const location of locations) {
26
+ beside(dirname(location));
27
+ let real = location;
28
+ try { real = realpathSync(location); } catch { /* an argv path may no longer exist */ }
29
+ if (real !== location) beside(dirname(real));
30
+ // A service can retain only the real Cellar executable and a short PATH.
31
+ // Derive the Homebrew prefix from that executable, without fixed prefixes.
32
+ for (let dir = dirname(real); dirname(dir) !== dir; dir = dirname(dir)) {
33
+ if (basename(dir) === 'Cellar') { beside(join(dirname(dir), 'bin')); break; }
34
+ }
35
+ }
36
+ }
37
+ // A custom npm prefix can differ from the Node installation. The installed
38
+ // package provides this location even when launchd/systemd strips PATH.
39
+ if (packageRoot) {
40
+ for (let dir = resolve(packageRoot); dirname(dir) !== dir; dir = dirname(dir)) {
41
+ if (basename(dir) === 'node_modules') { candidates.push(join(dir, 'npm', 'bin', 'npm-cli.js')); break; }
42
+ }
43
+ }
44
+ for (const bin of path) {
45
+ candidates.push(join(bin, 'npm'));
46
+ beside(bin);
47
+ }
48
+ for (const candidate of new Set(candidates)) {
49
+ if (!candidate) continue;
50
+ try {
51
+ const cli = realpathSync(candidate);
52
+ // The caller invokes this file with Node, never a shell shim or executable.
53
+ if (/\.[cm]?js$/i.test(cli) && statSync(cli).isFile()) return cli;
54
+ } catch { /* try the next installation layout */ }
55
+ }
56
+ throw new Error("Cannot locate npm-cli.js beside Node.js, in Arco's global package directory, or through npm on PATH. Check npm --version in a terminal.");
19
57
  }
20
58
  export function repairedNativeDir(env = process.env) {
21
59
  const home = resolve(env.ARCO_HOME?.trim() || join(homedir(), '.arco'));
@@ -41,7 +41,11 @@ export async function updatePackage(manifest, root, deps = {}) {
41
41
  const env = deps.env ?? process.env, platform = deps.platform ?? process.platform;
42
42
  const home = deps.home ?? servicePaths(platform, env).home;
43
43
  const prefix = deps.prefix ?? globalPrefix(root, platform);
44
- const npm = deps.npm ?? npmCliPath(env);
44
+ let npm = deps.npm;
45
+ if (!npm) {
46
+ try { npm = npmCliPath(env, process.execPath, { packageRoot: root }); }
47
+ catch (error) { throw new Error(`${error.message} To update manually, stop Arco, run npm install -g arco-workbench, then start Arco again.`); }
48
+ }
45
49
  const run = deps.run ?? ((command, args, options = {}) => spawnSync(command, args, { encoding: 'utf8', env: { ...env, npm_config_cache: env.npm_config_cache || join(home, 'cache', 'npm') }, ...options }));
46
50
  const service = deps.service ?? ((action) => serviceAction(action));
47
51
  const rootStat = lstatSync(root);
@@ -28,6 +28,10 @@ export declare function configure(opts: {
28
28
  }): void;
29
29
  export declare function start(): void;
30
30
  export declare function stop(): void;
31
+ export declare function pickupWaitingMail(clusterId: string, liveMembers?: {
32
+ workflowId: string;
33
+ busy: boolean;
34
+ }[] | undefined): Promise<void>;
31
35
  export declare function currentAutoTurnDepth(workflowId: string): number;
32
36
  export declare function clearAutoTurnDepth(workflowId: string): void;
33
37
  export declare function dropMember(workflowId: string): void;
@@ -191,29 +191,31 @@ async function sweep() {
191
191
  if (!membersByCluster)
192
192
  return;
193
193
  for (const clusterId of clusterStore.listKnownClusterIds()) {
194
- if (!clusterStore.isAutoPickupWaking(clusterId))
195
- continue;
196
- const liveMembers = membersByCluster.get(clusterId);
197
- if (!liveMembers || liveMembers.length === 0)
194
+ await pickupWaitingMail(clusterId, membersByCluster.get(clusterId));
195
+ }
196
+ }
197
+ // Resume uses the same scan as the periodic sweep, including every normal
198
+ // guard and budget. Never reset the Rule-based ledger to resume an operator pause.
199
+ export async function pickupWaitingMail(clusterId, liveMembers = resolveMembersFn?.()?.get(clusterId)) {
200
+ if (!isBusyFn || !clusterStore.isAutoPickupWaking(clusterId) || clusterStore.isAutoPickupPaused(clusterId) || !liveMembers)
201
+ return;
202
+ for (const m of liveMembers) {
203
+ if (m.busy) {
204
+ if (dispatchBusyReminderFn)
205
+ await remindBusyMember(clusterId, m.workflowId, { isBusy: isBusyFn, hasClusterTools: hasClusterToolsFn, dispatch: dispatchBusyReminderFn });
198
206
  continue;
199
- for (const m of liveMembers) {
200
- if (m.busy) {
201
- if (dispatchBusyReminderFn)
202
- await remindBusyMember(clusterId, m.workflowId, { isBusy: isBusyFn, hasClusterTools: hasClusterToolsFn, dispatch: dispatchBusyReminderFn });
203
- continue;
204
- }
205
- if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId))
206
- continue;
207
- const pending = await clusterMailbox.peek(m.workflowId).catch(() => []);
208
- if (pending.length === 0)
209
- continue;
210
- onPeerMessageSent({
211
- clusterId,
212
- senderWfid: pending[0].fromWorkflowId,
213
- recipientWfid: m.workflowId,
214
- incomingChainDepth: heldMailDepth(m.workflowId, pending),
215
- });
216
207
  }
208
+ if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId))
209
+ continue;
210
+ const pending = await clusterMailbox.peek(m.workflowId).catch(() => []);
211
+ if (pending.length === 0)
212
+ continue;
213
+ onPeerMessageSent({
214
+ clusterId,
215
+ senderWfid: pending[0].fromWorkflowId,
216
+ recipientWfid: m.workflowId,
217
+ incomingChainDepth: heldMailDepth(m.workflowId, pending),
218
+ });
217
219
  }
218
220
  }
219
221
  function getClusterState(clusterId) {
@@ -327,6 +329,8 @@ export function onPeerMessageSent(opts) {
327
329
  return;
328
330
  if (opts.incomingChainDepth > pendingChainDepth(opts.recipientWfid))
329
331
  pendingDepth.set(opts.recipientWfid, opts.incomingChainDepth);
332
+ if (clusterStore.isAutoPickupPaused(opts.clusterId))
333
+ return;
330
334
  try {
331
335
  ruleGuard.mail(opts.clusterId, opts.senderWfid, opts.recipientWfid);
332
336
  }
@@ -356,7 +360,7 @@ function fireRulePickup(opts) {
356
360
  const now = Date.now();
357
361
  // Guard 0: cluster toggle armed. Most clusters won't have this on; the
358
362
  // gate is the first check so the hot path is one map lookup when off.
359
- if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId))
363
+ if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId) || clusterStore.isAutoPickupPaused(clusterId))
360
364
  return;
361
365
  // Guard 1: depth cap. An incoming chainDepth of (cap - 1) is the last one
362
366
  // we'll auto-turn on; the auto-turn it produces will land at cap, so the
@@ -389,13 +393,13 @@ function fireRulePickup(opts) {
389
393
  const wasBudgetPaused = ruleGuard.snapshot(clusterId).budgetPaused;
390
394
  const problem = ruleGuard.admit(clusterId, senderWfid, recipientWfid, limits, now);
391
395
  if (problem) {
392
- const notice = problem === 'budget_paused' && !wasBudgetPaused ? 'Wake budget reached. Open AUTO-PICKUP and select RESUME.' : undefined;
396
+ const notice = problem === 'budget_paused' && !wasBudgetPaused ? 'Wake budget reached. Select RESET BUDGET beside AUTO-PICKUP.' : undefined;
393
397
  emitSkip(clusterId, recipientWfid, senderWfid, incomingChainDepth, problem, now, notice);
394
398
  return;
395
399
  }
396
400
  const pauses = ruleGuard.stamp(clusterId, senderWfid, recipientWfid, limits, now);
397
401
  const notices = [
398
- ...(pauses.budgetPaused ? ['Wake budget reached. Open AUTO-PICKUP and select RESUME.'] : []),
402
+ ...(pauses.budgetPaused ? ['Wake budget reached. Select RESET BUDGET beside AUTO-PICKUP.'] : []),
399
403
  ...(pauses.pairPaused ? [`Alternating wakes paused between ${clusterStore.displayNameFor(senderWfid)} and ${clusterStore.displayNameFor(recipientWfid)}.`] : []),
400
404
  ];
401
405
  // All guards pass — fire. Mark the new depth BEFORE dispatch so the
@@ -434,7 +438,7 @@ function fireRulePickup(opts) {
434
438
  const dispatch = dispatchAutoTurnFn;
435
439
  setImmediate(() => {
436
440
  try {
437
- if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId) || isBusyFn?.(recipientWfid))
441
+ if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId) || clusterStore.isAutoPickupPaused(clusterId) || isBusyFn?.(recipientWfid))
438
442
  return;
439
443
  dispatch(recipientWfid, prompt);
440
444
  }
@@ -6,7 +6,7 @@ const states = new Map();
6
6
  const pending = new Set();
7
7
  function enabled(clusterId, workflowId, now) {
8
8
  const state = store.getClusterCached(clusterId);
9
- if (state?.remindBusy !== true || !state.members.includes(workflowId))
9
+ if (state?.remindBusy !== true || state.autoPickupPausedAt !== undefined || !state.members.includes(workflowId))
10
10
  return false;
11
11
  const mode = store.autoPickupModeOf(state);
12
12
  return mode === 'rule' || (mode === 'smart-auto' && (state.smartPickup?.session?.expiresAt ?? 0) > now);
@@ -14,6 +14,7 @@ export interface ClusterState {
14
14
  idleNudgerEnabled?: boolean;
15
15
  autoTurnOnMailboxEnabled?: boolean;
16
16
  autoPickupMode?: AutoPickupMode;
17
+ autoPickupPausedAt?: number;
17
18
  remindBusy?: boolean;
18
19
  rulePickupLimits?: Partial<RulePickupLimits>;
19
20
  smartPickup?: {
@@ -102,6 +103,7 @@ export declare function setProgressTracking(clusterId: string, mode: ClusterProg
102
103
  export declare function setAutoTurnOnMailbox(clusterId: string, enabled: boolean): Promise<ClusterState | null>;
103
104
  export declare function setAutoPickup(clusterId: string, opts: {
104
105
  mode: AutoPickupMode;
106
+ paused?: boolean;
105
107
  evaluator?: SmartPickupEvaluator;
106
108
  limits?: Partial<SmartPickupLimits>;
107
109
  ruleLimits?: Partial<RulePickupLimits>;
@@ -109,6 +111,7 @@ export declare function setAutoPickup(clusterId: string, opts: {
109
111
  now?: number;
110
112
  }): Promise<ClusterState | null>;
111
113
  export declare function getAutoPickupMode(clusterId: string): AutoPickupMode;
114
+ export declare function isAutoPickupPaused(clusterId: string): boolean;
112
115
  export declare function autoPickupModeOf(state: Pick<ClusterState, 'autoPickupMode' | 'autoTurnOnMailboxEnabled'>): AutoPickupMode;
113
116
  export declare function isAutoTurnOnMailboxEnabled(clusterId: string): boolean;
114
117
  export declare function isAutoPickupWaking(clusterId: string): boolean;
@@ -798,11 +798,27 @@ export async function setAutoTurnOnMailbox(clusterId, enabled) {
798
798
  // its own id and expiry; any other mode clears the session, which makes any
799
799
  // outstanding Smart work stale. The evaluator, last explicit choice and
800
800
  // limits persist across disarm so re-arming can offer them again.
801
+ // Pause-only updates preserve session identity and remaining running time;
802
+ // resume moves its expiry forward by the saved pause duration.
801
803
  export async function setAutoPickup(clusterId, opts) {
802
804
  return withClusterMetaLock(clusterId, async () => {
803
805
  const state = await readCluster(clusterId);
804
806
  if (!state)
805
807
  return null;
808
+ if (typeof opts.paused === 'boolean') {
809
+ if (opts.mode === 'off' || opts.mode !== autoPickupModeOf(state))
810
+ return null;
811
+ const now = opts.now ?? Date.now();
812
+ const pausedAt = state.autoPickupPausedAt;
813
+ const session = state.smartPickup?.session;
814
+ const smartPickup = !opts.paused && pausedAt !== undefined && session && isSmartPickupMode(opts.mode)
815
+ ? { ...state.smartPickup, session: { ...session, expiresAt: session.expiresAt + Math.max(0, now - pausedAt) } }
816
+ : state.smartPickup;
817
+ const next = { ...state, autoPickupPausedAt: opts.paused ? pausedAt ?? now : undefined, smartPickup };
818
+ await writeMetaAtomic(next);
819
+ rebuildIndexFor(next);
820
+ return next;
821
+ }
806
822
  const now = opts.now ?? Date.now();
807
823
  const prior = state.smartPickup ?? {};
808
824
  const limits = opts.limits ? sanitizeSmartPickupLimits({ ...sanitizeSmartPickupLimits(prior.limits), ...opts.limits }) : prior.limits;
@@ -830,6 +846,9 @@ export async function setAutoPickup(clusterId, opts) {
830
846
  rulePickupLimits: opts.ruleLimits ? sanitizeRulePickupLimits({ ...sanitizeRulePickupLimits(state.rulePickupLimits), ...opts.ruleLimits }) : state.rulePickupLimits,
831
847
  remindBusy: typeof opts.remindBusy === 'boolean' ? opts.remindBusy : state.remindBusy,
832
848
  autoPickupMode: opts.mode === 'off' ? undefined : opts.mode,
849
+ autoPickupPausedAt: opts.mode !== 'off' && opts.mode === autoPickupModeOf(state) && state.autoPickupPausedAt !== undefined
850
+ ? isSmartPickupMode(opts.mode) ? now : state.autoPickupPausedAt
851
+ : undefined,
833
852
  autoTurnOnMailboxEnabled: opts.mode === 'rule' ? true : undefined,
834
853
  smartPickup: hasSmart ? smartPickup : undefined,
835
854
  };
@@ -842,6 +861,9 @@ export function getAutoPickupMode(clusterId) {
842
861
  const state = cache.get(clusterId);
843
862
  return resolveAutoPickupMode(state?.autoPickupMode, state?.autoTurnOnMailboxEnabled);
844
863
  }
864
+ export function isAutoPickupPaused(clusterId) {
865
+ return cache.get(clusterId)?.autoPickupPausedAt !== undefined;
866
+ }
845
867
  export function autoPickupModeOf(state) {
846
868
  return resolveAutoPickupMode(state.autoPickupMode, state.autoTurnOnMailboxEnabled);
847
869
  }
@@ -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
  }
@@ -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
- // Entries older than this cannot affect any limit (hour windows and sessions
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
- ledger.entries = ledger.entries.filter((e) => e.status === 'reserved' || now - e.at < RETAIN_MS);
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
- if (!armed(clusterId))
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);