Repository navigation
feat(cli): add exp task logs - #19915
Conversation
d0e4d4c to
cc041e5
Compare
There isn't a supporting API for this yet. This is a skeleton implementation prepared in advance for the API being available.
cc041e5 to
9ae4d44
Compare
| enc := json.NewEncoder(inv.Stdout) | ||
| for _, log := range logs.Logs { | ||
| if err := enc.Encode(log); err != nil { | ||
| return xerrors.Errorf("encode task log: %w", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
Q: Do we want this? This will spit out a json object per log line, each separated by a newline. This is easily consumed by jq and other tools. I'm happy to change this if desired.
There was a problem hiding this comment.
I think it's very usable! This way I can get just the last two entries, my input and the agents output.
❯ ./coder exp tasks logs task-foo-bar-15e4 | tail -n2 | jq -r '.type, .content'
input
run echo "are we there yet?"
output
● coder - coder_report_task (MCP)(summary: "Running echo command
with quoted string as requested",
link: "https://coder.com", state:
"working")
⎿ {
"message": "Thanks for reporting!"
}
● Bash(echo "are we there yet?")
⎿ are we there yet?
● are we there yet?
| Children: []*serpent.Command{ | ||
| r.taskList(), | ||
| r.taskCreate(), | ||
| r.taskStatus(), | ||
| r.taskDelete(), | ||
| r.taskList(), | ||
| r.taskLogs(), | ||
| r.taskSend(), | ||
| r.taskStatus(), | ||
| }, |
There was a problem hiding this comment.
drive-by: sort
| enc := json.NewEncoder(inv.Stdout) | ||
| for _, log := range logs.Logs { | ||
| if err := enc.Encode(log); err != nil { | ||
| return xerrors.Errorf("encode task log: %w", err) | ||
| } | ||
| } |
| if id, err := uuid.Parse(task); err == nil { | ||
| taskID = id | ||
| } else { | ||
| ws, err := namedWorkspace(ctx, client, task) | ||
| if err != nil { | ||
| return xerrors.Errorf("resolve task %q: %w", task, err) | ||
| } | ||
|
|
||
| taskID = ws.ID | ||
| } |
There was a problem hiding this comment.
suggestion: at this point, we can probably use some kind of helper taskByNameOrID
There was a problem hiding this comment.
Possibly. I'm curious about what it would look like though because I don't want to make an unnecessary API call.
| return xerrors.Errorf("get task logs: %w", err) | ||
| } | ||
|
|
||
| enc := json.NewEncoder(inv.Stdout) |
There was a problem hiding this comment.
suggestion: we could possibly use a cli.OutputFormatter and emit the logs either as text or JSON
There was a problem hiding this comment.
I've never used that before, I'll take a look at.
There was a problem hiding this comment.
Addressed in: refactor: use cliu.OutputFormatter
johnstcn
left a comment
There was a problem hiding this comment.
🚢
Note: with the cli.OutputFormatter the JSON output will be an array now.
Closes coder/internal#894