diff --git a/src/core/README.core.md b/src/core/README.core.md index 9bb8954..f0d9dc2 100644 --- a/src/core/README.core.md +++ b/src/core/README.core.md @@ -8,9 +8,9 @@ Core 层负责基础设施:企业配置管理、认证 Token 获取与缓存 src/core/ ├── auth/ # 登录认证协议与凭证存储(纯凭据层) │ ├── login.ts # 登录四矩阵(RSA账密登录、短信验证码、F12/cURL凭证导入、浏览器同步) -│ ├── account-store.ts # 多账号持久化存储 (~/.cache/ekb-mcp/accounts.json) +│ ├── account-store.ts # 多账号持久化存储 (~/.config/hose-use/accounts.json) │ ├── tools.ts # MCP Auth Tools 注册与调度 -│ ├── token-store.ts # 动态 Token 缓存(兼容 ~/.config/hose-use/tokens.json 与历史路径) +│ ├── token-store.ts # 动态 Token 缓存 (~/.config/hose-use/tokens.json) │ └── types.ts ├── http/ # 统一 HTTP 客户端装配与网络传输(语义化客户端) │ ├── factory.ts # Ky 底层客户端工厂(超时、重试、错误钩子) diff --git a/src/core/auth/account-store.ts b/src/core/auth/account-store.ts index da1d440..1421f78 100644 --- a/src/core/auth/account-store.ts +++ b/src/core/auth/account-store.ts @@ -1,12 +1,12 @@ -import { readFileSync, writeFileSync, mkdirSync } from "fs"; +import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"; import { join, dirname } from "path"; import { homedir } from "os"; import { z } from "zod"; -const ACCOUNT_CACHE_PATH = join( +export const ACCOUNT_CACHE_PATH = join( homedir(), - ".cache", - "ekb-mcp", + ".config", + "hose-use", "accounts.json" ); @@ -38,7 +38,13 @@ export type AccountEntry = z.infer; export type AccountStore = z.infer; function ensureDir(path: string): void { - mkdirSync(dirname(path), { recursive: true }); + const dir = dirname(path); + if (!existsSync(dir)) { + mkdirSync(dir, { recursive: true, mode: 0o700 }); + } + try { + chmodSync(dir, 0o700); + } catch {} } export function loadAccountStore(): AccountStore { diff --git a/src/core/auth/token-store.ts b/src/core/auth/token-store.ts index 06b044c..186d315 100644 --- a/src/core/auth/token-store.ts +++ b/src/core/auth/token-store.ts @@ -10,20 +10,9 @@ export const PRIMARY_TOKEN_CACHE_PATH = join( "tokens.json" ); -export const LEGACY_TOKEN_CACHE_PATH = join( - homedir(), - ".cache", - "ekb-mcp", - "tokens.json" -); +export const TOKEN_CACHE_PATH = PRIMARY_TOKEN_CACHE_PATH; function resolveTokenCachePath(): string { - if (existsSync(PRIMARY_TOKEN_CACHE_PATH)) { - return PRIMARY_TOKEN_CACHE_PATH; - } - if (existsSync(LEGACY_TOKEN_CACHE_PATH)) { - return LEGACY_TOKEN_CACHE_PATH; - } return PRIMARY_TOKEN_CACHE_PATH; }