paperclip-github-plugin 0.17.3 → 0.17.5

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
@@ -278,6 +278,8 @@ The plugin exposes GitHub workflow tools to Paperclip agents, including:
278
278
 
279
279
  Branch publication uses an isolated temporary bare repository backed by the selected trusted-workspace checkout's object database. It does not execute repository hooks, accept arbitrary refspecs, or honor repository-local remotes. An optional checkout path must resolve inside the issue execution workspace, while the selected target repository must be a canonical GitHub `owner/repo` reference. Publication rejects owner-qualified heads, base-branch targets, non-fast-forward updates, cross-project issues, mismatched local branch tips, and remote SHA mismatches.
280
280
 
281
+ Optional `labels`, `userReviewers`, and `teamReviewers` are applied right after the pull request exists (for example the approved `type:` label and the linked issue author as reviewer). Those follow-up calls never undo the pull request: their outcome is reported in the result as `labels`, `requestedReviewers`, `requestedTeams`, or `warnings`. The tool also appends the new pull request to the issue's GitHub link record immediately, so the Paperclip issue card shows the linked pull request without waiting for the next sync. `update_pull_request` accepts a replacement `labels` set, and `get_issue` returns the issue `author` so agents can decide reviewer routing.
282
+
281
283
  The call is ordered and retry-safe rather than a cross-system transaction: a published branch may remain if GitHub PR creation or Paperclip link persistence fails. On retry, the tool re-verifies and republishes the exact SHA, then recovers an already-open PR only when repository, head, base, and head SHA all match before repairing the link and metric. It never deletes a branch or closes a PR as automatic compensation.
282
284
 
283
285
  After that durable link is written, pull-request tools can use the same `paperclipIssueId` to read or update the PR immediately, even when the Paperclip issue was created natively and has no linked GitHub issue. If one Paperclip issue has same-number PRs in different repositories, the caller must also supply the repository so the worker can reject ambiguous or unlinked selections.
package/dist/manifest.js CHANGED
@@ -123,7 +123,7 @@ var GITHUB_AGENT_TOOLS = [
123
123
  {
124
124
  name: "get_issue",
125
125
  displayName: "Get Issue",
126
- description: "Read one GitHub issue with its metadata, assignees, labels, milestone, and linked pull requests.",
126
+ description: "Read one GitHub issue with its metadata, author, assignees, labels, milestone, and linked pull requests.",
127
127
  parametersSchema: {
128
128
  type: "object",
129
129
  additionalProperties: false,
@@ -268,7 +268,7 @@ var GITHUB_AGENT_TOOLS = [
268
268
  {
269
269
  name: "create_pull_request",
270
270
  displayName: "Create Pull Request",
271
- description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
271
+ description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. Optional labels and reviewer requests are applied right after creation and reported back; a failure in those follow-up steps does not undo the pull request. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
272
272
  parametersSchema: {
273
273
  type: "object",
274
274
  additionalProperties: false,
@@ -310,6 +310,27 @@ var GITHUB_AGENT_TOOLS = [
310
310
  llmModel: llmModelProperty,
311
311
  draft: {
312
312
  type: "boolean"
313
+ },
314
+ labels: {
315
+ type: "array",
316
+ items: {
317
+ type: "string"
318
+ },
319
+ description: "Optional GitHub labels to add to the new pull request, for example the approved `type:` label. Labels are applied after the pull request is created; failures are returned as warnings."
320
+ },
321
+ userReviewers: {
322
+ type: "array",
323
+ items: {
324
+ type: "string"
325
+ },
326
+ description: "Optional GitHub user logins to request as reviewers right after creation, for example the linked issue author when they are not the pull request author. Failures are returned as warnings."
327
+ },
328
+ teamReviewers: {
329
+ type: "array",
330
+ items: {
331
+ type: "string"
332
+ },
333
+ description: "Optional GitHub team slugs to request as reviewers right after creation. Failures are returned as warnings."
313
334
  }
314
335
  }
315
336
  }
@@ -332,7 +353,7 @@ var GITHUB_AGENT_TOOLS = [
332
353
  {
333
354
  name: "update_pull_request",
334
355
  displayName: "Update Pull Request",
335
- description: "Edit pull request title, body, base branch, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
356
+ description: "Edit pull request title, body, base branch, labels, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
336
357
  parametersSchema: {
337
358
  type: "object",
338
359
  additionalProperties: false,
@@ -359,6 +380,13 @@ var GITHUB_AGENT_TOOLS = [
359
380
  isDraft: {
360
381
  type: "boolean",
361
382
  description: "True converts the pull request to draft. False marks it ready for review."
383
+ },
384
+ labels: {
385
+ type: "array",
386
+ items: {
387
+ type: "string"
388
+ },
389
+ description: "Optional replacement label set for the pull request. When provided, the pull request ends up with exactly these labels."
362
390
  }
363
391
  }
364
392
  }
@@ -691,7 +719,7 @@ var COMPANY_METRIC_API_ROUTE_URL_PATH = `/api/plugins/${GITHUB_SYNC_PLUGIN_ID}/a
691
719
  var require2 = createRequire(import.meta.url);
692
720
  var packageJson = require2("../package.json");
693
721
  var SCHEDULE_TICK_CRON = "* * * * *";
694
- var MANIFEST_VERSION = "0.17.3"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
722
+ var MANIFEST_VERSION = "0.17.5"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
695
723
  var COMPANY_SECRET_REF_VALUE_SCHEMA = {
696
724
  anyOf: [
697
725
  { type: "string" },
package/dist/worker.js CHANGED
@@ -134,7 +134,7 @@ var GITHUB_AGENT_TOOLS = [
134
134
  {
135
135
  name: "get_issue",
136
136
  displayName: "Get Issue",
137
- description: "Read one GitHub issue with its metadata, assignees, labels, milestone, and linked pull requests.",
137
+ description: "Read one GitHub issue with its metadata, author, assignees, labels, milestone, and linked pull requests.",
138
138
  parametersSchema: {
139
139
  type: "object",
140
140
  additionalProperties: false,
@@ -279,7 +279,7 @@ var GITHUB_AGENT_TOOLS = [
279
279
  {
280
280
  name: "create_pull_request",
281
281
  displayName: "Create Pull Request",
282
- description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
282
+ description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. Optional labels and reviewer requests are applied right after creation and reported back; a failure in those follow-up steps does not undo the pull request. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
283
283
  parametersSchema: {
284
284
  type: "object",
285
285
  additionalProperties: false,
@@ -321,6 +321,27 @@ var GITHUB_AGENT_TOOLS = [
321
321
  llmModel: llmModelProperty,
322
322
  draft: {
323
323
  type: "boolean"
324
+ },
325
+ labels: {
326
+ type: "array",
327
+ items: {
328
+ type: "string"
329
+ },
330
+ description: "Optional GitHub labels to add to the new pull request, for example the approved `type:` label. Labels are applied after the pull request is created; failures are returned as warnings."
331
+ },
332
+ userReviewers: {
333
+ type: "array",
334
+ items: {
335
+ type: "string"
336
+ },
337
+ description: "Optional GitHub user logins to request as reviewers right after creation, for example the linked issue author when they are not the pull request author. Failures are returned as warnings."
338
+ },
339
+ teamReviewers: {
340
+ type: "array",
341
+ items: {
342
+ type: "string"
343
+ },
344
+ description: "Optional GitHub team slugs to request as reviewers right after creation. Failures are returned as warnings."
324
345
  }
325
346
  }
326
347
  }
@@ -343,7 +364,7 @@ var GITHUB_AGENT_TOOLS = [
343
364
  {
344
365
  name: "update_pull_request",
345
366
  displayName: "Update Pull Request",
346
- description: "Edit pull request title, body, base branch, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
367
+ description: "Edit pull request title, body, base branch, labels, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
347
368
  parametersSchema: {
348
369
  type: "object",
349
370
  additionalProperties: false,
@@ -370,6 +391,13 @@ var GITHUB_AGENT_TOOLS = [
370
391
  isDraft: {
371
392
  type: "boolean",
372
393
  description: "True converts the pull request to draft. False marks it ready for review."
394
+ },
395
+ labels: {
396
+ type: "array",
397
+ items: {
398
+ type: "string"
399
+ },
400
+ description: "Optional replacement label set for the pull request. When provided, the pull request ends up with exactly these labels."
373
401
  }
374
402
  }
375
403
  }
@@ -8560,15 +8588,18 @@ function buildGitHubIssueLinkRecord(target, issueId, githubIssue, linkedPullRequ
8560
8588
  }
8561
8589
  async function upsertGitHubIssueLinkRecord(ctx, target, issueId, githubIssue, linkedPullRequests) {
8562
8590
  const record = buildGitHubIssueLinkRecord(target, issueId, githubIssue, linkedPullRequests);
8563
- await ctx.entities.upsert({
8564
- entityType: ISSUE_LINK_ENTITY_TYPE,
8565
- scopeKind: "issue",
8566
- scopeId: issueId,
8567
- externalId: record.data.githubIssueUrl,
8568
- ...record.title ? { title: record.title } : {},
8569
- ...record.status ? { status: record.status } : {},
8570
- data: record.data
8571
- });
8591
+ await withPullRequestLinkMutationLock(
8592
+ issueLinkMutationLockKey(target.companyId, issueId),
8593
+ () => ctx.entities.upsert({
8594
+ entityType: ISSUE_LINK_ENTITY_TYPE,
8595
+ scopeKind: "issue",
8596
+ scopeId: issueId,
8597
+ externalId: record.data.githubIssueUrl,
8598
+ ...record.title ? { title: record.title } : {},
8599
+ ...record.status ? { status: record.status } : {},
8600
+ data: record.data
8601
+ })
8602
+ );
8572
8603
  }
8573
8604
  var pullRequestLinkMutationTails = /* @__PURE__ */ new Map();
8574
8605
  async function withPullRequestLinkMutationLock(key, mutation) {
@@ -8589,6 +8620,48 @@ async function withPullRequestLinkMutationLock(key, mutation) {
8589
8620
  }
8590
8621
  }
8591
8622
  }
8623
+ async function appendPullRequestToGitHubIssueLinkRecords(ctx, input) {
8624
+ return withPullRequestLinkMutationLock(issueLinkMutationLockKey(input.companyId, input.issueId), async () => {
8625
+ const repositoryUrl = parseRepositoryReference(input.repositoryUrl)?.url ?? input.repositoryUrl.trim();
8626
+ const records = await listGitHubIssueLinkRecords(ctx, { paperclipIssueId: input.issueId });
8627
+ let changed = false;
8628
+ for (const record of records) {
8629
+ if (record.data.companyId && record.data.companyId !== input.companyId) {
8630
+ continue;
8631
+ }
8632
+ const alreadyLinked = record.data.linkedPullRequests.some(
8633
+ (pullRequest) => pullRequest.number === input.pullRequestNumber && (parseRepositoryReference(pullRequest.repositoryUrl)?.url ?? pullRequest.repositoryUrl) === repositoryUrl
8634
+ );
8635
+ if (alreadyLinked) {
8636
+ continue;
8637
+ }
8638
+ const linkedPullRequests = normalizeLinkedPullRequestReferences(
8639
+ [...record.data.linkedPullRequests, { number: input.pullRequestNumber, repositoryUrl }],
8640
+ record.data.repositoryUrl
8641
+ );
8642
+ await ctx.entities.upsert({
8643
+ entityType: ISSUE_LINK_ENTITY_TYPE,
8644
+ scopeKind: "issue",
8645
+ scopeId: input.issueId,
8646
+ externalId: record.data.githubIssueUrl,
8647
+ ...record.title ? { title: record.title } : {},
8648
+ ...record.status ? { status: record.status } : {},
8649
+ data: {
8650
+ ...record.data,
8651
+ linkedPullRequestNumbers: normalizeLinkedPullRequestNumbers(
8652
+ linkedPullRequests.map((pullRequest) => pullRequest.number)
8653
+ ),
8654
+ linkedPullRequests
8655
+ }
8656
+ });
8657
+ changed = true;
8658
+ }
8659
+ return changed;
8660
+ });
8661
+ }
8662
+ function issueLinkMutationLockKey(companyId, issueId) {
8663
+ return `issue-link:${companyId ?? ""}:${issueId}`;
8664
+ }
8592
8665
  async function upsertGitHubPullRequestLinkRecord(ctx, params) {
8593
8666
  const repositoryUrl = getNormalizedMappingRepositoryUrl({ repositoryUrl: params.repositoryUrl });
8594
8667
  const referenceKey = buildGitHubPullRequestReferenceKey({
@@ -11641,7 +11714,8 @@ async function synchronizePaperclipPullRequestIssueStatuses(ctx, octokit, mappin
11641
11714
  await persistRemoteActionRegistry();
11642
11715
  remoteAction = remoteActionRegistry.find((record) => record.key === remoteActionKey) ?? remoteAction;
11643
11716
  }
11644
- if (shouldClearTransitionAssignee || shouldClearCompletedExecutionPolicy || nextAssigneeChanged) {
11717
+ const shouldClearExistingExecutionPolicy = (shouldPreserveMaintainerWaitRouting || shouldClearCompletedExecutionPolicy) && Boolean(paperclipIssueSyncContext.executionPolicy);
11718
+ if (shouldClearTransitionAssignee || shouldClearExistingExecutionPolicy || nextAssigneeChanged) {
11645
11719
  updateSyncFailureContext(syncFailureContext, {
11646
11720
  phase: "updating_paperclip_status",
11647
11721
  repositoryUrl: primaryRepository?.url,
@@ -11655,7 +11729,7 @@ async function synchronizePaperclipPullRequestIssueStatuses(ctx, octokit, mappin
11655
11729
  nextStatus,
11656
11730
  ...nextAssigneeChanged && nextTransitionAssignee ? { nextAssignee: nextTransitionAssignee.principal } : {},
11657
11731
  ...shouldClearTransitionAssignee ? { clearAssignee: true } : {},
11658
- ...shouldPreserveMaintainerWaitRouting || shouldClearCompletedExecutionPolicy ? { clearExecutionPolicy: true } : {},
11732
+ ...shouldClearExistingExecutionPolicy ? { clearExecutionPolicy: true } : {},
11659
11733
  transitionComment: "",
11660
11734
  actionFingerprint: actionJournalFingerprint,
11661
11735
  paperclipApiBaseUrl
@@ -17081,6 +17155,11 @@ function registerGitHubAgentTools(ctx) {
17081
17155
  url: issue.htmlUrl,
17082
17156
  state: issue.state,
17083
17157
  stateReason: issue.stateReason,
17158
+ author: issue.authorLogin ? {
17159
+ login: issue.authorLogin,
17160
+ ...issue.authorUrl ? { url: issue.authorUrl } : {},
17161
+ ...issue.authorAssociation ? { association: issue.authorAssociation } : {}
17162
+ } : null,
17084
17163
  labels: issue.labels,
17085
17164
  assignees,
17086
17165
  milestone,
@@ -17441,6 +17520,7 @@ function registerGitHubAgentTools(ctx) {
17441
17520
  }
17442
17521
  pullRequestData = existingPullRequest;
17443
17522
  }
17523
+ const postCreationWarnings = [];
17444
17524
  let persistedFollowThroughAssigneeAgentId = followThroughAssigneeAgentId ?? void 0;
17445
17525
  let persistedFollowThroughAssigneeUpdatedAt;
17446
17526
  if (paperclipIssueId) {
@@ -17466,6 +17546,62 @@ function registerGitHubAgentTools(ctx) {
17466
17546
  projectId: issueProjectId,
17467
17547
  repository
17468
17548
  });
17549
+ try {
17550
+ await appendPullRequestToGitHubIssueLinkRecords(ctx, {
17551
+ companyId: runCtx.companyId,
17552
+ issueId: paperclipIssueId,
17553
+ repositoryUrl: repository.url,
17554
+ pullRequestNumber: pullRequestData.number
17555
+ });
17556
+ } catch (error) {
17557
+ postCreationWarnings.push(
17558
+ `Pull request #${pullRequestData.number} was created, but the Paperclip issue link could not be refreshed yet: ${getErrorMessage(error)}`
17559
+ );
17560
+ }
17561
+ }
17562
+ const requestedLabels = normalizeToolStringArray(input.labels);
17563
+ let appliedLabels;
17564
+ if (requestedLabels.length > 0) {
17565
+ try {
17566
+ const labelResponse = await octokit.rest.issues.addLabels({
17567
+ owner: repository.owner,
17568
+ repo: repository.repo,
17569
+ issue_number: pullRequestData.number,
17570
+ labels: requestedLabels,
17571
+ headers: {
17572
+ "X-GitHub-Api-Version": GITHUB_API_VERSION
17573
+ }
17574
+ });
17575
+ appliedLabels = (labelResponse.data ?? []).map((label) => typeof label === "string" ? label : label?.name ?? "").filter(Boolean);
17576
+ } catch (error) {
17577
+ postCreationWarnings.push(
17578
+ `Pull request #${pullRequestData.number} was created, but labels could not be applied: ${getErrorMessage(error)}`
17579
+ );
17580
+ }
17581
+ }
17582
+ const requestedUserReviewers = normalizeToolStringArray(input.userReviewers);
17583
+ const requestedTeamReviewers = normalizeToolStringArray(input.teamReviewers);
17584
+ let requestedReviewers;
17585
+ let requestedTeams;
17586
+ if (requestedUserReviewers.length > 0 || requestedTeamReviewers.length > 0) {
17587
+ try {
17588
+ const reviewerResponse = await octokit.rest.pulls.requestReviewers({
17589
+ owner: repository.owner,
17590
+ repo: repository.repo,
17591
+ pull_number: pullRequestData.number,
17592
+ reviewers: requestedUserReviewers,
17593
+ team_reviewers: requestedTeamReviewers,
17594
+ headers: {
17595
+ "X-GitHub-Api-Version": GITHUB_API_VERSION
17596
+ }
17597
+ });
17598
+ requestedReviewers = (reviewerResponse.data.requested_reviewers ?? []).map((reviewer) => reviewer?.login ?? "").filter(Boolean);
17599
+ requestedTeams = (reviewerResponse.data.requested_teams ?? []).map((team) => team?.slug ?? "").filter(Boolean);
17600
+ } catch (error) {
17601
+ postCreationWarnings.push(
17602
+ `Pull request #${pullRequestData.number} was created, but reviewers could not be requested: ${getErrorMessage(error)}`
17603
+ );
17604
+ }
17469
17605
  }
17470
17606
  await persistCompanyActivityMetricEvent(
17471
17607
  ctx,
@@ -17481,9 +17617,13 @@ function registerGitHubAgentTools(ctx) {
17481
17617
  }
17482
17618
  );
17483
17619
  return buildToolSuccessResult(
17484
- `Created pull request #${pullRequestData.number} in ${formatRepositoryLabel(repository)}.`,
17620
+ postCreationWarnings.length > 0 ? `Created pull request #${pullRequestData.number} in ${formatRepositoryLabel(repository)} with follow-up warnings: ${postCreationWarnings.join(" ")}` : `Created pull request #${pullRequestData.number} in ${formatRepositoryLabel(repository)}.`,
17485
17621
  {
17486
17622
  repository: repository.url,
17623
+ ...appliedLabels ? { labels: appliedLabels } : {},
17624
+ ...requestedReviewers ? { requestedReviewers } : {},
17625
+ ...requestedTeams ? { requestedTeams } : {},
17626
+ ...postCreationWarnings.length > 0 ? { warnings: postCreationWarnings } : {},
17487
17627
  publishedBranch: {
17488
17628
  name: publishedBranch.branchName,
17489
17629
  commitSha: publishedBranch.commitSha,
@@ -17610,6 +17750,26 @@ function registerGitHubAgentTools(ctx) {
17610
17750
  }
17611
17751
  });
17612
17752
  }
17753
+ let labels;
17754
+ if (Array.isArray(input.labels)) {
17755
+ const requestedLabels = normalizeToolStringArray(input.labels);
17756
+ const currentLabels = (currentResponse.data.labels ?? []).map((label) => typeof label === "string" ? label : label?.name ?? "").filter(Boolean);
17757
+ if ([...requestedLabels].sort().join("\n") !== [...currentLabels].sort().join("\n")) {
17758
+ const labelResponse = await octokit.rest.issues.setLabels({
17759
+ owner: target.repository.owner,
17760
+ repo: target.repository.repo,
17761
+ issue_number: target.pullRequestNumber,
17762
+ labels: requestedLabels,
17763
+ headers: {
17764
+ "X-GitHub-Api-Version": GITHUB_API_VERSION
17765
+ }
17766
+ });
17767
+ labels = (labelResponse.data ?? []).map((label) => typeof label === "string" ? label : label?.name ?? "").filter(Boolean);
17768
+ changed = true;
17769
+ } else {
17770
+ labels = currentLabels;
17771
+ }
17772
+ }
17613
17773
  return buildToolSuccessResult(
17614
17774
  changed ? `Updated pull request #${currentResponse.data.number} in ${formatRepositoryLabel(target.repository)}.` : `No GitHub pull request changes were requested for #${currentResponse.data.number} in ${formatRepositoryLabel(target.repository)}.`,
17615
17775
  {
@@ -17621,7 +17781,8 @@ function registerGitHubAgentTools(ctx) {
17621
17781
  url: currentResponse.data.html_url,
17622
17782
  state: currentResponse.data.state,
17623
17783
  isDraft: currentResponse.data.draft,
17624
- baseRefName: currentResponse.data.base.ref
17784
+ baseRefName: currentResponse.data.base.ref,
17785
+ ...labels ? { labels } : {}
17625
17786
  }
17626
17787
  }
17627
17788
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.17.3",
3
+ "version": "0.17.5",
4
4
  "description": "Paperclip plugin for synchronizing GitHub issues into Paperclip projects.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",