@rarog/server 1.0.1 → 1.1.0-beta.1
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 +4 -3
- package/node_modules/@rarog/shared/package.json +1 -1
- package/node_modules/@rarog/shared/src/decode.js +49 -3
- package/node_modules/@rarog/shared/src/protocol/files.js +33 -0
- package/node_modules/@rarog/shared/src/protocol/inbox.js +38 -0
- package/node_modules/@rarog/shared/src/protocol.js +16 -17
- package/node_modules/@rarog/shared/src/rest.js +106 -12
- package/node_modules/@rarog/shared/src/sentences/rest.js +13 -0
- package/package.json +3 -3
- package/server/src/bootstrap/consent.js +88 -2
- package/server/src/bootstrap/http.js +3 -2
- package/server/src/bootstrap/inbox.js +29 -4
- package/server/src/bootstrap/sse.js +2 -1
- package/server/src/cli/doctor-no-hook.js +162 -0
- package/server/src/cli/doctor.js +2 -0
- package/server/src/cli/update-channel.js +100 -0
- package/server/src/cli/update-registry.js +160 -62
- package/server/src/cli/update.js +13 -3
- package/server/src/companion/turns-settle.js +4 -1
- package/server/src/companion/turns.js +36 -5
- package/server/src/config/files.js +32 -0
- package/server/src/config/flags.js +10 -1
- package/server/src/config-env.js +24 -0
- package/server/src/config.js +6 -2
- package/server/src/demo/files.js +49 -0
- package/server/src/demo/inbox.js +73 -0
- package/server/src/demo/review-routes.js +6 -1
- package/server/src/device-effects.js +3 -1
- package/server/src/drivers/herdr/consent-no-hook-io.js +89 -0
- package/server/src/drivers/herdr/consent-no-hook.js +316 -0
- package/server/src/drivers/herdr/refusals.js +226 -0
- package/server/src/drivers/herdr/returned-prompt.js +172 -0
- package/server/src/drivers/herdr-driver.js +116 -287
- package/server/src/files/file-index.js +246 -0
- package/server/src/files/ignored.js +119 -0
- package/server/src/files/listing.js +76 -0
- package/server/src/files/path-rule.js +145 -0
- package/server/src/files/refusals.js +36 -0
- package/server/src/files/send-file.js +115 -0
- package/server/src/files/session-download.js +51 -0
- package/server/src/files/session-files.js +38 -0
- package/server/src/files/session-gate.js +48 -0
- package/server/src/git-status.js +3 -2
- package/server/src/herdr/audit.js +1 -1
- package/server/src/herdr/dialogs/hook/contract.js +16 -9
- package/server/src/herdr/dialogs/index.js +6 -1
- package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +132 -59
- package/server/src/herdr/dialogs/layer1/hook-list/session-facts.js +135 -0
- package/server/src/herdr/dialogs/layer1/version-gate.js +13 -5
- package/server/src/herdr/dialogs/no-hook.js +63 -0
- package/server/src/herdr/dialogs/screen/block.js +10 -0
- package/server/src/herdr/dialogs/screen/parse.js +10 -1
- package/server/src/herdr/jsonl-pending.js +25 -1
- package/server/src/inbox/card.js +18 -9
- package/server/src/inbox/dialogs.js +40 -12
- package/server/src/inbox/heads.js +55 -0
- package/server/src/inbox/inbox.js +24 -2
- package/server/src/inbox/index.js +3 -1
- package/server/src/index.js +22 -18
- package/server/src/install/repair.js +8 -0
- package/server/src/log-timestamps.js +9 -4
- package/server/src/router.js +7 -1
- package/server/src/routes/devices.js +2 -2
- package/server/src/routes/inbox.js +91 -0
- package/server/src/routes/sessions.js +135 -14
- package/server/src/routes/system.js +5 -4
- package/server/src/safe-read.js +86 -1
- package/server/src/sessions/companion-scope.js +6 -2
- package/server/src/sessions/demo-modules.js +16 -0
- package/server/src/sessions/diff-measure.js +30 -0
- package/server/src/sessions/manager.js +64 -152
- package/server/src/sessions/ring-buffer.js +18 -3
- package/server/src/sessions/seen-marks.js +9 -6
- package/server/src/sessions/session-scope.js +30 -0
- package/server/src/sessions/session.js +20 -1
- package/server/src/sessions/waiting-line.js +72 -0
- package/server/src/sse.js +40 -6
- package/server/src/version.js +30 -0
package/server/src/sse.js
CHANGED
|
@@ -170,6 +170,7 @@ export class SseHub {
|
|
|
170
170
|
notesFor;
|
|
171
171
|
logger;
|
|
172
172
|
onClientCount;
|
|
173
|
+
inbox;
|
|
173
174
|
gzipEnabled;
|
|
174
175
|
createGzipFn;
|
|
175
176
|
/**
|
|
@@ -194,6 +195,7 @@ export class SseHub {
|
|
|
194
195
|
this.notesFor = options.notesFor;
|
|
195
196
|
this.logger = options.logger;
|
|
196
197
|
this.onClientCount = options.onClientCount;
|
|
198
|
+
this.inbox = options.inbox;
|
|
197
199
|
this.gzipEnabled = options.gzip ?? false;
|
|
198
200
|
this.createGzipFn = options.createGzip ?? (() => createGzip());
|
|
199
201
|
this.heartbeatMs = options.heartbeatMs ?? HEARTBEAT_MS;
|
|
@@ -223,6 +225,8 @@ export class SseHub {
|
|
|
223
225
|
return;
|
|
224
226
|
this.started = true;
|
|
225
227
|
this.manager.onEvent((scope, seq, ev) => { this.broadcast(scope, seq, ev); });
|
|
228
|
+
this.manager.onTranscriptReset?.((sessionId) => { this.resetTranscript(sessionId); });
|
|
229
|
+
this.inbox?.onEvent((event) => { this.broadcastInbox(event); });
|
|
226
230
|
if (this.heartbeatMs > 0) {
|
|
227
231
|
this.heartbeat = this.setIntervalFn(() => { this.sendHeartbeat(); }, this.heartbeatMs);
|
|
228
232
|
}
|
|
@@ -290,6 +294,30 @@ export class SseHub {
|
|
|
290
294
|
if (frame !== null && ready.type === 'session-changed')
|
|
291
295
|
this.announceNewCwd(ready.session.cwd);
|
|
292
296
|
}
|
|
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
|
+
/**
|
|
309
|
+
* Sends an Inbox event to the global streams opened with `inbox=1`; an older app never asks, so it never gets one.
|
|
310
|
+
* Fleeting like `herdr-status`: no `id:`, nothing to replay, a stream that opens later gets `inbox-heads`.
|
|
311
|
+
*/
|
|
312
|
+
broadcastInbox(event) {
|
|
313
|
+
let frame = null;
|
|
314
|
+
for (const client of this.clients.values()) {
|
|
315
|
+
if (!client.inbox)
|
|
316
|
+
continue;
|
|
317
|
+
frame ??= formatSseEvent(event, null, this.serverStartId);
|
|
318
|
+
this.writeRaw(client, frame);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
293
321
|
/**
|
|
294
322
|
* Dokłada do ramki `sessions-snapshot` pole `notesCwds` i odnotowuje, o czym klient już wie.
|
|
295
323
|
*
|
|
@@ -334,9 +362,11 @@ export class SseHub {
|
|
|
334
362
|
/**
|
|
335
363
|
* Otwiera strumień globalny: `hello` + `sessions-snapshot`, potem live.
|
|
336
364
|
* `Last-Event-ID` jest tu celowo ignorowany — snapshot listy jest tani i zawsze aktualny.
|
|
365
|
+
* `inbox`: the client asked for the Inbox heads (`inbox=1`); on a server with an Inbox `inbox-heads` follows the
|
|
366
|
+
* list and the stream gets the Inbox events from then on.
|
|
337
367
|
*/
|
|
338
|
-
openGlobal(res, owner, acceptEncoding) {
|
|
339
|
-
const client = this.register('global', res, owner, acceptEncoding);
|
|
368
|
+
openGlobal(res, owner, acceptEncoding, inbox = false) {
|
|
369
|
+
const client = this.register('global', res, owner, acceptEncoding, inbox && this.inbox !== undefined);
|
|
340
370
|
this.send(client, {
|
|
341
371
|
type: 'hello',
|
|
342
372
|
protocolVersion: this.protocolVersion,
|
|
@@ -363,6 +393,10 @@ export class SseHub {
|
|
|
363
393
|
* Liczy to `withNotes`, ta sama metoda co przy ramkach z managera — patrz `broadcast`.
|
|
364
394
|
*/
|
|
365
395
|
this.send(client, this.withNotes(snapshot), null);
|
|
396
|
+
// The Inbox heads after the list (`inbox=1`), so the app knows every session a head names.
|
|
397
|
+
if (client.inbox && this.inbox !== undefined) {
|
|
398
|
+
this.send(client, { type: 'inbox-heads', heads: this.inbox.heads() }, null);
|
|
399
|
+
}
|
|
366
400
|
}
|
|
367
401
|
/**
|
|
368
402
|
* Otwiera strumień transkryptu sesji.
|
|
@@ -450,8 +484,8 @@ export class SseHub {
|
|
|
450
484
|
* Wysyła `transcript-snapshot` i oddaje ramkę — waga trafia do linii logu powtórki. `onFlushed` dostaje wagę ramki po
|
|
451
485
|
* kompresji albo `null`, gdy kompresor zamknął się przed opróżnieniem bufora; bez kompresji nie jest wołane.
|
|
452
486
|
*/
|
|
453
|
-
sendTranscriptSnapshot(client, sessionId, onFlushed) {
|
|
454
|
-
const t = this.manager.transcript(sessionId);
|
|
487
|
+
sendTranscriptSnapshot(client, sessionId, onFlushed, peek = false) {
|
|
488
|
+
const t = peek ? this.manager.transcript(sessionId, { peek: true }) : this.manager.transcript(sessionId);
|
|
455
489
|
const event = {
|
|
456
490
|
type: 'transcript-snapshot',
|
|
457
491
|
sessionId,
|
|
@@ -468,10 +502,10 @@ export class SseHub {
|
|
|
468
502
|
this.writeChecked(client, frame, onFlushed);
|
|
469
503
|
return frame;
|
|
470
504
|
}
|
|
471
|
-
register(scope, res, owner, acceptEncoding) {
|
|
505
|
+
register(scope, res, owner, acceptEncoding, inbox = false) {
|
|
472
506
|
const id = this.nextClientId++;
|
|
473
507
|
const gzip = this.gzipEnabled && acceptsGzip(acceptEncoding) ? this.createGzipFn() : undefined;
|
|
474
|
-
const client = { id, scope, res, owner, gzip, bytesOut: 0, flushedBytes: 0 };
|
|
508
|
+
const client = { id, scope, inbox, res, owner, gzip, bytesOut: 0, flushedBytes: 0 };
|
|
475
509
|
res.writeHead(200, {
|
|
476
510
|
...SSE_HEADERS,
|
|
477
511
|
// Przy włączonej kompresji odpowiedź zależy od `Accept-Encoding`; pośrednik nie ma jej podać innemu klientowi.
|
package/server/src/version.js
CHANGED
|
@@ -57,6 +57,36 @@ export const RAROG_VERSION = readPackageVersion();
|
|
|
57
57
|
export const SERVER_CAPABILITIES = [
|
|
58
58
|
'device-auth', 'pair', 'pair-from-device', 'push-relay', 'push-e2e-v2', 'companion', 'companion-sessions',
|
|
59
59
|
];
|
|
60
|
+
/**
|
|
61
|
+
* `inbox` — the server keeps an Inbox card per session: `GET /api/stream?inbox=1` adds the Inbox heads, and
|
|
62
|
+
* `GET /api/inbox`, `GET /api/inbox/:sessionId` and `POST /api/inbox/:sessionId/remove|restore` answer. A capability of
|
|
63
|
+
* the configuration, unlike the list above: absent with `RAROG_INBOX=0`, and then the app hides its Inbox.
|
|
64
|
+
*/
|
|
65
|
+
export const INBOX_CAPABILITY = 'inbox';
|
|
66
|
+
/**
|
|
67
|
+
* `files` — the session file routes answer: `GET /api/sessions/:id/files?dir=` lists a directory of the session and
|
|
68
|
+
* `GET /api/sessions/:id/files/raw?path=` sends one file of it. A capability of the configuration, like the Inbox:
|
|
69
|
+
* absent while the routes are off, and then the app builds its file tree from the changes of `git-status` alone.
|
|
70
|
+
*/
|
|
71
|
+
export const FILES_CAPABILITY = 'files';
|
|
72
|
+
/**
|
|
73
|
+
* `file-index` — `GET /api/sessions/:id/files/index` answers with the index of a session's files, which the app
|
|
74
|
+
* searches. Announced with {@link FILES_CAPABILITY} and under the same switch; an app that does not see it searches
|
|
75
|
+
* only the directories it has listed.
|
|
76
|
+
*/
|
|
77
|
+
export const FILE_INDEX_CAPABILITY = 'file-index';
|
|
78
|
+
/**
|
|
79
|
+
* The capabilities announced now: {@link SERVER_CAPABILITIES}, plus {@link INBOX_CAPABILITY} when the Inbox is on and
|
|
80
|
+
* {@link FILES_CAPABILITY} with {@link FILE_INDEX_CAPABILITY} when the session file routes answer (missing `files` =
|
|
81
|
+
* they do not).
|
|
82
|
+
*/
|
|
83
|
+
export function serverCapabilities(features) {
|
|
84
|
+
return [
|
|
85
|
+
...SERVER_CAPABILITIES,
|
|
86
|
+
...(features.inbox ? [INBOX_CAPABILITY] : []),
|
|
87
|
+
...(features.files === true ? [FILES_CAPABILITY, FILE_INDEX_CAPABILITY] : []),
|
|
88
|
+
];
|
|
89
|
+
}
|
|
60
90
|
/**
|
|
61
91
|
* System maszyny serwera dla `GET /api/version` (`system`): `darwin` → `macos`, `linux` → `linux`, każdy inny
|
|
62
92
|
* `process.platform` → `other`. Z tego pola apka bierze słowo maszyny („Mac” albo „VPS”).
|