@rarog/server 1.1.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 (161) hide show
  1. package/node_modules/@rarog/shared/package.json +1 -1
  2. package/node_modules/@rarog/shared/src/decode.js +46 -1
  3. package/node_modules/@rarog/shared/src/notify-copy.js +2 -0
  4. package/node_modules/@rarog/shared/src/protocol/background.js +7 -0
  5. package/node_modules/@rarog/shared/src/protocol/context.js +57 -0
  6. package/node_modules/@rarog/shared/src/protocol/coordination.js +42 -0
  7. package/node_modules/@rarog/shared/src/protocol/dialog-live.js +117 -0
  8. package/node_modules/@rarog/shared/src/protocol/files.js +1 -1
  9. package/node_modules/@rarog/shared/src/protocol/inbox.js +6 -0
  10. package/node_modules/@rarog/shared/src/protocol/presence.js +47 -0
  11. package/node_modules/@rarog/shared/src/protocol.js +14 -146
  12. package/node_modules/@rarog/shared/src/rest.js +16 -1
  13. package/node_modules/@rarog/shared/src/sentences/dialogs.js +10 -0
  14. package/node_modules/@rarog/shared/src/sentences/push.js +9 -0
  15. package/node_modules/@rarog/shared/src/sentences/rest.js +9 -0
  16. package/node_modules/@rarog/shared/src/sentences/restart.js +1 -0
  17. package/node_modules/@rarog/shared/src/sentences/session.js +24 -0
  18. package/package.json +2 -2
  19. package/plugin/rarog/.claude-plugin/plugin.json +4 -0
  20. package/plugin/rarog/bin/rarog-coordinator +7 -0
  21. package/plugin/rarog/hooks/hooks.json +18 -0
  22. package/plugin/rarog/hooks/recipient.mjs +95 -0
  23. package/plugin/rarog/lib/coordinator.mjs +1340 -0
  24. package/plugin/rarog/lib/threads.mjs +350 -0
  25. package/plugin/rarog/skills/coordinator/SKILL.md +111 -0
  26. package/plugin/rarog/skills/coordinator/check-and-merge.md +46 -0
  27. package/plugin/rarog/skills/coordinator/close-thread.md +15 -0
  28. package/plugin/rarog/skills/coordinator/role.md +61 -0
  29. package/plugin/rarog/skills/coordinator/send-back.md +39 -0
  30. package/plugin/rarog/skills/coordinator/start-thread.md +43 -0
  31. package/server/src/bootstrap/coordination.js +49 -0
  32. package/server/src/bootstrap/coordinator-start.js +27 -0
  33. package/server/src/bootstrap/inbox.js +4 -0
  34. package/server/src/bootstrap/pr-status.js +15 -7
  35. package/server/src/bootstrap/push.js +59 -5
  36. package/server/src/cli/doctor-pr-status.js +10 -6
  37. package/server/src/companion/catalog.js +1 -1
  38. package/server/src/companion/index.js +2 -4
  39. package/server/src/config/flags.js +4 -0
  40. package/server/src/config-env.js +15 -0
  41. package/server/src/config.js +17 -3
  42. package/server/src/coordination/merge-events.js +86 -0
  43. package/server/src/coordination/merge-prompt.js +244 -0
  44. package/server/src/coordination/registry.js +289 -0
  45. package/server/src/coordination/state.js +94 -0
  46. package/server/src/coordination/summary.js +422 -0
  47. package/server/src/coordination/thread-file.js +245 -0
  48. package/server/src/coordination/thread-git.js +110 -0
  49. package/server/src/coordination/watch.js +237 -0
  50. package/server/src/demo/content/coordinator.js +89 -0
  51. package/server/src/demo/content/en.js +57 -1
  52. package/server/src/demo/content/pl.js +57 -1
  53. package/server/src/demo/control.js +4 -2
  54. package/server/src/demo/inbox.js +12 -0
  55. package/server/src/demo/mock-herdr.js +5 -4
  56. package/server/src/demo/review-routes.js +2 -2
  57. package/server/src/demo/scenarios.js +31 -17
  58. package/server/src/demo/seeds.js +82 -40
  59. package/server/src/drivers/herdr/live-dialog.js +412 -0
  60. package/server/src/drivers/herdr/live-step.js +261 -0
  61. package/server/src/drivers/herdr/pause-gate.js +60 -0
  62. package/server/src/drivers/herdr/pull-request-poll.js +5 -5
  63. package/server/src/drivers/herdr/queue-take-back.js +4 -0
  64. package/server/src/drivers/herdr/returned-prompt.js +4 -1
  65. package/server/src/drivers/herdr/screen-fallback.js +50 -0
  66. package/server/src/drivers/herdr/start-dialog-gate.js +136 -0
  67. package/server/src/drivers/herdr-driver.js +159 -77
  68. package/server/src/files/refusals.js +9 -2
  69. package/server/src/files/session-gate.js +5 -4
  70. package/server/src/git-branch-diff.js +194 -0
  71. package/server/src/herdr/argv.js +34 -3
  72. package/server/src/herdr/audit.js +32 -1
  73. package/server/src/herdr/background/cli-shapes.js +35 -15
  74. package/server/src/herdr/background/index.js +7 -7
  75. package/server/src/herdr/background/merge.js +17 -5
  76. package/server/src/herdr/background/notification.js +0 -4
  77. package/server/src/herdr/background/pull-request-files.js +53 -161
  78. package/server/src/herdr/background/pull-requests.js +54 -632
  79. package/server/src/herdr/background/queued-prompt.js +46 -0
  80. package/server/src/herdr/background/work.js +96 -0
  81. package/server/src/herdr/client.js +22 -46
  82. package/server/src/herdr/commands/catalog.js +11 -7
  83. package/server/src/herdr/commands/discover.js +33 -1
  84. package/server/src/herdr/commands/index.js +3 -2
  85. package/server/src/herdr/dialogs/copy.js +7 -0
  86. package/server/src/herdr/dialogs/index.js +13 -1
  87. package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +4 -56
  88. package/server/src/herdr/dialogs/live/model.js +220 -0
  89. package/server/src/herdr/dialogs/live/policy.js +108 -0
  90. package/server/src/herdr/dialogs/live/view.js +261 -0
  91. package/server/src/herdr/dialogs/screen/form.js +6 -4
  92. package/server/src/herdr/dialogs/screen/option-run.js +25 -3
  93. package/server/src/herdr/dialogs/screen/parse.js +3 -3
  94. package/server/src/herdr/dialogs/screen/signatures.js +78 -0
  95. package/server/src/herdr/dialogs/screen/start-dialog.js +72 -0
  96. package/server/src/herdr/dialogs/screen/trust-arrow.js +46 -9
  97. package/server/src/herdr/engines.js +96 -0
  98. package/server/src/herdr/history-steps.js +9 -4
  99. package/server/src/herdr/identity.js +20 -5
  100. package/server/src/herdr/jsonl-follow.js +26 -3
  101. package/server/src/herdr/label-code.js +104 -0
  102. package/server/src/herdr/label-migration.js +142 -0
  103. package/server/src/herdr/launcher.js +30 -5
  104. package/server/src/herdr/plugin-copy.js +281 -0
  105. package/server/src/herdr/provenance.js +80 -40
  106. package/server/src/herdr/session-index.js +19 -0
  107. package/server/src/herdr/start-dialog-wait.js +96 -0
  108. package/server/src/herdr/supervisor.js +49 -23
  109. package/server/src/herdr/types.js +1 -0
  110. package/server/src/herdr/workspace-resolver.js +5 -4
  111. package/server/src/inbox/card.js +31 -8
  112. package/server/src/inbox/heads.js +1 -0
  113. package/server/src/inbox/inbox.js +21 -4
  114. package/server/src/inbox/removals.js +10 -1
  115. package/server/src/index.js +45 -8
  116. package/server/src/notify/apns-payload.js +5 -3
  117. package/server/src/notify/content.js +64 -0
  118. package/server/src/notify/index.js +11 -3
  119. package/server/src/notify/live-activity-state.js +19 -6
  120. package/server/src/notify/live-activity.js +5 -2
  121. package/server/src/notify/policy.js +53 -13
  122. package/server/src/notify/ready-to-merge.js +148 -0
  123. package/server/src/notify/stalled-wait.js +213 -0
  124. package/server/src/pr-status/facts.js +87 -0
  125. package/server/src/pr-status/gh.js +76 -9
  126. package/server/src/pr-status/index.js +1 -10
  127. package/server/src/pr-status/source.js +20 -6
  128. package/server/src/pr-status/tracker.js +32 -9
  129. package/server/src/project-root.js +233 -0
  130. package/server/src/routes/sessions.js +68 -2
  131. package/server/src/sessions/branch-diff.js +57 -0
  132. package/server/src/sessions/cli-registry.js +17 -3
  133. package/server/src/sessions/companion-scope.js +2 -1
  134. package/server/src/sessions/consent-cards.js +49 -2
  135. package/server/src/sessions/conversation-lists.js +11 -2
  136. package/server/src/sessions/coordinator-start.js +172 -0
  137. package/server/src/sessions/demo-modules.js +1 -0
  138. package/server/src/sessions/demo-seeds.js +100 -0
  139. package/server/src/sessions/driver-events.js +68 -14
  140. package/server/src/sessions/herdr-lifecycle.js +11 -4
  141. package/server/src/sessions/interrupt-windows.js +28 -4
  142. package/server/src/sessions/launch-gate.js +36 -11
  143. package/server/src/sessions/live-dialog.js +69 -0
  144. package/server/src/sessions/manager.js +138 -287
  145. package/server/src/sessions/owner-turn.js +36 -0
  146. package/server/src/sessions/pr-status-link.js +64 -16
  147. package/server/src/sessions/seen-marks.js +31 -12
  148. package/server/src/sessions/session-dialog.js +82 -0
  149. package/server/src/sessions/session-git.js +1 -0
  150. package/server/src/sessions/session-scope.js +6 -5
  151. package/server/src/sessions/session-take-back.js +5 -0
  152. package/server/src/sessions/session.js +82 -10
  153. package/server/src/sessions/state-machine.js +13 -0
  154. package/server/src/sessions/state-sentences.js +87 -30
  155. package/server/src/sessions/test-session.js +50 -0
  156. package/server/src/sessions/waiting-line.js +49 -0
  157. package/server/src/term/herdr-backend.js +15 -12
  158. package/server/src/term/lifecycle.js +4 -6
  159. package/server/src/transcript-import.js +20 -2
  160. package/server/src/version.js +4 -0
  161. /package/server/src/{companion/asks-owner.js → asks-owner.js} +0 -0
@@ -4,6 +4,7 @@ import { foreign } from '@rarog/shared/sentences';
4
4
  import { MAX_DIRTY, demoGitStatus } from '../drivers/mock-driver.js';
5
5
  import { AsyncEventQueue } from '../drivers/runtime.js';
6
6
  import { APPLIED, STALE } from '../drivers/types.js';
7
+ import { ownCommandWaitOf } from '../herdr/background/work.js';
7
8
  import { echoKey } from '../herdr/jsonl-follow.js';
8
9
  import { demoArtifacts, demoBlocks, demoPullRequests, demoScheduledTasks, demoStandbyNotice } from './seeds.js';
9
10
  /** Katalog paneli scenariuszy — w tabeli ahead/behind demo (`rarog`: ↓1). */
@@ -27,6 +28,7 @@ export const SCENARIO_BLOCKED_REASON = 'this session must be restarted before it
27
28
  /** Subagent w postoju scenariusza `standby` (sekcja „w tle” apki: trzy stany subagenta). */
28
29
  export const SCENARIO_STANDBY_TASK_ID = 'm1-standby';
29
30
  export const SCENARIO_STANDBY_NAME = 'Przegląd pokrycia testami';
31
+ const STANDBY_WAIT_AGO_MS = { long: 47 * 60_000, stuck: 75 * 60_000 };
30
32
  /**
31
33
  * Rozkład startowy: 12 skończonych agentów implementacji, 44 skończonych i jeden żywy (od 4 min)
32
34
  * w Review, Poprawki bez agentów. Review ma 45 agentów: rozwinięta lista jej skończonych przewija panel na
@@ -52,7 +54,7 @@ export class ScenarioDriver {
52
54
  sends = 0;
53
55
  decisions = 0;
54
56
  answers = [];
55
- constructor(scenario, label) {
57
+ constructor(scenario, label, wait) {
56
58
  this.#blocksPrompts = scenario === 'prompt-blocked';
57
59
  this.events.push({ type: 'init', engineSessionId: randomUUID(), model: 'claude-fable-5-1' });
58
60
  this.events.push({ type: 'title', title: label });
@@ -70,11 +72,14 @@ export class ScenarioDriver {
70
72
  // „Skończone ostatnio".
71
73
  const now = Date.now();
72
74
  const at = (agoMs) => new Date(now - agoMs).toISOString();
73
- const notice = demoStandbyNotice(18 * 60_000, SCENARIO_STANDBY_NAME);
75
+ const standingMs = wait === undefined ? 18 * 60_000 : STANDBY_WAIT_AGO_MS[wait];
76
+ // The start of the turn, 7 min before the standby, as in the plain scenario.
77
+ const startedMs = standingMs + 7 * 60_000;
78
+ const notice = demoStandbyNotice(standingMs, SCENARIO_STANDBY_NAME);
74
79
  this.events.push({ type: 'history', messages: [
75
- { role: 'user', at: at(26 * 60_000),
80
+ { role: 'user', at: at(startedMs + 60_000),
76
81
  blocks: [{ type: 'text', text: foreign('Policz pokrycie testami modułu transkryptu.') }] },
77
- { role: 'assistant', at: at(25 * 60_000), blocks: [{ type: 'text', text: foreign('Puszczam subagenta w tle.') }] },
82
+ { role: 'assistant', at: at(startedMs), blocks: [{ type: 'text', text: foreign('Puszczam subagenta w tle.') }] },
78
83
  { role: 'user', at: at(notice.agoMs), blocks: demoBlocks(notice.blocks), notice: notice.notice },
79
84
  { role: 'assistant', at: at(notice.agoMs - 2000),
80
85
  blocks: [{
@@ -82,13 +87,17 @@ export class ScenarioDriver {
82
87
  }] },
83
88
  ] });
84
89
  // Stoi od 18 min i czeka na dwie własne komendy; druga bez treści (serwer bywa, że jej nie zna).
85
- this.#standby = {
86
- startedAt: at(25 * 60_000), waitingSince: at(18 * 60_000), waiting: true,
87
- commands: [
90
+ // The variant stands on a wait loop of its own: a `pgrep` that matches its own shell and a `sleep`.
91
+ const commands = wait === undefined
92
+ ? [
88
93
  { id: `${SCENARIO_STANDBY_TASK_ID}-cmd-1`, command: 'pnpm test -- --coverage', startedAt: at(21 * 60_000) },
89
94
  { id: `${SCENARIO_STANDBY_TASK_ID}-cmd-2`, startedAt: at(19 * 60_000) },
90
- ],
91
- };
95
+ ]
96
+ : [
97
+ { id: `${SCENARIO_STANDBY_TASK_ID}-cmd-1`, command: "pgrep -f 'demo-build'", startedAt: at(standingMs + 3 * 60_000) },
98
+ { id: `${SCENARIO_STANDBY_TASK_ID}-cmd-2`, command: 'sleep 30', startedAt: at(standingMs + 60_000) },
99
+ ];
100
+ this.#standby = { startedAt: at(startedMs), waitingSince: at(standingMs), waiting: true, commands };
92
101
  }
93
102
  if (scenario === 'artifacts')
94
103
  this.#pushArtifacts();
@@ -169,7 +178,7 @@ export class ScenarioDriver {
169
178
  say('user', 2 * hour + 60_000, 'Dodaj eksport notatek do CSV i otwórz PR.'),
170
179
  say('assistant', 2 * hour - 5000, 'PR z eksportem otwarty.'),
171
180
  ] });
172
- this.events.push({ type: 'pull-requests', pullRequests: demoPullRequests(now) });
181
+ this.events.push({ type: 'pull-requests', ...demoPullRequests(now) });
173
182
  }
174
183
  /**
175
184
  * Scenario `scheduled-tasks` (the inspector's scheduled tasks section): a short history, then a one-shot and a
@@ -188,17 +197,22 @@ export class ScenarioDriver {
188
197
  ] });
189
198
  this.events.push({ type: 'scheduled-tasks', scheduledTasks: demoScheduledTasks(now) });
190
199
  }
191
- /** Lista zadań scenariusza `standby`: jeden subagent, w postoju albo (po `agent-wake`) pracujący. */
200
+ /**
201
+ * Lista zadań scenariusza `standby`: jeden subagent, w postoju albo (po `agent-wake`) pracujący. The wait stage comes
202
+ * from `ownCommandWaitOf` with the clock of this emission, as `merge.ts` sets it on production lists.
203
+ */
192
204
  #pushStandby() {
193
205
  const agent = this.#standby;
194
206
  if (agent === null)
195
207
  return;
196
- this.events.push({ type: 'background-tasks', tasks: [{
197
- id: SCENARIO_STANDBY_TASK_ID, kind: 'agent', description: SCENARIO_STANDBY_NAME, agentType: 'general-purpose',
198
- model: 'claude-opus-5-5', startedAt: agent.startedAt,
199
- ...(agent.waiting ? { waitingSince: agent.waitingSince } : {}),
200
- ...(agent.commands.length > 0 ? { ownTasks: agent.commands.map((command) => ({ ...command })) } : {}),
201
- }] });
208
+ const task = {
209
+ id: SCENARIO_STANDBY_TASK_ID, kind: 'agent', description: SCENARIO_STANDBY_NAME, agentType: 'general-purpose',
210
+ model: 'claude-opus-5-5', startedAt: agent.startedAt,
211
+ ...(agent.waiting ? { waitingSince: agent.waitingSince } : {}),
212
+ ...(agent.commands.length > 0 ? { ownTasks: agent.commands.map((command) => ({ ...command })) } : {}),
213
+ };
214
+ const stage = ownCommandWaitOf(task, Date.now());
215
+ this.events.push({ type: 'background-tasks', tasks: [stage === undefined ? task : { ...task, ownCommandWait: stage }] });
202
216
  }
203
217
  /**
204
218
  * `agent-wake`: pierwsza własna komenda agenta się skończyła, więc agent ruszył sam. Jedzie w górę bez
@@ -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ę
@@ -19,7 +20,8 @@ import { DEMO_DIFF_FILES, demoAheadBehind } from '../drivers/mock-driver.js';
19
20
  import { toolCallSemantics, writeDiffText } from '../drivers/tool-text.js';
20
21
  import { createArtifactsTracker } from '../herdr/background/artifacts.js';
21
22
  import { noticeFromText } from '../herdr/background/notice.js';
22
- import { sessionPullRequests } from '../herdr/background/pull-requests.js';
23
+ import { CLI_SHAPES } from '../herdr/background/cli-shapes.js';
24
+ import { parsePullRequestUrl, pullRequestLinks } from '../herdr/background/pull-requests.js';
23
25
  import { createScheduledTasksTracker } from '../herdr/background/scheduled-tasks.js';
24
26
  /** Katalog-korzeń projektów demo (allow-lista `GET /api/projects` w trybie demo). */
25
27
  export const DEMO_PROJECTS_ROOT = '/Users/demo/Projects';
@@ -113,8 +115,25 @@ export function demoDiffFile(content, path) {
113
115
  // Bloki mocka dzieli pusta linia; w patchu jednego pliku nie ma po czym jej zostawiać.
114
116
  return block === undefined ? null : { path, patch: block.replace(/\n+$/, '\n'), truncated: false };
115
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
+ ];
116
125
  /**
117
- * 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}.
118
137
  *
119
138
  * @param content zestaw treści demo
120
139
  * @param now „teraz" w ms — wstrzykiwane przez managera, żeby godzina resetu limitu była
@@ -164,7 +183,7 @@ function seedKit(content, now) {
164
183
  { kind: 'image', name: '', bytes: 0, mime: 'image/png', file: BRIDGE_GONE_FILE },
165
184
  ],
166
185
  chartImage: (alt) => ({ type: 'image', dataUrl: demoImages().chart, alt }),
167
- pullRequests: (calls) => pullRequestsOfCalls(now, calls),
186
+ pullRequests: (links) => pullRequestsOfLinks(now, links),
168
187
  artifacts: (publications) => artifactsOfPublications(now, publications),
169
188
  };
170
189
  }
@@ -303,50 +322,73 @@ export function demoPullRequestStates(content) {
303
322
  ...content.pullRequestStates ?? [],
304
323
  ]);
305
324
  }
325
+ /** The `gh` login of the demo's fixed GitHub: the author of every demo PR. It stays in the server's memory. */
326
+ export const DEMO_GITHUB_LOGIN = 'demo';
327
+ /**
328
+ * Time of the first entry of every demo conversation and creation time of every demo PR on the demo's fixed GitHub
329
+ * (the epoch): only the window check reads it, so the demo lists do not depend on the server's uptime.
330
+ */
331
+ const DEMO_CONVERSATION_START_MS = 0;
332
+ /**
333
+ * The demo's fixed GitHub (`bootstrap/pr-status.ts`): every demo PR, authored by {@link DEMO_GITHUB_LOGIN}, with the
334
+ * state of {@link demoPullRequestStates} and the title its card shows (the bare PR has neither).
335
+ *
336
+ * The demo has no GitHub clock: every PR counts as created at {@link DEMO_CONVERSATION_START_MS}, the time of the
337
+ * first entry of every demo conversation ({@link pullRequestsOfLinks}). A conversation lists a PR only when it was
338
+ * created at or after that entry, so the demo PRs stay on their lists however long the server runs.
339
+ */
340
+ export function demoGitHub(content) {
341
+ const states = demoPullRequestStates(content);
342
+ const titles = new Map([
343
+ [DEMO_PULL_REQUESTS.titled, DEMO_PULL_REQUESTS.title],
344
+ [DEMO_PULL_REQUESTS.draft, DEMO_PULL_REQUESTS.draftTitle],
345
+ ...content.pullRequestTitles ?? [],
346
+ ]);
347
+ const urls = new Set([DEMO_PULL_REQUESTS.bare, ...states.keys(), ...titles.keys()]);
348
+ const prs = new Map([...urls].map((url) => {
349
+ const state = states.get(url);
350
+ const title = titles.get(url);
351
+ return [url, {
352
+ author: DEMO_GITHUB_LOGIN, createdAtMs: DEMO_CONVERSATION_START_MS,
353
+ ...(state === undefined ? {} : { state }), ...(title === undefined ? {} : { title }),
354
+ }];
355
+ }));
356
+ return { viewer: DEMO_GITHUB_LOGIN, prs };
357
+ }
306
358
  /**
307
- * Pull requesty sterowanego scenariusza odbioru `pull-requests` (`scenarios.ts`): PR z `--title` utworzony
308
- * 2 h temu, PR z `--fill` (bez tytułu) sprzed doby i PR z `--draft` sprzed ponad dwóch dób (stan `draft` z mapy
309
- * {@link demoPullRequestStates}), najnowszy pierwszy. Listę składa z wpisów pliku rozmowy (wywołanie
310
- * `Bash` i jego wynik) ta sama funkcja co czytnik na produkcji (`sessionPullRequests`), więc zmiana rozpoznania wyjdzie
311
- * też w demo. Repozytoria są syntetyczne.
359
+ * Linked PRs of the controlled `pull-requests` scenario (`scenarios.ts`): the titled PR linked 2 h ago, the bare one
360
+ * a day ago and the draft over two days ago, newest first. The set goes through the production reader rule
361
+ * ({@link pullRequestsOfLinks}); titles and states come from the demo's fixed GitHub ({@link demoGitHub}).
362
+ * The repositories are synthetic.
312
363
  */
313
364
  export function demoPullRequests(now) {
314
- return pullRequestsOfCalls(now, [
315
- {
316
- command: `gh pr create --draft --title "${DEMO_PULL_REQUESTS.draftTitle}"`, output: DEMO_PULL_REQUESTS.draft,
317
- agoMs: 50 * 60 * MIN,
318
- },
319
- {
320
- command: 'git push -u origin docs-csv && gh pr create --fill',
321
- output: `\nCreating pull request for docs-csv into main in acme/widget-docs\n\n${DEMO_PULL_REQUESTS.bare}`,
322
- agoMs: 26 * 60 * MIN,
323
- },
324
- {
325
- command: `gh pr create --title "${DEMO_PULL_REQUESTS.title}" --body "Exports notes as CSV."`,
326
- output: DEMO_PULL_REQUESTS.titled, agoMs: 2 * 60 * MIN,
327
- },
365
+ return pullRequestsOfLinks(now, [
366
+ { url: DEMO_PULL_REQUESTS.draft, agoMs: 50 * 60 * MIN },
367
+ { url: DEMO_PULL_REQUESTS.bare, agoMs: 26 * 60 * MIN },
368
+ { url: DEMO_PULL_REQUESTS.titled, agoMs: 2 * 60 * MIN },
328
369
  ]);
329
370
  }
330
371
  /**
331
- * PR list of a demo conversation: each call becomes a `Bash` call entry and its result entry in the shape of the
332
- * conversation file, and the production reader (`sessionPullRequests`) builds the list from them.
372
+ * Linked PRs of a demo conversation: a first entry at {@link DEMO_CONVERSATION_START_MS}, then each link as a link
373
+ * entry in the shape of the conversation file; the production rule ({@link pullRequestLinks}) builds the set and the
374
+ * window. The card shows the PRs the demo's fixed GitHub ({@link demoGitHub}) gives the demo login as author, with its titles.
333
375
  */
334
- function pullRequestsOfCalls(now, calls) {
376
+ function pullRequestsOfLinks(now, links) {
335
377
  const iso = (agoMs) => new Date(now - agoMs).toISOString();
336
- return sessionPullRequests(calls.flatMap(({ command, output, agoMs }, index) => {
337
- const id = `demo-pr-${String(index)}`;
338
- return [
339
- JSON.stringify({
340
- type: 'assistant', timestamp: iso(agoMs + 5000),
341
- message: { role: 'assistant', content: [{ type: 'tool_use', id, name: 'Bash', input: { command } }] },
342
- }),
343
- JSON.stringify({
344
- type: 'user', timestamp: iso(agoMs),
345
- message: { role: 'user', content: [{ type: 'tool_result', tool_use_id: id, content: output }] },
346
- toolUseResult: { stdout: output, stderr: '', interrupted: false, isImage: false },
347
- }),
348
- ];
349
- }));
378
+ const LINK = CLI_SHAPES.prLink.literals;
379
+ const start = new Date(DEMO_CONVERSATION_START_MS).toISOString();
380
+ const read = pullRequestLinks([
381
+ JSON.stringify({ type: 'user', timestamp: start, message: { role: 'user', content: 'demo' } }),
382
+ ...links.map(({ url, agoMs }) => {
383
+ const pr = parsePullRequestUrl(url);
384
+ return JSON.stringify({
385
+ type: LINK.type, sessionId: 'demo', [LINK.number]: pr?.number, [LINK.url]: url, [LINK.repository]: pr?.repo,
386
+ timestamp: iso(agoMs),
387
+ });
388
+ }),
389
+ ]);
390
+ const pullRequests = read.linked;
391
+ return read.windowStart === null ? { pullRequests } : { pullRequests, windowStart: read.windowStart };
350
392
  }
351
393
  /**
352
394
  * Artifact list of a demo conversation: each publication becomes a result entry of the `Artifact` tool in the shape