@agentage/cli 0.54.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.
@@ -1,6 +1,6 @@
1
1
  import type * as Kit from '@agentage/extension/tool';
2
2
  import { type KitCheck } from '../../core/loader/load.js';
3
- export type KitTool = Pick<typeof Kit, 'check' | 'checkLines' | 'build' | 'buildLines' | 'runCommand' | 'checkCli' | 'up' | 'down' | 'token' | 'readManifest' | 'writeContracts'>;
3
+ export type KitTool = Pick<typeof Kit, 'check' | 'checkLines' | 'build' | 'buildLines' | 'runCommand' | 'checkCli' | 'up' | 'down' | 'token' | 'readManifest' | 'writeContracts' | 'appBuilder' | 'buildApp'>;
4
4
  export type LoadKitTool = () => Promise<KitTool>;
5
5
  export declare const loadKitTool: LoadKitTool;
6
6
  export declare const kitCheck: (tool?: LoadKitTool) => KitCheck;
@@ -0,0 +1,9 @@
1
+ import type { AppBuilder } from '@agentage/extension/tool';
2
+ import { type LoadKitTool } from './kit-tool.js';
3
+ import { type Run } from './up-reload.js';
4
+ export declare const APP_OUT: string;
5
+ export declare const hasAppPart: (dir: string) => boolean;
6
+ export declare const startAppBuilder: (dir: string, tool?: LoadKitTool) => Promise<AppBuilder | null>;
7
+ export declare const appIntoNext: (dir: string) => void;
8
+ export declare const buildAppOnce: (dir: string, builder: AppBuilder) => Promise<boolean>;
9
+ export declare const appAndReload: (run: Run, builder: AppBuilder) => Promise<void>;
@@ -0,0 +1,59 @@
1
+ import { cpSync, existsSync, rmSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { isRecord } from '../../lib/fs/json-file.js';
4
+ import { messageOf } from '../../lib/json-output.js';
5
+ import { loadKitTool } from './kit-tool.js';
6
+ import { packageOf } from './package-build.js';
7
+ import { NEXT } from './up-build.js';
8
+ import {} from './up-reload.js';
9
+ // The app part's build output (kit APP_DIR); the shell imports it, the child never reads it.
10
+ export const APP_OUT = join('dist', 'app');
11
+ export const hasAppPart = (dir) => {
12
+ const agentage = packageOf(dir)['agentage'];
13
+ const parts = isRecord(agentage) ? agentage['parts'] : undefined;
14
+ return isRecord(parts) && parts['app'] === true;
15
+ };
16
+ // A warm esbuild context for the whole up; null (with one line) when it cannot start.
17
+ export const startAppBuilder = async (dir, tool = loadKitTool) => {
18
+ if (!hasAppPart(dir))
19
+ return null;
20
+ try {
21
+ return await (await tool()).appBuilder(dir);
22
+ }
23
+ catch (err) {
24
+ console.error(`app no app build: ${messageOf(err)}`);
25
+ return null;
26
+ }
27
+ };
28
+ // A full reload swaps dist.next for dist whole: dist.next/app must be the current app build.
29
+ export const appIntoNext = (dir) => {
30
+ const next = join(dir, NEXT, 'app');
31
+ rmSync(next, { recursive: true, force: true });
32
+ if (existsSync(join(dir, APP_OUT)))
33
+ cpSync(join(dir, APP_OUT), next, { recursive: true });
34
+ };
35
+ // One build of src/app into dist/app and dist.next/app; false (one line) when it failed.
36
+ export const buildAppOnce = async (dir, builder) => {
37
+ try {
38
+ await builder.rebuild();
39
+ }
40
+ catch (err) {
41
+ console.error(`app build failed, no reload: ${messageOf(err)}`);
42
+ return false;
43
+ }
44
+ appIntoNext(dir);
45
+ return true;
46
+ };
47
+ // A save in src/app: build it, then a reload of the app part only (the child keeps running).
48
+ export const appAndReload = async (run, builder) => {
49
+ const since = Date.now();
50
+ if (!(await buildAppOnce(run.dir, builder)))
51
+ return;
52
+ const answer = await run.host
53
+ .reload(run.id, 'app')
54
+ .catch((err) => ({ error: messageOf(err) }));
55
+ const ms = Date.now() - since;
56
+ if ('error' in answer)
57
+ return console.error(`app ${run.id} reload failed: ${answer.error}`);
58
+ console.log(`app ${run.id} reloaded in ${ms} ms (the child keeps running)`);
59
+ };
@@ -1,3 +1,4 @@
1
+ import type { AppBuilder } from '@agentage/extension/tool';
1
2
  import { type HostClient } from '../../lib/daemon/host-client.js';
2
3
  import { type Code } from '../../lib/json-output.js';
3
4
  import { type Npm } from './package-build.js';
@@ -11,8 +12,9 @@ export interface Run {
11
12
  fatal?: (why: string, code?: Code) => void;
12
13
  failed?: number;
13
14
  builtAt?: number;
15
+ app?: AppBuilder | null;
14
16
  }
15
- export declare const editedSince: (dir: string, since?: number) => boolean;
17
+ export declare const editedSince: (dir: string, since?: number, sub?: string) => boolean;
16
18
  export declare const RELOAD_STRIKES = 3;
17
19
  type Task = () => Promise<void>;
18
20
  export declare const lane: () => ((task: Task) => Promise<void>);
@@ -1,13 +1,14 @@
1
1
  import { cpSync, existsSync, readdirSync, statSync } from 'node:fs';
2
- import { join } from 'node:path';
2
+ import { join, sep } from 'node:path';
3
3
  import {} from '../../lib/daemon/host-client.js';
4
4
  import { messageOf } from '../../lib/json-output.js';
5
5
  import {} from './package-build.js';
6
+ import { appAndReload } from './up-app.js';
6
7
  import { NEXT, stagedBuild } from './up-build.js';
7
8
  import { coalesced, runRest, watchFolder, watchTsc, } from './up-watch.js';
8
9
  // A save between the start of the running build and the end of the first watch build.
9
- export const editedSince = (dir, since) => {
10
- const src = join(dir, 'src');
10
+ export const editedSince = (dir, since, sub = 'src') => {
11
+ const src = join(dir, sub);
11
12
  if (since === undefined || !existsSync(src))
12
13
  return false;
13
14
  return readdirSync(src, { recursive: true, withFileTypes: true }).some((f) => f.isFile() && statSync(join(f.parentPath, f.name)).mtimeMs >= since);
@@ -88,15 +89,38 @@ export const tscReloads = (run, inLane) => {
88
89
  };
89
90
  return { onChange: () => void (state.building = true), onBuilt };
90
91
  };
92
+ const inApp = (file) => file === 'app' || file.startsWith(`app${sep}`);
93
+ // src/app: its own watch, in the lane of every dist.next write, never a child restart.
94
+ const appWatch = (run, inLane) => {
95
+ const app = run.app;
96
+ if (!app)
97
+ return [];
98
+ const go = coalesced(() => inLane(() => appAndReload(run, app)));
99
+ const watcher = watchFolder(join(run.dir, 'src', 'app'), go);
100
+ // A save between the start of up and this watch (the page may be open already) is built now.
101
+ if (editedSince(run.dir, run.builtAt, join('src', 'app')))
102
+ void go();
103
+ return [watcher];
104
+ };
91
105
  const watchWithTsc = (run, mode, onDied) => {
92
106
  const inLane = lane();
93
107
  const tsc = watchTsc(run.dir, mode, { ...tscReloads(run, inLane), onDied });
108
+ const app = appWatch(run, inLane);
94
109
  if (!mode.rest)
95
- return { watchers: [tsc], tscPid: tsc.pid };
110
+ return { watchers: [tsc, ...app], tscPid: tsc.pid };
96
111
  const rest = mode.rest;
97
112
  const bundle = coalesced(() => inLane(() => bundleUi(run, rest)));
98
113
  const ui = watchFolder(join(run.dir, 'src', 'ui'), bundle);
99
- return { watchers: [tsc, ui], tscPid: tsc.pid };
114
+ return { watchers: [tsc, ui, ...app], tscPid: tsc.pid };
115
+ };
116
+ const watchStaged = (run, script) => {
117
+ const inLane = lane();
118
+ const app = appWatch(run, inLane);
119
+ if (!script)
120
+ return { watchers: app };
121
+ const skip = run.app ? inApp : undefined;
122
+ const go = coalesced(() => inLane(() => stageAndReload(run)));
123
+ return { watchers: [watchFolder(join(run.dir, 'src'), go, undefined, skip), ...app] };
100
124
  };
101
125
  export const startWatch = (run, mode, onDied) => {
102
126
  if (mode.kind === 'tsc')
@@ -105,11 +129,5 @@ export const startWatch = (run, mode, onDied) => {
105
129
  console.error('watch no build script: a change in src/ is not built');
106
130
  if (!existsSync(join(run.dir, 'src')))
107
131
  console.error('watch no src/ folder: nothing to watch');
108
- if (!mode.script)
109
- return { watchers: [] };
110
- return {
111
- watchers: [
112
- watchFolder(join(run.dir, 'src'), coalesced(() => stageAndReload(run))),
113
- ],
114
- };
132
+ return watchStaged(run, mode.script);
115
133
  };
@@ -1,3 +1,4 @@
1
+ import type { AppBuilder } from '@agentage/extension/tool';
1
2
  import { type HostClient } from '../../lib/daemon/host-client.js';
2
3
  import { type Npm, type PackageBuild } from './package-build.js';
3
4
  export interface LocalUpDeps {
@@ -8,6 +9,7 @@ export interface LocalUpDeps {
8
9
  }>;
9
10
  npm: Npm;
10
11
  stopped: (dir: string, nonce: string, ended: Promise<string>) => Promise<string>;
12
+ app?: (dir: string) => Promise<AppBuilder | null>;
11
13
  }
12
14
  export declare const localUpDeps: LocalUpDeps;
13
15
  export interface LocalUp {
@@ -9,6 +9,7 @@ import { CliError } from '../../lib/json-output.js';
9
9
  import { folderRow, installFolder } from './install-once.js';
10
10
  import { loadKitTool } from './kit-tool.js';
11
11
  import { buildPackage, npmIn, packageOf } from './package-build.js';
12
+ import { buildAppOnce, startAppBuilder } from './up-app.js';
12
13
  import { removeStage, seedNext, upModeOf } from './up-build.js';
13
14
  import { claimFolder, rewriteRecord, selfMark, untilStopped } from './up-local.js';
14
15
  import { stageAndReload, startWatch } from './up-reload.js';
@@ -51,7 +52,10 @@ const stopLine = (id, stoppedBy, added) => {
51
52
  console.log(` agentage extension down removes it (its data stays)`);
52
53
  };
53
54
  // The first build: in the folder while no child runs it (a create or an earlier up), else staged.
55
+ // The app goes into dist/app first, so dist.next starts with it (a full reload swaps dist whole).
54
56
  const firstBuild = async (run, mode, build) => {
57
+ if (run.app)
58
+ await buildAppOnce(run.dir, run.app);
55
59
  if (!(await folderRow(run.host, run.id, run.dir))) {
56
60
  await warnProblems(await build(run.dir));
57
61
  return seedNext(run.dir);
@@ -96,11 +100,13 @@ export const runLocalUp = async (folder = '.', deps = localUpDeps, json = false)
96
100
  const mode = upModeOf(dir);
97
101
  // A stage of an earlier up may hold an old package.json: the first staged build copies it again.
98
102
  removeStage(dir);
103
+ run.app = await (deps.app ?? startAppBuilder)(dir);
99
104
  try {
100
105
  return await upAndWatch(run, mode, deps, { port, json, before, nonce });
101
106
  }
102
107
  finally {
103
108
  removeStage(dir);
109
+ await run.app?.dispose();
104
110
  }
105
111
  };
106
112
  // The fatal channel is wired before the first build: a second up with no build tool stops too.
@@ -2,7 +2,7 @@ import { type UpMode } from './up-build.js';
2
2
  export interface Stoppable {
3
3
  stop: () => void;
4
4
  }
5
- export declare const watchFolder: (dir: string, onChange: () => void, debounceMs?: number) => Stoppable;
5
+ export declare const watchFolder: (dir: string, onChange: () => void, debounceMs?: number, skip?: (file: string) => boolean) => Stoppable;
6
6
  export declare const coalesced: (run: () => Promise<void>) => (() => Promise<void>);
7
7
  export interface TscBuilt {
8
8
  errors: number;
@@ -7,14 +7,24 @@ import { messageOf } from '../../lib/json-output.js';
7
7
  import { deadline, how, STEP_MS } from './package-build.js';
8
8
  import { NEXT } from './up-build.js';
9
9
  // A recursive watch of one folder of the working copy; saves inside the debounce are one change.
10
- export const watchFolder = (dir, onChange, debounceMs = 200) => {
10
+ // `skip`: a changed path (relative to dir) that is not this watch's change (src/app has its own).
11
+ export const watchFolder = (dir, onChange, debounceMs = 200, skip = () => false) => {
11
12
  if (!existsSync(dir))
12
13
  return { stop: () => undefined };
13
14
  let timer;
14
- const watcher = watch(dir, { recursive: true }, () => {
15
+ // Linux recursive watches lose a file an editor saved by rename (seen as `change`): re-armed each time.
16
+ const fire = () => {
17
+ watcher.close();
18
+ watcher = arm();
19
+ onChange();
20
+ };
21
+ const arm = () => watch(dir, { recursive: true }, (_event, file) => {
22
+ if (file && skip(file))
23
+ return;
15
24
  clearTimeout(timer);
16
- timer = setTimeout(onChange, debounceMs);
25
+ timer = setTimeout(fire, debounceMs);
17
26
  });
27
+ let watcher = arm();
18
28
  return { stop: () => (clearTimeout(timer), watcher.close()) };
19
29
  };
20
30
  // One run at a time, one more after a change during it; a throw prints one line, the watch goes on.
@@ -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
- const emit = (report, gathered, json) => {
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')
@@ -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,6 +42,7 @@ export interface HostReload {
42
42
  pid?: number;
43
43
  reloaded: boolean;
44
44
  refused?: string;
45
+ part?: string;
45
46
  }
46
47
  export interface Waits {
47
48
  read: number;
@@ -70,6 +70,6 @@ export const hostClient = (port, waits = WAITS, token = readHostToken, same = sa
70
70
  add: (body) => send('POST', '/host/extensions', body),
71
71
  change: (id, patch) => send('PATCH', at(id), patch),
72
72
  remove: (id, purge) => send('DELETE', `${at(id)}${purge ? '?purge=true' : ''}`),
73
- reload: (id) => send('POST', `${at(id)}/reload`, {}, 'RELOAD'),
73
+ reload: (id, part) => send('POST', `${at(id)}/reload`, part ? { part } : {}, 'RELOAD'),
74
74
  };
75
75
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/cli",
3
- "version": "0.54.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": "0.16.0",
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",