@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/backup.js CHANGED
@@ -7,7 +7,7 @@ import { acquireDaemonLock, alpHome, assertPrivateDirectory, daemonPaths, lockAl
7
7
  import { daemonHeld, holdDaemon, releaseHold } from "@anhlp/alp-client/supervise";
8
8
  import { start, stop } from "./daemon.js";
9
9
  import { UsageError } from "./usage.js";
10
- var VERSION = true ? "0.0.1-beta.7" : "dev";
10
+ var VERSION = true ? "0.0.1-beta.9" : "dev";
11
11
  var BY = `alp ${VERSION}`;
12
12
  var size = (bytes) => bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : bytes >= 1024 ? `${(bytes / 1024).toFixed(1)} KB` : `${bytes} B`;
13
13
  var stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
@@ -1,10 +1,12 @@
1
1
  {
2
- "version": "0.0.1-beta.7",
2
+ "version": "0.0.1-beta.9",
3
3
  "entries": {
4
4
  "packages/cli/dist/alpd.js": {
5
5
  "inputs": [
6
+ "packages/client/src/acp-probe.js",
6
7
  "packages/client/src/index.js",
7
8
  "packages/client/src/ipc.js",
9
+ "packages/client/src/mcp-probe.js",
8
10
  "packages/client/src/portable.js",
9
11
  "packages/client/src/rpc/client.js",
10
12
  "packages/client/src/rpc/errors.js",
@@ -41,6 +43,7 @@
41
43
  "packages/core/src/resolver.js",
42
44
  "packages/core/src/safe-path.js",
43
45
  "packages/core/src/shell.js",
46
+ "packages/core/src/skill-validate.js",
44
47
  "packages/core/src/state-schema.js",
45
48
  "packages/core/src/task-rows.js",
46
49
  "packages/core/src/tasks.js",
@@ -63,6 +66,7 @@
63
66
  "packages/daemon/src/lifecycle.ts",
64
67
  "packages/daemon/src/lock.ts",
65
68
  "packages/daemon/src/main.ts",
69
+ "packages/daemon/src/model-catalog.ts",
66
70
  "packages/daemon/src/native-terminal.ts",
67
71
  "packages/daemon/src/operations.ts",
68
72
  "packages/daemon/src/registry.ts",
@@ -110,13 +114,15 @@
110
114
  "packages/runtime/src/runtime-context.ts",
111
115
  "packages/runtime/src/runtime.ts",
112
116
  "packages/runtime/src/session-config.ts",
117
+ "packages/runtime/src/skill-resources.ts",
113
118
  "packages/runtime/src/tool-detail.ts",
114
119
  "packages/runtime/src/tool-results.ts",
115
120
  "packages/runtime/src/tools.ts",
116
121
  "packages/runtime/src/transport.ts",
117
122
  "packages/runtime/src/usage.ts",
118
123
  "packages/runtime/src/workspace.ts",
119
- "packages/runtime/src/worktree-domain.ts"
124
+ "packages/runtime/src/worktree-domain.ts",
125
+ "packages/runtime/src/write-error.ts"
120
126
  ],
121
127
  "external": [
122
128
  "child_process",
@@ -159,8 +165,16 @@
159
165
  "packages/client/src/service.js",
160
166
  "packages/client/src/supervise.js",
161
167
  "packages/client/src/websocket.js",
168
+ "packages/core/src/atomic.js",
169
+ "packages/core/src/errors.js",
162
170
  "packages/core/src/log.js",
171
+ "packages/core/src/models.js",
163
172
  "packages/core/src/packaged.js",
173
+ "packages/core/src/permissions.js",
174
+ "packages/core/src/shell.js",
175
+ "packages/core/src/user-settings.js",
176
+ "packages/core/src/validation.js",
177
+ "packages/core/src/verify.js",
164
178
  "packages/protocol/src/index.ts",
165
179
  "packages/protocol/src/wire.js"
166
180
  ],
@@ -176,7 +190,7 @@
176
190
  "node:timers/promises"
177
191
  ]
178
192
  },
179
- "packages/cli/dist/alp-web.js": {
193
+ "packages/cli/dist/alp-dashboard.js": {
180
194
  "inputs": [
181
195
  "apps/gateway/src/config.js",
182
196
  "apps/gateway/src/connection.js",
@@ -187,9 +201,9 @@
187
201
  "apps/gateway/src/server.js",
188
202
  "apps/gateway/src/tickets.js",
189
203
  "apps/gateway/src/upstream.js",
190
- "packages/cli/src/web/grant.js",
191
- "packages/cli/src/web/main.js",
192
- "packages/cli/src/web/serve.js",
204
+ "packages/cli/src/dashboard/grant.js",
205
+ "packages/cli/src/dashboard/main.js",
206
+ "packages/cli/src/dashboard/serve.js",
193
207
  "packages/client/src/command.js",
194
208
  "packages/client/src/index.js",
195
209
  "packages/client/src/integration-lock.js",
@@ -208,6 +222,7 @@
208
222
  "packages/client/src/websocket.js",
209
223
  "packages/core/src/atomic.js",
210
224
  "packages/core/src/errors.js",
225
+ "packages/core/src/gate-ledger.js",
211
226
  "packages/core/src/library-edit.js",
212
227
  "packages/core/src/library.js",
213
228
  "packages/core/src/log.js",
@@ -218,8 +233,11 @@
218
233
  "packages/core/src/resolver.js",
219
234
  "packages/core/src/safe-path.js",
220
235
  "packages/core/src/shell.js",
236
+ "packages/core/src/skill-validate.js",
237
+ "packages/core/src/tasks.js",
221
238
  "packages/core/src/teams.js",
222
239
  "packages/core/src/template-path.js",
240
+ "packages/core/src/user-settings.js",
223
241
  "packages/core/src/validation.js",
224
242
  "packages/core/src/verify.js",
225
243
  "packages/protocol/src/contract-v1.js",
package/dist/cli.js CHANGED
@@ -4,14 +4,16 @@
4
4
  import { setup } from "@anhlp/alp-client/setup";
5
5
  import { alpHome } from "@anhlp/alp-client/index";
6
6
  import { scrubText } from "@anhlp/alp-core/log";
7
+ import { catalogModels, useLiveModels } from "@anhlp/alp-core/models";
7
8
  import { USAGE, UsageError } from "./usage.js";
8
9
  import { project, permissionsCommand, trustCommand, language, verify, doctor } from "./projects.js";
9
10
  import { daemon } from "./daemon.js";
10
11
  import { run, ps, attach, send, questions, answer, top, log, board, models, pause, resume, recall, interrupt, compact } from "./sessions.js";
11
- import { libraryCommand, editCommand, teamsCommand } from "./library.js";
12
+ import { libraryCommand, editCommand, teamsCommand, packsCommand, packCommand } from "./library.js";
12
13
  import { scheduleCommand } from "./schedules.js";
13
14
  import { tasksCommand, formulaCommand, taskCommand } from "./tasks.js";
14
- import { webCommand, acpCommand } from "./interfaces.js";
15
+ import { dashboardCommand, acpCommand } from "./interfaces.js";
16
+ import { desktopCommand } from "./desktop.js";
15
17
  import { backupCommand, restoreCommand } from "./backup.js";
16
18
  import { terminalCommand } from "./terminal.js";
17
19
  import { bridgeCommand } from "./roles.js";
@@ -19,7 +21,7 @@ import { selfUpdate } from "./self-update.js";
19
21
  import { bundleInfo } from "@anhlp/alp-core/packaged";
20
22
  import { connect, lockAlive, readLock } from "@anhlp/alp-client/index";
21
23
  function alpVersion() {
22
- return true ? "0.0.1-beta.7" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
24
+ return true ? "0.0.1-beta.9" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
23
25
  }
24
26
  async function runningDaemon() {
25
27
  const lock = await readLock(alpHome());
@@ -39,13 +41,14 @@ async function updateCommand(args2) {
39
41
  const code = await selfUpdate(args2, { bundle: bundleInfo(), version: alpVersion(), daemon: runningDaemon });
40
42
  if (code) process.exitCode = code;
41
43
  }
42
- var commands = { schedule: scheduleCommand, setup: (args2) => setup(args2, alpHome()), init: (args2) => project("init", args2), "update-template": (args2) => project("upgrade", args2), upgrade: (args2) => project("upgrade", args2), update: updateCommand, daemon, doctor, run, ps, top, attach, send, questions, answer, log, board, tasks: tasksCommand, task: taskCommand, formula: formulaCommand, permissions: permissionsCommand, agents: (args2) => libraryCommand("agents", args2), skills: (args2) => libraryCommand("skills", args2), mcp: (args2) => ["add", "rm", "mv", "cp", "test", "show", "edit"].includes(args2[0]) ? editCommand("mcp", args2) : libraryCommand("mcp", args2), hooks: (args2) => libraryCommand("hooks", args2), providers: (args2) => libraryCommand("providers", args2), provider: (args2) => editCommand("providers", args2), teams: teamsCommand, trust: trustCommand, agent: (args2) => editCommand("agents", args2), team: (args2) => editCommand("teams", args2), skill: (args2) => editCommand("skills", args2), hook: (args2) => editCommand("hooks", args2), verify, recall, pause, resume, language, models, interrupt, compact, acp: acpCommand, web: webCommand, backup: backupCommand, restore: restoreCommand, terminal: terminalCommand, bridge: bridgeCommand };
44
+ var commands = { schedule: scheduleCommand, setup: (args2) => setup(args2, alpHome()), init: (args2) => project("init", args2), "update-template": (args2) => project("upgrade", args2), upgrade: (args2) => project("upgrade", args2), update: updateCommand, daemon, doctor, run, ps, top, attach, send, questions, answer, log, board, tasks: tasksCommand, task: taskCommand, formula: formulaCommand, permissions: permissionsCommand, agents: (args2) => libraryCommand("agents", args2), skills: (args2) => libraryCommand("skills", args2), mcp: (args2) => ["add", "rm", "mv", "cp", "test", "show", "edit"].includes(args2[0]) ? editCommand("mcp", args2) : libraryCommand("mcp", args2), hooks: (args2) => libraryCommand("hooks", args2), providers: (args2) => libraryCommand("providers", args2), provider: (args2) => editCommand("providers", args2), teams: teamsCommand, packs: packsCommand, pack: packCommand, trust: trustCommand, agent: (args2) => editCommand("agents", args2), team: (args2) => editCommand("teams", args2), skill: (args2) => editCommand("skills", args2), hook: (args2) => editCommand("hooks", args2), verify, recall, pause, resume, language, models, interrupt, compact, acp: acpCommand, dashboard: dashboardCommand, desktop: desktopCommand, backup: backupCommand, restore: restoreCommand, terminal: terminalCommand, bridge: bridgeCommand };
43
45
  var [command, ...args] = process.argv.slice(2);
44
46
  try {
45
47
  if (command === "--version") {
46
48
  console.log(alpVersion());
47
49
  } else {
48
50
  if (!Object.hasOwn(commands, command)) throw new UsageError();
51
+ if (command !== "setup") useLiveModels(catalogModels(alpHome()));
49
52
  await commands[command](args);
50
53
  }
51
54
  } catch (error) {
package/dist/daemon.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export function built(): Promise<void>;
2
- /** Waits until an alpd for this home is ready; returns its socket. */
1
+ export function built(entry?: string): Promise<void>;
2
+ /** Waits until an alpd for this home is ready; returns its socket. Default wait: ALP_DAEMON_START_TIMEOUT_MS, else 60 s. */
3
3
  export function ready(timeoutMs?: number): Promise<any>;
4
4
  /** The installed service for this ALP_HOME, if any. */
5
5
  export function installed(): Promise<{
package/dist/daemon.js CHANGED
@@ -3,19 +3,19 @@ import { access } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { installedProgram, installService, serviceFor, uninstallService } from "@anhlp/alp-client/service";
5
5
  import { holdDaemon, startDaemon } from "@anhlp/alp-client/supervise";
6
- import { alpHome, connect, lockAlive, readLock, withDaemonLifecycle } from "@anhlp/alp-client/index";
6
+ import { alpHome, connect, daemonStartTimeoutMs, lockAlive, readLock, withDaemonLifecycle } from "@anhlp/alp-client/index";
7
7
  import { scrubText } from "@anhlp/alp-core/log";
8
8
  import { UsageError } from "./usage.js";
9
- import { DAEMON_ENTRY } from "./paths.js";
9
+ import { DAEMON_ENTRY, DAEMON_SCRIPT } from "./paths.js";
10
10
  import { runRole } from "./roles.js";
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
- async function ready(timeoutMs = 15e3) {
18
+ async function ready(timeoutMs = daemonStartTimeoutMs()) {
19
19
  const deadline = Date.now() + timeoutMs;
20
20
  while (Date.now() < deadline) {
21
21
  const lock = await readLock(alpHome());
@@ -48,8 +48,8 @@ async function stop() {
48
48
  }
49
49
  async function daemon([action, ...rest]) {
50
50
  if (action === "run") {
51
- await built();
52
- return runRole("daemon", DAEMON_ENTRY, rest);
51
+ await built(DAEMON_SCRIPT);
52
+ return runRole("daemon", DAEMON_SCRIPT, rest);
53
53
  }
54
54
  if (rest.length && !(action === "status" && rest.length === 1 && rest[0] === "--json")) throw new UsageError();
55
55
  if (action === "start") {
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @param {string} home
3
+ * @param {{ strict?: boolean }} [options] strict: a legacy holder alp cannot stop is an error (a start
4
+ * would otherwise lose its port to it); without it, it is reported and the files are left alone.
5
+ * @returns {Promise<{ stopped?: number, held?: boolean, moved: string[], kept: string[], warnings: string[] }>}
6
+ * held: a legacy holder alp would not stop is still running (only without strict).
7
+ */
8
+ export function migrateDashboard(home: string, { strict }?: {
9
+ strict?: boolean;
10
+ }): Promise<{
11
+ stopped?: number;
12
+ held?: boolean;
13
+ moved: string[];
14
+ kept: string[];
15
+ warnings: string[];
16
+ }>;
17
+ /**
18
+ * What a home still has under the names from before the rename, without changing anything (for
19
+ * `alp dashboard --status`): `pending` the next `alp dashboard` moves, `kept` it leaves because the
20
+ * new name exists, and the legacy service if one runs.
21
+ * @param {string} home
22
+ * @returns {Promise<{ legacy?: { pid?: number, reason?: string }, pending: string[], kept: string[] }>}
23
+ */
24
+ export function legacyLeftovers(home: string): Promise<{
25
+ legacy?: {
26
+ pid?: number;
27
+ reason?: string;
28
+ };
29
+ pending: string[];
30
+ kept: string[];
31
+ }>;
@@ -0,0 +1,127 @@
1
+ // packages/cli/src/dashboard-migrate.js
2
+ import { randomBytes } from "node:crypto";
3
+ import { chmod, link, lstat, readFile, rename, unlink, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { migrateDashboardSettings } from "@anhlp/alp-core/user-settings";
6
+ import { DASHBOARD, LEGACY_WEB, refusal, serviceOwner, stopService } from "./dashboard-service.js";
7
+ var exists = (file) => lstat(file).then(() => true, () => false);
8
+ var readJson = (file) => readFile(file, "utf8").then((text) => {
9
+ try {
10
+ return JSON.parse(text);
11
+ } catch {
12
+ return void 0;
13
+ }
14
+ }, () => void 0);
15
+ var code = (error) => (
16
+ /** @type {any} */
17
+ error?.code
18
+ );
19
+ async function migrateDashboard(home, { strict = false } = {}) {
20
+ const report = { moved: [], kept: [], warnings: [] };
21
+ const owner = await serviceOwner(home, LEGACY_WEB);
22
+ if ("pid" in owner || owner.alive && owner.kind === "transient") {
23
+ try {
24
+ report.stopped = await stopService(home, 3e4, LEGACY_WEB);
25
+ } catch (error) {
26
+ if (strict) throw error;
27
+ report.warnings.push(
28
+ /** @type {any} */
29
+ error?.message ?? String(error)
30
+ );
31
+ report.held = true;
32
+ return report;
33
+ }
34
+ } else if (owner.alive) {
35
+ const message = `${refusal(home, LEGACY_WEB)} (${owner.reason}); stop it, then run the command again`;
36
+ if (strict) throw new Error(message);
37
+ report.warnings.push(message);
38
+ report.held = true;
39
+ return report;
40
+ }
41
+ const oldStore = path.join(home, "web");
42
+ const newStore = path.join(home, "dashboard");
43
+ if (await exists(path.join(oldStore, "credentials.json"))) {
44
+ if (await exists(newStore)) report.kept.push(oldStore);
45
+ else {
46
+ try {
47
+ await rename(oldStore, newStore);
48
+ report.moved.push(`${oldStore} -> ${newStore}`);
49
+ } catch (error) {
50
+ if (!["ENOENT", "EEXIST", "ENOTEMPTY"].includes(code(error))) throw error;
51
+ }
52
+ }
53
+ }
54
+ const oldInfo = path.join(home, LEGACY_WEB.info);
55
+ const newInfo = path.join(home, DASHBOARD.info);
56
+ const published = await readJson(oldInfo);
57
+ if (published?.app === LEGACY_WEB.app) {
58
+ const carriedAlready = async () => typeof published.token === "string" && published.token !== "" && (await readJson(newInfo))?.token === published.token;
59
+ const removeOld = () => unlink(oldInfo).catch((error) => {
60
+ if (code(error) !== "ENOENT") throw error;
61
+ });
62
+ if (await exists(newInfo)) {
63
+ if (await carriedAlready()) await removeOld();
64
+ else report.kept.push(oldInfo);
65
+ } else {
66
+ const carried = { version: published.version, app: DASHBOARD.app, token: published.token, credentialId: published.credentialId };
67
+ const temporary = `${newInfo}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
68
+ try {
69
+ await writeFile(temporary, `${JSON.stringify(carried)}
70
+ `, { mode: 384, flag: "wx" });
71
+ await chmod(temporary, 384);
72
+ const linked = await link(temporary, newInfo).then(() => true, (error) => {
73
+ if (code(error) !== "EEXIST") throw error;
74
+ return false;
75
+ });
76
+ if (linked) {
77
+ report.moved.push(`${oldInfo} -> ${newInfo}`);
78
+ await removeOld();
79
+ } else if (await carriedAlready()) await removeOld();
80
+ else report.kept.push(oldInfo);
81
+ } finally {
82
+ await unlink(temporary).catch(() => {
83
+ });
84
+ }
85
+ }
86
+ }
87
+ const logs = path.join(home, "logs", "integrations");
88
+ const oldLog = path.join(logs, "alp-web.log");
89
+ const newLog = path.join(logs, "alp-dashboard.log");
90
+ if (await exists(oldLog) && !await exists(newLog)) {
91
+ await rename(oldLog, newLog).then(() => report.moved.push(`${oldLog} -> ${newLog}`), (error) => {
92
+ if (code(error) !== "ENOENT") throw error;
93
+ });
94
+ }
95
+ try {
96
+ const settings = await migrateDashboardSettings(home);
97
+ for (const key of settings.moved) report.moved.push(`settings.json web.${key} -> dashboard.${key}`);
98
+ for (const key of settings.conflicts) report.kept.push(`settings.json web.${key} (dashboard.${key} is set and wins)`);
99
+ } catch (error) {
100
+ report.warnings.push(`settings.json was not migrated (web.* is still read): ${/** @type {any} */
101
+ error?.message ?? error}`);
102
+ }
103
+ return report;
104
+ }
105
+ async function legacyLeftovers(home) {
106
+ const result = { pending: [], kept: [] };
107
+ const owner = await serviceOwner(home, LEGACY_WEB);
108
+ if ("pid" in owner) result.legacy = { pid: owner.pid };
109
+ else if (owner.alive) result.legacy = { reason: owner.reason };
110
+ const place = async (old, current) => (await exists(current) ? result.kept : result.pending).push(old);
111
+ if (await exists(path.join(home, "web", "credentials.json"))) await place(path.join(home, "web"), path.join(home, "dashboard"));
112
+ const published = await readJson(path.join(home, LEGACY_WEB.info));
113
+ if (published?.app === LEGACY_WEB.app) await place(path.join(home, LEGACY_WEB.info), path.join(home, DASHBOARD.info));
114
+ const logs = path.join(home, "logs", "integrations");
115
+ if (await exists(path.join(logs, "alp-web.log"))) await place(path.join(logs, "alp-web.log"), path.join(logs, "alp-dashboard.log"));
116
+ const settings = await readJson(path.join(home, "settings.json"));
117
+ for (const key of ["enabled", "port", "permissions"]) {
118
+ if (settings?.web?.[key] === void 0) continue;
119
+ if (settings?.dashboard?.[key] !== void 0) result.kept.push(`settings.json web.${key} (dashboard.${key} is set and wins)`);
120
+ else result.pending.push(`settings.json web.${key}`);
121
+ }
122
+ return result;
123
+ }
124
+ export {
125
+ legacyLeftovers,
126
+ migrateDashboard
127
+ };
@@ -0,0 +1,69 @@
1
+ /** The alp-dashboard service script beside this CLI; a clear error when this CLI was built without it. */
2
+ export function dashboardScript(): string;
3
+ /**
4
+ * The process that owns `service`'s lock, if it is proven safe to stop; else why not. `kind` says
5
+ * whether waiting can help: `transient` (an owner still starting has not published its file yet),
6
+ * `foreign` (proven not to be the integration: another user's, another boot's, or a reused pid) or
7
+ * `unknown` (it cannot be proven either way, for example without ps or on Windows).
8
+ *
9
+ * The reuse proof compares the lock's creation time with the process's start from ps: when
10
+ * `startedUptime` is recorded, monotonic uptime comparison prevents clock step vulnerabilities.
11
+ * For legacy locks, wall-clock `startedAt` is compared.
12
+ * @param {string} home @param {Service} [service]
13
+ * @returns {Promise<{ pid: number, app: unknown } | { reason: string, alive: boolean, kind?: 'transient' | 'foreign' | 'unknown' }>}
14
+ */
15
+ export function serviceOwner(home: string, service?: Service): Promise<{
16
+ pid: number;
17
+ app: unknown;
18
+ } | {
19
+ reason: string;
20
+ alive: boolean;
21
+ kind?: "transient" | "foreign" | "unknown";
22
+ }>;
23
+ /**
24
+ * Stops whatever runs as `service` (alp dashboard; for LEGACY_WEB, alp web from before the rename or
25
+ * the Paseo integration from before its own), waiting up to `timeoutMs` for a starting owner to
26
+ * publish what proves it. Resolves with the pid it stopped, or undefined once no live process owns
27
+ * the lock; refuses at once an owner that is foreign or cannot be proven.
28
+ * @param {string} home @param {number} [timeoutMs] @param {Service} [service]
29
+ */
30
+ export function stopService(home: string, timeoutMs?: number, service?: Service): Promise<number | undefined>;
31
+ /** The opening of the message for a lock held by a process alp would not stop. @param {string} home @param {Service} [service] */
32
+ export function refusal(home: string, service?: Service): string;
33
+ /**
34
+ * Probes whether the published dashboard URL is live and answering requests.
35
+ * Accepts only loopback HTTP/HTTPS addresses.
36
+ * @param {string | undefined} url
37
+ * @param {number} [timeoutMs]
38
+ */
39
+ export function isDashboardReady(url: string | undefined, timeoutMs?: number): Promise<boolean>;
40
+ /**
41
+ * Whether the published file is genuinely claimed by a live alp-dashboard process.
42
+ * If the process is proven foreign (e.g. a reused PID or from another boot) or
43
+ * the URL does not answer HTTP requests, it is never claimed.
44
+ * @param {any} published
45
+ * @param {number | undefined} lockPid
46
+ * @param {any} held
47
+ * @param {number} [timeoutMs]
48
+ */
49
+ export function isServiceClaimed(published: any, lockPid: number | undefined, held: any, timeoutMs?: number): Promise<boolean>;
50
+ export function dashboardEntry(): string;
51
+ /**
52
+ * @typedef {{ lock: string, info: string, app: string, what: string }} Service
53
+ * The integration lock's name, the file the service publishes, the `app` it writes there, and what
54
+ * messages call it.
55
+ */
56
+ /** @type {Service} */
57
+ export const DASHBOARD: Service;
58
+ /** alp web as 0.0.1-beta.8 and earlier ran it (and, before that, the Paseo integration). @type {Service} */
59
+ export const LEGACY_WEB: Service;
60
+ /**
61
+ * The integration lock's name, the file the service publishes, the `app` it writes there, and what
62
+ * messages call it.
63
+ */
64
+ export type Service = {
65
+ lock: string;
66
+ info: string;
67
+ app: string;
68
+ what: string;
69
+ };
@@ -1,4 +1,4 @@
1
- // packages/cli/src/web-service.js
1
+ // packages/cli/src/dashboard-service.js
2
2
  import { execFile } from "node:child_process";
3
3
  import { existsSync } from "node:fs";
4
4
  import { lstat, readFile } from "node:fs/promises";
@@ -11,12 +11,14 @@ import { distributionEntry } from "./paths.js";
11
11
  import { selfEntry } from "@anhlp/alp-core/packaged";
12
12
  var execFileAsync = promisify(execFile);
13
13
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
14
- function alpWebScript() {
15
- const entry = fileURLToPath(distributionEntry("alp-web.js"));
16
- if (!existsSync(entry)) throw new Error(`alp web is not built: ${entry} is missing. Build the CLI (npm run build in the ALP checkout) or reinstall ALP.`);
14
+ function dashboardScript() {
15
+ const entry = fileURLToPath(distributionEntry("alp-dashboard.js"));
16
+ if (!existsSync(entry)) throw new Error(`alp dashboard is not built: ${entry} is missing. Build the CLI (npm run build in the ALP checkout) or reinstall ALP.`);
17
17
  return entry;
18
18
  }
19
- var alpWebEntry = () => selfEntry(alpWebScript());
19
+ var dashboardEntry = () => selfEntry(dashboardScript());
20
+ var DASHBOARD = Object.freeze({ lock: "dashboard", info: "dashboard.json", app: "alp-dashboard", what: "alp dashboard" });
21
+ var LEGACY_WEB = Object.freeze({ lock: "web", info: "web.json", app: "alp-web", what: "alp web from before its rename to alp dashboard" });
20
22
  var readJson = async (file) => JSON.parse(await readFile(file, "utf8"));
21
23
  async function processTimes(pid) {
22
24
  try {
@@ -30,9 +32,9 @@ async function processTimes(pid) {
30
32
  return void 0;
31
33
  }
32
34
  }
33
- async function webOwner(home) {
34
- const lockFile = path.join(home, "integrations", "web.lock");
35
- const infoFile = path.join(home, "web.json");
35
+ async function serviceOwner(home, service = DASHBOARD) {
36
+ const lockFile = path.join(home, "integrations", `${service.lock}.lock`);
37
+ const infoFile = path.join(home, service.info);
36
38
  let lock, lockInfo;
37
39
  try {
38
40
  lockInfo = await lstat(lockFile);
@@ -90,31 +92,26 @@ async function terminate(pid, what, timeoutMs = 2e4) {
90
92
  }
91
93
  throw new Error(`${what} (pid ${pid}) did not stop within ${timeoutMs / 1e3} s of SIGTERM; stop it, then run the command again`);
92
94
  }
93
- var isAlpWeb = (app) => app === "alp-web";
94
95
  var PASEO_BEFORE_RENAME = "The Paseo integration from before its rename";
95
- async function stopPreRenamePaseo(home) {
96
- const owner = await webOwner(home);
97
- if (!("pid" in owner) || isAlpWeb(owner.app)) return void 0;
98
- await terminate(owner.pid, PASEO_BEFORE_RENAME);
99
- return owner.pid;
100
- }
101
- async function stopWebService(home, timeoutMs = 3e4) {
96
+ var ownerName = (service, app) => app === service.app || service === DASHBOARD ? service.what : PASEO_BEFORE_RENAME;
97
+ async function stopService(home, timeoutMs = 3e4, service = DASHBOARD) {
102
98
  const deadline = Date.now() + timeoutMs;
103
99
  for (; ; ) {
104
- const owner = await webOwner(home);
100
+ const owner = await serviceOwner(home, service);
105
101
  if ("pid" in owner) {
106
- await terminate(owner.pid, isAlpWeb(owner.app) ? "alp web" : PASEO_BEFORE_RENAME);
102
+ await terminate(owner.pid, ownerName(service, owner.app));
107
103
  return owner.pid;
108
104
  }
109
105
  if (!owner.alive) return void 0;
110
- if (owner.kind !== "transient" || Date.now() >= deadline) throw new Error(`${refusal(home)} (${owner.reason}); stop it, then run the command again`);
106
+ if (owner.kind !== "transient" || Date.now() >= deadline) throw new Error(`${refusal(home, service)} (${owner.reason}); stop it, then run the command again`);
111
107
  await sleep(200);
112
108
  }
113
109
  }
114
- function refusal(home) {
115
- return `${path.join(home, "integrations", "web.lock")} is held by a process that alp cannot prove is alp web or the Paseo integration from before its rename, so it was left running`;
110
+ function refusal(home, service = DASHBOARD) {
111
+ const lock = path.join(home, "integrations", `${service.lock}.lock`);
112
+ return service === DASHBOARD ? `${lock} is held by a process that alp cannot prove is alp dashboard, so it was left running` : `${lock} is held by a process that alp cannot prove is ${service.what} or the Paseo integration from before its rename, so it was left running`;
116
113
  }
117
- async function isWebReady(url, timeoutMs = 1e3) {
114
+ async function isDashboardReady(url, timeoutMs = 1e3) {
118
115
  if (typeof url !== "string" || !url) return false;
119
116
  try {
120
117
  const parsed = new URL(url);
@@ -126,18 +123,19 @@ async function isWebReady(url, timeoutMs = 1e3) {
126
123
  return false;
127
124
  }
128
125
  }
129
- async function isWebClaimed(published, lockPid, held, timeoutMs = 1e3) {
130
- if (published?.app !== "alp-web" || published.pid !== lockPid) return false;
126
+ async function isServiceClaimed(published, lockPid, held, timeoutMs = 1e3) {
127
+ if (published?.app !== DASHBOARD.app || published.pid !== lockPid) return false;
131
128
  if (held?.kind === "foreign") return false;
132
- return isWebReady(published.url, timeoutMs);
129
+ return isDashboardReady(published.url, timeoutMs);
133
130
  }
134
131
  export {
135
- alpWebEntry,
136
- alpWebScript,
137
- isWebClaimed,
138
- isWebReady,
132
+ DASHBOARD,
133
+ LEGACY_WEB,
134
+ dashboardEntry,
135
+ dashboardScript,
136
+ isDashboardReady,
137
+ isServiceClaimed,
139
138
  refusal,
140
- stopPreRenamePaseo,
141
- stopWebService,
142
- webOwner
139
+ serviceOwner,
140
+ stopService
143
141
  };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The CFBundleIdentifier of the app bundle at `app`, or undefined when it cannot be read. An XML
3
+ * Info.plist (what electron-builder writes) is read directly; any other form through plutil.
4
+ * @param {string} app
5
+ * @returns {Promise<string | undefined>}
6
+ */
7
+ export function readBundleId(app: string): Promise<string | undefined>;
8
+ /**
9
+ * Where the app is and how to start it. Exported for tests.
10
+ * `onSkip` hears about each ALP.app passed over because its bundle id is not DESKTOP_BUNDLE_ID.
11
+ * @param {{ platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv, applications?: string[], onSkip?: (message: string) => void }} [options]
12
+ * @returns {Promise<{ kind: 'app', app: string, command: string, args: string[] }
13
+ * | { kind: 'checkout', dir: string, command: string, args: string[] }
14
+ * | { kind: 'missing', reason?: string }>}
15
+ */
16
+ export function resolveDesktop({ platform, home, env, applications, onSkip }?: {
17
+ platform?: NodeJS.Platform;
18
+ home?: string;
19
+ env?: NodeJS.ProcessEnv;
20
+ applications?: string[];
21
+ onSkip?: (message: string) => void;
22
+ }): Promise<{
23
+ kind: "app";
24
+ app: string;
25
+ command: string;
26
+ args: string[];
27
+ } | {
28
+ kind: "checkout";
29
+ dir: string;
30
+ command: string;
31
+ args: string[];
32
+ } | {
33
+ kind: "missing";
34
+ reason?: string;
35
+ }>;
36
+ /**
37
+ * @param {string[]} args
38
+ * @param {{ resolve?: typeof resolveDesktop, launch?: (command: string, args: string[], env: NodeJS.ProcessEnv) => Promise<void> }} [deps]
39
+ */
40
+ export function desktopCommand(args: string[], { resolve, launch }?: {
41
+ resolve?: typeof resolveDesktop;
42
+ launch?: (command: string, args: string[], env: NodeJS.ProcessEnv) => Promise<void>;
43
+ }): Promise<void>;
44
+ /**
45
+ * alp desktop (t-81b0.5): opens ALP's desktop app (apps/desktop, an Electron shell for macOS). The
46
+ * app is looked for, in order:
47
+ * 1. ALP.app in /Applications, then in ~/Applications (macOS), opened with `open`. Only a bundle
48
+ * whose CFBundleIdentifier is DESKTOP_BUNDLE_ID counts: another app of that name (an older ALP
49
+ * desktop app, say) is skipped with a one-line message and the lookup goes on;
50
+ * 2. a checkout named by ALP_DESKTOP_CHECKOUT (the repository root, or its apps/desktop), whose
51
+ * app is built (`bun install && bun run build` in apps/desktop), run with its own Electron;
52
+ * 3. neither: how to get it, and exit 1.
53
+ * Nothing secret passes here: the app asks `alp dashboard --print` for its address itself.
54
+ */
55
+ /** The bundle id of the packaged app (apps/desktop/electron-builder.yml, appId). */
56
+ export const DESKTOP_BUNDLE_ID: "com.anhlp.alp.shell";