opencastle 0.38.2 → 1.0.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 (267) hide show
  1. package/README.md +81 -1
  2. package/bin/cli.mjs +20 -3
  3. package/dist/cli/adapters/antigravity.d.ts +1 -1
  4. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  5. package/dist/cli/adapters/claude-code.d.ts +1 -1
  6. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  7. package/dist/cli/adapters/codex.d.ts +1 -1
  8. package/dist/cli/adapters/codex.d.ts.map +1 -1
  9. package/dist/cli/adapters/cursor.d.ts +1 -1
  10. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  11. package/dist/cli/adapters/opencode.d.ts +1 -1
  12. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  13. package/dist/cli/adapters/rules-dir-base.d.ts +3 -2
  14. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  15. package/dist/cli/adapters/rules-dir-base.js +13 -25
  16. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  17. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  18. package/dist/cli/adapters/single-file-base.js +30 -43
  19. package/dist/cli/adapters/single-file-base.js.map +1 -1
  20. package/dist/cli/adapters/vscode.d.ts +3 -2
  21. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  22. package/dist/cli/adapters/vscode.js +19 -71
  23. package/dist/cli/adapters/vscode.js.map +1 -1
  24. package/dist/cli/adapters/windsurf.d.ts +1 -1
  25. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  26. package/dist/cli/baseline.d.ts +3 -0
  27. package/dist/cli/baseline.d.ts.map +1 -0
  28. package/dist/cli/baseline.js +280 -0
  29. package/dist/cli/baseline.js.map +1 -0
  30. package/dist/cli/ci.d.ts +18 -0
  31. package/dist/cli/ci.d.ts.map +1 -0
  32. package/dist/cli/ci.js +279 -0
  33. package/dist/cli/ci.js.map +1 -0
  34. package/dist/cli/dispatcher.test.js +2 -2
  35. package/dist/cli/dispatcher.test.js.map +1 -1
  36. package/dist/cli/docs-accuracy.test.js +5 -0
  37. package/dist/cli/docs-accuracy.test.js.map +1 -1
  38. package/dist/cli/doctor.d.ts +3 -3
  39. package/dist/cli/doctor.d.ts.map +1 -1
  40. package/dist/cli/doctor.js +66 -9
  41. package/dist/cli/doctor.js.map +1 -1
  42. package/dist/cli/explain.d.ts +3 -0
  43. package/dist/cli/explain.d.ts.map +1 -0
  44. package/dist/cli/explain.js +210 -0
  45. package/dist/cli/explain.js.map +1 -0
  46. package/dist/cli/fleet.d.ts +30 -0
  47. package/dist/cli/fleet.d.ts.map +1 -0
  48. package/dist/cli/fleet.js +149 -0
  49. package/dist/cli/fleet.js.map +1 -0
  50. package/dist/cli/github-report.d.ts +49 -0
  51. package/dist/cli/github-report.d.ts.map +1 -0
  52. package/dist/cli/github-report.js +161 -0
  53. package/dist/cli/github-report.js.map +1 -0
  54. package/dist/cli/github-report.test.d.ts +2 -0
  55. package/dist/cli/github-report.test.d.ts.map +1 -0
  56. package/dist/cli/github-report.test.js +146 -0
  57. package/dist/cli/github-report.test.js.map +1 -0
  58. package/dist/cli/init.d.ts.map +1 -1
  59. package/dist/cli/init.js +135 -94
  60. package/dist/cli/init.js.map +1 -1
  61. package/dist/cli/init.test.js +26 -25
  62. package/dist/cli/init.test.js.map +1 -1
  63. package/dist/cli/layers.d.ts +152 -0
  64. package/dist/cli/layers.d.ts.map +1 -0
  65. package/dist/cli/layers.js +932 -0
  66. package/dist/cli/layers.js.map +1 -0
  67. package/dist/cli/layers.test.d.ts +2 -0
  68. package/dist/cli/layers.test.d.ts.map +1 -0
  69. package/dist/cli/layers.test.js +483 -0
  70. package/dist/cli/layers.test.js.map +1 -0
  71. package/dist/cli/lock.d.ts +130 -0
  72. package/dist/cli/lock.d.ts.map +1 -0
  73. package/dist/cli/lock.js +320 -0
  74. package/dist/cli/lock.js.map +1 -0
  75. package/dist/cli/mcp-audit.d.ts +164 -0
  76. package/dist/cli/mcp-audit.d.ts.map +1 -0
  77. package/dist/cli/mcp-audit.js +504 -0
  78. package/dist/cli/mcp-audit.js.map +1 -0
  79. package/dist/cli/mcp-audit.test.d.ts +2 -0
  80. package/dist/cli/mcp-audit.test.d.ts.map +1 -0
  81. package/dist/cli/mcp-audit.test.js +215 -0
  82. package/dist/cli/mcp-audit.test.js.map +1 -0
  83. package/dist/cli/mcp-upgrade.test.d.ts +2 -0
  84. package/dist/cli/mcp-upgrade.test.d.ts.map +1 -0
  85. package/dist/cli/mcp-upgrade.test.js +118 -0
  86. package/dist/cli/mcp-upgrade.test.js.map +1 -0
  87. package/dist/cli/mcp.d.ts +74 -5
  88. package/dist/cli/mcp.d.ts.map +1 -1
  89. package/dist/cli/mcp.js +340 -32
  90. package/dist/cli/mcp.js.map +1 -1
  91. package/dist/cli/policy.d.ts +58 -0
  92. package/dist/cli/policy.d.ts.map +1 -0
  93. package/dist/cli/policy.js +194 -0
  94. package/dist/cli/policy.js.map +1 -0
  95. package/dist/cli/publish-workflow.test.js +55 -1
  96. package/dist/cli/publish-workflow.test.js.map +1 -1
  97. package/dist/cli/remove.d.ts.map +1 -1
  98. package/dist/cli/remove.js +3 -2
  99. package/dist/cli/remove.js.map +1 -1
  100. package/dist/cli/review.d.ts +25 -0
  101. package/dist/cli/review.d.ts.map +1 -0
  102. package/dist/cli/review.js +437 -0
  103. package/dist/cli/review.js.map +1 -0
  104. package/dist/cli/status.d.ts +2 -0
  105. package/dist/cli/status.d.ts.map +1 -1
  106. package/dist/cli/status.js +25 -4
  107. package/dist/cli/status.js.map +1 -1
  108. package/dist/cli/status.test.js +5 -3
  109. package/dist/cli/status.test.js.map +1 -1
  110. package/dist/cli/sync-check.d.ts +16 -1
  111. package/dist/cli/sync-check.d.ts.map +1 -1
  112. package/dist/cli/sync-check.js +219 -13
  113. package/dist/cli/sync-check.js.map +1 -1
  114. package/dist/cli/sync-check.test.js +14 -8
  115. package/dist/cli/sync-check.test.js.map +1 -1
  116. package/dist/cli/sync.d.ts.map +1 -1
  117. package/dist/cli/sync.js +2 -0
  118. package/dist/cli/sync.js.map +1 -1
  119. package/dist/cli/team-ci.test.d.ts +2 -0
  120. package/dist/cli/team-ci.test.d.ts.map +1 -0
  121. package/dist/cli/team-ci.test.js +169 -0
  122. package/dist/cli/team-ci.test.js.map +1 -0
  123. package/dist/cli/team-commands.test.d.ts +2 -0
  124. package/dist/cli/team-commands.test.d.ts.map +1 -0
  125. package/dist/cli/team-commands.test.js +233 -0
  126. package/dist/cli/team-commands.test.js.map +1 -0
  127. package/dist/cli/team-config.d.ts +88 -0
  128. package/dist/cli/team-config.d.ts.map +1 -0
  129. package/dist/cli/team-config.js +261 -0
  130. package/dist/cli/team-config.js.map +1 -0
  131. package/dist/cli/team-health.d.ts +49 -0
  132. package/dist/cli/team-health.d.ts.map +1 -0
  133. package/dist/cli/team-health.js +205 -0
  134. package/dist/cli/team-health.js.map +1 -0
  135. package/dist/cli/team-sources.test.d.ts +2 -0
  136. package/dist/cli/team-sources.test.d.ts.map +1 -0
  137. package/dist/cli/team-sources.test.js +542 -0
  138. package/dist/cli/team-sources.test.js.map +1 -0
  139. package/dist/cli/types.d.ts +16 -2
  140. package/dist/cli/types.d.ts.map +1 -1
  141. package/dist/cli/types.js.map +1 -1
  142. package/dist/cli/update.d.ts.map +1 -1
  143. package/dist/cli/update.js +204 -44
  144. package/dist/cli/update.js.map +1 -1
  145. package/dist/cli/version-range.d.ts +24 -0
  146. package/dist/cli/version-range.d.ts.map +1 -0
  147. package/dist/cli/version-range.js +157 -0
  148. package/dist/cli/version-range.js.map +1 -0
  149. package/dist/cli/website-plugins.test.d.ts +2 -0
  150. package/dist/cli/website-plugins.test.d.ts.map +1 -0
  151. package/dist/cli/website-plugins.test.js +34 -0
  152. package/dist/cli/website-plugins.test.js.map +1 -0
  153. package/dist/orchestrator/plugins/chrome-devtools/config.d.ts.map +1 -1
  154. package/dist/orchestrator/plugins/chrome-devtools/config.js +11 -1
  155. package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
  156. package/dist/orchestrator/plugins/contentful/config.d.ts.map +1 -1
  157. package/dist/orchestrator/plugins/contentful/config.js +11 -1
  158. package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
  159. package/dist/orchestrator/plugins/convex/config.d.ts.map +1 -1
  160. package/dist/orchestrator/plugins/convex/config.js +11 -1
  161. package/dist/orchestrator/plugins/convex/config.js.map +1 -1
  162. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  163. package/dist/orchestrator/plugins/coolify/config.js +14 -1
  164. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  165. package/dist/orchestrator/plugins/figma/config.d.ts.map +1 -1
  166. package/dist/orchestrator/plugins/figma/config.js +24 -13
  167. package/dist/orchestrator/plugins/figma/config.js.map +1 -1
  168. package/dist/orchestrator/plugins/linear/config.d.ts.map +1 -1
  169. package/dist/orchestrator/plugins/linear/config.js +27 -17
  170. package/dist/orchestrator/plugins/linear/config.js.map +1 -1
  171. package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
  172. package/dist/orchestrator/plugins/netlify/config.js +23 -9
  173. package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
  174. package/dist/orchestrator/plugins/nextjs/config.d.ts.map +1 -1
  175. package/dist/orchestrator/plugins/nextjs/config.js +11 -1
  176. package/dist/orchestrator/plugins/nextjs/config.js.map +1 -1
  177. package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
  178. package/dist/orchestrator/plugins/nx/config.js +11 -1
  179. package/dist/orchestrator/plugins/nx/config.js.map +1 -1
  180. package/dist/orchestrator/plugins/pins.test.d.ts +2 -0
  181. package/dist/orchestrator/plugins/pins.test.d.ts.map +1 -0
  182. package/dist/orchestrator/plugins/pins.test.js +78 -0
  183. package/dist/orchestrator/plugins/pins.test.js.map +1 -0
  184. package/dist/orchestrator/plugins/playwright/config.d.ts.map +1 -1
  185. package/dist/orchestrator/plugins/playwright/config.js +11 -1
  186. package/dist/orchestrator/plugins/playwright/config.js.map +1 -1
  187. package/dist/orchestrator/plugins/prisma/config.d.ts.map +1 -1
  188. package/dist/orchestrator/plugins/prisma/config.js +17 -2
  189. package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
  190. package/dist/orchestrator/plugins/resend/config.d.ts.map +1 -1
  191. package/dist/orchestrator/plugins/resend/config.js +17 -1
  192. package/dist/orchestrator/plugins/resend/config.js.map +1 -1
  193. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  194. package/dist/orchestrator/plugins/sentry/config.js +13 -1
  195. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  196. package/dist/orchestrator/plugins/slack/config.d.ts.map +1 -1
  197. package/dist/orchestrator/plugins/slack/config.js +20 -1
  198. package/dist/orchestrator/plugins/slack/config.js.map +1 -1
  199. package/dist/orchestrator/plugins/strapi/config.d.ts.map +1 -1
  200. package/dist/orchestrator/plugins/strapi/config.js +11 -1
  201. package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
  202. package/dist/orchestrator/plugins/trello/config.d.ts.map +1 -1
  203. package/dist/orchestrator/plugins/trello/config.js +21 -1
  204. package/dist/orchestrator/plugins/trello/config.js.map +1 -1
  205. package/dist/orchestrator/plugins/types.d.ts +22 -0
  206. package/dist/orchestrator/plugins/types.d.ts.map +1 -1
  207. package/package.json +3 -1
  208. package/src/cli/adapters/rules-dir-base.ts +23 -44
  209. package/src/cli/adapters/single-file-base.ts +43 -46
  210. package/src/cli/adapters/vscode.ts +28 -71
  211. package/src/cli/baseline.ts +289 -0
  212. package/src/cli/ci.ts +289 -0
  213. package/src/cli/dispatcher.test.ts +2 -2
  214. package/src/cli/docs-accuracy.test.ts +5 -0
  215. package/src/cli/doctor.ts +92 -6
  216. package/src/cli/explain.ts +210 -0
  217. package/src/cli/fleet.ts +176 -0
  218. package/src/cli/github-report.test.ts +158 -0
  219. package/src/cli/github-report.ts +179 -0
  220. package/src/cli/init.test.ts +27 -27
  221. package/src/cli/init.ts +135 -93
  222. package/src/cli/layers.test.ts +525 -0
  223. package/src/cli/layers.ts +1089 -0
  224. package/src/cli/lock.ts +395 -0
  225. package/src/cli/mcp-audit.test.ts +259 -0
  226. package/src/cli/mcp-audit.ts +619 -0
  227. package/src/cli/mcp-upgrade.test.ts +135 -0
  228. package/src/cli/mcp.ts +373 -34
  229. package/src/cli/policy.ts +207 -0
  230. package/src/cli/publish-workflow.test.ts +60 -1
  231. package/src/cli/remove.ts +8 -2
  232. package/src/cli/review.ts +457 -0
  233. package/src/cli/status.test.ts +5 -3
  234. package/src/cli/status.ts +29 -4
  235. package/src/cli/sync-check.test.ts +16 -8
  236. package/src/cli/sync-check.ts +245 -14
  237. package/src/cli/sync.ts +2 -0
  238. package/src/cli/team-ci.test.ts +195 -0
  239. package/src/cli/team-commands.test.ts +253 -0
  240. package/src/cli/team-config.ts +289 -0
  241. package/src/cli/team-health.ts +234 -0
  242. package/src/cli/team-sources.test.ts +578 -0
  243. package/src/cli/types.ts +19 -1
  244. package/src/cli/update.ts +217 -44
  245. package/src/cli/version-range.ts +150 -0
  246. package/src/cli/website-plugins.test.ts +41 -0
  247. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  248. package/src/orchestrator/plugins/chrome-devtools/config.ts +11 -1
  249. package/src/orchestrator/plugins/contentful/config.ts +11 -1
  250. package/src/orchestrator/plugins/convex/config.ts +11 -1
  251. package/src/orchestrator/plugins/coolify/config.ts +14 -1
  252. package/src/orchestrator/plugins/figma/SKILL.md +18 -14
  253. package/src/orchestrator/plugins/figma/config.ts +24 -13
  254. package/src/orchestrator/plugins/linear/SKILL.md +6 -14
  255. package/src/orchestrator/plugins/linear/config.ts +27 -17
  256. package/src/orchestrator/plugins/netlify/config.ts +23 -9
  257. package/src/orchestrator/plugins/nextjs/config.ts +11 -1
  258. package/src/orchestrator/plugins/nx/config.ts +11 -1
  259. package/src/orchestrator/plugins/pins.test.ts +80 -0
  260. package/src/orchestrator/plugins/playwright/config.ts +11 -1
  261. package/src/orchestrator/plugins/prisma/config.ts +17 -2
  262. package/src/orchestrator/plugins/resend/config.ts +17 -1
  263. package/src/orchestrator/plugins/sentry/config.ts +13 -1
  264. package/src/orchestrator/plugins/slack/config.ts +20 -1
  265. package/src/orchestrator/plugins/strapi/config.ts +11 -1
  266. package/src/orchestrator/plugins/trello/config.ts +21 -1
  267. package/src/orchestrator/plugins/types.ts +24 -0
@@ -0,0 +1,207 @@
1
+ /**
2
+ * The rules a team's layers hold MCP servers to, in one place for the two
3
+ * readers that apply them: source resolution, which refuses to compile a
4
+ * server the policy forbids, and the audit, which reads what is actually in
5
+ * each target's config — including servers somebody added by hand.
6
+ */
7
+
8
+ export interface EffectivePolicy {
9
+ /** Every layer's allowlist; a server must be on all of them. */
10
+ allowLists: Array<{ by: string; where: string; patterns: string[] }>
11
+ hostLists: Array<{ by: string; where: string; patterns: string[] }>
12
+ /** The layer that turned it on, if one did. It cannot be turned off above. */
13
+ requirePinned?: string
14
+ require: Array<{ ref: string; by: string }>
15
+ contextBudget?: { tokens: number; by: string }
16
+ versionRanges: Array<{ range: string; by: string; where: string }>
17
+ }
18
+
19
+ export function emptyPolicy(): EffectivePolicy {
20
+ return { allowLists: [], hostLists: [], require: [], versionRanges: [] }
21
+ }
22
+
23
+ /** `*` matches any run of characters; everything else is literal. */
24
+ export function globMatch(pattern: string, value: string): boolean {
25
+ const re = new RegExp(`^${pattern.split('*').map((s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('.*')}$`)
26
+ return re.test(value)
27
+ }
28
+
29
+ /** `*.acme.dev` matches any subdomain of acme.dev; anything else must match exactly. */
30
+ function hostMatches(pattern: string, host: string): boolean {
31
+ const p = pattern.toLowerCase()
32
+ const h = host.toLowerCase()
33
+ if (p.startsWith('*.')) return h.endsWith(p.slice(1)) && h.length > p.length - 1
34
+ return p === h
35
+ }
36
+
37
+ /** The layers whose allowlist refuses a server key, or null when it is allowed. */
38
+ export function disallowedBy(policy: EffectivePolicy, key: string): string | null {
39
+ const refusing = policy.allowLists.filter((l) => !l.patterns.some((p) => globMatch(p, key)))
40
+ return refusing.length > 0 ? refusing.map((l) => l.by).join(', ') : null
41
+ }
42
+
43
+ /**
44
+ * A URL's host, and only its host. Messages name this and never the URL: a
45
+ * query string can carry a credential, and printing it to say the host is not
46
+ * allowed would leak it into terminals, CI logs and pull request annotations.
47
+ */
48
+ export function hostOfUrl(url: string): string {
49
+ try {
50
+ return new URL(url.replace(/\$\{[^}]*\}|\{env:[^}]*\}/g, 'x')).hostname
51
+ } catch {
52
+ return '(an unreadable URL)'
53
+ }
54
+ }
55
+
56
+ /** Whether one list of host patterns allows a URL. */
57
+ export function hostAllowedBy(patterns: string[], url: string): boolean {
58
+ let host: string
59
+ try {
60
+ host = new URL(url.replace(/\$\{[^}]*\}|\{env:[^}]*\}/g, 'x')).hostname
61
+ } catch {
62
+ return false
63
+ }
64
+ return patterns.some((p) => hostMatches(p, host))
65
+ }
66
+
67
+ /** The layers that refuse a remote URL's host, or null when it is allowed. */
68
+ export function hostDisallowedBy(policy: EffectivePolicy, url: string): string | null {
69
+ const refusing = policy.hostLists.filter((l) => !hostAllowedBy(l.patterns, url))
70
+ return refusing.length > 0 ? refusing.map((l) => l.by).join(', ') : null
71
+ }
72
+
73
+ // ── Credentials written into a config ──────────────────────────
74
+
75
+ /**
76
+ * Formats real tokens take. Deliberately specific: a false "you committed a
77
+ * secret" on an ordinary value teaches people to ignore the check.
78
+ */
79
+ const TOKEN_FORMATS = new RegExp(
80
+ '^(?:' +
81
+ [
82
+ 'sk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}',
83
+ 'sk_(?:live|test)_[A-Za-z0-9]{16,}',
84
+ 'rk_(?:live|test)_[A-Za-z0-9]{16,}',
85
+ 'whsec_[A-Za-z0-9]{24,}',
86
+ 'gh[pousr]_[A-Za-z0-9]{30,}',
87
+ 'github_pat_[A-Za-z0-9_]{30,}',
88
+ 'glpat-[A-Za-z0-9_-]{20,}',
89
+ 'npm_[A-Za-z0-9]{36}',
90
+ 'hf_[A-Za-z0-9]{30,}',
91
+ 'sbp_[a-f0-9]{40}',
92
+ 'shpat_[a-f0-9]{32}',
93
+ 'dop_v1_[a-f0-9]{64}',
94
+ 'xox[abeprs]-[A-Za-z0-9-]{10,}',
95
+ 'AKIA[0-9A-Z]{16}',
96
+ 'lin_(?:api|oauth)_[A-Za-z0-9]{20,}',
97
+ 'sntry[su]_[A-Za-z0-9+/=_-]{20,}',
98
+ 'figd_[A-Za-z0-9_-]{20,}',
99
+ 'ntn_[A-Za-z0-9]{20,}',
100
+ 're_[A-Za-z0-9]{8,}_[A-Za-z0-9]{16,}',
101
+ 'AIza[0-9A-Za-z_-]{35}',
102
+ 'eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}',
103
+ ].join('|') +
104
+ ')',
105
+ )
106
+
107
+ /**
108
+ * Names that say "this value is a credential". `auth` and `key` only as whole
109
+ * words: `OAUTH_CLIENT_ID` is an identifier and `AUTH_MODE` a setting, and
110
+ * flagging them stopped a compile over nothing secret.
111
+ */
112
+ const SECRET_NAME = /(token|secret|password|passwd|pwd|api[_-]?key|access[_-]?key|private[_-]?key|credential|authorization|(^|[_-])auth$|(^|[_-])key$)/i
113
+
114
+ /** Names that end like a pointer to a secret, not the secret itself. */
115
+ const NOT_A_SECRET = /[_-](id|mode|url|uri|file|path|dir|region|name|sha|hash|type|endpoint|host|port|user|username|header|scheme)$/i
116
+
117
+ /** Keys that are public by design, or not credentials at all. */
118
+ const PUBLIC_KEY = /(publishable|public|site|search|idempotency|cache|partition|sort|primary)[_-]?key$/i
119
+
120
+ const PLACEHOLDER = /^(?:replace[_-]?me|change[_-]?me|your[_-].*|<[^>]*>|x{3,}|\*+|todo|tbd|null|none|true|false|\d{1,6})$/i
121
+
122
+ /** `${NAME}`, `${env:NAME}`, `{env:NAME}`, `{file:…}` anywhere; `$NAME` only as the whole value. */
123
+ function isReference(value: string): boolean {
124
+ return /\$\{[^}]+\}|\{env:[^}]+\}|\{file:[^}]+\}/.test(value) || /^\$[A-Za-z_][A-Za-z0-9_]*$/.test(value)
125
+ }
126
+
127
+ /** A value that could be a credential: long, no spaces, letters and digits, not a path or URL. */
128
+ function looksRandom(value: string): boolean {
129
+ return (
130
+ value.length >= 16 &&
131
+ !/\s/.test(value) &&
132
+ /[A-Za-z]/.test(value) &&
133
+ /\d/.test(value) &&
134
+ !/^(?:https?:|\/|\.|~|[A-Za-z]:\\)/.test(value) &&
135
+ // A relative path to a file — `secrets/token.txt` — not base64, which can
136
+ // hold `/` too: an AWS secret key often does.
137
+ !/^[A-Za-z0-9_.-]+(\/[A-Za-z0-9_.-]+)*\/[A-Za-z0-9_-]+\.[A-Za-z0-9]{1,5}$/.test(value)
138
+ )
139
+ }
140
+
141
+ /** A URL with a password in it: `postgres://user:pass@host/db`. */
142
+ function urlWithPassword(value: string): boolean {
143
+ if (isReference(value)) return false
144
+ try {
145
+ const u = new URL(value)
146
+ return Boolean(u.password) && !isReference(decodeURIComponent(u.password))
147
+ } catch {
148
+ return false
149
+ }
150
+ }
151
+
152
+ function isSecretValue(name: string, raw: string): boolean {
153
+ const value = raw.replace(/^(?:Bearer|Basic|Token|token)\s+/, '').trim()
154
+ if (value === '' || isReference(value) || PLACEHOLDER.test(value)) return false
155
+ if (TOKEN_FORMATS.test(value)) return true
156
+ if (urlWithPassword(value)) return true
157
+ // Anything written into an Authorization header is the credential itself.
158
+ if (/^authorization$/i.test(name)) return value.length >= 8
159
+ if (NOT_A_SECRET.test(name) || PUBLIC_KEY.test(name)) return false
160
+ return SECRET_NAME.test(name) && looksRandom(value)
161
+ }
162
+
163
+ /**
164
+ * Where a server entry holds a credential written out in full, or null.
165
+ *
166
+ * Returns the location only (`env.API_KEY`, `headers.Authorization`, `args`,
167
+ * `url`), never the value: this is printed, and printing the secret to say it
168
+ * should not be visible would be its own leak.
169
+ */
170
+ export function findInlineSecret(entry: Record<string, unknown>): string | null {
171
+ for (const field of ['env', 'environment', 'headers']) {
172
+ const block = entry[field]
173
+ if (!block || typeof block !== 'object' || Array.isArray(block)) continue
174
+ for (const [name, value] of Object.entries(block as Record<string, unknown>)) {
175
+ if (typeof value === 'string' && isSecretValue(name, value)) return `${field}.${name}`
176
+ }
177
+ }
178
+ const command = entry.command
179
+ const args: unknown[] = Array.isArray(command)
180
+ ? command.slice(1)
181
+ : Array.isArray(entry.args)
182
+ ? (entry.args as unknown[])
183
+ : []
184
+ for (let i = 0; i < args.length; i++) {
185
+ const arg = args[i]
186
+ if (typeof arg !== 'string') continue
187
+ const eq = /^--?([A-Za-z0-9_-]+)=(.+)$/.exec(arg)
188
+ if (eq && isSecretValue(eq[1], eq[2])) return 'args'
189
+ const flag = /^--?([A-Za-z0-9_-]+)$/.exec(arg)
190
+ const next = args[i + 1]
191
+ if (flag && SECRET_NAME.test(flag[1]) && typeof next === 'string' && isSecretValue(flag[1], next)) return 'args'
192
+ if (!arg.startsWith('-') && !isReference(arg) && TOKEN_FORMATS.test(arg)) return 'args'
193
+ }
194
+ const url = entry.url ?? entry.serverUrl
195
+ if (typeof url === 'string') {
196
+ try {
197
+ const parsed = new URL(url.replace(/\$\{[^}]*\}|\{env:[^}]*\}/g, 'x'))
198
+ for (const [name, value] of parsed.searchParams) {
199
+ if (isSecretValue(name, value)) return 'url'
200
+ }
201
+ if (parsed.password) return 'url'
202
+ } catch {
203
+ // Not a URL we can read; nothing to say about it.
204
+ }
205
+ }
206
+ return null
207
+ }
@@ -1,4 +1,6 @@
1
- import { readFileSync } from 'node:fs'
1
+ import { execFileSync } from 'node:child_process'
2
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
2
4
  import { join } from 'node:path'
3
5
  import { describe, it, expect } from 'vitest'
4
6
  import { parse as yamlParse } from 'yaml'
@@ -84,3 +86,60 @@ describe('the publish workflow', () => {
84
86
  expect(toBranch, `pushes a branch the ruleset will reject: ${toBranch.join(', ')}`).toEqual([])
85
87
  })
86
88
  })
89
+
90
+ /**
91
+ * The version a merge releases, from the step that decides it, run for real in
92
+ * a scratch repository: a package.json and, optionally, the last release tag.
93
+ */
94
+ describe('the version a release takes', () => {
95
+ const step = steps.find(s => s.name === 'Determine next version')
96
+ const script = step?.run ?? ''
97
+
98
+ function release(pkgVersion: string, lastTag: string | null, bump: 'major' | 'minor' | 'patch'): string {
99
+ const dir = mkdtempSync(join(tmpdir(), 'oc-release-'))
100
+ try {
101
+ const git = (...args: string[]): void => {
102
+ execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@example.com', '-c', 'commit.gpgsign=false', ...args], { cwd: dir, stdio: 'ignore' })
103
+ }
104
+ writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'scratch', version: pkgVersion }, null, 2) + '\n')
105
+ git('init', '-q')
106
+ git('add', '.')
107
+ git('commit', '-q', '-m', 'release')
108
+ if (lastTag) git('tag', lastTag)
109
+ const output = join(dir, 'github-output')
110
+ writeFileSync(output, '')
111
+ execFileSync('bash', ['-e', '-c', script.replaceAll('${{ steps.bump.outputs.type }}', bump)], {
112
+ cwd: dir,
113
+ env: { ...process.env, GITHUB_OUTPUT: output },
114
+ stdio: 'ignore',
115
+ })
116
+ return /^new=(.*)$/m.exec(readFileSync(output, 'utf8'))?.[1] ?? ''
117
+ } finally {
118
+ rmSync(dir, { recursive: true, force: true })
119
+ }
120
+ }
121
+
122
+ it('exists', () => {
123
+ expect(script).toMatch(/npm version/)
124
+ })
125
+
126
+ it('ships a version a PR wrote by hand exactly as written', () => {
127
+ // A minor bump on top of it would turn the 1.0.0 the PR asked for into 1.1.0.
128
+ expect(release('1.0.0', 'v0.38.2', 'minor')).toBe('v1.0.0')
129
+ expect(release('1.0.0', 'v0.38.2', 'major')).toBe('v1.0.0')
130
+ })
131
+
132
+ it('bumps the last tag when package.json trails it', () => {
133
+ expect(release('0.35.3', 'v0.38.2', 'minor')).toBe('v0.39.0')
134
+ expect(release('0.35.3', 'v0.38.2', 'patch')).toBe('v0.38.3')
135
+ })
136
+
137
+ it('bumps the last tag once package.json has caught up with it', () => {
138
+ expect(release('1.0.0', 'v1.0.0', 'patch')).toBe('v1.0.1')
139
+ expect(release('1.0.0', 'v1.0.0', 'major')).toBe('v2.0.0')
140
+ })
141
+
142
+ it('bumps package.json when nothing has been tagged yet', () => {
143
+ expect(release('0.1.0', null, 'patch')).toBe('v0.1.1')
144
+ })
145
+ })
package/src/cli/remove.ts CHANGED
@@ -8,6 +8,7 @@ import { confirm, select, closePrompts, c } from './prompt.js'
8
8
  import { stripManagedBlockFromFile, predictStripFile } from './managed-block.js'
9
9
  import { resolveManagedPaths } from './managed-paths.js'
10
10
  import { stripManagedMcpServers, getMcpConfigRelPath, willKeepSomethingAfterStrip } from './mcp.js'
11
+ import { priorTeam } from './lock.js'
11
12
  import { IDE_ADAPTERS } from './adapters/index.js'
12
13
  import type { CliContext, IdeChoice } from './types.js'
13
14
 
@@ -106,7 +107,7 @@ async function previewCoOwned(
106
107
  const parsed = JSON.parse(await readFile(abs, 'utf8')) as Record<string, unknown>
107
108
  // Captured before the predicate runs — it edits `parsed` in place.
108
109
  const untouched = JSON.stringify(parsed)
109
- keepsSomething = willKeepSomethingAfterStrip(parsed, ideFor.get(p))
110
+ keepsSomething = willKeepSomethingAfterStrip(parsed, ideFor.get(p), ...priorTeam(projectRoot))
110
111
  tookAnything = JSON.stringify(parsed) !== untouched
111
112
  } catch {
112
113
  // Unreadable JSON is left alone entirely, so it certainly survives.
@@ -351,7 +352,12 @@ export default async function remove({ args }: CliContext): Promise<void> {
351
352
  // the file.
352
353
  const unreadable: string[] = []
353
354
  for (const ide of ides) {
354
- const outcome = await stripManagedMcpServers(projectRoot, ide, createdConfigs.has(getMcpConfigRelPath(ide)))
355
+ const outcome = await stripManagedMcpServers(
356
+ projectRoot,
357
+ ide,
358
+ createdConfigs.has(getMcpConfigRelPath(ide)),
359
+ ...priorTeam(projectRoot),
360
+ )
355
361
  if (outcome === 'deleted') removed++
356
362
  else if (outcome === 'stripped') stripped++
357
363
  else if (outcome === 'unreadable') unreadable.push(getMcpConfigRelPath(ide))