@npie/cli 0.0.0-stage → 0.1.0-npie.10
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 +74 -2
- package/bin/t3.mjs +175 -0
- package/dist/bin.mjs +2 -0
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @npie/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**嗯哌 · Npie —— 开源的 AI 编程智能体控制台。**
|
|
4
|
+
|
|
5
|
+
The command-line entry point for [Npie](https://github.com/BannyLon/npie). It keeps a source
|
|
6
|
+
checkout on your machine, builds the server once, and runs it. Your code, prompts and keys stay
|
|
7
|
+
local; the server runs where your code is, and desktop, browser and phone connect to it.
|
|
8
|
+
|
|
9
|
+
## 用法
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx @npie/cli@latest # 首次运行会拉取源码并构建,需要几分钟
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
装成全局命令:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g @npie/cli
|
|
19
|
+
npie # 启动服务端并打开 Web 界面
|
|
20
|
+
npie serve # 只启动服务端
|
|
21
|
+
npie pair # 生成配对链接,供手机或其它设备连接
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 它做了什么
|
|
25
|
+
|
|
26
|
+
第一次运行 `npie` 时,它会:
|
|
27
|
+
|
|
28
|
+
1. 从 GitHub 下载对应版本的源码
|
|
29
|
+
2. 运行 `pnpm install --frozen-lockfile`
|
|
30
|
+
3. 构建服务端
|
|
31
|
+
4. 启动它
|
|
32
|
+
|
|
33
|
+
源码放在 `~/.npie-cli/source/<version>`,每个版本一个目录,构建完成后打上标记;再次运行会直接复用。
|
|
34
|
+
|
|
35
|
+
想换位置就设 `NPIE_HOME`。
|
|
36
|
+
|
|
37
|
+
## 前置要求
|
|
38
|
+
|
|
39
|
+
| | |
|
|
40
|
+
| ------- | --------------------------------------------------------------------- |
|
|
41
|
+
| Node.js | **24.10 或更新**(`node --version` 检查) |
|
|
42
|
+
| pnpm | 通过 `corepack enable pnpm` 启用(Node 24 自带;Node 25+ 需单独安装) |
|
|
43
|
+
| 磁盘 | 首次构建约需 1.5 GB(依赖 + 产物) |
|
|
44
|
+
| 智能体 | 至少安装并登录一个,例如 `claude auth login` 或 `codex login` |
|
|
45
|
+
|
|
46
|
+
## 为什么要先构建
|
|
47
|
+
|
|
48
|
+
Npie 目前只发布源码。预编译二进制需要 macOS 与 Windows 的代码签名证书,这个项目还没有。
|
|
49
|
+
与其发一个跑不起来的包,不如老实把构建放在这里——过程慢一点,但每一步都是透明的。
|
|
50
|
+
|
|
51
|
+
拿到签名证书后,这里会改成下载预编译版本,命令不变。
|
|
52
|
+
|
|
53
|
+
## 可能遇到的问题
|
|
54
|
+
|
|
55
|
+
**`pnpm: command not found`**
|
|
56
|
+
Node 24 执行 `corepack enable pnpm` 后重试;Node 25 起不再自带 corepack,请按 pnpm 官网单独安装。
|
|
57
|
+
|
|
58
|
+
**`ERR_PNPM_OUTDATED_LOCKFILE`**
|
|
59
|
+
源码包与锁文件不匹配,属于发布缺陷(源码包固定且有校验,重试或换版本都无效)。请到项目 Issues 反馈。
|
|
60
|
+
|
|
61
|
+
**构建卡住或失败**
|
|
62
|
+
删掉对应版本的目录再试:`rm -rf ~/.npie-cli/source/<version>`。
|
|
63
|
+
|
|
64
|
+
**公司网络装不上依赖**
|
|
65
|
+
设置 `npm_config_registry` 指向你的镜像,Npie 只是沿用 pnpm 的配置。
|
|
66
|
+
|
|
67
|
+
## 链接
|
|
68
|
+
|
|
69
|
+
- [项目主页](https://github.com/BannyLon/npie)
|
|
70
|
+
- [安装说明](https://github.com/BannyLon/npie/blob/main/docs/user/install.md)
|
|
71
|
+
- [常见问题](https://github.com/BannyLon/npie/blob/main/docs/user/faq.md)
|
|
72
|
+
|
|
73
|
+
## 许可
|
|
74
|
+
|
|
75
|
+
MIT。嗯哌是 [T3 Code](https://github.com/pingdotgg/t3code) 的开源分支,上游商标归 T3 Tools, Inc. 所有。
|
package/bin/t3.mjs
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Npie CLI bootstrap: builds a checkout from source in NPIE_HOME, then runs it.
|
|
3
|
+
// No prebuilt binaries: signing needs certificates this project does not hold.
|
|
4
|
+
|
|
5
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const { version } = JSON.parse(
|
|
13
|
+
fs.readFileSync(path.join(import.meta.dirname, "../package.json"), "utf8"),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const REPOSITORY = "BannyLon/npie";
|
|
17
|
+
// The release attaches a source archive and SHA256SUMS.txt covering it. Prefer those over
|
|
18
|
+
// GitHub's auto-generated tarball so the download can be verified against a published digest.
|
|
19
|
+
const RELEASE_BASE = `https://github.com/${REPOSITORY}/releases/download/v${version}`;
|
|
20
|
+
const TARBALL_NAME = `npie-v${version}-source.tar.gz`;
|
|
21
|
+
const TARBALL = `${RELEASE_BASE}/${TARBALL_NAME}`;
|
|
22
|
+
const CHECKSUMS = `${RELEASE_BASE}/SHA256SUMS.txt`;
|
|
23
|
+
const REQUIRED_NODE_MAJOR = 24;
|
|
24
|
+
const REQUIRED_NODE_MINOR = 10;
|
|
25
|
+
|
|
26
|
+
function npiHome() {
|
|
27
|
+
const raw = (process.env.NPIE_HOME || "").trim();
|
|
28
|
+
// Not `~/.npie`: that directory predates this project on some machines and holds
|
|
29
|
+
// unrelated data. Keep the bootstrap in its own tree, matching T3CODE_HOME's shape.
|
|
30
|
+
if (raw === "") return path.join(os.homedir(), ".npie-cli");
|
|
31
|
+
if (raw === "~") return os.homedir();
|
|
32
|
+
if (raw.startsWith("~/") || raw.startsWith("~\\")) return path.join(os.homedir(), raw.slice(2));
|
|
33
|
+
return path.resolve(raw);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function fail(message, hint) {
|
|
37
|
+
process.stderr.write(`npie: ${message}\n`);
|
|
38
|
+
if (hint) process.stderr.write(`\n${hint}\n`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function which(command) {
|
|
43
|
+
const probe = spawnSync(command, ["--version"], { stdio: "ignore" });
|
|
44
|
+
return probe.status === 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function run(command, args, options = {}) {
|
|
48
|
+
const result = spawnSync(command, args, { stdio: "inherit", ...options });
|
|
49
|
+
if (result.error) fail(`could not run ${command}`, String(result.error.message));
|
|
50
|
+
if (result.status !== 0) {
|
|
51
|
+
fail(`${command} ${args.join(" ")} exited with ${result.status || result.signal}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function fetchText(url) {
|
|
56
|
+
const response = await fetch(url, { redirect: "follow" });
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
throw new Error(`could not download ${url} (HTTP ${response.status})`);
|
|
59
|
+
}
|
|
60
|
+
return response.text();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Downloads the release source archive and verifies it against the published digest. */
|
|
64
|
+
async function downloadSource(target) {
|
|
65
|
+
let expected;
|
|
66
|
+
try {
|
|
67
|
+
const sums = await fetchText(CHECKSUMS);
|
|
68
|
+
const line = sums.split("\n").find((entry) => entry.trim().endsWith(TARBALL_NAME));
|
|
69
|
+
expected = line?.trim().split(/\s+/)[0];
|
|
70
|
+
} catch (error) {
|
|
71
|
+
fail(
|
|
72
|
+
`could not read the checksums for v${version}`,
|
|
73
|
+
`${String(error?.message ?? error)}\nCheck that the tag exists: https://github.com/${REPOSITORY}/releases`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
// Publishing an archive without a matching digest is a release bug, not something to skip.
|
|
77
|
+
if (!expected || !/^[0-9a-f]{64}$/i.test(expected)) {
|
|
78
|
+
fail(`v${version} has no SHA256 digest for ${TARBALL_NAME}; refusing an unverified download.`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let response;
|
|
82
|
+
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
83
|
+
response = await fetch(TARBALL, { redirect: "follow" });
|
|
84
|
+
if (response.ok || (response.status < 500 && response.status !== 429)) break;
|
|
85
|
+
await response.body?.cancel();
|
|
86
|
+
await new Promise((resolve) => setTimeout(resolve, 500 * 2 ** attempt));
|
|
87
|
+
}
|
|
88
|
+
if (!response?.ok) {
|
|
89
|
+
fail(
|
|
90
|
+
`could not download Npie v${version} (HTTP ${response?.status ?? "?"})`,
|
|
91
|
+
`Check that the tag exists: https://github.com/${REPOSITORY}/releases`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
95
|
+
const actual = createHash("sha256").update(bytes).digest("hex");
|
|
96
|
+
if (actual !== expected.toLowerCase()) {
|
|
97
|
+
fail(`checksum mismatch for ${TARBALL_NAME}`, `expected ${expected}, got ${actual}`);
|
|
98
|
+
}
|
|
99
|
+
fs.writeFileSync(target, bytes);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** One checkout per version, marked complete only after dependencies and the build land. */
|
|
103
|
+
async function bootstrap(sourceDir) {
|
|
104
|
+
const complete = path.join(sourceDir, ".npie-complete");
|
|
105
|
+
if (fs.existsSync(complete) && fs.readFileSync(complete, "utf8").trim() === version) return;
|
|
106
|
+
|
|
107
|
+
if (!which("node")) fail("Node.js is required but was not found on PATH.");
|
|
108
|
+
const [major, minor] = process.versions.node.split(".").map(Number);
|
|
109
|
+
if (
|
|
110
|
+
major < REQUIRED_NODE_MAJOR ||
|
|
111
|
+
(major === REQUIRED_NODE_MAJOR && minor < REQUIRED_NODE_MINOR)
|
|
112
|
+
) {
|
|
113
|
+
fail(
|
|
114
|
+
`Npie needs Node.js ${REQUIRED_NODE_MAJOR}.${REQUIRED_NODE_MINOR} or newer; this is ${process.versions.node}.`,
|
|
115
|
+
"Install it from https://nodejs.org, then run this command again.",
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (!which("pnpm")) {
|
|
119
|
+
fail(
|
|
120
|
+
"pnpm is required but was not found on PATH.",
|
|
121
|
+
"Enable it with `corepack enable pnpm` (bundled with Node.js), then run this command again.",
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// mkdtemp needs its parent to exist; on a first run ~/.npie/source does not.
|
|
126
|
+
fs.mkdirSync(path.dirname(sourceDir), { recursive: true });
|
|
127
|
+
const staging = fs.mkdtempSync(`${sourceDir}.staging-`);
|
|
128
|
+
process.stderr.write(`npie: fetching Npie v${version}…\n`);
|
|
129
|
+
const tarball = path.join(staging, "source.tar.gz");
|
|
130
|
+
await downloadSource(tarball);
|
|
131
|
+
|
|
132
|
+
process.stderr.write("npie: unpacking…\n");
|
|
133
|
+
run("tar", ["-xzf", tarball, "-C", staging, "--strip-components=1"]);
|
|
134
|
+
fs.rmSync(tarball);
|
|
135
|
+
|
|
136
|
+
process.stderr.write("npie: installing dependencies (this takes a few minutes)…\n");
|
|
137
|
+
run("pnpm", ["install", "--frozen-lockfile"], { cwd: staging });
|
|
138
|
+
|
|
139
|
+
process.stderr.write("npie: building the server…\n");
|
|
140
|
+
// The server package's bundling script is `build:bundle`; there is no plain `build`.
|
|
141
|
+
run("pnpm", ["--filter", "t3", "run", "build:bundle"], { cwd: staging });
|
|
142
|
+
|
|
143
|
+
fs.writeFileSync(path.join(staging, ".npie-complete"), `${version}\n`);
|
|
144
|
+
fs.rmSync(sourceDir, { recursive: true, force: true });
|
|
145
|
+
fs.mkdirSync(path.dirname(sourceDir), { recursive: true });
|
|
146
|
+
fs.renameSync(staging, sourceDir);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function main() {
|
|
150
|
+
const sourceDir = path.join(npiHome(), "source", version);
|
|
151
|
+
await bootstrap(sourceDir);
|
|
152
|
+
|
|
153
|
+
const entry = path.join(sourceDir, "apps", "server", "dist", "bin.mjs");
|
|
154
|
+
if (!fs.existsSync(entry)) {
|
|
155
|
+
fail(
|
|
156
|
+
`the build finished but ${entry} is missing.`,
|
|
157
|
+
`Delete ${sourceDir} and run this command again.`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const child = spawn(process.execPath, [entry, ...process.argv.slice(2)], {
|
|
162
|
+
stdio: "inherit",
|
|
163
|
+
env: { ...process.env, NPIE_NPM_LAUNCHER_PATH: fileURLToPath(import.meta.url) },
|
|
164
|
+
});
|
|
165
|
+
child.on("exit", (code, signal) => {
|
|
166
|
+
process.exit(code ?? (signal ? 1 : 0));
|
|
167
|
+
});
|
|
168
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
169
|
+
process.on(signal, () => child.kill(signal));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
main().catch((error) => {
|
|
174
|
+
fail(error?.message ?? String(error));
|
|
175
|
+
});
|
package/dist/bin.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npie/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-npie.10",
|
|
4
|
+
"description": "Npie CLI. Bootstraps an Npie checkout and runs it. 嗯哌 —— 开源的 AI 编程智能体控制台。",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/BannyLon/npie.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/BannyLon/npie",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"npie",
|
|
13
|
+
"嗯哌",
|
|
14
|
+
"coding-agent",
|
|
15
|
+
"ai-agents",
|
|
16
|
+
"cli"
|
|
17
|
+
],
|
|
18
|
+
"bin": {
|
|
19
|
+
"npie": "bin/t3.mjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"bin",
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=24.10"
|
|
27
|
+
},
|
|
28
|
+
"t3code": {
|
|
29
|
+
"databaseMigration": 119
|
|
30
|
+
}
|
|
31
|
+
}
|