@rarog/server 1.1.2-beta.1 → 1.1.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/node_modules/@rarog/shared/package.json +1 -1
  2. package/node_modules/@rarog/shared/src/decode.js +43 -1
  3. package/node_modules/@rarog/shared/src/notify-copy.js +1 -0
  4. package/node_modules/@rarog/shared/src/protocol/context.js +57 -0
  5. package/node_modules/@rarog/shared/src/protocol/coordination.js +42 -0
  6. package/node_modules/@rarog/shared/src/protocol/dialog-live.js +117 -0
  7. package/node_modules/@rarog/shared/src/protocol/files.js +1 -1
  8. package/node_modules/@rarog/shared/src/protocol/inbox.js +6 -0
  9. package/node_modules/@rarog/shared/src/protocol/presence.js +47 -0
  10. package/node_modules/@rarog/shared/src/protocol.js +14 -146
  11. package/node_modules/@rarog/shared/src/rest.js +16 -1
  12. package/node_modules/@rarog/shared/src/sentences/push.js +6 -0
  13. package/node_modules/@rarog/shared/src/sentences/rest.js +9 -0
  14. package/node_modules/@rarog/shared/src/sentences/restart.js +1 -0
  15. package/node_modules/@rarog/shared/src/sentences/session.js +24 -0
  16. package/package.json +2 -2
  17. package/plugin/rarog/.claude-plugin/plugin.json +4 -0
  18. package/plugin/rarog/bin/rarog-coordinator +7 -0
  19. package/plugin/rarog/hooks/hooks.json +18 -0
  20. package/plugin/rarog/hooks/recipient.mjs +95 -0
  21. package/plugin/rarog/lib/coordinator.mjs +1340 -0
  22. package/plugin/rarog/lib/threads.mjs +350 -0
  23. package/plugin/rarog/skills/coordinator/SKILL.md +111 -0
  24. package/plugin/rarog/skills/coordinator/check-and-merge.md +46 -0
  25. package/plugin/rarog/skills/coordinator/close-thread.md +15 -0
  26. package/plugin/rarog/skills/coordinator/role.md +61 -0
  27. package/plugin/rarog/skills/coordinator/send-back.md +39 -0
  28. package/plugin/rarog/skills/coordinator/start-thread.md +43 -0
  29. package/server/src/bootstrap/coordination.js +49 -0
  30. package/server/src/bootstrap/coordinator-start.js +27 -0
  31. package/server/src/bootstrap/inbox.js +4 -0
  32. package/server/src/bootstrap/push.js +24 -1
  33. package/server/src/companion/catalog.js +1 -1
  34. package/server/src/companion/index.js +2 -4
  35. package/server/src/config/flags.js +4 -0
  36. package/server/src/config-env.js +15 -0
  37. package/server/src/config.js +17 -3
  38. package/server/src/coordination/merge-events.js +86 -0
  39. package/server/src/coordination/merge-prompt.js +244 -0
  40. package/server/src/coordination/registry.js +289 -0
  41. package/server/src/coordination/state.js +94 -0
  42. package/server/src/coordination/summary.js +422 -0
  43. package/server/src/coordination/thread-file.js +245 -0
  44. package/server/src/coordination/thread-git.js +110 -0
  45. package/server/src/coordination/watch.js +237 -0
  46. package/server/src/demo/content/coordinator.js +89 -0
  47. package/server/src/demo/content/en.js +57 -1
  48. package/server/src/demo/content/pl.js +57 -1
  49. package/server/src/demo/inbox.js +12 -0
  50. package/server/src/demo/mock-herdr.js +3 -2
  51. package/server/src/demo/review-routes.js +2 -2
  52. package/server/src/demo/seeds.js +20 -2
  53. package/server/src/drivers/herdr/live-dialog.js +412 -0
  54. package/server/src/drivers/herdr/live-step.js +261 -0
  55. package/server/src/drivers/herdr/pause-gate.js +60 -0
  56. package/server/src/drivers/herdr/returned-prompt.js +4 -1
  57. package/server/src/drivers/herdr/screen-fallback.js +50 -0
  58. package/server/src/drivers/herdr/start-dialog-gate.js +4 -0
  59. package/server/src/drivers/herdr-driver.js +88 -66
  60. package/server/src/files/refusals.js +9 -2
  61. package/server/src/files/session-gate.js +5 -4
  62. package/server/src/git-branch-diff.js +194 -0
  63. package/server/src/herdr/argv.js +34 -3
  64. package/server/src/herdr/audit.js +32 -1
  65. package/server/src/herdr/background/cli-shapes.js +19 -0
  66. package/server/src/herdr/background/queued-prompt.js +46 -0
  67. package/server/src/herdr/background/work.js +12 -0
  68. package/server/src/herdr/client.js +22 -46
  69. package/server/src/herdr/commands/catalog.js +11 -7
  70. package/server/src/herdr/commands/discover.js +33 -1
  71. package/server/src/herdr/commands/index.js +3 -2
  72. package/server/src/herdr/dialogs/index.js +9 -0
  73. package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +4 -56
  74. package/server/src/herdr/dialogs/live/model.js +220 -0
  75. package/server/src/herdr/dialogs/live/policy.js +108 -0
  76. package/server/src/herdr/dialogs/live/view.js +261 -0
  77. package/server/src/herdr/dialogs/screen/form.js +4 -3
  78. package/server/src/herdr/dialogs/screen/signatures.js +23 -0
  79. package/server/src/herdr/engines.js +96 -0
  80. package/server/src/herdr/history-steps.js +9 -4
  81. package/server/src/herdr/identity.js +20 -5
  82. package/server/src/herdr/jsonl-follow.js +20 -1
  83. package/server/src/herdr/plugin-copy.js +281 -0
  84. package/server/src/herdr/session-index.js +19 -0
  85. package/server/src/herdr/supervisor.js +16 -13
  86. package/server/src/herdr/types.js +1 -0
  87. package/server/src/inbox/card.js +31 -8
  88. package/server/src/inbox/heads.js +1 -0
  89. package/server/src/inbox/inbox.js +21 -4
  90. package/server/src/inbox/removals.js +10 -1
  91. package/server/src/index.js +37 -5
  92. package/server/src/notify/content.js +27 -0
  93. package/server/src/notify/index.js +7 -3
  94. package/server/src/notify/live-activity-state.js +14 -5
  95. package/server/src/notify/policy.js +49 -11
  96. package/server/src/notify/ready-to-merge.js +148 -0
  97. package/server/src/project-root.js +233 -0
  98. package/server/src/routes/sessions.js +68 -2
  99. package/server/src/sessions/branch-diff.js +57 -0
  100. package/server/src/sessions/cli-registry.js +17 -3
  101. package/server/src/sessions/companion-scope.js +2 -1
  102. package/server/src/sessions/consent-cards.js +49 -2
  103. package/server/src/sessions/conversation-lists.js +4 -1
  104. package/server/src/sessions/coordinator-start.js +172 -0
  105. package/server/src/sessions/demo-modules.js +1 -0
  106. package/server/src/sessions/demo-seeds.js +100 -0
  107. package/server/src/sessions/driver-events.js +61 -11
  108. package/server/src/sessions/herdr-lifecycle.js +11 -4
  109. package/server/src/sessions/launch-gate.js +36 -11
  110. package/server/src/sessions/live-dialog.js +69 -0
  111. package/server/src/sessions/manager.js +124 -282
  112. package/server/src/sessions/owner-turn.js +36 -0
  113. package/server/src/sessions/seen-marks.js +31 -12
  114. package/server/src/sessions/session-dialog.js +82 -0
  115. package/server/src/sessions/session-git.js +1 -0
  116. package/server/src/sessions/session-scope.js +6 -5
  117. package/server/src/sessions/session-take-back.js +5 -0
  118. package/server/src/sessions/session.js +72 -7
  119. package/server/src/sessions/state-machine.js +2 -0
  120. package/server/src/sessions/state-sentences.js +87 -30
  121. package/server/src/sessions/waiting-line.js +49 -0
  122. package/server/src/transcript-import.js +20 -2
  123. package/server/src/version.js +4 -0
  124. /package/server/src/{companion/asks-owner.js → asks-owner.js} +0 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Esc gate of the "Session paused" dialog (`docs/dialogs.md`, "CLI dialogs answered in the terminal"): the pause trace
3
+ * that every dialog screen read leaves in the blocked state, and the fresh read right before an Esc that refuses
4
+ * the key on a pause. It only judges; the driver facade sends or refuses the key. It does not import the facade.
5
+ */
6
+ import { SESSION_PAUSED_DIALOG, parseOptions, sessionPausedDialog } from '../../herdr/dialogs/index.js';
7
+ export class PauseGate {
8
+ /**
9
+ * Numer blokady, w której ostatni odczyt ekranu pokazał pauzę „Session paused” (`pauseBlocksEscape`);
10
+ * `null` = żaden. Przeżywa odmowę Esc, zgaszoną kartę i odczyt bez dialogu (przemalowanie); zdejmuje go
11
+ * dopiero odczyt z INNYM czytelnym dialogiem, a koniec blokady albo nowa blokada go unieważniają.
12
+ */
13
+ #pauseSeq = null;
14
+ #port;
15
+ constructor(port) {
16
+ this.#port = port;
17
+ }
18
+ /**
19
+ * Czy `escape` trafiłby w pauzę „Session paused"?
20
+ *
21
+ * Esc zmierzono tylko na pauzie wywołanej atrapą API (CLI 2.1.322), bo prawdziwej pauzy nie wolno wywołać celowo
22
+ * (to mechanizm bezpieczeństwa modelu), a pauza nie ma stopki, która by go nazywała. Dlatego „Odrzuć" i przerwanie
23
+ * nie wysyłają na nią klawisza.
24
+ *
25
+ * Ekran czytamy ŚWIEŻO, tuż przed klawiszem (`readFresh` — ten sam ekran trafia do zrzutu odmowy),
26
+ * przy każdej blokadzie (`blockedNow`): karta i ostatni odczyt nie dowodzą, że pauzy nie ma — dialog
27
+ * potrafi się podmienić w miejscu, zanim ocena przeczyta ekran. Bez blokady
28
+ * i bez podejrzenia Esc idzie jak dotąd, bez odczytu (przerwanie zwykłej tury). Podejrzenie pauzy to karta
29
+ * pauzy albo ślad pauzy z odczytu w tej blokadzie (`#pauseSeq`, przeżywa odmowę i zgaszoną kartę).
30
+ * Odmowa, gdy:
31
+ * - pauza stoi na świeżym ekranie (`sessionPausedDialog` — każdy wariant, także spoza listy);
32
+ * - przy podejrzeniu: odczyt się nie udał albo ekran nie pokazuje żadnego dialogu (przemalowanie) —
33
+ * nie wiadomo, czy pauza zeszła.
34
+ * Inny czytelny dialog = pauza zeszła (ślad gaśnie w `notePause`), Esc idzie jak dotąd.
35
+ *
36
+ * @returns `blocks` = odmowa; `text` = świeży ekran tej bramki (`null` bez odczytu albo po nieudanym), z którego
37
+ * „Odrzuć” po klawiszu poznaje zamknięty dialog (driver, `#clearHookAfterDecision`)
38
+ */
39
+ async pauseBlocksEscape() {
40
+ const suspected = this.#port.activeTerminalDialog() === SESSION_PAUSED_DIALOG
41
+ || (this.#pauseSeq === this.#port.blockedSeq() && this.#port.blockedNow());
42
+ if (!suspected && !this.#port.blockedNow())
43
+ return { blocks: false, text: null };
44
+ const text = await this.#port.readFresh();
45
+ if (text === null)
46
+ return { blocks: suspected, text: null };
47
+ const fresh = parseOptions(text);
48
+ return { blocks: fresh === null ? suspected : sessionPausedDialog(fresh), text };
49
+ }
50
+ /**
51
+ * Ślad pauzy z KAŻDEGO odczytu ekranu dialogu (`#pauseSeq`): pauza zapisuje numer blokady, inny czytelny
52
+ * dialog go zdejmuje, ekran bez dialogu (przemalowanie, odczyt w pół klatki) zostawia go bez zmian.
53
+ */
54
+ notePause(text) {
55
+ const dialog = parseOptions(text);
56
+ if (dialog === null)
57
+ return;
58
+ this.#pauseSeq = sessionPausedDialog(dialog) ? this.#port.blockedSeq() : null;
59
+ }
60
+ }
@@ -49,12 +49,15 @@ export class ReturnedPrompt {
49
49
  }
50
50
  /**
51
51
  * Human prompts of the conversation file, in file order: the newest one is the turn's prompt. A harness notice, a
52
- * command output and an entry with an image are no prompt the field could show as text.
52
+ * command output and an entry with an image are no prompt the field could show as text, and a message from another
53
+ * session was typed into no field.
53
54
  */
54
55
  noteFile(entries) {
55
56
  for (const entry of entries) {
56
57
  if (entry.role !== 'user' || entry.notice !== undefined || entry.commandOutput !== undefined)
57
58
  continue;
59
+ if (entry.peer === true)
60
+ continue;
58
61
  const texts = entry.blocks.map((block) => (block.type === 'text' && !('ref' in block.text) ? block.text.text : null));
59
62
  if (texts.length > 0 && texts.every((text) => text !== null))
60
63
  this.#note(texts.join('\n'));
@@ -106,6 +106,36 @@ export class ScreenFallback {
106
106
  return refuse('judgement');
107
107
  }
108
108
  }
109
+ /**
110
+ * The consent channel facts of the live dialog card (`herdr/dialogs/live/policy.ts`): the live mode, the judgement of
111
+ * the standing no-hook episode, the hook trace and the hook requests now, the hook process and a foreign hook from the
112
+ * judgement, the restart grace. `toolUse`: the transcript entry of the dialog on screen is known. `episode: false`:
113
+ * the standing episode came with a card of another dialog than the one on screen, so the facts are those without an
114
+ * episode. A fact that cannot be read is a doubt (`null`, or the value that refuses Enter); never throws.
115
+ */
116
+ liveFacts(toolUse, episode) {
117
+ const sources = this.#deps.consentNoHook;
118
+ let mode = null;
119
+ try {
120
+ mode = consentModeNow(this.#deps);
121
+ }
122
+ catch {
123
+ mode = null;
124
+ }
125
+ let standing = null;
126
+ try {
127
+ standing = episode ? this.#port.standing() : null;
128
+ }
129
+ catch {
130
+ standing = null;
131
+ }
132
+ const judgement = standing?.judgement ?? null;
133
+ return {
134
+ mode, judged: judgement !== null, trace: standing === null ? null : this.#trace(sources, standing),
135
+ hookWaits: this.#hookWaits(), hookRunning: judgement?.hookRunning ?? null,
136
+ foreignHook: judgement?.foreignHook ?? null, restarting: this.#restarting(sources), toolUse,
137
+ };
138
+ }
109
139
  /**
110
140
  * The guard that takes the button of a marked card under the live mode and class, the ones the card gate read when
111
141
  * it refused the digit; `mode` when the rule cannot be asked.
@@ -136,6 +166,26 @@ export class ScreenFallback {
136
166
  // The late hook then goes the desk fallback way.
137
167
  }
138
168
  }
169
+ /**
170
+ * Enter of the live dialog card (`live-step.ts`) is about to go to the dialog of a permission card's call in channel
171
+ * mode `main` or `all`: the consent cycle notes it like a digit ({@link keyNoted}), with the call input and the start
172
+ * of the standing no-hook episode, so that a hook of this dialog whose request comes after the note goes back to the
173
+ * terminal. Without an episode or outside those modes nothing is noted. Synchronous, right before the key.
174
+ */
175
+ liveKeyNoted(toolName, input) {
176
+ try {
177
+ const mode = consentModeNow(this.#deps);
178
+ const standing = this.#port.standing();
179
+ if ((mode !== 'main' && mode !== 'all') || standing === null)
180
+ return;
181
+ this.#deps.consentNoHook?.screenKey?.(standing.sessionId, {
182
+ toolName, inputSha256: canonicalSha256(input), at: this.#deps.now(), since: standing.t0,
183
+ });
184
+ }
185
+ catch {
186
+ // The late hook then goes the desk fallback way.
187
+ }
188
+ }
139
189
  /** The digit went out: the `screen fallback key` line. */
140
190
  keySent(verdict) {
141
191
  this.#log(screenFallbackKeyLine(verdict.line));
@@ -78,6 +78,10 @@ export class StartDialogGate {
78
78
  this.note(text);
79
79
  return this.#standing !== null;
80
80
  }
81
+ /** The start dialog remembered now, without a read; `null` outside the start phase or when none stands. */
82
+ standing() {
83
+ return this.#phase() === null ? null : this.#standing;
84
+ }
81
85
  /** A card was shown: the sentence of the start dialog under it, once per dialog. */
82
86
  cardShown() {
83
87
  const dialog = this.#phase() === null ? null : this.#standing;
@@ -14,6 +14,7 @@ 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 { PauseGate } from './herdr/pause-gate.js';
17
18
  import { ReturnedPrompt } from './herdr/returned-prompt.js';
18
19
  import { StartDialogGate, clientNotingScreens } from './herdr/start-dialog-gate.js';
19
20
  import { TurnGuard } from './herdr/turn-guard.js';
@@ -25,11 +26,13 @@ import { ConsentNoHook } from './herdr/consent-no-hook.js';
25
26
  import { ScreenFallback } from './herdr/screen-fallback.js';
26
27
  import { Layer2Cards, isLayer2Id, layer2HoldsKeys } from './herdr/layer2-card.js';
27
28
  import { Layer2Step } from './herdr/layer2-step.js';
29
+ import { LiveDialogCards } from './herdr/live-dialog.js';
30
+ import { LiveStep } from './herdr/live-step.js';
28
31
  import { approveContext, auditRefusal, layer2KeyRefusal, refuseDecision, refuseNote, refuseSend, reportStaleDecision, } from './herdr/refusals.js';
29
32
  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, START_DIALOG_REFUSED_MESSAGE, 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';
30
- import { shadowAuditFields } from '../herdr/audit.js';
33
+ import { pickLiveFields, shadowAuditFields } from '../herdr/audit.js';
31
34
  import { diagnosisFields, originFields } from './herdr/audit-fields.js';
32
- import { ASK_USER_QUESTION_TOOL, SANDBOX_NETWORK_TOOL, SESSION_PAUSED_DIALOG, canonicalLabel, exitDialogTasks, matchKnownDialog, parseOptions, resolveOptions, sameDialogIdentity, sessionPausedDialog, standingConsentDialog, } from '../herdr/dialogs/index.js';
35
+ import { ASK_USER_QUESTION_TOOL, SANDBOX_NETWORK_TOOL, canonicalLabel, exitDialogTasks, matchKnownDialog, parseOptions, resolveOptions, sameDialogIdentity, sessionPausedDialog, standingConsentDialog, } from '../herdr/dialogs/index.js';
33
36
  import { SHADOW_DEADLINE_MS, registryEvidenceFromSignal, shadowCardEligible } from '../herdr/dialogs/index.js';
34
37
  import { consentDigitRefused, consentModeNow, consentOnlyEvent } from '../herdr/dialogs/index.js';
35
38
  import { collapseFooterMode, parseModeFooter } from '../herdr/dialogs/screen/mode-footer.js';
@@ -255,12 +258,6 @@ export class HerdrDriver {
255
258
  #screenText = null;
256
259
  /** Kiedy powstał {@link #screenText} — cache dialogu ma TERMIN WAŻNOŚCI. */
257
260
  #screenAt = 0;
258
- /**
259
- * Numer blokady, w której ostatni odczyt ekranu pokazał pauzę „Session paused” (`#pauseBlocksEscape`);
260
- * `null` = żaden. Przeżywa odmowę Esc, zgaszoną kartę i odczyt bez dialogu (przemalowanie); zdejmuje go
261
- * dopiero odczyt z INNYM czytelnym dialogiem, a koniec blokady albo nowa blokada go unieważniają.
262
- */
263
- #pauseSeq = null;
264
261
  /** Zegar ponownej oceny stojącego dialogu; `null` = panel nie jest zablokowany. */
265
262
  #blockedTimer = null;
266
263
  /**
@@ -296,12 +293,18 @@ export class HerdrDriver {
296
293
  #refusals;
297
294
  /** No key or text to a start dialog herdr reads as ready: `drivers/herdr/start-dialog-gate.ts`. */
298
295
  #startGate;
296
+ /** No Esc on the "Session paused" dialog: `drivers/herdr/pause-gate.ts`. */
297
+ #pauseGate;
299
298
  /** The wait behind a command dialog the driver confirmed: `drivers/herdr/command-dialog-settle.ts`. */
300
299
  #commandSettle;
301
300
  /** The layer 2 card with buttons (`docs/dialog-card.md`): `drivers/herdr/layer2-card.ts`. */
302
301
  #layer2Cards;
303
302
  /** The key from a layer 2 card, after its proof: `drivers/herdr/layer2-step.ts`. */
304
303
  #layer2Step;
304
+ /** The live dialog card (`docs/dialogs.md`, "Live dialog card"): `drivers/herdr/live-dialog.ts`. */
305
+ #live;
306
+ /** A key of the live dialog card, after its checks: `drivers/herdr/live-step.ts`. */
307
+ #liveStep;
305
308
  /** Zwalnianie sierot trybu cienia w toku — następny odczyt rejestru nie zaczyna drugiego. */
306
309
  #shadowReleasing = false;
307
310
  /** The consent channel as the driver sees it: `drivers/herdr/consent-channel.ts`. */
@@ -369,6 +372,10 @@ export class HerdrDriver {
369
372
  startPhase: deps.startPhase ?? (() => null),
370
373
  readScreen: () => this.#readDialog(true), system: (text) => { this.#system(text); },
371
374
  });
375
+ this.#pauseGate = new PauseGate({
376
+ activeTerminalDialog: () => this.#activeReq?.terminalDialog, blockedSeq: () => this.#blockedSeq,
377
+ blockedNow: () => this.#blockedNow(), readFresh: () => this.#readDialog(true),
378
+ });
372
379
  this.#commandSettle = new CommandDialogSettle({ pollMs: deps.modelConfirmPollMs ?? MODEL_CONFIRM_POLL_MS }, {
373
380
  disposed: () => this.#disposed,
374
381
  readScreen: () => this.#deps.client.readScreen(this.#paneId, 'detection').then((s) => {
@@ -425,6 +432,22 @@ export class HerdrDriver {
425
432
  screenText: () => this.#screenText, standing: () => this.#noHook.standing(),
426
433
  keyHookWaits: () => this.#promptQueue.keyHookWaits(), pendingCallId: () => this.#pending?.id ?? null,
427
434
  });
435
+ this.#live = new LiveDialogCards({
436
+ level: deps.dialogLive ?? 0, inScope: this.#inScope, scheduler: this.#scheduler, pollMs: this.#blockedPollMs,
437
+ graceMs: this.#debounceMs * 2, cliReserve: this.#cliReserve, startDialog: () => this.#startGate.standing(),
438
+ channelCard: (onError) => this.#consentChannel.consentCardStands(onError),
439
+ consentFacts: (toolUse, episode) => this.#screenFallback.liveFacts(toolUse, episode), engine: this.#engine,
440
+ }, {
441
+ disposed: () => this.#disposed, blocked: () => this.#blockedNow(), consentDialog: () => this.#consentDialog,
442
+ blockedAt: () => this.#blockedAt, activeReq: () => this.#activeReq, engineSession: () => this.#agentSessionId,
443
+ shielded: () => this.#answerShieldUp() || this.#decidedShield() !== null, readDialog: () => this.#readDialog(false),
444
+ emit: (live) => { this.#emit({ type: 'dialog-live', ...(live === null ? {} : { live }) }); },
445
+ audit: (fields) => { this.#audit({ method: 'live-card', ...fields }); }, evaluate: () => this.#evaluate(),
446
+ });
447
+ this.#liveStep = new LiveStep({
448
+ cards: this.#live, screenFallback: this.#screenFallback, settleMs: deps.escSettleMs ?? ESC_SETTLE_MS,
449
+ registryRead: deps.consentRegistryRead, engine: this.#engine,
450
+ }, this.#liveStepPort());
428
451
  this.#promptQueue.restore(this.#engine === 'claude', () => ++this.#turnGuard.sendGeneration);
429
452
  if (this.#follower !== null)
430
453
  void this.#pumpFollower(this.#follower);
@@ -875,6 +898,30 @@ export class HerdrDriver {
875
898
  this.#rearmAfterScreenAnswer(answered);
876
899
  return true;
877
900
  }
901
+ #liveStepPort() {
902
+ return {
903
+ ...this.#layer2StepPort(), audit: (entry) => { this.#audit(entry); },
904
+ sendLiveKey: (key, entry) => this.#liveSendKey(key, entry),
905
+ noteRegistry: (signal) => { this.noteCliWaiting(signal); },
906
+ };
907
+ }
908
+ /**
909
+ * One key of the live dialog card: past the start gate and the pause gate (the live card shows the dialog as the
910
+ * terminal does), so not through `#send`. The attempt goes to the audit; a failure tells the transcript as any send.
911
+ */
912
+ async #liveSendKey(key, entry) {
913
+ const { client } = this.#deps;
914
+ try {
915
+ await (key === 'escape' ? client.sendKeys(this.#paneId, [key]) : client.sendDialogKey(this.#paneId, key));
916
+ this.#audit(entry);
917
+ return 'sent';
918
+ }
919
+ catch (err) {
920
+ this.#audit(entry);
921
+ this.#reportSendError(err);
922
+ return herdrCode(err) === 'herdr-read-only' ? 'off' : 'failed';
923
+ }
924
+ }
878
925
  /** Port of the two fallbacks: each module types only its own part, at most 14 members. */
879
926
  #reservePort() {
880
927
  return {
@@ -1147,12 +1194,16 @@ export class HerdrDriver {
1147
1194
  // Po wyczerpaniu prób i tak piszemy: kolejne odmowy wyglądałyby jak martwy composer.
1148
1195
  return true;
1149
1196
  }
1197
+ /** A key of the live dialog card (`drivers/herdr/live-step.ts`); no card outside the work area or off Claude Code. */
1198
+ dialogKey(body) {
1199
+ return this.#liveStep.key(body);
1200
+ }
1150
1201
  /**
1151
1202
  * Decyzja o czekającym narzędziu.
1152
1203
  *
1153
1204
  * `deny` nie potrzebuje ani cyfr, ani zgodnego `reqId`: `escape` na dialogu zgody to odmowa, a odmowa nie daje
1154
1205
  * narzędziu żadnego prawa. Esc nie wszędzie jest jednak tylko odmową: na dialogu zaufania katalogu zamyka
1155
- * `claude` (pomiar na CLI 2.1.299), a na pauzie „Session paused” (`#pauseBlocksEscape`) nie nazywa
1206
+ * `claude` (pomiar na CLI 2.1.299), a na pauzie „Session paused” (`pause-gate.ts`) nie nazywa
1156
1207
  * go żadna stopka, więc przy blokadzie pauzy decyduje świeży ekran. `allow` przechodzi tylko
1157
1208
  * wtedy, gdy karta pochodzi z udanego cross-checku ekran ↔ jsonl i ma DOKŁADNIE jedną opcję
1158
1209
  * „tak, ten jeden raz" — inaczej jest no-opem z wyjaśnieniem w transkrypcie.
@@ -1168,13 +1219,17 @@ export class HerdrDriver {
1168
1219
  if (this.#disposed)
1169
1220
  return Promise.resolve(STALE);
1170
1221
  if (decision === 'deny') {
1171
- // Bound to the card standing now, before the queue: a layer 2 card takes it only through its step.
1222
+ // Bound to the card standing now, before the queue: a layer 2 card takes it only through its step, and a live
1223
+ // card's occurrence takes one key, from either path (a live key in flight refuses the deny).
1172
1224
  const bound = this.#layer2Step.bindEscape(this.#activeReq);
1225
+ const liveBound = this.#liveStep.bindDeny();
1226
+ if (liveBound === null)
1227
+ return Promise.resolve(refused('in-flight'));
1173
1228
  const step = this.#enqueue(async () => {
1174
1229
  // Tryb cienia: plik cienia PRZED klawiszem, reszta kroku bez zmian (bez kanału `shadow` = `null`).
1175
1230
  const shadow = this.#shadowChannel() === undefined ? null : await this.#shadowStep('deny', this.#activeReq);
1176
1231
  // Jedyny wyjątek od „deny zawsze”: pauza „Session paused” — świeży ekran tuż przed klawiszem.
1177
- const pause = await this.#pauseBlocksEscape();
1232
+ const pause = await this.#pauseGate.pauseBlocksEscape();
1178
1233
  if (pause.blocks) {
1179
1234
  this.#shadowKeySent(shadow, false);
1180
1235
  if (this.#disposed)
@@ -1195,8 +1250,9 @@ export class HerdrDriver {
1195
1250
  this.#shadowKeySent(shadow, false);
1196
1251
  return STALE;
1197
1252
  }
1198
- // The layer 2 occurrence bound above, or a layer 2 card issued since: never today's Esc below.
1199
- const layer2 = this.#layer2Step.escapeBound(bound);
1253
+ // The layer 2 occurrence bound above, or a layer 2 card issued since: never today's Esc below. The live
1254
+ // occurrence is used right before the Esc, with no `await` up to it.
1255
+ const layer2 = this.#layer2Step.escapeBound(bound) ?? this.#liveStep.denyKey(liveBound, pause.text);
1200
1256
  if (layer2 !== null) {
1201
1257
  this.#shadowKeySent(shadow, false);
1202
1258
  return layer2;
@@ -1250,7 +1306,7 @@ export class HerdrDriver {
1250
1306
  });
1251
1307
  // `undefined` = krok wypadł z kolejki (driver zdążył pójść do `dispose`) — nie ma już
1252
1308
  // czego odrzucać ani czego zdejmować, więc to jest `stale`, nie odmowa.
1253
- return step.then((outcome) => outcome ?? STALE);
1309
+ return step.then((outcome) => this.#liveStep.release(liveBound, outcome ?? STALE));
1254
1310
  }
1255
1311
  if (this.#startGate.holds())
1256
1312
  return Promise.resolve(this.#startDialogRefused('start dialog: approve'));
@@ -1262,7 +1318,7 @@ export class HerdrDriver {
1262
1318
  * to any `screen: true` card would land a hold started on a full consent card in the fallback card without
1263
1319
  * options that replaced it, ending in "which option, unknown" instead of the truth.
1264
1320
  *
1265
- * Jedyny dozwolony rozjazd: adresowanie SESJĄ (`reqId` = id sesji, `#decideHerdrDialog`)
1321
+ * Jedyny dozwolony rozjazd: adresowanie SESJĄ (`reqId` = id sesji, `decideHerdrDialog`)
1266
1322
  * dla dialogu z zamkniętej listy sygnatur — taka karta nie ma wpisu w pending managera,
1267
1323
  * więc nie ma własnego `reqId`, a `allow` filtruje już manager (`herdrDialog` musi stać).
1268
1324
  * Każdy inny rozjazd to tapnięcie w kartę, której już nie ma — mówimy o tym GŁOŚNO,
@@ -2770,10 +2826,10 @@ export class HerdrDriver {
2770
2826
  && !this.#takeBack.holdsField());
2771
2827
  /*
2772
2828
  * "Session paused": Esc from the app keyboard with focus outside the card comes here, not through "Deny", and Esc
2773
- * on the pause stays a refusal (`#pauseBlocksEscape`): before any state change and after the field read above, so
2829
+ * on the pause stays a refusal (`pause-gate.ts`): before any state change and after the field read above, so
2774
2830
  * no read follows the gate before the key. `refuseDecision` restores the card the manager took at the interrupt.
2775
2831
  */
2776
- const pause = await this.#pauseBlocksEscape();
2832
+ const pause = await this.#pauseGate.pauseBlocksEscape();
2777
2833
  if (pause.blocks) {
2778
2834
  if (!this.#disposed) {
2779
2835
  refuseDecision(this.#refusals, PAUSE_ESCAPE_MESSAGE, 'przerwanie: Esc na pauzie „Session paused”', 'terminal-only');
@@ -3081,6 +3137,7 @@ export class HerdrDriver {
3081
3137
  this.#turnGuard.clearWatchdog();
3082
3138
  this.#consentChannel.dispose();
3083
3139
  this.#noHook.dispose();
3140
+ this.#live.dispose();
3084
3141
  stopTasks(this.#tasks, this.#scheduler);
3085
3142
  if (this.#blockedTimer !== null) {
3086
3143
  this.#scheduler.clearTimeout(this.#blockedTimer);
@@ -3303,7 +3360,7 @@ export class HerdrDriver {
3303
3360
  return null;
3304
3361
  this.#screenText = screen.text;
3305
3362
  this.#screenAt = this.#scheduler.now();
3306
- this.#notePause(screen.text);
3363
+ this.#pauseGate.notePause(screen.text);
3307
3364
  this.#noteStartDialog(screen.text);
3308
3365
  return screen.text;
3309
3366
  }
@@ -3313,48 +3370,6 @@ export class HerdrDriver {
3313
3370
  return null;
3314
3371
  }
3315
3372
  }
3316
- /**
3317
- * Czy `escape` trafiłby w pauzę „Session paused"?
3318
- *
3319
- * Esc zmierzono tylko na pauzie wywołanej atrapą API (CLI 2.1.322), bo prawdziwej pauzy nie wolno wywołać celowo
3320
- * (to mechanizm bezpieczeństwa modelu), a pauza nie ma stopki, która by go nazywała. Dlatego „Odrzuć" i przerwanie
3321
- * nie wysyłają na nią klawisza.
3322
- *
3323
- * Ekran czytamy ŚWIEŻO, tuż przed klawiszem (`#readDialog(true)` — ten sam ekran trafia do zrzutu odmowy),
3324
- * przy każdej blokadzie (`#blockedNow`): karta i ostatni odczyt nie dowodzą, że pauzy nie ma — dialog
3325
- * potrafi się podmienić w miejscu, zanim ocena przeczyta ekran. Bez blokady
3326
- * i bez podejrzenia Esc idzie jak dotąd, bez odczytu (przerwanie zwykłej tury). Podejrzenie pauzy to karta
3327
- * pauzy albo ślad pauzy z odczytu w tej blokadzie (`#pauseSeq`, przeżywa odmowę i zgaszoną kartę).
3328
- * Odmowa, gdy:
3329
- * - pauza stoi na świeżym ekranie (`sessionPausedDialog` — każdy wariant, także spoza listy);
3330
- * - przy podejrzeniu: odczyt się nie udał albo ekran nie pokazuje żadnego dialogu (przemalowanie) —
3331
- * nie wiadomo, czy pauza zeszła.
3332
- * Inny czytelny dialog = pauza zeszła (ślad gaśnie w `#notePause`), Esc idzie jak dotąd.
3333
- *
3334
- * @returns `blocks` = odmowa; `text` = świeży ekran tej bramki (`null` bez odczytu albo po nieudanym), z którego
3335
- * „Odrzuć” po klawiszu poznaje zamknięty dialog (`#clearHookAfterDecision`)
3336
- */
3337
- async #pauseBlocksEscape() {
3338
- const suspected = this.#activeReq?.terminalDialog === SESSION_PAUSED_DIALOG
3339
- || (this.#pauseSeq === this.#blockedSeq && this.#blockedNow());
3340
- if (!suspected && !this.#blockedNow())
3341
- return { blocks: false, text: null };
3342
- const text = await this.#readDialog(true);
3343
- if (text === null)
3344
- return { blocks: suspected, text: null };
3345
- const fresh = parseOptions(text);
3346
- return { blocks: fresh === null ? suspected : sessionPausedDialog(fresh), text };
3347
- }
3348
- /**
3349
- * Ślad pauzy z KAŻDEGO odczytu ekranu dialogu (`#pauseSeq`): pauza zapisuje numer blokady, inny czytelny
3350
- * dialog go zdejmuje, ekran bez dialogu (przemalowanie, odczyt w pół klatki) zostawia go bez zmian.
3351
- */
3352
- #notePause(text) {
3353
- const dialog = parseOptions(text);
3354
- if (dialog === null)
3355
- return;
3356
- this.#pauseSeq = sessionPausedDialog(dialog) ? this.#blockedSeq : null;
3357
- }
3358
3373
  /**
3359
3374
  * A successful `detection` read for the start dialog gate: every dialog read and every read of a gate before a key
3360
3375
  * or text, so the gate's last synchronous check before the client call judges the newest screen.
@@ -3587,13 +3602,14 @@ export class HerdrDriver {
3587
3602
  return;
3588
3603
  }
3589
3604
  case 'message': {
3590
- const { commandOutput, ...message } = event;
3605
+ const { commandOutput, peer, ...message } = event;
3591
3606
  // Wpis `user` z pliku (prompt przy Macu, wstrzymane echo, notka harnessu): pole nie trzyma już
3592
- // zablokowanego promptu pewnie.
3593
- if (event.role === 'user')
3607
+ // zablokowanego promptu pewnie. A bubble from another session was typed into no field: it ends nothing there.
3608
+ const typed = event.role === 'user' && peer !== true;
3609
+ if (typed)
3594
3610
  this.#turnGuard.blockedLeftover = null;
3595
3611
  this.#returnedPrompt.noteFile([event]);
3596
- if (event.role === 'user' && (this.#promptQueue.heldLeftover !== null || this.#promptQueue.submitted !== null)) {
3612
+ if (typed && (this.#promptQueue.heldLeftover !== null || this.#promptQueue.submitted !== null)) {
3597
3613
  const sent = squashWhitespace(event.blocks.map((block) => (block.type === 'text' ? block.text.text : '')).join(''));
3598
3614
  // Pozostałość wstrzymanego promptu albo wiadomości z kolejki wysłana: pole już jej nie trzyma.
3599
3615
  if (sent === this.#promptQueue.heldLeftover)
@@ -3605,7 +3621,8 @@ export class HerdrDriver {
3605
3621
  // Wiadomość z kolejki wklejeń stoi w pliku bez Entera Raroga: wpis kolejki się kończy.
3606
3622
  if (event.echoToken !== undefined)
3607
3623
  this.#promptQueue.noteQueuedEcho(event.echoToken);
3608
- this.#emit(message);
3624
+ // The mark of a message from another session reaches the manager as server-only `notFromOwner`.
3625
+ this.#emit(peer === true ? { ...message, notFromOwner: true } : message);
3609
3626
  // Najpierw notka z wynikiem, potem stan: na telefonie wynik stoi, zanim sesja wróci do „czeka”.
3610
3627
  if (commandOutput !== undefined)
3611
3628
  this.#turnGuard.noteCommandOutput(commandOutput);
@@ -3713,6 +3730,7 @@ export class HerdrDriver {
3713
3730
  do {
3714
3731
  this.#evaluateAgain = false;
3715
3732
  await this.#evaluateOnce();
3733
+ await this.#live.observe();
3716
3734
  } while (this.#evaluateAgain && !this.#disposed);
3717
3735
  }
3718
3736
  finally {
@@ -4017,6 +4035,7 @@ export class HerdrDriver {
4017
4035
  // Through the grace of a dialog without a hook trace the card waits too; the judgement orders the evaluation.
4018
4036
  if (this.#consentChannel.consentCardWait() || this.#screenFallback.waits(card)) {
4019
4037
  this.#undecided = null;
4038
+ this.#live.cardHeld(card.active);
4020
4039
  return;
4021
4040
  }
4022
4041
  }
@@ -4027,6 +4046,7 @@ export class HerdrDriver {
4027
4046
  ? { active: card.active, cliDialog: 'cliDialog' in event ? event.cliDialog ?? null : null }
4028
4047
  : null;
4029
4048
  this.#noHook.cardShown(card, event);
4049
+ this.#live.cardShown(card.active, event);
4030
4050
  this.#emit(event);
4031
4051
  this.#startGate.cardShown();
4032
4052
  this.#auditBlockCard(card.active);
@@ -4140,7 +4160,7 @@ export class HerdrDriver {
4140
4160
  // (`refusalDump`) bierze go stamtąd.
4141
4161
  this.#screenText = screen;
4142
4162
  this.#screenAt = this.#scheduler.now();
4143
- this.#notePause(screen);
4163
+ this.#pauseGate.notePause(screen);
4144
4164
  text = screen;
4145
4165
  }
4146
4166
  if (this.#disposed || this.#consentDialog !== dialog)
@@ -4369,6 +4389,7 @@ export class HerdrDriver {
4369
4389
  record.layer2Key = entry.layer2Key;
4370
4390
  if (entry.layer2Outcome !== undefined)
4371
4391
  record.layer2Outcome = entry.layer2Outcome;
4392
+ Object.assign(record, pickLiveFields(entry));
4372
4393
  try {
4373
4394
  this.#deps.audit.log(record);
4374
4395
  }
@@ -4438,6 +4459,7 @@ export class HerdrDriver {
4438
4459
  if (mapped.detail !== undefined)
4439
4460
  event.detail = mapped.detail;
4440
4461
  this.#emit(event);
4462
+ this.#live.stateSent(mapped.state);
4441
4463
  }
4442
4464
  /** Notka `system` w transkrypcie; tekst Raroga, więc zdanie z rejestru (`say`). */
4443
4465
  #system(text) {
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { FILES_BAD_PATH_ERROR, FILES_CODEX_ERROR, FILES_NOT_FOUND_ERROR, FILES_OUT_OF_SCOPE_ERROR, FILE_TOO_LARGE_ERROR, } from '@rarog/shared';
7
7
  import { say } from '@rarog/shared/sentences';
8
+ import { STATE_ONLY_REFUSALS } from '../herdr/engines.js';
8
9
  /** The path failed the shape check; the same sentence as a bad path of the diff routes. */
9
10
  export const BAD_PATH = { status: 400, code: FILES_BAD_PATH_ERROR, sentence: say('rest.diff-bad-path') };
10
11
  /** Nothing to list or send under the path, or the server never shows it: one answer, so it tells nothing apart. */
@@ -25,8 +26,14 @@ const CLOSED = new WeakSet();
25
26
  export function isClosedFolder(refusal) {
26
27
  return CLOSED.has(refusal);
27
28
  }
28
- /** A Codex entry: Rarog only observes it. */
29
- export const CODEX = { status: 400, code: FILES_CODEX_ERROR, sentence: say('rest.files-codex') };
29
+ /**
30
+ * An entry of a state-only engine: Rarog only observes it. The wire code is `codex` for every such engine, so an app
31
+ * build that decodes a newer engine as unknown still turns the session to its fallback source; the sentence names
32
+ * the engine.
33
+ */
34
+ export function stateOnly(engine) {
35
+ return { status: 400, code: FILES_CODEX_ERROR, sentence: STATE_ONLY_REFUSALS[engine].files };
36
+ }
30
37
  /** A pane outside the work area, or a session directory outside it on disk. */
31
38
  export const OUT_OF_SCOPE = {
32
39
  status: 400, code: FILES_OUT_OF_SCOPE_ERROR, sentence: say('rest.files-out-of-scope'),
@@ -8,7 +8,8 @@
8
8
  import { homedir } from 'node:os';
9
9
  import { inWorkAreaOnDisk, onDiskForms, resolveInWorkArea } from '../config/work-area.js';
10
10
  import { FILES_DISK } from './path-rule.js';
11
- import { CODEX, NOT_FOUND, NO_PANE, OUT_OF_SCOPE, closedFolder } from './refusals.js';
11
+ import { NOT_FOUND, NO_PANE, OUT_OF_SCOPE, closedFolder, stateOnly } from './refusals.js';
12
+ import { isStateOnlyEngine } from '../herdr/engines.js';
12
13
  /**
13
14
  * The area of the session directory `cwd`: refused when `cwd` lies outside the work area as written or on disk
14
15
  * (`out-of-scope`), when the way to it passes a guarded folder that a root opens and the folder gate holds closed
@@ -34,14 +35,14 @@ export function filesArea(cwd, config, disk = FILES_DISK.area) {
34
35
  return { ok: true, value: { cwd, realCwd, roots, realRoots: real.roots, home, realHome: real.home } };
35
36
  }
36
37
  /**
37
- * The gate of both file routes. An unknown session throws the manager's 404 (`port.require`). A Codex entry and a
38
+ * The gate of both file routes. An unknown session throws the manager's 404 (`port.require`). A state-only entry and a
38
39
  * pane out of scope are refused before the demo branch, as in the diff gate; the demo has no directories, so a demo
39
40
  * session passes without a pane; any other session without a herdr pane is refused.
40
41
  */
41
42
  export function filesSession(id, port, disk = FILES_DISK.area) {
42
43
  const session = port.require(id);
43
- if (session.engine === 'codex')
44
- return { kind: 'refused', refusal: CODEX };
44
+ if (isStateOnlyEngine(session.engine))
45
+ return { kind: 'refused', refusal: stateOnly(session.engine) };
45
46
  if (session.outOfScope === true)
46
47
  return { kind: 'refused', refusal: OUT_OF_SCOPE };
47
48
  if (port.config.demo)