@rarog/server 1.1.0-beta.1 → 1.1.0
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 -2
- package/node_modules/@rarog/shared/package.json +1 -1
- package/node_modules/@rarog/shared/src/decode.js +16 -1
- package/node_modules/@rarog/shared/src/protocol/folders.js +27 -0
- package/node_modules/@rarog/shared/src/protocol/herdr.js +23 -0
- package/node_modules/@rarog/shared/src/protocol/notes.js +7 -1
- package/node_modules/@rarog/shared/src/protocol.js +5 -31
- package/node_modules/@rarog/shared/src/sentences/herdr.js +0 -4
- package/node_modules/@rarog/shared/src/sentences/index.js +7 -1
- package/node_modules/@rarog/shared/src/sentences/rest.js +8 -0
- package/package.json +2 -2
- package/server/src/auth/admin.js +3 -1
- package/server/src/bootstrap/consent.js +11 -0
- package/server/src/bootstrap/folder-gate.js +55 -0
- package/server/src/cli/service-log.js +27 -0
- package/server/src/cli/service.js +5 -2
- package/server/src/cli/templates/launchd.plist +1 -1
- package/server/src/cli/templates/rarog.service +1 -1
- package/server/src/cli/update-provenance.js +37 -19
- package/server/src/config/protected-dirs.js +2 -0
- package/server/src/config/roots.js +13 -8
- package/server/src/config/work-area.js +36 -12
- package/server/src/config-env.js +9 -0
- package/server/src/config.js +17 -1
- package/server/src/demo/control.js +9 -1
- package/server/src/drivers/herdr/consent-no-hook.js +103 -8
- package/server/src/drivers/herdr/screen-fallback.js +246 -0
- package/server/src/drivers/herdr-driver.js +78 -9
- package/server/src/files/file-index.js +5 -3
- package/server/src/files/listing.js +8 -2
- package/server/src/files/path-rule.js +95 -41
- package/server/src/files/refusals.js +14 -0
- package/server/src/files/session-gate.js +11 -6
- package/server/src/folder-gate/client.js +314 -0
- package/server/src/folder-gate/disk.js +455 -0
- package/server/src/folder-gate/folders.js +23 -0
- package/server/src/folder-gate/gate.js +220 -0
- package/server/src/folder-gate/helper.js +118 -0
- package/server/src/folder-gate/install.js +27 -0
- package/server/src/folder-gate/relay-worker.js +147 -0
- package/server/src/folder-gate/types.js +115 -0
- package/server/src/folder-gate/wire.js +170 -0
- package/server/src/fs-browse.js +55 -23
- package/server/src/fs-mkdir.js +3 -1
- package/server/src/git-status.js +13 -5
- package/server/src/git-watch.js +130 -19
- package/server/src/git-work-tree.js +3 -3
- package/server/src/herdr/client.js +2 -2
- package/server/src/herdr/commands/discover.js +21 -9
- package/server/src/herdr/dialogs/consent-gate.js +28 -8
- package/server/src/herdr/dialogs/decide/sources.js +5 -2
- package/server/src/herdr/dialogs/hook/contract.js +1 -1
- package/server/src/herdr/dialogs/index.js +7 -2
- package/server/src/herdr/dialogs/layer1/cycle.js +43 -7
- package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +34 -27
- package/server/src/herdr/dialogs/layer1/screen-key.js +52 -0
- package/server/src/herdr/dialogs/router.js +21 -6
- package/server/src/herdr/dialogs/screen/parse.js +23 -2
- package/server/src/herdr/dialogs/screen/resolve.js +9 -7
- package/server/src/herdr/dialogs/screen-fallback.js +55 -0
- package/server/src/herdr/dialogs/shadow/alive.js +9 -8
- package/server/src/herdr/jsonl-follow.js +55 -14
- package/server/src/herdr/provenance.js +3 -3
- package/server/src/herdr/socket.js +25 -28
- package/server/src/herdr/supervisor.js +13 -10
- package/server/src/herdr/transcript-path.js +36 -0
- package/server/src/herdr/trust.js +11 -8
- package/server/src/herdr/uploads-registry.js +3 -2
- package/server/src/herdr/uploads.js +170 -47
- package/server/src/index.js +22 -3
- package/server/src/iroh/listener.js +3 -0
- package/server/src/iroh/log-budget.js +1 -0
- package/server/src/iroh/socket.js +2 -1
- package/server/src/notes/store.js +3 -2
- package/server/src/router.js +13 -1
- package/server/src/routes/projects.js +5 -1
- package/server/src/routes/sessions.js +10 -4
- package/server/src/routes/system.js +4 -0
- package/server/src/safe-read.js +12 -12
- package/server/src/sessions/companion-scope.js +10 -5
- package/server/src/sessions/done-retention.js +57 -0
- package/server/src/sessions/launch-gate.js +2 -2
- package/server/src/sessions/manager.js +35 -59
- package/server/src/sessions/project-scan.js +9 -3
- package/server/src/sessions/ring-buffer.js +8 -21
- package/server/src/sessions/session-git.js +31 -2
- package/server/src/sessions/session.js +1 -1
- package/server/src/sessions/state-sentences.js +1 -1
- package/server/src/sse.js +121 -22
- package/server/src/term/herdr-backend.js +2 -2
- package/server/src/term/index.js +2 -15
- package/server/src/term/registry.js +4 -3
- package/server/src/term/ws.js +9 -1
package/server/src/sse.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { HELLO_HEARTBEAT_MS, MAX_IMAGE_DATA_URL_BYTES } from '@rarog/shared';
|
|
2
2
|
import { say } from '@rarog/shared/sentences';
|
|
3
3
|
import { constants as zlibConstants, createGzip } from 'node:zlib';
|
|
4
|
+
import { folderGate as processFolderGate } from './folder-gate/install.js';
|
|
5
|
+
import { RING_MAX_BYTES } from './sessions/ring-buffer.js';
|
|
4
6
|
/**
|
|
5
7
|
* Default heartbeat interval (SSE comment plus a `ping` event) in ms. Every stream gets it, and `hello` announces it
|
|
6
8
|
* as `heartbeatMs`, so a client can tell a stream that stopped without an error from a quiet one.
|
|
@@ -38,6 +40,22 @@ export const REPLAY_SNAPSHOT_LOG = 'sse: replay';
|
|
|
38
40
|
* dziennie.
|
|
39
41
|
*/
|
|
40
42
|
export const SNAPSHOT_IMAGE_BUDGET_BYTES = MAX_IMAGE_DATA_URL_BYTES;
|
|
43
|
+
/**
|
|
44
|
+
* Backlog a stream may hold unsent on top of twice its largest frame: the socket buffer of the response plus the
|
|
45
|
+
* compressor input.
|
|
46
|
+
*
|
|
47
|
+
* A single valid frame has no fixed upper size (a snapshot carries every pending consent card besides a full ring
|
|
48
|
+
* ({@link RING_MAX_BYTES}) and the image budget), and with compression it sits in the compressor input while its
|
|
49
|
+
* output already fills the socket buffer, so the allowance grows with the largest frame the stream was sent and one
|
|
50
|
+
* frame never cuts a healthy client. A stream above the ceiling is a client that stopped reading, and its bytes would
|
|
51
|
+
* otherwise stay in server memory until the socket times out.
|
|
52
|
+
*/
|
|
53
|
+
export const SSE_WRITE_BUFFER_MAX = 2 * (RING_MAX_BYTES + SNAPSHOT_IMAGE_BUDGET_BYTES);
|
|
54
|
+
/**
|
|
55
|
+
* Phrase of the log line of a stream cut at the ceiling:
|
|
56
|
+
* `sse: write buffer over ceiling <MiB> MiB, stream closed (global|session <id>[, device <id>])`.
|
|
57
|
+
*/
|
|
58
|
+
export const WRITE_BUFFER_CUT_LOG = 'sse: write buffer over ceiling';
|
|
41
59
|
/**
|
|
42
60
|
* Podmienny data URL dla obrazka poza budżetem: przezroczysty PNG 1×1.
|
|
43
61
|
*
|
|
@@ -171,6 +189,11 @@ export class SseHub {
|
|
|
171
189
|
logger;
|
|
172
190
|
onClientCount;
|
|
173
191
|
inbox;
|
|
192
|
+
folderGateOption;
|
|
193
|
+
/** The enabled gate the hub listens to since `start()`; `undefined` = no `folder-access` frames. */
|
|
194
|
+
folderGate;
|
|
195
|
+
/** The closed folders as JSON, as the streams last heard them: a change that keeps the list sends nothing. */
|
|
196
|
+
folderBlocked = '';
|
|
174
197
|
gzipEnabled;
|
|
175
198
|
createGzipFn;
|
|
176
199
|
/**
|
|
@@ -187,6 +210,13 @@ export class SseHub {
|
|
|
187
210
|
heartbeat = null;
|
|
188
211
|
nextClientId = 1;
|
|
189
212
|
started = false;
|
|
213
|
+
/**
|
|
214
|
+
* Token of the current {@link start}. The manager offers no way to detach a listener, so the listeners of an earlier
|
|
215
|
+
* start check it and do nothing after {@link closeAll}; the Inbox and folder gate listeners are detached for real.
|
|
216
|
+
*/
|
|
217
|
+
subscription = null;
|
|
218
|
+
detachInbox;
|
|
219
|
+
detachFolderGate;
|
|
190
220
|
constructor(options) {
|
|
191
221
|
this.manager = options.manager;
|
|
192
222
|
this.serverStartId = options.serverStartId;
|
|
@@ -196,6 +226,7 @@ export class SseHub {
|
|
|
196
226
|
this.logger = options.logger;
|
|
197
227
|
this.onClientCount = options.onClientCount;
|
|
198
228
|
this.inbox = options.inbox;
|
|
229
|
+
this.folderGateOption = options.folderGate;
|
|
199
230
|
this.gzipEnabled = options.gzip ?? false;
|
|
200
231
|
this.createGzipFn = options.createGzip ?? (() => createGzip());
|
|
201
232
|
this.heartbeatMs = options.heartbeatMs ?? HEARTBEAT_MS;
|
|
@@ -224,9 +255,17 @@ export class SseHub {
|
|
|
224
255
|
if (this.started)
|
|
225
256
|
return;
|
|
226
257
|
this.started = true;
|
|
227
|
-
|
|
228
|
-
this.
|
|
229
|
-
this.
|
|
258
|
+
const token = {};
|
|
259
|
+
this.subscription = token;
|
|
260
|
+
this.manager.onEvent((scope, seq, ev) => { if (this.subscription === token)
|
|
261
|
+
this.broadcast(scope, seq, ev); });
|
|
262
|
+
this.detachInbox = this.inbox?.onEvent((event) => { this.broadcastInbox(event); });
|
|
263
|
+
const gate = this.folderGateOption ?? processFolderGate();
|
|
264
|
+
if (gate.enabled) {
|
|
265
|
+
this.folderGate = gate;
|
|
266
|
+
this.folderBlocked = JSON.stringify(gate.blocked());
|
|
267
|
+
this.detachFolderGate = gate.onChange(() => { this.broadcastFolderAccess(gate); });
|
|
268
|
+
}
|
|
230
269
|
if (this.heartbeatMs > 0) {
|
|
231
270
|
this.heartbeat = this.setIntervalFn(() => { this.sendHeartbeat(); }, this.heartbeatMs);
|
|
232
271
|
}
|
|
@@ -294,17 +333,6 @@ export class SseHub {
|
|
|
294
333
|
if (frame !== null && ready.type === 'session-changed')
|
|
295
334
|
this.announceNewCwd(ready.session.cwd);
|
|
296
335
|
}
|
|
297
|
-
/**
|
|
298
|
-
* A new card under an open session id: each open stream of that id gets a `transcript-snapshot` of the new card, which
|
|
299
|
-
* replaces the old card's list in the app. A push the server starts is not an opening of the transcript, so the
|
|
300
|
-
* snapshot is read with `peek` (no git refresh).
|
|
301
|
-
*/
|
|
302
|
-
resetTranscript(sessionId) {
|
|
303
|
-
for (const client of [...this.clients.values()]) {
|
|
304
|
-
if (client.scope === sessionId)
|
|
305
|
-
this.sendTranscriptSnapshot(client, sessionId, undefined, true);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
336
|
/**
|
|
309
337
|
* Sends an Inbox event to the global streams opened with `inbox=1`; an older app never asks, so it never gets one.
|
|
310
338
|
* Fleeting like `herdr-status`: no `id:`, nothing to replay, a stream that opens later gets `inbox-heads`.
|
|
@@ -318,6 +346,19 @@ export class SseHub {
|
|
|
318
346
|
this.writeRaw(client, frame);
|
|
319
347
|
}
|
|
320
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Sends `folder-access` to every global stream when the list of closed folders changed. The gate tells about every
|
|
351
|
+
* change of state, also one the list does not show (unknown to open, a missing folder). Fleeting like `herdr-status`:
|
|
352
|
+
* no `id:`, and a stream that opens later gets the list right after `sessions-snapshot`.
|
|
353
|
+
*/
|
|
354
|
+
broadcastFolderAccess(gate) {
|
|
355
|
+
const blocked = gate.blocked();
|
|
356
|
+
const json = JSON.stringify(blocked);
|
|
357
|
+
if (json === this.folderBlocked)
|
|
358
|
+
return;
|
|
359
|
+
this.folderBlocked = json;
|
|
360
|
+
this.broadcast('global', null, { type: 'folder-access', blocked });
|
|
361
|
+
}
|
|
321
362
|
/**
|
|
322
363
|
* Dokłada do ramki `sessions-snapshot` pole `notesCwds` i odnotowuje, o czym klient już wie.
|
|
323
364
|
*
|
|
@@ -362,6 +403,7 @@ export class SseHub {
|
|
|
362
403
|
/**
|
|
363
404
|
* Otwiera strumień globalny: `hello` + `sessions-snapshot`, potem live.
|
|
364
405
|
* `Last-Event-ID` jest tu celowo ignorowany — snapshot listy jest tani i zawsze aktualny.
|
|
406
|
+
* With the folder gate on, `folder-access` follows the list.
|
|
365
407
|
* `inbox`: the client asked for the Inbox heads (`inbox=1`); on a server with an Inbox `inbox-heads` follows the
|
|
366
408
|
* list and the stream gets the Inbox events from then on.
|
|
367
409
|
*/
|
|
@@ -393,6 +435,10 @@ export class SseHub {
|
|
|
393
435
|
* Liczy to `withNotes`, ta sama metoda co przy ramkach z managera — patrz `broadcast`.
|
|
394
436
|
*/
|
|
395
437
|
this.send(client, this.withNotes(snapshot), null);
|
|
438
|
+
// The closed macOS folders, also none: an empty list clears a banner the app kept from before the reconnect.
|
|
439
|
+
if (this.folderGate !== undefined) {
|
|
440
|
+
this.send(client, { type: 'folder-access', blocked: this.folderGate.blocked() }, null);
|
|
441
|
+
}
|
|
396
442
|
// The Inbox heads after the list (`inbox=1`), so the app knows every session a head names.
|
|
397
443
|
if (client.inbox && this.inbox !== undefined) {
|
|
398
444
|
this.send(client, { type: 'inbox-heads', heads: this.inbox.heads() }, null);
|
|
@@ -469,7 +515,7 @@ export class SseHub {
|
|
|
469
515
|
}
|
|
470
516
|
return closed;
|
|
471
517
|
}
|
|
472
|
-
/**
|
|
518
|
+
/** Closes every stream, stops the heartbeat and detaches what {@link start} attached (graceful shutdown). */
|
|
473
519
|
closeAll() {
|
|
474
520
|
for (const client of this.clients.values())
|
|
475
521
|
this.endClient(client);
|
|
@@ -479,13 +525,20 @@ export class SseHub {
|
|
|
479
525
|
this.clearIntervalFn(this.heartbeat);
|
|
480
526
|
this.heartbeat = null;
|
|
481
527
|
}
|
|
528
|
+
this.subscription = null;
|
|
529
|
+
this.detachInbox?.();
|
|
530
|
+
this.detachInbox = undefined;
|
|
531
|
+
this.detachFolderGate?.();
|
|
532
|
+
this.detachFolderGate = undefined;
|
|
533
|
+
this.folderGate = undefined;
|
|
534
|
+
this.started = false;
|
|
482
535
|
}
|
|
483
536
|
/**
|
|
484
537
|
* Wysyła `transcript-snapshot` i oddaje ramkę — waga trafia do linii logu powtórki. `onFlushed` dostaje wagę ramki po
|
|
485
538
|
* kompresji albo `null`, gdy kompresor zamknął się przed opróżnieniem bufora; bez kompresji nie jest wołane.
|
|
486
539
|
*/
|
|
487
|
-
sendTranscriptSnapshot(client, sessionId, onFlushed
|
|
488
|
-
const t =
|
|
540
|
+
sendTranscriptSnapshot(client, sessionId, onFlushed) {
|
|
541
|
+
const t = this.manager.transcript(sessionId);
|
|
489
542
|
const event = {
|
|
490
543
|
type: 'transcript-snapshot',
|
|
491
544
|
sessionId,
|
|
@@ -505,7 +558,8 @@ export class SseHub {
|
|
|
505
558
|
register(scope, res, owner, acceptEncoding, inbox = false) {
|
|
506
559
|
const id = this.nextClientId++;
|
|
507
560
|
const gzip = this.gzipEnabled && acceptsGzip(acceptEncoding) ? this.createGzipFn() : undefined;
|
|
508
|
-
const client = { id, scope, inbox, res, owner, gzip, bytesOut: 0, flushedBytes: 0
|
|
561
|
+
const client = { id, scope, inbox, res, owner, gzip, bytesOut: 0, flushedBytes: 0, cut: false,
|
|
562
|
+
largestFrame: 0 };
|
|
509
563
|
res.writeHead(200, {
|
|
510
564
|
...SSE_HEADERS,
|
|
511
565
|
// Przy włączonej kompresji odpowiedź zależy od `Accept-Encoding`; pośrednik nie ma jej podać innemu klientowi.
|
|
@@ -519,6 +573,8 @@ export class SseHub {
|
|
|
519
573
|
*/
|
|
520
574
|
const sink = res;
|
|
521
575
|
gzip.on('data', (bytes) => {
|
|
576
|
+
if (client.cut)
|
|
577
|
+
return;
|
|
522
578
|
client.bytesOut += bytes.length;
|
|
523
579
|
try {
|
|
524
580
|
sink.write(bytes);
|
|
@@ -527,7 +583,9 @@ export class SseHub {
|
|
|
527
583
|
// Zerwane gniazdo: klient znika z rejestru, kompresor się zamyka.
|
|
528
584
|
this.dropClient(id);
|
|
529
585
|
gzip.destroy();
|
|
586
|
+
return;
|
|
530
587
|
}
|
|
588
|
+
this.cutIfOverCeiling(client);
|
|
531
589
|
});
|
|
532
590
|
// Błąd kompresora kończy strumień; klient łączy się od nowa.
|
|
533
591
|
gzip.on('error', () => {
|
|
@@ -541,8 +599,11 @@ export class SseHub {
|
|
|
541
599
|
});
|
|
542
600
|
}
|
|
543
601
|
this.writeRaw(client, `retry: ${RETRY_MS}\n\n`);
|
|
544
|
-
|
|
545
|
-
|
|
602
|
+
// A socket already over the ceiling cuts the stream at its first line; such a client never enters the register.
|
|
603
|
+
if (!client.cut) {
|
|
604
|
+
this.clients.set(id, client);
|
|
605
|
+
this.countChanged();
|
|
606
|
+
}
|
|
546
607
|
res.on('close', () => {
|
|
547
608
|
this.dropClient(id);
|
|
548
609
|
// Rozłączenie: kompresor nie ma już dokąd pisać, więc zamyka się od razu.
|
|
@@ -584,11 +645,18 @@ export class SseHub {
|
|
|
584
645
|
* (`write()` oddało `false`), `null` = gniazdo zerwane i klient wyrejestrowany.
|
|
585
646
|
*/
|
|
586
647
|
writeChecked(client, chunk, onFlushed) {
|
|
648
|
+
if (client.cut)
|
|
649
|
+
return null;
|
|
650
|
+
client.largestFrame = Math.max(client.largestFrame, Buffer.byteLength(chunk));
|
|
587
651
|
try {
|
|
588
652
|
const gzip = client.gzip;
|
|
589
|
-
if (gzip === undefined)
|
|
590
|
-
|
|
653
|
+
if (gzip === undefined) {
|
|
654
|
+
const accepted = client.res.write(chunk);
|
|
655
|
+
return this.cutIfOverCeiling(client) ? null : accepted;
|
|
656
|
+
}
|
|
591
657
|
const accepted = gzip.write(chunk);
|
|
658
|
+
if (this.cutIfOverCeiling(client))
|
|
659
|
+
return null;
|
|
592
660
|
/*
|
|
593
661
|
* Opróżnienie bufora po KAŻDYM zapisie (ramka, ping, `retry:`): bez niego gzip trzyma bajty, aż uzbiera blok,
|
|
594
662
|
* a ping czekałby na następną ramkę. `Z_SYNC_FLUSH` zostawia słownik, więc ramka dalej kompresuje się względem
|
|
@@ -608,4 +676,35 @@ export class SseHub {
|
|
|
608
676
|
return null;
|
|
609
677
|
}
|
|
610
678
|
}
|
|
679
|
+
/**
|
|
680
|
+
* Cuts the stream when its unsent bytes pass {@link SSE_WRITE_BUFFER_MAX} plus twice its largest frame: the response
|
|
681
|
+
* buffer plus, with compression, the compressor input not yet compressed. The connection is destroyed rather than ended, because the
|
|
682
|
+
* stream would never get its bytes out; the client reconnects and gets a snapshot or a replay.
|
|
683
|
+
*
|
|
684
|
+
* @returns `true` = the stream was cut now.
|
|
685
|
+
*/
|
|
686
|
+
cutIfOverCeiling(client) {
|
|
687
|
+
if (client.cut)
|
|
688
|
+
return false;
|
|
689
|
+
const buffered = (client.res.writableLength ?? 0) + (client.gzip?.writableLength ?? 0);
|
|
690
|
+
if (buffered <= SSE_WRITE_BUFFER_MAX + 2 * client.largestFrame)
|
|
691
|
+
return false;
|
|
692
|
+
client.cut = true;
|
|
693
|
+
this.dropClient(client.id);
|
|
694
|
+
client.gzip?.destroy();
|
|
695
|
+
try {
|
|
696
|
+
if (client.res.destroy === undefined)
|
|
697
|
+
client.res.end();
|
|
698
|
+
else
|
|
699
|
+
client.res.destroy();
|
|
700
|
+
}
|
|
701
|
+
catch {
|
|
702
|
+
// The client may already be gone.
|
|
703
|
+
}
|
|
704
|
+
const mib = (bytes) => (bytes / (1024 * 1024)).toFixed(1);
|
|
705
|
+
const scope = client.scope === 'global' ? 'global' : `session ${client.scope}`;
|
|
706
|
+
const device = client.owner === undefined ? '' : `, device ${client.owner}`;
|
|
707
|
+
this.logger?.(`${WRITE_BUFFER_CUT_LOG} ${mib(SSE_WRITE_BUFFER_MAX)} MiB, stream closed (${scope}${device})`);
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
611
710
|
}
|
|
@@ -550,8 +550,8 @@ export function createHerdrBackend(options) {
|
|
|
550
550
|
*
|
|
551
551
|
* Niczego NIE zamyka (rola `lazygit`/`popup` też nie: token mógł zniknąć bez restartu herdr,
|
|
552
552
|
* a w panelu żyje praca) i niczego nie zakłada. Każda mutacja stoi za `refusal()` i `disposed`,
|
|
553
|
-
* sprawdzanymi po każdym `await`; `HerdrReadOnlyError` (
|
|
554
|
-
*
|
|
553
|
+
* sprawdzanymi po każdym `await`; `HerdrReadOnlyError` (`SEND=0` at the socket, a second line
|
|
554
|
+
* behind `refusal()`) ends the pass's mutations with one log line.
|
|
555
555
|
*/
|
|
556
556
|
async function reconcilePass() {
|
|
557
557
|
if (disposed)
|
package/server/src/term/index.js
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Terminal PTY — złożenie ficzeru.
|
|
3
|
-
*
|
|
4
|
-
* Jedno wejście dla `index.ts` i routera: backend trwałej powłoki, żniwiarz bezczynności
|
|
5
|
-
* przy starcie, rejestr, transport WS i sprzątanie przy zamknięciu serwera.
|
|
6
|
-
*
|
|
7
|
-
* **Powłoka mieszka w PANELU herdr**: `RAROG_HERDR_LAUNCH=0` i `RAROG_HERDR_SEND=0` odmawiają
|
|
8
|
-
* założenia terminala (`refusal()` w `herdr-backend.ts`, 409 z routera), a żniwa paneli
|
|
9
|
-
* chodzą tylko wtedy, gdy wolno je w ogóle zakładać.
|
|
10
|
-
*
|
|
11
|
-
* WŁASNYM killswitchem terminala jest `RAROG_TERM` i tylko on gasi ficzer w całości.
|
|
12
|
-
* Granice spisane w `docs/security-model.md` (sekcja terminala, punkty 1 i 10).
|
|
13
|
-
*/
|
|
14
|
-
import { realpathSync } from 'node:fs';
|
|
15
1
|
import { redact } from '../auth/index.js';
|
|
16
2
|
import { TERM_START_RETRY_MS, TERM_TOKEN_REFRESH_MS, validateProjectCwd } from '../config.js';
|
|
17
3
|
import { DEMO_SERVER_SYSTEM } from '../demo/mac.js';
|
|
4
|
+
import { DIRECT_DISK } from '../folder-gate/disk.js';
|
|
18
5
|
import { serverSystem } from '../version.js';
|
|
19
6
|
import { createHerdrBackend } from './herdr-backend.js';
|
|
20
7
|
import { matchTermId, shouldReap } from './lifecycle.js';
|
|
@@ -139,7 +126,7 @@ async function adoptSurvivors(backend, config, registry, log) {
|
|
|
139
126
|
continue;
|
|
140
127
|
let real;
|
|
141
128
|
try {
|
|
142
|
-
real =
|
|
129
|
+
real = DIRECT_DISK.sync('realpath', { path: session.cwd });
|
|
143
130
|
}
|
|
144
131
|
catch {
|
|
145
132
|
continue; // Katalog zniknął — sesja zostaje dla żniwiarza, nie dla rejestru.
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
* **Zero logowania treści.** Do `server.log` idzie WYŁĄCZNIE cykl życia (id, cwd, spawn,
|
|
19
19
|
* kill, exit, liczba gniazd). Ani jeden bajt wejścia ani wyjścia powłoki.
|
|
20
20
|
*/
|
|
21
|
-
import { realpathSync } from 'node:fs';
|
|
22
21
|
import { isPopupRole, TERM_SLOTS_MAX } from '@rarog/shared';
|
|
23
22
|
import { redact } from '../auth/index.js';
|
|
23
|
+
import { DIRECT_DISK } from '../folder-gate/disk.js';
|
|
24
24
|
import { serverSystem } from '../version.js';
|
|
25
25
|
import { say } from '@rarog/shared/sentences';
|
|
26
26
|
import { TermBackendRetryError, TermHandleStaleError, errFrame } from './backend.js';
|
|
@@ -88,8 +88,9 @@ export class TermRegistry {
|
|
|
88
88
|
constructor(options) {
|
|
89
89
|
this.config = options.config;
|
|
90
90
|
this.log = options.logger;
|
|
91
|
-
this.realPath = options.realPath ??
|
|
92
|
-
this.legacyRealPath = options.legacyRealPath ?? options.realPath
|
|
91
|
+
this.realPath = options.realPath ?? ((candidate) => DIRECT_DISK.sync('realpathNative', { path: candidate }));
|
|
92
|
+
this.legacyRealPath = options.legacyRealPath ?? options.realPath
|
|
93
|
+
?? ((candidate) => DIRECT_DISK.sync('realpath', { path: candidate }));
|
|
93
94
|
this.setTimer = options.setTimer ?? ((cb, ms) => setTimeout(cb, ms));
|
|
94
95
|
this.clearTimer = options.clearTimer ?? ((timer) => { clearTimeout(timer); });
|
|
95
96
|
this.backend = options.backend;
|
package/server/src/term/ws.js
CHANGED
|
@@ -40,7 +40,15 @@ export const TERM_PASTE_INTERRUPTED_LOG = 'input in the middle of a paste';
|
|
|
40
40
|
* starszy klient nie widzi żadnej zmiany.
|
|
41
41
|
*/
|
|
42
42
|
export function termAttachFromUrl(rawUrl) {
|
|
43
|
-
|
|
43
|
+
// The HTTP parser lets through targets `URL` rejects (`//:/`); this runs before any credential, and a throw here
|
|
44
|
+
// would end the process, so an unparsable target is a path outside `/api/term/:id`.
|
|
45
|
+
let url;
|
|
46
|
+
try {
|
|
47
|
+
url = new URL(rawUrl ?? '/', 'http://127.0.0.1');
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
44
52
|
const match = /^\/api\/term\/([^/]+)$/.exec(url.pathname.replace(/\/+$/, ''));
|
|
45
53
|
const id = match?.[1];
|
|
46
54
|
if (id === undefined || !TERM_ID_RE.test(id))
|