@hydranium/cli 1.0.0-next.17 → 1.0.0-next.173
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.
- package/README.md +14 -0
- package/lib/commands/analyze-heap.d.ts +3 -0
- package/lib/commands/analyze-heap.d.ts.map +1 -1
- package/lib/commands/analyze-heap.js +2 -1
- package/lib/commands/analyze-heap.js.map +1 -1
- package/lib/commands/ast-ground-truth.js +1 -1
- package/lib/commands/ast-ground-truth.js.map +1 -1
- package/lib/commands/generate-ast-builder.d.ts +49 -0
- package/lib/commands/generate-ast-builder.d.ts.map +1 -0
- package/lib/commands/generate-ast-builder.js +200 -0
- package/lib/commands/generate-ast-builder.js.map +1 -0
- package/lib/commands/generate-transfer-model-args.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model-args.js +11 -1
- package/lib/commands/generate-transfer-model-args.js.map +1 -1
- package/lib/commands/generate-transfer-model-config.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model-config.js +3 -1
- package/lib/commands/generate-transfer-model-config.js.map +1 -1
- package/lib/commands/generate-transfer-model.d.ts +9 -0
- package/lib/commands/generate-transfer-model.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model.js +16 -3
- package/lib/commands/generate-transfer-model.js.map +1 -1
- package/lib/commands/headless-harness.d.ts +18 -3
- package/lib/commands/headless-harness.d.ts.map +1 -1
- package/lib/commands/headless-harness.js +12 -4
- package/lib/commands/headless-harness.js.map +1 -1
- package/lib/commands/init-templates.d.ts +0 -9
- package/lib/commands/init-templates.d.ts.map +1 -1
- package/lib/commands/init-templates.js +55 -41
- package/lib/commands/init-templates.js.map +1 -1
- package/lib/commands/init.d.ts.map +1 -1
- package/lib/commands/init.js +2 -6
- package/lib/commands/init.js.map +1 -1
- package/lib/commands/lint-grammar.js +1 -1
- package/lib/commands/lint-grammar.js.map +1 -1
- package/lib/commands/measure-memory-driver.js +3 -2
- package/lib/commands/measure-memory-driver.js.map +1 -1
- package/lib/commands/measure-memory.js +1 -1
- package/lib/commands/measure-memory.js.map +1 -1
- package/lib/commands/model-docs.js +1 -1
- package/lib/commands/model-docs.js.map +1 -1
- package/lib/commands/reflect.js +1 -1
- package/lib/commands/reflect.js.map +1 -1
- package/lib/commands/save.d.ts +5 -0
- package/lib/commands/save.d.ts.map +1 -1
- package/lib/commands/save.js +29 -4
- package/lib/commands/save.js.map +1 -1
- package/lib/commands/validate.js +1 -1
- package/lib/commands/validate.js.map +1 -1
- package/lib/commands/watch.d.ts.map +1 -1
- package/lib/commands/watch.js +18 -0
- package/lib/commands/watch.js.map +1 -1
- package/lib/driver-heap.d.ts +52 -0
- package/lib/driver-heap.d.ts.map +1 -0
- package/lib/driver-heap.js +51 -0
- package/lib/driver-heap.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +11 -10
- package/src/commands/analyze-heap.ts +4 -1
- package/src/commands/ast-ground-truth.ts +1 -1
- package/src/commands/generate-ast-builder.ts +246 -0
- package/src/commands/generate-transfer-model-args.ts +11 -1
- package/src/commands/generate-transfer-model-config.ts +3 -1
- package/src/commands/generate-transfer-model.ts +25 -3
- package/src/commands/headless-harness.ts +22 -4
- package/src/commands/init-templates.ts +55 -42
- package/src/commands/init.ts +2 -8
- package/src/commands/lint-grammar.ts +1 -1
- package/src/commands/measure-memory-driver.ts +3 -2
- package/src/commands/measure-memory.ts +1 -1
- package/src/commands/model-docs.ts +1 -1
- package/src/commands/reflect.ts +1 -1
- package/src/commands/save.ts +45 -4
- package/src/commands/validate.ts +1 -1
- package/src/commands/watch.ts +24 -1
- package/src/driver-heap.ts +65 -0
- package/src/index.ts +1 -0
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
/*
|
|
11
11
|
* Spawned child of the `measure-memory` subcommand. Launched by the parent with
|
|
12
|
-
* `node --expose-gc
|
|
13
|
-
* so the underlying harness gets post-GC readings.
|
|
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
|
*/
|
|
@@ -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',
|
|
142
|
+
return runDriverChild(['--expose-gc', DRIVER, ...buildDriverArgs(options)], options);
|
|
143
143
|
}
|
|
@@ -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([
|
|
47
|
+
return runDriverChild([DRIVER, ...buildModelDocsDriverArgs(options)], options);
|
|
48
48
|
}
|
package/src/commands/reflect.ts
CHANGED
|
@@ -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([
|
|
50
|
+
return runDriverChild([DRIVER, ...buildReflectDriverArgs(options)], options);
|
|
51
51
|
}
|
package/src/commands/save.ts
CHANGED
|
@@ -23,6 +23,11 @@ import { withDataServer } from '../spawn-data-server.js';
|
|
|
23
23
|
*
|
|
24
24
|
* `clientId` defaults to `'hydranium-cli'` — adopters wanting a richer
|
|
25
25
|
* identity (per-user, per-script) override.
|
|
26
|
+
*
|
|
27
|
+
* The command saves as a client session under `clientId`: it registers the
|
|
28
|
+
* session, creates the document from the content when there is no file,
|
|
29
|
+
* opens it otherwise, saves, and ends the session, which leaves nothing open
|
|
30
|
+
* behind it.
|
|
26
31
|
*/
|
|
27
32
|
export interface SaveCommandOptions {
|
|
28
33
|
readonly serverCommand: string;
|
|
@@ -46,8 +51,7 @@ export async function runSave(options: SaveCommandOptions): Promise<void> {
|
|
|
46
51
|
const model = await resolveContent(options.content, options.__readFileForTest);
|
|
47
52
|
|
|
48
53
|
if (options.__proxyForTest) {
|
|
49
|
-
|
|
50
|
-
write(`${JSON.stringify(doc)}\n`);
|
|
54
|
+
write(`${JSON.stringify(await saveOpened(options.__proxyForTest, options.uri, clientId, model))}\n`);
|
|
51
55
|
return;
|
|
52
56
|
}
|
|
53
57
|
|
|
@@ -59,12 +63,49 @@ export async function runSave(options: SaveCommandOptions): Promise<void> {
|
|
|
59
63
|
env: options.logLevel ? logLevelEnv(options.logLevel) : undefined
|
|
60
64
|
},
|
|
61
65
|
async server => {
|
|
62
|
-
|
|
63
|
-
write(`${JSON.stringify(doc)}\n`);
|
|
66
|
+
write(`${JSON.stringify(await saveOpened(server, options.uri, clientId, model))}\n`);
|
|
64
67
|
}
|
|
65
68
|
);
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Save `model` to `uri` as the session `clientId`, and end the session whether
|
|
73
|
+
* the save succeeded or not. An end that fails after a failed save is
|
|
74
|
+
* swallowed: the save's error is the one the user needs.
|
|
75
|
+
*/
|
|
76
|
+
async function saveOpened(
|
|
77
|
+
server: Pick<
|
|
78
|
+
DataServerProtocol<TransferElement>,
|
|
79
|
+
'createSession' | 'openModelDocument' | 'createModelDocument' | 'saveModelDocument' | 'closeSession'
|
|
80
|
+
>,
|
|
81
|
+
uri: string,
|
|
82
|
+
clientId: string,
|
|
83
|
+
model: string
|
|
84
|
+
): Promise<unknown> {
|
|
85
|
+
await server.createSession({ clientId, label: 'hydranium-cli' });
|
|
86
|
+
let saved: unknown;
|
|
87
|
+
try {
|
|
88
|
+
// The server creates a document only when it finds no file and no
|
|
89
|
+
// client has it open; anything else is opened. An open that fails
|
|
90
|
+
// reports why the create failed too, since that may be the real cause.
|
|
91
|
+
await server.createModelDocument({ uri, clientId, text: model }).catch((created: unknown) =>
|
|
92
|
+
server.openModelDocument({ uri, clientId }).catch((opened: unknown) => {
|
|
93
|
+
throw new Error(`Cannot save ${uri}: ${describe(opened)} (creating it failed first: ${describe(created)})`, { cause: created });
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
saved = await server.saveModelDocument({ uri, clientId, model, basedOn: 'anything' });
|
|
97
|
+
} catch (error: unknown) {
|
|
98
|
+
await server.closeSession({ clientId }).catch(() => undefined);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
await server.closeSession({ clientId });
|
|
102
|
+
return saved;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function describe(error: unknown): string {
|
|
106
|
+
return error instanceof Error ? error.message : String(error);
|
|
107
|
+
}
|
|
108
|
+
|
|
68
109
|
/**
|
|
69
110
|
* Resolve the `--content` argument to its textual form. The `@<path>`
|
|
70
111
|
* prefix reads from a file (parses as UTF-8); anything else is taken
|
package/src/commands/validate.ts
CHANGED
|
@@ -54,5 +54,5 @@ export function buildValidateDriverArgs(options: ValidateCommandOptions): string
|
|
|
54
54
|
* The child's exit code propagates to this process so shells and CI see the gate.
|
|
55
55
|
*/
|
|
56
56
|
export function runValidate(options: ValidateCommandOptions): Promise<void> {
|
|
57
|
-
return runDriverChild([
|
|
57
|
+
return runDriverChild([DRIVER, ...buildValidateDriverArgs(options)], options);
|
|
58
58
|
}
|
package/src/commands/watch.ts
CHANGED
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import type { LogThreshold, TransferElement } from '@hydranium/protocol';
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
DataClientProtocol,
|
|
13
|
+
DataServerProtocol,
|
|
14
|
+
TransferDocumentDeletedEvent,
|
|
15
|
+
TransferDocumentUpdatedEvent
|
|
16
|
+
} from '@hydranium/protocol/data';
|
|
12
17
|
import { logLevelEnv } from '../log-level.js';
|
|
13
18
|
import { spawnDataServer } from '../spawn-data-server.js';
|
|
14
19
|
|
|
@@ -132,6 +137,24 @@ export async function runWatch(options: WatchCommandOptions): Promise<void> {
|
|
|
132
137
|
onDocumentSaved(): void {
|
|
133
138
|
// Persistence is out of band for the per-URI update view.
|
|
134
139
|
},
|
|
140
|
+
onDocumentDirtyChanged(): void {
|
|
141
|
+
// Out of band for the per-URI update view, as persistence is.
|
|
142
|
+
},
|
|
143
|
+
onDocumentDeleted(event: TransferDocumentDeletedEvent): void {
|
|
144
|
+
// In band, unlike the two neighbours: this is the end of the stream
|
|
145
|
+
// the view exists to show, and a consumer that never hears it waits
|
|
146
|
+
// forever for an update that cannot come. The line carries no
|
|
147
|
+
// `document`, so a reader must switch on shape rather than assume one.
|
|
148
|
+
if (event.uri !== options.uri) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
write(`${JSON.stringify(event)}\n`);
|
|
152
|
+
},
|
|
153
|
+
onDocumentsBuilt(): void {
|
|
154
|
+
// Out of band for a per-URI view by construction: this notification
|
|
155
|
+
// carries only documents nobody watches, and this command watches the
|
|
156
|
+
// one URI it was given.
|
|
157
|
+
},
|
|
135
158
|
onProjectsChanged(): void {
|
|
136
159
|
// Project lifecycle is out of band for the per-URI update view.
|
|
137
160
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { heapCeilingArgs } from '@hydranium/core/node';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Heap ceiling in MiB for a driver child on a machine with no cgroup limit.
|
|
14
|
+
*
|
|
15
|
+
* The subcommands that spawn one build a whole workspace in that child —
|
|
16
|
+
* `measure-memory` deliberately so, `analyze-heap` loads an entire heap
|
|
17
|
+
* snapshot — so the default Node would pick from physical RAM is too low for
|
|
18
|
+
* the workspaces these are pointed at.
|
|
19
|
+
*/
|
|
20
|
+
export const DRIVER_HEAP_MB = 8192;
|
|
21
|
+
|
|
22
|
+
/** Environment variable an operator raises or lowers {@link driverHeapArgs} with. */
|
|
23
|
+
export const DRIVER_HEAP_ENV = 'HYDRANIUM_CLI_MAX_OLD_SPACE_MB';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Smallest ceiling {@link DRIVER_HEAP_ENV} may state. A driver child builds a
|
|
27
|
+
* whole workspace, so a value this far below the default is a unit mistake
|
|
28
|
+
* rather than a deliberate squeeze.
|
|
29
|
+
*/
|
|
30
|
+
export const MIN_DRIVER_HEAP_MB = 256;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A cgroup reading, so a caller — in practice a test — can decide the ceiling
|
|
34
|
+
* instead of inheriting the machine's. Omitted fields fall back to this
|
|
35
|
+
* process's own reading.
|
|
36
|
+
*/
|
|
37
|
+
export interface HeapReading {
|
|
38
|
+
readonly constrained?: number;
|
|
39
|
+
readonly total?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The `execArgv` prefix every driver child is spawned under.
|
|
44
|
+
*
|
|
45
|
+
* Inside a container this is EMPTY on purpose. {@link DRIVER_HEAP_MB} is sized
|
|
46
|
+
* for a workstation, and handing it to a process under a smaller cgroup limit
|
|
47
|
+
* is worse than handing it nothing: V8 has no reason to collect hard below a
|
|
48
|
+
* ceiling it will never reach, so the kernel OOM-kills the container first and
|
|
49
|
+
* the failure arrives as a signal against the whole cgroup rather than as a
|
|
50
|
+
* heap error the parent can attribute. Left to itself, Node sizes the heap from
|
|
51
|
+
* the limit instead.
|
|
52
|
+
*
|
|
53
|
+
* That trades away the ability to use a LARGE container's memory, since Node's
|
|
54
|
+
* derived default is a fraction of the limit — which is what {@link DRIVER_HEAP_ENV}
|
|
55
|
+
* is for. An operator who states a number has decided, so it wins in a
|
|
56
|
+
* container too.
|
|
57
|
+
*/
|
|
58
|
+
export function driverHeapArgs(reading: HeapReading = {}): string[] {
|
|
59
|
+
return heapCeilingArgs({
|
|
60
|
+
desktopDefaultMb: DRIVER_HEAP_MB,
|
|
61
|
+
envValue: process.env[DRIVER_HEAP_ENV],
|
|
62
|
+
minMb: MIN_DRIVER_HEAP_MB,
|
|
63
|
+
...reading
|
|
64
|
+
});
|
|
65
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
+
export * from './commands/generate-ast-builder.js';
|
|
10
11
|
export * from './commands/generate-transfer-model.js';
|
|
11
12
|
export * from './commands/projects.js';
|
|
12
13
|
export * from './commands/query.js';
|