@rarog/server 1.0.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 +18 -5
- package/node_modules/@rarog/shared/package.json +1 -1
- package/node_modules/@rarog/shared/src/decode.js +64 -3
- package/node_modules/@rarog/shared/src/protocol/files.js +33 -0
- 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/inbox.js +38 -0
- package/node_modules/@rarog/shared/src/protocol/notes.js +7 -1
- package/node_modules/@rarog/shared/src/protocol.js +20 -47
- package/node_modules/@rarog/shared/src/rest.js +106 -12
- 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 +21 -0
- package/package.json +3 -3
- package/server/src/auth/admin.js +3 -1
- package/server/src/bootstrap/consent.js +99 -2
- package/server/src/bootstrap/folder-gate.js +55 -0
- 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/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-channel.js +100 -0
- package/server/src/cli/update-provenance.js +37 -19
- 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/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 +33 -0
- package/server/src/config.js +22 -2
- package/server/src/demo/control.js +9 -1
- 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 +411 -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/screen-fallback.js +246 -0
- package/server/src/drivers/herdr-driver.js +193 -295
- package/server/src/files/file-index.js +248 -0
- package/server/src/files/ignored.js +119 -0
- package/server/src/files/listing.js +82 -0
- package/server/src/files/path-rule.js +199 -0
- package/server/src/files/refusals.js +50 -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 +53 -0
- 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 +16 -7
- package/server/src/git-watch.js +130 -19
- package/server/src/git-work-tree.js +3 -3
- package/server/src/herdr/audit.js +1 -1
- 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 +16 -9
- package/server/src/herdr/dialogs/index.js +12 -2
- package/server/src/herdr/dialogs/layer1/cycle.js +43 -7
- package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +166 -86
- package/server/src/herdr/dialogs/layer1/hook-list/session-facts.js +135 -0
- package/server/src/herdr/dialogs/layer1/screen-key.js +52 -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/router.js +21 -6
- package/server/src/herdr/dialogs/screen/block.js +10 -0
- package/server/src/herdr/dialogs/screen/parse.js +33 -3
- 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/jsonl-pending.js +25 -1
- 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/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 +44 -21
- package/server/src/install/repair.js +8 -0
- 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/log-timestamps.js +9 -4
- package/server/src/notes/store.js +3 -2
- package/server/src/router.js +20 -2
- package/server/src/routes/devices.js +2 -2
- package/server/src/routes/inbox.js +91 -0
- package/server/src/routes/projects.js +5 -1
- package/server/src/routes/sessions.js +145 -18
- package/server/src/routes/system.js +9 -4
- package/server/src/safe-read.js +86 -1
- package/server/src/sessions/companion-scope.js +16 -7
- package/server/src/sessions/demo-modules.js +16 -0
- package/server/src/sessions/diff-measure.js +30 -0
- package/server/src/sessions/done-retention.js +57 -0
- package/server/src/sessions/launch-gate.js +2 -2
- package/server/src/sessions/manager.js +78 -190
- package/server/src/sessions/project-scan.js +9 -3
- package/server/src/sessions/ring-buffer.js +5 -3
- package/server/src/sessions/seen-marks.js +9 -6
- package/server/src/sessions/session-git.js +31 -2
- package/server/src/sessions/session-scope.js +30 -0
- package/server/src/sessions/session.js +19 -0
- package/server/src/sessions/state-sentences.js +1 -1
- package/server/src/sessions/waiting-line.js +72 -0
- package/server/src/sse.js +143 -10
- 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/version.js +30 -0
|
@@ -2,6 +2,7 @@ import { MAX_FILES_PER_MESSAGE, MAX_IMAGES_PER_MESSAGE, MAX_MESSAGE_BODY_BYTES,
|
|
|
2
2
|
import { COMPANION_BUSY_ERROR, COMPANION_CLI_ERROR, COMPANION_DISABLED_ERROR, COMPANION_LIMIT_ERROR, COMPANION_SESSIONS_DISABLED_ERROR, COMPANION_TIMEOUT_ERROR, companionTurnsCountSchema, answersBodySchema, companionAskBodySchema, messageBodySchema, queueTakeBackBodySchema, restartBodySchema, seenBodySchema, } from '@rarog/shared/rest';
|
|
3
3
|
import { say } from '@rarog/shared/sentences';
|
|
4
4
|
import { redact } from '../auth/index.js';
|
|
5
|
+
import { sendDownload } from '../files/send-file.js';
|
|
5
6
|
import { conversationToken } from '../companion/conversation.js';
|
|
6
7
|
import { readSettledTurns } from '../companion/turns-settle.js';
|
|
7
8
|
import { clientLabel, diffErrorStatus, managerErrorStatus, methodNotAllowed, parseBody, readJsonBody, readValidatedBody, recheckDevice, sendError, sendFailure, sendJson, } from '../router.js';
|
|
@@ -203,11 +204,14 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
203
204
|
return true;
|
|
204
205
|
}
|
|
205
206
|
// Diff jest READ-ONLY, więc jest GET-em — i musi być obsłużony PRZED strażnikiem POST-a.
|
|
207
|
+
// Git may outlast a revocation, so the device is checked again before the answer, as on all three diff routes.
|
|
206
208
|
if (action === 'diff' && segments.length === 4) {
|
|
207
209
|
if (method !== 'GET')
|
|
208
210
|
return methodNotAllowed(res, 'GET');
|
|
209
211
|
return runManagerAction(res, log, secrets, async () => {
|
|
210
|
-
|
|
212
|
+
const diff = await manager.diff(sessionId);
|
|
213
|
+
if (recheckDevice(req, res, 'while reading the diff of'))
|
|
214
|
+
sendJson(res, 200, diff);
|
|
211
215
|
});
|
|
212
216
|
}
|
|
213
217
|
/*
|
|
@@ -222,10 +226,9 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
222
226
|
return methodNotAllowed(res, 'GET');
|
|
223
227
|
const list = segments[4] === 'files';
|
|
224
228
|
const filePath = url.searchParams.get('path') ?? '';
|
|
229
|
+
let answer;
|
|
225
230
|
try {
|
|
226
|
-
|
|
227
|
-
? await manager.diffFiles(sessionId)
|
|
228
|
-
: await manager.diffFile(sessionId, filePath));
|
|
231
|
+
answer = list ? await manager.diffFiles(sessionId) : await manager.diffFile(sessionId, filePath);
|
|
229
232
|
}
|
|
230
233
|
catch (err) {
|
|
231
234
|
const status = diffErrorStatus(err);
|
|
@@ -233,7 +236,118 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
233
236
|
log.error(`manager action failed: ${redact(err, secrets)}`);
|
|
234
237
|
if (!res.headersSent)
|
|
235
238
|
sendFailure(res, status, err, 'diff');
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
if (!recheckDevice(req, res, 'while reading the diff of'))
|
|
242
|
+
return true;
|
|
243
|
+
sendJson(res, 200, answer);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
/*
|
|
247
|
+
* GET /api/sessions/:id/files?dir=<rel> → one directory of the session (`files/session-files.ts`): the gate of the
|
|
248
|
+
* file routes, the listing, git's `ignored` labels. With `RAROG_FILES=0` the route does not exist: 404 as an
|
|
249
|
+
* unknown route for every method. An unknown session is 404 `session-not-found`, as on the diff routes, so the
|
|
250
|
+
* app does not read it as a directory gone (`not-found`). The device is checked again after the read.
|
|
251
|
+
*/
|
|
252
|
+
if (action === 'files' && segments.length === 4) {
|
|
253
|
+
if (!config.filesEnabled) {
|
|
254
|
+
sendError(res, 404, 'not-found', say('rest.endpoint-not-found'));
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
if (method !== 'GET')
|
|
258
|
+
return methodNotAllowed(res, 'GET');
|
|
259
|
+
let listing;
|
|
260
|
+
try {
|
|
261
|
+
listing = await manager.listFiles(sessionId, url.searchParams.get('dir') ?? '', config.filesMaxBytes);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
const status = diffErrorStatus(err);
|
|
265
|
+
if (status === 500)
|
|
266
|
+
log.error(`manager action failed: ${redact(err, secrets)}`);
|
|
267
|
+
if (!res.headersSent)
|
|
268
|
+
sendFailure(res, status, err, 'diff');
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
if (!recheckDevice(req, res, 'while listing the files of'))
|
|
272
|
+
return true;
|
|
273
|
+
if (listing.ok)
|
|
274
|
+
sendJson(res, 200, listing.value);
|
|
275
|
+
else
|
|
276
|
+
sendError(res, listing.refusal.status, listing.refusal.code, listing.refusal.sentence);
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
/*
|
|
280
|
+
* GET /api/sessions/:id/files/index → the paths of the session's files (`files/file-index.ts`): the gate of the
|
|
281
|
+
* file routes, then a walk of the session directory by the rule of the listing, narrowed by git. Off with
|
|
282
|
+
* `RAROG_FILES=0` like the listing. Requests during a walk of the same directory get its answer; the device is
|
|
283
|
+
* checked again after it, per request.
|
|
284
|
+
*/
|
|
285
|
+
if (action === 'files' && segments.length === 5 && segments[4] === 'index') {
|
|
286
|
+
if (!config.filesEnabled) {
|
|
287
|
+
sendError(res, 404, 'not-found', say('rest.endpoint-not-found'));
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
if (method !== 'GET')
|
|
291
|
+
return methodNotAllowed(res, 'GET');
|
|
292
|
+
let index;
|
|
293
|
+
try {
|
|
294
|
+
index = await ctx.fileIndex.index(sessionId, config.filesMaxBytes, manager.filesPort());
|
|
295
|
+
}
|
|
296
|
+
catch (err) {
|
|
297
|
+
const status = diffErrorStatus(err);
|
|
298
|
+
if (status === 500)
|
|
299
|
+
log.error(`manager action failed: ${redact(err, secrets)}`);
|
|
300
|
+
if (!res.headersSent)
|
|
301
|
+
sendFailure(res, status, err, 'diff');
|
|
302
|
+
return true;
|
|
236
303
|
}
|
|
304
|
+
if (!recheckDevice(req, res, 'while indexing the files of'))
|
|
305
|
+
return true;
|
|
306
|
+
if (index.ok)
|
|
307
|
+
sendJson(res, 200, index.value);
|
|
308
|
+
else
|
|
309
|
+
sendError(res, index.refusal.status, index.refusal.code, index.refusal.sentence);
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
/*
|
|
313
|
+
* GET /api/sessions/:id/files/raw?path=<rel> → the bytes of one file of the session: the gate and the path rule
|
|
314
|
+
* of the listing and the limit before any byte (`files/session-download.ts`, 413 with `size` and `maxBytes`), then
|
|
315
|
+
* exactly `Content-Length` bytes from one descriptor (`files/send-file.ts`). Off with `RAROG_FILES=0` like the
|
|
316
|
+
* listing. The device is checked again after the open and the download is registered under it with no `await` in
|
|
317
|
+
* between, so a device unpaired from then on cuts the response; every exit after the open closes the file.
|
|
318
|
+
*/
|
|
319
|
+
if (action === 'files' && segments.length === 5 && segments[4] === 'raw') {
|
|
320
|
+
if (!config.filesEnabled) {
|
|
321
|
+
sendError(res, 404, 'not-found', say('rest.endpoint-not-found'));
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
if (method !== 'GET')
|
|
325
|
+
return methodNotAllowed(res, 'GET');
|
|
326
|
+
let answer;
|
|
327
|
+
try {
|
|
328
|
+
answer = await manager.openFile(sessionId, url.searchParams.get('path') ?? '', config.filesMaxBytes);
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
const status = diffErrorStatus(err);
|
|
332
|
+
if (status === 500)
|
|
333
|
+
log.error(`manager action failed: ${redact(err, secrets)}`);
|
|
334
|
+
if (!res.headersSent)
|
|
335
|
+
sendFailure(res, status, err, 'diff');
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
if (!recheckDevice(req, res, 'while opening a file of')) {
|
|
339
|
+
if (answer.ok)
|
|
340
|
+
await answer.value.close().catch(() => { });
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
if (!answer.ok) {
|
|
344
|
+
const { refusal } = answer;
|
|
345
|
+
sendError(res, refusal.status, refusal.code, refusal.sentence, 'extra' in refusal ? refusal.extra : undefined);
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
await sendDownload(res, answer.value, {
|
|
349
|
+
owner, downloads: ctx.fileDownloads, log: (line) => { log.info(`${line} (session ${sessionId})`); },
|
|
350
|
+
});
|
|
237
351
|
return true;
|
|
238
352
|
}
|
|
239
353
|
/*
|
|
@@ -250,14 +364,15 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
250
364
|
}, 'message');
|
|
251
365
|
}
|
|
252
366
|
/*
|
|
253
|
-
* GET /api/sessions/:id/companion/turns?count=1..3 → {messages, conversation, stateSince, complete}
|
|
367
|
+
* GET /api/sessions/:id/companion/turns?count=1..3 → {messages, conversation, stateSince, readMark, complete}
|
|
254
368
|
* (`docs/companion.md`, "Turns route"): the last turns of the engine conversation the session writes now, for the
|
|
255
369
|
* voice agent across sessions. Demo mode has no route (404 as unknown). The gate, in order: the voice agent (503
|
|
256
370
|
* `companion-disabled`), the mode across sessions (503 `companion-sessions-disabled`), `count` (400), a Claude Code
|
|
257
|
-
* session in scope (404). The conversation
|
|
258
|
-
* it (`companion/turns-settle.ts`): another conversation by then is read
|
|
259
|
-
* response closes without a body; a session gone or out of scope by then gets
|
|
260
|
-
* checked again before the answer, so a device unpaired during the read gets 401 and
|
|
371
|
+
* session in scope (404). The conversation, `stateSince` and the read mark of the session's memory are taken
|
|
372
|
+
* together before each read and again after it (`companion/turns-settle.ts`): another conversation by then is read
|
|
373
|
+
* again, at most three reads, then the response closes without a body; a session gone or out of scope by then gets
|
|
374
|
+
* the gate's 404. The device is checked again before the answer, so a device unpaired during the read gets 401 and
|
|
375
|
+
* no turns.
|
|
261
376
|
*/
|
|
262
377
|
if (action === 'companion' && segments.length === 5 && segments[4] === 'turns') {
|
|
263
378
|
if (config.demo) {
|
|
@@ -299,7 +414,9 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
299
414
|
return { refused: () => { sendError(res, 404, 'not-found', say('rest.companion-claude-only')); } };
|
|
300
415
|
}
|
|
301
416
|
const stateSince = manager.get(sessionId)?.stateSince ?? '';
|
|
302
|
-
return {
|
|
417
|
+
return {
|
|
418
|
+
target: { cwd: target.cwd, agentSessionId: target.agentSessionId, stateSince, readMark: target.readMark },
|
|
419
|
+
};
|
|
303
420
|
};
|
|
304
421
|
await readSettledTurns(ctx.companionTurns, take, count.data, (outcome) => {
|
|
305
422
|
if (!recheckDevice(req, res, 'while reading voice agent turns for'))
|
|
@@ -440,6 +557,11 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
440
557
|
* dalej wracają jako 400/409 z `runManagerAction` — mimo `async` tutaj.
|
|
441
558
|
*/
|
|
442
559
|
const delivered = await waitForDelivery(manager.interrupt(sessionId), interruptWaitMs);
|
|
560
|
+
/*
|
|
561
|
+
* Only a key that went can have handed the prompt back to Claude Code's field, so a `no` or `pending` answer
|
|
562
|
+
* waits for no field read. The read after a delivered key is bounded in the driver (`returned-prompt.ts`).
|
|
563
|
+
*/
|
|
564
|
+
const returnedPrompt = delivered === 'yes' ? await manager.returnedPrompt(sessionId) : null;
|
|
443
565
|
/*
|
|
444
566
|
* Odpowiedź niesie ŚWIEŻE `SessionSummary`, żeby widok po Esc nie czekał długo na stan.
|
|
445
567
|
*
|
|
@@ -452,9 +574,12 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
452
574
|
* `activity` jest ulotna (`seq === null`), więc replay po reconnekcie jej nie powtórzy.
|
|
453
575
|
*
|
|
454
576
|
* `ok: true` zostaje dla zgodności ze starszym klientem, który czyta sam status;
|
|
455
|
-
* `delivered` jest polem ADDYTYWNYM i taki klient je zignoruje.
|
|
577
|
+
* `delivered` jest polem ADDYTYWNYM i taki klient je zignoruje. `returnedPrompt` is additive as well and stands
|
|
578
|
+
* only when the field proved the hand-back.
|
|
456
579
|
*/
|
|
457
|
-
sendJson(res, 202, {
|
|
580
|
+
sendJson(res, 202, {
|
|
581
|
+
ok: true, session: manager.get(sessionId), delivered, ...(returnedPrompt === null ? {} : { returnedPrompt }),
|
|
582
|
+
});
|
|
458
583
|
});
|
|
459
584
|
}
|
|
460
585
|
/*
|
|
@@ -524,12 +649,14 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
524
649
|
* obsłużonej z telefonu. Dalej 200 i dalej natychmiastowe: fokus leci w TLE, a jego
|
|
525
650
|
* niepowodzenie nie jest błędem tego wywołania (znacznik lokalny stoi tak czy inaczej).
|
|
526
651
|
*
|
|
527
|
-
* The voice agent's pick-up (`docs/companion.md`, "Picking up a result"): the body `{by,
|
|
652
|
+
* The voice agent's pick-up (`docs/companion.md`, "Picking up a result"): the body `{by, conversation, readMark}`
|
|
528
653
|
* (all three or none, else the 400 of the schema) meets the gate of the mode's other routes (503), then the
|
|
529
654
|
* catalogue's scope (the 404 of the turns route), and the manager refuses with a 409 anything but the result the
|
|
530
|
-
* agent read (`markSeen` in `seen-marks.ts`: `waiting-input` with no decision card, the
|
|
531
|
-
*
|
|
532
|
-
*
|
|
655
|
+
* agent read (`markSeen` in `seen-marks.ts`: `waiting-input` with no decision card, the conversation of the token,
|
|
656
|
+
* the turns read's `readMark`: no newer message in the session's memory and the same `stateSince`), all with no
|
|
657
|
+
* `await` after the body.
|
|
658
|
+
* The token becomes a check of a conversation id as for a send. A body without `by` is a person's receipt with any
|
|
659
|
+
* flags.
|
|
533
660
|
*/
|
|
534
661
|
if (action === 'seen' && segments.length === 4) {
|
|
535
662
|
const body = await readValidatedBody(req, res, config, seenBodySchema);
|
|
@@ -537,10 +664,10 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
537
664
|
return true;
|
|
538
665
|
const token = deps.conversationToken ?? conversationToken;
|
|
539
666
|
const read = body.conversation;
|
|
540
|
-
const pickUp = body.by === undefined || body.
|
|
667
|
+
const pickUp = body.by === undefined || body.readMark === undefined || read === undefined
|
|
541
668
|
? undefined
|
|
542
669
|
: {
|
|
543
|
-
by: body.by,
|
|
670
|
+
by: body.by, readMark: body.readMark,
|
|
544
671
|
conversation: (agentSessionId) => token(agentSessionId) === read,
|
|
545
672
|
};
|
|
546
673
|
if (pickUp !== undefined && (!config.companionEnabled || deps.companion === undefined)) {
|
|
@@ -8,7 +8,7 @@ import { companionCatalog } from '../companion/catalog.js';
|
|
|
8
8
|
import { conversationToken } from '../companion/conversation.js';
|
|
9
9
|
import { HEALTH_ALIVE, fullHealthAllowed, healthPayload, readHookHealth } from '../health.js';
|
|
10
10
|
import { clientLabel, methodNotAllowed, readValidatedBody, recheckDevice, sendError, sendJson, } from '../router.js';
|
|
11
|
-
import {
|
|
11
|
+
import { serverCapabilities } from '../version.js';
|
|
12
12
|
/**
|
|
13
13
|
* Ciało `POST /api/voice/token`: puste i takie ma zostać.
|
|
14
14
|
*
|
|
@@ -98,9 +98,9 @@ export async function routeSystem(ctx, req, res, rq) {
|
|
|
98
98
|
apnsEnabled: apns !== undefined,
|
|
99
99
|
/*
|
|
100
100
|
* Możliwości po nazwie (`version.ts`) — apka sprawdza, czy serwer umie to, czego ona
|
|
101
|
-
* potrzebuje, zamiast porównywać numery wersji.
|
|
101
|
+
* potrzebuje, zamiast porównywać numery wersji. `inbox` only while the server keeps an Inbox.
|
|
102
102
|
*/
|
|
103
|
-
capabilities:
|
|
103
|
+
capabilities: serverCapabilities({ inbox: deps.inbox !== undefined, files: config.filesEnabled }),
|
|
104
104
|
/*
|
|
105
105
|
* System maszyny serwera (`serverSystem` w `version.ts`): apka bierze z niego słowo maszyny, „Mac” albo
|
|
106
106
|
* „VPS”. Pole jest zawsze; klient czyta brak (serwer sprzed pola) jako „nie wiem”.
|
|
@@ -120,6 +120,8 @@ export async function routeSystem(ctx, req, res, rq) {
|
|
|
120
120
|
* Endpoint nie przyjmuje żadnych parametrów i nigdy ich nie przyjmie: wszystko, co
|
|
121
121
|
* konfiguruje strumień (region, model, format, limity), jest decyzją serwera. Ciało
|
|
122
122
|
* czytamy wyłącznie po to, żeby domknąć żądanie i utrzymać limit 64 kB.
|
|
123
|
+
* After the key arrives the device is checked again: a device revoked meanwhile gets 401 and the key is dropped (it
|
|
124
|
+
* expires on its own).
|
|
123
125
|
*/
|
|
124
126
|
if (pathname === '/api/voice/token') {
|
|
125
127
|
if (method !== 'POST')
|
|
@@ -132,6 +134,8 @@ export async function routeSystem(ctx, req, res, rq) {
|
|
|
132
134
|
sendError(res, result.status, result.error, result.sentence);
|
|
133
135
|
return true;
|
|
134
136
|
}
|
|
137
|
+
if (!recheckDevice(req, res, 'while minting a dictation key for'))
|
|
138
|
+
return true;
|
|
135
139
|
// `sendJson` ustawia `Cache-Control: no-store` na KAŻDEJ odpowiedzi API — dla tej
|
|
136
140
|
// jednej to nie jest higiena, tylko wymóg: w ciele jedzie klucz.
|
|
137
141
|
sendJson(res, 200, result.token);
|
|
@@ -267,7 +271,8 @@ export async function routeSystem(ctx, req, res, rq) {
|
|
|
267
271
|
if (method !== 'GET')
|
|
268
272
|
return methodNotAllowed(res, 'GET');
|
|
269
273
|
// `Accept-Encoding` decyduje o kompresji strumienia (`RAROG_SSE_GZIP`).
|
|
270
|
-
|
|
274
|
+
// `inbox=1`: an app that shows the Inbox asks for its heads (`docs/implementation-spec.md`, "Inbox").
|
|
275
|
+
hub.openGlobal(res, owner, req.headers['accept-encoding'], rq.url.searchParams.get('inbox') === '1');
|
|
271
276
|
return true;
|
|
272
277
|
}
|
|
273
278
|
return false;
|
package/server/src/safe-read.js
CHANGED
|
@@ -18,9 +18,16 @@
|
|
|
18
18
|
* wołający ma już własną obsługę „nie da się przeczytać”, a `ensureGitExclude` odróżnia po `ENOENT` brak pliku
|
|
19
19
|
* od pliku, którego nie wolno ruszyć. Pilnuje tego strażnik `server/test/pliki-zwykle-guard.test.ts`: odczyt
|
|
20
20
|
* z `node:fs` poza tym modułem stoi na jego liście wyjątków z powodem.
|
|
21
|
+
*
|
|
22
|
+
* A file sent on in pieces opens with {@link openRegularFile} (the `openRead` of the work-area port) and is read with
|
|
23
|
+
* {@link exactReader} through the port's handle: exactly the bytes of its `fstat`, from that one descriptor.
|
|
24
|
+
*
|
|
25
|
+
* Besides regular files, one directory read lives here, because on Linux it opens the directory:
|
|
26
|
+
* {@link readDirectoryByIdentity} lists a directory through its `dev` and `ino` rather than its path. On Linux that
|
|
27
|
+
* binds the read to the checked directory; on macOS it narrows the window of a swap but does not close it.
|
|
21
28
|
*/
|
|
22
29
|
import { closeSync, constants, fstatSync, openSync, readSync } from 'node:fs';
|
|
23
|
-
import { open } from 'node:fs/promises';
|
|
30
|
+
import { open, readdir } from 'node:fs/promises';
|
|
24
31
|
/** Pierwszy odczyt bierze rozmiar z `fstat` (+1, żeby od razu zobaczyć koniec); plik rosnący dostaje więcej. */
|
|
25
32
|
const GROW_FACTOR = 2;
|
|
26
33
|
function openFlags(followSymlink) {
|
|
@@ -92,6 +99,84 @@ export async function readRegularFile(path, opts) {
|
|
|
92
99
|
await handle.close();
|
|
93
100
|
}
|
|
94
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* The open of {@link readRegularFile} without the read, for a caller that sends the file on in pieces: the same
|
|
104
|
+
* flags and the `fstat` on the descriptor; not a regular file → the handle is closed and the result is `null`. The
|
|
105
|
+
* caller closes the handle. Throws on an error of the open, like the readers.
|
|
106
|
+
*/
|
|
107
|
+
export async function openRegularFile(path, opts) {
|
|
108
|
+
const handle = await open(path, openFlags(opts.followSymlink));
|
|
109
|
+
try {
|
|
110
|
+
const stats = await handle.stat({ bigint: true });
|
|
111
|
+
if (stats.isFile())
|
|
112
|
+
return { handle, stats };
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
await handle.close();
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
await handle.close();
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
/** Bytes per piece of {@link exactReader} by default. */
|
|
122
|
+
export const EXACT_PIECE_BYTES = 64 * 1024;
|
|
123
|
+
/**
|
|
124
|
+
* Reads the first `size` bytes of an open file (the `fstat` size taken at its open), one piece of at most
|
|
125
|
+
* `pieceBytes` per call, each at its own offset: the position of the descriptor does not matter, and bytes appended
|
|
126
|
+
* past `size` are never read. `short`: the file ended before `size` bytes, so it was cut since its `fstat` and what
|
|
127
|
+
* was read is not the file. The reader is the handle of the work-area port, so a file in a guarded folder is read in
|
|
128
|
+
* that folder's helper; this function touches no disk itself. The caller calls it one step at a time, owns the handle
|
|
129
|
+
* and closes it; an error of the read rejects.
|
|
130
|
+
*/
|
|
131
|
+
export function exactReader(handle, size, pieceBytes = EXACT_PIECE_BYTES) {
|
|
132
|
+
let position = 0;
|
|
133
|
+
return async () => {
|
|
134
|
+
if (position >= size)
|
|
135
|
+
return { kind: 'done' };
|
|
136
|
+
const bytes = await handle.read(Math.min(pieceBytes, size - position), position);
|
|
137
|
+
if (bytes.length === 0)
|
|
138
|
+
return { kind: 'short', read: position };
|
|
139
|
+
position += bytes.length;
|
|
140
|
+
return { kind: 'piece', bytes };
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const DIRECTORY_FLAGS = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW | constants.O_NONBLOCK;
|
|
144
|
+
const entriesOf = (dir) => readdir(dir, { withFileTypes: true, encoding: 'buffer' });
|
|
145
|
+
export const DIRECTORY_IO = {
|
|
146
|
+
platform: process.platform,
|
|
147
|
+
openDirectory: (dir) => open(dir, DIRECTORY_FLAGS),
|
|
148
|
+
readOpen: (fd) => entriesOf(`/proc/self/fd/${String(fd)}`),
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Entries of the directory `dir` whose `stat` gave `identity`, names as bytes, read through that identity instead of
|
|
152
|
+
* the path:
|
|
153
|
+
* - macOS: `/.vol/<dev>/<ino>`. The kernel turns the inode back into its current path and looks that path up within
|
|
154
|
+
* the one call (a parent without search permission refuses it), so a swap made before the call does not redirect
|
|
155
|
+
* it. A swap that lands inside the call still can: Node has no descriptor-based directory read on macOS, so this
|
|
156
|
+
* narrows the race and the caller's checks after the read narrow it further, but neither closes it.
|
|
157
|
+
* - Linux: the directory opened with `O_DIRECTORY | O_NOFOLLOW`, its `fstat` must carry `identity`, and the entries
|
|
158
|
+
* come through `/proc/self/fd/<fd>`, that is from the open descriptor. The descriptor is closed on every path.
|
|
159
|
+
*
|
|
160
|
+
* `null`: another platform, or another directory stands under `dir` now. Throws on an error of the open or the read,
|
|
161
|
+
* as `readdir` does (`EACCES` for a directory the server may not read, `ENOENT` for one removed).
|
|
162
|
+
*/
|
|
163
|
+
export async function readDirectoryByIdentity(dir, identity, io = {}) {
|
|
164
|
+
const { platform, openDirectory, readOpen } = { ...DIRECTORY_IO, ...io };
|
|
165
|
+
if (platform === 'darwin')
|
|
166
|
+
return entriesOf(`/.vol/${String(identity.dev)}/${String(identity.ino)}`);
|
|
167
|
+
if (platform !== 'linux')
|
|
168
|
+
return null;
|
|
169
|
+
const handle = await openDirectory(dir);
|
|
170
|
+
try {
|
|
171
|
+
const info = await handle.stat({ bigint: true });
|
|
172
|
+
if (!info.isDirectory() || info.dev !== identity.dev || info.ino !== identity.ino)
|
|
173
|
+
return null;
|
|
174
|
+
return await readOpen(handle.fd);
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
await handle.close();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
95
180
|
/**
|
|
96
181
|
* Dopisuje `text` na koniec pliku zwykłego, tworząc go, gdy go nie ma (prawa `0644` przed umaskiem).
|
|
97
182
|
*
|
|
@@ -15,10 +15,10 @@ import { BadStateError } from './errors.js';
|
|
|
15
15
|
* root), as for the diff, because the list carries the names and descriptions of skills from `.claude/` of that
|
|
16
16
|
* directory. A card without a pane is in scope with its directory; demo mode reads the registry only.
|
|
17
17
|
*/
|
|
18
|
-
export function inCommandScope(session, config) {
|
|
18
|
+
export function inCommandScope(session, config, options = {}) {
|
|
19
19
|
if (session.engine === 'codex' || session.outOfScope === true)
|
|
20
20
|
return false;
|
|
21
|
-
return config.demo || sessionCwdInArea(session, config);
|
|
21
|
+
return config.demo || sessionCwdInArea(session, config, options);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Whether the directory a read of this session will use lies in the work area of `RAROG_HERDR_ROOTS`. A pane
|
|
@@ -27,9 +27,9 @@ export function inCommandScope(session, config) {
|
|
|
27
27
|
* as written and on disk ({@link inWorkAreaOnDisk}): a link into a protected folder of home, or a root that is a
|
|
28
28
|
* symlink to home, does not open that folder to a read.
|
|
29
29
|
*/
|
|
30
|
-
export function sessionCwdInArea(session, config) {
|
|
30
|
+
export function sessionCwdInArea(session, config, options = {}) {
|
|
31
31
|
return session.herdrKey === undefined
|
|
32
|
-
|| inWorkAreaOnDisk(session.cwd, config.herdrRoots ?? [], config.home ?? homedir());
|
|
32
|
+
|| inWorkAreaOnDisk(session.cwd, config.herdrRoots ?? [], config.home ?? homedir(), undefined, options);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Session the voice agent may ask about: its directory and the engine conversation it writes now (`init` of the
|
|
@@ -37,16 +37,25 @@ export function sessionCwdInArea(session, config) {
|
|
|
37
37
|
* own sentence instead of the 400 of the commands list.
|
|
38
38
|
*/
|
|
39
39
|
export function companionTargetOf(session, config) {
|
|
40
|
-
|
|
40
|
+
// The target names a transcript in the engine's store outside the session directory, so a macOS folder the gate
|
|
41
|
+
// holds closed does not take the session from the Inbox or the voice agent; the commands list and the diff,
|
|
42
|
+
// which read the directory itself, keep the gate.
|
|
43
|
+
return inCommandScope(session, config, { gate: 'ignore' })
|
|
44
|
+
? { cwd: session.cwd, agentSessionId: session.engineSessionId }
|
|
45
|
+
: null;
|
|
41
46
|
}
|
|
42
47
|
/**
|
|
43
48
|
* {@link companionTargetOf} with the newest message of the session's transcript in memory, for the voice agent's
|
|
44
49
|
* session catalog, only when that message belongs to the engine conversation the session writes now
|
|
45
|
-
* (`Session.lastMessageOfConversation`)
|
|
50
|
+
* (`Session.lastMessageOfConversation`), and the read mark of that memory (`Session.readMark`), which the turns route
|
|
51
|
+
* takes with the conversation before it reads the file. It reads the session only: no file, no mark of a card or a
|
|
52
|
+
* message as shown.
|
|
46
53
|
*/
|
|
47
54
|
export function companionEntryOf(session, config) {
|
|
48
55
|
const target = companionTargetOf(session, config);
|
|
49
|
-
return target === null
|
|
56
|
+
return target === null
|
|
57
|
+
? null
|
|
58
|
+
: { ...target, lastMessage: session.lastMessageOfConversation(), readMark: session.readMark };
|
|
50
59
|
}
|
|
51
60
|
/**
|
|
52
61
|
* Whether the session is in the engine conversation a client read: the conversation the session writes (`init` of
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Dynamiczny import scenariuszy demo — wołany WYŁĄCZNIE przy `config.demo`; treść z podanego zestawu. */
|
|
2
|
+
export async function loadDemoModules(content) {
|
|
3
|
+
const seeds = await import('../demo/seeds.js');
|
|
4
|
+
const files = await import('../demo/files.js');
|
|
5
|
+
return {
|
|
6
|
+
demoSeeds: (now) => seeds.demoSeeds(content, now),
|
|
7
|
+
demoBlocks: seeds.demoBlocks,
|
|
8
|
+
demoProjects: () => seeds.demoProjects(content),
|
|
9
|
+
demoResumable: (cwd, now) => seeds.demoResumable(content, cwd, now),
|
|
10
|
+
demoDiff: () => seeds.demoDiff(content),
|
|
11
|
+
demoDiffFiles: seeds.demoDiffFiles,
|
|
12
|
+
demoDiffFile: (path) => seeds.demoDiffFile(content, path),
|
|
13
|
+
demoFileEntries: files.demoFileEntries,
|
|
14
|
+
demoFileBytes: files.demoFileBytes,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The log line of a diff read: `git: diff list|file <ms> ms`, with the contract code of a refusal. One function over
|
|
3
|
+
* the manager's clock and logger; it reads nothing and holds no state. The manager re-exports the phrases, so
|
|
4
|
+
* importers keep their path. This module does not import `manager.ts`.
|
|
5
|
+
*/
|
|
6
|
+
import { DiffError } from '../git-diff.js';
|
|
7
|
+
/** Fraza linii kosztu listy plików gita czytanej od nowa: `git: diff list <ms> ms`. */
|
|
8
|
+
export const GIT_DIFF_LIST_LOG = 'git: diff list';
|
|
9
|
+
/** Fraza linii kosztu patcha jednego pliku: `git: diff file <ms> ms`. */
|
|
10
|
+
export const GIT_DIFF_FILE_LOG = 'git: diff file';
|
|
11
|
+
/**
|
|
12
|
+
* Linia `git: diff list|file <ms>` w logu: koszt list gita czytanych od nowa przy każdym
|
|
13
|
+
* żądaniu, czyli liczba, po której zapadnie decyzja o pamięci podręcznej. Niesie czas i — przy
|
|
14
|
+
* odmowie — kod z kontraktu; NIGDY ścieżki ani nazwy pliku.
|
|
15
|
+
*/
|
|
16
|
+
export async function measureDiff(phrase, clock, read) {
|
|
17
|
+
const startedAt = clock.now();
|
|
18
|
+
const line = (suffix) => {
|
|
19
|
+
clock.log(`${phrase} ${String(clock.now() - startedAt)} ms${suffix}`);
|
|
20
|
+
};
|
|
21
|
+
try {
|
|
22
|
+
const result = await read();
|
|
23
|
+
line('');
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
line(` (${error instanceof DiffError ? error.code : 'error'})`);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Closed cards the server keeps for resuming; each holds up to two transcript budgets (`ring-buffer.ts`). */
|
|
2
|
+
export const DONE_CARDS_MAX = 100;
|
|
3
|
+
/** `true` when the pane index (`HerdrAgent.key` → card id) still points at this card: its pane is alive. */
|
|
4
|
+
export function ownsPaneKey(herdrByKey, card) {
|
|
5
|
+
return card.herdrKey !== undefined && herdrByKey.get(card.herdrKey) === card.id;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Closed cards over the cap, the oldest `lastActivityAt` first. A card with a driver or a live pane and a card whose
|
|
9
|
+
* restart is in progress neither counts nor goes; a `resumable` card is not closed.
|
|
10
|
+
*/
|
|
11
|
+
export function doneCardsOver(sessions, herdrByKey, restarts, max = DONE_CARDS_MAX) {
|
|
12
|
+
const closed = [...sessions.values()].filter((card) => card.state === 'done' && card.driver === null
|
|
13
|
+
&& !ownsPaneKey(herdrByKey, card) && !restarts.has(card.id));
|
|
14
|
+
if (closed.length <= max)
|
|
15
|
+
return [];
|
|
16
|
+
closed.sort((a, b) => Date.parse(a.lastActivityAt) - Date.parse(b.lastActivityAt));
|
|
17
|
+
return closed.slice(0, closed.length - max);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The card was forgotten while its conversation has no live process and no other card: the consent cycle may drop
|
|
21
|
+
* the conversation's entries (`forgotten`). Called after the card left `sessions`.
|
|
22
|
+
*/
|
|
23
|
+
export function forgetConversation(card, sessions, forgotten) {
|
|
24
|
+
const engine = card.engineSessionId;
|
|
25
|
+
if (forgotten === undefined || engine === undefined || engine === '')
|
|
26
|
+
return;
|
|
27
|
+
for (const other of sessions.values())
|
|
28
|
+
if (other.engineSessionId === engine)
|
|
29
|
+
return;
|
|
30
|
+
forgotten(engine);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Zapamiętuje, w których indeksach stoi ta karta, i oddaje funkcję COFAJĄCĄ `#forget…`.
|
|
34
|
+
*
|
|
35
|
+
* Odtwarzamy dokładnie to, co było — a nie „co powinno być": `#indexEngineSession` pomija
|
|
36
|
+
* sesje `done`, więc bezwarunkowe wołanie go po rollbacku dokładałoby wpis, którego przed
|
|
37
|
+
* kasowaniem nie było. Jedyne, czego nie wskrzeszamy, to czekający z `AttachSlots`: to obietnice
|
|
38
|
+
* czekających na podpięcie drivera, a po nieudanym wznowieniu nie ma do czego ich podpiąć.
|
|
39
|
+
* Nowa karta pod tym samym id (gdyby `create()` zdążył ją wstawić) ma pierwszeństwo.
|
|
40
|
+
*/
|
|
41
|
+
export function snapshotIndexes(port, session) {
|
|
42
|
+
const key = session.herdrKey;
|
|
43
|
+
const engineSessionId = session.engineSessionId;
|
|
44
|
+
const hadKey = ownsPaneKey(port.herdrByKey, session);
|
|
45
|
+
const hadEngine = engineSessionId !== undefined
|
|
46
|
+
&& port.byEngineSession.get(engineSessionId) === session.id;
|
|
47
|
+
return () => {
|
|
48
|
+
if (port.sessions.has(session.id))
|
|
49
|
+
return;
|
|
50
|
+
port.sessions.set(session.id, session);
|
|
51
|
+
port.watch(session);
|
|
52
|
+
if (hadKey && key !== undefined)
|
|
53
|
+
port.herdrByKey.set(key, session.id);
|
|
54
|
+
if (hadEngine && engineSessionId !== undefined)
|
|
55
|
+
port.byEngineSession.set(engineSessionId, session.id);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -37,8 +37,8 @@ export class LaunchGate {
|
|
|
37
37
|
/*
|
|
38
38
|
* Sufit paneli sprawdzamy PRZED `canLaunch`, choć logicznie jest węższy.
|
|
39
39
|
*
|
|
40
|
-
* Powód jest czysto ludzki:
|
|
41
|
-
*
|
|
40
|
+
* Powód jest czysto ludzki: the supervisor turns `canLaunch` off for several reasons (killswitches,
|
|
41
|
+
* unavailable herdr, reached cap), a komunikat może być tylko jeden. Przy odwrotnej
|
|
42
42
|
* kolejności siódmy panel dostawał odpowiedź „zakładanie wyłączone” z nazwą killswitcha zakładania
|
|
43
43
|
* — zdanie nieprawdziwe i prowadzące donikąd, zamiast „zamknij któryś panel".
|
|
44
44
|
*/
|