@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
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* that every caller uses before Rarog runs anything in a directory. `loadConfig` (`server/src/config.ts`) passes in
|
|
4
4
|
* the values it read through `readEnv`.
|
|
5
5
|
*/
|
|
6
|
-
import { realpathSync, statSync } from 'node:fs';
|
|
7
6
|
import os from 'node:os';
|
|
8
7
|
import path from 'node:path';
|
|
9
8
|
import { say } from '@rarog/shared/sentences';
|
|
10
9
|
import { ConfigError, HERDR_ROOTS_ENV, PROJECT_ROOTS_ENV } from '../config-env.js';
|
|
10
|
+
import { DIRECT_DISK } from '../folder-gate/disk.js';
|
|
11
11
|
import { insideWorkArea, isExcludedPath, resolveInWorkArea } from './work-area.js';
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
13
|
// Korzenie projektów i walidacja cwd
|
|
@@ -85,9 +85,11 @@ export function isInsideAnyRoot(candidate, roots) {
|
|
|
85
85
|
return false;
|
|
86
86
|
return roots.some((root) => isInside(candidate, root));
|
|
87
87
|
}
|
|
88
|
+
/** `realpathSync` of the work-area disk port: the JavaScript walk, letter case as written. */
|
|
89
|
+
const realpathOnDisk = (candidate) => DIRECT_DISK.sync('realpath', { path: candidate });
|
|
88
90
|
function realIsDirectory(candidate) {
|
|
89
91
|
try {
|
|
90
|
-
return
|
|
92
|
+
return DIRECT_DISK.sync('stat', { path: candidate }).isDirectory();
|
|
91
93
|
}
|
|
92
94
|
catch {
|
|
93
95
|
return false;
|
|
@@ -110,7 +112,7 @@ function realIsDirectory(candidate) {
|
|
|
110
112
|
* nadrzędnym), odpada. Korzeń, którego nie da się rozwiązać, zostaje w postaci leksykalnej —
|
|
111
113
|
* nieistniejący korzeń nie może rozszerzać granicy, więc jego „zawężenie" byłoby tylko szumem.
|
|
112
114
|
*/
|
|
113
|
-
export function isInsideAnyRootReal(candidate, roots, realPath =
|
|
115
|
+
export function isInsideAnyRootReal(candidate, roots, realPath = realpathOnDisk) {
|
|
114
116
|
if (!isInsideAnyRoot(candidate, roots))
|
|
115
117
|
return false;
|
|
116
118
|
let resolved;
|
|
@@ -172,7 +174,8 @@ function realPathEntersHidden(resolved, realRoots) {
|
|
|
172
174
|
* 5. the work area, still text only: a macOS-protected folder of home is refused unless a root lies in it
|
|
173
175
|
* (`config/work-area.ts`); a read there makes macOS ask for access, and this check is synchronous,
|
|
174
176
|
* 6. the symlink walk (`resolveInWorkArea`) as the first disk access: it stops before an excluded folder, so
|
|
175
|
-
* `<root>/link -> ~/Desktop/x` is refused without a read in `Desktop`; a missing segment is "not found",
|
|
177
|
+
* `<root>/link -> ~/Desktop/x` is refused without a read in `Desktop`; a missing segment is "not found", and a
|
|
178
|
+
* guarded folder the folder gate holds closed gives the sentence of its state (metadata only, no helper call),
|
|
176
179
|
* 7. musi istnieć i być katalogiem,
|
|
177
180
|
* 8. i dopiero teraz to samo pytanie po ROZWIĄZANIU dowiązań — kroki 4 i 7 same
|
|
178
181
|
* przepuszczały `<korzeń>/skrót -> /gdziekolwiek`; the resolved path must also lie outside the excluded folders,
|
|
@@ -217,7 +220,7 @@ export function validateProjectCwd(input, roots, opts = {}) {
|
|
|
217
220
|
if (!insideWorkArea(cwd, roots, home)) {
|
|
218
221
|
return { ok: false, sentence: say('rest.cwd-protected') };
|
|
219
222
|
}
|
|
220
|
-
const resolveOne = opts.realPath ??
|
|
223
|
+
const resolveOne = opts.realPath ?? realpathOnDisk;
|
|
221
224
|
const onDisk = (entry) => {
|
|
222
225
|
try {
|
|
223
226
|
return resolveOne(entry);
|
|
@@ -234,8 +237,10 @@ export function validateProjectCwd(input, roots, opts = {}) {
|
|
|
234
237
|
const walked = resolveInWorkArea(cwd, realRoots, realHome, opts.walk);
|
|
235
238
|
if (walked.kind === 'missing')
|
|
236
239
|
return { ok: false, sentence: say('rest.cwd-not-found') };
|
|
237
|
-
if (walked.kind === 'excluded')
|
|
238
|
-
|
|
240
|
+
if (walked.kind === 'excluded') {
|
|
241
|
+
// A guarded folder the folder gate holds closed: the sentence of its state, not a link that leads out.
|
|
242
|
+
return { ok: false, sentence: walked.closed?.sentence ?? say('rest.cwd-symlink-escape') };
|
|
243
|
+
}
|
|
239
244
|
resolved = walked.path;
|
|
240
245
|
}
|
|
241
246
|
if (!isDirectory(cwd)) {
|
|
@@ -243,7 +248,7 @@ export function validateProjectCwd(input, roots, opts = {}) {
|
|
|
243
248
|
}
|
|
244
249
|
if (resolved === null) {
|
|
245
250
|
try {
|
|
246
|
-
resolved = opts.realPath === undefined ?
|
|
251
|
+
resolved = opts.realPath === undefined ? realpathOnDisk(cwd) : opts.realPath(cwd);
|
|
247
252
|
}
|
|
248
253
|
catch {
|
|
249
254
|
return { ok: false, sentence: say('rest.cwd-symlink-escape') };
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
* unless a root lies in that folder (`protected-dirs.ts`). `insideWorkArea` judges text only; `resolveInWorkArea`
|
|
6
6
|
* resolves symlinks one segment at a time and stops before it would touch an excluded folder; `inWorkAreaOnDisk`
|
|
7
7
|
* puts the two together for a directory that already exists, and `inExcludedOnDisk` asks only about the excluded
|
|
8
|
-
* folders, for a directory that may lie outside the roots.
|
|
8
|
+
* folders, for a directory that may lie outside the roots. A guarded folder the folder gate holds closed is out of the
|
|
9
|
+
* work area too, unless the caller asks to ignore the gate (`WalkOptions`). The module never lists a directory and
|
|
10
|
+
* never reads a file.
|
|
9
11
|
*/
|
|
10
|
-
import { lstatSync, readlinkSync, realpathSync } from 'node:fs';
|
|
11
12
|
import path from 'node:path';
|
|
13
|
+
import { DIRECT_DISK, closedFolderOf } from '../folder-gate/disk.js';
|
|
14
|
+
import { FolderGateError } from '../folder-gate/types.js';
|
|
12
15
|
import { PROTECTED_HOME_DIRS, foldCase, inProtectedFolder, openedByRoot } from './protected-dirs.js';
|
|
13
16
|
const lower = (value) => value.toLowerCase();
|
|
14
17
|
/** Whether `candidate` is `root` or lies inside it, by path segments. */
|
|
@@ -58,7 +61,14 @@ export function insideWorkArea(cwd, roots, home) {
|
|
|
58
61
|
});
|
|
59
62
|
return inRoot && !isExcludedPath(resolved, roots, home);
|
|
60
63
|
}
|
|
61
|
-
|
|
64
|
+
/** The walk's view of the work-area disk port. */
|
|
65
|
+
export function walkDiskOf(disk) {
|
|
66
|
+
return {
|
|
67
|
+
lstat: (file) => disk.sync('lstat', { path: file }),
|
|
68
|
+
readlink: (file) => disk.sync('readlink', { path: file }),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const DISK = walkDiskOf(DIRECT_DISK);
|
|
62
72
|
/** Symlinks followed in one walk before it gives up, as `ELOOP` of the system. */
|
|
63
73
|
const MAX_LINKS = 40;
|
|
64
74
|
/**
|
|
@@ -66,9 +76,13 @@ const MAX_LINKS = 40;
|
|
|
66
76
|
* built so far is checked, and one in an excluded folder ends the walk (`excluded`) without a read there. A
|
|
67
77
|
* symlink's target is walked the same way, so `<root>/link -> ~/Desktop/x` never reaches `Desktop`. An excluded
|
|
68
78
|
* folder that holds a root (`~/Documents` on the way to the root `~/Documents/Projects`) may be passed.
|
|
69
|
-
* `missing`: a segment does not exist, cannot be checked, or the links loop.
|
|
79
|
+
* `missing`: a segment does not exist, cannot be checked, or the links loop. A segment in a guarded folder the folder
|
|
80
|
+
* gate holds closed ends the walk as `excluded` with the refusal in `closed`, before its `lstat`: the folder cannot be
|
|
81
|
+
* entered now, and a missing segment would keep the verdict of the text. The walk asks the port for it
|
|
82
|
+
* (`closedFolderOf`), because metadata passes a closed folder; a disk that refuses a segment with `FolderGateError`
|
|
83
|
+
* ends the walk the same way. With `gate: 'ignore'` the walk does not ask the gate. `roots` and `home` in on-disk form.
|
|
70
84
|
*/
|
|
71
|
-
export function resolveInWorkArea(candidate, roots, home, disk = DISK) {
|
|
85
|
+
export function resolveInWorkArea(candidate, roots, home, disk = DISK, options = {}) {
|
|
72
86
|
if (!path.isAbsolute(candidate))
|
|
73
87
|
return { kind: 'missing' };
|
|
74
88
|
// The way to a root compares in lower case, like a root opening a path (`isExcludedPath`).
|
|
@@ -90,13 +104,16 @@ export function resolveInWorkArea(candidate, roots, home, disk = DISK) {
|
|
|
90
104
|
const next = path.join(current, part);
|
|
91
105
|
if (blocked(next))
|
|
92
106
|
return { kind: 'excluded' };
|
|
107
|
+
const closed = options.gate === 'ignore' ? null : closedFolderOf(next);
|
|
108
|
+
if (closed !== null)
|
|
109
|
+
return { kind: 'excluded', closed };
|
|
93
110
|
let link = null;
|
|
94
111
|
try {
|
|
95
112
|
if (disk.lstat(next).isSymbolicLink())
|
|
96
113
|
link = disk.readlink(next);
|
|
97
114
|
}
|
|
98
|
-
catch {
|
|
99
|
-
return { kind: 'missing' };
|
|
115
|
+
catch (error) {
|
|
116
|
+
return error instanceof FolderGateError ? { kind: 'excluded', closed: error } : { kind: 'missing' };
|
|
100
117
|
}
|
|
101
118
|
if (link === null) {
|
|
102
119
|
current = next;
|
|
@@ -111,7 +128,11 @@ export function resolveInWorkArea(candidate, roots, home, disk = DISK) {
|
|
|
111
128
|
}
|
|
112
129
|
return { kind: 'resolved', path: current };
|
|
113
130
|
}
|
|
114
|
-
|
|
131
|
+
/** The area's view of the work-area disk port: `realpath` is the JavaScript walk of `realpathSync`. */
|
|
132
|
+
export function areaDiskOf(disk) {
|
|
133
|
+
return { ...walkDiskOf(disk), realpath: (file) => disk.sync('realpath', { path: file }) };
|
|
134
|
+
}
|
|
135
|
+
const AREA_DISK = areaDiskOf(DIRECT_DISK);
|
|
115
136
|
/**
|
|
116
137
|
* Roots and home in on-disk form, the reference points of a walk: a root that is a symlink (`/srv/home -> ~`) counts
|
|
117
138
|
* where it leads. Only they go through `realpath`, never a folder inside them; one that does not resolve stays as given.
|
|
@@ -136,13 +157,15 @@ export function onDiskForms(roots, home, realpath = AREA_DISK.realpath) {
|
|
|
136
157
|
* meets the whole rule once more there, so `<root>/link -> ~/Desktop/x`, `<root ~>/visible -> ~/.cache/x` and a root
|
|
137
158
|
* that is a symlink to home (`/srv/home/Desktop`) stay out without a read in the excluded folder. A path the walk
|
|
138
159
|
* cannot resolve (deleted, unreadable, a loop of links) keeps the verdict of its text, because nothing can be read
|
|
139
|
-
* through it; a link that leads out of every root keeps it too, unless it ends in an excluded folder.
|
|
160
|
+
* through it; a link that leads out of every root keeps it too, unless it ends in an excluded folder. A guarded folder
|
|
161
|
+
* the folder gate holds closed on the way puts the path out of the work area until the folder opens, unless `options`
|
|
162
|
+
* ignore the gate ({@link WalkOptions}).
|
|
140
163
|
*/
|
|
141
|
-
export function inWorkAreaOnDisk(cwd, roots, home, disk = AREA_DISK) {
|
|
164
|
+
export function inWorkAreaOnDisk(cwd, roots, home, disk = AREA_DISK, options = {}) {
|
|
142
165
|
const real = onDiskForms(roots, home, disk.realpath);
|
|
143
166
|
if (!insideWorkArea(cwd, [...roots, ...real.roots], home))
|
|
144
167
|
return false;
|
|
145
|
-
const walked = resolveInWorkArea(cwd, real.roots, real.home, disk);
|
|
168
|
+
const walked = resolveInWorkArea(cwd, real.roots, real.home, disk, options);
|
|
146
169
|
if (walked.kind !== 'resolved')
|
|
147
170
|
return walked.kind === 'missing';
|
|
148
171
|
const inRoots = real.roots.some((root) => path.isAbsolute(root) && isWithin(walked.path, path.resolve(root)));
|
|
@@ -156,7 +179,8 @@ export function inWorkAreaOnDisk(cwd, roots, home, disk = AREA_DISK) {
|
|
|
156
179
|
* resolve before the text check, never `cwd`, and a root counts in both forms: one that is a symlink into a protected
|
|
157
180
|
* folder (`/srv/code -> ~/Desktop/project`) opens the physical path a pane reports. Then the walk
|
|
158
181
|
* ({@link resolveInWorkArea}), which stops before an excluded folder, and the excluded folders once more on the path
|
|
159
|
-
* it resolves to. A path the walk cannot resolve is not excluded: nothing can be read through it.
|
|
182
|
+
* it resolves to. A path the walk cannot resolve is not excluded: nothing can be read through it. A guarded folder
|
|
183
|
+
* the folder gate holds closed on the way counts as excluded, so git does not run there.
|
|
160
184
|
*/
|
|
161
185
|
export function inExcludedOnDisk(cwd, roots, home, disk = AREA_DISK) {
|
|
162
186
|
const real = onDiskForms(roots, home, disk.realpath);
|
package/server/src/config-env.js
CHANGED
|
@@ -182,6 +182,14 @@ export const CONSENT_RESTART_GRACE_ENV = 'RAROG_CONSENT_RESTART_GRACE';
|
|
|
182
182
|
* wysyła, więc to NIE jest szósty killswitch. Flaga kanału zgody jej nie zmienia i odwrotnie.
|
|
183
183
|
*/
|
|
184
184
|
export const DIALOG_LAYER2_ENV = 'RAROG_DIALOG_LAYER2';
|
|
185
|
+
/**
|
|
186
|
+
* Folder gate kill switch (`docs/macos-folders.md`): missing or empty = on on macOS and off elsewhere, `1` = on,
|
|
187
|
+
* `0` = off; any other value is a config error at start, also in the demo, which never runs the gate. On, a disk call
|
|
188
|
+
* of the work area in Desktop, Documents or Downloads (and any other guarded folder of home) runs in a helper
|
|
189
|
+
* process the server can kill, so a macOS consent window waits there instead of in the server. Off = every call in
|
|
190
|
+
* the server process, without helpers or the relay thread. It approves and sends nothing.
|
|
191
|
+
*/
|
|
192
|
+
export const FOLDER_GATE_ENV = 'RAROG_FOLDER_GATE';
|
|
185
193
|
/**
|
|
186
194
|
* SSE STREAM COMPRESSION flag: missing, empty or `1` = the server gzips the stream when the client sent
|
|
187
195
|
* `Accept-Encoding` with `gzip` at a weight above zero; `0` = no compression for any client; any other value is a
|
|
@@ -392,6 +400,7 @@ export const SERVER_ENV = {
|
|
|
392
400
|
[CONSENT_ALWAYS_ENV]: 'plain',
|
|
393
401
|
[CONSENT_RESTART_GRACE_ENV]: 'plain',
|
|
394
402
|
[DIALOG_LAYER2_ENV]: 'plain',
|
|
403
|
+
[FOLDER_GATE_ENV]: 'plain',
|
|
395
404
|
[SSE_GZIP_ENV]: 'plain',
|
|
396
405
|
[COMPANION_ENV]: 'plain',
|
|
397
406
|
[COMPANION_SESSIONS_ENV]: 'plain',
|
package/server/src/config.js
CHANGED
|
@@ -15,7 +15,7 @@ import path from 'node:path';
|
|
|
15
15
|
import { MAX_TRANSCRIPT_MESSAGES } from '@rarog/shared';
|
|
16
16
|
import { BUNDLE_ID_RE } from '@rarog/shared/rest';
|
|
17
17
|
import { dataDirConflictMessage, resolveDataDir } from '@rarog/shared/data-dir';
|
|
18
|
-
import { AGENT_FILES_ENV, APNS_ENV_NAMES, APNS_KEY_ID_ENV, APNS_KEY_PATH_ENV, APNS_TEAM_ID_ENV, APNS_TOPIC_ENV, CLAUDE_ENV_CLEAR_ENV, ConfigError, CLI_WAITING_ENV, CODEX_STATUS_ENV, COMPANION_ENV, COMPANION_MODEL_ENV, COMPANION_SESSIONS_ENV, COMPANION_ENV_PASSTHROUGH, CONSENT_CHANNEL_ENV, CONSENT_PROOF_ENV, CONSENT_ALWAYS_ENV, CONSENT_RESTART_GRACE_ENV, DEMO_CONTENT_ENV, DEMO_LANG_ENV, DEMO_REVIEW_CODE_ENV, DIALOG_LAYER2_ENV, GIT_ENV_PASSTHROUGH, GIT_ENV_PREFIX, GIT_FILE_DETAILS_ENV, HERDR_BIN_ENV, HERDR_LAUNCH_ENV, HERDR_ROOTS_ENV, HERDR_SEEN_FOCUS_ENV, HERDR_SEND_ENV, HERDR_SOCKET_ENV, HERDR_TAB_LABELS_ENV, INBOX_ENV, FILES_ENV, FILES_MAX_MB_ENV, IROH_ENV, IROH_KEY_ENV, IROH_PORT_ENV, IROH_RELAY_ENV, MAX_PANES_ENV, MIN_CLIENT_BUILD_ENV, NOTES_ENV, PROJECT_ROOTS_ENV, PROMPT_BLOCK_ENV, PUSH_E2E_ENV, PUSH_ENV, PR_STATUS_ENV, PR_STATUS_ENV_PASSTHROUGH, PUSH_RELAY_URL_ENV, QUEUE_ECHO_ENV, REFUSAL_DUMPS_ENV, SONIOX_API_HOST_ENV, SONIOX_API_KEY_ENV, OPENAI_API_KEY_ENV, SSE_GZIP_ENV, TALL_DIALOG_GUARD_ENV, TERM_ENV, TERM_ENV_PASSTHROUGH, TERM_IDLE_DAYS_ENV, TERM_MAX_ENV, VOICE_ENV, YOLO_ROOTS_ENV, readEnv, } from './config-env.js';
|
|
18
|
+
import { AGENT_FILES_ENV, APNS_ENV_NAMES, APNS_KEY_ID_ENV, APNS_KEY_PATH_ENV, APNS_TEAM_ID_ENV, APNS_TOPIC_ENV, CLAUDE_ENV_CLEAR_ENV, ConfigError, CLI_WAITING_ENV, CODEX_STATUS_ENV, COMPANION_ENV, COMPANION_MODEL_ENV, COMPANION_SESSIONS_ENV, COMPANION_ENV_PASSTHROUGH, CONSENT_CHANNEL_ENV, CONSENT_PROOF_ENV, CONSENT_ALWAYS_ENV, CONSENT_RESTART_GRACE_ENV, DEMO_CONTENT_ENV, DEMO_LANG_ENV, DEMO_REVIEW_CODE_ENV, DIALOG_LAYER2_ENV, FOLDER_GATE_ENV, GIT_ENV_PASSTHROUGH, GIT_ENV_PREFIX, GIT_FILE_DETAILS_ENV, HERDR_BIN_ENV, HERDR_LAUNCH_ENV, HERDR_ROOTS_ENV, HERDR_SEEN_FOCUS_ENV, HERDR_SEND_ENV, HERDR_SOCKET_ENV, HERDR_TAB_LABELS_ENV, INBOX_ENV, FILES_ENV, FILES_MAX_MB_ENV, IROH_ENV, IROH_KEY_ENV, IROH_PORT_ENV, IROH_RELAY_ENV, MAX_PANES_ENV, MIN_CLIENT_BUILD_ENV, NOTES_ENV, PROJECT_ROOTS_ENV, PROMPT_BLOCK_ENV, PUSH_E2E_ENV, PUSH_ENV, PR_STATUS_ENV, PR_STATUS_ENV_PASSTHROUGH, PUSH_RELAY_URL_ENV, QUEUE_ECHO_ENV, REFUSAL_DUMPS_ENV, SONIOX_API_HOST_ENV, SONIOX_API_KEY_ENV, OPENAI_API_KEY_ENV, SSE_GZIP_ENV, TALL_DIALOG_GUARD_ENV, TERM_ENV, TERM_ENV_PASSTHROUGH, TERM_IDLE_DAYS_ENV, TERM_MAX_ENV, VOICE_ENV, YOLO_ROOTS_ENV, readEnv, } from './config-env.js';
|
|
19
19
|
import { RAROG_VERSION } from './version.js';
|
|
20
20
|
import { INSTALL_MODE } from './install/mode.js';
|
|
21
21
|
import { DEVICES_FILENAME, activeDeviceEpochs } from './auth/devices-store.js';
|
|
@@ -528,6 +528,20 @@ export function parseDialogLayer2(raw) {
|
|
|
528
528
|
return true;
|
|
529
529
|
throw new ConfigError(`${DIALOG_LAYER2_ENV} takes 1 or 0 (got: ${value}).`);
|
|
530
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* The folder gate flag: missing or empty = the platform decides (on on macOS, where the consent windows are), `1` = on,
|
|
533
|
+
* `0` = off; any other value stops the start, so a typo never leaves the server in another mode than the owner meant.
|
|
534
|
+
*/
|
|
535
|
+
export function parseFolderGate(raw, platform) {
|
|
536
|
+
const value = raw?.trim() ?? '';
|
|
537
|
+
if (value === '')
|
|
538
|
+
return platform === 'darwin';
|
|
539
|
+
if (value === '1')
|
|
540
|
+
return true;
|
|
541
|
+
if (value === '0')
|
|
542
|
+
return false;
|
|
543
|
+
throw new ConfigError(`${FOLDER_GATE_ENV} takes 1 or 0 (got: ${value}).`);
|
|
544
|
+
}
|
|
531
545
|
/** Strażnik wysokości dialogu; brak wartości = WŁĄCZONY, `0`/`false` wyłącza. */
|
|
532
546
|
export function parseTallDialogGuard(raw) {
|
|
533
547
|
if (raw === undefined || raw.trim() === '')
|
|
@@ -707,6 +721,8 @@ export function loadConfig(env = process.env, mode = INSTALL_MODE) {
|
|
|
707
721
|
consentRestartGraceMs: parseConsentRestartGrace(readEnv(env, CONSENT_RESTART_GRACE_ENV)),
|
|
708
722
|
// W demo bez skutku (mock nie ma drivera herdr), ale zła wartość zatrzymuje start tak samo.
|
|
709
723
|
dialogLayer2: parseDialogLayer2(readEnv(env, DIALOG_LAYER2_ENV)),
|
|
724
|
+
// Off in demo unconditionally: the demo reads nothing of the host's folders; a wrong value stops the start there.
|
|
725
|
+
folderGate: parseFolderGate(readEnv(env, FOLDER_GATE_ENV), process.platform) && !demo,
|
|
710
726
|
sseGzip: parseSseGzip(readEnv(env, SSE_GZIP_ENV)),
|
|
711
727
|
// Off in demo unconditionally; a wrong value still stops the start there.
|
|
712
728
|
companionEnabled: parseCompanionEnabled(readEnv(env, COMPANION_ENV)) && !demo,
|
|
@@ -546,7 +546,15 @@ export function createDemoControl(router, config, manager, panels, notes) {
|
|
|
546
546
|
return true;
|
|
547
547
|
}
|
|
548
548
|
const handler = (req, res) => {
|
|
549
|
-
|
|
549
|
+
let url;
|
|
550
|
+
try {
|
|
551
|
+
url = new URL(req.url ?? '/', 'http://127.0.0.1');
|
|
552
|
+
}
|
|
553
|
+
catch {
|
|
554
|
+
// A target `URL` rejects would end the process here; the router answers it with its 400.
|
|
555
|
+
router(req, res);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
550
558
|
const pathname = url.pathname;
|
|
551
559
|
if (pathname === '/api/demo/control') {
|
|
552
560
|
controlChain = controlChain.then(() => control(req, res)).catch(() => {
|
|
@@ -13,8 +13,21 @@ export const NO_HOOK_GRACE_MS = 3_000;
|
|
|
13
13
|
* flap. Past the budget the episode stays judged and gets no line.
|
|
14
14
|
*/
|
|
15
15
|
export const NO_HOOK_EVALUATIONS = 3;
|
|
16
|
+
/**
|
|
17
|
+
* How long past the grace a card waits for the first judgement ({@link NoHookStanding.pending}): `ps` gives up after
|
|
18
|
+
* 1 s, but a facts read that hangs must not keep the card from the phone. Past it the card goes out without the
|
|
19
|
+
* emergency button, and a judgement that ends later can still give it to the same card.
|
|
20
|
+
*/
|
|
21
|
+
export const NO_HOOK_JUDGE_WAIT_MS = 2_000;
|
|
16
22
|
/** Reads of the session facts per episode: a read that ends on another process or `cwd` gives none and goes again. */
|
|
17
23
|
const FACTS_READS = 2;
|
|
24
|
+
/**
|
|
25
|
+
* Judgements after the first, at a registry signal at most once per {@link NO_HOOK_REJUDGE_MS}, while the hook process
|
|
26
|
+
* stands in `ps` or the hook list is in doubt: the same card gets the emergency button once the fact mends. Past the
|
|
27
|
+
* budget (about a minute of signals) the doubt stays and the card stays without it.
|
|
28
|
+
*/
|
|
29
|
+
export const NO_HOOK_REJUDGE_MAX = 40;
|
|
30
|
+
export const NO_HOOK_REJUDGE_MS = 1_000;
|
|
18
31
|
/** Card identities remembered for the `no approve button` line; past the cap the memory starts again. */
|
|
19
32
|
const BUTTONLESS_MAX = 256;
|
|
20
33
|
let episodes = 0;
|
|
@@ -83,6 +96,7 @@ export class ConsentNoHook {
|
|
|
83
96
|
id: `no-hook:${String(episodes)}`, sessionId, blockSeq: this.#port.blockedSeq(), t0, openedAt: now,
|
|
84
97
|
since: this.#since, callId: undefined, print: undefined, tool: card.active.toolName, screenButton: false,
|
|
85
98
|
thread: 'main', waiting: this.#port.cliWaiting() === 'permission', timer: null, evaluations: 0, state: 'grace',
|
|
99
|
+
judgement: null, restarting: false, judging: false, rejudged: 0, judgedAt: 0,
|
|
86
100
|
};
|
|
87
101
|
this.#describe(episode, card);
|
|
88
102
|
this.#episode = episode;
|
|
@@ -91,8 +105,33 @@ export class ConsentNoHook {
|
|
|
91
105
|
if (episode.state === 'grace')
|
|
92
106
|
episode.state = 'due';
|
|
93
107
|
this.#observe(() => { this.#judge(episode); });
|
|
108
|
+
this.#judged();
|
|
109
|
+
// A first judgement still reading its facts at the end of the wait lets the card go.
|
|
110
|
+
if (episode.judging && episode.state !== 'ended') {
|
|
111
|
+
episode.timer = this.#scheduler.setTimeout(() => {
|
|
112
|
+
episode.timer = null;
|
|
113
|
+
this.#judged();
|
|
114
|
+
}, NO_HOOK_JUDGE_WAIT_MS);
|
|
115
|
+
}
|
|
94
116
|
}, Math.max(0, t0 + NO_HOOK_GRACE_MS - now));
|
|
95
117
|
}
|
|
118
|
+
/** The standing episode, `null` without one; never throws. */
|
|
119
|
+
standing() {
|
|
120
|
+
try {
|
|
121
|
+
const episode = this.#episode;
|
|
122
|
+
if (episode === null || !this.#stands(episode))
|
|
123
|
+
return null;
|
|
124
|
+
return {
|
|
125
|
+
id: episode.id, sessionId: episode.sessionId, judgement: episode.judgement,
|
|
126
|
+
pending: episode.state === 'grace' || (episode.judging && episode.judgement === null
|
|
127
|
+
&& this.#scheduler.now() < episode.t0 + NO_HOOK_GRACE_MS + NO_HOOK_JUDGE_WAIT_MS),
|
|
128
|
+
t0: this.#epochOf(episode.t0), since: episode.since, graceEnd: episode.t0 + NO_HOOK_GRACE_MS,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
96
135
|
/**
|
|
97
136
|
* A card that goes out: when the channel gate took its approve button (the `off` path card would have it), one
|
|
98
137
|
* `consent: no approve button` line per card identity.
|
|
@@ -137,6 +176,27 @@ export class ConsentNoHook {
|
|
|
137
176
|
episode.waiting = true;
|
|
138
177
|
if (episode.state === 'due')
|
|
139
178
|
this.#judge(episode);
|
|
179
|
+
else if (this.#mendable(episode))
|
|
180
|
+
this.#rejudge(episode);
|
|
181
|
+
else if (episode.state === 'judged' && !episode.judging && episode.restarting && !this.#restarting()) {
|
|
182
|
+
// The restart grace ended past the judgement: no fact to read again, only the button to ask again.
|
|
183
|
+
episode.restarting = false;
|
|
184
|
+
this.#judged();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** A judged episode whose `ps` or hook list refuses the button, with budget and pause left, and no read running. */
|
|
188
|
+
#mendable(episode) {
|
|
189
|
+
const judgement = episode.judgement;
|
|
190
|
+
return episode.state === 'judged' && judgement !== null && !episode.judging
|
|
191
|
+
&& (judgement.hookRunning !== false || judgement.foreignHook !== false)
|
|
192
|
+
&& episode.rejudged < NO_HOOK_REJUDGE_MAX && this.#scheduler.now() - episode.judgedAt >= NO_HOOK_REJUDGE_MS;
|
|
193
|
+
}
|
|
194
|
+
#rejudge(episode) {
|
|
195
|
+
const sources = this.#deps.consentNoHook;
|
|
196
|
+
if (sources === undefined || !this.#stands(episode) || this.#traced(sources, episode))
|
|
197
|
+
return;
|
|
198
|
+
episode.rejudged += 1;
|
|
199
|
+
void this.#judgeFacts(sources, episode, false).catch((err) => { this.#failed(err); });
|
|
140
200
|
}
|
|
141
201
|
/**
|
|
142
202
|
* `drop` hands the effective block over within one block (herdr's own `blocked` follows the CLI registry
|
|
@@ -239,9 +299,26 @@ export class ConsentNoHook {
|
|
|
239
299
|
if (this.#traced(sources, episode))
|
|
240
300
|
return;
|
|
241
301
|
episode.evaluations += 1;
|
|
242
|
-
void this.#judgeFacts(sources, episode).catch((err) => { this.#failed(err); });
|
|
302
|
+
void this.#judgeFacts(sources, episode, true).catch((err) => { this.#failed(err); });
|
|
243
303
|
}
|
|
244
|
-
|
|
304
|
+
/** The first judgement writes the `no hook` line; a later one only renews the facts of the emergency button. */
|
|
305
|
+
async #judgeFacts(sources, episode, first) {
|
|
306
|
+
episode.judging = true;
|
|
307
|
+
try {
|
|
308
|
+
await this.#judgeOnce(sources, episode, first);
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
episode.judging = false;
|
|
312
|
+
episode.judgedAt = this.#scheduler.now();
|
|
313
|
+
// The first judgement ended: the wait it had (grace timer callback) is over.
|
|
314
|
+
if (first && episode.timer !== null) {
|
|
315
|
+
this.#scheduler.clearTimeout(episode.timer);
|
|
316
|
+
episode.timer = null;
|
|
317
|
+
}
|
|
318
|
+
this.#judged();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async #judgeOnce(sources, episode, first) {
|
|
245
322
|
let facts = null;
|
|
246
323
|
for (let read = 0; read < FACTS_READS && facts === null; read += 1) {
|
|
247
324
|
facts = await sources.facts({ sessionId: episode.sessionId, episode: episode.id }).catch(() => null);
|
|
@@ -257,18 +334,23 @@ export class ConsentNoHook {
|
|
|
257
334
|
if (this.#episode !== episode || !this.#stands(episode) || this.#traced(sources, episode))
|
|
258
335
|
return;
|
|
259
336
|
if (!consentChannelOpen(consentModeNow(this.#deps)) || this.#port.cliWaiting() !== 'permission') {
|
|
260
|
-
if (episode.evaluations < NO_HOOK_EVALUATIONS)
|
|
337
|
+
if (first && episode.evaluations < NO_HOOK_EVALUATIONS)
|
|
261
338
|
episode.state = 'due';
|
|
262
339
|
return;
|
|
263
340
|
}
|
|
264
341
|
const layers = facts?.layers ?? null;
|
|
342
|
+
const cause = noHookCause({
|
|
343
|
+
hookRunning, outsideWorkArea: this.#outsideWorkArea(sources, facts?.cwd ?? null),
|
|
344
|
+
disableAllHooks: layers?.disableAllHooks ?? null, allowManagedHooksOnly: layers?.allowManagedHooksOnly ?? null,
|
|
345
|
+
rarogEntry: layers?.rarogEntry ?? null,
|
|
346
|
+
});
|
|
347
|
+
episode.judgement = { cause, hookRunning, foreignHook: facts?.foreignHook ?? null };
|
|
348
|
+
episode.restarting = this.#restarting();
|
|
349
|
+
if (!first)
|
|
350
|
+
return;
|
|
265
351
|
this.#log(noHookLine({
|
|
266
352
|
sessionId: episode.sessionId,
|
|
267
|
-
cause
|
|
268
|
-
hookRunning, outsideWorkArea: this.#outsideWorkArea(sources, facts?.cwd ?? null),
|
|
269
|
-
disableAllHooks: layers?.disableAllHooks ?? null, allowManagedHooksOnly: layers?.allowManagedHooksOnly ?? null,
|
|
270
|
-
rarogEntry: layers?.rarogEntry ?? null,
|
|
271
|
-
}),
|
|
353
|
+
cause,
|
|
272
354
|
tool: episode.tool, cli: this.#port.cliVersion(), mode: this.#port.permissionMode(), thread: episode.thread,
|
|
273
355
|
afterMs: this.#scheduler.now() - episode.t0, hooks: facts?.verdict ?? null, statusline,
|
|
274
356
|
screenButton: episode.screenButton,
|
|
@@ -302,6 +384,15 @@ export class ConsentNoHook {
|
|
|
302
384
|
const screen = this.#port.screenText();
|
|
303
385
|
return screen !== null && subagentDialogOnScreen(screen) ? 'subagent' : 'main';
|
|
304
386
|
}
|
|
387
|
+
/** The server is within its restart grace; an exception counts as within. */
|
|
388
|
+
#restarting() {
|
|
389
|
+
try {
|
|
390
|
+
return this.#deps.consentNoHook?.restarting() ?? false;
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
305
396
|
#proofRules(sessionId) {
|
|
306
397
|
try {
|
|
307
398
|
return this.#deps.consentNoHook?.proofRules(sessionId) ?? null;
|
|
@@ -313,4 +404,8 @@ export class ConsentNoHook {
|
|
|
313
404
|
#log(line) {
|
|
314
405
|
this.#deps.logger?.(line);
|
|
315
406
|
}
|
|
407
|
+
/** Tells the port that the judgement changed; its failure stays here. */
|
|
408
|
+
#judged() {
|
|
409
|
+
this.#observe(() => { this.#port.judged?.(); });
|
|
410
|
+
}
|
|
316
411
|
}
|