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/ui/index.js CHANGED
@@ -276,7 +276,7 @@ var require_extend = __commonJS({
276
276
  "use strict";
277
277
  var hasOwn = Object.prototype.hasOwnProperty;
278
278
  var toStr = Object.prototype.toString;
279
- var defineProperty = Object.defineProperty;
279
+ var defineProperty2 = Object.defineProperty;
280
280
  var gOPD = Object.getOwnPropertyDescriptor;
281
281
  var isArray = function isArray2(arr) {
282
282
  if (typeof Array.isArray === "function") {
@@ -299,8 +299,8 @@ var require_extend = __commonJS({
299
299
  return typeof key === "undefined" || hasOwn.call(obj, key);
300
300
  };
301
301
  var setProperty = function setProperty2(target, options) {
302
- if (defineProperty && options.name === "__proto__") {
303
- defineProperty(target, options.name, {
302
+ if (defineProperty2 && options.name === "__proto__") {
303
+ defineProperty2(target, options.name, {
304
304
  enumerable: true,
305
305
  configurable: true,
306
306
  value: options.newValue,
@@ -370,7 +370,7 @@ import {
370
370
  usePluginToast
371
371
  } from "@paperclipai/plugin-sdk/ui";
372
372
 
373
- // node_modules/.pnpm/@ungap+structured-clone@1.3.3/node_modules/@ungap/structured-clone/esm/types.js
373
+ // node_modules/.pnpm/@ungap+structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/types.js
374
374
  var VOID = -1;
375
375
  var PRIMITIVE = 0;
376
376
  var ARRAY = 1;
@@ -382,7 +382,8 @@ var SET = 6;
382
382
  var ERROR = 7;
383
383
  var BIGINT = 8;
384
384
 
385
- // node_modules/.pnpm/@ungap+structured-clone@1.3.3/node_modules/@ungap/structured-clone/esm/deserialize.js
385
+ // node_modules/.pnpm/@ungap+structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/deserialize.js
386
+ var { defineProperty } = Object;
386
387
  var env = typeof self === "object" ? self : globalThis;
387
388
  var guard = (name2, init) => {
388
389
  switch (name2) {
@@ -417,8 +418,16 @@ var deserializer = ($2, _) => {
417
418
  }
418
419
  case OBJECT: {
419
420
  const object = as({}, index2);
420
- for (const [key, index3] of value)
421
- object[unpair(key)] = unpair(index3);
421
+ for (const [key, index3] of value) {
422
+ const k = unpair(key), value2 = unpair(index3);
423
+ if (k === "__proto__") defineProperty(object, k, {
424
+ value: value2,
425
+ configurable: true,
426
+ enumerable: true,
427
+ writable: true
428
+ });
429
+ else object[k] = value2;
430
+ }
422
431
  return object;
423
432
  }
424
433
  case DATE:
@@ -456,6 +465,8 @@ var deserializer = ($2, _) => {
456
465
  const { buffer } = new Uint8Array(value);
457
466
  return as(new DataView(buffer), value);
458
467
  }
468
+ case "-0":
469
+ return -0;
459
470
  }
460
471
  return as(guard(type, value), index2);
461
472
  };
@@ -463,10 +474,10 @@ var deserializer = ($2, _) => {
463
474
  };
464
475
  var deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
465
476
 
466
- // node_modules/.pnpm/@ungap+structured-clone@1.3.3/node_modules/@ungap/structured-clone/esm/serialize.js
477
+ // node_modules/.pnpm/@ungap+structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/serialize.js
467
478
  var EMPTY = "";
468
479
  var { toString } = {};
469
- var { keys } = Object;
480
+ var { keys, is } = Object;
470
481
  var typeOf = (value) => {
471
482
  const type = typeof value;
472
483
  if (type !== "object" || !value)
@@ -513,6 +524,10 @@ var serializer = (strict, json, $2, _) => {
513
524
  TYPE = BIGINT;
514
525
  entry = value.toString();
515
526
  break;
527
+ case "number":
528
+ if (!value && is(value, -0))
529
+ return _.push(["-0"]) - 1;
530
+ break;
516
531
  case "function":
517
532
  case "symbol":
518
533
  if (strict)
@@ -596,7 +611,7 @@ var serialize = (value, { json, lossy } = {}) => {
596
611
  return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
597
612
  };
598
613
 
599
- // node_modules/.pnpm/@ungap+structured-clone@1.3.3/node_modules/@ungap/structured-clone/esm/index.js
614
+ // node_modules/.pnpm/@ungap+structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/index.js
600
615
  var esm_default = typeof structuredClone === "function" ? (
601
616
  /* c8 ignore start */
602
617
  (any, options) => options && ("json" in options || "lossy" in options) ? deserialize(serialize(any, options)) : structuredClone(any)
@@ -10576,7 +10591,7 @@ function visitParents(tree, test, visitor, reverse) {
10576
10591
  } else {
10577
10592
  check = test;
10578
10593
  }
10579
- const is2 = convert(check);
10594
+ const is3 = convert(check);
10580
10595
  const step = reverse ? -1 : 1;
10581
10596
  factory(tree, void 0, [])();
10582
10597
  function factory(node2, index2, parents) {
@@ -10602,7 +10617,7 @@ function visitParents(tree, test, visitor, reverse) {
10602
10617
  let subresult;
10603
10618
  let offset;
10604
10619
  let grandparents;
10605
- if (!test || is2(node2, index2, parents[parents.length - 1] || void 0)) {
10620
+ if (!test || is3(node2, index2, parents[parents.length - 1] || void 0)) {
10606
10621
  result = toResult(visitor(node2, parents));
10607
10622
  if (result[0] === EXIT) {
10608
10623
  return result;
@@ -12015,7 +12030,7 @@ var urlAttributes = {
12015
12030
  ]
12016
12031
  };
12017
12032
 
12018
- // node_modules/.pnpm/react-markdown@10.1.0_@types+react@19.2.17_react@19.2.7/node_modules/react-markdown/lib/index.js
12033
+ // node_modules/.pnpm/react-markdown@10.1.0_@types+react@19.3.0_react@19.3.0/node_modules/react-markdown/lib/index.js
12019
12034
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12020
12035
  import { useEffect, useState } from "react";
12021
12036
 
@@ -19171,7 +19186,7 @@ function isUint8Array2(value) {
19171
19186
  );
19172
19187
  }
19173
19188
 
19174
- // node_modules/.pnpm/react-markdown@10.1.0_@types+react@19.2.17_react@19.2.7/node_modules/react-markdown/lib/index.js
19189
+ // node_modules/.pnpm/react-markdown@10.1.0_@types+react@19.3.0_react@19.3.0/node_modules/react-markdown/lib/index.js
19175
19190
  var changelog = "https://github.com/remarkjs/react-markdown/blob/main/changelog.md";
19176
19191
  var emptyPlugins = [];
19177
19192
  var emptyRemarkRehypeOptions = { allowDangerousHtml: true };
@@ -21773,21 +21788,26 @@ function gfmStrikethrough(options) {
21773
21788
  }
21774
21789
  }
21775
21790
 
21776
- // node_modules/.pnpm/micromark-extension-gfm-table@2.1.1/node_modules/micromark-extension-gfm-table/lib/edit-map.js
21791
+ // node_modules/.pnpm/micromark-extension-gfm-table@2.1.2/node_modules/micromark-extension-gfm-table/lib/edit-map.js
21777
21792
  var EditMap = class {
21778
21793
  /**
21779
21794
  * Create a new edit map.
21780
21795
  */
21781
21796
  constructor() {
21782
21797
  this.map = [];
21798
+ this.index = /* @__PURE__ */ new Map();
21783
21799
  }
21784
21800
  /**
21785
21801
  * Create an edit: a remove and/or add at a certain place.
21786
21802
  *
21787
21803
  * @param {number} index
21804
+ * Index at which to apply the edit.
21788
21805
  * @param {number} remove
21806
+ * Count of items to remove at the index.
21789
21807
  * @param {Array<Event>} add
21808
+ * Items to add at the index.
21790
21809
  * @returns {undefined}
21810
+ * Nothing.
21791
21811
  */
21792
21812
  add(index2, remove, add) {
21793
21813
  addImplementation(this, index2, remove, add);
@@ -21808,7 +21828,9 @@ var EditMap = class {
21808
21828
  * Done, change the events.
21809
21829
  *
21810
21830
  * @param {Array<Event>} events
21831
+ * List of events to apply the edits to.
21811
21832
  * @returns {undefined}
21833
+ * Nothing.
21812
21834
  */
21813
21835
  consume(events) {
21814
21836
  this.map.sort(function(a, b) {
@@ -21834,25 +21856,25 @@ var EditMap = class {
21834
21856
  slice = vecs.pop();
21835
21857
  }
21836
21858
  this.map.length = 0;
21859
+ this.index.clear();
21837
21860
  }
21838
21861
  };
21839
21862
  function addImplementation(editMap, at, remove, add) {
21840
- let index2 = 0;
21841
21863
  if (remove === 0 && add.length === 0) {
21842
21864
  return;
21843
21865
  }
21844
- while (index2 < editMap.map.length) {
21845
- if (editMap.map[index2][0] === at) {
21846
- editMap.map[index2][1] += remove;
21847
- editMap.map[index2][2].push(...add);
21848
- return;
21849
- }
21850
- index2 += 1;
21866
+ const existing = editMap.index.get(at);
21867
+ if (existing) {
21868
+ existing[1] += remove;
21869
+ existing[2].push(...add);
21870
+ return;
21851
21871
  }
21852
- editMap.map.push([at, remove, add]);
21872
+ const change = [at, remove, add];
21873
+ editMap.map.push(change);
21874
+ editMap.index.set(at, change);
21853
21875
  }
21854
21876
 
21855
- // node_modules/.pnpm/micromark-extension-gfm-table@2.1.1/node_modules/micromark-extension-gfm-table/lib/infer.js
21877
+ // node_modules/.pnpm/micromark-extension-gfm-table@2.1.2/node_modules/micromark-extension-gfm-table/lib/infer.js
21856
21878
  function gfmTableAlign(events, index2) {
21857
21879
  let inDelimiterRow = false;
21858
21880
  const align = [];
@@ -21879,7 +21901,7 @@ function gfmTableAlign(events, index2) {
21879
21901
  return align;
21880
21902
  }
21881
21903
 
21882
- // node_modules/.pnpm/micromark-extension-gfm-table@2.1.1/node_modules/micromark-extension-gfm-table/lib/syntax.js
21904
+ // node_modules/.pnpm/micromark-extension-gfm-table@2.1.2/node_modules/micromark-extension-gfm-table/lib/syntax.js
21883
21905
  function gfmTable() {
21884
21906
  return {
21885
21907
  flow: {
@@ -21900,10 +21922,15 @@ function tokenizeTable(effects, ok3, nok) {
21900
21922
  function start2(code4) {
21901
21923
  let index2 = self2.events.length - 1;
21902
21924
  while (index2 > -1) {
21903
- const type = self2.events[index2][1].type;
21925
+ const {
21926
+ type
21927
+ } = self2.events[index2][1];
21904
21928
  if (type === "lineEnding" || // Note: markdown-rs uses `whitespace` instead of `linePrefix`
21905
- type === "linePrefix") index2--;
21906
- else break;
21929
+ type === "linePrefix") {
21930
+ index2--;
21931
+ } else {
21932
+ break;
21933
+ }
21907
21934
  }
21908
21935
  const tail = index2 > -1 ? self2.events[index2][1].type : null;
21909
21936
  const next2 = tail === "tableHead" || tail === "tableRow" ? bodyRowStart : headRowBefore;
@@ -22367,6 +22394,11 @@ function remarkGfm(options) {
22367
22394
  toMarkdownExtensions.push(gfmToMarkdown(settings));
22368
22395
  }
22369
22396
 
22397
+ // src/kpi-contract.ts
22398
+ var GITHUB_SYNC_PLUGIN_ID = "paperclip-github-plugin";
22399
+ var COMPANY_METRIC_API_ROUTE_PATH = "/company-metrics/events";
22400
+ var COMPANY_METRIC_API_ROUTE_URL_PATH = `/api/plugins/${GITHUB_SYNC_PLUGIN_ID}/api${COMPANY_METRIC_API_ROUTE_PATH}`;
22401
+
22370
22402
  // src/github-repo.ts
22371
22403
  function parseRepositoryReference(repositoryInput) {
22372
22404
  const trimmed = repositoryInput.trim();
@@ -22625,6 +22657,105 @@ async function fetchPaperclipHealth(origin) {
22625
22657
  }
22626
22658
  }
22627
22659
 
22660
+ // src/ui/host-secrets.ts
22661
+ var HOST_GITHUB_TOKEN_SECRET_NAMES = ["GITHUB_TOKEN", "GH_TOKEN", "PAPERCLIP_GITHUB_TOKEN"];
22662
+ var HOST_GITHUB_TOKEN_SECRET_NAME = HOST_GITHUB_TOKEN_SECRET_NAMES[0];
22663
+ function buildCompanySecretListRequest(companyId) {
22664
+ return {
22665
+ url: `/api/companies/${encodeURIComponent(companyId)}/secrets`
22666
+ };
22667
+ }
22668
+ function buildCompanySecretCreateRequest(companyId, name2, value) {
22669
+ return {
22670
+ url: `/api/companies/${encodeURIComponent(companyId)}/secrets`,
22671
+ init: {
22672
+ method: "POST",
22673
+ body: JSON.stringify({
22674
+ name: name2,
22675
+ value
22676
+ })
22677
+ }
22678
+ };
22679
+ }
22680
+ function buildCompanySecretRotateRequest(secretId, value) {
22681
+ return {
22682
+ url: `/api/secrets/${encodeURIComponent(secretId)}/rotate`,
22683
+ init: {
22684
+ method: "POST",
22685
+ body: JSON.stringify({
22686
+ value
22687
+ })
22688
+ }
22689
+ };
22690
+ }
22691
+ function findCompanySecretByName(secrets, name2, options = {}) {
22692
+ const caseSensitive = options.caseSensitive === true;
22693
+ const expectedName = caseSensitive ? name2 : name2.trim().toLowerCase();
22694
+ return secrets.find((secret) => {
22695
+ if (typeof secret?.name !== "string") {
22696
+ return false;
22697
+ }
22698
+ const candidate = caseSensitive ? secret.name : secret.name.trim().toLowerCase();
22699
+ return candidate === expectedName;
22700
+ }) ?? null;
22701
+ }
22702
+ async function resolveOrCreateCompanySecret(fetchJson2, companyId, name2, value, options = {}) {
22703
+ const listRequest = buildCompanySecretListRequest(companyId);
22704
+ const existingSecrets = await fetchJson2(listRequest.url, listRequest.init);
22705
+ const existing = findCompanySecretByName(Array.isArray(existingSecrets) ? existingSecrets : [], name2, options);
22706
+ if (existing) {
22707
+ const rotateRequest = buildCompanySecretRotateRequest(existing.id, value);
22708
+ return fetchJson2(rotateRequest.url, rotateRequest.init);
22709
+ }
22710
+ const createRequest = buildCompanySecretCreateRequest(companyId, name2, value);
22711
+ return fetchJson2(createRequest.url, createRequest.init);
22712
+ }
22713
+ async function exposeGitHubTokenToPaperclipHost(fetchJson2, companyId, token) {
22714
+ const trimmedCompanyId = companyId.trim();
22715
+ if (!trimmedCompanyId) {
22716
+ throw new Error("Company context is required to expose the GitHub token to Paperclip.");
22717
+ }
22718
+ const trimmedToken = token.trim();
22719
+ if (!trimmedToken) {
22720
+ throw new Error("A GitHub token is required to expose it to Paperclip.");
22721
+ }
22722
+ const listRequest = buildCompanySecretListRequest(trimmedCompanyId);
22723
+ const existingSecrets = await fetchJson2(listRequest.url, listRequest.init);
22724
+ const existing = findCompanySecretByName(
22725
+ Array.isArray(existingSecrets) ? existingSecrets : [],
22726
+ HOST_GITHUB_TOKEN_SECRET_NAME,
22727
+ {
22728
+ caseSensitive: true
22729
+ }
22730
+ );
22731
+ if (existing) {
22732
+ if (typeof existing.status === "string" && existing.status !== "active") {
22733
+ throw new Error(
22734
+ `The ${HOST_GITHUB_TOKEN_SECRET_NAME} company secret is ${existing.status}, not active. Re-activate it in Settings -> Secrets and save the token again, because Paperclip ignores a secret in this state.`
22735
+ );
22736
+ }
22737
+ const rotateRequest = buildCompanySecretRotateRequest(existing.id, trimmedToken);
22738
+ return fetchJson2(rotateRequest.url, rotateRequest.init);
22739
+ }
22740
+ const createRequest = buildCompanySecretCreateRequest(
22741
+ trimmedCompanyId,
22742
+ HOST_GITHUB_TOKEN_SECRET_NAME,
22743
+ trimmedToken
22744
+ );
22745
+ try {
22746
+ return await fetchJson2(createRequest.url, createRequest.init);
22747
+ } catch (error) {
22748
+ const message = error instanceof Error ? error.message : String(error);
22749
+ if (/already exists/i.test(message)) {
22750
+ throw new Error(
22751
+ `Paperclip already has a company secret that conflicts with ${HOST_GITHUB_TOKEN_SECRET_NAME} (${message}). Paperclip matches this name exactly, so rename or delete the conflicting secret, or set ${HOST_GITHUB_TOKEN_SECRET_NAME} manually in Settings -> Secrets.`,
22752
+ { cause: error }
22753
+ );
22754
+ }
22755
+ throw error;
22756
+ }
22757
+ }
22758
+
22628
22759
  // src/ui/plugin-installation.ts
22629
22760
  var SETTINGS_INDEX_HREF = "/instance/settings/plugins";
22630
22761
  var GITHUB_SYNC_PLUGIN_KEY = "paperclip-github-plugin";
@@ -22714,6 +22845,14 @@ function normalizeCompanySecretRefMap(value) {
22714
22845
  }
22715
22846
  return Object.fromEntries(entries);
22716
22847
  }
22848
+ function hasLegacyPluginSecretRefs(value) {
22849
+ if (!isPlainRecord(value)) {
22850
+ return false;
22851
+ }
22852
+ return [value.githubTokenRefs, value.paperclipBoardApiTokenRefs].some(
22853
+ (refs) => isPlainRecord(refs) && Object.values(refs).some((secretRef) => !isPluginSecretRefBinding(secretRef) && Boolean(normalizeOptionalString2(secretRef)))
22854
+ );
22855
+ }
22717
22856
  function normalizePluginConfigBoardTokenRefs(value) {
22718
22857
  return normalizeCompanySecretRefMap(value);
22719
22858
  }
@@ -22847,6 +22986,7 @@ function filterExistingProjectSyncCandidates(candidates, mappings) {
22847
22986
 
22848
22987
  // src/ui/index.tsx
22849
22988
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
22989
+ var GITHUB_SYNC_TOOL_ACCESS_DOCS_URL = "https://github.com/alvarosanchez/paperclip-github-plugin#granting-the-tools-to-agents";
22850
22990
  var HOST_BUTTON_BASE_CLASSNAME = [
22851
22991
  "inline-flex items-center justify-center whitespace-nowrap text-sm font-medium",
22852
22992
  "transition-[color,background-color,border-color,box-shadow,opacity]",
@@ -24044,6 +24184,33 @@ var PAGE_STYLES = `
24044
24184
  color: var(--ghsync-muted);
24045
24185
  }
24046
24186
 
24187
+ .ghsync__checkbox-field {
24188
+ display: flex;
24189
+ gap: 10px;
24190
+ align-items: flex-start;
24191
+ }
24192
+
24193
+ .ghsync__checkbox-field input[type="checkbox"] {
24194
+ margin-top: 2px;
24195
+ accent-color: var(--ghsync-accent, currentColor);
24196
+ }
24197
+
24198
+ .ghsync__checkbox-field-copy {
24199
+ display: grid;
24200
+ gap: 4px;
24201
+ }
24202
+
24203
+ .ghsync__checkbox-field-copy label {
24204
+ font-size: 12px;
24205
+ font-weight: 600;
24206
+ color: var(--ghsync-title);
24207
+ }
24208
+
24209
+ .ghsync__checkbox-field-copy span {
24210
+ font-size: 12px;
24211
+ color: var(--ghsync-muted);
24212
+ }
24213
+
24047
24214
  .ghsync__input:focus {
24048
24215
  border-color: var(--ghsync-border);
24049
24216
  }
@@ -24400,6 +24567,12 @@ var PAGE_STYLES = `
24400
24567
  line-height: 1.5;
24401
24568
  }
24402
24569
 
24570
+ .ghsync__permission-audit-item a {
24571
+ color: var(--ghsync-title);
24572
+ font-size: 12px;
24573
+ text-decoration: underline;
24574
+ }
24575
+
24403
24576
  .ghsync__sync-summary--success {
24404
24577
  border-color: var(--ghsync-success-border);
24405
24578
  background: var(--ghsync-success-bg);
@@ -26659,15 +26832,6 @@ var EXTENSION_SURFACE_STYLES = `
26659
26832
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
26660
26833
  }
26661
26834
 
26662
- .ghsync-extension-card--compact {
26663
- gap: 10px;
26664
- padding: 0;
26665
- border: 0;
26666
- border-radius: 0;
26667
- background: transparent;
26668
- box-shadow: none;
26669
- }
26670
-
26671
26835
  .ghsync-extension-heading {
26672
26836
  display: flex;
26673
26837
  justify-content: space-between;
@@ -26751,7 +26915,6 @@ var EXTENSION_SURFACE_STYLES = `
26751
26915
 
26752
26916
  .ghsync-extension-links,
26753
26917
  .ghsync-extension-labels,
26754
- .ghsync-comment-annotation,
26755
26918
  .ghsync-toolbar-button {
26756
26919
  display: flex;
26757
26920
  flex-wrap: wrap;
@@ -26792,14 +26955,6 @@ var EXTENSION_SURFACE_STYLES = `
26792
26955
  font-weight: 500;
26793
26956
  }
26794
26957
 
26795
- .ghsync-comment-annotation__label {
26796
- color: var(--ghsync-muted);
26797
- font-size: 11px;
26798
- font-weight: 700;
26799
- letter-spacing: 0.08em;
26800
- text-transform: uppercase;
26801
- }
26802
-
26803
26958
  .ghsync-extension-note {
26804
26959
  padding: 12px;
26805
26960
  border-radius: 14px;
@@ -27540,9 +27695,12 @@ async function fetchPluginDataResult(params) {
27540
27695
  function buildPluginConfigUrl(pluginId, companyId) {
27541
27696
  return `/api/plugins/${pluginId}/config?companyId=${encodeURIComponent(companyId)}`;
27542
27697
  }
27543
- async function readPluginConfig(pluginId, companyId) {
27698
+ async function readRawPluginConfig(pluginId, companyId) {
27544
27699
  const currentConfigResponse = await fetchJson(buildPluginConfigUrl(pluginId, companyId));
27545
- return normalizePluginConfig(currentConfigResponse?.configJson);
27700
+ return currentConfigResponse?.configJson;
27701
+ }
27702
+ async function readPluginConfig(pluginId, companyId) {
27703
+ return normalizePluginConfig(await readRawPluginConfig(pluginId, companyId));
27546
27704
  }
27547
27705
  async function syncTrustedPaperclipApiBaseUrl(pluginId, companyId) {
27548
27706
  const resolvedPluginId = await resolveCurrentPluginId(pluginId);
@@ -28288,24 +28446,8 @@ async function ensureProjectRepoBinding(projectId, repositoryUrl) {
28288
28446
  })
28289
28447
  });
28290
28448
  }
28291
- async function resolveOrCreateCompanySecret(companyId, name2, value) {
28292
- const existingSecrets = await fetchJson(`/api/companies/${companyId}/secrets`);
28293
- const existing = existingSecrets.find((secret) => secret.name.trim().toLowerCase() === name2.trim().toLowerCase());
28294
- if (existing) {
28295
- return fetchJson(`/api/secrets/${existing.id}/rotate`, {
28296
- method: "POST",
28297
- body: JSON.stringify({
28298
- value
28299
- })
28300
- });
28301
- }
28302
- return fetchJson(`/api/companies/${companyId}/secrets`, {
28303
- method: "POST",
28304
- body: JSON.stringify({
28305
- name: name2,
28306
- value
28307
- })
28308
- });
28449
+ function resolveOrCreateCompanySecret2(companyId, name2, value) {
28450
+ return resolveOrCreateCompanySecret(fetchJson, companyId, name2, value);
28309
28451
  }
28310
28452
  function isPluginSecretReferencesDisabledError(error) {
28311
28453
  return getActionErrorMessage(error, "").toLowerCase().includes("plugin secret references are disabled");
@@ -28357,9 +28499,12 @@ async function patchPluginConfig(pluginId, companyId, patch5) {
28357
28499
  if (!companyId) {
28358
28500
  throw new Error("Company context is required to save GitHub Sync plugin config.");
28359
28501
  }
28360
- const currentConfig = await readPluginConfig(pluginId, companyId);
28502
+ const rawCurrentConfig = await readRawPluginConfig(pluginId, companyId);
28503
+ const currentConfig = normalizePluginConfig(rawCurrentConfig);
28361
28504
  const nextConfig = mergePluginConfig(currentConfig, patch5);
28362
- if (JSON.stringify(nextConfig) === JSON.stringify(currentConfig)) {
28505
+ const isLegacySecretRefMigration = hasLegacyPluginSecretRefs(rawCurrentConfig);
28506
+ const isNormalizedConfigUnchanged = JSON.stringify(nextConfig) === JSON.stringify(currentConfig);
28507
+ if (!isLegacySecretRefMigration && isNormalizedConfigUnchanged) {
28363
28508
  return;
28364
28509
  }
28365
28510
  try {
@@ -28368,6 +28513,9 @@ async function patchPluginConfig(pluginId, companyId, patch5) {
28368
28513
  if (!isPluginSecretReferencesDisabledError(error)) {
28369
28514
  throw error;
28370
28515
  }
28516
+ if (isLegacySecretRefMigration && isNormalizedConfigUnchanged) {
28517
+ return;
28518
+ }
28371
28519
  const safeConfig = stripPluginSecretRefConfig(nextConfig);
28372
28520
  if (JSON.stringify(safeConfig) === JSON.stringify(nextConfig)) {
28373
28521
  throw error;
@@ -31846,6 +31994,7 @@ function GitHubSyncSettingsPage() {
31846
31994
  const [tokenDraft, setTokenDraft] = useState2("");
31847
31995
  const [showSavedTokenHint, setShowSavedTokenHint] = useState2(false);
31848
31996
  const [showTokenEditor, setShowTokenEditor] = useState2(false);
31997
+ const [exposeTokenAsHostSecret, setExposeTokenAsHostSecret] = useState2(false);
31849
31998
  const [showAdvancedSettings, setShowAdvancedSettings] = useState2(false);
31850
31999
  const [cachedSettings, setCachedSettings] = useState2(null);
31851
32000
  const [existingProjectCandidates, setExistingProjectCandidates] = useState2([]);
@@ -31865,6 +32014,9 @@ function GitHubSyncSettingsPage() {
31865
32014
  setCachedSettings(settings.data);
31866
32015
  }
31867
32016
  }, [settings.data]);
32017
+ useEffect2(() => {
32018
+ setExposeTokenAsHostSecret(false);
32019
+ }, [hostContext.companyId]);
31868
32020
  useEffect2(() => {
31869
32021
  if (!settings.data) {
31870
32022
  return;
@@ -32175,6 +32327,10 @@ function GitHubSyncSettingsPage() {
32175
32327
  const tokenPermissionAuditErrorVisible = hasCompanyContext && tokenStatus === "valid" && tokenPermissionAuditData?.status === "error";
32176
32328
  const tokenPermissionWarningVisible = hasCompanyContext && tokenStatus === "valid" && tokenPermissionWarnings.length > 0;
32177
32329
  const tokenPermissionUnknownVisible = hasCompanyContext && tokenStatus === "valid" && !tokenPermissionAuditErrorVisible && !tokenPermissionWarningVisible && tokenPermissionAuditData?.status === "ready" && tokenPermissionRepositories.length === 0;
32330
+ const agentToolAccess = settings.data?.agentToolAccess;
32331
+ const agentToolAccessWarningVisible = hasCompanyContext && agentToolAccess?.status === "ready" && agentToolAccess.toolsVisibleToAgents === 0;
32332
+ const agentToolAccessSampleLabel = agentToolAccess?.checkedAgentName ? `Agent ${agentToolAccess.checkedAgentName}` : "The checked agent";
32333
+ const agentToolAccessOtherAgentsHint = typeof agentToolAccess?.checkableAgentCount === "number" && agentToolAccess.checkableAgentCount > 1 ? ` of ${agentToolAccess.checkableAgentCount}` : "";
32178
32334
  const boardAccessTone = connectingBoardAccess ? "info" : boardAccessConfigured ? "success" : boardAccessRequired ? "warning" : "info";
32179
32335
  const boardAccessBannerLabel = connectingBoardAccess ? "Connecting" : boardAccessConfigured ? "Connected" : boardAccessRequired ? "Required" : boardAccessRequirement.status === "loading" ? "Checking" : "Optional";
32180
32336
  const boardAccessSectionDescription = "";
@@ -32448,7 +32604,7 @@ function GitHubSyncSettingsPage() {
32448
32604
  }
32449
32605
  const trimmedToken = tokenDraft.trim();
32450
32606
  const secretName = `github_sync_${companyId.replace(/[^a-z0-9]+/gi, "_").toLowerCase()}`;
32451
- const secret = await resolveOrCreateCompanySecret(companyId, secretName, trimmedToken);
32607
+ const secret = await resolveOrCreateCompanySecret2(companyId, secretName, trimmedToken);
32452
32608
  await patchPluginConfig(pluginId, companyId, {
32453
32609
  githubTokenRefs: {
32454
32610
  [companyId]: secret.id
@@ -32471,6 +32627,16 @@ function GitHubSyncSettingsPage() {
32471
32627
  } catch (error) {
32472
32628
  availabilityWarning = error;
32473
32629
  }
32630
+ let hostSecretExposureWarning = null;
32631
+ let hostSecretExposed = false;
32632
+ if (exposeTokenAsHostSecret) {
32633
+ try {
32634
+ await exposeGitHubTokenToPaperclipHost(fetchJson, companyId, trimmedToken);
32635
+ hostSecretExposed = true;
32636
+ } catch (error) {
32637
+ hostSecretExposureWarning = error;
32638
+ }
32639
+ }
32474
32640
  setForm((current) => ({
32475
32641
  ...current,
32476
32642
  githubTokenConfigured: true
@@ -32480,6 +32646,7 @@ function GitHubSyncSettingsPage() {
32480
32646
  setTokenStatusOverride("valid");
32481
32647
  setValidatedLogin(validation.login);
32482
32648
  setTokenDraft("");
32649
+ setExposeTokenAsHostSecret(false);
32483
32650
  toast({
32484
32651
  title: `Authenticated as ${validation.login}`,
32485
32652
  body: "Token saved.",
@@ -32495,6 +32662,23 @@ function GitHubSyncSettingsPage() {
32495
32662
  tone: "error"
32496
32663
  });
32497
32664
  }
32665
+ if (hostSecretExposed) {
32666
+ toast({
32667
+ title: `Paperclip secret ${HOST_GITHUB_TOKEN_SECRET_NAME} updated`,
32668
+ body: "Paperclip host GitHub features can now authenticate with this token.",
32669
+ tone: "success"
32670
+ });
32671
+ }
32672
+ if (hostSecretExposureWarning) {
32673
+ toast({
32674
+ title: `GitHub token saved, but ${HOST_GITHUB_TOKEN_SECRET_NAME} could not be updated`,
32675
+ body: getActionErrorMessage(
32676
+ hostSecretExposureWarning,
32677
+ `Paperclip could not create or rotate the ${HOST_GITHUB_TOKEN_SECRET_NAME} company secret.`
32678
+ ),
32679
+ tone: "error"
32680
+ });
32681
+ }
32498
32682
  notifyGitHubSyncSettingsChanged();
32499
32683
  try {
32500
32684
  await settings.refresh();
@@ -32542,7 +32726,7 @@ function GitHubSyncSettingsPage() {
32542
32726
  const boardApiToken = await waitForBoardAccessApproval(challenge);
32543
32727
  const boardIdentity = await fetchBoardAccessIdentity(boardApiToken);
32544
32728
  const secretName = `paperclip_board_api_${companyId.replace(/[^a-z0-9]+/gi, "_").toLowerCase()}`;
32545
- const secret = await resolveOrCreateCompanySecret(companyId, secretName, boardApiToken);
32729
+ const secret = await resolveOrCreateCompanySecret2(companyId, secretName, boardApiToken);
32546
32730
  await patchPluginConfig(pluginId, companyId, {
32547
32731
  paperclipBoardApiTokenRefs: {
32548
32732
  [companyId]: secret.id
@@ -32837,6 +33021,28 @@ function GitHubSyncSettingsPage() {
32837
33021
  }
32838
33022
  )
32839
33023
  ] }),
33024
+ /* @__PURE__ */ jsxs2("div", { className: "ghsync__checkbox-field", children: [
33025
+ /* @__PURE__ */ jsx2(
33026
+ "input",
33027
+ {
33028
+ id: "github-token-expose-host-secret",
33029
+ type: "checkbox",
33030
+ checked: exposeTokenAsHostSecret,
33031
+ disabled: settingsMutationsLocked,
33032
+ onChange: (event) => {
33033
+ setExposeTokenAsHostSecret(event.currentTarget.checked);
33034
+ }
33035
+ }
33036
+ ),
33037
+ /* @__PURE__ */ jsxs2("div", { className: "ghsync__checkbox-field-copy", children: [
33038
+ /* @__PURE__ */ jsx2("label", { htmlFor: "github-token-expose-host-secret", children: `Also expose this token to Paperclip as ${HOST_GITHUB_TOKEN_SECRET_NAME}` }),
33039
+ /* @__PURE__ */ jsxs2("span", { children: [
33040
+ `Creates or rotates a company secret named ${HOST_GITHUB_TOKEN_SECRET_NAME} so Paperclip's own GitHub features `,
33041
+ "(managed-checkout git credentials, merged-PR confirmation sweep, workspace reaper, external-object liveness) ",
33042
+ "can authenticate with the same token. GitHub Sync itself does not need it."
33043
+ ] })
33044
+ ] })
33045
+ ] }),
32840
33046
  /* @__PURE__ */ jsx2("div", { className: "ghsync__actions", children: /* @__PURE__ */ jsxs2("div", { className: "ghsync__button-row", children: [
32841
33047
  hasSavedToken ? /* @__PURE__ */ jsx2(
32842
33048
  "button",
@@ -32848,6 +33054,7 @@ function GitHubSyncSettingsPage() {
32848
33054
  setShowTokenEditor(false);
32849
33055
  setTokenDraft("");
32850
33056
  setTokenStatusOverride("valid");
33057
+ setExposeTokenAsHostSecret(false);
32851
33058
  },
32852
33059
  children: "Cancel"
32853
33060
  }
@@ -32909,6 +33116,30 @@ function GitHubSyncSettingsPage() {
32909
33116
  tokenPermissionUnknownVisible ? /* @__PURE__ */ jsxs2("div", { className: "ghsync__permission-audit", children: [
32910
33117
  /* @__PURE__ */ jsx2("div", { className: "ghsync__permission-audit-header", children: /* @__PURE__ */ jsx2("strong", { children: "Token permission audit pending" }) }),
32911
33118
  /* @__PURE__ */ jsx2("div", { className: "ghsync__permission-audit-list", children: /* @__PURE__ */ jsx2("div", { className: "ghsync__permission-audit-item", children: /* @__PURE__ */ jsx2("span", { children: tokenPermissionAuditData?.warnings[0] ?? "Add a mapped repository in this company so GitHub Sync can verify the token permissions it needs." }) }) })
33119
+ ] }) : null,
33120
+ agentToolAccessWarningVisible ? /* @__PURE__ */ jsxs2("div", { className: "ghsync__permission-audit ghsync__permission-audit--warning", children: [
33121
+ /* @__PURE__ */ jsxs2("div", { className: "ghsync__permission-audit-header", children: [
33122
+ /* @__PURE__ */ jsx2("strong", { children: `${agentToolAccessSampleLabel} cannot see the GitHub Sync tools` }),
33123
+ /* @__PURE__ */ jsx2("span", { className: "ghsync__badge ghsync__badge--warning", children: "Tool access" })
33124
+ ] }),
33125
+ /* @__PURE__ */ jsx2("div", { className: "ghsync__permission-audit-list", children: /* @__PURE__ */ jsxs2("div", { className: "ghsync__permission-audit-item", children: [
33126
+ /* @__PURE__ */ jsxs2("span", { children: [
33127
+ `Paperclip's tool gateway is fail-closed, and no tool profile that applies to ${agentToolAccessSampleLabel} includes any of the `,
33128
+ agentToolAccess?.totalToolCount ? `${agentToolAccess.totalToolCount} ` : "",
33129
+ `${GITHUB_SYNC_PLUGIN_ID}:* tools, so those tools will not be offered. `,
33130
+ "Bind a tool profile with tool_name include entries at company scope. ",
33131
+ `This is a sample of one agent${agentToolAccessOtherAgentsHint}: Paperclip evaluates tool profiles per agent, and an agent-scoped binding overrides the company one.`
33132
+ ] }),
33133
+ /* @__PURE__ */ jsx2(
33134
+ "a",
33135
+ {
33136
+ href: GITHUB_SYNC_TOOL_ACCESS_DOCS_URL,
33137
+ target: "_blank",
33138
+ rel: "noreferrer",
33139
+ children: "How to grant the tools to agents"
33140
+ }
33141
+ )
33142
+ ] }) })
32912
33143
  ] }) : null
32913
33144
  ] }),
32914
33145
  boardAccessSettingsVisible ? /* @__PURE__ */ jsxs2("section", { className: "ghsync__section", children: [
@@ -35008,47 +35239,8 @@ function GitHubSyncIssueTaskDetailView(props) {
35008
35239
  );
35009
35240
  }
35010
35241
  var GitHubSyncIssueDetailTab = GitHubSyncIssueTaskDetailView;
35011
- function GitHubSyncCommentAnnotation() {
35012
- const context = useHostContext();
35013
- const themeMode = useResolvedThemeMode();
35014
- const theme = themeMode === "light" ? LIGHT_PALETTE : DARK_PALETTE;
35015
- const themeVars = buildThemeVars(theme, themeMode);
35016
- const annotation = usePluginData("comment.annotation", {
35017
- ...context.companyId ? { companyId: context.companyId } : {},
35018
- ...context.entityId ? { commentId: context.entityId } : {},
35019
- ...context.parentEntityId ? { parentIssueId: context.parentEntityId } : {}
35020
- });
35021
- if (annotation.loading && !annotation.data) {
35022
- return null;
35023
- }
35024
- if (annotation.error || !annotation.data || annotation.data.links.length === 0) {
35025
- return null;
35026
- }
35027
- return /* @__PURE__ */ jsxs2("div", { className: "ghsync-extension-card ghsync-extension-card--compact", style: themeVars, children: [
35028
- /* @__PURE__ */ jsx2("style", { children: EXTENSION_SURFACE_STYLES }),
35029
- /* @__PURE__ */ jsxs2("div", { className: "ghsync-comment-annotation", children: [
35030
- /* @__PURE__ */ jsx2("span", { className: "ghsync-comment-annotation__label", children: "GitHub refs" }),
35031
- annotation.data.links.map((link3) => /* @__PURE__ */ jsx2(
35032
- "a",
35033
- {
35034
- href: link3.href,
35035
- target: "_blank",
35036
- rel: "noreferrer",
35037
- className: getPluginActionClassName({
35038
- variant: "secondary",
35039
- size: "sm",
35040
- extraClassName: "ghsync-extension-link"
35041
- }),
35042
- children: /* @__PURE__ */ jsx2(GitHubButtonLabel, { label: link3.label })
35043
- },
35044
- `${link3.type}:${link3.href}`
35045
- ))
35046
- ] })
35047
- ] });
35048
- }
35049
35242
  var index_default = GitHubSyncSettingsPage;
35050
35243
  export {
35051
- GitHubSyncCommentAnnotation,
35052
35244
  GitHubSyncDashboardWidget,
35053
35245
  GitHubSyncEntityToolbarButton,
35054
35246
  GitHubSyncGlobalToolbarButton,