Compare commits

...
Author SHA1 Message Date
weichen 1a5ef6b75c Anchor work decisions to a reserved follow-up run identity
Why: Reconcile interrupted dispatch without spending another model request.

Evidence: Core package tests pass locally; integration exercises acceptance and recovery.

Impact: Add one optional persisted run identifier.

Refs: feature/workbench-flow-completion
2026-10-15 06:53:28 +00:00
weichen fcfe8149bd Verify durable work results and legacy card compatibility
Why: Retain full results and exact answers across persistence and reload.

Evidence: go test ./... passed locally, including full-tail and legacy JSON coverage.

Impact: Add contract roundtrip tests and a guarded dispatching state.

Refs: feature/workbench-flow-completion
2026-10-15 06:49:33 +00:00
weichen 00f182611c Define durable nonblocking work card snapshots
Why: Keep background results and optional decisions outside the foreground conversation lock.

Evidence: Core package tests and combination checks are recorded in the Dev task.

Impact: Add an optional backward-compatible work card payload without a database migration.

Refs: feature/workbench-flow-completion
2026-10-15 06:46:23 +00:00
3 changed files with 107 additions and 14 deletions
+46 -13
View File
@@ -12,19 +12,52 @@ import "time"
type ActivityCard struct {
ID ID `json:"id"`
// ProjectID/ConversationID 定位归属;ConversationID 为空表示项目级卡片(远期跨会话收件箱)。
ProjectID ID `json:"projectId"`
ConversationID ID `json:"conversationId,omitempty"`
SourceRunID ID `json:"sourceRunId,omitempty"` // 溯源:产生卡片的 run
AnchorMessageID ID `json:"anchorMessageId,omitempty"` // 互定位:出生消息(↙ 定位到对话)
Kind CardKind `json:"kind"`
Title string `json:"title"`
Status CardStatus `json:"status"`
Tone string `json:"tone,omitempty"` // ok | warn | danger | info
Body []UINode `json:"body,omitempty"`
Actions []UIAction `json:"actions,omitempty"` // 走命令总线;未绑定 command 降级为发消息
Pinned bool `json:"pinned,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ProjectID ID `json:"projectId"`
ConversationID ID `json:"conversationId,omitempty"`
SourceRunID ID `json:"sourceRunId,omitempty"` // 溯源:产生卡片的 run
AnchorMessageID ID `json:"anchorMessageId,omitempty"` // 互定位:出生消息(↙ 定位到对话)
Kind CardKind `json:"kind"`
Title string `json:"title"`
Status CardStatus `json:"status"`
Tone string `json:"tone,omitempty"` // ok | warn | danger | info
Body []UINode `json:"body,omitempty"`
Actions []UIAction `json:"actions,omitempty"` // 走命令总线;未绑定 command 降级为发消息
Pinned bool `json:"pinned,omitempty"`
Work *WorkCard `json:"work,omitempty"` // optional background-work snapshot; never a foreground approval
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// WorkCard keeps the complete saved result and an optional, non-blocking next step
// on the original task. Reading and answering do not change the result version.
type WorkCard struct {
Result string `json:"result,omitempty"`
ResultVersion int `json:"resultVersion"`
ReadVersion int `json:"readVersion"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
Decision *WorkDecision `json:"decision,omitempty"`
}
type WorkDecision struct {
RunID ID `json:"runId,omitempty"` // reserved child identity; reconciles acceptance after restart without rerunning
Mode string `json:"mode"` // single | multiple
State string `json:"state"` // open | deferred | dispatching | submitted
Options []WorkOption `json:"options,omitempty"`
SelectedIDs []string `json:"selectedIds,omitempty"`
FreeText string `json:"freeText,omitempty"`
RespondedAt *time.Time `json:"respondedAt,omitempty"`
}
type WorkOption struct {
ID string `json:"id"`
Label string `json:"label"`
}
// WorkCardAction is version-fenced. Presentation-only opens never mark a result read.
type WorkCardAction struct {
ResultVersion int `json:"resultVersion"`
SelectedIDs []string `json:"selectedIds,omitempty"`
FreeText string `json:"freeText,omitempty"`
}
type CardKind string
+46
View File
@@ -0,0 +1,46 @@
package core
import (
"encoding/json"
"strings"
"testing"
"time"
)
func TestWorkCardSurvivesPersistedSnapshot(t *testing.T) {
completed := time.Date(2026, 10, 15, 6, 0, 0, 0, time.UTC)
card := ActivityCard{ID: "card_work", Status: CardDone, Work: &WorkCard{
Result: strings.Repeat("完整结果\n", 200) + "最后一项依据",
ResultVersion: 2, ReadVersion: 1, CompletedAt: &completed,
Decision: &WorkDecision{Mode: "multiple", State: "submitted", Options: []WorkOption{{ID: "summary", Label: "生成摘要"}},
SelectedIDs: []string{"summary"}, FreeText: "请突出关键限制", RespondedAt: &completed},
}}
data, err := json.Marshal(card)
if err != nil {
t.Fatal(err)
}
var restored ActivityCard
if err := json.Unmarshal(data, &restored); err != nil {
t.Fatal(err)
}
if restored.Work == nil || restored.Work.Result != card.Work.Result || restored.Work.ReadVersion != 1 || restored.Work.ResultVersion != 2 {
t.Fatalf("complete result or unread version lost: %+v", restored.Work)
}
if d := restored.Work.Decision; d.State != "submitted" || d.SelectedIDs[0] != "summary" || d.FreeText != "请突出关键限制" || !d.RespondedAt.Equal(completed) {
t.Fatalf("decision history lost: %+v", d)
}
}
func TestLegacyCardOmitsOptionalWork(t *testing.T) {
var legacy ActivityCard
if err := json.Unmarshal([]byte(`{"id":"old","status":"resolved","body":[{"type":"markdown","markdown":"保留历史"}]}`), &legacy); err != nil {
t.Fatal(err)
}
data, err := json.Marshal(legacy)
if err != nil {
t.Fatal(err)
}
if legacy.Work != nil || strings.Contains(string(data), `"work"`) || legacy.Body[0].Markdown != "保留历史" {
t.Fatalf("legacy payload changed: %s", data)
}
}
+15 -1
View File
@@ -150,7 +150,21 @@ export interface ActivityCard {
sourceRunId?: ID; anchorMessageId?: ID;
kind: CardKind; title: string; status: CardStatus; tone?: string;
body?: UINode[]; actions?: { id: string; label: string; style?: 'primary' | 'default' | 'danger'; command?: string }[];
pinned?: boolean; createdAt: string; updatedAt: string;
pinned?: boolean; createdAt: string; updatedAt: string; work?: WorkCard;
}
export interface WorkCard {
result?: string; resultVersion: number; readVersion: number; completedAt?: string;
decision?: WorkDecision;
}
export interface WorkDecision {
runId?: ID;
mode: 'single' | 'multiple'; state: 'open' | 'deferred' | 'dispatching' | 'submitted';
options?: { id: string; label: string }[];
selectedIds?: string[]; freeText?: string; respondedAt?: string;
}
export interface WorkCardAction {
resultVersion: number; selectedIds?: string[]; freeText?: string;
}
export interface CardPayload { card: ActivityCard }