@useavalon/caelence-agent 0.1.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.
Files changed (161) hide show
  1. package/README.md +201 -0
  2. package/bin/harness.ts +10 -0
  3. package/package.json +75 -0
  4. package/skills/copy-editor/SKILL.md +74 -0
  5. package/skills/copy-editor/references/anti-slop.md +62 -0
  6. package/skills/copy-editor/references/ui-states.md +46 -0
  7. package/skills/copy-editor/scripts/lint-copy.py +78 -0
  8. package/skills/copy-harry-dry/SKILL.md +120 -0
  9. package/skills/copy-rmbc/SKILL.md +97 -0
  10. package/skills/copywriting/SKILL.md +73 -0
  11. package/skills/impeccable/SKILL.md +133 -0
  12. package/skills/impeccable/references/visual-slop.md +36 -0
  13. package/src/cli/main.test.ts +36 -0
  14. package/src/cli/main.ts +384 -0
  15. package/src/cli/media-models.ts +82 -0
  16. package/src/cli/models.ts +43 -0
  17. package/src/cli/openrouter-live.test.ts +35 -0
  18. package/src/cli/openrouter-live.ts +72 -0
  19. package/src/cli/openrouter-modality.test.ts +25 -0
  20. package/src/cli/openrouter-modality.ts +83 -0
  21. package/src/cli/picker.test.ts +53 -0
  22. package/src/cli/picker.ts +48 -0
  23. package/src/cli/plain-text.ts +15 -0
  24. package/src/cli/slash-dispatch.test.ts +213 -0
  25. package/src/cli/slash-dispatch.ts +298 -0
  26. package/src/cli/slash.test.ts +113 -0
  27. package/src/cli/slash.ts +119 -0
  28. package/src/cli/theme.test.ts +10 -0
  29. package/src/cli/theme.ts +44 -0
  30. package/src/cli/tui-layout.test.ts +33 -0
  31. package/src/cli/tui-layout.ts +33 -0
  32. package/src/cli/tui-screen.test.ts +33 -0
  33. package/src/cli/tui-screen.ts +13 -0
  34. package/src/cli/tui.tsx +735 -0
  35. package/src/config.ts +86 -0
  36. package/src/core/approval.test.ts +60 -0
  37. package/src/core/approval.ts +83 -0
  38. package/src/core/auto-router.test.ts +31 -0
  39. package/src/core/auto-router.ts +66 -0
  40. package/src/core/errors.ts +67 -0
  41. package/src/core/events.ts +85 -0
  42. package/src/core/hooks.test.ts +66 -0
  43. package/src/core/hooks.ts +94 -0
  44. package/src/core/ids.ts +6 -0
  45. package/src/core/instructions.test.ts +49 -0
  46. package/src/core/instructions.ts +44 -0
  47. package/src/core/logger.ts +45 -0
  48. package/src/core/mcp.ts +191 -0
  49. package/src/core/mode.test.ts +63 -0
  50. package/src/core/mode.ts +60 -0
  51. package/src/core/run-turn.test.ts +339 -0
  52. package/src/core/run-turn.ts +487 -0
  53. package/src/core/session.test.ts +203 -0
  54. package/src/core/session.ts +349 -0
  55. package/src/core/stdio-mcp.ts +143 -0
  56. package/src/core/strands.ts +262 -0
  57. package/src/core/usage.test.ts +69 -0
  58. package/src/core/usage.ts +171 -0
  59. package/src/desktop/bridge.test.ts +331 -0
  60. package/src/desktop/bridge.ts +729 -0
  61. package/src/desktop/open-local.test.ts +40 -0
  62. package/src/desktop/open-local.ts +52 -0
  63. package/src/desktop/preview-cache.test.ts +36 -0
  64. package/src/desktop/preview-cache.ts +63 -0
  65. package/src/desktop/secrets.test.ts +44 -0
  66. package/src/desktop/secrets.ts +60 -0
  67. package/src/evals/runner.test.ts +43 -0
  68. package/src/evals/runner.ts +225 -0
  69. package/src/index.ts +132 -0
  70. package/src/init.test.ts +54 -0
  71. package/src/init.ts +117 -0
  72. package/src/integrations/catalog-data.json +424 -0
  73. package/src/integrations/catalog.ts +81 -0
  74. package/src/integrations/connect.ts +231 -0
  75. package/src/integrations/integrations.test.ts +329 -0
  76. package/src/integrations/marks/airtable.svg +1 -0
  77. package/src/integrations/marks/algolia-mcp.svg +1 -0
  78. package/src/integrations/marks/canva.jpg +0 -0
  79. package/src/integrations/marks/cloudflare-mcp.svg +1 -0
  80. package/src/integrations/marks/contentful-mcp.svg +1 -0
  81. package/src/integrations/marks/craft.png +0 -0
  82. package/src/integrations/marks/dinero.png +0 -0
  83. package/src/integrations/marks/figma.svg +1 -0
  84. package/src/integrations/marks/gitlab.svg +1 -0
  85. package/src/integrations/marks/google-calendar.svg +1 -0
  86. package/src/integrations/marks/google-docs.svg +1 -0
  87. package/src/integrations/marks/google-drive.svg +1 -0
  88. package/src/integrations/marks/google-gmail.svg +1 -0
  89. package/src/integrations/marks/google-sheets.svg +1 -0
  90. package/src/integrations/marks/google-slides.svg +1 -0
  91. package/src/integrations/marks/granola.png +0 -0
  92. package/src/integrations/marks/jira.svg +1 -0
  93. package/src/integrations/marks/linear.svg +1 -0
  94. package/src/integrations/marks/microsoft-365.svg +7 -0
  95. package/src/integrations/marks/miro.svg +1 -0
  96. package/src/integrations/marks/mixpanel-mcp.svg +1 -0
  97. package/src/integrations/marks/monday.png +0 -0
  98. package/src/integrations/marks/mux-mcp.png +0 -0
  99. package/src/integrations/marks/neon-mcp.svg +1 -0
  100. package/src/integrations/marks/notion.svg +1 -0
  101. package/src/integrations/marks/paddle-mcp.svg +1 -0
  102. package/src/integrations/marks/posthog-mcp.svg +1 -0
  103. package/src/integrations/marks/prismic-mcp.svg +1 -0
  104. package/src/integrations/marks/replicate-mcp.svg +1 -0
  105. package/src/integrations/marks/resend-mcp.svg +1 -0
  106. package/src/integrations/marks/sanity-mcp.svg +1 -0
  107. package/src/integrations/marks/sceneplane.png +0 -0
  108. package/src/integrations/marks/sentry-mcp.svg +1 -0
  109. package/src/integrations/marks/stripe-mcp.svg +1 -0
  110. package/src/integrations/marks/supabase-mcp.svg +1 -0
  111. package/src/integrations/marks/upstash-mcp.svg +1 -0
  112. package/src/integrations/marks/vercel.svg +1 -0
  113. package/src/integrations/marks/webflow.svg +1 -0
  114. package/src/integrations/mcp-oauth.test.ts +39 -0
  115. package/src/integrations/mcp-oauth.ts +330 -0
  116. package/src/integrations/oauth-clients.test.ts +77 -0
  117. package/src/integrations/oauth-clients.ts +127 -0
  118. package/src/integrations/oauth.ts +145 -0
  119. package/src/integrations/remote-mcp.ts +307 -0
  120. package/src/integrations/store.ts +149 -0
  121. package/src/media/openrouter-generate.test.ts +80 -0
  122. package/src/media/openrouter-generate.ts +178 -0
  123. package/src/media/prefs.ts +54 -0
  124. package/src/observability/categories.ts +41 -0
  125. package/src/observability/create.test.ts +56 -0
  126. package/src/observability/create.ts +45 -0
  127. package/src/observability/experiments.ts +113 -0
  128. package/src/observability/fake.ts +191 -0
  129. package/src/observability/index.ts +57 -0
  130. package/src/observability/judges.ts +91 -0
  131. package/src/observability/langfuse.ts +275 -0
  132. package/src/observability/noop.ts +33 -0
  133. package/src/observability/observability.test.ts +113 -0
  134. package/src/observability/prompts.ts +98 -0
  135. package/src/observability/regression-items.ts +158 -0
  136. package/src/observability/sanitize.test.ts +26 -0
  137. package/src/observability/sanitize.ts +57 -0
  138. package/src/observability/types.ts +122 -0
  139. package/src/observability/version.ts +41 -0
  140. package/src/product.ts +2 -0
  141. package/src/runtime.test.ts +98 -0
  142. package/src/runtime.ts +438 -0
  143. package/src/skills/author-skill.ts +49 -0
  144. package/src/skills/create-skill.test.ts +108 -0
  145. package/src/skills/create-skill.ts +70 -0
  146. package/src/skills/loader.test.ts +122 -0
  147. package/src/skills/loader.ts +162 -0
  148. package/src/skills/registry.test.ts +190 -0
  149. package/src/skills/registry.ts +402 -0
  150. package/src/skills/skill-command.ts +53 -0
  151. package/src/skills/user-dir.ts +8 -0
  152. package/src/tools/git.test.ts +71 -0
  153. package/src/tools/git.ts +126 -0
  154. package/src/tools/local.ts +258 -0
  155. package/src/tools/paths.test.ts +24 -0
  156. package/src/tools/paths.ts +39 -0
  157. package/src/tools/read-skill.ts +43 -0
  158. package/src/tools/subagent.test.ts +77 -0
  159. package/src/tools/subagent.ts +74 -0
  160. package/src/tools/todo.test.ts +25 -0
  161. package/src/tools/todo.ts +70 -0
@@ -0,0 +1 @@
1
+ <svg fill="#000000" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Notion</title><path d="M4.459 4.208c.746.606 1.026.56 2.428.466l13.215-.793c.28 0 .047-.28-.046-.326L17.86 1.968c-.42-.326-.981-.7-2.055-.607L3.01 2.295c-.466.046-.56.28-.374.466zm.793 3.08v13.904c0 .747.373 1.027 1.214.98l14.523-.84c.841-.046.935-.56.935-1.167V6.354c0-.606-.233-.933-.748-.887l-15.177.887c-.56.047-.747.327-.747.933zm14.337.745c.093.42 0 .84-.42.888l-.7.14v10.264c-.608.327-1.168.514-1.635.514-.748 0-.935-.234-1.495-.933l-4.577-7.186v6.952L12.21 19s0 .84-1.168.84l-3.222.186c-.093-.186 0-.653.327-.746l.84-.233V9.854L7.822 9.76c-.094-.42.14-1.026.793-1.073l3.456-.233 4.764 7.279v-6.44l-1.215-.139c-.093-.514.28-.887.747-.933zM1.936 1.035l13.31-.98c1.634-.14 2.055-.047 3.082.7l4.249 2.986c.7.513.934.653.934 1.213v16.378c0 1.026-.373 1.634-1.68 1.726l-15.458.934c-.98.047-1.448-.093-1.962-.747l-3.129-4.06c-.56-.747-.793-1.306-.793-1.96V2.667c0-.839.374-1.54 1.447-1.632z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#FDDD35" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Paddle</title><path d="M2.363 7.904v.849a3.95 3.95 0 0 1 3.65 2.425c.198.476.3.987.299 1.502h.791c0-1.04.416-2.037 1.157-2.772a3.962 3.962 0 0 1 2.792-1.149V7.91a3.959 3.959 0 0 1-3.65-2.425 3.893 3.893 0 0 1-.299-1.502h-.791c0 1.04-.416 2.037-1.157 2.772a3.96 3.96 0 0 1-2.792 1.149M13.105 2.51H6.312V0h6.793c4.772 0 8.532 3.735 8.532 8.314 0 4.58-3.76 8.314-8.532 8.314H9.156V24H6.312v-9.882h6.793c3.319 0 5.688-2.352 5.688-5.804 0-3.451-2.37-5.804-5.688-5.804"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#000000" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>PostHog</title><path d="M9.854 14.5 5 9.647.854 5.5A.5.5 0 0 0 0 5.854V8.44a.5.5 0 0 0 .146.353L5 13.647l.147.146L9.854 18.5l.146.147v-.049c.065.03.134.049.207.049h2.586a.5.5 0 0 0 .353-.854L9.854 14.5zm0-5-4-4a.487.487 0 0 0-.409-.144.515.515 0 0 0-.356.21.493.493 0 0 0-.089.288V8.44a.5.5 0 0 0 .147.353l9 9a.5.5 0 0 0 .853-.354v-2.585a.5.5 0 0 0-.146-.354l-5-5zm1-4a.5.5 0 0 0-.854.354V8.44a.5.5 0 0 0 .147.353l4 4a.5.5 0 0 0 .853-.354V9.854a.5.5 0 0 0-.146-.354l-4-4zm12.647 11.515a3.863 3.863 0 0 1-2.232-1.1l-4.708-4.707a.5.5 0 0 0-.854.354v6.585a.5.5 0 0 0 .5.5H23.5a.5.5 0 0 0 .5-.5v-.6c0-.276-.225-.497-.499-.532zm-5.394.032a.8.8 0 1 1 0-1.6.8.8 0 0 1 0 1.6zM.854 15.5a.5.5 0 0 0-.854.354v2.293a.5.5 0 0 0 .5.5h2.293c.222 0 .39-.135.462-.309a.493.493 0 0 0-.109-.545L.854 15.501zM5 14.647.854 10.5a.5.5 0 0 0-.854.353v2.586a.5.5 0 0 0 .146.353L4.854 18.5l.146.147h2.793a.5.5 0 0 0 .353-.854L5 14.647z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#5163BA" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Prismic</title><path d="M7.7 0C5.033 0 4.066.278 3.09.8A5.447 5.447 0 0 0 .825 3.07c-.522.977-.8 1.947-.8 4.622v.998c0 .199.078.388.218.529l1.77 1.774a.15.15 0 0 0 .257-.106V8.019c0-2.006.208-2.733.6-3.467A4.088 4.088 0 0 1 4.568 2.85c.731-.392 1.457-.6 3.459-.6h2.164c.199 0 .39-.08.53-.221l1.77-1.772A.15.15 0 0 0 12.387 0zm7.605 0c-.2 0-.392.08-.532.22l-1.769 1.775a.147.147 0 0 0-.044.104c0 .083.068.15.15.15h2.862c2.002 0 2.728.21 3.46.601a4.089 4.089 0 0 1 1.698 1.702c.39.734.599 1.461.599 3.467v2.17c0 .198.078.39.218.53l1.77 1.774a.15.15 0 0 0 .257-.106V7.692c0-2.675-.278-3.645-.8-4.623A5.446 5.446 0 0 0 20.91.801C19.935.278 18.968 0 16.3 0zM6.761 3.75a2.995 2.995 0 0 0-2.993 2.999v5.691a.75.75 0 0 0 .219.529l1.77 1.776a.149.149 0 0 0 .255-.106v-7.14a1.5 1.5 0 0 1 .097-.53c.072-.2.188-.385.348-.545l2.308-2.421a.15.15 0 0 0-.11-.253zm4.802 0c-.2 0-.39.08-.53.22L9.26 5.744A.151.151 0 0 0 9.366 6h7.124c.186 0 .364.034.528.097.2.072.386.188.546.347l2.413 2.313a.15.15 0 0 0 .255-.108v-1.9a2.995 2.995 0 0 0-2.993-3zm6.573 5.463a.15.15 0 0 0-.15.15v7.139a1.5 1.5 0 0 1-.095.53 1.49 1.49 0 0 1-.348.546l-2.308 2.42a.15.15 0 0 0 .108.255h1.896a2.997 2.997 0 0 0 2.993-3.002v-5.69a.752.752 0 0 0-.219-.53l-1.77-1.774a.15.15 0 0 0-.107-.044zm-17.96 2.25a.15.15 0 0 0-.15.15v4.695c0 2.674.278 3.645.8 4.623a5.442 5.442 0 0 0 2.263 2.267c.976.522 1.943.802 4.612.802h.994c.2 0 .39-.08.53-.22l1.771-1.775a.149.149 0 0 0-.106-.255H8.027c-2.002 0-2.728-.208-3.46-.6a4.088 4.088 0 0 1-1.698-1.702c-.39-.734-.599-1.461-.599-3.467v-2.172a.749.749 0 0 0-.22-.528L.282 11.507a.15.15 0 0 0-.106-.044zm21.703 1.5a.15.15 0 0 0-.15.15v2.868c0 2.006-.208 2.733-.6 3.467a4.088 4.088 0 0 1-1.698 1.702c-.731.392-1.457.6-3.459.6h-2.164a.749.749 0 0 0-.532.22l-1.769 1.773a.151.151 0 0 0-.043.107c0 .083.065.15.148.15H16.3c2.67 0 3.636-.28 4.612-.802a5.442 5.442 0 0 0 2.263-2.267c.522-.978.8-1.948.8-4.623v-.998a.749.749 0 0 0-.22-.529l-1.769-1.774a.15.15 0 0 0-.106-.044zm-17.96 2.238a.15.15 0 0 0-.151.15v1.898a2.997 2.997 0 0 0 2.993 3.001h5.676c.2 0 .39-.08.53-.22l1.773-1.775a.146.146 0 0 0 .044-.104.15.15 0 0 0-.15-.15H7.51a1.48 1.48 0 0 1-.53-.098 1.49 1.49 0 0 1-.546-.347l-2.413-2.313a.147.147 0 0 0-.103-.042z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#000000" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Replicate</title><path d="M24 10.262v2.712h-9.518V24h-3.034V10.262zm0-5.131v2.717H8.755V24H5.722V5.131zM24 0v2.717H3.034V24H0V0z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#000000" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Resend</title><path d="M14.679 0c4.648 0 7.413 2.765 7.413 6.434s-2.765 6.434-7.413 6.434H12.33L24 24h-8.245l-8.88-8.44c-.636-.588-.93-1.273-.93-1.86 0-.831.587-1.565 1.713-1.883l4.574-1.224c1.737-.465 2.936-1.81 2.936-3.572 0-2.153-1.761-3.4-3.939-3.4H0V0z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#0D0E12" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Sanity</title><path d="m23.327 15.205-.893-1.555-4.321 2.632 4.799-6.11.726-.426-.179-.27.33-.421-1.515-1.261-.693.883-13.992 8.186 5.173-6.221 9.636-5.282-.915-1.769-5.248 2.876 2.584-3.106-1.481-1.305-5.816 6.994-5.777 3.168 4.423-5.847 2.771-1.442-.88-1.789-8.075 4.203L6.186 4.43 4.648 3.198 0 9.349l.072.058.868 1.768 5.153-2.683-4.696 6.207.77.617.458.885 5.425-2.974-5.974 7.185 1.481 1.304.297-.358 14.411-8.459-4.785 6.094.078.065-.007.005.992 1.726 6.364-3.877-2.451 3.954 1.642 1.077L24 15.648z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#362D59" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Sentry</title><path d="M13.91 2.505c-.873-1.448-2.972-1.448-3.844 0L6.904 7.92a15.478 15.478 0 0 1 8.53 12.811h-2.221A13.301 13.301 0 0 0 5.784 9.814l-2.926 5.06a7.65 7.65 0 0 1 4.435 5.848H2.194a.365.365 0 0 1-.298-.534l1.413-2.402a5.16 5.16 0 0 0-1.614-.913L.296 19.275a2.182 2.182 0 0 0 .812 2.999 2.24 2.24 0 0 0 1.086.288h6.983a9.322 9.322 0 0 0-3.845-8.318l1.11-1.922a11.47 11.47 0 0 1 4.95 10.24h5.915a17.242 17.242 0 0 0-7.885-15.28l2.244-3.845a.37.37 0 0 1 .504-.13c.255.14 9.75 16.708 9.928 16.9a.365.365 0 0 1-.327.543h-2.287c.029.612.029 1.223 0 1.831h2.297a2.206 2.206 0 0 0 1.922-3.31z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#635BFF" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Stripe</title><path d="M13.976 9.15c-2.172-.806-3.356-1.426-3.356-2.409 0-.831.683-1.305 1.901-1.305 2.227 0 4.515.858 6.09 1.631l.89-5.494C18.252.975 15.697 0 12.165 0 9.667 0 7.589.654 6.104 1.872 4.56 3.147 3.757 4.992 3.757 7.218c0 4.039 2.467 5.76 6.476 7.219 2.585.92 3.445 1.574 3.445 2.583 0 .98-.84 1.545-2.354 1.545-1.875 0-4.965-.921-6.99-2.109l-.9 5.555C5.175 22.99 8.385 24 11.714 24c2.641 0 4.843-.624 6.328-1.813 1.664-1.305 2.525-3.236 2.525-5.732 0-4.128-2.524-5.851-6.594-7.305h.003z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#3FCF8E" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Supabase</title><path d="M11.9 1.036c-.015-.986-1.26-1.41-1.874-.637L.764 12.05C-.33 13.427.65 15.455 2.409 15.455h9.579l.113 7.51c.014.985 1.259 1.408 1.873.636l9.262-11.653c1.093-1.375.113-3.403-1.645-3.403h-9.642z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#00E9A3" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Upstash</title><path d="M13.8027 0C11.193 0 8.583.9952 6.5918 2.9863c-3.9823 3.9823-3.9823 10.4396 0 14.4219 1.9911 1.9911 5.2198 1.9911 7.211 0 1.991-1.9911 1.991-5.2198 0-7.211L12 12c.9956.9956.9956 2.6098 0 3.6055-.9956.9955-2.6099.9955-3.6055 0-2.9866-2.9868-2.9866-7.8297 0-10.8164 2.9868-2.9868 7.8297-2.9868 10.8164 0l1.8028-1.8028C19.0225.9952 16.4125 0 13.8027 0zM12 12c-.9956-.9956-.9956-2.6098 0-3.6055.9956-.9955 2.6098-.9955 3.6055 0 2.9867 2.9868 2.9867 7.8297 0 10.8164-2.9867 2.9868-7.8297 2.9868-10.8164 0l-1.8028 1.8028c3.9823 3.9822 10.4396 3.9822 14.4219 0 3.9823-3.9824 3.9823-10.4396 0-14.4219-.9956-.9956-2.3006-1.4922-3.6055-1.4922-1.3048 0-2.6099.4966-3.6054 1.4922-1.9912 1.9912-1.9912 5.2198 0 7.211z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#000000" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Vercel</title><path d="m12 1.608 12 20.784H0Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="#146EF5" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Webflow</title><path d="m24 4.515-7.658 14.97H9.149l3.205-6.204h-.144C9.566 16.713 5.621 18.973 0 19.485v-6.118s3.596-.213 5.71-2.435H0V4.515h6.417v5.278l.144-.001 2.622-5.277h4.854v5.244h.144l2.72-5.244H24Z"/></svg>
@@ -0,0 +1,39 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { isLoopbackRedirect, registerMcpClient } from "./mcp-oauth.ts";
3
+
4
+ describe("MCP client registration", () => {
5
+ test("loopback redirects register as native first", async () => {
6
+ const bodies: string[] = [];
7
+ const registered = await registerMcpClient({
8
+ registrationUrl: "https://mcp.linear.app/register",
9
+ redirectUri: "http://127.0.0.1:9/oauth/callback",
10
+ clientName: "Caelence agent",
11
+ tokenEndpointAuthMethod: "none",
12
+ fetchImpl: (async (_input, init) => {
13
+ bodies.push(String(init?.body ?? ""));
14
+ return Response.json({ client_id: "cli" });
15
+ }) as typeof fetch,
16
+ });
17
+ expect(registered.clientId).toBe("cli");
18
+ expect(bodies).toHaveLength(1);
19
+ expect(bodies[0]).toContain('"application_type":"native"');
20
+ expect(isLoopbackRedirect("http://127.0.0.1:9/oauth/callback")).toBe(true);
21
+ });
22
+
23
+ test("retries web after native 403 and reports Figma allowlisting", async () => {
24
+ const types: string[] = [];
25
+ await expect(
26
+ registerMcpClient({
27
+ registrationUrl: "https://api.figma.com/v1/oauth/mcp/register",
28
+ redirectUri: "http://127.0.0.1:9/oauth/callback",
29
+ clientName: "Caelence agent",
30
+ fetchImpl: (async (_input, init) => {
31
+ const body = JSON.parse(String(init?.body ?? "{}")) as { application_type?: string };
32
+ types.push(body.application_type ?? "");
33
+ return new Response("Forbidden", { status: 403 });
34
+ }) as typeof fetch,
35
+ }),
36
+ ).rejects.toThrow(/Figma blocked client registration \(403\)/);
37
+ expect(types).toEqual(["native", "web"]);
38
+ });
39
+ });
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Remote MCP OAuth 2.1: protected-resource discovery, authorization-server
3
+ * metadata, and dynamic client registration (RFC 9728 / 8414 / 7591).
4
+ */
5
+
6
+ export interface ProtectedResourceMetadata {
7
+ resource: string;
8
+ authorization_servers?: string[];
9
+ }
10
+
11
+ export interface AuthorizationServerMetadata {
12
+ issuer: string;
13
+ authorization_endpoint: string;
14
+ token_endpoint: string;
15
+ registration_endpoint?: string;
16
+ code_challenge_methods_supported?: string[];
17
+ token_endpoint_auth_methods_supported?: string[];
18
+ }
19
+
20
+ export interface DynamicClientRegistration {
21
+ clientId: string;
22
+ clientSecret: string;
23
+ tokenAuth: "none" | "body" | "basic";
24
+ }
25
+
26
+ export interface DiscoveredMcpAuth {
27
+ resource: string;
28
+ authorizeUrl: string;
29
+ tokenUrl: string;
30
+ registrationUrl?: string;
31
+ tokenAuth: "none" | "body" | "basic";
32
+ client: DynamicClientRegistration;
33
+ }
34
+
35
+ const INIT_BODY = JSON.stringify({
36
+ jsonrpc: "2.0",
37
+ id: 1,
38
+ method: "initialize",
39
+ params: {
40
+ protocolVersion: "2025-06-18",
41
+ capabilities: {},
42
+ clientInfo: { name: "caelence-agent", version: "0.1" },
43
+ },
44
+ });
45
+
46
+ export function canonicalResourceUri(mcpUrl: string): string {
47
+ const url = new URL(mcpUrl);
48
+ url.hash = "";
49
+ url.search = "";
50
+ const path = url.pathname.replace(/\/+$/, "");
51
+ url.pathname = path === "/" ? "" : path;
52
+ return url.toString().replace(/\/+$/, "");
53
+ }
54
+
55
+ export function parseResourceMetadataUrl(header: string): string | undefined {
56
+ const quoted = /resource_metadata\s*=\s*"([^"]+)"/i.exec(header);
57
+ if (quoted?.[1]) return quoted[1];
58
+ const bare = /resource_metadata\s*=\s*([^\s,]+)/i.exec(header);
59
+ return bare?.[1];
60
+ }
61
+
62
+ export function protectedResourceMetadataUrls(mcpUrl: string): string[] {
63
+ const url = new URL(mcpUrl);
64
+ const path = url.pathname.replace(/\/+$/, "");
65
+ const origin = url.origin;
66
+ const urls = [`${origin}/.well-known/oauth-protected-resource`];
67
+ if (path && path !== "/") {
68
+ urls.unshift(`${origin}/.well-known/oauth-protected-resource${path}`);
69
+ }
70
+ return urls;
71
+ }
72
+
73
+ export function authorizationServerMetadataUrls(issuer: string): string[] {
74
+ const url = new URL(issuer);
75
+ const path = url.pathname.replace(/\/+$/, "");
76
+ if (!path || path === "/") {
77
+ return [`${url.origin}/.well-known/oauth-authorization-server`];
78
+ }
79
+ return [
80
+ `${url.origin}/.well-known/oauth-authorization-server${path}`,
81
+ `${issuer.replace(/\/+$/, "")}/.well-known/oauth-authorization-server`,
82
+ ];
83
+ }
84
+
85
+ export function registrationAuthMethod(
86
+ methods: readonly string[] | undefined,
87
+ ): "none" | "client_secret_post" | "client_secret_basic" {
88
+ const set = new Set((methods ?? []).map((m) => m.toLowerCase()));
89
+ if (set.has("none") || set.size === 0) return "none";
90
+ if (set.has("client_secret_post")) return "client_secret_post";
91
+ return "client_secret_basic";
92
+ }
93
+
94
+ export function pickTokenAuth(
95
+ methods: readonly string[] | undefined,
96
+ hasSecret: boolean,
97
+ ): "none" | "body" | "basic" {
98
+ const set = new Set((methods ?? []).map((m) => m.toLowerCase()));
99
+ if (hasSecret && set.has("client_secret_basic")) return "basic";
100
+ if (hasSecret && (set.has("client_secret_post") || set.size === 0)) return "body";
101
+ if (set.has("none") || set.size === 0) return "none";
102
+ return hasSecret ? "body" : "none";
103
+ }
104
+
105
+ export async function discoverMcpAuth(input: {
106
+ mcpUrl: string;
107
+ redirectUri: string;
108
+ clientName?: string;
109
+ client?: { clientId: string; clientSecret: string };
110
+ fetchImpl?: typeof fetch;
111
+ }): Promise<DiscoveredMcpAuth> {
112
+ const fetchImpl = input.fetchImpl ?? globalThis.fetch;
113
+ const resourceMeta = await loadProtectedResourceMetadata(input.mcpUrl, fetchImpl);
114
+ const resource = resourceMeta.resource?.trim() || canonicalResourceUri(input.mcpUrl);
115
+ const issuer = resourceMeta.authorization_servers?.[0]?.trim() || new URL(input.mcpUrl).origin;
116
+ const asMeta = await loadAuthorizationServerMetadata(issuer, fetchImpl);
117
+ if (!asMeta.authorization_endpoint || !asMeta.token_endpoint) {
118
+ throw new Error("Authorization server did not advertise authorize and token endpoints.");
119
+ }
120
+ const stored = input.client?.clientId.trim()
121
+ ? { clientId: input.client.clientId.trim(), clientSecret: input.client.clientSecret.trim() }
122
+ : undefined;
123
+ if (stored) {
124
+ const tokenAuth = pickTokenAuth(
125
+ asMeta.token_endpoint_auth_methods_supported,
126
+ Boolean(stored.clientSecret),
127
+ );
128
+ return {
129
+ resource,
130
+ authorizeUrl: asMeta.authorization_endpoint,
131
+ tokenUrl: asMeta.token_endpoint,
132
+ registrationUrl: asMeta.registration_endpoint?.trim(),
133
+ tokenAuth,
134
+ client: { ...stored, tokenAuth },
135
+ };
136
+ }
137
+ const registrationUrl = asMeta.registration_endpoint?.trim();
138
+ if (!registrationUrl) {
139
+ throw new Error("This MCP does not support dynamic client registration.");
140
+ }
141
+ const registered = await registerMcpClient({
142
+ registrationUrl,
143
+ redirectUri: input.redirectUri,
144
+ clientName: input.clientName ?? "Caelence agent",
145
+ tokenEndpointAuthMethod: registrationAuthMethod(asMeta.token_endpoint_auth_methods_supported),
146
+ fetchImpl,
147
+ });
148
+ const tokenAuth = pickTokenAuth(
149
+ asMeta.token_endpoint_auth_methods_supported,
150
+ Boolean(registered.clientSecret),
151
+ );
152
+ return {
153
+ resource,
154
+ authorizeUrl: asMeta.authorization_endpoint,
155
+ tokenUrl: asMeta.token_endpoint,
156
+ registrationUrl,
157
+ tokenAuth,
158
+ client: { ...registered, tokenAuth },
159
+ };
160
+ }
161
+
162
+ async function loadProtectedResourceMetadata(
163
+ mcpUrl: string,
164
+ fetchImpl: typeof fetch,
165
+ ): Promise<ProtectedResourceMetadata> {
166
+ const headerUrl = await probeResourceMetadataUrl(mcpUrl, fetchImpl);
167
+ const candidates = headerUrl
168
+ ? [headerUrl, ...protectedResourceMetadataUrls(mcpUrl)]
169
+ : protectedResourceMetadataUrls(mcpUrl);
170
+ const seen = new Set<string>();
171
+ for (const url of candidates) {
172
+ if (seen.has(url)) continue;
173
+ seen.add(url);
174
+ const json = await getJson(url, fetchImpl);
175
+ if (!json) continue;
176
+ const resource = typeof json.resource === "string" ? json.resource : "";
177
+ if (!resource) continue;
178
+ const servers = Array.isArray(json.authorization_servers)
179
+ ? json.authorization_servers.filter(
180
+ (s): s is string => typeof s === "string" && s.trim() !== "",
181
+ )
182
+ : [];
183
+ return { resource, authorization_servers: servers };
184
+ }
185
+ const origin = new URL(mcpUrl).origin;
186
+ const asMeta = await loadAuthorizationServerMetadata(origin, fetchImpl).catch(() => null);
187
+ if (asMeta?.authorization_endpoint && asMeta?.token_endpoint) {
188
+ return { resource: canonicalResourceUri(mcpUrl), authorization_servers: [origin] };
189
+ }
190
+ throw new Error("Could not discover OAuth metadata for this MCP.");
191
+ }
192
+
193
+ async function probeResourceMetadataUrl(
194
+ mcpUrl: string,
195
+ fetchImpl: typeof fetch,
196
+ ): Promise<string | undefined> {
197
+ try {
198
+ const res = await fetchImpl(mcpUrl, {
199
+ method: "POST",
200
+ headers: {
201
+ Accept: "application/json, text/event-stream",
202
+ "Content-Type": "application/json",
203
+ "MCP-Protocol-Version": "2025-06-18",
204
+ },
205
+ body: INIT_BODY,
206
+ signal: AbortSignal.timeout(4000),
207
+ });
208
+ if (res.status !== 401) return undefined;
209
+ return parseResourceMetadataUrl(res.headers.get("www-authenticate") ?? "");
210
+ } catch {
211
+ return undefined;
212
+ }
213
+ }
214
+
215
+ async function loadAuthorizationServerMetadata(
216
+ issuer: string,
217
+ fetchImpl: typeof fetch,
218
+ ): Promise<AuthorizationServerMetadata> {
219
+ for (const url of authorizationServerMetadataUrls(issuer)) {
220
+ const json = await getJson(url, fetchImpl);
221
+ if (!json) continue;
222
+ const authorization_endpoint =
223
+ typeof json.authorization_endpoint === "string" ? json.authorization_endpoint : "";
224
+ const token_endpoint = typeof json.token_endpoint === "string" ? json.token_endpoint : "";
225
+ if (!authorization_endpoint || !token_endpoint) continue;
226
+ return {
227
+ issuer: typeof json.issuer === "string" ? json.issuer : issuer,
228
+ authorization_endpoint,
229
+ token_endpoint,
230
+ registration_endpoint:
231
+ typeof json.registration_endpoint === "string" ? json.registration_endpoint : undefined,
232
+ code_challenge_methods_supported: stringList(json.code_challenge_methods_supported),
233
+ token_endpoint_auth_methods_supported: stringList(json.token_endpoint_auth_methods_supported),
234
+ };
235
+ }
236
+ throw new Error("Could not load authorization server metadata.");
237
+ }
238
+
239
+ export function isLoopbackRedirect(uri: string): boolean {
240
+ try {
241
+ const host = new URL(uri).hostname;
242
+ return host === "127.0.0.1" || host === "localhost" || host === "[::1]";
243
+ } catch {
244
+ return false;
245
+ }
246
+ }
247
+
248
+ export async function registerMcpClient(input: {
249
+ registrationUrl: string;
250
+ redirectUri: string;
251
+ clientName: string;
252
+ tokenEndpointAuthMethod?: "none" | "client_secret_post" | "client_secret_basic";
253
+ fetchImpl: typeof fetch;
254
+ }): Promise<DynamicClientRegistration> {
255
+ const tokenEndpointAuthMethod = input.tokenEndpointAuthMethod ?? "none";
256
+ const preferred: "native" | "web" = isLoopbackRedirect(input.redirectUri) ? "native" : "web";
257
+ const attempts: Array<"native" | "web"> =
258
+ preferred === "native" ? ["native", "web"] : ["web", "native"];
259
+ let lastStatus = 0;
260
+ let lastBody = "";
261
+ for (const applicationType of attempts) {
262
+ const res = await input.fetchImpl(input.registrationUrl, {
263
+ method: "POST",
264
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
265
+ body: JSON.stringify({
266
+ client_name: input.clientName,
267
+ redirect_uris: [input.redirectUri],
268
+ grant_types: ["authorization_code", "refresh_token"],
269
+ response_types: ["code"],
270
+ token_endpoint_auth_method: tokenEndpointAuthMethod,
271
+ application_type: applicationType,
272
+ }),
273
+ });
274
+ const raw = await res.text();
275
+ if (res.ok) return parseRegistration(raw);
276
+ lastStatus = res.status;
277
+ lastBody = raw;
278
+ if (res.status !== 400 && res.status !== 403) break;
279
+ }
280
+ throw new Error(registrationError(input.registrationUrl, lastStatus, lastBody));
281
+ }
282
+
283
+ function parseRegistration(raw: string): DynamicClientRegistration {
284
+ let json: { client_id?: string; client_secret?: string };
285
+ try {
286
+ json = JSON.parse(raw) as { client_id?: string; client_secret?: string };
287
+ } catch {
288
+ throw new Error("Client registration returned a non-JSON body.");
289
+ }
290
+ const clientId = json.client_id?.trim() ?? "";
291
+ if (!clientId) throw new Error("Authorization server did not return a client id.");
292
+ const clientSecret = json.client_secret?.trim() ?? "";
293
+ return {
294
+ clientId,
295
+ clientSecret,
296
+ tokenAuth: clientSecret ? "body" : "none",
297
+ };
298
+ }
299
+
300
+ function registrationError(registrationUrl: string, status: number, raw: string): string {
301
+ const snippet = raw.replace(/\s+/g, " ").trim().slice(0, 160);
302
+ if (/figma\.com/i.test(registrationUrl) && status === 403) {
303
+ return "Figma blocked client registration (403). Remote MCP only allows approved clients. Open Figma desktop, enable the Dev Mode MCP server, then Connect again.";
304
+ }
305
+ return snippet
306
+ ? `Client registration failed (${status}): ${snippet}`
307
+ : `Client registration failed (${status})`;
308
+ }
309
+
310
+ async function getJson(
311
+ url: string,
312
+ fetchImpl: typeof fetch,
313
+ ): Promise<Record<string, unknown> | null> {
314
+ try {
315
+ const res = await fetchImpl(url, { headers: { Accept: "application/json" } });
316
+ if (!res.ok) return null;
317
+ const json: unknown = await res.json();
318
+ return json && typeof json === "object" && !Array.isArray(json)
319
+ ? (json as Record<string, unknown>)
320
+ : null;
321
+ } catch {
322
+ return null;
323
+ }
324
+ }
325
+
326
+ function stringList(value: unknown): string[] | undefined {
327
+ if (!Array.isArray(value)) return undefined;
328
+ const out = value.filter((item): item is string => typeof item === "string");
329
+ return out.length > 0 ? out : undefined;
330
+ }
@@ -0,0 +1,77 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { mkdtemp, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { readProviderOAuth, writeProviderOAuth } from "./oauth-clients.ts";
6
+
7
+ describe("Google OAuth client", () => {
8
+ test("uses a Settings Desktop client id without a secret", async () => {
9
+ const home = await mkdtemp(join(tmpdir(), "harness-oauth-store-"));
10
+ const prevHome = process.env.HARNESS_HOME;
11
+ process.env.HARNESS_HOME = home;
12
+ try {
13
+ writeProviderOAuth("google", { clientId: "user.apps.googleusercontent.com" });
14
+ const env: Record<string, string | undefined> = { ...process.env, HARNESS_HOME: home };
15
+ delete env.CAELENCE_GOOGLE_OAUTH_CLIENT_ID;
16
+ delete env.GOOGLE_OAUTH_CLIENT_ID;
17
+ delete env.GOOGLE_CLIENT_ID;
18
+ expect(readProviderOAuth("google", env)).toEqual({
19
+ clientId: "user.apps.googleusercontent.com",
20
+ clientSecret: "",
21
+ });
22
+ } finally {
23
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
24
+ else process.env.HARNESS_HOME = prevHome;
25
+ await rm(home, { recursive: true, force: true });
26
+ }
27
+ });
28
+
29
+ test("uses a branded env client without a Settings paste", async () => {
30
+ const home = await mkdtemp(join(tmpdir(), "harness-oauth-env-"));
31
+ const prevHome = process.env.HARNESS_HOME;
32
+ process.env.HARNESS_HOME = home;
33
+ const env: Record<string, string | undefined> = {
34
+ ...process.env,
35
+ HARNESS_HOME: home,
36
+ CAELENCE_GOOGLE_OAUTH_CLIENT_ID: "caelence.apps.googleusercontent.com",
37
+ };
38
+ delete env.GOOGLE_OAUTH_CLIENT_ID;
39
+ delete env.GOOGLE_CLIENT_ID;
40
+ delete env.GOOGLE_CLIENT_SECRET;
41
+ delete env.CAELENCE_GOOGLE_OAUTH_CLIENT_SECRET;
42
+ try {
43
+ expect(readProviderOAuth("google", env)).toEqual({
44
+ clientId: "caelence.apps.googleusercontent.com",
45
+ clientSecret: "",
46
+ });
47
+ } finally {
48
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
49
+ else process.env.HARNESS_HOME = prevHome;
50
+ await rm(home, { recursive: true, force: true });
51
+ }
52
+ });
53
+
54
+ test("prefers a branded env client over a leftover Settings client", async () => {
55
+ const home = await mkdtemp(join(tmpdir(), "harness-oauth-pref-"));
56
+ const prevHome = process.env.HARNESS_HOME;
57
+ process.env.HARNESS_HOME = home;
58
+ try {
59
+ writeProviderOAuth("google", {
60
+ clientId: "legacy.apps.googleusercontent.com",
61
+ clientSecret: "s",
62
+ });
63
+ const env = {
64
+ ...process.env,
65
+ HARNESS_HOME: home,
66
+ CAELENCE_GOOGLE_OAUTH_CLIENT_ID: "caelence.apps.googleusercontent.com",
67
+ };
68
+ expect(readProviderOAuth("google", env)?.clientId).toBe(
69
+ "caelence.apps.googleusercontent.com",
70
+ );
71
+ } finally {
72
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
73
+ else process.env.HARNESS_HOME = prevHome;
74
+ await rm(home, { recursive: true, force: true });
75
+ }
76
+ });
77
+ });
@@ -0,0 +1,127 @@
1
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { harnessHome } from "../desktop/secrets.ts";
4
+
5
+ export type ProviderOAuthKind = "google" | "microsoft";
6
+
7
+ export interface ProviderOAuthClient {
8
+ clientId: string;
9
+ clientSecret: string;
10
+ }
11
+
12
+ interface StoreFile {
13
+ google?: ProviderOAuthClient;
14
+ microsoft?: ProviderOAuthClient;
15
+ }
16
+
17
+ /**
18
+ * Optional distributor Google OAuth client (Desktop app, PKCE, loopback).
19
+ * Official Caelence builds may set CAELENCE_GOOGLE_OAUTH_CLIENT_ID. Open-source
20
+ * builds leave this empty; each user pastes their own Desktop client id in Settings.
21
+ */
22
+ export const BUNDLED_GOOGLE_OAUTH_CLIENT_ID = "";
23
+
24
+ const GOOGLE_ID_ENV = [
25
+ "CAELENCE_GOOGLE_OAUTH_CLIENT_ID",
26
+ "GOOGLE_OAUTH_CLIENT_ID",
27
+ "GOOGLE_CLIENT_ID",
28
+ ] as const;
29
+
30
+ const GOOGLE_SECRET_ENV = [
31
+ "CAELENCE_GOOGLE_OAUTH_CLIENT_SECRET",
32
+ "GOOGLE_OAUTH_CLIENT_SECRET",
33
+ "GOOGLE_CLIENT_SECRET",
34
+ ] as const;
35
+
36
+ const ENV_KEYS: Record<ProviderOAuthKind, { id: string; secret: string }> = {
37
+ google: { id: "GOOGLE_OAUTH_CLIENT_ID", secret: "GOOGLE_OAUTH_CLIENT_SECRET" },
38
+ microsoft: { id: "MICROSOFT_OAUTH_CLIENT_ID", secret: "MICROSOFT_OAUTH_CLIENT_SECRET" },
39
+ };
40
+
41
+ export function oauthClientsPath(env: Record<string, string | undefined> = process.env): string {
42
+ return resolve(harnessHome(env), "oauth-clients.json");
43
+ }
44
+
45
+ function readStore(env: Record<string, string | undefined> = process.env): StoreFile {
46
+ const path = oauthClientsPath(env);
47
+ if (!existsSync(path)) return {};
48
+ try {
49
+ const parsed = JSON.parse(readFileSync(path, "utf8")) as StoreFile;
50
+ return parsed && typeof parsed === "object" ? parsed : {};
51
+ } catch {
52
+ return {};
53
+ }
54
+ }
55
+
56
+ function writeStore(store: StoreFile, env: Record<string, string | undefined> = process.env): void {
57
+ const path = oauthClientsPath(env);
58
+ mkdirSync(dirname(path), { recursive: true });
59
+ writeFileSync(path, `${JSON.stringify(store, null, "\t")}\n`, { encoding: "utf8", mode: 0o600 });
60
+ try {
61
+ chmodSync(path, 0o600);
62
+ } catch {
63
+ // best-effort on filesystems that ignore mode
64
+ }
65
+ }
66
+
67
+ function fromPair(
68
+ id: string | undefined,
69
+ secret: string | undefined,
70
+ ): ProviderOAuthClient | undefined {
71
+ const clientId = id?.trim() ?? "";
72
+ if (!clientId) return undefined;
73
+ return { clientId, clientSecret: secret?.trim() ?? "" };
74
+ }
75
+
76
+ function firstEnv(keys: readonly string[], env: Record<string, string | undefined>): string {
77
+ for (const key of keys) {
78
+ const value = env[key]?.trim();
79
+ if (value) return value;
80
+ }
81
+ return "";
82
+ }
83
+
84
+ export function readProviderOAuth(
85
+ kind: ProviderOAuthKind,
86
+ env: Record<string, string | undefined> = process.env,
87
+ ): ProviderOAuthClient | undefined {
88
+ if (kind === "google") {
89
+ const fromEnv = fromPair(firstEnv(GOOGLE_ID_ENV, env), firstEnv(GOOGLE_SECRET_ENV, env));
90
+ if (fromEnv) return fromEnv;
91
+ const stored = readStore(env).google;
92
+ const fromStore = fromPair(stored?.clientId, stored?.clientSecret);
93
+ if (fromStore) return fromStore;
94
+ return fromPair(BUNDLED_GOOGLE_OAUTH_CLIENT_ID, "");
95
+ }
96
+ const keys = ENV_KEYS[kind];
97
+ const fromEnv = fromPair(env[keys.id], env[keys.secret]);
98
+ if (fromEnv) return fromEnv;
99
+ const stored = readStore(env)[kind];
100
+ return fromPair(stored?.clientId, stored?.clientSecret);
101
+ }
102
+
103
+ export function writeProviderOAuth(
104
+ kind: ProviderOAuthKind,
105
+ patch: { clientId?: string; clientSecret?: string },
106
+ env: Record<string, string | undefined> = process.env,
107
+ ): void {
108
+ const store = readStore(env);
109
+ const prev = store[kind] ?? { clientId: "", clientSecret: "" };
110
+ const next: ProviderOAuthClient = {
111
+ clientId: patch.clientId?.trim() || prev.clientId,
112
+ clientSecret: patch.clientSecret?.trim() || prev.clientSecret,
113
+ };
114
+ if (!next.clientId && !next.clientSecret) {
115
+ delete store[kind];
116
+ } else {
117
+ store[kind] = next;
118
+ }
119
+ writeStore(store, env);
120
+ }
121
+
122
+ export function missingProviderClientMessage(kind: ProviderOAuthKind): string {
123
+ if (kind === "google") {
124
+ return "Google Workspace MCP has no dynamic client registration. Add a Desktop OAuth client id in Settings, then Connect.";
125
+ }
126
+ return "Microsoft MCP does not support one-click registration. Add an Entra app client id in Settings, then Connect.";
127
+ }