@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
@@ -7,16 +7,19 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
+ import { describeError } from '@hydranium/protocol';
10
11
  import {
11
12
  exitWithUsage,
13
+ HARNESS_VALUE_FLAGS,
12
14
  helpRequested,
13
- LOG_LEVEL_FLAG,
14
- logLevelHelpLine,
15
- logLevelOption,
15
+ importHelpLines,
16
+ LOG_FILE_FLAG,
17
+ LOG_VALUE_FLAGS,
18
+ logHelpLines,
19
+ logOptions,
16
20
  numericOption,
17
21
  parseHarnessArgs,
18
22
  printHelp,
19
- SERVICES_FLAG,
20
23
  type UsageError
21
24
  } from './harness-args.js';
22
25
  import { parseProfileDimensions, runMeasureMemory, type MeasureMemoryCommandOptions } from './measure-memory.js';
@@ -29,23 +32,24 @@ const VALUE_FLAGS = [
29
32
  '--snapshot-path',
30
33
  '--profile',
31
34
  '--session-out',
32
- LOG_LEVEL_FLAG
35
+ ...LOG_VALUE_FLAGS
33
36
  ] as const;
34
37
  const BOOL_FLAGS = ['--snapshot', '--json'] as const;
35
38
 
36
39
  /**
37
40
  * Every flag `measure-memory` accepts, derived from the sets the parser is
38
- * handed so the list cannot claim a flag the parser would reject. `--services`
39
- * is consumed by the shared harness parser itself, so it is in neither set.
41
+ * handed so the list cannot claim a flag the parser would reject.
42
+ * {@link HARNESS_VALUE_FLAGS} are consumed by the shared harness parser itself,
43
+ * so they are in neither set.
40
44
  */
41
- export const MEASURE_MEMORY_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_FLAGS, ...BOOL_FLAGS];
45
+ export const MEASURE_MEMORY_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS, ...BOOL_FLAGS];
42
46
 
43
47
  /** The subset that takes a value, so `--help` in a value position reads as data. */
44
- export const MEASURE_MEMORY_VALUE_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_FLAGS];
48
+ export const MEASURE_MEMORY_VALUE_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS];
45
49
 
46
50
  /** The `--help` text, as data, held to {@link MEASURE_MEMORY_FLAGS} by a test. */
47
51
  export const MEASURE_MEMORY_HELP: readonly string[] = [
48
- 'Usage: hydranium-cli measure-memory --services <module> <workspace> [options]',
52
+ 'Usage: hydranium-cli measure-memory --services <module> [--import <specifier>]... <workspace> [options]',
49
53
  '',
50
54
  'Measure model-store memory for a workspace. `<module>` is an ESM module that',
51
55
  'exports a zero-arg `createServices(): { shared }` thunk (the head wires its own',
@@ -54,6 +58,7 @@ export const MEASURE_MEMORY_HELP: readonly string[] = [
54
58
  '',
55
59
  'Options:',
56
60
  ' --services <module> ESM module exporting `createServices(): { shared }` (required).',
61
+ ...importHelpLines(22),
57
62
  ' <workspace> Workspace root (path or file URI) to build (required).',
58
63
  ' --edits <N> Rebuild-churn cycles to probe for retention. Default: 0 (skip).',
59
64
  ' --edit-docs <N> Documents to churn per cycle. Default: 25.',
@@ -67,11 +72,13 @@ export const MEASURE_MEMORY_HELP: readonly string[] = [
67
72
  ' --profile <dims> Capture sampled profiles around the build (+churn) into a',
68
73
  ' profiling session. Comma-separated: cpu,alloc,gc,eld,heap.',
69
74
  ' --session-out <dir> Parent directory for the profiling session folder (with --profile).',
75
+ ' The session logs to its server.log at --log-file-level, else at',
76
+ ' --log-level, else info; --log-file is refused beside --profile.',
70
77
  ' --json Emit the measurement as one JSON document instead of the',
71
78
  ' progress lines: documentCount, buildMs, emptyHeapBytes,',
72
79
  ' afterBuildHeapBytes, and churnGrowthBytes / snapshotPath /',
73
80
  ' profilingSession where the run produced them.',
74
- logLevelHelpLine(22)
81
+ ...logHelpLines(22)
75
82
  ];
76
83
 
77
84
  /**
@@ -91,15 +98,21 @@ function validatedProfile(csv: string | undefined, onError: UsageError): string
91
98
  try {
92
99
  parseProfileDimensions(csv);
93
100
  } catch (err: unknown) {
94
- onError(`Option --profile: ${err instanceof Error ? err.message : String(err)}`);
101
+ onError(`Option --profile: ${describeError(err)}`);
95
102
  }
96
103
  return csv;
97
104
  }
98
105
 
99
106
  export function parseMeasureMemoryArgs(args: string[], onError: UsageError = exitWithUsage): MeasureMemoryCommandOptions {
100
- const { servicesModule, workspace, options } = parseHarnessArgs(args, 'measure-memory', VALUE_FLAGS, BOOL_FLAGS, { onError });
107
+ const { servicesModule, imports, workspace, options } = parseHarnessArgs(args, 'measure-memory', VALUE_FLAGS, BOOL_FLAGS, { onError });
108
+ // The profiling session points the log at its own `server.log`, which would
109
+ // replace the requested file without a word.
110
+ if (options['--profile'] !== undefined && options[LOG_FILE_FLAG] !== undefined) {
111
+ onError(`${LOG_FILE_FLAG} cannot be combined with --profile, which logs to the session's server.log`);
112
+ }
101
113
  return {
102
114
  servicesModule,
115
+ imports,
103
116
  workspace,
104
117
  editCycles: numericOption(options['--edits'], '--edits', onError),
105
118
  editDocs: numericOption(options['--edit-docs'], '--edit-docs', onError),
@@ -110,7 +123,7 @@ export function parseMeasureMemoryArgs(args: string[], onError: UsageError = exi
110
123
  profile: validatedProfile(options['--profile'], onError),
111
124
  sessionOut: options['--session-out'],
112
125
  json: options['--json'] === 'true',
113
- logLevel: logLevelOption(options[LOG_LEVEL_FLAG])
126
+ ...logOptions(options)
114
127
  };
115
128
  }
116
129
 
@@ -9,12 +9,14 @@
9
9
 
10
10
  /*
11
11
  * Spawned child of the `measure-memory` subcommand. Launched by the parent with
12
- * `node --expose-gc --max-old-space-size=8192 <this> --services <module> <workspace> ...`
13
- * so the underlying harness gets post-GC readings. It dynamic-imports the head's
12
+ * `node [heap ceiling] --expose-gc <this> --services <module> <workspace> ...`
13
+ * so the underlying harness gets post-GC readings. The ceiling is whatever
14
+ * `driverHeapArgs` decides, which is nothing at all inside a container. It dynamic-imports the head's
14
15
  * services module and runs the framework's `measureModelMemory`, streaming the
15
16
  * baseline / after-build / churn lines to stdout. Never imported — only spawned.
16
17
  */
17
18
 
19
+ import { describeError } from '@hydranium/protocol';
18
20
  import { loadHeadlessContext } from './headless-harness.js';
19
21
  import { parseProfileDimensions } from './measure-memory.js';
20
22
 
@@ -123,6 +125,6 @@ async function main(argv: string[]): Promise<void> {
123
125
  main(process.argv.slice(2))
124
126
  .then(() => process.exit(0))
125
127
  .catch((error: unknown) => {
126
- console.error(error instanceof Error ? error.message : String(error));
128
+ console.error(describeError(error));
127
129
  process.exit(1);
128
130
  });
@@ -139,5 +139,5 @@ export function buildDriverArgs(options: MeasureMemoryCommandOptions): string[]
139
139
  * module and reports the baseline / after-build / churn lines on stdout.
140
140
  */
141
141
  export function runMeasureMemory(options: MeasureMemoryCommandOptions): Promise<void> {
142
- return runDriverChild(['--expose-gc', '--max-old-space-size=8192', DRIVER, ...buildDriverArgs(options)], options);
142
+ return runDriverChild(['--expose-gc', DRIVER, ...buildDriverArgs(options)], options);
143
143
  }
@@ -9,33 +9,35 @@
9
9
 
10
10
  import {
11
11
  exitWithUsage,
12
+ HARNESS_VALUE_FLAGS,
12
13
  helpRequested,
13
- LOG_LEVEL_FLAG,
14
- logLevelHelpLine,
15
- logLevelOption,
14
+ importHelpLines,
15
+ LOG_VALUE_FLAGS,
16
+ logHelpLines,
17
+ logOptions,
16
18
  parseHarnessArgs,
17
19
  printHelp,
18
- SERVICES_FLAG,
19
20
  type UsageError
20
21
  } from './harness-args.js';
21
22
  import { OUT_FILE_FLAG } from './headless-harness.js';
22
23
  import { runModelDocs, type ModelDocsCommandOptions } from './model-docs.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
- * Every flag `model-docs` accepts, derived from the sets the parser is handed so
28
- * the list cannot claim a flag the parser would reject. `--services` is consumed
29
- * by the shared harness parser itself, so it is in neither set.
28
+ * Every flag `model-docs` accepts, derived from the sets the parser is handed
29
+ * 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 MODEL_DOCS_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_FLAGS];
33
+ export const MODEL_DOCS_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 MODEL_DOCS_VALUE_FLAGS: readonly string[] = MODEL_DOCS_FLAGS;
35
37
 
36
38
  /** The `--help` text, as data, held to {@link MODEL_DOCS_FLAGS} by a test. */
37
39
  export const MODEL_DOCS_HELP: readonly string[] = [
38
- 'Usage: hydranium-cli model-docs --services <module> [--out-file <file>] [--log-level <lvl>]',
40
+ 'Usage: hydranium-cli model-docs --services <module> [--import <specifier>]... [--out-file <file>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
39
41
  '',
40
42
  'Generate a navigable Markdown reference of every AST node type — a type index,',
41
43
  'cross-linked super/sub types, a reverse "referenced by" index, and a per-language',
@@ -46,18 +48,19 @@ export const MODEL_DOCS_HELP: readonly string[] = [
46
48
  '',
47
49
  'Options:',
48
50
  ' --services <module> ESM module exporting `createServices(): { shared }` (required).',
51
+ ...importHelpLines(22),
49
52
  ' --out-file <file> Write the Markdown to this file instead of stdout. Written',
50
53
  ' only once the report exists, unlike a shell redirection,',
51
54
  ' which truncates the file before the head is even booted.',
52
- logLevelHelpLine(22)
55
+ ...logHelpLines(22)
53
56
  ];
54
57
 
55
58
  export function parseModelDocsArgs(args: string[], onError: UsageError = exitWithUsage): ModelDocsCommandOptions {
56
- const { servicesModule, options } = parseHarnessArgs(args, 'model-docs', VALUE_FLAGS, [], {
59
+ const { servicesModule, imports, options } = parseHarnessArgs(args, 'model-docs', VALUE_FLAGS, [], {
57
60
  requireWorkspace: false,
58
61
  onError
59
62
  });
60
- return { servicesModule, outFile: options[OUT_FILE_FLAG], logLevel: logLevelOption(options[LOG_LEVEL_FLAG]) };
63
+ return { servicesModule, imports, outFile: options[OUT_FILE_FLAG], ...logOptions(options) };
61
64
  }
62
65
 
63
66
  export function runModelDocsCommand(args: string[]): Promise<void> {
@@ -16,6 +16,7 @@
16
16
  * head throws. Never imported — only spawned.
17
17
  */
18
18
 
19
+ import { describeError } from '@hydranium/protocol';
19
20
  import { emitReport, loadHeadlessContext, OUT_FILE_FLAG } from './headless-harness.js';
20
21
  import { formatModelDocs } from './model-docs-report.js';
21
22
 
@@ -63,6 +64,6 @@ async function main(argv: string[]): Promise<number> {
63
64
  main(process.argv.slice(2))
64
65
  .then(code => process.exit(code))
65
66
  .catch((error: unknown) => {
66
- console.error(error instanceof Error ? error.message : String(error));
67
+ console.error(describeError(error));
67
68
  process.exit(1);
68
69
  });
@@ -44,5 +44,5 @@ export function buildModelDocsDriverArgs(options: ModelDocsCommandOptions): stri
44
44
  * module, keeping the binary language-agnostic.
45
45
  */
46
46
  export function runModelDocs(options: ModelDocsCommandOptions): Promise<void> {
47
- return runDriverChild(['--max-old-space-size=8192', DRIVER, ...buildModelDocsDriverArgs(options)], options);
47
+ return runDriverChild([DRIVER, ...buildModelDocsDriverArgs(options)], options);
48
48
  }
@@ -10,6 +10,7 @@
10
10
  import {
11
11
  exitWithUsage,
12
12
  helpRequested,
13
+ logHelpLines,
13
14
  parseFlagOptions,
14
15
  parseServerSpawnOptions,
15
16
  printHelp,
@@ -32,7 +33,7 @@ export const PROJECTS_VALUE_FLAGS: readonly string[] = PROJECTS_FLAGS;
32
33
 
33
34
  /** The `--help` text, as data, held to {@link PROJECTS_FLAGS} by a test. */
34
35
  export const PROJECTS_HELP: readonly string[] = [
35
- 'Usage: hydranium-cli projects --server "<cmd> [args...]" [--cwd <dir>] [--log-level <level>]',
36
+ 'Usage: hydranium-cli projects --server "<cmd> [args...]" [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
36
37
  '',
37
38
  'List projects exposed by the data-server subprocess. Output is newline-delimited',
38
39
  'JSON — one project envelope per line.',
@@ -40,17 +41,17 @@ export const PROJECTS_HELP: readonly string[] = [
40
41
  'Options:',
41
42
  ' --server "<cmd>" Command-line for the data-server subprocess (required).',
42
43
  ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
43
- ' --log-level <lvl> Log threshold for the spawned server (off|error|warn|info|debug|trace).'
44
+ ...logHelpLines(19, 'the spawned server')
44
45
  ];
45
46
 
46
47
  export function parseProjectsArgs(args: string[], onError: UsageError = exitWithUsage): ProjectsCommandOptions {
47
- const { serverCommand, serverArgs, cwd, logLevel, extra } = parseServerSpawnOptions(args, 'projects', onError);
48
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'projects', onError);
48
49
  // `projects` declares no options beyond the shared ones, so nothing may
49
50
  // survive the spawn parser. Draining `extra` against an empty set is what
50
51
  // makes a typo an error here rather than a flag that silently did nothing —
51
52
  // the siblings get this from the option list they pass.
52
53
  parseFlagOptions(extra, 'projects', [], onError);
53
- return { serverCommand, serverArgs, cwd, logLevel };
54
+ return { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel };
54
55
  }
55
56
 
56
57
  export function runProjectsCommand(args: string[]): Promise<void> {
@@ -7,9 +7,9 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { LogThreshold, Project, TransferElement } from '@hydranium/protocol';
10
+ import type { Project, TransferElement } from '@hydranium/protocol';
11
11
  import type { DataServerProtocol } from '@hydranium/protocol/data';
12
- import { logLevelEnv } from '../log-level.js';
12
+ import { logEnv, type LogOptions } from '../log-level.js';
13
13
  import { withDataServer } from '../spawn-data-server.js';
14
14
 
15
15
  /**
@@ -17,7 +17,7 @@ import { withDataServer } from '../spawn-data-server.js';
17
17
  * `serverArgs` mirror what an adopter would pass to spawn the data-server
18
18
  * subprocess.
19
19
  */
20
- export interface ProjectsCommandOptions {
20
+ export interface ProjectsCommandOptions extends LogOptions {
21
21
  /**
22
22
  * Command-line tokens used to spawn the data-server child. Mirrors
23
23
  * the `--server "<cmd> [args...]"` shape on the CLI surface — split
@@ -26,8 +26,6 @@ export interface ProjectsCommandOptions {
26
26
  readonly serverCommand: string;
27
27
  readonly serverArgs?: readonly string[];
28
28
  readonly cwd?: string;
29
- /** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
30
- readonly logLevel?: LogThreshold;
31
29
  /**
32
30
  * Output sink. Default: `process.stdout.write`. Tests inject a
33
31
  * capturing stub.
@@ -60,7 +58,7 @@ export async function runProjects(options: ProjectsCommandOptions): Promise<void
60
58
  command: options.serverCommand,
61
59
  args: options.serverArgs,
62
60
  cwd: options.cwd,
63
- env: options.logLevel ? logLevelEnv(options.logLevel) : undefined
61
+ env: logEnv(options)
64
62
  },
65
63
  async server => {
66
64
  const projects = await server.getProjects();
@@ -11,6 +11,7 @@ import {
11
11
  assertRequired,
12
12
  exitWithUsage,
13
13
  helpRequested,
14
+ logHelpLines,
14
15
  parseFlagOptions,
15
16
  parseServerSpawnOptions,
16
17
  printHelp,
@@ -35,7 +36,7 @@ export const QUERY_VALUE_FLAGS: readonly string[] = QUERY_FLAGS;
35
36
 
36
37
  /** The `--help` text, as data, held to {@link QUERY_FLAGS} by a test. */
37
38
  export const QUERY_HELP: readonly string[] = [
38
- 'Usage: hydranium-cli query --server "<cmd> [args...]" --uri <uri> [--cwd <dir>] [--log-level <level>]',
39
+ 'Usage: hydranium-cli query --server "<cmd> [args...]" --uri <uri> [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
39
40
  '',
40
41
  'Print the data-server document envelope for `<uri>` as a single JSON line.',
41
42
  '',
@@ -43,13 +44,13 @@ export const QUERY_HELP: readonly string[] = [
43
44
  ' --server "<cmd>" Command-line for the data-server subprocess (required).',
44
45
  ' --uri <uri> Document URI (required).',
45
46
  ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
46
- ' --log-level <lvl> Log threshold for the spawned server (off|error|warn|info|debug|trace).'
47
+ ...logHelpLines(19, 'the spawned server')
47
48
  ];
48
49
 
49
50
  export function parseQueryArgs(args: string[], onError: UsageError = exitWithUsage): QueryCommandOptions {
50
- const { serverCommand, serverArgs, cwd, logLevel, extra } = parseServerSpawnOptions(args, 'query', onError);
51
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'query', onError);
51
52
  const { uri } = parseFlagOptions(extra, 'query', OWN_FLAGS, onError);
52
- return { serverCommand, serverArgs, cwd, logLevel, uri: assertRequired(uri, '--uri', 'query', onError) };
53
+ return { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, uri: assertRequired(uri, '--uri', 'query', onError) };
53
54
  }
54
55
 
55
56
  export function runQueryCommand(args: string[]): Promise<void> {
@@ -7,9 +7,9 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { LogThreshold, TransferElement } from '@hydranium/protocol';
10
+ import type { TransferElement } from '@hydranium/protocol';
11
11
  import type { DataServerProtocol } from '@hydranium/protocol/data';
12
- import { logLevelEnv } from '../log-level.js';
12
+ import { logEnv, type LogOptions } from '../log-level.js';
13
13
  import { withDataServer } from '../spawn-data-server.js';
14
14
 
15
15
  /**
@@ -22,12 +22,10 @@ import { withDataServer } from '../spawn-data-server.js';
22
22
  * Test-only `__proxyForTest` bypasses the spawn for unit tests; the
23
23
  * production CLI never passes it.
24
24
  */
25
- export interface QueryCommandOptions {
25
+ export interface QueryCommandOptions extends LogOptions {
26
26
  readonly serverCommand: string;
27
27
  readonly serverArgs?: readonly string[];
28
28
  readonly cwd?: string;
29
- /** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
30
- readonly logLevel?: LogThreshold;
31
29
  readonly uri: string;
32
30
  readonly write?: (line: string) => void;
33
31
  readonly __proxyForTest?: DataServerProtocol<TransferElement>;
@@ -48,7 +46,7 @@ export async function runQuery(options: QueryCommandOptions): Promise<void> {
48
46
  command: options.serverCommand,
49
47
  args: options.serverArgs,
50
48
  cwd: options.cwd,
51
- env: options.logLevel ? logLevelEnv(options.logLevel) : undefined
49
+ env: logEnv(options)
52
50
  },
53
51
  async server => {
54
52
  const doc = await server.getModelDocument({ uri: options.uri, includeDiagnostics: true });
@@ -9,34 +9,36 @@
9
9
 
10
10
  import {
11
11
  exitWithUsage,
12
+ HARNESS_VALUE_FLAGS,
12
13
  helpRequested,
13
- LOG_LEVEL_FLAG,
14
- logLevelHelpLine,
15
- logLevelOption,
14
+ importHelpLines,
15
+ LOG_VALUE_FLAGS,
16
+ logHelpLines,
17
+ logOptions,
16
18
  parseHarnessArgs,
17
19
  printHelp,
18
- SERVICES_FLAG,
19
20
  type UsageError
20
21
  } from './harness-args.js';
21
22
  import { OUT_FILE_FLAG } from './headless-harness.js';
22
23
  import { runReflect, type ReflectCommandOptions } from './reflect.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
  const BOOL_FLAGS = ['--json'] as const;
26
27
 
27
28
  /**
28
29
  * Every flag `reflect` accepts, derived from the sets the parser is handed so
29
- * the list cannot claim a flag the parser would reject. `--services` is consumed
30
- * by the shared harness parser itself, so it is in neither set.
30
+ * the list cannot claim a flag the parser would reject.
31
+ * {@link HARNESS_VALUE_FLAGS} are consumed by the shared harness parser itself,
32
+ * so they are in neither set.
31
33
  */
32
- export const REFLECT_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_FLAGS, ...BOOL_FLAGS];
34
+ export const REFLECT_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS, ...BOOL_FLAGS];
33
35
 
34
36
  /** The subset that takes a value, so `--help` in a value position reads as data. */
35
- export const REFLECT_VALUE_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_FLAGS];
37
+ export const REFLECT_VALUE_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS];
36
38
 
37
39
  /** The `--help` text, as data, held to {@link REFLECT_FLAGS} by a test. */
38
40
  export const REFLECT_HELP: readonly string[] = [
39
- 'Usage: hydranium-cli reflect --services <module> [--json] [--out-file <file>] [--log-level <lvl>]',
41
+ 'Usage: hydranium-cli reflect --services <module> [--import <specifier>]... [--json] [--out-file <file>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
40
42
  '',
41
43
  "Dump a head's grammar/AST reflection — the type hierarchy, each language's",
42
44
  'terminals and entry rule, and every cross-reference target. Read-only: no',
@@ -46,23 +48,25 @@ export const REFLECT_HELP: readonly string[] = [
46
48
  '',
47
49
  'Options:',
48
50
  ' --services <module> ESM module exporting `createServices(): { shared }` (required).',
51
+ ...importHelpLines(22),
49
52
  ' --json Emit the raw JSON reflection instead of the Markdown report.',
50
53
  ' --out-file <file> Write the report to this file instead of stdout. Written',
51
54
  ' only once the report exists, unlike a shell redirection,',
52
55
  ' which truncates the file before the head is even booted.',
53
- logLevelHelpLine(22)
56
+ ...logHelpLines(22)
54
57
  ];
55
58
 
56
59
  export function parseReflectArgs(args: string[], onError: UsageError = exitWithUsage): ReflectCommandOptions {
57
- const { servicesModule, options } = parseHarnessArgs(args, 'reflect', VALUE_FLAGS, BOOL_FLAGS, {
60
+ const { servicesModule, imports, options } = parseHarnessArgs(args, 'reflect', VALUE_FLAGS, BOOL_FLAGS, {
58
61
  requireWorkspace: false,
59
62
  onError
60
63
  });
61
64
  return {
62
65
  servicesModule,
66
+ imports,
63
67
  json: options['--json'] === 'true',
64
68
  outFile: options[OUT_FILE_FLAG],
65
- logLevel: logLevelOption(options[LOG_LEVEL_FLAG])
69
+ ...logOptions(options)
66
70
  };
67
71
  }
68
72
 
@@ -16,6 +16,7 @@
16
16
  * imported — only spawned.
17
17
  */
18
18
 
19
+ import { describeError } from '@hydranium/protocol';
19
20
  import { emitReport, loadHeadlessContext, OUT_FILE_FLAG } from './headless-harness.js';
20
21
  import { formatReflectionReport } from './reflect-report.js';
21
22
 
@@ -71,6 +72,6 @@ async function main(argv: string[]): Promise<number> {
71
72
  main(process.argv.slice(2))
72
73
  .then(code => process.exit(code))
73
74
  .catch((error: unknown) => {
74
- console.error(error instanceof Error ? error.message : String(error));
75
+ console.error(describeError(error));
75
76
  process.exit(1);
76
77
  });
@@ -47,5 +47,5 @@ export function buildReflectDriverArgs(options: ReflectCommandOptions): string[]
47
47
  * the binary language-agnostic.
48
48
  */
49
49
  export function runReflect(options: ReflectCommandOptions): Promise<void> {
50
- return runDriverChild(['--max-old-space-size=8192', DRIVER, ...buildReflectDriverArgs(options)], options);
50
+ return runDriverChild([DRIVER, ...buildReflectDriverArgs(options)], options);
51
51
  }
@@ -11,6 +11,7 @@ import {
11
11
  assertRequired,
12
12
  exitWithUsage,
13
13
  helpRequested,
14
+ logHelpLines,
14
15
  parseFlagOptions,
15
16
  parseServerSpawnOptions,
16
17
  printHelp,
@@ -36,9 +37,10 @@ export const SAVE_VALUE_FLAGS: readonly string[] = SAVE_FLAGS;
36
37
 
37
38
  /** The `--help` text, as data, held to {@link SAVE_FLAGS} by a test. */
38
39
  export const SAVE_HELP: readonly string[] = [
39
- 'Usage: hydranium-cli save --server "<cmd>..." --uri <uri> --content <text|@file> [--client-id <id>] [--cwd <dir>] [--log-level <level>]',
40
+ 'Usage: hydranium-cli save --server "<cmd>..." --uri <uri> --content <text|@file> [--client-id <id>] [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
40
41
  '',
41
42
  'Update the document at `<uri>` with `<content>` and persist via saveModelDocument.',
43
+ 'Fails when the file does not exist; `create` writes a new one.',
42
44
  'Output is the post-save envelope as a single JSON line.',
43
45
  '',
44
46
  'Options:',
@@ -48,17 +50,19 @@ export const SAVE_HELP: readonly string[] = [
48
50
  ' (escape with `\\@` for literal `@`-leading content).',
49
51
  ' --client-id <id> clientId for authorship attribution. Default: hydranium-cli.',
50
52
  ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
51
- ' --log-level <lvl> Log threshold for the spawned server (off|error|warn|info|debug|trace).'
53
+ ...logHelpLines(22, 'the spawned server')
52
54
  ];
53
55
 
54
56
  export function parseSaveArgs(args: string[], onError: UsageError = exitWithUsage): SaveCommandOptions {
55
- const { serverCommand, serverArgs, cwd, logLevel, extra } = parseServerSpawnOptions(args, 'save', onError);
57
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'save', onError);
56
58
  const { uri, content, clientId } = parseFlagOptions(extra, 'save', OWN_FLAGS, onError);
57
59
  return {
58
60
  serverCommand,
59
61
  serverArgs,
60
62
  cwd,
61
63
  logLevel,
64
+ logFile,
65
+ logFileLevel,
62
66
  uri: assertRequired(uri, '--uri', 'save', onError),
63
67
  content: assertRequired(content, '--content', 'save', onError),
64
68
  clientId
@@ -7,11 +7,12 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { LogThreshold, TransferElement } from '@hydranium/protocol';
10
+ import type { TransferElement } from '@hydranium/protocol';
11
11
  import type { DataServerProtocol } from '@hydranium/protocol/data';
12
- import * as fs from 'node:fs/promises';
13
- import { logLevelEnv } from '../log-level.js';
12
+ import { logEnv, type LogOptions } from '../log-level.js';
14
13
  import { withDataServer } from '../spawn-data-server.js';
14
+ import { withClientSession } from './client-session.js';
15
+ import { resolveContent } from './harness-args.js';
15
16
 
16
17
  /**
17
18
  * Options for the {@link runSave} subcommand. Updates the document at
@@ -23,13 +24,16 @@ import { withDataServer } from '../spawn-data-server.js';
23
24
  *
24
25
  * `clientId` defaults to `'hydranium-cli'` — adopters wanting a richer
25
26
  * identity (per-user, per-script) override.
27
+ *
28
+ * The command saves as a client session under `clientId`: it registers the
29
+ * session, opens the document, saves, and ends the session, which leaves
30
+ * nothing open behind it. A missing file fails the open; `runCreate` writes a
31
+ * new one.
26
32
  */
27
- export interface SaveCommandOptions {
33
+ export interface SaveCommandOptions extends LogOptions {
28
34
  readonly serverCommand: string;
29
35
  readonly serverArgs?: readonly string[];
30
36
  readonly cwd?: string;
31
- /** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
32
- readonly logLevel?: LogThreshold;
33
37
  readonly uri: string;
34
38
  /** Literal content text, or `@<path>` to read from a file. */
35
39
  readonly content: string;
@@ -46,8 +50,7 @@ export async function runSave(options: SaveCommandOptions): Promise<void> {
46
50
  const model = await resolveContent(options.content, options.__readFileForTest);
47
51
 
48
52
  if (options.__proxyForTest) {
49
- const doc = await options.__proxyForTest.saveModelDocument({ uri: options.uri, clientId, model });
50
- write(`${JSON.stringify(doc)}\n`);
53
+ write(`${JSON.stringify(await saveOpened(options.__proxyForTest, options.uri, clientId, model))}\n`);
51
54
  return;
52
55
  }
53
56
 
@@ -56,29 +59,23 @@ export async function runSave(options: SaveCommandOptions): Promise<void> {
56
59
  command: options.serverCommand,
57
60
  args: options.serverArgs,
58
61
  cwd: options.cwd,
59
- env: options.logLevel ? logLevelEnv(options.logLevel) : undefined
62
+ env: logEnv(options)
60
63
  },
61
64
  async server => {
62
- const doc = await server.saveModelDocument({ uri: options.uri, clientId, model });
63
- write(`${JSON.stringify(doc)}\n`);
65
+ write(`${JSON.stringify(await saveOpened(server, options.uri, clientId, model))}\n`);
64
66
  }
65
67
  );
66
68
  }
67
69
 
68
- /**
69
- * Resolve the `--content` argument to its textual form. The `@<path>`
70
- * prefix reads from a file (parses as UTF-8); anything else is taken
71
- * literally. The leading `@` can be escaped as `\@` for content that
72
- * legitimately starts with `@`.
73
- */
74
- async function resolveContent(content: string, readFile?: (path: string) => Promise<string>): Promise<string> {
75
- if (content.startsWith('@')) {
76
- const path = content.slice(1);
77
- const reader = readFile ?? ((target: string) => fs.readFile(target, 'utf8'));
78
- return reader(path);
79
- }
80
- if (content.startsWith('\\@')) {
81
- return content.slice(1);
82
- }
83
- return content;
70
+ /** Open `uri` as the session `clientId` and save `model` to it, then end the session. */
71
+ function saveOpened(
72
+ server: Pick<DataServerProtocol<TransferElement>, 'createSession' | 'openModelDocument' | 'saveModelDocument' | 'closeSession'>,
73
+ uri: string,
74
+ clientId: string,
75
+ model: string
76
+ ): Promise<unknown> {
77
+ return withClientSession(server, clientId, async () => {
78
+ await server.openModelDocument({ uri, clientId });
79
+ return server.saveModelDocument({ uri, clientId, model, baseVersion: 'any' });
80
+ });
84
81
  }