gen-cordis-catalog.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /**
  2. * Generate the Cordis event and service catalogs from static declarations.
  3. * The walk enforces event modes plus JSDoc parameter/return completeness;
  4. * inherited Cordis services come from the curated table below. `--check`
  5. * verifies both committed artifacts.
  6. */
  7. import { globSync, readFileSync, writeFileSync } from 'node:fs'
  8. import { resolve, sep } from 'node:path'
  9. import ts from 'typescript'
  10. import { checkParams, checkReturns, parseJsDoc, parseTags, pointer, rawJsDoc, reportViolations, type Mode } from './jsdoc.ts'
  11. import { cordisModuleBody, eventMembers, serviceClasses } from './cordis-walk.ts'
  12. const root = resolve(import.meta.dirname, '..')
  13. const OUT_EVENTS = 'docs/cordis-catalog/events.md'
  14. const OUT_SERVICES = 'docs/cordis-catalog/services.md'
  15. /** The fenced-block info string for generated signature blocks (skipped by
  16. * doc-typecheck, since a bare signature fragment is not standalone-compilable). */
  17. const FENCE = 'ts cordis-catalog'
  18. /**
  19. * One primary core-data-structures page per signature type, shared by the
  20. * Cordis and config catalogs; union names intentionally do not reuse the
  21. * type-equivalence manifest's map-symbol entries.
  22. */
  23. // TODO(catalog-type-links): verify or generate link-map coverage.
  24. export const LINK_MAP: Record<string, string> = {
  25. Agent: 'core.md',
  26. ContentBlock: 'core.md',
  27. Message: 'core.md',
  28. MessageSource: 'core.md',
  29. GenerateOptions: 'core.md',
  30. LlmCallConfig: 'core.md',
  31. SessionEvent: 'core.md',
  32. SessionStartSource: 'core.md',
  33. StreamChunk: 'llm-streaming.md',
  34. TurnEndReason: 'session.md',
  35. ToolDefinition: 'tools.md',
  36. ToolExecution: 'tools.md',
  37. ToolExecutionMode: 'tools.md',
  38. ToolExecutionInput: 'tools.md',
  39. ToolExecutionResult: 'tools.md',
  40. ToolExecutionToken: 'tools.md',
  41. ApprovalOutcome: 'approval.md',
  42. ApprovalPolicy: 'approval.md',
  43. ApprovalRequest: 'approval.md',
  44. BashExecRequest: 'bash.md',
  45. BashExecSpec: 'bash.md',
  46. BashRunResult: 'bash.md',
  47. ConfinedArgv: 'sandbox.md',
  48. SandboxMode: 'sandbox.md',
  49. SandboxPolicy: 'sandbox.md',
  50. CodeRunRequest: 'code-runtime.md',
  51. CodeRunResult: 'code-runtime.md',
  52. FsEditOutcome: 'filesystem.md',
  53. FsEditRequest: 'filesystem.md',
  54. FsInfo: 'filesystem.md',
  55. FsTarget: 'filesystem.md',
  56. FsVersion: 'filesystem.md',
  57. FsWriteIntent: 'filesystem.md',
  58. FsWriteOutcome: 'filesystem.md',
  59. FsPolicyExec: 'filesystem.md',
  60. FileReadOutcome: 'filesystem.md',
  61. }
  62. /** One harness event, extracted from an `interface Events` block. */
  63. interface EventEntry {
  64. /** Scoped name, e.g. `agent/request`. */
  65. name: string
  66. /** The scope prefix, e.g. `agent` (everything before the first `/`). */
  67. scope: string
  68. /** Full signature text (the method-signature member, JSDoc stripped). */
  69. signature: string
  70. /** Dispatch mode from the `@mode` tag. */
  71. mode: Mode
  72. /** Description prose (JSDoc minus the `@mode` tag), one line per paragraph. */
  73. doc: string
  74. /** Source pointer `packages/…/file.ts:line` of the declaration. */
  75. source: string
  76. }
  77. /** One harness service, extracted from an `interface Context` block. */
  78. interface ServiceEntry {
  79. /** The `ctx.<key>` name, e.g. `llm`. */
  80. key: string
  81. /** The service class/interface name, e.g. `LlmService`. */
  82. type: string
  83. /** Whether the service class is abstract (a seam interface). */
  84. abstract: boolean
  85. /** Class-level JSDoc prose, one line per paragraph. */
  86. doc: string
  87. /** Public method signatures (bodies stripped), in source order. */
  88. methods: string[]
  89. /** Source pointer of the class declaration. */
  90. source: string
  91. }
  92. /** A terse inherited-tier entry (pinned vendor surface). */
  93. interface InheritedEntry {
  94. name: string
  95. summary: string
  96. /** Source pointer `vendor/…:line`. */
  97. source: string
  98. }
  99. // cordisModuleBody / eventMembers / serviceClasses live in cordis-walk.ts,
  100. // shared with gen-website-api.ts — one walk, two renderers.
  101. /** The signature text of a method-signature member (everything but a body). */
  102. function memberSignature(member: ts.TypeElement | ts.ClassElement, sf: ts.SourceFile): string {
  103. const full = member.getText(sf)
  104. const body = (member as { body?: ts.Node }).body
  105. const sig = body ? full.slice(0, full.length - body.getText(sf).length) : full
  106. return sig.replace(/\s*;?\s*$/, '').replace(/\s+/g, ' ').trim()
  107. }
  108. /** Walk every harness `interface Events` block and extract its events, hard-
  109. * erroring (aggregated) on any JSDoc-completeness violation: a missing/
  110. * contradicted `@mode`, missing description prose, or an undocumented payload
  111. * parameter. `scanRoot` defaults to the repo root; tests pass a fixture dir. */
  112. export function collectEvents(scanRoot: string = root): EventEntry[] {
  113. const entries: EventEntry[] = []
  114. const violations: string[] = []
  115. for (const rel of globSync('packages/*/*/src/*.ts', { cwd: scanRoot }).map(s => s.split(sep).join('/')).sort()) {
  116. const abs = resolve(scanRoot, rel)
  117. const text = readFileSync(abs, 'utf8')
  118. if (!text.includes('interface Events')) continue
  119. const sf = ts.createSourceFile(abs, text, ts.ScriptTarget.Latest, true)
  120. const body = cordisModuleBody(sf)
  121. if (!body) continue
  122. for (const { name, member } of eventMembers(body, sf)) {
  123. const signature = memberSignature(member, sf)
  124. const raw = rawJsDoc(text, member)
  125. const { doc, mode } = parseJsDoc(raw)
  126. const src = pointer(rel, sf, member)
  127. const where = `event '${name}' (${src})`
  128. if (!mode) {
  129. violations.push(`${where} is missing an @mode tag. Add '@mode emit|waterfall|parallel|serial' to its JSDoc (see AGENTS.md).`)
  130. }
  131. // Conclusive structural check: a trailing `next: () => …` parameter is a
  132. // waterfall. (emit vs parallel vs serial is not structurally
  133. // distinguishable, so it is trusted from the tag.)
  134. const last = member.parameters.at(-1)
  135. const hasNext = !!last && last.name.getText(sf) === 'next'
  136. if (mode && hasNext && mode !== 'waterfall') {
  137. violations.push(`${where} has a trailing 'next' parameter (structurally a waterfall) but is tagged '@mode ${mode}'. Fix the tag or the signature.`)
  138. }
  139. if (mode && !hasNext && mode === 'waterfall') {
  140. violations.push(`${where} is tagged '@mode waterfall' but has no trailing 'next' parameter. A waterfall delegates via next().`)
  141. }
  142. if (!doc) violations.push(`${where} has no description prose. Say what happened / what a listener may do, above the block tags.`)
  143. // Payload parameters need a non-empty @param. The `this` receiver is not
  144. // payload, and a waterfall's trailing `next` is covered by its mode.
  145. const { params } = parseTags(raw)
  146. checkParams(where, 'event', member.parameters, params, sf,
  147. p => (ts.isIdentifier(p.name) && p.name.text === 'this') || (hasNext && p === last), violations)
  148. if (mode) entries.push({ name, scope: name.split('/')[0] ?? name, signature, mode, doc, source: src })
  149. }
  150. }
  151. reportViolations('gen-cordis-catalog', violations)
  152. return entries
  153. }
  154. /** Walk every harness `interface Context` block + its service class, hard-
  155. * erroring (aggregated) on any JSDoc-completeness violation: a class or public
  156. * method without JSDoc prose, an undocumented parameter, a stale `@param`, a
  157. * missing `@returns` on a non-void method, or an inferred (unannotated) return
  158. * type the pure-AST walk cannot classify.
  159. * `scanRoot` defaults to the repo root; tests pass a fixture dir. */
  160. export function collectServices(scanRoot: string = root): ServiceEntry[] {
  161. const entries: ServiceEntry[] = []
  162. const violations: string[] = []
  163. for (const rel of globSync('packages/*/*/src/index.ts', { cwd: scanRoot }).map(s => s.split(sep).join('/')).sort()) {
  164. const abs = resolve(scanRoot, rel)
  165. const text = readFileSync(abs, 'utf8')
  166. if (!text.includes('interface Context')) continue
  167. const sf = ts.createSourceFile(abs, text, ts.ScriptTarget.Latest, true)
  168. const body = cordisModuleBody(sf)
  169. if (!body) continue
  170. // Resolve each ctx key to its service class (shared walk) and emit an entry.
  171. for (const { key, type, cls, abstract, doc: clsDoc } of serviceClasses(body, sf, rel, violations)) {
  172. const methods: string[] = []
  173. for (const member of cls.members) {
  174. if (!ts.isMethodDeclaration(member)) continue
  175. // Only instance methods callable through `ctx.<key>` are surface;
  176. // private, protected, and static methods are not.
  177. const nonPublic = member.modifiers?.some(m =>
  178. m.kind === ts.SyntaxKind.PrivateKeyword
  179. || m.kind === ts.SyntaxKind.ProtectedKeyword
  180. || m.kind === ts.SyntaxKind.StaticKeyword)
  181. || ts.isPrivateIdentifier(member.name)
  182. if (nonPublic) continue
  183. const memberName = member.name.getText(sf)
  184. if (memberName.startsWith('[')) continue // computed/symbol members
  185. methods.push(memberSignature(member, sf))
  186. const where = `service method ctx.${key}.${memberName} (${pointer(rel, sf, member)})`
  187. const raw = rawJsDoc(text, member)
  188. if (!raw) { violations.push(`${where} has no JSDoc.`); continue }
  189. if (!parseJsDoc(raw).doc) violations.push(`${where} has no description prose above its block tags.`)
  190. const { params, returns } = parseTags(raw)
  191. // Every parameter needs a non-empty @param (`this` receiver exempt),
  192. // and a non-void ANNOTATED result needs a non-empty @returns — the
  193. // shared checkers carry the exact contract.
  194. checkParams(where, 'service', member.parameters, params, sf,
  195. p => ts.isIdentifier(p.name) && p.name.text === 'this', violations)
  196. checkReturns(where, member.type, returns, sf, violations)
  197. }
  198. entries.push({
  199. key,
  200. type,
  201. abstract,
  202. doc: clsDoc,
  203. methods,
  204. source: pointer(rel, sf, cls),
  205. })
  206. }
  207. }
  208. reportViolations('gen-cordis-catalog', violations)
  209. return entries.sort((a, b) => a.key.localeCompare(b.key))
  210. }
  211. /**
  212. * The inherited tier — cordis core + loader/hmr/timer. Curated, terse, and
  213. * hand-summarized because (a) it is pinned vendor source that changes only on a
  214. * deliberate vendor sync, (b) the cordis-core `Context` mixes true ctx members
  215. * with non-service fields (`root`, `baseUrl`, `logger`) that a blind walk would
  216. * wrongly surface as services, and (c) the internal/* events carry no JSDoc to
  217. * render. Source pointers are verified against vendor by `verify-md-links`'
  218. * sibling check is N/A; keep them current on a vendor bump.
  219. */
  220. const INHERITED_EVENTS: InheritedEntry[] = [
  221. { name: 'internal/plugin', summary: 'A plugin fiber was created.', source: 'vendor/cordis/src/events.ts:328' },
  222. { name: 'internal/status', summary: 'A fiber changed lifecycle state.', source: 'vendor/cordis/src/events.ts:330' },
  223. { name: 'internal/service', summary: 'Interception hook for a service binding (no core producer).', source: 'vendor/cordis/src/events.ts:332' },
  224. { name: 'internal/update', summary: 'Waterfall: a fiber config update is being applied.', source: 'vendor/cordis/src/events.ts:334' },
  225. { name: 'internal/get', summary: 'Waterfall: a service is being read from the store.', source: 'vendor/cordis/src/events.ts:336' },
  226. { name: 'internal/set', summary: 'Waterfall: a service is being written to the store.', source: 'vendor/cordis/src/events.ts:338' },
  227. { name: 'internal/listener', summary: 'A listener was registered.', source: 'vendor/cordis/src/events.ts:340' },
  228. { name: 'internal/dispatch', summary: 'An event is being dispatched to listeners.', source: 'vendor/cordis/src/events.ts:342' },
  229. { name: 'hmr/change', summary: 'A watched source file changed on disk.', source: 'vendor/hmr/src/index.ts:20' },
  230. { name: 'hmr/reload', summary: 'Plugins are being reloaded after a change.', source: 'vendor/hmr/src/index.ts:21' },
  231. { name: 'exit', summary: 'The process is exiting on a signal.', source: 'vendor/loader/src/index.ts:23' },
  232. { name: 'loader/config-update', summary: 'The loader config tree changed.', source: 'vendor/loader/src/index.ts:24' },
  233. { name: 'loader/entry-init', summary: 'A config entry is being initialized.', source: 'vendor/loader/src/index.ts:25' },
  234. { name: 'loader/partial-dispose', summary: 'An entry is being partially disposed on reload.', source: 'vendor/loader/src/index.ts:26' },
  235. { name: 'loader/patch-context', summary: 'A context is being patched during a reload.', source: 'vendor/loader/src/index.ts:27' },
  236. ]
  237. export const INHERITED_SERVICES: InheritedEntry[] = [
  238. { name: 'ctx.on / ctx.once', summary: 'Register an event listener (disposable).', source: 'vendor/cordis/src/events.ts:34' },
  239. { name: 'ctx.emit / ctx.parallel / ctx.serial / ctx.bail / ctx.waterfall', summary: 'Dispatch an event (sync / awaited / first-bail / veto-chain).', source: 'vendor/cordis/src/events.ts:34' },
  240. { name: 'ctx.plugin / ctx.inject', summary: 'Load a plugin / declare required services.', source: 'vendor/cordis/src/registry.ts:164' },
  241. { name: 'ctx.effect', summary: 'Register a disposable side effect tied to the fiber.', source: 'vendor/cordis/src/fiber.ts:9' },
  242. { name: 'ctx.get / ctx.set / ctx.provide / ctx.accessor / ctx.mixin', summary: 'Low-level service-store access and binding.', source: 'vendor/cordis/src/reflect.ts:7' },
  243. { name: 'ctx.extend / ctx.isolate / ctx.intercept', summary: 'Derive a child context (scoped services / isolation / interception).', source: 'vendor/cordis/src/context.ts:42' },
  244. { name: 'ctx.root / ctx.scope / ctx.fiber / ctx.registry / ctx.reflect / ctx.events / ctx.logger', summary: 'Ambient handles onto the running context graph.', source: 'vendor/cordis/src/context.ts:16' },
  245. { name: 'ctx.timer (+ interval / timeout / throttle / debounce / setTimeout / setInterval)', summary: 'Disposable timer helpers. The `timer` key is provided at runtime; the six helpers are mixed onto ctx directly (declared via Pick).', source: 'vendor/timer/src/index.ts:4' },
  246. { name: 'ctx.loader', summary: 'The config Loader that booted the app (present under the loader).', source: 'vendor/loader/src/index.ts:30' },
  247. { name: 'ctx.hmr', summary: 'The hot-module-reload watcher (present under the hmr plugin).', source: 'vendor/hmr/src/index.ts:15' },
  248. ]
  249. /** Render the cross-link "Types:" line for a signature, or '' if none apply. */
  250. function typeLinks(signature: string): string {
  251. const seen = new Set<string>()
  252. for (const name of Object.keys(LINK_MAP)) {
  253. if (new RegExp(`\\b${name}\\b`).test(signature)) seen.add(name)
  254. }
  255. if (seen.size === 0) return ''
  256. const links = [...seen].sort().map(n => `[${n}](../core-data-structures/${LINK_MAP[n]})`)
  257. return `Types: ${links.join(' · ')}`
  258. }
  259. /** Render one harness event entry. */
  260. function renderEvent(e: EventEntry): string[] {
  261. const out = [`### \`${e.name}\` — ${e.mode}`, '']
  262. if (e.doc) out.push(e.doc, '')
  263. out.push('```' + FENCE, e.signature, '```', '')
  264. const links = typeLinks(e.signature)
  265. if (links) out.push(links, '')
  266. out.push(`Source: [\`${e.source}\`](../../${e.source.split(':')[0]})`, '')
  267. return out
  268. }
  269. /** Render one harness service entry. */
  270. function renderService(s: ServiceEntry): string[] {
  271. const kind = s.abstract ? ' (abstract seam)' : ''
  272. const out = [`## \`ctx.${s.key}\` — \`${s.type}\`${kind}`, '']
  273. if (s.doc) out.push(s.doc, '')
  274. if (s.methods.length) {
  275. out.push('```' + FENCE, ...s.methods, '```', '')
  276. const links = typeLinks(s.methods.join('\n'))
  277. if (links) out.push(links, '')
  278. }
  279. out.push(`Source: [\`${s.source}\`](../../${s.source.split(':')[0]})`, '')
  280. return out
  281. }
  282. /** The shared generated-file banner comment. */
  283. const BANNER = [
  284. '<!-- Generated by scripts/gen-cordis-catalog.ts — do not edit by hand.',
  285. ' Run `pnpm run gen-cordis-catalog` to regenerate. -->',
  286. '',
  287. ]
  288. /** The shared GENERATED + freshness-gate + fence notice paragraph. */
  289. const GATE_NOTICE = 'This file is GENERATED from source (`scripts/gen-cordis-catalog.ts`) and verified fresh by `pnpm run verify-cordis-catalog` (part of `doc-sync`) — do not edit it by hand. Signature blocks use a `ts cordis-catalog` fence (skipped by doc-typecheck, since a bare signature is not standalone-compilable). Type names in a signature link to the page that documents them.'
  290. /** Render the events catalog (pure, deterministic given sorted inputs). */
  291. function renderEvents(events: EventEntry[]): string {
  292. const lines: string[] = [
  293. ...BANNER,
  294. '# Cordis Events Catalog',
  295. '',
  296. 'Every cordis event a plugin can listen to: exact signature, dispatch mode, and the declaration\'s JSDoc. This is one axis of the **wiring** reference a plugin author works against — the callable `ctx.<key>` surface is the sibling [services catalog](services.md), and [core-data-structures/](../core-data-structures/core.md) catalogs the *data structures* these signatures move around.',
  297. '',
  298. GATE_NOTICE,
  299. '',
  300. 'The **harness tier** below (the `@deepseek-ai/dsh-*` packages) is the vocabulary this repo owns, grouped by scope. The **inherited tier** at the end is the cordis-core + loader/hmr/timer event surface a plugin also sees — pinned vendor source, summarized tersely.',
  301. '',
  302. 'Dispatch modes: **emit** (fire-and-forget), **waterfall** (each listener gets `next()` and may transform or veto — see [waterfall semantics](../cordis-primer.md#cordis-waterfall-semantics)), **parallel** (awaited fan-out; all listeners run), **serial** (awaited in registration order until one returns a bail value — anything other than `null`, `false`, or `undefined`).',
  303. '',
  304. ]
  305. const scopes = [...new Set(events.map(e => e.scope))].sort()
  306. for (const scope of scopes) {
  307. lines.push(`## \`${scope}/*\``, '')
  308. for (const e of events.filter(x => x.scope === scope).sort((a, b) => a.name.localeCompare(b.name))) {
  309. lines.push(...renderEvent(e))
  310. }
  311. }
  312. lines.push(
  313. '## Inherited events (cordis core + loader/hmr/timer)',
  314. '',
  315. 'The framework events every plugin also sees, beyond the harness vocabulary above. This is pinned vendor source ([vendoring policy](../../vendor/README.md)); it is summarized here so the page is a complete picture of the event bus, without elevating framework internals to the harness tier\'s prominence.',
  316. '',
  317. )
  318. for (const e of INHERITED_EVENTS) {
  319. lines.push(`- \`${e.name}\` — ${e.summary} ([\`${e.source}\`](../../${e.source.split(':')[0]}))`)
  320. }
  321. lines.push('')
  322. return lines.join('\n')
  323. }
  324. /** Render the services catalog (pure, deterministic given sorted inputs). */
  325. function renderServices(services: ServiceEntry[]): string {
  326. const lines: string[] = [
  327. ...BANNER,
  328. '# Cordis Services Catalog',
  329. '',
  330. 'Every `ctx.<key>` service a plugin can call: the exact public interface plus the class JSDoc. This is one axis of the **wiring** reference a plugin author works against — the events a plugin listens to are the sibling [events catalog](events.md), and [core-data-structures/](../core-data-structures/core.md) catalogs the *data structures* these signatures move around. An abstract seam (e.g. `ctx.bash`) is implemented by a separate package; the interface is what consumers code against.',
  331. '',
  332. GATE_NOTICE,
  333. '',
  334. 'The **harness tier** below (the `@deepseek-ai/dsh-*` packages) is the vocabulary this repo owns. The **inherited tier** at the end is the cordis-core + loader/hmr/timer `ctx` surface a plugin also sees — pinned vendor source, summarized tersely.',
  335. '',
  336. ]
  337. for (const s of services) lines.push(...renderService(s))
  338. lines.push(
  339. '## Inherited `ctx` members (cordis core + loader/hmr/timer)',
  340. '',
  341. 'The framework `ctx` surface every plugin also sees, beyond the harness services above. This is pinned vendor source ([vendoring policy](../../vendor/README.md)); it is summarized here so the page is a complete picture of what `ctx` offers, without elevating framework internals to the harness tier\'s prominence.',
  342. '',
  343. )
  344. for (const s of INHERITED_SERVICES) {
  345. lines.push(`- \`${s.name}\` — ${s.summary} ([\`${s.source}\`](../../${s.source.split(':')[0]}))`)
  346. }
  347. lines.push('')
  348. return lines.join('\n')
  349. }
  350. /** CLI entry: `--write` (default) writes both catalogs, `--check` fails if
  351. * either is stale. Guarded behind an entry-point check so importing this module
  352. * for tests neither regenerates the committed files nor calls process.exit. */
  353. function main(): void {
  354. const outputs: [string, string][] = [
  355. [OUT_EVENTS, renderEvents(collectEvents())],
  356. [OUT_SERVICES, renderServices(collectServices())],
  357. ]
  358. if (process.argv.includes('--check')) {
  359. const stale: string[] = []
  360. for (const [out, content] of outputs) {
  361. let committed: string | null = null
  362. try {
  363. committed = readFileSync(resolve(root, out), 'utf8')
  364. } catch {
  365. // Only ENOENT (not yet generated) is expected; a present-but-unreadable
  366. // file is not a state this repo produces. Either way the remedy is the
  367. // same — regenerate — so treat a read failure as "stale".
  368. committed = null
  369. }
  370. if (committed !== content) stale.push(out)
  371. }
  372. if (stale.length === 0) {
  373. console.log(`gen-cordis-catalog: ${OUT_EVENTS} and ${OUT_SERVICES} are up to date.`)
  374. process.exit(0)
  375. }
  376. console.error(`gen-cordis-catalog: ${stale.join(' and ')} ${stale.length === 1 ? 'is' : 'are'} stale. Run \`pnpm run gen-cordis-catalog\` and commit the result.`)
  377. process.exit(1)
  378. }
  379. for (const [out, content] of outputs) writeFileSync(resolve(root, out), content)
  380. console.log(`gen-cordis-catalog: wrote ${OUT_EVENTS} and ${OUT_SERVICES}.`)
  381. }
  382. // Run only when invoked as a script, not when imported by a test.
  383. if (process.argv[1] && import.meta.filename === resolve(process.argv[1])) {
  384. main()
  385. }