@hydranium/cli 1.0.0-next.30 → 1.0.0-next.301

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 (222) hide show
  1. package/README.md +75 -204
  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-ast-builder.d.ts +49 -0
  41. package/lib/commands/generate-ast-builder.d.ts.map +1 -0
  42. package/lib/commands/generate-ast-builder.js +200 -0
  43. package/lib/commands/generate-ast-builder.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 +11 -1
  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 +9 -0
  51. package/lib/commands/generate-transfer-model.d.ts.map +1 -1
  52. package/lib/commands/generate-transfer-model.js +18 -4
  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.js +6 -6
  63. package/lib/commands/init-args.js.map +1 -1
  64. package/lib/commands/init-prompt.d.ts.map +1 -1
  65. package/lib/commands/init-templates.d.ts +8 -10
  66. package/lib/commands/init-templates.d.ts.map +1 -1
  67. package/lib/commands/init-templates.js +261 -167
  68. package/lib/commands/init-templates.js.map +1 -1
  69. package/lib/commands/init-wizard.js +4 -4
  70. package/lib/commands/init-wizard.js.map +1 -1
  71. package/lib/commands/init-workspace.d.ts +13 -3
  72. package/lib/commands/init-workspace.d.ts.map +1 -1
  73. package/lib/commands/init-workspace.js +21 -6
  74. package/lib/commands/init-workspace.js.map +1 -1
  75. package/lib/commands/init.d.ts +16 -10
  76. package/lib/commands/init.d.ts.map +1 -1
  77. package/lib/commands/init.js +17 -15
  78. package/lib/commands/init.js.map +1 -1
  79. package/lib/commands/lint-grammar-args.d.ts +3 -2
  80. package/lib/commands/lint-grammar-args.d.ts.map +1 -1
  81. package/lib/commands/lint-grammar-args.js +13 -10
  82. package/lib/commands/lint-grammar-args.js.map +1 -1
  83. package/lib/commands/lint-grammar-driver.js +2 -1
  84. package/lib/commands/lint-grammar-driver.js.map +1 -1
  85. package/lib/commands/lint-grammar-report.js.map +1 -1
  86. package/lib/commands/lint-grammar.js +1 -1
  87. package/lib/commands/lint-grammar.js.map +1 -1
  88. package/lib/commands/measure-memory-args.d.ts +3 -2
  89. package/lib/commands/measure-memory-args.d.ts.map +1 -1
  90. package/lib/commands/measure-memory-args.js +22 -11
  91. package/lib/commands/measure-memory-args.js.map +1 -1
  92. package/lib/commands/measure-memory-driver.js +5 -3
  93. package/lib/commands/measure-memory-driver.js.map +1 -1
  94. package/lib/commands/measure-memory.js +1 -1
  95. package/lib/commands/measure-memory.js.map +1 -1
  96. package/lib/commands/model-docs-args.d.ts +4 -3
  97. package/lib/commands/model-docs-args.d.ts.map +1 -1
  98. package/lib/commands/model-docs-args.js +12 -10
  99. package/lib/commands/model-docs-args.js.map +1 -1
  100. package/lib/commands/model-docs-driver.js +2 -1
  101. package/lib/commands/model-docs-driver.js.map +1 -1
  102. package/lib/commands/model-docs.js +1 -1
  103. package/lib/commands/model-docs.js.map +1 -1
  104. package/lib/commands/projects-args.d.ts.map +1 -1
  105. package/lib/commands/projects-args.js +5 -5
  106. package/lib/commands/projects-args.js.map +1 -1
  107. package/lib/commands/projects.d.ts +3 -4
  108. package/lib/commands/projects.d.ts.map +1 -1
  109. package/lib/commands/projects.js +2 -2
  110. package/lib/commands/projects.js.map +1 -1
  111. package/lib/commands/query-args.d.ts.map +1 -1
  112. package/lib/commands/query-args.js +5 -5
  113. package/lib/commands/query-args.js.map +1 -1
  114. package/lib/commands/query.d.ts +3 -4
  115. package/lib/commands/query.d.ts.map +1 -1
  116. package/lib/commands/query.js +2 -2
  117. package/lib/commands/query.js.map +1 -1
  118. package/lib/commands/reflect-args.d.ts +3 -2
  119. package/lib/commands/reflect-args.d.ts.map +1 -1
  120. package/lib/commands/reflect-args.js +13 -10
  121. package/lib/commands/reflect-args.js.map +1 -1
  122. package/lib/commands/reflect-driver.js +2 -1
  123. package/lib/commands/reflect-driver.js.map +1 -1
  124. package/lib/commands/reflect-report.js.map +1 -1
  125. package/lib/commands/reflect.js +1 -1
  126. package/lib/commands/reflect.js.map +1 -1
  127. package/lib/commands/save-args.d.ts.map +1 -1
  128. package/lib/commands/save-args.js +7 -4
  129. package/lib/commands/save-args.js.map +1 -1
  130. package/lib/commands/save.d.ts +8 -4
  131. package/lib/commands/save.d.ts.map +1 -1
  132. package/lib/commands/save.js +12 -23
  133. package/lib/commands/save.js.map +1 -1
  134. package/lib/commands/validate-args.d.ts +3 -2
  135. package/lib/commands/validate-args.d.ts.map +1 -1
  136. package/lib/commands/validate-args.js +13 -10
  137. package/lib/commands/validate-args.js.map +1 -1
  138. package/lib/commands/validate-driver.js +2 -1
  139. package/lib/commands/validate-driver.js.map +1 -1
  140. package/lib/commands/validate-report.js.map +1 -1
  141. package/lib/commands/validate.js +1 -1
  142. package/lib/commands/validate.js.map +1 -1
  143. package/lib/commands/watch-args.d.ts.map +1 -1
  144. package/lib/commands/watch-args.js +6 -4
  145. package/lib/commands/watch-args.js.map +1 -1
  146. package/lib/commands/watch.d.ts +3 -4
  147. package/lib/commands/watch.d.ts.map +1 -1
  148. package/lib/commands/watch.js +20 -2
  149. package/lib/commands/watch.js.map +1 -1
  150. package/lib/driver-heap.d.ts +52 -0
  151. package/lib/driver-heap.d.ts.map +1 -0
  152. package/lib/driver-heap.js +51 -0
  153. package/lib/driver-heap.js.map +1 -0
  154. package/lib/index.d.ts +3 -0
  155. package/lib/index.d.ts.map +1 -1
  156. package/lib/index.js +3 -0
  157. package/lib/index.js.map +1 -1
  158. package/lib/log-level.d.ts +21 -11
  159. package/lib/log-level.d.ts.map +1 -1
  160. package/lib/log-level.js +25 -14
  161. package/lib/log-level.js.map +1 -1
  162. package/lib/spawn-data-server.d.ts +9 -4
  163. package/lib/spawn-data-server.d.ts.map +1 -1
  164. package/lib/spawn-data-server.js +5 -4
  165. package/lib/spawn-data-server.js.map +1 -1
  166. package/lib/stderr-connection-logger.d.ts +12 -0
  167. package/lib/stderr-connection-logger.d.ts.map +1 -0
  168. package/lib/stderr-connection-logger.js +16 -0
  169. package/lib/stderr-connection-logger.js.map +1 -0
  170. package/lib/testing/echo-server.js +9 -1
  171. package/lib/testing/echo-server.js.map +1 -1
  172. package/package.json +50 -39
  173. package/src/cli.ts +7 -2
  174. package/src/commands/analyze-heap.ts +4 -1
  175. package/src/commands/ast-ground-truth-args.ts +15 -12
  176. package/src/commands/ast-ground-truth-driver.ts +2 -1
  177. package/src/commands/ast-ground-truth.ts +1 -1
  178. package/src/commands/client-session.ts +33 -0
  179. package/src/commands/create-args.ts +68 -0
  180. package/src/commands/create.ts +83 -0
  181. package/src/commands/delete-args.ts +64 -0
  182. package/src/commands/delete.ts +61 -0
  183. package/src/commands/generate-ast-builder.ts +246 -0
  184. package/src/commands/generate-transfer-model-args.ts +11 -1
  185. package/src/commands/generate-transfer-model-config.ts +6 -3
  186. package/src/commands/generate-transfer-model.ts +27 -4
  187. package/src/commands/harness-args.ts +99 -31
  188. package/src/commands/headless-harness.ts +86 -26
  189. package/src/commands/init-args.ts +6 -6
  190. package/src/commands/init-templates.ts +272 -169
  191. package/src/commands/init-wizard.ts +4 -4
  192. package/src/commands/init-workspace.ts +31 -7
  193. package/src/commands/init.ts +36 -26
  194. package/src/commands/lint-grammar-args.ts +17 -13
  195. package/src/commands/lint-grammar-driver.ts +2 -1
  196. package/src/commands/lint-grammar.ts +1 -1
  197. package/src/commands/measure-memory-args.ts +27 -14
  198. package/src/commands/measure-memory-driver.ts +5 -3
  199. package/src/commands/measure-memory.ts +1 -1
  200. package/src/commands/model-docs-args.ts +16 -13
  201. package/src/commands/model-docs-driver.ts +2 -1
  202. package/src/commands/model-docs.ts +1 -1
  203. package/src/commands/projects-args.ts +5 -4
  204. package/src/commands/projects.ts +4 -6
  205. package/src/commands/query-args.ts +5 -4
  206. package/src/commands/query.ts +4 -6
  207. package/src/commands/reflect-args.ts +17 -13
  208. package/src/commands/reflect-driver.ts +2 -1
  209. package/src/commands/reflect.ts +1 -1
  210. package/src/commands/save-args.ts +7 -3
  211. package/src/commands/save.ts +24 -27
  212. package/src/commands/validate-args.ts +17 -13
  213. package/src/commands/validate-driver.ts +2 -1
  214. package/src/commands/validate.ts +1 -1
  215. package/src/commands/watch-args.ts +6 -3
  216. package/src/commands/watch.ts +28 -7
  217. package/src/driver-heap.ts +65 -0
  218. package/src/index.ts +3 -0
  219. package/src/log-level.ts +42 -14
  220. package/src/spawn-data-server.ts +17 -5
  221. package/src/stderr-connection-logger.ts +18 -0
  222. package/src/testing/echo-server.ts +11 -2
package/src/log-level.ts CHANGED
@@ -7,29 +7,47 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import { DEFAULT_LOG_LEVEL_ENV, LEVEL_ORDER, parseLogLevel, type LogThreshold } from '@hydranium/protocol';
10
+ import {
11
+ DEFAULT_LOG_FILE_ENV,
12
+ DEFAULT_LOG_FILE_LEVEL_ENV,
13
+ DEFAULT_LOG_LEVEL_ENV,
14
+ LEVEL_ORDER,
15
+ parseLogLevel,
16
+ type LogThreshold
17
+ } from '@hydranium/protocol';
18
+
19
+ /** The log flags every subcommand takes, as the env {@link logEnv} hands its child. */
20
+ export interface LogOptions {
21
+ /** Threshold for the client sink; the server's log-level setting replaces it. */
22
+ readonly logLevel?: LogThreshold;
23
+ /** File the server tees its log to; `{workspace}` expands once it is known, `{pid}` from the start. */
24
+ readonly logFile?: string;
25
+ /** The file's own threshold, which the log-level setting does not change. */
26
+ readonly logFileLevel?: LogThreshold;
27
+ }
11
28
 
12
29
  /**
13
- * Validate a raw `--log-level` argument into a {@link LogThreshold}. Throws on
14
- * an unrecognised value so the CLI's top-level `catch` surfaces a clean error
15
- * and exits non-zero (mirroring how the other option parsers fail fast). Use
16
- * for the argv-supplied value; the resolved threshold is handed to
17
- * {@link logLevelEnv} to target the spawned server.
30
+ * Validate a raw `--log-level` / `--log-file-level` argument into a
31
+ * {@link LogThreshold}. Throws on an unrecognised value so the CLI's top-level
32
+ * `catch` surfaces a clean error and exits non-zero (mirroring how the other
33
+ * option parsers fail fast). Use for the argv-supplied value; the resolved
34
+ * threshold is handed to {@link logEnv} to target the spawned server.
18
35
  */
19
- export function parseLogLevelOption(raw: string): LogThreshold {
36
+ export function parseLogLevelOption(raw: string, flag = '--log-level'): LogThreshold {
20
37
  const level = parseLogLevel(raw);
21
38
  if (!level) {
22
- throw new Error(`Invalid --log-level: ${raw} (expected one of: ${Object.keys(LEVEL_ORDER).join(', ')})`);
39
+ throw new Error(`Invalid ${flag}: ${raw} (expected one of: ${Object.keys(LEVEL_ORDER).join(', ')})`);
23
40
  }
24
41
  return level;
25
42
  }
26
43
 
27
44
  /**
28
45
  * Build the environment override that targets *only the spawned server's* log
29
- * threshold. Passed to `spawnDataServer` as `env`, it sets the same
30
- * `HYDRANIUM_LOG_LEVEL` variable the server reads at startup — the CLI's own
31
- * logging is unaffected, unlike an ambient `HYDRANIUM_LOG_LEVEL=…` that the
32
- * child would inherit alongside the parent. The server owns *how* log level
46
+ * configuration, or `undefined` when no log flag was given. Passed to
47
+ * `spawnDataServer` as `env`, it sets the same `HYDRANIUM_LOG_LEVEL` /
48
+ * `HYDRANIUM_LOG_FILE` / `HYDRANIUM_LOG_FILE_LEVEL` variables the server reads
49
+ * at startup — the CLI's own logging is unaffected, unlike ambient variables
50
+ * that the child would inherit alongside the parent. The server owns *how* log level
33
51
  * works; this only routes the CLI's request onto the channel it already reads.
34
52
  *
35
53
  * **The variable is read by `LspLogger`'s constructor**, which is bound on the
@@ -44,6 +62,16 @@ export function parseLogLevelOption(raw: string): LogThreshold {
44
62
  * not go to stdout: that is the JSON-RPC channel, so a log line there would
45
63
  * corrupt the very request this flag was set to diagnose.
46
64
  */
47
- export function logLevelEnv(level: LogThreshold): Record<string, string> {
48
- return { [DEFAULT_LOG_LEVEL_ENV]: level };
65
+ export function logEnv(options: LogOptions): Record<string, string> | undefined {
66
+ const env: Record<string, string> = {};
67
+ if (options.logLevel !== undefined) {
68
+ env[DEFAULT_LOG_LEVEL_ENV] = options.logLevel;
69
+ }
70
+ if (options.logFile !== undefined) {
71
+ env[DEFAULT_LOG_FILE_ENV] = options.logFile;
72
+ }
73
+ if (options.logFileLevel !== undefined) {
74
+ env[DEFAULT_LOG_FILE_LEVEL_ENV] = options.logFileLevel;
75
+ }
76
+ return Object.keys(env).length > 0 ? env : undefined;
49
77
  }
@@ -15,7 +15,14 @@ import {
15
15
  type DataServerProtocol
16
16
  } from '@hydranium/protocol/data';
17
17
  import { type ChildProcess, spawn } from 'node:child_process';
18
- import { StreamMessageReader, StreamMessageWriter, createMessageConnection, type MessageConnection } from 'vscode-jsonrpc/node';
18
+ import {
19
+ StreamMessageReader,
20
+ StreamMessageWriter,
21
+ createMessageConnection,
22
+ type Logger as ConnectionLogger,
23
+ type MessageConnection
24
+ } from 'vscode-jsonrpc/node';
25
+ import { STDERR_CONNECTION_LOGGER } from './stderr-connection-logger.js';
19
26
 
20
27
  /**
21
28
  * Options for {@link spawnDataServer}. `command` is the binary or script
@@ -49,6 +56,11 @@ export interface SpawnDataServerOptions {
49
56
  * scripted use; set to `'pipe'` to capture for assertion in tests.
50
57
  */
51
58
  readonly stderr?: 'inherit' | 'ignore' | 'pipe';
59
+ /**
60
+ * Where the connection to the child logs its protocol faults, such as a
61
+ * response that matches no request. Default: this process's stderr.
62
+ */
63
+ readonly logger?: ConnectionLogger;
52
64
  }
53
65
 
54
66
  /**
@@ -143,7 +155,7 @@ export function spawnDataServer<TTransfer extends TransferElement, TDiagnostic e
143
155
 
144
156
  const reader = new StreamMessageReader(child.stdout);
145
157
  const writer = new StreamMessageWriter(child.stdin);
146
- const connection = createMessageConnection(reader, writer);
158
+ const connection = createMessageConnection(reader, writer, options.logger ?? STDERR_CONNECTION_LOGGER);
147
159
  // Consume transport error / close so a child that dies mid-stream (its stdout
148
160
  // closing, a write landing on a torn-down stdin) is observed here rather than
149
161
  // escaping as an unhandled error — the death is reported via `whenTerminated`.
@@ -224,9 +236,9 @@ export function spawnDataServer<TTransfer extends TransferElement, TDiagnostic e
224
236
  * child down afterwards. The `use` call is raced against
225
237
  * {@link DataServerHandle.whenTerminated}, so a spawn failure or a premature child
226
238
  * exit rejects with a clear message instead of hanging on an RPC that can never be
227
- * answered. This is the one-shot counterpart the `projects` / `query` / `save`
228
- * subcommands compose; `watch` races its own long-running loop against
229
- * `whenTerminated` directly.
239
+ * answered. This is the one-shot counterpart the data-server subcommands
240
+ * compose; `watch` races its own long-running loop against `whenTerminated`
241
+ * directly.
230
242
  */
231
243
  export async function withDataServer<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic, R>(
232
244
  options: SpawnDataServerOptions,
@@ -0,0 +1,18 @@
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 { Logger as ConnectionLogger } from 'vscode-jsonrpc/node';
11
+
12
+ /** Every connection line goes to stderr: stdout carries the command's output or the protocol stream. */
13
+ export const STDERR_CONNECTION_LOGGER: ConnectionLogger = {
14
+ error: message => console.error(message),
15
+ warn: message => console.error(message),
16
+ info: message => console.error(message),
17
+ log: message => console.error(message)
18
+ };
@@ -20,8 +20,10 @@
20
20
 
21
21
  import { DataServer } from '@hydranium/data-server';
22
22
  import { makeTestServices } from '@hydranium/core/testing';
23
+ import { describeErrorWithStack } from '@hydranium/protocol';
23
24
  import type { AstNode, URI } from '@hydranium/langium';
24
- import { StreamMessageReader, StreamMessageWriter, createMessageConnection } from 'vscode-jsonrpc/node';
25
+ import { StreamMessageReader, StreamMessageWriter, createMessageConnection, type ResponseMessage } from 'vscode-jsonrpc/node';
26
+ import { STDERR_CONNECTION_LOGGER } from '../stderr-connection-logger.js';
25
27
 
26
28
  interface FakeRoot extends AstNode {
27
29
  readonly $type: 'FakeRoot';
@@ -72,7 +74,14 @@ function main(): void {
72
74
  }
73
75
  };
74
76
 
75
- const connection = createMessageConnection(new StreamMessageReader(process.stdin), new StreamMessageWriter(process.stdout));
77
+ const writer = new StreamMessageWriter(process.stdout);
78
+ const connection = createMessageConnection(new StreamMessageReader(process.stdin), writer, STDERR_CONNECTION_LOGGER);
79
+
80
+ if (process.argv.includes('--send-response-without-id')) {
81
+ // A response the parent cannot match to a request, for its connection to log.
82
+ const response: ResponseMessage = { jsonrpc: '2.0', id: null, result: null };
83
+ writer.write(response).catch((error: unknown) => STDERR_CONNECTION_LOGGER.error(describeErrorWithStack(error)));
84
+ }
76
85
 
77
86
  if (process.argv.includes('--exit-on-request')) {
78
87
  // Fail-fast fixture mode: read a full request (the reader parses the whole