@anhlp/alp-cli 0.0.1-beta.4 → 0.0.1-beta.7

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.
Files changed (66) hide show
  1. package/dist/THIRD-PARTY-NOTICES.txt +26 -1
  2. package/dist/acp/main.js +1 -1
  3. package/dist/acp.js +152 -33
  4. package/dist/alp-web/THIRD-PARTY-NOTICES.txt +666 -0
  5. package/dist/alp-web/alp-boundary.json +1 -0
  6. package/dist/alp-web/assets/TerminalPanel-BeMws9CP.js +22 -0
  7. package/dist/alp-web/assets/highlighter-BnicKQ_d.js +18 -0
  8. package/dist/alp-web/assets/index-Dl7motn1.js +59 -0
  9. package/dist/alp-web/assets/index-DwqDSiIi.css +1 -0
  10. package/dist/alp-web/index.html +2 -2
  11. package/dist/alp-web.js +529 -172
  12. package/dist/alpd.js +10623 -2570
  13. package/dist/backup.js +1 -1
  14. package/dist/build-manifest.json +22 -2
  15. package/dist/cli.js +28 -3
  16. package/dist/daemon.d.ts +1 -1
  17. package/dist/daemon.js +5 -0
  18. package/dist/interfaces.d.ts +13 -1
  19. package/dist/interfaces.js +95 -11
  20. package/dist/paths.d.ts +1 -0
  21. package/dist/paths.js +2 -1
  22. package/dist/roles.d.ts +15 -0
  23. package/dist/roles.js +16 -0
  24. package/dist/self-update.d.ts +149 -0
  25. package/dist/self-update.js +399 -0
  26. package/dist/sessions.d.ts +4 -0
  27. package/dist/sessions.js +22 -1
  28. package/dist/tasks.js +22 -8
  29. package/dist/terminal-native/README.md +201 -0
  30. package/dist/terminal-native/prebuilt/darwin-arm64/manifest.json +11 -0
  31. package/dist/terminal-native/prebuilt/darwin-arm64/terminal-owner +0 -0
  32. package/dist/terminal-native/prebuilt/darwin-x64/manifest.json +11 -0
  33. package/dist/terminal-native/prebuilt/darwin-x64/terminal-owner +0 -0
  34. package/dist/terminal-native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
  35. package/dist/terminal-native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
  36. package/dist/terminal-native/prebuilt/linux-arm64-musl/manifest.json +10 -0
  37. package/dist/terminal-native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
  38. package/dist/terminal-native/prebuilt/linux-x64-glibc/manifest.json +10 -0
  39. package/dist/terminal-native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
  40. package/dist/terminal-native/prebuilt/linux-x64-musl/manifest.json +10 -0
  41. package/dist/terminal-native/prebuilt/linux-x64-musl/terminal-owner +0 -0
  42. package/dist/terminal-native/terminal-owner.c +389 -0
  43. package/dist/terminal.d.ts +5 -0
  44. package/dist/terminal.js +4 -3
  45. package/dist/usage.d.ts +1 -1
  46. package/dist/usage.js +14 -5
  47. package/dist/web-service.d.ts +22 -4
  48. package/dist/web-service.js +32 -8
  49. package/package.json +6 -5
  50. package/src/cli.js +35 -4
  51. package/src/daemon.js +3 -0
  52. package/src/interfaces.js +101 -12
  53. package/src/paths.js +3 -1
  54. package/src/roles.js +26 -0
  55. package/src/self-update.js +406 -0
  56. package/src/sessions.js +23 -2
  57. package/src/tasks.js +22 -8
  58. package/src/terminal.js +4 -3
  59. package/src/usage.js +14 -5
  60. package/src/web-service.js +56 -13
  61. package/dist/alp-web/assets/TerminalPanel-PrU2l3u5.js +0 -16
  62. package/dist/alp-web/assets/index-BJdBTDFX.css +0 -1
  63. package/dist/alp-web/assets/index-DpfiPv5s.js +0 -52
  64. package/src/web/grant.js +0 -204
  65. package/src/web/main.js +0 -285
  66. package/src/web/serve.js +0 -144
@@ -224,6 +224,31 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
224
224
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
225
225
  SOFTWARE.
226
226
 
227
+ ================================================================================
228
+ @xterm/headless@6.0.0 (MIT)
229
+ ================================================================================
230
+
231
+ The package ships no licence file; its package.json declares MIT and the repository https://github.com/xtermjs/xterm.js. The standard MIT text (SPDX):
232
+
233
+ MIT License
234
+
235
+ Copyright (c) <year> <copyright holders>
236
+
237
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
238
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
239
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
240
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
241
+ following conditions:
242
+
243
+ The above copyright notice and this permission notice shall be included in all copies or substantial
244
+ portions of the Software.
245
+
246
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
247
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
248
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
249
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
250
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
251
+
227
252
  ================================================================================
228
253
  ajv@8.20.0 (MIT)
229
254
  ================================================================================
@@ -382,7 +407,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
382
407
  SOFTWARE.
383
408
 
384
409
  ================================================================================
385
- fast-uri@3.1.8 (BSD-3-Clause)
410
+ fast-uri@3.1.9 (BSD-3-Clause)
386
411
  ================================================================================
387
412
 
388
413
  Copyright (c) 2011-2021, Gary Court until https://github.com/garycourt/uri-js/commit/a1acf730b4bba3f1097c9f52e7d9d3aba8cdcaae
package/dist/acp/main.js CHANGED
@@ -6,7 +6,7 @@ import { startDaemon } from "@anhlp/alp-client/supervise";
6
6
  import { createLogger } from "@anhlp/alp-core/log";
7
7
  import { createAcpAgent } from "./agent.js";
8
8
  async function runAcp({ daemonEntry }) {
9
- const version = true ? "0.0.1-beta.4" : "0.0.0";
9
+ const version = true ? "0.0.1-beta.7" : "0.0.0";
10
10
  const logger = createLogger({ component: "acp" });
11
11
  const log = (message, fields) => logger.warn(message, fields);
12
12
  const app = createAcpAgent({
package/dist/acp.js CHANGED
@@ -18418,8 +18418,10 @@ var legacyClientNotificationMethods = /* @__PURE__ */ new Set([
18418
18418
  import { Readable, Writable } from "node:stream";
18419
18419
 
18420
18420
  // packages/client/src/index.js
18421
- import { spawn } from "node:child_process";
18421
+ import { setTimeout as delay } from "node:timers/promises";
18422
+ import { execFileSync, spawn } from "node:child_process";
18422
18423
  import { createHash, randomUUID } from "node:crypto";
18424
+ import { readFileSync } from "node:fs";
18423
18425
  import { open, readFile, writeFile, realpath, stat, lstat, mkdir, readlink, unlink, readdir, rename, rmdir, link } from "node:fs/promises";
18424
18426
  import net from "node:net";
18425
18427
  import os from "node:os";
@@ -18540,6 +18542,28 @@ function createLogger({ component, level, context = {}, write = stderrSink, now
18540
18542
  }
18541
18543
  var TAIL_BYTES = 256 * 1024;
18542
18544
 
18545
+ // packages/core/src/packaged.js
18546
+ var ROLE_ARGS = Object.freeze({
18547
+ daemon: Object.freeze(["daemon", "run"]),
18548
+ web: Object.freeze(["web", "serve"]),
18549
+ "bridge-acp": Object.freeze(["bridge", "acp"]),
18550
+ "bridge-antigravity": Object.freeze(["bridge", "antigravity"])
18551
+ });
18552
+ var isExecutableName = (file2) => /^alp(\.exe|\.cmd)?$/i.test(file2.split(/[\\/]/).pop() ?? "");
18553
+ var isScript = (file2) => /\.[cm]?js$/i.test(file2);
18554
+ function roleArgs(role) {
18555
+ const args = ROLE_ARGS[role];
18556
+ if (!args) throw new TypeError(`Unknown ALP role: ${role}`);
18557
+ return [...args];
18558
+ }
18559
+ function entryCommand(entry, role, args = [], execPath = process.execPath, { scriptOnly = false } = {}) {
18560
+ if (scriptOnly || isScript(entry) || !isExecutableName(entry)) return { command: execPath, args: [entry, ...args] };
18561
+ return { command: entry, args: [...roleArgs(role), ...args] };
18562
+ }
18563
+ function scriptCommand(script, args = []) {
18564
+ return { command: process.execPath, args: [script, ...args] };
18565
+ }
18566
+
18543
18567
  // packages/protocol/src/wire.js
18544
18568
  var PROTOCOL_VERSION2 = 1;
18545
18569
  var MAX_FRAME = 16 * 1024 * 1024;
@@ -18552,10 +18576,10 @@ var AlpRpcError = class extends Error {
18552
18576
  };
18553
18577
  var ERROR = Object.freeze({ failed: 1e3, notFound: 1001, forbidden: 1003, conflict: 1004, unavailable: 1005, protocol: 1006 });
18554
18578
  var RPC_ERROR = Object.freeze({ parseError: -32700, invalidRequest: -32600, methodNotFound: -32601, invalidParams: -32602 });
18555
- var CAPABILITY = Object.freeze({ sessionInterruptTurn: "session.interrupt.turn", attachAfter: "attach.after", sessionHistory: "session.history", workspaceRegistry: "workspace.registry", workspaceWorktree: "workspace.worktree", workspaceGit: "workspace.git", promptReceipts: "prompt.receipts", extensionMethods: "extension.methods", team: "team", task: "task", library: "library", libraryProjectWrite: "library.project.write", settingsLanguage: "settings.language", sessionListPage: "session.list.page", questionWatch: "question.watch", questionWatchTurns: "question.watch.turns", sessionAttention: "session.attention", workspaceFiles: "workspace.files", workspaceFilesRead: "workspace.files.read", promptImages: "prompt.images", schedule: "schedule", attachments: "attachments", sessionFork: "session.fork", sessionRewind: "session.rewind", sessionReload: "session.reload", sessionResumeCommand: "session.resumeCommand", sessionConfigureLive: "session.configure.live", terminal: "terminal" });
18579
+ var CAPABILITY = Object.freeze({ sessionInterruptTurn: "session.interrupt.turn", catalogLive: "catalog.live", attachAfter: "attach.after", sessionHistory: "session.history", workspaceRegistry: "workspace.registry", workspaceWorktree: "workspace.worktree", workspaceGit: "workspace.git", workspaceGitFacts: "workspace.git.facts", promptReceipts: "prompt.receipts", extensionMethods: "extension.methods", team: "team", task: "task", library: "library", libraryProjectWrite: "library.project.write", settingsLanguage: "settings.language", sessionListPage: "session.list.page", questionWatch: "question.watch", questionWatchTurns: "question.watch.turns", sessionAttention: "session.attention", workspaceFiles: "workspace.files", workspaceFilesRead: "workspace.files.read", workspaceFilesBrowse: "workspace.files.browse", hostDirectories: "host.directories", promptImages: "prompt.images", schedule: "schedule", attachments: "attachments", sessionFork: "session.fork", sessionRewind: "session.rewind", sessionReload: "session.reload", sessionResumeCommand: "session.resumeCommand", sessionCommands: "session.commands", sessionConfigureLive: "session.configure.live", terminal: "terminal", terminalCapture: "terminal.capture", terminalWatch: "terminal.watch" });
18556
18580
  var PROMPT_IMAGES = Object.freeze({ mimeTypes: Object.freeze(["image/png", "image/jpeg", "image/gif", "image/webp"]), maxCount: 8, maxBytes: 5 * 1024 * 1024, maxTotalBytes: 11 * 1024 * 1024 });
18557
- var RPC_METHODS = Object.freeze(["assignment.recall", "attachment.abort", "attachment.begin", "attachment.chunk", "attachment.commit", "attachment.delete", "attachment.get", "board.list", "catalog.get", "daemon.hello", "daemon.pause", "daemon.pauses", "daemon.resume", "daemon.shutdown", "daemon.status", "daemon.usage", "extension.register", "extension.unregister", "library.delete", "library.duplicate", "library.get", "library.list", "library.models", "library.rename", "library.save", "library.skills.set", "project.list", "project.register", "project.remove", "question.answer", "question.list", "question.watch", "registry.owner", "registry.worktree", "schedule.cancel", "schedule.create", "schedule.get", "schedule.list", "session.archive", "session.attach", "session.attention.clear", "session.close", "session.configure", "session.configure.preview", "session.create", "session.fork", "session.get", "session.history", "session.interrupt", "session.list", "session.log", "session.message", "session.preview", "session.prompt", "session.release", "session.reload", "session.rename", "session.resumeCommand", "session.rewind", "session.status", "settings.language.get", "settings.language.set", "task.create", "task.gate.resolve", "task.list", "task.update", "team.list", "terminal.attach", "terminal.close", "terminal.create", "terminal.input", "terminal.list", "terminal.resize", "terminal.revoke", "workspace.files.list", "workspace.files.read", "workspace.files.search", "workspace.get", "workspace.git.diff", "workspace.git.status", "workspace.list", "workspace.update", "workspace.worktree.create", "workspace.worktree.options", "workspace.worktree.remove"]);
18558
- var WORKSPACE_FILES = Object.freeze({ maxReadBytes: 1024 * 1024, maxListEntries: 1e3, maxPathLength: 4096 });
18581
+ var RPC_METHODS = Object.freeze(["assignment.recall", "attachment.abort", "attachment.begin", "attachment.chunk", "attachment.commit", "attachment.delete", "attachment.get", "board.list", "catalog.get", "catalog.refresh", "daemon.hello", "daemon.pause", "daemon.pauses", "daemon.resume", "daemon.shutdown", "daemon.status", "daemon.usage", "extension.register", "extension.unregister", "host.directories.search", "library.delete", "library.duplicate", "library.get", "library.list", "library.models", "library.rename", "library.save", "library.skills.set", "project.list", "project.register", "project.remove", "question.answer", "question.list", "question.watch", "registry.owner", "registry.worktree", "schedule.cancel", "schedule.create", "schedule.get", "schedule.list", "session.archive", "session.attach", "session.attention.clear", "session.close", "session.commands", "session.compact", "session.configure", "session.configure.preview", "session.create", "session.fork", "session.get", "session.history", "session.interrupt", "session.list", "session.log", "session.message", "session.preview", "session.prompt", "session.release", "session.reload", "session.rename", "session.resumeCommand", "session.rewind", "session.status", "settings.language.get", "settings.language.set", "task.create", "task.gate.resolve", "task.list", "task.update", "team.list", "terminal.attach", "terminal.close", "terminal.capture", "terminal.create", "terminal.input", "terminal.list", "terminal.watch", "terminal.unwatch", "terminal.resize", "terminal.revoke", "workspace.files.find", "workspace.files.list", "workspace.files.preview", "workspace.files.read", "workspace.files.search", "workspace.get", "workspace.git.diff", "workspace.git.facts", "workspace.git.status", "workspace.list", "workspace.update", "workspace.worktree.create", "workspace.worktree.options", "workspace.worktree.remove"]);
18582
+ var WORKSPACE_FILES = Object.freeze({ maxReadBytes: 1024 * 1024, maxListEntries: 1e3, maxPathLength: 4096, maxPreviewBytes: 50 * 1024 * 1024, maxPreviewChunkBytes: 8 * 1024 * 1024, maxFindEntries: 1e3 });
18559
18583
  var WORKSPACE_GIT = Object.freeze({ maxFileBytes: 1024 * 1024, maxTotalBytes: 2 * 1024 * 1024, maxUntracked: 200, maxStatusFiles: 1e3, maxRefLength: 255 });
18560
18584
  var ATTACHMENTS = Object.freeze({
18561
18585
  maxObjectBytes: 20 * 1024 * 1024,
@@ -18814,9 +18838,9 @@ var AlpRpcClient = class {
18814
18838
  if (this.#closeError) return Promise.reject(new AlpClientError(CLOSED, { reason: this.#closeError.reason === "closed" ? "closed" : "disconnected", cause: this.#closeError }));
18815
18839
  if (signal?.aborted) return Promise.reject(abortError(signal));
18816
18840
  if (this.#pending.size >= this.#maxPending) return Promise.reject(new AlpClientError(`Too many ALP requests waiting for an answer (${this.#maxPending})`, { reason: "overloaded" }));
18817
- let delay;
18841
+ let delay2;
18818
18842
  try {
18819
- delay = timerDelay(timeoutMs);
18843
+ delay2 = timerDelay(timeoutMs);
18820
18844
  } catch (error51) {
18821
18845
  return Promise.reject(error51);
18822
18846
  }
@@ -18844,12 +18868,12 @@ var AlpRpcClient = class {
18844
18868
  signal?.removeEventListener("abort", onAbort);
18845
18869
  };
18846
18870
  this.#pending.set(id, { resolve, reject, cleanup });
18847
- if (delay !== void 0) {
18871
+ if (delay2 !== void 0) {
18848
18872
  timer = setTimeout(() => {
18849
18873
  if (!this.#pending.delete(id)) return;
18850
18874
  cleanup();
18851
18875
  reject(new AlpClientError(`ALP request ${method} timed out after ${timeoutMs} ms`, { reason: "timeout" }));
18852
- }, delay);
18876
+ }, delay2);
18853
18877
  }
18854
18878
  signal?.addEventListener("abort", onAbort, { once: true });
18855
18879
  try {
@@ -19024,8 +19048,9 @@ var AlpRpcClient = class {
19024
19048
  };
19025
19049
 
19026
19050
  // packages/client/src/rpc/handshake.js
19027
- function hello(client, info = { name: "alp", version: "0" }, options) {
19028
- return client.request("daemon.hello", { protocolVersion: PROTOCOL_VERSION2, client: info }, options);
19051
+ var AGENT_CAPABILITY = "principal.agent";
19052
+ function hello(client, info = { name: "alp", version: "0" }, options, { agent: agent2 = false } = {}) {
19053
+ return client.request("daemon.hello", { protocolVersion: PROTOCOL_VERSION2, client: info, ...agent2 ? { capabilities: [AGENT_CAPABILITY] } : {} }, options);
19029
19054
  }
19030
19055
 
19031
19056
  // packages/client/src/websocket.js
@@ -19095,8 +19120,27 @@ async function assertPrivateSocket(socketPath) {
19095
19120
  return info;
19096
19121
  }
19097
19122
  var isFile = (file2) => stat(file2).then((info) => info.isFile(), () => false);
19098
- var BIN_DIRECTORIES = [path.join(os.homedir(), ".npm-global", "bin"), path.join(os.homedir(), ".local", "bin"), "/opt/homebrew/bin", "/usr/local/bin"];
19123
+ var BIN_DIRECTORIES = [path.join(os.homedir(), ".alp", "bin"), path.join(os.homedir(), ".npm-global", "bin"), path.join(os.homedir(), ".local", "bin"), "/opt/homebrew/bin", "/usr/local/bin"];
19099
19124
  var CLI_PACKAGES = ["@anhlp/alp", "@anhlp/alp-cli"];
19125
+ async function cliDaemonEntry(cli) {
19126
+ const base = path.basename(cli).toLowerCase();
19127
+ const root = path.resolve(path.dirname(cli), "..");
19128
+ const alpd = (directory) => path.join(directory, "dist", "alpd.js");
19129
+ const named = async (directory) => readFile(path.join(directory, "package.json"), "utf8").then((text) => JSON.parse(text)?.name).catch(() => void 0);
19130
+ let candidates = [];
19131
+ if (base === "alp" || base === "alp.cmd") {
19132
+ if (!await isFile(path.join(root, "alp-bundle.json"))) return void 0;
19133
+ const current = path.join(path.dirname(root), "current");
19134
+ const viaCurrent = await realpath(current).then((real) => real === root, () => false);
19135
+ candidates = [alpd(path.join(viaCurrent ? current : root, "lib", "node_modules", "@anhlp", "alp-cli"))];
19136
+ } else if (base === "cli.js" && CLI_PACKAGES.includes(await named(root))) {
19137
+ candidates = [alpd(root)];
19138
+ } else if (base === "alp.js" && await named(root) === "@anhlp/alp") {
19139
+ candidates = [alpd(path.join(root, "node_modules", "@anhlp", "alp-cli")), alpd(path.join(root, "..", "alp-cli"))];
19140
+ }
19141
+ for (const candidate of candidates) if (await isFile(candidate)) return candidate;
19142
+ return void 0;
19143
+ }
19100
19144
  async function findDaemonEntry({ home = alpHome(), env = process.env, candidates = (
19101
19145
  /** @type {Array<string | undefined>} */
19102
19146
  []
@@ -19108,18 +19152,53 @@ async function findDaemonEntry({ home = alpHome(), env = process.env, candidates
19108
19152
  } catch {
19109
19153
  }
19110
19154
  for (const directory of [...(env.PATH ?? "").split(path.delimiter).filter(Boolean), ...BIN_DIRECTORIES]) {
19111
- const cli = await realpath(path.join(directory, "alp")).catch(() => void 0);
19112
- if (!cli || path.basename(cli) !== "cli.js") continue;
19113
- const root = path.resolve(path.dirname(cli), "..");
19114
- const name = await readFile(path.join(root, "package.json"), "utf8").then((text) => JSON.parse(text).name, () => void 0);
19115
- const entry = path.join(root, "dist", "alpd.js");
19116
- if (CLI_PACKAGES.includes(name) && await isFile(entry)) return entry;
19155
+ for (const name of process.platform === "win32" ? ["alp.cmd", "alp"] : ["alp"]) {
19156
+ const cli = await realpath(path.join(directory, name)).catch(() => void 0);
19157
+ const entry = cli && await cliDaemonEntry(cli);
19158
+ if (entry) return entry;
19159
+ }
19117
19160
  }
19118
19161
  return void 0;
19119
19162
  }
19163
+ var cachedBootId = null;
19164
+ function bootId() {
19165
+ if (cachedBootId !== null) return cachedBootId;
19166
+ try {
19167
+ if (process.platform === "linux") {
19168
+ const id = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
19169
+ if (id.length > 0) {
19170
+ cachedBootId = id;
19171
+ return cachedBootId;
19172
+ }
19173
+ } else if (process.platform === "darwin") {
19174
+ const id = execFileSync("sysctl", ["-n", "kern.bootsessionuuid"], {
19175
+ encoding: "utf8",
19176
+ stdio: ["ignore", "pipe", "ignore"],
19177
+ timeout: 2e3
19178
+ }).trim();
19179
+ if (id.length > 0) {
19180
+ cachedBootId = id;
19181
+ return cachedBootId;
19182
+ }
19183
+ }
19184
+ } catch {
19185
+ }
19186
+ cachedBootId = void 0;
19187
+ return cachedBootId;
19188
+ }
19120
19189
  function bootTime() {
19121
19190
  return Math.round((Date.now() - os.uptime() * 1e3) / 1e3);
19122
19191
  }
19192
+ function isSameBoot(lock, { bootId: curBootId = bootId(), bootTime: curBootTime = bootTime() } = {}) {
19193
+ if (!lock) return false;
19194
+ if (typeof lock.bootId === "string" && lock.bootId.length > 0 && typeof curBootId === "string" && curBootId.length > 0) {
19195
+ return lock.bootId === curBootId;
19196
+ }
19197
+ if (typeof lock.bootTime === "number" && Number.isFinite(lock.bootTime) && Number.isFinite(curBootTime)) {
19198
+ return Math.abs(lock.bootTime - curBootTime) <= 30;
19199
+ }
19200
+ return false;
19201
+ }
19123
19202
  async function readLock(home) {
19124
19203
  try {
19125
19204
  return JSON.parse(await readFile(daemonPaths(home).lock, "utf8"));
@@ -19129,7 +19208,7 @@ async function readLock(home) {
19129
19208
  }
19130
19209
  }
19131
19210
  function lockAlive(lock) {
19132
- if (!lock || !Number.isSafeInteger(lock.pid) || Math.abs((lock.bootTime ?? 0) - bootTime()) > 30) return false;
19211
+ if (!lock || !Number.isSafeInteger(lock.pid) || !isSameBoot(lock)) return false;
19133
19212
  try {
19134
19213
  process.kill(lock.pid, 0);
19135
19214
  return true;
@@ -19140,6 +19219,12 @@ function lockAlive(lock) {
19140
19219
  var AlpClient = class extends AlpRpcClient {
19141
19220
  /** Host features captured by connect's handshake. @type {readonly string[]} */
19142
19221
  capabilities = [];
19222
+ /** Limits captured by connect's handshake. @type {import('@anhlp/alp-protocol').AttachmentLimits | undefined} */
19223
+ attachmentLimits;
19224
+ /** @type {{ readonly maxCount: number; readonly maxBytes: number; readonly maxTotalBytes: number } | undefined} */
19225
+ promptImageLimits;
19226
+ /** @type {import('@anhlp/alp-protocol').TerminalLimits | undefined} */
19227
+ terminalLimits;
19143
19228
  /**
19144
19229
  * @param {import('node:net').Socket} socket a connected or connecting socket; the client owns it
19145
19230
  * @param {import('./rpc/client.js').AlpRpcClientOptions & import('./ipc.js').SocketTransportOptions} [options]
@@ -19165,8 +19250,17 @@ async function openSocket(socketPath) {
19165
19250
  async function connect(socketPath, client = { name: "alp", version: "0" }, options = {}) {
19166
19251
  const connection = new AlpClient(await openSocket(socketPath), options);
19167
19252
  try {
19168
- const greeting = await hello(connection, client);
19253
+ const greeting = await hello(connection, client, void 0, { agent: typeof process.env.ALP_AGENT_SESSION === "string" && process.env.ALP_AGENT_SESSION !== "" });
19169
19254
  connection.capabilities = Object.freeze(Array.isArray(greeting.capabilities) ? greeting.capabilities.filter((value) => typeof value === "string") : []);
19255
+ if (greeting.attachmentLimits && typeof greeting.attachmentLimits === "object") {
19256
+ connection.attachmentLimits = Object.freeze({ ...greeting.attachmentLimits });
19257
+ }
19258
+ if (greeting.promptImageLimits && typeof greeting.promptImageLimits === "object") {
19259
+ connection.promptImageLimits = Object.freeze({ ...greeting.promptImageLimits });
19260
+ }
19261
+ if (greeting.terminalLimits && typeof greeting.terminalLimits === "object") {
19262
+ connection.terminalLimits = Object.freeze({ ...greeting.terminalLimits });
19263
+ }
19170
19264
  } catch (error51) {
19171
19265
  connection.close();
19172
19266
  throw error51;
@@ -19206,7 +19300,11 @@ async function lifecycleOwners(home) {
19206
19300
  async function readDaemonLifecycle(home) {
19207
19301
  return (await lifecycleOwners(home)).find((owner) => lockAlive(owner));
19208
19302
  }
19209
- async function withDaemonLifecycle(home, action, run, { joinStart = false } = {}) {
19303
+ async function withDaemonLifecycle(home, action, run, { joinStart = false, signal = (
19304
+ /** @type {AbortSignal | undefined} */
19305
+ void 0
19306
+ ) } = {}) {
19307
+ signal?.throwIfAborted();
19210
19308
  try {
19211
19309
  await assertPrivateDirectory(home, { create: true });
19212
19310
  } catch (cause) {
@@ -19215,10 +19313,17 @@ async function withDaemonLifecycle(home, action, run, { joinStart = false } = {}
19215
19313
  const state = path.join(home, "state");
19216
19314
  await assertPrivateDirectory(state, { create: true });
19217
19315
  const directory = path.join(state, "alpd.starting");
19316
+ const currentBootId = bootId();
19218
19317
  const token = `owner-${process.pid}-${bootTime()}-${action}-${randomUUID()}`;
19219
19318
  const candidate = path.join(state, `alpd.starting-${token}`);
19220
19319
  await mkdir(candidate, { mode: 448 });
19221
- await writeFile(path.join(candidate, token), JSON.stringify({ pid: process.pid, bootTime: bootTime(), action }), { mode: 384 });
19320
+ await writeFile(path.join(candidate, token), JSON.stringify({
19321
+ pid: process.pid,
19322
+ bootTime: bootTime(),
19323
+ ...currentBootId ? { bootId: currentBootId } : {},
19324
+ startedUptime: Math.floor(os.uptime()),
19325
+ action
19326
+ }), { mode: 384 });
19222
19327
  try {
19223
19328
  let joined = false;
19224
19329
  if (joinStart) {
@@ -19233,6 +19338,7 @@ async function withDaemonLifecycle(home, action, run, { joinStart = false } = {}
19233
19338
  }
19234
19339
  }
19235
19340
  while (!joined) {
19341
+ signal?.throwIfAborted();
19236
19342
  try {
19237
19343
  await rename(candidate, directory);
19238
19344
  break;
@@ -19246,10 +19352,11 @@ async function withDaemonLifecycle(home, action, run, { joinStart = false } = {}
19246
19352
  await rmdir(directory).catch((error52) => {
19247
19353
  if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(error52.code)) throw error52;
19248
19354
  });
19249
- await new Promise((resolve) => setTimeout(resolve, 25));
19355
+ await delay(25, void 0, { signal });
19250
19356
  }
19251
19357
  }
19252
19358
  try {
19359
+ signal?.throwIfAborted();
19253
19360
  return await run();
19254
19361
  } finally {
19255
19362
  await unlink(path.join(directory, token));
@@ -19269,8 +19376,12 @@ async function withDaemonLifecycle(home, action, run, { joinStart = false } = {}
19269
19376
  async function ensureDaemon({ home = alpHome(), entry = (
19270
19377
  /** @type {string | undefined} */
19271
19378
  void 0
19272
- ), env = process.env, execPath = process.execPath, timeoutMs = 15e3, lifecycleLocked = false } = {}) {
19273
- if (!lifecycleLocked) return withDaemonLifecycle(home, "start", () => ensureDaemon({ home, entry, env, execPath, timeoutMs, lifecycleLocked: true }));
19379
+ ), env = process.env, execPath = process.execPath, timeoutMs = 15e3, lifecycleLocked = false, signal = (
19380
+ /** @type {AbortSignal | undefined} */
19381
+ void 0
19382
+ ) } = {}) {
19383
+ signal?.throwIfAborted();
19384
+ if (!lifecycleLocked) return withDaemonLifecycle(home, "start", () => ensureDaemon({ home, entry, env, execPath, timeoutMs, lifecycleLocked: true, signal }), { signal });
19274
19385
  const ready = async () => {
19275
19386
  const lock = await readLock(home);
19276
19387
  return lockAlive(lock) && lock.ready ? lock.socket : void 0;
@@ -19282,8 +19393,10 @@ async function ensureDaemon({ home = alpHome(), entry = (
19282
19393
  if (!lockAlive(held)) {
19283
19394
  entry ??= await findDaemonEntry({ home, env });
19284
19395
  if (!entry) throw new Error("ALP daemon is not running and alpd.js was not found. Install the ALP CLI and run `alp daemon start`, or set ALP_DAEMON_ENTRY to alpd.js");
19396
+ signal?.throwIfAborted();
19285
19397
  await new Promise((resolve, reject) => {
19286
- const launcher = spawn(execPath, [entry, "--detach", `--startup-timeout=${timeoutMs}`], {
19398
+ const launch = entryCommand(entry, "daemon", ["--detach", `--startup-timeout=${timeoutMs}`], execPath);
19399
+ const launcher = spawn(launch.command, launch.args, {
19287
19400
  env: { ...env, ALP_HOME: home, ELECTRON_RUN_AS_NODE: "1" },
19288
19401
  stdio: ["ignore", "ignore", "pipe"],
19289
19402
  windowsHide: true
@@ -19298,6 +19411,7 @@ async function ensureDaemon({ home = alpHome(), entry = (
19298
19411
  }
19299
19412
  const deadline = Date.now() + timeoutMs;
19300
19413
  while (Date.now() < deadline) {
19414
+ signal?.throwIfAborted();
19301
19415
  const socket = await ready();
19302
19416
  if (socket) return socket;
19303
19417
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -19323,8 +19437,9 @@ function runCommand(command, args, { cwd, env = process.env, timeoutMs = 15e3 }
19323
19437
  return new Promise((resolve) => {
19324
19438
  let child;
19325
19439
  const script = process.platform === "win32" && /\.[cm]?js$/i.test(command);
19440
+ const run = script ? scriptCommand(command, args) : { command, args };
19326
19441
  try {
19327
- child = spawn2(script ? process.execPath : command, script ? [command, ...args] : args, { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
19442
+ child = spawn2(run.command, run.args, { cwd, env: run.env ? { ...env, ...run.env } : env, stdio: ["ignore", "pipe", "pipe"] });
19328
19443
  } catch (error51) {
19329
19444
  resolve({ code: -1, stdout: "", stderr: error51.message });
19330
19445
  return;
@@ -19413,29 +19528,33 @@ async function releaseHold(home) {
19413
19528
  async function daemonHeld(home) {
19414
19529
  return stat2(holdFile(home)).then(() => true, () => false);
19415
19530
  }
19416
- async function whenReady(home, timeoutMs) {
19531
+ async function whenReady(home, timeoutMs, signal) {
19417
19532
  const deadline = Date.now() + timeoutMs;
19418
19533
  while (Date.now() < deadline) {
19534
+ signal?.throwIfAborted();
19419
19535
  const lock = await readLock(home);
19420
19536
  if (lockAlive(lock) && lock.ready) return lock.socket;
19421
19537
  await new Promise((resolve) => setTimeout(resolve, 100));
19422
19538
  }
19423
19539
  throw new Error(`alpd did not become ready within ${timeoutMs / 1e3} s; see ${path3.join(home, "logs")}`);
19424
19540
  }
19425
- async function startDaemon({ home, entry, env = process.env, timeoutMs = 15e3, automatic = false }) {
19541
+ async function startDaemon({ home, entry, env = process.env, timeoutMs = 15e3, automatic = false, signal }) {
19426
19542
  return withDaemonLifecycle(home, "start", async () => {
19543
+ signal?.throwIfAborted();
19427
19544
  if (automatic) {
19428
19545
  if (await daemonHeld(home)) return;
19429
19546
  } else await releaseHold(home);
19430
19547
  const lock = await readLock(home);
19431
- if (lockAlive(lock)) return lock.ready ? lock.socket : whenReady(home, timeoutMs);
19548
+ signal?.throwIfAborted();
19549
+ if (lockAlive(lock)) return lock.ready ? lock.socket : whenReady(home, timeoutMs, signal);
19432
19550
  const service = serviceFor({ home, env });
19433
19551
  if (service && await installedProgram(service)) {
19552
+ signal?.throwIfAborted();
19434
19553
  await startService(service);
19435
- return whenReady(home, timeoutMs);
19554
+ return whenReady(home, timeoutMs, signal);
19436
19555
  }
19437
- return ensureDaemon({ home, entry, env, timeoutMs, lifecycleLocked: true });
19438
- });
19556
+ return ensureDaemon({ home, entry, env, timeoutMs, lifecycleLocked: true, signal });
19557
+ }, { signal });
19439
19558
  }
19440
19559
 
19441
19560
  // packages/cli/src/acp/agent.ts
@@ -19919,7 +20038,7 @@ ${item2.text}`;
19919
20038
 
19920
20039
  // packages/cli/src/acp/main.ts
19921
20040
  async function runAcp({ daemonEntry }) {
19922
- const version2 = true ? "0.0.1-beta.4" : "0.0.0";
20041
+ const version2 = true ? "0.0.1-beta.7" : "0.0.0";
19923
20042
  const logger = createLogger({ component: "acp" });
19924
20043
  const log = (message, fields) => logger.warn(message, fields);
19925
20044
  const app = createAcpAgent({