@anhlp/alp-core 0.0.1-beta.8 → 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.
package/dist/bridges.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // packages/core/src/bridges.js
2
2
  import { createRequire } from "node:module";
3
- import { isExecutableName, stablePath } from "./packaged.js";
3
+ import { isExecutableName, nodeExecutable, stablePath } from "./packaged.js";
4
4
  var ACP_BRIDGE = `
5
5
  const net = require('node:net');
6
6
  const readline = require('node:readline');
@@ -79,7 +79,7 @@ function runBridge(kind) {
79
79
  }
80
80
  function bridgeCommand(kind) {
81
81
  if (!Object.hasOwn(BRIDGES, kind)) throw new Error(`Unknown bridge: ${kind}; expected acp or antigravity`);
82
- return { command: stablePath(process.execPath), args: ["-e", BRIDGES[kind]] };
82
+ return { command: stablePath(nodeExecutable()), args: ["-e", BRIDGES[kind]] };
83
83
  }
84
84
  function isBridgeArgs(kind, args, command = void 0) {
85
85
  if (!Array.isArray(args)) return false;
@@ -1,9 +1,19 @@
1
+ /** Registers this process as the native alpd. Only native-entry.ts calls it. @param {NativeDaemon} native */
2
+ export function registerNativeDaemon(native: NativeDaemon): void;
3
+ /** The native alpd's registration when this process is the native alpd, else undefined. @returns {NativeDaemon | undefined} */
4
+ export function nativeDaemon(): NativeDaemon | undefined;
1
5
  /**
2
6
  * The ALP bundle this Node belongs to, or undefined for any other Node (an npm install).
3
7
  * @param {string} [execPath]
4
8
  * @returns {BundleInfo | undefined}
5
9
  */
6
10
  export function bundleInfo(execPath?: string): BundleInfo | undefined;
11
+ /**
12
+ * The Node that runs JavaScript for this process: process.execPath, except in the native alpd, which
13
+ * cannot run a script (`spawn(execPath, [script])` would start alpd again, and `-e` is not evaluated):
14
+ * there it is the bundle's Node, or `node` on PATH for a native alpd outside a bundle.
15
+ */
16
+ export function nodeExecutable(): string;
7
17
  /**
8
18
  * `file` named through `<app>/current` when it lies inside this process's bundle and `current` points
9
19
  * at that bundle; otherwise `file` unchanged. For paths written to disk for later processes.
@@ -54,29 +64,52 @@ export function scriptCommand(script: string, args?: string[]): {
54
64
  args: string[];
55
65
  env?: Record<string, string>;
56
66
  };
57
- /** Where this process's own entry lives, for records that later processes read: `script`, through `current` in a bundle. @param {string} script */
67
+ /**
68
+ * Where this process's own entry lives, for records that later processes read: `script`, through
69
+ * `current` in a bundle; the native alpd's own executable in the native alpd.
70
+ * @param {string} script
71
+ */
58
72
  export function selfEntry(script: string): string;
59
73
  /**
60
- * How ALP starts its own processes, and where its bundle lives. ALP always runs under Node: from npm
61
- * (`node cli.js`, `node alpd.js`) or from the ALP bundle (t-1807), which is the same npm install
62
- * beside an official Node release, started by `bin/alp`:
63
- *
64
- * <app>/<version>/{bin/alp, node/bin/node, lib/node_modules/@anhlp/alp-cli, alp-bundle.json}
65
- * <app>/current → <version> (install.sh and `alp update` move it)
66
- *
67
- * Paths that outlive this process (a launchd/systemd service, alpd's install record) name the bundle
68
- * through `current`, so an update never leaves them on a removed version.
74
+ * What starts alpd for this `alp`: the bundle's native alpd when the bundle ships one, else `script`
75
+ * (alpd.js), each named through `current`. ALP_NATIVE_DAEMON=0 keeps alpd on the bundle's Node.
76
+ * @param {string} script alpd.js
77
+ * @param {{ bundle?: BundleInfo | undefined, env?: NodeJS.ProcessEnv }} [options]
69
78
  */
70
- /** Subcommands of `alp` that run each ALP role in that process (`alp daemon run`, `alp web serve`, `alp bridge acp`). */
79
+ export function daemonEntry(script: string, { bundle, env }?: {
80
+ bundle?: BundleInfo | undefined;
81
+ env?: NodeJS.ProcessEnv;
82
+ }): string;
83
+ /** The native alpd's file name on this platform. */
84
+ export const NATIVE_DAEMON: "alpd.exe" | "alpd";
85
+ export function isNativeDaemonName(file: string): boolean;
86
+ export function isBundleDaemon(file: string): boolean;
87
+ /** Subcommands of `alp` that run each ALP role in that process (`alp daemon run`, `alp dashboard serve`, `alp bridge acp`). */
71
88
  export const ROLE_ARGS: Readonly<{
72
89
  daemon: readonly string[];
73
- web: readonly string[];
90
+ dashboard: readonly string[];
74
91
  'bridge-acp': readonly string[];
75
92
  'bridge-antigravity': readonly string[];
76
93
  }>;
77
94
  export function isExecutableName(file: string): boolean;
78
95
  export function isScript(file: string): boolean;
79
96
  export function samePath(a: string, b: string): boolean;
97
+ export function bundleNode(bundle: BundleInfo): string;
98
+ export function bundleDaemon(bundle: BundleInfo): string;
99
+ export function bundleDist(bundle: BundleInfo): string;
100
+ /**
101
+ * The native alpd (t-81b0.9): alpd compiled with `bun build --compile` into one executable, shipped as
102
+ * `<bundle>/bin/alpd` beside the bundle's Node. Only alpd is native; the `alp` CLI still runs on the
103
+ * bundle's Node. Its entry (packages/daemon/src/native-entry.ts) registers itself here before alpd loads:
104
+ * `modules` holds what alpd would otherwise import by a computed name (the Claude Agent SDK); `distDir`
105
+ * names the bundle's
106
+ */
107
+ export type NativeDaemon = {
108
+ modules: {
109
+ claudeAgentSdk?: () => Promise<any>;
110
+ };
111
+ distDir?: () => string | undefined;
112
+ };
80
113
  /**
81
114
  * root: the bundle directory (real path); app: its parent; current: `<app>/current` when it points at root.
82
115
  */
package/dist/packaged.js CHANGED
@@ -1,9 +1,22 @@
1
1
  // packages/core/src/packaged.js
2
2
  import { existsSync, readFileSync, realpathSync } from "node:fs";
3
3
  import path from "node:path";
4
+ var NATIVE = Symbol.for("alp.nativeDaemon");
5
+ function registerNativeDaemon(native) {
6
+ globalThis[NATIVE] = native;
7
+ }
8
+ function nativeDaemon() {
9
+ return (
10
+ /** @type {any} */
11
+ globalThis[NATIVE]
12
+ );
13
+ }
14
+ var NATIVE_DAEMON = process.platform === "win32" ? "alpd.exe" : "alpd";
15
+ var isNativeDaemonName = (file) => /^alpd(\.exe)?$/i.test(file.split(/[\\/]/).pop() ?? "");
16
+ var isBundleDaemon = (file) => isNativeDaemonName(file) && path.basename(path.dirname(file)) === "bin" && existsSync(path.join(path.dirname(path.dirname(file)), "alp-bundle.json"));
4
17
  var ROLE_ARGS = Object.freeze({
5
18
  daemon: Object.freeze(["daemon", "run"]),
6
- web: Object.freeze(["web", "serve"]),
19
+ dashboard: Object.freeze(["dashboard", "serve"]),
7
20
  "bridge-acp": Object.freeze(["bridge", "acp"]),
8
21
  "bridge-antigravity": Object.freeze(["bridge", "antigravity"])
9
22
  });
@@ -29,9 +42,10 @@ function bundleInfo(execPath = process.execPath) {
29
42
  let info;
30
43
  try {
31
44
  const real = realpathSync(execPath);
45
+ const native = isNativeDaemonName(real) && path.basename(path.dirname(real)) === "bin";
32
46
  const nodeDir = path.basename(path.dirname(real)) === "bin" ? path.dirname(path.dirname(real)) : path.dirname(real);
33
- const root = path.dirname(nodeDir);
34
- if (path.basename(nodeDir) === "node") {
47
+ const root = native ? nodeDir : path.dirname(nodeDir);
48
+ if (native || path.basename(nodeDir) === "node") {
35
49
  const manifest = JSON.parse(readFileSync(path.join(root, "alp-bundle.json"), "utf8"));
36
50
  if (manifest?.name === "alp" && typeof manifest.version === "string") {
37
51
  const app = path.dirname(root);
@@ -44,6 +58,14 @@ function bundleInfo(execPath = process.execPath) {
44
58
  bundles.set(execPath, info);
45
59
  return info;
46
60
  }
61
+ var bundleNode = (bundle) => path.join(bundle.root, "node", process.platform === "win32" ? "node.exe" : "bin/node");
62
+ var bundleDaemon = (bundle) => path.join(bundle.root, "bin", NATIVE_DAEMON);
63
+ var bundleDist = (bundle) => path.join(bundle.root, "lib", "node_modules", "@anhlp", "alp-cli", "dist");
64
+ function nodeExecutable() {
65
+ if (!nativeDaemon()) return process.execPath;
66
+ const bundle = bundleInfo();
67
+ return bundle ? bundleNode(bundle) : "node";
68
+ }
47
69
  function stablePath(file, { bundle = bundleInfo() } = {}) {
48
70
  if (!bundle?.current) return file;
49
71
  let real;
@@ -58,24 +80,43 @@ function stablePath(file, { bundle = bundleInfo() } = {}) {
58
80
  }
59
81
  function selfCommand(role, { script, args = [] }) {
60
82
  roleArgs(role);
83
+ if (nativeDaemon()) {
84
+ if (role !== "daemon") throw new Error(`The native alpd cannot start ALP's ${role}`);
85
+ return { command: process.execPath, args: [...args] };
86
+ }
61
87
  return { command: process.execPath, args: [script, ...args] };
62
88
  }
63
89
  function entryCommand(entry, role, args = [], execPath = process.execPath, { scriptOnly = false } = {}) {
90
+ if (!scriptOnly && role === "daemon" && isBundleDaemon(entry)) return { command: entry, args: [...args] };
64
91
  if (scriptOnly || isScript(entry) || !isExecutableName(entry)) return { command: execPath, args: [entry, ...args] };
65
92
  return { command: entry, args: [...roleArgs(role), ...args] };
66
93
  }
67
94
  function scriptCommand(script, args = []) {
68
- return { command: process.execPath, args: [script, ...args] };
95
+ return { command: nodeExecutable(), args: [script, ...args] };
69
96
  }
70
97
  function selfEntry(script) {
71
- return stablePath(script);
98
+ return stablePath(nativeDaemon() ? process.execPath : script);
99
+ }
100
+ function daemonEntry(script, { bundle = bundleInfo(), env = process.env } = {}) {
101
+ const native = bundle && env.ALP_NATIVE_DAEMON !== "0" ? bundleDaemon(bundle) : void 0;
102
+ return stablePath(native && existsSync(native) ? native : script, { bundle });
72
103
  }
73
104
  export {
105
+ NATIVE_DAEMON,
74
106
  ROLE_ARGS,
107
+ bundleDaemon,
108
+ bundleDist,
75
109
  bundleInfo,
110
+ bundleNode,
111
+ daemonEntry,
76
112
  entryCommand,
113
+ isBundleDaemon,
77
114
  isExecutableName,
115
+ isNativeDaemonName,
78
116
  isScript,
117
+ nativeDaemon,
118
+ nodeExecutable,
119
+ registerNativeDaemon,
79
120
  samePath,
80
121
  scriptCommand,
81
122
  selfCommand,
@@ -4,3 +4,5 @@ export function userLanguage(home?: string): Promise<string>;
4
4
  export function languageSetting(home: string): Promise<{ language: string | null; applies: string; default: string }>;
5
5
  export function setLanguage(home: string | undefined, language: string | null): Promise<{ language: string | null; applies: string; default: string }>;
6
6
  export function setWebRelay(home: string, patch: { enabled?: boolean; endpoint?: string; useTls?: boolean }): Promise<{ enabled?: boolean; endpoint?: string; useTls?: boolean }>;
7
+ export function dashboardSettings(settings: unknown): { enabled?: boolean; port?: number; permissions?: string[] };
8
+ export function migrateDashboardSettings(home: string): Promise<{ moved: string[]; conflicts: string[] }>;
@@ -4,7 +4,7 @@ import { moveFile } from "./atomic.js";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import path from "node:path";
6
6
  import { AlpError } from "./errors.js";
7
- import { validateUserSettings } from "./validation.js";
7
+ import { DASHBOARD_SETTINGS, validateUserSettings } from "./validation.js";
8
8
  var DEFAULT_LANGUAGE = "Vietnamese";
9
9
  var LANGUAGE_CHARS = 40;
10
10
  async function readSettings(home) {
@@ -62,10 +62,49 @@ async function setWebRelay(home, patch) {
62
62
  await moveFile(temporary, file);
63
63
  return next.web.relay;
64
64
  }
65
+ function dashboardSettings(settings) {
66
+ const now = settings?.dashboard ?? {};
67
+ const before = settings?.web ?? {};
68
+ const result = {};
69
+ for (const key of DASHBOARD_SETTINGS) {
70
+ const value = now[key] !== void 0 ? now[key] : before[key];
71
+ if (value !== void 0) result[key] = value;
72
+ }
73
+ return result;
74
+ }
75
+ async function migrateDashboardSettings(home) {
76
+ const { file, settings } = await readSettings(home);
77
+ const web = settings.web;
78
+ if (!web || typeof web !== "object") return { moved: [], conflicts: [] };
79
+ const moved = [], conflicts = [];
80
+ const dashboard = { ...settings.dashboard };
81
+ const rest = { ...web };
82
+ for (const key of DASHBOARD_SETTINGS) {
83
+ if (web[key] === void 0) continue;
84
+ if (dashboard[key] !== void 0) {
85
+ conflicts.push(key);
86
+ continue;
87
+ }
88
+ dashboard[key] = web[key];
89
+ delete rest[key];
90
+ moved.push(key);
91
+ }
92
+ if (!moved.length) return { moved, conflicts };
93
+ const next = { ...settings, dashboard };
94
+ if (Object.keys(rest).length) next.web = rest;
95
+ else delete next.web;
96
+ validateUserSettings(next, file);
97
+ const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
98
+ await writeFile(temporary, JSON.stringify(next, null, 2) + "\n", { mode: 384 });
99
+ await moveFile(temporary, file);
100
+ return { moved, conflicts };
101
+ }
65
102
  export {
66
103
  DEFAULT_LANGUAGE,
67
104
  LANGUAGE_CHARS,
105
+ dashboardSettings,
68
106
  languageSetting,
107
+ migrateDashboardSettings,
69
108
  setLanguage,
70
109
  setWebRelay,
71
110
  userLanguage
@@ -1,5 +1,6 @@
1
1
  export const PROJECT_SETTINGS: string[];
2
2
  export const USER_SETTINGS: string[];
3
+ export const DASHBOARD_SETTINGS: readonly string[];
3
4
  export const RETIRED_SETTINGS: { project: Record<string, string>; user: Record<string, string> };
4
5
  export function settingsKeys(settings: unknown, known: string[], retired?: Record<string, string>): { unknown: Array<{ key: string; suggestion?: string }>; retired: Array<{ key: string; instead: string }> };
5
6
  export function settingsWarnings(settings: unknown, scope: 'project' | 'user'): string[];
@@ -11,7 +11,8 @@ function requireValue(condition, code, source, message) {
11
11
  if (!condition) throw new AlpError(code, `${source}: ${message}`);
12
12
  }
13
13
  var PROJECT_SETTINGS = ["$schema", "defaultAgent", "workflow", "runtime", "permissions", "verify", "delegation", "team", "profile", "templateDefaults", "compact", "curate"];
14
- var USER_SETTINGS = ["$schema", "language", "permissions", "limits", "recovery", "web", "curate"];
14
+ var USER_SETTINGS = ["$schema", "language", "permissions", "limits", "recovery", "dashboard", "web", "curate"];
15
+ var DASHBOARD_SETTINGS = Object.freeze(["enabled", "port", "permissions"]);
15
16
  var RETIRED_SETTINGS = { project: {}, user: {} };
16
17
  function distance(a, b) {
17
18
  const row = Array.from({ length: b.length + 1 }, (_, index) => index);
@@ -159,11 +160,18 @@ function validateUserSettings(settings, source) {
159
160
  check(!extra, `unsupported ${key} field '${extra}'; use autoResume`);
160
161
  if (settings[key].autoResume !== void 0) check(typeof settings[key].autoResume === "boolean", `${key}.autoResume must be true or false`);
161
162
  }
163
+ for (const key of ["dashboard", "web"]) {
164
+ const section = settings[key];
165
+ if (section === void 0) continue;
166
+ check(object(section), `${key} must be an object`);
167
+ const allowed = key === "web" ? [...DASHBOARD_SETTINGS, "relay"] : DASHBOARD_SETTINGS;
168
+ const extra = Object.keys(section).find((field) => !allowed.includes(field));
169
+ check(!extra, `unsupported ${key} field '${extra}'; use ${allowed.slice(0, -1).join(", ")} or ${allowed.at(-1)}`);
170
+ if (section.permissions !== void 0) check(Array.isArray(section.permissions) && section.permissions.every((entry) => typeof entry === "string" && /^[a-z][a-z.]*$/.test(entry)), `${key}.permissions must be a list of permission names, such as files.read`);
171
+ if (section.enabled !== void 0) check(typeof section.enabled === "boolean", `${key}.enabled must be true or false`);
172
+ if (section.port !== void 0) check(Number.isInteger(section.port) && section.port >= 1024 && section.port <= 65535, `${key}.port must be a port from 1024 to 65535`);
173
+ }
162
174
  if (settings.web !== void 0) {
163
- check(object(settings.web), "web must be an object");
164
- const extra = Object.keys(settings.web).find((field) => !["enabled", "port", "relay", "permissions"].includes(field));
165
- check(!extra, `unsupported web field '${extra}'; use enabled, port, relay or permissions`);
166
- if (settings.web.permissions !== void 0) check(Array.isArray(settings.web.permissions) && settings.web.permissions.every((entry) => typeof entry === "string" && /^[a-z][a-z.]*$/.test(entry)), "web.permissions must be a list of permission names, such as files.read");
167
175
  const relay = settings.web.relay;
168
176
  if (relay !== void 0) {
169
177
  check(object(relay), "web.relay must be an object");
@@ -173,8 +181,6 @@ function validateUserSettings(settings, source) {
173
181
  if (relay.endpoint !== void 0) check(typeof relay.endpoint === "string" && /^[a-z0-9.-]+:\d{1,5}$/i.test(relay.endpoint), "web.relay.endpoint must be host:port, such as relay.paseo.sh:443");
174
182
  if (relay.useTls !== void 0) check(typeof relay.useTls === "boolean", "web.relay.useTls must be true or false");
175
183
  }
176
- if (settings.web.enabled !== void 0) check(typeof settings.web.enabled === "boolean", "web.enabled must be true or false");
177
- if (settings.web.port !== void 0) check(Number.isInteger(settings.web.port) && settings.web.port >= 1024 && settings.web.port <= 65535, "web.port must be a port from 1024 to 65535");
178
184
  }
179
185
  if (settings.language !== void 0) check(nonempty(settings.language) && settings.language.trim().length <= 40, "language must be a language name of at most 40 characters, such as Vietnamese or English");
180
186
  validatePermissions(settings.permissions, source);
@@ -293,6 +299,7 @@ export {
293
299
  AGENT_SETTINGS,
294
300
  BLOCKING_HOOK_EVENTS,
295
301
  CONTEXT_TOKENS,
302
+ DASHBOARD_SETTINGS,
296
303
  HOOK_EVENTS,
297
304
  HOOK_SETTINGS,
298
305
  PROJECT_SETTINGS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anhlp/alp-core",
3
- "version": "0.0.1-beta.8",
3
+ "version": "0.0.1-beta.9",
4
4
  "type": "module",
5
5
  "description": "ALP core module",
6
6
  "files": [
@@ -316,7 +316,7 @@
316
316
  "node": ">=22.12"
317
317
  },
318
318
  "dependencies": {
319
- "@anhlp/alp-protocol": "0.0.1-beta.8"
319
+ "@anhlp/alp-protocol": "0.0.1-beta.9"
320
320
  },
321
321
  "scripts": {
322
322
  "build": "node ../../scripts/build-workspace.mjs core",
package/src/bridges.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'node:module';
2
- import { isExecutableName, stablePath } from './packaged.js';
2
+ import { isExecutableName, nodeExecutable, stablePath } from './packaged.js';
3
3
 
4
4
  /**
5
5
  * The stdio MCP bridges an agent CLI starts to reach alpd's tools (ACP agents and Antigravity).
@@ -94,7 +94,8 @@ export function runBridge(kind) {
94
94
  export function bridgeCommand(kind) {
95
95
  if (!Object.hasOwn(BRIDGES, kind)) throw new Error(`Unknown bridge: ${kind}; expected acp or antigravity`);
96
96
  // Agents keep this command in their MCP configuration: name the ALP bundle's Node through app/current.
97
- return { command: stablePath(process.execPath), args: ['-e', BRIDGES[kind]] };
97
+ // In the native alpd (t-81b0.9) that is still the bundle's Node: the native alpd does not evaluate -e.
98
+ return { command: stablePath(nodeExecutable()), args: ['-e', BRIDGES[kind]] };
98
99
  }
99
100
 
100
101
  /**
package/src/packaged.js CHANGED
@@ -13,10 +13,35 @@ import path from 'node:path';
13
13
  * through `current`, so an update never leaves them on a removed version.
14
14
  */
15
15
 
16
- /** Subcommands of `alp` that run each ALP role in that process (`alp daemon run`, `alp web serve`, `alp bridge acp`). */
16
+ /**
17
+ * The native alpd (t-81b0.9): alpd compiled with `bun build --compile` into one executable, shipped as
18
+ * `<bundle>/bin/alpd` beside the bundle's Node. Only alpd is native; the `alp` CLI still runs on the
19
+ * bundle's Node. Its entry (packages/daemon/src/native-entry.ts) registers itself here before alpd loads:
20
+ * `modules` holds what alpd would otherwise import by a computed name (the Claude Agent SDK); `distDir`
21
+ * names the bundle's @anhlp/alp-cli dist, where the terminal helper is (undefined outside a bundle).
22
+ * @typedef {{ modules: { claudeAgentSdk?: () => Promise<any> }, distDir?: () => string | undefined }} NativeDaemon
23
+ */
24
+ const NATIVE = Symbol.for('alp.nativeDaemon');
25
+
26
+ /** Registers this process as the native alpd. Only native-entry.ts calls it. @param {NativeDaemon} native */
27
+ export function registerNativeDaemon(native) { /** @type {any} */ (globalThis)[NATIVE] = native; }
28
+
29
+ /** The native alpd's registration when this process is the native alpd, else undefined. @returns {NativeDaemon | undefined} */
30
+ export function nativeDaemon() { return /** @type {any} */ (globalThis)[NATIVE]; }
31
+
32
+ /** The native alpd's file name on this platform. */
33
+ export const NATIVE_DAEMON = process.platform === 'win32' ? 'alpd.exe' : 'alpd';
34
+
35
+ /** Whether `file` is named like the native alpd (alpd, alpd.exe). @param {string} file */
36
+ export const isNativeDaemonName = file => /^alpd(\.exe)?$/i.test(file.split(/[\\/]/).pop() ?? '');
37
+
38
+ /** Whether `file` is an ALP bundle's native alpd: `<bundle>/bin/alpd` beside alp-bundle.json. @param {string} file */
39
+ export const isBundleDaemon = file => isNativeDaemonName(file) && path.basename(path.dirname(file)) === 'bin' && existsSync(path.join(path.dirname(path.dirname(file)), 'alp-bundle.json'));
40
+
41
+ /** Subcommands of `alp` that run each ALP role in that process (`alp daemon run`, `alp dashboard serve`, `alp bridge acp`). */
17
42
  export const ROLE_ARGS = Object.freeze({
18
43
  daemon: Object.freeze(['daemon', 'run']),
19
- web: Object.freeze(['web', 'serve']),
44
+ dashboard: Object.freeze(['dashboard', 'serve']),
20
45
  'bridge-acp': Object.freeze(['bridge', 'acp']),
21
46
  'bridge-antigravity': Object.freeze(['bridge', 'antigravity']),
22
47
  });
@@ -66,10 +91,11 @@ export function bundleInfo(execPath = process.execPath) {
66
91
  let info;
67
92
  try {
68
93
  const real = realpathSync(execPath);
69
- // node/bin/node on macOS and Linux, node/node.exe on Windows.
94
+ // node/bin/node on macOS and Linux, node/node.exe on Windows; or the native alpd, bin/alpd.
95
+ const native = isNativeDaemonName(real) && path.basename(path.dirname(real)) === 'bin';
70
96
  const nodeDir = path.basename(path.dirname(real)) === 'bin' ? path.dirname(path.dirname(real)) : path.dirname(real);
71
- const root = path.dirname(nodeDir);
72
- if (path.basename(nodeDir) === 'node') {
97
+ const root = native ? nodeDir : path.dirname(nodeDir);
98
+ if (native || path.basename(nodeDir) === 'node') {
73
99
  const manifest = JSON.parse(readFileSync(path.join(root, 'alp-bundle.json'), 'utf8'));
74
100
  if (manifest?.name === 'alp' && typeof manifest.version === 'string') {
75
101
  const app = path.dirname(root);
@@ -82,6 +108,26 @@ export function bundleInfo(execPath = process.execPath) {
82
108
  return info;
83
109
  }
84
110
 
111
+ /** The bundle's own Node executable. @param {BundleInfo} bundle */
112
+ export const bundleNode = bundle => path.join(bundle.root, 'node', process.platform === 'win32' ? 'node.exe' : 'bin/node');
113
+
114
+ /** The bundle's native alpd, whether or not it exists. @param {BundleInfo} bundle */
115
+ export const bundleDaemon = bundle => path.join(bundle.root, 'bin', NATIVE_DAEMON);
116
+
117
+ /** Where @anhlp/alp-cli's dist lies in the bundle (alpd.js, the terminal helper). @param {BundleInfo} bundle */
118
+ export const bundleDist = bundle => path.join(bundle.root, 'lib', 'node_modules', '@anhlp', 'alp-cli', 'dist');
119
+
120
+ /**
121
+ * The Node that runs JavaScript for this process: process.execPath, except in the native alpd, which
122
+ * cannot run a script (`spawn(execPath, [script])` would start alpd again, and `-e` is not evaluated):
123
+ * there it is the bundle's Node, or `node` on PATH for a native alpd outside a bundle.
124
+ */
125
+ export function nodeExecutable() {
126
+ if (!nativeDaemon()) return process.execPath;
127
+ const bundle = bundleInfo();
128
+ return bundle ? bundleNode(bundle) : 'node';
129
+ }
130
+
85
131
  /**
86
132
  * `file` named through `<app>/current` when it lies inside this process's bundle and `current` points
87
133
  * at that bundle; otherwise `file` unchanged. For paths written to disk for later processes.
@@ -105,6 +151,11 @@ export function stablePath(file, { bundle = bundleInfo() } = {}) {
105
151
  */
106
152
  export function selfCommand(role, { script, args = [] }) {
107
153
  roleArgs(role);
154
+ // The native alpd is its own entry: it starts itself with its options only, never a script path.
155
+ if (nativeDaemon()) {
156
+ if (role !== 'daemon') throw new Error(`The native alpd cannot start ALP's ${role}`);
157
+ return { command: process.execPath, args: [...args] };
158
+ }
108
159
  return { command: process.execPath, args: [script, ...args] };
109
160
  }
110
161
 
@@ -120,6 +171,9 @@ export function selfCommand(role, { script, args = [] }) {
120
171
  * @returns {{ command: string, args: string[] }}
121
172
  */
122
173
  export function entryCommand(entry, role, args = [], execPath = process.execPath, { scriptOnly = false } = {}) {
174
+ // The native alpd (t-81b0.9) runs on its own, with alpd's options: only a bundle's bin/alpd, so an
175
+ // extensionless script named alpd (an npm .bin shim, a source checkout) still runs under execPath.
176
+ if (!scriptOnly && role === 'daemon' && isBundleDaemon(entry)) return { command: entry, args: [...args] };
123
177
  if (scriptOnly || isScript(entry) || !isExecutableName(entry)) return { command: execPath, args: [entry, ...args] };
124
178
  return { command: entry, args: [...roleArgs(role), ...args] };
125
179
  }
@@ -131,8 +185,23 @@ export function entryCommand(entry, role, args = [], execPath = process.execPath
131
185
  * @returns {{ command: string, args: string[], env?: Record<string, string> }}
132
186
  */
133
187
  export function scriptCommand(script, args = []) {
134
- return { command: process.execPath, args: [script, ...args] };
188
+ return { command: nodeExecutable(), args: [script, ...args] };
135
189
  }
136
190
 
137
- /** Where this process's own entry lives, for records that later processes read: `script`, through `current` in a bundle. @param {string} script */
138
- export function selfEntry(script) { return stablePath(script); }
191
+ /**
192
+ * Where this process's own entry lives, for records that later processes read: `script`, through
193
+ * `current` in a bundle; the native alpd's own executable in the native alpd.
194
+ * @param {string} script
195
+ */
196
+ export function selfEntry(script) { return stablePath(nativeDaemon() ? process.execPath : script); }
197
+
198
+ /**
199
+ * What starts alpd for this `alp`: the bundle's native alpd when the bundle ships one, else `script`
200
+ * (alpd.js), each named through `current`. ALP_NATIVE_DAEMON=0 keeps alpd on the bundle's Node.
201
+ * @param {string} script alpd.js
202
+ * @param {{ bundle?: BundleInfo | undefined, env?: NodeJS.ProcessEnv }} [options]
203
+ */
204
+ export function daemonEntry(script, { bundle = bundleInfo(), env = process.env } = {}) {
205
+ const native = bundle && env.ALP_NATIVE_DAEMON !== '0' ? bundleDaemon(bundle) : undefined;
206
+ return stablePath(native && existsSync(native) ? native : script, { bundle });
207
+ }
@@ -4,3 +4,5 @@ export function userLanguage(home?: string): Promise<string>;
4
4
  export function languageSetting(home: string): Promise<{ language: string | null; applies: string; default: string }>;
5
5
  export function setLanguage(home: string | undefined, language: string | null): Promise<{ language: string | null; applies: string; default: string }>;
6
6
  export function setWebRelay(home: string, patch: { enabled?: boolean; endpoint?: string; useTls?: boolean }): Promise<{ enabled?: boolean; endpoint?: string; useTls?: boolean }>;
7
+ export function dashboardSettings(settings: unknown): { enabled?: boolean; port?: number; permissions?: string[] };
8
+ export function migrateDashboardSettings(home: string): Promise<{ moved: string[]; conflicts: string[] }>;
@@ -3,7 +3,7 @@ import { moveFile } from './atomic.js';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import path from 'node:path';
5
5
  import { AlpError } from './errors.js';
6
- import { validateUserSettings } from './validation.js';
6
+ import { DASHBOARD_SETTINGS, validateUserSettings } from './validation.js';
7
7
 
8
8
  /**
9
9
  * The user's own settings in $ALP_HOME/settings.json that ALP and its screens edit
@@ -74,3 +74,53 @@ export async function setWebRelay(home, patch) {
74
74
  await moveFile(temporary, file);
75
75
  return next.web.relay;
76
76
  }
77
+
78
+ /**
79
+ * alp dashboard's settings (enabled, port, permissions): `dashboard.*` first, then the `web.*` they
80
+ * had before the rename (t-81b0.5), so a file not yet migrated is still obeyed rather than ignored.
81
+ * @param {any} settings
82
+ * @returns {{ enabled?: boolean, port?: number, permissions?: string[] }}
83
+ */
84
+ export function dashboardSettings(settings) {
85
+ const now = settings?.dashboard ?? {};
86
+ const before = settings?.web ?? {};
87
+ /** @type {any} */
88
+ const result = {};
89
+ for (const key of DASHBOARD_SETTINGS) {
90
+ const value = now[key] !== undefined ? now[key] : before[key];
91
+ if (value !== undefined) result[key] = value;
92
+ }
93
+ return result;
94
+ }
95
+
96
+ /**
97
+ * Moves alp dashboard's settings from `web` (before the rename, t-81b0.5) to `dashboard` in
98
+ * settings.json, keeping everything else, `web.relay` (Paseo's) included. A key `dashboard` already
99
+ * sets wins: the `web` one is left in place and reported, never merged over it. Idempotent: a file
100
+ * with nothing to move is not written. Returns what it moved and what it left.
101
+ * @param {string} home
102
+ * @returns {Promise<{ moved: string[], conflicts: string[] }>}
103
+ */
104
+ export async function migrateDashboardSettings(home) {
105
+ const { file, settings } = await readSettings(home);
106
+ const web = settings.web;
107
+ if (!web || typeof web !== 'object') return { moved: [], conflicts: [] };
108
+ const moved = [], conflicts = [];
109
+ const dashboard = { ...settings.dashboard };
110
+ const rest = { ...web };
111
+ for (const key of DASHBOARD_SETTINGS) {
112
+ if (web[key] === undefined) continue;
113
+ if (dashboard[key] !== undefined) { conflicts.push(key); continue; }
114
+ dashboard[key] = web[key];
115
+ delete rest[key];
116
+ moved.push(key);
117
+ }
118
+ if (!moved.length) return { moved, conflicts };
119
+ const next = { ...settings, dashboard };
120
+ if (Object.keys(rest).length) next.web = rest; else delete next.web;
121
+ validateUserSettings(next, file);
122
+ const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
123
+ await writeFile(temporary, JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
124
+ await moveFile(temporary, file);
125
+ return { moved, conflicts };
126
+ }
@@ -1,5 +1,6 @@
1
1
  export const PROJECT_SETTINGS: string[];
2
2
  export const USER_SETTINGS: string[];
3
+ export const DASHBOARD_SETTINGS: readonly string[];
3
4
  export const RETIRED_SETTINGS: { project: Record<string, string>; user: Record<string, string> };
4
5
  export function settingsKeys(settings: unknown, known: string[], retired?: Record<string, string>): { unknown: Array<{ key: string; suggestion?: string }>; retired: Array<{ key: string; instead: string }> };
5
6
  export function settingsWarnings(settings: unknown, scope: 'project' | 'user'): string[];
package/src/validation.js CHANGED
@@ -14,7 +14,9 @@ function requireValue(condition, code, source, message) {
14
14
  /** Top-level keys of a project's .alp/settings.json. */
15
15
  export const PROJECT_SETTINGS = ['$schema', 'defaultAgent', 'workflow', 'runtime', 'permissions', 'verify', 'delegation', 'team', 'profile', 'templateDefaults', 'compact', 'curate'];
16
16
  /** Top-level keys of the user's $ALP_HOME/settings.json. */
17
- export const USER_SETTINGS = ['$schema', 'language', 'permissions', 'limits', 'recovery', 'web', 'curate'];
17
+ export const USER_SETTINGS = ['$schema', 'language', 'permissions', 'limits', 'recovery', 'dashboard', 'web', 'curate'];
18
+ /** The settings of `alp dashboard`; before the rename (t-81b0.5) they lived under `web`, which still holds Paseo's relay. */
19
+ export const DASHBOARD_SETTINGS = Object.freeze(['enabled', 'port', 'permissions']);
18
20
  /**
19
21
  * Top-level keys ALP no longer reads, with what to use instead. They warn rather than
20
22
  * fail, so settings written for an older ALP keep working.
@@ -182,12 +184,22 @@ export function validateUserSettings(settings, source) {
182
184
  check(!extra, `unsupported ${key} field '${extra}'; use autoResume`);
183
185
  if (settings[key].autoResume !== undefined) check(typeof settings[key].autoResume === 'boolean', `${key}.autoResume must be true or false`);
184
186
  }
187
+ // `dashboard` holds alp dashboard's settings. `web` keeps Paseo's relay, and still accepts the
188
+ // dashboard settings written before the rename (alp dashboard moves them, then reads them from
189
+ // `dashboard` first and `web` second), so a file written for an older release stays valid.
190
+ for (const key of ['dashboard', 'web']) {
191
+ const section = settings[key];
192
+ if (section === undefined) continue;
193
+ check(object(section), `${key} must be an object`);
194
+ const allowed = key === 'web' ? [...DASHBOARD_SETTINGS, 'relay'] : DASHBOARD_SETTINGS;
195
+ const extra = Object.keys(section).find(field => !allowed.includes(field));
196
+ check(!extra, `unsupported ${key} field '${extra}'; use ${allowed.slice(0, -1).join(', ')} or ${allowed.at(-1)}`);
197
+ // Gateway permissions `alp dashboard` adds to its default grant; the service checks each name against the gateway's list.
198
+ if (section.permissions !== undefined) check(Array.isArray(section.permissions) && section.permissions.every(entry => typeof entry === 'string' && /^[a-z][a-z.]*$/.test(entry)), `${key}.permissions must be a list of permission names, such as files.read`);
199
+ if (section.enabled !== undefined) check(typeof section.enabled === 'boolean', `${key}.enabled must be true or false`);
200
+ if (section.port !== undefined) check(Number.isInteger(section.port) && section.port >= 1024 && section.port <= 65535, `${key}.port must be a port from 1024 to 65535`);
201
+ }
185
202
  if (settings.web !== undefined) {
186
- check(object(settings.web), 'web must be an object');
187
- const extra = Object.keys(settings.web).find(field => !['enabled', 'port', 'relay', 'permissions'].includes(field));
188
- check(!extra, `unsupported web field '${extra}'; use enabled, port, relay or permissions`);
189
- // Gateway permissions `alp web` adds to its default grant; alp-web checks each name against the gateway's list.
190
- if (settings.web.permissions !== undefined) check(Array.isArray(settings.web.permissions) && settings.web.permissions.every(entry => typeof entry === 'string' && /^[a-z][a-z.]*$/.test(entry)), 'web.permissions must be a list of permission names, such as files.read');
191
203
  // The relay that lets Paseo's app reach alpd from another device (ALPD §64).
192
204
  const relay = settings.web.relay;
193
205
  if (relay !== undefined) {
@@ -198,8 +210,6 @@ export function validateUserSettings(settings, source) {
198
210
  if (relay.endpoint !== undefined) check(typeof relay.endpoint === 'string' && /^[a-z0-9.-]+:\d{1,5}$/i.test(relay.endpoint), 'web.relay.endpoint must be host:port, such as relay.paseo.sh:443');
199
211
  if (relay.useTls !== undefined) check(typeof relay.useTls === 'boolean', 'web.relay.useTls must be true or false');
200
212
  }
201
- if (settings.web.enabled !== undefined) check(typeof settings.web.enabled === 'boolean', 'web.enabled must be true or false');
202
- if (settings.web.port !== undefined) check(Number.isInteger(settings.web.port) && settings.web.port >= 1024 && settings.web.port <= 65535, 'web.port must be a port from 1024 to 65535');
203
213
  }
204
214
  if (settings.language !== undefined) check(nonempty(settings.language) && settings.language.trim().length <= 40, 'language must be a language name of at most 40 characters, such as Vietnamese or English');
205
215
  validatePermissions(settings.permissions, source);