@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.
Files changed (140) hide show
  1. package/README.md +18 -5
  2. package/node_modules/@rarog/shared/package.json +1 -1
  3. package/node_modules/@rarog/shared/src/decode.js +64 -3
  4. package/node_modules/@rarog/shared/src/protocol/files.js +33 -0
  5. package/node_modules/@rarog/shared/src/protocol/folders.js +27 -0
  6. package/node_modules/@rarog/shared/src/protocol/herdr.js +23 -0
  7. package/node_modules/@rarog/shared/src/protocol/inbox.js +38 -0
  8. package/node_modules/@rarog/shared/src/protocol/notes.js +7 -1
  9. package/node_modules/@rarog/shared/src/protocol.js +20 -47
  10. package/node_modules/@rarog/shared/src/rest.js +106 -12
  11. package/node_modules/@rarog/shared/src/sentences/herdr.js +0 -4
  12. package/node_modules/@rarog/shared/src/sentences/index.js +7 -1
  13. package/node_modules/@rarog/shared/src/sentences/rest.js +21 -0
  14. package/package.json +3 -3
  15. package/server/src/auth/admin.js +3 -1
  16. package/server/src/bootstrap/consent.js +99 -2
  17. package/server/src/bootstrap/folder-gate.js +55 -0
  18. package/server/src/bootstrap/http.js +3 -2
  19. package/server/src/bootstrap/inbox.js +29 -4
  20. package/server/src/bootstrap/sse.js +2 -1
  21. package/server/src/cli/doctor-no-hook.js +162 -0
  22. package/server/src/cli/doctor.js +2 -0
  23. package/server/src/cli/service-log.js +27 -0
  24. package/server/src/cli/service.js +5 -2
  25. package/server/src/cli/templates/launchd.plist +1 -1
  26. package/server/src/cli/templates/rarog.service +1 -1
  27. package/server/src/cli/update-channel.js +100 -0
  28. package/server/src/cli/update-provenance.js +37 -19
  29. package/server/src/cli/update-registry.js +160 -62
  30. package/server/src/cli/update.js +13 -3
  31. package/server/src/companion/turns-settle.js +4 -1
  32. package/server/src/companion/turns.js +36 -5
  33. package/server/src/config/files.js +32 -0
  34. package/server/src/config/flags.js +10 -1
  35. package/server/src/config/protected-dirs.js +2 -0
  36. package/server/src/config/roots.js +13 -8
  37. package/server/src/config/work-area.js +36 -12
  38. package/server/src/config-env.js +33 -0
  39. package/server/src/config.js +22 -2
  40. package/server/src/demo/control.js +9 -1
  41. package/server/src/demo/files.js +49 -0
  42. package/server/src/demo/inbox.js +73 -0
  43. package/server/src/demo/review-routes.js +6 -1
  44. package/server/src/device-effects.js +3 -1
  45. package/server/src/drivers/herdr/consent-no-hook-io.js +89 -0
  46. package/server/src/drivers/herdr/consent-no-hook.js +411 -0
  47. package/server/src/drivers/herdr/refusals.js +226 -0
  48. package/server/src/drivers/herdr/returned-prompt.js +172 -0
  49. package/server/src/drivers/herdr/screen-fallback.js +246 -0
  50. package/server/src/drivers/herdr-driver.js +193 -295
  51. package/server/src/files/file-index.js +248 -0
  52. package/server/src/files/ignored.js +119 -0
  53. package/server/src/files/listing.js +82 -0
  54. package/server/src/files/path-rule.js +199 -0
  55. package/server/src/files/refusals.js +50 -0
  56. package/server/src/files/send-file.js +115 -0
  57. package/server/src/files/session-download.js +51 -0
  58. package/server/src/files/session-files.js +38 -0
  59. package/server/src/files/session-gate.js +53 -0
  60. package/server/src/folder-gate/client.js +314 -0
  61. package/server/src/folder-gate/disk.js +455 -0
  62. package/server/src/folder-gate/folders.js +23 -0
  63. package/server/src/folder-gate/gate.js +220 -0
  64. package/server/src/folder-gate/helper.js +118 -0
  65. package/server/src/folder-gate/install.js +27 -0
  66. package/server/src/folder-gate/relay-worker.js +147 -0
  67. package/server/src/folder-gate/types.js +115 -0
  68. package/server/src/folder-gate/wire.js +170 -0
  69. package/server/src/fs-browse.js +55 -23
  70. package/server/src/fs-mkdir.js +3 -1
  71. package/server/src/git-status.js +16 -7
  72. package/server/src/git-watch.js +130 -19
  73. package/server/src/git-work-tree.js +3 -3
  74. package/server/src/herdr/audit.js +1 -1
  75. package/server/src/herdr/client.js +2 -2
  76. package/server/src/herdr/commands/discover.js +21 -9
  77. package/server/src/herdr/dialogs/consent-gate.js +28 -8
  78. package/server/src/herdr/dialogs/decide/sources.js +5 -2
  79. package/server/src/herdr/dialogs/hook/contract.js +16 -9
  80. package/server/src/herdr/dialogs/index.js +12 -2
  81. package/server/src/herdr/dialogs/layer1/cycle.js +43 -7
  82. package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +166 -86
  83. package/server/src/herdr/dialogs/layer1/hook-list/session-facts.js +135 -0
  84. package/server/src/herdr/dialogs/layer1/screen-key.js +52 -0
  85. package/server/src/herdr/dialogs/layer1/version-gate.js +13 -5
  86. package/server/src/herdr/dialogs/no-hook.js +63 -0
  87. package/server/src/herdr/dialogs/router.js +21 -6
  88. package/server/src/herdr/dialogs/screen/block.js +10 -0
  89. package/server/src/herdr/dialogs/screen/parse.js +33 -3
  90. package/server/src/herdr/dialogs/screen/resolve.js +9 -7
  91. package/server/src/herdr/dialogs/screen-fallback.js +55 -0
  92. package/server/src/herdr/dialogs/shadow/alive.js +9 -8
  93. package/server/src/herdr/jsonl-follow.js +55 -14
  94. package/server/src/herdr/jsonl-pending.js +25 -1
  95. package/server/src/herdr/provenance.js +3 -3
  96. package/server/src/herdr/socket.js +25 -28
  97. package/server/src/herdr/supervisor.js +13 -10
  98. package/server/src/herdr/transcript-path.js +36 -0
  99. package/server/src/herdr/trust.js +11 -8
  100. package/server/src/herdr/uploads-registry.js +3 -2
  101. package/server/src/herdr/uploads.js +170 -47
  102. package/server/src/inbox/card.js +18 -9
  103. package/server/src/inbox/dialogs.js +40 -12
  104. package/server/src/inbox/heads.js +55 -0
  105. package/server/src/inbox/inbox.js +24 -2
  106. package/server/src/inbox/index.js +3 -1
  107. package/server/src/index.js +44 -21
  108. package/server/src/install/repair.js +8 -0
  109. package/server/src/iroh/listener.js +3 -0
  110. package/server/src/iroh/log-budget.js +1 -0
  111. package/server/src/iroh/socket.js +2 -1
  112. package/server/src/log-timestamps.js +9 -4
  113. package/server/src/notes/store.js +3 -2
  114. package/server/src/router.js +20 -2
  115. package/server/src/routes/devices.js +2 -2
  116. package/server/src/routes/inbox.js +91 -0
  117. package/server/src/routes/projects.js +5 -1
  118. package/server/src/routes/sessions.js +145 -18
  119. package/server/src/routes/system.js +9 -4
  120. package/server/src/safe-read.js +86 -1
  121. package/server/src/sessions/companion-scope.js +16 -7
  122. package/server/src/sessions/demo-modules.js +16 -0
  123. package/server/src/sessions/diff-measure.js +30 -0
  124. package/server/src/sessions/done-retention.js +57 -0
  125. package/server/src/sessions/launch-gate.js +2 -2
  126. package/server/src/sessions/manager.js +78 -190
  127. package/server/src/sessions/project-scan.js +9 -3
  128. package/server/src/sessions/ring-buffer.js +5 -3
  129. package/server/src/sessions/seen-marks.js +9 -6
  130. package/server/src/sessions/session-git.js +31 -2
  131. package/server/src/sessions/session-scope.js +30 -0
  132. package/server/src/sessions/session.js +19 -0
  133. package/server/src/sessions/state-sentences.js +1 -1
  134. package/server/src/sessions/waiting-line.js +72 -0
  135. package/server/src/sse.js +143 -10
  136. package/server/src/term/herdr-backend.js +2 -2
  137. package/server/src/term/index.js +2 -15
  138. package/server/src/term/registry.js +4 -3
  139. package/server/src/term/ws.js +9 -1
  140. 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 (ZBIÓR przetestowanych numerów — {@link KNOWN_PROTOCOLS},
8
- * dziś `{22}`). Dotyczy to OBU ścieżek piszących do gniazda:
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` (czyli
103
- * `RAROG_HERDR_SEND=0` ORAZ nieznany protokół) jest sprawdzany WYŁĄCZNIE po tej liście.
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` i nieznany protokół gaszą je razem z resztą mutacji.
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` i nieznanym protokole.
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
- * NIEZMIENNIK, o który łatwo się potknąć przy sprzątaniu: klasyfikacja „nieznany numer" liczy się
199
- * od MINIMUM tego zbioru. Numer PONIŻEJ minimum wyłącza integrację (nie znamy kształtów, na
200
- * których stoi cały parser), każdy inny nieznany numer daje tryb tylko do odczytu. Usunięcie
201
- * najstarszego numeru ze zbioru (np. przy dokładaniu 23) PRZESTAWIA więc wszystko pod nim
202
- * z „tylko odczyt" na „wyłączona" — to jest zmiana zachowania, nie porządki.
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
- * Najwyższy przetestowany numer — do komunikatów i do testów. Eksport zostaje, bo bramka jest
207
- * jedna, a nie każda linia, która o niej mówi, potrzebuje całego zbioru.
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
- /** Najstarszy przetestowany numer: pod nim integracja jest WYŁĄCZONA, nie „tylko do odczytu". */
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
- // Udane żądanie kasuje POWÓD niedostępności, ale nie powód trybu tylko-do-odczytu:
653
- // ten drugi (nowszy protokół, `RAROG_HERDR_SEND=0`) nadal obowiązuje i ma być widoczny.
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
- * Numer W {@link KNOWN_PROTOCOLS} → pełna integracja. Numer PONIŻEJ minimum zbioru →
674
- * integracja nieaktywna (nie znamy kształtów, na których stoi cały parser). Każdy inny numer
675
- * (nieznany, także nowszy) → tryb TYLKO ODCZYT: w 0.8.2 zmieniła się SEMANTYKA `agent prompt`
676
- * bez zmiany numeru protokołu, więc fail-open na mutacjach jest zakładem o cudzy changelog.
677
- * Fail-open na odczytach jest bezpieczny i utrzymuje wartość Raroga po każdej aktualizacji.
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. **Transport ma pierwszeństwo.** Gdy herdr milczy albo mówi nieznanym protokołem, to jest
111
- * większa prawda niż sufit — a przy niedostępnym herdr sufit i tak nic nie znaczy.
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`, nieznany protokół): bramka gniazda i tak
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 or unknown protocol)');
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` gaśnie z CZTERECH niezależnych powodów i każdy z nich jest osobną
1539
- * władzą: brak opt-inu (`RAROG_HERDR_LAUNCH=0` → brak launchera), tryb tylko do
1540
- * odczytu (nieznany protokół albo `RAROG_HERDR_SEND=0` — bo `agent.start` jest
1541
- * w `MUTATING_METHODS`), niedostępny herdr i osiągnięty sufit paneli Raroga.
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 { lstat as fsLstat, readFile as fsReadFile, stat as fsStat } from 'node:fs/promises';
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 { readRegularFile } from '../safe-read.js';
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 fsLstat(gitPath);
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 readRegularFile(gitPath, { maxBytes: GIT_FILE_MAX_BYTES, followSymlink: false });
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 statGit = opts.statGit ?? defaultStatGit;
134
- const readGitFile = opts.readGitFile ?? defaultReadGitFile;
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: a write that finds no file waits in memory until the
9
- * first-start walk writes it, so a server stopped in the middle of that walk walks again at the next start.
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';