@akanjs/cli 3.1.1-rc.9 → 3.1.2-rc.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 (207) hide show
  1. package/.build-stamp +1 -1
  2. package/CodeAgent-dyc45f5w.js +11 -0
  3. package/{CodeAgentRpcHost-9g27hmer.js → CodeAgentRpcHost-6dzfkvsc.js} +1 -1
  4. package/CodeAgentRpcListener-tcwrdvst.js +182 -0
  5. package/{CodeTui-z5vkm9ea.js → CodeTui-q55b2zrn.js} +25 -8
  6. package/TunnelShare-hdq9h1hr.js +14 -0
  7. package/agent.command-20zaqe60.js +49 -0
  8. package/akanCode.js +13 -8
  9. package/{application.command-wthg8nn9.js → application.command-nd0fshsk.js} +45 -12
  10. package/{applicationBuildRunner-t2r84sz6.js → applicationBuildRunner-s13x3zqb.js} +14 -10
  11. package/buildBatch.proc.js +7 -7
  12. package/{cloud.command-sz11hpre.js → cloud.command-8kbddsz9.js} +28 -19
  13. package/cloud.script-hgvvajm3.js +27 -0
  14. package/code.command-625bg8s8.js +345 -0
  15. package/commandManifest.json +1 -1
  16. package/{context.command-15j9b7c0.js → context.command-p6haqjay.js} +20 -18
  17. package/context.runner-rsnqnk9j.js +27 -0
  18. package/{dependencyScanner-3afj2vt1.js → dependencyScanner-78sq8m4q.js} +2 -2
  19. package/{devTui-q7k7bakd.js → devTui-evr3b35y.js} +1 -1
  20. package/{fileSys-wzzrntkw.js → fileSys-zpvt5gtf.js} +1 -1
  21. package/{guideline.command-snh85ctf.js → guideline.command-195g0h9a.js} +4 -4
  22. package/guidelines/agentRule/agentRule.instruction.md +22 -8
  23. package/guidelines/conventions/core.md +106 -0
  24. package/guidelines/conventions/rules/app.md +83 -0
  25. package/guidelines/conventions/rules/auth.md +46 -0
  26. package/guidelines/conventions/rules/config.md +60 -0
  27. package/guidelines/conventions/rules/constant.md +24 -0
  28. package/guidelines/conventions/rules/gates.md +32 -0
  29. package/guidelines/conventions/rules/layer.md +25 -0
  30. package/guidelines/conventions/rules/migration.md +27 -0
  31. package/guidelines/conventions/rules/module.md +90 -0
  32. package/guidelines/conventions/rules/page.md +56 -0
  33. package/guidelines/conventions/rules/sensitive.md +16 -0
  34. package/guidelines/conventions/rules/server.md +91 -0
  35. package/guidelines/conventions/rules/ssr.md +47 -0
  36. package/guidelines/conventions/rules/style.md +43 -0
  37. package/guidelines/conventions/rules/test.md +34 -0
  38. package/guidelines/conventions/rules/ts.md +95 -0
  39. package/guidelines/conventions/rules/tsx.md +76 -0
  40. package/guidelines/mcpRule/mcpRule.instruction.md +1 -1
  41. package/guidelines/pageRule/pageRule.instruction.md +8 -7
  42. package/guidelines/queryRule/queryRule.instruction.md +4 -0
  43. package/guidelines/runtimeRule/runtimeRule.instruction.md +35 -25
  44. package/guidelines/ssrRule/ssrRule.instruction.md +11 -10
  45. package/guidelines/transportRule/transportRule.instruction.md +5 -4
  46. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +4 -4
  47. package/incrementalBuilder.proc.js +7 -7
  48. package/{index-301pdbzz.js → index-00a7j05x.js} +7 -7
  49. package/{index-js6geqjn.js → index-0j1t1h2b.js} +3 -1
  50. package/{index-6txx6a9p.js → index-1h2jc0x3.js} +154 -88
  51. package/{index-55j120r8.js → index-1qsd8ft1.js} +65 -145
  52. package/{index-9th4gszy.js → index-2mwjshz5.js} +233 -1271
  53. package/index-2nxk8wgs.js +266 -0
  54. package/{index-j9vyj3dj.js → index-2phm56a1.js} +49 -8
  55. package/index-35j83zkd.js +61 -0
  56. package/index-4am4dvmf.js +29 -0
  57. package/index-75y7bcz4.js +28 -0
  58. package/index-7apsdr5g.js +487 -0
  59. package/{index-42j4a8zq.js → index-84h43kg6.js} +8 -6
  60. package/index-9bv479q5.js +1 -0
  61. package/{index-3wypz6xj.js → index-9zy8479y.js} +11 -5
  62. package/{index-a5dhqkdr.js → index-a1vb3x7t.js} +273 -259
  63. package/{index-52w0fvh8.js → index-bns3wcpc.js} +15 -0
  64. package/index-cjmjvg4r.js +3622 -0
  65. package/{index-pcwzkdqb.js → index-defp4gmb.js} +1 -1
  66. package/index-ewbmfarf.js +1606 -0
  67. package/index-fbewhg4g.js +590 -0
  68. package/index-fhw7yq2d.js +653 -0
  69. package/{index-wcej7g4z.js → index-g500c5j9.js} +271 -105
  70. package/{index-74tjjsnc.js → index-g841cap9.js} +33 -37
  71. package/{index-2azahjaw.js → index-gr9thy79.js} +5 -5
  72. package/{index-4pf8g7ff.js → index-h7hehkw6.js} +3 -0
  73. package/{index-xjf5j657.js → index-hm0tn7qv.js} +1001 -91
  74. package/index-j6eeh5d7.js +138 -0
  75. package/{index-31es1yev.js → index-j7hwy56s.js} +108 -7
  76. package/{index-skk9zc1x.js → index-jc2zbwra.js} +2 -2
  77. package/{index-905qdgqp.js → index-khk05tsf.js} +1 -1
  78. package/{index-5nd1wtkv.js → index-p6x5b7hr.js} +1 -1
  79. package/{index-tvehn2sp.js → index-qd7xn2bk.js} +1 -1
  80. package/{index-a58emady.js → index-qw6814m4.js} +55 -17
  81. package/index-raz588b3.js +445 -0
  82. package/{index-at7bz0xq.js → index-s4nvxpzm.js} +2 -0
  83. package/{index-bt438yxm.js → index-sp0qsr7a.js} +116 -13
  84. package/{index-xb8809yb.js → index-sveq36gh.js} +40 -43
  85. package/{index-hmt54t45.js → index-t1t9wq9a.js} +4 -4
  86. package/index-t78230d7.js +191 -0
  87. package/index-tenw3mah.js +225 -0
  88. package/{index-qfp55x1y.js → index-tgqameyb.js} +4 -4
  89. package/{index-espk51ah.js → index-tp56652m.js} +6 -6
  90. package/index-w15mg3km.js +389 -0
  91. package/{index-dy0jx9ay.js → index-wwe9rsrx.js} +14 -0
  92. package/{index-2xcc2ax5.js → index-y4kcmbt2.js} +2 -2
  93. package/index-yf9wc28h.js +52 -0
  94. package/{index-0fz95kxe.js → index-zbrwnmf1.js} +9 -7
  95. package/{index-40brg4px.js → index-zttm13c3.js} +5 -5
  96. package/index.js +24 -23
  97. package/{library.command-gycrwhf1.js → library.command-63hgt9te.js} +4 -4
  98. package/{localRegistry.command-jtd8gaes.js → localRegistry.command-g3f8k25t.js} +46 -22
  99. package/{module.command-v6hgs1bc.js → module.command-r4sa2khp.js} +7 -6
  100. package/{package.command-shzpcfph.js → package.command-96eheyvd.js} +5 -5
  101. package/package.json +2 -2
  102. package/{page.command-ptxn5kqk.js → page.command-gs6d841d.js} +4 -4
  103. package/{pipeline.command-zz31pgax.js → pipeline.command-wdfvdbfj.js} +3 -3
  104. package/{primitive.command-a1vse91z.js → primitive.command-dfsv4mpe.js} +8 -7
  105. package/{projectTypecheck-2ztky9cf.js → projectTypecheck-kqj1t6hb.js} +1 -1
  106. package/{prompter-76k56b37.js → prompter-qrwx1p17.js} +2 -2
  107. package/quality.command-webzxee2.js +78 -0
  108. package/{repair.command-cvazbz99.js → repair.command-3r3j1xre.js} +7 -6
  109. package/{routeSourceValidator-6jd0q6r6.js → routeSourceValidator-4h947v7c.js} +13 -3
  110. package/{scalar.command-0acvyp26.js → scalar.command-e8y47j6d.js} +6 -5
  111. package/skills/akan-agent/SKILL.md +43 -0
  112. package/skills/akan-code/SKILL.md +38 -11
  113. package/skills/akan-debug/SKILL.md +41 -6
  114. package/skills/akan-deps/SKILL.md +1 -2
  115. package/skills/akan-err/SKILL.md +2 -1
  116. package/skills/akan-mcp/SKILL.md +40 -0
  117. package/skills/akan-page/SKILL.md +44 -0
  118. package/skills/akan-query/SKILL.md +39 -0
  119. package/skills/akan-runtime/SKILL.md +43 -0
  120. package/skills/akan-scaffold/SKILL.md +16 -6
  121. package/skills/akan-transport/SKILL.md +40 -0
  122. package/skills/akan-validate/SKILL.md +13 -11
  123. package/{subspace.command-822qx2bx.js → subspace.command-a1sf9n5a.js} +12 -10
  124. package/templates/__scalar/__model__/__model__.constant.ts +3 -5
  125. package/templates/__scalar/__model__/__model__.dictionary.ts +6 -5
  126. package/templates/__scalar/__model__/__model__.document.ts +3 -3
  127. package/templates/app/akan.config.ts +2 -3
  128. package/templates/app/env/env.client.ts +2 -4
  129. package/templates/app/env/env.client.type.ts +2 -3
  130. package/templates/app/env/env.server.ts +2 -3
  131. package/templates/app/lib/___appName__/__appName__.dictionary.ts +1 -2
  132. package/templates/app/lib/___appName__/__appName__.service.ts +3 -3
  133. package/templates/app/lib/___appName__/__appName__.signal.ts +5 -5
  134. package/templates/app/lib/___appName__/__appName__.store.ts +4 -6
  135. package/templates/app/lib/option.ts +2 -3
  136. package/templates/app/main.ts +2 -4
  137. package/templates/app/page/_index.tsx +3 -3
  138. package/templates/app/page/_layout.tsx +13 -10
  139. package/templates/appSample/lib/__scalar/workHistory/workHistory.constant.ts +1 -5
  140. package/templates/appSample/lib/__scalar/workHistory/workHistory.dictionary.ts +1 -1
  141. package/templates/appSample/lib/_noti/noti.signal.ts +1 -1
  142. package/templates/appSample/lib/task/Task.Template.tsx +2 -1
  143. package/templates/appSample/lib/task/Task.Unit.tsx +3 -2
  144. package/templates/appSample/lib/task/Task.Util.tsx +16 -4
  145. package/templates/appSample/lib/task/task.constant.ts +1 -5
  146. package/templates/appSample/lib/task/task.dictionary.ts +2 -8
  147. package/templates/appSample/lib/task/task.document.ts +1 -1
  148. package/templates/appSample/lib/task/task.signal.ts +14 -9
  149. package/templates/appSample/page/task/_index.tsx +2 -1
  150. package/templates/appSample/page/task/new.tsx +2 -1
  151. package/templates/appSample/srvkit/guards.ts +11 -0
  152. package/templates/appSample/ui/QuantityControl.tsx +5 -9
  153. package/templates/biomeForm.ts +144 -0
  154. package/templates/crudPages/[__model__Id]/edit/page.tsx +3 -3
  155. package/templates/crudPages/[__model__Id]/page.tsx +5 -5
  156. package/templates/crudPages/new/page.tsx +4 -3
  157. package/templates/crudPages/page.tsx +3 -3
  158. package/templates/crudSinglePage/page.tsx +9 -5
  159. package/templates/libRoot/akan.config.ts +2 -3
  160. package/templates/libRoot/lib/___libName__/__libName__.dictionary.ts +1 -2
  161. package/templates/libRoot/lib/___libName__/__libName__.service.ts +5 -4
  162. package/templates/libRoot/lib/___libName__/__libName__.signal.ts +6 -5
  163. package/templates/libRoot/lib/___libName__/__libName__.store.ts +5 -6
  164. package/templates/libRoot/lib/option.ts +1 -2
  165. package/templates/module/__Model__.Template.tsx +11 -10
  166. package/templates/module/__Model__.Unit.tsx +18 -5
  167. package/templates/module/__Model__.Util.tsx +9 -7
  168. package/templates/module/__Model__.View.tsx +9 -6
  169. package/templates/module/__Model__.Zone.tsx +25 -17
  170. package/templates/module/__model__.constant.ts +8 -9
  171. package/templates/module/__model__.dictionary.ts +16 -17
  172. package/templates/module/__model__.document.ts +6 -8
  173. package/templates/module/__model__.service.ts +3 -3
  174. package/templates/module/__model__.signal.ts +11 -10
  175. package/templates/module/__model__.store.ts +3 -5
  176. package/templates/service/__model__.dictionary.ts +5 -6
  177. package/templates/service/__model__.service.ts +3 -3
  178. package/templates/service/__model__.signal.ts +5 -4
  179. package/templates/service/__model__.store.ts +3 -5
  180. package/templates/workspaceRoot/.gitignore.template +4 -0
  181. package/templates/workspaceRoot/.vscode/settings.json.template +21 -21
  182. package/templates/workspaceRoot/AGENTS.md.template +4 -10
  183. package/{tunnel.command-ycmja19q.js → tunnel.command-dcb0wg93.js} +25 -13
  184. package/{typeChecker-px49mezc.js → typeChecker-j2jdnqsr.js} +1 -1
  185. package/typecheck.proc.js +6 -1
  186. package/verify.command-yyepccbh.js +93 -0
  187. package/{workflow.command-abb1d5xy.js → workflow.command-z5pg9ay0.js} +49 -14
  188. package/workspace.command-d7x5jttw.js +290 -0
  189. package/CodeAgent-8d5qs787.js +0 -9
  190. package/CodeAgentRpcListener-7p7z5dd7.js +0 -97
  191. package/TunnelShare-qkm8zp03.js +0 -14
  192. package/agent.command-ydftceda.js +0 -25
  193. package/cloud.script-nqevg5qw.js +0 -24
  194. package/code.command-9h3yrzhe.js +0 -167
  195. package/context.runner-8gg030b0.js +0 -25
  196. package/guidelines/conventions/conventions.instruction.md +0 -617
  197. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +0 -291
  198. package/index-2mwc0g0d.js +0 -49
  199. package/index-4vgbysa0.js +0 -279
  200. package/index-7md2g9vw.js +0 -6
  201. package/index-b70zct19.js +0 -856
  202. package/index-c6eggbee.js +0 -123
  203. package/index-zzvvc845.js +0 -74
  204. package/quality.command-ah8qcakd.js +0 -1478
  205. package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +0 -69
  206. package/templates/workspaceRoot/docs/GENERATED.md.template +0 -55
  207. package/workspace.command-qm7cw29v.js +0 -521
@@ -1,4 +1,7 @@
1
1
  // @bun
2
+ import {
3
+ akanCodePaths2
4
+ } from "./index-35j83zkd.js";
2
5
  import {
3
6
  ConfigLock
4
7
  } from "./index-bqbf654f.js";
@@ -41,31 +44,6 @@ class AkanCodeCompaction2 {
41
44
  }
42
45
  }
43
46
 
44
- // pkgs/@akanjs/devkit/codeAgent/agent/akanCodePaths.ts
45
- import { existsSync } from "fs";
46
- import { homedir } from "os";
47
- import path from "path";
48
- var builtinSkillsDir = () => {
49
- const candidates = [path.join(import.meta.dir, "skills"), path.join(import.meta.dir, "..", "skills")];
50
- return candidates.find((candidate) => existsSync(candidate));
51
- };
52
- var globalDir = () => process.env.AKAN_CODE_HOME ?? path.join(homedir(), ".akan", "code");
53
- var akanCodePaths2 = {
54
- workspaceDir: (workspaceRoot) => path.join(workspaceRoot, ".akan", "code"),
55
- sessionsDir: (workspaceRoot) => path.join(workspaceRoot, ".akan", "code", "sessions"),
56
- extensionsDir: (workspaceRoot) => path.join(workspaceRoot, ".akan", "code", "extensions"),
57
- skillsDir: (workspaceRoot) => path.join(workspaceRoot, ".akan", "code", "skills"),
58
- mailDir: (workspaceRoot) => path.join(workspaceRoot, ".akan", "code", "mail"),
59
- builtinSkillsDir,
60
- mcpFile: (workspaceRoot) => path.join(workspaceRoot, ".akan", "code", "mcp.json"),
61
- globalMcpFile: () => path.join(globalDir(), "mcp.json"),
62
- globalSkillsDir: () => path.join(globalDir(), "skills"),
63
- globalDir,
64
- authFile: () => path.join(globalDir(), "auth.json"),
65
- mcpAuthFile: () => path.join(globalDir(), "mcpAuth.json"),
66
- modelsFile: () => path.join(globalDir(), "models.json")
67
- };
68
-
69
47
  // pkgs/@akanjs/devkit/codeAgent/agent/SubagentPool.ts
70
48
  import { codeAgentReadOnlyBuiltins } from "akanjs/common";
71
49
  import { Type } from "typebox";
@@ -179,13 +157,15 @@ class SubagentPool2 {
179
157
  }
180
158
  }
181
159
  async#run(id, kind, prompt, signal) {
182
- const { CodeAgent } = await import("./CodeAgent-8d5qs787.js");
160
+ const { CodeAgent } = await import("./CodeAgent-dyc45f5w.js");
183
161
  const budget = this.#options.parent.tools.subagent;
184
162
  const child = SubagentPool2.childOf(this.#options.parent, kind);
163
+ const model = this.#options.model?.();
185
164
  const agent = await CodeAgent.create({
186
165
  workspace: this.#options.workspace,
187
166
  cwd: this.#options.cwd,
188
167
  profile: child,
168
+ ...model ? { model } : {},
189
169
  apps: [],
190
170
  depth: this.#options.depth + 1,
191
171
  subagentSpend: this.#spend
@@ -229,98 +209,6 @@ class SubagentPool2 {
229
209
  }
230
210
  }
231
211
 
232
- // pkgs/@akanjs/devkit/codeAgent/tools/McpServerConfig.ts
233
- import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
234
- import path2 from "path";
235
- class McpServerConfig {
236
- static file(workspaceRoot, scope = "workspace") {
237
- return scope === "global" ? akanCodePaths2.globalMcpFile() : akanCodePaths2.mcpFile(workspaceRoot);
238
- }
239
- static files(workspaceRoot) {
240
- return [
241
- { scope: "global", file: McpServerConfig.file(workspaceRoot, "global") },
242
- { scope: "workspace", file: McpServerConfig.file(workspaceRoot, "workspace") }
243
- ];
244
- }
245
- static read(workspaceRoot) {
246
- return McpServerConfig.declared(workspaceRoot).filter((entry) => !entry.disabled).map((entry) => entry.ref);
247
- }
248
- static declared(workspaceRoot) {
249
- const byName = new Map;
250
- for (const { scope } of McpServerConfig.files(workspaceRoot))
251
- for (const [name, entry] of Object.entries(McpServerConfig.#parse(workspaceRoot, scope).map))
252
- byName.set(name, { ref: McpServerConfig.#refOf(name, entry), disabled: !!entry.disabled, scope });
253
- return [...byName.values()];
254
- }
255
- static add(workspaceRoot, name, target, scope = "global") {
256
- const [head, ...rest] = target;
257
- if (!head)
258
- throw new Error("Give the server a command to run, or a url to reach.");
259
- const entry = /^https?:\/\//.test(head) ? { url: head } : { command: head, args: rest };
260
- const { file, key, map } = McpServerConfig.#parse(workspaceRoot, scope);
261
- const next = { ...map, [name]: entry };
262
- mkdirSync(path2.dirname(file), { recursive: true });
263
- writeFileSync(file, `${JSON.stringify({ [key]: next }, null, 2)}
264
- `);
265
- return McpServerConfig.#refOf(name, entry);
266
- }
267
- static remove(workspaceRoot, name, only) {
268
- const candidates = McpServerConfig.files(workspaceRoot).filter(({ scope }) => !only || scope === only);
269
- for (const { scope } of candidates.reverse()) {
270
- const { file, key, map } = McpServerConfig.#parse(workspaceRoot, scope);
271
- if (!(name in map))
272
- continue;
273
- const next = { ...map };
274
- delete next[name];
275
- writeFileSync(file, `${JSON.stringify({ [key]: next }, null, 2)}
276
- `);
277
- return scope;
278
- }
279
- return false;
280
- }
281
- static #refOf(name, entry) {
282
- return {
283
- name,
284
- transport: entry.url ? "http" : "stdio",
285
- ...entry.command ? { command: entry.command } : {},
286
- ...entry.args ? { args: entry.args } : {},
287
- ...entry.url ? { url: entry.url } : {},
288
- ...entry.env ? { env: entry.env } : {},
289
- ...entry.headers ? { headers: entry.headers } : {},
290
- ...entry.oauth ? { oauth: entry.oauth } : {}
291
- };
292
- }
293
- static targetOf(ref) {
294
- return ref.url ?? [ref.command, ...ref.args ?? []].filter(Boolean).join(" ");
295
- }
296
- static problem(workspaceRoot) {
297
- for (const { file } of McpServerConfig.files(workspaceRoot)) {
298
- if (!existsSync2(file))
299
- continue;
300
- try {
301
- JSON.parse(readFileSync(file, "utf8"));
302
- } catch (error) {
303
- return `${file} is not valid JSON \u2014 ${String(error)}`;
304
- }
305
- }
306
- return;
307
- }
308
- static #parse(workspaceRoot, scope) {
309
- const file = McpServerConfig.file(workspaceRoot, scope);
310
- const empty = { file, key: "mcpServers", map: {} };
311
- if (!existsSync2(file))
312
- return empty;
313
- try {
314
- const parsed = JSON.parse(readFileSync(file, "utf8"));
315
- if (parsed.servers && !parsed.mcpServers)
316
- return { file, key: "servers", map: parsed.servers };
317
- return { ...empty, map: parsed.mcpServers ?? {} };
318
- } catch {
319
- return empty;
320
- }
321
- }
322
- }
323
-
324
212
  // pkgs/@akanjs/devkit/codeAgent/tools/McpOAuth.ts
325
213
  import { createHash, randomBytes } from "crypto";
326
214
 
@@ -546,8 +434,8 @@ class McpOAuthLoopback {
546
434
  }
547
435
 
548
436
  // pkgs/@akanjs/devkit/codeAgent/tools/McpTokenStore.ts
549
- import { chmodSync, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "fs";
550
- import path3 from "path";
437
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
438
+ import path from "path";
551
439
  class McpTokenStore {
552
440
  static file() {
553
441
  return akanCodePaths2.mcpAuthFile();
@@ -555,43 +443,75 @@ class McpTokenStore {
555
443
  static lockFile() {
556
444
  return `${McpTokenStore.file()}.lock`;
557
445
  }
558
- static read(name) {
559
- return McpTokenStore.#all()[name];
446
+ static read(owner) {
447
+ const origin = McpTokenStore.#originOf(owner.url);
448
+ if (!origin)
449
+ return;
450
+ const here = McpTokenStore.#all().filter((entry) => entry.origin === origin);
451
+ const entry = here.find((candidate) => candidate.name === owner.name) ?? here[0];
452
+ if (!entry)
453
+ return;
454
+ const { name: _name, origin: _origin, ...auth } = entry;
455
+ return auth;
560
456
  }
561
457
  static names() {
562
- return Object.keys(McpTokenStore.#all());
458
+ return [...new Set(McpTokenStore.#all().map((entry) => entry.name))];
563
459
  }
564
- static write(name, auth) {
565
- McpTokenStore.#save({ ...McpTokenStore.#all(), [name]: auth });
460
+ static write(owner, auth) {
461
+ const origin = McpTokenStore.#originOf(owner.url);
462
+ if (!origin)
463
+ throw new Error(`"${owner.name}" has no http(s) url to bind its token to.`);
464
+ const kept = McpTokenStore.#all().filter((entry) => entry.origin !== origin || entry.issuer !== auth.issuer && entry.name !== owner.name);
465
+ McpTokenStore.#save([...kept, { ...auth, name: owner.name, origin }]);
566
466
  }
567
- static clear(name) {
467
+ static clear(owner) {
468
+ const origin = McpTokenStore.#originOf(owner.url);
568
469
  const all = McpTokenStore.#all();
569
- if (!(name in all))
470
+ const kept = all.filter((entry) => entry.name !== owner.name && entry.origin !== origin);
471
+ if (kept.length === all.length)
570
472
  return false;
571
- delete all[name];
572
- McpTokenStore.#save(all);
473
+ McpTokenStore.#save(kept);
573
474
  return true;
574
475
  }
575
476
  static isExpired(auth) {
576
477
  return auth.expiresAt !== undefined && auth.expiresAt <= Date.now() + McpTokenStore.skewMs;
577
478
  }
578
479
  static skewMs = 60000;
480
+ static #originOf(url) {
481
+ if (!url)
482
+ return;
483
+ try {
484
+ const parsed = new URL(url);
485
+ return parsed.protocol === "http:" || parsed.protocol === "https:" ? parsed.origin : undefined;
486
+ } catch {
487
+ return;
488
+ }
489
+ }
490
+ static #keyOf(entry) {
491
+ return `${entry.origin} ${entry.issuer}`;
492
+ }
579
493
  static #all() {
580
494
  const file = McpTokenStore.file();
581
- if (!existsSync3(file))
582
- return {};
495
+ if (!existsSync(file))
496
+ return [];
583
497
  try {
584
- const parsed = JSON.parse(readFileSync2(file, "utf8"));
585
- return parsed.servers ?? {};
498
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
499
+ if (parsed.tokens)
500
+ return Object.values(parsed.tokens);
501
+ return Object.entries(parsed.servers ?? {}).flatMap(([name, auth]) => {
502
+ const origin = McpTokenStore.#originOf(auth.resource);
503
+ return origin ? [{ ...auth, name, origin }] : [];
504
+ });
586
505
  } catch {
587
- return {};
506
+ return [];
588
507
  }
589
508
  }
590
- static #save(servers) {
509
+ static #save(entries) {
591
510
  const file = McpTokenStore.file();
592
- mkdirSync2(path3.dirname(file), { recursive: true, mode: 448 });
511
+ mkdirSync(path.dirname(file), { recursive: true, mode: 448 });
512
+ const tokens = Object.fromEntries(entries.map((entry) => [McpTokenStore.#keyOf(entry), entry]));
593
513
  const temp = `${file}.${process.pid}.tmp`;
594
- writeFileSync2(temp, `${JSON.stringify({ servers }, null, 2)}
514
+ writeFileSync(temp, `${JSON.stringify({ tokens }, null, 2)}
595
515
  `, { mode: 384 });
596
516
  renameSync(temp, file);
597
517
  chmodSync(file, 384);
@@ -602,7 +522,7 @@ class McpTokenStore {
602
522
  class McpSignIn {
603
523
  static #refreshing = new Map;
604
524
  static async token(ref, onNotice) {
605
- const stored = McpTokenStore.read(ref.name);
525
+ const stored = McpTokenStore.read(ref);
606
526
  if (!stored)
607
527
  return;
608
528
  if (!McpTokenStore.isExpired(stored))
@@ -610,7 +530,7 @@ class McpSignIn {
610
530
  return await McpSignIn.#refreshOnce(ref, stored, onNotice);
611
531
  }
612
532
  static async retryToken(ref, refused, onNotice) {
613
- const stored = McpTokenStore.read(ref.name);
533
+ const stored = McpTokenStore.read(ref);
614
534
  if (!stored)
615
535
  return;
616
536
  if (stored.accessToken !== refused && !McpTokenStore.isExpired(stored))
@@ -618,7 +538,7 @@ class McpSignIn {
618
538
  return await McpSignIn.#refreshOnce(ref, stored, onNotice);
619
539
  }
620
540
  static async#refreshOnce(ref, stored, onNotice) {
621
- const key = `${ref.name}
541
+ const key = `${stored.issuer}
622
542
  ${stored.refreshToken}`;
623
543
  let pending = McpSignIn.#refreshing.get(key);
624
544
  if (!pending) {
@@ -632,7 +552,7 @@ ${stored.refreshToken}`;
632
552
  return;
633
553
  try {
634
554
  return await ConfigLock.run(McpTokenStore.lockFile(), async () => {
635
- const current = McpTokenStore.read(ref.name);
555
+ const current = McpTokenStore.read(ref);
636
556
  if (!current)
637
557
  return;
638
558
  if (current.accessToken !== stored.accessToken && !McpTokenStore.isExpired(current))
@@ -645,7 +565,7 @@ ${stored.refreshToken}`;
645
565
  };
646
566
  const tokens = await McpOAuth.refresh(server, current);
647
567
  const { expiresAt: _spent, ...grant } = current;
648
- McpTokenStore.write(ref.name, { ...grant, ...tokens });
568
+ McpTokenStore.write(ref, { ...grant, ...tokens });
649
569
  return tokens.accessToken;
650
570
  });
651
571
  } catch (error) {
@@ -658,7 +578,7 @@ ${stored.refreshToken}`;
658
578
  throw new Error(`"${ref.name}" is a stdio server: give it its credential through "env".`);
659
579
  const challenge = await McpSignIn.challenge(ref);
660
580
  const server = await McpOAuth.discover(ref.url, challenge);
661
- const stored = McpTokenStore.read(ref.name);
581
+ const stored = McpTokenStore.read(ref);
662
582
  const reusable = stored && stored.issuer === server.issuer && !ref.oauth?.clientId ? stored : undefined;
663
583
  const loopback = McpOAuthLoopback.bind(McpSignIn.#portOf(reusable?.redirectUri));
664
584
  try {
@@ -684,7 +604,7 @@ ${stored.refreshToken}`;
684
604
  redirectUri,
685
605
  ...tokens
686
606
  };
687
- McpTokenStore.write(ref.name, auth);
607
+ McpTokenStore.write(ref, auth);
688
608
  return auth;
689
609
  } finally {
690
610
  loopback.close();
@@ -735,4 +655,4 @@ ${stored.refreshToken}`;
735
655
  }
736
656
  }
737
657
 
738
- export { SubagentPool2, akanCodePaths2, McpServerConfig, McpTokenStore, McpSignIn, AkanCodeCompaction2 };
658
+ export { SubagentPool2, McpTokenStore, McpSignIn, AkanCodeCompaction2 };