Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
【架构优化】合并 tracker 创建结果的对象/数组首元素解码为 decodeCreatedRecord (#639) (#642)
fx-kurumid31b084b5943
diff --git a/internal/tracker/decode_created_record_test.go b/internal/tracker/decode_created_record_test.gonew file mode 100644index 00000000..190156b3--- /dev/null+++ b/internal/tracker/decode_created_record_test.go@@ -0,0 +1,52 @@+package tracker++import (+ "encoding/json"+ "testing"+)++func TestDecodeCreatedRecordObject(t *testing.T) {+ gi, err := decodeCreatedRecord[gongfengIssue](`{"id":7,"iid":3,"title":"t","state":"opened"}`)+ if err != nil {+ t.Fatalf("decode object: %v", err)+ }+ if gi.ID != 7 || gi.IID != 3 || gi.Title != "t" || gi.State != "opened" {+ t.Fatalf("unexpected issue: %+v", gi)+ }+}++func TestDecodeCreatedRecordArrayFirstElement(t *testing.T) {+ st, err := decodeCreatedRecord[tapdStory](`[{"id":"1001","name":"first"},{"id":"1002","name":"second"}]`)+ if err != nil {+ t.Fatalf("decode array: %v", err)+ }+ if st.ID != "1001" || st.Name != "first" {+ t.Fatalf("expected first element, got %+v", st)+ }+}++func TestDecodeCreatedRecordFailuresReturnObjectError(t *testing.T) {+ for name, raw := range map[string]string{+ "empty array": `[]`,+ "invalid json": `not json`,+ "scalar": `"created"`,+ } {+ t.Run(name, func(t *testing.T) {+ var want gongfengIssue+ wantErr := json.Unmarshal([]byte(raw), &want)+ if wantErr == nil {+ t.Fatalf("test payload %q unexpectedly decodes as an object", raw)+ }+ gi, err := decodeCreatedRecord[gongfengIssue](raw)+ if err == nil {+ t.Fatalf("expected error, got %+v", gi)+ }+ if err.Error() != wantErr.Error() {+ t.Fatalf("error = %q, want the object decode error %q", err, wantErr)+ }+ if gi.ID != 0 || gi.IID != 0 || gi.Title != "" {+ t.Fatalf("expected zero value on failure, got %+v", gi)+ }+ })+ }+}diff --git a/internal/tracker/service.go b/internal/tracker/service.goindex 030d476d..18e43a37 100644--- a/internal/tracker/service.go+++ b/internal/tracker/service.go@@ -584,14 +584,9 @@ func (s *Service) CreateGongfengIssue(store IssueStoreAdapter, issue domain.Issureturn issue, err}- var gi gongfengIssue- if err := json.Unmarshal([]byte(raw), &gi); err != nil {- var arr []gongfengIssue- if err2 := json.Unmarshal([]byte(raw), &arr); err2 == nil && len(arr) > 0 {- gi = arr[0]- } else {- return issue, fmt.Errorf("decode created issue: %w", err)- }+ gi, err := decodeCreatedRecord[gongfengIssue](raw)+ if err != nil {+ return issue, fmt.Errorf("decode created issue: %w", err)}issue.Source = "gongfeng"@@ -1338,14 +1333,9 @@ func (s *Service) CreateTAPDStory(store IssueStoreAdapter, issue domain.Issue) (return issue, err}- var st tapdStory- if err := json.Unmarshal([]byte(raw), &st); err != nil {- var arr []tapdStory- if err2 := json.Unmarshal([]byte(raw), &arr); err2 == nil && len(arr) > 0 {- st = arr[0]- } else if extracted := extractTAPDStory(raw); extracted.ID != "" {- st = extracted- } else {+ st, err := decodeCreatedRecord[tapdStory](raw)+ if err != nil {+ if st = extractTAPDStory(raw); st.ID == "" {return issue, fmt.Errorf("decode created story: %w", err)}}@@ -1551,6 +1541,24 @@ func collectTAPDStories(value any) []tapdStory {return out}+// decodeCreatedRecord decodes the payload a tracker MCP create tool returns:+// a single object, or an array whose first element is the created record.+// When neither shape fits it returns the zero value and the error from+// decoding the payload as a single object.+func decodeCreatedRecord[T any](raw string) (T, error) {+ var record T+ err := json.Unmarshal([]byte(raw), &record)+ if err == nil {+ return record, nil+ }+ var records []T+ if json.Unmarshal([]byte(raw), &records) == nil && len(records) > 0 {+ return records[0], nil+ }+ var zero T+ return zero, err+}+func extractTAPDStory(raw string) tapdStory {var nested struct {Data struct {