@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,43 @@
1
+ # Start a thread
2
+
3
+ One owner request is one thread. You never do the request's work yourself.
4
+
5
+ 1. `command -v rarog-coordinator` (rule 1).
6
+ 2. Name. Choose a short English name for the request: ASCII letters, digits, hyphens and single spaces, at most
7
+ 24 characters and 4 words, for example `Fix checkout`. No `;`, `$(`, quotes or other symbols: the tool refuses
8
+ them. The thread's session is called `[A] <name>`; the owner types `Merge: <name>`.
9
+ 3. Free name. Call ListAgents. If any session, in any project, is called `[A] <name>`, choose another name.
10
+ 4. Run (Bash, `dangerouslyDisableSandbox: true`, `timeout: 600000`):
11
+
12
+ ```bash
13
+ rarog-coordinator start --name "<name>" --goal "<the owner's request in one sentence, in the owner's words>"
14
+ ```
15
+
16
+ It makes the worktree `<main>/.claude/worktrees/<slug>` on a new branch `<slug>` from local `main`, runs `init`,
17
+ writes the thread file, opens a herdr tab in the main checkout with
18
+ `claude --worktree <slug> --session-id <id> --name "[A] <name>"` in your permission mode and model, and checks
19
+ that the thread runs inside its worktree. Run one `start` at a time, never two in parallel tool calls: `start`
20
+ holds the metadata lock for its whole run.
21
+ - `refused start: metadata lock … is held`: another `start` or `claim` runs; run this `start` again after it
22
+ ends. `… is STALE` or `… in an unknown state`: show the line to the owner; never remove the lock yourself.
23
+ - `refused start: branch <slug> moved while start read it …`: someone committed on that branch; choose another
24
+ name.
25
+ - Another `refused start:` or `failed start:`: tell the owner the reason in one sentence and send no brief.
26
+ Running `start` again with the same name finishes a half-made start.
27
+ 5. Brief. Only after `ok start:`, SendMessage to `"[A] <name>"` with `notify_when_idle: true` and this text, filled
28
+ in (the goal in the owner's words, the rest as written):
29
+
30
+ ```text
31
+ You are the thread "[A] <name>" of the coordinator "[C] <Project>".
32
+ Goal (the owner's words): <goal>
33
+ You work only in your worktree <worktree> on branch <slug>; Claude Code started you there.
34
+ Commit your work on that branch. When the goal is done and committed, SendMessage to "[C] <Project>":
35
+ "done: <commit> <one line>". If you cannot go on, send "blocked: <reason>".
36
+ You write only to "[C] <Project>". ListAgents shows sessions of other projects too: never write to them.
37
+ Do not merge into main and do not push. Rebase onto main only when the coordinator asks you to.
38
+ The coordinator checks your branch and merges it after the owner's Merge.
39
+ Ask the owner only through your question dialog (AskUserQuestion); the coordinator does not answer for the owner.
40
+ ```
41
+
42
+ 6. `rarog-coordinator note "<name>" --next "waiting for done"`.
43
+ 7. Tell the owner one line: thread `[A] <name>` started, and what it does.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Server start: the coordination fields of the session summaries (`coordination/summary.ts`). It opens the
3
+ * coordinator registry from the data directory once, builds the overlay the manager gets in its configuration, and
4
+ * feeds it the manager's event stream. The demo gets none: its seeds carry fixed fields and it reads no disk.
5
+ */
6
+ import { homedir } from 'node:os';
7
+ import { openCoordinatorRegistry } from '../coordination/registry.js';
8
+ import { SessionCoordination } from '../coordination/summary.js';
9
+ import { gitReadEnv, spawnGitArgs } from '../git-status.js';
10
+ import { createJsonlFollower } from '../herdr/jsonl-follow.js';
11
+ /** The overlay of this start, or `null` in the demo. */
12
+ export function createCoordination(config, deps) {
13
+ if (config.demo)
14
+ return null;
15
+ return new SessionCoordination({
16
+ registry: deps.options?.registry ?? openCoordinatorRegistry({ dataDir: config.dataDir, log: deps.log }),
17
+ roots: config.herdrRoots,
18
+ home: deps.home ?? homedir(),
19
+ run: deps.options?.run ?? spawnGitArgs(gitReadEnv(config.gitEnvBase)),
20
+ ...(deps.options?.pluginOf === undefined ? {} : { pluginOf: deps.options.pluginOf }),
21
+ ...(deps.options?.watcher === undefined ? {} : { watcher: deps.options.watcher }),
22
+ });
23
+ }
24
+ /**
25
+ * State and git events of the sessions move roles and merge states, which `state` frames do not carry; so does a new
26
+ * conversation in a pane, which changes no other field.
27
+ */
28
+ export function wireCoordination(coordination, manager) {
29
+ // A `state` frame goes to the global and the session stream, a `git-status` frame to the session stream: one each.
30
+ manager.onEvent((scope, _seq, event) => {
31
+ if (scope === 'global' ? event.type === 'state' : event.type === 'git-status')
32
+ coordination.noteEvent(event);
33
+ });
34
+ manager.onConversationChange((sessionId) => { coordination.conversationChanged(sessionId); });
35
+ }
36
+ /**
37
+ * The transcript follower of every herdr pane: a message from another session is a prompt bubble only while the
38
+ * conversation is a coordinator's thread or a coordinator (`SessionCoordination.crossSessionPrompts`), asked at every
39
+ * line, and every entry of the live tail goes to the overlay for the Merge events. `base`: tests only (store root, no
40
+ * `fs.watch`).
41
+ */
42
+ export function coordinationFollower(coordination, base = {}) {
43
+ return (opts) => createJsonlFollower({
44
+ ...base, ...opts,
45
+ crossSessionPrompts: (conversation) => coordination.crossSessionPrompts(conversation),
46
+ // A live coordinator's Merge prompts and turn ends (`SessionCoordination.transcriptEntry`).
47
+ onEntry: (conversation, entry) => { coordination.transcriptEntry(conversation, entry); },
48
+ });
49
+ }
@@ -0,0 +1,27 @@
1
+ import { openCoordinatorRegistry } from '../coordination/registry.js';
2
+ import { ensurePluginCopy } from '../herdr/plugin-copy.js';
3
+ import { CoordinatorStart } from '../sessions/coordinator-start.js';
4
+ /** The registry of this start, or `null` in the demo. */
5
+ export function openCoordinators(config, log) {
6
+ return config.demo ? null : openCoordinatorRegistry({ dataDir: config.dataDir, log });
7
+ }
8
+ /**
9
+ * Whether a session's process runs with the coordinator plugin: a fact the server produced when it started the
10
+ * process (`ManagerApi.pluginDirOf`), never a client's word. The manager exists after the overlay, so it is read late;
11
+ * before it exists no session has the plugin.
12
+ */
13
+ export function pluginFact(manager) {
14
+ return (sessionId) => manager()?.pluginDirOf(sessionId) != null;
15
+ }
16
+ /** The decision the manager gets in its configuration: plugin copies in the data directory, roles in the registry. */
17
+ export function createCoordinatorStart(config, deps) {
18
+ return new CoordinatorStart({
19
+ registry: deps.registry,
20
+ pluginCopy: (inUse) => ensurePluginCopy({
21
+ dataDir: config.dataDir, inUse, ...(deps.installRoot === undefined ? {} : { installRoot: deps.installRoot }),
22
+ }),
23
+ // A confirmed role reaches the summaries the same way as a new conversation in a pane.
24
+ roleChanged: (sessionId) => { deps.coordination.conversationChanged(sessionId); },
25
+ log: deps.log,
26
+ });
27
+ }
@@ -24,6 +24,7 @@ export function startInbox(deps) {
24
24
  log: deps.log,
25
25
  ...(deps.debounceMs === undefined ? {} : { debounceMs: deps.debounceMs }),
26
26
  ...(deps.timing === undefined ? {} : { timing: deps.timing }),
27
+ ...(deps.checkedOf === undefined ? {} : { checkedOf: deps.checkedOf }),
27
28
  }, manager);
28
29
  manager.onEvent((scope, _seq, event) => { inbox.noteEvent(scope, event); });
29
30
  manager.onConversationChange((sessionId) => { inbox.noteConversation(sessionId); });
@@ -41,11 +42,14 @@ export async function assembleInbox(deps) {
41
42
  return null;
42
43
  const demo = config.demo ? await import('../demo/inbox.js') : null;
43
44
  const port = demo === null ? manager : demo.demoInboxManager(manager);
45
+ // The demo has no coordination overlay; its ready thread's checked commit comes from the seed.
46
+ const checkedOf = deps.checkedOf ?? demo?.demoCheckedOf(port);
44
47
  const inbox = startInbox({
45
48
  manager: port, ready: deps.ready, dataDir: config.dataDir, promptBlock: config.promptBlock, log: deps.log,
46
49
  ...(demo === null ? {} : { readSegments: demo.createDemoSegmentReader(port) }),
47
50
  ...(deps.locate === undefined ? {} : { locate: deps.locate }),
48
51
  ...(deps.debounceMs === undefined ? {} : { debounceMs: deps.debounceMs }),
52
+ ...(checkedOf === undefined ? {} : { checkedOf }),
49
53
  });
50
54
  const heads = new InboxHeads(inbox);
51
55
  if (demo !== null)
@@ -2,10 +2,27 @@ import { createApnsChannel } from '../notify/apns-channel.js';
2
2
  import { createFanoutSink } from '../notify/fanout.js';
3
3
  import { Notifier, sessionLook } from '../notify/index.js';
4
4
  import { Presence } from '../notify/presence.js';
5
+ import { createReadyToMergeAlert, readyToMergeFactsOf } from '../notify/ready-to-merge.js';
5
6
  import { createStalledWaitAlert } from '../notify/stalled-wait.js';
6
7
  import { inTemporaryDirectory } from '../sessions/test-session.js';
7
8
  /** Start log phrase when `RAROG_PUSH_RELAY_URL` has a bad value (`docs/server-config.md`). */
8
9
  export const PUSH_RELAY_DISABLED_LOG = 'push: push relay off';
10
+ /**
11
+ * The ready-to-merge push behind the manager's stream: every `session-changed` of a thread hands in its facts with
12
+ * the `checked` commit of its thread file; another conversation in the session drops its memory.
13
+ */
14
+ export function wireReadyToMerge(alert, manager, checkedOf) {
15
+ manager.onEvent((scope, _seq, event) => {
16
+ if (scope !== 'global' || event.type !== 'session-changed')
17
+ return;
18
+ const facts = readyToMergeFactsOf(event.session, checkedOf(event.session.id));
19
+ if (facts === undefined)
20
+ alert.forget(event.session.id);
21
+ else
22
+ alert.update(facts);
23
+ });
24
+ manager.onConversationChange((sessionId) => { alert.forget(sessionId); });
25
+ }
9
26
  /**
10
27
  * The stalled wait alarm behind the manager's listener: the session facts of the push (`title`, `label`, `termId`) and
11
28
  * the test session rule (`inTemporaryDirectory(cwd)`) come from the session at every list swap.
@@ -84,6 +101,10 @@ export function createPush(config, deps) {
84
101
  const alert = apns === undefined ? undefined : createStalledWaitAlert({
85
102
  send: (content) => apns.sink.send(content), presence, badge, log: (line) => { log.info(line); },
86
103
  });
104
+ // The ready-to-merge push too: a thread turning ready is no state transition of its session.
105
+ const readyToMerge = apns === undefined ? undefined : createReadyToMergeAlert({
106
+ send: (content) => apns.sink.send(content), presence, badge, log: (line) => { log.info(line); },
107
+ });
87
108
  if (notifier !== null && apns !== undefined) {
88
109
  // Powrót do Raroga kasuje czekające banery i dźwięki kafla, które jeszcze nie wyszły.
89
110
  const liveActivity = apns.liveActivity;
@@ -110,9 +131,11 @@ export function createPush(config, deps) {
110
131
  return {
111
132
  presence, apns, notifier,
112
133
  stalledWait: alert === undefined ? undefined : stalledWaitListener(alert),
134
+ readyToMerge,
113
135
  close: () => {
114
- // The alarm only stops its timers (nothing to wait for), so the channel starts closing at once, as before.
136
+ // The alarms only stop their timers (nothing to wait for), so the channel starts closing at once, as before.
115
137
  void alert?.close();
138
+ void readyToMerge?.close();
116
139
  return apns?.close() ?? Promise.resolve();
117
140
  },
118
141
  };
@@ -1,4 +1,4 @@
1
- import { messageAsksOwner } from './asks-owner.js';
1
+ import { messageAsksOwner } from '../asks-owner.js';
2
2
  /**
3
3
  * The catalog now. A row carries the session id, `conversation` (the token of its engine conversation, the same
4
4
  * function as the turns route), `stateSince` as the session list carries it and `asksOwner: true` only while the
@@ -28,9 +28,8 @@
28
28
  * - `conversation.ts` — opaque token of a session's engine conversation (`conversationToken`): HMAC under a key drawn
29
29
  * at server start, so it changes with the conversation and with every restart.
30
30
  * - `catalog.ts` — the session catalog behind `GET /api/companion/sessions`: one row per session in the voice agent's
31
- * scope, from the server's memory (`companionCatalog`).
32
- * - `asks-owner.ts` — whether an agent message asks the owner: the app's rule for its question block, on the top-level
33
- * blocks of each text block (`messageAsksOwner`, `textAsksOwner`).
31
+ * scope, from the server's memory (`companionCatalog`); whether an agent message asks the owner comes from
32
+ * `server/src/asks-owner.ts`.
34
33
  * - `index.ts` — this entry.
35
34
  */
36
35
  export { assembleCompanion, createCompanionFeature } from './ask.js';
@@ -43,4 +42,3 @@ export { TURNS_FIRST_WINDOW, assembleCompanionTurns, createCompanionTurns, isTur
43
42
  export { TURNS_MAX_READS, readSettledTurns } from './turns-settle.js';
44
43
  export { CONVERSATION_TOKEN_CHARS, conversationToken, conversationTokens } from './conversation.js';
45
44
  export { companionCatalog } from './catalog.js';
46
- export { ASKS_OWNER_MARKERS, messageAsksOwner, textAsksOwner } from './asks-owner.js';
@@ -59,6 +59,10 @@ export function parseCodexStatusEnabled(raw) {
59
59
  return true;
60
60
  return !(raw === '0' || raw === 'false');
61
61
  }
62
+ /** Flag of the agy row; no value = ON, for the same reason as {@link parseCodexStatusEnabled}. `0` hides agy rows. */
63
+ export function parseAgyStatusEnabled(raw) {
64
+ return parseCodexStatusEnabled(raw);
65
+ }
62
66
  /** Preferencja wykrycia dialogu z rejestru CLI; brak wartości = WŁĄCZONE. */
63
67
  export function parseCliWaiting(raw) {
64
68
  if (raw === undefined || raw.trim() === '')
@@ -71,6 +71,12 @@ export const NOTES_ENV = 'RAROG_NOTES';
71
71
  * każda inna. Flaga wyłącza wiersz Codexa bez zmiany kodu.
72
72
  */
73
73
  export const CODEX_STATUS_ENV = 'RAROG_CODEX_STATUS';
74
+ /**
75
+ * Flag of the AGY ROW, the twin of {@link CODEX_STATUS_ENV}. `0` = `agent === 'agy'` panes (Antigravity CLI) do not
76
+ * exist for Rarog. Not a killswitch for the same reason: the entry sends nothing, reads no screen, and its only
77
+ * mutation (`agent.focus`) is under `RAROG_HERDR_SEND`.
78
+ */
79
+ export const AGY_STATUS_ENV = 'RAROG_AGY_STATUS';
74
80
  /**
75
81
  * Preferencja WYKRYCIA DIALOGU Z REJESTRU SESJI CLI. `0` = Rarog nie czyta
76
82
  * `~/.claude/sessions/<pid>.json` co 1,5 s i widzi dialog tylko wtedy, gdy herdr zgłosi
@@ -182,6 +188,13 @@ export const CONSENT_RESTART_GRACE_ENV = 'RAROG_CONSENT_RESTART_GRACE';
182
188
  * wysyła, więc to NIE jest szósty killswitch. Flaga kanału zgody jej nie zmienia i odwrotnie.
183
189
  */
184
190
  export const DIALOG_LAYER2_ENV = 'RAROG_DIALOG_LAYER2';
191
+ /**
192
+ * Level of the live dialog card (`docs/dialogs.md`, "Live dialog card"): `0` = no live card (the kill switch), missing
193
+ * or `1` = the live card with Enter only on dialogs with light guards (a question, a dialog), `2` = Enter on a consent
194
+ * dialog too, under the consent guards; any other value is a configuration error at start. Read once at start and
195
+ * passed to the driver (`HerdrDriverDeps.dialogLive`).
196
+ */
197
+ export const DIALOG_LIVE_ENV = 'RAROG_DIALOG_LIVE';
185
198
  /**
186
199
  * Folder gate kill switch (`docs/macos-folders.md`): missing or empty = on on macOS and off elsewhere, `1` = on,
187
200
  * `0` = off; any other value is a config error at start, also in the demo, which never runs the gate. On, a disk call
@@ -389,6 +402,7 @@ export const SERVER_ENV = {
389
402
  [VOICE_ENV]: 'plain',
390
403
  [NOTES_ENV]: 'plain',
391
404
  [CODEX_STATUS_ENV]: 'plain',
405
+ [AGY_STATUS_ENV]: 'plain',
392
406
  [CLI_WAITING_ENV]: 'plain',
393
407
  [GIT_FILE_DETAILS_ENV]: 'plain',
394
408
  [AGENT_FILES_ENV]: 'plain',
@@ -400,6 +414,7 @@ export const SERVER_ENV = {
400
414
  [CONSENT_ALWAYS_ENV]: 'plain',
401
415
  [CONSENT_RESTART_GRACE_ENV]: 'plain',
402
416
  [DIALOG_LAYER2_ENV]: 'plain',
417
+ [DIALOG_LIVE_ENV]: 'plain',
403
418
  [FOLDER_GATE_ENV]: 'plain',
404
419
  [SSE_GZIP_ENV]: 'plain',
405
420
  [COMPANION_ENV]: 'plain',
@@ -15,7 +15,7 @@ import path from 'node:path';
15
15
  import { MAX_TRANSCRIPT_MESSAGES } from '@rarog/shared';
16
16
  import { BUNDLE_ID_RE } from '@rarog/shared/rest';
17
17
  import { dataDirConflictMessage, resolveDataDir } from '@rarog/shared/data-dir';
18
- import { AGENT_FILES_ENV, APNS_ENV_NAMES, APNS_KEY_ID_ENV, APNS_KEY_PATH_ENV, APNS_TEAM_ID_ENV, APNS_TOPIC_ENV, CLAUDE_ENV_CLEAR_ENV, ConfigError, CLI_WAITING_ENV, CODEX_STATUS_ENV, COMPANION_ENV, COMPANION_MODEL_ENV, COMPANION_SESSIONS_ENV, COMPANION_ENV_PASSTHROUGH, CONSENT_CHANNEL_ENV, CONSENT_PROOF_ENV, CONSENT_ALWAYS_ENV, CONSENT_RESTART_GRACE_ENV, DEMO_CONTENT_ENV, DEMO_LANG_ENV, DEMO_REVIEW_CODE_ENV, DIALOG_LAYER2_ENV, FOLDER_GATE_ENV, GIT_ENV_PASSTHROUGH, GIT_ENV_PREFIX, GIT_FILE_DETAILS_ENV, HERDR_BIN_ENV, HERDR_LAUNCH_ENV, HERDR_ROOTS_ENV, HERDR_SEEN_FOCUS_ENV, HERDR_SEND_ENV, HERDR_SOCKET_ENV, HERDR_TAB_LABELS_ENV, INBOX_ENV, FILES_ENV, FILES_MAX_MB_ENV, IROH_ENV, IROH_KEY_ENV, IROH_PORT_ENV, IROH_RELAY_ENV, MAX_PANES_ENV, MIN_CLIENT_BUILD_ENV, NOTES_ENV, PROJECT_ROOTS_ENV, PROMPT_BLOCK_ENV, PUSH_E2E_ENV, PUSH_ENV, PR_STATUS_ENV, PR_STATUS_ENV_PASSTHROUGH, PUSH_RELAY_URL_ENV, QUEUE_ECHO_ENV, REFUSAL_DUMPS_ENV, SONIOX_API_HOST_ENV, SONIOX_API_KEY_ENV, OPENAI_API_KEY_ENV, SSE_GZIP_ENV, TALL_DIALOG_GUARD_ENV, TERM_ENV, TERM_ENV_PASSTHROUGH, TERM_IDLE_DAYS_ENV, TERM_MAX_ENV, VOICE_ENV, YOLO_ROOTS_ENV, readEnv, } from './config-env.js';
18
+ import { AGENT_FILES_ENV, AGY_STATUS_ENV, APNS_ENV_NAMES, APNS_KEY_ID_ENV, APNS_KEY_PATH_ENV, APNS_TEAM_ID_ENV, APNS_TOPIC_ENV, CLAUDE_ENV_CLEAR_ENV, ConfigError, CLI_WAITING_ENV, CODEX_STATUS_ENV, COMPANION_ENV, COMPANION_MODEL_ENV, COMPANION_SESSIONS_ENV, COMPANION_ENV_PASSTHROUGH, CONSENT_CHANNEL_ENV, CONSENT_PROOF_ENV, CONSENT_ALWAYS_ENV, CONSENT_RESTART_GRACE_ENV, DEMO_CONTENT_ENV, DEMO_LANG_ENV, DEMO_REVIEW_CODE_ENV, DIALOG_LAYER2_ENV, DIALOG_LIVE_ENV, FOLDER_GATE_ENV, GIT_ENV_PASSTHROUGH, GIT_ENV_PREFIX, GIT_FILE_DETAILS_ENV, HERDR_BIN_ENV, HERDR_LAUNCH_ENV, HERDR_ROOTS_ENV, HERDR_SEEN_FOCUS_ENV, HERDR_SEND_ENV, HERDR_SOCKET_ENV, HERDR_TAB_LABELS_ENV, INBOX_ENV, FILES_ENV, FILES_MAX_MB_ENV, IROH_ENV, IROH_KEY_ENV, IROH_PORT_ENV, IROH_RELAY_ENV, MAX_PANES_ENV, MIN_CLIENT_BUILD_ENV, NOTES_ENV, PROJECT_ROOTS_ENV, PROMPT_BLOCK_ENV, PUSH_E2E_ENV, PUSH_ENV, PR_STATUS_ENV, PR_STATUS_ENV_PASSTHROUGH, PUSH_RELAY_URL_ENV, QUEUE_ECHO_ENV, REFUSAL_DUMPS_ENV, SONIOX_API_HOST_ENV, SONIOX_API_KEY_ENV, OPENAI_API_KEY_ENV, SSE_GZIP_ENV, TALL_DIALOG_GUARD_ENV, TERM_ENV, TERM_ENV_PASSTHROUGH, TERM_IDLE_DAYS_ENV, TERM_MAX_ENV, VOICE_ENV, YOLO_ROOTS_ENV, readEnv, } from './config-env.js';
19
19
  import { RAROG_VERSION } from './version.js';
20
20
  import { INSTALL_MODE } from './install/mode.js';
21
21
  import { DEVICES_FILENAME, activeDeviceEpochs } from './auth/devices-store.js';
@@ -24,7 +24,7 @@ import { CONSENT_PROOF_RULES } from './herdr/dialogs/layer1/contract.js';
24
24
  import { readAccountDefaultEffort, readAccountDefaultModel } from './config/claude-account.js';
25
25
  import { minClientBuildOf, parseMinClientBuild } from './config/clients.js';
26
26
  import { DEMO_REVIEW_MAX_DEVICES, assertDemoReviewOrigins, demoEnabled, parseDemoContent, parseDemoLang, parseDemoReview, } from './config/demo.js';
27
- import { COMPANION_MODEL_DEFAULT, COMPANION_MODEL_PATTERN, parseAgentFiles, parseCliWaiting, parseCodexStatusEnabled, parseCompanionEnabled, parseCompanionModel, parseCompanionSessionsEnabled, parseConsentRestartGrace, parseGitFileDetails, parseInboxEnabled, parseNotesEnabled, parsePrStatusEnabled, parsePromptBlock, parseQueueEcho, parseRefusalDumps, parseSseGzip, } from './config/flags.js';
27
+ import { COMPANION_MODEL_DEFAULT, COMPANION_MODEL_PATTERN, parseAgentFiles, parseAgyStatusEnabled, parseCliWaiting, parseCodexStatusEnabled, parseCompanionEnabled, parseCompanionModel, parseCompanionSessionsEnabled, parseConsentRestartGrace, parseGitFileDetails, parseInboxEnabled, parseNotesEnabled, parsePrStatusEnabled, parsePromptBlock, parseQueueEcho, parseRefusalDumps, parseSseGzip, } from './config/flags.js';
28
28
  import { parseFilesEnabled, parseFilesMaxBytes } from './config/files.js';
29
29
  import { DEFAULT_MAX_PANES, defaultHerdrSocket, parseHerdrLaunch, parseHerdrSeenFocus, parseHerdrSend, parseHerdrSocket, parseHerdrTabLabels, parseMaxPanes, } from './config/herdr.js';
30
30
  import { DEFAULT_PORT, MAX_BODY_BYTES, RAROG_HOST, assertLoopbackHost, demoOrigins, parseIroh, parseOrigins, parsePort, } from './config/listen.js';
@@ -37,7 +37,7 @@ import { VOICE_TOKEN_HOURLY_CAP, VOICE_TOKEN_MIN_INTERVAL_MS, parseVoiceEnabled
37
37
  * `loadConfig` below passes the values in. This file re-exports their names, so imports from `config.ts`
38
38
  * stay as they are.
39
39
  */
40
- export { COMPANION_MODEL_DEFAULT, COMPANION_MODEL_PATTERN, parseCompanionModel, DEFAULT_HERDR_BIN, DEFAULT_MAX_PANES, DEFAULT_PORT, DEFAULT_TERM_IDLE_DAYS, DEFAULT_TERM_MAX, DEMO_REVIEW_MAX_DEVICES, MAX_BODY_BYTES, RAROG_HOST, RAROG_TERM_PANE_TOKEN, TERM_START_RETRY_MS, TERM_TOKEN_REFRESH_MS, VOICE_TOKEN_HOURLY_CAP, VOICE_TOKEN_MIN_INTERVAL_MS, assertLoopbackHost, defaultHerdrSocket, demoOrigins, expandTilde, isInsideAnyRoot, isInsideAnyRootReal, parseAgentFiles, parseCliWaiting, parseCodexStatusEnabled, parseCompanionEnabled, parseGitFileDetails, parseHerdrBin, parseHerdrLaunch, parseHerdrRoots, parseHerdrSeenFocus, parseHerdrSend, parseHerdrSocket, parseHerdrTabLabels, parseMinClientBuild, parseNotesEnabled, parseProjectRoots, parsePromptBlock, parsePushE2e, parsePushEnabled, parsePushRelay, parseQueueEcho, parseRefusalDumps, parseSseGzip, parseTermEnabled, parseTermIdleDays, parseTermMax, parseVoiceEnabled, parseYoloRoots, readAccountDefaultEffort, readAccountDefaultModel, termPaneTokenOf, validateProjectCwd, };
40
+ export { COMPANION_MODEL_DEFAULT, COMPANION_MODEL_PATTERN, parseCompanionModel, DEFAULT_HERDR_BIN, DEFAULT_MAX_PANES, DEFAULT_PORT, DEFAULT_TERM_IDLE_DAYS, DEFAULT_TERM_MAX, DEMO_REVIEW_MAX_DEVICES, MAX_BODY_BYTES, RAROG_HOST, RAROG_TERM_PANE_TOKEN, TERM_START_RETRY_MS, TERM_TOKEN_REFRESH_MS, VOICE_TOKEN_HOURLY_CAP, VOICE_TOKEN_MIN_INTERVAL_MS, assertLoopbackHost, defaultHerdrSocket, demoOrigins, expandTilde, isInsideAnyRoot, isInsideAnyRootReal, parseAgentFiles, parseAgyStatusEnabled, parseCliWaiting, parseCodexStatusEnabled, parseCompanionEnabled, parseGitFileDetails, parseHerdrBin, parseHerdrLaunch, parseHerdrRoots, parseHerdrSeenFocus, parseHerdrSend, parseHerdrSocket, parseHerdrTabLabels, parseMinClientBuild, parseNotesEnabled, parseProjectRoots, parsePromptBlock, parsePushE2e, parsePushEnabled, parsePushRelay, parseQueueEcho, parseRefusalDumps, parseSseGzip, parseTermEnabled, parseTermIdleDays, parseTermMax, parseVoiceEnabled, parseYoloRoots, readAccountDefaultEffort, readAccountDefaultModel, termPaneTokenOf, validateProjectCwd, };
41
41
  /** Błąd konfiguracji (definicja w `config-env.ts`, bo rzuca go też odczyt zmiennej). */
42
42
  export { ConfigError };
43
43
  // ---------------------------------------------------------------------------
@@ -528,6 +528,17 @@ export function parseDialogLayer2(raw) {
528
528
  return true;
529
529
  throw new ConfigError(`${DIALOG_LAYER2_ENV} takes 1 or 0 (got: ${value}).`);
530
530
  }
531
+ /** The live dialog card level: missing, empty or `0` = off, `1` or `2`; any other value stops the start. */
532
+ export function parseDialogLive(raw) {
533
+ const value = raw?.trim() ?? '';
534
+ if (value === '0')
535
+ return 0;
536
+ if (value === '' || value === '1')
537
+ return 1;
538
+ if (value === '2')
539
+ return 2;
540
+ throw new ConfigError(`${DIALOG_LIVE_ENV} takes 0, 1 or 2 (got: ${value}).`);
541
+ }
531
542
  /**
532
543
  * The folder gate flag: missing or empty = the platform decides (on on macOS, where the consent windows are), `1` = on,
533
544
  * `0` = off; any other value stops the start, so a typo never leaves the server in another mode than the owner meant.
@@ -694,6 +705,8 @@ export function loadConfig(env = process.env, mode = INSTALL_MODE) {
694
705
  * przypadkowe.
695
706
  */
696
707
  codexStatusEnabled: !demo && parseCodexStatusEnabled(readEnv(env, CODEX_STATUS_ENV)),
708
+ // Off in demo for the same reason as the Codex row: the entry comes only from a live herdr `agent.list`.
709
+ agyStatusEnabled: !demo && parseAgyStatusEnabled(readEnv(env, AGY_STATUS_ENV)),
697
710
  /*
698
711
  * Rejestr CLI wyłączony w demo BEZWARUNKOWO: tryb pokazowy nie czyta rejestru procesów Maca
699
712
  * (czytnika wydań w demo nie ma wcale), a jego sesje są fikcyjne.
@@ -721,6 +734,7 @@ export function loadConfig(env = process.env, mode = INSTALL_MODE) {
721
734
  consentRestartGraceMs: parseConsentRestartGrace(readEnv(env, CONSENT_RESTART_GRACE_ENV)),
722
735
  // W demo bez skutku (mock nie ma drivera herdr), ale zła wartość zatrzymuje start tak samo.
723
736
  dialogLayer2: parseDialogLayer2(readEnv(env, DIALOG_LAYER2_ENV)),
737
+ dialogLive: parseDialogLive(readEnv(env, DIALOG_LIVE_ENV)),
724
738
  // Off in demo unconditionally: the demo reads nothing of the host's folders; a wrong value stops the start there.
725
739
  folderGate: parseFolderGate(readEnv(env, FOLDER_GATE_ENV), process.platform) && !demo,
726
740
  sseGzip: parseSseGzip(readEnv(env, SSE_GZIP_ENV)),
@@ -0,0 +1,86 @@
1
+ import { isTurnEnd } from '../herdr/jsonl-pending.js';
2
+ import { MergeEpisodes, peerMessageOf } from './merge-prompt.js';
3
+ import { threadNamed } from './thread-file.js';
4
+ function timeOf(entry) {
5
+ const raw = typeof entry === 'object' && entry !== null ? entry.timestamp : undefined;
6
+ if (typeof raw !== 'string')
7
+ return null;
8
+ const at = Date.parse(raw);
9
+ return Number.isNaN(at) ? null : at;
10
+ }
11
+ export class MergeEvents {
12
+ #byProject = new Map();
13
+ #now;
14
+ constructor(now) {
15
+ this.#now = now;
16
+ }
17
+ /**
18
+ * The coordinator of `project` runs `conversation` from now on: an entry older than this moment is history, so a
19
+ * Merge in it is no request. The same conversation keeps its episodes.
20
+ */
21
+ started(project, conversation) {
22
+ if (this.#byProject.get(project)?.conversation === conversation)
23
+ return;
24
+ this.#byProject.set(project, { conversation, episodes: new MergeEpisodes(this.#now()), checked: new Map() });
25
+ }
26
+ /** The project has no live coordinator: its episodes go with the process that worked on them. */
27
+ ended(project) {
28
+ this.#byProject.delete(project);
29
+ }
30
+ /**
31
+ * One entry of the coordinator's transcript, in file order: a Merge prompt for a thread starts its episode, the end
32
+ * of a turn (also an interrupted one) ends the running ones at the moment the turn ended. Returns the names whose
33
+ * episode changed.
34
+ */
35
+ coordinatorEntry(project, conversation, entry, threads) {
36
+ const coordinator = this.#byProject.get(project);
37
+ if (coordinator?.conversation !== conversation)
38
+ return [];
39
+ const changed = [];
40
+ const name = coordinator.episodes.note(entry, (one) => threadNamed(threads, one) !== undefined);
41
+ if (name !== null) {
42
+ coordinator.checked.set(name, threadNamed(threads, name)?.checked ?? undefined);
43
+ changed.push(name);
44
+ }
45
+ const end = isTurnEnd(entry) ? timeOf(entry) : null;
46
+ if (end !== null)
47
+ changed.push(...coordinator.episodes.coordinatorStopped(end));
48
+ return changed;
49
+ }
50
+ /**
51
+ * One entry of the transcript of the thread `name`, in file order: a message from another session whose sender is a
52
+ * live process of the coordinator's conversation sends the thread back. `livePids` gives those processes from the
53
+ * CLI process registry; `null` (unknown) recognises no send-back. Returns true when the entry changed the episode.
54
+ */
55
+ threadEntry(project, name, entry, livePids) {
56
+ const coordinator = this.#byProject.get(project);
57
+ if (coordinator === undefined)
58
+ return false;
59
+ const message = peerMessageOf(entry);
60
+ if (message?.pid === undefined || livePids(coordinator.conversation)?.includes(message.pid) !== true)
61
+ return false;
62
+ return coordinator.episodes.sentBack(name, message.at);
63
+ }
64
+ /** The thread file of `name` records the merge; true when that ended a running episode. */
65
+ merged(project, name) {
66
+ return this.#byProject.get(project)?.episodes.merged(name, this.#now()) ?? false;
67
+ }
68
+ /** The Merge events of the thread `name`, oldest first; none without a Merge since its coordinator took the role. */
69
+ eventsOf(project, name) {
70
+ const coordinator = this.#byProject.get(project);
71
+ const episode = coordinator?.episodes.episodeOf(name);
72
+ if (coordinator === undefined || episode === undefined)
73
+ return [];
74
+ const checked = coordinator.checked.get(name);
75
+ const events = [{
76
+ kind: 'merge-delivered', at: new Date(episode.since).toISOString(), ...(checked === undefined ? {} : { checked }),
77
+ }];
78
+ if (episode.phase === 'merging')
79
+ return events;
80
+ const at = new Date(episode.endedAt).toISOString();
81
+ events.push(episode.how === 'sent-back'
82
+ ? { kind: 'peer-message', at, from: 'coordinator' }
83
+ : { kind: 'coordinator-stopped', at });
84
+ return events;
85
+ }
86
+ }