@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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consent without a hook: the cause why a tool permission dialog in channel mode got no trace of Rarog's
|
|
3
|
+
* `PermissionRequest` hook, the two log lines that name it, and whether the card of the `off` path would carry the
|
|
4
|
+
* approve button. Pure functions over explicit arguments: the driver module `drivers/herdr/consent-no-hook.ts` gathers
|
|
5
|
+
* the facts and writes the lines. Nothing here gives or takes a button; the card stays as the decision built it.
|
|
6
|
+
*/
|
|
7
|
+
import { cardShowsAll } from '../../drivers/tool-text.js';
|
|
8
|
+
import { hookListWhyCode } from './layer1/hook-list/hook-list.js';
|
|
9
|
+
/** Causes in the order they are checked: the first that holds names the dialog. */
|
|
10
|
+
export const NO_HOOK_CAUSES = [
|
|
11
|
+
'hook-running', 'outside-work-area', 'hooks-disabled', 'not-in-session-hooks', 'unexplained',
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* The first cause that holds: the hook process runs without a registration; the session `cwd` lies outside the work
|
|
15
|
+
* area; hooks are off by settings; the session's settings layers have no Rarog entry; otherwise `unexplained` (the CLI
|
|
16
|
+
* did not call the hook, or the hook left quietly for a reason the server cannot see). Only a certain value decides:
|
|
17
|
+
* the layer read is a superset, so only `rarogEntry: false` is sure, and only a `true` turns hooks off.
|
|
18
|
+
*/
|
|
19
|
+
export function noHookCause(facts) {
|
|
20
|
+
if (facts.hookRunning === true)
|
|
21
|
+
return 'hook-running';
|
|
22
|
+
if (facts.outsideWorkArea === true)
|
|
23
|
+
return 'outside-work-area';
|
|
24
|
+
if (facts.disableAllHooks === true || facts.allowManagedHooksOnly === true)
|
|
25
|
+
return 'hooks-disabled';
|
|
26
|
+
if (facts.rarogEntry === false)
|
|
27
|
+
return 'not-in-session-hooks';
|
|
28
|
+
return 'unexplained';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether the card the `off` path shows would carry the approve button by today's rules: a consent card the driver
|
|
32
|
+
* understood (`input`), with the button (`canAllow`), whose whole text the card shows (`cardShowsAll`, the manager's
|
|
33
|
+
* rule for the button). Read from the card before the channel gate (`consentOnlyEvent`), which does not change it.
|
|
34
|
+
*/
|
|
35
|
+
export function offPathApprove(event) {
|
|
36
|
+
return event.type === 'permission-request' && event.input !== null && event.canAllow !== false
|
|
37
|
+
&& cardShowsAll(event.displayText, event.truncation);
|
|
38
|
+
}
|
|
39
|
+
/** Characters a log value may carry: an identifier, a name or a version, never a path, a command or free text. */
|
|
40
|
+
const TOKEN = /^[A-Za-z0-9_.:+-]{1,80}$/;
|
|
41
|
+
/** A value fit for a log line, or `?` for anything else (unknown, empty, a path, spaces, separators). */
|
|
42
|
+
export function logToken(value) {
|
|
43
|
+
return typeof value === 'string' && TOKEN.test(value) ? value : '?';
|
|
44
|
+
}
|
|
45
|
+
/** The hook list verdict as a log value: `ok` or the code of its reason, never the file it names; `?` without one. */
|
|
46
|
+
export function hooksToken(verdict) {
|
|
47
|
+
if (verdict === null)
|
|
48
|
+
return '?';
|
|
49
|
+
return verdict.ok ? 'ok' : logToken(hookListWhyCode(verdict.why));
|
|
50
|
+
}
|
|
51
|
+
/** `consent: no hook — …`, one per consent dialog episode without a hook trace. */
|
|
52
|
+
export function noHookLine(line) {
|
|
53
|
+
return `consent: no hook — session ${logToken(line.sessionId)}, cause ${line.cause}, tool ${logToken(line.tool)}, `
|
|
54
|
+
+ `cli ${logToken(line.cli)}, mode ${logToken(line.mode)}, thread ${line.thread}, `
|
|
55
|
+
+ `after ${String(Math.max(0, Math.round(line.afterMs)))} ms, hooks ${hooksToken(line.hooks)}, `
|
|
56
|
+
+ `statusline ${line.statusline}, screen-button ${line.screenButton ? 'yes' : 'no'}`;
|
|
57
|
+
}
|
|
58
|
+
/** `consent: no approve button — …`, one per card identity whose approve button the channel gate took. */
|
|
59
|
+
export function noApproveButtonLine(line) {
|
|
60
|
+
return `consent: no approve button — session ${logToken(line.sessionId)}, reason ${logToken(line.reason)}, `
|
|
61
|
+
+ `tool ${logToken(line.tool)}, channel ${logToken(line.channel)}, rule ${logToken(line.rule)}, `
|
|
62
|
+
+ `cli ${logToken(line.cli)}`;
|
|
63
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HOOK_PERMISSION_REQUEST_EVENT, HOOK_QUESTION_TOOL } from './hook/contract.js';
|
|
2
|
+
import { screenFallbackHolds } from './screen-fallback.js';
|
|
2
3
|
import { askFormOnScreen, cliDialogOnScreen } from './presence.js';
|
|
3
4
|
/**
|
|
4
5
|
* Werdykt rozdzielacza — ZAMKNIĘTA lista, bo wpisy dziennika mają się sumować:
|
|
@@ -93,16 +94,14 @@ const KNOWN_DIALOG_CARD_TOOLS = new Set(['dialog:trust', 'dialog:model']);
|
|
|
93
94
|
* z ekranu, które bywa zgodą `WebFetch`) tylko przy klasie `input` albo `dialog` z rejestru. Przy `off` i `shadow`
|
|
94
95
|
* nic się nie zmienia. Klawisz `escape` (odmowa) tej bramki nie przechodzi: niczego nie zatwierdza.
|
|
95
96
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* and the driver still checks the mark on a fresh screen and the registry right before the key.
|
|
97
|
+
* Two exceptions ({@link consentDigitException}) let the "Yes" button through; the driver checks each again on a fresh
|
|
98
|
+
* screen and the registry right before the key.
|
|
99
99
|
*/
|
|
100
100
|
export function consentDigitBlocked(input) {
|
|
101
101
|
if (input.mode === 'off' || input.mode === 'shadow')
|
|
102
102
|
return false;
|
|
103
|
-
if (input.cliDialog === 'permission' || input.cliDialog === 'sandbox')
|
|
104
|
-
return
|
|
105
|
-
}
|
|
103
|
+
if (input.cliDialog === 'permission' || input.cliDialog === 'sandbox')
|
|
104
|
+
return consentDigitException(input) === null;
|
|
106
105
|
if (KNOWN_DIALOG_CARD_TOOLS.has(input.toolName))
|
|
107
106
|
return false;
|
|
108
107
|
if (input.consent)
|
|
@@ -111,6 +110,22 @@ export function consentDigitBlocked(input) {
|
|
|
111
110
|
return false;
|
|
112
111
|
return input.cliDialog !== 'input' && input.cliDialog !== 'dialog';
|
|
113
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* The exception that lets the "Yes" button of a `permission` or `sandbox` card through in channel mode, or `null`:
|
|
115
|
+
* a measured consent mark under the same registry class (sandbox network, MCP tool with user interaction: neither has
|
|
116
|
+
* a working hook answer), else the emergency mark of a `permission` dialog without a hook, by the rule of
|
|
117
|
+
* `screen-fallback.ts` under the live mode and class. Never for an answer (`consent: false`).
|
|
118
|
+
*/
|
|
119
|
+
export function consentDigitException(input) {
|
|
120
|
+
if (!input.consent)
|
|
121
|
+
return null;
|
|
122
|
+
if (input.measured !== undefined && input.measured.cliDialog === input.cliDialog)
|
|
123
|
+
return 'measured';
|
|
124
|
+
if (input.fallback !== undefined && screenFallbackHolds(input.fallback, input.mode, input.cliDialog)) {
|
|
125
|
+
return 'screen-fallback';
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
114
129
|
/**
|
|
115
130
|
* The hook dump as router input: only a tool permission request dump matters, i.e. the `PermissionRequest`
|
|
116
131
|
* event (the CLI is about to ask) for a tool other than the question form. A `PreToolUse` dump (the tool input
|
|
@@ -182,6 +182,16 @@ export function fileDialogTitle(block) {
|
|
|
182
182
|
return 'edit';
|
|
183
183
|
return block.title.tool === 'Write' ? 'write' : null;
|
|
184
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Whether the block's own title line (the line under its top rule, {@link DialogBlock.titleLine}) ends with the subagent
|
|
187
|
+
* suffix (` · from the Explore agent`). Only that line counts, never a line of the transcript above the block; an
|
|
188
|
+
* ambiguous block or one without a known title is not a subagent's.
|
|
189
|
+
*/
|
|
190
|
+
export function blockFromSubagent(lines, block) {
|
|
191
|
+
if (block.ambiguous || block.titleLine < 0)
|
|
192
|
+
return false;
|
|
193
|
+
return SUBAGENT_TITLE_SUFFIX.test(unbox(lines[block.titleLine] ?? ''));
|
|
194
|
+
}
|
|
185
195
|
/** Pierwsza niepusta linia pod kreską `rule`, przed `limit`, bez krawędzi ramki `╭──╮`; `-1` = brak. */
|
|
186
196
|
export function lineBelow(lines, rule, limit) {
|
|
187
197
|
for (let i = rule + 1; i < limit; i += 1) {
|
|
@@ -24,7 +24,7 @@ import { trimmedLines } from './text.js';
|
|
|
24
24
|
import { DIALOG_TAIL_LINES, blockTopOf, dialogRegions, framedDialogText } from './region.js';
|
|
25
25
|
import { OPTION_LINE_PATTERN, guideMap, isCompleteOptionSet, optionsCloseRegion, optionsIn, selectedOptionIn, selectedWithLabel, unbox, unframe, } from './options.js';
|
|
26
26
|
import { contentEscalates } from '../policy/escalation.js';
|
|
27
|
-
import { dialogBlock, fileDialogTitle, lineBelow, regionCallTrace, toolNaming } from './block.js';
|
|
27
|
+
import { blockFromSubagent, dialogBlock, fileDialogTitle, lineBelow, regionCallTrace, toolNaming, } from './block.js';
|
|
28
28
|
import { PLAN_DIALOG_PATTERN, PLAN_EXIT_CONFIRM_PATTERN, SANDBOX_NETWORK_TOOL, dialogKind } from './kinds.js';
|
|
29
29
|
import { FORM_IDENTITY } from './identity.js';
|
|
30
30
|
import { blockKnownDialog } from './known.js';
|
|
@@ -38,6 +38,30 @@ export function screenOnlyDialog(text) {
|
|
|
38
38
|
const dialog = parseOptions(text);
|
|
39
39
|
return dialog !== null && dialog.toolName === SANDBOX_NETWORK_TOOL;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Whether the dialog standing on screen is a subagent's: the title line of its block carries the subagent suffix
|
|
43
|
+
* ({@link blockFromSubagent}). No dialog with a complete option list = not a subagent's.
|
|
44
|
+
*/
|
|
45
|
+
export function subagentDialogOnScreen(text) {
|
|
46
|
+
const lines = trimmedLines(text);
|
|
47
|
+
const found = optionRegion(lines);
|
|
48
|
+
return found !== null && blockFromSubagent(lines, dialogBlock(lines, found.firstOption));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The thread of the dialog standing on screen, read from the title line of its block: `subagent` with the subagent
|
|
52
|
+
* suffix, `main` without it, `null` when no title line can be read (no complete option list, an ambiguous block, the
|
|
53
|
+
* title above the pane edge), so that a missing suffix is never taken for the main thread.
|
|
54
|
+
*/
|
|
55
|
+
export function dialogThreadOnScreen(text) {
|
|
56
|
+
const lines = trimmedLines(text);
|
|
57
|
+
const found = optionRegion(lines);
|
|
58
|
+
if (found === null)
|
|
59
|
+
return null;
|
|
60
|
+
const block = dialogBlock(lines, found.firstOption);
|
|
61
|
+
if (block.ambiguous || block.titleLine < 0)
|
|
62
|
+
return null;
|
|
63
|
+
return blockFromSubagent(lines, block) ? 'subagent' : 'main';
|
|
64
|
+
}
|
|
41
65
|
/**
|
|
42
66
|
* Region opcji, z którego czyta {@link parseOptions}: pierwszy kandydat (od najwęższego), który widzi
|
|
43
67
|
* spójną i KOMPLETNĄ listę opcji `1…N`; `null`, gdy żaden.
|
|
@@ -123,9 +147,15 @@ export function parseOptions(text, opts) {
|
|
|
123
147
|
* line of its own. The call trace in the region (`regionCallTrace`) guards the reverse mistake:
|
|
124
148
|
* a signature sentence above a real consent dialog may not rename it to `ExitPlanMode`. The
|
|
125
149
|
* sandbox network dialog is recognised by the block TITLE, under the same condition.
|
|
150
|
+
*
|
|
151
|
+
* The signature sentence is matched on the region lines joined by a space: a pane narrower than the sentence
|
|
152
|
+
* wraps it ("…is ready to" / "execute. Would you like to proceed?" at 50 columns, CLI 2.1.331), and a match
|
|
153
|
+
* within one line would leave the dialog `other`. A question form keeps its kind: the author of the question may
|
|
154
|
+
* quote the sentence, and the joined region would then rename the form to `ExitPlanMode`.
|
|
126
155
|
*/
|
|
127
|
-
const regionText = region.join('
|
|
128
|
-
const planDialog =
|
|
156
|
+
const regionText = region.join(' ');
|
|
157
|
+
const planDialog = kind !== 'question'
|
|
158
|
+
&& (PLAN_DIALOG_PATTERN.test(regionText) || PLAN_EXIT_CONFIRM_PATTERN.test(regionText))
|
|
129
159
|
&& !trace && (block.title === null || block.title.kind === 'plan');
|
|
130
160
|
const networkDialog = !planDialog && block.title?.kind === 'network' && !trace;
|
|
131
161
|
// A file dialog whose key footer a narrow pane cut or wrapped has lost its only kind marker (`screen/file-dialog.ts`).
|
|
@@ -40,12 +40,14 @@ function mcpWords(text) {
|
|
|
40
40
|
return text.toLowerCase().split(/[\s_-]+/u).filter((word) => word !== '').join(' ');
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Whether the MCP tool title on screen ({@link ScreenDialog.mcpTool}) is THIS tool from the jsonl entry or hook dump.
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
* `
|
|
47
|
-
*
|
|
48
|
-
*
|
|
45
|
+
* Both texts become lower-case words. The title matches `<tool>` of `mcp__<server>__<tool>` without the `<server>_`
|
|
46
|
+
* prefix (server `catalog` names its tools `catalog_get_task`, title "Get Task") or the whole `<tool>`, when the
|
|
47
|
+
* title repeats the prefix ("Catalog get task"). A title that repeats neither (the server gave the tool another
|
|
48
|
+
* title) gives `false`: a mismatch, a card without buttons. The server alone is not enough: a `delete_task` card
|
|
49
|
+
* would pass over a `get_project_tree_layout` dialog. The two forms cannot tell `x_get` from `x_x_get` on one server
|
|
50
|
+
* (both read "X get"): the screen shows no raw tool name, so a server with a doubled prefix stays ambiguous.
|
|
49
51
|
*/
|
|
50
52
|
export function mcpTitleMatches(toolName, screenTitle) {
|
|
51
53
|
const match = MCP_TOOL_NAME_PATTERN.exec(toolName);
|
|
@@ -54,8 +56,8 @@ export function mcpTitleMatches(toolName, screenTitle) {
|
|
|
54
56
|
if (server === undefined || tool === undefined || screenTitle === null)
|
|
55
57
|
return false;
|
|
56
58
|
const bare = tool.startsWith(`${server}_`) ? tool.slice(server.length + 1) : tool;
|
|
57
|
-
const
|
|
58
|
-
return
|
|
59
|
+
const title = mcpWords(screenTitle);
|
|
60
|
+
return title !== '' && (title === mcpWords(bare) || title === mcpWords(tool));
|
|
59
61
|
}
|
|
60
62
|
/** Nazwa narzędzia, którego dialog jest FORMULARZEM pytania, a nie zgodą na wykonanie. */
|
|
61
63
|
export const ASK_USER_QUESTION_TOOL = 'AskUserQuestion';
|
|
@@ -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
|
/**
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wąski parser surowej linii jsonl — wyłącznie to, czego `parseImportLine` NIE zwraca:
|
|
3
|
+
* `id` i SUROWY `input` czekającego narzędzia, tryb uprawnień, model, effort i `cwd`.
|
|
4
|
+
*
|
|
5
|
+
* Dlaczego osobny parser, a nie rozszerzenie `transcript-import.ts`:
|
|
6
|
+
* tamten moduł celowo GUBI to, czego tu potrzebujemy. `assistantBlocksFrom` zamienia
|
|
7
|
+
* `tool_use` na blok prezentacyjny (`summary` + przycięty `detail`) i wyrzuca `id` oraz pełny
|
|
8
|
+
* `input` — bo jego zadaniem jest transkrypt na telefonie. Karta zgody potrzebuje czegoś
|
|
9
|
+
* dokładnie odwrotnego: PEŁNEGO inputu, żeby `classifyRisk` widział to samo, co widział przy
|
|
10
|
+
* SDK, i `id`, żeby dało się sparować z `tool_result`. Rozszerzenie tamtego parsera znaczyłoby
|
|
11
|
+
* zmianę pliku, który jest read-only dla wszystkich (i którego używa cała warstwa treści).
|
|
12
|
+
*
|
|
13
|
+
* Moduł jest CZYSTY: bez I/O, bez zegara, bez logów. Okno wejściowe wyznacza wołający
|
|
14
|
+
* (`HERDR_HISTORY_BYTES` ogona pliku).
|
|
15
|
+
*
|
|
16
|
+
* REGUŁA, KTÓRA JEST TU WAŻNIEJSZA NIŻ KOD: **tryb uprawnień z jsonl służy WYŁĄCZNIE do chipu
|
|
17
|
+
* w UI i nigdy do bramki wysyłki.** Wpisy `permission-mode` powstają PO turze, więc `shift+tab`
|
|
18
|
+
* naciśnięty przy biurku między turami jest w pliku niewidoczny — panel przełączony na
|
|
19
|
+
* `bypass permissions` wyglądałby w jsonl na `manual` przez całą następną turę. Do bramki
|
|
20
|
+
* (`commands/guard.ts`, reguła 4) tryb bierze się z odczytu stopki ekranu.
|
|
21
|
+
*/
|
|
22
|
+
import path from 'node:path';
|
|
1
23
|
import { EFFORT_LEVELS, MODEL_ID_PATTERN } from '@rarog/shared';
|
|
2
24
|
import { asRecord } from '../drivers/tool-text.js';
|
|
3
25
|
import { CLI_SHAPES } from './background/cli-shapes.js';
|
|
@@ -116,6 +138,8 @@ export function createPendingTracker() {
|
|
|
116
138
|
const blocks = blocksOf(entry);
|
|
117
139
|
if (type === 'assistant') {
|
|
118
140
|
const at = asText(entry['timestamp']);
|
|
141
|
+
const cwd = asText(entry['cwd']);
|
|
142
|
+
const entryCwd = path.isAbsolute(cwd) ? { entryCwd: cwd } : {};
|
|
119
143
|
for (const block of blocks) {
|
|
120
144
|
if (block['type'] !== 'tool_use')
|
|
121
145
|
continue;
|
|
@@ -125,7 +149,7 @@ export function createPendingTracker() {
|
|
|
125
149
|
continue;
|
|
126
150
|
if (settled.has(id) || open.some((tool) => tool.id === id))
|
|
127
151
|
continue;
|
|
128
|
-
open.push({ id, toolName, input: block['input'], at });
|
|
152
|
+
open.push({ id, toolName, input: block['input'], at, ...entryCwd });
|
|
129
153
|
}
|
|
130
154
|
return;
|
|
131
155
|
}
|
|
@@ -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);
|