@hydranium/client-theia 1.0.0-next.36 → 1.0.0-next.360

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 (95) hide show
  1. package/README.md +52 -80
  2. package/lib/browser/browser-capture.js.map +1 -1
  3. package/lib/browser/channel-logger.d.ts +4 -3
  4. package/lib/browser/channel-logger.d.ts.map +1 -1
  5. package/lib/browser/channel-logger.js +11 -19
  6. package/lib/browser/channel-logger.js.map +1 -1
  7. package/lib/browser/connection-diagnostics-contribution.d.ts +73 -0
  8. package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
  9. package/lib/browser/connection-diagnostics-contribution.js +162 -0
  10. package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
  11. package/lib/browser/connection-reporter.d.ts +57 -0
  12. package/lib/browser/connection-reporter.d.ts.map +1 -0
  13. package/lib/browser/connection-reporter.js +104 -0
  14. package/lib/browser/connection-reporter.js.map +1 -0
  15. package/lib/browser/editor-disk-sync.d.ts +142 -0
  16. package/lib/browser/editor-disk-sync.d.ts.map +1 -0
  17. package/lib/browser/editor-disk-sync.js +250 -0
  18. package/lib/browser/editor-disk-sync.js.map +1 -0
  19. package/lib/browser/hydranium-file-service.d.ts +44 -0
  20. package/lib/browser/hydranium-file-service.d.ts.map +1 -0
  21. package/lib/browser/hydranium-file-service.js +61 -0
  22. package/lib/browser/hydranium-file-service.js.map +1 -0
  23. package/lib/browser/index.d.ts +5 -0
  24. package/lib/browser/index.d.ts.map +1 -1
  25. package/lib/browser/index.js +5 -0
  26. package/lib/browser/index.js.map +1 -1
  27. package/lib/browser/log-level-preference.d.ts.map +1 -1
  28. package/lib/browser/log-level-preference.js +11 -0
  29. package/lib/browser/log-level-preference.js.map +1 -1
  30. package/lib/browser/memory-diagnostics-contribution.d.ts +1 -1
  31. package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
  32. package/lib/browser/memory-diagnostics-contribution.js +1 -1
  33. package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
  34. package/lib/browser/session-aware-connection-source.d.ts +104 -0
  35. package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
  36. package/lib/browser/session-aware-connection-source.js +193 -0
  37. package/lib/browser/session-aware-connection-source.js.map +1 -0
  38. package/lib/common/clock.d.ts +19 -0
  39. package/lib/common/clock.d.ts.map +1 -0
  40. package/lib/common/clock.js +13 -0
  41. package/lib/common/clock.js.map +1 -0
  42. package/lib/common/connection-resilience-options.d.ts +30 -0
  43. package/lib/common/connection-resilience-options.d.ts.map +1 -0
  44. package/lib/common/connection-resilience-options.js +11 -0
  45. package/lib/common/connection-resilience-options.js.map +1 -0
  46. package/lib/common/framed-socket-write-buffer.d.ts +173 -0
  47. package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
  48. package/lib/common/framed-socket-write-buffer.js +293 -0
  49. package/lib/common/framed-socket-write-buffer.js.map +1 -0
  50. package/lib/common/inbound-message-sequence.d.ts +56 -0
  51. package/lib/common/inbound-message-sequence.d.ts.map +1 -0
  52. package/lib/common/inbound-message-sequence.js +98 -0
  53. package/lib/common/inbound-message-sequence.js.map +1 -0
  54. package/lib/common/index.d.ts +13 -0
  55. package/lib/common/index.d.ts.map +1 -0
  56. package/lib/common/index.js +32 -0
  57. package/lib/common/index.js.map +1 -0
  58. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +16 -12
  59. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
  60. package/lib/node/abstract-socket-forwarding-connection-handler.js +94 -31
  61. package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
  62. package/lib/node/index.d.ts +2 -0
  63. package/lib/node/index.d.ts.map +1 -1
  64. package/lib/node/index.js +2 -0
  65. package/lib/node/index.js.map +1 -1
  66. package/lib/node/session-bound-frontend-connection-service.d.ts +122 -0
  67. package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
  68. package/lib/node/session-bound-frontend-connection-service.js +236 -0
  69. package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
  70. package/lib/node/socket-channel-forwarder.d.ts +54 -0
  71. package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
  72. package/lib/node/socket-channel-forwarder.js +95 -0
  73. package/lib/node/socket-channel-forwarder.js.map +1 -0
  74. package/lib/testing/stub-inversify-context.js.map +1 -1
  75. package/lib/testing/stub-output-channel.js.map +1 -1
  76. package/package.json +33 -34
  77. package/src/browser/browser-capture.ts +1 -1
  78. package/src/browser/channel-logger.ts +11 -19
  79. package/src/browser/connection-diagnostics-contribution.ts +146 -0
  80. package/src/browser/connection-reporter.ts +121 -0
  81. package/src/browser/editor-disk-sync.ts +253 -0
  82. package/src/browser/hydranium-file-service.ts +56 -0
  83. package/src/browser/index.ts +5 -0
  84. package/src/browser/log-level-preference.ts +11 -0
  85. package/src/browser/memory-diagnostics-contribution.ts +4 -3
  86. package/src/browser/session-aware-connection-source.ts +205 -0
  87. package/src/common/clock.ts +20 -0
  88. package/src/common/connection-resilience-options.ts +30 -0
  89. package/src/common/framed-socket-write-buffer.ts +345 -0
  90. package/src/common/inbound-message-sequence.ts +102 -0
  91. package/src/common/index.ts +16 -0
  92. package/src/node/abstract-socket-forwarding-connection-handler.ts +85 -36
  93. package/src/node/index.ts +2 -0
  94. package/src/node/session-bound-frontend-connection-service.ts +264 -0
  95. package/src/node/socket-channel-forwarder.ts +101 -0
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the MIT License which is available in the project root.
7
+ *
8
+ * SPDX-License-Identifier: MIT
9
+ ********************************************************************************/
10
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ };
16
+ var __metadata = (this && this.__metadata) || function (k, v) {
17
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.SessionBoundFrontendConnectionService = exports.AcknowledgedSocketChannel = void 0;
21
+ exports.bindConnectionResilience = bindConnectionResilience;
22
+ const protocol_1 = require("@hydranium/protocol");
23
+ const disposable_1 = require("@theia/core/lib/common/disposable");
24
+ const channel_1 = require("@theia/core/lib/common/message-rpc/channel");
25
+ const uint8_array_message_buffer_1 = require("@theia/core/lib/common/message-rpc/uint8-array-message-buffer");
26
+ const backend_application_config_provider_1 = require("@theia/core/lib/node/backend-application-config-provider");
27
+ const socket_write_buffer_1 = require("@theia/core/lib/common/messaging/socket-write-buffer");
28
+ const websocket_frontend_connection_service_1 = require("@theia/core/lib/node/messaging/websocket-frontend-connection-service");
29
+ const inversify_1 = require("@theia/core/shared/inversify");
30
+ const clock_1 = require("../common/clock");
31
+ const framed_socket_write_buffer_1 = require("../common/framed-socket-write-buffer");
32
+ const inbound_message_sequence_1 = require("../common/inbound-message-sequence");
33
+ /**
34
+ * The server end of one frontend's session, carried across the sockets the
35
+ * frontend reconnects on.
36
+ *
37
+ * Theia's own channel sends straight into any socket that reports itself
38
+ * connected. A socket whose far end died unnoticed still does, so whatever is
39
+ * sent until the server notices is lost. This one numbers and keeps every
40
+ * message through {@link FramedSocketWriteBuffer}, resends what is still
41
+ * unacknowledged when the frontend reconnects, and drops what it has received
42
+ * twice. Otherwise it behaves as Theia's.
43
+ */
44
+ class AcknowledgedSocketChannel extends channel_1.AbstractChannel {
45
+ socketBuffer;
46
+ socket;
47
+ socketDisposables = new disposable_1.DisposableCollection();
48
+ inbound = new inbound_message_sequence_1.InboundMessageSequence(sequence => this.socket?.emit(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, sequence));
49
+ constructor(socketBuffer) {
50
+ super();
51
+ this.socketBuffer = socketBuffer;
52
+ this.toDispose.push(this.inbound);
53
+ this.toDispose.push(disposable_1.Disposable.create(() => this.socketDisposables.dispose()));
54
+ }
55
+ /** Flushes in the same step that attaches the listeners, so nothing new can overtake the resend. */
56
+ connect(socket) {
57
+ this.socketDisposables.dispose();
58
+ this.socketDisposables = new disposable_1.DisposableCollection();
59
+ this.socket = socket;
60
+ const errorHandler = (error) => this.onErrorEmitter.fire(error);
61
+ const dataListener = (data, sequence) => {
62
+ if (typeof sequence === 'number') {
63
+ this.socketBuffer.markPeerDeduplicates();
64
+ }
65
+ if (!this.inbound.accept(sequence, data.byteLength)) {
66
+ return;
67
+ }
68
+ const buffer = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
69
+ this.onMessageEmitter.fire(() => new uint8_array_message_buffer_1.Uint8ArrayReadBuffer(buffer));
70
+ };
71
+ const acknowledgementListener = (sequence) => {
72
+ if (typeof sequence === 'number') {
73
+ this.socketBuffer.acknowledge(sequence);
74
+ }
75
+ };
76
+ socket.on('error', errorHandler);
77
+ socket.on('message', dataListener);
78
+ socket.on(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, acknowledgementListener);
79
+ this.socketDisposables.push(disposable_1.Disposable.create(() => {
80
+ socket.off('error', errorHandler);
81
+ socket.off('message', dataListener);
82
+ socket.off(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, acknowledgementListener);
83
+ }));
84
+ this.socketBuffer.flush(socket);
85
+ }
86
+ disconnect() {
87
+ this.socketDisposables.dispose();
88
+ this.socket = undefined;
89
+ }
90
+ drainBuffer() {
91
+ this.socketBuffer.drain();
92
+ }
93
+ getWriteBuffer() {
94
+ const writeBuffer = new uint8_array_message_buffer_1.Uint8ArrayWriteBuffer();
95
+ writeBuffer.onCommit(data => this.socketBuffer.sendOrQueue(this.socket?.connected ? this.socket : undefined, data));
96
+ return writeBuffer;
97
+ }
98
+ }
99
+ exports.AcknowledgedSocketChannel = AcknowledgedSocketChannel;
100
+ /**
101
+ * Ignores a disconnect from a socket that no longer belongs to the frontend.
102
+ *
103
+ * A frontend that loses its network reconnects on a new socket within seconds;
104
+ * the server only notices the old one is gone when its next heartbeat write
105
+ * fails, which is a whole ping interval later. For that stretch both sockets are
106
+ * registered against the same session, and Theia's disconnect handler tears the
107
+ * session off its socket without checking which one just died. The late
108
+ * notification from the abandoned socket therefore cuts the healthy one loose.
109
+ * The frontend sees a connected socket and never retries, so the session is dead
110
+ * until the page is reloaded.
111
+ *
112
+ * Changed here: only the socket the session is currently using may act on a
113
+ * disconnect. The handler is rewritten rather than wrapped because the problem
114
+ * sits inside the listener Theia installs; the rest of the body is Theia's.
115
+ *
116
+ * Re-diff against Theia when the supported range moves: `override` catches a changed signature,
117
+ * not a changed body, so this copy can go stale in silence.
118
+ */
119
+ let SessionBoundFrontendConnectionService = class SessionBoundFrontendConnectionService extends websocket_frontend_connection_service_1.WebsocketFrontendConnectionService {
120
+ /** Times the gaps the log reports: the container's {@link Clock}, or a `SystemClock`. */
121
+ clock = new protocol_1.SystemClock();
122
+ /** Socket each frontend's channel is currently bound to, with how long it has been. */
123
+ bindings = new Map();
124
+ /** Running since a frontend's live socket went away, so the reconnect gap can be reported. */
125
+ sinceOffline = new Map();
126
+ handleSocketDisconnect(socket, channel, frontEndId) {
127
+ const previous = this.bindings.get(frontEndId);
128
+ this.bindings.set(frontEndId, { socketId: socket.id, sinceBound: this.clock.stopwatch() });
129
+ const sinceOffline = this.sinceOffline.get(frontEndId);
130
+ this.sinceOffline.delete(frontEndId);
131
+ const replacing = previous ? `, replacing socket ${previous.socketId}` : '';
132
+ const gap = sinceOffline === undefined ? '' : `, after ${Math.round(sinceOffline.elapsedMs)} ms offline`;
133
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} frontend ${frontEndId} channel bound to socket ${socket.id}${replacing}${gap}`);
134
+ socket.on('disconnect', reason => {
135
+ const bound = this.bindings.get(frontEndId);
136
+ if (bound?.socketId !== socket.id) {
137
+ // Either a superseded socket being reaped late, or one outliving `closeConnection`, which
138
+ // deletes the binding. Neither owns the channel, so neither may disconnect it, arm a close
139
+ // timeout, or close a connection that is no longer in `connectionsByFrontend`.
140
+ const owner = bound
141
+ ? `socket ${bound.socketId} owns it (bound ${Math.round(bound.sinceBound.elapsedMs)} ms ago)`
142
+ : 'the connection is already closed';
143
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} ignoring disconnect of stale socket ${socket.id} (frontend ${frontEndId}, ${reason}); ${owner}`);
144
+ return;
145
+ }
146
+ // From here on: Theia's own handler body, unchanged apart from naming the socket.
147
+ this.sinceOffline.set(frontEndId, this.clock.stopwatch());
148
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} socket ${socket.id} (frontend ${frontEndId}) disconnected: ${reason}`);
149
+ channel.disconnect();
150
+ const timeout = this.connectionTimeout();
151
+ const isMarkedForClose = this.channelsMarkedForClose.delete(frontEndId);
152
+ if (timeout === 0 || isMarkedForClose) {
153
+ this.closeConnection(frontEndId, reason);
154
+ }
155
+ else if (timeout > 0) {
156
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} close timeout for frontend ${frontEndId} set to ${timeout} ms`);
157
+ this.closeTimeouts.set(frontEndId, setTimeout(() => this.closeConnection(frontEndId, reason), timeout));
158
+ }
159
+ // timeout < 0: never close the back end.
160
+ });
161
+ }
162
+ /**
163
+ * Theia's body, building an {@link AcknowledgedSocketChannel} in place of its own channel.
164
+ *
165
+ * Handed over through a cast, because Theia types the slot as its own channel class. The cast
166
+ * also hides from the compiler what Theia calls on the channel, so a release that calls a member
167
+ * this one lacks fails at runtime: re-diff with the disconnect handler.
168
+ */
169
+ createConnection(socket, frontEndId) {
170
+ const channel = new AcknowledgedSocketChannel(this.createWriteBuffer());
171
+ channel.connect(socket);
172
+ this.connectionsByFrontend.set(frontEndId, channel);
173
+ return channel;
174
+ }
175
+ /**
176
+ * One buffer per session, from the container Theia resolves its own channel's buffer from.
177
+ * Reached through a structural view because Theia 1.70 does not declare `container`.
178
+ */
179
+ createWriteBuffer() {
180
+ const container = this.container;
181
+ const buffer = container.get(socket_write_buffer_1.SocketWriteBuffer);
182
+ if (!(buffer instanceof framed_socket_write_buffer_1.FramedSocketWriteBuffer)) {
183
+ throw new Error('SessionBoundFrontendConnectionService requires FramedSocketWriteBuffer to be bound');
184
+ }
185
+ return buffer;
186
+ }
187
+ closeConnection(frontEndId, reason) {
188
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} closing frontend ${frontEndId}: ${reason}`);
189
+ this.bindings.delete(frontEndId);
190
+ this.sinceOffline.delete(frontEndId);
191
+ super.closeConnection(frontEndId, reason);
192
+ }
193
+ /** Mirrors Theia's private `frontendConnectionTimeout`, including `Number('')` resolving to 0.
194
+ * Private there, so the copy is forced; re-diff it with the handler above. */
195
+ connectionTimeout() {
196
+ const envValue = Number(process.env['FRONTEND_CONNECTION_TIMEOUT']);
197
+ if (!isNaN(envValue)) {
198
+ return envValue;
199
+ }
200
+ return backend_application_config_provider_1.BackendApplicationConfigProvider.get().frontendConnectionTimeout;
201
+ }
202
+ };
203
+ exports.SessionBoundFrontendConnectionService = SessionBoundFrontendConnectionService;
204
+ __decorate([
205
+ (0, inversify_1.inject)(clock_1.Clock),
206
+ (0, inversify_1.optional)(),
207
+ __metadata("design:type", Object)
208
+ ], SessionBoundFrontendConnectionService.prototype, "clock", void 0);
209
+ exports.SessionBoundFrontendConnectionService = SessionBoundFrontendConnectionService = __decorate([
210
+ (0, inversify_1.injectable)()
211
+ ], SessionBoundFrontendConnectionService);
212
+ /**
213
+ * Replaces the server pieces that decide how a session survives a reconnect.
214
+ *
215
+ * `FrontendConnectionService` is bound `toService(WebsocketFrontendConnectionService)`,
216
+ * so rebinding the concrete class is enough. The buffer stays transient (one per
217
+ * connection), matching Theia's `bind(SocketWriteBuffer).toSelf()`; the frontend
218
+ * counterpart is bound by `bindConnectionResilience` in a `frontendPreload`
219
+ * module, which is the only point early enough on that side.
220
+ *
221
+ * Does nothing but warn on a Theia too old to expose the buffer binding, so the
222
+ * package keeps one supported range rather than splitting its floor for this
223
+ * feature. Returns whether the hardening was installed, for an adopter that
224
+ * wants to branch on it.
225
+ */
226
+ function bindConnectionResilience(bind, isBound, rebind, options = {}) {
227
+ if (!(0, framed_socket_write_buffer_1.supportsConnectionResilience)(isBound)) {
228
+ (0, framed_socket_write_buffer_1.warnConnectionResilienceUnavailable)('backend');
229
+ return false;
230
+ }
231
+ bind(SessionBoundFrontendConnectionService).toSelf().inSingletonScope();
232
+ rebind(websocket_frontend_connection_service_1.WebsocketFrontendConnectionService).toService(SessionBoundFrontendConnectionService);
233
+ rebind(socket_write_buffer_1.SocketWriteBuffer).toDynamicValue(() => (0, framed_socket_write_buffer_1.createFramedSocketWriteBuffer)(options));
234
+ return true;
235
+ }
236
+ //# sourceMappingURL=session-bound-frontend-connection-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-bound-frontend-connection-service.js","sourceRoot":"","sources":["../../src/node/session-bound-frontend-connection-service.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;AAElF,kDAAkE;AAClE,kEAAqF;AACrF,wEAA6E;AAE7E,8GAA4H;AAC5H,kHAA4G;AAC5G,8FAAyF;AACzF,gIAA0H;AAC1H,4DAA6F;AAC7F,2CAAwC;AAExC,qFAM8C;AAC9C,iFAAmG;AAqBnG;;;;;;;;;;GAUG;AACH,+BAAuC,SAAQ,yBAAe;IAK5B,YAAY;IAJjC,MAAM,CAA6B;IACnC,iBAAiB,GAAG,IAAI,iCAAoB,EAAE,CAAC;IACtC,OAAO,GAAG,IAAI,iDAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,g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AO,sEAAgC,CAAC,GAAG,EAAE,CAAC,yBAAyB,CAAC;IAC3E,CAAC;CACH,CAAA;;AA3FgD;IAA7C,IAAA,kBAAM,EAAC,aAAK,CAAC;IAAE,IAAA,oBAAQ,GAAE;;oEAAqD;gDAFrE,qCAAqC;IADjD,IAAA,sBAAU,GAAE;GACA,qCAAqC,CA6FjD;AAED;;;;;;;;;;;;;GAaG;AACH,kCACG,IAAqB,EACrB,OAA2B,EAC3B,MAAyB,EACzB,OAAO,GAAgC,EAAE;IAEzC,IAAI,CAAC,IAAA,yDAA4B,EAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,IAAA,gEAAmC,EAAC,SAAS,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,qCAAqC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACxE,MAAM,CAAC,0EAAkC,CAAC,CAAC,SAAS,CAAC,qCAAqC,CAAC,CAAC;IAC5F,MAAM,CAAC,uCAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,IAAA,0DAA6B,EAAC,OAAO,CAAC,CAAC,CAAC;IACvF,OAAO,IAAI,CAAC;AACf,CAAC"}
@@ -0,0 +1,54 @@
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
+ import { type Clock } from '@hydranium/protocol';
10
+ import { type Channel, Disposable, DisposableCollection, type MessageProvider } from '@theia/core';
11
+ import type * as net from 'node:net';
12
+ import { type Message, type MessageConnection } from 'vscode-jsonrpc/node';
13
+ /**
14
+ * Relays JSON-RPC messages between a Theia browser-frontend {@link Channel} and
15
+ * a server's TCP socket — the backend half of a head's transport. The server
16
+ * speaks vscode-jsonrpc (Content-Length framed) on the socket; the frontend
17
+ * speaks the same protocol over the channel. This forwarder decodes each side
18
+ * and re-emits on the other.
19
+ *
20
+ * Behaves as `@eclipse-glsp/theia-integration`'s `SocketConnectionForwarder`
21
+ * does, and both heads use it, except that when the channel closes, the writes
22
+ * still queued go out before the socket ends. A page going away sends its last
23
+ * messages and closes its channel in the same tick, and the writer takes
24
+ * several turns per message, so destroying the socket on the close loses them.
25
+ */
26
+ export declare class SocketChannelForwarder implements Disposable {
27
+ protected readonly channel: Channel;
28
+ protected readonly socket: net.Socket;
29
+ /** Times {@link flushTimeoutMs}. */
30
+ protected readonly clock: Clock;
31
+ protected readonly toDispose: DisposableCollection;
32
+ /** The last write to the socket; the writer runs its writes one at a time, so this settles last. */
33
+ protected lastWrite: Promise<void>;
34
+ /**
35
+ * How long {@link endSocket} waits for the queued writes before it destroys
36
+ * the socket anyway. Without a bound, a server that stops reading holds the
37
+ * socket open for good, and with it the server's end of the connection.
38
+ */
39
+ protected readonly flushTimeoutMs: number;
40
+ constructor(channel: Channel, socket: net.Socket,
41
+ /** Times {@link flushTimeoutMs}. */
42
+ clock?: Clock);
43
+ /**
44
+ * Dispose `connection`, which destroys the socket, once the writes queued
45
+ * before the channel closed are out, or {@link flushTimeoutMs} has passed. A
46
+ * write has settled once the socket handed its bytes to the OS, and
47
+ * destroying the socket then loses nothing.
48
+ */
49
+ protected endSocket(connection: MessageConnection): Promise<void>;
50
+ protected decodeChannelMessage(provider: MessageProvider): Message;
51
+ protected writeToChannel(message: Message): void;
52
+ dispose(): void;
53
+ }
54
+ //# sourceMappingURL=socket-channel-forwarder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-channel-forwarder.d.ts","sourceRoot":"","sources":["../../src/node/socket-channel-forwarder.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,KAAK,EAAe,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,KAAK,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,KAAK,KAAK,GAAG,MAAM,UAAU,CAAC;AACrC,OAAO,EAEJ,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAGxB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAuB,YAAW,UAAU;IAYnD,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO;IACnC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM;IACrC,oCAAoC;IACpC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK;IAdlC,SAAS,CAAC,QAAQ,CAAC,SAAS,uBAA8B;IAC1D,oGAAoG;IACpG,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAqB;IACvD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAU;IAEnD,YACsB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,GAAG,CAAC,MAAM;IACrC,oCAAoC;IACjB,KAAK,GAAE,KAAyB,EAyBrD;IAED;;;;;OAKG;IACH,UAAgB,SAAS,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGtE;IAED,SAAS,CAAC,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAGjE;IAED,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAI/C;IAED,OAAO,IAAI,IAAI,CAEd;CACH"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the MIT License which is available in the project root.
7
+ *
8
+ * SPDX-License-Identifier: MIT
9
+ ********************************************************************************/
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.SocketChannelForwarder = void 0;
12
+ const protocol_1 = require("@hydranium/protocol");
13
+ const core_1 = require("@theia/core");
14
+ const node_1 = require("vscode-jsonrpc/node");
15
+ /**
16
+ * Relays JSON-RPC messages between a Theia browser-frontend {@link Channel} and
17
+ * a server's TCP socket — the backend half of a head's transport. The server
18
+ * speaks vscode-jsonrpc (Content-Length framed) on the socket; the frontend
19
+ * speaks the same protocol over the channel. This forwarder decodes each side
20
+ * and re-emits on the other.
21
+ *
22
+ * Behaves as `@eclipse-glsp/theia-integration`'s `SocketConnectionForwarder`
23
+ * does, and both heads use it, except that when the channel closes, the writes
24
+ * still queued go out before the socket ends. A page going away sends its last
25
+ * messages and closes its channel in the same tick, and the writer takes
26
+ * several turns per message, so destroying the socket on the close loses them.
27
+ */
28
+ class SocketChannelForwarder {
29
+ channel;
30
+ socket;
31
+ clock;
32
+ toDispose = new core_1.DisposableCollection();
33
+ /** The last write to the socket; the writer runs its writes one at a time, so this settles last. */
34
+ lastWrite = Promise.resolve();
35
+ /**
36
+ * How long {@link endSocket} waits for the queued writes before it destroys
37
+ * the socket anyway. Without a bound, a server that stops reading holds the
38
+ * socket open for good, and with it the server's end of the connection.
39
+ */
40
+ flushTimeoutMs = 10_000;
41
+ constructor(channel, socket,
42
+ /** Times {@link flushTimeoutMs}. */
43
+ clock = new protocol_1.SystemClock()) {
44
+ this.channel = channel;
45
+ this.socket = socket;
46
+ this.clock = clock;
47
+ const reader = new node_1.SocketMessageReader(socket);
48
+ const writer = new node_1.SocketMessageWriter(socket);
49
+ // Never listens, so it handles no message and has nothing to log.
50
+ // ast-grep-ignore: connection-without-logger
51
+ const connection = (0, node_1.createMessageConnection)(reader, writer);
52
+ // Nothing here destroys the socket directly. `SocketMessageWriter.dispose()`
53
+ // destroys it itself, which covers both `dispose` and `endSocket`; and
54
+ // `connection.onClose` fires only from the reader's or writer's own close,
55
+ // which for a socket means the socket has already gone — so a destroy
56
+ // handler there is downstream of the effect it would be trying to cause.
57
+ this.toDispose.pushAll([
58
+ reader.listen(message => this.writeToChannel(message)),
59
+ channel.onMessage(provider => {
60
+ // A failed write means the socket is gone, which its own close reports.
61
+ this.lastWrite = writer.write(this.decodeChannelMessage(provider)).catch(() => undefined);
62
+ }),
63
+ channel.onClose(() => void this.endSocket(connection)),
64
+ connection.onClose(() => channel.close()),
65
+ core_1.Disposable.create(() => {
66
+ channel.close();
67
+ connection.dispose();
68
+ })
69
+ ]);
70
+ }
71
+ /**
72
+ * Dispose `connection`, which destroys the socket, once the writes queued
73
+ * before the channel closed are out, or {@link flushTimeoutMs} has passed. A
74
+ * write has settled once the socket handed its bytes to the OS, and
75
+ * destroying the socket then loses nothing.
76
+ */
77
+ async endSocket(connection) {
78
+ await this.clock.raceTimer(this.lastWrite, this.flushTimeoutMs);
79
+ connection.dispose();
80
+ }
81
+ decodeChannelMessage(provider) {
82
+ const buffer = provider().readBytes();
83
+ return JSON.parse(new TextDecoder().decode(buffer));
84
+ }
85
+ writeToChannel(message) {
86
+ const writeBuffer = this.channel.getWriteBuffer();
87
+ writeBuffer.writeBytes(new TextEncoder().encode(JSON.stringify(message)));
88
+ writeBuffer.commit();
89
+ }
90
+ dispose() {
91
+ this.toDispose.dispose();
92
+ }
93
+ }
94
+ exports.SocketChannelForwarder = SocketChannelForwarder;
95
+ //# sourceMappingURL=socket-channel-forwarder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-channel-forwarder.js","sourceRoot":"","sources":["../../src/node/socket-channel-forwarder.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,kDAA8D;AAC9D,sCAAmG;AAEnG,8CAM6B;AAE7B;;;;;;;;;;;;GAYG;AACH;IAYyB,OAAO;IACP,MAAM;IAEN,KAAK;IAdR,SAAS,GAAG,IAAI,2BAAoB,EAAE,CAAC;IAC1D,oGAAoG;IAC1F,SAAS,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IACvD;;;;OAIG;IACgB,cAAc,GAAW,MAAM,CAAC;IAEnD,YACsB,OAAgB,EAChB,MAAkB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AS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAChE,UAAU,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAES,oBAAoB,CAAC,QAAyB;QACrD,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC,SAAS,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAY,CAAC;IAClE,CAAC;IAES,cAAc,CAAC,OAAgB;QACtC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAClD,WAAW,CAAC,UAAU,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1E,WAAW,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACJ,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"stub-inversify-context.js","sourceRoot":"","sources":["../../src/testing/stub-inversify-context.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;AAQlF,4DAgBC;AApBD;;;2CAG2C;AAC3C,SAAgB,wBAAwB,CAAC,eAAwB;IAC9D,MAAM,aAAa,GAChB,eAAe,KAAK,SAAS;QAC1B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC;YACG,QAAQ,EAAE;gBACP;oBACG,kBAAkB,EAAE,eAAe,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE;iBAC7E;aACH;SACH,CAAC;IACV,OAAO;QACJ,cAAc,EAAE;YACb,aAAa;SACf;KAC8B,CAAC;AACtC,CAAC"}
1
+ {"version":3,"file":"stub-inversify-context.js","sourceRoot":"","sources":["../../src/testing/stub-inversify-context.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAIlF;;;2CAG2C;AAC3C,kCAAyC,eAAwB;IAC9D,MAAM,aAAa,GAChB,eAAe,KAAK,SAAS;QAC1B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC;YACG,QAAQ,EAAE;gBACP;oBACG,kBAAkB,EAAE,eAAe,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE;iBAC7E;aACH;SACH,CAAC;IACV,OAAO;QACJ,cAAc,EAAE;YACb,aAAa;SACf;KAC8B,CAAC;AACtC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"stub-output-channel.js","sourceRoot":"","sources":["../../src/testing/stub-output-channel.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;AAmBlF,oEAoBC;AApBD,SAAgB,4BAA4B;IACzC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;IACtD,OAAO;QACJ,QAAQ;QACR,UAAU,CAAC,IAAY;YACpB,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACjC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,GAAa,EAAE,CAAC;gBAC3B,OAAO,GAAG;oBACP,IAAI;oBACJ,KAAK;oBACL,UAAU,CAAC,IAAY;wBACpB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACpB,CAAC;iBACH,CAAC;gBACF,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,OAAO,CAAC;QAClB,CAAC;KACH,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"stub-output-channel.js","sourceRoot":"","sources":["../../src/testing/stub-output-channel.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAmBlF;IACG,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;IACtD,OAAO;QACJ,QAAQ;QACR,UAAU,CAAC,IAAY;YACpB,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACjC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,GAAa,EAAE,CAAC;gBAC3B,OAAO,GAAG;oBACP,IAAI;oBACJ,KAAK;oBACL,UAAU,CAAC,IAAY;wBACpB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACpB,CAAC;iBACH,CAAC;gBACF,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,OAAO,CAAC;QAClB,CAAC;KACH,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydranium/client-theia",
3
- "version": "1.0.0-next.36",
3
+ "version": "1.0.0-next.360",
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",
@@ -13,16 +13,23 @@
13
13
  "bugs": {
14
14
  "url": "https://github.com/eclipse-emfcloud/hydranium/issues"
15
15
  },
16
+ "license": "MIT",
17
+ "author": {
18
+ "name": "Hydranium Team"
19
+ },
16
20
  "repository": {
17
21
  "type": "git",
18
22
  "url": "https://github.com/eclipse-emfcloud/hydranium.git",
19
23
  "directory": "packages/client-theia"
20
24
  },
21
- "license": "MIT",
22
- "author": {
23
- "name": "Hydranium Team"
24
- },
25
+ "files": [
26
+ "lib",
27
+ "src",
28
+ "!lib/**/*.tsbuildinfo"
29
+ ],
25
30
  "sideEffects": false,
31
+ "main": "lib/index.js",
32
+ "types": "lib/index.d.ts",
26
33
  "exports": {
27
34
  ".": {
28
35
  "types": "./lib/index.d.ts",
@@ -32,64 +39,56 @@
32
39
  "types": "./lib/browser/index.d.ts",
33
40
  "default": "./lib/browser/index.js"
34
41
  },
35
- "./lib/browser": {
36
- "types": "./lib/browser/index.d.ts",
37
- "default": "./lib/browser/index.js"
42
+ "./common": {
43
+ "types": "./lib/common/index.d.ts",
44
+ "default": "./lib/common/index.js"
38
45
  },
39
46
  "./node": {
40
47
  "types": "./lib/node/index.d.ts",
41
48
  "default": "./lib/node/index.js"
42
49
  },
43
- "./lib/node": {
44
- "types": "./lib/node/index.d.ts",
45
- "default": "./lib/node/index.js"
46
- },
47
50
  "./testing": {
48
51
  "types": "./lib/testing/index.d.ts",
49
52
  "default": "./lib/testing/index.js"
50
- },
51
- "./lib/testing": {
52
- "types": "./lib/testing/index.d.ts",
53
- "default": "./lib/testing/index.js"
54
53
  }
55
54
  },
56
- "main": "lib/index.js",
57
- "types": "lib/index.d.ts",
58
- "files": [
59
- "lib",
60
- "src",
61
- "!lib/**/*.tsbuildinfo"
62
- ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
63
58
  "scripts": {
64
59
  "build": "tsc -b",
65
60
  "clean": "rimraf lib tsconfig.tsbuildinfo",
66
- "lint": "eslint src test --max-warnings 0",
61
+ "lint": "oxlint --format stylish --config ../../oxlint.config.cjs src test --max-warnings 0",
67
62
  "prepack": "node -e \"const m=require('./package.json'),fs=require('node:fs');const missing=[m.main,...Object.values(m.bin||{})].filter(entry=>entry&&!fs.existsSync(entry));if(missing.length){console.error('prepack '+m.name+': not built ('+missing.join(', ')+' missing). Run the build before packing: a files entry that matches nothing is skipped silently, so the tarball would ship src only.');process.exit(1);}\"",
68
63
  "test": "npm run typecheck:test && vitest run",
69
64
  "typecheck:test": "tsc --noEmit -p tsconfig.test.json",
70
65
  "watch": "tsc -b -w --preserveWatchOutput"
71
66
  },
72
67
  "devDependencies": {
73
- "@hydranium/protocol": "1.0.0-next.36",
74
- "@theia/core": "^1.70.0",
75
- "@theia/output": "^1.70.0",
68
+ "@hydranium/protocol": "1.0.0-next.360",
69
+ "@theia/core": "1.74.3",
70
+ "@theia/editor": "1.74.3",
71
+ "@theia/filesystem": "1.74.3",
72
+ "@theia/output": "1.74.3",
76
73
  "@types/node": "^22.0.0",
77
74
  "inversify": "6.2.2",
78
75
  "reflect-metadata": "0.2.2",
79
76
  "rimraf": "^5.0.0",
80
- "typescript": "^5.8.0"
77
+ "typescript": "^7.0.2",
78
+ "vscode-jsonrpc": "9.0.0"
81
79
  },
82
80
  "peerDependencies": {
83
- "@hydranium/protocol": "1.0.0-next.36",
81
+ "@hydranium/protocol": "1.0.0-next.360",
84
82
  "@theia/core": "^1.70.0",
83
+ "@theia/editor": "^1.70.0",
84
+ "@theia/filesystem": "^1.70.0",
85
85
  "@theia/output": "^1.70.0",
86
- "inversify": "^6.0.0"
86
+ "inversify": "^6.0.0",
87
+ "vscode-jsonrpc": "^9.0.0"
87
88
  },
88
89
  "engines": {
89
90
  "node": ">=22.13"
90
91
  },
91
- "publishConfig": {
92
- "access": "public"
93
- },
94
- "//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."
92
+ "//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. `vscode-jsonrpc` takes a caret: each `vscode-languageserver-protocol` release pins its transport exactly, so an exact peer would name a copy a fresh install rarely holds, while the caret still excludes the 8.x line.",
93
+ "//prepack": "The publish guard, a `prepack` rather than a `prepare`: `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. 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
94
  }
@@ -33,7 +33,7 @@ interface MemoryCapablePerformance {
33
33
  * CDP source (`nodes`/`jsEventListeners`/… + delta) is the e2e bridge's job.
34
34
  */
35
35
  export async function captureBrowserRuntime(): Promise<BrowserRuntimeReport> {
36
- const perf = globalThis.performance as (Performance & MemoryCapablePerformance) | undefined;
36
+ const perf = globalThis.performance as MemoryCapablePerformance | undefined;
37
37
  if (perf?.measureUserAgentSpecificMemory) {
38
38
  try {
39
39
  const result = await perf.measureUserAgentSpecificMemory();
@@ -10,6 +10,7 @@
10
10
  import { AbstractLogger, DefaultTracer, type LogLevel, type MemoryReader, SystemClock } from '@hydranium/protocol';
11
11
  import { injectable, type interfaces, unmanaged, inject } from '@theia/core/shared/inversify';
12
12
  import { type OutputChannel, OutputChannelManager } from '@theia/output/lib/browser/output-channel';
13
+ import { Clock } from '../common/clock';
13
14
 
14
15
  /**
15
16
  * Configuration for a {@link ChannelLogger}, supplied once at bind time via
@@ -65,10 +66,8 @@ export class ChannelLogger extends AbstractLogger {
65
66
  }
66
67
 
67
68
  protected emit(_level: LogLevel, label: string, message: string, args: readonly unknown[]): void {
68
- const componentSegment = this.component ? ` [${this.component}]` : '';
69
- const formattedArgs = args.length > 0 ? ' ' + args.map(stringifyArg).join(' ') : '';
70
- // Pad to match the server's 5-char label width so timestamps align across sources.
71
- this.channel.appendLine(`[${label.padEnd(5)} - ${this.timestamp()}]${componentSegment} ${message}${formattedArgs}`);
69
+ const formattedArgs = args.length > 0 ? ' ' + args.map(arg => this.formatArg(arg)).join(' ') : '';
70
+ this.channel.appendLine(`${this.formatLinePrefix(label)} ${message}${formattedArgs}`);
72
71
  }
73
72
 
74
73
  /**
@@ -94,9 +93,10 @@ const ChannelLoggerBase = Symbol('ChannelLoggerBase');
94
93
 
95
94
  /**
96
95
  * Inversify token for the browser `Tracer` — a {@link DefaultTracer} over
97
- * the {@link ChannelLogger} (emit sink) + a {@link SystemClock} + a browser
98
- * heap reader. The browser head has no Langium `services.Tracer` slot, so this
99
- * is how frontend services that time obtain a tracer: `@inject(ChannelTracer)`.
96
+ * the {@link ChannelLogger} (emit sink) + the container's {@link Clock}, or a
97
+ * `SystemClock` when it binds none, + a browser heap reader. The browser head
98
+ * has no Langium `services.Tracer` slot, so this is how frontend services that
99
+ * time obtain a tracer: `@inject(ChannelTracer)`.
100
100
  * Bound by {@link bindChannelLogger}.
101
101
  */
102
102
  export const ChannelTracer = Symbol('ChannelTracer');
@@ -134,7 +134,10 @@ export function bindChannelLogger(bind: interfaces.Bind, options: ChannelLoggerO
134
134
  return parentName ? base.for(parentName) : base;
135
135
  });
136
136
  bind(ChannelTracer)
137
- .toDynamicValue(ctx => new DefaultTracer(ctx.container.get<ChannelLogger>(ChannelLoggerBase), new SystemClock(), readBrowserMemory))
137
+ .toDynamicValue(ctx => {
138
+ const clock = ctx.container.isBound(Clock) ? ctx.container.get<Clock>(Clock) : new SystemClock();
139
+ return new DefaultTracer(ctx.container.get<ChannelLogger>(ChannelLoggerBase), clock, readBrowserMemory);
140
+ })
138
141
  .inSingletonScope();
139
142
  }
140
143
 
@@ -147,14 +150,3 @@ const readBrowserMemory: MemoryReader = () => {
147
150
  const mem = (performance as unknown as ChromiumPerformance).memory;
148
151
  return mem ? { usedBytes: mem.usedJSHeapSize, totalBytes: mem.totalJSHeapSize } : undefined;
149
152
  };
150
-
151
- function stringifyArg(arg: unknown): string {
152
- if (typeof arg === 'string') {
153
- return arg;
154
- }
155
- try {
156
- return JSON.stringify(arg);
157
- } catch {
158
- return String(arg);
159
- }
160
- }