@openreachtech/hora-skills-ort-renchan 0.0.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 (126) hide show
  1. package/LICENSE +201 -0
  2. package/README.ja.md +135 -0
  3. package/README.md +135 -0
  4. package/dist/skills/hor-agent-loop/SKILL.md +123 -0
  5. package/dist/skills/hor-agent-loop/references/core.md +485 -0
  6. package/dist/skills/hor-agent-loop/references/graphql-integration.md +178 -0
  7. package/dist/skills/hor-agent-loop/references/renchan-job-integration.md +368 -0
  8. package/dist/skills/hor-agent-loop/references/testing.md +492 -0
  9. package/dist/skills/hor-ai-agent-structure/SKILL.md +403 -0
  10. package/dist/skills/hor-ai-agent-structure/references/loop-and-actions.md +100 -0
  11. package/dist/skills/hor-ai-prompt-document-store/SKILL.md +220 -0
  12. package/dist/skills/hor-ai-prompt-document-store/references/models-and-composition.md +156 -0
  13. package/dist/skills/hor-backend-testing/SKILL.md +118 -0
  14. package/dist/skills/hor-backend-testing/references/placement-and-ordering.md +89 -0
  15. package/dist/skills/hor-backend-testing/references/purity-and-mocks.md +82 -0
  16. package/dist/skills/hor-backend-testing/references/running-tests.md +186 -0
  17. package/dist/skills/hor-bank-id/SKILL.md +91 -0
  18. package/dist/skills/hor-build-e2e-test-environment/SKILL.md +609 -0
  19. package/dist/skills/hor-build-e2e-test-environment/references/compose-definition.md +368 -0
  20. package/dist/skills/hor-build-e2e-test-environment/references/edge-and-proxy.md +287 -0
  21. package/dist/skills/hor-build-e2e-test-environment/references/environment-and-ports.md +201 -0
  22. package/dist/skills/hor-build-e2e-test-environment/references/runner-and-lifecycle.md +330 -0
  23. package/dist/skills/hor-build-e2e-test-environment/references/seed-data.md +145 -0
  24. package/dist/skills/hor-build-e2e-test-environment/references/windows-runner.md +146 -0
  25. package/dist/skills/hor-constant-definition/SKILL.md +139 -0
  26. package/dist/skills/hor-cookie-authentication/SKILL.md +33 -0
  27. package/dist/skills/hor-cookie-authentication/references/auth-filter.md +55 -0
  28. package/dist/skills/hor-cookie-authentication/references/cookie-context.md +53 -0
  29. package/dist/skills/hor-cookie-authentication/references/dev-login-seeder.md +22 -0
  30. package/dist/skills/hor-cookie-authentication/references/environment.md +64 -0
  31. package/dist/skills/hor-cookie-authentication/references/error-codes.md +24 -0
  32. package/dist/skills/hor-cookie-authentication/references/migrations.md +18 -0
  33. package/dist/skills/hor-cookie-authentication/references/resolvers.md +97 -0
  34. package/dist/skills/hor-cookie-authentication/references/session-clerk.md +41 -0
  35. package/dist/skills/hor-cookie-authentication/references/token-models.md +125 -0
  36. package/dist/skills/hor-database-design/SKILL.md +54 -0
  37. package/dist/skills/hor-database-design/references/column-types.md +92 -0
  38. package/dist/skills/hor-database-design/references/datetimes.md +88 -0
  39. package/dist/skills/hor-database-design/references/master-tables.md +117 -0
  40. package/dist/skills/hor-database-design/references/normalization.md +40 -0
  41. package/dist/skills/hor-database-design/references/update-history.md +35 -0
  42. package/dist/skills/hor-execution-placement-pattern/SKILL.md +216 -0
  43. package/dist/skills/hor-external-api-client/SKILL.md +99 -0
  44. package/dist/skills/hor-external-api-client/references/architecture.md +127 -0
  45. package/dist/skills/hor-external-api-client/references/authorization.md +105 -0
  46. package/dist/skills/hor-external-api-client/references/capsule.md +130 -0
  47. package/dist/skills/hor-external-api-client/references/conventions.md +68 -0
  48. package/dist/skills/hor-external-api-client/references/launcher.md +138 -0
  49. package/dist/skills/hor-external-api-client/references/payload.md +176 -0
  50. package/dist/skills/hor-external-api-client/references/sdk-wrapper.md +291 -0
  51. package/dist/skills/hor-external-api-client/references/testing.md +130 -0
  52. package/dist/skills/hor-external-api-client/references/usage.md +152 -0
  53. package/dist/skills/hor-graphql-schema/SKILL.md +360 -0
  54. package/dist/skills/hor-graphql-server-engine/SKILL.md +356 -0
  55. package/dist/skills/hor-light-rag/SKILL.md +242 -0
  56. package/dist/skills/hor-light-rag/references/retrieval-internals.md +143 -0
  57. package/dist/skills/hor-multi-llm-provider/SKILL.md +288 -0
  58. package/dist/skills/hor-multi-llm-provider/references/provider-internals.md +153 -0
  59. package/dist/skills/hor-mutation-resolver/SKILL.md +360 -0
  60. package/dist/skills/hor-mutation-resolver/references/dependency-injection.md +148 -0
  61. package/dist/skills/hor-mutation-resolver/references/errors.md +120 -0
  62. package/dist/skills/hor-mutation-resolver/references/resolve-flow.md +275 -0
  63. package/dist/skills/hor-mutation-resolver/references/testing.md +125 -0
  64. package/dist/skills/hor-mutation-resolver/references/transaction.md +197 -0
  65. package/dist/skills/hor-post-worker/SKILL.md +320 -0
  66. package/dist/skills/hor-query-resolver/SKILL.md +246 -0
  67. package/dist/skills/hor-query-resolver/references/anatomy.md +384 -0
  68. package/dist/skills/hor-query-resolver/references/data-access.md +248 -0
  69. package/dist/skills/hor-query-resolver/references/errors-and-context.md +172 -0
  70. package/dist/skills/hor-query-resolver/references/testing.md +241 -0
  71. package/dist/skills/hor-renchan-job-bullmq/SKILL.md +178 -0
  72. package/dist/skills/hor-renchan-job-bullmq/references/daemon-and-scheduler.md +182 -0
  73. package/dist/skills/hor-renchan-job-bullmq/references/engine-and-infra.md +106 -0
  74. package/dist/skills/hor-renchan-job-bullmq/references/job-triple.md +189 -0
  75. package/dist/skills/hor-renchan-job-bullmq/references/queues.md +74 -0
  76. package/dist/skills/hor-renchan-job-bullmq/references/subscriptions.md +113 -0
  77. package/dist/skills/hor-resolver-share/SKILL.md +262 -0
  78. package/dist/skills/hor-resolver-validator/SKILL.md +194 -0
  79. package/dist/skills/hor-resolver-validator/references/inspector-api.md +115 -0
  80. package/dist/skills/hor-resolver-validator/references/validator-pattern.md +281 -0
  81. package/dist/skills/hor-restfulapi-architecture/SKILL.md +275 -0
  82. package/dist/skills/hor-restfulapi-architecture/references/engine-and-context.md +192 -0
  83. package/dist/skills/hor-restfulapi-architecture/references/renderers.md +204 -0
  84. package/dist/skills/hor-restfulapi-architecture/references/response-and-flusher.md +118 -0
  85. package/dist/skills/hor-restfulapi-architecture/references/validation.md +229 -0
  86. package/dist/skills/hor-security-audit/SKILL.md +110 -0
  87. package/dist/skills/hor-security-audit/references/application-surface.md +90 -0
  88. package/dist/skills/hor-security-audit/references/auth-and-transport.md +147 -0
  89. package/dist/skills/hor-security-audit/references/code-safety.md +74 -0
  90. package/dist/skills/hor-security-audit/references/dependencies.md +72 -0
  91. package/dist/skills/hor-security-audit/references/network-and-logging.md +56 -0
  92. package/dist/skills/hor-security-audit/references/secrets.md +95 -0
  93. package/dist/skills/hor-sequelize-migration/SKILL.md +336 -0
  94. package/dist/skills/hor-sequelize-migration/references/alter-table.md +147 -0
  95. package/dist/skills/hor-sequelize-migration/references/foreign-keys.md +107 -0
  96. package/dist/skills/hor-sequelize-migration/references/indexes.md +149 -0
  97. package/dist/skills/hor-sequelize-migration/references/notation.md +215 -0
  98. package/dist/skills/hor-sequelize-model/SKILL.md +69 -0
  99. package/dist/skills/hor-sequelize-model/references/associations.md +218 -0
  100. package/dist/skills/hor-sequelize-model/references/default-methods.md +244 -0
  101. package/dist/skills/hor-sequelize-model/references/mixins.md +247 -0
  102. package/dist/skills/hor-sequelize-model/references/notation.md +225 -0
  103. package/dist/skills/hor-sequelize-model/references/timestamps.md +74 -0
  104. package/dist/skills/hor-sequelize-seeder/SKILL.md +275 -0
  105. package/dist/skills/hor-sequelize-seeder/references/development-coverage.md +74 -0
  106. package/dist/skills/hor-sequelize-seeder/references/directory-structure.md +113 -0
  107. package/dist/skills/hor-sequelize-seeder/references/id-numbering.md +133 -0
  108. package/dist/skills/hor-sequelize-seeder/references/naming.md +59 -0
  109. package/dist/skills/hor-sequelize-seeder/references/notation.md +170 -0
  110. package/dist/skills/hor-sequelize-subquery/SKILL.md +369 -0
  111. package/dist/skills/hor-strategy-pattern/SKILL.md +371 -0
  112. package/dist/skills/hor-stub-api/SKILL.md +330 -0
  113. package/dist/skills/hor-subscription-resolver/SKILL.md +105 -0
  114. package/dist/skills/hor-subscription-resolver/references/authentication.md +99 -0
  115. package/dist/skills/hor-subscription-resolver/references/basic-notation.md +116 -0
  116. package/dist/skills/hor-subscription-resolver/references/design-philosophy.md +68 -0
  117. package/dist/skills/hor-type-interface/SKILL.md +200 -0
  118. package/docs/skills.ja.md +40 -0
  119. package/docs/skills.md +40 -0
  120. package/lib/equip/CommandLineArguments.js +178 -0
  121. package/lib/equip/HoraSkillsCli.js +590 -0
  122. package/lib/equip/SkillsInstaller.js +443 -0
  123. package/lib/equip/SkillsManifestFile.js +260 -0
  124. package/lib/equip/constants/CLI_COMMAND.js +8 -0
  125. package/lib/equip/hora-skills-ort-renchan.js +8 -0
  126. package/package.json +51 -0
@@ -0,0 +1,443 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+
5
+ import SkillsManifestFile from './SkillsManifestFile.js'
6
+
7
+ /**
8
+ * Installer that copies the distributed skills into a consuming repository.
9
+ *
10
+ * One run replaces what the previous run wrote: the skills recorded in the manifest,
11
+ * along with the folders named after a distributed skill, are removed first, then the
12
+ * distributed skills are copied and recorded again.
13
+ *
14
+ * A folder named after nothing this package distributes, and recorded by no previous
15
+ * run, is never removed — that is what keeps a skill the consuming repository authored
16
+ * out of the way of an installation, including the very first one.
17
+ */
18
+ export default class SkillsInstaller {
19
+ /**
20
+ * Constructor.
21
+ *
22
+ * @param {{
23
+ * sourceDirectoryPath: string
24
+ * targetDirectoryPath: string
25
+ * manifestFile: SkillsManifestFile
26
+ * }} params - Parameters.
27
+ */
28
+ constructor ({
29
+ sourceDirectoryPath,
30
+ targetDirectoryPath,
31
+ manifestFile,
32
+ }) {
33
+ this.sourceDirectoryPath = sourceDirectoryPath
34
+ this.targetDirectoryPath = targetDirectoryPath
35
+ this.manifestFile = manifestFile
36
+ }
37
+
38
+ /**
39
+ * Factory method.
40
+ *
41
+ * @template {X extends typeof SkillsInstaller ? X : never} T, X
42
+ * @param {{
43
+ * workingDirectoryPath: string
44
+ * targetDirectoryPath: string
45
+ * sourceDirectoryPath?: string
46
+ * }} params - Parameters for the factory method.
47
+ * @returns {InstanceType<T>} Instance of this class.
48
+ * @this {T}
49
+ * @public
50
+ */
51
+ static create ({
52
+ workingDirectoryPath,
53
+ targetDirectoryPath,
54
+ sourceDirectoryPath = this.buildDefaultSourceDirectoryPath(),
55
+ }) {
56
+ const manifestFile = this.createSkillsManifestFile({
57
+ workingDirectoryPath,
58
+ targetDirectoryPath,
59
+ })
60
+
61
+ return new this({
62
+ sourceDirectoryPath,
63
+ targetDirectoryPath,
64
+ manifestFile,
65
+ })
66
+ }
67
+
68
+ /**
69
+ * Constructor of the manifest file.
70
+ *
71
+ * @returns {typeof SkillsManifestFile} Constructor of the manifest file.
72
+ */
73
+ static get SkillsManifestFileCtor () {
74
+ return SkillsManifestFile
75
+ }
76
+
77
+ /**
78
+ * Path segments of the manifest, relative to the working directory.
79
+ *
80
+ * The manifest belongs to this package rather than to Claude Code, so it is kept
81
+ * out of the installation directory and placed under a directory of its own.
82
+ *
83
+ * It is named after this package, so that the sibling skill libraries installing into
84
+ * one repository each record their own installation instead of one overwriting another.
85
+ *
86
+ * @returns {Array<string>} Path segments of the manifest.
87
+ */
88
+ static get manifestPathSegments () {
89
+ return [
90
+ '.hora',
91
+ 'hora-skills-ort-renchan.json',
92
+ ]
93
+ }
94
+
95
+ /**
96
+ * Build the path of the distributed skills shipped inside this package.
97
+ *
98
+ * @returns {string} Absolute path of `dist/skills/`.
99
+ */
100
+ static buildDefaultSourceDirectoryPath () {
101
+ return fileURLToPath(
102
+ new URL('../../dist/skills/', import.meta.url)
103
+ )
104
+ }
105
+
106
+ /**
107
+ * Create the manifest file recording the installation into the target directory.
108
+ *
109
+ * @param {{
110
+ * workingDirectoryPath: string
111
+ * targetDirectoryPath: string
112
+ * }} params - Parameters.
113
+ * @returns {SkillsManifestFile} Manifest file of the working directory.
114
+ */
115
+ static createSkillsManifestFile ({
116
+ workingDirectoryPath,
117
+ targetDirectoryPath,
118
+ }) {
119
+ return this.SkillsManifestFileCtor.create({
120
+ filePath: path.join(
121
+ workingDirectoryPath,
122
+ ...this.manifestPathSegments
123
+ ),
124
+ installationPath: this.buildInstallationPath({
125
+ workingDirectoryPath,
126
+ targetDirectoryPath,
127
+ }),
128
+ })
129
+ }
130
+
131
+ /**
132
+ * Build the key an installation is recorded under.
133
+ *
134
+ * The path is relative to the working directory and uses forward slashes, so that
135
+ * the same installation is recorded under one key on every platform.
136
+ *
137
+ * @param {{
138
+ * workingDirectoryPath: string
139
+ * targetDirectoryPath: string
140
+ * }} params - Parameters.
141
+ * @returns {string} Key of the installation.
142
+ */
143
+ static buildInstallationPath ({
144
+ workingDirectoryPath,
145
+ targetDirectoryPath,
146
+ }) {
147
+ return path.relative(
148
+ workingDirectoryPath,
149
+ targetDirectoryPath
150
+ )
151
+ .split(path.sep)
152
+ .join('/')
153
+ }
154
+
155
+ /**
156
+ * Tell whether a skill name addresses a folder directly inside an installation directory.
157
+ *
158
+ * A skill name is one name of one folder, so it never carries a path. Reading one that
159
+ * does would let a manifest of the consuming repository name a path outside the
160
+ * installation directory, and a removal follows what the manifest names.
161
+ *
162
+ * The separators of both platforms are refused, rather than the one this platform uses,
163
+ * so that a manifest written on either is read the same way on either.
164
+ *
165
+ * @param {{
166
+ * skillName: string
167
+ * }} params - Parameters.
168
+ * @returns {boolean} Whether the skill name addresses a folder of an installation directory.
169
+ * @public
170
+ */
171
+ static isPlainSkillName ({
172
+ skillName,
173
+ }) {
174
+ return skillName !== ''
175
+ && skillName !== '.'
176
+ && skillName !== '..'
177
+ && !skillName.includes('/')
178
+ && !skillName.includes('\\')
179
+ }
180
+
181
+ /**
182
+ * Constructor of this instance.
183
+ *
184
+ * @returns {typeof SkillsInstaller} Constructor of this instance.
185
+ */
186
+ get Ctor () {
187
+ return /** @type {typeof SkillsInstaller} */ (this.constructor)
188
+ }
189
+
190
+ /**
191
+ * Node file system module.
192
+ *
193
+ * @returns {typeof fs} Node file system module.
194
+ */
195
+ get fs () {
196
+ return fs
197
+ }
198
+
199
+ /**
200
+ * Node path module.
201
+ *
202
+ * @returns {typeof path} Node path module.
203
+ */
204
+ get path () {
205
+ return path
206
+ }
207
+
208
+ /**
209
+ * Install the selected skills, replacing whatever the previous run installed.
210
+ *
211
+ * @returns {{
212
+ * installedSkillNames: Array<string>
213
+ * removedSkillNames: Array<string>
214
+ * }} Skill folder names installed and removed by this run.
215
+ * @public
216
+ */
217
+ install () {
218
+ const removedSkillNames = this.removeInstalledSkills()
219
+ const installedSkillNames = this.copyDistributedSkills()
220
+
221
+ this.saveManifest({
222
+ skillNames: installedSkillNames,
223
+ })
224
+
225
+ return {
226
+ installedSkillNames,
227
+ removedSkillNames,
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Remove the skills the previous run installed.
233
+ *
234
+ * @returns {Array<string>} Removed skill folder names.
235
+ */
236
+ removeInstalledSkills () {
237
+ const skillNames = this.collectRemovableSkillNames()
238
+
239
+ skillNames.forEach(it => {
240
+ this.fs.rmSync(
241
+ this.buildTargetSkillPath({ skillName: it }),
242
+ {
243
+ recursive: true,
244
+ force: true,
245
+ }
246
+ )
247
+ })
248
+
249
+ return skillNames
250
+ }
251
+
252
+ /**
253
+ * Collect the skill folder names this run may remove.
254
+ *
255
+ * The manifest records what the previous run wrote, and a folder carrying the name of
256
+ * a distributed skill is one this package would have written, so both are replaced.
257
+ * A folder named after nothing this package distributes is left alone, which is what
258
+ * keeps a skill the consuming repository authored out of the removal.
259
+ *
260
+ * What the manifest records is read as a claim rather than as a fact, so a name that
261
+ * does not address a folder of the installation directory is dropped before anything
262
+ * is removed.
263
+ *
264
+ * @returns {Array<string>} Skill folder names to remove.
265
+ */
266
+ collectRemovableSkillNames () {
267
+ return [
268
+ ...new Set([
269
+ ...this.manifestFile.loadSkillNames(),
270
+ ...this.collectDistributedSkillNamesInTarget(),
271
+ ]),
272
+ ]
273
+ .filter(it => this.Ctor.isPlainSkillName({ skillName: it }))
274
+ .toSorted()
275
+ }
276
+
277
+ /**
278
+ * Collect the distributed skill folder names present in the target directory.
279
+ *
280
+ * Every distributed name is considered, whether or not the manifest records it, so
281
+ * that a run following a version that installed more removes what it left behind.
282
+ *
283
+ * @returns {Array<string>} Distributed skill folder names sitting in the target directory.
284
+ */
285
+ collectDistributedSkillNamesInTarget () {
286
+ const installedSkillNames = this.collectDirectoryNames({
287
+ directoryPath: this.targetDirectoryPath,
288
+ })
289
+
290
+ return this.collectDistributedSkillNames()
291
+ .filter(it => installedSkillNames.includes(it))
292
+ }
293
+
294
+ /**
295
+ * Collect the names of the directories directly under a directory.
296
+ *
297
+ * @param {{
298
+ * directoryPath: string
299
+ * }} params - Parameters.
300
+ * @returns {Array<string>} Directory names, empty when the directory is absent.
301
+ */
302
+ collectDirectoryNames ({
303
+ directoryPath,
304
+ }) {
305
+ if (!this.fs.existsSync(directoryPath)) {
306
+ return []
307
+ }
308
+
309
+ return this.fs.readdirSync(
310
+ directoryPath,
311
+ { withFileTypes: true }
312
+ )
313
+ .filter(it => it.isDirectory())
314
+ .map(it => it.name)
315
+ .toSorted()
316
+ }
317
+
318
+ /**
319
+ * Build the path a skill is installed at.
320
+ *
321
+ * @param {{
322
+ * skillName: string
323
+ * }} params - Parameters.
324
+ * @returns {string} Path of the installed skill.
325
+ */
326
+ buildTargetSkillPath ({
327
+ skillName,
328
+ }) {
329
+ return this.path.join(
330
+ this.targetDirectoryPath,
331
+ skillName
332
+ )
333
+ }
334
+
335
+ /**
336
+ * Copy the distributed skills into the target directory.
337
+ *
338
+ * @returns {Array<string>} Copied skill folder names.
339
+ */
340
+ copyDistributedSkills () {
341
+ const skillNames = this.collectDistributedSkillNames()
342
+
343
+ this.fs.mkdirSync(
344
+ this.targetDirectoryPath,
345
+ { recursive: true }
346
+ )
347
+
348
+ skillNames.forEach(it => {
349
+ this.fs.cpSync(
350
+ this.buildSourceSkillPath({ skillName: it }),
351
+ this.buildTargetSkillPath({ skillName: it }),
352
+ { recursive: true }
353
+ )
354
+ })
355
+
356
+ return skillNames
357
+ }
358
+
359
+ /**
360
+ * Collect every skill folder name this package distributes.
361
+ *
362
+ * @returns {Array<string>} Distributed skill folder names.
363
+ * @public
364
+ */
365
+ collectDistributedSkillNames () {
366
+ return this.collectDirectoryNames({
367
+ directoryPath: this.sourceDirectoryPath,
368
+ })
369
+ }
370
+
371
+ /**
372
+ * Build the path a skill is distributed at.
373
+ *
374
+ * @param {{
375
+ * skillName: string
376
+ * }} params - Parameters.
377
+ * @returns {string} Path of the distributed skill.
378
+ */
379
+ buildSourceSkillPath ({
380
+ skillName,
381
+ }) {
382
+ return this.path.join(
383
+ this.sourceDirectoryPath,
384
+ skillName
385
+ )
386
+ }
387
+
388
+ /**
389
+ * Record what this run installed.
390
+ *
391
+ * @param {{
392
+ * skillNames: Array<string>
393
+ * }} params - Parameters.
394
+ * @returns {void}
395
+ */
396
+ saveManifest ({
397
+ skillNames,
398
+ }) {
399
+ this.manifestFile.save({
400
+ version: this.loadPackageVersion(),
401
+ skillNames,
402
+ })
403
+ }
404
+
405
+ /**
406
+ * Load the version of this package.
407
+ *
408
+ * @returns {string | null} Version of this package, or null when unreadable.
409
+ */
410
+ loadPackageVersion () {
411
+ try {
412
+ const packageHash = JSON.parse(
413
+ this.fs.readFileSync(
414
+ new URL('../../package.json', import.meta.url),
415
+ 'utf8'
416
+ )
417
+ )
418
+
419
+ return packageHash.version
420
+ ?? null
421
+ } catch {
422
+ return null
423
+ }
424
+ }
425
+
426
+ /**
427
+ * Remove every skill this package installed, along with the manifest.
428
+ *
429
+ * @returns {{
430
+ * removedSkillNames: Array<string>
431
+ * }} Removed skill folder names.
432
+ * @public
433
+ */
434
+ uninstall () {
435
+ const removedSkillNames = this.removeInstalledSkills()
436
+
437
+ this.manifestFile.remove()
438
+
439
+ return {
440
+ removedSkillNames,
441
+ }
442
+ }
443
+ }
@@ -0,0 +1,260 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ /**
5
+ * The record of what this package installed into a consuming repository.
6
+ *
7
+ * It exists so that a later run removes exactly what an earlier run wrote, and
8
+ * never a skill the consuming repository authored itself.
9
+ *
10
+ * One file holds an entry per installation directory, keyed by the path the skills
11
+ * were installed into, so that installing into two directories keeps two records
12
+ * instead of one overwriting the other.
13
+ *
14
+ * ```json
15
+ * {
16
+ * "version": "0.1.0",
17
+ * "installations": {
18
+ * ".claude/skills": {
19
+ * "skillNames": ["hor-jsdoc", "hor-naming"]
20
+ * }
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export default class SkillsManifestFile {
26
+ /**
27
+ * Constructor.
28
+ *
29
+ * @param {{
30
+ * filePath: string
31
+ * installationPath: string
32
+ * }} params - Parameters.
33
+ */
34
+ constructor ({
35
+ filePath,
36
+ installationPath,
37
+ }) {
38
+ this.filePath = filePath
39
+ this.installationPath = installationPath
40
+ }
41
+
42
+ /**
43
+ * Factory method.
44
+ *
45
+ * @template {X extends typeof SkillsManifestFile ? X : never} T, X
46
+ * @param {{
47
+ * filePath: string
48
+ * installationPath: string
49
+ * }} params - Parameters for the factory method.
50
+ * @returns {InstanceType<T>} Instance of this class.
51
+ * @this {T}
52
+ * @public
53
+ */
54
+ static create ({
55
+ filePath,
56
+ installationPath,
57
+ }) {
58
+ return new this({
59
+ filePath,
60
+ installationPath,
61
+ })
62
+ }
63
+
64
+ /**
65
+ * Node file system module.
66
+ *
67
+ * @returns {typeof fs} Node file system module.
68
+ */
69
+ get fs () {
70
+ return fs
71
+ }
72
+
73
+ /**
74
+ * Node path module.
75
+ *
76
+ * @returns {typeof path} Node path module.
77
+ */
78
+ get path () {
79
+ return path
80
+ }
81
+
82
+ /**
83
+ * Load the skill names recorded for this installation directory by the previous run.
84
+ *
85
+ * The manifest sits in the consuming repository, so what it holds is not guaranteed to
86
+ * be what a previous run wrote. Anything but an array of strings is read as nothing
87
+ * recorded, and a member that is not a string is dropped from the ones that are.
88
+ *
89
+ * @returns {Array<string>} Recorded skill folder names, empty when nothing usable is recorded.
90
+ * @public
91
+ */
92
+ loadSkillNames () {
93
+ const skillNames = this.loadInstallation()
94
+ ?.skillNames
95
+
96
+ if (!Array.isArray(skillNames)) {
97
+ return []
98
+ }
99
+
100
+ return skillNames.filter(it => typeof it === 'string')
101
+ }
102
+
103
+ /**
104
+ * Load the entry of this installation directory.
105
+ *
106
+ * @returns {SkillsInstallationHash | null} Entry of this installation directory, or null when absent.
107
+ */
108
+ loadInstallation () {
109
+ const installationHash = this.loadInstallationHash()
110
+
111
+ return installationHash[this.installationPath]
112
+ ?? null
113
+ }
114
+
115
+ /**
116
+ * Load the entries of every installation directory.
117
+ *
118
+ * @returns {Record<string, SkillsInstallationHash>} Entries by installation directory, empty when none is readable.
119
+ */
120
+ loadInstallationHash () {
121
+ return this.load()
122
+ ?.installations
123
+ ?? {}
124
+ }
125
+
126
+ /**
127
+ * Load the manifest.
128
+ *
129
+ * @returns {SkillsManifestHash | null} Manifest hash, or null when absent or unreadable.
130
+ * @public
131
+ */
132
+ load () {
133
+ if (!this.fs.existsSync(this.filePath)) {
134
+ return null
135
+ }
136
+
137
+ try {
138
+ return JSON.parse(
139
+ this.fs.readFileSync(
140
+ this.filePath,
141
+ 'utf8'
142
+ )
143
+ )
144
+ } catch {
145
+ return null
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Save the entry of this installation directory, keeping the entries of the others.
151
+ *
152
+ * @param {{
153
+ * version: string | null
154
+ * skillNames: Array<string>
155
+ * }} params - Parameters.
156
+ * @returns {void}
157
+ * @public
158
+ */
159
+ save ({
160
+ version,
161
+ skillNames,
162
+ }) {
163
+ this.write({
164
+ manifestHash: {
165
+ version,
166
+ installations: {
167
+ ...this.loadInstallationHash(),
168
+ [this.installationPath]: {
169
+ skillNames,
170
+ },
171
+ },
172
+ },
173
+ })
174
+ }
175
+
176
+ /**
177
+ * Write the manifest, creating the directory holding it.
178
+ *
179
+ * @param {{
180
+ * manifestHash: SkillsManifestHash
181
+ * }} params - Parameters.
182
+ * @returns {void}
183
+ */
184
+ write ({
185
+ manifestHash,
186
+ }) {
187
+ const manifestJson = JSON.stringify(
188
+ manifestHash,
189
+ null,
190
+ 2
191
+ )
192
+
193
+ this.fs.mkdirSync(
194
+ this.path.dirname(this.filePath),
195
+ { recursive: true }
196
+ )
197
+
198
+ this.fs.writeFileSync(
199
+ this.filePath,
200
+ `${manifestJson}\n`
201
+ )
202
+ }
203
+
204
+ /**
205
+ * Remove the entry of this installation directory, and the file once no entry is left.
206
+ *
207
+ * @returns {void}
208
+ * @public
209
+ */
210
+ remove () {
211
+ const manifestHash = this.load()
212
+
213
+ if (!manifestHash) {
214
+ return
215
+ }
216
+
217
+ const remainingInstallationHash = this.buildRemainingInstallationHash()
218
+
219
+ if (Object.keys(remainingInstallationHash).length === 0) {
220
+ this.fs.rmSync(
221
+ this.filePath,
222
+ { force: true }
223
+ )
224
+
225
+ return
226
+ }
227
+
228
+ this.write({
229
+ manifestHash: {
230
+ ...manifestHash,
231
+ installations: remainingInstallationHash,
232
+ },
233
+ })
234
+ }
235
+
236
+ /**
237
+ * Build the entries left after dropping the one of this installation directory.
238
+ *
239
+ * @returns {Record<string, SkillsInstallationHash>} Entries of the other installation directories.
240
+ */
241
+ buildRemainingInstallationHash () {
242
+ return Object.fromEntries(
243
+ Object.entries(this.loadInstallationHash())
244
+ .filter(([installationPath]) => installationPath !== this.installationPath)
245
+ )
246
+ }
247
+ }
248
+
249
+ /**
250
+ * @typedef {{
251
+ * version: string | null
252
+ * installations: Record<string, SkillsInstallationHash>
253
+ * }} SkillsManifestHash
254
+ */
255
+
256
+ /**
257
+ * @typedef {{
258
+ * skillNames: Array<string>
259
+ * }} SkillsInstallationHash
260
+ */
@@ -0,0 +1,8 @@
1
+ const CLI_COMMAND = {
2
+ INSTALL: 'install',
3
+ LIST: 'list',
4
+ UNINSTALL: 'uninstall',
5
+ HELP: 'help',
6
+ }
7
+
8
+ export default CLI_COMMAND
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ import HoraSkillsCli from './HoraSkillsCli.js'
4
+
5
+ process.exitCode = HoraSkillsCli.create({
6
+ args: process.argv.slice(2),
7
+ })
8
+ .run()