@anhlp/alp-cli 0.0.1-beta.4 → 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 +26 -1
- package/dist/acp/main.js +1 -1
- package/dist/acp.js +267 -92
- package/dist/alp-web/THIRD-PARTY-NOTICES.txt +666 -0
- package/dist/alp-web/alp-boundary.json +1 -0
- package/dist/alp-web/assets/TerminalPanel-CqTsgY-W.js +22 -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/index.html +2 -2
- package/dist/alp-web.js +666 -187
- package/dist/alpd.js +10768 -2592
- package/dist/backup.js +1 -1
- package/dist/build-manifest.json +22 -2
- package/dist/cli.js +32 -3
- package/dist/daemon.d.ts +1 -1
- package/dist/daemon.js +5 -0
- package/dist/interfaces.d.ts +13 -1
- package/dist/interfaces.js +96 -11
- 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/self-update.d.ts +152 -0
- package/dist/self-update.js +390 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +22 -1
- 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 +5 -0
- package/dist/terminal.js +4 -3
- package/dist/usage.d.ts +1 -1
- package/dist/usage.js +14 -5
- package/dist/web-service.d.ts +22 -4
- package/dist/web-service.js +33 -9
- package/package.json +6 -5
- package/src/cli.js +38 -4
- package/src/daemon.js +3 -0
- package/src/interfaces.js +102 -12
- package/src/paths.js +3 -1
- package/src/roles.js +28 -0
- package/src/self-update.js +406 -0
- package/src/sessions.js +23 -2
- package/src/tasks.js +22 -8
- package/src/terminal.js +4 -3
- package/src/usage.js +14 -5
- package/src/web-service.js +58 -14
- package/dist/alp-web/assets/TerminalPanel-PrU2l3u5.js +0 -16
- package/dist/alp-web/assets/index-BJdBTDFX.css +0 -1
- package/dist/alp-web/assets/index-DpfiPv5s.js +0 -52
- package/src/web/grant.js +0 -204
- package/src/web/main.js +0 -285
- package/src/web/serve.js +0 -144
package/dist/backup.js
CHANGED
|
@@ -7,7 +7,7 @@ import { acquireDaemonLock, alpHome, assertPrivateDirectory, daemonPaths, lockAl
|
|
|
7
7
|
import { daemonHeld, holdDaemon, releaseHold } from "@anhlp/alp-client/supervise";
|
|
8
8
|
import { start, stop } from "./daemon.js";
|
|
9
9
|
import { UsageError } from "./usage.js";
|
|
10
|
-
var VERSION = true ? "0.0.1-beta.
|
|
10
|
+
var VERSION = true ? "0.0.1-beta.6" : "dev";
|
|
11
11
|
var BY = `alp ${VERSION}`;
|
|
12
12
|
var size = (bytes) => bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : bytes >= 1024 ? `${(bytes / 1024).toFixed(1)} KB` : `${bytes} B`;
|
|
13
13
|
var stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
package/dist/build-manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.1-beta.
|
|
2
|
+
"version": "0.0.1-beta.6",
|
|
3
3
|
"entries": {
|
|
4
4
|
"packages/cli/dist/alpd.js": {
|
|
5
5
|
"inputs": [
|
|
@@ -12,15 +12,18 @@
|
|
|
12
12
|
"packages/client/src/rpc/handshake.js",
|
|
13
13
|
"packages/client/src/rpc/reconnect.js",
|
|
14
14
|
"packages/client/src/rpc/registry.js",
|
|
15
|
+
"packages/client/src/rpc/terminal-directory.js",
|
|
15
16
|
"packages/client/src/rpc/timers.js",
|
|
16
17
|
"packages/client/src/websocket.js",
|
|
17
18
|
"packages/core/src/adapter.js",
|
|
18
19
|
"packages/core/src/atomic.js",
|
|
19
20
|
"packages/core/src/backup.js",
|
|
20
21
|
"packages/core/src/beads.js",
|
|
22
|
+
"packages/core/src/bridges.js",
|
|
21
23
|
"packages/core/src/delegation.js",
|
|
22
24
|
"packages/core/src/errors.js",
|
|
23
25
|
"packages/core/src/formulas.js",
|
|
26
|
+
"packages/core/src/gate-ledger.js",
|
|
24
27
|
"packages/core/src/hook-run.js",
|
|
25
28
|
"packages/core/src/hooks.js",
|
|
26
29
|
"packages/core/src/index.js",
|
|
@@ -30,6 +33,7 @@
|
|
|
30
33
|
"packages/core/src/log.js",
|
|
31
34
|
"packages/core/src/migrations.js",
|
|
32
35
|
"packages/core/src/models.js",
|
|
36
|
+
"packages/core/src/packaged.js",
|
|
33
37
|
"packages/core/src/permissions.js",
|
|
34
38
|
"packages/core/src/profiles.js",
|
|
35
39
|
"packages/core/src/promptsafe.js",
|
|
@@ -51,6 +55,7 @@
|
|
|
51
55
|
"packages/core/src/workflow.js",
|
|
52
56
|
"packages/daemon/src/attachments.ts",
|
|
53
57
|
"packages/daemon/src/conversation.ts",
|
|
58
|
+
"packages/daemon/src/disk.ts",
|
|
54
59
|
"packages/daemon/src/files.ts",
|
|
55
60
|
"packages/daemon/src/git.ts",
|
|
56
61
|
"packages/daemon/src/gitignore.ts",
|
|
@@ -58,6 +63,7 @@
|
|
|
58
63
|
"packages/daemon/src/lifecycle.ts",
|
|
59
64
|
"packages/daemon/src/lock.ts",
|
|
60
65
|
"packages/daemon/src/main.ts",
|
|
66
|
+
"packages/daemon/src/native-terminal.ts",
|
|
61
67
|
"packages/daemon/src/operations.ts",
|
|
62
68
|
"packages/daemon/src/registry.ts",
|
|
63
69
|
"packages/daemon/src/rpc-error.ts",
|
|
@@ -65,7 +71,9 @@
|
|
|
65
71
|
"packages/daemon/src/schedules.ts",
|
|
66
72
|
"packages/daemon/src/server.ts",
|
|
67
73
|
"packages/daemon/src/store.ts",
|
|
74
|
+
"packages/daemon/src/terminal-screen.ts",
|
|
68
75
|
"packages/daemon/src/terminals.ts",
|
|
76
|
+
"packages/daemon/src/windows-terminal.ts",
|
|
69
77
|
"packages/daemon/src/worktrees.ts",
|
|
70
78
|
"packages/protocol/src/contract-v1.js",
|
|
71
79
|
"packages/protocol/src/contract.js",
|
|
@@ -80,16 +88,20 @@
|
|
|
80
88
|
"packages/runtime/src/board.ts",
|
|
81
89
|
"packages/runtime/src/catalog.ts",
|
|
82
90
|
"packages/runtime/src/claude-transport.ts",
|
|
91
|
+
"packages/runtime/src/compact.ts",
|
|
83
92
|
"packages/runtime/src/configure.ts",
|
|
84
93
|
"packages/runtime/src/contracts.ts",
|
|
85
94
|
"packages/runtime/src/conversation.ts",
|
|
86
95
|
"packages/runtime/src/github.ts",
|
|
87
96
|
"packages/runtime/src/handoff.ts",
|
|
88
97
|
"packages/runtime/src/index.ts",
|
|
98
|
+
"packages/runtime/src/input-limits.ts",
|
|
89
99
|
"packages/runtime/src/language.ts",
|
|
90
100
|
"packages/runtime/src/live.ts",
|
|
91
101
|
"packages/runtime/src/mailbox.ts",
|
|
92
102
|
"packages/runtime/src/mcp-tools.ts",
|
|
103
|
+
"packages/runtime/src/model-catalog.ts",
|
|
104
|
+
"packages/runtime/src/model-probes.ts",
|
|
93
105
|
"packages/runtime/src/permission-path.ts",
|
|
94
106
|
"packages/runtime/src/process-info.ts",
|
|
95
107
|
"packages/runtime/src/providers.ts",
|
|
@@ -122,6 +134,7 @@
|
|
|
122
134
|
"node:stream",
|
|
123
135
|
"node:stream/promises",
|
|
124
136
|
"node:string_decoder",
|
|
137
|
+
"node:timers/promises",
|
|
125
138
|
"node:url",
|
|
126
139
|
"node:zlib",
|
|
127
140
|
"path"
|
|
@@ -141,22 +154,26 @@
|
|
|
141
154
|
"packages/client/src/rpc/handshake.js",
|
|
142
155
|
"packages/client/src/rpc/reconnect.js",
|
|
143
156
|
"packages/client/src/rpc/registry.js",
|
|
157
|
+
"packages/client/src/rpc/terminal-directory.js",
|
|
144
158
|
"packages/client/src/rpc/timers.js",
|
|
145
159
|
"packages/client/src/service.js",
|
|
146
160
|
"packages/client/src/supervise.js",
|
|
147
161
|
"packages/client/src/websocket.js",
|
|
148
162
|
"packages/core/src/log.js",
|
|
163
|
+
"packages/core/src/packaged.js",
|
|
149
164
|
"packages/protocol/src/index.ts",
|
|
150
165
|
"packages/protocol/src/wire.js"
|
|
151
166
|
],
|
|
152
167
|
"external": [
|
|
153
168
|
"node:child_process",
|
|
154
169
|
"node:crypto",
|
|
170
|
+
"node:fs",
|
|
155
171
|
"node:fs/promises",
|
|
156
172
|
"node:net",
|
|
157
173
|
"node:os",
|
|
158
174
|
"node:path",
|
|
159
|
-
"node:stream"
|
|
175
|
+
"node:stream",
|
|
176
|
+
"node:timers/promises"
|
|
160
177
|
]
|
|
161
178
|
},
|
|
162
179
|
"packages/cli/dist/alp-web.js": {
|
|
@@ -184,6 +201,7 @@
|
|
|
184
201
|
"packages/client/src/rpc/handshake.js",
|
|
185
202
|
"packages/client/src/rpc/reconnect.js",
|
|
186
203
|
"packages/client/src/rpc/registry.js",
|
|
204
|
+
"packages/client/src/rpc/terminal-directory.js",
|
|
187
205
|
"packages/client/src/rpc/timers.js",
|
|
188
206
|
"packages/client/src/service.js",
|
|
189
207
|
"packages/client/src/supervise.js",
|
|
@@ -194,6 +212,7 @@
|
|
|
194
212
|
"packages/core/src/library.js",
|
|
195
213
|
"packages/core/src/log.js",
|
|
196
214
|
"packages/core/src/models.js",
|
|
215
|
+
"packages/core/src/packaged.js",
|
|
197
216
|
"packages/core/src/permissions.js",
|
|
198
217
|
"packages/core/src/providers.js",
|
|
199
218
|
"packages/core/src/resolver.js",
|
|
@@ -226,6 +245,7 @@
|
|
|
226
245
|
"node:net",
|
|
227
246
|
"node:os",
|
|
228
247
|
"node:path",
|
|
248
|
+
"node:timers/promises",
|
|
229
249
|
"node:url",
|
|
230
250
|
"node:util",
|
|
231
251
|
"stream",
|
package/dist/cli.js
CHANGED
|
@@ -7,18 +7,47 @@ import { scrubText } from "@anhlp/alp-core/log";
|
|
|
7
7
|
import { USAGE, UsageError } from "./usage.js";
|
|
8
8
|
import { project, permissionsCommand, trustCommand, language, verify, doctor } from "./projects.js";
|
|
9
9
|
import { daemon } from "./daemon.js";
|
|
10
|
-
import { run, ps, attach, send, questions, answer, top, log, board, pause, resume, recall, interrupt } from "./sessions.js";
|
|
10
|
+
import { run, ps, attach, send, questions, answer, top, log, board, models, pause, resume, recall, interrupt, compact } from "./sessions.js";
|
|
11
11
|
import { libraryCommand, editCommand, teamsCommand } from "./library.js";
|
|
12
12
|
import { scheduleCommand } from "./schedules.js";
|
|
13
13
|
import { tasksCommand, formulaCommand, taskCommand } from "./tasks.js";
|
|
14
14
|
import { webCommand, acpCommand } from "./interfaces.js";
|
|
15
15
|
import { backupCommand, restoreCommand } from "./backup.js";
|
|
16
16
|
import { terminalCommand } from "./terminal.js";
|
|
17
|
-
|
|
17
|
+
import { bridgeCommand } from "./roles.js";
|
|
18
|
+
import { cleanupOldExecutable, selfUpdate } from "./self-update.js";
|
|
19
|
+
import { executablePath, packagedInfo } from "@anhlp/alp-core/packaged";
|
|
20
|
+
import { connect, lockAlive, readLock } from "@anhlp/alp-client/index";
|
|
21
|
+
function alpVersion() {
|
|
22
|
+
return packagedInfo()?.version ?? (true ? "0.0.1-beta.6" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version);
|
|
23
|
+
}
|
|
24
|
+
async function runningDaemon() {
|
|
25
|
+
const lock = await readLock(alpHome());
|
|
26
|
+
if (!lockAlive(lock)) return void 0;
|
|
27
|
+
const client = await connect(lock.socket, { name: "alp-cli", version: "1" }).catch(() => void 0);
|
|
28
|
+
if (!client) return { version: lock.version };
|
|
29
|
+
try {
|
|
30
|
+
const status = await client.request("daemon.status");
|
|
31
|
+
return { version: status.version ?? lock.version, sessions: status.sessions };
|
|
32
|
+
} catch {
|
|
33
|
+
return { version: lock.version };
|
|
34
|
+
} finally {
|
|
35
|
+
client.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function updateCommand(args2) {
|
|
39
|
+
const code = await selfUpdate(args2, { packaged: packagedInfo() !== void 0, version: alpVersion(), daemon: runningDaemon });
|
|
40
|
+
if (code) process.exitCode = code;
|
|
41
|
+
}
|
|
42
|
+
{
|
|
43
|
+
const executable = executablePath();
|
|
44
|
+
if (executable) cleanupOldExecutable(executable);
|
|
45
|
+
}
|
|
46
|
+
var commands = { schedule: scheduleCommand, setup: (args2) => setup(args2, alpHome()), init: (args2) => project("init", args2), "update-template": (args2) => project("upgrade", args2), upgrade: (args2) => project("upgrade", args2), update: updateCommand, daemon, doctor, run, ps, top, attach, send, questions, answer, log, board, tasks: tasksCommand, task: taskCommand, formula: formulaCommand, permissions: permissionsCommand, agents: (args2) => libraryCommand("agents", args2), skills: (args2) => libraryCommand("skills", args2), mcp: (args2) => ["add", "rm", "mv", "cp", "test", "show", "edit"].includes(args2[0]) ? editCommand("mcp", args2) : libraryCommand("mcp", args2), hooks: (args2) => libraryCommand("hooks", args2), providers: (args2) => libraryCommand("providers", args2), provider: (args2) => editCommand("providers", args2), teams: teamsCommand, trust: trustCommand, agent: (args2) => editCommand("agents", args2), team: (args2) => editCommand("teams", args2), skill: (args2) => editCommand("skills", args2), hook: (args2) => editCommand("hooks", args2), verify, recall, pause, resume, language, models, interrupt, compact, acp: acpCommand, web: webCommand, backup: backupCommand, restore: restoreCommand, terminal: terminalCommand, bridge: bridgeCommand };
|
|
18
47
|
var [command, ...args] = process.argv.slice(2);
|
|
19
48
|
try {
|
|
20
49
|
if (command === "--version") {
|
|
21
|
-
console.log(
|
|
50
|
+
console.log(alpVersion());
|
|
22
51
|
} else {
|
|
23
52
|
if (!Object.hasOwn(commands, command)) throw new UsageError();
|
|
24
53
|
await commands[command](args);
|
package/dist/daemon.d.ts
CHANGED
|
@@ -32,4 +32,4 @@ export function start(): Promise<string>;
|
|
|
32
32
|
/** Connects to a running daemon without starting one. */
|
|
33
33
|
export function running(): Promise<import("@anhlp/alp-client/index").AlpClient>;
|
|
34
34
|
export function stop(): Promise<boolean>;
|
|
35
|
-
export function daemon([action, ...rest]: [any, ...any[]]): Promise<
|
|
35
|
+
export function daemon([action, ...rest]: [any, ...any[]]): Promise<any>;
|
package/dist/daemon.js
CHANGED
|
@@ -7,6 +7,7 @@ import { alpHome, connect, lockAlive, readLock, withDaemonLifecycle } from "@anh
|
|
|
7
7
|
import { scrubText } from "@anhlp/alp-core/log";
|
|
8
8
|
import { UsageError } from "./usage.js";
|
|
9
9
|
import { DAEMON_ENTRY } from "./paths.js";
|
|
10
|
+
import { runRole } from "./roles.js";
|
|
10
11
|
async function built() {
|
|
11
12
|
try {
|
|
12
13
|
await access(DAEMON_ENTRY);
|
|
@@ -46,6 +47,10 @@ async function stop() {
|
|
|
46
47
|
return true;
|
|
47
48
|
}
|
|
48
49
|
async function daemon([action, ...rest]) {
|
|
50
|
+
if (action === "run") {
|
|
51
|
+
await built();
|
|
52
|
+
return runRole("daemon", DAEMON_ENTRY, rest);
|
|
53
|
+
}
|
|
49
54
|
if (rest.length && !(action === "status" && rest.length === 1 && rest[0] === "--json")) throw new UsageError();
|
|
50
55
|
if (action === "start") {
|
|
51
56
|
const socket = await start();
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* @param {string} home
|
|
6
6
|
*/
|
|
7
7
|
export function startPaseoIntegration(home: string): Promise<any>;
|
|
8
|
+
/**
|
|
9
|
+
* Registers `directory` as a project in alpd via IPC (`project.register`).
|
|
10
|
+
* If alpd cannot be reached or the call fails, this is best-effort.
|
|
11
|
+
* @param {string} home
|
|
12
|
+
* @param {string} directory
|
|
13
|
+
* @param {{ timeoutMs?: number, connectClient?: typeof connect }} [options]
|
|
14
|
+
*/
|
|
15
|
+
export function registerProject(home: string, directory: string, { timeoutMs, connectClient }?: {
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
connectClient?: typeof connect;
|
|
18
|
+
}): Promise<void>;
|
|
8
19
|
/**
|
|
9
20
|
* alp web pair: the link that pairs Paseo's app on another device with alpd through Paseo's relay
|
|
10
21
|
* (ALPD §64). The device then signs in with the password this command prints (the token kept in
|
|
@@ -18,7 +29,8 @@ export function startPaseoIntegration(home: string): Promise<any>;
|
|
|
18
29
|
* Exported so the wait can be pinned by a regression test without a live daemon restart.
|
|
19
30
|
*/
|
|
20
31
|
export function requestPairing(client: any, params: any, attempts?: number): Promise<any>;
|
|
21
|
-
|
|
32
|
+
import { connect } from '@anhlp/alp-client/index';
|
|
33
|
+
export function webCommand(args: any): Promise<any>;
|
|
22
34
|
export function pairCommand(args: any): Promise<void>;
|
|
23
35
|
/** alp acp: ALP as an ACP agent for editors; stdout carries only the protocol (ALPD §60). */
|
|
24
36
|
export function acpCommand(args: any): Promise<void>;
|
package/dist/interfaces.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// packages/cli/src/interfaces.js
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { execFile, spawn } from "node:child_process";
|
|
3
|
-
import { readFile, stat } from "node:fs/promises";
|
|
4
|
+
import { readFile, realpath, stat } from "node:fs/promises";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { parseArgs } from "node:util";
|
|
6
|
-
import { alpHome, discoverIntegration, startIntegration } from "@anhlp/alp-client/index";
|
|
7
|
+
import { alpHome, connect, daemonPaths, discoverIntegration, startIntegration } from "@anhlp/alp-client/index";
|
|
7
8
|
import { UsageError } from "./usage.js";
|
|
8
9
|
import { built, start, running } from "./daemon.js";
|
|
9
10
|
import { DAEMON_ENTRY, distributionEntry } from "./paths.js";
|
|
10
|
-
import {
|
|
11
|
+
import { entryCommand, packagedInfo } from "@anhlp/alp-core/packaged";
|
|
12
|
+
import { runRole } from "./roles.js";
|
|
13
|
+
import { alpWebEntry, alpWebScript, isWebClaimed, isWebReady, refusal, stopPreRenamePaseo, stopWebService, webOwner } from "./web-service.js";
|
|
11
14
|
var PASEO = "paseo";
|
|
12
15
|
var WEB = "web";
|
|
13
16
|
async function startPaseoIntegration(home) {
|
|
@@ -33,9 +36,76 @@ async function legacyDescriptorEntry(file, home) {
|
|
|
33
36
|
}
|
|
34
37
|
return void 0;
|
|
35
38
|
}
|
|
36
|
-
async function
|
|
39
|
+
async function currentProject() {
|
|
37
40
|
const cwd = process.cwd();
|
|
38
|
-
return await stat(path.join(cwd, ".alp")).then((info) => info.isDirectory(), () => false) ?
|
|
41
|
+
return await stat(path.join(cwd, ".alp")).then((info) => info.isDirectory(), () => false) ? cwd : void 0;
|
|
42
|
+
}
|
|
43
|
+
async function projectArgs() {
|
|
44
|
+
const project = await currentProject();
|
|
45
|
+
return project ? ["--project", project] : [];
|
|
46
|
+
}
|
|
47
|
+
async function registerProject(home, directory, { timeoutMs = 5e3, connectClient = connect } = {}) {
|
|
48
|
+
const socket = daemonPaths(home).socket;
|
|
49
|
+
let client;
|
|
50
|
+
let expired = false;
|
|
51
|
+
let timer;
|
|
52
|
+
const work = (async () => {
|
|
53
|
+
const connected = await connectClient(socket, { name: "alp-cli", version: "1" }, { timeoutMs });
|
|
54
|
+
if (expired) {
|
|
55
|
+
connected.close();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
client = connected;
|
|
59
|
+
for (let attempt = 0; attempt < 5 && !expired; attempt++) {
|
|
60
|
+
const list = await client.request("project.list", { limit: 1 }, { timeoutMs }).catch(() => void 0);
|
|
61
|
+
if (expired) return;
|
|
62
|
+
const revision = typeof list?.revision === "number" ? list.revision : 0;
|
|
63
|
+
try {
|
|
64
|
+
await client.request("project.register", { directory, ifRevision: revision, requestId: randomUUID() }, { timeoutMs });
|
|
65
|
+
break;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error?.data?.reason === "stale_revision" && attempt < 4) continue;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
try {
|
|
73
|
+
await Promise.race([work.catch(() => {
|
|
74
|
+
}), new Promise((resolve) => {
|
|
75
|
+
timer = setTimeout(() => {
|
|
76
|
+
expired = true;
|
|
77
|
+
try {
|
|
78
|
+
client?.close();
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
resolve(void 0);
|
|
82
|
+
}, timeoutMs);
|
|
83
|
+
})]);
|
|
84
|
+
} finally {
|
|
85
|
+
expired = true;
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
try {
|
|
88
|
+
client?.close();
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function waitForGrant(home, credentialId, project, { timeoutMs = 5e3 } = {}) {
|
|
94
|
+
const credentialsFile = path.join(home, "web", "credentials.json");
|
|
95
|
+
const canonical = await realpath(project).catch(() => project);
|
|
96
|
+
const deadline = Date.now() + timeoutMs;
|
|
97
|
+
while (Date.now() < deadline) {
|
|
98
|
+
try {
|
|
99
|
+
const raw = JSON.parse(await readFile(credentialsFile, "utf8"));
|
|
100
|
+
const credential = raw?.credentials?.find((c) => c.id === credentialId && !c.revokedAt);
|
|
101
|
+
if (credential?.workspaces?.some((w) => w.canonical === canonical || w.path === project || w.path === canonical)) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
39
109
|
}
|
|
40
110
|
async function webDisabled(home) {
|
|
41
111
|
const settings = await readFile(path.join(home, "settings.json"), "utf8").then((text) => JSON.parse(text), () => void 0);
|
|
@@ -46,11 +116,13 @@ async function serveWeb(home, entry) {
|
|
|
46
116
|
await stopPreRenamePaseo(home);
|
|
47
117
|
const held = await webOwner(home);
|
|
48
118
|
const published = await readFile(path.join(home, "web.json"), "utf8").then((text) => JSON.parse(text), () => void 0);
|
|
49
|
-
const
|
|
119
|
+
const lockPid = await readFile(path.join(home, "integrations", "web.lock"), "utf8").then((text) => JSON.parse(text)?.pid, () => void 0);
|
|
120
|
+
const claimed = await isWebClaimed(published, lockPid, held);
|
|
50
121
|
if ("reason" in held && held.alive && held.kind === "foreign" && !claimed) throw new Error(`${refusal(home)} (${held.reason}). Stop it, then run alp web again.`);
|
|
122
|
+
const project = await currentProject();
|
|
51
123
|
let lock;
|
|
52
124
|
try {
|
|
53
|
-
lock = await startIntegration({ name: WEB, entry, home, args:
|
|
125
|
+
lock = await startIntegration({ name: WEB, entry, home, args: project ? ["--project", project] : [] });
|
|
54
126
|
} catch (error) {
|
|
55
127
|
const owner = await webOwner(home);
|
|
56
128
|
if ("reason" in owner && owner.alive) throw new Error(`${error?.message ?? error}
|
|
@@ -62,12 +134,19 @@ ${refusal(home)} (${owner.reason}). If it is not alp web, stop it, then run alp
|
|
|
62
134
|
const owner = await webOwner(home);
|
|
63
135
|
throw new Error(`${refusal(home)}${"reason" in owner ? ` (${owner.reason})` : ""}. Stop pid ${lock.pid}, then run alp web again.`);
|
|
64
136
|
}
|
|
65
|
-
if (typeof info.url !== "string" || typeof info.token !== "string"
|
|
137
|
+
if (typeof info.url !== "string" || typeof info.token !== "string" || !await isWebReady(info.url)) {
|
|
138
|
+
throw new Error(`alp web published no address; see ${path.join(home, "logs", "integrations", "alp-web.log")}`);
|
|
139
|
+
}
|
|
140
|
+
if (project) {
|
|
141
|
+
await registerProject(home, project);
|
|
142
|
+
await waitForGrant(home, info.credentialId, project);
|
|
143
|
+
}
|
|
66
144
|
return `${info.url}#token=${info.token}`;
|
|
67
145
|
}
|
|
68
146
|
async function webCommand(args) {
|
|
69
147
|
if (args[0] === "pair") return pairCommand(args.slice(1));
|
|
70
148
|
if (args[0] === "rotate") return rotateCommand(args.slice(1));
|
|
149
|
+
if (args[0] === "serve") return runRole("web", alpWebScript(), args.slice(1));
|
|
71
150
|
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { print: { type: "boolean" } } });
|
|
72
151
|
if (positionals.length) throw new UsageError();
|
|
73
152
|
const entry = alpWebEntry();
|
|
@@ -89,9 +168,10 @@ async function rotateCommand(args) {
|
|
|
89
168
|
for (let attempt = 1; ; attempt++) {
|
|
90
169
|
await stopWebService(home);
|
|
91
170
|
const rotated = await new Promise((resolve) => {
|
|
171
|
+
const rotate = entryCommand(entry, "web", ["--rotate", ...project]);
|
|
92
172
|
execFile(
|
|
93
|
-
|
|
94
|
-
|
|
173
|
+
rotate.command,
|
|
174
|
+
rotate.args,
|
|
95
175
|
{ env: { ...process.env, ALP_HOME: home }, encoding: "utf8", timeout: 6e4, killSignal: "SIGTERM" },
|
|
96
176
|
(error, stdout, stderr) => resolve({ code: error ? typeof error.code === "number" ? error.code : 1 : 0, output: `${stderr}${stdout}`.trim() })
|
|
97
177
|
);
|
|
@@ -144,12 +224,17 @@ ${pairing.url}`);
|
|
|
144
224
|
async function acpCommand(args) {
|
|
145
225
|
if (args.length) throw new UsageError();
|
|
146
226
|
await built();
|
|
147
|
-
const
|
|
227
|
+
const acp = packagedInfo()?.roles?.acp;
|
|
228
|
+
const { runAcp } = (
|
|
229
|
+
/** @type {{ runAcp: (options: { daemonEntry: string }) => Promise<void> }} */
|
|
230
|
+
acp ? await acp() : await import(distributionEntry("acp.js").href)
|
|
231
|
+
);
|
|
148
232
|
await runAcp({ daemonEntry: DAEMON_ENTRY });
|
|
149
233
|
}
|
|
150
234
|
export {
|
|
151
235
|
acpCommand,
|
|
152
236
|
pairCommand,
|
|
237
|
+
registerProject,
|
|
153
238
|
requestPairing,
|
|
154
239
|
startPaseoIntegration,
|
|
155
240
|
webCommand
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
/** Locate artifacts in either the independently shipped CLI or the legacy root build. */
|
|
2
2
|
export function distributionEntry(name: any): URL;
|
|
3
|
+
/** What starts alpd: alpd.js under Node, or the ALP executable itself (`alp daemon run`). */
|
|
3
4
|
export const DAEMON_ENTRY: string;
|
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,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 {};
|