f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
// ABOUTME: `session tool-calls <id>` subcommand — flattens every
|
|
// ABOUTME: tool call in a session into a JSON list or tab-aligned
|
|
// ABOUTME: human table.
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"text/tabwriter"
|
|
|
|
"github.com/spf13/cobra"
|
|
"go.kenn.io/agentsview/internal/service"
|
|
)
|
|
|
|
func newSessionToolCallsCommand() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "tool-calls <id>",
|
|
Short: "List tool calls made during a session",
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
svc, cleanup, err := resolveService(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer cleanup()
|
|
|
|
id, err := resolveServiceSessionID(cmd.Context(), svc, args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
list, err := svc.ToolCalls(cmd.Context(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if outputFormat(cmd) == "json" {
|
|
return json.NewEncoder(cmd.OutOrStdout()).Encode(list)
|
|
}
|
|
return printToolCallsHuman(cmd.OutOrStdout(), list)
|
|
},
|
|
}
|
|
}
|
|
|
|
// printToolCallsHuman writes a tabwriter-aligned table. Timestamp
|
|
// is trimmed to 19 chars (YYYY-MM-DDTHH:MM:SS). Session-derived
|
|
// fields are sanitized for terminal safety.
|
|
func printToolCallsHuman(w io.Writer, list *service.ToolCallList) error {
|
|
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
|
|
fmt.Fprintln(tw, "ORDINAL\tTIMESTAMP\tTOOL\tCATEGORY")
|
|
for _, tc := range list.ToolCalls {
|
|
ts := tc.Timestamp
|
|
if len(ts) >= 19 {
|
|
ts = ts[:19]
|
|
}
|
|
fmt.Fprintf(tw, "%d\t%s\t%s\t%s\n",
|
|
tc.Ordinal,
|
|
sanitizeTerminal(ts),
|
|
sanitizeTerminal(tc.ToolName),
|
|
sanitizeTerminal(tc.Category))
|
|
}
|
|
return tw.Flush()
|
|
}
|