@proagentstore/cli 0.4.149 → 0.4.152

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proagentstore/cli",
3
- "version": "0.4.149",
3
+ "version": "0.4.152",
4
4
  "description": "CLI for creating, publishing, and running ProAgentStore agents",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,138 +0,0 @@
1
- // src/bootstrap/payload.ts
2
- import { execFile } from "child_process";
3
- import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync } from "fs";
4
- import { homedir } from "os";
5
- import { join, win32 } from "path";
6
- import { promisify } from "util";
7
- var run = promisify(execFile);
8
- var CLI_PACKAGE = "@proagentstore/cli";
9
- var BOOTSTRAP_ENV = "PAGS_BOOTSTRAP";
10
- var NO_SELF_UPDATE_ENV = "PAGS_NO_SELF_UPDATE";
11
- var KEEP = 2;
12
- function payloadRoot() {
13
- return process.env.PAGS_CLI_CACHE || join(homedir(), ".config", "proagentstore", "cli");
14
- }
15
- function isVersion(v) {
16
- return typeof v === "string" && /^(\d+)\.(\d+)\.(\d+)/.test(v.trim());
17
- }
18
- function olderThan(a, b) {
19
- const parse = (v) => /^(\d+)\.(\d+)\.(\d+)/.exec(v.trim())?.slice(1).map(Number);
20
- const x = parse(a);
21
- const y = parse(b);
22
- if (!x || !y) return false;
23
- for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] < y[i];
24
- return false;
25
- }
26
- function payloadAt(dir) {
27
- try {
28
- const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
29
- if (pkg.name !== CLI_PACKAGE || !pkg.version) return null;
30
- const entry = join(dir, pkg.pagsPayload || "dist/index.js");
31
- return existsSync(entry) ? { version: pkg.version, entry } : null;
32
- } catch {
33
- return null;
34
- }
35
- }
36
- var installedAt = (prefix) => join(prefix, "node_modules", ...CLI_PACKAGE.split("/"));
37
- var packageDir = (root, version) => installedAt(join(root, version));
38
- function cachedPayloads(root = payloadRoot()) {
39
- let names;
40
- try {
41
- names = readdirSync(root);
42
- } catch {
43
- return [];
44
- }
45
- return names.flatMap((v) => v.startsWith(".") ? [] : payloadAt(packageDir(root, v)) ?? []);
46
- }
47
- function newestPayload(payloads) {
48
- return payloads.reduce((best, p) => !best || olderThan(best.version, p.version) ? p : best, null);
49
- }
50
- var CMD_META = /([()\][%!^"`<>&|;, *?])/g;
51
- function quoteCmdArg(arg) {
52
- const quoted = `"${arg.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1")}"`;
53
- return quoted.replace(CMD_META, "^$1").replace(CMD_META, "^$1");
54
- }
55
- var envVar = (env, name) => env[Object.keys(env).find((k) => k.toUpperCase() === name) ?? name];
56
- function npmInvocation(args, deps = {}) {
57
- if ((deps.platform ?? process.platform) !== "win32") return { file: "npm", args };
58
- const env = deps.env ?? process.env;
59
- const exists = deps.exists ?? existsSync;
60
- const execPath = deps.execPath ?? process.execPath;
61
- const cli = (dir) => win32.join(dir, "node_modules", "npm", "bin", "npm-cli.js");
62
- const onPath = (envVar(env, "PATH") ?? "").split(";").filter((dir) => dir && exists(win32.join(dir, "npm.cmd")));
63
- for (const dir of [...onPath, win32.dirname(execPath)]) {
64
- if (exists(cli(dir))) return { file: execPath, args: [cli(dir), ...args] };
65
- }
66
- const line = ["npm", ...args.map(quoteCmdArg)].join(" ");
67
- return { file: envVar(env, "COMSPEC") || "cmd.exe", args: ["/d", "/s", "/c", `"${line}"`], windowsVerbatimArguments: true };
68
- }
69
- function runNpm(args, options) {
70
- const npm = npmInvocation(args);
71
- return run(npm.file, npm.args, { ...options, ...npm.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {} });
72
- }
73
- async function latestPublishedRelease(timeoutMs = 3e4, signal, deps = {}) {
74
- try {
75
- const { stdout } = await (deps.runNpm ?? runNpm)(["view", CLI_PACKAGE, "version"], { timeout: timeoutMs, signal });
76
- const version = String(stdout).trim();
77
- return version ? { version } : { error: "npm printed no version" };
78
- } catch (e) {
79
- return { error: npmFailure(e) };
80
- }
81
- }
82
- function npmFailure(e) {
83
- const err = e;
84
- const stderr = String(err?.stderr ?? "").split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
85
- const npmErrors = stderr.filter((l) => /npm (ERR!|error)/i.test(l));
86
- const why = npmErrors.slice(0, 2).join(" ") || stderr.at(-1) || (err?.killed || err?.signal ? `npm did not answer in time (${String(err.signal ?? "killed")})` : "") || (typeof err?.code === "string" ? `npm could not be started (${err.code}: ${String(err.message ?? "")})` : "") || String(err?.message ?? e);
87
- return why.replace(/\s+/g, " ").trim().slice(0, 300);
88
- }
89
- async function latestPublishedVersion(timeoutMs = 3e4, signal) {
90
- const r = await latestPublishedRelease(timeoutMs, signal);
91
- return "version" in r ? r.version : null;
92
- }
93
- async function npmInstallInto(dir, version) {
94
- try {
95
- await runNpm(["install", "--prefix", dir, "--omit=dev", "--no-audit", "--no-fund", "--no-save", `${CLI_PACKAGE}@${version}`], { timeout: 5 * 6e4 });
96
- } catch (e) {
97
- const stderr = String(e.stderr ?? "").trim();
98
- throw new Error((stderr || (e instanceof Error ? e.message : String(e))).slice(-400));
99
- }
100
- }
101
- async function installPayload(version, root = payloadRoot(), install = npmInstallInto) {
102
- const done = payloadAt(packageDir(root, version));
103
- if (done) return done;
104
- mkdirSync(root, { recursive: true });
105
- const scratch = mkdtempSync(join(root, `.install-${version}-`));
106
- try {
107
- await install(scratch, version);
108
- if (payloadAt(installedAt(scratch))?.version !== version) throw new Error(`npm installed no ${CLI_PACKAGE}@${version}`);
109
- try {
110
- renameSync(scratch, join(root, version));
111
- } catch (e) {
112
- if (!payloadAt(packageDir(root, version))) throw e;
113
- }
114
- } finally {
115
- rmSync(scratch, { recursive: true, force: true });
116
- }
117
- const payload = payloadAt(packageDir(root, version));
118
- if (!payload) throw new Error(`${CLI_PACKAGE}@${version} is not usable after install`);
119
- for (const old of cachedPayloads(root).sort((a, b) => olderThan(a.version, b.version) ? 1 : -1).slice(KEEP)) {
120
- rmSync(join(root, old.version), { recursive: true, force: true });
121
- }
122
- return payload;
123
- }
124
-
125
- export {
126
- CLI_PACKAGE,
127
- BOOTSTRAP_ENV,
128
- NO_SELF_UPDATE_ENV,
129
- isVersion,
130
- olderThan,
131
- payloadAt,
132
- cachedPayloads,
133
- newestPayload,
134
- runNpm,
135
- latestPublishedRelease,
136
- latestPublishedVersion,
137
- installPayload
138
- };