@howone/agent-cli 0.5.2 → 0.5.3
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/README.md +18 -0
- package/bin/index.mjs +193 -7
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -43,3 +43,21 @@ npm install -g @howone/agent-cli
|
|
|
43
43
|
已有同路径 HowOne Skill 会被更新。其他 Skill 不受影响。
|
|
44
44
|
禁用安装脚本(如 --ignore-scripts)的环境需手动运行 howone setup --target codex。
|
|
45
45
|
Skill 安装失败不会阻止 CLI 安装,使用 setup 可重试。
|
|
46
|
+
|
|
47
|
+
## 自动更新
|
|
48
|
+
|
|
49
|
+
npm 全局安装的 CLI 在命令成功结束后,后台每天检查一次 npm `latest` 稳定版。
|
|
50
|
+
有新版时,自动更新同一安装位置的 `@howone/agent-cli`,并通过安装脚本更新 Skill。
|
|
51
|
+
本次命令继续使用原版本,下次启动使用新版;登录凭证和 App 文件不变。
|
|
52
|
+
检查和更新失败不会阻断命令,也不会污染 `--json` 输出。
|
|
53
|
+
|
|
54
|
+
设置 `HOWONE_AUTO_UPDATE=0` 可关闭自动更新。CI、源码开发、npx 临时运行和无写权限的
|
|
55
|
+
系统级安装跳过自动更新;不会请求 sudo,也不会更改 npm 的全局 registry 配置。
|
|
56
|
+
此功能需先手动安装包含它的新版 CLI,旧版不会自行获得更新能力。
|
|
57
|
+
|
|
58
|
+
## 临时跳过 API 证书校验
|
|
59
|
+
|
|
60
|
+
`howone login --api-url https://isoeax.howone.dev --insecure` 显式跳过本次命令的
|
|
61
|
+
目标 API 证书校验,并在 stderr 显示警告。该设置不保存,后续命令需要再次指定。
|
|
62
|
+
默认仍校验证书;优先修复公司 CA 或服务端证书链。该参数不会影响 npm 自动更新,
|
|
63
|
+
不允许把跳过校验的请求重定向到其他地址,也不会修改系统或 Node 的全局 TLS 设置。
|
package/bin/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { execFile, spawn } from "node:child_process";
|
|
4
|
-
import { appendFile, chmod, cp, lstat, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { access, appendFile, chmod, cp, lstat, mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { promisify } from "node:util";
|
|
@@ -11,9 +11,155 @@ import { copy, emptyDir, ensureDir, pathExists } from "fs-extra/esm";
|
|
|
11
11
|
import pc from "picocolors";
|
|
12
12
|
import validatePackageName from "validate-npm-package-name";
|
|
13
13
|
import yargsParser from "yargs-parser";
|
|
14
|
-
import { existsSync, watch } from "node:fs";
|
|
15
|
-
import os from "node:os";
|
|
16
14
|
import { createHash, randomUUID } from "node:crypto";
|
|
15
|
+
import { constants, existsSync, watch } from "node:fs";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
//#region src/auto-update.ts
|
|
18
|
+
const execFileAsync$2 = promisify(execFile);
|
|
19
|
+
const PACKAGE = "@howone/agent-cli";
|
|
20
|
+
const REGISTRY = "https://registry.npmjs.org/";
|
|
21
|
+
const DAY = 1440 * 60 * 1e3;
|
|
22
|
+
const LOCK_TTL = 600 * 1e3;
|
|
23
|
+
const WORKER_ARG = "--internal-auto-update";
|
|
24
|
+
function globalInstallPrefix(root, platform = process.platform) {
|
|
25
|
+
if (path.basename(root) !== "agent-cli" || path.basename(path.dirname(root)) !== "@howone") return null;
|
|
26
|
+
const modules = path.dirname(path.dirname(root));
|
|
27
|
+
if (path.basename(modules) !== "node_modules") return null;
|
|
28
|
+
const parent = path.dirname(modules);
|
|
29
|
+
if (platform === "win32") {
|
|
30
|
+
if (path.basename(parent) === "_npx" || parent.includes(`${path.sep}_npx${path.sep}`)) return null;
|
|
31
|
+
return parent;
|
|
32
|
+
}
|
|
33
|
+
return path.basename(parent) === "lib" ? path.dirname(parent) : null;
|
|
34
|
+
}
|
|
35
|
+
function autoUpdateEnabled(env = process.env) {
|
|
36
|
+
return env.HOWONE_AUTO_UPDATE !== "0" && !env.CI && !env.npm_lifecycle_event && !env.npm_execpath?.includes("npx");
|
|
37
|
+
}
|
|
38
|
+
/** Only a completed command starts the detached updater; stdout/JSON stays untouched. */
|
|
39
|
+
function scheduleAutoUpdate(root) {
|
|
40
|
+
if (!autoUpdateEnabled() || !globalInstallPrefix(root)) return;
|
|
41
|
+
process.once("exit", (code) => {
|
|
42
|
+
if (code !== 0) return;
|
|
43
|
+
try {
|
|
44
|
+
const child = spawn(process.execPath, [path.join(root, "bin", "index.mjs"), WORKER_ARG], {
|
|
45
|
+
detached: true,
|
|
46
|
+
stdio: "ignore",
|
|
47
|
+
windowsHide: true
|
|
48
|
+
});
|
|
49
|
+
child.on("error", () => {});
|
|
50
|
+
child.unref();
|
|
51
|
+
} catch {}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function newerStable(latest, current) {
|
|
55
|
+
if (!/^\d+\.\d+\.\d+$/.test(latest) || !/^\d+\.\d+\.\d+$/.test(current)) return false;
|
|
56
|
+
const a = latest.split(".").map(Number);
|
|
57
|
+
const b = current.split(".").map(Number);
|
|
58
|
+
for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
async function npmCommand() {
|
|
62
|
+
if (process.platform === "win32") {
|
|
63
|
+
const candidates = [path.join(path.dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js"), ...(process.env.PATH ?? "").split(path.delimiter).map((dir) => path.join(dir, "node_modules", "npm", "bin", "npm-cli.js"))];
|
|
64
|
+
for (const candidate of candidates) if (await stat(candidate).then((s) => s.isFile()).catch(() => false)) return {
|
|
65
|
+
executable: process.execPath,
|
|
66
|
+
args: [candidate]
|
|
67
|
+
};
|
|
68
|
+
throw new Error("npm is not available");
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
executable: "npm",
|
|
72
|
+
args: []
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async function runAutoUpdate(options) {
|
|
76
|
+
const prefix = globalInstallPrefix(options.root);
|
|
77
|
+
if (!prefix || !autoUpdateEnabled(options.env)) return;
|
|
78
|
+
if (await realpath(options.root) !== path.resolve(options.root)) return;
|
|
79
|
+
const launcher = process.platform === "win32" ? path.join(prefix, "howone.cmd") : path.join(prefix, "bin", "howone");
|
|
80
|
+
if (process.platform === "win32") {
|
|
81
|
+
if (!(await stat(launcher)).isFile()) return;
|
|
82
|
+
} else if (await realpath(launcher) !== path.join(options.root, "bin", "index.mjs")) return;
|
|
83
|
+
await Promise.all([
|
|
84
|
+
options.root,
|
|
85
|
+
path.dirname(path.dirname(options.root)),
|
|
86
|
+
process.platform === "win32" ? prefix : path.join(prefix, "bin")
|
|
87
|
+
].map((dir) => access(dir, constants.W_OK)));
|
|
88
|
+
const key = createHash("sha256").update(prefix).digest("hex").slice(0, 16);
|
|
89
|
+
const cacheDir = options.cacheDir ?? path.join(process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"), "howone", "updates");
|
|
90
|
+
await mkdir(cacheDir, {
|
|
91
|
+
recursive: true,
|
|
92
|
+
mode: 448
|
|
93
|
+
});
|
|
94
|
+
const stateFile = path.join(cacheDir, `${key}.json`);
|
|
95
|
+
const lock = path.join(cacheDir, `${key}.lock`);
|
|
96
|
+
const now = options.now ?? Date.now();
|
|
97
|
+
const lockStat = await stat(lock).catch(() => null);
|
|
98
|
+
if (lockStat && now - lockStat.mtimeMs > LOCK_TTL) await rm(lock, {
|
|
99
|
+
recursive: true,
|
|
100
|
+
force: true
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
await mkdir(lock);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error.code === "EEXIST") return;
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const previous = await readFile(stateFile, "utf8").then(JSON.parse).catch(() => null);
|
|
110
|
+
if (previous?.checkedAt && now - previous.checkedAt < DAY) return;
|
|
111
|
+
await writeFile(stateFile, JSON.stringify({ checkedAt: now }), { mode: 384 });
|
|
112
|
+
const npm = options.runNpm ? null : await npmCommand();
|
|
113
|
+
const runNpm = options.runNpm ?? (async (args) => {
|
|
114
|
+
const { stdout } = await execFileAsync$2(npm.executable, [...npm.args, ...args], {
|
|
115
|
+
timeout: args[0] === "view" ? 2e4 : 18e4,
|
|
116
|
+
maxBuffer: 1024 * 1024,
|
|
117
|
+
windowsHide: true,
|
|
118
|
+
env: {
|
|
119
|
+
...process.env,
|
|
120
|
+
HOWONE_AUTO_UPDATE: "0"
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return stdout;
|
|
124
|
+
});
|
|
125
|
+
const registryArgs = [`--registry=${REGISTRY}`, `--@howone:registry=${REGISTRY}`];
|
|
126
|
+
const latest = JSON.parse(await runNpm([
|
|
127
|
+
"view",
|
|
128
|
+
`${PACKAGE}@latest`,
|
|
129
|
+
"version",
|
|
130
|
+
"--json",
|
|
131
|
+
...registryArgs,
|
|
132
|
+
"--fetch-retries=0",
|
|
133
|
+
"--fetch-timeout=15000"
|
|
134
|
+
]));
|
|
135
|
+
if (typeof latest !== "string" || !newerStable(latest, options.currentVersion)) return;
|
|
136
|
+
await runNpm([
|
|
137
|
+
"install",
|
|
138
|
+
"--global",
|
|
139
|
+
"--prefix",
|
|
140
|
+
prefix,
|
|
141
|
+
`${PACKAGE}@${latest}`,
|
|
142
|
+
...registryArgs,
|
|
143
|
+
"--engine-strict",
|
|
144
|
+
"--ignore-scripts=false",
|
|
145
|
+
"--no-audit",
|
|
146
|
+
"--no-fund",
|
|
147
|
+
"--fetch-retries=0",
|
|
148
|
+
"--fetch-timeout=30000"
|
|
149
|
+
]);
|
|
150
|
+
await writeFile(stateFile, JSON.stringify({
|
|
151
|
+
checkedAt: now,
|
|
152
|
+
updatedTo: latest
|
|
153
|
+
}), { mode: 384 });
|
|
154
|
+
} finally {
|
|
155
|
+
await rm(lock, {
|
|
156
|
+
recursive: true,
|
|
157
|
+
force: true
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const isAutoUpdateWorker = () => process.argv[2] === WORKER_ARG;
|
|
162
|
+
//#endregion
|
|
17
163
|
//#region src/errors.ts
|
|
18
164
|
var CliError = class extends Error {
|
|
19
165
|
constructor(code, message, details) {
|
|
@@ -25,10 +171,34 @@ var CliError = class extends Error {
|
|
|
25
171
|
};
|
|
26
172
|
//#endregion
|
|
27
173
|
//#region src/network.ts
|
|
174
|
+
let insecureOrigin;
|
|
175
|
+
let insecureDispatcher;
|
|
176
|
+
/** Explicit command-local exception; never changes Node's global TLS settings. */
|
|
177
|
+
function configureInsecureTls(apiUrl) {
|
|
178
|
+
insecureOrigin = new URL(apiUrl).origin;
|
|
179
|
+
}
|
|
28
180
|
async function networkFetch(url, init) {
|
|
29
181
|
const target = new URL(url);
|
|
30
182
|
if (!["http:", "https:"].includes(target.protocol) || target.username || target.password) throw new CliError("E_BAD_URL", "Use an HTTP(S) API URL without embedded credentials.");
|
|
31
183
|
try {
|
|
184
|
+
if (target.protocol === "https:" && target.origin === insecureOrigin) {
|
|
185
|
+
const { Agent, EnvHttpProxyAgent, fetch: insecureFetch } = await import("undici");
|
|
186
|
+
const hasProxy = [
|
|
187
|
+
"http_proxy",
|
|
188
|
+
"HTTP_PROXY",
|
|
189
|
+
"https_proxy",
|
|
190
|
+
"HTTPS_PROXY"
|
|
191
|
+
].some((key) => process.env[key]);
|
|
192
|
+
insecureDispatcher ??= hasProxy ? new EnvHttpProxyAgent({
|
|
193
|
+
connect: { rejectUnauthorized: false },
|
|
194
|
+
requestTls: { rejectUnauthorized: false }
|
|
195
|
+
}) : new Agent({ connect: { rejectUnauthorized: false } });
|
|
196
|
+
return await insecureFetch(target, {
|
|
197
|
+
...init,
|
|
198
|
+
redirect: "error",
|
|
199
|
+
dispatcher: insecureDispatcher
|
|
200
|
+
});
|
|
201
|
+
}
|
|
32
202
|
return await fetch(target, init);
|
|
33
203
|
} catch (error) {
|
|
34
204
|
if (init?.signal?.aborted) throw error;
|
|
@@ -1501,11 +1671,24 @@ const execFileAsync = promisify(execFile);
|
|
|
1501
1671
|
const DEFAULT_PROJECT_NAME = "howone-app";
|
|
1502
1672
|
const TEMPLATES = ["vite"];
|
|
1503
1673
|
const TEMPLATE_ALIASES = { vite: "vite" };
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1674
|
+
if (isAutoUpdateWorker()) runAutoUpdate({
|
|
1675
|
+
root: path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."),
|
|
1676
|
+
currentVersion: packageJson.version
|
|
1677
|
+
}).catch(() => {});
|
|
1678
|
+
else {
|
|
1679
|
+
scheduleAutoUpdate(path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."));
|
|
1680
|
+
main().catch((error) => {
|
|
1681
|
+
handleFatalError(error, process.argv.includes("--json"));
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1507
1684
|
async function main() {
|
|
1508
1685
|
const command = parseCommand(process.argv.slice(2));
|
|
1686
|
+
if (command.options.insecure && !command.options.help && !command.options.version) {
|
|
1687
|
+
const destination = command.options.apiUrl?.trim();
|
|
1688
|
+
const connection = await resolveConnection({ apiUrl: destination && !destination.includes("://") ? `https://${destination}` : destination });
|
|
1689
|
+
configureInsecureTls(connection.apiUrl);
|
|
1690
|
+
console.error(`Warning: --insecure disables TLS certificate verification for ${new URL(connection.apiUrl).origin} for this command only.`);
|
|
1691
|
+
}
|
|
1509
1692
|
if (command.options.version) {
|
|
1510
1693
|
console.log(packageJson.version);
|
|
1511
1694
|
return;
|
|
@@ -1613,7 +1796,8 @@ function parseCommand(args) {
|
|
|
1613
1796
|
"skill",
|
|
1614
1797
|
"browser",
|
|
1615
1798
|
"fresh",
|
|
1616
|
-
"wait"
|
|
1799
|
+
"wait",
|
|
1800
|
+
"insecure"
|
|
1617
1801
|
],
|
|
1618
1802
|
default: {
|
|
1619
1803
|
build: true,
|
|
@@ -1663,6 +1847,7 @@ function parseCommand(args) {
|
|
|
1663
1847
|
prompt: typeof parsed.prompt === "string" ? parsed.prompt : void 0,
|
|
1664
1848
|
region: typeof parsed.region === "string" ? parsed.region : void 0,
|
|
1665
1849
|
apiUrl: typeof parsed["api-url"] === "string" ? parsed["api-url"] : void 0,
|
|
1850
|
+
insecure: Boolean(parsed.insecure),
|
|
1666
1851
|
token: typeof parsed.token === "string" ? parsed.token : void 0,
|
|
1667
1852
|
stream: Boolean(parsed.stream),
|
|
1668
1853
|
status: typeof parsed.status === "string" ? parsed.status : void 0,
|
|
@@ -2307,6 +2492,7 @@ function printRootHelp() {
|
|
|
2307
2492
|
formatCommand("-v, --version", "Show version"),
|
|
2308
2493
|
formatCommand("--app <app>", "Which app (default: the pulled directory you are in)"),
|
|
2309
2494
|
formatCommand("--json", "Machine-readable output (for agents and CI)"),
|
|
2495
|
+
formatCommand("--insecure", "Skip API TLS certificate verification for this command only"),
|
|
2310
2496
|
"",
|
|
2311
2497
|
pc.bold("Examples"),
|
|
2312
2498
|
` ${pc.cyan("howone login")}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howone/agent-cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "HowOne CLI and agent skill installer for Codex and Claude.",
|
|
6
6
|
"type": "module",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@clack/prompts": "^1.3.0",
|
|
37
37
|
"fs-extra": "^11.3.4",
|
|
38
38
|
"picocolors": "^1.1.1",
|
|
39
|
+
"undici": "^6.27.0",
|
|
39
40
|
"validate-npm-package-name": "^7.0.2",
|
|
40
41
|
"yargs-parser": "^22.0.0"
|
|
41
42
|
},
|