agentroam 0.2.0-preview.7 → 0.2.0-preview.70
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/README.md +61 -15
- package/bin/agentroam.mjs +10 -1
- package/bin/cli-progress.d.mts +9 -0
- package/bin/cli-progress.mjs +65 -0
- package/bin/desktop-download.mjs +69 -0
- package/bin/node-preflight.mjs +171 -0
- package/bin/node-runtime-policy.json +4 -0
- package/bin/runtime-policy.d.mts +5 -0
- package/bin/runtime-policy.mjs +37 -0
- package/dist/abort.js +25 -0
- package/dist/args.js +102 -3
- package/dist/cli.js +229 -33
- package/dist/cloudflared/bundled-asset.js +3 -2
- package/dist/cloudflared/manifest.js +2 -2
- package/dist/codex-desktop-command.js +70 -0
- package/dist/codex-desktop-force-stop.js +46 -0
- package/dist/codex-desktop-idle-guard.js +15 -0
- package/dist/codex-desktop-preflight.js +63 -0
- package/dist/codex-desktop-probe.js +152 -0
- package/dist/codex-desktop-setup.js +154 -0
- package/dist/codex-desktop-status.js +85 -0
- package/dist/codex-desktop-windows.js +122 -0
- package/dist/codex-runtime-manager.js +368 -0
- package/dist/codex-sharing.js +153 -0
- package/dist/codex-windows-backend-host.js +59 -0
- package/dist/codex-windows-backend.js +120 -0
- package/dist/desktop-authorization-prompt.js +84 -0
- package/dist/desktop-authorization.js +161 -0
- package/dist/device-pairing.js +170 -0
- package/dist/error-log.js +113 -0
- package/dist/instance-takeover.js +143 -0
- package/dist/local-desktop-url.js +8 -0
- package/dist/local-service-request.js +69 -0
- package/dist/native-runtime.js +68 -0
- package/dist/network.js +32 -3
- package/dist/node-runtime-manager.js +251 -0
- package/dist/opencode-runtime-manager.js +239 -0
- package/dist/platform-packages.js +16 -5
- package/dist/platform.js +6 -4
- package/dist/power/sleep-inhibitor.js +161 -0
- package/dist/runtime-manager.js +129 -19
- package/dist/service/launcher-cleanup.js +79 -0
- package/dist/service/macos-launch-agent.js +288 -0
- package/dist/service/runtime-state.js +43 -0
- package/dist/service/service-command.js +219 -0
- package/dist/service/service-controller.js +27 -0
- package/dist/service/service-files.js +78 -0
- package/dist/service/windows-service-host.js +59 -0
- package/dist/service/windows-task-service.js +289 -0
- package/dist/startup-lock.js +81 -0
- package/dist/tunnel/cloudflare-provider.js +4 -1
- package/dist/tunnel/public-readiness.js +76 -50
- package/dist/tunnel/relay-orchestrator.js +29 -9
- package/dist/unlock-service.js +105 -0
- package/dist/update/update-channel.js +38 -0
- package/dist/update/update-command.js +96 -0
- package/dist/update/update-install.js +34 -0
- package/dist/update/update-state.js +43 -0
- package/dist/update/update-worker.js +80 -0
- package/install/README.md +55 -0
- package/install/codex-shared-watchdog.sh +16 -0
- package/install/install-agentroam.ps1 +358 -0
- package/install/install-agentroam.sh +457 -0
- package/install/install-manifest.json +15 -0
- package/install/start-codex-desktop-shared.sh +152 -0
- package/package.json +13 -10
- package/dist/args.test.js +0 -27
- package/dist/cloudflared/bundled-asset.test.js +0 -76
- package/dist/cloudflared/installer.test.js +0 -95
- package/dist/native-runtime.test.js +0 -19
- package/dist/network.test.js +0 -20
- package/dist/pairing.js +0 -2
- package/dist/platform-packages.test.js +0 -75
- package/dist/platform.test.js +0 -3
- package/dist/port.test.js +0 -3
- package/dist/process-supervisor.test.js +0 -42
- package/dist/tunnel/cloudflare-provider.test.js +0 -33
- package/dist/tunnel/pinggy-provider.test.js +0 -40
- package/dist/tunnel/proxy-settings.test.js +0 -111
- package/dist/tunnel/public-readiness.test.js +0 -104
- package/dist/tunnel/relay-orchestrator.test.js +0 -72
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Zero-install mobile remote terminal and file console. **No desktop app, no VPN**
|
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
|
-
- **Node.js 22** (
|
|
7
|
+
- **Node.js >=22.22.0** (no upper version bound)
|
|
8
8
|
- macOS arm64 or Windows 10/11 x64
|
|
9
9
|
|
|
10
10
|
The release is assembled on macOS arm64. Windows does not need Bun, Python,
|
|
@@ -17,29 +17,30 @@ on a real Windows runner before release.
|
|
|
17
17
|
npx agentroam@preview
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Or install from
|
|
20
|
+
Or install from the release tarballs. `<version>` is per-file: platform packages
|
|
21
|
+
may each reuse an older version, so use the actual file names from `dist/cli-release`.
|
|
21
22
|
|
|
22
23
|
```bash
|
|
23
|
-
npm install ./agentroam-cloudflared-darwin-arm64
|
|
24
|
-
./agentroam-runtime-darwin-arm64
|
|
25
|
-
./agentroam-tui-darwin-arm64
|
|
26
|
-
./agentroam
|
|
24
|
+
npm install ./agentroam-cloudflared-darwin-arm64-<version>.tgz \
|
|
25
|
+
./agentroam-runtime-darwin-arm64-<version>.tgz \
|
|
26
|
+
./agentroam-tui-darwin-arm64-<version>.tgz \
|
|
27
|
+
./agentroam-<version>.tgz
|
|
27
28
|
npx agentroam
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
Windows PowerShell:
|
|
31
32
|
|
|
32
33
|
```powershell
|
|
33
|
-
npm install ./agentroam-cloudflared-win32-x64
|
|
34
|
-
./agentroam-runtime-win32-x64
|
|
35
|
-
./caoqu-agentroam-tui-win32-x64
|
|
36
|
-
./agentroam
|
|
34
|
+
npm install ./agentroam-cloudflared-win32-x64-<version>.tgz `
|
|
35
|
+
./agentroam-runtime-win32-x64-<version>.tgz `
|
|
36
|
+
./caoqu-agentroam-tui-win32-x64-<version>.tgz `
|
|
37
|
+
./agentroam-<version>.tgz
|
|
37
38
|
npx agentroam
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
On first run:
|
|
41
42
|
|
|
42
|
-
1. AgentRoam tries a bundled **Cloudflare Quick Tunnel
|
|
43
|
+
1. AgentRoam tries a bundled **Cloudflare Quick Tunnel** for up to 30 seconds, then uses **LAN access** if that attempt fails or times out.
|
|
43
44
|
2. A **QR code** prints in the terminal — scan it on your phone.
|
|
44
45
|
3. Complete **one-time pairing** (5-minute token) and create the admin account.
|
|
45
46
|
4. Use the web terminal + file tree remotely.
|
|
@@ -48,18 +49,61 @@ On first run:
|
|
|
48
49
|
|
|
49
50
|
```bash
|
|
50
51
|
agentroam # start (default)
|
|
51
|
-
agentroam doctor # check native modules
|
|
52
|
+
agentroam doctor # check native modules and install Codex if missing
|
|
52
53
|
agentroam version
|
|
53
54
|
agent-tui # start the bundled terminal Agent UI
|
|
54
55
|
```
|
|
55
56
|
|
|
57
|
+
## Install and run in the background
|
|
58
|
+
|
|
59
|
+
Run the Shell installer on macOS or the PowerShell installer on Windows
|
|
60
|
+
from the project directory AgentRoam should expose. The installer verifies or
|
|
61
|
+
installs a compatible Node and the matching CLI, registers the current-user service, starts
|
|
62
|
+
it, checks readiness, and prints the access URL. Set `AGENTROAM_ROOT` to select a
|
|
63
|
+
different root explicitly. The current directory, including the home directory, is accepted.
|
|
64
|
+
|
|
65
|
+
The installer reuses the active Node when it meets the minimum version. Otherwise
|
|
66
|
+
it checks nvm-sh on macOS and nvm-windows on Windows and uses the highest
|
|
67
|
+
compatible installed version. The service records that executable without
|
|
68
|
+
changing the user's global or active NVM version. A private Node 22.22.0 is
|
|
69
|
+
downloaded only when no compatible installed Node is available. Higher Node
|
|
70
|
+
versions are never rejected or downgraded solely because of their major version.
|
|
71
|
+
|
|
72
|
+
The service keeps running after the terminal closes, restarts after failure, and
|
|
73
|
+
starts again when the user logs in. macOS uses a user LaunchAgent; Windows uses a
|
|
74
|
+
current-user Task Scheduler task. Neither requires administrator privileges.
|
|
75
|
+
Re-running the installer automatically stops and replaces an existing
|
|
76
|
+
AgentRoam user service before starting the new version. Session data, pairing
|
|
77
|
+
state, managed runtimes, and service logs are preserved during the upgrade.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
agentroam service status
|
|
81
|
+
agentroam service start
|
|
82
|
+
agentroam service stop
|
|
83
|
+
agentroam service url
|
|
84
|
+
agentroam service logs
|
|
85
|
+
agentroam service restart
|
|
86
|
+
agentroam service uninstall
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The current phone URL is stored privately at `~/.agentroam/tunnel.url`.
|
|
90
|
+
Cloudflared keeps the same Quick Tunnel hostname while its process reconnects;
|
|
91
|
+
a full service or computer restart creates a new random hostname. Re-run the
|
|
92
|
+
installer after moving or replacing Node/npm so the service receives
|
|
93
|
+
the new absolute executable paths.
|
|
94
|
+
|
|
95
|
+
Both foreground `agentroam start` and the background service prevent idle system
|
|
96
|
+
sleep for as long as they run. The display can still dim and turn off normally.
|
|
97
|
+
Stopping AgentRoam releases the assertion. Lid close, explicit sleep,
|
|
98
|
+
hibernation, shutdown, and low-battery forced sleep remain controlled by the OS.
|
|
99
|
+
|
|
56
100
|
## Options
|
|
57
101
|
|
|
58
102
|
| Flag | Description |
|
|
59
103
|
|------|-------------|
|
|
60
104
|
| `--root <path>` | Workspace root (repeatable). Default: cwd |
|
|
61
105
|
| `--local-only` | Skip tunnel; LAN/localhost only |
|
|
62
|
-
| `--relay auto` | Cloudflare, then
|
|
106
|
+
| `--relay auto` | Cloudflare, then LAN on failure or timeout (default) |
|
|
63
107
|
| `--relay cloudflare` | Cloudflare only, then LAN |
|
|
64
108
|
| `--relay pinggy` | Pinggy only, then LAN |
|
|
65
109
|
| `--relay custom --tunnel-command "<cmd>"` | Your own tunnel command |
|
|
@@ -67,14 +111,16 @@ agent-tui # start the bundled terminal Agent UI
|
|
|
67
111
|
| `--port <n>` | Fixed local port |
|
|
68
112
|
| `--data-dir <path>` | State directory (default: `~/.agentroam`) |
|
|
69
113
|
|
|
70
|
-
The platform cloudflared binary is installed from npm after size and SHA-256 verification, so startup does not download from GitHub.
|
|
114
|
+
The platform cloudflared binary is installed from npm after size and SHA-256 verification, so startup does not download from GitHub. Automatic mode attempts Cloudflare for at most 30 seconds, including connection and public health checks. Any failure falls back directly to LAN, where the phone must be on the same local network. Pinggy is only used when explicitly selected with `--relay pinggy`; a failed explicit relay also falls back to LAN.
|
|
115
|
+
|
|
116
|
+
Startup reuses a compatible installed Codex CLI. Only when none is found does it install `@openai/codex@latest`; Codex preparation is limited to 180 seconds. Installed OpenCode is reused, and missing OpenCode is skipped without downloading. If Codex installation fails or times out, the local service still starts with an explicit warning that Codex sessions are unavailable. Run `agentroam doctor` to repair Codex, then restart the service. Remote desktop uses the bundled native runtime and still requires system authorization.
|
|
71
117
|
|
|
72
118
|
## What's included
|
|
73
119
|
|
|
74
120
|
- Next.js **standalone** web gateway + WebSocket PTY server
|
|
75
121
|
- `@agent/core` bundled runtime
|
|
76
122
|
- Optional platform **cloudflared** package (verified size + SHA-256 before execution)
|
|
77
|
-
- Optional platform **agent-tui** package (Node 22 bundle; Bun is not required)
|
|
123
|
+
- Optional platform **agent-tui** package (Node >=22.22.0 bundle; Bun is not required)
|
|
78
124
|
- **Pairing token** + secure cookies behind HTTPS tunnel
|
|
79
125
|
|
|
80
126
|
Not included: Electron desktop app, SDK, dev `.env`, session caches.
|
package/bin/agentroam.mjs
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import("
|
|
2
|
+
import("./node-preflight.mjs").then(async ({ runNodePreflight }) => {
|
|
3
|
+
const result = await runNodePreflight();
|
|
4
|
+
if (result.handled) {
|
|
5
|
+
if (result.signal) process.kill(process.pid, result.signal);
|
|
6
|
+
else process.exitCode = result.exitCode ?? 1;
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const { main } = await import("../dist/cli.js");
|
|
10
|
+
await main(process.argv.slice(2));
|
|
11
|
+
}).catch((error) => {
|
|
3
12
|
console.error(`agentroam: ${error?.message ?? error}`);
|
|
4
13
|
process.exitCode = error?.exitCode ?? 1;
|
|
5
14
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CliProgressOptions {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
environment?: NodeJS.ProcessEnv;
|
|
4
|
+
log?: (line: string) => void;
|
|
5
|
+
delayMs?: number;
|
|
6
|
+
intervalMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export function withCliProgress<T>(label: string, operation: () => T | Promise<T>, options?: CliProgressOptions): Promise<T>;
|
|
9
|
+
export function withoutCliProgress<T>(operation: () => T | Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
|
|
3
|
+
const context = new AsyncLocalStorage();
|
|
4
|
+
|
|
5
|
+
// Append complete lines to stderr so stdout (URLs, QR codes, JSON) stays usable.
|
|
6
|
+
class ProgressReporter {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
const environment = options.environment ?? process.env;
|
|
9
|
+
this.enabled = options.enabled ?? (environment.AGENTROAM_SERVICE !== '1' && environment.AGENTROAM_NO_PROGRESS !== '1');
|
|
10
|
+
this.log = options.log ?? ((line) => process.stderr.write(`${line}\n`));
|
|
11
|
+
this.delayMs = options.delayMs ?? 800;
|
|
12
|
+
this.intervalMs = options.intervalMs ?? 5000;
|
|
13
|
+
this.steps = [];
|
|
14
|
+
this.pauses = 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
begin(label) {
|
|
18
|
+
const step = { label, started: Date.now() };
|
|
19
|
+
this.steps.push(step);
|
|
20
|
+
this.schedule(this.delayMs);
|
|
21
|
+
return () => {
|
|
22
|
+
const wasActive = this.steps.at(-1) === step;
|
|
23
|
+
this.steps.splice(this.steps.indexOf(step), 1);
|
|
24
|
+
if (wasActive) this.schedule(this.delayMs);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
schedule(milliseconds) {
|
|
29
|
+
clearTimeout(this.timer);
|
|
30
|
+
if (!this.enabled || this.pauses || !this.steps.length) return;
|
|
31
|
+
this.timer = setTimeout(() => {
|
|
32
|
+
const step = this.steps.at(-1);
|
|
33
|
+
const seconds = Math.floor((Date.now() - step.started) / 1000);
|
|
34
|
+
this.log(`… ${step.label} (elapsed ${seconds}s)`);
|
|
35
|
+
this.schedule(this.intervalMs);
|
|
36
|
+
}, milliseconds);
|
|
37
|
+
this.timer.unref?.();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pause() {
|
|
41
|
+
this.pauses++;
|
|
42
|
+
clearTimeout(this.timer);
|
|
43
|
+
return () => {
|
|
44
|
+
this.pauses--;
|
|
45
|
+
this.schedule(this.delayMs);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Nested stages share one heartbeat. Timers always stop, including on failure. */
|
|
51
|
+
export async function withCliProgress(label, operation, options = {}) {
|
|
52
|
+
const reporter = context.getStore() ?? new ProgressReporter(options);
|
|
53
|
+
return context.run(reporter, async () => {
|
|
54
|
+
const finish = reporter.begin(label);
|
|
55
|
+
try { return await operation(); }
|
|
56
|
+
finally { finish(); }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Suspend every nested heartbeat while a terminal prompt owns the cursor. */
|
|
61
|
+
export async function withoutCliProgress(operation) {
|
|
62
|
+
const resume = context.getStore()?.pause();
|
|
63
|
+
try { return await operation(); }
|
|
64
|
+
finally { resume?.(); }
|
|
65
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { mkdir, mkdtemp, rename, rm } from 'node:fs/promises';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { Transform, Readable } from 'node:stream';
|
|
9
|
+
import { pipeline } from 'node:stream/promises';
|
|
10
|
+
import { execFile } from 'node:child_process';
|
|
11
|
+
import { withCliProgress } from './cli-progress.mjs';
|
|
12
|
+
|
|
13
|
+
// 桌面端安装包是构建产物(dmg / exe),进不了只放源码的仓库,只能走 Releases 资产。
|
|
14
|
+
// 资产由 `node scripts/publish-agentroam-release.mjs sync-github --commit <sha>` 上传;
|
|
15
|
+
// 仓库还没有对应版本的 release 时这里必然取不到包(CLI 本体不受影响,它走 raw 安装脚本)。
|
|
16
|
+
const RELEASE_BASE = 'https://github.com/tclxqu-cao/team-agent/releases/download';
|
|
17
|
+
|
|
18
|
+
export function desktopAsset(manifest, version, platform, arch) {
|
|
19
|
+
if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-preview\.(0|[1-9]\d*))?$/.test(version)) throw new Error('Invalid AgentRoam version');
|
|
20
|
+
const target = platform === 'darwin' && arch === 'arm64' ? 'darwin-arm64' : platform === 'win32' && arch === 'x64' ? 'windows-amd64' : null;
|
|
21
|
+
if (!target) throw new Error('Desktop download supports macOS Apple Silicon and Windows x64');
|
|
22
|
+
const asset = manifest?.installers?.desktop?.[target];
|
|
23
|
+
const expected = platform === 'darwin' ? `AgentRoam-${version}-arm64.dmg` : `AgentRoam-Setup-${version}-x64.exe`;
|
|
24
|
+
if (manifest?.schemaVersion !== 2 || manifest.version !== version || manifest.channel !== (version.includes('-preview.') ? 'preview' : 'latest') || asset?.fileName !== expected || !/^[a-f0-9]{64}$/.test(asset?.sha256 ?? '') || asset.signed !== false || (asset.size !== undefined && (!Number.isSafeInteger(asset.size) || asset.size <= 0))) {
|
|
25
|
+
throw new Error('This release has no valid desktop installer for your platform');
|
|
26
|
+
}
|
|
27
|
+
return asset;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function downloadDesktop(version, { platform = process.platform, arch = process.arch, directory = join(homedir(), 'Downloads'), fetchImpl = fetch } = {}) {
|
|
31
|
+
const launcher = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
32
|
+
if (version === launcher.version) version = launcher.optionalDependencies['agentroam-runtime-darwin-arm64'];
|
|
33
|
+
// Validate coordinates before making any request.
|
|
34
|
+
if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-preview\.(0|[1-9]\d*))?$/.test(version)) throw new Error('Invalid AgentRoam version');
|
|
35
|
+
const response = await fetchImpl(`${RELEASE_BASE}/v${version}/release-manifest.json`, { signal: AbortSignal.timeout(30_000) });
|
|
36
|
+
if (!response.ok) throw new Error(`Desktop release manifest unavailable (${response.status})`);
|
|
37
|
+
const asset = desktopAsset(await response.json(), version, platform, arch);
|
|
38
|
+
await mkdir(directory, { recursive: true });
|
|
39
|
+
// Unique directory prevents overwriting an existing installer, including concurrent downloads.
|
|
40
|
+
const staging = await mkdtemp(join(directory, 'AgentRoam-'));
|
|
41
|
+
const partial = join(staging, `${asset.fileName}.download`);
|
|
42
|
+
try {
|
|
43
|
+
const binary = await fetchImpl(`${RELEASE_BASE}/v${version}/${encodeURIComponent(asset.fileName)}`, { signal: AbortSignal.timeout(600_000) });
|
|
44
|
+
if (!binary.ok || !binary.body) throw new Error(`Desktop download failed (${binary.status})`);
|
|
45
|
+
const hash = createHash('sha256');
|
|
46
|
+
let size = 0;
|
|
47
|
+
const verifier = new Transform({ transform(chunk, _encoding, callback) { size += chunk.length; hash.update(chunk); callback(null, chunk); } });
|
|
48
|
+
await pipeline(Readable.fromWeb(binary.body), verifier, createWriteStream(partial, { flags: 'wx', mode: 0o600 }));
|
|
49
|
+
if (hash.digest('hex') !== asset.sha256 || (asset.size !== undefined && asset.size !== size)) throw new Error('Desktop installer checksum or size mismatch');
|
|
50
|
+
const destination = join(staging, asset.fileName);
|
|
51
|
+
await rename(partial, destination);
|
|
52
|
+
return destination;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
await rm(staging, { recursive: true, force: true });
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
60
|
+
try {
|
|
61
|
+
const destination = await withCliProgress('Downloading and verifying the desktop installer', () => downloadDesktop(process.argv[2]));
|
|
62
|
+
console.log(`Desktop installer downloaded: ${destination}\nOpen the installer, then follow the remote desktop authorization prompts.`);
|
|
63
|
+
if (process.platform === 'darwin') execFile('/usr/bin/open', ['-R', destination], () => undefined);
|
|
64
|
+
else if (process.platform === 'win32') execFile('explorer.exe', [`/select,${destination}`], () => undefined);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(`Desktop download failed: ${error.message}. CLI is installed and ready to use.`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { access, readdir } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { delimiter, dirname, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { MINIMUM_NODE_VERSION, compareNodeVersions, isSupportedNodeVersion, parseNodeVersion } from "./runtime-policy.mjs";
|
|
8
|
+
import { withCliProgress } from "./cli-progress.mjs";
|
|
9
|
+
|
|
10
|
+
const execFileAsync = promisify(execFile);
|
|
11
|
+
// 安装引导地址:指向仓库主分支上的安装脚本(raw 路径)。
|
|
12
|
+
// 不走 release 产物 —— 避免依赖「发布流程是否产出 asset」,用户拿到的始终是最新安装器。
|
|
13
|
+
const INSTALL_BASE_URL = "https://github.com/tclxqu-cao/team-agent/raw/main/packages/cli/install";
|
|
14
|
+
const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
15
|
+
|
|
16
|
+
export async function runNodePreflight(options = {}) {
|
|
17
|
+
const argv = options.argv ?? process.argv.slice(2);
|
|
18
|
+
const nodeVersion = options.nodeVersion ?? process.versions.node;
|
|
19
|
+
const platform = options.platform ?? process.platform;
|
|
20
|
+
const arch = options.arch ?? process.arch;
|
|
21
|
+
const launcherPath = options.launcherPath ?? fileURLToPath(new URL("./agentroam.mjs", import.meta.url));
|
|
22
|
+
const environment = options.environment ?? process.env;
|
|
23
|
+
const processHost = options.processHost ?? process;
|
|
24
|
+
const major = Number(nodeVersion.split(".")[0]);
|
|
25
|
+
|
|
26
|
+
if (isSupportedNodeVersion(nodeVersion)) return { handled: false };
|
|
27
|
+
if (environment.AGENTROAM_MANAGED_NODE) {
|
|
28
|
+
throw cliError(
|
|
29
|
+
`managed Node.js re-entry failed: expected >=${MINIMUM_NODE_VERSION}, got ${nodeVersion} (${environment.AGENTROAM_MANAGED_NODE})`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (!Number.isFinite(major) || major < 18) {
|
|
33
|
+
throw cliError(standaloneInstallerMessage(platform));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const target = detectManagedTarget(platform, arch);
|
|
37
|
+
const dataDir = parsePreflightDataDir(argv, environment, options.homeDir ?? homedir());
|
|
38
|
+
const findSystemNode = options.findSystemNode ?? defaultFindSystemNode;
|
|
39
|
+
const executable = await withCliProgress("正在查找或安装兼容的 Node.js", async () => {
|
|
40
|
+
const systemNode = await findSystemNode(environment, platform, options.currentExecutable ?? process.execPath);
|
|
41
|
+
if (systemNode) return systemNode;
|
|
42
|
+
const ensureNode = options.ensureNode ?? (async (installOptions) => {
|
|
43
|
+
const { ensureManagedNode } = await import("../dist/node-runtime-manager.js");
|
|
44
|
+
return ensureManagedNode(installOptions);
|
|
45
|
+
});
|
|
46
|
+
const resolution = await ensureNode({
|
|
47
|
+
dataDir,
|
|
48
|
+
target,
|
|
49
|
+
platform,
|
|
50
|
+
arch,
|
|
51
|
+
onProgress: options.onProgress ?? ((message) => processHost.stderr.write(`${message}\n`)),
|
|
52
|
+
});
|
|
53
|
+
return resolution.executable;
|
|
54
|
+
}, { environment, log: (line) => processHost.stderr.write(`${line}\n`) });
|
|
55
|
+
|
|
56
|
+
const spawnChild = options.spawnChild ?? defaultSpawnChild;
|
|
57
|
+
const child = spawnChild(executable, [launcherPath, ...argv], {
|
|
58
|
+
stdio: "inherit",
|
|
59
|
+
env: { ...environment, AGENTROAM_MANAGED_NODE: executable },
|
|
60
|
+
});
|
|
61
|
+
const result = await waitForChild(child, processHost);
|
|
62
|
+
return { handled: true, ...result };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function parsePreflightDataDir(argv, environment = process.env, homeDir = homedir()) {
|
|
66
|
+
const index = argv.indexOf("--data-dir");
|
|
67
|
+
if (index >= 0) {
|
|
68
|
+
const value = argv[index + 1];
|
|
69
|
+
if (!value || value.startsWith("--")) throw cliError("missing value for --data-dir");
|
|
70
|
+
return resolve(value);
|
|
71
|
+
}
|
|
72
|
+
return resolve(environment.AGENTROAM_DATA_DIR?.trim() || homeDir, environment.AGENTROAM_DATA_DIR?.trim() ? "" : ".agentroam");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function detectManagedTarget(platform, arch) {
|
|
76
|
+
if (platform === "darwin" && arch === "arm64") return "darwin-arm64";
|
|
77
|
+
if (platform === "win32" && arch === "x64") return "windows-amd64";
|
|
78
|
+
throw cliError(`managed Node.js is unsupported on ${platform}-${arch}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function defaultFindSystemNode(environment, platform, currentExecutable) {
|
|
82
|
+
const executableName = platform === "win32" ? "node.exe" : "node";
|
|
83
|
+
const pathDelimiter = platform === "win32" ? ";" : delimiter;
|
|
84
|
+
const currentDirectory = dirname(currentExecutable);
|
|
85
|
+
for (const directory of (environment.PATH ?? "").split(pathDelimiter).filter(Boolean)) {
|
|
86
|
+
if (resolve(directory) === resolve(currentDirectory)) continue;
|
|
87
|
+
const candidate = resolve(directory, executableName);
|
|
88
|
+
const version = await inspectNodeVersion(candidate);
|
|
89
|
+
if (isSupportedNodeVersion(version)) return candidate;
|
|
90
|
+
}
|
|
91
|
+
return findNvmNode(environment, platform);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function findNvmNode(environment = process.env, platform = process.platform) {
|
|
95
|
+
const windows = platform === "win32";
|
|
96
|
+
const homeDir = environment.HOME || environment.USERPROFILE || homedir();
|
|
97
|
+
const roots = windows
|
|
98
|
+
? [environment.NVM_HOME, environment.APPDATA ? resolve(environment.APPDATA, "nvm") : undefined]
|
|
99
|
+
: [environment.NVM_DIR, resolve(homeDir, ".nvm")];
|
|
100
|
+
const candidates = [];
|
|
101
|
+
for (const root of [...new Set(roots.filter(Boolean))]) {
|
|
102
|
+
const versionsRoot = windows ? root : resolve(root, "versions", "node");
|
|
103
|
+
let entries;
|
|
104
|
+
try {
|
|
105
|
+
entries = await readdir(versionsRoot, { withFileTypes: true });
|
|
106
|
+
} catch {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
if (!entry.isDirectory()) continue;
|
|
111
|
+
const candidate = resolve(versionsRoot, entry.name, windows ? "node.exe" : "bin/node");
|
|
112
|
+
const version = await inspectNodeVersion(candidate);
|
|
113
|
+
if (isSupportedNodeVersion(version)) candidates.push({ candidate, version });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
candidates.sort((left, right) => compareNodeVersions(right.version, left.version));
|
|
117
|
+
return candidates[0]?.candidate ?? null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function inspectNodeVersion(candidate) {
|
|
121
|
+
try {
|
|
122
|
+
await access(candidate);
|
|
123
|
+
const { stdout } = await execFileAsync(candidate, ["-p", "process.versions.node"], {
|
|
124
|
+
encoding: "utf8",
|
|
125
|
+
timeout: 5_000,
|
|
126
|
+
windowsHide: true,
|
|
127
|
+
});
|
|
128
|
+
const version = stdout.trim();
|
|
129
|
+
return parseNodeVersion(version) ? version : null;
|
|
130
|
+
} catch {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function defaultSpawnChild(executable, args, options) {
|
|
136
|
+
const { spawn } = await import("node:child_process");
|
|
137
|
+
return spawn(executable, args, options);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function waitForChild(childPromise, processHost) {
|
|
141
|
+
return Promise.resolve(childPromise).then((child) => new Promise((resolveChild, rejectChild) => {
|
|
142
|
+
const listeners = new Map();
|
|
143
|
+
const cleanup = () => {
|
|
144
|
+
for (const [signal, listener] of listeners) processHost.off(signal, listener);
|
|
145
|
+
};
|
|
146
|
+
for (const signal of FORWARDED_SIGNALS) {
|
|
147
|
+
const listener = () => child.kill(signal);
|
|
148
|
+
listeners.set(signal, listener);
|
|
149
|
+
processHost.on(signal, listener);
|
|
150
|
+
}
|
|
151
|
+
child.once("error", (error) => {
|
|
152
|
+
cleanup();
|
|
153
|
+
rejectChild(error);
|
|
154
|
+
});
|
|
155
|
+
child.once("exit", (exitCode, signal) => {
|
|
156
|
+
cleanup();
|
|
157
|
+
resolveChild({ exitCode, signal });
|
|
158
|
+
});
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function standaloneInstallerMessage(platform) {
|
|
163
|
+
if (platform === "win32") {
|
|
164
|
+
return `Node.js 18+ is required for automatic bootstrap. Run: irm ${INSTALL_BASE_URL}/install-agentroam.ps1 | iex`;
|
|
165
|
+
}
|
|
166
|
+
return `Node.js 18+ is required for automatic bootstrap. Run: curl -fsSL ${INSTALL_BASE_URL}/install-agentroam.sh | sh`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function cliError(message) {
|
|
170
|
+
return Object.assign(new Error(message), { exitCode: 2 });
|
|
171
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const MINIMUM_NODE_VERSION: string;
|
|
2
|
+
export function parseNodeVersion(version: unknown): number[] | null;
|
|
3
|
+
export function compareNodeVersions(left: string, right: string): number;
|
|
4
|
+
export function isSupportedNodeVersion(version: unknown, minimum?: string): boolean;
|
|
5
|
+
export function assertSupportedNodeVersion(version?: string): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
const policy = JSON.parse(readFileSync(new URL("./node-runtime-policy.json", import.meta.url), "utf8"));
|
|
4
|
+
|
|
5
|
+
export const MINIMUM_NODE_VERSION = policy.minimumNodeVersion;
|
|
6
|
+
|
|
7
|
+
export function parseNodeVersion(version) {
|
|
8
|
+
if (typeof version !== "string") return null;
|
|
9
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(version);
|
|
10
|
+
if (!match) return null;
|
|
11
|
+
const parts = match.slice(1, 4).map(Number);
|
|
12
|
+
return parts.every(Number.isSafeInteger) ? parts : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function compareNodeVersions(left, right) {
|
|
16
|
+
const leftParts = parseNodeVersion(left);
|
|
17
|
+
const rightParts = parseNodeVersion(right);
|
|
18
|
+
if (!leftParts || !rightParts) throw new Error("invalid Node.js version");
|
|
19
|
+
for (let index = 0; index < 3; index++) {
|
|
20
|
+
if (leftParts[index] !== rightParts[index]) return leftParts[index] - rightParts[index];
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isSupportedNodeVersion(version, minimum = MINIMUM_NODE_VERSION) {
|
|
26
|
+
return parseNodeVersion(version) !== null && compareNodeVersions(version, minimum) >= 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function assertSupportedNodeVersion(version = process.versions.node) {
|
|
30
|
+
if (!isSupportedNodeVersion(version)) {
|
|
31
|
+
throw Object.assign(new Error(`Node.js >=${MINIMUM_NODE_VERSION} required (current ${version})`), { exitCode: 2 });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (policy.schemaVersion !== 1 || !parseNodeVersion(MINIMUM_NODE_VERSION)) {
|
|
36
|
+
throw new Error("invalid AgentRoam Node.js runtime policy");
|
|
37
|
+
}
|
package/dist/abort.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Bound an asynchronous operation even when its implementation ignores cancellation. */
|
|
2
|
+
export async function withAbortSignal(operation, signal) {
|
|
3
|
+
signal.throwIfAborted();
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const abort = () => {
|
|
6
|
+
signal.removeEventListener("abort", abort);
|
|
7
|
+
reject(signal.reason);
|
|
8
|
+
};
|
|
9
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
10
|
+
Promise.resolve().then(() => {
|
|
11
|
+
signal.throwIfAborted();
|
|
12
|
+
return operation();
|
|
13
|
+
}).then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export async function withTimeout(operation, timeoutMs, message) {
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
const timer = setTimeout(() => controller.abort(new Error(message)), timeoutMs);
|
|
19
|
+
try {
|
|
20
|
+
return await withAbortSignal(() => operation(controller.signal), controller.signal);
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
}
|
|
25
|
+
}
|