@akanjs/cli 3.1.0-rc.2 → 3.1.0-rc.20

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 (100) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-q50k4s45.js → CodeAgent-n3tzjm91.js} +2 -2
  3. package/{CodeAgentRpcHost-p7h6n2hp.js → CodeAgentRpcHost-9g27hmer.js} +1 -1
  4. package/{CodeTui-62g35ztk.js → CodeTui-fnm9ft4d.js} +47 -4
  5. package/TunnelShare-661cxz5e.js +14 -0
  6. package/{agent.command-adfd5299.js → agent.command-3qxf4xcj.js} +5 -5
  7. package/akanCode.js +7 -5
  8. package/{application.command-hj3gv1rx.js → application.command-zfja7x4r.js} +12 -11
  9. package/{applicationBuildRunner-by10r9gf.js → applicationBuildRunner-vh4j6vdv.js} +16 -9
  10. package/buildBatch.proc.js +7 -7
  11. package/{cloud.command-k2fhaape.js → cloud.command-fcc8e8tp.js} +17 -16
  12. package/cloud.script-1xt3tnts.js +24 -0
  13. package/{code.command-kt5zgcc2.js → code.command-130bdmhe.js} +25 -12
  14. package/{context.command-8fgn42jw.js → context.command-0qx447mb.js} +17 -16
  15. package/context.runner-1vsjztjg.js +25 -0
  16. package/{dependencyScanner-06z2dmrr.js → dependencyScanner-3afj2vt1.js} +1 -1
  17. package/{guideline.command-3yxxr2mm.js → guideline.command-cv5bmrx2.js} +2 -2
  18. package/guidelines/agentRule/agentRule.instruction.md +25 -10
  19. package/guidelines/conventions/conventions.instruction.md +463 -1084
  20. package/guidelines/cssRule/cssRule.instruction.md +16 -1
  21. package/guidelines/fieldRule/fieldRule.instruction.md +74 -0
  22. package/guidelines/framework/framework.instruction.md +4 -7
  23. package/guidelines/mcpRule/mcpRule.instruction.md +16 -9
  24. package/guidelines/modelConstant/modelConstant.instruction.md +2 -1
  25. package/guidelines/modelStore/modelStore.instruction.md +16 -0
  26. package/guidelines/pageRule/pageRule.instruction.md +80 -0
  27. package/guidelines/queryRule/queryRule.instruction.md +47 -12
  28. package/guidelines/runtimeRule/runtimeRule.instruction.md +89 -2
  29. package/guidelines/ssrRule/ssrRule.instruction.md +13 -0
  30. package/guidelines/transportRule/transportRule.instruction.md +107 -8
  31. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +4 -4
  32. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +70 -7
  33. package/incrementalBuilder.proc.js +4 -4
  34. package/{index-nq045px5.js → index-192ha4xh.js} +356 -307
  35. package/{index-t7nws9mx.js → index-1djcjcre.js} +661 -448
  36. package/{index-h85cxfkg.js → index-1p98exm2.js} +2 -2
  37. package/{index-hnby7p9n.js → index-1xj2t7cb.js} +7 -7
  38. package/{index-wa5jbxj1.js → index-2mrn1mrg.js} +1 -0
  39. package/{index-58vvz603.js → index-35hc95h5.js} +1 -1
  40. package/{index-tv8fjaba.js → index-4mhy6qme.js} +4 -4
  41. package/{index-rk9sdys3.js → index-5edzv8fn.js} +5 -5
  42. package/{index-k9rrten6.js → index-5nd1wtkv.js} +92 -94
  43. package/index-62md4dwy.js +260 -0
  44. package/{index-kc8z134d.js → index-665zp9rs.js} +38 -15
  45. package/{index-jwqtchha.js → index-86jt2a0e.js} +1 -1
  46. package/{index-d2242ksy.js → index-at7bz0xq.js} +3 -0
  47. package/{index-sqfdmb5b.js → index-awbdfcf2.js} +4 -4
  48. package/{index-azh29dc8.js → index-axs61rna.js} +19 -14
  49. package/{index-3hx1z96c.js → index-bqbf654f.js} +1 -1
  50. package/{index-6726qr1m.js → index-cpb3nvma.js} +57 -58
  51. package/{index-pyxn1b53.js → index-d72hfmdm.js} +13 -13
  52. package/{index-8zdwpxef.js → index-dye8pnxx.js} +119 -81
  53. package/{index-z507nzhg.js → index-fmzcs8v6.js} +4 -4
  54. package/{index-3reaaa1h.js → index-fyq1z6kt.js} +29 -27
  55. package/{index-0909wckt.js → index-g1mbppa9.js} +238 -236
  56. package/{index-fjsv10hd.js → index-hsadfb6c.js} +7 -7
  57. package/{index-tz5evhdr.js → index-j237xtew.js} +6 -6
  58. package/{index-nq2ja5e0.js → index-j4mkhz93.js} +3 -3
  59. package/{index-31ce9vhg.js → index-jw1zm273.js} +28 -30
  60. package/{index-q958tqqg.js → index-m9jj544v.js} +1 -1
  61. package/{index-8935h3n1.js → index-mdjc93e1.js} +1 -1
  62. package/{index-bea2gwc6.js → index-pydbnfez.js} +2 -2
  63. package/{index-20cebtth.js → index-qtfmtcrw.js} +17 -15
  64. package/{index-sby8fe1p.js → index-qwa5k1j8.js} +1 -1
  65. package/{index-e9prnmyt.js → index-tamvyvj3.js} +3 -3
  66. package/{index-rhbabmja.js → index-trpasv9q.js} +260 -259
  67. package/{index-2ahj896a.js → index-tvehn2sp.js} +1 -1
  68. package/{index-2etqq75t.js → index-va06nr10.js} +1090 -1078
  69. package/{index-g0vwzy9m.js → index-vk0pa0mn.js} +20 -21
  70. package/{index-xpdgxsj5.js → index-w44cy4vs.js} +2216 -2216
  71. package/index.js +22 -22
  72. package/{library.command-8tw59xzj.js → library.command-erp2f56n.js} +3 -3
  73. package/{localRegistry.command-tf3dmznd.js → localRegistry.command-hj3p16p5.js} +15 -14
  74. package/{module.command-9vm8hffy.js → module.command-gs2r615e.js} +5 -5
  75. package/{package.command-erbxe2tz.js → package.command-j10r76ax.js} +4 -4
  76. package/package.json +21 -21
  77. package/{page.command-jpavcj0p.js → page.command-4h4a8pnh.js} +3 -3
  78. package/{pipeline.command-b8rzvjvv.js → pipeline.command-a2nrk26m.js} +3 -3
  79. package/{primitive.command-sm32chzk.js → primitive.command-w6t0asqz.js} +6 -6
  80. package/{projectTypecheck-jamtx95x.js → projectTypecheck-f534enqj.js} +1 -1
  81. package/{quality.command-pkd17n6y.js → quality.command-77x7vbbx.js} +4 -4
  82. package/{repair.command-8y4mq6hs.js → repair.command-y6sstev7.js} +5 -5
  83. package/{scalar.command-q8khmyx5.js → scalar.command-20b8cy0k.js} +4 -4
  84. package/skills/akan-code/SKILL.md +4 -0
  85. package/skills/akan-store/SKILL.md +2 -1
  86. package/{subspace.command-51n0ykbx.js → subspace.command-baz73jpk.js} +11 -10
  87. package/templates/appSample/lib/task/Task.Util.tsx +7 -7
  88. package/templates/appSample/lib/task/Task.Zone.tsx +1 -1
  89. package/templates/appSample/ui/QuantityControl.tsx +2 -2
  90. package/templates/crudSinglePage/page.tsx +1 -1
  91. package/templates/lib/cnst.ts +0 -1
  92. package/templates/workspaceRoot/.gitignore.template +23 -52
  93. package/templates/workspaceRoot/biome.json.template +1 -1
  94. package/{tunnel.command-7820vtxq.js → tunnel.command-2kw8vt9g.js} +8 -7
  95. package/{workflow.command-n5sv4wqz.js → workflow.command-2djwmpqf.js} +10 -10
  96. package/{workspace.command-zdy60jh8.js → workspace.command-jqs7vjhe.js} +29 -28
  97. package/TunnelShare-f1egrktx.js +0 -13
  98. package/cloud.script-z8p5dz7e.js +0 -23
  99. package/context.runner-hnh0rg7m.js +0 -24
  100. package/index-n68jx79w.js +0 -120
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-31ce9vhg.js";
5
+ } from "./index-jw1zm273.js";
6
6
  import {
7
7
  generatedFilesForSync,
8
8
  createPassedPrimitiveReport,
9
9
  scalarChangedFiles
10
- } from "./index-rhbabmja.js";
10
+ } from "./index-trpasv9q.js";
11
11
  import {
12
12
  pluralizeName
13
13
  } from "./index-nz8prx9g.js";
@@ -22,26 +22,26 @@ import {
22
22
  renderWorkflowApply,
23
23
  renderWorkflowValidation,
24
24
  renderWorkflowRunArtifact
25
- } from "./index-rhbabmja.js";
25
+ } from "./index-trpasv9q.js";
26
26
  import {
27
27
  AkanContextAnalyzer
28
- } from "./index-rk9sdys3.js";
28
+ } from "./index-5edzv8fn.js";
29
29
  import {
30
30
  CommandContainer,
31
31
  runner
32
- } from "./index-31ce9vhg.js";
32
+ } from "./index-jw1zm273.js";
33
33
  import {
34
34
  ModuleScript
35
- } from "./index-z507nzhg.js";
35
+ } from "./index-fmzcs8v6.js";
36
36
  import {
37
37
  PrimitiveScript
38
- } from "./index-sqfdmb5b.js";
38
+ } from "./index-awbdfcf2.js";
39
39
  import {
40
40
  spawnShell
41
- } from "./index-nq2ja5e0.js";
41
+ } from "./index-j4mkhz93.js";
42
42
  import {
43
43
  ScalarScript
44
- } from "./index-h85cxfkg.js";
44
+ } from "./index-1p98exm2.js";
45
45
 
46
46
  // pkgs/@akanjs/cli/workflow/workflow.runner.ts
47
47
  import { mkdir, readFile, writeFile } from "fs/promises";
@@ -250,6 +250,7 @@ class CodeTuiCommands2 {
250
250
  { name: "effort", desc: "how hard the model thinks before it answers", arg: "<level>" },
251
251
  { name: "thinking", desc: "show the model's reasoning, or fold it away again" },
252
252
  { name: "compact", desc: "summarise the conversation to free the window", arg: "[notes]" },
253
+ { name: "autocompact", desc: "how full the window gets before it is summarised", arg: "[<percent>]" },
253
254
  { name: "abort", desc: "stop the running turn" },
254
255
  { name: "clear", desc: "wipe the screen; the model keeps the conversation" },
255
256
  { name: "name", desc: "name this session", arg: "<text>" },
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  AppInfo
4
- } from "./index-2etqq75t.js";
4
+ } from "./index-va06nr10.js";
5
5
 
6
6
  // pkgs/@akanjs/devkit/slicePlanner.ts
7
7
  class SlicePlanner {
@@ -1,16 +1,16 @@
1
1
  // @bun
2
2
  import {
3
3
  jsonText
4
- } from "./index-rhbabmja.js";
4
+ } from "./index-trpasv9q.js";
5
5
  import {
6
6
  akanMcpInstallTargets
7
- } from "./index-rk9sdys3.js";
7
+ } from "./index-5edzv8fn.js";
8
8
  import {
9
9
  script
10
- } from "./index-31ce9vhg.js";
10
+ } from "./index-jw1zm273.js";
11
11
  import {
12
12
  ContextRunner2
13
- } from "./index-pyxn1b53.js";
13
+ } from "./index-d72hfmdm.js";
14
14
 
15
15
  // pkgs/@akanjs/cli/context/context.script.ts
16
16
  import { Logger } from "akanjs/common";
@@ -10,7 +10,7 @@ import {
10
10
  isScannedRootEntry,
11
11
  AppExecutor,
12
12
  LibExecutor
13
- } from "./index-2etqq75t.js";
13
+ } from "./index-va06nr10.js";
14
14
  import {
15
15
  FileSys2
16
16
  } from "./index-52w0fvh8.js";
@@ -23,7 +23,7 @@ import {
23
23
  workflowPathsForPlan,
24
24
  workflowRunArtifactPath,
25
25
  workflowSyncDir
26
- } from "./index-rhbabmja.js";
26
+ } from "./index-trpasv9q.js";
27
27
 
28
28
  // pkgs/@akanjs/devkit/akanContext.ts
29
29
  import { readdir } from "fs/promises";
@@ -79,7 +79,7 @@ var upsertCodexMcpServerBlock = (existing, block, { force = false } = {}) => {
79
79
  if (!match) {
80
80
  if (!existing.trim())
81
81
  return nextBlock;
82
- return `${existing.replace(/\s*$/, "")}
82
+ return `${existing.trimEnd()}
83
83
 
84
84
  ${nextBlock}`;
85
85
  }
@@ -532,14 +532,14 @@ class AkanContextAnalyzer {
532
532
  if (frameworkDeclared.size > 0) {
533
533
  const agentsMd = await Bun.file(path.join(workspace.workspaceRoot, "AGENTS.md")).text().catch(() => "");
534
534
  const listed = listedByImport(sectionOf(agentsMd, "## Recipes")).get("akanjs/ui") ?? new Set;
535
- pushIndexDiagnostic("AGENTS.md", [...frameworkDeclared].filter((name) => !listed.has(name)).sort(), [...listed].filter((name) => !frameworkDeclared.has(name)).sort(), "akan agent install agents-md");
535
+ pushIndexDiagnostic("AGENTS.md", [...frameworkDeclared].filter((name) => !listed.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0), [...listed].filter((name) => !frameworkDeclared.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0), "akan agent install agents-md");
536
536
  }
537
537
  for (const sys of [...context.apps, ...context.libs]) {
538
538
  const own = declaredByImport.get(`@${sys.path}/ui`) ?? new Set;
539
539
  const scopeMd = await Bun.file(path.join(workspace.workspaceRoot, sys.path, "AGENTS.md")).text().catch(() => "");
540
540
  const groups = listedByImport(sectionOf(scopeMd, "## Recipes In Scope"));
541
541
  const ownListed = groups.get(`@${sys.path}/ui`) ?? new Set;
542
- const missing = [...own].filter((name) => !ownListed.has(name)).sort();
542
+ const missing = [...own].filter((name) => !ownListed.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
543
543
  const stale = [...groups.entries()].flatMap(([importFrom, names]) => [...names].filter((name) => !(declaredByImport.get(importFrom) ?? new Set).has(name))).sort();
544
544
  pushIndexDiagnostic(`${sys.path}/AGENTS.md`, missing, stale, `akan sync ${sys.name}`);
545
545
  }
@@ -71,13 +71,6 @@ Caused by: ${ApplicationBuildReporter.formatError(error.cause, workspaceRoot)}`
71
71
  }
72
72
  }
73
73
 
74
- // pkgs/@akanjs/devkit/frontendBuild/hmrWatcher.ts
75
- import fs from "fs";
76
- import path5 from "path";
77
-
78
- // pkgs/@akanjs/devkit/frontendBuild/hmrChangeClassifier.ts
79
- import path3 from "path";
80
-
81
74
  // pkgs/@akanjs/devkit/akanApp/devHostPolicy.ts
82
75
  import path2 from "path";
83
76
  var UNAVAILABLE_REDIS_HOST = "redis-tunnel-unavailable.invalid";
@@ -293,7 +286,83 @@ var mergeInvalidateMessages = (current, next) => {
293
286
  var buildStatusReplaySequence = (pendingReplay, latestByPhase) => [...pendingReplay, ...latestByPhase.values()];
294
287
  var filesChangedSince = (before, after) => [...before].filter(([file, stamp]) => after.get(file) !== stamp).map(([file]) => file);
295
288
 
289
+ // pkgs/@akanjs/devkit/frontendBuild/watchRootResolver.ts
290
+ import fs from "fs";
291
+ import { readFile } from "fs/promises";
292
+ import path3 from "path";
293
+
294
+ class WatchRootResolver {
295
+ #app;
296
+ constructor(app) {
297
+ this.#app = app;
298
+ }
299
+ async resolve() {
300
+ const tsconfig = await this.#app.getTsConfig();
301
+ const appDir = path3.resolve(this.#app.cwdPath);
302
+ const appsContainer = path3.dirname(appDir);
303
+ const libsContainer = path3.resolve(this.#app.workspace.workspaceRoot, "libs");
304
+ const libRoots = (await this.#resolveLibDeps(libsContainer))?.map((name) => path3.join(libsContainer, name)).filter((dir) => fs.existsSync(dir));
305
+ const set = new Set;
306
+ set.add(path3.resolve(`${this.#app.cwdPath}/page`));
307
+ for (const targets of Object.values(tsconfig.compilerOptions.paths ?? {})) {
308
+ for (const target of targets) {
309
+ if (!target)
310
+ continue;
311
+ if (path3.isAbsolute(target))
312
+ continue;
313
+ const cleaned = target.replace(/\/?\*+.*$/, "").replace(/\/[^/]+\.[^/]+$/, "");
314
+ const resolved = path3.resolve(this.#app.workspace.workspaceRoot, cleaned);
315
+ if (resolved === libsContainer && libRoots) {
316
+ for (const root of libRoots)
317
+ set.add(root);
318
+ continue;
319
+ }
320
+ const root = resolved === appsContainer ? appDir : resolved;
321
+ if (fs.existsSync(root))
322
+ set.add(root);
323
+ }
324
+ }
325
+ return [...set];
326
+ }
327
+ async#resolveLibDeps(libsContainer) {
328
+ const scanInfo = this.#app.getScanInfo({ allowEmpty: true });
329
+ if (scanInfo?.type === "app")
330
+ return scanInfo.libDeps;
331
+ const direct = await WatchRootResolver.#readManifestLibDeps(path3.join(this.#app.cwdPath, "akan.app.json"));
332
+ if (!direct)
333
+ return null;
334
+ const closure = new Set;
335
+ const queue = [...direct];
336
+ while (queue.length > 0) {
337
+ const name = queue.shift();
338
+ if (!name || closure.has(name))
339
+ continue;
340
+ closure.add(name);
341
+ const nested = await WatchRootResolver.#readManifestLibDeps(path3.join(libsContainer, name, "akan.lib.json"));
342
+ if (!nested)
343
+ return null;
344
+ queue.push(...nested);
345
+ }
346
+ return [...closure];
347
+ }
348
+ static async#readManifestLibDeps(manifestPath) {
349
+ try {
350
+ const parsed = JSON.parse(await readFile(manifestPath, "utf8"));
351
+ if (!Array.isArray(parsed.libDeps))
352
+ return null;
353
+ return parsed.libDeps.filter((name) => typeof name === "string" && name.length > 0);
354
+ } catch {
355
+ return null;
356
+ }
357
+ }
358
+ }
359
+
360
+ // pkgs/@akanjs/devkit/frontendBuild/hmrWatcher.ts
361
+ import fs2 from "fs";
362
+ import path6 from "path";
363
+
296
364
  // pkgs/@akanjs/devkit/frontendBuild/hmrChangeClassifier.ts
365
+ import path4 from "path";
297
366
  var CSS_EXTS = new Set([".css"]);
298
367
  var CONFIG_BASENAMES = new Set(["akan.config.ts", "bunfig.toml", "tsconfig.json", "package.json"]);
299
368
 
@@ -301,10 +370,10 @@ class HmrChangeClassifier {
301
370
  classify(abs) {
302
371
  if (this.#isUninteresting(abs))
303
372
  return "ignore";
304
- const base = path3.basename(abs);
373
+ const base = path4.basename(abs);
305
374
  if (CONFIG_BASENAMES.has(base))
306
375
  return "config";
307
- const ext = path3.extname(abs).toLowerCase();
376
+ const ext = path4.extname(abs).toLowerCase();
308
377
  if (CSS_EXTS.has(ext))
309
378
  return "css";
310
379
  if (SOURCE_EXTS.has(ext))
@@ -312,16 +381,16 @@ class HmrChangeClassifier {
312
381
  return "ignore";
313
382
  }
314
383
  #isUninteresting(abs) {
315
- const base = path3.basename(abs);
384
+ const base = path4.basename(abs);
316
385
  if (!base)
317
386
  return true;
318
387
  if (base.startsWith("."))
319
388
  return true;
320
389
  if (base.endsWith("~") || base.endsWith(".swp") || base.endsWith(".swx") || base.endsWith(".tmp"))
321
390
  return true;
322
- if (abs.includes(`${path3.sep}node_modules${path3.sep}`))
391
+ if (abs.includes(`${path4.sep}node_modules${path4.sep}`))
323
392
  return true;
324
- if (abs.includes(`${path3.sep}.akan${path3.sep}`))
393
+ if (abs.includes(`${path4.sep}.akan${path4.sep}`))
325
394
  return true;
326
395
  return false;
327
396
  }
@@ -329,7 +398,7 @@ class HmrChangeClassifier {
329
398
 
330
399
  // pkgs/@akanjs/devkit/frontendBuild/sourceMtimeIndex.ts
331
400
  import { readdir, stat } from "fs/promises";
332
- import path4 from "path";
401
+ import path5 from "path";
333
402
  var UNREADABLE = Number.NaN;
334
403
 
335
404
  class SourceMtimeIndex {
@@ -392,7 +461,7 @@ class SourceMtimeIndex {
392
461
  if (!this.#primed)
393
462
  return;
394
463
  await Promise.all(paths.map(async (file) => {
395
- const abs = path4.resolve(file);
464
+ const abs = path5.resolve(file);
396
465
  const stats = await stat(abs).catch(() => null);
397
466
  if (!stats?.isFile()) {
398
467
  this.#files.delete(abs);
@@ -478,7 +547,7 @@ class SourceMtimeIndex {
478
547
  for (const entry of entries) {
479
548
  if (SourceMtimeIndex.#skipDirent(entry.name))
480
549
  continue;
481
- const abs = path4.join(dir, entry.name);
550
+ const abs = path5.join(dir, entry.name);
482
551
  if (entry.isDirectory()) {
483
552
  descend.push(abs);
484
553
  continue;
@@ -505,7 +574,7 @@ class SourceMtimeIndex {
505
574
  }
506
575
  if (known) {
507
576
  for (const abs of [...this.#files.keys()]) {
508
- if (present.has(abs) || path4.dirname(abs) !== dir)
577
+ if (present.has(abs) || path5.dirname(abs) !== dir)
509
578
  continue;
510
579
  this.#files.delete(abs);
511
580
  changed?.add(abs);
@@ -523,7 +592,7 @@ class SourceMtimeIndex {
523
592
  this.#unsettled.delete(dir);
524
593
  }
525
594
  #forget(dir) {
526
- const prefix = `${dir}${path4.sep}`;
595
+ const prefix = `${dir}${path5.sep}`;
527
596
  this.#dirs.delete(dir);
528
597
  this.#unreadable.delete(dir);
529
598
  this.#unsettled.delete(dir);
@@ -561,8 +630,8 @@ class SourceMtimeIndex {
561
630
  return !name || name.startsWith(".") || name === "node_modules";
562
631
  }
563
632
  static #pruneNestedRoots(roots) {
564
- const resolved = [...new Set(roots.map((root) => path4.resolve(root)))].sort();
565
- return resolved.filter((root) => !resolved.some((other) => other !== root && root.startsWith(`${other}${path4.sep}`)));
633
+ const resolved = [...new Set(roots.map((root) => path5.resolve(root)))].sort();
634
+ return resolved.filter((root) => !resolved.some((other) => other !== root && root.startsWith(`${other}${path5.sep}`)));
566
635
  }
567
636
  }
568
637
 
@@ -587,7 +656,7 @@ class HmrWatcher {
587
656
  #reportedCompensating = false;
588
657
  #reportedGaps = "";
589
658
  constructor(opts) {
590
- this.#roots = [...new Set(opts.roots.map((r) => path5.resolve(r)))];
659
+ this.#roots = [...new Set(opts.roots.map((r) => path6.resolve(r)))];
591
660
  this.#debounceMs = opts.debounceMs ?? HmrWatcher.#envDebounceMs() ?? 30;
592
661
  this.#verifyDelayMs = opts.verifyDelayMs ?? 250;
593
662
  this.#onBatch = opts.onBatch;
@@ -600,10 +669,10 @@ class HmrWatcher {
600
669
  async start() {
601
670
  for (const root of this.#roots) {
602
671
  try {
603
- const w = fs.watch(root, { recursive: true, persistent: false }, (_event, filename) => {
672
+ const w = fs2.watch(root, { recursive: true, persistent: false }, (_event, filename) => {
604
673
  if (!filename)
605
674
  return;
606
- const abs = path5.resolve(root, filename.toString());
675
+ const abs = path6.resolve(root, filename.toString());
607
676
  this.#queue(abs);
608
677
  });
609
678
  w.on("error", (err) => {
@@ -729,7 +798,7 @@ class HmrWatcher {
729
798
  }
730
799
  #reportCoverageGaps() {
731
800
  const gaps = this.#index.coverageGaps;
732
- const key = gaps.map((gap) => `${gap.code}:${gap.path}`).sort().join("|");
801
+ const key = gaps.map((gap) => `${gap.code}:${gap.path}`).sort((a, b) => a < b ? -1 : a > b ? 1 : 0).join("|");
733
802
  if (key === this.#reportedGaps)
734
803
  return;
735
804
  this.#reportedGaps = key;
@@ -767,75 +836,4 @@ class HmrWatcher {
767
836
  }
768
837
  }
769
838
 
770
- // pkgs/@akanjs/devkit/frontendBuild/watchRootResolver.ts
771
- import fs2 from "fs";
772
- import { readFile } from "fs/promises";
773
- import path6 from "path";
774
-
775
- class WatchRootResolver {
776
- #app;
777
- constructor(app) {
778
- this.#app = app;
779
- }
780
- async resolve() {
781
- const tsconfig = await this.#app.getTsConfig();
782
- const appDir = path6.resolve(this.#app.cwdPath);
783
- const appsContainer = path6.dirname(appDir);
784
- const libsContainer = path6.resolve(this.#app.workspace.workspaceRoot, "libs");
785
- const libRoots = (await this.#resolveLibDeps(libsContainer))?.map((name) => path6.join(libsContainer, name)).filter((dir) => fs2.existsSync(dir));
786
- const set = new Set;
787
- set.add(path6.resolve(`${this.#app.cwdPath}/page`));
788
- for (const targets of Object.values(tsconfig.compilerOptions.paths ?? {})) {
789
- for (const target of targets) {
790
- if (!target)
791
- continue;
792
- if (path6.isAbsolute(target))
793
- continue;
794
- const cleaned = target.replace(/\/?\*+.*$/, "").replace(/\/[^/]+\.[^/]+$/, "");
795
- const resolved = path6.resolve(this.#app.workspace.workspaceRoot, cleaned);
796
- if (resolved === libsContainer && libRoots) {
797
- for (const root of libRoots)
798
- set.add(root);
799
- continue;
800
- }
801
- const root = resolved === appsContainer ? appDir : resolved;
802
- if (fs2.existsSync(root))
803
- set.add(root);
804
- }
805
- }
806
- return [...set];
807
- }
808
- async#resolveLibDeps(libsContainer) {
809
- const scanInfo = this.#app.getScanInfo({ allowEmpty: true });
810
- if (scanInfo?.type === "app")
811
- return scanInfo.libDeps;
812
- const direct = await WatchRootResolver.#readManifestLibDeps(path6.join(this.#app.cwdPath, "akan.app.json"));
813
- if (!direct)
814
- return null;
815
- const closure = new Set;
816
- const queue = [...direct];
817
- while (queue.length > 0) {
818
- const name = queue.shift();
819
- if (!name || closure.has(name))
820
- continue;
821
- closure.add(name);
822
- const nested = await WatchRootResolver.#readManifestLibDeps(path6.join(libsContainer, name, "akan.lib.json"));
823
- if (!nested)
824
- return null;
825
- queue.push(...nested);
826
- }
827
- return [...closure];
828
- }
829
- static async#readManifestLibDeps(manifestPath) {
830
- try {
831
- const parsed = JSON.parse(await readFile(manifestPath, "utf8"));
832
- if (!Array.isArray(parsed.libDeps))
833
- return null;
834
- return parsed.libDeps.filter((name) => typeof name === "string" && name.length > 0);
835
- } catch {
836
- return null;
837
- }
838
- }
839
- }
840
-
841
839
  export { ApplicationBuildReporter, UNAVAILABLE_REDIS_HOST, redisTunnelPolicy, BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS, SOURCE_EXTS, shouldRestartBackendByDevPlan, shouldRestartBuilderByDevPlan, shouldAbandonBackendRecovery, normalizeBackendReportedGeneration, shouldRestartDevHostByDevPlan, devHostStateOf, isLegacyBackendFallbackFile, shouldMarkBuildPhaseRecovered, shouldKeepBuildFailure, createBackendBuildStatus, backendRestartReasonFromMessage, mergeBackendRestartReasons, shouldReplaceLastGoodMessage, shouldQueueBuildStatusReplay, hasBuildFailureForGeneration, decideBuilderRssRecycle, decideBuilderRssSettle, decideIdleSuspend, resolveIdleSuspendMs, hasAnyBuildFailure, shouldRefreshConfigOnIdleWake, shouldHoldForReturningBuilder, shouldWarnBuilderRssCeilingTight, isRssCeilingUnreachable, shouldRelayRecycledFrontendState, mergeInvalidateMessages, buildStatusReplaySequence, filesChangedSince, HmrWatcher, WatchRootResolver };
@@ -0,0 +1,260 @@
1
+ // @bun
2
+ // pkgs/@akanjs/devkit/frontendBuild/cssBlockParser.ts
3
+ class CssBlockParser {
4
+ #css;
5
+ #stack = [{ kind: "block", prelude: "", atRule: null, nodes: [] }];
6
+ #pendingParts = [];
7
+ #segmentStart = 0;
8
+ #parenDepth = 0;
9
+ constructor(css) {
10
+ this.#css = css;
11
+ }
12
+ static parse(css) {
13
+ return new CssBlockParser(css).#run();
14
+ }
15
+ static walk(root, context, visit) {
16
+ const stack = [{ nodes: root.nodes, idx: 0, context }];
17
+ while (stack.length > 0) {
18
+ const frame = stack[stack.length - 1];
19
+ const node = frame.nodes[frame.idx];
20
+ if (!node) {
21
+ stack.pop();
22
+ continue;
23
+ }
24
+ frame.idx += 1;
25
+ const childContext = visit(node, frame.context);
26
+ if (node.kind === "block" && childContext !== null)
27
+ stack.push({ nodes: node.nodes, idx: 0, context: childContext });
28
+ }
29
+ }
30
+ #run() {
31
+ const css = this.#css;
32
+ let idx = 0;
33
+ while (idx < css.length) {
34
+ const char = css[idx];
35
+ if (char === "/" && css[idx + 1] === "*") {
36
+ this.#pendingParts.push(css.slice(this.#segmentStart, idx));
37
+ const end = css.indexOf("*/", idx + 2);
38
+ idx = end === -1 ? css.length : end + 2;
39
+ this.#segmentStart = idx;
40
+ continue;
41
+ }
42
+ if (char === "\\") {
43
+ idx += 2;
44
+ continue;
45
+ }
46
+ if (char === '"' || char === "'") {
47
+ idx = this.#skipString(idx);
48
+ continue;
49
+ }
50
+ if (char === "(")
51
+ this.#parenDepth += 1;
52
+ else if (char === ")")
53
+ this.#parenDepth = Math.max(0, this.#parenDepth - 1);
54
+ else if (char === "{")
55
+ this.#openBlock(idx);
56
+ else if (char === "}")
57
+ this.#closeBlock(idx);
58
+ else if (char === ";" && this.#parenDepth === 0)
59
+ this.#endStatement(idx);
60
+ idx += 1;
61
+ }
62
+ this.#endStatement(css.length);
63
+ return this.#stack[0];
64
+ }
65
+ get #current() {
66
+ return this.#stack[this.#stack.length - 1];
67
+ }
68
+ #skipString(start) {
69
+ const css = this.#css;
70
+ const quote = css[start];
71
+ let idx = start + 1;
72
+ while (idx < css.length) {
73
+ const char = css[idx];
74
+ if (char === "\\")
75
+ idx += 2;
76
+ else if (char === quote)
77
+ return idx + 1;
78
+ else if (char === `
79
+ `)
80
+ return idx;
81
+ else
82
+ idx += 1;
83
+ }
84
+ return css.length;
85
+ }
86
+ #takeSegment(end) {
87
+ const text = this.#pendingParts.join("") + this.#css.slice(this.#segmentStart, end);
88
+ this.#pendingParts = [];
89
+ this.#segmentStart = end + 1;
90
+ return text.trim();
91
+ }
92
+ #openBlock(idx) {
93
+ const prelude = this.#takeSegment(idx);
94
+ const block = { kind: "block", prelude, atRule: CssBlockParser.#atRuleOf(prelude), nodes: [] };
95
+ this.#current.nodes.push(block);
96
+ this.#stack.push(block);
97
+ this.#parenDepth = 0;
98
+ }
99
+ #closeBlock(idx) {
100
+ this.#endStatement(idx);
101
+ if (this.#stack.length > 1)
102
+ this.#stack.pop();
103
+ this.#parenDepth = 0;
104
+ }
105
+ #endStatement(idx) {
106
+ const text = this.#takeSegment(idx);
107
+ if (!text || text.startsWith("@"))
108
+ return;
109
+ const colon = text.indexOf(":");
110
+ if (colon <= 0)
111
+ return;
112
+ const property = text.slice(0, colon).trim();
113
+ if (!/^[\w-]+$/.test(property))
114
+ return;
115
+ this.#current.nodes.push({ kind: "declaration", property, value: text.slice(colon + 1).trim() });
116
+ }
117
+ static #atRuleOf(prelude) {
118
+ return prelude.match(/^@[\w-]+/)?.[0].toLowerCase() ?? null;
119
+ }
120
+ }
121
+
122
+ // pkgs/@akanjs/devkit/frontendBuild/styleContract.ts
123
+ var countBlocking = (violations) => violations.theme.length;
124
+ var formatStyleContract = (violations) => violations.theme.flatMap((theme) => [
125
+ ` [error] contrast ${theme.scope} ${theme.pair} = ${theme.ratio}:1 (min ${theme.threshold}:1)`,
126
+ ` \u2192 ${theme.suggestion}`
127
+ ]).join(`
128
+ `);
129
+
130
+ // pkgs/@akanjs/devkit/frontendBuild/themeValidator.ts
131
+ var PAIRS = [
132
+ { base: "background", fg: "foreground", threshold: 4.5 },
133
+ { base: "primary", fg: "primary-foreground", threshold: 4.5 },
134
+ { base: "secondary", fg: "secondary-foreground", threshold: 4.5 },
135
+ { base: "accent", fg: "accent-foreground", threshold: 4.5 },
136
+ { base: "neutral", fg: "neutral-foreground", threshold: 4.5 },
137
+ { base: "card", fg: "card-foreground", threshold: 4.5 },
138
+ { base: "popover", fg: "popover-foreground", threshold: 4.5 },
139
+ { base: "muted", fg: "muted-foreground", threshold: 3 },
140
+ { base: "info", fg: "info-foreground", threshold: 3 },
141
+ { base: "success", fg: "success-foreground", threshold: 3 },
142
+ { base: "warning", fg: "warning-foreground", threshold: 3 },
143
+ { base: "destructive", fg: "destructive-foreground", threshold: 3 },
144
+ { base: "open", fg: "open-foreground", threshold: 3 }
145
+ ];
146
+ var THEME_SCOPES = new Set([":root", '[data-theme="dark"]', '[data-theme="light"]']);
147
+ var CONDITIONAL_AT_RULES = new Set(["@media", "@supports", "@container"]);
148
+
149
+ class ThemeValidator {
150
+ validate(css) {
151
+ const tokensByScope = ThemeValidator.parseThemeTokens(css);
152
+ const violations = [];
153
+ for (const [scope, tokens] of Object.entries(tokensByScope)) {
154
+ const underlying = THEME_SCOPES.has(scope) ? null : [...THEME_SCOPES].find((name) => scope.endsWith(` ${name}`));
155
+ const effective = underlying ? ThemeValidator.#overlayPairs(tokensByScope[underlying] ?? {}, tokens) : tokens;
156
+ violations.push(...this.validateScope(effective, scope));
157
+ }
158
+ return violations;
159
+ }
160
+ validateScope(tokens, scope) {
161
+ const violations = [];
162
+ for (const { base, fg, threshold } of PAIRS) {
163
+ const bg = tokens[base];
164
+ const front = tokens[fg];
165
+ if (!bg || !front)
166
+ continue;
167
+ const bgRgb = ThemeValidator.parseHex(bg);
168
+ const fgRgb = ThemeValidator.parseHex(front);
169
+ if (!bgRgb || !fgRgb)
170
+ continue;
171
+ const ratio = ThemeValidator.contrastRatio(bgRgb, fgRgb);
172
+ if (ratio >= threshold)
173
+ continue;
174
+ violations.push({
175
+ scope,
176
+ pair: `${base} / ${fg}`,
177
+ background: bg,
178
+ foreground: front,
179
+ ratio: Math.round(ratio * 100) / 100,
180
+ threshold,
181
+ suggestion: `In ${scope}, --${base} (${bg}) against --${fg} (${front}) is ${ratio.toFixed(2)}:1, under the ${threshold}:1 minimum. Lighten or darken one of them until it clears.`
182
+ });
183
+ }
184
+ return violations;
185
+ }
186
+ static parseThemeTokens(css) {
187
+ const result = {};
188
+ CssBlockParser.walk(CssBlockParser.parse(css), "", (node, condition) => {
189
+ if (node.kind !== "block")
190
+ return null;
191
+ if (node.atRule === "@layer")
192
+ return condition;
193
+ if (node.atRule)
194
+ return CONDITIONAL_AT_RULES.has(node.atRule) ? node.prelude.replace(/\s+/g, " ") : null;
195
+ const scopes = node.prelude.split(",").map((selector) => ThemeValidator.#normalizeScope(selector)).filter((scope) => THEME_SCOPES.has(scope));
196
+ if (scopes.length === 0)
197
+ return null;
198
+ const tokens = ThemeValidator.#customProperties(node);
199
+ for (const scope of scopes) {
200
+ const key = condition ? `${condition} ${scope}` : scope;
201
+ result[key] = Object.assign(result[key] ?? {}, tokens);
202
+ }
203
+ return null;
204
+ });
205
+ return result;
206
+ }
207
+ static #customProperties(block) {
208
+ const tokens = {};
209
+ for (const node of block.nodes) {
210
+ if (node.kind === "declaration" && node.property.startsWith("--"))
211
+ tokens[node.property.slice(2)] = node.value;
212
+ }
213
+ return tokens;
214
+ }
215
+ static #overlayPairs(underlying, tokens) {
216
+ const effective = {};
217
+ for (const name of PAIRS.flatMap(({ base, fg }) => [base, fg])) {
218
+ const value = tokens[name] ?? underlying[name];
219
+ if (value)
220
+ effective[name] = value;
221
+ }
222
+ return effective;
223
+ }
224
+ static #normalizeScope(selector) {
225
+ return selector.replace(/\[data-theme=['"]?([\w-]+)['"]?\]/g, '[data-theme="$1"]').trim();
226
+ }
227
+ static parseHex(value) {
228
+ const v = value.trim();
229
+ if (!v.startsWith("#"))
230
+ return null;
231
+ const hex = v.slice(1);
232
+ let full;
233
+ if (hex.length === 3 || hex.length === 4)
234
+ full = hex.slice(0, 3).split("").map((c) => c + c).join("");
235
+ else if (hex.length === 6 || hex.length === 8)
236
+ full = hex.slice(0, 6);
237
+ else
238
+ return null;
239
+ if (!/^[0-9a-fA-F]{6}$/.test(full))
240
+ return null;
241
+ const n = Number.parseInt(full, 16);
242
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
243
+ }
244
+ static #relativeLuminance([r, g, b]) {
245
+ const channel = (c) => {
246
+ const s = c / 255;
247
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
248
+ };
249
+ return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
250
+ }
251
+ static contrastRatio(a, b) {
252
+ const la = ThemeValidator.#relativeLuminance(a);
253
+ const lb = ThemeValidator.#relativeLuminance(b);
254
+ const hi = Math.max(la, lb);
255
+ const lo = Math.min(la, lb);
256
+ return (hi + 0.05) / (lo + 0.05);
257
+ }
258
+ }
259
+
260
+ export { countBlocking, formatStyleContract, CssBlockParser, ThemeValidator };