@hydranium/cli 1.0.0-next.31 → 1.0.0-next.312

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 (252) hide show
  1. package/README.md +79 -205
  2. package/bin/hydranium-cli.js +13 -0
  3. package/heap-analysis/heap/core/load.mjs +2 -2
  4. package/lib/cli-version.js.map +1 -1
  5. package/lib/cli.js +7 -2
  6. package/lib/cli.js.map +1 -1
  7. package/lib/commands/analyze-heap-args.js.map +1 -1
  8. package/lib/commands/analyze-heap.d.ts +3 -0
  9. package/lib/commands/analyze-heap.d.ts.map +1 -1
  10. package/lib/commands/analyze-heap.js +2 -1
  11. package/lib/commands/analyze-heap.js.map +1 -1
  12. package/lib/commands/ast-ground-truth-args.d.ts +3 -2
  13. package/lib/commands/ast-ground-truth-args.d.ts.map +1 -1
  14. package/lib/commands/ast-ground-truth-args.js +11 -9
  15. package/lib/commands/ast-ground-truth-args.js.map +1 -1
  16. package/lib/commands/ast-ground-truth-driver.js +2 -1
  17. package/lib/commands/ast-ground-truth-driver.js.map +1 -1
  18. package/lib/commands/ast-ground-truth.js +1 -1
  19. package/lib/commands/ast-ground-truth.js.map +1 -1
  20. package/lib/commands/client-session.d.ts +17 -0
  21. package/lib/commands/client-session.d.ts.map +1 -0
  22. package/lib/commands/client-session.js +27 -0
  23. package/lib/commands/client-session.js.map +1 -0
  24. package/lib/commands/create-args.d.ts +17 -0
  25. package/lib/commands/create-args.d.ts.map +1 -0
  26. package/lib/commands/create-args.js +53 -0
  27. package/lib/commands/create-args.js.map +1 -0
  28. package/lib/commands/create.d.ts +38 -0
  29. package/lib/commands/create.d.ts.map +1 -0
  30. package/lib/commands/create.js +43 -0
  31. package/lib/commands/create.js.map +1 -0
  32. package/lib/commands/delete-args.d.ts +17 -0
  33. package/lib/commands/delete-args.d.ts.map +1 -0
  34. package/lib/commands/delete-args.js +49 -0
  35. package/lib/commands/delete-args.js.map +1 -0
  36. package/lib/commands/delete.d.ts +30 -0
  37. package/lib/commands/delete.d.ts.map +1 -0
  38. package/lib/commands/delete.js +32 -0
  39. package/lib/commands/delete.js.map +1 -0
  40. package/lib/commands/generate-languages.d.ts +35 -0
  41. package/lib/commands/generate-languages.d.ts.map +1 -0
  42. package/lib/commands/generate-languages.js +105 -0
  43. package/lib/commands/generate-languages.js.map +1 -0
  44. package/lib/commands/generate-transfer-model-args.d.ts.map +1 -1
  45. package/lib/commands/generate-transfer-model-args.js +7 -0
  46. package/lib/commands/generate-transfer-model-args.js.map +1 -1
  47. package/lib/commands/generate-transfer-model-config.d.ts.map +1 -1
  48. package/lib/commands/generate-transfer-model-config.js +6 -3
  49. package/lib/commands/generate-transfer-model-config.js.map +1 -1
  50. package/lib/commands/generate-transfer-model.d.ts +15 -1
  51. package/lib/commands/generate-transfer-model.d.ts.map +1 -1
  52. package/lib/commands/generate-transfer-model.js +46 -8
  53. package/lib/commands/generate-transfer-model.js.map +1 -1
  54. package/lib/commands/harness-args.d.ts +44 -42
  55. package/lib/commands/harness-args.d.ts.map +1 -1
  56. package/lib/commands/harness-args.js +109 -27
  57. package/lib/commands/harness-args.js.map +1 -1
  58. package/lib/commands/headless-harness.d.ts +37 -20
  59. package/lib/commands/headless-harness.d.ts.map +1 -1
  60. package/lib/commands/headless-harness.js +68 -17
  61. package/lib/commands/headless-harness.js.map +1 -1
  62. package/lib/commands/init-args.d.ts.map +1 -1
  63. package/lib/commands/init-args.js +32 -27
  64. package/lib/commands/init-args.js.map +1 -1
  65. package/lib/commands/init-prompt.d.ts +3 -3
  66. package/lib/commands/init-prompt.d.ts.map +1 -1
  67. package/lib/commands/init-prompt.js +4 -5
  68. package/lib/commands/init-prompt.js.map +1 -1
  69. package/lib/commands/init-templates.d.ts +18 -14
  70. package/lib/commands/init-templates.d.ts.map +1 -1
  71. package/lib/commands/init-templates.js +732 -677
  72. package/lib/commands/init-templates.js.map +1 -1
  73. package/lib/commands/init-wizard.d.ts.map +1 -1
  74. package/lib/commands/init-wizard.js +17 -27
  75. package/lib/commands/init-wizard.js.map +1 -1
  76. package/lib/commands/init-workspace.d.ts +13 -11
  77. package/lib/commands/init-workspace.d.ts.map +1 -1
  78. package/lib/commands/init-workspace.js +21 -7
  79. package/lib/commands/init-workspace.js.map +1 -1
  80. package/lib/commands/init.d.ts +45 -19
  81. package/lib/commands/init.d.ts.map +1 -1
  82. package/lib/commands/init.js +80 -43
  83. package/lib/commands/init.js.map +1 -1
  84. package/lib/commands/kebab.d.ts +15 -0
  85. package/lib/commands/kebab.d.ts.map +1 -0
  86. package/lib/commands/kebab.js +17 -0
  87. package/lib/commands/kebab.js.map +1 -0
  88. package/lib/commands/lint-grammar-args.d.ts +3 -2
  89. package/lib/commands/lint-grammar-args.d.ts.map +1 -1
  90. package/lib/commands/lint-grammar-args.js +13 -10
  91. package/lib/commands/lint-grammar-args.js.map +1 -1
  92. package/lib/commands/lint-grammar-driver.js +2 -1
  93. package/lib/commands/lint-grammar-driver.js.map +1 -1
  94. package/lib/commands/lint-grammar-report.js.map +1 -1
  95. package/lib/commands/lint-grammar.js +1 -1
  96. package/lib/commands/lint-grammar.js.map +1 -1
  97. package/lib/commands/measure-memory-args.d.ts +3 -2
  98. package/lib/commands/measure-memory-args.d.ts.map +1 -1
  99. package/lib/commands/measure-memory-args.js +22 -11
  100. package/lib/commands/measure-memory-args.js.map +1 -1
  101. package/lib/commands/measure-memory-driver.js +5 -3
  102. package/lib/commands/measure-memory-driver.js.map +1 -1
  103. package/lib/commands/measure-memory.js +1 -1
  104. package/lib/commands/measure-memory.js.map +1 -1
  105. package/lib/commands/model-docs-args.d.ts +4 -3
  106. package/lib/commands/model-docs-args.d.ts.map +1 -1
  107. package/lib/commands/model-docs-args.js +12 -10
  108. package/lib/commands/model-docs-args.js.map +1 -1
  109. package/lib/commands/model-docs-driver.js +2 -1
  110. package/lib/commands/model-docs-driver.js.map +1 -1
  111. package/lib/commands/model-docs.js +1 -1
  112. package/lib/commands/model-docs.js.map +1 -1
  113. package/lib/commands/projects-args.d.ts.map +1 -1
  114. package/lib/commands/projects-args.js +5 -5
  115. package/lib/commands/projects-args.js.map +1 -1
  116. package/lib/commands/projects.d.ts +3 -4
  117. package/lib/commands/projects.d.ts.map +1 -1
  118. package/lib/commands/projects.js +2 -2
  119. package/lib/commands/projects.js.map +1 -1
  120. package/lib/commands/query-args.d.ts.map +1 -1
  121. package/lib/commands/query-args.js +5 -5
  122. package/lib/commands/query-args.js.map +1 -1
  123. package/lib/commands/query.d.ts +3 -4
  124. package/lib/commands/query.d.ts.map +1 -1
  125. package/lib/commands/query.js +2 -2
  126. package/lib/commands/query.js.map +1 -1
  127. package/lib/commands/reflect-args.d.ts +3 -2
  128. package/lib/commands/reflect-args.d.ts.map +1 -1
  129. package/lib/commands/reflect-args.js +13 -10
  130. package/lib/commands/reflect-args.js.map +1 -1
  131. package/lib/commands/reflect-driver.js +2 -1
  132. package/lib/commands/reflect-driver.js.map +1 -1
  133. package/lib/commands/reflect-report.js.map +1 -1
  134. package/lib/commands/reflect.js +1 -1
  135. package/lib/commands/reflect.js.map +1 -1
  136. package/lib/commands/save-args.d.ts.map +1 -1
  137. package/lib/commands/save-args.js +7 -4
  138. package/lib/commands/save-args.js.map +1 -1
  139. package/lib/commands/save.d.ts +8 -4
  140. package/lib/commands/save.d.ts.map +1 -1
  141. package/lib/commands/save.js +12 -23
  142. package/lib/commands/save.js.map +1 -1
  143. package/lib/commands/validate-args.d.ts +3 -2
  144. package/lib/commands/validate-args.d.ts.map +1 -1
  145. package/lib/commands/validate-args.js +13 -10
  146. package/lib/commands/validate-args.js.map +1 -1
  147. package/lib/commands/validate-driver.js +2 -1
  148. package/lib/commands/validate-driver.js.map +1 -1
  149. package/lib/commands/validate-report.js.map +1 -1
  150. package/lib/commands/validate.js +1 -1
  151. package/lib/commands/validate.js.map +1 -1
  152. package/lib/commands/watch-args.d.ts.map +1 -1
  153. package/lib/commands/watch-args.js +6 -4
  154. package/lib/commands/watch-args.js.map +1 -1
  155. package/lib/commands/watch.d.ts +3 -4
  156. package/lib/commands/watch.d.ts.map +1 -1
  157. package/lib/commands/watch.js +20 -2
  158. package/lib/commands/watch.js.map +1 -1
  159. package/lib/driver-heap.d.ts +52 -0
  160. package/lib/driver-heap.d.ts.map +1 -0
  161. package/lib/driver-heap.js +51 -0
  162. package/lib/driver-heap.js.map +1 -0
  163. package/lib/index.d.ts +2 -0
  164. package/lib/index.d.ts.map +1 -1
  165. package/lib/index.js +2 -0
  166. package/lib/index.js.map +1 -1
  167. package/lib/log-level.d.ts +21 -11
  168. package/lib/log-level.d.ts.map +1 -1
  169. package/lib/log-level.js +25 -14
  170. package/lib/log-level.js.map +1 -1
  171. package/lib/spawn-data-server.d.ts +9 -4
  172. package/lib/spawn-data-server.d.ts.map +1 -1
  173. package/lib/spawn-data-server.js +5 -4
  174. package/lib/spawn-data-server.js.map +1 -1
  175. package/lib/stderr-connection-logger.d.ts +12 -0
  176. package/lib/stderr-connection-logger.d.ts.map +1 -0
  177. package/lib/stderr-connection-logger.js +16 -0
  178. package/lib/stderr-connection-logger.js.map +1 -0
  179. package/lib/testing/echo-server.js +9 -1
  180. package/lib/testing/echo-server.js.map +1 -1
  181. package/package.json +52 -39
  182. package/src/cli.ts +7 -2
  183. package/src/commands/analyze-heap.ts +4 -1
  184. package/src/commands/ast-ground-truth-args.ts +15 -12
  185. package/src/commands/ast-ground-truth-driver.ts +2 -1
  186. package/src/commands/ast-ground-truth.ts +1 -1
  187. package/src/commands/client-session.ts +33 -0
  188. package/src/commands/create-args.ts +68 -0
  189. package/src/commands/create.ts +83 -0
  190. package/src/commands/delete-args.ts +64 -0
  191. package/src/commands/delete.ts +61 -0
  192. package/src/commands/generate-languages.ts +132 -0
  193. package/src/commands/generate-transfer-model-args.ts +7 -0
  194. package/src/commands/generate-transfer-model-config.ts +6 -3
  195. package/src/commands/generate-transfer-model.ts +56 -8
  196. package/src/commands/harness-args.ts +99 -31
  197. package/src/commands/headless-harness.ts +86 -26
  198. package/src/commands/init-args.ts +32 -27
  199. package/src/commands/init-prompt.ts +5 -6
  200. package/src/commands/init-templates.ts +790 -696
  201. package/src/commands/init-wizard.ts +17 -27
  202. package/src/commands/init-workspace.ts +31 -16
  203. package/src/commands/init.ts +126 -58
  204. package/src/commands/kebab.ts +17 -0
  205. package/src/commands/lint-grammar-args.ts +17 -13
  206. package/src/commands/lint-grammar-driver.ts +2 -1
  207. package/src/commands/lint-grammar.ts +1 -1
  208. package/src/commands/measure-memory-args.ts +27 -14
  209. package/src/commands/measure-memory-driver.ts +5 -3
  210. package/src/commands/measure-memory.ts +1 -1
  211. package/src/commands/model-docs-args.ts +16 -13
  212. package/src/commands/model-docs-driver.ts +2 -1
  213. package/src/commands/model-docs.ts +1 -1
  214. package/src/commands/projects-args.ts +5 -4
  215. package/src/commands/projects.ts +4 -6
  216. package/src/commands/query-args.ts +5 -4
  217. package/src/commands/query.ts +4 -6
  218. package/src/commands/reflect-args.ts +17 -13
  219. package/src/commands/reflect-driver.ts +2 -1
  220. package/src/commands/reflect.ts +1 -1
  221. package/src/commands/save-args.ts +7 -3
  222. package/src/commands/save.ts +24 -27
  223. package/src/commands/validate-args.ts +17 -13
  224. package/src/commands/validate-driver.ts +2 -1
  225. package/src/commands/validate.ts +1 -1
  226. package/src/commands/watch-args.ts +6 -3
  227. package/src/commands/watch.ts +28 -7
  228. package/src/driver-heap.ts +65 -0
  229. package/src/index.ts +2 -0
  230. package/src/log-level.ts +42 -14
  231. package/src/spawn-data-server.ts +17 -5
  232. package/src/stderr-connection-logger.ts +18 -0
  233. package/src/testing/echo-server.ts +11 -2
  234. package/templates/gitignore +1 -0
  235. package/templates/protocol/gitignore +3 -0
  236. package/templates/protocol/src/__GRAMMAR_ID__-diagram-types.ts +41 -0
  237. package/templates/server/gitignore +6 -0
  238. package/templates/server/src/glsp/__GRAMMAR_ID__/create-node-operation-handler.ts +62 -0
  239. package/templates/server/src/glsp/__GRAMMAR_ID__/gmodel-factory.ts +60 -0
  240. package/templates/server/src/glsp/__GRAMMAR_ID__/state.ts +18 -0
  241. package/templates/server/src/glsp/__GRAMMAR_ID__/storage.ts +16 -0
  242. package/templates/server/src/glsp/__GRAMMAR_ID__/submission-handler.ts +24 -0
  243. package/templates/server/src/grammar/common.langium +12 -0
  244. package/templates/server/src/language-server/__GRAMMAR_ID__-serializer.ts +53 -0
  245. package/templates/server/src/language-server/ast.ts +23 -0
  246. package/templates/server/src/node/services.ts +16 -0
  247. package/templates/server/test/__GRAMMAR_ID__-diagram.test.ts +112 -0
  248. package/templates/server/test/tsconfig.json +4 -0
  249. package/templates/server/tsconfig.test.json +10 -0
  250. package/templates/server/vitest.config.ts +14 -0
  251. package/templates/workspace/nodes.__EXTENSION__ +5 -0
  252. package/templates/workspace/references.__EXTENSION__ +2 -0
@@ -10,32 +10,34 @@
10
10
  import { runAstGroundTruth, type AstGroundTruthCommandOptions } from './ast-ground-truth.js';
11
11
  import {
12
12
  exitWithUsage,
13
+ HARNESS_VALUE_FLAGS,
13
14
  helpRequested,
14
- LOG_LEVEL_FLAG,
15
- logLevelHelpLine,
16
- logLevelOption,
15
+ importHelpLines,
16
+ LOG_VALUE_FLAGS,
17
+ logHelpLines,
18
+ logOptions,
17
19
  parseHarnessArgs,
18
20
  printHelp,
19
- SERVICES_FLAG,
20
21
  type UsageError
21
22
  } from './harness-args.js';
22
23
  import { OUT_FILE_FLAG } from './headless-harness.js';
23
24
 
24
- const VALUE_FLAGS = [OUT_FILE_FLAG, LOG_LEVEL_FLAG] as const;
25
+ const VALUE_FLAGS = [OUT_FILE_FLAG, ...LOG_VALUE_FLAGS] as const;
25
26
 
26
27
  /**
27
28
  * Every flag `ast-ground-truth` accepts, derived from the sets the parser is
28
- * handed so the list cannot claim a flag the parser would reject. `--services`
29
- * is consumed by the shared harness parser itself, so it is in neither set.
29
+ * handed so the list cannot claim a flag the parser would reject.
30
+ * {@link HARNESS_VALUE_FLAGS} are consumed by the shared harness parser itself,
31
+ * so they are in neither set.
30
32
  */
31
- export const AST_GROUND_TRUTH_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_FLAGS];
33
+ export const AST_GROUND_TRUTH_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS];
32
34
 
33
35
  /** The subset that takes a value, so `--help` in a value position reads as data. */
34
36
  export const AST_GROUND_TRUTH_VALUE_FLAGS: readonly string[] = AST_GROUND_TRUTH_FLAGS;
35
37
 
36
38
  /** The `--help` text, as data, held to {@link AST_GROUND_TRUTH_FLAGS} by a test. */
37
39
  export const AST_GROUND_TRUTH_HELP: readonly string[] = [
38
- 'Usage: hydranium-cli ast-ground-truth --services <module> <workspace> [--out-file <file>] [--log-level <lvl>]',
40
+ 'Usage: hydranium-cli ast-ground-truth --services <module> [--import <specifier>]... <workspace> [--out-file <file>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
39
41
  '',
40
42
  "Tally a workspace's live-model AST nodes by `$type` — the ground truth that",
41
43
  '`analyze-heap --validate <gt.json>` checks a heap snapshot against. `<module>`',
@@ -44,14 +46,15 @@ export const AST_GROUND_TRUTH_HELP: readonly string[] = [
44
46
  '',
45
47
  'Options:',
46
48
  ' --services <module> ESM module exporting `createServices(): { shared }` (required).',
49
+ ...importHelpLines(22),
47
50
  ' <workspace> Workspace root (path or file URI) to build (required).',
48
51
  ' --out-file <file> Write the JSON to this file instead of stdout.',
49
- logLevelHelpLine(22)
52
+ ...logHelpLines(22)
50
53
  ];
51
54
 
52
55
  export function parseAstGroundTruthArgs(args: string[], onError: UsageError = exitWithUsage): AstGroundTruthCommandOptions {
53
- const { servicesModule, workspace, options } = parseHarnessArgs(args, 'ast-ground-truth', VALUE_FLAGS, [], { onError });
54
- return { servicesModule, workspace, outFile: options[OUT_FILE_FLAG], logLevel: logLevelOption(options[LOG_LEVEL_FLAG]) };
56
+ const { servicesModule, imports, workspace, options } = parseHarnessArgs(args, 'ast-ground-truth', VALUE_FLAGS, [], { onError });
57
+ return { servicesModule, imports, workspace, outFile: options[OUT_FILE_FLAG], ...logOptions(options) };
55
58
  }
56
59
 
57
60
  export function runAstGroundTruthCommand(args: string[]): Promise<void> {
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  import * as fs from 'node:fs';
19
+ import { describeError } from '@hydranium/protocol';
19
20
  import { loadHeadlessContext, OUT_FILE_FLAG } from './headless-harness.js';
20
21
 
21
22
  interface DriverArgs {
@@ -76,6 +77,6 @@ async function main(argv: string[]): Promise<void> {
76
77
  main(process.argv.slice(2))
77
78
  .then(() => process.exit(0))
78
79
  .catch((error: unknown) => {
79
- console.error(error instanceof Error ? error.message : String(error));
80
+ console.error(describeError(error));
80
81
  process.exit(1);
81
82
  });
@@ -45,5 +45,5 @@ export function buildGroundTruthDriverArgs(options: AstGroundTruthCommandOptions
45
45
  * `--out-file`). No `--expose-gc` needed — this walks the AST, it does not weigh it.
46
46
  */
47
47
  export function runAstGroundTruth(options: AstGroundTruthCommandOptions): Promise<void> {
48
- return runDriverChild(['--max-old-space-size=8192', DRIVER, ...buildGroundTruthDriverArgs(options)], options);
48
+ return runDriverChild([DRIVER, ...buildGroundTruthDriverArgs(options)], options);
49
49
  }
@@ -0,0 +1,33 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import type { TransferElement } from '@hydranium/protocol';
11
+ import type { DataServerProtocol } from '@hydranium/protocol/data';
12
+
13
+ /**
14
+ * Run `fn` as the client session `clientId`, and end the session whether `fn`
15
+ * succeeded or not, which closes whatever it left open. An end that fails
16
+ * after a failed `fn` is swallowed: `fn`'s error is the one the user needs.
17
+ */
18
+ export async function withClientSession<T>(
19
+ server: Pick<DataServerProtocol<TransferElement>, 'createSession' | 'closeSession'>,
20
+ clientId: string,
21
+ fn: () => Promise<T>
22
+ ): Promise<T> {
23
+ await server.createSession({ clientId, label: 'hydranium-cli' });
24
+ let result: T;
25
+ try {
26
+ result = await fn();
27
+ } catch (error: unknown) {
28
+ await server.closeSession({ clientId }).catch(() => undefined);
29
+ throw error;
30
+ }
31
+ await server.closeSession({ clientId });
32
+ return result;
33
+ }
@@ -0,0 +1,68 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import {
11
+ assertRequired,
12
+ exitWithUsage,
13
+ helpRequested,
14
+ logHelpLines,
15
+ parseFlagOptions,
16
+ parseServerSpawnOptions,
17
+ printHelp,
18
+ SERVER_SPAWN_VALUE_FLAGS,
19
+ type UsageError
20
+ } from './harness-args.js';
21
+ import { type CreateCommandOptions, runCreate } from './create.js';
22
+
23
+ const OWN_FLAGS = ['--uri', '--content', '--client-id'] as const;
24
+
25
+ /** Every flag `create` accepts, each of which takes a value. */
26
+ export const CREATE_FLAGS: readonly string[] = [...SERVER_SPAWN_VALUE_FLAGS, ...OWN_FLAGS];
27
+
28
+ /** The `--help` text, as data, held to {@link CREATE_FLAGS} by a test. */
29
+ export const CREATE_HELP: readonly string[] = [
30
+ 'Usage: hydranium-cli create --server "<cmd>..." --uri <uri> --content <text|@file> [--client-id <id>] [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
31
+ '',
32
+ 'Create the document at `<uri>` with `<content>` via createModelDocument, and persist it',
33
+ 'as given. Fails when the file exists or a client has it open.',
34
+ 'Output is the post-save envelope as a single JSON line.',
35
+ '',
36
+ 'Options:',
37
+ ' --server "<cmd>" Command-line for the data-server subprocess (required).',
38
+ ' --uri <uri> Document URI (required).',
39
+ ' --content <text> Content to write (required). Prefix `@` to read from a file',
40
+ ' (escape with `\\@` for literal `@`-leading content).',
41
+ ' --client-id <id> clientId for authorship attribution. Default: hydranium-cli.',
42
+ ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
43
+ ...logHelpLines(22, 'the spawned server')
44
+ ];
45
+
46
+ export function parseCreateArgs(args: string[], onError: UsageError = exitWithUsage): CreateCommandOptions {
47
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'create', onError);
48
+ const { uri, content, clientId } = parseFlagOptions(extra, 'create', OWN_FLAGS, onError);
49
+ return {
50
+ serverCommand,
51
+ serverArgs,
52
+ cwd,
53
+ logLevel,
54
+ logFile,
55
+ logFileLevel,
56
+ uri: assertRequired(uri, '--uri', 'create', onError),
57
+ content: assertRequired(content, '--content', 'create', onError),
58
+ clientId
59
+ };
60
+ }
61
+
62
+ export function runCreateCommand(args: string[]): Promise<void> {
63
+ if (helpRequested(args, CREATE_FLAGS)) {
64
+ printHelp(CREATE_HELP);
65
+ return Promise.resolve();
66
+ }
67
+ return runCreate(parseCreateArgs(args));
68
+ }
@@ -0,0 +1,83 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import type { TransferElement } from '@hydranium/protocol';
11
+ import type { DataServerProtocol } from '@hydranium/protocol/data';
12
+ import { logEnv, type LogOptions } from '../log-level.js';
13
+ import { withDataServer } from '../spawn-data-server.js';
14
+ import { withClientSession } from './client-session.js';
15
+ import { resolveContent } from './harness-args.js';
16
+
17
+ /**
18
+ * Options for the {@link runCreate} subcommand. Creates the document at `uri`
19
+ * with `content` (literal text or `@<path>` for a file reference) via the
20
+ * data-server's `createModelDocument` RPC, and persists that text as it is.
21
+ * Fails when the file exists or a client has it open. Writes the post-save
22
+ * envelope as a single JSON line, as `save` does.
23
+ *
24
+ * `clientId` defaults to `'hydranium-cli'`. The command creates as a client
25
+ * session under it: it registers the session, creates the document, persists
26
+ * it, since a created document reaches disk only with a save, and ends the
27
+ * session.
28
+ */
29
+ export interface CreateCommandOptions extends LogOptions {
30
+ readonly serverCommand: string;
31
+ readonly serverArgs?: readonly string[];
32
+ readonly cwd?: string;
33
+ readonly uri: string;
34
+ /** Literal content text, or `@<path>` to read from a file. */
35
+ readonly content: string;
36
+ readonly clientId?: string;
37
+ readonly write?: (line: string) => void;
38
+ readonly __proxyForTest?: DataServerProtocol<TransferElement>;
39
+ /** Test-only: override the file-reader so unit tests can stub `@<path>` expansion. */
40
+ readonly __readFileForTest?: (path: string) => Promise<string>;
41
+ }
42
+
43
+ export async function runCreate(options: CreateCommandOptions): Promise<void> {
44
+ const write = options.write ?? ((line: string) => process.stdout.write(line));
45
+ const clientId = options.clientId ?? 'hydranium-cli';
46
+ const text = await resolveContent(options.content, options.__readFileForTest);
47
+
48
+ if (options.__proxyForTest) {
49
+ write(`${JSON.stringify(await createPersisted(options.__proxyForTest, options.uri, clientId, text))}\n`);
50
+ return;
51
+ }
52
+
53
+ await withDataServer(
54
+ {
55
+ command: options.serverCommand,
56
+ args: options.serverArgs,
57
+ cwd: options.cwd,
58
+ env: logEnv(options)
59
+ },
60
+ async server => {
61
+ write(`${JSON.stringify(await createPersisted(server, options.uri, clientId, text))}\n`);
62
+ }
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Create `uri` with `text` as the session `clientId` and persist it, then end
68
+ * the session. The persist is gated on the version the create made, so a
69
+ * write that landed before the create's answer or after it, another client's
70
+ * or an integrity repair, fails the command with a conflict and nothing
71
+ * persists.
72
+ */
73
+ function createPersisted(
74
+ server: Pick<DataServerProtocol<TransferElement>, 'createSession' | 'createModelDocument' | 'persistModelDocument' | 'closeSession'>,
75
+ uri: string,
76
+ clientId: string,
77
+ text: string
78
+ ): Promise<unknown> {
79
+ return withClientSession(server, clientId, async () => {
80
+ const created = await server.createModelDocument({ uri, clientId, text });
81
+ return server.persistModelDocument({ uri, clientId, baseVersion: created.created.version });
82
+ });
83
+ }
@@ -0,0 +1,64 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import {
11
+ assertRequired,
12
+ exitWithUsage,
13
+ helpRequested,
14
+ logHelpLines,
15
+ parseFlagOptions,
16
+ parseServerSpawnOptions,
17
+ printHelp,
18
+ SERVER_SPAWN_VALUE_FLAGS,
19
+ type UsageError
20
+ } from './harness-args.js';
21
+ import { type DeleteCommandOptions, runDelete } from './delete.js';
22
+
23
+ const OWN_FLAGS = ['--uri', '--client-id'] as const;
24
+
25
+ /** Every flag `delete` accepts, each of which takes a value. */
26
+ export const DELETE_FLAGS: readonly string[] = [...SERVER_SPAWN_VALUE_FLAGS, ...OWN_FLAGS];
27
+
28
+ /** The `--help` text, as data, held to {@link DELETE_FLAGS} by a test. */
29
+ export const DELETE_HELP: readonly string[] = [
30
+ 'Usage: hydranium-cli delete --server "<cmd>..." --uri <uri> [--client-id <id>] [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
31
+ '',
32
+ 'Delete the document at `<uri>`, its file and then the document, via deleteModelDocument,',
33
+ 'whatever text it holds. Prints nothing.',
34
+ '',
35
+ 'Options:',
36
+ ' --server "<cmd>" Command-line for the data-server subprocess (required).',
37
+ ' --uri <uri> Document URI (required).',
38
+ ' --client-id <id> clientId the deletion is attributed to. Default: hydranium-cli.',
39
+ ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
40
+ ...logHelpLines(22, 'the spawned server')
41
+ ];
42
+
43
+ export function parseDeleteArgs(args: string[], onError: UsageError = exitWithUsage): DeleteCommandOptions {
44
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'delete', onError);
45
+ const { uri, clientId } = parseFlagOptions(extra, 'delete', OWN_FLAGS, onError);
46
+ return {
47
+ serverCommand,
48
+ serverArgs,
49
+ cwd,
50
+ logLevel,
51
+ logFile,
52
+ logFileLevel,
53
+ uri: assertRequired(uri, '--uri', 'delete', onError),
54
+ clientId
55
+ };
56
+ }
57
+
58
+ export function runDeleteCommand(args: string[]): Promise<void> {
59
+ if (helpRequested(args, DELETE_FLAGS)) {
60
+ printHelp(DELETE_HELP);
61
+ return Promise.resolve();
62
+ }
63
+ return runDelete(parseDeleteArgs(args));
64
+ }
@@ -0,0 +1,61 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import type { TransferElement } from '@hydranium/protocol';
11
+ import type { DataServerProtocol } from '@hydranium/protocol/data';
12
+ import { logEnv, type LogOptions } from '../log-level.js';
13
+ import { withDataServer } from '../spawn-data-server.js';
14
+ import { withClientSession } from './client-session.js';
15
+
16
+ /**
17
+ * Options for the {@link runDelete} subcommand. Deletes the document at `uri`,
18
+ * its file and then the document, via the data-server's `deleteModelDocument`
19
+ * RPC, whatever text it holds. Prints nothing; a failed delete rejects.
20
+ *
21
+ * `clientId` defaults to `'hydranium-cli'`. The command deletes as a client
22
+ * session under it: it registers the session, opens the document, deletes it,
23
+ * and ends the session.
24
+ */
25
+ export interface DeleteCommandOptions extends LogOptions {
26
+ readonly serverCommand: string;
27
+ readonly serverArgs?: readonly string[];
28
+ readonly cwd?: string;
29
+ readonly uri: string;
30
+ readonly clientId?: string;
31
+ readonly __proxyForTest?: DataServerProtocol<TransferElement>;
32
+ }
33
+
34
+ export async function runDelete(options: DeleteCommandOptions): Promise<void> {
35
+ const clientId = options.clientId ?? 'hydranium-cli';
36
+ if (options.__proxyForTest) {
37
+ await deleteOpened(options.__proxyForTest, options.uri, clientId);
38
+ return;
39
+ }
40
+ await withDataServer(
41
+ {
42
+ command: options.serverCommand,
43
+ args: options.serverArgs,
44
+ cwd: options.cwd,
45
+ env: logEnv(options)
46
+ },
47
+ server => deleteOpened(server, options.uri, clientId)
48
+ );
49
+ }
50
+
51
+ /** Open `uri` as the session `clientId` and delete it, then end the session. */
52
+ function deleteOpened(
53
+ server: Pick<DataServerProtocol<TransferElement>, 'createSession' | 'openModelDocument' | 'deleteModelDocument' | 'closeSession'>,
54
+ uri: string,
55
+ clientId: string
56
+ ): Promise<void> {
57
+ return withClientSession(server, clientId, async () => {
58
+ await server.openModelDocument({ uri, clientId });
59
+ await server.deleteModelDocument({ uri, clientId, baseVersion: 'any' });
60
+ });
61
+ }
@@ -0,0 +1,132 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import * as fs from 'fs';
11
+ import * as path from 'path';
12
+ import { kebab } from './kebab.js';
13
+ import { type Expression, type ObjectLiteralExpression, type SourceFile, SyntaxKind } from 'ts-morph';
14
+
15
+ /** Inputs for {@link emitLanguages}, resolved by the transfer-model command. */
16
+ export interface EmitLanguagesOptions {
17
+ /** Destination path for the generated languages module. */
18
+ outFile: string;
19
+ /** Header line naming the command that regenerates the file. */
20
+ regenCommand: string;
21
+ }
22
+
23
+ interface LanguageEntry {
24
+ constName: string;
25
+ languageId: string;
26
+ fileExtensions: string[];
27
+ }
28
+
29
+ /** Suffix langium-cli gives each grammar's metadata const in `module.ts`. */
30
+ const METADATA_SUFFIX = 'LanguageMetaData';
31
+
32
+ /**
33
+ * Emit a module stating each grammar's language id and file extensions for a
34
+ * package a client can depend on.
35
+ *
36
+ * Read from the `<Grammar>LanguageMetaData` consts langium-cli writes into
37
+ * `module.ts`, which is the only place the ids exist outside `langium-config.json`
38
+ * and which a client cannot import, since it pulls in Langium. Generating the
39
+ * copy instead of writing it by hand is what keeps every host's id list in step
40
+ * with the grammars.
41
+ */
42
+ export function emitLanguages(moduleSource: SourceFile, options: EmitLanguagesOptions): void {
43
+ const content = buildLanguagesSource(moduleSource, options);
44
+ fs.mkdirSync(path.dirname(options.outFile), { recursive: true });
45
+ if (fs.existsSync(options.outFile) && fs.readFileSync(options.outFile, 'utf-8') === content) {
46
+ console.log('Languages module is up to date.');
47
+ return;
48
+ }
49
+ fs.writeFileSync(options.outFile, content, 'utf-8');
50
+ console.log(`Generated: ${options.outFile}`);
51
+ }
52
+
53
+ /**
54
+ * The module text {@link emitLanguages} would write. Pure over its inputs, so
55
+ * the emitted shape is testable without touching a filesystem. Throws when the
56
+ * source declares no metadata, since an empty list would make every host
57
+ * register nothing without an error.
58
+ */
59
+ export function buildLanguagesSource(moduleSource: SourceFile, options: Pick<EmitLanguagesOptions, 'regenCommand'>): string {
60
+ const entries: LanguageEntry[] = [];
61
+ const grammarsByConst = new Map<string, string>();
62
+ for (const declaration of moduleSource.getVariableDeclarations()) {
63
+ const name = declaration.getName();
64
+ if (!name.endsWith(METADATA_SUFFIX)) {
65
+ continue;
66
+ }
67
+ const literal = objectLiteralOf(declaration.getInitializer());
68
+ const grammar = name.slice(0, -METADATA_SUFFIX.length);
69
+ const constName = `${kebab(grammar).replace(/-/g, '_').toUpperCase()}_LANGUAGE`;
70
+ const clash = grammarsByConst.get(constName);
71
+ if (clash !== undefined) {
72
+ throw new Error(
73
+ `Cannot emit the languages module: grammars '${clash}' and '${grammar}' both map to '${constName}'. ` +
74
+ 'Rename one grammar so the generated constants stay distinct.'
75
+ );
76
+ }
77
+ grammarsByConst.set(constName, grammar);
78
+ entries.push({
79
+ constName,
80
+ languageId: stringProperty(literal, name, 'languageId'),
81
+ fileExtensions: stringArrayProperty(literal, name, 'fileExtensions')
82
+ });
83
+ }
84
+ if (entries.length === 0) {
85
+ throw new Error(`Cannot emit the languages module: ${moduleSource.getFilePath()} declares no '<Grammar>${METADATA_SUFFIX}'.`);
86
+ }
87
+
88
+ const out: string[] = [];
89
+ out.push('/******************************************************************************');
90
+ out.push(' * Generated from the Langium language metadata — DO NOT EDIT MANUALLY!');
91
+ out.push(` * ${options.regenCommand}`);
92
+ out.push(' ******************************************************************************/');
93
+ out.push('');
94
+ for (const entry of entries) {
95
+ const extensions = entry.fileExtensions.map(extension => JSON.stringify(extension)).join(', ');
96
+ out.push(
97
+ `export const ${entry.constName} = { languageId: ${JSON.stringify(entry.languageId)}, fileExtensions: [${extensions}] } as const;`
98
+ );
99
+ }
100
+ out.push('');
101
+ out.push('/** Every language of the project, in the order langium-cli declares them. */');
102
+ out.push(`export const ALL_LANGUAGES = [${entries.map(entry => entry.constName).join(', ')}] as const;`);
103
+ return out.join('\n') + '\n';
104
+ }
105
+
106
+ /** The object literal under `as const` / `satisfies` wrappers, which langium-cli adds. */
107
+ function objectLiteralOf(initializer: Expression | undefined): ObjectLiteralExpression | undefined {
108
+ return (
109
+ initializer?.asKind(SyntaxKind.ObjectLiteralExpression) ?? initializer?.getFirstDescendantByKind(SyntaxKind.ObjectLiteralExpression)
110
+ );
111
+ }
112
+
113
+ function stringProperty(literal: ObjectLiteralExpression | undefined, owner: string, key: string): string {
114
+ const value = literal?.getProperty(key)?.asKind(SyntaxKind.PropertyAssignment)?.getInitializer()?.asKind(SyntaxKind.StringLiteral);
115
+ if (value === undefined) {
116
+ throw new Error(`Cannot emit the languages module: ${owner} has no string '${key}'.`);
117
+ }
118
+ return value.getLiteralValue();
119
+ }
120
+
121
+ function stringArrayProperty(literal: ObjectLiteralExpression | undefined, owner: string, key: string): string[] {
122
+ const array = literal
123
+ ?.getProperty(key)
124
+ ?.asKind(SyntaxKind.PropertyAssignment)
125
+ ?.getInitializer()
126
+ ?.asKind(SyntaxKind.ArrayLiteralExpression);
127
+ const values = array?.getElements().map(element => element.asKind(SyntaxKind.StringLiteral)?.getLiteralValue());
128
+ if (values === undefined || !values.every((value): value is string => value !== undefined)) {
129
+ throw new Error(`Cannot emit the languages module: ${owner} has no string array '${key}'.`);
130
+ }
131
+ return values;
132
+ }
@@ -30,6 +30,7 @@ export const GENERATE_TRANSFER_MODEL_FLAGS: readonly string[] = [
30
30
  '--augmentation-file',
31
31
  '--out-file',
32
32
  '--ast-builder-file',
33
+ '--languages-file',
33
34
  '--element-type-name',
34
35
  '--terminals-name',
35
36
  '--terminals-source-name',
@@ -74,6 +75,9 @@ export const GENERATE_TRANSFER_MODEL_HELP: readonly string[] = [
74
75
  ' spanning all of them. Omit if nothing constructs',
75
76
  ' AST nodes. Same restriction as --out-file: keep it',
76
77
  " out of langium-cli's own `out` directory.",
78
+ " --languages-file <path> Also emit each grammar's language id and file",
79
+ ' extensions here, read from the module.ts beside',
80
+ ' --ast-file, for a package without Langium.',
77
81
  ' --element-type-name <name> Base element type name in output. Default: TransferElement.',
78
82
  ' --terminals-name <name> Terminals const name in output. Default: ModelTerminals.',
79
83
  ' --terminals-source-name <n> Source-side terminals variable name. Default: <LanguageId>Terminals.',
@@ -130,6 +134,9 @@ export function parseGenerateOptions(args: string[], onError: UsageError = exitW
130
134
  case '--ast-builder-file':
131
135
  flags.astBuilderFile = next();
132
136
  break;
137
+ case '--languages-file':
138
+ flags.languagesFile = next();
139
+ break;
133
140
  case '--element-type-name':
134
141
  flags.elementTypeName = next();
135
142
  break;
@@ -9,10 +9,11 @@
9
9
 
10
10
  import * as fs from 'node:fs';
11
11
  import * as path from 'node:path';
12
+ import { describeError } from '@hydranium/protocol';
12
13
  import type { GenerateTransferModelOptions } from './generate-transfer-model.js';
13
14
 
14
15
  /** Path-valued option keys — resolved relative to a config/langium-config file's directory. */
15
- const PATH_KEYS = ['astFile', 'augmentationFile', 'outFile', 'astBuilderFile'] as const;
16
+ const PATH_KEYS = ['astFile', 'augmentationFile', 'outFile', 'astBuilderFile', 'languagesFile'] as const;
16
17
 
17
18
  /** Resolve `value` against `baseDir` when it is relative; absolute paths pass through. */
18
19
  function resolveAgainst(baseDir: string, value: string): string {
@@ -31,7 +32,7 @@ export function loadTransferModelConfig(configPath: string): Partial<GenerateTra
31
32
  try {
32
33
  raw = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
33
34
  } catch (error: unknown) {
34
- throw new Error(`Cannot read transfer-model config '${configPath}': ${error instanceof Error ? error.message : String(error)}`);
35
+ throw new Error(`Cannot read transfer-model config '${configPath}': ${describeError(error)}`);
35
36
  }
36
37
  if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
37
38
  throw new Error(`Transfer-model config '${configPath}' must be a JSON object.`);
@@ -44,6 +45,7 @@ export function loadTransferModelConfig(configPath: string): Partial<GenerateTra
44
45
  'augmentationFile',
45
46
  'outFile',
46
47
  'astBuilderFile',
48
+ 'languagesFile',
47
49
  'elementTypeName',
48
50
  'terminalsName',
49
51
  'terminalsSourceName',
@@ -75,7 +77,7 @@ export function deriveAstFileFromLangiumConfig(langiumConfigPath: string): strin
75
77
  try {
76
78
  raw = JSON.parse(fs.readFileSync(langiumConfigPath, 'utf-8'));
77
79
  } catch (error: unknown) {
78
- throw new Error(`Cannot read langium-config '${langiumConfigPath}': ${error instanceof Error ? error.message : String(error)}`);
80
+ throw new Error(`Cannot read langium-config '${langiumConfigPath}': ${describeError(error)}`);
79
81
  }
80
82
  const out = (raw as { out?: unknown })?.out;
81
83
  if (typeof out !== 'string') {
@@ -120,6 +122,7 @@ export function mergeTransferModelOptions(...sources: Array<Partial<GenerateTran
120
122
  augmentationFile: augmentationFile!,
121
123
  outFile: outFile!,
122
124
  astBuilderFile: pick('astBuilderFile'),
125
+ languagesFile: pick('languagesFile'),
123
126
  elementTypeName: pick('elementTypeName'),
124
127
  terminalsName: pick('terminalsName'),
125
128
  terminalsSourceName: pick('terminalsSourceName'),