@anhlp/alp-cli 0.0.1-beta.3 → 0.0.1-beta.6
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/THIRD-PARTY-NOTICES.txt +51 -1
- package/dist/acp/main.js +1 -1
- package/dist/acp.js +300 -92
- package/dist/alp-web/THIRD-PARTY-NOTICES.txt +3256 -0
- package/dist/alp-web/alp-boundary.json +16 -0
- package/dist/alp-web/apple-touch-icon.png +0 -0
- package/dist/alp-web/assets/TerminalPanel-CqTsgY-W.js +22 -0
- package/dist/alp-web/assets/TerminalPanel-DLuoa74B.css +1 -0
- package/dist/alp-web/assets/highlighter-BnicKQ_d.js +18 -0
- package/dist/alp-web/assets/index-BMbDUCHW.css +1 -0
- package/dist/alp-web/assets/index-B_RFaj2C.js +59 -0
- package/dist/alp-web/favicon-attention.svg +6 -0
- package/dist/alp-web/favicon-running.svg +6 -0
- package/dist/alp-web/favicon.svg +5 -0
- package/dist/alp-web/index.html +20 -0
- package/dist/alp-web.js +10119 -0
- package/dist/alpd.js +30333 -15153
- package/dist/backup.js +2 -2
- package/dist/build-manifest.json +120 -2
- package/dist/cli.js +34 -3
- package/dist/daemon.d.ts +1 -1
- package/dist/daemon.js +5 -0
- package/dist/interfaces.d.ts +22 -2
- package/dist/interfaces.js +182 -37
- package/dist/paths.d.ts +1 -0
- package/dist/paths.js +2 -1
- package/dist/roles.d.ts +15 -0
- package/dist/roles.js +18 -0
- package/dist/schedules.d.ts +2 -0
- package/dist/schedules.js +45 -0
- package/dist/self-update.d.ts +152 -0
- package/dist/self-update.js +390 -0
- package/dist/sessions.d.ts +7 -1
- package/dist/sessions.js +44 -12
- package/dist/tasks.js +22 -8
- package/dist/terminal-native/README.md +201 -0
- package/dist/terminal-native/prebuilt/darwin-arm64/manifest.json +11 -0
- package/dist/terminal-native/prebuilt/darwin-arm64/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/darwin-x64/manifest.json +11 -0
- package/dist/terminal-native/prebuilt/darwin-x64/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-arm64-musl/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-x64-glibc/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-x64-musl/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-x64-musl/terminal-owner +0 -0
- package/dist/terminal-native/terminal-owner.c +389 -0
- package/dist/terminal.d.ts +13 -0
- package/dist/terminal.js +80 -0
- package/dist/usage.d.ts +1 -1
- package/dist/usage.js +22 -7
- package/dist/web-service.d.ts +56 -0
- package/dist/web-service.js +143 -0
- package/package.json +11 -4
- package/src/backup.js +1 -1
- package/src/cli.js +40 -4
- package/src/daemon.js +3 -0
- package/src/interfaces.js +227 -32
- package/src/paths.js +3 -1
- package/src/roles.js +28 -0
- package/src/schedules.js +38 -0
- package/src/self-update.js +406 -0
- package/src/sessions.js +44 -13
- package/src/tasks.js +22 -8
- package/src/terminal.js +78 -0
- package/src/usage.js +22 -7
- package/src/web-service.js +187 -0
package/dist/paths.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { selfEntry } from "@anhlp/alp-core/packaged";
|
|
5
6
|
function distributionEntry(name) {
|
|
6
7
|
const entry = process.argv[1] && path.basename(process.argv[1]) === "cli.js" ? pathToFileURL(path.resolve(process.argv[1])) : void 0;
|
|
7
8
|
const candidates = [
|
|
@@ -11,7 +12,7 @@ function distributionEntry(name) {
|
|
|
11
12
|
];
|
|
12
13
|
return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];
|
|
13
14
|
}
|
|
14
|
-
var DAEMON_ENTRY = fileURLToPath(distributionEntry("alpd.js"));
|
|
15
|
+
var DAEMON_ENTRY = selfEntry(fileURLToPath(distributionEntry("alpd.js")));
|
|
15
16
|
export {
|
|
16
17
|
DAEMON_ENTRY,
|
|
17
18
|
distributionEntry
|
package/dist/roles.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The role subcommands (t-1e02): `alp daemon run`, `alp web serve` and `alp bridge acp|antigravity`
|
|
3
|
+
* run alpd, alp-web and the MCP bridges in this process. The ALP executable starts its own roles
|
|
4
|
+
* this way, since it cannot run a script path; under Node they import the same scripts that
|
|
5
|
+
* `node alpd.js` and `node alp-web.js` run.
|
|
6
|
+
*
|
|
7
|
+
* The role's module reads its options from process.argv as when run directly, so argv is rewritten
|
|
8
|
+
* to `[runtime, entry, ...args]` before the module loads.
|
|
9
|
+
* @param {'daemon' | 'web' | 'acp'} role
|
|
10
|
+
* @param {string} file the role's script beside this CLI
|
|
11
|
+
* @param {string[]} args
|
|
12
|
+
*/
|
|
13
|
+
export function runRole(role: "daemon" | "web" | "acp", file: string, args: string[]): Promise<any>;
|
|
14
|
+
/** alp bridge acp|antigravity: the stdio MCP bridge an agent CLI starts to reach alpd's tools. @param {string[]} args */
|
|
15
|
+
export function bridgeCommand(args: string[]): void;
|
package/dist/roles.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// packages/cli/src/roles.js
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { runBridge } from "@anhlp/alp-core/bridges";
|
|
4
|
+
import { packagedInfo } from "@anhlp/alp-core/packaged";
|
|
5
|
+
import { UsageError } from "./usage.js";
|
|
6
|
+
async function runRole(role, file, args) {
|
|
7
|
+
process.argv = [process.argv[0], file, ...args];
|
|
8
|
+
const load = packagedInfo()?.roles?.[role];
|
|
9
|
+
return load ? load() : import(pathToFileURL(file).href);
|
|
10
|
+
}
|
|
11
|
+
function bridgeCommand(args) {
|
|
12
|
+
if (args.length !== 1 || !["acp", "antigravity"].includes(args[0])) throw new UsageError();
|
|
13
|
+
runBridge(args[0]);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
bridgeCommand,
|
|
17
|
+
runRole
|
|
18
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// packages/cli/src/schedules.js
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { running } from "./daemon.js";
|
|
5
|
+
import { UsageError } from "./usage.js";
|
|
6
|
+
async function scheduleCommand(args) {
|
|
7
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: {
|
|
8
|
+
project: { type: "string" },
|
|
9
|
+
session: { type: "string" },
|
|
10
|
+
at: { type: "string" },
|
|
11
|
+
prompt: { type: "string" },
|
|
12
|
+
status: { type: "string" },
|
|
13
|
+
json: { type: "boolean" }
|
|
14
|
+
} });
|
|
15
|
+
const [action, id, ...extra] = positionals;
|
|
16
|
+
if (!["create", "list", "show", "cancel"].includes(action) || extra.length) throw new UsageError();
|
|
17
|
+
if (action === "show" || action === "cancel" ? !id : !!id) throw new UsageError();
|
|
18
|
+
if (action !== "create" && (values.session || values.at || values.prompt)) throw new UsageError();
|
|
19
|
+
if (action !== "list" && values.status) throw new UsageError();
|
|
20
|
+
if (action === "create" && (!values.session || !values.prompt?.trim() || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})$/.test(values.at ?? "") || !Number.isFinite(Date.parse(values.at)))) throw new Error("create needs --session, --prompt and --at ISO timestamp with Z or a UTC offset (for example 2026-10-20T16:00:00+07:00)");
|
|
21
|
+
const projectRoot = path.resolve(values.project ?? process.cwd());
|
|
22
|
+
const params = action === "create" ? { projectRoot, sessionId: values.session, dueAt: values.at, prompt: values.prompt } : { projectRoot, ...id ? { id } : {}, ...values.status ? { status: values.status } : {} };
|
|
23
|
+
const client = await running();
|
|
24
|
+
try {
|
|
25
|
+
const result = await client.request(`schedule.${action === "show" ? "get" : action}`, params);
|
|
26
|
+
if (values.json) {
|
|
27
|
+
console.log(JSON.stringify(result));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const jobs = result.jobs ?? [result.job];
|
|
31
|
+
if (!jobs.length) console.log("No scheduled continuations");
|
|
32
|
+
for (const job of jobs) {
|
|
33
|
+
console.log(`${job.id} ${job.status} ${job.dueAt} session ${job.sessionId}`);
|
|
34
|
+
console.log(` ${job.prompt}`);
|
|
35
|
+
if (job.attemptedAt) console.log(` attempted ${job.attemptedAt}; attempts ${job.attempts}; late ${job.lateByMs ?? 0} ms`);
|
|
36
|
+
for (const field of ["deliveredAt", "failedAt", "cancelledAt"]) if (job[field]) console.log(` ${field}: ${job[field]}`);
|
|
37
|
+
if (job.lastError) console.log(` ${job.lastError.code ?? "error"}: ${job.lastError.message}`);
|
|
38
|
+
}
|
|
39
|
+
} finally {
|
|
40
|
+
client.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
scheduleCommand
|
|
45
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/** The release platform of this process: darwin-arm64, linux-x64, windows-x64. @param {string} platform @param {string} arch */
|
|
2
|
+
export function releasePlatform(platform?: string, arch?: string): string;
|
|
3
|
+
/** Parses SHA256SUMS into [{ sha256, name }]. @param {string} text */
|
|
4
|
+
export function parseSums(text: string): {
|
|
5
|
+
sha256: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}[];
|
|
8
|
+
/**
|
|
9
|
+
* The archive for `platform` in SHA256SUMS: alp-<version>-<platform>.<ext>, for `version` when given.
|
|
10
|
+
* @param {string} sumsText @param {string} platform @param {string} [version]
|
|
11
|
+
* @returns {{ name: string, sha256: string, version: string }}
|
|
12
|
+
*/
|
|
13
|
+
export function selectAsset(sumsText: string, platform: string, version?: string): {
|
|
14
|
+
name: string;
|
|
15
|
+
sha256: string;
|
|
16
|
+
version: string;
|
|
17
|
+
};
|
|
18
|
+
/** Refuses an archive whose digest differs from SHA256SUMS. @param {Uint8Array} bytes @param {{ name: string, sha256: string }} asset */
|
|
19
|
+
export function verifyChecksum(bytes: Uint8Array, asset: {
|
|
20
|
+
name: string;
|
|
21
|
+
sha256: string;
|
|
22
|
+
}): string;
|
|
23
|
+
/** Compares dotted versions numerically, prerelease below release. @param {string} a @param {string} b */
|
|
24
|
+
export function compareVersions(a: string, b: string): number;
|
|
25
|
+
/** The base URL that holds SHA256SUMS and the archives. @param {{ repo: string, version?: string, baseUrl?: string }} options */
|
|
26
|
+
export function releaseBaseUrl({ repo, version, baseUrl }: {
|
|
27
|
+
repo: string;
|
|
28
|
+
version?: string;
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether a download may go to `next`: every hop of an https download stays https, since one plain
|
|
33
|
+
* http hop lets a man in the middle replace the archive and SHA256SUMS together. Only a loopback
|
|
34
|
+
* http mirror given explicitly (tests) may use loopback http, besides https.
|
|
35
|
+
* @param {string} start @param {string} next
|
|
36
|
+
*/
|
|
37
|
+
export function allowedHop(start: string, next: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Downloads `url` (https, loopback http or file) within a time and size limit, following at most 10
|
|
40
|
+
* redirects itself and refusing any hop that `allowedHop` refuses.
|
|
41
|
+
* @param {string} url @param {{ timeoutMs?: number, max?: number, fetch?: typeof globalThis.fetch }} [options]
|
|
42
|
+
*/
|
|
43
|
+
export function fetchBytes(url: string, { timeoutMs, max, fetch: fetchImpl }?: {
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
max?: number;
|
|
46
|
+
fetch?: typeof globalThis.fetch;
|
|
47
|
+
}): Promise<Uint8Array<ArrayBuffer>>;
|
|
48
|
+
/**
|
|
49
|
+
* Verifies the archive's build provenance with gh. Returns 'verified', or 'unavailable' when gh is
|
|
50
|
+
* absent (ALP_UPDATE_NO_GH=1 treats it as absent); throws when gh reports a failure.
|
|
51
|
+
* @param {string} file @param {{ repo: string, env?: NodeJS.ProcessEnv, run?: typeof spawnSync, find?: typeof which }} options
|
|
52
|
+
*/
|
|
53
|
+
export function verifyProvenance(file: string, { repo, env, run, find }: {
|
|
54
|
+
repo: string;
|
|
55
|
+
env?: NodeJS.ProcessEnv;
|
|
56
|
+
run?: typeof spawnSync;
|
|
57
|
+
find?: typeof which;
|
|
58
|
+
}): "unavailable" | "verified";
|
|
59
|
+
/**
|
|
60
|
+
* Runs `action`, again after a pause while Windows reports the file busy: a virus scanner holds an
|
|
61
|
+
* executable it just saw run (the staged file's --version) for a moment. About 6 s in all.
|
|
62
|
+
* @template T @param {() => T} action @param {(ms: number) => void} [sleep]
|
|
63
|
+
*/
|
|
64
|
+
export function retryBusy<T>(action: () => T, sleep?: (ms: number) => void, attempts?: number): T;
|
|
65
|
+
/**
|
|
66
|
+
* Puts `staged` in place of `target`. Unix: rename over the running file. Windows: the running
|
|
67
|
+
* alp.exe cannot be overwritten but can be renamed, so it becomes alp.old.exe (deleted on the next
|
|
68
|
+
* start) and the new file takes its name; a failure puts the old one back.
|
|
69
|
+
* @param {string} staged @param {string} target @param {{ platform?: string, fs?: Pick<typeof nodeFs, 'renameSync' | 'rmSync' | 'existsSync'>, unique?: () => string, sleep?: (ms: number) => void }} [options]
|
|
70
|
+
*/
|
|
71
|
+
export function replaceExecutable(staged: string, target: string, { platform, fs, unique, sleep }?: {
|
|
72
|
+
platform?: string;
|
|
73
|
+
fs?: Pick<typeof nodeFs, "renameSync" | "rmSync" | "existsSync">;
|
|
74
|
+
unique?: () => string;
|
|
75
|
+
sleep?: (ms: number) => void;
|
|
76
|
+
}): {
|
|
77
|
+
old: undefined;
|
|
78
|
+
} | {
|
|
79
|
+
old: string;
|
|
80
|
+
};
|
|
81
|
+
/** Deletes the alp.old.exe (and alp.old.<hex>.exe) a Windows update left behind; called on every packaged start. @param {string} target @param {{ platform?: string, fs?: Pick<typeof nodeFs, 'rmSync' | 'readdirSync'> }} [options] */
|
|
82
|
+
export function cleanupOldExecutable(target: string, { platform, fs }?: {
|
|
83
|
+
platform?: string;
|
|
84
|
+
fs?: Pick<typeof nodeFs, "rmSync" | "readdirSync">;
|
|
85
|
+
}): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Whether the executable is the one npm installed for @anhlp/alp (t-cd7f): it lives in a platform
|
|
88
|
+
* package, node_modules/@anhlp/alp-<os>-<arch>/bin/. npm owns that file; updating it in place would
|
|
89
|
+
* leave npm's records behind, so npm updates it. @param {string} execPath
|
|
90
|
+
*/
|
|
91
|
+
export function isNpmExecutable(execPath: string): boolean;
|
|
92
|
+
/** What to say outside the executable (an npm install). @param {string[]} positionals */
|
|
93
|
+
export function npmMessage(positionals?: string[]): string;
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {{
|
|
96
|
+
* packaged: boolean, version: string, execPath: string, env: NodeJS.ProcessEnv, platform: string, arch: string,
|
|
97
|
+
* log: (line: string) => void, warn: (line: string) => void, interactive: boolean,
|
|
98
|
+
* fetchBytes: (url: string) => Promise<Uint8Array>, confirm: (question: string) => Promise<boolean>,
|
|
99
|
+
* provenance: (file: string, repo: string) => string, extract: typeof extract,
|
|
100
|
+
* daemon: () => Promise<{ version: string, sessions?: number } | undefined>, restartDaemon: (binary: string) => number,
|
|
101
|
+
* runVersion: (binary: string) => string,
|
|
102
|
+
* }} UpdateDeps
|
|
103
|
+
*/
|
|
104
|
+
/** @param {string[]} args @param {Partial<UpdateDeps>} [overrides] @returns {Promise<number>} the exit code */
|
|
105
|
+
export function selfUpdate(args: string[], overrides?: Partial<UpdateDeps>): Promise<number>;
|
|
106
|
+
/**
|
|
107
|
+
* `alp update` (t-1e02 P3): replaces the ALP executable with a release from GitHub Releases, after
|
|
108
|
+
* checking the archive against the release's SHA256SUMS and, when `gh` is installed, its build
|
|
109
|
+
* provenance. The project template upgrade that `alp update` used to run is `alp update-template`.
|
|
110
|
+
*
|
|
111
|
+
* Everything that touches the network, the filesystem or child processes comes in through `deps`
|
|
112
|
+
* so the tests can drive each step.
|
|
113
|
+
*/
|
|
114
|
+
export const DEFAULT_REPO: "phucanh08/alp";
|
|
115
|
+
export const SIGNER_WORKFLOW: ".github/workflows/release-binaries.yml";
|
|
116
|
+
export const NPM_PACKAGE: "@anhlp/alp";
|
|
117
|
+
export const UPDATE_USAGE: "Usage: alp update [--check] [--yes] [--version X] [--base-url URL]\nReplaces this ALP executable with the latest release (or release X) from GitHub Releases, after checking\nit against SHA256SUMS and, when gh is installed, its build provenance. --check only reports.\nALP_UPDATE_BASE_URL (as --base-url, an https:// or file:// mirror) and ALP_INSTALL_REPO (owner/name) override the source.\nThe project template upgrade is `alp update-template [directory]`.";
|
|
118
|
+
export function archiveExtension(platform: string): ".zip" | ".tar.gz";
|
|
119
|
+
export function sha256(bytes: Uint8Array): string;
|
|
120
|
+
/** The largest file alp update downloads: the executable is about 100 MB. */
|
|
121
|
+
export const MAX_DOWNLOAD: number;
|
|
122
|
+
export function oldPath(target: string, platform?: string): string;
|
|
123
|
+
export type UpdateDeps = {
|
|
124
|
+
packaged: boolean;
|
|
125
|
+
version: string;
|
|
126
|
+
execPath: string;
|
|
127
|
+
env: NodeJS.ProcessEnv;
|
|
128
|
+
platform: string;
|
|
129
|
+
arch: string;
|
|
130
|
+
log: (line: string) => void;
|
|
131
|
+
warn: (line: string) => void;
|
|
132
|
+
interactive: boolean;
|
|
133
|
+
fetchBytes: (url: string) => Promise<Uint8Array>;
|
|
134
|
+
confirm: (question: string) => Promise<boolean>;
|
|
135
|
+
provenance: (file: string, repo: string) => string;
|
|
136
|
+
extract: typeof extract;
|
|
137
|
+
daemon: () => Promise<{
|
|
138
|
+
version: string;
|
|
139
|
+
sessions?: number;
|
|
140
|
+
} | undefined>;
|
|
141
|
+
restartDaemon: (binary: string) => number;
|
|
142
|
+
runVersion: (binary: string) => string;
|
|
143
|
+
};
|
|
144
|
+
import { spawnSync } from 'node:child_process';
|
|
145
|
+
/** Whether a program is on PATH. @param {string} name */
|
|
146
|
+
declare function which(name: string): string | undefined;
|
|
147
|
+
import * as nodeFs from 'node:fs';
|
|
148
|
+
/** Extracts the archive and returns the executable inside it. @param {string} archive @param {string} directory @param {{ name: string }} asset @param {string} platform */
|
|
149
|
+
declare function extract(archive: string, directory: string, asset: {
|
|
150
|
+
name: string;
|
|
151
|
+
}, platform: string, run?: typeof spawnSync): string;
|
|
152
|
+
export {};
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
// packages/cli/src/self-update.js
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
4
|
+
import * as nodeFs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { createInterface } from "node:readline/promises";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
import { executablePath } from "@anhlp/alp-core/packaged";
|
|
11
|
+
var DEFAULT_REPO = "phucanh08/alp";
|
|
12
|
+
var SIGNER_WORKFLOW = ".github/workflows/release-binaries.yml";
|
|
13
|
+
var NPM_PACKAGE = "@anhlp/alp";
|
|
14
|
+
var TEMPLATE_HINT = "did you mean `alp update-template`? (`alp update` now updates the ALP executable; the project template upgrade is `alp update-template [directory]`)";
|
|
15
|
+
var OPTIONS = { check: { type: "boolean" }, yes: { type: "boolean", short: "y" }, version: { type: "string" }, "base-url": { type: "string" }, help: { type: "boolean", short: "h" } };
|
|
16
|
+
var UPDATE_USAGE = `Usage: alp update [--check] [--yes] [--version X] [--base-url URL]
|
|
17
|
+
Replaces this ALP executable with the latest release (or release X) from GitHub Releases, after checking
|
|
18
|
+
it against SHA256SUMS and, when gh is installed, its build provenance. --check only reports.
|
|
19
|
+
ALP_UPDATE_BASE_URL (as --base-url, an https:// or file:// mirror) and ALP_INSTALL_REPO (owner/name) override the source.
|
|
20
|
+
The project template upgrade is \`alp update-template [directory]\`.`;
|
|
21
|
+
function releasePlatform(platform = process.platform, arch = process.arch) {
|
|
22
|
+
const osName = { darwin: "darwin", linux: "linux", win32: "windows" }[platform];
|
|
23
|
+
const archName = { x64: "x64", arm64: "arm64" }[arch];
|
|
24
|
+
if (!osName || !archName || osName === "windows" && archName !== "x64") throw new Error(`ALP publishes no executable for ${platform}-${arch}`);
|
|
25
|
+
return `${osName}-${archName}`;
|
|
26
|
+
}
|
|
27
|
+
var archiveExtension = (platform) => platform.startsWith("windows-") ? ".zip" : ".tar.gz";
|
|
28
|
+
function parseSums(text) {
|
|
29
|
+
const entries = [];
|
|
30
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
31
|
+
const line = raw.trim();
|
|
32
|
+
if (!line) continue;
|
|
33
|
+
const match = /^([0-9a-fA-F]{64}) [ *]?(.+)$/.exec(line);
|
|
34
|
+
if (!match) throw new Error(`Malformed SHA256SUMS line: ${JSON.stringify(line)}`);
|
|
35
|
+
entries.push({ sha256: match[1].toLowerCase(), name: match[2].trim() });
|
|
36
|
+
}
|
|
37
|
+
return entries;
|
|
38
|
+
}
|
|
39
|
+
function selectAsset(sumsText, platform, version) {
|
|
40
|
+
const suffix = `-${platform}${archiveExtension(platform)}`;
|
|
41
|
+
const matches = parseSums(sumsText).filter(({ name }) => name.endsWith(suffix) && /^alp-[0-9]/.test(name) && (!version || name === `alp-${version}${suffix}`));
|
|
42
|
+
if (matches.length === 0) throw new Error(`This release has no ALP executable for ${platform}${version ? ` at version ${version}` : ""}`);
|
|
43
|
+
if (matches.length > 1) throw new Error(`SHA256SUMS lists more than one ${platform} archive: ${matches.map((m) => m.name).join(", ")}`);
|
|
44
|
+
const [match] = matches;
|
|
45
|
+
if (/[^0-9A-Za-z.+_-]/.test(match.name)) throw new Error(`Unexpected archive name in SHA256SUMS: ${match.name}`);
|
|
46
|
+
return { ...match, version: match.name.slice("alp-".length, -suffix.length) };
|
|
47
|
+
}
|
|
48
|
+
var sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
49
|
+
function verifyChecksum(bytes, asset) {
|
|
50
|
+
const actual = sha256(bytes);
|
|
51
|
+
if (actual !== asset.sha256) throw new Error(`Checksum mismatch for ${asset.name} (expected ${asset.sha256}, got ${actual}); nothing was replaced`);
|
|
52
|
+
return actual;
|
|
53
|
+
}
|
|
54
|
+
function compareVersions(a, b) {
|
|
55
|
+
const split = (v) => {
|
|
56
|
+
const [core, pre] = v.replace(/^v/, "").replace(/\+.*$/s, "").split(/-(.*)/s);
|
|
57
|
+
if (!/^\d+(\.\d+)*$/.test(core)) throw new Error(`Invalid version: ${JSON.stringify(v)}`);
|
|
58
|
+
return { core: core.split(".").map(Number), pre };
|
|
59
|
+
};
|
|
60
|
+
const x = split(a), y = split(b);
|
|
61
|
+
for (let i = 0; i < Math.max(x.core.length, y.core.length); i++) {
|
|
62
|
+
const d = (x.core[i] ?? 0) - (y.core[i] ?? 0);
|
|
63
|
+
if (d) return Math.sign(d);
|
|
64
|
+
}
|
|
65
|
+
if (x.pre === y.pre) return 0;
|
|
66
|
+
if (x.pre === void 0) return 1;
|
|
67
|
+
if (y.pre === void 0) return -1;
|
|
68
|
+
return x.pre.localeCompare(y.pre, "en", { numeric: true });
|
|
69
|
+
}
|
|
70
|
+
function releaseBaseUrl({ repo, version, baseUrl }) {
|
|
71
|
+
let base = baseUrl;
|
|
72
|
+
if (!base) base = version ? `https://github.com/${repo}/releases/download/v${version}` : `https://github.com/${repo}/releases/latest/download`;
|
|
73
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(base) && (path.isAbsolute(base) || process.platform === "win32" && path.win32.isAbsolute(base))) base = pathToFileURL(base).href;
|
|
74
|
+
base = base.replace(/\/+$/, "");
|
|
75
|
+
const url = new URL(base);
|
|
76
|
+
const loopback = isLoopbackHttp(url);
|
|
77
|
+
if (url.protocol !== "https:" && url.protocol !== "file:" && !loopback) throw new Error(`The release mirror must be https:// or file:// (${base})`);
|
|
78
|
+
return base;
|
|
79
|
+
}
|
|
80
|
+
var MAX_DOWNLOAD = 512 * 1024 * 1024;
|
|
81
|
+
var LOOPBACK = ["127.0.0.1", "localhost", "[::1]"];
|
|
82
|
+
var isLoopbackHttp = (url) => url.protocol === "http:" && LOOPBACK.includes(url.hostname);
|
|
83
|
+
function allowedHop(start, next) {
|
|
84
|
+
const to = new URL(next);
|
|
85
|
+
if (to.protocol === "https:") return true;
|
|
86
|
+
return isLoopbackHttp(new URL(start)) && isLoopbackHttp(to);
|
|
87
|
+
}
|
|
88
|
+
async function fetchBytes(url, { timeoutMs = 10 * 6e4, max = MAX_DOWNLOAD, fetch: fetchImpl = globalThis.fetch } = {}) {
|
|
89
|
+
if (url.startsWith("file:")) {
|
|
90
|
+
const file = fileURLToPath(url);
|
|
91
|
+
if (nodeFs.statSync(file).size > max) throw new Error(`${url} is larger than ${max} bytes`);
|
|
92
|
+
return new Uint8Array(await nodeFs.promises.readFile(file));
|
|
93
|
+
}
|
|
94
|
+
if (!allowedHop(url, url)) throw new Error(`Refusing to download ${url}: not https`);
|
|
95
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
96
|
+
let current = url;
|
|
97
|
+
let response;
|
|
98
|
+
for (let hop = 0; ; hop++) {
|
|
99
|
+
response = await fetchImpl(current, { redirect: "manual", signal });
|
|
100
|
+
if (![301, 302, 303, 307, 308].includes(response.status)) break;
|
|
101
|
+
const location = response.headers.get("location");
|
|
102
|
+
await response.body?.cancel().catch(() => {
|
|
103
|
+
});
|
|
104
|
+
if (!location) throw new Error(`${current} redirected without a location`);
|
|
105
|
+
if (hop >= 10) throw new Error(`${url} redirected more than 10 times`);
|
|
106
|
+
const next = new URL(location, current).href;
|
|
107
|
+
if (!allowedHop(url, next)) throw new Error(`${url} redirected to ${next}, which is not https; refused`);
|
|
108
|
+
current = next;
|
|
109
|
+
}
|
|
110
|
+
if (!response.ok) throw new Error(`Could not download ${current} (HTTP ${response.status})`);
|
|
111
|
+
if (Number(response.headers.get("content-length") ?? 0) > max) throw new Error(`${current} is larger than ${max} bytes`);
|
|
112
|
+
const chunks = [];
|
|
113
|
+
let size = 0;
|
|
114
|
+
for await (
|
|
115
|
+
const chunk of
|
|
116
|
+
/** @type {AsyncIterable<Uint8Array>} */
|
|
117
|
+
response.body ?? []
|
|
118
|
+
) {
|
|
119
|
+
size += chunk.byteLength;
|
|
120
|
+
if (size > max) throw new Error(`${current} is larger than ${max} bytes`);
|
|
121
|
+
chunks.push(chunk);
|
|
122
|
+
}
|
|
123
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
124
|
+
}
|
|
125
|
+
function which(name) {
|
|
126
|
+
const result = spawnSync(process.platform === "win32" ? "where" : "which", [name], { encoding: "utf8", windowsHide: true });
|
|
127
|
+
return result.status === 0 ? result.stdout.split(/\r?\n/)[0].trim() || void 0 : void 0;
|
|
128
|
+
}
|
|
129
|
+
function verifyProvenance(file, { repo, env = process.env, run = spawnSync, find = which }) {
|
|
130
|
+
if (env.ALP_UPDATE_NO_GH === "1") return "unavailable";
|
|
131
|
+
const gh = find("gh");
|
|
132
|
+
if (!gh) return "unavailable";
|
|
133
|
+
const result = run(gh, ["attestation", "verify", file, "--repo", repo, "--source-ref", "refs/heads/main", "--signer-workflow", `${repo}/${SIGNER_WORKFLOW}`], { encoding: "utf8", windowsHide: true });
|
|
134
|
+
if (result.status !== 0) {
|
|
135
|
+
const detail = `${result.stderr ?? ""}${result.stdout ?? ""}`.trim().split(/\r?\n/).slice(-3).join(" ");
|
|
136
|
+
throw new Error(`gh attestation verify refused ${path.basename(file)}${detail ? `: ${detail}` : ""}; nothing was replaced (sign in with gh auth login, or set ALP_UPDATE_NO_GH=1 to rely on the checksum only)`);
|
|
137
|
+
}
|
|
138
|
+
return "verified";
|
|
139
|
+
}
|
|
140
|
+
var oldPath = (target, platform = process.platform) => {
|
|
141
|
+
const p = platform === "win32" ? path.win32 : path;
|
|
142
|
+
return p.join(p.dirname(target), `${p.basename(target, p.extname(target))}.old${p.extname(target) || ".exe"}`);
|
|
143
|
+
};
|
|
144
|
+
var TRANSIENT = /* @__PURE__ */ new Set(["EBUSY", "EPERM", "EACCES"]);
|
|
145
|
+
var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
146
|
+
function retryBusy(action, sleep = pause, attempts = 25) {
|
|
147
|
+
for (let attempt = 1; ; attempt++) {
|
|
148
|
+
try {
|
|
149
|
+
return action();
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (attempt >= attempts || !TRANSIENT.has(error?.code)) throw error;
|
|
152
|
+
sleep(Math.min(50 * attempt, 400));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function replaceExecutable(staged, target, { platform = process.platform, fs = nodeFs, unique = () => randomBytes(4).toString("hex"), sleep = pause } = {}) {
|
|
157
|
+
if (platform !== "win32") {
|
|
158
|
+
fs.renameSync(staged, target);
|
|
159
|
+
return { old: void 0 };
|
|
160
|
+
}
|
|
161
|
+
const old = oldPath(target, platform);
|
|
162
|
+
if (fs.existsSync(old)) {
|
|
163
|
+
try {
|
|
164
|
+
fs.rmSync(old, { force: true });
|
|
165
|
+
} catch {
|
|
166
|
+
const aside = old.replace(/\.exe$/i, `.${unique()}.exe`);
|
|
167
|
+
try {
|
|
168
|
+
fs.renameSync(old, aside);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
throw new Error(`${old} is in use and could not be moved (${error.code ?? error.message}); stop the ALP processes started from it (alp daemon stop) and run alp update again`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
retryBusy(() => fs.renameSync(target, old), sleep);
|
|
175
|
+
try {
|
|
176
|
+
retryBusy(() => fs.renameSync(staged, target), sleep);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
try {
|
|
179
|
+
retryBusy(() => fs.renameSync(old, target), sleep);
|
|
180
|
+
} catch (restore) {
|
|
181
|
+
throw new Error(`Could not put the new executable at ${target} (${error.code ?? error.message}), and could not move the previous one back (${restore.code ?? restore.message}): rename ${old} to ${target} yourself`);
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
return { old };
|
|
186
|
+
}
|
|
187
|
+
function cleanupOldExecutable(target, { platform = process.platform, fs = nodeFs } = {}) {
|
|
188
|
+
if (platform !== "win32") return false;
|
|
189
|
+
const old = path.win32.basename(oldPath(target, platform));
|
|
190
|
+
const stem = old.slice(0, -".exe".length).toLowerCase();
|
|
191
|
+
let names;
|
|
192
|
+
try {
|
|
193
|
+
names = fs.readdirSync(path.win32.dirname(target));
|
|
194
|
+
} catch {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
let removed = false;
|
|
198
|
+
for (const name of names) {
|
|
199
|
+
const lower = name.toLowerCase();
|
|
200
|
+
if (lower !== `${stem}.exe` && !(lower.startsWith(`${stem}.`) && /^[0-9a-f]+\.exe$/.test(lower.slice(stem.length + 1)))) continue;
|
|
201
|
+
try {
|
|
202
|
+
fs.rmSync(path.win32.join(path.win32.dirname(target), name), { force: true });
|
|
203
|
+
removed = true;
|
|
204
|
+
} catch {
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return removed;
|
|
208
|
+
}
|
|
209
|
+
function isNpmExecutable(execPath) {
|
|
210
|
+
return /[\\/]node_modules[\\/]@anhlp[\\/]alp-(?:darwin|linux|win32)-(?:arm64|x64)[\\/]bin[\\/]alp(?:\.exe)?$/i.test(execPath ?? "");
|
|
211
|
+
}
|
|
212
|
+
function npmMessage(positionals = []) {
|
|
213
|
+
const lines = [];
|
|
214
|
+
if (positionals.length) lines.push(`alp: ${TEMPLATE_HINT}`);
|
|
215
|
+
lines.push(`This alp was installed with npm; update it with npm:
|
|
216
|
+
npm install -g ${NPM_PACKAGE}@beta
|
|
217
|
+
Then restart alpd when no sessions are running: alp daemon restart
|
|
218
|
+
(The project template upgrade is \`alp update-template [directory]\`.)`);
|
|
219
|
+
return lines.join("\n");
|
|
220
|
+
}
|
|
221
|
+
function extract(archive, directory, asset, platform, run = spawnSync) {
|
|
222
|
+
const windows = platform.startsWith("windows-");
|
|
223
|
+
const tar = process.platform === "win32" ? path.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "tar.exe") : "tar";
|
|
224
|
+
const result = run(tar, [windows ? "-xf" : "-xzf", archive, "-C", directory], { encoding: "utf8", windowsHide: true });
|
|
225
|
+
if (result.status !== 0) throw new Error(`Could not extract ${asset.name}: ${(result.stderr || result.error?.message || "").trim()}`);
|
|
226
|
+
const name = asset.name.slice(0, -archiveExtension(platform).length);
|
|
227
|
+
const binary = path.join(directory, name, windows ? "alp.exe" : "alp");
|
|
228
|
+
if (!nodeFs.existsSync(binary)) throw new Error(`${asset.name} does not contain ${name}/${windows ? "alp.exe" : "alp"}`);
|
|
229
|
+
return binary;
|
|
230
|
+
}
|
|
231
|
+
async function confirm(question) {
|
|
232
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
233
|
+
try {
|
|
234
|
+
return /^y(es)?$/i.test((await rl.question(`${question} [y/N] `)).trim());
|
|
235
|
+
} finally {
|
|
236
|
+
rl.close();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function selfUpdate(args, overrides = {}) {
|
|
240
|
+
const deps = {
|
|
241
|
+
packaged: false,
|
|
242
|
+
version: "0.0.0",
|
|
243
|
+
execPath: executablePath() ?? "",
|
|
244
|
+
env: process.env,
|
|
245
|
+
platform: process.platform,
|
|
246
|
+
arch: process.arch,
|
|
247
|
+
log: (line) => console.log(line),
|
|
248
|
+
warn: (line) => console.error(line),
|
|
249
|
+
interactive: !!(process.stdin.isTTY && process.stdout.isTTY),
|
|
250
|
+
fetchBytes,
|
|
251
|
+
confirm,
|
|
252
|
+
extract,
|
|
253
|
+
provenance: (file, repo2) => verifyProvenance(file, { repo: repo2 }),
|
|
254
|
+
daemon: async () => void 0,
|
|
255
|
+
restartDaemon: (binary) => spawnSync(binary, ["daemon", "restart"], { stdio: "inherit", windowsHide: true }).status ?? 1,
|
|
256
|
+
runVersion: (binary) => spawnSync(binary, ["--version"], { encoding: "utf8", windowsHide: true, timeout: 6e4 }).stdout?.trim() ?? "",
|
|
257
|
+
...overrides
|
|
258
|
+
};
|
|
259
|
+
let parsed;
|
|
260
|
+
try {
|
|
261
|
+
parsed = parseArgs({ args, allowPositionals: true, options: OPTIONS, strict: true });
|
|
262
|
+
} catch (error) {
|
|
263
|
+
deps.warn(`alp: ${error.message}`);
|
|
264
|
+
deps.warn(`alp: ${TEMPLATE_HINT}`);
|
|
265
|
+
return deps.packaged ? 1 : 0;
|
|
266
|
+
}
|
|
267
|
+
const { values, positionals } = parsed;
|
|
268
|
+
if (values.help) {
|
|
269
|
+
deps.log(UPDATE_USAGE);
|
|
270
|
+
return 0;
|
|
271
|
+
}
|
|
272
|
+
if (!deps.packaged || isNpmExecutable(deps.execPath)) {
|
|
273
|
+
deps.log(npmMessage(positionals));
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
if (positionals.length) {
|
|
277
|
+
deps.warn(`alp: ${TEMPLATE_HINT}`);
|
|
278
|
+
return 1;
|
|
279
|
+
}
|
|
280
|
+
const wanted = values.version?.replace(/^v/, "");
|
|
281
|
+
if (wanted !== void 0 && !/^[0-9][0-9A-Za-z.+-]*$/.test(wanted)) throw new Error(`Invalid version: ${values.version}`);
|
|
282
|
+
const repo = deps.env.ALP_INSTALL_REPO || DEFAULT_REPO;
|
|
283
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(repo)) throw new Error(`Invalid ALP_INSTALL_REPO: ${repo}`);
|
|
284
|
+
const base = releaseBaseUrl({ repo, version: wanted, baseUrl: values["base-url"] ?? deps.env.ALP_UPDATE_BASE_URL });
|
|
285
|
+
const platform = releasePlatform(deps.platform, deps.arch);
|
|
286
|
+
const sums = new TextDecoder().decode(await deps.fetchBytes(`${base}/SHA256SUMS`));
|
|
287
|
+
const asset = selectAsset(sums, platform, wanted);
|
|
288
|
+
const order = compareVersions(asset.version, deps.version);
|
|
289
|
+
if (values.check) {
|
|
290
|
+
if (order === 0) deps.log(`alp ${deps.version} is up to date (${platform})`);
|
|
291
|
+
else if (order < 0 && !wanted) deps.log(`alp ${deps.version} is newer than the latest release ${asset.version}`);
|
|
292
|
+
else deps.log(`alp ${deps.version} \u2192 ${asset.version} available (${asset.name}); run: alp update${wanted ? ` --version ${wanted}` : ""}`);
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
if (order === 0 && !wanted) {
|
|
296
|
+
deps.log(`alp ${deps.version} is up to date (${platform})`);
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
if (order < 0 && !wanted) {
|
|
300
|
+
deps.log(`alp ${deps.version} is newer than the latest release ${asset.version}; nothing to do (pass --version ${asset.version} to go back)`);
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
let target;
|
|
304
|
+
try {
|
|
305
|
+
target = nodeFs.realpathSync(deps.execPath);
|
|
306
|
+
} catch {
|
|
307
|
+
target = deps.execPath;
|
|
308
|
+
}
|
|
309
|
+
const dir = path.dirname(target);
|
|
310
|
+
try {
|
|
311
|
+
nodeFs.accessSync(dir, nodeFs.constants.W_OK);
|
|
312
|
+
} catch {
|
|
313
|
+
throw new Error(`${dir} is not writable; run alp update with the permissions that installed ${target}`);
|
|
314
|
+
}
|
|
315
|
+
if (!values.yes) {
|
|
316
|
+
if (!deps.interactive) throw new Error(`alp update would replace ${target} (${deps.version} \u2192 ${asset.version}); pass --yes to do it without a terminal`);
|
|
317
|
+
if (!await deps.confirm(`Replace ${target} (${deps.version} \u2192 ${asset.version})?`)) {
|
|
318
|
+
deps.log("Not updated.");
|
|
319
|
+
return 1;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const work = nodeFs.mkdtempSync(path.join(os.tmpdir(), "alp-update-"));
|
|
323
|
+
let staged;
|
|
324
|
+
try {
|
|
325
|
+
deps.log(`Downloading ${asset.name} from ${base}`);
|
|
326
|
+
const bytes = await deps.fetchBytes(`${base}/${asset.name}`);
|
|
327
|
+
verifyChecksum(bytes, asset);
|
|
328
|
+
deps.log(`Checksum verified (${asset.sha256})`);
|
|
329
|
+
const archive = path.join(work, asset.name);
|
|
330
|
+
nodeFs.writeFileSync(archive, bytes);
|
|
331
|
+
const provenance = deps.provenance(archive, repo);
|
|
332
|
+
if (provenance === "verified") deps.log(`Provenance verified by gh attestation (${repo}, refs/heads/main, release-binaries.yml)`);
|
|
333
|
+
else deps.warn("alp: warning: gh is not available, so only the SHA256SUMS checksum was verified, not the build provenance (install gh to verify it)");
|
|
334
|
+
const unpacked = path.join(work, "x");
|
|
335
|
+
nodeFs.mkdirSync(unpacked);
|
|
336
|
+
const binary = deps.extract(archive, unpacked, asset, platform);
|
|
337
|
+
staged = path.join(dir, `.alp.update.${randomBytes(6).toString("hex")}${deps.platform === "win32" ? ".exe" : ""}`);
|
|
338
|
+
nodeFs.copyFileSync(binary, staged);
|
|
339
|
+
if (deps.platform !== "win32") nodeFs.chmodSync(staged, 493);
|
|
340
|
+
const reported = deps.runVersion(staged);
|
|
341
|
+
if (reported !== asset.version) throw new Error(`The downloaded executable reports version ${JSON.stringify(reported)}, not ${asset.version}; nothing was replaced`);
|
|
342
|
+
replaceExecutable(staged, target, { platform: deps.platform });
|
|
343
|
+
staged = void 0;
|
|
344
|
+
} finally {
|
|
345
|
+
if (staged) try {
|
|
346
|
+
nodeFs.rmSync(staged, { force: true, maxRetries: 10, retryDelay: 100 });
|
|
347
|
+
} catch {
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
nodeFs.rmSync(work, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
deps.log(`Updated ${target}: ${deps.version} \u2192 ${asset.version}`);
|
|
355
|
+
const running = await deps.daemon().catch(() => void 0);
|
|
356
|
+
if (running && running.version !== asset.version) {
|
|
357
|
+
const sessions = running.sessions;
|
|
358
|
+
const known = Number.isSafeInteger(sessions);
|
|
359
|
+
deps.log(`alpd ${running.version} is still running${!known ? " (its live sessions could not be read)" : sessions ? ` with ${sessions} live session${sessions === 1 ? "" : "s"}` : ""}; it runs the new version after: alp daemon restart`);
|
|
360
|
+
if (!values.yes && deps.interactive && known && sessions === 0 && await deps.confirm("Restart alpd now?")) {
|
|
361
|
+
if (deps.restartDaemon(target) !== 0) deps.warn("alp: alp daemon restart failed; run it yourself");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
export {
|
|
367
|
+
DEFAULT_REPO,
|
|
368
|
+
MAX_DOWNLOAD,
|
|
369
|
+
NPM_PACKAGE,
|
|
370
|
+
SIGNER_WORKFLOW,
|
|
371
|
+
UPDATE_USAGE,
|
|
372
|
+
allowedHop,
|
|
373
|
+
archiveExtension,
|
|
374
|
+
cleanupOldExecutable,
|
|
375
|
+
compareVersions,
|
|
376
|
+
fetchBytes,
|
|
377
|
+
isNpmExecutable,
|
|
378
|
+
npmMessage,
|
|
379
|
+
oldPath,
|
|
380
|
+
parseSums,
|
|
381
|
+
releaseBaseUrl,
|
|
382
|
+
releasePlatform,
|
|
383
|
+
replaceExecutable,
|
|
384
|
+
retryBusy,
|
|
385
|
+
selectAsset,
|
|
386
|
+
selfUpdate,
|
|
387
|
+
sha256,
|
|
388
|
+
verifyChecksum,
|
|
389
|
+
verifyProvenance
|
|
390
|
+
};
|