feat(bizdev): snapshot collaborators onto Runtime and Server ports

Composition roots copy Parts once so HTTP/CLI handlers stop calling locator getters on every request.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
weichen
2026-09-15 13:00:33 +00:00
co-authored by Cursor
parent 92a9c6783d
commit 3f42149457
68 changed files with 458 additions and 315 deletions
+24 -24
View File
@@ -330,7 +330,7 @@ func main() {
func handleStageRun(
ctx context.Context,
svc bizdev.BizdevService,
svc *bizdev.Service,
stageName string,
project, customer, device, use, market, backend string,
autoRepair bool,
@@ -455,7 +455,7 @@ func printAdvisorBrief(brief *bizdev.AdvisorBriefing) {
fmt.Println("==================================================================")
}
func handleInspect(ctx context.Context, svc bizdev.BizdevService, workDir string, addStepFlag string, backend string) {
func handleInspect(ctx context.Context, svc *bizdev.Service, workDir string, addStepFlag string, backend string) {
state, err := svc.InspectWorkspace(ctx, workDir)
if err != nil {
fmt.Fprintf(os.Stderr, "查看工作区失败: %v\n", err)
@@ -586,7 +586,7 @@ func createCLIStreamListener(verbose bool) stream.Listener {
func handleChatMode(
ctx context.Context,
svc bizdev.BizdevService,
svc *bizdev.Service,
chatQuery string,
workDir string,
project string,
@@ -664,7 +664,7 @@ func handleChatMode(
rec := intent.NewRecognizer()
engine := coordinator.NewCoordinatorEngine(stageflow.New(svc))
session := chat.NewSession("cli_chat_sess", userCtx, rec, engine)
session.CtxMgr = svc.ContextManager()
session.CtxMgr = bizdev.Snapshot(svc).Ctx
// 单次提问模式 (支持脚本与自动化测试)
if chatQuery != "" {
@@ -805,8 +805,8 @@ func handleChatMode(
// 标杆案例独立检索 CLI 处理函数
// -----------------------------------------------------------------------------
func handleRecommendCases(ctx context.Context, svc bizdev.BizdevService, query string) {
ctxMgr := svc.ContextManager()
func handleRecommendCases(ctx context.Context, svc *bizdev.Service, query string) {
ctxMgr := bizdev.Snapshot(svc).Ctx
if ctxMgr == nil {
fmt.Fprintf(os.Stderr, "错误: 上下文管理器未初始化\n")
os.Exit(1)
@@ -851,8 +851,8 @@ func handleRecommendCases(ctx context.Context, svc bizdev.BizdevService, query s
// 受控文档治理 CLI 处理函数集
// -----------------------------------------------------------------------------
func handleDocStatus(ctx context.Context, svc bizdev.BizdevService, docID string) {
doc, err := svc.DocGov().GetDocument(ctx, docID)
func handleDocStatus(ctx context.Context, svc *bizdev.Service, docID string) {
doc, err := bizdev.Snapshot(svc).Gov.GetDocument(ctx, docID)
if err != nil {
fmt.Fprintf(os.Stderr, "查询受控文档失败 [%s]: %v\n", docID, err)
os.Exit(1)
@@ -879,7 +879,7 @@ func handleDocStatus(ctx context.Context, svc bizdev.BizdevService, docID string
}
// 打印批注
comments, _ := svc.DocGov().ListComments(ctx, docID)
comments, _ := bizdev.Snapshot(svc).Gov.ListComments(ctx, docID)
if len(comments) > 0 {
fmt.Printf("\n批注与修改意见 (%d 条):\n", len(comments))
for idx, c := range comments {
@@ -888,7 +888,7 @@ func handleDocStatus(ctx context.Context, svc bizdev.BizdevService, docID string
}
// 打印审计记录
audits, _ := svc.DocGov().ListAuditLogs(ctx, docID)
audits, _ := bizdev.Snapshot(svc).Gov.ListAuditLogs(ctx, docID)
if len(audits) > 0 {
fmt.Printf("\n全生命周期审计轨迹 (%d 条):\n", len(audits))
for idx, a := range audits {
@@ -899,9 +899,9 @@ func handleDocStatus(ctx context.Context, svc bizdev.BizdevService, docID string
fmt.Println("==================================================================")
}
func handleDocClaim(ctx context.Context, svc bizdev.BizdevService, docID string, userID int64, userRoleStr string, userName string) {
func handleDocClaim(ctx context.Context, svc *bizdev.Service, docID string, userID int64, userRoleStr string, userName string) {
role := docgov.UserRole(userRoleStr)
doc, err := svc.DocGov().RecordDocumentViewed(ctx, docID, userID, role, userName)
doc, err := bizdev.Snapshot(svc).Gov.RecordDocumentViewed(ctx, docID, userID, role, userName)
if err != nil {
fmt.Fprintf(os.Stderr, "认领/查看文档失败: %v\n", err)
os.Exit(1)
@@ -917,7 +917,7 @@ func handleDocClaim(ctx context.Context, svc bizdev.BizdevService, docID string,
}
}
func handleDecideProposal(ctx context.Context, svc bizdev.BizdevService, param string, authorID int64) {
func handleDecideProposal(ctx context.Context, svc *bizdev.Service, param string, authorID int64) {
// 格式: proposal_id:agree/reject:理由
parts := strings.SplitN(param, ":", 3)
if len(parts) < 2 {
@@ -932,7 +932,7 @@ func handleDecideProposal(ctx context.Context, svc bizdev.BizdevService, param s
}
approve := decision == "agree" || decision == "approve" || decision == "yes" || decision == "true"
prop, err := svc.DocGov().DecideModificationProposal(ctx, proposalID, authorID, approve, reason)
prop, err := bizdev.Snapshot(svc).Gov.DecideModificationProposal(ctx, proposalID, authorID, approve, reason)
if err != nil {
fmt.Fprintf(os.Stderr, "拍板决策变更提案失败: %v\n", err)
os.Exit(1)
@@ -946,8 +946,8 @@ func handleDecideProposal(ctx context.Context, svc bizdev.BizdevService, param s
}
}
func handleDocSubmitReview(ctx context.Context, svc bizdev.BizdevService, docID string, userID int64, userRoleStr string, userName string) {
doc, err := svc.DocGov().SubmitForReview(ctx, docID, userID, docgov.RoleAuthor, userName)
func handleDocSubmitReview(ctx context.Context, svc *bizdev.Service, docID string, userID int64, userRoleStr string, userName string) {
doc, err := bizdev.Snapshot(svc).Gov.SubmitForReview(ctx, docID, userID, docgov.RoleAuthor, userName)
if err != nil {
fmt.Fprintf(os.Stderr, "提交审核失败: %v\n", err)
os.Exit(1)
@@ -955,8 +955,8 @@ func handleDocSubmitReview(ctx context.Context, svc bizdev.BizdevService, docID
fmt.Printf("✓ 文档 [%s] 编制完成并成功送审!当前状态: %s,文档已进入受控锁定。\n", doc.DocID, doc.CurrentState)
}
func handleDocReviewApprove(ctx context.Context, svc bizdev.BizdevService, docID string, userID int64, userRoleStr string, userName string) {
doc, err := svc.DocGov().ReviewApprove(ctx, docID, userID, docgov.RoleReviewer, userName, "审核无误,同意提交批准")
func handleDocReviewApprove(ctx context.Context, svc *bizdev.Service, docID string, userID int64, userRoleStr string, userName string) {
doc, err := bizdev.Snapshot(svc).Gov.ReviewApprove(ctx, docID, userID, docgov.RoleReviewer, userName, "审核无误,同意提交批准")
if err != nil {
fmt.Fprintf(os.Stderr, "审核通过失败: %v\n", err)
os.Exit(1)
@@ -964,7 +964,7 @@ func handleDocReviewApprove(ctx context.Context, svc bizdev.BizdevService, docID
fmt.Printf("✓ 审核人 %s 审核通过!文档 [%s] 流转至批准阶段: %s\n", userName, doc.DocID, doc.CurrentState)
}
func handleDocReviewReject(ctx context.Context, svc bizdev.BizdevService, param string, userID int64, userRoleStr string, userName string) {
func handleDocReviewReject(ctx context.Context, svc *bizdev.Service, param string, userID int64, userRoleStr string, userName string) {
parts := strings.SplitN(param, ":", 2)
if len(parts) < 2 || strings.TrimSpace(parts[1]) == "" {
fmt.Fprintf(os.Stderr, "错误: 驳回时必须提供驳回原因!格式: doc_id:驳回原因\n")
@@ -973,7 +973,7 @@ func handleDocReviewReject(ctx context.Context, svc bizdev.BizdevService, param
docID := strings.TrimSpace(parts[0])
reason := strings.TrimSpace(parts[1])
doc, err := svc.DocGov().ReviewReject(ctx, docID, userID, docgov.RoleReviewer, userName, reason)
doc, err := bizdev.Snapshot(svc).Gov.ReviewReject(ctx, docID, userID, docgov.RoleReviewer, userName, reason)
if err != nil {
fmt.Fprintf(os.Stderr, "审核驳回失败: %v\n", err)
os.Exit(1)
@@ -982,8 +982,8 @@ func handleDocReviewReject(ctx context.Context, svc bizdev.BizdevService, param
userName, doc.DocID, doc.CurrentState, reason)
}
func handleDocApproverApprove(ctx context.Context, svc bizdev.BizdevService, docID string, userID int64, userRoleStr string, userName string) {
doc, err := svc.DocGov().ApproverApprove(ctx, docID, userID, docgov.RoleApprover, userName, "评估完备,批准受控发布")
func handleDocApproverApprove(ctx context.Context, svc *bizdev.Service, docID string, userID int64, userRoleStr string, userName string) {
doc, err := bizdev.Snapshot(svc).Gov.ApproverApprove(ctx, docID, userID, docgov.RoleApprover, userName, "评估完备,批准受控发布")
if err != nil {
fmt.Fprintf(os.Stderr, "批准失败: %v\n", err)
os.Exit(1)
@@ -991,7 +991,7 @@ func handleDocApproverApprove(ctx context.Context, svc bizdev.BizdevService, doc
fmt.Printf("🎉 批准负责人 %s 最终批准文档 [%s]!当前状态: %s,受控终态归档锁定。\n", userName, doc.DocID, doc.CurrentState)
}
func handleDocApproverReject(ctx context.Context, svc bizdev.BizdevService, param string, userID int64, userRoleStr string, userName string) {
func handleDocApproverReject(ctx context.Context, svc *bizdev.Service, param string, userID int64, userRoleStr string, userName string) {
parts := strings.SplitN(param, ":", 2)
if len(parts) < 2 || strings.TrimSpace(parts[1]) == "" {
fmt.Fprintf(os.Stderr, "错误: 驳回时必须提供驳回原因!格式: doc_id:驳回原因\n")
@@ -1000,7 +1000,7 @@ func handleDocApproverReject(ctx context.Context, svc bizdev.BizdevService, para
docID := strings.TrimSpace(parts[0])
reason := strings.TrimSpace(parts[1])
doc, err := svc.DocGov().ApproverReject(ctx, docID, userID, docgov.RoleApprover, userName, reason, docgov.StateDrafting)
doc, err := bizdev.Snapshot(svc).Gov.ApproverReject(ctx, docID, userID, docgov.RoleApprover, userName, reason, docgov.StateDrafting)
if err != nil {
fmt.Fprintf(os.Stderr, "批准驳回失败: %v\n", err)
os.Exit(1)
+1 -1
View File
@@ -27,7 +27,7 @@ func main() {
fmt.Fprintf(os.Stderr, "NewService: %v\n", err)
os.Exit(1)
}
ctxMgr := svc.ContextManager()
ctxMgr := bizdev.Snapshot(svc).Ctx
if ctxMgr == nil {
fmt.Fprintf(os.Stderr, "ContextManager 未初始化\n")
os.Exit(1)