MCPcopy Create free account
hub / github.com/ByteYellow/AgentProvenance / sessionCmd

Function sessionCmd

internal/cli/session_cmd.go:11–153  ·  view source on GitHub ↗
(dataDir, daemonURL *string)

Source from the content-addressed store, hash-verified

9)
10
11func sessionCmd(dataDir, daemonURL *string) *cobra.Command {
12 var leaseID string
13 create := &cobra.Command{
14 Use: "create",
15 Short: "create a Docker-backed sandbox session",
16 RunE: func(cmd *cobra.Command, args []string) error {
17 if client, ok := daemonClient(*daemonURL); ok {
18 id, err := client.CreateSession(leaseID)
19 if err != nil {
20 return err
21 }
22 fmt.Fprintln(cmd.OutOrStdout(), id)
23 return nil
24 }
25 svc, closeFn, err := controlSvc(*dataDir)
26 if err != nil {
27 return err
28 }
29 defer closeFn()
30 id, err := svc.CreateSession(leaseID)
31 if err != nil {
32 return err
33 }
34 fmt.Fprintln(cmd.OutOrStdout(), id)
35 return nil
36 },
37 }
38 create.Flags().StringVar(&leaseID, "lease", "", "lease id")
39 _ = create.MarkFlagRequired("lease")
40 list := &cobra.Command{
41 Use: "list",
42 Short: "list sandbox sessions",
43 RunE: func(cmd *cobra.Command, args []string) error {
44 sessions, err := listSessions(*dataDir, *daemonURL)
45 if err != nil {
46 return err
47 }
48 w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
49 fmt.Fprintln(w, "ID\tSTATUS\tRUN\tRUNTIME\tCONTAINER\tRESUMED_FROM\tWORKSPACE\tSTARTUP_MS")
50 for _, session := range sessions {
51 fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\n", session.ID, session.Status, session.RunID, session.RuntimeName, short(session.ContainerID), short(session.ResumedFromSnapshotID), session.WorkspacePath, session.StartupColdMS)
52 }
53 return w.Flush()
54 },
55 }
56 inspect := &cobra.Command{
57 Use: "inspect <session_id>",
58 Short: "inspect a sandbox session",
59 Args: cobra.ExactArgs(1),
60 RunE: func(cmd *cobra.Command, args []string) error {
61 session, err := inspectSession(*dataDir, *daemonURL, args[0])
62 if err != nil {
63 return err
64 }
65 fmt.Fprintf(cmd.OutOrStdout(), "id=%s\nlease_id=%s\nrun_id=%s\nruntime=%s\ncontainer_id=%s\nworkspace=%s\nstatus=%s\nparent_snapshot_id=%s\nresumed_from_snapshot_id=%s\nstartup_cold_ms=%d\ncreated_at=%s\nupdated_at=%s\n",
66 session.ID, session.LeaseID, session.RunID, session.RuntimeName, session.ContainerID, session.WorkspacePath, session.Status, session.ParentSnapshotID, session.ResumedFromSnapshotID, session.StartupColdMS, session.CreatedAt, session.UpdatedAt)
67 return nil
68 },

Callers 1

NewRootCommandFunction · 0.85

Calls 10

daemonClientFunction · 0.85
controlSvcFunction · 0.85
listSessionsFunction · 0.85
shortFunction · 0.85
inspectSessionFunction · 0.85
FlushMethod · 0.80
CreateSessionMethod · 0.65
StopSessionMethod · 0.45
SetSessionCPUProfileMethod · 0.45
RemoveSessionMethod · 0.45

Tested by

no test coverage detected