diff options
Diffstat (limited to 'internal/executor/channel.go')
| -rw-r--r-- | internal/executor/channel.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/internal/executor/channel.go b/internal/executor/channel.go index 30d826c..ef64ede 100644 --- a/internal/executor/channel.go +++ b/internal/executor/channel.go @@ -2,12 +2,15 @@ package executor import ( "context" + "database/sql" "encoding/json" + "errors" "sync" "time" "github.com/thepeterstone/claudomator/internal/agentchannel" "github.com/thepeterstone/claudomator/internal/event" + "github.com/thepeterstone/claudomator/internal/story" "github.com/thepeterstone/claudomator/internal/task" "github.com/google/uuid" ) @@ -29,12 +32,24 @@ type AgentChannel = agentchannel.AgentChannel type SubtaskSpec = agentchannel.SubtaskSpec type BlockedError = agentchannel.BlockedError +// EpicProposal is the Phase 7c sibling of SubtaskSpec above: an alias so +// existing code that refers to executor.EpicProposal (agentmcp.go, tests) +// compiles against the same type agentchannel.AgentChannel.ProposeEpic uses. +type EpicProposal = agentchannel.EpicProposal + var ErrAgentBlocked = agentchannel.ErrAgentBlocked // channelStore is the subset of storage the default channel needs. type channelStore interface { CreateTask(t *task.Task) error CreateEvent(e *event.Event) error + // CreateEpic, GetEpicByName, GetStory, and UpdateStory back + // storeChannel.ProposeEpic (Phase 7c): matching an existing epic by exact + // name (or creating a new one), then attaching the given stories to it. + CreateEpic(e *story.Epic) error + GetEpicByName(name string) (*story.Epic, error) + GetStory(id string) (*story.Story, error) + UpdateStory(st *story.Story) error } // pendingAsker is implemented by channels that buffer an ask_user call so the @@ -153,4 +168,59 @@ func (c *storeChannel) RecordProgress(_ context.Context, message string) error { Actor: event.ActorAgent, Payload: payload, }) +} + +// ProposeEpic groups spec.StoryIDs under a new or existing epic, matched by +// exact spec.Name — the simplest reasonable de-dup; a fuzzy-matching pass is +// left to a later phase if it turns out to matter. Story IDs that don't +// resolve are skipped (not fatal to the call): one bad ID shouldn't prevent +// grouping the rest. The event is attached to the epic's own ID, matching +// the story orchestrator's convention (KindEvalVerdict/KindArbitrationDecided) +// of attaching planning-layer ceremony events to the entity they're about +// rather than to a task ID — events.task_id has no enforced FK, so this is +// exactly the tolerance already built in for that. +func (c *storeChannel) ProposeEpic(_ context.Context, spec agentchannel.EpicProposal) (string, error) { + epic, err := c.store.GetEpicByName(spec.Name) + if err != nil { + if !errors.Is(err, sql.ErrNoRows) { + return "", err + } + epic = &story.Epic{ + ID: uuid.NewString(), + Name: spec.Name, + Description: spec.Description, + DiscoverySource: "agent", + } + if err := c.store.CreateEpic(epic); err != nil { + return "", err + } + } + + grouped := make([]string, 0, len(spec.StoryIDs)) + for _, sid := range spec.StoryIDs { + st, err := c.store.GetStory(sid) + if err != nil { + continue // unresolved story ID: skip, don't fail the whole call + } + st.EpicID = epic.ID + if err := c.store.UpdateStory(st); err != nil { + continue + } + grouped = append(grouped, sid) + } + + payload, _ := json.Marshal(struct { + EpicID string `json:"epic_id"` + Name string `json:"name"` + StoryIDs []string `json:"story_ids"` + }{EpicID: epic.ID, Name: epic.Name, StoryIDs: grouped}) + if err := c.store.CreateEvent(&event.Event{ + TaskID: epic.ID, + Kind: event.KindEpicProposed, + Actor: event.ActorAgent, + Payload: payload, + }); err != nil { + return epic.ID, err + } + return epic.ID, nil }
\ No newline at end of file |
