refactor(storage): 采用 OpenCode 风格三层存储结构

重构消息存储系统,从"每条消息一个文件"改为分层存储:
- Session → Message → Parts 三层结构
- 12 种 Part 类型(TextPart, ToolPart, ReasoningPart 等)
- ToolPart 状态机(pending → running → completed/error)
- 通用 Storage API(read/write/list/remove)

新增文件:
- parts.ts: Part 类型定义(Zod schema)
- message.ts: MessageInfo 类型定义
- id.ts: ID 生成器
- storage/: 分层存储实现

删除旧文件:
- storage.ts, types.ts, migration.ts

存储路径:
~/.local/share/ai-assist/
├── session/{projectId}/{sessionId}.json
├── message/{sessionId}/{messageId}.json
├── part/{messageId}/{partId}.json
└── todo/{sessionId}.json
This commit is contained in:
2025-12-15 11:16:10 +08:00
parent b8fcb65f73
commit 527692ec03
19 changed files with 1867 additions and 943 deletions
+23 -2
View File
@@ -14,9 +14,30 @@ export type {
CompressionConfig,
DetailedCompressionResult,
} from './context/index.js';
export { SessionStorage } from './session/storage.js';
// Session - 新的三层存储结构
export { SessionManager } from './session/index.js';
export type { SessionData, SessionSummary } from './session/types.js';
export type { SessionData, SessionSummary, ProjectMetadata } from './session/index.js';
// Session Storage API
export {
SessionStorage,
MessageStorage,
PartStorage,
TodoStorage,
initStorage,
getStorageDir,
StorageNotFoundError,
} from './session/index.js';
export type {
SessionInfo,
MessageInfo,
Part,
PartType,
ToolStatus,
TodoItem,
TodoList,
} from './session/index.js';
// Types
export type { UserInput, ChatResult } from './types/index.js';