paperclip-github-plugin 0.21.0 → 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 +2 -1
- package/dist/manifest.js +2 -1
- package/dist/worker.js +36 -12
- package/package.json +1 -1
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
|
|
|
@@ -167,6 +167,7 @@ Only the worker reads it, and the token is never copied into plugin state or con
|
|
|
167
167
|
- **Webhook deliveries fail with 502.** Releases before 0.20 read instance-wide config while handling a delivery, which Paperclip 2026.1117 refuses with `company context is required`. Upgrade the plugin.
|
|
168
168
|
- **Upgrading to 0.21.** Webhook wakes now need the `issues.read`, `issues.create`, `issues.update`, `issues.wakeup`, `issues.orchestration.read` and `jobs.schedule` capabilities and no longer use `agents.invoke`. Approve the new capabilities when Paperclip asks during the upgrade, or wakes fail and deliveries show as failed.
|
|
169
169
|
- **A wake issue is blocked.** The agent was woken 3 times and no run succeeded. Read the issue's runs, fix the cause, then set the issue back to `todo` and it is woken on the next sweep.
|
|
170
|
+
- **Deliveries fail with `Rate limit exceeded for secret resolution`.** Releases before 0.21.1 resolved the webhook secret on every delivery, and Paperclip allows 30 a minute per company. Upgrade, then redeliver the failed `completed` deliveries from the App's delivery log.
|
|
170
171
|
- **No agent wakes.** In the App's delivery log on GitHub, check the delivery got a 2xx. Then check the company has a webhook secret (the settings page shows **Secret saved**), the App is subscribed to the route's events, and the route's filters match. Comment routes need an `@<app slug>` mention unless `requireMention` is `false`.
|
|
171
172
|
- **Tools fail with `deny_default`.** No tool profile grants the tool to that agent. See [Granting the tools to agents](#granting-the-tools-to-agents).
|
|
172
173
|
- **`Secret is not bound to plugin` or `Invalid secret reference for plugin`.** The company's plugin config still holds a pre-2026.831 bare secret id. Open the settings page in that company so it re-saves the reference as a binding, or save the credentials again.
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
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 });
|
|
@@ -2261,12 +2272,24 @@ function readCompanyScopedConfigValue(config, key, companyId) {
|
|
|
2261
2272
|
const map = config[key];
|
|
2262
2273
|
return isPlainRecord(map) ? map[companyId] : void 0;
|
|
2263
2274
|
}
|
|
2275
|
+
var PLUGIN_SECRET_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
2276
|
+
var resolvedPluginSecrets = /* @__PURE__ */ new Map();
|
|
2277
|
+
function clearResolvedPluginSecrets() {
|
|
2278
|
+
resolvedPluginSecrets.clear();
|
|
2279
|
+
}
|
|
2264
2280
|
async function resolvePluginSecret(ctx, secretId, options = {}) {
|
|
2265
2281
|
const companyId = normalizeCompanyId(options.companyId);
|
|
2266
|
-
|
|
2282
|
+
const cacheKey = JSON.stringify([companyId ?? null, options.configPath ?? null, secretId]);
|
|
2283
|
+
const cached = resolvedPluginSecrets.get(cacheKey);
|
|
2284
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
2285
|
+
return cached.value;
|
|
2286
|
+
}
|
|
2287
|
+
const value = await ctx.secrets.resolve(toSecretRefBinding(secretId), {
|
|
2267
2288
|
...companyId ? { companyId } : {},
|
|
2268
2289
|
...options.configPath ? { configPath: options.configPath } : {}
|
|
2269
2290
|
});
|
|
2291
|
+
resolvedPluginSecrets.set(cacheKey, { value, expiresAt: Date.now() + PLUGIN_SECRET_CACHE_TTL_MS });
|
|
2292
|
+
return value;
|
|
2270
2293
|
}
|
|
2271
2294
|
function normalizeGitHubLowercaseString(value) {
|
|
2272
2295
|
if (typeof value !== "string") {
|
|
@@ -2509,6 +2532,11 @@ async function handleGitHubWebhook(ctx, input) {
|
|
|
2509
2532
|
if (!installationId) {
|
|
2510
2533
|
throw new Error("GitHub webhook delivery has no App installation. Deliveries must come from a GitHub App.");
|
|
2511
2534
|
}
|
|
2535
|
+
const ci = describeGitHubCiCompletion(headers.event, payload);
|
|
2536
|
+
const directSubject = ci ? void 0 : describeGitHubEvent(headers.event, payload);
|
|
2537
|
+
if (!ci && !directSubject && headers.event !== "ping") {
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2512
2540
|
const { companies, candidates } = await resolveVerifiedGitHubWebhookCompanies(
|
|
2513
2541
|
ctx,
|
|
2514
2542
|
installationId,
|
|
@@ -2522,11 +2550,6 @@ async function handleGitHubWebhook(ctx, input) {
|
|
|
2522
2550
|
ctx.logger.info("GitHub App webhook verified.", { installationId, companies: companies.map((company) => company.companyId) });
|
|
2523
2551
|
return;
|
|
2524
2552
|
}
|
|
2525
|
-
const ci = describeGitHubCiCompletion(headers.event, payload);
|
|
2526
|
-
const directSubject = ci ? void 0 : describeGitHubEvent(headers.event, payload);
|
|
2527
|
-
if (!ci && !directSubject) {
|
|
2528
|
-
return;
|
|
2529
|
-
}
|
|
2530
2553
|
const failures = [];
|
|
2531
2554
|
for (const company of companies) {
|
|
2532
2555
|
const routes = company.routes.filter((route) => ci ? route.event === "ci_completed" : route.event !== "ci_completed");
|
|
@@ -5528,6 +5551,7 @@ var plugin = definePlugin({
|
|
|
5528
5551
|
const companyId = normalizeCompanyId(context?.companyId) ?? null;
|
|
5529
5552
|
rememberTrustedConfig(companyId, newConfig);
|
|
5530
5553
|
clearGitHubRepositoryTokenCapabilityAudits();
|
|
5554
|
+
clearResolvedPluginSecrets();
|
|
5531
5555
|
pluginRuntimeContext?.logger.debug("The GitHub plugin received company-scoped plugin config.", {
|
|
5532
5556
|
companyId,
|
|
5533
5557
|
configKeys: Object.keys(isPlainRecord(newConfig) ? newConfig : {})
|
package/package.json
CHANGED