Skip to content

Commit 99bffe2

Browse files
authored
Rebase onto upstream/master (2026-08-05): 171 commits (2f42a49..d5b9f6c) (#320)
Supersedes #312. Brings in upstream 2f42a49..d5b9f6c — 171 commits including Connections v3 schema core, AppDefinition Wave 1 catalog, status cards, task-scoped sandbox egress grants, native file-sync lifecycle hooks, run-bound agent secret access, routines activity gate API, sandbox exec optimisations, and dependency bumps. Migrations 0185–0198 renumbered +3 for the fork offset. Journal idx defect from #312 fixed.
2 parents 9d742a4 + 201aaa1 commit 99bffe2

673 files changed

Lines changed: 66104 additions & 3812 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/skills/pr-gardening/SKILL.md

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,57 @@
11
---
22
name: pr-gardening
33
description: >
4-
Discover recently referenced Paperclip pull requests, mechanically verify
5-
their current-head readiness, drive non-draft PRs back to green through their
6-
originating issues, and publish a merge-confidence report without merging.
4+
Discover the pull requests this Paperclip instance opened (never community
5+
contributions), report what each is for and how confident we are that it is
6+
merge-ready, and automatically drive the non-ready ones back to green with
7+
/prepare-paperclip-pr — without ever merging.
78
compatibility: Requires Node.js 20+, gh authenticated for GitHub read access, and Paperclip run credentials.
89
allowed-tools: Bash(node:*) Bash(gh:*) Bash(curl:*)
910
---
1011

1112
# PR Gardening
1213

13-
Actively garden pull requests referenced by Paperclip issues active in a recent window. Candidate discovery and readiness checking are scripts, not LLM analysis. GitHub access is read-only throughout this workflow.
14+
Actively garden the pull requests **this Paperclip instance opened** that are referenced by Paperclip issues active in a recent window (default 14 days). Candidate discovery and readiness checking are scripts, not LLM analysis. GitHub access is read-only throughout this workflow.
15+
16+
## Scope — Our PRs Only
17+
18+
By default the workflow gardens only pull requests authored by this instance's GitHub identity (the `gh` authenticated login, e.g. `cryppadotta`). Community contributions and dependabot PRs are excluded mechanically by author login in Stage A and land in `droppedCommunityPullRequests`; never re-add them by hand, widen the scope only when the caller explicitly passes `--authors` or `--include-community`.
1419

1520
## Hard Guardrails
1621

1722
- **Never merge, approve, or close a pull request.**
1823
- **Never instruct another person or agent to merge, approve, or close a pull request.**
24+
- **Never garden, comment on, or run `/prepare-paperclip-pr` against a community PR.** Only PRs from the Stage A author allowlist are actionable.
1925
- Never use mutating `gh` commands or mutating GitHub API requests. The scripts only use `gh pr view` and read-only `gh api` GET requests.
2026
- Draft pull requests are report-only. Do not post gardening comments for drafts.
2127
- Comment only on existing originating issues. Never create a gardening issue per pull request.
22-
- `--dry-run` suppresses all Paperclip mutations, including gardening comments and inbox archives. Discovery and GitHub inspection remain read-only in every mode.
28+
- `--dry-run` suppresses all Paperclip mutations, including gardening comments, prepare tasks, and inbox archives. Discovery and GitHub inspection remain read-only in every mode.
2329

2430
## Inputs
2531

26-
- `--days <N>`: issue activity window, default `30`.
32+
- `--days <N>`: activity window, default `14`. Applies to both mentioning-issue activity and the PR's own `updatedAt`; open PRs with no activity inside the window are dropped as stale.
33+
- `--authors <logins>`: comma-separated GitHub logins whose PRs are in scope; default is the `gh` authenticated user.
34+
- `--include-community`: disable the author filter entirely. Only on explicit caller request.
2735
- `--repo <owner/repo>`: GitHub repository, default detected by `gh repo view`.
28-
- `--dry-run`: discover, verify, and report without posting comments or archiving inbox entries.
36+
- `--dry-run`: discover, verify, and report without posting comments, creating prepare tasks, or archiving inbox entries.
2937
- `--archive-inbox`: after GitHub confirms a candidate PR is merged at its current head, archive the originating issue from the responsible user's inbox in Stage D.
30-
- `--cooldown-hours <N>`: repeat-comment cooldown, default `48`.
38+
- `--cooldown-hours <N>`: repeat-gardening cooldown, default `48`.
3139
- `--max-rounds <N>`: maximum gardening rounds per PR, default `3`.
3240

3341
Use a run-owned directory such as `$PAPERCLIP_RUN_SCRATCH_DIR/pr-gardening` for generated files.
3442

3543
## Stage A — Discover Candidates
3644

37-
Run the extract-search path. It scans every result page, rejects truncated match sets, normalizes PR URLs, deduplicates PR numbers, records every mentioning issue, checks issue work products to identify the origin, and drops PRs that GitHub says are merged or closed.
45+
Run the extract-search path. It scans every result page, normalizes PR URLs, deduplicates PR numbers, records every mentioning issue, checks issue work products to identify the origin, drops PRs that GitHub says are merged or closed, drops PRs whose author is outside the allowlist (community contributions) into `droppedCommunityPullRequests`, and drops open PRs whose own `updatedAt` is older than the window into `droppedStalePullRequests`. Issues that exceed the per-issue extract match cap (typically digest or QA issues that enumerate hundreds of PR URLs) are recorded in `source.truncatedIssues` and noted in the report instead of aborting the run.
3846

3947
```bash
4048
node .agents/skills/pr-gardening/scripts/find-candidates.mjs \
41-
--days 30 \
49+
--days 14 \
4250
--dry-run \
4351
--output "$RUN_DIR/candidates.json"
4452
```
4553

46-
The script calls `GET /api/companies/:companyId/search/extract` with `kind=url`, `scope=all`, and `updatedWithin=<N>d`. Do not replace it with full issue-list fetching or LLM scanning.
54+
The script calls `GET /api/companies/:companyId/search/extract` with `kind=url`, `scope=all`, and `updatedWithin=<N>d`, then resolves the author allowlist from `gh api user` unless `--authors` or `--include-community` overrides it. Do not replace it with full issue-list fetching or LLM scanning.
4755

4856
## Stage B — Verify Current-Head Readiness
4957

@@ -75,33 +83,33 @@ For each branch, process one branch at a time and do this serially:
7583
3. If an equivalent open task exists, reuse it: add a concise comment with the current PR/head/reason context and link it from the gardening issue or blocker list. Do not create another task.
7684
4. Only if no equivalent open task exists, create exactly one follow-up task for that branch.
7785

78-
Never fan out follow-up task creation in parallel. Do not issue concurrent `POST /api/companies/:companyId/issues` calls for create-PR tasks. After P1's issue-create idempotency support is available, every create-PR follow-up task creation must include `idempotencyKey: "pr-gardening:create-pr:{branch}"`, where `{branch}` is the exact branch name.
86+
Never fan out follow-up task creation in parallel. Do not issue concurrent `POST /api/companies/:companyId/issues` calls for create-PR or prepare-PR tasks. After P1's issue-create idempotency support is available, every create-PR follow-up task creation must include `idempotencyKey: "pr-gardening:create-pr:{branch}"` and every prepare-PR task `idempotencyKey: "pr-gardening:prepare-pr:{owner/repo}#{number}"`.
7987

80-
## Stage C — Comment on Originating Issues
88+
## Stage C — Drive Our PRs to Ready with /prepare-paperclip-pr
8189

8290
Skip this stage in `--dry-run` mode and for `ready` or `report_only` entries.
8391

84-
For each `needs_gardening` PR, use `originatingIssue` from `candidates.json`. Selection priority is:
92+
Every `needs_gardening` PR here was opened by this instance (Stage A guarantees it), so do not just report — actively get it merge-ready by running the `/prepare-paperclip-pr` skill against it. Process PRs one at a time:
8593

86-
1. issue carrying the exact PR URL as a `pull_request` work product;
87-
2. issue whose comment mentions the PR;
88-
3. most recently active mentioning issue.
94+
1. **Cooldown and rounds.** Locate the `originatingIssue` from `candidates.json` (selection priority: issue carrying the exact PR URL as a `pull_request` work product; then issue whose comment mentions the PR; then most recently active mentioning issue). Fetch its comments and search for the marker:
8995

90-
Before commenting, fetch the issue comments and search for this marker:
96+
```text
97+
<!-- pr-gardening:<owner/repo>#<number> -->
98+
```
9199

92-
```text
93-
<!-- pr-gardening:<owner/repo>#<number> -->
94-
```
100+
Skip the PR if the latest matching marker is newer than the cooldown. Track rounds from matching markers; after three rounds, stop and report `not converging; recommend close or human decision`. That is a recommendation for human disposition, not an instruction to close the PR.
95101

96-
Do not comment if the latest matching marker is newer than the cooldown. Track rounds from matching markers; after three rounds, stop nagging and report `not converging; recommend close or human decision`. This is a recommendation for human disposition, not an instruction to close the PR.
102+
2. **Deduplicate.** Search open Paperclip issues for the PR number/branch. If an equivalent open prepare-PR task already exists, reuse it with a concise status comment instead of creating another (see the deduplication section above).
97103

98-
When a comment is allowed, mention the originating issue assignee, instruct them to run `/prepare-pr`, include the current head SHA, and copy the exact machine-detected `reasons[]`. Use `POST /api/issues/:issueId/comments` with `X-Paperclip-Run-Id`. Include `resume: true` when the issue is terminal so the comment creates a live continuation.
104+
3. **Run the prepare skill.** Create one focused child task per PR assigned to a coder agent (prefer CodexCoder) instructing it to run `/prepare-paperclip-pr` for that PR — include the PR URL, branch, current head SHA, and the exact machine-detected `reasons[]` from `readiness.json`. If you are the gardener and already have the PR's branch checked out in a worktree, you may run `/prepare-paperclip-pr` directly instead of delegating. Either way, the prepare work must never merge, approve, or close the PR.
105+
106+
4. **Leave the marker comment.** Comment on the originating issue with the marker above, the current head SHA, the copied `reasons[]`, the round counter, and a link to the prepare task. Use `POST /api/issues/:issueId/comments` with `X-Paperclip-Run-Id`. Include `resume: true` when the issue is terminal so the comment creates a live continuation.
99107

100108
Suggested body:
101109

102110
```markdown
103111
<!-- pr-gardening:paperclipai/paperclip#1234 -->
104-
@Assignee please run `/prepare-pr` for https://github.com/paperclipai/paperclip/pull/1234.
112+
Gardening: dispatched `/prepare-paperclip-pr` for https://github.com/paperclipai/paperclip/pull/1234 via PAP-XXXX.
105113

106114
Current-head verification at `abc123` found:
107115
- failing check: test
@@ -133,7 +141,7 @@ Use `POST /api/issues/:issueId/comments` and include `X-Paperclip-Run-Id` on bot
133141

134142
## Stage E — Monitor to Termination
135143

136-
Set the gardening run issue's `blockedByIssueIds` to the non-terminal issues commented in Stage C so blocker resolution wakes the gardener. A scheduled or manual rerun is the fallback.
144+
Set the gardening run issue's `blockedByIssueIds` to the non-terminal prepare tasks and originating issues engaged in Stage C so blocker resolution wakes the gardener. A scheduled or manual rerun is the fallback.
137145

138146
On every wake, rerun Stage B first. A PR terminates from active gardening only when one of these is mechanically observed:
139147

@@ -151,12 +159,14 @@ node .agents/skills/pr-gardening/scripts/render-report.mjs \
151159
--output "$RUN_DIR/gardening-report.md"
152160
```
153161

154-
The report groups open PRs by confidence:
162+
The report states the scope (authors + window), and for every open PR gives its author, a one-line purpose summary taken from the PR description, and a readiness confidence bucket:
155163

156164
- **High:** current-head checks green, no conflicts, Greptile clean, base fresh, originating issue terminal.
157165
- **Medium:** otherwise green but base stale, review not complete, or originating issue active.
158166
- **Low:** failing/pending checks, missing Greptile, draft/just-fixed-unverified state, or no identifiable origin.
159167

168+
If a PR's generated purpose line is empty or unhelpful, write a one-sentence description from the PR title and diff summary when publishing the report.
169+
160170
Upload `candidates.json`, `readiness.json`, and `gardening-report.md` to the gardening issue, create/update the `gardening-report` issue document with the Markdown body, and leave a summary comment linking the artifacts. The report is the deliverable; it is never authorization to merge.
161171

162172
## Verification
@@ -167,4 +177,4 @@ Run focused script tests:
167177
node --test .agents/skills/pr-gardening/scripts/pr-gardening.test.mjs
168178
```
169179

170-
For a live dry run, execute Stages A, B, and F with `--dry-run`, then sanity-check named PRs only if they are still open. Merged or closed examples should appear under `droppedClosedPullRequests`, not in readiness results. If also exercising `--archive-inbox`, confirm the report describes the suppressed Stage D action and that no Paperclip archive or marker-comment mutation occurred.
180+
For a live dry run, execute Stages A, B, and F with `--dry-run`, then sanity-check named PRs only if they are still open. Merged or closed examples should appear under `droppedClosedPullRequests`, not in readiness results, and community-authored PRs must appear only under `droppedCommunityPullRequests` — a candidate or report entry with an author outside the allowlist is a scope failure. If also exercising `--archive-inbox`, confirm the report describes the suppressed Stage D action and that no Paperclip archive or marker-comment mutation occurred.

.agents/skills/pr-gardening/scripts/check-readiness.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
parseArgs,
99
readJson,
1010
reason,
11+
summarizePullRequestBody,
1112
writeJson,
1213
} from "./lib.mjs";
1314

@@ -114,7 +115,7 @@ export async function checkReadiness(candidatesDocument, options = {}) {
114115
"--repo",
115116
repository,
116117
"--json",
117-
"number,url,title,state,isDraft,headRefOid,baseRefName,headRefName,mergeable,mergeStateStatus,reviewDecision,statusCheckRollup,updatedAt",
118+
"number,url,title,author,body,state,isDraft,headRefOid,baseRefName,headRefName,mergeable,mergeStateStatus,reviewDecision,statusCheckRollup,updatedAt",
118119
]);
119120
const checkRuns = fetchCheckRuns(repository, pullRequest.headRefOid);
120121
const comparison = ghJson([
@@ -134,6 +135,8 @@ export async function checkReadiness(candidatesDocument, options = {}) {
134135
number: pullRequest.number,
135136
url: pullRequest.url,
136137
title: pullRequest.title,
138+
author: pullRequest.author?.login ?? candidate.author ?? null,
139+
purpose: summarizePullRequestBody(pullRequest.body),
137140
state: pullRequest.state.toLowerCase(),
138141
isDraft: pullRequest.isDraft,
139142
headSha: pullRequest.headRefOid,
@@ -156,6 +159,9 @@ export async function checkReadiness(candidatesDocument, options = {}) {
156159
schemaVersion: 1,
157160
generatedAt: new Date().toISOString(),
158161
repository,
162+
windowDays: candidatesDocument.windowDays ?? null,
163+
authors: candidatesDocument.query?.authors ?? null,
164+
truncatedIssues: candidatesDocument.source?.truncatedIssues ?? [],
159165
candidatesGeneratedAt: candidatesDocument.generatedAt,
160166
dryRun: Boolean(options.dry_run ?? candidatesDocument.dryRun),
161167
summary: {

0 commit comments

Comments
 (0)