Add inbox send fetch claim show commands

This commit is contained in:
2026-03-19 03:02:21 +08:00
parent 7b35f4dc5f
commit e9792dee88
7 changed files with 1085 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
package inbox
import (
"fmt"
"ai-workflow-skill/internal/db"
"ai-workflow-skill/internal/protocol"
"ai-workflow-skill/internal/store"
"github.com/spf13/cobra"
)
type showOptions struct {
threadID string
}
func newShowCmd(root *rootOptions) *cobra.Command {
opts := &showOptions{}
cmd := &cobra.Command{
Use: "show",
Short: "Show one thread with message history",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
sqlDB, err := db.Open(ctx, root.dbPath)
if err != nil {
return err
}
defer sqlDB.Close()
s := store.NewInboxStore(sqlDB)
detail, err := s.GetThread(ctx, opts.threadID)
if err != nil {
return err
}
resp := protocol.Success{
OK: true,
Command: "show",
Data: map[string]any{
"thread": detail.Thread,
"messages": detail.Messages,
},
}
if root.json {
return protocol.WriteJSON(cmd.OutOrStdout(), resp)
}
if _, err := fmt.Fprintf(cmd.OutOrStdout(), "%s\t%s\t%s\n", detail.Thread.ThreadID, detail.Thread.Status, detail.Thread.Subject); err != nil {
return err
}
for _, message := range detail.Messages {
if _, err := fmt.Fprintf(cmd.OutOrStdout(), "- %s\t%s\t%s\n", message.MessageID, message.Kind, message.Summary); err != nil {
return err
}
}
return nil
},
}
cmd.Flags().StringVar(&opts.threadID, "thread", "", "Thread ID")
_ = cmd.MarkFlagRequired("thread")
return cmd
}