paperclip-github-plugin 0.21.1 → 0.21.2

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.
package/README.md CHANGED
@@ -84,7 +84,7 @@ In **GitHub App events**:
84
84
 
85
85
  Each matching delivery creates a wake issue assigned to the route's agent and wakes the agent for it. The issue description is the prompt: it names the event, repository, pull request or issue, head commit, labels and any comment text, and marks GitHub text as untrusted. The agent fetches the rest with the tools and sets the issue to done when it has finished.
86
86
 
87
- Wake issues have the origin `plugin:paperclip-github-plugin:operation:wake`, which keeps them out of Paperclip's default issue lists. Each one has its own task key, so wakes for different pull requests queue and run in parallel up to the agent's `maxConcurrentRuns` instead of merging into one run. A new CI wake for a pull request cancels the route's older wakes for it that have no run yet. Every 5 minutes the `wakes.reconcile` job looks at open wake issues with no queued or running run, 10 minutes after their last wake, doubling each time. If the last run succeeded, it closes the issue, unless the agent blocked it. If there was no run, or the run failed or timed out, it wakes the agent again, and after 3 wakes it blocks the issue so a person sees it. Finished work is never run twice. A wake that cannot be created, or a CI delivery whose pull request cannot be looked up, fails the delivery, so it appears in the App's delivery log and can be redelivered.
87
+ Wake issues have the origin `plugin:paperclip-github-plugin:operation:wake`, which keeps them out of Paperclip's default issue lists. Each one has its own task key, so wakes for different pull requests queue and run in parallel up to the agent's `maxConcurrentRuns` instead of merging into one run. A new CI wake for a pull request cancels the route's older wakes for it that have no run yet. Every 5 minutes the `wakes.reconcile` job looks at open wake issues with no queued or running run, 10 minutes after their last wake, doubling each time. If the last run succeeded, it closes the issue, unless the agent blocked it. It also closes an issue whose run succeeded when a later Paperclip follow-up run for it failed or blocked it. If there was no run, or the run failed or timed out, it wakes the agent again, and after 3 wakes it blocks the issue so a person sees it. Finished work is never run twice. A wake that cannot be created, or a CI delivery whose pull request cannot be looked up, fails the delivery, so it appears in the App's delivery log and can be redelivered.
88
88
 
89
89
  `ci_completed` fires when every check run on a pull request's head commit has finished, not counting the App's own checks, so a review can wait for CI. It comes from `check_suite` and `workflow_run` deliveries, finds pull requests from forks through the commit, and reports the overall result as `success` or `failure`.
90
90
 
package/dist/manifest.js CHANGED
@@ -814,6 +814,7 @@ var GITHUB_WAKE_ISSUE_ORIGIN_KIND = `plugin:${GITHUB_SYNC_PLUGIN_ID}:operation:w
814
814
  var GITHUB_WAKE_RECONCILE_JOB_KEY = "wakes.reconcile";
815
815
  var GITHUB_WAKE_RECONCILE_SCHEDULE = "*/5 * * * *";
816
816
  var GITHUB_WAKE_RECHECK_AFTER_MS = 10 * 60 * 1e3;
817
+ var RUN_CLOCK_SLACK_MS = 60 * 1e3;
817
818
 
818
819
  // src/github-webhooks.ts
819
820
  var GITHUB_WEBHOOK_ENDPOINT_KEY = "github";
@@ -821,7 +822,7 @@ var GITHUB_WEBHOOK_ENDPOINT_KEY = "github";
821
822
  // src/manifest.ts
822
823
  var require2 = createRequire(import.meta.url);
823
824
  var packageJson = require2("../package.json");
824
- var MANIFEST_VERSION = "0.21.1"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
825
+ var MANIFEST_VERSION = "0.21.2"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
825
826
  var COMPANY_SECRET_REF_VALUE_SCHEMA = {
826
827
  anyOf: [
827
828
  { type: "string" },
package/dist/worker.js CHANGED
@@ -1329,13 +1329,19 @@ function toTime(value) {
1329
1329
  const time = value instanceof Date ? value.getTime() : Date.parse(value);
1330
1330
  return Number.isFinite(time) ? time : 0;
1331
1331
  }
1332
- async function readIssueRuns(ctx, issueId, companyId) {
1332
+ var RUN_CLOCK_SLACK_MS = 60 * 1e3;
1333
+ function runTime(run) {
1334
+ return toTime(run.finishedAt ?? run.startedAt ?? run.createdAt);
1335
+ }
1336
+ async function readIssueRuns(ctx, issueId, companyId, since = 0) {
1333
1337
  const { runs } = await ctx.issues.summaries.getOrchestration({ issueId, companyId });
1334
1338
  const own = runs.filter((run) => run.issueId === issueId);
1335
- const last = [...own].sort(
1336
- (left, right) => toTime(right.finishedAt ?? right.startedAt ?? right.createdAt) - toTime(left.finishedAt ?? left.startedAt ?? left.createdAt)
1337
- )[0];
1338
- return { active: own.some((run) => ACTIVE_RUN_STATUSES.has(run.status)), ...last ? { last } : {} };
1339
+ const last = [...own].sort((left, right) => runTime(right) - runTime(left))[0];
1340
+ return {
1341
+ active: own.some((run) => ACTIVE_RUN_STATUSES.has(run.status)),
1342
+ succeededSince: own.some((run) => run.status === "succeeded" && toTime(run.createdAt) >= since - RUN_CLOCK_SLACK_MS),
1343
+ ...last ? { last } : {}
1344
+ };
1339
1345
  }
1340
1346
  function getGitHubWakeIssueOriginId(route, subject) {
1341
1347
  return `${route.id}|${subject.repository}#${subject.number}`;
@@ -1441,7 +1447,7 @@ async function reconcileWakeIssue(ctx, companyId, issue, now, summary) {
1441
1447
  if (now.getTime() - lastWakeAt < backoff) {
1442
1448
  return;
1443
1449
  }
1444
- const runs = await readIssueRuns(ctx, issue.id, companyId);
1450
+ const runs = await readIssueRuns(ctx, issue.id, companyId, lastWakeAt);
1445
1451
  if (runs.active) {
1446
1452
  return;
1447
1453
  }
@@ -1452,6 +1458,11 @@ async function reconcileWakeIssue(ctx, companyId, issue, now, summary) {
1452
1458
  }
1453
1459
  return;
1454
1460
  }
1461
+ if (!reopened && runs.succeededSince) {
1462
+ await ctx.issues.update(issue.id, { status: "done" }, companyId);
1463
+ summary.closed += 1;
1464
+ return;
1465
+ }
1455
1466
  if (attempts >= GITHUB_WAKE_MAX_ATTEMPTS) {
1456
1467
  await ctx.issues.update(issue.id, { status: "blocked" }, companyId);
1457
1468
  await writeWakeState(ctx, issue.id, { attempts, lastWakeAt: state?.lastWakeAt ?? now.toISOString(), blocked: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "Paperclip plugin that gives agents a GitHub App identity, GitHub tools, webhook wakes and shared memory.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",