@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,590 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ import CommandLineArguments from './CommandLineArguments.js'
5
+ import SkillsInstaller from './SkillsInstaller.js'
6
+
7
+ import CLI_COMMAND from './constants/CLI_COMMAND.js'
8
+
9
+ /**
10
+ * The `hora-skills-ort-renchan` command.
11
+ *
12
+ * It installs every skill this package distributes into a consuming repository, and
13
+ * removes what an earlier run of it installed. Which skills a repository equips is
14
+ * answered by which of the sibling skill libraries it installs, so this command has
15
+ * nothing to select.
16
+ */
17
+ export default class HoraSkillsCli {
18
+ /**
19
+ * Constructor.
20
+ *
21
+ * @param {{
22
+ * commandLineArguments: CommandLineArguments
23
+ * workingDirectoryPath: string
24
+ * logger: Console
25
+ * }} params - Parameters.
26
+ */
27
+ constructor ({
28
+ commandLineArguments,
29
+ workingDirectoryPath,
30
+ logger,
31
+ }) {
32
+ this.commandLineArguments = commandLineArguments
33
+ this.workingDirectoryPath = workingDirectoryPath
34
+ this.logger = logger
35
+ }
36
+
37
+ /**
38
+ * Factory method.
39
+ *
40
+ * @template {X extends typeof HoraSkillsCli ? X : never} T, X
41
+ * @param {{
42
+ * args: Array<string>
43
+ * workingDirectoryPath?: string
44
+ * logger?: Console
45
+ * }} params - Parameters for the factory method.
46
+ * @returns {InstanceType<T>} Instance of this class.
47
+ * @this {T}
48
+ * @public
49
+ */
50
+ static create ({
51
+ args,
52
+ workingDirectoryPath = process.cwd(),
53
+ logger = console,
54
+ }) {
55
+ const commandLineArguments = this.createCommandLineArguments({
56
+ args,
57
+ })
58
+
59
+ return new this({
60
+ commandLineArguments,
61
+ workingDirectoryPath,
62
+ logger,
63
+ })
64
+ }
65
+
66
+ /**
67
+ * Constructor of the command line arguments.
68
+ *
69
+ * @returns {typeof CommandLineArguments} Constructor of the command line arguments.
70
+ */
71
+ static get CommandLineArgumentsCtor () {
72
+ return CommandLineArguments
73
+ }
74
+
75
+ /**
76
+ * Constructor of the installer.
77
+ *
78
+ * @returns {typeof SkillsInstaller} Constructor of the installer.
79
+ */
80
+ static get SkillsInstallerCtor () {
81
+ return SkillsInstaller
82
+ }
83
+
84
+ /**
85
+ * Directory the skills are installed into, relative to the consuming repository.
86
+ *
87
+ * @returns {Array<string>} Path segments of the default target directory.
88
+ */
89
+ static get defaultTargetDirectorySegments () {
90
+ return [
91
+ '.claude',
92
+ 'skills',
93
+ ]
94
+ }
95
+
96
+ /**
97
+ * Build the path of every step from a base directory down to a path below it.
98
+ *
99
+ * The steps are what a path is reached through, so verifying a path means verifying
100
+ * each of them — a link at any one of them redirects everything below it.
101
+ *
102
+ * @param {{
103
+ * basePath: string
104
+ * targetPath: string
105
+ * }} params - Parameters.
106
+ * @returns {Array<string>} Path of every step, the target path last.
107
+ */
108
+ static buildPathSteps ({
109
+ basePath,
110
+ targetPath,
111
+ }) {
112
+ return path.relative(basePath, targetPath)
113
+ .split(path.sep)
114
+ .filter(it => it !== '')
115
+ .reduce(
116
+ (steps, segment) => [
117
+ ...steps,
118
+ path.join(
119
+ steps.at(-1) ?? basePath,
120
+ segment
121
+ ),
122
+ ],
123
+ /** @type {Array<string>} */ ([])
124
+ )
125
+ }
126
+
127
+ /**
128
+ * Build the line a failure is reported as.
129
+ *
130
+ * A message names the path the failure happened on, and a path can carry a skill name
131
+ * the consuming repository chose, so the characters a terminal acts on are dropped
132
+ * before the line reaches one. Everything a path may legitimately hold is kept.
133
+ *
134
+ * @param {{
135
+ * error: unknown
136
+ * }} params - Parameters.
137
+ * @returns {string} Line reporting the failure.
138
+ */
139
+ static buildFailureMessage ({
140
+ error,
141
+ }) {
142
+ const message = error instanceof Error
143
+ ? error.message
144
+ : String(error)
145
+
146
+ return [
147
+ ...message,
148
+ ]
149
+ .map(it => this.buildPrintableCharacter({ character: it }))
150
+ .join('')
151
+ }
152
+
153
+ /**
154
+ * Build the character a terminal prints in place of one it would act on.
155
+ *
156
+ * @param {{
157
+ * character: string
158
+ * }} params - Parameters.
159
+ * @returns {string} The character itself, or the one standing for it.
160
+ */
161
+ static buildPrintableCharacter ({
162
+ character,
163
+ }) {
164
+ const codePoint = character.codePointAt(0)
165
+
166
+ if (codePoint >= 0x20 && codePoint !== 0x7f) {
167
+ return character
168
+ }
169
+
170
+ return '?'
171
+ }
172
+
173
+ /**
174
+ * Usage text.
175
+ *
176
+ * @returns {string} Usage text.
177
+ */
178
+ static get usageText () {
179
+ return [
180
+ 'Usage: hora-skills-ort-renchan <command> [options]',
181
+ '',
182
+ 'Commands:',
183
+ ' install Install every skill this package distributes, replacing the installed ones',
184
+ ' list Print the skills this package distributes, installing nothing',
185
+ ' uninstall Remove every skill this package installed',
186
+ ' help Print this text',
187
+ '',
188
+ 'Options:',
189
+ ' --dir <path> Directory to install into (default: .claude/skills)',
190
+ ]
191
+ .join('\n')
192
+ }
193
+
194
+ /**
195
+ * Create the command line arguments.
196
+ *
197
+ * @param {{
198
+ * args: Array<string>
199
+ * }} params - Parameters.
200
+ * @returns {CommandLineArguments} Command line arguments.
201
+ */
202
+ static createCommandLineArguments ({
203
+ args,
204
+ }) {
205
+ return this.CommandLineArgumentsCtor.create({
206
+ args,
207
+ })
208
+ }
209
+
210
+ /**
211
+ * Create the installer.
212
+ *
213
+ * @param {{
214
+ * workingDirectoryPath: string
215
+ * targetDirectoryPath: string
216
+ * }} params - Parameters.
217
+ * @returns {SkillsInstaller} Installer.
218
+ */
219
+ static createSkillsInstaller ({
220
+ workingDirectoryPath,
221
+ targetDirectoryPath,
222
+ }) {
223
+ return this.SkillsInstallerCtor.create({
224
+ workingDirectoryPath,
225
+ targetDirectoryPath,
226
+ })
227
+ }
228
+
229
+ /**
230
+ * Constructor of this instance.
231
+ *
232
+ * @returns {typeof HoraSkillsCli} Constructor of this instance.
233
+ */
234
+ get Ctor () {
235
+ return /** @type {typeof HoraSkillsCli} */ (this.constructor)
236
+ }
237
+
238
+ /**
239
+ * Node file system module.
240
+ *
241
+ * @returns {typeof fs} Node file system module.
242
+ */
243
+ get fs () {
244
+ return fs
245
+ }
246
+
247
+ /**
248
+ * Node path module.
249
+ *
250
+ * @returns {typeof path} Node path module.
251
+ */
252
+ get path () {
253
+ return path
254
+ }
255
+
256
+ /**
257
+ * Run the command, reporting whatever it raises.
258
+ *
259
+ * A command reaches the file system of a repository this package knows nothing about, so
260
+ * a failure it cannot help is ordinary: a skill directory that is a file, a `.claude/`
261
+ * that is read only, a disk with nothing left. None of them is worth a stack trace, so
262
+ * the command reports what it raised and ends with a failing exit code.
263
+ *
264
+ * @returns {number} Exit code.
265
+ * @public
266
+ */
267
+ run () {
268
+ try {
269
+ return this.dispatch()
270
+ } catch (error) {
271
+ return this.reportFailure({ error })
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Dispatch to the command.
277
+ *
278
+ * @returns {number} Exit code.
279
+ */
280
+ dispatch () {
281
+ const command = this.commandLineArguments.extractCommand()
282
+ ?? CLI_COMMAND.HELP
283
+
284
+ if (command === CLI_COMMAND.INSTALL) {
285
+ return this.runInstall()
286
+ }
287
+
288
+ if (command === CLI_COMMAND.LIST) {
289
+ return this.runCatalog()
290
+ }
291
+
292
+ if (command === CLI_COMMAND.UNINSTALL) {
293
+ return this.runUninstall()
294
+ }
295
+
296
+ if (command === CLI_COMMAND.HELP) {
297
+ return this.runHelp()
298
+ }
299
+
300
+ return this.reportUnknownCommand({
301
+ command,
302
+ })
303
+ }
304
+
305
+ /**
306
+ * Install every skill this package distributes.
307
+ *
308
+ * @returns {number} Exit code.
309
+ */
310
+ runInstall () {
311
+ const verifiedExitCode = this.verifyPaths()
312
+
313
+ if (verifiedExitCode !== 0) {
314
+ return verifiedExitCode
315
+ }
316
+
317
+ const installer = this.buildSkillsInstaller()
318
+ const {
319
+ installedSkillNames,
320
+ removedSkillNames,
321
+ } = installer.install()
322
+
323
+ this.logger.log(`Removed ${removedSkillNames.length} skills from ${this.buildTargetDirectoryPath()}`)
324
+ this.logger.log(`Installed ${installedSkillNames.length} skills into ${this.buildTargetDirectoryPath()}`)
325
+
326
+ return 0
327
+ }
328
+
329
+ /**
330
+ * Build the installer against the target directory.
331
+ *
332
+ * @returns {SkillsInstaller} Installer.
333
+ */
334
+ buildSkillsInstaller () {
335
+ return this.Ctor.createSkillsInstaller({
336
+ workingDirectoryPath: this.workingDirectoryPath,
337
+ targetDirectoryPath: this.buildTargetDirectoryPath(),
338
+ })
339
+ }
340
+
341
+ /**
342
+ * Build the directory the skills are installed into.
343
+ *
344
+ * @returns {string} Target directory path.
345
+ */
346
+ buildTargetDirectoryPath () {
347
+ const specifiedPath = this.commandLineArguments.extractTargetDirectoryPath()
348
+
349
+ if (specifiedPath) {
350
+ return this.path.resolve(
351
+ this.workingDirectoryPath,
352
+ specifiedPath
353
+ )
354
+ }
355
+
356
+ return this.path.join(
357
+ this.workingDirectoryPath,
358
+ ...this.Ctor.defaultTargetDirectorySegments
359
+ )
360
+ }
361
+
362
+ /**
363
+ * Build the directory an installation is verified from.
364
+ *
365
+ * A `--dir` is named by whoever runs the command, so it is taken as given and only what
366
+ * lies below it is verified — and it is the installation directory itself, so nothing
367
+ * lies below it. Without one the installation is placed inside the consuming repository,
368
+ * and every step below that repository is verified.
369
+ *
370
+ * @returns {string} Directory the verification starts from.
371
+ */
372
+ buildVerifiedBaseDirectoryPath () {
373
+ const specifiedPath = this.commandLineArguments.extractTargetDirectoryPath()
374
+
375
+ if (specifiedPath) {
376
+ return this.buildTargetDirectoryPath()
377
+ }
378
+
379
+ return this.workingDirectoryPath
380
+ }
381
+
382
+ /**
383
+ * Tell whether a path is a symbolic link.
384
+ *
385
+ * A path that does not exist is not one — an installation directory is commonly absent
386
+ * until the first run creates it.
387
+ *
388
+ * @param {{
389
+ * filePath: string
390
+ * }} params - Parameters.
391
+ * @returns {boolean} Whether the path is a symbolic link.
392
+ */
393
+ isSymbolicLink ({
394
+ filePath,
395
+ }) {
396
+ try {
397
+ return this.fs.lstatSync(filePath)
398
+ .isSymbolicLink()
399
+ } catch {
400
+ return false
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Tell whether a path is reached through a symbolic link.
406
+ *
407
+ * @param {{
408
+ * basePath: string
409
+ * targetPath: string
410
+ * }} params - Parameters.
411
+ * @returns {boolean} Whether the path is reached through a symbolic link.
412
+ */
413
+ isReachedThroughSymbolicLink ({
414
+ basePath,
415
+ targetPath,
416
+ }) {
417
+ return this.Ctor.buildPathSteps({
418
+ basePath,
419
+ targetPath,
420
+ })
421
+ .some(it => this.isSymbolicLink({ filePath: it }))
422
+ }
423
+
424
+ /**
425
+ * Collect the installation directories reached through a symbolic link.
426
+ *
427
+ * @returns {Array<string>} Installation directories reached through a symbolic link.
428
+ */
429
+ collectLinkedTargetDirectoryPaths () {
430
+ const basePath = this.buildVerifiedBaseDirectoryPath()
431
+
432
+ return [
433
+ this.buildTargetDirectoryPath(),
434
+ ]
435
+ .filter(it => this.isReachedThroughSymbolicLink({
436
+ basePath,
437
+ targetPath: it,
438
+ }))
439
+ }
440
+
441
+ /**
442
+ * Build the path of the record an installation writes.
443
+ *
444
+ * The record belongs to the consuming repository rather than to an installation
445
+ * directory, so it sits below the working directory whatever `--dir` names.
446
+ *
447
+ * @returns {string} Path of the record.
448
+ */
449
+ buildManifestFilePath () {
450
+ return this.path.join(
451
+ this.workingDirectoryPath,
452
+ ...this.Ctor.SkillsInstallerCtor.manifestPathSegments
453
+ )
454
+ }
455
+
456
+ /**
457
+ * Collect the record's path when it is reached through a symbolic link.
458
+ *
459
+ * Writing the record follows a link the way any write does, so a repository carrying
460
+ * one there hands this package the file at its far end to overwrite.
461
+ *
462
+ * @returns {Array<string>} Path of the record, empty when it is reached through none.
463
+ */
464
+ collectLinkedManifestFilePaths () {
465
+ const filePath = this.buildManifestFilePath()
466
+
467
+ if (!this.isReachedThroughSymbolicLink({
468
+ basePath: this.workingDirectoryPath,
469
+ targetPath: filePath,
470
+ })) {
471
+ return []
472
+ }
473
+
474
+ return [
475
+ filePath,
476
+ ]
477
+ }
478
+
479
+ /**
480
+ * Verify that nothing a command writes is reached through a symbolic link.
481
+ *
482
+ * A link is content of the repository rather than an instruction of whoever runs the
483
+ * command, so following one would let the repository decide where skills are written
484
+ * and, worse, where they are removed — and where the record is written, which overwrites
485
+ * whatever the link stands for. Nothing is carried through one, and the whole command
486
+ * ends rather than half of it running.
487
+ *
488
+ * @returns {number} Exit code, zero when every path is what it appears to be.
489
+ */
490
+ verifyPaths () {
491
+ const linkedPaths = [
492
+ ...this.collectLinkedTargetDirectoryPaths(),
493
+ ...this.collectLinkedManifestFilePaths(),
494
+ ]
495
+
496
+ if (linkedPaths.length === 0) {
497
+ return 0
498
+ }
499
+
500
+ linkedPaths.forEach(it => {
501
+ this.logger.error(`${it} is reached through a symbolic link.`)
502
+ })
503
+
504
+ this.logger.error('Nothing was changed. An installation carries nothing through a link — replace it, or give --dir the directory it resolves to.')
505
+
506
+ return 1
507
+ }
508
+
509
+ /**
510
+ * Print the skills this package distributes.
511
+ *
512
+ * @returns {number} Exit code.
513
+ */
514
+ runCatalog () {
515
+ const installer = this.buildSkillsInstaller()
516
+ const skillNames = installer.collectDistributedSkillNames()
517
+
518
+ skillNames.forEach(it => {
519
+ this.logger.log(it)
520
+ })
521
+
522
+ this.logger.log(`${skillNames.length} skills distributed`)
523
+
524
+ return 0
525
+ }
526
+
527
+ /**
528
+ * Remove every skill this package installed.
529
+ *
530
+ * @returns {number} Exit code.
531
+ */
532
+ runUninstall () {
533
+ const verifiedExitCode = this.verifyPaths()
534
+
535
+ if (verifiedExitCode !== 0) {
536
+ return verifiedExitCode
537
+ }
538
+
539
+ const installer = this.buildSkillsInstaller()
540
+ const { removedSkillNames } = installer.uninstall()
541
+
542
+ this.logger.log(`Removed ${removedSkillNames.length} skills from ${this.buildTargetDirectoryPath()}`)
543
+
544
+ return 0
545
+ }
546
+
547
+ /**
548
+ * Report a failure raised while a command ran.
549
+ *
550
+ * @param {{
551
+ * error: unknown
552
+ * }} params - Parameters.
553
+ * @returns {number} Exit code.
554
+ */
555
+ reportFailure ({
556
+ error,
557
+ }) {
558
+ this.logger.error(this.Ctor.buildFailureMessage({ error }))
559
+
560
+ return 1
561
+ }
562
+
563
+ /**
564
+ * Print the usage text.
565
+ *
566
+ * @returns {number} Exit code.
567
+ */
568
+ runHelp () {
569
+ this.logger.log(this.Ctor.usageText)
570
+
571
+ return 0
572
+ }
573
+
574
+ /**
575
+ * Report a command this CLI does not have.
576
+ *
577
+ * @param {{
578
+ * command: string
579
+ * }} params - Parameters.
580
+ * @returns {number} Exit code.
581
+ */
582
+ reportUnknownCommand ({
583
+ command,
584
+ }) {
585
+ this.logger.error(`Unknown command: ${command}`)
586
+ this.logger.error(this.Ctor.usageText)
587
+
588
+ return 1
589
+ }
590
+ }