@a-tether/pi 0.1.2 → 0.2.0

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.
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  // Starts the user's own Pi with the A-tether extension. Never installs Pi.
3
- import { spawn } from "node:child_process";
3
+ import { spawn, spawnSync } from "node:child_process";
4
4
  import { accessSync, constants, statSync } from "node:fs";
5
5
  import { delimiter, join } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { displayPath, loadSettings, saveToken } from "../../shared/settings.js";
8
+ import { isVersionFlag, version } from "../../shared/version.js";
8
9
  const extension = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./extension.ts" : "./extension.js", import.meta.url));
9
10
  const subcommands = new Set(["install", "remove", "uninstall", "update", "list", "config", "auth", "mcp"]);
10
11
  const windows = process.platform === "win32";
@@ -50,8 +51,27 @@ export function login(args) {
50
51
  "在 Pi 中运行 /a-tether-status 检查连接。",
51
52
  ].join("\n");
52
53
  }
54
+ // The launcher's version, then the version of the Pi it would start.
55
+ export function versions(pi) {
56
+ const lines = ["a-tether-pi " + version];
57
+ if (!pi)
58
+ return [...lines, "pi 未找到"];
59
+ const shell = windows && /\.cmd$/i.test(pi);
60
+ const result = spawnSync(shell ? `"${pi}"` : pi, ["--version"], { encoding: "utf8", shell });
61
+ const output = result.status === 0 ? result.stdout.trim() : "";
62
+ return [...lines, output ? "pi " + output : "pi 版本未知(pi --version 运行失败)"];
63
+ }
53
64
  function main() {
54
65
  const argv = process.argv.slice(2);
66
+ if (isVersionFlag(argv)) {
67
+ let pi;
68
+ try {
69
+ pi = findPi();
70
+ }
71
+ catch { } // a broken settings.json must not hide the version
72
+ console.log(versions(pi).join("\n"));
73
+ return;
74
+ }
55
75
  if (argv[0] === "login") {
56
76
  try {
57
77
  console.log(login(argv.slice(1)));
@@ -10,7 +10,8 @@ export const messages = {
10
10
  quota: "Claude 额度、速率或计费限制,请在 C 上检查账户。",
11
11
  backend: "C 上的 Claude Code 调用失败,具体原因见 C 端服务控制台。",
12
12
  overloaded: "模型服务繁忙或暂时不可用,请稍后重试。",
13
- context: "请求超出模型的上下文长度,请在 Pi 中压缩上下文或减少输入。",
13
+ // Pi recognizes an overflow by English provider phrases and then compacts and retries.
14
+ context: "请求超出模型的上下文长度(prompt is too long)。Pi 开启自动压缩时会压缩后重试,否则请运行 /compact 或减少输入。",
14
15
  discovery: "C 无法获取 Claude 模型目录,请检查 CLI 版本和连接。",
15
16
  cancelled: "请求已取消。",
16
17
  timeout: "C 上的请求超时。",
@@ -68,6 +68,9 @@ export function loadSettings(file = settingsPath()) {
68
68
  const allowUsageCredits = server.allowUsageCredits ?? false;
69
69
  if (typeof allowUsageCredits !== "boolean")
70
70
  fail("server.allowUsageCredits", "必须是 true 或 false");
71
+ const maxSessions = server.maxSessions ?? 16;
72
+ if (typeof maxSessions !== "number" || !Number.isInteger(maxSessions) || maxSessions < 0 || maxSessions > 256)
73
+ fail("server.maxSessions", "必须是 0–256 的整数");
71
74
  // Without client.url, Pi on the same machine follows server.port.
72
75
  const url = text(client, "client.url") ?? "http://127.0.0.1:" + port;
73
76
  let origin = "";
@@ -83,7 +86,8 @@ export function loadSettings(file = settingsPath()) {
83
86
  return {
84
87
  token: raw.token,
85
88
  server: { host: text(server, "server.host") ?? "127.0.0.1", port: port,
86
- claude: text(server, "server.claude") ?? "claude", allowUsageCredits: allowUsageCredits },
89
+ claude: text(server, "server.claude") ?? "claude", allowUsageCredits: allowUsageCredits,
90
+ maxSessions: maxSessions },
87
91
  client: { url: origin, pi: text(client, "client.pi") },
88
92
  };
89
93
  }
@@ -0,0 +1,5 @@
1
+ import { readFileSync } from "node:fs";
2
+ // The repository keeps package.json one level above src/, and each published package
3
+ // one level above dist/, so the same relative path works in both.
4
+ export const version = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
5
+ export const isVersionFlag = (args) => args.length === 1 && (args[0] === "--version" || args[0] === "-v");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-tether/pi",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Pi extension and launcher that uses a remote Claude Code through an A-tether SSH tunnel.",
5
5
  "type": "module",
6
6
  "license": "MIT",