Streamline directory layout and consolidate state and cache paths
This commit is contained in:
1 parent
9cf3e8ce56
commit
d3642b93d8
13 files changed
+94
-29
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { homedir } from "node:os";
|
||||
import { SEAL_CONFIG_DIR } from "../paths.js";
|
||||
import {
|
||||
CorpTokenCache,
|
||||
HoseAuthCache,
|
||||
@@ -9,14 +9,14 @@ import {
|
||||
TokenStoreSchema
|
||||
} from "./types.js";
|
||||
|
||||
const PRIMARY_TOKEN_STORE = join(homedir(), ".config", "seal-use", "sealTokens.json");
|
||||
const LEGACY_TOKEN_STORE = join(homedir(), ".config", "seal-home", "sealTokens.json");
|
||||
const PRIMARY_TOKEN_STORE = join(SEAL_CONFIG_DIR, "tokens.json");
|
||||
const MIGRATION_TOKEN_STORE = join(SEAL_CONFIG_DIR, "sealTokens.json");
|
||||
|
||||
function resolveReadStorePath(): string {
|
||||
const configured = (process.env.SEAL_USE_TOKEN_STORE ?? process.env.SEAL_HOME_TOKEN_STORE)?.trim();
|
||||
if (configured) return configured;
|
||||
if (existsSync(PRIMARY_TOKEN_STORE)) return PRIMARY_TOKEN_STORE;
|
||||
if (existsSync(LEGACY_TOKEN_STORE)) return LEGACY_TOKEN_STORE;
|
||||
if (existsSync(MIGRATION_TOKEN_STORE)) return MIGRATION_TOKEN_STORE;
|
||||
return PRIMARY_TOKEN_STORE;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,10 +112,15 @@ function findGroupOrWorldReadable(paths: string[]): string[] {
|
||||
export function diagnoseSystem(): DoctorDiagnosis {
|
||||
const home = homedir();
|
||||
const configDir = join(home, ".config", "seal-use");
|
||||
const stateDir = join(configDir, "state");
|
||||
const enterprisesDir = join(configDir, "enterprises");
|
||||
const globalConfigFile = join(configDir, "config.json");
|
||||
const tokenStore = join(configDir, "sealTokens.json");
|
||||
const mappingsDir = join(configDir, "mappings");
|
||||
const tokenStore = existsSync(join(configDir, "tokens.json"))
|
||||
? join(configDir, "tokens.json")
|
||||
: existsSync(join(configDir, "sealTokens.json"))
|
||||
? join(configDir, "sealTokens.json")
|
||||
: join(configDir, "tokens.json");
|
||||
const mappingsDir = existsSync(join(stateDir, "mappings")) ? join(stateDir, "mappings") : join(configDir, "mappings");
|
||||
const agentSkillDir = getDefaultGlobalSkillDir();
|
||||
const exportDir = join(home, "Downloads");
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
export interface DirectorySpec {
|
||||
name: string;
|
||||
category: "config" | "binary" | "skill" | "export" | "temp";
|
||||
category: "config" | "binary" | "skill" | "export" | "temp" | "cache";
|
||||
standardPath: string;
|
||||
purpose: string;
|
||||
accessMode: "read-write" | "executable" | "transient";
|
||||
@@ -55,19 +55,27 @@ export const EMBEDDED_DIRECTORY_SPECS: DirectorySpec[] = [
|
||||
{
|
||||
name: "会话凭据安全缓存",
|
||||
category: "config",
|
||||
standardPath: "~/.config/seal-use/sealTokens.json",
|
||||
standardPath: "~/.config/seal-use/tokens.json",
|
||||
purpose: "缓存已认证租户的 Bearer Token 与过期时间戳,避免高频调用上游 OAuth 换票接口。",
|
||||
accessMode: "read-write",
|
||||
retention: "cache"
|
||||
},
|
||||
{
|
||||
name: "规则版本映射快照",
|
||||
name: "业务持久状态目录",
|
||||
category: "config",
|
||||
standardPath: "~/.config/seal-use/mappings",
|
||||
purpose: "存储 corps sync-test 生成的生产与测试规则版本/编号对照映射快照,供 rules map 离线毫秒级速查。",
|
||||
standardPath: "~/.config/seal-use/state",
|
||||
purpose: "业务持久状态统一子目录,存放规则映射对照(mappings)、发布快照(snapshots)与人工复核账本(reviews)。",
|
||||
accessMode: "read-write",
|
||||
retention: "persistent"
|
||||
},
|
||||
{
|
||||
name: "运行时缓存根目录",
|
||||
category: "cache",
|
||||
standardPath: "~/.cache/seal-use",
|
||||
purpose: "用户本地运行时缓存目录,存放版本检测缓存、打点度量、官方只读校验器及报告离线资源,可随时安全清理。",
|
||||
accessMode: "read-write",
|
||||
retention: "cache"
|
||||
},
|
||||
{
|
||||
name: "全局命令行程序",
|
||||
category: "binary",
|
||||
|
||||
+9
-2
@@ -2,5 +2,12 @@ import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
export const SEAL_CONFIG_DIR = join(homedir(), ".config", "seal-use");
|
||||
export const PRIMARY_LINTERS_DIR = join(SEAL_CONFIG_DIR, "linters");
|
||||
export const OFFICIAL_LINTERS_DIR = join(PRIMARY_LINTERS_DIR, "official");
|
||||
export const SEAL_STATE_DIR = join(SEAL_CONFIG_DIR, "state");
|
||||
export const SEAL_CACHE_DIR = join(homedir(), ".cache", "seal-use");
|
||||
|
||||
/** 用户全局自定义校验器存放目录(属于用户资产,保留在 ~/.config/,防止随缓存被误删) */
|
||||
export const USER_LINTERS_DIR = join(SEAL_CONFIG_DIR, "linters");
|
||||
export const PRIMARY_LINTERS_DIR = USER_LINTERS_DIR;
|
||||
|
||||
/** 官方明文下发校验器目录(由 CLI 自动同步与重写,属于只读缓存,归位于 ~/.cache/) */
|
||||
export const OFFICIAL_LINTERS_DIR = join(SEAL_CACHE_DIR, "linters", "official");
|
||||
@@ -1,9 +1,10 @@
|
||||
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { SEAL_CACHE_DIR } from "../paths.js";
|
||||
|
||||
export const USAGE_FILE_ENV = "SEAL_USE_USAGE_FILE";
|
||||
const DEFAULT_USAGE_FILE = join(homedir(), ".config", "seal-use", "usage.json");
|
||||
const DEFAULT_USAGE_FILE = join(SEAL_CACHE_DIR, "usage.json");
|
||||
const DEFAULT_WINDOW_DAYS = 7;
|
||||
|
||||
export type CorpUsageDailyStats = Record<string, number>;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
import type { LauncherConfig } from "./runtime.js";
|
||||
import { formatBeijingIso, normalizeBeijingIso } from "./config/timestamps.js";
|
||||
|
||||
import { SEAL_CACHE_DIR } from "./paths.js";
|
||||
|
||||
export const UPDATE_CACHE_FILE_ENV = "SEAL_USE_UPDATE_CACHE_FILE";
|
||||
export const DEFAULT_UPDATE_CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||
|
||||
const DEFAULT_UPDATE_CACHE_FILE = join(homedir(), ".config", "seal-use", "update-cache.json");
|
||||
const DEFAULT_UPDATE_CACHE_FILE = join(SEAL_CACHE_DIR, "update-cache.json");
|
||||
|
||||
export interface UpdateCacheData {
|
||||
checkedAt: string;
|
||||
|
||||
Reference in new issue
Block a user