@anhlp/alp-cli 0.0.1-beta.7 → 0.0.1-beta.9

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 (56) hide show
  1. package/dist/THIRD-PARTY-NOTICES.txt +1 -1
  2. package/dist/acp/main.js +1 -1
  3. package/dist/acp.js +7586 -2258
  4. package/dist/{alp-web → alp-dashboard}/THIRD-PARTY-NOTICES.txt +1 -1
  5. package/dist/{alp-web/assets/TerminalPanel-BeMws9CP.js → alp-dashboard/assets/TerminalPanel-BSjqIfNr.js} +1 -1
  6. package/dist/{alp-web/assets/index-Dl7motn1.js → alp-dashboard/assets/index-CZFfSOIE.js} +35 -35
  7. package/dist/{alp-web → alp-dashboard}/index.html +1 -1
  8. package/dist/{alp-web.js → alp-dashboard.js} +491 -323
  9. package/dist/alpd.js +11807 -5372
  10. package/dist/backup.js +1 -1
  11. package/dist/build-manifest.json +24 -6
  12. package/dist/cli.js +7 -4
  13. package/dist/daemon.d.ts +2 -2
  14. package/dist/daemon.js +8 -8
  15. package/dist/dashboard-migrate.d.ts +31 -0
  16. package/dist/dashboard-migrate.js +127 -0
  17. package/dist/dashboard-service.d.ts +69 -0
  18. package/dist/{web-service.js → dashboard-service.js} +30 -32
  19. package/dist/desktop.d.ts +56 -0
  20. package/dist/desktop.js +91 -0
  21. package/dist/interfaces.d.ts +2 -2
  22. package/dist/interfaces.js +134 -42
  23. package/dist/library.d.ts +16 -2
  24. package/dist/library.js +114 -7
  25. package/dist/paths.d.ts +6 -1
  26. package/dist/paths.js +4 -2
  27. package/dist/projects.js +2 -1
  28. package/dist/roles.d.ts +5 -5
  29. package/dist/self-update.d.ts +4 -2
  30. package/dist/self-update.js +29 -6
  31. package/dist/sessions.d.ts +0 -1
  32. package/dist/usage.d.ts +1 -1
  33. package/dist/usage.js +13 -6
  34. package/package.json +6 -6
  35. package/src/cli.js +8 -3
  36. package/src/daemon.js +10 -9
  37. package/src/dashboard-migrate.js +152 -0
  38. package/src/{web-service.js → dashboard-service.js} +54 -48
  39. package/src/desktop.js +122 -0
  40. package/src/interfaces.js +171 -58
  41. package/src/library.js +108 -9
  42. package/src/paths.js +9 -3
  43. package/src/projects.js +3 -1
  44. package/src/roles.js +4 -4
  45. package/src/self-update.js +45 -8
  46. package/src/sessions.js +0 -2
  47. package/src/usage.js +13 -6
  48. package/dist/web-service.d.ts +0 -56
  49. /package/dist/{alp-web → alp-dashboard}/alp-boundary.json +0 -0
  50. /package/dist/{alp-web → alp-dashboard}/apple-touch-icon.png +0 -0
  51. /package/dist/{alp-web → alp-dashboard}/assets/TerminalPanel-DLuoa74B.css +0 -0
  52. /package/dist/{alp-web → alp-dashboard}/assets/highlighter-BnicKQ_d.js +0 -0
  53. /package/dist/{alp-web → alp-dashboard}/assets/index-DwqDSiIi.css +0 -0
  54. /package/dist/{alp-web → alp-dashboard}/favicon-attention.svg +0 -0
  55. /package/dist/{alp-web → alp-dashboard}/favicon-running.svg +0 -0
  56. /package/dist/{alp-web → alp-dashboard}/favicon.svg +0 -0
package/dist/projects.js CHANGED
@@ -21,8 +21,9 @@ async function project(command, args) {
21
21
  try {
22
22
  const result = await (command === "upgrade" ? upgradeProject : initProject)(args[0] ?? process.cwd(), { library: alpHome() });
23
23
  console.log(`ALP initialized: ${result.created.length} files created, ${result.preserved.length} existing files preserved.`);
24
- const library = await seedLibrary(alpHome());
24
+ const library = await seedLibrary(alpHome(), { offerRoleSkills: command === "upgrade" });
25
25
  if (library.created.length || library.updated.length) console.log(`Skill library ${alpHome()}: ${library.created.length} files added, ${library.updated.length} unchanged files updated.`);
26
+ if (library.offered?.length) console.log(`New built-in skills given to roles in your edited role-skills.json: ${library.offered.join(", ")} (remove any you do not want; ALP will not add it again).`);
26
27
  if (command === "init" && result.updated?.length) console.log(`Template model profiles refreshed: ${result.updated.join(", ")}`);
27
28
  if (command === "upgrade") {
28
29
  console.log(`ALP upgraded: ${result.updated.length} files updated.${result.backup ? ` Backup: ${result.backup}` : ""}`);
package/dist/roles.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  /**
2
- * The role subcommands (t-1e02): `alp daemon run`, `alp web serve` and `alp bridge acp|antigravity`
3
- * run alpd, alp-web and the MCP bridges in this process: they import the same scripts that
4
- * `node alpd.js` and `node alp-web.js` run. Services and MCP entries written by the single-file
2
+ * The role subcommands (t-1e02): `alp daemon run`, `alp dashboard serve` and `alp bridge acp|antigravity`
3
+ * run alpd, alp-dashboard and the MCP bridges in this process: they import the same scripts that
4
+ * `node alpd.js` and `node alp-dashboard.js` run. Services and MCP entries written by the single-file
5
5
  * executable of 0.0.1-beta.5/6 still name them.
6
6
  *
7
7
  * The role's module reads its options from process.argv as when run directly, so argv is rewritten
8
8
  * to `[runtime, entry, ...args]` before the module loads.
9
- * @param {'daemon' | 'web' | 'acp'} role
9
+ * @param {'daemon' | 'dashboard' | 'acp'} role
10
10
  * @param {string} file the role's script beside this CLI
11
11
  * @param {string[]} args
12
12
  */
13
- export function runRole(role: "daemon" | "web" | "acp", file: string, args: string[]): Promise<any>;
13
+ export function runRole(role: "daemon" | "dashboard" | "acp", file: string, args: string[]): Promise<any>;
14
14
  /** alp bridge acp|antigravity: the stdio MCP bridge an agent CLI starts to reach alpd's tools. @param {string[]} args */
15
15
  export function bridgeCommand(args: string[]): void;
@@ -58,7 +58,7 @@ export function verifyProvenance(file: string, { repo, env, run, find }: {
58
58
  }): "unavailable" | "verified";
59
59
  /**
60
60
  * Runs `action`, again after a pause while Windows reports the file busy: a virus scanner holds an
61
- * executable it just saw run (the staged bundle's --version) for a moment. About 6 s in all.
61
+ * executable it just saw run (the staged bundle's --version) for a moment. About 8 s in all.
62
62
  * @template T @param {() => T} action @param {(ms: number) => void} [sleep]
63
63
  */
64
64
  export function retryBusy<T>(action: () => T, sleep?: (ms: number) => void, attempts?: number): T;
@@ -95,7 +95,7 @@ export function pruneVersions(app: string, keep: string[], fs?: typeof nodeFs, {
95
95
  * fetchBytes: (url: string) => Promise<Uint8Array>, confirm: (question: string) => Promise<boolean>,
96
96
  * provenance: (file: string, repo: string) => string, extract: typeof extract,
97
97
  * daemon: () => Promise<{ version: string, sessions?: number } | undefined>, restartDaemon: (root: string) => number,
98
- * runVersion: (root: string) => string,
98
+ * runVersion: (root: string) => string, runDaemonVersion: (root: string) => string,
99
99
  * }} UpdateDeps
100
100
  */
101
101
  /** @param {string[]} args @param {Partial<UpdateDeps>} [overrides] @returns {Promise<number>} the exit code */
@@ -118,6 +118,7 @@ export function sha256(bytes: Uint8Array): string;
118
118
  /** The largest file alp update downloads: an archive of the bundle is about 70 MB. */
119
119
  export const MAX_DOWNLOAD: number;
120
120
  export function notInstalledMessage(root: string): string;
121
+ export function systemTar(platform?: string, env?: Record<string, string | undefined>): string;
121
122
  export type UpdateDeps = {
122
123
  bundle: import("@anhlp/alp-core/packaged").BundleInfo | undefined;
123
124
  version: string;
@@ -137,6 +138,7 @@ export type UpdateDeps = {
137
138
  } | undefined>;
138
139
  restartDaemon: (root: string) => number;
139
140
  runVersion: (root: string) => string;
141
+ runDaemonVersion: (root: string) => string;
140
142
  };
141
143
  import { spawnSync } from 'node:child_process';
142
144
  /** Whether a program is on PATH. @param {string} name */
@@ -7,7 +7,7 @@ import path from "node:path";
7
7
  import { createInterface } from "node:readline/promises";
8
8
  import { fileURLToPath, pathToFileURL } from "node:url";
9
9
  import { parseArgs } from "node:util";
10
- import { bundleInfo, samePath } from "@anhlp/alp-core/packaged";
10
+ import { bundleInfo, NATIVE_DAEMON, samePath } from "@anhlp/alp-core/packaged";
11
11
  var DEFAULT_REPO = "phucanh08/alp";
12
12
  var SIGNER_WORKFLOW = ".github/workflows/release-binaries.yml";
13
13
  var NPM_PACKAGE = "@anhlp/alp";
@@ -160,7 +160,7 @@ Then restart alpd when no sessions are running: alp daemon restart
160
160
  }
161
161
  var notInstalledMessage = (root) => `alp: ${root} is not an installed ALP (no app/current points at it); install the release with install.sh (Windows: install.ps1), which alp update can then keep up to date:
162
162
  curl -fsSL https://github.com/${DEFAULT_REPO}/releases/latest/download/install.sh | sh`;
163
- var systemTar = () => process.platform === "win32" ? path.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "tar.exe") : "tar";
163
+ var systemTar = (platform = process.platform, env = process.env) => platform === "win32" ? path.win32.join(env.SystemRoot ?? "C:\\Windows", "System32", "tar.exe") : "tar";
164
164
  function extract(archive, directory, asset, platform, run = spawnSync) {
165
165
  const windows = platform.startsWith("windows-");
166
166
  const result = run(systemTar(), [windows ? "-xf" : "-xzf", archive, "-C", directory], { encoding: "utf8", windowsHide: true });
@@ -256,6 +256,8 @@ async function selfUpdate(args, overrides = {}) {
256
256
  const run = bundleCommand(root);
257
257
  return spawnSync(run.command, [...run.args, "--version"], { encoding: "utf8", windowsHide: true, timeout: 6e4 }).stdout?.trim() ?? "";
258
258
  },
259
+ // Without BUN_BE_BUN, which would make the native alpd the Bun CLI.
260
+ runDaemonVersion: (root) => spawnSync(path.join(root, "bin", NATIVE_DAEMON), ["--version"], { encoding: "utf8", windowsHide: true, timeout: 6e4, env: Object.fromEntries(Object.entries(process.env).filter(([name]) => name !== "BUN_BE_BUN")) }).stdout?.trim() ?? "",
259
261
  ...overrides
260
262
  };
261
263
  const { bundle } = deps;
@@ -308,7 +310,6 @@ async function selfUpdate(args, overrides = {}) {
308
310
  return 0;
309
311
  }
310
312
  const { app, current } = bundle;
311
- if (deps.platform === "win32" && asset.version === path.basename(bundle.root)) throw new Error(`ALP ${asset.version} is the version running now; Windows cannot replace it in place. Close ALP (alp daemon stop) and rerun install.ps1 to repair it`);
312
313
  const running = await deps.daemon().catch(() => void 0);
313
314
  try {
314
315
  nodeFs.accessSync(app, nodeFs.constants.W_OK);
@@ -342,13 +343,34 @@ async function selfUpdate(args, overrides = {}) {
342
343
  if (manifest.version !== asset.version || manifest.platform && manifest.platform !== platform) throw new Error(`${asset.name} holds ALP ${manifest.version} for ${manifest.platform}, not ${asset.version} for ${platform}; nothing was changed`);
343
344
  const reported = deps.runVersion(unpacked);
344
345
  if (reported !== asset.version) throw new Error(`The downloaded ALP reports version ${JSON.stringify(reported)}, not ${asset.version}; nothing was changed`);
346
+ if (deps.env.ALP_NATIVE_DAEMON !== "0" && nodeFs.existsSync(path.join(unpacked, "bin", NATIVE_DAEMON))) {
347
+ const native = deps.runDaemonVersion(unpacked);
348
+ if (native !== asset.version) throw new Error(`The downloaded ALP's native alpd (bin/${NATIVE_DAEMON}) reports version ${JSON.stringify(native)}, not ${asset.version}, so it cannot run here; nothing was changed. To update with alpd on the bundled Node, set ALP_NATIVE_DAEMON=0 for this update and keep it set`);
349
+ }
345
350
  if (nodeFs.existsSync(target)) {
346
351
  if (samePath(target, bundle.root) || running?.version === asset.version) {
347
- aside = `.alp-old-${randomBytes(6).toString("hex")}`;
348
- retryBusy(() => nodeFs.renameSync(target, path.join(app, aside)));
352
+ const moved = `.alp-old-${randomBytes(6).toString("hex")}`;
353
+ try {
354
+ retryBusy(() => nodeFs.renameSync(target, path.join(app, moved)));
355
+ } catch (error) {
356
+ throw new Error(`Could not move ${target} aside to reinstall ALP ${asset.version}: ${error.message}. Something holds that directory: a process whose working directory is inside it, or a file handle opened without delete sharing. Stop alpd (alp daemon stop), leave that directory in any shell, and run alp update again`, { cause: error });
357
+ }
358
+ aside = moved;
349
359
  } else nodeFs.rmSync(target, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
350
360
  }
351
- retryBusy(() => nodeFs.renameSync(unpacked, target));
361
+ try {
362
+ retryBusy(() => nodeFs.renameSync(unpacked, target));
363
+ } catch (error) {
364
+ if (aside && !nodeFs.existsSync(target)) {
365
+ try {
366
+ nodeFs.renameSync(path.join(app, aside), target);
367
+ aside = void 0;
368
+ } catch {
369
+ throw new Error(`${error.message}; the running ALP ${asset.version} is in ${path.join(app, aside)}: move it back to ${target}`, { cause: error });
370
+ }
371
+ }
372
+ throw error;
373
+ }
352
374
  switchCurrent(app, asset.version, { platform: deps.platform });
353
375
  } finally {
354
376
  try {
@@ -394,6 +416,7 @@ export {
394
416
  selfUpdate,
395
417
  sha256,
396
418
  switchCurrent,
419
+ systemTar,
397
420
  verifyChecksum,
398
421
  verifyProvenance
399
422
  };
@@ -41,7 +41,6 @@ export function pause(args: any): Promise<void>;
41
41
  export function resume(args: any): Promise<void>;
42
42
  /** alp language: the language the user reads (ALPD §54); new sessions use it. */
43
43
  export function recall(args: any): Promise<void>;
44
- /** alp web: opens the web app alpd serves on 127.0.0.1, with the token in the address (ALPD §61). */
45
44
  export function interrupt(args: any): Promise<void>;
46
45
  /** alp compact <session>: compacts a root's context now, or at its next turn boundary (t-0e56). */
47
46
  export function compact(args: any): Promise<void>;
package/dist/usage.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export const USAGE: "Usage:\n alp <init|update-template> [directory] create a project, or upgrade an older project's ALP template (upgrade is an alias)\n alp update [--check] [--yes] [--version X] update ALP from GitHub Releases (checksum and provenance checked)\n alp --version\n alp setup [directory] [--runtime codex|claude|mix] [--prefer claude|codex]\n [--claude-model M] [--codex-model M] [--claude-supervisor M] [--codex-supervisor M]\n [--claude-oracle M] [--codex-oracle M] write Ph\u1EDF/Cafe's agent profiles to .alp/settings.json\n alp daemon <start|stop|restart>\n alp daemon status [--json] liveness and readiness; exit 0 ready, 3 not running, 4 not ready\n alp daemon <install|uninstall> run alpd as a login service that restarts after a crash\n alp daemon run [--detach] [--service] run alpd in this process (what services written by 0.0.1-beta.5/6 start)\n alp acp serve ALP to an editor (Zed, JetBrains) over the Agent Client Protocol on stdio\n alp web [--print] open the ALP web app on this machine (alp-web, loopback); --print only prints its address\n alp web serve [--service|--rotate] [--project DIR] run alp-web in this process (what alp web starts)\n alp bridge <acp|antigravity> the stdio MCP bridge an agent CLI starts to reach alpd (internal)\n alp web rotate give alp web a new token: open pages lose access; prints the new address\n alp web pair [--on|--off] the link that pairs Paseo's app on another device through the relay; --on or --off turns the relay on or off\n alp terminal <allow [--paseo] --yes|deny [--paseo]|status> [--json] remote terminals (a shell as you on this host; a workspace is not a sandbox), off by default\n alp doctor [--project DIR] [--fix] [--json] check this machine and project; --fix repairs what is safe to\n alp backup [-o FILE] [--project DIR]... [--no-projects] [--stop] [--json] sessions, settings, library and tasks in one file\n alp backup verify <file> [--json] | alp backup list [--json]\n alp restore <file> [--home-only] [--dry-run] [--stop] [--replace-newer] [--json] checks the whole backup first; keeps what it replaces\n alpd must be stopped for both; --stop stops it and starts it again after\n alp run [--agent A] [--team pho|cafe|ID] [--model M] [--mode read-only|workspace-write|full-access] [--thinking T] [--project DIR] [--json] <prompt>\n alp schedule create --session ID --at ISO_WITH_OFFSET --prompt TEXT [--project DIR] [--json]\n alp schedule list [--status pending|delivered|failed|cancelled] [--project DIR] [--json]\n alp schedule <show|cancel> ID [--project DIR] [--json] one-shot wake; timer gates only unblock tasks\n alp ps [--all]\n alp top [session] [--once]\n alp attach <session> [--json]\n alp send <session> [--prompt] [--json] <text>\n child default: user mail; --prompt: explicit new prompt to a live root or child\n alp questions [--json]\n alp answer <question> <text> | alp answer <question> --dismiss [--reason R]\n alp log <session> [--json]\n alp board [--project DIR] [--json]\n alp <agents|skills|mcp|hooks> [--project DIR] [--json] the library: built-in, ~/.alp and project entries\n alp providers [--json] ACP and Antigravity providers in your library\n alp teams [--project DIR] [--json] teams sessions run in: members, delegation, house rules\n alp agent <new|edit> <name> [--project [DIR]] [--from A] [-d text] [--provider P] [--model M] [--thinking T] [--mode M]\n [--skills a,b] [--mcp a,b] [--hooks a,b] [--instructions FILE]\n alp team <new|edit> <id> [--project [DIR]] [--from ID] [--label L] [-d text] [--main A] [--member name=role]...\n [--member-model name=M]... [--member-thinking name=T]... [--delegate owner=a,b]... [--max-peers N]\n [--supervisor A] [--supervisor-model M] [--supervisor-thinking T] [--no-supervisor] [--rules FILE]\n alp skill new <name> [--project [DIR]] [--from S] [--file FILE]\n alp mcp add <name> [--project [DIR]] (--command C [--arg A]... [--env K=V]... [--cwd D] | --url U [--header K=V]...)\n alp hook add <name> [--project [DIR]] --event E --command C [--blocking] [--timeout SEC] [--match-agent A] [--match-label L]\n alp provider add <id> --command C [--arg A]... [--env K=V]... [--label L] [-d text] [--models a,b] an ACP agent; use id antigravity for native agy\n alp provider edit antigravity --read-only-mode instructions|reject legacy, no effect: agy enforces every mode itself\n alp <agent|team|skill|mcp|hook|provider> <rm|show> <name> [--project [DIR]] | <cp|mv> <from> <to> [--project [DIR]]\n alp <mcp|hook|provider> test <name> [--project [DIR]] list an MCP server's tools; run a hook once; initialize a provider\n without --project, changes go to your library in ~/.alp; built-in agents and teams are never changed\n alp trust [--project DIR] | --revoke [--project DIR] | --list [--json] whether the project's hooks may run\n alp permissions [--project DIR] [--json] each agent's permission profile\n alp permissions check <agent> \"<command>\" what that agent's profile says about a command\n alp tasks [ready] [--all] [--status S] [--label L] [--project DIR] [--json]\n alp tasks gates [--json] open gates; checks GitHub ones\n alp tasks compact [--days 30] [--dry-run]\n alp tasks export [-o file.jsonl] as beads JSONL\n alp tasks import [file.jsonl] [--dry-run] beads JSONL; default .beads/issues.jsonl\n alp formula list | show <name> | pour <name> [--var k=v]... [--parent ID] [--dry-run]\n alp task add <title> [-d text] [-p 0-4] [-t task|bug|feature|chore|epic] [--parent ID] [--after ID]... [-l label]... [--path P]... [--from ID]\n alp task show <id> [--json]\n alp task report <epic> [--json] what an epic came to: tasks, time, rework, verification\n alp task edit <id> [--title T] [-d text] [-p N] [-t type] [-l label]... [--path P]... [-m note]\n alp task close <id> [--reason done|wontfix|duplicate|superseded] [-m summary] [--unverified \"why\"]\n alp verify [--project DIR] [--task ID] [--json] run the project's verify commands; --task records the result\n alp task reopen <id> [-m note]\n alp task dep <add|rm> <id> [--after ID]... [--parent ID] [--related ID]...\n alp task gate add <id> --human \"question\" [--option answer]... | --timer +2h|ISO | --pr N|owner/repo#N | --run N|owner/repo#N\n alp task gate clear <id> <gate> [--choice answer] [-m note] approve; main is told by mail\n alp task gate reject <id> <gate> [-m reason] the gate stays open; main is told by mail\n alp task gate rm <id> <gate> [-m note]\n alp pause [codex|claude] [--now] [-m reason] | alp pause status hold delegation; --now parks running assignments\n alp resume [codex|claude] lift a pause; parked assignments continue\n alp models [--refresh] [--json] the models alpd offers now, from each provider (cached; refreshed every 6 h)\n alp language [name | --reset] the language agents and ALP write to you in; default Vietnamese\n alp recall <assignment|task> [--project DIR] [--json] <question> ask a finished assignment about its work\n alp interrupt <session>\n alp compact <session>";
1
+ export const USAGE: "Usage:\n alp <init|update-template> [directory] create a project, or upgrade an older project's ALP template (upgrade is an alias)\n alp update [--check] [--yes] [--version X] update ALP from GitHub Releases (checksum and provenance checked)\n alp --version\n alp setup [directory] [--runtime codex|claude|mix] [--prefer claude|codex]\n [--claude-model M] [--codex-model M] [--claude-supervisor M] [--codex-supervisor M]\n [--claude-oracle M] [--codex-oracle M] write Ph\u1EDF/Cafe's agent profiles to .alp/settings.json\n (keeps profiles written by hand; names other teams and the keys to edit)\n alp daemon <start|stop|restart>\n alp daemon status [--json] liveness and readiness; exit 0 ready, 3 not running, 4 not ready\n alp daemon <install|uninstall> run alpd as a login service that restarts after a crash\n alp daemon run [--detach] [--service] run alpd in this process (what services written by 0.0.1-beta.5/6 start)\n alp acp serve ALP to an editor (Zed, JetBrains) over the Agent Client Protocol on stdio\n alp dashboard [--port N] [--host 127.0.0.1|localhost] [--no-open|--print] open ALP's dashboard in the browser (alp-dashboard, loopback only); --no-open/--print only print its address\n alp dashboard --status|--stop whether alp dashboard runs (address without its token) | stop it\n alp desktop open ALP's desktop app (ALP.app, else the checkout in ALP_DESKTOP_CHECKOUT)\n alp dashboard serve [--service|--rotate] [--project DIR] [--port N] run alp-dashboard in this process (what alp dashboard starts)\n alp bridge <acp|antigravity> the stdio MCP bridge an agent CLI starts to reach alpd (internal)\n alp dashboard rotate give alp dashboard a new token: open pages lose access; prints the new address\n alp dashboard pair [--on|--off] the link that pairs Paseo's app on another device through the relay; --on or --off turns the relay on or off\n alp terminal <allow [--paseo] --yes|deny [--paseo]|status> [--json] remote terminals (a shell as you on this host; a workspace is not a sandbox), off by default\n alp doctor [--project DIR] [--fix] [--json] check this machine and project; --fix repairs what is safe to\n alp backup [-o FILE] [--project DIR]... [--no-projects] [--stop] [--json] sessions, settings, library and tasks in one file\n alp backup verify <file> [--json] | alp backup list [--json]\n alp restore <file> [--home-only] [--dry-run] [--stop] [--replace-newer] [--json] checks the whole backup first; keeps what it replaces\n alpd must be stopped for both; --stop stops it and starts it again after\n alp run [--agent A] [--team pho|cafe|ID] [--model M] [--mode read-only|workspace-write|full-access] [--thinking T] [--project DIR] [--json] <prompt>\n alp schedule create --session ID --at ISO_WITH_OFFSET --prompt TEXT [--project DIR] [--json]\n alp schedule list [--status pending|delivered|failed|cancelled] [--project DIR] [--json]\n alp schedule <show|cancel> ID [--project DIR] [--json] one-shot wake; timer gates only unblock tasks\n alp ps [--all]\n alp top [session] [--once]\n alp attach <session> [--json]\n alp send <session> [--prompt] [--json] <text>\n child default: user mail; --prompt: explicit new prompt to a live root or child\n alp questions [--json]\n alp answer <question> <text> | alp answer <question> --dismiss [--reason R]\n alp log <session> [--json]\n alp board [--project DIR] [--json]\n alp <agents|skills|mcp|hooks> [--project DIR] [--json] the library: built-in, ~/.alp and project entries\n alp skills --retired [--json] skills alp_skill_retire moved to ~/.alp/retired-skills\n alp providers [--json] ACP and Antigravity providers in your library\n alp teams [--project DIR] [--json] teams sessions run in: members, delegation, house rules\n alp packs [--project DIR] [--json] optional skill packs ALP ships (backend, frontend, architecture, ...)\n alp pack install <id> [--project [DIR]] [--assign] [--json] copy a pack's skills, agents and teams; existing entries are kept\n alp agent <new|edit> <name> [--project [DIR]] [--from A] [-d text] [--provider P] [--model M] [--thinking T] [--mode M]\n [--skills a,b] [--mcp a,b] [--hooks a,b] [--instructions FILE]\n alp team <new|edit> <id> [--project [DIR]] [--from ID] [--label L] [-d text] [--main A] [--member name=role]...\n [--member-model name=M]... [--member-thinking name=T]... [--delegate owner=a,b]... [--max-peers N]\n [--supervisor A] [--supervisor-model M] [--supervisor-thinking T] [--no-supervisor] [--rules FILE]\n alp skill <new|edit> <name> [--project [DIR]] [--from S] [--file FILE]\n alp skill check [name|DIR] [--project [DIR]] [--strict] [--json] validate skills (format, references, links); exit 1 on errors\n alp skill restore <name> [--from DIR] [--roles a,b | --no-roles] bring back a retired skill; --roles needed if it was retired without retired.json\n alp mcp add <name> [--project [DIR]] (--command C [--arg A]... [--env K=V]... [--cwd D] | --url U [--header K=V]...)\n alp hook add <name> [--project [DIR]] --event E --command C [--blocking] [--timeout SEC] [--match-agent A] [--match-label L]\n alp provider add <id> --command C [--arg A]... [--env K=V]... [--label L] [-d text] [--models a,b] an ACP agent; use id antigravity for native agy\n alp <agent|team|skill|mcp|hook|provider> <rm|show> <name> [--project [DIR]] | <cp|mv> <from> <to> [--project [DIR]]\n alp <mcp|hook|provider> test <name> [--project [DIR]] list an MCP server's tools; run a hook once; initialize a provider\n without --project, changes go to your library in ~/.alp; built-in agents and teams are never changed\n alp trust [--project DIR] | --revoke [--project DIR] | --list [--json] whether the project's hooks may run\n alp permissions [--project DIR] [--json] each agent's permission profile\n alp permissions check <agent> \"<command>\" what that agent's profile says about a command\n alp tasks [ready] [--all] [--status S] [--label L] [--project DIR] [--json]\n alp tasks gates [--json] open gates; checks GitHub ones\n alp tasks compact [--days 30] [--dry-run]\n alp tasks export [-o file.jsonl] as beads JSONL\n alp tasks import [file.jsonl] [--dry-run] beads JSONL; default .beads/issues.jsonl\n alp formula list | show <name> | pour <name> [--var k=v]... [--parent ID] [--dry-run]\n alp task add <title> [-d text] [-p 0-4] [-t task|bug|feature|chore|epic] [--parent ID] [--after ID]... [-l label]... [--path P]... [--from ID]\n alp task show <id> [--json]\n alp task report <epic> [--json] what an epic came to: tasks, time, rework, verification\n alp task edit <id> [--title T] [-d text] [-p N] [-t type] [-l label]... [--path P]... [-m note]\n alp task close <id> [--reason done|wontfix|duplicate|superseded] [-m summary] [--unverified \"why\"]\n alp verify [--project DIR] [--task ID] [--json] run the project's verify commands; --task records the result\n alp task reopen <id> [-m note]\n alp task dep <add|rm> <id> [--after ID]... [--parent ID] [--related ID]...\n alp task gate add <id> --human \"question\" [--option answer]... | --timer +2h|ISO | --pr N|owner/repo#N | --run N|owner/repo#N\n alp task gate clear <id> <gate> [--choice answer] [-m note] approve; main is told by mail\n alp task gate reject <id> <gate> [-m reason] the gate stays open; main is told by mail\n alp task gate rm <id> <gate> [-m note]\n alp pause [codex|claude] [--now] [-m reason] | alp pause status hold delegation; --now parks running assignments\n alp resume [codex|claude] lift a pause; parked assignments continue\n alp models [--refresh] [--json] the models alpd offers now, from each provider (cached; refreshed every 6 h)\n alp language [name | --reset] the language agents and ALP write to you in; default Vietnamese\n alp recall <assignment|task> [--project DIR] [--json] <question> ask a finished assignment about its work\n alp interrupt <session>\n alp compact <session>";
2
2
  export class UsageError extends Error {
3
3
  }
package/dist/usage.js CHANGED
@@ -6,16 +6,19 @@ var USAGE = `Usage:
6
6
  alp setup [directory] [--runtime codex|claude|mix] [--prefer claude|codex]
7
7
  [--claude-model M] [--codex-model M] [--claude-supervisor M] [--codex-supervisor M]
8
8
  [--claude-oracle M] [--codex-oracle M] write Ph\u1EDF/Cafe's agent profiles to .alp/settings.json
9
+ (keeps profiles written by hand; names other teams and the keys to edit)
9
10
  alp daemon <start|stop|restart>
10
11
  alp daemon status [--json] liveness and readiness; exit 0 ready, 3 not running, 4 not ready
11
12
  alp daemon <install|uninstall> run alpd as a login service that restarts after a crash
12
13
  alp daemon run [--detach] [--service] run alpd in this process (what services written by 0.0.1-beta.5/6 start)
13
14
  alp acp serve ALP to an editor (Zed, JetBrains) over the Agent Client Protocol on stdio
14
- alp web [--print] open the ALP web app on this machine (alp-web, loopback); --print only prints its address
15
- alp web serve [--service|--rotate] [--project DIR] run alp-web in this process (what alp web starts)
15
+ alp dashboard [--port N] [--host 127.0.0.1|localhost] [--no-open|--print] open ALP's dashboard in the browser (alp-dashboard, loopback only); --no-open/--print only print its address
16
+ alp dashboard --status|--stop whether alp dashboard runs (address without its token) | stop it
17
+ alp desktop open ALP's desktop app (ALP.app, else the checkout in ALP_DESKTOP_CHECKOUT)
18
+ alp dashboard serve [--service|--rotate] [--project DIR] [--port N] run alp-dashboard in this process (what alp dashboard starts)
16
19
  alp bridge <acp|antigravity> the stdio MCP bridge an agent CLI starts to reach alpd (internal)
17
- alp web rotate give alp web a new token: open pages lose access; prints the new address
18
- alp web pair [--on|--off] the link that pairs Paseo's app on another device through the relay; --on or --off turns the relay on or off
20
+ alp dashboard rotate give alp dashboard a new token: open pages lose access; prints the new address
21
+ alp dashboard pair [--on|--off] the link that pairs Paseo's app on another device through the relay; --on or --off turns the relay on or off
19
22
  alp terminal <allow [--paseo] --yes|deny [--paseo]|status> [--json] remote terminals (a shell as you on this host; a workspace is not a sandbox), off by default
20
23
  alp doctor [--project DIR] [--fix] [--json] check this machine and project; --fix repairs what is safe to
21
24
  alp backup [-o FILE] [--project DIR]... [--no-projects] [--stop] [--json] sessions, settings, library and tasks in one file
@@ -36,18 +39,22 @@ var USAGE = `Usage:
36
39
  alp log <session> [--json]
37
40
  alp board [--project DIR] [--json]
38
41
  alp <agents|skills|mcp|hooks> [--project DIR] [--json] the library: built-in, ~/.alp and project entries
42
+ alp skills --retired [--json] skills alp_skill_retire moved to ~/.alp/retired-skills
39
43
  alp providers [--json] ACP and Antigravity providers in your library
40
44
  alp teams [--project DIR] [--json] teams sessions run in: members, delegation, house rules
45
+ alp packs [--project DIR] [--json] optional skill packs ALP ships (backend, frontend, architecture, ...)
46
+ alp pack install <id> [--project [DIR]] [--assign] [--json] copy a pack's skills, agents and teams; existing entries are kept
41
47
  alp agent <new|edit> <name> [--project [DIR]] [--from A] [-d text] [--provider P] [--model M] [--thinking T] [--mode M]
42
48
  [--skills a,b] [--mcp a,b] [--hooks a,b] [--instructions FILE]
43
49
  alp team <new|edit> <id> [--project [DIR]] [--from ID] [--label L] [-d text] [--main A] [--member name=role]...
44
50
  [--member-model name=M]... [--member-thinking name=T]... [--delegate owner=a,b]... [--max-peers N]
45
51
  [--supervisor A] [--supervisor-model M] [--supervisor-thinking T] [--no-supervisor] [--rules FILE]
46
- alp skill new <name> [--project [DIR]] [--from S] [--file FILE]
52
+ alp skill <new|edit> <name> [--project [DIR]] [--from S] [--file FILE]
53
+ alp skill check [name|DIR] [--project [DIR]] [--strict] [--json] validate skills (format, references, links); exit 1 on errors
54
+ alp skill restore <name> [--from DIR] [--roles a,b | --no-roles] bring back a retired skill; --roles needed if it was retired without retired.json
47
55
  alp mcp add <name> [--project [DIR]] (--command C [--arg A]... [--env K=V]... [--cwd D] | --url U [--header K=V]...)
48
56
  alp hook add <name> [--project [DIR]] --event E --command C [--blocking] [--timeout SEC] [--match-agent A] [--match-label L]
49
57
  alp provider add <id> --command C [--arg A]... [--env K=V]... [--label L] [-d text] [--models a,b] an ACP agent; use id antigravity for native agy
50
- alp provider edit antigravity --read-only-mode instructions|reject legacy, no effect: agy enforces every mode itself
51
58
  alp <agent|team|skill|mcp|hook|provider> <rm|show> <name> [--project [DIR]] | <cp|mv> <from> <to> [--project [DIR]]
52
59
  alp <mcp|hook|provider> test <name> [--project [DIR]] list an MCP server's tools; run a hook once; initialize a provider
53
60
  without --project, changes go to your library in ~/.alp; built-in agents and teams are never changed
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@anhlp/alp-cli",
3
- "version": "0.0.1-beta.7",
3
+ "version": "0.0.1-beta.9",
4
4
  "type": "module",
5
5
  "description": "ALP cli module",
6
6
  "files": [
7
7
  "src",
8
- "!src/web",
8
+ "!src/dashboard",
9
9
  "dist",
10
10
  "NOTICE"
11
11
  ],
@@ -127,9 +127,9 @@
127
127
  "node": ">=22.12"
128
128
  },
129
129
  "dependencies": {
130
- "@anhlp/alp-core": "0.0.1-beta.7",
131
- "@anhlp/alp-client": "0.0.1-beta.7",
132
- "@anhlp/alp-protocol": "0.0.1-beta.7",
130
+ "@anhlp/alp-core": "0.0.1-beta.9",
131
+ "@anhlp/alp-client": "0.0.1-beta.9",
132
+ "@anhlp/alp-protocol": "0.0.1-beta.9",
133
133
  "smol-toml": "1.9.0",
134
134
  "@agentclientprotocol/sdk": "1.7.0",
135
135
  "@anthropic-ai/claude-agent-sdk": "^0.3.292"
@@ -161,6 +161,6 @@
161
161
  "node-pty": "1.2.0-beta.15"
162
162
  },
163
163
  "devDependencies": {
164
- "@anhlp/alp-gateway": "0.0.1-beta.7"
164
+ "@anhlp/alp-gateway": "0.0.1-beta.9"
165
165
  }
166
166
  }
package/src/cli.js CHANGED
@@ -3,14 +3,16 @@ import { readFileSync } from 'node:fs';
3
3
  import { setup } from '@anhlp/alp-client/setup';
4
4
  import { alpHome } from '@anhlp/alp-client/index';
5
5
  import { scrubText } from '@anhlp/alp-core/log';
6
+ import { catalogModels, useLiveModels } from '@anhlp/alp-core/models';
6
7
  import { USAGE, UsageError } from './usage.js';
7
8
  import { project, permissionsCommand, trustCommand, language, verify, doctor } from './projects.js';
8
9
  import { daemon } from './daemon.js';
9
10
  import { run, ps, attach, send, questions, answer, top, log, board, models, pause, resume, recall, interrupt, compact } from './sessions.js';
10
- import { libraryCommand, editCommand, teamsCommand } from './library.js';
11
+ import { libraryCommand, editCommand, teamsCommand, packsCommand, packCommand } from './library.js';
11
12
  import { scheduleCommand } from './schedules.js';
12
13
  import { tasksCommand, formulaCommand, taskCommand } from './tasks.js';
13
- import { webCommand, acpCommand } from './interfaces.js';
14
+ import { dashboardCommand, acpCommand } from './interfaces.js';
15
+ import { desktopCommand } from './desktop.js';
14
16
  import { backupCommand, restoreCommand } from './backup.js';
15
17
  import { terminalCommand } from './terminal.js';
16
18
  import { bridgeCommand } from './roles.js';
@@ -46,7 +48,7 @@ async function updateCommand(args) {
46
48
  if (code) process.exitCode = code;
47
49
  }
48
50
 
49
- const commands = { schedule: scheduleCommand, setup: args => setup(args, alpHome()), init: args => project('init', args), 'update-template': args => project('upgrade', args), upgrade: args => project('upgrade', args), update: updateCommand, daemon, doctor, run, ps, top, attach, send, questions, answer, log, board, tasks: tasksCommand, task: taskCommand, formula: formulaCommand, permissions: permissionsCommand, agents: args => libraryCommand('agents', args), skills: args => libraryCommand('skills', args), mcp: args => ['add', 'rm', 'mv', 'cp', 'test', 'show', 'edit'].includes(args[0]) ? editCommand('mcp', args) : libraryCommand('mcp', args), hooks: args => libraryCommand('hooks', args), providers: args => libraryCommand('providers', args), provider: args => editCommand('providers', args), teams: teamsCommand, trust: trustCommand, agent: args => editCommand('agents', args), team: args => editCommand('teams', args), skill: args => editCommand('skills', args), hook: args => editCommand('hooks', args), verify, recall, pause, resume, language, models, interrupt, compact, acp: acpCommand, web: webCommand, backup: backupCommand, restore: restoreCommand, terminal: terminalCommand, bridge: bridgeCommand };
51
+ const commands = { schedule: scheduleCommand, setup: args => setup(args, alpHome()), init: args => project('init', args), 'update-template': args => project('upgrade', args), upgrade: args => project('upgrade', args), update: updateCommand, daemon, doctor, run, ps, top, attach, send, questions, answer, log, board, tasks: tasksCommand, task: taskCommand, formula: formulaCommand, permissions: permissionsCommand, agents: args => libraryCommand('agents', args), skills: args => libraryCommand('skills', args), mcp: args => ['add', 'rm', 'mv', 'cp', 'test', 'show', 'edit'].includes(args[0]) ? editCommand('mcp', args) : libraryCommand('mcp', args), hooks: args => libraryCommand('hooks', args), providers: args => libraryCommand('providers', args), provider: args => editCommand('providers', args), teams: teamsCommand, packs: packsCommand, pack: packCommand, trust: trustCommand, agent: args => editCommand('agents', args), team: args => editCommand('teams', args), skill: args => editCommand('skills', args), hook: args => editCommand('hooks', args), verify, recall, pause, resume, language, models, interrupt, compact, acp: acpCommand, dashboard: dashboardCommand, desktop: desktopCommand, backup: backupCommand, restore: restoreCommand, terminal: terminalCommand, bridge: bridgeCommand };
50
52
  const [command, ...args] = process.argv.slice(2);
51
53
  try {
52
54
  if (command === '--version') {
@@ -54,6 +56,9 @@ try {
54
56
  console.log(alpVersion());
55
57
  } else {
56
58
  if (!Object.hasOwn(commands, command)) throw new UsageError();
59
+ // Effort checks read the catalog alpd last cached, the rows alpd itself checks with (t-086c), so
60
+ // the CLI and alpd agree on a model only live rows list (t-b3cd #8). No provider is asked.
61
+ if (command !== 'setup') useLiveModels(catalogModels(alpHome()));
57
62
  await commands[command](args);
58
63
  }
59
64
  } catch (error) {
package/src/daemon.js CHANGED
@@ -2,23 +2,23 @@ import { access } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { installedProgram, installService, serviceFor, uninstallService } from '@anhlp/alp-client/service';
4
4
  import { holdDaemon, startDaemon } from '@anhlp/alp-client/supervise';
5
- import { alpHome, connect, lockAlive, readLock, withDaemonLifecycle } from '@anhlp/alp-client/index';
5
+ import { alpHome, connect, daemonStartTimeoutMs, lockAlive, readLock, withDaemonLifecycle } from '@anhlp/alp-client/index';
6
6
  import { scrubText } from '@anhlp/alp-core/log';
7
7
  import { UsageError } from './usage.js';
8
- import { DAEMON_ENTRY } from './paths.js';
8
+ import { DAEMON_ENTRY, DAEMON_SCRIPT } from './paths.js';
9
9
  import { runRole } from './roles.js';
10
10
 
11
- async function built() {
11
+ async function built(entry = DAEMON_ENTRY) {
12
12
  try {
13
- await access(DAEMON_ENTRY);
13
+ await access(entry);
14
14
  } catch {
15
- throw new Error(`alpd is not built (${DAEMON_ENTRY}); run npm run build`);
15
+ throw new Error(`alpd is not built (${entry}); run npm run build`);
16
16
  }
17
17
  }
18
18
 
19
- /** Waits until an alpd for this home is ready; returns its socket. */
19
+ /** Waits until an alpd for this home is ready; returns its socket. Default wait: ALP_DAEMON_START_TIMEOUT_MS, else 60 s. */
20
20
 
21
- async function ready(timeoutMs = 15_000) {
21
+ async function ready(timeoutMs = daemonStartTimeoutMs()) {
22
22
  const deadline = Date.now() + timeoutMs;
23
23
  while (Date.now() < deadline) {
24
24
  const lock = await readLock(alpHome());
@@ -61,8 +61,9 @@ async function stop() {
61
61
  }
62
62
 
63
63
  async function daemon([action, ...rest]) {
64
- // alpd itself in this process; its own options (--detach, --service, --startup-timeout=MS) follow.
65
- if (action === 'run') { await built(); return runRole('daemon', DAEMON_ENTRY, rest); }
64
+ // alpd itself in this process (alpd.js on this Node, even where the bundle ships the native alpd);
65
+ // its own options (--detach, --service, --startup-timeout=MS) follow.
66
+ if (action === 'run') { await built(DAEMON_SCRIPT); return runRole('daemon', DAEMON_SCRIPT, rest); }
66
67
  if (rest.length && !(action === 'status' && rest.length === 1 && rest[0] === '--json')) throw new UsageError();
67
68
  if (action === 'start') {
68
69
  const socket = await start();
@@ -0,0 +1,152 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { chmod, link, lstat, readFile, rename, unlink, writeFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { migrateDashboardSettings } from '@anhlp/alp-core/user-settings';
5
+ import { DASHBOARD, LEGACY_WEB, refusal, serviceOwner, stopService } from './dashboard-service.js';
6
+
7
+ /**
8
+ * The move from `alp web` (0.0.1-beta.8 and earlier) to `alp dashboard` (t-81b0.5), run by every
9
+ * `alp dashboard` command before it reads or starts anything. An install keeps its token, its port
10
+ * and its enabled/disabled setting:
11
+ *
12
+ * 1. alp web still running under `integrations/web.lock` (or the Paseo integration from before its
13
+ * own rename, which held the same lock) is stopped, with the same proofs `alp dashboard --stop`
14
+ * uses; a holder that cannot be proven is left running and nothing below is moved, since it
15
+ * may still write the old files.
16
+ * 2. `<home>/web/` (alp web's credential store) becomes `<home>/dashboard/`.
17
+ * 3. `<home>/web.json` written by alp web (`app: 'alp-web'`) becomes `<home>/dashboard.json`, keeping
18
+ * its token and credential id; one without `app` is the Paseo integration's identity and is left
19
+ * for the service to carry into paseo.json, as before.
20
+ * 4. `logs/integrations/alp-web.log` becomes `alp-dashboard.log`.
21
+ * 5. settings.json: `web.enabled`, `web.port` and `web.permissions` move to `dashboard.*`
22
+ * (`web.relay`, Paseo's, stays); see migrateDashboardSettings.
23
+ *
24
+ * Every step only moves an old name onto a missing new one, so a second run does nothing and a home
25
+ * that has both keeps the new one untouched (the old one is reported, never merged or deleted).
26
+ * Steps that race another `alp dashboard` lose cleanly: a rename or link that finds its source gone
27
+ * or its target present is skipped.
28
+ */
29
+
30
+ /** @param {string} file */
31
+ const exists = file => lstat(file).then(() => true, () => false);
32
+ /** A file's JSON, or undefined when it is missing or not JSON. @param {string} file */
33
+ const readJson = file => readFile(file, 'utf8').then(text => { try { return JSON.parse(text); } catch { return undefined; } }, () => undefined);
34
+ /** @param {unknown} error */
35
+ const code = error => /** @type {any} */ (error)?.code;
36
+
37
+ /**
38
+ * @param {string} home
39
+ * @param {{ strict?: boolean }} [options] strict: a legacy holder alp cannot stop is an error (a start
40
+ * would otherwise lose its port to it); without it, it is reported and the files are left alone.
41
+ * @returns {Promise<{ stopped?: number, held?: boolean, moved: string[], kept: string[], warnings: string[] }>}
42
+ * held: a legacy holder alp would not stop is still running (only without strict).
43
+ */
44
+ export async function migrateDashboard(home, { strict = false } = {}) {
45
+ /** @type {{ stopped?: number, held?: boolean, moved: string[], kept: string[], warnings: string[] }} */
46
+ const report = { moved: [], kept: [], warnings: [] };
47
+
48
+ // 1. The service from before the rename.
49
+ const owner = await serviceOwner(home, LEGACY_WEB);
50
+ if ('pid' in owner || (owner.alive && owner.kind === 'transient')) {
51
+ try { report.stopped = await stopService(home, 30_000, LEGACY_WEB); }
52
+ catch (error) {
53
+ if (strict) throw error;
54
+ report.warnings.push(/** @type {any} */ (error)?.message ?? String(error));
55
+ report.held = true;
56
+ return report;
57
+ }
58
+ } else if (owner.alive) {
59
+ const message = `${refusal(home, LEGACY_WEB)} (${owner.reason}); stop it, then run the command again`;
60
+ if (strict) throw new Error(message);
61
+ report.warnings.push(message);
62
+ report.held = true;
63
+ return report;
64
+ }
65
+
66
+ // 2. The credential store.
67
+ const oldStore = path.join(home, 'web');
68
+ const newStore = path.join(home, 'dashboard');
69
+ if (await exists(path.join(oldStore, 'credentials.json'))) {
70
+ if (await exists(newStore)) report.kept.push(oldStore);
71
+ else {
72
+ try { await rename(oldStore, newStore); report.moved.push(`${oldStore} -> ${newStore}`); }
73
+ catch (error) { if (!['ENOENT', 'EEXIST', 'ENOTEMPTY'].includes(code(error))) throw error; }
74
+ }
75
+ }
76
+
77
+ // 3. What the service published.
78
+ const oldInfo = path.join(home, LEGACY_WEB.info);
79
+ const newInfo = path.join(home, DASHBOARD.info);
80
+ const published = await readJson(oldInfo);
81
+ if (published?.app === LEGACY_WEB.app) {
82
+ // The same token in dashboard.json: this file was already carried (by an earlier or a concurrent
83
+ // run, or a crash after the link), so the old one is only a copy.
84
+ const carriedAlready = async () => typeof published.token === 'string' && published.token !== '' && (await readJson(newInfo))?.token === published.token;
85
+ const removeOld = () => unlink(oldInfo).catch(error => { if (code(error) !== 'ENOENT') throw error; });
86
+ if (await exists(newInfo)) {
87
+ if (await carriedAlready()) await removeOld();
88
+ else report.kept.push(oldInfo);
89
+ } else {
90
+ // Only what the next start reuses; the old pid, port and URL died with the old service.
91
+ const carried = { version: published.version, app: DASHBOARD.app, token: published.token, credentialId: published.credentialId };
92
+ const temporary = `${newInfo}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
93
+ try {
94
+ await writeFile(temporary, `${JSON.stringify(carried)}\n`, { mode: 0o600, flag: 'wx' });
95
+ await chmod(temporary, 0o600);
96
+ // A link never replaces: a dashboard.json written meanwhile wins, and the old file is
97
+ // removed only when that one carries the same token.
98
+ const linked = await link(temporary, newInfo).then(() => true, error => { if (code(error) !== 'EEXIST') throw error; return false; });
99
+ if (linked) { report.moved.push(`${oldInfo} -> ${newInfo}`); await removeOld(); }
100
+ else if (await carriedAlready()) await removeOld();
101
+ else report.kept.push(oldInfo);
102
+ } finally { await unlink(temporary).catch(() => {}); }
103
+ }
104
+ }
105
+
106
+ // 4. The service's log.
107
+ const logs = path.join(home, 'logs', 'integrations');
108
+ const oldLog = path.join(logs, 'alp-web.log');
109
+ const newLog = path.join(logs, 'alp-dashboard.log');
110
+ if (await exists(oldLog) && !(await exists(newLog))) {
111
+ await rename(oldLog, newLog).then(() => report.moved.push(`${oldLog} -> ${newLog}`), error => { if (code(error) !== 'ENOENT') throw error; });
112
+ }
113
+
114
+ // 5. Settings. A file alp cannot rewrite (invalid, read-only) is still obeyed: dashboardSettings
115
+ // reads `web.*` where `dashboard.*` is not set.
116
+ try {
117
+ const settings = await migrateDashboardSettings(home);
118
+ for (const key of settings.moved) report.moved.push(`settings.json web.${key} -> dashboard.${key}`);
119
+ for (const key of settings.conflicts) report.kept.push(`settings.json web.${key} (dashboard.${key} is set and wins)`);
120
+ } catch (error) {
121
+ report.warnings.push(`settings.json was not migrated (web.* is still read): ${/** @type {any} */ (error)?.message ?? error}`);
122
+ }
123
+ return report;
124
+ }
125
+
126
+ /**
127
+ * What a home still has under the names from before the rename, without changing anything (for
128
+ * `alp dashboard --status`): `pending` the next `alp dashboard` moves, `kept` it leaves because the
129
+ * new name exists, and the legacy service if one runs.
130
+ * @param {string} home
131
+ * @returns {Promise<{ legacy?: { pid?: number, reason?: string }, pending: string[], kept: string[] }>}
132
+ */
133
+ export async function legacyLeftovers(home) {
134
+ /** @type {{ legacy?: { pid?: number, reason?: string }, pending: string[], kept: string[] }} */
135
+ const result = { pending: [], kept: [] };
136
+ const owner = await serviceOwner(home, LEGACY_WEB);
137
+ if ('pid' in owner) result.legacy = { pid: owner.pid };
138
+ else if (owner.alive) result.legacy = { reason: owner.reason };
139
+ const place = async (/** @type {string} */ old, /** @type {string} */ current) => (await exists(current) ? result.kept : result.pending).push(old);
140
+ if (await exists(path.join(home, 'web', 'credentials.json'))) await place(path.join(home, 'web'), path.join(home, 'dashboard'));
141
+ const published = await readJson(path.join(home, LEGACY_WEB.info));
142
+ if (published?.app === LEGACY_WEB.app) await place(path.join(home, LEGACY_WEB.info), path.join(home, DASHBOARD.info));
143
+ const logs = path.join(home, 'logs', 'integrations');
144
+ if (await exists(path.join(logs, 'alp-web.log'))) await place(path.join(logs, 'alp-web.log'), path.join(logs, 'alp-dashboard.log'));
145
+ const settings = await readJson(path.join(home, 'settings.json'));
146
+ for (const key of ['enabled', 'port', 'permissions']) {
147
+ if (settings?.web?.[key] === undefined) continue;
148
+ if (settings?.dashboard?.[key] !== undefined) result.kept.push(`settings.json web.${key} (dashboard.${key} is set and wins)`);
149
+ else result.pending.push(`settings.json web.${key}`);
150
+ }
151
+ return result;
152
+ }