@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,110 @@
1
+ /**
2
+ * Git facts of a thread, read with the server's git runner (`git-status.ts`): the head of the thread branch, whether
3
+ * the thread's worktree is clean, and the commits and files of the branch against the branch of the main checkout.
4
+ * {@link ThreadGitFacts} keeps the last facts per thread session and reads them again when asked: at the build of a
5
+ * summary and on an event of the thread's session, because a write in the worktree that moves neither `HEAD` nor the
6
+ * index is not seen by the git watcher. It runs no git command that writes.
7
+ */
8
+ import path from 'node:path';
9
+ import { DIRECT_DISK } from '../folder-gate/disk.js';
10
+ import { parseGitStatusV2 } from '../git-status.js';
11
+ const SHA_LINE = /^[0-9a-f]{40}$/;
12
+ const output = (result) => (result.ok && result.capped !== true ? result.stdout : null);
13
+ async function branchHead(run, main, branch) {
14
+ const command = { sub: 'rev-parse', rest: ['--verify', '--quiet', `refs/heads/${branch}^{commit}`] };
15
+ const out = output(await run(command, main));
16
+ const sha = out?.trim() ?? '';
17
+ return SHA_LINE.test(sha) ? sha : null;
18
+ }
19
+ /**
20
+ * Whether the thread's worktree is clean. The runner binds a read to the nearest directory up with `.git`, so a
21
+ * worktree directory without its own `.git` file would report the main checkout: the worktree must have a `.git`
22
+ * file and stand on the thread branch, otherwise the answer is unknown.
23
+ */
24
+ async function worktreeClean(run, disk, thread) {
25
+ try {
26
+ if (!(await disk.call('lstat', { path: path.join(thread.worktree, '.git') })).isFile())
27
+ return null;
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ const command = { sub: 'status', rest: ['--porcelain=v2', '--branch', '--untracked-files=all'] };
33
+ const out = output(await run(command, thread.worktree));
34
+ if (out === null)
35
+ return null;
36
+ const status = parseGitStatusV2(out);
37
+ return status.branch === thread.branch ? status.dirtyCount === 0 : null;
38
+ }
39
+ async function counts(run, main, head) {
40
+ const [log, diff] = await Promise.all([
41
+ run({ sub: 'log', rest: ['--format=%H', `HEAD..${head}`, '--'] }, main),
42
+ run({ sub: 'diff', rest: ['--name-only', '-z', `HEAD...${head}`, '--'] }, main),
43
+ ]);
44
+ const commits = output(log)?.split('\n').filter((line) => SHA_LINE.test(line)).length ?? null;
45
+ const files = output(diff)?.split('\0').filter(Boolean).length ?? null;
46
+ return { commits, files };
47
+ }
48
+ /** The facts of one thread of the project in `main` (its main checkout). */
49
+ export async function readThreadGit(run, main, thread, disk = DIRECT_DISK) {
50
+ const [head, clean] = await Promise.all([branchHead(run, main, thread.branch), worktreeClean(run, disk, thread)]);
51
+ if (head === null)
52
+ return { head: null, clean, commits: null, files: null };
53
+ return { head, clean, ...(await counts(run, main, head)) };
54
+ }
55
+ const same = (a, b) => a !== undefined && a.head === b.head && a.clean === b.clean && a.commits === b.commits && a.files === b.files;
56
+ /**
57
+ * The last facts per thread session. A refresh asked while one runs is run once more after it, on the newest target,
58
+ * since the write that caused it may have come after the running read began. `forget` drops a running read too: its
59
+ * late result writes nothing, so a pane that moved to another conversation never keeps the previous thread's facts.
60
+ */
61
+ export class ThreadGitFacts {
62
+ #run;
63
+ #disk;
64
+ #facts = new Map();
65
+ #running = new Map();
66
+ constructor(opts) {
67
+ this.#run = opts.run;
68
+ this.#disk = opts.disk ?? DIRECT_DISK;
69
+ }
70
+ /** The last facts read for the thread session, without reading. */
71
+ get(session) {
72
+ return this.#facts.get(session);
73
+ }
74
+ /** Reads the facts of the thread session again; true when they changed. */
75
+ refresh(session, main, thread) {
76
+ const running = this.#running.get(session);
77
+ if (running !== undefined) {
78
+ running.again = true;
79
+ running.main = main;
80
+ running.thread = thread;
81
+ return running.done;
82
+ }
83
+ const entry = { done: Promise.resolve(false), again: false, main, thread };
84
+ entry.done = (async () => {
85
+ let changed = false;
86
+ try {
87
+ do {
88
+ entry.again = false;
89
+ const facts = await readThreadGit(this.#run, entry.main, entry.thread, this.#disk);
90
+ if (this.#running.get(session) !== entry)
91
+ return false;
92
+ if (!same(this.#facts.get(session), facts))
93
+ changed = true;
94
+ this.#facts.set(session, facts);
95
+ } while (entry.again);
96
+ }
97
+ finally {
98
+ if (this.#running.get(session) === entry)
99
+ this.#running.delete(session);
100
+ }
101
+ return changed;
102
+ })();
103
+ this.#running.set(session, entry);
104
+ return entry.done;
105
+ }
106
+ forget(session) {
107
+ this.#facts.delete(session);
108
+ this.#running.delete(session);
109
+ }
110
+ }
@@ -0,0 +1,237 @@
1
+ /**
2
+ * Watcher of the coordinator directory `<main checkout>/.rarog/` of projects with a coordinator: a change of a thread
3
+ * file (`threads/<slug>.md`) tells the caller to read that project again, with one call per burst. The plugin writes a
4
+ * thread file through a temporary file and a rename, so the directory is watched, not the file. The main checkout is
5
+ * watched too, for the `.rarog` entry: a watcher stays with the directory it opened, so after `.rarog` appears, is
6
+ * removed, moved or replaced, the watcher of `.rarog` is opened again on what stands there now. It reads no file and
7
+ * decides nothing about threads.
8
+ *
9
+ * `fs.watch` in a macOS-guarded folder of home waits for the consent window, so a project in such a folder is watched
10
+ * only while the folder gate holds that folder open, as the git watcher does: an unknown folder is checked first, a
11
+ * closed one pauses the project, and `open` starts it again with one call, because changes made meanwhile were not
12
+ * seen.
13
+ */
14
+ import { watch } from 'node:fs';
15
+ import path from 'node:path';
16
+ import { DIRECT_DISK, guardedFolderOf } from '../folder-gate/disk.js';
17
+ import { folderGate } from '../folder-gate/install.js';
18
+ import { COORDINATION_DIR, THREADS_DIR, THREAD_SLUG_RE } from './thread-file.js';
19
+ /** Delay between the first event of a burst and the call; later events of the burst join it. */
20
+ export const DEFAULT_COORDINATION_DEBOUNCE_MS = 300;
21
+ /** Whether an event name relative to `.rarog` can change what the thread reader finds. */
22
+ export function isThreadEvent(name) {
23
+ if (name === null)
24
+ return true;
25
+ const parts = name.split(path.sep);
26
+ if (parts[0] !== THREADS_DIR)
27
+ return false;
28
+ if (parts.length === 1)
29
+ return true;
30
+ const file = parts[1] ?? '';
31
+ return parts.length === 2 && file.endsWith('.md') && THREAD_SLUG_RE.test(file.slice(0, -'.md'.length));
32
+ }
33
+ function isDirectory(dir) {
34
+ try {
35
+ return DIRECT_DISK.sync('lstat', { path: dir }).isDirectory();
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ }
41
+ const defaultWatch = (dir, options, listener) => watch(dir, { recursive: options.recursive, persistent: options.persistent }, (event, name) => {
42
+ listener(event, typeof name === 'string' ? name : null);
43
+ });
44
+ /** One watcher for every project with a coordinator; `watch` and `unwatch` are counted per main checkout. */
45
+ export class CoordinationWatcher {
46
+ #onChange;
47
+ #debounceMs;
48
+ #watchFn;
49
+ #gate;
50
+ #exists;
51
+ #projects = new Map();
52
+ #offGate;
53
+ #closed = false;
54
+ constructor(opts) {
55
+ this.#onChange = opts.onChange;
56
+ this.#debounceMs = opts.debounceMs ?? DEFAULT_COORDINATION_DEBOUNCE_MS;
57
+ this.#watchFn = opts.watchFn ?? defaultWatch;
58
+ this.#gate = opts.gate ?? folderGate();
59
+ this.#exists = opts.exists ?? isDirectory;
60
+ this.#offGate = this.#gate.onChange((folder) => { this.#folderChanged(folder); });
61
+ }
62
+ watch(main) {
63
+ if (this.#closed)
64
+ return;
65
+ const known = this.#projects.get(main);
66
+ if (known !== undefined) {
67
+ known.count += 1;
68
+ return;
69
+ }
70
+ const project = {
71
+ count: 1, data: null, root: null, timer: null, folders: this.#foldersOf(main), paused: false,
72
+ };
73
+ this.#projects.set(main, project);
74
+ if (this.#allOpen(project))
75
+ this.#start(main, project);
76
+ else
77
+ project.paused = true;
78
+ }
79
+ unwatch(main) {
80
+ const project = this.#projects.get(main);
81
+ if (project === undefined)
82
+ return;
83
+ project.count -= 1;
84
+ if (project.count > 0)
85
+ return;
86
+ this.#stop(project);
87
+ this.#projects.delete(main);
88
+ }
89
+ close() {
90
+ this.#closed = true;
91
+ this.#offGate();
92
+ for (const project of this.#projects.values())
93
+ this.#stop(project);
94
+ this.#projects.clear();
95
+ }
96
+ /** Watches the main checkout for the `.rarog` entry, and `.rarog` itself while it is a directory. */
97
+ #start(main, project) {
98
+ project.root ??= this.#open(main, project, main, false, (name) => {
99
+ if (name !== null && name !== COORDINATION_DIR)
100
+ return;
101
+ this.#renewData(main, project);
102
+ this.#bump(main, project);
103
+ });
104
+ if (project.data === null)
105
+ this.#openData(main, project);
106
+ }
107
+ /**
108
+ * The `.rarog` entry changed (created, removed, moved, replaced): the old watcher may hold a directory that is no
109
+ * longer there and would never report again, with or without an error, so it goes and a new one opens.
110
+ */
111
+ #renewData(main, project) {
112
+ if (project.data !== null)
113
+ closeQuietly(project.data);
114
+ project.data = null;
115
+ this.#openData(main, project);
116
+ }
117
+ #openData(main, project) {
118
+ const data = path.join(main, COORDINATION_DIR);
119
+ if (!this.#exists(data))
120
+ return;
121
+ project.data = this.#open(main, project, data, true, (name) => {
122
+ if (isThreadEvent(name))
123
+ this.#bump(main, project);
124
+ });
125
+ }
126
+ #open(main, project, dir, recursive, onName) {
127
+ try {
128
+ const watcher = this.#watchFn(dir, { recursive, persistent: false }, (_event, name) => { onName(name); });
129
+ watcher.on('error', () => { this.#failed(main, project, watcher); });
130
+ return watcher;
131
+ }
132
+ catch {
133
+ return null;
134
+ }
135
+ }
136
+ /** A watcher failed (its directory was removed): close it; for `.rarog`, look again for what stands there now. */
137
+ #failed(main, project, watcher) {
138
+ closeQuietly(watcher);
139
+ if (project.data === watcher) {
140
+ project.data = null;
141
+ if (this.#projects.get(main) === project && !project.paused)
142
+ this.#start(main, project);
143
+ this.#bump(main, project);
144
+ }
145
+ else if (project.root === watcher) {
146
+ project.root = null;
147
+ }
148
+ }
149
+ #bump(main, project) {
150
+ if (this.#closed || project.timer !== null)
151
+ return;
152
+ const timer = setTimeout(() => {
153
+ project.timer = null;
154
+ if (this.#projects.get(main) === project)
155
+ this.#onChange(main);
156
+ }, this.#debounceMs);
157
+ timer.unref();
158
+ project.timer = timer;
159
+ }
160
+ #closeRoot(project) {
161
+ if (project.root !== null)
162
+ closeQuietly(project.root);
163
+ project.root = null;
164
+ }
165
+ #stop(project) {
166
+ if (project.timer !== null)
167
+ clearTimeout(project.timer);
168
+ project.timer = null;
169
+ if (project.data !== null)
170
+ closeQuietly(project.data);
171
+ project.data = null;
172
+ this.#closeRoot(project);
173
+ }
174
+ /**
175
+ * The guarded folders the main checkout lies in, as written or where it resolves: `fs.watch` follows a symbolic
176
+ * link, and the gate judges text only. Both forms are metadata, which never waits for a consent window.
177
+ */
178
+ #foldersOf(main) {
179
+ if (!this.#gate.enabled)
180
+ return [];
181
+ const forms = [main];
182
+ for (const op of ['realpath', 'realpathNative']) {
183
+ try {
184
+ forms.push(DIRECT_DISK.sync(op, { path: main }));
185
+ }
186
+ catch {
187
+ // The other forms decide.
188
+ }
189
+ }
190
+ const folders = new Set();
191
+ for (const form of forms) {
192
+ const folder = this.#gate.stateOf(form)?.folder ?? guardedFolderOf(form)?.folder;
193
+ if (folder !== undefined)
194
+ folders.add(folder);
195
+ }
196
+ return [...folders];
197
+ }
198
+ #allOpen(project) {
199
+ let ready = true;
200
+ for (const folder of project.folders) {
201
+ const state = this.#gate.stateOf(folder)?.state;
202
+ if (state === 'open')
203
+ continue;
204
+ ready = false;
205
+ if (state === 'unknown')
206
+ void this.#gate.check(folder, 0);
207
+ }
208
+ return ready;
209
+ }
210
+ #folderChanged(folder) {
211
+ if (this.#closed)
212
+ return;
213
+ for (const [main, project] of this.#projects) {
214
+ if (!project.folders.includes(folder))
215
+ continue;
216
+ if (this.#allOpen(project)) {
217
+ if (!project.paused)
218
+ continue;
219
+ project.paused = false;
220
+ this.#start(main, project);
221
+ this.#bump(main, project);
222
+ }
223
+ else if (!project.paused) {
224
+ project.paused = true;
225
+ this.#stop(project);
226
+ }
227
+ }
228
+ }
229
+ }
230
+ function closeQuietly(watcher) {
231
+ try {
232
+ watcher.close();
233
+ }
234
+ catch {
235
+ // A watcher after `error` may be closed already.
236
+ }
237
+ }
@@ -0,0 +1,89 @@
1
+ const MIN = 60_000;
2
+ /** Project of the scene, next to the demo projects of the roles; not in the New Session picker. */
3
+ export const DEMO_COORDINATOR_PROJECT = 'atlas';
4
+ /** Threads of the scene in list order; the key is also the branch, the worktree directory and the id suffix. */
5
+ export const DEMO_THREAD_KEYS = [
6
+ 'fix-checkout', 'rate-limits', 'invoice-export', 'search-index', 'release-notes', 'login-copy',
7
+ ];
8
+ /** The coordinator and its threads in the order of {@link DEMO_THREAD_KEYS}. */
9
+ export function coordinatorSeeds(kit, text) {
10
+ const root = `${kit.project('main').replace(/\/[^/]+$/u, '')}/${DEMO_COORDINATOR_PROJECT}`;
11
+ const coordinatorId = 'demo-atlas-coordinator';
12
+ const since = (agoMs) => new Date(kit.now - agoMs).toISOString();
13
+ const threads = DEMO_THREAD_KEYS.map((key) => threadSeed(kit, root, coordinatorId, key, text, since));
14
+ const open = threads.filter((seed) => seed.coordination?.role === 'thread' && seed.coordination.merge?.state !== 'merged');
15
+ const coordinator = {
16
+ id: coordinatorId,
17
+ model: 'claude-opus-4-6',
18
+ effort: 'high',
19
+ cwd: root,
20
+ title: DEMO_COORDINATOR_PROJECT,
21
+ label: text.coordinator.label,
22
+ // Waits for input, so the Merge of a card reaches it as a prompt.
23
+ state: 'waiting-input',
24
+ stateSinceAgoMs: 4 * MIN,
25
+ createdAtAgoMs: 180 * MIN,
26
+ lastActivityAgoMs: 4 * MIN,
27
+ branch: 'main',
28
+ lastSummary: text.coordinator.summary,
29
+ coordination: { role: 'coordinator', threads: open.length },
30
+ messages: [
31
+ { role: 'user', agoMs: 180 * MIN, blocks: kit.text(text.coordinator.prompt) },
32
+ { role: 'assistant', agoMs: 4 * MIN, blocks: kit.text(text.coordinator.reply) },
33
+ ],
34
+ // A live driver, so a Merge sent to the coordinator in the demo starts a turn.
35
+ live: { kind: 'idle' },
36
+ };
37
+ return [coordinator, ...threads];
38
+ }
39
+ /** Per-thread structure: state, clocks, merge state and numbers. */
40
+ const THREADS = {
41
+ // Checks passed on the branch head, clean worktree, idle session: ready to merge.
42
+ 'fix-checkout': { state: 'waiting-input', agoMs: 6 * MIN, createdAgoMs: 150 * MIN, merge: { state: 'ready', commits: 3, files: 6 } },
43
+ 'rate-limits': { state: 'waiting-permission', agoMs: 2 * MIN, createdAgoMs: 140 * MIN, dirtyCount: 2 },
44
+ 'invoice-export': { state: 'error', agoMs: 12 * MIN, createdAgoMs: 130 * MIN, dirtyCount: 1 },
45
+ 'search-index': { state: 'running', agoMs: 40_000, createdAgoMs: 90 * MIN, dirtyCount: 4 },
46
+ // A finished turn whose branch has no passed checks yet: an unread result, no merge state.
47
+ 'release-notes': { state: 'waiting-input', agoMs: 9 * MIN, createdAgoMs: 70 * MIN, dirtyCount: 1 },
48
+ 'login-copy': { state: 'done', agoMs: 35 * MIN, createdAgoMs: 170 * MIN, merge: { state: 'merged', commits: 2, files: 3 } },
49
+ };
50
+ function threadSeed(kit, root, coordinatorId, key, scene, since) {
51
+ const shape = THREADS[key];
52
+ const text = scene.threads[key];
53
+ const id = `demo-atlas-${key}`;
54
+ const merge = shape.merge === undefined ? undefined : { ...shape.merge, since: since(shape.agoMs) };
55
+ const seed = {
56
+ id,
57
+ model: 'claude-opus-4-6',
58
+ effort: 'high',
59
+ cwd: `${root}/.claude/worktrees/${key}`,
60
+ title: key,
61
+ label: text.name,
62
+ state: shape.state,
63
+ stateSinceAgoMs: shape.agoMs,
64
+ createdAtAgoMs: shape.createdAgoMs,
65
+ lastActivityAgoMs: shape.agoMs,
66
+ branch: key,
67
+ ...(shape.dirtyCount === undefined ? {} : { dirtyCount: shape.dirtyCount }),
68
+ lastSummary: text.summary,
69
+ projectRoot: root,
70
+ coordination: {
71
+ role: 'thread', name: text.name, coordinatorId, ...(merge === undefined ? {} : { merge }),
72
+ },
73
+ messages: [
74
+ { role: 'user', agoMs: shape.createdAgoMs, blocks: kit.text(text.brief) },
75
+ { role: 'assistant', agoMs: shape.agoMs, blocks: kit.text(text.reply) },
76
+ ],
77
+ };
78
+ if (shape.state === 'waiting-permission') {
79
+ const permId = `demo-perm-${key}`;
80
+ seed.permission = kit.shellPermission(permId, scene.permissionCommand, shape.agoMs);
81
+ // A driver that holds the card, so Allow and Deny reach it in the demo.
82
+ seed.live = { kind: 'awaiting-permission', reqId: permId };
83
+ }
84
+ // A turn in progress, so Stop works on it in the demo; a thread waiting for input takes a message like any other
85
+ // demo session, because the server refuses a send to a session without a driver.
86
+ if (shape.state === 'running' || shape.state === 'waiting-input')
87
+ seed.live = { kind: 'idle' };
88
+ return seed;
89
+ }
@@ -1,3 +1,4 @@
1
+ import { coordinatorSeeds } from './coordinator.js';
1
2
  const MIN = 60_000;
2
3
  /** Nazwy projektów demo według roli: fikcyjne. */
3
4
  const PROJECTS = {
@@ -176,6 +177,60 @@ const STREAM_FRAGMENTS = [
176
177
  // pierwszego fragmentu skleiłby się ze zdaniem i renderer pokazałby hasze jako tekst.
177
178
  'Next step: finish the integration test on the mock driver.\n\n',
178
179
  ];
180
+ /** The coordinator scene (`coordinator.ts`): project `atlas`, a coordinator and six threads. */
181
+ const COORDINATOR = {
182
+ coordinator: {
183
+ label: 'Coordinator',
184
+ prompt: 'Run the checkout, rate limit, invoice export, search, release notes and login copy work as threads.',
185
+ reply: [
186
+ 'Six threads started, each on its own branch.',
187
+ '',
188
+ '- **Fix checkout** is checked and ready to merge.',
189
+ '- **Login copy** is merged to `main` (not pushed).',
190
+ '- **Invoice export** stopped on an error; I asked it for the failing test.',
191
+ ].join('\n'),
192
+ summary: 'Fix checkout is ready to merge; Login copy merged.',
193
+ },
194
+ threads: {
195
+ 'fix-checkout': {
196
+ name: 'Fix checkout',
197
+ brief: 'The checkout total ignores the discount after a coupon is removed. Fix it and add a test.',
198
+ reply: 'Fixed in `cart/total.ts`; the coupon test covers removal. Done, over to the coordinator.',
199
+ summary: 'Discount recalculated after coupon removal, 3 commits.',
200
+ },
201
+ 'rate-limits': {
202
+ name: 'Rate limits',
203
+ brief: 'Add a per-key rate limit to the public API and document the headers.',
204
+ reply: 'The limiter is in place; I want to run the load test before reporting.',
205
+ summary: 'Limiter added, load test pending.',
206
+ },
207
+ 'invoice-export': {
208
+ name: 'Invoice export',
209
+ brief: 'Export invoices as CSV with the tax columns the accountant asked for.',
210
+ reply: 'The export test fails on the rounding of the tax column; I stopped here.',
211
+ summary: 'Export test fails on tax rounding.',
212
+ },
213
+ 'search-index': {
214
+ name: 'Search index',
215
+ brief: 'Split the search index per workspace so a rebuild does not block the others.',
216
+ reply: 'Rebuilding the index per workspace and measuring the rebuild time.',
217
+ summary: 'Index split per workspace, measuring.',
218
+ },
219
+ 'release-notes': {
220
+ name: 'Release notes',
221
+ brief: 'Draft the release notes for the next version from the merged changes.',
222
+ reply: 'The draft is in `docs/release-notes.txt`; checks have not run on it yet.',
223
+ summary: 'Release notes drafted.',
224
+ },
225
+ 'login-copy': {
226
+ name: 'Login copy',
227
+ brief: 'Rewrite the error messages of the login form in plain language.',
228
+ reply: 'Messages rewritten and the form tests updated.',
229
+ summary: 'Login messages rewritten.',
230
+ },
231
+ },
232
+ permissionCommand: 'npm run load-test -- --rate 200',
233
+ };
179
234
  /**
180
235
  * Definicje 8 sesji startowych (spec, sekcja „Demo mode"), kształt jak w `pl.ts`.
181
236
  *
@@ -602,7 +657,8 @@ function seeds(kit) {
602
657
  }
603
658
  export const demoContentEn = {
604
659
  projects: PROJECTS,
605
- seeds,
660
+ // The 8 sessions of the roles, then the coordinator scene of project `atlas`.
661
+ seeds: (kit) => [...seeds(kit), ...coordinatorSeeds(kit, COORDINATOR)],
606
662
  resumable: [
607
663
  {
608
664
  // Wpis `-0`: w projekcie `main` to rozmowa ŻYWEJ karty `demo-willow` (wiersz „otwarta”).
@@ -1,3 +1,4 @@
1
+ import { coordinatorSeeds } from './coordinator.js';
1
2
  const MIN = 60_000;
2
3
  /** Nazwy projektów demo według roli (testy UI apki szukają ich po tych nazwach). */
3
4
  const PROJECTS = {
@@ -177,6 +178,60 @@ const STREAM_FRAGMENTS = [
177
178
  // (poprawnie, wg CommonMark) traktuje hasze jako zwykły tekst zamiast nagłówka.
178
179
  'Następny krok to domknięcie testu integracyjnego na mock-driverze.\n\n',
179
180
  ];
181
+ /** The coordinator scene (`coordinator.ts`): project `atlas`, a coordinator and six threads. */
182
+ const COORDINATOR = {
183
+ coordinator: {
184
+ label: 'Koordynator',
185
+ prompt: 'Puść jako wątki: koszyk, limity API, eksport faktur, wyszukiwanie, notatki wydania i teksty logowania.',
186
+ reply: [
187
+ 'Sześć wątków ruszyło, każdy na własnej gałęzi.',
188
+ '',
189
+ '- **Napraw koszyk** jest sprawdzony i gotowy do scalenia.',
190
+ '- **Teksty logowania** są scalone do `main` (bez pusha).',
191
+ '- **Eksport faktur** stanął na błędzie; poprosiłem o padający test.',
192
+ ].join('\n'),
193
+ summary: 'Napraw koszyk gotowy do scalenia; Teksty logowania scalone.',
194
+ },
195
+ threads: {
196
+ 'fix-checkout': {
197
+ name: 'Napraw koszyk',
198
+ brief: 'Suma koszyka ignoruje rabat po usunięciu kuponu. Popraw to i dodaj test.',
199
+ reply: 'Poprawione w `cart/total.ts`; test kuponu obejmuje usunięcie. Gotowe, oddaję koordynatorowi.',
200
+ summary: 'Rabat liczony po usunięciu kuponu, 3 commity.',
201
+ },
202
+ 'rate-limits': {
203
+ name: 'Limity API',
204
+ brief: 'Dodaj limit zapytań na klucz w publicznym API i opisz nagłówki.',
205
+ reply: 'Limiter jest; przed raportem chcę puścić test obciążenia.',
206
+ summary: 'Limiter dodany, test obciążenia czeka.',
207
+ },
208
+ 'invoice-export': {
209
+ name: 'Eksport faktur',
210
+ brief: 'Eksportuj faktury do CSV z kolumnami podatku, o które prosiła księgowa.',
211
+ reply: 'Test eksportu pada na zaokrągleniu kolumny podatku; zatrzymałem się.',
212
+ summary: 'Test eksportu pada na zaokrągleniu podatku.',
213
+ },
214
+ 'search-index': {
215
+ name: 'Indeks wyszukiwania',
216
+ brief: 'Podziel indeks wyszukiwania na przestrzenie, żeby przebudowa jednej nie blokowała innych.',
217
+ reply: 'Przebudowuję indeks per przestrzeń i mierzę czas przebudowy.',
218
+ summary: 'Indeks podzielony, pomiar trwa.',
219
+ },
220
+ 'release-notes': {
221
+ name: 'Notatki wydania',
222
+ brief: 'Przygotuj notatki wydania następnej wersji ze scalonych zmian.',
223
+ reply: 'Szkic jest w `docs/release-notes.txt`; sprawdzenia jeszcze na nim nie szły.',
224
+ summary: 'Szkic notatek wydania gotowy.',
225
+ },
226
+ 'login-copy': {
227
+ name: 'Teksty logowania',
228
+ brief: 'Przepisz komunikaty błędów formularza logowania prostym językiem.',
229
+ reply: 'Komunikaty przepisane, testy formularza poprawione.',
230
+ summary: 'Komunikaty logowania przepisane.',
231
+ },
232
+ },
233
+ permissionCommand: 'npm run load-test -- --rate 200',
234
+ };
180
235
  /**
181
236
  * Definicje 8 sesji startowych (spec, sekcja „Demo mode").
182
237
  *
@@ -616,7 +671,8 @@ function seeds(kit) {
616
671
  }
617
672
  export const demoContentPl = {
618
673
  projects: PROJECTS,
619
- seeds,
674
+ // The 8 sessions of the roles, then the coordinator scene of project `atlas`.
675
+ seeds: (kit) => [...seeds(kit), ...coordinatorSeeds(kit, COORDINATOR)],
620
676
  resumable: [
621
677
  {
622
678
  // Wpis `-0`: w projekcie `main` to rozmowa ŻYWEJ karty `demo-willow` (wiersz „otwarta”); w pozostałych
@@ -21,6 +21,18 @@ export function demoInboxManager(manager) {
21
21
  eventsSince: manager.eventsSince.bind(manager),
22
22
  };
23
23
  }
24
+ /** The commit the checks of every demo thread ready to merge passed on: made up, a full SHA as a thread file holds. */
25
+ export const DEMO_CHECKED_COMMIT = '3f9c2a7d41e8b05c6a2f9e1d7b4c8a0e5f6d3b21';
26
+ /**
27
+ * The checked commit of a demo session: the seeds carry no thread file, so a thread whose seed is ready to merge
28
+ * reads {@link DEMO_CHECKED_COMMIT}, and its result card carries the Merge as on the real server; any other none.
29
+ */
30
+ export function demoCheckedOf(manager) {
31
+ return (sessionId) => {
32
+ const role = manager.get(sessionId)?.coordination;
33
+ return role?.role === 'thread' && role.merge?.state === 'ready' ? DEMO_CHECKED_COMMIT : undefined;
34
+ };
35
+ }
24
36
  /** The dialog events of a session stream the tracker folds for the identity of a decision card's dialog. */
25
37
  const DIALOG_EVENTS = new Set([
26
38
  'permission-pending', 'permission-settled', 'permission-resolved', 'question-pending', 'question-resolved',
@@ -24,8 +24,9 @@ import { ScenarioDriver, SCENARIO_CWD } from './scenarios.js';
24
24
  /** Sufit paneli w demo — niższy niż produkcyjny, żeby ścieżkę „limit" dało się pokazać. */
25
25
  export const DEMO_MAX_PANES = 6;
26
26
  /**
27
- * Free panes above the live seeds: a named set can seed more live panes than `en` and `pl` (4), and a fresh demo must
28
- * still let a new session start, or the new session button is dimmed. `en` and `pl` keep 6.
27
+ * Free panes above the live seeds: a set can seed more live panes than {@link DEMO_MAX_PANES} (`en` and `pl`: 9, four
28
+ * among the sessions of the roles and five in the coordinator scene), and a fresh demo must still let a new session
29
+ * start, or the new session button is dimmed.
29
30
  */
30
31
  const DEMO_FREE_PANES = 2;
31
32
  /** Minimalny odstęp między zakładaniem sesji w demo (ta sama reguła co na produkcji). */
@@ -23,8 +23,8 @@
23
23
  */
24
24
  /** Akcje `/api/sessions/:id/<akcja>` (`segments[3]` w routerze): wszystkie dozwolone, podakcje dziedziczą klasę. */
25
25
  const SESSION_ACTIONS = [
26
- 'answers', 'close', 'commands', 'diff', 'files', 'focus', 'interrupt', 'messages', 'mode', 'model', 'permission',
27
- 'permissions', 'queue', 'restart', 'resume', 'seen', 'stream', 'unseen', 'uploads',
26
+ 'answers', 'branch-diff', 'close', 'commands', 'diff', 'dialog-key', 'files', 'focus', 'interrupt', 'messages',
27
+ 'mode', 'model', 'permission', 'permissions', 'queue', 'restart', 'resume', 'seen', 'stream', 'unseen', 'uploads',
28
28
  ];
29
29
  export const REVIEW_ROUTES = [
30
30
  { route: '/health', class: 'allow' },
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Seedy trybu demo — 8 sesji zakładanych przy starcie, gdy rejestr jest pusty.
2
+ * Demo mode seeds: the sessions created at start when the registry is empty (`en` and `pl`: 8 sessions of the roles
3
+ * and the coordinator scene).
3
4
  *
4
5
  * Seedy opisują PRZESZŁOŚĆ deklaratywnie (transkrypt, stan, „czeka od"), a przyszłość zostawiają
5
6
  * mock-driverowi: sesja czekająca na zgodę dostaje żywy driver, który po decyzji poprowadzi turę
@@ -114,8 +115,25 @@ export function demoDiffFile(content, path) {
114
115
  // Bloki mocka dzieli pusta linia; w patchu jednego pliku nie ma po czym jej zostawiać.
115
116
  return block === undefined ? null : { path, patch: block.replace(/\n+$/, '\n'), truncated: false };
116
117
  }
118
+ /** Head of the demo thread branch: a full SHA, as the branch diff contract requires. */
119
+ export const DEMO_BRANCH_HEAD = '4b8e1d6a3f9c2e7b5a0d8f1c6e3b9a2d7f4c0e5b';
120
+ /** Commits of the demo thread branch past its base, newest first. */
121
+ const DEMO_BRANCH_COMMITS = [
122
+ { hash: '4b8e1d6', subject: 'Export invoices as CSV', at: '2026-10-08T10:00:00.000Z' },
123
+ { hash: '9c2f7a1', subject: 'Add the CSV writer', at: '2026-10-08T09:00:00.000Z' },
124
+ ];
117
125
  /**
118
- * 8 sesji startowych (spec, sekcja „Demo mode") z zestawu treści, złożonych z klocków {@link DemoSeedKit}.
126
+ * The branch diff of a demo session: the files of {@link demoDiffFiles}, whose patches {@link demoDiffFile} gives, with
127
+ * the branch's commits, its base branch and its head.
128
+ */
129
+ export function demoBranchDiffFiles() {
130
+ return {
131
+ ...demoDiffFiles(), commits: DEMO_BRANCH_COMMITS.map((commit) => ({ ...commit })), base: { branch: 'main' },
132
+ head: DEMO_BRANCH_HEAD,
133
+ };
134
+ }
135
+ /**
136
+ * Starting sessions (spec, section "Demo mode") of the content set, built from the blocks of {@link DemoSeedKit}.
119
137
  *
120
138
  * @param content zestaw treści demo
121
139
  * @param now „teraz" w ms — wstrzykiwane przez managera, żeby godzina resetu limitu była