@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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { logToken } from './no-hook.js';
|
|
2
|
+
/**
|
|
3
|
+
* Why the button is not there, in the order the rule checks: the first that holds names the refusal. The rule's own
|
|
4
|
+
* guards come first; `registry`, `screen`, `channel-card` and `always` only come from the checks at the key.
|
|
5
|
+
*/
|
|
6
|
+
export const SCREEN_FALLBACK_GUARDS = [
|
|
7
|
+
'mode', 'class', 'card', 'thread', 'judgement', 'trace', 'hook', 'hook-running', 'ps', 'hook-list', 'restart',
|
|
8
|
+
'registry', 'screen', 'channel-card', 'always',
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* The first guard that refuses the button, or `null` when the card may carry it. Only channel mode and the
|
|
12
|
+
* `permission` class; a card the `off` path would give the button; a title that says the thread, and a subagent's
|
|
13
|
+
* dialog only in `all` (the card cannot tell it from an identical call of the main thread); an episode judged without
|
|
14
|
+
* a trace and nothing in the way now; no hook process in `ps`, and for a subagent `ps` must answer; no foreign hook in
|
|
15
|
+
* the current settings (a settings change after the session start alone does not refuse); outside the restart grace.
|
|
16
|
+
*/
|
|
17
|
+
export function screenFallbackGuard(facts) {
|
|
18
|
+
if (facts.mode !== 'main' && facts.mode !== 'all')
|
|
19
|
+
return 'mode';
|
|
20
|
+
if (facts.cliDialog !== 'permission')
|
|
21
|
+
return 'class';
|
|
22
|
+
if (!facts.card)
|
|
23
|
+
return 'card';
|
|
24
|
+
if (facts.thread === null || (facts.thread === 'subagent' && facts.mode !== 'all'))
|
|
25
|
+
return 'thread';
|
|
26
|
+
if (!facts.judged)
|
|
27
|
+
return 'judgement';
|
|
28
|
+
if (facts.trace !== false)
|
|
29
|
+
return 'trace';
|
|
30
|
+
if (facts.hookWaits)
|
|
31
|
+
return 'hook';
|
|
32
|
+
if (facts.hookRunning === true)
|
|
33
|
+
return 'hook-running';
|
|
34
|
+
if (facts.hookRunning === null && facts.thread === 'subagent')
|
|
35
|
+
return 'ps';
|
|
36
|
+
if (facts.foreignHook !== false)
|
|
37
|
+
return 'hook-list';
|
|
38
|
+
if (facts.restarting)
|
|
39
|
+
return 'restart';
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/** Whether the mark still lets the card's "Yes" digit through under the live mode and registry class. */
|
|
43
|
+
export function screenFallbackHolds(mark, mode, cliDialog) {
|
|
44
|
+
return screenFallbackGuard({ ...mark.facts, mode, cliDialog }) === null;
|
|
45
|
+
}
|
|
46
|
+
/** `consent: screen fallback key — …`, at every digit the emergency button sent. */
|
|
47
|
+
export function screenFallbackKeyLine(line) {
|
|
48
|
+
return `consent: screen fallback key — session ${logToken(line.sessionId)}, tool ${logToken(line.tool)}, `
|
|
49
|
+
+ `cause ${line.cause}, card ${logToken(line.card)}, tool_use ${logToken(line.toolUseId)}`;
|
|
50
|
+
}
|
|
51
|
+
/** `consent: screen fallback refused — …`, at every tap of the button that sent no key. */
|
|
52
|
+
export function screenFallbackRefusedLine(line) {
|
|
53
|
+
return `consent: screen fallback refused — session ${logToken(line.sessionId)}, tool ${logToken(line.tool)}, `
|
|
54
|
+
+ `guard ${line.guard}, card ${logToken(line.card)}`;
|
|
55
|
+
}
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
* (`HookMarkerFile`). Przy `shadow` i `off` pola nie ma, więc plik
|
|
18
18
|
* trybu cienia jest bit w bit ten sam co bez opcji. Dziennik przejść pola nie niesie.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* A new session does not wait for the tick: {@link AliveWriter.sessionsChanged} writes at once when the current list
|
|
21
|
+
* has a session the last successful write did not carry. A hook whose session is not on the list leaves without the
|
|
22
|
+
* consent channel, so the tick would send the first request of a new session (or of the first sessions after a
|
|
23
|
+
* restart) to the terminal. A session that only left waits for the tick.
|
|
23
24
|
*
|
|
24
25
|
* Restart break: with a restart grace G above 0 ({@link AliveWriterOptions.graceMs}) every write carries
|
|
25
26
|
* `phase: "starting"` from the first one until the first one with a session after the channel mode is resolved
|
|
@@ -77,8 +78,8 @@ export function createAliveWriter(options) {
|
|
|
77
78
|
/** Kolejka wyrzuciła linię: następna udana niesie `luka: true`. */
|
|
78
79
|
let gap = false;
|
|
79
80
|
let logFailing = false;
|
|
80
|
-
/** The
|
|
81
|
-
let
|
|
81
|
+
/** The session list of the last successful write. */
|
|
82
|
+
let published = new Set();
|
|
82
83
|
const graceMs = options.graceMs ?? 0;
|
|
83
84
|
/** `phase: "starting"` until the first write with a session after the mode is resolved (only with a grace). */
|
|
84
85
|
let starting = graceMs > 0;
|
|
@@ -149,7 +150,7 @@ export function createAliveWriter(options) {
|
|
|
149
150
|
options.log?.('shadow: alive.json written again');
|
|
150
151
|
failing = !ok;
|
|
151
152
|
if (ok)
|
|
152
|
-
|
|
153
|
+
published = new Set(sessions);
|
|
153
154
|
if (ok)
|
|
154
155
|
history(ts, { mode, send, sessions }, stop);
|
|
155
156
|
return ok;
|
|
@@ -189,9 +190,9 @@ export function createAliveWriter(options) {
|
|
|
189
190
|
return tick();
|
|
190
191
|
},
|
|
191
192
|
sessionsChanged() {
|
|
192
|
-
if (timer === null || stopped
|
|
193
|
+
if (timer === null || stopped)
|
|
193
194
|
return false;
|
|
194
|
-
if (currentSessions().
|
|
195
|
+
if (currentSessions().every((id) => published.has(id)))
|
|
195
196
|
return false;
|
|
196
197
|
return tick();
|
|
197
198
|
},
|
|
@@ -52,7 +52,7 @@ import { MAIN_SCAN_MAX_BYTES } from './background/main-scan.js';
|
|
|
52
52
|
import { defaultStatuslineRoot, readStatusline } from './statusline.js';
|
|
53
53
|
import { createPendingTracker, createUltracodeTracker, mainAssistantAt, metaOf, parseJsonlEntry, } from './jsonl-pending.js';
|
|
54
54
|
import { createCliQueueTracker } from './jsonl-queue.js';
|
|
55
|
-
import { TRANSCRIPT_EXT, locateTranscript, transcriptHasConversation } from './transcript-path.js';
|
|
55
|
+
import { LookupRequests, TRANSCRIPT_EXT, locateTranscript, transcriptHasConversation } from './transcript-path.js';
|
|
56
56
|
import { UPLOAD_DIR_NAME } from './uploads.js';
|
|
57
57
|
// ---------------------------------------------------------------------------
|
|
58
58
|
// Stałe (świadomie w kodzie, nie w env: to nie jest konfiguracja bezpieczeństwa)
|
|
@@ -379,6 +379,10 @@ class Follower {
|
|
|
379
379
|
* to nowe pytanie.
|
|
380
380
|
*/
|
|
381
381
|
#pathLookedUp = false;
|
|
382
|
+
/** Lookup requests of this engine session; a new session gets a new one, so an old lookup in flight answers none. */
|
|
383
|
+
#lookups = new LookupRequests();
|
|
384
|
+
/** The armed retry of the lookup (`#armLookup`): one at a time, so requests never start a second chain. */
|
|
385
|
+
#lookupTimer = null;
|
|
382
386
|
/** Ile BAJTÓW pliku już skonsumowaliśmy. */
|
|
383
387
|
#offset = 0;
|
|
384
388
|
/**
|
|
@@ -659,18 +663,29 @@ class Follower {
|
|
|
659
663
|
this.#openSession(agentSessionId);
|
|
660
664
|
}
|
|
661
665
|
expectTranscript() {
|
|
662
|
-
if (this.#closed
|
|
666
|
+
if (this.#closed)
|
|
663
667
|
return;
|
|
664
|
-
this.#expecting
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
668
|
+
if (!this.#expecting) {
|
|
669
|
+
this.#expecting = true;
|
|
670
|
+
// Karencja liczy się od chwili, w której powstał POWÓD oczekiwania — nie od podpięcia
|
|
671
|
+
// drivera. Panel podpięty rano i użyty wieczorem ma dostać pełne 15 s, a nie alarm
|
|
672
|
+
// w tej samej sekundzie, w której poszła pierwsza wiadomość.
|
|
673
|
+
this.#missingSince = this.#now();
|
|
674
|
+
}
|
|
675
|
+
// The file is due now; after the fast window the next retry is seconds away.
|
|
676
|
+
this.lookUpTranscript();
|
|
677
|
+
}
|
|
678
|
+
lookUpTranscript() {
|
|
679
|
+
// An open file follows its own relocation tries, and a known path or a missing uuid has nothing to look for.
|
|
680
|
+
if (this.#closed || this.#primed || this.#path !== null || this.#agentSessionId === null)
|
|
681
|
+
return;
|
|
682
|
+
if (this.#lookups.ask())
|
|
683
|
+
this.#armLookup(0);
|
|
669
684
|
}
|
|
670
685
|
hasTranscript() {
|
|
671
686
|
if (this.#path !== null)
|
|
672
687
|
return 'yes';
|
|
673
|
-
return this.#pathLookedUp ? 'no' : 'unknown';
|
|
688
|
+
return this.#pathLookedUp && !this.#lookups.unanswered ? 'no' : 'unknown';
|
|
674
689
|
}
|
|
675
690
|
openToolUses() {
|
|
676
691
|
if (this.#trackerUnknown())
|
|
@@ -811,6 +826,7 @@ class Follower {
|
|
|
811
826
|
* Sam `#closed` nie wystarczy: follower ŻYJE dalej, zmienia tylko plik.
|
|
812
827
|
*/
|
|
813
828
|
this.#generation += 1;
|
|
829
|
+
this.#lookups = new LookupRequests();
|
|
814
830
|
// Identyfikator spoza wzorca = brak transkryptu. Świadomie po cichu: to nie jest sytuacja,
|
|
815
831
|
// z którą użytkownik telefonu może cokolwiek zrobić, a stan panelu dalej działa.
|
|
816
832
|
this.#agentSessionId = ENGINE_SESSION_ID_PATTERN.test(agentSessionId) ? agentSessionId : null;
|
|
@@ -849,14 +865,25 @@ class Follower {
|
|
|
849
865
|
if (uuid === null)
|
|
850
866
|
return null;
|
|
851
867
|
const gen = this.#generation;
|
|
852
|
-
const
|
|
868
|
+
const lookups = this.#lookups;
|
|
869
|
+
const mark = lookups.began();
|
|
870
|
+
let found;
|
|
871
|
+
try {
|
|
872
|
+
found = await locateTranscript(this.#root, this.#cwd, uuid);
|
|
873
|
+
}
|
|
874
|
+
finally {
|
|
875
|
+
lookups.ended(mark);
|
|
876
|
+
}
|
|
853
877
|
// Odpowiedź dotyczy TEJ sesji silnika: po `/clear` w trakcie globu wynik opisuje stary uuid
|
|
854
878
|
// i nie ma prawa ani ustawić ścieżki, ani zamknąć okna „nie wiem" nowej sesji.
|
|
855
879
|
if (this.#stale(gen))
|
|
856
880
|
return found;
|
|
857
881
|
this.#pathLookedUp = true;
|
|
858
|
-
if (found !== null)
|
|
882
|
+
if (found !== null) {
|
|
859
883
|
this.#path = found;
|
|
884
|
+
// A request left open would make every retry of a failed read of this file immediate.
|
|
885
|
+
lookups.found();
|
|
886
|
+
}
|
|
860
887
|
return found;
|
|
861
888
|
}
|
|
862
889
|
/**
|
|
@@ -1232,12 +1259,25 @@ class Follower {
|
|
|
1232
1259
|
this.#noTranscriptReported = true;
|
|
1233
1260
|
this.#push({ type: 'error', reason: 'no-transcript' });
|
|
1234
1261
|
}
|
|
1235
|
-
|
|
1262
|
+
// A request that came during the lookup which just missed wants a lookup that begins after it: now.
|
|
1263
|
+
const delay = this.#lookups.unanswered ? 0
|
|
1264
|
+
: elapsed < this.#missingWindowMs ? this.#missingFastMs : this.#missingSlowMs;
|
|
1265
|
+
this.#armLookup(delay);
|
|
1266
|
+
}
|
|
1267
|
+
/** Arms the retry of the lookup in `delay` ms in place of the one armed before. */
|
|
1268
|
+
#armLookup(delay) {
|
|
1269
|
+
if (this.#lookupTimer !== null) {
|
|
1270
|
+
clearTimeout(this.#lookupTimer);
|
|
1271
|
+
this.#timers.delete(this.#lookupTimer);
|
|
1272
|
+
}
|
|
1236
1273
|
// Ponowienie należy do TEJ sesji silnika. Po `repoint()` nowy plik ma własne otwarcie i własne
|
|
1237
1274
|
// ponowienia; stare, które wypadłoby w trakcie, otwierałoby go drugi raz.
|
|
1238
1275
|
const gen = this.#generation;
|
|
1239
|
-
this.#after(delay, () => {
|
|
1240
|
-
|
|
1276
|
+
this.#lookupTimer = this.#after(delay, () => {
|
|
1277
|
+
this.#lookupTimer = null;
|
|
1278
|
+
if (!this.#stale(gen))
|
|
1279
|
+
void this.#prime();
|
|
1280
|
+
});
|
|
1241
1281
|
}
|
|
1242
1282
|
#startWatch() {
|
|
1243
1283
|
if (this.#closed)
|
|
@@ -2336,7 +2376,7 @@ class Follower {
|
|
|
2336
2376
|
}
|
|
2337
2377
|
#after(ms, fn) {
|
|
2338
2378
|
if (this.#closed)
|
|
2339
|
-
return;
|
|
2379
|
+
return null;
|
|
2340
2380
|
const timer = setTimeout(() => {
|
|
2341
2381
|
this.#timers.delete(timer);
|
|
2342
2382
|
if (this.#closed)
|
|
@@ -2345,6 +2385,7 @@ class Follower {
|
|
|
2345
2385
|
}, ms);
|
|
2346
2386
|
timer.unref?.();
|
|
2347
2387
|
this.#timers.add(timer);
|
|
2388
|
+
return timer;
|
|
2348
2389
|
}
|
|
2349
2390
|
}
|
|
2350
2391
|
/**
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
* rarog" jest ślad ({@link labelTrace}) w etykiecie PANELU Claude.
|
|
31
31
|
*/
|
|
32
32
|
import { createHash, randomBytes } from 'node:crypto';
|
|
33
|
-
import { realpath } from 'node:fs/promises';
|
|
34
33
|
import path from 'node:path';
|
|
35
34
|
import { TERM_ID_RE } from '@rarog/shared';
|
|
35
|
+
import { DIRECT_DISK } from '../folder-gate/disk.js';
|
|
36
36
|
import { normalizeSessionLabel } from '../session-label.js';
|
|
37
37
|
/** Przedrostek nazw Raroga w herdr: nazwa agenta, etykiety paneli i etykieta taba terminala. */
|
|
38
38
|
export const HERDR_NAME_PREFIX = 'rarog';
|
|
@@ -75,9 +75,9 @@ export function projectKey(realCwd) {
|
|
|
75
75
|
* znormalizowana zamiast rzucać. Launcher liczy klucz PO starcie agenta i jego etykieta jest
|
|
76
76
|
* best effort — brak katalogu na dysku nie ma prawa wywrócić startu sesji.
|
|
77
77
|
*/
|
|
78
|
-
export async function realProjectPath(cwd) {
|
|
78
|
+
export async function realProjectPath(cwd, disk = DIRECT_DISK) {
|
|
79
79
|
try {
|
|
80
|
-
return await
|
|
80
|
+
return await disk.call('realpathNative', { path: cwd });
|
|
81
81
|
}
|
|
82
82
|
catch {
|
|
83
83
|
return path.resolve(cwd);
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Reszta integracji rozmawia z `HerdrClient` (typowana fasada) albo z `HerdrSupervisor` —
|
|
5
5
|
* żaden inny moduł nie ma prawa wiedzieć, że po drugiej stronie jest gniazdo. Dzięki temu
|
|
6
6
|
* cały ruch do herdr przechodzi przez DWIE bramki, które da się sprawdzić w jednym pliku:
|
|
7
|
-
* allow-listę metod i bramkę protokołu (
|
|
8
|
-
*
|
|
7
|
+
* allow-listę metod i bramkę protokołu (the minimum of the tested set {@link KNOWN_PROTOCOLS},
|
|
8
|
+
* today `{22}`). Dotyczy to OBU ścieżek piszących do gniazda:
|
|
9
9
|
* `request()` i `subscribe()` — ta druga wysyła nazwę metody literałem, więc przepuszcza go
|
|
10
10
|
* przez `assertMethodAllowed`, żeby gwarancja była sprawdzalna testem, a nie opisowa.
|
|
11
11
|
*
|
|
@@ -99,8 +99,8 @@ export const READ_METHODS = new Set([
|
|
|
99
99
|
/**
|
|
100
100
|
* Metody MUTUJĄCE stan po stronie herdr. Tylko one podlegają bramce trybu tylko-do-odczytu.
|
|
101
101
|
*
|
|
102
|
-
* Każdy zapis MUSI być tutaj, a nie w {@link READ_METHODS}: `readOnly` (
|
|
103
|
-
* `RAROG_HERDR_SEND=0`
|
|
102
|
+
* Każdy zapis MUSI być tutaj, a nie w {@link READ_METHODS}: `readOnly` (that is,
|
|
103
|
+
* `RAROG_HERDR_SEND=0`) is checked ONLY against this list.
|
|
104
104
|
* Bez tych linii runbook „kradzież telefonu" byłby fikcją — `agent.start` i `tab.close`
|
|
105
105
|
* przechodziłyby przy wyłączonym kanale zapisu.
|
|
106
106
|
*/
|
|
@@ -134,7 +134,7 @@ export const MUTATING_METHODS = new Set([
|
|
|
134
134
|
* taba z Claude równą etykiecie karty (`syncTabLabel`) i migruje stare etykiety tabów terminala
|
|
135
135
|
* — zawsze tylko w tabie jednopanelowym z panelem oznaczonym przez Raroga. Obie są
|
|
136
136
|
* ZAPISAMI: zmieniają to, co człowiek widzi w herdr, i to, co Rarog uzna za swoje, więc
|
|
137
|
-
* `RAROG_HERDR_SEND=0`
|
|
137
|
+
* `RAROG_HERDR_SEND=0` turns them off together with the other mutations.
|
|
138
138
|
*/
|
|
139
139
|
'pane.rename', 'tab.rename',
|
|
140
140
|
/*
|
|
@@ -144,7 +144,7 @@ export const MUTATING_METHODS = new Set([
|
|
|
144
144
|
* wtedy wysyła osobny Enter (`agent.send_keys`). Jedyny wołający to `HerdrClient.pasteText`: ciało ma wyłącznie
|
|
145
145
|
* `pane_id` i `text`, nigdy `keys`. Adres panelu jest pozycyjny i metoda pisze też do panelu bez agenta, dlatego
|
|
146
146
|
* driver woła ją tylko po świeżym `agent.get`, że pod tym adresem stoi agent tej samej sesji. ZAPIS: gaśnie razem
|
|
147
|
-
* z resztą przy `RAROG_HERDR_SEND=0
|
|
147
|
+
* z resztą przy `RAROG_HERDR_SEND=0`.
|
|
148
148
|
*/
|
|
149
149
|
'pane.send_input',
|
|
150
150
|
]);
|
|
@@ -195,19 +195,20 @@ export function assertMethodAllowed(method) {
|
|
|
195
195
|
* first `agent.list`, so it loses nothing. 20 and 21 are NOT in the set: on 20 `agent.prompt` has
|
|
196
196
|
* different semantics (#3506), no herdr release carries 21, and the dialog parser is measured on 22.
|
|
197
197
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
198
|
+
* INVARIANT that is easy to trip over when tidying up: at runtime only the MINIMUM of this set gates.
|
|
199
|
+
* A number below it turns integration off (the shapes the whole parser stands on are unknown); every
|
|
200
|
+
* number at or above it, also one above the tested maximum, gets full integration. Adding a number
|
|
201
|
+
* changes nothing at runtime, it records a measurement (the after-update measurement scripts read the
|
|
202
|
+
* set). Dropping or replacing the oldest number turns that protocol off: a change of behaviour, not
|
|
203
|
+
* tidying.
|
|
203
204
|
*/
|
|
204
205
|
export const KNOWN_PROTOCOLS = new Set([22]);
|
|
205
206
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
207
|
+
* The highest tested number, for messages and tests. The export stays because the gate is one, and
|
|
208
|
+
* not every line that talks about it needs the whole set.
|
|
208
209
|
*/
|
|
209
210
|
export const TESTED_PROTOCOL = Math.max(...KNOWN_PROTOCOLS);
|
|
210
|
-
/**
|
|
211
|
+
/** The oldest tested number and the only runtime gate: below it integration is OFF. */
|
|
211
212
|
const OLDEST_KNOWN_PROTOCOL = Math.min(...KNOWN_PROTOCOLS);
|
|
212
213
|
export const CONNECT_TIMEOUT_MS = 2_000;
|
|
213
214
|
export const REQUEST_TIMEOUT_MS = 5_000;
|
|
@@ -649,8 +650,8 @@ export function createHerdrSocket(opts) {
|
|
|
649
650
|
try {
|
|
650
651
|
const result = await roundtrip(method, params, timeoutMs);
|
|
651
652
|
if (!available) {
|
|
652
|
-
//
|
|
653
|
-
//
|
|
653
|
+
// A successful request clears the REASON for unavailability, not the reason for read-only
|
|
654
|
+
// mode: that one (`RAROG_HERDR_SEND=0`) still holds and has to stay visible.
|
|
654
655
|
setStatus(readOnly && detail !== undefined
|
|
655
656
|
? { available: true, readOnly, detail }
|
|
656
657
|
: { available: true, readOnly });
|
|
@@ -670,11 +671,14 @@ export function createHerdrSocket(opts) {
|
|
|
670
671
|
/**
|
|
671
672
|
* Bramka protokołu wykonywana przy starcie i przy KAŻDYM (re)connectcie subskrypcji.
|
|
672
673
|
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
674
|
+
* The gate is a MINIMUM. No number in the pong, or a number below the minimum of
|
|
675
|
+
* {@link KNOWN_PROTOCOLS}, turns integration off (the shapes the whole parser stands on are
|
|
676
|
+
* unknown). Every number at or above the minimum, also one above the tested maximum, gets full
|
|
677
|
+
* integration, and `sendEnabled` decides about writes exactly as on a tested number: a newer herdr
|
|
678
|
+
* must not stop Rarog. The number never guarded the meaning of a method anyway: in herdr 0.8.2 the
|
|
679
|
+
* semantics of `agent prompt` changed without a new protocol number. On an untested number writes
|
|
680
|
+
* stay behind the method allow-list and the response checks; `RAROG_HERDR_SEND=0` is the manual way
|
|
681
|
+
* back to read-only.
|
|
678
682
|
*
|
|
679
683
|
* Z ponga czytamy przy okazji `capabilities.endpoint_protocol_generation` — do
|
|
680
684
|
* {@link HerdrSocketStatus.generation}, czyli WYŁĄCZNIE do diagnostyki, NIGDY do `readOnly`
|
|
@@ -707,13 +711,6 @@ export function createHerdrSocket(opts) {
|
|
|
707
711
|
setStatus({ available: false, readOnly: true, detail: say('herdr.protocol-too-old', versions) });
|
|
708
712
|
throw new HerdrUnavailableError(say('herdr.protocol-too-old.disabled', versions));
|
|
709
713
|
}
|
|
710
|
-
if (!KNOWN_PROTOCOLS.has(protocol)) {
|
|
711
|
-
const tested = [...KNOWN_PROTOCOLS].join(', ');
|
|
712
|
-
setStatus({
|
|
713
|
-
available: true, readOnly: true, detail: say('herdr.protocol-unknown', { protocol: String(protocol), tested }),
|
|
714
|
-
});
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
714
|
setStatus(sendEnabled
|
|
718
715
|
? { available: true, readOnly: false }
|
|
719
716
|
: { available: true, readOnly: true, detail: SEND_DISABLED_DETAIL });
|
|
@@ -107,8 +107,8 @@ const STATUS_EVENT = 'pane_agent_status_changed';
|
|
|
107
107
|
*
|
|
108
108
|
* Dwie zasady, obie wynikają z tego jednego zdarzenia:
|
|
109
109
|
*
|
|
110
|
-
* 1. **
|
|
111
|
-
*
|
|
110
|
+
* 1. **The transport wins.** When herdr is silent or its protocol is missing or too old, that is
|
|
111
|
+
* a bigger truth than the cap, and with herdr unavailable the cap means nothing anyway.
|
|
112
112
|
* 2. **Sufit pokazujemy TYLKO wtedy, gdy jest jedynym powodem.** Przy `RAROG_HERDR_LAUNCH=0`
|
|
113
113
|
* zdanie „zamknij którąś sesję" byłoby radą, która niczego nie odblokuje: zamknięcie
|
|
114
114
|
* panelu nie włączy killswitcha. Wtedy `undefined` jest uczciwsze — klient powie własne,
|
|
@@ -452,13 +452,13 @@ export function createHerdrSupervisor(config, deps) {
|
|
|
452
452
|
return 'retry';
|
|
453
453
|
const client = launchClient;
|
|
454
454
|
/*
|
|
455
|
-
* Kanał zapisu zamknięty (`RAROG_HERDR_SEND=0
|
|
455
|
+
* Kanał zapisu zamknięty (`RAROG_HERDR_SEND=0`): bramka gniazda i tak
|
|
456
456
|
* odbiłaby `tab.rename`, ale bez tego warunku każdy klucz płaciłby odczyty i linię logu.
|
|
457
457
|
* Jedna linia na proces mówi, czemu taby nie idą za kartami.
|
|
458
458
|
*/
|
|
459
459
|
if (!config.sendEnabled || transport.status().readOnly) {
|
|
460
460
|
logTabLabelOnce('read-only', 'herdr: tab labels on hold — write channel closed '
|
|
461
|
-
+ '(RAROG_HERDR_SEND=0
|
|
461
|
+
+ '(RAROG_HERDR_SEND=0)');
|
|
462
462
|
return 'done';
|
|
463
463
|
}
|
|
464
464
|
// Manager podaje etykietę już po `normalizeSessionLabel`; tu ta sama funkcja (idempotentna)
|
|
@@ -838,9 +838,10 @@ export function createHerdrSupervisor(config, deps) {
|
|
|
838
838
|
* warunkiem poprawności, a nie estetyką: gałąź zmiany `cwd` liczyła zakres wyłącznie
|
|
839
839
|
* z korzeni, więc `cd` pod korzeń włączyłby Codexowi followera pliku, którego nie ma.
|
|
840
840
|
* The roots count as the work area: no hidden entry of a root, no macOS-protected folder of home, as written
|
|
841
|
-
* and on disk, so a link into such a folder or a root that is a symlink to home does not open it.
|
|
841
|
+
* and on disk, so a link into such a folder or a root that is a symlink to home does not open it. Scope ignores
|
|
842
|
+
* the folder gate: a pane in a guarded folder a root opens stays in scope while the folder is closed.
|
|
842
843
|
*/
|
|
843
|
-
const scopeOf = (info) => (info.engine === 'codex' ? false : inWorkAreaOnDisk(info.cwd, config.roots, home));
|
|
844
|
+
const scopeOf = (info) => (info.engine === 'codex' ? false : inWorkAreaOnDisk(info.cwd, config.roots, home, undefined, { gate: 'ignore' }));
|
|
844
845
|
/**
|
|
845
846
|
* Nowy wpis agenta w mapach supervisora.
|
|
846
847
|
*
|
|
@@ -1044,6 +1045,7 @@ export function createHerdrSupervisor(config, deps) {
|
|
|
1044
1045
|
// `set` nadpisuje też ewentualny wpis cudzego panelu pod tym uuid (kolizja wyżej):
|
|
1045
1046
|
// od teraz sesję silnika ma TEN panel; tamten wpis zniknie z listy swoim trybem.
|
|
1046
1047
|
bySession.set(info.agentSessionId, key);
|
|
1048
|
+
deps.onAgentsChanged?.();
|
|
1047
1049
|
emitPane(entry, { type: 'session-changed', agentSessionId: info.agentSessionId });
|
|
1048
1050
|
}
|
|
1049
1051
|
}
|
|
@@ -1110,6 +1112,7 @@ export function createHerdrSupervisor(config, deps) {
|
|
|
1110
1112
|
*/
|
|
1111
1113
|
if (inScope !== entry.agent.inScope) {
|
|
1112
1114
|
entry.agent.inScope = inScope;
|
|
1115
|
+
deps.onAgentsChanged?.();
|
|
1113
1116
|
if (entry.attached)
|
|
1114
1117
|
entry.needsReattach = true;
|
|
1115
1118
|
log(`herdr: ${entry.agent.paneId} changed scope (inScope=${String(inScope)}) after cd to ${info.cwd}`);
|
|
@@ -1535,10 +1538,10 @@ export function createHerdrSupervisor(config, deps) {
|
|
|
1535
1538
|
const raw = transport.status();
|
|
1536
1539
|
const readOnly = raw.readOnly || !config.sendEnabled;
|
|
1537
1540
|
/*
|
|
1538
|
-
* `canLaunch`
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
1541
|
-
*
|
|
1541
|
+
* `canLaunch` goes off for FOUR independent reasons, each a separate power: no opt-in
|
|
1542
|
+
* (`RAROG_HERDR_LAUNCH=0`, no launcher), read-only mode (`RAROG_HERDR_SEND=0`, because
|
|
1543
|
+
* `agent.start` is in `MUTATING_METHODS`), an unavailable herdr (also a protocol below the
|
|
1544
|
+
* tested minimum) and the reached cap of Rarog panes.
|
|
1542
1545
|
*
|
|
1543
1546
|
* Rozbite na dwie liczby, bo sufit jako JEDYNY ma dla człowieka wyjście („zamknij
|
|
1544
1547
|
* którąś sesję") i tylko wtedy wolno je pokazać — patrz `launchDetail`.
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* Granica bezpieczeństwa: `uuid` przechodzi `ENGINE_SESSION_ID_PATTERN` PRZED jakimkolwiek
|
|
16
16
|
* `join`. Identyfikator bywa wejściem z requestu (`resumeFrom`), a `../../…` czytałoby dowolny
|
|
17
17
|
* plik konta użytkownika.
|
|
18
|
+
*
|
|
19
|
+
* The module also keeps the requests to look a file not found yet up now (`LookupRequests`); the follower's retry
|
|
20
|
+
* chain runs the lookups.
|
|
18
21
|
*/
|
|
19
22
|
import { open, readdir, stat } from 'node:fs/promises';
|
|
20
23
|
import { join } from 'node:path';
|
|
@@ -63,6 +66,39 @@ export async function locateTranscript(root, cwd, uuid) {
|
|
|
63
66
|
const hits = await Promise.all(candidates.map(async (path) => (await isFile(path) ? path : null)));
|
|
64
67
|
return hits.find((path) => path !== null) ?? null;
|
|
65
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Requests to look a transcript file up now, and which lookup answers them. A lookup answers only the requests made
|
|
71
|
+
* before it began: one that began earlier may have read the store before the file was created, so after its miss
|
|
72
|
+
* a request stays open and the follower looks again at once.
|
|
73
|
+
*/
|
|
74
|
+
export class LookupRequests {
|
|
75
|
+
#asked = 0;
|
|
76
|
+
#answered = 0;
|
|
77
|
+
#running = 0;
|
|
78
|
+
/** A request; `true` when no lookup is running, so the caller starts one now. */
|
|
79
|
+
ask() {
|
|
80
|
+
this.#asked += 1;
|
|
81
|
+
return this.#running === 0;
|
|
82
|
+
}
|
|
83
|
+
/** A lookup begins; the mark goes to {@link LookupRequests.ended}. */
|
|
84
|
+
began() {
|
|
85
|
+
this.#running += 1;
|
|
86
|
+
return this.#asked;
|
|
87
|
+
}
|
|
88
|
+
/** The lookup that began at `mark` ended, with a file or without one. */
|
|
89
|
+
ended(mark) {
|
|
90
|
+
this.#running -= 1;
|
|
91
|
+
this.#answered = Math.max(this.#answered, mark);
|
|
92
|
+
}
|
|
93
|
+
/** The file is found: that answers every request, also one made while the lookup ran. */
|
|
94
|
+
found() {
|
|
95
|
+
this.#answered = this.#asked;
|
|
96
|
+
}
|
|
97
|
+
/** A request that no ended lookup answers yet. */
|
|
98
|
+
get unanswered() {
|
|
99
|
+
return this.#answered < this.#asked;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
66
102
|
/**
|
|
67
103
|
* Ile bajtów prefiksu wystarczy, żeby rozstrzygnąć „czy w tym pliku była rozmowa".
|
|
68
104
|
*
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Rarog tego pliku NIGDY nie zapisuje (`docs/security-model.md`, „Starting sessions from the phone: three powers”).
|
|
17
17
|
*/
|
|
18
|
-
import {
|
|
18
|
+
import { readFile as fsReadFile, stat as fsStat } from 'node:fs/promises';
|
|
19
19
|
import os from 'node:os';
|
|
20
20
|
import path from 'node:path';
|
|
21
|
-
import {
|
|
21
|
+
import { DIRECT_DISK } from '../folder-gate/disk.js';
|
|
22
22
|
/**
|
|
23
23
|
* Jak długo trzymamy wynik bez parsowania pliku od nowa: pełny odczyt i `JSON.parse` całego `~/.claude.json` przy
|
|
24
24
|
* każdym starcie panelu to koszt bez potrzeby, a zmianę pliku i tak łapie znacznik `mtime:size` (`fileStamp`).
|
|
@@ -30,9 +30,9 @@ const GITDIR_LINE = /^gitdir: (.+)$/m;
|
|
|
30
30
|
const WORKTREE_GITDIR = /^(.+)\/\.git\/worktrees\/[^/]+\/?$/;
|
|
31
31
|
/** Sufit odczytu pliku `.git`: jedna linia ścieżki. */
|
|
32
32
|
const GIT_FILE_MAX_BYTES = 4096;
|
|
33
|
-
async function defaultStatGit(gitPath) {
|
|
33
|
+
async function defaultStatGit(disk, gitPath) {
|
|
34
34
|
try {
|
|
35
|
-
const st = await
|
|
35
|
+
const st = await disk.call('lstat', { path: gitPath });
|
|
36
36
|
if (st.isDirectory())
|
|
37
37
|
return 'directory';
|
|
38
38
|
return st.isFile() ? 'file' : 'other';
|
|
@@ -44,8 +44,8 @@ async function defaultStatGit(gitPath) {
|
|
|
44
44
|
throw err;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
async function defaultReadGitFile(gitPath) {
|
|
48
|
-
const read = await
|
|
47
|
+
async function defaultReadGitFile(disk, gitPath) {
|
|
48
|
+
const read = await disk.call('readHead', { path: gitPath, maxBytes: GIT_FILE_MAX_BYTES, followSymlink: false });
|
|
49
49
|
return read === null ? null : read.bytes.toString('utf8');
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
@@ -130,8 +130,11 @@ export function createTrustCheck(opts = {}) {
|
|
|
130
130
|
return `${st.mtimeMs}:${st.size}`;
|
|
131
131
|
});
|
|
132
132
|
const home = path.resolve(opts.home ?? os.homedir());
|
|
133
|
-
const
|
|
134
|
-
const
|
|
133
|
+
const disk = opts.disk ?? DIRECT_DISK;
|
|
134
|
+
const statGit = opts.statGit
|
|
135
|
+
?? (async (gitPath) => defaultStatGit(disk, gitPath));
|
|
136
|
+
const readGitFile = opts.readGitFile
|
|
137
|
+
?? (async (gitPath) => defaultReadGitFile(disk, gitPath));
|
|
135
138
|
let cache = null;
|
|
136
139
|
/** Dedup równoległych wywołań: dwie karty naraz nie mają czytać 210 kB dwa razy. */
|
|
137
140
|
let inFlight = null;
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* roots. The module only keeps the list: it neither reads nor deletes attachments. An entry is the real path of the
|
|
6
6
|
* `<cwd>` of a write (the caller resolves it), and the sweep appends `.rarog-uploads` itself and skips an entry that
|
|
7
7
|
* no longer resolves to itself, so an entry cannot point the sweep at another directory.
|
|
8
|
-
* The file exists only after one complete walk of the roots
|
|
9
|
-
*
|
|
8
|
+
* The file exists only after one complete walk of the roots, a part deferred until a guarded folder opens included: a
|
|
9
|
+
* write that finds no file waits in memory until that walk writes it, so a server stopped before the walk ended walks
|
|
10
|
+
* again at the next start.
|
|
10
11
|
*/
|
|
11
12
|
import { randomBytes } from 'node:crypto';
|
|
12
13
|
import { mkdir, rename, unlink, writeFile } from 'node:fs/promises';
|