Skip to content

feat(tfe): add list_run_comments tool (#347)#352

Open
ChrisJr404 wants to merge 2 commits into
hashicorp:mainfrom
ChrisJr404:feat/list-run-comments-tool-347
Open

feat(tfe): add list_run_comments tool (#347)#352
ChrisJr404 wants to merge 2 commits into
hashicorp:mainfrom
ChrisJr404:feat/list-run-comments-tool-347

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #347.

`action_run` already lets agents post a run comment when applying / discarding / canceling, but there was no way to read the existing comments back. `get_run_details` returns the comment ID, but no body — so an agent inspecting a run can see that humans left context but can't act on it.

This wires the existing TFE Comments API (`GET /runs/{run_id}/comments`, surfaced via `go-tfe`'s `Comments.List`) as a new `list_run_comments` tool. Shape mirrors `list_runs`:

```json
// list_run_comments({"run_id": "run-CZcmD7eagjhyX0vN"})
{
"items": [
{"id": "comment-XXX", "body": "Approved by @sre, retrying after the 503"},
{"id": "comment-YYY", "body": "..."}
]
}
```

  • Read-only and non-destructive annotations.
  • Structured `RunCommentSummary` / `RunCommentList` types so future field additions (resolved-by, created-at) are a passthrough rather than a struct rewrite.

Wiring

Three files:

  • New `pkg/tools/tfe/list_run_comments.go` (mirrors `list_runs.go` shape).
  • `pkg/toolsets/mapping.go` — `list_run_comments → Terraform` toolset.
  • `pkg/tools/dynamic_tool.go` — conditional registration alongside `list_runs`.

What's not in scope

  • Pagination. The upstream `Comments.List` endpoint returns the full list in a single response (the go-tfe `CommentList` type embeds `*Pagination` but the endpoint doesn't actually populate page cursors). Output is wrapped in a struct anyway so pagination is a passthrough add later if upstream gets it.
  • Read-by-id. `go-tfe` exposes `Comments.Read(commentID)` too, but the issue's ask is the list path. Happy to add a `get_run_comment` companion if reviewers want it.

Test plan

  • `go build ./...` clean
  • `go vet ./...` clean
  • `go test ./pkg/tools/tfe/... ./pkg/toolsets/...` ok
  • (For maintainer) — exercise against a real TFC org with a run that has 1+ comments and confirm the bodies render correctly. The go-tfe lib is already used heavily in this repo so the network path itself is well-trodden.

Note on duplication

@vavdoshka offered on the issue to contribute this — happy to defer if they were already partway through. Didn't see an open PR or a draft branch from them, so I went ahead. If you'd rather their PR land instead, totally fine to close this one.

Closes the read-side gap on the run-comment surface. `action_run`
already lets agents post a comment when applying / discarding /
canceling a run, but until now there was no way to read the existing
comments back: an agent inspecting a run via `get_run_details` could
see that comments existed (the workspace comment ID is returned) but
couldn't retrieve their bodies, which limits its ability to act on
context left by humans or other automation.

The new tool wraps the existing TFE Comments API endpoint
(`GET /runs/{run_id}/comments`) via go-tfe's Comments.List. It takes
a single required `run_id`, returns each comment's id and body in a
RunCommentList projection, and follows the same shape conventions as
list_runs:

  - read-only annotation (WithReadOnlyHintAnnotation true)
  - non-destructive annotation
  - structured RunCommentSummary / RunCommentList types so future
    field additions (resolved-by, created-at) are passthrough

Wired through the standard places — toolsets/mapping.go for toolset
gating, tools/dynamic_tool.go for the conditional registration on
the Terraform toolset.

No pagination today because the upstream Comments.List endpoint
returns the full list in one response (the go-tfe CommentList
type embeds *Pagination but the endpoint doesn't actually populate
page cursors). Wrapping in a struct anyway so it stays
forward-compatible if pagination is later wired up.

  go build ./...                               → clean
  go vet ./...                                 → clean
  go test ./pkg/tools/tfe/... ./pkg/toolsets/... → ok
@ChrisJr404 ChrisJr404 requested a review from a team as a code owner May 4, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add tool to read/list run comments

1 participant