lua-cli 3.12.1 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/dist/api/logs.api.service.d.ts +6 -3
  2. package/dist/api/logs.api.service.d.ts.map +1 -1
  3. package/dist/api/logs.api.service.js +5 -4
  4. package/dist/api/logs.api.service.js.map +1 -1
  5. package/dist/cli/command-definitions.d.ts.map +1 -1
  6. package/dist/cli/command-definitions.js +24 -2
  7. package/dist/cli/command-definitions.js.map +1 -1
  8. package/dist/commands/channels.d.ts.map +1 -1
  9. package/dist/commands/channels.js +2 -11
  10. package/dist/commands/channels.js.map +1 -1
  11. package/dist/commands/chat-log-probe.d.ts +59 -0
  12. package/dist/commands/chat-log-probe.d.ts.map +1 -0
  13. package/dist/commands/chat-log-probe.js +91 -0
  14. package/dist/commands/chat-log-probe.js.map +1 -0
  15. package/dist/commands/chat.d.ts.map +1 -1
  16. package/dist/commands/chat.js +134 -28
  17. package/dist/commands/chat.js.map +1 -1
  18. package/dist/commands/compile.d.ts +7 -0
  19. package/dist/commands/compile.d.ts.map +1 -1
  20. package/dist/commands/compile.js +32 -2
  21. package/dist/commands/compile.js.map +1 -1
  22. package/dist/commands/completion.d.ts.map +1 -1
  23. package/dist/commands/completion.js +7 -8
  24. package/dist/commands/completion.js.map +1 -1
  25. package/dist/commands/deploy.d.ts.map +1 -1
  26. package/dist/commands/deploy.js +108 -23
  27. package/dist/commands/deploy.js.map +1 -1
  28. package/dist/commands/devices.d.ts.map +1 -1
  29. package/dist/commands/devices.js +3 -2
  30. package/dist/commands/devices.js.map +1 -1
  31. package/dist/commands/env.d.ts.map +1 -1
  32. package/dist/commands/env.js +43 -20
  33. package/dist/commands/env.js.map +1 -1
  34. package/dist/commands/features.d.ts.map +1 -1
  35. package/dist/commands/features.js +2 -12
  36. package/dist/commands/features.js.map +1 -1
  37. package/dist/commands/governance.d.ts.map +1 -1
  38. package/dist/commands/governance.js +4 -8
  39. package/dist/commands/governance.js.map +1 -1
  40. package/dist/commands/index.d.ts +1 -0
  41. package/dist/commands/index.d.ts.map +1 -1
  42. package/dist/commands/index.js +1 -0
  43. package/dist/commands/index.js.map +1 -1
  44. package/dist/commands/init.d.ts.map +1 -1
  45. package/dist/commands/init.js +12 -2
  46. package/dist/commands/init.js.map +1 -1
  47. package/dist/commands/integrations.d.ts.map +1 -1
  48. package/dist/commands/integrations.js +4 -2
  49. package/dist/commands/integrations.js.map +1 -1
  50. package/dist/commands/jobs.d.ts.map +1 -1
  51. package/dist/commands/jobs.js +61 -23
  52. package/dist/commands/jobs.js.map +1 -1
  53. package/dist/commands/log-tip.d.ts +79 -0
  54. package/dist/commands/log-tip.d.ts.map +1 -0
  55. package/dist/commands/log-tip.js +91 -0
  56. package/dist/commands/log-tip.js.map +1 -0
  57. package/dist/commands/logs.d.ts.map +1 -1
  58. package/dist/commands/logs.js +97 -136
  59. package/dist/commands/logs.js.map +1 -1
  60. package/dist/commands/marketplace.d.ts.map +1 -1
  61. package/dist/commands/marketplace.js +14 -25
  62. package/dist/commands/marketplace.js.map +1 -1
  63. package/dist/commands/mcp.d.ts.map +1 -1
  64. package/dist/commands/mcp.js +17 -19
  65. package/dist/commands/mcp.js.map +1 -1
  66. package/dist/commands/models.d.ts.map +1 -1
  67. package/dist/commands/models.js +2 -1
  68. package/dist/commands/models.js.map +1 -1
  69. package/dist/commands/persona.d.ts.map +1 -1
  70. package/dist/commands/persona.js +4 -30
  71. package/dist/commands/persona.js.map +1 -1
  72. package/dist/commands/postprocessors.d.ts.map +1 -1
  73. package/dist/commands/postprocessors.js +43 -17
  74. package/dist/commands/postprocessors.js.map +1 -1
  75. package/dist/commands/preprocessors.d.ts.map +1 -1
  76. package/dist/commands/preprocessors.js +43 -17
  77. package/dist/commands/preprocessors.js.map +1 -1
  78. package/dist/commands/production.d.ts.map +1 -1
  79. package/dist/commands/production.js +2 -12
  80. package/dist/commands/production.js.map +1 -1
  81. package/dist/commands/push-helpers.d.ts +42 -0
  82. package/dist/commands/push-helpers.d.ts.map +1 -0
  83. package/dist/commands/push-helpers.js +48 -0
  84. package/dist/commands/push-helpers.js.map +1 -0
  85. package/dist/commands/push.d.ts +2 -0
  86. package/dist/commands/push.d.ts.map +1 -1
  87. package/dist/commands/push.js +269 -54
  88. package/dist/commands/push.js.map +1 -1
  89. package/dist/commands/pushBackup.d.ts.map +1 -1
  90. package/dist/commands/pushBackup.js +7 -1
  91. package/dist/commands/pushBackup.js.map +1 -1
  92. package/dist/commands/resources.d.ts.map +1 -1
  93. package/dist/commands/resources.js +2 -12
  94. package/dist/commands/resources.js.map +1 -1
  95. package/dist/commands/skills.d.ts.map +1 -1
  96. package/dist/commands/skills.js +51 -36
  97. package/dist/commands/skills.js.map +1 -1
  98. package/dist/commands/status.d.ts +14 -0
  99. package/dist/commands/status.d.ts.map +1 -0
  100. package/dist/commands/status.js +734 -0
  101. package/dist/commands/status.js.map +1 -0
  102. package/dist/commands/sync.d.ts.map +1 -1
  103. package/dist/commands/sync.js +37 -2
  104. package/dist/commands/sync.js.map +1 -1
  105. package/dist/commands/telemetry.d.ts.map +1 -1
  106. package/dist/commands/telemetry.js +4 -0
  107. package/dist/commands/telemetry.js.map +1 -1
  108. package/dist/commands/test-output.helpers.d.ts +24 -0
  109. package/dist/commands/test-output.helpers.d.ts.map +1 -0
  110. package/dist/commands/test-output.helpers.js +62 -0
  111. package/dist/commands/test-output.helpers.js.map +1 -0
  112. package/dist/commands/test.d.ts.map +1 -1
  113. package/dist/commands/test.js +236 -76
  114. package/dist/commands/test.js.map +1 -1
  115. package/dist/commands/webhooks.d.ts.map +1 -1
  116. package/dist/commands/webhooks.js +34 -21
  117. package/dist/commands/webhooks.js.map +1 -1
  118. package/dist/compiler/agent-traverser.d.ts +50 -14
  119. package/dist/compiler/agent-traverser.d.ts.map +1 -1
  120. package/dist/compiler/agent-traverser.js +191 -86
  121. package/dist/compiler/agent-traverser.js.map +1 -1
  122. package/dist/compiler/compiler.d.ts +32 -0
  123. package/dist/compiler/compiler.d.ts.map +1 -1
  124. package/dist/compiler/compiler.js +143 -18
  125. package/dist/compiler/compiler.js.map +1 -1
  126. package/dist/compiler/index.d.ts +1 -1
  127. package/dist/compiler/index.d.ts.map +1 -1
  128. package/dist/compiler/index.js +1 -1
  129. package/dist/compiler/index.js.map +1 -1
  130. package/dist/compiler/plugins/base.d.ts +21 -0
  131. package/dist/compiler/plugins/base.d.ts.map +1 -1
  132. package/dist/compiler/plugins/base.js +10 -0
  133. package/dist/compiler/plugins/base.js.map +1 -1
  134. package/dist/compiler/plugins/skill.plugin.d.ts +35 -9
  135. package/dist/compiler/plugins/skill.plugin.d.ts.map +1 -1
  136. package/dist/compiler/plugins/skill.plugin.js +131 -84
  137. package/dist/compiler/plugins/skill.plugin.js.map +1 -1
  138. package/dist/compiler/types.d.ts +33 -0
  139. package/dist/compiler/types.d.ts.map +1 -1
  140. package/dist/compiler/types.js.map +1 -1
  141. package/dist/compiler/utils/ast-helpers.d.ts +1 -16
  142. package/dist/compiler/utils/ast-helpers.d.ts.map +1 -1
  143. package/dist/compiler/utils/ast-helpers.js +2 -31
  144. package/dist/compiler/utils/ast-helpers.js.map +1 -1
  145. package/dist/compiler/utils/common.d.ts +14 -0
  146. package/dist/compiler/utils/common.d.ts.map +1 -1
  147. package/dist/compiler/utils/common.js +38 -0
  148. package/dist/compiler/utils/common.js.map +1 -1
  149. package/dist/compiler/utils/path-resolver.d.ts +67 -10
  150. package/dist/compiler/utils/path-resolver.d.ts.map +1 -1
  151. package/dist/compiler/utils/path-resolver.js +120 -24
  152. package/dist/compiler/utils/path-resolver.js.map +1 -1
  153. package/dist/compiler/utils/reference-resolver.d.ts +196 -0
  154. package/dist/compiler/utils/reference-resolver.d.ts.map +1 -0
  155. package/dist/compiler/utils/reference-resolver.js +1030 -0
  156. package/dist/compiler/utils/reference-resolver.js.map +1 -0
  157. package/dist/compiler/utils/schema-converter.d.ts +25 -0
  158. package/dist/compiler/utils/schema-converter.d.ts.map +1 -1
  159. package/dist/compiler/utils/schema-converter.js +83 -4
  160. package/dist/compiler/utils/schema-converter.js.map +1 -1
  161. package/dist/compiler/utils/workspace.d.ts +35 -0
  162. package/dist/compiler/utils/workspace.d.ts.map +1 -0
  163. package/dist/compiler/utils/workspace.js +121 -0
  164. package/dist/compiler/utils/workspace.js.map +1 -0
  165. package/dist/compiler/utils/zod-runtime.mjs +5334 -0
  166. package/dist/index.js +1 -0
  167. package/dist/index.js.map +1 -1
  168. package/dist/interfaces/backup.d.ts +19 -1
  169. package/dist/interfaces/backup.d.ts.map +1 -1
  170. package/dist/interfaces/chat.d.ts +2 -2
  171. package/dist/interfaces/chat.d.ts.map +1 -1
  172. package/dist/interfaces/logs.d.ts +7 -4
  173. package/dist/interfaces/logs.d.ts.map +1 -1
  174. package/dist/primitives/base.handler.d.ts +10 -0
  175. package/dist/primitives/base.handler.d.ts.map +1 -1
  176. package/dist/primitives/base.handler.js +73 -44
  177. package/dist/primitives/base.handler.js.map +1 -1
  178. package/dist/primitives/job.handler.d.ts +5 -0
  179. package/dist/primitives/job.handler.d.ts.map +1 -1
  180. package/dist/primitives/job.handler.js +9 -0
  181. package/dist/primitives/job.handler.js.map +1 -1
  182. package/dist/primitives/webhook.handler.d.ts +2 -1
  183. package/dist/primitives/webhook.handler.d.ts.map +1 -1
  184. package/dist/primitives/webhook.handler.js +7 -1
  185. package/dist/primitives/webhook.handler.js.map +1 -1
  186. package/dist/services/auth.d.ts +8 -0
  187. package/dist/services/auth.d.ts.map +1 -1
  188. package/dist/services/auth.js +19 -0
  189. package/dist/services/auth.js.map +1 -1
  190. package/dist/services/sandbox.service.d.ts.map +1 -1
  191. package/dist/services/sandbox.service.js +6 -2
  192. package/dist/services/sandbox.service.js.map +1 -1
  193. package/dist/utils/aliases.d.ts +7 -0
  194. package/dist/utils/aliases.d.ts.map +1 -0
  195. package/dist/utils/aliases.js +457 -0
  196. package/dist/utils/aliases.js.map +1 -0
  197. package/dist/utils/backup-helpers.d.ts +24 -0
  198. package/dist/utils/backup-helpers.d.ts.map +1 -1
  199. package/dist/utils/backup-helpers.js +94 -8
  200. package/dist/utils/backup-helpers.js.map +1 -1
  201. package/dist/utils/chat-attachments.d.ts +15 -0
  202. package/dist/utils/chat-attachments.d.ts.map +1 -0
  203. package/dist/utils/chat-attachments.js +116 -0
  204. package/dist/utils/chat-attachments.js.map +1 -0
  205. package/dist/utils/cli.d.ts +24 -6
  206. package/dist/utils/cli.d.ts.map +1 -1
  207. package/dist/utils/cli.js +23 -9
  208. package/dist/utils/cli.js.map +1 -1
  209. package/dist/utils/hints.d.ts +81 -0
  210. package/dist/utils/hints.d.ts.map +1 -0
  211. package/dist/utils/hints.js +83 -0
  212. package/dist/utils/hints.js.map +1 -0
  213. package/dist/utils/suggest.d.ts +3 -0
  214. package/dist/utils/suggest.d.ts.map +1 -0
  215. package/dist/utils/suggest.js +34 -0
  216. package/dist/utils/suggest.js.map +1 -0
  217. package/dist/utils/write-info.d.ts +9 -0
  218. package/dist/utils/write-info.d.ts.map +1 -0
  219. package/dist/utils/write-info.js +11 -0
  220. package/dist/utils/write-info.js.map +1 -0
  221. package/docs/README.md +1 -1
  222. package/node_modules/@lua/shared-types/dist/index.d.mts +64 -2
  223. package/node_modules/@lua/shared-types/dist/index.d.ts +64 -2
  224. package/node_modules/@lua/shared-types/dist/index.js +27 -0
  225. package/node_modules/@lua/shared-types/dist/index.mjs +24 -0
  226. package/node_modules/@lua/shared-types/src/channel.type.ts +1 -0
  227. package/node_modules/@lua/shared-types/src/client-tools.types.ts +47 -0
  228. package/node_modules/@lua/shared-types/src/index.ts +2 -0
  229. package/node_modules/@lua/shared-types/src/vm-execution-log.types.ts +41 -0
  230. package/package.json +10 -6
  231. package/scripts/build-vendor.mjs +53 -0
  232. package/scripts/vendor-entry.mjs +11 -0
  233. package/template/examples/skills/tools/CustomDataTool.ts +1 -5
  234. package/template/examples/skills/tools/PremiumFeatureTool.ts +18 -18
  235. package/template/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
  * Common utility functions for the compiler.
3
3
  */
4
4
  import crypto from 'crypto';
5
+ import path from 'path';
5
6
  // =============================================================================
6
7
  // HASHING
7
8
  // =============================================================================
@@ -53,6 +54,43 @@ export function shouldSkipDirectory(name) {
53
54
  // =============================================================================
54
55
  // FORMATTING
55
56
  // =============================================================================
57
+ // =============================================================================
58
+ // PATHS
59
+ // =============================================================================
60
+ /**
61
+ * Return `true` when `child` is contained in `parent` (or is `parent` itself).
62
+ * Uses normalized absolute paths so trailing slashes, `..` segments, and mixed
63
+ * separators don't cause false negatives.
64
+ *
65
+ * Naive separator-boundary checks like `child.startsWith(parent)` are avoided
66
+ * because they would treat `/foo/bar-baz` as a child of `/foo/bar`.
67
+ */
68
+ export function isInside(child, parent) {
69
+ const resolvedChild = path.resolve(child);
70
+ const resolvedParent = path.resolve(parent);
71
+ if (resolvedChild === resolvedParent)
72
+ return true;
73
+ const rel = path.relative(resolvedParent, resolvedChild);
74
+ return !!rel && !rel.startsWith('..') && !path.isAbsolute(rel);
75
+ }
76
+ /**
77
+ * Classify a project file by its name so the backup manifest knows whether
78
+ * it's a source file, a config file, or something else.
79
+ */
80
+ export function classifyProjectFile(name) {
81
+ if (name.endsWith('.ts') || name.endsWith('.tsx') || name.endsWith('.js')) {
82
+ return 'source';
83
+ }
84
+ if (name === 'package.json' ||
85
+ name === 'tsconfig.json' ||
86
+ name === 'lua.skill.yaml' ||
87
+ name.endsWith('.yaml') ||
88
+ name.endsWith('.yml') ||
89
+ name.endsWith('.json')) {
90
+ return 'config';
91
+ }
92
+ return 'other';
93
+ }
56
94
  /**
57
95
  * Format file size in human-readable format.
58
96
  */
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/compiler/utils/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF;;;GAGG;AAC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AAa;IACtC,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,GAAG,KAAK,GAAG,CAAC;IACrC,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC"}
@@ -1,26 +1,83 @@
1
1
  /**
2
2
  * Path Resolver Utilities
3
3
  *
4
- * Resolves TypeScript path aliases (e.g., @/, ~/) from tsconfig.json.
5
- * Enables the compiler to follow imports that use path aliases.
4
+ * Resolves TypeScript path aliases (e.g., @/, ~/) from a project's
5
+ * tsconfig.json and resolves relative/aliased module specifiers to
6
+ * absolute file paths.
7
+ *
8
+ * Design notes:
9
+ * - Every entry point that reads a tsconfig is keyed by `rootDir`. A
10
+ * single Node process can compile multiple projects (tests do this,
11
+ * and future "Compiler as library" consumers will too); the earlier
12
+ * implementation cached mappings in module scope and mixed aliases
13
+ * across projects. That's fixed here — the cache is a `Map<rootDir,
14
+ * mappings | null>`.
15
+ * - `resolveModuleSpecifier` is the single source of truth for
16
+ * "specifier → absolute path". Previously the resolver and the agent
17
+ * traverser each reimplemented the same logic; now both go through
18
+ * this one helper.
19
+ * - A `registerProjectRootDir(project, rootDir)` side-channel lets
20
+ * downstream code (plugins, resolver) recover the correct rootDir
21
+ * from a ts-morph Project without threading it through every call
22
+ * signature. The Compiler sets it once in its constructor.
6
23
  */
24
+ import type { Project } from 'ts-morph';
7
25
  interface PathMappings {
26
+ /** The tsconfig's `baseUrl` (falls back to `.`). */
8
27
  baseUrl: string;
28
+ /** Raw `paths` mapping from the tsconfig. */
9
29
  paths: Record<string, string[]>;
30
+ /** Absolute rootDir the tsconfig was loaded from. */
31
+ rootDir: string;
10
32
  }
11
33
  /**
12
- * Reads TypeScript path alias mappings from tsconfig.json.
13
- * Results are cached for the process lifetime.
34
+ * Read the tsconfig at `<rootDir>/tsconfig.json` and extract its
35
+ * `paths` mappings. Returns null when no paths are configured or the
36
+ * tsconfig is missing/unreadable. Result is cached keyed by the
37
+ * normalized rootDir.
38
+ */
39
+ export declare function getTsConfigPathMappings(rootDir: string): PathMappings | null;
40
+ /**
41
+ * Resolve a TypeScript path alias (e.g. `@/tools/MyTool`) to an
42
+ * absolute path. Returns null if no alias matches.
14
43
  *
15
- * @returns Path mappings or null if no paths configured
44
+ * `rootDir` is required it's the project's root, the directory that
45
+ * contains the tsconfig.json whose `paths` we're consulting.
16
46
  */
17
- export declare function getTsConfigPathMappings(): PathMappings | null;
47
+ export declare function resolvePathAlias(specifier: string, rootDir: string): string | null;
18
48
  /**
19
- * Resolves a path alias to an absolute path using tsconfig.json mappings.
49
+ * Resolve a module specifier (`./foo`, `../bar`, `@/tools/Xyz`) to an
50
+ * absolute file path, trying each of our supported extensions.
20
51
  *
21
- * @param specifier - The import specifier (e.g., '@/tools/MyTool')
22
- * @returns Resolved absolute path or null if no alias matched
52
+ * This is the single consolidated helper that replaces:
53
+ * - `reference-resolver.ts::resolveSpecifierToPath`
54
+ * - `agent-traverser.ts::resolveImportPath`
55
+ *
56
+ * Both previously duplicated this logic; drift between them was a real
57
+ * bug surface. Returns undefined when nothing resolves — callers
58
+ * interpret that as a deopt or a warning depending on context.
59
+ */
60
+ export declare function resolveModuleSpecifier(specifier: string, fromFile: string, rootDir: string): string | undefined;
61
+ /**
62
+ * Associate a ts-morph Project with its source `rootDir`. Called once
63
+ * by the Compiler constructor. Downstream code that only has a
64
+ * SourceFile can recover the rootDir via `getProjectRootDir`.
65
+ */
66
+ export declare function registerProjectRootDir(project: Project, rootDir: string): void;
67
+ /**
68
+ * Look up the registered rootDir for a project, or `undefined` if the
69
+ * project wasn't registered. Callers that need a rootDir but can't
70
+ * tolerate undefined should fall back to a sensible default (e.g.
71
+ * process.cwd() for standalone tooling, or a field on the plugin
72
+ * context for in-compiler use).
73
+ */
74
+ export declare function getProjectRootDir(project: Project): string | undefined;
75
+ /**
76
+ * Test-only: clear the path-alias cache. Tests that compile multiple
77
+ * projects back-to-back in the same process should call this between
78
+ * compilations to avoid stale aliases; the Compiler itself doesn't
79
+ * need to call this because the cache is keyed by rootDir.
23
80
  */
24
- export declare function resolvePathAlias(specifier: string): string | null;
81
+ export declare function clearPathResolverCacheForTests(): void;
25
82
  export {};
26
83
  //# sourceMappingURL=path-resolver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"path-resolver.d.ts","sourceRoot":"","sources":["../../../src/compiler/utils/path-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACjC;AAID;;;;;GAKG;AACH,wBAAgB,uBAAuB,IAAI,YAAY,GAAG,IAAI,CA4B7D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAwBjE"}
1
+ {"version":3,"file":"path-resolver.d.ts","sourceRoot":"","sources":["../../../src/compiler/utils/path-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,UAAU,YAAY;IACpB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAChC,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;CACjB;AAcD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAgC5E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAyBlF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAoBpB;AAUD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAE9E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,IAAI,IAAI,CAErD"}
@@ -1,24 +1,51 @@
1
1
  /**
2
2
  * Path Resolver Utilities
3
3
  *
4
- * Resolves TypeScript path aliases (e.g., @/, ~/) from tsconfig.json.
5
- * Enables the compiler to follow imports that use path aliases.
4
+ * Resolves TypeScript path aliases (e.g., @/, ~/) from a project's
5
+ * tsconfig.json and resolves relative/aliased module specifiers to
6
+ * absolute file paths.
7
+ *
8
+ * Design notes:
9
+ * - Every entry point that reads a tsconfig is keyed by `rootDir`. A
10
+ * single Node process can compile multiple projects (tests do this,
11
+ * and future "Compiler as library" consumers will too); the earlier
12
+ * implementation cached mappings in module scope and mixed aliases
13
+ * across projects. That's fixed here — the cache is a `Map<rootDir,
14
+ * mappings | null>`.
15
+ * - `resolveModuleSpecifier` is the single source of truth for
16
+ * "specifier → absolute path". Previously the resolver and the agent
17
+ * traverser each reimplemented the same logic; now both go through
18
+ * this one helper.
19
+ * - A `registerProjectRootDir(project, rootDir)` side-channel lets
20
+ * downstream code (plugins, resolver) recover the correct rootDir
21
+ * from a ts-morph Project without threading it through every call
22
+ * signature. The Compiler sets it once in its constructor.
6
23
  */
7
24
  import * as fs from 'fs';
8
25
  import * as path from 'path';
9
- let cachedMappings;
26
+ // Per-rootDir cache. `null` means "tsconfig exists but has no paths" or
27
+ // "tsconfig unreadable"; both cases still benefit from caching so we
28
+ // don't hit the filesystem repeatedly.
29
+ const mappingsCache = new Map();
30
+ // ts-morph Project → rootDir. Populated by the Compiler constructor.
31
+ // Lets plugin code that only has a SourceFile/Project in hand recover
32
+ // the correct rootDir without changing every plugin API signature.
33
+ const projectRootDirs = new WeakMap();
34
+ const MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '/index.ts', '/index.tsx', '/index.js'];
10
35
  /**
11
- * Reads TypeScript path alias mappings from tsconfig.json.
12
- * Results are cached for the process lifetime.
13
- *
14
- * @returns Path mappings or null if no paths configured
36
+ * Read the tsconfig at `<rootDir>/tsconfig.json` and extract its
37
+ * `paths` mappings. Returns null when no paths are configured or the
38
+ * tsconfig is missing/unreadable. Result is cached keyed by the
39
+ * normalized rootDir.
15
40
  */
16
- export function getTsConfigPathMappings() {
17
- if (cachedMappings !== undefined)
18
- return cachedMappings;
19
- const tsconfigPath = path.join(process.cwd(), 'tsconfig.json');
41
+ export function getTsConfigPathMappings(rootDir) {
42
+ const resolvedRoot = path.resolve(rootDir);
43
+ if (mappingsCache.has(resolvedRoot)) {
44
+ return mappingsCache.get(resolvedRoot) ?? null;
45
+ }
46
+ const tsconfigPath = path.join(resolvedRoot, 'tsconfig.json');
20
47
  if (!fs.existsSync(tsconfigPath)) {
21
- cachedMappings = null;
48
+ mappingsCache.set(resolvedRoot, null);
22
49
  return null;
23
50
  }
24
51
  try {
@@ -26,41 +53,110 @@ export function getTsConfigPathMappings() {
26
53
  const tsconfig = JSON.parse(tsconfigContent);
27
54
  const compilerOptions = tsconfig.compilerOptions || {};
28
55
  if (compilerOptions.paths) {
29
- cachedMappings = {
56
+ const mappings = {
30
57
  baseUrl: compilerOptions.baseUrl || '.',
31
58
  paths: compilerOptions.paths,
59
+ rootDir: resolvedRoot,
32
60
  };
33
- return cachedMappings;
61
+ mappingsCache.set(resolvedRoot, mappings);
62
+ return mappings;
34
63
  }
35
64
  }
36
65
  catch {
37
- // Ignore parsing errors
66
+ // Ignore parsing errors — treat as "no paths configured".
38
67
  }
39
- cachedMappings = null;
68
+ mappingsCache.set(resolvedRoot, null);
40
69
  return null;
41
70
  }
42
71
  /**
43
- * Resolves a path alias to an absolute path using tsconfig.json mappings.
72
+ * Resolve a TypeScript path alias (e.g. `@/tools/MyTool`) to an
73
+ * absolute path. Returns null if no alias matches.
44
74
  *
45
- * @param specifier - The import specifier (e.g., '@/tools/MyTool')
46
- * @returns Resolved absolute path or null if no alias matched
75
+ * `rootDir` is required it's the project's root, the directory that
76
+ * contains the tsconfig.json whose `paths` we're consulting.
47
77
  */
48
- export function resolvePathAlias(specifier) {
49
- const mappings = getTsConfigPathMappings();
78
+ export function resolvePathAlias(specifier, rootDir) {
79
+ const mappings = getTsConfigPathMappings(rootDir);
50
80
  if (!mappings)
51
81
  return null;
52
- // Sort patterns by specificity (longest first) to match TypeScript's behavior
82
+ // Sort patterns by specificity (longest first) mirrors TypeScript's
83
+ // own order-of-precedence for overlapping patterns.
53
84
  const sortedPatterns = Object.entries(mappings.paths).sort(([a], [b]) => b.length - a.length);
54
85
  for (const [pattern, targets] of sortedPatterns) {
55
- // Convert TypeScript path pattern to regex (e.g., "@/*" -> /^@\/(.*)$/)
86
+ // Convert a TS path pattern to regex: `@/*` /^@\/(.*)$/
56
87
  const patternRegex = new RegExp('^' + pattern.replace(/\*/g, '(.*)').replace(/\//g, '\\/') + '$');
57
88
  const match = specifier.match(patternRegex);
58
89
  if (match) {
59
90
  const captured = match[1] || '';
60
91
  const targetPath = targets[0].replace('*', captured);
61
- return path.join(process.cwd(), mappings.baseUrl, targetPath);
92
+ return path.join(mappings.rootDir, mappings.baseUrl, targetPath);
62
93
  }
63
94
  }
64
95
  return null;
65
96
  }
97
+ /**
98
+ * Resolve a module specifier (`./foo`, `../bar`, `@/tools/Xyz`) to an
99
+ * absolute file path, trying each of our supported extensions.
100
+ *
101
+ * This is the single consolidated helper that replaces:
102
+ * - `reference-resolver.ts::resolveSpecifierToPath`
103
+ * - `agent-traverser.ts::resolveImportPath`
104
+ *
105
+ * Both previously duplicated this logic; drift between them was a real
106
+ * bug surface. Returns undefined when nothing resolves — callers
107
+ * interpret that as a deopt or a warning depending on context.
108
+ */
109
+ export function resolveModuleSpecifier(specifier, fromFile, rootDir) {
110
+ // Strip trailing `.js` which NodeNext users write for runtime
111
+ // compatibility (`import foo from './foo.js'` refers to `foo.ts`
112
+ // during compilation).
113
+ const normalized = specifier.endsWith('.js') ? specifier.slice(0, -3) : specifier;
114
+ // Path alias wins when configured — matches TypeScript's resolver order.
115
+ const aliasResolved = resolvePathAlias(normalized, rootDir);
116
+ if (aliasResolved) {
117
+ return tryExtensions(aliasResolved);
118
+ }
119
+ if (normalized.startsWith('./') || normalized.startsWith('../')) {
120
+ const basePath = path.resolve(path.dirname(fromFile), normalized);
121
+ return tryExtensions(basePath);
122
+ }
123
+ // Bare specifiers (npm packages) aren't resolved here — they're
124
+ // someone else's responsibility.
125
+ return undefined;
126
+ }
127
+ function tryExtensions(basePath) {
128
+ for (const ext of MODULE_EXTENSIONS) {
129
+ const full = ext.startsWith('/') ? path.join(basePath, ext) : basePath + ext;
130
+ if (fs.existsSync(full))
131
+ return full;
132
+ }
133
+ return undefined;
134
+ }
135
+ /**
136
+ * Associate a ts-morph Project with its source `rootDir`. Called once
137
+ * by the Compiler constructor. Downstream code that only has a
138
+ * SourceFile can recover the rootDir via `getProjectRootDir`.
139
+ */
140
+ export function registerProjectRootDir(project, rootDir) {
141
+ projectRootDirs.set(project, path.resolve(rootDir));
142
+ }
143
+ /**
144
+ * Look up the registered rootDir for a project, or `undefined` if the
145
+ * project wasn't registered. Callers that need a rootDir but can't
146
+ * tolerate undefined should fall back to a sensible default (e.g.
147
+ * process.cwd() for standalone tooling, or a field on the plugin
148
+ * context for in-compiler use).
149
+ */
150
+ export function getProjectRootDir(project) {
151
+ return projectRootDirs.get(project);
152
+ }
153
+ /**
154
+ * Test-only: clear the path-alias cache. Tests that compile multiple
155
+ * projects back-to-back in the same process should call this between
156
+ * compilations to avoid stale aliases; the Compiler itself doesn't
157
+ * need to call this because the cache is keyed by rootDir.
158
+ */
159
+ export function clearPathResolverCacheForTests() {
160
+ mappingsCache.clear();
161
+ }
66
162
  //# sourceMappingURL=path-resolver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"path-resolver.js","sourceRoot":"","sources":["../../../src/compiler/utils/path-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,IAAI,cAA+C,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,cAAc,KAAK,SAAS;QAAE,OAAO,cAAc,CAAC;IAExD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;IAE/D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,cAAc,GAAG,IAAI,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAC7C,MAAM,eAAe,GAAG,QAAQ,CAAC,eAAe,IAAI,EAAE,CAAC;QAEvD,IAAI,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,cAAc,GAAG;gBACf,OAAO,EAAE,eAAe,CAAC,OAAO,IAAI,GAAG;gBACvC,KAAK,EAAE,eAAe,CAAC,KAAK;aAC7B,CAAC;YACF,OAAO,cAAc,CAAC;QACxB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,wBAAwB;IAC1B,CAAC;IAED,cAAc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,GAAG,GAAG,CAAC;QAC7E,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;IACvC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgB,EAAE,OAAe;IACtE,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAC5C,aAAa,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Primitive Reference Resolver
3
+ *
4
+ * Statically resolves a TypeScript expression that is expected to yield an
5
+ * array of primitive instances (e.g. `mcpServers: [luaDocsMcpServer, ...more]`)
6
+ * into a list of named references (`ResolvedRef[]`), without executing user
7
+ * code.
8
+ *
9
+ * ## Supported expression shapes
10
+ *
11
+ * - Inline: `[new LuaMCPServer({...}), foo]`
12
+ * - Variable ref: `const servers = [...]; mcpServers: servers`
13
+ * - Spread: `[...base, new LuaMCPServer({...})]`
14
+ * - Cross-file: `import servers from './servers'; mcpServers: servers`
15
+ * - Re-export: `export { servers } from './impl'`
16
+ * - Barrel chains: `export * from './servers'` + same-name imports
17
+ * - Path aliases: `@shared/tools`, `~/lib/tools`, etc. (via tsconfig paths)
18
+ * - Property read: `const all = { mcp: [...] }; mcpServers: all.mcp`
19
+ * - Identifier chains: `const a = inner; const b = a; mcpServers: b`
20
+ *
21
+ * ## Result shape (Babel's `path.evaluate()` convention)
22
+ *
23
+ * { confident: true; value: ResolvedRef[] }
24
+ * | { confident: false; value: ResolvedRef[]; deopt: Node; reason: string;
25
+ * ruleId: 'lua/unresolved-primitive-ref' }
26
+ *
27
+ * The `deopt` field pinpoints the AST node that defeated resolution so the
28
+ * compiler can emit an actionable `file:line:col` diagnostic. Partial results
29
+ * (`value`) are returned even on deopt so the compiler can emit whatever was
30
+ * resolvable up to the unknown shape.
31
+ *
32
+ * ## Resolution strategy
33
+ *
34
+ * 1. **AST fast path** (primary). Traverse ArrayLiteralExpression, follow
35
+ * Identifiers to their VariableDeclaration (same-file or via ImportDeclaration
36
+ * → getModuleSpecifierSourceFile()), recursively expand spreads. This is
37
+ * the idiomatic ts-morph pattern (see ts-morph issue #644 — manual iteration
38
+ * is ~1000x faster than getExportedDeclarations() because it doesn't trigger
39
+ * full symbol binding). Files are added to the project on demand via
40
+ * `addSourceFileAtPath()` as the walk discovers them.
41
+ * 2. **Symbol fallback** (only when fast path exhausts). Uses
42
+ * `getAliasedSymbol()` + `symbol.getDeclarations()[0]` to handle exotic
43
+ * re-export chains the manual walk can't follow.
44
+ *
45
+ * ## Escape hatch
46
+ *
47
+ * A leading `/* @lua-ignore-ref *\/` comment on the expression silences the
48
+ * deopt diagnostic for users who intentionally construct the array dynamically.
49
+ *
50
+ * ## Why we don't evaluate code
51
+ *
52
+ * Earlier iterations used `ts-evaluator` to sandbox-evaluate array expressions.
53
+ * That path loses the link to the compile-time identifier (it yields runtime
54
+ * `.name` strings, not the class/variable name needed for import resolution)
55
+ * and adds a sandboxed-RCE surface (cf. CVE-2023-45133 in Babel). The AST
56
+ * approach covers every case the evaluator did, cheaper and safer.
57
+ */
58
+ import { Node, Project, SourceFile, VariableDeclaration, ClassDeclaration, FunctionDeclaration, NewExpression } from 'ts-morph';
59
+ /**
60
+ * A resolved primitive reference.
61
+ *
62
+ * Carries enough information for downstream consumers (AgentTraverser,
63
+ * SkillPlugin) to locate both the identifier name and the source file
64
+ * where the primitive is declared — no second pass through `findImportSource`
65
+ * needed.
66
+ */
67
+ export interface ResolvedRef {
68
+ /**
69
+ * The identifier name as written in user code (`luaDocsMcpServer`,
70
+ * `MyToolClass`, `default`). Used for plugin detect() matching and
71
+ * manifest lookup.
72
+ */
73
+ identifierName: string;
74
+ /**
75
+ * The source file containing the ultimate declaration. May be different
76
+ * from the agent's source file when the ref came from an import or
77
+ * re-export chain.
78
+ */
79
+ sourceFile: SourceFile;
80
+ /**
81
+ * The underlying declaration node. For `new LuaMCPServer({...})` assigned
82
+ * to a `const`, this is the VariableDeclaration. For a bare `new X()` inline
83
+ * element, this is undefined and `newExpression` carries the node.
84
+ */
85
+ declaration?: VariableDeclaration | ClassDeclaration | FunctionDeclaration;
86
+ /**
87
+ * For inline `new X({...})` elements that aren't bound to a variable,
88
+ * this is the NewExpression itself. Lets the agent traverser report
89
+ * them with a synthetic name (`__inline_<n>`) rather than dropping them.
90
+ */
91
+ newExpression?: NewExpression;
92
+ /**
93
+ * True when the ref reached this source file through a default import
94
+ * (`import x from './target'`). Downstream detect-match logic uses this
95
+ * to prefer the target file's default export over a name-based match,
96
+ * because the local binding name (`x`) is chosen by the consumer and
97
+ * is unrelated to any exportName on the target side.
98
+ */
99
+ viaDefaultImport?: boolean;
100
+ }
101
+ /**
102
+ * Babel-style evaluation result. `confident: true` means the resolver is
103
+ * certain it saw every ref in the expression. `confident: false` means the
104
+ * walk hit something it couldn't statically understand — `value` holds what
105
+ * was resolvable up to that point.
106
+ */
107
+ export type EvaluationResult = {
108
+ confident: true;
109
+ value: ResolvedRef[];
110
+ } | {
111
+ confident: false;
112
+ value: ResolvedRef[];
113
+ deopt: Node;
114
+ reason: string;
115
+ ruleId: 'lua/unresolved-primitive-ref';
116
+ };
117
+ /**
118
+ * Shared state for a single `resolveArrayRefs()` invocation: carries the
119
+ * ts-morph project for on-demand file loading, a cycle-detection set, and
120
+ * an optional debug logger.
121
+ */
122
+ export interface ResolverContext {
123
+ /** ts-morph project — resolver may call addSourceFileAtPath() on it. */
124
+ project: Project;
125
+ /**
126
+ * Project rootDir used for resolving tsconfig `paths` aliases and
127
+ * relative imports. When omitted, the resolver falls back to
128
+ * `getProjectRootDir(project)` — which the Compiler populates in its
129
+ * constructor. Tests or direct callers can pass it explicitly.
130
+ */
131
+ rootDir?: string;
132
+ /**
133
+ * Set of `<absolutePath>#<identifier>` pairs we've already visited in this
134
+ * walk, used to break cycles (A imports B, B re-exports A, etc.).
135
+ */
136
+ visited?: Set<string>;
137
+ /** Optional debug logger. */
138
+ log?: (message: string) => void;
139
+ }
140
+ /**
141
+ * Resolve an expression node that represents an array of primitive references.
142
+ *
143
+ * Typical usage from a plugin/traverser:
144
+ *
145
+ * const prop = configObj.getProperty('mcpServers');
146
+ * const init = (prop as PropertyAssignment).getInitializer();
147
+ * const result = resolveArrayRefs(init, { project });
148
+ * if (!result.confident) { log.warn(reportDeopt(result, 'mcpServers')); }
149
+ * const refs = result.value;
150
+ *
151
+ * @param expression - The expression node whose value is expected to be an
152
+ * array of primitive instances. Typically the initializer of a
153
+ * `skills` / `tools` / `mcpServers` property.
154
+ * @param ctx - Resolver context carrying the project and optional logger.
155
+ * @returns An `EvaluationResult` — confident + full value on success,
156
+ * confident:false + partial value + deopt node on unknown shapes.
157
+ */
158
+ export declare function resolveArrayRefs(expression: Node | undefined, ctx: ResolverContext): EvaluationResult;
159
+ /**
160
+ * Format an `EvaluationResult.deopt` as a SARIF-style diagnostic string
161
+ * for `log.warn()`. Includes the rule id, file:line:col, reason, and a
162
+ * remediation hint pointing the user at the escape hatch.
163
+ *
164
+ * Call sites log this rather than constructing the string inline so every
165
+ * resolver deopt surfaces with the same shape.
166
+ */
167
+ export declare function reportDeopt(result: Extract<EvaluationResult, {
168
+ confident: false;
169
+ }>, propertyName: string): string;
170
+ /**
171
+ * Rule IDs used by resolver/traverser diagnostics. SARIF requires every
172
+ * issued warning to carry a stable, human-meaningful id so tools
173
+ * (CI, editor integrations) can filter or suppress them individually.
174
+ * Keep this list small and descriptive — new rules should follow the
175
+ * `lua/<kebab-case-category>` naming convention.
176
+ */
177
+ export type DiagnosticRuleId = 'lua/unresolved-primitive-ref' | 'lua/missing-primitive-declaration' | 'lua/missing-tool-import';
178
+ /**
179
+ * Format a SARIF-style diagnostic that isn't anchored on an AST node we
180
+ * parsed directly (e.g. "tried to find a tool in this file and the
181
+ * plugin returned nothing"). For node-anchored deopts, use
182
+ * `reportDeopt()` instead — it produces richer output.
183
+ *
184
+ * All resolver/traverser warnings should flow through either this
185
+ * helper or `reportDeopt`, so every line the user sees has a rule id
186
+ * and follows the same shape.
187
+ */
188
+ export declare function formatSarifWarning(args: {
189
+ ruleId: DiagnosticRuleId;
190
+ filePath: string;
191
+ line?: number;
192
+ column?: number;
193
+ message: string;
194
+ hint?: string;
195
+ }): string;
196
+ //# sourceMappingURL=reference-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-resolver.d.ts","sourceRoot":"","sources":["../../../src/compiler/utils/reference-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,EACL,IAAI,EACJ,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EAId,MAAM,UAAU,CAAC;AAUlB;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,UAAU,EAAE,UAAU,CAAC;IACvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;IAC3E;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,GACzC;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE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