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/dist/worker.js CHANGED
@@ -9184,6 +9184,12 @@ function getPaperclipHealthEndpoint(baseUrl) {
9184
9184
  function getPaperclipAgentWakeupEndpoint(baseUrl, agentId) {
9185
9185
  return new URL(`/api/agents/${agentId}/wakeup`, baseUrl).toString();
9186
9186
  }
9187
+ function getPaperclipEffectiveAgentToolProfilesEndpoint(baseUrl, companyId, agentId) {
9188
+ return new URL(
9189
+ `/api/companies/${encodeURIComponent(companyId)}/tools/profiles/effective/agents/${encodeURIComponent(agentId)}`,
9190
+ baseUrl
9191
+ ).toString();
9192
+ }
9187
9193
  function getActivePaperclipApiAuthToken(companyId) {
9188
9194
  if (!companyId) {
9189
9195
  return void 0;
@@ -11795,7 +11801,7 @@ function mergeRememberedTrustedConfig() {
11795
11801
  }
11796
11802
  return merged;
11797
11803
  }
11798
- async function readTrustedConfig(ctx, companyId) {
11804
+ async function readTrustedConfig(ctx, companyId, options = {}) {
11799
11805
  const normalizedCompanyId = normalizeCompanyId(companyId);
11800
11806
  try {
11801
11807
  const value = await ctx.config.get(normalizedCompanyId);
@@ -11806,6 +11812,9 @@ async function readTrustedConfig(ctx, companyId) {
11806
11812
  return record;
11807
11813
  } catch (error) {
11808
11814
  const remembered = normalizedCompanyId ? rememberedTrustedConfigByCompanyId.get(normalizedCompanyId) : mergeRememberedTrustedConfig();
11815
+ if (options.requireCompanyScope && normalizedCompanyId && !remembered && isCompanyScopeDeniedError(error)) {
11816
+ throw error;
11817
+ }
11809
11818
  const warningKey = `${normalizedCompanyId ?? "<instance>"}:${getErrorMessage(error)}`;
11810
11819
  if (!reportedTrustedConfigReadFailures.has(warningKey)) {
11811
11820
  reportedTrustedConfigReadFailures.add(warningKey);
@@ -11821,9 +11830,9 @@ async function readTrustedConfig(ctx, companyId) {
11821
11830
  return remembered ?? {};
11822
11831
  }
11823
11832
  }
11824
- async function getResolvedConfig(ctx, companyId) {
11833
+ async function getResolvedConfig(ctx, companyId, options = {}) {
11825
11834
  const [savedConfig, externalConfig] = await Promise.all([
11826
- readTrustedConfig(ctx, companyId),
11835
+ readTrustedConfig(ctx, companyId, options),
11827
11836
  readExternalConfig(ctx)
11828
11837
  ]);
11829
11838
  return {
@@ -11925,53 +11934,56 @@ async function resolvePaperclipApiAuthTokens(ctx, settings, config, mappings) {
11925
11934
  ];
11926
11935
  const tokensByCompanyId = /* @__PURE__ */ new Map();
11927
11936
  for (const companyId of companyIds) {
11928
- const configuredSecretRef = getConfiguredPaperclipBoardApiTokenRef(config, companyId);
11929
- const savedSecretRef = getSavedPaperclipBoardApiTokenRef(settings, companyId);
11930
- const fallbackToken = normalizeGitHubToken(config.paperclipBoardApiTokensByCompanyId?.[companyId]);
11931
- const secretRef = configuredSecretRef ?? savedSecretRef;
11932
- if (!secretRef) {
11933
- continue;
11937
+ const token = await resolvePaperclipApiAuthTokenForCompany(ctx, settings, config, companyId);
11938
+ if (token) {
11939
+ tokensByCompanyId.set(companyId, token);
11934
11940
  }
11935
- if (!configuredSecretRef && savedSecretRef) {
11936
- if (fallbackToken) {
11937
- tokensByCompanyId.set(companyId, fallbackToken);
11938
- continue;
11939
- }
11940
- ctx.logger.warn(
11941
- "Paperclip board access is saved in plugin state but has not been mirrored into plugin config yet. Open plugin settings to finish migrating it, or reconnect board access, before retrying sync.",
11942
- {
11943
- companyId,
11944
- secretRef: savedSecretRef
11945
- }
11946
- );
11947
- continue;
11941
+ }
11942
+ return tokensByCompanyId;
11943
+ }
11944
+ async function resolvePaperclipApiAuthTokenForCompany(ctx, settings, config, companyId) {
11945
+ const configuredSecretRef = getConfiguredPaperclipBoardApiTokenRef(config, companyId);
11946
+ const savedSecretRef = getSavedPaperclipBoardApiTokenRef(settings, companyId);
11947
+ const fallbackToken = normalizeGitHubToken(config.paperclipBoardApiTokensByCompanyId?.[companyId]);
11948
+ const secretRef = configuredSecretRef ?? savedSecretRef;
11949
+ if (!secretRef) {
11950
+ return null;
11951
+ }
11952
+ if (!configuredSecretRef && savedSecretRef) {
11953
+ if (fallbackToken) {
11954
+ return fallbackToken;
11948
11955
  }
11949
- try {
11950
- const token = (await resolvePluginSecret(ctx, secretRef, {
11956
+ ctx.logger.warn(
11957
+ "Paperclip board access is saved in plugin state but has not been mirrored into plugin config yet. Open plugin settings to finish migrating it, or reconnect board access, before retrying sync.",
11958
+ {
11951
11959
  companyId,
11952
- configPath: getPaperclipBoardApiTokenRefConfigPath(companyId)
11953
- })).trim();
11954
- if (token) {
11955
- tokensByCompanyId.set(companyId, token);
11960
+ secretRef: savedSecretRef
11956
11961
  }
11957
- } catch (error) {
11958
- if (fallbackToken && isPluginSecretReferenceUnavailableError(error)) {
11959
- ctx.logger.warn("GitHub Sync is using a worker-local Paperclip board token fallback because plugin secret refs are unavailable in this host.", {
11960
- companyId,
11961
- secretRef,
11962
- error: getErrorMessage(error)
11963
- });
11964
- tokensByCompanyId.set(companyId, fallbackToken);
11965
- continue;
11966
- }
11967
- ctx.logger.warn("Unable to resolve the saved Paperclip board API token. Direct REST calls will continue without it.", {
11962
+ );
11963
+ return null;
11964
+ }
11965
+ try {
11966
+ const token = (await resolvePluginSecret(ctx, secretRef, {
11967
+ companyId,
11968
+ configPath: getPaperclipBoardApiTokenRefConfigPath(companyId)
11969
+ })).trim();
11970
+ return token ? token : null;
11971
+ } catch (error) {
11972
+ if (fallbackToken && isPluginSecretReferenceUnavailableError(error)) {
11973
+ ctx.logger.warn("GitHub Sync is using a worker-local Paperclip board token fallback because plugin secret refs are unavailable in this host.", {
11968
11974
  companyId,
11969
11975
  secretRef,
11970
11976
  error: getErrorMessage(error)
11971
11977
  });
11978
+ return fallbackToken;
11972
11979
  }
11980
+ ctx.logger.warn("Unable to resolve the saved Paperclip board API token. Direct REST calls will continue without it.", {
11981
+ companyId,
11982
+ secretRef,
11983
+ error: getErrorMessage(error)
11984
+ });
11985
+ return null;
11973
11986
  }
11974
- return tokensByCompanyId;
11975
11987
  }
11976
11988
  async function resolveGithubToken(ctx, options = {}) {
11977
11989
  const settings = options.settings ?? normalizeSettings(await ctx.state.get(SETTINGS_SCOPE));
@@ -14537,6 +14549,138 @@ async function buildProjectPullRequestCountData(ctx, input) {
14537
14549
  };
14538
14550
  }
14539
14551
  }
14552
+ var AGENT_TOOL_ACCESS_CACHE_TTL_MS = 12e4;
14553
+ var GITHUB_SYNC_AGENT_TOOL_NAME_PREFIX = `${GITHUB_SYNC_PLUGIN_ID}:`;
14554
+ var AGENT_TOOL_ACCESS_CHECKABLE_AGENT_STATUSES = /* @__PURE__ */ new Set(["active", "idle", "running", "error"]);
14555
+ var agentToolAccessSummaryCache = /* @__PURE__ */ new Map();
14556
+ function clearAgentToolAccessSummaryCache(companyId) {
14557
+ if (companyId) {
14558
+ agentToolAccessSummaryCache.delete(companyId);
14559
+ return;
14560
+ }
14561
+ agentToolAccessSummaryCache.clear();
14562
+ }
14563
+ function buildUnavailableAgentToolAccessSummary(status) {
14564
+ return {
14565
+ status,
14566
+ toolsVisibleToAgents: null,
14567
+ totalToolCount: GITHUB_AGENT_TOOLS.length
14568
+ };
14569
+ }
14570
+ function countGitHubSyncToolNames(value) {
14571
+ if (!Array.isArray(value)) {
14572
+ return 0;
14573
+ }
14574
+ return new Set(
14575
+ value.filter((entry) => typeof entry === "string" && entry.startsWith(GITHUB_SYNC_AGENT_TOOL_NAME_PREFIX))
14576
+ ).size;
14577
+ }
14578
+ function effectiveToolProfilesGrantUnnamedTools(payload) {
14579
+ const profiles = Array.isArray(payload.profiles) ? payload.profiles : [];
14580
+ if (profiles.some((profile) => isPlainRecord(profile) && profile.defaultAction === "allow")) {
14581
+ return true;
14582
+ }
14583
+ const entries = Array.isArray(payload.entries) ? payload.entries : [];
14584
+ return entries.some((entry) => isPlainRecord(entry) && entry.selectorType === "risk_level" && entry.effect === "include");
14585
+ }
14586
+ async function selectAgentForToolAccessCheck(ctx, companyId) {
14587
+ const agents = await ctx.agents.list({
14588
+ companyId,
14589
+ limit: 500
14590
+ });
14591
+ const checkableAgents = agents.filter((agent) => !agent.status || AGENT_TOOL_ACCESS_CHECKABLE_AGENT_STATUSES.has(agent.status));
14592
+ const preferredAgent = checkableAgents.find((agent) => agent.status === "active") ?? checkableAgents[0];
14593
+ return {
14594
+ agent: preferredAgent ? { id: preferredAgent.id, name: preferredAgent.name } : null,
14595
+ checkableAgentCount: checkableAgents.length
14596
+ };
14597
+ }
14598
+ async function buildAgentToolAccessSummary(ctx, companyId, settings, config) {
14599
+ const cached = agentToolAccessSummaryCache.get(companyId);
14600
+ if (cached && cached.expiresAt > Date.now()) {
14601
+ return cached.summary;
14602
+ }
14603
+ const summary = await loadAgentToolAccessSummary(ctx, companyId, settings, config);
14604
+ agentToolAccessSummaryCache.set(companyId, {
14605
+ expiresAt: Date.now() + AGENT_TOOL_ACCESS_CACHE_TTL_MS,
14606
+ summary
14607
+ });
14608
+ return summary;
14609
+ }
14610
+ async function loadAgentToolAccessSummary(ctx, companyId, settings, config) {
14611
+ const paperclipApiBaseUrl = getConfiguredPaperclipApiBaseUrl(settings, config, companyId);
14612
+ if (!paperclipApiBaseUrl) {
14613
+ return buildUnavailableAgentToolAccessSummary("not_checked");
14614
+ }
14615
+ const boardApiToken = await resolvePaperclipApiAuthTokenForCompany(ctx, settings, config, companyId);
14616
+ if (!boardApiToken) {
14617
+ return buildUnavailableAgentToolAccessSummary("not_checked");
14618
+ }
14619
+ let sample;
14620
+ try {
14621
+ sample = await selectAgentForToolAccessCheck(ctx, companyId);
14622
+ } catch (error) {
14623
+ ctx.logger.debug("GitHub Sync could not list company agents for the tool-access check.", {
14624
+ companyId,
14625
+ error: getErrorMessage(error)
14626
+ });
14627
+ return buildUnavailableAgentToolAccessSummary("unavailable");
14628
+ }
14629
+ if (!sample.agent) {
14630
+ return buildUnavailableAgentToolAccessSummary("no_agents");
14631
+ }
14632
+ const agentId = sample.agent.id;
14633
+ try {
14634
+ const response = await fetchPaperclipApi(
14635
+ getPaperclipEffectiveAgentToolProfilesEndpoint(paperclipApiBaseUrl, companyId, agentId),
14636
+ {
14637
+ method: "GET",
14638
+ headers: {
14639
+ accept: "application/json",
14640
+ authorization: `Bearer ${boardApiToken}`
14641
+ }
14642
+ },
14643
+ {
14644
+ companyId
14645
+ }
14646
+ );
14647
+ const payloadResult = await readPaperclipApiJsonResponse(response, {
14648
+ operationLabel: "agent tool access"
14649
+ });
14650
+ if (payloadResult.failure || !isPlainRecord(payloadResult.data)) {
14651
+ ctx.logger.debug("GitHub Sync could not read effective agent tool profiles.", {
14652
+ companyId,
14653
+ agentId,
14654
+ ...payloadResult.failure?.status !== void 0 ? { status: payloadResult.failure.status } : {}
14655
+ });
14656
+ return buildUnavailableAgentToolAccessSummary("unavailable");
14657
+ }
14658
+ const sampleFields = {
14659
+ checkedAgentId: agentId,
14660
+ checkedAgentName: sample.agent.name,
14661
+ checkableAgentCount: sample.checkableAgentCount
14662
+ };
14663
+ if (effectiveToolProfilesGrantUnnamedTools(payloadResult.data)) {
14664
+ return {
14665
+ ...buildUnavailableAgentToolAccessSummary("ready"),
14666
+ ...sampleFields
14667
+ };
14668
+ }
14669
+ return {
14670
+ status: "ready",
14671
+ toolsVisibleToAgents: countGitHubSyncToolNames(payloadResult.data.allowedToolNames),
14672
+ totalToolCount: GITHUB_AGENT_TOOLS.length,
14673
+ ...sampleFields
14674
+ };
14675
+ } catch (error) {
14676
+ ctx.logger.debug("GitHub Sync could not reach the effective agent tool profile route.", {
14677
+ companyId,
14678
+ agentId,
14679
+ error: getErrorMessage(error)
14680
+ });
14681
+ return buildUnavailableAgentToolAccessSummary("unavailable");
14682
+ }
14683
+ }
14540
14684
  async function buildSettingsTokenPermissionAuditData(ctx, input) {
14541
14685
  const requestedCompanyId = normalizeCompanyId(input.companyId);
14542
14686
  if (!requestedCompanyId) {
@@ -16457,10 +16601,19 @@ async function startSync(ctx, trigger, options = {}) {
16457
16601
  }
16458
16602
  await reconcileOrphanedRunningSyncState(ctx, options.target?.companyId);
16459
16603
  const targetCompanyId = normalizeCompanyId(options.target?.companyId);
16460
- const [config, persistedSettings] = await Promise.all([
16461
- getResolvedConfig(ctx, targetCompanyId),
16462
- ctx.state.get(SETTINGS_SCOPE).then((value) => normalizeSettings(value))
16463
- ]);
16604
+ let config;
16605
+ let persistedSettings;
16606
+ try {
16607
+ [config, persistedSettings] = await Promise.all([
16608
+ getResolvedConfig(ctx, targetCompanyId, { requireCompanyScope: true }),
16609
+ ctx.state.get(SETTINGS_SCOPE).then((value) => normalizeSettings(value))
16610
+ ]);
16611
+ } catch (error) {
16612
+ if (!isCompanyScopeDeniedError(error)) {
16613
+ throw error;
16614
+ }
16615
+ return createUnexpectedSyncErrorResult(ctx, trigger, error, targetCompanyId);
16616
+ }
16464
16617
  const token = await resolveGithubToken(ctx, {
16465
16618
  companyId: targetCompanyId,
16466
16619
  config,
@@ -17938,6 +18091,7 @@ var plugin = definePlugin({
17938
18091
  const companyId = normalizeCompanyId(context?.companyId) ?? null;
17939
18092
  rememberTrustedConfig(companyId, newConfig);
17940
18093
  clearGitHubRepositoryTokenCapabilityAudits();
18094
+ clearAgentToolAccessSummaryCache(companyId);
17941
18095
  pluginRuntimeContext?.logger.debug("GitHub Sync received company-scoped plugin config.", {
17942
18096
  companyId,
17943
18097
  configKeys: Object.keys(isPlainRecord(newConfig) ? newConfig : {})
@@ -17945,6 +18099,7 @@ var plugin = definePlugin({
17945
18099
  },
17946
18100
  async setup(ctx) {
17947
18101
  pluginRuntimeContext = ctx;
18102
+ clearAgentToolAccessSummaryCache();
17948
18103
  ctx.data.register("settings.registration", async (input) => {
17949
18104
  const record = input && typeof input === "object" ? input : {};
17950
18105
  const requestedCompanyId = normalizeCompanyId(record.companyId);
@@ -17982,11 +18137,15 @@ var plugin = definePlugin({
17982
18137
  await saveSettingsSyncState(ctx, normalizedSettings, settingsForResponse.syncState, requestedCompanyId);
17983
18138
  }
17984
18139
  const scopedMappings = filterMappingsByCompany(settingsForResponse.mappings, requestedCompanyId);
17985
- const availableAssignees = includeAssignees && requestedCompanyId ? await listAvailableAssignees(ctx, requestedCompanyId, settingsForResponse) : [];
18140
+ const [availableAssignees, agentToolAccess] = await Promise.all([
18141
+ includeAssignees && requestedCompanyId ? listAvailableAssignees(ctx, requestedCompanyId, settingsForResponse) : Promise.resolve([]),
18142
+ requestedCompanyId ? buildAgentToolAccessSummary(ctx, requestedCompanyId, normalizedSettings, config) : Promise.resolve(buildUnavailableAgentToolAccessSummary("not_checked"))
18143
+ ]);
17986
18144
  return {
17987
18145
  ...getPublicSettingsForScope(settingsForResponse, requestedCompanyId),
17988
18146
  ...includeAssignees ? { availableAssignees } : {},
17989
18147
  totalSyncedIssuesCount: countImportedIssuesForMappings(importRegistry, scopedMappings),
18148
+ agentToolAccess,
17990
18149
  paperclipApiBaseUrlConfigured: Boolean(normalizePaperclipApiBaseUrl(config.paperclipApiBaseUrl)),
17991
18150
  githubTokenConfigured,
17992
18151
  paperclipBoardAccessConfigured: requestedCompanyId ? hasConfiguredPaperclipBoardAccess(settingsForResponse, config, requestedCompanyId) : hasConfiguredPaperclipBoardAccessForMappings(settingsForResponse, config, scopedMappings),
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
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.11.0",
7
+ "packageManager": "pnpm@12.4.1",
8
8
  "engines": {
9
- "node": ">=24.11.0"
9
+ "node": ">=24.21.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -42,18 +42,18 @@
42
42
  "dependencies": {
43
43
  "@octokit/rest": "^22.0.1",
44
44
  "@paperclipai/plugin-sdk": "^2026.831.1",
45
- "react": "^19.2.7",
45
+ "react": "^19.3.0",
46
46
  "react-markdown": "^10.1.0",
47
47
  "rehype-raw": "^7.0.0",
48
48
  "rehype-sanitize": "^6.0.0",
49
49
  "remark-gfm": "^4.0.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/node": "24.13.3",
53
- "@types/react": "19.2.17",
54
- "esbuild": "0.28.1",
55
- "playwright": "1.61.1",
56
- "tsx": "4.23.1",
57
- "typescript": "6.0.3"
52
+ "@types/node": "24.13.4",
53
+ "@types/react": "19.3.0",
54
+ "esbuild": "0.28.2",
55
+ "playwright": "1.63.0",
56
+ "tsx": "4.23.13",
57
+ "typescript": "7.0.2"
58
58
  }
59
59
  }