teamroom 0.4.0 → 0.6.0

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 (48) hide show
  1. package/README.md +8 -1
  2. package/dist/cli/index.js +8 -8
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/client/config.d.ts +6 -0
  5. package/dist/client/config.js +6 -0
  6. package/dist/client/config.js.map +1 -1
  7. package/dist/client/git.d.ts +5 -0
  8. package/dist/client/git.js +21 -4
  9. package/dist/client/git.js.map +1 -1
  10. package/dist/client/hooks.d.ts +1 -0
  11. package/dist/client/hooks.js +1 -1
  12. package/dist/client/hooks.js.map +1 -1
  13. package/dist/client/setup-files.d.ts +13 -3
  14. package/dist/client/setup-files.js +30 -12
  15. package/dist/client/setup-files.js.map +1 -1
  16. package/dist/client/workspace.js +1 -1
  17. package/dist/client/workspace.js.map +1 -1
  18. package/dist/core/room.d.ts +5 -0
  19. package/dist/core/room.js +29 -15
  20. package/dist/core/room.js.map +1 -1
  21. package/dist/dashboard/model.d.ts +2 -0
  22. package/dist/dashboard/model.js +1 -0
  23. package/dist/dashboard/model.js.map +1 -1
  24. package/dist/server/app.d.ts +4 -2
  25. package/dist/server/app.js +10 -11
  26. package/dist/server/app.js.map +1 -1
  27. package/dist/server/serve.d.ts +9 -0
  28. package/dist/server/serve.js +41 -1
  29. package/dist/server/serve.js.map +1 -1
  30. package/dist/store/file-store.d.ts +3 -0
  31. package/dist/store/file-store.js +32 -1
  32. package/dist/store/file-store.js.map +1 -1
  33. package/dist/store/memory-store.d.ts +2 -0
  34. package/dist/store/memory-store.js +14 -1
  35. package/dist/store/memory-store.js.map +1 -1
  36. package/dist/store/store.d.ts +4 -0
  37. package/dist/store/store.js +3 -0
  38. package/dist/store/store.js.map +1 -1
  39. package/dist/web/join-page.d.ts +9 -0
  40. package/dist/web/join-page.js +119 -0
  41. package/dist/web/join-page.js.map +1 -0
  42. package/dist/web/page.d.ts +3 -3
  43. package/dist/web/page.js +380 -142
  44. package/dist/web/page.js.map +1 -1
  45. package/dist/web/payload.d.ts +29 -0
  46. package/dist/web/payload.js +85 -15
  47. package/dist/web/payload.js.map +1 -1
  48. package/package.json +1 -1
package/dist/web/page.js CHANGED
@@ -26,7 +26,7 @@ export const PAGE_HTML = `<!DOCTYPE html>
26
26
  <header class="top">
27
27
  <p class="brand"><span class="dot" aria-hidden="true"></span>teamroom</p>
28
28
  <p class="where" id="where">Loading the room…</p>
29
- <p class="updated" id="updated"></p>
29
+ <p class="live" id="live"><span class="pulse" aria-hidden="true"></span><span id="updated">Connecting</span></p>
30
30
  </header>
31
31
  <p class="problem" id="problem" role="status" hidden></p>
32
32
  <main>
@@ -34,7 +34,7 @@ export const PAGE_HTML = `<!DOCTYPE html>
34
34
  <div class="columns">
35
35
  <section aria-labelledby="who-title">
36
36
  <h2 id="who-title">Who is working</h2>
37
- <ul class="sessions" id="sessions"></ul>
37
+ <ul class="people" id="sessions"></ul>
38
38
  </section>
39
39
  <section aria-labelledby="log-title">
40
40
  <h2 id="log-title">What happened</h2>
@@ -43,10 +43,12 @@ export const PAGE_HTML = `<!DOCTYPE html>
43
43
  </div>
44
44
  </main>
45
45
  <footer class="how">
46
- <h2>How this works</h2>
47
- <p>Every folder where someone works on this project shares the names of the files it is changing, never what is in them.</p>
48
- <p>When two places change the same file, it shows up at the top of this page, and coding agents get a heads-up before they edit it.</p>
49
- <p id="closing">This page updates on its own. To close it, stop the terminal that opened it.</p>
46
+ <details>
47
+ <summary>How this works</summary>
48
+ <p>Every folder where someone works on this project shares the names of the files it is changing, never what is in them.</p>
49
+ <p>When two people change the same file, or one plans to change a file another is already changing, it shows up at the top of this page, and their coding agents are told before they edit it.</p>
50
+ <p id="closing">This page updates on its own. To close it, stop the terminal that opened it.</p>
51
+ </details>
50
52
  </footer>
51
53
  </body>
52
54
  </html>
@@ -87,79 +89,112 @@ html { background: var(--paper); color: var(--ink); font-family: var(--words); f
87
89
  body { margin: 0 auto; max-width: 1120px; padding: 24px 28px 64px; }
88
90
  h1, h2, p, ul, ol { margin: 0; }
89
91
  ul, ol { padding: 0; list-style: none; }
90
- .mono { font-family: var(--code); font-size: 0.86em; }
92
+ button { font: inherit; }
93
+ :focus-visible { outline: 3px solid var(--overlap); outline-offset: 2px; border-radius: var(--radius-chip); }
91
94
 
92
95
  .top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 20px; padding-bottom: 18px; border-bottom: 1px solid var(--rule); }
93
96
  .brand { font-weight: 800; letter-spacing: -0.02em; font-size: 18px; display: flex; align-items: center; gap: 8px; }
94
97
  .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--overlap); box-shadow: 0 0 0 3px color-mix(in srgb, var(--overlap) 35%, transparent); }
95
98
  .where { color: var(--muted); }
96
99
  .where strong { color: var(--ink); font-weight: 700; }
97
- .updated { margin-left: auto; color: var(--muted); font-size: 13px; }
100
+ .live { margin-left: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
101
+ .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--rule); }
102
+ .live.ok .pulse { background: var(--working); }
103
+ @media (prefers-reduced-motion: no-preference) {
104
+ .live.ok .pulse { animation: pulse 2.4s ease-out infinite; }
105
+ @keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--working) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }
106
+ }
98
107
 
99
108
  .problem { margin-top: 16px; padding: 10px 14px; border-radius: var(--radius-chip); background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--overlap); }
100
109
 
101
- .verdict { padding: 48px 0 40px; }
102
- .verdict h1 { max-width: 24ch; font-size: clamp(30px, 4.4vw, 48px); font-weight: 800; letter-spacing: -0.035em; line-height: 1.04; }
103
- .verdict h1 .mono { font-size: 0.82em; font-weight: 700; letter-spacing: -0.02em; }
104
- .verdict > p { margin-top: 14px; color: var(--muted); font-size: 18px; max-width: 60ch; }
110
+ .verdict { padding: 52px 0 44px; }
111
+ .verdict h1 { max-width: 26ch; font-size: clamp(30px, 4.4vw, 50px); font-weight: 800; letter-spacing: -0.035em; line-height: 1.06; text-wrap: balance; }
112
+ .verdict h1 .file { font-family: var(--code); font-size: 0.8em; font-weight: 700; letter-spacing: -0.02em; }
113
+ .verdict > p { margin-top: 16px; color: var(--muted); font-size: 18px; max-width: 58ch; }
105
114
  mark { color: inherit; background: linear-gradient(transparent 60%, var(--mark-band) 60%, var(--mark-band) 92%, transparent 92%) no-repeat; background-size: 100% 100%; }
115
+ mark.coming { background: none; text-decoration: underline 0.14em dashed var(--overlap); text-underline-offset: 0.16em; }
106
116
  @media (prefers-reduced-motion: no-preference) {
107
117
  mark.arrive { animation: band 700ms cubic-bezier(.2,.7,.2,1) both; }
108
118
  @keyframes band { from { background-size: 0% 100%; } to { background-size: 100% 100%; } }
109
119
  }
110
120
 
111
- .meets { margin-top: 32px; display: grid; gap: 20px; max-width: 920px; }
121
+ .meets { margin-top: 34px; display: grid; gap: 22px; max-width: 940px; }
112
122
  .meet { position: relative; display: grid; gap: 16px; align-items: stretch; }
113
123
  .meet.two { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
114
- .meet.two .file { align-self: center; }
124
+ .meet.two .shared-file { align-self: center; }
115
125
  .meet.two::before { content: ""; position: absolute; left: 12%; right: 12%; top: 50%; border-top: 2px solid var(--overlap); }
126
+ .meet.two.coming::before { border-top-style: dashed; }
116
127
  .meet.many { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
117
- .meet.many .file { grid-column: 1 / -1; justify-self: start; }
118
- .meet .file { position: relative; font-family: var(--code); font-size: 14px; font-weight: 600; padding: 6px 12px; border-radius: var(--radius-chip); background: var(--overlap); color: var(--overlap-ink); }
128
+ .meet.many .shared-file { grid-column: 1 / -1; justify-self: start; }
129
+ .shared-file .dir { opacity: 0.7; font-weight: 500; }
130
+ .shared-file { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; position: relative; font-family: var(--code); font-size: 14px; font-weight: 600; padding: 6px 12px; border-radius: var(--radius-chip); background: var(--overlap); color: var(--overlap-ink); }
131
+ .coming .shared-file { background: var(--surface); color: var(--ink); border: 2px dashed var(--overlap); }
119
132
  .touch { position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-panel); padding: 14px 16px; }
133
+ .touch .head { display: flex; align-items: center; gap: 10px; }
120
134
  .touch .name { font-weight: 700; font-size: 17px; }
121
- .touch .who { color: var(--muted); font-size: 14px; }
122
- .touch .plan { margin-top: 10px; overflow-wrap: anywhere; }
123
-
124
- .columns { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 40px; padding-top: 32px; border-top: 1px solid var(--rule); }
125
- .columns h2, .how h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
126
-
127
- .sessions { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-panel); }
128
- .session { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 4px 12px; padding: 16px 18px; }
129
- .session + .session { border-top: 1px solid var(--rule); }
130
- .state { width: 10px; height: 10px; margin-top: 7px; border-radius: 50%; border: 2px solid var(--rule); }
131
- .state.on { background: var(--working); border-color: var(--working); }
132
- .session .title { font-weight: 700; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
133
- .session .here { font-weight: 500; font-size: 13px; color: var(--muted); }
134
- .session .age { color: var(--muted); font-size: 13px; white-space: nowrap; }
135
- .session .meta, .session .doing, .session .files { grid-column: 2 / 4; }
136
- .session .meta { color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
135
+ .touch .role { color: var(--muted); font-size: 14px; }
136
+ .touch .text { margin-top: 10px; }
137
+
138
+ .columns { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 44px; padding-top: 32px; border-top: 1px solid var(--rule); }
139
+ .columns h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
140
+
141
+ .avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; background: var(--ink); color: var(--paper); }
142
+ .avatar.small { width: 26px; height: 26px; font-size: 12px; }
143
+
144
+ .people { display: grid; gap: 12px; }
145
+ .person { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-panel); padding: 16px 18px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 14px; }
146
+ .person.waiting { border-color: var(--overlap); box-shadow: inset 3px 0 0 var(--overlap); }
147
+ .person.quiet { border-style: dashed; }
148
+ .person .avatar { grid-row: span 2; align-self: start; }
149
+ .person .head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
150
+ .person .name { font-weight: 700; font-size: 17px; }
151
+ .person .place { color: var(--muted); font-size: 14px; }
152
+ .status { margin-left: auto; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
153
+ .status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--rule); }
154
+ .status.on::before { background: var(--working); border-color: var(--working); }
155
+ .status.wait::before { background: var(--overlap); border-color: var(--overlap); }
156
+ .person .meta { color: var(--muted); font-size: 14px; }
157
+ .person .meta .branch { font-family: var(--code); font-size: 13px; }
158
+ .person .body { grid-column: 1 / -1; margin-top: 10px; }
137
159
  .agent { color: var(--agent); font-weight: 600; }
138
- .files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
139
- .chip { font-family: var(--code); font-size: 12.5px; padding: 1px 7px; border-radius: var(--radius-chip); border: 1px solid var(--rule); background: var(--paper); overflow-wrap: anywhere; }
160
+
161
+ .clamp { overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
162
+ .clamp.two { -webkit-line-clamp: 2; }
163
+ .clamp.open { display: block; }
164
+ .toggle { margin-top: 2px; padding: 0; border: 0; background: none; color: var(--agent); font-size: 14px; font-weight: 600; cursor: pointer; }
165
+
166
+ .files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
167
+ .chip { font-family: var(--code); font-size: 12.5px; padding: 2px 8px; border-radius: var(--radius-chip); border: 1px solid var(--rule); background: var(--paper); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
168
+ .chip .dir { color: var(--muted); }
140
169
  .chip.shared { background: var(--overlap); border-color: var(--overlap); color: var(--overlap-ink); }
170
+ .chip.shared .dir { color: inherit; opacity: 0.75; }
171
+ .chip.planned { border-style: dashed; border-color: var(--overlap); }
141
172
  .more { font-size: 13px; color: var(--muted); align-self: center; }
142
- .none { color: var(--muted); padding: 16px 18px; }
143
-
144
- .log li { padding: 2px 0 2px 14px; border-left: 3px solid var(--rule); margin-bottom: 14px; }
145
- .log li.note { border-left-color: var(--ink); }
146
- .log li.edit { border-left-color: var(--agent); }
147
- .log li.commit { border-left-color: var(--working); }
148
- .log .line1 { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 8px; }
149
- .log .line1 .kind { color: var(--ink); font-weight: 600; }
150
- .log .text { overflow-wrap: anywhere; }
173
+ .none { color: var(--muted); background: var(--surface); border: 1px dashed var(--rule); border-radius: var(--radius-panel); padding: 18px; }
174
+
175
+ .log li { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 2px 10px; padding: 10px 0; border-top: 1px solid var(--rule); }
176
+ .log li:first-child { border-top: 0; padding-top: 0; }
177
+ .log .when { color: var(--muted); font-size: 13px; padding-top: 2px; }
178
+ .log .what { overflow-wrap: anywhere; }
179
+ .log .what strong { font-weight: 700; }
180
+ .log .with { color: var(--muted); font-size: 14px; }
181
+ .log .quote { margin-top: 4px; color: var(--muted); }
182
+ .log .files { margin-top: 6px; }
151
183
  .log .times { color: var(--muted); font-size: 13px; margin-left: 6px; }
184
+ .log .empty { display: block; color: var(--muted); border: 0; }
152
185
 
153
- .how { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--rule); color: var(--muted); max-width: 68ch; }
154
- .how p + p { margin-top: 6px; }
186
+ .how { margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--rule); color: var(--muted); max-width: 68ch; }
187
+ .how summary { cursor: pointer; font-weight: 700; color: var(--ink); font-size: 15px; }
188
+ .how p { margin-top: 8px; }
155
189
 
156
190
  @media (max-width: 760px) {
157
191
  body { padding: 18px 16px 48px; }
158
192
  .columns { grid-template-columns: 1fr; }
159
193
  .meet.two { grid-template-columns: 1fr; justify-items: stretch; }
160
- .meet.two .file { justify-self: center; }
194
+ .meet.two .shared-file { justify-self: center; }
161
195
  .meet.two::before { left: 50%; right: auto; top: 10%; bottom: 10%; border-top: 0; border-left: 2px solid var(--overlap); }
162
- .updated { margin-left: 0; width: 100%; }
196
+ .meet.two.coming::before { border-left-style: dashed; }
197
+ .live { margin-left: 0; width: 100%; }
163
198
  }
164
199
  `;
165
200
  export const PAGE_SCRIPT = `"use strict";
@@ -167,9 +202,10 @@ export const PAGE_SCRIPT = `"use strict";
167
202
  var POLL_MS = 3000;
168
203
  var MAX_BACKOFF_MS = 30000;
169
204
  var REQUEST_TIMEOUT_MS = 10000;
170
- var FILES_SHOWN = 8;
171
- var SHARED_FILES_SHOWN = 5;
172
- var KIND_WORDS = { wip: "Shared changes", note: "Plan", edit: "Agent edit", commit: "Commit" };
205
+ var FILES_SHOWN = 6;
206
+ var LOG_FILES_SHOWN = 3;
207
+ var SHARED_FILES_SHOWN = 4;
208
+ var DIRS_KEPT = 2;
173
209
 
174
210
  // A view link carries the room and a read-only key after the #, which the browser never sends to the server.
175
211
  var linkParams = new URLSearchParams(location.hash.slice(1));
@@ -181,15 +217,19 @@ export const PAGE_SCRIPT = `"use strict";
181
217
  var failures = 0;
182
218
  var lastData = null;
183
219
  var lastVerdict = "";
184
- var hadSharedFiles = false;
220
+ var hadCollisions = false;
221
+ var opened = {};
185
222
 
186
223
  function el(tag, className, children) {
187
224
  var node = document.createElement(tag);
188
225
  if (className) node.className = className;
189
- [].concat(children === undefined ? [] : children).forEach(function (child) {
190
- if (child === null || child === undefined || child === false || child === "") return;
191
- node.append(child);
192
- });
226
+ (function add(items) {
227
+ [].concat(items === undefined ? [] : items).forEach(function (child) {
228
+ if (child === null || child === undefined || child === false || child === "") return;
229
+ if (Array.isArray(child)) add(child);
230
+ else node.append(child);
231
+ });
232
+ })(children);
193
233
  return node;
194
234
  }
195
235
 
@@ -207,10 +247,86 @@ export const PAGE_SCRIPT = `"use strict";
207
247
  return plural(Math.round(hours / 24), "day") + " ago";
208
248
  }
209
249
 
250
+ function shortAgo(iso, now) {
251
+ var minutes = Math.round(Math.max(0, now - Date.parse(iso)) / 60000);
252
+ if (minutes < 1) return "now";
253
+ if (minutes < 60) return minutes + " min";
254
+ var hours = Math.round(minutes / 60);
255
+ return hours < 48 ? hours + " h" : Math.round(hours / 24) + " d";
256
+ }
257
+
210
258
  function personName(data, member) {
211
259
  return member === data.me ? "You" : member;
212
260
  }
213
261
 
262
+ function initial(name) {
263
+ var letter = (name || "?").trim().charAt(0);
264
+ return letter ? letter.toUpperCase() : "?";
265
+ }
266
+
267
+ function avatar(name, small) {
268
+ var node = el("span", "avatar" + (small ? " small" : ""), initial(name));
269
+ node.setAttribute("aria-hidden", "true");
270
+ return node;
271
+ }
272
+
273
+ // "You are", "Ada and Bo are", "Ada is".
274
+ function verb(subject, one, many) {
275
+ return subject === "You" || subject.indexOf(" and ") !== -1 ? many : one;
276
+ }
277
+
278
+ function baseName(path) {
279
+ return path.split("/").pop();
280
+ }
281
+
282
+ function joinNames(names) {
283
+ if (names.length <= 1) return names.join("");
284
+ return names.slice(0, -1).join(", ") + " and " + names[names.length - 1];
285
+ }
286
+
287
+ // The last folders and the file name: enough to recognise a file, short enough for one line.
288
+ function fileChip(path, className) {
289
+ var parts = path.split("/");
290
+ var base = parts.pop();
291
+ var dirs = parts.slice(-DIRS_KEPT);
292
+ var prefix = dirs.length ? (parts.length > DIRS_KEPT ? "…/" : "") + dirs.join("/") + "/" : "";
293
+ var chip = el("span", "chip" + (className ? " " + className : ""), [prefix ? el("span", "dir", prefix) : null, base]);
294
+ chip.setAttribute("title", path);
295
+ return chip;
296
+ }
297
+
298
+ function fileList(paths, limit, classFor) {
299
+ var shown = paths.slice(0, limit).map(function (path) { return fileChip(path, classFor ? classFor(path) : ""); });
300
+ if (paths.length > limit) shown.push(el("span", "more", "and " + (paths.length - limit) + " more"));
301
+ return el("div", "files", shown);
302
+ }
303
+
304
+ // Long text shows a few lines and a button that opens the rest; what is open stays open across refreshes.
305
+ function clamped(id, text, className) {
306
+ var body = el("p", "clamp " + (className || "") + (opened[id] ? " open" : ""), text);
307
+ var wrap = el("div", "", body);
308
+ requestAnimationFrame(function () {
309
+ if (!opened[id] && body.scrollHeight <= body.clientHeight + 1) return;
310
+ var button = el("button", "toggle", opened[id] ? "Show less" : "Show more");
311
+ button.type = "button";
312
+ button.setAttribute("aria-expanded", opened[id] ? "true" : "false");
313
+ button.addEventListener("click", function () {
314
+ opened[id] = !opened[id];
315
+ body.classList.toggle("open", opened[id]);
316
+ button.textContent = opened[id] ? "Show less" : "Show more";
317
+ button.setAttribute("aria-expanded", opened[id] ? "true" : "false");
318
+ });
319
+ wrap.append(button);
320
+ });
321
+ return wrap;
322
+ }
323
+
324
+ function sharedChip(path) {
325
+ var chip = fileChip(path);
326
+ chip.className = "shared-file";
327
+ return chip;
328
+ }
329
+
214
330
  function renderTop(data) {
215
331
  var where = document.getElementById("where");
216
332
  var scope = data.room.mode === "local"
@@ -219,140 +335,260 @@ export const PAGE_SCRIPT = `"use strict";
219
335
  where.replaceChildren(el("strong", "", data.room.name), ", " + scope);
220
336
  }
221
337
 
222
- function touchCard(data, session) {
338
+ function sessionName(data, session) {
339
+ return personName(data, session.member) + (session.place ? " in " + session.place : "");
340
+ }
341
+
342
+ function touchCard(data, session, role) {
223
343
  return el("div", "touch", [
224
- el("p", "name", session.label),
225
- el("p", "who", [personName(data, session.member), session.agent ? el("span", "agent", ", with " + session.agent) : ", no agent"]),
226
- el("p", "plan", session.plan || session.doing)
344
+ el("div", "head", [avatar(session.member), el("div", "", [
345
+ el("p", "name", sessionName(data, session)),
346
+ el("p", "role", [role, session.agent ? el("span", "agent", ", with " + session.agent) : null])
347
+ ])]),
348
+ el("div", "text", clamped("touch:" + session.key, session.plan || session.doing))
227
349
  ]);
228
350
  }
229
351
 
230
- function renderVerdict(data) {
231
- var byKey = {};
232
- data.sessions.forEach(function (session) { byKey[session.key] = session; });
233
- var signature = JSON.stringify([data.sessions.length, data.sharedFiles, data.sharedFiles.map(function (file) {
234
- return file.sessionKeys.map(function (key) { return byKey[key] && [byKey[key].doing, byKey[key].agent]; });
235
- })]);
236
- if (signature === lastVerdict) return;
237
- lastVerdict = signature;
238
-
239
- var verdict = document.getElementById("verdict");
240
- var hasShared = data.sharedFiles.length > 0;
241
- var arriving = hasShared && !hadSharedFiles;
242
- hadSharedFiles = hasShared;
352
+ function verdictMessage(data, byKey) {
353
+ var collisions = data.sharedFiles;
354
+ var coming = data.plannedFiles || [];
355
+ var names = function (keys) {
356
+ return joinNames(keys.map(function (key) { return byKey[key] ? sessionName(data, byKey[key]) : "someone"; }));
357
+ };
243
358
 
244
359
  if (data.sessions.length === 0) {
245
- verdict.replaceChildren(
246
- el("h1", "", "Nobody has shared any work yet."),
247
- el("p", "", ["Make a commit in a project folder, or run ", el("span", "mono", "teamroom report"), ", and it shows up here."])
248
- );
249
- return;
360
+ return {
361
+ heading: ["Nobody is working right now."],
362
+ detail: hosted
363
+ ? "This page fills in as soon as someone starts, and it refreshes on its own."
364
+ : "Start a coding agent in a project folder, or make a commit, and it shows up here."
365
+ };
250
366
  }
251
367
 
252
- if (!hasShared) {
253
- verdict.replaceChildren(
254
- el("h1", "", "Everyone is working in their own files."),
255
- el("p", "", "No file is being changed in two places right now.")
256
- );
257
- return;
368
+ if (collisions.length > 0) {
369
+ var first = collisions[0];
370
+ var allMine = collisions.every(function (file) {
371
+ return file.sessionKeys.every(function (key) { return byKey[key] && byKey[key].isMine; });
372
+ });
373
+ return {
374
+ collision: true,
375
+ heading: collisions.length === 1
376
+ ? [{ mark: baseName(first.path), title: first.path, file: true }, " is being changed by " + names(first.sessionKeys) + "."]
377
+ : [{ mark: plural(collisions.length, "file") }, " are being changed in more than one place."],
378
+ detail: allMine
379
+ ? "These are all your own folders. Let one finish before the other continues, or they will clash when you merge."
380
+ : "Agree on who goes first before everyone continues. What each one is doing is below."
381
+ };
258
382
  }
259
383
 
260
- var first = data.sharedFiles[0];
261
- var heading = data.sharedFiles.length === 1
262
- ? el("h1", "", [el("mark", arriving ? "arrive" : "", el("span", "mono", first.path)), " is being changed in " + first.sessionKeys.length + " places."])
263
- : el("h1", "", [el("mark", arriving ? "arrive" : "", plural(data.sharedFiles.length, "file")), " are being changed in more than one place."]);
384
+ if (coming.length > 0) {
385
+ var next = coming[0];
386
+ var heading = coming.length > 1
387
+ ? [{ mark: plural(coming.length, "file"), coming: true }, " are about to be changed in two places."]
388
+ : next.changingBy.length > 0
389
+ ? [names(next.plannedBy) + " " + verb(names(next.plannedBy), "wants", "want") + " to change ", { mark: baseName(next.path), title: next.path, file: true, coming: true }, ", which " + names(next.changingBy) + " " + verb(names(next.changingBy), "is", "are") + " changing now."]
390
+ : [names(next.plannedBy) + " both plan to change ", { mark: baseName(next.path), title: next.path, file: true, coming: true }, "."];
391
+ return {
392
+ coming: true,
393
+ heading: heading,
394
+ detail: "Caught before both edited it, so nothing clashes yet. Agree on who goes first."
395
+ };
396
+ }
264
397
 
265
- var allMine = data.sharedFiles.every(function (file) {
266
- return file.sessionKeys.every(function (key) { return byKey[key] && byKey[key].isMine; });
398
+ var fileCount = data.sessions.reduce(function (total, session) { return total + session.files.length; }, 0);
399
+ var activePeople = [];
400
+ data.sessions.forEach(function (session) {
401
+ if (session.active && activePeople.indexOf(session.member) === -1) activePeople.push(session.member);
267
402
  });
268
- var advice = allMine
269
- ? "These are all your own folders. Let one finish before the other continues, or they will clash when you merge."
270
- : "Agree on who goes first before " + (data.sharedFiles.length === 1 && first.sessionKeys.length === 2 ? "both continue" : "everyone continues") + ". What each one is doing is below.";
271
-
272
- var meets = el("div", "meets", data.sharedFiles.slice(0, SHARED_FILES_SHOWN).map(function (file) {
273
- var touching = file.sessionKeys.map(function (key) { return byKey[key]; }).filter(Boolean);
274
- var chip = el("p", "file", file.path);
275
- if (touching.length === 2) {
276
- return el("div", "meet two", [touchCard(data, touching[0]), chip, touchCard(data, touching[1])]);
277
- }
278
- return el("div", "meet many", [chip].concat(touching.map(function (session) { return touchCard(data, session); })));
279
- }));
403
+ var inProgress = fileCount > 0 ? plural(fileCount, "file") + " in progress" : "No files in progress";
404
+ if (activePeople.length === 0) {
405
+ return { heading: ["Nobody is working right now."], detail: inProgress + ". This page refreshes on its own." };
406
+ }
407
+ if (activePeople.length === 1) {
408
+ var only = personName(data, activePeople[0]);
409
+ return {
410
+ heading: [only === "You" ? "Only you are working right now." : "Only " + only + " is working right now."],
411
+ detail: inProgress + "."
412
+ };
413
+ }
414
+ return {
415
+ heading: ["Everyone is on different files."],
416
+ detail: plural(activePeople.length, "person").replace("persons", "people") + " working, " + inProgress.charAt(0).toLowerCase() + inProgress.slice(1) + ", none of them shared."
417
+ };
418
+ }
280
419
 
281
- verdict.replaceChildren(heading, el("p", "", advice), meets);
420
+ function renderVerdict(data) {
421
+ var byKey = {};
422
+ data.sessions.forEach(function (session) { byKey[session.key] = session; });
423
+ var signature = JSON.stringify([data.sessions.map(function (session) {
424
+ return [session.key, session.doing, session.plan, session.agent, session.files.length, session.active];
425
+ }), data.sharedFiles, data.plannedFiles]);
426
+ if (signature === lastVerdict) return;
427
+ lastVerdict = signature;
428
+
429
+ var message = verdictMessage(data, byKey);
430
+ var arriving = !!message.collision && !hadCollisions;
431
+ hadCollisions = !!message.collision;
432
+
433
+ var heading = el("h1", "", message.heading.map(function (part) {
434
+ if (typeof part === "string") return part;
435
+ var label = part.file ? el("span", "file", part.mark) : part.mark;
436
+ var marked = el("mark", (part.coming ? "coming" : "") + (arriving ? " arrive" : ""), label);
437
+ if (part.title) marked.setAttribute("title", part.title);
438
+ return marked;
439
+ }));
440
+ var parts = [heading, el("p", "", message.detail)];
441
+
442
+ if (message.collision) {
443
+ parts.push(el("div", "meets", data.sharedFiles.slice(0, SHARED_FILES_SHOWN).map(function (file) {
444
+ var touching = file.sessionKeys.map(function (key) { return byKey[key]; }).filter(Boolean);
445
+ var chip = sharedChip(file.path);
446
+ var cards = touching.map(function (session) { return touchCard(data, session, "Changing it"); });
447
+ return touching.length === 2
448
+ ? el("div", "meet two", [cards[0], chip, cards[1]])
449
+ : el("div", "meet many", [chip].concat(cards));
450
+ })));
451
+ } else if (message.coming) {
452
+ parts.push(el("div", "meets", data.plannedFiles.slice(0, SHARED_FILES_SHOWN).map(function (file) {
453
+ var cards = file.changingBy.map(function (key) { return byKey[key] && touchCard(data, byKey[key], "Changing it"); })
454
+ .concat(file.plannedBy.map(function (key) { return byKey[key] && touchCard(data, byKey[key], "Wants to change it"); }))
455
+ .filter(Boolean);
456
+ var chip = sharedChip(file.path);
457
+ return cards.length === 2
458
+ ? el("div", "meet two coming", [cards[0], chip, cards[1]])
459
+ : el("div", "meet many coming", [chip].concat(cards));
460
+ })));
461
+ }
462
+ document.getElementById("verdict").replaceChildren.apply(document.getElementById("verdict"), parts);
282
463
  }
283
464
 
284
465
  function renderSessions(data, now) {
285
466
  var list = document.getElementById("sessions");
286
- if (data.sessions.length === 0) {
287
- list.replaceChildren(el("li", "none", "No one has worked here in the last 3 days."));
467
+ var notStarted = data.notStarted || [];
468
+ if (data.sessions.length === 0 && notStarted.length === 0) {
469
+ list.replaceChildren(el("li", "none", hosted
470
+ ? "No one has worked here in the last 3 days. People show up as soon as they start."
471
+ : "No one has worked here in the last 3 days."));
288
472
  return;
289
473
  }
290
- list.replaceChildren.apply(list, data.sessions.map(function (session) {
291
- var state = el("span", "state" + (session.active ? " on" : ""));
292
- state.setAttribute("title", session.active ? "Working now" : "Quiet");
293
- state.setAttribute("aria-label", session.active ? "Working now" : "Quiet");
294
- state.setAttribute("role", "img");
295
-
296
- var shown = session.files.slice(0, FILES_SHOWN);
297
- var hidden = session.files.length - shown.length;
298
- var files = shown.map(function (file) {
299
- var chip = el("span", "chip" + (file.shared ? " shared" : ""), file.path);
300
- if (file.shared) chip.setAttribute("title", "Also being changed somewhere else");
301
- return chip;
302
- });
303
- if (hidden > 0) files.push(el("span", "more", "and " + hidden + " more"));
304
-
305
- return el("li", "session", [
306
- state,
307
- el("p", "title", [session.label, session.isHere ? el("span", "here", "this folder") : null]),
308
- el("p", "age", ago(session.lastSeen, now)),
474
+ var waiting = {};
475
+ (data.plannedFiles || []).forEach(function (file) {
476
+ if (file.changingBy.length > 0) file.plannedBy.forEach(function (key) { waiting[key] = true; });
477
+ });
478
+ var planned = {};
479
+ (data.plannedFiles || []).forEach(function (file) { planned[file.path] = true; });
480
+
481
+ var cards = data.sessions.map(function (session) {
482
+ var status = waiting[session.key]
483
+ ? el("span", "status wait", "Waiting on a file")
484
+ : el("span", "status" + (session.active ? " on" : ""), session.active ? "Working now" : "Quiet, " + ago(session.lastSeen, now));
485
+ var filePaths = session.files.map(function (file) { return file.path; });
486
+ var shared = {};
487
+ session.files.forEach(function (file) { if (file.shared) shared[file.path] = true; });
488
+ var wanted = session.plannedFiles.filter(function (path) { return filePaths.indexOf(path) === -1; });
489
+
490
+ return el("li", "person" + (waiting[session.key] ? " waiting" : ""), [
491
+ avatar(session.member),
492
+ el("p", "head", [
493
+ el("span", "name", personName(data, session.member)),
494
+ session.place ? el("span", "place", "in " + session.place + (session.isHere ? ", this folder" : "")) : null,
495
+ status
496
+ ]),
309
497
  el("p", "meta", [
310
- el("span", "", personName(data, session.member)),
311
- session.branch ? el("span", "", ["on ", el("span", "mono", session.branch)]) : null,
312
- session.agent ? el("span", "agent", session.agent) : el("span", "", "No agent")
498
+ session.agent ? el("span", "agent", session.agent) : "No agent",
499
+ session.branch ? [" on ", el("span", "branch", session.branch)] : null
313
500
  ]),
314
- el("p", "doing", session.plan || session.doing),
315
- files.length > 0 ? el("div", "files", files) : null
501
+ el("div", "body", [
502
+ clamped("person:" + session.key, session.plan || session.doing),
503
+ filePaths.length > 0 ? fileList(filePaths, FILES_SHOWN, function (path) {
504
+ return shared[path] ? "shared" : planned[path] ? "planned" : "";
505
+ }) : null,
506
+ wanted.length > 0 && waiting[session.key] ? fileList(wanted, FILES_SHOWN, function () { return "planned"; }) : null
507
+ ])
316
508
  ]);
317
- }));
509
+ });
510
+ list.replaceChildren.apply(list, cards.concat(notStarted.map(function (quiet) {
511
+ return quietCard(data, quiet, now);
512
+ })));
513
+ }
514
+
515
+ function quietCard(data, quiet, now) {
516
+ var you = quiet.member === data.me;
517
+ return el("li", "person quiet", [
518
+ avatar(quiet.member),
519
+ el("p", "head", [
520
+ el("span", "name", personName(data, quiet.member)),
521
+ el("span", "status", "Joined " + ago(quiet.joinedAt, now))
522
+ ]),
523
+ el("p", "meta", you
524
+ ? "Nothing shared yet. You show up here once you change a file or share a plan."
525
+ : "Nothing shared yet. They show up here once they change a file or share a plan.")
526
+ ]);
527
+ }
528
+
529
+ function logLine(data, entry, now) {
530
+ var who = el("strong", "", personName(data, entry.member) + (entry.place ? " in " + entry.place : ""));
531
+ var with_ = entry.agent ? el("span", "with", " with " + entry.agent) : null;
532
+ var times = entry.count > 1 ? el("span", "times", entry.count + " times") : null;
533
+ var what;
534
+ if (entry.kind === "note") {
535
+ what = [el("p", "", [who, " shared a plan", with_, times]), el("div", "quote", clamped("log:" + entry.id, entry.text, "two"))];
536
+ } else if (entry.kind === "edit" && entry.files.length > 0) {
537
+ what = [el("p", "", [who, " edited", with_, times]), fileList(entry.files, LOG_FILES_SHOWN)];
538
+ } else if (entry.kind === "wip") {
539
+ var subject = personName(data, entry.member);
540
+ what = [el("p", "", [who, " " + verb(subject, "is", "are") + " working on " + plural(entry.files.length, "file"), times]), fileList(entry.files, LOG_FILES_SHOWN)];
541
+ } else if (entry.kind === "commit") {
542
+ what = [el("p", "", [who, " committed", times]), el("div", "quote", clamped("log:" + entry.id, entry.text, "two"))];
543
+ } else {
544
+ what = [el("p", "", [who, ": " + entry.text, times])];
545
+ }
546
+ var when = el("time", "when", shortAgo(entry.at, now));
547
+ when.setAttribute("datetime", entry.at);
548
+ when.setAttribute("title", ago(entry.at, now));
549
+ return el("li", entry.kind, [when, el("div", "what", what)]);
318
550
  }
319
551
 
320
552
  function renderLog(data, now) {
321
553
  var log = document.getElementById("log");
322
554
  if (data.recent.length === 0) {
323
- log.replaceChildren(el("li", "", "Nothing yet."));
555
+ log.replaceChildren(el("li", "empty", "Nothing yet."));
324
556
  return;
325
557
  }
326
- log.replaceChildren.apply(log, data.recent.map(function (entry) {
327
- var who = personName(data, entry.member) + (entry.sessionLabel ? " in " + entry.sessionLabel : "");
328
- return el("li", entry.kind, [
329
- el("p", "line1", [
330
- el("span", "kind", KIND_WORDS[entry.kind] || entry.kind),
331
- el("span", "", who + (entry.agent ? ", " + entry.agent : "")),
332
- el("span", "", ago(entry.at, now))
333
- ]),
334
- el("p", "text", [entry.text, entry.count > 1 ? el("span", "times", entry.count + " times") : null])
335
- ]);
336
- }));
558
+ log.replaceChildren.apply(log, data.recent.map(function (entry) { return logLine(data, entry, now); }));
337
559
  }
338
560
 
561
+ // Rebuilding a list only when what it shows changed keeps clicks, focus and text selection intact between refreshes.
562
+ var lastLists = "";
563
+ var MINUTE_MS = 60000;
564
+
339
565
  function render(data) {
340
566
  var now = Date.now();
341
567
  renderTop(data);
342
568
  renderVerdict(data);
569
+ var lists = JSON.stringify([data.me, data.sessions, data.plannedFiles, data.recent, Math.floor(now / MINUTE_MS)]);
570
+ if (lists === lastLists) return;
571
+ lastLists = lists;
343
572
  renderSessions(data, now);
344
573
  renderLog(data, now);
345
574
  }
346
575
 
576
+ function setLive(ok) {
577
+ document.getElementById("live").classList.toggle("ok", ok);
578
+ }
579
+
347
580
  function showProblem(message, retryMs) {
348
581
  var problem = document.getElementById("problem");
349
582
  var shownSince = lastData ? " Showing what was there " + ago(lastData.updatedAt, Date.now()) + "." : "";
350
583
  problem.textContent = "Can't reach the room: " + message + shownSince + " Trying again in " + Math.round(retryMs / 1000) + " s.";
351
584
  problem.hidden = false;
585
+ setLive(false);
352
586
  }
353
587
 
354
588
  function showUpdated() {
355
- document.getElementById("updated").textContent = lastData ? "Updated " + ago(lastData.updatedAt, Date.now()) : "";
589
+ document.getElementById("updated").textContent = lastData
590
+ ? (failures === 0 ? "Live, updated " + ago(lastData.updatedAt, Date.now()) : "Updated " + ago(lastData.updatedAt, Date.now()))
591
+ : "Connecting";
356
592
  }
357
593
 
358
594
  function request(signal) {
@@ -370,6 +606,7 @@ export const PAGE_SCRIPT = `"use strict";
370
606
  problem.hidden = false;
371
607
  document.getElementById("where").textContent = "";
372
608
  document.querySelector("main").hidden = true;
609
+ setLive(false);
373
610
  }
374
611
 
375
612
  function poll() {
@@ -391,6 +628,7 @@ export const PAGE_SCRIPT = `"use strict";
391
628
  failures = 0;
392
629
  lastData = data;
393
630
  document.getElementById("problem").hidden = true;
631
+ setLive(true);
394
632
  render(data);
395
633
  })
396
634
  .catch(function (error) {