@slats/claude-assets-sync 0.1.4 → 0.2.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.
- package/README.md +111 -587
- package/bin/claude-sync.mjs +24 -0
- package/dist/claude-hashes.json +20 -0
- package/dist/commands/index.d.ts +1 -112
- package/dist/commands/runCli/index.d.ts +2 -0
- package/dist/commands/runCli/runCli.cjs +31 -0
- package/dist/commands/runCli/runCli.d.ts +10 -0
- package/dist/commands/runCli/runCli.mjs +29 -0
- package/dist/commands/runCli/type.d.ts +28 -0
- package/dist/commands/runCli/utils/injectOne.cjs +48 -0
- package/dist/commands/runCli/utils/injectOne.d.ts +3 -0
- package/dist/commands/runCli/utils/injectOne.mjs +46 -0
- package/dist/commands/runCli/utils/resolveScopeFlag.cjs +28 -0
- package/dist/commands/runCli/utils/resolveScopeFlag.d.ts +2 -0
- package/dist/commands/runCli/utils/resolveScopeFlag.mjs +26 -0
- package/dist/commands/runCli/utils/runInject.cjs +36 -0
- package/dist/commands/runCli/utils/runInject.d.ts +2 -0
- package/dist/commands/runCli/utils/runInject.mjs +34 -0
- package/dist/core/buildPlan/buildPlan.cjs +42 -0
- package/dist/core/buildPlan/buildPlan.d.ts +2 -0
- package/dist/core/buildPlan/buildPlan.mjs +40 -0
- package/dist/core/buildPlan/index.d.ts +2 -0
- package/dist/core/buildPlan/type.d.ts +32 -0
- package/dist/core/buildPlan/utils/toPosix.cjs +9 -0
- package/dist/core/buildPlan/utils/toPosix.d.ts +1 -0
- package/dist/core/buildPlan/utils/toPosix.mjs +7 -0
- package/dist/core/buildPlan/utils/walkFiles.cjs +25 -0
- package/dist/core/buildPlan/utils/walkFiles.d.ts +1 -0
- package/dist/core/buildPlan/utils/walkFiles.mjs +23 -0
- package/dist/core/hash/hash.cjs +30 -0
- package/dist/core/hash/hash.d.ts +4 -0
- package/dist/core/hash/hash.mjs +26 -0
- package/dist/core/hash/index.d.ts +1 -0
- package/dist/core/hashManifest/hashManifest.cjs +27 -0
- package/dist/core/hashManifest/hashManifest.d.ts +17 -0
- package/dist/core/hashManifest/hashManifest.mjs +23 -0
- package/dist/core/hashManifest/index.d.ts +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/injectDocs/index.d.ts +2 -0
- package/dist/core/injectDocs/injectDocs.cjs +43 -0
- package/dist/core/injectDocs/injectDocs.d.ts +2 -0
- package/dist/core/injectDocs/injectDocs.mjs +41 -0
- package/dist/core/injectDocs/type.d.ts +30 -0
- package/dist/core/injectDocs/utils/applyAction.cjs +21 -0
- package/dist/core/injectDocs/utils/applyAction.d.ts +2 -0
- package/dist/core/injectDocs/utils/applyAction.mjs +19 -0
- package/dist/core/injectDocs/utils/emitCiForceList.cjs +10 -0
- package/dist/core/injectDocs/utils/emitCiForceList.d.ts +2 -0
- package/dist/core/injectDocs/utils/emitCiForceList.mjs +8 -0
- package/dist/core/injectDocs/utils/printPlan.cjs +20 -0
- package/dist/core/injectDocs/utils/printPlan.d.ts +2 -0
- package/dist/core/injectDocs/utils/printPlan.mjs +18 -0
- package/dist/core/injectDocs/utils/summarize.cjs +27 -0
- package/dist/core/injectDocs/utils/summarize.d.ts +3 -0
- package/dist/core/injectDocs/utils/summarize.mjs +25 -0
- package/dist/core/scope/index.d.ts +1 -0
- package/dist/core/scope/scope.cjs +46 -0
- package/dist/core/scope/scope.d.ts +16 -0
- package/dist/core/scope/scope.mjs +41 -0
- package/dist/core/scope/utils/isDirectory.cjs +14 -0
- package/dist/core/scope/utils/isDirectory.d.ts +1 -0
- package/dist/core/scope/utils/isDirectory.mjs +12 -0
- package/dist/index.cjs +15 -9
- package/dist/index.d.ts +3 -5
- package/dist/index.mjs +7 -3
- package/dist/prompts/confirmForce.cjs +27 -0
- package/dist/prompts/confirmForce.d.ts +1 -0
- package/dist/prompts/confirmForce.mjs +25 -0
- package/dist/prompts/index.d.ts +2 -0
- package/dist/prompts/selectScope.cjs +30 -0
- package/dist/prompts/selectScope.d.ts +2 -0
- package/dist/prompts/selectScope.mjs +28 -0
- package/dist/utils/heartbeat.cjs +25 -0
- package/dist/utils/heartbeat.d.ts +16 -0
- package/dist/utils/heartbeat.mjs +23 -0
- package/dist/utils/logger.cjs +7 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.mjs +7 -0
- package/dist/utils/types.d.ts +1 -252
- package/dist/utils/version.cjs +2 -14
- package/dist/utils/version.d.ts +3 -53
- package/dist/utils/version.mjs +2 -13
- package/docs/bundle-size-decision.md +36 -0
- package/docs/claude/skills/claude-sync-applier/SKILL.md +195 -0
- package/docs/claude/skills/claude-sync-applier/knowledge/claude-md-template.md +77 -0
- package/docs/claude/skills/claude-sync-applier/knowledge/dependency-cruiser.md +126 -0
- package/docs/claude/skills/claude-sync-applier/knowledge/gotchas.md +139 -0
- package/docs/claude/skills/claude-sync-applier/knowledge/package-json-patches.md +130 -0
- package/docs/claude/skills/claude-sync-applier/knowledge/reference-files.md +120 -0
- package/docs/claude/skills/claude-sync-applier/knowledge/smoke-tests.md +102 -0
- package/docs/consumer-integration.md +153 -0
- package/package.json +24 -16
- package/scripts/build-hashes.mjs +30 -0
- package/scripts/buildHashes.d.mts +15 -0
- package/scripts/buildHashes.mjs +82 -0
- package/scripts/claude-build-hashes.mjs +42 -0
- package/scripts/inject-version.js +112 -0
- package/dist/cli.cjs +0 -8
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +0 -7
- package/dist/commands/add.cjs +0 -80
- package/dist/commands/add.d.ts +0 -8
- package/dist/commands/add.mjs +0 -78
- package/dist/commands/list.cjs +0 -94
- package/dist/commands/list.d.ts +0 -15
- package/dist/commands/list.mjs +0 -91
- package/dist/commands/migrate.cjs +0 -9
- package/dist/commands/migrate.d.ts +0 -6
- package/dist/commands/migrate.mjs +0 -7
- package/dist/commands/remove.cjs +0 -127
- package/dist/commands/remove.d.ts +0 -6
- package/dist/commands/remove.mjs +0 -105
- package/dist/commands/status.cjs +0 -193
- package/dist/commands/status.d.ts +0 -6
- package/dist/commands/status.mjs +0 -171
- package/dist/commands/sync.cjs +0 -28
- package/dist/commands/sync.d.ts +0 -6
- package/dist/commands/sync.mjs +0 -26
- package/dist/commands/types.d.ts +0 -89
- package/dist/commands/update.cjs +0 -209
- package/dist/commands/update.d.ts +0 -29
- package/dist/commands/update.mjs +0 -206
- package/dist/components/add/AddCommand.cjs +0 -103
- package/dist/components/add/AddCommand.d.ts +0 -14
- package/dist/components/add/AddCommand.mjs +0 -101
- package/dist/components/add/BulkAddView.cjs +0 -165
- package/dist/components/add/BulkAddView.d.ts +0 -11
- package/dist/components/add/BulkAddView.mjs +0 -163
- package/dist/components/add/index.d.ts +0 -2
- package/dist/components/index.d.ts +0 -2
- package/dist/components/list/EditableTreeItem.d.ts +0 -13
- package/dist/components/list/ListCommand.cjs +0 -651
- package/dist/components/list/ListCommand.d.ts +0 -5
- package/dist/components/list/ListCommand.mjs +0 -649
- package/dist/components/list/SyncedPackageTree.d.ts +0 -14
- package/dist/components/list/index.d.ts +0 -10
- package/dist/components/list/types.d.ts +0 -14
- package/dist/components/primitives/Box.d.ts +0 -4
- package/dist/components/primitives/Spinner.d.ts +0 -6
- package/dist/components/primitives/Text.d.ts +0 -4
- package/dist/components/primitives/index.d.ts +0 -3
- package/dist/components/remove/RemoveConfirm.cjs +0 -18
- package/dist/components/remove/RemoveConfirm.d.ts +0 -11
- package/dist/components/remove/RemoveConfirm.mjs +0 -16
- package/dist/components/shared/Confirm.cjs +0 -30
- package/dist/components/shared/Confirm.d.ts +0 -8
- package/dist/components/shared/Confirm.mjs +0 -28
- package/dist/components/shared/MenuItem.cjs +0 -18
- package/dist/components/shared/MenuItem.d.ts +0 -7
- package/dist/components/shared/MenuItem.mjs +0 -16
- package/dist/components/shared/ProgressBar.d.ts +0 -7
- package/dist/components/shared/StepRunner.cjs +0 -58
- package/dist/components/shared/StepRunner.d.ts +0 -15
- package/dist/components/shared/StepRunner.mjs +0 -56
- package/dist/components/shared/Table.cjs +0 -19
- package/dist/components/shared/Table.d.ts +0 -8
- package/dist/components/shared/Table.mjs +0 -17
- package/dist/components/shared/index.d.ts +0 -6
- package/dist/components/status/PackageStatusCard.d.ts +0 -10
- package/dist/components/status/StatusDisplay.cjs +0 -26
- package/dist/components/status/StatusDisplay.d.ts +0 -23
- package/dist/components/status/StatusDisplay.mjs +0 -24
- package/dist/components/status/StatusTreeNode.cjs +0 -40
- package/dist/components/status/StatusTreeNode.d.ts +0 -15
- package/dist/components/status/StatusTreeNode.mjs +0 -38
- package/dist/components/status/index.d.ts +0 -6
- package/dist/components/tree/AssetTreeNode.cjs +0 -54
- package/dist/components/tree/AssetTreeNode.d.ts +0 -12
- package/dist/components/tree/AssetTreeNode.mjs +0 -52
- package/dist/components/tree/TreeSelect.cjs +0 -129
- package/dist/components/tree/TreeSelect.d.ts +0 -12
- package/dist/components/tree/TreeSelect.mjs +0 -127
- package/dist/components/tree/index.d.ts +0 -4
- package/dist/core/assetStructure.cjs +0 -30
- package/dist/core/assetStructure.d.ts +0 -36
- package/dist/core/assetStructure.mjs +0 -27
- package/dist/core/cli.cjs +0 -106
- package/dist/core/cli.d.ts +0 -9
- package/dist/core/cli.mjs +0 -103
- package/dist/core/constants.cjs +0 -28
- package/dist/core/constants.d.ts +0 -94
- package/dist/core/constants.mjs +0 -21
- package/dist/core/filesystem.cjs +0 -98
- package/dist/core/filesystem.d.ts +0 -94
- package/dist/core/filesystem.mjs +0 -88
- package/dist/core/github.cjs +0 -115
- package/dist/core/github.d.ts +0 -61
- package/dist/core/github.mjs +0 -107
- package/dist/core/io.cjs +0 -46
- package/dist/core/io.d.ts +0 -40
- package/dist/core/io.mjs +0 -39
- package/dist/core/listOperations.cjs +0 -228
- package/dist/core/listOperations.d.ts +0 -43
- package/dist/core/listOperations.mjs +0 -205
- package/dist/core/localSource.cjs +0 -126
- package/dist/core/localSource.d.ts +0 -33
- package/dist/core/localSource.mjs +0 -120
- package/dist/core/migration.cjs +0 -201
- package/dist/core/migration.d.ts +0 -57
- package/dist/core/migration.mjs +0 -198
- package/dist/core/packageScanner.cjs +0 -360
- package/dist/core/packageScanner.d.ts +0 -22
- package/dist/core/packageScanner.mjs +0 -356
- package/dist/core/sync.cjs +0 -400
- package/dist/core/sync.d.ts +0 -21
- package/dist/core/sync.mjs +0 -397
- package/dist/core/syncMeta.cjs +0 -242
- package/dist/core/syncMeta.d.ts +0 -75
- package/dist/core/syncMeta.mjs +0 -229
- package/dist/utils/dependencies.cjs +0 -57
- package/dist/utils/dependencies.d.ts +0 -10
- package/dist/utils/dependencies.mjs +0 -34
- package/dist/utils/nameTransform.cjs +0 -13
- package/dist/utils/nameTransform.d.ts +0 -65
- package/dist/utils/nameTransform.mjs +0 -11
- package/dist/utils/package.cjs +0 -170
- package/dist/utils/package.d.ts +0 -105
- package/dist/utils/package.mjs +0 -157
- package/dist/utils/packageName.cjs +0 -24
- package/dist/utils/packageName.d.ts +0 -32
- package/dist/utils/packageName.mjs +0 -21
- package/dist/utils/paths.cjs +0 -18
- package/dist/utils/paths.d.ts +0 -55
- package/dist/utils/paths.mjs +0 -15
- package/dist/version.cjs +0 -5
- package/dist/version.d.ts +0 -5
- 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 };
|