paperclip-github-plugin 0.14.1 → 0.15.1

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
@@ -239,9 +239,9 @@ The plugin exposes GitHub workflow tools to Paperclip agents, including:
239
239
  - review-thread reads, replies, resolve and unresolve actions, and `request_pull_request_reviewers` reviewer requests
240
240
  - organization-level GitHub Project search/listing and pull-request-to-project association
241
241
 
242
- `create_pull_request` is the single agent-facing delivery call for both branch publication and PR creation. The caller supplies the Paperclip issue id, a plain local branch name, the exact 40-character local branch-tip SHA, the base branch, and the PR metadata. The trusted plugin worker verifies checkout ownership, resolves the issue's execution worktree and GitHub secret, verifies the checked-out branch, worktree HEAD, local branch tip, and base ancestry, publishes only that exact commit with a non-forcing refspec, reads the remote branch SHA back, and only then creates and links the PR. The GitHub credential is never returned to or injected into the calling agent.
242
+ `create_pull_request` is the single agent-facing delivery call for both branch publication and PR creation. The caller supplies the Paperclip issue id, a plain local branch name, the exact 40-character local branch-tip SHA, the base branch, and the PR metadata. The optional `repository` may select any GitHub repository, including one that is not mapped in Paperclip; if omitted, the issue project must have exactly one mapped repository. By default the tool uses the execution-workspace root as the local Git checkout. For general-purpose workspaces that contain several repositories, `workspaceRelativePath` selects a checkout below that trusted root, with realpath containment enforced. The trusted plugin worker verifies checkout ownership, resolves the issue's execution worktree and GitHub secret, verifies the checked-out branch, worktree HEAD, local branch tip, and base ancestry, publishes only that exact commit with a non-forcing refspec, reads the remote branch SHA back, and only then asks GitHub to create and link the PR. GitHub token permissions determine whether publication and PR creation are allowed. The credential is never returned to or injected into the calling agent.
243
243
 
244
- Branch publication uses an isolated temporary bare repository backed by the trusted workspace object database. It does not execute repository hooks, accept arbitrary refspecs, or honor agent-supplied remote URLs. Publication rejects owner-qualified heads, base-branch targets, non-fast-forward updates, cross-project issues, mismatched local branch tips, and remote SHA mismatches.
244
+ 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.
245
245
 
246
246
  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.
247
247
 
package/dist/manifest.js CHANGED
@@ -260,10 +260,17 @@ var GITHUB_AGENT_TOOLS = [
260
260
  additionalProperties: false,
261
261
  required: ["paperclipIssueId", "head", "headCommitSha", "base", "title"],
262
262
  properties: {
263
- repository: repositoryProperty,
263
+ repository: {
264
+ type: "string",
265
+ description: "Target GitHub repository as owner/repo or https://github.com/owner/repo. It may be outside Paperclip repository mappings. Omit only when the issue project has exactly one mapped repository."
266
+ },
267
+ workspaceRelativePath: {
268
+ type: "string",
269
+ description: "Optional path to the local Git checkout, relative to the trusted issue execution workspace. Use this when a general-purpose workspace contains the target repository in a subdirectory."
270
+ },
264
271
  paperclipIssueId: {
265
272
  type: "string",
266
- description: "Paperclip issue id used to resolve the trusted project workspace, mapped GitHub repository, and durable pull-request link."
273
+ description: "Paperclip issue id used to resolve the trusted execution workspace and durable pull-request link."
267
274
  },
268
275
  head: {
269
276
  type: "string",
@@ -641,7 +648,7 @@ var COMPANY_METRIC_API_ROUTE_URL_PATH = `/api/plugins/${GITHUB_SYNC_PLUGIN_ID}/a
641
648
  var require2 = createRequire(import.meta.url);
642
649
  var packageJson = require2("../package.json");
643
650
  var SCHEDULE_TICK_CRON = "* * * * *";
644
- var MANIFEST_VERSION = "0.14.1"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
651
+ var MANIFEST_VERSION = "0.15.1"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
645
652
  var manifest = {
646
653
  id: GITHUB_SYNC_PLUGIN_ID,
647
654
  apiVersion: 1,
package/dist/worker.js CHANGED
@@ -3,7 +3,7 @@ import { Buffer as Buffer2 } from "node:buffer";
3
3
  import { realpathSync } from "node:fs";
4
4
  import { chmod, mkdir as mkdir2, readFile, writeFile } from "node:fs/promises";
5
5
  import { homedir } from "node:os";
6
- import { dirname, join as join2, resolve as resolve2 } from "node:path";
6
+ import { dirname, isAbsolute as isAbsolute2, join as join2, relative, resolve as resolve2 } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { Octokit } from "@octokit/rest";
9
9
  import {
@@ -270,10 +270,17 @@ 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. Omit only when the issue project has exactly one mapped repository."
276
+ },
277
+ workspaceRelativePath: {
278
+ type: "string",
279
+ description: "Optional path to the local Git checkout, relative to the trusted issue execution workspace. Use this when a general-purpose workspace contains the target repository in a subdirectory."
280
+ },
274
281
  paperclipIssueId: {
275
282
  type: "string",
276
- description: "Paperclip issue id used to resolve the trusted project workspace, mapped GitHub repository, and durable pull-request link."
283
+ description: "Paperclip issue id used to resolve the trusted execution workspace and durable pull-request link."
277
284
  },
278
285
  head: {
279
286
  type: "string",
@@ -15125,6 +15132,21 @@ async function startSync(ctx, trigger, options = {}) {
15125
15132
  return getActiveOrCurrentSyncState(ctx);
15126
15133
  }
15127
15134
  }
15135
+ function resolveTrustedWorkspacePath(workspacePath, workspaceRelativePath) {
15136
+ if (!workspaceRelativePath) {
15137
+ return workspacePath;
15138
+ }
15139
+ const trustedRoot = realpathSync(workspacePath);
15140
+ if (isAbsolute2(workspaceRelativePath)) {
15141
+ throw new Error("workspaceRelativePath must be relative to the trusted execution workspace.");
15142
+ }
15143
+ const candidate = realpathSync(resolve2(trustedRoot, workspaceRelativePath));
15144
+ const relativeCandidate = relative(trustedRoot, candidate);
15145
+ if (relativeCandidate === ".." || relativeCandidate.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute2(relativeCandidate)) {
15146
+ throw new Error("workspaceRelativePath must stay inside the trusted execution workspace.");
15147
+ }
15148
+ return candidate;
15149
+ }
15128
15150
  function registerGitHubAgentTools(ctx) {
15129
15151
  async function createAgentToolOctokit(runCtx, toolName, repository) {
15130
15152
  return createGitHubToolOctokit(ctx, runCtx.companyId, {
@@ -15438,6 +15460,7 @@ function registerGitHubAgentTools(ctx) {
15438
15460
  const input = getToolInputRecord(params);
15439
15461
  const paperclipIssueId = normalizeOptionalToolString(input.paperclipIssueId);
15440
15462
  const explicitRepository = normalizeOptionalToolString(input.repository);
15463
+ const workspaceRelativePath = normalizeOptionalToolString(input.workspaceRelativePath);
15441
15464
  const head = normalizeOptionalToolString(input.head);
15442
15465
  const headCommitSha = normalizeOptionalToolString(input.headCommitSha);
15443
15466
  const base = normalizeOptionalToolString(input.base);
@@ -15445,15 +15468,15 @@ function registerGitHubAgentTools(ctx) {
15445
15468
  if (!paperclipIssueId || !head || !headCommitSha || !base || !title) {
15446
15469
  throw new Error("paperclipIssueId, head, headCommitSha, base, and title are required.");
15447
15470
  }
15448
- const issueLinkScope = await resolveIssueGitHubLinkMapping(ctx, {
15449
- companyId: runCtx.companyId,
15450
- issueId: paperclipIssueId,
15451
- ...explicitRepository ? { repositoryUrl: explicitRepository } : {}
15452
- });
15453
- if (issueLinkScope.projectId !== runCtx.projectId) {
15471
+ const issue = await ctx.issues.get(paperclipIssueId, runCtx.companyId);
15472
+ if (!issue) {
15473
+ throw new Error("Paperclip issue was not found.");
15474
+ }
15475
+ const issueProjectId = normalizeOptionalToolString(issue.projectId);
15476
+ if (!issueProjectId || issueProjectId !== runCtx.projectId) {
15454
15477
  throw new Error("The selected Paperclip issue does not belong to the current tool run project.");
15455
15478
  }
15456
- if (issueLinkScope.issue.assigneeAgentId && issueLinkScope.issue.assigneeAgentId !== runCtx.agentId) {
15479
+ if (issue.assigneeAgentId && issue.assigneeAgentId !== runCtx.agentId) {
15457
15480
  throw new Error("The selected Paperclip issue is assigned to another agent.");
15458
15481
  }
15459
15482
  await ctx.issues.assertCheckoutOwner({
@@ -15462,7 +15485,7 @@ function registerGitHubAgentTools(ctx) {
15462
15485
  actorAgentId: runCtx.agentId,
15463
15486
  actorRunId: runCtx.runId
15464
15487
  });
15465
- const executionWorkspaceId = normalizeOptionalToolString(issueLinkScope.issue.executionWorkspaceId);
15488
+ const executionWorkspaceId = normalizeOptionalToolString(issue.executionWorkspaceId);
15466
15489
  if (!executionWorkspaceId) {
15467
15490
  throw new Error("The selected Paperclip issue does not have an execution workspace for branch publication.");
15468
15491
  }
@@ -15474,17 +15497,20 @@ function registerGitHubAgentTools(ctx) {
15474
15497
  if (!workspacePath) {
15475
15498
  throw new Error("The selected Paperclip issue execution workspace is not locally realized.");
15476
15499
  }
15477
- const workspaceRepository = workspace.repoUrl ? parseRepositoryReference(workspace.repoUrl) : null;
15478
- const repository = issueLinkScope.repository;
15479
- if (!workspaceRepository || !areRepositoriesEqual(workspaceRepository, repository)) {
15480
- throw new Error("The execution workspace repository does not match the GitHub repository mapped to this Paperclip issue.");
15500
+ const publicationWorkspacePath = resolveTrustedWorkspacePath(workspacePath, workspaceRelativePath);
15501
+ const repository = explicitRepository ? parseRepositoryReference(explicitRepository) : (await resolveIssueGitHubLinkMapping(ctx, {
15502
+ companyId: runCtx.companyId,
15503
+ issueId: paperclipIssueId
15504
+ })).repository;
15505
+ if (!repository) {
15506
+ throw new Error(`Invalid GitHub repository: ${explicitRepository}. Use owner/repo or https://github.com/owner/repo.`);
15481
15507
  }
15482
15508
  const githubToken = (await resolveGithubToken(ctx, { companyId: runCtx.companyId })).trim();
15483
15509
  if (!githubToken) {
15484
15510
  throw new Error(MISSING_GITHUB_TOKEN_SYNC_MESSAGE);
15485
15511
  }
15486
15512
  const publishedBranch = await createPullRequestBranchPublisher({
15487
- workspacePath,
15513
+ workspacePath: publicationWorkspacePath,
15488
15514
  repositoryUrl: repository.url,
15489
15515
  branchName: head,
15490
15516
  expectedCommitSha: headCommitSha,
@@ -15540,15 +15566,10 @@ function registerGitHubAgentTools(ctx) {
15540
15566
  pullRequestData = existingPullRequest;
15541
15567
  }
15542
15568
  if (paperclipIssueId) {
15543
- const linkScope = issueLinkScope ?? await resolveIssueGitHubLinkMapping(ctx, {
15544
- companyId: runCtx.companyId,
15545
- issueId: paperclipIssueId,
15546
- repositoryUrl: repository.url
15547
- });
15548
15569
  const pullRequestUrl = normalizeGitHubPullRequestHtmlUrl(pullRequestData.html_url) ?? `${repository.url}/pull/${pullRequestData.number}`;
15549
15570
  await upsertGitHubPullRequestLinkRecord(ctx, {
15550
15571
  companyId: runCtx.companyId,
15551
- projectId: linkScope.mapping.paperclipProjectId ?? linkScope.projectId,
15572
+ projectId: issueProjectId,
15552
15573
  issueId: paperclipIssueId,
15553
15574
  repositoryUrl: repository.url,
15554
15575
  pullRequestNumber: pullRequestData.number,
@@ -15561,7 +15582,7 @@ function registerGitHubAgentTools(ctx) {
15561
15582
  });
15562
15583
  invalidateProjectPullRequestCaches({
15563
15584
  companyId: runCtx.companyId,
15564
- projectId: linkScope.mapping.paperclipProjectId ?? linkScope.projectId,
15585
+ projectId: issueProjectId,
15565
15586
  repository
15566
15587
  });
15567
15588
  }
@@ -16145,6 +16166,7 @@ var __testing = {
16145
16166
  resolveGithubToken,
16146
16167
  resolvePaperclipPullRequestIssueStatus,
16147
16168
  resolveSyncTransitionAssignee,
16169
+ resolveTrustedWorkspacePath,
16148
16170
  setCreatePullRequestBranchPublisher(publisher) {
16149
16171
  createPullRequestBranchPublisher = publisher ?? publishLocalBranchForPullRequest;
16150
16172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.14.1",
3
+ "version": "0.15.1",
4
4
  "description": "Paperclip plugin for synchronizing GitHub issues into Paperclip projects.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",