@hydranium/client-theia 1.0.0-next.8 → 1.0.0-next.86

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 (51) hide show
  1. package/README.md +2 -2
  2. package/lib/browser/connection-diagnostics-contribution.d.ts +69 -0
  3. package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
  4. package/lib/browser/connection-diagnostics-contribution.js +153 -0
  5. package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
  6. package/lib/browser/index.d.ts +2 -0
  7. package/lib/browser/index.d.ts.map +1 -1
  8. package/lib/browser/index.js +2 -0
  9. package/lib/browser/index.js.map +1 -1
  10. package/lib/browser/log-level-preference.d.ts.map +1 -1
  11. package/lib/browser/log-level-preference.js +11 -0
  12. package/lib/browser/log-level-preference.js.map +1 -1
  13. package/lib/browser/memory-diagnostics-contribution.d.ts +40 -4
  14. package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
  15. package/lib/browser/memory-diagnostics-contribution.js +161 -31
  16. package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
  17. package/lib/browser/session-aware-connection-source.d.ts +98 -0
  18. package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
  19. package/lib/browser/session-aware-connection-source.js +167 -0
  20. package/lib/browser/session-aware-connection-source.js.map +1 -0
  21. package/lib/common/connection-resilience-options.d.ts +24 -0
  22. package/lib/common/connection-resilience-options.d.ts.map +1 -0
  23. package/lib/common/connection-resilience-options.js +11 -0
  24. package/lib/common/connection-resilience-options.js.map +1 -0
  25. package/lib/common/framed-socket-write-buffer.d.ts +121 -0
  26. package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
  27. package/lib/common/framed-socket-write-buffer.js +190 -0
  28. package/lib/common/framed-socket-write-buffer.js.map +1 -0
  29. package/lib/common/index.d.ts +11 -0
  30. package/lib/common/index.d.ts.map +1 -0
  31. package/lib/common/index.js +30 -0
  32. package/lib/common/index.js.map +1 -0
  33. package/lib/node/index.d.ts +1 -0
  34. package/lib/node/index.d.ts.map +1 -1
  35. package/lib/node/index.js +1 -0
  36. package/lib/node/index.js.map +1 -1
  37. package/lib/node/session-bound-frontend-connection-service.d.ts +77 -0
  38. package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
  39. package/lib/node/session-bound-frontend-connection-service.js +128 -0
  40. package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
  41. package/package.json +16 -7
  42. package/src/browser/connection-diagnostics-contribution.ts +142 -0
  43. package/src/browser/index.ts +2 -0
  44. package/src/browser/log-level-preference.ts +11 -0
  45. package/src/browser/memory-diagnostics-contribution.ts +268 -45
  46. package/src/browser/session-aware-connection-source.ts +179 -0
  47. package/src/common/connection-resilience-options.ts +24 -0
  48. package/src/common/framed-socket-write-buffer.ts +227 -0
  49. package/src/common/index.ts +14 -0
  50. package/src/node/index.ts +1 -0
  51. package/src/node/session-bound-frontend-connection-service.ts +155 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydranium/client-theia",
3
- "version": "1.0.0-next.8",
3
+ "version": "1.0.0-next.86",
4
4
  "description": "Cross-head Theia client primitives shared by the hydranium protocol heads. Provides the socket-forwarding connection-handler base that the data-server and GLSP Theia integrations subclass, plus the preference-driven Output-channel logger; carries no head-specific dependency.",
5
5
  "keywords": [
6
6
  "hydranium",
@@ -36,6 +36,14 @@
36
36
  "types": "./lib/browser/index.d.ts",
37
37
  "default": "./lib/browser/index.js"
38
38
  },
39
+ "./common": {
40
+ "types": "./lib/common/index.d.ts",
41
+ "default": "./lib/common/index.js"
42
+ },
43
+ "./lib/common": {
44
+ "types": "./lib/common/index.d.ts",
45
+ "default": "./lib/common/index.js"
46
+ },
39
47
  "./node": {
40
48
  "types": "./lib/node/index.d.ts",
41
49
  "default": "./lib/node/index.js"
@@ -70,9 +78,9 @@
70
78
  "watch": "tsc -b -w --preserveWatchOutput"
71
79
  },
72
80
  "devDependencies": {
73
- "@hydranium/protocol": "1.0.0-next.8",
74
- "@theia/core": "^1.71.0",
75
- "@theia/output": "^1.71.0",
81
+ "@hydranium/protocol": "1.0.0-next.86",
82
+ "@theia/core": "^1.70.0",
83
+ "@theia/output": "^1.70.0",
76
84
  "@types/node": "^22.0.0",
77
85
  "inversify": "6.2.2",
78
86
  "reflect-metadata": "0.2.2",
@@ -80,9 +88,9 @@
80
88
  "typescript": "^5.8.0"
81
89
  },
82
90
  "peerDependencies": {
83
- "@hydranium/protocol": "1.0.0-next.8",
84
- "@theia/core": "^1.71.0",
85
- "@theia/output": "^1.71.0",
91
+ "@hydranium/protocol": "1.0.0-next.86",
92
+ "@theia/core": "^1.70.0",
93
+ "@theia/output": "^1.70.0",
86
94
  "inversify": "^6.0.0"
87
95
  },
88
96
  "engines": {
@@ -91,5 +99,6 @@
91
99
  "publishConfig": {
92
100
  "access": "public"
93
101
  },
102
+ "//peerDependencies": "@theia/core stays at 1.70 here, matching the sibling Theia packages, even though the connection-resilience bindings need 1.71: Theia only began binding `SocketWriteBuffer` then, and before that each connection built one privately, so there is no binding to rebind. Rather than split the package's floor for one feature, `bindConnectionResilience` probes for that binding and warns instead of installing when it is absent — a capability check rather than a version parse, so it answers about the container in front of it. Everything else the feature touches exists at 1.70, and the emitted declarations deliberately name no type that 1.70 lacks, so the package still compiles there. Verified by unpacking 1.70, 1.71 and 1.72, not inferred from a changelog.",
94
103
  "//prepack": "The publish guard, and it deliberately is NOT a `prepare`: npm runs a workspace `prepare` BEFORE the root `postinstall` that applies patches/vscode-jsonrpc+9.0.1.patch, so building there fails on a cold clone and npm rolls the entire install back. `prepack` runs only when a tarball is made (`npm pack`, `npm publish`) and never on install, so it cannot break the install it has no business touching. It FAILS rather than rebuilds, because the rebuild is exactly the part that ordering defeats. What it defends against: `files` lists `lib`, `lib` is gitignored, and a `files` entry matching nothing is skipped SILENTLY — so `npm publish` from an unbuilt tree emits a tarball of `src` and nothing else, with no error."
95
104
  }
@@ -0,0 +1,142 @@
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 { MessageService, nls } from '@theia/core';
11
+ import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application-contribution';
12
+ import { ConnectionStatus, ConnectionStatusService } from '@theia/core/lib/browser/connection-status-service';
13
+ import { WebSocketConnectionSource } from '@theia/core/lib/browser/messaging/ws-connection-source';
14
+ import { inject, injectable, type interfaces } from '@theia/core/shared/inversify';
15
+ import { type ConnectionBufferOverflow } from '../common/framed-socket-write-buffer';
16
+ import { ChannelLogger } from './channel-logger';
17
+ import { SessionAwareConnectionSource } from './session-aware-connection-source';
18
+
19
+ /**
20
+ * Records the browser side of the websocket lifecycle into the adopter's Output
21
+ * channel, and tells the user the one thing they cannot recover from on their
22
+ * own.
23
+ *
24
+ * Theia reports an outage only as an "Offline" status-bar item, which cannot
25
+ * distinguish a plain network drop from the server having stopped answering on a
26
+ * socket that is still up. The latter is what a connection defect looks like
27
+ * from here, so the two are logged differently — that distinction is what says
28
+ * whether reopening an editor helps or only a reload does.
29
+ *
30
+ * Purely observational apart from the overflow message: nothing here changes how
31
+ * the connection behaves.
32
+ */
33
+ @injectable()
34
+ export class ConnectionDiagnosticsContribution implements FrontendApplicationContribution {
35
+ @inject(WebSocketConnectionSource) protected readonly connectionSource: WebSocketConnectionSource;
36
+ @inject(ConnectionStatusService) protected readonly connectionStatus: ConnectionStatusService;
37
+ @inject(ChannelLogger) protected readonly logger: ChannelLogger;
38
+ @inject(MessageService) protected readonly messageService: MessageService;
39
+
40
+ /** Main channels created so far; more than one means the server did not recognise this frontend. */
41
+ protected channelCount = 0;
42
+ protected socketClosedAt?: number;
43
+ protected offlineAt?: number;
44
+
45
+ initialize(): void {
46
+ this.connectionSource.onSocketDidOpen(() => this.handleSocketOpen());
47
+ this.connectionSource.onSocketDidClose(() => this.handleSocketClose());
48
+ this.connectionSource.onConnectionDidOpen(() => this.handleChannelOpen());
49
+ this.connectionStatus.onStatusChange(status => this.handleStatusChange(status));
50
+ if (this.connectionSource instanceof SessionAwareConnectionSource) {
51
+ this.connectionSource.onBufferOverflow(overflow => this.handleBufferOverflow(overflow));
52
+ }
53
+ // The socket is opened by the preloader, before this contribution exists, so the first
54
+ // `onSocketDidOpen` has already fired; state the current situation instead.
55
+ this.logger.info(`diagnostics active; socket ${this.socketId()}, backend ${this.statusName(this.connectionStatus.currentStatus)}`);
56
+ }
57
+
58
+ protected handleSocketOpen(): void {
59
+ const downFor = this.socketClosedAt === undefined ? '' : ` after ${Date.now() - this.socketClosedAt} ms down`;
60
+ this.socketClosedAt = undefined;
61
+ this.logger.info(`websocket connected: socket ${this.socketId()}${downFor}`);
62
+ }
63
+
64
+ protected handleSocketClose(): void {
65
+ this.socketClosedAt = Date.now();
66
+ this.logger.info(`websocket disconnected: socket ${this.socketId()}; outgoing messages are buffered until it returns`);
67
+ }
68
+
69
+ /**
70
+ * A second channel means the reconnect was refused and the session discarded.
71
+ * Only reachable with `reloadOnReconnect` off — with it on, Theia reloads the
72
+ * page instead of opening another channel.
73
+ */
74
+ protected handleChannelOpen(): void {
75
+ this.channelCount++;
76
+ if (this.channelCount === 1) {
77
+ this.logger.info(`initial channel opened on socket ${this.socketId()}`);
78
+ return;
79
+ }
80
+ this.logger.warn(
81
+ `new channel #${this.channelCount} on socket ${this.socketId()}: the backend did not recognise this frontend, ` +
82
+ 'so its session was discarded and every pending request rejected'
83
+ );
84
+ }
85
+
86
+ protected handleStatusChange(status: ConnectionStatus): void {
87
+ if (status === ConnectionStatus.ONLINE) {
88
+ const offlineFor = this.offlineAt === undefined ? '' : ` after ${Date.now() - this.offlineAt} ms`;
89
+ this.offlineAt = undefined;
90
+ this.logger.info(`backend reachable again${offlineFor}`);
91
+ return;
92
+ }
93
+ this.offlineAt = Date.now();
94
+ const socket = this.connectionSource.socket;
95
+ if (socket?.connected) {
96
+ this.logger.warn(
97
+ `backend stopped answering while socket ${socket.id} is still connected: nothing this session sends will ` +
98
+ 'arrive, and socket.io will not reconnect on its own. Reload the page to recover.'
99
+ );
100
+ return;
101
+ }
102
+ this.logger.info(`backend unreachable; websocket is disconnected (socket ${this.socketId()})`);
103
+ }
104
+
105
+ /**
106
+ * The outage outlasted what the buffer can hold, so changes made from here on
107
+ * are being thrown away rather than queued. Reconnecting resumes sending but
108
+ * cannot bring those back, which leaves the editor disagreeing with the
109
+ * server — and without a message the user would see nothing but an editor
110
+ * that has quietly stopped saving, so say it plainly.
111
+ */
112
+ protected handleBufferOverflow(overflow: ConnectionBufferOverflow): void {
113
+ this.logger.error(`buffer full at ${overflow.maxBytes} bytes holding ${overflow.messages} message(s)`);
114
+ this.messageService.error(
115
+ nls.localize(
116
+ 'hydranium/connection/offlineLimitReached',
117
+ 'Disconnected for too long: recent changes were not sent. Reload the page before continuing.'
118
+ )
119
+ );
120
+ }
121
+
122
+ protected socketId(): string {
123
+ return this.connectionSource.socket?.id ?? WebSocketConnectionSource.NO_CONNECTION;
124
+ }
125
+
126
+ protected statusName(status: ConnectionStatus): string {
127
+ return status === ConnectionStatus.ONLINE ? 'online' : 'offline';
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Bind {@link ConnectionDiagnosticsContribution} as a `FrontendApplicationContribution`.
133
+ *
134
+ * Needs a {@link ChannelLogger} binding, so call it from a module that has also
135
+ * called `bindChannelLogger`. Unlike `bindConnectionResilience` this belongs in a
136
+ * normal frontend module: it only observes, so it has no reason to run during
137
+ * preload, and `MessageService` is not available that early.
138
+ */
139
+ export function bindConnectionDiagnostics(bind: interfaces.Bind): void {
140
+ bind(ConnectionDiagnosticsContribution).toSelf().inSingletonScope();
141
+ bind(FrontendApplicationContribution).toService(ConnectionDiagnosticsContribution);
142
+ }
@@ -12,3 +12,5 @@ export * from './channel-logger';
12
12
  export * from './log-level-preference';
13
13
  export * from './browser-capture';
14
14
  export * from './memory-diagnostics-contribution';
15
+ export * from './session-aware-connection-source';
16
+ export * from './connection-diagnostics-contribution';
@@ -108,7 +108,18 @@ export class LogLevelPreferenceContribution implements FrontendApplicationContri
108
108
  protected applyLevel(): void {
109
109
  const level = parseLogLevel(this.preferences.get<string>(this.preferenceName));
110
110
  if (level) {
111
+ const previous = Logger.getLevel();
111
112
  Logger.setLevel(level);
113
+ if (previous !== level) {
114
+ // Through Theia's `ILogger`, which has a threshold of its own and so
115
+ // is not silenced by the value just applied — the framework logger
116
+ // this preference governs would drop the line on a switch to `error`.
117
+ //
118
+ // Frontend and server announce separately: this preference reaches
119
+ // the server only if a client delivers it as configuration, so one
120
+ // line without the other says it did not.
121
+ this.logger.info(`Log level ${previous} → ${level} (preference '${this.preferenceName}')`);
122
+ }
112
123
  }
113
124
  }
114
125
  }
@@ -14,7 +14,7 @@ import {
14
14
  type StartProfilingArgs
15
15
  } from '@hydranium/protocol';
16
16
  import { captureBrowserRuntime, formatBrowserRuntime } from './browser-capture';
17
- import { CommandContribution, MessageService, type Command, type CommandRegistry } from '@theia/core';
17
+ import { CommandContribution, MessageService, nls, type Command, type CommandRegistry } from '@theia/core';
18
18
  import { inject, injectable, optional, type interfaces } from '@theia/core/shared/inversify';
19
19
  import { OutputChannelManager, type OutputChannel } from '@theia/output/lib/browser/output-channel';
20
20
 
@@ -54,6 +54,17 @@ export const MemoryDiagnosticsService = Symbol('MemoryDiagnosticsService');
54
54
  export type HostMemoryDiagnosticsService = HostDiagnosticsProtocol;
55
55
  export const HostMemoryDiagnosticsService = Symbol('HostMemoryDiagnosticsService');
56
56
 
57
+ /**
58
+ * What a `report` call captured, as a code rather than a prose fragment. The
59
+ * sentences it appears in are authored once per code, because a fragment
60
+ * substituted into a sentence is itself translatable text and a translator
61
+ * given the sentence alone cannot inflect around a hole.
62
+ */
63
+ export type DiagnosticsSubject = 'server-state' | 'pod-memory' | 'latency' | 'backend-state' | 'profile';
64
+
65
+ /** Which process a heap snapshot is taken of; a code, for the reason {@link DiagnosticsSubject} is one. */
66
+ export type HeapSnapshotTarget = 'server' | 'backend';
67
+
57
68
  /**
58
69
  * Memory-diagnostics commands, one per layer reachable from the frontend. Full
59
70
  * multi-line snapshots are appended to the configured output channel; a one-line
@@ -88,76 +99,162 @@ export class MemoryDiagnosticsContribution implements CommandContribution {
88
99
  * localized apart, leaving a button or an instruction that names a command
89
100
  * the user cannot find.
90
101
  */
91
- protected readonly stopProfilingLabel: string = 'Stop Profiling (Server)';
102
+ protected readonly stopProfilingLabel: string = nls.localize(
103
+ 'hydranium/client-theia/command-stop-profiling-server',
104
+ 'Stop Profiling (Server)'
105
+ );
92
106
 
93
107
  registerCommands(registry: CommandRegistry): void {
94
108
  const { category } = this.options;
95
- registry.registerCommand(this.command('dumpServerState', 'Dump Server State', category), {
96
- execute: () => this.report('server state', () => this.diagnostics.dumpServerState({ label: new Date().toISOString() }), ['heap'])
97
- });
98
- registry.registerCommand(this.command('dumpPodMemory', 'Dump Pod Memory', category), {
99
- execute: () => this.report('pod memory', () => this.diagnostics.dumpPodMemory(), ['current', 'rss sum'])
100
- });
101
- registry.registerCommand(this.command('dumpFrontendState', 'Dump Frontend State', category), {
102
- execute: () => this.dumpFrontendState()
103
- });
104
- registry.registerCommand(this.command('writeHeapSnapshot', 'Write Heap Snapshot (Server)', category), {
105
- execute: () => this.writeSnapshot('server', label => this.diagnostics.writeHeapSnapshot({ label }))
106
- });
109
+ registry.registerCommand(
110
+ this.command({
111
+ id: 'dumpServerState',
112
+ label: nls.localize('hydranium/client-theia/command-dump-server-state', 'Dump Server State'),
113
+ category
114
+ }),
115
+ {
116
+ execute: () =>
117
+ this.report('server-state', () => this.diagnostics.dumpServerState({ label: new Date().toISOString() }), ['heap'])
118
+ }
119
+ );
120
+ registry.registerCommand(
121
+ this.command({
122
+ id: 'dumpPodMemory',
123
+ label: nls.localize('hydranium/client-theia/command-dump-pod-memory', 'Dump Pod Memory'),
124
+ category
125
+ }),
126
+ {
127
+ execute: () => this.report('pod-memory', () => this.diagnostics.dumpPodMemory(), ['current', 'rss sum'])
128
+ }
129
+ );
130
+ registry.registerCommand(
131
+ this.command({
132
+ id: 'dumpFrontendState',
133
+ label: nls.localize('hydranium/client-theia/command-dump-frontend-state', 'Dump Frontend State'),
134
+ category
135
+ }),
136
+ {
137
+ execute: () => this.dumpFrontendState()
138
+ }
139
+ );
140
+ registry.registerCommand(
141
+ this.command({
142
+ id: 'writeHeapSnapshot',
143
+ label: nls.localize('hydranium/client-theia/command-write-heap-snapshot-server', 'Write Heap Snapshot (Server)'),
144
+ category
145
+ }),
146
+ {
147
+ execute: () => this.writeSnapshot('server', label => this.diagnostics.writeHeapSnapshot({ label }))
148
+ }
149
+ );
107
150
  // Sampled profiling of the server process — sampling does NOT pause it (unlike
108
151
  // the heap snapshot). Start/Stop are the manual pair; Record wraps a fixed window.
109
- registry.registerCommand(this.command('startProfiling', 'Start Profiling (Server)', category), {
110
- execute: () => this.startProfiling()
111
- });
112
- registry.registerCommand(this.command('stopProfiling', this.stopProfilingLabel, category), {
152
+ registry.registerCommand(
153
+ this.command({
154
+ id: 'startProfiling',
155
+ label: nls.localize('hydranium/client-theia/command-start-profiling-server', 'Start Profiling (Server)'),
156
+ category
157
+ }),
158
+ {
159
+ execute: () => this.startProfiling()
160
+ }
161
+ );
162
+ registry.registerCommand(this.command({ id: 'stopProfiling', label: this.stopProfilingLabel, category }), {
113
163
  execute: () => this.stopProfiling()
114
164
  });
115
165
  registry.registerCommand(
116
- this.command('recordProfile', `Record Performance Profile (Server, ${Math.round(this.recordDurationMs / 1000)}s)`, category),
166
+ this.command({
167
+ id: 'recordProfile',
168
+ // The window length rides the substitution path rather than a
169
+ // template literal: an extractor reads the source text, so an
170
+ // interpolated default is never in the catalogue at all.
171
+ label: nls.localize(
172
+ 'hydranium/client-theia/command-record-profile',
173
+ 'Record Performance Profile (Server, {0}s)',
174
+ this.recordDurationSeconds()
175
+ ),
176
+ category
177
+ }),
117
178
  {
118
179
  execute: () => this.recordProfile()
119
180
  }
120
181
  );
121
- registry.registerCommand(this.command('dumpLatency', 'Dump RPC/LSP Latency (Server)', category), {
122
- execute: () => this.report('RPC/LSP latency', async () => formatLatencyReport(await this.diagnostics.getLatency()), ['window'])
123
- });
182
+ registry.registerCommand(
183
+ this.command({
184
+ id: 'dumpLatency',
185
+ label: nls.localize('hydranium/client-theia/command-dump-latency', 'Dump RPC/LSP Latency (Server)'),
186
+ category
187
+ }),
188
+ {
189
+ execute: () => this.report('latency', async () => formatLatencyReport(await this.diagnostics.getLatency()), ['window'])
190
+ }
191
+ );
124
192
  // Host (Theia backend) process commands — registered only when the
125
193
  // optional host-diagnostics service is bound (see HostMemoryDiagnosticsService).
126
194
  const hostDiagnostics = this.hostDiagnostics;
127
195
  if (hostDiagnostics) {
128
- registry.registerCommand(this.command('dumpBackendState', 'Dump Backend State', category), {
129
- execute: () => this.report('backend state', () => hostDiagnostics.dumpHostState({ label: new Date().toISOString() }), ['heap'])
130
- });
131
- registry.registerCommand(this.command('writeBackendHeapSnapshot', 'Write Heap Snapshot (Backend)', category), {
132
- execute: () => this.writeSnapshot('backend', label => hostDiagnostics.writeHostHeapSnapshot({ label }))
133
- });
196
+ registry.registerCommand(
197
+ this.command({
198
+ id: 'dumpBackendState',
199
+ label: nls.localize('hydranium/client-theia/command-dump-backend-state', 'Dump Backend State'),
200
+ category
201
+ }),
202
+ {
203
+ execute: () =>
204
+ this.report('backend-state', () => hostDiagnostics.dumpHostState({ label: new Date().toISOString() }), ['heap'])
205
+ }
206
+ );
207
+ registry.registerCommand(
208
+ this.command({
209
+ id: 'writeBackendHeapSnapshot',
210
+ label: nls.localize('hydranium/client-theia/command-write-heap-snapshot-backend', 'Write Heap Snapshot (Backend)'),
211
+ category
212
+ }),
213
+ {
214
+ execute: () => this.writeSnapshot('backend', label => hostDiagnostics.writeHostHeapSnapshot({ label }))
215
+ }
216
+ );
134
217
  }
135
218
  }
136
219
 
137
- protected command(id: string, label: string, category: string): Command {
138
- return { id: `${this.options.commandIdPrefix}.${id}`, label, category };
220
+ /**
221
+ * Takes an object rather than positional arguments so that `label` — the one
222
+ * user-facing member — is addressable by name. A lint rule guarding the
223
+ * localization of labels has only syntax to work with, and a selector for an
224
+ * argument position would equally catch `id`, which must stay a bare literal.
225
+ */
226
+ protected command(spec: { id: string; label: string; category: string }): Command {
227
+ return { id: `${this.options.commandIdPrefix}.${spec.id}`, label: spec.label, category: spec.category };
228
+ }
229
+
230
+ /** The record window as whole seconds, for the label and the toast that must agree on it. */
231
+ protected recordDurationSeconds(): number {
232
+ return Math.round(this.recordDurationMs / 1000);
139
233
  }
140
234
 
141
235
  /** Run a snapshot call, append the full result to the channel, toast the first matching summary line. */
142
- protected async report(what: string, produce: () => Promise<string>, summaryKeys: string[]): Promise<void> {
236
+ protected async report(subject: DiagnosticsSubject, produce: () => Promise<string>, summaryKeys: string[]): Promise<void> {
143
237
  try {
144
238
  const snapshot = await produce();
145
239
  this.channel().appendLine(snapshot);
146
240
  this.channel().appendLine('');
147
- this.messageService.info(this.summarize(snapshot, what, summaryKeys), { timeout: 5000 });
241
+ this.messageService.info(this.summarize(snapshot, subject, summaryKeys), { timeout: 5000 });
148
242
  } catch (error) {
149
- this.messageService.error(`Failed to dump ${what}: ${this.errorMessage(error)}`);
243
+ this.messageService.error(this.dumpFailedMessage(subject, this.errorMessage(error)));
150
244
  }
151
245
  }
152
246
 
153
- protected async writeSnapshot(target: string, produce: (label: string) => Promise<string>): Promise<void> {
247
+ protected async writeSnapshot(target: HeapSnapshotTarget, produce: (label: string) => Promise<string>): Promise<void> {
154
248
  try {
155
- this.messageService.info(`Writing ${target} heap snapshot — this briefly pauses that process...`, { timeout: 3000 });
249
+ this.messageService.info(this.writingSnapshotMessage(target), { timeout: 3000 });
156
250
  const filePath = await produce(new Date().toISOString());
157
- this.channel().appendLine(`Heap snapshot (${target}) written to ${filePath}`);
158
- this.messageService.info(`Heap snapshot (${target}) written to ${filePath}`, { timeout: 8000 });
251
+ // One sentence, shown in both places: two literals of equal value can be
252
+ // localized apart, leaving the channel and the toast naming different files.
253
+ const written = this.wroteSnapshotMessage(target, filePath);
254
+ this.channel().appendLine(written);
255
+ this.messageService.info(written, { timeout: 8000 });
159
256
  } catch (error) {
160
- this.messageService.error(`Failed to write ${target} heap snapshot: ${this.errorMessage(error)}`);
257
+ this.messageService.error(this.writeSnapshotFailedMessage(target, this.errorMessage(error)));
161
258
  }
162
259
  }
163
260
 
@@ -166,7 +263,7 @@ export class MemoryDiagnosticsContribution implements CommandContribution {
166
263
  try {
167
264
  await this.diagnostics.startProfiling(this.profileDimensions);
168
265
  } catch (error) {
169
- this.messageService.error(`Failed to start profiling: ${this.errorMessage(error)}`);
266
+ this.messageService.error(this.startProfilingFailedMessage(this.errorMessage(error)));
170
267
  return;
171
268
  }
172
269
  // No timeout: the capture runs as long as the user wants it to, and an
@@ -174,7 +271,7 @@ export class MemoryDiagnosticsContribution implements CommandContribution {
174
271
  // toast is what keeps the action live, so this resolves only once the
175
272
  // user acts on it or dismisses it.
176
273
  const chosen = await this.messageService.info(
177
- 'Server profiling started — sampling does not stop the process.',
274
+ nls.localize('hydranium/client-theia/profiling-started', 'Server profiling started — sampling does not stop the process.'),
178
275
  { timeout: 0 },
179
276
  this.stopProfilingLabel
180
277
  );
@@ -188,15 +285,27 @@ export class MemoryDiagnosticsContribution implements CommandContribution {
188
285
  return this.report('profile', () => this.diagnostics.stopProfiling({ label: new Date().toISOString() }), ['duration']);
189
286
  }
190
287
 
288
+ /** One authored sentence for both start paths; identical literals in two places drift apart under translation. */
289
+ protected startProfilingFailedMessage(detail: string): string {
290
+ return nls.localize('hydranium/client-theia/error-start-profiling', 'Failed to start profiling: {0}', detail);
291
+ }
292
+
191
293
  /** Capture a fixed-length window: start, wait, stop, and report the result. */
192
294
  protected async recordProfile(): Promise<void> {
193
295
  try {
194
296
  await this.diagnostics.startProfiling(this.profileDimensions);
195
297
  } catch (error) {
196
- this.messageService.error(`Failed to start profiling: ${this.errorMessage(error)}`);
298
+ this.messageService.error(this.startProfilingFailedMessage(this.errorMessage(error)));
197
299
  return;
198
300
  }
199
- this.messageService.info(`Recording a ${Math.round(this.recordDurationMs / 1000)}s server performance profile...`, { timeout: 4000 });
301
+ this.messageService.info(
302
+ nls.localize(
303
+ 'hydranium/client-theia/recording-profile',
304
+ 'Recording a {0}s server performance profile...',
305
+ this.recordDurationSeconds()
306
+ ),
307
+ { timeout: 4000 }
308
+ );
200
309
  await this.delay(this.recordDurationMs);
201
310
  await this.stopProfiling();
202
311
  }
@@ -219,15 +328,129 @@ export class MemoryDiagnosticsContribution implements CommandContribution {
219
328
  }
220
329
 
221
330
  /** Pull the first line starting with one of `keys` for a one-line toast; full text is in the channel. */
222
- protected summarize(snapshot: string, what: string, keys: string[]): string {
331
+ protected summarize(snapshot: string, subject: DiagnosticsSubject, keys: string[]): string {
223
332
  const lines = snapshot.split('\n');
224
333
  for (const key of keys) {
225
334
  const line = lines.find(entry => entry.trim().startsWith(key));
226
335
  if (line) {
227
- return `Captured ${what} —${line.replace(new RegExp(`^\\s*${key}\\s*`), ` ${key} `)}`;
336
+ return this.capturedDetailMessage(subject, line.replace(new RegExp(`^\\s*${key}\\s*`), ` ${key} `));
228
337
  }
229
338
  }
230
- return `Captured ${what} (see the ${this.options.channelName} output channel)`;
339
+ return this.capturedChannelMessage(subject);
340
+ }
341
+
342
+ /**
343
+ * The captured-with-detail toast. The detail is a machine-formatted figure,
344
+ * so it is safe as a substitution parameter; the subject is not, hence one
345
+ * authored sentence per subject.
346
+ */
347
+ protected capturedDetailMessage(subject: DiagnosticsSubject, detail: string): string {
348
+ switch (subject) {
349
+ case 'server-state':
350
+ return nls.localize('hydranium/client-theia/captured-server-state-detail', 'Captured server state —{0}', detail);
351
+ case 'pod-memory':
352
+ return nls.localize('hydranium/client-theia/captured-pod-memory-detail', 'Captured pod memory —{0}', detail);
353
+ case 'latency':
354
+ return nls.localize('hydranium/client-theia/captured-latency-detail', 'Captured RPC/LSP latency —{0}', detail);
355
+ case 'backend-state':
356
+ return nls.localize('hydranium/client-theia/captured-backend-state-detail', 'Captured backend state —{0}', detail);
357
+ case 'profile':
358
+ return nls.localize('hydranium/client-theia/captured-profile-detail', 'Captured profile —{0}', detail);
359
+ }
360
+ }
361
+
362
+ /** The captured-without-detail toast; the channel name is adopter branding, not translatable text. */
363
+ protected capturedChannelMessage(subject: DiagnosticsSubject): string {
364
+ const channelName = this.options.channelName;
365
+ switch (subject) {
366
+ case 'server-state':
367
+ return nls.localize(
368
+ 'hydranium/client-theia/captured-server-state-channel',
369
+ 'Captured server state (see the {0} output channel)',
370
+ channelName
371
+ );
372
+ case 'pod-memory':
373
+ return nls.localize(
374
+ 'hydranium/client-theia/captured-pod-memory-channel',
375
+ 'Captured pod memory (see the {0} output channel)',
376
+ channelName
377
+ );
378
+ case 'latency':
379
+ return nls.localize(
380
+ 'hydranium/client-theia/captured-latency-channel',
381
+ 'Captured RPC/LSP latency (see the {0} output channel)',
382
+ channelName
383
+ );
384
+ case 'backend-state':
385
+ return nls.localize(
386
+ 'hydranium/client-theia/captured-backend-state-channel',
387
+ 'Captured backend state (see the {0} output channel)',
388
+ channelName
389
+ );
390
+ case 'profile':
391
+ return nls.localize(
392
+ 'hydranium/client-theia/captured-profile-channel',
393
+ 'Captured profile (see the {0} output channel)',
394
+ channelName
395
+ );
396
+ }
397
+ }
398
+
399
+ /** The failed-to-dump toast; the detail is a technical error string, safe as a parameter. */
400
+ protected dumpFailedMessage(subject: DiagnosticsSubject, detail: string): string {
401
+ switch (subject) {
402
+ case 'server-state':
403
+ return nls.localize('hydranium/client-theia/error-dump-server-state', 'Failed to dump server state: {0}', detail);
404
+ case 'pod-memory':
405
+ return nls.localize('hydranium/client-theia/error-dump-pod-memory', 'Failed to dump pod memory: {0}', detail);
406
+ case 'latency':
407
+ return nls.localize('hydranium/client-theia/error-dump-latency', 'Failed to dump RPC/LSP latency: {0}', detail);
408
+ case 'backend-state':
409
+ return nls.localize('hydranium/client-theia/error-dump-backend-state', 'Failed to dump backend state: {0}', detail);
410
+ case 'profile':
411
+ return nls.localize('hydranium/client-theia/error-dump-profile', 'Failed to dump profile: {0}', detail);
412
+ }
413
+ }
414
+
415
+ protected writingSnapshotMessage(target: HeapSnapshotTarget): string {
416
+ switch (target) {
417
+ case 'server':
418
+ return nls.localize(
419
+ 'hydranium/client-theia/writing-heap-snapshot-server',
420
+ 'Writing server heap snapshot — this briefly pauses that process...'
421
+ );
422
+ case 'backend':
423
+ return nls.localize(
424
+ 'hydranium/client-theia/writing-heap-snapshot-backend',
425
+ 'Writing backend heap snapshot — this briefly pauses that process...'
426
+ );
427
+ }
428
+ }
429
+
430
+ protected wroteSnapshotMessage(target: HeapSnapshotTarget, filePath: string): string {
431
+ switch (target) {
432
+ case 'server':
433
+ return nls.localize('hydranium/client-theia/wrote-heap-snapshot-server', 'Heap snapshot (server) written to {0}', filePath);
434
+ case 'backend':
435
+ return nls.localize('hydranium/client-theia/wrote-heap-snapshot-backend', 'Heap snapshot (backend) written to {0}', filePath);
436
+ }
437
+ }
438
+
439
+ protected writeSnapshotFailedMessage(target: HeapSnapshotTarget, detail: string): string {
440
+ switch (target) {
441
+ case 'server':
442
+ return nls.localize(
443
+ 'hydranium/client-theia/error-write-heap-snapshot-server',
444
+ 'Failed to write server heap snapshot: {0}',
445
+ detail
446
+ );
447
+ case 'backend':
448
+ return nls.localize(
449
+ 'hydranium/client-theia/error-write-heap-snapshot-backend',
450
+ 'Failed to write backend heap snapshot: {0}',
451
+ detail
452
+ );
453
+ }
231
454
  }
232
455
 
233
456
  protected errorMessage(error: unknown): string {