@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,356 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { toFlatFileName } from '../utils/nameTransform.mjs';
4
- import { resolveClaudeConfig, resolvePackagePath, parseGitHubRepo } from '../utils/package.mjs';
5
- import { DEFAULT_ASSET_TYPES } from './constants.mjs';
6
- import { fetchDirectoryContents } from './github.mjs';
7
-
8
- function readPackageJsonFromPath(packagePath) {
9
- try {
10
- const packageJsonPath = join(packagePath, 'package.json');
11
- if (!existsSync(packageJsonPath)) {
12
- return null;
13
- }
14
- const content = readFileSync(packageJsonPath, 'utf-8');
15
- const json = JSON.parse(content);
16
- return {
17
- name: json.name,
18
- version: json.version,
19
- repository: json.repository,
20
- claude: json.claude,
21
- };
22
- }
23
- catch {
24
- return null;
25
- }
26
- }
27
- async function scanPackageAssets(packageName, options) {
28
- const cwd = options.cwd ?? process.cwd();
29
- if (options.local) {
30
- return scanLocalAssets(packageName, cwd);
31
- }
32
- return scanRemoteAssets(packageName, cwd, options.ref);
33
- }
34
- async function scanLocalAssets(packageName, cwd) {
35
- const packagePath = findLocalPackage(packageName, cwd);
36
- if (!packagePath) {
37
- throw new Error(`Package ${packageName} not found in local workspace`);
38
- }
39
- const pkgInfo = readPackageJsonFromPath(packagePath);
40
- if (!pkgInfo) {
41
- throw new Error(`Package ${packageName} not found in local workspace`);
42
- }
43
- const claudeConfig = resolveClaudeConfig(pkgInfo.claude);
44
- const assetPath = join(packagePath, claudeConfig.assetPath);
45
- if (!existsSync(assetPath)) {
46
- throw new Error(`Asset path ${assetPath} does not exist`);
47
- }
48
- const trees = [];
49
- for (const assetType of DEFAULT_ASSET_TYPES) {
50
- const assetDir = join(assetPath, assetType);
51
- if (!existsSync(assetDir)) {
52
- continue;
53
- }
54
- const tree = buildTreeFromLocalDir(assetType, assetDir, assetType);
55
- if (tree.children && tree.children.length > 0) {
56
- trees.push(tree);
57
- }
58
- }
59
- return trees;
60
- }
61
- async function scanRemoteAssets(packageName, cwd, ref) {
62
- const nodeModulesPath = resolvePackagePath(packageName, cwd);
63
- if (!nodeModulesPath) {
64
- throw new Error(`Package ${packageName} not found`);
65
- }
66
- const pkgInfo = readPackageJsonFromPath(nodeModulesPath);
67
- if (!pkgInfo) {
68
- throw new Error(`Package ${packageName} not found`);
69
- }
70
- const claudeConfig = resolveClaudeConfig(pkgInfo.claude);
71
- const assetBasePath = claudeConfig.assetPath;
72
- if (!ref) {
73
- const localDocsPath = join(nodeModulesPath, assetBasePath);
74
- if (existsSync(localDocsPath)) {
75
- const trees = [];
76
- for (const assetType of DEFAULT_ASSET_TYPES) {
77
- const assetDir = join(localDocsPath, assetType);
78
- if (!existsSync(assetDir))
79
- continue;
80
- const tree = buildTreeFromLocalDir(assetType, assetDir, assetType);
81
- if (tree.children && tree.children.length > 0) {
82
- trees.push(tree);
83
- }
84
- }
85
- if (trees.length > 0)
86
- return trees;
87
- }
88
- }
89
- if (!pkgInfo.repository) {
90
- throw new Error(`Package ${packageName} has no repository field`);
91
- }
92
- const repoInfo = parseGitHubRepo(pkgInfo.repository);
93
- if (!repoInfo) {
94
- throw new Error(`Invalid GitHub repository URL in package ${packageName}`);
95
- }
96
- const tag = ref ?? 'HEAD';
97
- const trees = [];
98
- for (const assetType of DEFAULT_ASSET_TYPES) {
99
- const assetPath = repoInfo.directory
100
- ? `${repoInfo.directory}/${assetBasePath}/${assetType}`
101
- : `${assetBasePath}/${assetType}`;
102
- try {
103
- const entries = await fetchDirectoryContents(repoInfo, assetPath, tag);
104
- if (entries && entries.length > 0) {
105
- const dirContentsMap = new Map();
106
- for (const entry of entries) {
107
- if (entry.type === 'dir') {
108
- const dirEntries = await fetchDirectoryContents(repoInfo, `${assetPath}/${entry.name}`, tag);
109
- if (dirEntries) {
110
- dirContentsMap.set(entry.name, dirEntries);
111
- }
112
- }
113
- }
114
- const tree = buildTreeFromGitHubEntries(assetType, entries, assetType, dirContentsMap);
115
- if (tree.children && tree.children.length > 0) {
116
- trees.push(tree);
117
- }
118
- }
119
- }
120
- catch {
121
- continue;
122
- }
123
- }
124
- return trees;
125
- }
126
- function scanDirectoryRecursive(dirPath, prefix) {
127
- const results = [];
128
- try {
129
- const entries = readdirSync(dirPath);
130
- for (const entry of entries) {
131
- const fullPath = join(dirPath, entry);
132
- const relativePath = prefix ? `${prefix}/${entry}` : entry;
133
- const stat = statSync(fullPath);
134
- if (stat.isDirectory()) {
135
- results.push(...scanDirectoryRecursive(fullPath, relativePath));
136
- }
137
- else {
138
- results.push(relativePath);
139
- }
140
- }
141
- }
142
- catch {
143
- }
144
- return results;
145
- }
146
- function buildTreeFromLocalDir(label, dirPath, basePath) {
147
- const entries = readdirSync(dirPath);
148
- const children = [];
149
- for (const entry of entries) {
150
- const fullPath = join(dirPath, entry);
151
- const stat = statSync(fullPath);
152
- const relativePath = join(basePath, entry);
153
- if (stat.isDirectory()) {
154
- const isSkill = existsSync(join(fullPath, 'SKILL.md')) ||
155
- existsSync(join(fullPath, 'Skill.md'));
156
- if (isSkill) {
157
- const internalFiles = scanDirectoryRecursive(fullPath, '');
158
- const internalChildren = internalFiles.map((f) => ({
159
- id: `${relativePath}/${f}`,
160
- label: f,
161
- path: `${relativePath}/${f}`,
162
- type: 'file',
163
- selected: true,
164
- expanded: false,
165
- disabled: true,
166
- }));
167
- children.push({
168
- id: relativePath,
169
- label: entry,
170
- path: relativePath,
171
- type: 'skill-directory',
172
- children: internalChildren,
173
- viewOnly: true,
174
- selected: true,
175
- expanded: false,
176
- });
177
- }
178
- else {
179
- const subTree = buildTreeFromLocalDir(entry, fullPath, relativePath);
180
- if (subTree.children && subTree.children.length > 0) {
181
- children.push(subTree);
182
- }
183
- }
184
- }
185
- else {
186
- children.push({
187
- id: relativePath,
188
- label: entry,
189
- path: relativePath,
190
- type: 'file',
191
- selected: true,
192
- expanded: false,
193
- });
194
- }
195
- }
196
- return {
197
- id: basePath,
198
- label,
199
- path: basePath,
200
- type: 'directory',
201
- children,
202
- selected: true,
203
- expanded: true,
204
- };
205
- }
206
- function buildTreeFromGitHubEntries(label, entries, basePath, dirContentsMap) {
207
- const children = [];
208
- for (const entry of entries) {
209
- if (entry.type === 'file') {
210
- children.push({
211
- id: entry.path,
212
- label: entry.name,
213
- path: entry.path,
214
- type: 'file',
215
- selected: true,
216
- expanded: false,
217
- });
218
- }
219
- else if (entry.type === 'dir') {
220
- const dirEntries = dirContentsMap?.get(entry.name);
221
- const hasSkillMd = dirEntries ? isDirectorySkill(dirEntries) : false;
222
- if (hasSkillMd) {
223
- const skillPath = `${basePath}/${entry.name}`;
224
- const internalChildren = dirEntries
225
- ? dirEntries.map((de) => ({
226
- id: `${skillPath}/${de.name}`,
227
- label: de.name,
228
- path: `${skillPath}/${de.name}`,
229
- type: 'file',
230
- selected: true,
231
- expanded: false,
232
- disabled: true,
233
- }))
234
- : [];
235
- children.push({
236
- id: skillPath,
237
- label: entry.name,
238
- path: skillPath,
239
- type: 'skill-directory',
240
- children: internalChildren,
241
- viewOnly: true,
242
- selected: true,
243
- expanded: false,
244
- });
245
- }
246
- else if (dirEntries && dirEntries.length > 0) {
247
- const subTree = buildTreeFromGitHubEntries(entry.name, dirEntries, `${basePath}/${entry.name}`);
248
- if (subTree.children && subTree.children.length > 0) {
249
- children.push(subTree);
250
- }
251
- }
252
- }
253
- }
254
- return {
255
- id: basePath,
256
- label,
257
- path: basePath,
258
- type: 'directory',
259
- children,
260
- selected: true,
261
- expanded: true,
262
- };
263
- }
264
- function isDirectorySkill(entries) {
265
- return entries.some((entry) => entry.type === 'file' &&
266
- (entry.name === 'SKILL.md' || entry.name === 'Skill.md'));
267
- }
268
- function findLocalPackage(packageName, cwd) {
269
- const monorepoRoot = findMonorepoRoot(cwd);
270
- const searchRoot = monorepoRoot || cwd;
271
- const packagesDir = join(searchRoot, 'packages');
272
- if (existsSync(packagesDir)) {
273
- const found = searchPackagesRecursively(packagesDir, packageName);
274
- if (found)
275
- return found;
276
- }
277
- const nodeModulesPath = join(searchRoot, 'node_modules', packageName);
278
- if (existsSync(nodeModulesPath)) {
279
- return nodeModulesPath;
280
- }
281
- return null;
282
- }
283
- function findMonorepoRoot(startDir) {
284
- let currentDir = startDir;
285
- const root = '/';
286
- while (currentDir !== root) {
287
- const pkgJsonPath = join(currentDir, 'package.json');
288
- if (existsSync(pkgJsonPath)) {
289
- try {
290
- const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
291
- if (pkgJson.workspaces) {
292
- return currentDir;
293
- }
294
- }
295
- catch {
296
- }
297
- }
298
- currentDir = join(currentDir, '..');
299
- }
300
- return null;
301
- }
302
- function searchPackagesRecursively(dir, packageName) {
303
- try {
304
- const entries = readdirSync(dir);
305
- for (const entry of entries) {
306
- const fullPath = join(dir, entry);
307
- const stat = statSync(fullPath);
308
- if (stat.isDirectory()) {
309
- const pkgJsonPath = join(fullPath, 'package.json');
310
- if (existsSync(pkgJsonPath)) {
311
- const pkgInfo = readPackageJsonFromPath(fullPath);
312
- if (pkgInfo && pkgInfo.name === packageName) {
313
- return fullPath;
314
- }
315
- }
316
- const found = searchPackagesRecursively(fullPath, packageName);
317
- if (found)
318
- return found;
319
- }
320
- }
321
- }
322
- catch {
323
- }
324
- return null;
325
- }
326
- function buildSkillUnitsFromTree(tree, prefix) {
327
- if (!tree.children)
328
- return [];
329
- const units = [];
330
- for (const child of tree.children) {
331
- if (child.type === 'skill-directory') {
332
- const internalFiles = child.children
333
- ? child.children.map((c) => c.label)
334
- : [];
335
- units.push({
336
- name: child.label,
337
- isDirectory: true,
338
- transformed: toFlatFileName(prefix, child.label),
339
- internalFiles,
340
- });
341
- }
342
- else if (child.type === 'file') {
343
- units.push({
344
- name: child.label,
345
- isDirectory: false,
346
- transformed: toFlatFileName(prefix, child.label),
347
- });
348
- }
349
- else if (child.type === 'directory') {
350
- units.push(...buildSkillUnitsFromTree(child, prefix));
351
- }
352
- }
353
- return units;
354
- }
355
-
356
- export { buildSkillUnitsFromTree, isDirectorySkill, scanPackageAssets };