@inneranimalmedia/agentsam-rc 0.1.0 → 0.1.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/README.md +4 -2
- package/bin/agentsam-rc +2 -2
- package/dist/apps/local-studio/agentsam.app.json +1 -0
- package/dist/src/commands/remote.js +78 -18
- package/dist/src/commands/runtime-connect.js +5 -4
- package/dist/src/commands/runtime.js +18 -15
- package/dist/src/commands/setup.js +22 -12
- package/dist/src/lib/setup/runtime.js +15 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Standalone machine pairing and remote runtime for AgentSam. This package is inde
|
|
|
5
5
|
## Start
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npx @inneranimalmedia/agentsam-rc@latest remote
|
|
8
|
+
npx @inneranimalmedia/agentsam-rc@latest remote
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
The first interactive run opens your selected AgentSam installation for account authorization, enrolls this machine, installs or starts `agentsamd`, and guides you through choosing a connection transport. The server issues the stable machine identity (`instanceId`) and connection identity (`connectionId`).
|
|
@@ -30,13 +30,15 @@ npx @inneranimalmedia/agentsam-rc@latest remote --logout
|
|
|
30
30
|
|
|
31
31
|
Set `AGENTSAM_HOME` to relocate machine and runtime state. Account sessions use the shared SDK account session location.
|
|
32
32
|
|
|
33
|
+
The executable is installed in `~/.local/bin/agentsamd` on macOS/Linux (or the explicitly selected `AGENTSAM_HOME` for isolated runtimes). Legacy installations are discovered and migrated on a managed runtime start; their original executable is retained for rollback.
|
|
34
|
+
|
|
33
35
|
## Runtime requirements
|
|
34
36
|
|
|
35
37
|
Node.js 20 or newer. If an `agentsamd` binary is not already installed, the package builds its bundled Go runtime source locally and therefore requires the Go toolchain declared in the bundled `apps/agentsam-go-worker/runtime/go.mod`.
|
|
36
38
|
|
|
37
39
|
## Source and release
|
|
38
40
|
|
|
39
|
-
The prepack step assembles the CLI, identity client, runtime protocol and daemon from their canonical repository sources. No duplicated source tree is maintained here and no SDK npm release is required. The
|
|
41
|
+
The prepack step assembles the CLI, identity client, runtime protocol and daemon from their canonical repository sources. No duplicated source tree is maintained here and no SDK npm release is required. The hosted installation is selected from the bundled canonical app manifest. To use your own deployment, add `--server https://your-agentsam.example.com`. Saved account sessions and device pairings take precedence over the packaged default.
|
|
40
42
|
|
|
41
43
|
## Runtime lanes
|
|
42
44
|
|
package/bin/agentsam-rc
CHANGED
|
@@ -9,7 +9,7 @@ if (command === '--version' || command === '-v') {
|
|
|
9
9
|
process.stdout.write(`${version}\n`);
|
|
10
10
|
} else if (command === 'remote') {
|
|
11
11
|
try {
|
|
12
|
-
const code = await runRemote(args.length && (args[0] === '--logout' || args[0] === '--help' || !args[0].startsWith('-')) ? args : ['start', ...args]);
|
|
12
|
+
const code = await runRemote(args.length && (args[0] === '--logout' || args[0] === '--help' || !args[0].startsWith('-')) ? args : ['start', ...args], { consumerRemote: true });
|
|
13
13
|
process.exitCode = Number.isInteger(code) ? code : 0;
|
|
14
14
|
} catch (error) {
|
|
15
15
|
process.stderr.write(`AgentSam Remote Control: ${error?.message || String(error)}\n`);
|
|
@@ -20,7 +20,7 @@ if (command === '--version' || command === '-v') {
|
|
|
20
20
|
'',
|
|
21
21
|
'AgentSam Remote Control',
|
|
22
22
|
'',
|
|
23
|
-
' npx @inneranimalmedia/agentsam-rc@latest remote
|
|
23
|
+
' npx @inneranimalmedia/agentsam-rc@latest remote',
|
|
24
24
|
' npx @inneranimalmedia/agentsam-rc@latest remote status',
|
|
25
25
|
' npx @inneranimalmedia/agentsam-rc@latest remote --logout',
|
|
26
26
|
'',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"local-studio","hosts":[{"host_id":"local-studio-production","origin":"https://agentsam.inneranimalmedia.com","role":"production"}]}
|
|
@@ -10,7 +10,7 @@ import os from 'node:os';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import { execFile } from 'node:child_process';
|
|
12
12
|
import { promisify } from 'node:util';
|
|
13
|
-
import { confirm, isCancel, text } from '@clack/prompts';
|
|
13
|
+
import { confirm, isCancel, select, text } from '@clack/prompts';
|
|
14
14
|
import { runSetupRuntime } from './setup.js';
|
|
15
15
|
import { runRuntime, probeAgentsamd } from './runtime.js';
|
|
16
16
|
import { runConnect, runDisconnect } from './runtime-connect.js';
|
|
@@ -256,17 +256,52 @@ async function remoteSnapshot({ home, env, fetchImpl, authorityLoader, root, rea
|
|
|
256
256
|
async function ensureRemoteAccountAuthority({ options, env, home, hostOrigin, interactive, write }) {
|
|
257
257
|
if (!hostOrigin) throw new Error('local_studio_host_required: use --server to select your AgentSam installation');
|
|
258
258
|
const load = options.authorityLoader || resolveAccountAuthority;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
259
|
+
const sessionOnly = Boolean(options.consumerRemote);
|
|
260
|
+
const args = { env, home, fetchImpl: options.fetchImpl, browserSessionOnly: sessionOnly };
|
|
261
|
+
const valid = (auth) => auth?.value && (!sessionOnly || auth.kind === 'agentsam_local_studio_session') && (!auth.session?.host_origin || new URL(auth.session.host_origin).origin === new URL(hostOrigin).origin);
|
|
262
|
+
async function verify(auth) {
|
|
263
|
+
if (!valid(auth)) return null;
|
|
264
|
+
if (!options.consumerRemote) return auth;
|
|
265
|
+
try {
|
|
266
|
+
const request = options.studioRequestImpl || studioRequest;
|
|
267
|
+
const result = await request('/api/sdk/context', { env, home, hostOrigin, authorityMode: 'account', authorityLoader: async () => auth, fetchImpl: options.fetchImpl });
|
|
268
|
+
if (!result?.account_id || result.authenticated !== true) throw new Error('AgentSam did not confirm your account.');
|
|
269
|
+
return { ...auth, account: result.account };
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (error.status === 401 || error.status === 403) return null;
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
let authority = await verify(await load(args));
|
|
276
|
+
if (authority) return authority;
|
|
277
|
+
if (!interactive) throw new Error('Sign in to AgentSam on this computer first.');
|
|
278
|
+
let loginProvider = 'google';
|
|
279
|
+
if (options.consumerRemote) {
|
|
280
|
+
loginProvider = await (options.selectFn || select)({ message: 'Sign in to AgentSam', options: [{ value: 'google', label: 'Continue with Google' }, { value: 'github', label: 'Continue with GitHub' }] });
|
|
281
|
+
if (isCancel(loginProvider)) return null;
|
|
282
|
+
}
|
|
283
|
+
line(write, 'Opening your browser to sign in…');
|
|
263
284
|
const authenticate = options.authenticateViaLocalStudioImpl || authenticateViaLocalStudio;
|
|
264
|
-
await authenticate({ env, home, studioHost: hostOrigin, loginProvider
|
|
265
|
-
authority = await load(
|
|
266
|
-
if (!authority
|
|
285
|
+
await authenticate({ env, home, studioHost: hostOrigin, loginProvider, input: options.input, output: options.output, openImpl: options.openImpl, promptToOpenUrlImpl: options.promptToOpenUrlImpl, fetchImpl: options.fetchImpl });
|
|
286
|
+
authority = await verify(await load(args));
|
|
287
|
+
if (!authority) throw new Error('AgentSam could not verify your sign-in.');
|
|
267
288
|
return authority;
|
|
268
289
|
}
|
|
269
290
|
|
|
291
|
+
function normalizedMachineName(value) {
|
|
292
|
+
return String(value || '').trim().toLowerCase().replace(/\.local$/, '');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Use the account-owned machine registry; never infer device ownership from a workspace.
|
|
296
|
+
// Prefer the existing reported hostname over an unverified provisioning record.
|
|
297
|
+
export function matchingRemoteMachines(machines, hostname, substrate = 'host') {
|
|
298
|
+
const target = normalizedMachineName(hostname);
|
|
299
|
+
if (!target) return [];
|
|
300
|
+
const candidates = (machines || []).filter(machine => machine.substrate === substrate && isDeviceInstanceId(machine.instanceId || machine.instance_id));
|
|
301
|
+
const exact = candidates.filter(machine => normalizedMachineName(machine.hostname) === target);
|
|
302
|
+
return exact.length ? exact : candidates.filter(machine => !machine.hostname && normalizedMachineName(machine.name) === target);
|
|
303
|
+
}
|
|
304
|
+
|
|
270
305
|
export async function runRemote(argv = [], options = {}) {
|
|
271
306
|
const write = options.write || ((value) => process.stdout.write(value));
|
|
272
307
|
const env = options.env || process.env;
|
|
@@ -287,6 +322,13 @@ export async function runRemote(argv = [], options = {}) {
|
|
|
287
322
|
if (command === 'help') {
|
|
288
323
|
line(write, 'AgentSam Remote Control');
|
|
289
324
|
line(write, '');
|
|
325
|
+
if (options.consumerRemote) {
|
|
326
|
+
line(write, ' npx @inneranimalmedia/agentsam-rc@latest remote');
|
|
327
|
+
line(write, ' agentsam-rc remote status | doctor | stop | --logout');
|
|
328
|
+
line(write, ' Optional: --server <your AgentSam installation>');
|
|
329
|
+
line(write, ' Connect to your account, pair your computer, then choose how to reach it.');
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
290
332
|
line(write, ' agentsam remote start [--via cloudflare|tailscale|ngrok|ssh|url] [--local-only]');
|
|
291
333
|
line(write, ' agentsam remote status [--json]');
|
|
292
334
|
line(write, ' agentsam remote doctor [--json]');
|
|
@@ -303,11 +345,12 @@ export async function runRemote(argv = [], options = {}) {
|
|
|
303
345
|
const config = await readConfig(home, env);
|
|
304
346
|
if (!config?.connectionId) { line(write, 'This machine is not paired.'); return 0; }
|
|
305
347
|
const hostOrigin = config.server;
|
|
306
|
-
await ensureRemoteAccountAuthority({ options, env, home, hostOrigin, interactive, write });
|
|
348
|
+
const authority = await ensureRemoteAccountAuthority({ options, env, home, hostOrigin, interactive, write });
|
|
349
|
+
if (!authority) return 0;
|
|
307
350
|
try {
|
|
308
351
|
await requestStudio(`/api/machines/${encodeURIComponent(config.connectionId)}/revoke`, {
|
|
309
352
|
method: 'POST', body: {}, env, home, hostOrigin, authorityMode: 'account',
|
|
310
|
-
authorityLoader: options.authorityLoader, fetchImpl: options.fetchImpl, root: options.root,
|
|
353
|
+
authorityLoader: options.consumerRemote ? async () => authority : options.authorityLoader, fetchImpl: options.fetchImpl, root: options.root,
|
|
311
354
|
});
|
|
312
355
|
} catch (error) { line(write, `Could not revoke this machine: ${error.message}. Local credentials retained.`); return 2; }
|
|
313
356
|
if (config.instanceId) writeDeviceIdentity({ instanceId: config.instanceId, hostOrigin }, home, env);
|
|
@@ -337,7 +380,7 @@ export async function runRemote(argv = [], options = {}) {
|
|
|
337
380
|
const showBoot = interactive && !flags.json;
|
|
338
381
|
if (showBoot) write(renderRemoteBoot({ columns: options.columns || process.stdout.columns || 80, color: remoteBootColor(env) }));
|
|
339
382
|
|
|
340
|
-
if (!flags.yes) {
|
|
383
|
+
if (!flags.yes && !options.consumerRemote) {
|
|
341
384
|
const planCode = await runSetup([...setupArgs(flags, false), '--dry-run'], { ...options, write, env, home });
|
|
342
385
|
if (planCode !== 0) return planCode;
|
|
343
386
|
const approve = options.confirmFn || confirm;
|
|
@@ -360,18 +403,35 @@ export async function runRemote(argv = [], options = {}) {
|
|
|
360
403
|
if (!selectedHost) throw new Error('local_studio_host_required: use --server');
|
|
361
404
|
const hostOrigin = normalizeServer(selectedHost);
|
|
362
405
|
if (config?.server && new URL(config.server).origin !== new URL(hostOrigin).origin) throw new Error('machine_already_paired_to_different_installation');
|
|
363
|
-
if (showBoot) line(write, ` ◇
|
|
364
|
-
await ensureRemoteAccountAuthority({ options, env, home, hostOrigin, interactive, write });
|
|
365
|
-
if (
|
|
406
|
+
if (showBoot) line(write, ` ◇ AgentSam ${hostOrigin}`);
|
|
407
|
+
const authority = await ensureRemoteAccountAuthority({ options, env, home, hostOrigin, interactive, write });
|
|
408
|
+
if (!authority) return 0;
|
|
409
|
+
if (showBoot) line(write, ` ✓ Signed in${authority.account?.display_name ? ' — ' + String(authority.account.display_name).replace(/[\x00-\x1f\x7f]/g, '') : ''}`);
|
|
366
410
|
const saved = readDeviceIdentity(home, env);
|
|
367
|
-
|
|
368
|
-
const
|
|
411
|
+
let instanceId = flags.instanceId || (config?.server === hostOrigin ? config.instanceId : saved?.hostOrigin === hostOrigin ? saved.instanceId : '');
|
|
412
|
+
const sessionOptions = options.consumerRemote ? { ...options, authorityLoader: async () => authority } : options;
|
|
413
|
+
if (options.consumerRemote && !instanceId) {
|
|
414
|
+
const list = await requestStudio('/api/machines', { env, home, hostOrigin, authorityMode: 'account', authorityLoader: async () => authority, fetchImpl: options.fetchImpl });
|
|
415
|
+
const candidates = matchingRemoteMachines(list?.machines, options.hostname || os.hostname(), flags.substrate);
|
|
416
|
+
if (candidates.length && interactive) {
|
|
417
|
+
const selected = await (options.selectFn || select)({ message: 'Connect this computer', options: [...candidates.map(machine => ({ value: machine.instanceId || machine.instance_id, label: String(machine.name || machine.hostname).replace(/[\x00-\x1f\x7f]/g, ''), hint: 'Existing device' })), { value: 'new', label: 'Add as a new device' }] });
|
|
418
|
+
if (isCancel(selected)) return 0;
|
|
419
|
+
if (selected !== 'new') instanceId = selected;
|
|
420
|
+
} else if (candidates.length === 1 && flags.yes) instanceId = candidates[0].instanceId || candidates[0].instance_id;
|
|
421
|
+
else if (candidates.length > 1) throw new Error('Multiple matching devices. Select your device interactively.');
|
|
422
|
+
}
|
|
423
|
+
if (options.consumerRemote && !flags.yes) {
|
|
424
|
+
const approved = await (options.confirmFn || confirm)({ message: `Allow AgentSam to connect to ${options.hostname || os.hostname()}?`, initialValue: false });
|
|
425
|
+
if (isCancel(approved) || approved !== true) { line(write, 'Cancelled. This computer was not paired.'); return 0; }
|
|
426
|
+
}
|
|
427
|
+
if (showBoot) line(write, ' ◇ Preparing this computer…');
|
|
428
|
+
const setupCode = await runSetup(setupArgs({ ...flags, server: hostOrigin }, true, instanceId), { ...sessionOptions, write, env, home });
|
|
369
429
|
if (setupCode !== 0) return setupCode;
|
|
370
|
-
if (showBoot) line(write, '
|
|
430
|
+
if (showBoot) line(write, ' ◇ Connecting your device…');
|
|
371
431
|
|
|
372
432
|
const args = connectArgs(flags);
|
|
373
433
|
const connectCode = await runConnectImpl(args, {
|
|
374
|
-
...
|
|
434
|
+
...sessionOptions, write, env, home, interactive,
|
|
375
435
|
managedTunnelStatePath: statePath,
|
|
376
436
|
});
|
|
377
437
|
return connectCode || 0;
|
|
@@ -59,13 +59,14 @@ export async function runConnect(args = [], options = {}) {
|
|
|
59
59
|
const interactive = options.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
60
60
|
const prompts = { text, select, confirm, ...(options.prompts || {}) };
|
|
61
61
|
const ctx = { home: options.home, fetch: options.fetch, env };
|
|
62
|
-
if (interactive && !flags.json) intro('Connect this runtime to AgentSam');
|
|
62
|
+
if (interactive && !flags.json && !options.consumerRemote) intro('Connect this runtime to AgentSam');
|
|
63
63
|
|
|
64
64
|
// 1. Pair (skip when already paired and no new code given).
|
|
65
65
|
let cfg = readMachineConfig(ctx.home, env);
|
|
66
66
|
if (cfg && !flags.code) {
|
|
67
|
-
line(write, ` Already connected to ${cfg.server}. (Use --code to connect to a different AgentSam host.)`);
|
|
67
|
+
if (!options.consumerRemote) line(write, ` Already connected to ${cfg.server}. (Use --code to connect to a different AgentSam host.)`);
|
|
68
68
|
} else {
|
|
69
|
+
if (options.consumerRemote && !flags.code) { line(write, ' Pairing was not saved. Run AgentSam Remote again.'); return 2; }
|
|
69
70
|
let server = flags.server || cfg?.server || env.AGENTSAM_SERVER;
|
|
70
71
|
let code = flags.code;
|
|
71
72
|
if (!server) {
|
|
@@ -106,7 +107,7 @@ export async function runConnect(args = [], options = {}) {
|
|
|
106
107
|
}
|
|
107
108
|
via = via || 'local';
|
|
108
109
|
|
|
109
|
-
let outcome = '
|
|
110
|
+
let outcome = 'Device paired. Remote access is not enabled.';
|
|
110
111
|
if (via === 'url') {
|
|
111
112
|
let address = flags.address;
|
|
112
113
|
if (!address && interactive) address = await ask(prompts.text, { message: 'The https address that reaches this machine', placeholder: 'https://my-machine.example.com' });
|
|
@@ -133,7 +134,7 @@ export async function runConnect(args = [], options = {}) {
|
|
|
133
134
|
|
|
134
135
|
line(write, ` ✓ ${outcome}`);
|
|
135
136
|
line(write, ' Manage it in AgentSam: Settings → Machines & Runtimes.');
|
|
136
|
-
if (interactive && !flags.json) outro('
|
|
137
|
+
if (interactive && !flags.json) outro(via === 'local' ? 'Paired · local access only' : 'Device endpoint registered');
|
|
137
138
|
return 0;
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -10,6 +10,7 @@ import { promisify } from 'node:util';
|
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import {
|
|
12
12
|
discoverRuntimeFacts,
|
|
13
|
+
preferredAgentsamdPath, installedAgentsamdPath, legacyAgentsamdPath,
|
|
13
14
|
agentsamHomeDir,
|
|
14
15
|
ensureRuntimeStateDir,
|
|
15
16
|
runtimeStateDir,
|
|
@@ -63,14 +64,6 @@ function printHelp(write) {
|
|
|
63
64
|
writeLine(write, '');
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
function binDir(home = os.homedir()) {
|
|
67
|
-
return path.join(agentsamHomeDir(home), 'bin');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function agentsamdPath(home = os.homedir()) {
|
|
71
|
-
return path.join(binDir(home), process.platform === 'win32' ? 'agentsamd.exe' : 'agentsamd');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
67
|
function pidPath(home = os.homedir()) {
|
|
75
68
|
return path.join(runtimeStateDir(home), 'agentsamd.pid');
|
|
76
69
|
}
|
|
@@ -83,16 +76,16 @@ function darwinPlistPath(home) {
|
|
|
83
76
|
return path.join(home, 'Library', 'LaunchAgents', `${DARWIN_LAUNCH_LABEL}.plist`);
|
|
84
77
|
}
|
|
85
78
|
|
|
86
|
-
async function buildAgentsamd(write) {
|
|
79
|
+
async function buildAgentsamd(write, home, env) {
|
|
87
80
|
if (!fs.existsSync(path.join(AGENTSAMD_MAIN, 'main.go'))) {
|
|
88
81
|
throw new Error(`agentsamd source missing at ${AGENTSAMD_MAIN}`);
|
|
89
82
|
}
|
|
90
|
-
const out =
|
|
83
|
+
const out = preferredAgentsamdPath(home, env);
|
|
91
84
|
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
92
85
|
writeLine(write, ` Building agentsamd → ${out}`);
|
|
93
86
|
await execFileAsync('go', ['build', '-o', out, './cmd/agentsamd'], {
|
|
94
87
|
cwd: GO_RUNTIME_ROOT,
|
|
95
|
-
env: { ...
|
|
88
|
+
env: { ...env, CGO_ENABLED: '0' },
|
|
96
89
|
timeout: 120000,
|
|
97
90
|
});
|
|
98
91
|
try { fs.chmodSync(out, 0o755); } catch { /* ignore */ }
|
|
@@ -121,9 +114,19 @@ async function waitForAgentsamd({ attempts = 8, delayMs = 250, env = process.env
|
|
|
121
114
|
}
|
|
122
115
|
|
|
123
116
|
async function startAgentsamd(home, write, env = process.env) {
|
|
124
|
-
|
|
125
|
-
if (!
|
|
117
|
+
let bin = installedAgentsamdPath(home, env);
|
|
118
|
+
if (!bin) throw new Error('agentsamd_not_installed');
|
|
126
119
|
|
|
120
|
+
const preferred = preferredAgentsamdPath(home, env);
|
|
121
|
+
// Move the executable location only on a requested start, not during discovery.
|
|
122
|
+
// Retain the original binary for rollback and never overwrite another install.
|
|
123
|
+
if (bin === legacyAgentsamdPath(home, env) && bin !== preferred && !fs.existsSync(preferred)) {
|
|
124
|
+
fs.mkdirSync(path.dirname(preferred), { recursive: true });
|
|
125
|
+
fs.copyFileSync(bin, preferred, fs.constants.COPYFILE_EXCL);
|
|
126
|
+
fs.chmodSync(preferred, 0o755);
|
|
127
|
+
bin = preferred;
|
|
128
|
+
if (process.platform === 'darwin') writeLaunchAgent(home, bin, listenAddr(env));
|
|
129
|
+
}
|
|
127
130
|
if (process.platform === 'win32') {
|
|
128
131
|
try {
|
|
129
132
|
await startWindowsScheduledTask();
|
|
@@ -307,7 +310,7 @@ export async function runRuntime(argv = [], options = {}) {
|
|
|
307
310
|
|
|
308
311
|
if (sub === 'install') {
|
|
309
312
|
if (!yes && process.stdin.isTTY) {
|
|
310
|
-
writeLine(write, ' Pass --yes to build and install agentsamd into
|
|
313
|
+
writeLine(write, ' Pass --yes to build and install agentsamd into the user executable directory');
|
|
311
314
|
}
|
|
312
315
|
if (!yes && !process.stdin.isTTY) {
|
|
313
316
|
writeLine(write, ' Non-interactive: pass --yes');
|
|
@@ -319,7 +322,7 @@ export async function runRuntime(argv = [], options = {}) {
|
|
|
319
322
|
}
|
|
320
323
|
let binary;
|
|
321
324
|
try {
|
|
322
|
-
binary = await buildAgentsamd(write);
|
|
325
|
+
binary = await buildAgentsamd(write, home, env);
|
|
323
326
|
} catch (err) {
|
|
324
327
|
writeLine(write, ` ✕ build failed: ${err.message || err}`);
|
|
325
328
|
return 2;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import readline from 'node:readline/promises';
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import os from 'node:os';
|
|
7
|
-
import path from 'node:path';
|
|
8
7
|
import { stdin as input, stdout as output } from 'node:process';
|
|
9
8
|
import { discoverEnvironment, renderEnvironment } from '../lib/setup/discover.js';
|
|
10
9
|
import { buildSetupPlan, renderSetupPlan } from '../lib/setup/planner.js';
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
writeRuntimeInstallReceipt,
|
|
21
20
|
RUNTIME_PROFILES,
|
|
22
21
|
RUNTIME_PROFILE_ALIASES,
|
|
23
|
-
|
|
22
|
+
preferredAgentsamdPath, installedAgentsamdPath,
|
|
24
23
|
} from '../lib/setup/runtime.js';
|
|
25
24
|
import { readMachineConfig, pairThisMachine, findMachineConnection } from '../lib/machine-connection.js';
|
|
26
25
|
import { readAccountSession } from '../lib/account-session.js';
|
|
@@ -194,15 +193,18 @@ export async function runSetupRuntime(argv = [], options = {}) {
|
|
|
194
193
|
substrate: parsed.substrate,
|
|
195
194
|
});
|
|
196
195
|
const planPath = writePlanReceipt(plan, home);
|
|
197
|
-
write(renderRuntimePlan(plan));
|
|
196
|
+
if (!options.consumerRemote) write(renderRuntimePlan(plan));
|
|
197
|
+
else if (parsed.dryRun) writeLine(write, ` ${plan.recommended?.eligible ? "✓ This computer is ready for pairing." : "✕ Machine runtime prerequisites are missing."}`);
|
|
198
198
|
|
|
199
199
|
if (parsed.json && (parsed.dryRun || !parsed.yes)) {
|
|
200
200
|
write(`${JSON.stringify({ plan, plan_receipt: planPath, executed: false }, null, 2)}\n`);
|
|
201
201
|
return plan.recommended?.eligible ? 0 : 2;
|
|
202
202
|
}
|
|
203
203
|
if (parsed.dryRun || !parsed.yes) {
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
if (!options.consumerRemote) {
|
|
205
|
+
writeLine(write, ` Plan receipt ${planPath}`);
|
|
206
|
+
writeLine(write, ' Pass --yes to register and pair this runtime with the selected AgentSam account.');
|
|
207
|
+
}
|
|
206
208
|
writeLine(write, '');
|
|
207
209
|
return 0;
|
|
208
210
|
}
|
|
@@ -292,9 +294,9 @@ export async function runSetupRuntime(argv = [], options = {}) {
|
|
|
292
294
|
machineConfig = await readConfig(home, env);
|
|
293
295
|
}
|
|
294
296
|
|
|
295
|
-
const binaryPath =
|
|
297
|
+
const binaryPath = preferredAgentsamdPath(home, env);
|
|
296
298
|
if (!localProbe.ok) {
|
|
297
|
-
if (
|
|
299
|
+
if (installedAgentsamdPath(home, env) || plan.facts.agentsamd.installed) {
|
|
298
300
|
let code = await runRuntimeImpl(['start'], { home, env, write: () => {} });
|
|
299
301
|
if (code !== 0) code = await runRuntimeImpl(['install', '--yes'], { home, env, write });
|
|
300
302
|
serviceResult = { status: code === 0 ? 'started_or_repaired' : 'failed', code };
|
|
@@ -316,7 +318,7 @@ export async function runSetupRuntime(argv = [], options = {}) {
|
|
|
316
318
|
|
|
317
319
|
const machine = sanitizeMachine(machineRecord);
|
|
318
320
|
const remoteAccessReady = Boolean(machine.isActive && machine.endpointUrl);
|
|
319
|
-
const binaryReady =
|
|
321
|
+
const binaryReady = installedAgentsamdPath(home, env) || plan.facts.agentsamd.installed || ['installed_and_started', 'started_or_repaired', 'reused_running'].includes(serviceResult.status);
|
|
320
322
|
const actionSteps = [
|
|
321
323
|
{ action_id: 'ensure_agentsamd_binary', status: binaryReady ? 'completed' : 'failed', evidence: binaryPath },
|
|
322
324
|
{ action_id: 'create_instance_record', status: created ? 'created' : 'reused', evidence: machine.instanceId },
|
|
@@ -355,6 +357,10 @@ export async function runSetupRuntime(argv = [], options = {}) {
|
|
|
355
357
|
plan_receipt: planPath,
|
|
356
358
|
}, home);
|
|
357
359
|
|
|
360
|
+
if (options.consumerRemote) {
|
|
361
|
+
writeLine(write, ` ✓ Device paired: ${machine.name || os.hostname()}`);
|
|
362
|
+
writeLine(write, localProbe.ok ? ' ✓ Machine runtime ready' : ' ✕ Machine runtime is not responding');
|
|
363
|
+
} else {
|
|
358
364
|
writeLine(write, ` ✓ Account machine ${machine.instanceId}`);
|
|
359
365
|
writeLine(write, ` ✓ Connection ${machine.connectionId}`);
|
|
360
366
|
writeLine(write, ` ✓ Runtime ${localProbe.ok ? 'healthy' : 'not healthy'}`);
|
|
@@ -368,6 +374,8 @@ export async function runSetupRuntime(argv = [], options = {}) {
|
|
|
368
374
|
writeLine(write, ` ✓ Setup receipt ${receiptPath}`);
|
|
369
375
|
writeLine(write, '');
|
|
370
376
|
|
|
377
|
+
}
|
|
378
|
+
|
|
371
379
|
if (parsed.json) write(`${JSON.stringify({ plan, plan_receipt: planPath, install_receipt: receiptPath, machine, remote_access: remoteAccess, goap_execution: goapExecution, local_health_probe: localProbe }, null, 2)}\n`);
|
|
372
380
|
return pendingActionIds.length ? 2 : 0;
|
|
373
381
|
} catch (error) {
|
|
@@ -389,10 +397,12 @@ export async function runSetupRuntime(argv = [], options = {}) {
|
|
|
389
397
|
machine: { instanceId: created.instanceId, connectionId: created.connectionId, status: 'pending_pairing' },
|
|
390
398
|
plan_receipt: planPath,
|
|
391
399
|
}, home);
|
|
392
|
-
writeLine(write, ` ✕ Runtime setup incomplete: ${error?.message || error}`);
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
400
|
+
writeLine(write, ` ✕ ${options.consumerRemote ? "Device connection incomplete" : "Runtime setup incomplete"}: ${error?.message || error}`);
|
|
401
|
+
if (!options.consumerRemote) {
|
|
402
|
+
writeLine(write, ` Pairing record ${created.connectionId}`);
|
|
403
|
+
writeLine(write, ` Retry pairing agentsam rc machines rotate --connection ${created.connectionId}`);
|
|
404
|
+
writeLine(write, ` Partial receipt ${receiptPath}`);
|
|
405
|
+
} else writeLine(write, " Run AgentSam Remote again to retry the connection.");
|
|
396
406
|
writeLine(write, '');
|
|
397
407
|
if (parsed.json) write(`${JSON.stringify({ ok: false, error: String(error?.message || error), plan_receipt: planPath, install_receipt: receiptPath, connection_id: created.connectionId }, null, 2)}\n`);
|
|
398
408
|
return 2;
|
|
@@ -47,6 +47,20 @@ export function agentsamHomeDir(home = os.homedir(), env = process.env) {
|
|
|
47
47
|
return override ? path.resolve(override) : path.join(home, '.agentsam');
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
export function preferredAgentsamdPath(home = os.homedir(), env = process.env, platform = process.platform) {
|
|
51
|
+
const executable = platform === 'win32' ? 'agentsamd.exe' : 'agentsamd';
|
|
52
|
+
const bin = env.AGENTSAM_HOME || platform === 'win32' ? path.join(agentsamHomeDir(home, env), 'bin') : path.join(home, '.local', 'bin');
|
|
53
|
+
return path.join(bin, executable);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function legacyAgentsamdPath(home = os.homedir(), env = process.env, platform = process.platform) {
|
|
57
|
+
return path.join(agentsamHomeDir(home, env), 'bin', platform === 'win32' ? 'agentsamd.exe' : 'agentsamd');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function installedAgentsamdPath(home = os.homedir(), env = process.env) {
|
|
61
|
+
return [preferredAgentsamdPath(home, env), legacyAgentsamdPath(home, env)].find(file => fs.existsSync(file)) || null;
|
|
62
|
+
}
|
|
63
|
+
|
|
50
64
|
export function runtimeStateDir(home = os.homedir(), env = process.env) {
|
|
51
65
|
return path.join(agentsamHomeDir(home, env), 'runtime');
|
|
52
66
|
}
|
|
@@ -83,11 +97,7 @@ export async function discoverRuntimeFacts(options = {}) {
|
|
|
83
97
|
prior = null;
|
|
84
98
|
}
|
|
85
99
|
|
|
86
|
-
const agentsamdBin =
|
|
87
|
-
(await whichBinary('agentsamd')) ||
|
|
88
|
-
(fs.existsSync(path.join(agentsamHomeDir(home, options.env || process.env), 'bin', 'agentsamd'))
|
|
89
|
-
? path.join(agentsamHomeDir(home, options.env || process.env), 'bin', 'agentsamd')
|
|
90
|
-
: null);
|
|
100
|
+
const agentsamdBin = installedAgentsamdPath(home, options.env || process.env) || await whichBinary('agentsamd');
|
|
91
101
|
|
|
92
102
|
return {
|
|
93
103
|
schema: RUNTIME_SETUP_SCHEMA,
|