wicked-crew 0.18.21 → 0.18.22

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 (255) hide show
  1. package/dist/api/audit.d.ts +28 -1
  2. package/dist/api/audit.d.ts.map +1 -1
  3. package/dist/api/audit.js +90 -9
  4. package/dist/api/audit.js.map +1 -1
  5. package/dist/api/auth.d.ts +7 -0
  6. package/dist/api/auth.d.ts.map +1 -1
  7. package/dist/api/auth.js +53 -10
  8. package/dist/api/auth.js.map +1 -1
  9. package/dist/api/capture.d.ts +11 -2
  10. package/dist/api/capture.d.ts.map +1 -1
  11. package/dist/api/capture.js +7 -2
  12. package/dist/api/capture.js.map +1 -1
  13. package/dist/api/chat-context.d.ts +6 -1
  14. package/dist/api/chat-context.d.ts.map +1 -1
  15. package/dist/api/chat-context.js +45 -11
  16. package/dist/api/chat-context.js.map +1 -1
  17. package/dist/api/chat-proposals.d.ts +24 -7
  18. package/dist/api/chat-proposals.d.ts.map +1 -1
  19. package/dist/api/chat-proposals.js +98 -18
  20. package/dist/api/chat-proposals.js.map +1 -1
  21. package/dist/api/chat-scope.d.ts +6 -2
  22. package/dist/api/chat-scope.d.ts.map +1 -1
  23. package/dist/api/chat-scope.js +13 -7
  24. package/dist/api/chat-scope.js.map +1 -1
  25. package/dist/api/cluster-status.d.ts +17 -0
  26. package/dist/api/cluster-status.d.ts.map +1 -1
  27. package/dist/api/cluster-status.js +70 -3
  28. package/dist/api/cluster-status.js.map +1 -1
  29. package/dist/api/compose-facts.d.ts +35 -0
  30. package/dist/api/compose-facts.d.ts.map +1 -0
  31. package/dist/api/compose-facts.js +46 -0
  32. package/dist/api/compose-facts.js.map +1 -0
  33. package/dist/api/cut-read.d.ts +62 -0
  34. package/dist/api/cut-read.d.ts.map +1 -0
  35. package/dist/api/cut-read.js +101 -0
  36. package/dist/api/cut-read.js.map +1 -0
  37. package/dist/api/desk-snoozes.d.ts +54 -0
  38. package/dist/api/desk-snoozes.d.ts.map +1 -0
  39. package/dist/api/desk-snoozes.js +174 -0
  40. package/dist/api/desk-snoozes.js.map +1 -0
  41. package/dist/api/diagnostics.d.ts +4 -0
  42. package/dist/api/diagnostics.d.ts.map +1 -1
  43. package/dist/api/diagnostics.js +15 -7
  44. package/dist/api/diagnostics.js.map +1 -1
  45. package/dist/api/disk-stores.d.ts +66 -0
  46. package/dist/api/disk-stores.d.ts.map +1 -0
  47. package/dist/api/disk-stores.js +206 -0
  48. package/dist/api/disk-stores.js.map +1 -0
  49. package/dist/api/gate-cache.d.ts +8 -0
  50. package/dist/api/gate-cache.d.ts.map +1 -1
  51. package/dist/api/gate-cache.js +8 -1
  52. package/dist/api/gate-cache.js.map +1 -1
  53. package/dist/api/mcp.d.ts +16 -0
  54. package/dist/api/mcp.d.ts.map +1 -1
  55. package/dist/api/mcp.js +118 -1
  56. package/dist/api/mcp.js.map +1 -1
  57. package/dist/api/needs.d.ts +3 -0
  58. package/dist/api/needs.d.ts.map +1 -1
  59. package/dist/api/needs.js +7 -3
  60. package/dist/api/needs.js.map +1 -1
  61. package/dist/api/post-hoc-deliver.d.ts +7 -0
  62. package/dist/api/post-hoc-deliver.d.ts.map +1 -1
  63. package/dist/api/post-hoc-deliver.js +16 -5
  64. package/dist/api/post-hoc-deliver.js.map +1 -1
  65. package/dist/api/product-publish.d.ts +242 -0
  66. package/dist/api/product-publish.d.ts.map +1 -0
  67. package/dist/api/product-publish.js +902 -0
  68. package/dist/api/product-publish.js.map +1 -0
  69. package/dist/api/product.d.ts +5 -6
  70. package/dist/api/product.d.ts.map +1 -1
  71. package/dist/api/product.js +4 -4
  72. package/dist/api/product.js.map +1 -1
  73. package/dist/api/proposal-cut.d.ts +95 -0
  74. package/dist/api/proposal-cut.d.ts.map +1 -0
  75. package/dist/api/proposal-cut.js +231 -0
  76. package/dist/api/proposal-cut.js.map +1 -0
  77. package/dist/api/requirements.d.ts +3 -3
  78. package/dist/api/requirements.js +3 -3
  79. package/dist/api/routes.d.ts +15 -0
  80. package/dist/api/routes.d.ts.map +1 -1
  81. package/dist/api/routes.js +410 -88
  82. package/dist/api/routes.js.map +1 -1
  83. package/dist/api/run-liveness.d.ts.map +1 -1
  84. package/dist/api/run-liveness.js +3 -1
  85. package/dist/api/run-liveness.js.map +1 -1
  86. package/dist/api/run-timing-index.d.ts +10 -0
  87. package/dist/api/run-timing-index.d.ts.map +1 -1
  88. package/dist/api/run-timing-index.js +29 -9
  89. package/dist/api/run-timing-index.js.map +1 -1
  90. package/dist/api/seat-container-login.d.ts +11 -17
  91. package/dist/api/seat-container-login.d.ts.map +1 -1
  92. package/dist/api/seat-container-login.js +36 -69
  93. package/dist/api/seat-container-login.js.map +1 -1
  94. package/dist/api/system-snapshot.d.ts +2 -1
  95. package/dist/api/system-snapshot.d.ts.map +1 -1
  96. package/dist/api/system-snapshot.js +17 -6
  97. package/dist/api/system-snapshot.js.map +1 -1
  98. package/dist/api/ui-text.d.ts.map +1 -1
  99. package/dist/api/ui-text.js +3 -1
  100. package/dist/api/ui-text.js.map +1 -1
  101. package/dist/apps/store.d.ts +11 -0
  102. package/dist/apps/store.d.ts.map +1 -1
  103. package/dist/apps/store.js +47 -0
  104. package/dist/apps/store.js.map +1 -1
  105. package/dist/apps-server/server/lib/bundle/server.mjs +12 -2
  106. package/dist/cli/index.d.ts.map +1 -1
  107. package/dist/cli/index.js +27 -52
  108. package/dist/cli/index.js.map +1 -1
  109. package/dist/cli/start-stand-ins.d.ts +13 -0
  110. package/dist/cli/start-stand-ins.d.ts.map +1 -0
  111. package/dist/cli/start-stand-ins.js +30 -0
  112. package/dist/cli/start-stand-ins.js.map +1 -0
  113. package/dist/core/adapter.d.ts +43 -6
  114. package/dist/core/adapter.d.ts.map +1 -1
  115. package/dist/core/adapter.js +169 -30
  116. package/dist/core/adapter.js.map +1 -1
  117. package/dist/core/ado-env.d.ts +17 -0
  118. package/dist/core/ado-env.d.ts.map +1 -0
  119. package/dist/core/ado-env.js +34 -0
  120. package/dist/core/ado-env.js.map +1 -0
  121. package/dist/core/deliver-text.d.ts +17 -0
  122. package/dist/core/deliver-text.d.ts.map +1 -1
  123. package/dist/core/deliver-text.js +76 -1
  124. package/dist/core/deliver-text.js.map +1 -1
  125. package/dist/core/deliver.d.ts +6 -0
  126. package/dist/core/deliver.d.ts.map +1 -1
  127. package/dist/core/deliver.js +12 -4
  128. package/dist/core/deliver.js.map +1 -1
  129. package/dist/core/exec.d.ts +1 -10
  130. package/dist/core/exec.d.ts.map +1 -1
  131. package/dist/core/exec.js +4 -17
  132. package/dist/core/exec.js.map +1 -1
  133. package/dist/core/governance-store.d.ts +3 -1
  134. package/dist/core/governance-store.d.ts.map +1 -1
  135. package/dist/core/governance-store.js +7 -2
  136. package/dist/core/governance-store.js.map +1 -1
  137. package/dist/core/repo-clone.d.ts.map +1 -1
  138. package/dist/core/repo-clone.js +2 -1
  139. package/dist/core/repo-clone.js.map +1 -1
  140. package/dist/core/run-log-facts.d.ts +56 -0
  141. package/dist/core/run-log-facts.d.ts.map +1 -0
  142. package/dist/core/run-log-facts.js +230 -0
  143. package/dist/core/run-log-facts.js.map +1 -0
  144. package/dist/core/shutdown.d.ts +27 -0
  145. package/dist/core/shutdown.d.ts.map +1 -1
  146. package/dist/core/shutdown.js +72 -0
  147. package/dist/core/shutdown.js.map +1 -1
  148. package/dist/core/stand-in.d.ts +40 -0
  149. package/dist/core/stand-in.d.ts.map +1 -0
  150. package/dist/core/stand-in.js +118 -0
  151. package/dist/core/stand-in.js.map +1 -0
  152. package/dist/core/types.d.ts +17 -0
  153. package/dist/core/types.d.ts.map +1 -1
  154. package/dist/core/types.js.map +1 -1
  155. package/dist/editors/pack-extras.d.ts +162 -0
  156. package/dist/editors/pack-extras.d.ts.map +1 -0
  157. package/dist/editors/pack-extras.js +596 -0
  158. package/dist/editors/pack-extras.js.map +1 -0
  159. package/dist/editors/pack-install.d.ts +15 -7
  160. package/dist/editors/pack-install.d.ts.map +1 -1
  161. package/dist/editors/pack-install.js +140 -19
  162. package/dist/editors/pack-install.js.map +1 -1
  163. package/dist/editors/registry.d.ts +42 -3
  164. package/dist/editors/registry.d.ts.map +1 -1
  165. package/dist/editors/registry.js +114 -11
  166. package/dist/editors/registry.js.map +1 -1
  167. package/dist/editors/routes.d.ts +10 -5
  168. package/dist/editors/routes.d.ts.map +1 -1
  169. package/dist/editors/routes.js +45 -11
  170. package/dist/editors/routes.js.map +1 -1
  171. package/dist/interactive/bridge-pool.d.ts +5 -2
  172. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  173. package/dist/interactive/bridge-pool.js +4 -1
  174. package/dist/interactive/bridge-pool.js.map +1 -1
  175. package/dist/interactive/landing-guard.d.ts.map +1 -1
  176. package/dist/interactive/landing-guard.js +79 -5
  177. package/dist/interactive/landing-guard.js.map +1 -1
  178. package/dist/knowledge/adapters/toolbox/memory.d.ts.map +1 -1
  179. package/dist/knowledge/adapters/toolbox/memory.js +3 -2
  180. package/dist/knowledge/adapters/toolbox/memory.js.map +1 -1
  181. package/dist/knowledge/trackers/set.d.ts +28 -0
  182. package/dist/knowledge/trackers/set.d.ts.map +1 -1
  183. package/dist/knowledge/trackers/set.js +26 -0
  184. package/dist/knowledge/trackers/set.js.map +1 -1
  185. package/dist/mcp/policies.d.ts +35 -0
  186. package/dist/mcp/policies.d.ts.map +1 -1
  187. package/dist/mcp/policies.js +138 -1
  188. package/dist/mcp/policies.js.map +1 -1
  189. package/dist/mcp/registry-store.d.ts +10 -0
  190. package/dist/mcp/registry-store.d.ts.map +1 -1
  191. package/dist/mcp/registry-store.js.map +1 -1
  192. package/dist/mcp/registry.d.ts +40 -3
  193. package/dist/mcp/registry.d.ts.map +1 -1
  194. package/dist/mcp/registry.js +211 -16
  195. package/dist/mcp/registry.js.map +1 -1
  196. package/dist/mcp/trigger-names.d.ts +32 -0
  197. package/dist/mcp/trigger-names.d.ts.map +1 -0
  198. package/dist/mcp/trigger-names.js +529 -0
  199. package/dist/mcp/trigger-names.js.map +1 -0
  200. package/dist/skills/store.d.ts +11 -1
  201. package/dist/skills/store.d.ts.map +1 -1
  202. package/dist/skills/store.js +37 -3
  203. package/dist/skills/store.js.map +1 -1
  204. package/dist/studio/apps-standalone/fixture.js +3 -3
  205. package/dist/studio/assets/{KnowledgeGraph-yP4WsnST.js → KnowledgeGraph-D6RRLDnV.js} +1 -1
  206. package/dist/studio/assets/{index-DW53FKuT.js → index-BLo9vFQI.js} +324 -310
  207. package/dist/studio/assets/index-xW21Gkam.css +32 -0
  208. package/dist/studio/editors/wicked-apps/editor.json +1 -1
  209. package/dist/studio/editors/wicked-apps/index.html +1 -1
  210. package/dist/studio/editors/wicked-deck/editor.json +1 -1
  211. package/dist/studio/editors/wicked-deck/index.html +1 -1
  212. package/dist/studio/editors/wicked-doc/editor.json +1 -1
  213. package/dist/studio/editors/wicked-doc/index.html +1 -1
  214. package/dist/studio/editors/wicked-insights/editor.json +1 -1
  215. package/dist/studio/editors/wicked-insights/index.html +1 -1
  216. package/dist/studio/editors/wicked-page/editor.json +1 -1
  217. package/dist/studio/editors/wicked-page/index.html +1 -1
  218. package/dist/studio/editors/wicked-video/editor.json +1 -1
  219. package/dist/studio/editors/wicked-video/index.html +1 -1
  220. package/dist/studio/index.html +2 -2
  221. package/dist/studio/testid-inventory.json +539 -5
  222. package/dist/team/routes.d.ts +4 -1
  223. package/dist/team/routes.d.ts.map +1 -1
  224. package/dist/team/routes.js +1 -1
  225. package/dist/team/routes.js.map +1 -1
  226. package/dist/voice/tts.d.ts +6 -0
  227. package/dist/voice/tts.d.ts.map +1 -1
  228. package/dist/voice/tts.js +16 -1
  229. package/dist/voice/tts.js.map +1 -1
  230. package/endpoint-manifest.json +85 -6
  231. package/package.json +4 -4
  232. package/voice-locks/darwin-arm64-cp310.txt +12 -0
  233. package/voice-locks/darwin-arm64-cp311.txt +8 -0
  234. package/voice-locks/darwin-arm64-cp312.txt +8 -0
  235. package/voice-locks/darwin-arm64-cp313.txt +8 -0
  236. package/voice-locks/darwin-arm64-cp314.txt +8 -0
  237. package/voice-locks/darwin-arm64-cp39.txt +12 -0
  238. package/voice-locks/darwin-x64-cp310.txt +12 -0
  239. package/voice-locks/darwin-x64-cp311.txt +12 -0
  240. package/voice-locks/darwin-x64-cp312.txt +12 -0
  241. package/voice-locks/darwin-x64-cp313.txt +12 -0
  242. package/voice-locks/darwin-x64-cp39.txt +12 -0
  243. package/voice-locks/linux-arm64-cp310.txt +12 -0
  244. package/voice-locks/linux-arm64-cp311.txt +8 -0
  245. package/voice-locks/linux-arm64-cp312.txt +8 -0
  246. package/voice-locks/linux-arm64-cp313.txt +8 -0
  247. package/voice-locks/linux-arm64-cp314.txt +8 -0
  248. package/voice-locks/linux-arm64-cp39.txt +12 -0
  249. package/voice-locks/linux-x64-cp310.txt +12 -0
  250. package/voice-locks/linux-x64-cp311.txt +8 -0
  251. package/voice-locks/linux-x64-cp312.txt +8 -0
  252. package/voice-locks/linux-x64-cp313.txt +8 -0
  253. package/voice-locks/linux-x64-cp314.txt +8 -0
  254. package/voice-locks/linux-x64-cp39.txt +12 -0
  255. package/dist/studio/assets/index-DNaLjJ7M.css +0 -32
@@ -45,7 +45,6 @@ export const PREVIEW_TTL_MS = 15 * 60 * 1000;
45
45
  const PREVIEW_CACHE_MAX = 64;
46
46
  /** Consecutive failed probes before a server's health reads `failing`. */
47
47
  export const HEALTH_FAILING_AFTER = 3;
48
- /** A refusal the routes map to a status code. */
49
48
  export class McpRegistryError extends Error {
50
49
  status;
51
50
  code;
@@ -139,6 +138,11 @@ export class McpRegistry {
139
138
  if ((config.kind === 'sql' || config.kind === 'graphql' || config.kind === 'toolbox-source') && config.name === CREW_SOURCE) {
140
139
  throw new McpRegistryError(400, 'reserved_name', `"${CREW_SOURCE}" is the built-in crew source; choose another name`);
141
140
  }
141
+ // (crew#1514) A name a live entry was renamed away from is retired: refused here, and again inside the save.
142
+ const registered = (await this.readFile()).servers;
143
+ const retiring = retiredBy(registered, config.name);
144
+ if (retiring !== undefined)
145
+ throw retiredName(config.name, retiring);
142
146
  // (DES-KNOWLEDGE-DATA-001 §5.1) A database source is saved as its Toolbox document, checked against the
143
147
  // deployment policy here (the preview) and again when the write lands.
144
148
  config = this.forSave(config);
@@ -149,8 +153,11 @@ export class McpRegistry {
149
153
  if (!this.deps.secrets.available) {
150
154
  throw new McpRegistryError(501, 'secret_store_unavailable', 'this platform has no OS secret store; reference a daemon env variable instead (auth.ref "env:<NAME>")');
151
155
  }
152
- if (config.auth === null || config.auth.ref !== keychainRef(config.name)) {
153
- throw new McpRegistryError(400, 'secret_not_staged_here', `a staged secret is stored as this server's own keychain entry, so auth.ref must be ${keychainRef(config.name)}`);
156
+ // (crew#1514) A renamed entry's own entry keeps the account it was saved under (`keychainAccount`).
157
+ const own = registered.find((x) => x.name === config.name);
158
+ const account = own !== undefined ? ownAccount(own) : config.name;
159
+ if (config.auth === null || config.auth.ref !== keychainRef(account)) {
160
+ throw new McpRegistryError(400, 'secret_not_staged_here', `a staged secret is stored as this server's own keychain entry, so auth.ref must be ${keychainRef(account)}`);
154
161
  }
155
162
  // The reference is answered back and audited, so a value it contains would be echoed there.
156
163
  if (config.auth.ref.includes(stagedSecret)) {
@@ -268,19 +275,29 @@ export class McpRegistry {
268
275
  // orphan this was written to prevent. `null` = no prior value, and then the rollback deletes.
269
276
  // (DES-PM-001 §3) A save that would drop or change a PM source's marker is refused BEFORE any credential is
270
277
  // written (the mutation refuses it again, under the store's chain, for a marker set meanwhile).
271
- const existing = (await this.readFile()).servers.find((s) => s.name === held.config.name);
278
+ const current = (await this.readFile()).servers;
279
+ const existing = current.find((s) => s.name === held.config.name);
280
+ // (crew#1514) Judged BEFORE any credential is written: a preview held across a rename can't save over the retired
281
+ // name, nor write the keychain account the renamed entry still uses.
282
+ const retiring = retiredBy(current, held.config.name);
283
+ if (retiring !== undefined)
284
+ throw retiredName(held.config.name, retiring);
285
+ const account = held.secret === null ? held.config.name : stagedAccount(held.config, existing);
272
286
  const existingPm = existing === undefined ? null : pmOf(existing);
273
287
  if (existingPm !== null && (held.config.pm == null || held.config.pm.system !== existingPm.system)) {
274
288
  throw new McpRegistryError(409, 'pm_marker_fixed', `${held.config.name} is registered as a ${existingPm.system} project-management source; save it with pm.system "${existingPm.system}", or remove it and register it again`);
275
289
  }
276
- const prior = held.secret === null ? null : await this.deps.secrets.get(held.config.name);
290
+ const prior = held.secret === null ? null : await this.deps.secrets.get(account);
277
291
  if (held.secret !== null)
278
- await this.deps.secrets.set(held.config.name, held.secret);
292
+ await this.deps.secrets.set(account, held.secret);
279
293
  // (crew#1328 item 3) A save that changes a source's allowed views with no new description changes its projection key
280
294
  // with no catalog written: it is named once the write lands, so its structure is projected again now.
281
295
  let viewsChanged = false;
282
- const saved = await this.restoreSecretOnFailure(held.config.name, held.secret !== null, prior, () => this.mutate(async (file) => {
296
+ const saved = await this.restoreSecretOnFailure(account, held.secret !== null, prior, () => this.mutate(async (file) => {
283
297
  const prior = file.servers.find((s) => s.name === held.config.name);
298
+ const retiredNow = retiredBy(file.servers, held.config.name);
299
+ if (retiredNow !== undefined)
300
+ throw retiredName(held.config.name, retiredNow);
284
301
  // (DES-PM-001 §3) A PM entry stays the PM system it was registered as: a re-save that drops the marker, or
285
302
  // names another system, would hand its tools to the plain path (or its links to another vendor).
286
303
  const priorPm = prior === undefined ? null : pmOf(prior);
@@ -343,6 +360,10 @@ export class McpRegistry {
343
360
  registeredAt: prior?.registeredAt ?? stamp,
344
361
  updatedAt: stamp,
345
362
  tools,
363
+ // (crew#1514) A re-save keeps the names it retired and its keychain account (its own account for as long as it
364
+ // lives, whatever its reference names now: a re-save back to keychain:wicked-mcp/<account> owns it again).
365
+ ...(prior?.formerNames !== undefined && prior.formerNames.length > 0 ? { formerNames: [...prior.formerNames] } : {}),
366
+ ...(prior?.keychainAccount !== undefined ? { keychainAccount: prior.keychainAccount } : {}),
346
367
  };
347
368
  // (DES-APPS-001 §7.4, DES-KNOWLEDGE-DATA-001 §5.4) Allow writes is off on every new Postgres source, and
348
369
  // "query" on every new source. A re-save keeps each only while the descriptor is unchanged, and a K1
@@ -543,7 +564,85 @@ export class McpRegistry {
543
564
  });
544
565
  return this.view(rec);
545
566
  }
546
- /** Remove a server, and the keychain secret it owns (`keychain:wicked-mcp/<name>`). */
567
+ /**
568
+ * (crew#1514) What {@link rename} would refuse now (the names, the entry, the new name taken or retired by another
569
+ * entry), checked before the caller moves any rule: a refused rename never lends another entry's rules to a live
570
+ * destination, even for a moment. {@link rename} checks again inside its write.
571
+ */
572
+ async checkRename(from, to) {
573
+ renameNameRefusal(from, to);
574
+ this.renameRefusal((await this.readFile()).servers, from, to);
575
+ }
576
+ /** The entry `from` names, or the refusal: crew's web source, `to` taken, or `to` retired by another entry. */
577
+ renameRefusal(servers, from, to) {
578
+ const s = this.find(servers, from);
579
+ if (s.kind === 'web')
580
+ throw new McpRegistryError(409, 'not_renamable', `${from} is crew's built-in web source: its name is fixed`);
581
+ const taken = servers.find((x) => x.name === to);
582
+ if (taken !== undefined)
583
+ throw new McpRegistryError(409, 'name_taken', `${to} is already a registered ${taken.kind} server; choose another name`);
584
+ const retiring = retiredBy(servers, to);
585
+ if (retiring !== undefined && retiring !== s)
586
+ throw retiredName(to, retiring);
587
+ return s;
588
+ }
589
+ /**
590
+ * (crew#1514) Rename an entry, keeping everything bound to it: its id, its secret reference (an owned keychain entry
591
+ * stays under the account it was saved as: `keychainAccount`), its tools, switches, grants, agents and links. `from`
592
+ * becomes one of its RETIRED names (`formerNames`): no other entry may take it while this one lives. Its stored
593
+ * description moves with it: copied inside the write, the old file removed once the write has landed (a failed write
594
+ * leaves no copy behind). Held previews of either name are dropped, so none saves over the renamed entry or under
595
+ * the retired name. The caller holds both names' policy locks and moves the rules (`McpPolicies`).
596
+ */
597
+ async rename(from, to) {
598
+ renameNameRefusal(from, to);
599
+ const stamp = new Date(this.now()).toISOString();
600
+ let copied = false;
601
+ let renamed;
602
+ try {
603
+ renamed = await this.mutate(async (file) => {
604
+ const s = this.renameRefusal(file.servers, from, to);
605
+ // The secret is never moved: `auth.ref` is part of the descriptor every grant and lock binds to. The entry's own
606
+ // account stays the name it had (retired with it), so no other entry can ever write it.
607
+ if (s.keychainAccount === undefined)
608
+ s.keychainAccount = s.name;
609
+ if (s.keychainAccount === to)
610
+ delete s.keychainAccount;
611
+ const former = [...new Set([...(s.formerNames ?? []).filter((n) => n !== to), from])];
612
+ s.formerNames = former;
613
+ s.name = to;
614
+ s.updatedAt = stamp;
615
+ if (isSourceRecord(s)) {
616
+ const d = await this.catalogs.read(from);
617
+ if (d !== null) {
618
+ await this.catalogs.write(to, d);
619
+ copied = true;
620
+ }
621
+ }
622
+ return s;
623
+ });
624
+ }
625
+ catch (err) {
626
+ if (copied)
627
+ await this.catalogs.remove(to).catch(() => undefined);
628
+ throw err;
629
+ }
630
+ if (copied)
631
+ await this.catalogs.remove(from).catch(() => undefined);
632
+ for (const [hash, held] of this.previews)
633
+ if (held.config.name === from || held.config.name === to)
634
+ this.previews.delete(hash);
635
+ if (isSourceRecord(renamed))
636
+ this.sourceChanged(to);
637
+ try {
638
+ return await this.view(renamed);
639
+ }
640
+ catch (err) {
641
+ // The rename has landed: the caller must not undo anything bound to it because its answer could not be built.
642
+ throw new McpRenameCommitted(from, to, err);
643
+ }
644
+ }
645
+ /** Remove a server, and the keychain secret it owns (`keychain:wicked-mcp/<name>`, or its `keychainAccount`). */
547
646
  async remove(name) {
548
647
  const { removed, tombstoned } = await this.mutate(async (file) => {
549
648
  const s = this.find(file.servers, name);
@@ -558,15 +657,20 @@ export class McpRegistry {
558
657
  return { removed: s, tombstoned: ids };
559
658
  });
560
659
  this.tombstoned(tombstoned);
561
- if (removed.auth?.ref === keychainRef(name) && this.deps.secrets.available) {
660
+ const account = ownAccount(removed);
661
+ // (crew#1514) A renamed entry owns its account for its whole life, whatever its reference names now (re-saved with
662
+ // an env secret, say): the secret under that account goes with it, when there is one.
663
+ const owned = removed.auth?.ref === keychainRef(account)
664
+ || (removed.keychainAccount !== undefined && this.deps.secrets.available && (await this.deps.secrets.has(account).catch(() => false)));
665
+ if (owned && this.deps.secrets.available) {
562
666
  try {
563
- await this.deps.secrets.delete(name);
667
+ await this.deps.secrets.delete(account);
564
668
  }
565
669
  catch (err) {
566
670
  // (crew#719) The row is already gone, so the secret is now unreachable by any route. Say
567
671
  // so — the alternative is a silent orphan in the operator's keychain.
568
672
  const why = err instanceof Error ? err.message : String(err);
569
- throw new McpRegistryError(500, 'secret_orphaned', `${name} was removed but its secret could not be deleted (${why}); remove the "${KEYCHAIN_SERVICE}" keychain entry for account "${name}" by hand`);
673
+ throw new McpRegistryError(500, 'secret_orphaned', `${name} was removed but its secret could not be deleted (${why}); remove the "${KEYCHAIN_SERVICE}" keychain entry for account "${account}" by hand`);
570
674
  }
571
675
  }
572
676
  }
@@ -687,20 +791,27 @@ export class McpRegistry {
687
791
  if (!this.deps.secrets.available) {
688
792
  throw new McpRegistryError(501, 'secret_store_unavailable', 'this platform has no OS secret store; reference a daemon env variable instead (auth.ref "env:<NAME>")');
689
793
  }
690
- const ref = keychainRef(name);
691
- // The route answers and audits the reference, so a value it contains would be echoed there.
692
- if (ref.includes(value))
693
- throw new McpRegistryError(400, 'secret_in_ref', 'the secret must not appear in its own reference; choose a different value');
694
794
  // (crew#719) RE-KEY ONLY. A secret written for a name no registered server references is an
695
795
  // orphan nothing can find again — a keychain service's entries cannot be enumerated — and it
696
796
  // was the first half of the non-atomic add: secret, then save, with a window between them.
697
797
  // A NEW server's secret is staged with its preview and committed by `save`.
798
+ // The route answers and audits the reference, so a value it contains would be echoed there (checked before the
799
+ // lookup, as ever, and again for a renamed entry's own account below).
800
+ const inRef = (r) => {
801
+ if (r.includes(value))
802
+ throw new McpRegistryError(400, 'secret_in_ref', 'the secret must not appear in its own reference; choose a different value');
803
+ };
804
+ inRef(keychainRef(name));
698
805
  const server = this.find((await this.readFile()).servers, name);
806
+ // (crew#1514) A renamed entry keeps the account it was saved under.
807
+ const account = ownAccount(server);
808
+ const ref = keychainRef(account);
809
+ inRef(ref);
699
810
  if (server.auth?.ref !== ref) {
700
811
  // The stored reference is a connection field: it is not echoed (an agent-kind caller reads errors too).
701
812
  throw new McpRegistryError(400, 'secret_not_referenced', `${name} does not reference ${ref}, so a secret stored there would be unreachable; stage it with the preview instead`);
702
813
  }
703
- await this.deps.secrets.set(name, value);
814
+ await this.deps.secrets.set(account, value);
704
815
  return ref;
705
816
  }
706
817
  /**
@@ -857,6 +968,9 @@ export class McpRegistry {
857
968
  const stamp = new Date(this.now()).toISOString();
858
969
  const rec = await this.mutate(async (file) => {
859
970
  const prior = file.servers.find((s) => s.name === name);
971
+ const retiring = retiredBy(file.servers, name);
972
+ if (retiring !== undefined)
973
+ throw retiredName(name, retiring);
860
974
  if (prior !== undefined && !(prior.kind === 'sql' && prior.sql?.driver === 'sqlite')) {
861
975
  throw new McpRegistryError(409, 'name_taken', `${name} is already a registered ${prior.kind} server; choose another name`);
862
976
  }
@@ -875,6 +989,9 @@ export class McpRegistry {
875
989
  registeredAt: prior?.registeredAt ?? stamp,
876
990
  updatedAt: stamp,
877
991
  tools: [],
992
+ // (crew#1514) A new upload of a renamed source keeps the names it retired.
993
+ ...(prior?.formerNames !== undefined && prior.formerNames.length > 0 ? { formerNames: [...prior.formerNames] } : {}),
994
+ ...(prior?.keychainAccount !== undefined ? { keychainAccount: prior.keychainAccount } : {}),
878
995
  // (DES-KNOWLEDGE-DATA-001 §7.1) A new upload of the same name keeps the person's agent switches; "query"
879
996
  // only when it is the same snapshot (a new digest is a new descriptor).
880
997
  ...(prior?.agents !== undefined ? { agents: { ...agentAccessOf(prior), query: agentAccessOf(prior).query && prior.sql?.snapshot === digest } } : {}),
@@ -894,6 +1011,9 @@ export class McpRegistry {
894
1011
  const stamp = new Date(this.now()).toISOString();
895
1012
  const rec = await this.mutate(async (file) => {
896
1013
  const prior = file.servers.find((s) => s.name === name);
1014
+ const retiring = retiredBy(file.servers, name);
1015
+ if (retiring !== undefined)
1016
+ throw retiredName(name, retiring);
897
1017
  if (prior !== undefined && prior.kind !== 'web')
898
1018
  throw new McpRegistryError(409, 'name_taken', `${name} is already a registered ${prior.kind} server; rename or remove it first`);
899
1019
  const other = file.servers.find((s) => s.kind === 'web' && s.name !== name);
@@ -957,6 +1077,9 @@ export class McpRegistry {
957
1077
  const why = err instanceof Error ? err.message : String(err);
958
1078
  throw new McpRegistryError(409, 'generation_unreadable', `generation ${generation} is not a registry crew can read: ${why}`);
959
1079
  }
1080
+ // (crew#1514) An entry the generation holds under another name than the live one was renamed since: the rules,
1081
+ // picks and keychain account follow the live name, so the restore is refused until it is renamed back.
1082
+ crossesRename(generation, servers, (await this.readFile()).servers);
960
1083
  for (const s of servers) {
961
1084
  if (s.kind !== 'toolbox-source')
962
1085
  continue;
@@ -1008,6 +1131,8 @@ export class McpRegistry {
1008
1131
  s.updatedAt = stamp;
1009
1132
  }
1010
1133
  const { current, tombstoned } = await this.mutate((file) => {
1134
+ // (crew#1514) Again inside the write: a rename that landed after the plan was made is not undone by it.
1135
+ crossesRename(plan.generation, servers, file.servers);
1011
1136
  if (expected !== undefined) {
1012
1137
  const late = file.servers.map((s) => s.name).filter((n) => !expected.includes(n));
1013
1138
  if (late.length > 0)
@@ -1180,6 +1305,8 @@ export class McpRegistry {
1180
1305
  ...(isPostgresRecord(s) ? { allowWrites: s.allowWrites === true } : {}),
1181
1306
  ...(isSource ? { descriptorHash: sourceDescriptorHash(configOf(s)), agents: agentAccessOf(s) } : {}),
1182
1307
  ...(pm !== null ? { agents: agentAccessOf(s), trackers: this.trackerLinksOf(s) } : {}),
1308
+ ...(s.formerNames !== undefined && s.formerNames.length > 0 ? { formerNames: [...s.formerNames] } : {}),
1309
+ ...(s.keychainAccount !== undefined ? { keychainAccount: s.keychainAccount } : {}),
1183
1310
  authState: await this.authState(s.auth),
1184
1311
  enabled: s.enabled,
1185
1312
  health: s.health,
@@ -1452,6 +1579,74 @@ export function isPostgresRecord(s) {
1452
1579
  return s.toolbox?.type === 'postgres';
1453
1580
  return s.kind === 'sql' && s.sql?.driver === 'postgres';
1454
1581
  }
1582
+ /** (crew#1514) A rename committed, but its answer could not be built (the record is read again by the caller). */
1583
+ export class McpRenameCommitted extends Error {
1584
+ from;
1585
+ to;
1586
+ cause;
1587
+ constructor(from, to, cause) {
1588
+ super(`${from} was renamed to ${to}, but its record could not be read back: ${cause instanceof Error ? cause.message : String(cause)}`);
1589
+ this.from = from;
1590
+ this.to = to;
1591
+ this.cause = cause;
1592
+ }
1593
+ }
1594
+ /**
1595
+ * (crew#1514) Refuse a restore that would undo a rename (409 `restore_crosses_rename`): an entry the generation holds
1596
+ * under another name, or with other retired names or another keychain account, than the live one; or an entry whose
1597
+ * name a live entry has retired. The rules, picks and keychain account follow the live names.
1598
+ */
1599
+ function crossesRename(generation, kept, live) {
1600
+ const names = (l) => [...new Set(l ?? [])].sort().join(',');
1601
+ const crossed = [];
1602
+ for (const s of kept) {
1603
+ const l = live.find((x) => entryId(x) === entryId(s));
1604
+ if (l !== undefined && (l.name !== s.name || names(l.formerNames) !== names(s.formerNames) || l.keychainAccount !== s.keychainAccount)) {
1605
+ crossed.push(l.name !== s.name ? `${l.name} (was ${s.name})` : `${l.name} (renamed since)`);
1606
+ continue;
1607
+ }
1608
+ const by = live.find((x) => entryId(x) !== entryId(s) && (x.formerNames ?? []).includes(s.name));
1609
+ if (by !== undefined)
1610
+ crossed.push(`${s.name} (a name ${by.name} retired)`);
1611
+ }
1612
+ if (crossed.length > 0) {
1613
+ throw new McpRegistryError(409, 'restore_crosses_rename', `generation ${generation} would undo a rename: ${crossed.join(', ')}. A restore keeps every entry's current name, retired names and keychain account, so pick a generation saved since the rename`);
1614
+ }
1615
+ }
1616
+ /** (crew#1514) The new name's own refusals: its form, crew's reserved names, and no change. */
1617
+ function renameNameRefusal(from, to) {
1618
+ if (!MCP_SERVER_NAME_RE.test(to))
1619
+ throw new McpRegistryError(400, 'bad_name', 'a name is 1-63 of a-z 0-9 _ -, starting with a letter or digit');
1620
+ if (to === APPS_SERVER || to === ESTATE_SERVER || to === CREW_SOURCE || to === 'web') {
1621
+ throw new McpRegistryError(409, 'reserved_name', `"${to}" is reserved for crew's own ${to === 'web' ? 'web source' : to === CREW_SOURCE ? 'crew source' : `${to} server`}; choose another name`);
1622
+ }
1623
+ if (from === to)
1624
+ throw new McpRegistryError(409, 'name_unchanged', `${from} already has that name`);
1625
+ }
1626
+ /** (crew#1514) The keychain account a record's own secret lives under: the name it was saved as. */
1627
+ export function ownAccount(s) {
1628
+ return s.keychainAccount ?? s.name;
1629
+ }
1630
+ /** (crew#1514) The live entry that retired `name` (was renamed away from it), or `undefined`. */
1631
+ export function retiredBy(servers, name) {
1632
+ return servers.find((s) => s.name !== name && (s.formerNames ?? []).includes(name));
1633
+ }
1634
+ function retiredName(name, by) {
1635
+ return new McpRegistryError(409, 'name_retired', `${name} was renamed to ${by.name}, so the name stays retired while ${by.name} exists; choose another name, or rename ${by.name} back to ${name}`);
1636
+ }
1637
+ /**
1638
+ * (crew#1514) The keychain account a held preview's staged secret goes to: the one its reference names, which the
1639
+ * preview checked was the server's own. Re-judged at the save against the entry as it is now.
1640
+ */
1641
+ function stagedAccount(config, existing) {
1642
+ const parsed = config.auth === null ? null : parseSecretRef(config.auth.ref);
1643
+ const account = parsed?.kind === 'keychain' ? parsed.account : null;
1644
+ const own = existing !== undefined ? ownAccount(existing) : config.name;
1645
+ if (account === null || account !== own) {
1646
+ throw new McpRegistryError(409, 'server_changed', `${config.name} changed since it was previewed (its keychain entry is now "${own}"): preview it again, then save`);
1647
+ }
1648
+ return account;
1649
+ }
1455
1650
  /** A record's id; one read through {@link normalizeRegistryFile} always has it. */
1456
1651
  export function entryId(s) {
1457
1652
  return s.id ?? legacyEntryId(s.name, s.registeredAt);