@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
|
@@ -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';
|