@slats/claude-assets-sync 0.1.4 → 0.3.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 (239) hide show
  1. package/README.md +89 -581
  2. package/bin/inject-claude-settings.mjs +4 -0
  3. package/dist/claude-hashes.json +20 -0
  4. package/dist/commands/index.d.ts +1 -112
  5. package/dist/commands/runCli/index.d.ts +2 -0
  6. package/dist/commands/runCli/runCli.cjs +53 -0
  7. package/dist/commands/runCli/runCli.d.ts +14 -0
  8. package/dist/commands/runCli/runCli.mjs +51 -0
  9. package/dist/commands/runCli/type.d.ts +19 -0
  10. package/dist/commands/runCli/utils/classifyTarget.cjs +48 -0
  11. package/dist/commands/runCli/utils/classifyTarget.d.ts +19 -0
  12. package/dist/commands/runCli/utils/classifyTarget.mjs +46 -0
  13. package/dist/commands/runCli/utils/injectOne.cjs +47 -0
  14. package/dist/commands/runCli/utils/injectOne.d.ts +3 -0
  15. package/dist/commands/runCli/utils/injectOne.mjs +45 -0
  16. package/dist/commands/runCli/utils/resolvePackage.cjs +77 -0
  17. package/dist/commands/runCli/utils/resolvePackage.d.ts +16 -0
  18. package/dist/commands/runCli/utils/resolvePackage.mjs +74 -0
  19. package/dist/commands/runCli/utils/resolveScopeAlias.cjs +69 -0
  20. package/dist/commands/runCli/utils/resolveScopeAlias.d.ts +2 -0
  21. package/dist/commands/runCli/utils/resolveScopeAlias.mjs +67 -0
  22. package/dist/commands/runCli/utils/resolveScopeFlag.cjs +28 -0
  23. package/dist/commands/runCli/utils/resolveScopeFlag.d.ts +2 -0
  24. package/dist/commands/runCli/utils/resolveScopeFlag.mjs +26 -0
  25. package/dist/commands/runCli/utils/resolveTargets.cjs +40 -0
  26. package/dist/commands/runCli/utils/resolveTargets.d.ts +15 -0
  27. package/dist/commands/runCli/utils/resolveTargets.mjs +38 -0
  28. package/dist/commands/runCli/utils/runInject.cjs +52 -0
  29. package/dist/commands/runCli/utils/runInject.d.ts +3 -0
  30. package/dist/commands/runCli/utils/runInject.mjs +50 -0
  31. package/dist/core/buildPlan/buildPlan.cjs +42 -0
  32. package/dist/core/buildPlan/buildPlan.d.ts +2 -0
  33. package/dist/core/buildPlan/buildPlan.mjs +40 -0
  34. package/dist/core/buildPlan/index.d.ts +2 -0
  35. package/dist/core/buildPlan/type.d.ts +32 -0
  36. package/dist/core/buildPlan/utils/toPosix.cjs +9 -0
  37. package/dist/core/buildPlan/utils/toPosix.d.ts +1 -0
  38. package/dist/core/buildPlan/utils/toPosix.mjs +7 -0
  39. package/dist/core/buildPlan/utils/walkFiles.cjs +25 -0
  40. package/dist/core/buildPlan/utils/walkFiles.d.ts +1 -0
  41. package/dist/core/buildPlan/utils/walkFiles.mjs +23 -0
  42. package/dist/core/hash/hash.cjs +30 -0
  43. package/dist/core/hash/hash.d.ts +4 -0
  44. package/dist/core/hash/hash.mjs +26 -0
  45. package/dist/core/hash/index.d.ts +1 -0
  46. package/dist/core/hashManifest/hashManifest.cjs +27 -0
  47. package/dist/core/hashManifest/hashManifest.d.ts +17 -0
  48. package/dist/core/hashManifest/hashManifest.mjs +23 -0
  49. package/dist/core/hashManifest/index.d.ts +1 -0
  50. package/dist/core/index.d.ts +5 -0
  51. package/dist/core/injectDocs/index.d.ts +2 -0
  52. package/dist/core/injectDocs/injectDocs.cjs +43 -0
  53. package/dist/core/injectDocs/injectDocs.d.ts +2 -0
  54. package/dist/core/injectDocs/injectDocs.mjs +41 -0
  55. package/dist/core/injectDocs/type.d.ts +30 -0
  56. package/dist/core/injectDocs/utils/applyAction.cjs +21 -0
  57. package/dist/core/injectDocs/utils/applyAction.d.ts +2 -0
  58. package/dist/core/injectDocs/utils/applyAction.mjs +19 -0
  59. package/dist/core/injectDocs/utils/emitCiForceList.cjs +10 -0
  60. package/dist/core/injectDocs/utils/emitCiForceList.d.ts +2 -0
  61. package/dist/core/injectDocs/utils/emitCiForceList.mjs +8 -0
  62. package/dist/core/injectDocs/utils/printPlan.cjs +20 -0
  63. package/dist/core/injectDocs/utils/printPlan.d.ts +2 -0
  64. package/dist/core/injectDocs/utils/printPlan.mjs +18 -0
  65. package/dist/core/injectDocs/utils/summarize.cjs +27 -0
  66. package/dist/core/injectDocs/utils/summarize.d.ts +3 -0
  67. package/dist/core/injectDocs/utils/summarize.mjs +25 -0
  68. package/dist/core/scope/index.d.ts +1 -0
  69. package/dist/core/scope/scope.cjs +46 -0
  70. package/dist/core/scope/scope.d.ts +16 -0
  71. package/dist/core/scope/scope.mjs +41 -0
  72. package/dist/core/scope/utils/isDirectory.cjs +14 -0
  73. package/dist/core/scope/utils/isDirectory.d.ts +1 -0
  74. package/dist/core/scope/utils/isDirectory.mjs +12 -0
  75. package/dist/index.cjs +15 -9
  76. package/dist/index.d.ts +3 -5
  77. package/dist/index.mjs +7 -3
  78. package/dist/prompts/confirmForce.cjs +27 -0
  79. package/dist/prompts/confirmForce.d.ts +1 -0
  80. package/dist/prompts/confirmForce.mjs +25 -0
  81. package/dist/prompts/index.d.ts +2 -0
  82. package/dist/prompts/selectScope.cjs +30 -0
  83. package/dist/prompts/selectScope.d.ts +2 -0
  84. package/dist/prompts/selectScope.mjs +28 -0
  85. package/dist/utils/heartbeat.cjs +25 -0
  86. package/dist/utils/heartbeat.d.ts +16 -0
  87. package/dist/utils/heartbeat.mjs +23 -0
  88. package/dist/utils/logger.cjs +7 -0
  89. package/dist/utils/logger.d.ts +8 -0
  90. package/dist/utils/logger.mjs +7 -0
  91. package/dist/utils/types.d.ts +1 -252
  92. package/dist/utils/version.cjs +2 -14
  93. package/dist/utils/version.d.ts +3 -53
  94. package/dist/utils/version.mjs +2 -13
  95. package/docs/bundle-size-decision.md +36 -0
  96. package/docs/claude/skills/claude-docs-asset-wiring/SKILL.md +159 -0
  97. package/docs/claude/skills/claude-docs-asset-wiring/knowledge/claude-md-template.md +86 -0
  98. package/docs/claude/skills/claude-docs-asset-wiring/knowledge/dependency-cruiser.md +54 -0
  99. package/docs/claude/skills/claude-docs-asset-wiring/knowledge/gotchas.md +122 -0
  100. package/docs/claude/skills/claude-docs-asset-wiring/knowledge/package-json-patches.md +145 -0
  101. package/docs/claude/skills/claude-docs-asset-wiring/knowledge/reference-files.md +37 -0
  102. package/docs/claude/skills/claude-docs-asset-wiring/knowledge/smoke-tests.md +111 -0
  103. package/docs/consumer-integration.md +94 -0
  104. package/package.json +24 -16
  105. package/scripts/build-hashes.mjs +30 -0
  106. package/scripts/buildHashes.d.mts +15 -0
  107. package/scripts/buildHashes.mjs +82 -0
  108. package/scripts/claude-build-hashes.mjs +42 -0
  109. package/scripts/inject-version.js +112 -0
  110. package/dist/cli.cjs +0 -8
  111. package/dist/cli.d.ts +0 -1
  112. package/dist/cli.mjs +0 -7
  113. package/dist/commands/add.cjs +0 -80
  114. package/dist/commands/add.d.ts +0 -8
  115. package/dist/commands/add.mjs +0 -78
  116. package/dist/commands/list.cjs +0 -94
  117. package/dist/commands/list.d.ts +0 -15
  118. package/dist/commands/list.mjs +0 -91
  119. package/dist/commands/migrate.cjs +0 -9
  120. package/dist/commands/migrate.d.ts +0 -6
  121. package/dist/commands/migrate.mjs +0 -7
  122. package/dist/commands/remove.cjs +0 -127
  123. package/dist/commands/remove.d.ts +0 -6
  124. package/dist/commands/remove.mjs +0 -105
  125. package/dist/commands/status.cjs +0 -193
  126. package/dist/commands/status.d.ts +0 -6
  127. package/dist/commands/status.mjs +0 -171
  128. package/dist/commands/sync.cjs +0 -28
  129. package/dist/commands/sync.d.ts +0 -6
  130. package/dist/commands/sync.mjs +0 -26
  131. package/dist/commands/types.d.ts +0 -89
  132. package/dist/commands/update.cjs +0 -209
  133. package/dist/commands/update.d.ts +0 -29
  134. package/dist/commands/update.mjs +0 -206
  135. package/dist/components/add/AddCommand.cjs +0 -103
  136. package/dist/components/add/AddCommand.d.ts +0 -14
  137. package/dist/components/add/AddCommand.mjs +0 -101
  138. package/dist/components/add/BulkAddView.cjs +0 -165
  139. package/dist/components/add/BulkAddView.d.ts +0 -11
  140. package/dist/components/add/BulkAddView.mjs +0 -163
  141. package/dist/components/add/index.d.ts +0 -2
  142. package/dist/components/index.d.ts +0 -2
  143. package/dist/components/list/EditableTreeItem.d.ts +0 -13
  144. package/dist/components/list/ListCommand.cjs +0 -651
  145. package/dist/components/list/ListCommand.d.ts +0 -5
  146. package/dist/components/list/ListCommand.mjs +0 -649
  147. package/dist/components/list/SyncedPackageTree.d.ts +0 -14
  148. package/dist/components/list/index.d.ts +0 -10
  149. package/dist/components/list/types.d.ts +0 -14
  150. package/dist/components/primitives/Box.d.ts +0 -4
  151. package/dist/components/primitives/Spinner.d.ts +0 -6
  152. package/dist/components/primitives/Text.d.ts +0 -4
  153. package/dist/components/primitives/index.d.ts +0 -3
  154. package/dist/components/remove/RemoveConfirm.cjs +0 -18
  155. package/dist/components/remove/RemoveConfirm.d.ts +0 -11
  156. package/dist/components/remove/RemoveConfirm.mjs +0 -16
  157. package/dist/components/shared/Confirm.cjs +0 -30
  158. package/dist/components/shared/Confirm.d.ts +0 -8
  159. package/dist/components/shared/Confirm.mjs +0 -28
  160. package/dist/components/shared/MenuItem.cjs +0 -18
  161. package/dist/components/shared/MenuItem.d.ts +0 -7
  162. package/dist/components/shared/MenuItem.mjs +0 -16
  163. package/dist/components/shared/ProgressBar.d.ts +0 -7
  164. package/dist/components/shared/StepRunner.cjs +0 -58
  165. package/dist/components/shared/StepRunner.d.ts +0 -15
  166. package/dist/components/shared/StepRunner.mjs +0 -56
  167. package/dist/components/shared/Table.cjs +0 -19
  168. package/dist/components/shared/Table.d.ts +0 -8
  169. package/dist/components/shared/Table.mjs +0 -17
  170. package/dist/components/shared/index.d.ts +0 -6
  171. package/dist/components/status/PackageStatusCard.d.ts +0 -10
  172. package/dist/components/status/StatusDisplay.cjs +0 -26
  173. package/dist/components/status/StatusDisplay.d.ts +0 -23
  174. package/dist/components/status/StatusDisplay.mjs +0 -24
  175. package/dist/components/status/StatusTreeNode.cjs +0 -40
  176. package/dist/components/status/StatusTreeNode.d.ts +0 -15
  177. package/dist/components/status/StatusTreeNode.mjs +0 -38
  178. package/dist/components/status/index.d.ts +0 -6
  179. package/dist/components/tree/AssetTreeNode.cjs +0 -54
  180. package/dist/components/tree/AssetTreeNode.d.ts +0 -12
  181. package/dist/components/tree/AssetTreeNode.mjs +0 -52
  182. package/dist/components/tree/TreeSelect.cjs +0 -129
  183. package/dist/components/tree/TreeSelect.d.ts +0 -12
  184. package/dist/components/tree/TreeSelect.mjs +0 -127
  185. package/dist/components/tree/index.d.ts +0 -4
  186. package/dist/core/assetStructure.cjs +0 -30
  187. package/dist/core/assetStructure.d.ts +0 -36
  188. package/dist/core/assetStructure.mjs +0 -27
  189. package/dist/core/cli.cjs +0 -106
  190. package/dist/core/cli.d.ts +0 -9
  191. package/dist/core/cli.mjs +0 -103
  192. package/dist/core/constants.cjs +0 -28
  193. package/dist/core/constants.d.ts +0 -94
  194. package/dist/core/constants.mjs +0 -21
  195. package/dist/core/filesystem.cjs +0 -98
  196. package/dist/core/filesystem.d.ts +0 -94
  197. package/dist/core/filesystem.mjs +0 -88
  198. package/dist/core/github.cjs +0 -115
  199. package/dist/core/github.d.ts +0 -61
  200. package/dist/core/github.mjs +0 -107
  201. package/dist/core/io.cjs +0 -46
  202. package/dist/core/io.d.ts +0 -40
  203. package/dist/core/io.mjs +0 -39
  204. package/dist/core/listOperations.cjs +0 -228
  205. package/dist/core/listOperations.d.ts +0 -43
  206. package/dist/core/listOperations.mjs +0 -205
  207. package/dist/core/localSource.cjs +0 -126
  208. package/dist/core/localSource.d.ts +0 -33
  209. package/dist/core/localSource.mjs +0 -120
  210. package/dist/core/migration.cjs +0 -201
  211. package/dist/core/migration.d.ts +0 -57
  212. package/dist/core/migration.mjs +0 -198
  213. package/dist/core/packageScanner.cjs +0 -360
  214. package/dist/core/packageScanner.d.ts +0 -22
  215. package/dist/core/packageScanner.mjs +0 -356
  216. package/dist/core/sync.cjs +0 -400
  217. package/dist/core/sync.d.ts +0 -21
  218. package/dist/core/sync.mjs +0 -397
  219. package/dist/core/syncMeta.cjs +0 -242
  220. package/dist/core/syncMeta.d.ts +0 -75
  221. package/dist/core/syncMeta.mjs +0 -229
  222. package/dist/utils/dependencies.cjs +0 -57
  223. package/dist/utils/dependencies.d.ts +0 -10
  224. package/dist/utils/dependencies.mjs +0 -34
  225. package/dist/utils/nameTransform.cjs +0 -13
  226. package/dist/utils/nameTransform.d.ts +0 -65
  227. package/dist/utils/nameTransform.mjs +0 -11
  228. package/dist/utils/package.cjs +0 -170
  229. package/dist/utils/package.d.ts +0 -105
  230. package/dist/utils/package.mjs +0 -157
  231. package/dist/utils/packageName.cjs +0 -24
  232. package/dist/utils/packageName.d.ts +0 -32
  233. package/dist/utils/packageName.mjs +0 -21
  234. package/dist/utils/paths.cjs +0 -18
  235. package/dist/utils/paths.d.ts +0 -55
  236. package/dist/utils/paths.mjs +0 -15
  237. package/dist/version.cjs +0 -5
  238. package/dist/version.d.ts +0 -5
  239. package/dist/version.mjs +0 -3
@@ -1,107 +0,0 @@
1
- class RateLimitError extends Error {
2
- constructor() {
3
- super('GitHub API rate limit exceeded. Set GITHUB_TOKEN environment variable to increase the limit.');
4
- this.name = 'RateLimitError';
5
- }
6
- }
7
- class NotFoundError extends Error {
8
- constructor(resource) {
9
- super(`GitHub resource not found: ${resource}`);
10
- this.name = 'NotFoundError';
11
- }
12
- }
13
- const getHeaders = () => {
14
- const headers = {
15
- Accept: 'application/vnd.github.v3+json',
16
- 'User-Agent': 'claude-assets-sync',
17
- };
18
- const token = process.env.GITHUB_TOKEN;
19
- if (token)
20
- headers.Authorization = `Bearer ${token}`;
21
- return headers;
22
- };
23
- const fetchDirectoryContents = async (repoInfo, path, tag) => {
24
- const url = `https://api.github.com/repos/${repoInfo.owner}/${repoInfo.repo}/contents/${path}?ref=${encodeURIComponent(tag)}`;
25
- const response = await fetch(url, {
26
- headers: getHeaders(),
27
- });
28
- if (response.status === 403) {
29
- const remaining = response.headers.get('x-ratelimit-remaining');
30
- if (remaining === '0')
31
- throw new RateLimitError();
32
- }
33
- if (response.status === 404)
34
- return null;
35
- if (!response.ok)
36
- throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
37
- const data = await response.json();
38
- return data.filter((entry) => (entry.type === 'file' && entry.name.endsWith('.md')) ||
39
- entry.type === 'dir');
40
- };
41
- const expandDirectoryEntries = async (repoInfo, parentPath, entries, tag, prefix = '') => {
42
- const result = [];
43
- for (const entry of entries) {
44
- const entryPrefix = prefix ? `${prefix}/${entry.name}` : entry.name;
45
- if (entry.type === 'file') {
46
- result.push({
47
- ...entry,
48
- name: prefix ? entryPrefix : entry.name,
49
- });
50
- }
51
- else if (entry.type === 'dir') {
52
- const subEntries = await fetchDirectoryContents(repoInfo, `${parentPath}/${entry.name}`, tag);
53
- if (subEntries) {
54
- const expanded = await expandDirectoryEntries(repoInfo, `${parentPath}/${entry.name}`, subEntries, tag, entryPrefix);
55
- result.push(...expanded);
56
- }
57
- }
58
- }
59
- return result;
60
- };
61
- const fetchAssetFiles = async (repoInfo, assetPath, tag, assetTypes) => {
62
- const basePath = repoInfo.directory
63
- ? `${repoInfo.directory}/${assetPath}`
64
- : assetPath;
65
- const fetchPromises = assetTypes.map((assetType) => fetchDirectoryContents(repoInfo, `${basePath}/${assetType}`, tag));
66
- const rawResults = await Promise.all(fetchPromises);
67
- const expandedResults = await Promise.all(rawResults.map((entries, index) => {
68
- if (!entries)
69
- return Promise.resolve([]);
70
- const assetDirPath = `${basePath}/${assetTypes[index]}`;
71
- return expandDirectoryEntries(repoInfo, assetDirPath, entries, tag);
72
- }));
73
- const assetFiles = {};
74
- assetTypes.forEach((assetType, index) => {
75
- assetFiles[assetType] = expandedResults[index] || [];
76
- });
77
- return assetFiles;
78
- };
79
- const downloadFile = async (repoInfo, filePath, tag) => {
80
- const url = `https://raw.githubusercontent.com/${repoInfo.owner}/${repoInfo.repo}/${encodeURIComponent(tag)}/${filePath}`;
81
- const response = await fetch(url, {
82
- headers: {
83
- 'User-Agent': 'claude-assets-sync',
84
- },
85
- });
86
- if (response.status === 404) {
87
- throw new NotFoundError(filePath);
88
- }
89
- if (!response.ok) {
90
- throw new Error(`Failed to download file: ${response.status} ${response.statusText}`);
91
- }
92
- return response.text();
93
- };
94
- const downloadAssetFiles = async (repoInfo, assetPath, assetType, entries, tag) => {
95
- const basePath = repoInfo.directory
96
- ? `${repoInfo.directory}/${assetPath}/${assetType}`
97
- : `${assetPath}/${assetType}`;
98
- const results = new Map();
99
- for (const entry of entries) {
100
- const filePath = `${basePath}/${entry.name}`;
101
- const content = await downloadFile(repoInfo, filePath, tag);
102
- results.set(entry.name, content);
103
- }
104
- return results;
105
- };
106
-
107
- export { NotFoundError, RateLimitError, downloadAssetFiles, downloadFile, expandDirectoryEntries, fetchAssetFiles, fetchDirectoryContents };
package/dist/core/io.cjs DELETED
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('node:fs');
4
- var path = require('node:path');
5
-
6
- function readJsonFile(path) {
7
- if (!fs.existsSync(path)) {
8
- return null;
9
- }
10
- try {
11
- const content = fs.readFileSync(path, 'utf-8');
12
- return JSON.parse(content);
13
- }
14
- catch {
15
- return null;
16
- }
17
- }
18
- function writeJsonFile(path$1, data) {
19
- ensureDirectory(path.dirname(path$1));
20
- fs.writeFileSync(path$1, JSON.stringify(data, null, 2), 'utf-8');
21
- }
22
- function ensureDirectory(path) {
23
- if (!fs.existsSync(path)) {
24
- fs.mkdirSync(path, { recursive: true });
25
- }
26
- }
27
- function fileExists(path) {
28
- return fs.existsSync(path);
29
- }
30
- function listDirectory(path) {
31
- if (!fs.existsSync(path)) {
32
- return [];
33
- }
34
- return fs.readdirSync(path);
35
- }
36
- function writeTextFile(path$1, content) {
37
- ensureDirectory(path.dirname(path$1));
38
- fs.writeFileSync(path$1, content, 'utf-8');
39
- }
40
-
41
- exports.ensureDirectory = ensureDirectory;
42
- exports.fileExists = fileExists;
43
- exports.listDirectory = listDirectory;
44
- exports.readJsonFile = readJsonFile;
45
- exports.writeJsonFile = writeJsonFile;
46
- exports.writeTextFile = writeTextFile;
package/dist/core/io.d.ts DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- * Read and parse JSON file
3
- * @param path - File path
4
- * @returns Parsed JSON or null if file doesn't exist or parsing fails
5
- */
6
- export declare function readJsonFile<T>(path: string): T | null;
7
- /**
8
- * Write JSON file with pretty formatting
9
- * @param path - File path
10
- * @param data - Data to serialize
11
- */
12
- export declare function writeJsonFile<T>(path: string, data: T): void;
13
- /**
14
- * Ensure directory exists (creates recursively if needed)
15
- * @param path - Directory path
16
- */
17
- export declare function ensureDirectory(path: string): void;
18
- /**
19
- * Check if file or directory exists
20
- * @param path - File or directory path
21
- * @returns true if exists
22
- */
23
- export declare function fileExists(path: string): boolean;
24
- /**
25
- * Remove directory recursively
26
- * @param path - Directory path
27
- */
28
- export declare function removeDirectory(path: string): void;
29
- /**
30
- * List files in directory
31
- * @param path - Directory path
32
- * @returns Array of file names
33
- */
34
- export declare function listDirectory(path: string): string[];
35
- /**
36
- * Write text file with directory creation
37
- * @param path - File path
38
- * @param content - File content
39
- */
40
- export declare function writeTextFile(path: string, content: string): void;
package/dist/core/io.mjs DELETED
@@ -1,39 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync, readdirSync, mkdirSync } from 'node:fs';
2
- import { dirname } from 'node:path';
3
-
4
- function readJsonFile(path) {
5
- if (!existsSync(path)) {
6
- return null;
7
- }
8
- try {
9
- const content = readFileSync(path, 'utf-8');
10
- return JSON.parse(content);
11
- }
12
- catch {
13
- return null;
14
- }
15
- }
16
- function writeJsonFile(path, data) {
17
- ensureDirectory(dirname(path));
18
- writeFileSync(path, JSON.stringify(data, null, 2), 'utf-8');
19
- }
20
- function ensureDirectory(path) {
21
- if (!existsSync(path)) {
22
- mkdirSync(path, { recursive: true });
23
- }
24
- }
25
- function fileExists(path) {
26
- return existsSync(path);
27
- }
28
- function listDirectory(path) {
29
- if (!existsSync(path)) {
30
- return [];
31
- }
32
- return readdirSync(path);
33
- }
34
- function writeTextFile(path, content) {
35
- ensureDirectory(dirname(path));
36
- writeFileSync(path, content, 'utf-8');
37
- }
38
-
39
- export { ensureDirectory, fileExists, listDirectory, readJsonFile, writeJsonFile, writeTextFile };
@@ -1,228 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('node:fs');
4
- var path = require('node:path');
5
- var sync = require('./sync.cjs');
6
- var syncMeta = require('./syncMeta.cjs');
7
-
8
- function _interopNamespaceDefault(e) {
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n.default = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
26
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
27
-
28
- function computeFileOperations(meta, packageFiles, selectedTrees, cwd) {
29
- const newPackageFiles = { ...packageFiles };
30
- for (const packageTree of selectedTrees) {
31
- const prefix = packageTree.id;
32
- if (!newPackageFiles[prefix])
33
- continue;
34
- const selectedPaths = new Set();
35
- if (packageTree.children) {
36
- for (const assetTypeNode of packageTree.children) {
37
- if (assetTypeNode.children) {
38
- for (const fileNode of assetTypeNode.children) {
39
- if (fileNode.disabled)
40
- continue;
41
- if (fileNode.selected) {
42
- selectedPaths.add(fileNode.path);
43
- }
44
- }
45
- }
46
- }
47
- }
48
- newPackageFiles[prefix] = {
49
- ...newPackageFiles[prefix],
50
- selected: selectedPaths,
51
- };
52
- }
53
- const fileOperations = [];
54
- const filesToDelete = [];
55
- const packagesToSync = [];
56
- for (const [prefix] of Object.entries(meta.packages)) {
57
- const packageTree = selectedTrees.find((t) => t.id === prefix);
58
- const packageInfo = meta.packages[prefix];
59
- const packageData = newPackageFiles[prefix];
60
- if (!packageTree || !packageTree.selected || !packageData) {
61
- for (const [assetType, files] of Object.entries(packageInfo.files)) {
62
- if (!Array.isArray(files))
63
- continue;
64
- const units = files;
65
- for (const unit of units) {
66
- fileOperations.push({
67
- type: 'remove',
68
- prefix,
69
- assetType,
70
- skillName: unit.name,
71
- });
72
- }
73
- const firstUnit = units[0];
74
- if (firstUnit?.transformed) {
75
- for (const unit of units) {
76
- const targetPath = path__namespace.join(cwd, '.claude', assetType, unit.transformed);
77
- filesToDelete.push(targetPath);
78
- }
79
- }
80
- else {
81
- const dirPath = path__namespace.join(cwd, '.claude', assetType, packageInfo.originalName);
82
- filesToDelete.push(dirPath);
83
- }
84
- }
85
- continue;
86
- }
87
- let hasChanges = false;
88
- const selectedByAssetType = {};
89
- for (const filePath of packageData.selected) {
90
- const [assetType, fileName] = filePath.split('/');
91
- if (!selectedByAssetType[assetType]) {
92
- selectedByAssetType[assetType] = new Set();
93
- }
94
- selectedByAssetType[assetType].add(fileName);
95
- }
96
- for (const [assetType, originalFiles] of Object.entries(packageInfo.files)) {
97
- const selectedFiles = selectedByAssetType[assetType];
98
- const units = Array.isArray(originalFiles)
99
- ? originalFiles
100
- : [];
101
- const firstUnit = units[0];
102
- const isFlat = !!firstUnit?.transformed;
103
- if (!selectedFiles || selectedFiles.size === 0) {
104
- hasChanges = true;
105
- for (const unit of units) {
106
- fileOperations.push({
107
- type: 'remove',
108
- prefix,
109
- assetType,
110
- skillName: unit.name,
111
- });
112
- }
113
- if (isFlat) {
114
- for (const unit of units) {
115
- const targetPath = path__namespace.join(cwd, '.claude', assetType, unit.transformed);
116
- filesToDelete.push(targetPath);
117
- }
118
- }
119
- else {
120
- const dirPath = path__namespace.join(cwd, '.claude', assetType, packageInfo.originalName);
121
- filesToDelete.push(dirPath);
122
- }
123
- continue;
124
- }
125
- const originalNames = new Set(units.map((u) => u.name));
126
- for (const unit of units) {
127
- if (!selectedFiles.has(unit.name)) {
128
- hasChanges = true;
129
- fileOperations.push({
130
- type: 'remove',
131
- prefix,
132
- assetType,
133
- skillName: unit.name,
134
- });
135
- if (unit.transformed) {
136
- const targetPath = path__namespace.join(cwd, '.claude', assetType, unit.transformed);
137
- filesToDelete.push(targetPath);
138
- }
139
- else {
140
- const filePath = path__namespace.join(cwd, '.claude', assetType, packageInfo.originalName, unit.name);
141
- filesToDelete.push(filePath);
142
- }
143
- }
144
- }
145
- for (const skillName of selectedFiles) {
146
- if (!originalNames.has(skillName)) {
147
- hasChanges = true;
148
- fileOperations.push({
149
- type: 'add',
150
- prefix,
151
- assetType,
152
- skillName,
153
- });
154
- }
155
- }
156
- }
157
- if (hasChanges) {
158
- packagesToSync.push({
159
- prefix,
160
- name: packageInfo.originalName,
161
- local: packageInfo.local,
162
- });
163
- }
164
- }
165
- return { filesToDelete, fileOperations, packagesToSync };
166
- }
167
- async function applyChangesAndSync(changesSummary, meta, cwd, callbacks) {
168
- const syncErrors = [];
169
- for (const filePath of changesSummary.filesToDelete) {
170
- try {
171
- const stat = fs__namespace.statSync(filePath);
172
- if (stat.isDirectory()) {
173
- fs__namespace.rmSync(filePath, { recursive: true, force: true });
174
- }
175
- else {
176
- fs__namespace.unlinkSync(filePath);
177
- }
178
- }
179
- catch (error) {
180
- if (error.code !== 'ENOENT') {
181
- console.error(`Failed to remove ${filePath}: ${error}`);
182
- }
183
- }
184
- }
185
- let updatedMeta = { ...meta };
186
- const hasAddOperations = changesSummary.fileOperations.some((op) => op.type === 'add');
187
- for (const op of changesSummary.fileOperations) {
188
- if (op.type === 'remove') {
189
- updatedMeta = syncMeta.removeSkillUnitFromPackage(updatedMeta, op.prefix, op.assetType, op.skillName);
190
- }
191
- }
192
- for (const prefix of Object.keys(updatedMeta.packages)) {
193
- const pkg = updatedMeta.packages[prefix];
194
- if (!pkg.files || Object.keys(pkg.files).length === 0) {
195
- updatedMeta = syncMeta.removePackageFromMeta(updatedMeta, prefix);
196
- }
197
- }
198
- syncMeta.writeUnifiedSyncMeta(cwd, updatedMeta);
199
- if (hasAddOperations && changesSummary.packagesToSync.length > 0) {
200
- callbacks?.onSyncStart?.();
201
- for (const { prefix, name, local } of changesSummary.packagesToSync) {
202
- try {
203
- const removedFiles = changesSummary.fileOperations
204
- .filter((op) => op.type === 'remove' && op.prefix === prefix)
205
- .map((op) => `${op.assetType}/${op.skillName}`);
206
- const exclusions = removedFiles.length > 0
207
- ? { directories: [], files: removedFiles }
208
- : undefined;
209
- await sync.syncPackage(name, {
210
- force: true,
211
- dryRun: false,
212
- local: local ?? false,
213
- ref: undefined,
214
- flat: undefined,
215
- }, cwd, exclusions);
216
- }
217
- catch (error) {
218
- const msg = `Failed to sync ${name}: ${error}`;
219
- console.error(msg);
220
- syncErrors.push(msg);
221
- }
222
- }
223
- }
224
- return { updatedMeta, syncErrors };
225
- }
226
-
227
- exports.applyChangesAndSync = applyChangesAndSync;
228
- exports.computeFileOperations = computeFileOperations;
@@ -1,43 +0,0 @@
1
- import type { TreeNode, UnifiedSyncMeta } from '../utils/types.js';
2
- export type FileOperation = {
3
- type: 'add';
4
- prefix: string;
5
- assetType: string;
6
- skillName: string;
7
- } | {
8
- type: 'remove';
9
- prefix: string;
10
- assetType: string;
11
- skillName: string;
12
- };
13
- export interface ChangesSummary {
14
- filesToDelete: string[];
15
- fileOperations: FileOperation[];
16
- packagesToSync: Array<{
17
- prefix: string;
18
- name: string;
19
- local?: boolean;
20
- }>;
21
- }
22
- export interface PackageFiles {
23
- [prefix: string]: {
24
- available: TreeNode[];
25
- selected: Set<string>;
26
- };
27
- }
28
- /**
29
- * Pure computation: given current meta, packageFiles, and selected trees,
30
- * compute what file operations need to happen.
31
- * No React state, no side effects.
32
- */
33
- export declare function computeFileOperations(meta: UnifiedSyncMeta, packageFiles: PackageFiles, selectedTrees: TreeNode[], cwd: string): ChangesSummary;
34
- /**
35
- * Apply file changes and sync packages.
36
- * Has side effects (filesystem writes, sync calls) but NO React/ink dependencies.
37
- */
38
- export declare function applyChangesAndSync(changesSummary: ChangesSummary, meta: UnifiedSyncMeta, cwd: string, callbacks?: {
39
- onSyncStart?: () => void;
40
- }): Promise<{
41
- updatedMeta: UnifiedSyncMeta;
42
- syncErrors: string[];
43
- }>;