Skip to content

feat(cli): add exp task logs - #19915

Merged
DanielleMaywood merged 2 commits into
mainfrom
danielle/tasks/cli-logs
Sep 26, 2025
Merged

DanielleMaywood merged 2 commits into
mainfrom
danielle/tasks/cli-logs

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Sep 22, 2025 •

Copy link
Copy Markdown
Contributor

@DanielleMaywood
DanielleMaywood force-pushed the danielle/tasks/cli-logs branch 11 times, most recently from d0e4d4c to cc041e5 Compare September 25, 2025 15:43
There isn't a supporting API for this yet. This is a skeleton
implementation prepared in advance for the API being available.
Comment thread cli/exp_task_logs.go Outdated
Comment on lines +49 to +54
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)
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is fine!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread cli/exp_task.go
Comment on lines 15 to 22
Children: []*serpent.Command{
r.taskList(),
r.taskCreate(),
r.taskStatus(),
r.taskDelete(),
r.taskList(),
r.taskLogs(),
r.taskSend(),
r.taskStatus(),
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by: sort

@DanielleMaywood
DanielleMaywood marked this pull request as ready for review September 25, 2025 15:46
Comment thread cli/exp_task_logs.go Outdated
Comment on lines +49 to +54
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)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is fine!

Comment thread cli/exp_task_logs.go
Comment on lines +33 to +42
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
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: at this point, we can probably use some kind of helper taskByNameOrID

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. I'm curious about what it would look like though because I don't want to make an unnecessary API call.

Comment thread cli/exp_task_logs.go Outdated
return xerrors.Errorf("get task logs: %w", err)
}

enc := json.NewEncoder(inv.Stdout)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: we could possibly use a cli.OutputFormatter and emit the logs either as text or JSON

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used that before, I'll take a look at.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

Note: with the cli.OutputFormatter the JSON output will be an array now.

@DanielleMaywood
DanielleMaywood merged commit b7e0b2a into main Sep 26, 2025
@DanielleMaywood
DanielleMaywood deleted the danielle/tasks/cli-logs branch September 26, 2025 09:37
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tasks CLI: Add logs command

3 participants