brumate 0.3.0 → 0.4.1

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 (122) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-C25Sa6vq.d.ts → boot-SCWYwuUd.d.ts} +8 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BBtVTOIt.js +3506 -0
  7. package/dist/client-BBtVTOIt.js.map +1 -0
  8. package/dist/{client-D0CqSxoO.d.ts → client-Cs3o4key.d.ts} +390 -181
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-BzllthiF.js → cookies-Cnbf4w-S.js} +14 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-BbD7JQhj.js → defer-BLJjxqVc.js} +4 -4
  14. package/dist/defer-BLJjxqVc.js.map +1 -0
  15. package/dist/{devtools-CQgD7NPB.js → devtools-DTpsVFbn.js} +56 -82
  16. package/dist/devtools-DTpsVFbn.js.map +1 -0
  17. package/dist/{devtools-panel-BVB-W5q4.js → devtools-panel-C1Dfv6nq.js} +397 -333
  18. package/dist/devtools-panel-C1Dfv6nq.js.map +1 -0
  19. package/dist/{events-CSs7OwIC.js → events-LgLdp1R7.js} +34 -5
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-DZIiMDnS.js +506 -0
  24. package/dist/files-DZIiMDnS.js.map +1 -0
  25. package/dist/{forms-Cl21hkHt.d.ts → forms-j1xPAR14.d.ts} +3 -3
  26. package/dist/{forms-Bg-CwGqX.js → forms-nXK7-Lv_.js} +78 -44
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.js +31 -22
  29. package/dist/highlight.js.map +1 -1
  30. package/dist/{html-mNTKzaDD.js → html-DS9B1H-M.js} +92 -22
  31. package/dist/html-DS9B1H-M.js.map +1 -0
  32. package/dist/{html-Bq1rFxX_.d.ts → html-Gggepsf-.d.ts} +22 -5
  33. package/dist/index.d.ts +98 -10
  34. package/dist/index.js +639 -104
  35. package/dist/index.js.map +1 -1
  36. package/dist/{inspect-BHpOw1LF.js → inspect-DomFHy5O.js} +3832 -695
  37. package/dist/inspect-DomFHy5O.js.map +1 -0
  38. package/dist/{loader-Dos_3NP0.js → loader-D62komKu.js} +20 -14
  39. package/dist/loader-D62komKu.js.map +1 -0
  40. package/dist/logo-DQ_OYhBi.js +10 -0
  41. package/dist/logo-DQ_OYhBi.js.map +1 -0
  42. package/dist/{navigate-O78d_zGN.js → navigate-CfOr-TRF.js} +94 -31
  43. package/dist/navigate-CfOr-TRF.js.map +1 -0
  44. package/dist/nesting-DA5vJw9X.js +265 -0
  45. package/dist/nesting-DA5vJw9X.js.map +1 -0
  46. package/dist/{produce-Doc91GkX.js → produce-BNIpmZq2.js} +138 -9
  47. package/dist/produce-BNIpmZq2.js.map +1 -0
  48. package/dist/{produce-D0V0ICkz.d.ts → produce-CRfouraC.d.ts} +44 -5
  49. package/dist/{rpc-ygMRPmN4.js → rpc-BTMb8jap.js} +11 -6
  50. package/dist/rpc-BTMb8jap.js.map +1 -0
  51. package/dist/runtime/batch.js +9 -7
  52. package/dist/runtime/batch.js.map +1 -1
  53. package/dist/runtime/client.d.ts +4 -4
  54. package/dist/runtime/client.js +4 -4
  55. package/dist/runtime/devtools.d.ts +11 -29
  56. package/dist/runtime/devtools.js +3 -1
  57. package/dist/runtime/env.js +14 -2
  58. package/dist/runtime/env.js.map +1 -1
  59. package/dist/runtime/events.d.ts +23 -1
  60. package/dist/runtime/events.js +1 -1
  61. package/dist/runtime/forms.d.ts +2 -2
  62. package/dist/runtime/forms.js +1 -1
  63. package/dist/runtime/hot.d.ts +1 -1
  64. package/dist/runtime/hot.js +5 -2
  65. package/dist/runtime/hot.js.map +1 -1
  66. package/dist/runtime/html.d.ts +2 -2
  67. package/dist/runtime/html.js +1 -1
  68. package/dist/runtime/loader.d.ts +2 -2
  69. package/dist/runtime/loader.js +2 -2
  70. package/dist/runtime/routes.js +4 -1
  71. package/dist/runtime/routes.js.map +1 -1
  72. package/dist/runtime/server.d.ts +5 -5
  73. package/dist/runtime/server.js +5 -5
  74. package/dist/runtime/signals.d.ts +38 -1
  75. package/dist/runtime/signals.js +33 -1
  76. package/dist/runtime/signals.js.map +1 -1
  77. package/dist/runtime/static-loader.d.ts +2 -2
  78. package/dist/runtime/static-loader.js +1 -1
  79. package/dist/runtime/testing.d.ts +18 -3
  80. package/dist/runtime/testing.js +150 -33
  81. package/dist/runtime/testing.js.map +1 -1
  82. package/dist/{server-CxVDYE_V.js → server-BTtsQFFw.js} +633 -163
  83. package/dist/server-BTtsQFFw.js.map +1 -0
  84. package/dist/{server-DuFYRXrd.d.ts → server-CYw15Dsg.d.ts} +103 -22
  85. package/dist/{static-loader-nZssh66R.js → static-loader-C_GYIFtt.js} +79 -99
  86. package/dist/static-loader-C_GYIFtt.js.map +1 -0
  87. package/dist/{static-loader-Drpr0AzI.d.ts → static-loader-DVuLmXeu.d.ts} +2 -2
  88. package/dist/{stream-DCYZO4IF.js → stream-r4V5zBKm.js} +102 -16
  89. package/dist/stream-r4V5zBKm.js.map +1 -0
  90. package/dist/vite.d.ts +13 -20
  91. package/dist/vite.js +1956 -554
  92. package/dist/vite.js.map +1 -1
  93. package/elements.d.ts +951 -0
  94. package/forms/forms.brm.ts +3 -3
  95. package/package.json +12 -3
  96. package/skills/brumate/SKILL.md +58 -0
  97. package/skills/brumate/references/errors.md +2078 -0
  98. package/skills/brumate/references/events.md +117 -0
  99. package/skills/brumate/references/signals.md +61 -0
  100. package/skills/brumate/references/state.md +235 -0
  101. package/skills/brumate/references/syntax.md +250 -0
  102. package/types.d.ts +4 -4
  103. package/dist/client-BD6XT-s5.js +0 -1968
  104. package/dist/client-BD6XT-s5.js.map +0 -1
  105. package/dist/client-routes-JTbGtukf.js.map +0 -1
  106. package/dist/cookies-BzllthiF.js.map +0 -1
  107. package/dist/defer-BbD7JQhj.js.map +0 -1
  108. package/dist/devtools-CQgD7NPB.js.map +0 -1
  109. package/dist/devtools-panel-BVB-W5q4.js.map +0 -1
  110. package/dist/events-CSs7OwIC.js.map +0 -1
  111. package/dist/files-BXSSrQgc.js +0 -205
  112. package/dist/files-BXSSrQgc.js.map +0 -1
  113. package/dist/forms-Bg-CwGqX.js.map +0 -1
  114. package/dist/html-mNTKzaDD.js.map +0 -1
  115. package/dist/inspect-BHpOw1LF.js.map +0 -1
  116. package/dist/loader-Dos_3NP0.js.map +0 -1
  117. package/dist/navigate-O78d_zGN.js.map +0 -1
  118. package/dist/produce-Doc91GkX.js.map +0 -1
  119. package/dist/rpc-ygMRPmN4.js.map +0 -1
  120. package/dist/server-CxVDYE_V.js.map +0 -1
  121. package/dist/static-loader-nZssh66R.js.map +0 -1
  122. package/dist/stream-DCYZO4IF.js.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > A component language and compiler for resumable web apps.
4
4
 
5
- `brumate` compiles single-file `.brm` components into server-rendered HTML and small client modules. The browser does not hydrate. It reads the state that the server wrote into the page, and loads the code of an event handler only when that event fires.
5
+ `brumate` compiles single-file `.brm` components into server-rendered HTML and small client modules. The browser does not hydrate. It reads the state that the server wrote into the page, and loads the code of the components on the page when it starts.
6
6
 
7
7
  ## Install
8
8
 
@@ -46,7 +46,7 @@ import 'virtual:brumate/start';
46
46
  <p>Double: {double}</p>
47
47
  ```
48
48
 
49
- The server renders the button and the text. The browser loads the code of the click handler, and of the updates it causes, the first time the button is clicked.
49
+ The server renders the button and the text. The browser loads the code of the click handler, and of the updates it causes, when the page starts. It does not render the page again.
50
50
 
51
51
  ## What it includes
52
52
 
package/check.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ // Internal types of the generated code that checks a .brm file (src/check.ts). Not a public
2
+ // API: they can change in any release. They live here and not in the prelude of each generated
3
+ // file, so TypeScript resolves them once for the program.
4
+
5
+ import type { ElementEvents, Elements, GlobalAttributes } from 'brumate/elements';
6
+ import type { BindableMark } from 'brumate/signals';
7
+
8
+ /**
9
+ * The attributes of the tag `T` of a dynamic tag: those of its element, or any for a custom
10
+ * tag. A declaration with a generic `T` leaves the conditional unresolved.
11
+ */
12
+ export type DynamicAttributes<T> = T extends keyof Elements ? Elements[T] : Record<string, unknown>;
13
+
14
+ /**
15
+ * The attributes of a tag that can be any element or component, such as a generic
16
+ * `T extends AsTarget`: the global ones, with a `ref` of any element, and any other name.
17
+ */
18
+ export type AnyTagAttributes = Omit<GlobalAttributes<HTMLElement | SVGElement>, 'ref'> & {
19
+ ref?: BindableMark<unknown>;
20
+ [name: string]: unknown;
21
+ };
22
+
23
+ /**
24
+ * Types a handler of a dynamic tag on the element `E`: the event of its name. Another name keeps
25
+ * the type of the handler, and the object of the attributes checks it.
26
+ */
27
+ export type DynamicHandle<E> = {
28
+ <K extends keyof ElementEvents & string>(
29
+ event: K,
30
+ handler: (event: ElementEvents[K] & { currentTarget: E }) => unknown,
31
+ ): (event: ElementEvents[K] & { currentTarget: E }) => unknown;
32
+ <H>(event: string, handler: H): H;
33
+ };
34
+
35
+ /** The keys of each object of a union, so an optional key counts. */
36
+ export type SpreadKeys<U> = U extends unknown ? keyof U : never;
37
+
38
+ /**
39
+ * Checks the props of a component as a dynamic tag. Without a spread, the props are complete.
40
+ * With spreads, each one is part of the props, and the object must give each required prop that
41
+ * no spread names.
42
+ */
43
+ export type DynamicProps<P> = {
44
+ (props: P): void;
45
+ <S extends [Partial<P>, ...Partial<P>[]]>(
46
+ props: Omit<P, SpreadKeys<S[number]>> & Partial<P>,
47
+ ...spreads: S
48
+ ): void;
49
+ };
@@ -1,5 +1,5 @@
1
- import { t as ClientModule } from "./client-D0CqSxoO.js";
2
1
  import { r as SerialEntry } from "./values-B8C7CLvG.js";
2
+ import { At as ClientModule } from "./client-Cs3o4key.js";
3
3
  //#region src/runtime/boot.d.ts
4
4
  interface LoaderOptions {
5
5
  /**
@@ -7,6 +7,12 @@ interface LoaderOptions {
7
7
  * a component that has no client code.
8
8
  */
9
9
  load: (id: string) => Promise<ClientModule> | undefined;
10
+ /**
11
+ * Loads the bundle of a root component of the page, such as a route: the client modules of
12
+ * the components that it can render, in one chunk. Undefined for a component that is not a
13
+ * root.
14
+ */
15
+ loadBundle?: (id: string) => Promise<unknown> | undefined;
10
16
  /** The URL prefix of server function calls. */
11
17
  rpc?: string;
12
18
  /** Imports the serial entry, which the core takes before it reads the page state. */
@@ -17,14 +23,6 @@ interface LoaderOptions {
17
23
  * from server functions to the same origin. Defaults to true.
18
24
  */
19
25
  navigate?: boolean | NavigateOptions;
20
- /**
21
- * After the page loads, while the browser is idle, loads the core and the
22
- * code of the handlers of elements in or near the viewport, so a first
23
- * event needs no request. Elements with `data-prefetch="none"` are left
24
- * out, and nothing loads when the browser asks to save data or the
25
- * connection is 2G. Defaults to true.
26
- */
27
- preload?: boolean;
28
26
  /**
29
27
  * The ID of the build of the page, for skew protection. The Vite plugin
30
28
  * sets it. Calls send it, and a page of another build, or a call that
@@ -59,4 +57,4 @@ interface NavigateOptions {
59
57
  }
60
58
  //#endregion
61
59
  export { NavigateOptions as n, LoaderOptions as t };
62
- //# sourceMappingURL=boot-C25Sa6vq.d.ts.map
60
+ //# sourceMappingURL=boot-SCWYwuUd.d.ts.map
package/dist/cli.js CHANGED
@@ -1,36 +1,260 @@
1
1
  #!/usr/bin/env node
2
- import { j as analyzeProjectProps, o as CompileError, r as inspect } from "./inspect-BHpOw1LF.js";
3
- import { n as findFiles, t as defaultExclude } from "./files-BXSSrQgc.js";
4
- import { readFile, stat } from "node:fs/promises";
2
+ import { B as getLocation, H as findError, j as analyzeProjectProps, o as CompileError, r as inspect, s as compile, w as resolveFromDisk, z as BrumateError } from "./inspect-DomFHy5O.js";
3
+ import { h as findPackages, o as findPackageServerFile, s as findServerImport, t as collectSources, v as resolveComponentPackage } from "./files-DZIiMDnS.js";
4
+ import { createRequire } from "node:module";
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { cp } from "node:fs/promises";
5
7
  import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import { spawnSync } from "node:child_process";
10
+ //#region src/check-command.ts
11
+ /** How many records are errors. Warnings do not count. */
12
+ function errorCount(records) {
13
+ let count = 0;
14
+ for (const record of records) if (record.severity === "error") count++;
15
+ return count;
16
+ }
17
+ function toPosix$1(file) {
18
+ return file.split(path.sep).join("/");
19
+ }
20
+ function fromDiagnostic(source, file, diagnostic) {
21
+ const entry = diagnostic.severity === "error" ? findError(diagnostic.message) : void 0;
22
+ const first = Math.min(diagnostic.range.start, source.length);
23
+ return {
24
+ file,
25
+ range: {
26
+ start: getLocation(source, first),
27
+ end: getLocation(source, Math.min(Math.max(first, diagnostic.range.end), source.length))
28
+ },
29
+ severity: diagnostic.severity === "error" ? "error" : "warning",
30
+ message: diagnostic.message,
31
+ code: entry?.code ?? null,
32
+ link: entry?.link ?? null,
33
+ source: "brumate"
34
+ };
35
+ }
36
+ /** Compiles one file and gives its errors and warnings. */
37
+ function checkFile(source, file, absolute, liveProps, packages) {
38
+ try {
39
+ const result = compile(source, {
40
+ filename: file,
41
+ path: absolute,
42
+ liveProps,
43
+ serverImport: (specifier) => specifier.startsWith(".") ? findServerImport(absolute, specifier) : findPackageServerFile(packages, absolute, specifier),
44
+ resolveModule: (specifier, importer) => {
45
+ const local = resolveFromDisk(specifier, importer);
46
+ const found = local === void 0 ? resolveComponentPackage(packages, specifier, importer) : void 0;
47
+ return found ? {
48
+ path: found,
49
+ source: readFileSync(found, "utf8")
50
+ } : local;
51
+ }
52
+ });
53
+ const records = [];
54
+ for (const warning of result.warnings) records.push(fromDiagnostic(source, file, warning));
55
+ return records;
56
+ } catch (error) {
57
+ if (error instanceof CompileError) {
58
+ const records = [];
59
+ for (const diagnostic of error.diagnostics) records.push(fromDiagnostic(source, file, diagnostic));
60
+ return records;
61
+ }
62
+ if (error instanceof BrumateError) {
63
+ const message = error.message.replace(/ \([^()]*:\d+:\d+\)$/, "").replace(/ \[BRM\d+\]$/, "");
64
+ const entry = findError(message);
65
+ return [{
66
+ file,
67
+ range: {
68
+ start: error.location,
69
+ end: getLocation(source, Math.min(error.offset + 1, source.length))
70
+ },
71
+ severity: "error",
72
+ message,
73
+ code: entry?.code ?? null,
74
+ link: entry?.link ?? null,
75
+ source: "brumate"
76
+ }];
77
+ }
78
+ throw error;
79
+ }
80
+ }
81
+ const TS_LINE = /^(.+?)\((\d+),(\d+)\): (error|warning) (TS\d+|BRM\d*): (.*)$/;
82
+ const TS_GLOBAL = /^(error|warning) (TS\d+): (.*)$/;
83
+ /** Reads the lines that `tsc` prints without colors. */
84
+ function parseTypeOutput(output, root) {
85
+ const records = [];
86
+ let last;
87
+ for (const line of output.split("\n")) {
88
+ const match = TS_LINE.exec(line);
89
+ if (match) {
90
+ last = void 0;
91
+ if (match[5].startsWith("BRM")) continue;
92
+ const position = {
93
+ line: Number(match[2]),
94
+ column: Number(match[3])
95
+ };
96
+ last = {
97
+ file: toPosix$1(path.relative(root, path.resolve(root, match[1]))),
98
+ range: {
99
+ start: position,
100
+ end: position
101
+ },
102
+ severity: match[4] === "warning" ? "warning" : "error",
103
+ message: match[6],
104
+ code: match[5],
105
+ link: null,
106
+ source: "typescript"
107
+ };
108
+ records.push(last);
109
+ continue;
110
+ }
111
+ const global = TS_GLOBAL.exec(line);
112
+ if (global) {
113
+ last = {
114
+ file: null,
115
+ range: null,
116
+ severity: global[1] === "warning" ? "warning" : "error",
117
+ message: global[3],
118
+ code: global[2],
119
+ link: null,
120
+ source: "typescript"
121
+ };
122
+ records.push(last);
123
+ continue;
124
+ }
125
+ if (last && /^\s+\S/.test(line)) last.message += `\n${line}`;
126
+ }
127
+ return records;
128
+ }
129
+ /**
130
+ * Runs `brumate-tsc`, the type checker of `.brm` files. It has no API that
131
+ * gives its errors, so its output is read. Without the package, it gives a
132
+ * note and no records.
133
+ */
134
+ function typeCheck(root, tscBin) {
135
+ if (!existsSync(path.join(root, "tsconfig.json"))) return {
136
+ records: [],
137
+ note: "The type check was skipped: there is no tsconfig.json in the current directory."
138
+ };
139
+ let bin;
140
+ try {
141
+ const require = createRequire(path.join(root, "noop.js"));
142
+ bin = tscBin ?? path.join(path.dirname(require.resolve("@brumate/tsc/package.json")), "bin/brumate-tsc.js");
143
+ } catch {
144
+ return {
145
+ records: [],
146
+ note: "The type check was skipped: install @brumate/tsc to run it, or pass --no-types."
147
+ };
148
+ }
149
+ const result = spawnSync(process.execPath, [
150
+ bin,
151
+ "--noEmit",
152
+ "--pretty",
153
+ "false"
154
+ ], {
155
+ cwd: root,
156
+ encoding: "utf8",
157
+ maxBuffer: 67108864
158
+ });
159
+ const records = parseTypeOutput(`${result.stdout}\n${result.stderr}`, root);
160
+ function fail(message) {
161
+ records.push({
162
+ file: null,
163
+ range: null,
164
+ severity: "error",
165
+ message,
166
+ code: null,
167
+ link: null,
168
+ source: "typescript"
169
+ });
170
+ }
171
+ if (result.error) fail(`The type check did not finish: ${result.error.message}`);
172
+ else if (result.signal) fail(`The type check was stopped by ${result.signal}`);
173
+ else if (result.status !== 0 && errorCount(records) === 0) {
174
+ const text = `${result.stdout}${result.stderr}`.trim();
175
+ if (!/error BRM\d*:/.test(text)) fail(text || `The type check ended with status ${result.status}`);
176
+ }
177
+ return { records };
178
+ }
179
+ /** Compiles every `.brm` file under the root, and runs the type checker. */
180
+ async function check(root, options = {}) {
181
+ const records = [];
182
+ const paths = [];
183
+ for (const target of options.paths ?? []) if (existsSync(path.resolve(root, target))) paths.push(target);
184
+ else records.push({
185
+ file: toPosix$1(target),
186
+ range: null,
187
+ severity: "error",
188
+ message: "This file or directory does not exist",
189
+ code: null,
190
+ link: null,
191
+ source: "brumate"
192
+ });
193
+ const { sources, targets } = paths.length === 0 && (options.paths?.length ?? 0) > 0 ? {
194
+ sources: /* @__PURE__ */ new Map(),
195
+ targets: []
196
+ } : await collectSources(root, paths);
197
+ const props = analyzeProjectProps(sources);
198
+ const packages = findPackages(root);
199
+ for (const file of targets) {
200
+ const parents = props.get(file);
201
+ records.push(...checkFile(sources.get(file), toPosix$1(path.relative(root, file)), file, parents && new Set(parents.keys()), packages));
202
+ }
203
+ const notes = [];
204
+ if (options.types !== false) {
205
+ const types = typeCheck(root, options.tscBin);
206
+ records.push(...types.records);
207
+ if (types.note) notes.push(types.note);
208
+ }
209
+ return {
210
+ records,
211
+ notes
212
+ };
213
+ }
214
+ /** One line for a person: `file:line:column: error BRM012: message`. */
215
+ function formatRecord(record) {
216
+ const place = record.file ? `${record.file}${record.range ? `:${record.range.start.line}:${record.range.start.column}` : ""}: ` : "";
217
+ const code = record.code ? ` ${record.code}` : "";
218
+ const link = record.link ? `\n ${record.link}` : "";
219
+ return `${place}${record.severity}${code}: ${record.message}${link}`;
220
+ }
221
+ //#endregion
6
222
  //#region src/cli.ts
7
223
  const USAGE = `Usage: brumate inspect [--json] [files or directories]
8
224
 
9
225
  Shows what each component ships to the client, and why.
10
- Without paths, inspects every .brm file under the current directory.`;
226
+ Without paths, inspects every .brm file under the current directory.
227
+
228
+ brumate check [--json] [--no-types] [files or directories]
229
+
230
+ Compiles every .brm file and type-checks the project with brumate-tsc.
231
+ Prints each problem with its place, its code and a link to the docs.
232
+ With --json, prints one JSON object per line. Exits with 1 on an error.
233
+
234
+ brumate skill [folder]
235
+
236
+ Copies the skill for .brm files into folder/brumate, for coding agents.
237
+ The folder defaults to .claude/skills.`;
11
238
  function toPosix(file) {
12
239
  return file.split(path.sep).join("/");
13
240
  }
14
241
  /** Shows parent files relative to the current directory. */
15
242
  function relativeParents(parents, root) {
16
243
  const result = /* @__PURE__ */ new Map();
17
- for (const [prop, files] of parents) result.set(prop, new Set([...files].map((file) => toPosix(path.relative(root, file)))));
244
+ for (const [prop, files] of parents) {
245
+ const relative = /* @__PURE__ */ new Set();
246
+ for (const file of files) relative.add(toPosix(path.relative(root, file)));
247
+ result.set(prop, relative);
248
+ }
18
249
  return result;
19
250
  }
20
251
  async function inspectCommand(args) {
21
252
  const json = args.includes("--json");
22
- const paths = args.filter((arg) => arg !== "--json");
253
+ const paths = [];
254
+ for (const arg of args) if (arg !== "--json") paths.push(arg);
23
255
  const root = process.cwd();
24
- const project = await findFiles(root, defaultExclude);
25
- const sources = /* @__PURE__ */ new Map();
26
- for (const [index, source] of (await Promise.all(project.map((file) => readFile(file, "utf8")))).entries()) sources.set(project[index], source);
256
+ const { sources, targets } = await collectSources(root, paths);
27
257
  const props = analyzeProjectProps(sources);
28
- const targets = (await Promise.all((paths.length > 0 ? paths : ["."]).map(async (target) => {
29
- const absolute = path.resolve(root, target);
30
- return (await stat(absolute)).isDirectory() ? findFiles(absolute, defaultExclude) : [toPosix(absolute)];
31
- }))).flat();
32
- const extra = targets.filter((file) => !sources.has(file));
33
- for (const [index, source] of (await Promise.all(extra.map((file) => readFile(file, "utf8")))).entries()) sources.set(extra[index], source);
34
258
  const reports = [];
35
259
  const texts = [];
36
260
  let failed = false;
@@ -55,8 +279,44 @@ async function inspectCommand(args) {
55
279
  console.log(json ? JSON.stringify(reports, null, 2) : texts.join("\n\n"));
56
280
  return failed ? 1 : 0;
57
281
  }
282
+ async function checkCommand(args) {
283
+ const flags = /* @__PURE__ */ new Set(["--json", "--no-types"]);
284
+ const paths = [];
285
+ for (const arg of args) if (!arg.startsWith("-")) paths.push(arg);
286
+ else if (!flags.has(arg)) {
287
+ console.error(`brumate check does not know ${arg}\n\n${USAGE}`);
288
+ return 1;
289
+ }
290
+ const { records, notes } = await check(process.cwd(), {
291
+ paths,
292
+ types: !args.includes("--no-types")
293
+ });
294
+ const json = args.includes("--json");
295
+ for (const record of records) console.log(json ? JSON.stringify(record) : formatRecord(record));
296
+ for (const note of notes) console.error(note);
297
+ const errors = errorCount(records);
298
+ if (!json) console.log(errors === 0 ? "No errors." : `${errors} ${errors === 1 ? "error" : "errors"}.`);
299
+ return errors === 0 ? 0 : 1;
300
+ }
301
+ async function skillCommand(args) {
302
+ if (args.length > 1 || args[0]?.startsWith("-")) {
303
+ console.error(`brumate skill takes one folder, not ${args.join(" ")}\n\n${USAGE}`);
304
+ return 1;
305
+ }
306
+ const folder = path.resolve(args[0] ?? ".claude/skills");
307
+ const target = path.join(folder, "brumate");
308
+ const source = fileURLToPath(new URL("../skills/brumate", import.meta.url));
309
+ await cp(source, target, {
310
+ recursive: true,
311
+ force: true
312
+ });
313
+ console.log(`Copied the skill to ${path.relative(process.cwd(), target) || "."}`);
314
+ return 0;
315
+ }
58
316
  async function main(args) {
59
317
  const [command, ...rest] = args;
318
+ if (command === "skill") return skillCommand(rest);
319
+ if (command === "check") return checkCommand(rest);
60
320
  if (command === "inspect") return inspectCommand(rest);
61
321
  console.log(USAGE);
62
322
  return command === void 0 || command === "--help" ? 0 : 1;
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { readFile, stat } from 'node:fs/promises';\nimport path from 'node:path';\nimport { CompileError } from './compile.ts';\nimport { defaultExclude, findFiles } from './files.ts';\nimport { inspect } from './inspect.ts';\nimport type { InspectReport } from './inspect.ts';\nimport { analyzeProjectProps } from './project.ts';\n\nconst USAGE = `Usage: brumate inspect [--json] [files or directories]\n\nShows what each component ships to the client, and why.\nWithout paths, inspects every .brm file under the current directory.`;\n\nfunction toPosix(file: string): string {\n return file.split(path.sep).join('/');\n}\n\n/** Shows parent files relative to the current directory. */\nfunction relativeParents(\n parents: Map<string, Set<string>>,\n root: string,\n): Map<string, Set<string>> {\n const result = new Map<string, Set<string>>();\n for (const [prop, files] of parents) {\n result.set(prop, new Set([...files].map((file) => toPosix(path.relative(root, file)))));\n }\n return result;\n}\n\nasync function inspectCommand(args: string[]): Promise<number> {\n const json = args.includes('--json');\n const paths = args.filter((arg) => arg !== '--json');\n const root = process.cwd();\n\n // Props are analyzed across every file under the current directory.\n const project = await findFiles(root, defaultExclude);\n const sources = new Map<string, string>();\n for (const [index, source] of (\n await Promise.all(project.map((file) => readFile(file, 'utf8')))\n ).entries()) {\n sources.set(project[index]!, source);\n }\n const props = analyzeProjectProps(sources);\n\n const found = await Promise.all(\n (paths.length > 0 ? paths : ['.']).map(async (target) => {\n const absolute = path.resolve(root, target);\n return (await stat(absolute)).isDirectory()\n ? findFiles(absolute, defaultExclude)\n : [toPosix(absolute)];\n }),\n );\n const targets = found.flat();\n // Files outside the current directory are read here.\n const extra = targets.filter((file) => !sources.has(file));\n for (const [index, source] of (\n await Promise.all(extra.map((file) => readFile(file, 'utf8')))\n ).entries()) {\n sources.set(extra[index]!, source);\n }\n\n const reports: InspectReport[] = [];\n const texts: string[] = [];\n let failed = false;\n for (const file of targets) {\n const source = sources.get(file)!;\n const filename = toPosix(path.relative(root, file));\n try {\n const parents = props.get(file);\n const result = inspect(source, {\n filename,\n liveProps: parents && new Set(parents.keys()),\n parents: parents && relativeParents(parents, root),\n });\n reports.push(result.report);\n texts.push(result.text);\n } catch (error) {\n if (!(error instanceof CompileError)) {\n throw error;\n }\n failed = true;\n console.error(error.message);\n }\n }\n console.log(json ? JSON.stringify(reports, null, 2) : texts.join('\\n\\n'));\n return failed ? 1 : 0;\n}\n\nasync function main(args: string[]): Promise<number> {\n const [command, ...rest] = args;\n if (command === 'inspect') {\n return inspectCommand(rest);\n }\n console.log(USAGE);\n return command === undefined || command === '--help' ? 0 : 1;\n}\n\nprocess.exitCode = await main(process.argv.slice(2));\n"],"mappings":";;;;;;AASA,MAAM,QAAQ;;;;AAKd,SAAS,QAAQ,MAAsB;CACrC,OAAO,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;AACtC;;AAGA,SAAS,gBACP,SACA,MAC0B;CAC1B,MAAM,yBAAS,IAAI,IAAyB;CAC5C,KAAK,MAAM,CAAC,MAAM,UAAU,SAC1B,OAAO,IAAI,MAAM,IAAI,IAAI,C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S,MAAM,IAAI,CAAC;EAClD,IAAI;GACF,MAAM,UAAU,MAAM,IAAI,IAAI;GAC9B,MAAM,SAAS,QAAQ,QAAQ;IAC7B;IACA,WAAW,WAAW,IAAI,IAAI,QAAQ,KAAK,CAAC;IAC5C,SAAS,WAAW,gBAAgB,SAAS,IAAI;GACnD,CAAC;GACD,QAAQ,KAAK,OAAO,MAAM;GAC1B,MAAM,KAAK,OAAO,IAAI;EACxB,SAAS,OAAO;GACd,IAAI,EAAE,iBAAiB,eACrB,MAAM;GAER,SAAS;GACT,QAAQ,MAAM,MAAM,OAAO;EAC7B;CACF;CACA,QAAQ,IAAI,OAAO,KAAK,UAAU,SAAS,MAAM,CAAC,IAAI,MAAM,KAAK,MAAM,CAAC;CACxE,OAAO,SAAS,IAAI;AACtB;AAEA,eAAe,KAAK,MAAiC;CACnD,MAAM,CAAC,SAAS,GAAG,QAAQ;CAC3B,IAAI,YAAY,WACd,OAAO,eAAe,IAAI;CAE5B,QAAQ,IAAI,KAAK;CACjB,OAAO,YAAY,KAAA,KAAa,YAAY,WAAW,IAAI;AAC7D;AAEA,QAAQ,WAAW,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"cli.js","names":["toPosix"],"sources":["../src/check-command.ts","../src/cli.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { CompileError, compile } from './compile.ts';\nimport type { Diagnostic } from './model.ts';\nimport { findError } from './error-catalog.ts';\nimport { BrumateError, getLocation } from './error.ts';\nimport { collectSources } from './files.ts';\nimport { resolveFromDisk } from './modules.ts';\nimport type { BrumatePackage } from './packages.ts';\nimport { findPackages, resolveComponentPackage } from './packages.ts';\nimport { analyzeProjectProps } from './project.ts';\nimport { findPackageServerFile, findServerImport } from './server-files.ts';\n\n/** A place in a file. Lines and columns start at 1. */\nexport interface CheckPosition {\n line: number;\n column: number;\n}\n\n/** One problem, as `brumate check --json` prints it. */\nexport interface CheckRecord {\n /** The file, relative to the current directory. Null for a problem of the whole project. */\n file: string | null;\n /** Where the problem is. The type checker gives a start only, so its end is the start. */\n range: { start: CheckPosition; end: CheckPosition } | null;\n severity: 'error' | 'warning';\n /** The message without its code or its place. */\n message: string;\n /** `BRM012` for an error of the compiler, `TS2322` for one of TypeScript, null for a warning. */\n code: string | null;\n /** The page of the docs that explains the code, null when there is none. */\n link: string | null;\n /** Who found it. */\n source: 'brumate' | 'typescript';\n}\n\nexport interface CheckOptions {\n /** Files or directories to check. Defaults to the root. */\n paths?: string[];\n /** Runs the type checker too. Defaults to true. */\n types?: boolean;\n /** The `brumate-tsc` script to run. Defaults to the one of the installed @brumate/tsc. */\n tscBin?: string;\n}\n\nexport interface CheckResult {\n records: CheckRecord[];\n /** Why the type check did not run, such as a missing package. */\n notes: string[];\n}\n\n/** How many records are errors. Warnings do not count. */\nexport function errorCount(records: CheckRecord[]): number {\n let count = 0;\n for (const record of records) {\n if (record.severity === 'error') {\n count++;\n }\n }\n return count;\n}\n\nfunction toPosix(file: string): string {\n return file.split(path.sep).join('/');\n}\n\nfunction fromDiagnostic(source: string, file: string, diagnostic: Diagnostic): CheckRecord {\n const entry = diagnostic.severity === 'error' ? findError(diagnostic.message) : undefined;\n // A range at the end of the file stays in the file.\n const first = Math.min(diagnostic.range.start, source.length);\n const start = getLocation(source, first);\n const end = getLocation(source, Math.min(Math.max(first, diagnostic.range.end), source.length));\n return {\n file,\n range: { start, end },\n severity: diagnostic.severity === 'error' ? 'error' : 'warning',\n message: diagnostic.message,\n code: entry?.code ?? null,\n link: entry?.link ?? null,\n source: 'brumate',\n };\n}\n\n/** Compiles one file and gives its errors and warnings. */\nfunction checkFile(\n source: string,\n file: string,\n absolute: string,\n liveProps: Set<string> | undefined,\n packages: BrumatePackage[],\n): CheckRecord[] {\n try {\n const result = compile(source, {\n filename: file,\n path: absolute,\n liveProps,\n serverImport: (specifier) =>\n specifier.startsWith('.')\n ? findServerImport(absolute, specifier)\n : findPackageServerFile(packages, absolute, specifier),\n resolveModule: (specifier, importer) => {\n const local = resolveFromDisk(specifier, importer);\n const found =\n local === undefined ? resolveComponentPackage(packages, specifier, importer) : undefined;\n return found ? { path: found, source: readFileSync(found, 'utf8') } : local;\n },\n });\n const records: CheckRecord[] = [];\n for (const warning of result.warnings) {\n records.push(fromDiagnostic(source, file, warning));\n }\n return records;\n } catch (error) {\n if (error instanceof CompileError) {\n const records: CheckRecord[] = [];\n for (const diagnostic of error.diagnostics) {\n records.push(fromDiagnostic(source, file, diagnostic));\n }\n return records;\n }\n if (error instanceof BrumateError) {\n // The message holds the code and the place. The parts are in the entry and the location.\n const message = error.message.replace(/ \\([^()]*:\\d+:\\d+\\)$/, '').replace(/ \\[BRM\\d+\\]$/, '');\n const entry = findError(message);\n const start = error.location;\n return [\n {\n file,\n range: { start, end: getLocation(source, Math.min(error.offset + 1, source.length)) },\n severity: 'error',\n message,\n code: entry?.code ?? null,\n link: entry?.link ?? null,\n source: 'brumate',\n },\n ];\n }\n throw error;\n }\n}\n\nconst TS_LINE = /^(.+?)\\((\\d+),(\\d+)\\): (error|warning) (TS\\d+|BRM\\d*): (.*)$/;\nconst TS_GLOBAL = /^(error|warning) (TS\\d+): (.*)$/;\n\n/** Reads the lines that `tsc` prints without colors. */\nexport function parseTypeOutput(output: string, root: string): CheckRecord[] {\n const records: CheckRecord[] = [];\n let last: CheckRecord | undefined;\n for (const line of output.split('\\n')) {\n const match = TS_LINE.exec(line);\n if (match) {\n last = undefined;\n // Syntax errors of `.brm` files are reported by the compiler, with their codes.\n if (match[5]!.startsWith('BRM')) {\n continue;\n }\n const position = { line: Number(match[2]), column: Number(match[3]) };\n last = {\n file: toPosix(path.relative(root, path.resolve(root, match[1]!))),\n range: { start: position, end: position },\n severity: match[4] === 'warning' ? 'warning' : 'error',\n message: match[6]!,\n code: match[5]!,\n link: null,\n source: 'typescript',\n };\n records.push(last);\n continue;\n }\n const global = TS_GLOBAL.exec(line);\n if (global) {\n last = {\n file: null,\n range: null,\n severity: global[1] === 'warning' ? 'warning' : 'error',\n message: global[3]!,\n code: global[2]!,\n link: null,\n source: 'typescript',\n };\n records.push(last);\n continue;\n }\n // The lines under a message, indented, belong to it.\n if (last && /^\\s+\\S/.test(line)) {\n last.message += `\\n${line}`;\n }\n }\n return records;\n}\n\n/**\n * Runs `brumate-tsc`, the type checker of `.brm` files. It has no API that\n * gives its errors, so its output is read. Without the package, it gives a\n * note and no records.\n */\nfunction typeCheck(root: string, tscBin?: string): { records: CheckRecord[]; note?: string } {\n if (!existsSync(path.join(root, 'tsconfig.json'))) {\n return {\n records: [],\n note: 'The type check was skipped: there is no tsconfig.json in the current directory.',\n };\n }\n let bin: string;\n try {\n const require = createRequire(path.join(root, 'noop.js'));\n bin =\n tscBin ??\n path.join(path.dirname(require.resolve('@brumate/tsc/package.json')), 'bin/brumate-tsc.js');\n } catch {\n return {\n records: [],\n note: 'The type check was skipped: install @brumate/tsc to run it, or pass --no-types.',\n };\n }\n const result = spawnSync(process.execPath, [bin, '--noEmit', '--pretty', 'false'], {\n cwd: root,\n encoding: 'utf8',\n maxBuffer: 64 * 1024 * 1024,\n });\n const records = parseTypeOutput(`${result.stdout}\\n${result.stderr}`, root);\n function fail(message: string): void {\n records.push({\n file: null,\n range: null,\n severity: 'error',\n message,\n code: null,\n link: null,\n source: 'typescript',\n });\n }\n if (result.error) {\n // The process did not start, ran too long for a timeout, or printed more than maxBuffer.\n fail(`The type check did not finish: ${result.error.message}`);\n } else if (result.signal) {\n fail(`The type check was stopped by ${result.signal}`);\n } else if (result.status !== 0 && errorCount(records) === 0) {\n // A failure that has no error line of TypeScript, such as an unreadable tsconfig.json. A\n // failure of syntax errors only is reported by the compiler.\n const text = `${result.stdout}${result.stderr}`.trim();\n if (!/error BRM\\d*:/.test(text)) {\n fail(text || `The type check ended with status ${result.status}`);\n }\n }\n return { records };\n}\n\n/** Compiles every `.brm` file under the root, and runs the type checker. */\nexport async function check(root: string, options: CheckOptions = {}): Promise<CheckResult> {\n const records: CheckRecord[] = [];\n // A path that does not exist is a problem of its own. The others are still checked.\n const paths: string[] = [];\n for (const target of options.paths ?? []) {\n if (existsSync(path.resolve(root, target))) {\n paths.push(target);\n } else {\n records.push({\n file: toPosix(target),\n range: null,\n severity: 'error',\n message: 'This file or directory does not exist',\n code: null,\n link: null,\n source: 'brumate',\n });\n }\n }\n const missingOnly = paths.length === 0 && (options.paths?.length ?? 0) > 0;\n const { sources, targets } = missingOnly\n ? { sources: new Map<string, string>(), targets: [] }\n : await collectSources(root, paths);\n const props = analyzeProjectProps(sources);\n\n const packages = findPackages(root);\n for (const file of targets) {\n const parents = props.get(file);\n records.push(\n ...checkFile(\n sources.get(file)!,\n toPosix(path.relative(root, file)),\n file,\n parents && new Set(parents.keys()),\n packages,\n ),\n );\n }\n\n const notes: string[] = [];\n if (options.types !== false) {\n const types = typeCheck(root, options.tscBin);\n records.push(...types.records);\n if (types.note) {\n notes.push(types.note);\n }\n }\n return { records, notes };\n}\n\n/** One line for a person: `file:line:column: error BRM012: message`. */\nexport function formatRecord(record: CheckRecord): string {\n const place = record.file\n ? `${record.file}${record.range ? `:${record.range.start.line}:${record.range.start.column}` : ''}: `\n : '';\n const code = record.code ? ` ${record.code}` : '';\n const link = record.link ? `\\n ${record.link}` : '';\n return `${place}${record.severity}${code}: ${record.message}${link}`;\n}\n","#!/usr/bin/env node\nimport { cp } from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { check, errorCount, formatRecord } from './check-command.ts';\nimport { CompileError } from './compile.ts';\nimport { collectSources } from './files.ts';\nimport { inspect } from './inspect.ts';\nimport type { InspectReport } from './inspect.ts';\nimport { analyzeProjectProps } from './project.ts';\n\nconst USAGE = `Usage: brumate inspect [--json] [files or directories]\n\nShows what each component ships to the client, and why.\nWithout paths, inspects every .brm file under the current directory.\n\n brumate check [--json] [--no-types] [files or directories]\n\nCompiles every .brm file and type-checks the project with brumate-tsc.\nPrints each problem with its place, its code and a link to the docs.\nWith --json, prints one JSON object per line. Exits with 1 on an error.\n\n brumate skill [folder]\n\nCopies the skill for .brm files into folder/brumate, for coding agents.\nThe folder defaults to .claude/skills.`;\n\nfunction toPosix(file: string): string {\n return file.split(path.sep).join('/');\n}\n\n/** Shows parent files relative to the current directory. */\nfunction relativeParents(\n parents: Map<string, Set<string>>,\n root: string,\n): Map<string, Set<string>> {\n const result = new Map<string, Set<string>>();\n for (const [prop, files] of parents) {\n const relative = new Set<string>();\n for (const file of files) {\n relative.add(toPosix(path.relative(root, file)));\n }\n result.set(prop, relative);\n }\n return result;\n}\n\nasync function inspectCommand(args: string[]): Promise<number> {\n const json = args.includes('--json');\n const paths: string[] = [];\n for (const arg of args) {\n if (arg !== '--json') {\n paths.push(arg);\n }\n }\n const root = process.cwd();\n\n // Props are analyzed across every file under the current directory.\n const { sources, targets } = await collectSources(root, paths);\n const props = analyzeProjectProps(sources);\n\n const reports: InspectReport[] = [];\n const texts: string[] = [];\n let failed = false;\n for (const file of targets) {\n const source = sources.get(file)!;\n const filename = toPosix(path.relative(root, file));\n try {\n const parents = props.get(file);\n const result = inspect(source, {\n filename,\n liveProps: parents && new Set(parents.keys()),\n parents: parents && relativeParents(parents, root),\n });\n reports.push(result.report);\n texts.push(result.text);\n } catch (error) {\n if (!(error instanceof CompileError)) {\n throw error;\n }\n failed = true;\n console.error(error.message);\n }\n }\n console.log(json ? JSON.stringify(reports, null, 2) : texts.join('\\n\\n'));\n return failed ? 1 : 0;\n}\n\nasync function checkCommand(args: string[]): Promise<number> {\n const flags = new Set(['--json', '--no-types']);\n const paths: string[] = [];\n for (const arg of args) {\n if (!arg.startsWith('-')) {\n paths.push(arg);\n } else if (!flags.has(arg)) {\n console.error(`brumate check does not know ${arg}\\n\\n${USAGE}`);\n return 1;\n }\n }\n const { records, notes } = await check(process.cwd(), {\n paths,\n types: !args.includes('--no-types'),\n });\n const json = args.includes('--json');\n for (const record of records) {\n console.log(json ? JSON.stringify(record) : formatRecord(record));\n }\n for (const note of notes) {\n console.error(note);\n }\n const errors = errorCount(records);\n if (!json) {\n console.log(errors === 0 ? 'No errors.' : `${errors} ${errors === 1 ? 'error' : 'errors'}.`);\n }\n return errors === 0 ? 0 : 1;\n}\n\nasync function skillCommand(args: string[]): Promise<number> {\n if (args.length > 1 || args[0]?.startsWith('-')) {\n console.error(`brumate skill takes one folder, not ${args.join(' ')}\\n\\n${USAGE}`);\n return 1;\n }\n const folder = path.resolve(args[0] ?? '.claude/skills');\n const target = path.join(folder, 'brumate');\n // The skill is in the package, next to dist and src.\n const source = fileURLToPath(new URL('../skills/brumate', import.meta.url));\n await cp(source, target, { recursive: true, force: true });\n console.log(`Copied the skill to ${path.relative(process.cwd(), target) || '.'}`);\n return 0;\n}\n\nasync function main(args: string[]): Promise<number> {\n const [command, ...rest] = args;\n if (command === 'skill') {\n return skillCommand(rest);\n }\n if (command === 'check') {\n return checkCommand(rest);\n }\n if (command === 'inspect') {\n return inspectCommand(rest);\n }\n console.log(USAGE);\n return command === undefined || command === '--help' ? 0 : 1;\n}\n\nprocess.exitCode = await main(process.argv.slice(2));\n"],"mappings":";;;;;;;;;;;AAsDA,SAAgB,WAAW,SAAgC;CACzD,IAAI,QAAQ;CACZ,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,aAAa,SACtB;CAGJ,OAAO;AACT;AAEA,SAASA,UAAQ,MAAsB;CACrC,OAAO,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;AACtC;AAEA,SAAS,eAAe,QAAgB,MAAc,YAAqC;CACzF,MAAM,QAAQ,WAAW,aAAa,UAAU,UAAU,WAAW,OAAO,IAAI,KAAA;CAEhF,MAAM,QAAQ,KAAK,IAAI,WAAW,MAAM,OAAO,OAAO,MAAM;CAG5D,OAAO;EACL;EACA,OAAO;GAAE,OAJG,YAAY,QAAQ,KAInB;GAAG,KAHN,YAAY,QAAQ,KAAK,IAAI,KAAK,IAAI,O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