@agentage/cli 0.53.0 → 0.54.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.
Files changed (37) hide show
  1. package/README.md +9 -11
  2. package/dist/commands/daemon/daemon.d.ts +3 -3
  3. package/dist/commands/daemon/daemon.js +21 -8
  4. package/dist/commands/daemon/installer.js +4 -7
  5. package/dist/commands/extension/build.js +5 -3
  6. package/dist/commands/extension/configure.js +2 -1
  7. package/dist/commands/extension/create-install.js +3 -2
  8. package/dist/commands/extension/install-once.d.ts +2 -0
  9. package/dist/commands/extension/install-once.js +5 -5
  10. package/dist/commands/extension/lifecycle.d.ts +0 -2
  11. package/dist/commands/extension/lifecycle.js +4 -4
  12. package/dist/commands/extension/package-build.d.ts +10 -0
  13. package/dist/commands/extension/package-build.js +28 -9
  14. package/dist/commands/extension/release-guard.d.ts +8 -1
  15. package/dist/commands/extension/release-guard.js +39 -16
  16. package/dist/commands/extension/release.js +35 -19
  17. package/dist/commands/extension/setup-install.js +2 -4
  18. package/dist/commands/extension/up-build.d.ts +0 -1
  19. package/dist/commands/extension/up-build.js +3 -9
  20. package/dist/commands/extension/up-local.d.ts +3 -0
  21. package/dist/commands/extension/up-local.js +30 -11
  22. package/dist/commands/extension/up-reload.d.ts +7 -1
  23. package/dist/commands/extension/up-reload.js +30 -7
  24. package/dist/commands/extension/up-run.js +74 -38
  25. package/dist/commands/extension/up-watch.d.ts +1 -1
  26. package/dist/commands/extension/up-watch.js +8 -8
  27. package/dist/commands/extension/up.js +6 -4
  28. package/dist/core/loader/manifest.js +1 -2
  29. package/dist/lib/daemon/daemon-client.js +3 -6
  30. package/dist/lib/daemon/daemon-probe.d.ts +1 -0
  31. package/dist/lib/daemon/daemon-probe.js +7 -2
  32. package/dist/lib/daemon/host-client.d.ts +6 -4
  33. package/dist/lib/daemon/host-client.js +19 -16
  34. package/dist/lib/fs/file-lock.js +6 -0
  35. package/dist/lib/proc/start-time.d.ts +2 -2
  36. package/dist/lib/proc/start-time.js +12 -10
  37. package/package.json +2 -2
@@ -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, readDaemonFile, readHostToken } from './daemon-file.js';
5
- import { probe, proven } from './daemon-probe.js';
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
- const WAITS = { read: 10_000, change: 12 * 60_000 };
8
- // The kit's queue and installer can each take 11 min, so a change can still finish after this
9
- // wait; /health lists it under pending until it ends.
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
- const file = readDaemonFile();
33
- return file?.port === port && proven(file, await probe(port)) !== null;
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, method);
45
+ throw unreachable(to.port, err, ms, kind);
45
46
  });
46
47
  const parsed = await res.json().catch(() => null);
47
- if (!res.ok || !isRecord(parsed) || parsed['success'] !== true)
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) => send('POST', `${at(id)}/reload`, {}, 'RELOAD'),
71
74
  };
72
75
  };
@@ -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, read?: ReadStart) => boolean;
10
- export declare const stopProven: (mark: ProcessMark, read?: ReadStart) => boolean;
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
- const fromPs = (pid) => execFileSync('ps', ['-o', 'lstart=', '-p', String(pid)], { encoding: 'utf8' }).trim() || null;
11
- // When a pid started: a pid plus this proves one process, a reused pid has another.
12
- // Windows has neither /proc nor ps: null there, so a process is never proven and never signalled.
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 === 'object' &&
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, read = startedAt) => (mark ? read(mark.pid) === mark.started : false);
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, read = startedAt) => {
35
- if (!proven(mark, read))
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.53.0",
3
+ "version": "0.54.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,7 +54,7 @@
54
54
  "prepublishOnly": "npm run verify"
55
55
  },
56
56
  "dependencies": {
57
- "@agentage/extension": "^0.15.0",
57
+ "@agentage/extension": "0.16.0",
58
58
  "@electric-sql/pglite": "^0.5.16",
59
59
  "chalk": "^6.0.0",
60
60
  "commander": "^15.0.0",