arco-workbench 0.2.0 → 0.2.1
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/client/dist/assets/{PhosphorBackdrop-9jNRO1ZM.js → PhosphorBackdrop-BbR3xmfD.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-tUi3k54Y.js → ThemedBackgroundShaderImpl-UMjbs9ZN.js} +1 -1
- package/client/dist/assets/{XtermView-B7BOSnVo.js → XtermView-n135qz-f.js} +1 -1
- package/client/dist/assets/{galleryEditor-Ohc2h9cD.js → galleryEditor-CFSke4by.js} +1 -1
- package/client/dist/assets/{index-ILGXWriO.js → index-DeoJbjI3.js} +235 -235
- package/client/dist/index.html +1 -1
- package/client/src/components/HeaderVersionBox.tsx +6 -8
- package/client/src/components/SettingsPanel.tsx +44 -6
- package/client/src/components/settings/AppVersionSection.tsx +4 -4
- package/client/src/help/content/header.tsx +3 -2
- package/client/src/help/content/settings.tsx +10 -5
- package/client/src/help/manualSections/configuration.tsx +2 -0
- package/client/src/help/manualSections/maintenance.tsx +11 -7
- package/client/src/stores/appUpdateStore.ts +7 -1
- package/docs/HTTP_API.md +2 -2
- package/docs/OPERATIONS.md +22 -14
- package/docs/PROTOCOL.md +2 -2
- package/docs/RESEARCH.md +1 -1
- package/docs/SETTINGS.md +11 -7
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +2 -2
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/scripts/packaging/update.mjs +92 -35
- package/server/dist/authLoginSession.js +9 -1
- package/server/dist/http/diagnosticsRoutes.js +1 -1
- package/server/dist/providers/antigravity/index.js +2 -2
- package/server/dist/providers/antigravity/status.js +3 -2
- package/server/dist/providers/antigravity/usage.js +3 -2
- package/server/dist/updateCheck.js +53 -67
- package/server/dist/updateManager.d.ts +2 -4
- package/server/dist/updateManager.js +4 -1
- package/server/dist/windowsCommand.d.ts +15 -0
- package/server/dist/windowsCommand.js +85 -4
- package/server/package.json +1 -1
- package/server/src/authLoginSession.ts +9 -1
- package/server/src/http/diagnosticsRoutes.ts +1 -1
- package/server/src/providers/antigravity/index.ts +2 -2
- package/server/src/providers/antigravity/status.ts +3 -2
- package/server/src/providers/antigravity/usage.ts +3 -2
- package/server/src/updateCheck.ts +47 -54
- package/server/src/updateManager.ts +5 -2
- package/server/src/windowsCommand.ts +83 -4
- package/shared/dist/protocol/serverMessages.d.ts +2 -2
- package/shared/src/protocol/serverMessages.ts +2 -2
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.2.
|
|
7
|
+
"version": "0.2.1",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/ghreprimand/arco.git"
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"word-extractor": "1.0.4",
|
|
68
68
|
"ws": "8.22.0",
|
|
69
69
|
"xlsx": "0.20.3",
|
|
70
|
-
"@arco/shared": "0.2.
|
|
70
|
+
"@arco/shared": "0.2.1"
|
|
71
71
|
},
|
|
72
72
|
"bundleDependencies": [
|
|
73
73
|
"@arco/shared",
|
|
@@ -37,7 +37,45 @@ export function writeUpdateResult(resultFile, attemptId, result, now = Date.now)
|
|
|
37
37
|
writeFileSync(resultFile, JSON.stringify({ ...attempt, outcome: result.outcome, ...(typeof result.message === 'string' ? { message: result.message } : {}), finishedAt: now() }), { mode: 0o600 });
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
// npm diagnostics can contain registry credentials, URLs and local paths.
|
|
41
|
+
const safeErrorCodes = new Set([
|
|
42
|
+
'E401', 'E403', 'E404', 'E405', 'E429', 'E500', 'E502', 'E503', 'E504',
|
|
43
|
+
'EACCES', 'EAUTH', 'EAI_AGAIN', 'ECONNREFUSED', 'ECONNRESET', 'EEXIST',
|
|
44
|
+
'EINTEGRITY', 'EINVAL', 'EIO', 'ENOENT', 'ENOMSG', 'ENOSPC', 'ENOTCACHED',
|
|
45
|
+
'ENOTEMPTY', 'ENOTFOUND', 'EOVERFLOW', 'EPERM', 'ERESOLVE', 'ETARGET',
|
|
46
|
+
'ETIMEDOUT', 'ERR_TLS_CERT_ALTNAME_INVALID', 'SELF_SIGNED_CERT_IN_CHAIN',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
function npmFailure(result) {
|
|
50
|
+
const diagnostic = /^npm (?:error|ERR!) code ([A-Z0-9_]+)\r?$/mi;
|
|
51
|
+
const code = result.error?.code ?? diagnostic.exec(result.stderr ?? '')?.[1] ?? diagnostic.exec(result.stdout ?? '')?.[1];
|
|
52
|
+
if (safeErrorCodes.has(code)) return ' (' + code + ')';
|
|
53
|
+
return Number.isInteger(result.status) ? ' (npm exit ' + result.status + ')' : '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const publicRegistry = '--registry=https://registry.npmjs.org/';
|
|
57
|
+
|
|
58
|
+
function stagePackage(call, name, version, scratch) {
|
|
59
|
+
const expectedName = `${name.replace(/^@/, '').replace('/', '-')}-${version}.tgz`;
|
|
60
|
+
const archive = join(scratch, expectedName);
|
|
61
|
+
const result = call('Package download failed', [
|
|
62
|
+
'pack', `${name}@${version}`, '--json', '--ignore-scripts', '--pack-destination', scratch,
|
|
63
|
+
publicRegistry, '--prefer-online', '--fetch-retries=0', '--fetch-timeout=30000',
|
|
64
|
+
], { timeout: 90_000 });
|
|
65
|
+
let packed, stat;
|
|
66
|
+
try {
|
|
67
|
+
stat = lstatSync(archive, { throwIfNoEntry: false });
|
|
68
|
+
packed = JSON.parse(result.stdout);
|
|
69
|
+
} catch { /* invalid npm output or archive */ }
|
|
70
|
+
if (!Array.isArray(packed) || packed.length !== 1 || packed[0]?.name !== name
|
|
71
|
+
|| packed[0]?.version !== version || packed[0]?.filename !== expectedName || !stat?.isFile() || stat.size === 0) {
|
|
72
|
+
throw new Error('Package download failed: npm did not stage the requested archive');
|
|
73
|
+
}
|
|
74
|
+
return archive;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function updatePackage(manifest, packageRoot, deps = {}) {
|
|
78
|
+
const root = resolve(packageRoot);
|
|
41
79
|
const env = deps.env ?? process.env, platform = deps.platform ?? process.platform;
|
|
42
80
|
const home = deps.home ?? servicePaths(platform, env).home;
|
|
43
81
|
const prefix = deps.prefix ?? globalPrefix(root, platform);
|
|
@@ -56,36 +94,37 @@ export async function updatePackage(manifest, root, deps = {}) {
|
|
|
56
94
|
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
57
95
|
const lock = join(home, 'package-update.lock'); let lockFd;
|
|
58
96
|
try { lockFd = openSync(lock, 'wx', 0o600); } catch { throw new Error('Another update may be running. Verify that no update is active before removing package-update.lock from the Arco home.'); }
|
|
59
|
-
|
|
60
|
-
let stopped = false,
|
|
61
|
-
const call = (args, options = {}) => {
|
|
97
|
+
let scratch, backup, preserve = false;
|
|
98
|
+
let stopped = false, installAttempted = false;
|
|
99
|
+
const call = (stage, args, options = {}) => {
|
|
62
100
|
const result = run(process.execPath, [npm, ...args], options);
|
|
63
|
-
if (result.error || result.status !== 0) throw new Error(
|
|
101
|
+
if (result.error || result.status !== 0) throw new Error(stage + npmFailure(result));
|
|
64
102
|
return result;
|
|
65
103
|
};
|
|
66
104
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const parsed = JSON.parse(result.stdout || 'null');
|
|
71
|
-
version = Array.isArray(parsed) && parsed.length === 1 ? parsed[0] : parsed;
|
|
72
|
-
if (typeof version !== 'string' || !/^\d+\.\d+\.\d+$/.test(version)) throw new Error('The registry did not return a stable release version.');
|
|
73
|
-
}
|
|
105
|
+
scratch = mkdtempSync(join(home, '.update-'));
|
|
106
|
+
backup = join(scratch, 'previous-package');
|
|
107
|
+
let version;
|
|
74
108
|
if (!deps.target) {
|
|
109
|
+
const result = call('Could not check npm for updates', [
|
|
110
|
+
'view', `${manifest.name}@latest`, 'version', '--json', publicRegistry,
|
|
111
|
+
'--prefer-online', '--fetch-retries=0', '--fetch-timeout=5000',
|
|
112
|
+
], { timeout: 10_000 });
|
|
113
|
+
let parsed;
|
|
114
|
+
try { parsed = JSON.parse(result.stdout); } catch { /* invalid npm output */ }
|
|
115
|
+
version = Array.isArray(parsed) && parsed.length === 1 ? parsed[0] : parsed;
|
|
116
|
+
if (typeof version !== 'string' || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) {
|
|
117
|
+
throw new Error('npm did not return a stable release version');
|
|
118
|
+
}
|
|
119
|
+
if (deps.expected && deps.expected !== `v${version}`) {
|
|
120
|
+
throw new Error('The latest npm version changed. Use CHECK NOW to review it before updating');
|
|
121
|
+
}
|
|
75
122
|
const order = compareVersions(version, manifest.version);
|
|
76
123
|
if (order === null) throw new Error('The installed or target package version is invalid.');
|
|
77
124
|
if (order < 0) throw new Error('The latest package is older than this installation. A downgrade is not performed.');
|
|
78
125
|
if (order === 0) return { outcome: 'unchanged', message: 'Already on the newest release.' };
|
|
79
|
-
if (deps.expected) {
|
|
80
|
-
let published;
|
|
81
|
-
try {
|
|
82
|
-
const result = call(['view', `${manifest.name}@${version}`, 'version', '--json', '--cache', join(scratch, 'registry-cache'), '--prefer-online', '--fetch-retries=0', '--fetch-timeout=5000'], { timeout: 15000 });
|
|
83
|
-
published = JSON.parse(result.stdout || 'null');
|
|
84
|
-
if (Array.isArray(published) && published.length === 1) published = published[0];
|
|
85
|
-
} catch { throw new Error('The confirmed release is not available from the npm registry, or the registry could not be reached. Try again later.'); }
|
|
86
|
-
if (published !== version) throw new Error('The confirmed release is not available from the npm registry, or the registry could not be reached. Try again later.');
|
|
87
|
-
}
|
|
88
126
|
}
|
|
127
|
+
const archive = deps.target ?? stagePackage(call, manifest.name, version, scratch);
|
|
89
128
|
// Dependencies are not all bundled in the tarball. A full local snapshot
|
|
90
129
|
// permits rollback even when the registry or the network is unavailable.
|
|
91
130
|
cpSync(root, backup, { recursive: true, dereference: false, verbatimSymlinks: true, errorOnExist: true, force: false });
|
|
@@ -98,9 +137,8 @@ export async function updatePackage(manifest, root, deps = {}) {
|
|
|
98
137
|
const running = servicePid ? await waitForRecordedPid(servicePid, deps) : await windowsRunning();
|
|
99
138
|
if (running) throw new Error(servicePid ? `The Arco service process ${servicePid} is still running. Stop it before updating on Windows.` : 'Stop all Arco processes before updating on Windows.');
|
|
100
139
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
call(['install', '--global', '--ignore-scripts', '--no-audit', '--no-fund', '--prefix', prefix, target], { stdio: 'inherit' });
|
|
140
|
+
installAttempted = true;
|
|
141
|
+
call('Package installation failed', ['install', '--global', '--ignore-scripts', '--no-audit', '--no-fund', '--prefix', prefix, archive]);
|
|
104
142
|
// The new package may define the service differently. A fresh process loads
|
|
105
143
|
// the new code to
|
|
106
144
|
// rewrite an unmodified Arco-owned definition; a failure keeps the old one.
|
|
@@ -114,23 +152,42 @@ export async function updatePackage(manifest, root, deps = {}) {
|
|
|
114
152
|
return { outcome: 'updated', message: `Updated${version ? ` to v${version}` : ` ${manifest.name}`}; ${managed ? 'service restarted' : 'restart Arco to use the update'}.${refreshNote}` };
|
|
115
153
|
} catch (error) {
|
|
116
154
|
const detail = String(error.message).replace(/[.\s]+$/, '');
|
|
117
|
-
|
|
155
|
+
let damaged;
|
|
156
|
+
if (installAttempted) {
|
|
118
157
|
// Keep both copies until a complete restoration is available. If the
|
|
119
158
|
// copy fails, retain the snapshot and report its location for recovery.
|
|
120
|
-
|
|
159
|
+
damaged = `${root}.arco-update-failed-${process.pid}`;
|
|
121
160
|
try {
|
|
122
|
-
if (
|
|
123
|
-
if (
|
|
161
|
+
if (lstatSync(damaged, { throwIfNoEntry: false })) throw new Error('A previous failed update needs manual recovery.');
|
|
162
|
+
if (lstatSync(root, { throwIfNoEntry: false })) renameSync(root, damaged);
|
|
124
163
|
try { cpSync(backup, root, { recursive: true, dereference: false, verbatimSymlinks: true, errorOnExist: true, force: false }); }
|
|
125
|
-
catch (copyError) {
|
|
126
|
-
|
|
127
|
-
|
|
164
|
+
catch (copyError) { rmSync(root, { recursive: true, force: true }); if (lstatSync(damaged, { throwIfNoEntry: false })) renameSync(damaged, root); throw copyError; }
|
|
165
|
+
} catch (rollback) {
|
|
166
|
+
preserve = true;
|
|
167
|
+
const code = safeErrorCodes.has(rollback.code) ? ' (' + rollback.code + ')' : '';
|
|
168
|
+
throw new Error(`Update failed: ${detail}. Could not restore the previous package${code}. Keep Arco stopped and copy the snapshot back to the original package folder. Previous package snapshot: ${backup}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (stopped) {
|
|
172
|
+
try { await service('start'); }
|
|
173
|
+
catch {
|
|
174
|
+
preserve = true;
|
|
175
|
+
const recovery = installAttempted
|
|
176
|
+
? `The previous package was restored. Previous package snapshot: ${backup}`
|
|
177
|
+
: 'The installed package was left unchanged.';
|
|
178
|
+
throw new Error(`Update failed: ${detail}. The service could not restart. Check the service and run arco service start after resolving the error. ${recovery}`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const recovery = installAttempted ? ' The previous package was restored.' + (stopped ? ' The service was restarted.' : '') : '';
|
|
182
|
+
let cleanupNote = '';
|
|
183
|
+
if (damaged) {
|
|
184
|
+
try { rmSync(damaged, { recursive: true, force: true }); }
|
|
185
|
+
catch { cleanupNote = ' The failed package remains in quarantine beside the installation.'; }
|
|
128
186
|
}
|
|
129
|
-
|
|
130
|
-
throw new Error(`Update failed: ${detail}.${installed ? ' The previous package was restored.' : ''}`);
|
|
187
|
+
throw new Error(`Update failed: ${detail}.${recovery}${cleanupNote}`);
|
|
131
188
|
} finally {
|
|
132
|
-
if (!preserve) rmSync(scratch, { recursive: true, force: true });
|
|
133
|
-
closeSync(lockFd); try { unlinkSync(lock); } catch { /* stale lock fails closed */ }
|
|
189
|
+
try { if (scratch && !preserve) rmSync(scratch, { recursive: true, force: true }); }
|
|
190
|
+
finally { closeSync(lockFd); try { unlinkSync(lock); } catch { /* stale lock fails closed */ } }
|
|
134
191
|
}
|
|
135
192
|
}
|
|
136
193
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { noteAntigravityLoginCompleted } from './providers/antigravity/status.js';
|
|
8
8
|
import { noteGeminiResearchSignInExpired } from './providers/antigravity/researchSignIn.js';
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
|
+
import { resolveLoginCommand, withSinglePath } from './windowsCommand.js';
|
|
10
11
|
import { killProcessTree } from './workers/processKill.js';
|
|
11
12
|
const SESSION_TTL_MS = 15 * 60_000;
|
|
12
13
|
const OUTPUT_CAP = 16 * 1024;
|
|
@@ -71,11 +72,18 @@ export function startLoginSession(provider, command) {
|
|
|
71
72
|
};
|
|
72
73
|
live.set(provider, entry);
|
|
73
74
|
let child;
|
|
75
|
+
// Windows: find the program the way provider turns do (running PATH, then the
|
|
76
|
+
// PATH a new terminal reads), so sign-in does not depend on cmd.exe alone.
|
|
77
|
+
const resolved = resolveLoginCommand(spec.command ?? command, { fresh: provider === 'antigravity-cli' });
|
|
78
|
+
if ('missing' in resolved) {
|
|
79
|
+
finish(entry, 'failed', `${resolved.missing} was not found on the PATH Arco is running with. Restart Arco from a new terminal after installing it, or run the sign-in command in your terminal.`);
|
|
80
|
+
return snapshot(entry);
|
|
81
|
+
}
|
|
74
82
|
try {
|
|
75
83
|
// No browser exists where the server runs; the CLIs print the link anyway.
|
|
76
84
|
// detached on POSIX makes the shell a process-group leader, so a cancel or
|
|
77
85
|
// timeout reaches the provider CLI it started, not only the shell.
|
|
78
|
-
child = spawn(
|
|
86
|
+
child = spawn(resolved.line, { shell: true, detached: process.platform !== 'win32', windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'], env: Object.fromEntries(Object.entries({ ...(resolved.path ? withSinglePath(process.env, resolved.path) : process.env), BROWSER: 'true', NO_BROWSER: 'true', ...(spec.env ?? {}) }).filter(([name]) => !spec.unsetEnv?.includes(name))) });
|
|
79
87
|
}
|
|
80
88
|
catch (err) {
|
|
81
89
|
finish(entry, 'failed', err instanceof Error ? err.message : String(err));
|
|
@@ -37,7 +37,7 @@ export async function tryHandleDiagnosticsRoutes(req, res) {
|
|
|
37
37
|
const path = req.url.split('?')[0];
|
|
38
38
|
if (path === '/api/diagnostics/research-sandbox') {
|
|
39
39
|
const [claudeCli, codex, cursor, gemini, geminiSignIn] = await Promise.all([researchSandboxAvailable('claude'), researchSandboxAvailable('codex'), researchSandboxAvailable('cursor'), researchSandboxAvailable('antigravity'), geminiResearchSignInState()]);
|
|
40
|
-
return send(200, { claudeCli, codex, cursor, gemini, geminiSignIn, codexVersionReason: codexResearchVersionReason(installedCodexVersion()), cursorVersionReason: cursorIsolationReason() });
|
|
40
|
+
return send(200, { claudeCli, codex, cursor, gemini, geminiSignIn, platform: process.platform, codexVersionReason: codexResearchVersionReason(installedCodexVersion()), cursorVersionReason: cursorIsolationReason() });
|
|
41
41
|
}
|
|
42
42
|
if (path === '/api/diagnostics/support-bundle') {
|
|
43
43
|
try {
|
|
@@ -18,7 +18,7 @@ import { spawn } from 'node:child_process';
|
|
|
18
18
|
import { EventEmitter } from 'node:events';
|
|
19
19
|
import { AcpJsonRpcClient, AcpReplyError } from '../acp/acpJsonRpc.js';
|
|
20
20
|
import { cancelAcpPermissions, requestAcpPermission } from '../acp/permissionGate.js';
|
|
21
|
-
import {
|
|
21
|
+
import { resolveCommand } from '../../windowsCommand.js';
|
|
22
22
|
import { killProcessTree } from '../../workers/processKill.js';
|
|
23
23
|
import { probeVersion } from '../../capabilities.js';
|
|
24
24
|
import { compareVersions } from '../../updateCheck.js';
|
|
@@ -146,7 +146,7 @@ class AntigravityTurn extends EventEmitter {
|
|
|
146
146
|
}
|
|
147
147
|
const proc = fenced
|
|
148
148
|
? spawn(fenced.command.file, fenced.command.args, { cwd: '/', env: { PATH: '/usr/bin:/bin' }, stdio: ['pipe', 'pipe', 'pipe'], detached: true })
|
|
149
|
-
:
|
|
149
|
+
: (() => { const agy = resolveCommand('agy', ['acp'], { fresh: true }); return spawn(agy.command, agy.args, { cwd, ...(agy.env ? { env: agy.env } : {}), stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32' }); })();
|
|
150
150
|
if (fenced) {
|
|
151
151
|
const launch = fenced;
|
|
152
152
|
proc.once('close', () => { void launch.close().catch(() => this.emit('system_notice', 'Worker isolation cleanup failed.')); });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
-
import {
|
|
3
|
+
import { resolveCommand } from '../../windowsCommand.js';
|
|
4
4
|
let authState = 'unknown';
|
|
5
5
|
let models = [];
|
|
6
6
|
let capabilities = {};
|
|
@@ -13,7 +13,8 @@ export async function antigravityStatus() {
|
|
|
13
13
|
if (Date.now() - lastProbe > 60_000) {
|
|
14
14
|
lastProbe = Date.now();
|
|
15
15
|
try {
|
|
16
|
-
const
|
|
16
|
+
const agy = resolveCommand('agy', ['models'], { fresh: true });
|
|
17
|
+
const { stdout } = await exec(agy.command, agy.args, { timeout: 10_000, maxBuffer: 256 * 1024, ...(agy.env ? { env: agy.env } : {}) });
|
|
17
18
|
const ids = stdout.split(/\r?\n/).map(line => line.split(/\s+/)[0]).filter(id => /^gemini-[a-z0-9.-]+$/.test(id));
|
|
18
19
|
models = [...new Set(ids.map(id => id.replace(/-(low|medium|high|xhigh)$/, '')))];
|
|
19
20
|
capabilities = Object.fromEntries(models.map(model => { const levels = ['low', 'medium', 'high', 'xhigh'].filter(level => ids.includes(`${model}-${level}`)); return [model, { tools: true, vision: true, thinking: levels.length > 0, thinkingLevels: levels }]; }));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
-
import {
|
|
3
|
+
import { resolveCommand } from '../../windowsCommand.js';
|
|
4
4
|
const exec = promisify(execFile);
|
|
5
5
|
export function parseAntigravityUsage(text) {
|
|
6
6
|
try {
|
|
@@ -25,7 +25,8 @@ export function parseAntigravityUsage(text) {
|
|
|
25
25
|
}
|
|
26
26
|
export async function getAntigravityUsage() {
|
|
27
27
|
try {
|
|
28
|
-
const
|
|
28
|
+
const agy = resolveCommand('agy', ['-p', '/usage', '--output-format', 'json'], { fresh: true });
|
|
29
|
+
const { stdout } = await exec(agy.command, agy.args, { timeout: 5000, killSignal: 'SIGKILL', maxBuffer: 256 * 1024, windowsHide: true, ...(agy.env ? { env: agy.env } : {}) });
|
|
29
30
|
return parseAntigravityUsage(stdout);
|
|
30
31
|
}
|
|
31
32
|
catch {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const GITHUB_LATEST = 'https://api.github.com/repos/ghreprimand/arco/releases/latest';
|
|
2
|
+
const NPM_LATEST = 'https://registry.npmjs.org/arco-workbench/latest';
|
|
3
|
+
const STABLE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
2
4
|
const RELEASE_PREFIX = 'https://github.com/ghreprimand/arco/releases/tag/';
|
|
3
5
|
const SEMVER = /^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][\da-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][\da-zA-Z-]*))*))?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/;
|
|
4
6
|
export function compareVersions(a, b) {
|
|
@@ -40,81 +42,65 @@ export function createUpdateChecker(deps) {
|
|
|
40
42
|
async function status() {
|
|
41
43
|
return { ...cache, enabled: enabled(await deps.settings()) };
|
|
42
44
|
}
|
|
45
|
+
async function lookup() {
|
|
46
|
+
const response = await request(deps.packaged ? NPM_LATEST : GITHUB_LATEST, {
|
|
47
|
+
headers: { Accept: deps.packaged ? 'application/json' : 'application/vnd.github+json', 'User-Agent': `arco/${deps.current}` },
|
|
48
|
+
signal: AbortSignal.timeout(5000), redirect: 'error',
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok)
|
|
51
|
+
throw new Error('Release check unavailable');
|
|
52
|
+
if (deps.packaged) {
|
|
53
|
+
const pkg = await response.json();
|
|
54
|
+
const version = pkg?.version;
|
|
55
|
+
if (pkg?.name !== 'arco-workbench' || typeof version !== 'string' || !STABLE_VERSION.test(version) ||
|
|
56
|
+
pkg.dist?.tarball !== `https://registry.npmjs.org/arco-workbench/-/arco-workbench-${version}.tgz`)
|
|
57
|
+
throw new Error('Invalid npm release');
|
|
58
|
+
const latest = `v${version}`;
|
|
59
|
+
return { latest, url: RELEASE_PREFIX + latest, publishedAt: null };
|
|
60
|
+
}
|
|
61
|
+
const release = await response.json();
|
|
62
|
+
const tag = release?.tag_name;
|
|
63
|
+
if (typeof tag !== 'string' || !STABLE_VERSION.test(tag.replace(/^v/, '')) ||
|
|
64
|
+
typeof release.html_url !== 'string' || !release.html_url.startsWith(RELEASE_PREFIX) ||
|
|
65
|
+
typeof release.published_at !== 'string' || !Number.isFinite(Date.parse(release.published_at)))
|
|
66
|
+
throw new Error('Invalid GitHub release');
|
|
67
|
+
return { latest: `v${tag.replace(/^v/, '')}`, url: release.html_url, publishedAt: release.published_at };
|
|
68
|
+
}
|
|
43
69
|
async function perform() {
|
|
44
70
|
if (!enabled(await deps.settings()))
|
|
45
71
|
return status();
|
|
46
|
-
|
|
72
|
+
const checkedAt = now().toISOString();
|
|
73
|
+
let release;
|
|
47
74
|
try {
|
|
48
|
-
|
|
49
|
-
headers: { Accept: 'application/vnd.github+json', 'User-Agent': `arco/${deps.current}` },
|
|
50
|
-
signal: AbortSignal.timeout(5000), redirect: 'error',
|
|
51
|
-
});
|
|
52
|
-
if (!response.ok)
|
|
53
|
-
throw new Error('release check unavailable');
|
|
54
|
-
const release = await response.json();
|
|
55
|
-
const tag = release.tag_name;
|
|
56
|
-
if (typeof tag !== 'string' || compareVersions(tag, deps.current) === null ||
|
|
57
|
-
typeof release.html_url !== 'string' || !release.html_url.startsWith(RELEASE_PREFIX) ||
|
|
58
|
-
typeof release.published_at !== 'string' || !Number.isFinite(Date.parse(release.published_at)))
|
|
59
|
-
throw new Error('invalid release');
|
|
60
|
-
const latest = `v${tag.replace(/^v/, '')}`;
|
|
61
|
-
let packageStatus;
|
|
62
|
-
if (deps.packaged && compareVersions(tag, deps.current) > 0) {
|
|
63
|
-
try {
|
|
64
|
-
const version = tag.replace(/^v/, '');
|
|
65
|
-
if (!/^\d+\.\d+\.\d+$/.test(version))
|
|
66
|
-
throw new Error('not a stable version');
|
|
67
|
-
const npm = await request(`https://registry.npmjs.org/arco-workbench/${version}`, {
|
|
68
|
-
headers: { Accept: 'application/json' }, signal: AbortSignal.timeout(5000), redirect: 'error',
|
|
69
|
-
});
|
|
70
|
-
if (npm.status === 404)
|
|
71
|
-
packageStatus = 'unpublished';
|
|
72
|
-
else if (!npm.ok)
|
|
73
|
-
packageStatus = 'unknown';
|
|
74
|
-
else {
|
|
75
|
-
const metadata = await npm.json();
|
|
76
|
-
packageStatus = metadata.name === 'arco-workbench' && metadata.version === version && !!(metadata.dist && typeof metadata.dist === 'object' && typeof metadata.dist.tarball === 'string') ? 'available' : 'unknown';
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
packageStatus = 'unknown';
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Re-read preferences: an opt-out or dismissal can arrive during the request.
|
|
84
|
-
const settings = await deps.settings();
|
|
85
|
-
if (!enabled(settings))
|
|
86
|
-
return status();
|
|
87
|
-
const wasAvailable = cache.updateAvailable;
|
|
88
|
-
const previousLatest = cache.latest;
|
|
89
|
-
cache = { ...cache, latest, url: release.html_url, publishedAt: release.published_at, updateAvailable: compareVersions(tag, deps.current) > 0 && (!deps.packaged || packageStatus === 'available'), ...(deps.packaged ? { packageStatus } : {}) };
|
|
90
|
-
if (deps.packaged && wasAvailable && !cache.updateAvailable) {
|
|
91
|
-
if (previousLatest)
|
|
92
|
-
announced.delete(previousLatest);
|
|
93
|
-
deps.broadcast({ type: 'app_update_status_changed' });
|
|
94
|
-
}
|
|
95
|
-
if (cache.updateAvailable && settings.updateCheckDismissed !== latest && !announced.has(latest)) {
|
|
96
|
-
announced.add(latest);
|
|
97
|
-
const message = { type: 'app_update_available', current: deps.current, latest, url: release.html_url, publishedAt: release.published_at };
|
|
98
|
-
deps.broadcast(message);
|
|
99
|
-
deps.log?.(`app_update_available ${latest}`);
|
|
100
|
-
}
|
|
75
|
+
release = await lookup();
|
|
101
76
|
}
|
|
102
|
-
catch {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
77
|
+
catch { /* Record the source of the failed check without exposing upstream detail. */ }
|
|
78
|
+
const settings = await deps.settings();
|
|
79
|
+
if (!enabled(settings))
|
|
80
|
+
return status();
|
|
81
|
+
const previous = cache;
|
|
82
|
+
if (release) {
|
|
83
|
+
const order = compareVersions(release.latest, deps.current);
|
|
84
|
+
cache = { ...release, current: deps.current, enabled: true, checkedAt, updateAvailable: order === 1 };
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const checkFailure = deps.packaged ? 'npm' : 'github';
|
|
88
|
+
cache = { ...cache, checkedAt, updateAvailable: false, checkFailure };
|
|
112
89
|
if (!loggedFailure) {
|
|
113
90
|
loggedFailure = true;
|
|
114
|
-
deps.debug?.(
|
|
91
|
+
deps.debug?.(`Release check unavailable (${checkFailure}); retrying on the next scheduled check.`);
|
|
115
92
|
}
|
|
116
93
|
}
|
|
117
|
-
|
|
94
|
+
if (previous.latest !== cache.latest || previous.checkFailure !== cache.checkFailure || previous.updateAvailable !== cache.updateAvailable) {
|
|
95
|
+
deps.broadcast({ type: 'app_update_status_changed' });
|
|
96
|
+
}
|
|
97
|
+
const { latest, url, publishedAt } = cache;
|
|
98
|
+
if (cache.updateAvailable && latest && url && settings.updateCheckDismissed !== latest && !announced.has(latest)) {
|
|
99
|
+
announced.add(latest);
|
|
100
|
+
deps.broadcast({ type: 'app_update_available', current: deps.current, latest, url, publishedAt });
|
|
101
|
+
deps.log?.(`app_update_available ${latest}`);
|
|
102
|
+
}
|
|
103
|
+
return { ...cache, enabled: true };
|
|
118
104
|
}
|
|
119
105
|
function check() {
|
|
120
106
|
if (!pending)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UpdateCheckStatus } from '@arco/shared';
|
|
1
2
|
export type UpdateMode = 'service' | 'foreground' | 'docker';
|
|
2
3
|
export declare function updateMode(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): UpdateMode;
|
|
3
4
|
type Status = {
|
|
@@ -16,10 +17,7 @@ export declare function createUpdateManager(deps?: {
|
|
|
16
17
|
root?: string;
|
|
17
18
|
env?: NodeJS.ProcessEnv;
|
|
18
19
|
platform?: NodeJS.Platform;
|
|
19
|
-
check?: () => Promise<
|
|
20
|
-
latest: string | null;
|
|
21
|
-
updateAvailable: boolean;
|
|
22
|
-
}>;
|
|
20
|
+
check?: () => Promise<Pick<UpdateCheckStatus, 'latest' | 'updateAvailable' | 'checkFailure'>>;
|
|
23
21
|
launch?: (command: string, args: string[]) => {
|
|
24
22
|
status: number | null;
|
|
25
23
|
error?: Error;
|
|
@@ -72,12 +72,15 @@ export function createUpdateManager(deps = {}) {
|
|
|
72
72
|
if (previous?.outcome === 'running' && now() - (previous.startedAt ?? 0) < 30 * 60_000)
|
|
73
73
|
return { ok: false, status: 409, error: 'An update is already running.' };
|
|
74
74
|
let latest;
|
|
75
|
+
const lookupError = packaged ? 'Could not check npm for updates.' : 'Could not check GitHub for releases.';
|
|
75
76
|
try {
|
|
76
77
|
latest = await check();
|
|
77
78
|
}
|
|
78
79
|
catch {
|
|
79
|
-
return { ok: false, status: 503, error:
|
|
80
|
+
return { ok: false, status: 503, error: lookupError };
|
|
80
81
|
}
|
|
82
|
+
if (latest.checkFailure)
|
|
83
|
+
return { ok: false, status: 503, error: lookupError };
|
|
81
84
|
if (!latest.updateAvailable || !latest.latest || !/^v\d+\.\d+\.\d+$/.test(latest.latest))
|
|
82
85
|
return { ok: false, status: 409, error: 'No newer stable release is available.' };
|
|
83
86
|
if (body.expectedLatest !== latest.latest)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface ResolvedCommand {
|
|
2
2
|
command: string;
|
|
3
3
|
args: string[];
|
|
4
|
+
env?: NodeJS.ProcessEnv;
|
|
4
5
|
}
|
|
5
6
|
export interface ResolveOptions {
|
|
6
7
|
platform?: NodeJS.Platform;
|
|
@@ -8,8 +9,22 @@ export interface ResolveOptions {
|
|
|
8
9
|
nodePath?: string;
|
|
9
10
|
isFile?: (path: string) => boolean;
|
|
10
11
|
readText?: (path: string) => string;
|
|
12
|
+
fresh?: boolean;
|
|
13
|
+
registryPath?: () => string;
|
|
11
14
|
}
|
|
12
15
|
export declare function findWindowsCommand(command: string, env: NodeJS.ProcessEnv, isFile: (p: string) => boolean): string | null;
|
|
16
|
+
export declare function readRegistryPath(): string;
|
|
17
|
+
export declare function locateWindowsCommand(command: string, env: NodeJS.ProcessEnv, isFile: (p: string) => boolean, registryPath?: () => string): {
|
|
18
|
+
file: string;
|
|
19
|
+
path?: string;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare function withSinglePath(env: NodeJS.ProcessEnv, path: string): NodeJS.ProcessEnv;
|
|
22
|
+
export declare function resolveLoginCommand(line: string, opts?: ResolveOptions): {
|
|
23
|
+
line: string;
|
|
24
|
+
path?: string;
|
|
25
|
+
} | {
|
|
26
|
+
missing: string;
|
|
27
|
+
};
|
|
13
28
|
export declare function npmShimTarget(shimPath: string, text: string): string | null;
|
|
14
29
|
export declare function resolveCommand(command: string, args?: readonly string[], opts?: ResolveOptions): ResolvedCommand;
|
|
15
30
|
export declare function commandArgs(command: string, args?: readonly string[]): [string, string[]];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
3
|
import { win32 } from 'node:path';
|
|
3
4
|
const defaultIsFile = (p) => {
|
|
@@ -32,6 +33,84 @@ export function findWindowsCommand(command, env, isFile) {
|
|
|
32
33
|
}
|
|
33
34
|
return null;
|
|
34
35
|
}
|
|
36
|
+
// A service or launcher started before an install keeps the PATH it began
|
|
37
|
+
// with, while a new terminal reads the current one from the registry. This
|
|
38
|
+
// reads that current value (machine then user, as Windows joins them) and
|
|
39
|
+
// expands %NAME% references. Empty when it cannot be read.
|
|
40
|
+
// The system utility by absolute path, never found through PATH or the folder.
|
|
41
|
+
function regExe() {
|
|
42
|
+
const root = process.env.SystemRoot ?? process.env.windir ?? 'C:\\Windows';
|
|
43
|
+
return win32.join(root, 'System32', 'reg.exe');
|
|
44
|
+
}
|
|
45
|
+
let registryCache = null;
|
|
46
|
+
export function readRegistryPath() {
|
|
47
|
+
const env = process.env;
|
|
48
|
+
if (process.platform !== 'win32')
|
|
49
|
+
return '';
|
|
50
|
+
if (registryCache && Date.now() - registryCache.at < 30_000)
|
|
51
|
+
return registryCache.value;
|
|
52
|
+
const read = (key) => {
|
|
53
|
+
try {
|
|
54
|
+
const out = execFileSync(regExe(), ['query', key, '/v', 'Path'], { encoding: 'utf8', timeout: 3000, windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
55
|
+
return /^\s*Path\s+REG_(?:EXPAND_)?SZ\s+(.*)$/im.exec(out)?.[1]?.trim() ?? '';
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const joined = [read('HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment'), read('HKCU\\Environment')].filter(Boolean).join(';');
|
|
62
|
+
const value = joined.replace(/%([^%]+)%/g, (whole, name) => envValue(env, name.toUpperCase()) ?? whole);
|
|
63
|
+
registryCache = { at: Date.now(), value };
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
// findWindowsCommand on the running PATH first, then on the PATH a new
|
|
67
|
+
// terminal would have. Returns the file and the PATH that located it, so a
|
|
68
|
+
// child process can be given the same PATH.
|
|
69
|
+
export function locateWindowsCommand(command, env, isFile, registryPath) {
|
|
70
|
+
const direct = findWindowsCommand(command, env, isFile);
|
|
71
|
+
if (direct)
|
|
72
|
+
return { file: direct };
|
|
73
|
+
if (/[\\/]/.test(command) || win32.isAbsolute(command))
|
|
74
|
+
return null;
|
|
75
|
+
const fresh = registryPath?.();
|
|
76
|
+
if (!fresh)
|
|
77
|
+
return null;
|
|
78
|
+
const current = envValue(env, 'PATH') ?? '';
|
|
79
|
+
const merged = [...new Set([...fresh.split(';'), ...current.split(';')].map((d) => d.trim()).filter(Boolean))].join(';');
|
|
80
|
+
const file = findWindowsCommand(command, { ...env, PATH: merged, Path: merged }, isFile);
|
|
81
|
+
return file ? { file, path: merged } : null;
|
|
82
|
+
}
|
|
83
|
+
function freshSource(opts) {
|
|
84
|
+
if (!opts.fresh)
|
|
85
|
+
return undefined;
|
|
86
|
+
if (opts.registryPath)
|
|
87
|
+
return opts.registryPath;
|
|
88
|
+
return opts.env ? undefined : readRegistryPath;
|
|
89
|
+
}
|
|
90
|
+
// The environment with exactly one PATH variable, whatever its spelling.
|
|
91
|
+
export function withSinglePath(env, path) {
|
|
92
|
+
const key = Object.keys(env).find((k) => k.toUpperCase() === 'PATH') ?? 'PATH';
|
|
93
|
+
const out = {};
|
|
94
|
+
for (const [k, v] of Object.entries(env))
|
|
95
|
+
if (k.toUpperCase() !== 'PATH')
|
|
96
|
+
out[k] = v;
|
|
97
|
+
out[key] = path;
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
// The first word of a sign-in command line, found like a provider program is;
|
|
101
|
+
// the rest is kept. `missing` names the program when it cannot be located.
|
|
102
|
+
export function resolveLoginCommand(line, opts = {}) {
|
|
103
|
+
if ((opts.platform ?? process.platform) !== 'win32')
|
|
104
|
+
return { line };
|
|
105
|
+
const match = /^([A-Za-z0-9._-]+)(\s.*)?$/.exec(line.trim());
|
|
106
|
+
if (!match)
|
|
107
|
+
return { line };
|
|
108
|
+
const env = opts.env ?? process.env;
|
|
109
|
+
const hit = locateWindowsCommand(match[1], env, opts.isFile ?? defaultIsFile, freshSource(opts));
|
|
110
|
+
if (!hit)
|
|
111
|
+
return { missing: match[1] };
|
|
112
|
+
return { line: `"${hit.file}"${match[2] ?? ''}`, ...(hit.path ? { path: hit.path } : {}) };
|
|
113
|
+
}
|
|
35
114
|
// npm's cmd-shim writes `"%dp0%\node_modules\<pkg>\<bin>.js" %*` (older
|
|
36
115
|
// versions `"%~dp0\..."`). Returns the absolute JavaScript entry, or null when
|
|
37
116
|
// the shim does not wrap a script (for example a shim for a native binary).
|
|
@@ -50,9 +129,11 @@ export function resolveCommand(command, args = [], opts = {}) {
|
|
|
50
129
|
return { command, args: [...args] };
|
|
51
130
|
const env = opts.env ?? process.env;
|
|
52
131
|
const isFile = opts.isFile ?? defaultIsFile;
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
132
|
+
const located = locateWindowsCommand(command, env, isFile, freshSource(opts));
|
|
133
|
+
if (!located)
|
|
55
134
|
return { command, args: [...args] };
|
|
135
|
+
const found = located.file;
|
|
136
|
+
const freshEnv = located.path ? { env: withSinglePath(env, located.path) } : {};
|
|
56
137
|
const ext = win32.extname(found).toLowerCase();
|
|
57
138
|
if (ext === '.cmd' || ext === '.bat') {
|
|
58
139
|
let text = '';
|
|
@@ -62,10 +143,10 @@ export function resolveCommand(command, args = [], opts = {}) {
|
|
|
62
143
|
catch { /* unreadable shim */ }
|
|
63
144
|
const script = npmShimTarget(found, text);
|
|
64
145
|
if (script && isFile(script))
|
|
65
|
-
return { command: opts.nodePath ?? process.execPath, args: [script, ...args] };
|
|
146
|
+
return { command: opts.nodePath ?? process.execPath, args: [script, ...args], ...freshEnv };
|
|
66
147
|
return { command, args: [...args] };
|
|
67
148
|
}
|
|
68
|
-
return { command: found, args: [...args] };
|
|
149
|
+
return { command: found, args: [...args], ...freshEnv };
|
|
69
150
|
}
|
|
70
151
|
// `spawn(...commandArgs('codex', args), options)`: the resolved command and
|
|
71
152
|
// arguments as a tuple for the spawn/execFile call sites.
|