@akanjs/cli 3.1.1-rc.16 → 3.1.1-rc.18

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 (118) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-23ewzxqa.js → CodeAgent-fbcq8vks.js} +2 -2
  3. package/{CodeTui-kc99fk78.js → CodeTui-0626gxqd.js} +1 -1
  4. package/TunnelShare-2p24xxza.js +14 -0
  5. package/agent.command-hpza0pg9.js +46 -0
  6. package/akanCode.js +5 -3
  7. package/{application.command-bvfd1680.js → application.command-3a7q1hs2.js} +11 -10
  8. package/{applicationBuildRunner-4ajaesk1.js → applicationBuildRunner-s7yt71j4.js} +5 -5
  9. package/buildBatch.proc.js +6 -6
  10. package/{cloud.command-f2w40fyy.js → cloud.command-4vg0pcea.js} +15 -14
  11. package/cloud.script-nkmeyhet.js +25 -0
  12. package/{code.command-dbhhnahn.js → code.command-fbntb67p.js} +6 -6
  13. package/commandManifest.json +1 -1
  14. package/{context.command-yswjwv6y.js → context.command-31rm54v0.js} +18 -18
  15. package/context.runner-w01a32ph.js +26 -0
  16. package/{guideline.command-ztx6dkpk.js → guideline.command-cv3by2ng.js} +3 -3
  17. package/guidelines/conventions/core.md +104 -0
  18. package/guidelines/conventions/rules/app.md +83 -0
  19. package/guidelines/conventions/rules/auth.md +45 -0
  20. package/guidelines/conventions/rules/config.md +56 -0
  21. package/guidelines/conventions/rules/constant.md +24 -0
  22. package/guidelines/conventions/rules/gates.md +31 -0
  23. package/guidelines/conventions/rules/layer.md +25 -0
  24. package/guidelines/conventions/rules/migration.md +27 -0
  25. package/guidelines/conventions/rules/module.md +90 -0
  26. package/guidelines/conventions/rules/page.md +56 -0
  27. package/guidelines/conventions/rules/sensitive.md +16 -0
  28. package/guidelines/conventions/rules/server.md +86 -0
  29. package/guidelines/conventions/rules/ssr.md +47 -0
  30. package/guidelines/conventions/rules/style.md +43 -0
  31. package/guidelines/conventions/rules/test.md +34 -0
  32. package/guidelines/conventions/rules/ts.md +95 -0
  33. package/guidelines/conventions/rules/tsx.md +75 -0
  34. package/guidelines/mcpRule/mcpRule.instruction.md +1 -1
  35. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +3 -3
  36. package/incrementalBuilder.proc.js +6 -6
  37. package/{index-xjwcp91m.js → index-05nxx4m5.js} +43 -12
  38. package/{index-k9k18vq9.js → index-0ht91675.js} +37 -59
  39. package/{index-er16p89s.js → index-0zwznvv1.js} +1 -1
  40. package/{index-76jwsm3g.js → index-0zyatd10.js} +2 -2
  41. package/{index-97fsvy66.js → index-12kzwak1.js} +3 -3
  42. package/{index-005dqc83.js → index-1dhf8ymv.js} +2 -2
  43. package/{index-00ke4phc.js → index-3gccwenr.js} +1 -1
  44. package/{index-2epb3wgh.js → index-3txrjt6n.js} +2 -2
  45. package/{index-7ndgffg4.js → index-57q1ayd2.js} +18 -1240
  46. package/index-5kh9scvs.js +514 -0
  47. package/index-5n5hds19.js +1246 -0
  48. package/{index-9sa6abze.js → index-6269mf2s.js} +10 -9
  49. package/{index-921cxqrd.js → index-64g9fsjy.js} +41 -12
  50. package/index-7zeb5r1p.js +653 -0
  51. package/{index-s4c2y5gs.js → index-8s8b4eba.js} +45 -4
  52. package/{index-4332q6yj.js → index-922k2zwq.js} +3 -3
  53. package/{index-m6qgr1rx.js → index-9ndw5d8j.js} +7 -7
  54. package/{index-xfp4dcnx.js → index-et6ce601.js} +1 -1
  55. package/{index-saj9cx3a.js → index-f5adsa58.js} +4 -4
  56. package/{index-vgt25eh1.js → index-fbewhg4g.js} +7 -32
  57. package/{index-ysyt782g.js → index-hm7x0c11.js} +4 -4
  58. package/{index-2p1brf5e.js → index-hvv5rnaq.js} +2 -2
  59. package/index-jje9qzyq.js +27 -0
  60. package/{index-rxse80x6.js → index-js1gj6f6.js} +12 -10
  61. package/{index-p2pahmsa.js → index-kjrvwzav.js} +3 -3
  62. package/index-m6r88hhr.js +3582 -0
  63. package/{index-mk391h0z.js → index-mt0wa941.js} +4 -4
  64. package/{index-m93qg20j.js → index-mwj9q2ya.js} +1 -1
  65. package/{index-5nd1wtkv.js → index-p6x5b7hr.js} +1 -1
  66. package/index-r2wedvqn.js +138 -0
  67. package/{index-gxj80jz7.js → index-rvynj5gz.js} +1 -1
  68. package/{index-m54n0v29.js → index-tdv66eah.js} +4 -4
  69. package/{index-vq77g679.js → index-w134p86k.js} +1 -1
  70. package/{index-deeskxjh.js → index-wfczhj1z.js} +14 -36
  71. package/{index-dy0jx9ay.js → index-wwe9rsrx.js} +14 -0
  72. package/{index-qx4r4cj2.js → index-x5ecanqh.js} +2 -2
  73. package/{index-nzfgyw3b.js → index-zre4m2ce.js} +4 -4
  74. package/index.js +23 -22
  75. package/{library.command-hmbkcwzw.js → library.command-sh70fyvy.js} +3 -3
  76. package/{localRegistry.command-sq5p4c9x.js → localRegistry.command-2nbyy84d.js} +14 -13
  77. package/{module.command-n4z29zcv.js → module.command-n0bmtzwy.js} +5 -5
  78. package/{package.command-20025dy3.js → package.command-7h9r51bz.js} +3 -3
  79. package/package.json +2 -2
  80. package/{page.command-q8fvpjer.js → page.command-vjtpfbb1.js} +3 -3
  81. package/{pipeline.command-8j97fq88.js → pipeline.command-c93se3ar.js} +2 -2
  82. package/{primitive.command-e5y6dqp1.js → primitive.command-a3075qp2.js} +6 -6
  83. package/{projectTypecheck-tbdye9k3.js → projectTypecheck-sf9xwaga.js} +1 -1
  84. package/{prompter-76k56b37.js → prompter-hgcta8pb.js} +1 -1
  85. package/quality.command-dw1y9hmy.js +76 -0
  86. package/{repair.command-dq1gckth.js → repair.command-tg57d8yt.js} +5 -5
  87. package/{scalar.command-5vwf152w.js → scalar.command-cwzge353.js} +4 -4
  88. package/skills/akan-agent/SKILL.md +36 -0
  89. package/skills/akan-debug/SKILL.md +3 -3
  90. package/skills/akan-deps/SKILL.md +1 -2
  91. package/skills/akan-mcp/SKILL.md +40 -0
  92. package/skills/akan-page/SKILL.md +44 -0
  93. package/skills/akan-query/SKILL.md +38 -0
  94. package/skills/akan-runtime/SKILL.md +40 -0
  95. package/skills/akan-scaffold/SKILL.md +16 -6
  96. package/skills/akan-transport/SKILL.md +40 -0
  97. package/skills/akan-validate/SKILL.md +13 -11
  98. package/{subspace.command-182be8vj.js → subspace.command-3h03c7kc.js} +8 -8
  99. package/templates/workspaceRoot/.gitignore.template +3 -0
  100. package/templates/workspaceRoot/AGENTS.md.template +4 -10
  101. package/{tunnel.command-bfzj7xkb.js → tunnel.command-czaz6ys4.js} +7 -7
  102. package/{typeChecker-px49mezc.js → typeChecker-j2jdnqsr.js} +1 -1
  103. package/typecheck.proc.js +6 -1
  104. package/verify.command-nzwhtz71.js +91 -0
  105. package/{workflow.command-3g53242s.js → workflow.command-srhky88x.js} +23 -13
  106. package/{workspace.command-h7399jwv.js → workspace.command-9stchcd2.js} +31 -29
  107. package/TunnelShare-dk2gw78d.js +0 -14
  108. package/agent.command-knp5j7bq.js +0 -25
  109. package/cloud.script-2r82sv0f.js +0 -24
  110. package/context.runner-c3wsh2jw.js +0 -26
  111. package/guidelines/conventions/conventions.instruction.md +0 -663
  112. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +0 -291
  113. package/index-4t4qb8jg.js +0 -279
  114. package/index-hvg3esm0.js +0 -1844
  115. package/index-zzvvc845.js +0 -74
  116. package/quality.command-168pt5vm.js +0 -1788
  117. package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +0 -69
  118. package/templates/workspaceRoot/docs/GENERATED.md.template +0 -55
@@ -0,0 +1,514 @@
1
+ // @bun
2
+ import {
3
+ ApplicationBuildReporter
4
+ } from "./index-p6x5b7hr.js";
5
+ import {
6
+ parseBiomeReport,
7
+ Linter,
8
+ TypecheckFailure,
9
+ ProjectTypecheck2,
10
+ AppExecutor,
11
+ LibExecutor,
12
+ PkgExecutor
13
+ } from "./index-64g9fsjy.js";
14
+ import {
15
+ WorkspaceRunner,
16
+ AkanQualityScanner
17
+ } from "./index-m6r88hhr.js";
18
+ import {
19
+ ExitCodeError
20
+ } from "./index-3gccwenr.js";
21
+
22
+ // pkgs/@akanjs/cli/verify/verifyComments.ts
23
+ import { existsSync } from "fs";
24
+ import path from "path";
25
+
26
+ class VerifyComments {
27
+ static code = "akan.comment.added";
28
+ static fix = "keep only a fact the code cannot say (vendor quirk, constraint, security, domain meaning, rejected alternative); delete the rest";
29
+ static #codeFile = /\.[cm]?[jt]sx?$/;
30
+ static #directive = /^(\/\/\/?|\/\*+)\s*(biome-ignore|@ts-|eslint-|prettier-ignore|#region|#endregion|<reference|[#@]__PURE__|@__NO_SIDE_EFFECTS__)/;
31
+ static #typescriptLoad;
32
+ static #loadTypescript() {
33
+ VerifyComments.#typescriptLoad ??= import("typescript").then((mod) => mod.default ?? mod);
34
+ return VerifyComments.#typescriptLoad;
35
+ }
36
+ static async added(root, files) {
37
+ const code = files.filter((file) => VerifyComments.#codeFile.test(file) && existsSync(path.join(root, file)));
38
+ if (!code.length)
39
+ return [];
40
+ const changed = await VerifyComments.#addedLines(root, code);
41
+ if (!changed)
42
+ return [];
43
+ const typescript = await VerifyComments.#loadTypescript();
44
+ const diagnostics = [];
45
+ for (const file of code) {
46
+ const lines = changed.get(file);
47
+ if (lines?.size === 0)
48
+ continue;
49
+ const text = await Bun.file(path.join(root, file)).text();
50
+ for (const comment of VerifyComments.commentsOf(typescript, file, text)) {
51
+ if (VerifyComments.#directive.test(comment.text))
52
+ continue;
53
+ if (lines && !VerifyComments.#touches(comment, lines))
54
+ continue;
55
+ diagnostics.push({
56
+ step: "lint",
57
+ file,
58
+ line: comment.line,
59
+ col: comment.col,
60
+ code: VerifyComments.code,
61
+ severity: "warning",
62
+ message: VerifyComments.#excerpt(comment.text)
63
+ });
64
+ }
65
+ }
66
+ const [first] = diagnostics;
67
+ if (first)
68
+ first.fix = VerifyComments.fix;
69
+ return diagnostics;
70
+ }
71
+ static commentsOf(typescript, file, text) {
72
+ const kind = file.endsWith("x") ? typescript.ScriptKind.TSX : typescript.ScriptKind.TS;
73
+ const source = typescript.createSourceFile(file, text, typescript.ScriptTarget.Latest, true, kind);
74
+ const ranges = new Map;
75
+ const visit = (node) => {
76
+ if (node.kind === typescript.SyntaxKind.JsxText)
77
+ return;
78
+ if (node.kind >= typescript.SyntaxKind.FirstJSDocNode && node.kind <= typescript.SyntaxKind.LastJSDocNode)
79
+ return;
80
+ const children = node.getChildren(source);
81
+ for (const child of children)
82
+ visit(child);
83
+ if (children.length)
84
+ return;
85
+ const start = node.getFullStart();
86
+ for (const range of [
87
+ ...typescript.getTrailingCommentRanges(text, start) ?? [],
88
+ ...typescript.getLeadingCommentRanges(text, start) ?? []
89
+ ])
90
+ ranges.set(range.pos, range);
91
+ };
92
+ visit(source);
93
+ return [...ranges.values()].sort((a, b) => a.pos - b.pos).map((range) => {
94
+ const start = source.getLineAndCharacterOfPosition(range.pos);
95
+ const end = source.getLineAndCharacterOfPosition(range.end);
96
+ return {
97
+ text: text.slice(range.pos, range.end),
98
+ line: start.line + 1,
99
+ col: start.character + 1,
100
+ lastLine: end.line + 1
101
+ };
102
+ });
103
+ }
104
+ static #touches(comment, lines) {
105
+ for (let line = comment.line;line <= comment.lastLine; line++)
106
+ if (lines.has(line))
107
+ return true;
108
+ return false;
109
+ }
110
+ static #excerpt(comment) {
111
+ const first = comment.split(`
112
+ `).find((line) => line.replace(/^[\s/*]+/, "").trim()) ?? comment;
113
+ const flat = first.replace(/\s+/g, " ").trim();
114
+ return flat.length <= 60 ? flat : `${flat.slice(0, 59)}\u2026`;
115
+ }
116
+ static async#addedLines(root, files) {
117
+ const tracked = await VerifyComments.#git(root, ["ls-files", "-z", "--", ...files]);
118
+ const diff = await VerifyComments.#git(root, [
119
+ "-c",
120
+ "core.quotePath=false",
121
+ "diff",
122
+ "-U0",
123
+ "--no-color",
124
+ "--no-ext-diff",
125
+ "--relative",
126
+ "HEAD",
127
+ "--",
128
+ ...files
129
+ ]);
130
+ if (tracked === null || diff === null)
131
+ return null;
132
+ const trackedFiles = new Set(tracked.split("\x00").filter(Boolean));
133
+ const added = VerifyComments.parseDiff(diff);
134
+ return new Map(files.map((file) => [file, trackedFiles.has(file) ? added.get(file) ?? new Set : undefined]));
135
+ }
136
+ static parseDiff(diff) {
137
+ const added = new Map;
138
+ let current = null;
139
+ for (const line of diff.split(`
140
+ `)) {
141
+ if (line.startsWith("+++ ")) {
142
+ const file = line.slice(4).replace(/^b\//, "");
143
+ current = file === "/dev/null" ? null : new Set;
144
+ if (current)
145
+ added.set(file, current);
146
+ continue;
147
+ }
148
+ const [, from, length] = line.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/) ?? [];
149
+ if (from === undefined || !current)
150
+ continue;
151
+ const start = Number(from);
152
+ const count = length === undefined ? 1 : Number(length);
153
+ for (let offset = 0;offset < count; offset++)
154
+ current.add(start + offset);
155
+ }
156
+ return added;
157
+ }
158
+ static async#git(root, args) {
159
+ const proc = Bun.spawn(["git", ...args], { cwd: root, stdout: "pipe", stderr: "ignore" });
160
+ const [stdout, code] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
161
+ return code === 0 ? stdout : null;
162
+ }
163
+ }
164
+
165
+ // pkgs/@akanjs/cli/verify/verifyPipeline.ts
166
+ import { existsSync as existsSync2 } from "fs";
167
+ import path2 from "path";
168
+
169
+ // pkgs/@akanjs/cli/verify/verifyDiagnostics.ts
170
+ class VerifyDiagnostics {
171
+ static fromTypecheck(records) {
172
+ return records.map((record) => ({
173
+ step: "typecheck",
174
+ file: record.file,
175
+ line: record.line,
176
+ col: record.col,
177
+ code: record.code,
178
+ severity: record.severity,
179
+ message: record.message.split(`
180
+ `)[0] ?? record.message
181
+ }));
182
+ }
183
+ static fromBiome(report) {
184
+ return (report.diagnostics ?? []).filter((diagnostic) => diagnostic.severity === "error" || diagnostic.severity === "warning").map((diagnostic) => ({
185
+ step: "lint",
186
+ file: diagnostic.location?.path?.replaceAll("\\", "/") ?? null,
187
+ line: diagnostic.location?.start?.line ?? 0,
188
+ col: diagnostic.location?.start?.column ?? 0,
189
+ code: diagnostic.category ?? "biome",
190
+ severity: diagnostic.severity === "error" ? "error" : "warning",
191
+ message: diagnostic.message
192
+ }));
193
+ }
194
+ static fromMaintainability(entries) {
195
+ return entries.map((entry) => ({
196
+ step: "lint",
197
+ file: entry.file,
198
+ line: entry.line,
199
+ col: 0,
200
+ code: entry.rule,
201
+ severity: "error",
202
+ message: entry.problem,
203
+ fix: entry.path ? `${entry.fix} Path: ${entry.path}` : entry.fix
204
+ }));
205
+ }
206
+ static fromQuality(warnings, changedFiles) {
207
+ return warnings.filter((warning) => warning.file && changedFiles.has(warning.file)).map((warning) => ({
208
+ step: "ssr",
209
+ file: warning.file ?? null,
210
+ line: warning.line ?? 0,
211
+ col: 0,
212
+ code: warning.rule,
213
+ severity: "warning",
214
+ message: warning.message,
215
+ ...warning.fix ? { fix: warning.fix } : {}
216
+ }));
217
+ }
218
+ static #prefix = /^\[([\w.-]+)\]\s*/;
219
+ static #location = /((?:apps|libs|pkgs)\/[^\s:()`'"]+\.[a-z]+)(?::(\d+)(?::(\d+))?)?/;
220
+ static fromMessage(step, message, code = `akan.${step}`) {
221
+ const prefix = VerifyDiagnostics.#prefix.exec(message);
222
+ const location = VerifyDiagnostics.#location.exec(message);
223
+ return {
224
+ step,
225
+ file: location ? location[1] ?? null : null,
226
+ line: Number(location?.[2] ?? 0),
227
+ col: Number(location?.[3] ?? 0),
228
+ code: prefix?.[1] ?? code,
229
+ severity: "error",
230
+ message: message.slice(prefix?.[0].length ?? 0).trim()
231
+ };
232
+ }
233
+ }
234
+
235
+ // pkgs/@akanjs/cli/verify/verifyPipeline.ts
236
+ class VerifyPipeline {
237
+ #workspace;
238
+ #workspaceRunner;
239
+ #applicationRunner;
240
+ #steps = new Map;
241
+ #diagnostics = [];
242
+ constructor(workspace, workspaceRunner, applicationRunner) {
243
+ this.#workspace = workspace;
244
+ this.#workspaceRunner = workspaceRunner;
245
+ this.#applicationRunner = applicationRunner;
246
+ }
247
+ get #root() {
248
+ return this.#workspace.workspaceRoot;
249
+ }
250
+ async run(scope, { lintOnly = false, build = true } = {}) {
251
+ const startedAt = performance.now();
252
+ const systems = scope.targets.filter((target) => target.type !== "pkg");
253
+ if (!lintOnly)
254
+ await this.#each("sync", systems, (target) => this.#sync(target));
255
+ const synced = !this.#failed("sync");
256
+ await Promise.all([
257
+ this.#each("lint", scope.targets, (target) => this.#lint(target, { comments: !lintOnly })),
258
+ lintOnly || !synced ? null : this.#each("typecheck", scope.targets, (target) => this.#typecheck(target))
259
+ ]);
260
+ const apps = scope.targets.filter((target) => target.type === "app");
261
+ const clean = !this.#diagnostics.some((diagnostic) => diagnostic.severity === "error");
262
+ if (!lintOnly && build && apps.length) {
263
+ if (clean)
264
+ await this.#each("build", apps, (target) => this.#build(target));
265
+ else
266
+ this.#skip("build");
267
+ }
268
+ if (!lintOnly && scope.touchesTsx)
269
+ await this.#each("ssr", [null], () => this.#ssr(scope));
270
+ return {
271
+ ok: !this.#diagnostics.some((diagnostic) => diagnostic.severity === "error"),
272
+ targets: scope.targets.map((target) => target.name),
273
+ ms: Math.round(performance.now() - startedAt),
274
+ steps: [...this.#steps.values()],
275
+ diagnostics: this.#diagnostics
276
+ };
277
+ }
278
+ async#each(name, items, step) {
279
+ if (!items.length)
280
+ return;
281
+ const startedAt = performance.now();
282
+ let fixed = 0;
283
+ let failed = false;
284
+ for (const item of items) {
285
+ const outcome = await step(item).catch((error) => ({
286
+ diagnostics: [VerifyDiagnostics.fromMessage(name, ApplicationBuildReporter.formatError(error, this.#root))]
287
+ }));
288
+ fixed += outcome.fixed ?? 0;
289
+ failed ||= outcome.diagnostics.some((diagnostic) => diagnostic.severity === "error");
290
+ this.#diagnostics.push(...outcome.diagnostics);
291
+ }
292
+ const ms = Math.round(performance.now() - startedAt);
293
+ this.#steps.set(name, { name, status: failed ? "fail" : "pass", ms, fixed });
294
+ }
295
+ #skip(name) {
296
+ this.#steps.set(name, { name, status: "skip", ms: 0, fixed: 0 });
297
+ }
298
+ #failed(name) {
299
+ return this.#steps.get(name)?.status === "fail";
300
+ }
301
+ async#sync(target) {
302
+ if (target.type === "app")
303
+ await AppExecutor.from(this.#workspace, target.name).scanSync();
304
+ else
305
+ await LibExecutor.from(this.#workspace, target.name).scan();
306
+ return { diagnostics: [] };
307
+ }
308
+ async#lint(target, { comments }) {
309
+ const files = target.files.length ? target.files.filter((file) => existsSync2(path2.join(this.#root, file))) : [target.dir];
310
+ const biome = files.length ? await this.#biome(files) : { diagnostics: [], fixed: 0 };
311
+ const exec = this.#execOf(target);
312
+ const gates = await this.#workspaceRunner.lintGateFailures(exec, true);
313
+ const added = comments && target.files.length ? await VerifyComments.added(this.#root, target.files) : [];
314
+ return {
315
+ diagnostics: [
316
+ ...biome.diagnostics,
317
+ ...added,
318
+ ...gates.messages.map((message) => VerifyDiagnostics.fromMessage("lint", message, "akan.lint")),
319
+ ...VerifyDiagnostics.fromMaintainability(gates.maintainability)
320
+ ],
321
+ fixed: biome.fixed
322
+ };
323
+ }
324
+ async#biome(files) {
325
+ const configPath = await WorkspaceRunner.resolveBiomeConfigPath(this.#workspace);
326
+ const [biome, ...biomeArgs] = Linter.biomeCommand(this.#root);
327
+ const proc = Bun.spawn([
328
+ biome,
329
+ ...biomeArgs,
330
+ "check",
331
+ "--write",
332
+ "--reporter=json",
333
+ "--max-diagnostics=none",
334
+ "--no-errors-on-unmatched",
335
+ ...configPath ? ["--config-path", configPath] : [],
336
+ ...files
337
+ ], { cwd: this.#root, stdout: "pipe", stderr: "pipe" });
338
+ const [stdout, stderr] = await Promise.all([
339
+ new Response(proc.stdout).text(),
340
+ new Response(proc.stderr).text(),
341
+ proc.exited
342
+ ]);
343
+ try {
344
+ const report = parseBiomeReport(stdout);
345
+ return { diagnostics: VerifyDiagnostics.fromBiome(report), fixed: report.summary?.changed ?? 0 };
346
+ } catch {
347
+ return { diagnostics: [VerifyDiagnostics.fromMessage("lint", (stderr || stdout).trim(), "biome")] };
348
+ }
349
+ }
350
+ async#typecheck(target) {
351
+ try {
352
+ if (target.type === "app")
353
+ await this.#applicationRunner.typecheck(AppExecutor.from(this.#workspace, target.name), {
354
+ tests: true,
355
+ report: "records"
356
+ });
357
+ else if (target.type === "lib")
358
+ await this.#applicationRunner.typecheckLibrary(LibExecutor.from(this.#workspace, target.name), {
359
+ tests: true,
360
+ report: "records"
361
+ });
362
+ else {
363
+ const tsconfigPath = path2.join(this.#root, target.dir, "tsconfig.json");
364
+ if (!existsSync2(tsconfigPath))
365
+ return { diagnostics: [] };
366
+ await new ProjectTypecheck2(path2.join(this.#root, target.dir), this.#root, process.env).check(tsconfigPath, "records");
367
+ }
368
+ return { diagnostics: [] };
369
+ } catch (error) {
370
+ if (error instanceof TypecheckFailure)
371
+ return { diagnostics: VerifyDiagnostics.fromTypecheck(error.records) };
372
+ throw error;
373
+ }
374
+ }
375
+ async#build(target) {
376
+ await this.#applicationRunner.build(AppExecutor.from(this.#workspace, target.name), { fast: true });
377
+ return { diagnostics: [] };
378
+ }
379
+ async#ssr(scope) {
380
+ const scanned = await new AkanQualityScanner().scan(this.#root);
381
+ const warnings = scanned.warnings.filter((warning) => warning.scope === "ssr");
382
+ return { diagnostics: VerifyDiagnostics.fromQuality(warnings, scope.changedFiles) };
383
+ }
384
+ #execOf(target) {
385
+ if (target.type === "app")
386
+ return AppExecutor.from(this.#workspace, target.name);
387
+ if (target.type === "lib")
388
+ return LibExecutor.from(this.#workspace, target.name);
389
+ return PkgExecutor.from(this.#workspace, target.name);
390
+ }
391
+ }
392
+
393
+ // pkgs/@akanjs/cli/verify/verifyReport.ts
394
+ class VerifyReport {
395
+ static lineMax = 280;
396
+ static defaultMax = 20;
397
+ static text(result, { max = VerifyReport.defaultMax } = {}) {
398
+ if (!result.targets.length)
399
+ return "verify ok \xB7 nothing changed under apps/, libs/ or pkgs/";
400
+ const lines = [VerifyReport.#header(result), ...VerifyReport.#diagnosticLines(result.diagnostics, max)];
401
+ return lines.join(`
402
+ `);
403
+ }
404
+ static json(result) {
405
+ return JSON.stringify(result);
406
+ }
407
+ static #header(result) {
408
+ const ran = result.steps.filter((step) => step.name !== "sync" || step.status === "fail");
409
+ const fixed = result.steps.reduce((sum, step) => sum + step.fixed, 0);
410
+ const seconds = `${(result.ms / 1000).toFixed(1)}s`;
411
+ const fixedNote = fixed ? `fixed ${fixed} file${fixed === 1 ? "" : "s"}` : null;
412
+ const steps = result.ok ? ran.filter((step) => step.status === "pass").map((step) => step.name).join(" ") : ran.map((step) => VerifyReport.#stepLabel(step, result.diagnostics)).join(" \xB7 ");
413
+ return [`verify ${result.ok ? "ok" : "fail"}`, result.targets.join(", "), steps, fixedNote, seconds].filter(Boolean).join(" \xB7 ");
414
+ }
415
+ static #stepLabel(step, diagnostics) {
416
+ if (step.status === "skip")
417
+ return `${step.name} skipped`;
418
+ if (step.status === "pass")
419
+ return `${step.name} ok`;
420
+ const errors = diagnostics.filter((entry) => entry.step === step.name && entry.severity === "error").length;
421
+ return `${step.name} ${errors} error${errors === 1 ? "" : "s"}`;
422
+ }
423
+ static #diagnosticLines(diagnostics, max) {
424
+ const groups = new Map;
425
+ const ordered = [...diagnostics].sort((a, b) => Number(a.severity === "warning") - Number(b.severity === "warning"));
426
+ for (const diagnostic of ordered) {
427
+ const key = `${diagnostic.code}\x00${diagnostic.message}`;
428
+ groups.set(key, [...groups.get(key) ?? [], diagnostic]);
429
+ }
430
+ const lines = [...groups.values()].map((group) => VerifyReport.#lineOf(group));
431
+ if (max <= 0 || lines.length <= max)
432
+ return lines;
433
+ return [...lines.slice(0, max), `+${lines.length - max} more \xB7 akan verify --max 0`];
434
+ }
435
+ static #lineOf([first, ...rest]) {
436
+ if (!first)
437
+ return "";
438
+ const where = first.file ? `${first.file}${first.line ? `:${first.line}${first.col ? `:${first.col}` : ""}` : ""}` : "-";
439
+ const others = rest.length ? ` (\xD7${rest.length + 1}: ${rest.slice(0, 2).map((entry) => entry.file === first.file ? `:${entry.line}` : entry.file ?? "-").join(", ")}${rest.length > 2 ? `, +${rest.length - 2}` : ""})` : "";
440
+ const fix = first.fix ? ` fix: ${first.fix}` : "";
441
+ const warning = first.severity === "warning" ? " warning" : "";
442
+ const line = `${where}${others}${warning} ${first.code} ${first.message}${fix}`.replace(/\s+/g, " ").trim();
443
+ return line.length <= VerifyReport.lineMax ? line : `${line.slice(0, VerifyReport.lineMax - 1)}\u2026`;
444
+ }
445
+ }
446
+
447
+ // pkgs/@akanjs/cli/verify/verifyScope.ts
448
+ class VerifyScope {
449
+ targets;
450
+ constructor(targets) {
451
+ this.targets = targets;
452
+ }
453
+ get touchesTsx() {
454
+ return this.targets.some((target) => target.files.some((file) => file.endsWith(".tsx")));
455
+ }
456
+ get changedFiles() {
457
+ return new Set(this.targets.flatMap((target) => target.files));
458
+ }
459
+ static async changesIn(workspaceRoot) {
460
+ const prefix = await VerifyScope.#git(workspaceRoot, ["rev-parse", "--show-prefix"]);
461
+ if (prefix === null)
462
+ return null;
463
+ const status = await VerifyScope.#git(workspaceRoot, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
464
+ if (status === null)
465
+ return null;
466
+ return VerifyScope.parseStatus(status, prefix.trim());
467
+ }
468
+ static parseStatus(status, prefix = "") {
469
+ const tokens = status.split("\x00");
470
+ const changes = [];
471
+ for (let idx = 0;idx < tokens.length; idx++) {
472
+ const token = tokens[idx] ?? "";
473
+ if (token.length < 4)
474
+ continue;
475
+ const code = token.slice(0, 2);
476
+ const file = token.slice(3);
477
+ if (code.includes("R") || code.includes("C"))
478
+ idx++;
479
+ if (!file.startsWith(prefix))
480
+ continue;
481
+ changes.push({ code, file: file.slice(prefix.length) });
482
+ }
483
+ return changes;
484
+ }
485
+ static resolve(changes, names, requested = []) {
486
+ const known = VerifyScope.#knownTargets(names);
487
+ const changedFilesOf = (dir) => changes.filter((change) => change.file.startsWith(`${dir}/`)).map((change) => change.file);
488
+ if (requested.length) {
489
+ const targets = requested.map((name) => {
490
+ const target = known.find((candidate) => candidate.name === name);
491
+ if (!target)
492
+ throw new ExitCodeError(`${name} is not an app, library or package of this workspace`, 2);
493
+ return { ...target, files: changedFilesOf(target.dir) };
494
+ });
495
+ return new VerifyScope(targets);
496
+ }
497
+ const targets = known.map((target) => ({ ...target, files: changedFilesOf(target.dir) })).filter((target) => target.files.length > 0);
498
+ return new VerifyScope(targets);
499
+ }
500
+ static #knownTargets({ apps, libs, pkgs }) {
501
+ return [
502
+ ...apps.map((name) => ({ type: "app", name, dir: `apps/${name}`, files: [] })),
503
+ ...libs.map((name) => ({ type: "lib", name, dir: `libs/${name}`, files: [] })),
504
+ ...pkgs.map((name) => ({ type: "pkg", name, dir: `pkgs/${name}`, files: [] }))
505
+ ];
506
+ }
507
+ static async#git(cwd, args) {
508
+ const proc = Bun.spawn(["git", ...args], { cwd, stdout: "pipe", stderr: "ignore" });
509
+ const [text, exitCode] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
510
+ return exitCode === 0 ? text : null;
511
+ }
512
+ }
513
+
514
+ export { VerifyComments, VerifyPipeline, VerifyReport, VerifyScope };