Skip to content

feat(pr): pr comment and gh issue comment run gh #4855

Description

@dan-petty

Problem or Motivation

No devops command posts a comment. devops pr comment and devops gh pr comment failed 42 times (Claude 41 in 9 sessions, other tools 1), and devops gh issues comment failed 1 time. 39 of the 40 pr comment failures went on with devops gh api -X POST. In the Claude logs, devops gh api posted 959 issue comments in 29 sessions, with the body in a shell argument or in the -F body=@file form that agents must look up.

Tracker #4833, child 9. The owner asked on 2026-11-11 to fix the devops gh issue name and to record such errors for a later analysis of missing flags, features and aliases. The counts come from a study of Claude Code, Kilo, Antigravity and Loki records from 2026-09-23 to 2026-11-11.

Proposed Solution & Architectural Design

Add devops pr comment <number> and devops gh issue comment <number>, as gh has them, with --body/-b, --body-file/-F (helper of item pr-body-file) and --repo/-R. Each sends one POST repos/:owner/:repo/issues/:n/comments through the paced devops gh session and prints the URL of the comment. --dry-run lists the request and sends nothing. Register the MCP tools only for the roles that may write (ai/mcp/roles.py) and the dry-run class (#3296). devops pr threads reply does not change.

Target Subsystem

SDLC, Git & PR Governance (devops pr and devops gh issue).

Existing Tool Considered

gh's pr comment and issue comment names and flags. The GitHub REST endpoint POST repos/:owner/:repo/issues/:n/comments through the paced devops gh session.

Acceptance Criteria

devops pr comment 1 --body-file c.md --dry-run lists 1 POST and sends 0 requests. A test with the session stub posts 1 comment and prints its URL, for both commands. --body with --body-file exits 2. The MCP tool listing holds the two tools only in the write roles.

Dependencies

Merge first: #4835, #4852.

Source: #4833

Alternatives check of 2026-11-24: in-use.
The repository already uses this tool.
Tool: cli/cli (https://github.com/cli/cli), MIT, last activity 2026-11-24, maintained.
Reason: The gh manual shows gh pr comment with -b/--body, -F/--body-file and inherited -R/--repo, and gh issue comment is the same command for issues, so the item only needs to wrap an existing, already-used tool.

Covers:

  • Comment on a pull request or an issue
  • Body from text or from a file
  • Another repository through -R/--repo
  • Prints the URL of the new comment

Lacks:

  • Dry-run request plan that sends nothing
  • Text-only MCP tools gated to the write role
  • Exit 2 when both body flags are given

Proposed design

Problem statement

No devops command posts a comment. devops pr comment, devops gh pr comment and devops gh issue comment do not exist. The logs record 42 failed pr comment or gh pr comment calls and 1 failed gh issues comment call, and 39 of the 40 pr comment failures went on with devops gh api -X POST, with the body in a shell argument or in a file flag that agents must look up. The reply of 2026-11-26 shows the same failure on devops gh pr comment 92 -R dan-petty/devtools --body-file <file>. This item adds the comment commands as wrappers around gh pr comment and gh issue comment: one body source, one gh run, the comment URL on stdout, a dry run that prints the POST request and the gh command, and a text-only MCP tool in the write role.

Acceptance criteria

Requirement: gh command names and flags

The comment commands SHALL use gh's names and flags: devops pr comment and devops gh issue comment, with --body/-b, --body-file/-F, --repo/-R and --dry-run, and the command SHALL also be reachable as devops gh pr comment through the existing mount of the pr app.

Scenario: Help lists the gh names and flags

  • WHEN A test runs devops pr comment --help, devops gh pr comment --help and devops gh issue comment --help with CliRunner.
  • THEN Each command exits 0, and its output lists --body, --body-file, --repo and --dry-run, with the short flags -b, -F and -R.

Requirement: Body flags forwarded to gh

Each comment command SHALL forward --body and --body-file to gh in their long forms, and SHALL exit 2 with a bad-parameter error that names both flags when both are given.

Scenario: Two body sources are refused

  • WHEN A test runs each comment command with 1 --body text --body-file c.md.
  • THEN Each command exits 2, prints an error that names --body and --body-file, and the process stub records no gh invocation.

Requirement: Missing body source

Each comment command SHALL exit 2 when neither --body nor --body-file is given, because gh prompts for the comment text when no flag supplies a body.

Scenario: No body source is refused

  • WHEN A test runs each comment command with 1 only.
  • THEN Each command exits 2, prints an error that names --body and --body-file, and the stub records no gh invocation.

Requirement: Body file path reaches gh unchanged

Each comment command SHALL pass the --body-file path to gh unchanged, so the command reads no file itself, a dry run included.

Scenario: A dry run with a missing body file reads no file

  • WHEN A test runs devops pr comment 1 --body-file missing.md --dry-run in a directory where missing.md does not exist, with the process stub.
  • THEN The command exits 0 and prints gh pr comment 1 --body-file missing.md, and the stub records no gh invocation.

Requirement: Dry run lists one comment request

Each comment command SHALL print one POST repos/<owner>/<repo>/issues/<number>/comments request and its gh command, and SHALL run no gh, when --dry-run is set.

Scenario: The dry run prints the request and runs no gh

  • WHEN A test runs each comment command with 1 --body-file c.md -R octo/repo --dry-run and the process stub, and the plan is rendered with described=True.
  • THEN Each output holds POST repos/octo/repo/issues/1/comments and the gh command gh pr comment 1 --body-file c.md --repo octo/repo or gh issue comment 1 --body-file c.md --repo octo/repo, and the stub records no gh invocation.

Requirement: Request-plan dry-run class

Each comment command SHALL declare the request-plan dry-run class.

Scenario: The dry-run ratchet passes

  • WHEN uv run pytest tests/invariants/test_dry_run_class_ratchet.py -n 0 runs after the commands are added.
  • THEN The test passes, and tests/fixtures/dry_run_gaps.json holds neither the pr comment path nor the gh issue comment path.

Requirement: Comment URL from gh

Each comment command SHALL run gh one time with max_retries=0 and SHALL print the URL that gh returns on stdout.

Scenario: A posted comment prints its URL

  • WHEN A test runs each command with 1 --body text -R octo/repo, and the process stub returns https://github.com/octo/repo/pull/1#issuecomment-2 for the pr commands and https://github.com/octo/repo/issues/1#issuecomment-3 for the issue command.
  • THEN Each command prints its URL, and the stub records one gh invocation.

Requirement: Repo flag

Each comment command SHALL accept -R/--repo and SHALL pass --repo <owner/repo> to gh.

Scenario: Another repository is selected

  • WHEN A test runs each command with 1 --body text -R octo/repo.
  • THEN The stub records gh pr comment 1 --body text --repo octo/repo for the two pr paths and gh issue comment 1 --body text --repo octo/repo for the issue path.

Requirement: No second POST on a rate limit

A gh failure that names secondary rate limit SHALL NOT cause a second gh invocation.

Scenario: A rate-limit refusal is not retried

  • WHEN The process stub fails with secondary rate limit for each comment command.
  • THEN The stub records one gh invocation for each command, and each command exits non-zero with the failure text.

Requirement: MCP comment tools publish text only

The MCP tools pr_comment and gh_issue_comment SHALL publish number, body, repo and dry_run only, with body required, and SHALL refuse a body_file argument before they run the command.

Scenario: A body-file parameter is refused

  • WHEN An MCP caller sends {"number": 1, "body": "text", "body_file": "/etc/hostname"} to pr_comment and to gh_issue_comment.
  • THEN Each call returns an error of kind HALLUCINATED_PARAM, each tool schema holds number, body, repo and dry_run and no body_file property, and the dispatcher runs no command.

Requirement: MCP write-role listing

The two tools SHALL be rows of CONST_MCP_EXPOSURE_TABLE with read_only false, and the MCP tool listing SHALL include them only in the write role ops.

Scenario: A job role lacks the comment tools

  • WHEN A test calls tools_for_role for the write role ops and for each job role.
  • THEN The ops listing holds both tools, each job role listing holds neither, and the pr comment and gh issue comment rows of CONST_MCP_EXPOSURE_TABLE hold False for read_only.

Requirement: Generated docs hold the new commands

The generated command and tool docs SHALL list the new comment commands and tools.

Scenario: The generated docs match the commands

  • WHEN uv run devops docs generate --check runs after uv run devops docs generate --sync-readme.
  • THEN The check exits 0, which shows docs/commands/pr.md, docs/commands/gh.md, docs/CLI_REFERENCE.md and docs/MCP_TOOLS.md hold devops pr comment, devops gh issue comment, pr_comment and gh_issue_comment.

Existing Tool Considered

cli/cli (gh), MIT, last activity 2026-11-24, maintained, verdict in-use: the alternatives check of 2026-11-24 in the issue body records in its block what gh lacks. This item wraps gh pr comment and gh issue comment through the paced run_gh session and builds no comment mechanism, no body-file reader and no URL builder.

Key questions

  • Do the comment commands run gh, or send the REST POST themselves?: Run gh through run_gh. gh holds the commands, the flags, the body-file read, the repository selection and the comment URL. devops pr already wraps gh pr subcommands in _run_gh_pr_command, and that helper captures gh's output and drops it, so the comment command prints res.stdout itself. (best practice) [sources: AGENTS.md:13, src/devops_cli/commands/pr.py:126, src/devops_cli/commands/gh.py:143, https://cli.github.com/manual/gh_pr_comment]
    • Chosen: Run gh through run_gh. gh has the commands, the flags, the body-file read and the URL output, and the project already wraps gh pr subcommands.
    • Rejected: Send the REST POST in the command. It rebuilds the body-file read and the URL output that gh holds, and it needs the pr-body-file helper.
  • Which command paths does the item add?: devops pr comment and devops gh issue comment, in gh's singular nouns. devops gh pr comment comes with the first at no extra code, because src/devops_cli/commands/gh.py:143 mounts the devops pr app at devops gh pr, so the new command appears at both paths. The reply of 2026-11-26 shows an agent that typed the devops gh pr comment form, and the issue counts failures of both pr names. (best practice) [sources: src/devops_cli/commands/gh.py:143, openspec/specs/gh-command-names/spec.md:9, CONTRIBUTING.md:213, https://cli.github.com/manual/gh_pr_comment]
    • Chosen: Two command definitions, pr comment in pr.py and issue comment in gh.py. The pr app is already mounted at devops gh pr, so one definition serves both pr paths, and the issue group holds the issue command.
    • Rejected: Only devops pr comment and devops gh issue comment, with no devops gh pr form. The issue counts failures of the gh pr comment form, and the mount makes the third path free.
    • Rejected: A second handler for devops gh pr comment in gh.py. The mount already exposes the command; a second handler would drift from the first.
    • Rejected: Plural issues group. gh writes issue, and the naming spec makes a plural group a usage error.
  • How does a comment command avoid a second POST after a rate-limit refusal?: Pass max_retries=0 to run_gh. The default is 2, the loop runs max_retries + 1 times, and at the last attempt _handle_attempt_backoff holds the wait and returns False, so the command makes one attempt and reports the refusal. ADR 0006 records the same rule for the session: it does not send a lost write again. (best practice) [sources: src/devops_cli/github/rate_limiter.py:1898, src/devops_cli/github/rate_limiter.py:1849, src/devops_cli/github/rate_limiter.py:1805, docs/adr/0006-github-session-requests-go-through-gidgethub.md:17]
    • Chosen: Pass max_retries=0. One gh invocation for each comment. A rate-limit refusal is reported and never retried.
    • Rejected: Keep the default retry count. A retry sends the same gh command again, so a write that GitHub applied before its answer was lost can post two comments.
  • How do the comment commands take the body, and what happens when the body flags conflict or are missing?: Forward --body and --body-file to gh in their long forms, with --body-file a plain path (str | None, not typer.FileText), so gh reads the file and a dry run reads no file and never waits on stdin. Exit 2 when both flags are given, as _resolve_body_input refuses them, and when neither is given, because gh then prompts for the comment text. (best practice) [sources: https://cli.github.com/manual/gh_pr_comment, src/devops_cli/commands/pr.py:1022, src/devops_cli/commands/pr.py:1024, openspec/changes/archive/2026-11-25-4852-pr-body-file/design.md:6]
    • Chosen: Forward both flags and exit 2 on a conflict or on no body. gh reads the file and reports its own error for a missing one, and the dry run reads no file because the path is passed through.
    • Rejected: Read the file with typer.FileText and forward --body <text>. typer.FileText with _resolve_body_input reads the file, or stdin for -, before the dry-run branch, so a dry run would read a file and --body-file - --dry-run would block on stdin.
    • Rejected: Pass a missing body through to gh. gh then prompts for the comment text, and an agent that runs the command waits at the prompt.
  • Does the session pace a comment as a write?: Yes. is_write_gh_command reads gh's group and verb and counts every verb that is not a read verb as a write, and comment is not in CONST_GH_READ_VERBS, so run_gh paces the comment with mutation_min_interval. [sources: src/devops_cli/github/request_classifier.py:102, src/devops_cli/github/request_classifier.py:108, src/devops_cli/config/constants.py:3105]
  • Which parameters do the MCP comment tools publish?: Publish number, body, repo and dry_run only, and make body required. A _PATH_PARAM_RESTRICTIONS entry for ("pr", "comment") and for ("gh", "issue", "comment") drops every other option in _introspect_command_parameters, and number is an integer id of at least 1. A body_file argument fails the closed schema and maps to HALLUCINATED_PARAM before the dispatcher runs a command. (best practice) [sources: SECURITY.md:32, src/devops_cli/ai/mcp/generator.py:24, src/devops_cli/ai/mcp/generator.py:40, src/devops_cli/ai/mcp/generator.py:298, src/devops_cli/ai/mcp/generator.py:310, ARCHITECTURE.md:181, src/devops_cli/config/constants.py:545]
    • Chosen: Publish number, body, repo and dry_run. A remote caller sends text only. It cannot name a local file or open an editor.
    • Rejected: Publish the full gh flag set. It exposes --body-file, --editor, --web, --edit-last and --create-if-none to a remote caller.
  • Which MCP roles hold the two comment tools?: The write role ops only. tools_for_role returns the whole catalogue for ops, and for a job role it keeps only a tool that the role table names and that is read-only. Both comment commands write. (best practice) [sources: src/devops_cli/ai/mcp/roles.py:56, src/devops_cli/ai/mcp/roles.py:64, src/devops_cli/config/constants.py:302]
    • Chosen: The ops role only. ops is the write role. A job role keeps read-only tools only, so it gets no tool that posts.
    • Rejected: Every role. A read-only job role would hold a tool that writes to GitHub.
  • Which dry-run class do the comment commands declare?: request-plan. The spec puts each external-request command of devops pr in that class and requires the command to print its planned requests, and ARCHITECTURE.md says a dry run prints the requests that a real run would send. The ratchet keeps each classified command out of tests/fixtures/dry_run_gaps.json. (best practice) [sources: openspec/specs/command-dry-run-class/spec.md:9, openspec/specs/command-dry-run-class/spec.md:98, openspec/specs/command-dry-run-class/spec.md:23, ARCHITECTURE.md:170, tests/invariants/test_dry_run_class_ratchet.py]
    • Chosen: request-plan. The command sends an external request and has a dry run that prints the request and the gh command.
    • Rejected: no-external-request. The command sends a POST. The class is for a command with no external request.
  • Which read-only mark do the two exposure-table rows carry?: False for both. The tool listing is generated from CONST_MCP_EXPOSURE_TABLE, whose rows hold the command path, the timeout and the read-only mark, and tools_for_role keeps a job role's tool only when its read-only hint is true. A comment writes to GitHub, so the mark is false. (best practice) [sources: src/devops_cli/config/constants.py:298, src/devops_cli/config/constants.py:306, src/devops_cli/ai/mcp/roles.py:44, src/devops_cli/ai/mcp/roles.py:64]
    • Chosen: read_only false. The command posts a comment, so no job role may hold its tool.
    • Rejected: read_only true. A read-only mark would put a writing tool in a job role, and the read-only write-option test fails on a read-only tool whose option writes.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4835, #4852

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/pr
    status/new
    value/high
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/pr. The (pr) scope of the title gives the scope.
    • Priority: P2-Medium. 42 recorded agent failures show recurring friction, but no user is blocked and a workaround exists via 'devops gh api'.
    • Value: High. Agents fail 42 times without this command and must fall back to raw API calls with shell-argument bodies.
    • Effort: Medium. Two new subcommands, flag parsing, dry-run, MCP role registration, and stub-based tests are required.
    • Related: feat(github): implement native devops cli functionality for gh operations and pr governance #181, which asks for a different change. Both add native devops CLI commands for GitHub PR operations, but #181 is the closed umbrella for the full suite while the candidate adds only the comment subcommands.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. removed
    priority/p2-medium
    on Nov 11, 2026
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/pr. The (pr) scope of the title gives the scope.
    • Priority: P2-Medium. The change removes frequent friction, but it is not critical and has merge dependencies.
    • Value: High. Agents tried a comment command 42 times and fell back to the gh api.
    • Effort: Medium. Two commands need shared flags, a dry run, role-based MCP tools and tests.
    • Related: feat(gh): devops gh issues close records the close reason and a comment, so a superseded item closes as not planned through rate-managed tooling #1658, which asks for a different change. Both items concern an issue comment. 1658 changes the close command to record the reason and a comment. The candidate adds standalone comment commands.
  7. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Seen again on 2026-11-12: devops gh pr comment 4966 --body-file <file> failed with "No such command 'comment'". The work-around was devops gh api repos/<owner>/<repo>/issues/<pr>/comments -X POST -F body=@<file>.

  8. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Re-scope (owner direction of 2026-11-12). New title: feat(pr): pr comment and gh issue comment run gh.

    New scope

    devops pr comment and devops gh issue comment become write entries (#5223, ADR 0026) for gh pr comment and gh issue comment. This item builds no REST POST and no body-file helper. gh reads -b, -F/--body-file and - (stdin) itself. gh also gives --edit-last, --delete-last and --create-if-none.

    Evidence

    • feat(cli): track gh-parity names and usage-error capture #4833 study: pr comment failed 42 times in 10 sessions. devops gh api posted 959 comments in 29 sessions, with the -F body=@file form.
    • GraphQL cost: gh posts a comment with the mutation addComment. It costs 1 point, plus 5 points of the secondary limit of 2,000 a minute. 959 comments in 50 days is less than 1 an hour.

    Proposed Solution & Architectural Design

    • Add two write entries to the registry. Each runs gh once, so a rate-limit refusal never posts a comment twice. Add ("pr", "comment") and ("issue", "comment") to CONST_GH_GRAPHQL_PORCELAIN_COMMANDS.
    • Add two MCP rows that are not read-only. Their allowlists hold -b/--body, --edit-last, --create-if-none and -R/--repo, and no -F/--body-file, -e/--editor or -w/--web. So an MCP caller gives the body as text and cannot send a local file. tools_for_role keeps the two tools out of the read-only roles.
    • devops pr threads reply does not change.

    Acceptance Criteria

    • devops pr comment 1 --body-file c.md --dry-run prints gh pr comment 1 --body-file c.md and sends 0 requests.
    • With the process stub, each command runs gh once and prints the URL line of gh. When the stub fails with secondary rate limit, gh still runs once.
    • MCP refuses a call with args ["1", "-F", "/etc/hostname"] and ["1", "-F/etc/hostname"] before a request.
    • The MCP listing holds the two tools only in the write roles.

    Dependencies

    Merge first: #5223, #4852 (commands/pr.py) and #5226 (commands/gh.py).

  9. changed the title [-]feat(pr): add pr comment and gh issue comment[/-] [+]feat(pr): pr comment and gh issue comment run gh[/+] on Nov 12, 2026
  10. 14 remaining items

  11. added
    status/ready
    on Nov 25, 2026
  12. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  13. dan-petty commented on Nov 26, 2026

    @dan-petty
    OwnerAuthor

    Evidence of 2026-11-26: devops gh pr comment 92 -R dan-petty/devtools --body-file <file> stopped and named devops gh api repos/{owner}/{repo}/issues/<n>/comments -X POST -F body=@<file> as the way. Six pull request comments of one session used that API form.

  14. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  15. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  16. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  17. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 18:38 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/prsource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions