Files
ai-workflow-skill/packages/inbox-runtime/internal/cli/inbox/update.go
T

110 lines
3.1 KiB
Go

package inbox
import (
"fmt"
"ai-workflow-skill/packages/coord-core/protocol"
"ai-workflow-skill/packages/coord-core/store"
"github.com/spf13/cobra"
)
type updateOptions struct {
agent string
threadID string
status string
summary string
body string
bodyFile string
payloadJSON string
artifacts artifactOptions
}
func newUpdateCmd(root *rootOptions) *cobra.Command {
opts := &updateOptions{}
cmd := &cobra.Command{
Use: "update",
Short: "Append a progress or blocked update to a thread",
Long: helpLong(
"Use update to append worker progress inside one claimed thread.",
"in_progress means real work has started.",
"blocked means the worker cannot continue without a precise answer or dependency.",
"Blocked updates should include a concise summary and usually a payload_json question so the leader can answer deterministically.",
),
Example: ` inbox --db .agents/coord.db update --agent worker-a --thread thr_123 --status in_progress --summary "Reading current auth flow"
inbox --db .agents/coord.db update --agent worker-a --thread thr_123 --status blocked --summary "Need logging decision" --payload-json '{"question":"Use stdout or stderr?"}'`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
agent := opts.agent
if agent == "" {
agent = root.agent
}
if agent == "" {
return protocol.InvalidInput("agent is required", nil)
}
body, err := resolveBodyValue(opts.body, opts.bodyFile)
if err != nil {
return err
}
artifacts, err := resolveArtifacts(opts.artifacts)
if err != nil {
return err
}
sqlDB, err := openInboxDB(ctx, root.dbPath)
if err != nil {
return err
}
defer sqlDB.Close()
s := store.NewInboxStore(sqlDB)
thread, message, err := s.UpdateThreadStatus(ctx, store.UpdateInput{
ThreadID: opts.threadID,
Agent: agent,
Status: opts.status,
Summary: opts.summary,
Body: body,
PayloadJSON: opts.payloadJSON,
Artifacts: artifacts,
})
if err != nil {
return err
}
resp := protocol.Success{
OK: true,
Command: "update",
Data: map[string]any{
"thread": thread,
"message": message,
},
}
if root.json {
return protocol.WriteJSON(cmd.OutOrStdout(), resp)
}
_, err = fmt.Fprintf(cmd.OutOrStdout(), "updated thread %s to %s\n", thread.ThreadID, thread.Status)
return err
},
}
cmd.Flags().StringVar(&opts.agent, "agent", "", "Updating agent")
cmd.Flags().StringVar(&opts.threadID, "thread", "", "Thread ID")
cmd.Flags().StringVar(&opts.status, "status", "", "New status: in_progress or blocked")
cmd.Flags().StringVar(&opts.summary, "summary", "", "Short update summary")
cmd.Flags().StringVar(&opts.body, "body", "", "Update body")
cmd.Flags().StringVar(&opts.bodyFile, "body-file", "", "Read update body from file")
cmd.Flags().StringVar(&opts.payloadJSON, "payload-json", "", "Structured payload JSON string")
addArtifactFlags(cmd, &opts.artifacts)
_ = cmd.MarkFlagRequired("thread")
_ = cmd.MarkFlagRequired("status")
_ = cmd.MarkFlagRequired("summary")
return cmd
}