@tokenbuddy/tokenbuddy 1.0.37 → 1.0.38

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.
@@ -251,7 +251,7 @@ export interface BuyerStoreOptions {
251
251
  }
252
252
  /**
253
253
  * 解析 buyer store 的 DB 路径。
254
- * 优先级:`dbPath` → `TOKENBUDDY_BUYER_STORE` env → `~/.tokenbuddy-store/buyer-store.db`。
254
+ * 优先级:`dbPath` → `TOKENBUDDY_BUYER_STORE` env → `TB_WORKDIR` env → `~/.config/tokenbuddy/buyer-store.db`。
255
255
  *
256
256
  * @param options 解析选项
257
257
  * @returns DB 文件绝对路径
@@ -2,9 +2,9 @@
2
2
  import { DatabaseSync } from "node:sqlite";
3
3
  import * as crypto from "crypto";
4
4
  import * as fs from "fs";
5
- import * as os from "os";
6
5
  import * as path from "path";
7
6
  import { createModuleLogger } from "@tokenbuddy/logging";
7
+ import { resolveTokenBuddyWorkdir } from "./workdir.js";
8
8
  const logger = createModuleLogger("tb-proxyd");
9
9
  function nowIso() {
10
10
  return new Date().toISOString();
@@ -26,7 +26,7 @@ function ensureDirForFile(filePath) {
26
26
  }
27
27
  /**
28
28
  * 解析 buyer store 的 DB 路径。
29
- * 优先级:`dbPath` → `TOKENBUDDY_BUYER_STORE` env → `~/.tokenbuddy-store/buyer-store.db`。
29
+ * 优先级:`dbPath` → `TOKENBUDDY_BUYER_STORE` env → `TB_WORKDIR` env → `~/.config/tokenbuddy/buyer-store.db`。
30
30
  *
31
31
  * @param options 解析选项
32
32
  * @returns DB 文件绝对路径
@@ -35,7 +35,7 @@ export function resolveBuyerStorePath(options = {}) {
35
35
  if (options.dbPath) {
36
36
  return options.dbPath;
37
37
  }
38
- const root = options.root || process.env.TOKENBUDDY_BUYER_STORE || path.join(os.homedir(), ".tokenbuddy-store");
38
+ const root = options.root || process.env.TOKENBUDDY_BUYER_STORE || resolveTokenBuddyWorkdir();
39
39
  return path.join(root, "buyer-store.db");
40
40
  }
41
41
  /**
package/dist/src/cli.d.ts CHANGED
@@ -34,6 +34,7 @@ export interface LaunchdPlistOptions {
34
34
  proxyPort: number;
35
35
  sellerRegistryUrl: string;
36
36
  pathEnv?: string;
37
+ workdir?: string;
37
38
  clawtipProofCommand?: string;
38
39
  clawtipProofTimeoutMs?: number;
39
40
  }
package/dist/src/cli.js CHANGED
@@ -19,6 +19,7 @@ import { DEFAULT_CLAWTIP_BOOTSTRAP_URL, fetchClawtipBootstrap, } from "./clawtip
19
19
  import { displayTerminalImage } from "./terminal-image.js";
20
20
  import { checkPackageUpdate, readInstalledPackageManifest, runPackageUpdate, } from "./package-update.js";
21
21
  import { DEFAULT_SELLER_REGISTRY_URL } from "./registry-trust.js";
22
+ import { resolveTokenBuddyWorkdir, resolveTokenBuddyWorkdirPath, TB_WORKDIR_ENV } from "./workdir.js";
22
23
  // @ts-ignore
23
24
  import qrcode from "qrcode-terminal";
24
25
  const CONTROL_PORT = 17820;
@@ -119,7 +120,7 @@ function launchControlUi(controlPort, pathname = "/") {
119
120
  return url;
120
121
  }
121
122
  function defaultProxydLogPath(kind) {
122
- const logDir = path.join(os.homedir(), ".tokenbuddy-store");
123
+ const logDir = resolveTokenBuddyWorkdir();
123
124
  fs.mkdirSync(logDir, { recursive: true });
124
125
  return path.join(logDir, `tb-proxyd.${kind}.log`);
125
126
  }
@@ -164,6 +165,9 @@ export function buildLaunchdPlistContent(options) {
164
165
  if (options.clawtipProofCommand?.trim()) {
165
166
  env.TB_PROXYD_CLAWTIP_PROOF_COMMAND = options.clawtipProofCommand.trim();
166
167
  }
168
+ if (options.workdir?.trim()) {
169
+ env[TB_WORKDIR_ENV] = options.workdir.trim();
170
+ }
167
171
  if (options.clawtipProofTimeoutMs !== undefined) {
168
172
  env.TB_PROXYD_CLAWTIP_PROOF_TIMEOUT_MS = String(options.clawtipProofTimeoutMs);
169
173
  }
@@ -383,8 +387,9 @@ export async function runWebInitLauncher(deps = {}) {
383
387
  if (platform === "darwin") {
384
388
  const plistDir = path.join(home, "Library", "LaunchAgents");
385
389
  const plistPath = path.join(plistDir, `${TOKENBUDDY_LAUNCHD_LABEL}.plist`);
386
- const stdoutPath = deps.stdoutPath ?? path.join(home, ".tokenbuddy-store", "tb-proxyd.stdout.log");
387
- const stderrPath = deps.stderrPath ?? path.join(home, ".tokenbuddy-store", "tb-proxyd.stderr.log");
390
+ const workdir = resolveTokenBuddyWorkdir({ homeDir: home });
391
+ const stdoutPath = deps.stdoutPath ?? resolveTokenBuddyWorkdirPath("tb-proxyd.stdout.log", { homeDir: home });
392
+ const stderrPath = deps.stderrPath ?? resolveTokenBuddyWorkdirPath("tb-proxyd.stderr.log", { homeDir: home });
388
393
  try {
389
394
  (deps.mkdirSync ?? fs.mkdirSync)(plistDir, { recursive: true });
390
395
  (deps.mkdirSync ?? fs.mkdirSync)(path.dirname(stdoutPath), { recursive: true });
@@ -394,6 +399,7 @@ export async function runWebInitLauncher(deps = {}) {
394
399
  nodePath: deps.nodePath ?? process.execPath,
395
400
  scriptPath: deps.scriptPath ?? tbProxydScriptPath(),
396
401
  pathEnv: deps.pathEnv,
402
+ workdir,
397
403
  stdoutPath,
398
404
  stderrPath,
399
405
  controlPort,
@@ -1799,8 +1805,9 @@ export function buildCli() {
1799
1805
  const sellerRegistryUrl = sellerRegistryUrlForInit();
1800
1806
  const nodePath = process.execPath;
1801
1807
  const scriptPath = tbProxydScriptPath();
1802
- const stdoutPath = path.join(home, ".tokenbuddy-store", "tb-proxyd.stdout.log");
1803
- const stderrPath = path.join(home, ".tokenbuddy-store", "tb-proxyd.stderr.log");
1808
+ const workdir = resolveTokenBuddyWorkdir({ homeDir: home });
1809
+ const stdoutPath = resolveTokenBuddyWorkdirPath("tb-proxyd.stdout.log", { homeDir: home });
1810
+ const stderrPath = resolveTokenBuddyWorkdirPath("tb-proxyd.stderr.log", { homeDir: home });
1804
1811
  fs.mkdirSync(path.dirname(stdoutPath), { recursive: true });
1805
1812
  fs.mkdirSync(path.dirname(stderrPath), { recursive: true });
1806
1813
  const plistContent = buildLaunchdPlistContent({
@@ -1813,6 +1820,7 @@ export function buildCli() {
1813
1820
  proxyPort,
1814
1821
  sellerRegistryUrl,
1815
1822
  pathEnv: process.env.PATH,
1823
+ workdir,
1816
1824
  clawtipProofCommand: defaultClawtipProofCommand(),
1817
1825
  clawtipProofTimeoutMs: process.env.TB_PROXYD_CLAWTIP_PROOF_TIMEOUT_MS
1818
1826
  ? Number(process.env.TB_PROXYD_CLAWTIP_PROOF_TIMEOUT_MS)
@@ -0,0 +1,10 @@
1
+ export declare const TB_WORKDIR_ENV = "TB_WORKDIR";
2
+ export declare const DEFAULT_TOKENBUDDY_WORKDIR_RELATIVE: string;
3
+ export interface TokenBuddyWorkdirOptions {
4
+ env?: NodeJS.ProcessEnv;
5
+ homeDir?: string;
6
+ }
7
+ export declare function defaultTokenBuddyWorkdir(homeDir?: string): string;
8
+ export declare function resolveTokenBuddyWorkdir(options?: TokenBuddyWorkdirOptions): string;
9
+ export declare function resolveTokenBuddyWorkdirPath(relativePath: string, options?: TokenBuddyWorkdirOptions): string;
10
+ //# sourceMappingURL=workdir.d.ts.map
@@ -0,0 +1,26 @@
1
+ import * as os from "os";
2
+ import * as path from "path";
3
+ export const TB_WORKDIR_ENV = "TB_WORKDIR";
4
+ export const DEFAULT_TOKENBUDDY_WORKDIR_RELATIVE = path.join(".config", "tokenbuddy");
5
+ function expandHome(input, homeDir) {
6
+ if (input === "~") {
7
+ return homeDir;
8
+ }
9
+ if (input.startsWith("~/")) {
10
+ return path.join(homeDir, input.slice(2));
11
+ }
12
+ return input;
13
+ }
14
+ export function defaultTokenBuddyWorkdir(homeDir = os.homedir()) {
15
+ return path.join(homeDir, DEFAULT_TOKENBUDDY_WORKDIR_RELATIVE);
16
+ }
17
+ export function resolveTokenBuddyWorkdir(options = {}) {
18
+ const env = options.env || process.env;
19
+ const homeDir = options.homeDir || os.homedir();
20
+ const raw = env[TB_WORKDIR_ENV] || defaultTokenBuddyWorkdir(homeDir);
21
+ return path.resolve(expandHome(raw, homeDir));
22
+ }
23
+ export function resolveTokenBuddyWorkdirPath(relativePath, options = {}) {
24
+ return path.join(resolveTokenBuddyWorkdir(options), relativePath);
25
+ }
26
+ //# sourceMappingURL=workdir.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenbuddy/tokenbuddy",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "TokenBuddy Client CLI and Daemon",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@clack/prompts": "^0.7.0",
31
- "@tokenbuddy/contracts": "^1.0.37",
31
+ "@tokenbuddy/contracts": "^1.0.38",
32
32
  "@tokenbuddy/logging": "^1.0.0",
33
33
  "cli-table3": "^0.6.4",
34
34
  "commander": "^12.0.0",