paperclip-github-plugin 0.14.0 → 0.15.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.
package/dist/worker.js CHANGED
@@ -270,10 +270,13 @@ var GITHUB_AGENT_TOOLS = [
270
270
  additionalProperties: false,
271
271
  required: ["paperclipIssueId", "head", "headCommitSha", "base", "title"],
272
272
  properties: {
273
- repository: repositoryProperty,
273
+ repository: {
274
+ type: "string",
275
+ description: "Target GitHub repository as owner/repo or https://github.com/owner/repo. It may be outside Paperclip repository mappings, but it must match the issue execution workspace. Omit only when the issue project has exactly one mapped repository."
276
+ },
274
277
  paperclipIssueId: {
275
278
  type: "string",
276
- description: "Paperclip issue id used to resolve the trusted project workspace, mapped GitHub repository, and durable pull-request link."
279
+ description: "Paperclip issue id used to resolve the trusted execution workspace and durable pull-request link."
277
280
  },
278
281
  head: {
279
282
  type: "string",
@@ -2978,7 +2981,7 @@ async function resolvePaperclipIssueGitHubLink(ctx, issueId, companyId, options
2978
2981
  };
2979
2982
  return await hydrateRecoveredPaperclipIssueGitHubLink(ctx, issueId, fallbackLink) ?? fallbackLink;
2980
2983
  }
2981
- async function resolvePaperclipIssueGitHubPullRequestLink(ctx, issueId, companyId) {
2984
+ async function listPaperclipIssueGitHubPullRequestLinks(ctx, issueId, companyId) {
2982
2985
  const links = await listGitHubPullRequestLinkRecords(ctx, {
2983
2986
  paperclipIssueId: issueId
2984
2987
  });
@@ -2988,7 +2991,10 @@ async function resolvePaperclipIssueGitHubPullRequestLink(ctx, issueId, companyI
2988
2991
  const safeRightTimestamp = Number.isFinite(rightTimestamp) ? rightTimestamp : 0;
2989
2992
  const safeLeftTimestamp = Number.isFinite(leftTimestamp) ? leftTimestamp : 0;
2990
2993
  return safeRightTimestamp - safeLeftTimestamp;
2991
- })[0] ?? null;
2994
+ });
2995
+ }
2996
+ async function resolvePaperclipIssueGitHubPullRequestLink(ctx, issueId, companyId) {
2997
+ return (await listPaperclipIssueGitHubPullRequestLinks(ctx, issueId, companyId))[0] ?? null;
2992
2998
  }
2993
2999
  async function hydrateRecoveredPaperclipIssueGitHubLink(ctx, issueId, fallbackLink) {
2994
3000
  const repository = parseRepositoryReference(fallbackLink.repositoryUrl);
@@ -11401,12 +11407,72 @@ async function resolveGitHubIssueToolTarget(ctx, runCtx, input) {
11401
11407
  async function resolveGitHubPullRequestToolTarget(ctx, runCtx, input) {
11402
11408
  const paperclipIssueId = normalizeOptionalToolString(input.paperclipIssueId);
11403
11409
  if (paperclipIssueId) {
11404
- const link = await resolvePaperclipIssueGitHubLink(ctx, paperclipIssueId, runCtx.companyId);
11405
- if (!link) {
11410
+ const [link, directPullRequestLinks] = await Promise.all([
11411
+ resolvePaperclipIssueGitHubLink(ctx, paperclipIssueId, runCtx.companyId),
11412
+ listPaperclipIssueGitHubPullRequestLinks(ctx, paperclipIssueId, runCtx.companyId)
11413
+ ]);
11414
+ const directPullRequestReferences = normalizeLinkedPullRequestReferences(
11415
+ directPullRequestLinks.map((record) => ({
11416
+ number: record.data.githubPullRequestNumber,
11417
+ repositoryUrl: record.data.repositoryUrl
11418
+ }))
11419
+ );
11420
+ if (!link && directPullRequestReferences.length === 0) {
11406
11421
  throw new Error("This Paperclip issue is not linked to GitHub yet.");
11407
11422
  }
11408
11423
  const explicitPullRequestNumber = normalizeToolPositiveInteger(input.pullRequestNumber);
11409
- const linkedPullRequests = link.linkedPullRequests.length > 0 ? link.linkedPullRequests : normalizeLinkedPullRequestReferences(link.linkedPullRequestNumbers, link.repositoryUrl);
11424
+ if (!link) {
11425
+ const explicitRepository = normalizeOptionalToolString(input.repository);
11426
+ if (explicitPullRequestNumber !== void 0) {
11427
+ const matchingPullRequests = directPullRequestReferences.filter(
11428
+ (pullRequest) => pullRequest.number === explicitPullRequestNumber
11429
+ );
11430
+ if (explicitRepository) {
11431
+ const requestedRepository = requireRepositoryReference(explicitRepository);
11432
+ const matchingPullRequest = matchingPullRequests.find(
11433
+ (pullRequest) => areRepositoriesEqual(requestedRepository, requireRepositoryReference(pullRequest.repositoryUrl))
11434
+ );
11435
+ if (!matchingPullRequest) {
11436
+ throw new Error("repository and pullRequestNumber must match a pull request directly linked to the provided Paperclip issue.");
11437
+ }
11438
+ return {
11439
+ repository: requestedRepository,
11440
+ pullRequestNumber: explicitPullRequestNumber,
11441
+ paperclipIssueId
11442
+ };
11443
+ }
11444
+ if (matchingPullRequests.length === 1) {
11445
+ return {
11446
+ repository: requireRepositoryReference(matchingPullRequests[0].repositoryUrl),
11447
+ pullRequestNumber: explicitPullRequestNumber,
11448
+ paperclipIssueId
11449
+ };
11450
+ }
11451
+ if (matchingPullRequests.length > 1) {
11452
+ throw new Error("repository is required because the Paperclip issue has matching direct pull request links in multiple repositories.");
11453
+ }
11454
+ throw new Error("pullRequestNumber must match a pull request directly linked to the provided Paperclip issue.");
11455
+ }
11456
+ if (directPullRequestReferences.length === 1) {
11457
+ const inferredPullRequest = directPullRequestReferences[0];
11458
+ if (explicitRepository) {
11459
+ const requestedRepository = requireRepositoryReference(explicitRepository);
11460
+ if (!areRepositoriesEqual(requestedRepository, requireRepositoryReference(inferredPullRequest.repositoryUrl))) {
11461
+ throw new Error("repository must match the GitHub repository for the directly linked pull request.");
11462
+ }
11463
+ }
11464
+ return {
11465
+ repository: requireRepositoryReference(inferredPullRequest.repositoryUrl),
11466
+ pullRequestNumber: inferredPullRequest.number,
11467
+ paperclipIssueId
11468
+ };
11469
+ }
11470
+ throw new Error("pullRequestNumber is required unless the Paperclip issue has exactly one directly linked pull request.");
11471
+ }
11472
+ const linkedPullRequests = normalizeLinkedPullRequestReferences([
11473
+ ...link.linkedPullRequests.length > 0 ? link.linkedPullRequests : normalizeLinkedPullRequestReferences(link.linkedPullRequestNumbers, link.repositoryUrl),
11474
+ ...directPullRequestReferences
11475
+ ]);
11410
11476
  if (explicitPullRequestNumber !== void 0) {
11411
11477
  const explicitRepository = normalizeOptionalToolString(input.repository);
11412
11478
  const matchingLinkedPullRequests = linkedPullRequests.filter(
@@ -15382,15 +15448,15 @@ function registerGitHubAgentTools(ctx) {
15382
15448
  if (!paperclipIssueId || !head || !headCommitSha || !base || !title) {
15383
15449
  throw new Error("paperclipIssueId, head, headCommitSha, base, and title are required.");
15384
15450
  }
15385
- const issueLinkScope = await resolveIssueGitHubLinkMapping(ctx, {
15386
- companyId: runCtx.companyId,
15387
- issueId: paperclipIssueId,
15388
- ...explicitRepository ? { repositoryUrl: explicitRepository } : {}
15389
- });
15390
- if (issueLinkScope.projectId !== runCtx.projectId) {
15451
+ const issue = await ctx.issues.get(paperclipIssueId, runCtx.companyId);
15452
+ if (!issue) {
15453
+ throw new Error("Paperclip issue was not found.");
15454
+ }
15455
+ const issueProjectId = normalizeOptionalToolString(issue.projectId);
15456
+ if (!issueProjectId || issueProjectId !== runCtx.projectId) {
15391
15457
  throw new Error("The selected Paperclip issue does not belong to the current tool run project.");
15392
15458
  }
15393
- if (issueLinkScope.issue.assigneeAgentId && issueLinkScope.issue.assigneeAgentId !== runCtx.agentId) {
15459
+ if (issue.assigneeAgentId && issue.assigneeAgentId !== runCtx.agentId) {
15394
15460
  throw new Error("The selected Paperclip issue is assigned to another agent.");
15395
15461
  }
15396
15462
  await ctx.issues.assertCheckoutOwner({
@@ -15399,7 +15465,7 @@ function registerGitHubAgentTools(ctx) {
15399
15465
  actorAgentId: runCtx.agentId,
15400
15466
  actorRunId: runCtx.runId
15401
15467
  });
15402
- const executionWorkspaceId = normalizeOptionalToolString(issueLinkScope.issue.executionWorkspaceId);
15468
+ const executionWorkspaceId = normalizeOptionalToolString(issue.executionWorkspaceId);
15403
15469
  if (!executionWorkspaceId) {
15404
15470
  throw new Error("The selected Paperclip issue does not have an execution workspace for branch publication.");
15405
15471
  }
@@ -15412,9 +15478,15 @@ function registerGitHubAgentTools(ctx) {
15412
15478
  throw new Error("The selected Paperclip issue execution workspace is not locally realized.");
15413
15479
  }
15414
15480
  const workspaceRepository = workspace.repoUrl ? parseRepositoryReference(workspace.repoUrl) : null;
15415
- const repository = issueLinkScope.repository;
15481
+ const repository = explicitRepository ? parseRepositoryReference(explicitRepository) : (await resolveIssueGitHubLinkMapping(ctx, {
15482
+ companyId: runCtx.companyId,
15483
+ issueId: paperclipIssueId
15484
+ })).repository;
15485
+ if (!repository) {
15486
+ throw new Error(`Invalid GitHub repository: ${explicitRepository}. Use owner/repo or https://github.com/owner/repo.`);
15487
+ }
15416
15488
  if (!workspaceRepository || !areRepositoriesEqual(workspaceRepository, repository)) {
15417
- throw new Error("The execution workspace repository does not match the GitHub repository mapped to this Paperclip issue.");
15489
+ throw new Error("The execution workspace repository does not match the selected GitHub repository.");
15418
15490
  }
15419
15491
  const githubToken = (await resolveGithubToken(ctx, { companyId: runCtx.companyId })).trim();
15420
15492
  if (!githubToken) {
@@ -15477,15 +15549,10 @@ function registerGitHubAgentTools(ctx) {
15477
15549
  pullRequestData = existingPullRequest;
15478
15550
  }
15479
15551
  if (paperclipIssueId) {
15480
- const linkScope = issueLinkScope ?? await resolveIssueGitHubLinkMapping(ctx, {
15481
- companyId: runCtx.companyId,
15482
- issueId: paperclipIssueId,
15483
- repositoryUrl: repository.url
15484
- });
15485
15552
  const pullRequestUrl = normalizeGitHubPullRequestHtmlUrl(pullRequestData.html_url) ?? `${repository.url}/pull/${pullRequestData.number}`;
15486
15553
  await upsertGitHubPullRequestLinkRecord(ctx, {
15487
15554
  companyId: runCtx.companyId,
15488
- projectId: linkScope.mapping.paperclipProjectId ?? linkScope.projectId,
15555
+ projectId: issueProjectId,
15489
15556
  issueId: paperclipIssueId,
15490
15557
  repositoryUrl: repository.url,
15491
15558
  pullRequestNumber: pullRequestData.number,
@@ -15498,7 +15565,7 @@ function registerGitHubAgentTools(ctx) {
15498
15565
  });
15499
15566
  invalidateProjectPullRequestCaches({
15500
15567
  companyId: runCtx.companyId,
15501
- projectId: linkScope.mapping.paperclipProjectId ?? linkScope.projectId,
15568
+ projectId: issueProjectId,
15502
15569
  repository
15503
15570
  });
15504
15571
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Paperclip plugin for synchronizing GitHub issues into Paperclip projects.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
- "packageManager": "pnpm@11.7.0",
7
+ "packageManager": "pnpm@11.9.0",
8
8
  "engines": {
9
9
  "node": ">=20"
10
10
  },
@@ -52,7 +52,7 @@
52
52
  "@types/node": "24.13.2",
53
53
  "@types/react": "19.2.17",
54
54
  "esbuild": "0.28.1",
55
- "playwright": "1.61.0",
55
+ "playwright": "1.61.1",
56
56
  "tsx": "4.22.4",
57
57
  "typescript": "6.0.3"
58
58
  }