@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rarog/shared",
3
- "version": "1.1.2-beta.1",
3
+ "version": "1.1.2-beta.2",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  * złotych ramek (`shared/test/sse-fixtures.test.ts` sprawdza nim `degrades`, które czyta Swift).
23
23
  */
24
24
  import { z } from 'zod';
25
- import { activityEventSchema, activitySchema, backgroundTaskSchema, blockSchema, contextLimitStateSchema, deltaEventSchema, folderAccessEventSchema, gitFileDetailSchema, gitStatusEventSchema, helloEventSchema, herdrStatusEventSchema, inboxCardKindSchema, inboxDialogKindSchema, inboxEventSchemas, inboxHeadSchemaOf, macFolderBlockSchema, macFolderStateSchema, messageAttachmentSchema, messageEventSchema, notesEventSchema, parseServerEvent, permissionPendingEventSchema, permissionRequestObjectSchema, permissionRequestSchema, permissionResolvedEventSchema, permissionSettledEventSchema, questionOptionSchema, questionPendingEventSchema, questionRequestSchema, questionSchema, questionResolvedEventSchema, sessionChangedEventSchema, sessionPullRequestSchema, sessionStateSchema, sessionsSnapshotEventSchema, sessionSummarySchema, stateEventSchema, transcriptMessageSchema, transcriptNoticeSchema, transcriptSnapshotEventSchema, usageEventSchema, toolCallBlockObjectSchema, waitingForSchema, withDetailTruncation, withDisplayTextTruncation, } from './protocol.js';
25
+ import { activityEventSchema, activitySchema, backgroundTaskSchema, blockSchema, contextLimitStateSchema, deltaEventSchema, dialogLiveKeySchema, folderAccessEventSchema, gitFileDetailSchema, gitStatusEventSchema, helloEventSchema, herdrDialogLiveSchema, herdrStatusEventSchema, inboxCardKindSchema, inboxDialogKindSchema, inboxEventSchemas, inboxHeadSchemaOf, macFolderBlockSchema, macFolderStateSchema, messageAttachmentSchema, messageEventSchema, notesEventSchema, parseServerEvent, permissionPendingEventSchema, permissionRequestObjectSchema, permissionRequestSchema, permissionResolvedEventSchema, permissionSettledEventSchema, questionOptionSchema, questionPendingEventSchema, questionRequestSchema, questionSchema, questionResolvedEventSchema, SESSION_COORDINATION_ROLES, sessionChangedEventSchema, sessionCoordinationSchema, sessionPullRequestSchema, sessionStateSchema, sessionsSnapshotEventSchema, sessionSummarySchema, stateEventSchema, threadMergeSchema, transcriptMessageSchema, transcriptNoticeSchema, transcriptSnapshotEventSchema, usageEventSchema, toolCallBlockObjectSchema, waitingForSchema, withDetailTruncation, withDisplayTextTruncation, } from './protocol.js';
26
26
  /**
27
27
  * Wartownik „ta wersja klienta tego nie zna". Zarezerwowany w KLIENCIE: serwer go nie nadaje
28
28
  * i nie zna (schematy ścisłe), więc w polu stanu nie pomyli się z żadną prawdziwą wartością.
@@ -51,6 +51,11 @@ export const DEGRADATIONS = {
51
51
  herdrDialogReason: undefined,
52
52
  /** Klasa dialogu z rejestru CLI — bez pola karta mówi to, co bez rejestru. */
53
53
  cliDialog: undefined,
54
+ /**
55
+ * `SessionSummary.herdrDialogLive` with an unknown key in `keys` or an unknown `refuse`: the whole live card drops, so
56
+ * the app shows the card without buttons the server sends next to it, never a key row it cannot read in full.
57
+ */
58
+ herdrDialogLive: undefined,
54
59
  /** Nie `undefined`: brak pola znaczy „Claude", a nieznanego silnika nie wolno czytać jak Claude. */
55
60
  engine: UNSUPPORTED,
56
61
  'context.kind': undefined,
@@ -113,6 +118,12 @@ export const DEGRADATIONS = {
113
118
  'pullRequests.state': undefined,
114
119
  /** `SessionSummary.seenBy`: an unknown picker drops the field, so the received result reads as a human's. */
115
120
  seenBy: undefined,
121
+ /**
122
+ * `SessionSummary.coordination` with an unknown `role`, or a thread whose `merge` has an unknown `state` or
123
+ * `outcome`: the whole field drops, so the session reads as an ordinary one and the app offers no Merge on a state
124
+ * it cannot read. The rest of the summary stays.
125
+ */
126
+ coordination: undefined,
116
127
  /**
117
128
  * An `inbox-heads` head with an unknown `kind`, `state` or `dialog`: that head drops out of the list and the other
118
129
  * heads stay, so a card kind added later does not empty an older app's Inbox. A single `inbox-head` with such a
@@ -193,6 +204,35 @@ function buildSchemas(raw) {
193
204
  }),
194
205
  unknownObject('kind', waitingForSchema.shape.kind.options, undefined),
195
206
  ]);
207
+ /*
208
+ * `coordination`: an unknown role, or an unknown merge `state` or `outcome` of a thread, drops the whole field. Any
209
+ * other broken value (a string `commits`, a `null`, a missing `name`) still rejects the frame.
210
+ */
211
+ const [, threadRole] = sessionCoordinationSchema.options;
212
+ const mergeShape = threadMergeSchema.shape;
213
+ const unknownMerge = (known) => unknownOf(known).transform(or(undefined));
214
+ const unreadableThread = threadRole.extend({
215
+ merge: threadMergeSchema.extend({
216
+ state: z.union([mergeShape.state, unknownMerge(mergeShape.state.options)]),
217
+ outcome: z.union([mergeShape.outcome.unwrap(), unknownMerge(mergeShape.outcome.unwrap().options)]).optional(),
218
+ }),
219
+ }).transform((value) => (raw ? value : undefined));
220
+ const coordination = z.union([
221
+ sessionCoordinationSchema,
222
+ unreadableThread,
223
+ unknownObject('role', SESSION_COORDINATION_ROLES, undefined),
224
+ ]);
225
+ /*
226
+ * The live dialog card: an unknown string in `keys` or `refuse` drops the whole field (in the raw view the field
227
+ * keeps its markers, so the degradation names the key). Any other broken field still rejects the frame.
228
+ */
229
+ const dialogLive = z.union([
230
+ herdrDialogLiveSchema,
231
+ herdrDialogLiveSchema.extend({
232
+ keys: z.array(lenient(dialogLiveKeySchema, undefined)),
233
+ refuse: lenientOpt(herdrDialogLiveSchema.shape.refuse, undefined),
234
+ }).transform((live) => (raw ? live : undefined)),
235
+ ]);
196
236
  const summaryShape = sessionSummarySchema.shape;
197
237
  const summary = sessionSummarySchema.extend({
198
238
  state: lenient(summaryShape.state, UNSUPPORTED),
@@ -201,6 +241,7 @@ function buildSchemas(raw) {
201
241
  herdrDialog: lenientOpt(summaryShape.herdrDialog, undefined),
202
242
  herdrDialogReason: lenientOpt(summaryShape.herdrDialogReason, undefined),
203
243
  cliDialog: lenientOpt(summaryShape.cliDialog, undefined),
244
+ herdrDialogLive: dialogLive.optional(),
204
245
  seenBy: lenientOpt(summaryShape.seenBy, undefined),
205
246
  engine: lenientOpt(summaryShape.engine, UNSUPPORTED),
206
247
  context: context.optional(),
@@ -213,6 +254,7 @@ function buildSchemas(raw) {
213
254
  pullRequests: z.array(sessionPullRequestSchema.extend({
214
255
  state: lenientOpt(sessionPullRequestSchema.shape.state, undefined),
215
256
  })).optional(),
257
+ coordination: coordination.optional(),
216
258
  });
217
259
  const [textBlock, , imageBlock] = blockSchema.options;
218
260
  // Baza bez reguły `truncation`: `.extend` nie nadpisuje pól obiektu z regułą, więc regułę nakładamy na widok.
@@ -10,4 +10,5 @@ export const NOTIFY_KIND_TITLE = {
10
10
  error: 'push.title.error',
11
11
  limit: 'push.title.limit',
12
12
  stalled: 'push.title.stalled',
13
+ 'ready-to-merge': 'push.title.ready-to-merge',
13
14
  };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Protocol contract, context window area: the context usage of an engine session, the known or unknown window and
3
+ * the table of windows known for sure.
4
+ *
5
+ * Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
6
+ */
7
+ import { z } from 'zod';
8
+ export const sessionUsageSchema = z.object({
9
+ contextTokens: z.number(),
10
+ contextLimit: z.number(),
11
+ });
12
+ export const contextLimitStateSchema = z.discriminatedUnion('kind', [
13
+ z.object({ kind: z.literal('unknown'), tokens: z.number(), atLeast: z.number().optional() }),
14
+ z.object({
15
+ kind: z.literal('known'),
16
+ tokens: z.number(),
17
+ limit: z.number(),
18
+ source: z.enum(['compact-boundary', 'model', 'statusline']),
19
+ }),
20
+ ]);
21
+ const _contextLimitSchemaMatchesType = true;
22
+ const _contextLimitTypeMatchesSchema = true;
23
+ void _contextLimitSchemaMatchesType;
24
+ void _contextLimitTypeMatchesSchema;
25
+ /**
26
+ * Okna kontekstu, które znamy na pewno — dla aliasów z flag Raroga (`fable`, `opus[1m]`, …) oraz
27
+ * dla pełnych identyfikatorów Fable ROZWIĄZANYCH z jsonl (follower potwierdza nimi limit sesji).
28
+ * `opus[1m]` = 1M (`contextWindow: 1000000` in `--output-format json`).
29
+ * The bare alias `opus` = 1M (Claude Code 2.1.280): `claude --model opus` resolves to
30
+ * `claude-opus-5-5` with `contextWindow: 1000000`, and `opus[1m]` to `claude-opus-5-5[1m]` with the
31
+ * SAME window — Opus 5.5 has 1M without a variant, like Fable 5.1. The full id `claude-opus-5-5`
32
+ * is in the table because a session on the account's default model (`opus`, no flag) gets its
33
+ * window only from jsonl and without this entry would stay `unknown`.
34
+ *
35
+ * The model list carries only the `fable` alias, yet the full Fable ids stay in this table on
36
+ * purpose: Rarog also reads sessions started outside it, and transcripts with these ids exist.
37
+ * Dropping an entry would not revoke the model — it would take the known window from those
38
+ * sessions and drop the context bar to `unknown`.
39
+ *
40
+ * Fable = 1M, measured on THIS account: the account has the `claude-fable-5[1m]` variant,
41
+ * transcripts carry window sums up to 885 852, manual compactions at `preTokens` 744 448,
42
+ * and herdr shows 14% exactly when the window sum is 148 704 (148 704 / 1M). A 200 000 limit
43
+ * would understate the window fivefold and raise the colour alarm at a third of the session.
44
+ *
45
+ * Sesja bez flagi `--model` na innym modelu niż fable startuje jako `unknown`: aliasy flag
46
+ * (`fable`/`sonnet`/`opus`/`haiku`) nigdy nie są identyfikatorem z jsonl, a wariantu `[1m]`
47
+ * modeli spoza rodziny Fable jsonl nie odróżnia. Alias `fable` = 1M, bo obie znane wersje
48
+ * (5 z pomiaru, 5.1 z dokumentacji) mają to samo okno.
49
+ *
50
+ * Fable 5.1 = 1M z dokumentacji API: 1M to dla `claude-fable-5-1` maksimum
51
+ * I domyślne okno zarazem, więc wariantu `[1m]` ten model nie ma i czysty identyfikator
52
+ * nie zaniża limitu tak, jak robił to `claude-fable-5` bez nawiasu.
53
+ */
54
+ export const KNOWN_CONTEXT_LIMITS = {
55
+ fable: 1_000_000, 'opus[1m]': 1_000_000, opus: 1_000_000, sonnet: 200_000, haiku: 200_000,
56
+ 'claude-fable-5': 1_000_000, 'claude-fable-5-1': 1_000_000, 'claude-opus-5-5': 1_000_000,
57
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Protocol contract, coordination area: the project coordinator and its threads as a session summary carries them
3
+ * (`docs/coordinator.md`, "Protocol contract").
4
+ *
5
+ * A coordinator is a session that starts threads, each one a session of its own on a branch in a worktree. The server
6
+ * reads the thread files the coordinator writes and says per summary which role the session has and whether a thread
7
+ * is ready to merge, merging or merged; the app derives none of it itself. A worktree session's summary also carries
8
+ * `projectRoot`, the main checkout it belongs to, so the app can group it under its project. All fields are additive.
9
+ *
10
+ * Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
11
+ */
12
+ import { z } from 'zod';
13
+ /**
14
+ * `ready`: the coordinator's checks passed on the branch head, the worktree is clean and the thread is idle;
15
+ * `merging`: the coordinator received Merge for this thread and works on it; `merged`: the branch is on `main`.
16
+ */
17
+ export const THREAD_MERGE_STATES = ['ready', 'merging', 'merged'];
18
+ /** `not-merged`: `ready` again after a Merge that ended without a merge. */
19
+ export const THREAD_MERGE_OUTCOMES = ['not-merged'];
20
+ export const SESSION_COORDINATION_ROLES = ['coordinator', 'thread'];
21
+ export const threadMergeSchema = z.object({
22
+ state: z.enum(THREAD_MERGE_STATES),
23
+ commits: z.number().int().nonnegative(),
24
+ files: z.number().int().nonnegative(),
25
+ since: z.string(),
26
+ outcome: z.enum(THREAD_MERGE_OUTCOMES).optional(),
27
+ });
28
+ export const coordinatorRoleSchema = z.object({
29
+ role: z.literal('coordinator'),
30
+ threads: z.number().int().nonnegative(),
31
+ });
32
+ export const threadRoleSchema = z.object({
33
+ role: z.literal('thread'),
34
+ name: z.string().min(1),
35
+ coordinatorId: z.string().min(1).optional(),
36
+ merge: threadMergeSchema.optional(),
37
+ });
38
+ export const sessionCoordinationSchema = z.discriminatedUnion('role', [coordinatorRoleSchema, threadRoleSchema]);
39
+ const _coordinationSchemaMatchesType = true;
40
+ const _coordinationTypeMatchesSchema = true;
41
+ void _coordinationSchemaMatchesType;
42
+ void _coordinationTypeMatchesSchema;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Protocol contract, dialog card area: the closed lists behind the dialog fields of the session summary (known
3
+ * dialogs, CLI dialog classes, refusal reasons, live card keys) and the fields themselves (`herdrDialog`,
4
+ * `herdrDialogReason`, `herdrDialogScreen`, `cliDialog`, `herdrDialogLive`). `SessionSummary` extends
5
+ * {@link SessionDialogFields}, and `sessionSummarySchema` spreads {@link sessionDialogFieldsShape} in the place of these
6
+ * keys. The body and the answer of `POST /api/sessions/:id/dialog-key` live here too.
7
+ *
8
+ * Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
9
+ */
10
+ import { z } from 'zod';
11
+ /**
12
+ * Dialogi spoza jsonl, które Rarog ROZUMIE na tyle, żeby wystawić przyciski.
13
+ *
14
+ * Lista jest ZAMKNIĘTA i jest odbiciem `KNOWN_DIALOGS` z `server/src/herdr/screen.ts` — nie
15
+ * rośnie „przy okazji". Dialog bez odpowiednika w jsonl to dokładnie ta sytuacja, w której
16
+ * Rarog nie wie, co zatwierdza (zgoda MCP, wyjście z trybu plan), więc wszystko spoza tej
17
+ * listy zostaje przy wycinku ekranu i „Odrzuć dialog" — bez przycisku zatwierdzania.
18
+ */
19
+ export const KNOWN_DIALOG_IDS = ['trust', 'model'];
20
+ export const knownDialogIdSchema = z.enum(KNOWN_DIALOG_IDS);
21
+ /**
22
+ * Klasa dialogu, który rejestr sesji Claude Code zgłasza jako stojący.
23
+ *
24
+ * Serwer czyta ją z pola `waitingFor` pliku `~/.claude/sessions/<pid>.json` i tłumaczy dosłowne
25
+ * nazwy CLI (`permission prompt`, `input needed`, `sandbox request`…) na te krótkie, własne nazwy
26
+ * Raroga (`server/src/cli-version.ts`) — klient nazw CLI nie zna. `other` = dialog jest, tylko nie
27
+ * wiadomo jaki. Lista stoi w protokole, bo czytają ją obie strony: serwer (czytnik, driver,
28
+ * dziennik odmów) i klient (`SessionSummary.cliDialog`).
29
+ */
30
+ export const CLI_DIALOG_CLASSES = [
31
+ 'permission', 'input', 'sandbox', 'worker', 'dialog', 'goal', 'other',
32
+ ];
33
+ export const cliDialogClassSchema = z.enum(CLI_DIALOG_CLASSES);
34
+ /**
35
+ * Powody, dla których decyzja z telefonu NIE wyszła do panelu — ZAMKNIĘTA lista.
36
+ *
37
+ * Jedna unia obsługuje trzy rzeczy naraz i to jest cały powód, dla którego mieszka
38
+ * w protokole, a nie po stronie serwera: kontrakt drivera (`DecisionOutcome`), dziennik
39
+ * audytu (`method: "refuse"` — wpisy mają się SUMOWAĆ, `summarizeRefusals` serwera)
40
+ * i ciało odpowiedzi 422 czytane przez klienta. Dwie równoległe listy rozjechałyby się przy
41
+ * pierwszym nowym powodzie, a wtedy licznik odmów przestałby odpowiadać na pytanie
42
+ * „czy ścieżka cyfrowa realnie zawodzi".
43
+ *
44
+ * Powody dzielą się na trzy grupy i tylko dwie ostatnie wracają kodem 422:
45
+ * - **ocena karty** (`mismatch`, `unreadable`, `no-jsonl`) — Rarog nie umiał złożyć karty
46
+ * z przyciskami; nikt jeszcze o nic nie prosił, więc nie ma żądania, na które odpowiedzieć;
47
+ * - **decyzja** (`multi-select` … `send-failed`) — człowiek tapnął, a klawisz nie wyszedł;
48
+ * - **blokada** (`in-flight`) — powstaje w MANAGERZE, nie w driverze: decyzja o tej karcie
49
+ * właśnie leci z drugiego urządzenia. Do dziennika audytu nie trafia nigdy (`auditRefusal`
50
+ * woła wyłącznie driver), więc obietnicy „wpisy się SUMUJĄ" nie narusza.
51
+ *
52
+ * Lista stoi PRZED sekcją schematów, bo `sessionSummarySchema.herdrDialogReason` jej używa,
53
+ * a `z.enum` czyta stałą w chwili budowy schematu.
54
+ */
55
+ export const REFUSE_REASONS = [
56
+ 'mismatch', 'unreadable', 'no-jsonl', 'multi-select', 'no-digit', 'terminal-only',
57
+ 'screen-changed', 'stale-card', 'form-submit', 'send-failed', 'in-flight',
58
+ /** Dialog ZGODY CLI (np. „Teach auto mode…") stoi w panelu, choć herdr widzi `idle`. */
59
+ 'consent-dialog',
60
+ ];
61
+ export const refuseReasonSchema = z.enum(REFUSE_REASONS);
62
+ /**
63
+ * Keys the live dialog card sends to the dialog in the pane: a closed list, the only keys
64
+ * `POST /api/sessions/:id/dialog-key` takes.
65
+ */
66
+ export const DIALOG_LIVE_KEYS = ['escape', 'up', 'down', 'enter'];
67
+ export const dialogLiveKeySchema = z.enum(DIALOG_LIVE_KEYS);
68
+ /**
69
+ * The live dialog card (`SessionSummary.herdrDialogLive`): the dialog region of the pane as text, refreshed while the
70
+ * dialog stands, with the keys the server takes now.
71
+ *
72
+ * The server sends it next to the card without buttons, never in place of it: an app that does not know the field
73
+ * shows that card. `id` names one occurrence of the card (bound to the engine session and the registry episode when the
74
+ * server issued it); `rev` grows with every change of the view inside it. A key request names both, so a key aimed at
75
+ * another view does not reach the pane.
76
+ */
77
+ export const herdrDialogLiveSchema = z.object({
78
+ /** The occurrence of the card, opaque to the client (the server issues `lv:` and 12 hex digits). */
79
+ id: z.string().min(1),
80
+ /** The view revision inside the occurrence. */
81
+ rev: z.number().int().nonnegative(),
82
+ /** The dialog region, top rule to the last footer line, capped by the server. */
83
+ text: z.string(),
84
+ /** The full label of the option under the cursor, with its continuation lines; `null` = Enter is not available. */
85
+ cursorLabel: z.string().nullable(),
86
+ /** The keys the server takes now. */
87
+ keys: z.array(dialogLiveKeySchema),
88
+ /** Why Enter is not available. */
89
+ refuse: refuseReasonSchema.optional(),
90
+ /** The option under the cursor has a lasting effect (settings, a mode). */
91
+ lasting: z.boolean().optional(),
92
+ /** The dialog is cut at the top: the number of hidden lines, `null` = cut, number unknown; absent = not cut. */
93
+ hiddenAbove: z.number().int().min(1).nullable().optional(),
94
+ /** The full operation from the transcript's `tool_use` entry, when Rarog knows it. */
95
+ operation: z.string().optional(),
96
+ });
97
+ /** Body of `POST /api/sessions/:id/dialog-key`: the occurrence and the view revision the device shows, and the key. */
98
+ export const dialogKeyBodySchema = z.object({
99
+ id: z.string().min(1).max(64),
100
+ rev: z.number().int().nonnegative(),
101
+ key: dialogLiveKeySchema,
102
+ });
103
+ /**
104
+ * 200 of `POST /api/sessions/:id/dialog-key`: the key went out; `live` is the card from a fresh read after the key
105
+ * (also when the screen did not change), `null` = the dialog closed.
106
+ */
107
+ export const dialogKeyResponseSchema = z.object({
108
+ live: herdrDialogLiveSchema.nullable(),
109
+ });
110
+ /** Schemas of {@link SessionDialogFields}, spread into `sessionSummarySchema` in the place of these keys. */
111
+ export const sessionDialogFieldsShape = {
112
+ herdrDialog: knownDialogIdSchema.optional(),
113
+ herdrDialogReason: refuseReasonSchema.optional(),
114
+ herdrDialogScreen: z.string().optional(),
115
+ cliDialog: cliDialogClassSchema.optional(),
116
+ herdrDialogLive: herdrDialogLiveSchema.optional(),
117
+ };
@@ -21,7 +21,7 @@ function byCodeUnits(a, b) {
21
21
  export const FILES_BAD_PATH_ERROR = 'bad-path';
22
22
  /** 400: the session's directory is outside the work area, or the session has no pane: its files stay on the server. */
23
23
  export const FILES_OUT_OF_SCOPE_ERROR = 'out-of-scope';
24
- /** 400: a Codex entry, which Rarog only observes. */
24
+ /** 400: an entry of a state-only engine (Codex, agy), which Rarog only observes; the name stays `codex` on the wire. */
25
25
  export const FILES_CODEX_ERROR = 'codex';
26
26
  /**
27
27
  * 404: nothing to list or send under this path: it does not exist, or the server never shows it (a segment that
@@ -15,6 +15,11 @@ export const inboxCardKindSchema = z.enum(INBOX_CARD_KINDS);
15
15
  /** What a `decision` card waits for: a permission card, a question card, or a dialog in the pane without a card. */
16
16
  export const INBOX_DIALOG_KINDS = ['permission', 'question', 'panel'];
17
17
  export const inboxDialogKindSchema = z.enum(INBOX_DIALOG_KINDS);
18
+ export const inboxCardMergeSchema = z.object({
19
+ name: z.string().min(1),
20
+ coordinatorId: z.string().min(1),
21
+ checked: z.string().regex(/^[0-9a-f]{40}$/u),
22
+ });
18
23
  /** The head schema over the protocol's session state schema. */
19
24
  export function inboxHeadSchemaOf(state) {
20
25
  return z.object({
@@ -25,6 +30,7 @@ export function inboxHeadSchemaOf(state) {
25
30
  state,
26
31
  at: z.string(),
27
32
  dialog: inboxDialogKindSchema.optional(),
33
+ merge: inboxCardMergeSchema.optional(),
28
34
  });
29
35
  }
30
36
  /** The three event schemas, in the order of {@link InboxEventOf}, for the protocol's event union. */
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Protocol contract, presence area: the presence beacon `POST /api/presence` and how long it holds
3
+ * (`PRESENCE_TTL_MS`).
4
+ *
5
+ * Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
6
+ */
7
+ import { z } from 'zod';
8
+ /**
9
+ * Beacon obecności (`POST /api/presence`) — jedyny kanał, którym klient mówi serwerowi
10
+ * „patrzę" albo „już nie patrzę".
11
+ *
12
+ * Istnieje, bo obecności NIE DA SIĘ wywnioskować z otwartego strumienia SSE: iOS usypia apkę
13
+ * w tle, a gniazdo potrafi jeszcze chwilę wisieć. Serwer widziałby wtedy „klient jest" przy
14
+ * zgaszonym ekranie i wysyłał powiadomienia dokładnie wtedy, gdy nie miał prawa — czyli
15
+ * powtórzyłby błąd hooków, tylko z innego powodu.
16
+ *
17
+ * Klient odpowiada na heartbeat SSE, DOPÓKI jest widoczny, i zgłasza zmianę od razu przy
18
+ * `visibilitychange`. Koszt: jedno małe żądanie na 25 s przy otwartej apce, ZERO w tle.
19
+ */
20
+ /**
21
+ * Po tylu ms bez potwierdzenia serwer przestaje uważać klienta za obecnego.
22
+ *
23
+ * Stała mieszka w protokole, bo jest KONTRAKTEM między dwiema stronami, a nie szczegółem
24
+ * którejś z nich: serwer po niej wygasza obecność, a klient musi odświeżać się wyraźnie
25
+ * CZĘŚCIEJ — jedno zgubione żądanie na kiepskim LTE nie ma prawa zamienić patrzącego
26
+ * człowieka w nieobecnego i wypchnąć powiadomienia, którego nikt nie chciał.
27
+ *
28
+ * 40 s covers two presence beacons of the native app (every 20 s), so one lost request is tolerated.
29
+ */
30
+ export const PRESENCE_TTL_MS = 40_000;
31
+ export const presenceBodySchema = z.object({
32
+ /**
33
+ * Identyfikator KARTY, nie użytkownika — losowany przy starcie skryptu i żyjący tyle, co
34
+ * dokument. Serwer używa go wyłącznie do odróżnienia dwóch urządzeń (telefon i iPad mogą
35
+ * patrzeć naraz) i nie wiąże go z niczym trwałym.
36
+ */
37
+ clientId: z.string().min(1).max(64),
38
+ /** `document.visibilityState !== 'hidden'`. */
39
+ visible: z.boolean(),
40
+ /**
41
+ * Sesja, której TRANSKRYPT jest otwarty. Brak = lista, ustawienia, terminal.
42
+ *
43
+ * Osobna informacja od `visible` i o czym innym: `visible` gasi push (patrzysz w Raroga
44
+ * gdziekolwiek), a to pole gasi sygnał o sesji, na którą i tak patrzysz.
45
+ */
46
+ sessionId: z.string().min(1).max(128).optional(),
47
+ });
@@ -14,17 +14,23 @@ import { activitySchema } from './protocol/activity.js';
14
14
  import { imageDataUrlSchema, messageAttachmentSchema } from './protocol/attachments.js';
15
15
  import { backgroundTaskSchema, sessionArtifactSchema, sessionPullRequestSchema, sessionScheduledTaskSchema, } from './protocol/background.js';
16
16
  import { consentAlwaysEntrySchema, SCREEN_UNAVAILABLE_REASONS, } from './protocol/consent.js';
17
+ import { REFUSE_REASONS, refuseReasonSchema, sessionDialogFieldsShape, } from './protocol/dialog-live.js';
17
18
  import { gitCommitSchema, gitFileDetailSchema, gitFileKindsSchema, } from './protocol/git.js';
18
19
  import { herdrModeSchema, herdrStatusEventSchema, herdrStatusSchema, } from './protocol/herdr.js';
19
20
  import { inboxEventSchemas } from './protocol/inbox.js';
20
21
  import { effortLevelSchema, modelIdSchema } from './protocol/model.js';
21
22
  import { notesEventSchema } from './protocol/notes.js';
23
+ import { contextLimitStateSchema, sessionUsageSchema, } from './protocol/context.js';
22
24
  import { folderAccessEventSchema } from './protocol/folders.js';
25
+ import { sessionCoordinationSchema } from './protocol/coordination.js';
23
26
  export * from './protocol/activity.js';
24
27
  export * from './protocol/attachments.js';
25
28
  export * from './protocol/background.js';
26
29
  export * from './protocol/commands.js';
27
30
  export * from './protocol/consent.js';
31
+ export * from './protocol/context.js';
32
+ export * from './protocol/coordination.js';
33
+ export * from './protocol/dialog-live.js';
28
34
  export * from './protocol/dictation.js';
29
35
  export * from './protocol/diff.js';
30
36
  export * from './protocol/directories.js';
@@ -35,6 +41,7 @@ export * from './protocol/herdr.js';
35
41
  export * from './protocol/inbox.js';
36
42
  export * from './protocol/model.js';
37
43
  export * from './protocol/notes.js';
44
+ export * from './protocol/presence.js';
38
45
  export * from './protocol/resume.js';
39
46
  export * from './protocol/terminal.js';
40
47
  /**
@@ -55,74 +62,9 @@ export * from './protocol/terminal.js';
55
62
  * jako „Nie potwierdzono. [Ponów]" i zapraszała do wysłania jej drugi raz.
56
63
  */
57
64
  export const PROTOCOL_VERSION = 3;
58
- export const contextLimitStateSchema = z.discriminatedUnion('kind', [
59
- z.object({ kind: z.literal('unknown'), tokens: z.number(), atLeast: z.number().optional() }),
60
- z.object({
61
- kind: z.literal('known'),
62
- tokens: z.number(),
63
- limit: z.number(),
64
- source: z.enum(['compact-boundary', 'model', 'statusline']),
65
- }),
66
- ]);
67
- /**
68
- * Okna kontekstu, które znamy na pewno — dla aliasów z flag Raroga (`fable`, `opus[1m]`, …) oraz
69
- * dla pełnych identyfikatorów Fable ROZWIĄZANYCH z jsonl (follower potwierdza nimi limit sesji).
70
- * `opus[1m]` = 1M (`contextWindow: 1000000` in `--output-format json`).
71
- * The bare alias `opus` = 1M (Claude Code 2.1.280): `claude --model opus` resolves to
72
- * `claude-opus-5-5` with `contextWindow: 1000000`, and `opus[1m]` to `claude-opus-5-5[1m]` with the
73
- * SAME window — Opus 5.5 has 1M without a variant, like Fable 5.1. The full id `claude-opus-5-5`
74
- * is in the table because a session on the account's default model (`opus`, no flag) gets its
75
- * window only from jsonl and without this entry would stay `unknown`.
76
- *
77
- * The model list carries only the `fable` alias, yet the full Fable ids stay in this table on
78
- * purpose: Rarog also reads sessions started outside it, and transcripts with these ids exist.
79
- * Dropping an entry would not revoke the model — it would take the known window from those
80
- * sessions and drop the context bar to `unknown`.
81
- *
82
- * Fable = 1M, measured on THIS account: the account has the `claude-fable-5[1m]` variant,
83
- * transcripts carry window sums up to 885 852, manual compactions at `preTokens` 744 448,
84
- * and herdr shows 14% exactly when the window sum is 148 704 (148 704 / 1M). A 200 000 limit
85
- * would understate the window fivefold and raise the colour alarm at a third of the session.
86
- *
87
- * Sesja bez flagi `--model` na innym modelu niż fable startuje jako `unknown`: aliasy flag
88
- * (`fable`/`sonnet`/`opus`/`haiku`) nigdy nie są identyfikatorem z jsonl, a wariantu `[1m]`
89
- * modeli spoza rodziny Fable jsonl nie odróżnia. Alias `fable` = 1M, bo obie znane wersje
90
- * (5 z pomiaru, 5.1 z dokumentacji) mają to samo okno.
91
- *
92
- * Fable 5.1 = 1M z dokumentacji API: 1M to dla `claude-fable-5-1` maksimum
93
- * I domyślne okno zarazem, więc wariantu `[1m]` ten model nie ma i czysty identyfikator
94
- * nie zaniża limitu tak, jak robił to `claude-fable-5` bez nawiasu.
95
- */
96
- export const KNOWN_CONTEXT_LIMITS = {
97
- fable: 1_000_000, 'opus[1m]': 1_000_000, opus: 1_000_000, sonnet: 200_000, haiku: 200_000,
98
- 'claude-fable-5': 1_000_000, 'claude-fable-5-1': 1_000_000, 'claude-opus-5-5': 1_000_000,
99
- };
100
65
  // ---------------------------------------------------------------------------
101
66
  // Sesje herdr — jedyne źródło sesji
102
67
  // ---------------------------------------------------------------------------
103
- /**
104
- * Dialogi spoza jsonl, które Rarog ROZUMIE na tyle, żeby wystawić przyciski.
105
- *
106
- * Lista jest ZAMKNIĘTA i jest odbiciem `KNOWN_DIALOGS` z `server/src/herdr/screen.ts` — nie
107
- * rośnie „przy okazji". Dialog bez odpowiednika w jsonl to dokładnie ta sytuacja, w której
108
- * Rarog nie wie, co zatwierdza (zgoda MCP, wyjście z trybu plan), więc wszystko spoza tej
109
- * listy zostaje przy wycinku ekranu i „Odrzuć dialog" — bez przycisku zatwierdzania.
110
- */
111
- export const KNOWN_DIALOG_IDS = ['trust', 'model'];
112
- export const knownDialogIdSchema = z.enum(KNOWN_DIALOG_IDS);
113
- /**
114
- * Klasa dialogu, który rejestr sesji Claude Code zgłasza jako stojący.
115
- *
116
- * Serwer czyta ją z pola `waitingFor` pliku `~/.claude/sessions/<pid>.json` i tłumaczy dosłowne
117
- * nazwy CLI (`permission prompt`, `input needed`, `sandbox request`…) na te krótkie, własne nazwy
118
- * Raroga (`server/src/cli-version.ts`) — klient nazw CLI nie zna. `other` = dialog jest, tylko nie
119
- * wiadomo jaki. Lista stoi w protokole, bo czytają ją obie strony: serwer (czytnik, driver,
120
- * dziennik odmów) i klient (`SessionSummary.cliDialog`).
121
- */
122
- export const CLI_DIALOG_CLASSES = [
123
- 'permission', 'input', 'sandbox', 'worker', 'dialog', 'goal', 'other',
124
- ];
125
- export const cliDialogClassSchema = z.enum(CLI_DIALOG_CLASSES);
126
68
  /**
127
69
  * Twardy limit tekstu wysyłanego do PANELU herdr (`agent.prompt`).
128
70
  *
@@ -151,10 +93,6 @@ export const MAX_HERDR_PROMPT_BYTES = 512 * 1024;
151
93
  * Historia po restarcie serwera zwykle i tak nie dobija do sufitu — tnie ją `HISTORY_MAX_BYTES`.
152
94
  */
153
95
  export const MAX_TRANSCRIPT_MESSAGES = 500;
154
- const _contextLimitSchemaMatchesType = true;
155
- const _contextLimitTypeMatchesSchema = true;
156
- void _contextLimitSchemaMatchesType;
157
- void _contextLimitTypeMatchesSchema;
158
96
  /**
159
97
  * Kanał zgód (warstwa 1): karta, na którą odpowiada się podpisanym plikiem dla śpiącego hooka
160
98
  * `PermissionRequest`, a nie klawiszem do panelu. Dziś jedyna wartość; brak pola = karta ekranowa.
@@ -201,34 +139,6 @@ export const EXIT_PLAN_MODE_TOOL = 'ExitPlanMode';
201
139
  * (`shortenPaths`) — a wtedy z linii zostaje sam prefiks `/Users/…`, czyli nic.
202
140
  */
203
141
  export const WAITING_TEXT_MAX = 120;
204
- /**
205
- * Powody, dla których decyzja z telefonu NIE wyszła do panelu — ZAMKNIĘTA lista.
206
- *
207
- * Jedna unia obsługuje trzy rzeczy naraz i to jest cały powód, dla którego mieszka
208
- * w protokole, a nie po stronie serwera: kontrakt drivera (`DecisionOutcome`), dziennik
209
- * audytu (`method: "refuse"` — wpisy mają się SUMOWAĆ, `summarizeRefusals` serwera)
210
- * i ciało odpowiedzi 422 czytane przez klienta. Dwie równoległe listy rozjechałyby się przy
211
- * pierwszym nowym powodzie, a wtedy licznik odmów przestałby odpowiadać na pytanie
212
- * „czy ścieżka cyfrowa realnie zawodzi".
213
- *
214
- * Powody dzielą się na trzy grupy i tylko dwie ostatnie wracają kodem 422:
215
- * - **ocena karty** (`mismatch`, `unreadable`, `no-jsonl`) — Rarog nie umiał złożyć karty
216
- * z przyciskami; nikt jeszcze o nic nie prosił, więc nie ma żądania, na które odpowiedzieć;
217
- * - **decyzja** (`multi-select` … `send-failed`) — człowiek tapnął, a klawisz nie wyszedł;
218
- * - **blokada** (`in-flight`) — powstaje w MANAGERZE, nie w driverze: decyzja o tej karcie
219
- * właśnie leci z drugiego urządzenia. Do dziennika audytu nie trafia nigdy (`auditRefusal`
220
- * woła wyłącznie driver), więc obietnicy „wpisy się SUMUJĄ" nie narusza.
221
- *
222
- * Lista stoi PRZED sekcją schematów, bo `sessionSummarySchema.herdrDialogReason` jej używa,
223
- * a `z.enum` czyta stałą w chwili budowy schematu.
224
- */
225
- export const REFUSE_REASONS = [
226
- 'mismatch', 'unreadable', 'no-jsonl', 'multi-select', 'no-digit', 'terminal-only',
227
- 'screen-changed', 'stale-card', 'form-submit', 'send-failed', 'in-flight',
228
- /** Dialog ZGODY CLI (np. „Teach auto mode…") stoi w panelu, choć herdr widzi `idle`. */
229
- 'consent-dialog',
230
- ];
231
- export const refuseReasonSchema = z.enum(REFUSE_REASONS);
232
142
  // ---------------------------------------------------------------------------
233
143
  // Schematy zod — bloki domenowe
234
144
  // ---------------------------------------------------------------------------
@@ -237,10 +147,6 @@ export const sessionStateSchema = z.enum([
237
147
  'limit-reached', 'error', 'interrupted', 'done', 'resumable',
238
148
  ]);
239
149
  export const riskSchema = z.enum(['normal', 'red']);
240
- export const sessionUsageSchema = z.object({
241
- contextTokens: z.number(),
242
- contextLimit: z.number(),
243
- });
244
150
  /*
245
151
  * Stands BEFORE `sessionSummarySchema`, which uses it: a module `const` does not hoist like a function, so the
246
152
  * reverse order is a TDZ error at module load.
@@ -321,17 +227,15 @@ export const sessionSummarySchema = z.object({
321
227
  seen: z.boolean().optional(),
322
228
  markedUnseen: z.literal(true).optional(),
323
229
  seenBy: z.literal('voice-agent').optional(),
230
+ ownerTurn: z.literal(true).optional(),
324
231
  stale: z.boolean().optional(),
325
232
  herdrMode: herdrModeSchema.optional(),
326
- herdrDialog: knownDialogIdSchema.optional(),
327
- herdrDialogReason: refuseReasonSchema.optional(),
328
- herdrDialogScreen: z.string().optional(),
329
- cliDialog: cliDialogClassSchema.optional(),
233
+ ...sessionDialogFieldsShape,
330
234
  outOfScope: z.boolean().optional(),
331
235
  // Oba pola ADDYTYWNE i opcjonalne — brak `engine` znaczy „Claude", brak `termId`
332
236
  // znaczy „nie ma dokąd wejść". `z.object` odcina nieznane klucze, więc bez tych dwóch linii
333
237
  // serwer mógłby je wysyłać, a klient parsujący tym schematem i tak by ich nie zobaczył.
334
- engine: z.literal('codex').optional(),
238
+ engine: z.enum(['codex', 'agy']).optional(),
335
239
  termId: z.string().optional(),
336
240
  activity: activitySchema.optional(),
337
241
  backgroundTasks: z.array(backgroundTaskSchema).optional(),
@@ -343,6 +247,8 @@ export const sessionSummarySchema = z.object({
343
247
  waitingFor: waitingForSchema.optional(),
344
248
  cliUpdate: cliUpdateSchema.optional(),
345
249
  promptBlocked: sessionPromptBlockedSchema.optional(),
250
+ projectRoot: z.string().min(1).optional(),
251
+ coordination: sessionCoordinationSchema.optional(),
346
252
  });
347
253
  /** Blok `tool-call` bez reguły `truncation` — baza dla `blockSchema` i widoku tolerancyjnego dekodera. */
348
254
  export const toolCallBlockObjectSchema = z.object({
@@ -655,6 +561,8 @@ export const createSessionBodySchema = z.object({
655
561
  fork: z.boolean().optional(),
656
562
  ultracode: z.literal(true, { error: 'ultracode w ciele startu tylko jako true; brak pola = bez flagi.' })
657
563
  .optional(),
564
+ /** The project's coordinator (`docs/coordinator.md`): `true` or no field, like `ultracode`. */
565
+ coordinator: z.literal(true).optional(),
658
566
  }).refine((body) => body.fork !== true || body.resumeFrom !== undefined, {
659
567
  message: 'Rozwidlenie wymaga podania sesji do wznowienia (`resumeFrom`).',
660
568
  }).refine((body) => body.ultracode !== true || body.effort === undefined || body.effort === 'xhigh', {
@@ -791,46 +699,6 @@ export const clientLogBodySchema = z.object({
791
699
  msg: z.string(),
792
700
  })),
793
701
  });
794
- /**
795
- * Beacon obecności (`POST /api/presence`) — jedyny kanał, którym klient mówi serwerowi
796
- * „patrzę" albo „już nie patrzę".
797
- *
798
- * Istnieje, bo obecności NIE DA SIĘ wywnioskować z otwartego strumienia SSE: iOS usypia apkę
799
- * w tle, a gniazdo potrafi jeszcze chwilę wisieć. Serwer widziałby wtedy „klient jest" przy
800
- * zgaszonym ekranie i wysyłał powiadomienia dokładnie wtedy, gdy nie miał prawa — czyli
801
- * powtórzyłby błąd hooków, tylko z innego powodu.
802
- *
803
- * Klient odpowiada na heartbeat SSE, DOPÓKI jest widoczny, i zgłasza zmianę od razu przy
804
- * `visibilitychange`. Koszt: jedno małe żądanie na 25 s przy otwartej apce, ZERO w tle.
805
- */
806
- /**
807
- * Po tylu ms bez potwierdzenia serwer przestaje uważać klienta za obecnego.
808
- *
809
- * Stała mieszka w protokole, bo jest KONTRAKTEM między dwiema stronami, a nie szczegółem
810
- * którejś z nich: serwer po niej wygasza obecność, a klient musi odświeżać się wyraźnie
811
- * CZĘŚCIEJ — jedno zgubione żądanie na kiepskim LTE nie ma prawa zamienić patrzącego
812
- * człowieka w nieobecnego i wypchnąć powiadomienia, którego nikt nie chciał.
813
- *
814
- * 40 s covers two presence beacons of the native app (every 20 s), so one lost request is tolerated.
815
- */
816
- export const PRESENCE_TTL_MS = 40_000;
817
- export const presenceBodySchema = z.object({
818
- /**
819
- * Identyfikator KARTY, nie użytkownika — losowany przy starcie skryptu i żyjący tyle, co
820
- * dokument. Serwer używa go wyłącznie do odróżnienia dwóch urządzeń (telefon i iPad mogą
821
- * patrzeć naraz) i nie wiąże go z niczym trwałym.
822
- */
823
- clientId: z.string().min(1).max(64),
824
- /** `document.visibilityState !== 'hidden'`. */
825
- visible: z.boolean(),
826
- /**
827
- * Sesja, której TRANSKRYPT jest otwarty. Brak = lista, ustawienia, terminal.
828
- *
829
- * Osobna informacja od `visible` i o czym innym: `visible` gasi push (patrzysz w Raroga
830
- * gdziekolwiek), a to pole gasi sygnał o sesji, na którą i tak patrzysz.
831
- */
832
- sessionId: z.string().min(1).max(128).optional(),
833
- });
834
702
  /**
835
703
  * Etykieta urządzenia w rejestracji APNs (`apnsRegisterBodySchema` w `rest.ts`) — wejście
836
704
  * z telefonu; serwer i tak ją sanityzuje przed zapisem (`sanitizeLabel` w `apns-devices.ts`).