@npie/cli 0.1.0-npie.1 → 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.
Files changed (3) hide show
  1. package/README.md +16 -16
  2. package/bin/t3.mjs +54 -18
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -16,32 +16,32 @@ npx @npie/cli@latest # 首次运行会拉取源码并构建,需要几
16
16
 
17
17
  ```bash
18
18
  npm install -g @npie/cli
19
- t3 # 启动服务端并打开 Web 界面
20
- t3 serve # 只启动服务端
21
- t3 pair # 生成配对链接,供手机或其它设备连接
19
+ npie # 启动服务端并打开 Web 界面
20
+ npie serve # 只启动服务端
21
+ npie pair # 生成配对链接,供手机或其它设备连接
22
22
  ```
23
23
 
24
24
  ## 它做了什么
25
25
 
26
- 第一次运行 `t3` 时,它会:
26
+ 第一次运行 `npie` 时,它会:
27
27
 
28
28
  1. 从 GitHub 下载对应版本的源码
29
29
  2. 运行 `pnpm install --frozen-lockfile`
30
30
  3. 构建服务端
31
31
  4. 启动它
32
32
 
33
- 源码放在 `~/.npie/source/<version>`,每个版本一个目录,构建完成后打上标记;再次运行会直接复用。
33
+ 源码放在 `~/.npie-cli/source/<version>`,每个版本一个目录,构建完成后打上标记;再次运行会直接复用。
34
34
 
35
35
  想换位置就设 `NPIE_HOME`。
36
36
 
37
37
  ## 前置要求
38
38
 
39
- | | |
40
- | --- | --- |
41
- | Node.js | **24 或更新**(`node --version` 检查) |
42
- | pnpm | 通过 `corepack enable pnpm` 启用,Node 自带 |
43
- | 磁盘 | 首次构建约需 1.5 GB(依赖 + 产物) |
44
- | 智能体 | 至少安装并登录一个,例如 `claude auth login` 或 `codex login` |
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
45
 
46
46
  ## 为什么要先构建
47
47
 
@@ -53,13 +53,13 @@ Npie 目前只发布源码。预编译二进制需要 macOS 与 Windows 的代
53
53
  ## 可能遇到的问题
54
54
 
55
55
  **`pnpm: command not found`**
56
- Node 24 自带 corepack,执行 `corepack enable pnpm` 后重试。
56
+ Node 24 执行 `corepack enable pnpm` 后重试;Node 25 起不再自带 corepack,请按 pnpm 官网单独安装。
57
57
 
58
58
  **`ERR_PNPM_OUTDATED_LOCKFILE`**
59
- 源码与锁文件不匹配,通常是版本刚发布。等几分钟重试,或换 `@latest`。
59
+ 源码包与锁文件不匹配,属于发布缺陷(源码包固定且有校验,重试或换版本都无效)。请到项目 Issues 反馈。
60
60
 
61
61
  **构建卡住或失败**
62
- 删掉对应版本的目录再试:`rm -rf ~/.npie/source/<version>`。
62
+ 删掉对应版本的目录再试:`rm -rf ~/.npie-cli/source/<version>`。
63
63
 
64
64
  **公司网络装不上依赖**
65
65
  设置 `npm_config_registry` 指向你的镜像,Npie 只是沿用 pnpm 的配置。
@@ -67,8 +67,8 @@ Node 24 自带 corepack,执行 `corepack enable pnpm` 后重试。
67
67
  ## 链接
68
68
 
69
69
  - [项目主页](https://github.com/BannyLon/npie)
70
- - [安装说明](https://github.com/BannyLon/npie/blob/npie/docs/user/install.md)
71
- - [常见问题](https://github.com/BannyLon/npie/blob/npie/docs/user/faq.md)
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
72
 
73
73
  ## 许可
74
74
 
package/bin/t3.mjs CHANGED
@@ -1,16 +1,9 @@
1
1
  #!/usr/bin/env node
2
- // Npie CLI bootstrap.
3
- //
4
- // Npie ships source only. This launcher keeps a checkout in NPIE_HOME (default
5
- // ~/.npie/source), fetches the requested version, installs dependencies once, builds the
6
- // server, and then runs it. The bin is still called `t3` because every doc, service unit
7
- // and keybinding in the product uses that name.
8
- //
9
- // Why not ship prebuilt binaries: signing macOS and Windows builds needs certificates
10
- // this project does not hold yet. A bootstrap is honest about what it does and works on
11
- // every platform Node runs on.
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.
12
4
 
13
5
  import { spawn, spawnSync } from "node:child_process";
6
+ import { createHash } from "node:crypto";
14
7
  import fs from "node:fs";
15
8
  import os from "node:os";
16
9
  import path from "node:path";
@@ -21,12 +14,20 @@ const { version } = JSON.parse(
21
14
  );
22
15
 
23
16
  const REPOSITORY = "BannyLon/npie";
24
- const TARBALL = `https://codeload.github.com/${REPOSITORY}/tar.gz/refs/tags/v${version}`;
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`;
25
23
  const REQUIRED_NODE_MAJOR = 24;
24
+ const REQUIRED_NODE_MINOR = 10;
26
25
 
27
26
  function npiHome() {
28
27
  const raw = (process.env.NPIE_HOME || "").trim();
29
- if (raw === "") return path.join(os.homedir(), ".npie");
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");
30
31
  if (raw === "~") return os.homedir();
31
32
  if (raw.startsWith("~/") || raw.startsWith("~\\")) return path.join(os.homedir(), raw.slice(2));
32
33
  return path.resolve(raw);
@@ -51,7 +52,32 @@ function run(command, args, options = {}) {
51
52
  }
52
53
  }
53
54
 
54
- async function downloadTarball(target) {
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
+
55
81
  let response;
56
82
  for (let attempt = 1; attempt <= 3; attempt += 1) {
57
83
  response = await fetch(TARBALL, { redirect: "follow" });
@@ -65,7 +91,12 @@ async function downloadTarball(target) {
65
91
  `Check that the tag exists: https://github.com/${REPOSITORY}/releases`,
66
92
  );
67
93
  }
68
- fs.writeFileSync(target, Buffer.from(await response.arrayBuffer()));
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);
69
100
  }
70
101
 
71
102
  /** One checkout per version, marked complete only after dependencies and the build land. */
@@ -74,10 +105,13 @@ async function bootstrap(sourceDir) {
74
105
  if (fs.existsSync(complete) && fs.readFileSync(complete, "utf8").trim() === version) return;
75
106
 
76
107
  if (!which("node")) fail("Node.js is required but was not found on PATH.");
77
- const major = Number(process.versions.node.split(".")[0]);
78
- if (major < REQUIRED_NODE_MAJOR) {
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
+ ) {
79
113
  fail(
80
- `Npie needs Node.js ${REQUIRED_NODE_MAJOR} or newer; this is ${process.versions.node}.`,
114
+ `Npie needs Node.js ${REQUIRED_NODE_MAJOR}.${REQUIRED_NODE_MINOR} or newer; this is ${process.versions.node}.`,
81
115
  "Install it from https://nodejs.org, then run this command again.",
82
116
  );
83
117
  }
@@ -88,10 +122,12 @@ async function bootstrap(sourceDir) {
88
122
  );
89
123
  }
90
124
 
125
+ // mkdtemp needs its parent to exist; on a first run ~/.npie/source does not.
126
+ fs.mkdirSync(path.dirname(sourceDir), { recursive: true });
91
127
  const staging = fs.mkdtempSync(`${sourceDir}.staging-`);
92
128
  process.stderr.write(`npie: fetching Npie v${version}…\n`);
93
129
  const tarball = path.join(staging, "source.tar.gz");
94
- await downloadTarball(tarball);
130
+ await downloadSource(tarball);
95
131
 
96
132
  process.stderr.write("npie: unpacking…\n");
97
133
  run("tar", ["-xzf", tarball, "-C", staging, "--strip-components=1"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npie/cli",
3
- "version": "0.1.0-npie.1",
3
+ "version": "0.1.0-npie.10",
4
4
  "description": "Npie CLI. Bootstraps an Npie checkout and runs it. 嗯哌 —— 开源的 AI 编程智能体控制台。",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,14 +16,14 @@
16
16
  "cli"
17
17
  ],
18
18
  "bin": {
19
- "t3": "bin/t3.mjs"
19
+ "npie": "bin/t3.mjs"
20
20
  },
21
21
  "files": [
22
22
  "bin",
23
23
  "dist"
24
24
  ],
25
25
  "engines": {
26
- "node": ">=20.11"
26
+ "node": ">=24.10"
27
27
  },
28
28
  "t3code": {
29
29
  "databaseMigration": 119