-
Notifications
You must be signed in to change notification settings - Fork 7
pref(provider):收敛公共契约、配置装配与模型目录边界 #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1d06281
Merge remote-tracking branch 'refs/remotes/upstream/main' into provid…
phantom5099 55491d3
pref(provider):修改公共契约并增加能力模型
phantom5099 707049c
fix(provider):修复当前存在EOF被误当作正常完成问题
phantom5099 ab21ca1
Merge branch 'refs/heads/provider-phase2-A'
phantom5099 5006a85
Merge remote-tracking branch 'refs/remotes/upstream/main'
phantom5099 b134397
pref(provider):重构配置装配、远程发现缓存与共享模型类型边界
phantom5099 d37880a
fix(provider):修复切换到不存在的模型会偷偷改配置等问题
phantom5099 3319c73
fix(provider):解决冲突
phantom5099 8588495
Merge remote-tracking branch 'upstream/main'
phantom5099 1c51367
fix(provider):修 APIStyle 身份不一致
phantom5099 871a1dd
Merge remote-tracking branch 'upstream/main'
phantom5099 46bc129
fix(provider):修复测试错误
phantom5099 56d9be0
docs(session): restore persistence design notes
xgopilot ca8f094
docs(session): dedupe persistence references
xgopilot 3da60fc
fix(provider):修复强制 current_model 必须非空导致可能启动失败问题
phantom5099 cd2f541
Merge remote-tracking branch 'upstream/main'
phantom5099 b7685a7
Merge remote-tracking branch 'origin/main'
phantom5099 0beb008
Merge remote-tracking branch 'upstream/main'
phantom5099 8b3f741
pref(provider):增加同步发现模型
phantom5099 9c1ced6
fix(provider):修复测试报错
phantom5099 b8dc340
fix(provider):修复测试报错
phantom5099 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,66 @@ | ||
| # Session 持久化设计 | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
|
|
||
| ## 模块职责与收口边界 | ||
| - `internal/session`:承载会话领域模型、存储抽象与 JSON 持久化实现,是唯一的会话持久化实现归属层 | ||
| - `internal/runtime`:只依赖 `internal/session` 提供的抽象与模型,负责会话保存时机与主循环编排,不再维护会话存储实现细节 | ||
| - `internal/tui`:仅消费 runtime 暴露的会话数据,不直接执行会话持久化 | ||
| ## 模块职责与边界 | ||
|
|
||
| - `internal/session` 是会话领域模型、存储抽象与 JSON 持久化实现的唯一归属层。 | ||
| - `internal/runtime` 负责决定保存时机、恢复会话状态和编排主循环,不承载文件存储细节。 | ||
| - `internal/tui` 只消费 runtime 暴露的会话数据,不直接读写会话文件。 | ||
|
|
||
| ## 存储策略 | ||
| NeoCode 在 MVP 阶段使用 JSON 文件持久化 Session,以保持本地优先、易于调试和跨平台可移植。 | ||
|
|
||
| NeoCode 当前使用本地 JSON 文件持久化会话,以保持实现简单、可调试且跨平台可移植。 | ||
|
|
||
| - 默认目录按工作区隔离:`~/.neocode/projects/<workspace-hash>/sessions/` | ||
| - 工作区哈希基于启动阶段确定的工作区根目录生成 | ||
| - `session.Workdir` 表示会话当前实际执行命令使用的目录,可被运行期命令修改,但不参与分桶 | ||
| - 旧的全局 `~/.neocode/sessions/` 开发期数据不迁移、不回读 | ||
|
|
||
| ## 数据模型 | ||
| - `Session`:完整消息历史以及 `id`、`title`、`updated_at`、`token_input_total`、`token_output_total` 等元信息 | ||
| - `Summary`:用于侧边栏的轻量摘要结构(原 `SessionSummary` 命名已统一收口为 `Summary`) | ||
|
|
||
| ### Token 持久化 | ||
| - `token_input_total` 和 `token_output_total` 分别记录会话累计输入和输出 token。 | ||
| - 使用 `omitempty` 标签,确保旧版 JSON 文件正常加载(零值不序列化)。 | ||
| - runtime 在每次 provider 调用后更新 session 的 token 字段,随 session save 一起持久化。 | ||
| - 会话加载时,runtime 从 session 恢复 token 计数器;新建会话时计数器清零。 | ||
| - 自动压缩成功后 token 计数器重置为零,并持久化到 session。 | ||
| `internal/session.Session` 持久化以下核心字段: | ||
|
|
||
| - `id`、`title` | ||
| - `provider`、`model` | ||
| - `created_at`、`updated_at` | ||
| - `workdir` | ||
| - `messages` | ||
| - `token_input_total` | ||
| - `token_output_total` | ||
|
|
||
| 其中: | ||
|
|
||
| - `provider` / `model` 记录最近一次成功运行会话时使用的配置,供 compact 等流程优先复用 | ||
| - `token_input_total` / `token_output_total` 分别表示会话累计输入与输出 token | ||
| - token 字段使用 `omitempty`,以兼容旧版 session JSON 文件 | ||
|
|
||
| ## 加载策略 | ||
| - `ListSummaries` 只读取渲染侧边栏所需的基础信息 | ||
| - `Load` 仅在用户真正进入某个会话时读取完整消息历史 | ||
| - `Save` 通过临时文件原子写入完整 Session | ||
| `internal/session.Summary` 只保留会话列表渲染所需的轻量字段,不加载完整消息历史。 | ||
|
|
||
| ## 命名策略 | ||
| - 新会话默认展示为 `New Session` | ||
| - 一旦持久化,runtime 会根据首轮用户消息生成简短标题 | ||
| ## 读写行为 | ||
|
|
||
| - `Save` 使用“临时文件 + 原子替换”写入完整会话 JSON | ||
| - `Load` 在用户真正进入某个会话时读取完整历史 | ||
| - `ListSummaries` 只解析摘要字段,并按 `updated_at` 倒序返回 | ||
|
|
||
| ## Token 计数持久化 | ||
|
|
||
| - runtime 在 provider 调用完成后更新 session 的累计 token 字段 | ||
| - 会话保存时,token 计数随 session 一起持久化 | ||
| - 会话重新加载时,runtime 从 session 恢复累计 token | ||
| - 自动 compact 成功后,runtime 会重置累计 token,并将重置后的值持久化 | ||
|
|
||
| ## 保存时机 | ||
|
|
||
| - 用户消息提交后保存 | ||
| - assistant 完整回复后保存 | ||
| - 每个工具结果完成后保存 | ||
| - 避免在高频 UI 刷新路径中直接做磁盘 I/O | ||
|
|
||
| ## 并发约束 | ||
| - `internal/session` 中的 Store 实现必须自行保护共享访问 | ||
| - 真正的保存时机由 runtime 决定,TUI 不负责直接触发磁盘写入 | ||
|
|
||
| ## 兼容性与演进说明 | ||
| - 会话持久化能力已从 runtime 侧实现中彻底收口到 `internal/session` | ||
| - 新增会话存储实现时,应优先在 `internal/session` 内扩展并通过接口注入 runtime,避免跨层实现 | ||
| - `internal/session` 的存储实现自行保护共享访问 | ||
| - 保存时机统一由 runtime 决定,TUI 不直接触发磁盘写入 | ||
|
|
||
| ## 工作区隔离 | ||
| ## 演进约束 | ||
|
|
||
| - session 现按工作区隔离存储,目录规则为 `~/.neocode/projects/<workspace-hash>/sessions/` | ||
| - 工作区哈希基于启动时确定的工作区根目录生成,而不是基于 `session.Workdir` | ||
| - `session.Workdir` 仍表示该会话当前实际执行命令时使用的目录,可被 `/cwd` 修改 | ||
| - 旧的全局 `~/.neocode/sessions/` 开发期数据不迁移、不回读 | ||
| - 新增存储实现时,应优先在 `internal/session` 内扩展并通过接口注入 | ||
| - 不应把持久化逻辑重新分散到 `runtime`、`tui` 或其他上层模块 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This README now advertises
docs/guides/adding-providers.mdas the contributor guide, but that guide still describes the pre-refactor API (internal/provider/openai, driver"openai",ChatRequest/Chat). After this PR the canonical names areinternal/provider/openaicompat, driver"openaicompat", andGenerateRequest/Generate. Surfacing the stale guide here will send new provider implementations down a non-compiling path.