pr-shepherd 1.3.0 → 1.5.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 (48) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +1 -0
  3. package/bin/api.mjs +4 -1
  4. package/bin/cli/api-usage-formatter.mjs +18 -8
  5. package/bin/cli/help-command-pages.d.mts +2 -2
  6. package/bin/cli/help-iterate-poll-pages.d.mts +2 -2
  7. package/bin/cli/help-iterate-poll-pages.mjs +3 -2
  8. package/bin/cli/help.d.mts +2 -2
  9. package/bin/cli-parser.mjs +5 -2
  10. package/bin/commands/poll-summary-explicit-instructions.mjs +1 -1
  11. package/bin/commands/tick.mjs +1 -0
  12. package/bin/github/api-telemetry-adopt.d.mts +4 -0
  13. package/bin/github/api-telemetry-adopt.mjs +52 -0
  14. package/bin/github/api-telemetry-aggregate.d.mts +6 -2
  15. package/bin/github/api-telemetry-aggregate.mjs +19 -52
  16. package/bin/github/api-telemetry-summary.d.mts +4 -0
  17. package/bin/github/api-telemetry-summary.mjs +63 -0
  18. package/bin/github/api-telemetry.d.mts +2 -0
  19. package/bin/github/api-telemetry.mjs +2 -43
  20. package/bin/github/app-eligibility.d.mts +9 -0
  21. package/bin/github/app-eligibility.mjs +21 -0
  22. package/bin/github/app-quota.d.mts +10 -0
  23. package/bin/github/app-quota.mjs +44 -0
  24. package/bin/github/auth-target.d.mts +16 -0
  25. package/bin/github/auth-target.mjs +29 -0
  26. package/bin/github/client.mjs +4 -2
  27. package/bin/github/github-app-config.d.mts +12 -0
  28. package/bin/github/github-app-config.mjs +102 -0
  29. package/bin/github/github-app-token.d.mts +13 -0
  30. package/bin/github/github-app-token.mjs +107 -0
  31. package/bin/github/graphql-http.mjs +18 -2
  32. package/bin/github/http-auth.d.mts +15 -2
  33. package/bin/github/http-auth.mjs +35 -4
  34. package/bin/github/http-intermediate.d.mts +1 -0
  35. package/bin/github/http-intermediate.mjs +1 -0
  36. package/bin/github/rest-http.mjs +19 -2
  37. package/bin/github/rest-text.mjs +22 -3
  38. package/bin/pr-reference.mjs +3 -0
  39. package/bin/types/api-usage.d.mts +14 -0
  40. package/package.json +1 -1
  41. package/plugins/pr-shepherd/.claude-plugin/plugin.json +1 -1
  42. package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
  43. package/plugins/pr-shepherd/.codex.mcp.json +1 -1
  44. package/plugins/pr-shepherd/.mcp.json +1 -1
  45. package/plugins/pr-shepherd/package-lock.json +4 -4
  46. package/plugins/pr-shepherd/package.json +1 -1
  47. package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +2 -2
  48. package/plugins/pr-shepherd/skills/pr-shepherd/references/waiting.md +8 -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": "1.3.0",
4
+ "version": "1.5.0",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
package/README.md CHANGED
@@ -209,6 +209,7 @@ Leave out the PR number to use the current branch.
209
209
  | Index of every doc | [docs/README.md](docs/README.md) |
210
210
  | Features, workflow assumptions, limits | [docs/features.md](docs/features.md) |
211
211
  | Commands, flags, stacks, polling | [docs/cli-usage.md](docs/cli-usage.md) |
212
+ | GitHub App auth (separate rate limit) | [docs/github-app.md](docs/github-app.md) |
212
213
  | Actions and exit codes | [docs/actions.md](docs/actions.md), [docs/exit-codes.md](docs/exit-codes.md) |
213
214
  | Configuration and classification rules | [docs/configuration.md](docs/configuration.md), [examples/classification/](examples/classification/) |
214
215
  | Journal, library API | [docs/api.md](docs/api.md) |
package/bin/api.mjs CHANGED
@@ -14,7 +14,9 @@ import { applyQueueRemovalAck, } from "./commands/apply-queue-removal.mjs";
14
14
  import { runWithExecutionCwd } from "./execution-context.mjs";
15
15
  import { loadConfig } from "./config/load.mjs";
16
16
  import { parsePrReference, normalizeRepositoryIdentity, resolveParsedPrTarget, } from "./pr-reference.mjs";
17
+ import { runWithAuthScope } from "./github/auth-target.mjs";
17
18
  import { getPullRequestBody, getRepoInfo } from "./github/client.mjs";
19
+ import { loadGithubApps } from "./github/github-app-config.mjs";
18
20
  import { getLocalHeadSha } from "./commands/suggestion-patch-git.mjs";
19
21
  import { extractShepherdJournal } from "./journal/index.mjs";
20
22
  /** Raised before any API mutation when an input cannot be validated. */
@@ -47,7 +49,8 @@ export function createPrShepherd(options = {}) {
47
49
  // Validate config first, as the CLI does, so a bad or pre-v1 file rejects before GitHub I/O.
48
50
  return runWithExecutionCwd(cwd, async () => {
49
51
  loadConfig();
50
- return transportRunner(work, input?.transport);
52
+ loadGithubApps();
53
+ return runWithAuthScope(() => transportRunner(work, input?.transport));
51
54
  });
52
55
  }
53
56
  function iterate(input = {}) {
@@ -37,19 +37,29 @@ function recommendation(warning) {
37
37
  }
38
38
  return "- Recommendation: keep polling pr-shepherd at the cadence above; for incidental PR reads use explicit REST endpoints such as `gh api repos/OWNER/REPO/pulls/PR`; do not substitute `gh pr checks` or `gh pr watch`";
39
39
  }
40
+ function formatChain(chain, indent) {
41
+ const lines = [];
42
+ if (chain.graphql !== undefined) {
43
+ lines.push(formatResource(chain.graphql));
44
+ lines.push(`- GraphQL measured cost: ${chain.graphql.measuredQueryCost} · unmeasured requests: ${chain.graphql.unmeasuredRequestCount} · nodes: ${chain.graphql.nodeCount}`);
45
+ }
46
+ for (const resource of chain.rest ?? [])
47
+ lines.push(formatResource(resource));
48
+ if (chain.unmeteredRestRequestCount !== undefined) {
49
+ lines.push(`- REST requests without rate-limit headers (unmetered): ${chain.unmeteredRestRequestCount}`);
50
+ }
51
+ return lines.map((line) => `${indent}${line}`);
52
+ }
40
53
  export function formatApiUsage(usage) {
41
54
  if (usage === undefined)
42
55
  return null;
43
56
  const lines = ["## GitHub API usage", ""];
44
- lines.push(`- Credential source: ${usage.credentialSources.map((source) => `\`${source}\``).join(", ")}`);
45
- if (usage.graphql !== undefined) {
46
- lines.push(formatResource(usage.graphql));
47
- lines.push(`- GraphQL measured cost: ${usage.graphql.measuredQueryCost} · unmeasured requests: ${usage.graphql.unmeasuredRequestCount} · nodes: ${usage.graphql.nodeCount}`);
57
+ if (usage.credentialSources.length > 0) {
58
+ lines.push(`- Credential source: ${usage.credentialSources.map((source) => `\`${source}\``).join(", ")}`);
48
59
  }
49
- for (const resource of usage.rest ?? [])
50
- lines.push(formatResource(resource));
51
- if (usage.unmeteredRestRequestCount !== undefined) {
52
- lines.push(`- REST requests without rate-limit headers (unmetered): ${usage.unmeteredRestRequestCount}`);
60
+ lines.push(...formatChain(usage, ""));
61
+ for (const app of usage.githubApps ?? []) {
62
+ lines.push(`- \`${app.source}\`:`, ...formatChain(app, " "));
53
63
  }
54
64
  return lines.join("\n");
55
65
  }
@@ -1,5 +1,5 @@
1
1
  export declare const COMMAND_USAGE: {
2
- readonly default: "pr-shepherd [PR]\n\nRun iterate repeatedly for one PR, or read compact summaries for an explicit same-repository PR set.\nAggregate mode returns when any row needs work, every row is terminal, or timeout.\nWhen CLAUDE_CODE_REMOTE=true, the command runs one tick like iterate and prints nextCheck instead.\nPoll exits as soon as iterate returns READY, MARK_READY, CANCEL, or ESCALATE, or when timeout\nreturns the last WAIT result. TRIAGE starts a --debounce settle window (default:\npoll.debounce-seconds; built-in 1m): poll keeps\niterating at --interval, then runs one more tick after the window and returns that result.\nWith --until-terminal or --merge, poll also continues through MARK_READY.\n\nUsage:\n pr-shepherd [PR ...] [poll-flags] [iterate-flags]\n\nUse 'pr-shepherd stack PR' for a native GitHub stack.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s). Stack and multi-PR polls multiply that by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).\n --debounce <duration> Settle window after first TRIAGE or stack SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT/MARK_READY until READY/TRIAGE/MERGE/CANCEL/ESCALATE or stack SHEPHERD.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields and detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\nEach WAIT tick writes a stderr line naming what it is waiting on by default; poll.quiet-status can change that default, --quiet-status/--no-quiet-status override it, and --verbose emits detailed per-tick lines.\nTRIAGE debounce writes a remaining-seconds line to stderr. --timeout does not cut an in-flight debounce short.\nWith --until-terminal, --timeout is ignored for WAIT ticks and polling continues until READY, TRIAGE, MERGE, CANCEL, or ESCALATE. With --merge, --timeout still bounds WAIT ticks; it only continues through MARK_READY while polling remains within that timeout.\n\nExit codes: same as iterate (the final tick's action/reason decides the code).\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY (including a WAIT returned by --timeout)\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
2
+ readonly default: "pr-shepherd [PR]\n\nRun iterate repeatedly for one PR, or read compact summaries for an explicit same-repository PR set.\nAggregate mode returns when any row needs work, every row is terminal, or timeout.\nWhen CLAUDE_CODE_REMOTE=true, the command runs one tick like iterate and prints nextCheck instead.\nPoll exits as soon as iterate returns READY, MARK_READY, CANCEL, or ESCALATE, or when timeout\nreturns the last WAIT result. TRIAGE starts a --debounce settle window (default:\npoll.debounce-seconds; built-in 1m): poll keeps\niterating at --interval, then runs one more tick after the window and returns that result.\nWith --until-terminal or --merge, poll also continues through MARK_READY.\n\nUsage:\n pr-shepherd [PR ...] [poll-flags] [iterate-flags]\n\nUse 'pr-shepherd stack PR' for a native GitHub stack.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s). Stack and multi-PR polls multiply that by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).\n --debounce <duration> Settle window after first TRIAGE or stack SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT/MARK_READY until READY/TRIAGE/MERGE/CANCEL/ESCALATE or stack SHEPHERD.\n For background runs that wake the caller on exit; foreground waits use the bounded default.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields and detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\nEach WAIT tick writes a stderr line naming what it is waiting on by default; poll.quiet-status can change that default, --quiet-status/--no-quiet-status override it, and --verbose emits detailed per-tick lines.\nTRIAGE debounce writes a remaining-seconds line to stderr. --timeout does not cut an in-flight debounce short.\nWith --until-terminal, --timeout is ignored for WAIT ticks and polling continues until READY, TRIAGE, MERGE, CANCEL, or ESCALATE. With --merge, --timeout still bounds WAIT ticks; it only continues through MARK_READY while polling remains within that timeout.\n\nExit codes: same as iterate (the final tick's action/reason decides the code).\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY (including a WAIT returned by --timeout)\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
3
3
  readonly "apply merge": `pr-shepherd apply merge
4
4
 
5
5
  Submit one SHA-guarded asynchronous merge or enqueue request with REST.
@@ -162,7 +162,7 @@ When CLAUDE_CODE_REMOTE=true, state is the durable copy under the git common dir
162
162
  --help, -h Print this help and exit before any cleanup.`;
163
163
  readonly "admin log-file": "pr-shepherd admin log-file\n\nPrint the per-worktree append-only debug log path for the current repository.\nThe log is created by the first non-help pr-shepherd command that initializes logging.\n\nUsage:\n pr-shepherd admin log-file [--format text|json]\n\nFlags:\n --format text|json Print a raw path or {\"path\": \"...\"} JSON. Default: text.\n --help, -h Print this help and exit before logging setup.\n\nEnvironment:\n PR_SHEPHERD_LOG_DISABLED=1 disables logging.\n PR_SHEPHERD_STATE_DIR overrides the base state directory.\n CLAUDE_CODE_REMOTE=true reports the durable log under the git common directory.\n\nExit code: 0 on success; 1 if repository identity cannot be resolved.";
164
164
  readonly iterate: "pr-shepherd iterate\n\nRun one tick and return without sleeping. The no-subcommand form polls; use this subcommand when the\ncaller owns the next wake-up. One PR prints one action and an action-specific ## Instructions section.\nSeveral same-repository PRs print one aggregate summary. Unless nothing remains to wait for, the output\ncarries nextCheck: when to rerun if no GitHub event arrives first.\n\nUsage:\n pr-shepherd iterate [PR ...] [iterate-flags]\n\nIterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number is minutes; decimals are allowed only with an explicit unit (4.5m).\n\nActions:\n WAIT No immediate action; continue with the next poll.\n MARK_READY Draft PR was marked ready; continue with the next poll.\n READY Clean PR is inside the ready-delay. Schedule the rerun for when remainingSeconds elapses. Do not invent unrelated work. Already-owned later work may continue.\n TRIAGE Agent action is required; follow the instructions, then continue polling.\n CANCEL Stop polling this pull request: merged/closed, ready-delay elapsed, or a clean draft left in draft because auto mark-ready is disabled. Continue remaining work from the original request.\n ESCALATE Stop polling until a human provides direction.\n MERGE Run the emitted merge/queue command, then continue monitoring.\n\nExit codes:\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
165
- readonly stack: "pr-shepherd stack\n\nShepherd every open PR in one PR's native GitHub stack, bottom to top. Each poll reads compact\nper-layer summaries and returns when a layer needs work, every layer is terminal, or timeout.\nSHEPHERD lists one-PR sessions to run before rerunning this command.\n--once, or CLAUDE_CODE_REMOTE=true, runs one aggregate tick and prints nextCheck instead of sleeping.\n\nUsage:\n pr-shepherd stack PR [--once] [poll-flags] [iterate-flags]\n\nStack flags:\n --once Run one aggregate tick without sleeping; poll flags are ignored.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s) multiplied by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).\n --debounce <duration> Settle window after the first SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT until SHEPHERD, MERGE, CANCEL, or ESCALATE.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Do not convert draft PRs to ready for review.\n --merge Shepherd through readiness, then emit the stack merge commands.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\n\nExit codes:\n 0 CANCEL (every layer merged)\n 10 WAIT\n 13 ESCALATE\n 14 CANCEL (a layer closed without merging)\n 15 MERGE\n 16 SHEPHERD (run the listed one-PR sessions, then rerun this stack command)\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
165
+ readonly stack: "pr-shepherd stack\n\nShepherd every open PR in one PR's native GitHub stack, bottom to top. Each poll reads compact\nper-layer summaries and returns when a layer needs work, every layer is terminal, or timeout.\nSHEPHERD lists one-PR sessions to run before rerunning this command.\n--once, or CLAUDE_CODE_REMOTE=true, runs one aggregate tick and prints nextCheck instead of sleeping.\n\nUsage:\n pr-shepherd stack PR [--once] [poll-flags] [iterate-flags]\n\nStack flags:\n --once Run one aggregate tick without sleeping; poll flags are ignored.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s) multiplied by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).\n --debounce <duration> Settle window after the first SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT until SHEPHERD, MERGE, CANCEL, or ESCALATE.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Do not convert draft PRs to ready for review.\n --merge Shepherd through readiness, then emit the stack merge commands.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\n\nExit codes:\n 0 CANCEL (every layer merged)\n 10 WAIT\n 13 ESCALATE\n 14 CANCEL (a layer closed without merging)\n 15 MERGE\n 16 SHEPHERD (run the listed one-PR sessions, then rerun this stack command)\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
166
166
  readonly "journal extract": `pr-shepherd journal extract
167
167
 
168
168
  Extract one visible, structurally valid Shepherd Journal from a local PR-body file.
@@ -1,5 +1,5 @@
1
1
  export declare const ITERATE_USAGE = "pr-shepherd iterate\n\nRun one tick and return without sleeping. The no-subcommand form polls; use this subcommand when the\ncaller owns the next wake-up. One PR prints one action and an action-specific ## Instructions section.\nSeveral same-repository PRs print one aggregate summary. Unless nothing remains to wait for, the output\ncarries nextCheck: when to rerun if no GitHub event arrives first.\n\nUsage:\n pr-shepherd iterate [PR ...] [iterate-flags]\n\nIterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number is minutes; decimals are allowed only with an explicit unit (4.5m).\n\nActions:\n WAIT No immediate action; continue with the next poll.\n MARK_READY Draft PR was marked ready; continue with the next poll.\n READY Clean PR is inside the ready-delay. Schedule the rerun for when remainingSeconds elapses. Do not invent unrelated work. Already-owned later work may continue.\n TRIAGE Agent action is required; follow the instructions, then continue polling.\n CANCEL Stop polling this pull request: merged/closed, ready-delay elapsed, or a clean draft left in draft because auto mark-ready is disabled. Continue remaining work from the original request.\n ESCALATE Stop polling until a human provides direction.\n MERGE Run the emitted merge/queue command, then continue monitoring.\n\nExit codes:\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
2
2
  /** Public help page for the default PR polling invocation. */
3
- export declare const DEFAULT_USAGE = "pr-shepherd [PR]\n\nRun iterate repeatedly for one PR, or read compact summaries for an explicit same-repository PR set.\nAggregate mode returns when any row needs work, every row is terminal, or timeout.\nWhen CLAUDE_CODE_REMOTE=true, the command runs one tick like iterate and prints nextCheck instead.\nPoll exits as soon as iterate returns READY, MARK_READY, CANCEL, or ESCALATE, or when timeout\nreturns the last WAIT result. TRIAGE starts a --debounce settle window (default:\npoll.debounce-seconds; built-in 1m): poll keeps\niterating at --interval, then runs one more tick after the window and returns that result.\nWith --until-terminal or --merge, poll also continues through MARK_READY.\n\nUsage:\n pr-shepherd [PR ...] [poll-flags] [iterate-flags]\n\nUse 'pr-shepherd stack PR' for a native GitHub stack.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s). Stack and multi-PR polls multiply that by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).\n --debounce <duration> Settle window after first TRIAGE or stack SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT/MARK_READY until READY/TRIAGE/MERGE/CANCEL/ESCALATE or stack SHEPHERD.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields and detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\nEach WAIT tick writes a stderr line naming what it is waiting on by default; poll.quiet-status can change that default, --quiet-status/--no-quiet-status override it, and --verbose emits detailed per-tick lines.\nTRIAGE debounce writes a remaining-seconds line to stderr. --timeout does not cut an in-flight debounce short.\nWith --until-terminal, --timeout is ignored for WAIT ticks and polling continues until READY, TRIAGE, MERGE, CANCEL, or ESCALATE. With --merge, --timeout still bounds WAIT ticks; it only continues through MARK_READY while polling remains within that timeout.\n\nExit codes: same as iterate (the final tick's action/reason decides the code).\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY (including a WAIT returned by --timeout)\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
3
+ export declare const DEFAULT_USAGE = "pr-shepherd [PR]\n\nRun iterate repeatedly for one PR, or read compact summaries for an explicit same-repository PR set.\nAggregate mode returns when any row needs work, every row is terminal, or timeout.\nWhen CLAUDE_CODE_REMOTE=true, the command runs one tick like iterate and prints nextCheck instead.\nPoll exits as soon as iterate returns READY, MARK_READY, CANCEL, or ESCALATE, or when timeout\nreturns the last WAIT result. TRIAGE starts a --debounce settle window (default:\npoll.debounce-seconds; built-in 1m): poll keeps\niterating at --interval, then runs one more tick after the window and returns that result.\nWith --until-terminal or --merge, poll also continues through MARK_READY.\n\nUsage:\n pr-shepherd [PR ...] [poll-flags] [iterate-flags]\n\nUse 'pr-shepherd stack PR' for a native GitHub stack.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s). Stack and multi-PR polls multiply that by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).\n --debounce <duration> Settle window after first TRIAGE or stack SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT/MARK_READY until READY/TRIAGE/MERGE/CANCEL/ESCALATE or stack SHEPHERD.\n For background runs that wake the caller on exit; foreground waits use the bounded default.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields and detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\nEach WAIT tick writes a stderr line naming what it is waiting on by default; poll.quiet-status can change that default, --quiet-status/--no-quiet-status override it, and --verbose emits detailed per-tick lines.\nTRIAGE debounce writes a remaining-seconds line to stderr. --timeout does not cut an in-flight debounce short.\nWith --until-terminal, --timeout is ignored for WAIT ticks and polling continues until READY, TRIAGE, MERGE, CANCEL, or ESCALATE. With --merge, --timeout still bounds WAIT ticks; it only continues through MARK_READY while polling remains within that timeout.\n\nExit codes: same as iterate (the final tick's action/reason decides the code).\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY (including a WAIT returned by --timeout)\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
4
4
  /** Public help page for `pr-shepherd stack`. */
5
- export declare const STACK_USAGE = "pr-shepherd stack\n\nShepherd every open PR in one PR's native GitHub stack, bottom to top. Each poll reads compact\nper-layer summaries and returns when a layer needs work, every layer is terminal, or timeout.\nSHEPHERD lists one-PR sessions to run before rerunning this command.\n--once, or CLAUDE_CODE_REMOTE=true, runs one aggregate tick and prints nextCheck instead of sleeping.\n\nUsage:\n pr-shepherd stack PR [--once] [poll-flags] [iterate-flags]\n\nStack flags:\n --once Run one aggregate tick without sleeping; poll flags are ignored.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s) multiplied by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).\n --debounce <duration> Settle window after the first SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT until SHEPHERD, MERGE, CANCEL, or ESCALATE.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Do not convert draft PRs to ready for review.\n --merge Shepherd through readiness, then emit the stack merge commands.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\n\nExit codes:\n 0 CANCEL (every layer merged)\n 10 WAIT\n 13 ESCALATE\n 14 CANCEL (a layer closed without merging)\n 15 MERGE\n 16 SHEPHERD (run the listed one-PR sessions, then rerun this stack command)\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
5
+ export declare const STACK_USAGE = "pr-shepherd stack\n\nShepherd every open PR in one PR's native GitHub stack, bottom to top. Each poll reads compact\nper-layer summaries and returns when a layer needs work, every layer is terminal, or timeout.\nSHEPHERD lists one-PR sessions to run before rerunning this command.\n--once, or CLAUDE_CODE_REMOTE=true, runs one aggregate tick and prints nextCheck instead of sleeping.\n\nUsage:\n pr-shepherd stack PR [--once] [poll-flags] [iterate-flags]\n\nStack flags:\n --once Run one aggregate tick without sleeping; poll flags are ignored.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s) multiplied by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).\n --debounce <duration> Settle window after the first SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT until SHEPHERD, MERGE, CANCEL, or ESCALATE.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Do not convert draft PRs to ready for review.\n --merge Shepherd through readiness, then emit the stack merge commands.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\n\nExit codes:\n 0 CANCEL (every layer merged)\n 10 WAIT\n 13 ESCALATE\n 14 CANCEL (a layer closed without merging)\n 15 MERGE\n 16 SHEPHERD (run the listed one-PR sessions, then rerun this stack command)\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
@@ -58,11 +58,12 @@ Use 'pr-shepherd stack PR' for a native GitHub stack.
58
58
 
59
59
  Poll flags:
60
60
  --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s). Stack and multi-PR polls multiply that by poll.stack-interval-factor (built-in 2) unless this flag is set.
61
- --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).
61
+ --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).
62
62
  --debounce <duration> Settle window after first TRIAGE or stack SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.
63
63
  --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.
64
64
  --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.
65
65
  --until-terminal Continue through WAIT/MARK_READY until READY/TRIAGE/MERGE/CANCEL/ESCALATE or stack SHEPHERD.
66
+ For background runs that wake the caller on exit; foreground waits use the bounded default.
66
67
 
67
68
  Forwarded iterate flags:
68
69
  --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.
@@ -107,7 +108,7 @@ Stack flags:
107
108
 
108
109
  Poll flags:
109
110
  --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s) multiplied by poll.stack-interval-factor (built-in 2) unless this flag is set.
110
- --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).
111
+ --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).
111
112
  --debounce <duration> Settle window after the first SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.
112
113
  --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.
113
114
  --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.
@@ -1,5 +1,5 @@
1
1
  export declare const USAGE: {
2
- readonly default: "pr-shepherd [PR]\n\nRun iterate repeatedly for one PR, or read compact summaries for an explicit same-repository PR set.\nAggregate mode returns when any row needs work, every row is terminal, or timeout.\nWhen CLAUDE_CODE_REMOTE=true, the command runs one tick like iterate and prints nextCheck instead.\nPoll exits as soon as iterate returns READY, MARK_READY, CANCEL, or ESCALATE, or when timeout\nreturns the last WAIT result. TRIAGE starts a --debounce settle window (default:\npoll.debounce-seconds; built-in 1m): poll keeps\niterating at --interval, then runs one more tick after the window and returns that result.\nWith --until-terminal or --merge, poll also continues through MARK_READY.\n\nUsage:\n pr-shepherd [PR ...] [poll-flags] [iterate-flags]\n\nUse 'pr-shepherd stack PR' for a native GitHub stack.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s). Stack and multi-PR polls multiply that by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).\n --debounce <duration> Settle window after first TRIAGE or stack SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT/MARK_READY until READY/TRIAGE/MERGE/CANCEL/ESCALATE or stack SHEPHERD.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields and detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\nEach WAIT tick writes a stderr line naming what it is waiting on by default; poll.quiet-status can change that default, --quiet-status/--no-quiet-status override it, and --verbose emits detailed per-tick lines.\nTRIAGE debounce writes a remaining-seconds line to stderr. --timeout does not cut an in-flight debounce short.\nWith --until-terminal, --timeout is ignored for WAIT ticks and polling continues until READY, TRIAGE, MERGE, CANCEL, or ESCALATE. With --merge, --timeout still bounds WAIT ticks; it only continues through MARK_READY while polling remains within that timeout.\n\nExit codes: same as iterate (the final tick's action/reason decides the code).\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY (including a WAIT returned by --timeout)\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
2
+ readonly default: "pr-shepherd [PR]\n\nRun iterate repeatedly for one PR, or read compact summaries for an explicit same-repository PR set.\nAggregate mode returns when any row needs work, every row is terminal, or timeout.\nWhen CLAUDE_CODE_REMOTE=true, the command runs one tick like iterate and prints nextCheck instead.\nPoll exits as soon as iterate returns READY, MARK_READY, CANCEL, or ESCALATE, or when timeout\nreturns the last WAIT result. TRIAGE starts a --debounce settle window (default:\npoll.debounce-seconds; built-in 1m): poll keeps\niterating at --interval, then runs one more tick after the window and returns that result.\nWith --until-terminal or --merge, poll also continues through MARK_READY.\n\nUsage:\n pr-shepherd [PR ...] [poll-flags] [iterate-flags]\n\nUse 'pr-shepherd stack PR' for a native GitHub stack.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s). Stack and multi-PR polls multiply that by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).\n --debounce <duration> Settle window after first TRIAGE or stack SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT/MARK_READY until READY/TRIAGE/MERGE/CANCEL/ESCALATE or stack SHEPHERD.\n For background runs that wake the caller on exit; foreground waits use the bounded default.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields and detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\nEach WAIT tick writes a stderr line naming what it is waiting on by default; poll.quiet-status can change that default, --quiet-status/--no-quiet-status override it, and --verbose emits detailed per-tick lines.\nTRIAGE debounce writes a remaining-seconds line to stderr. --timeout does not cut an in-flight debounce short.\nWith --until-terminal, --timeout is ignored for WAIT ticks and polling continues until READY, TRIAGE, MERGE, CANCEL, or ESCALATE. With --merge, --timeout still bounds WAIT ticks; it only continues through MARK_READY while polling remains within that timeout.\n\nExit codes: same as iterate (the final tick's action/reason decides the code).\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY (including a WAIT returned by --timeout)\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
3
3
  readonly "apply merge": `pr-shepherd apply merge
4
4
 
5
5
  Submit one SHA-guarded asynchronous merge or enqueue request with REST.
@@ -162,7 +162,7 @@ When CLAUDE_CODE_REMOTE=true, state is the durable copy under the git common dir
162
162
  --help, -h Print this help and exit before any cleanup.`;
163
163
  readonly "admin log-file": "pr-shepherd admin log-file\n\nPrint the per-worktree append-only debug log path for the current repository.\nThe log is created by the first non-help pr-shepherd command that initializes logging.\n\nUsage:\n pr-shepherd admin log-file [--format text|json]\n\nFlags:\n --format text|json Print a raw path or {\"path\": \"...\"} JSON. Default: text.\n --help, -h Print this help and exit before logging setup.\n\nEnvironment:\n PR_SHEPHERD_LOG_DISABLED=1 disables logging.\n PR_SHEPHERD_STATE_DIR overrides the base state directory.\n CLAUDE_CODE_REMOTE=true reports the durable log under the git common directory.\n\nExit code: 0 on success; 1 if repository identity cannot be resolved.";
164
164
  readonly iterate: "pr-shepherd iterate\n\nRun one tick and return without sleeping. The no-subcommand form polls; use this subcommand when the\ncaller owns the next wake-up. One PR prints one action and an action-specific ## Instructions section.\nSeveral same-repository PRs print one aggregate summary. Unless nothing remains to wait for, the output\ncarries nextCheck: when to rerun if no GitHub event arrives first.\n\nUsage:\n pr-shepherd iterate [PR ...] [iterate-flags]\n\nIterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Leave draft PRs in draft; stop when otherwise ready.\n --merge Shepherd through readiness, then emit a merge or merge-queue command.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include verbose iterate fields.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number is minutes; decimals are allowed only with an explicit unit (4.5m).\n\nActions:\n WAIT No immediate action; continue with the next poll.\n MARK_READY Draft PR was marked ready; continue with the next poll.\n READY Clean PR is inside the ready-delay. Schedule the rerun for when remainingSeconds elapses. Do not invent unrelated work. Already-owned later work may continue.\n TRIAGE Agent action is required; follow the instructions, then continue polling.\n CANCEL Stop polling this pull request: merged/closed, ready-delay elapsed, or a clean draft left in draft because auto mark-ready is disabled. Continue remaining work from the original request.\n ESCALATE Stop polling until a human provides direction.\n MERGE Run the emitted merge/queue command, then continue monitoring.\n\nExit codes:\n 0 CANCEL (merged, ready-delay elapsed, or clean draft left in draft by disabled auto mark-ready)\n 10 WAIT or READY\n 11 MARK_READY\n 12 TRIAGE\n 13 ESCALATE\n 14 CANCEL (closed without merging)\n 15 MERGE\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
165
- readonly stack: "pr-shepherd stack\n\nShepherd every open PR in one PR's native GitHub stack, bottom to top. Each poll reads compact\nper-layer summaries and returns when a layer needs work, every layer is terminal, or timeout.\nSHEPHERD lists one-PR sessions to run before rerunning this command.\n--once, or CLAUDE_CODE_REMOTE=true, runs one aggregate tick and prints nextCheck instead of sleeping.\n\nUsage:\n pr-shepherd stack PR [--once] [poll-flags] [iterate-flags]\n\nStack flags:\n --once Run one aggregate tick without sleeping; poll flags are ignored.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s) multiplied by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m).\n --debounce <duration> Settle window after the first SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT until SHEPHERD, MERGE, CANCEL, or ESCALATE.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Do not convert draft PRs to ready for review.\n --merge Shepherd through readiness, then emit the stack merge commands.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\n\nExit codes:\n 0 CANCEL (every layer merged)\n 10 WAIT\n 13 ESCALATE\n 14 CANCEL (a layer closed without merging)\n 15 MERGE\n 16 SHEPHERD (run the listed one-PR sessions, then rerun this stack command)\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
165
+ readonly stack: "pr-shepherd stack\n\nShepherd every open PR in one PR's native GitHub stack, bottom to top. Each poll reads compact\nper-layer summaries and returns when a layer needs work, every layer is terminal, or timeout.\nSHEPHERD lists one-PR sessions to run before rerunning this command.\n--once, or CLAUDE_CODE_REMOTE=true, runs one aggregate tick and prints nextCheck instead of sleeping.\n\nUsage:\n pr-shepherd stack PR [--once] [poll-flags] [iterate-flags]\n\nStack flags:\n --once Run one aggregate tick without sleeping; poll flags are ignored.\n\nPoll flags:\n --interval <duration> Sleep between WAIT ticks. Bare number = seconds. Default: poll.interval-seconds (built-in 60s) multiplied by poll.stack-interval-factor (built-in 2) unless this flag is set.\n --timeout <duration> Maximum wall-clock wait for WAIT ticks. Bare number = seconds. Default: poll.timeout-seconds (built-in 4.5m, for foreground waits).\n --debounce <duration> Settle window after the first SHEPHERD before returning. Bare number = seconds. Default: poll.debounce-seconds (built-in 60s). 0 disables.\n --quiet-status Print only changed WAIT snapshots. Overrides poll.quiet-status.\n --no-quiet-status Print every WAIT snapshot. Overrides poll.quiet-status.\n --until-terminal Continue through WAIT until SHEPHERD, MERGE, CANCEL, or ESCALATE.\n\nForwarded iterate flags:\n --ready-delay <duration> Settle window before a clean PR cancels. Bare number = minutes. Default: iterate.ready-delay-minutes (built-in 0). Example: 15m.\n --stall-timeout <duration> Escalate repeated unchanged failures after this duration. Bare number = minutes. 0 disables.\n --no-auto-mark-ready Do not convert draft PRs to ready for review.\n --merge Shepherd through readiness, then emit the stack merge commands.\n --instructions playbook|inline Render triage steps inline every tick (default) or fold the invariant ones into a playbook pointer. Default: iterate.instructions (inline).\n --transport auto|graphql|rest Select GitHub transport. Default: github.transport (auto).\n --format text|json Output Markdown text or JSON. Default: text.\n --verbose Include detailed per-tick lines.\n --help, -h Print this help and exit before GitHub, git, config, or log I/O.\n\nDurations accept s/m/h suffixes: 30s, 4.5m, 1h. A bare number uses each flag's default unit (seconds\nfor --interval/--timeout/--debounce, minutes for --ready-delay/--stall-timeout); decimals are allowed only with\nan explicit unit (4.5m).\n\nExit codes:\n 0 CANCEL (every layer merged)\n 10 WAIT\n 13 ESCALATE\n 14 CANCEL (a layer closed without merging)\n 15 MERGE\n 16 SHEPHERD (run the listed one-PR sessions, then rerun this stack command)\n A command/validation/GitHub failure exits with a sysexits.h code instead (see docs/exit-codes.md).";
166
166
  readonly "journal extract": `pr-shepherd journal extract
167
167
 
168
168
  Extract one visible, structurally valid Shepherd Journal from a local PR-body file.
@@ -24,6 +24,8 @@ import { handleApplyMerge } from "./cli/apply-merge-handler.mjs";
24
24
  import { getLocalHeadSha } from "./commands/suggestion-patch-git.mjs";
25
25
  import { extractTransportArgs } from "./cli/transport-args.mjs";
26
26
  import { parseGithubTransport } from "./github/transport-mode.mjs";
27
+ import { runWithAuthScope } from "./github/auth-target.mjs";
28
+ import { loadGithubApps } from "./github/github-app-config.mjs";
27
29
  import { runWithGithubTransport } from "./github/transport.mjs";
28
30
  // ---------------------------------------------------------------------------
29
31
  // Entry
@@ -53,6 +55,7 @@ export async function main(argv) {
53
55
  // Validate config before any GitHub work, so a bad or pre-v1 config file exits 78 up front.
54
56
  try {
55
57
  loadConfig();
58
+ loadGithubApps();
56
59
  }
57
60
  catch (error) {
58
61
  if (!(error instanceof ShepherdError))
@@ -61,9 +64,9 @@ export async function main(argv) {
61
64
  process.exitCode = error.exitCode;
62
65
  return;
63
66
  }
64
- return runWithGithubTransport(mode, () => dispatch(dispatched), {
67
+ return runWithAuthScope(() => runWithGithubTransport(mode, () => dispatch(dispatched), {
65
68
  verbose: extracted.args.includes("--verbose"),
66
- });
69
+ }));
67
70
  }
68
71
  async function dispatch(argv) {
69
72
  const args = argv.slice(2); // strip node + script path
@@ -13,7 +13,7 @@ export function onlyDraftVerificationSelection(result) {
13
13
  isDraftReadinessVerification(item)));
14
14
  }
15
15
  /** Rerunning is mandatory while any selected row is non-terminal; a finished one-PR poll is not the end. */
16
- const KEEP_WATCHING = "Do not end the turn while any selected row is non-terminal: a one-PR poll returning `CANCEL` or `ESCALATE` finishes only that row, and rows that are `CANCEL`, `ESCALATE`, or handed off do not count.";
16
+ const KEEP_WATCHING = "Do not end the turn while any selected row is non-terminal: a one-PR poll returning `CANCEL` or `ESCALATE` finishes only that row, and rows that are `CANCEL`, `ESCALATE`, or handed off do not count. If a background exit wakes you, end the turn and continue then.";
17
17
  export function explicitInstructions(result, rerunCommand) {
18
18
  const again = rerunCommand ? `\`${rerunCommand}\`` : "this aggregate command";
19
19
  if (result.reason === "all_terminal")
@@ -86,6 +86,7 @@ async function withAggregateNextCheck(result, opts) {
86
86
  function withoutPollingCadence(step) {
87
87
  return step
88
88
  .replace(/ Recheck(?: them)? at the configured polling cadence\./g, "")
89
+ .replace(" If a background exit wakes you, end the turn and continue then.", "")
89
90
  .replace(/Do not end the turn while any selected row is non-terminal: /g, "Keep watching every non-terminal selected row through the wake-up below: ")
90
91
  .replace("rerun that command at the configured cadence to resume its UUID", "rerun that command after the wake-up below to resume its UUID");
91
92
  }
@@ -0,0 +1,4 @@
1
+ import type { RateLimitInfo } from "./http-utils.mts";
2
+ import type { RestTelemetryGroup, TelemetryAggregate } from "./api-telemetry-aggregate.mts";
3
+ export declare function adoptGraphqlRateLimit(graphql: TelemetryAggregate["graphql"], candidate: RateLimitInfo, fingerprint: string | undefined): void;
4
+ export declare function adoptRestRateLimit(group: RestTelemetryGroup, candidate: RateLimitInfo, fingerprint: string | undefined, sequence: number | undefined, latestCredentialFingerprint?: string | undefined, latestCredentialSequence?: number | undefined): void;
@@ -0,0 +1,52 @@
1
+ import { mostConservativeSample } from "./rate-limit-sample.mjs";
2
+ export function adoptGraphqlRateLimit(graphql, candidate, fingerprint) {
3
+ // Two credentials' samples are compared whole, never mixed: a mixed sample would be
4
+ // attributed to whichever credential supplied the changed half.
5
+ const sameCredential = fingerprint === undefined ||
6
+ graphql.credentialFingerprint === undefined ||
7
+ fingerprint === graphql.credentialFingerprint;
8
+ const next = selectAuthoritativeRateLimit(graphql.rateLimit, candidate, sameCredential);
9
+ if (next !== graphql.rateLimit)
10
+ graphql.credentialFingerprint = fingerprint;
11
+ graphql.rateLimit = next;
12
+ }
13
+ export function adoptRestRateLimit(group, candidate, fingerprint, sequence, latestCredentialFingerprint = fingerprint, latestCredentialSequence = sequence) {
14
+ const credentialChanged = group.latestCredentialFingerprint !== undefined &&
15
+ latestCredentialFingerprint !== undefined &&
16
+ group.latestCredentialFingerprint !== latestCredentialFingerprint;
17
+ const olderCredentialObservation = credentialChanged &&
18
+ group.latestCredentialSequence !== undefined &&
19
+ latestCredentialSequence !== undefined &&
20
+ latestCredentialSequence < group.latestCredentialSequence;
21
+ if (olderCredentialObservation)
22
+ return;
23
+ if (group.rateLimit === undefined || credentialChanged) {
24
+ group.rateLimit = { ...candidate };
25
+ group.credentialFingerprint = fingerprint;
26
+ }
27
+ else {
28
+ const next = selectAuthoritativeRateLimit(group.rateLimit, candidate);
29
+ if (next !== group.rateLimit) {
30
+ group.rateLimit = next;
31
+ group.credentialFingerprint = fingerprint;
32
+ }
33
+ }
34
+ if (latestCredentialFingerprint !== undefined &&
35
+ (group.latestCredentialSequence === undefined ||
36
+ latestCredentialSequence === undefined ||
37
+ latestCredentialSequence >= group.latestCredentialSequence)) {
38
+ group.latestCredentialFingerprint = latestCredentialFingerprint;
39
+ group.latestCredentialSequence = latestCredentialSequence;
40
+ }
41
+ }
42
+ function selectAuthoritativeRateLimit(current, candidate, sameCredential = true) {
43
+ if (current === undefined)
44
+ return { ...candidate };
45
+ if (candidate.resetAt !== current.resetAt) {
46
+ return candidate.resetAt > current.resetAt ? { ...candidate } : current;
47
+ }
48
+ if (!sameCredential)
49
+ return candidate.remaining < current.remaining ? { ...candidate } : current;
50
+ const merged = mostConservativeSample(current, candidate);
51
+ return merged.remaining === current.remaining && merged.used === current.used ? current : merged;
52
+ }
@@ -1,6 +1,6 @@
1
1
  import type { ApiTelemetryEvent } from "./api-telemetry.mts";
2
2
  import type { RateLimitInfo } from "./http-utils.mts";
3
- interface RestTelemetryGroup {
3
+ export interface RestTelemetryGroup {
4
4
  /** Quota-consuming requests; 304 Not Modified responses are tallied separately. */
5
5
  requestCount: number;
6
6
  notModifiedCount: number;
@@ -25,6 +25,11 @@ export interface TelemetryAggregate {
25
25
  rest: Map<string, RestTelemetryGroup>;
26
26
  /** Headerless REST responses (not 304s), kept out of every resource group: the proxy's `ccr` routes. */
27
27
  unmeteredRestRequestCount: number;
28
+ /**
29
+ * GitHub App installation requests, kept apart so the fields above describe only the user's
30
+ * token chain. Keyed by installation source; each value's own `apps` is empty.
31
+ */
32
+ apps: Map<string, TelemetryAggregate>;
28
33
  }
29
34
  export interface SequencedApiTelemetryEvent extends ApiTelemetryEvent {
30
35
  sequence: number;
@@ -41,4 +46,3 @@ export declare function emptyAggregate(): TelemetryAggregate;
41
46
  export declare function aggregateEvents(events: SequencedApiTelemetryEvent[]): TelemetryAggregate;
42
47
  export declare function mergeAggregate(target: TelemetryAggregate, source: TelemetryAggregate): void;
43
48
  export declare function aggregateStore(active: TelemetryStore): TelemetryAggregate;
44
- export {};
@@ -1,4 +1,4 @@
1
- import { mostConservativeSample } from "./rate-limit-sample.mjs";
1
+ import { adoptGraphqlRateLimit, adoptRestRateLimit } from "./api-telemetry-adopt.mjs";
2
2
  export function emptyAggregate() {
3
3
  return {
4
4
  eventCount: 0,
@@ -6,12 +6,20 @@ export function emptyAggregate() {
6
6
  graphql: { requestCount: 0, measuredQueryCost: 0, unmeasuredRequestCount: 0, nodeCount: 0 },
7
7
  rest: new Map(),
8
8
  unmeteredRestRequestCount: 0,
9
+ apps: new Map(),
9
10
  };
10
11
  }
11
12
  export function aggregateEvents(events) {
12
13
  const aggregate = emptyAggregate();
14
+ const appEvents = new Map();
13
15
  for (const event of events) {
14
16
  aggregate.eventCount += 1;
17
+ if (event.githubApp) {
18
+ const group = appEvents.get(event.authSource) ?? [];
19
+ group.push(event);
20
+ appEvents.set(event.authSource, group);
21
+ continue;
22
+ }
15
23
  if (!aggregate.credentialSources.has(event.authSource)) {
16
24
  aggregate.credentialSources.set(event.authSource, event.sequence);
17
25
  }
@@ -42,6 +50,11 @@ export function aggregateEvents(events) {
42
50
  adoptRestRateLimit(group, sample, event.credentialFingerprint, event.sequence);
43
51
  aggregate.rest.set(resource, group);
44
52
  }
53
+ for (const [source, group] of appEvents) {
54
+ // Re-aggregate as a plain chain: clearing the flag keeps the nested pass from splitting again.
55
+ const chain = group.map((event) => ({ ...event, githubApp: false }));
56
+ aggregate.apps.set(source, aggregateEvents(chain));
57
+ }
45
58
  return aggregate;
46
59
  }
47
60
  export function mergeAggregate(target, source) {
@@ -57,6 +70,11 @@ export function mergeAggregate(target, source) {
57
70
  target.graphql.unmeasuredRequestCount += source.graphql.unmeasuredRequestCount;
58
71
  target.graphql.nodeCount += source.graphql.nodeCount;
59
72
  target.unmeteredRestRequestCount += source.unmeteredRestRequestCount;
73
+ for (const [appSource, sourceApp] of source.apps) {
74
+ const targetApp = target.apps.get(appSource) ?? emptyAggregate();
75
+ mergeAggregate(targetApp, sourceApp);
76
+ target.apps.set(appSource, targetApp);
77
+ }
60
78
  if (source.graphql.rateLimit !== undefined) {
61
79
  adoptGraphqlRateLimit(target.graphql, source.graphql.rateLimit, source.graphql.credentialFingerprint);
62
80
  }
@@ -76,54 +94,3 @@ export function aggregateStore(active) {
76
94
  mergeAggregate(all, aggregateEvents(active.events));
77
95
  return all;
78
96
  }
79
- function adoptGraphqlRateLimit(graphql, candidate, fingerprint) {
80
- // Two credentials' samples are compared whole, never mixed: a mixed sample would be
81
- // attributed to whichever credential supplied the changed half.
82
- const sameCredential = fingerprint === undefined ||
83
- graphql.credentialFingerprint === undefined ||
84
- fingerprint === graphql.credentialFingerprint;
85
- const next = selectAuthoritativeRateLimit(graphql.rateLimit, candidate, sameCredential);
86
- if (next !== graphql.rateLimit)
87
- graphql.credentialFingerprint = fingerprint;
88
- graphql.rateLimit = next;
89
- }
90
- function adoptRestRateLimit(group, candidate, fingerprint, sequence, latestCredentialFingerprint = fingerprint, latestCredentialSequence = sequence) {
91
- const credentialChanged = group.latestCredentialFingerprint !== undefined &&
92
- latestCredentialFingerprint !== undefined &&
93
- group.latestCredentialFingerprint !== latestCredentialFingerprint;
94
- const olderCredentialObservation = credentialChanged &&
95
- group.latestCredentialSequence !== undefined &&
96
- latestCredentialSequence !== undefined &&
97
- latestCredentialSequence < group.latestCredentialSequence;
98
- if (olderCredentialObservation)
99
- return;
100
- if (group.rateLimit === undefined || credentialChanged) {
101
- group.rateLimit = { ...candidate };
102
- group.credentialFingerprint = fingerprint;
103
- }
104
- else {
105
- const next = selectAuthoritativeRateLimit(group.rateLimit, candidate);
106
- if (next !== group.rateLimit) {
107
- group.rateLimit = next;
108
- group.credentialFingerprint = fingerprint;
109
- }
110
- }
111
- if (latestCredentialFingerprint !== undefined &&
112
- (group.latestCredentialSequence === undefined ||
113
- latestCredentialSequence === undefined ||
114
- latestCredentialSequence >= group.latestCredentialSequence)) {
115
- group.latestCredentialFingerprint = latestCredentialFingerprint;
116
- group.latestCredentialSequence = latestCredentialSequence;
117
- }
118
- }
119
- function selectAuthoritativeRateLimit(current, candidate, sameCredential = true) {
120
- if (current === undefined)
121
- return { ...candidate };
122
- if (candidate.resetAt !== current.resetAt) {
123
- return candidate.resetAt > current.resetAt ? { ...candidate } : current;
124
- }
125
- if (!sameCredential)
126
- return candidate.remaining < current.remaining ? { ...candidate } : current;
127
- const merged = mostConservativeSample(current, candidate);
128
- return merged.remaining === current.remaining && merged.used === current.used ? current : merged;
129
- }
@@ -0,0 +1,4 @@
1
+ import type { ApiUsage } from "../types.mts";
2
+ import type { TelemetryAggregate } from "./api-telemetry-aggregate.mts";
3
+ /** Top level covers the user's token chain only; each GitHub App installation is its own entry. */
4
+ export declare function summarizeAggregate(selected: TelemetryAggregate): ApiUsage | undefined;
@@ -0,0 +1,63 @@
1
+ function orderedSources(selected) {
2
+ return [...selected.credentialSources.entries()]
3
+ .sort((left, right) => left[1] - right[1])
4
+ .map(([source]) => source);
5
+ }
6
+ /** Usage of one credential chain: per-resource counts, costs, nodes and quota sample. */
7
+ function summarizeChain(selected) {
8
+ const graphql = summarizeGraphql(selected.graphql);
9
+ const rest = summarizeRest(selected.rest);
10
+ const unmeteredRestRequestCount = selected.unmeteredRestRequestCount;
11
+ return {
12
+ ...(graphql !== undefined && { graphql }),
13
+ ...(rest.length > 0 && { rest }),
14
+ ...(unmeteredRestRequestCount > 0 && { unmeteredRestRequestCount }),
15
+ };
16
+ }
17
+ /** Top level covers the user's token chain only; each GitHub App installation is its own entry. */
18
+ export function summarizeAggregate(selected) {
19
+ if (selected.eventCount === 0)
20
+ return undefined;
21
+ const githubApps = [...selected.apps.values()]
22
+ .map((app) => ({ app, first: Math.min(...app.credentialSources.values()) }))
23
+ .sort((left, right) => left.first - right.first)
24
+ .map(({ app }) => {
25
+ const { graphql, rest } = summarizeChain(app);
26
+ return {
27
+ source: orderedSources(app)[0],
28
+ ...(graphql !== undefined && { graphql }),
29
+ ...(rest !== undefined && { rest }),
30
+ };
31
+ });
32
+ return {
33
+ credentialSources: orderedSources(selected),
34
+ ...summarizeChain(selected),
35
+ ...(githubApps.length > 0 && { githubApps }),
36
+ };
37
+ }
38
+ function summarizeGraphql(selected) {
39
+ if (selected.rateLimit === undefined)
40
+ return undefined;
41
+ return {
42
+ ...resourceUsage(selected.rateLimit, selected.requestCount, "graphql"),
43
+ measuredQueryCost: selected.measuredQueryCost,
44
+ unmeasuredRequestCount: selected.unmeasuredRequestCount,
45
+ nodeCount: selected.nodeCount,
46
+ };
47
+ }
48
+ function summarizeRest(selected) {
49
+ return [...selected.entries()].flatMap(([resource, group]) => group.rateLimit
50
+ ? [resourceUsage(group.rateLimit, group.requestCount, resource, group.notModifiedCount)]
51
+ : []);
52
+ }
53
+ function resourceUsage(rateLimit, requestCount, fallbackResource, notModified = 0) {
54
+ return {
55
+ resource: rateLimit.resource ?? fallbackResource,
56
+ ...(requestCount > 0 && { requestCount }),
57
+ ...(notModified > 0 && { notModified }),
58
+ limit: rateLimit.limit,
59
+ ...(rateLimit.used !== undefined && { used: rateLimit.used }),
60
+ remaining: rateLimit.remaining,
61
+ resetAt: rateLimit.resetAt,
62
+ };
63
+ }
@@ -4,6 +4,8 @@ export interface ApiTelemetryEvent {
4
4
  kind: "GraphQL" | "REST";
5
5
  method: string;
6
6
  authSource: string;
7
+ /** True when a GitHub App installation token answered this request, not the user's chain. */
8
+ githubApp: boolean;
7
9
  /** Truncated SHA-256 of the credential that produced this request. */
8
10
  credentialFingerprint?: string;
9
11
  rateLimit?: RateLimitInfo;