@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { say } from '@rarog/shared/sentences';
|
|
2
|
-
import { HERDR_BLOCKED_POLL_MS, HERDR_CONSENT_CARD_WAIT_MS,
|
|
2
|
+
import { HERDR_BLOCKED_POLL_MS, HERDR_CONSENT_CARD_WAIT_MS, HERDR_PENDING_DEBOUNCE_MS, HERDR_PENDING_RETRY_MS, HERDR_SCREEN_CACHE_MS, HERDR_STALL_SETTLE_MS, HERDR_TURN_WATCHDOG_MS, } from '../config.js';
|
|
3
3
|
import { APPLIED, STALE, refused } from './types.js';
|
|
4
4
|
import { AsyncEventQueue, systemScheduler } from './runtime.js';
|
|
5
5
|
import { HerdrOutOfScopeError, reasonOfError } from '../herdr/types.js';
|
|
@@ -14,17 +14,21 @@ import * as crons from './herdr/scheduled-task-poll.js';
|
|
|
14
14
|
import { cliWaitsForPermission, noteConsentRegistryRead } from './herdr/consent-registry-read.js';
|
|
15
15
|
import { PromptQueue, promptEntry } from './herdr/prompt-queue.js';
|
|
16
16
|
import { QueueTakeBack } from './herdr/queue-take-back.js';
|
|
17
|
+
import { ReturnedPrompt } from './herdr/returned-prompt.js';
|
|
17
18
|
import { TurnGuard } from './herdr/turn-guard.js';
|
|
18
19
|
import { FormReserve } from './herdr/form-reserve.js';
|
|
19
20
|
import { CliReserve } from './herdr/cli-reserve.js';
|
|
20
21
|
import { CommandDialogSettle } from './herdr/command-dialog-settle.js';
|
|
21
22
|
import { ConsentChannel } from './herdr/consent-channel.js';
|
|
23
|
+
import { ConsentNoHook } from './herdr/consent-no-hook.js';
|
|
24
|
+
import { ScreenFallback } from './herdr/screen-fallback.js';
|
|
22
25
|
import { Layer2Cards, isLayer2Id, layer2HoldsKeys } from './herdr/layer2-card.js';
|
|
23
26
|
import { Layer2Step } from './herdr/layer2-step.js';
|
|
24
|
-
import {
|
|
27
|
+
import { approveContext, auditRefusal, layer2KeyRefusal, refuseDecision, refuseNote, refuseSend, reportStaleDecision, } from './herdr/refusals.js';
|
|
28
|
+
import { ANSWERED_HOOK_SHIELD_MS, CLI_WAITING_PROBES, DECIDED_SHIELD_MS, FORM_SUBMIT_CONFIRM_DELAY_MS, FORM_SUBMIT_GONE_MESSAGE, FORM_SUBMIT_KEY, HOOK_ANSWER_POLL_MS, HOOK_ANSWER_WAIT_MS, HOOK_PERMISSION_REQUEST_EVENT, MULTI_SELECT_MESSAGE, NOTE_NOT_ALLOWED_MESSAGE, NOTE_NO_CHANNEL_MESSAGE, NOTE_WRITE_FAILED_MESSAGE, NO_ANSWER_ON_SCREEN_MESSAGE, NO_DIGIT_MESSAGE, PAUSE_ESCAPE_MESSAGE, SCREEN_ANSWER_REARM_DELAYS_MS, SCREEN_CHANGED_MESSAGE, SCREEN_DIALOG_TOOL, TERMINAL_DIALOG_MESSAGE, TERMINAL_ONLY_MESSAGE, affirmativeOption, alwaysOption, admittedHook, applyMultiSelectOverride, blockCardRecord, confirmFormSubmit, decideCard, dialogShapeOf, measuredConsentHolds, evaluationReqId, fallbackSnippet, formSubmitAbortMessage, hookAnnotations, hookAnswerPartialMessage, besideAtDecision, hookPendingFor, hookPendingFrom, noteNotDeliveredMessage, optionPolicy, otherDialogDump, screenAnswerIndex, screenDialogCard, screenFormReqId, staleDumpProvesOther, } from '../herdr/dialogs/index.js';
|
|
25
29
|
import { shadowAuditFields } from '../herdr/audit.js';
|
|
26
30
|
import { diagnosisFields, originFields } from './herdr/audit-fields.js';
|
|
27
|
-
import { ASK_USER_QUESTION_TOOL, SANDBOX_NETWORK_TOOL, SESSION_PAUSED_DIALOG,
|
|
31
|
+
import { ASK_USER_QUESTION_TOOL, SANDBOX_NETWORK_TOOL, SESSION_PAUSED_DIALOG, canonicalLabel, exitDialogTasks, matchKnownDialog, parseOptions, resolveOptions, sameDialogIdentity, sessionPausedDialog, standingConsentDialog, } from '../herdr/dialogs/index.js';
|
|
28
32
|
import { SHADOW_DEADLINE_MS, registryEvidenceFromSignal, shadowCardEligible } from '../herdr/dialogs/index.js';
|
|
29
33
|
import { consentDigitRefused, consentModeNow, consentOnlyEvent } from '../herdr/dialogs/index.js';
|
|
30
34
|
import { collapseFooterMode, parseModeFooter } from '../herdr/dialogs/screen/mode-footer.js';
|
|
@@ -155,6 +159,7 @@ export class HerdrDriver {
|
|
|
155
159
|
#promptQueue;
|
|
156
160
|
/** Taking both prompt queues back for the app: `drivers/herdr/queue-take-back.ts`. */
|
|
157
161
|
#takeBack;
|
|
162
|
+
#returnedPrompt;
|
|
158
163
|
#paneId;
|
|
159
164
|
#mode;
|
|
160
165
|
#lastTitle = null;
|
|
@@ -282,6 +287,12 @@ export class HerdrDriver {
|
|
|
282
287
|
#formReserve;
|
|
283
288
|
/** The CLI registry fallback: `drivers/herdr/cli-reserve.ts`. */
|
|
284
289
|
#cliReserve;
|
|
290
|
+
/** Consent without a hook and cards without the approve button, in the log: `drivers/herdr/consent-no-hook.ts`. */
|
|
291
|
+
#noHook;
|
|
292
|
+
/** The emergency approve button of a consent dialog without a hook: `drivers/herdr/screen-fallback.ts`. */
|
|
293
|
+
#screenFallback;
|
|
294
|
+
/** The port of the refusals and their audit funnel: `drivers/herdr/refusals.ts`. */
|
|
295
|
+
#refusals;
|
|
285
296
|
/** The wait behind a command dialog the driver confirmed: `drivers/herdr/command-dialog-settle.ts`. */
|
|
286
297
|
#commandSettle;
|
|
287
298
|
/** The layer 2 card with buttons (`docs/dialog-card.md`): `drivers/herdr/layer2-card.ts`. */
|
|
@@ -347,6 +358,7 @@ export class HerdrDriver {
|
|
|
347
358
|
const reservePort = this.#reservePort();
|
|
348
359
|
this.#formReserve = new FormReserve({ deps, scheduler: this.#scheduler }, reservePort);
|
|
349
360
|
this.#cliReserve = new CliReserve({ inScope: this.#inScope, form: this.#formReserve }, reservePort);
|
|
361
|
+
this.#refusals = this.#refusalPort();
|
|
350
362
|
this.#commandSettle = new CommandDialogSettle({ pollMs: deps.modelConfirmPollMs ?? MODEL_CONFIRM_POLL_MS }, {
|
|
351
363
|
disposed: () => this.#disposed,
|
|
352
364
|
readScreen: () => this.#deps.client.readScreen(this.#paneId, 'detection').then((s) => s.text, () => null),
|
|
@@ -379,6 +391,26 @@ export class HerdrDriver {
|
|
|
379
391
|
deps, scheduler: this.#scheduler, key: this.#key, consentCardWaitMs: this.#consentCardWaitMs,
|
|
380
392
|
follower: this.#follower, claude: this.#engine === 'claude' && this.#inScope, queue: this.#promptQueue,
|
|
381
393
|
}, this.#takeBackPort());
|
|
394
|
+
this.#returnedPrompt = new ReturnedPrompt({ deps, scheduler: this.#scheduler, key: this.#key }, { paneId: () => this.#paneId });
|
|
395
|
+
this.#noHook = new ConsentNoHook({ deps, scheduler: this.#scheduler, inScope: this.#inScope, cwd: this.#cwd }, {
|
|
396
|
+
disposed: () => this.#disposed, agentSessionId: () => this.#agentSessionId, blockedNow: () => this.#blockedNow(),
|
|
397
|
+
blockedSeq: () => this.#blockedSeq, blockedAt: () => this.#blockedAt, answeredAt: () => this.#answeredAt,
|
|
398
|
+
cliWaiting: () => this.#cliReserve.cliWaiting, screenText: () => this.#screenText,
|
|
399
|
+
cliVersion: () => (this.#cliReserve.cliSignal?.kind === 'unknown' ? null : this.#cliReserve.cliSignal?.version ?? null),
|
|
400
|
+
permissionMode: () => (this.#mode === 'unknown' ? null : this.#mode),
|
|
401
|
+
// The button of the standing card changed (or a card waits for it): the card goes out again under its `reqId`.
|
|
402
|
+
judged: () => {
|
|
403
|
+
if (this.#disposed || !this.#screenFallback.judged(this.#activeReq))
|
|
404
|
+
return;
|
|
405
|
+
this.#clearActive('screen fallback changed');
|
|
406
|
+
this.#scheduleEvaluate();
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
this.#screenFallback = new ScreenFallback({ deps, inScope: this.#inScope }, {
|
|
410
|
+
agentSessionId: () => this.#agentSessionId, cliWaiting: () => this.#cliReserve.cliWaiting,
|
|
411
|
+
screenText: () => this.#screenText, standing: () => this.#noHook.standing(),
|
|
412
|
+
keyHookWaits: () => this.#promptQueue.keyHookWaits(), pendingCallId: () => this.#pending?.id ?? null,
|
|
413
|
+
});
|
|
382
414
|
this.#promptQueue.restore(this.#engine === 'claude', () => ++this.#turnGuard.sendGeneration);
|
|
383
415
|
if (this.#follower !== null)
|
|
384
416
|
void this.#pumpFollower(this.#follower);
|
|
@@ -674,6 +706,8 @@ export class HerdrDriver {
|
|
|
674
706
|
}
|
|
675
707
|
// Prompt doszedł do panelu — także zablokowany przez hook: odmowę niesie notka, nie ostrzeżenie wysyłki.
|
|
676
708
|
onDelivered();
|
|
709
|
+
if (outcome === 'sent' && slash === null && !midTurn)
|
|
710
|
+
this.#returnedPrompt.noteSent(finalText);
|
|
677
711
|
this.#turnGuard.afterSubmit(outcome === 'blocked', slash, echo, generation, silent);
|
|
678
712
|
}
|
|
679
713
|
/**
|
|
@@ -810,7 +844,7 @@ export class HerdrDriver {
|
|
|
810
844
|
const { client } = this.#deps;
|
|
811
845
|
const sent = await this.#send(() => (key.via === 'keys'
|
|
812
846
|
? client.sendKeys(this.#paneId, key.keys) : client.sendDialogKey(this.#paneId, key.key)), {
|
|
813
|
-
...entry, ...this.#
|
|
847
|
+
...entry, ...approveContext(this.#refusals),
|
|
814
848
|
});
|
|
815
849
|
if (!sent)
|
|
816
850
|
return false;
|
|
@@ -846,6 +880,24 @@ export class HerdrDriver {
|
|
|
846
880
|
evaluate: () => this.#evaluate(),
|
|
847
881
|
};
|
|
848
882
|
}
|
|
883
|
+
/** Port of the refusals: the card, screen and registry state they read and the steps that stay here. */
|
|
884
|
+
#refusalPort() {
|
|
885
|
+
return {
|
|
886
|
+
deps: this.#deps,
|
|
887
|
+
scheduler: this.#scheduler,
|
|
888
|
+
paneId: () => this.#paneId,
|
|
889
|
+
agentSessionId: () => this.#agentSessionId,
|
|
890
|
+
screenText: () => this.#screenText,
|
|
891
|
+
activeReq: () => this.#activeReq,
|
|
892
|
+
pending: () => this.#pending,
|
|
893
|
+
cliWaiting: () => this.#cliReserve.cliWaiting,
|
|
894
|
+
resolveOptions: (text, expected) => this.#resolveOptions(text, expected),
|
|
895
|
+
audit: (entry, at) => { this.#audit(entry, at); },
|
|
896
|
+
system: (text) => { this.#system(text); },
|
|
897
|
+
clearActive: (reason) => { this.#clearActive(reason); },
|
|
898
|
+
scheduleEvaluate: () => { this.#scheduleEvaluate(); },
|
|
899
|
+
};
|
|
900
|
+
}
|
|
849
901
|
/**
|
|
850
902
|
* Wysyłka z tokenem echa odroczonego nie doszła do panelu: wpis z okna echa wypada (inaczej
|
|
851
903
|
* identyczny prompt wysłany potem trafiłby na sierotę), a manager dostaje `echo-refused` i spłukuje
|
|
@@ -1093,7 +1145,7 @@ export class HerdrDriver {
|
|
|
1093
1145
|
this.#shadowKeySent(shadow, false);
|
|
1094
1146
|
if (this.#disposed)
|
|
1095
1147
|
return STALE;
|
|
1096
|
-
return this.#
|
|
1148
|
+
return refuseDecision(this.#refusals, PAUSE_ESCAPE_MESSAGE, 'Esc na pauzie „Session paused”', 'terminal-only');
|
|
1097
1149
|
}
|
|
1098
1150
|
if (this.#disposed) {
|
|
1099
1151
|
this.#shadowKeySent(shadow, false);
|
|
@@ -1129,7 +1181,7 @@ export class HerdrDriver {
|
|
|
1129
1181
|
// doszło, dialog stoi dalej i zrzut wciąż jest jego prawdziwym opisem. Wyjątek ten sam co po cyfrze:
|
|
1130
1182
|
// zrzut `Bash` INNEGO dialogu, który czeka w kolejce za zamkniętym (`#clearHookAfterDecision`).
|
|
1131
1183
|
if (!ok)
|
|
1132
|
-
return this.#
|
|
1184
|
+
return refuseSend(this.#refusals);
|
|
1133
1185
|
const keptHookAt = this.#clearHookAfterDecision(this.#readHookFile(), resolvedText, denied);
|
|
1134
1186
|
/*
|
|
1135
1187
|
* Osłona po własnej decyzji także po `escape`. Karta BEZ przycisków jest
|
|
@@ -1180,9 +1232,9 @@ export class HerdrDriver {
|
|
|
1180
1232
|
const sessionAddressed = active.screen === true
|
|
1181
1233
|
&& active.toolName.startsWith(`${SCREEN_DIALOG_TOOL}:`);
|
|
1182
1234
|
if (!sessionAddressed)
|
|
1183
|
-
return Promise.resolve(this.#
|
|
1235
|
+
return Promise.resolve(reportStaleDecision(this.#refusals));
|
|
1184
1236
|
}
|
|
1185
|
-
const held = this.#
|
|
1237
|
+
const held = layer2KeyRefusal(this.#refusals);
|
|
1186
1238
|
if (held !== null)
|
|
1187
1239
|
return Promise.resolve(held);
|
|
1188
1240
|
/*
|
|
@@ -1191,7 +1243,7 @@ export class HerdrDriver {
|
|
|
1191
1243
|
* etykiety, nie na flagę — przyszła opcja „Yes…” w takim dialogu nie ma prawa stać się celem tapnięcia.
|
|
1192
1244
|
*/
|
|
1193
1245
|
if (active.terminalDialog !== undefined) {
|
|
1194
|
-
return Promise.resolve(this.#
|
|
1246
|
+
return Promise.resolve(refuseDecision(this.#refusals, TERMINAL_DIALOG_MESSAGE, 'dialog z listy terminalowej', 'terminal-only'));
|
|
1195
1247
|
}
|
|
1196
1248
|
/*
|
|
1197
1249
|
* Lista opcji jest tu jedyną bramką i jest pusta wszędzie tam, gdzie Rarog nie wie, co
|
|
@@ -1209,7 +1261,7 @@ export class HerdrDriver {
|
|
|
1209
1261
|
// Karta nie niesie przycisku „zawsze", a ta bramka zamyka go też dla starego
|
|
1210
1262
|
// albo obcego klienta — „don't ask again for <host>" zostaje do wybrania przy biurku.
|
|
1211
1263
|
if (decision === 'allow-always' && active.toolName === SANDBOX_NETWORK_TOOL) {
|
|
1212
|
-
return Promise.resolve(this.#
|
|
1264
|
+
return Promise.resolve(refuseDecision(this.#refusals, TERMINAL_ONLY_MESSAGE, 'sieć sandboksa: tylko zgoda jednorazowa', 'terminal-only'));
|
|
1213
1265
|
}
|
|
1214
1266
|
/*
|
|
1215
1267
|
* Dialog zaufania BEZ cyfr: karta nie ma opcji, a zatwierdzenie idzie osobną ścieżką `down`/`enter`
|
|
@@ -1217,11 +1269,16 @@ export class HerdrDriver {
|
|
|
1217
1269
|
*/
|
|
1218
1270
|
if (active.trustArrow !== undefined && decision === 'allow')
|
|
1219
1271
|
return this.#approveTrustArrow(active, active.trustArrow);
|
|
1272
|
+
// The emergency button approves this one call: "don't ask again" stays at the desk.
|
|
1273
|
+
if (decision === 'allow-always' && active.screenFallback !== undefined) {
|
|
1274
|
+
this.#screenFallback.refused(active, 'always');
|
|
1275
|
+
return Promise.resolve(refuseDecision(this.#refusals, TERMINAL_ONLY_MESSAGE, 'screen fallback: once only', 'terminal-only'));
|
|
1276
|
+
}
|
|
1220
1277
|
const option = decision === 'allow-always'
|
|
1221
1278
|
? alwaysOption(active.options)
|
|
1222
1279
|
: affirmativeOption(active.options);
|
|
1223
1280
|
if (option === null) {
|
|
1224
|
-
return Promise.resolve(this.#
|
|
1281
|
+
return Promise.resolve(refuseDecision(this.#refusals, NO_DIGIT_MESSAGE, decision === 'allow-always'
|
|
1225
1282
|
? 'brak jednoznacznej opcji „nie pytaj więcej"'
|
|
1226
1283
|
: 'zgoda bez jednoznacznej opcji „tak"', 'no-digit'));
|
|
1227
1284
|
}
|
|
@@ -1259,7 +1316,7 @@ export class HerdrDriver {
|
|
|
1259
1316
|
if (active === null)
|
|
1260
1317
|
return Promise.resolve(STALE);
|
|
1261
1318
|
if (active.reqId !== reqId)
|
|
1262
|
-
return Promise.resolve(this.#
|
|
1319
|
+
return Promise.resolve(reportStaleDecision(this.#refusals));
|
|
1263
1320
|
const target = active.hookAnswer;
|
|
1264
1321
|
const complete = target !== undefined
|
|
1265
1322
|
&& answers.length === target.questions.length
|
|
@@ -1272,7 +1329,7 @@ export class HerdrDriver {
|
|
|
1272
1329
|
*/
|
|
1273
1330
|
const noted = notes?.some((note) => note !== null && note.trim() !== '') === true;
|
|
1274
1331
|
if (noted && (target === undefined || !complete || this.#deps.hookAnswers === undefined)) {
|
|
1275
|
-
return Promise.resolve(this.#
|
|
1332
|
+
return Promise.resolve(refuseNote(this.#refusals, NOTE_NO_CHANNEL_MESSAGE));
|
|
1276
1333
|
}
|
|
1277
1334
|
if (target !== undefined && complete && this.#deps.hookAnswers !== undefined) {
|
|
1278
1335
|
return this.#answerViaHook(active, target, answers, noted ? notes : undefined);
|
|
@@ -1301,7 +1358,7 @@ export class HerdrDriver {
|
|
|
1301
1358
|
groups: answers.map((group) => group.length),
|
|
1302
1359
|
};
|
|
1303
1360
|
if (index === -1) {
|
|
1304
|
-
return Promise.resolve(this.#
|
|
1361
|
+
return Promise.resolve(refuseDecision(this.#refusals, NO_DIGIT_MESSAGE, 'pytania z ekranu nie ma na karcie', 'no-digit', shape));
|
|
1305
1362
|
}
|
|
1306
1363
|
const first = answers[index] ?? [];
|
|
1307
1364
|
/*
|
|
@@ -1311,7 +1368,7 @@ export class HerdrDriver {
|
|
|
1311
1368
|
* tamta oddaje `screen-changed`, choć ekran się nie zmienił.
|
|
1312
1369
|
*/
|
|
1313
1370
|
if (active.multiSelect === true) {
|
|
1314
|
-
return Promise.resolve(this.#
|
|
1371
|
+
return Promise.resolve(refuseDecision(this.#refusals, MULTI_SELECT_MESSAGE, 'wielokrotny wybór', 'multi-select', shape));
|
|
1315
1372
|
}
|
|
1316
1373
|
/*
|
|
1317
1374
|
* PUSTA grupa to brak odpowiedzi na pytanie, które stoi w terminalu — nie wielokrotny
|
|
@@ -1319,11 +1376,11 @@ export class HerdrDriver {
|
|
|
1319
1376
|
* „Wielokrotny wybór zrób w terminalu" przy formularzu bez żadnego checkboxa.
|
|
1320
1377
|
*/
|
|
1321
1378
|
if (first.length === 0) {
|
|
1322
|
-
return Promise.resolve(this.#
|
|
1379
|
+
return Promise.resolve(refuseDecision(this.#refusals, NO_ANSWER_ON_SCREEN_MESSAGE, 'brak odpowiedzi na pytanie z ekranu', 'no-digit', shape));
|
|
1323
1380
|
}
|
|
1324
1381
|
// Wielokrotny wybór wymagałby `space` + `enter`, czyli wyboru po POZYCJI.
|
|
1325
1382
|
if (first.length !== 1) {
|
|
1326
|
-
return Promise.resolve(this.#
|
|
1383
|
+
return Promise.resolve(refuseDecision(this.#refusals, MULTI_SELECT_MESSAGE, 'wielokrotny wybór', 'multi-select', shape));
|
|
1327
1384
|
}
|
|
1328
1385
|
const label = canonicalLabel(first[0] ?? '');
|
|
1329
1386
|
/*
|
|
@@ -1333,11 +1390,11 @@ export class HerdrDriver {
|
|
|
1333
1390
|
* kluczu kanonicznym odpowiedzi, więc pełna etykieta i sam jej prefiks dostają tę samą odmowę.
|
|
1334
1391
|
*/
|
|
1335
1392
|
if (active.terminalOnlyLabels?.includes(label) === true) {
|
|
1336
|
-
return Promise.resolve(this.#
|
|
1393
|
+
return Promise.resolve(refuseDecision(this.#refusals, TERMINAL_ONLY_MESSAGE, 'opcja tylko z terminala na karcie', 'terminal-only'));
|
|
1337
1394
|
}
|
|
1338
1395
|
const option = active.options.find((candidate) => candidate.label === label);
|
|
1339
1396
|
if (option === undefined) {
|
|
1340
|
-
return Promise.resolve(this.#
|
|
1397
|
+
return Promise.resolve(refuseDecision(this.#refusals, NO_DIGIT_MESSAGE, 'etykiety nie ma na żywej liście opcji', 'no-digit', shape));
|
|
1341
1398
|
}
|
|
1342
1399
|
/*
|
|
1343
1400
|
* Bramka SERWEROWA, nie tylko UI: opcja eskalująca uprawnienia („always allow…") jest na
|
|
@@ -1360,8 +1417,8 @@ export class HerdrDriver {
|
|
|
1360
1417
|
if (policy.digitBlocked || option.terminalOnly === true) {
|
|
1361
1418
|
// Karta dialogu z listy terminalowej: flagę ma KAŻDA opcja, a zdanie o uprawnieniach byłoby fałszem.
|
|
1362
1419
|
return Promise.resolve(policy.why === 'terminal-dialog'
|
|
1363
|
-
? this.#
|
|
1364
|
-
: this.#
|
|
1420
|
+
? refuseDecision(this.#refusals, TERMINAL_DIALOG_MESSAGE, 'dialog z listy terminalowej', 'terminal-only')
|
|
1421
|
+
: refuseDecision(this.#refusals, TERMINAL_ONLY_MESSAGE, 'opcja eskalująca uprawnienia', 'terminal-only'));
|
|
1365
1422
|
}
|
|
1366
1423
|
return this.#sendDigit(option, active);
|
|
1367
1424
|
}
|
|
@@ -1387,7 +1444,7 @@ export class HerdrDriver {
|
|
|
1387
1444
|
if (channel === undefined) {
|
|
1388
1445
|
return notes === undefined
|
|
1389
1446
|
? this.#answerWithDigit(active, answers)
|
|
1390
|
-
: this.#
|
|
1447
|
+
: refuseNote(this.#refusals, NOTE_NO_CHANNEL_MESSAGE);
|
|
1391
1448
|
}
|
|
1392
1449
|
/*
|
|
1393
1450
|
* Reguła „jedno tapnięcie nie zmienia trwale uprawnień” obowiązuje w KAŻDYM kanale: opcja eskalująca uprawnienia
|
|
@@ -1397,7 +1454,7 @@ export class HerdrDriver {
|
|
|
1397
1454
|
*/
|
|
1398
1455
|
const escalating = answers.flat().some((raw) => target.blocked.includes(canonicalLabel(raw)));
|
|
1399
1456
|
if (escalating) {
|
|
1400
|
-
return this.#
|
|
1457
|
+
return refuseDecision(this.#refusals, TERMINAL_ONLY_MESSAGE, 'opcja eskalująca uprawnienia', 'terminal-only');
|
|
1401
1458
|
}
|
|
1402
1459
|
// Klucz mapy to DOSŁOWNA treść pytania z payloadu (po niej dopasowuje CLI), a wiele
|
|
1403
1460
|
// wartości jedzie JEDNYM stringiem po przecinku — tak CLI czyta `multiSelect`.
|
|
@@ -1415,7 +1472,7 @@ export class HerdrDriver {
|
|
|
1415
1472
|
*/
|
|
1416
1473
|
const annotations = notes === undefined ? null : hookAnnotations(target, answers, notes);
|
|
1417
1474
|
if (notes !== undefined && annotations === null)
|
|
1418
|
-
return this.#
|
|
1475
|
+
return refuseNote(this.#refusals, NOTE_NOT_ALLOWED_MESSAGE);
|
|
1419
1476
|
const noteCount = annotations === null ? 0 : Object.keys(annotations).length;
|
|
1420
1477
|
/*
|
|
1421
1478
|
* Zakaz fallbacku cyfrą wynika z ŻĄDANIA (niepuste notatki od człowieka), a nie z liczby
|
|
@@ -1424,7 +1481,7 @@ export class HerdrDriver {
|
|
|
1424
1481
|
*/
|
|
1425
1482
|
const noted = notes !== undefined;
|
|
1426
1483
|
if (noted && noteCount === 0)
|
|
1427
|
-
return this.#
|
|
1484
|
+
return refuseNote(this.#refusals, NOTE_NOT_ALLOWED_MESSAGE);
|
|
1428
1485
|
let path;
|
|
1429
1486
|
try {
|
|
1430
1487
|
path = channel.write(this.#agentSessionId, target.key, map, noteCount > 0 ? annotations : null);
|
|
@@ -1439,7 +1496,7 @@ export class HerdrDriver {
|
|
|
1439
1496
|
*/
|
|
1440
1497
|
if (path === null) {
|
|
1441
1498
|
return noted
|
|
1442
|
-
? this.#
|
|
1499
|
+
? refuseNote(this.#refusals, NOTE_WRITE_FAILED_MESSAGE)
|
|
1443
1500
|
: this.#answerWithDigit(active, answers);
|
|
1444
1501
|
}
|
|
1445
1502
|
// Numer blokady sprzed osłony — do przywrócenia, gdy odpowiedź z notatką nie dojdzie.
|
|
@@ -1535,9 +1592,10 @@ export class HerdrDriver {
|
|
|
1535
1592
|
* notatki jej nie gasi i oceny nie ponawia. Notatka nie doszła tak samo, więc zdanie z jej treścią idzie
|
|
1536
1593
|
* do transkryptu, a dziennik dostaje nazwę narzędzia karty, na którą przyszła odpowiedź.
|
|
1537
1594
|
*/
|
|
1538
|
-
if (this.#activeReq !== null && this.#activeReq !== active)
|
|
1539
|
-
return this.#
|
|
1540
|
-
|
|
1595
|
+
if (this.#activeReq !== null && this.#activeReq !== active) {
|
|
1596
|
+
return refuseNote(this.#refusals, message, active.toolName);
|
|
1597
|
+
}
|
|
1598
|
+
return refuseDecision(this.#refusals, message, 'notatka: hook nie odebrał pliku odpowiedzi', 'send-failed');
|
|
1541
1599
|
}
|
|
1542
1600
|
/*
|
|
1543
1601
|
* Karta podmieniona w oknie czekania: nowy zrzut i nowy ekran wystawiły inną kartę, a odpowiedź
|
|
@@ -1551,7 +1609,7 @@ export class HerdrDriver {
|
|
|
1551
1609
|
if (this.#activeReq === null)
|
|
1552
1610
|
return STALE;
|
|
1553
1611
|
if (this.#activeReq !== active)
|
|
1554
|
-
return this.#
|
|
1612
|
+
return reportStaleDecision(this.#refusals);
|
|
1555
1613
|
/*
|
|
1556
1614
|
* Cyfra dowozi TYLKO pytanie stojące na ekranie — i wcale nie musi to być pierwsze
|
|
1557
1615
|
* pytanie karty (zakładkę przełącza się przy biurku bez mignięcia `agent_status`).
|
|
@@ -1578,227 +1636,6 @@ export class HerdrDriver {
|
|
|
1578
1636
|
await this.#sleep(pollMs);
|
|
1579
1637
|
}
|
|
1580
1638
|
}
|
|
1581
|
-
/**
|
|
1582
|
-
* Odmowa wysyłki cyfry: powiedz DLACZEGO i ODBUDUJ kartę.
|
|
1583
|
-
*
|
|
1584
|
-
* Karta gaśnie i ocena buduje ją od nowa z tego, co stoi TERAZ — decyzja nie wyszła, ale
|
|
1585
|
-
* człowiek ma na czym pracować. To JEDYNA ścieżka odbudowy po odmowie
|
|
1586
|
-
* decyzji: pending w managerze przeżywa `refused` (kontrakt `DecisionOutcome`), więc
|
|
1587
|
-
* odbudowa nie musi już nadrabiać wpisu zjedzonego przez first-wins.
|
|
1588
|
-
*/
|
|
1589
|
-
#refuseDecision(message, reason, audit, shape) {
|
|
1590
|
-
this.#auditRefusal(audit, this.#activeReq?.toolName, 'refuse', shape);
|
|
1591
|
-
this.#system(message);
|
|
1592
|
-
this.#clearActive(reason);
|
|
1593
|
-
this.#scheduleEvaluate();
|
|
1594
|
-
return refused(audit);
|
|
1595
|
-
}
|
|
1596
|
-
/**
|
|
1597
|
-
* Herdr odrzucił samo wywołanie — nic nie poszło do panelu.
|
|
1598
|
-
*
|
|
1599
|
-
* Karty NIE gasimy i oceny nie ponawiamy: dialog stoi dalej, a `#send` zdążył już
|
|
1600
|
-
* powiedzieć człowiekowi, co się stało (blokada / panel zniknął / tryb tylko do odczytu).
|
|
1601
|
-
* Wpis w dzienniku dokłada tę odmowę do licznika (`summarizeRefusals` w `herdr/audit.ts`) — bez niego
|
|
1602
|
-
* najczęstsza awaria kanału nie miałaby w statystyce ani jednej linii.
|
|
1603
|
-
*/
|
|
1604
|
-
#refuseSend() {
|
|
1605
|
-
this.#auditRefusal('send-failed', this.#activeReq?.toolName);
|
|
1606
|
-
return refused('send-failed');
|
|
1607
|
-
}
|
|
1608
|
-
/**
|
|
1609
|
-
* `allow` over a layer 2 card (`layer2HoldsKeys`, `docs/dialog-card.md`): `terminal-only` with the sentence of the
|
|
1610
|
-
* terminal dialogs, the card stays; a choice goes only through the layer 2 step. `null` = another card or none.
|
|
1611
|
-
*/
|
|
1612
|
-
#layer2KeyRefusal() {
|
|
1613
|
-
if (!layer2HoldsKeys(this.#activeReq))
|
|
1614
|
-
return null;
|
|
1615
|
-
this.#auditRefusal('terminal-only', this.#activeReq?.toolName);
|
|
1616
|
-
this.#system(TERMINAL_DIALOG_MESSAGE);
|
|
1617
|
-
return refused('terminal-only');
|
|
1618
|
-
}
|
|
1619
|
-
/**
|
|
1620
|
-
* Odpowiedź z NOTATKĄ nie wyszła — nic nie poszło ani do panelu, ani do pliku.
|
|
1621
|
-
*
|
|
1622
|
-
* Karty NIE gasimy, jak przy `#refuseSend`: dialog stoi dalej, a człowiek ma na niej szkic
|
|
1623
|
-
* z notatką (odmowa 422 zostawia kartę w stanie wyboru). Powód `send-failed` z zamkniętej
|
|
1624
|
-
* listy znaczy dokładnie to: „nic nie doszło" — dokładniejsze zdanie idzie do transkryptu.
|
|
1625
|
-
* `toolName` podaje wołający, gdy odpowiedź przyszła na inną kartę niż ta, która stoi.
|
|
1626
|
-
*/
|
|
1627
|
-
#refuseNote(message, toolName = this.#activeReq?.toolName) {
|
|
1628
|
-
this.#auditRefusal('send-failed', toolName);
|
|
1629
|
-
this.#system(message);
|
|
1630
|
-
return refused('send-failed');
|
|
1631
|
-
}
|
|
1632
|
-
/**
|
|
1633
|
-
* Wpis „decyzja NIE wyszła" — jedyna metoda dziennika bez ani jednego bajtu do panelu.
|
|
1634
|
-
*
|
|
1635
|
-
* Powód jest z zamkniętej listy, bo te wpisy mają się SUMOWAĆ (`summarizeRefusals` w `herdr/audit.ts`),
|
|
1636
|
-
* a nie opisywać: zdanie dla człowieka i tak idzie do transkryptu osobno. Nazwa narzędzia
|
|
1637
|
-
* jedzie z kartą — bez niej „18 odmów" nie mówi, czego dotyczyły.
|
|
1638
|
-
*/
|
|
1639
|
-
#auditRefusal(reason, toolName, method = 'refuse', shape, degrade) {
|
|
1640
|
-
const at = this.#deps.now();
|
|
1641
|
-
// The class from the CLI registry when it says `waiting`: the counter must tell WHICH dialogs
|
|
1642
|
-
// Rarog cannot read, and the router verdict (`#routeFields`) uses it as input.
|
|
1643
|
-
const cliDialog = this.#cliReserve.cliWaiting;
|
|
1644
|
-
const hook = this.#readHookQuietly();
|
|
1645
|
-
/*
|
|
1646
|
-
* KSZTAŁT przypadku. Karta bez decyzji niesie go z oceny (`decideCard` liczy go z tego
|
|
1647
|
-
* samego odczytu ekranu, z którego powstała karta, razem z podpowodem sprzed spadku na ścieżkę
|
|
1648
|
-
* ekranową). Odmowa wysyłki — ze stojącej karty i z ostatniego odczytu ekranu, tego samego, który
|
|
1649
|
-
* trafia do zrzutu odmowy.
|
|
1650
|
-
*/
|
|
1651
|
-
const caseShape = {
|
|
1652
|
-
...(degrade === undefined
|
|
1653
|
-
? {
|
|
1654
|
-
...originFields(this.#activeReq?.reqId ?? null, this.#activeReq?.origin),
|
|
1655
|
-
...diagnosisFields({ mismatchReason: null, ...dialogShapeOf(this.#screenText) }),
|
|
1656
|
-
}
|
|
1657
|
-
: { ...originFields(degrade.reqId, degrade.origin), ...diagnosisFields(degrade.diagnosis) }),
|
|
1658
|
-
...this.#routeFields(hook),
|
|
1659
|
-
};
|
|
1660
|
-
const entry = {
|
|
1661
|
-
method,
|
|
1662
|
-
reason,
|
|
1663
|
-
...(toolName === undefined ? {} : { toolName }),
|
|
1664
|
-
...(shape === undefined ? {} : { shape }),
|
|
1665
|
-
...(cliDialog === null ? {} : { cliDialog }),
|
|
1666
|
-
...caseShape,
|
|
1667
|
-
};
|
|
1668
|
-
const dump = this.#refusalDump(reason, toolName, caseShape, cliDialog, hook, at);
|
|
1669
|
-
const write = (rows) => {
|
|
1670
|
-
const withRows = rows === null ? {} : { paneRows: rows };
|
|
1671
|
-
this.#audit({ ...entry, ...withRows }, at);
|
|
1672
|
-
if (dump !== null)
|
|
1673
|
-
this.#writeDump({ ...dump, shape: { ...caseShape, ...withRows } });
|
|
1674
|
-
};
|
|
1675
|
-
/*
|
|
1676
|
-
* Wiersze panelu z herdr WYŁĄCZNIE przy karcie bez decyzji: jeden `pane.list`, po nim
|
|
1677
|
-
* wpis i zrzut. Karta nie czeka — wpis dochodzi do pliku z czasem oceny. Budżet czekania liczy
|
|
1678
|
-
* DRIVER (`HERDR_PANE_ROWS_WAIT_MS`, łącznie z kolejką slotów gniazda): po nim wpis i zrzut idą
|
|
1679
|
-
* bez wierszy, dokładnie raz, a spóźniony wynik przepada. Sufit gniazda zostaje zwykły — krótszy
|
|
1680
|
-
* oznaczałby herdr jako niedostępny z powodu diagnostyki. Błąd odczytu
|
|
1681
|
-
* albo brak metody = wpis bez wierszy, nigdy liczba zgadnięta z ekranu.
|
|
1682
|
-
*/
|
|
1683
|
-
const client = this.#deps.client;
|
|
1684
|
-
if (method !== 'degrade' || client.readPaneRows === undefined) {
|
|
1685
|
-
write(null);
|
|
1686
|
-
return;
|
|
1687
|
-
}
|
|
1688
|
-
let timer = null;
|
|
1689
|
-
let written = false;
|
|
1690
|
-
const once = (rows) => {
|
|
1691
|
-
if (written)
|
|
1692
|
-
return;
|
|
1693
|
-
written = true;
|
|
1694
|
-
if (timer !== null)
|
|
1695
|
-
this.#scheduler.clearTimeout(timer);
|
|
1696
|
-
write(rows);
|
|
1697
|
-
};
|
|
1698
|
-
timer = this.#scheduler.setTimeout(() => { once(null); }, this.#deps.paneRowsWaitMs ?? HERDR_PANE_ROWS_WAIT_MS);
|
|
1699
|
-
void client.readPaneRows(this.#paneId).then((rows) => { once(rows); }, () => { once(null); });
|
|
1700
|
-
}
|
|
1701
|
-
/**
|
|
1702
|
-
* Zrzut diagnostyczny do `<dataDir>/refusals/`
|
|
1703
|
-
* („Refusal diagnostics” w `docs/dialogs.md`) — jedno wywołanie na jedną odmowę.
|
|
1704
|
-
*
|
|
1705
|
-
* Stoi w `#auditRefusal`, bo to JEDYNY lejek odmów w driverze: każdy powód, który wchodzi
|
|
1706
|
-
* do statystyki, zostawia też ekran, z którego powstał. Ekran bierzemy z cache'u ostatniego
|
|
1707
|
-
* odczytu (`#screenText`) — świeżego, bo ocena dialogu czyta go tuż przed decyzją.
|
|
1708
|
-
*
|
|
1709
|
-
* Treść zrzutu składamy OD RAZU (ekran, zrzut hooka i wpis jsonl z chwili odmowy), a zapisujemy
|
|
1710
|
-
* po odczycie wierszy panelu (`#writeDump`) — w tym czasie kolejna ocena mogłaby podmienić cache.
|
|
1711
|
-
*
|
|
1712
|
-
* Ze zrzutu hooka jadą wyłącznie METADANE (zdarzenie, czas, narzędzie, a w kształcie przypadku
|
|
1713
|
-
* identyfikatory tury i subagenta). `toolInput` NIE —
|
|
1714
|
-
* on siedzi w `pending/` i nie ma powodu leżeć na dysku drugi raz.
|
|
1715
|
-
*/
|
|
1716
|
-
#refusalDump(reason, toolName, shape, cliDialog, hook, at) {
|
|
1717
|
-
if (this.#deps.dumpRefusal === undefined)
|
|
1718
|
-
return null;
|
|
1719
|
-
const pending = this.#pending;
|
|
1720
|
-
return {
|
|
1721
|
-
reason,
|
|
1722
|
-
toolName,
|
|
1723
|
-
...(this.#deps.sessionId === undefined ? {} : { sessionId: this.#deps.sessionId }),
|
|
1724
|
-
screen: this.#screenText,
|
|
1725
|
-
hook: hook === null
|
|
1726
|
-
? null
|
|
1727
|
-
: {
|
|
1728
|
-
toolName: hook.toolName,
|
|
1729
|
-
at: hook.at,
|
|
1730
|
-
...(hook.hookEventName === undefined ? {} : { hookEventName: hook.hookEventName }),
|
|
1731
|
-
},
|
|
1732
|
-
jsonl: pending === null ? null : { id: pending.id, toolName: pending.toolName },
|
|
1733
|
-
shape,
|
|
1734
|
-
...(cliDialog === null ? {} : { cliDialog }),
|
|
1735
|
-
at,
|
|
1736
|
-
};
|
|
1737
|
-
}
|
|
1738
|
-
#writeDump(dump) {
|
|
1739
|
-
try {
|
|
1740
|
-
this.#deps.dumpRefusal?.(dump);
|
|
1741
|
-
}
|
|
1742
|
-
catch {
|
|
1743
|
-
// Diagnostyka nie ma prawa wywrócić obsługi odmowy — cisza, jak przy dzienniku.
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* Zrzut hooka tej sesji do dziennika; błąd czytnika znaczy „brak zrzutu”, nigdy wyjątek w obsłudze. Zrzut `Bash`
|
|
1748
|
-
* starszy niż 10 minut liczy się tylko z dowodem z ostatniego odczytu ekranu (`admittedHook`),
|
|
1749
|
-
* jak w ocenie: inaczej rozdzielacz widziałby zrzut, którego karta nie wzięła.
|
|
1750
|
-
*/
|
|
1751
|
-
#readHookQuietly() {
|
|
1752
|
-
try {
|
|
1753
|
-
const raw = this.#deps.readPendingHook?.(this.#agentSessionId) ?? null;
|
|
1754
|
-
return admittedHook(raw, this.#screenText, (text, expected) => this.#resolveOptions(text, expected));
|
|
1755
|
-
}
|
|
1756
|
-
catch {
|
|
1757
|
-
return null;
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
/**
|
|
1761
|
-
* Pola dziennika z rozdzielacza warstw i pełnego bloku (`approve`, `degrade`, `refuse`): werdykt
|
|
1762
|
-
* `routeDialog` z klasy rejestru CLI, zrzutu hooka i ostatniego odczytu ekranu (`#screenText`, ten sam,
|
|
1763
|
-
* który trafia do zrzutu odmowy) oraz `blockVisible` z tego odczytu. Wyłącznie dziennik — karta, przyciski
|
|
1764
|
-
* i klawisze od tych pól nie zależą. Wyjątek parsera daje wpis bez tych pól, nigdy wstrzymaną wysyłkę.
|
|
1765
|
-
*/
|
|
1766
|
-
#routeFields(hook) {
|
|
1767
|
-
try {
|
|
1768
|
-
const text = this.#screenText;
|
|
1769
|
-
const { route, reason } = routeDialog({
|
|
1770
|
-
cliDialog: this.#cliReserve.cliWaiting, hook: routeHookOf(hook), screen: routeScreenOf(text),
|
|
1771
|
-
});
|
|
1772
|
-
return { ...(text === null ? {} : { blockVisible: blockVisible(text) }), route, routeReason: reason };
|
|
1773
|
-
}
|
|
1774
|
-
catch {
|
|
1775
|
-
return {};
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
/** Kontekst rejestru i rozdzielacza do wpisu `approve`: klasa CLI (gdy `waiting`) i {@link #routeFields}. */
|
|
1779
|
-
#approveContext() {
|
|
1780
|
-
const cliDialog = this.#cliReserve.cliWaiting;
|
|
1781
|
-
return { ...(cliDialog === null ? {} : { cliDialog }), ...this.#routeFields(this.#readHookQuietly()) };
|
|
1782
|
-
}
|
|
1783
|
-
/**
|
|
1784
|
-
* Odpowiedź w inny dialog niż ten, który AKTUALNIE stoi — mówimy o tym GŁOŚNO.
|
|
1785
|
-
*
|
|
1786
|
-
* `active === null` to normalny wyścig (dialog właśnie rozstrzygnięto — decyzja spóźniona
|
|
1787
|
-
* o ułamek sekundy, cisza jest poprawna). Ale odpowiedź adresująca INNY dialog znaczy, że
|
|
1788
|
-
* telefon patrzył na nieświeżą kartę — a jej zjedzenie po cichu wyglądałoby jak „tapnąłem
|
|
1789
|
-
* i nic".
|
|
1790
|
-
*/
|
|
1791
|
-
#reportStaleDecision() {
|
|
1792
|
-
this.#auditRefusal('stale-card', this.#activeReq?.toolName);
|
|
1793
|
-
this.#system(STALE_DECISION_MESSAGE);
|
|
1794
|
-
/*
|
|
1795
|
-
* `refused`, nie `stale`: Rarog POKAZUJE dziś inną kartę niż ta, w którą tapnięto, więc
|
|
1796
|
-
* karta, o której mówi żądanie, ma zniknąć razem ze swoim pendingiem — ale ta ŻYWA ma
|
|
1797
|
-
* zostać. `stale` wygasiłoby cały pending sesji (410 + `expired`), czyli zdjęłoby także
|
|
1798
|
-
* kartę, która mówi prawdę o ekranie.
|
|
1799
|
-
*/
|
|
1800
|
-
return refused('stale-card');
|
|
1801
|
-
}
|
|
1802
1639
|
/**
|
|
1803
1640
|
* Jedna cyfra do panelu + wpis dziennika, który mówi CO zatwierdzono, a nie co wysłano.
|
|
1804
1641
|
*
|
|
@@ -1817,30 +1654,58 @@ export class HerdrDriver {
|
|
|
1817
1654
|
return STALE;
|
|
1818
1655
|
// Tryb kanału (`main`): zgoda na narzędzie nie idzie cyfrą, także odpowiedź na potwierdzenie z ekranu.
|
|
1819
1656
|
if (consentDigitRefused(this.#deps, this.#cliReserve.cliWaiting, answered, consent)) {
|
|
1820
|
-
|
|
1657
|
+
// An emergency card that lost its button under the live mode or class: 410, and the card goes out again.
|
|
1658
|
+
if (consent && answered.screenFallback !== undefined) {
|
|
1659
|
+
return this.#fallbackLost(answered, this.#screenFallback.gateGuard(answered), null);
|
|
1660
|
+
}
|
|
1661
|
+
return refuseDecision(this.#refusals, TERMINAL_ONLY_MESSAGE, 'consent channel main: no digit for a consent', 'terminal-only');
|
|
1821
1662
|
}
|
|
1822
1663
|
const shadow = consent && this.#shadowChannel() !== undefined ? await this.#shadowStep('allow', answered) : null;
|
|
1823
1664
|
// Digit that only the measured mark lets through: the send shield before the fresh read and the key.
|
|
1824
|
-
const
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1665
|
+
const bare = { ...answered, measuredConsent: undefined, screenFallback: undefined };
|
|
1666
|
+
const gated = consent && consentDigitRefused(this.#deps, this.#cliReserve.cliWaiting, bare, true);
|
|
1667
|
+
const mark = gated ? answered.measuredConsent : undefined;
|
|
1668
|
+
// Digit that only the emergency mark lets through: "Yes" alone, the same shields, then the rule on fresh facts,
|
|
1669
|
+
// which refuses whatever moved since the gate above. A marked card takes this path in every mode, and a mode that
|
|
1670
|
+
// left `main` or `all` since the card refuses the key: the card goes out again as the live mode gives it.
|
|
1671
|
+
const fallback = consent && mark === undefined && answered.screenFallback !== undefined;
|
|
1672
|
+
if (fallback && !gated)
|
|
1673
|
+
return this.#fallbackLost(answered, this.#screenFallback.gateGuard(answered), shadow);
|
|
1674
|
+
if (fallback && option.digit !== affirmativeOption(answered.options)?.digit) {
|
|
1675
|
+
this.#screenFallback.refused(answered, 'always');
|
|
1676
|
+
return refuseDecision(this.#refusals, TERMINAL_ONLY_MESSAGE, 'screen fallback: once only', 'terminal-only');
|
|
1677
|
+
}
|
|
1678
|
+
const shielded = mark?.cliDialog ?? (fallback ? 'permission' : null);
|
|
1679
|
+
const shield = shielded === null ? null : await this.#promptQueue.keyShield(shielded);
|
|
1680
|
+
if (shield !== null && fallback)
|
|
1681
|
+
return this.#fallbackLost(answered, shield, shadow);
|
|
1682
|
+
if (shield !== null) {
|
|
1683
|
+
return refuseDecision(this.#refusals, SCREEN_CHANGED_MESSAGE, `measured: ${shield}`, 'screen-changed');
|
|
1684
|
+
}
|
|
1830
1685
|
const held = await this.#digitStillHolds(option, answered);
|
|
1831
1686
|
if (!held.ok) {
|
|
1832
1687
|
this.#shadowKeySent(shadow, false);
|
|
1688
|
+
if (fallback)
|
|
1689
|
+
this.#screenFallback.refused(answered, 'screen');
|
|
1833
1690
|
return held.outcome;
|
|
1834
1691
|
}
|
|
1692
|
+
// From here to the key nothing awaits: the rule, the channel card and the hook requests are asked last.
|
|
1693
|
+
const verdict = fallback ? this.#screenFallback.keyGuard(answered, this.#screenText) : null;
|
|
1694
|
+
if (verdict?.ok === false)
|
|
1695
|
+
return this.#fallbackLost(answered, verdict.guard, shadow);
|
|
1835
1696
|
// Zgoda z karty, a dialog przejęła karta kanału zgód (także w trakcie świeżego odczytu): cyfra trafiłaby
|
|
1836
1697
|
// w dialog, na który odpowiada hook. Bez klawisza; karta z ekranu wygasa (410).
|
|
1837
1698
|
if (consent && this.#consentChannel.consentCardStands(true)) {
|
|
1838
1699
|
this.#shadowKeySent(shadow, false);
|
|
1700
|
+
if (fallback)
|
|
1701
|
+
this.#screenFallback.refused(answered, 'channel-card');
|
|
1839
1702
|
return STALE;
|
|
1840
1703
|
}
|
|
1841
1704
|
// Measured digit: a hook registration without a card can come during the fresh read, after the shield.
|
|
1842
|
-
if (mark !== undefined && this.#promptQueue.keyHookWaits()) {
|
|
1843
|
-
|
|
1705
|
+
if ((mark !== undefined || fallback) && this.#promptQueue.keyHookWaits()) {
|
|
1706
|
+
if (fallback)
|
|
1707
|
+
return this.#fallbackLost(answered, 'hook', shadow);
|
|
1708
|
+
return refuseDecision(this.#refusals, SCREEN_CHANGED_MESSAGE, 'measured: hook', 'screen-changed');
|
|
1844
1709
|
}
|
|
1845
1710
|
const live = held.dialog;
|
|
1846
1711
|
// Odświeżamy meldunek o dialogu zaufania w chwili DECYZJI: to od niej liczy się karencja
|
|
@@ -1858,7 +1723,13 @@ export class HerdrDriver {
|
|
|
1858
1723
|
// Ekran, w który idzie cyfra: po klawiszu mówi też, który dialog rozstrzygnięto (`#clearHookAfterDecision`).
|
|
1859
1724
|
const resolvedText = this.#screenText;
|
|
1860
1725
|
const shot = { bodyPrint: live.bodyPrint, screenReqId: this.#screenIdentity(resolvedText) };
|
|
1861
|
-
const sent = await this.#send(() =>
|
|
1726
|
+
const sent = await this.#send(() => {
|
|
1727
|
+
// The emergency key is noted right before it goes, with no await in between. A note of a key that then
|
|
1728
|
+
// fails stays for its minute: at worst a late hook of this dialog goes back to the terminal.
|
|
1729
|
+
if (verdict?.ok === true)
|
|
1730
|
+
this.#screenFallback.keyNoted(verdict);
|
|
1731
|
+
return this.#deps.client.sendKeys(this.#paneId, [option.digit]);
|
|
1732
|
+
}, {
|
|
1862
1733
|
// `approve`, nie `send_keys`: to jest ZATWIERDZENIE dialogu z kontekstem decyzji
|
|
1863
1734
|
// (`toolName` + `optionLabel`), a runbook kradzieży (`docs/security-model.md`)
|
|
1864
1735
|
// grepuje `"method":"approve"`; wpis `send_keys` dałby
|
|
@@ -1867,13 +1738,15 @@ export class HerdrDriver {
|
|
|
1867
1738
|
// Tożsamość i pochodzenie zatwierdzonej karty — spina wpis z `degrade`/`refuse`.
|
|
1868
1739
|
...originFields(answered.reqId, answered.origin),
|
|
1869
1740
|
// Klasa CLI i werdykt rozdzielacza ze świeżego ekranu `#digitStillHolds` — tylko dziennik.
|
|
1870
|
-
...this.#
|
|
1741
|
+
...approveContext(this.#refusals),
|
|
1871
1742
|
// Wynik kroku trybu cienia i klucz pliku — tylko dziennik.
|
|
1872
1743
|
...shadowAuditFields(shadow),
|
|
1873
1744
|
});
|
|
1874
1745
|
this.#shadowKeySent(shadow, sent);
|
|
1875
1746
|
if (!sent)
|
|
1876
|
-
return this.#
|
|
1747
|
+
return refuseSend(this.#refusals);
|
|
1748
|
+
if (verdict?.ok === true)
|
|
1749
|
+
this.#screenFallback.keySent(verdict);
|
|
1877
1750
|
/*
|
|
1878
1751
|
* Tryb zatwierdzania z ŻYWEGO odczytu, nie z karty: `preview` jest
|
|
1879
1752
|
* własnością POJEDYNCZEGO pytania, a formularz przełącza zakładki bez mignięcia
|
|
@@ -1905,6 +1778,15 @@ export class HerdrDriver {
|
|
|
1905
1778
|
});
|
|
1906
1779
|
return step.then((outcome) => outcome ?? STALE);
|
|
1907
1780
|
}
|
|
1781
|
+
/** The emergency button lost before the key: no key, the refused line, 410, and the card goes out again. */
|
|
1782
|
+
#fallbackLost(answered, guard, shadow) {
|
|
1783
|
+
this.#shadowKeySent(shadow, false);
|
|
1784
|
+
this.#screenFallback.refused(answered, guard);
|
|
1785
|
+
if (this.#activeReq === answered)
|
|
1786
|
+
this.#clearActive('screen fallback lost');
|
|
1787
|
+
this.#scheduleEvaluate();
|
|
1788
|
+
return STALE;
|
|
1789
|
+
}
|
|
1908
1790
|
/**
|
|
1909
1791
|
* Zrzut hooka po WŁASNEJ cyfrze — kasujemy go dopiero wtedy, gdy jest ZUŻYTY.
|
|
1910
1792
|
*
|
|
@@ -1977,7 +1859,7 @@ export class HerdrDriver {
|
|
|
1977
1859
|
const abort = (message, reason) => {
|
|
1978
1860
|
// Licznik odmów obejmuje TAKŻE ten krok: `abort` jest wspólną drogą obu ścieżek
|
|
1979
1861
|
// odmowy (`gone()` też przez nią przechodzi), a wpis znaczy „cyfra poszła, `enter` NIE".
|
|
1980
|
-
this.#
|
|
1862
|
+
auditRefusal(this.#refusals, 'form-submit', toolName);
|
|
1981
1863
|
this.#system(message);
|
|
1982
1864
|
// Gasimy WYŁĄCZNIE własną kartę: przy podmianie w oknie pauzy `#clearActive` trafiłby
|
|
1983
1865
|
// w świeżą kartę postawioną przez ocenę panelu — a ona mówi prawdę o ekranie.
|
|
@@ -2026,9 +1908,9 @@ export class HerdrDriver {
|
|
|
2026
1908
|
{
|
|
2027
1909
|
method: 'approve', keys: [FORM_SUBMIT_KEY], toolName, optionLabel: option.label,
|
|
2028
1910
|
...originFields(answered.reqId, answered.origin),
|
|
2029
|
-
...this.#
|
|
1911
|
+
...approveContext(this.#refusals),
|
|
2030
1912
|
});
|
|
2031
|
-
return sent ? APPLIED : this.#
|
|
1913
|
+
return sent ? APPLIED : refuseSend(this.#refusals);
|
|
2032
1914
|
}
|
|
2033
1915
|
/**
|
|
2034
1916
|
* Zatwierdzenie dialogu zaufania BEZ cyfr (wyjątek od drogi cyfrowej, wzorem drogi formularza).
|
|
@@ -2055,7 +1937,7 @@ export class HerdrDriver {
|
|
|
2055
1937
|
return STALE;
|
|
2056
1938
|
const seq = this.#blockedSeq;
|
|
2057
1939
|
const refuse = (why) => {
|
|
2058
|
-
this.#
|
|
1940
|
+
auditRefusal(this.#refusals, 'screen-changed', toolName);
|
|
2059
1941
|
this.#system(SCREEN_CHANGED_MESSAGE);
|
|
2060
1942
|
// Gasimy WYŁĄCZNIE własną kartę: podmieniona w trakcie mówi prawdę o ekranie.
|
|
2061
1943
|
if (this.#activeReq === answered) {
|
|
@@ -2096,7 +1978,7 @@ export class HerdrDriver {
|
|
|
2096
1978
|
// `send_keys`, nie `approve`: `down` tylko przesuwa `❯`, niczego nie zatwierdza.
|
|
2097
1979
|
const moved = await this.#send(() => this.#deps.client.sendTrustStep(this.#paneId, TRUST_DOWN_KEY), { method: 'send_keys', keys: [TRUST_DOWN_KEY], ...audit });
|
|
2098
1980
|
if (!moved)
|
|
2099
|
-
return this.#
|
|
1981
|
+
return refuseSend(this.#refusals);
|
|
2100
1982
|
await this.#sleep(this.#deps.formSubmitConfirmDelayMs ?? FORM_SUBMIT_CONFIRM_DELAY_MS);
|
|
2101
1983
|
verdict = await read(false);
|
|
2102
1984
|
if (verdict === null)
|
|
@@ -2115,9 +1997,9 @@ export class HerdrDriver {
|
|
|
2115
1997
|
// Meldunek o dialogu zaufania w chwili decyzji, po dowodzie z ekranu i po kontroli stanu: od niej liczy się
|
|
2116
1998
|
// karencja zniknięcia. Meldunek jest synchroniczny (zapis czasu u nadzorcy), więc kontroli nie unieważnia.
|
|
2117
1999
|
this.#deps.markTrustDialog?.();
|
|
2118
|
-
const sent = await this.#send(() => this.#deps.client.sendTrustStep(this.#paneId, enterKey), { method: 'approve', keys: [enterKey], ...audit, ...this.#
|
|
2000
|
+
const sent = await this.#send(() => this.#deps.client.sendTrustStep(this.#paneId, enterKey), { method: 'approve', keys: [enterKey], ...audit, ...approveContext(this.#refusals) });
|
|
2119
2001
|
if (!sent)
|
|
2120
|
-
return this.#
|
|
2002
|
+
return refuseSend(this.#refusals);
|
|
2121
2003
|
this.#noteDecided(answered, seq, this.#hookGeneration(), this.#pending, {
|
|
2122
2004
|
bodyPrint: expectedPrint ?? null, screenReqId: answered.reqId,
|
|
2123
2005
|
});
|
|
@@ -2325,7 +2207,7 @@ export class HerdrDriver {
|
|
|
2325
2207
|
&& this.#sameScreenPermission(text, answered)) {
|
|
2326
2208
|
return { ok: true, dialog };
|
|
2327
2209
|
}
|
|
2328
|
-
this.#
|
|
2210
|
+
auditRefusal(this.#refusals, 'screen-changed', this.#activeReq?.toolName);
|
|
2329
2211
|
this.#system(SCREEN_CHANGED_MESSAGE);
|
|
2330
2212
|
// Karta jest już nieprawdą — gasimy ją i każemy ocenie zbudować nową z tego, co stoi
|
|
2331
2213
|
// TERAZ (świeży ekran siedzi po `#readDialog(true)` w cache'u tej blokady).
|
|
@@ -2825,16 +2707,10 @@ export class HerdrDriver {
|
|
|
2825
2707
|
return 'no-dialog';
|
|
2826
2708
|
}
|
|
2827
2709
|
/**
|
|
2828
|
-
*
|
|
2829
|
-
* Esc
|
|
2830
|
-
*
|
|
2831
|
-
*
|
|
2832
|
-
* TUI ignorowany. Jeden Esc, nie dwa: podwójny na pustym polu otwiera w CC rewind.
|
|
2833
|
-
*
|
|
2834
|
-
* Obietnica rozstrzyga się PO wysłaniu klawisza (`true` = poszedł), bo przerwanie czeka
|
|
2835
|
-
* w tej samej kolejce co wysyłki — router składa z tego `delivered`. Metoda celowo
|
|
2836
|
-
* NIE jest `async`: `#assertInScope()` ma rzucać synchronicznie, inaczej odmowa dla panelu
|
|
2837
|
-
* poza zasięgiem zamienia się w odrzuconą obietnicę i przestaje być 400.
|
|
2710
|
+
* Interrupts the turn with ONE `escape`, not `ctrl+c`: Esc is Claude Code's own interrupt, and a second one on an
|
|
2711
|
+
* empty field opens the rewind. Whether Esc handed the prompt back to the field: {@link returnedPrompt}. The promise
|
|
2712
|
+
* settles AFTER the key went (`true` = sent), as the interrupt waits in the send queue; the router builds `delivered`
|
|
2713
|
+
* from it. Not `async`: `#assertInScope()` must throw synchronously, or an out-of-scope refusal stops being a 400.
|
|
2838
2714
|
*/
|
|
2839
2715
|
interrupt() {
|
|
2840
2716
|
this.#assertInScope();
|
|
@@ -2843,18 +2719,21 @@ export class HerdrDriver {
|
|
|
2843
2719
|
// Flaga PRZED wysyłką: nawet gdy `escape` nie dojdzie, następna wysyłka ma wyczyścić pole.
|
|
2844
2720
|
this.#needsEscape = true;
|
|
2845
2721
|
const session = this.#agentSessionId;
|
|
2846
|
-
//
|
|
2722
|
+
// After Esc the field no longer surely holds the blocked prompt: it may hold the interrupted one.
|
|
2847
2723
|
this.#turnGuard.blockedLeftover = null;
|
|
2848
2724
|
const token = ++this.#interruptProbeToken;
|
|
2849
2725
|
return this.#enqueue(async () => {
|
|
2726
|
+
const expected = await this.#returnedPrompt.beforeEscape(this.#engine === 'claude' && !this.#blockedNow()
|
|
2727
|
+
&& this.#activeReq === null && this.#promptQueue.prompts.length === 0 && !this.#promptQueue.submitUnsettled()
|
|
2728
|
+
&& !this.#takeBack.holdsField());
|
|
2850
2729
|
/*
|
|
2851
|
-
*
|
|
2852
|
-
*
|
|
2853
|
-
*
|
|
2730
|
+
* "Session paused": Esc from the app keyboard with focus outside the card comes here, not through "Deny", and Esc
|
|
2731
|
+
* on the pause stays a refusal (`#pauseBlocksEscape`): before any state change and after the field read above, so
|
|
2732
|
+
* no read follows the gate before the key. `refuseDecision` restores the card the manager took at the interrupt.
|
|
2854
2733
|
*/
|
|
2855
2734
|
if ((await this.#pauseBlocksEscape()).blocks) {
|
|
2856
2735
|
if (!this.#disposed) {
|
|
2857
|
-
this.#
|
|
2736
|
+
refuseDecision(this.#refusals, PAUSE_ESCAPE_MESSAGE, 'przerwanie: Esc na pauzie „Session paused”', 'terminal-only');
|
|
2858
2737
|
}
|
|
2859
2738
|
return false;
|
|
2860
2739
|
}
|
|
@@ -2866,9 +2745,9 @@ export class HerdrDriver {
|
|
|
2866
2745
|
*/
|
|
2867
2746
|
this.#turnGuard.clearWatchdog();
|
|
2868
2747
|
this.#turnGuard.localCommand = null;
|
|
2869
|
-
// Set again here: a send that was in flight when Esc came cleared the flag in `afterSubmit`, yet
|
|
2870
|
-
//
|
|
2871
|
-
// conversation: its field holds that conversation's text, not the prompt this interrupt was accepted for.
|
|
2748
|
+
// Set again here: a send that was in flight when Esc came cleared the flag in `afterSubmit`, yet Esc may hand
|
|
2749
|
+
// that prompt back to its field (CLI 2.1.329), and the next send would type behind it. Not after a move to
|
|
2750
|
+
// another conversation: its field holds that conversation's text, not the prompt this interrupt was accepted for.
|
|
2872
2751
|
if (this.#agentSessionId === session)
|
|
2873
2752
|
this.#needsEscape = true;
|
|
2874
2753
|
/*
|
|
@@ -2899,6 +2778,7 @@ export class HerdrDriver {
|
|
|
2899
2778
|
throw err;
|
|
2900
2779
|
}
|
|
2901
2780
|
}, { method: 'send_keys', keys: ['escape'] }, 'interrupt');
|
|
2781
|
+
this.#returnedPrompt.start(sent ? expected : null, () => this.#disposed || token !== this.#interruptProbeToken || this.#agentSessionId !== session);
|
|
2902
2782
|
if (sent && !this.#disposed) {
|
|
2903
2783
|
/*
|
|
2904
2784
|
* Ślad po geście pisze SERWER, a nie telefon: tylko on zna
|
|
@@ -2919,6 +2799,10 @@ export class HerdrDriver {
|
|
|
2919
2799
|
// Krok, który poległ, oddaje `undefined` — dla przerwania to znaczy „klawisz nie poszedł".
|
|
2920
2800
|
}).then((sent) => sent ?? false);
|
|
2921
2801
|
}
|
|
2802
|
+
/** {@link SessionDriver.returnedPrompt}: the field read after the last delivered `escape` (`returned-prompt.ts`). */
|
|
2803
|
+
returnedPrompt() {
|
|
2804
|
+
return this.#returnedPrompt.answer();
|
|
2805
|
+
}
|
|
2922
2806
|
/**
|
|
2923
2807
|
* Sonda stanu po przerwaniu — poza kolejką wysyłek (nie blokuje kolejnych promptów).
|
|
2924
2808
|
*
|
|
@@ -3073,6 +2957,7 @@ export class HerdrDriver {
|
|
|
3073
2957
|
const waiting = signal.kind === 'waiting' ? signal.dialog : null;
|
|
3074
2958
|
const was = this.#cliReserve.cliWaiting;
|
|
3075
2959
|
this.#cliReserve.cliWaiting = waiting;
|
|
2960
|
+
this.#noHook.registrySignal(signal.kind === 'active');
|
|
3076
2961
|
if (signal.kind === 'active')
|
|
3077
2962
|
this.#cliReserve.cliActiveAt = this.#scheduler.now();
|
|
3078
2963
|
if (waiting === null) {
|
|
@@ -3148,6 +3033,7 @@ export class HerdrDriver {
|
|
|
3148
3033
|
}
|
|
3149
3034
|
this.#turnGuard.clearWatchdog();
|
|
3150
3035
|
this.#consentChannel.dispose();
|
|
3036
|
+
this.#noHook.dispose();
|
|
3151
3037
|
stopTasks(this.#tasks, this.#scheduler);
|
|
3152
3038
|
if (this.#blockedTimer !== null) {
|
|
3153
3039
|
this.#scheduler.clearTimeout(this.#blockedTimer);
|
|
@@ -3204,6 +3090,7 @@ export class HerdrDriver {
|
|
|
3204
3090
|
this.#lastFollowAt = this.#scheduler.now();
|
|
3205
3091
|
// Pole nowej rozmowy nie trzyma promptu zablokowanego w poprzedniej ani tekstu oddanego po jej Enterze.
|
|
3206
3092
|
this.#turnGuard.blockedLeftover = null;
|
|
3093
|
+
this.#returnedPrompt.conversationChanged();
|
|
3207
3094
|
// The new conversation ran no send: a block entry of the old file still on its way decides none (notice only).
|
|
3208
3095
|
this.#turnGuard.executedGeneration = 0;
|
|
3209
3096
|
this.#promptQueue.heldLeftover = null;
|
|
@@ -3272,8 +3159,9 @@ export class HerdrDriver {
|
|
|
3272
3159
|
this.#formReserve.formMisses = 0;
|
|
3273
3160
|
}
|
|
3274
3161
|
// herdr sam widzi blokadę — rezerwa z rejestru oddaje mu ją PO CICHU (ta sama blokada).
|
|
3162
|
+
// The block only changes hands, so the consent-without-hook episode goes on.
|
|
3275
3163
|
if (status === 'blocked')
|
|
3276
|
-
this.#cliReserve.dropCliHold();
|
|
3164
|
+
this.#noHook.handover(() => { this.#cliReserve.dropCliHold(); });
|
|
3277
3165
|
/*
|
|
3278
3166
|
* Spóźniony herdr `working` (albo `idle`/`done`), a rejestr CLI dalej mówi `waiting`:
|
|
3279
3167
|
* dialog sprzed chwili wciąż stoi, więc blokada przechodzi na rezerwę z rejestru — bez nowego
|
|
@@ -3306,6 +3194,8 @@ export class HerdrDriver {
|
|
|
3306
3194
|
// Nowa blokada = nowy ekran i nowy identyfikator dialogu spoza jsonl.
|
|
3307
3195
|
this.#blockedSeq += 1;
|
|
3308
3196
|
this.#blockedAt = this.#scheduler.now();
|
|
3197
|
+
// A transcript not found yet is looked up now, and the evaluation waits for that lookup before the screen.
|
|
3198
|
+
this.#follower?.lookUpTranscript?.();
|
|
3309
3199
|
this.#dropScreen();
|
|
3310
3200
|
this.#reportBlocked();
|
|
3311
3201
|
return;
|
|
@@ -3437,6 +3327,7 @@ export class HerdrDriver {
|
|
|
3437
3327
|
// Blokada EFEKTYWNA: formularz trzymany przez rezerwę też stoi i też może się podmienić.
|
|
3438
3328
|
const wanted = !this.#disposed && this.#inScope && this.#blockedNow();
|
|
3439
3329
|
if (!wanted) {
|
|
3330
|
+
this.#noHook.blockEnded();
|
|
3440
3331
|
if (this.#blockedTimer !== null) {
|
|
3441
3332
|
this.#scheduler.clearTimeout(this.#blockedTimer);
|
|
3442
3333
|
this.#blockedTimer = null;
|
|
@@ -3626,6 +3517,7 @@ export class HerdrDriver {
|
|
|
3626
3517
|
resetPulseEcho(this.#pulseEcho);
|
|
3627
3518
|
switch (event.type) {
|
|
3628
3519
|
case 'history': {
|
|
3520
|
+
this.#returnedPrompt.noteHistory(event.messages);
|
|
3629
3521
|
const { messages, output } = withoutCommandOutput(event.messages);
|
|
3630
3522
|
// Wiadomość z kolejki wklejeń stoi w pliku bez Entera Raroga: wpis kolejki się kończy.
|
|
3631
3523
|
for (const m of messages)
|
|
@@ -3642,6 +3534,7 @@ export class HerdrDriver {
|
|
|
3642
3534
|
// zablokowanego promptu pewnie.
|
|
3643
3535
|
if (event.role === 'user')
|
|
3644
3536
|
this.#turnGuard.blockedLeftover = null;
|
|
3537
|
+
this.#returnedPrompt.noteFile([event]);
|
|
3645
3538
|
if (event.role === 'user' && (this.#promptQueue.heldLeftover !== null || this.#promptQueue.submitted !== null)) {
|
|
3646
3539
|
const sent = squashWhitespace(event.blocks.map((block) => (block.type === 'text' ? block.text.text : '')).join(''));
|
|
3647
3540
|
// Pozostałość wstrzymanego promptu albo wiadomości z kolejki wysłana: pole już jej nie trzyma.
|
|
@@ -3994,7 +3887,7 @@ export class HerdrDriver {
|
|
|
3994
3887
|
// Karta bez decyzji postawiona przy OCENIE ekranu — degradacja, nie odmowa wysyłki.
|
|
3995
3888
|
// Kształt przypadku i pochodzenie karty jadą z oceny.
|
|
3996
3889
|
if (action.audit !== null) {
|
|
3997
|
-
this.#
|
|
3890
|
+
auditRefusal(this.#refusals, action.audit, source?.toolName, 'degrade', undefined, {
|
|
3998
3891
|
reqId: action.kind === 'card' ? action.card.active.reqId : action.reqId,
|
|
3999
3892
|
origin: action.kind === 'card' ? action.card.active.origin : action.origin,
|
|
4000
3893
|
// `decideCard` daje kształt przy każdym `audit`; zapas z cache'u ekranu, żeby wpis nie zniknął.
|
|
@@ -4044,7 +3937,10 @@ export class HerdrDriver {
|
|
|
4044
3937
|
* i zrzutu hooka), a WŁAŚCICIELEM stanu jest fasada — rozdzielenie tych dwóch kroków po
|
|
4045
3938
|
* pięciu ścieżkach kończyłoby się kartą wysłaną bez zapamiętania (albo odwrotnie).
|
|
4046
3939
|
*/
|
|
4047
|
-
#showCard(
|
|
3940
|
+
#showCard(built) {
|
|
3941
|
+
this.#noHook.noteCard(built);
|
|
3942
|
+
// The emergency mark from the episode the detector just noted, before the channel gate reads the card.
|
|
3943
|
+
const card = this.#screenFallback.stamp(built);
|
|
4048
3944
|
const event = consentOnlyEvent(card.event, card.active, this.#deps, this.#cliReserve.cliWaiting, {
|
|
4049
3945
|
engineSessionId: this.#agentSessionId, cwd: this.#cwd,
|
|
4050
3946
|
});
|
|
@@ -4060,7 +3956,8 @@ export class HerdrDriver {
|
|
|
4060
3956
|
* (bramka „ta sama karta” nie zamraża oceny), a ocena na koniec czekania wystawia ją, jeśli karta kanału nie
|
|
4061
3957
|
* przyszła.
|
|
4062
3958
|
*/
|
|
4063
|
-
|
|
3959
|
+
// Through the grace of a dialog without a hook trace the card waits too; the judgement orders the evaluation.
|
|
3960
|
+
if (this.#consentChannel.consentCardWait() || this.#screenFallback.waits(card)) {
|
|
4064
3961
|
this.#undecided = null;
|
|
4065
3962
|
return;
|
|
4066
3963
|
}
|
|
@@ -4071,6 +3968,7 @@ export class HerdrDriver {
|
|
|
4071
3968
|
this.#undecided = undecided
|
|
4072
3969
|
? { active: card.active, cliDialog: 'cliDialog' in event ? event.cliDialog ?? null : null }
|
|
4073
3970
|
: null;
|
|
3971
|
+
this.#noHook.cardShown(card, event);
|
|
4074
3972
|
this.#emit(event);
|
|
4075
3973
|
this.#auditBlockCard(card.active);
|
|
4076
3974
|
}
|
|
@@ -4179,7 +4077,7 @@ export class HerdrDriver {
|
|
|
4179
4077
|
}
|
|
4180
4078
|
else {
|
|
4181
4079
|
// Ekran z bramki wysyłki wchodzi do cache'u jak każdy odczyt dialogu — zrzut odmowy
|
|
4182
|
-
// (
|
|
4080
|
+
// (`refusalDump`) bierze go stamtąd.
|
|
4183
4081
|
this.#screenText = screen;
|
|
4184
4082
|
this.#screenAt = this.#scheduler.now();
|
|
4185
4083
|
this.#notePause(screen);
|
|
@@ -4192,7 +4090,7 @@ export class HerdrDriver {
|
|
|
4192
4090
|
const origin = { source: 'screen' };
|
|
4193
4091
|
// Karta bez zatwierdzania = odmowa w dzienniku: suma odmów ma ją policzyć
|
|
4194
4092
|
// razem z resztą „odpowiedz w terminalu", a zrzut ekranu wyjaśnia, co stało.
|
|
4195
|
-
this.#
|
|
4093
|
+
auditRefusal(this.#refusals, 'consent-dialog', `${SCREEN_DIALOG_TOOL}:${dialog}`, 'degrade', undefined, {
|
|
4196
4094
|
reqId, origin, diagnosis: { mismatchReason: null, ...dialogShapeOf(text) },
|
|
4197
4095
|
});
|
|
4198
4096
|
this.#clearActive('dialog zgody CLI');
|