refactor(workflow): 抽离统一 Workflow Registry - #28
Merged
Merged
Conversation
把 Workflow 模板模型与校验、published 文件持久化、发布/退役/回滚生命周期、 版本比较、match 打分与向量索引从 HTTP 层完整迁入独立的业务包: - model.go:Template/Step/MatchRule/Status/Candidate、结构与反 SOP guardrails 校验、内容哈希、三段数字版本比较与 LatestVersions。 - registry.go:Registry 以 published 目录为唯一事实来源,Publish/Retire/Get/ Active/List 全部加锁串行;OperationError 携带稳定错误码与 HTTP 状态码供边界 映射;落盘沿用临时文件 + rename + 目录 fsync 的原子写,发布或退役中途失败 按顺序回滚。 - match.go:词法 + 向量打分与候选排序;embedding 网络调用在锁外执行。 - vector.go:向量索引模型与严格 JSON 校验、状态快照、重建、embedding 客户端; AIConfig 为运行期可变设置的按调用传入子集。 测试随职责一起迁移(哈希一致性、生命周期元数据归一、发布/退役失败回滚、 严格 JSON 损坏报告、文件权限、向量索引 stale/invalid/维度一致性、embedding API Key 与请求取消),保持与原 HTTP 层测试等效的行为覆盖。
删除 internal/httpx/workflow_template_registry.go(约 1105 行),HTTP 层只保留 JSON/HTTP 映射与展示视图: - workflow_templates_http.go:7 个 REST 端点路由与业务错误到 HTTP 响应的映射; workflowAIConfig 把运行期可变的 AI 设置按请求映射成 workflow.AIConfig。 - workflow_templates.go / workflow_templates_lifecycle.go:summary 展示视图、 文件元数据(经 Registry.PublishedFilePath 定位)、当前版本折叠与计数; 版本比较复用 workflow.CompareVersions,不再有第二套实现。 - mcp_workflow.go:集中式 MCP 工具 workflow_template_manage 与 REST 共用同一个 workflow.Registry;match/vector_index 响应组装保持原字段形状。 - mcp_context.go / evolution_stage3.go:共享上下文与 Stage3 快照改为读取 Registry.List + workflow.LatestVersions。 - server.go:新增 WithWorkflowRegistry 注入点;nexusapp/app.go 组合根显式创建 Registry(NexusDataDir/workflow-templates)后注入,REST 与 MCP 共用同一实例。 HTTP API 形状与 MCP 工具契约不变,无需更新生成契约与前端产物; 业务测试已随上一提交迁入 internal/workflow,HTTP 层保留路由形状、 重复版本 409 与取消行为测试。
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
主要改动
internal/workflow验证
go test ./internal/workflow ./internal/httpxgo test -race ./internal/workflowmake ci