@detergent-software/atk 0.12.1-dev.2

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 (314) hide show
  1. package/build/cli.d.ts +3 -0
  2. package/build/cli.d.ts.map +1 -0
  3. package/build/cli.js +35 -0
  4. package/build/cli.js.map +1 -0
  5. package/build/commands/_app.d.ts +3 -0
  6. package/build/commands/_app.d.ts.map +1 -0
  7. package/build/commands/_app.js +12 -0
  8. package/build/commands/_app.js.map +1 -0
  9. package/build/commands/audit.d.ts +12 -0
  10. package/build/commands/audit.d.ts.map +1 -0
  11. package/build/commands/audit.js +78 -0
  12. package/build/commands/audit.js.map +1 -0
  13. package/build/commands/browse.d.ts +15 -0
  14. package/build/commands/browse.d.ts.map +1 -0
  15. package/build/commands/browse.js +284 -0
  16. package/build/commands/browse.js.map +1 -0
  17. package/build/commands/cache.d.ts +13 -0
  18. package/build/commands/cache.d.ts.map +1 -0
  19. package/build/commands/cache.js +67 -0
  20. package/build/commands/cache.js.map +1 -0
  21. package/build/commands/config.d.ts +13 -0
  22. package/build/commands/config.d.ts.map +1 -0
  23. package/build/commands/config.js +62 -0
  24. package/build/commands/config.js.map +1 -0
  25. package/build/commands/diff.d.ts +16 -0
  26. package/build/commands/diff.d.ts.map +1 -0
  27. package/build/commands/diff.js +158 -0
  28. package/build/commands/diff.js.map +1 -0
  29. package/build/commands/doctor.d.ts +11 -0
  30. package/build/commands/doctor.d.ts.map +1 -0
  31. package/build/commands/doctor.js +30 -0
  32. package/build/commands/doctor.js.map +1 -0
  33. package/build/commands/index.d.ts +3 -0
  34. package/build/commands/index.d.ts.map +1 -0
  35. package/build/commands/index.js +30 -0
  36. package/build/commands/index.js.map +1 -0
  37. package/build/commands/info.d.ts +25 -0
  38. package/build/commands/info.d.ts.map +1 -0
  39. package/build/commands/info.js +198 -0
  40. package/build/commands/info.js.map +1 -0
  41. package/build/commands/init.d.ts +17 -0
  42. package/build/commands/init.d.ts.map +1 -0
  43. package/build/commands/init.js +504 -0
  44. package/build/commands/init.js.map +1 -0
  45. package/build/commands/install.d.ts +18 -0
  46. package/build/commands/install.d.ts.map +1 -0
  47. package/build/commands/install.js +186 -0
  48. package/build/commands/install.js.map +1 -0
  49. package/build/commands/list.d.ts +20 -0
  50. package/build/commands/list.d.ts.map +1 -0
  51. package/build/commands/list.js +61 -0
  52. package/build/commands/list.js.map +1 -0
  53. package/build/commands/outdated.d.ts +21 -0
  54. package/build/commands/outdated.d.ts.map +1 -0
  55. package/build/commands/outdated.js +81 -0
  56. package/build/commands/outdated.js.map +1 -0
  57. package/build/commands/pin.d.ts +22 -0
  58. package/build/commands/pin.d.ts.map +1 -0
  59. package/build/commands/pin.js +94 -0
  60. package/build/commands/pin.js.map +1 -0
  61. package/build/commands/prune.d.ts +14 -0
  62. package/build/commands/prune.d.ts.map +1 -0
  63. package/build/commands/prune.js +203 -0
  64. package/build/commands/prune.js.map +1 -0
  65. package/build/commands/publish.d.ts +14 -0
  66. package/build/commands/publish.d.ts.map +1 -0
  67. package/build/commands/publish.js +345 -0
  68. package/build/commands/publish.js.map +1 -0
  69. package/build/commands/search.d.ts +16 -0
  70. package/build/commands/search.d.ts.map +1 -0
  71. package/build/commands/search.js +80 -0
  72. package/build/commands/search.js.map +1 -0
  73. package/build/commands/sync.d.ts +15 -0
  74. package/build/commands/sync.d.ts.map +1 -0
  75. package/build/commands/sync.js +209 -0
  76. package/build/commands/sync.js.map +1 -0
  77. package/build/commands/uninstall.d.ts +18 -0
  78. package/build/commands/uninstall.d.ts.map +1 -0
  79. package/build/commands/uninstall.js +304 -0
  80. package/build/commands/uninstall.js.map +1 -0
  81. package/build/commands/unpin.d.ts +22 -0
  82. package/build/commands/unpin.d.ts.map +1 -0
  83. package/build/commands/unpin.js +79 -0
  84. package/build/commands/unpin.js.map +1 -0
  85. package/build/commands/update.d.ts +17 -0
  86. package/build/commands/update.d.ts.map +1 -0
  87. package/build/commands/update.js +151 -0
  88. package/build/commands/update.js.map +1 -0
  89. package/build/commands/why.d.ts +23 -0
  90. package/build/commands/why.d.ts.map +1 -0
  91. package/build/commands/why.js +108 -0
  92. package/build/commands/why.js.map +1 -0
  93. package/build/components/AssetDetail.d.ts +32 -0
  94. package/build/components/AssetDetail.d.ts.map +1 -0
  95. package/build/components/AssetDetail.js +45 -0
  96. package/build/components/AssetDetail.js.map +1 -0
  97. package/build/components/AssetTable.d.ts +25 -0
  98. package/build/components/AssetTable.d.ts.map +1 -0
  99. package/build/components/AssetTable.js +96 -0
  100. package/build/components/AssetTable.js.map +1 -0
  101. package/build/components/BrowseExpandedBundle.d.ts +26 -0
  102. package/build/components/BrowseExpandedBundle.d.ts.map +1 -0
  103. package/build/components/BrowseExpandedBundle.js +59 -0
  104. package/build/components/BrowseExpandedBundle.js.map +1 -0
  105. package/build/components/BrowseExpandedRow.d.ts +14 -0
  106. package/build/components/BrowseExpandedRow.d.ts.map +1 -0
  107. package/build/components/BrowseExpandedRow.js +9 -0
  108. package/build/components/BrowseExpandedRow.js.map +1 -0
  109. package/build/components/BrowseList.d.ts +26 -0
  110. package/build/components/BrowseList.d.ts.map +1 -0
  111. package/build/components/BrowseList.js +101 -0
  112. package/build/components/BrowseList.js.map +1 -0
  113. package/build/components/BundleDetail.d.ts +7 -0
  114. package/build/components/BundleDetail.d.ts.map +1 -0
  115. package/build/components/BundleDetail.js +12 -0
  116. package/build/components/BundleDetail.js.map +1 -0
  117. package/build/components/DependencyTree.d.ts +19 -0
  118. package/build/components/DependencyTree.d.ts.map +1 -0
  119. package/build/components/DependencyTree.js +21 -0
  120. package/build/components/DependencyTree.js.map +1 -0
  121. package/build/components/DiagnosticList.d.ts +19 -0
  122. package/build/components/DiagnosticList.d.ts.map +1 -0
  123. package/build/components/DiagnosticList.js +17 -0
  124. package/build/components/DiagnosticList.js.map +1 -0
  125. package/build/components/DiffView.d.ts +30 -0
  126. package/build/components/DiffView.d.ts.map +1 -0
  127. package/build/components/DiffView.js +32 -0
  128. package/build/components/DiffView.js.map +1 -0
  129. package/build/components/DryRunBanner.d.ts +11 -0
  130. package/build/components/DryRunBanner.d.ts.map +1 -0
  131. package/build/components/DryRunBanner.js +6 -0
  132. package/build/components/DryRunBanner.js.map +1 -0
  133. package/build/components/Field.d.ts +12 -0
  134. package/build/components/Field.d.ts.map +1 -0
  135. package/build/components/Field.js +9 -0
  136. package/build/components/Field.js.map +1 -0
  137. package/build/components/FilterBar.d.ts +18 -0
  138. package/build/components/FilterBar.d.ts.map +1 -0
  139. package/build/components/FilterBar.js +21 -0
  140. package/build/components/FilterBar.js.map +1 -0
  141. package/build/components/Header.d.ts +13 -0
  142. package/build/components/Header.d.ts.map +1 -0
  143. package/build/components/Header.js +20 -0
  144. package/build/components/Header.js.map +1 -0
  145. package/build/components/HelpBar.d.ts +11 -0
  146. package/build/components/HelpBar.d.ts.map +1 -0
  147. package/build/components/HelpBar.js +9 -0
  148. package/build/components/HelpBar.js.map +1 -0
  149. package/build/components/InstallConfirmBar.d.ts +9 -0
  150. package/build/components/InstallConfirmBar.d.ts.map +1 -0
  151. package/build/components/InstallConfirmBar.js +23 -0
  152. package/build/components/InstallConfirmBar.js.map +1 -0
  153. package/build/components/InstallSummary.d.ts +29 -0
  154. package/build/components/InstallSummary.d.ts.map +1 -0
  155. package/build/components/InstallSummary.js +12 -0
  156. package/build/components/InstallSummary.js.map +1 -0
  157. package/build/components/SectionDivider.d.ts +5 -0
  158. package/build/components/SectionDivider.d.ts.map +1 -0
  159. package/build/components/SectionDivider.js +11 -0
  160. package/build/components/SectionDivider.js.map +1 -0
  161. package/build/components/Spinner.d.ts +13 -0
  162. package/build/components/Spinner.d.ts.map +1 -0
  163. package/build/components/Spinner.js +11 -0
  164. package/build/components/Spinner.js.map +1 -0
  165. package/build/components/StatusBadge.d.ts +23 -0
  166. package/build/components/StatusBadge.d.ts.map +1 -0
  167. package/build/components/StatusBadge.js +43 -0
  168. package/build/components/StatusBadge.js.map +1 -0
  169. package/build/components/index.d.ts +20 -0
  170. package/build/components/index.d.ts.map +1 -0
  171. package/build/components/index.js +20 -0
  172. package/build/components/index.js.map +1 -0
  173. package/build/hooks/useBrowseState.d.ts +122 -0
  174. package/build/hooks/useBrowseState.d.ts.map +1 -0
  175. package/build/hooks/useBrowseState.js +315 -0
  176. package/build/hooks/useBrowseState.js.map +1 -0
  177. package/build/hooks/useCommand.d.ts +23 -0
  178. package/build/hooks/useCommand.d.ts.map +1 -0
  179. package/build/hooks/useCommand.js +43 -0
  180. package/build/hooks/useCommand.js.map +1 -0
  181. package/build/lib/adapter.d.ts +40 -0
  182. package/build/lib/adapter.d.ts.map +1 -0
  183. package/build/lib/adapter.js +112 -0
  184. package/build/lib/adapter.js.map +1 -0
  185. package/build/lib/auth.d.ts +31 -0
  186. package/build/lib/auth.d.ts.map +1 -0
  187. package/build/lib/auth.js +101 -0
  188. package/build/lib/auth.js.map +1 -0
  189. package/build/lib/breakpoints.d.ts +3 -0
  190. package/build/lib/breakpoints.d.ts.map +1 -0
  191. package/build/lib/breakpoints.js +8 -0
  192. package/build/lib/breakpoints.js.map +1 -0
  193. package/build/lib/checksum.d.ts +31 -0
  194. package/build/lib/checksum.d.ts.map +1 -0
  195. package/build/lib/checksum.js +78 -0
  196. package/build/lib/checksum.js.map +1 -0
  197. package/build/lib/config.d.ts +42 -0
  198. package/build/lib/config.d.ts.map +1 -0
  199. package/build/lib/config.js +123 -0
  200. package/build/lib/config.js.map +1 -0
  201. package/build/lib/detector.d.ts +35 -0
  202. package/build/lib/detector.d.ts.map +1 -0
  203. package/build/lib/detector.js +125 -0
  204. package/build/lib/detector.js.map +1 -0
  205. package/build/lib/diagnostics.d.ts +10 -0
  206. package/build/lib/diagnostics.d.ts.map +1 -0
  207. package/build/lib/diagnostics.js +195 -0
  208. package/build/lib/diagnostics.js.map +1 -0
  209. package/build/lib/diff.d.ts +34 -0
  210. package/build/lib/diff.d.ts.map +1 -0
  211. package/build/lib/diff.js +78 -0
  212. package/build/lib/diff.js.map +1 -0
  213. package/build/lib/fetch-retry.d.ts +43 -0
  214. package/build/lib/fetch-retry.d.ts.map +1 -0
  215. package/build/lib/fetch-retry.js +137 -0
  216. package/build/lib/fetch-retry.js.map +1 -0
  217. package/build/lib/github.d.ts +57 -0
  218. package/build/lib/github.d.ts.map +1 -0
  219. package/build/lib/github.js +96 -0
  220. package/build/lib/github.js.map +1 -0
  221. package/build/lib/gitignore.d.ts +37 -0
  222. package/build/lib/gitignore.d.ts.map +1 -0
  223. package/build/lib/gitignore.js +142 -0
  224. package/build/lib/gitignore.js.map +1 -0
  225. package/build/lib/init.d.ts +100 -0
  226. package/build/lib/init.d.ts.map +1 -0
  227. package/build/lib/init.js +295 -0
  228. package/build/lib/init.js.map +1 -0
  229. package/build/lib/installer.d.ts +50 -0
  230. package/build/lib/installer.d.ts.map +1 -0
  231. package/build/lib/installer.js +435 -0
  232. package/build/lib/installer.js.map +1 -0
  233. package/build/lib/lockfile.d.ts +170 -0
  234. package/build/lib/lockfile.d.ts.map +1 -0
  235. package/build/lib/lockfile.js +437 -0
  236. package/build/lib/lockfile.js.map +1 -0
  237. package/build/lib/markdown.d.ts +9 -0
  238. package/build/lib/markdown.d.ts.map +1 -0
  239. package/build/lib/markdown.js +67 -0
  240. package/build/lib/markdown.js.map +1 -0
  241. package/build/lib/parse-json.d.ts +34 -0
  242. package/build/lib/parse-json.d.ts.map +1 -0
  243. package/build/lib/parse-json.js +52 -0
  244. package/build/lib/parse-json.js.map +1 -0
  245. package/build/lib/paths.d.ts +28 -0
  246. package/build/lib/paths.d.ts.map +1 -0
  247. package/build/lib/paths.js +68 -0
  248. package/build/lib/paths.js.map +1 -0
  249. package/build/lib/publisher.d.ts +49 -0
  250. package/build/lib/publisher.d.ts.map +1 -0
  251. package/build/lib/publisher.js +388 -0
  252. package/build/lib/publisher.js.map +1 -0
  253. package/build/lib/registry.d.ts +97 -0
  254. package/build/lib/registry.d.ts.map +1 -0
  255. package/build/lib/registry.js +248 -0
  256. package/build/lib/registry.js.map +1 -0
  257. package/build/lib/resolver.d.ts +50 -0
  258. package/build/lib/resolver.d.ts.map +1 -0
  259. package/build/lib/resolver.js +110 -0
  260. package/build/lib/resolver.js.map +1 -0
  261. package/build/lib/schemas/adapter.d.ts +33 -0
  262. package/build/lib/schemas/adapter.d.ts.map +1 -0
  263. package/build/lib/schemas/adapter.js +27 -0
  264. package/build/lib/schemas/adapter.js.map +1 -0
  265. package/build/lib/schemas/bundle.d.ts +38 -0
  266. package/build/lib/schemas/bundle.d.ts.map +1 -0
  267. package/build/lib/schemas/bundle.js +19 -0
  268. package/build/lib/schemas/bundle.js.map +1 -0
  269. package/build/lib/schemas/config.d.ts +12 -0
  270. package/build/lib/schemas/config.d.ts.map +1 -0
  271. package/build/lib/schemas/config.js +14 -0
  272. package/build/lib/schemas/config.js.map +1 -0
  273. package/build/lib/schemas/index.d.ts +7 -0
  274. package/build/lib/schemas/index.d.ts.map +1 -0
  275. package/build/lib/schemas/index.js +7 -0
  276. package/build/lib/schemas/index.js.map +1 -0
  277. package/build/lib/schemas/lockfile.d.ts +102 -0
  278. package/build/lib/schemas/lockfile.d.ts.map +1 -0
  279. package/build/lib/schemas/lockfile.js +50 -0
  280. package/build/lib/schemas/lockfile.js.map +1 -0
  281. package/build/lib/schemas/manifest.d.ts +91 -0
  282. package/build/lib/schemas/manifest.d.ts.map +1 -0
  283. package/build/lib/schemas/manifest.js +42 -0
  284. package/build/lib/schemas/manifest.js.map +1 -0
  285. package/build/lib/schemas/registry.d.ts +225 -0
  286. package/build/lib/schemas/registry.d.ts.map +1 -0
  287. package/build/lib/schemas/registry.js +59 -0
  288. package/build/lib/schemas/registry.js.map +1 -0
  289. package/build/lib/search.d.ts +23 -0
  290. package/build/lib/search.d.ts.map +1 -0
  291. package/build/lib/search.js +139 -0
  292. package/build/lib/search.js.map +1 -0
  293. package/build/lib/tool-resolver.d.ts +12 -0
  294. package/build/lib/tool-resolver.d.ts.map +1 -0
  295. package/build/lib/tool-resolver.js +24 -0
  296. package/build/lib/tool-resolver.js.map +1 -0
  297. package/build/lib/uninstaller.d.ts +109 -0
  298. package/build/lib/uninstaller.d.ts.map +1 -0
  299. package/build/lib/uninstaller.js +368 -0
  300. package/build/lib/uninstaller.js.map +1 -0
  301. package/build/lib/updater.d.ts +68 -0
  302. package/build/lib/updater.d.ts.map +1 -0
  303. package/build/lib/updater.js +230 -0
  304. package/build/lib/updater.js.map +1 -0
  305. package/build/lib/version.d.ts +13 -0
  306. package/build/lib/version.d.ts.map +1 -0
  307. package/build/lib/version.js +30 -0
  308. package/build/lib/version.js.map +1 -0
  309. package/build/windows-esm-loader.d.ts +15 -0
  310. package/build/windows-esm-loader.d.ts.map +1 -0
  311. package/build/windows-esm-loader.js +11 -0
  312. package/build/windows-esm-loader.js.map +1 -0
  313. package/package.json +67 -0
  314. package/tool-adapters/claude-code.json +34 -0
@@ -0,0 +1,435 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
3
+ import { dirname, join } from 'node:path';
4
+ import { getPlacement } from './adapter.js';
5
+ import { getGitHubToken } from './auth.js';
6
+ import { hashString } from './checksum.js';
7
+ import { fetchFileContent, getEffectiveBranch, listAssetDirectoryFiles } from './github.js';
8
+ import { ensureGitignoreEntries } from './gitignore.js';
9
+ import { addAssetToLockfile, readLockfile, removeAssetFromLockfile, writeLockfile } from './lockfile.js';
10
+ import { toRelativePosix } from './paths.js';
11
+ export class InstallerError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = 'InstallerError';
15
+ }
16
+ }
17
+ /**
18
+ * Execute a full install plan — install all assets in order.
19
+ * On partial failure, rolls back previously installed assets (deletes placed files,
20
+ * reverts config entries, removes lockfile entries) so the system is not left in
21
+ * an inconsistent state.
22
+ */
23
+ export async function executeInstallPlan(plan, options) {
24
+ const results = [];
25
+ // Ensure .gitignore has entries for ATK-managed asset directories (non-fatal)
26
+ try {
27
+ await ensureGitignoreEntries(options.projectDir, options.adapter);
28
+ }
29
+ catch {
30
+ options.onProgress?.('Warning: Failed to update .gitignore — continuing with install');
31
+ }
32
+ // Read lockfile once — used for both conflict detection and per-asset install logic
33
+ let lockfile = await readLockfile(options.projectDir, options.adapter.tool);
34
+ // Build set of ATK-managed file paths from the lockfile for conflict detection
35
+ const managedPaths = buildManagedPathsSet(lockfile, options.projectDir);
36
+ try {
37
+ for (const entry of plan.entries) {
38
+ const { lockfile: updatedLockfile, result } = await installAsset(entry, options, managedPaths, lockfile);
39
+ results.push(result);
40
+ lockfile = updatedLockfile;
41
+ }
42
+ }
43
+ catch (error) {
44
+ // Roll back all successfully installed assets in reverse order
45
+ if (results.length > 0) {
46
+ options.onProgress?.(`Install failed, rolling back ${results.length} installed asset(s)...`);
47
+ for (let i = results.length - 1; i >= 0; i--) {
48
+ const result = results[i];
49
+ options.onProgress?.(`Rolling back ${result.name}...`);
50
+ // Delete placed files (best-effort)
51
+ for (const file of result.filesPlaced) {
52
+ try {
53
+ if (existsSync(file.destination)) {
54
+ await unlink(file.destination);
55
+ }
56
+ }
57
+ catch (error) {
58
+ options.onProgress?.(`Warning: Failed to delete file during rollback: ${file.destination} — ${error instanceof Error ? error.message : String(error)}`);
59
+ }
60
+ }
61
+ // Revert config file entries (best-effort)
62
+ for (const entry of result.configEntriesCreated) {
63
+ try {
64
+ await revertConfigEntry(join(options.projectDir, entry.file), entry.key, options.onProgress);
65
+ }
66
+ catch (error) {
67
+ options.onProgress?.(`Warning: Failed to revert config entry ${entry.key} during rollback — ${error instanceof Error ? error.message : String(error)}`);
68
+ }
69
+ }
70
+ // Remove lockfile entry using in-memory lockfile (best-effort)
71
+ try {
72
+ lockfile = removeAssetFromLockfile(lockfile, result.name);
73
+ await writeLockfile(options.projectDir, lockfile);
74
+ }
75
+ catch (error) {
76
+ options.onProgress?.(`Warning: Failed to remove lockfile entry during rollback for ${result.name} — ${error instanceof Error ? error.message : String(error)}`);
77
+ }
78
+ }
79
+ options.onProgress?.(`Rollback complete.`);
80
+ }
81
+ // Re-throw the original error wrapped in InstallerError with rollback context
82
+ const originalMessage = error instanceof Error ? error.message : String(error);
83
+ throw new InstallerError(`Install failed at asset "${plan.entries[results.length]?.asset.name ?? 'unknown'}" ` +
84
+ `and ${results.length} previously installed asset(s) were rolled back: ${originalMessage}`);
85
+ }
86
+ return results;
87
+ }
88
+ /**
89
+ * Build a set of all file paths managed by ATK from the given lockfile.
90
+ * Used for conflict detection — files in this set can be safely overwritten.
91
+ * Resolves relative lockfile paths to absolute paths for comparison with `existsSync` results.
92
+ */
93
+ function buildManagedPathsSet(lockfile, projectDir) {
94
+ const paths = new Set();
95
+ for (const asset of lockfile.assets ?? []) {
96
+ for (const file of asset.files) {
97
+ paths.add(join(projectDir, file.installedPath));
98
+ }
99
+ }
100
+ return paths;
101
+ }
102
+ /**
103
+ * Check if a file at the destination path would conflict with an existing non-ATK file.
104
+ * Throws InstallerError if the file exists and is not tracked in the lockfile.
105
+ * ATK-managed files (in the lockfile) can be safely overwritten (e.g., reinstall/update).
106
+ */
107
+ async function checkFileConflict(destPath, managedPaths) {
108
+ if (!existsSync(destPath)) {
109
+ return;
110
+ }
111
+ if (managedPaths.has(destPath)) {
112
+ return;
113
+ }
114
+ throw new InstallerError(`File conflict: "${destPath}" already exists and was not installed by ATK. Use --force to overwrite.`);
115
+ }
116
+ /**
117
+ * Fetch all files for an asset from GitHub.
118
+ * Lists the asset directory contents and downloads each file in parallel.
119
+ * The version parameter is included in the URL path: assets/{type}s/{name}/{version}/
120
+ */
121
+ async function fetchAssetFiles(asset, version, registryBranch) {
122
+ const token = await getGitHubToken();
123
+ const effectiveBranch = getEffectiveBranch(registryBranch);
124
+ try {
125
+ const remoteFiles = await listAssetDirectoryFiles(token, asset, version, effectiveBranch);
126
+ const files = await Promise.all(remoteFiles.map(async (item) => {
127
+ const content = await fetchFileContent(token, item.path, effectiveBranch);
128
+ return {
129
+ content,
130
+ relativePath: item.name,
131
+ };
132
+ }));
133
+ if (files.length === 0) {
134
+ throw new InstallerError(`No installable files found for asset "${asset.name}"`);
135
+ }
136
+ return files;
137
+ }
138
+ catch (error) {
139
+ if (error instanceof InstallerError) {
140
+ throw error;
141
+ }
142
+ throw new InstallerError(error instanceof Error ? error.message : String(error));
143
+ }
144
+ }
145
+ /**
146
+ * Install a single asset from the install plan.
147
+ * Accepts the current in-memory lockfile and returns the updated lockfile alongside the result.
148
+ */
149
+ async function installAsset(entry, options, managedPaths, lockfile) {
150
+ const { asset } = entry;
151
+ const { adapter, force, onProgress, pin, projectDir, registryBranch } = options;
152
+ onProgress?.(`Installing ${asset.name}...`);
153
+ // Determine placement
154
+ const placement = getPlacement(adapter, asset.type);
155
+ if (!placement) {
156
+ throw new InstallerError(`Tool "${adapter.tool}" does not support asset type "${asset.type}"`);
157
+ }
158
+ // Determine base path
159
+ const basePath = projectDir;
160
+ // Fetch asset files from GitHub (version-aware path)
161
+ const assetFiles = await fetchAssetFiles(asset, entry.version, registryBranch);
162
+ // Find the entrypoint file
163
+ const entrypointFile = assetFiles.find((f) => isEntrypoint(f.relativePath, asset.type));
164
+ // Branch on placement type
165
+ const placedFiles = [];
166
+ const filesPlaced = [];
167
+ const configEntries = [];
168
+ if (placement.fileless) {
169
+ // Fileless placement (e.g., MCP configs) — no files placed on disk
170
+ // Config merging handled below
171
+ }
172
+ else if (asset.type === 'memory-template') {
173
+ // Memory templates append to a shared file with delimiters
174
+ const targetPath = join(basePath, placement.path.replace(/\{name\}/g, asset.name));
175
+ const targetDir = dirname(targetPath);
176
+ if (!existsSync(targetDir)) {
177
+ await mkdir(targetDir, { recursive: true });
178
+ }
179
+ const firstFile = assetFiles[0];
180
+ if (!entrypointFile && !firstFile) {
181
+ throw new InstallerError(`No files available for memory-template asset "${asset.name}"`);
182
+ }
183
+ const content = entrypointFile?.content ?? firstFile.content;
184
+ const delimitedContent = `<!-- ATK: ${asset.name} -->\n${content}\n<!-- /ATK: ${asset.name} -->`;
185
+ if (existsSync(targetPath)) {
186
+ const existing = await readFile(targetPath, 'utf-8');
187
+ // Strip any existing ATK block for this asset before appending the new one
188
+ const cleaned = stripAtkBlock(existing, asset.name);
189
+ await writeFile(targetPath, cleaned.trimEnd() + '\n\n' + delimitedContent + '\n', 'utf-8');
190
+ }
191
+ else {
192
+ await writeFile(targetPath, delimitedContent + '\n', 'utf-8');
193
+ }
194
+ // Record as config entry for tracking (not a regular file)
195
+ configEntries.push({
196
+ file: toRelativePosix(projectDir, targetPath),
197
+ key: `memory-template.${asset.name}`,
198
+ });
199
+ }
200
+ else if (placement.entrypointName) {
201
+ // Directory-based placement (e.g., skills)
202
+ for (const file of assetFiles) {
203
+ const destPath = resolveFilePath(placement.path, asset.name, basePath, file.relativePath, asset.type, placement.entrypointName);
204
+ const destDir = dirname(destPath);
205
+ if (!force) {
206
+ await checkFileConflict(destPath, managedPaths);
207
+ }
208
+ if (!existsSync(destDir)) {
209
+ await mkdir(destDir, { recursive: true });
210
+ }
211
+ await writeFile(destPath, file.content, 'utf-8');
212
+ const checksum = hashString(file.content);
213
+ placedFiles.push({
214
+ checksum,
215
+ installedPath: toRelativePosix(projectDir, destPath),
216
+ sourcePath: file.relativePath,
217
+ });
218
+ filesPlaced.push({
219
+ destination: destPath,
220
+ source: file.relativePath,
221
+ });
222
+ }
223
+ }
224
+ else {
225
+ // Default single-file placement
226
+ for (const file of assetFiles) {
227
+ const destPath = resolveFilePath(placement.path, asset.name, basePath, file.relativePath, asset.type);
228
+ const destDir = dirname(destPath);
229
+ if (!force) {
230
+ await checkFileConflict(destPath, managedPaths);
231
+ }
232
+ if (!existsSync(destDir)) {
233
+ await mkdir(destDir, { recursive: true });
234
+ }
235
+ await writeFile(destPath, file.content, 'utf-8');
236
+ const checksum = hashString(file.content);
237
+ placedFiles.push({
238
+ checksum,
239
+ installedPath: toRelativePosix(projectDir, destPath),
240
+ sourcePath: file.relativePath,
241
+ });
242
+ filesPlaced.push({
243
+ destination: destPath,
244
+ source: file.relativePath,
245
+ });
246
+ }
247
+ }
248
+ // Handle config file updates if needed
249
+ if (placement.configFile && placement.configKey) {
250
+ // Determine merge content for configMerge mode
251
+ let mergeContent;
252
+ if (placement.configMerge && entrypointFile) {
253
+ try {
254
+ mergeContent = JSON.parse(entrypointFile.content);
255
+ }
256
+ catch {
257
+ // If content isn't valid JSON, fall back to marker-only behavior
258
+ }
259
+ }
260
+ const configResult = await updateConfigFile(join(basePath, placement.configFile), placement.configKey, asset.name, asset.type, projectDir, mergeContent, onProgress);
261
+ if (configResult) {
262
+ configEntries.push(configResult);
263
+ }
264
+ }
265
+ // Update lockfile — use resolved version and per-version dependency data
266
+ const installedAsset = {
267
+ ...(options.bundleOrigin ? { bundleOrigin: options.bundleOrigin } : {}),
268
+ configEntries,
269
+ dependencies: (entry.versionData.dependencies ?? []).map((d) => ({
270
+ name: d.name,
271
+ type: d.type,
272
+ ...(d.version ? { version: d.version } : {}),
273
+ })),
274
+ files: placedFiles,
275
+ installedAt: new Date().toISOString(),
276
+ installReason: entry.reason,
277
+ name: asset.name,
278
+ ...(pin ? { pinnedVersion: entry.version } : {}),
279
+ type: asset.type,
280
+ version: entry.version,
281
+ };
282
+ const updatedLockfile = addAssetToLockfile(lockfile, installedAsset);
283
+ await writeLockfile(projectDir, updatedLockfile);
284
+ onProgress?.(`Installed ${asset.name}@${entry.version}`);
285
+ return {
286
+ lockfile: updatedLockfile,
287
+ result: {
288
+ ...(options.bundleOrigin ? { bundleOrigin: options.bundleOrigin } : {}),
289
+ configEntriesCreated: configEntries,
290
+ filesPlaced,
291
+ installReason: entry.reason,
292
+ name: asset.name,
293
+ type: asset.type,
294
+ version: entry.version,
295
+ },
296
+ };
297
+ }
298
+ /**
299
+ * Heuristic: the entrypoint is typically the main file matching the asset type convention.
300
+ * Returns false for unknown asset types to avoid multiple files resolving to the same path.
301
+ */
302
+ function isEntrypoint(relativePath, assetType) {
303
+ const entrypointPatterns = {
304
+ agent: /^(agent|index)\.(md|txt)$/i,
305
+ hook: /^(hook|index)\.(sh|js|ts)$/i,
306
+ 'mcp-config': /^(mcp-config|config|index)\.json$/i,
307
+ 'memory-template': /^(memory|template|index)\.(md|txt)$/i,
308
+ rule: /^(rule|rules|index)\.(md|txt)$/i,
309
+ skill: /^(skill|index)\.(md|txt)$/i,
310
+ };
311
+ const pattern = entrypointPatterns[assetType];
312
+ if (pattern) {
313
+ return pattern.test(relativePath);
314
+ }
315
+ // Unknown asset type — return false so each file keeps its original name
316
+ return false;
317
+ }
318
+ /**
319
+ * Resolve the destination file path for an asset file.
320
+ * For directory-based placement (entrypointName set), the path is a directory template.
321
+ * For the entrypoint (or single-file assets), use the placement path template.
322
+ * For additional files, place them relative to the entrypoint's directory.
323
+ */
324
+ function resolveFilePath(pathTemplate, assetName, basePath, relativePath, assetType, entrypointName) {
325
+ const resolvedTemplate = pathTemplate.replace(/\{name\}/g, assetName);
326
+ if (entrypointName) {
327
+ // Directory-based placement: path is a directory, entrypoint gets the fixed name
328
+ const dirPath = resolvedTemplate;
329
+ if (isEntrypoint(relativePath, assetType)) {
330
+ return join(basePath, dirPath, entrypointName);
331
+ }
332
+ return join(basePath, dirPath, relativePath);
333
+ }
334
+ // Default: single-file placement
335
+ const templateDir = dirname(resolvedTemplate);
336
+ if (isEntrypoint(relativePath, assetType)) {
337
+ return join(basePath, resolvedTemplate);
338
+ }
339
+ return join(basePath, templateDir, relativePath);
340
+ }
341
+ /**
342
+ * Revert a config file entry created during installation.
343
+ * Reads the config file, removes the entry at the given key path (e.g., "mcpServers.my-mcp"),
344
+ * and writes it back. If the parent section becomes empty, it is also removed.
345
+ */
346
+ async function revertConfigEntry(configFilePath, keyPath, onProgress) {
347
+ if (!existsSync(configFilePath)) {
348
+ return;
349
+ }
350
+ try {
351
+ const raw = await readFile(configFilePath, 'utf-8');
352
+ const config = JSON.parse(raw);
353
+ // keyPath is "section.childKey" (e.g., "mcpServers.my-mcp")
354
+ const dotIndex = keyPath.indexOf('.');
355
+ if (dotIndex === -1) {
356
+ return;
357
+ }
358
+ const sectionKey = keyPath.slice(0, dotIndex);
359
+ const childKey = keyPath.slice(dotIndex + 1);
360
+ const section = config[sectionKey];
361
+ if (!section || typeof section !== 'object') {
362
+ return;
363
+ }
364
+ const sectionObj = section;
365
+ delete sectionObj[childKey];
366
+ // Remove the section entirely if it's now empty
367
+ if (Object.keys(sectionObj).length === 0) {
368
+ delete config[sectionKey];
369
+ }
370
+ await writeFile(configFilePath, JSON.stringify(config, null, '\t') + '\n', 'utf-8');
371
+ }
372
+ catch (error) {
373
+ onProgress?.(`Warning: Failed to revert config entry ${keyPath} in ${configFilePath} — ${error instanceof Error ? error.message : String(error)}`);
374
+ }
375
+ }
376
+ /**
377
+ * Remove an existing ATK-delimited block for the given asset name from file content.
378
+ * Matches blocks of the form:
379
+ * <!-- ATK: {name} -->
380
+ * ...content...
381
+ * <!-- /ATK: {name} -->
382
+ * along with surrounding blank lines to keep formatting clean.
383
+ */
384
+ function stripAtkBlock(content, assetName) {
385
+ const escapedName = assetName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
386
+ const pattern = new RegExp(`(\n{0,2})<!-- ATK: ${escapedName} -->\\n[\\s\\S]*?<!-- /ATK: ${escapedName} -->\\n?`, 'g');
387
+ return content.replace(pattern, '');
388
+ }
389
+ /**
390
+ * Update a tool config file (e.g., settings.json) with an entry for the installed asset.
391
+ * When mergeContent is provided, it is merged into the config section with _managedBy marker.
392
+ * Otherwise, a simple marker is written.
393
+ */
394
+ async function updateConfigFile(configFilePath, configKey, assetName, assetType, projectDir, mergeContent, onProgress) {
395
+ try {
396
+ let config = {};
397
+ if (existsSync(configFilePath)) {
398
+ const raw = await readFile(configFilePath, 'utf-8');
399
+ config = JSON.parse(raw);
400
+ }
401
+ else {
402
+ const dir = dirname(configFilePath);
403
+ if (!existsSync(dir)) {
404
+ await mkdir(dir, { recursive: true });
405
+ }
406
+ }
407
+ // Get or create the section
408
+ if (!config[configKey] || typeof config[configKey] !== 'object') {
409
+ config[configKey] = {};
410
+ }
411
+ const section = config[configKey];
412
+ if (mergeContent) {
413
+ // Merge actual asset content with _managedBy marker
414
+ section[assetName] = {
415
+ ...mergeContent,
416
+ _managedBy: 'atk',
417
+ };
418
+ }
419
+ else {
420
+ // Simple marker
421
+ section[assetName] = {
422
+ _managedBy: 'atk',
423
+ type: assetType,
424
+ };
425
+ }
426
+ await writeFile(configFilePath, JSON.stringify(config, null, '\t') + '\n', 'utf-8');
427
+ return { file: toRelativePosix(projectDir, configFilePath), key: `${configKey}.${assetName}` };
428
+ }
429
+ catch (error) {
430
+ // Non-fatal — log but don't fail the install
431
+ onProgress?.(`Warning: Failed to update config file ${configFilePath} — ${error instanceof Error ? error.message : String(error)}`);
432
+ return null;
433
+ }
434
+ }
435
+ //# sourceMappingURL=installer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installer.js","sourceRoot":"","sources":["../../src/lib/installer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAO1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAkC7C,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,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AAc,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACtH,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,170 @@
1
+ import type { AssetType } from './schemas/manifest.js';
2
+ import { type InstalledAsset, type Lockfile } from './schemas/lockfile.js';
3
+ export interface AcquireLockOptions {
4
+ /** Maximum time (ms) to wait to acquire the lock. Default: 30 000. */
5
+ acquireTimeout?: number;
6
+ /** Interval (ms) between retry attempts. Default: 200. */
7
+ retryInterval?: number;
8
+ /** Time (ms) after which a held lock is considered stale. Default: 60 000. */
9
+ staleTimeout?: number;
10
+ }
11
+ /**
12
+ * A node in a reverse dependency chain, representing an asset that depends on its parent node.
13
+ * The tree is structured with the queried asset conceptually at the root and
14
+ * direct-install ancestors at the leaves.
15
+ */
16
+ export interface DependencyChainNode {
17
+ /** Child nodes representing dependents moving toward a direct-install root. */
18
+ children: DependencyChainNode[];
19
+ /** Why this asset was installed ('direct' or 'dependency'). */
20
+ installReason: 'dependency' | 'direct';
21
+ /** Asset name. */
22
+ name: string;
23
+ /** Asset type. */
24
+ type: AssetType;
25
+ /** Installed version. */
26
+ version: string;
27
+ }
28
+ /**
29
+ * Result of tracing the reverse dependency chain for an asset.
30
+ * Discriminated union on the `status` field.
31
+ */
32
+ export type DependencyChainResult = {
33
+ asset: InstalledAsset;
34
+ chains: DependencyChainNode[];
35
+ status: 'dependency';
36
+ } | {
37
+ asset: InstalledAsset;
38
+ status: 'direct';
39
+ } | {
40
+ asset: InstalledAsset;
41
+ status: 'orphaned';
42
+ } | {
43
+ name: string;
44
+ status: 'not_installed';
45
+ };
46
+ export declare class LockfileError extends Error {
47
+ constructor(message: string);
48
+ }
49
+ export declare class LockfileLockedError extends Error {
50
+ constructor(pid: number, sentinelPath: string);
51
+ }
52
+ /**
53
+ * Acquire an advisory lock on the lockfile.
54
+ *
55
+ * Creates a sentinel file (`.atk-lock.json.lock`) atomically using the `'wx'`
56
+ * flag. If the sentinel already exists the function will:
57
+ * 1. Read the sentinel to get the holding PID and timestamp.
58
+ * 2. If the holding PID is dead **or** the lock is older than `staleTimeout`,
59
+ * remove the stale sentinel and retry immediately.
60
+ * 3. Otherwise wait `retryInterval` ms and retry, up to `acquireTimeout` ms total.
61
+ *
62
+ * @throws {LockfileLockedError} if the lock cannot be acquired within the timeout.
63
+ */
64
+ export declare function acquireLockfileLock(projectDir: string, options?: AcquireLockOptions): Promise<void>;
65
+ /**
66
+ * Add an installed asset to the lockfile.
67
+ * If the asset already exists, it is replaced (updated).
68
+ */
69
+ export declare function addAssetToLockfile(lockfile: Lockfile, asset: InstalledAsset): Lockfile;
70
+ /**
71
+ * Find all orphaned dependency assets in the lockfile.
72
+ * An asset is orphaned if it was installed as a dependency but no longer has
73
+ * a valid reverse dependency chain leading to a direct-install root.
74
+ */
75
+ export declare function findAllOrphanedAssets(lockfile: Lockfile): InstalledAsset[];
76
+ /**
77
+ * Find installed assets that depend on the given asset.
78
+ * Returns those whose `dependencies` array includes the given asset name (and optionally type).
79
+ */
80
+ export declare function findDependents(lockfile: Lockfile, assetName: string, assetType?: AssetType): InstalledAsset[];
81
+ /**
82
+ * Find an installed asset in the lockfile.
83
+ */
84
+ export declare function findInstalledAsset(lockfile: Lockfile, name: string, type?: AssetType): InstalledAsset | undefined;
85
+ /**
86
+ * Find dependencies of assetBeingRemoved that would become orphaned after removal.
87
+ * A dependency is orphaned if:
88
+ * (a) it has installReason === 'dependency', and
89
+ * (b) no other remaining installed asset (excluding those in otherNamesBeingRemoved) lists it in dependencies.
90
+ */
91
+ export declare function findOrphanedDependencies(lockfile: Lockfile, assetBeingRemoved: InstalledAsset, otherNamesBeingRemoved?: string[]): InstalledAsset[];
92
+ /**
93
+ * Get all installed assets, optionally filtered by type.
94
+ */
95
+ export declare function getInstalledAssets(lockfile: Lockfile, type?: AssetType): InstalledAsset[];
96
+ /**
97
+ * Get the count of installed assets.
98
+ */
99
+ export declare function getInstalledCount(lockfile: Lockfile, type?: AssetType): number;
100
+ /**
101
+ * Get the path to the lockfile in the given project directory.
102
+ */
103
+ export declare function getLockfilePath(projectDir: string): string;
104
+ /**
105
+ * Get the path to the lock sentinel file for the given project directory.
106
+ */
107
+ export declare function getLockSentinelPath(projectDir: string): string;
108
+ /**
109
+ * Check if an asset is installed.
110
+ */
111
+ export declare function isInstalled(lockfile: Lockfile, name: string, type?: AssetType): boolean;
112
+ /**
113
+ * Check whether an asset has a pinned version in the lockfile.
114
+ * Returns `true` if the asset exists and has a truthy `pinnedVersion`, `false` otherwise.
115
+ * This is a read-only query that never throws.
116
+ */
117
+ export declare function isPinned(lockfile: Lockfile, name: string, type?: AssetType): boolean;
118
+ /**
119
+ * Pin an installed asset to a specific version.
120
+ * Only direct installs can be pinned; pinning a dependency throws an error.
121
+ *
122
+ * @throws {LockfileError} if the asset is not found or is not a direct install
123
+ */
124
+ export declare function pinAssetVersion(lockfile: Lockfile, name: string, version: string, type?: AssetType): Lockfile;
125
+ /**
126
+ * Read the lockfile from the project directory.
127
+ * Returns a default empty lockfile if none exists.
128
+ */
129
+ export declare function readLockfile(projectDir: string, tool: string): Promise<Lockfile>;
130
+ /**
131
+ * Release the advisory lock by removing the sentinel file.
132
+ * Silently ignores `ENOENT` (the sentinel was already removed).
133
+ */
134
+ export declare function releaseLockfileLock(projectDir: string): Promise<void>;
135
+ /**
136
+ * Remove an asset from the lockfile by name and optional type.
137
+ */
138
+ export declare function removeAssetFromLockfile(lockfile: Lockfile, name: string, type?: AssetType): Lockfile;
139
+ /**
140
+ * Trace the reverse dependency chain from a given asset upward to all
141
+ * direct-install roots.
142
+ *
143
+ * Returns a discriminated union indicating whether the asset is:
144
+ * - `direct`: explicitly installed by the user
145
+ * - `dependency`: pulled in as a dependency, with chain(s) to direct root(s)
146
+ * - `not_installed`: not found in the lockfile
147
+ * - `orphaned`: installed as a dependency but no path to a direct root exists
148
+ */
149
+ export declare function traceDependencyChain(lockfile: Lockfile, assetName: string, assetType?: AssetType): DependencyChainResult;
150
+ /**
151
+ * Remove the version pin from an installed asset.
152
+ *
153
+ * @throws {LockfileError} if the asset is not found
154
+ */
155
+ export declare function unpinAssetVersion(lockfile: Lockfile, name: string, type?: AssetType): Lockfile;
156
+ /**
157
+ * Upgrade an asset's installReason from 'dependency' to 'direct'.
158
+ * Used when a user explicitly installs something that was previously auto-installed.
159
+ */
160
+ export declare function upgradeToDirectInstall(lockfile: Lockfile, name: string, type?: AssetType): Lockfile;
161
+ /**
162
+ * Execute `fn` while holding the advisory lockfile lock.
163
+ * The lock is always released in a `finally` block, even if `fn` throws.
164
+ */
165
+ export declare function withLockfileLock<T>(projectDir: string, fn: () => Promise<T>): Promise<T>;
166
+ /**
167
+ * Write the lockfile to the project directory.
168
+ */
169
+ export declare function writeLockfile(projectDir: string, lockfile: Lockfile): Promise<void>;
170
+ //# sourceMappingURL=lockfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockfile.d.ts","sourceRoot":"","sources":["../../src/lib/lockfile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAkB,MAAM,uBAAuB,CAAC;AAe3F,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,+EAA+E;IAC/E,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,+DAA+D;IAC/D,aAAa,EAAE,YAAY,GAAG,QAAQ,CAAC;IACvC,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAk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