Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7420: render the workflow brief once on the server, for the assignee or an observer (#9293)
Jiayuan Zhang700d25eef51b
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex 7b2696f855..39af184c71 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -10011,20 +10011,6 @@ func convertIssueStatusesForEnv(statuses []IssueStatusData) []execenv.IssueStatureturn result}-func convertProjectWorkflowForEnv(w *ProjectWorkflowData) *execenv.ProjectWorkflowForEnv {- if w == nil || len(w.Steps) == 0 {- return nil- }- steps := make([]execenv.ProjectWorkflowStepForEnv, len(w.Steps))- for i, s := range w.Steps {- steps[i] = execenv.ProjectWorkflowStepForEnv{- Key: s.Key, Name: s.Name, Handler: s.Handler, Instructions: s.Instructions,- NextStatusKey: s.NextStatusKey, BackStatusKey: s.BackStatusKey,- }- }- return &execenv.ProjectWorkflowForEnv{Name: w.Name, CurrentStatusKey: w.CurrentStatusKey, Steps: steps}-}-func convertReposForEnv(repos []RepoData) []execenv.RepoContextForEnv {if len(repos) == 0 {return nildiff --git a/server/internal/daemon/execenv/execenv.go b/server/internal/daemon/execenv/execenv.goindex e1405e28d7..a6f908e362 100644--- a/server/internal/daemon/execenv/execenv.go+++ b/server/internal/daemon/execenv/execenv.go@@ -248,25 +248,6 @@ type IssueStatusForEnv struct {Description string}-// ProjectWorkflowForEnv is the workflow of the issue's project (MUL-7420),-// present only when that project's workflow hands off. It is rendered into-// the per-turn prompt by BuildProjectWorkflowBlock and never into the brief:-// it varies by project and the current step by run.-type ProjectWorkflowForEnv struct {- Name string- CurrentStatusKey string- Steps []ProjectWorkflowStepForEnv-}--type ProjectWorkflowStepForEnv struct {- Key string- Name string- Handler string- Instructions string- NextStatusKey string- BackStatusKey string-}-type SkillContextForEnv struct {Name stringDescription stringdiff --git a/server/internal/daemon/execenv/runtime_config_project_workflow_test.go b/server/internal/daemon/execenv/runtime_config_project_workflow_test.godeleted file mode 100644index ee0046119d..0000000000--- a/server/internal/daemon/execenv/runtime_config_project_workflow_test.go+++ /dev/null@@ -1,68 +0,0 @@-package execenv--import (- "strings"- "testing"-)--// Project workflow block of the per-turn prompt (MUL-7420). The brief has no-// workflow input at all: TaskContextForEnv carries none, so neither the-// project nor the current step can reach the cached prefix (MUL-5377).--func TestProjectWorkflowBlockEmptyRendersNothing(t *testing.T) {- t.Parallel()- if got := BuildProjectWorkflowBlock(nil, "issue-1"); got != "" {- t.Fatalf("nil workflow rendered %q", got)- }- if got := BuildProjectWorkflowBlock(&ProjectWorkflowForEnv{Name: "Delivery"}, "issue-1"); got != "" {- t.Fatalf("a workflow without steps rendered %q", got)- }-}--func TestProjectWorkflowBlockRendersStepsAndExits(t *testing.T) {- t.Parallel()- out := BuildProjectWorkflowBlock(&ProjectWorkflowForEnv{- Name: "Delivery",- CurrentStatusKey: "implement",- Steps: []ProjectWorkflowStepForEnv{- {Key: "todo", Name: "Todo"},- {Key: "implement", Name: "Implement", Handler: "Forge", Instructions: "Open a PR.\nLink it here.", NextStatusKey: "code_review"},- {Key: "code_review", Name: "Code review", Handler: "Sentinel", NextStatusKey: "done", BackStatusKey: "implement"},- {Key: "done", Name: "Done"},- },- }, "issue-1")- for _, want := range []string{- "[Project workflow: Delivery]\n",- "finish your step by moving to the step's next status instead",- "- `todo` Todo\n",- "- `implement` Implement — hands off to Forge (current)\n",- "- `code_review` Code review — hands off to Sentinel\n",- "> Open a PR.\n> Link it here.\n",- "- Step done → `multica issue status issue-1 code_review`\n",- } {- if !strings.Contains(out, want) {- t.Errorf("block is missing %q\n---\n%s", want, out)- }- }- if strings.Contains(out, "Needs changes →") {- t.Errorf("the current step has no back status, so no needs-changes exit may render")- }-}--func TestProjectWorkflowBlockSanitizesUserText(t *testing.T) {- t.Parallel()- out := BuildProjectWorkflowBlock(&ProjectWorkflowForEnv{- Name: "Flow\n## Injected",- CurrentStatusKey: "a",- Steps: []ProjectWorkflowStepForEnv{- {Key: "a", Name: "Step\n# Heading"},- {Key: "bad key`", Name: "Dropped"},- },- }, "issue-1")- if strings.Contains(out, "\n## Injected") || strings.Contains(out, "\n# Heading") {- t.Fatalf("user-authored names must not inject headings\n---\n%s", out)- }- if strings.Contains(out, "Dropped") {- t.Errorf("a step whose key is not a code token must be dropped")- }-}diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex 3e74d8326a..92ebda662a 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -615,74 +615,6 @@ func writeWorkflowIssue(b *strings.Builder, ctx TaskContextForEnv) {b.WriteString("- Your turn produced none of the issue's own deliverable — you answered a question or consulted on work owned elsewhere → write nothing, at any point; questions, discussion, and acknowledgements never touch status. This no-write default is what keeps concurrent runs from flapping the board.\n\n")}-// BuildProjectWorkflowBlock renders the issue's project workflow (MUL-7420)-// for the per-turn prompt: its statuses in board order, who each step hands-// the issue to, and the current step's instructions and exits. Moving the-// issue into a step with a handler reassigns it to that handler, which is how-// work passes along the workflow; nothing advances the status when a run ends.-//-// Names, handlers and instructions are user-authored and pass through the-// same sanitizers as the status catalog; a step whose key fails the code-token-// check is dropped.-func BuildProjectWorkflowBlock(w *ProjectWorkflowForEnv, issueID string) string {- if w == nil || len(w.Steps) == 0 {- return ""- }- var sb strings.Builder- b := &sb- fmt.Fprintf(b, "[Project workflow: %s]\n", sanitizeNameForBriefMarkdown(w.Name))- b.WriteString("This issue's status can only be one of the keys below. Where a status rule names a key this workflow does not list — `in_review` on delivery, for example — finish your step by moving to the step's next status instead. Moving the issue into a step that hands off reassigns it to that step's handler and starts their run; the system never advances the status when a run ends. Each step's handler gets a run when the issue enters that step, so do not use `multica issue wakeup` to watch this issue's status, assignee or runs; use wakeups only to wait for a time or for something outside this issue.\n\n")- var current *ProjectWorkflowStepForEnv- for i := range w.Steps {- s := &w.Steps[i]- key := sanitizeBriefCodeToken(s.Key)- if key == "" {- continue- }- fmt.Fprintf(b, "- `%s`", key)- if name := sanitizeNameForBriefMarkdown(s.Name); name != "" {- fmt.Fprintf(b, " %s", name)- }- if handler := sanitizeNameForBriefMarkdown(s.Handler); handler != "" {- fmt.Fprintf(b, " — hands off to %s", handler)- }- if s.Key == w.CurrentStatusKey {- b.WriteString(" (current)")- current = s- }- b.WriteString("\n")- }- b.WriteString("\n")- if current == nil {- return sb.String()- }- if instructions := strings.TrimSpace(current.Instructions); instructions != "" {- b.WriteString("Current step instructions:\n")- for _, line := range strings.Split(instructions, "\n") {- b.WriteString("> ")- b.WriteString(line)- b.WriteString("\n")- }- b.WriteString("\n")- }- next := sanitizeBriefCodeToken(current.NextStatusKey)- back := sanitizeBriefCodeToken(current.BackStatusKey)- id := sanitizeBriefCodeToken(issueID)- if id == "" {- id = "<id>"- }- if next != "" {- fmt.Fprintf(b, "- Step done → `multica issue status %s %s`\n", id, next)- }- if back != "" {- fmt.Fprintf(b, "- Needs changes → `multica issue status %s %s`\n", id, back)- }- if next != "" || back != "" {- b.WriteString("\n")- }- return sb.String()-}-// writeSubIssueCreation emits the Sub-issue Creation section.//// MUL-5442 demotes the full todo/backlog/stage playbook to the multica-platformdiff --git a/server/internal/daemon/prompt.go b/server/internal/daemon/prompt.goindex 1cba6be69d..7acaecda78 100644--- a/server/internal/daemon/prompt.go+++ b/server/internal/daemon/prompt.go@@ -76,13 +76,16 @@ func perTurnContextBlocks(task Task, opts promptOpts) string {// buildProjectWorkflowBlock carries the issue's project workflow and current// step (MUL-7420). It varies by project and by step, so it lives here and not-// in the cached brief (MUL-5377). A handoff run already got the same workflow-// and step brief as its handoff note, so it is not repeated.+// in the cached brief (MUL-5377).func buildProjectWorkflowBlock(task Task) string {- if task.ProjectWorkflow == nil || (task.HandoffNote != "" && task.WakeupID == "") {+ if task.ProjectWorkflow == nil {return ""}- return execenv.BuildProjectWorkflowBlock(convertProjectWorkflowForEnv(task.ProjectWorkflow), task.IssueID)+ brief := strings.TrimSpace(task.ProjectWorkflow.Brief)+ if brief == "" {+ return ""+ }+ return "[Project workflow]\n" + brief + "\n\n"}// buildJoinedWakeupsBlock carries wakeups that fired while this run was@@ -257,7 +260,10 @@ func buildPromptBody(task Task, provider string) string {// per-turn prompt rather than the cached runtime brief (MUL-5377).if task.HandoffNote != "" {b.WriteString("You were handed this issue with a handoff note. Treat it as the assigner's scoping instruction for this run; follow it before doing anything broader, and do not reply to it as if it were a comment:\n\n")- fmt.Fprintf(&b, "> %s\n\n", task.HandoffNote)+ for _, line := range strings.Split(strings.TrimSpace(task.HandoffNote), "\n") {+ fmt.Fprintf(&b, "> %s\n", line)+ }+ b.WriteString("\n")}fmt.Fprintf(&b, "Start by running `multica issue get %s --output json` to understand your task, then complete it.\n", task.IssueID)// Workflow step 2 owns the catch-up rule for every issue turn; this linediff --git a/server/internal/daemon/types.go b/server/internal/daemon/types.goindex cdecd2de24..09b671642b 100644--- a/server/internal/daemon/types.go+++ b/server/internal/daemon/types.go@@ -65,22 +65,11 @@ type IssueStatusData struct {Description string `json:"description,omitempty"`}-// ProjectWorkflowData mirrors the claim payload's project workflow (MUL-7420):-// the statuses the issue's project uses, in board order, and who each step-// hands the issue to.+// ProjectWorkflowData mirrors the claim payload's project workflow (MUL-7420).+// Brief is rendered by the server for this run — the assignee's or an+// observer's — and goes into the per-turn prompt as is.type ProjectWorkflowData struct {- Name string `json:"name"`- CurrentStatusKey string `json:"current_status_key"`- Steps []ProjectWorkflowStepData `json:"steps"`-}--type ProjectWorkflowStepData struct {- Key string `json:"key"`- Name string `json:"name"`- Handler string `json:"handler,omitempty"`- Instructions string `json:"instructions,omitempty"`- NextStatusKey string `json:"next_status_key,omitempty"`- BackStatusKey string `json:"back_status_key,omitempty"`+ Brief string `json:"brief"`}// Task represents a claimed task from the server.diff --git a/server/internal/daemon/workflow_prompt_test.go b/server/internal/daemon/workflow_prompt_test.goindex dfbb3bedaa..2d9d65ebbb 100644--- a/server/internal/daemon/workflow_prompt_test.go+++ b/server/internal/daemon/workflow_prompt_test.go@@ -5,52 +5,53 @@ import ("testing")-func deliveryWorkflowAt(step string) *ProjectWorkflowData {- return &ProjectWorkflowData{- Name: "Delivery",- CurrentStatusKey: step,- Steps: []ProjectWorkflowStepData{- {Key: "todo"},- {Key: "in_progress", Handler: "Forge", Instructions: "Open a PR.", NextStatusKey: "in_review"},- {Key: "in_review", Handler: "Forge", Instructions: "Review your own PR.", NextStatusKey: "done", BackStatusKey: "in_progress"},- {Key: "done"},- },- }-}+const deliveryBrief = "This project's workflow — Delivery\nYou are handling the \"Code review\" step of MUL-1.\n"-// The workflow and its current step are per-turn context (MUL-7420): appended-// after everything else, so the prompt ahead of it is the same whatever step-// the issue is at (MUL-5377).+// Project workflow block of the per-turn prompt (MUL-7420). The brief has no+// workflow input at all; the block is appended after everything else, so the+// prompt ahead of it is the same whatever the workflow says.func TestBuildPromptAppendsProjectWorkflowBlock(t *testing.T) {- base := Task{IssueID: "issue-1", TriggerCommentID: "c-1", TriggerCommentContent: "please continue"}+ base := Task{IssueID: "issue-1"}plain := BuildPrompt(base, "claude")- for _, step := range []string{"in_progress", "in_review"} {- task := base- task.ProjectWorkflow = deliveryWorkflowAt(step)- out := BuildPrompt(task, "claude")- if !strings.HasPrefix(out, plain) {- t.Fatalf("step %s: the workflow block must be appended, not change the prompt ahead of it", step)- }- block := out[len(plain):]- for _, want := range []string{"[Project workflow: Delivery]", "- `" + step + "`", "(current)", "multica issue status issue-1 "} {- if !strings.Contains(block, want) {- t.Errorf("step %s: block is missing %q\n---\n%s", step, want, block)- }- }+ task := base+ task.ProjectWorkflow = &ProjectWorkflowData{Brief: deliveryBrief}+ out := BuildPrompt(task, "claude")+ if !strings.HasPrefix(out, plain) {+ t.Fatalf("the workflow block must be appended, not change the prompt ahead of it:\n%s", out)+ }+ if !strings.Contains(out, "[Project workflow]\n"+deliveryBrief) {+ t.Fatalf("prompt is missing the workflow brief:\n%s", out)}}-func TestBuildPromptSkipsWorkflowBlockForHandoffRun(t *testing.T) {- task := Task{IssueID: "issue-1", HandoffNote: "This project's workflow — Delivery\nYou are handling the step.", ProjectWorkflow: deliveryWorkflowAt("in_progress")}- if out := BuildPrompt(task, "claude"); strings.Contains(out, "[Project workflow:") {- t.Fatalf("a handoff run already has the workflow in its note:\n%s", out)+func TestBuildPromptSkipsEmptyWorkflowBrief(t *testing.T) {+ task := Task{IssueID: "issue-1", ProjectWorkflow: &ProjectWorkflowData{Brief: " \n"}}+ if out := BuildPrompt(task, "claude"); strings.Contains(out, "[Project workflow]") {+ t.Fatalf("an empty brief rendered a block:\n%s", out)+ }+}++// A handoff note is the caller's own instruction now; the workflow brief+// arrives through the claim, so a handoff run gets both.+func TestBuildPromptKeepsWorkflowBlockBesideHandoffNote(t *testing.T) {+ task := Task{IssueID: "issue-1", HandoffNote: "Only the login flow.", ProjectWorkflow: &ProjectWorkflowData{Brief: deliveryBrief}}+ out := BuildPrompt(task, "claude")+ if !strings.Contains(out, "> Only the login flow.") || !strings.Contains(out, "[Project workflow]") {+ t.Fatalf("handoff run must carry the note and the workflow brief:\n%s", out)}}func TestBuildPromptKeepsWorkflowBlockForWakeup(t *testing.T) {- task := Task{IssueID: "issue-1", WakeupID: "w-1", HandoffNote: "check the PR", ProjectWorkflow: deliveryWorkflowAt("in_review")}- if out := BuildPrompt(task, "claude"); !strings.Contains(out, "[Project workflow: Delivery]") {- t.Fatalf("a wakeup's note is not the workflow brief, so the block must render:\n%s", out)+ task := Task{IssueID: "issue-1", WakeupID: "w-1", HandoffNote: "check the PR", ProjectWorkflow: &ProjectWorkflowData{Brief: deliveryBrief}}+ if out := BuildPrompt(task, "claude"); !strings.Contains(out, "[Project workflow]") {+ t.Fatalf("wakeup run lost the workflow block:\n%s", out)+ }+}++func TestBuildPromptQuotesEveryHandoffNoteLine(t *testing.T) {+ out := BuildPrompt(Task{IssueID: "issue-1", HandoffNote: "First line.\nSecond line."}, "claude")+ if !strings.Contains(out, "> First line.\n> Second line.\n") {+ t.Fatalf("every handoff note line must be quoted:\n%s", out)}}diff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.goindex c8185ba927..508cc25ad5 100644--- a/server/internal/handler/agent.go+++ b/server/internal/handler/agent.go@@ -349,26 +349,12 @@ type TaskIssueStatusData struct {}// TaskProjectWorkflowData is the workflow of the project a task's issue-// belongs to (MUL-7420), sent only when that project uses a workflow other-// than the workspace Default. The daemon renders it into the brief so the-// agent moves the issue along this project's statuses instead of the-// built-in ones its generic status rules name.+// belongs to (MUL-7420), sent only when that workflow says more than the+// runtime's status rules: a named workflow, or a Default that hands off.+// Brief is the server-rendered text (issueworkflow.Brief); the daemon puts it+// in the per-turn prompt, never in the cached runtime brief.type TaskProjectWorkflowData struct {- Name string `json:"name"`- CurrentStatusKey string `json:"current_status_key"`- Steps []TaskProjectWorkflowStep `json:"steps"`-}--// TaskProjectWorkflowStep is one step of TaskProjectWorkflowData. Handler is a-// display description ("Sentinel", "Lin (project lead)"), empty when the step-// does not hand off. Instructions are sent for the current step only.-type TaskProjectWorkflowStep struct {- Key string `json:"key"`- Name string `json:"name"`- Handler string `json:"handler,omitempty"`- Instructions string `json:"instructions,omitempty"`- NextStatusKey string `json:"next_status_key,omitempty"`- BackStatusKey string `json:"back_status_key,omitempty"`+ Brief string `json:"brief"`}// TaskCancellationActor is the point-in-time actor snapshot attached to adiff --git a/server/internal/handler/daemon.go b/server/internal/handler/daemon.goindex 504c9a0299..87a0f37d0d 100644--- a/server/internal/handler/daemon.go+++ b/server/internal/handler/daemon.go@@ -2821,7 +2821,7 @@ func (h *Handler) buildClaimedTaskResponse(r *http.Request, task *db.AgentTaskQuprojectCtx.applyTo(&resp)// Project workflow (MUL-7420): best-effort, like the status catalog// below — a failure degrades to the workspace-wide status rules.- resp.ProjectWorkflow = h.claimProjectWorkflow(r.Context(), issue)+ resp.ProjectWorkflow = h.claimProjectWorkflow(r.Context(), issue, task)// Load every planned input as one chronological, de-duplicated set.// The trigger is included here so the delivery receipt can only containdiff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.goindex a598b70f39..c5fd276acd 100644--- a/server/internal/handler/issue.go+++ b/server/internal/handler/issue.go@@ -3297,7 +3297,6 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusInternalServerError, "failed to resolve project workflow")return}- var createHandoff *workflowHandoffif createWorkflow != nil {if err := issueworkflow.CheckStatus(createWorkflow, status); err != nil {writeIssueWorkflowError(w, err)@@ -3313,7 +3312,6 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {writeError(w, status, msg)return}- createHandoff = &workflowHandoff{def: *createWorkflow, step: step, project: createWorkflowProject}}}}@@ -3468,9 +3466,6 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {ActorID: actualCreatorID,AnalyticsAgentID: analyticsAgentID,Platform: func() string { p, _, _ := middleware.ClientMetadataFromContext(r.Context()); return p }(),- HandoffNote: func(issue db.Issue) string {- return h.workflowHandoffNote(r.Context(), issue, createHandoff)- },BroadcastPayload: func(issue db.Issue, atts []db.Attachment, labels []db.IssueLabel) map[string]any {payload := issueToResponse(issue, prefix)// The event other tabs receive must carry the category too — filling@@ -4108,11 +4103,10 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {// A workflow handoff (MUL-7420) is decided before the event goes out so// the timeline can record it as one entry: the status change, who the- // issue went to, whether their run started, and the brief it received.+ // issue went to, whether their run started, and the brief it reads. The+ // run gets that brief from its claim; its handoff note stays the+ // caller's own.handoffNote := req.HandoffNote- if handoff != nil && handoffNote == "" {- handoffNote = h.workflowHandoffNote(r.Context(), issue, handoff)- }trigger, willRun := h.IssueService.WillEnqueueRun(r.Context(),service.IssueTriggerInput{Issue: issue,@@ -4151,7 +4145,7 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {"prev_duplicate_of_issue_id": liveDuplicateMark(prevIssue.Status, prevIssue.DuplicateOfIssueID),}if handoff != nil {- updatedPayload["workflow_handoff"] = workflowHandoffPayload(issue, handoff, handoffNote, willRun)+ updatedPayload["workflow_handoff"] = workflowHandoffPayload(issue, handoff, h.workflowHandoffBrief(r.Context(), issue, handoff), willRun)}h.publish(protocol.EventIssueUpdated, workspaceID, actorType, actorID, updatedPayload)if attachmentsChanged {@@ -4908,9 +4902,6 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {projectChanged := req.Updates.ProjectID != nil && uuidToString(prevIssue.ProjectID) != uuidToString(issue.ProjectID)batchHandoffNote := req.Updates.HandoffNote- if handoff != nil && batchHandoffNote == "" {- batchHandoffNote = h.workflowHandoffNote(r.Context(), issue, handoff)- }trigger, willRun := h.IssueService.WillEnqueueRun(r.Context(),service.IssueTriggerInput{Issue: issue,@@ -4933,7 +4924,7 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {"prev_duplicate_of_issue_id": liveDuplicateMark(prevIssue.Status, prevIssue.DuplicateOfIssueID),}if handoff != nil {- batchPayload["workflow_handoff"] = workflowHandoffPayload(issue, handoff, batchHandoffNote, willRun)+ batchPayload["workflow_handoff"] = workflowHandoffPayload(issue, handoff, h.workflowHandoffBrief(r.Context(), issue, handoff), willRun)}h.publish(protocol.EventIssueUpdated, workspaceID, actorType, actorID, batchPayload)diff --git a/server/internal/handler/issue_workflow.go b/server/internal/handler/issue_workflow.goindex e5c9ff9e9e..635d0fd480 100644--- a/server/internal/handler/issue_workflow.go+++ b/server/internal/handler/issue_workflow.go@@ -1399,7 +1399,7 @@ func (h *Handler) PreviewWorkflowHandoff(w http.ResponseWriter, r *http.Request)next.ProjectID = params.ProjectIDnext.AssigneeType = params.AssigneeTypenext.AssigneeID = params.AssigneeID- resp.Brief = h.workflowHandoffNote(r.Context(), next, hand)+ resp.Brief = h.workflowHandoffBrief(r.Context(), next, hand)if issue.AssigneeType != params.AssigneeType || issue.AssigneeID != params.AssigneeID {for _, task := range h.assigneeActiveRuns(r.Context(), issue) {started := task.StartedAtdiff --git a/server/internal/handler/issue_workflow_entry.go b/server/internal/handler/issue_workflow_entry.goindex 977cdce019..a260defb70 100644--- a/server/internal/handler/issue_workflow_entry.go+++ b/server/internal/handler/issue_workflow_entry.go@@ -215,22 +215,30 @@ func (h *Handler) stepMovedError(ctx context.Context, issue db.Issue, step strinreturn out}-// workflowHandoffNote renders the brief the handler's run receives. Only an-// agent or squad handler runs, so members never need one.-func (h *Handler) workflowHandoffNote(ctx context.Context, issue db.Issue, hand *workflowHandoff) string {+// workflowHandoffBrief renders the brief a handoff's agent or squad will+// read, for the timeline and the handoff confirmation. Members run nothing,+// so they get none. The run itself reads the brief its claim renders.+func (h *Handler) workflowHandoffBrief(ctx context.Context, issue db.Issue, hand *workflowHandoff) string {if hand == nil || !issue.AssigneeType.Valid {return ""}if t := issue.AssigneeType.String; t != "agent" && t != "squad" {return ""}+ in := h.workflowBriefInput(ctx, issue, hand.def, hand.project)+ in.StatusKey = hand.step.StatusKey+ return issueworkflow.Brief(in)+}++// workflowBriefInput describes an issue at its current status under its+// project's workflow, for the assignee's brief.+func (h *Handler) workflowBriefInput(ctx context.Context, issue db.Issue, def issueworkflow.Definition, project db.Project) issueworkflow.BriefInput {resolver := issuestatus.NewResolver(issue.WorkspaceID)- identifier := h.getIssuePrefix(ctx, issue.WorkspaceID) + "-" + strconv.Itoa(int(issue.Number))- return issueworkflow.Brief(issueworkflow.BriefInput{- Workflow: hand.def,- ProjectName: hand.project.Title,- StatusKey: hand.step.StatusKey,- IssueIdentifier: identifier,+ return issueworkflow.BriefInput{+ Workflow: def,+ ProjectName: project.Title,+ StatusKey: issue.Status,+ IssueIdentifier: h.getIssuePrefix(ctx, issue.WorkspaceID) + "-" + strconv.Itoa(int(issue.Number)),StatusName: func(key string) string {return resolver.Name(ctx, h.Queries, key)},@@ -238,9 +246,9 @@ func (h *Handler) workflowHandoffNote(ctx context.Context, issue db.Issue, handif !step.HandsOff() {return ""}- return h.stepHandlerName(ctx, issue, hand.project, step)+ return h.stepHandlerName(ctx, issue, project, step)},- })+ }}// actorDisplayName names an agent, squad or member for a brief. It falls back@@ -318,10 +326,12 @@ func (h *Handler) assigneeActiveRuns(ctx context.Context, issue db.Issue) []db.Areturn out}-// claimProjectWorkflow describes the issue's project workflow for a task-// claim, or nil when there is nothing to say beyond the runtime's own status-// rules: no project, or Default with no handoffs.-func (h *Handler) claimProjectWorkflow(ctx context.Context, issue db.Issue) *TaskProjectWorkflowData {+// claimProjectWorkflow renders the issue's project workflow for a task claim,+// or nil when there is nothing to say beyond the runtime's own status rules:+// no project, or Default with no handoffs. The issue's assignee gets the+// step's instructions and commands; any other agent working on the issue+// gets the observer brief, so it does not move a step it does not own.+func (h *Handler) claimProjectWorkflow(ctx context.Context, issue db.Issue, task *db.AgentTaskQueue) *TaskProjectWorkflowData {def, project, err := issueworkflow.ForProject(ctx, h.Queries, issue.WorkspaceID, issue.ProjectID)if err != nil {slog.Warn("task claim: failed to load project workflow for brief injection",@@ -331,28 +341,30 @@ func (h *Handler) claimProjectWorkflow(ctx context.Context, issue db.Issue) *Tasif def == nil || (def.IsDefault && !def.HandsOffAnywhere()) {return nil}- resolver := issuestatus.NewResolver(issue.WorkspaceID)- out := &TaskProjectWorkflowData{- Name: def.Name,- CurrentStatusKey: issue.Status,- Steps: make([]TaskProjectWorkflowStep, 0, len(def.Steps)),- }- for _, step := range def.Steps {- entry := TaskProjectWorkflowStep{- Key: step.StatusKey,- Name: resolver.Name(ctx, h.Queries, step.StatusKey),- NextStatusKey: def.NextStatus(step.StatusKey),- BackStatusKey: step.BackStatusKey,- }- if step.HandsOff() {- entry.Handler = h.stepHandlerName(ctx, issue, project, step)- }- if step.StatusKey == issue.Status {- entry.Instructions = step.Instructions+ in := h.workflowBriefInput(ctx, issue, *def, project)+ if !taskRunsForAssignee(issue, task) {+ in.Observer = true+ if issue.AssigneeType.Valid && issue.AssigneeID.Valid {+ in.AssigneeName = h.actorDisplayName(ctx, issue.WorkspaceID, issue.AssigneeType.String, issue.AssigneeID)}- out.Steps = append(out.Steps, entry)}- return out+ return &TaskProjectWorkflowData{Brief: issueworkflow.Brief(in)}+}++// taskRunsForAssignee reports whether a run works on the issue as its+// assignee: the assigned agent's own run, or a run made for the assigned+// squad.+func taskRunsForAssignee(issue db.Issue, task *db.AgentTaskQueue) bool {+ if task == nil || !issue.AssigneeID.Valid {+ return false+ }+ switch issue.AssigneeType.String {+ case "agent":+ return task.AgentID == issue.AssigneeID+ case "squad":+ return task.SquadID == issue.AssigneeID+ }+ return false}// stepHandlerName describes who a step hands the issue to, for briefs.diff --git a/server/internal/handler/issue_workflow_test.go b/server/internal/handler/issue_workflow_test.goindex bbc302fa51..68c9fc5bfb 100644--- a/server/internal/handler/issue_workflow_test.go+++ b/server/internal/handler/issue_workflow_test.go@@ -15,6 +15,7 @@ import ("github.com/multica-ai/multica/server/internal/service""github.com/multica-ai/multica/server/internal/testutil""github.com/multica-ai/multica/server/internal/util"+ db "github.com/multica-ai/multica/server/pkg/db/generated")// Project workflow tests (MUL-7420).@@ -352,20 +353,28 @@ func TestStatusChangeHandsOffOnDefaultProject(t *testing.T) {if err != nil || len(tasks) != 1 {t.Fatalf("tasks = %d (%v), want one handoff run", len(tasks), err)}- note := tasks[0].HandoffNote.String+ // The run reads the step's brief from its claim; the handoff note is+ // left for a caller's own instruction.+ if tasks[0].HandoffNote.String != "" {+ t.Fatalf("handoff note = %q, want none: the brief rides the claim", tasks[0].HandoffNote.String)+ }+ brief := claimBriefForTest(t, issueID, tasks[0])for _, want := range []string{"Implement it and open a PR.", "This project's workflow — Default (Workflow handoff project)", "Step done → multica issue status"} {- if !strings.Contains(note, want) {- t.Fatalf("handoff note is missing %q:\n%s", want, note)+ if !strings.Contains(brief, want) {+ t.Fatalf("claim brief is missing %q:\n%s", want, brief)}}- // A caller-written note replaces the step's brief.+ // A caller-written note rides beside the step's brief.back := dbfx.Issue(t, "explicit note", testutil.Cols{"project_id": projectID, "status": "todo"})updateIssueForTest(t, back, map[string]any{"status": "in_progress", "handoff_note": "Only the login flow."}).Want(http.StatusOK)backTasks, _ := testHandler.Queries.ListTasksByIssue(context.Background(), util.MustParseUUID(back))if len(backTasks) != 1 || backTasks[0].HandoffNote.String != "Only the login flow." {t.Fatalf("explicit handoff note was not kept: %+v", backTasks)}+ if !strings.Contains(claimBriefForTest(t, back, backTasks[0]), "Implement it and open a PR.") {+ t.Fatal("a caller-written note must not cost the run its step brief")+ }// A project on a workflow without handoffs hands nothing off.plainProject := createWorkflowTestProject(t, "Workflow no handoff project")@@ -599,7 +608,7 @@ func TestCreateIssueHandsOffItsStartingColumn(t *testing.T) {t.Fatalf("assignee = %v, want the todo column's agent", created.AssigneeID)}tasks, _ := testHandler.Queries.ListTasksByIssue(context.Background(), util.MustParseUUID(created.ID))- if len(tasks) != 1 || !strings.Contains(tasks[0].HandoffNote.String, "Triage it.") {+ if len(tasks) != 1 || !strings.Contains(claimBriefForTest(t, created.ID, tasks[0]), "Triage it.") {t.Fatalf("create did not start the column's run with its brief: %+v", tasks)}@@ -650,36 +659,57 @@ func TestClaimCarriesProjectWorkflow(t *testing.T) {quietProject := createWorkflowTestProject(t, "Workflow quiet project")quiet := dbfx.Issue(t, "no handoffs", testutil.Cols{"project_id": quietProject, "status": "todo"})quietIssue, _ := testHandler.Queries.GetIssue(context.Background(), util.MustParseUUID(quiet))- if testHandler.claimProjectWorkflow(context.Background(), quietIssue) != nil {+ if testHandler.claimProjectWorkflow(context.Background(), quietIssue, nil) != nil {t.Fatal("a Default project without handoffs must not carry a workflow")}projectID := deliveryProject(t, "Workflow claim project", agentID)- issueID := dbfx.Issue(t, "claim context", testutil.Cols{"project_id": projectID, "status": "in_progress"})+ issueID := dbfx.Issue(t, "claim context", testutil.Cols{+ "project_id": projectID, "status": "in_progress", "assignee_type": "agent", "assignee_id": agentID,+ })- issue, err := testHandler.Queries.GetIssue(context.Background(), util.MustParseUUID(issueID))- if err != nil {- t.Fatalf("load issue: %v", err)- }- got := testHandler.claimProjectWorkflow(context.Background(), issue)- if got == nil || got.CurrentStatusKey != "in_progress" || len(got.Steps) != 7 {- t.Fatalf("claim workflow = %+v", got)- }- current := got.Steps[2]- if current.Handler == "" || current.Handler == "agent" || current.Instructions == "" || current.NextStatusKey != "in_review" {- t.Fatalf("current step = %+v, want a named handler, its instructions and the next column", current)+ // The assignee's run gets the step's instructions and its commands.+ brief := claimBriefForTest(t, issueID, db.AgentTaskQueue{AgentID: util.MustParseUUID(agentID)})+ for _, want := range []string{+ "This project's workflow — Default (Workflow claim project)",+ "Implement it and open a PR.",+ " ← current",+ "Step done → multica issue status",+ } {+ if !strings.Contains(brief, want) {+ t.Fatalf("assignee brief is missing %q:\n%s", want, brief)+ }}- if got.Steps[3].Instructions != "" {- t.Fatal("only the current step's instructions ride the claim")++ // Any other agent on the issue — mentioned in a comment, say — gets the+ // statuses and is told to leave them to the assignee.+ other := claimBriefForTest(t, issueID, db.AgentTaskQueue{AgentID: util.MustParseUUID(dbfx.Agent(t, "Workflow observer", handlerTestRuntimeID(t)))})+ if !strings.Contains(other, "You are not its assignee") || strings.Contains(other, "Step done") || strings.Contains(other, "Implement it and open a PR.") {+ t.Fatalf("observer brief must leave the step to its assignee:\n%s", other)}plain := dbfx.Issue(t, "no workflow", testutil.Cols{"status": "todo"})plainIssue, _ := testHandler.Queries.GetIssue(context.Background(), util.MustParseUUID(plain))- if testHandler.claimProjectWorkflow(context.Background(), plainIssue) != nil {+ if testHandler.claimProjectWorkflow(context.Background(), plainIssue, nil) != nil {t.Fatal("an issue outside a project must not carry a workflow")}}+// claimBriefForTest renders the workflow brief a claim of task would carry+// for the issue as it is now.+func claimBriefForTest(t *testing.T, issueID string, task db.AgentTaskQueue) string {+ t.Helper()+ issue, err := testHandler.Queries.GetIssue(context.Background(), util.MustParseUUID(issueID))+ if err != nil {+ t.Fatalf("load issue: %v", err)+ }+ got := testHandler.claimProjectWorkflow(context.Background(), issue, &task)+ if got == nil {+ t.Fatalf("claim of %s carries no workflow", issueID)+ }+ return got.Brief+}+func TestPreviewWorkflowHandoffNamesHandlerRunsAndBrief(t *testing.T) {seedTestCatalog(t)agentID := seededReadyAgentID(t)@@ -800,11 +830,13 @@ func TestSameAgentNextStepQueuesARun(t *testing.T) {agentUpdateIssue(t, issueID, agentID, taskID, map[string]any{"status": "in_review"}).Want(http.StatusOK)var queued int- var note string- dbfx.QueryRow(t, `SELECT count(*), COALESCE(max(handoff_note), '') FROM agent_task_queue- WHERE issue_id = $1 AND agent_id = $2 AND status = 'queued'`, issueID, agentID).Scan(&queued, ¬e)- if queued != 1 || !strings.Contains(note, "Review your own PR.") {- t.Fatalf("queued runs for the next step = %d (note %q), want one with the step's brief", queued, note)+ dbfx.QueryRow(t, `SELECT count(*) FROM agent_task_queue+ WHERE issue_id = $1 AND agent_id = $2 AND status = 'queued'`, issueID, agentID).Scan(&queued)+ if queued != 1 {+ t.Fatalf("queued runs for the next step = %d, want one", queued)+ }+ if brief := claimBriefForTest(t, issueID, db.AgentTaskQueue{AgentID: util.MustParseUUID(agentID)}); !strings.Contains(brief, "Review your own PR.") {+ t.Fatalf("the next step's run would not read its instructions:\n%s", brief)}}diff --git a/server/internal/issueworkflow/issueworkflow.go b/server/internal/issueworkflow/issueworkflow.goindex cd5cf9c3e5..af1b53b50f 100644--- a/server/internal/issueworkflow/issueworkflow.go+++ b/server/internal/issueworkflow/issueworkflow.go@@ -614,41 +614,67 @@ type BriefInput struct {// HandlerName describes who a step hands off to, e.g. "Sentinel" or// "Lin (project lead)". Empty means the step does not hand off.HandlerName func(step Step) string-}--// Brief renders the handoff note an agent receives when an-// issue enters a step that hands off to it. The runtime brief's built-in-// status rules (for example in_review on delivery) name statuses this project-// may not use, so the note spells out the workflow's own statuses and the-// exact commands for the next move.+ // Observer renders the brief for an agent working on the issue without+ // being its assignee — mentioned in a comment, say: the statuses, and to+ // leave the status to AssigneeName. The zero value is the assignee's+ // brief, with the step's instructions and the commands that finish it.+ Observer bool+ // AssigneeName names the issue's assignee in an observer's brief; empty+ // means unassigned.+ AssigneeName string+}++// Brief renders what an agent reads about the issue's project workflow: the+// workflow's statuses, who each step hands off to, and — for the assignee —+// the current step's instructions and the commands for the next move. The+// runtime brief's built-in status rules (for example in_review on delivery)+// name statuses this project may not use, so this text replaces them.+//+// It is the one rendering of a workflow for agents: the claim carries it into+// every run's prompt, and the editor and timeline show the same text. Names+// and instructions are user-authored, so control characters are dropped and+// names are kept to one line.func Brief(in BriefInput) string {step, _ := in.Workflow.Step(in.StatusKey)name := func(key string) string {if in.StatusName == nil {return key}- if n := in.StatusName(key); n != "" {+ if n := briefLine(in.StatusName(key)); n != "" {return n}return key}var b strings.Builder- title := in.Workflow.Name- if in.ProjectName != "" {- title = fmt.Sprintf("%s (%s)", title, in.ProjectName)+ title := briefLine(in.Workflow.Name)+ if project := briefLine(in.ProjectName); project != "" {+ title = fmt.Sprintf("%s (%s)", title, project)}fmt.Fprintf(&b, "This project's workflow — %s\n", title)- fmt.Fprintf(&b, "You are handling the %q step of %s. You were assigned because the issue entered this status.\n",- name(in.StatusKey), in.IssueIdentifier)- if step.Instructions != "" {- b.WriteString("\nStep instructions:\n")- for _, line := range strings.Split(step.Instructions, "\n") {- b.WriteString("> ")- b.WriteString(line)- b.WriteString("\n")+ b.WriteString("This workflow replaces the status rules in your runtime instructions: use only the status keys below")+ if !in.Workflow.Has(issuestatus.InReview) {+ fmt.Fprintf(&b, ", never `%s`", issuestatus.InReview)+ }+ b.WriteString(".\n")+ if in.Observer {+ assignee := "is unassigned"+ if who := briefLine(in.AssigneeName); who != "" {+ assignee = "is assigned to " + who+ }+ fmt.Fprintf(&b, "%s is at the %q step and %s. You are not its assignee: leave the status to them unless you are explicitly asked to change it.\n",+ in.IssueIdentifier, name(in.StatusKey), assignee)+ } else {+ fmt.Fprintf(&b, "You are handling the %q step of %s.\n", name(in.StatusKey), in.IssueIdentifier)+ if instructions := briefText(step.Instructions); instructions != "" {+ b.WriteString("\nStep instructions:\n")+ for _, line := range strings.Split(instructions, "\n") {+ b.WriteString("> ")+ b.WriteString(line)+ b.WriteString("\n")+ }}}- b.WriteString("\nStatuses in this workflow (use only these keys):\n")+ b.WriteString("\nStatuses in this workflow:\n")for _, s := range in.Workflow.Steps {// Built-in statuses have no stored name; their key reads on its own.fmt.Fprintf(&b, "- `%s`", s.StatusKey)@@ -656,7 +682,7 @@ func Brief(in BriefInput) string {fmt.Fprintf(&b, " %s", n)}if in.HandlerName != nil {- if who := in.HandlerName(s); who != "" {+ if who := briefLine(in.HandlerName(s)); who != "" {fmt.Fprintf(&b, " — hands off to %s", who)}}@@ -665,7 +691,11 @@ func Brief(in BriefInput) string {}b.WriteString("\n")}- b.WriteString("\nHand off by changing the status:\n")+ if in.Observer {+ b.WriteString("\nMoving the issue into a step that hands off reassigns it to that step's handler and starts their run.\n")+ return b.String()+ }+ b.WriteString("\nHand off by changing the status — moving the issue into a step that hands off reassigns it to that step's handler and starts their run:\n")if next := in.Workflow.NextStatus(in.StatusKey); next != "" {fmt.Fprintf(&b, "Step done → multica issue status %s %s\n", in.IssueIdentifier, next)}@@ -680,7 +710,29 @@ func Brief(in BriefInput) string {default:b.WriteString("Can't proceed → this workflow has no blocked status: comment why and leave the status as it is\n")}- b.WriteString("The system does not advance the status when your run ends. Where your runtime instructions name a status this list does not include, use the commands above instead.\n")- b.WriteString("Each step's handler gets a run when the issue enters that step, so do not use `multica issue wakeup` to watch this issue's status, assignee or runs; use wakeups only to wait for a time or for something outside this issue.\n")+ b.WriteString("The system does not advance the status when your run ends.\n")+ b.WriteString("When the issue enters a step you handle, you get a run automatically — do not add a wakeup for that. Wakeups for anything else (a time, a PR, another issue, a step someone else handles) are fine.\n")return b.String()}++// briefLine keeps a user-authored name on one line of a brief: line breaks+// and tabs become single spaces and other control characters are dropped.+func briefLine(s string) string {+ return strings.Join(strings.Fields(briefText(s)), " ")+}++// briefText drops the control characters of user-authored text, keeping its+// line breaks, so it cannot reshape the brief around it.+func briefText(s string) string {+ s = strings.ReplaceAll(s, "\r\n", "\n")+ s = strings.Map(func(r rune) rune {+ if r == '\n' || r == '\t' {+ return r+ }+ if r < 0x20 || r == 0x7f || (r >= 0x80 && r < 0xa0) || r == '\u2028' || r == '\u2029' {+ return -1+ }+ return r+ }, s)+ return strings.TrimSpace(s)+}diff --git a/server/internal/issueworkflow/issueworkflow_test.go b/server/internal/issueworkflow/issueworkflow_test.goindex 772a963aa4..471ade8d3e 100644--- a/server/internal/issueworkflow/issueworkflow_test.go+++ b/server/internal/issueworkflow/issueworkflow_test.go@@ -273,6 +273,64 @@ func TestBriefNamesStepCommandsAndHandlers(t *testing.T) {}}+func TestBriefForObserverLeavesTheStepToItsAssignee(t *testing.T) {+ brief := Brief(BriefInput{+ Workflow: devDefinition(),+ StatusKey: "code_review",+ IssueIdentifier: "MUL-7",+ Observer: true,+ AssigneeName: "Forge",+ })+ if !strings.Contains(brief, `MUL-7 is at the "code_review" step and is assigned to Forge. You are not its assignee`) {+ t.Fatalf("observer brief must name the assignee and leave them the step:\n%s", brief)+ }+ for _, leak := range []string{"Step instructions", "Step done", "Needs changes", "Can't proceed"} {+ if strings.Contains(brief, leak) {+ t.Fatalf("observer brief must not carry %q:\n%s", leak, brief)+ }+ }+ unassigned := Brief(BriefInput{Workflow: devDefinition(), StatusKey: "code_review", IssueIdentifier: "MUL-7", Observer: true})+ if !strings.Contains(unassigned, "step and is unassigned.") {+ t.Fatalf("observer brief of an unassigned issue:\n%s", unassigned)+ }+}++func TestBriefReplacesInReviewOnlyWhenTheWorkflowLacksIt(t *testing.T) {+ without := Brief(BriefInput{Workflow: devDefinition(), StatusKey: "code_review", IssueIdentifier: "MUL-7"})+ if !strings.Contains(without, "replaces the status rules in your runtime instructions: use only the status keys below, never `in_review`.\n") {+ t.Fatalf("a workflow without in_review must rule it out:\n%s", without)+ }+ def := Definition{Name: DefaultName, IsDefault: true, Steps: stepsFor(BuiltInDefaultKeys())}+ with := Brief(BriefInput{Workflow: def, StatusKey: "in_progress", IssueIdentifier: "MUL-7"})+ if strings.Contains(with, "never `in_review`") {+ t.Fatalf("a workflow that lists in_review must not rule it out:\n%s", with)+ }+}++func TestBriefDropsControlCharactersFromUserText(t *testing.T) {+ def := withHandoffs(devDefinition(), []Step{{+ StatusKey: "code_review", Handler: Handler{Type: HandlerProjectLead},+ Instructions: "Check it.\r\n\x1b[2JThen approve.\u2028Done",+ }})+ def.Name = "Delivery\n## Agent Identity"+ brief := Brief(BriefInput{+ Workflow: def, ProjectName: "Pay\tments", StatusKey: "code_review", IssueIdentifier: "MUL-7",+ HandlerName: func(Step) string { return "Lin\n- `done` fake" },+ })+ for _, want := range []string{+ "This project's workflow — Delivery ## Agent Identity (Pay ments)\n",+ "> Check it.\n> [2JThen approve.Done\n",+ "hands off to Lin - `done` fake",+ } {+ if !strings.Contains(brief, want) {+ t.Fatalf("brief is missing %q:\n%s", want, brief)+ }+ }+ if strings.ContainsAny(brief, "\r\x1b\u2028") {+ t.Fatalf("brief kept a control character:\n%q", brief)+ }+}+func TestBriefPrintsBuiltInKeysOnce(t *testing.T) {def := withHandoffs(Definition{Name: DefaultName, IsDefault: true, Steps: stepsFor(BuiltInDefaultKeys())},[]Step{{StatusKey: "in_review", Handler: Handler{Type: HandlerProjectLead}}})diff --git a/server/internal/service/builtin_skills/multica-platform/SKILL.md b/server/internal/service/builtin_skills/multica-platform/SKILL.mdindex 4f2f1baa78..e3474e98f7 100644--- a/server/internal/service/builtin_skills/multica-platform/SKILL.md+++ b/server/internal/service/builtin_skills/multica-platform/SKILL.md@@ -24,7 +24,7 @@ Read the invariants below, then open the reference(s) your task actually needs| `references/agents.md` | Creating, copying or debugging an agent definition: fields, secrets, MCP config, skill binding || `references/squads.md` | Squads: leader routing, roster, recording leader activity, why a squad did or did not run || `references/autopilots.md` | Autopilots: schedule / webhook / manual triggers, `create_issue` vs `run_only`, why one did not fire |-| `references/projects.md` | Projects and their durable resources (`github_repo`, `local_directory`, worktree mode) |+| `references/projects.md` | Projects and their durable resources (`github_repo`, `local_directory`, worktree mode); project workflows — status columns, handoffs, a `[Project workflow]` block in your prompt || `references/runtimes.md` | Runtimes, daemons, `repo checkout`, and the task CLI boundary || `references/skill-import.md` | Importing a skill into this workspace from a URL or a local archive |diff --git a/server/internal/service/builtin_skills/multica-platform/references/issues.md b/server/internal/service/builtin_skills/multica-platform/references/issues.mdindex 7d41d579f2..ca35f98444 100644--- a/server/internal/service/builtin_skills/multica-platform/references/issues.md+++ b/server/internal/service/builtin_skills/multica-platform/references/issues.md@@ -266,6 +266,9 @@ archived statuses remain readable via an explicit status filter.- **Failed issue-triggered tasks** may roll an issue from `in_progress` back to`todo` when no active task / retry remains — that is the main server-ownedstatus write on the agent-run path.+- **Project workflows** can limit which statuses an issue takes and turn a+ status change into a handoff to another agent. When the per-turn prompt+ carries a `[Project workflow]` block, read `references/projects.md`.## Who else is running right nowdiff --git a/server/internal/service/builtin_skills/multica-platform/references/projects.md b/server/internal/service/builtin_skills/multica-platform/references/projects.mdindex 5768249edd..ece409f478 100644--- a/server/internal/service/builtin_skills/multica-platform/references/projects.md+++ b/server/internal/service/builtin_skills/multica-platform/references/projects.md@@ -11,6 +11,7 @@ display metadata; it is context later injected into task briefs and- [When to add a resource](#when-to-add-a-resource)- [Debugging wrong context](#debugging-wrong-context)- [Side effects](#side-effects)+- [Project workflows](#project-workflows)## Core model@@ -153,3 +154,38 @@ is task-local checkout state.Project create/update/delete/status and project resource add/update/removemutate durable workspace state and affect future tasks. Ask before changing`local_directory` unless the user explicitly requested that exact local path.++## Project workflows++A project can use a workflow: its ordered status columns, where a column may+hand the issue off to a handler — a fixed agent, squad or member, the project+lead, or the issue's creator. When the issue's project uses one, the per-turn+prompt carries a `[Project workflow]` block, and that block replaces the+status rules of your runtime brief for this issue.++- **Only the workflow's keys.** A named workflow accepts only its own+ statuses; any other status write fails with `status_not_in_workflow`, and+ the error lists the allowed keys. The workspace Default workflow accepts+ every status, so issues on statuses it no longer lists keep working.+- **Changing the status is the handoff.** Entering a column that hands off+ reassigns the issue to that column's handler and starts their run; a member+ handler is assigned and runs nothing. Nothing advances the status when a run+ ends: finishing a step means moving the issue to the next status yourself,+ with the command the block names. A column can also name a "needs changes"+ status that sends the issue back.+- **Entering a step you handle starts your run.** Even when your own run makes+ the move, a run for the new step queues behind the current one, and the+ write skips your own event wakeups so one change starts one run. Do not add+ a wakeup to catch it.+- **A run works one step.** A run is bound to the status the issue was at when+ it was queued, and moves along with your own status changes. If someone else+ moves the issue while you work, your status changes are refused with+ `workflow_step_moved`, naming who moved it. Do not retry; comment if+ something still needs attention.+- **The assignee owns the step.** Only the issue's assignee gets the step's+ instructions and commands. Any other agent on the issue — mentioned in a+ comment, say — sees the statuses and leaves them to the assignee unless+ explicitly asked to change them.+- **No `blocked` column.** When the workflow has none, comment why you cannot+ proceed, then use the "needs changes" status if the step has one, or leave+ the status as it is.diff --git a/server/internal/service/issue.go b/server/internal/service/issue.goindex 1a0369c9f6..d7e6b32756 100644--- a/server/internal/service/issue.go+++ b/server/internal/service/issue.go@@ -136,13 +136,6 @@ type IssueCreateOpts struct {// still resolving, then promotes the returned task after attachment binding.// Zero preserves the ordinary immediate enqueue path.AssignedAgentRunFireAt time.Time-- // HandoffNote, when set, renders the note that rides the run the create- // starts for its assignee. The HTTP handler sets it when a project- // workflow's starting step hands the new issue off, so the handler's run- // receives the step's instructions. It takes the created issue because the- // note names the issue's identifier. (MUL-7420)- HandoffNote func(issue db.Issue) string}// ErrActiveDuplicate signals that the duplicate guard found an active@@ -555,11 +548,7 @@ func (s *IssueService) Create(ctx context.Context, p IssueCreateParams, opts Isss.publishIssueCreated(issue, attachments, labels, p.CreatorType, actorID, opts)s.captureCreatedAnalytics(issue, p.CreatorType, actorID, opts)if opts.AssignedAgentRunFireAt.IsZero() {- handoffNote := ""- if opts.HandoffNote != nil {- handoffNote = opts.HandoffNote(issue)- }- assignedTaskID = s.maybeEnqueueOnAssign(ctx, issue, p.CreatorType, actorID, opts.AssignedAgentRunFireAt, handoffNote)+ assignedTaskID = s.maybeEnqueueOnAssign(ctx, issue, p.CreatorType, actorID, opts.AssignedAgentRunFireAt)}return IssueCreateResult{Issue: issue, Attachments: attachments, Labels: labels, AssignedTaskID: assignedTaskID}, nil@@ -865,7 +854,7 @@ func (s *IssueService) createWorkflow(ctx context.Context, qtx *db.Queries, p Isreturn def, err}-func (s *IssueService) maybeEnqueueOnAssign(ctx context.Context, issue db.Issue, creatorType, actorID string, agentRunFireAt time.Time, handoffNote string) pgtype.UUID {+func (s *IssueService) maybeEnqueueOnAssign(ctx context.Context, issue db.Issue, creatorType, actorID string, agentRunFireAt time.Time) pgtype.UUID {if !issue.AssigneeType.Valid || !issue.AssigneeID.Valid {return pgtype.UUID{}}@@ -889,9 +878,7 @@ func (s *IssueService) maybeEnqueueOnAssign(ctx context.Context, issue db.Issue,if admitted {var task db.AgentTaskQueuevar err error- if agentRunFireAt.IsZero() && handoffNote != "" {- task, err = s.TaskService.EnqueueTaskForIssueWithHandoff(ctx, issue, handoffNote, pgtype.UUID{})- } else if agentRunFireAt.IsZero() {+ if agentRunFireAt.IsZero() {task, err = s.TaskService.EnqueueTaskForIssue(ctx, issue)} else {task, err = s.TaskService.EnqueueDeferredChannelIssueTask(ctx, issue, agentRunFireAt)@@ -905,42 +892,11 @@ func (s *IssueService) maybeEnqueueOnAssign(ctx context.Context, issue db.Issue,}}if s.shouldEnqueueSquadLeaderOnAssign(ctx, issue) {- if handoffNote != "" {- s.enqueueSquadLeaderHandoffTask(ctx, issue, handoffNote)- } else {- s.enqueueSquadLeaderTask(ctx, issue, pgtype.UUID{}, creatorType, actorID)- }+ s.enqueueSquadLeaderTask(ctx, issue, pgtype.UUID{}, creatorType, actorID)}return pgtype.UUID{}}-// enqueueSquadLeaderHandoffTask starts a squad leader's run carrying a-// workflow step's handoff note, with the same pending-task dedup as-// enqueueSquadLeaderTask. (MUL-7420)-func (s *IssueService) enqueueSquadLeaderHandoffTask(ctx context.Context, issue db.Issue, handoffNote string) {- squad, err := s.Queries.GetSquadInWorkspace(ctx, db.GetSquadInWorkspaceParams{- ID: issue.AssigneeID,- WorkspaceID: issue.WorkspaceID,- })- if err != nil {- return- }- hasPending, err := s.Queries.HasPendingTaskForIssueAndAgent(ctx, db.HasPendingTaskForIssueAndAgentParams{- IssueID: issue.ID,- AgentID: squad.LeaderID,- HeadSha: headShaText(s.TaskService.ResolveIssueReviewSHA(ctx, issue.ID)),- })- if err != nil || hasPending {- return- }- if _, err := s.TaskService.EnqueueTaskForSquadLeaderWithHandoff(ctx, issue, squad.LeaderID, squad.ID, handoffNote, pgtype.UUID{}); err != nil {- slog.Warn("enqueue squad leader handoff task on create failed",- "issue_id", util.UUIDToString(issue.ID),- "squad_id", util.UUIDToString(squad.ID),- "error", err)- }-}-// shouldEnqueueAgentTaskWithQueries returns true when an issue create should// trigger the assigned agent. Backlog issues are skipped — backlog acts as a// parking lot for pre-assigning without immediate execution. The assignment