refactor(core): 统一存储路径到 ~/.ai-terminal-assistant/
- 新增 constants/paths.ts 模块统一管理存储路径 - Session 数据从 ~/.local/share/ai-assist/ 迁移到 ~/.ai-terminal-assistant/data/ - Checkpoint 从 ~/.ai-assist/checkpoints/ 迁移到 ~/.ai-terminal-assistant/checkpoints/ - MCP 配置从 ~/.ai-assist/config.* 迁移到 ~/.ai-terminal-assistant/mcp.* - Agent 配置保持在 ~/.ai-terminal-assistant/agents.json
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
|
||||||
import type { AgentConfigFile } from './types.js';
|
import type { AgentConfigFile } from './types.js';
|
||||||
|
import { getConfigDir } from '../constants/paths.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局配置目录
|
* 全局配置目录
|
||||||
*/
|
*/
|
||||||
const GLOBAL_CONFIG_DIR = path.join(os.homedir(), '.ai-terminal-assistant');
|
const GLOBAL_CONFIG_DIR = getConfigDir();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载用户自定义 Agent 配置
|
* 加载用户自定义 Agent 配置
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
import { getCheckpointsDir } from '../constants/paths.js';
|
||||||
import { ShadowGit, createShadowGit } from './shadow-git.js';
|
import { ShadowGit, createShadowGit } from './shadow-git.js';
|
||||||
import { CheckpointLock } from './lock.js';
|
import { CheckpointLock } from './lock.js';
|
||||||
import { CheckpointSafetyChecker } from './safety.js';
|
import { CheckpointSafetyChecker } from './safety.js';
|
||||||
@@ -75,7 +75,7 @@ export class CheckpointManager {
|
|||||||
},
|
},
|
||||||
maxCheckpoints: 100,
|
maxCheckpoints: 100,
|
||||||
maxAge: 7 * 24 * 60 * 60 * 1000,
|
maxAge: 7 * 24 * 60 * 60 * 1000,
|
||||||
storageDir: path.join(os.homedir(), '.ai-assist', 'checkpoints'),
|
storageDir: getCheckpointsDir(),
|
||||||
...config,
|
...config,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './paths.js';
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
* 统一存储路径常量
|
||||||
|
* 所有数据统一存储在 ~/.ai-terminal-assistant/ 目录下
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as os from 'os';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用根目录名称
|
||||||
|
*/
|
||||||
|
export const APP_DIR_NAME = '.ai-terminal-assistant';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取应用根目录
|
||||||
|
* ~/.ai-terminal-assistant/
|
||||||
|
*/
|
||||||
|
export function getAppDir(): string {
|
||||||
|
return path.join(os.homedir(), APP_DIR_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置目录(与应用根目录相同)
|
||||||
|
* ~/.ai-terminal-assistant/
|
||||||
|
*/
|
||||||
|
export function getConfigDir(): string {
|
||||||
|
return getAppDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据存储目录
|
||||||
|
* ~/.ai-terminal-assistant/data/
|
||||||
|
*/
|
||||||
|
export function getDataDir(): string {
|
||||||
|
return path.join(getAppDir(), 'data');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 Checkpoint 存储目录
|
||||||
|
* ~/.ai-terminal-assistant/checkpoints/
|
||||||
|
*/
|
||||||
|
export function getCheckpointsDir(): string {
|
||||||
|
return path.join(getAppDir(), 'checkpoints');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存目录
|
||||||
|
* ~/.ai-terminal-assistant/cache/
|
||||||
|
*/
|
||||||
|
export function getCacheDir(): string {
|
||||||
|
return path.join(getAppDir(), 'cache');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日志目录
|
||||||
|
* ~/.ai-terminal-assistant/logs/
|
||||||
|
*/
|
||||||
|
export function getLogsDir(): string {
|
||||||
|
return path.join(getAppDir(), 'logs');
|
||||||
|
}
|
||||||
@@ -248,3 +248,14 @@ export type {
|
|||||||
FileIndexEntry,
|
FileIndexEntry,
|
||||||
FileSearchOptions,
|
FileSearchOptions,
|
||||||
} from './file-index/index.js';
|
} from './file-index/index.js';
|
||||||
|
|
||||||
|
// Constants - 统一存储路径
|
||||||
|
export {
|
||||||
|
APP_DIR_NAME,
|
||||||
|
getAppDir,
|
||||||
|
getConfigDir,
|
||||||
|
getDataDir,
|
||||||
|
getCheckpointsDir,
|
||||||
|
getCacheDir,
|
||||||
|
getLogsDir,
|
||||||
|
} from './constants/index.js';
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type {
|
|||||||
LocalMCPServer,
|
LocalMCPServer,
|
||||||
RemoteMCPServer,
|
RemoteMCPServer,
|
||||||
} from './types.js';
|
} from './types.js';
|
||||||
|
import { getConfigDir } from '../constants/paths.js';
|
||||||
|
|
||||||
/** 默认配置值 */
|
/** 默认配置值 */
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
@@ -239,20 +240,20 @@ function mergeConfigs(base: MCPConfig, override: MCPConfig): MCPConfig {
|
|||||||
/**
|
/**
|
||||||
* 加载 MCP 配置
|
* 加载 MCP 配置
|
||||||
* 按优先级从低到高加载:
|
* 按优先级从低到高加载:
|
||||||
* 1. 用户级: ~/.ai-assist/config.{json,yaml}
|
* 1. 用户级: ~/.ai-terminal-assistant/mcp.{json,yaml}
|
||||||
* 2. 项目级: .ai-assist/config.{json,yaml}
|
* 2. 项目级: .ai-assist/config.{json,yaml}
|
||||||
*/
|
*/
|
||||||
export function loadMCPConfig(workdir?: string): MCPConfig {
|
export function loadMCPConfig(workdir?: string): MCPConfig {
|
||||||
const cwd = workdir || process.cwd();
|
const cwd = workdir || process.cwd();
|
||||||
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
const configDir = getConfigDir();
|
||||||
|
|
||||||
// 配置文件搜索路径
|
// 配置文件搜索路径
|
||||||
const searchPaths = [
|
const searchPaths = [
|
||||||
// 用户级配置
|
// 用户级配置(统一到 ~/.ai-terminal-assistant/)
|
||||||
path.join(homeDir, '.ai-assist', 'config.json'),
|
path.join(configDir, 'mcp.json'),
|
||||||
path.join(homeDir, '.ai-assist', 'config.jsonc'),
|
path.join(configDir, 'mcp.jsonc'),
|
||||||
path.join(homeDir, '.ai-assist', 'config.yaml'),
|
path.join(configDir, 'mcp.yaml'),
|
||||||
path.join(homeDir, '.ai-assist', 'config.yml'),
|
path.join(configDir, 'mcp.yml'),
|
||||||
// 项目级配置
|
// 项目级配置
|
||||||
path.join(cwd, '.ai-assist', 'config.json'),
|
path.join(cwd, '.ai-assist', 'config.json'),
|
||||||
path.join(cwd, '.ai-assist', 'config.jsonc'),
|
path.join(cwd, '.ai-assist', 'config.jsonc'),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as fs from 'fs/promises';
|
import * as fs from 'fs/promises';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
|
||||||
import { Lock } from '../../utils/lock.js';
|
import { Lock } from '../../utils/lock.js';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { getDataDir } from '../../constants/paths.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储错误类型
|
* 存储错误类型
|
||||||
@@ -19,14 +19,10 @@ export class StorageNotFoundError extends Error {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取默认存储目录
|
* 获取默认存储目录
|
||||||
* 遵循 XDG 规范:~/.local/share/ai-assist/
|
* 统一存储在 ~/.ai-terminal-assistant/data/
|
||||||
*/
|
*/
|
||||||
export function getDefaultStorageDir(): string {
|
export function getDefaultStorageDir(): string {
|
||||||
const xdgDataHome = process.env.XDG_DATA_HOME;
|
return getDataDir();
|
||||||
if (xdgDataHome) {
|
|
||||||
return path.join(xdgDataHome, 'ai-assist');
|
|
||||||
}
|
|
||||||
return path.join(os.homedir(), '.local', 'share', 'ai-assist');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user