arco-workbench 0.2.5 → 0.2.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 (33) hide show
  1. package/client/dist/assets/{PhosphorBackdrop-CLILIwOQ.js → PhosphorBackdrop-Df7xl7fv.js} +1 -1
  2. package/client/dist/assets/{ThemedBackgroundShaderImpl-B87chcb5.js → ThemedBackgroundShaderImpl-HQHu9fmC.js} +1 -1
  3. package/client/dist/assets/{XtermView-BP_j7WSN.js → XtermView-BlQ7QADf.js} +1 -1
  4. package/client/dist/assets/{galleryEditor-B90phoBI.js → galleryEditor-Db_t1HrV.js} +1 -1
  5. package/client/dist/assets/{index-BfPp1Oup.js → index-BPeBsjq5.js} +99 -99
  6. package/client/dist/index.html +1 -1
  7. package/client/src/components/UpdateAction.tsx +43 -16
  8. package/client/src/help/content/cluster.tsx +1 -1
  9. package/client/src/help/content/header.tsx +7 -3
  10. package/client/src/help/content/settings.tsx +2 -2
  11. package/client/src/help/manualSections/clusters.tsx +2 -1
  12. package/client/src/help/manualSections/maintenance.tsx +10 -7
  13. package/docs/DOCKER.md +4 -3
  14. package/docs/GLOSSARY.md +1 -1
  15. package/docs/OPERATIONS.md +32 -16
  16. package/docs/PROTOCOL_CLUSTER.md +1 -1
  17. package/docs/SETTINGS.md +8 -7
  18. package/node_modules/@arco/shared/dist/clusterCoordination.js +1 -1
  19. package/node_modules/@arco/shared/package.json +1 -1
  20. package/package.json +3 -2
  21. package/scripts/packaging/arco.mjs +17 -3
  22. package/scripts/packaging/update-process.mjs +160 -0
  23. package/scripts/packaging/update.mjs +50 -11
  24. package/server/dist/clusterDirector.js +1 -2
  25. package/server/dist/providers/claude-native/worker.js +6 -5
  26. package/server/dist/updateManager.d.ts +6 -1
  27. package/server/dist/updateManager.js +87 -20
  28. package/server/package.json +1 -1
  29. package/server/src/clusterDirector.ts +1 -2
  30. package/server/src/providers/claude-native/worker.ts +6 -5
  31. package/server/src/updateManager.ts +62 -18
  32. package/shared/dist/clusterCoordination.js +1 -1
  33. package/shared/src/clusterCoordination.ts +1 -1
@@ -1,17 +1,23 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import { once } from 'node:events';
3
+ import { mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
3
4
  import { dirname, join, resolve } from 'node:path';
4
5
  import { fileURLToPath } from 'node:url';
5
6
  import { randomUUID } from 'node:crypto';
7
+ import { createRequire } from 'node:module';
6
8
  import { arcoHome } from './arcoHome.js';
7
9
  import { updateChecker } from './server/updateCheck.js';
8
10
  import { APP_VERSION } from './appVersion.js';
9
11
  import type { UpdateCheckStatus } from '@arco/shared';
10
12
 
11
13
  export type UpdateMode = 'service' | 'foreground' | 'docker';
12
- export function updateMode(platform = process.platform, env: NodeJS.ProcessEnv = process.env): UpdateMode {
14
+ export function updateMode(platform = process.platform, env: NodeJS.ProcessEnv = process.env, launcher?: 'start' | 'service-run'): UpdateMode {
13
15
  if (env.ARCO_DEPLOYMENT === 'docker') return 'docker';
14
- if (env.ARCO_PACKAGED === '1' && env.ARCO_PACKAGE_SERVICE === '1') return 'service';
16
+ if (env.ARCO_PACKAGED === '1') {
17
+ // A foreground launcher can inherit systemd markers from its parent.
18
+ if (launcher === 'start') return 'foreground';
19
+ if (launcher === 'service-run' || env.ARCO_PACKAGE_SERVICE === '1') return 'service';
20
+ }
15
21
  return platform === 'linux' && !!(env.INVOCATION_ID || env.SYSTEMD_EXEC_PID) ? 'service' : 'foreground';
16
22
  }
17
23
  const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
@@ -20,9 +26,11 @@ export function createUpdateManager(deps: {
20
26
  mode?: () => UpdateMode; home?: () => string; root?: string; env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform;
21
27
  check?: () => Promise<Pick<UpdateCheckStatus, 'latest' | 'updateAvailable' | 'checkFailure'>>;
22
28
  launch?: (command: string, args: string[]) => { status: number | null; error?: Error; stderr?: string | null };
29
+ launchForeground?: (args: string[]) => Promise<void>;
30
+ packageInstallation?: () => boolean;
31
+ argv?: string[];
23
32
  now?: () => number; version?: string;
24
33
  } = {}) {
25
- const mode = deps.mode ?? (() => updateMode());
26
34
  const home = deps.home ?? arcoHome;
27
35
  const env = deps.env ?? process.env;
28
36
  const platform = deps.platform ?? process.platform;
@@ -31,9 +39,44 @@ export function createUpdateManager(deps: {
31
39
  const launch = deps.launch ?? ((command, args) => spawnSync(command, args, { encoding: 'utf8', timeout: 15_000 }));
32
40
  const now = deps.now ?? Date.now;
33
41
  const version = deps.version ?? APP_VERSION;
42
+ const repo = deps.root ?? repoRoot;
43
+ const cli = join(repo, 'scripts', 'packaging', 'arco.mjs');
44
+ const argv = deps.argv ?? process.argv;
45
+ const launcher = (() => {
46
+ const command = argv[2];
47
+ if (!packaged || (command !== 'start' && command !== 'service-run') || !argv[1]) return undefined;
48
+ try { return realpathSync.native(argv[1]) === realpathSync.native(cli) ? command : undefined; } catch { return undefined; }
49
+ })();
50
+ const mode = deps.mode ?? (() => updateMode(platform, env, launcher));
51
+ const packageInstallation = deps.packageInstallation ?? (() => {
52
+ try {
53
+ const { verifiedPackagePrefix } = createRequire(import.meta.url)(join(repo, 'scripts', 'packaging', 'update.mjs'));
54
+ verifiedPackagePrefix(repo);
55
+ return true;
56
+ } catch { return false; }
57
+ });
58
+ const canUpdate = () => {
59
+ const current = mode();
60
+ if (!packaged) return current === 'service' && platform === 'linux';
61
+ if (!['linux', 'darwin', 'win32'].includes(platform)) return false;
62
+ if (current === 'foreground') return launcher === 'start' && packageInstallation();
63
+ return current === 'service' && launcher === 'service-run' && packageInstallation();
64
+ };
65
+ const launchForeground = deps.launchForeground ?? (async (args: string[]) => {
66
+ const child = spawn(process.execPath, args, {
67
+ detached: true, stdio: ['ignore', 'ignore', 'ignore', 'ipc'], cwd: home(), env, windowsHide: true,
68
+ });
69
+ child.once('message', (message) => {
70
+ if (message === 'stop-for-update') process.emit('SIGTERM', 'SIGTERM');
71
+ });
72
+ try { await once(child, 'spawn'); } finally { child.unref(); child.channel?.unref(); }
73
+ });
34
74
  const resultPath = () => join(home(), 'update-result.json');
35
75
  function read(): Status | null { try { const x = JSON.parse(readFileSync(resultPath(), 'utf8')); return x && typeof x.outcome === 'string' ? x : null; } catch { return null; } }
36
76
  function status() {
77
+ return { ...readStatus(), canUpdate: canUpdate() };
78
+ }
79
+ function readStatus() {
37
80
  const result = read();
38
81
  if (!result?.attemptId || !Number.isFinite(result.startedAt) || !result.fromVersion || !/^v\d+\.\d+\.\d+$/.test(result.target ?? '')) return { mode: mode(), platform, packaged, result: null };
39
82
  if (result.outcome === 'running') return { mode: mode(), platform, packaged, result: now() - result.startedAt! < 30 * 60_000 && now() >= result.startedAt! ? result : null };
@@ -52,7 +95,7 @@ export function createUpdateManager(deps: {
52
95
  }
53
96
  let starting = false;
54
97
  async function start(body: unknown) {
55
- if (mode() !== 'service') return { ok: false, status: 409, error: 'Use the update command for this run mode.' };
98
+ if (!canUpdate()) return { ok: false, status: 409, error: 'Arco cannot update this launch from the browser.' };
56
99
  if (!body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).some((key) => key !== 'expectedLatest') || typeof (body as { expectedLatest?: unknown }).expectedLatest !== 'string') return { ok: false, status: 400, error: 'Confirm the displayed release; update accepts no target.' };
57
100
  if (starting) return { ok: false, status: 409, error: 'An update is already starting.' };
58
101
  starting = true;
@@ -69,24 +112,26 @@ export function createUpdateManager(deps: {
69
112
  if (packaged) {
70
113
  const resultFile = resultPath(); mkdirSync(home(), { recursive: true, mode: 0o700 });
71
114
  writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: 'running' }), { mode: 0o600 });
72
- const repo = deps.root ?? repoRoot;
73
- const task = `arco-updater-${randomUUID()}`;
74
- const cli = join(repo, 'scripts', 'packaging', 'arco.mjs');
75
- const updateArgs = [cli, 'package-update', latest.latest, resultFile, task, attempt.attemptId];
115
+ const task = mode() === 'service' ? `arco-updater-${randomUUID()}` : '';
116
+ const updateArgs = [cli, 'package-update', latest.latest, resultFile, task, attempt.attemptId,
117
+ String(process.pid), version, env.ARCO_PORT || '3001', env.ARCO_HOST || '127.0.0.1'];
76
118
  let result: { status: number | null; error?: Error; stderr?: string | null };
77
- if (platform === 'linux') {
119
+ if (!task) {
120
+ try { await launchForeground(updateArgs); result = { status: 0 }; }
121
+ catch { result = { status: 1 }; }
122
+ } else if (platform === 'linux') {
78
123
  if ([repo, resultFile, home(), process.execPath].some((value) => value.includes('$'))) {
79
- const message = 'Run arco update from a terminal.';
124
+ const message = 'The installation path cannot be passed safely to the service updater.';
80
125
  writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: 'failed', message, finishedAt: now() }), { mode: 0o600 });
81
126
  return { ok: false, status: 503, error: message };
82
127
  }
83
- result = launch('systemd-run', ['--user', '--collect', '--no-ask-password', '--service-type=exec', '--quiet', `--unit=${task}`, `--working-directory=${home()}`, `--setenv=ARCO_HOME=${home()}`, ...(env.PATH ? [`--setenv=PATH=${env.PATH}`] : []), process.execPath, ...updateArgs]);
128
+ result = launch('systemd-run', ['--user', '--collect', '--no-ask-password', '--service-type=exec', '--quiet', `--unit=${task}`, `--working-directory=${home()}`, `--setenv=ARCO_HOME=${home()}`, ...(env.PATH ? [`--setenv=PATH=${env.PATH}`] : []), ...(env.XDG_CONFIG_HOME ? [`--setenv=XDG_CONFIG_HOME=${env.XDG_CONFIG_HOME}`] : []), process.execPath, ...updateArgs]);
84
129
  } else if (platform === 'darwin') {
85
130
  result = launch('launchctl', ['submit', '-l', task, '--', process.execPath, ...updateArgs]);
86
131
  } else if (platform === 'win32') {
87
132
  const user = env.USERDOMAIN && env.USERNAME ? `${env.USERDOMAIN}\\${env.USERNAME}` : env.USERNAME;
88
133
  if (!user || [user, repo, resultFile, process.execPath].some((value) => /[\r\n\0]/.test(value))) {
89
- const message = 'Run arco update from a terminal.';
134
+ const message = 'The updater could not identify the Windows account or installation.';
90
135
  writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: 'failed', message, finishedAt: now() }), { mode: 0o600 });
91
136
  return { ok: false, status: 503, error: message };
92
137
  }
@@ -102,7 +147,7 @@ export function createUpdateManager(deps: {
102
147
  } else rmSync(xmlPath, { force: true });
103
148
  } else result = { status: 1 };
104
149
  if (result.error || result.status !== 0) {
105
- const message = 'Could not start a separate updater. Run arco update from a terminal.';
150
+ const message = 'Could not start a separate updater. Try again.';
106
151
  writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: 'failed', message, finishedAt: now() }), { mode: 0o600 });
107
152
  return { ok: false, status: 503, error: message };
108
153
  }
@@ -112,9 +157,8 @@ export function createUpdateManager(deps: {
112
157
  if (!/^[a-zA-Z0-9][a-zA-Z0-9_.@-]*\.service$/.test(unit)) return { ok: false, status: 409, error: 'The service unit name is invalid.' };
113
158
  const resultFile = resultPath(); mkdirSync(home(), { recursive: true, mode: 0o700 });
114
159
  writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: 'running' }), { mode: 0o600 });
115
- const repo = deps.root ?? repoRoot;
116
160
  if ([repo, resultFile, home(), process.execPath].some((value) => value.includes('$'))) {
117
- const message = 'The checkout or home path cannot be passed safely to the service. Run npm run arco:update from a terminal.';
161
+ const message = 'The checkout or home path cannot be passed safely to the service updater.';
118
162
  writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: 'failed', message, finishedAt: now() }), { mode: 0o600 });
119
163
  return { ok: false, status: 503, error: message };
120
164
  }
@@ -123,7 +167,7 @@ export function createUpdateManager(deps: {
123
167
  process.execPath, join(repo, 'scripts', 'arco-update.mjs'), '--yes', '--require-service', '--expected-release', latest.latest, '--result-file', resultFile, '--attempt-id', attempt.attemptId];
124
168
  const result = launch('systemd-run', args);
125
169
  if (result.error || result.status !== 0) {
126
- const message = 'Could not start a separate updater. Run npm run arco:update from a terminal.';
170
+ const message = 'Could not start a separate updater. Try again.';
127
171
  writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: 'failed', message, finishedAt: now() }), { mode: 0o600 });
128
172
  return { ok: false, status: 503, error: message };
129
173
  }
@@ -1,7 +1,7 @@
1
1
  // Shared deterministic coordination wording for worker prompts and operator nudges.
2
2
  import { CLUSTER_EFFICIENCY_ADDENDUM_MAX } from './protocol/clusters.js';
3
3
  export const isClusterDirector = (role) => /^\s*(?:director|coordinator)\b/i.test(role ?? '');
4
- const DIRECTOR_TURN_WAIT = 'Do not wait inside a turn for long-running checks: never sleep or poll for more than 60 seconds at a time. Start long runs in the background or hand them off, report what is running, and end the turn.';
4
+ const DIRECTOR_TURN_WAIT = 'For Directors and Coordinators: stay available to the operator. Follow operator and project instructions on long checks and when to end the turn.';
5
5
  export const AGENT_TURN_WAIT = 'For standalone agents and non-Director cluster members: when a report depends on a build, test run or CI result, wait inside the turn in steps of at most 120 seconds each, repeated as many times as the job needs. Use a foreground command within the tool timeout or check a background run between steps. Between waits, check for new messages (peer_read in a cluster) and act on them. Report when the result is in. End the turn early only when blocked or when the job clearly cannot finish within a reasonable time; then state in one line what you are waiting on and that you need a nudge. When you report progress or answer a question while assigned work is unfinished, continue that work in the same turn; end the turn only when it is done or with one stated blocker.';
6
6
  /** Blocked reasons that ask the operator (not a peer) for a decision or action.
7
7
  * Shared by the board's BLOCKED badge and the Director's open-work block so
@@ -3,7 +3,7 @@ import { CLUSTER_EFFICIENCY_ADDENDUM_MAX, type ClusterEfficiencyLevel, type Clus
3
3
 
4
4
  export const isClusterDirector = (role?: string): boolean => /^\s*(?:director|coordinator)\b/i.test(role ?? '');
5
5
 
6
- const DIRECTOR_TURN_WAIT = 'Do not wait inside a turn for long-running checks: never sleep or poll for more than 60 seconds at a time. Start long runs in the background or hand them off, report what is running, and end the turn.';
6
+ const DIRECTOR_TURN_WAIT = 'For Directors and Coordinators: stay available to the operator. Follow operator and project instructions on long checks and when to end the turn.';
7
7
  export const AGENT_TURN_WAIT = 'For standalone agents and non-Director cluster members: when a report depends on a build, test run or CI result, wait inside the turn in steps of at most 120 seconds each, repeated as many times as the job needs. Use a foreground command within the tool timeout or check a background run between steps. Between waits, check for new messages (peer_read in a cluster) and act on them. Report when the result is in. End the turn early only when blocked or when the job clearly cannot finish within a reasonable time; then state in one line what you are waiting on and that you need a nudge. When you report progress or answer a question while assigned work is unfinished, continue that work in the same turn; end the turn only when it is done or with one stated blocker.';
8
8
 
9
9
  /** Blocked reasons that ask the operator (not a peer) for a decision or action.