pr-shepherd 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +86 -125
  3. package/bin/cli/args.mjs +2 -0
  4. package/bin/cli/fix-formatter.mjs +2 -1
  5. package/bin/cli/formatters.mjs +3 -45
  6. package/bin/cli/handlers.mjs +22 -1
  7. package/bin/cli/help-command-pages.mjs +27 -2
  8. package/bin/cli/help-top-page.mjs +2 -0
  9. package/bin/cli/list-formatters.mjs +3 -1
  10. package/bin/cli/mark-files-as-viewed-flags.mjs +34 -0
  11. package/bin/cli/mark-files-as-viewed-formatter.mjs +52 -0
  12. package/bin/cli/mutate-formatter.mjs +50 -0
  13. package/bin/cli-parser.mjs +11 -2
  14. package/bin/cli-parser.test-support.mjs +6 -1
  15. package/bin/commands/check.mjs +20 -55
  16. package/bin/commands/commit-suggestion-instruction.mjs +1 -1
  17. package/bin/commands/iterate/classify.mjs +25 -30
  18. package/bin/commands/iterate/fix-code.mjs +21 -17
  19. package/bin/commands/iterate/render.mjs +3 -3
  20. package/bin/commands/iterate-thread-test-support.mjs +18 -0
  21. package/bin/commands/iterate.fix-code-in-progress.test-support.mjs +7 -3
  22. package/bin/commands/mark-files-as-viewed.mjs +220 -0
  23. package/bin/commands/resolve-mutate.mjs +41 -4
  24. package/bin/commands/resolve.mjs +15 -76
  25. package/bin/commands/resolve.test-support.mjs +2 -0
  26. package/bin/commands/shepherd-journal.mjs +1 -1
  27. package/bin/comments/authors.mjs +14 -0
  28. package/bin/comments/minimize-policy.mjs +6 -3
  29. package/bin/comments/pending-ops.mjs +6 -0
  30. package/bin/comments/resolve.mjs +28 -11
  31. package/bin/comments/resolve.test-support.mjs +6 -1
  32. package/bin/comments/review-visibility.mjs +14 -0
  33. package/bin/comments/thread-visibility.mjs +60 -0
  34. package/bin/comments/visible-comments.mjs +1 -1
  35. package/bin/github/batch-parser-helpers.mjs +3 -4
  36. package/bin/github/batch-parsers.mjs +6 -6
  37. package/bin/reporters/agent.mjs +1 -0
  38. package/bin/threads/transcript.mjs +6 -6
  39. package/package.json +1 -1
  40. package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
  41. package/plugins/pr-shepherd/skills/mark-files-as-viewed/SKILL.md +31 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
3
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
4
- "version": "0.22.0",
4
+ "version": "0.23.0",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
package/README.md CHANGED
@@ -1,28 +1,24 @@
1
1
  # pr-shepherd
2
2
 
3
3
  Autonomous PR CI monitor and review-comment resolver for agentic coding tools, including Claude Code and Codex.
4
- The goal is to have an agent take a plan to a human-reviewable PR autonomously.
5
4
 
6
- Example Workflow:
5
+ The goal is to help an agent carry a planned change to a human-reviewable PR: passing CI, no unresolved Shepherd-visible work, and a useful PR description/journal.
7
6
 
8
- 1. `/model opusplan`
9
- 2. Create a plan
10
- 3. Accept the plan
11
- 4. Switch to Auto Mode
12
- 5. Prompt: `make a PR, then run /pr-shepherd:pr-shepherd`
13
- 6. Agent makes a draft PR
14
- 7. PR has passing CI -> draft is marked Ready for Review
15
- 8. Review bots begin providing reviews
16
- 9. Agent automatically classifies and fixes review comments based on the Plan
17
- 10. Human reviews PR with a well-documented PR title and description, passing CI, and no open threads/comments/reviews
7
+ ## How It Works
18
8
 
19
- ## How it works
9
+ `pr-shepherd` moves deterministic PR orchestration into a CLI. The CLI fetches GitHub state, emits raw-enough context, and prints a numbered `## Instructions` section for the calling agent to follow. The agent still decides whether a comment or CI failure requires a code change.
20
10
 
21
- `pr-shepherd` optimizes token management, rate limits, and agentic orchestration by moving **ALL** deterministic logic and prompts to code via a CLI tool, enshrining what would be a large skill or command prompt (of which the agent would inevitably make mistakes) into the code and returning a clear, actionable prompt.
11
+ The shipped skills invoke the default poll dispatcher (`pr-shepherd <PR>`, equivalent to `pr-shepherd poll <PR>`). Use `pr-shepherd iterate <PR>` for one single tick.
22
12
 
23
- The CLI emits unified recheck instructions. Generated commands call `pr-shepherd` directly.
13
+ Each tick returns exactly one action:
24
14
 
25
- At a high level, the skill invokes `pr-shepherd <PR>` (which polls by default), providing actionable feedback directly to the agent:
15
+ - `WAIT` no immediate action; poll can recheck until timeout.
16
+ - `MARK_READY` — the CLI already converted an eligible draft PR to ready for review.
17
+ - `FIX_CODE` — review items, failing CI, conflicts, or minimization work need agent action.
18
+ - `CANCEL` — terminal success for merged/closed PRs or elapsed ready-delay.
19
+ - `ESCALATE` — manual direction is needed.
20
+
21
+ Example shape:
26
22
 
27
23
  ```text
28
24
  > pr-shepherd 123
@@ -36,205 +32,170 @@ At a high level, the skill invokes `pr-shepherd <PR>` (which polls by default),
36
32
 
37
33
  ### `threadId=PRRT_kwDOSGizTs58XB1L` — `src/commands/iterate/index.mts:42` (@alice)
38
34
 
39
- #### `commentId=PRRC_kwDOSGizTs58XB1M` (@alice)
40
-
41
35
  > The variable name is misleading.
42
- >
43
- > Consider renaming `x` to `remainingSeconds` so readers don't have to
44
- > trace back to the declaration to understand its meaning.
45
36
 
46
37
  ## Failing checks
47
38
 
48
- - `24697658766` — `CI › lint / typecheck / test (22.x)`
39
+ - `24697658766` — `CI › lint / typecheck / test (22.x)` [conclusion: FAILURE]
49
40
  > oxfmt
50
41
 
51
42
  ## Post-fix push
52
43
 
53
44
  - base: `main`
54
- - resolve: `pr-shepherd resolve 123 --resolve-thread-ids PRRT_kwDOSGizTs58XB1L --minimize-comment-ids IC_kwDOSGizTs7_ajT8,IC_kwDOSGizTs7_ajT9 --dismiss-review-ids PRR_kwDOSGizTs58XB1R --message "$DISMISS_MESSAGE" --require-sha "$HEAD_SHA"`
45
+ - resolve: `pr-shepherd resolve 123 --reply-thread-ids PRRT_kwDOSGizTs58XB1L --message "$DISMISS_MESSAGE" --require-sha "$HEAD_SHA"`
55
46
 
56
47
  ## Instructions
57
48
 
58
- _(schematic actual steps depend on PR state)_
59
-
60
- 1. Apply code fixes for each file referenced under `## Review threads`.
61
- 2. For each failing check: examine the log tail to decide — rerun if transient, fix code if real.
62
- 3. Commit changed files.
63
- 4. Rebase and push: `git fetch origin && git rebase origin/main && git push --force-with-lease` — capture `HEAD_SHA=$(git rev-parse HEAD)`.
64
- 5. Run the `resolve:` command above, substituting `"$HEAD_SHA"`.
65
- 6. Add or update a `## Shepherd Journal` section in the PR description for any large decisions made, appending under the existing heading if it already exists.
66
- 7. CI needs time to run on the new push. Run `pr-shepherd 123` again to continue until Shepherd returns `[CANCEL]` or `[ESCALATE]`.
49
+ 1. Decide for each item under `## Review threads` and `## Failing checks` whether a code change is warranted. If code changes are needed, apply edits, commit, rebase/push according to the repository's conventions, then run the `resolve:` command.
50
+ 2. For each failing check under `## Failing checks`: fetch logs when needed and decide whether to rerun or fix.
51
+ 3. Run the `resolve:` command shown above with a specific `$DISMISS_MESSAGE` and the relevant `$HEAD_SHA`.
52
+ 4. Stop this iteration.
67
53
  ```
68
54
 
69
- On every iteration, a command is returned to instruct the agent exactly what to do. No guessing, no thinking, as few agentic turns as possible:
55
+ See [docs/actions.md](docs/actions.md) for the complete output contract.
70
56
 
71
- ```text
72
- pr-shepherd resolve 123 --resolve-thread-ids PRRT_kwDOSGizTs58XB1L --minimize-comment-ids IC_kwDOSGizTs7_ajT8,IC_kwDOSGizTs7_ajT9 --dismiss-review-ids PRR_kwDOSGizTs58XB1R --message "$DISMISS_MESSAGE" --require-sha "$HEAD_SHA"
73
- ```
57
+ ## Workflow Assumptions
74
58
 
75
- ## Workflow
59
+ This system is opinionated and works best with PRs that use required status checks and conversation resolution.
76
60
 
77
- This system makes opinionated decisions, which may or may not work for your team's workflow.
61
+ - Human-authored threads are replied to, not resolved or minimized by Shepherd.
62
+ - Bot/non-human threads, PR comments, and review summaries can be resolved or minimized when eligible.
63
+ - Every review thread/comment/review summary is surfaced at least once, even if already outdated, resolved, or minimized; edited items re-surface through seen markers.
64
+ - Draft PRs can be marked ready automatically when clean; disable with `actions.autoMarkReady: false` or `--no-auto-mark-ready`.
65
+ - The CLI never performs git mutations. It emits instructions; the caller commits, rebases, pushes, and handles repository hooks.
66
+ - `commit-suggestion` turns one GitHub suggestion thread into a patch and commit instructions, but still does not edit the working tree or git history.
78
67
 
79
- - The following PR branch protection rules are expected:
80
- - There are required status checks
81
- - All inline comments are resolved
82
- - **ALL** comments/threads/reviews will be hidden by default except for PR approvals. The only option here is to hide PR approvals as well.
83
- - The primary reason is to optimize tokens by avoiding re-fetching comments and re-adding them to the agent's context.
84
- - This also ties hand-in-hand with requiring all inline comments to be resolved.
85
- - We also want to avoid storing state as comments can be unresolved/minimized/hidden.
86
- - `pr-shepherd` keeps the PR title and description up to date, including a journal of decisions with links to comments/threads/reviews (that would be hidden at this point).
87
- - This may break your workflow if your PR titles and descriptions are restricted to a specific format.
88
- - `pr-shepherd` does **NOT** reply to inline comments when resolving them. Doing so would require agentic loops and more tokens. Instead, it updates the PR title & description once per loop with only the relevant information.
89
- - Branches are currently kept up-to-date with `git push --force-with-lease`. Please make a PR for making `merge <default branch>` an option.
90
- - Branches are currently only rebased when 1) pushing a commit on a branch that is out of date or 2) there are merge conflicts. It does not continuously rebase the branch (use a merge queue for that).
91
- - To optimize AI code reviewer tokens, create your pull requests initially as drafts and instruct your AI code reviewers to only code review PRs that are ready for review. `pr-shepherd` will automatically mark PRs as ready for review when all CI passes (can be disabled). If you have no intention of marking your PR as ready for review, then don't run `pr-shepherd`.
68
+ ## Usage
92
69
 
93
- Some other workflow improvements:
70
+ ### Iterate A PR
94
71
 
95
- - `pr-shepherd` knows whether a GitHub Copilot code review is in progress
96
- - `pr-shepherd` waits 10 minutes (configurable) until after all comments are hidden and CI passes before exiting. The primary reason is to wait for any lingering automated code reviews that do not provide status updates via the GitHub GraphQL API.
97
- - The agent is instructed to cancel failed CI runs and, when a failure looks transient (e.g. network timeout, runner setup crash), re-run them via `gh run rerun <id> --failed`. The primary reason is to minimize CI costs.
98
- - `pr-shepherd` supports "commit suggestions" by converting them into a diff, applying them, and then committing them with attribution. This avoids a file read & write. One commit is always made per suggestion to avoid any merge conflicts — in these cases, the agent will resolve the comment manually.
72
+ Claude Code:
99
73
 
100
- Recommendations:
74
+ ```text
75
+ /goal /pr-shepherd:pr-shepherd # infer PR from current branch
76
+ /goal /pr-shepherd:pr-shepherd 42
77
+ ```
101
78
 
102
- - Run `pr-shepherd` on all your PRs before you go to sleep so that you wake up to reviewable PRs. Keep an active goal cycling `pr-shepherd <PR>` until Shepherd emits `[CANCEL]` for ready-delay completion or merged/closed, or `[ESCALATE]` (including `stall-timeout` for repeated unchanged CI failures or CI that never starts).
103
- - Instruct your agents to write comments in a single review (comment, changes requested, or approved). This allows the review's comments/threads to be minimized or resolved together, keeping your pull request history clean. If you write inline comments outside of a review, each comment would still show up in the pull request history and take up space.
104
- - Avoid sticky comments as they will continue to be hidden. Instead, just make a new comment, especially on reviews. If you really want sticky comments, instruct your agent to unhide/unminimize them when updating them.
105
- - Avoid having automation edit comments, reviews, or threads in place because updated items get minimized. Instead, always make a new review, comment, thread, etc.
79
+ Codex:
106
80
 
107
- ## Design Principles
81
+ ```text
82
+ /goal $pr-shepherd # infer PR from current branch
83
+ /goal $pr-shepherd 42
84
+ ```
108
85
 
109
- - **Reduced agent context and turns** — logic lives in the CLI, not the prompt. The relevant context is provided automatically to the agent, reducing tool calls.
110
- - **Reduced GitHub rate-limit exposure** — GraphQL requests are batched when possible
111
- - **Minimal state** — `pr-shepherd` stores minimal state in `$PR_SHEPHERD_STATE_DIR` (default `$TMPDIR/pr-shepherd-state/`), not in the repository
112
- - **Classifications and decisions still happen at the agent level** — `pr-shepherd`'s goal is to provide sufficient context to make informed decisions and provide clear actionable steps without writing unreliable code-level heuristics
113
- - **Configurable** — `pr-shepherd` is configurable via `.pr-shepherdrc.yml`, which is only possible with a light prompt that simply invokes the CLI which returns the prompt.
86
+ Direct CLI:
114
87
 
115
- ## Usage
88
+ ```sh
89
+ pr-shepherd 42 # poll until non-WAIT or timeout
90
+ pr-shepherd 42 --interval 45s --timeout 4m
91
+ pr-shepherd 42 --ready-delay 15m
92
+ pr-shepherd iterate 42 # single tick
93
+ pr-shepherd poll 42 # explicit poll command
94
+ ```
116
95
 
117
- ### Iterate a PR to completion
96
+ ### Resolve Review Items
118
97
 
119
- Poll dispatcher — checks CI and review comments, fixes issues, and marks the PR ready for review when clean. Each non-terminal tick emits an `## Instructions` section; the skill follows it, then invokes `pr-shepherd <PR>` again until `[CANCEL]` or `[ESCALATE]`.
98
+ ```sh
99
+ pr-shepherd resolve 42 --fetch
100
+ pr-shepherd resolve 42 --reply-thread-ids PRRT_abc --message "Renamed the variable for clarity." --require-sha "$(git rev-parse HEAD)"
101
+ ```
120
102
 
121
- Claude Code (via `pr-shepherd` skill):
103
+ ### Apply One Suggestion Thread
122
104
 
123
- ```
124
- /pr-shepherd:pr-shepherd # infer PR from current branch
125
- /pr-shepherd:pr-shepherd 42
126
- /pr-shepherd:pr-shepherd 42 --ready-delay 15m
105
+ ```sh
106
+ pr-shepherd commit-suggestion 42 --thread-id PRRT_abc --message "rename value for clarity"
127
107
  ```
128
108
 
129
- Codex or direct CLI:
109
+ The output contains a diff and numbered instructions for applying, staging, committing, resolving, and pushing.
110
+
111
+ ### Mark Files As Viewed
130
112
 
131
113
  ```sh
132
- pr-shepherd 42
133
- pr-shepherd 42 --interval 45s --timeout 4m
134
- pr-shepherd 42 --ready-delay 15m
135
- pr-shepherd iterate 42 # single tick
114
+ pr-shepherd mark-files-as-viewed 42 --tests
115
+ pr-shepherd mark-files-as-viewed 42 src/a.ts --match '^docs/'
136
116
  ```
137
117
 
138
- ## Iterate decision loop
118
+ The shipped `mark-files-as-viewed` skill maps a standalone `tests` argument to `--tests`.
139
119
 
140
- On each tick: fetch PR state in one GraphQL batch → classify CI, comments, and merge status → take one action (`fix_code`, `mark_ready`, `cancel`, `escalate`, or `wait`). See [docs/iterate-flow.md](docs/iterate-flow.md) for the decision table and [docs/flow.md](docs/flow.md) for the end-to-end flow diagram.
120
+ ### Clean Local State
141
121
 
142
- ## Cleaning state
143
-
144
- `pr-shepherd` accumulates state under `$PR_SHEPHERD_STATE_DIR` (seen markers, fix-attempt counters, stall fingerprints, etc.). To reset it:
122
+ `pr-shepherd` stores seen markers, fix-attempt counters, stall fingerprints, ready-delay markers, and logs under `$PR_SHEPHERD_STATE_DIR` (default `$TMPDIR/pr-shepherd-state`).
145
123
 
146
124
  ```sh
147
- pr-shepherd clean current # remove state for the current branch's PR
148
- pr-shepherd clean repo # remove all state for this repo
149
- pr-shepherd clean all # remove all pr-shepherd state
125
+ pr-shepherd clean current
126
+ pr-shepherd clean repo
127
+ pr-shepherd clean all --dry-run
128
+ pr-shepherd log-file
150
129
  ```
151
130
 
152
- Add `--dry-run` to preview what would be removed. See [docs/cli-usage.md](docs/cli-usage.md) for the full `clean` reference.
153
-
154
131
  ## Install
155
132
 
156
- > **Note:** Skill and plugin install methods add the skill definitions only they do not install the `pr-shepherd` CLI. Ensure `pr-shepherd` is available on `PATH` wherever the skill runs.
133
+ Skill and plugin install methods add the skill definitions only. Install the `pr-shepherd` CLI separately wherever the skill runs.
157
134
 
158
135
  ### Claude Code
159
136
 
160
- Install as a Claude Code plugin:
161
-
162
137
  ```bash
163
138
  claude /plugin marketplace add jonathanong/pr-shepherd
164
139
  claude /plugin install pr-shepherd
165
140
  ```
166
141
 
167
- This repo ships two `marketplace.json` files that serve different Claude install flows: the root `marketplace.json` resolves the published plugin (used by the `claude /plugin marketplace add` command above); `.claude-plugin/marketplace.json` is the owner-level registry manifest that resolves the plugin from the local plugin directory (used when Claude Code installs from a local or git-based source). Both files are needed to support these two install paths.
168
-
169
142
  ### Codex
170
143
 
171
- Codex uses the repo-shipped Codex plugin rather than the Claude plugin or `/pr-shepherd:*` slash commands. The plugin provides one `pr-shepherd` skill for iterating a PR to completion.
172
-
173
- Install the Codex plugin marketplace from GitHub:
174
-
175
144
  ```bash
176
145
  codex plugin marketplace add jonathanong/pr-shepherd
177
146
  ```
178
147
 
179
- Or pin a branch/tag/ref:
148
+ Or pin a ref:
180
149
 
181
150
  ```bash
182
151
  codex plugin marketplace add jonathanong/pr-shepherd --ref main
183
152
  ```
184
153
 
185
- For local development, point Codex at a checkout:
154
+ For local development:
186
155
 
187
156
  ```bash
188
157
  git clone https://github.com/jonathanong/pr-shepherd ~/.codex/plugin-sources/pr-shepherd
189
158
  codex plugin marketplace add ~/.codex/plugin-sources/pr-shepherd
190
159
  ```
191
160
 
192
- After adding the marketplace, open the Codex plugin directory, choose the `jonathanong` marketplace, and install/enable `pr-shepherd`. The marketplace root must contain `.agents/plugins/marketplace.json` and `plugins/pr-shepherd/`.
193
-
194
- Install the CLI where Codex will run it so `pr-shepherd` is available on `PATH`. The plugin only installs the skill; it does not install the CLI into target repositories.
195
-
196
- Iterate a PR from Codex:
197
-
198
- ```bash
199
- pr-shepherd iterate 42
200
- ```
201
-
202
- Or ask Codex to use the `pr-shepherd` skill, for example: `run pr-shepherd until this PR is ready`. Follow the output's `## Instructions`. Continue until Shepherd emits `[CANCEL]` or `[ESCALATE]` (including `stall-timeout` for repeated unchanged CI failures or CI that never starts). `pr-shepherd iterate 42` remains supported for existing workflows.
161
+ After adding the marketplace, install/enable the `pr-shepherd` plugin from Codex. The marketplace root must contain `.agents/plugins/marketplace.json` and `plugins/pr-shepherd/`.
203
162
 
204
163
  ## Configuration
205
164
 
206
- Create a `.pr-shepherdrc.yml` in your project root (or any parent directory) to override defaults. The loader walks up from `cwd` to `$HOME` (if `$HOME` is on that path) or the filesystem root; the first match wins.
165
+ Create `.pr-shepherdrc.yml` in your project root or an ancestor directory.
207
166
 
208
167
  ```yaml
209
168
  iterate:
210
- fixAttemptsPerThread: 5 # raise before escalating to manual review
169
+ fixAttemptsPerThread: 5
170
+ stallTimeoutMinutes: 60
171
+ minimizeApprovals: false
211
172
  minimizeComments: all # all | bots | users | none
212
173
  checks:
213
174
  ciTriggerEvents:
214
175
  - pull_request
215
176
  - pull_request_target
216
- - merge_group # add for merge-queue repos
177
+ - merge_group
217
178
  actions:
218
- autoMarkReady: false # disable to stay draft until you manually promote
179
+ autoMarkReady: false
219
180
  ```
220
181
 
221
- Environment variables: `GH_TOKEN` / `GITHUB_TOKEN` (auth; falls back to `gh auth token`, then `GITHUB_PERSONAL_ACCESS_TOKEN`), `PR_SHEPHERD_STATE_DIR` (override loop-state and log base dir), `PR_SHEPHERD_LOG_DISABLED=1` (disable the per-worktree debug log).
182
+ Environment variables:
183
+
184
+ - `GH_TOKEN` / `GITHUB_TOKEN` / `GITHUB_PERSONAL_ACCESS_TOKEN` for auth; `gh auth token` is used as a fallback.
185
+ - `PR_SHEPHERD_STATE_DIR` to override state and log location.
186
+ - `PR_SHEPHERD_LOG_DISABLED=1` to disable per-worktree debug logging.
222
187
 
223
- See [docs/configuration.md](docs/configuration.md) for full semantics and deprecated-key migration.
188
+ See [docs/configuration.md](docs/configuration.md) for the full reference.
224
189
 
225
190
  ## Requirements
226
191
 
227
- - Node.js 22.0.0
228
- - A GitHub token: set `GH_TOKEN` or `GITHUB_TOKEN`, **or** install and authenticate the `gh` CLI (`gh auth login`) — pr-shepherd uses `gh auth token` as a fallback before trying `GITHUB_PERSONAL_ACCESS_TOKEN`. The `repo` scope is required for private repositories.
192
+ - Node.js >= 22.0.0
193
+ - A GitHub token or authenticated `gh` CLI; private repositories require `repo` scope.
229
194
  - `git`
230
195
 
231
196
  ## Docs
232
197
 
233
- Full reference: [docs/README.md](docs/README.md) — CLI usage, skills, configuration, architecture, actions, debugging, and more.
234
-
235
- ## Architecture
236
-
237
- See [docs/architecture.md](docs/architecture.md) for the module map and dependency rules.
198
+ Full reference: [docs/README.md](docs/README.md).
238
199
 
239
200
  ## License
240
201
 
package/bin/cli/args.mjs CHANGED
@@ -13,10 +13,12 @@ const FLAGS_WITH_VALUES = new Set([
13
13
  "--description",
14
14
  "--thread-id",
15
15
  "--resolve-thread-ids",
16
+ "--reply-thread-ids",
16
17
  "--minimize-comment-ids",
17
18
  "--dismiss-review-ids",
18
19
  "--interval",
19
20
  "--timeout",
21
+ "--match",
20
22
  ]);
21
23
  // Boolean flags that do NOT consume the next argument. Any --flag not in this
22
24
  // set and not in FLAGS_WITH_VALUES is treated conservatively as value-taking
@@ -13,7 +13,8 @@ export function formatFixCodeResult(header, result, opts) {
13
13
  const loc = t.path ? `\`${t.path}:${lineLabel}\`` : "(no location)";
14
14
  const heading = t.url ? `[threadId=${t.id}](${t.url})` : `\`threadId=${t.id}\``;
15
15
  const suggestionMarker = t.suggestion ? " [suggestion]" : "";
16
- sections.push(`### ${heading} ${loc} (${renderAuthor(t.author, t.authorType)})${suggestionMarker}`);
16
+ const editedMarker = t.edited ? " [edited since first look]" : "";
17
+ sections.push(`### ${heading} — ${loc} (${renderAuthor(t.author, t.authorType)})${suggestionMarker}${editedMarker}`);
17
18
  sections.push(renderThreadConversation(t));
18
19
  if (t.suggestion) {
19
20
  sections.push(renderSuggestionBlock(t.suggestion, ""));
@@ -1,6 +1,8 @@
1
1
  export { formatIterateResult } from "./iterate-formatter.mjs";
2
2
  export { projectIterateLean, projectIterateVerbose } from "./iterate-lean.mjs";
3
3
  export { formatCleanResult } from "./clean-formatter.mjs";
4
+ export { formatMarkFilesAsViewedResult } from "./mark-files-as-viewed-formatter.mjs";
5
+ export { formatMutateResult } from "./mutate-formatter.mjs";
4
6
  import { safeFence } from "./fence.mjs";
5
7
  import { renderThreadBullet, renderCommentBullet, renderReviewBullet, renderThreadResolutionStatusTag, buildFirstLookBullets, renderEditedCommentTag, } from "./list-formatters.mjs";
6
8
  import { joinSections } from "../util/markdown.mjs";
@@ -79,12 +81,7 @@ export function formatCommitSuggestionResult(result) {
79
81
  lines.push(result.patch.trimEnd());
80
82
  lines.push(fence);
81
83
  }
82
- lines.push("");
83
- lines.push("## Suggested commit message");
84
- lines.push("");
85
- lines.push(result.commitMessage);
86
- lines.push("");
87
- lines.push(result.commitBody);
84
+ lines.push("", "## Suggested commit message", "", result.commitMessage, "", result.commitBody);
88
85
  if (result.postActionInstructions.length > 0) {
89
86
  lines.push("");
90
87
  lines.push("## Instructions");
@@ -95,42 +92,3 @@ export function formatCommitSuggestionResult(result) {
95
92
  }
96
93
  return lines.join("\n");
97
94
  }
98
- export function formatMutateResult(result) {
99
- const lines = [];
100
- if (result.resolvedThreads.length)
101
- lines.push(`Resolved threads (${result.resolvedThreads.length}): ${result.resolvedThreads.join(", ")}`);
102
- if (result.minimizedComments.length)
103
- lines.push(`Minimized comments (${result.minimizedComments.length}): ${result.minimizedComments.join(", ")}`);
104
- if (result.dismissedReviews.length)
105
- lines.push(`Dismissed reviews (${result.dismissedReviews.length}): ${result.dismissedReviews.join(", ")}`);
106
- if (result.skippedDismissals?.length)
107
- lines.push(`Skipped dismissals (${result.skippedDismissals.length}): ${result.skippedDismissals.join(", ")}`);
108
- if (result.rateLimit) {
109
- const details = [
110
- result.rateLimit.retryAfterSeconds !== undefined
111
- ? `retry after ${result.rateLimit.retryAfterSeconds}s`
112
- : null,
113
- result.rateLimit.remaining !== undefined && result.rateLimit.limit !== undefined
114
- ? `remaining ${result.rateLimit.remaining}/${result.rateLimit.limit}`
115
- : null,
116
- result.rateLimit.resetAt !== undefined
117
- ? `reset at ${new Date(result.rateLimit.resetAt * 1000).toISOString()}`
118
- : null,
119
- ]
120
- .filter(Boolean)
121
- .join(", ");
122
- lines.push(`Stopped: GitHub rate limit hit — ${result.rateLimit.message}${details ? ` (${details})` : ""}`);
123
- }
124
- if (result.unresolvedThreads?.length)
125
- lines.push(`Not resolved due to rate limit (${result.unresolvedThreads.length}): ${result.unresolvedThreads.join(", ")}`);
126
- if (result.unminimizedComments?.length)
127
- lines.push(`Not minimized due to rate limit (${result.unminimizedComments.length}): ${result.unminimizedComments.join(", ")}`);
128
- if (result.undismissedReviews?.length)
129
- lines.push(`Not dismissed due to rate limit (${result.undismissedReviews.length}): ${result.undismissedReviews.join(", ")}`);
130
- const errors = result.rateLimit
131
- ? result.errors.filter((e) => !e.startsWith("rate limit:"))
132
- : result.errors;
133
- if (errors.length)
134
- lines.push(`Errors:\n ${errors.join("\n ")}`);
135
- return lines.join("\n");
136
- }
@@ -1,12 +1,14 @@
1
1
  import { runCommitSuggestion } from "../commands/commit-suggestion.mjs";
2
+ import { runMarkFilesAsViewed } from "../commands/mark-files-as-viewed.mjs";
2
3
  import { runIterate } from "../commands/iterate/index.mjs";
3
4
  import { runClean } from "../commands/clean.mjs";
4
5
  import { loadConfig } from "../config/load.mjs";
5
6
  import { parseCommonArgs, getFlag } from "./args.mjs";
6
7
  import { USAGE } from "./help.mjs";
7
- import { formatCommitSuggestionResult, formatCleanResult } from "./formatters.mjs";
8
+ import { formatCommitSuggestionResult, formatCleanResult, formatMarkFilesAsViewedResult, } from "./formatters.mjs";
8
9
  import { parseIterateFlags } from "./iterate-flags.mjs";
9
10
  import { emitIterateResult } from "./iterate-emitter.mjs";
11
+ import { parseMarkFilesAsViewedArgs } from "./mark-files-as-viewed-flags.mjs";
10
12
  const CLEAN_VARIANTS = new Set(["pr", "branch", "current", "repo", "all"]);
11
13
  export async function handleClean(args) {
12
14
  const variant = args[0];
@@ -108,3 +110,22 @@ export async function handleIterate(args) {
108
110
  readyDelaySuffix: flags.readyDelaySuffix ?? undefined,
109
111
  });
110
112
  }
113
+ export async function handleMarkFilesAsViewed(args) {
114
+ const { prNumber, global: globalOpts, extra } = parseCommonArgs(args);
115
+ const parsed = parseMarkFilesAsViewedArgs(extra);
116
+ if (!parsed.ok) {
117
+ process.stderr.write(`pr-shepherd: mark-files-as-viewed: ${parsed.error}\n`);
118
+ process.exitCode = 1;
119
+ return;
120
+ }
121
+ const result = await runMarkFilesAsViewed({
122
+ ...globalOpts,
123
+ prNumber,
124
+ files: parsed.files,
125
+ tests: parsed.tests,
126
+ matchPatterns: parsed.matchPatterns,
127
+ });
128
+ process.stdout.write(globalOpts.format === "json"
129
+ ? `${JSON.stringify(result, null, 2)}\n`
130
+ : `${formatMarkFilesAsViewedResult(result)}\n`);
131
+ }
@@ -5,6 +5,7 @@ Fetch actionable review items or apply GitHub review-state mutations after fixes
5
5
 
6
6
  Usage:
7
7
  pr-shepherd resolve [PR] [--fetch] [--format text|json]
8
+ pr-shepherd resolve [PR] --reply-thread-ids A,B --message MSG
8
9
  pr-shepherd resolve [PR] --resolve-thread-ids A,B [--minimize-comment-ids X,Y]
9
10
  [--dismiss-review-ids Q] [--message MSG]
10
11
  [--require-sha SHA] [--format text|json]
@@ -13,14 +14,18 @@ Modes:
13
14
  fetch Default when no mutation IDs are provided. Fetches review threads,
14
15
  comments, first-look items, and instructions.
15
16
  mutate Runs when any mutation ID flag is present. Resolves threads,
16
- minimizes comments/review summaries, and dismisses reviews.
17
+ replies to human threads, resolves non-human/manual thread IDs,
18
+ minimizes non-human comments/review summaries, and dismisses non-human reviews.
17
19
 
18
20
  Flags:
19
21
  --fetch Force fetch mode.
20
22
  --resolve-thread-ids <ids> Comma-separated review thread IDs to resolve.
23
+ Human-authored thread IDs are skipped; use --reply-thread-ids.
24
+ --reply-thread-ids <ids> Comma-separated human review thread IDs to reply to.
21
25
  --minimize-comment-ids <ids> Comma-separated issue/review comment IDs to minimize.
22
26
  --dismiss-review-ids <ids> Comma-separated CHANGES_REQUESTED review IDs to dismiss.
23
- --message <text> Dismiss message. Required with --dismiss-review-ids.
27
+ --message <text> Reply/dismiss message. Required with --reply-thread-ids
28
+ or --dismiss-review-ids.
24
29
  --require-sha <sha> Wait until GitHub reports this PR head SHA before mutating.
25
30
  --format text|json Output format. Default: text.
26
31
  --help, -h Print this help and exit before GitHub I/O.
@@ -49,6 +54,26 @@ Preconditions:
49
54
  Exit codes:
50
55
  0 suggestion patch and instructions produced
51
56
  1 validation, lookup, precondition, or suggestion parsing failure`,
57
+ "mark-files-as-viewed": `pr-shepherd mark-files-as-viewed
58
+
59
+ Mark changed files as viewed in the GitHub pull request diff.
60
+
61
+ Usage:
62
+ pr-shepherd mark-files-as-viewed [PR] [files...] [--tests] [--match REGEX]
63
+ [--format text|json]
64
+
65
+ Selectors:
66
+ files... Exact changed-file paths from the PR diff.
67
+ --tests Select changed test files.
68
+ --match <regex> Select changed files whose paths match a case-insensitive JavaScript regex.
69
+ May be repeated.
70
+
71
+ Flags:
72
+ --format text|json Output format. Default: text.
73
+ --help, -h Print this help and exit before GitHub I/O.
74
+
75
+ PR may be a number or GitHub pull request URL. When omitted, the current branch PR is inferred.
76
+ Exit code: 0 on success; 1 on validation or lookup failure.`,
52
77
  iterate: `pr-shepherd iterate
53
78
 
54
79
  Run one iterate tick for a pull request. The no-subcommand form polls; use this subcommand for a single tick.
@@ -10,6 +10,7 @@ Usage:
10
10
  pr-shepherd poll [PR] [poll-flags] [iterate-flags]
11
11
  pr-shepherd resolve [PR] [resolve-flags]
12
12
  pr-shepherd commit-suggestion [PR] --thread-id ID --message MSG [flags]
13
+ pr-shepherd mark-files-as-viewed [PR] [files...] [--tests] [--match REGEX]
13
14
  pr-shepherd clean <pr|branch|current|repo|all> [value] [flags]
14
15
  pr-shepherd log-file [--format text|json]
15
16
 
@@ -19,6 +20,7 @@ Commands:
19
20
  poll Re-run iterate while the action is WAIT, then print the final tick.
20
21
  resolve Fetch actionable review items, or resolve/minimize/dismiss IDs.
21
22
  commit-suggestion Convert one GitHub suggestion thread into a patch and commit instructions.
23
+ mark-files-as-viewed Mark PR changed files as viewed in GitHub.
22
24
  clean Remove pr-shepherd state files.
23
25
  log-file Print the per-worktree debug log path.
24
26
 
@@ -27,8 +27,9 @@ export function renderThreadBullet(t, opts = {}) {
27
27
  ? `\`${t.path}:${renderLineRange(t.startLine ?? undefined, t.line ?? null)}\``
28
28
  : "`(no location)`";
29
29
  const suggestionMarker = t.suggestion ? " [suggestion]" : "";
30
+ const editedMarker = t.edited && !opts.suppressEditedMarker ? " [edited since first look]" : "";
30
31
  const statusSuffix = opts.statusTag ? ` ${opts.statusTag}` : "";
31
- const bulletLine = `- \`threadId=${t.id}\`${link} ${loc} (${renderAuthor(t.author, t.authorType)})${suggestionMarker}${statusSuffix}`;
32
+ const bulletLine = `- \`threadId=${t.id}\`${link} ${loc} (${renderAuthor(t.author, t.authorType)})${suggestionMarker}${editedMarker}${statusSuffix}`;
32
33
  if (!opts.noBody && (!t.comments || t.comments.length === 0)) {
33
34
  const legacyLine = `${bulletLine}: ${renderBodyPreview(t.body)}`;
34
35
  return t.suggestion && opts.renderSuggestion
@@ -111,6 +112,7 @@ export function buildFirstLookBullets(firstLookThreads, resolutionOnlyIds, first
111
112
  bullets.push(renderThreadBullet(t, {
112
113
  statusTag: renderFirstLookStatusTag(t),
113
114
  noBody: resolutionOnlyIds.has(t.id),
115
+ suppressEditedMarker: true,
114
116
  }));
115
117
  }
116
118
  for (const c of firstLookComments) {
@@ -0,0 +1,34 @@
1
+ import { hasFlag } from "./args.mjs";
2
+ export function parseMarkFilesAsViewedArgs(args) {
3
+ const files = [];
4
+ const matchPatterns = [];
5
+ const tests = hasFlag(args, "--tests");
6
+ for (let i = 0; i < args.length; i += 1) {
7
+ const arg = args[i];
8
+ if (arg === "--tests")
9
+ continue;
10
+ if (arg === "--match") {
11
+ const value = args[i + 1];
12
+ if (value === undefined || value.startsWith("--")) {
13
+ return { ok: false, error: "--match requires a regex value" };
14
+ }
15
+ matchPatterns.push(value);
16
+ i += 1;
17
+ continue;
18
+ }
19
+ if (arg.startsWith("--match=")) {
20
+ const value = arg.slice("--match=".length);
21
+ if (value === "")
22
+ return { ok: false, error: "--match requires a regex value" };
23
+ matchPatterns.push(value);
24
+ continue;
25
+ }
26
+ if (arg.startsWith("--"))
27
+ return { ok: false, error: `unknown flag: "${arg}"` };
28
+ files.push(arg);
29
+ }
30
+ if (files.length === 0 && !tests && matchPatterns.length === 0) {
31
+ return { ok: false, error: "provide at least one file, --tests, or --match <regex>" };
32
+ }
33
+ return { ok: true, files, tests, matchPatterns };
34
+ }
@@ -0,0 +1,52 @@
1
+ export function formatMarkFilesAsViewedResult(result) {
2
+ const lines = [];
3
+ lines.push(`# PR #${result.prNumber} — Mark files as viewed (${result.markedPaths.length} marked)`);
4
+ lines.push("");
5
+ lines.push(`repo: ${result.repo}`);
6
+ appendPathSection(lines, "Matched files", result.matchedPaths);
7
+ appendPathSection(lines, "Marked viewed", result.markedPaths);
8
+ appendPathSection(lines, "Already viewed", result.alreadyViewedPaths);
9
+ appendPathSection(lines, "Missing from PR diff", result.missingPaths);
10
+ appendTextSection(lines, "Unmatched selectors", result.unmatchedSelectors);
11
+ if (result.rateLimit) {
12
+ const details = [
13
+ result.rateLimit.retryAfterSeconds !== undefined
14
+ ? `retry after ${result.rateLimit.retryAfterSeconds}s`
15
+ : null,
16
+ result.rateLimit.remaining !== undefined && result.rateLimit.limit !== undefined
17
+ ? `remaining ${result.rateLimit.remaining}/${result.rateLimit.limit}`
18
+ : null,
19
+ result.rateLimit.resetAt !== undefined
20
+ ? `reset at ${new Date(result.rateLimit.resetAt * 1000).toISOString()}`
21
+ : null,
22
+ ]
23
+ .filter(Boolean)
24
+ .join(", ");
25
+ lines.push("");
26
+ lines.push(`Stopped: GitHub rate limit hit — ${result.rateLimit.message}${details ? ` (${details})` : ""}`);
27
+ }
28
+ appendPathSection(lines, "Not marked due to rate limit", result.unmarkedPaths ?? []);
29
+ const errors = result.rateLimit
30
+ ? result.errors.filter((e) => !e.startsWith("rate limit:"))
31
+ : result.errors;
32
+ appendTextSection(lines, "Errors", errors);
33
+ if (result.matchedPaths.length === 0) {
34
+ lines.push("");
35
+ lines.push("No files matched.");
36
+ }
37
+ return lines.join("\n");
38
+ }
39
+ function appendPathSection(lines, label, paths) {
40
+ if (paths.length === 0)
41
+ return;
42
+ lines.push("");
43
+ lines.push(`## ${label} (${paths.length})`);
44
+ lines.push(paths.map((path) => `- \`${path}\``).join("\n"));
45
+ }
46
+ function appendTextSection(lines, label, values) {
47
+ if (values.length === 0)
48
+ return;
49
+ lines.push("");
50
+ lines.push(`## ${label} (${values.length})`);
51
+ lines.push(values.map((value) => `- ${value}`).join("\n"));
52
+ }