@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.
Files changed (228) hide show
  1. package/README.md +111 -587
  2. package/bin/claude-sync.mjs +24 -0
  3. package/dist/@aileron/declare/index.d.ts +4 -4
  4. package/dist/claude-hashes.json +20 -0
  5. package/dist/commands/index.d.ts +1 -112
  6. package/dist/commands/runCli/index.d.ts +2 -0
  7. package/dist/commands/runCli/runCli.cjs +31 -0
  8. package/dist/commands/runCli/runCli.d.ts +10 -0
  9. package/dist/commands/runCli/runCli.mjs +29 -0
  10. package/dist/commands/runCli/type.d.ts +28 -0
  11. package/dist/commands/runCli/utils/injectOne.cjs +48 -0
  12. package/dist/commands/runCli/utils/injectOne.d.ts +3 -0
  13. package/dist/commands/runCli/utils/injectOne.mjs +46 -0
  14. package/dist/commands/runCli/utils/resolveScopeFlag.cjs +28 -0
  15. package/dist/commands/runCli/utils/resolveScopeFlag.d.ts +2 -0
  16. package/dist/commands/runCli/utils/resolveScopeFlag.mjs +26 -0
  17. package/dist/commands/runCli/utils/runInject.cjs +36 -0
  18. package/dist/commands/runCli/utils/runInject.d.ts +2 -0
  19. package/dist/commands/runCli/utils/runInject.mjs +34 -0
  20. package/dist/core/buildPlan/buildPlan.cjs +42 -0
  21. package/dist/core/buildPlan/buildPlan.d.ts +2 -0
  22. package/dist/core/buildPlan/buildPlan.mjs +40 -0
  23. package/dist/core/buildPlan/index.d.ts +2 -0
  24. package/dist/core/buildPlan/type.d.ts +32 -0
  25. package/dist/core/buildPlan/utils/toPosix.cjs +9 -0
  26. package/dist/core/buildPlan/utils/toPosix.d.ts +1 -0
  27. package/dist/core/buildPlan/utils/toPosix.mjs +7 -0
  28. package/dist/core/buildPlan/utils/walkFiles.cjs +25 -0
  29. package/dist/core/buildPlan/utils/walkFiles.d.ts +1 -0
  30. package/dist/core/buildPlan/utils/walkFiles.mjs +23 -0
  31. package/dist/core/hash/hash.cjs +30 -0
  32. package/dist/core/hash/hash.d.ts +4 -0
  33. package/dist/core/hash/hash.mjs +26 -0
  34. package/dist/core/hash/index.d.ts +1 -0
  35. package/dist/core/hashManifest/hashManifest.cjs +27 -0
  36. package/dist/core/hashManifest/hashManifest.d.ts +17 -0
  37. package/dist/core/hashManifest/hashManifest.mjs +23 -0
  38. package/dist/core/hashManifest/index.d.ts +1 -0
  39. package/dist/core/index.d.ts +5 -0
  40. package/dist/core/injectDocs/index.d.ts +2 -0
  41. package/dist/core/injectDocs/injectDocs.cjs +43 -0
  42. package/dist/core/injectDocs/injectDocs.d.ts +2 -0
  43. package/dist/core/injectDocs/injectDocs.mjs +41 -0
  44. package/dist/core/injectDocs/type.d.ts +30 -0
  45. package/dist/core/injectDocs/utils/applyAction.cjs +21 -0
  46. package/dist/core/injectDocs/utils/applyAction.d.ts +2 -0
  47. package/dist/core/injectDocs/utils/applyAction.mjs +19 -0
  48. package/dist/core/injectDocs/utils/emitCiForceList.cjs +10 -0
  49. package/dist/core/injectDocs/utils/emitCiForceList.d.ts +2 -0
  50. package/dist/core/injectDocs/utils/emitCiForceList.mjs +8 -0
  51. package/dist/core/injectDocs/utils/printPlan.cjs +20 -0
  52. package/dist/core/injectDocs/utils/printPlan.d.ts +2 -0
  53. package/dist/core/injectDocs/utils/printPlan.mjs +18 -0
  54. package/dist/core/injectDocs/utils/summarize.cjs +27 -0
  55. package/dist/core/injectDocs/utils/summarize.d.ts +3 -0
  56. package/dist/core/injectDocs/utils/summarize.mjs +25 -0
  57. package/dist/core/scope/index.d.ts +1 -0
  58. package/dist/core/scope/scope.cjs +46 -0
  59. package/dist/core/scope/scope.d.ts +16 -0
  60. package/dist/core/scope/scope.mjs +41 -0
  61. package/dist/core/scope/utils/isDirectory.cjs +14 -0
  62. package/dist/core/scope/utils/isDirectory.d.ts +1 -0
  63. package/dist/core/scope/utils/isDirectory.mjs +12 -0
  64. package/dist/index.cjs +15 -9
  65. package/dist/index.d.ts +3 -5
  66. package/dist/index.mjs +7 -3
  67. package/dist/prompts/confirmForce.cjs +27 -0
  68. package/dist/prompts/confirmForce.d.ts +1 -0
  69. package/dist/prompts/confirmForce.mjs +25 -0
  70. package/dist/prompts/index.d.ts +2 -0
  71. package/dist/prompts/selectScope.cjs +30 -0
  72. package/dist/prompts/selectScope.d.ts +2 -0
  73. package/dist/prompts/selectScope.mjs +28 -0
  74. package/dist/utils/heartbeat.cjs +25 -0
  75. package/dist/utils/heartbeat.d.ts +16 -0
  76. package/dist/utils/heartbeat.mjs +23 -0
  77. package/dist/utils/logger.cjs +7 -0
  78. package/dist/utils/logger.d.ts +8 -0
  79. package/dist/utils/logger.mjs +7 -0
  80. package/dist/utils/types.d.ts +1 -252
  81. package/dist/utils/version.cjs +2 -14
  82. package/dist/utils/version.d.ts +3 -53
  83. package/dist/utils/version.mjs +2 -13
  84. package/docs/bundle-size-decision.md +36 -0
  85. package/docs/claude/skills/claude-sync-applier/SKILL.md +195 -0
  86. package/docs/claude/skills/claude-sync-applier/knowledge/claude-md-template.md +77 -0
  87. package/docs/claude/skills/claude-sync-applier/knowledge/dependency-cruiser.md +126 -0
  88. package/docs/claude/skills/claude-sync-applier/knowledge/gotchas.md +139 -0
  89. package/docs/claude/skills/claude-sync-applier/knowledge/package-json-patches.md +130 -0
  90. package/docs/claude/skills/claude-sync-applier/knowledge/reference-files.md +120 -0
  91. package/docs/claude/skills/claude-sync-applier/knowledge/smoke-tests.md +102 -0
  92. package/docs/consumer-integration.md +153 -0
  93. package/package.json +25 -17
  94. package/scripts/build-hashes.mjs +30 -0
  95. package/scripts/buildHashes.d.mts +15 -0
  96. package/scripts/buildHashes.mjs +82 -0
  97. package/scripts/claude-build-hashes.mjs +42 -0
  98. package/scripts/inject-version.js +112 -0
  99. package/dist/cli.cjs +0 -8
  100. package/dist/cli.d.ts +0 -1
  101. package/dist/cli.mjs +0 -7
  102. package/dist/commands/add.cjs +0 -80
  103. package/dist/commands/add.d.ts +0 -8
  104. package/dist/commands/add.mjs +0 -78
  105. package/dist/commands/list.cjs +0 -94
  106. package/dist/commands/list.d.ts +0 -15
  107. package/dist/commands/list.mjs +0 -91
  108. package/dist/commands/migrate.cjs +0 -9
  109. package/dist/commands/migrate.d.ts +0 -6
  110. package/dist/commands/migrate.mjs +0 -7
  111. package/dist/commands/remove.cjs +0 -127
  112. package/dist/commands/remove.d.ts +0 -6
  113. package/dist/commands/remove.mjs +0 -105
  114. package/dist/commands/status.cjs +0 -193
  115. package/dist/commands/status.d.ts +0 -6
  116. package/dist/commands/status.mjs +0 -171
  117. package/dist/commands/sync.cjs +0 -28
  118. package/dist/commands/sync.d.ts +0 -6
  119. package/dist/commands/sync.mjs +0 -26
  120. package/dist/commands/types.d.ts +0 -89
  121. package/dist/commands/update.cjs +0 -209
  122. package/dist/commands/update.d.ts +0 -29
  123. package/dist/commands/update.mjs +0 -206
  124. package/dist/components/add/AddCommand.cjs +0 -103
  125. package/dist/components/add/AddCommand.d.ts +0 -14
  126. package/dist/components/add/AddCommand.mjs +0 -101
  127. package/dist/components/add/BulkAddView.cjs +0 -165
  128. package/dist/components/add/BulkAddView.d.ts +0 -11
  129. package/dist/components/add/BulkAddView.mjs +0 -163
  130. package/dist/components/add/index.d.ts +0 -2
  131. package/dist/components/index.d.ts +0 -2
  132. package/dist/components/list/EditableTreeItem.d.ts +0 -13
  133. package/dist/components/list/ListCommand.cjs +0 -651
  134. package/dist/components/list/ListCommand.d.ts +0 -5
  135. package/dist/components/list/ListCommand.mjs +0 -649
  136. package/dist/components/list/SyncedPackageTree.d.ts +0 -14
  137. package/dist/components/list/index.d.ts +0 -10
  138. package/dist/components/list/types.d.ts +0 -14
  139. package/dist/components/primitives/Box.d.ts +0 -4
  140. package/dist/components/primitives/Spinner.d.ts +0 -6
  141. package/dist/components/primitives/Text.d.ts +0 -4
  142. package/dist/components/primitives/index.d.ts +0 -3
  143. package/dist/components/remove/RemoveConfirm.cjs +0 -18
  144. package/dist/components/remove/RemoveConfirm.d.ts +0 -11
  145. package/dist/components/remove/RemoveConfirm.mjs +0 -16
  146. package/dist/components/shared/Confirm.cjs +0 -30
  147. package/dist/components/shared/Confirm.d.ts +0 -8
  148. package/dist/components/shared/Confirm.mjs +0 -28
  149. package/dist/components/shared/MenuItem.cjs +0 -18
  150. package/dist/components/shared/MenuItem.d.ts +0 -7
  151. package/dist/components/shared/MenuItem.mjs +0 -16
  152. package/dist/components/shared/ProgressBar.d.ts +0 -7
  153. package/dist/components/shared/StepRunner.cjs +0 -58
  154. package/dist/components/shared/StepRunner.d.ts +0 -15
  155. package/dist/components/shared/StepRunner.mjs +0 -56
  156. package/dist/components/shared/Table.cjs +0 -19
  157. package/dist/components/shared/Table.d.ts +0 -8
  158. package/dist/components/shared/Table.mjs +0 -17
  159. package/dist/components/shared/index.d.ts +0 -6
  160. package/dist/components/status/PackageStatusCard.d.ts +0 -10
  161. package/dist/components/status/StatusDisplay.cjs +0 -26
  162. package/dist/components/status/StatusDisplay.d.ts +0 -23
  163. package/dist/components/status/StatusDisplay.mjs +0 -24
  164. package/dist/components/status/StatusTreeNode.cjs +0 -40
  165. package/dist/components/status/StatusTreeNode.d.ts +0 -15
  166. package/dist/components/status/StatusTreeNode.mjs +0 -38
  167. package/dist/components/status/index.d.ts +0 -6
  168. package/dist/components/tree/AssetTreeNode.cjs +0 -54
  169. package/dist/components/tree/AssetTreeNode.d.ts +0 -12
  170. package/dist/components/tree/AssetTreeNode.mjs +0 -52
  171. package/dist/components/tree/TreeSelect.cjs +0 -129
  172. package/dist/components/tree/TreeSelect.d.ts +0 -12
  173. package/dist/components/tree/TreeSelect.mjs +0 -127
  174. package/dist/components/tree/index.d.ts +0 -4
  175. package/dist/core/assetStructure.cjs +0 -30
  176. package/dist/core/assetStructure.d.ts +0 -36
  177. package/dist/core/assetStructure.mjs +0 -27
  178. package/dist/core/cli.cjs +0 -106
  179. package/dist/core/cli.d.ts +0 -9
  180. package/dist/core/cli.mjs +0 -103
  181. package/dist/core/constants.cjs +0 -28
  182. package/dist/core/constants.d.ts +0 -94
  183. package/dist/core/constants.mjs +0 -21
  184. package/dist/core/filesystem.cjs +0 -98
  185. package/dist/core/filesystem.d.ts +0 -94
  186. package/dist/core/filesystem.mjs +0 -88
  187. package/dist/core/github.cjs +0 -115
  188. package/dist/core/github.d.ts +0 -61
  189. package/dist/core/github.mjs +0 -107
  190. package/dist/core/io.cjs +0 -46
  191. package/dist/core/io.d.ts +0 -40
  192. package/dist/core/io.mjs +0 -39
  193. package/dist/core/listOperations.cjs +0 -228
  194. package/dist/core/listOperations.d.ts +0 -43
  195. package/dist/core/listOperations.mjs +0 -205
  196. package/dist/core/localSource.cjs +0 -126
  197. package/dist/core/localSource.d.ts +0 -33
  198. package/dist/core/localSource.mjs +0 -120
  199. package/dist/core/migration.cjs +0 -201
  200. package/dist/core/migration.d.ts +0 -57
  201. package/dist/core/migration.mjs +0 -198
  202. package/dist/core/packageScanner.cjs +0 -360
  203. package/dist/core/packageScanner.d.ts +0 -22
  204. package/dist/core/packageScanner.mjs +0 -356
  205. package/dist/core/sync.cjs +0 -400
  206. package/dist/core/sync.d.ts +0 -21
  207. package/dist/core/sync.mjs +0 -397
  208. package/dist/core/syncMeta.cjs +0 -242
  209. package/dist/core/syncMeta.d.ts +0 -75
  210. package/dist/core/syncMeta.mjs +0 -229
  211. package/dist/utils/dependencies.cjs +0 -57
  212. package/dist/utils/dependencies.d.ts +0 -10
  213. package/dist/utils/dependencies.mjs +0 -34
  214. package/dist/utils/nameTransform.cjs +0 -13
  215. package/dist/utils/nameTransform.d.ts +0 -65
  216. package/dist/utils/nameTransform.mjs +0 -11
  217. package/dist/utils/package.cjs +0 -170
  218. package/dist/utils/package.d.ts +0 -105
  219. package/dist/utils/package.mjs +0 -157
  220. package/dist/utils/packageName.cjs +0 -24
  221. package/dist/utils/packageName.d.ts +0 -32
  222. package/dist/utils/packageName.mjs +0 -21
  223. package/dist/utils/paths.cjs +0 -18
  224. package/dist/utils/paths.d.ts +0 -55
  225. package/dist/utils/paths.mjs +0 -15
  226. package/dist/version.cjs +0 -5
  227. package/dist/version.d.ts +0 -5
  228. package/dist/version.mjs +0 -3
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- var version = require('../version.cjs');
4
-
5
- const CLAUDE_BASE_DIR = '.claude';
6
- const DEFAULT_ASSET_PATH = 'docs/claude';
7
- const META_FILES = {
8
- SYNC_META: '.sync-meta.json',
9
- UNIFIED_SYNC_META: '.claude/.sync-meta.json',
10
- };
11
- const SCHEMA_VERSIONS = {
12
- UNIFIED_SYNC_META: version.VERSION,
13
- LEGACY_SYNC_META: '1.0.0',
14
- SKILL_UNIT_FORMAT: '2',
15
- };
16
- const DEFAULT_ASSET_TYPES = ['commands', 'skills', 'agents'];
17
- const FS_PATTERNS = {
18
- GITHUB_HTTPS_URL: /https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/,
19
- GITHUB_SSH_URL: /git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/,
20
- GITHUB_SHORTHAND: /^github:([^/]+)\/([^/]+)$/,
21
- };
22
-
23
- exports.CLAUDE_BASE_DIR = CLAUDE_BASE_DIR;
24
- exports.DEFAULT_ASSET_PATH = DEFAULT_ASSET_PATH;
25
- exports.DEFAULT_ASSET_TYPES = DEFAULT_ASSET_TYPES;
26
- exports.FS_PATTERNS = FS_PATTERNS;
27
- exports.META_FILES = META_FILES;
28
- exports.SCHEMA_VERSIONS = SCHEMA_VERSIONS;
@@ -1,94 +0,0 @@
1
- /**
2
- * Base directory for Claude assets
3
- */
4
- export declare const CLAUDE_BASE_DIR: ".claude";
5
- /**
6
- * Default asset path when claude.assetPath is not configured
7
- */
8
- export declare const DEFAULT_ASSET_PATH: "docs/claude";
9
- /**
10
- * Asset directory names
11
- */
12
- export declare const ASSET_DIRS: {
13
- readonly COMMANDS: "commands";
14
- readonly SKILLS: "skills";
15
- readonly AGENTS: "agents";
16
- };
17
- /**
18
- * Metadata file names
19
- */
20
- export declare const META_FILES: {
21
- readonly SYNC_META: ".sync-meta.json";
22
- readonly PROJECT_META: ".project-meta.json";
23
- readonly UNIFIED_SYNC_META: ".claude/.sync-meta.json";
24
- };
25
- /**
26
- * Schema versions for metadata files
27
- */
28
- export declare const SCHEMA_VERSIONS: {
29
- readonly UNIFIED_SYNC_META: "0.1.3";
30
- readonly LEGACY_SYNC_META: "1.0.0";
31
- readonly SKILL_UNIT_FORMAT: "2";
32
- };
33
- /**
34
- * Schema version for SkillUnit-based metadata format.
35
- * Separate from package VERSION to allow independent format evolution.
36
- * Used to detect whether migration from old format is needed.
37
- */
38
- export declare const SKILL_UNIT_SCHEMA_VERSION: "2";
39
- /**
40
- * Default asset types (exported for backward compatibility)
41
- */
42
- export declare const DEFAULT_ASSET_TYPES: readonly ["commands", "skills", "agents"];
43
- /**
44
- * Default structure configuration for built-in asset types
45
- *
46
- * @deprecated Import from './assetStructure' instead to avoid circular dependency.
47
- * This re-export will be removed in version 1.0.0
48
- *
49
- * @example
50
- * ```typescript
51
- * // ❌ Old (causes circular dependency)
52
- * import { DEFAULT_ASSET_STRUCTURES } from './constants';
53
- *
54
- * // ✅ New (recommended)
55
- * import { DEFAULT_ASSET_STRUCTURES } from './assetStructure';
56
- * ```
57
- */
58
- /**
59
- * GitHub API configuration
60
- */
61
- export declare const GITHUB_CONFIG: {
62
- readonly API_BASE: "https://api.github.com";
63
- readonly RAW_BASE: "https://raw.githubusercontent.com";
64
- readonly DEFAULT_REF: "HEAD";
65
- };
66
- /**
67
- * File system patterns
68
- */
69
- export declare const FS_PATTERNS: {
70
- readonly SCOPE_PACKAGE_REGEX: RegExp;
71
- readonly GITHUB_HTTPS_URL: RegExp;
72
- readonly GITHUB_SSH_URL: RegExp;
73
- readonly GITHUB_SHORTHAND: RegExp;
74
- };
75
- /**
76
- * CLI exit codes
77
- */
78
- export declare const EXIT_CODES: {
79
- readonly SUCCESS: 0;
80
- readonly GENERAL_ERROR: 1;
81
- readonly INVALID_ARGS: 2;
82
- readonly NO_PACKAGES: 3;
83
- };
84
- /**
85
- * Logging prefixes
86
- */
87
- export declare const LOG_PREFIXES: {
88
- readonly ERROR: "❌";
89
- readonly SUCCESS: "✓";
90
- readonly INFO: "ℹ";
91
- readonly WARNING: "⚠️";
92
- readonly DRY_RUN: "👀";
93
- readonly SKIP: "⏭️";
94
- };
@@ -1,21 +0,0 @@
1
- import { VERSION } from '../version.mjs';
2
-
3
- const CLAUDE_BASE_DIR = '.claude';
4
- const DEFAULT_ASSET_PATH = 'docs/claude';
5
- const META_FILES = {
6
- SYNC_META: '.sync-meta.json',
7
- UNIFIED_SYNC_META: '.claude/.sync-meta.json',
8
- };
9
- const SCHEMA_VERSIONS = {
10
- UNIFIED_SYNC_META: VERSION,
11
- LEGACY_SYNC_META: '1.0.0',
12
- SKILL_UNIT_FORMAT: '2',
13
- };
14
- const DEFAULT_ASSET_TYPES = ['commands', 'skills', 'agents'];
15
- const FS_PATTERNS = {
16
- GITHUB_HTTPS_URL: /https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/,
17
- GITHUB_SSH_URL: /git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/,
18
- GITHUB_SHORTHAND: /^github:([^/]+)\/([^/]+)$/,
19
- };
20
-
21
- export { CLAUDE_BASE_DIR, DEFAULT_ASSET_PATH, DEFAULT_ASSET_TYPES, FS_PATTERNS, META_FILES, SCHEMA_VERSIONS };
@@ -1,98 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('node:fs');
4
- var path = require('node:path');
5
- var paths = require('../utils/paths.cjs');
6
- var version = require('../utils/version.cjs');
7
- var constants = require('./constants.cjs');
8
- var io = require('./io.cjs');
9
-
10
- const writeFile = io.writeTextFile;
11
- const readSyncMeta = (cwd, packageName, assetType) => {
12
- const destDir = paths.getDestinationDir(cwd, packageName, assetType);
13
- const metaPath = path.join(destDir, constants.META_FILES.SYNC_META);
14
- return io.readJsonFile(metaPath);
15
- };
16
- const writeSyncMeta = (cwd, packageName, assetType, meta) => {
17
- const destDir = paths.getDestinationDir(cwd, packageName, assetType);
18
- const metaPath = path.join(destDir, constants.META_FILES.SYNC_META);
19
- io.writeJsonFile(metaPath, meta);
20
- };
21
- const writeAssetFile = (cwd, packageName, assetType, fileName, content) => {
22
- const destDir = paths.getDestinationDir(cwd, packageName, assetType);
23
- const filePath = path.join(destDir, fileName);
24
- writeFile(filePath, content);
25
- };
26
- const cleanAssetDir = (cwd, packageName, assetType) => {
27
- const destDir = paths.getDestinationDir(cwd, packageName, assetType);
28
- if (io.fileExists(destDir)) {
29
- fs.rmSync(destDir, { recursive: true, force: true });
30
- }
31
- };
32
- const needsSync = (cwd, packageName, version$1, assetTypes) => {
33
- const typesToCheck = assetTypes || [...constants.DEFAULT_ASSET_TYPES];
34
- const metadataByType = typesToCheck.map((assetType) => readSyncMeta(cwd, packageName, assetType));
35
- if (metadataByType.every((meta) => !meta))
36
- return true;
37
- if (metadataByType.some((meta) => meta && version.needsVersionSync(version$1, meta.version))) {
38
- return true;
39
- }
40
- return false;
41
- };
42
- const createSyncMeta = (version, files) => ({
43
- version,
44
- syncedAt: new Date().toISOString(),
45
- files,
46
- });
47
- const writeFlatAssetFile = (cwd, assetType, flatFileName, content) => {
48
- const destDir = paths.getFlatDestinationDir(cwd, assetType);
49
- const filePath = path.join(destDir, flatFileName);
50
- writeFile(filePath, content);
51
- };
52
- const cleanFlatAssetFiles = (cwd, assetType, prefix, existingMeta) => {
53
- const destDir = paths.getFlatDestinationDir(cwd, assetType);
54
- if (!io.fileExists(destDir)) {
55
- return;
56
- }
57
- if (existingMeta?.packages[prefix]) {
58
- const packageInfo = existingMeta.packages[prefix];
59
- const filesToRemove = packageInfo.files[assetType];
60
- if (Array.isArray(filesToRemove)) {
61
- for (const unit of filesToRemove) {
62
- const fileName = unit.transformed ?? unit.name;
63
- if (unit.isDirectory) {
64
- const dirPath = path.join(destDir, fileName);
65
- if (io.fileExists(dirPath)) {
66
- fs.rmSync(dirPath, { recursive: true, force: true });
67
- }
68
- }
69
- else {
70
- const filePath = path.join(destDir, fileName);
71
- if (io.fileExists(filePath)) {
72
- fs.rmSync(filePath, { force: true });
73
- }
74
- }
75
- }
76
- }
77
- }
78
- else {
79
- const pattern = `${prefix}_`;
80
- const entries = io.listDirectory(destDir);
81
- for (const entry of entries) {
82
- if (entry.startsWith(pattern)) {
83
- const entryPath = path.join(destDir, entry);
84
- fs.rmSync(entryPath, { recursive: true, force: true });
85
- }
86
- }
87
- }
88
- };
89
-
90
- exports.cleanAssetDir = cleanAssetDir;
91
- exports.cleanFlatAssetFiles = cleanFlatAssetFiles;
92
- exports.createSyncMeta = createSyncMeta;
93
- exports.needsSync = needsSync;
94
- exports.readSyncMeta = readSyncMeta;
95
- exports.writeAssetFile = writeAssetFile;
96
- exports.writeFile = writeFile;
97
- exports.writeFlatAssetFile = writeFlatAssetFile;
98
- exports.writeSyncMeta = writeSyncMeta;
@@ -1,94 +0,0 @@
1
- import type { AssetType, SyncMeta, UnifiedSyncMeta } from '../utils/types.js';
2
- import { ensureDirectory, writeTextFile } from './io';
3
- /**
4
- * Ensure directory exists (creates recursively if needed)
5
- * @param dirPath - Directory path
6
- */
7
- export declare const ensureDir: typeof ensureDirectory;
8
- /**
9
- * Write file with directory creation
10
- * @param filePath - Full file path
11
- * @param content - File content
12
- */
13
- export declare const writeFile: typeof writeTextFile;
14
- /**
15
- * Read sync metadata file
16
- * @param cwd - Current working directory
17
- * @param packageName - Package name
18
- * @param assetType - Asset type
19
- * @returns SyncMeta or null if not found
20
- */
21
- export declare const readSyncMeta: (cwd: string, packageName: string, assetType: AssetType) => SyncMeta | null;
22
- /**
23
- * Write sync metadata file
24
- * @param cwd - Current working directory
25
- * @param packageName - Package name
26
- * @param assetType - Asset type
27
- * @param meta - Sync metadata
28
- */
29
- export declare const writeSyncMeta: (cwd: string, packageName: string, assetType: AssetType, meta: SyncMeta) => void;
30
- /**
31
- * Write asset file to destination
32
- * @param cwd - Current working directory
33
- * @param packageName - Package name
34
- * @param assetType - Asset type
35
- * @param fileName - File name
36
- * @param content - File content
37
- */
38
- export declare const writeAssetFile: (cwd: string, packageName: string, assetType: AssetType, fileName: string, content: string) => void;
39
- /**
40
- * Clean existing synced files for a package
41
- * @param cwd - Current working directory
42
- * @param packageName - Package name
43
- * @param assetType - Asset type
44
- */
45
- export declare const cleanAssetDir: (cwd: string, packageName: string, assetType: AssetType) => void;
46
- /**
47
- * Check if package assets need sync (version mismatch)
48
- * @param cwd - Current working directory
49
- * @param packageName - Package name
50
- * @param version - Current package version
51
- * @param assetTypes - Optional array of asset types to check. If not provided, uses default types.
52
- * @returns true if sync is needed
53
- */
54
- export declare const needsSync: (cwd: string, packageName: string, version: string, assetTypes?: string[]) => boolean;
55
- /**
56
- * Create SyncMeta object for current sync operation
57
- * @param version - Package version
58
- * @param files - List of synced file names
59
- * @returns SyncMeta object
60
- */
61
- export declare const createSyncMeta: (version: string, files: string[]) => SyncMeta;
62
- /**
63
- * Write asset file to flat structure destination
64
- * @param cwd - Current working directory
65
- * @param assetType - Asset type (commands or skills)
66
- * @param flatFileName - Flat file name with prefix (e.g., "canard-schemaForm_guide.md")
67
- * @param content - File content
68
- * @example
69
- * writeFlatAssetFile(cwd, 'commands', 'canard-schemaForm_guide.md', content)
70
- */
71
- export declare const writeFlatAssetFile: (cwd: string, assetType: AssetType, flatFileName: string, content: string) => void;
72
- /**
73
- * Clean flat asset files with specific prefix
74
- * Removes only files belonging to the specified package, preserving others.
75
- * Handles both single flat files (prefix_file.md) and directory-based skills (prefix_dir/).
76
- * @param cwd - Current working directory
77
- * @param assetType - Asset type (commands, skills, agents, or any custom string)
78
- * @param prefix - Package prefix (e.g., "canard-schemaForm")
79
- * @param existingMeta - Existing unified metadata to identify exact files to remove
80
- * @example
81
- * cleanFlatAssetFiles(cwd, 'commands', 'canard-schemaForm', meta)
82
- */
83
- export declare const cleanFlatAssetFiles: (cwd: string, assetType: AssetType, prefix: string, existingMeta: UnifiedSyncMeta | null) => void;
84
- /**
85
- * List flat asset files with specific prefix
86
- * @param cwd - Current working directory
87
- * @param assetType - Asset type (commands or skills)
88
- * @param prefix - Package prefix (e.g., "canard-schemaForm")
89
- * @returns Array of file names matching the pattern
90
- * @example
91
- * listFlatAssetFiles(cwd, 'commands', 'canard-schemaForm')
92
- * // => ['canard-schemaForm_guide.md', 'canard-schemaForm_usage.md']
93
- */
94
- export declare const listFlatAssetFiles: (cwd: string, assetType: AssetType, prefix: string) => string[];
@@ -1,88 +0,0 @@
1
- import { rmSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { getFlatDestinationDir, getDestinationDir } from '../utils/paths.mjs';
4
- import { needsVersionSync } from '../utils/version.mjs';
5
- import { DEFAULT_ASSET_TYPES, META_FILES } from './constants.mjs';
6
- import { writeTextFile, fileExists, listDirectory, writeJsonFile, readJsonFile } from './io.mjs';
7
-
8
- const writeFile = writeTextFile;
9
- const readSyncMeta = (cwd, packageName, assetType) => {
10
- const destDir = getDestinationDir(cwd, packageName, assetType);
11
- const metaPath = join(destDir, META_FILES.SYNC_META);
12
- return readJsonFile(metaPath);
13
- };
14
- const writeSyncMeta = (cwd, packageName, assetType, meta) => {
15
- const destDir = getDestinationDir(cwd, packageName, assetType);
16
- const metaPath = join(destDir, META_FILES.SYNC_META);
17
- writeJsonFile(metaPath, meta);
18
- };
19
- const writeAssetFile = (cwd, packageName, assetType, fileName, content) => {
20
- const destDir = getDestinationDir(cwd, packageName, assetType);
21
- const filePath = join(destDir, fileName);
22
- writeFile(filePath, content);
23
- };
24
- const cleanAssetDir = (cwd, packageName, assetType) => {
25
- const destDir = getDestinationDir(cwd, packageName, assetType);
26
- if (fileExists(destDir)) {
27
- rmSync(destDir, { recursive: true, force: true });
28
- }
29
- };
30
- const needsSync = (cwd, packageName, version, assetTypes) => {
31
- const typesToCheck = assetTypes || [...DEFAULT_ASSET_TYPES];
32
- const metadataByType = typesToCheck.map((assetType) => readSyncMeta(cwd, packageName, assetType));
33
- if (metadataByType.every((meta) => !meta))
34
- return true;
35
- if (metadataByType.some((meta) => meta && needsVersionSync(version, meta.version))) {
36
- return true;
37
- }
38
- return false;
39
- };
40
- const createSyncMeta = (version, files) => ({
41
- version,
42
- syncedAt: new Date().toISOString(),
43
- files,
44
- });
45
- const writeFlatAssetFile = (cwd, assetType, flatFileName, content) => {
46
- const destDir = getFlatDestinationDir(cwd, assetType);
47
- const filePath = join(destDir, flatFileName);
48
- writeFile(filePath, content);
49
- };
50
- const cleanFlatAssetFiles = (cwd, assetType, prefix, existingMeta) => {
51
- const destDir = getFlatDestinationDir(cwd, assetType);
52
- if (!fileExists(destDir)) {
53
- return;
54
- }
55
- if (existingMeta?.packages[prefix]) {
56
- const packageInfo = existingMeta.packages[prefix];
57
- const filesToRemove = packageInfo.files[assetType];
58
- if (Array.isArray(filesToRemove)) {
59
- for (const unit of filesToRemove) {
60
- const fileName = unit.transformed ?? unit.name;
61
- if (unit.isDirectory) {
62
- const dirPath = join(destDir, fileName);
63
- if (fileExists(dirPath)) {
64
- rmSync(dirPath, { recursive: true, force: true });
65
- }
66
- }
67
- else {
68
- const filePath = join(destDir, fileName);
69
- if (fileExists(filePath)) {
70
- rmSync(filePath, { force: true });
71
- }
72
- }
73
- }
74
- }
75
- }
76
- else {
77
- const pattern = `${prefix}_`;
78
- const entries = listDirectory(destDir);
79
- for (const entry of entries) {
80
- if (entry.startsWith(pattern)) {
81
- const entryPath = join(destDir, entry);
82
- rmSync(entryPath, { recursive: true, force: true });
83
- }
84
- }
85
- }
86
- };
87
-
88
- export { cleanAssetDir, cleanFlatAssetFiles, createSyncMeta, needsSync, readSyncMeta, writeAssetFile, writeFile, writeFlatAssetFile, writeSyncMeta };
@@ -1,115 +0,0 @@
1
- 'use strict';
2
-
3
- class RateLimitError extends Error {
4
- constructor() {
5
- super('GitHub API rate limit exceeded. Set GITHUB_TOKEN environment variable to increase the limit.');
6
- this.name = 'RateLimitError';
7
- }
8
- }
9
- class NotFoundError extends Error {
10
- constructor(resource) {
11
- super(`GitHub resource not found: ${resource}`);
12
- this.name = 'NotFoundError';
13
- }
14
- }
15
- const getHeaders = () => {
16
- const headers = {
17
- Accept: 'application/vnd.github.v3+json',
18
- 'User-Agent': 'claude-assets-sync',
19
- };
20
- const token = process.env.GITHUB_TOKEN;
21
- if (token)
22
- headers.Authorization = `Bearer ${token}`;
23
- return headers;
24
- };
25
- const fetchDirectoryContents = async (repoInfo, path, tag) => {
26
- const url = `https://api.github.com/repos/${repoInfo.owner}/${repoInfo.repo}/contents/${path}?ref=${encodeURIComponent(tag)}`;
27
- const response = await fetch(url, {
28
- headers: getHeaders(),
29
- });
30
- if (response.status === 403) {
31
- const remaining = response.headers.get('x-ratelimit-remaining');
32
- if (remaining === '0')
33
- throw new RateLimitError();
34
- }
35
- if (response.status === 404)
36
- return null;
37
- if (!response.ok)
38
- throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
39
- const data = await response.json();
40
- return data.filter((entry) => (entry.type === 'file' && entry.name.endsWith('.md')) ||
41
- entry.type === 'dir');
42
- };
43
- const expandDirectoryEntries = async (repoInfo, parentPath, entries, tag, prefix = '') => {
44
- const result = [];
45
- for (const entry of entries) {
46
- const entryPrefix = prefix ? `${prefix}/${entry.name}` : entry.name;
47
- if (entry.type === 'file') {
48
- result.push({
49
- ...entry,
50
- name: prefix ? entryPrefix : entry.name,
51
- });
52
- }
53
- else if (entry.type === 'dir') {
54
- const subEntries = await fetchDirectoryContents(repoInfo, `${parentPath}/${entry.name}`, tag);
55
- if (subEntries) {
56
- const expanded = await expandDirectoryEntries(repoInfo, `${parentPath}/${entry.name}`, subEntries, tag, entryPrefix);
57
- result.push(...expanded);
58
- }
59
- }
60
- }
61
- return result;
62
- };
63
- const fetchAssetFiles = async (repoInfo, assetPath, tag, assetTypes) => {
64
- const basePath = repoInfo.directory
65
- ? `${repoInfo.directory}/${assetPath}`
66
- : assetPath;
67
- const fetchPromises = assetTypes.map((assetType) => fetchDirectoryContents(repoInfo, `${basePath}/${assetType}`, tag));
68
- const rawResults = await Promise.all(fetchPromises);
69
- const expandedResults = await Promise.all(rawResults.map((entries, index) => {
70
- if (!entries)
71
- return Promise.resolve([]);
72
- const assetDirPath = `${basePath}/${assetTypes[index]}`;
73
- return expandDirectoryEntries(repoInfo, assetDirPath, entries, tag);
74
- }));
75
- const assetFiles = {};
76
- assetTypes.forEach((assetType, index) => {
77
- assetFiles[assetType] = expandedResults[index] || [];
78
- });
79
- return assetFiles;
80
- };
81
- const downloadFile = async (repoInfo, filePath, tag) => {
82
- const url = `https://raw.githubusercontent.com/${repoInfo.owner}/${repoInfo.repo}/${encodeURIComponent(tag)}/${filePath}`;
83
- const response = await fetch(url, {
84
- headers: {
85
- 'User-Agent': 'claude-assets-sync',
86
- },
87
- });
88
- if (response.status === 404) {
89
- throw new NotFoundError(filePath);
90
- }
91
- if (!response.ok) {
92
- throw new Error(`Failed to download file: ${response.status} ${response.statusText}`);
93
- }
94
- return response.text();
95
- };
96
- const downloadAssetFiles = async (repoInfo, assetPath, assetType, entries, tag) => {
97
- const basePath = repoInfo.directory
98
- ? `${repoInfo.directory}/${assetPath}/${assetType}`
99
- : `${assetPath}/${assetType}`;
100
- const results = new Map();
101
- for (const entry of entries) {
102
- const filePath = `${basePath}/${entry.name}`;
103
- const content = await downloadFile(repoInfo, filePath, tag);
104
- results.set(entry.name, content);
105
- }
106
- return results;
107
- };
108
-
109
- exports.NotFoundError = NotFoundError;
110
- exports.RateLimitError = RateLimitError;
111
- exports.downloadAssetFiles = downloadAssetFiles;
112
- exports.downloadFile = downloadFile;
113
- exports.expandDirectoryEntries = expandDirectoryEntries;
114
- exports.fetchAssetFiles = fetchAssetFiles;
115
- exports.fetchDirectoryContents = fetchDirectoryContents;
@@ -1,61 +0,0 @@
1
- import type { AssetType, GitHubEntry, GitHubRepoInfo } from '../utils/types.js';
2
- /**
3
- * Error thrown when GitHub API rate limit is exceeded
4
- */
5
- export declare class RateLimitError extends Error {
6
- constructor();
7
- }
8
- /**
9
- * Error thrown when GitHub resource is not found
10
- */
11
- export declare class NotFoundError extends Error {
12
- constructor(resource: string);
13
- }
14
- /**
15
- * Fetch directory contents from GitHub API
16
- * @param repoInfo - GitHub repository information
17
- * @param path - Path to the directory
18
- * @param tag - Git tag or ref to fetch from
19
- * @returns Array of GitHubEntry or null if directory doesn't exist
20
- */
21
- export declare const fetchDirectoryContents: (repoInfo: GitHubRepoInfo, path: string, tag: string) => Promise<GitHubEntry[] | null>;
22
- /**
23
- * Expand directory entries into flat file entries with recursive traversal.
24
- * Fetches contents of each directory and prefixes file names with the directory path.
25
- * Recursively traverses subdirectories to collect all nested files.
26
- *
27
- * @param repoInfo - GitHub repository information
28
- * @param parentPath - Parent directory path in the repository
29
- * @param entries - Array of GitHubEntry (may contain both file and dir types)
30
- * @param tag - Git tag or ref to fetch from
31
- * @param prefix - Accumulated path prefix for nested entries
32
- * @returns Flat array of file GitHubEntry with dir-prefixed names
33
- */
34
- export declare const expandDirectoryEntries: (repoInfo: GitHubRepoInfo, parentPath: string, entries: GitHubEntry[], tag: string, prefix?: string) => Promise<GitHubEntry[]>;
35
- /**
36
- * Fetch asset files dynamically from GitHub
37
- * @param repoInfo - GitHub repository information
38
- * @param assetPath - Base path to Claude assets (e.g., "docs/claude")
39
- * @param tag - Git tag or ref to fetch from
40
- * @param assetTypes - Array of asset type names to fetch
41
- * @returns Record mapping asset type names to their GitHubEntry arrays
42
- */
43
- export declare const fetchAssetFiles: (repoInfo: GitHubRepoInfo, assetPath: string, tag: string, assetTypes: string[]) => Promise<Record<string, GitHubEntry[]>>;
44
- /**
45
- * Download file content from raw.githubusercontent.com
46
- * @param repoInfo - GitHub repository information
47
- * @param filePath - Full path to the file
48
- * @param tag - Git tag or ref
49
- * @returns File content as string
50
- */
51
- export declare const downloadFile: (repoInfo: GitHubRepoInfo, filePath: string, tag: string) => Promise<string>;
52
- /**
53
- * Download multiple files from a specific asset type
54
- * @param repoInfo - GitHub repository information
55
- * @param assetPath - Base path to Claude assets
56
- * @param assetType - Type of asset (commands or skills)
57
- * @param entries - Array of GitHubEntry to download
58
- * @param tag - Git tag or ref
59
- * @returns Map of filename to content
60
- */
61
- export declare const downloadAssetFiles: (repoInfo: GitHubRepoInfo, assetPath: string, assetType: AssetType, entries: GitHubEntry[], tag: string) => Promise<Map<string, string>>;