molecule-core/platform/cmd/cli/cmd_events.go
Hongming Wang 24fec62d7f initial commit — Molecule AI platform
Forked clean from public hackathon repo (Starfire-AgentTeam, BSL 1.1)
with full rebrand to Molecule AI under github.com/Molecule-AI/molecule-monorepo.

Brand: Starfire → Molecule AI.
Slug: starfire / agent-molecule → molecule.
Env vars: STARFIRE_* → MOLECULE_*.
Go module: github.com/agent-molecule/platform → github.com/Molecule-AI/molecule-monorepo/platform.
Python packages: starfire_plugin → molecule_plugin, starfire_agent → molecule_agent.
DB: agentmolecule → molecule.

History truncated; see public repo for prior commits and contributor
attribution. Verified green: go test -race ./... (platform), pytest
(workspace-template 1129 + sdk 132), vitest (canvas 352), build (mcp).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 11:55:37 -07:00

74 lines
1.5 KiB
Go

package main
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
func buildEventsCmd() *cobra.Command {
var (
workspaceID string
limit int
)
cmd := &cobra.Command{
Use: "events",
Short: "List recent platform events",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
client := NewPlatformClient(baseURL())
var (
events []EventInfo
err error
)
if workspaceID != "" {
events, err = client.FetchEventsByWorkspace(workspaceID)
} else {
events, err = client.FetchEvents()
}
if err != nil {
return err
}
// Apply limit (most recent first)
if limit > 0 && len(events) > limit {
events = events[len(events)-limit:]
}
if flagJSON {
return printJSON(events)
}
tw := newTabWriter()
fmt.Fprintln(tw, "TIME\tEVENT\tWORKSPACE\tID")
fmt.Fprintln(tw, strings.Repeat("-", 8)+"\t"+
strings.Repeat("-", 25)+"\t"+
strings.Repeat("-", 8)+"\t"+
strings.Repeat("-", 8))
// Print newest first
for i := len(events) - 1; i >= 0; i-- {
e := events[i]
wsID := ""
if e.WorkspaceID != nil {
wsID = shortID(*e.WorkspaceID)
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n",
e.CreatedAt.Local().Format("15:04:05"),
e.EventType,
wsID,
shortID(e.ID),
)
}
tw.Flush()
return nil
},
}
cmd.Flags().StringVarP(&workspaceID, "workspace", "w", "", "Filter by workspace ID")
cmd.Flags().IntVarP(&limit, "limit", "l", 50, "Maximum number of events to show (0 = all)")
return cmd
}