@slats/claude-assets-sync 0.1.3 → 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/@aileron/declare/index.d.ts +4 -4
- 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 +25 -17
- 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
package/dist/core/sync.mjs
DELETED
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
import { logger } from '../utils/logger.mjs';
|
|
2
|
-
import { toFlatFileName } from '../utils/nameTransform.mjs';
|
|
3
|
-
import { findGitRoot, readLocalPackageJson, readPackageJson, resolveClaudeConfig, parseGitHubRepo, buildAssetPath, getAssetTypes, buildVersionTag } from '../utils/package.mjs';
|
|
4
|
-
import { packageNameToPrefix } from '../utils/packageName.mjs';
|
|
5
|
-
import { getDestinationDir, getFlatDestinationDir } from '../utils/paths.mjs';
|
|
6
|
-
import { SCHEMA_VERSIONS } from './constants.mjs';
|
|
7
|
-
import { cleanAssetDir, cleanFlatAssetFiles, writeAssetFile, writeFlatAssetFile, needsSync, writeSyncMeta, createSyncMeta } from './filesystem.mjs';
|
|
8
|
-
import { fetchAssetFiles, downloadAssetFiles, RateLimitError } from './github.mjs';
|
|
9
|
-
import { canUseLocalSource, fetchLocalAssetFiles, downloadLocalAssetFiles } from './localSource.mjs';
|
|
10
|
-
import { readUnifiedSyncMeta, createEmptyUnifiedMeta, needsSyncUnified, updatePackageInMeta, writeUnifiedSyncMeta } from './syncMeta.mjs';
|
|
11
|
-
import { getAssetStructure } from './assetStructure.mjs';
|
|
12
|
-
|
|
13
|
-
function groupEntriesIntoSkillUnits(entries, prefix) {
|
|
14
|
-
const dirGroups = new Map();
|
|
15
|
-
const singleFiles = [];
|
|
16
|
-
for (const entry of entries) {
|
|
17
|
-
const slashIndex = entry.name.indexOf('/');
|
|
18
|
-
if (slashIndex === -1) {
|
|
19
|
-
singleFiles.push({
|
|
20
|
-
name: entry.name,
|
|
21
|
-
isDirectory: false,
|
|
22
|
-
transformed: toFlatFileName(prefix, entry.name),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const dirName = entry.name.substring(0, slashIndex);
|
|
27
|
-
const internalFile = entry.name.substring(slashIndex + 1);
|
|
28
|
-
if (!dirGroups.has(dirName)) {
|
|
29
|
-
dirGroups.set(dirName, []);
|
|
30
|
-
}
|
|
31
|
-
dirGroups.get(dirName).push(internalFile);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const dirSkillUnits = [];
|
|
35
|
-
for (const [dirName, internalFiles] of dirGroups.entries()) {
|
|
36
|
-
dirSkillUnits.push({
|
|
37
|
-
name: dirName,
|
|
38
|
-
isDirectory: true,
|
|
39
|
-
transformed: toFlatFileName(prefix, dirName),
|
|
40
|
-
internalFiles,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return [...singleFiles, ...dirSkillUnits];
|
|
44
|
-
}
|
|
45
|
-
const syncPackage = async (packageName, options, cwd = process.cwd(), exclusions, outputDir) => {
|
|
46
|
-
logger.packageStart(packageName);
|
|
47
|
-
try {
|
|
48
|
-
const destDir = outputDir ?? findGitRoot(cwd) ?? cwd;
|
|
49
|
-
const packageInfo = options.local
|
|
50
|
-
? readLocalPackageJson(packageName, cwd)
|
|
51
|
-
: readPackageJson(packageName, cwd);
|
|
52
|
-
if (!packageInfo) {
|
|
53
|
-
const location = options.local ? 'workspace' : 'node_modules';
|
|
54
|
-
return {
|
|
55
|
-
packageName,
|
|
56
|
-
success: false,
|
|
57
|
-
skipped: true,
|
|
58
|
-
reason: `Package not found in ${location}`,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const claudeConfig = resolveClaudeConfig(packageInfo.claude);
|
|
62
|
-
const repoInfo = parseGitHubRepo(packageInfo.repository);
|
|
63
|
-
const useFlat = options.flat !== false;
|
|
64
|
-
if (useFlat) {
|
|
65
|
-
const prefix = packageNameToPrefix(packageName);
|
|
66
|
-
const unifiedMeta = readUnifiedSyncMeta(destDir) ?? createEmptyUnifiedMeta();
|
|
67
|
-
if (!options.force &&
|
|
68
|
-
!needsSyncUnified(unifiedMeta, prefix, packageInfo.version)) {
|
|
69
|
-
return {
|
|
70
|
-
packageName,
|
|
71
|
-
success: true,
|
|
72
|
-
skipped: true,
|
|
73
|
-
reason: `Already synced at version ${packageInfo.version}`,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const assetPath = buildAssetPath(claudeConfig.assetPath);
|
|
77
|
-
const useLocalSource = options.ref
|
|
78
|
-
? { available: false }
|
|
79
|
-
: canUseLocalSource(packageName, packageInfo.version, assetPath, cwd);
|
|
80
|
-
const assetTypes = getAssetTypes(claudeConfig);
|
|
81
|
-
let assetFiles;
|
|
82
|
-
let isLocalSource;
|
|
83
|
-
if (useLocalSource.available && useLocalSource.docsPath) {
|
|
84
|
-
isLocalSource = true;
|
|
85
|
-
logger.step('Using', 'local docs from node_modules');
|
|
86
|
-
assetFiles = await fetchLocalAssetFiles(useLocalSource.docsPath, assetTypes);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
if (!repoInfo) {
|
|
90
|
-
return {
|
|
91
|
-
packageName,
|
|
92
|
-
success: false,
|
|
93
|
-
skipped: true,
|
|
94
|
-
reason: `Package ${packageName} has no valid GitHub repository URL for remote fetch`,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
isLocalSource = false;
|
|
98
|
-
const tag = options.ref ?? buildVersionTag(packageName, packageInfo.version);
|
|
99
|
-
logger.step('Fetching', `asset list from GitHub (ref: ${tag})`);
|
|
100
|
-
assetFiles = await fetchAssetFiles(repoInfo, assetPath, tag, assetTypes);
|
|
101
|
-
}
|
|
102
|
-
let totalFiles = 0;
|
|
103
|
-
for (const assetType of assetTypes) {
|
|
104
|
-
totalFiles += (assetFiles[assetType] || []).length;
|
|
105
|
-
}
|
|
106
|
-
if (totalFiles === 0)
|
|
107
|
-
return {
|
|
108
|
-
packageName,
|
|
109
|
-
success: false,
|
|
110
|
-
skipped: true,
|
|
111
|
-
reason: `No assets found in package (checked: ${assetTypes.join(', ')})`,
|
|
112
|
-
};
|
|
113
|
-
const foundSummary = assetTypes
|
|
114
|
-
.map((type) => `${(assetFiles[type] || []).length} ${type}`)
|
|
115
|
-
.join(', ');
|
|
116
|
-
logger.step('Found', foundSummary);
|
|
117
|
-
const fileMappings = {};
|
|
118
|
-
for (const assetType of assetTypes) {
|
|
119
|
-
const entries = assetFiles[assetType] || [];
|
|
120
|
-
if (entries.length === 0)
|
|
121
|
-
continue;
|
|
122
|
-
const filteredEntries = entries.filter((entry) => {
|
|
123
|
-
if (!exclusions)
|
|
124
|
-
return true;
|
|
125
|
-
const excludedPath = `${assetType}/${entry.name}`;
|
|
126
|
-
return !exclusions.files.includes(excludedPath);
|
|
127
|
-
});
|
|
128
|
-
if (filteredEntries.length === 0)
|
|
129
|
-
continue;
|
|
130
|
-
const structure = getAssetStructure(assetType, claudeConfig);
|
|
131
|
-
if (structure === 'nested') {
|
|
132
|
-
fileMappings[assetType] = filteredEntries.map((e) => ({
|
|
133
|
-
name: e.name,
|
|
134
|
-
isDirectory: false,
|
|
135
|
-
}));
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
fileMappings[assetType] = groupEntriesIntoSkillUnits(filteredEntries, prefix);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (options.dryRun) {
|
|
142
|
-
for (const assetType of assetTypes) {
|
|
143
|
-
const units = fileMappings[assetType];
|
|
144
|
-
if (!units || units.length === 0)
|
|
145
|
-
continue;
|
|
146
|
-
const structure = getAssetStructure(assetType, claudeConfig);
|
|
147
|
-
if (structure === 'nested') {
|
|
148
|
-
logger.step(`Would sync ${assetType} to`, getDestinationDir(destDir, packageName, assetType));
|
|
149
|
-
units.forEach((unit) => {
|
|
150
|
-
logger.file('create', unit.name);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
logger.step(`Would sync ${assetType} to`, getFlatDestinationDir(destDir, assetType));
|
|
155
|
-
units.forEach((unit) => {
|
|
156
|
-
const displayName = unit.transformed ?? unit.name;
|
|
157
|
-
logger.file('create', displayName);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const syncedFiles = {};
|
|
162
|
-
for (const assetType of assetTypes) {
|
|
163
|
-
const units = fileMappings[assetType];
|
|
164
|
-
if (!units || units.length === 0)
|
|
165
|
-
continue;
|
|
166
|
-
syncedFiles[assetType] = units.map((u) => u.transformed ?? u.name);
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
packageName,
|
|
170
|
-
success: true,
|
|
171
|
-
skipped: false,
|
|
172
|
-
syncedFiles,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
for (const assetType of assetTypes) {
|
|
176
|
-
const structure = getAssetStructure(assetType, claudeConfig);
|
|
177
|
-
if (structure === 'nested') {
|
|
178
|
-
cleanAssetDir(destDir, packageName, assetType);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
cleanFlatAssetFiles(destDir, assetType, prefix, unifiedMeta);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
for (const assetType of assetTypes) {
|
|
185
|
-
const entries = assetFiles[assetType] || [];
|
|
186
|
-
if (entries.length === 0)
|
|
187
|
-
continue;
|
|
188
|
-
const filteredEntries = entries.filter((entry) => {
|
|
189
|
-
if (!exclusions)
|
|
190
|
-
return true;
|
|
191
|
-
const excludedPath = `${assetType}/${entry.name}`;
|
|
192
|
-
return !exclusions.files.includes(excludedPath);
|
|
193
|
-
});
|
|
194
|
-
if (filteredEntries.length === 0)
|
|
195
|
-
continue;
|
|
196
|
-
const structure = getAssetStructure(assetType, claudeConfig);
|
|
197
|
-
logger.step('Downloading', assetType);
|
|
198
|
-
let downloadedFiles;
|
|
199
|
-
if (isLocalSource && useLocalSource.docsPath) {
|
|
200
|
-
downloadedFiles = await downloadLocalAssetFiles(useLocalSource.docsPath, assetType, filteredEntries);
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
const tag = options.ref ?? buildVersionTag(packageName, packageInfo.version);
|
|
204
|
-
downloadedFiles = await downloadAssetFiles(repoInfo, assetPath, assetType, filteredEntries, tag);
|
|
205
|
-
}
|
|
206
|
-
if (structure === 'nested') {
|
|
207
|
-
for (const [fileName, content] of downloadedFiles) {
|
|
208
|
-
writeAssetFile(destDir, packageName, assetType, fileName, content);
|
|
209
|
-
logger.file('create', fileName);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
for (const [fileName, content] of downloadedFiles) {
|
|
214
|
-
const flatName = toFlatFileName(prefix, fileName);
|
|
215
|
-
writeFlatAssetFile(destDir, assetType, flatName, content);
|
|
216
|
-
logger.file('create', flatName);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const updatedMeta = updatePackageInMeta(unifiedMeta, prefix, {
|
|
221
|
-
originalName: packageName,
|
|
222
|
-
version: packageInfo.version,
|
|
223
|
-
local: options.local,
|
|
224
|
-
files: fileMappings,
|
|
225
|
-
exclusions: exclusions &&
|
|
226
|
-
(exclusions.directories.length > 0 || exclusions.files.length > 0)
|
|
227
|
-
? exclusions
|
|
228
|
-
: undefined,
|
|
229
|
-
});
|
|
230
|
-
updatedMeta.skillUnitFormat = SCHEMA_VERSIONS.SKILL_UNIT_FORMAT;
|
|
231
|
-
writeUnifiedSyncMeta(destDir, updatedMeta);
|
|
232
|
-
const syncedFiles = {};
|
|
233
|
-
for (const assetType of assetTypes) {
|
|
234
|
-
const units = fileMappings[assetType];
|
|
235
|
-
if (!units || units.length === 0)
|
|
236
|
-
continue;
|
|
237
|
-
syncedFiles[assetType] = units.map((u) => u.transformed ?? u.name);
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
packageName,
|
|
241
|
-
success: true,
|
|
242
|
-
skipped: false,
|
|
243
|
-
syncedFiles,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
const assetPath = buildAssetPath(claudeConfig.assetPath);
|
|
248
|
-
const useLocalSource = options.ref
|
|
249
|
-
? { available: false }
|
|
250
|
-
: canUseLocalSource(packageName, packageInfo.version, assetPath, cwd);
|
|
251
|
-
const assetTypes = getAssetTypes(claudeConfig);
|
|
252
|
-
let assetFiles;
|
|
253
|
-
let isLocalSource;
|
|
254
|
-
if (useLocalSource.available && useLocalSource.docsPath) {
|
|
255
|
-
isLocalSource = true;
|
|
256
|
-
logger.step('Using', 'local docs from node_modules');
|
|
257
|
-
assetFiles = await fetchLocalAssetFiles(useLocalSource.docsPath, assetTypes);
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
if (!repoInfo) {
|
|
261
|
-
return {
|
|
262
|
-
packageName,
|
|
263
|
-
success: false,
|
|
264
|
-
skipped: true,
|
|
265
|
-
reason: `Package ${packageName} has no valid GitHub repository URL for remote fetch`,
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
isLocalSource = false;
|
|
269
|
-
const tag = options.ref ?? buildVersionTag(packageName, packageInfo.version);
|
|
270
|
-
logger.step('Fetching', `asset list from GitHub (ref: ${tag})`);
|
|
271
|
-
assetFiles = await fetchAssetFiles(repoInfo, assetPath, tag, assetTypes);
|
|
272
|
-
}
|
|
273
|
-
let totalFiles = 0;
|
|
274
|
-
for (const assetType of assetTypes) {
|
|
275
|
-
totalFiles += (assetFiles[assetType] || []).length;
|
|
276
|
-
}
|
|
277
|
-
if (totalFiles === 0)
|
|
278
|
-
return {
|
|
279
|
-
packageName,
|
|
280
|
-
success: false,
|
|
281
|
-
skipped: true,
|
|
282
|
-
reason: `No assets found in package (checked: ${assetTypes.join(', ')})`,
|
|
283
|
-
};
|
|
284
|
-
const foundSummary = assetTypes
|
|
285
|
-
.map((type) => `${(assetFiles[type] || []).length} ${type}`)
|
|
286
|
-
.join(', ');
|
|
287
|
-
logger.step('Found', foundSummary);
|
|
288
|
-
if (!options.force &&
|
|
289
|
-
!needsSync(destDir, packageName, packageInfo.version, assetTypes)) {
|
|
290
|
-
return {
|
|
291
|
-
packageName,
|
|
292
|
-
success: true,
|
|
293
|
-
skipped: true,
|
|
294
|
-
reason: `Already synced at version ${packageInfo.version}`,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
if (options.dryRun) {
|
|
298
|
-
const syncedFiles = {};
|
|
299
|
-
for (const assetType of assetTypes) {
|
|
300
|
-
const entries = assetFiles[assetType] || [];
|
|
301
|
-
if (entries.length === 0)
|
|
302
|
-
continue;
|
|
303
|
-
const filteredEntries = entries.filter((entry) => {
|
|
304
|
-
if (!exclusions)
|
|
305
|
-
return true;
|
|
306
|
-
const excludedPath = `${assetType}/${entry.name}`;
|
|
307
|
-
return !exclusions.files.includes(excludedPath);
|
|
308
|
-
});
|
|
309
|
-
if (filteredEntries.length === 0)
|
|
310
|
-
continue;
|
|
311
|
-
logger.step(`Would sync ${assetType} to`, getDestinationDir(destDir, packageName, assetType));
|
|
312
|
-
filteredEntries.forEach((entry) => logger.file('create', entry.name));
|
|
313
|
-
syncedFiles[assetType] = filteredEntries.map((e) => e.name);
|
|
314
|
-
}
|
|
315
|
-
return {
|
|
316
|
-
packageName,
|
|
317
|
-
success: true,
|
|
318
|
-
skipped: false,
|
|
319
|
-
syncedFiles,
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
const syncedFiles = {};
|
|
323
|
-
for (const assetType of assetTypes) {
|
|
324
|
-
const entries = assetFiles[assetType] || [];
|
|
325
|
-
if (entries.length === 0)
|
|
326
|
-
continue;
|
|
327
|
-
const filteredEntries = entries.filter((entry) => {
|
|
328
|
-
if (!exclusions)
|
|
329
|
-
return true;
|
|
330
|
-
const excludedPath = `${assetType}/${entry.name}`;
|
|
331
|
-
return !exclusions.files.includes(excludedPath);
|
|
332
|
-
});
|
|
333
|
-
if (filteredEntries.length === 0)
|
|
334
|
-
continue;
|
|
335
|
-
logger.step('Downloading', assetType);
|
|
336
|
-
let downloadedFiles;
|
|
337
|
-
if (isLocalSource && useLocalSource.docsPath) {
|
|
338
|
-
downloadedFiles = await downloadLocalAssetFiles(useLocalSource.docsPath, assetType, filteredEntries);
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
const tag = options.ref ?? buildVersionTag(packageName, packageInfo.version);
|
|
342
|
-
downloadedFiles = await downloadAssetFiles(repoInfo, assetPath, assetType, filteredEntries, tag);
|
|
343
|
-
}
|
|
344
|
-
cleanAssetDir(destDir, packageName, assetType);
|
|
345
|
-
syncedFiles[assetType] = [];
|
|
346
|
-
for (const [fileName, content] of downloadedFiles) {
|
|
347
|
-
writeAssetFile(destDir, packageName, assetType, fileName, content);
|
|
348
|
-
logger.file('create', fileName);
|
|
349
|
-
syncedFiles[assetType].push(fileName);
|
|
350
|
-
}
|
|
351
|
-
writeSyncMeta(destDir, packageName, assetType, createSyncMeta(packageInfo.version, syncedFiles[assetType]));
|
|
352
|
-
}
|
|
353
|
-
return {
|
|
354
|
-
packageName,
|
|
355
|
-
success: true,
|
|
356
|
-
skipped: false,
|
|
357
|
-
syncedFiles,
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
catch (error) {
|
|
362
|
-
if (error instanceof RateLimitError)
|
|
363
|
-
return {
|
|
364
|
-
packageName,
|
|
365
|
-
success: false,
|
|
366
|
-
skipped: false,
|
|
367
|
-
reason: error.message,
|
|
368
|
-
};
|
|
369
|
-
const message = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
370
|
-
return {
|
|
371
|
-
packageName,
|
|
372
|
-
success: false,
|
|
373
|
-
skipped: false,
|
|
374
|
-
reason: message,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
const syncPackages = async (packages, options, cwd = process.cwd()) => {
|
|
379
|
-
const results = [];
|
|
380
|
-
const gitRoot = findGitRoot(cwd);
|
|
381
|
-
if (gitRoot)
|
|
382
|
-
logger.info(`[Output] ${gitRoot}/.claude\n`);
|
|
383
|
-
for (const packageName of packages) {
|
|
384
|
-
const result = await syncPackage(packageName, options, cwd, undefined, gitRoot ?? undefined);
|
|
385
|
-
logger.packageEnd(packageName, result);
|
|
386
|
-
results.push(result);
|
|
387
|
-
}
|
|
388
|
-
const summary = {
|
|
389
|
-
success: results.filter((r) => r.success && !r.skipped).length,
|
|
390
|
-
skipped: results.filter((r) => r.skipped).length,
|
|
391
|
-
failed: results.filter((r) => !r.success && !r.skipped).length,
|
|
392
|
-
};
|
|
393
|
-
logger.summary(summary);
|
|
394
|
-
return results;
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
export { syncPackage, syncPackages };
|
package/dist/core/syncMeta.cjs
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('node:path');
|
|
4
|
-
var version = require('../utils/version.cjs');
|
|
5
|
-
var constants = require('./constants.cjs');
|
|
6
|
-
var io = require('./io.cjs');
|
|
7
|
-
|
|
8
|
-
const UNIFIED_META_PATH = constants.META_FILES.UNIFIED_SYNC_META;
|
|
9
|
-
const SCHEMA_VERSION = constants.SCHEMA_VERSIONS.UNIFIED_SYNC_META;
|
|
10
|
-
function readUnifiedSyncMeta(cwd) {
|
|
11
|
-
const metaPath = path.join(cwd, UNIFIED_META_PATH);
|
|
12
|
-
const meta = io.readJsonFile(metaPath);
|
|
13
|
-
if (meta && needsSkillUnitMigration(meta)) {
|
|
14
|
-
return migrateToSkillUnitSchema(meta);
|
|
15
|
-
}
|
|
16
|
-
return meta;
|
|
17
|
-
}
|
|
18
|
-
function writeUnifiedSyncMeta(cwd, meta) {
|
|
19
|
-
const metaPath = path.join(cwd, UNIFIED_META_PATH);
|
|
20
|
-
try {
|
|
21
|
-
io.writeJsonFile(metaPath, meta);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.error(`Failed to write unified sync meta to ${metaPath}:`, error);
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function updatePackageInMeta(meta, prefix, info) {
|
|
29
|
-
return {
|
|
30
|
-
...meta,
|
|
31
|
-
syncedAt: new Date().toISOString(),
|
|
32
|
-
packages: {
|
|
33
|
-
...meta.packages,
|
|
34
|
-
[prefix]: info,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function removePackageFromMeta(meta, prefix) {
|
|
39
|
-
const { [prefix]: removed, ...remainingPackages } = meta.packages;
|
|
40
|
-
return {
|
|
41
|
-
...meta,
|
|
42
|
-
packages: remainingPackages,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function needsSyncUnified(meta, prefix, version$1) {
|
|
46
|
-
if (!meta) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
const pkgInfo = meta.packages[prefix];
|
|
50
|
-
if (!pkgInfo) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
return version.needsVersionSync(version$1, pkgInfo.version);
|
|
54
|
-
}
|
|
55
|
-
function createEmptyUnifiedMeta() {
|
|
56
|
-
return {
|
|
57
|
-
schemaVersion: SCHEMA_VERSION,
|
|
58
|
-
syncedAt: new Date().toISOString(),
|
|
59
|
-
packages: {},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function removeSkillUnitFromPackage(meta, prefix, assetType, skillName) {
|
|
63
|
-
const pkgInfo = meta.packages[prefix];
|
|
64
|
-
if (!pkgInfo) {
|
|
65
|
-
throw new Error(`Package ${prefix} not found in metadata`);
|
|
66
|
-
}
|
|
67
|
-
const existingUnits = (pkgInfo.files[assetType] || []);
|
|
68
|
-
const updatedUnits = existingUnits.filter((u) => u.name !== skillName);
|
|
69
|
-
if (existingUnits.length === updatedUnits.length) {
|
|
70
|
-
return meta;
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
...meta,
|
|
74
|
-
syncedAt: new Date().toISOString(),
|
|
75
|
-
packages: {
|
|
76
|
-
...meta.packages,
|
|
77
|
-
[prefix]: {
|
|
78
|
-
...pkgInfo,
|
|
79
|
-
files: {
|
|
80
|
-
...pkgInfo.files,
|
|
81
|
-
[assetType]: updatedUnits,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function updatePackageVersion(meta, prefix, newVersion) {
|
|
88
|
-
const pkgInfo = meta.packages[prefix];
|
|
89
|
-
if (!pkgInfo) {
|
|
90
|
-
throw new Error(`Package ${prefix} not found in metadata`);
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
...meta,
|
|
94
|
-
syncedAt: new Date().toISOString(),
|
|
95
|
-
packages: {
|
|
96
|
-
...meta.packages,
|
|
97
|
-
[prefix]: {
|
|
98
|
-
...pkgInfo,
|
|
99
|
-
version: newVersion,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function updatePackageFilesystemMeta(meta, prefix, assetType, updatedUnits) {
|
|
105
|
-
const pkgInfo = meta.packages[prefix];
|
|
106
|
-
if (!pkgInfo) {
|
|
107
|
-
throw new Error(`Package ${prefix} not found in metadata`);
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
...meta,
|
|
111
|
-
syncedAt: new Date().toISOString(),
|
|
112
|
-
skillUnitFormat: constants.SCHEMA_VERSIONS.SKILL_UNIT_FORMAT,
|
|
113
|
-
packages: {
|
|
114
|
-
...meta.packages,
|
|
115
|
-
[prefix]: {
|
|
116
|
-
...pkgInfo,
|
|
117
|
-
files: {
|
|
118
|
-
...pkgInfo.files,
|
|
119
|
-
[assetType]: updatedUnits,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function needsSkillUnitMigration(meta) {
|
|
126
|
-
if (meta.skillUnitFormat === constants.SCHEMA_VERSIONS.SKILL_UNIT_FORMAT) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
for (const pkgInfo of Object.values(meta.packages)) {
|
|
130
|
-
for (const rawFiles of Object.values(pkgInfo.files)) {
|
|
131
|
-
const files = rawFiles;
|
|
132
|
-
if (!Array.isArray(files) || files.length === 0) {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const first = files[0];
|
|
136
|
-
if (typeof first === 'string') {
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
if (typeof first === 'object' &&
|
|
140
|
-
first !== null &&
|
|
141
|
-
'original' in first &&
|
|
142
|
-
'transformed' in first &&
|
|
143
|
-
!('isDirectory' in first)) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
if (typeof first === 'object' &&
|
|
147
|
-
first !== null &&
|
|
148
|
-
'isDirectory' in first) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
function migrateToSkillUnitSchema(meta) {
|
|
156
|
-
const migratedPackages = {};
|
|
157
|
-
for (const [prefix, pkgInfo] of Object.entries(meta.packages)) {
|
|
158
|
-
const migratedFiles = {};
|
|
159
|
-
for (const [assetType, rawFiles] of Object.entries(pkgInfo.files)) {
|
|
160
|
-
const files = rawFiles;
|
|
161
|
-
if (!Array.isArray(files) || files.length === 0) {
|
|
162
|
-
migratedFiles[assetType] = [];
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
const first = files[0];
|
|
166
|
-
if (typeof first === 'string') {
|
|
167
|
-
migratedFiles[assetType] = files.map((name) => ({
|
|
168
|
-
name,
|
|
169
|
-
isDirectory: false,
|
|
170
|
-
}));
|
|
171
|
-
}
|
|
172
|
-
else if (typeof first === 'object' &&
|
|
173
|
-
first !== null &&
|
|
174
|
-
'original' in first &&
|
|
175
|
-
!('isDirectory' in first)) {
|
|
176
|
-
const fileMappings = files;
|
|
177
|
-
const groupedByDir = new Map();
|
|
178
|
-
const singleFiles = [];
|
|
179
|
-
for (const mapping of fileMappings) {
|
|
180
|
-
const slashIndex = mapping.original.indexOf('/');
|
|
181
|
-
if (slashIndex === -1) {
|
|
182
|
-
singleFiles.push({
|
|
183
|
-
name: mapping.original,
|
|
184
|
-
isDirectory: false,
|
|
185
|
-
transformed: mapping.transformed,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
const dirName = mapping.original.substring(0, slashIndex);
|
|
190
|
-
const internalFile = mapping.original.substring(slashIndex + 1);
|
|
191
|
-
const transformedSlashIndex = mapping.transformed.indexOf('/');
|
|
192
|
-
const transformedDir = transformedSlashIndex !== -1
|
|
193
|
-
? mapping.transformed.substring(0, transformedSlashIndex)
|
|
194
|
-
: mapping.transformed;
|
|
195
|
-
if (!groupedByDir.has(dirName)) {
|
|
196
|
-
groupedByDir.set(dirName, {
|
|
197
|
-
transformed: transformedDir,
|
|
198
|
-
internalFiles: [],
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
groupedByDir.get(dirName).internalFiles.push(internalFile);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const dirSkillUnits = [];
|
|
205
|
-
for (const [dirName, data] of groupedByDir.entries()) {
|
|
206
|
-
dirSkillUnits.push({
|
|
207
|
-
name: dirName,
|
|
208
|
-
isDirectory: true,
|
|
209
|
-
transformed: data.transformed,
|
|
210
|
-
internalFiles: data.internalFiles,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
migratedFiles[assetType] = [...singleFiles, ...dirSkillUnits];
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
migratedFiles[assetType] = files;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
migratedPackages[prefix] = {
|
|
220
|
-
...pkgInfo,
|
|
221
|
-
files: migratedFiles,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
return {
|
|
225
|
-
...meta,
|
|
226
|
-
skillUnitFormat: constants.SCHEMA_VERSIONS.SKILL_UNIT_FORMAT,
|
|
227
|
-
packages: migratedPackages,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
exports.SCHEMA_VERSION = SCHEMA_VERSION;
|
|
232
|
-
exports.createEmptyUnifiedMeta = createEmptyUnifiedMeta;
|
|
233
|
-
exports.migrateToSkillUnitSchema = migrateToSkillUnitSchema;
|
|
234
|
-
exports.needsSkillUnitMigration = needsSkillUnitMigration;
|
|
235
|
-
exports.needsSyncUnified = needsSyncUnified;
|
|
236
|
-
exports.readUnifiedSyncMeta = readUnifiedSyncMeta;
|
|
237
|
-
exports.removePackageFromMeta = removePackageFromMeta;
|
|
238
|
-
exports.removeSkillUnitFromPackage = removeSkillUnitFromPackage;
|
|
239
|
-
exports.updatePackageFilesystemMeta = updatePackageFilesystemMeta;
|
|
240
|
-
exports.updatePackageInMeta = updatePackageInMeta;
|
|
241
|
-
exports.updatePackageVersion = updatePackageVersion;
|
|
242
|
-
exports.writeUnifiedSyncMeta = writeUnifiedSyncMeta;
|