Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/qa/conversation-sop/after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/qa/conversation-sop/before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion internal/httpapi/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ const assistantNativeSystemPrompt = `你是 LoopForge 的统一协作助手。
平台只读数据用 MCP 工具读取:当前项目和个人已安装的 HTTP MCP,以及 agentflow__issues_list、agentflow__workflows_get、agentflow__agents_list 等平台只读工具。GitHub 仓库可用 repositories_save 绑定;外部 MCP 的能力与工具名以当前已安装工具及 schema 为准,不要假设内置某个私有服务;外部 MCP 的全部工具都可调用,写入外部系统的调用按当前审批模式执行(完全权限直接执行,辅助模式先经自动审批,请求批准模式下直接调用工具,网关会等待本轮发言人批准后执行)。不要把密钥写入参数。stdio MCP 不可用。
分析运行为什么失败、卡住或需要人工确认时,先用 agentflow__runs_get 读取该运行:problems 列出失败或等待确认的节点、原因,credential 给出需要运行责任人本人配置的个人凭证与步骤。回答时说清卡在哪个节点、具体原因(引用原始错误)、需要谁做什么;凭证问题照 credential.steps 给出配置步骤,并告诉用户对话里的运行提醒卡片有「去配置」按钮可一键跳转。没读到 runs_get 结果前不要猜原因,也不要把凭证问题归因成执行机器故障。
用户要你改代码、跑命令、构建或测试,或者要查看、评论、审查、合并 GitHub 上的 PR、Issue 时,就在本对话里直接做:调用 workbench_workspace_open 进入工作区(sandboxProfileId 按需要的语言和工具链选择运行环境,不填沿用当前工作区)。普通新开工作区默认是空目录,平台不预先检出仓库:交接后自己 git clone 需要的仓库,自己建分支、提交、推送、开 PR,GitHub API 用已设置的 GH_TOKEN(gh 或 curl);若要直接接入某次同项目历史/暂停 SOP 的原工作区现场(保留未推送改动与产物,且改完后也可回 SOP 继续或重跑节点)或切回本对话之前开过的工作区,调用 workbench_workspace_open 传入其 workspaceRunId(与当前对话在同一执行机器时直接复用原工作区并自动恢复已回收快照,不在同一执行机器时如实告知用户无法跨机器共用)。工具返回 handoff=true 时只回复一句「好的。」并结束本阶段,不向用户解释内部切换,由平台保存原生日志并在同一执行机器的工作区内续接 CLI;handoff=false 表示 SOP 尚在执行,先用 runs_pause 或 runs_cancel 停下。续接后使用 CLI 原生文件、补丁和命令工具完成任务并跑相关测试,最后用简短的话说明改了哪些文件和测试结果。不要让用户去别的入口、另开会话或重复描述需求,也不要为此派发 SOP。推送到主分支、强推、合并 PR 只在用户明确要求时做;开好 PR 后把链接发给用户,平台会在本轮结束时自动把它登记到需求。当前对话没有选择项目、因而没有 workbench_workspace_open 时,请用户点对话右上角的项目名称选择项目(个人对话会直接绑定)后再发一次。平台模式中 cwd 是执行机器上的会话缓存目录,不是项目工作区,原生命令和写入不可用。不要在这里搜索或修改项目代码;先打开工作区,明确开始交接后结束当前阶段。工具集合不会在当前 CLI 内热更新,必须等平台重新启动 CLI 后才使用工作区原生工具;无需用户再发消息。需要打开或查看网页时用 workbench_browser_* 工具(普通对话先用 workbench_workspace_open 开工作区),不要把页面 URL 传给文件或终端工具。用户的浏览器访问不到执行机,但对话侧栏的「浏览器」页签就是你用的这个 Agent 浏览器,用户能实时看到并操作。给用户看页面时,用 workbench_browser_navigate 打开并用 workbench_browser_screenshot 截图(截图自动附在本轮回复里,显示在正文下方),再写出页面地址(file:///workspace/… 或 http://localhost:端口/…),用户点击地址就会在「浏览器」页签打开;工作区回收后这些地址就打不开了,所以要交付 HTML demo、报告等文件,在工作区里用 workbench_publish_artifact 传文件 path 附在回复里(HTML 可在产物栏交互预览)。改动大到需要多角色协作或用户要求走流程时,再建议派发 SOP。
用户问平台有哪些 SOP、准备写需求、新建项目或不知道怎么开始时,主动推荐平台内置的三套通用 SOP,并用 workflows_list / workflows_get 的实际结果核对后说明各自适合什么、好在哪里:generic-product-delivery(通用产品交付:产品定义 → 交互 Demo → 研发交接 → 产品验收 → TAPD 回写 → 交付汇总;想法还没定型、要先出 PRD 和可以点的交互 Demo 时用)、generic-frontend-delivery(通用前端交付:需求契约 → 实现 → 真实验证 → 发起 MR → 归档,可勾选前端预览自动构建静态站点;页面和交互类需求用)、generic-backend-delivery(通用后端交付:定方案 → 实现 → 增量单测 → 独立 CR → 交付;接口、服务和数据类需求用,新项目默认绑定它)。前后端都要做时,可以先用产品 SOP 定稿,再分别派发前端和后端 SOP。结合用户的需求和当前项目已绑定的 SOP 给出一个明确推荐,并告诉用户下一步怎么绑定或派发。
用户问平台有哪些 SOP、准备写需求、新建项目或不知道怎么开始时,主动推荐平台内置的三套通用 SOP,并用 workflows_list / workflows_get 的实际结果核对后说明各自适合什么、好在哪里:generic-product-delivery(通用产品交付:产品定义 → 交互 Demo → 研发交接 → 产品验收 → TAPD 回写 → 交付汇总;想法还没定型、要先出 PRD 和可以点的交互 Demo 时用)、generic-frontend-delivery(通用前端交付:需求契约 → 实现 → 真实验证 → 发起 MR → 归档,可勾选前端预览自动构建静态站点;页面和交互类需求用)、generic-backend-delivery(通用后端交付:定方案 → 实现 → 增量单测 → 独立 CR → 交付;接口、服务和数据类需求用,新建项目时写成项目默认 SOP,对话新建需求只有用户点名才写 workflowId)。前后端都要做时,可以先用产品 SOP 定稿,再分别派发前端和后端 SOP。结合用户的需求和当前项目已绑定的 SOP 给出一个明确推荐,并告诉用户下一步怎么绑定或派发。
` + assistantGeneralChatPrompt

const assistantWorkflowDocumentPrompt = `修改已有 SOP 时先用 workflows_get 或 workflows_revision_get 读取完整定义再改。workflows_save 按 id 整图覆盖 nodes 和 edges,未提交的节点会被删除。`
Expand Down
1 change: 1 addition & 0 deletions internal/httpapi/assistant_conversation_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func conversationRequirementIssue(s *AgentToolSession, run domain.Run, conv doma
Priority: "medium",
Kind: "requirement",
Source: "local",
SOPMode: domain.IssueSOPNone,
AutomationState: "ignored",
AssigneeUserID: s.UserID,
ConversationSessionID: s.ChatSessionID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestConversationRequirementIssueDefaults(t *testing.T) {
if !strings.HasPrefix(issue.ID, "issue-") || issue.ProjectID != "p" || issue.Title != "修复登录页文案" || issue.Description != "按钮文案错了" {
t.Fatalf("identity fields = %+v", issue)
}
if issue.Status != "in_progress" || issue.Priority != "medium" || issue.Kind != "requirement" || issue.Source != "local" || issue.AutomationState != "ignored" {
if issue.Status != "in_progress" || issue.Priority != "medium" || issue.Kind != "requirement" || issue.Source != "local" || issue.SOPMode != domain.IssueSOPNone || issue.AutomationState != "ignored" {
t.Fatalf("default fields = %+v", issue)
}
if issue.AssigneeUserID != 7 || issue.ConversationSessionID != "chat-1" {
Expand Down
5 changes: 4 additions & 1 deletion internal/httpapi/assistant_message_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestAssistantTurnContextStatesBeijingTimeAndProjectSwitching(t *testing.T)
assistantNow = func() time.Time { return time.Date(2026, 11, 1, 6, 16, 0, 0, time.UTC) }
t.Cleanup(func() { assistantNow = old })
inProject := assistantTurnContext(assistantRequest{ProjectID: "skillhub"})
for _, want := range []string{"当前北京时间:2026-11-01 14:16(星期日)", "不要写 UTC", "+08:00", "右上角的项目名称", "不要让用户去输入框上方", "generic-backend-delivery", "不要说「暂不绑定」"} {
for _, want := range []string{"当前北京时间:2026-11-01 14:16(星期日)", "不要写 UTC", "+08:00", "右上角的项目名称", "不要让用户去输入框上方", "sopMode=none", "不要写 workflowId"} {
if !strings.Contains(inProject, want) {
t.Errorf("project context missing %q", want)
}
Expand All @@ -152,4 +152,7 @@ func TestSystemPromptRecommendsTheGenericSOPs(t *testing.T) {
if strings.Contains(prompt, "请用户在输入框上方选择项目") {
t.Error("system prompt still points at the hidden composer picker")
}
if !strings.Contains(prompt, "只有用户点名才写 workflowId") {
t.Error("system prompt still tells the model that a new project requirement is bound")
}
}
2 changes: 1 addition & 1 deletion internal/httpapi/assistant_native_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func assistantIncrementalPrompt(req assistantRequest, checkpoint assistantNative
// selected, offered a project-settings delete that did not exist, and could
// not say what to do about a repository it cannot create.
func assistantProjectScopeNote(projectID string) string {
common := "新项目不指定 workflowId 时,平台默认绑定 generic-backend-delivery(通用后端交付 SOP):草稿和总结里如实写明,不要说「暂不绑定」。"
common := "用户没有点名要走 SOP、也没有给出 workflowId 时,新建需求不要写 workflowId。平台会把这次创建记为不使用 SOP(sopMode=none),不要说已经绑定了通用后端交付。只有用户明确要走某条 SOP 时才在 issues_save 里写 workflowId。项目设置里的默认 SOP 只是以后手动选用时的默认值,不会自动套到这条对话需求上。"
if strings.TrimSpace(projectID) == "" {
return "\n本对话没有绑定项目(个人对话);写入项目内资源前先和用户确认目标项目。需要项目时,请用户点对话右上角的项目名称选择项目(个人对话会直接绑定,不用重开)。" + common
}
Expand Down
4 changes: 2 additions & 2 deletions internal/httpapi/conversation_sop.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

// chatSessionHeader names the conversation a browser-confirmed tool call was
// drafted in. It only links the dispatched issue to that conversation; access
// is checked by the project operation that carries it.
// drafted in. Issue creation and dispatch use this context. Each operation
// performs its own project access checks.
const chatSessionHeader = "X-AgentFlow-Chat-Session"

type conversationSessionKey struct{}
Expand Down
68 changes: 68 additions & 0 deletions internal/httpapi/issue_sop_mode_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httpapi

import (
"context"
"net/http"
"path/filepath"
"testing"
Expand Down Expand Up @@ -77,3 +78,70 @@ func TestRequirementWithoutSOP(t *testing.T) {
t.Fatalf("binding an SOP must switch the requirement to SOP delivery: %+v", rebound)
}
}

func TestConversationIssueSaveRespectsSOPSelection(t *testing.T) {
t.Setenv("AGENTFLOW_SESSION_SECRET", "conversation-issue-test-secret")
h, user := workbenchFixture(t)
h.api = New(h.repo, engine.New(h.repo, runtime.NewManager(t.TempDir())), tracker.NewService(), "", "")
const flow = "generic-backend-delivery"
project, _ := h.repo.Project("workbench")
project.WorkflowID = flow
project.SOPPlaybooks = []domain.SOPPlaybook{
{ID: "chosen", Name: "Chosen workflow", Bindings: []domain.IssueSOPBinding{{WorkflowID: flow}}},
}
if err := h.repo.PutProject(project); err != nil {
t.Fatal(err)
}
save := func(id string, fields map[string]any, confirm bool) domain.Issue {
t.Helper()
body := map[string]any{"id": id, "projectId": project.ID, "kind": "requirement", "title": id}
for k, v := range fields {
body[k] = v
}
if confirm {
browser := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Header.Set(chatSessionHeader, "qa-conversation")
h.api.ServeHTTP(w, r)
})
requestJSONAuthed[map[string]any](t, browser, user, http.MethodPost, "/mcp", map[string]any{
"jsonrpc": "2.0", "id": 1, "method": "tools/call",
"params": map[string]any{"name": "issues_save", "arguments": map[string]any{"body": body}},
}, http.StatusOK)
} else {
ctx := withAssistantExecMode(context.Background(), assistantExecMode{AutoWrite: true})
_, err := h.callAssistantPlatform(ctx, user, project.ID, assistantMCPCall{
Tool: "issues_save", Arguments: map[string]any{"body": body},
})
if err != nil {
t.Fatal(err)
}
}
issue, ok := h.repo.Issue(id)
if !ok {
t.Fatalf("issue %s was not saved", id)
}
return issue
}
for _, mode := range []string{"confirmed", "automatic"} {
t.Run(mode, func(t *testing.T) {
confirm := mode == "confirmed"
unbound := save(mode+"-unbound", nil, confirm)
if !unbound.WithoutSOP() || unbound.WorkflowID != "" || unbound.AutomationState != "ignored" {
t.Errorf("new issue inherited SOP: mode=%q workflow=%q automation=%q", unbound.SOPMode, unbound.WorkflowID, unbound.AutomationState)
}
named := save(mode+"-workflow", map[string]any{"workflowId": flow}, confirm)
edited := save(named.ID, map[string]any{"title": "Updated title"}, confirm)
if edited.WithoutSOP() || edited.WorkflowID != flow {
t.Errorf("edit lost the chosen workflow: %q", edited.WorkflowID)
}
book := save(mode+"-playbook", map[string]any{"playbookId": "chosen"}, confirm)
if book.WithoutSOP() || book.PlaybookID != "chosen" {
t.Errorf("lost named playbook: %q", book.PlaybookID)
}
chain := save(mode+"-chain", map[string]any{"sopBindings": []map[string]any{{"workflowId": flow}}}, confirm)
if chain.WithoutSOP() || len(chain.SOPBindings) != 1 || chain.SOPBindings[0].WorkflowID != flow {
t.Errorf("lost explicit chain: %+v", chain.SOPBindings)
}
})
}
}
7 changes: 7 additions & 0 deletions internal/httpapi/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ func (h issuesHandlers) issues(c *gin.Context) {
c.JSON(400, map[string]string{"error": "project not found"})
return
}
// Confirmed drafts go through /mcp; automatic assistant saves invoke
// the same HTTP handler in process. Choose the default only on create.
fromConversation := r.Context().Value(conversationSessionKey{}) != nil || assistantExecModeFrom(r.Context()).AutoWrite
if !found && fromConversation && strings.TrimSpace(v.SOPMode) == "" &&
strings.TrimSpace(v.WorkflowID) == "" && strings.TrimSpace(v.PlaybookID) == "" && len(v.SOPBindings) == 0 {
v.SOPMode = domain.IssueSOPNone
}
h.bindRequirementPlaybook(&v)
if v.AssigneeUserID > 0 {
if _, ok := h.repo.User(v.AssigneeUserID); !ok {
Expand Down
Loading