@shubao-ai/shubao-cli 0.1.1 → 0.1.2

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,3 +1,3 @@
1
- export async function bootstrapDevice(client, key) { return client.request("/api/v1/runtime/devices/bootstrap", key, { method: "POST", body: JSON.stringify({ device_name: `${process.platform} shubao-cli`, platform: process.platform, arch: process.arch, client_name: "shubao-cli", client_version: "0.1.1" }) }); }
1
+ export async function bootstrapDevice(client, key) { return client.request("/api/v1/runtime/devices/bootstrap", key, { method: "POST", body: JSON.stringify({ device_name: `${process.platform} shubao-cli`, platform: process.platform, arch: process.arch, client_name: "shubao-cli", client_version: "0.1.2" }) }); }
2
2
  export async function revokeBootstrapDevice(client, key, deviceID) { await client.request(`/api/v1/runtime/devices/bootstrap/${encodeURIComponent(deviceID)}`, key, { method: "DELETE" }); }
3
3
  export async function exchangeRuntimeToken(client, refresh) { return client.request("/api/v1/runtime/access-tokens", undefined, { method: "POST", headers: { Authorization: `Device ${refresh}` } }); }
package/dist/src/app.js CHANGED
@@ -39,7 +39,7 @@ const help = `数宝小助手
39
39
  npx @shubao-ai/shubao-cli 一次性执行(推荐)
40
40
  npm install -g @shubao-ai/shubao-cli 全局安装后直接用 shubao`;
41
41
  export async function run(argv) {
42
- const version = "0.1.1";
42
+ const version = "0.1.2";
43
43
  let args = [...argv];
44
44
  let serverOverride;
45
45
  const pos = args.indexOf("--server");
@@ -3,10 +3,18 @@ import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { normalizeServerURL } from "./server-url.js";
5
5
  export const DEFAULT_SERVER = "https://shubao.wuhuangwansui.cn";
6
+ // 各平台配置目录约定:
7
+ // macOS / Linux:~/.config/shubao-cli (XDG Base Directory 规范)
8
+ // Windows: %APPDATA%\shubao-cli (即 C:\Users\<你>\AppData\Roaming\shubao-cli)
9
+ function defaultConfigDir(home, platform = process.platform) {
10
+ if (platform === "win32")
11
+ return join(process.env.APPDATA ?? join(home, "AppData", "Roaming"), "shubao-cli");
12
+ return join(home, ".config", "shubao-cli");
13
+ }
6
14
  export class ConfigStore {
7
15
  dir;
8
16
  file;
9
- constructor(home = homedir()) { this.dir = join(home, ".config", "shubao-cli"); this.file = join(this.dir, "config.json"); }
17
+ constructor(home = homedir(), platform = process.platform) { this.dir = defaultConfigDir(home, platform); this.file = join(this.dir, "config.json"); }
10
18
  async load() {
11
19
  try {
12
20
  const parsed = JSON.parse(await readFile(this.file, "utf8"));
@@ -3,6 +3,8 @@ import { homedir } from "node:os";
3
3
  import { basename, dirname, join } from "node:path";
4
4
  import { parseHelperKey } from "../auth/key-format.js";
5
5
  import { normalizeServerURL } from "../config/server-url.js";
6
+ // 受管理块标记。在所有平台上都是用 # 起头的注释行(PowerShell 与 POSIX shell 都支持),
7
+ // 因此 MANAGED 正则跨平台通用。
6
8
  const START = "# >>> shubao helper >>>";
7
9
  const END = "# <<< shubao helper <<<";
8
10
  const MANAGED = new RegExp(`${escapeRegExp(START)}[\\s\\S]*?${escapeRegExp(END)}\\n?`, "g");
@@ -28,17 +30,17 @@ export class ShellProfileStore {
28
30
  if (this.profilePath)
29
31
  return this.profilePath;
30
32
  if (this.platform === "win32")
31
- throw new EnvStorageError("ENV_STORAGE_NOT_IMPLEMENTED_ON_PLATFORM", "Windows 环境变量存储暂未实现");
33
+ return join(this.home, "Documents", "PowerShell", "profile.ps1");
32
34
  const name = basename(this.shell);
33
35
  if (name === "zsh")
34
36
  return join(this.home, ".zshrc");
35
37
  if (name === "bash")
36
38
  return join(this.home, ".bashrc");
37
- throw new EnvStorageError("ENV_STORAGE_SHELL_NOT_SUPPORTED", "仅支持 zsh 或 bash 的环境变量存储");
39
+ throw new EnvStorageError("ENV_STORAGE_SHELL_NOT_SUPPORTED", "仅支持 zsh、bashWindows PowerShell 的环境变量存储");
38
40
  }
39
41
  reloadCommand() {
40
42
  const path = this.path();
41
- return `source ${shellQuote(path)}`;
43
+ return this.platform === "win32" ? `. ${powershellQuote(path)}` : `source ${shellQuote(path)}`;
42
44
  }
43
45
  async write(apiKey, server) {
44
46
  if (!parseHelperKey(apiKey) || /[\r\n]/.test(apiKey))
@@ -59,7 +61,11 @@ export class ShellProfileStore {
59
61
  throw error;
60
62
  }
61
63
  const withoutManaged = existing.replace(MANAGED, "").replace(/\n{3,}/g, "\n\n").replace(/\s*$/, "");
62
- const block = `${START}\nexport SHUBAO_API_KEY="${apiKey}"\nexport SHUBAO_API_BASE_URL="${normalizedServer}"\n${END}\n`;
64
+ // PowerShell $env:VAR 写环境变量;POSIX shell 用 export VAR=
65
+ const lines = this.platform === "win32"
66
+ ? `$env:SHUBAO_API_KEY = "${apiKey}"\n$env:SHUBAO_API_BASE_URL = "${normalizedServer}"`
67
+ : `export SHUBAO_API_KEY="${apiKey}"\nexport SHUBAO_API_BASE_URL="${normalizedServer}"`;
68
+ const block = `${START}\n${lines}\n${END}\n`;
63
69
  await atomicWrite(path, `${withoutManaged}${withoutManaged ? "\n\n" : ""}${block}`, Math.min(mode, 0o600));
64
70
  return path;
65
71
  }
@@ -73,7 +79,7 @@ export class ShellProfileStore {
73
79
  existing = await readFile(path, "utf8");
74
80
  }
75
81
  catch (error) {
76
- if (error.code === "ENOENT")
82
+ if (error.code !== "ENOENT")
77
83
  return;
78
84
  throw error;
79
85
  }
@@ -94,3 +100,5 @@ async function atomicWrite(path, content, mode) {
94
100
  }
95
101
  function escapeRegExp(value) { return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); }
96
102
  function shellQuote(value) { return `'${value.replace(/'/g, "'\\''")}'`; }
103
+ // PowerShell 单引号字符串:把内部单引号写成两个单引号即可。
104
+ function powershellQuote(value) { return `'${value.replace(/'/g, "''")}'`; }
@@ -35,7 +35,7 @@ export function banner() {
35
35
  ...logo,
36
36
  "",
37
37
  center("SHUBAO HELPER"),
38
- center("数宝小助手 · v0.1.1"),
38
+ center("数宝小助手 · v0.1.2"),
39
39
  "",
40
40
  ]),
41
41
  "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shubao-ai/shubao-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "数宝小助手",
5
5
  "type": "module",
6
6
  "bin": {