@anhlp/alp-client 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.
- package/README.md +1 -1
- package/dist/acp-probe.d.ts +3 -2
- package/dist/acp-probe.js +11 -2
- package/dist/antigravity-probe.d.ts +1 -1
- package/dist/doctor.d.ts +8 -1
- package/dist/doctor.js +180 -11
- package/dist/index.d.ts +22 -8
- package/dist/index.js +89 -32
- package/dist/render.js +3 -0
- package/dist/service.d.ts +2 -2
- package/dist/setup.d.ts +7 -1
- package/dist/setup.js +154 -29
- package/dist/supervise.js +2 -2
- package/package.json +3 -3
- package/src/acp-probe.js +10 -3
- package/src/antigravity-probe.js +1 -1
- package/src/doctor.d.ts +8 -1
- package/src/doctor.js +248 -11
- package/src/index.js +119 -50
- package/src/integration-lock.js +1 -1
- package/src/render.js +3 -0
- package/src/service.js +2 -2
- package/src/setup.js +194 -31
- package/src/supervise.js +5 -4
package/src/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
2
|
import { execFileSync, spawn } from 'node:child_process';
|
|
3
3
|
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
-
import { readFileSync } from 'node:fs';
|
|
5
|
-
import { open, readFile, writeFile, realpath, stat, lstat, mkdir, readlink, unlink, readdir, rename, rmdir, link } from 'node:fs/promises';
|
|
4
|
+
import { fstatSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { open, readFile, writeFile, realpath, stat, lstat, mkdir, readlink, unlink, readdir, chmod, rename, rmdir, link } from 'node:fs/promises';
|
|
6
6
|
import net from 'node:net';
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
|
|
10
10
|
import { scrubText } from '@anhlp/alp-core/log';
|
|
11
|
-
import { entryCommand } from '@anhlp/alp-core/packaged';
|
|
11
|
+
import { entryCommand, isNativeDaemonName, NATIVE_DAEMON } from '@anhlp/alp-core/packaged';
|
|
12
|
+
import { dashboardSettings } from '@anhlp/alp-core/user-settings';
|
|
12
13
|
import { createSocketTransport } from './ipc.js';
|
|
13
14
|
import { AlpRpcClient } from './rpc/client.js';
|
|
14
15
|
import { hello } from './rpc/handshake.js';
|
|
@@ -70,11 +71,24 @@ async function assertSafeAncestors(directory) {
|
|
|
70
71
|
export async function assertPrivateDirectory(directory, { create = false } = {}) {
|
|
71
72
|
await assertSafeAncestors(directory);
|
|
72
73
|
if (create) await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
73
|
-
|
|
74
|
+
let info = await lstat(directory);
|
|
74
75
|
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('IPC requires a private directory, not a symlink');
|
|
75
|
-
if (process.platform
|
|
76
|
-
|
|
76
|
+
if (process.platform === 'win32') return;
|
|
77
|
+
const shown = JSON.stringify(directory);
|
|
78
|
+
const mine = (/** @type {import('node:fs').Stats} */ entry) => entry.isDirectory() && !entry.isSymbolicLink() && entry.uid === process.getuid?.();
|
|
79
|
+
if (info.uid !== process.getuid?.()) throw new Error(`IPC directory ${shown} must be owned by the current user (it belongs to uid ${info.uid}); use a directory of your own`);
|
|
80
|
+
if ((info.mode & 0o077) === 0) return;
|
|
81
|
+
// t-37f1: a directory the user made for ALP (mkdir, mktemp) and left at 0755 is still empty:
|
|
82
|
+
// ALP tightens it. One that holds anything is left alone, with the exact command to fix it.
|
|
83
|
+
if (create && (await readdir(directory)).length === 0) {
|
|
84
|
+
await chmod(directory, 0o700).catch(() => {});
|
|
77
85
|
}
|
|
86
|
+
// Re-read: another ALP process may have tightened it meanwhile (and filled it).
|
|
87
|
+
info = await lstat(directory);
|
|
88
|
+
if (mine(info) && (info.mode & 0o077) === 0) return;
|
|
89
|
+
// Single quotes, so the command is safe to paste into a POSIX shell.
|
|
90
|
+
const quoted = `'${directory.replaceAll("'", "'\\''")}'`;
|
|
91
|
+
throw new Error(`IPC directory ${shown} must have private permissions (0700), not ${(info.mode & 0o777).toString(8).padStart(4, '0')}; fix it with: chmod 700 ${quoted}`);
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
export async function assertPrivateSocket(socketPath) {
|
|
@@ -96,23 +110,37 @@ const BIN_DIRECTORIES = [path.join(os.homedir(), '.alp', 'bin'), path.join(os.ho
|
|
|
96
110
|
const CLI_PACKAGES = ['@anhlp/alp', '@anhlp/alp-cli'];
|
|
97
111
|
|
|
98
112
|
/**
|
|
99
|
-
* alpd
|
|
100
|
-
* (<bundle>/bin/alp or alp.cmd, t-1807), npm's @anhlp/alp-cli (dist/cli.js) or the @anhlp/alp wrapper (bin/alp.js),
|
|
101
|
-
* which depends on @anhlp/alp-cli (installed beside it, or in its own node_modules).
|
|
102
|
-
*
|
|
113
|
+
* alpd behind an `alp` found on PATH (its real path), or undefined: the ALP bundle's launcher
|
|
114
|
+
* (<bundle>/bin/alp or alp.cmd, t-1807; its native alpd when it ships one, t-81b0.9, else its alpd.js), npm's @anhlp/alp-cli (dist/cli.js) or the @anhlp/alp wrapper (bin/alp.js),
|
|
115
|
+
* which depends on @anhlp/alp-cli (installed beside it, or in its own node_modules). On Windows an
|
|
116
|
+
* alp.cmd shim of npm or install.ps1 is followed to the script it runs (t-1f14).
|
|
117
|
+
* @param {string} cli @param {number} [depth] @param {NodeJS.ProcessEnv} [env]
|
|
103
118
|
*/
|
|
104
|
-
async function cliDaemonEntry(cli) {
|
|
119
|
+
async function cliDaemonEntry(cli, depth = 0, env = process.env) {
|
|
105
120
|
const base = path.basename(cli).toLowerCase();
|
|
106
121
|
const root = path.resolve(path.dirname(cli), '..');
|
|
107
122
|
const alpd = directory => path.join(directory, 'dist', 'alpd.js');
|
|
108
123
|
const named = async directory => readFile(path.join(directory, 'package.json'), 'utf8').then(text => JSON.parse(text)?.name).catch(() => undefined);
|
|
109
124
|
let candidates = [];
|
|
125
|
+
if (base === 'alp.cmd' && depth < 1 && !await isFile(path.join(root, 'alp-bundle.json'))) {
|
|
126
|
+
// A Windows shim that is not the bundle's own: npm's ("%dp0%\node_modules\@anhlp\alp\bin\alp.js")
|
|
127
|
+
// or install.ps1's ("<root>\app\current\lib\node_modules\@anhlp\alp-cli\dist\cli.js"): follow the script it runs.
|
|
128
|
+
const text = await stat(cli).then(info => info.size <= 64 * 1024 ? readFile(cli, 'utf8') : '', () => '');
|
|
129
|
+
for (const [, quoted] of text.matchAll(/"([^"\r\n]+\.js)"/gi)) {
|
|
130
|
+
const script = quoted.replace(/^%~?dp0%?[\\/]?/i, `${path.dirname(cli)}${path.sep}`);
|
|
131
|
+
const entry = path.isAbsolute(script) && await isFile(script) ? await cliDaemonEntry(script, depth + 1, env) : undefined;
|
|
132
|
+
if (entry) return entry;
|
|
133
|
+
}
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
110
136
|
if (base === 'alp' || base === 'alp.cmd') {
|
|
111
137
|
// A bundle: bin/ beside alp-bundle.json; name alpd through app/current when that is this bundle.
|
|
112
138
|
if (!await isFile(path.join(root, 'alp-bundle.json'))) return undefined;
|
|
113
139
|
const current = path.join(path.dirname(root), 'current');
|
|
114
140
|
const viaCurrent = await realpath(current).then(real => real === root, () => false);
|
|
115
|
-
|
|
141
|
+
const bundle = viaCurrent ? current : root;
|
|
142
|
+
// The native alpd first (t-81b0.9), as the bundle's own `alp` starts it; alpd.js where it ships none.
|
|
143
|
+
candidates = [...(env.ALP_NATIVE_DAEMON === '0' ? [] : [path.join(bundle, 'bin', NATIVE_DAEMON)]), alpd(path.join(bundle, 'lib', 'node_modules', '@anhlp', 'alp-cli'))];
|
|
116
144
|
} else if (base === 'cli.js' && CLI_PACKAGES.includes(await named(root))) {
|
|
117
145
|
candidates = [alpd(root)];
|
|
118
146
|
} else if (base === 'alp.js' && await named(root) === '@anhlp/alp') {
|
|
@@ -125,18 +153,19 @@ async function cliDaemonEntry(cli) {
|
|
|
125
153
|
/**
|
|
126
154
|
* Finds alpd.js for a client that cannot locate it beside itself, such as the Paseo
|
|
127
155
|
* plugin, which Paseo re-bundles: the first existing candidate, then where alpd last
|
|
128
|
-
* recorded itself ($ALP_HOME/alpd.json), then the ALP CLI (`alp`) on PATH
|
|
156
|
+
* recorded itself ($ALP_HOME/alpd.json), then the ALP CLI (`alp`) on PATH and in the usual install
|
|
157
|
+
* directories (`binDirectories`; a test passes [] so the caller's own install is not found).
|
|
129
158
|
*/
|
|
130
|
-
export async function findDaemonEntry({ home = alpHome(), env = process.env, candidates = /** @type {Array<string | undefined>} */ ([]) } = {}) {
|
|
159
|
+
export async function findDaemonEntry({ home = alpHome(), env = process.env, candidates = /** @type {Array<string | undefined>} */ ([]), binDirectories = BIN_DIRECTORIES } = {}) {
|
|
131
160
|
for (const candidate of candidates) if (candidate && await isFile(candidate)) return candidate;
|
|
132
161
|
try {
|
|
133
162
|
const { entry } = JSON.parse(await readFile(daemonPaths(home).install, 'utf8'));
|
|
134
163
|
if (typeof entry === 'string' && await isFile(entry)) return entry;
|
|
135
164
|
} catch {}
|
|
136
|
-
for (const directory of [...(env.PATH ?? '').split(path.delimiter).filter(Boolean), ...
|
|
165
|
+
for (const directory of [...(env.PATH ?? '').split(path.delimiter).filter(Boolean), ...binDirectories]) {
|
|
137
166
|
for (const name of process.platform === 'win32' ? ['alp.cmd', 'alp'] : ['alp']) {
|
|
138
167
|
const cli = await realpath(path.join(directory, name)).catch(() => undefined);
|
|
139
|
-
const entry = cli && await cliDaemonEntry(cli);
|
|
168
|
+
const entry = cli && await cliDaemonEntry(cli, 0, env);
|
|
140
169
|
if (entry) return entry;
|
|
141
170
|
}
|
|
142
171
|
}
|
|
@@ -272,16 +301,34 @@ export async function acquireDaemonLock(home, contents) {
|
|
|
272
301
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
273
302
|
try {
|
|
274
303
|
const handle = await open(file, 'wx', 0o600);
|
|
275
|
-
|
|
304
|
+
// The identity of the file this call created, taken before anything can fail on it.
|
|
305
|
+
let ours;
|
|
306
|
+
try {
|
|
307
|
+
ours = await handle.stat();
|
|
308
|
+
await handle.writeFile(JSON.stringify(lock));
|
|
309
|
+
} catch (error) {
|
|
310
|
+
// Recover the descriptor identity if async fstat failed. Never infer ownership from
|
|
311
|
+
// the pathname: another process may already have replaced it. If both stats fail,
|
|
312
|
+
// leave the unreadable lock for explicit recovery rather than unlinking a successor.
|
|
313
|
+
if (!ours) { try { ours = fstatSync(handle.fd); } catch {} }
|
|
314
|
+
await handle.close().catch(() => {});
|
|
315
|
+
const there = await lstat(file).catch(() => undefined);
|
|
316
|
+
if (ours && there && ours.ino === there.ino && ours.dev === there.dev) await unlink(file).catch(() => {});
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
276
319
|
await handle.close();
|
|
277
320
|
return lock;
|
|
278
321
|
} catch (error) {
|
|
279
322
|
if (error?.code !== 'EEXIST') throw error;
|
|
280
323
|
const current = await readLock(home);
|
|
281
324
|
if (lockAlive(current)) throw new Error(current.maintenance ? `ALP is busy: alp ${current.maintenance} runs (pid ${current.pid}); try again when it finishes` : `ALP daemon already running (pid ${current.pid})`);
|
|
282
|
-
// Remove the stale lock only if nobody replaced it meanwhile.
|
|
325
|
+
// Remove the stale lock only if nobody replaced it meanwhile. A lock that cannot be read may
|
|
326
|
+
// be one another start is writing now: it stays, and this start says so.
|
|
283
327
|
const again = await readFile(file, 'utf8').catch(() => undefined);
|
|
284
|
-
|
|
328
|
+
let parsed;
|
|
329
|
+
try { parsed = again === undefined ? undefined : JSON.parse(again); }
|
|
330
|
+
catch { throw new Error(`ALP daemon lock ${file} cannot be read: another start may be writing it. If no alpd or alp command is starting, remove it and try again`); }
|
|
331
|
+
if (again === undefined || JSON.stringify(current) === again || !lockAlive(parsed)) await unlink(file).catch(() => {});
|
|
285
332
|
}
|
|
286
333
|
}
|
|
287
334
|
throw new Error('Could not acquire the ALP daemon lock');
|
|
@@ -460,12 +507,29 @@ export async function withDaemonLifecycle(home, action, run, { joinStart = false
|
|
|
460
507
|
}
|
|
461
508
|
}
|
|
462
509
|
|
|
510
|
+
/** How long a start waits for alpd to be ready by default: generous, as a loaded host can take a while. */
|
|
511
|
+
export const DAEMON_START_TIMEOUT_MS = 60_000;
|
|
512
|
+
/** The largest wait ALP_DAEMON_START_TIMEOUT_MS may ask for (one hour; setTimeout's own bound is about 24 days). */
|
|
513
|
+
const DAEMON_START_TIMEOUT_MAX_MS = 3_600_000;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* The time a start of alpd waits for it to become ready, in ms: ALP_DAEMON_START_TIMEOUT_MS when it
|
|
517
|
+
* is a positive whole number of at most one hour, else DAEMON_START_TIMEOUT_MS.
|
|
518
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
519
|
+
*/
|
|
520
|
+
export function daemonStartTimeoutMs(env = process.env) {
|
|
521
|
+
const raw = env.ALP_DAEMON_START_TIMEOUT_MS?.trim();
|
|
522
|
+
if (!raw || !/^[0-9]+$/.test(raw)) return DAEMON_START_TIMEOUT_MS;
|
|
523
|
+
const value = Number(raw);
|
|
524
|
+
return value > 0 && value <= DAEMON_START_TIMEOUT_MAX_MS ? value : DAEMON_START_TIMEOUT_MS;
|
|
525
|
+
}
|
|
526
|
+
|
|
463
527
|
/**
|
|
464
528
|
* Returns the socket of a ready daemon, starting one when none runs.
|
|
465
529
|
* `entry` is the daemon script; it is started through its own detaching launcher so the
|
|
466
530
|
* daemon outlives the client that started it.
|
|
467
531
|
*/
|
|
468
|
-
export async function ensureDaemon({ home = alpHome(), entry = /** @type {string | undefined} */ (undefined), env = process.env, execPath = process.execPath, timeoutMs =
|
|
532
|
+
export async function ensureDaemon({ home = alpHome(), entry = /** @type {string | undefined} */ (undefined), env = process.env, execPath = process.execPath, timeoutMs = daemonStartTimeoutMs(env), lifecycleLocked = false, signal = /** @type {AbortSignal | undefined} */ (undefined) } = {}) {
|
|
469
533
|
signal?.throwIfAborted();
|
|
470
534
|
if (!lifecycleLocked) return withDaemonLifecycle(home, 'start', () => ensureDaemon({ home, entry, env, execPath, timeoutMs, lifecycleLocked: true, signal }), { signal });
|
|
471
535
|
const ready = async () => {
|
|
@@ -482,8 +546,11 @@ export async function ensureDaemon({ home = alpHome(), entry = /** @type {string
|
|
|
482
546
|
signal?.throwIfAborted();
|
|
483
547
|
await new Promise((resolve, reject) => {
|
|
484
548
|
const launch = entryCommand(entry, 'daemon', ['--detach', `--startup-timeout=${timeoutMs}`], execPath);
|
|
549
|
+
// BUN_BE_BUN=1 would turn the native alpd (t-81b0.9) into the Bun CLI instead of starting alpd.
|
|
550
|
+
const launchEnv = { ...env, ALP_HOME: home, ELECTRON_RUN_AS_NODE: '1' };
|
|
551
|
+
if (isNativeDaemonName(launch.command)) delete launchEnv.BUN_BE_BUN;
|
|
485
552
|
const launcher = spawn(launch.command, launch.args, {
|
|
486
|
-
env:
|
|
553
|
+
env: launchEnv,
|
|
487
554
|
stdio: ['ignore', 'ignore', 'pipe'],
|
|
488
555
|
windowsHide: true,
|
|
489
556
|
});
|
|
@@ -570,23 +637,25 @@ async function distributionRoots() {
|
|
|
570
637
|
/**
|
|
571
638
|
* The entry of integration `name`: an environment override, a descriptor under the home or a
|
|
572
639
|
* distribution root, or an `alp-<name>-integration` binary. Discovery never returns an entry for
|
|
573
|
-
* `
|
|
574
|
-
* entry
|
|
640
|
+
* `dashboard`: that is alp dashboard's service, which ships with the CLI and is started with its
|
|
641
|
+
* explicit entry; nor for `web`, its name before the rename (t-81b0.5). Everything once registered
|
|
642
|
+
* under `web` (the descriptor `integrations/web.json`, the
|
|
575
643
|
* `alp-web-integration` binary, `ALP_WEB_INTEGRATION`) is the Paseo integration from before its
|
|
576
644
|
* rename to `paseo`, which must never run under the web lock. `ALP_WEB_INTEGRATION` is read for
|
|
577
645
|
* `paseo` only, after `ALP_PASEO_INTEGRATION`, for one release (like the alp-web-integration alias).
|
|
578
646
|
* @param {string} [name]
|
|
579
|
-
* @param {{ home?: string }} [options]
|
|
647
|
+
* @param {{ home?: string, env?: NodeJS.ProcessEnv, binDirectories?: string[], roots?: string[] }} [options]
|
|
580
648
|
*/
|
|
581
|
-
export async function discoverIntegration(name = '
|
|
649
|
+
export async function discoverIntegration(name = 'dashboard', options = {}) {
|
|
582
650
|
// The name becomes a descriptor path under <home>/integrations, so it must stay one safe segment.
|
|
583
651
|
assertIntegrationName(name);
|
|
584
|
-
if (name === 'web') return undefined;
|
|
652
|
+
if (name === 'dashboard' || name === 'web') return undefined;
|
|
653
|
+
const { env = process.env, binDirectories = BIN_DIRECTORIES, roots } = options;
|
|
585
654
|
// Explicit environment override always wins: the integration's own, then the generic one.
|
|
586
655
|
const envCandidates = [
|
|
587
|
-
|
|
588
|
-
name === 'paseo' ?
|
|
589
|
-
|
|
656
|
+
env[`ALP_${name.toUpperCase()}_INTEGRATION`],
|
|
657
|
+
name === 'paseo' ? env.ALP_WEB_INTEGRATION : undefined,
|
|
658
|
+
env.ALP_INTEGRATION_ENTRY,
|
|
590
659
|
].filter(Boolean);
|
|
591
660
|
for (const candidate of envCandidates) if (await isFile(candidate)) return candidate;
|
|
592
661
|
|
|
@@ -595,7 +664,7 @@ export async function discoverIntegration(name = 'web', options = {}) {
|
|
|
595
664
|
if (fromHome) return fromHome;
|
|
596
665
|
|
|
597
666
|
// A full distribution may describe a bundled integration relative to its own root.
|
|
598
|
-
for (const root of await distributionRoots()) {
|
|
667
|
+
for (const root of roots ?? await distributionRoots()) {
|
|
599
668
|
for (const descriptorPath of [path.join(root, 'integrations', `${name}.json`), path.join(root, 'integrations', name, 'integration.json')]) {
|
|
600
669
|
const entry = await readIntegrationDescriptor(descriptorPath, [root]);
|
|
601
670
|
if (entry) return entry;
|
|
@@ -604,7 +673,7 @@ export async function discoverIntegration(name = 'web', options = {}) {
|
|
|
604
673
|
|
|
605
674
|
// Installed integration packages announce themselves on PATH.
|
|
606
675
|
const binary = integrationBinaryName(name);
|
|
607
|
-
for (const directory of [...(
|
|
676
|
+
for (const directory of [...(env.PATH ?? '').split(path.delimiter).filter(Boolean), ...binDirectories]) {
|
|
608
677
|
const candidate = await realpath(path.join(directory, binary)).catch(() => undefined);
|
|
609
678
|
if (candidate && await isFile(candidate)) return candidate;
|
|
610
679
|
}
|
|
@@ -622,17 +691,17 @@ export function integrationAlive(lock) {
|
|
|
622
691
|
}
|
|
623
692
|
|
|
624
693
|
/**
|
|
625
|
-
* What startIntegration says about integration `name`, and where its service writes its log: alp
|
|
626
|
-
* (`
|
|
694
|
+
* What startIntegration says about integration `name`, and where its service writes its log: alp
|
|
695
|
+
* dashboard (`dashboard`) is part of the CLI, Paseo (`paseo`) an optional package, anything else named as is.
|
|
627
696
|
* @param {string} name
|
|
628
697
|
* @param {string} home
|
|
629
698
|
*/
|
|
630
699
|
function integrationText(name, home) {
|
|
631
700
|
const logs = path.join(home, 'logs', 'integrations');
|
|
632
|
-
if (name === '
|
|
633
|
-
what: 'alp
|
|
634
|
-
log: path.join(logs, 'alp-
|
|
635
|
-
missing: 'alp
|
|
701
|
+
if (name === 'dashboard') return {
|
|
702
|
+
what: 'alp dashboard',
|
|
703
|
+
log: path.join(logs, 'alp-dashboard.log'),
|
|
704
|
+
missing: 'alp dashboard runs the alp-dashboard service of the ALP CLI, which is started with its entry (packages/cli/dist/alp-dashboard.js); run `alp dashboard`',
|
|
636
705
|
};
|
|
637
706
|
if (name === 'paseo') return {
|
|
638
707
|
what: 'The Paseo integration',
|
|
@@ -647,16 +716,16 @@ function integrationText(name, home) {
|
|
|
647
716
|
}
|
|
648
717
|
|
|
649
718
|
/**
|
|
650
|
-
* Starts integration `name` (default `
|
|
719
|
+
* Starts integration `name` (default `dashboard`) detached with `--service` (then `args`) unless its lock
|
|
651
720
|
* already names a live owner, then waits until its ready lock and `<home>/<name>.json` name the same
|
|
652
721
|
* pid. `entry` names the script to run with this Node and skips descriptor, environment and PATH
|
|
653
|
-
* discovery; `
|
|
654
|
-
* in the home's settings.json
|
|
722
|
+
* discovery; `dashboard` is never discovered, so it needs its entry. `"dashboard": { "enabled": false }`
|
|
723
|
+
* in the home's settings.json (or `web.enabled`, its key before the rename) refuses `dashboard` only.
|
|
655
724
|
* @param {string | { name?: string, entry?: string, home?: string, args?: string[] }} [nameOrOptions]
|
|
656
725
|
*/
|
|
657
|
-
export async function startIntegration(nameOrOptions = '
|
|
726
|
+
export async function startIntegration(nameOrOptions = 'dashboard') {
|
|
658
727
|
const options = typeof nameOrOptions === 'string' ? { name: nameOrOptions } : (nameOrOptions ?? {});
|
|
659
|
-
const name = assertIntegrationName(options.name ?? '
|
|
728
|
+
const name = assertIntegrationName(options.name ?? 'dashboard');
|
|
660
729
|
if (options.entry !== undefined && (typeof options.entry !== 'string' || !options.entry)) throw new TypeError('startIntegration entry must be a non-empty path');
|
|
661
730
|
const args = options.args ?? [];
|
|
662
731
|
if (!Array.isArray(args) || !args.every(arg => typeof arg === 'string')) throw new TypeError('startIntegration args must be a list of strings');
|
|
@@ -672,11 +741,11 @@ export async function startIntegration(nameOrOptions = 'web') {
|
|
|
672
741
|
const webPath = pathMod.join(home, `${name}.json`);
|
|
673
742
|
const started = explicit ? ` (entry ${explicit})` : '';
|
|
674
743
|
|
|
675
|
-
//
|
|
676
|
-
if (name === '
|
|
744
|
+
// dashboard.enabled turns off alp dashboard only; other integrations have their own switches.
|
|
745
|
+
if (name === 'dashboard') {
|
|
677
746
|
let settings = {};
|
|
678
747
|
try { settings = JSON.parse(await fs.readFile(pathMod.join(home, 'settings.json'), 'utf8')); } catch {}
|
|
679
|
-
if (settings
|
|
748
|
+
if (dashboardSettings(settings).enabled === false) throw new Error('alp dashboard is disabled by settings ("dashboard.enabled": false).');
|
|
680
749
|
}
|
|
681
750
|
|
|
682
751
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -698,10 +767,10 @@ export async function startIntegration(nameOrOptions = 'web') {
|
|
|
698
767
|
const info = await readWeb();
|
|
699
768
|
if (info && info.pid === lock.pid) return lock;
|
|
700
769
|
}
|
|
701
|
-
// alp
|
|
770
|
+
// alp dashboard can fail during bootstrap after the initial exit check (for example a
|
|
702
771
|
// refused uncertain lock). Its service log carries the cause; do not mask it with
|
|
703
|
-
// a readiness/
|
|
704
|
-
if (name === '
|
|
772
|
+
// a readiness/dashboard.json timeout. Check a concurrent winner's ready lock first.
|
|
773
|
+
if (name === 'dashboard' && webStartupFailed()) throw new Error(`${text.what}${started} failed to start; see ${text.log}`);
|
|
705
774
|
await sleep(100);
|
|
706
775
|
}
|
|
707
776
|
const lock = await readLock();
|
|
@@ -724,8 +793,8 @@ export async function startIntegration(nameOrOptions = 'web') {
|
|
|
724
793
|
// The child is detached with its stdio ignored, so it cannot rely on the parent's console. `--service`
|
|
725
794
|
// is the generic contract: the entry writes its own log (the path its error messages advertise) and
|
|
726
795
|
// keeps the process alive as a service. `--register` still prints to stdout and is not passed here.
|
|
727
|
-
// alp
|
|
728
|
-
const launch = name === '
|
|
796
|
+
// alp dashboard may be an `alp` command (`alp dashboard serve`); other integrations are scripts.
|
|
797
|
+
const launch = name === 'dashboard' ? entryCommand(entry, 'dashboard', ['--service', ...args]) : entryCommand(entry, 'dashboard', ['--service', ...args], undefined, { scriptOnly: true });
|
|
729
798
|
const child = spawn(launch.command, launch.args, { stdio: 'ignore', detached: true, env: { ...process.env, ALP_HOME: home } });
|
|
730
799
|
let spawnError = null;
|
|
731
800
|
child.on('error', error => { spawnError = error; });
|
package/src/integration-lock.js
CHANGED
|
@@ -174,7 +174,7 @@ export function createIntegrationLock(home, name) {
|
|
|
174
174
|
try {
|
|
175
175
|
try { await handle.writeFile(JSON.stringify(value)); info = await handle.stat(); }
|
|
176
176
|
finally { await handle.close(); }
|
|
177
|
-
// Readers (alp
|
|
177
|
+
// Readers (alp dashboard --status, a polling client) may hold the lock open; Windows then refuses the
|
|
178
178
|
// replace with EPERM/EACCES/EBUSY for a moment, so moveFile retries it there.
|
|
179
179
|
await moveFile(tmp, file);
|
|
180
180
|
owned = { owner: value.owner, dev: info.dev, ino: info.ino };
|
package/src/render.js
CHANGED
|
@@ -94,6 +94,9 @@ export function renderLog(rootId, entries) {
|
|
|
94
94
|
? `✦ ${entry.agent} saved skill ${entry.name} for ${entry.roles.join(', ')}`
|
|
95
95
|
: `✦ ${entry.agent} uses skill ${entry.skill}${entry.via === 'skill' ? ' (Skill tool)' : ''}`;
|
|
96
96
|
break;
|
|
97
|
+
case 'skill-resource':
|
|
98
|
+
text = `✦ ${entry.agent} ${entry.action === 'run' ? 'runs' : 'reads'} ${entry.skill}/${entry.resource}`;
|
|
99
|
+
break;
|
|
97
100
|
case 'compacted':
|
|
98
101
|
text = entry.failed
|
|
99
102
|
? `✗ ${entry.agent}'s context could not be compacted${entry.error ? `: ${entry.error}` : ''}`
|
package/src/service.js
CHANGED
|
@@ -54,7 +54,7 @@ export function serviceFor({ home, env = process.env, platform = process.platfor
|
|
|
54
54
|
return undefined;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/** The service definition that runs `entry` (alpd.js with `execPath`, or an `alp` command) for `home`. */
|
|
57
|
+
/** The service definition that runs `entry` (alpd.js with `execPath`, the native alpd, or an `alp` command) for `home`. */
|
|
58
58
|
export function serviceDefinition(service, { home, entry, execPath = process.execPath, env = process.env }) {
|
|
59
59
|
const variables = { ALP_HOME: path.resolve(home), PATH: env.PATH ?? '' };
|
|
60
60
|
for (const name of CARRIED) if (env[name]) variables[name] = env[name];
|
|
@@ -115,7 +115,7 @@ WantedBy=default.target
|
|
|
115
115
|
`;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
/** The program an installed definition runs: [node, alpd.js], or undefined when it is not installed. */
|
|
118
|
+
/** The program an installed definition runs: [node, alpd.js] or [alpd, --service] (native, t-81b0.9), or undefined when it is not installed. */
|
|
119
119
|
export async function installedProgram(service) {
|
|
120
120
|
const text = await readFile(service.file, 'utf8').catch(() => undefined);
|
|
121
121
|
if (text === undefined) return undefined;
|