@anhlp/alp-cli 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/acp/main.js +1 -1
- package/dist/acp.js +180 -82
- package/dist/{alp-web → alp-dashboard}/THIRD-PARTY-NOTICES.txt +1 -1
- package/dist/{alp-web/assets/TerminalPanel-BbYa_Xkd.js → alp-dashboard/assets/TerminalPanel-BSjqIfNr.js} +1 -1
- package/dist/{alp-web/assets/index-DOJh89Ik.js → alp-dashboard/assets/index-CZFfSOIE.js} +5 -5
- package/dist/{alp-web → alp-dashboard}/index.html +1 -1
- package/dist/{alp-web.js → alp-dashboard.js} +349 -306
- package/dist/alpd.js +1308 -1271
- package/dist/backup.js +1 -1
- package/dist/build-manifest.json +14 -5
- package/dist/cli.js +4 -3
- package/dist/daemon.d.ts +1 -1
- package/dist/daemon.js +6 -6
- package/dist/dashboard-migrate.d.ts +31 -0
- package/dist/dashboard-migrate.js +127 -0
- package/dist/dashboard-service.d.ts +69 -0
- package/dist/{web-service.js → dashboard-service.js} +30 -32
- package/dist/desktop.d.ts +56 -0
- package/dist/desktop.js +91 -0
- package/dist/interfaces.d.ts +2 -2
- package/dist/interfaces.js +133 -43
- package/dist/paths.d.ts +6 -1
- package/dist/paths.js +4 -2
- package/dist/roles.d.ts +5 -5
- package/dist/self-update.d.ts +2 -1
- package/dist/self-update.js +7 -1
- package/dist/sessions.d.ts +0 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.js +6 -4
- package/package.json +6 -6
- package/src/cli.js +3 -2
- package/src/daemon.js +7 -6
- package/src/dashboard-migrate.js +152 -0
- package/src/{web-service.js → dashboard-service.js} +54 -48
- package/src/desktop.js +122 -0
- package/src/interfaces.js +170 -61
- package/src/paths.js +9 -3
- package/src/roles.js +4 -4
- package/src/self-update.js +10 -2
- package/src/sessions.js +0 -2
- package/src/usage.js +6 -4
- package/dist/web-service.d.ts +0 -56
- /package/dist/{alp-web → alp-dashboard}/alp-boundary.json +0 -0
- /package/dist/{alp-web → alp-dashboard}/apple-touch-icon.png +0 -0
- /package/dist/{alp-web → alp-dashboard}/assets/TerminalPanel-DLuoa74B.css +0 -0
- /package/dist/{alp-web → alp-dashboard}/assets/highlighter-BnicKQ_d.js +0 -0
- /package/dist/{alp-web → alp-dashboard}/assets/index-DwqDSiIi.css +0 -0
- /package/dist/{alp-web → alp-dashboard}/favicon-attention.svg +0 -0
- /package/dist/{alp-web → alp-dashboard}/favicon-running.svg +0 -0
- /package/dist/{alp-web → alp-dashboard}/favicon.svg +0 -0
package/src/interfaces.js
CHANGED
|
@@ -10,12 +10,12 @@ import { DAEMON_ENTRY, distributionEntry } from './paths.js';
|
|
|
10
10
|
import { entryCommand } from '@anhlp/alp-core/packaged';
|
|
11
11
|
import { isAgentProcess } from '@anhlp/alp-core/tasks';
|
|
12
12
|
import { runRole } from './roles.js';
|
|
13
|
-
import {
|
|
13
|
+
import { DASHBOARD, LEGACY_WEB, dashboardEntry, dashboardScript, isDashboardReady, isServiceClaimed, refusal, serviceOwner, stopService } from './dashboard-service.js';
|
|
14
|
+
import { legacyLeftovers, migrateDashboard } from './dashboard-migrate.js';
|
|
15
|
+
import { dashboardSettings } from '@anhlp/alp-core/user-settings';
|
|
14
16
|
|
|
15
17
|
/** The Paseo integration (its web app, bridge and relay) runs as integration `paseo`. */
|
|
16
18
|
const PASEO = 'paseo';
|
|
17
|
-
/** alp-web (packages/cli/src/web), the service behind `alp web`, runs as integration `web`. */
|
|
18
|
-
const WEB = 'web';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Starts the Paseo integration. For one release, a home that still has only the descriptor
|
|
@@ -38,7 +38,7 @@ export async function startPaseoIntegration(home) {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* The entry named by the pre-rename descriptor `<home>/integrations/web.json`, and nothing else: no
|
|
41
|
-
* environment, distribution or PATH lookup, since the name `web`
|
|
41
|
+
* environment, distribution or PATH lookup, since the name `web` belonged to alp web after that. A relative
|
|
42
42
|
* `main` resolves against the descriptor's directory, then the home, as discovery does.
|
|
43
43
|
* @param {string} file
|
|
44
44
|
* @param {string} home
|
|
@@ -63,7 +63,7 @@ async function currentProject() {
|
|
|
63
63
|
return await stat(path.join(cwd, '.alp')).then(info => info.isDirectory(), () => false) ? cwd : undefined;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/** `--project <cwd>` when the directory `alp
|
|
66
|
+
/** `--project <cwd>` when the directory `alp dashboard` runs in is an ALP project: its grant then covers it. */
|
|
67
67
|
async function projectArgs() {
|
|
68
68
|
const project = await currentProject();
|
|
69
69
|
return project ? ['--project', project] : [];
|
|
@@ -115,7 +115,7 @@ export async function registerProject(home, directory, { timeoutMs = 5_000, conn
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* Waits until the credential in `<home>/
|
|
118
|
+
* Waits until the credential in `<home>/dashboard/credentials.json` contains `project`.
|
|
119
119
|
* Polls for up to `timeoutMs` (default 5,000 ms).
|
|
120
120
|
* @param {string} home
|
|
121
121
|
* @param {string} credentialId
|
|
@@ -123,7 +123,7 @@ export async function registerProject(home, directory, { timeoutMs = 5_000, conn
|
|
|
123
123
|
* @param {{ timeoutMs?: number }} [options]
|
|
124
124
|
*/
|
|
125
125
|
async function waitForGrant(home, credentialId, project, { timeoutMs = 5_000 } = {}) {
|
|
126
|
-
const credentialsFile = path.join(home, '
|
|
126
|
+
const credentialsFile = path.join(home, 'dashboard', 'credentials.json');
|
|
127
127
|
const canonical = await realpath(project).catch(() => project);
|
|
128
128
|
const deadline = Date.now() + timeoutMs;
|
|
129
129
|
while (Date.now() < deadline) {
|
|
@@ -139,45 +139,76 @@ async function waitForGrant(home, credentialId, project, { timeoutMs = 5_000 } =
|
|
|
139
139
|
return false;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
/** Whether settings.json turns alp
|
|
143
|
-
async function
|
|
144
|
-
const settings = await
|
|
145
|
-
return settings
|
|
142
|
+
/** Whether settings.json turns alp dashboard off (`dashboard.enabled`, else `web.enabled` from before the rename). @param {string} home */
|
|
143
|
+
async function dashboardDisabled(home) {
|
|
144
|
+
const settings = await readJsonFile(path.join(home, 'settings.json'));
|
|
145
|
+
return dashboardSettings(settings).enabled === false;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
const DISABLED = 'alp
|
|
148
|
+
const DISABLED = 'alp dashboard is disabled by settings ("dashboard.enabled": false).';
|
|
149
|
+
|
|
150
|
+
/** A file's JSON, or undefined when it is missing or not JSON (as before: a broken file counts as none). @param {string} file */
|
|
151
|
+
const readJsonFile = file => readFile(file, 'utf8').then(text => { try { return JSON.parse(text); } catch { return undefined; } }, () => undefined);
|
|
152
|
+
/** @param {string} home */
|
|
153
|
+
const readPublished = home => readJsonFile(path.join(home, DASHBOARD.info));
|
|
154
|
+
/** @param {string} home */
|
|
155
|
+
const readServiceLock = home => readJsonFile(path.join(home, 'integrations', `${DASHBOARD.lock}.lock`));
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The running service as its files and its listener show it, without ps (so also on Windows): the
|
|
159
|
+
* lock names a live pid, dashboard.json names the same pid and is alp-dashboard's, and its address
|
|
160
|
+
* answers. `held` is a live lock owner that is not (yet) that.
|
|
161
|
+
* @param {string} home
|
|
162
|
+
* @returns {Promise<{ pid: number, port: number, url: string } | { held: number } | undefined>}
|
|
163
|
+
*/
|
|
164
|
+
async function runningDashboard(home) {
|
|
165
|
+
const lock = await readServiceLock(home);
|
|
166
|
+
if (!Number.isSafeInteger(lock?.pid) || lock.pid <= 0) return undefined;
|
|
167
|
+
try { process.kill(lock.pid, 0); } catch (error) { if (/** @type {any} */ (error)?.code !== 'EPERM') return undefined; }
|
|
168
|
+
const info = await readPublished(home);
|
|
169
|
+
if (info?.app === DASHBOARD.app && info.pid === lock.pid && typeof info.url === 'string' && await isDashboardReady(info.url)) return { pid: info.pid, port: info.port, url: info.url };
|
|
170
|
+
return { held: lock.pid };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Loopback names `--host` accepts; the service listens on 127.0.0.1 only, which serves both. */
|
|
174
|
+
const LOOPBACK_HOSTS = ['127.0.0.1', 'localhost'];
|
|
149
175
|
|
|
150
176
|
/**
|
|
151
|
-
* Starts alp-
|
|
152
|
-
* the browser never sends to a server).
|
|
153
|
-
*
|
|
154
|
-
* @param {string} home @param {string} entry
|
|
177
|
+
* Starts alp-dashboard unless it runs and returns the address to open, the token in its fragment
|
|
178
|
+
* (which the browser never sends to a server).
|
|
179
|
+
* @param {string} home @param {string} entry @param {{ port?: number }} [options]
|
|
155
180
|
*/
|
|
156
|
-
async function
|
|
157
|
-
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
async function serveDashboard(home, entry, { port } = {}) {
|
|
182
|
+
// A lock held by a process proven not to be alp dashboard: say so now rather than wait for it. A
|
|
183
|
+
// running alp-dashboard (its dashboard.json names the lock's pid and is answering) is left to startIntegration.
|
|
184
|
+
const held = await serviceOwner(home);
|
|
185
|
+
const published = await readPublished(home);
|
|
186
|
+
const lockPid = (await readServiceLock(home))?.pid;
|
|
187
|
+
const claimed = await isServiceClaimed(published, lockPid, held);
|
|
188
|
+
if ('reason' in held && held.alive && held.kind === 'foreign' && !claimed) throw new Error(`${refusal(home)} (${held.reason}). Stop it, then run alp dashboard again.`);
|
|
189
|
+
// `--port` asks for a port; a service already running elsewhere is not silently reused.
|
|
190
|
+
if (port !== undefined && claimed && published.port !== port) {
|
|
191
|
+
throw new Error(`alp dashboard already runs on port ${published.port} (pid ${published.pid}); you asked for port ${port}. Stop it with \`alp dashboard --stop\`, or drop --port to use the running one.`);
|
|
192
|
+
}
|
|
165
193
|
const project = await currentProject();
|
|
166
194
|
let lock;
|
|
167
|
-
try { lock = await startIntegration({ name:
|
|
195
|
+
try { lock = await startIntegration({ name: DASHBOARD.lock, entry, home, args: [...(project ? ['--project', project] : []), ...(port !== undefined ? ['--port', String(port)] : [])] }); }
|
|
168
196
|
catch (error) {
|
|
169
197
|
// Still held by a live process alp cannot prove: name it, as the wait may have been for it.
|
|
170
|
-
const owner = await
|
|
171
|
-
if ('reason' in owner && owner.alive) throw new Error(`${error?.message ?? error}\n${refusal(home)} (${owner.reason}). If it is not alp
|
|
198
|
+
const owner = await serviceOwner(home);
|
|
199
|
+
if ('reason' in owner && owner.alive) throw new Error(`${error?.message ?? error}\n${refusal(home)} (${owner.reason}). If it is not alp dashboard, stop it, then run alp dashboard again.`, { cause: error });
|
|
172
200
|
throw error;
|
|
173
201
|
}
|
|
174
|
-
const info = await
|
|
175
|
-
if (info?.app !==
|
|
176
|
-
const owner = await
|
|
177
|
-
throw new Error(`${refusal(home)}${'reason' in owner ? ` (${owner.reason})` : ''}. Stop pid ${lock.pid}, then run alp
|
|
202
|
+
const info = await readPublished(home);
|
|
203
|
+
if (info?.app !== DASHBOARD.app || info.pid !== lock.pid) {
|
|
204
|
+
const owner = await serviceOwner(home);
|
|
205
|
+
throw new Error(`${refusal(home)}${'reason' in owner ? ` (${owner.reason})` : ''}. Stop pid ${lock.pid}, then run alp dashboard again.`);
|
|
206
|
+
}
|
|
207
|
+
if (typeof info.url !== 'string' || typeof info.token !== 'string' || !(await isDashboardReady(info.url))) {
|
|
208
|
+
throw new Error(`alp dashboard published no address; see ${path.join(home, 'logs', 'integrations', 'alp-dashboard.log')}`);
|
|
178
209
|
}
|
|
179
|
-
if (
|
|
180
|
-
throw new Error(`alp
|
|
210
|
+
if (port !== undefined && info.port !== port) {
|
|
211
|
+
throw new Error(`alp dashboard is running on port ${info.port}, not ${port} (port ${port} was busy or alp dashboard was starting already); it was left running there. Stop it with \`alp dashboard --stop\` and free port ${port}, or drop --port`);
|
|
181
212
|
}
|
|
182
213
|
if (project) {
|
|
183
214
|
await registerProject(home, project);
|
|
@@ -186,59 +217,137 @@ async function serveWeb(home, entry) {
|
|
|
186
217
|
return `${info.url}#token=${info.token}`;
|
|
187
218
|
}
|
|
188
219
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (
|
|
220
|
+
/** Reports what the migration from `alp web` did, on stderr (stdout carries only the address). @param {Awaited<ReturnType<typeof migrateDashboard>>} report */
|
|
221
|
+
function reportMigration(report) {
|
|
222
|
+
if (report.stopped) console.error(`Stopped ${LEGACY_WEB.what} (pid ${report.stopped}).`);
|
|
223
|
+
if (report.moved.length) console.error(`Moved alp web's files to alp dashboard's names: ${report.moved.join('; ')}`);
|
|
224
|
+
for (const warning of report.warnings) console.error(warning);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* alp dashboard --status, after Hermes' `hermes dashboard --status` (hermes_cli/main_dashboard.py
|
|
229
|
+
* _report_dashboard_status): what runs, or that nothing does; always exit 0, and nothing is changed
|
|
230
|
+
* (the move from `alp web` waits for a command that starts or stops). The address is printed
|
|
231
|
+
* without its token.
|
|
232
|
+
* @param {string} home
|
|
233
|
+
*/
|
|
234
|
+
async function statusCommand(home) {
|
|
235
|
+
try {
|
|
236
|
+
const running = await runningDashboard(home);
|
|
237
|
+
if (running && 'url' in running) {
|
|
238
|
+
console.log('1 alp dashboard process running:');
|
|
239
|
+
console.log(` PID ${running.pid} [dashboard]: ${running.url} (port ${running.port})`);
|
|
240
|
+
} else if (running) {
|
|
241
|
+
const owner = await serviceOwner(home);
|
|
242
|
+
console.log(`No alp dashboard running. pid ${running.held} holds ${path.join(home, 'integrations', `${DASHBOARD.lock}.lock`)}${'reason' in owner ? ` (${owner.reason})` : ''}.`);
|
|
243
|
+
} else console.log('No alp dashboard running.');
|
|
244
|
+
if (await dashboardDisabled(home)) console.log(DISABLED);
|
|
245
|
+
const left = await legacyLeftovers(home);
|
|
246
|
+
if (left.legacy?.pid) console.log(`${LEGACY_WEB.what} still runs (pid ${left.legacy.pid}); \`alp dashboard\` or \`alp dashboard --stop\` stops it.`);
|
|
247
|
+
else if (left.legacy) console.log(`${refusal(home, LEGACY_WEB)} (${left.legacy.reason}).`);
|
|
248
|
+
for (const item of left.pending) console.log(`From before the rename to alp dashboard, moved by the next \`alp dashboard\`: ${item}`);
|
|
249
|
+
for (const item of left.kept) console.log(`Left from before the rename to alp dashboard, not used: ${item}`);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.log(`alp dashboard could not tell everything: ${error?.message ?? error}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* alp dashboard --stop, after Hermes' `hermes dashboard --stop` (hermes_cli/main.py
|
|
257
|
+
* _dashboard_lifecycle_flags): only this ALP home's service (and alp web from before the rename,
|
|
258
|
+
* which the move stops); nothing running is not an error; a process alp cannot prove is the service
|
|
259
|
+
* is left running and the command fails.
|
|
260
|
+
* @param {string} home
|
|
261
|
+
*/
|
|
262
|
+
async function stopCommand(home) {
|
|
263
|
+
const report = await migrateDashboard(home);
|
|
264
|
+
reportMigration(report);
|
|
265
|
+
// alp web from before the rename still holds its lock: not stopped, so not a success.
|
|
266
|
+
if (report.held) process.exitCode = 1;
|
|
267
|
+
const owner = await serviceOwner(home);
|
|
268
|
+
if (!owner.alive && !('pid' in owner)) {
|
|
269
|
+
if (!report.stopped) console.log('No alp dashboard running for this ALP home.');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const pid = await stopService(home);
|
|
273
|
+
if (pid) console.log(`Stopped alp dashboard (pid ${pid}).`);
|
|
274
|
+
else console.log('No alp dashboard running for this ALP home.');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async function dashboardCommand(args) {
|
|
278
|
+
// alp dashboard prints, rotates and pairs with the user's own secrets (t-1c59), and stops the
|
|
279
|
+
// user's service: a process an ALP agent started is refused before anything is read, stopped or printed.
|
|
280
|
+
if (isAgentProcess()) throw new Error('alp dashboard is the user\'s: it prints and rotates the user\'s credential; this process was started by an ALP agent (ALP_AGENT_SESSION is set)');
|
|
193
281
|
if (args[0] === 'pair') return pairCommand(args.slice(1));
|
|
194
282
|
if (args[0] === 'rotate') return rotateCommand(args.slice(1));
|
|
195
|
-
// alp-
|
|
196
|
-
if (args[0] === 'serve') return runRole('
|
|
197
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: {
|
|
283
|
+
// alp-dashboard itself in this process; its own options (--service, --rotate, --project DIR, --port N) follow.
|
|
284
|
+
if (args[0] === 'serve') return runRole('dashboard', dashboardScript(), args.slice(1));
|
|
285
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: {
|
|
286
|
+
print: { type: 'boolean' }, 'no-open': { type: 'boolean' }, status: { type: 'boolean' }, stop: { type: 'boolean' },
|
|
287
|
+
port: { type: 'string' }, host: { type: 'string' },
|
|
288
|
+
} });
|
|
198
289
|
if (positionals.length) throw new UsageError();
|
|
199
|
-
const entry = alpWebEntry();
|
|
200
290
|
const home = alpHome();
|
|
201
|
-
|
|
291
|
+
// As in Hermes, the lifecycle flags win over the start flags: they report or stop, and exit.
|
|
292
|
+
if (values.status && values.stop) throw new UsageError();
|
|
293
|
+
if (values.status) return statusCommand(home);
|
|
294
|
+
if (values.stop) return stopCommand(home);
|
|
295
|
+
let port;
|
|
296
|
+
if (values.port !== undefined) {
|
|
297
|
+
port = Number(values.port);
|
|
298
|
+
if (!/^\d+$/.test(values.port) || port < 1024 || port > 65535) throw new Error(`--port must be a port from 1024 to 65535, not ${values.port}`);
|
|
299
|
+
}
|
|
300
|
+
// ALP's token is the dashboard's only lock and its gateway accepts only loopback Host and Origin
|
|
301
|
+
// names, so it is never bound beyond this machine (Hermes too refuses a non-loopback bind without
|
|
302
|
+
// an auth provider, which ALP does not have).
|
|
303
|
+
if (values.host !== undefined && !LOOPBACK_HOSTS.includes(values.host)) {
|
|
304
|
+
throw new Error(`alp dashboard listens on this machine only (127.0.0.1): --host ${values.host} is refused. Reach it from another machine through an SSH tunnel to 127.0.0.1.`);
|
|
305
|
+
}
|
|
306
|
+
const entry = dashboardEntry();
|
|
307
|
+
reportMigration(await migrateDashboard(home, { strict: true }));
|
|
308
|
+
if (await dashboardDisabled(home)) throw new Error(DISABLED);
|
|
202
309
|
await start();
|
|
203
|
-
|
|
310
|
+
let url = await serveDashboard(home, entry, { port });
|
|
311
|
+
if (values.host === 'localhost') url = url.replace('://127.0.0.1:', '://localhost:');
|
|
204
312
|
console.log(url);
|
|
205
|
-
if (values.print) return;
|
|
313
|
+
if (values.print || values['no-open']) return;
|
|
206
314
|
const opener = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'explorer' : 'xdg-open';
|
|
207
315
|
spawn(opener, [url], { stdio: 'ignore', detached: true }).on('error', () => console.error('Open the address above in your browser')).unref();
|
|
208
316
|
}
|
|
209
317
|
|
|
210
318
|
/**
|
|
211
|
-
* alp
|
|
212
|
-
* access. Only the process holding the
|
|
213
|
-
* stopped first; `alp-
|
|
214
|
-
* new token in
|
|
319
|
+
* alp dashboard rotate: alp dashboard's token is replaced and the old one revoked, so every open
|
|
320
|
+
* page loses access. Only the process holding the dashboard lock writes its credentials, so the
|
|
321
|
+
* service is stopped first; `alp-dashboard.js --rotate` then takes the lock, replaces the credential,
|
|
322
|
+
* records the new token in dashboard.json and releases the lock, and the service starts again with it.
|
|
215
323
|
*/
|
|
216
324
|
async function rotateCommand(args) {
|
|
217
325
|
if (args.length) throw new UsageError();
|
|
218
|
-
const entry =
|
|
326
|
+
const entry = dashboardEntry();
|
|
219
327
|
const home = alpHome();
|
|
328
|
+
reportMigration(await migrateDashboard(home, { strict: true }));
|
|
220
329
|
await start();
|
|
221
330
|
const project = await projectArgs();
|
|
222
331
|
for (let attempt = 1; ; attempt++) {
|
|
223
|
-
await
|
|
332
|
+
await stopService(home);
|
|
224
333
|
const rotated = await new Promise(resolve => {
|
|
225
|
-
const rotate = entryCommand(entry, '
|
|
334
|
+
const rotate = entryCommand(entry, 'dashboard', ['--rotate', ...project]);
|
|
226
335
|
execFile(rotate.command, rotate.args, { env: { ...process.env, ALP_HOME: home }, encoding: 'utf8', timeout: 60_000, killSignal: 'SIGTERM' },
|
|
227
336
|
(error, stdout, stderr) => resolve({ code: error ? (typeof error.code === 'number' ? error.code : 1) : 0, output: `${stderr}${stdout}`.trim() }));
|
|
228
337
|
});
|
|
229
338
|
if (rotated.code === 0) break;
|
|
230
|
-
// Exit 3: alp
|
|
231
|
-
if (rotated.code !== 3 || attempt >= 3) throw new Error(`alp
|
|
339
|
+
// Exit 3: alp dashboard started again between the stop and the rotation; stop it once more.
|
|
340
|
+
if (rotated.code !== 3 || attempt >= 3) throw new Error(`alp dashboard could not rotate its token${rotated.output ? `:\n${rotated.output.slice(-2000)}` : ''}`);
|
|
232
341
|
}
|
|
233
|
-
if (await
|
|
234
|
-
console.log(`alp
|
|
342
|
+
if (await dashboardDisabled(home)) {
|
|
343
|
+
console.log(`alp dashboard has a new token; the old one no longer works. ${DISABLED.replace(/\.$/, '')}, so it was not started.`);
|
|
235
344
|
return;
|
|
236
345
|
}
|
|
237
|
-
console.log(await
|
|
346
|
+
console.log(await serveDashboard(home, entry));
|
|
238
347
|
}
|
|
239
348
|
|
|
240
349
|
/**
|
|
241
|
-
* alp
|
|
350
|
+
* alp dashboard pair: the link that pairs Paseo's app on another device with alpd through Paseo's relay
|
|
242
351
|
* (ALPD §64). The device then signs in with the password this command prints (the token kept in
|
|
243
352
|
* ~/.alp/paseo.json).
|
|
244
353
|
*/
|
|
@@ -260,7 +369,7 @@ export async function requestPairing(client, params, attempts = 50) {
|
|
|
260
369
|
if (!unknown) throw outcome.error;
|
|
261
370
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
262
371
|
}
|
|
263
|
-
throw last ?? new Error('alpd did not register web.pairing; run `alp
|
|
372
|
+
throw last ?? new Error('alpd did not register web.pairing; run `alp dashboard pair` again to let the integration start');
|
|
264
373
|
}
|
|
265
374
|
|
|
266
375
|
async function pairCommand(args) {
|
|
@@ -273,7 +382,7 @@ async function pairCommand(args) {
|
|
|
273
382
|
try {
|
|
274
383
|
const pairing = await requestPairing(client, values.on ? { enable: true } : values.off ? { enable: false } : {});
|
|
275
384
|
if (!pairing.relayEnabled) {
|
|
276
|
-
console.log(`The relay is off${values.off ? ' now' : ''}. Turn it on with: alp
|
|
385
|
+
console.log(`The relay is off${values.off ? ' now' : ''}. Turn it on with: alp dashboard pair --on`);
|
|
277
386
|
return;
|
|
278
387
|
}
|
|
279
388
|
console.log(`Relay ${pairing.endpoint}: ${pairing.connected ? 'connected' : 'connecting'}`);
|
|
@@ -295,4 +404,4 @@ async function acpCommand(args) {
|
|
|
295
404
|
await runAcp({ daemonEntry: DAEMON_ENTRY });
|
|
296
405
|
}
|
|
297
406
|
|
|
298
|
-
export {
|
|
407
|
+
export { dashboardCommand, pairCommand, acpCommand };
|
package/src/paths.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { selfEntry } from '@anhlp/alp-core/packaged';
|
|
4
|
+
import { daemonEntry, selfEntry } from '@anhlp/alp-core/packaged';
|
|
5
5
|
|
|
6
6
|
/** Locate artifacts in either the independently shipped CLI or the legacy root build. */
|
|
7
7
|
export function distributionEntry(name) {
|
|
@@ -14,5 +14,11 @@ export function distributionEntry(name) {
|
|
|
14
14
|
return candidates.find(candidate => existsSync(candidate)) ?? candidates[0];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
export const
|
|
17
|
+
/** alpd.js, which `alp daemon run` runs in this process (named through app/current in the ALP bundle). */
|
|
18
|
+
export const DAEMON_SCRIPT = selfEntry(fileURLToPath(distributionEntry('alpd.js')));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* What starts alpd: the bundle's native alpd when it ships one (t-81b0.9), else alpd.js under Node;
|
|
22
|
+
* ALP_NATIVE_DAEMON=0 keeps the Node alpd. Named through app/current in the ALP bundle.
|
|
23
|
+
*/
|
|
24
|
+
export const DAEMON_ENTRY = daemonEntry(fileURLToPath(distributionEntry('alpd.js')));
|
package/src/roles.js
CHANGED
|
@@ -3,14 +3,14 @@ import { runBridge } from '@anhlp/alp-core/bridges';
|
|
|
3
3
|
import { UsageError } from './usage.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* The role subcommands (t-1e02): `alp daemon run`, `alp
|
|
7
|
-
* run alpd, alp-
|
|
8
|
-
* `node alpd.js` and `node alp-
|
|
6
|
+
* The role subcommands (t-1e02): `alp daemon run`, `alp dashboard serve` and `alp bridge acp|antigravity`
|
|
7
|
+
* run alpd, alp-dashboard and the MCP bridges in this process: they import the same scripts that
|
|
8
|
+
* `node alpd.js` and `node alp-dashboard.js` run. Services and MCP entries written by the single-file
|
|
9
9
|
* executable of 0.0.1-beta.5/6 still name them.
|
|
10
10
|
*
|
|
11
11
|
* The role's module reads its options from process.argv as when run directly, so argv is rewritten
|
|
12
12
|
* to `[runtime, entry, ...args]` before the module loads.
|
|
13
|
-
* @param {'daemon' | '
|
|
13
|
+
* @param {'daemon' | 'dashboard' | 'acp'} role
|
|
14
14
|
* @param {string} file the role's script beside this CLI
|
|
15
15
|
* @param {string[]} args
|
|
16
16
|
*/
|
package/src/self-update.js
CHANGED
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import { createInterface } from 'node:readline/promises';
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
8
|
import { parseArgs } from 'node:util';
|
|
9
|
-
import { bundleInfo, samePath } from '@anhlp/alp-core/packaged';
|
|
9
|
+
import { bundleInfo, NATIVE_DAEMON, samePath } from '@anhlp/alp-core/packaged';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* `alp update` (t-1807): installs a release of the ALP bundle from GitHub Releases beside the running
|
|
@@ -304,7 +304,7 @@ async function confirm(question) {
|
|
|
304
304
|
* fetchBytes: (url: string) => Promise<Uint8Array>, confirm: (question: string) => Promise<boolean>,
|
|
305
305
|
* provenance: (file: string, repo: string) => string, extract: typeof extract,
|
|
306
306
|
* daemon: () => Promise<{ version: string, sessions?: number } | undefined>, restartDaemon: (root: string) => number,
|
|
307
|
-
* runVersion: (root: string) => string,
|
|
307
|
+
* runVersion: (root: string) => string, runDaemonVersion: (root: string) => string,
|
|
308
308
|
* }} UpdateDeps
|
|
309
309
|
*/
|
|
310
310
|
|
|
@@ -319,6 +319,8 @@ export async function selfUpdate(args, overrides = {}) {
|
|
|
319
319
|
daemon: async () => undefined,
|
|
320
320
|
restartDaemon: root => { const run = bundleCommand(root); return spawnSync(run.command, [...run.args, 'daemon', 'restart'], { stdio: 'inherit', windowsHide: true }).status ?? 1; },
|
|
321
321
|
runVersion: root => { const run = bundleCommand(root); return spawnSync(run.command, [...run.args, '--version'], { encoding: 'utf8', windowsHide: true, timeout: 60_000 }).stdout?.trim() ?? ''; },
|
|
322
|
+
// Without BUN_BE_BUN, which would make the native alpd the Bun CLI.
|
|
323
|
+
runDaemonVersion: root => spawnSync(path.join(root, 'bin', NATIVE_DAEMON), ['--version'], { encoding: 'utf8', windowsHide: true, timeout: 60_000, env: Object.fromEntries(Object.entries(process.env).filter(([name]) => name !== 'BUN_BE_BUN')) }).stdout?.trim() ?? '',
|
|
322
324
|
...overrides,
|
|
323
325
|
};
|
|
324
326
|
const { bundle } = deps;
|
|
@@ -392,6 +394,12 @@ export async function selfUpdate(args, overrides = {}) {
|
|
|
392
394
|
if (manifest.version !== asset.version || (manifest.platform && manifest.platform !== platform)) throw new Error(`${asset.name} holds ALP ${manifest.version} for ${manifest.platform}, not ${asset.version} for ${platform}; nothing was changed`);
|
|
393
395
|
const reported = deps.runVersion(unpacked);
|
|
394
396
|
if (reported !== asset.version) throw new Error(`The downloaded ALP reports version ${JSON.stringify(reported)}, not ${asset.version}; nothing was changed`);
|
|
397
|
+
// The native alpd (t-81b0.9) must run on this machine too: an old CPU, glibc or a quarantined file would
|
|
398
|
+
// otherwise leave alp without a daemon after the switch.
|
|
399
|
+
if (deps.env.ALP_NATIVE_DAEMON !== '0' && nodeFs.existsSync(path.join(unpacked, 'bin', NATIVE_DAEMON))) {
|
|
400
|
+
const native = deps.runDaemonVersion(unpacked);
|
|
401
|
+
if (native !== asset.version) throw new Error(`The downloaded ALP's native alpd (bin/${NATIVE_DAEMON}) reports version ${JSON.stringify(native)}, not ${asset.version}, so it cannot run here; nothing was changed. To update with alpd on the bundled Node, set ALP_NATIVE_DAEMON=0 for this update and keep it set`);
|
|
402
|
+
}
|
|
395
403
|
if (nodeFs.existsSync(target)) {
|
|
396
404
|
// A reinstall of the running version moves it aside (its processes keep their files); any other copy is stale.
|
|
397
405
|
if (samePath(target, bundle.root) || running?.version === asset.version) {
|
package/src/sessions.js
CHANGED
|
@@ -410,8 +410,6 @@ async function recall(args) {
|
|
|
410
410
|
console.log(answer.answer);
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
/** alp web: opens the web app alpd serves on 127.0.0.1, with the token in the address (ALPD §61). */
|
|
414
|
-
|
|
415
413
|
async function interrupt(args) {
|
|
416
414
|
if (args.length !== 1) throw new UsageError();
|
|
417
415
|
const client = await running();
|
package/src/usage.js
CHANGED
|
@@ -14,11 +14,13 @@ const USAGE = `Usage:
|
|
|
14
14
|
alp daemon <install|uninstall> run alpd as a login service that restarts after a crash
|
|
15
15
|
alp daemon run [--detach] [--service] run alpd in this process (what services written by 0.0.1-beta.5/6 start)
|
|
16
16
|
alp acp serve ALP to an editor (Zed, JetBrains) over the Agent Client Protocol on stdio
|
|
17
|
-
alp
|
|
18
|
-
alp
|
|
17
|
+
alp dashboard [--port N] [--host 127.0.0.1|localhost] [--no-open|--print] open ALP's dashboard in the browser (alp-dashboard, loopback only); --no-open/--print only print its address
|
|
18
|
+
alp dashboard --status|--stop whether alp dashboard runs (address without its token) | stop it
|
|
19
|
+
alp desktop open ALP's desktop app (ALP.app, else the checkout in ALP_DESKTOP_CHECKOUT)
|
|
20
|
+
alp dashboard serve [--service|--rotate] [--project DIR] [--port N] run alp-dashboard in this process (what alp dashboard starts)
|
|
19
21
|
alp bridge <acp|antigravity> the stdio MCP bridge an agent CLI starts to reach alpd (internal)
|
|
20
|
-
alp
|
|
21
|
-
alp
|
|
22
|
+
alp dashboard rotate give alp dashboard a new token: open pages lose access; prints the new address
|
|
23
|
+
alp dashboard pair [--on|--off] the link that pairs Paseo's app on another device through the relay; --on or --off turns the relay on or off
|
|
22
24
|
alp terminal <allow [--paseo] --yes|deny [--paseo]|status> [--json] remote terminals (a shell as you on this host; a workspace is not a sandbox), off by default
|
|
23
25
|
alp doctor [--project DIR] [--fix] [--json] check this machine and project; --fix repairs what is safe to
|
|
24
26
|
alp backup [-o FILE] [--project DIR]... [--no-projects] [--stop] [--json] sessions, settings, library and tasks in one file
|
package/dist/web-service.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** The alp-web service script beside this CLI; a clear error when this CLI was built without it. */
|
|
2
|
-
export function alpWebScript(): string;
|
|
3
|
-
/**
|
|
4
|
-
* The process that owns alp web'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 web.json 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
|
|
13
|
-
* @returns {Promise<{ pid: number, app: unknown } | { reason: string, alive: boolean, kind?: 'transient' | 'foreign' | 'unknown' }>}
|
|
14
|
-
*/
|
|
15
|
-
export function webOwner(home: string): Promise<{
|
|
16
|
-
pid: number;
|
|
17
|
-
app: unknown;
|
|
18
|
-
} | {
|
|
19
|
-
reason: string;
|
|
20
|
-
alive: boolean;
|
|
21
|
-
kind?: "transient" | "foreign" | "unknown";
|
|
22
|
-
}>;
|
|
23
|
-
/**
|
|
24
|
-
* Stops the Paseo integration from before its rename when it still runs as integration `web` (its
|
|
25
|
-
* web.json has no `app: 'alp-web'`), so alp-web can take the lock and web.port. Returns the pid it
|
|
26
|
-
* stopped. A process that cannot be proven to be that integration is left alone.
|
|
27
|
-
* @param {string} home
|
|
28
|
-
*/
|
|
29
|
-
export function stopPreRenamePaseo(home: string): Promise<number | undefined>;
|
|
30
|
-
/**
|
|
31
|
-
* Stops whatever runs as integration `web` (alp-web, or the Paseo integration from before its
|
|
32
|
-
* rename), waiting up to `timeoutMs` for a starting owner to publish what proves it. Resolves once
|
|
33
|
-
* no live process owns the lock; refuses at once an owner that is foreign or cannot be proven.
|
|
34
|
-
* @param {string} home @param {number} [timeoutMs]
|
|
35
|
-
*/
|
|
36
|
-
export function stopWebService(home: string, timeoutMs?: number): Promise<number | undefined>;
|
|
37
|
-
/** The opening of the message for a web lock held by a process alp would not stop. @param {string} home */
|
|
38
|
-
export function refusal(home: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Probes whether the published web service URL is live and answering requests.
|
|
41
|
-
* Accepts only loopback HTTP/HTTPS addresses.
|
|
42
|
-
* @param {string | undefined} url
|
|
43
|
-
* @param {number} [timeoutMs]
|
|
44
|
-
*/
|
|
45
|
-
export function isWebReady(url: string | undefined, timeoutMs?: number): Promise<boolean>;
|
|
46
|
-
/**
|
|
47
|
-
* Whether web metadata is genuinely claimed by a live alp-web process.
|
|
48
|
-
* If the process is proven foreign (e.g. a reused PID or from another boot) or
|
|
49
|
-
* the URL does not answer HTTP requests, it is never claimed.
|
|
50
|
-
* @param {any} published
|
|
51
|
-
* @param {number | undefined} lockPid
|
|
52
|
-
* @param {any} held
|
|
53
|
-
* @param {number} [timeoutMs]
|
|
54
|
-
*/
|
|
55
|
-
export function isWebClaimed(published: any, lockPid: number | undefined, held: any, timeoutMs?: number): Promise<boolean>;
|
|
56
|
-
export function alpWebEntry(): string;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|