@npie/cli 0.0.0-stage → 0.1.0-npie.1

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 CHANGED
@@ -1,3 +1,75 @@
1
- # Temporary Holding Version
1
+ # @npie/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ t3 # 启动服务端并打开 Web 界面
20
+ t3 serve # 只启动服务端
21
+ t3 pair # 生成配对链接,供手机或其它设备连接
22
+ ```
23
+
24
+ ## 它做了什么
25
+
26
+ 第一次运行 `t3` 时,它会:
27
+
28
+ 1. 从 GitHub 下载对应版本的源码
29
+ 2. 运行 `pnpm install --frozen-lockfile`
30
+ 3. 构建服务端
31
+ 4. 启动它
32
+
33
+ 源码放在 `~/.npie/source/<version>`,每个版本一个目录,构建完成后打上标记;再次运行会直接复用。
34
+
35
+ 想换位置就设 `NPIE_HOME`。
36
+
37
+ ## 前置要求
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` |
45
+
46
+ ## 为什么要先构建
47
+
48
+ Npie 目前只发布源码。预编译二进制需要 macOS 与 Windows 的代码签名证书,这个项目还没有。
49
+ 与其发一个跑不起来的包,不如老实把构建放在这里——过程慢一点,但每一步都是透明的。
50
+
51
+ 拿到签名证书后,这里会改成下载预编译版本,命令不变。
52
+
53
+ ## 可能遇到的问题
54
+
55
+ **`pnpm: command not found`**
56
+ Node 24 自带 corepack,执行 `corepack enable pnpm` 后重试。
57
+
58
+ **`ERR_PNPM_OUTDATED_LOCKFILE`**
59
+ 源码与锁文件不匹配,通常是版本刚发布。等几分钟重试,或换 `@latest`。
60
+
61
+ **构建卡住或失败**
62
+ 删掉对应版本的目录再试:`rm -rf ~/.npie/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/npie/docs/user/install.md)
71
+ - [常见问题](https://github.com/BannyLon/npie/blob/npie/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,139 @@
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.
12
+
13
+ import { spawn, spawnSync } from "node:child_process";
14
+ import fs from "node:fs";
15
+ import os from "node:os";
16
+ import path from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+
19
+ const { version } = JSON.parse(
20
+ fs.readFileSync(path.join(import.meta.dirname, "../package.json"), "utf8"),
21
+ );
22
+
23
+ const REPOSITORY = "BannyLon/npie";
24
+ const TARBALL = `https://codeload.github.com/${REPOSITORY}/tar.gz/refs/tags/v${version}`;
25
+ const REQUIRED_NODE_MAJOR = 24;
26
+
27
+ function npiHome() {
28
+ const raw = (process.env.NPIE_HOME || "").trim();
29
+ if (raw === "") return path.join(os.homedir(), ".npie");
30
+ if (raw === "~") return os.homedir();
31
+ if (raw.startsWith("~/") || raw.startsWith("~\\")) return path.join(os.homedir(), raw.slice(2));
32
+ return path.resolve(raw);
33
+ }
34
+
35
+ function fail(message, hint) {
36
+ process.stderr.write(`npie: ${message}\n`);
37
+ if (hint) process.stderr.write(`\n${hint}\n`);
38
+ process.exit(1);
39
+ }
40
+
41
+ function which(command) {
42
+ const probe = spawnSync(command, ["--version"], { stdio: "ignore" });
43
+ return probe.status === 0;
44
+ }
45
+
46
+ function run(command, args, options = {}) {
47
+ const result = spawnSync(command, args, { stdio: "inherit", ...options });
48
+ if (result.error) fail(`could not run ${command}`, String(result.error.message));
49
+ if (result.status !== 0) {
50
+ fail(`${command} ${args.join(" ")} exited with ${result.status || result.signal}`);
51
+ }
52
+ }
53
+
54
+ async function downloadTarball(target) {
55
+ let response;
56
+ for (let attempt = 1; attempt <= 3; attempt += 1) {
57
+ response = await fetch(TARBALL, { redirect: "follow" });
58
+ if (response.ok || (response.status < 500 && response.status !== 429)) break;
59
+ await response.body?.cancel();
60
+ await new Promise((resolve) => setTimeout(resolve, 500 * 2 ** attempt));
61
+ }
62
+ if (!response?.ok) {
63
+ fail(
64
+ `could not download Npie v${version} (HTTP ${response?.status ?? "?"})`,
65
+ `Check that the tag exists: https://github.com/${REPOSITORY}/releases`,
66
+ );
67
+ }
68
+ fs.writeFileSync(target, Buffer.from(await response.arrayBuffer()));
69
+ }
70
+
71
+ /** One checkout per version, marked complete only after dependencies and the build land. */
72
+ async function bootstrap(sourceDir) {
73
+ const complete = path.join(sourceDir, ".npie-complete");
74
+ if (fs.existsSync(complete) && fs.readFileSync(complete, "utf8").trim() === version) return;
75
+
76
+ 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) {
79
+ fail(
80
+ `Npie needs Node.js ${REQUIRED_NODE_MAJOR} or newer; this is ${process.versions.node}.`,
81
+ "Install it from https://nodejs.org, then run this command again.",
82
+ );
83
+ }
84
+ if (!which("pnpm")) {
85
+ fail(
86
+ "pnpm is required but was not found on PATH.",
87
+ "Enable it with `corepack enable pnpm` (bundled with Node.js), then run this command again.",
88
+ );
89
+ }
90
+
91
+ const staging = fs.mkdtempSync(`${sourceDir}.staging-`);
92
+ process.stderr.write(`npie: fetching Npie v${version}…\n`);
93
+ const tarball = path.join(staging, "source.tar.gz");
94
+ await downloadTarball(tarball);
95
+
96
+ process.stderr.write("npie: unpacking…\n");
97
+ run("tar", ["-xzf", tarball, "-C", staging, "--strip-components=1"]);
98
+ fs.rmSync(tarball);
99
+
100
+ process.stderr.write("npie: installing dependencies (this takes a few minutes)…\n");
101
+ run("pnpm", ["install", "--frozen-lockfile"], { cwd: staging });
102
+
103
+ process.stderr.write("npie: building the server…\n");
104
+ // The server package's bundling script is `build:bundle`; there is no plain `build`.
105
+ run("pnpm", ["--filter", "t3", "run", "build:bundle"], { cwd: staging });
106
+
107
+ fs.writeFileSync(path.join(staging, ".npie-complete"), `${version}\n`);
108
+ fs.rmSync(sourceDir, { recursive: true, force: true });
109
+ fs.mkdirSync(path.dirname(sourceDir), { recursive: true });
110
+ fs.renameSync(staging, sourceDir);
111
+ }
112
+
113
+ async function main() {
114
+ const sourceDir = path.join(npiHome(), "source", version);
115
+ await bootstrap(sourceDir);
116
+
117
+ const entry = path.join(sourceDir, "apps", "server", "dist", "bin.mjs");
118
+ if (!fs.existsSync(entry)) {
119
+ fail(
120
+ `the build finished but ${entry} is missing.`,
121
+ `Delete ${sourceDir} and run this command again.`,
122
+ );
123
+ }
124
+
125
+ const child = spawn(process.execPath, [entry, ...process.argv.slice(2)], {
126
+ stdio: "inherit",
127
+ env: { ...process.env, NPIE_NPM_LAUNCHER_PATH: fileURLToPath(import.meta.url) },
128
+ });
129
+ child.on("exit", (code, signal) => {
130
+ process.exit(code ?? (signal ? 1 : 0));
131
+ });
132
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
133
+ process.on(signal, () => child.kill(signal));
134
+ }
135
+ }
136
+
137
+ main().catch((error) => {
138
+ fail(error?.message ?? String(error));
139
+ });
package/dist/bin.mjs ADDED
@@ -0,0 +1,2 @@
1
+ // Legacy background services still enter the npm package through this path.
2
+ import "../bin/t3.mjs";
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@npie/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-npie.1",
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
+ "t3": "bin/t3.mjs"
20
+ },
21
+ "files": [
22
+ "bin",
23
+ "dist"
24
+ ],
25
+ "engines": {
26
+ "node": ">=20.11"
27
+ },
28
+ "t3code": {
29
+ "databaseMigration": 119
30
+ }
31
+ }