paperclip-github-plugin 0.17.0 → 0.17.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
@@ -225,6 +225,16 @@ The plugin is designed to avoid persisting raw credentials in plugin state.
225
225
  - On authenticated Paperclip deployments, sync is blocked until the relevant company has connected Paperclip board access. On local trusted deployments, board access setup remains visible so operators can configure it for host API paths that still require board credentials, but missing board access does not by itself block sync preflight.
226
226
  - KPI API route requests must include `Authorization: Bearer <PAPERCLIP_API_KEY>` from an agent run; the Paperclip host authenticates the token and supplies the agent company before the worker records any metric event.
227
227
 
228
+ #### Sharing the token with Paperclip's own GitHub features
229
+
230
+ GitHub Sync stores its token as a company secret named `github_sync_<company id>` and references it from plugin config. Paperclip's host-side GitHub features do not read that reference: `server/src/services/git-credentials.ts` resolves a company secret **by name**, probing `GITHUB_TOKEN`, `GH_TOKEN` and `PAPERCLIP_GITHUB_TOKEN` in that order. Those credentials back managed-checkout git authentication, the merged-PR confirmation sweep, the execution-workspace reaper's `merged_via_pr` detection, and the built-in GitHub external-object provider's liveness snapshots. Without one of those secrets those host features run unauthenticated and degrade on private repositories and GitHub rate limits.
231
+
232
+ The **GitHub access** section of GitHub Sync settings has an opt-in checkbox, **Also expose this token to Paperclip as `GITHUB_TOKEN`**. It is unchecked by default. When checked, saving the token also creates a company secret named `GITHUB_TOKEN` with the same value, or rotates the existing one in place when the company already has it, so there is never a second divergent copy. The plugin's own `github_sync_<company id>` secret and its plugin-config reference are unchanged either way; unchecking the box on a later save does **not** delete or rotate an existing `GITHUB_TOKEN`.
233
+
234
+ The host matches the name **exactly**, so the plugin looks for a secret named `GITHUB_TOKEN` case-sensitively. Paperclip also derives a unique `key` from a secret's name, so a company that already has a secret named `github_token` (or any other casing) makes the create fail with a conflict; the settings page surfaces that conflict instead of silently rotating the wrong row. Keep the secret's status `active`: the git-credential probe silently skips a disabled or archived secret, and the external-object/merged-PR path fails with an auth error on one.
235
+
236
+ Leave it unchecked if you want the GitHub credential scoped to the plugin worker only. A secret named `GITHUB_TOKEN` is readable by any host feature and by agent-facing secret surfaces that resolve company secrets by name, which is a wider blast radius than a plugin secret reference bound to GitHub Sync. If you prefer separate credentials, create a `GITHUB_TOKEN` company secret manually with a narrower token instead of ticking the box.
237
+
228
238
  ### Optional worker-local token file
229
239
 
230
240
  Paperclip-managed, company-scoped secret refs are the normal path on Paperclip `2026.831` and newer. If they are not available, the worker can read a local fallback file at `${PAPERCLIP_HOME:-~/.paperclip}/plugins/github-sync/config.json`:
@@ -276,6 +286,123 @@ When an agent sends GitHub body content through the plugin, including issue bodi
276
286
 
277
287
  `update_issue` accepts `stateReason` with GitHub's native values `completed`, `not_planned`, `duplicate`, and `reopened`. Closing uses `state: "closed"` with one of the first three reasons; reopening uses `state: "open"` with `stateReason: "reopened"`. Duplicate closure also requires `duplicateIssueNumber`, which the worker resolves to GitHub's canonical database id in the same repository. GitHub only applies a reason while changing state, so changing the reason of an already-closed issue fails clearly and requires reopening it first.
278
288
 
289
+ ### Granting the tools to agents
290
+
291
+ On Paperclip `2026.831` and newer, agent tool discovery and execution go through the host MCP **tool gateway**, and the gateway is **fail-closed**. When no tool profile, explicit grant, or allow policy matches a call, the policy service returns `deny_default` (`server/src/services/tool-access-policy.ts`). That means a freshly installed GitHub Sync sees **zero** `paperclip-github-plugin:*` tools offered to agents until a tool profile includes them — the plugin manifest has no field that can declare default access.
292
+
293
+ Two details decide the recipe:
294
+
295
+ - Plugin tools are dispatched with `providerType: "paperclip_plugin"` and carry **no connection id, no catalog entry id and no application id** (`server/src/services/tool-gateway.ts`). A profile entry with `selectorType: "connection"` or `"catalog_entry"` requires a non-null id at write time, so those selectors can never match a plugin tool.
296
+ - The selectors that *can* match are `tool_name` (compared against the fully namespaced name, `paperclip-github-plugin:<tool>`) and `risk_level`. A profile with `defaultAction: "allow"` also matches everything.
297
+
298
+ The recipe below uses explicit `tool_name` include entries for all 21 tools on a profile whose `defaultAction` stays `deny`, bound at **company** scope. That keeps the profile least-privilege and makes the grant auditable per tool.
299
+
300
+ #### The 21 tool names
301
+
302
+ ```text
303
+ paperclip-github-plugin:search_repository_items
304
+ paperclip-github-plugin:get_issue
305
+ paperclip-github-plugin:list_issue_comments
306
+ paperclip-github-plugin:update_issue
307
+ paperclip-github-plugin:assign_to_current_user
308
+ paperclip-github-plugin:add_issue_comment
309
+ paperclip-github-plugin:create_pull_request
310
+ paperclip-github-plugin:get_pull_request
311
+ paperclip-github-plugin:update_pull_request
312
+ paperclip-github-plugin:list_pull_request_files
313
+ paperclip-github-plugin:get_pull_request_checks
314
+ paperclip-github-plugin:list_pull_request_review_threads
315
+ paperclip-github-plugin:reply_to_review_thread
316
+ paperclip-github-plugin:resolve_review_thread
317
+ paperclip-github-plugin:unresolve_review_thread
318
+ paperclip-github-plugin:request_pull_request_reviewers
319
+ paperclip-github-plugin:list_organization_projects
320
+ paperclip-github-plugin:add_pull_request_to_project
321
+ paperclip-github-plugin:upload_pull_request_asset
322
+ paperclip-github-plugin:link_github_item
323
+ paperclip-github-plugin:get_issue_interaction_summary
324
+ ```
325
+
326
+ #### Ready-to-run recipe
327
+
328
+ The script derives the names from the host instead of hard-coding them, so it stays correct across plugin versions. Use a **board API key** as the bearer token: board *session* cookies are additionally subject to the host's board-mutation origin guard, which rejects `POST`s without a trusted `Origin` header.
329
+
330
+ ```bash
331
+ #!/usr/bin/env bash
332
+ set -euo pipefail
333
+
334
+ PAPERCLIP_API_URL="${PAPERCLIP_API_URL:-http://localhost:3100}"
335
+ PAPERCLIP_BOARD_API_KEY="${PAPERCLIP_BOARD_API_KEY:?set a board API key}"
336
+ COMPANY_ID="${COMPANY_ID:?set the Paperclip company id}"
337
+ PLUGIN_ID="paperclip-github-plugin"
338
+
339
+ # `--fail-with-body` makes curl exit non-zero on 4xx/5xx while still printing the error body,
340
+ # so a 409 conflict or a 403 cannot be parsed into a null id and used in the next request.
341
+ api() {
342
+ local method="$1" path="$2"
343
+ shift 2
344
+ curl -sS --fail-with-body -X "${method}" "${PAPERCLIP_API_URL%/}${path}" \
345
+ -H "authorization: Bearer ${PAPERCLIP_BOARD_API_KEY}" \
346
+ -H "content-type: application/json" \
347
+ -H "accept: application/json" "$@"
348
+ }
349
+
350
+ require_id() {
351
+ local value="$1" label="$2"
352
+ if [ -z "${value}" ] || [ "${value}" = "null" ]; then
353
+ echo "${label} was not returned by Paperclip." >&2
354
+ exit 1
355
+ fi
356
+ printf '%s' "${value}"
357
+ }
358
+
359
+ # 1. Derive the tool names. As a board actor this route is unfiltered by policy and
360
+ # `pluginId` must be the plugin key, not the plugin's database UUID.
361
+ # The response is a bare array whose `name` field is already `<pluginKey>:<tool>`.
362
+ tool_names="$(api GET "/api/plugins/tools?pluginId=${PLUGIN_ID}" | jq -r '.[].name')"
363
+ test -n "${tool_names}" || { echo "No plugin tools returned; is GitHub Sync installed?" >&2; exit 1; }
364
+
365
+ # 2. Build one include entry per tool.
366
+ entries="$(jq -Rn --arg names "${tool_names}" '
367
+ ($names | split("\n") | map(select(length > 0)))
368
+ | map({ selectorType: "tool_name", toolName: ., effect: "include" })
369
+ ')"
370
+
371
+ # 3. Create the profile. `defaultAction` stays "deny": only the listed tools are included.
372
+ profile_id="$(require_id "$(api POST "/api/companies/${COMPANY_ID}/tools/profiles" -d "$(jq -n \
373
+ --argjson entries "${entries}" '{
374
+ profileKey: "github-sync-tools",
375
+ name: "GitHub Sync tools",
376
+ defaultAction: "deny",
377
+ status: "active",
378
+ entries: $entries
379
+ }')" | jq -r '.id')" "Profile id")"
380
+
381
+ # 4. Bind it to the whole company. `targetId` must equal the company id for company scope.
382
+ api POST "/api/companies/${COMPANY_ID}/tools/profiles/${profile_id}/bind" -d "$(jq -n \
383
+ --arg targetId "${COMPANY_ID}" '{
384
+ targetType: "company",
385
+ targetId: $targetId,
386
+ priority: 100
387
+ }')" | jq '{ id, targetType, targetId, priority }'
388
+
389
+ # 5. Verify for one agent. `allowedToolNames` includes tool_name entries that have no MCP
390
+ # catalog row, which is exactly how plugin tools show up here.
391
+ agent_id="$(require_id "$(api GET "/api/companies/${COMPANY_ID}/agents" \
392
+ | jq -r '[.[] | select(.status == "active")][0].id')" "Active agent id")"
393
+ api GET "/api/companies/${COMPANY_ID}/tools/profiles/effective/agents/${agent_id}" \
394
+ | jq --arg prefix "${PLUGIN_ID}:" '[.allowedToolNames[] | select(startswith($prefix))] | length'
395
+ ```
396
+
397
+ Notes and gotchas:
398
+
399
+ - Request/response shapes at `2026.831.1`: profile create returns the profile object **at the top level** (so `.id` works), bind returns the binding at the top level, and list returns `{ "profiles": [...] }`. Profile-entry bodies take `selectorType`, `effect`, `toolName`, `riskLevel`, `applicationId`, `connectionId`, `catalogEntryId` and `conditions` — there is no `selectorValue` field, and unknown keys are silently dropped by the validator.
400
+ - `profileKey` must match `^[a-z0-9][a-z0-9._:-]*$`; creating a second profile with the same name in one company is a conflict.
401
+ - Both `POST`s require a board actor with an **active, non-viewer** company membership. Agent API keys are rejected.
402
+ - Binding `targetType: "agent"` narrows the grant to a single agent and wins over a company-scope binding for that agent. `project`, `routine`, `issue` and `gateway` bindings are ignored by the effective-tools view.
403
+ - To revoke, `POST /api/companies/{companyId}/tools/profiles/{profileId}/unbind` with `{"targetType":"company","targetId":"<companyId>"}`.
404
+ - The effective-tools route is evaluated **per agent**, and an `agent`-scoped binding overrides the company one, so verifying one agent does not prove the grant for every agent. GitHub Sync settings runs this same check read-only against a single sampled agent and warns when that agent can see none of the tools; the banner names the agent it checked. The check needs Paperclip board access connected and a reachable **Worker Paperclip API URL**; on hosts that do not expose the route it stays silent.
405
+
279
406
  ### KPI attribution API route
280
407
 
281
408
  The `create_pull_request` tool automatically records a company-level Paperclip PR creation metric. For delivery flows that use `gh` or another non-plugin GitHub client, post a JSON payload to `/api/plugins/paperclip-github-plugin/api/company-metrics/events` after the PR is created.
@@ -317,8 +444,11 @@ GitHub Sync targets Paperclip `2026.831.1` and adopts the host changes that matt
317
444
 
318
445
  - **Company-scoped plugin config.** The host now stores one GitHub Sync config row per company and replays each of them to the worker after startup instead of passing a bootstrap config. The worker declares `multiCompanyConfig: true`, keys the delivered config by company, and passes the company id to every config read. Scheduled sync and other proactive paths only get host access for companies that have a saved GitHub Sync config; a company that has mappings but no saved config shows a sync error asking you to open GitHub Sync settings in that company and save once.
319
446
  - **Secret refs re-enabled.** Company-scoped secret refs are the normal path again. The settings UI mirrors GitHub tokens and board access tokens into plugin config as `{ "type": "secret_ref", "secretId": "<uuid>" }` bindings, and the worker resolves them with the company id and config path. The worker-local token file remains a compatibility fallback only.
320
- - **Tool gateway.** Agent tool discovery and execution now run through the host tool gateway, which applies each company's tool-access policy before a GitHub Sync tool runs. Tool names are unchanged (`<pluginId>:<tool>`); if a tool is missing for an agent, check the company's tool-access policy before suspecting the plugin.
447
+ - **Tool gateway.** Agent tool discovery and execution now run through the host tool gateway, which applies each company's tool-access policy before a GitHub Sync tool runs. The gateway is fail-closed, so a company with no matching tool profile sees no GitHub Sync tools at all. Tool names are unchanged (`<pluginId>:<tool>`); see [Granting the tools to agents](#granting-the-tools-to-agents) for the profile recipe and the settings-page warning that detects this.
321
448
  - **Optional capabilities not adopted.** `2026.831` adds `issue.interactions.read`, `issue.attachments.read`, `approvals.read`, `issue.comments.create_human_attributed`, `issue.interactions.respond`, and `approvals.respond`. GitHub Sync does not use those host surfaces, so it does not declare them; it keeps its existing capability set.
449
+ - **Company export/import does not carry plugin data.** The full-fidelity import/export bundles introduced in `2026.817` describe companies, agents, skills, projects, issues, comments, labels, blobs, documents, work products, monitors and attachments (`packages/shared/src/validators/company-portability.ts`). The manifest has no plugin section at all, so **nothing owned by GitHub Sync survives an export/import**: repository mappings, plugin config and secret refs, issue-link and pull-request-link entities, the import registry, KPI history and the issue interaction ledger are all absent from the bundle, and imported issues keep only their `metadata`. After importing a company, re-open GitHub Sync settings in the target company, save the token and mappings again, and expect the first sync to treat previously imported GitHub issues as new work unless the links are rebuilt. A "re-link imported company" action that rebuilds link entities from the canonical GitHub URLs in issue descriptions and comments is future work, not a shipped feature.
450
+ - **The experimental GitHub MCP app is complementary, not a replacement.** Connections v3 (`2026.722`) ships a GitHub app definition (`packages/shared/src/app-definitions/github.json`) that connects agents to GitHub's hosted MCP server at `https://api.githubcopilot.com/mcp/` with an API key. Those are *raw* GitHub tools: they act on `owner/repo` coordinates, know nothing about Paperclip issues, and the connection credential is handled as a normal connection secret. GitHub Sync's tools are *issue-aware*: they take a `paperclipIssueId`, resolve the mapped repository and execution worktree, write durable issue/PR link entities and interaction-ledger rows, record KPI attribution, and never return or inject the GitHub token into the calling agent. Use the MCP app for ad-hoc or read-only GitHub work outside mapped projects, and GitHub Sync tools for anything that has to stay attached to Paperclip work. If both are enabled, scope them with separate tool profiles so agents get a predictable set.
451
+ - **The host's merged-PR confirmation sweep coexists with plugin status routing.** `2026.817` added a sweep (`server/src/services/issue-thread-interactions.ts`, `sweepMergedPullRequestConfirmations`) that auto-resolves `request_confirmation` interactions whose text references a pull request once GitHub reports it merged. It uses a read-only merge-state resolver and the host's own `GITHUB_TOKEN`-family credential, so it never writes to GitHub and never changes issue status. GitHub Sync remains the source of truth for mapped and linked issue status: the sweep closes the human confirmation loop, while sync still performs the `in_review` -> `done` transition, the assignee and execution-policy handoff, and the transition comment. The two can run against the same pull request without conflicting; if the sweep resolves nothing, check that the host has one of the `GITHUB_TOKEN`-family company secrets (see [Security and authentication](#security-and-authentication)).
322
452
  - **No strict host-version gate.** The manifest still relies on declared capabilities and runtime fallbacks instead of `minimumHostVersion`, because latest/development hosts can report `0.0.0` during plugin upgrade.
323
453
  - **Project sidebar item has no mount point.** `2026.831` made the streamlined main sidebar mandatory (PAP-12472) and no longer renders the per-project list that hosted `projectSidebarItem` contributions. GitHub Sync keeps declaring the slot for hosts that render it, but on `2026.831` the **Pull Requests** entry does not appear; the queue page itself is unaffected and opens at `/<company-prefix>/github-pull-requests?projectId=<project id>`. The e2e harness verifies the sidebar link only when the host renders it and always opens the page by route.
324
454
 
package/dist/manifest.js CHANGED
@@ -691,7 +691,7 @@ var COMPANY_METRIC_API_ROUTE_URL_PATH = `/api/plugins/${GITHUB_SYNC_PLUGIN_ID}/a
691
691
  var require2 = createRequire(import.meta.url);
692
692
  var packageJson = require2("../package.json");
693
693
  var SCHEDULE_TICK_CRON = "* * * * *";
694
- var MANIFEST_VERSION = "0.17.0"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
694
+ var MANIFEST_VERSION = "0.17.2"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
695
695
  var COMPANY_SECRET_REF_VALUE_SCHEMA = {
696
696
  anyOf: [
697
697
  { type: "string" },