@agentage/cli 0.53.0 → 0.55.0
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 +9 -11
- package/dist/commands/daemon/daemon.d.ts +3 -3
- package/dist/commands/daemon/daemon.js +21 -8
- package/dist/commands/daemon/installer.js +4 -7
- package/dist/commands/extension/build.js +5 -3
- package/dist/commands/extension/configure.js +2 -1
- package/dist/commands/extension/create-install.js +3 -2
- package/dist/commands/extension/install-once.d.ts +2 -0
- package/dist/commands/extension/install-once.js +5 -5
- package/dist/commands/extension/kit-tool.d.ts +1 -1
- package/dist/commands/extension/lifecycle.d.ts +0 -2
- package/dist/commands/extension/lifecycle.js +4 -4
- package/dist/commands/extension/package-build.d.ts +10 -0
- package/dist/commands/extension/package-build.js +28 -9
- package/dist/commands/extension/release-guard.d.ts +8 -1
- package/dist/commands/extension/release-guard.js +39 -16
- package/dist/commands/extension/release.js +35 -19
- package/dist/commands/extension/setup-install.js +2 -4
- package/dist/commands/extension/up-app.d.ts +9 -0
- package/dist/commands/extension/up-app.js +59 -0
- package/dist/commands/extension/up-build.d.ts +0 -1
- package/dist/commands/extension/up-build.js +3 -9
- package/dist/commands/extension/up-local.d.ts +3 -0
- package/dist/commands/extension/up-local.js +30 -11
- package/dist/commands/extension/up-reload.d.ts +9 -1
- package/dist/commands/extension/up-reload.js +58 -17
- package/dist/commands/extension/up-run.d.ts +2 -0
- package/dist/commands/extension/up-run.js +80 -38
- package/dist/commands/extension/up-watch.d.ts +2 -2
- package/dist/commands/extension/up-watch.js +21 -11
- package/dist/commands/extension/up.js +6 -4
- package/dist/commands/status/status-daemon.d.ts +12 -0
- package/dist/commands/status/status-daemon.js +22 -0
- package/dist/commands/status/status.d.ts +2 -0
- package/dist/commands/status/status.js +18 -4
- package/dist/core/loader/manifest.js +1 -2
- package/dist/lib/daemon/daemon-client.js +3 -6
- package/dist/lib/daemon/daemon-probe.d.ts +1 -0
- package/dist/lib/daemon/daemon-probe.js +7 -2
- package/dist/lib/daemon/host-client.d.ts +8 -5
- package/dist/lib/daemon/host-client.js +19 -16
- package/dist/lib/fs/file-lock.js +6 -0
- package/dist/lib/proc/start-time.d.ts +2 -2
- package/dist/lib/proc/start-time.js +12 -10
- package/package.json +7 -3
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
2
|
import { join, resolve } from 'node:path';
|
|
3
3
|
import { ensureDaemon } from '../../lib/daemon/daemon-client.js';
|
|
4
4
|
import { hostClient } from '../../lib/daemon/host-client.js';
|
|
5
5
|
import { CliError, omitJson } from '../../lib/json-output.js';
|
|
6
|
+
import { folderRow } from './install-once.js';
|
|
6
7
|
import { loadKitTool } from './kit-tool.js';
|
|
7
8
|
import { execIn } from './release-guard.js';
|
|
8
9
|
import { assertOwnStack } from './stack-owner.js';
|
|
10
|
+
import { removeStage } from './up-build.js';
|
|
9
11
|
import { readRecord, stopLocal } from './up-local.js';
|
|
10
12
|
import { runLocalUp } from './up-run.js';
|
|
11
|
-
const real = (path) => (existsSync(path) ? realpathSync(path) : path);
|
|
12
13
|
// Prints each line as the kit reports it and keeps them for the --json answer.
|
|
13
14
|
const printed = () => {
|
|
14
15
|
const lines = [];
|
|
@@ -46,8 +47,7 @@ const removeAdded = async (dir, record, host) => {
|
|
|
46
47
|
if (!record?.added)
|
|
47
48
|
return [];
|
|
48
49
|
const client = await host();
|
|
49
|
-
|
|
50
|
-
if (!row || real(row.source) !== real(dir))
|
|
50
|
+
if (!(await folderRow(client, record.id, dir)))
|
|
51
51
|
return [];
|
|
52
52
|
await client.remove(record.id, false);
|
|
53
53
|
return [`removed ${record.id} from the daemon (its data stays)`];
|
|
@@ -60,6 +60,8 @@ const stopAndRemove = async (dir, host, stopMs) => {
|
|
|
60
60
|
let down = 'none';
|
|
61
61
|
try {
|
|
62
62
|
down = (await stopLocal(dir, stopMs)).down;
|
|
63
|
+
// Only once no up runs: a killed up leaves its stage in the config cache.
|
|
64
|
+
removeStage(dir);
|
|
63
65
|
if (down !== 'none')
|
|
64
66
|
lines.push(LOCAL_LINES[down]);
|
|
65
67
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readDaemonFile } from '../../lib/daemon/daemon-file.js';
|
|
2
|
+
export interface StatusDaemon {
|
|
3
|
+
pid: number;
|
|
4
|
+
port: number;
|
|
5
|
+
version: string;
|
|
6
|
+
}
|
|
7
|
+
export interface StatusDaemonDeps {
|
|
8
|
+
off: () => boolean;
|
|
9
|
+
ensure: () => Promise<number>;
|
|
10
|
+
file: typeof readDaemonFile;
|
|
11
|
+
}
|
|
12
|
+
export declare const daemonOfStatus: (deps?: StatusDaemonDeps) => Promise<StatusDaemon | null>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ensureDaemon } from '../../lib/daemon/daemon-client.js';
|
|
2
|
+
import { daemonOff, readDaemonFile } from '../../lib/daemon/daemon-file.js';
|
|
3
|
+
import { messageOf } from '../../lib/json-output.js';
|
|
4
|
+
const defaults = {
|
|
5
|
+
off: () => daemonOff(),
|
|
6
|
+
ensure: () => ensureDaemon(),
|
|
7
|
+
file: readDaemonFile,
|
|
8
|
+
};
|
|
9
|
+
// Two terminals get the same pid: both ask for the one daemon of the folder (started once).
|
|
10
|
+
export const daemonOfStatus = async (deps = defaults) => {
|
|
11
|
+
if (deps.off())
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
const port = await deps.ensure();
|
|
15
|
+
const file = deps.file();
|
|
16
|
+
return file && file.port === port ? { pid: file.pid, port, version: file.version } : null;
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
console.error(`daemon: ${messageOf(err)}`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Command } from 'commander';
|
|
2
|
+
import { type StatusDaemon } from './status-daemon.js';
|
|
2
3
|
import { type StatusReport } from '../../lib/status/status-info.js';
|
|
3
4
|
import { type ExtensionsGather } from '../extension/rows.js';
|
|
4
5
|
export declare const printStatus: (report: StatusReport) => void;
|
|
@@ -9,6 +10,7 @@ export interface StatusOptions {
|
|
|
9
10
|
export interface StatusDeps {
|
|
10
11
|
gather: (opts: StatusOptions) => Promise<StatusReport>;
|
|
11
12
|
extensions: (opts: StatusOptions) => Promise<ExtensionsGather>;
|
|
13
|
+
daemon?: () => Promise<StatusDaemon | null>;
|
|
12
14
|
}
|
|
13
15
|
export declare const statusDeps: (account?: boolean) => StatusDeps;
|
|
14
16
|
export declare const runStatus: (opts?: StatusOptions, deps?: StatusDeps) => Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import {} from 'commander';
|
|
3
3
|
import { resolveAuth } from '../../lib/auth/credentials.js';
|
|
4
|
+
import { daemonOfStatus } from './status-daemon.js';
|
|
4
5
|
import { DEFAULT_FQDN, siteFqdn } from '../../lib/net/origins.js';
|
|
5
6
|
import { gatherStatus } from '../../lib/status/status-info.js';
|
|
6
7
|
import { INSTALL_HINT } from '../../lib/update/update-check.js';
|
|
@@ -53,10 +54,15 @@ export const printStatus = (report) => {
|
|
|
53
54
|
if (report.update.message)
|
|
54
55
|
console.log(chalk.yellow(`\n${report.update.message}`));
|
|
55
56
|
};
|
|
57
|
+
const daemonLine = (d) => d
|
|
58
|
+
? `${mark(true)} pid ${d.pid} on 127.0.0.1:${d.port} (${d.version})`
|
|
59
|
+
: chalk.dim('- not running');
|
|
56
60
|
// `account` false: the report that closes setup, which reached the account already.
|
|
57
61
|
export const statusDeps = (account = true) => ({
|
|
58
62
|
gather: (opts) => gatherStatus(resolveAuth({ token: opts.token }), siteFqdn()),
|
|
59
63
|
extensions: (opts) => account ? signedInAccount({ token: opts.token }).then(gatherWithAccount) : gatherExtensions(),
|
|
64
|
+
// The report that closes setup starts no daemon: setup owns that (and --no-daemon).
|
|
65
|
+
...(account && { daemon: () => daemonOfStatus() }),
|
|
60
66
|
});
|
|
61
67
|
const settle = async (deps, opts) => {
|
|
62
68
|
try {
|
|
@@ -74,18 +80,23 @@ const jsonOf = (report, gathered) => {
|
|
|
74
80
|
const { machine, profile, extensions, plan } = gathered.status;
|
|
75
81
|
return { ...report, machine, profile, extensions: extensions.length, plan };
|
|
76
82
|
};
|
|
77
|
-
|
|
83
|
+
// The daemon comes last, in the lines and in --json: the keys and lines before it keep their place.
|
|
84
|
+
const emit = (report, gathered, daemon, json) => {
|
|
85
|
+
const last = daemon === undefined ? {} : { daemon };
|
|
78
86
|
if (json)
|
|
79
|
-
return console.log(JSON.stringify(jsonOf(report, gathered), null, 2));
|
|
87
|
+
return console.log(JSON.stringify({ ...jsonOf(report, gathered), ...last }, null, 2));
|
|
80
88
|
printStatus(report);
|
|
81
89
|
for (const text of gathered ? summaryLines(gathered.status) : [])
|
|
82
90
|
console.log(text);
|
|
91
|
+
if (daemon !== undefined)
|
|
92
|
+
row('daemon', daemonLine(daemon));
|
|
83
93
|
};
|
|
84
94
|
// The report always prints; an extension-side failure then fails the step (exit 1) on stderr.
|
|
85
95
|
export const runStatus = async (opts = {}, deps = statusDeps()) => {
|
|
86
96
|
const report = await deps.gather(opts);
|
|
97
|
+
const daemon = deps.daemon ? await deps.daemon() : undefined;
|
|
87
98
|
const { gathered, error } = await settle(deps, opts);
|
|
88
|
-
emit(report, gathered, opts.json);
|
|
99
|
+
emit(report, gathered, daemon, opts.json);
|
|
89
100
|
printWarnings(gathered?.warnings ?? []);
|
|
90
101
|
if (error)
|
|
91
102
|
throw error;
|
|
@@ -99,7 +110,10 @@ Extensions: adds this machine's id and name (machine.json), the local profile ve
|
|
|
99
110
|
account's when that moved on, and the number of extensions, with what setup would change, e.g.
|
|
100
111
|
(1 to add); agentage extension list shows one row per extension. Signed in, it also marks this
|
|
101
112
|
machine seen in your account (--json: machine.registered). Extension code is never loaded; the
|
|
102
|
-
only file written is machine.json
|
|
113
|
+
only file written is machine.json.
|
|
114
|
+
|
|
115
|
+
Daemon: the one daemon of this config folder (--json: daemon.pid, port, version), started when
|
|
116
|
+
none runs; with AGENTAGE_NO_DAEMON=1 it is null.`;
|
|
103
117
|
export const registerStatus = (program, action) => {
|
|
104
118
|
program
|
|
105
119
|
.command('status')
|
|
@@ -85,8 +85,7 @@ const engineProblem = (engine, version, against) => {
|
|
|
85
85
|
};
|
|
86
86
|
// C10 (D8): the oldest kit minor this cli runs; it moves only with a breaking ctx change.
|
|
87
87
|
export const KIT_FLOOR = '0.12';
|
|
88
|
-
//
|
|
89
|
-
// contract are those of the bundled kit (the update smoke proves it).
|
|
88
|
+
// KIT_FLOOR up to the bundled minor: they share its parts and command contract (the update smoke).
|
|
90
89
|
export const olderKitMinors = (kit = kitVersion()) => {
|
|
91
90
|
const [major, minor] = kit.split('.').map(Number);
|
|
92
91
|
const [floorMajor, floor] = KIT_FLOOR.split('.').map(Number);
|
|
@@ -9,7 +9,7 @@ import { compareVersions } from '../update/update-check.js';
|
|
|
9
9
|
import { VERSION } from '../../utils/version.js';
|
|
10
10
|
import { waitFor } from '../wait.js';
|
|
11
11
|
import { daemonFilePath, daemonOff, daemonPort, EADDRINUSE_EXIT, isAlive, readDaemonFile, removeDaemonFile, } from './daemon-file.js';
|
|
12
|
-
import { otherFolder, unreadableFile, portInUse, probe, probeRetry, PROGRESS_MS, PROTOCOL, proven, unresponsive, } from './daemon-probe.js';
|
|
12
|
+
import { otherFolder, unreadableFile, portInUse, probe, probeRetry, PROGRESS_MS, PROTOCOL, proven, provenPort, unresponsive, } from './daemon-probe.js';
|
|
13
13
|
import { stopDaemon } from './daemon-stop.js';
|
|
14
14
|
const START_MS = 30_000;
|
|
15
15
|
// Over this the log moves to daemon.log.1 at the next start; one old file is kept.
|
|
@@ -18,7 +18,7 @@ export const LOG_CAP = 5 * 1024 * 1024;
|
|
|
18
18
|
export const LATE_FILE_MS = 2_000;
|
|
19
19
|
const answersAs = (pid, found) => found.kind === 'ours' && found.health.pid === pid;
|
|
20
20
|
const announced = (pid) => readDaemonFile()?.pid === pid;
|
|
21
|
-
// Healthy only as the spawned pid,
|
|
21
|
+
// Healthy only as the spawned pid, once its daemon.json (the host token) is written.
|
|
22
22
|
export const waitForHealth = (port, pid, timeoutMs = START_MS) => waitFor(async () => answersAs(pid, await probe(port, 500)) && announced(pid), timeoutMs, {
|
|
23
23
|
afterMs: PROGRESS_MS,
|
|
24
24
|
line: `waiting for the daemon to start on 127.0.0.1:${port}...`,
|
|
@@ -55,10 +55,7 @@ export const defaultEnsureDeps = {
|
|
|
55
55
|
log: (line) => console.error(line),
|
|
56
56
|
};
|
|
57
57
|
// A start that timed out may still have come up late: a proven daemon in daemon.json serves.
|
|
58
|
-
const lateDaemon =
|
|
59
|
-
const file = readDaemonFile();
|
|
60
|
-
return file && proven(file, await deps.probe(file.port)) ? file.port : null;
|
|
61
|
-
};
|
|
58
|
+
const lateDaemon = (deps) => provenPort(deps.probe);
|
|
62
59
|
const notStarted = () => new CliError('daemon_unavailable', `the daemon did not start: it did not answer; see agentage daemon status and ${daemonLogPath()}`);
|
|
63
60
|
// Another cli of this folder may have started one at the same time: its daemon.json can lag.
|
|
64
61
|
const ownLate = async (deps, port, ms) => waitFor(async () => (await lateDaemon(deps)) === port, ms);
|
|
@@ -32,6 +32,7 @@ export type Probe = {
|
|
|
32
32
|
export declare const probe: (port: number, timeoutMs?: number) => Promise<Probe>;
|
|
33
33
|
export declare const probeRetry: (port: number, tries?: number, timeoutMs?: number) => Promise<Probe>;
|
|
34
34
|
export declare const proven: (file: DaemonFile, found: Probe) => Health | null;
|
|
35
|
+
export declare const provenPort: (look?: (port: number) => Promise<Probe>) => Promise<number | null>;
|
|
35
36
|
export declare const unresponsive: (file: DaemonFile) => CliError;
|
|
36
37
|
export declare const otherFolder: (port: number, pid: number, platform?: NodeJS.Platform) => CliError;
|
|
37
38
|
export declare const unreadableFile: (port: number, pid: number) => CliError;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isRecord } from '../fs/json-file.js';
|
|
2
2
|
import { CliError } from '../json-output.js';
|
|
3
|
-
import {} from './daemon-file.js';
|
|
4
|
-
// C4/C5: the protocol this cli speaks; a daemon with another one is restarted.
|
|
3
|
+
import { readDaemonFile } from './daemon-file.js';
|
|
5
4
|
// A wait longer than this prints one line on stderr, so a slow start or stop does not look hung.
|
|
6
5
|
export const PROGRESS_MS = 3_000;
|
|
6
|
+
// C4/C5: the protocol this cli speaks; a daemon with another one is restarted.
|
|
7
7
|
export const PROTOCOL = 1;
|
|
8
8
|
export const DAEMON_SERVICE = 'agentage-daemon';
|
|
9
9
|
const isHealth = (body) => isRecord(body) &&
|
|
@@ -37,6 +37,11 @@ export const probeRetry = async (port, tries = 3, timeoutMs = 2000) => {
|
|
|
37
37
|
};
|
|
38
38
|
// The proof that daemon.json names a daemon of ours: its port answers with the same pid.
|
|
39
39
|
export const proven = (file, found) => found.kind === 'ours' && found.health.pid === file.pid ? found.health : null;
|
|
40
|
+
// The port of daemon.json when its daemon is proven there, else null.
|
|
41
|
+
export const provenPort = async (look = probe) => {
|
|
42
|
+
const file = readDaemonFile();
|
|
43
|
+
return file && proven(file, await look(file.port)) ? file.port : null;
|
|
44
|
+
};
|
|
40
45
|
export const unresponsive = (file) => new CliError('daemon_unresponsive', `the daemon (pid ${file.pid}) does not answer on 127.0.0.1:${file.port}; ` +
|
|
41
46
|
'try again, or stop that process yourself');
|
|
42
47
|
const killLine = (pid, platform = process.platform) => platform === 'win32' ? `taskkill /PID ${pid} /F` : `kill ${pid}`;
|
|
@@ -33,7 +33,7 @@ export interface HostClient {
|
|
|
33
33
|
remove: (id: string, purge: boolean) => Promise<{
|
|
34
34
|
id: string;
|
|
35
35
|
}>;
|
|
36
|
-
reload: (id: string) => Promise<HostReload>;
|
|
36
|
+
reload: (id: string, part?: 'app') => Promise<HostReload>;
|
|
37
37
|
}
|
|
38
38
|
export interface HostReload {
|
|
39
39
|
id: string;
|
|
@@ -42,12 +42,15 @@ export interface HostReload {
|
|
|
42
42
|
pid?: number;
|
|
43
43
|
reloaded: boolean;
|
|
44
44
|
refused?: string;
|
|
45
|
+
part?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface Waits {
|
|
48
|
+
read: number;
|
|
49
|
+
change: number;
|
|
50
|
+
reload?: number;
|
|
45
51
|
}
|
|
46
52
|
type Token = () => string | undefined;
|
|
47
53
|
type Same = (port: number) => Promise<boolean>;
|
|
48
54
|
export declare const sameDaemon: Same;
|
|
49
|
-
export declare const hostClient: (port: number, waits?:
|
|
50
|
-
read: number;
|
|
51
|
-
change: number;
|
|
52
|
-
}, token?: Token, same?: Same) => HostClient;
|
|
55
|
+
export declare const hostClient: (port: number, waits?: Waits, token?: Token, same?: Same) => HostClient;
|
|
53
56
|
export {};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { isRecord } from '../fs/json-file.js';
|
|
2
2
|
import { CliError, DaemonError, messageOf } from '../json-output.js';
|
|
3
3
|
import { daemonFailure } from './daemon-answer.js';
|
|
4
|
-
import { daemonFilePath,
|
|
5
|
-
import {
|
|
4
|
+
import { daemonFilePath, readHostToken } from './daemon-file.js';
|
|
5
|
+
import { provenPort } from './daemon-probe.js';
|
|
6
6
|
// An install runs npm (the daemon waits up to 660 s), then starts the child: past that it is stuck.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// wait; /health lists it
|
|
7
|
+
// A reload: drain 10 s, start and health 60 s each, and the same again to restore: past 5 min stuck.
|
|
8
|
+
const WAITS = { read: 10_000, change: 12 * 60_000, reload: 5 * 60_000 };
|
|
9
|
+
// A change can finish after this wait (queue and installer 11 min each); /health lists it pending.
|
|
10
10
|
const LOOK = {
|
|
11
11
|
GET: 'agentage daemon status',
|
|
12
12
|
POST: 'the daemon may still finish the install: agentage daemon status shows it under pending, then agentage extension list shows if it was installed',
|
|
13
13
|
PATCH: 'the daemon may still finish the change: agentage daemon status shows it under pending, then agentage extension list shows the version',
|
|
14
|
+
RELOAD: 'agentage extension list shows its state; agentage daemon restart if it stays so',
|
|
14
15
|
};
|
|
15
16
|
// A timed-out change may still finish in the daemon: say how to look, never that it failed.
|
|
16
17
|
const unreachable = (port, err, ms, method) => {
|
|
@@ -20,6 +21,8 @@ const unreachable = (port, err, ms, method) => {
|
|
|
20
21
|
const look = LOOK[method] ?? LOOK['PATCH'];
|
|
21
22
|
return new CliError('timeout', `${after}; ${look}`);
|
|
22
23
|
};
|
|
24
|
+
// A body that is no envelope is not the daemon's answer (a proxy, a crash page, another program).
|
|
25
|
+
const foreign = (port, status) => new CliError('daemon_unavailable', `127.0.0.1:${port} answered HTTP ${status} with no agentage answer; agentage daemon status shows what runs there, agentage daemon restart starts it again`);
|
|
23
26
|
const headersOf = (body, token) => ({
|
|
24
27
|
...(body && { 'content-type': 'application/json' }),
|
|
25
28
|
...(token && { authorization: `Bearer ${token}` }),
|
|
@@ -28,12 +31,10 @@ const REFUSED = [401, 403];
|
|
|
28
31
|
// A token that stays refused: daemon.json names another daemon than the one on the port.
|
|
29
32
|
const tokenRefused = (err) => new DaemonError(err.code, `the daemon refused the host token of ${daemonFilePath()} (${err.message}); run agentage daemon restart`, err.status, err.details);
|
|
30
33
|
// A retry with a new token only when daemon.json still names this port and its pid answers there.
|
|
31
|
-
export const sameDaemon = async (port) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const sendOnce = async (to, method, path, body) => {
|
|
36
|
-
const ms = method === 'GET' ? to.waits.read : to.waits.change;
|
|
34
|
+
export const sameDaemon = async (port) => (await provenPort()) === port;
|
|
35
|
+
const waitOf = ({ waits }, kind) => kind === 'GET' ? waits.read : kind === 'RELOAD' ? (waits.reload ?? waits.read) : waits.change;
|
|
36
|
+
const sendOnce = async (to, method, path, body, kind = method) => {
|
|
37
|
+
const ms = waitOf(to, kind);
|
|
37
38
|
const res = await fetch(`http://127.0.0.1:${to.port}${path}`, {
|
|
38
39
|
method,
|
|
39
40
|
headers: headersOf(body, to.token()),
|
|
@@ -41,21 +42,23 @@ const sendOnce = async (to, method, path, body) => {
|
|
|
41
42
|
signal: AbortSignal.timeout(ms),
|
|
42
43
|
redirect: 'error',
|
|
43
44
|
}).catch((err) => {
|
|
44
|
-
throw unreachable(to.port, err, ms,
|
|
45
|
+
throw unreachable(to.port, err, ms, kind);
|
|
45
46
|
});
|
|
46
47
|
const parsed = await res.json().catch(() => null);
|
|
47
|
-
if (!
|
|
48
|
+
if (!isRecord(parsed) || typeof parsed['success'] !== 'boolean')
|
|
49
|
+
throw foreign(to.port, res.status);
|
|
50
|
+
if (!res.ok || parsed['success'] !== true)
|
|
48
51
|
throw daemonFailure(res.status, parsed);
|
|
49
52
|
return parsed['data'];
|
|
50
53
|
};
|
|
51
54
|
const refused = (err) => err instanceof DaemonError && REFUSED.includes(err.status);
|
|
52
55
|
// 401 or 403 is refused before any change: daemon.json is read again (a new daemon), once.
|
|
53
|
-
const sender = (to) => (method, path, body) => sendOnce(to, method, path, body).catch(async (err) => {
|
|
56
|
+
const sender = (to) => (method, path, body, kind = method) => sendOnce(to, method, path, body, kind).catch(async (err) => {
|
|
54
57
|
if (!refused(err))
|
|
55
58
|
throw err;
|
|
56
59
|
if (!(await to.same(to.port)))
|
|
57
60
|
throw tokenRefused(err);
|
|
58
|
-
return sendOnce(to, method, path, body).catch((again) => {
|
|
61
|
+
return sendOnce(to, method, path, body, kind).catch((again) => {
|
|
59
62
|
throw refused(again) ? tokenRefused(again) : again;
|
|
60
63
|
});
|
|
61
64
|
});
|
|
@@ -67,6 +70,6 @@ export const hostClient = (port, waits = WAITS, token = readHostToken, same = sa
|
|
|
67
70
|
add: (body) => send('POST', '/host/extensions', body),
|
|
68
71
|
change: (id, patch) => send('PATCH', at(id), patch),
|
|
69
72
|
remove: (id, purge) => send('DELETE', `${at(id)}${purge ? '?purge=true' : ''}`),
|
|
70
|
-
reload: (id) => send('POST', `${at(id)}/reload`, {}),
|
|
73
|
+
reload: (id, part) => send('POST', `${at(id)}/reload`, part ? { part } : {}, 'RELOAD'),
|
|
71
74
|
};
|
|
72
75
|
};
|
package/dist/lib/fs/file-lock.js
CHANGED
|
@@ -60,6 +60,12 @@ const createLockExclusive = (path, content) => {
|
|
|
60
60
|
try {
|
|
61
61
|
linkSync(tmp, path);
|
|
62
62
|
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
// No hard links on the volume (exFAT, some SMB or Docker mounts): an exclusive create instead.
|
|
65
|
+
if (err.code === 'EEXIST')
|
|
66
|
+
throw err;
|
|
67
|
+
writeFileSync(path, content, { flag: 'wx' });
|
|
68
|
+
}
|
|
63
69
|
finally {
|
|
64
70
|
unlinkQuiet(tmp);
|
|
65
71
|
}
|
|
@@ -6,5 +6,5 @@ export interface ProcessMark {
|
|
|
6
6
|
}
|
|
7
7
|
export declare const markOf: (pid: number | undefined, read?: ReadStart) => ProcessMark | null;
|
|
8
8
|
export declare const isMark: (value: unknown) => value is ProcessMark;
|
|
9
|
-
export declare const proven: (mark: ProcessMark | undefined | null
|
|
10
|
-
export declare const stopProven: (mark: ProcessMark
|
|
9
|
+
export declare const proven: (mark: ProcessMark | undefined | null) => boolean;
|
|
10
|
+
export declare const stopProven: (mark: ProcessMark) => boolean;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { isPid } from '../daemon/daemon-file.js';
|
|
4
|
+
import { isRecord } from '../fs/json-file.js';
|
|
4
5
|
// Field 22 of /proc/<pid>/stat, counted from the state field after the `(comm)` part.
|
|
5
6
|
const STARTTIME = 19;
|
|
6
7
|
const fromProc = (pid) => {
|
|
7
8
|
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
8
9
|
return stat.slice(stat.lastIndexOf(')') + 2).split(' ')[STARTTIME] ?? null;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// A ps that hangs reads as "cannot tell", so nothing is signalled.
|
|
12
|
+
const PS_MS = 5_000;
|
|
13
|
+
const fromPs = (pid) => execFileSync('ps', ['-o', 'lstart=', '-p', String(pid)], {
|
|
14
|
+
encoding: 'utf8',
|
|
15
|
+
timeout: PS_MS,
|
|
16
|
+
}).trim() || null;
|
|
17
|
+
// Pid plus start time proves one process; null on Windows (no /proc, no ps): never signalled.
|
|
13
18
|
export const startedAt = (pid) => {
|
|
14
19
|
if (!isPid(pid) || process.platform === 'win32')
|
|
15
20
|
return null;
|
|
@@ -24,15 +29,12 @@ export const markOf = (pid, read = startedAt) => {
|
|
|
24
29
|
const started = pid === undefined ? null : read(pid);
|
|
25
30
|
return pid !== undefined && started !== null ? { pid, started } : null;
|
|
26
31
|
};
|
|
27
|
-
export const isMark = (value) => typeof value === '
|
|
28
|
-
value !== null &&
|
|
29
|
-
isPid(value.pid) &&
|
|
30
|
-
typeof value.started === 'string';
|
|
32
|
+
export const isMark = (value) => isRecord(value) && isPid(value['pid']) && typeof value['started'] === 'string';
|
|
31
33
|
// The same process still runs: the pid lives and started at the recorded time.
|
|
32
|
-
export const proven = (mark
|
|
34
|
+
export const proven = (mark) => mark ? startedAt(mark.pid) === mark.started : false;
|
|
33
35
|
// SIGTERM only to a proven process; anything else is left alone and reported.
|
|
34
|
-
export const stopProven = (mark
|
|
35
|
-
if (!proven(mark
|
|
36
|
+
export const stopProven = (mark) => {
|
|
37
|
+
if (!proven(mark))
|
|
36
38
|
return false;
|
|
37
39
|
try {
|
|
38
40
|
process.kill(mark.pid, 'SIGTERM');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "The agentage CLI - connect this machine to agentage from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,12 +54,16 @@
|
|
|
54
54
|
"prepublishOnly": "npm run verify"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@agentage/extension": "
|
|
57
|
+
"@agentage/extension": "0.18.1",
|
|
58
58
|
"@electric-sql/pglite": "^0.5.16",
|
|
59
|
+
"@tailwindcss/postcss": "^4.3.5",
|
|
59
60
|
"chalk": "^6.0.0",
|
|
60
61
|
"commander": "^15.0.0",
|
|
62
|
+
"esbuild": "^0.28.2",
|
|
61
63
|
"express": "^5.3.0",
|
|
62
|
-
"open": "^11.0.0"
|
|
64
|
+
"open": "^11.0.0",
|
|
65
|
+
"postcss": "^8.5.33",
|
|
66
|
+
"tailwindcss": "^4.3.5"
|
|
63
67
|
},
|
|
64
68
|
"devDependencies": {
|
|
65
69
|
"@playwright/test": "latest",
|